From 25a8b125ed8c75a3891f7a1a23ac664c5c5fb598 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 19 Mar 2017 14:30:40 -0700 Subject: [PATCH] GBA Video: Allow windows that end at 256 --- .../mgba/internal/gba/renderers/video-software.h | 6 +++--- src/gba/renderers/video-software.c | 16 +++++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/mgba/internal/gba/renderers/video-software.h b/include/mgba/internal/gba/renderers/video-software.h index d52af88e2..df887ede0 100644 --- a/include/mgba/internal/gba/renderers/video-software.h +++ b/include/mgba/internal/gba/renderers/video-software.h @@ -80,8 +80,8 @@ enum { #define IS_WRITABLE(PIXEL) ((PIXEL) & 0xFE000000) struct WindowRegion { - uint8_t end; - uint8_t start; + int end; + int start; }; DECL_BITFIELD(GBAWindowControl, uint8_t); @@ -168,7 +168,7 @@ struct GBAVideoSoftwareRenderer { int start; int end; int masterEnd; - unsigned masterHeight; + int masterHeight; int masterScanlines; int masterBright; diff --git a/src/gba/renderers/video-software.c b/src/gba/renderers/video-software.c index b93848b7e..e56ff673b 100644 --- a/src/gba/renderers/video-software.c +++ b/src/gba/renderers/video-software.c @@ -282,7 +282,7 @@ static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRender } break; case REG_WIN0H: - softwareRenderer->winN[0].h.end = value; + softwareRenderer->winN[0].h.end = value & 0xFF; softwareRenderer->winN[0].h.start = value >> 8; if (softwareRenderer->winN[0].h.start > softwareRenderer->masterEnd && softwareRenderer->winN[0].h.start > softwareRenderer->winN[0].h.end) { softwareRenderer->winN[0].h.start = 0; @@ -293,9 +293,12 @@ static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRender softwareRenderer->winN[0].h.start = softwareRenderer->masterEnd; } } + if (softwareRenderer->masterEnd > 0xFF && softwareRenderer->winN[0].h.end == (softwareRenderer->masterEnd & 0xFF) && softwareRenderer->winN[0].h.start != softwareRenderer->winN[0].h.end) { + softwareRenderer->winN[0].h.end = softwareRenderer->masterEnd; + } break; case REG_WIN1H: - softwareRenderer->winN[1].h.end = value; + softwareRenderer->winN[1].h.end = value & 0xFF; softwareRenderer->winN[1].h.start = value >> 8; if (softwareRenderer->winN[1].h.start > softwareRenderer->masterEnd && softwareRenderer->winN[1].h.start > softwareRenderer->winN[1].h.end) { softwareRenderer->winN[1].h.start = 0; @@ -306,9 +309,12 @@ static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRender softwareRenderer->winN[1].h.start = softwareRenderer->masterEnd; } } + if (softwareRenderer->masterEnd > 0xFF && softwareRenderer->winN[1].h.end == (softwareRenderer->masterEnd & 0xFF) && softwareRenderer->winN[1].h.start != softwareRenderer->winN[1].h.end) { + softwareRenderer->winN[1].h.end = softwareRenderer->masterEnd; + } break; case REG_WIN0V: - softwareRenderer->winN[0].v.end = value; + softwareRenderer->winN[0].v.end = value & 0xFF; softwareRenderer->winN[0].v.start = value >> 8; if (softwareRenderer->winN[0].v.start > softwareRenderer->masterHeight && softwareRenderer->winN[0].v.start > softwareRenderer->winN[0].v.end) { softwareRenderer->winN[0].v.start = 0; @@ -321,7 +327,7 @@ static uint16_t GBAVideoSoftwareRendererWriteVideoRegister(struct GBAVideoRender } break; case REG_WIN1V: - softwareRenderer->winN[1].v.end = value; + softwareRenderer->winN[1].v.end = value & 0xFF; softwareRenderer->winN[1].v.start = value >> 8; if (softwareRenderer->winN[1].v.start > softwareRenderer->masterHeight && softwareRenderer->winN[1].v.start > softwareRenderer->winN[1].v.end) { softwareRenderer->winN[1].v.start = 0; @@ -607,7 +613,7 @@ static void GBAVideoSoftwareRendererPutPixels(struct GBAVideoRenderer* renderer, struct GBAVideoSoftwareRenderer* softwareRenderer = (struct GBAVideoSoftwareRenderer*) renderer; const color_t* colorPixels = pixels; - unsigned i; + int i; for (i = 0; i < softwareRenderer->masterHeight; ++i) { memmove(&softwareRenderer->outputBuffer[softwareRenderer->outputBufferStride * i], &colorPixels[stride * i], softwareRenderer->masterEnd * BYTES_PER_PIXEL); }