diff --git a/CHANGES b/CHANGES index 267600d79..f0ca8a816 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,7 @@ Bugfixes: - FFmpeg: Fix encoding AAC - GB Video: Fix video frames getting missed when LCDC is off - LR35902: Fix events running with the wrong cycle active + - GB Video: Clear screen when LCDC is off Misc: - All: Only update version info if needed - FFmpeg: Encoding cleanup diff --git a/src/gb/renderers/software.c b/src/gb/renderers/software.c index 7d9e8e569..e6995b1f8 100644 --- a/src/gb/renderers/software.c +++ b/src/gb/renderers/software.c @@ -21,6 +21,31 @@ static void GBVideoSoftwareRendererPutPixels(struct GBVideoRenderer* renderer, s static void GBVideoSoftwareRendererDrawBackground(struct GBVideoSoftwareRenderer* renderer, uint8_t* maps, int startX, int endX, int sx, int sy); static void GBVideoSoftwareRendererDrawObj(struct GBVideoSoftwareRenderer* renderer, struct GBObj* obj, int startX, int endX, int y); +static void _clearScreen(struct GBVideoSoftwareRenderer* renderer) { + // TODO: Dynamic from dmgPalette +#ifdef COLOR_16_BIT +#ifdef COLOR_5_6_5 + color_t palette0 = 0xFFDF; +#else + color_t palette0 = 0x7FFF; +#endif +#else + color_t palette0 = 0xF8F8F8; +#endif + + int y; + for (y = 0; y < GB_VIDEO_VERTICAL_PIXELS; ++y) { + color_t* row = &renderer->outputBuffer[renderer->outputBufferStride * y]; + int x; + for (x = 0; x < GB_VIDEO_HORIZONTAL_PIXELS; x += 4) { + row[x + 0] = palette0; + row[x + 1] = palette0; + row[x + 2] = palette0; + row[x + 3] = palette0; + } + } +} + void GBVideoSoftwareRendererCreate(struct GBVideoSoftwareRenderer* renderer) { renderer->d.init = GBVideoSoftwareRendererInit; renderer->d.deinit = GBVideoSoftwareRendererDeinit; @@ -44,14 +69,7 @@ static void GBVideoSoftwareRendererInit(struct GBVideoRenderer* renderer, enum G softwareRenderer->wx = 0; softwareRenderer->model = model; - int y; - for (y = 0; y < GB_VIDEO_VERTICAL_PIXELS; ++y) { - color_t* row = &softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * y]; - int x; - for (x = 0; x < GB_VIDEO_HORIZONTAL_PIXELS; ++x) { - row[x] = softwareRenderer->palette[0]; - } - } + _clearScreen(softwareRenderer); } static void GBVideoSoftwareRendererDeinit(struct GBVideoRenderer* renderer) { @@ -63,6 +81,9 @@ static uint8_t GBVideoSoftwareRendererWriteVideoRegister(struct GBVideoRenderer* struct GBVideoSoftwareRenderer* softwareRenderer = (struct GBVideoSoftwareRenderer*) renderer; switch (address) { case REG_LCDC: + if (GBRegisterLCDCIsEnable(softwareRenderer->lcdc) && !GBRegisterLCDCIsEnable(value)) { + _clearScreen(softwareRenderer); + } softwareRenderer->lcdc = value; break; case REG_SCY: