A2osX/SBIN/GETTY.S.txt
2018-09-12 17:27:00 +02:00

250 lines
4.7 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
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF SBIN/GETTY
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/NET.TELNET.I
*--------------------------------------
TIMEOUT.MAX .EQ 100 10 sec.
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
.DA 0
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #64 SS
.DA #0 ZP
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.MSG.USAGE .DA MSG.USAGE
L.MSG.GREETINGS .DA MSG.GREETINGS
L.TELNETOPTS .DA TELNETOPTS
L.ENV.TERM .DA ENV.TERM
.DA 0 End Of Reloc Table
*--------------------------------------
CS.INIT ldy #S.PS.ARGC
lda (pPs),y
cmp #2
bne .90
>PUSHBI 0
lda #1
>SYSCALL GetArg get /dev/xxx
>SYSCALL open
bcs .9
ldy #S.PS.hStdIn
sta (pPs),y
iny #S.PS.hStdOut
sta (pPs),y
iny #S.PS.hStdErr
sta (pPs),y
>STA.G hDEV
lda #2
>SYSCALL GetArg
bcs .9
lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
rts
.90 >LDYA L.MSG.USAGE
>SYSCALL puts
lda #0
sec
.9 rts
*--------------------------------------
CS.RUN >PUSHWI TELNETOPTS.LEN
>PUSHW L.TELNETOPTS
ldy #S.PS.hStdOut
lda (pPs),y
>SYSCALL write
bcs CS.RUN.8
>PUSHWI K.VER
>PUSHBI 2
>LDYA L.MSG.GREETINGS
>SYSCALL printf
bcs CS.RUN.8 unable to send greetings...reset..
jsr Init.Timeout
CS.RUN.LOOP
* >SLEEP
*.1 >SYSCALL GetChar
* bcs .2
* cmp #IAC
* beq CS.RUN.IACMODE
*.2 jsr Wait.Timeout
* bcc .1
lda #2
>SYSCALL GetArg
>SYSCALL ExecPS
rts
CS.RUN.8 clc
rts
*--------------------------------------
CS.RUN.IACMODE >SLEEP Wait for IAC VERB (or SB)
>SYSCALL GetChar
bcs CS.RUN.IACMODE
>STA.G IAC.VERB
.1 >SLEEP Wait for IAC OPT
>SYSCALL GetChar
bcs .1
>STA.G IAC.OPT
>LDA.G IAC.VERB
cmp #SB
beq CS.RUN.IACSB
*--------------------------------------
CS.RUN.IACVERB
jmp CS.RUN.LOOP
*--------------------------------------
CS.RUN.IACSB
.1 >SLEEP
>SYSCALL GetChar
bcs .1
>STA.G IAC.SB
lda #0
sta (pData) reset IAC.SB.DATA
.2 >SLEEP
>SYSCALL GetChar
bcs .2
cmp #IAC
beq .4 end of DATA, go wait SE
pha
ldy #IAC.SB.DATA-1
.3 iny
lda (pData),y
bne .3
pla
sta (pData),y
iny
lda #0
sta (pData),y
bra .2
.4 >SLEEP
>SYSCALL GetChar
bcs .4
cmp #SE
bne .8
>LDA.G IAC.OPT
cmp #TELOPT.TTYPE
bne .8
>LDA.G IAC.SB
cmp #SB.IS
bne .8
>PUSHEA.G IAC.SB.DATA
>LDYA L.ENV.TERM
>SYSCALL SetEnv
.8 jmp CS.RUN.LOOP
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
>LDA.G TimeOut
beq .9
dec
sta (pData),y
.9 sec do not discard TIMER event
rts
*--------------------------------------
CS.QUIT >LDA.G hDEV
beq .8
>SYSCALL close
.8 clc
rts
*--------------------------------------
Init.Timeout lda #TIMEOUT.MAX
>STA.G TimeOut
rts
*--------------------------------------
Wait.TimeOut sec
>LDA.G TimeOut
beq .9
clc
.9 rts
*--------------------------------------
CS.END
MSG.USAGE .AZ "Usage : GETTY <DEV> <PROGRAM>"
MSG.GREETINGS .AZ "\r\nA2osX-GeTTY %d.%d\r\n"
*--------------------------------------
TELNETOPTS .DA #IAC,#WILL,#TELOPT.BINARY
.DA #IAC,#WILL,#TELOPT.ECHO
* .DA #IAC,#DONT,#TELOPT.ECHO
.DA #IAC,#WILL,#TELOPT.SGA
.DA #IAC,#DO,#TELOPT.SGA
.DA #IAC,#DO,#TELOPT.NAWS
.DA #IAC,#DO,#TELOPT.TTYPE
.DA #IAC,#DONT,#TELOPT.LINEMODE
* .DA #IAC,#SB,#TELOPT.LINEMODE,#SB.SEND,#0,#IAC,#SE
* .DA #IAC,#SB,#TELOPT.TTYPE,#SB.SEND,#IAC,#SE
TELNETOPTS.LEN .EQ *-TELNETOPTS
ENV.TERM .AZ "TERM"
*--------------------------------------
.DUMMY
.OR 0
DS.START
IAC.SB.DATA .BS 64
IAC.VERB .BS 1
IAC.OPT .BS 1
IAC.SB .BS 1
hDEV .BS 1
TimeOut .BS 1
DS.END .ED
MAN
SAVE /A2OSX.SRC/SBIN/GETTY.S
ASM