mirror of
https://github.com/colby-swandale/waterfoul
synced 2025-01-13 08:01:18 +01:00
rewrote ROM controller
This commit is contained in:
parent
2bbfd679e2
commit
f7887b745e
1 changed files with 8 additions and 11 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue