zasm: add ".bin" directive

Also, remove zasm/test7 because it changes too much all time time
(whenever zasm changes) and isn't precise enough. Too much noise,
not worth it.
This commit is contained in:
Virgil Dupras 2019-07-21 12:58:02 -04:00
parent 01031a780a
commit 34f499184d
9 changed files with 68 additions and 60 deletions

View File

@ -139,15 +139,8 @@ allowed. An included file cannot have an `#inc` directive.
and output its binary content as is the code has been in the includer and output its binary content as is the code has been in the includer
file. file.
## Compatibility with scas **.bin**: Takes a string literal as an argument. Open the file name specified
in the argument in the currently active filesystem and outputs its
This project was initially assembled with [scas][scas], but now that zasm self- contents directly.
assembles, it isn't used any more. However, the kernel and zasm code are still
written to be compatible with scas because scas is still used as a comparison
tool in tests.
There are, however, features I want to implement in zasm that will break
compatibility with scas, so in the near future, scas will be left behind.
[libz80]: https://github.com/ggambetta/libz80 [libz80]: https://github.com/ggambetta/libz80
[scas]: https://github.com/KnightOS/scas

View File

@ -7,6 +7,7 @@
.equ D_FIL 0x04 .equ D_FIL 0x04
.equ D_OUT 0x05 .equ D_OUT 0x05
.equ D_INC 0x06 .equ D_INC 0x06
.equ D_BIN 0x07
.equ D_BAD 0xff .equ D_BAD 0xff
; *** Variables *** ; *** Variables ***
@ -23,6 +24,7 @@ directiveNames:
.db ".FIL" .db ".FIL"
.db ".OUT" .db ".OUT"
.db "#inc" .db "#inc"
.db ".BIN"
; This is a list of handlers corresponding to indexes in directiveNames ; This is a list of handlers corresponding to indexes in directiveNames
directiveHandlers: directiveHandlers:
@ -33,6 +35,7 @@ directiveHandlers:
.dw handleFIL .dw handleFIL
.dw handleOUT .dw handleOUT
.dw handleINC .dw handleINC
.dw handleBIN
handleDB: handleDB:
push hl push hl
@ -254,12 +257,31 @@ handleINC:
call unsetZ call unsetZ
ret ret
handleBIN:
call readWord
jr nz, .badfmt
; HL points to scratchpad
call enterDoubleQuotes
jr nz, .badfmt
call ioSpitBin
jr nz, .badfn
cp a ; ensure Z
ret
.badfmt:
ld a, ERR_BAD_FMT
jr .error
.badfn:
ld a, ERR_FILENOTFOUND
.error:
call unsetZ
ret
; Reads string in (HL) and returns the corresponding ID (D_*) in A. Sets Z if ; Reads string in (HL) and returns the corresponding ID (D_*) in A. Sets Z if
; there's a match. ; there's a match.
getDirectiveID: getDirectiveID:
push bc push bc
push de push de
ld b, D_INC+1 ; D_INC is last ld b, D_BIN+1 ; D_BIN is last
ld c, 4 ld c, 4
ld de, directiveNames ld de, directiveNames
call findStringInList call findStringInList

View File

@ -58,7 +58,9 @@
.equ IO_INC_LINENO IO_LINENO+2 .equ IO_INC_LINENO IO_LINENO+2
; Line number (can be top-level or include) when ioSavePos was last called. ; Line number (can be top-level or include) when ioSavePos was last called.
.equ IO_SAVED_LINENO IO_INC_LINENO+2 .equ IO_SAVED_LINENO IO_INC_LINENO+2
.equ IO_RAMEND IO_SAVED_LINENO+2 ; Handle for the ioSpitBin
.equ IO_BIN_HDL IO_SAVED_LINENO+2
.equ IO_RAMEND IO_BIN_HDL+FS_HANDLE_SIZE
; *** Code *** ; *** Code ***
@ -238,6 +240,27 @@ ioOpenInclude:
cp a ; ensure Z cp a ; ensure Z
ret ret
; Open file specified in (HL) and spit its contents through ioPutC
; Sets Z on success.
ioSpitBin:
call fsFindFN
ret nz
push hl ; --> lvl 1
ld ix, IO_BIN_HDL
call fsOpen
ld hl, 0
.loop:
ld ix, IO_BIN_HDL
call fsGetC
jr nz, .loopend
call ioPutC
inc hl
jr .loop
.loopend:
pop hl ; <-- lvl 1
cp a ; ensure Z
ret
; Return current lineno in HL and, if in an include, its lineno in DE. ; Return current lineno in HL and, if in an include, its lineno in DE.
; If not in an include, DE is set to 0 ; If not in an include, DE is set to 0
ioLineNo: ioLineNo:

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
inc a
.bin "err.h"
inc b

View File

@ -0,0 +1,15 @@
<; Error codes used throughout the kernel
; The command that was type isn't known to the shell
.equ SHELL_ERR_UNKNOWN_CMD 0x01
; Arguments for the command weren't properly formatted
.equ SHELL_ERR_BAD_ARGS 0x02
.equ BLOCKDEV_ERR_OUT_OF_BOUNDS 0x03
.equ BLOCKDEV_ERR_UNSUPPORTED 0x04
; IO routines (GetC, PutC) returned an error in a load/save command
.equ SHELL_ERR_IO_ERROR 0x05


View File

@ -1,48 +0,0 @@
.equ USER_CODE 0x4800
.equ USER_RAMSTART 0x5800
.equ FS_HANDLE_SIZE 6
.equ BLOCKDEV_SIZE 8
; *** JUMP TABLE ***
.equ strncmp 0x03
.equ addDE 0x06
.equ addHL 0x09
.equ upcase 0x0c
.equ unsetZ 0x0f
.equ intoDE 0x12
.equ intoHL 0x15
.equ writeHLinDE 0x18
.equ findchar 0x1b
.equ parseHex 0x1e
.equ parseHexPair 0x21
.equ blkSel 0x24
.equ blkSet 0x27
.equ fsFindFN 0x2a
.equ fsOpen 0x2d
.equ fsGetC 0x30
.equ cpHLDE 0x33
.equ parseArgs 0x36
.equ _blkGetC 0x39
.equ _blkPutC 0x3c
.equ _blkSeek 0x3f
.equ _blkTell 0x42
.equ printstr 0x45
#include "err.h"
#include "zasm/const.asm"
#include "lib/util.asm"
#include "zasm/util.asm"
.equ IO_RAMSTART USER_RAMSTART
#include "zasm/io.asm"
.equ SYM_RAMSTART IO_RAMEND
#include "zasm/symbol.asm"
#include "lib/parse.asm"
#include "zasm/parse.asm"
.equ TOK_RAMSTART SYM_RAMEND
#include "zasm/tok.asm"
.equ DIREC_RAMSTART TOK_RAMEND
#include "zasm/directive.asm"
#include "zasm/instr.asm"
#include "zasm/expr.asm"
.equ ZASM_RAMSTART TOK_RAMEND
#include "zasm/main.asm"

Binary file not shown.