add halting

This commit is contained in:
Matthew Berry 2020-11-30 08:44:37 -08:00
parent 042b76d910
commit a79afb3817
3 changed files with 12 additions and 7 deletions

View file

@ -47,6 +47,7 @@ class CPU
getter thumb_lut : Slice(Proc(Word, Nil)) { fill_thumb_lut }
@reg_banks = Array(Array(Word)).new 6 { Array(Word).new 7, 0 }
@spsr_banks = Array(Word).new 6, CPU::Mode::SYS.value # logically independent of typical register banks
property halted = false
def initialize(@gba : GBA)
@reg_banks[Mode::USR.bank][5] = @r[13] = 0x03007F00
@ -115,12 +116,14 @@ class CPU
def tick : Nil
fill_pipeline
instr = @pipeline.shift
{% if flag? :trace %} print_state instr {% end %}
if @cpsr.thumb
thumb_execute instr
else
arm_execute instr
unless @halted
instr = @pipeline.shift
{% if flag? :trace %} print_state instr {% end %}
if @cpsr.thumb
thumb_execute instr
else
arm_execute instr
end
end
@gba.tick 1
end

View file

@ -55,7 +55,7 @@ class Interrupts
private def check_interrupts : Nil
if @reg_ie.value & @reg_if.value != 0
# todo this condition unhalts
@gba.cpu.halted = false
@gba.cpu.irq if @ime
end
end

View file

@ -48,6 +48,8 @@ class MMIO
shift = 8 * (io_addr & 1)
mask = 0xFF00_u16 >> shift
@waitcnt.value = (@waitcnt.value & mask) | value.to_u16 << shift
elsif io_addr == 0x301
@gba.cpu.halted = bit?(value, 7)
elsif not_used? io_addr
else
puts "Unmapped MMIO write ~ addr:#{hex_str index.to_u32}, val:#{hex_str value}".colorize(:yellow)