Restructure video memory

This commit is contained in:
Jeffrey Pfau 2013-04-20 16:16:37 -07:00
parent cb48145ea3
commit 9ba9fac898
5 changed files with 31 additions and 10 deletions

View File

@ -91,7 +91,7 @@ void GBASwi16(struct ARMBoard* board, int immediate) {
_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);

View File

@ -16,6 +16,10 @@ static void* _GBAThreadRun(void* context) {
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) {

View File

@ -4,8 +4,12 @@
#include <pthread.h>
struct GBAThread {
// Output
struct GBA* gba;
struct ARMDebugger* debugger;
// Input
struct GBAVideoRenderer* renderer;
int fd;
};

View File

@ -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,
@ -43,6 +43,13 @@ void GBAVideoInit(struct GBAVideo* video) {
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) {
video->nextEvent -= cycles;
if (video->nextEvent <= 0) {
@ -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);

View File

@ -89,15 +89,16 @@ union GBAOAM {
};
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 @@ struct GBAVideo {
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);