make #010e DEO print stack in the recommended repr
This commit is contained in:
parent
b71cf4343e
commit
bc1bae5977
8 changed files with 837 additions and 52 deletions
|
|
@ -5,7 +5,10 @@ open Effect
|
|||
type stack = Stack of { data : bytes; mutable sp : int }
|
||||
type mode = Mode of { short : bool; keep : bool; mutable temp : int }
|
||||
|
||||
let stack_create () = Stack { data = Bytes.create 256; sp = 0 }
|
||||
let stack_create () =
|
||||
let data = Bytes.create 256 in
|
||||
Bytes.unsafe_fill data 0 256 '\x00';
|
||||
Stack { data; sp = 0 }
|
||||
|
||||
let peek (Mode { short; keep; temp }) (Stack { data; sp }) : int =
|
||||
let amt = if short then 2 else 1 in
|
||||
|
|
@ -36,13 +39,6 @@ let pushbyte (Mode m) s v =
|
|||
m.temp <- temp
|
||||
[@@inline]
|
||||
|
||||
let pushshort (Mode m) s v =
|
||||
let m' = Mode { m with short = true } in
|
||||
push m' s v;
|
||||
let (Mode { temp; _ }) = m' in
|
||||
m.temp <- temp
|
||||
[@@inline]
|
||||
|
||||
let popbyte (Mode m) s =
|
||||
let m' = Mode { m with short = false } in
|
||||
let r = pop m' s in
|
||||
|
|
@ -75,9 +71,6 @@ type _ Effect.t +=
|
|||
| DEI : ([ `Byte | `Short ] * int) -> int Effect.t
|
||||
| DEO : (int * int) -> unit Effect.t
|
||||
| Trace : (int * Instr.t * int list) -> unit Effect.t
|
||||
| Breakpoint : int -> unit Effect.t
|
||||
|
||||
type machine_state = Break | Next of int
|
||||
|
||||
let ram (Machine { data; _ }) = data
|
||||
let dev (Machine { dev; _ }) = dev
|
||||
|
|
|
|||
|
|
@ -5,10 +5,6 @@ val stack_create : unit -> stack
|
|||
val peek : mode -> stack -> int
|
||||
val pop : mode -> stack -> int
|
||||
val push : mode -> stack -> int -> unit
|
||||
val pushbyte : mode -> stack -> int -> unit
|
||||
val pushshort : mode -> stack -> int -> unit
|
||||
val popbyte : mode -> stack -> int
|
||||
val popshort : mode -> stack -> int
|
||||
|
||||
type machine
|
||||
|
||||
|
|
@ -17,14 +13,11 @@ val dev : machine -> bytes
|
|||
val wst : machine -> stack
|
||||
val rst : machine -> stack
|
||||
|
||||
type machine_state = Break | Next of int
|
||||
|
||||
type _ Effect.t +=
|
||||
| BRK : int Effect.t
|
||||
| DEI : ([ `Byte | `Short ] * int) -> int Effect.t
|
||||
| DEO : (int * int) -> unit Effect.t
|
||||
| Trace : (int * Instr.t * int list) -> unit Effect.t
|
||||
| Breakpoint : int -> unit Effect.t
|
||||
|
||||
val create : string -> machine
|
||||
val dispatch : ?trace:bool -> machine -> int -> 'a
|
||||
|
|
|
|||
|
|
@ -5,24 +5,21 @@ type file_state =
|
|||
| Dir_read of Unix.dir_handle * string (* dir_handle, filepath *)
|
||||
| Dir_write
|
||||
|
||||
type file_device = {
|
||||
type state = {
|
||||
mutable filepath : string option;
|
||||
mutable state : file_state;
|
||||
mutable length : int;
|
||||
}
|
||||
|
||||
module type ADDR = sig
|
||||
val start_addr : int
|
||||
val start : int
|
||||
end
|
||||
|
||||
module Make (Addr : ADDR) : Uxn.Device.DEVICE with type state = file_device =
|
||||
struct
|
||||
type state = file_device
|
||||
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_addr && port <= Addr.start_addr + 0x0f
|
||||
let can_handle port = port >= Addr.start && port <= Addr.start + 0x0f
|
||||
|
||||
let read_cstring ram addr =
|
||||
let buf = Buffer.create 256 in
|
||||
|
|
@ -204,17 +201,15 @@ struct
|
|||
let open Uxn in
|
||||
let ram = Machine.ram mach in
|
||||
let dev = Machine.dev mach in
|
||||
let with_success result =
|
||||
file_success dev (Addr.start_addr + 0x02) result
|
||||
in
|
||||
match port - Addr.start_addr with
|
||||
let with_success result = file_success dev (Addr.start + 0x02) result in
|
||||
match port - Addr.start with
|
||||
| 0x0a -> state.length <- value
|
||||
| 0x04 -> file_stat (Machine.ram mach) value state.length |> with_success
|
||||
| 0x06 -> file_delete () |> with_success
|
||||
| 0x08 -> file_init (Machine.ram mach) value |> with_success
|
||||
| 0x0c -> file_read (Machine.ram mach) value state.length |> with_success
|
||||
| 0x0e ->
|
||||
let append = Bytes.get_uint8 dev (Addr.start_addr + 0x07) in
|
||||
let append = Bytes.get_uint8 dev (Addr.start + 0x07) in
|
||||
file_write ram value state.length append |> with_success
|
||||
| _ -> ()
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,9 +9,13 @@ module Make () : Uxn.Device.DEVICE with type state = state = struct
|
|||
let can_handle port = port >= 0x00 && port <= 0x0f
|
||||
|
||||
let print_stack ~name (Machine.Stack { data; sp }) =
|
||||
Fmt.epr "%s: @[%a@]@." name
|
||||
(Fmt.on_bytes (Fmt.octets ()))
|
||||
(Bytes.sub data 0 sp)
|
||||
Printf.eprintf "%s " name;
|
||||
for i = sp - 8 to sp - 1 do
|
||||
Printf.eprintf "%02x%s"
|
||||
(Bytes.get_uint8 data (i land 0xff))
|
||||
(if i land 0xff == 0xff then "|" else " ")
|
||||
done;
|
||||
Printf.eprintf "<%02x\n" sp
|
||||
|
||||
let get_bank mach bank =
|
||||
if bank = 0 then Machine.ram mach
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
(library
|
||||
(name varvara)
|
||||
(libraries uxn fmt unix))
|
||||
(libraries uxn unix))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue