GB Video: Implement SGB ATTR_CHR

This commit is contained in:
Vicki Pfau 2018-01-08 23:42:43 -08:00
parent 65207f5c0f
commit 12931fbe25
3 changed files with 49 additions and 0 deletions

View File

@ -45,6 +45,9 @@ struct GBVideoSoftwareRenderer {
int sgbDataSets; int sgbDataSets;
uint8_t sgbPartialDataSet[15]; uint8_t sgbPartialDataSet[15];
bool sgbBorders; bool sgbBorders;
int sgbAttrX;
int sgbAttrY;
int sgbAttrDirection;
}; };
void GBVideoSoftwareRendererCreate(struct GBVideoSoftwareRenderer*); void GBVideoSoftwareRendererCreate(struct GBVideoSoftwareRenderer*);

View File

@ -302,6 +302,51 @@ static void GBVideoSoftwareRendererWriteSGBPacket(struct GBVideoRenderer* render
if (i < 16 && softwareRenderer->sgbDataSets) { if (i < 16 && softwareRenderer->sgbDataSets) {
memcpy(softwareRenderer->sgbPartialDataSet, &softwareRenderer->sgbPacket[i], 16 - i); 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; break;
case SGB_ATRC_EN: case SGB_ATRC_EN:
if (softwareRenderer->sgbBorders) { if (softwareRenderer->sgbBorders) {

View File

@ -685,6 +685,7 @@ void GBVideoWriteSGBPacket(struct GBVideo* video, uint8_t* data) {
} }
break; break;
case SGB_ATTR_BLK: case SGB_ATTR_BLK:
case SGB_ATTR_CHR:
case SGB_PAL_TRN: case SGB_PAL_TRN:
case SGB_ATRC_EN: case SGB_ATRC_EN:
case SGB_CHR_TRN: case SGB_CHR_TRN: