add datetime device, revise device handling, remove tracing code
This commit is contained in:
parent
56a3398c8f
commit
cf31dc5564
8 changed files with 115 additions and 119 deletions
|
|
@ -1,44 +1,54 @@
|
|||
open Uxn
|
||||
open Effect.Deep
|
||||
|
||||
let trace = Option.is_some (Sys.getenv_opt "UXNEMU_DEBUG")
|
||||
let devices_deo = Hashtbl.create 256
|
||||
let devices_dei = Hashtbl.create 256
|
||||
|
||||
let register_device (module D : Device.DEVICE) =
|
||||
Device.Int_set.iter
|
||||
(fun port -> Hashtbl.add devices_dei port (module D : Device.DEVICE))
|
||||
D.dei_ports;
|
||||
Device.Int_set.iter
|
||||
(fun port -> Hashtbl.add devices_deo port (module D : Device.DEVICE))
|
||||
D.deo_ports
|
||||
|
||||
module System = Varvara.System.Make ()
|
||||
module Console = Varvara.Console.Make ()
|
||||
module Datetime = Varvara.Datetime.Make ()
|
||||
|
||||
module File =
|
||||
Uxn.Device.Compose
|
||||
(Varvara.File.Make (struct
|
||||
let start = 0xa0
|
||||
end))
|
||||
(Varvara.File.Make (struct
|
||||
let start = 0xb0
|
||||
end))
|
||||
module File_a = Varvara.File.Make (struct
|
||||
let start = 0xa0
|
||||
end)
|
||||
|
||||
module Devices =
|
||||
Uxn.Device.Compose (Uxn.Device.Compose (System) (Console)) (File)
|
||||
module File_b = Varvara.File.Make (struct
|
||||
let start = 0xb0
|
||||
end)
|
||||
|
||||
let run m pc =
|
||||
let dev = Machine.dev m in
|
||||
try Machine.dispatch ~trace m pc with
|
||||
| effect Machine.Trace (pc, instr, args), k ->
|
||||
if trace then begin
|
||||
Printf.eprintf "PC = %04x %6s %s\n" pc (Instr.to_string instr)
|
||||
(List.map (Format.sprintf "%02x") args |> String.concat " ");
|
||||
Out_channel.flush stderr
|
||||
end;
|
||||
continue k ()
|
||||
try Machine.dispatch m pc with
|
||||
| effect Machine.BRK, _ -> ()
|
||||
| effect Machine.DEI (`Byte, port), k -> (
|
||||
match Devices.dei m port with
|
||||
| Some v -> continue k v
|
||||
| None -> continue k (Bytes.get_uint8 dev port))
|
||||
| effect Machine.DEI (`Short, port), k -> (
|
||||
match Devices.dei2 m port with
|
||||
| Some v -> continue k v
|
||||
| None -> continue k (Util.get_uint16_wrap dev port))
|
||||
| effect Machine.DEI (`Byte, port), k -> begin
|
||||
try
|
||||
let module Device = (val Hashtbl.find devices_dei port : Device.DEVICE)
|
||||
in
|
||||
continue k (Device.dei m port)
|
||||
with Not_found -> continue k (Bytes.get_uint8 dev port)
|
||||
end
|
||||
| effect Machine.DEI (`Short, port), k -> begin
|
||||
try
|
||||
let module Device = (val Hashtbl.find devices_dei port : Device.DEVICE)
|
||||
in
|
||||
continue k (Device.dei2 m port)
|
||||
with Not_found -> continue k (Util.get_uint16_wrap dev port)
|
||||
end
|
||||
| effect Machine.DEO (port, value), k ->
|
||||
if Devices.can_handle port then Devices.deo m port value;
|
||||
begin try
|
||||
let module Device = (val Hashtbl.find devices_deo port : Device.DEVICE)
|
||||
in
|
||||
Device.deo m port value
|
||||
with Not_found -> ()
|
||||
end;
|
||||
continue k ()
|
||||
|
||||
let main () =
|
||||
|
|
@ -46,6 +56,12 @@ let main () =
|
|||
Printf.eprintf "usage: uxnemu file.rom ...\n";
|
||||
exit 1);
|
||||
|
||||
register_device (module System : Device.DEVICE);
|
||||
register_device (module Console : Device.DEVICE);
|
||||
register_device (module File_a : Device.DEVICE);
|
||||
register_device (module File_b : Device.DEVICE);
|
||||
register_device (module Datetime : Device.DEVICE);
|
||||
|
||||
let code =
|
||||
In_channel.with_open_bin Sys.argv.(1) (fun i -> In_channel.input_all i)
|
||||
in
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue