GBA Video: Add delay when enabling BGs (fixes #744, fixes #752)
Vicki Pfau vi@endrift.com
Thu, 02 Nov 2017 10:04:13 -0700
6 files changed,
44 insertions(+),
6 deletions(-)
M
CHANGES
→
CHANGES
@@ -25,6 +25,7 @@ - GBA Cheats: Fix PARv3 slide codes (fixes mgba.io/i/919)
- GBA Video: OBJWIN can change blend params after OBJ is drawn (fixes mgba.io/i/921) - GBA DMA: Fix invalid DMA reads (fixes mgba.io/i/142) - GBA Savedata: Fix crash when resizing flash + - GBA Video: Add delay when enabling BGs (fixes mgba.io/i/744, mgba.io/i/752) Misc: - GBA Timer: Use global cycles for timers - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722)
M
src/gba/renderers/video-software.c
→
src/gba/renderers/video-software.c
@@ -577,7 +577,6 @@ } else {
softwareRenderer->windows[0].control.packed = 0xFF; } - GBAVideoSoftwareRendererUpdateDISPCNT(softwareRenderer); if (softwareRenderer->blendDirty) { _updatePalettes(softwareRenderer); softwareRenderer->blendDirty = false;@@ -683,6 +682,19 @@ softwareRenderer->bg[2].sx = softwareRenderer->bg[2].refx;
softwareRenderer->bg[2].sy = softwareRenderer->bg[2].refy; softwareRenderer->bg[3].sx = softwareRenderer->bg[3].refx; softwareRenderer->bg[3].sy = softwareRenderer->bg[3].refy; + + if (softwareRenderer->bg[0].enabled > 0) { + softwareRenderer->bg[0].enabled = 4; + } + if (softwareRenderer->bg[1].enabled > 0) { + softwareRenderer->bg[1].enabled = 4; + } + if (softwareRenderer->bg[2].enabled > 0) { + softwareRenderer->bg[2].enabled = 4; + } + if (softwareRenderer->bg[3].enabled > 0) { + softwareRenderer->bg[3].enabled = 4; + } } static void GBAVideoSoftwareRendererGetPixels(struct GBAVideoRenderer* renderer, size_t* stride, const void** pixels) {@@ -701,11 +713,23 @@ memmove(&softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * i], &colorPixels[stride * i], VIDEO_HORIZONTAL_PIXELS * BYTES_PER_PIXEL);
} } +static void _enableBg(struct GBAVideoSoftwareRenderer* renderer, int bg, bool active) { + if (renderer->d.disableBG[bg] || !active) { + renderer->bg[bg].enabled = 0; + } else if (!renderer->bg[bg].enabled && active) { + if (renderer->nextY == 0) { + renderer->bg[bg].enabled = 4; + } else { + renderer->bg[bg].enabled = 1; + } + } +} + static void GBAVideoSoftwareRendererUpdateDISPCNT(struct GBAVideoSoftwareRenderer* renderer) { - renderer->bg[0].enabled = GBARegisterDISPCNTGetBg0Enable(renderer->dispcnt) && !renderer->d.disableBG[0]; - renderer->bg[1].enabled = GBARegisterDISPCNTGetBg1Enable(renderer->dispcnt) && !renderer->d.disableBG[1]; - renderer->bg[2].enabled = GBARegisterDISPCNTGetBg2Enable(renderer->dispcnt) && !renderer->d.disableBG[2]; - renderer->bg[3].enabled = GBARegisterDISPCNTGetBg3Enable(renderer->dispcnt) && !renderer->d.disableBG[3]; + _enableBg(renderer, 0, GBARegisterDISPCNTGetBg0Enable(renderer->dispcnt)); + _enableBg(renderer, 1, GBARegisterDISPCNTGetBg1Enable(renderer->dispcnt)); + _enableBg(renderer, 2, GBARegisterDISPCNTGetBg2Enable(renderer->dispcnt)); + _enableBg(renderer, 3, GBARegisterDISPCNTGetBg3Enable(renderer->dispcnt)); } static void GBAVideoSoftwareRendererWriteBGCNT(struct GBAVideoSoftwareRenderer* renderer, struct GBAVideoSoftwareBackground* bg, uint16_t value) {@@ -767,7 +791,7 @@ }
} #define TEST_LAYER_ENABLED(X) \ - (renderer->bg[X].enabled && \ + (renderer->bg[X].enabled == 4 && \ (GBAWindowControlIsBg ## X ## Enable(renderer->currentWindow.packed) || \ (GBARegisterDISPCNTIsObjwinEnable(renderer->dispcnt) && GBAWindowControlIsBg ## X ## Enable (renderer->objwin.packed))) && \ renderer->bg[X].priority == priority)@@ -864,6 +888,19 @@ renderer->bg[2].sx += renderer->bg[2].dmx;
renderer->bg[2].sy += renderer->bg[2].dmy; renderer->bg[3].sx += renderer->bg[3].dmx; renderer->bg[3].sy += renderer->bg[3].dmy; + } + + if (renderer->bg[0].enabled > 0 && renderer->bg[0].enabled < 4) { + ++renderer->bg[0].enabled; + } + if (renderer->bg[1].enabled > 0 && renderer->bg[1].enabled < 4) { + ++renderer->bg[1].enabled; + } + if (renderer->bg[2].enabled > 0 && renderer->bg[2].enabled < 4) { + ++renderer->bg[2].enabled; + } + if (renderer->bg[3].enabled > 0 && renderer->bg[3].enabled < 4) { + ++renderer->bg[3].enabled; } }