Automatically increment PC register.

This commit is contained in:
Fabien Freling 2015-03-23 17:34:22 +01:00
parent f3916dfd64
commit b3ca33a814

View file

@ -95,44 +95,56 @@ let cmp_A cpu n =
(** http://imrannazar.com/GameBoy-Z80-Opcode-Map *)
let run cpu (mem: Memory.map) =
let n = Memory.get mem (cpu.reg.pc + 1) |> int_of_char in
let opcode = Memory.get mem cpu.reg.pc in
inc_pc cpu 1;
let n = Memory.get mem cpu.reg.pc |> int_of_char in
(* let nn = Memory.get mem (cpu.reg.pc + 2) in *)
(* Hexa.print_slice cartridge.full_rom cpu.reg.pc (cpu.reg.pc + 7); *)
match Memory.get mem cpu.reg.pc with
match opcode with
| '\x00' -> printf " NOP\n";
inc_pc cpu 1; inc_cycles cpu 4
inc_cycles cpu 4
| '\x03' -> printf " INC \tBC\n";
inc_BC cpu;
inc_pc cpu 1; inc_cycles cpu 8
inc_cycles cpu 8
| '\x20' -> printf " JR\t NZ, 0x%02X\n" n;
if cpu.flag.z = false then
begin
inc_pc cpu n; inc_cycles cpu 12
end else
begin
inc_pc cpu 1; inc_cycles cpu 8
end
| '\x3E' -> printf " LD \tA, 0x%02X\n" n;
cpu.reg.a <- char_of_int(n);
inc_pc cpu 2; inc_cycles cpu 8
inc_pc cpu 1; inc_cycles cpu 8
| '\xAF' -> printf " XOR \tA, A\n";
let int_A = int_of_char cpu.reg.a in
cpu.reg.a <- char_of_int @@ int_A lxor int_A;
inc_pc cpu 1; inc_cycles cpu 4
inc_cycles cpu 4
| '\xC3' -> let addr = read_2B mem (cpu.reg.pc + 1) in
| '\xC3' -> let addr = read_2B mem cpu.reg.pc in
printf " JP \t0x%04X\n" addr;
cpu.reg.pc <- addr; inc_cycles cpu 16
| '\xE0' -> printf " LDH \t(0xFF%02X), A\n" n;
Memory.set mem (0xFF00 + n) cpu.reg.a;
inc_pc cpu 2; inc_cycles cpu 12
inc_pc cpu 1; inc_cycles cpu 12
| '\xF0' -> printf " LDH \tA, (0xFF%02X)\n" n;
cpu.reg.a <- Memory.get mem (0xFF00 + n);
inc_pc cpu 2; inc_cycles cpu 12
inc_pc cpu 1; inc_cycles cpu 12
| '\xF3' -> printf " DI\n";
(* fixme *)
inc_pc cpu 1; inc_cycles cpu 4
inc_cycles cpu 4
| '\xFE' -> printf " CP\t0x%02X\n" n;
cmp_A cpu n;
inc_pc cpu 2; inc_cycles cpu 8
inc_pc cpu 1; inc_cycles cpu 8
| _ as x -> eprintf "opcode %02X\n" (int_of_char x); failwith "Unimplemented opcode."
| _ as x -> eprintf "opcode %02X\n" (int_of_char x);
failwith "Unimplemented opcode."