mirror of https://github.com/mgba-emu/mgba.git
Be more rigorous when reseting
This commit is contained in:
parent
6456a88669
commit
3202811e41
|
@ -20,6 +20,13 @@ static int _applyBias(struct GBAAudio* audio, int sample);
|
||||||
static void _sample(struct GBAAudio* audio);
|
static void _sample(struct GBAAudio* audio);
|
||||||
|
|
||||||
void GBAAudioInit(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->nextEvent = 0;
|
||||||
audio->nextCh1 = 0;
|
audio->nextCh1 = 0;
|
||||||
audio->nextCh2 = 0;
|
audio->nextCh2 = 0;
|
||||||
|
@ -49,10 +56,10 @@ void GBAAudioInit(struct GBAAudio* audio) {
|
||||||
audio->soundcntX = 0;
|
audio->soundcntX = 0;
|
||||||
audio->sampleInterval = GBA_ARM7TDMI_FREQUENCY / audio->sampleRate;
|
audio->sampleInterval = GBA_ARM7TDMI_FREQUENCY / audio->sampleRate;
|
||||||
|
|
||||||
CircleBufferInit(&audio->left, GBA_AUDIO_SAMPLES * sizeof(int32_t));
|
CircleBufferClear(&audio->left);
|
||||||
CircleBufferInit(&audio->right, GBA_AUDIO_SAMPLES * sizeof(int32_t));
|
CircleBufferClear(&audio->right);
|
||||||
CircleBufferInit(&audio->chA.fifo, GBA_AUDIO_FIFO_SIZE);
|
CircleBufferClear(&audio->chA.fifo);
|
||||||
CircleBufferInit(&audio->chB.fifo, GBA_AUDIO_FIFO_SIZE);
|
CircleBufferClear(&audio->chB.fifo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GBAAudioDeinit(struct GBAAudio* audio) {
|
void GBAAudioDeinit(struct GBAAudio* audio) {
|
||||||
|
|
|
@ -219,6 +219,7 @@ struct GBAStereoSample {
|
||||||
};
|
};
|
||||||
|
|
||||||
void GBAAudioInit(struct GBAAudio* audio);
|
void GBAAudioInit(struct GBAAudio* audio);
|
||||||
|
void GBAAudioReset(struct GBAAudio* audio);
|
||||||
void GBAAudioDeinit(struct GBAAudio* audio);
|
void GBAAudioDeinit(struct GBAAudio* audio);
|
||||||
|
|
||||||
int32_t GBAAudioProcessEvents(struct GBAAudio* audio, int32_t cycles);
|
int32_t GBAAudioProcessEvents(struct GBAAudio* audio, int32_t cycles);
|
||||||
|
|
|
@ -102,7 +102,6 @@ void GBAMemoryReset(struct GBA* gba) {
|
||||||
if (!gba->memory.wram || !gba->memory.iwram) {
|
if (!gba->memory.wram || !gba->memory.iwram) {
|
||||||
GBAMemoryDeinit(gba);
|
GBAMemoryDeinit(gba);
|
||||||
GBALog(gba, GBA_LOG_FATAL, "Could not map memory");
|
GBALog(gba, GBA_LOG_FATAL, "Could not map memory");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "util/memory.h"
|
#include "util/memory.h"
|
||||||
|
|
||||||
static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer);
|
static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer);
|
||||||
|
static void GBAVideoDummyRendererReset(struct GBAVideoRenderer* renderer);
|
||||||
static void GBAVideoDummyRendererDeinit(struct GBAVideoRenderer* renderer);
|
static void GBAVideoDummyRendererDeinit(struct GBAVideoRenderer* renderer);
|
||||||
static uint16_t GBAVideoDummyRendererWriteVideoRegister(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
static uint16_t GBAVideoDummyRendererWriteVideoRegister(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
||||||
static void GBAVideoDummyRendererDrawScanline(struct GBAVideoRenderer* renderer, int y);
|
static void GBAVideoDummyRendererDrawScanline(struct GBAVideoRenderer* renderer, int y);
|
||||||
|
@ -16,6 +17,7 @@ static void GBAVideoDummyRendererFinishFrame(struct GBAVideoRenderer* renderer);
|
||||||
|
|
||||||
static struct GBAVideoRenderer dummyRenderer = {
|
static struct GBAVideoRenderer dummyRenderer = {
|
||||||
.init = GBAVideoDummyRendererInit,
|
.init = GBAVideoDummyRendererInit,
|
||||||
|
.reset = GBAVideoDummyRendererReset,
|
||||||
.deinit = GBAVideoDummyRendererDeinit,
|
.deinit = GBAVideoDummyRendererDeinit,
|
||||||
.writeVideoRegister = GBAVideoDummyRendererWriteVideoRegister,
|
.writeVideoRegister = GBAVideoDummyRendererWriteVideoRegister,
|
||||||
.drawScanline = GBAVideoDummyRendererDrawScanline,
|
.drawScanline = GBAVideoDummyRendererDrawScanline,
|
||||||
|
@ -24,7 +26,10 @@ static struct GBAVideoRenderer dummyRenderer = {
|
||||||
|
|
||||||
void GBAVideoInit(struct GBAVideo* video) {
|
void GBAVideoInit(struct GBAVideo* video) {
|
||||||
video->renderer = &dummyRenderer;
|
video->renderer = &dummyRenderer;
|
||||||
|
video->vram = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GBAVideoReset(struct GBAVideo* video) {
|
||||||
video->inHblank = 0;
|
video->inHblank = 0;
|
||||||
video->inVblank = 0;
|
video->inVblank = 0;
|
||||||
video->vcounter = 0;
|
video->vcounter = 0;
|
||||||
|
@ -44,11 +49,18 @@ void GBAVideoInit(struct GBAVideo* video) {
|
||||||
video->nextVblankIRQ = 0;
|
video->nextVblankIRQ = 0;
|
||||||
video->nextVcounterIRQ = 0;
|
video->nextVcounterIRQ = 0;
|
||||||
|
|
||||||
|
if (video->vram) {
|
||||||
|
mappedMemoryFree(video->vram, SIZE_VRAM);
|
||||||
|
}
|
||||||
video->vram = anonymousMemoryMap(SIZE_VRAM);
|
video->vram = anonymousMemoryMap(SIZE_VRAM);
|
||||||
|
video->renderer->vram = video->vram;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < 128; ++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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +173,11 @@ static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer) {
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void GBAVideoDummyRendererReset(struct GBAVideoRenderer* renderer) {
|
||||||
|
UNUSED(renderer);
|
||||||
|
// Nothing to do
|
||||||
|
}
|
||||||
|
|
||||||
static void GBAVideoDummyRendererDeinit(struct GBAVideoRenderer* renderer) {
|
static void GBAVideoDummyRendererDeinit(struct GBAVideoRenderer* renderer) {
|
||||||
UNUSED(renderer);
|
UNUSED(renderer);
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
|
|
|
@ -169,6 +169,7 @@ union GBARegisterBGCNT {
|
||||||
|
|
||||||
struct GBAVideoRenderer {
|
struct GBAVideoRenderer {
|
||||||
void (*init)(struct GBAVideoRenderer* renderer);
|
void (*init)(struct GBAVideoRenderer* renderer);
|
||||||
|
void (*reset)(struct GBAVideoRenderer* renderer);
|
||||||
void (*deinit)(struct GBAVideoRenderer* renderer);
|
void (*deinit)(struct GBAVideoRenderer* renderer);
|
||||||
|
|
||||||
uint16_t (*writeVideoRegister)(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
uint16_t (*writeVideoRegister)(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value);
|
||||||
|
@ -213,6 +214,7 @@ struct GBAVideo {
|
||||||
};
|
};
|
||||||
|
|
||||||
void GBAVideoInit(struct GBAVideo* video);
|
void GBAVideoInit(struct GBAVideo* video);
|
||||||
|
void GBAVideoReset(struct GBAVideo* video);
|
||||||
void GBAVideoDeinit(struct GBAVideo* video);
|
void GBAVideoDeinit(struct GBAVideo* video);
|
||||||
void GBAVideoAssociateRenderer(struct GBAVideo* video, struct GBAVideoRenderer* renderer);
|
void GBAVideoAssociateRenderer(struct GBAVideo* video, struct GBAVideoRenderer* renderer);
|
||||||
int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles);
|
int32_t GBAVideoProcessEvents(struct GBAVideo* video, int32_t cycles);
|
||||||
|
|
|
@ -182,6 +182,9 @@ void GBAReset(struct ARMCore* cpu) {
|
||||||
|
|
||||||
struct GBA* gba = (struct GBA*) cpu->master;
|
struct GBA* gba = (struct GBA*) cpu->master;
|
||||||
GBAMemoryReset(gba);
|
GBAMemoryReset(gba);
|
||||||
|
GBAVideoReset(&gba->video);
|
||||||
|
GBAAudioReset(&gba->audio);
|
||||||
|
GBAIOInit(gba);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void GBAProcessEvents(struct ARMCore* cpu) {
|
static void GBAProcessEvents(struct ARMCore* cpu) {
|
||||||
|
|
|
@ -60,6 +60,7 @@ static unsigned _mix(int weightA, unsigned colorA, int weightB, unsigned colorB)
|
||||||
|
|
||||||
void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer) {
|
void GBAVideoSoftwareRendererCreate(struct GBAVideoSoftwareRenderer* renderer) {
|
||||||
renderer->d.init = GBAVideoSoftwareRendererInit;
|
renderer->d.init = GBAVideoSoftwareRendererInit;
|
||||||
|
renderer->d.reset = GBAVideoSoftwareRendererInit;
|
||||||
renderer->d.deinit = GBAVideoSoftwareRendererDeinit;
|
renderer->d.deinit = GBAVideoSoftwareRendererDeinit;
|
||||||
renderer->d.writeVideoRegister = GBAVideoSoftwareRendererWriteVideoRegister;
|
renderer->d.writeVideoRegister = GBAVideoSoftwareRendererWriteVideoRegister;
|
||||||
renderer->d.writeOAM = GBAVideoSoftwareRendererWriteOAM;
|
renderer->d.writeOAM = GBAVideoSoftwareRendererWriteOAM;
|
||||||
|
|
Loading…
Reference in New Issue