31 lines
1,005 B
OCaml
31 lines
1,005 B
OCaml
(*pogajalnik bo izvajal exekucijo eno za drugo*)
|
|
|
|
let run (state : Processor.state) (khz : float) : unit =
|
|
let perioda_sekunde = 1.0 /. (khz *. 1000.0) in
|
|
let rec loop state last_pc count=
|
|
|
|
(*izvedi ukaz*)
|
|
Izvajalnik.execute state;
|
|
|
|
(*printni stanje*)
|
|
Printf.printf "After execution:\n";
|
|
Processor.print_regs state;
|
|
Processor.print_memory_pretty state 160;
|
|
Printf.printf "-----------------------------------\n";
|
|
flush stdout;
|
|
|
|
(*spi*)
|
|
Unix.sleepf perioda_sekunde;(*mogoče spremeni na time of day approach , da se izogneš driftu*)
|
|
|
|
(*preveri ali je PC obtičan na istem mestu*)
|
|
let current_pc = state.regs.pc in
|
|
let count, last_pc =
|
|
if current_pc = last_pc then (count + 1, last_pc)
|
|
else (1, current_pc)
|
|
in
|
|
(*Nehaj rekurzijo če je PC 5x na istem mestu*)
|
|
if count >= 5 then
|
|
Printf.printf "PC stuck at 0x%X 5 times. Ending loop.\n" current_pc
|
|
else
|
|
loop state last_pc count
|
|
in loop state state.regs.pc 0
|