Work In Progress (ASM)

This commit is contained in:
Rémy GIBERT 2015-11-13 17:25:31 +01:00
parent 36027b8d75
commit 7fa3545a19
4 changed files with 157 additions and 76 deletions

View File

@ -107,8 +107,7 @@ FIO.OpenFileA sta hFileName
.99 sec .99 sec
rts rts
*--------------------------------------- *---------------------------------------
FIO.ReadLine stz SRC.Label.Flags FIO.ReadLine stz SRC.BufPtr
stz SRC.BufPtr
ldy #SRC.COUNT ldy #SRC.COUNT
lda (pData),y lda (pData),y

View File

@ -46,11 +46,11 @@ SRC.ParseLine ldx TmpBuffer256
bcs SRC.ParseLine.Err bcs SRC.ParseLine.Err
SRC.ParseLine.Ok lda SRC.Label.Flags SRC.ParseLine.Ok lda SRC.GLabel.Len
beq .1 beq .1
jsr SYM.Add * jsr SYM.AddToGBlock
bcs SRC.ParseLine.Err * bcs SRC.ParseLine.Err
.1 .1
SRC.ParseLine.skip clc SRC.ParseLine.skip clc
rts rts
@ -71,16 +71,13 @@ SRC.ParseLine.SymL jsr SRC.GetChar
bcs SRC.ParseLine.SymR bcs SRC.ParseLine.SymR
jmp SYM.AddLocal jmp SYM.AddLocal
*--------------------------------------- *---------------------------------------
SRC.ParseLine.SymG jsr SYM.ClearLocal SRC.ParseLine.SymG jsr SRC.GetGLabel
jsr SRC.GetLabel
bcs SRC.ParseLine.SymE bcs SRC.ParseLine.SymE
inc SRC.Label.Flags Remember to Add Label
ldx #3 Makes Current Label = PC for now ldx #3 Makes Current Label = PC for now
ldy #ASM.PC ldy #ASM.PC
lda (pdata),y lda (pdata),y
.1 sta SRC.LabelValue,x .1 sta SRC.GLabel.Value,x
dey dey
dex dex
bpl .1 bpl .1
@ -191,11 +188,12 @@ SRC.ParseLine.AM stz SRC.AM.ID
ldx SRC.AM.StrBuf ldx SRC.AM.StrBuf
sta SRC.AM.StrBuf,x sta SRC.AM.StrBuf,x
bra .1 bra .1
.8 lda SRC.AM.StrBuf .8 lda SRC.AM.StrBuf
beq .89 beq .89
>PUSHWI TmpBuffer256
>PUSHW L.SRC.AM.StrBuf >PUSHW L.SRC.AM.StrBuf
>PUSHB SRC.AM.StrBuf
>PUSHW L.MSG.DEBUG >PUSHW L.MSG.DEBUG
>LIBCALL hLIBSTR,LIBSTR.PRINTF >LIBCALL hLIBSTR,LIBSTR.PRINTF
.89 clc .89 clc
@ -225,6 +223,7 @@ SRC.ParseLine.AM stz SRC.AM.ID
beq .71 last register ? beq .71 last register ?
ldx #$ff ldx #$ff
phy
.6 lda (ZPPtr3),y .6 lda (ZPPtr3),y
iny iny
@ -235,6 +234,8 @@ SRC.ParseLine.AM stz SRC.AM.ID
cpx SRC.AM.tmpBuf cpx SRC.AM.tmpBuf
bne .6 bne .6
ply
ldy #0 register match, add to AM string ldy #0 register match, add to AM string
ldx SRC.AM.StrBuf ldx SRC.AM.StrBuf
@ -247,7 +248,11 @@ SRC.ParseLine.AM stz SRC.AM.ID
stx SRC.AM.StrBuf stx SRC.AM.StrBuf
bra .72 bra .72
.7 iny .7 ply
tya
sec
adc (ZPPtr3),y
tay
bra .5 bra .5
.70 dec SRC.BufPtr back one char .70 dec SRC.BufPtr back one char
@ -462,12 +467,12 @@ SRC.GetBinary stz SRC.ACC+1
sec sec
rts rts
*--------------------------------------- *---------------------------------------
SRC.GetLabel jsr SRC.GetCharUC SRC.GetGLabel jsr SRC.GetCharUC
beq .9 beq .9
jsr SRC.IsLetter jsr SRC.IsLetter
bcs .9 bcs .9
sta SRC.Label sta SRC.GLabel.Name
ldy #1 ldy #1
@ -482,16 +487,17 @@ SRC.GetLabel jsr SRC.GetCharUC
jsr SRC.IsLetterOrDigit jsr SRC.IsLetterOrDigit
bcs .9 bcs .9
.2 sta SRC.Label,y
.2 sta SRC.GLabel.Name,y
iny iny
cpy #SRC.LABEL.MAXLEN cpy #SRC.GLABEL.MAXLEN
bne .1 if equ Carry is set bne .1 if equ Carry is set
.9 sec .9 sec
rts rts
.8 lda #0 .8 tya
sta SRC.Label,y sta SRC.GLabel.Len
clc clc
rts rts
*--------------------------------------- *---------------------------------------
@ -613,12 +619,12 @@ SRC.IsLetterOrDigit jsr SRC.IsDigit10
*--------------------------------------- *---------------------------------------
SRC.IsLetter cmp #'A' SRC.IsLetter cmp #'A'
bcc .9 bcc .9
cmp #'[' cmp #'Z'+1
bcc SRC.IsLetterRTS bcc SRC.IsLetterRTS
cmp #'a' cmp #'a'
bcc .9 bcc .9
cmp #'{' cmp #'z'+1
rts CC if lowercase rts CC if lowercase
.9 sec .9 sec

View File

@ -5,46 +5,55 @@ INC 1
AUTO 6 AUTO 6
.LIST OFF .LIST OFF
*--------------------------------------- *---------------------------------------
* Global Symbol Record: (7 bytes) * Global Symbol Record: (8+ bytes)
* 0 : SYM.Block.ID * 0-3 : 32 bits Value
* 1 : Index in SYM.Block * 4 : Flags:
* 2 : Flags:
* b7=R/W (.SE) * b7=R/W (.SE)
* b6=Forward ref * b6=pending
* 3-6 : Value * 5 : Len
*--------------------------------------- * 6-... Name
* Local Symbol Record: (4 bytes) * ......
* 0,1 : Pointer to Global Symbol in main table * Local Symbol Record: (2 bytes)
* 2 : 2 digits name (.99) * 2 : Local ID (0->255)
* 3 : offset from Global Symbol * 3 : offset from Global Symbol
* ......
* Ending 0
*---------------------------------------
* Global Symbol Index (Sorted)
* 0 : hGblock
* 1 : Offset in block
*--------------------------------------- *---------------------------------------
* Private Symbol Record: (7 bytes) * Private Symbol Record: (7 bytes)
* 0,1 : MacroID * 0,1 : MacroID
* 2 : 2 digits name (:99) * 2 : Private ID (0->255)
* 3-6 : Value * 3-6 : Value
*--------------------------------------- *---------------------------------------
SYM.Init >PUSHWI SYM.MAXCOUNT*8 * Macro Record: ( bytes)
>PUSHBI S.MEM.F.INIT0 *---------------------------------------
>SYSCALL SYS.GetMem SYM.Init jsr SYM.NewGBlock
bcs .9 bcs .9
ldy #SYM.hMem
txa
sta (pData),y
clc clc
.9 rts .9 rts
*--------------------------------------- *---------------------------------------
SYM.Quit ldy #SYM.hMem SYM.Quit ldy #SYM.LastGBlock
lda (pData),y
bmi .8
.1 clc
adc #SYM.hGBlocks
tay
lda (pData),y lda (pData),y
beq .8
>SYSCALL SYS.FreeMemA >SYSCALL SYS.FreeMemA
ldy #SYM.LastGBlock
lda (pData),y
dec
sta (pData),y
bpl .1
.8 clc .8 clc
rts rts
*--------------------------------------- *---------------------------------------
SYM.Add
clc
rts
*---------------------------------------
SYM.AddGlobal SYM.AddGlobal
clc clc
rts rts
@ -53,14 +62,6 @@ SYM.LookupGlobal
clc clc
rts rts
*--------------------------------------- *---------------------------------------
SYM.ClearPrivate
clc
rts
*---------------------------------------
SYM.ClearLocal
clc
rts
*---------------------------------------
SYM.AddLocal SYM.AddLocal
clc clc
rts rts
@ -77,23 +78,80 @@ SYM.LookupPrivate
clc clc
rts rts
*--------------------------------------- *---------------------------------------
SYM.AddBlock ldx #0 SYM.AddMacro
.1 lda SYM.BLOCKS,x clc
beq .2
inx
cpx #SYM.BLOCK.MAX
bne .1
lda #ERR.SYM.TOO.LONG
sec Out of block error
rts rts
*---------------------------------------
SYM.LookupMacro
clc
rts
*---------------------------------------
SYM.AddToGBlock ldy #SYM.GBlockPtr
lda (pData),y
clc
adc #6 Value+Flags+Len
bcs .1
adc SRC.GLabel.Len
bcs .1
ldy #SYM.LastGBlock
lda (pData),y
>SYSCALL SYS.GetMemPtrA
>STYA ZPPtr1
bra .2
.2 phx Save next free block .1 jsr SYM.NewGBlock
>LDYA SYM.BLOCK.SIZE bcs .9
>STYA ZPPtr1
.2 ldx #0
ldy #SYM.GBlockPtr
.3 lda SRC.GLabel.Value,x
sta (ZPPtr1),y
inx
iny
cpx #6
bne .3
ldx #0
.4 lda SRC.GLabel.Name,x
sta (ZPPtr1),y
inx
iny
cpx SRC.GLabel.Len
bne .4
tya
ldy #SYM.GBlockPtr
sta (pData),y set new SYM.GBlockPtr
clc
.9
rts
*---------------------------------------
SYM.NewGBlock >PUSHWI 256
>PUSHBI S.MEM.F.INIT0
>SYSCALL SYS.GetMem >SYSCALL SYS.GetMem
bcs .9 bcs .9
>STYA ZPPtr1
ldy #SYM.LastGBlock
lda (pData),y
inc
sta (pData),y
ldy #SYM.hGBlocks
clc
adc (pData),y
tay
txa txa
plx sta (pData),y
sta SYM.BLOCKS,x
lda #0
ldy #SYM.GBlockPtr
sta (pData),y
clc clc
.9 rts .9 rts
*--------------------------------------- *---------------------------------------

View File

@ -21,10 +21,13 @@ ASM.T.AM .EQ 0
ASM.T.R .EQ 2 ASM.T.R .EQ 2
ASM.T.O .EQ 4 ASM.T.O .EQ 4
*--------------------------------------- *---------------------------------------
SYM.BLOCK.MAX .EQ 128 128*256 = 32k max of symbols
SYM.MAXCOUNT .EQ 1024
SRC.IN.MAXDEPTH .EQ 7 SRC.IN.MAXDEPTH .EQ 7
SRC.LABEL.MAXLEN .EQ 32 SRC.GLABEL.MAXLEN .EQ 32
*---------------------------------------
SYM.GBLOCK.MAX .EQ 64 64*256=16k
SYM.SBLOCK.MAX .EQ 16 16*256=4k
SYM.PBLOCK.MAX .EQ 32 32*256=8k
SYM.MBLOCK.MAX .EQ 32 32*256=8k
*--------------------------------------- *---------------------------------------
ERR.INV.ARGS .EQ $80 ERR.INV.ARGS .EQ $80
ERR.SRC.INV.TYPE .EQ $90 ERR.SRC.INV.TYPE .EQ $90
@ -178,8 +181,7 @@ CS.INIT >LDYA L.LIBSTR
ldy #ASM.LI.ON ldy #ASM.LI.ON
sta (pData),y sta (pData),y
* lda #$00 lda #$00
lda #$80
ldy #ASM.LI.CON ldy #ASM.LI.CON
sta (pData),y sta (pData),y
ldy #ASM.LI.XON ldy #ASM.LI.XON
@ -433,7 +435,7 @@ MSG.OBJ.FILE >CSTRING "Object File:%S, Type=%02x\n"
MSG.T.FILE >CSTRING "CPU Definition File:%S\n" MSG.T.FILE >CSTRING "CPU Definition File:%S\n"
MSG.SRCLINE >CSTRING "%05D-%s\n" MSG.SRCLINE >CSTRING "%05D-%s\n"
MSG.ERROR >CSTRING "%05D-Error:$%h\n" MSG.ERROR >CSTRING "%05D-Error:$%h\n"
MSG.DEBUG >CSTRING "DEBUG:%S\n" MSG.DEBUG >CSTRING "DEBUG:%h:%S:%s\n"
SRC.AM.RESERVED >PSTRING "[]#()," SRC.AM.RESERVED >PSTRING "[]#(),"
SRC.EXP.RESERVED >PSTRING "^!|&<=>+-*/" SRC.EXP.RESERVED >PSTRING "^!|&<=>+-*/"
ASM.T.DEFAULT .AS ".T.6502" ASM.T.DEFAULT .AS ".T.6502"
@ -442,9 +444,6 @@ ASM.T.FILENAME .BS 65
hLIBSTR .BS 1 hLIBSTR .BS 1
hFileName .BS 1 hFileName .BS 1
SRC.LINENUM .BS 2 SRC.LINENUM .BS 2
SRC.Label.Flags .BS 1
SRC.Label .BS SRC.LABEL.MAXLEN
SRC.LabelValue .BS 4
SRC.Directive.ID .BS 1 SRC.Directive.ID .BS 1
SRC.Keyword.ID .BS 1 SRC.Keyword.ID .BS 1
SRC.ACC .BS 4 SRC.ACC .BS 4
@ -456,6 +455,11 @@ SRC.Exp .BS 128
SRC.BufPtr .BS 1 SRC.BufPtr .BS 1
SRC.BufPtrSave .BS 1 SRC.BufPtrSave .BS 1
SRC.Buffer .BS 256 SRC.Buffer .BS 256
*--------------------------------------
SRC.GLabel.Value .BS 4
SRC.GLabel.Flags .BS 1
SRC.GLabel.Len .BS 1
SRC.GLabel.Name .BS SRC.GLABEL.MAXLEN
*-------------------------------------- *--------------------------------------
.DUMMY .DUMMY
.OR 0 .OR 0
@ -477,9 +481,21 @@ DST.hFILETYPE .BS 1
ASM.T.hMem .BS 1 handle to ASM.T.xxxxx ASM.T.hMem .BS 1 handle to ASM.T.xxxxx
SYM.Count .BS 2 SYM.LastGBlock .BS 1
SYM.hMem .BS 1 SYM.hGBlocks .BS SYM.GBLOCK.MAX
SYM.hBlocks .BS SYM.BLOCK.MAX SYM.GBlockPtr .BS 1
SYM.LastSBlock .BS 1
SYM.hSBlocks .BS SYM.SBLOCK.MAX
SYM.SBlockPtr .BS 1
SYM.LastPBlock .BS 1
SYM.hPBlocks .BS SYM.PBLOCK.MAX
SYM.PrivateBlockPtr .BS 1
SYM.LastMBlock .BS 1
SYM.hMBlocks .BS SYM.MBLOCK.MAX
SYM.MBlockPtr .BS 1
ASM.PASS .BS 1 ASM.PASS .BS 1
ASM.MACRO.ON .BS 1 ASM.MACRO.ON .BS 1
@ -489,7 +505,9 @@ ASM.LI.CON .BS 1
ASM.LI.XON .BS 1 ASM.LI.XON .BS 1
ASM.PC .BS 4 32Bits PC ASM.PC .BS 4 32Bits PC
ASM.PC.PH .BS 4 32Bits PC saved for PH directive ASM.PC.PH .BS 4 32Bits PC saved for PH directive
ASM.LOCAL.OFFSET .BS 1 Store local offset from last Global Symbol for local (.xx)
ASM.LOCAL.INVALID .BS 1 If not in global or offset out of range this flag is set
ASM.SYM.ID .BS 2 For reference when a local label is parsed
DS.END .ED DS.END .ED
*--------------------------------------- *---------------------------------------
MAN MAN