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
rts
*---------------------------------------
FIO.ReadLine stz SRC.Label.Flags
stz SRC.BufPtr
FIO.ReadLine stz SRC.BufPtr
ldy #SRC.COUNT
lda (pData),y

View File

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

View File

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

View File

@ -21,10 +21,13 @@ ASM.T.AM .EQ 0
ASM.T.R .EQ 2
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.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.SRC.INV.TYPE .EQ $90
@ -178,8 +181,7 @@ CS.INIT >LDYA L.LIBSTR
ldy #ASM.LI.ON
sta (pData),y
* lda #$00
lda #$80
lda #$00
ldy #ASM.LI.CON
sta (pData),y
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.SRCLINE >CSTRING "%05D-%s\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.EXP.RESERVED >PSTRING "^!|&<=>+-*/"
ASM.T.DEFAULT .AS ".T.6502"
@ -442,9 +444,6 @@ ASM.T.FILENAME .BS 65
hLIBSTR .BS 1
hFileName .BS 1
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.Keyword.ID .BS 1
SRC.ACC .BS 4
@ -456,6 +455,11 @@ SRC.Exp .BS 128
SRC.BufPtr .BS 1
SRC.BufPtrSave .BS 1
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
.OR 0
@ -477,9 +481,21 @@ DST.hFILETYPE .BS 1
ASM.T.hMem .BS 1 handle to ASM.T.xxxxx
SYM.Count .BS 2
SYM.hMem .BS 1
SYM.hBlocks .BS SYM.BLOCK.MAX
SYM.LastGBlock .BS 1
SYM.hGBlocks .BS SYM.GBLOCK.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.MACRO.ON .BS 1
@ -489,7 +505,9 @@ ASM.LI.CON .BS 1
ASM.LI.XON .BS 1
ASM.PC .BS 4 32Bits PC
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
*---------------------------------------
MAN