Merge pull request #13 from mebibytedraco/command-asm-refactor

Refactor monitor/commands/commands.asm
This commit is contained in:
Ry 2023-12-22 20:47:56 -08:00 committed by GitHub
commit f8e2fa453b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,53 +1,20 @@
; command parser ; command parser
; FIXME: thjs is a terrible way to do this
monitor_shell_parse_command: monitor_shell_parse_command:
mov r0, MONITOR_SHELL_TEXT_BUF_BOTTOM mov r0, MONITOR_SHELL_TEXT_BUF_BOTTOM
; exit ; loop over the table of commands
mov r1, monitor_shell_exit_command_string mov r2, monitor_shell_command_table
monitor_shell_parse_command_loop:
mov r1, [r2]
call compare_string call compare_string
ifz jmp monitor_shell_exit_command ; if the string matches, jump to the corresponding address in the table
ifz jmp [r2+4]
; help ; otherwise, move to the next entry
mov r1, monitor_shell_help_command_string add r2, 8
call compare_string ; if the entry is zero, then we have reached the end of the table
ifz jmp monitor_shell_help_command cmp [r2], 0
ifnz jmp monitor_shell_parse_command_loop
; jump
mov r1, monitor_shell_jump_command_string
call compare_string
ifz jmp monitor_shell_jump_command
; list
mov r1, monitor_shell_list_command_string
call compare_string
ifz jmp monitor_shell_list_command
; load
mov r1, monitor_shell_load_command_string
call compare_string
ifz jmp monitor_shell_load_command
; reg
mov r1, monitor_shell_reg_command_string
call compare_string
ifz jmp monitor_shell_reg_command
; set.8
mov r1, monitor_shell_set8_command_string
call compare_string
ifz jmp monitor_shell_set8_command
; set.16
mov r1, monitor_shell_set16_command_string
call compare_string
ifz jmp monitor_shell_set16_command
; set.32
mov r1, monitor_shell_set32_command_string
call compare_string
ifz jmp monitor_shell_set32_command
; invalid command ; invalid command
mov r0, monitor_shell_invalid_command_string mov r0, monitor_shell_invalid_command_string
@ -56,6 +23,26 @@ monitor_shell_parse_command:
ret ret
monitor_shell_command_table:
data.32 monitor_shell_exit_command_string
data.32 monitor_shell_exit_command
data.32 monitor_shell_help_command_string
data.32 monitor_shell_help_command
data.32 monitor_shell_jump_command_string
data.32 monitor_shell_jump_command
data.32 monitor_shell_list_command_string
data.32 monitor_shell_list_command
data.32 monitor_shell_load_command_string
data.32 monitor_shell_load_command
data.32 monitor_shell_reg_command_string
data.32 monitor_shell_reg_command
data.32 monitor_shell_set8_command_string
data.32 monitor_shell_set8_command
data.32 monitor_shell_set16_command_string
data.32 monitor_shell_set16_command
data.32 monitor_shell_set32_command_string
data.32 monitor_shell_set32_command
data.32 0 data.32 0
monitor_shell_invalid_command_string: data.str "invalid command" data.8 10 data.8 0 monitor_shell_invalid_command_string: data.str "invalid command" data.8 10 data.8 0
; all commands ; all commands