A2osX/BIN/FORTH.S.CP.txt

467 lines
7.8 KiB
Plaintext
Raw Normal View History

2020-11-25 09:36:30 +00:00
NEW
AUTO 3,1
*--------------------------------------
2021-04-30 15:25:19 +00:00
CP.JSRX lda #$20 JSR
jsr CP.Emit.Byte
lda I.KEYWORDS,x
jsr CP.Emit.Byte
lda I.KEYWORDS+1,x
jmp CP.Emit.Byte
*--------------------------------------
CP.ECOLON lda #$60 RTS
jsr CP.Emit.Byte
stz bCompile
2020-12-02 15:22:57 +00:00
2021-04-30 15:25:19 +00:00
clc
rts
*--------------------------------------
CP.INVALID lda #E.CSYN
sec
rts
*--------------------------------------
* : TEST ." hello" CR ;
*--------------------------------------
CP.PRINT ldy #$ff
.1 iny
lda (ZPCLBufPtr),y
beq CP.INVALID
cmp #'"'
beq .2
sta (ZPDataPtr),y
bra .1
.2 lda #0
sta (ZPDataPtr),y
phy
>LDYA ZPDataPtr
jsr CP.Emit.LDYAI
ldx #SYS.PutS
jsr CP.Emit.SYSCALL
2020-11-26 19:47:57 +00:00
2021-04-30 15:25:19 +00:00
pla
pha
sec skip "
adc ZPCLBufPtr
sta ZPCLBufPtr
bcc .3
inc ZPCLBufPtr+1
.3 pla
2021-05-19 12:44:47 +00:00
sec include \0
2021-04-30 15:25:19 +00:00
adc ZPDataPtr
sta ZPDataPtr
bcc .4
inc ZPDataPtr+1
2020-11-26 19:47:57 +00:00
2021-04-30 15:25:19 +00:00
.4
clc
rts
2020-11-26 19:47:57 +00:00
*--------------------------------------
2020-12-23 14:54:57 +00:00
CP.DO jsr CP.Emit.DO I,n -> RP
2021-04-11 19:47:48 +00:00
2020-12-23 14:54:57 +00:00
ldy RP
lda ZPCodePtr+1
sta (pData),y
dey
lda ZPCodePtr
sta (pData),y
dey push CodePtr=DOTEST on RP for LOOP/LEAVE
sty RP
jsr CP.Emit.DOTEST CODE: I < n ?
ldx #KW.DO.ID
jsr CP.Emit.JMP0000 to put jmp LOOPEND
2020-12-02 15:22:57 +00:00
clc
rts
2020-11-26 19:47:57 +00:00
*--------------------------------------
2020-12-17 20:23:54 +00:00
CP.LOOP lda #$00
jsr CP.Emit.PUSHBI >PUSHBI 0
lda #$01 >PUSHBI 1
jsr CP.Emit.PUSHBI
2020-12-02 15:22:57 +00:00
*--------------------------------------
2020-12-23 14:54:57 +00:00
CP.pLOOP ldy RP
iny
bmi .9
lda (pData),y
cmp #KW.DO.ID
bne .9
phy
jsr CP.Emit.LOOP CODE: I=I+n
ply
iny POP LOOPEND@ -> Ptr1
lda (pData),y
sta ZPPtr1
2020-12-17 20:23:54 +00:00
2020-12-23 14:54:57 +00:00
iny
lda (pData),y
sta ZPPtr1+1
jsr CP.Emit.JMPBack CODE: JMP to DOTEST
sty RP discard ID DOTEST@ LOOPEND@
jsr CP.UpdatePtr1 update JMP LOOPEND@ with CodePtr
jsr CP.Emit.LOOPEND
2020-12-17 20:23:54 +00:00
2020-12-02 15:22:57 +00:00
clc
rts
2020-12-23 14:54:57 +00:00
.9 lda #E.NODO
sec
rts
2020-11-26 19:47:57 +00:00
*--------------------------------------
2020-12-17 20:23:54 +00:00
CP.I jsr CP.Emit.I
2020-12-02 15:22:57 +00:00
clc
2020-12-17 20:23:54 +00:00
rts
2020-11-26 19:47:57 +00:00
*--------------------------------------
2020-12-23 14:54:57 +00:00
CP.LEAVE ldy RP
2021-04-11 19:47:48 +00:00
2020-12-23 14:54:57 +00:00
.1 iny
bmi .9
2020-11-26 19:47:57 +00:00
2020-12-23 14:54:57 +00:00
lda (pData),y
cmp #KW.DO.ID
beq .2
iny
iny
bpl .1 skip 3 bytes on RP
.9 lda #E.NODO
sec
rts
.2 phy
jsr CP.Emit.LEAVE set I = END on RP
ply
iny skip LOOPEND ptr
iny
jsr CP.Emit.JMPBack jmp DOTEST
2020-11-26 19:47:57 +00:00
clc
rts
2020-11-25 09:36:30 +00:00
*--------------------------------------
2020-12-02 15:22:57 +00:00
CP.IF jsr CP.Emit.TESTTRUE
2020-12-23 14:54:57 +00:00
ldx #KW.IF.ID
2021-04-29 11:56:34 +00:00
jsr CP.Emit.JMP0000 to put jmp -> ELSE/THEN later
2020-11-26 19:47:57 +00:00
2020-11-27 16:37:47 +00:00
clc
rts
*--------------------------------------
2020-12-23 14:54:57 +00:00
CP.ELSE jsr CP.PopCodePtr get previous JMP -> ptr1
ldx #KW.IF.ID
2021-04-29 11:56:34 +00:00
jsr CP.Emit.JMP0000 to put jmp -> THEN later
2020-11-29 13:16:39 +00:00
jsr CP.UpdatePtr1
2020-11-25 16:29:06 +00:00
clc
rts
2020-11-25 09:36:30 +00:00
*--------------------------------------
2021-04-29 11:56:34 +00:00
CP.THEN jsr CP.PopCodePtr
2020-11-29 13:16:39 +00:00
jsr CP.UpdatePtr1
2020-11-26 19:47:57 +00:00
2020-11-25 16:29:06 +00:00
clc
rts
2020-11-25 09:36:30 +00:00
*--------------------------------------
2020-12-23 14:54:57 +00:00
CP.BEGIN jsr CP.PushCodePtr X = BEGIN ID
2020-11-29 13:16:39 +00:00
clc
rts
2020-11-26 19:47:57 +00:00
*--------------------------------------
2020-12-02 15:22:57 +00:00
CP.UNTIL jsr CP.Emit.TESTFALSE
2020-11-29 13:16:39 +00:00
2020-12-23 14:54:57 +00:00
bra CP.WHILE.1
2020-11-26 19:47:57 +00:00
*--------------------------------------
2020-12-23 14:54:57 +00:00
CP.REPEAT ldy RP
iny
bmi CP.E.NOBEGIN
jsr CP.Emit.JMPBack
2020-11-26 19:47:57 +00:00
2020-11-29 13:16:39 +00:00
clc
rts
2020-11-26 19:47:57 +00:00
*--------------------------------------
2020-12-02 15:22:57 +00:00
CP.WHILE jsr CP.Emit.TESTTRUE
2020-12-23 14:54:57 +00:00
CP.WHILE.1 ldy RP
iny
bmi CP.E.NOBEGIN
2020-12-02 15:22:57 +00:00
jsr CP.Emit.JMPBack
jsr CP.Emit.RPDROP2
2020-11-27 16:37:47 +00:00
2020-12-17 20:23:54 +00:00
clc
2020-11-29 13:16:39 +00:00
rts
*--------------------------------------
2020-12-23 14:54:57 +00:00
CP.E.NOBEGIN lda #E.NOFOR
sec
rts
*--------------------------------------
2021-04-29 11:56:34 +00:00
KW.gR
*--------------------------------------
KW.Rg
*--------------------------------------
KW.R
lda #E.SYN
sec
rts
*--------------------------------------
2020-12-02 15:22:57 +00:00
CP.Emit.JMP0000 lda #$4C JMP
jsr CP.Emit.Byte
2020-11-27 16:37:47 +00:00
jsr CP.PushCodePtr
lda #0
2020-12-02 15:22:57 +00:00
jsr CP.Emit.Byte
jsr CP.Emit.Byte
2020-11-27 16:37:47 +00:00
rts
*--------------------------------------
2020-12-02 15:22:57 +00:00
CP.Emit.JMPBack lda #$4C JMP
jsr CP.Emit.Byte
2020-12-23 14:54:57 +00:00
2020-12-02 15:22:57 +00:00
iny
lda (pData),y
jsr CP.Emit.Byte
2020-12-17 20:23:54 +00:00
2020-12-02 15:22:57 +00:00
iny
lda (pData),y
jmp CP.Emit.Byte
*--------------------------------------
CP.Emit.RPDROP2 ldx #CODE.RPDROP2.L
ldy #0
2020-11-29 13:16:39 +00:00
2020-12-02 15:22:57 +00:00
.1 lda CODE.RPDROP2,y
jsr CP.Emit.Byte
iny
dex
bne .1
2020-11-29 13:16:39 +00:00
rts
*--------------------------------------
2020-12-02 15:22:57 +00:00
CP.Emit.TESTTRUE
ldx #CODE.TESTTRUE.L
ldy #0
2020-11-26 19:47:57 +00:00
2020-12-02 15:22:57 +00:00
.1 lda CODE.TESTTRUE,y
jsr CP.Emit.Byte
iny
dex
bne .1
2020-12-17 20:23:54 +00:00
2020-12-02 15:22:57 +00:00
rts
2020-11-26 19:47:57 +00:00
*--------------------------------------
2020-12-02 15:22:57 +00:00
CP.Emit.TESTFALSE
ldx #CODE.TESTFALSE.L
ldy #0
2020-11-26 19:47:57 +00:00
2020-12-02 15:22:57 +00:00
.1 lda CODE.TESTFALSE,y
jsr CP.Emit.Byte
iny
dex
bne .1
2020-12-17 20:23:54 +00:00
2020-12-02 15:22:57 +00:00
rts
*--------------------------------------
CP.Emit.PULLA ldx #CODE.PULLA.L
ldy #0
2020-11-26 19:47:57 +00:00
2020-12-02 15:22:57 +00:00
.1 lda CODE.PULLA,y
jsr CP.Emit.Byte
iny
dex
bne .1
2020-12-17 20:23:54 +00:00
2020-12-02 15:22:57 +00:00
rts
*--------------------------------------
2020-12-17 20:23:54 +00:00
CP.Emit.PUSHBI pha
lda #$A9 lda #imm
jsr CP.Emit.Byte
pla
jsr CP.Emit.Byte
*--------------------------------------
2020-12-02 15:22:57 +00:00
CP.Emit.PUSHA ldx #CODE.PUSHA.L
ldy #0
2020-11-26 19:47:57 +00:00
2020-12-02 15:22:57 +00:00
.1 lda CODE.PUSHA,y
jsr CP.Emit.Byte
iny
dex
bne .1
2020-12-17 20:23:54 +00:00
rts
*--------------------------------------
CP.Emit.DO ldx #CODE.DO.L
ldy #0
.1 lda CODE.DO,y
jsr CP.Emit.Byte
iny
dex
bne .1
2020-12-02 15:22:57 +00:00
rts
*--------------------------------------
2020-12-23 14:54:57 +00:00
CP.Emit.DOTEST ldx #CODE.DOTEST.L
ldy #0
.1 lda CODE.DOTEST,y
jsr CP.Emit.Byte
iny
dex
bne .1
rts
*--------------------------------------
2020-12-02 15:22:57 +00:00
CP.Emit.LOOP ldx #CODE.LOOP.L
ldy #0
2020-11-26 19:47:57 +00:00
2020-12-02 15:22:57 +00:00
.1 lda CODE.LOOP,y
jsr CP.Emit.Byte
iny
dex
bne .1
2020-12-17 20:23:54 +00:00
2020-12-02 15:22:57 +00:00
rts
*--------------------------------------
CP.Emit.LOOPEND ldx #CODE.LOOPEND.L
ldy #0
2020-11-26 19:47:57 +00:00
2020-12-02 15:22:57 +00:00
.1 lda CODE.LOOPEND,y
jsr CP.Emit.Byte
iny
dex
bne .1
2020-12-17 20:23:54 +00:00
rts
*--------------------------------------
CP.Emit.I ldx #CODE.I.L
ldy #0
.1 lda CODE.I,y
jsr CP.Emit.Byte
iny
dex
bne .1
rts
*--------------------------------------
CP.Emit.LEAVE ldx #CODE.LEAVE.L
ldy #0
.1 lda CODE.LEAVE,y
jsr CP.Emit.Byte
iny
dex
bne .1
2020-12-02 15:22:57 +00:00
rts
2020-11-26 19:47:57 +00:00
*--------------------------------------
2021-04-30 15:25:19 +00:00
CP.Emit.LDYAI pha
lda #$A0 LDY #imm
jsr CP.Emit.Byte
tya
jsr CP.Emit.Byte
lda #$A9 LDA #imm
jsr CP.Emit.Byte
pla
jmp CP.Emit.Byte
*--------------------------------------
CP.Emit.SYSCALL lda #$A2 LDX #imm
jsr CP.Emit.Byte
txa
jsr CP.Emit.Byte
lda #$20 JSR
jsr CP.Emit.Byte
lda #A2osX.SYSCALL
jsr CP.Emit.Byte
lda /A2osX.SYSCALL
jmp CP.Emit.Byte
*--------------------------------------
2020-12-02 15:22:57 +00:00
CP.Emit.JsrYA pha
2020-11-26 19:47:57 +00:00
lda #$20
2020-12-02 15:22:57 +00:00
jsr CP.Emit.Byte
2020-11-26 19:47:57 +00:00
tya
2020-12-02 15:22:57 +00:00
jsr CP.Emit.Byte
2020-11-26 19:47:57 +00:00
pla
*--------------------------------------
2020-12-02 15:22:57 +00:00
CP.Emit.Byte sta (ZPCodePtr)
2020-11-26 19:47:57 +00:00
inc ZPCodePtr
bne .8
inc ZPCodePtr+1
.8 rts
*--------------------------------------
2020-12-17 20:23:54 +00:00
CP.PushCodePtr ldy RP
lda ZPCodePtr+1
sta (pData),y
dey
lda ZPCodePtr
sta (pData),y
dey
2020-12-23 14:54:57 +00:00
txa
sta (pData),y
dey
2020-12-17 20:23:54 +00:00
sty RP
rts
*--------------------------------------
2020-12-23 14:54:57 +00:00
CP.PopCodePtr ldy RP
iny
lda (pData),y
cmp #KW.IF.ID
bne .9
2020-12-17 20:23:54 +00:00
iny
lda (pData),y
sta ZPPtr1
iny
lda (pData),y
sta ZPPtr1+1
sty RP
2020-12-23 14:54:57 +00:00
clc
rts
.9 lda #E.NOIF
sec
2020-12-17 20:23:54 +00:00
rts
*--------------------------------------
CP.UpdatePtr1 lda ZPCodePtr
sta (ZPPtr1)
ldy #1
lda ZPCodePtr+1
sta (ZPPtr1),y
rts
*--------------------------------------
2020-11-25 09:36:30 +00:00
MAN
SAVE usr/src/bin/forth.s.cp
LOAD usr/src/bin/forth.s
ASM