GB Memory: Add segment parameter to GBPatch8

This commit is contained in:
Jeffrey Pfau 2016-09-16 18:17:29 -07:00
parent 1c9db6058c
commit 50466642ad
4 changed files with 35 additions and 17 deletions

View File

@ -28,7 +28,7 @@ static void _patchROM(struct mCheatDevice* device, struct GBCheatSet* cheats) {
continue;
}
}
GBPatch8(device->p->cpu, patch->address, patch->newValue, &patch->oldValue);
GBPatch8(device->p->cpu, patch->address, patch->newValue, &patch->oldValue, 0);
patch->applied = true;
}
}
@ -43,7 +43,7 @@ static void _unpatchROM(struct mCheatDevice* device, struct GBCheatSet* cheats)
if (!patch->applied) {
continue;
}
GBPatch8(device->p->cpu, patch->address, patch->oldValue, &patch->newValue);
GBPatch8(device->p->cpu, patch->address, patch->oldValue, &patch->newValue, 0);
patch->applied = false;
}
}

View File

@ -385,21 +385,21 @@ static uint32_t _GBCoreRawRead32(struct mCore* core, uint32_t address, int segme
static void _GBCoreRawWrite8(struct mCore* core, uint32_t address, int segment, uint8_t value) {
struct LR35902Core* cpu = core->cpu;
GBPatch8(cpu, address, value, NULL);
GBPatch8(cpu, address, value, NULL, segment);
}
static void _GBCoreRawWrite16(struct mCore* core, uint32_t address, int segment, uint16_t value) {
struct LR35902Core* cpu = core->cpu;
GBPatch8(cpu, address, value, NULL);
GBPatch8(cpu, address + 1, value >> 8, NULL);
GBPatch8(cpu, address, value, NULL, segment);
GBPatch8(cpu, address + 1, value >> 8, NULL, segment);
}
static void _GBCoreRawWrite32(struct mCore* core, uint32_t address, int segment, uint32_t value) {
struct LR35902Core* cpu = core->cpu;
GBPatch8(cpu, address, value, NULL);
GBPatch8(cpu, address + 1, value >> 8, NULL);
GBPatch8(cpu, address + 2, value >> 16, NULL);
GBPatch8(cpu, address + 3, value >> 24, NULL);
GBPatch8(cpu, address, value, NULL, segment);
GBPatch8(cpu, address + 1, value >> 8, NULL, segment);
GBPatch8(cpu, address + 2, value >> 16, NULL, segment);
GBPatch8(cpu, address + 3, value >> 24, NULL, segment);
}
static bool _GBCoreSupportsDebuggerType(struct mCore* core, enum mDebuggerType type) {

View File

@ -478,7 +478,7 @@ void GBDMAStore8(struct LR35902Core* cpu, uint16_t address, int8_t value) {
GBStore8(cpu, address, value);
}
void GBPatch8(struct LR35902Core* cpu, uint16_t address, int8_t value, int8_t* old) {
void GBPatch8(struct LR35902Core* cpu, uint16_t address, int8_t value, int8_t* old, int segment) {
struct GB* gb = (struct GB*) cpu->master;
struct GBMemory* memory = &gb->memory;
int8_t oldValue = -1;
@ -497,13 +497,26 @@ void GBPatch8(struct LR35902Core* cpu, uint16_t address, int8_t value, int8_t* o
case GB_REGION_CART_BANK1 + 2:
case GB_REGION_CART_BANK1 + 3:
_pristineCow(gb);
oldValue = memory->romBank[address & (GB_SIZE_CART_BANK0 - 1)];
memory->romBank[address & (GB_SIZE_CART_BANK0 - 1)] = value;
if (segment < 0) {
oldValue = memory->romBank[address & (GB_SIZE_CART_BANK0 - 1)];
memory->romBank[address & (GB_SIZE_CART_BANK0 - 1)] = value;
} else {
if ((size_t) segment * GB_SIZE_CART_BANK0 > memory->romSize) {
return;
}
oldValue = memory->rom[(address & (GB_SIZE_CART_BANK0 - 1)) + segment * GB_SIZE_CART_BANK0];
memory->rom[(address & (GB_SIZE_CART_BANK0 - 1)) + segment * GB_SIZE_CART_BANK0] = value;
}
break;
case GB_REGION_VRAM:
case GB_REGION_VRAM + 1:
oldValue = gb->video.vramBank[address & (GB_SIZE_VRAM_BANK0 - 1)];
gb->video.vramBank[address & (GB_SIZE_VRAM_BANK0 - 1)] = value;
if (segment < 0) {
oldValue = gb->video.vramBank[address & (GB_SIZE_VRAM_BANK0 - 1)];
gb->video.vramBank[address & (GB_SIZE_VRAM_BANK0 - 1)] = value;
} else {
oldValue = gb->video.vram[(address & (GB_SIZE_VRAM_BANK0 - 1)) + segment * GB_SIZE_VRAM_BANK0];
gb->video.vramBank[(address & (GB_SIZE_VRAM_BANK0 - 1)) + segment * GB_SIZE_VRAM_BANK0] = value;
}
break;
case GB_REGION_EXTERNAL_RAM:
case GB_REGION_EXTERNAL_RAM + 1:
@ -515,8 +528,13 @@ void GBPatch8(struct LR35902Core* cpu, uint16_t address, int8_t value, int8_t* o
memory->wram[address & (GB_SIZE_WORKING_RAM_BANK0 - 1)] = value;
break;
case GB_REGION_WORKING_RAM_BANK1:
oldValue = memory->wramBank[address & (GB_SIZE_WORKING_RAM_BANK0 - 1)];
memory->wramBank[address & (GB_SIZE_WORKING_RAM_BANK0 - 1)] = value;
if (segment < 0) {
oldValue = memory->wramBank[address & (GB_SIZE_WORKING_RAM_BANK0 - 1)];
memory->wramBank[address & (GB_SIZE_WORKING_RAM_BANK0 - 1)] = value;
} else {
oldValue = memory->wram[(address & (GB_SIZE_WORKING_RAM_BANK0 - 1)) + segment * GB_SIZE_WORKING_RAM_BANK0];
memory->wram[(address & (GB_SIZE_WORKING_RAM_BANK0 - 1)) + segment * GB_SIZE_WORKING_RAM_BANK0] = value;
}
break;
default:
if (address < GB_BASE_OAM) {

View File

@ -166,7 +166,7 @@ void GBMemoryWriteHDMA5(struct GB* gb, uint8_t value);
uint8_t GBDMALoad8(struct LR35902Core* cpu, uint16_t address);
void GBDMAStore8(struct LR35902Core* cpu, uint16_t address, int8_t value);
void GBPatch8(struct LR35902Core* cpu, uint16_t address, int8_t value, int8_t* old);
void GBPatch8(struct LR35902Core* cpu, uint16_t address, int8_t value, int8_t* old, int segment);
struct GBSerializedState;
void GBMemorySerialize(const struct GB* gb, struct GBSerializedState* state);