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
|
|
@ -4,9 +4,10 @@ module Make () : Uxn.Device.DEVICE with type state = state = struct
|
|||
type nonrec state = state
|
||||
|
||||
let state = { console_vector = 0 }
|
||||
let can_handle port = port >= 0x10 && port <= 0x1f
|
||||
let dei _ _ = None
|
||||
let dei2 _ _ = None
|
||||
let dei_ports = Uxn.Device.Int_set.empty
|
||||
let deo_ports = Uxn.Device.Int_set.of_list [ 0x10; 0x18; 0x19 ]
|
||||
let dei _ _ = assert false
|
||||
let dei2 _ _ = assert false
|
||||
|
||||
let deo _ port value =
|
||||
match port with
|
||||
|
|
@ -17,5 +18,5 @@ module Make () : Uxn.Device.DEVICE with type state = state = struct
|
|||
| 0x19 ->
|
||||
prerr_char (Char.chr value);
|
||||
Out_channel.flush stderr
|
||||
| _ -> ()
|
||||
| _ -> assert false
|
||||
end
|
||||
|
|
|
|||
34
lib/Varvara/Datetime.ml
Normal file
34
lib/Varvara/Datetime.ml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
module Make () : Uxn.Device.DEVICE with type state = unit = struct
|
||||
type state = unit
|
||||
|
||||
let state = ()
|
||||
|
||||
let dei_ports =
|
||||
Uxn.Device.Int_set.of_list
|
||||
[ 0xc0; 0xc2; 0xc3; 0xc4; 0xc5; 0xc6; 0xc7; 0xc8; 0xca ]
|
||||
|
||||
let deo_ports = Uxn.Device.Int_set.empty
|
||||
|
||||
let dei _ port =
|
||||
let now = Unix.time () in
|
||||
let tm = Unix.localtime now in
|
||||
match port with
|
||||
| 0xc2 -> tm.Unix.tm_mon
|
||||
| 0xc3 -> tm.Unix.tm_mday
|
||||
| 0xc4 -> tm.Unix.tm_hour
|
||||
| 0xc5 -> tm.Unix.tm_min
|
||||
| 0xc6 -> tm.Unix.tm_sec
|
||||
| 0xc7 -> tm.Unix.tm_wday
|
||||
| 0xca -> Bool.to_int tm.Unix.tm_isdst
|
||||
| _ -> assert false
|
||||
|
||||
let dei2 _ port =
|
||||
let now = Unix.time () in
|
||||
let tm = Unix.localtime now in
|
||||
match port with
|
||||
| 0xc0 -> tm.Unix.tm_year + 1900
|
||||
| 0xc8 -> tm.Unix.tm_yday
|
||||
| _ -> assert false
|
||||
|
||||
let deo _ _ _ = assert false
|
||||
end
|
||||
|
|
@ -19,7 +19,18 @@ module Make (Addr : ADDR) : Uxn.Device.DEVICE with type state = state = struct
|
|||
type nonrec state = state
|
||||
|
||||
let state = { filepath = None; state = Idle; length = 0 }
|
||||
let can_handle port = port >= Addr.start && port <= Addr.start + 0x0f
|
||||
let dei_ports = Uxn.Device.Int_set.empty
|
||||
|
||||
let deo_ports =
|
||||
Uxn.Device.Int_set.of_list
|
||||
[
|
||||
Addr.start + 0x0a;
|
||||
Addr.start + 0x04;
|
||||
Addr.start + 0x06;
|
||||
Addr.start + 0x08;
|
||||
Addr.start + 0x0c;
|
||||
Addr.start + 0x0e;
|
||||
]
|
||||
|
||||
let read_cstring ram addr =
|
||||
let buf = Buffer.create 256 in
|
||||
|
|
@ -194,8 +205,8 @@ module Make (Addr : ADDR) : Uxn.Device.DEVICE with type state = state = struct
|
|||
with Unix.Unix_error _ -> -1)
|
||||
|
||||
let file_success dev port value = Bytes.set_uint16_be dev port value
|
||||
let dei _ _ = None
|
||||
let dei2 _ _ = None
|
||||
let dei _ _ = assert false
|
||||
let dei2 _ _ = assert false
|
||||
|
||||
let deo mach port value =
|
||||
let open Uxn in
|
||||
|
|
@ -211,5 +222,5 @@ module Make (Addr : ADDR) : Uxn.Device.DEVICE with type state = state = struct
|
|||
| 0x0e ->
|
||||
let append = Bytes.get_uint8 dev (Addr.start + 0x07) in
|
||||
file_write ram value state.length append |> with_success
|
||||
| _ -> ()
|
||||
| _ -> failwith (Printf.sprintf "%02x" port)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@ module Make () : Uxn.Device.DEVICE with type state = state = struct
|
|||
type nonrec state = state
|
||||
|
||||
let state = { banks = Array.init 15 (fun _ -> Bytes.create 65536) }
|
||||
let can_handle port = port >= 0x00 && port <= 0x0f
|
||||
let dei_ports = Uxn.Device.Int_set.of_list [ 0x04; 0x05 ]
|
||||
let deo_ports = Uxn.Device.Int_set.of_list [ 0x02; 0x04; 0x05; 0x0e; 0x0f ]
|
||||
|
||||
let print_stack ~name (Machine.Stack { data; sp }) =
|
||||
Printf.eprintf "%s " name;
|
||||
|
|
@ -76,13 +77,13 @@ module Make () : Uxn.Device.DEVICE with type state = state = struct
|
|||
match port with
|
||||
| 0x04 ->
|
||||
let (Machine.Stack { sp; _ }) = Machine.wst m in
|
||||
Some sp
|
||||
sp
|
||||
| 0x05 ->
|
||||
let (Machine.Stack { sp; _ }) = Machine.rst m in
|
||||
Some sp
|
||||
| _ -> None
|
||||
sp
|
||||
| _ -> assert false
|
||||
|
||||
let dei2 _ _ = None
|
||||
let dei2 _ _ = assert false
|
||||
|
||||
let deo mach port value =
|
||||
match port with
|
||||
|
|
@ -100,5 +101,5 @@ module Make () : Uxn.Device.DEVICE with type state = state = struct
|
|||
Out_channel.flush stderr
|
||||
end
|
||||
| 0x0f -> Bytes.set_uint8 (Machine.dev mach) 0x0f value
|
||||
| _ -> ()
|
||||
| _ -> assert false
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue