diff --git a/apps/zasm/README.md b/apps/zasm/README.md index 9ae8f41..335660b 100644 --- a/apps/zasm/README.md +++ b/apps/zasm/README.md @@ -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 file. -## Compatibility with scas - -This project was initially assembled with [scas][scas], but now that zasm self- -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. +**.bin**: Takes a string literal as an argument. Open the file name specified + in the argument in the currently active filesystem and outputs its + contents directly. [libz80]: https://github.com/ggambetta/libz80 -[scas]: https://github.com/KnightOS/scas diff --git a/apps/zasm/directive.asm b/apps/zasm/directive.asm index 2fae320..cc8201d 100644 --- a/apps/zasm/directive.asm +++ b/apps/zasm/directive.asm @@ -7,6 +7,7 @@ .equ D_FIL 0x04 .equ D_OUT 0x05 .equ D_INC 0x06 +.equ D_BIN 0x07 .equ D_BAD 0xff ; *** Variables *** @@ -23,6 +24,7 @@ directiveNames: .db ".FIL" .db ".OUT" .db "#inc" + .db ".BIN" ; This is a list of handlers corresponding to indexes in directiveNames directiveHandlers: @@ -33,6 +35,7 @@ directiveHandlers: .dw handleFIL .dw handleOUT .dw handleINC + .dw handleBIN handleDB: push hl @@ -254,12 +257,31 @@ handleINC: call unsetZ 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 ; there's a match. getDirectiveID: push bc push de - ld b, D_INC+1 ; D_INC is last + ld b, D_BIN+1 ; D_BIN is last ld c, 4 ld de, directiveNames call findStringInList diff --git a/apps/zasm/io.asm b/apps/zasm/io.asm index 8ed4df8..783db63 100644 --- a/apps/zasm/io.asm +++ b/apps/zasm/io.asm @@ -58,7 +58,9 @@ .equ IO_INC_LINENO IO_LINENO+2 ; Line number (can be top-level or include) when ioSavePos was last called. .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 *** @@ -238,6 +240,27 @@ ioOpenInclude: cp a ; ensure Z 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. ; If not in an include, DE is set to 0 ioLineNo: diff --git a/tools/emul/zasm/kernel.bin b/tools/emul/zasm/kernel.bin index 673bef5..6c3c6ea 100644 Binary files a/tools/emul/zasm/kernel.bin and b/tools/emul/zasm/kernel.bin differ diff --git a/tools/emul/zasm/zasm.bin b/tools/emul/zasm/zasm.bin index c8d8272..37e5bef 100644 Binary files a/tools/emul/zasm/zasm.bin and b/tools/emul/zasm/zasm.bin differ diff --git a/tools/tests/zasm/test10.asm b/tools/tests/zasm/test10.asm new file mode 100644 index 0000000..e881084 --- /dev/null +++ b/tools/tests/zasm/test10.asm @@ -0,0 +1,3 @@ +inc a +.bin "err.h" +inc b diff --git a/tools/tests/zasm/test10.asm.expected b/tools/tests/zasm/test10.asm.expected new file mode 100644 index 0000000..56d3434 --- /dev/null +++ b/tools/tests/zasm/test10.asm.expected @@ -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 + + \ No newline at end of file diff --git a/tools/tests/zasm/test7.asm b/tools/tests/zasm/test7.asm deleted file mode 100644 index 1b28c11..0000000 --- a/tools/tests/zasm/test7.asm +++ /dev/null @@ -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" diff --git a/tools/tests/zasm/test7.asm.expected b/tools/tests/zasm/test7.asm.expected deleted file mode 100644 index 2046b75..0000000 Binary files a/tools/tests/zasm/test7.asm.expected and /dev/null differ