Skip to content

Commit

Permalink
Only redirect ROM read of dynamic area to MBC (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
kremi151 committed Dec 29, 2020
1 parent d1499c3 commit 94f99a3
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions core/source/memory/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,13 @@ case 0x ## x ## 0: case 0x ## x ## 1: case 0x ## x ## 2: case 0x ## x ## 3: case
case 0x ## x ## 6: case 0x ## x ## 7: case 0x ## x ## 8: case 0x ## x ## 9: case 0x ## x ## A: case 0x ## x ## B: \
case 0x ## x ## C: case 0x ## x ## D: case 0x ## x ## E: case 0x ## x ## F

#define FB_MEMORY_CARTRIDGE \
#define FB_MEMORY_CARTRIDGE_FIXED \
FB_MEMORY_NIBBLE_RANGE(0): \
FB_MEMORY_NIBBLE_RANGE(1): \
FB_MEMORY_NIBBLE_RANGE(2): \
FB_MEMORY_NIBBLE_RANGE(3): \
FB_MEMORY_NIBBLE_RANGE(3)

#define FB_MEMORY_CARTRIDGE_DYNAMIC \
FB_MEMORY_NIBBLE_RANGE(4): \
FB_MEMORY_NIBBLE_RANGE(5): \
FB_MEMORY_NIBBLE_RANGE(6): \
Expand Down Expand Up @@ -272,7 +274,9 @@ case 0xFF

u8 Memory::read8BitsAt(memory_address offset) {
switch ((offset >> 8) & 0xff) {
FB_MEMORY_CARTRIDGE:
FB_MEMORY_CARTRIDGE_FIXED:
return *(rom + offset);
FB_MEMORY_CARTRIDGE_DYNAMIC:
return mbc->readFromROMAt(offset, rom);
FB_MEMORY_VRAM:
return ppuMemory.isVRAMAccessibleFromMMU()
Expand Down Expand Up @@ -325,7 +329,8 @@ i8 Memory::readSigned8BitsAt(memory_address offset) {

void Memory::write8BitsTo(memory_address offset, u8 val) {
switch ((offset >> 8) & 0xff) {
FB_MEMORY_CARTRIDGE:
FB_MEMORY_CARTRIDGE_FIXED:
FB_MEMORY_CARTRIDGE_DYNAMIC:
// Writing to read-only area, so we let it intercept by the MBC
mbc->interceptROMWrite(offset, val);
break;
Expand Down

0 comments on commit 94f99a3

Please sign in to comment.