diff --git a/src/gba/gba-io.c b/src/gba/gba-io.c index ae3e8094b..a3664e9b3 100644 --- a/src/gba/gba-io.c +++ b/src/gba/gba-io.c @@ -3,6 +3,7 @@ #include "gba-video.h" void GBAIOInit(struct GBA* gba) { + gba->memory.io[REG_DISPCNT >> 1] = 0x0080; gba->memory.io[REG_KEYINPUT >> 1] = 0x3FF; } diff --git a/src/gba/renderers/video-software.c b/src/gba/renderers/video-software.c index af7363ea0..852cbd7ce 100644 --- a/src/gba/renderers/video-software.c +++ b/src/gba/renderers/video-software.c @@ -1,6 +1,7 @@ #include "video-software.h" #include "gba.h" +#include "gba-io.h" static void GBAVideoSoftwareRendererInit(struct GBAVideoRenderer* renderer); static void GBAVideoSoftwareRendererDeinit(struct GBAVideoRenderer* renderer); @@ -8,6 +9,8 @@ static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRender static void GBAVideoSoftwareRendererDrawScanline(struct GBAVideoRenderer* renderer, int y); static void GBAVideoSoftwareRendererFinishFrame(struct GBAVideoRenderer* renderer); +static void GBAVideoSoftwareRendererUpdateDISPCNT(struct GBAVideoSoftwareRenderer* renderer); + void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer) { renderer->d.init = GBAVideoSoftwareRendererInit; renderer->d.deinit = GBAVideoSoftwareRendererDeinit; @@ -26,6 +29,8 @@ void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer) { static void GBAVideoSoftwareRendererInit(struct GBAVideoRenderer* renderer) { struct GBAVideoSoftwareRenderer* softwareRenderer = (struct GBAVideoSoftwareRenderer*) renderer; + softwareRenderer->dispcnt.packed = 0x0080; + pthread_mutex_init(&softwareRenderer->mutex, 0); pthread_cond_init(&softwareRenderer->cond, 0); } @@ -37,8 +42,13 @@ static void GBAVideoSoftwareRendererDeinit(struct GBAVideoRenderer* renderer) { static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value) { struct GBAVideoSoftwareRenderer* softwareRenderer = (struct GBAVideoSoftwareRenderer*) renderer; switch (address) { + case REG_DISPCNT: + value &= 0xFFFB; + softwareRenderer->dispcnt.packed = value; + GBAVideoSoftwareRendererUpdateDISPCNT(softwareRenderer); + break; default: - GBALog(GBA_LOG_STUB, "Stub video register write: %03x", address); + GBALog(GBA_LOG_STUB, "Stub video register write: %03x", address); } return value; } @@ -47,6 +57,12 @@ static void GBAVideoSoftwareRendererDrawScanline(struct GBAVideoRenderer* render struct GBAVideoSoftwareRenderer* softwareRenderer = (struct GBAVideoSoftwareRenderer*) renderer; int x; uint16_t* row = &softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * y]; + if (softwareRenderer->dispcnt.forcedBlank) { + for (x = 0; x < VIDEO_HORIZONTAL_PIXELS; ++x) { + row[x] = 0x7FFF; + } + return; + } for (x = 0; x < 16; ++x) { row[(x * 15) + 0] = renderer->palette[x + (y / 5) * 16]; row[(x * 15) + 1] = renderer->palette[x + (y / 5) * 16]; @@ -73,3 +89,7 @@ static void GBAVideoSoftwareRendererFinishFrame(struct GBAVideoRenderer* rendere pthread_cond_wait(&softwareRenderer->cond, &softwareRenderer->mutex); pthread_mutex_unlock(&softwareRenderer->mutex); } + +static void GBAVideoSoftwareRendererUpdateDISPCNT(struct GBAVideoSoftwareRenderer* renderer) { + // TODO +} diff --git a/src/gba/renderers/video-software.h b/src/gba/renderers/video-software.h index 8632850e7..aff0ec632 100644 --- a/src/gba/renderers/video-software.h +++ b/src/gba/renderers/video-software.h @@ -11,6 +11,8 @@ struct GBAVideoSoftwareRenderer { uint16_t* outputBuffer; unsigned outputBufferStride; + union GBARegisterDISPCNT dispcnt; + pthread_mutex_t mutex; pthread_cond_t cond; };