A2osX/BIN/ASM.S.SRC.txt

734 lines
13 KiB
Plaintext
Raw Normal View History

2015-10-06 16:14:48 +00:00
PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*---------------------------------------
2015-10-28 16:55:12 +00:00
SRC.ParseLine ldx TmpBuffer256
2015-10-09 15:53:30 +00:00
beq SRC.ParseLine.Skip
2015-10-06 16:14:48 +00:00
2015-10-09 15:53:30 +00:00
cpx #'*' Comment?
beq SRC.ParseLine.Skip
cpx #';' Comment?
beq SRC.ParseLine.Skip
2015-10-06 16:14:48 +00:00
2015-10-09 15:53:30 +00:00
cpx #' ' no label...go scan dir/opcode
beq .4
2015-10-06 16:14:48 +00:00
2015-10-09 15:53:30 +00:00
.1 cpx #'.' local symbol?
bne .2
jsr SRC.ParseLine.SymL
bra .3
2015-10-06 16:14:48 +00:00
2015-10-09 15:53:30 +00:00
.2 jsr SRC.ParseLine.SymG
.3 bcs SRC.ParseLine.Err
.4 jsr SRC.GetCharNB Scan for an Opcode...
2015-10-06 16:14:48 +00:00
beq SRC.ParseLine.Ok
cmp #'.'
2015-10-09 15:53:30 +00:00
bne .5
2015-10-06 16:14:48 +00:00
2015-10-09 15:53:30 +00:00
jsr SRC.ParseLine.Dir
bcs SRC.ParseLine.Err
2015-10-06 16:14:48 +00:00
bra SRC.ParseLine.Ok
2015-10-28 16:55:12 +00:00
.5 cmp #'>'
bne .6
jsr SRC.ParseLine.Exec.Macro
bcs SRC.ParseLine.Err
bra SRC.ParseLine.Ok
.6 dec SRC.BufPtr Back one char...
jsr SRC.ParseLine.OpCode
2015-10-09 15:53:30 +00:00
bcs SRC.ParseLine.Err
2015-10-06 16:14:48 +00:00
2015-11-13 16:25:31 +00:00
SRC.ParseLine.Ok lda SRC.GLabel.Len
2015-10-09 15:53:30 +00:00
beq .1
2015-11-13 16:25:31 +00:00
* jsr SYM.AddToGBlock
* bcs SRC.ParseLine.Err
2015-10-28 16:55:12 +00:00
.1
2015-10-09 15:53:30 +00:00
SRC.ParseLine.skip clc
2015-10-06 16:14:48 +00:00
rts
SRC.ParseLine.Err1 lda #ERR.INVALID.LABEL
SRC.ParseLine.Err sec
rts
*---------------------------------------
2015-10-09 15:53:30 +00:00
SRC.ParseLine.SymP jsr SRC.GetChar
beq SRC.ParseLine.SymE
jsr SRC.GetDecimal
bcs SRC.ParseLine.SymR
jmp SYM.AddPrivate
*---------------------------------------
SRC.ParseLine.SymL jsr SRC.GetChar
beq SRC.ParseLine.SymE
jsr SRC.GetDecimal
bcs SRC.ParseLine.SymR
jmp SYM.AddLocal
*---------------------------------------
2015-11-13 16:25:31 +00:00
SRC.ParseLine.SymG jsr SRC.GetGLabel
2015-10-09 15:53:30 +00:00
bcs SRC.ParseLine.SymE
ldx #3 Makes Current Label = PC for now
ldy #ASM.PC
lda (pdata),y
2015-11-13 16:25:31 +00:00
.1 sta SRC.GLabel.Value,x
2015-10-09 15:53:30 +00:00
dey
dex
bpl .1
clc
rts
SRC.ParseLine.SymE lda #ERR.INVALID.LABEL
sec
SRC.ParseLine.SymR rts
*---------------------------------------
2015-10-06 16:14:48 +00:00
SRC.ParseLine.Dir >LDYA L.T.DIRECTIVES
jsr SRC.GetKeyword
bcs .9
jmp (J.DIRECTIVES,x)
.9 lda #ERR.INVALID.DIRECTIVE
sec
rts
*---------------------------------------
2015-10-28 16:55:12 +00:00
SRC.ParseLine.Exec.Macro
2015-10-09 15:53:30 +00:00
clc
rts
*---------------------------------------
2015-10-28 16:55:12 +00:00
SRC.ParseLine.Add.Macro
2015-10-06 16:14:48 +00:00
clc
rts
*---------------------------------------
2015-10-28 16:55:12 +00:00
SRC.ParseLine.OpCode
jsr SRC.GetArg
bcs .9
ldy #ASM.T.hMem
lda (pData),y
>SYSCALL SYS.GetMemPtrA
>STYA ZPPtr1
2015-10-30 16:34:59 +00:00
ldy #ASM.T.O setup Ptr to Opcodes
2015-10-28 16:55:12 +00:00
lda (ZPPtr1),y
clc
adc ZPPtr1
sta ZPPtr2
iny
lda (ZPPtr1),y
adc ZPPtr1+1
sta ZPPtr2+1
2015-10-30 16:34:59 +00:00
ldy #ASM.T.R setup Ptr to Registers
lda (ZPPtr1),y
clc
adc ZPPtr1
sta ZPPtr3
iny
lda (ZPPtr1),y
adc ZPPtr1+1
sta ZPPtr3+1
2015-10-28 16:55:12 +00:00
.10 lda (ZPPtr2)
ldy #1
ora (ZPPtr2),y
beq .9
ldx #$FF
.1 inx
lda SRC.Buffer,x
iny
cmp (ZPPtr2),y
bne .7
cpx SRC.Buffer
bne .1
2015-10-30 16:34:59 +00:00
jsr SRC.ParseLine.AM
bcs .99
2015-10-28 16:55:12 +00:00
clc
rts
.7 lda ZPPtr1
clc
adc (ZPPtr2)
tax
lda ZPPtr1+1
ldy #1
adc (ZPPtr2),y
stx ZPPtr2
sta ZPPtr2+1
bra .10
.9 lda #ERR.INVALID.OPCODE
sec
2015-10-30 16:34:59 +00:00
.99 rts
*---------------------------------------
SRC.ParseLine.AM stz SRC.AM.ID
stz SRC.AM.StrBuf
.1 jsr SRC.GetCharUC 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 lda SRC.AM.StrBuf
beq .89
2015-11-13 16:25:31 +00:00
>PUSHWI TmpBuffer256
2015-10-30 16:34:59 +00:00
>PUSHW L.SRC.AM.StrBuf
2015-11-13 16:25:31 +00:00
>PUSHB SRC.AM.StrBuf
2015-10-30 16:34:59 +00:00
>PUSHW L.MSG.DEBUG
>LIBCALL hLIBSTR,LIBSTR.PRINTF
.89 clc
2015-10-28 16:55:12 +00:00
rts
2015-10-30 16:34:59 +00:00
.2 jsr SRC.IsLetter Any register?
bcs .70 no, try something else
stz SRC.AM.tmpBuf
sta SRC.AM.tmpBuf+1
inc SRC.AM.tmpBuf
.3 jsr SRC.GetCharUC
beq .4
jsr SRC.IsLetterOrDigit
bne .4
inc SRC.AM.tmpBuf
ldx SRC.AM.tmpBuf
sta SRC.AM.tmpBuf,x
bra .3
.4 dec SRC.BufPtr back one char
ldy #0
.5 lda (ZPPtr3),y
beq .71 last register ?
ldx #$ff
2015-11-13 16:25:31 +00:00
phy
2015-10-30 16:34:59 +00:00
.6 lda (ZPPtr3),y
iny
inx
cmp SRC.AM.tmpBuf,x
bne .7
cpx SRC.AM.tmpBuf
bne .6
2015-11-13 16:25:31 +00:00
ply
2015-10-30 16:34:59 +00:00
ldy #0 register match, add to AM string
ldx SRC.AM.StrBuf
.61 iny
lda SRC.AM.tmpBuf,y
sta SRC.AM.StrBuf,x
inx
cpy SRC.AM.tmpBuf
bne .61
stx SRC.AM.StrBuf
bra .72
2015-11-13 16:25:31 +00:00
.7 ply
tya
sec
adc (ZPPtr3),y
tay
2015-10-30 16:34:59 +00:00
bra .5
.70 dec SRC.BufPtr back one char
.71 jsr SRC.GetExp
bcs .99
.72 jmp .1
clc
rts
.9 lda #ERR.INVALID.AM.SYN
sec
.99 rts
2015-10-28 16:55:12 +00:00
*---------------------------------------
2015-10-09 15:53:30 +00:00
SRC.PrintLine bcs .8 if CS, unconditional
2015-10-28 16:55:12 +00:00
ldy #ASM.MACRO.ON
2015-10-06 16:14:48 +00:00
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
>PUSHW L.MSG.SRCLINE
>LIBCALL hLIBSTR,LIBSTR.PRINTF
.9 rts
*---------------------------------------
SRC.GetDecimal stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
jsr SRC.GetChar
beq .99
jsr SRC.IsDigit10
bcs .99
and #$0F
sta SRC.ACC
.1 jsr SRC.GetChar
beq .8
cmp #' '
beq .8
jsr SRC.IsDigit10
bcs .99
and #$0F
pha
jsr SRC.ACC10
pla
bcs .9
clc
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
2015-10-28 16:55:12 +00:00
.99 lda #ERR.SYNTAX.ERROR
sec
rts
*---------------------------------------
SRC.GetHex stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
jsr SRC.GetChar
beq .99
jsr SRC.IsDigit16
bcs .99
and #$0F
sta SRC.ACC
.1 jsr SRC.GetChar
beq .8
cmp #' '
beq .8
jsr SRC.IsDigit16
bcs .99
asl
asl
asl
asl
ldx #4
.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
2015-10-30 16:34:59 +00:00
.99 lda #ERR.SYNTAX.ERROR
sec
rts
*---------------------------------------
SRC.GetOctal stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
jsr SRC.GetChar
beq .99
jsr SRC.IsDigit8
bcs .99
and #$0F
sta SRC.ACC
.1 jsr SRC.GetChar
beq .8
cmp #' '
beq .8
jsr SRC.IsDigit8
bcs .99
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
2015-10-28 16:55:12 +00:00
.99 lda #ERR.SYNTAX.ERROR
sec
rts
*---------------------------------------
SRC.GetBinary stz SRC.ACC+1
stz SRC.ACC+2
stz SRC.ACC+3
jsr SRC.GetChar
beq .99
cmp #'1'
beq .10
cmp #'0'
bne .99
.10 and #$01
sta SRC.ACC
.1 jsr SRC.GetChar
beq .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
2015-10-06 16:14:48 +00:00
.99 lda #ERR.SYNTAX.ERROR
sec
rts
*---------------------------------------
2015-11-13 16:25:31 +00:00
SRC.GetGLabel jsr SRC.GetCharUC
2015-10-06 16:14:48 +00:00
beq .9
jsr SRC.IsLetter
bcs .9
2015-11-13 16:25:31 +00:00
sta SRC.GLabel.Name
2015-10-06 16:14:48 +00:00
ldy #1
.1 jsr SRC.GetCharUC
beq .8
cmp #' '
beq .8
cmp #'.'
beq .2
jsr SRC.IsLetterOrDigit
bcs .9
2015-11-13 16:25:31 +00:00
.2 sta SRC.GLabel.Name,y
2015-10-06 16:14:48 +00:00
iny
2015-11-13 16:25:31 +00:00
cpy #SRC.GLABEL.MAXLEN
2015-10-06 16:14:48 +00:00
bne .1 if equ Carry is set
.9 sec
rts
2015-11-13 16:25:31 +00:00
.8 tya
sta SRC.GLabel.Len
2015-10-06 16:14:48 +00:00
clc
rts
*---------------------------------------
SRC.GetKeyword >STYA ZPPtr1
jsr SRC.GetArg
bcs .9
stz SRC.Keyword.ID
ldy #0
.3 lda (ZPPtr1),y
beq .9
cmp SRC.Buffer
bne .6
phy
ldx #0
.4 iny
inx
lda (ZPPtr1),y
cmp SRC.Buffer,x
bne .5
cpx SRC.Buffer
bne .4
ply
ldx SRC.Keyword.ID
clc
rts
.5 ply
.6 tya
sec Add keyword Len+1
adc (ZPPtr1),y
tay
inc SRC.Keyword.ID
inc SRC.Keyword.ID
bra .3
2015-10-30 16:34:59 +00:00
.9 sec
rts
*---------------------------------------
SRC.GetExp stz SRC.Exp
jsr SRC.GetCharUC
beq .9
ldy #0
jsr SRC.IsAMReserved
bcc .8
iny
sta SRC.Exp+1
.1 jsr SRC.GetCharUC
beq .89
cmp #' '
beq .89
jsr SRC.IsAMReserved
bcc .8
iny
sta SRC.Exp,y
bra .1
.8 dec SRC.BufPtr
.89 sty SRC.Exp
clc
rts
2015-10-06 16:14:48 +00:00
.9 sec
rts
*---------------------------------------
SRC.GetArg jsr SRC.GetCharUC
beq .9
sta SRC.Buffer+1
ldy #1
.1 jsr SRC.GetCharUC
beq .2
cmp #' '
beq .2
iny
sta SRC.Buffer,y
bra .1
.2 sty SRC.Buffer
clc
rts
.9 sec
rts
*---------------------------------------
2015-10-30 16:34:59 +00:00
SRC.IsAMReserved ldx SRC.AM.RESERVED
.1 cmp SRC.AM.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
*---------------------------------------
2015-10-06 16:14:48 +00:00
SRC.IsLetterOrDigit jsr SRC.IsDigit10
bcc SRC.IsLetterRTS
*---------------------------------------
SRC.IsLetter cmp #'A'
bcc .9
2015-11-13 16:25:31 +00:00
cmp #'Z'+1
2015-10-06 16:14:48 +00:00
bcc SRC.IsLetterRTS
cmp #'a'
bcc .9
2015-11-13 16:25:31 +00:00
cmp #'z'+1
2015-10-06 16:14:48 +00:00
rts CC if lowercase
.9 sec
SRC.IsLetterRTS rts
*---------------------------------------
2015-10-28 16:55:12 +00:00
SRC.IsDigit16 jsr SRC.IsDigit10
bcc .8
cmp #'A'
bcc .9
cmp #'G'
bcc .1
rts cc if ok, cs if not
.1 sbc #'A'-10 cc so A->10
clc
.8 and #$0F
rts
.9 sec
rts
*---------------------------------------
2015-10-06 16:14:48 +00:00
SRC.IsDigit10 cmp #'0'
bcc .9
2015-10-28 16:55:12 +00:00
cmp #'9'+1
2015-10-06 16:14:48 +00:00
rts cc if ok, cs if not
2015-10-30 16:34:59 +00:00
.9 sec
rts
*---------------------------------------
SRC.IsDigit8 cmp #'0'
bcc .9
cmp #'7'+1
rts cc if ok, cs if not
2015-10-06 16:14:48 +00:00
.9 sec
rts
*---------------------------------------
2015-10-09 15:53:30 +00:00
SRC.GetCharNB jsr SRC.GetCharUC
2015-10-06 16:14:48 +00:00
beq .9
cmp #' '
beq SRC.GetCharNB
.9 rts
*---------------------------------------
SRC.GetCharUC jsr SRC.GetChar
beq .9
cmp #'a'
bcc .9
2015-10-30 16:34:59 +00:00
cmp #'z'+1
2015-10-06 16:14:48 +00:00
bcs .9
eor #$20 to Uppercase
.9 rts
*---------------------------------------
SRC.GetChar ldx SRC.BufPtr
lda TmpBuffer256,x
2015-10-28 16:55:12 +00:00
beq .9
inc SRC.BufPtr if 255, will make Z
and #$7f Make sure NZ
.9 rts
2015-10-06 16:14:48 +00:00
*---------------------------------------
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 #1
.1 asl SRC.ACC ACC=ACC*8
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 BIN/ASM.S.SRC
LOAD BIN/ASM.S
ASM