diff --git a/include/mgba/internal/gba/renderers/video-software.h b/include/mgba/internal/gba/renderers/video-software.h index 7f930a4e8..c4ed2d5cd 100644 --- a/include/mgba/internal/gba/renderers/video-software.h +++ b/include/mgba/internal/gba/renderers/video-software.h @@ -163,6 +163,8 @@ struct GBAVideoSoftwareRenderer { int start; int end; int masterEnd; + int masterHeight; + int masterScanlines; }; void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer); diff --git a/src/ds/renderers/software.c b/src/ds/renderers/software.c index 07f315fbf..93ebdf858 100644 --- a/src/ds/renderers/software.c +++ b/src/ds/renderers/software.c @@ -94,10 +94,14 @@ static void DSVideoSoftwareRendererInit(struct DSVideoRenderer* renderer) { softwareRenderer->engA.d.palette = &renderer->palette[0]; softwareRenderer->engA.d.oam = &renderer->oam->oam[0]; softwareRenderer->engA.masterEnd = DS_VIDEO_HORIZONTAL_PIXELS; + softwareRenderer->engA.masterHeight = DS_VIDEO_VERTICAL_PIXELS; + softwareRenderer->engA.masterScanlines = DS_VIDEO_VERTICAL_TOTAL_PIXELS; softwareRenderer->engA.outputBufferStride = softwareRenderer->outputBufferStride; softwareRenderer->engB.d.palette = &renderer->palette[512]; softwareRenderer->engB.d.oam = &renderer->oam->oam[1]; softwareRenderer->engB.masterEnd = DS_VIDEO_HORIZONTAL_PIXELS; + softwareRenderer->engB.masterHeight = DS_VIDEO_VERTICAL_PIXELS; + softwareRenderer->engB.masterScanlines = DS_VIDEO_VERTICAL_TOTAL_PIXELS; softwareRenderer->engB.outputBufferStride = softwareRenderer->outputBufferStride; DSVideoSoftwareRendererReset(renderer); diff --git a/src/gba/renderers/video-software.c b/src/gba/renderers/video-software.c index 1a41a37eb..f434f7e66 100644 --- a/src/gba/renderers/video-software.c +++ b/src/gba/renderers/video-software.c @@ -63,6 +63,8 @@ void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer) { renderer->d.disableOBJ = false; renderer->tileStride = 0x20; renderer->masterEnd = VIDEO_HORIZONTAL_PIXELS; + renderer->masterHeight = VIDEO_VERTICAL_PIXELS; + renderer->masterScanlines = VIDEO_VERTICAL_TOTAL_PIXELS; renderer->temporaryBuffer = 0; } @@ -471,7 +473,7 @@ static void _cleanOAM(struct GBAVideoSoftwareRenderer* renderer) { if (GBAObjAttributesAIsTransformed(obj.a)) { height <<= GBAObjAttributesAGetDoubleSize(obj.a); } - if (GBAObjAttributesAGetY(obj.a) < VIDEO_VERTICAL_PIXELS || GBAObjAttributesAGetY(obj.a) + height >= VIDEO_VERTICAL_TOTAL_PIXELS) { + if (GBAObjAttributesAGetY(obj.a) < renderer->masterHeight || GBAObjAttributesAGetY(obj.a) + height >= renderer->masterScanlines) { renderer->sprites[oamMax].y = GBAObjAttributesAGetY(obj.a); renderer->sprites[oamMax].endY = GBAObjAttributesAGetY(obj.a) + height; renderer->sprites[oamMax].obj = obj; @@ -571,7 +573,7 @@ static void GBAVideoSoftwareRendererFinishFrame(struct GBAVideoRenderer* rendere struct GBAVideoSoftwareRenderer* softwareRenderer = (struct GBAVideoSoftwareRenderer*) renderer; if (softwareRenderer->temporaryBuffer) { - mappedMemoryFree(softwareRenderer->temporaryBuffer, softwareRenderer->masterEnd * VIDEO_VERTICAL_PIXELS * 4); + mappedMemoryFree(softwareRenderer->temporaryBuffer, softwareRenderer->masterEnd * softwareRenderer->masterHeight * 4); softwareRenderer->temporaryBuffer = 0; } softwareRenderer->bg[2].sx = softwareRenderer->bg[2].refx; @@ -591,7 +593,7 @@ static void GBAVideoSoftwareRendererPutPixels(struct GBAVideoRenderer* renderer, const color_t* colorPixels = pixels; unsigned i; - for (i = 0; i < VIDEO_VERTICAL_PIXELS; ++i) { + for (i = 0; i < softwareRenderer->masterHeight; ++i) { memmove(&softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * i], &colorPixels[stride * i], softwareRenderer->masterEnd * BYTES_PER_PIXEL); } }