all repos — mgba @ 12931fbe25e2ccbd796a826368a444e79316e426

mGBA Game Boy Advance Emulator

GB Video: Implement SGB ATTR_CHR
Vicki Pfau vi@endrift.com
Mon, 08 Jan 2018 23:42:43 -0800
commit

12931fbe25e2ccbd796a826368a444e79316e426

parent

65207f5c0f8173ac31c5f382e1f6f274ab6e701f

3 files changed, 49 insertions(+), 0 deletions(-)

jump to
M include/mgba/internal/gb/renderers/software.hinclude/mgba/internal/gb/renderers/software.h

@@ -45,6 +45,9 @@ int sgbPacketId;

int sgbDataSets; uint8_t sgbPartialDataSet[15]; bool sgbBorders; + int sgbAttrX; + int sgbAttrY; + int sgbAttrDirection; }; void GBVideoSoftwareRendererCreate(struct GBVideoSoftwareRenderer*);
M src/gb/renderers/software.csrc/gb/renderers/software.c

@@ -303,6 +303,51 @@ if (i < 16 && softwareRenderer->sgbDataSets) {

memcpy(softwareRenderer->sgbPartialDataSet, &softwareRenderer->sgbPacket[i], 16 - i); } break; + case SGB_ATTR_CHR: + if (softwareRenderer->sgbPacketId == 1) { + softwareRenderer->sgbAttrX = softwareRenderer->sgbPacket[1]; + softwareRenderer->sgbAttrY = softwareRenderer->sgbPacket[2]; + if (softwareRenderer->sgbAttrX >= GB_VIDEO_HORIZONTAL_PIXELS / 8) { + softwareRenderer->sgbAttrX = 0; + } + if (softwareRenderer->sgbAttrY >= GB_VIDEO_VERTICAL_PIXELS / 8) { + softwareRenderer->sgbAttrY = 0; + } + softwareRenderer->sgbDataSets = softwareRenderer->sgbPacket[3]; + softwareRenderer->sgbDataSets |= softwareRenderer->sgbPacket[4] << 8; + softwareRenderer->sgbAttrDirection = softwareRenderer->sgbPacket[5]; + i = 6; + } else { + i = 0; + } + for (; i < 16 && softwareRenderer->sgbDataSets; ++i) { + int j; + for (j = 0; j < 4 && softwareRenderer->sgbDataSets; ++j, --softwareRenderer->sgbDataSets) { + uint8_t p = softwareRenderer->sgbPacket[i] >> (6 - j * 2); + _setAttribute(renderer->sgbAttributes, softwareRenderer->sgbAttrX, softwareRenderer->sgbAttrY, p & 3); + if (softwareRenderer->sgbAttrDirection) { + ++softwareRenderer->sgbAttrY; + if (softwareRenderer->sgbAttrY >= GB_VIDEO_VERTICAL_PIXELS / 8) { + softwareRenderer->sgbAttrY = 0; + ++softwareRenderer->sgbAttrX; + } + if (softwareRenderer->sgbAttrX >= GB_VIDEO_HORIZONTAL_PIXELS / 8) { + softwareRenderer->sgbAttrX = 0; + } + } else { + ++softwareRenderer->sgbAttrX; + if (softwareRenderer->sgbAttrX >= GB_VIDEO_HORIZONTAL_PIXELS / 8) { + softwareRenderer->sgbAttrX = 0; + ++softwareRenderer->sgbAttrY; + } + if (softwareRenderer->sgbAttrY >= GB_VIDEO_VERTICAL_PIXELS / 8) { + softwareRenderer->sgbAttrY = 0; + } + } + } + } + + break; case SGB_ATRC_EN: if (softwareRenderer->sgbBorders) { _regenerateSGBBorder(softwareRenderer);
M src/gb/video.csrc/gb/video.c

@@ -685,6 +685,7 @@ video->renderer->writePalette(video->renderer, i * 4 + 3, video->palette[i * 4 + 3]);

} break; case SGB_ATTR_BLK: + case SGB_ATTR_CHR: case SGB_PAL_TRN: case SGB_ATRC_EN: case SGB_CHR_TRN: