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.
This commit is contained in:
Virgil Dupras 2019-11-04 09:55:12 -05:00
parent 2a513e6f57
commit 2a55bfd375
12 changed files with 63 additions and 85 deletions

View File

@ -12,43 +12,39 @@ look like:
.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
.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
im 1
call aciaInit
xor a
ld de, BLOCKDEV_SEL
call blkSel
call stdioInit
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"
Once this is written, building it is easy:
zasm < glue.asm > collapseos.bin

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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