From 2cd339d3f6075e8e68a5ea5dd81d06ea3e10aac8 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 21 Apr 2018 17:36:42 -0700 Subject: [PATCH] GB Video: Implement ATTR_DIV --- src/gb/renderers/software.c | 52 +++++++++++++++++++++++++++++++++++++ src/gb/video.c | 1 + 2 files changed, 53 insertions(+) diff --git a/src/gb/renderers/software.c b/src/gb/renderers/software.c index e1447daf5..77cb64ca5 100644 --- a/src/gb/renderers/software.c +++ b/src/gb/renderers/software.c @@ -264,6 +264,9 @@ static void GBVideoSoftwareRendererWriteSGBPacket(struct GBVideoRenderer* render int attrX; int attrY; int attrDirection; + int pBefore; + int pAfter; + int pDiv; switch (softwareRenderer->sgbCommandHeader >> 3) { case SGB_PAL_SET: softwareRenderer->sgbPacket[1] = data[9]; @@ -284,6 +287,55 @@ static void GBVideoSoftwareRendererWriteSGBPacket(struct GBVideoRenderer* render _parseAttrBlock(softwareRenderer, i); } break; + case SGB_ATTR_DIV: + pAfter = softwareRenderer->sgbPacket[1] & 3; + pBefore = (softwareRenderer->sgbPacket[1] >> 2) & 3; + pDiv = (softwareRenderer->sgbPacket[1] >> 4) & 3; + attrX = softwareRenderer->sgbPacket[2]; + if (softwareRenderer->sgbPacket[1] & 0x40) { + if (attrX > GB_VIDEO_VERTICAL_PIXELS / 8) { + attrX = GB_VIDEO_VERTICAL_PIXELS / 8; + } + int j; + for (j = 0; j < attrX; ++j) { + for (i = 0; i < GB_VIDEO_HORIZONTAL_PIXELS / 8; ++i) { + _setAttribute(renderer->sgbAttributes, i, j, pBefore); + } + } + if (attrX < GB_VIDEO_VERTICAL_PIXELS / 8) { + for (i = 0; i < GB_VIDEO_HORIZONTAL_PIXELS / 8; ++i) { + _setAttribute(renderer->sgbAttributes, i, attrX, pDiv); + } + + } + for (; j < GB_VIDEO_VERTICAL_PIXELS / 8; ++j) { + for (i = 0; i < GB_VIDEO_HORIZONTAL_PIXELS / 8; ++i) { + _setAttribute(renderer->sgbAttributes, i, j, pAfter); + } + } + } else { + if (attrX > GB_VIDEO_HORIZONTAL_PIXELS / 8) { + attrX = GB_VIDEO_HORIZONTAL_PIXELS / 8; + } + int j; + for (j = 0; j < attrX; ++j) { + for (i = 0; i < GB_VIDEO_HORIZONTAL_PIXELS / 8; ++i) { + _setAttribute(renderer->sgbAttributes, j, i, pBefore); + } + } + if (attrX < GB_VIDEO_HORIZONTAL_PIXELS / 8) { + for (i = 0; i < GB_VIDEO_VERTICAL_PIXELS / 8; ++i) { + _setAttribute(renderer->sgbAttributes, attrX, i, pDiv); + } + + } + for (; j < GB_VIDEO_HORIZONTAL_PIXELS / 8; ++j) { + for (i = 0; i < GB_VIDEO_VERTICAL_PIXELS / 8; ++i) { + _setAttribute(renderer->sgbAttributes, j, i, pAfter); + } + } + } + break; case SGB_ATTR_CHR: attrX = softwareRenderer->sgbPacket[1]; attrY = softwareRenderer->sgbPacket[2]; diff --git a/src/gb/video.c b/src/gb/video.c index 51354d288..fe9a9dac8 100644 --- a/src/gb/video.c +++ b/src/gb/video.c @@ -692,6 +692,7 @@ void GBVideoWriteSGBPacket(struct GBVideo* video, uint8_t* data) { } break; case SGB_ATTR_BLK: + case SGB_ATTR_DIV: case SGB_ATTR_CHR: case SGB_PAL_TRN: case SGB_ATRC_EN: