Restructure video memory
Jeffrey Pfau jeffrey@endrift.com
Sat, 20 Apr 2013 16:16:37 -0700
5 files changed,
31 insertions(+),
10 deletions(-)
M
src/gba/gba-bios.c
→
src/gba/gba-bios.c
@@ -91,7 +91,7 @@ case 0x11:
_unLz77(&gba->memory, gba->cpu.gprs[0], &((uint8_t*) gba->memory.wram)[(gba->cpu.gprs[1] & (SIZE_WORKING_RAM - 1))]); break; case 0x12: - _unLz77(&gba->memory, gba->cpu.gprs[0], &((uint8_t*) gba->video.renderer->vram)[(gba->cpu.gprs[1] & (SIZE_VRAM - 1))]); + _unLz77(&gba->memory, gba->cpu.gprs[0], &((uint8_t*) gba->video.vram)[(gba->cpu.gprs[1] & (SIZE_VRAM - 1))]); break; case 0x1F: _MidiKey2Freq(gba);
M
src/gba/gba-thread.c
→
src/gba/gba-thread.c
@@ -16,6 +16,10 @@ sigfillset(&signals);
pthread_sigmask(SIG_UNBLOCK, &signals, 0); GBAInit(&gba); + if (threadContext->renderer) { + GBAVideoAssociateRenderer(&gba.video, threadContext->renderer); + } + threadContext->gba = &gba; threadContext->debugger = &debugger; if (threadContext->fd >= 0) {
M
src/gba/gba-thread.h
→
src/gba/gba-thread.h
@@ -4,8 +4,12 @@
#include <pthread.h> struct GBAThread { + // Output struct GBA* gba; struct ARMDebugger* debugger; + + // Input + struct GBAVideoRenderer* renderer; int fd; };
M
src/gba/gba-video.c
→
src/gba/gba-video.c
@@ -6,14 +6,14 @@
#include <limits.h> #include <string.h> -static void GBAVideoRendererInit(struct GBAVideoRenderer* renderer); - +static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer); static void GBAVideoDummyRendererDeinit(struct GBAVideoRenderer* renderer); static uint16_t GBAVideoDummyRendererWriteVideoRegister(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value); static void GBAVideoDummyRendererDrawScanline(struct GBAVideoRenderer* renderer, int y); static void GBAVideoDummyRendererFinishFrame(struct GBAVideoRenderer* renderer); static struct GBAVideoRenderer dummyRenderer = { + .init = GBAVideoDummyRendererInit, .deinit = GBAVideoDummyRendererDeinit, .writeVideoRegister = GBAVideoDummyRendererWriteVideoRegister, .drawScanline = GBAVideoDummyRendererDrawScanline,@@ -41,6 +41,13 @@
video->nextHblankIRQ = 0; video->nextVblankIRQ = 0; video->nextVcounterIRQ = 0; +} + +void GBAVideoAssociateRenderer(struct GBAVideo* video, struct GBAVideoRenderer* renderer) { + video->renderer = renderer; + renderer->palette = video->palette; + renderer->vram = video->vram; + renderer->oam = &video->oam; } int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles) {@@ -128,16 +135,16 @@ uint16_t GBAVideoReadDISPSTAT(struct GBAVideo* video) {
return (video->inVblank) | (video->inHblank << 1) | (video->vcounter << 2); } -static void GBAVideoRendererInit(struct GBAVideoRenderer* renderer) { - memset(renderer->palette, 0, sizeof(renderer->palette)); - memset(renderer->vram, 0, sizeof(renderer->vram)); - memset(&renderer->oam, 0, sizeof(renderer->oam)); +static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer) { + (void)(renderer); + // Nothing to do } static void GBAVideoDummyRendererDeinit(struct GBAVideoRenderer* renderer) { (void)(renderer); // Nothing to do } + static uint16_t GBAVideoDummyRendererWriteVideoRegister(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value) { (void)(renderer); (void)(address);
M
src/gba/gba-video.h
→
src/gba/gba-video.h
@@ -89,15 +89,16 @@ uint16_t raw[512];
}; struct GBAVideoRenderer { + void (*init)(struct GBAVideoRenderer* renderer); void (*deinit)(struct GBAVideoRenderer* renderer); uint16_t (*writeVideoRegister)(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value); void (*drawScanline)(struct GBAVideoRenderer* renderer, int y); void (*finishFrame)(struct GBAVideoRenderer* renderer); - uint16_t palette[SIZE_PALETTE_RAM >> 1]; - uint16_t vram[SIZE_VRAM >> 1]; - union GBAOAM oam; + uint16_t* palette; + uint16_t* vram; + union GBAOAM* oam; }; struct GBAVideo {@@ -124,9 +125,14 @@
int32_t nextHblankIRQ; int32_t nextVblankIRQ; int32_t nextVcounterIRQ; + + uint16_t palette[SIZE_PALETTE_RAM >> 1]; + uint16_t vram[SIZE_VRAM >> 1]; + union GBAOAM oam; }; void GBAVideoInit(struct GBAVideo* video); +void GBAVideoAssociateRenderer(struct GBAVideo* video, struct GBAVideoRenderer* renderer); int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles); void GBAVideoWriteDISPSTAT(struct GBAVideo* video, uint16_t value);