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:
parent
01031a780a
commit
34f499184d
@ -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
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Binary file not shown.
Binary file not shown.
3
tools/tests/zasm/test10.asm
Normal file
3
tools/tests/zasm/test10.asm
Normal file
@ -0,0 +1,3 @@
|
||||
inc a
|
||||
.bin "err.h"
|
||||
inc b
|
15
tools/tests/zasm/test10.asm.expected
Normal file
15
tools/tests/zasm/test10.asm.expected
Normal 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
|
||||
|
||||
|
@ -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.
Loading…
Reference in New Issue
Block a user