mirror of
https://github.com/hsoft/collapseos.git
synced 2024-12-24 14:28:06 +11:00
stdio: de-macro-ize
This commit is contained in:
parent
dfce0d3a62
commit
56760b5aba
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -141,7 +141,7 @@ int main()
|
||||
cpu.memRead = mem_read;
|
||||
cpu.memWrite = mem_write;
|
||||
|
||||
while (running) {
|
||||
while (running && !cpu.halted) {
|
||||
Z80Execute(&cpu);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user