diff --git a/include/mgba/internal/gba/renderers/video-software.h b/include/mgba/internal/gba/renderers/video-software.h index ee4af4fc3..8df09011d 100644 --- a/include/mgba/internal/gba/renderers/video-software.h +++ b/include/mgba/internal/gba/renderers/video-software.h @@ -15,6 +15,9 @@ CXX_GUARD_START #include #include #include +#ifdef M_CORE_DS +#include +#endif struct GBAVideoSoftwareBackground { unsigned index; @@ -158,7 +161,11 @@ struct GBAVideoSoftwareRenderer { struct ScanlineCache { uint16_t io[REG_SOUND1CNT_LO >> 1]; int32_t scale[2][2]; +#ifdef M_CORE_DS + } cache[DS_VIDEO_VERTICAL_PIXELS]; +#else } cache[GBA_VIDEO_VERTICAL_PIXELS]; +#endif int nextY; int start; diff --git a/src/ds/renderers/software.c b/src/ds/renderers/software.c index 9e8f180f5..ad5552022 100644 --- a/src/ds/renderers/software.c +++ b/src/ds/renderers/software.c @@ -378,6 +378,18 @@ static void DSVideoSoftwareRendererInvalidateExtPal(struct DSVideoRenderer* rend static void DSVideoSoftwareRendererDrawGBAScanline(struct GBAVideoRenderer* renderer, struct DSGX* gx, int y) { struct GBAVideoSoftwareRenderer* softwareRenderer = (struct GBAVideoSoftwareRenderer*) renderer; + if (y == DS_VIDEO_VERTICAL_PIXELS - 1) { + softwareRenderer->nextY = 0; + } else { + softwareRenderer->nextY = y + 1; + } + + bool dirty = softwareRenderer->scanlineDirty[y >> 5] & (1 << (y & 0x1F)); + if (memcmp(softwareRenderer->nextIo, softwareRenderer->cache[y].io, sizeof(softwareRenderer->nextIo))) { + memcpy(softwareRenderer->cache[y].io, softwareRenderer->nextIo, sizeof(softwareRenderer->nextIo)); + dirty = true; + } + int x; color_t* row = &softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * y]; if (GBARegisterDISPCNTIsForcedBlank(softwareRenderer->dispcnt)) {