Change of heart, begin is cool
This commit is contained in:
parent
77f7c7bef3
commit
c6106203eb
15
src/cpu.ml
15
src/cpu.ml
|
@ -189,24 +189,22 @@ let run cpu (mem: Memory.map) =
|
||||||
| '\x20' -> let n = read_pc_byte cpu mem in
|
| '\x20' -> let n = read_pc_byte cpu mem in
|
||||||
let s = Bit.signed_byte n in
|
let s = Bit.signed_byte n in
|
||||||
let inst = sprintf "JR \tNZ, 0x%02X (%d)" n s 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 *)
|
inc_pc cpu (s - 2); (* we read 2 bytes from PC, opcode and n *)
|
||||||
inst, 12
|
inst, 12
|
||||||
) else (
|
end else
|
||||||
inst, 8
|
inst, 8
|
||||||
)
|
|
||||||
|
|
||||||
| '\xC9' -> let inst = sprintf "RET" in
|
| '\xC9' -> let inst = sprintf "RET" in
|
||||||
cpu.reg.pc <- pop_stack cpu mem;
|
cpu.reg.pc <- pop_stack cpu mem;
|
||||||
inst, 16
|
inst, 16
|
||||||
|
|
||||||
| '\xC0' -> let inst = sprintf "RET \tNZ" in
|
| '\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;
|
cpu.reg.pc <- pop_stack cpu mem;
|
||||||
inst, 20
|
inst, 20
|
||||||
) else (
|
end else
|
||||||
inst, 8
|
inst, 8
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -250,12 +248,11 @@ let run cpu (mem: Memory.map) =
|
||||||
|
|
||||||
| '\x28' -> let n = read_pc_byte cpu mem in
|
| '\x28' -> let n = read_pc_byte cpu mem in
|
||||||
let inst = sprintf "JR \tZ, 0x%02X" n 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);
|
inc_pc cpu (n - 1);
|
||||||
inst, 12
|
inst, 12
|
||||||
) else (
|
end else
|
||||||
inst, 8
|
inst, 8
|
||||||
)
|
|
||||||
|
|
||||||
| '\x34' -> let inst = sprintf "INC \t(HL)" in
|
| '\x34' -> let inst = sprintf "INC \t(HL)" in
|
||||||
let hl = merge_bytes cpu.reg.l cpu.reg.h in
|
let hl = merge_bytes cpu.reg.l cpu.reg.h in
|
||||||
|
|
|
@ -99,11 +99,11 @@ let update_timers mem cycles =
|
||||||
if should_inc_div then ignore (inc mem.map gDIV);
|
if should_inc_div then ignore (inc mem.map gDIV);
|
||||||
|
|
||||||
let should_inc_tima = Timer.update mem.tima cycles in
|
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
|
let overflow = inc mem.map gTIMA in
|
||||||
if overflow then (
|
if overflow then begin
|
||||||
let tma = get mem.map gTMA in
|
let tma = get mem.map gTMA in
|
||||||
set mem.map gTIMA tma
|
set mem.map gTIMA tma
|
||||||
(* TODO: INT 50 - Timer interupt *)
|
(* TODO: INT 50 - Timer interupt *)
|
||||||
)
|
end
|
||||||
)
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ let rec run (cpu: Cpu.t) (mem: Memory.t) (screen: Screen.t) =
|
||||||
printf "start %f\n" start;
|
printf "start %f\n" start;
|
||||||
|
|
||||||
let rec run_for cpu (mem: Memory.t) cycles_remaining =
|
let rec run_for cpu (mem: Memory.t) cycles_remaining =
|
||||||
if cycles_remaining > 0 then (
|
if cycles_remaining > 0 then begin
|
||||||
printf "\n";
|
printf "\n";
|
||||||
let inst, cycles = Cpu.run cpu mem.map in
|
let inst, cycles = Cpu.run cpu mem.map in
|
||||||
printf "[Instruction] %s\n" inst;
|
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;
|
Memory.update_timers mem cycles;
|
||||||
|
|
||||||
run_for cpu mem (cycles_remaining - cycles)
|
run_for cpu mem (cycles_remaining - cycles)
|
||||||
)
|
end
|
||||||
in
|
in
|
||||||
run_for cpu mem cycles_per_frame;
|
run_for cpu mem cycles_per_frame;
|
||||||
|
|
||||||
|
@ -59,11 +59,11 @@ let power_up cartridge =
|
||||||
|
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
if Array.length Sys.argv < 2 then (
|
if Array.length Sys.argv < 2 then begin
|
||||||
prerr_endline "Please specify a ROM.";
|
prerr_endline "Please specify a ROM.";
|
||||||
eprintf "Usage: %s path/to/rom\n" Sys.argv.(0);
|
eprintf "Usage: %s path/to/rom\n" Sys.argv.(0);
|
||||||
exit 1;
|
exit 1;
|
||||||
);
|
end;
|
||||||
|
|
||||||
let cartridge = Cartridge.read_cartridge Sys.argv.(1) in
|
let cartridge = Cartridge.read_cartridge Sys.argv.(1) in
|
||||||
match cartridge with
|
match cartridge with
|
||||||
|
|
Loading…
Reference in a new issue