From 502df9b6342082fb04894ce85810295528f92e34 Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Sat, 7 Nov 2020 19:40:29 -0800 Subject: [PATCH] cartridge oob data, wait states 1/2 --- src/crab/bus.cr | 14 ++++++++------ src/crab/cartridge.cr | 14 ++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/crab/bus.cr b/src/crab/bus.cr index 152e1e2..3528d8d 100644 --- a/src/crab/bus.cr +++ b/src/crab/bus.cr @@ -19,9 +19,11 @@ class Bus address = 0x1FFFF_u32 & index address -= 0x8000 if address > 0x17FFF @gba.ppu.vram[address] - when 0x7 then @gba.ppu.oam[index & 0x3FF] - when 0x8, 0x9 then @gba.cartridge[index & 0x7FFFFFF] - else raise "Unmapped read: #{hex_str index.to_u32}" + when 0x7 then @gba.ppu.oam[index & 0x3FF] + when 0x8, 0x9, + 0xA, 0xB, + 0xC, 0xD then @gba.cartridge[index & 0x01FFFFFF] + else raise "Unmapped read: #{hex_str index.to_u32}" end end @@ -73,9 +75,9 @@ class Bus address = 0x1FFFF_u32 & index address -= 0x8000 if address > 0x17FFF @gba.ppu.vram[address] = value - when 0x7 then @gba.ppu.oam[index & 0x3FF] - when 0x8, 0x9 then @gba.cartridge[index & 0x7FFFFFF] = value - else raise "Unmapped write: #{hex_str index.to_u32}" + when 0x7 then @gba.ppu.oam[index & 0x3FF] + when 0x8, 0x9 # can't write to cartridge + else raise "Unmapped write: #{hex_str index.to_u32}" end end diff --git a/src/crab/cartridge.cr b/src/crab/cartridge.cr index 4471807..5437b9d 100644 --- a/src/crab/cartridge.cr +++ b/src/crab/cartridge.cr @@ -7,18 +7,16 @@ class Cartridge io.to_s } + @rom = Bytes.new 0x02000000 do |addr| + oob = 0xFFFF & (addr >> 1) + (oob >> (8 * (addr & 1))).to_u8! + end + def initialize(rom_path : String) - @rom = File.open rom_path do |file| - bytes = Bytes.new file.size - file.read bytes - bytes - end + File.open(rom_path) { |file| file.read @rom } end def [](index : Int) : Byte @rom[index] end - - def []=(index : Int, value : Byte) : Nil - end end