From dc263295dd58f6b03726767220f9b401a53a971c Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 17 Nov 2024 03:34:33 -0800 Subject: [PATCH] GBA Memory: Add unlicensed cart write handling stub --- include/mgba/internal/gba/cart/unlicensed.h | 1 + src/gba/cart/unlicensed.c | 13 +++++++++++++ src/gba/memory.c | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/include/mgba/internal/gba/cart/unlicensed.h b/include/mgba/internal/gba/cart/unlicensed.h index ec13abb55..816aa1dfd 100644 --- a/include/mgba/internal/gba/cart/unlicensed.h +++ b/include/mgba/internal/gba/cart/unlicensed.h @@ -60,6 +60,7 @@ void GBAUnlCartReset(struct GBA*); void GBAUnlCartUnload(struct GBA*); void GBAUnlCartDetect(struct GBA*); void GBAUnlCartWriteSRAM(struct GBA*, uint32_t address, uint8_t value); +void GBAUnlCartWriteROM(struct GBA*, uint32_t address, uint16_t value); struct GBASerializedState; void GBAUnlCartSerialize(const struct GBA* gba, struct GBASerializedState* state); diff --git a/src/gba/cart/unlicensed.c b/src/gba/cart/unlicensed.c index 318ffe891..442ec9865 100644 --- a/src/gba/cart/unlicensed.c +++ b/src/gba/cart/unlicensed.c @@ -126,6 +126,19 @@ void GBAUnlCartWriteSRAM(struct GBA* gba, uint32_t address, uint8_t value) { gba->memory.savedata.data[address & (GBA_SIZE_SRAM - 1)] = value; } +void GBAUnlCartWriteROM(struct GBA* gba, uint32_t address, uint16_t value) { + struct GBAUnlCart* unl = &gba->memory.unl; + + switch (unl->type) { + case GBA_UNL_CART_VFAME: + case GBA_UNL_CART_NONE: + break; + case GBA_UNL_CART_MULTICART: + mLOG(GBA_MEM, STUB, "Unimplemented writing to ROM %07X:%04X", address, value); + break; + } +} + static void _multicartSettle(struct mTiming* timing, void* context, uint32_t cyclesLate) { UNUSED(timing); UNUSED(cyclesLate); diff --git a/src/gba/memory.c b/src/gba/memory.c index 53d0f7cc9..1561aef91 100644 --- a/src/gba/memory.c +++ b/src/gba/memory.c @@ -963,6 +963,10 @@ void GBAStore16(struct ARMCore* cpu, uint32_t address, int16_t value, int* cycle break; } } + if (memory->unl.type) { + GBAUnlCartWriteROM(gba, address & (GBA_SIZE_ROM0 - 1), value); + break; + } mLOG(GBA_MEM, GAME_ERROR, "Bad cartridge Store16: 0x%08X", address); break; case GBA_REGION_ROM2_EX: