A2osX/BIN/CC.S.PCC.txt

751 lines
14 KiB
Plaintext
Raw Permalink Normal View History

2022-08-20 14:37:37 +00:00
NEW
AUTO 3,1
*--------------------------------------
* PCC = Pre Compiled Code
*--------------------------------------
ZS.RT.Ptr1 .EQ ZPBIN
ZS.RT.Ptr2 .EQ ZPBIN+2
*--------------------------------------
PCC.FH .PH $2000
PCC.FH.ORG cld
2022-08-20 14:37:37 +00:00
jmp (PCC.FH.JMP,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA #0 S.PS.F.EVENT
.DA #0
PCC.FH.CSSIZE .EQ *-PCC.FH.ORG
.DA $FFFF Code Size (without Constants)
PCC.FH.DSSIZE .EQ *-PCC.FH.ORG
.DA $FFFF Data Size
2022-08-20 14:37:37 +00:00
.DA #256 Stack Size
.DA #4 ZP Size
.DA 0
PCC.FH.JMP .DA PCC.FH.INIT
.DA PCC.FH.RUN
.DA PCC.FH.DOEVENT
.DA PCC.FH.QUIT
PCC.FH.CONST .EQ *-PCC.FH.ORG
.DA $FFFF
2022-08-20 14:37:37 +00:00
.DA 0
2023-01-26 07:07:08 +00:00
PCC.FH.INIT >LDYA PCC.FH.ORG+PCC.FH.CONST
>STYA ZS.RT.Ptr1
2023-01-27 14:49:42 +00:00
* >DEBUG
ldx #0
.1 lda (ZS.RT.Ptr1)
beq .8
phx
>LDYA ZS.RT.Ptr1
>SYSCALL LoadLib
plx
bcs .9
sta PCC.PH.hLIBs,x
phx
>SYSCALL GetMemPtr
plx
>STYA PCC.PH.JMPLIBs+1,x
inx
inx
inx
inx
ldy #0
.2 iny
lda (ZS.RT.Ptr1),y
bne .2
tya
sec
adc ZS.RT.Ptr1
sta ZS.RT.Ptr1
bcc .1
inc ZS.RT.Ptr1+1
bra .1
.8 clc
.9 rts
PCC.FH.QUIT ldx #12
.1 lda PCC.PH.hLIBs,x
beq .2
phx
>SYSCALL UnloadLib
plx
.2 dex
dex
dex
dex
bpl .1
clc
rts
PCC.PH.hLIBs .DA #0
PCC.PH.JMPLIBs jmp $FFFF
.DA #0
jmp $FFFF
.DA #0
jmp $FFFF
.DA #0
jmp $FFFF
PCC.FH.DOEVENT sec do not discard TIMER event
2022-08-20 14:37:37 +00:00
rts
* int main(int argc, char *argv[]) ;
PCC.FH.RUN lda #0
.1 pha
>SYSCALL ArgV
bcs .2
>STYA ZS.RT.Ptr1
pla
pha
asl
tay
lda ZS.RT.Ptr1
sta (pData),y
lda ZS.RT.Ptr1+1
iny
sta (pData),y
pla
inc
bra .1
.2 pla
jsr PCC.FH.CS Execute INIT code
lda #0
>PUSHA returned int=0
2022-08-20 14:37:37 +00:00
>PUSHA
>PUSHA int ARGC (hi byte=0)
2022-08-20 14:37:37 +00:00
ldy #S.PS.ARGC
lda (pPS),y
>PUSHA int ARGC (lo byte)
2022-08-20 14:37:37 +00:00
>PUSHW pData *char[] ARGV
* >DEBUG
PCC.FH.MAIN .EQ *-PCC.FH.ORG+1
jsr $FFFF jsr main
2022-08-20 14:37:37 +00:00
>PULLA
inc pStack pull returned int
sec
rts
*PCC.FH.SYSCALL jsr A2osX.SYSCALL
* bcc .8
* inc pStack
* eor #$ff
* inc
* >PUSHA int -ERROR code...
* ldy #1
* lda #$FF
* sta (pStack),y FFxx on stack
*.8
PCC.FH.CS .EP
PCC.FH.L .EQ *-PCC.FH
*--------------------------------------
PCC.DEBUG .DA #PCC.DEBUG.L
>DEBUG
PCC.DEBUG.L .EQ *-PCC.DEBUG
*--------------------------------------
PCC.SLEEP .DA #PCC.SLEEP.L
>SLEEP
PCC.SLEEP.L .EQ *-PCC.SLEEP
*--------------------------------------
PCC.ENTER .DA #PCC.ENTER.L
ldx pBase
phx
clc
adc pStack A = Local Size
sta pBase
PCC.ENTER.L .EQ *-PCC.ENTER
*--------------------------------------
PCC.LEAVE .DA #PCC.LEAVE.L
ldx pBase
stx pStack
plx
stx pBase
rts
PCC.LEAVE.L .EQ *-PCC.LEAVE
*--------------------------------------
PCC.ADDLOCAL .DA #PCC.ADDLOCAL.L
clc
adc pStack
sta pStack
PCC.ADDLOCAL.L .EQ *-PCC.ADDLOCAL
*--------------------------------------
PCC.SetRetValue .DA #PCC.SetRetValue.L
ldy #0
.1 >PULLA
sta (pBase),y
iny
dex
bne .1
PCC.SetRetValue.L .EQ *-PCC.SetRetValue
*--------------------------------------
PCC.8to16 .DA #PCC.8to16.L
lda (pStack)
pha
lda #0
sta (pStack)
pla
>PUSHA
PCC.8to16.L .EQ *-PCC.8to16
*--------------------------------------
PCC.JmpOnYA .DA #PCC.JmpOnYA.L
cmp (pStack)
bne .2+5 skip JMP abs
txa
ldy #1
cmp (pStack),y
.2 bne .2+5 skip JMP abs
PCC.JmpOnYA.L .EQ *-PCC.JmpOnYA
*--------------------------------------
PCC.Pop16 .DA #PCC.Pop16.L
inc pStack
inc pStack
PCC.Pop16.L .EQ *-PCC.Pop16
*--------------------------------------
2022-08-20 14:37:37 +00:00
PCC.TestZero1 .DA #PCC.TestZero1.L
>PULLA
tay
.2 bne .2+5 skip JMP abs
PCC.TestZero1.L .EQ *-PCC.TestZero1
*--------------------------------------
PCC.TestZero2 .DA #PCC.TestZero2.L
>PULLA
ora (pStack)
inc pStack
tay
.2 bne .2+5 skip JMP abs
PCC.TestZero2.L .EQ *-PCC.TestZero2
*--------------------------------------
PCC.TestZeroX .DA #PCC.TestZeroX.L
lda #0
.1 ora (pStack)
inc pStack
dex
bne .1
tay
.2 bne .2+5 skip JMP abs
PCC.TestZeroX.L .EQ *-PCC.TestZeroX
*--------------------------------------
PCC.TestnZero1 .DA #PCC.TestnZero1.L
>PULLA
tay
.2 beq .2+5 skip JMP abs
PCC.TestnZero1.L .EQ *-PCC.TestnZero1
*--------------------------------------
PCC.TestnZero2 .DA #PCC.TestnZero2.L
>PULLA
ora (pStack)
inc pStack
tay
.2 beq .2+5 skip JMP abs
PCC.TestnZero2.L .EQ *-PCC.TestnZero2
*--------------------------------------
PCC.TestnZeroX .DA #PCC.TestnZeroX.L
lda #0
.1 ora (pStack)
inc pStack
dex
bne .1
tay
.2 beq .2+5 skip JMP abs
PCC.TestnZeroX.L .EQ *-PCC.TestnZeroX
*--------------------------------------
PCC.PushLAddrH .DA #PCC.PushLAddrH.L
>PUSHB pBase+1
PCC.PushLAddrH.L .EQ *-PCC.PushLAddrH
*--------------------------------------
PCC.PushLAddrL .DA #PCC.PushLAddrL.L
clc
adc pBase
>PUSHA
PCC.PushLAddrL.L .EQ *-PCC.PushLAddrL
*--------------------------------------
PCC.PushIAddr .DA #PCC.PushIAddr.L
clc
adc PCC.FH.ORG+PCC.FH.CONST
2022-08-20 14:37:37 +00:00
dec pStack
>PUSHA
txa
adc PCC.FH.ORG+PCC.FH.CONST+1
2022-08-20 14:37:37 +00:00
ldy #1
sta (pStack),y
PCC.PushIAddr.L .EQ *-PCC.PushIAddr
*--------------------------------------
PCC.PushUAddr .DA #PCC.PushUAddr.L
clc
adc pData
dec pStack
>PUSHA
txa
adc pData+1
ldy #1
sta (pStack),y
PCC.PushUAddr.L .EQ *-PCC.PushUAddr
*--------------------------------------
PCC.GetLAddr1 .DA #PCC.GetLAddr1.L
clc
adc pBase
sta ZS.RT.Ptr1
lda pBase+1
sta ZS.RT.Ptr1+1
PCC.GetLAddr1.L .EQ *-PCC.GetLAddr1
*--------------------------------------
PCC.GetIAddr1 .DA #PCC.GetIAddr1.L
clc
adc PCC.FH.ORG+PCC.FH.CONST
2022-08-20 14:37:37 +00:00
sta ZS.RT.Ptr1
txa
adc PCC.FH.ORG+PCC.FH.CONST+1
2022-08-20 14:37:37 +00:00
sta ZS.RT.Ptr1+1
PCC.GetIAddr1.L .EQ *-PCC.GetIAddr1
*--------------------------------------
PCC.GetUAddr1 .DA #PCC.GetUAddr1.L
clc
adc pData
sta ZS.RT.Ptr1
txa
adc pData+1
sta ZS.RT.Ptr1+1
PCC.GetUAddr1.L .EQ *-PCC.GetUAddr1
*--------------------------------------
PCC.PopAddr1 .DA #PCC.PopAddr1.L
>PULLA
sta ZS.RT.Ptr1
>PULLA
sta ZS.RT.Ptr1+1
PCC.PopAddr1.L .EQ *-PCC.PopAddr1
*--------------------------------------
PCC.PopValue1 .DA #PCC.PopValue1.L
>PULLA
sta (ZS.RT.Ptr1)
PCC.PopValue1.L .EQ *-PCC.PopValue1
*--------------------------------------
PCC.PopValue2 .DA #PCC.PopValue2.L
>PULLA
sta (ZS.RT.Ptr1)
>PULLA
ldy #1
2022-08-20 14:37:37 +00:00
sta (ZS.RT.Ptr1),y
PCC.PopValue2.L .EQ *-PCC.PopValue2
*--------------------------------------
PCC.PopValueX .DA #PCC.PopValueX.L
ldy #0
.1 >PULLA
sta (ZS.RT.Ptr1),y
iny
dex
2022-08-20 14:37:37 +00:00
bpl .1
PCC.PopValueX.L .EQ *-PCC.PopValueX
2022-08-20 14:37:37 +00:00
*--------------------------------------
PCC.GetLAddr2 .DA #PCC.GetLAddr2.L
clc
adc pBase
sta ZS.RT.Ptr2
lda pBase+1
sta ZS.RT.Ptr2+1
PCC.GetLAddr2.L .EQ *-PCC.GetLAddr2
*--------------------------------------
PCC.GetIAddr2 .DA #PCC.GetIAddr2.L
clc
adc PCC.FH.ORG+PCC.FH.CONST
2022-08-20 14:37:37 +00:00
sta ZS.RT.Ptr2
txa
adc PCC.FH.ORG+PCC.FH.CONST+1
2022-08-20 14:37:37 +00:00
sta ZS.RT.Ptr2+1
PCC.GetIAddr2.L .EQ *-PCC.GetIAddr2
*--------------------------------------
PCC.GetUAddr2 .DA #PCC.GetUAddr2.L
clc
adc pData
sta ZS.RT.Ptr2
txa
adc pData+1
sta ZS.RT.Ptr2+1
PCC.GetUAddr2.L .EQ *-PCC.GetUAddr2
*--------------------------------------
PCC.PopAddr2 .DA #PCC.PopAddr2.L
>PULLA
sta ZS.RT.Ptr2
>PULLA
sta ZS.RT.Ptr2+1
PCC.PopAddr2.L .EQ *-PCC.PopAddr2
*--------------------------------------
PCC.Deref2 .DA #PCC.Deref2.L
ldy #1
lda (ZS.RT.Ptr2),y
tay
lda (ZS.RT.Ptr2)
sta ZS.RT.Ptr2
sty ZS.RT.Ptr2+1
PCC.Deref2.L .EQ *-PCC.Deref2
*--------------------------------------
PCC.PushDeref2 .DA #PCC.PushDeref2.L
ldy #1
>PUSHB (ZS.RT.Ptr2),y
>PUSHB (ZS.RT.Ptr2)
PCC.PushDeref2.L .EQ *-PCC.PushDeref2
*--------------------------------------
PCC.PushValue1 .DA #PCC.PushValue1.L
lda (ZS.RT.Ptr2)
>PUSHA
PCC.PushValue1.L .EQ *-PCC.PushValue1
*--------------------------------------
PCC.PushValue2 .DA #PCC.PushValue2.L
ldy #1
lda (ZS.RT.Ptr2),y
>PUSHA
lda (ZS.RT.Ptr2)
>PUSHA
PCC.PushValue2.L .EQ *-PCC.PushValue2
*--------------------------------------
PCC.PushValueY .DA #PCC.PushValueY.L
2022-08-20 14:37:37 +00:00
.1 lda (ZS.RT.Ptr2),y
>PUSHA
dey
bpl .1
PCC.PushValueY.L .EQ *-PCC.PushValueY
2022-08-20 14:37:37 +00:00
*--------------------------------------
PCC.Inc1 .DA #PCC.Inc1.L
lda (ZS.RT.Ptr2)
inc
sta (ZS.RT.Ptr2)
PCC.Inc1.L .EQ *-PCC.Inc1
*--------------------------------------
PCC.Inc2 .DA #PCC.Inc2.L
lda (ZS.RT.Ptr2)
inc
sta (ZS.RT.Ptr2)
bne .1
2022-08-20 14:37:37 +00:00
ldy #1
lda (ZS.RT.Ptr2),y
inc
sta (ZS.RT.Ptr2),y
.1
2022-08-20 14:37:37 +00:00
PCC.Inc2.L .EQ *-PCC.Inc2
*--------------------------------------
PCC.Inc4 .DA #PCC.Inc4.L
lda (ZS.RT.Ptr2)
inc
sta (ZS.RT.Ptr2)
bne .2
2022-08-20 14:37:37 +00:00
ldy #1
.1 lda (ZS.RT.Ptr2),y
inc
sta (ZS.RT.Ptr2),y
beq .2
2022-08-20 14:37:37 +00:00
iny
cpy #4
bne .1
.2
2022-08-20 14:37:37 +00:00
PCC.Inc4.L .EQ *-PCC.Inc4
*--------------------------------------
PCC.Dec1 .DA #PCC.Dec1.L
lda (ZS.RT.Ptr2)
dec
sta (ZS.RT.Ptr2)
PCC.Dec1.L .EQ *-PCC.Dec1
*--------------------------------------
PCC.Dec2 .DA #PCC.Dec2.L
lda (ZS.RT.Ptr2)
php
dec
sta (ZS.RT.Ptr2)
plp
bne .1
2022-08-20 14:37:37 +00:00
ldy #1
lda (ZS.RT.Ptr2),y
dec
sta (ZS.RT.Ptr2),y
.1
2022-08-20 14:37:37 +00:00
PCC.Dec2.L .EQ *-PCC.Dec2
*--------------------------------------
PCC.Dec4 .DA #PCC.Dec4.L
lda (ZS.RT.Ptr2)
clc
sbc #0
sta (ZS.RT.Ptr2)
bcs .2
2022-08-20 14:37:37 +00:00
ldy #1
.1 lda (ZS.RT.Ptr2),y
sbc #0
sta (ZS.RT.Ptr2),y
bcs .2
2022-08-20 14:37:37 +00:00
iny
cpy #4
bne .1
.2
2022-08-20 14:37:37 +00:00
PCC.Dec4.L .EQ *-PCC.Dec4
*--------------------------------------
PCC.BOPS.bMUL .DA #PCC.BOPS.bMUL.L
ldx #0 result
>PULLA
tay b2
.1 tya
beq .8
lsr
tay
bcc .2
clc
txa
adc (pStack) b1
tax
.2 lda (pStack) b1*2
asl
sta (pStack)
bne .1
.8 txa
sta (pStack)
PCC.BOPS.bMUL.L .EQ *-PCC.BOPS.bMUL
2022-08-20 14:37:37 +00:00
*--------------------------------------
PCC.BOPS.cMUL
*--------------------------------------
PCC.BOPS.bDIV
*--------------------------------------
PCC.BOPS.cDIV
*--------------------------------------
PCC.BOPS.bMOD
*--------------------------------------
PCC.BOPS.cMOD
*--------------------------------------
PCC.BOPS.ADD .DA #PCC.BOPS.ADD.L
clc
>PULLA
adc (pStack)
sta (pStack)
PCC.BOPS.ADD.L .EQ *-PCC.BOPS.ADD
*--------------------------------------
PCC.BOPS.SUB .DA #PCC.BOPS.SUB.L
sec
ldy #1
lda (pStack),y
sbc (pStack)
sta (pStack),y
inc pStack
PCC.BOPS.SUB.L .EQ *-PCC.BOPS.SUB
2022-08-20 14:37:37 +00:00
*--------------------------------------
PCC.BOPS.SHL .DA #PCC.BOPS.SHL.L
>PULLA
tax
beq .8
2022-08-20 14:37:37 +00:00
lda (pStack)
.1 asl
dex
bne .1
2022-08-20 14:37:37 +00:00
sta (pStack)
2022-08-20 14:37:37 +00:00
.8
PCC.BOPS.SHL.L .EQ *-PCC.BOPS.SHL
2022-08-20 14:37:37 +00:00
*--------------------------------------
PCC.BOPS.SHR .DA #PCC.BOPS.SHR.L
>PULLA
tax
beq .8
2022-08-20 14:37:37 +00:00
lda (pStack)
.1 lsr
dex
bne .1
2022-08-20 14:37:37 +00:00
sta (pStack)
2022-08-20 14:37:37 +00:00
.8
PCC.BOPS.SHR.L .EQ *-PCC.BOPS.SHR
2022-08-20 14:37:37 +00:00
*--------------------------------------
PCC.BOPS.L .DA #PCC.BOPS.L.L
>PULLA
cmp (pStack)
bcc .8
lda #0
sta (pStack)
rts
2022-08-20 14:37:37 +00:00
.8 lda #1
sta (pStack)
PCC.BOPS.L.L .EQ *-PCC.BOPS.L
*--------------------------------------
PCC.BOPS.G .DA #PCC.BOPS.G.L
>PULLA
cmp (pStack)
beq .1
bcs .8
.1 lda #0
sta (pStack)
rts
2022-08-20 14:37:37 +00:00
.8 lda #1
sta (pStack)
PCC.BOPS.G.L .EQ *-PCC.BOPS.G
*--------------------------------------
PCC.BOPS.LE .DA #PCC.BOPS.LE.L
>PULLA
cmp (pStack)
bcc .8
beq .8
lda #0
sta (pStack)
rts
2022-08-20 14:37:37 +00:00
.8 lda #1
sta (pStack)
PCC.BOPS.LE.L .EQ *-PCC.BOPS.LE
*--------------------------------------
PCC.BOPS.GE .DA #PCC.BOPS.GE.L
>PULLA
cmp (pStack)
bcs .8
lda #0
sta (pStack)
rts
2022-08-20 14:37:37 +00:00
.8 lda #1
sta (pStack)
PCC.BOPS.GE.L .EQ *-PCC.BOPS.GE
*--------------------------------------
PCC.BOPS.EQ .DA #PCC.BOPS.EQ.L
>PULLA
cmp (pStack)
beq .1
2022-08-20 14:37:37 +00:00
lda #0
clc
2022-08-20 14:37:37 +00:00
.1 ror
sta (pStack)
PCC.BOPS.EQ.L .EQ *-PCC.BOPS.EQ
*--------------------------------------
PCC.BOPS.NE .DA #PCC.BOPS.NE.L
>PULLA
eor (pStack)
sta (pStack)
PCC.BOPS.NE.L .EQ *-PCC.BOPS.NE
*--------------------------------------
PCC.BOPS.LAND
2022-08-20 14:37:37 +00:00
*--------------------------------------
PCC.BOPS.AND .DA #PCC.BOPS.AND.L
>PULLA
and (pStack)
sta (pStack)
PCC.BOPS.AND.L .EQ *-PCC.BOPS.AND
*--------------------------------------
PCC.BOPS.LOR
2022-08-20 14:37:37 +00:00
*--------------------------------------
PCC.BOPS.OR .DA #PCC.BOPS.OR.L
>PULLA
ora (pStack)
sta (pStack)
PCC.BOPS.OR.L .EQ *-PCC.BOPS.OR
*--------------------------------------
PCC.BOPS.EOR .DA #PCC.BOPS.EOR.L
>PULLA
eor (pStack)
sta (pStack)
PCC.BOPS.EOR.L .EQ *-PCC.BOPS.EOR
*--------------------------------------
MAN
SAVE usr/src/bin/cc.s.pcc
LOAD usr/src/bin/cc.s
ASM