A2osX/BIN/TERM.S.txt

169 lines
3.0 KiB
Plaintext
Raw Normal View History

2019-11-06 13:14:42 +00:00
NEW
AUTO 3,1
.LIST OFF
.OP 65C02
.OR $2000
2020-02-24 13:33:28 +00:00
.TF bin/term
2019-11-06 13:14:42 +00:00
*--------------------------------------
2020-05-25 21:03:11 +00:00
.INB inc/macros.i
.INB inc/a2osx.i
2019-11-06 13:14:42 +00:00
*--------------------------------------
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
2020-02-24 13:33:28 +00:00
>PUSHYA
2019-11-06 13:14:42 +00:00
>PUSHBI O.RDWR
2020-02-24 13:33:28 +00:00
>PUSHBI 0 type
>PUSHWZ auxtype
2020-03-09 16:24:08 +00:00
>SYSCALL FOpen
2019-11-06 13:14:42 +00:00
bcs .99
stx hDev
>LDYA L.MSG.DEVOK
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2019-11-06 13:14:42 +00:00
>LDYAI BUFSIZE
2020-02-28 07:21:46 +00:00
>SYSCALL GetMem
2019-11-06 13:14:42 +00:00
bcs .99
>STYA ZPBufPtr
stx hBuf
bra CS.RUN.LOOP
.9 >LDYA L.MSG.USAGE
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2019-11-06 13:14:42 +00:00
lda #E.SYN
sec
.99 rts
CS.RUN.LOOP >SLEEP
lda hDev
2020-08-25 10:56:00 +00:00
>SYSCALL FEOF
2019-11-06 13:14:42 +00:00
bcs .99
tay
bne .2 EOF, no char
>PUSHWI BUFSIZE
>PUSHW ZPBufPtr
lda hDev
2020-08-25 10:56:00 +00:00
>SYSCALL FRead
2019-11-06 13:14:42 +00:00
bcc .1
.99 rts
.1 >PUSHYA len
>PUSHW ZPBufPtr
ldy #S.PS.hStdOut
2020-02-28 07:21:46 +00:00
lda (pPS),y
2020-08-25 10:56:00 +00:00
>SYSCALL FWrite
2019-11-06 13:14:42 +00:00
bcs .9
.2 ldy #S.PS.hStdIn
2020-02-28 07:21:46 +00:00
lda (pPS),y
2019-11-06 13:14:42 +00:00
2020-08-25 10:56:00 +00:00
>SYSCALL FEOF
2019-11-06 13:14:42 +00:00
bcs .9
tay
bne CS.RUN.LOOP EOF = true, no char from STDIN
>PUSHWI BUFSIZE
>PUSHW ZPBufPtr
ldy #S.PS.hStdIn
2020-02-28 07:21:46 +00:00
lda (pPS),y
2020-08-25 10:56:00 +00:00
>SYSCALL FRead
2019-11-06 13:14:42 +00:00
.3 bcs .9
>STYA ZPBufLen
lda (ZPBufPtr)
cmp #$14 Ctrl-T
beq .9
>PUSHW ZPBufLen
>PUSHW ZPBufPtr
lda hDev
2020-08-25 10:56:00 +00:00
>SYSCALL FWrite
2019-11-06 13:14:42 +00:00
bcs .9
jmp CS.RUN.LOOP
.9 rts
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
2020-05-25 21:03:11 +00:00
2019-11-06 13:14:42 +00:00
lda TimeOut
beq .9
2020-05-25 21:03:11 +00:00
2019-11-06 13:14:42 +00:00
dec TimeOut
.9 sec do not discard TIMER event
rts
*--------------------------------------
CS.QUIT lda hDev
beq .1
2020-02-28 07:21:46 +00:00
>SYSCALL FClose
2019-11-06 13:14:42 +00:00
.1 lda hBuf
beq .2
2020-02-28 07:21:46 +00:00
>SYSCALL FreeMem
2019-11-06 13:14:42 +00:00
.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
2020-05-25 21:03:11 +00:00
SAVE usr/src/bin/term.s
2019-11-06 13:14:42 +00:00
ASM