diff --git a/src/crab/gba/bus.cr b/src/crab/gba/bus.cr index a53f3cf..0e8a207 100644 --- a/src/crab/gba/bus.cr +++ b/src/crab/gba/bus.cr @@ -169,8 +169,10 @@ module GBA when 0x4 then @gba.mmio[index] = value when 0x5 then (@gba.ppu.pram.to_unsafe + (index & 0x3FE)).as(HalfWord*).value = 0x0101_u16 * value when 0x6 - address = 0x1FFFE_u32 & index # todo ignored range is different when in bitmap mode - (@gba.ppu.vram.to_unsafe + address).as(HalfWord*).value = 0x0101_u16 * value if address <= 0x0FFFF + limit = @gba.ppu.bitmap? ? 0x13FFF : 0x0FFFF # (u8 write only) upper limit depends on display mode + address = 0x1FFFE_u32 & index # (u8 write only) halfword-aligned + address -= 0x8000 if address > 0x17FFF # todo: determine if this happens before or after the limit check + (@gba.ppu.vram.to_unsafe + address).as(HalfWord*).value = 0x0101_u16 * value if address <= limit when 0xD then @gba.storage[index] = value if @gba.storage.eeprom? index when 0xE, 0xF then @gba.storage[index] = value else log "Unmapped write: #{hex_str index.to_u32}" diff --git a/src/crab/gba/ppu.cr b/src/crab/gba/ppu.cr index c4d7116..3d39df4 100644 --- a/src/crab/gba/ppu.cr +++ b/src/crab/gba/ppu.cr @@ -35,6 +35,10 @@ module GBA start_line end + def bitmap? : Bool + @dispcnt.bg_mode >= 3 + end + def start_line : Nil @gba.scheduler.schedule 960, ->start_hblank end