From 56760b5aba97115d6519d3bc8db4ab9774c8b6a8 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 17 May 2019 08:14:19 -0400 Subject: [PATCH] stdio: de-macro-ize --- parts/z80/shell.asm | 4 ++-- parts/z80/stdio.asm | 34 +++++++++++++++++++++++------- recipes/rc2014/glue.asm | 38 ++++++++++++++++++++++------------ recipes/rc2014/sdcard/glue.asm | 12 +++++------ tools/emul/shell/shell.c | 2 +- tools/emul/shell/shell_.asm | 15 ++++++++------ 6 files changed, 70 insertions(+), 35 deletions(-) diff --git a/parts/z80/shell.asm b/parts/z80/shell.asm index ca994ac..78b5270 100644 --- a/parts/z80/shell.asm +++ b/parts/z80/shell.asm @@ -79,7 +79,7 @@ shellInit: ; to it rather than call it. Saves two precious bytes in the stack. shellLoop: ; First, let's wait until something is typed. - STDIO_GETC + call stdioGetC jr nz, shellLoop ; nothing typed? loop ; got it. Now, is it a CR or LF? cp ASCII_CR @@ -88,7 +88,7 @@ shellLoop: jr z, .do ; char is LF? do! ; Echo the received character right away so that we see what we type - STDIO_PUTC + call stdioPutC ; Ok, gotta add it do the buffer ; save char for later diff --git a/parts/z80/stdio.asm b/parts/z80/stdio.asm index c5018e4..5f631fa 100644 --- a/parts/z80/stdio.asm +++ b/parts/z80/stdio.asm @@ -4,13 +4,33 @@ ; which the user is connected in a decoupled manner. ; ; *** REQUIREMENTS *** -; STDIO_GETC: a macro that follows GetC API -; STDIO_PUTC: a macro that follows GetC API +; blkdev. select the block device you want to use as stdio just before you call +; stdioInit. ; *** VARIABLES *** ; Used to store formatted hex values just before printing it. STDIO_HEX_FMT .equ STDIO_RAMSTART -STDIO_RAMEND .equ STDIO_HEX_FMT+2 +STDIO_GETC .equ STDIO_HEX_FMT+2 +STDIO_PUTC .equ STDIO_GETC+2 +STDIO_RAMEND .equ STDIO_PUTC+2 + +; Select the blockdev to use as stdio before calling this. +stdioInit: + push hl + ld hl, (BLOCKDEV_GETC) + ld (STDIO_GETC), hl + ld hl, (BLOCKDEV_PUTC) + ld (STDIO_PUTC), hl + pop hl + ret + +stdioGetC: + ld ix, (STDIO_GETC) + jp (ix) + +stdioPutC: + ld ix, (STDIO_PUTC) + jp (ix) ; print null-terminated string pointed to by HL printstr: @@ -21,7 +41,7 @@ printstr: ld a, (hl) ; load character to send or a ; is it zero? jr z, .end ; if yes, we're finished - STDIO_PUTC + call stdioPutC inc hl jr .loop @@ -38,7 +58,7 @@ printnstr: ld b, a .loop: ld a, (hl) ; load character to send - STDIO_PUTC + call stdioPutC inc hl djnz .loop @@ -49,9 +69,9 @@ printnstr: printcrlf: ld a, ASCII_CR - STDIO_PUTC + call stdioPutC ld a, ASCII_LF - STDIO_PUTC + call stdioPutC ret ; Print the hex char in A diff --git a/recipes/rc2014/glue.asm b/recipes/rc2014/glue.asm index d1850f3..1368f73 100644 --- a/recipes/rc2014/glue.asm +++ b/recipes/rc2014/glue.asm @@ -5,32 +5,44 @@ RAMEND .equ 0xffff ACIA_CTL .equ 0x80 ; Control and status. RS off. ACIA_IO .equ 0x81 ; Transmit. RS on. -jr init +jp init ; interrupt hook .fill 0x38-$ jp aciaInt +#include "core.asm" +ACIA_RAMSTART .equ RAMSTART +#include "acia.asm" + +BLOCKDEV_RAMSTART .equ ACIA_RAMEND +BLOCKDEV_COUNT .equ 1 +#include "blockdev.asm" +; List of devices +.dw aciaGetC, aciaPutC, 0, 0 + +STDIO_RAMSTART .equ BLOCKDEV_RAMEND +#include "stdio.asm" + +SHELL_RAMSTART .equ STDIO_RAMEND +.define SHELL_IO_GETC call aciaGetC +.define SHELL_IO_PUTC call aciaPutC +SHELL_EXTRA_CMD_COUNT .equ 0 +#include "shell.asm" + init: di ; setup stack ld hl, RAMEND ld sp, hl im 1 + call aciaInit + xor a + ld de, BLOCKDEV_GETC + call blkSel + call stdioInit call shellInit ei jp shellLoop -#include "core.asm" -ACIA_RAMSTART .equ RAMSTART -#include "acia.asm" -.define STDIO_GETC call aciaGetC -.define STDIO_PUTC call aciaPutC -STDIO_RAMSTART .equ ACIA_RAMEND -#include "stdio.asm" -SHELL_RAMSTART .equ STDIO_RAMEND -.define SHELL_IO_GETC call aciaGetC -.define SHELL_IO_PUTC call aciaPutC -SHELL_EXTRA_CMD_COUNT .equ 0 -#include "shell.asm" diff --git a/recipes/rc2014/sdcard/glue.asm b/recipes/rc2014/sdcard/glue.asm index 5844e65..8bfa450 100644 --- a/recipes/rc2014/sdcard/glue.asm +++ b/recipes/rc2014/sdcard/glue.asm @@ -27,11 +27,7 @@ jp aciaInt #include "core.asm" ACIA_RAMSTART .equ RAMSTART #include "acia.asm" -.define STDIO_GETC call aciaGetC -.define STDIO_PUTC call aciaPutC -STDIO_RAMSTART .equ ACIA_RAMEND -#include "stdio.asm" -BLOCKDEV_RAMSTART .equ STDIO_RAMEND +BLOCKDEV_RAMSTART .equ ACIA_RAMEND BLOCKDEV_COUNT .equ 2 #include "blockdev.asm" ; List of devices @@ -40,7 +36,10 @@ BLOCKDEV_COUNT .equ 2 #include "blockdev_cmds.asm" -SHELL_RAMSTART .equ BLOCKDEV_RAMEND +STDIO_RAMSTART .equ BLOCKDEV_RAMEND +#include "stdio.asm" + +SHELL_RAMSTART .equ STDIO_RAMEND .define SHELL_IO_GETC call blkGetCW .define SHELL_IO_PUTC call blkPutC SHELL_EXTRA_CMD_COUNT .equ 3 @@ -63,6 +62,7 @@ init: xor a ld de, BLOCKDEV_GETC call blkSel + call stdioInit call shellInit ei diff --git a/tools/emul/shell/shell.c b/tools/emul/shell/shell.c index 1d71b83..2e1935e 100644 --- a/tools/emul/shell/shell.c +++ b/tools/emul/shell/shell.c @@ -141,7 +141,7 @@ int main() cpu.memRead = mem_read; cpu.memWrite = mem_write; - while (running) { + while (running && !cpu.halted) { Z80Execute(&cpu); } diff --git a/tools/emul/shell/shell_.asm b/tools/emul/shell/shell_.asm index 2953b21..db4ca77 100644 --- a/tools/emul/shell/shell_.asm +++ b/tools/emul/shell/shell_.asm @@ -9,12 +9,8 @@ FS_SEEKH_PORT .equ 0x03 jp init #include "core.asm" -.define STDIO_GETC call emulGetC -.define STDIO_PUTC call emulPutC -STDIO_RAMSTART .equ RAMSTART -#include "stdio.asm" -BLOCKDEV_RAMSTART .equ STDIO_RAMEND +BLOCKDEV_RAMSTART .equ RAMSTART BLOCKDEV_COUNT .equ 4 #include "blockdev.asm" ; List of devices @@ -25,7 +21,10 @@ BLOCKDEV_COUNT .equ 4 #include "blockdev_cmds.asm" -.equ FS_RAMSTART BLOCKDEV_RAMEND +STDIO_RAMSTART .equ BLOCKDEV_RAMEND +#include "stdio.asm" + +.equ FS_RAMSTART STDIO_RAMEND .equ FS_HANDLE_COUNT 2 #include "fs.asm" #include "fs_cmds.asm" @@ -42,6 +41,10 @@ init: ; setup stack ld hl, RAMEND ld sp, hl + xor a + ld de, BLOCKDEV_GETC + call blkSel + call stdioInit call fsInit ld a, 1 ; select fsdev ld de, BLOCKDEV_GETC