Skip to content

Commit

Permalink
initial screen memory remapping implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
jtothebell committed Jan 21, 2022
1 parent 139f985 commit 8351970
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
15 changes: 8 additions & 7 deletions source/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down
41 changes: 41 additions & 0 deletions test/graphicstests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/vmtests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8351970

Please sign in to comment.