all repos — mgba @ cab1415d07e0711433844ee1c60976c65a83927d

mGBA Game Boy Advance Emulator

GB Core: Return the current number of banks for ROM/SRAM, not theoretical max
Vicki Pfau vi@endrift.com
Fri, 01 Jan 2021 17:12:38 -0800
commit

cab1415d07e0711433844ee1c60976c65a83927d

parent

bca8cb918fc0c6067da21ccef49db9a72e34377a

2 files changed, 26 insertions(+), 14 deletions(-)

jump to
M CHANGESCHANGES

@@ -96,6 +96,7 @@ - Core: Rework thread state synchronization

- Core: Improve support for ROM patch cheats, supporting disabling overlapping patches - GB: Allow pausing event loop while CPU is blocked - GB: Add support for sleep and shutdown callbacks + - GB Core: Return the current number of banks for ROM/SRAM, not theoretical max - GB I/O: Implement preliminary support for PCM12/PCM34 (closes mgba.io/i/1468) - GBA: Allow pausing event loop while CPU is blocked - GBA BIOS: Division by zero should emit a FATAL error
M src/gb/core.csrc/gb/core.c

@@ -75,6 +75,7 @@ struct mCPUComponent* components[CPU_COMPONENT_MAX];

const struct Configuration* overrides; struct mDebuggerPlatform* debuggerPlatform; struct mCheatDevice* cheatDevice; + struct mCoreMemoryBlock memoryBlocks[8]; }; static bool _GBCoreInit(struct mCore* core) {

@@ -96,6 +97,7 @@ gbcore->cheatDevice = NULL;

#ifndef MINIMAL_CORE gbcore->logContext = NULL; #endif + memcpy(gbcore->memoryBlocks, _GBMemoryBlocks, sizeof(_GBMemoryBlocks)); GBCreate(gb); memset(gbcore->components, 0, sizeof(gbcore->components));

@@ -559,6 +561,26 @@ }

} #endif + if (gb->model < GB_MODEL_CGB) { + memcpy(gbcore->memoryBlocks, _GBMemoryBlocks, sizeof(_GBMemoryBlocks)); + } else { + memcpy(gbcore->memoryBlocks, _GBCMemoryBlocks, sizeof(_GBCMemoryBlocks)); + } + + size_t i; + for (i = 0; i < sizeof(gbcore->memoryBlocks) / sizeof(*gbcore->memoryBlocks); ++i) { + if (gbcore->memoryBlocks[i].id == GB_REGION_CART_BANK0) { + gbcore->memoryBlocks[i].maxSegment = gb->memory.romSize / GB_SIZE_CART_BANK0; + } else if (gbcore->memoryBlocks[i].id == GB_REGION_EXTERNAL_RAM) { + gbcore->memoryBlocks[i].maxSegment = gb->sramSize / GB_SIZE_EXTERNAL_RAM; + } else { + continue; + } + if (gbcore->memoryBlocks[i].maxSegment) { + --gbcore->memoryBlocks[i].maxSegment; + } + } + SM83Reset(core->cpu); if (core->opts.skipBios) {

@@ -732,20 +754,9 @@ GBPatch8(cpu, address + 3, value >> 24, NULL, segment);

} size_t _GBListMemoryBlocks(const struct mCore* core, const struct mCoreMemoryBlock** blocks) { - const struct GB* gb = core->board; - switch (gb->model) { - case GB_MODEL_DMG: - case GB_MODEL_MGB: - case GB_MODEL_SGB: - case GB_MODEL_SGB2: - default: - *blocks = _GBMemoryBlocks; - return sizeof(_GBMemoryBlocks) / sizeof(*_GBMemoryBlocks); - case GB_MODEL_CGB: - case GB_MODEL_AGB: - *blocks = _GBCMemoryBlocks; - return sizeof(_GBCMemoryBlocks) / sizeof(*_GBCMemoryBlocks); - } + struct GBCore* gbcore = (struct GBCore*) core; + *blocks = gbcore->memoryBlocks; + return sizeof(gbcore->memoryBlocks) / sizeof(*gbcore->memoryBlocks); } void* _GBGetMemoryBlock(struct mCore* core, size_t id, size_t* sizeOut) {