From 336f2fe1813cb662ddefedc07fbf9061ec027a3b Mon Sep 17 00:00:00 2001 From: Daniele Verducci su MatissePenguin Date: Wed, 25 Nov 2020 19:39:20 +0100 Subject: [PATCH] First working interactive shell for memory monitor --- .../arduino_terminal.asm} | 2 +- .../hd44780.asm} | 0 .../keyboard.asm} | 0 assembly/bios/libs/strings.asm | 23 ++++++++++ assembly/bios/main.asm | 34 +++----------- assembly/bios/monitor.asm | 44 +++++++++++++------ 6 files changed, 60 insertions(+), 43 deletions(-) rename assembly/bios/{driver_arduino_terminal.asm => drivers/arduino_terminal.asm} (97%) rename assembly/bios/{driver_hd44780.asm => drivers/hd44780.asm} (100%) rename assembly/bios/{driver_keyboard.asm => drivers/keyboard.asm} (100%) create mode 100644 assembly/bios/libs/strings.asm diff --git a/assembly/bios/driver_arduino_terminal.asm b/assembly/bios/drivers/arduino_terminal.asm similarity index 97% rename from assembly/bios/driver_arduino_terminal.asm rename to assembly/bios/drivers/arduino_terminal.asm index d481eb2..04d3af8 100644 --- a/assembly/bios/driver_arduino_terminal.asm +++ b/assembly/bios/drivers/arduino_terminal.asm @@ -52,6 +52,6 @@ Term_readline: inc bc ; point to next array position jp Term_readline term_readline_foundcr: ; called when carriage return was found (end of line) - ld (bc), 0 ; Null-terminate string + ;ld (bc), 0 ; Null-terminate string ld bc, incoming_string ; Returns read string pointer ret diff --git a/assembly/bios/driver_hd44780.asm b/assembly/bios/drivers/hd44780.asm similarity index 100% rename from assembly/bios/driver_hd44780.asm rename to assembly/bios/drivers/hd44780.asm diff --git a/assembly/bios/driver_keyboard.asm b/assembly/bios/drivers/keyboard.asm similarity index 100% rename from assembly/bios/driver_keyboard.asm rename to assembly/bios/drivers/keyboard.asm diff --git a/assembly/bios/libs/strings.asm b/assembly/bios/libs/strings.asm new file mode 100644 index 0000000..dc530f6 --- /dev/null +++ b/assembly/bios/libs/strings.asm @@ -0,0 +1,23 @@ +; Strings manipulation library +; @author Daniele Verducci + +; Transforms case to upper + +Strings_strToUpper: + ; TODO + ret + +Strings_strToLower: + ; TODO + ret + +; Transforms character in A to uppercase. If is not a character, returns as is +; @param A character to transform +; @return A upper char +Strings_charToUpper: + ; TODO + ret + +Strings_charToLower: + ; TODO + ret diff --git a/assembly/bios/main.asm b/assembly/bios/main.asm index 8d9ff75..23111a2 100644 --- a/assembly/bios/main.asm +++ b/assembly/bios/main.asm @@ -37,17 +37,12 @@ IO_7: EQU 0xE0 -; CONSTANTS -SYSINIT_GREETING: - DB "Pat80",10,0 ; null terminated string - - -;include 'driver_hd44780.asm' -;include 'driver_keyboard.asm' -include 'driver_arduino_terminal.asm' +;include 'drivers/hd44780.asm' +;include 'drivers/keyboard.asm' +include 'drivers/arduino_terminal.asm' include 'monitor.asm' ; SYSTEM CALLS @@ -79,23 +74,6 @@ Readline: ; System initialization Sysinit: - ld bc, SYSINIT_GREETING - call Print - - _io_test_loop: - call Readline - call Print - - ; call Printc - ; call Readline - ; ld a, (bc) - ; cp a, 0 - ; jp z, _io_test_loop - ; ld (APP_VAR_SPACE), bc - ; ld bc, SAYS - ; call Print - ; ld bc, (APP_VAR_SPACE) - ; call Print - jp _io_test_loop - - + ; Start Monitor + call Monitor_main + halt diff --git a/assembly/bios/monitor.asm b/assembly/bios/monitor.asm index b366dc9..12f6faf 100644 --- a/assembly/bios/monitor.asm +++ b/assembly/bios/monitor.asm @@ -9,38 +9,54 @@ ; R (RUN) $pos Starts executing code from $pos ; The commands are entered with a single letter and the program completes the command +include 'libs/strings.asm' + ; CONSTANTS ; All monitor commands are 3 chars long. -MON_WELCOME: DB "PAT80 MEmory MOnitor 0.1" +MON_WELCOME: DB "PAT80 MEMORY MONITOR 0.1",10,0 MON_COMMAND_HELP: DB "HELP",0 ; null terminated strings -MON_COMMAND_DUMP: DB "DUMP",0 ; null terminated strings +MON_COMMAND_DUMP: DB "DUMP",0 MON_COMMAND_SET: DB "SET",0 MON_COMMAND_LOAD: DB "LOAD",0 MON_COMMAND_RUN: DB "RUN",0 MON_ARG_HEX: DB "0x",0 -MON_HELP: DB "Available commands: HELP, DUMP, SET, LOAD, RUN" +MON_HELP: DB 10,"Available commands: HELP, DUMP, SET, LOAD, RUN",0 +MON_ERR_SYNTAX: DB " Syntax error",0 Monitor_main: ; Print welcome string ld bc, MON_WELCOME call Print monitor_main_loop: + ; Newline + ld a, 10 + call Printc ; Draw prompt char ld a, 62 ; > call Printc ; Read char from command line - call Readc: ; blocking: returns when a character was read and placed in A reg + 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 ; Switch case - cp (MON_COMMAND_HELP) ; check incoming char is equal to command's first char + ld hl, MON_COMMAND_HELP + cp (hl) ; check incoming char is equal to command's first char jp z, monitor_help - cp (MON_COMMAND_DUMP) + ld hl, MON_COMMAND_DUMP + cp (hl) jp z, monitor_dump - cp (MON_COMMAND_SET) + ld hl, MON_COMMAND_SET + cp (hl) jp z, monitor_set - cp (MON_COMMAND_LOAD) + ld hl, MON_COMMAND_LOAD + cp (hl) jp z, monitor_load - cp (MON_COMMAND_RUN) + ld hl, MON_COMMAND_RUN + cp (hl) jp z, monitor_run + ; Unrecognized command: print error + ld bc, MON_ERR_SYNTAX + call Print jp monitor_main_loop monitor_help: @@ -49,28 +65,28 @@ monitor_help: ld bc, MON_HELP call Print - ret + jp monitor_main_loop monitor_dump: ld bc, MON_COMMAND_DUMP + 1 ; autocomplete command call Print - ret + jp monitor_main_loop monitor_set: ld bc, MON_COMMAND_SET + 1 ; autocomplete command call Print - ret + jp monitor_main_loop monitor_load: ld bc, MON_COMMAND_LOAD + 1 ; autocomplete command call Print - ret + jp monitor_main_loop monitor_run: ld bc, MON_COMMAND_RUN + 1 ; autocomplete command call Print jp APP_VAR_SPACE ; Start executing code - ret + jp monitor_main_loop