NEW
  AUTO 3,1
*--------------------------------------
CODE.Init		>STZ.G CC.bInitCode

				>STA.G CC.ScopeID
				iny
				sta (pData),y

				>LDYAI PCC.FH.CS
				>STYA ZPCCCode

				ldy #SCOPE-1
				lda #0

.1				sta (ScopeStk),y		reset initial Scope ID, LocalPtr, FrameSize
				dey
				bpl .1

				stz ZPCCConst
				stz ZPCCConst+1

				jsr CODE.DSSelect
				bcs .99

				stz ArgIndex

.2				lda ArgIndex
				>CMP.G LibCount
				beq .8

				clc
				adc #hLibNs
				tay
				lda (pData),y
				>SYSCALL ArgV
				>STYA ZPPtr1

				ldy #0

.3				lda (ZPPtr1),y
				beq .4

				jsr CODE.EmitDATA
				bcs .99

				iny
				bne .3

.4				jsr CODE.EmitDATA		\0
				bcs .99

				inc ArgIndex
				bra .2

.8				lda #0
				jsr CODE.EmitDATA		\0
				bcs .99

				jsr CODE.CSSelect
				bcs .99

				>LDYAI 20				char *ARGV[10]
				>STYA ZPCCData

				clc
.99				rts
*--------------------------------------
CODE.Quit		>LDA.G CC.hOutFile
				beq .8

				>SYSCALL FClose

.8				clc
				rts
*--------------------------------------
CODE.AddLocal	eor #$FF
				inc

CODE.RemLocal	jsr CODE.LDAI
				bcs .9

				>LDYA L.PCC.ADDLOCAL
				jmp CODE.EmitPCC

.9				rts
*--------------------------------------
CODE.SetRetValue
				jsr CODE.LDXI
				bcs .9

				>LDYA L.PCC.SetRetValue
				jmp CODE.EmitPCC

.9				rts
*--------------------------------------
CODE.PUSHAXI	pha
				txa
				jsr CODE.PUSHI
				bcs CODE.LDAXI.RTS

				pla
*--------------------------------------
CODE.PUSHI		jsr CODE.LDAI
				bcs CODE.LDAXI.RTS

				bra CODE.PUSHA
*--------------------------------------
CODE.LDYAI		pha

				lda #$A0				LDY #imm
				jsr CODE.EmitByte
				bcs CODE.LDAXI.RTS

				tya
				jsr CODE.EmitByte
				bcs CODE.LDAXI.RTS

				lda #$A9				LDA #imm
				jsr CODE.EmitByte
				bcs CODE.LDAXI.RTS

				pla

				jmp CODE.EmitByte
*--------------------------------------
CODE.LDAXI		jsr CODE.LDAI
				bcc CODE.LDXI

CODE.LDAXI.RTS	rts
*--------------------------------------
CODE.LDYI		lda #$A0				LDY #imm
				jsr CODE.EmitByte
				bcs .9

				tya
				jmp CODE.EmitByte

.9				rts
*--------------------------------------
CODE.LDXI		lda #$A2				LDX #imm
				jsr CODE.EmitByte
				bcs .9

				txa
				jmp CODE.EmitByte

.9				rts
*--------------------------------------
CODE.LDAI		pha
				lda #$A9				LDA #imm
				jsr CODE.EmitByte
				bcs .9

				pla
				jmp CODE.EmitByte

.9				plx
				rts
*--------------------------------------
CODE.PUSHYA		jsr CODE.PUSHA
				lda #$98				TYA
				jsr CODE.EmitByte
*--------------------------------------
CODE.PUSHA		lda #$C6				DEC zp
				jsr CODE.EmitByte
				lda #pStack
				jsr CODE.EmitByte

				lda #$92				STA (zp)
				jsr CODE.EmitByte
				lda #pStack
				jmp CODE.EmitByte
*--------------------------------------
CODE.PULLYA		jsr CODE.PULLA
				lda #$48				PHA
				jsr CODE.EmitByte
				jsr CODE.PULLA
				lda #$7A				PLY
				bra CODE.EmitByte
*--------------------------------------
CODE.PULLA		lda #$B2				LDA (zp)
				jsr CODE.EmitByte
				lda #pStack
				jsr CODE.EmitByte
*--------------------------------------
CODE.INCPSTACK	lda #$E6				INC zp
				jsr CODE.EmitByte
				lda #pStack
				bra CODE.EmitByte
*--------------------------------------
CODE.SYSCALL	jsr CODE.LDXI
				bcs .9

				lda #$20				JSR
				ldx #A2osX.SYSCALL
				ldy /A2osX.SYSCALL
				bra CODE.TOABSYX

.9				rts
*--------------------------------------
CODE.FPUCALL	jsr CODE.LDXI
				bcs .9

				lda #$20				JSR
				ldx #A2osX.FPUCALL
				ldy /A2osX.FPUCALL
				bra CODE.TOABSYX

.9				rts
*--------------------------------------
CODE.LIBCALL	jsr CODE.LDXI
				bcs .9

				tya
				dec
				dec
				dec
				asl
				asl
				clc
				adc #PCC.PH.JMPLIBs
				tax
				lda #0
				adc /PCC.PH.JMPLIBs
				tay
				lda #$20				JSR
				bra CODE.TOABSYX

.9				rts
*--------------------------------------
CODE.TOABSYX	jsr CODE.EmitByte		A=opcode : JMP, JSR .....
				bcs .9

				txa
				jsr CODE.EmitByte
				bcs .9

				tya
				bra CODE.EmitByte

.9				rts
*--------------------------------------
CODE.DEBUG		>LDYA L.PCC.DEBUG
*--------------------------------------
CODE.EmitPCC	>STYA ZPLookupPtr

				lda (ZPLookupPtr)
				tax
				dex

				ldy #1

.1				lda (ZPLookupPtr),y
				jsr CODE.EmitByte
				bcs .9

				iny
				dex
				bne .1

.9				rts
*--------------------------------------
CODE.EmitByte	clc						if Pass 1...
				bit bPass2
				bpl .1

				phx
				phy
				pha

				.DO _DBG_OUT=1

				lda ZPCCCode
				and #$1F
				bne .11

				>PUSHW L.MSG.DEBUG.CSOUT
				>PUSHW ZPCCCode
				>PUSHBI 2
				>SYSCALL PrintF

.11				>PUSHW L.MSG.DEBUG.OUT
				pla
				pha
				>PUSHA
				>PUSHBI 1
				>SYSCALL PrintF

				.FIN

				>PUSHB.G CC.hOutFile
				pla

				>PUSHA
				>SYSCALL fputc

				ply
				plx

.1				inc ZPCCCode
				bne .8

				inc ZPCCCode+1

.8				rts						CC/CS from fputc
*--------------------------------------
CODE.EmitDATA	clc
				bit bPass2
				bpl .1

				phx
				phy
				tax
				>PUSHB.G CC.hOutFile
				txa

				>PUSHA
				>SYSCALL fputc
				ply
				plx

.1				inc ZPCCConst
				bne .8

				inc ZPCCConst+1

.8				rts						CC/CS from fputc
*--------------------------------------
CODE.CSSelect	clc
				bit bPass2
				bpl .8

				>PUSHB.G CC.hOutFile
				>PUSHWZ
*			>DEBUG
				lda ZPCCCode+1
				sec
				sbc #$20
				>PUSHA
				lda ZPCCCode
				>PUSHA
				>PUSHBI SEEK.SET
				>SYSCALL fseek

.8				rts
*--------------------------------------
CODE.DSSelect	clc
				bit bPass2
				bpl .8

				>PUSHB.G CC.hOutFile
				>PUSHWZ
*			>DEBUG
				lda PCC.FH+PCC.FH.CONST
				clc
				adc ZPCCConst
				tay
				
				lda PCC.FH+PCC.FH.CONST+1
				adc ZPCCConst+1
				sec
				sbc #$20

				>PUSHYA
				>PUSHBI SEEK.SET

				>SYSCALL fseek

.8				rts
*--------------------------------------
MAN
SAVE usr/src/bin/cc.s.code
LOAD usr/src/bin/cc.s
ASM
