make #010e DEO print stack in the recommended repr

This commit is contained in:
Lobo 2025-12-18 15:50:34 -03:00
parent b71cf4343e
commit bc1bae5977
8 changed files with 837 additions and 52 deletions

View file

@ -9,28 +9,22 @@ module Console = Varvara.Console.Make ()
module File =
Uxn.Device.Compose
(Varvara.File.Make (struct
let start_addr = 0xa0
let start = 0xa0
end))
(Varvara.File.Make (struct
let start_addr = 0xb0
let start = 0xb0
end))
module Devices =
Uxn.Device.Compose (Uxn.Device.Compose (System) (Console)) (File)
let print_stack ~name (Machine.Stack { data; sp }) =
Fmt.epr "%s: @[%a@]@." name
(Fmt.on_bytes (Fmt.octets ()))
(Bytes.sub data 0 sp)
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
Fmt.epr "PC = %04x | %6s %a@." pc (Instr.to_string instr)
(Fmt.list ~sep:(Fmt.any " ") (Fmt.fmt "%02x"))
args;
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 ()
@ -49,7 +43,7 @@ let run m pc =
let main () =
if Array.length Sys.argv < 2 then (
Fmt.epr "usage: uxnemu file.rom ...\n";
Printf.eprintf "usage: uxnemu file.rom ...\n";
exit 1);
let code =
@ -92,11 +86,6 @@ let main () =
done
with Exit -> console_input 0 4
end;
if trace then begin
print_stack ~name:"wst" (Machine.wst mach);
print_stack ~name:"rst" (Machine.rst mach)
end;
exit (Bytes.get_uint8 dev 0x0f land 0x7f)
let _ = main ()