mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-30 20:48:06 +11:00
zasm: add separate symbol registry for constants
This will allow me to make the ".org" treatment a bit less murky.
This commit is contained in:
parent
cdb206b7a5
commit
9ea72dc1d0
@ -142,7 +142,7 @@ handleEQU:
|
|||||||
jr nz, .badarg
|
jr nz, .badarg
|
||||||
ld hl, DIREC_SCRATCHPAD
|
ld hl, DIREC_SCRATCHPAD
|
||||||
push ix \ pop de
|
push ix \ pop de
|
||||||
call symRegisterGlobal ; A and Z set
|
call symRegisterConst ; A and Z set
|
||||||
jr .end
|
jr .end
|
||||||
.badfmt:
|
.badfmt:
|
||||||
ld a, ERR_BAD_FMT
|
ld a, ERR_BAD_FMT
|
||||||
|
@ -11,32 +11,38 @@
|
|||||||
; and continue second pass as usual.
|
; and continue second pass as usual.
|
||||||
|
|
||||||
; *** Constants ***
|
; *** Constants ***
|
||||||
; Maximum number of symbols we can have in the global registry
|
; Maximum number of symbols we can have in the global and consts registry
|
||||||
.equ SYM_MAXCOUNT 0x200
|
.equ SYM_MAXCOUNT 0x100
|
||||||
; Maximum number of symbols we can have in the local registry
|
; Maximum number of symbols we can have in the local registry
|
||||||
.equ SYM_LOC_MAXCOUNT 0x40
|
.equ SYM_LOC_MAXCOUNT 0x40
|
||||||
|
|
||||||
; Size of the symbol name buffer size. This is a pool. There is no maximum name
|
; Size of the symbol name buffer size. This is a pool. There is no maximum name
|
||||||
; length for a single symbol, just a maximum size for the whole pool.
|
; length for a single symbol, just a maximum size for the whole pool.
|
||||||
.equ SYM_BUFSIZE 0x2000
|
; Global labels and consts have the same buf size
|
||||||
|
.equ SYM_BUFSIZE 0x1000
|
||||||
|
|
||||||
; Size of the names buffer for the local context registry
|
; Size of the names buffer for the local context registry
|
||||||
.equ SYM_LOC_BUFSIZE 0x200
|
.equ SYM_LOC_BUFSIZE 0x200
|
||||||
|
|
||||||
; *** Variables ***
|
; *** Variables ***
|
||||||
|
; Global labels registry
|
||||||
|
|
||||||
; Each symbol is mapped to a word value saved here.
|
; Each symbol is mapped to a word value saved here.
|
||||||
.equ SYM_VALUES SYM_RAMSTART
|
.equ SYM_GLOB_VALUES SYM_RAMSTART
|
||||||
|
|
||||||
; A list of symbol names separated by null characters. When we encounter a
|
; A list of symbol names separated by null characters. When we encounter a
|
||||||
; symbol name and want to get its value, we search the name here, retrieve the
|
; symbol name and want to get its value, we search the name here, retrieve the
|
||||||
; index of the name, then go get the value at that index in SYM_VALUES.
|
; index of the name, then go get the value at that index in SYM_GLOB_VALUES.
|
||||||
.equ SYM_NAMES SYM_VALUES+SYM_MAXCOUNT*2
|
.equ SYM_GLOB_NAMES SYM_GLOB_VALUES+SYM_MAXCOUNT*2
|
||||||
|
|
||||||
; Registry for local labels. Wiped out after each context change.
|
; Registry for local labels. Wiped out after each context change.
|
||||||
.equ SYM_LOC_VALUES SYM_NAMES+SYM_BUFSIZE
|
.equ SYM_LOC_VALUES SYM_GLOB_NAMES+SYM_BUFSIZE
|
||||||
.equ SYM_LOC_NAMES SYM_LOC_VALUES+SYM_LOC_MAXCOUNT*2
|
.equ SYM_LOC_NAMES SYM_LOC_VALUES+SYM_LOC_MAXCOUNT*2
|
||||||
|
|
||||||
.equ SYM_RAMEND SYM_LOC_NAMES+SYM_LOC_BUFSIZE
|
; Registry for constants
|
||||||
|
.equ SYM_CONST_VALUES SYM_LOC_NAMES+SYM_LOC_BUFSIZE
|
||||||
|
.equ SYM_CONST_NAMES SYM_CONST_VALUES+SYM_MAXCOUNT*2
|
||||||
|
.equ SYM_RAMEND SYM_CONST_NAMES+SYM_BUFSIZE
|
||||||
|
|
||||||
; *** Registries ***
|
; *** Registries ***
|
||||||
; A symbol registry is a 6 bytes record with points to names and values of
|
; A symbol registry is a 6 bytes record with points to names and values of
|
||||||
@ -44,10 +50,14 @@
|
|||||||
; It's 3 pointers: names, names end, values
|
; It's 3 pointers: names, names end, values
|
||||||
|
|
||||||
SYM_GLOBAL_REGISTRY:
|
SYM_GLOBAL_REGISTRY:
|
||||||
.dw SYM_NAMES, SYM_NAMES+SYM_BUFSIZE, SYM_VALUES
|
.dw SYM_GLOB_NAMES, SYM_GLOB_NAMES+SYM_BUFSIZE, SYM_GLOB_VALUES
|
||||||
|
|
||||||
SYM_LOCAL_REGISTRY:
|
SYM_LOCAL_REGISTRY:
|
||||||
.dw SYM_LOC_NAMES, SYM_LOC_NAMES+SYM_LOC_BUFSIZE, SYM_LOC_VALUES
|
.dw SYM_LOC_NAMES, SYM_LOC_NAMES+SYM_LOC_BUFSIZE, SYM_LOC_VALUES
|
||||||
|
|
||||||
|
SYM_CONST_REGISTRY:
|
||||||
|
.dw SYM_CONST_NAMES, SYM_CONST_NAMES+SYM_BUFSIZE, SYM_CONST_VALUES
|
||||||
|
|
||||||
; *** Code ***
|
; *** Code ***
|
||||||
|
|
||||||
; Assuming that HL points in to a symbol name list, advance HL to the beginning
|
; Assuming that HL points in to a symbol name list, advance HL to the beginning
|
||||||
@ -71,8 +81,9 @@ _symNext:
|
|||||||
|
|
||||||
symInit:
|
symInit:
|
||||||
xor a
|
xor a
|
||||||
ld (SYM_NAMES), a
|
ld (SYM_GLOB_NAMES), a
|
||||||
ld (SYM_LOC_NAMES), a
|
ld (SYM_LOC_NAMES), a
|
||||||
|
ld (SYM_CONST_NAMES), a
|
||||||
; Continue to symSelectGlobalRegistry
|
; Continue to symSelectGlobalRegistry
|
||||||
|
|
||||||
; Sets Z according to whether label in (HL) is local (starts with a dot)
|
; Sets Z according to whether label in (HL) is local (starts with a dot)
|
||||||
@ -142,6 +153,13 @@ symRegisterLocal:
|
|||||||
pop ix
|
pop ix
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
symRegisterConst:
|
||||||
|
push ix
|
||||||
|
ld ix, SYM_CONST_REGISTRY
|
||||||
|
call symRegister
|
||||||
|
pop ix
|
||||||
|
ret
|
||||||
|
|
||||||
; Register label in (HL) (minus the ending ":") into the symbol registry and
|
; Register label in (HL) (minus the ending ":") into the symbol registry and
|
||||||
; set its value in that registry to DE.
|
; set its value in that registry to DE.
|
||||||
; If successful, Z is set and A is the symbol index. Otherwise, Z is unset and
|
; If successful, Z is set and A is the symbol index. Otherwise, Z is unset and
|
||||||
@ -281,16 +299,25 @@ _symFind:
|
|||||||
; reselect it afterwards.
|
; reselect it afterwards.
|
||||||
symFindVal:
|
symFindVal:
|
||||||
push ix
|
push ix
|
||||||
ld ix, SYM_GLOBAL_REGISTRY
|
|
||||||
call symIsLabelLocal
|
call symIsLabelLocal
|
||||||
jp nz, .notLocal
|
jr z, .local
|
||||||
ld ix, SYM_LOCAL_REGISTRY
|
; global. Let's try labels first, then consts
|
||||||
.notLocal:
|
ld ix, SYM_GLOBAL_REGISTRY
|
||||||
|
call _symFind
|
||||||
|
jr z, .found
|
||||||
|
ld ix, SYM_CONST_REGISTRY
|
||||||
call _symFind
|
call _symFind
|
||||||
jr nz, .end
|
jr nz, .end
|
||||||
|
.found:
|
||||||
; Found! let's fetch value
|
; Found! let's fetch value
|
||||||
; DE is pointing to our result
|
; DE is pointing to our result
|
||||||
call intoDE
|
call intoDE
|
||||||
|
jr .end
|
||||||
|
.local:
|
||||||
|
ld ix, SYM_LOCAL_REGISTRY
|
||||||
|
call _symFind
|
||||||
|
jr z, .found
|
||||||
|
; continue to end
|
||||||
.end:
|
.end:
|
||||||
pop ix
|
pop ix
|
||||||
ret
|
ret
|
||||||
|
Loading…
Reference in New Issue
Block a user