thumb stm correct direction, handle empty list case

This commit is contained in:
Matthew Berry 2020-10-31 16:50:53 -07:00
parent 9ad6086baf
commit ec08f0ee21

View file

@ -4,6 +4,7 @@ module THUMB
rb = bits(instr, 8..10) rb = bits(instr, 8..10)
list = bits(instr, 0..7) list = bits(instr, 0..7)
address = @r[rb] address = @r[rb]
unless list == 0
if load # ldmia if load # ldmia
8.times do |idx| 8.times do |idx|
if bit?(list, idx) if bit?(list, idx)
@ -12,7 +13,7 @@ module THUMB
end end
end end
else # stmia else # stmia
7.downto(0).each do |idx| 8.times do |idx|
if bit?(list, idx) if bit?(list, idx)
@gba.bus[address] = @r[idx] @gba.bus[address] = @r[idx]
address &+= 4 address &+= 4
@ -20,5 +21,13 @@ module THUMB
end end
end end
set_reg(rb, address) set_reg(rb, address)
else # https://github.com/jsmolka/gba-suite/blob/0e32e15c6241e6dc20851563ba88f4656ac50936/thumb/memory.asm#L459
if load
set_reg(15, @gba.bus.read_word(address))
else
@gba.bus[address] = @r[15] &+ 2
end
set_reg(rb, address &+ 0x40)
end
end end
end end