mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-25 20:33:13 +00:00
458 lines
7.7 KiB
Plaintext
458 lines
7.7 KiB
Plaintext
NEW
|
||
PREFIX
|
||
AUTO 4,1
|
||
*---------------------------------------
|
||
* Global Symbol Record: (6+ bytes)
|
||
* 0 : Len
|
||
* 1 : Flags:
|
||
* b7=0=pending,1=resolved
|
||
* b6=R/W (.SE)
|
||
* b2,b1,b0 : Size (in bytes)
|
||
* 2-5 : 32 bits Value
|
||
* 6+ : Local Symbols.....
|
||
*---------------------------------------
|
||
* Local Symbol Record: (5 bytes)
|
||
* 0 : Local ID (1->255)
|
||
* 1-4 : 32 bits Value (PC)
|
||
*---------------------------------------
|
||
SYM.Init >SYSCALL SListNew
|
||
bcs .9
|
||
|
||
>STA.G SYM.hGlobalList
|
||
|
||
>LDYAI 256
|
||
>SYSCALL getmem
|
||
bcs .9
|
||
|
||
>STYA ZPNameBuf
|
||
txa
|
||
>STA.G SYM.hNameBuf
|
||
|
||
>LDYAI 256
|
||
>SYSCALL getmem
|
||
bcs .9
|
||
|
||
>STYA ZPGlobalBuf
|
||
txa
|
||
>STA.G SYM.hGlobalBuf
|
||
|
||
.9 rts
|
||
*---------------------------------------
|
||
SYM.Reset >STZ.G SYM.bInGlobal
|
||
rts
|
||
*---------------------------------------
|
||
SYM.Quit >LDA.G SYM.hNameBuf
|
||
beq .2
|
||
|
||
>SYSCALL FreeMem
|
||
|
||
.2 >LDA.G SYM.hGlobalBuf
|
||
beq .3
|
||
|
||
>SYSCALL FreeMem
|
||
|
||
.3 >LDA.G SYM.hGlobalList
|
||
beq SYM.Quit.8
|
||
>SYSCALL SListFree
|
||
|
||
SYM.Quit.8 clc
|
||
SYM.Quit.RTS rts
|
||
*---------------------------------------
|
||
SYM.Dump >LDA.G ASM.LI.ON
|
||
bpl SYM.Quit.8
|
||
|
||
>LDYA L.MSG.SYMBOLS
|
||
>SYSCALL puts
|
||
|
||
stz ZPPtr2
|
||
stz ZPPtr2+1
|
||
|
||
.1 >LDYA ZPPtr2
|
||
>STYA ZPPtr1
|
||
|
||
>PUSHW ZPNameBuf
|
||
>PUSHW ZPPtr1
|
||
>LDA.G SYM.hGlobalList
|
||
>SYSCALL SListGetByID
|
||
bcs SYM.Quit.8
|
||
|
||
>STYA ZPPtr2 Save Next ID
|
||
|
||
>PUSHWI 0 Start
|
||
>PUSHWI $ffff End
|
||
>PUSHW ZPGlobalBuf
|
||
>PUSHW ZPPtr1 KeyID
|
||
>LDA.G SYM.hGlobalList
|
||
|
||
>SYSCALL SListGetData
|
||
bcs SYM.Quit.RTS
|
||
|
||
ldy #SYMG.SIZE Get Symbol Size
|
||
lda (ZPGlobalBuf),y
|
||
|
||
tax
|
||
beq .3
|
||
|
||
phx
|
||
|
||
.2 iny
|
||
lda (ZPGlobalBuf),y
|
||
>PUSHA
|
||
dex
|
||
bne .2
|
||
|
||
pla Byte Count
|
||
asl
|
||
tax
|
||
|
||
.3 >PUSHA
|
||
|
||
ldy L.MSG.EQU0,x
|
||
lda L.MSG.EQU0+1,x
|
||
>SYSCALL printf
|
||
|
||
>PUSHBI 0
|
||
>LDYA ZPNameBuf Label
|
||
>SYSCALL printf
|
||
|
||
lda (ZPGlobalBuf)
|
||
|
||
bit #SYMG.F.LOCALS
|
||
beq .7
|
||
|
||
ldy #SYMG
|
||
|
||
.4 lda (ZPGlobalBuf),y
|
||
beq .7 End Local Symbol
|
||
|
||
pha Save ID
|
||
|
||
ldx #4
|
||
|
||
.5 iny
|
||
lda (ZPGlobalBuf),y
|
||
>PUSHA
|
||
dex
|
||
bne .5
|
||
|
||
pla
|
||
>PUSHA
|
||
phy
|
||
>PUSHBI 6
|
||
>LDYA L.MSG.LSYMBOL
|
||
>SYSCALL printf
|
||
ply
|
||
bne .4
|
||
|
||
.7 >PUSHBI 0
|
||
>LDYA L.MSG.CRLF
|
||
>SYSCALL printf
|
||
jmp .1
|
||
*---------------------------------------
|
||
SYM.NewOrGetGlobal
|
||
>LDA.G ASM.PASS
|
||
bne SYM.GetGlobal
|
||
|
||
SYM.NewGlobal jsr SYM.StoreGlobal
|
||
bcs .99
|
||
|
||
>PUSHW ZPLinePtr Pass #1; try to add global...
|
||
>LDA.G SYM.hGlobalList
|
||
>SYSCALL SListNewKey
|
||
bcs .9 Already Defined
|
||
>STYA.G SYM.GlobalID
|
||
txa
|
||
|
||
adc ZPLinePtr
|
||
sta ZPLinePtr
|
||
bcc .1
|
||
|
||
inc ZPLinePtr+1
|
||
|
||
.1 jsr SYM.PC2Acc
|
||
|
||
jsr SYM.Acc2Global
|
||
|
||
lda #SYMG
|
||
|
||
>STA.G SYM.GlobalPtr
|
||
tay
|
||
|
||
lda #0
|
||
sta (ZPGlobalBuf),y
|
||
|
||
lda #$ff
|
||
>STA.G SYM.bInGlobal
|
||
|
||
clc
|
||
rts
|
||
|
||
.9 lda #ERR.SYMBOL.REDEF
|
||
sec
|
||
.99 rts
|
||
*---------------------------------------
|
||
SYM.GetGlobal >PUSHW ZPLinePtr Pass #2: should be already defined...
|
||
>LDA.G SYM.hGlobalList
|
||
>SYSCALL SListLookup
|
||
bcs .9
|
||
>STYA.G SYM.GlobalID
|
||
|
||
txa
|
||
adc ZPLinePtr
|
||
sta ZPLinePtr
|
||
bcc .1
|
||
|
||
inc ZPLinePtr+1
|
||
|
||
.1 >PUSHWI 0 Start
|
||
>PUSHWI $ffff End
|
||
>PUSHW ZPGlobalBuf
|
||
>PUSHW.G SYM.GlobalID
|
||
>LDA.G SYM.hGlobalList
|
||
>SYSCALL SListGetData
|
||
bcs .99
|
||
|
||
lda #$ff
|
||
>STA.G SYM.bInGlobal
|
||
* clc
|
||
rts
|
||
|
||
.9 lda #ERR.UNDEF.SYMBOL
|
||
sec
|
||
.99 rts
|
||
*---------------------------------------
|
||
SYM.LookupGlobal
|
||
>PUSHW ZPLinePtr
|
||
>LDA.G SYM.hGlobalList
|
||
>SYSCALL SListLookup
|
||
bcs .9
|
||
|
||
>STYA ZPPtr1
|
||
|
||
txa
|
||
adc ZPLinePtr
|
||
sta ZPLinePtr
|
||
bcc .1
|
||
|
||
inc ZPLinePtr+1
|
||
|
||
.1 >LDA.G SYM.GlobalID
|
||
cmp ZPPtr1
|
||
bne .3
|
||
iny SYM.GlobalID+1
|
||
lda (pData),y
|
||
cmp ZPPtr1+1
|
||
bne .3
|
||
|
||
ldy #SYMG-1
|
||
|
||
.2 lda (ZPGlobalBuf),y
|
||
sta SRC.ACC.F,y
|
||
dey
|
||
bpl .2
|
||
|
||
clc
|
||
rts
|
||
|
||
.3 >PUSHWI 0 Start
|
||
>PUSHWI SYMG Get only Global value
|
||
>PUSHW L.SRC.ACC.F
|
||
>PUSHW ZPPtr1
|
||
>LDA.G SYM.hGlobalList
|
||
>SYSCALL SListGetData
|
||
rts
|
||
|
||
.9 lda #ERR.UNDEF.SYMBOL
|
||
sec
|
||
rts
|
||
*---------------------------------------
|
||
SYM.StoreGlobal >LDA.G ASM.PASS
|
||
bne .8
|
||
|
||
>LDA.G SYM.bInGlobal
|
||
bpl .8
|
||
|
||
>LDA.G SYM.GlobalPtr
|
||
tay
|
||
lda #0
|
||
cpy #SYMG
|
||
beq .1
|
||
|
||
lda (ZPGlobalBuf)
|
||
ora #SYMG.F.LOCALS
|
||
sta (ZPGlobalBuf)
|
||
|
||
lda #0
|
||
sta (ZPGlobalBuf),y
|
||
iny
|
||
bne .1
|
||
inc
|
||
|
||
.1 >PUSHYA
|
||
|
||
.2 >PUSHW ZPGlobalBuf
|
||
>PUSHW.G SYM.GlobalID
|
||
>LDA.G SYM.hGlobalList
|
||
>SYSCALL SListAddData
|
||
bcs .9
|
||
|
||
lda #0
|
||
>STA.G SYM.bInGlobal
|
||
|
||
rts
|
||
|
||
.8 clc
|
||
.9 rts
|
||
*---------------------------------------
|
||
SYM.UpdateGlobal
|
||
>PUSHWI SYMG
|
||
>PUSHW L.SRC.ACC.F
|
||
>PUSHW.G SYM.GlobalID
|
||
>LDA.G SYM.hGlobalList
|
||
>SYSCALL SListSetData
|
||
rts
|
||
*---------------------------------------
|
||
SYM.PC2Acc ldy #ASM.PC+3
|
||
ldx #3
|
||
|
||
.1 lda (pData),y
|
||
sta SRC.ACC,x
|
||
dey
|
||
dex
|
||
bpl .1
|
||
|
||
lda #2
|
||
sta SRC.ACC.SIZE
|
||
stz SRC.ACC.F
|
||
|
||
rts
|
||
*---------------------------------------
|
||
SYM.Acc2Global ldy #SYMG-1
|
||
|
||
.2 lda SRC.ACC.F,y
|
||
sta (ZPGlobalBuf),y
|
||
|
||
dey
|
||
bpl .2
|
||
rts
|
||
*---------------------------------------
|
||
* Local Symbol Record: (5 bytes)
|
||
* 0 : Local ID (1->255)
|
||
* 1-4 : 32 bits Value (PC)
|
||
*---------------------------------------
|
||
SYM.NewOrGetLocalA
|
||
tax Save Local ID
|
||
|
||
>LDA.G SYM.bInGlobal not in a global label
|
||
bpl .91
|
||
|
||
>LDA.G ASM.PASS Pass #2: should be already defined...
|
||
bne SYM.GetLocalX
|
||
|
||
jsr SYM.GetLocalX Pass #1; try to add
|
||
bcc .9 Already Defined
|
||
|
||
>LDA.G SYM.GlobalPtr
|
||
tay
|
||
beq .90
|
||
|
||
ldy #ASM.PC+4
|
||
|
||
.1 dey
|
||
lda (pData),y
|
||
pha
|
||
cpy #ASM.PC
|
||
bne .1
|
||
|
||
>LDA.G SYM.GlobalPtr
|
||
tay
|
||
|
||
txa Get Back ID
|
||
sta (ZPGlobalBuf),y
|
||
|
||
ldx #4
|
||
|
||
.2 pla
|
||
iny
|
||
sta (ZPGlobalBuf),y
|
||
dex
|
||
bne .2
|
||
|
||
tya
|
||
>STA.G SYM.GlobalPtr
|
||
|
||
iny
|
||
lda #0
|
||
sta (ZPGlobalBuf),y
|
||
|
||
clc
|
||
rts
|
||
|
||
.91 lda #ERR.INV.LABEL
|
||
sec
|
||
rts
|
||
|
||
.90 lda #ERR.TOO.MANY.LOCAL
|
||
sec
|
||
rts
|
||
|
||
.9 lda #ERR.SYMBOL.REDEF
|
||
sec
|
||
rts
|
||
*---------------------------------------
|
||
SYM.GetLocalX lda (ZPGlobalBuf)
|
||
and #SYMG.F.LOCALS
|
||
beq .9
|
||
|
||
ldy #SYML
|
||
|
||
.1 lda (ZPGlobalBuf),y
|
||
beq .9
|
||
|
||
txa
|
||
cmp (ZPGlobalBuf),y
|
||
bne .3
|
||
|
||
ldx #4
|
||
stx SRC.ACC.SIZE
|
||
|
||
.2 iny
|
||
lda (ZPGlobalBuf),y
|
||
sta SRC.ACC.SIZE,x
|
||
dex
|
||
bne .2
|
||
|
||
clc
|
||
rts
|
||
|
||
.3 tya
|
||
clc
|
||
adc #SYML
|
||
tay
|
||
bne .1
|
||
|
||
.9 lda #ERR.UNDEF.SYMBOL
|
||
sec
|
||
rts
|
||
*---------------------------------------
|
||
* Private Symbol Record: (9 bytes)
|
||
* 0 : Len (8)
|
||
* 1 : Flags:
|
||
* b7=0=pending,1=resolved
|
||
* 2-5 : 32 bits Value (PC)
|
||
* 6,7 : MCID (Macro Context ID)
|
||
* 8 : Private ID (0->255)
|
||
*---------------------------------------
|
||
SYM.AddPrivate
|
||
clc
|
||
rts
|
||
*---------------------------------------
|
||
SYM.LookupPrivate
|
||
clc
|
||
rts
|
||
*---------------------------------------
|
||
MAN
|
||
SAVE USR/SRC/BIN/ASM.S.SYM
|
||
LOAD USR/SRC/BIN/ASM.S
|
||
ASM
|