Working hex parsing in monitor
This commit is contained in:
parent
336f2fe181
commit
229ba1d48d
@ -5,7 +5,7 @@
|
|||||||
; H (HELP) Shows available commands
|
; H (HELP) Shows available commands
|
||||||
; D (DUMP) $pos Dumps first 100 bytes of memory starting at $pos
|
; D (DUMP) $pos Dumps first 100 bytes of memory starting at $pos
|
||||||
; S (SET) $pos $val Replaces byte at $pos with $val
|
; S (SET) $pos $val Replaces byte at $pos with $val
|
||||||
; L (LOAD) $pos $val Loads all the incoming bytes in memory starting from $pos
|
; L (LOAD) $pos $val Loads all the incoming bytes in memory starting from $pos. Ends when "0" is received 8 times.
|
||||||
; R (RUN) $pos Starts executing code from $pos
|
; R (RUN) $pos Starts executing code from $pos
|
||||||
; The commands are entered with a single letter and the program completes the command
|
; The commands are entered with a single letter and the program completes the command
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ MON_COMMAND_DUMP: DB "DUMP",0
|
|||||||
MON_COMMAND_SET: DB "SET",0
|
MON_COMMAND_SET: DB "SET",0
|
||||||
MON_COMMAND_LOAD: DB "LOAD",0
|
MON_COMMAND_LOAD: DB "LOAD",0
|
||||||
MON_COMMAND_RUN: DB "RUN",0
|
MON_COMMAND_RUN: DB "RUN",0
|
||||||
MON_ARG_HEX: DB "0x",0
|
MON_ARG_HEX: DB " 0x",0
|
||||||
MON_HELP: DB 10,"Available commands: HELP, DUMP, SET, LOAD, RUN",0
|
MON_HELP: DB 10,"Available commands: HELP, DUMP, SET, LOAD, RUN",0
|
||||||
MON_ERR_SYNTAX: DB " Syntax error",0
|
MON_ERR_SYNTAX: DB " Syntax error",0
|
||||||
|
|
||||||
@ -70,6 +70,7 @@ monitor_help:
|
|||||||
monitor_dump:
|
monitor_dump:
|
||||||
ld bc, MON_COMMAND_DUMP + 1 ; autocomplete command
|
ld bc, MON_COMMAND_DUMP + 1 ; autocomplete command
|
||||||
call Print
|
call Print
|
||||||
|
call monitor_arg_byte
|
||||||
jp monitor_main_loop
|
jp monitor_main_loop
|
||||||
|
|
||||||
monitor_set:
|
monitor_set:
|
||||||
@ -88,5 +89,56 @@ monitor_run:
|
|||||||
jp APP_VAR_SPACE ; Start executing code
|
jp APP_VAR_SPACE ; Start executing code
|
||||||
jp monitor_main_loop
|
jp monitor_main_loop
|
||||||
|
|
||||||
|
monitor_arg_byte:
|
||||||
|
; Print 0x... prompt
|
||||||
|
ld bc, MON_ARG_HEX
|
||||||
|
call Print
|
||||||
|
; Receive two hex digits
|
||||||
|
call monitor_readHexDigit
|
||||||
|
call monitor_readHexDigit
|
||||||
|
ret
|
||||||
|
|
||||||
|
monitor_arg_2byte:
|
||||||
|
; Print 0x... prompt
|
||||||
|
ld bc, MON_ARG_HEX
|
||||||
|
call Print
|
||||||
|
; Receive four hex digits
|
||||||
|
call monitor_readHexDigit
|
||||||
|
call monitor_readHexDigit
|
||||||
|
call monitor_readHexDigit
|
||||||
|
call monitor_readHexDigit
|
||||||
|
ret
|
||||||
|
|
||||||
|
monitor_readHexDigit:
|
||||||
|
call Readc
|
||||||
|
; check if is a valid hex digit (0-9 -> ascii codes 48 to 57; A-F -> ascii codes 65 to 70)
|
||||||
|
; first check if is between 0 and F(ascii codes 48 to 70)
|
||||||
|
ld b, a
|
||||||
|
sub a, 48
|
||||||
|
jp m, monitor_readHexDigit ; if negative (s), ascii code is under 48: ignore char
|
||||||
|
ld a, b
|
||||||
|
sub a, 71 ; 71 because we want to include 70 and the result must be negative
|
||||||
|
jp p, monitor_readHexDigit ; if not negative (ns), ascii code is over 70: ignore it
|
||||||
|
; check if is a valid int (<=57)
|
||||||
|
ld a, b
|
||||||
|
sub a, 58
|
||||||
|
jp p, monitor_readHexDigit_char ; if not negative (ns), maybe is a char
|
||||||
|
; otherwise is a number! First print for visive feedback
|
||||||
|
ld a, b
|
||||||
|
call Printc
|
||||||
|
; then convert to its value subtracting 48
|
||||||
|
sub a, 48
|
||||||
|
ret
|
||||||
|
monitor_readHexDigit_char:
|
||||||
|
; check if is A, B, C, D, E, F (ascii codes 65 to 70). We already checked it is less than 70.
|
||||||
|
ld a, b
|
||||||
|
sub a, 65
|
||||||
|
jp m, monitor_readHexDigit ; if negative (s), ascii code is under 65: ignore char
|
||||||
|
; otherwise is a valid char (A-F). Print for visive feedback
|
||||||
|
ld a, b
|
||||||
|
call Printc
|
||||||
|
; Its numeric value is 10 (A) to 15 (F). To obtain this, subtract 55.
|
||||||
|
sub a, 55
|
||||||
|
ret
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user