...
This commit is contained in:
parent
ad589d2894
commit
0c0bcb7e73
3 changed files with 19 additions and 20 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
*.rom
|
*.rom
|
||||||
*.rom.sym
|
*.rom.sym
|
||||||
/_build
|
/_build
|
||||||
/uxn-utils/uxnmin
|
/utils/uxnmin
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ let print_stack ?(name = "wst") (Machine.Stack stack) =
|
||||||
let stack = Bytes.to_seq stack.data |> Seq.take stack.sp |> Bytes.of_seq in
|
let stack = Bytes.to_seq stack.data |> Seq.take stack.sp |> Bytes.of_seq in
|
||||||
Fmt.epr "@[%s: [@[%a@]]@]@." name (Fmt.on_bytes (Fmt.octets ())) stack
|
Fmt.epr "@[%s: [@[%a@]]@]@." name (Fmt.on_bytes (Fmt.octets ())) stack
|
||||||
|
|
||||||
let print_instruction i pc = Fmt.epr "%6s (PC = %04x)@." (Instr.to_string i) pc
|
let print_instruction i pc =
|
||||||
|
Fmt.epr "%6s (%02x) (PC = %04x)@." (Instr.to_string i) (Instr.to_int i) pc
|
||||||
|
|
||||||
let debug = Option.is_some (Sys.getenv_opt "DBG")
|
let debug = Option.is_some (Sys.getenv_opt "DBG")
|
||||||
let console_vector = ref 0
|
let console_vector = ref 0
|
||||||
|
|
||||||
|
|
@ -22,29 +24,27 @@ let dispatch =
|
||||||
else Machine.dispatch ~dbg:None
|
else Machine.dispatch ~dbg:None
|
||||||
|
|
||||||
let eval m pc =
|
let eval m pc =
|
||||||
let console_input mach ch ty k =
|
let dev = Machine.dev m in
|
||||||
Bytes.set_uint8 (Machine.dev mach) 0x12 ch;
|
let continue_with_console ch ty k =
|
||||||
Bytes.set_uint8 (Machine.dev mach) 0x17 ty;
|
Bytes.set_uint8 dev 0x12 ch;
|
||||||
if !console_vector != 0 && Bytes.get_uint8 (Machine.dev mach) 0x0f = 0 then
|
Bytes.set_uint8 dev 0x17 ty;
|
||||||
continue k !console_vector
|
if !console_vector != 0 && Bytes.get_uint8 dev 0x0f = 0 then (
|
||||||
|
Fmt.epr "Continuing with console vector!\n";
|
||||||
|
continue k !console_vector)
|
||||||
in
|
in
|
||||||
try dispatch m pc with
|
try dispatch m pc with
|
||||||
| effect Machine.BRK, k ->
|
| effect Machine.BRK, _ when Bytes.get_uint8 dev 0x0f != 0 -> ()
|
||||||
if !console_vector != 0 then (
|
| effect Machine.BRK, k -> (
|
||||||
|
if !console_vector != 0 then
|
||||||
try
|
try
|
||||||
while Bytes.get_uint8 (Machine.dev m) 0x0f = 0 do
|
while Bytes.get_uint8 dev 0x0f = 0 do
|
||||||
match In_channel.input_char stdin with
|
match In_channel.input_char stdin with
|
||||||
| None -> raise Exit
|
| None -> raise Exit
|
||||||
| Some c -> console_input m (Char.code c) 1 k
|
| Some c -> continue_with_console (Char.code c) 1 k
|
||||||
done
|
done
|
||||||
with Exit ->
|
with Exit -> continue_with_console 0 4 k)
|
||||||
Bytes.set_uint8 (Machine.dev m) 0x12 0;
|
| effect Machine.DEI port, k -> continue k (Bytes.get_uint8 dev port)
|
||||||
Bytes.set_uint8 (Machine.dev m) 0x17 4;
|
| effect Machine.DEI2 port, k -> continue k (Util.get_uint16_wrap dev port)
|
||||||
continue k !console_vector)
|
|
||||||
| effect Machine.DEI port, k ->
|
|
||||||
continue k (Bytes.get_uint8 (Machine.dev m) port)
|
|
||||||
| effect Machine.DEI2 port, k ->
|
|
||||||
continue k (Util.get_uint16_wrap (Machine.dev m) port)
|
|
||||||
| effect Machine.DEO (port, value), k ->
|
| effect Machine.DEO (port, value), k ->
|
||||||
(match port with
|
(match port with
|
||||||
| 0x10 -> console_vector := value
|
| 0x10 -> console_vector := value
|
||||||
|
|
@ -69,7 +69,6 @@ let main () =
|
||||||
Out_channel.set_binary_mode stdout true;
|
Out_channel.set_binary_mode stdout true;
|
||||||
|
|
||||||
let mach = Machine.create code in
|
let mach = Machine.create code in
|
||||||
Bytes.set_uint8 (Machine.dev mach) 0x17 0;
|
|
||||||
eval mach 0x100;
|
eval mach 0x100;
|
||||||
|
|
||||||
if debug then (
|
if debug then (
|
||||||
|
|
|
||||||
BIN
utils/uxnmin
BIN
utils/uxnmin
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue