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 *-------------------------------------- FILES.MAX .EQ 4 SCOPE.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.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.SizeOf .EQ 4 SYM.Addr .EQ 6 SYM.Def .EQ 8 * SYM .EQ 10 *-------------------------------------- CPS.ParentID .EQ 0 CPS.hSYM .EQ 2 * CPS.Cont .EQ 4 CPS.Break .EQ 6 * CPS .EQ 8 *-------------------------------------- * 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 ZPCCStack .BS 2 ZPLineBufPtr .BS 2 ZPLookupPtr .BS 2 CStackPtr .BS 1 LocalPtr .BS 1 ScopePtr .BS 1 ScopenCnt .BS 1 * .BS 1 * .BS 1 ZPSymSize .BS 2 ZPSymBufPtr .BS 2 ZPLookupSymPtr .BS 2 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.COMPILING .DA MSG.COMPILING L.MSG.LINKING .DA MSG.LINKING L.MSG.LINKING2 .DA MSG.LINKING2 L.MSG.GENERATING .DA MSG.GENERATING L.MSG.DEBUG .DA MSG.DEBUG L.MSG.TRACE .DA MSG.TRACE 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.ENV.INCLUDE .DA ENV.INCLUDE *-------------------------------------- L.CC.PREOPS .DA CC.PREOPS J.CC.PREOPS .DA CC.EXP.GetRef .DA CC.EXP.GetDeref L.CC.POSTOPS .DA CC.POSTOPS L.CC.AOPS .DA CC.AOPS L.CC.BOPS .DA CC.BOPS J.CC.bBOPS .DA CC.BOPS.bMUL .DA CC.BOPS.bDIV .DA CC.BOPS.bMOD .DA CC.BOPS.ADD .DA CC.BOPS.SUB .DA CC.BOPS.SHL .DA CC.BOPS.SHR .DA CC.BOPS.L .DA CC.BOPS.LE .DA CC.BOPS.G .DA CC.BOPS.GE .DA CC.BOPS.EQ .DA CC.BOPS.NE .DA CC.BOPS.AND .DA CC.BOPS.OR .DA CC.BOPS.EOR .DA CC.BOPS.LAND .DA CC.BOPS.LOR J.CC.cBOPS .DA CC.BOPS.cMUL .DA CC.BOPS.cDIV .DA CC.BOPS.cMOD .DA CC.BOPS.ADD .DA CC.BOPS.SUB .DA CC.BOPS.SHL .DA CC.BOPS.SHR .DA CC.BOPS.L .DA CC.BOPS.LE .DA CC.BOPS.G .DA CC.BOPS.GE .DA CC.BOPS.EQ .DA CC.BOPS.NE .DA CC.BOPS.AND .DA CC.BOPS.OR .DA CC.BOPS.EOR .DA CC.BOPS.LAND .DA CC.BOPS.LOR L.CC.DIRS .DA CC.DIRS L.CC.KW .DA CC.KW 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 CC.DIR.DEFINE .DA CC.DIR.INCLUDE *-------------------------------------- J.CC.KW .DA CC.KW.IF .DA CC.KW.WHILE .DA CC.KW.ELSE .DA CC.KW.DO .DA CC.KW.FOR .DA CC.KW.SWITCH .DA CC.KW.CASE .DA CC.KW.BREAK .DA CC.KW.CONTINUE .DA CC.KW.RETURN *-------------------------------------- .DA CC.KW.SIZEOF .DA CC.KW.STRUCT *-------------------------------------- J.CC.KW.END .DA CC.KW.IF.END .DA CC.KW.WHILE.END .DA CC.KW.ELSE.END .DA CC.KW.DO.END .DA CC.KW.FOR.END *-------------------------------------- J.CC.SCSPEC .DA CC.SCSPEC.AUTO .DA CC.SCSPEC.REGISTER .DA CC.SCSPEC.STATIC .DA CC.SCSPEC.EXTERN .DA CC.SCSPEC.TYPEDEF J.CC.TYPEQUAL .DA CC.TYPE.CONST .DA CC.TYPE.VOLATILE J.CC.TYPESPEC .DA CC.TYPE.SIGNED .DA CC.TYPE.UNSIGNED .DA CC.TYPE.SHORT J.CC.TYPES .DA CC.TYPE.VOID .DA CC.TYPE.CHAR .DA CC.TYPE.INT .DA CC.TYPE.LONG .DA CC.TYPE.FLOAT J.CC.UTYPES .DA CC.TYPE.UCHAR .DA CC.TYPE.UINT .DA CC.TYPE.ULONG J.CC.STYPES .DA CC.TYPE.SCHAR .DA CC.TYPE.SINT .DA CC.TYPE.SLONG *-------------------------------------- L.CC.MAIN .DA CC.MAIN L.CC.LIBC .DA CC.LIBC L.PCC.FH .DA PCC.FH .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 CC.Init bcs CS.INIT.RTS jsr CODE.Init jsr CS.RUN.FOpen1st bcs CS.INIT.RTS *-------------------------------------- CS.RUN.CLOOP jsr CC.CompileFile cmp #MLI.E.EOF bne .9 jsr CS.RUN.FClose bne CS.RUN.CLOOP *-------------------------------------- jsr PrintSummary bcs .99 jsr CC.Link bcs .99 jsr CheckMain bcs .99 dec bPass2 jsr CS.RUN.FCreate bcs .99 jsr CODE.Init bcs .99 jsr CS.RUN.FOpen1st bcs .99 *-------------------------------------- .2 jsr CC.CompileFile cmp #MLI.E.EOF bne .9 jsr CS.RUN.FClose bne .2 *-------------------------------------- .8 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 ldx #OptionVars-OptionList-1 .1 cmp OptionList,x beq .2 dex bpl .1 bra .90 .2 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.RUN.FOpen1st >LDA.G CC.InFileArg >SYSCALL ArgV CS.RUN.FOpen phy pha >PUSHW L.MSG.COMPILING pla pha >PUSHYA >PUSHBI 2 >SYSCALL PrintF pla ply >PUSHYA >PUSHBI O.RDONLY >PUSHBI S.FI.T.TXT >PUSHWZ Aux type >SYSCALL FOpen bcs .9 tax >LDA.G hFilePtr inc sta (pData),y tay txa sta (pData),y >LDA.G LineCntPtr inc inc sta (pData),y tay lda #0 sta (pData),y iny sta (pData),y .9 rts *-------------------------------------- CS.RUN.FGetS >LDYA.G LineBufPtr >STYA ZPLineBufPtr >LDA.G LineCntPtr tay lda (pData),y inc sta (pData),y bne .1 iny lda (pData),y inc sta (pData),y .1 >LDA.G hFilePtr tay lda (pData),y >PUSHA >PUSHW ZPLineBufPtr >PUSHWI 255 >SYSCALL FGetS bcs .9 >LDA.G bTrace bpl .8 jsr PrintTraceMsg .8 .9 rts *-------------------------------------- CS.RUN.FClose >LDA.G hFilePtr cmp #hFilePtr beq .8 tay lda (pData),y >SYSCALL FClose >LDA.G hFilePtr dec sta (pData),y cmp #hFilePtr beq .8 >LDA.G LineCntPtr dec dec sta (pData),y NZ .8 rts *-------------------------------------- CS.RUN.FCreate >LDA.G CC.OutFileArg >SYSCALL ArgV >STYA ZPPtr1 >PUSHW L.MSG.GENERATING >PUSHW ZPPtr1 >PUSHBI 2 >SYSCALL PrintF >PUSHW ZPPtr1 >PUSHBI O.WRONLY+O.CREATE >PUSHBI S.FI.T.BIN >PUSHWI $2000 Aux type >SYSCALL FOpen bcs .9 >STA.G CC.hOutFile >PUSHA A = CC.hOutFile >PUSHW L.PCC.FH >PUSHWI PCC.FH.L >SYSCALL FWrite .9 rts *-------------------------------------- CS.DOEVENT sec rts *-------------------------------------- CS.QUIT jsr CODE.Quit jsr CC.Quit >LDA.G hLineBuf beq .8 >SYSCALL FreeMem .8 clc rts *-------------------------------------- PrintTraceMsg ldy #S.PS.hStdErr lda (pPS),y >PUSHA >PUSHW L.MSG.TRACE >LDA.G LineCntPtr inc tay lda (pData),y >PUSHA dey lda (pData),y >PUSHA >PUSHW.G LineBufPtr >PUSHBI 4 >SYSCALL FPrintF rts *-------------------------------------- PrintDebugMsg >PUSHW L.MSG.DEBUG >PUSHW ZPCCCode >PUSHW ZPCCConst >PUSHW ZPCCData lda pStack clc adc #8 pha lda pStack+1 adc #0 >PUSHA pla >PUSHA >PUSHB LocalPtr >PUSHW ZPCCStack >PUSHB CStackPtr tay beq .1 lda (ZPCCStack),y pha iny lda (ZPCCStack),y ply .1 >PUSHYA lda ScopePtr sec sbc #CC.hSymbols >PUSHA >PUSHBI 15 >SYSCALL PrintF >DEBUG rts *-------------------------------------- PrintErrorMsg >LDA.G CC.hDefineBuf beq .10 >LDYA.G CC.SaveDefine >STYA ZPLineBufPtr .10 >LDA.G bTrace bmi .1 jsr PrintTraceMsg .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 lda ZPCCCode+1 sta PCC.FH+PCC.FH.IDATA+1 sec sbc #$20 sta PCC.FH+PCC.FH.CSSIZE+1 lda ZPCCCode sta PCC.FH+PCC.FH.CSSIZE sta PCC.FH+PCC.FH.IDATA >PUSHW L.MSG.SUMMARY >PUSHW PCC.FH+PCC.FH.CSSIZE >PUSHW ZPCCConst lda ZPCCData+1 >PUSHA sta PCC.FH+PCC.FH.DSSIZE+1 lda ZPCCData >PUSHA sta PCC.FH+PCC.FH.DSSIZE >PUSHBI 6 >SYSCALL PrintF rts *-------------------------------------- CheckMain >PUSHB.G CC.hSymbols >PUSHW L.CC.MAIN >SYSCALL SListLookup bcs .9 >STYA ZPPtr1 SymID >PUSHB.G CC.hSymbols >PUSHW ZPPtr1 SymID >PUSHWZ allocate >PUSHWI 65535 all >PUSHWZ From Start >SYSCALL SListGetData .9 bcs .99 >STYA ZPPtr2 ldy #SYM.Addr lda (ZPPtr2),y iny ora (ZPPtr2),y beq .90 lda (ZPPtr2),y sta PCC.FH+PCC.FH.MAIN+1 dey lda (ZPPtr2),y sta PCC.FH+PCC.FH.MAIN txa >SYSCALL FreeMem rts .90 txa >SYSCALL FreeMem .99 >LDYA L.MSG.NOMAIN >SYSCALL puts lda #E.CSYN sec rts *-------------------------------------- .INB usr/src/bin/cc.s.code .INB usr/src/bin/cc.s.core .INB usr/src/bin/cc.s.dir .INB usr/src/bin/cc.s.decl .INB usr/src/bin/cc.s.stmt .INB usr/src/bin/cc.s.kw .INB usr/src/bin/cc.s.type .INB usr/src/bin/cc.s.f .INB usr/src/bin/cc.s.exp .INB usr/src/bin/cc.s.sym .INB usr/src/bin/cc.s.link .INB usr/src/bin/cc.s.exec *-------------------------------------- CS.END *-------------------------------------- * Initialized DATA *-------------------------------------- MSG.GREETINGS .AZ "\r\nA2osX C Compiler %d.%d\r\n\r\n" MSG.USAGE .AS "Usage : CC