A2osX/BIN/ASM.S.SRC.txt
2018-01-19 16:21:31 +00:00

857 lines
15 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
*---------------------------------------
SRC.PrintLine bra .8
>LDA.G ASM.MACRO.ON
bpl .1
>LDA.G ASM.LI.CON
bpl .9
bmi .8
.1 >LDA.G ASM.LI.ON
bpl .9
.8 >PUSHW ZPLineBuf
>PUSHW SRC.LINENUM
ldy #ASM.PC+1
>PUSHB (pData),y
dey
>PUSHB (pData),y
>LDYA L.MSG.SRCLINE
>SYSCALL PrintF.YA
.9 rts
*---------------------------------------
SRC.PrintLineErr >PUSHW ZPLineBuf
>LDYA L.MSG.LINECR
>SYSCALL PrintF.YA
bcs .9
lda ZPLinePtr
sec
sbc ZPLineBuf
tax
beq .4
.3 phx
lda #'-'
>SYSCALL PutChar.A
plx
bcs .9
dex
bne .3
.4 lda #'^'
phy
>SYSCALL PutChar.A
ply
bcs .9
.5 lda #13
>SYSCALL PutChar.A
lda #10
>SYSCALL PutChar.A
.9 rts
*---------------------------------------
SRC.ParseLine lda (ZPLineBuf)
tax
beq .1
cmp #'*' Comment?
beq .1
cmp #';' Comment?
beq .1
ldy #ASM.DO.ON
lda (pData),y
bne .1
stz SRC.GLabel.New
cpx #' ' no label...go scan dir/opcode
beq .4
cpx #'.' local symbol?
bne .2
jsr SRC.ParseLine.SymL
bra .3
.1 clc
rts
.2 jsr SRC.ParseLine.SymG
.3 bcs SRC.ParseLine.Err
.4 jsr SRC.GetNextCharNB Scan for an Opcode...
beq SRC.ParseLine.Ok
cmp #'.'
bne .5
jsr SRC.GetNextChar Skip .
jsr SRC.ParseLine.Dir
bcs SRC.ParseLine.Err
bra SRC.ParseLine.Ok
.5 cmp #'>'
bne .6
jsr SRC.ParseLine.Exec.Macro
bcs SRC.ParseLine.Err
bra SRC.ParseLine.Ok
.6 jsr SRC.ParseLine.OpCode
bcs SRC.ParseLine.Err
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
bit #$40 found symbol pending ?
bne .2 yes, update
bit #$1 found is .SE ?
beq SRC.ParseLine.Redef no, redefine error
.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.Inv lda #ERR.INV.LABEL
SRC.ParseLine.Err sec
rts
SRC.ParseLine.Redef lda #ERR.SYMBOL.REDEFINE
sec
rts
*---------------------------------------
SRC.ParseLine.SymP jsr SRC.GetNextChar
beq SRC.ParseLine.SymE
jsr SRC.GetDecimal
bcs SRC.ParseLine.SymE
jmp SYM.AddPrivate
*---------------------------------------
SRC.ParseLine.SymL jsr SRC.GetNextChar
beq SRC.ParseLine.SymE
jsr SRC.GetDecimal
bcs SRC.ParseLine.SymE
lda SRC.ACC+1
ora SRC.ACC+2
ora SRC.ACC+3
bne SRC.ParseLine.SymE Max .255
lda SRC.ACC
beq SRC.ParseLine.SymE .0 is not allowed
clc
rts
*---------------------------------------
SRC.ParseLine.SymE lda #ERR.INV.LABEL
sec
rts
SRC.ParseLine.SymR lda #ERR.RANGE
sec
rts
*---------------------------------------
SRC.ParseLine.SymG >PUSHB.G SYM.hGlobals
>PUSHW ZPLinePtr
>PUSHEA.G SYM.Value
>SYSCALL SListAdd
bcs SRC.ParseLine.SymE
adc ZPLinePtr
sta ZPLinePtr
bcc .1
inc ZPLinePtr+1
.1
clc
rts
*---------------------------------------
SRC.ParseLine.Dir >LDYA L.T.DIRECTIVES
jsr SRC.GetKeyword
bcs .9
jmp (J.DIRECTIVES,x)
.9 lda #ERR.INV.DIRECTIVE
sec
rts
*---------------------------------------
SRC.ParseLine.Exec.Macro
clc
rts
*---------------------------------------
SRC.ParseLine.Add.Macro
clc
rts
*---------------------------------------
SRC.ParseLine.OpCode
>LDYA ZPOPtr
>STYA ZPPtr1
.10 lda (ZPPtr1) End Of OpCode List
ldy #1
ora (ZPPtr1),y
beq .9
lda ZPPtr1
clc
adc #2
sta ZPPtr2
lda ZPPtr1+1
adc #0
sta ZPPtr2+1
lda (ZPPtr2)
tax
ldy #0
.1 lda (ZPLinePtr),y
cmp #'a'
bcc .11
cmp #'z'+1
bcs .11
eor #$20
.11 iny
cmp (ZPPtr2),y
bne .7
dex
bne .1
* jsr SRC.ParseLine.AM
clc
rts
bcs .99
bcc .20
ldx SRC.AM.StrBuf
beq .20
ldx #0
.21 inx
lda SRC.AM.StrBuf,x
phx
>SYSCALL PutChar.A
plx
cpx SRC.AM.StrBuf
bne .21
lda #13
>SYSCALL PutChar.A
.20 ldy #ASM.PC
lda (pData),y
inc
sta (pData),y
bne .2
iny
lda (pData),y
inc
sta (pData),y
.2 clc
rts
.7 lda ZPPtr1
clc
adc (ZPPtr1)
tax
lda ZPPtr1+1
ldy #1
adc (ZPPtr1),y
stx ZPPtr1
sta ZPPtr1+1
bra .10
.9 lda #ERR.INV.OPCODE
sec
.99 rts
*---------------------------------------
SRC.ParseLine.AM stz SRC.AM.ID
stz SRC.AM.StrBuf
.1 jsr SRC.GetNextCharUC any arg immediately after ' '?
beq .8 no, AM.ID=0 (implied)
cmp #' ' another space ?
beq .8 ignore end of line (comment)
jsr SRC.IsAMReserved
bcs .2
inc SRC.AM.StrBuf
ldx SRC.AM.StrBuf
sta SRC.AM.StrBuf,x
bra .1
.8 clc
rts
.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
ldx ZPLinePtr
stx SRC.LinePtrSave
ldx ZPLinePtr+1
stx SRC.LinePtrSave+1
stz SRC.AM.tmpBuf
sta SRC.AM.tmpBuf+1
inc SRC.AM.tmpBuf
.3 jsr SRC.GetNextCharUC
beq .4
jsr SRC.IsLetterOrDigit
bcs .4
inc SRC.AM.tmpBuf
ldx SRC.AM.tmpBuf
sta SRC.AM.tmpBuf,x
bra .3
.4 ldy #0
.5 lda (ZPPtr3),y
beq .71 last register ?
phy
ldx #$ff
.6 lda (ZPPtr3),y
iny
inx
cmp SRC.AM.tmpBuf,x
bne .7
cpx SRC.AM.tmpBuf
bne .6
ply
ldy #0 register match, add to AM string
ldx SRC.AM.StrBuf
.61 iny
lda SRC.AM.tmpBuf,y
inx
sta SRC.AM.StrBuf,x
cpy SRC.AM.tmpBuf
bne .61
stx SRC.AM.StrBuf
jmp .1
.7 ply
tya
sec
adc (ZPPtr3),y
tay
bra .5
.71 ldx SRC.LinePtrSave Does not match a register,restore Ptr
stx ZPLinePtr
stx SRC.LinePtrSave+1
stx ZPLinePtr+1
.70 jsr EXP.Eval
bcs .99
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
.9 lda #ERR.INV.AM.SYN
sec
.99 rts
*---------------------------------------
SRC.GetDecimal stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
lda (ZPLinePtr)
beq .99
jsr SRC.IsDigit10
bcs .99
and #$0F
sta SRC.ACC
.1 jsr SRC.GetNextChar
beq .8
cmp #' '
beq .8
jsr SRC.IsEXPReserved
bcc .8
jsr SRC.IsAMReserved
bcc .8
jsr SRC.IsDigit10
bcs .9
and #$0F
pha
jsr SRC.ACC10
pla
bcs .9
adc SRC.ACC
sta SRC.ACC
bcc .1
inc SRC.ACC+1
bne .1
inc SRC.ACC+2
bne .1
inc SRC.ACC+3
bne .1
.9 lda #ERR.VAL.TOO.BIG
sec
rts
.8 clc
rts
.99 lda #ERR.SYNTAX.ERROR
sec
rts
*---------------------------------------
SRC.GetHex stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
jsr SRC.GetNextChar
lda (ZPLinePtr)
beq .99
jsr SRC.IsDigit16
bcs .99
sta SRC.ACC
.1 jsr SRC.GetNextChar
beq .8
cmp #' '
beq .8
jsr SRC.IsEXPReserved
bcc .8
jsr SRC.IsAMReserved
bcc .8
jsr SRC.IsDigit16
bcs .99
ldx #4
.2 asl SRC.ACC
rol SRC.ACC+1
rol SRC.ACC+2
rol SRC.ACC+3
bcs .9
dex
bne .2
ora SRC.ACC
sta SRC.ACC
bra .1
.8 clc
rts
.9 lda #ERR.VAL.TOO.BIG
sec
rts
.99 lda #ERR.SYNTAX.ERROR
sec
rts
*---------------------------------------
SRC.GetOctal stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
jsr SRC.GetNextChar
lda (ZPLinePtr)
beq .99
jsr SRC.IsDigit8
bcs .99
and #$0F
sta SRC.ACC
.1 jsr SRC.GetNextChar
beq .8
cmp #' '
beq .8
jsr SRC.IsEXPReserved
bcc .8
jsr SRC.IsAMReserved
bcc .8
jsr SRC.IsDigit8
bcs .9
asl
asl
asl
asl
asl
ldx #3
.2 asl
rol SRC.ACC
rol SRC.ACC+1
rol SRC.ACC+2
rol SRC.ACC+3
bcs .9
dex
bne .2
bra .1
.8 clc
rts
.9 lda #ERR.VAL.TOO.BIG
sec
rts
.99 lda #ERR.SYNTAX.ERROR
sec
rts
*---------------------------------------
SRC.GetBinary stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
jsr SRC.GetNextChar
lda (ZPLinePtr)
beq .99
cmp #'1'
beq .10
cmp #'0'
bne .99
.10 and #$01
sta SRC.ACC
.1 jsr SRC.GetNextChar
beq .8
cmp #' '
beq .8
jsr SRC.IsEXPReserved
bcc .8
jsr SRC.IsAMReserved
bcc .8
cmp #'1'
beq .11
cmp #'0'
bne .8
.11 lsr
rol SRC.ACC
rol SRC.ACC+1
rol SRC.ACC+2
rol SRC.ACC+3
bcs .9
bra .1
.8 clc
rts
.9 lda #ERR.VAL.TOO.BIG
sec
rts
.99 lda #ERR.SYNTAX.ERROR
sec
rts
*---------------------------------------
SRC.GetKeyword >STYA ZPPtr1 KeyWord table
stz SRC.Keyword.ID
.1 lda (ZPPtr1)
beq .9 End Of table
tax KW len
.2 ldy #0
.3 lda (ZPLinePtr),y
beq .5
jsr SRC.IsLetter
bcs .5
iny
cmp (ZPPtr1),y
bne .5
dex
bne .3
lda (ZPLinePtr),y All chars match...
beq .4 End of Line ?
jsr SRC.IsLetter
bcc .5 Additional letters...
.4 lda ZPLinePtr
clc
adc (ZPPtr1)
sta ZPLinePtr
bcc .41
inc ZPLinePtr+1
.41 ldx SRC.Keyword.ID
clc
rts
.5 lda (ZPPtr1)
sec Add keyword Len+1
adc ZPPtr1
sta ZPPtr1
bcc .6
inc ZPPtr1+1
.6 inc SRC.Keyword.ID
inc SRC.Keyword.ID
bra .1
.9 sec
rts
*---------------------------------------
SRC.IsAMReserved ldx SRC.AM.RESERVED
.1 cmp SRC.AM.RESERVED,x
beq .8
dex
bne .1
sec
rts
.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
dex
bne .1
sec
rts
.8 clc
rts
*---------------------------------------
SRC.IsLetterOrDigit jsr SRC.IsDigit10
bcc SRC.IsLetterRTS
*---------------------------------------
SRC.IsLetter cmp #'A'
bcc .9
cmp #'Z'+1
bcc SRC.IsLetterRTS
cmp #'a'
bcc .9
cmp #'z'+1
rts CC if lowercase
.9 sec
SRC.IsLetterRTS rts
*---------------------------------------
SRC.IsDigit16 jsr SRC.IsDigit10
bcc .8
cmp #'A'
bcc .9
cmp #'F'+1
bcc .1
rts cc if ok, cs if not
.1 sbc #'A'-11 cc so A->10 (11-CC)
clc
.8 and #$0F
rts
.9 sec
rts
*---------------------------------------
SRC.IsDigit10 cmp #'0'
bcc .9
cmp #'9'+1
rts cc if ok, cs if not
.9 sec
rts
*---------------------------------------
SRC.IsDigit8 cmp #'0'
bcc .9
cmp #'7'+1
rts cc if ok, cs if not
.9 sec
rts
*---------------------------------------
SRC.GetNextCharNB jsr SRC.GetNextCharUC
beq .9
cmp #' '
beq SRC.GetNextCharNB
.9 rts
*---------------------------------------
SRC.GetNextCharUC jsr SRC.GetNextChar
beq .9
cmp #'a'
bcc .9
cmp #'z'+1
bcs .9
eor #$20 to Uppercase
.9 rts
*---------------------------------------
SRC.GetCharUC lda (ZPLinePtr)
beq .9
cmp #'a'
bcc .9
cmp #'z'+1
bcs .9
eor #$20 to Uppercase
.9 rts
*---------------------------------------
SRC.GetNextChar lda (ZPLinePtr)
beq .9
inc ZPLinePtr
bne .1
inc ZPLinePtr+1
.1 lda (ZPLinePtr)
.9 rts
*---------------------------------------
SRC.ACC10 lda SRC.ACC ACC*2-> ACC & ACCTMP
asl
sta SRC.ACC
sta SRC.ACCTMP
lda SRC.ACC+1
rol
sta SRC.ACC+1
sta SRC.ACCTMP+1
lda SRC.ACC+2
rol
sta SRC.ACC+2
sta SRC.ACCTMP+2
lda SRC.ACC+3
rol
sta SRC.ACC+3
sta SRC.ACCTMP+3
bcs .9
ldx #2
.1 asl SRC.ACC ACC=ACC*4
rol SRC.ACC+1
rol SRC.ACC+2
rol SRC.ACC+3
bcs .9
dex
bne .1
lda SRC.ACC CC from ROL SRC.ACC+3
adc SRC.ACCTMP
sta SRC.ACC
lda SRC.ACC+1
adc SRC.ACCTMP+1
sta SRC.ACC+1
lda SRC.ACC+2
adc SRC.ACCTMP+2
sta SRC.ACC+2
lda SRC.ACC+3
adc SRC.ACCTMP+3
sta SRC.ACC+3 CS if overflow
.9 rts
*---------------------------------------
MAN
SAVE /A2OSX.BUILD/BIN/DEV/ASM.S.SRC
LOAD /A2OSX.BUILD/BIN/DEV/ASM.S
ASM