support halting + fast-forwarding the scheduler on halt

this improves performance dramatically in games that utilize halting, including pokemon ruby and golden sun. in both games, framerate was doubled or trippled in many cases
This commit is contained in:
Matthew Berry 2021-04-29 23:50:48 -07:00
parent b8c64fa69d
commit c584c29fd6
4 changed files with 13 additions and 6 deletions

View file

@ -136,8 +136,10 @@ class CPU
else
arm_execute instr
end
@gba.scheduler.tick 1
else
@gba.scheduler.fast_forward
end
@gba.tick 1
end
def check_cond(cond : Word) : Bool

View file

@ -83,8 +83,4 @@ class GBA
cpu.tick
end
end
def tick(cycles : Int) : Nil
scheduler.tick cycles
end
end

View file

@ -67,7 +67,11 @@ class MMIO
mask = 0xFF00_u16 >> shift
@waitcnt.value = (@waitcnt.value & mask) | value.to_u16 << shift
elsif io_addr == 0x301
@gba.cpu.halted = bit?(value, 7)
if bit?(value, 7)
abort "Stopping not supported"
else
@gba.cpu.halted = true
end
elsif not_used? io_addr
else
puts "Unmapped MMIO write ~ addr:#{hex_str index.to_u32}, val:#{hex_str value}".colorize(:yellow)

View file

@ -63,4 +63,9 @@ class Scheduler
end
end
end
def fast_forward : Nil
@cycles = @next_event
call_current
end
end