Work In Progress (ASM)

This commit is contained in:
Rémy GIBERT 2015-12-17 17:57:35 +01:00
parent adc8ad9630
commit 27c265a290
4 changed files with 212 additions and 137 deletions

View File

@ -14,22 +14,33 @@ AUTO 6
* * = PC
*---------------------------------------
EXP.Eval stz EXP.Operator
EXP.Eval.Next jsr SRC.GetCharNB
bne .13
lda #ERR.MISSING.EXP
stz EXP.Modifier
jsr SRC.GetCharNB
beq EXP.Eval.Missing
jsr SRC.IsMODReserved
bcs EXP.Eval.Next1
stx EXP.Modifier
bra EXP.Eval.Next
EXP.Eval.Missing lda #ERR.MISSING.EXP
sec
.14 rts
rts
.13 cmp #'.' Local Label?
EXP.Eval.Next jsr SRC.GetCharUC
beq EXP.Eval.Missing
EXP.Eval.Next1 cmp #'.' Local Label?
bne .12
jsr EXP.GetLocal
bcs .14
jmp EXP.EvalOperator
.14 rts
.12 cmp #'*'
bne .10
@ -42,8 +53,8 @@ EXP.Eval.Next jsr SRC.GetCharNB
dey
dex
bpl .11
bra EXP.EvalOperator
jmp EXP.EvalOperator
.10 jsr SRC.IsDigit10 Decimal constant ?
bcs .1
@ -132,7 +143,7 @@ EXP.EvalOperator lda EXP.Operator
beq EXP.EvalExitOK1
cmp #' '
beq EXP.EvalExitOK1
beq EXP.EvalExitOK
jsr SRC.IsAMReserved
bcc EXP.EvalExitOK
@ -149,9 +160,6 @@ EXP.EvalOperator lda EXP.Operator
bpl .8
jmp EXP.Eval.Next
clc
rts
*---------------------------------------
EXP.GetLocal jsr SRC.GetDecimal
bcs EXP.EvalExitSYN
@ -200,7 +208,12 @@ EXP.GetSymbol >LDYA L.SRC.ELabel.Len
EXP.Compute dec
asl
tax
* ldy #ASM.PASS
* lda (pData),y pass#2?
* beq .8
jmp (J.EXP.OP,x)
.8 clc
rts
*---------------------------------------
EXP.Compute.EOR
*---------------------------------------

View File

@ -5,6 +5,66 @@ INC 1
AUTO 6
.LIST OFF
*---------------------------------------
SRC.PrintLine ldy #ASM.MACRO.ON
lda (pData),y
bpl .1
ldy #ASM.LI.CON
lda (pData),y
bpl .9
bmi .8
.1 ldy #ASM.LI.ON
lda (pData),y
bpl .9
.8 >PUSHWI TmpBuffer256
>PUSHW SRC.LINENUM
ldy #ASM.PC+1
>PUSHB (pData),y
dey
>PUSHB (pData),y
>PUSHW L.MSG.SRCLINE
>LIBCALL hLIBSTR,LIBSTR.PRINTF
.9 rts
*---------------------------------------
SRC.PrintLineErr ldx #0
.1 lda TmpBuffer256,x
beq .2
phx
>SYSCALL SYS.CoutA
plx
inx
bcc .1
rts
.2 lda #13
>SYSCALL SYS.CoutA
bcs .9
ldx #0
.3 lda TmpBuffer256,x
beq .5
inx
cpx SRC.BufPtr
beq .4
phx
lda #'-'
>SYSCALL SYS.CoutA
plx
bcs .9
bra .3
.4 lda #'^'
phx
>SYSCALL SYS.CoutA
plx
bcs .9
.5 lda #13
>SYSCALL SYS.CoutA
.9 rts
*---------------------------------------
SRC.ParseLine ldx TmpBuffer256
beq .1
@ -59,40 +119,37 @@ SRC.ParseLine ldx TmpBuffer256
SRC.ParseLine.Ok lda SRC.GLabel.New
bpl .8
ldy #ASM.PASS
lda (pData),y pass#2?
bne .8 yes, nothing to do
* --- Pass #1
>LDYA L.SRC.GLabel.Flags
jsr SYM.SearchGlobal
bcs .1 if CS, not found, add
lda SRC.FLabel.Flags
and SRC.GLabel.Flags
lsr both are .SE ?
bcs .1 yes, update during pass 1 & 2
lda SRC.FLabel.Flags
bit #$40 found symbol pending ?
bne .2 yes, update
bit #$1 found is .SE ?
beq SRC.ParseLine.Redef no, redefine error
lda SRC.FLabel.Flags
and #$40 found symbol pending ?
bne .10
lda SRC.GLabel.Flags
and #$40 new is pending ? (if yes, no need to update)
bne .8
.10 ldy #ASM.PASS
lda (pData),y pass#2?
beq .1 yes, skip to avoid redefinition error
lda SRC.FLabel.Flags
and #$40
beq SRC.ParseLine.Redef
.2 ldx #0 update current symbol with
.3 lda SRC.GLabel.Flags flags & value
jsr SYM.AddByteGBlock
inx
cpx #5
bne .3
bra .8
.1 >LDYA L.SRC.GLabel.Flags
jsr SYM.AddGToGBlockYA
bcs SRC.ParseLine.Err
.8 clc
rts
SRC.ParseLine.Err1 lda #ERR.INVALID.LABEL
SRC.ParseLine.Inv lda #ERR.INVALID.LABEL
SRC.ParseLine.Err sec
rts
@ -202,9 +259,10 @@ SRC.ParseLine.Add.Macro
*---------------------------------------
SRC.ParseLine.OpCode
jsr SRC.GetArg
bcs .9
bcc .11
rts
ldy #ASM.T.hMem
.11 ldy #ASM.T.hMem
lda (pData),y
>SYSCALL SYS.GetMemPtrA
>STYA ZPPtr1
@ -252,7 +310,7 @@ SRC.ParseLine.OpCode
bcs *
@ -261,8 +319,22 @@ SRC.ParseLine.OpCode
bcs .99
bcc .20
ldx SRC.AM.StrBuf
beq .20
ldx #0
.21 inx
lda SRC.AM.StrBuf,x
phx
>SYSCALL SYS.CoutA
plx
cpx SRC.AM.StrBuf
bne .21
lda #13
>SYSCALL SYS.CoutA
ldy #ASM.PC
.20 ldy #ASM.PC
lda (pData),y
inc
sta (pData),y
@ -310,11 +382,19 @@ SRC.ParseLine.AM stz SRC.AM.ID
.8 clc
rts
.2 jsr SRC.IsLetter Any register?
.2 jsr SRC.IsMODReserved
bcs .21
lda #'#'
inc SRC.AM.StrBuf
ldx SRC.AM.StrBuf
sta SRC.AM.StrBuf,x
bra .1
.21 jsr SRC.IsLetter Any register?
bcs .70 no, try something else
lda SRC.BufPtr
sta SRC.BufPtrSave
ldx SRC.BufPtr
stx SRC.BufPtrSave
stz SRC.AM.tmpBuf
sta SRC.AM.tmpBuf+1
@ -323,7 +403,7 @@ SRC.ParseLine.AM stz SRC.AM.ID
.3 jsr SRC.GetCharUC
beq .41
jsr SRC.IsLetterOrDigit
bne .4
bcs .4
inc SRC.AM.tmpBuf
ldx SRC.AM.tmpBuf
sta SRC.AM.tmpBuf,x
@ -336,8 +416,8 @@ SRC.ParseLine.AM stz SRC.AM.ID
.5 lda (ZPPtr3),y
beq .71 last register ?
ldx #$ff
phy
ldx #$ff
.6 lda (ZPPtr3),y
iny
@ -361,7 +441,7 @@ SRC.ParseLine.AM stz SRC.AM.ID
bne .61
stx SRC.AM.StrBuf
bra .72
jmp .1
.7 ply
tya
@ -376,9 +456,23 @@ SRC.ParseLine.AM stz SRC.AM.ID
.70 dec SRC.BufPtr back one char
jsr EXP.Eval
bcs *
bcs .99
.72 jmp .1
ldx #3
.73 lda SRC.ACC,x
bne .72
dex
bne .73
.72 inx
txa
ora #$30
inc SRC.AM.StrBuf
ldx SRC.AM.StrBuf
sta SRC.AM.StrBuf,x
jmp .1
clc
rts
@ -388,31 +482,6 @@ SRC.ParseLine.AM stz SRC.AM.ID
sec
.99 rts
*---------------------------------------
SRC.PrintLine bcs .8 if CS, unconditional
ldy #ASM.MACRO.ON
lda (pData),y
bpl .1
ldy #ASM.LI.CON
lda (pData),y
bpl .9
bmi .8
.1 ldy #ASM.LI.ON
lda (pData),y
bpl .9
.8 >PUSHWI TmpBuffer256
>PUSHW SRC.LINENUM
ldy #ASM.PC+1
>PUSHB (pData),y
dey
>PUSHB (pData),y
>PUSHW L.MSG.SRCLINE
>LIBCALL hLIBSTR,LIBSTR.PRINTF
.9 rts
*---------------------------------------
SRC.GetDecimal stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
@ -427,7 +496,7 @@ SRC.GetDecimal stz SRC.ACC+1
.1 jsr SRC.GetChar
beq .8
cmp #' '
beq .8
beq .88
jsr SRC.IsEXPReserved
bcc .88
jsr SRC.IsAMReserved
@ -478,7 +547,7 @@ SRC.GetHex stz SRC.ACC+1
.1 jsr SRC.GetChar
beq .8
cmp #' '
beq .8
beq .88
jsr SRC.IsEXPReserved
bcc .88
jsr SRC.IsAMReserved
@ -524,7 +593,7 @@ SRC.GetOctal stz SRC.ACC+1
.1 jsr SRC.GetChar
beq .8
cmp #' '
beq .8
beq .88
jsr SRC.IsEXPReserved
bcc .88
jsr SRC.IsAMReserved
@ -577,7 +646,7 @@ SRC.GetBinary stz SRC.ACC+1
.1 jsr SRC.GetChar
beq .8
cmp #' '
beq .8
beq .88
jsr SRC.IsEXPReserved
bcc .88
jsr SRC.IsAMReserved
@ -609,9 +678,10 @@ SRC.GetBinary stz SRC.ACC+1
rts
*---------------------------------------
SRC.GetLabel >STYA ZPPtr1
jsr SRC.GetCharUC
beq .9
jsr SRC.IsLetter
bcs .9
@ -621,31 +691,29 @@ SRC.GetLabel >STYA ZPPtr1
.1 jsr SRC.GetCharUC
beq .8
cmp #' '
beq .8
jsr SRC.IsLetterOrDigit
bcc .2
cmp #'.'
beq .2
cmp #'_'
beq .2
cmp #' '
beq .88
jsr SRC.IsEXPReserved
bcc .88
jsr SRC.IsAMReserved
bcc .88
jsr SRC.IsLetterOrDigit
bcs *
* bcs .9
.9 lda #ERR.SYNTAX.ERROR
sec
rts
.2 iny
sta (ZPPtr1),y
cpy #SRC.GLABEL.MAXLEN
bcc .1 if equ Carry is set
.9 lda #ERR.SYNTAX.ERROR
sec
rts
.88 dec SRC.BufPtr Back One Char
.8 tya
@ -727,6 +795,16 @@ SRC.IsAMReserved ldx SRC.AM.RESERVED
.8 clc
rts
*---------------------------------------
SRC.IsMODReserved ldx SRC.MOD.RESERVED
.1 cmp SRC.MOD.RESERVED,x
beq .8
dex
bne .1
sec
rts
.8 clc
rts
*---------------------------------------
SRC.IsEXPReserved ldx SRC.EXP.RESERVED
.1 cmp SRC.EXP.RESERVED,x
beq .8
@ -804,7 +882,6 @@ SRC.GetChar ldx SRC.BufPtr
lda TmpBuffer256,x
beq .9
inc SRC.BufPtr if 255, will make Z
and #$7f Make sure NZ
.9 rts
*---------------------------------------
SRC.ACC10 lda SRC.ACC ACC*2-> ACC & ACCTMP

View File

@ -133,33 +133,6 @@ SYM.Dump >PUSHW L.MSG.SYMBOLS
jmp .1
.9 rts
*---------------------------------------
SYM.DumpGSymbol.DELETE >SYSCALL SYS.CoutA
lda ZPSymbolPtr
clc
adc #5
tay
lda ZPSymbolPtr+1
adc #0
>PUSHYA
ldy #2
lda (ZPSymbolPtr),y
>PUSHA
dey
lda (ZPSymbolPtr),y
>PUSHA
ldy #4
lda (ZPSymbolPtr),y
>PUSHA
dey
lda (ZPSymbolPtr),y
>PUSHA
>PUSHW L.MSG.GSYMBOL
>LIBCALL hLIBSTR,LIBSTR.PRINTF
rts
*---------------------------------------
SYM.AddPrivate
clc
rts
@ -188,7 +161,14 @@ SYM.SearchGlobal >STYA ZPSymbolPtr
jsr SYM.ResetGBlockPtr
.1 jsr SYM.GetByteGBlock Get Flags
.1 ldy #SYM.iCurGBlock
lda (pData),y
sta SYM.iCurGBlock.Save
ldy #SYM.pCurGBlock
lda (pData),y
sta SYM.pCurGBlock.Save
jsr SYM.GetByteGBlock Get Flags
beq .9
sta SRC.FLabel.Flags
@ -221,8 +201,14 @@ SYM.SearchGlobal >STYA ZPSymbolPtr
cpx SRC.FLabel.Len
bne .4
clc
rts
lda SYM.pCurGBlock.Save
ldy #SYM.pCurGBlock
sta (pData),y
lda SYM.iCurGBlock.Save
ldy #SYM.iCurGBlock
sta (pData),y
jmp SYM.GetGBlockA
.5 jsr SYM.GetByteGBlock skip Locals
beq .1
@ -280,16 +266,6 @@ SYM.AddLToGBlock jsr SYM.SetGBlockPtr
jmp SYM.AddByteGBlock
.9 rts
*---------------------------------------
SYM.ResetGBlockPtr lda #0
jsr SYM.GetGBlockA
lda #0
ldy #SYM.pCurGBlock
sta (pData),y
ldy #SYM.iCurGBlock
sta (pData),y
rts
*---------------------------------------
SYM.GetByteGBlock ldy #SYM.iCurGBlock
lda (pData),y
tay
@ -312,6 +288,13 @@ SYM.GetByteGBlock ldy #SYM.iCurGBlock
clc
rts
*---------------------------------------
SYM.ResetGBlockPtr lda #0
ldy #SYM.pCurGBlock
sta (pData),y
ldy #SYM.iCurGBlock
sta (pData),y
bra SYM.GetGBlockA
*---------------------------------------
SYM.SetGBlockPtr ldy #SYM.pLastGBlock
lda (pData),y

View File

@ -241,7 +241,7 @@ CS.RUN ldy #bCANCEL
.99 sec
rts
.2 jsr SRC.PrintLine with CC, conditional
.2 jsr SRC.PrintLine
jsr SRC.ParseLine
bcs .9
@ -250,8 +250,7 @@ CS.RUN ldy #bCANCEL
rts
.9 pha
sec
jsr SRC.PrintLine with CS, print always
jsr SRC.PrintLineErr
pla
pha
>PUSHA
@ -435,7 +434,7 @@ MSG.SYMBOLS >CSTRING "Symbol Table:\n"
MSG.GSYMBOL >CSTRING "$%H%H:%S"
MSG.LSYMBOL >CSTRING " .%d:+$%h"
MSG.SUMMARY >CSTRING "\nEnd Of Assembly.\n"
SRC.AM.RESERVED >PSTRING "[]#(),"
SRC.AM.RESERVED >PSTRING "[](),"
SRC.MOD.RESERVED >PSTRING "#/<>"
SRC.EXP.RESERVED >PSTRING "^!|&<=>+-*/"
ASM.T.DEFAULT .AS ".T.6502"
@ -447,6 +446,10 @@ FIO.hFileName .BS 1
FIO.hFullPath .BS 1
EXP.Operator .BS 1
EXP.Modifier .BS 1
SYM.iCurGBlock.Save .BS 1
SYM.pCurGBlock.Save .BS 1
SRC.LINENUM .BS 2
SRC.Directive.ID .BS 1
@ -461,7 +464,6 @@ SRC.Exp .BS 128
SRC.BufPtr .BS 1
SRC.BufPtrSave .BS 1
SRC.Buffer .BS 256
*--------------------------------------
SRC.GLabel.New .BS 1
SRC.GLabel.Flags .BS 1
SRC.GLabel.Value .BS 4
@ -536,9 +538,9 @@ ASM.LI.XON .BS 1
ASM.PC .BS 4
ASM.PC.PH .BS 4
ASM.PC.GLABEL .BS 4
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
ASM.LOCAL.OFFSET .BS 1
ASM.LOCAL.INVALID .BS 1
ASM.SYM.ID .BS 2
DS.END .ED
*---------------------------------------
.DO DS.END-DS.START>$FF