Change of heart, begin is cool

master
Fabien Freling 2016-03-01 00:22:56 +01:00
parent 77f7c7bef3
commit c6106203eb
3 changed files with 14 additions and 17 deletions

View File

@ -189,24 +189,22 @@ let run cpu (mem: Memory.map) =
| '\x20' -> let n = read_pc_byte cpu mem in
let s = Bit.signed_byte n in
let inst = sprintf "JR \tNZ, 0x%02X (%d)" n s in
if cpu.flag.z = false then (
if cpu.flag.z = false then begin
inc_pc cpu (s - 2); (* we read 2 bytes from PC, opcode and n *)
inst, 12
) else (
end else
inst, 8
)
| '\xC9' -> let inst = sprintf "RET" in
cpu.reg.pc <- pop_stack cpu mem;
inst, 16
| '\xC0' -> let inst = sprintf "RET \tNZ" in
if cpu.flag.z = false then (
if cpu.flag.z = false then begin
cpu.reg.pc <- pop_stack cpu mem;
inst, 20
) else (
end else
inst, 8
)
@ -250,12 +248,11 @@ let run cpu (mem: Memory.map) =
| '\x28' -> let n = read_pc_byte cpu mem in
let inst = sprintf "JR \tZ, 0x%02X" n in
if cpu.flag.z = true then (
if cpu.flag.z = true then begin
inc_pc cpu (n - 1);
inst, 12
) else (
end else
inst, 8
)
| '\x34' -> let inst = sprintf "INC \t(HL)" in
let hl = merge_bytes cpu.reg.l cpu.reg.h in

View File

@ -99,11 +99,11 @@ let update_timers mem cycles =
if should_inc_div then ignore (inc mem.map gDIV);
let should_inc_tima = Timer.update mem.tima cycles in
if should_inc_tima then (
if should_inc_tima then begin
let overflow = inc mem.map gTIMA in
if overflow then (
if overflow then begin
let tma = get mem.map gTMA in
set mem.map gTIMA tma
(* TODO: INT 50 - Timer interupt *)
)
)
end
end

View File

@ -16,7 +16,7 @@ let rec run (cpu: Cpu.t) (mem: Memory.t) (screen: Screen.t) =
printf "start %f\n" start;
let rec run_for cpu (mem: Memory.t) cycles_remaining =
if cycles_remaining > 0 then (
if cycles_remaining > 0 then begin
printf "\n";
let inst, cycles = Cpu.run cpu mem.map in
printf "[Instruction] %s\n" inst;
@ -24,7 +24,7 @@ let rec run (cpu: Cpu.t) (mem: Memory.t) (screen: Screen.t) =
Memory.update_timers mem cycles;
run_for cpu mem (cycles_remaining - cycles)
)
end
in
run_for cpu mem cycles_per_frame;
@ -59,11 +59,11 @@ let power_up cartridge =
let () =
if Array.length Sys.argv < 2 then (
if Array.length Sys.argv < 2 then begin
prerr_endline "Please specify a ROM.";
eprintf "Usage: %s path/to/rom\n" Sys.argv.(0);
exit 1;
);
end;
let cartridge = Cartridge.read_cartridge Sys.argv.(1) in
match cartridge with