commit 139f985e0136ab18d80d9154ef250c6b06ece06e
Author: jtothebell <j.to.the.bell@gmail.com>
AuthorDate: Thu Jan 20 18:55:34 2022 -0700
Commit: jtothebell <j.to.the.bell@gmail.com>
CommitDate: Thu Jan 20 18:55:34 2022 -0700
Initial support for mapping sprite sheet to screen
---
source/graphics.cpp | 19 ++++++----
source/graphics.h | 1 +
test/graphicstests.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 108 insertions(+), 6 deletions(-)
diff --git a/source/graphics.cpp b/source/graphics.cpp
index 61a6496..eb62b5a 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -73,8 +73,15 @@ Graphics::Graphics(std::string fontdata, PicoRam* memory) {
uint8_t* Graphics::GetP8FrameBuffer(){
- //TODO: replace with ram's screen buffer
- return _memory->screenBuffer;
+ return _memory->hwState.screenDataMemMapping == 0
+ ? _memory->spriteSheetData
+ : _memory->screenBuffer;
+}
+
+uint8_t* Graphics::GetP8SpriteSheetBuffer(){
+ return _memory->hwState.spriteSheetMemMapping == 0x60
+ ? _memory->screenBuffer
+ : _memory->spriteSheetData;
}
uint8_t* Graphics::GetScreenPaletteMap(){
@@ -1353,7 +1360,7 @@ void Graphics::spr(
int spr_y = (n / 16) * 8;
int16_t spr_w = (int16_t)(w * (fix32)8);
int16_t spr_h = (int16_t)(h * (fix32)8);
- copySpriteToScreen(_memory->spriteSheetData, x, y, spr_x, spr_y, spr_w, spr_h, flip_x, flip_y);
+ copySpriteToScreen(GetP8SpriteSheetBuffer(), x, y, spr_x, spr_y, spr_w, spr_h, flip_x, flip_y);
}
void Graphics::sspr(
@@ -1368,7 +1375,7 @@ void Graphics::sspr(
bool flip_x = false,
bool flip_y = false)
{
- copyStretchSpriteToScreen(_memory->spriteSheetData, sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y);
+ copyStretchSpriteToScreen(GetP8SpriteSheetBuffer(), sx, sy, sw, sh, dx, dy, dw, dh, flip_x, flip_y);
}
bool Graphics::fget(uint8_t n, uint8_t f){
@@ -1393,11 +1400,11 @@ void Graphics::fset(uint8_t n, uint8_t v){
}
uint8_t Graphics::sget(uint8_t x, uint8_t y){
- return getPixelNibble(x, y, _memory->spriteSheetData);
+ return getPixelNibble(x, y, GetP8SpriteSheetBuffer());
}
void Graphics::sset(uint8_t x, uint8_t y, uint8_t c){
- setPixelNibble(x, y, c, _memory->spriteSheetData);
+ setPixelNibble(x, y, c, GetP8SpriteSheetBuffer());
}
std::tuple<int16_t, int16_t> Graphics::camera() {
diff --git a/source/graphics.h b/source/graphics.h
index 0090eb6..b85d83b 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -98,6 +98,7 @@ class Graphics {
Graphics(std::string fontdata, PicoRam* memory);
uint8_t* GetP8FrameBuffer();
+ uint8_t* GetP8SpriteSheetBuffer();
uint8_t* GetScreenPaletteMap();
Color* GetPaletteColors();
diff --git a/test/graphicstests.cpp b/test/graphicstests.cpp
index 3a05061..b1f65af 100644
--- a/test/graphicstests.cpp
+++ b/test/graphicstests.cpp
@@ -2098,6 +2098,100 @@ TEST_CASE("graphics class behaves as expected") {
checkPoints(graphics, expectedPoints);
}
*/
+
+ SUBCASE("Remap spritesheet to screen"){
+ graphics->cls();
+ graphics->print("zo", 8, 0);
+ picoRam.hwState.spriteSheetMemMapping = 0x60;
+
+ graphics->spr(1, 0, 64, 1.0, 1.0, false, false);
+
+ std::vector<coloredPoint> expectedPoints = {
+ {0,64,6},
+ {1,64,6},
+ {2,64,6},
+ {3,64,0},
+ {4,64,0},
+ {5,64,6},
+ {6,64,6},
+ {7,64,0},
+ {8,64,0},
+ {0,65,0},
+ {1,65,0},
+ {2,65,6},
+ {3,65,0},
+ {4,65,6},
+ {5,65,0},
+ {6,65,6},
+ {7,65,0},
+ {8,65,0},
+ {0,66,0},
+ {1,66,6},
+ {2,66,0},
+ {3,66,0},
+ {4,66,6},
+ {5,66,0},
+ {6,66,6},
+ {7,66,0},
+ {8,66,0},
+ {0,67,6},
+ {1,67,0},
+ {2,67,0},
+ {3,67,0},
+ {4,67,6},
+ {5,67,0},
+ {6,67,6},
+ {7,67,0},
+ {8,67,0},
+ {0,68,6},
+ {1,68,6},
+ {2,68,6},
+ {3,68,0},
+ {4,68,6},
+ {5,68,6},
+ {6,68,0},
+ {7,68,0},
+ {8,68,0},
+ {0,69,0},
+ {1,69,0},
+ {2,69,0},
+ {3,69,0},
+ {4,69,0},
+ {5,69,0},
+ {6,69,0},
+ {7,69,0},
+ {8,69,0},
+ {0,70,0},
+ {1,70,0},
+ {2,70,0},
+ {3,70,0},
+ {4,70,0},
+ {5,70,0},
+ {6,70,0},
+ {7,70,0},
+ {8,70,0},
+ {0,71,0},
+ {1,71,0},
+ {2,71,0},
+ {3,71,0},
+ {4,71,0},
+ {5,71,0},
+ {6,71,0},
+ {7,71,0},
+ {8,71,0},
+ {0,72,0},
+ {1,72,0},
+ {2,72,0},
+ {3,72,0},
+ {4,72,0},
+ {5,72,0},
+ {6,72,0},
+ {7,72,0},
+ {8,72,0}
+ };
+
+ checkPoints(graphics, expectedPoints);
+ }
//general teardown