all repos — mgba @ 3202811e416e8b7c6ddc8a68442536510aa2b85e

mGBA Game Boy Advance Emulator

Be more rigorous when reseting
Jeffrey Pfau jeffrey@endrift.com
Sat, 19 Jul 2014 14:34:24 -0700
commit

3202811e416e8b7c6ddc8a68442536510aa2b85e

parent

6456a886695e6290fee373255fef014f47c20562

M src/gba/gba-audio.csrc/gba/gba-audio.c

@@ -20,6 +20,13 @@ static int _applyBias(struct GBAAudio* audio, int sample);

static void _sample(struct GBAAudio* audio); void GBAAudioInit(struct GBAAudio* audio) { + CircleBufferInit(&audio->left, GBA_AUDIO_SAMPLES * sizeof(int32_t)); + CircleBufferInit(&audio->right, GBA_AUDIO_SAMPLES * sizeof(int32_t)); + CircleBufferInit(&audio->chA.fifo, GBA_AUDIO_FIFO_SIZE); + CircleBufferInit(&audio->chB.fifo, GBA_AUDIO_FIFO_SIZE); +} + +void GBAAudioReset(struct GBAAudio* audio) { audio->nextEvent = 0; audio->nextCh1 = 0; audio->nextCh2 = 0;

@@ -49,10 +56,10 @@ audio->soundcntHi = 0;

audio->soundcntX = 0; audio->sampleInterval = GBA_ARM7TDMI_FREQUENCY / audio->sampleRate; - CircleBufferInit(&audio->left, GBA_AUDIO_SAMPLES * sizeof(int32_t)); - CircleBufferInit(&audio->right, GBA_AUDIO_SAMPLES * sizeof(int32_t)); - CircleBufferInit(&audio->chA.fifo, GBA_AUDIO_FIFO_SIZE); - CircleBufferInit(&audio->chB.fifo, GBA_AUDIO_FIFO_SIZE); + CircleBufferClear(&audio->left); + CircleBufferClear(&audio->right); + CircleBufferClear(&audio->chA.fifo); + CircleBufferClear(&audio->chB.fifo); } void GBAAudioDeinit(struct GBAAudio* audio) {
M src/gba/gba-audio.hsrc/gba/gba-audio.h

@@ -219,6 +219,7 @@ int16_t right;

}; void GBAAudioInit(struct GBAAudio* audio); +void GBAAudioReset(struct GBAAudio* audio); void GBAAudioDeinit(struct GBAAudio* audio); int32_t GBAAudioProcessEvents(struct GBAAudio* audio, int32_t cycles);
M src/gba/gba-memory.csrc/gba/gba-memory.c

@@ -102,7 +102,6 @@

if (!gba->memory.wram || !gba->memory.iwram) { GBAMemoryDeinit(gba); GBALog(gba, GBA_LOG_FATAL, "Could not map memory"); - return; } }
M src/gba/gba-video.csrc/gba/gba-video.c

@@ -9,6 +9,7 @@

#include "util/memory.h" static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer); +static void GBAVideoDummyRendererReset(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);

@@ -16,6 +17,7 @@ static void GBAVideoDummyRendererFinishFrame(struct GBAVideoRenderer* renderer);

static struct GBAVideoRenderer dummyRenderer = { .init = GBAVideoDummyRendererInit, + .reset = GBAVideoDummyRendererReset, .deinit = GBAVideoDummyRendererDeinit, .writeVideoRegister = GBAVideoDummyRendererWriteVideoRegister, .drawScanline = GBAVideoDummyRendererDrawScanline,

@@ -24,7 +26,10 @@ };

void GBAVideoInit(struct GBAVideo* video) { video->renderer = &dummyRenderer; + video->vram = 0; +} +void GBAVideoReset(struct GBAVideo* video) { video->inHblank = 0; video->inVblank = 0; video->vcounter = 0;

@@ -44,11 +49,18 @@ video->nextHblankIRQ = 0;

video->nextVblankIRQ = 0; video->nextVcounterIRQ = 0; + if (video->vram) { + mappedMemoryFree(video->vram, SIZE_VRAM); + } video->vram = anonymousMemoryMap(SIZE_VRAM); + video->renderer->vram = video->vram; int i; for (i = 0; i < 128; ++i) { - video->oam.obj[i].disable = 1; + video->oam.raw[i * 4] = 0x0200; + video->oam.raw[i * 4 + 1] = 0x0000; + video->oam.raw[i * 4 + 2] = 0x0000; + video->oam.raw[i * 4 + 3] = 0x0000; } }

@@ -157,6 +169,11 @@ }

} static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer) { + UNUSED(renderer); + // Nothing to do +} + +static void GBAVideoDummyRendererReset(struct GBAVideoRenderer* renderer) { UNUSED(renderer); // Nothing to do }
M src/gba/gba-video.hsrc/gba/gba-video.h

@@ -169,6 +169,7 @@ };

struct GBAVideoRenderer { void (*init)(struct GBAVideoRenderer* renderer); + void (*reset)(struct GBAVideoRenderer* renderer); void (*deinit)(struct GBAVideoRenderer* renderer); uint16_t (*writeVideoRegister)(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);

@@ -213,6 +214,7 @@ union GBAOAM oam;

}; void GBAVideoInit(struct GBAVideo* video); +void GBAVideoReset(struct GBAVideo* video); void GBAVideoDeinit(struct GBAVideo* video); void GBAVideoAssociateRenderer(struct GBAVideo* video, struct GBAVideoRenderer* renderer); int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles);
M src/gba/gba.csrc/gba/gba.c

@@ -182,6 +182,9 @@ cpu->gprs[ARM_SP] = SP_BASE_SYSTEM;

struct GBA* gba = (struct GBA*) cpu->master; GBAMemoryReset(gba); + GBAVideoReset(&gba->video); + GBAAudioReset(&gba->audio); + GBAIOInit(gba); } static void GBAProcessEvents(struct ARMCore* cpu) {
M src/gba/renderers/video-software.csrc/gba/renderers/video-software.c

@@ -60,6 +60,7 @@ static unsigned _mix(int weightA, unsigned colorA, int weightB, unsigned colorB);

void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer) { renderer->d.init = GBAVideoSoftwareRendererInit; + renderer->d.reset = GBAVideoSoftwareRendererInit; renderer->d.deinit = GBAVideoSoftwareRendererDeinit; renderer->d.writeVideoRegister = GBAVideoSoftwareRendererWriteVideoRegister; renderer->d.writeOAM = GBAVideoSoftwareRendererWriteOAM;