GBA Video: Use constant for enable scanline delay max

This commit is contained in:
Vicki Pfau 2022-01-30 14:29:16 -08:00
parent 4e9389eba6
commit 16125e8623
2 changed files with 19 additions and 17 deletions

View File

@ -15,6 +15,8 @@
#define VIDEO_CHECKS true
#endif
#define ENABLED_MAX 4
void GBAVideoSoftwareRendererDrawBackgroundMode0(struct GBAVideoSoftwareRenderer* renderer,
struct GBAVideoSoftwareBackground* background, int y);
void GBAVideoSoftwareRendererDrawBackgroundMode2(struct GBAVideoSoftwareRenderer* renderer,
@ -215,7 +217,7 @@ static inline void _compositeNoBlendNoObjwin(struct GBAVideoSoftwareRenderer* re
#define TEST_LAYER_ENABLED(X) \
!softwareRenderer->d.disableBG[X] && \
(softwareRenderer->bg[X].enabled == 4 && \
(softwareRenderer->bg[X].enabled == ENABLED_MAX && \
(GBAWindowControlIsBg ## X ## Enable(softwareRenderer->currentWindow.packed) || \
(GBARegisterDISPCNTIsObjwinEnable(softwareRenderer->dispcnt) && GBAWindowControlIsBg ## X ## Enable (softwareRenderer->objwin.packed))) && \
softwareRenderer->bg[X].priority == priority)

View File

@ -545,11 +545,11 @@ static void GBAVideoSoftwareRendererDrawScanline(struct GBAVideoRenderer* render
if (!dirty) {
if (GBARegisterDISPCNTGetMode(softwareRenderer->dispcnt) != 0) {
if (softwareRenderer->bg[2].enabled == 4) {
if (softwareRenderer->bg[2].enabled == ENABLED_MAX) {
softwareRenderer->bg[2].sx += softwareRenderer->bg[2].dmx;
softwareRenderer->bg[2].sy += softwareRenderer->bg[2].dmy;
}
if (softwareRenderer->bg[3].enabled == 4) {
if (softwareRenderer->bg[3].enabled == ENABLED_MAX) {
softwareRenderer->bg[3].sx += softwareRenderer->bg[3].dmx;
softwareRenderer->bg[3].sy += softwareRenderer->bg[3].dmy;
}
@ -625,29 +625,29 @@ static void GBAVideoSoftwareRendererDrawScanline(struct GBAVideoRenderer* render
GBAVideoSoftwareRendererPostprocessBuffer(softwareRenderer);
if (GBARegisterDISPCNTGetMode(softwareRenderer->dispcnt) != 0) {
if (softwareRenderer->bg[2].enabled == 4) {
if (softwareRenderer->bg[2].enabled == ENABLED_MAX) {
softwareRenderer->bg[2].sx += softwareRenderer->bg[2].dmx;
softwareRenderer->bg[2].sy += softwareRenderer->bg[2].dmy;
}
if (softwareRenderer->bg[3].enabled == 4) {
if (softwareRenderer->bg[3].enabled == ENABLED_MAX) {
softwareRenderer->bg[3].sx += softwareRenderer->bg[3].dmx;
softwareRenderer->bg[3].sy += softwareRenderer->bg[3].dmy;
}
}
if (softwareRenderer->bg[0].enabled != 0 && softwareRenderer->bg[0].enabled < 4) {
if (softwareRenderer->bg[0].enabled != 0 && softwareRenderer->bg[0].enabled < ENABLED_MAX) {
++softwareRenderer->bg[0].enabled;
DIRTY_SCANLINE(softwareRenderer, y);
}
if (softwareRenderer->bg[1].enabled != 0 && softwareRenderer->bg[1].enabled < 4) {
if (softwareRenderer->bg[1].enabled != 0 && softwareRenderer->bg[1].enabled < ENABLED_MAX) {
++softwareRenderer->bg[1].enabled;
DIRTY_SCANLINE(softwareRenderer, y);
}
if (softwareRenderer->bg[2].enabled != 0 && softwareRenderer->bg[2].enabled < 4) {
if (softwareRenderer->bg[2].enabled != 0 && softwareRenderer->bg[2].enabled < ENABLED_MAX) {
++softwareRenderer->bg[2].enabled;
DIRTY_SCANLINE(softwareRenderer, y);
}
if (softwareRenderer->bg[3].enabled != 0 && softwareRenderer->bg[3].enabled < 4) {
if (softwareRenderer->bg[3].enabled != 0 && softwareRenderer->bg[3].enabled < ENABLED_MAX) {
++softwareRenderer->bg[3].enabled;
DIRTY_SCANLINE(softwareRenderer, y);
}
@ -693,16 +693,16 @@ static void GBAVideoSoftwareRendererFinishFrame(struct GBAVideoRenderer* rendere
softwareRenderer->bg[3].sy = softwareRenderer->bg[3].refy;
if (softwareRenderer->bg[0].enabled > 0) {
softwareRenderer->bg[0].enabled = 4;
softwareRenderer->bg[0].enabled = ENABLED_MAX;
}
if (softwareRenderer->bg[1].enabled > 0) {
softwareRenderer->bg[1].enabled = 4;
softwareRenderer->bg[1].enabled = ENABLED_MAX;
}
if (softwareRenderer->bg[2].enabled > 0) {
softwareRenderer->bg[2].enabled = 4;
softwareRenderer->bg[2].enabled = ENABLED_MAX;
}
if (softwareRenderer->bg[3].enabled > 0) {
softwareRenderer->bg[3].enabled = 4;
softwareRenderer->bg[3].enabled = ENABLED_MAX;
}
}
@ -725,22 +725,22 @@ static void GBAVideoSoftwareRendererPutPixels(struct GBAVideoRenderer* renderer,
static void _enableBg(struct GBAVideoSoftwareRenderer* renderer, int bg, bool active) {
int wasActive = renderer->bg[bg].enabled;
if (!active) {
if (renderer->nextY == 0 || (wasActive > 0 && wasActive < 4)) {
if (renderer->nextY == 0 || (wasActive > 0 && wasActive < ENABLED_MAX)) {
renderer->bg[bg].enabled = 0;
} else if (wasActive == 4) {
} else if (wasActive == ENABLED_MAX) {
renderer->bg[bg].enabled = -2;
}
} else if (!wasActive && active) {
if (renderer->nextY == 0) {
// TODO: Investigate in more depth how switching background works in different modes
renderer->bg[bg].enabled = 4;
renderer->bg[bg].enabled = ENABLED_MAX;
} else if (GBARegisterDISPCNTGetMode(renderer->dispcnt) > 2) {
renderer->bg[bg].enabled = 2;
} else {
renderer->bg[bg].enabled = 1;
}
} else if (wasActive < 0 && active) {
renderer->bg[bg].enabled = 4;
renderer->bg[bg].enabled = ENABLED_MAX;
}
}