From b87b5a344889e95638b1e490c49f5862c8fb2fee Mon Sep 17 00:00:00 2001 From: Ry Date: Mon, 25 Apr 2022 21:46:47 -0700 Subject: [PATCH] monitor: Proper command parsing --- monitor/commands/commands.asm | 21 +++++++++++++++++++++ monitor/commands/exit.asm | 6 ++++++ monitor/commands/help.asm | 15 +++++++++++++++ monitor/monitor.asm | 15 ++++++++++++--- monitor/shell.asm | 12 +++++------- 5 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 monitor/commands/commands.asm create mode 100644 monitor/commands/exit.asm create mode 100644 monitor/commands/help.asm diff --git a/monitor/commands/commands.asm b/monitor/commands/commands.asm new file mode 100644 index 0000000..94c2de3 --- /dev/null +++ b/monitor/commands/commands.asm @@ -0,0 +1,21 @@ +; command parser + +; FIXME: thjs is a terrible way to do this +monitor_shell_parse_command: + mov r0, MONITOR_SHELL_TEXT_BUF_BOTTOM + + ; exit + mov r1, monitor_shell_exit_command_string + call compare_string + ifz jmp monitor_shell_exit_command + + ; help + mov r1, monitor_shell_help_command_string + call compare_string + ifz jmp monitor_shell_help_command + + ret + + ; all commands + #include "monitor/commands/exit.asm" + #include "monitor/commands/help.asm" diff --git a/monitor/commands/exit.asm b/monitor/commands/exit.asm new file mode 100644 index 0000000..2b2f0a7 --- /dev/null +++ b/monitor/commands/exit.asm @@ -0,0 +1,6 @@ +; exit command + +monitor_shell_exit_command_string: data.str "exit" data.8 0 + +monitor_shell_exit_command: + jmp exit_monitor diff --git a/monitor/commands/help.asm b/monitor/commands/help.asm new file mode 100644 index 0000000..1c93d5a --- /dev/null +++ b/monitor/commands/help.asm @@ -0,0 +1,15 @@ +; help command + +monitor_shell_help_command_string: data.str "help" data.8 0 + +monitor_shell_help_command: + mov r0, monitor_shell_help_text + call print_string_to_monitor + ret + +monitor_shell_help_text: + data.str "command | description" data.8 10 + data.str "------- | -----------" data.8 10 + data.str "exit | exit the monitor" data.8 10 + data.str "help | display this help text" data.8 10 + data.8 0 diff --git a/monitor/monitor.asm b/monitor/monitor.asm index 696a2fc..e16cc7d 100644 --- a/monitor/monitor.asm +++ b/monitor/monitor.asm @@ -46,20 +46,29 @@ invoke_monitor: mov r5, 31 call draw_filled_rectangle_to_overlay - call monitor_shell_start + call redraw_monitor_console - ; restore the old vsync handler and exit + mov [MONITOR_OLD_RSP], rsp + jmp monitor_shell_start +exit_monitor: + ; restore the old RSP and vsync handler, reset the cursor, and exit + mov rsp, [MONITOR_OLD_RSP] mov [0x000003FC], [MONITOR_OLD_VSYNC_HANDLER] + + call enable_cursor + ret info_str: data.str "fox32rom monitor" data.8 0x00 + #include "monitor/commands/commands.asm" #include "monitor/console.asm" #include "monitor/keyboard.asm" #include "monitor/shell.asm" #include "monitor/vsync.asm" -const MONITOR_OLD_VSYNC_HANDLER: 0x03ED36C6 ; 4 bytes +const MONITOR_OLD_RSP: 0x03ED36BD ; 4 bytes +const MONITOR_OLD_VSYNC_HANDLER: 0x03ED36C1 ; 4 bytes const MONITOR_BACKGROUND_COLOR: 0xFF282828 diff --git a/monitor/shell.asm b/monitor/shell.asm index d1a3bb8..19412c4 100644 --- a/monitor/shell.asm +++ b/monitor/shell.asm @@ -46,6 +46,10 @@ monitor_shell_key_down_event: monitor_shell_key_down_event_enter: mov r0, 10 ; line feed call print_character_to_monitor + + mov r0, 0 + call monitor_shell_push_character + call monitor_shell_parse_line call monitor_shell_clear_buffer mov r0, monitor_shell_prompt @@ -85,15 +89,9 @@ monitor_shell_parse_line: call monitor_shell_tokenize mov [MONTIOR_SHELL_ARGS_PTR], r0 - mov r0, MONITOR_SHELL_TEXT_BUF_BOTTOM - mov r1, test_string - call compare_string - ifz mov r0, test_working - ifz call print_string_to_monitor + call monitor_shell_parse_command ret -test_string: data.str "test" data.8 0 -test_working: data.str "it's working!!!" data.8 10 data.8 0 ; return tokens separated by the specified character ; returns the next token in the list