fix DUPk not working (use pop instead of peek)
This commit is contained in:
parent
9ee039f413
commit
5d28728e61
3 changed files with 19 additions and 23 deletions
|
|
@ -3,6 +3,11 @@ open Effect.Deep
|
|||
|
||||
let debug = Option.is_some (Sys.getenv_opt "DBG")
|
||||
|
||||
let print_stack ~name (Machine.Stack { data; sp }) =
|
||||
Fmt.epr "%s: @[%a@]@." name
|
||||
(Fmt.on_bytes (Fmt.octets ()))
|
||||
(Bytes.sub data 0 sp)
|
||||
|
||||
let rec run m pc =
|
||||
let dev = Machine.dev m in
|
||||
let console_vector = ref 0 in
|
||||
|
|
@ -13,7 +18,7 @@ let rec run m pc =
|
|||
in
|
||||
try Machine.dispatch ~trace:debug m pc with
|
||||
| effect Machine.Trace (pc, instr, args), k when debug ->
|
||||
Fmt.epr "PC = %04x | %6s : %a\n" pc (Instr.to_string instr)
|
||||
Fmt.epr "PC = %04x | %6s : %a@." pc (Instr.to_string instr)
|
||||
(Fmt.list ~sep:(Fmt.any " ") (Fmt.fmt "%02x"))
|
||||
args;
|
||||
Out_channel.flush stderr;
|
||||
|
|
@ -37,12 +42,8 @@ let rec run m pc =
|
|||
| effect Machine.DEO (port, value), k ->
|
||||
(match port with
|
||||
| 0x10 -> console_vector := value
|
||||
| 0x18 ->
|
||||
print_char (Char.chr value);
|
||||
Out_channel.flush stdout
|
||||
| 0x19 ->
|
||||
prerr_char (Char.chr value);
|
||||
Out_channel.flush stderr
|
||||
| 0x18 -> print_char (Char.chr value)
|
||||
| 0x19 -> prerr_char (Char.chr value)
|
||||
| _ -> ());
|
||||
continue k ()
|
||||
|
||||
|
|
@ -54,11 +55,17 @@ let main () =
|
|||
let code =
|
||||
In_channel.with_open_bin Sys.argv.(1) (fun i -> In_channel.input_all i)
|
||||
in
|
||||
|
||||
In_channel.set_binary_mode stdin true;
|
||||
Out_channel.set_binary_mode stdout true;
|
||||
|
||||
let mach = Machine.create code in
|
||||
Bytes.set (Machine.dev mach) 0 '\x00';
|
||||
run mach 0x100;
|
||||
if debug then begin
|
||||
print_stack ~name:"wst" (Machine.wst mach);
|
||||
print_stack ~name:"rst" (Machine.rst mach)
|
||||
end;
|
||||
exit (Bytes.get_uint8 (Machine.dev mach) 0x0f land 0x7f)
|
||||
|
||||
let _ = main ()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue