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

zasm: add "last value" symbol (@)

This commit is contained in:
Virgil Dupras 2019-10-04 20:26:21 -04:00
parent 63d6cf0875
commit 612323f714
9 changed files with 52 additions and 24 deletions

View File

@ -1,8 +1,7 @@
# z80 assembler # z80 assembler
This is probably the most critical part of the Collapse OS project. If this app This is probably the most critical part of the Collapse OS project because it
can be brought to completion, it pretty much makes the project a success because ensures its self-reproduction.
it ensures self-reproduction.
## Running on a "modern" machine ## Running on a "modern" machine
@ -92,6 +91,12 @@ The `$` is a special symbol that can be placed in any expression and evaluated
as the current output offset. That is, it's the value that a label would have if as the current output offset. That is, it's the value that a label would have if
it was placed there. it was placed there.
## The Last Value
Whenever a `.equ` directive is evaluated, its resulting value is saved in a
special "last value" register that can then be used in any expression. This
is very useful for variable definitions and for jump tables.
## Includes ## Includes
The `#inc` directive is special. It takes a string literal as an argument and The `#inc` directive is special. It takes a string literal as an argument and

View File

@ -11,7 +11,9 @@
.equ D_BAD 0xff .equ D_BAD 0xff
; *** Variables *** ; *** Variables ***
.equ DIREC_SCRATCHPAD DIREC_RAMSTART ; Result of the last .equ evaluation. Used for "@" symbol.
.equ DIREC_LASTVAL DIREC_RAMSTART
.equ DIREC_SCRATCHPAD DIREC_LASTVAL+2
.equ DIREC_RAMEND DIREC_SCRATCHPAD+SCRATCHPAD_SIZE .equ DIREC_RAMEND DIREC_SCRATCHPAD+SCRATCHPAD_SIZE
; *** CODE *** ; *** CODE ***
@ -148,6 +150,8 @@ handleEQU:
jr nz, .badarg jr nz, .badarg
ld hl, DIREC_SCRATCHPAD ld hl, DIREC_SCRATCHPAD
push ix \ pop de push ix \ pop de
; Save value in "@" special variable
ld (DIREC_LASTVAL), de
call symRegisterConst ; A and Z set call symRegisterConst ; A and Z set
jr z, .end ; success jr z, .end ; success
; register ended up in error. We need to figure which error. If it's ; register ended up in error. We need to figure which error. If it's

View File

@ -76,12 +76,12 @@ jp zasmMain
.equ TOK_RAMSTART IO_RAMEND .equ TOK_RAMSTART IO_RAMEND
#include "zasm/tok.asm" #include "zasm/tok.asm"
#include "lib/parse.asm" #include "lib/parse.asm"
#include "zasm/parse.asm"
#include "zasm/expr.asm"
.equ INS_RAMSTART TOK_RAMEND .equ INS_RAMSTART TOK_RAMEND
#include "zasm/instr.asm" #include "zasm/instr.asm"
.equ DIREC_RAMSTART INS_RAMEND .equ DIREC_RAMSTART INS_RAMEND
#include "zasm/directive.asm" #include "zasm/directive.asm"
#include "zasm/parse.asm"
#include "zasm/expr.asm"
.equ SYM_RAMSTART DIREC_RAMEND .equ SYM_RAMSTART DIREC_RAMEND
#include "zasm/symbol.asm" #include "zasm/symbol.asm"
.equ ZASM_RAMSTART SYM_RAMEND .equ ZASM_RAMSTART SYM_RAMEND

View File

@ -168,13 +168,19 @@ parseLiteral:
parseNumberOrSymbol: parseNumberOrSymbol:
call parseLiteral call parseLiteral
ret z ret z
; Not a number. Try PC ; Not a number.
push de ; --> lvl 1 ; Is str a single char? If yes, maybe it's a special symbol.
ld de, .sDollar call strIs1L
call strcmp jr nz, .symbol ; nope
pop de ; <-- lvl 1 ld a, (hl)
cp '$'
jr z, .returnPC jr z, .returnPC
; Not PC either, try symbol cp '@'
jr nz, .symbol
; last val
ld ix, (DIREC_LASTVAL)
ret
.symbol:
push de ; --> lvl 1 push de ; --> lvl 1
call symFindVal ; --> DE call symFindVal ; --> DE
jr nz, .notfound jr nz, .notfound
@ -197,5 +203,3 @@ parseNumberOrSymbol:
push hl \ pop ix push hl \ pop ix
pop hl pop hl
ret ret
.sDollar:
.db '$', 0

View File

@ -52,6 +52,16 @@ strlen:
pop bc pop bc
ret ret
; Sets Z if string at (HL) is one character long
strIs1L:
xor a
cp (hl)
jp z, unsetZ ; empty string
inc hl
cp (hl) ; Z has proper value
dec hl ; doesn't touch Z
ret
; Compares strings pointed to by HL and DE up to A count of characters in a ; Compares strings pointed to by HL and DE up to A count of characters in a
; case-insensitive manner. ; case-insensitive manner.
; If equal, Z is set. If not equal, Z is reset. ; If equal, Z is set. If not equal, Z is reset.

View File

@ -43,15 +43,6 @@ updatebootstrap: $(ZASMBIN) $(INCCFS)
$(ZASMSH) $(KERNEL) < zasm/glue.asm > zasm/kernel.bin $(ZASMSH) $(KERNEL) < zasm/glue.asm > zasm/kernel.bin
$(ZASMSH) $(KERNEL) $(APPS) zasm/user.h < $(APPS)/zasm/glue.asm > zasm/zasm.bin $(ZASMSH) $(KERNEL) $(APPS) zasm/user.h < $(APPS)/zasm/glue.asm > zasm/zasm.bin
# Sometimes, when developing zasm, stuff get messed up and it's hard to unmess
# because zasm's brake-up ends up in its bootstrap bins. Sure, we can revert
# from git, but if we're in the middle of some work, it's inconvenient. As long
# as we don't diverge from scas's syntax, it can come to the recue!
.PHONY: rescue
rescue:
scas -o zasm/kernel.bin -I $(KERNEL) zasm/glue.asm
scas -o zasm/zasm.bin -I $(APPS) -I $(KERNEL) -I zasm $(APPS)/zasm/glue.asm
.PHONY: clean .PHONY: clean
clean: clean:
rm -f $(TARGETS) $(SHELLAPPS) {zasm,shell}/*-bin.h rm -f $(TARGETS) $(SHELLAPPS) {zasm,shell}/*-bin.h

Binary file not shown.

View File

@ -4,6 +4,9 @@
.equ ZASM_REG_BUFSZ 0x1000 .equ ZASM_REG_BUFSZ 0x1000
.equ ZASM_LREG_BUFSZ 0x200 .equ ZASM_LREG_BUFSZ 0x200
; declare DIREC_LASTVAL manually so that we don't have to include directive.asm
.equ DIREC_LASTVAL RAMSTART
jp test jp test
#include "core.asm" #include "core.asm"
@ -13,7 +16,7 @@ jp test
#include "zasm/const.asm" #include "zasm/const.asm"
#include "lib/parse.asm" #include "lib/parse.asm"
#include "zasm/parse.asm" #include "zasm/parse.asm"
.equ SYM_RAMSTART RAMSTART .equ SYM_RAMSTART DIREC_LASTVAL+2
#include "zasm/symbol.asm" #include "zasm/symbol.asm"
#include "zasm/expr.asm" #include "zasm/expr.asm"

View File

@ -1,3 +1,7 @@
.equ RAMSTART 0x4000
; declare DIREC_LASTVAL manually so that we don't have to include directive.asm
.equ DIREC_LASTVAL RAMSTART
jp test jp test
#include "core.asm" #include "core.asm"
@ -80,6 +84,13 @@ test:
jp nz, fail jp nz, fail
call nexttest call nexttest
.equ FOO 0x42
.equ BAR @+1
ld a, BAR
cp 0x43
jp nz, fail
call nexttest
; success ; success
xor a xor a
halt halt