Reshape MMU#[] to share to move common accesses first

This commit is contained in:
Benoit Daloze 2017-03-05 16:43:01 +01:00
parent c1e927fc1d
commit d4c2f76bc1

View file

@ -30,21 +30,14 @@ module Waterfoul
def [](i) def [](i)
raise MemoryOutOfBounds if i > MEMORY_SIZE || i < 0 raise MemoryOutOfBounds if i > MEMORY_SIZE || i < 0
case i if i == 0xFF00
when 0xFF00
Input.read_keyboard @memory[i] Input.read_keyboard @memory[i]
when 0x0000...0x8000 # ROM Bank 0 + n elsif (0x8000...0xA000) === i or (0xC000...0xE000) === i or (0xFE00..0xFFFF) === i
@cartridge[i]
when 0x8000...0xA000 # Video RAM
@memory[i] @memory[i]
when 0xA000...0xC000 # RAM Bank elsif (0xE000...0xFE00) === i
@cartridge[i]
when 0xC000...0xE000 # Internal RAM
@memory[i]
when 0xE000...0xFE00 # Internal RAM (shadow)
@memory[i - 0x2000] @memory[i - 0x2000]
when 0xFE00..0xFFFF # Graphics (OAM), IO, Zero-page elsif (0x0000...0x8000) === i or (0xA000...0xC000) === i
@memory[i] @cartridge[i]
end end
end end