diff --git a/src/cpu.ml b/src/cpu.ml index f67bf2a..27295e5 100644 --- a/src/cpu.ml +++ b/src/cpu.ml @@ -30,6 +30,21 @@ type t = { mutable cycles : int; } +let print_cpu_state cpu = + printf "Registers:\n"; + printf " A: 0x%02X F: 0x%02X\n" (int_of_char cpu.reg.a) (int_of_char cpu.reg.f); + printf " B: 0x%02X C: 0x%02X\n" (int_of_char cpu.reg.b) (int_of_char cpu.reg.c); + printf " D: 0x%02X E: 0x%02X\n" (int_of_char cpu.reg.d) (int_of_char cpu.reg.e); + printf " H: 0x%02X L: 0x%02X\n" (int_of_char cpu.reg.h) (int_of_char cpu.reg.l); + printf " PC: 0x%04X\n" cpu.reg.pc; + printf " SP: 0x%04X\n" cpu.reg.sp; + + printf "Flags:\n"; + printf " Z: %b\n" cpu.flag.z; + printf " N: %b\n" cpu.flag.n; + printf " H: %b\n" cpu.flag.h; + printf " C: %b\n" cpu.flag.c + (** http://bgb.bircd.org/pandocs.htm#powerupsequence *) let init_registers = { @@ -109,6 +124,8 @@ let read_pc_2bytes cpu mem = https://github.com/sinamas/gambatte/blob/master/libgambatte/src/cpu.cpp *) let run cpu (mem: Memory.map) = + printf "\n"; + print_cpu_state cpu; let opcode = read_pc_byte cpu mem |> char_of_int in (* Hexa.print_slice cartridge.full_rom cpu.reg.pc (cpu.reg.pc + 7); *) match opcode with