refactor memory mapping

This commit is contained in:
Colby 2016-07-20 14:21:24 +10:00
parent a68e9339d8
commit 346b4ae443

View file

@ -35,22 +35,21 @@ module Waterfoul
raise MemoryOutOfBounds if i > MEMORY_SIZE || i < 0 raise MemoryOutOfBounds if i > MEMORY_SIZE || i < 0
case i case i
when 0x0000..0x7FFF when 0x0000...0x8000 # ROM Bank 0 + n
if @map_boot_rom && i <= BOOT_ROM_END_MEM_LOC if @map_boot_rom && i <= BOOT_ROM_END_MEM_LOC
BootROM[i] BootROM[i]
else else
@cartridge[i] @cartridge[i]
end end
when 0x8000..0xDFFF when 0x8000...0xA000 # Video RAM
# Working RAM
@memory[i] @memory[i]
when 0xA000..0xBFFF when 0xA000...0xC000 # RAM Bank
@cartridge[i] @cartridge[i]
when 0xE000..0xFDFF when 0xC000...0xE000 # Internal RAM
# Working RAM (shadow) @memory[i]
when 0xE000...0xFE00 # Internal RAM (shadow)
@memory[i - 0x1000] @memory[i - 0x1000]
when 0xFE00..0xFFFF when 0xFE00..0xFFFF # Graphics (OAM), IO, Zero-page
# Graphics, IO, Zero-page
@memory[i] @memory[i]
end end
end end
@ -65,16 +64,23 @@ module Waterfoul
unless options[:hardware_operation] unless options[:hardware_operation]
case i case i
when UNMAP_BOOT_ROM_MEM_LOC when UNMAP_BOOT_ROM_MEM_LOC # unmap the boot rom when 0xFF50 is wrtiten to in memory
# unmap the boot rom when 0xFF50 is wrtiten to in memory
@map_boot_rom = false if v == 0x1 && @map_boot_rom @map_boot_rom = false if v == 0x1 && @map_boot_rom
when 0x0..0x7FFF
@cartridge[i] = v
when 0xFF46 # DMA transfer when 0xFF46 # DMA transfer
dma_transfer v dma_transfer v
when 0xFF04 # reset divider register when 0xFF04 # reset divider register
@memory[i] = 0 @memory[i] = 0
else when 0x0...0x8000 # ROM Bank 0 + n
@cartridge[i] = v
when 0x8000...0xA000 # Video RAM
@memory[i] = v
when 0xA000...0xC000 # RAM Bank
@cartridge[i] = v
when 0xC000...0xE000 # Internal RAM
@memory[i] = v
when 0xE000...0xFE00 # Internal RAM (Shadow)
@memory[i - 0x1000] = v
when 0xFE00..0xFFFF # Graphics (OAM), IO, Zero Page
@memory[i] = v @memory[i] = v
end end
else else