thumb load/store halfword, add halfword type, add halfword write

This commit is contained in:
Matthew Berry 2020-10-01 22:20:03 -07:00
parent b830b97687
commit 1d148c3ea7
4 changed files with 22 additions and 1 deletions

View file

@ -54,6 +54,12 @@ class Bus
end
end
def []=(index : Int, value : HalfWord) : Nil
log "write #{hex_str index.to_u32} -> #{hex_str value}"
self[index + 1] = 0xFF_u8 & (value >> 8)
self[index] = 0xFF_u8 & value
end
def []=(index : Int, value : Word) : Nil
log "write #{hex_str index.to_u32} -> #{hex_str value}"
self[index + 3] = 0xFF_u8 & (value >> 24)

View file

@ -0,0 +1,14 @@
module THUMB
def thumb_load_store_halfword(instr : Word) : Nil
load = bit?(instr, 11)
offset = bits(instr, 6..10)
rb = bits(instr, 3..5)
rd = bits(instr, 0..2)
address = @r[rb] + (offset << 1)
if load
@r[rd] = @gba.bus.read_half(address)
else
@gba.bus[address] = @r[rd].to_u16!
end
end
end

View file

@ -25,7 +25,7 @@ module THUMB
elsif idx & 0b11110000 == 0b10010000
# sp-relative load/store
elsif idx & 0b11110000 == 0b10000000
# load/store halfword
lut[idx] = -> thumb_load_store_halfword(Word)
elsif idx & 0b11100000 == 0b01100000
lut[idx] = ->thumb_load_store_immediate_offset(Word)
elsif idx & 0b11110010 == 0b01010010

View file

@ -1,3 +1,4 @@
alias Byte = UInt8
alias HalfWord = UInt16
alias Word = UInt32
alias Words = Slice(UInt32)