2020-11-23 08:47:23 +01:00
|
|
|
; Pat80 Memory Monitor
|
|
|
|
; @author Daniele Verducci
|
|
|
|
;
|
|
|
|
; Monitor commands (CMD $arg):
|
2020-11-25 08:53:41 +01:00
|
|
|
; H (HELP) Shows available commands
|
|
|
|
; D (DUMP) $pos Dumps first 100 bytes of memory starting at $pos
|
|
|
|
; S (SET) $pos $val Replaces byte at $pos with $val
|
|
|
|
; L (LOAD) $pos $val Loads all the incoming bytes in memory starting from $pos
|
|
|
|
; R (RUN) $pos Starts executing code from $pos
|
|
|
|
; The commands are entered with a single letter and the program completes the command
|
2020-11-23 08:47:23 +01:00
|
|
|
|
2020-11-25 19:39:20 +01:00
|
|
|
include 'libs/strings.asm'
|
|
|
|
|
2020-11-23 08:47:23 +01:00
|
|
|
; CONSTANTS
|
|
|
|
; All monitor commands are 3 chars long.
|
2020-11-25 19:39:20 +01:00
|
|
|
MON_WELCOME: DB "PAT80 MEMORY MONITOR 0.1",10,0
|
2020-11-25 08:53:41 +01:00
|
|
|
MON_COMMAND_HELP: DB "HELP",0 ; null terminated strings
|
2020-11-25 19:39:20 +01:00
|
|
|
MON_COMMAND_DUMP: DB "DUMP",0
|
2020-11-25 08:53:41 +01:00
|
|
|
MON_COMMAND_SET: DB "SET",0
|
|
|
|
MON_COMMAND_LOAD: DB "LOAD",0
|
|
|
|
MON_COMMAND_RUN: DB "RUN",0
|
|
|
|
MON_ARG_HEX: DB "0x",0
|
2020-11-25 19:39:20 +01:00
|
|
|
MON_HELP: DB 10,"Available commands: HELP, DUMP, SET, LOAD, RUN",0
|
|
|
|
MON_ERR_SYNTAX: DB " Syntax error",0
|
2020-11-23 08:47:23 +01:00
|
|
|
|
|
|
|
Monitor_main:
|
2020-11-25 08:53:41 +01:00
|
|
|
; Print welcome string
|
|
|
|
ld bc, MON_WELCOME
|
|
|
|
call Print
|
|
|
|
monitor_main_loop:
|
2020-11-25 19:39:20 +01:00
|
|
|
; Newline
|
|
|
|
ld a, 10
|
|
|
|
call Printc
|
2020-11-25 08:53:41 +01:00
|
|
|
; Draw prompt char
|
|
|
|
ld a, 62 ; >
|
|
|
|
call Printc
|
|
|
|
; Read char from command line
|
2020-11-25 19:39:20 +01:00
|
|
|
call Readc ; blocking: returns when a character was read and placed in A reg
|
|
|
|
call Strings_charToUpper ; user may enter lowercase char: transform to upper
|
|
|
|
call Printc ; Print back the character to provide user feedback
|
2020-11-25 08:53:41 +01:00
|
|
|
; Switch case
|
2020-11-25 19:39:20 +01:00
|
|
|
ld hl, MON_COMMAND_HELP
|
|
|
|
cp (hl) ; check incoming char is equal to command's first char
|
2020-11-25 08:53:41 +01:00
|
|
|
jp z, monitor_help
|
2020-11-25 19:39:20 +01:00
|
|
|
ld hl, MON_COMMAND_DUMP
|
|
|
|
cp (hl)
|
2020-11-25 08:53:41 +01:00
|
|
|
jp z, monitor_dump
|
2020-11-25 19:39:20 +01:00
|
|
|
ld hl, MON_COMMAND_SET
|
|
|
|
cp (hl)
|
2020-11-25 08:53:41 +01:00
|
|
|
jp z, monitor_set
|
2020-11-25 19:39:20 +01:00
|
|
|
ld hl, MON_COMMAND_LOAD
|
|
|
|
cp (hl)
|
2020-11-25 08:53:41 +01:00
|
|
|
jp z, monitor_load
|
2020-11-25 19:39:20 +01:00
|
|
|
ld hl, MON_COMMAND_RUN
|
|
|
|
cp (hl)
|
2020-11-25 08:53:41 +01:00
|
|
|
jp z, monitor_run
|
2020-11-25 19:39:20 +01:00
|
|
|
; Unrecognized command: print error
|
|
|
|
ld bc, MON_ERR_SYNTAX
|
|
|
|
call Print
|
2020-11-25 08:53:41 +01:00
|
|
|
jp monitor_main_loop
|
|
|
|
|
|
|
|
monitor_help:
|
|
|
|
ld bc, MON_COMMAND_HELP + 1 ; autocomplete command
|
|
|
|
call Print
|
|
|
|
|
|
|
|
ld bc, MON_HELP
|
|
|
|
call Print
|
2020-11-25 19:39:20 +01:00
|
|
|
jp monitor_main_loop
|
2020-11-25 08:53:41 +01:00
|
|
|
|
|
|
|
monitor_dump:
|
|
|
|
ld bc, MON_COMMAND_DUMP + 1 ; autocomplete command
|
|
|
|
call Print
|
2020-11-25 19:39:20 +01:00
|
|
|
jp monitor_main_loop
|
2020-11-25 08:53:41 +01:00
|
|
|
|
|
|
|
monitor_set:
|
|
|
|
ld bc, MON_COMMAND_SET + 1 ; autocomplete command
|
|
|
|
call Print
|
2020-11-25 19:39:20 +01:00
|
|
|
jp monitor_main_loop
|
2020-11-23 08:47:23 +01:00
|
|
|
|
2020-11-25 08:53:41 +01:00
|
|
|
monitor_load:
|
|
|
|
ld bc, MON_COMMAND_LOAD + 1 ; autocomplete command
|
|
|
|
call Print
|
2020-11-25 19:39:20 +01:00
|
|
|
jp monitor_main_loop
|
2020-11-25 08:53:41 +01:00
|
|
|
|
|
|
|
monitor_run:
|
|
|
|
ld bc, MON_COMMAND_RUN + 1 ; autocomplete command
|
|
|
|
call Print
|
|
|
|
jp APP_VAR_SPACE ; Start executing code
|
2020-11-25 19:39:20 +01:00
|
|
|
jp monitor_main_loop
|
2020-11-25 08:53:41 +01:00
|
|
|
|
|
|
|
|
|
|
|
|