mirror of
https://github.com/A2osX/A2osX.git
synced 2025-01-08 04:29:37 +00:00
491 lines
7.8 KiB
Plaintext
491 lines
7.8 KiB
Plaintext
NEW
|
||
AUTO 3,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/Private Symbol Record: (6 bytes)
|
||
* 0 : Local ID (1->255)
|
||
* 1 : Macro Context ID (private)
|
||
* 2-5 : 32 bits Value (PC)
|
||
*---------------------------------------
|
||
SYM.Init >SYSCALL SListNew
|
||
bcs .9
|
||
|
||
>STA.G SYM.hList
|
||
>LDYAI 256
|
||
>SYSCALL getmem
|
||
bcs .9
|
||
>STYA ZPSymbolBuf
|
||
txa
|
||
>STA.G SYM.hGlobalBuf
|
||
.9 rts
|
||
*---------------------------------------
|
||
SYM.Reset >STZ.G SYM.bInGlobal
|
||
rts
|
||
*---------------------------------------
|
||
SYM.Quit >LDA.G SYM.hGlobalBuf
|
||
beq .1
|
||
|
||
>SYSCALL FreeMem
|
||
|
||
.1 >LDA.G SYM.hList
|
||
beq .8
|
||
|
||
>PUSHA
|
||
>SYSCALL SListFree
|
||
|
||
.8 rts
|
||
*---------------------------------------
|
||
SYM.NewOrGetGlobal
|
||
>LDA.G ASM.PASS
|
||
bne SYM.GetGlobal
|
||
|
||
SYM.NewGlobal jsr SYM.StoreGlobal
|
||
bcs .99
|
||
|
||
>PUSHB.G SYM.hList
|
||
>PUSHW ZPLinePtr Pass #1: try to add global...
|
||
>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 (ZPSymbolBuf),y
|
||
|
||
lda #$ff
|
||
>STA.G SYM.bInGlobal
|
||
|
||
clc
|
||
rts
|
||
|
||
.9 lda #E.SYMBOL.REDEF
|
||
sec
|
||
.99 rts
|
||
*---------------------------------------
|
||
SYM.GetGlobal >PUSHB.G SYM.hList
|
||
>PUSHW ZPLinePtr Pass #2: should be already defined...
|
||
>SYSCALL SListLookup
|
||
bcs .9
|
||
>STYA.G SYM.GlobalID
|
||
|
||
txa
|
||
adc ZPLinePtr
|
||
sta ZPLinePtr
|
||
bcc .1
|
||
inc ZPLinePtr+1
|
||
|
||
.1 >PUSHB.G SYM.hList
|
||
>PUSHW.G SYM.GlobalID
|
||
>PUSHW ZPSymbolBuf
|
||
>PUSHWI $ffff all
|
||
>PUSHWZ from Start
|
||
>SYSCALL SListGetData
|
||
bcs .99
|
||
|
||
lda #$ff
|
||
>STA.G SYM.bInGlobal
|
||
* clc
|
||
rts
|
||
|
||
.9 lda #E.UNDEF.SYMBOL
|
||
sec
|
||
.99 rts
|
||
*---------------------------------------
|
||
SYM.LookupGlobal
|
||
>PUSHB.G SYM.hList
|
||
>PUSHW ZPLinePtr
|
||
>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 (ZPSymbolBuf),y
|
||
sta SRC.ACC.F,y
|
||
dey
|
||
bpl .2
|
||
|
||
clc
|
||
rts
|
||
|
||
.3 >PUSHB.G SYM.hList
|
||
>PUSHW ZPPtr1
|
||
>PUSHW L.SRC.ACC.F
|
||
>PUSHWI SYMG Get only Global value
|
||
>PUSHWZ Start
|
||
>SYSCALL SListGetData
|
||
rts
|
||
|
||
.9 lda #E.UNDEF.SYMBOL
|
||
sec
|
||
rts
|
||
*---------------------------------------
|
||
SYM.StoreGlobal >LDA.G ASM.PASS
|
||
bne .8
|
||
|
||
>LDA.G SYM.bInGlobal
|
||
bpl .8
|
||
|
||
>PUSHB.G SYM.hList
|
||
>PUSHW.G SYM.GlobalID
|
||
>PUSHW ZPSymbolBuf
|
||
|
||
>LDA.G SYM.GlobalPtr
|
||
tay
|
||
lda #0
|
||
cpy #SYMG
|
||
beq .1
|
||
|
||
iny Add 1 for \0 after locals/privates
|
||
bne .1
|
||
inc
|
||
|
||
.1 >PUSHYA
|
||
|
||
>SYSCALL SListAddData
|
||
bcs .9
|
||
|
||
>STZ.G SYM.bInGlobal
|
||
>STA.G MAC.CtxID
|
||
|
||
.8 clc
|
||
.9 rts
|
||
*---------------------------------------
|
||
SYM.UpdateGlobal
|
||
>PUSHB.G SYM.hList
|
||
>PUSHW.G SYM.GlobalID
|
||
>PUSHW ZPSymbolBuf
|
||
|
||
>LDA.G SYM.GlobalPtr
|
||
tay
|
||
lda #0
|
||
cpy #SYMG
|
||
beq .1
|
||
|
||
iny Add 1 for \0 after locals/privates
|
||
bne .1
|
||
inc
|
||
|
||
.1 >PUSHYA
|
||
|
||
>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 (ZPSymbolBuf),y
|
||
dey
|
||
bpl .2
|
||
|
||
rts
|
||
*---------------------------------------
|
||
SYM.NewLocalA 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 .8
|
||
|
||
jsr SYM.GetLocalX Pass #1; try to add
|
||
bcc .9 Already Defined
|
||
|
||
>LDA.G SYM.GlobalPtr
|
||
cmp #252 6*42
|
||
beq .90
|
||
|
||
ldy #ASM.PC+4
|
||
|
||
.1 dey
|
||
lda (pData),y
|
||
pha
|
||
cpy #ASM.PC
|
||
bne .1
|
||
|
||
>LDA.G MAC.CtxID Get Macro Context ID
|
||
|
||
pha
|
||
|
||
>LDA.G SYM.GlobalPtr
|
||
tay
|
||
txa Get Back ID
|
||
sta (ZPSymbolBuf),y
|
||
|
||
ldx #5 MAC ID + PC (4)
|
||
|
||
.2 pla
|
||
iny
|
||
sta (ZPSymbolBuf),y
|
||
dex
|
||
bne .2
|
||
|
||
iny
|
||
lda #0
|
||
sta (ZPSymbolBuf),y ending \0
|
||
tya
|
||
|
||
>STA.G SYM.GlobalPtr
|
||
|
||
lda (ZPSymbolBuf)
|
||
ora #SYMG.F.LOCALS
|
||
sta (ZPSymbolBuf)
|
||
|
||
.8 clc
|
||
rts
|
||
|
||
.91 lda #E.INV.LABEL
|
||
sec
|
||
rts
|
||
|
||
.90 lda #E.TOO.MANY.LOCAL
|
||
sec
|
||
rts
|
||
|
||
.9 lda #E.SYMBOL.REDEF
|
||
sec
|
||
rts
|
||
*---------------------------------------
|
||
SYM.GetLocalX lda (ZPSymbolBuf)
|
||
and #SYMG.F.LOCALS
|
||
beq .9
|
||
|
||
ldy #SYMG
|
||
|
||
.1 lda (ZPSymbolBuf),y
|
||
beq .9
|
||
|
||
txa
|
||
cmp (ZPSymbolBuf),y
|
||
bne .4
|
||
|
||
phy
|
||
>LDA.G MAC.CtxID
|
||
ply
|
||
iny
|
||
cmp (ZPSymbolBuf),y
|
||
bne .3
|
||
|
||
ldx #0
|
||
|
||
.2 iny
|
||
lda (ZPSymbolBuf),y
|
||
sta SRC.ACC,x
|
||
inx
|
||
cpx #4
|
||
|
||
bne .2
|
||
|
||
lda #2
|
||
sta SRC.ACC.SIZE
|
||
clc
|
||
rts
|
||
|
||
.3 dey
|
||
.4 tya
|
||
clc
|
||
adc #SYML
|
||
tay
|
||
bra .1
|
||
|
||
.9 lda #E.UNDEF.SYMBOL
|
||
sec
|
||
rts
|
||
*---------------------------------------
|
||
SYM.Dump.End >PUSHW L.MSG.SUMMARY
|
||
>PUSHW ZPPtr2
|
||
>PUSHBI 2
|
||
jmp OUT.Print
|
||
|
||
SYM.Dump.8 clc
|
||
rts
|
||
*---------------------------------------
|
||
SYM.Dump >LDA.G bListAll
|
||
bmi .10
|
||
|
||
>LDA.G ASM.LI.ON
|
||
bpl SYM.Dump.8
|
||
|
||
.10 >LDYA L.MSG.SYMBOLS
|
||
>SYSCALL puts
|
||
|
||
stz ZPPtr2
|
||
stz ZPPtr2+1
|
||
|
||
.1 >LDYA ZPPtr2
|
||
>STYA ZPPtr1
|
||
|
||
>PUSHB.G SYM.hList
|
||
>PUSHW ZPPtr1
|
||
>PUSHW ZPTmpBuf
|
||
>SYSCALL SListGetByID
|
||
bcs SYM.Dump.End
|
||
|
||
>STYA ZPPtr2 Save Next ID
|
||
|
||
>PUSHB.G SYM.hList
|
||
>PUSHW ZPPtr1 KeyID
|
||
>PUSHW ZPSymbolBuf
|
||
>PUSHWI $ffff All
|
||
>PUSHWZ from Start
|
||
>SYSCALL SListGetData
|
||
bcs .9
|
||
|
||
ldy #SYMG.SIZE Get Symbol Size
|
||
lda (ZPSymbolBuf),y
|
||
|
||
pha
|
||
|
||
asl
|
||
tax
|
||
>PUSHB L.MSG.EQU0+1,x
|
||
>PUSHB L.MSG.EQU0,x
|
||
|
||
pla
|
||
pha
|
||
tax byte count
|
||
|
||
clc
|
||
adc #SYMG.V
|
||
|
||
tay
|
||
|
||
.2 dey
|
||
lda (ZPSymbolBuf),y
|
||
>PUSHA
|
||
dex
|
||
bne .2
|
||
|
||
pla Byte Count
|
||
|
||
.3 >PUSHA
|
||
|
||
>SYSCALL printf
|
||
|
||
>PUSHW ZPTmpBuf Label
|
||
>PUSHBI 0
|
||
>SYSCALL printf
|
||
|
||
lda (ZPSymbolBuf)
|
||
|
||
bit #SYMG.F.LOCALS
|
||
beq .7
|
||
|
||
jsr SYM.Dump.LP
|
||
.7 jsr OUT.PrintCR
|
||
jmp .1
|
||
.9 rts
|
||
*---------------------------------------
|
||
SYM.Dump.LP ldy #SYMG
|
||
|
||
.1 lda (ZPSymbolBuf),y
|
||
beq .8
|
||
|
||
phy
|
||
|
||
tax ID
|
||
|
||
iny
|
||
lda (ZPSymbolBuf),y MacID
|
||
bne .3
|
||
|
||
>PUSHW L.MSG.LSYMBOL
|
||
txa
|
||
>PUSHA
|
||
|
||
jsr SYM.Dump.PushValueY
|
||
|
||
lda #5
|
||
bra .5
|
||
|
||
.3 >PUSHW L.MSG.PSYMBOL
|
||
txa
|
||
>PUSHA
|
||
|
||
>PUSHB (ZPSymbolBuf),y
|
||
|
||
jsr SYM.Dump.PushValueY
|
||
|
||
lda #6
|
||
|
||
.5 >PUSHA
|
||
|
||
>SYSCALL printf
|
||
|
||
pla
|
||
clc
|
||
adc #SYML
|
||
tay
|
||
|
||
bra .1
|
||
|
||
.8 rts
|
||
*---------------------------------------
|
||
SYM.Dump.PushValueY
|
||
ldx #4
|
||
|
||
iny
|
||
iny
|
||
iny
|
||
iny
|
||
|
||
.1 lda (ZPSymbolBuf),y
|
||
>PUSHA
|
||
dey
|
||
dex
|
||
bne .1
|
||
|
||
rts
|
||
*---------------------------------------
|
||
MAN
|
||
SAVE USR/SRC/BIN/ASM.S.SYM
|
||
LOAD USR/SRC/BIN/ASM.S
|
||
ASM
|