From f7887b745ed063f217c2946fd3ea11431daa8792 Mon Sep 17 00:00:00 2001 From: Colby Date: Thu, 21 Jul 2016 18:09:11 +1000 Subject: [PATCH] rewrote ROM controller --- lib/waterfoul/mbc/rom.rb | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/waterfoul/mbc/rom.rb b/lib/waterfoul/mbc/rom.rb index 71b9960..2484c69 100644 --- a/lib/waterfoul/mbc/rom.rb +++ b/lib/waterfoul/mbc/rom.rb @@ -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