From 2a55bfd375913e445837a5e18e5b1fd9e7e25bbe Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 4 Nov 2019 09:55:12 -0500 Subject: [PATCH] stdio: remove a layer of indirection in GetC/PutC We use zasm's ability to use labels in .equ directive. We didn't do it before because for a while, we were in between scas and zasm (scas was used in automated tests) so we needed to use the lowest common denominator: zasm doesn't have macros and scas can't use labels in .equ directives. This forced us to add this layer of indirection. But now that we are completely cut from scas' dependency, we can use this nice zasm's ability. --- doc/glue-code.md | 58 ++++++++++++++++------------------ kernel/stdio.asm | 38 ++++++++++------------ recipes/rc2014/eeprom/glue.asm | 5 ++- recipes/rc2014/glue.asm | 5 ++- recipes/rc2014/ps2/glue.asm | 5 ++- recipes/rc2014/sdcard/glue.asm | 5 ++- recipes/rc2014/zasm/glue.asm | 5 ++- recipes/sms/glue.asm | 6 ++-- recipes/sms/kbd/glue.asm | 6 ++-- recipes/sms/romasm/glue.asm | 5 ++- tools/emul/shell/shell_.asm | 5 ++- tools/emul/zasm/glue.asm | 5 ++- 12 files changed, 63 insertions(+), 85 deletions(-) diff --git a/doc/glue-code.md b/doc/glue-code.md index 647c7a4..1533adf 100644 --- a/doc/glue-code.md +++ b/doc/glue-code.md @@ -7,47 +7,43 @@ look like: ; The RAM module is selected on A15, so it has the range 0x8000-0xffff - .equ RAMSTART 0x8000 - .equ RAMEND 0xffff - .equ ACIA_CTL 0x80 ; Control and status. RS off. - .equ ACIA_IO 0x81 ; Transmit. RS on. + .equ RAMSTART 0x8000 + .equ RAMEND 0xffff + .equ ACIA_CTL 0x80 ; Control and status. RS off. + .equ ACIA_IO 0x81 ; Transmit. RS on. - jr init + jp init ; interrupt hook .fill 0x38-$ - jp aciaInt + jp aciaInt + + .inc "err.h" + .inc "core.asm" + .inc "parse.asm" + .equ ACIA_RAMSTART RAMSTART + .inc "acia.asm" + + .equ STDIO_RAMSTART ACIA_RAMEND + .equ STDIO_GETC aciaGetC + .equ STDIO_PUTC aciaPutC + .inc "stdio.asm" + + .equ SHELL_RAMSTART STDIO_RAMEND + .equ SHELL_EXTRA_CMD_COUNT 0 + .inc "shell.asm" init: di ; setup stack - ld hl, RAMEND - ld sp, hl + ld hl, RAMEND + ld sp, hl im 1 - call aciaInit - xor a - ld de, BLOCKDEV_SEL - call blkSel - call stdioInit - call shellInit + + call aciaInit + call shellInit ei - jp shellLoop - - #include "core.asm" - .equ ACIA_RAMSTART RAMSTART - #include "acia.asm" - .equ BLOCKDEV_RAMSTART ACIA_RAMEND - .equ BLOCKDEV_COUNT 1 - #include "blockdev.asm" - ; List of devices - .dw aciaGetC, aciaPutC, 0, 0 - - .equ STDIO_RAMSTART BLOCKDEV_RAMEND - #include "stdio.asm" - - .equ SHELL_RAMSTART STDIO_RAMEND - .equ SHELL_EXTRA_CMD_COUNT 0 - #include "shell.asm" + jp shellLoop Once this is written, building it is easy: diff --git a/kernel/stdio.asm b/kernel/stdio.asm index f408802..c248e54 100644 --- a/kernel/stdio.asm +++ b/kernel/stdio.asm @@ -4,13 +4,17 @@ ; in", that is, the console through which the user is connected in a decoupled ; manner. ; -; Those GetC/PutC routines are hooked in during stdioInit and have this API: +; Those GetC/PutC routines are hooked through defines and have this API: ; ; GetC: Blocks until a character is read from the device and return that ; character in A. ; ; PutC: Write character specified onto the device. ; +; *** Defines *** +; STDIO_GETC: address of a GetC routine +; STDIO_PUTC: address of a PutC routine +; ; *** Consts *** ; Size of the readline buffer. If a typed line reaches this size, the line is ; flushed immediately (same as pressing return). @@ -19,8 +23,6 @@ ; *** Variables *** ; Used to store formatted hex values just before printing it. .equ STDIO_HEX_FMT STDIO_RAMSTART -.equ STDIO_GETC @+2 -.equ STDIO_PUTC @+2 ; Line buffer. We read types chars into this buffer until return is pressed ; This buffer is null-terminated. @@ -29,19 +31,11 @@ ; Index where the next char will go in stdioGetC. .equ STDIO_RAMEND @+STDIO_BUFSIZE -; Sets GetC to the routine where HL points to and PutC to DE. -stdioInit: - ld (STDIO_GETC), hl - ld (STDIO_PUTC), de - ret - stdioGetC: - ld ix, (STDIO_GETC) - jp (ix) + jp STDIO_GETC stdioPutC: - ld ix, (STDIO_PUTC) - jp (ix) + jp STDIO_PUTC ; print null-terminated string pointed to by HL printstr: @@ -52,7 +46,7 @@ printstr: ld a, (hl) ; load character to send or a ; is it zero? jr z, .end ; if yes, we're finished - call stdioPutC + call STDIO_PUTC inc hl jr .loop @@ -67,7 +61,7 @@ printnstr: push hl .loop: ld a, (hl) ; load character to send - call stdioPutC + call STDIO_PUTC inc hl djnz .loop @@ -79,9 +73,9 @@ printnstr: printcrlf: push af ld a, ASCII_CR - call stdioPutC + call STDIO_PUTC ld a, ASCII_LF - call stdioPutC + call STDIO_PUTC pop af ret @@ -119,7 +113,7 @@ stdioReadLine: ld b, STDIO_BUFSIZE-1 .loop: ; Let's wait until something is typed. - call stdioGetC + call STDIO_GETC ; got it. Now, is it a CR or LF? cp ASCII_CR jr z, .complete ; char is CR? buffer complete! @@ -131,7 +125,7 @@ stdioReadLine: jr z, .delchr ; Echo the received character right away so that we see what we type - call stdioPutC + call STDIO_PUTC ; Ok, gotta add it do the buffer ld (hl), a @@ -159,9 +153,9 @@ stdioReadLine: ; Char deleted in buffer, now send BS + space + BS for the terminal ; to clear its previous char ld a, ASCII_BS - call stdioPutC + call STDIO_PUTC ld a, ' ' - call stdioPutC + call STDIO_PUTC ld a, ASCII_BS - call stdioPutC + call STDIO_PUTC jr .loop diff --git a/recipes/rc2014/eeprom/glue.asm b/recipes/rc2014/eeprom/glue.asm index 2256d0e..c375413 100644 --- a/recipes/rc2014/eeprom/glue.asm +++ b/recipes/rc2014/eeprom/glue.asm @@ -27,6 +27,8 @@ jp aciaInt .dw mmapGetB, mmapPutB .equ STDIO_RAMSTART BLOCKDEV_RAMEND +.equ STDIO_GETC aciaGetC +.equ STDIO_PUTC aciaPutC .inc "stdio.asm" .equ AT28W_RAMSTART STDIO_RAMEND @@ -49,9 +51,6 @@ init: im 1 call aciaInit - ld hl, aciaGetC - ld de, aciaPutC - call stdioInit call shellInit xor a diff --git a/recipes/rc2014/glue.asm b/recipes/rc2014/glue.asm index 39e6fe2..9ded2da 100644 --- a/recipes/rc2014/glue.asm +++ b/recipes/rc2014/glue.asm @@ -18,6 +18,8 @@ jp aciaInt .inc "acia.asm" .equ STDIO_RAMSTART ACIA_RAMEND +.equ STDIO_GETC aciaGetC +.equ STDIO_PUTC aciaPutC .inc "stdio.asm" .equ SHELL_RAMSTART STDIO_RAMEND @@ -32,9 +34,6 @@ init: im 1 call aciaInit - ld hl, aciaGetC - ld de, aciaPutC - call stdioInit call shellInit ei jp shellLoop diff --git a/recipes/rc2014/ps2/glue.asm b/recipes/rc2014/ps2/glue.asm index 926e323..6096e6a 100644 --- a/recipes/rc2014/ps2/glue.asm +++ b/recipes/rc2014/ps2/glue.asm @@ -16,6 +16,8 @@ jp init .inc "kbd.asm" .equ STDIO_RAMSTART KBD_RAMEND +.equ STDIO_GETC kbdGetC +.equ STDIO_PUTC aciaPutC .inc "stdio.asm" .equ SHELL_RAMSTART STDIO_RAMEND @@ -30,9 +32,6 @@ init: call aciaInit call kbdInit - ld hl, kbdGetC - ld de, aciaPutC - call stdioInit call shellInit jp shellLoop diff --git a/recipes/rc2014/sdcard/glue.asm b/recipes/rc2014/sdcard/glue.asm index 476ba0b..474de9c 100644 --- a/recipes/rc2014/sdcard/glue.asm +++ b/recipes/rc2014/sdcard/glue.asm @@ -34,6 +34,8 @@ jp aciaInt .equ STDIO_RAMSTART BLOCKDEV_RAMEND +.equ STDIO_GETC aciaGetC +.equ STDIO_PUTC aciaPutC .inc "stdio.asm" .equ FS_RAMSTART STDIO_RAMEND @@ -66,9 +68,6 @@ init: ld sp, hl im 1 call aciaInit - ld hl, aciaGetC - ld de, aciaPutC - call stdioInit call fsInit call shellInit ld hl, pgmShellHook diff --git a/recipes/rc2014/zasm/glue.asm b/recipes/rc2014/zasm/glue.asm index 04901ea..a93ef6b 100644 --- a/recipes/rc2014/zasm/glue.asm +++ b/recipes/rc2014/zasm/glue.asm @@ -65,6 +65,8 @@ jp aciaInt .inc "mmap.asm" .equ STDIO_RAMSTART BLOCKDEV_RAMEND +.equ STDIO_GETC aciaGetC +.equ STDIO_PUTC aciaPutC .inc "stdio.asm" .equ FS_RAMSTART STDIO_RAMEND @@ -99,9 +101,6 @@ init: ld sp, hl im 1 call aciaInit - ld hl, aciaGetC - ld de, aciaPutC - call stdioInit call fsInit call shellInit ld hl, pgmShellHook diff --git a/recipes/sms/glue.asm b/recipes/sms/glue.asm index 501ad64..c2ab816 100644 --- a/recipes/sms/glue.asm +++ b/recipes/sms/glue.asm @@ -19,6 +19,8 @@ .inc "sms/vdp.asm" .equ STDIO_RAMSTART VDP_RAMEND +.equ STDIO_GETC padGetC +.equ STDIO_PUTC vdpPutC .inc "stdio.asm" .equ SHELL_RAMSTART STDIO_RAMEND @@ -33,10 +35,6 @@ init: call padInit call vdpInit - - ld hl, padGetC - ld de, vdpPutC - call stdioInit call shellInit jp shellLoop diff --git a/recipes/sms/kbd/glue.asm b/recipes/sms/kbd/glue.asm index 6cfa426..87723a6 100644 --- a/recipes/sms/kbd/glue.asm +++ b/recipes/sms/kbd/glue.asm @@ -21,6 +21,8 @@ .inc "sms/vdp.asm" .equ STDIO_RAMSTART VDP_RAMEND +.equ STDIO_GETC kbdGetC +.equ STDIO_PUTC vdpPutC .inc "stdio.asm" .equ SHELL_RAMSTART STDIO_RAMEND @@ -45,10 +47,6 @@ init: call kbdInit call vdpInit - - ld hl, kbdGetC - ld de, vdpPutC - call stdioInit call shellInit jp shellLoop diff --git a/recipes/sms/romasm/glue.asm b/recipes/sms/romasm/glue.asm index 8704ac5..6daf3a1 100644 --- a/recipes/sms/romasm/glue.asm +++ b/recipes/sms/romasm/glue.asm @@ -52,6 +52,8 @@ .inc "sms/vdp.asm" .equ STDIO_RAMSTART VDP_RAMEND +.equ STDIO_GETC kbdGetC +.equ STDIO_PUTC vdpPutC .inc "stdio.asm" .equ MMAP_START 0xd700 @@ -104,9 +106,6 @@ init: ld a, 'S' ld (hl), a - ld hl, kbdGetC - ld de, vdpPutC - call stdioInit call fsInit xor a ld de, BLOCKDEV_SEL diff --git a/tools/emul/shell/shell_.asm b/tools/emul/shell/shell_.asm index b858f46..cda6357 100644 --- a/tools/emul/shell/shell_.asm +++ b/tools/emul/shell/shell_.asm @@ -58,6 +58,8 @@ .inc "mmap.asm" .equ STDIO_RAMSTART BLOCKDEV_RAMEND +.equ STDIO_GETC emulGetC +.equ STDIO_PUTC emulPutC .inc "stdio.asm" .equ FS_RAMSTART STDIO_RAMEND @@ -84,9 +86,6 @@ init: ; setup stack ld hl, KERNEL_RAMEND ld sp, hl - ld hl, emulGetC - ld de, emulPutC - call stdioInit call fsInit ld a, 0 ; select fsdev ld de, BLOCKDEV_SEL diff --git a/tools/emul/zasm/glue.asm b/tools/emul/zasm/glue.asm index 98e40a5..7c65151 100644 --- a/tools/emul/zasm/glue.asm +++ b/tools/emul/zasm/glue.asm @@ -45,6 +45,8 @@ jp printstr .dw fsdevGetB, fsdevPutB .equ STDIO_RAMSTART BLOCKDEV_RAMEND +.equ STDIO_GETC noop +.equ STDIO_PUTC stderrPutC .inc "stdio.asm" .equ FS_RAMSTART STDIO_RAMEND @@ -55,9 +57,6 @@ init: di ld hl, 0xffff ld sp, hl - ld hl, unsetZ - ld de, stderrPutC - call stdioInit ld a, 2 ; select fsdev ld de, BLOCKDEV_SEL call blkSel