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,21 +4,30 @@ module THUMB
rb = bits(instr, 8..10)
list = bits(instr, 0..7)
address = @r[rb]
if load # ldmia
8.times do |idx|
if bit?(list, idx)
set_reg(idx, @gba.bus.read_word(address))
address &+= 4
unless list == 0
if load # ldmia
8.times do |idx|
if bit?(list, idx)
set_reg(idx, @gba.bus.read_word(address))
address &+= 4
end
end
else # stmia
8.times do |idx|
if bit?(list, idx)
@gba.bus[address] = @r[idx]
address &+= 4
end
end
end
else # stmia
7.downto(0).each do |idx|
if bit?(list, idx)
@gba.bus[address] = @r[idx]
address &+= 4
end
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
set_reg(rb, address)
end
end