Skip to content

Commit

Permalink
Changes needed for GSF playback MINIMAL_CORE=3
Browse files Browse the repository at this point in the history
Note: This removes the MINIMAL_CORE check on creating the output mixer,
because GSF playback obviously requires the audio mixer.
  • Loading branch information
kode54 committed Jan 20, 2022
1 parent 5064242 commit 183a2e5
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/mgba/internal/gba/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ struct GBAMemory {
struct GBASavedata savedata;
struct GBAVFameCart vfame;
struct GBAMatrix matrix;
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
struct GBACartEReader ereader;
#endif
size_t romSize;
uint32_t romMask;
uint16_t romID;
Expand Down
4 changes: 4 additions & 0 deletions src/core/serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ bool mCoreExtractExtdata(struct mCore* core, struct VFile* vf, struct mStateExtd
}

bool mCoreLoadStateNamed(struct mCore* core, struct VFile* vf, int flags) {
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
struct mStateExtdata extdata;
mStateExtdataInit(&extdata);
void* state = mCoreExtractState(core, vf, &extdata);
Expand Down Expand Up @@ -549,5 +550,8 @@ bool mCoreLoadStateNamed(struct mCore* core, struct VFile* vf, int flags) {
}
mStateExtdataDeinit(&extdata);
return success;
#else
return true;
#endif
}

18 changes: 16 additions & 2 deletions src/gba/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@ struct GBACore {
struct mCPUComponent* components[CPU_COMPONENT_MAX];
const struct Configuration* overrides;
struct mDebuggerPlatform* debuggerPlatform;
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
struct mCheatDevice* cheatDevice;
#endif
struct GBAAudioMixer* audioMixer;
};

Expand All @@ -171,7 +173,9 @@ static bool _GBACoreInit(struct mCore* core) {
core->videoLogger = NULL;
gbacore->overrides = NULL;
gbacore->debuggerPlatform = NULL;
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
gbacore->cheatDevice = NULL;
#endif
#ifndef MINIMAL_CORE
gbacore->logContext = NULL;
#endif
Expand All @@ -188,8 +192,10 @@ static bool _GBACoreInit(struct mCore* core) {
GBAVideoDummyRendererCreate(&gbacore->dummyRenderer);
GBAVideoAssociateRenderer(&gba->video, &gbacore->dummyRenderer);

#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
GBAVideoSoftwareRendererCreate(&gbacore->renderer);
gbacore->renderer.outputBuffer = NULL;
#endif

#ifdef BUILD_GLES3
GBAVideoGLRendererCreate(&gbacore->glRenderer);
Expand Down Expand Up @@ -227,9 +233,11 @@ static void _GBACoreDeinit(struct mCore* core) {

struct GBACore* gbacore = (struct GBACore*) core;
free(gbacore->debuggerPlatform);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if (gbacore->cheatDevice) {
mCheatDeviceDestroy(gbacore->cheatDevice);
}
#endif
free(gbacore->audioMixer);
mCoreConfigFreeOpts(&core->opts);
free(core);
Expand Down Expand Up @@ -529,12 +537,14 @@ static bool _GBACoreLoadPatch(struct mCore* core, struct VFile* vf) {
static void _GBACoreUnloadROM(struct mCore* core) {
struct GBACore* gbacore = (struct GBACore*) core;
struct ARMCore* cpu = core->cpu;
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if (gbacore->cheatDevice) {
ARMHotplugDetach(cpu, CPU_COMPONENT_CHEAT_DEVICE);
cpu->components[CPU_COMPONENT_CHEAT_DEVICE] = NULL;
mCheatDeviceDestroy(gbacore->cheatDevice);
gbacore->cheatDevice = NULL;
}
#endif
return GBAUnloadROM(core->board);
}

Expand All @@ -553,6 +563,7 @@ static void _GBACoreReset(struct mCore* core) {
struct GBA* gba = (struct GBA*) core->board;
bool value;
UNUSED(value);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if (gbacore->renderer.outputBuffer
#ifdef BUILD_GLES3
|| gbacore->glRenderer.outputTex != (unsigned) -1
Expand Down Expand Up @@ -588,16 +599,15 @@ static void _GBACoreReset(struct mCore* core) {
GBAVideoAssociateRenderer(&gba->video, renderer);
}
}
#endif

#ifndef MINIMAL_CORE
int useAudioMixer;
if (!gbacore->audioMixer && mCoreConfigGetIntValue(&core->config, "gba.audioHle", &useAudioMixer) && useAudioMixer) {
gbacore->audioMixer = malloc(sizeof(*gbacore->audioMixer));
GBAAudioMixerCreate(gbacore->audioMixer);
((struct ARMCore*) core->cpu)->components[CPU_COMPONENT_AUDIO_MIXER] = &gbacore->audioMixer->d;
ARMHotplugAttach(core->cpu, CPU_COMPONENT_AUDIO_MIXER);
}
#endif

bool forceGbp = false;
bool vbaBugCompat = true;
Expand Down Expand Up @@ -973,6 +983,7 @@ static bool _GBACoreLookupIdentifier(struct mCore* core, const char* name, int32
#endif

static struct mCheatDevice* _GBACoreCheatDevice(struct mCore* core) {
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
struct GBACore* gbacore = (struct GBACore*) core;
if (!gbacore->cheatDevice) {
gbacore->cheatDevice = GBACheatDeviceCreate();
Expand All @@ -981,6 +992,9 @@ static struct mCheatDevice* _GBACoreCheatDevice(struct mCore* core) {
gbacore->cheatDevice->p = core;
}
return gbacore->cheatDevice;
#else
return NULL;
#endif
}

static size_t _GBACoreSavedataClone(struct mCore* core, void** sram) {
Expand Down
4 changes: 4 additions & 0 deletions src/gba/gba.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ void GBABreakpoint(struct ARMCore* cpu, int immediate) {
break;
#endif
case CPU_COMPONENT_CHEAT_DEVICE:
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if (gba->cpu->components[CPU_COMPONENT_CHEAT_DEVICE]) {
struct mCheatDevice* device = (struct mCheatDevice*) gba->cpu->components[CPU_COMPONENT_CHEAT_DEVICE];
struct GBACheatHook* hook = 0;
Expand All @@ -817,6 +818,7 @@ void GBABreakpoint(struct ARMCore* cpu, int immediate) {
ARMRunFake(cpu, hook->patchedOpcode);
}
}
#endif
break;
default:
break;
Expand All @@ -843,6 +845,7 @@ void GBAFrameEnded(struct GBA* gba) {
int wasDirty = gba->memory.savedata.dirty;
GBASavedataClean(&gba->memory.savedata, gba->video.frameCounter);

#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if (gba->cpu->components && gba->cpu->components[CPU_COMPONENT_CHEAT_DEVICE]) {
struct mCheatDevice* device = (struct mCheatDevice*) gba->cpu->components[CPU_COMPONENT_CHEAT_DEVICE];
size_t i;
Expand All @@ -853,6 +856,7 @@ void GBAFrameEnded(struct GBA* gba) {
}
}
}
#endif

if (gba->stream && gba->stream->postVideoFrame) {
const color_t* pixels;
Expand Down
21 changes: 18 additions & 3 deletions src/gba/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ void GBAMemoryInit(struct GBA* gba) {
GBADMAInit(gba);
GBAVFameInit(&gba->memory.vfame);

#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
gba->memory.ereader.p = gba;
gba->memory.ereader.dots = NULL;
memset(gba->memory.ereader.cards, 0, sizeof(gba->memory.ereader.cards));
#endif
}

void GBAMemoryDeinit(struct GBA* gba) {
Expand All @@ -112,7 +114,9 @@ void GBAMemoryDeinit(struct GBA* gba) {
mappedMemoryFree(gba->memory.agbPrintBufferBackup, SIZE_AGB_PRINT);
}

#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
GBACartEReaderDeinit(&gba->memory.ereader);
#endif
}

void GBAMemoryReset(struct GBA* gba) {
Expand Down Expand Up @@ -599,8 +603,10 @@ uint32_t GBALoad16(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
wait = memory->waitstatesNonseq16[address >> BASE_OFFSET];
if (memory->savedata.type == SAVEDATA_EEPROM || memory->savedata.type == SAVEDATA_EEPROM512) {
value = GBASavedataReadEEPROM(&memory->savedata);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
} else if ((address & 0x0DFC0000) >= 0x0DF80000 && memory->hw.devices & HW_EREADER) {
value = GBACartEReaderRead(&memory->ereader, address);
#endif
} else if ((address & (SIZE_CART0 - 1)) < memory->romSize) {
LOAD_16(value, address & (SIZE_CART0 - 2), memory->rom);
} else if (memory->mirroring && (address & memory->romMask) < memory->romSize) {
Expand Down Expand Up @@ -715,9 +721,12 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
if (gba->performingDMA == 1) {
break;
}
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if (memory->hw.devices & HW_EREADER && (address & 0xE00FF80) >= 0xE00FF80) {
value = GBACartEReaderReadFlash(&memory->ereader, address);
} else if (memory->savedata.type == SAVEDATA_SRAM) {
} else
#endif
if (memory->savedata.type == SAVEDATA_SRAM) {
value = memory->savedata.data[address & (SIZE_CART_SRAM - 1)];
} else if (memory->savedata.type == SAVEDATA_FLASH512 || memory->savedata.type == SAVEDATA_FLASH1M) {
value = GBASavedataReadFlash(&memory->savedata, address);
Expand Down Expand Up @@ -978,10 +987,13 @@ void GBAStore16(struct ARMCore* cpu, uint32_t address, int16_t value, int* cycle
mLOG(GBA_MEM, GAME_ERROR, "Bad cartridge Store16: 0x%08X", address);
break;
case REGION_CART2_EX:
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if ((address & 0x0DFC0000) >= 0x0DF80000 && memory->hw.devices & HW_EREADER) {
GBACartEReaderWrite(&memory->ereader, address, value);
break;
} else if (memory->savedata.type == SAVEDATA_AUTODETECT) {
} else
#endif
if (memory->savedata.type == SAVEDATA_AUTODETECT) {
mLOG(GBA_MEM, INFO, "Detected EEPROM savegame");
GBASavedataInitEEPROM(&memory->savedata);
}
Expand Down Expand Up @@ -1065,9 +1077,12 @@ void GBAStore8(struct ARMCore* cpu, uint32_t address, int8_t value, int* cycleCo
GBASavedataInitSRAM(&memory->savedata);
}
}
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if (memory->hw.devices & HW_EREADER && (address & 0xE00FF80) >= 0xE00FF80) {
GBACartEReaderWriteFlash(&memory->ereader, address, value);
} else if (memory->savedata.type == SAVEDATA_FLASH512 || memory->savedata.type == SAVEDATA_FLASH1M) {
} else
#endif
if (memory->savedata.type == SAVEDATA_FLASH512 || memory->savedata.type == SAVEDATA_FLASH1M) {
GBASavedataWriteFlash(&memory->savedata, address, value);
} else if (memory->savedata.type == SAVEDATA_SRAM) {
if (memory->vfame.cartType) {
Expand Down
2 changes: 2 additions & 0 deletions src/gba/overrides.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,11 @@ void GBAOverrideApply(struct GBA* gba, const struct GBACartridgeOverride* overri
GBAHardwareInitTilt(&gba->memory.hw);
}

#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if (override->hardware & HW_EREADER) {
GBACartEReaderInit(&gba->memory.ereader);
}
#endif

if (override->hardware & HW_GB_PLAYER_DETECTION) {
gba->memory.hw.devices |= HW_GB_PLAYER_DETECTION;
Expand Down
6 changes: 6 additions & 0 deletions src/gba/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,11 @@ static void GBAVideoDummyRendererDeinit(struct GBAVideoRenderer* renderer) {
}

static uint16_t GBAVideoDummyRendererWriteVideoRegister(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value) {
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if (renderer->cache) {
GBAVideoCacheWriteVideoRegister(renderer->cache, address, value);
}
#endif
switch (address) {
case REG_DISPCNT:
value &= 0xFFF7;
Expand Down Expand Up @@ -291,15 +293,19 @@ static uint16_t GBAVideoDummyRendererWriteVideoRegister(struct GBAVideoRenderer*
}

static void GBAVideoDummyRendererWriteVRAM(struct GBAVideoRenderer* renderer, uint32_t address) {
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if (renderer->cache) {
mCacheSetWriteVRAM(renderer->cache, address);
}
#endif
}

static void GBAVideoDummyRendererWritePalette(struct GBAVideoRenderer* renderer, uint32_t address, uint16_t value) {
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
if (renderer->cache) {
mCacheSetWritePalette(renderer->cache, address >> 1, mColorFrom555(value));
}
#endif
}

static void GBAVideoDummyRendererWriteOAM(struct GBAVideoRenderer* renderer, uint32_t oam) {
Expand Down
2 changes: 2 additions & 0 deletions src/util/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ char* utf16to8(const uint16_t* utf16, size_t length) {
return newUTF8;
}

#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 3
extern const uint16_t gbkUnicodeTable[];

char* gbkToUtf8(const char* gbk, size_t length) {
Expand Down Expand Up @@ -340,6 +341,7 @@ char* gbkToUtf8(const char* gbk, size_t length) {
newUTF8[utf8Length] = '\0';
return newUTF8;
}
#endif

int hexDigit(char digit) {
switch (digit) {
Expand Down

0 comments on commit 183a2e5

Please sign in to comment.