mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 14:58: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.
|
; to it rather than call it. Saves two precious bytes in the stack.
|
||||||
shellLoop:
|
shellLoop:
|
||||||
; First, let's wait until something is typed.
|
; First, let's wait until something is typed.
|
||||||
STDIO_GETC
|
call stdioGetC
|
||||||
jr nz, shellLoop ; nothing typed? loop
|
jr nz, shellLoop ; nothing typed? loop
|
||||||
; got it. Now, is it a CR or LF?
|
; got it. Now, is it a CR or LF?
|
||||||
cp ASCII_CR
|
cp ASCII_CR
|
||||||
@ -88,7 +88,7 @@ shellLoop:
|
|||||||
jr z, .do ; char is LF? do!
|
jr z, .do ; char is LF? do!
|
||||||
|
|
||||||
; 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
|
||||||
STDIO_PUTC
|
call stdioPutC
|
||||||
|
|
||||||
; Ok, gotta add it do the buffer
|
; Ok, gotta add it do the buffer
|
||||||
; save char for later
|
; save char for later
|
||||||
|
@ -4,13 +4,33 @@
|
|||||||
; which the user is connected in a decoupled manner.
|
; which the user is connected in a decoupled manner.
|
||||||
;
|
;
|
||||||
; *** REQUIREMENTS ***
|
; *** REQUIREMENTS ***
|
||||||
; STDIO_GETC: a macro that follows GetC API
|
; blkdev. select the block device you want to use as stdio just before you call
|
||||||
; STDIO_PUTC: a macro that follows GetC API
|
; stdioInit.
|
||||||
|
|
||||||
; *** VARIABLES ***
|
; *** VARIABLES ***
|
||||||
; Used to store formatted hex values just before printing it.
|
; Used to store formatted hex values just before printing it.
|
||||||
STDIO_HEX_FMT .equ STDIO_RAMSTART
|
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
|
; print null-terminated string pointed to by HL
|
||||||
printstr:
|
printstr:
|
||||||
@ -21,7 +41,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
|
||||||
STDIO_PUTC
|
call stdioPutC
|
||||||
inc hl
|
inc hl
|
||||||
jr .loop
|
jr .loop
|
||||||
|
|
||||||
@ -38,7 +58,7 @@ printnstr:
|
|||||||
ld b, a
|
ld b, a
|
||||||
.loop:
|
.loop:
|
||||||
ld a, (hl) ; load character to send
|
ld a, (hl) ; load character to send
|
||||||
STDIO_PUTC
|
call stdioPutC
|
||||||
inc hl
|
inc hl
|
||||||
djnz .loop
|
djnz .loop
|
||||||
|
|
||||||
@ -49,9 +69,9 @@ printnstr:
|
|||||||
|
|
||||||
printcrlf:
|
printcrlf:
|
||||||
ld a, ASCII_CR
|
ld a, ASCII_CR
|
||||||
STDIO_PUTC
|
call stdioPutC
|
||||||
ld a, ASCII_LF
|
ld a, ASCII_LF
|
||||||
STDIO_PUTC
|
call stdioPutC
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Print the hex char in A
|
; Print the hex char in A
|
||||||
|
@ -5,32 +5,44 @@ RAMEND .equ 0xffff
|
|||||||
ACIA_CTL .equ 0x80 ; Control and status. RS off.
|
ACIA_CTL .equ 0x80 ; Control and status. RS off.
|
||||||
ACIA_IO .equ 0x81 ; Transmit. RS on.
|
ACIA_IO .equ 0x81 ; Transmit. RS on.
|
||||||
|
|
||||||
jr init
|
jp init
|
||||||
|
|
||||||
; interrupt hook
|
; interrupt hook
|
||||||
.fill 0x38-$
|
.fill 0x38-$
|
||||||
jp aciaInt
|
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:
|
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
|
call aciaInit
|
||||||
|
xor a
|
||||||
|
ld de, BLOCKDEV_GETC
|
||||||
|
call blkSel
|
||||||
|
call stdioInit
|
||||||
call shellInit
|
call shellInit
|
||||||
ei
|
ei
|
||||||
jp shellLoop
|
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"
|
#include "core.asm"
|
||||||
ACIA_RAMSTART .equ RAMSTART
|
ACIA_RAMSTART .equ RAMSTART
|
||||||
#include "acia.asm"
|
#include "acia.asm"
|
||||||
.define STDIO_GETC call aciaGetC
|
BLOCKDEV_RAMSTART .equ ACIA_RAMEND
|
||||||
.define STDIO_PUTC call aciaPutC
|
|
||||||
STDIO_RAMSTART .equ ACIA_RAMEND
|
|
||||||
#include "stdio.asm"
|
|
||||||
BLOCKDEV_RAMSTART .equ STDIO_RAMEND
|
|
||||||
BLOCKDEV_COUNT .equ 2
|
BLOCKDEV_COUNT .equ 2
|
||||||
#include "blockdev.asm"
|
#include "blockdev.asm"
|
||||||
; List of devices
|
; List of devices
|
||||||
@ -40,7 +36,10 @@ BLOCKDEV_COUNT .equ 2
|
|||||||
|
|
||||||
#include "blockdev_cmds.asm"
|
#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_GETC call blkGetCW
|
||||||
.define SHELL_IO_PUTC call blkPutC
|
.define SHELL_IO_PUTC call blkPutC
|
||||||
SHELL_EXTRA_CMD_COUNT .equ 3
|
SHELL_EXTRA_CMD_COUNT .equ 3
|
||||||
@ -63,6 +62,7 @@ init:
|
|||||||
xor a
|
xor a
|
||||||
ld de, BLOCKDEV_GETC
|
ld de, BLOCKDEV_GETC
|
||||||
call blkSel
|
call blkSel
|
||||||
|
call stdioInit
|
||||||
call shellInit
|
call shellInit
|
||||||
|
|
||||||
ei
|
ei
|
||||||
|
@ -141,7 +141,7 @@ int main()
|
|||||||
cpu.memRead = mem_read;
|
cpu.memRead = mem_read;
|
||||||
cpu.memWrite = mem_write;
|
cpu.memWrite = mem_write;
|
||||||
|
|
||||||
while (running) {
|
while (running && !cpu.halted) {
|
||||||
Z80Execute(&cpu);
|
Z80Execute(&cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,12 +9,8 @@ FS_SEEKH_PORT .equ 0x03
|
|||||||
jp init
|
jp init
|
||||||
|
|
||||||
#include "core.asm"
|
#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
|
BLOCKDEV_COUNT .equ 4
|
||||||
#include "blockdev.asm"
|
#include "blockdev.asm"
|
||||||
; List of devices
|
; List of devices
|
||||||
@ -25,7 +21,10 @@ BLOCKDEV_COUNT .equ 4
|
|||||||
|
|
||||||
#include "blockdev_cmds.asm"
|
#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
|
.equ FS_HANDLE_COUNT 2
|
||||||
#include "fs.asm"
|
#include "fs.asm"
|
||||||
#include "fs_cmds.asm"
|
#include "fs_cmds.asm"
|
||||||
@ -42,6 +41,10 @@ init:
|
|||||||
; setup stack
|
; setup stack
|
||||||
ld hl, RAMEND
|
ld hl, RAMEND
|
||||||
ld sp, hl
|
ld sp, hl
|
||||||
|
xor a
|
||||||
|
ld de, BLOCKDEV_GETC
|
||||||
|
call blkSel
|
||||||
|
call stdioInit
|
||||||
call fsInit
|
call fsInit
|
||||||
ld a, 1 ; select fsdev
|
ld a, 1 ; select fsdev
|
||||||
ld de, BLOCKDEV_GETC
|
ld de, BLOCKDEV_GETC
|
||||||
|
Loading…
Reference in New Issue
Block a user