rewrote ROM controller

This commit is contained in:
Colby 2016-07-21 18:09:11 +10:00
parent 2bbfd679e2
commit f7887b745e

View file

@ -1,29 +1,26 @@
module Waterfoul
module MBC
class ROM
EXTERNAL_RAM_START_ADDR = 0xA000
EXTERNAL_RAM_SIZE = 0x1FFF
def initialize(program)
@external_ram = []
@external_ram = Array.new EXTERNAL_RAM_SIZE, 0
@program = program
end
def [](i)
case i & 0xE000
when 0xA000,0xB000
@external_ram[i]
case i
when 0xA000...0xC000
@external_ram[i - 0xA000]
else
@program[i]
end
end
def []=(i,v)
case i & 0xE000
when 0xA000, 0xB000
addr = i - EXTERNAL_RAM_START_ADDR
@external_ram[addr] = v
else
fail 'forbidden write to rom'
case i
when 0xA000...0xC000
@external_ram[i - 0xA000] = v
end
end
end