commit 83519708bc2c2401d3ccde7f42c000353ab6339a
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Thu Jan 20 22:03:10 2022 -0700
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Thu Jan 20 22:03:10 2022 -0700
initial screen memory remapping implementation
---
source/graphics.cpp | 15 ++++++++-------
test/graphicstests.cpp | 41 +++++++++++++++++++++++++++++++++++++++++
test/vmtests.cpp | 1 +
3 files changed, 50 insertions(+), 7 deletions(-)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index eb62b5a..0474a71 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -112,7 +112,7 @@ void Graphics::copySpriteToScreen(
auto &drawState = _memory->drawState;
auto &hwState = _memory->hwState;
- auto &screenBuffer = _memory->screenBuffer;
+ uint8_t *screenBuffer = GetP8FrameBuffer();
const uint8_t writeMask = hwState.colorBitmask & 15;
const uint8_t readMask = hwState.colorBitmask >> 4;
@@ -262,7 +262,7 @@ void Graphics::copyStretchSpriteToScreen(
auto &drawState = _memory->drawState;
auto &hwState = _memory->hwState;
- auto &screenBuffer = _memory->screenBuffer;
+ uint8_t *screenBuffer = GetP8FrameBuffer();
const uint8_t writeMask = hwState.colorBitmask & 15;
const uint8_t readMask = hwState.colorBitmask >> 4;
@@ -535,7 +535,7 @@ void Graphics::_setPixelFromSprite(int x, int y, uint8_t col) {
auto &drawState = _memory->drawState;
auto &hwState = _memory->hwState;
- auto &screenBuffer = _memory->screenBuffer;
+ uint8_t *screenBuffer = GetP8FrameBuffer();
//col = getDrawPalMappedColor(col);
col = drawState.drawPaletteMap[col & 0x0f] & 0x0f;
@@ -561,7 +561,7 @@ void Graphics::_setPixelFromPen(int x, int y) {
auto &drawState = _memory->drawState;
auto &hwState = _memory->hwState;
- auto &screenBuffer = _memory->screenBuffer;
+ uint8_t *screenBuffer = GetP8FrameBuffer();
uint8_t col = drawState.color;
@@ -615,7 +615,7 @@ void Graphics::cls() {
void Graphics::cls(uint8_t color) {
color = color & 15;
uint8_t val = color << 4 | color;
- memset(_memory->screenBuffer, val, sizeof(_memory->screenBuffer));
+ memset(GetP8FrameBuffer(), val, sizeof(_memory->screenBuffer));
_memory->drawState.text_x = 0;
_memory->drawState.text_y = 0;
@@ -644,7 +644,7 @@ uint8_t Graphics::pget(int x, int y){
applyCameraToPoint(&x, &y);
if (isOnScreen(x, y)){
- return getPixelNibble(x, y, _memory->screenBuffer);
+ return getPixelNibble(x, y, GetP8FrameBuffer());
}
return 0;
@@ -750,6 +750,7 @@ void Graphics::_private_h_line(int x1, int x2, int y){
void Graphics::_private_v_line (int y1, int y2, int x){
auto &drawState = _memory->drawState;
auto &hwState = _memory->hwState;
+ uint8_t * screenBuffer = GetP8FrameBuffer();
if (!(x >= drawState.clip_xb && x < drawState.clip_xe)) {
return;
@@ -782,7 +783,7 @@ void Graphics::_private_v_line (int y1, int y2, int x){
for (int16_t y = miny; y <= maxy; ++y)
{
int pixIdx = COMBINED_IDX(x, y);
- auto &data = _memory->screenBuffer[pixIdx];
+ auto &data = screenBuffer[pixIdx];
data = (data & mask) | nibble;
}
}
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index b1f65af..1f31fe6 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -2192,6 +2192,47 @@ TEST_CASE("graphics class behaves as expected") {
checkPoints(graphics, expectedPoints);
}
+
+ SUBCASE("Remap screen to spritesheet"){
+ graphics->cls();
+ graphics->sset(125,125,4);
+ graphics->sset(126,126,5);
+ graphics->sset(127,127,6);
+ graphics->sset(128,128,13);
+
+ picoRam.hwState.screenDataMemMapping = 0x00;
+
+ std::vector<coloredPoint> expectedPoints = {
+ {124,124,0},
+ {125,124,0},
+ {126,124,0},
+ {127,124,0},
+ {128,124,0},
+ {124,125,0},
+ {125,125,4},
+ {126,125,0},
+ {127,125,0},
+ {128,125,0},
+ {124,126,0},
+ {125,126,0},
+ {126,126,5},
+ {127,126,0},
+ {128,126,0},
+ {124,127,0},
+ {125,127,0},
+ {126,127,0},
+ {127,127,6},
+ {128,127,0},
+ {124,128,0},
+ {125,128,0},
+ {126,128,0},
+ {127,128,0},
+ {128,128,0}
+
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
//general teardown
diff --git a/test/vmtests.cpp b/test/vmtests.cpp
index b3b2d14..18d35ee 100644
--- a/test/vmtests.cpp
+++ b/test/vmtests.cpp
@@ -14,6 +14,7 @@
TEST_CASE("Vm memory functions") {
StubHost* stubHost = new StubHost();
PicoRam* memory = new PicoRam();
+ memory->Reset();
Graphics* graphics = new Graphics(get_font_data(), memory);
Input* input = new Input(memory);
Audio* audio = new Audio(memory);