Use memory map instead of cartridge.

This commit is contained in:
Fabien Freling 2015-03-22 16:57:03 +01:00
parent 16d303008c
commit e5bc9bc4db
3 changed files with 36 additions and 16 deletions

View file

@ -61,9 +61,9 @@ let split_2B x =
let high = x / 256 |> char_of_int in
(high, low)
let read_2B b addr =
let low = Bytes.get b addr in
let high = Bytes.get b (addr + 1) in
let read_2B m addr =
let low = Memory.get m addr in
let high = Memory.get m (addr + 1) in
merge_bytes low high
let inc_BC cpu =
@ -73,12 +73,11 @@ let inc_BC cpu =
cpu.reg.b <- high
(** http://imrannazar.com/GameBoy-Z80-Opcode-Map *)
let run cpu (cartridge: Cartridge.t) =
let data = cartridge.full_rom in
let n = Bytes.get data (cpu.reg.pc + 1) in
let nn = Bytes.get data (cpu.reg.pc + 2) in
let run cpu (mem: Memory.map) =
let n = Memory.get mem (cpu.reg.pc + 1) 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 Bytes.get data cpu.reg.pc with
match Memory.get mem cpu.reg.pc with
| '\x00' -> printf " NOP\n";
inc_pc cpu 1; inc_cycles cpu 4
@ -95,16 +94,16 @@ let run cpu (cartridge: Cartridge.t) =
cpu.reg.a <- char_of_int @@ int_A lxor int_A;
inc_pc cpu 1; inc_cycles cpu 4
| '\xC3' -> let addr = read_2B data (cpu.reg.pc + 1) in
| '\xC3' -> let addr = read_2B mem (cpu.reg.pc + 1) in
printf " JP \t0x%04X\n" addr;
cpu.reg.pc <- addr; inc_cycles cpu 16
| '\xE0' -> printf " LDH \t(0xFF%02X), A\n" (int_of_char n);
(* fixme *)
Memory.set mem (0xFF00 + (int_of_char n)) cpu.reg.a;
inc_pc cpu 2; inc_cycles cpu 12
| '\xF0' -> printf " LDH \tA, (0xFF%02X)\n" (int_of_char n);
(* fixme *)
cpu.reg.a = Memory.get mem (0xFF00 + (int_of_char n));
inc_pc cpu 2; inc_cycles cpu 12
| '\xF3' -> printf " DI\n";