NEW PREFIX /A2OSX.BUILD AUTO 4,1 *--------------------------------------- SRC.PrintLine >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 ldx ZPLinePtr cpx ZPLineBuf beq .4 .3 phx lda #'-' >SYSCALL PutChar.A plx bcs .9 dex cpx ZPLineBuf 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 #0 >STA.G SYM.bGlobalUpdate jsr SRC.GetChar bcs .8 cmp #'*' Comment? beq .8 cmp #';' Comment? beq .8 cmp #' ' no label...go scan dir/opcode beq SRC.ParseLine.DirOp cmp #'.' local symbol? bne .2 jsr SRC.GetNextChar bcs SRC.ParseLine.InvLbl jsr SRC.GetDecimal bcs SRC.ParseLine.InvLbl lda SRC.ACC+1 ora SRC.ACC+2 ora SRC.ACC+3 bne SRC.ParseLine.InvLbl Max .255 lda SRC.ACC beq SRC.ParseLine.InvLbl .0 is not allowed jsr SYM.AddLocal bra .3 .8 clc rts .2 jsr SYM.AddGlobalPC .3 bcs SRC.ParseLine.Err SRC.ParseLine.DirOp jsr SRC.GetNextCharNB Scan for an Opcode... bcs SRC.ParseLine.Ok cmp #'.' bne .5 jsr SRC.GetNextChar bcs SRC.ParseLine.InvDir 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.G SYM.bGlobalUpdate bpl .8 bra .8 ldy #ASM.PASS lda (pData),y pass#2? bne .8 yes, nothing to do * --- Pass #1 >LDA.G SYM.Global+SYM.F bit #SYM.F.RESOLVED found symbol pending ? bne .2 yes, update bit #SYM.F.RW found is .SE ? beq SRC.ParseLine.Redef no, redefine error .2 jsr SYM.UpdateGlobal bra .8 .8 clc rts SRC.ParseLine.InvLbl lda #ERR.INV.LABEL SRC.ParseLine.Err sec rts SRC.ParseLine.Redef lda #ERR.SYMBOL.REDEFINE sec rts SRC.ParseLine.InvDir lda #ERR.INV.DIR sec rts *--------------------------------------- SRC.ParseLine.Dir >LDYA L.T.DIRECTIVES jsr SRC.GetKeyword bcs SRC.ParseLine.InvDir jmp (J.DIRECTIVES,x) *--------------------------------------- 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 ' '? bcs .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 bcs .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 jsr SRC.GetChar beq .99 stz SRC.ACC+1 stz SRC.ACC+2 stz SRC.ACC+3 jsr SRC.IsDigit10 bcs .99 and #$0F sta SRC.ACC .1 jsr SRC.GetNextChar bcs .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 jsr SRC.GetNextChar skip '$' bcs .99 stz SRC.ACC+1 stz SRC.ACC+2 stz SRC.ACC+3 jsr SRC.IsDigit16 bcs .99 sta SRC.ACC .1 jsr SRC.GetNextChar bcs .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 jsr SRC.GetNextChar skip '&' bcs .99 stz SRC.ACC+1 stz SRC.ACC+2 stz SRC.ACC+3 jsr SRC.IsDigit8 bcs .99 and #$0F sta SRC.ACC .1 jsr SRC.GetNextChar bcs .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 jsr SRC.GetNextChar skip '%' bcs .99 stz SRC.ACC+1 stz SRC.ACC+2 stz SRC.ACC+3 cmp #'1' beq .10 cmp #'0' bne .99 .10 and #$01 sta SRC.ACC .1 jsr SRC.GetNextChar bcs .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.GetNextChar bcs .9 cmp #' ' beq SRC.GetNextCharNB clc .9 rts *--------------------------------------- SRC.GetNextCharUC jsr SRC.GetNextChar bcs .9 cmp #'a' bcc .8 cmp #'z'+1 bcs .8 eor #$20 to Uppercase .8 clc .9 rts *--------------------------------------- SRC.GetNextChar lda (ZPLinePtr) beq SRC.GetChar.ERR cmp #$0D beq SRC.GetChar.ERR inc ZPLinePtr bne SRC.GetChar inc ZPLinePtr+1 SRC.GetChar lda (ZPLinePtr) beq SRC.GetChar.ERR cmp #$0D beq SRC.GetChar.ERR clc rts SRC.GetChar.ERR sec 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