From a26a17028485480af2f769169a22b0577aecccbd Mon Sep 17 00:00:00 2001 From: Matthew Berry Date: Fri, 26 Feb 2021 21:39:49 -0800 Subject: [PATCH] sram word and halfword reads --- src/crab/bus.cr | 4 ++-- src/crab/storage.cr | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/crab/bus.cr b/src/crab/bus.cr index 20147a1..2249623 100644 --- a/src/crab/bus.cr +++ b/src/crab/bus.cr @@ -43,7 +43,7 @@ class Bus when 0x8, 0x9, 0xA, 0xB, 0xC, 0xD then (@gba.cartridge.rom.to_unsafe + (index & 0x01FFFFFF)).as(HalfWord*).value - when 0xE, 0xF then read_half_slow(index) + when 0xE, 0xF then @gba.storage.read_half(index) else abort "Unmapped read: #{hex_str index.to_u32}" end end @@ -81,7 +81,7 @@ class Bus when 0x8, 0x9, 0xA, 0xB, 0xC, 0xD then (@gba.cartridge.rom.to_unsafe + (index & 0x01FFFFFF)).as(Word*).value - when 0xE, 0xF then read_word_slow(index) + when 0xE, 0xF then @gba.storage.read_word(index) else abort "Unmapped read: #{hex_str index.to_u32}" end end diff --git a/src/crab/storage.cr b/src/crab/storage.cr index 88a5677..e3a30b3 100644 --- a/src/crab/storage.cr +++ b/src/crab/storage.cr @@ -49,6 +49,14 @@ abstract class Storage abstract def [](index : Int) : Byte + def read_half(index : Int) : HalfWord + 0x0101_u16 * self[index & ~1] + end + + def read_word(index : Int) : Word + 0x01010101_u32 * self[index & ~3] + end + abstract def []=(index : Int, value : Byte) : Nil private def self.find_type(file : File) : Type?