Add print_cpu_state.

This function pretty prints the state of the CPU on stdout.
This commit is contained in:
Fabien Freling 2015-05-20 16:38:39 +02:00
parent c8b231d48a
commit 6599857947

View file

@ -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