A2osX/BIN/TERM.S.txt
2020-08-25 12:56:00 +02:00

169 lines
3.0 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
.TF bin/term
*--------------------------------------
.INB inc/macros.i
.INB inc/a2osx.i
*--------------------------------------
TIMEOUT.MAX .EQ 200 20 sec.
BUFSIZE .EQ 256
*--------------------------------------
.DUMMY
.OR ZPBIN
ZS.START
ZPBufPtr .BS 2
ZPBufLen .BS 2
hBuf .BS 1
hDev .BS 1
TimeOut .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 #S.PS.F.EVENT S.PS.F
.DA #0
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data Segment Size
.DA #32 Stack Size
.DA #ZS.END-ZS.START Zero Page Size
.DA 0
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.DEVOK .DA MSG.DEVOK
.DA 0
*--------------------------------------
CS.INIT clc
rts
*--------------------------------------
CS.RUN lda #1
>SYSCALL ArgV
bcs .9
>PUSHYA
>PUSHBI O.RDWR
>PUSHBI 0 type
>PUSHWZ auxtype
>SYSCALL FOpen
bcs .99
stx hDev
>LDYA L.MSG.DEVOK
>SYSCALL PutS
>LDYAI BUFSIZE
>SYSCALL GetMem
bcs .99
>STYA ZPBufPtr
stx hBuf
bra CS.RUN.LOOP
.9 >LDYA L.MSG.USAGE
>SYSCALL PutS
lda #E.SYN
sec
.99 rts
CS.RUN.LOOP >SLEEP
lda hDev
>SYSCALL FEOF
bcs .99
tay
bne .2 EOF, no char
>PUSHWI BUFSIZE
>PUSHW ZPBufPtr
lda hDev
>SYSCALL FRead
bcc .1
.99 rts
.1 >PUSHYA len
>PUSHW ZPBufPtr
ldy #S.PS.hStdOut
lda (pPS),y
>SYSCALL FWrite
bcs .9
.2 ldy #S.PS.hStdIn
lda (pPS),y
>SYSCALL FEOF
bcs .9
tay
bne CS.RUN.LOOP EOF = true, no char from STDIN
>PUSHWI BUFSIZE
>PUSHW ZPBufPtr
ldy #S.PS.hStdIn
lda (pPS),y
>SYSCALL FRead
.3 bcs .9
>STYA ZPBufLen
lda (ZPBufPtr)
cmp #$14 Ctrl-T
beq .9
>PUSHW ZPBufLen
>PUSHW ZPBufPtr
lda hDev
>SYSCALL FWrite
bcs .9
jmp CS.RUN.LOOP
.9 rts
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
lda TimeOut
beq .9
dec TimeOut
.9 sec do not discard TIMER event
rts
*--------------------------------------
CS.QUIT lda hDev
beq .1
>SYSCALL FClose
.1 lda hBuf
beq .2
>SYSCALL FreeMem
.2 clc
rts
*--------------------------------------
CS.END
MSG.USAGE .AZ "Usage : TERM device "
MSG.DEVOK .AZ "Connected (Exit key is Ctrl-T)"
*--------------------------------------
.DUMMY
.OR 0
DS.START
DS.END
.ED
*--------------------------------------
MAN
SAVE usr/src/bin/term.s
ASM