NEW AUTO 3,1 .LIST OFF .OP 65C02 .OR $2000 .TF bin/cc *-------------------------------------- .INB inc/macros.i .INB inc/a2osx.i .INB inc/mli.i .INB inc/mli.e.i *-------------------------------------- _DBG_SYM .EQ 0 _DBG_SCOPE .EQ 0 _DBG_OUT .EQ 0 *-------------------------------------- FILES.MAX .EQ 4 LIBS.MAX .EQ 4 SCOPE.MAX .EQ 16 LOOKUP.MAX .EQ 16 *-------------------------------------- SYM.T .EQ 0 SYM.T.VOID .EQ 1 SYM.T.UCHAR .EQ 2 SYM.T.SCHAR .EQ 3 SYM.T.UINT .EQ 4 SYM.T.SINT .EQ 5 SYM.T.ULONG .EQ 6 SYM.T.SLONG .EQ 7 SYM.T.FLOAT .EQ 8 SYM.T.SU .EQ 9 SYM.T.ENUM .EQ 10 SYM.T.VARIADIC .EQ $FF SYM.Q .EQ 1 SYM.Q.POINTER .EQ %01000000 SYM.Q.PPOINTER .EQ %10000000 SYM.Q.PPPOINTER .EQ %11000000 SYM.Q.ARRAY .EQ %00010000 SYM.Q.AARRAY .EQ %00100000 SYM.Q.AAARRAY .EQ %00110000 SYM.Q.CONST .EQ %00001000 SYM.Q.VOLATILE .EQ %00000100 SYM.Q.FUNC .EQ %00000010 SYM.Q.FASTCALL .EQ %00000001 SYM.SC .EQ 2 SYM.SC.STATIC .EQ 0 SYM.SC.AUTO .EQ 2 SYM.SC.REGISTER .EQ 4 SYM.SC.EXTERN .EQ 6 SYM.SC.TYPEDEF .EQ 8 SYM.SC.DEFINE .EQ 10 SYM.SC.TAG .EQ 12 SYM.DefSize .EQ 3 SYM.SizeOf .EQ 4 SYM.Addr .EQ 6 SYM.BitO .EQ 8 SYM.BitW .EQ 9 SYM.ScopeID .EQ 10 * * SYM.Def .EQ 14 Funtions : fTQ,a1TQ,a2TQ.... * SYM .EQ 16 SYM.F.MAX .EQ 64 *-------------------------------------- SU.F.T .EQ 0 SU.F.Q .EQ 1 SU.F.O .EQ 2 SU.F.BitO .EQ 4 SU.F.BitW .EQ 5 SU.F.Name .EQ 6 *-------------------------------------- SCOPE.ID .EQ 0 SCOPE.LocalPtr .EQ 2 SCOPE.FrameSize .EQ 3 * SCOPE .EQ 4 *-------------------------------------- STMT.hMEM .EQ 3 switch/case STMT.MemPtr .EQ 2 STMT.TERM .EQ 1 STMT.KW .EQ 0 * STMT .EQ 4 *-------------------------------------- *-------------------------------------- * Zero Page Segment, up to 32 bytes *-------------------------------------- .DUMMY .OR ZPBIN ZS.START ZPPtr1 .BS 2 ZPPtr2 .BS 2 ZPPtr3 .BS 2 ArgIndex .BS 1 bPass2 .BS 1 ZPCCCode .BS 2 ZPCCConst .BS 2 ZPCCData .BS 2 ScopePtr .BS 1 StmtPtr .BS 1 ScopeStk .BS 2 StmtStk .BS 2 ZPLineBufPtr .BS 2 ZPLookupPtr .BS 2 ZPSymBufPtr .BS 2 ZPLookupSymPtr .BS 2 bLocalScope .BS 1 StmtPreOp .BS 1 ExpState .BS 1 *ExpState.VinYA .EQ $10 ExpState.AonStack .EQ $20 ExpState.AinPTR .EQ $40 ExpState.VonStack .EQ $80 * .BS 1 ZS.END .ED *-------------------------------------- * File Header (16 Bytes) *-------------------------------------- CS.START cld jmp (.1,x) .DA #$61 6502,Level 1 (65c02) .DA #1 BIN Layout Version 1 .DA #0 S.PS.F.EVENT .DA #0 .DA CS.END-CS.START Code Size (without Constants) .DA DS.END-DS.START Data Size .DA #256 Stack Size .DA #ZS.END-ZS.START Zero Page Size .DA 0 *-------------------------------------- * Relocation Table *-------------------------------------- .1 .DA CS.INIT .DA CS.RUN .DA CS.DOEVENT .DA CS.QUIT *-------------------------------------- L.MSG.GREETINGS .DA MSG.GREETINGS L.MSG.USAGE .DA MSG.USAGE L.MSG.READING .DA MSG.READING L.MSG.LINKING .DA MSG.LINKING L.MSG.LINKING2 .DA MSG.LINKING2 L.MSG.GENERATING .DA MSG.GENERATING .DO _DBG_SYM=1 L.MSG.DEBUG.SYMN .DA MSG.DEBUG.SYMN L.MSG.DEBUG.SYMU .DA MSG.DEBUG.SYMU L.MSG.DEBUG.SYMS .DA MSG.DEBUG.SYMS L.MSG.DEBUG.SYMG .DA MSG.DEBUG.SYMG L.MSG.DEBUG.SYMNL .DA MSG.DEBUG.SYMNL L.MSG.DEBUG.SYMSL .DA MSG.DEBUG.SYMSL .FIN .DO _DBG_SCOPE=1 L.MSG.DEBUG.SCIN .DA MSG.DEBUG.SCIN L.MSG.DEBUG.SC .DA MSG.DEBUG.SC L.MSG.DEBUG.SCOUT .DA MSG.DEBUG.SCOUT .FIN .DO _DBG_OUT=1 L.MSG.DEBUG.CSOUT .DA MSG.DEBUG.CSOUT L.MSG.DEBUG.OUT .DA MSG.DEBUG.OUT .FIN L.MSG.VERBOSE .DA MSG.VERBOSE L.MSG.RTSTK .DA MSG.RTSTK L.MSG.ERROR .DA MSG.ERROR L.MSG.SUMMARY .DA MSG.SUMMARY L.MSG.NOMAIN .DA MSG.NOMAIN L.MSG.ALLDONE .DA MSG.ALLDONE L.ENV.INCLUDE .DA ENV.INCLUDE L.ENV.LIB .DA ENV.LIB L.LIB.O .DA LIB.O *-------------------------------------- L.CC.AOPS .DA CC.AOPS L.CC.PREOPS .DA CC.PREOPS L.CC.POSTOPS .DA CC.POSTOPS L.CC.BOPS .DA CC.BOPS L.CC.DIRS .DA CC.DIRS L.CC.KW .DA CC.KW L.CC.KW2.IF .DA CC.KW2.IF L.CC.KW2.DO .DA CC.KW2.DO L.CC.SCSPEC .DA CC.SCSPEC L.CC.TYPEQUAL .DA CC.TYPEQUAL L.CC.TYPESPEC .DA CC.TYPESPEC L.CC.TYPES .DA CC.TYPES L.CC.FTYPES .DA CC.FTYPES *-------------------------------------- J.CC.DIRS .DA DIR.DEFINE .DA DIR.INCLUDE .DA DIR.IFDEF .DA DIR.IFNDEF .DA DIR.ELSE .DA DIR.ENDIF *-------------------------------------- J.CC.PREOPS .DA EXP.Ref .DA EXP.Deref .DA EXP.Abs .DA EXP.negate .DA EXP.lnot .DA EXP.bnot .DA EXP.preinc .DA EXP.predec *-------------------------------------- J.CC.POSTOPS .DA EXP.postinc .DA EXP.postdec .DA EXP.idx .DA EXP.SU .DA EXP.pSU *-------------------------------------- J.CC.KW .DA KW.IF .DA KW.WHILE KW.ELSE.ID .EQ *-J.CC.KW .DA KW.ELSE .DA KW.DO .DA KW.FOR KW.SWITCH.ID .EQ *-J.CC.KW .DA KW.SWITCH .DA KW.CASE .DA KW.DEFAULT .DA KW.BREAK .DA KW.CONTINUE .DA KW.RETURN .DA KW.SIZEOF *-------------------------------------- J.CC.KW.END .DA KW.IF.END .DA KW.WHILE.END .DA KW.ELSE.END .DA KW.DO.END .DA KW.FOR.END .DA KW.SWITCH.END *-------------------------------------- J.CC.SCSPEC .DA DECL.AUTO .DA DECL.REGISTER .DA DECL.STATIC .DA DECL.EXTERN .DA DECL.TYPEDEF J.CC.TYPEQUAL .DA TYPE.CONST .DA TYPE.VOLATILE J.CC.TYPESPEC .DA TYPE.STRUCT .DA TYPE.UNION .DA TYPE.ENUM .DA TYPE.SIGNED .DA TYPE.UNSIGNED .DA TYPE.SHORT J.CC.TYPES .DA TYPE.VOID .DA TYPE.CHAR .DA TYPE.INT .DA TYPE.LONG .DA TYPE.FLOAT J.CC.UTYPES .DA TYPE.UCHAR .DA TYPE.UINT .DA TYPE.ULONG J.CC.STYPES .DA TYPE.SCHAR .DA TYPE.SINT .DA TYPE.SLONG *-------------------------------------- L.CC.MAIN .DA CC.MAIN L.CC.SYSCALL .DA CC.SYSCALL L.CC.FPUCALL .DA CC.FPUCALL *-------------------------------------- L.PCC.FH .DA PCC.FH L.PCC.DEBUG .DA PCC.DEBUG L.PCC.SLEEP .DA PCC.SLEEP L.PCC.ENTER .DA PCC.ENTER L.PCC.LEAVE .DA PCC.LEAVE L.PCC.ADDLOCAL .DA PCC.ADDLOCAL L.PCC.SetRetValue .DA PCC.SetRetValue L.PCC.8to16 .DA PCC.8to16 L.PCC.JmpOnYA .DA PCC.JmpOnYA L.PCC.Pop16 .DA PCC.Pop16 L.PCC.TestZero1 .DA PCC.TestZero1 L.PCC.TestZero2 .DA PCC.TestZero2 L.PCC.TestZeroX .DA PCC.TestZeroX L.PCC.TestnZero1 .DA PCC.TestnZero1 L.PCC.TestnZero2 .DA PCC.TestnZero2 L.PCC.TestnZeroX .DA PCC.TestnZeroX L.PCC.PushLAddrH .DA PCC.PushLAddrH L.PCC.PushLAddrL .DA PCC.PushLAddrL L.PCC.PushIAddr .DA PCC.PushIAddr L.PCC.PushUAddr .DA PCC.PushUAddr L.PCC.GetLAddr1 .DA PCC.GetLAddr1 L.PCC.GetIAddr1 .DA PCC.GetIAddr1 L.PCC.GetUAddr1 .DA PCC.GetUAddr1 L.PCC.PopAddr1 .DA PCC.PopAddr1 L.PCC.PopValue1 .DA PCC.PopValue1 L.PCC.PopValue2 .DA PCC.PopValue2 L.PCC.PopValueX .DA PCC.PopValueX L.PCC.GetLAddr2 .DA PCC.GetLAddr2 L.PCC.GetIAddr2 .DA PCC.GetIAddr2 L.PCC.GetUAddr2 .DA PCC.GetUAddr2 L.PCC.PopAddr2 .DA PCC.PopAddr2 L.PCC.Deref2 .DA PCC.Deref2 L.PCC.PushDeref2 .DA PCC.PushDeref2 L.PCC.PushValue1 .DA PCC.PushValue1 L.PCC.PushValue2 .DA PCC.PushValue2 L.PCC.PushValueY .DA PCC.PushValueY L.PCC.Inc1 .DA PCC.Inc1 L.PCC.Inc2 .DA PCC.Inc2 L.PCC.Inc4 .DA PCC.Inc4 L.PCC.Dec1 .DA PCC.Dec1 L.PCC.Dec2 .DA PCC.Dec2 L.PCC.Dec4 .DA PCC.Dec4 *-------------------------------------- L.PCC.bBOPS .DA PCC.BOPS.bMUL .DA PCC.BOPS.bDIV .DA PCC.BOPS.bMOD .DA PCC.BOPS.ADD .DA PCC.BOPS.SUB .DA PCC.BOPS.SHL .DA PCC.BOPS.SHR .DA PCC.BOPS.L .DA PCC.BOPS.G .DA PCC.BOPS.LE .DA PCC.BOPS.GE .DA PCC.BOPS.EQ .DA PCC.BOPS.NE .DA PCC.BOPS.LAND .DA PCC.BOPS.AND .DA PCC.BOPS.LOR .DA PCC.BOPS.OR .DA PCC.BOPS.EOR *-------------------------------------- L.PCC.cBOPS .DA PCC.BOPS.cMUL .DA PCC.BOPS.cDIV .DA PCC.BOPS.cMOD .DA PCC.BOPS.ADD .DA PCC.BOPS.SUB .DA PCC.BOPS.SHL .DA PCC.BOPS.SHR .DA PCC.BOPS.L .DA PCC.BOPS.G .DA PCC.BOPS.LE .DA PCC.BOPS.GE .DA PCC.BOPS.EQ .DA PCC.BOPS.NE .DA PCC.BOPS.LAND .DA PCC.BOPS.AND .DA PCC.BOPS.LOR .DA PCC.BOPS.OR .DA PCC.BOPS.EOR *-------------------------------------- .DA 0 *-------------------------------------- * Called once at process creation * Put code for loading LIB here *-------------------------------------- CS.INIT clc CS.INIT.RTS rts *-------------------------------------- * Called until exit with CS * if RUN exits with CC, RN entered again *-------------------------------------- CS.RUN >PUSHW L.MSG.GREETINGS >PUSHW A2osX.KVER >PUSHBI 2 >SYSCALL PrintF bcs CS.INIT.RTS lda #hFilePtr >STA.G hFilePtr lda #LineCntPtr >STA.G LineCntPtr >LDYAI 256 >SYSCALL GetMem bcs CS.INIT.RTS >STYA.G LineBufPtr txa >STA.G hLineBuf jsr CS.RUN.ARGS bcs CS.INIT.RTS jsr CORE.Init bcs CS.INIT.RTS jsr CODE.Init bcs CS.INIT.RTS jsr FIO.FOpen1st bcs CS.INIT.RTS *-------------------------------------- CS.RUN.CLOOP jsr CORE.CompileFile cmp #MLI.E.EOF bne .9 * bne .1 jsr FIO.FClose bne CS.RUN.CLOOP *-------------------------------------- .1 jsr PrintSummary bcs .99 * >DEBUG jsr CC.Link bcs .99 * >DEBUG jsr CC.Link.CheckMain bcs .99 dec bPass2 jsr FIO.FCreate bcs .99 jsr CODE.Init bcs .99 jsr FIO.FOpen1st bcs .99 *-------------------------------------- .2 jsr CORE.CompileFile cmp #MLI.E.EOF bne .9 jsr FIO.FClose bne .2 *-------------------------------------- >LDYA L.MSG.ALLDONE >SYSCALL PutS lda #0 Exit Code = Success sec rts .9 pha jsr PrintErrorMsg pla sec .99 rts *-------------------------------------- CS.RUN.ARGS inc ArgIndex lda ArgIndex >SYSCALL ArgV bcs .8 >STYA ZPPtr1 lda (ZPPtr1) cmp #'-' bne .4 ldy #1 lda (ZPPtr1),y beq .90 ldx #OptionVars-OptionList-1 .1 cmp OptionList,x beq .2 dex bpl .1 bra .90 .2 cpx #2 LIB bcc .3 inc ArgIndex lda ArgIndex >SYSCALL ArgV bcs .90 jsr FIO.LoadLIB.o bcc CS.RUN.ARGS rts .3 ldy OptionVars,x lda #$ff sta (pData),y bra CS.RUN.ARGS .4 >LDA.G CC.InFileArg bne .5 lda ArgIndex >STA.G CC.InFileArg bra CS.RUN.ARGS .5 >LDA.G CC.OutFileArg bne .90 lda ArgIndex >STA.G CC.OutFileArg bra CS.RUN.ARGS .8 >LDA.G CC.InFileArg beq .90 >LDA.G CC.OutFileArg beq .90 clc .9 rts .90 >PUSHW L.MSG.USAGE >PUSHBI 0 >SYSCALL PrintF lda #E.SYN sec rts *-------------------------------------- CS.DOEVENT sec rts *-------------------------------------- CS.QUIT jsr CODE.Quit jsr CORE.Quit .1 >LDA.G LibCount beq .6 dec sta (pData),y clc adc #hLibOs tay lda (pData),y >SYSCALL FreeMem bra .1 .6 >LDA.G hLineBuf beq .8 >SYSCALL FreeMem .8 clc rts *-------------------------------------- PrintVerboseMsg .DO _DBG_SCOPE=1 >PUSHW L.MSG.DEBUG.SC jsr SCOPE.Push lda ScopePtr >PUSHA tay iny iny >PUSHB (ScopeStk),y iny >PUSHB (ScopeStk),y >PUSHBI 5 >SYSCALL PrintF * >DEBUG .FIN ldy #S.PS.hStdOut * ldy #S.PS.hStdErr lda (pPS),y >PUSHA >PUSHW L.MSG.VERBOSE >LDA.G LineCntPtr inc tay lda (pData),y >PUSHA dey lda (pData),y >PUSHA >PUSHW.G LineBufPtr >PUSHBI 4 >SYSCALL FPrintF rts *-------------------------------------- PrintErrorMsg >LDA.G CC.hDefineBuf beq .10 >LDYA.G CC.SaveDefine >STYA ZPLineBufPtr .10 >LDA.G bVerbose bmi .1 jsr PrintVerboseMsg .1 lda ZPLineBufPtr sec >SBC.G LineBufPtr tax >LDYA.G LineBufPtr >STYA ZPLineBufPtr txa beq .3 ldy #0 lda #'-' .2 sta (ZPLineBufPtr),y iny dex bne .2 txa .3 sta (ZPLineBufPtr),y .8 ldy #S.PS.hStdErr lda (pPS),y >PUSHA >PUSHW L.MSG.ERROR >PUSHW ZPLineBufPtr >PUSHBI 2 >SYSCALL FPrintF rts *-------------------------------------- PrintSummary >PUSHW L.MSG.SUMMARY lda ZPCCCode+1 sec sbc #$20 >PUSHA >PUSHB ZPCCCode >PUSHW ZPCCConst >PUSHW ZPCCData >PUSHBI 6 >SYSCALL PrintF rts *-------------------------------------- .INB usr/src/bin/cc.s.code .INB usr/src/bin/cc.s.core .INB usr/src/bin/cc.s.decl .INB usr/src/bin/cc.s.dir .INB usr/src/bin/cc.s.exp .INB usr/src/bin/cc.s.f .INB usr/src/bin/cc.s.fio .INB usr/src/bin/cc.s.kw .INB usr/src/bin/cc.s.link .INB usr/src/bin/cc.s.scope .INB usr/src/bin/cc.s.stmt .INB usr/src/bin/cc.s.sym .INB usr/src/bin/cc.s.type *-------------------------------------- CS.END *-------------------------------------- * Initialized DATA *-------------------------------------- MSG.GREETINGS .CZ "\r\nA2osX C Compiler %d.%d\r\n\r\n" MSG.USAGE .CS "Usage : CC