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:
parent
2a513e6f57
commit
2a55bfd375
@ -7,47 +7,43 @@ look like:
|
|||||||
|
|
||||||
|
|
||||||
; The RAM module is selected on A15, so it has the range 0x8000-0xffff
|
; The RAM module is selected on A15, so it has the range 0x8000-0xffff
|
||||||
.equ RAMSTART 0x8000
|
.equ RAMSTART 0x8000
|
||||||
.equ RAMEND 0xffff
|
.equ RAMEND 0xffff
|
||||||
.equ ACIA_CTL 0x80 ; Control and status. RS off.
|
.equ ACIA_CTL 0x80 ; Control and status. RS off.
|
||||||
.equ ACIA_IO 0x81 ; Transmit. RS on.
|
.equ ACIA_IO 0x81 ; Transmit. RS on.
|
||||||
|
|
||||||
jr init
|
jp init
|
||||||
|
|
||||||
; interrupt hook
|
; interrupt hook
|
||||||
.fill 0x38-$
|
.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:
|
init:
|
||||||
di
|
di
|
||||||
; setup stack
|
; setup stack
|
||||||
ld hl, RAMEND
|
ld hl, RAMEND
|
||||||
ld sp, hl
|
ld sp, hl
|
||||||
im 1
|
im 1
|
||||||
call aciaInit
|
|
||||||
xor a
|
call aciaInit
|
||||||
ld de, BLOCKDEV_SEL
|
call shellInit
|
||||||
call blkSel
|
|
||||||
call stdioInit
|
|
||||||
call shellInit
|
|
||||||
ei
|
ei
|
||||||
jp shellLoop
|
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:
|
Once this is written, building it is easy:
|
||||||
|
|
||||||
|
@ -4,13 +4,17 @@
|
|||||||
; in", that is, the console through which the user is connected in a decoupled
|
; in", that is, the console through which the user is connected in a decoupled
|
||||||
; manner.
|
; 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
|
; GetC: Blocks until a character is read from the device and return that
|
||||||
; character in A.
|
; character in A.
|
||||||
;
|
;
|
||||||
; PutC: Write character specified onto the device.
|
; PutC: Write character specified onto the device.
|
||||||
;
|
;
|
||||||
|
; *** Defines ***
|
||||||
|
; STDIO_GETC: address of a GetC routine
|
||||||
|
; STDIO_PUTC: address of a PutC routine
|
||||||
|
;
|
||||||
; *** Consts ***
|
; *** Consts ***
|
||||||
; Size of the readline buffer. If a typed line reaches this size, the line is
|
; Size of the readline buffer. If a typed line reaches this size, the line is
|
||||||
; flushed immediately (same as pressing return).
|
; flushed immediately (same as pressing return).
|
||||||
@ -19,8 +23,6 @@
|
|||||||
; *** Variables ***
|
; *** Variables ***
|
||||||
; Used to store formatted hex values just before printing it.
|
; Used to store formatted hex values just before printing it.
|
||||||
.equ STDIO_HEX_FMT STDIO_RAMSTART
|
.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
|
; Line buffer. We read types chars into this buffer until return is pressed
|
||||||
; This buffer is null-terminated.
|
; This buffer is null-terminated.
|
||||||
@ -29,19 +31,11 @@
|
|||||||
; Index where the next char will go in stdioGetC.
|
; Index where the next char will go in stdioGetC.
|
||||||
.equ STDIO_RAMEND @+STDIO_BUFSIZE
|
.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:
|
stdioGetC:
|
||||||
ld ix, (STDIO_GETC)
|
jp STDIO_GETC
|
||||||
jp (ix)
|
|
||||||
|
|
||||||
stdioPutC:
|
stdioPutC:
|
||||||
ld ix, (STDIO_PUTC)
|
jp STDIO_PUTC
|
||||||
jp (ix)
|
|
||||||
|
|
||||||
; print null-terminated string pointed to by HL
|
; print null-terminated string pointed to by HL
|
||||||
printstr:
|
printstr:
|
||||||
@ -52,7 +46,7 @@ printstr:
|
|||||||
ld a, (hl) ; load character to send
|
ld a, (hl) ; load character to send
|
||||||
or a ; is it zero?
|
or a ; is it zero?
|
||||||
jr z, .end ; if yes, we're finished
|
jr z, .end ; if yes, we're finished
|
||||||
call stdioPutC
|
call STDIO_PUTC
|
||||||
inc hl
|
inc hl
|
||||||
jr .loop
|
jr .loop
|
||||||
|
|
||||||
@ -67,7 +61,7 @@ printnstr:
|
|||||||
push hl
|
push hl
|
||||||
.loop:
|
.loop:
|
||||||
ld a, (hl) ; load character to send
|
ld a, (hl) ; load character to send
|
||||||
call stdioPutC
|
call STDIO_PUTC
|
||||||
inc hl
|
inc hl
|
||||||
djnz .loop
|
djnz .loop
|
||||||
|
|
||||||
@ -79,9 +73,9 @@ printnstr:
|
|||||||
printcrlf:
|
printcrlf:
|
||||||
push af
|
push af
|
||||||
ld a, ASCII_CR
|
ld a, ASCII_CR
|
||||||
call stdioPutC
|
call STDIO_PUTC
|
||||||
ld a, ASCII_LF
|
ld a, ASCII_LF
|
||||||
call stdioPutC
|
call STDIO_PUTC
|
||||||
pop af
|
pop af
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -119,7 +113,7 @@ stdioReadLine:
|
|||||||
ld b, STDIO_BUFSIZE-1
|
ld b, STDIO_BUFSIZE-1
|
||||||
.loop:
|
.loop:
|
||||||
; Let's wait until something is typed.
|
; Let's wait until something is typed.
|
||||||
call stdioGetC
|
call STDIO_GETC
|
||||||
; got it. Now, is it a CR or LF?
|
; got it. Now, is it a CR or LF?
|
||||||
cp ASCII_CR
|
cp ASCII_CR
|
||||||
jr z, .complete ; char is CR? buffer complete!
|
jr z, .complete ; char is CR? buffer complete!
|
||||||
@ -131,7 +125,7 @@ stdioReadLine:
|
|||||||
jr z, .delchr
|
jr z, .delchr
|
||||||
|
|
||||||
; Echo the received character right away so that we see what we type
|
; 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
|
; Ok, gotta add it do the buffer
|
||||||
ld (hl), a
|
ld (hl), a
|
||||||
@ -159,9 +153,9 @@ stdioReadLine:
|
|||||||
; Char deleted in buffer, now send BS + space + BS for the terminal
|
; Char deleted in buffer, now send BS + space + BS for the terminal
|
||||||
; to clear its previous char
|
; to clear its previous char
|
||||||
ld a, ASCII_BS
|
ld a, ASCII_BS
|
||||||
call stdioPutC
|
call STDIO_PUTC
|
||||||
ld a, ' '
|
ld a, ' '
|
||||||
call stdioPutC
|
call STDIO_PUTC
|
||||||
ld a, ASCII_BS
|
ld a, ASCII_BS
|
||||||
call stdioPutC
|
call STDIO_PUTC
|
||||||
jr .loop
|
jr .loop
|
||||||
|
@ -27,6 +27,8 @@ jp aciaInt
|
|||||||
.dw mmapGetB, mmapPutB
|
.dw mmapGetB, mmapPutB
|
||||||
|
|
||||||
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
||||||
|
.equ STDIO_GETC aciaGetC
|
||||||
|
.equ STDIO_PUTC aciaPutC
|
||||||
.inc "stdio.asm"
|
.inc "stdio.asm"
|
||||||
|
|
||||||
.equ AT28W_RAMSTART STDIO_RAMEND
|
.equ AT28W_RAMSTART STDIO_RAMEND
|
||||||
@ -49,9 +51,6 @@ init:
|
|||||||
im 1
|
im 1
|
||||||
|
|
||||||
call aciaInit
|
call aciaInit
|
||||||
ld hl, aciaGetC
|
|
||||||
ld de, aciaPutC
|
|
||||||
call stdioInit
|
|
||||||
call shellInit
|
call shellInit
|
||||||
|
|
||||||
xor a
|
xor a
|
||||||
|
@ -18,6 +18,8 @@ jp aciaInt
|
|||||||
.inc "acia.asm"
|
.inc "acia.asm"
|
||||||
|
|
||||||
.equ STDIO_RAMSTART ACIA_RAMEND
|
.equ STDIO_RAMSTART ACIA_RAMEND
|
||||||
|
.equ STDIO_GETC aciaGetC
|
||||||
|
.equ STDIO_PUTC aciaPutC
|
||||||
.inc "stdio.asm"
|
.inc "stdio.asm"
|
||||||
|
|
||||||
.equ SHELL_RAMSTART STDIO_RAMEND
|
.equ SHELL_RAMSTART STDIO_RAMEND
|
||||||
@ -32,9 +34,6 @@ init:
|
|||||||
im 1
|
im 1
|
||||||
|
|
||||||
call aciaInit
|
call aciaInit
|
||||||
ld hl, aciaGetC
|
|
||||||
ld de, aciaPutC
|
|
||||||
call stdioInit
|
|
||||||
call shellInit
|
call shellInit
|
||||||
ei
|
ei
|
||||||
jp shellLoop
|
jp shellLoop
|
||||||
|
@ -16,6 +16,8 @@ jp init
|
|||||||
.inc "kbd.asm"
|
.inc "kbd.asm"
|
||||||
|
|
||||||
.equ STDIO_RAMSTART KBD_RAMEND
|
.equ STDIO_RAMSTART KBD_RAMEND
|
||||||
|
.equ STDIO_GETC kbdGetC
|
||||||
|
.equ STDIO_PUTC aciaPutC
|
||||||
.inc "stdio.asm"
|
.inc "stdio.asm"
|
||||||
|
|
||||||
.equ SHELL_RAMSTART STDIO_RAMEND
|
.equ SHELL_RAMSTART STDIO_RAMEND
|
||||||
@ -30,9 +32,6 @@ init:
|
|||||||
|
|
||||||
call aciaInit
|
call aciaInit
|
||||||
call kbdInit
|
call kbdInit
|
||||||
ld hl, kbdGetC
|
|
||||||
ld de, aciaPutC
|
|
||||||
call stdioInit
|
|
||||||
call shellInit
|
call shellInit
|
||||||
jp shellLoop
|
jp shellLoop
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@ jp aciaInt
|
|||||||
|
|
||||||
|
|
||||||
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
||||||
|
.equ STDIO_GETC aciaGetC
|
||||||
|
.equ STDIO_PUTC aciaPutC
|
||||||
.inc "stdio.asm"
|
.inc "stdio.asm"
|
||||||
|
|
||||||
.equ FS_RAMSTART STDIO_RAMEND
|
.equ FS_RAMSTART STDIO_RAMEND
|
||||||
@ -66,9 +68,6 @@ init:
|
|||||||
ld sp, hl
|
ld sp, hl
|
||||||
im 1
|
im 1
|
||||||
call aciaInit
|
call aciaInit
|
||||||
ld hl, aciaGetC
|
|
||||||
ld de, aciaPutC
|
|
||||||
call stdioInit
|
|
||||||
call fsInit
|
call fsInit
|
||||||
call shellInit
|
call shellInit
|
||||||
ld hl, pgmShellHook
|
ld hl, pgmShellHook
|
||||||
|
@ -65,6 +65,8 @@ jp aciaInt
|
|||||||
.inc "mmap.asm"
|
.inc "mmap.asm"
|
||||||
|
|
||||||
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
||||||
|
.equ STDIO_GETC aciaGetC
|
||||||
|
.equ STDIO_PUTC aciaPutC
|
||||||
.inc "stdio.asm"
|
.inc "stdio.asm"
|
||||||
|
|
||||||
.equ FS_RAMSTART STDIO_RAMEND
|
.equ FS_RAMSTART STDIO_RAMEND
|
||||||
@ -99,9 +101,6 @@ init:
|
|||||||
ld sp, hl
|
ld sp, hl
|
||||||
im 1
|
im 1
|
||||||
call aciaInit
|
call aciaInit
|
||||||
ld hl, aciaGetC
|
|
||||||
ld de, aciaPutC
|
|
||||||
call stdioInit
|
|
||||||
call fsInit
|
call fsInit
|
||||||
call shellInit
|
call shellInit
|
||||||
ld hl, pgmShellHook
|
ld hl, pgmShellHook
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
.inc "sms/vdp.asm"
|
.inc "sms/vdp.asm"
|
||||||
|
|
||||||
.equ STDIO_RAMSTART VDP_RAMEND
|
.equ STDIO_RAMSTART VDP_RAMEND
|
||||||
|
.equ STDIO_GETC padGetC
|
||||||
|
.equ STDIO_PUTC vdpPutC
|
||||||
.inc "stdio.asm"
|
.inc "stdio.asm"
|
||||||
|
|
||||||
.equ SHELL_RAMSTART STDIO_RAMEND
|
.equ SHELL_RAMSTART STDIO_RAMEND
|
||||||
@ -33,10 +35,6 @@ init:
|
|||||||
|
|
||||||
call padInit
|
call padInit
|
||||||
call vdpInit
|
call vdpInit
|
||||||
|
|
||||||
ld hl, padGetC
|
|
||||||
ld de, vdpPutC
|
|
||||||
call stdioInit
|
|
||||||
call shellInit
|
call shellInit
|
||||||
jp shellLoop
|
jp shellLoop
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
.inc "sms/vdp.asm"
|
.inc "sms/vdp.asm"
|
||||||
|
|
||||||
.equ STDIO_RAMSTART VDP_RAMEND
|
.equ STDIO_RAMSTART VDP_RAMEND
|
||||||
|
.equ STDIO_GETC kbdGetC
|
||||||
|
.equ STDIO_PUTC vdpPutC
|
||||||
.inc "stdio.asm"
|
.inc "stdio.asm"
|
||||||
|
|
||||||
.equ SHELL_RAMSTART STDIO_RAMEND
|
.equ SHELL_RAMSTART STDIO_RAMEND
|
||||||
@ -45,10 +47,6 @@ init:
|
|||||||
|
|
||||||
call kbdInit
|
call kbdInit
|
||||||
call vdpInit
|
call vdpInit
|
||||||
|
|
||||||
ld hl, kbdGetC
|
|
||||||
ld de, vdpPutC
|
|
||||||
call stdioInit
|
|
||||||
call shellInit
|
call shellInit
|
||||||
jp shellLoop
|
jp shellLoop
|
||||||
|
|
||||||
|
@ -52,6 +52,8 @@
|
|||||||
.inc "sms/vdp.asm"
|
.inc "sms/vdp.asm"
|
||||||
|
|
||||||
.equ STDIO_RAMSTART VDP_RAMEND
|
.equ STDIO_RAMSTART VDP_RAMEND
|
||||||
|
.equ STDIO_GETC kbdGetC
|
||||||
|
.equ STDIO_PUTC vdpPutC
|
||||||
.inc "stdio.asm"
|
.inc "stdio.asm"
|
||||||
|
|
||||||
.equ MMAP_START 0xd700
|
.equ MMAP_START 0xd700
|
||||||
@ -104,9 +106,6 @@ init:
|
|||||||
ld a, 'S'
|
ld a, 'S'
|
||||||
ld (hl), a
|
ld (hl), a
|
||||||
|
|
||||||
ld hl, kbdGetC
|
|
||||||
ld de, vdpPutC
|
|
||||||
call stdioInit
|
|
||||||
call fsInit
|
call fsInit
|
||||||
xor a
|
xor a
|
||||||
ld de, BLOCKDEV_SEL
|
ld de, BLOCKDEV_SEL
|
||||||
|
@ -58,6 +58,8 @@
|
|||||||
.inc "mmap.asm"
|
.inc "mmap.asm"
|
||||||
|
|
||||||
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
||||||
|
.equ STDIO_GETC emulGetC
|
||||||
|
.equ STDIO_PUTC emulPutC
|
||||||
.inc "stdio.asm"
|
.inc "stdio.asm"
|
||||||
|
|
||||||
.equ FS_RAMSTART STDIO_RAMEND
|
.equ FS_RAMSTART STDIO_RAMEND
|
||||||
@ -84,9 +86,6 @@ init:
|
|||||||
; setup stack
|
; setup stack
|
||||||
ld hl, KERNEL_RAMEND
|
ld hl, KERNEL_RAMEND
|
||||||
ld sp, hl
|
ld sp, hl
|
||||||
ld hl, emulGetC
|
|
||||||
ld de, emulPutC
|
|
||||||
call stdioInit
|
|
||||||
call fsInit
|
call fsInit
|
||||||
ld a, 0 ; select fsdev
|
ld a, 0 ; select fsdev
|
||||||
ld de, BLOCKDEV_SEL
|
ld de, BLOCKDEV_SEL
|
||||||
|
@ -45,6 +45,8 @@ jp printstr
|
|||||||
.dw fsdevGetB, fsdevPutB
|
.dw fsdevGetB, fsdevPutB
|
||||||
|
|
||||||
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
||||||
|
.equ STDIO_GETC noop
|
||||||
|
.equ STDIO_PUTC stderrPutC
|
||||||
.inc "stdio.asm"
|
.inc "stdio.asm"
|
||||||
|
|
||||||
.equ FS_RAMSTART STDIO_RAMEND
|
.equ FS_RAMSTART STDIO_RAMEND
|
||||||
@ -55,9 +57,6 @@ init:
|
|||||||
di
|
di
|
||||||
ld hl, 0xffff
|
ld hl, 0xffff
|
||||||
ld sp, hl
|
ld sp, hl
|
||||||
ld hl, unsetZ
|
|
||||||
ld de, stderrPutC
|
|
||||||
call stdioInit
|
|
||||||
ld a, 2 ; select fsdev
|
ld a, 2 ; select fsdev
|
||||||
ld de, BLOCKDEV_SEL
|
ld de, BLOCKDEV_SEL
|
||||||
call blkSel
|
call blkSel
|
||||||
|
Loading…
Reference in New Issue
Block a user