monitor: Proper command parsing

This commit is contained in:
Ry 2022-04-25 21:46:47 -07:00
parent e5c98ddd69
commit b87b5a3448
5 changed files with 59 additions and 10 deletions

View File

@ -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"

View File

@ -0,0 +1,6 @@
; exit command
monitor_shell_exit_command_string: data.str "exit" data.8 0
monitor_shell_exit_command:
jmp exit_monitor

15
monitor/commands/help.asm Normal file
View File

@ -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

View File

@ -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

View File

@ -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