mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-24 02:38:05 +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:
parent
5a6078df4d
commit
34ee91a0d7
@ -1,21 +1,25 @@
|
|||||||
; *** Consts ***
|
; *** Consts ***
|
||||||
.equ IO_MAX_LINELEN 0xff
|
.equ IO_MAX_LINELEN 0xff
|
||||||
; *** Variables ***
|
; *** Variables ***
|
||||||
ioGetCPtr:
|
.equ IO_IN_GETC IO_RAMSTART
|
||||||
.fill 2
|
.equ IO_IN_PUTC IO_IN_GETC+2
|
||||||
ioPutCPtr:
|
.equ IO_IN_SEEK IO_IN_PUTC+2
|
||||||
.fill 2
|
.equ IO_IN_TELL IO_IN_SEEK+2
|
||||||
ioLineBuf:
|
.equ IO_OUT_GETC IO_IN_TELL+2
|
||||||
.fill IO_MAX_LINELEN+1
|
.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 ***
|
; *** Code ***
|
||||||
|
|
||||||
ioGetC:
|
ioGetC:
|
||||||
ld ix, (ioGetCPtr)
|
ld ix, (IO_IN_GETC)
|
||||||
jp (ix)
|
jp (ix)
|
||||||
|
|
||||||
ioPutC:
|
ioPutC:
|
||||||
ld ix, (ioPutCPtr)
|
ld ix, (IO_OUT_PUTC)
|
||||||
jp (ix)
|
jp (ix)
|
||||||
|
|
||||||
; Sets Z is A is CR, LF, or null.
|
; Sets Z is A is CR, LF, or null.
|
||||||
@ -27,9 +31,9 @@ isLineEnd:
|
|||||||
cp 0x0a
|
cp 0x0a
|
||||||
ret
|
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
|
; 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.
|
; We ignore empty lines and pass through them like butter.
|
||||||
; A null char is written at the end of the line.
|
; A null char is written at the end of the line.
|
||||||
ioReadLine:
|
ioReadLine:
|
||||||
@ -43,8 +47,8 @@ ioReadLine:
|
|||||||
jr z, .loop1
|
jr z, .loop1
|
||||||
; A contains the first char of our line.
|
; A contains the first char of our line.
|
||||||
ld c, 1
|
ld c, 1
|
||||||
ld (ioLineBuf), a
|
ld (IO_LINEBUF), a
|
||||||
ld hl, ioLineBuf+1
|
ld hl, IO_LINEBUF+1
|
||||||
.loop2:
|
.loop2:
|
||||||
call ioGetC
|
call ioGetC
|
||||||
call isLineEnd
|
call isLineEnd
|
||||||
@ -59,7 +63,7 @@ ioReadLine:
|
|||||||
xor a
|
xor a
|
||||||
ld (hl), a
|
ld (hl), a
|
||||||
ld a, c
|
ld a, c
|
||||||
ld hl, ioLineBuf
|
ld hl, IO_LINEBUF
|
||||||
jr .end
|
jr .end
|
||||||
.eof:
|
.eof:
|
||||||
xor a
|
xor a
|
||||||
|
@ -7,14 +7,30 @@
|
|||||||
; JUMP_UNSETZ
|
; JUMP_UNSETZ
|
||||||
; JUMP_INTODE
|
; JUMP_INTODE
|
||||||
; JUMP_FINDCHAR
|
; JUMP_FINDCHAR
|
||||||
|
; JUMP_BLKSEL
|
||||||
; RAMSTART (where we put our variables in RAM)
|
; 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 ***
|
; *** Code ***
|
||||||
; Read file through GetC routine pointer at HL and outputs its upcodes through
|
; Read file through blockdev ID in H and outputs its upcodes through blockdev
|
||||||
; the PutC routine pointer at DE.
|
; ID in L.
|
||||||
main:
|
main:
|
||||||
ld (ioGetCPtr), hl
|
ld a, h
|
||||||
ld (ioPutCPtr), de
|
ld de, IO_IN_GETC
|
||||||
|
call JUMP_BLKSEL
|
||||||
|
ld a, l
|
||||||
|
ld de, IO_OUT_GETC
|
||||||
|
call JUMP_BLKSEL
|
||||||
ld hl, 0
|
ld hl, 0
|
||||||
ld (curOutputOffset), hl
|
ld (curOutputOffset), hl
|
||||||
.loop:
|
.loop:
|
||||||
@ -27,15 +43,6 @@ main:
|
|||||||
.stop:
|
.stop:
|
||||||
ret
|
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
|
; Increase (curOutputOffset) by A
|
||||||
incOutputOffset:
|
incOutputOffset:
|
||||||
push de
|
push de
|
||||||
|
@ -33,9 +33,11 @@ BLOCKDEV_TELL .equ BLOCKDEV_SEEK+2
|
|||||||
BLOCKDEV_RAMEND .equ BLOCKDEV_TELL+2
|
BLOCKDEV_RAMEND .equ BLOCKDEV_TELL+2
|
||||||
|
|
||||||
; *** CODE ***
|
; *** 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:
|
blkSel:
|
||||||
push af
|
push af
|
||||||
|
push de
|
||||||
push hl
|
push hl
|
||||||
ld hl, blkDevTbl
|
ld hl, blkDevTbl
|
||||||
cp 0
|
cp 0
|
||||||
@ -50,25 +52,32 @@ blkSel:
|
|||||||
.afterloop:
|
.afterloop:
|
||||||
push hl
|
push hl
|
||||||
call intoHL
|
call intoHL
|
||||||
ld (BLOCKDEV_GETC), hl
|
call writeHLinDE
|
||||||
|
inc de
|
||||||
|
inc de
|
||||||
pop hl
|
pop hl
|
||||||
inc hl
|
inc hl
|
||||||
inc hl
|
inc hl
|
||||||
push hl
|
push hl
|
||||||
call intoHL
|
call intoHL
|
||||||
ld (BLOCKDEV_PUTC), hl
|
call writeHLinDE
|
||||||
|
inc de
|
||||||
|
inc de
|
||||||
pop hl
|
pop hl
|
||||||
inc hl
|
inc hl
|
||||||
inc hl
|
inc hl
|
||||||
push hl
|
push hl
|
||||||
call intoHL
|
call intoHL
|
||||||
ld (BLOCKDEV_SEEK), hl
|
call writeHLinDE
|
||||||
|
inc de
|
||||||
|
inc de
|
||||||
pop hl
|
pop hl
|
||||||
inc hl
|
inc hl
|
||||||
inc hl
|
inc hl
|
||||||
call intoHL
|
call intoHL
|
||||||
ld (BLOCKDEV_TELL), hl
|
call writeHLinDE
|
||||||
pop hl
|
pop hl
|
||||||
|
pop de
|
||||||
pop af
|
pop af
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -7,7 +7,10 @@ blkBselCmd:
|
|||||||
ld a, (hl) ; argument supplied
|
ld a, (hl) ; argument supplied
|
||||||
cp BLOCKDEV_COUNT
|
cp BLOCKDEV_COUNT
|
||||||
jr nc, .error ; if selection >= device count, error
|
jr nc, .error ; if selection >= device count, error
|
||||||
|
push de
|
||||||
|
ld de, BLOCKDEV_GETC
|
||||||
call blkSel
|
call blkSel
|
||||||
|
pop de
|
||||||
xor a
|
xor a
|
||||||
ret
|
ret
|
||||||
.error:
|
.error:
|
||||||
|
@ -5,10 +5,10 @@ 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
|
||||||
|
|
||||||
; *** JUMP TABLE ***
|
; *** 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 printstr
|
||||||
jp printHex
|
jp printHex
|
||||||
jp sdcInitialize
|
jp sdcInitialize
|
||||||
@ -24,20 +24,6 @@ jr init
|
|||||||
.fill 0x38-$
|
.fill 0x38-$
|
||||||
jp aciaInt
|
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"
|
#include "core.asm"
|
||||||
ACIA_RAMSTART .equ RAMSTART
|
ACIA_RAMSTART .equ RAMSTART
|
||||||
#include "acia.asm"
|
#include "acia.asm"
|
||||||
@ -66,3 +52,19 @@ SHELL_EXTRA_CMD_COUNT .equ 3
|
|||||||
.equ SDC_PORT_CSLOW 5
|
.equ SDC_PORT_CSLOW 5
|
||||||
.equ SDC_PORT_SPI 4
|
.equ SDC_PORT_SPI 4
|
||||||
#include "sdc.asm"
|
#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
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
JUMP_PRINTSTR .equ 0x02
|
JUMP_PRINTSTR .equ 0x03
|
||||||
JUMP_PRINTHEX .equ 0x05
|
JUMP_PRINTHEX .equ 0x06
|
||||||
JUMP_SDCINITALIZE .equ 0x08
|
JUMP_SDCINITALIZE .equ 0x09
|
||||||
JUMP_SDCSENDRECV .equ 0x0b
|
JUMP_SDCSENDRECV .equ 0x0c
|
||||||
JUMP_SDCWAITRESP .equ 0x0e
|
JUMP_SDCWAITRESP .equ 0x0f
|
||||||
JUMP_SDCCMD .equ 0x11
|
JUMP_SDCCMD .equ 0x12
|
||||||
JUMP_SDCCMDR1 .equ 0x14
|
JUMP_SDCCMDR1 .equ 0x15
|
||||||
JUMP_SDCCMDR7 .equ 0x17
|
JUMP_SDCCMDR7 .equ 0x18
|
||||||
JUMP_SDCREAD .equ 0x1a
|
JUMP_SDCREAD .equ 0x1b
|
||||||
JUMP_SDCSETBLKSIZE .equ 0x1d
|
JUMP_SDCSETBLKSIZE .equ 0x1e
|
||||||
|
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
* Memory layout:
|
* Memory layout:
|
||||||
*
|
*
|
||||||
* 0x0000 - 0x3fff: ROM code from zasm_glue.asm
|
* 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:
|
* I/O Ports:
|
||||||
*
|
*
|
||||||
@ -19,7 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// in sync with zasm_glue.asm
|
// in sync with zasm_glue.asm
|
||||||
#define USER_CODE 0x4000
|
#define USER_CODE 0x4800
|
||||||
#define STDIO_PORT 0x00
|
#define STDIO_PORT 0x00
|
||||||
|
|
||||||
static Z80Context cpu;
|
static Z80Context cpu;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
; Glue code for the emulated environment
|
; Glue code for the emulated environment
|
||||||
.equ USER_CODE 0x4000
|
.equ RAMSTART 0x4000
|
||||||
.equ RAMEND 0xffff
|
.equ USER_CODE 0x4800
|
||||||
.equ STDIO_PORT 0x00
|
.equ STDIO_PORT 0x00
|
||||||
|
|
||||||
jr init ; 2 bytes
|
jr init ; 2 bytes
|
||||||
@ -13,13 +13,15 @@ jp unsetZ
|
|||||||
jp intoDE
|
jp intoDE
|
||||||
jp findchar
|
jp findchar
|
||||||
jp parseHexPair
|
jp parseHexPair
|
||||||
|
jp blkSel
|
||||||
|
|
||||||
init:
|
init:
|
||||||
di
|
di
|
||||||
ld hl, RAMEND
|
; We put the stack at the end of the kernel memory
|
||||||
|
ld hl, USER_CODE-1
|
||||||
ld sp, hl
|
ld sp, hl
|
||||||
ld hl, emulGetC
|
ld h, 0 ; input blkdev
|
||||||
ld de, emulPutC
|
ld l, 1 ; output blkdev
|
||||||
call USER_CODE
|
call USER_CODE
|
||||||
; signal the emulator we're done
|
; signal the emulator we're done
|
||||||
halt
|
halt
|
||||||
@ -39,3 +41,9 @@ emulPutC:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
#include "core.asm"
|
#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
|
||||||
|
@ -7,8 +7,9 @@ JUMP_UNSETZ .equ 0x0e
|
|||||||
JUMP_INTODE .equ 0x11
|
JUMP_INTODE .equ 0x11
|
||||||
JUMP_FINDCHAR .equ 0x14
|
JUMP_FINDCHAR .equ 0x14
|
||||||
JUMP_PARSEHEXPAIR .equ 0x17
|
JUMP_PARSEHEXPAIR .equ 0x17
|
||||||
|
JUMP_BLKSEL .equ 0x1a
|
||||||
|
|
||||||
.equ USER_CODE 0x4000
|
.equ USER_CODE 0x4800
|
||||||
.equ RAMSTART 0x6000
|
.equ RAMSTART 0x5800
|
||||||
.org USER_CODE
|
.org USER_CODE
|
||||||
#include "main.asm"
|
#include "main.asm"
|
||||||
|
Loading…
Reference in New Issue
Block a user