From 461c09f1e58345f3c5329a925fa80bbe943b6bb0 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Sun, 14 Apr 2019 14:24:29 -0400 Subject: [PATCH] Decouple shell from acia --- parts/README.md | 14 ++++++++++++++ parts/acia.asm | 2 +- parts/shell.asm | 17 ++++++++++------- recipes/rc2014.md | 6 ++++++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/parts/README.md b/parts/README.md index a70f056..77010d3 100644 --- a/parts/README.md +++ b/parts/README.md @@ -35,4 +35,18 @@ Thus, code that glue parts together coould look like: MOD2_RAMSTART .equ MOD1_RAMEND #include "mod2.asm" +## Code style + +The asm code used in these parts is heavily dependent on what scas offers. I +try to be as "low-tech" as possible because the implementation of the assembler +to be implemented for the z80 will likely be more limited. For example, I try +to avoid macros. + +One exception, however, is for the routine hooks (`SHELL_GETC` for example). At +first, I wanted to assign a label to a const (`SHELL_GETC .equ aciaGetC` for +example), but it turns out that scas doesn't support this (but it could: label +addresses are known at compile time and thus can be consts (maybe at the cost +of an extra pass though)). I went for macros instead, but that doesn't mean +that the z80 assembler will need to support macros. It just need to support +labels-as-consts. [scas]: https://github.com/KnightOS/scas diff --git a/parts/acia.asm b/parts/acia.asm index 3aade58..dd8de21 100644 --- a/parts/acia.asm +++ b/parts/acia.asm @@ -115,7 +115,7 @@ aciaGetC: call aciaIncIndex ld (ACIA_BUFRDIDX), a - ; And finially, fetch the value. + ; And finally, fetch the value. ld a, (de) pop de diff --git a/parts/shell.asm b/parts/shell.asm index 77ffca8..e174ca5 100644 --- a/parts/shell.asm +++ b/parts/shell.asm @@ -1,20 +1,23 @@ ; shell ; -; Runs a shell over an asynchronous communication interface adapter (ACIA). -; for now, this unit is tightly coupled to acia.asm, but it will eventually be -; more general than that. +; Runs a shell over an block device interface. ; Status: incomplete. As it is now, it spits a welcome prompt, wait for input ; and compare the first 4 chars of the input with a command table and call the ; appropriate routine if it's found, an error if it's not. ; -; Commands, for now, are dummy. +; Commands, for now, are partially implemented. ; ; See constants below for error codes. ; ; All numerical values in the Collapse OS shell are represented and parsed in ; hexadecimal form, without prefix or suffix. +; *** DEFINES *** +; SHELL_GETC: Macro that calls a GetC routine +; SHELL_PUTC: Macro that calls a PutC routine +; SHELL_RAMSTART + ; *** CONSTS *** ; number of entries in shellCmdTbl @@ -61,7 +64,7 @@ shellInit: shellLoop: ; First, let's wait until something is typed. - call aciaGetC + SHELL_GETC ; got it. Now, is it a CR or LF? cp ASCII_CR jr z, .do ; char is CR? do! @@ -100,9 +103,9 @@ shellLoop: printcrlf: ld a, ASCII_CR - call aciaPutC + SHELL_PUTC ld a, ASCII_LF - call aciaPutC + SHELL_PUTC ret ; Parse command (null terminated) at HL and calls it diff --git a/recipes/rc2014.md b/recipes/rc2014.md index 7dcc4e0..ed55cfa 100644 --- a/recipes/rc2014.md +++ b/recipes/rc2014.md @@ -67,6 +67,8 @@ init: ACIA_RAMSTART .equ RAMSTART #include "acia.asm" SHELL_RAMSTART .equ ACIA_RAMEND +.define SHELL_GETC call aciaGetC +.define SHELL_PUTC call aciaPutC #include "shell.asm" ``` @@ -89,6 +91,10 @@ What comes below is actual code include from parts we want to include in our OS. As you can see, we need to tell each module where to put their variables. See `parts/README.md` for details. +You can also see from the `SHELL_GETC` and `SHELL_PUTC` macros that the shell +is decoupled from the ACIA and can get its IO from anything. See +`parts/README.md` for details. + ### Build the image We only have the shell to build, so it's rather straightforward: