Add fps to main loop
This commit is contained in:
parent
fb5eeed6ba
commit
013fd9abe4
3 changed files with 64 additions and 34 deletions
30
src/oboy.ml
30
src/oboy.ml
|
@ -1,7 +1,31 @@
|
|||
open Printf
|
||||
|
||||
let fps = 60
|
||||
let cycles_per_frame = Cpu.frequence / fps
|
||||
|
||||
let rec run (cpu: Cpu.t) (mem: Memory.map) (screen: Screen.t) =
|
||||
Cpu.run cpu mem;
|
||||
printf "\n";
|
||||
let start = Unix.gettimeofday () in
|
||||
printf "start %f\n" start;
|
||||
|
||||
let rec run_for cpu mem cycles_remaining =
|
||||
if cycles_remaining > 0 then
|
||||
begin
|
||||
let inst, cycles = Cpu.run cpu mem in
|
||||
printf "[Instruction] %s\n" inst;
|
||||
run_for cpu mem (cycles_remaining - cycles)
|
||||
end
|
||||
in
|
||||
run_for cpu mem cycles_per_frame;
|
||||
|
||||
let stop = Unix.gettimeofday () in
|
||||
let delay = (1. -. (stop -. start)) /. (float_of_int fps) in
|
||||
printf "stop %f\n" stop;
|
||||
printf "delta %f\n" (stop -. start);
|
||||
printf "delay %f\n" delay;
|
||||
flush_all ();
|
||||
|
||||
if delay > 0. then Thread.delay delay;
|
||||
run cpu mem screen
|
||||
|
||||
(** Power up sequence
|
||||
|
@ -18,9 +42,9 @@ let power_up cartridge =
|
|||
let mem = Memory.init cartridge in
|
||||
let screen = Screen.init in
|
||||
|
||||
Graphics.open_graph "";
|
||||
(*Graphics.open_graph "";
|
||||
Graphics.resize_window Screen.width Screen.height;
|
||||
|
||||
*)
|
||||
run cpu mem screen
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue