1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-23 16:08:06 +11:00

zasm: use blkdev IDs as input and output

This will soon allow use to seek and tell on input, which is necessary
for a second pass which is necessary for forward symbol references.

This require making `blkSel` a bit more flexible. Rather than having one
global selected blkdev, each app can select its own, in its own memory
space.
This commit is contained in:
Virgil Dupras 2019-05-10 18:20:43 -04:00
parent 5a6078df4d
commit 34ee91a0d7
9 changed files with 102 additions and 66 deletions

View File

@ -1,21 +1,25 @@
; *** Consts ***
.equ IO_MAX_LINELEN 0xff
; *** Variables ***
ioGetCPtr:
.fill 2
ioPutCPtr:
.fill 2
ioLineBuf:
.fill IO_MAX_LINELEN+1
.equ IO_IN_GETC IO_RAMSTART
.equ IO_IN_PUTC IO_IN_GETC+2
.equ IO_IN_SEEK IO_IN_PUTC+2
.equ IO_IN_TELL IO_IN_SEEK+2
.equ IO_OUT_GETC IO_IN_TELL+2
.equ IO_OUT_PUTC IO_OUT_GETC+2
.equ IO_OUT_SEEK IO_OUT_PUTC+2
.equ IO_OUT_TELL IO_OUT_SEEK+2
.equ IO_LINEBUF IO_OUT_TELL+2
.equ IO_RAMEND IO_LINEBUF+IO_MAX_LINELEN+1
; *** Code ***
ioGetC:
ld ix, (ioGetCPtr)
ld ix, (IO_IN_GETC)
jp (ix)
ioPutC:
ld ix, (ioPutCPtr)
ld ix, (IO_OUT_PUTC)
jp (ix)
; Sets Z is A is CR, LF, or null.
@ -27,9 +31,9 @@ isLineEnd:
cp 0x0a
ret
; Read a single line from ioGetCPtr and place it in ioLineBuf.
; Read a single line from ioGetCPtr and place it in IO_LINEBUF.
; Returns number of chars read in A. 0 means we're at the end of our input
; stream, which happens when GetC unsets Z. Make HL point to ioLineBuf.
; stream, which happens when GetC unsets Z. Make HL point to IO_LINEBUF.
; We ignore empty lines and pass through them like butter.
; A null char is written at the end of the line.
ioReadLine:
@ -43,8 +47,8 @@ ioReadLine:
jr z, .loop1
; A contains the first char of our line.
ld c, 1
ld (ioLineBuf), a
ld hl, ioLineBuf+1
ld (IO_LINEBUF), a
ld hl, IO_LINEBUF+1
.loop2:
call ioGetC
call isLineEnd
@ -59,7 +63,7 @@ ioReadLine:
xor a
ld (hl), a
ld a, c
ld hl, ioLineBuf
ld hl, IO_LINEBUF
jr .end
.eof:
xor a

View File

@ -7,14 +7,30 @@
; JUMP_UNSETZ
; JUMP_INTODE
; JUMP_FINDCHAR
; JUMP_BLKSEL
; RAMSTART (where we put our variables in RAM)
jp main
#include "util.asm"
.equ IO_RAMSTART RAMSTART
#include "io.asm"
#include "parse.asm"
#include "literal.asm"
#include "instr.asm"
#include "directive.asm"
.equ SYM_RAMSTART IO_RAMEND
#include "symbol.asm"
; *** Code ***
; Read file through GetC routine pointer at HL and outputs its upcodes through
; the PutC routine pointer at DE.
; Read file through blockdev ID in H and outputs its upcodes through blockdev
; ID in L.
main:
ld (ioGetCPtr), hl
ld (ioPutCPtr), de
ld a, h
ld de, IO_IN_GETC
call JUMP_BLKSEL
ld a, l
ld de, IO_OUT_GETC
call JUMP_BLKSEL
ld hl, 0
ld (curOutputOffset), hl
.loop:
@ -27,15 +43,6 @@ main:
.stop:
ret
#include "util.asm"
#include "io.asm"
#include "parse.asm"
#include "literal.asm"
#include "instr.asm"
#include "directive.asm"
.equ SYM_RAMSTART RAMSTART
#include "symbol.asm"
; Increase (curOutputOffset) by A
incOutputOffset:
push de

View File

@ -33,9 +33,11 @@ BLOCKDEV_TELL .equ BLOCKDEV_SEEK+2
BLOCKDEV_RAMEND .equ BLOCKDEV_TELL+2
; *** CODE ***
; Select block index specified in A
; Select block index specified in A and place them in routine pointers at (DE).
; For example, for a "regular" blkSel, you will want to set DE to BLOCKDEV_GETC.
blkSel:
push af
push de
push hl
ld hl, blkDevTbl
cp 0
@ -50,25 +52,32 @@ blkSel:
.afterloop:
push hl
call intoHL
ld (BLOCKDEV_GETC), hl
call writeHLinDE
inc de
inc de
pop hl
inc hl
inc hl
push hl
call intoHL
ld (BLOCKDEV_PUTC), hl
call writeHLinDE
inc de
inc de
pop hl
inc hl
inc hl
push hl
call intoHL
ld (BLOCKDEV_SEEK), hl
call writeHLinDE
inc de
inc de
pop hl
inc hl
inc hl
call intoHL
ld (BLOCKDEV_TELL), hl
call writeHLinDE
pop hl
pop de
pop af
ret

View File

@ -7,7 +7,10 @@ blkBselCmd:
ld a, (hl) ; argument supplied
cp BLOCKDEV_COUNT
jr nc, .error ; if selection >= device count, error
push de
ld de, BLOCKDEV_GETC
call blkSel
pop de
xor a
ret
.error:

View File

@ -5,10 +5,10 @@ RAMEND .equ 0xffff
ACIA_CTL .equ 0x80 ; Control and status. RS off.
ACIA_IO .equ 0x81 ; Transmit. RS on.
jr init
jp init
; *** JUMP TABLE ***
; Why not use this unused space between 0x02 and 0x28 for a jump table?
; Why not use this unused space between 0x03 and 0x38 for a jump table?
jp printstr
jp printHex
jp sdcInitialize
@ -24,20 +24,6 @@ jr init
.fill 0x38-$
jp aciaInt
init:
di
; setup stack
ld hl, RAMEND
ld sp, hl
im 1
call aciaInit
xor a
call blkSel
call shellInit
ei
jp shellLoop
#include "core.asm"
ACIA_RAMSTART .equ RAMSTART
#include "acia.asm"
@ -66,3 +52,19 @@ SHELL_EXTRA_CMD_COUNT .equ 3
.equ SDC_PORT_CSLOW 5
.equ SDC_PORT_SPI 4
#include "sdc.asm"
init:
di
; setup stack
ld hl, RAMEND
ld sp, hl
im 1
call aciaInit
xor a
ld de, BLOCKDEV_GETC
call blkSel
call shellInit
ei
jp shellLoop

View File

@ -1,11 +1,11 @@
JUMP_PRINTSTR .equ 0x02
JUMP_PRINTHEX .equ 0x05
JUMP_SDCINITALIZE .equ 0x08
JUMP_SDCSENDRECV .equ 0x0b
JUMP_SDCWAITRESP .equ 0x0e
JUMP_SDCCMD .equ 0x11
JUMP_SDCCMDR1 .equ 0x14
JUMP_SDCCMDR7 .equ 0x17
JUMP_SDCREAD .equ 0x1a
JUMP_SDCSETBLKSIZE .equ 0x1d
JUMP_PRINTSTR .equ 0x03
JUMP_PRINTHEX .equ 0x06
JUMP_SDCINITALIZE .equ 0x09
JUMP_SDCSENDRECV .equ 0x0c
JUMP_SDCWAITRESP .equ 0x0f
JUMP_SDCCMD .equ 0x12
JUMP_SDCCMDR1 .equ 0x15
JUMP_SDCCMDR7 .equ 0x18
JUMP_SDCREAD .equ 0x1b
JUMP_SDCSETBLKSIZE .equ 0x1e

View File

@ -11,7 +11,9 @@
* Memory layout:
*
* 0x0000 - 0x3fff: ROM code from zasm_glue.asm
* 0x4000 - 0xffff: Userspace
* 0x4000 - 0x47ff: RAM for kernel and stack
* 0x4800 - 0x57ff: Userspace code
* 0x5800 - 0xffff: Userspace RAM
*
* I/O Ports:
*
@ -19,7 +21,7 @@
*/
// in sync with zasm_glue.asm
#define USER_CODE 0x4000
#define USER_CODE 0x4800
#define STDIO_PORT 0x00
static Z80Context cpu;

View File

@ -1,6 +1,6 @@
; Glue code for the emulated environment
.equ USER_CODE 0x4000
.equ RAMEND 0xffff
.equ RAMSTART 0x4000
.equ USER_CODE 0x4800
.equ STDIO_PORT 0x00
jr init ; 2 bytes
@ -13,13 +13,15 @@ jp unsetZ
jp intoDE
jp findchar
jp parseHexPair
jp blkSel
init:
di
ld hl, RAMEND
; We put the stack at the end of the kernel memory
ld hl, USER_CODE-1
ld sp, hl
ld hl, emulGetC
ld de, emulPutC
ld h, 0 ; input blkdev
ld l, 1 ; output blkdev
call USER_CODE
; signal the emulator we're done
halt
@ -39,3 +41,9 @@ emulPutC:
ret
#include "core.asm"
.equ BLOCKDEV_RAMSTART RAMSTART
.equ BLOCKDEV_COUNT 2
#include "blockdev.asm"
; List of devices
.dw emulGetC, 0, 0, 0
.dw 0, emulPutC, 0, 0

View File

@ -7,8 +7,9 @@ JUMP_UNSETZ .equ 0x0e
JUMP_INTODE .equ 0x11
JUMP_FINDCHAR .equ 0x14
JUMP_PARSEHEXPAIR .equ 0x17
JUMP_BLKSEL .equ 0x1a
.equ USER_CODE 0x4000
.equ RAMSTART 0x6000
.equ USER_CODE 0x4800
.equ RAMSTART 0x5800
.org USER_CODE
#include "main.asm"