A2osX/BIN/TELNET.S.txt
2019-02-23 22:01:58 +00:00

329 lines
6.4 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
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF BIN/TELNET
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/ETH.I
.INB INC/LIBTCPIP.I
.INB INC/NET.TELNET.I
*--------------------------------------
TIMEOUT.MAX .EQ 40 4 sec.
BUFSIZE .EQ 256
*--------------------------------------
ZPIPCfgPtr .EQ ZPBIN
ZPBufPtr .EQ ZPBIN+2
ZPBufLen .EQ ZPBIN+4
*--------------------------------------
* 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 Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
.DA #16 SS
.DA #6 ZP
.DA 0
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP
L.SA.LOCAL .DA SA.LOCAL
L.SA.REMOTE .DA SA.REMOTE
L.SA.REMOTE.AD .DA SA.REMOTE+S.SOCKADDR.ADDR
L.MSG.IPKO .DA MSG.IPKO
L.MSG.USAGE .DA MSG.USAGE
L.MSG.UNKNOWN .DA MSG.UNKNOWN
L.MSG.HOSTOK .DA MSG.HOSTOK
L.MSG.SKTKO .DA MSG.SKTKO
L.MSG.SKTOK .DA MSG.SKTOK
L.MSG.SKTERR .DA MSG.SKTERR
L.MSG.IOERR .DA MSG.IOERR
L.MSG.USER .DA MSG.USER
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBTCPIP
>SYSCALL LoadLib
bcs .9
sta hLIBTCPIP
.9 rts
*--------------------------------------
CS.RUN >LIBCALL hLIBTCPIP,LIBTCPIP.GETCFG is TCPIP loaded ?
>STYA ZPIPCfgPtr
lda (ZPIPCfgPtr) Configured ?
bmi CS.RUN.IPOK
>LDYA L.MSG.IPKO
>SYSCALL puts
lda #E.SYN
sec
rts
CS.RUN.IPOK ldy #S.PS.ARGC
lda (pPs),y
cmp #1
bcc .9
ldy #S.IPCFG.IP+3
ldx #3
.1 lda (ZPIPCfgPtr),y
sta SA.LOCAL+S.SOCKADDR.ADDR,x
dey
dex
bpl .1
jsr Init.Timeout
.2 >PUSHW L.SA.REMOTE.AD
lda #1
>SYSCALL ArgV
>PUSHYA
>LIBCALL hLIBTCPIP,LIBTCPIP.HST.GETBYNAME
bcc CS.RUN.HOSTOK
>SLEEP
jsr Wait.Timeout
bcc .2
lda #1
>SYSCALL ArgV
>PUSHYA
>PUSHBI 2
>LDYA L.MSG.UNKNOWN
>SYSCALL printf
bra .99
.9 >LDYA L.MSG.USAGE
>SYSCALL puts
.99 lda #E.SYN
sec
rts
CS.RUN.HOSTOK lda #2
>SYSCALL ArgV
bcs CS.RUN.PORTOK
>SYSCALL atoi
>STYA SA.REMOTE+S.SOCKADDR.PORT
CS.RUN.PORTOK lda #1
>SYSCALL ArgV
>PUSHYA
>PUSHW SA.REMOTE+S.SOCKADDR.PORT
ldx #3
.1 >PUSHB SA.REMOTE+S.SOCKADDR.ADDR,x
dex
bpl .1
>PUSHBI 8
>LDYA L.MSG.HOSTOK
>SYSCALL printf
CS.RUN.OPENSKT >PUSHBI 0 no protocol
lda #S.SOCKET.T.STREAM
>LIBCALL hLIBTCPIP,LIBTCPIP.Socket
bcs .9
>STA.G hSocket
pha
>PUSHW L.SA.LOCAL
pla
>LIBCALL hLIBTCPIP,LIBTCPIP.Bind
bcc .2
.9 >LDYA L.MSG.SKTKO
>SYSCALL puts
lda #E.SYN
sec
rts
.2 >PUSHW L.SA.REMOTE
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Connect
bcs .9
>PUSHBI 0
>LDYA L.MSG.SKTOK
>SYSCALL printf
>LDYAI BUFSIZE
>SYSCALL getmem
bcs .9
>STYA ZPBufPtr
txa
>STA.G hBuf
CS.RUN.LOOP >SLEEP
>PUSHWI BUFSIZE
>PUSHW ZPBufPtr
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Read
bcc .1
tay
beq .2 no char
jmp CS.RUN.SKTERR
.1 >PUSHYA len
>PUSHW ZPBufPtr
ldy #S.PS.hStdOut
lda (pPs),y
>SYSCALL fwrite
bcs .11
.2 ldy #S.PS.hStdIn
lda (pPs),y
>SYSCALL feof
bcs CS.RUN.IOERR
tay
beq CS.RUN.LOOP no char from STDIN
>PUSHWI BUFSIZE
>PUSHW ZPBufPtr
ldy #S.PS.hStdIn
lda (pPs),y
>SYSCALL fread
.11 bcs CS.RUN.IOERR
.3 >STYA ZPBufLen
lda (ZPBufPtr)
cmp #$14 Ctrl-T
beq CS.RUN.USER
.4 >PUSHW ZPBufLen
>PUSHW ZPBufPtr
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Write
bcc .8
tay
bne CS.RUN.SKTERR
>SLEEP
bra .4
.8 jmp CS.RUN.LOOP
.9 lda #0
sec
rts
*--------------------------------------
CS.RUN.SKTERR pha
>PUSHA
>PUSHBI 1
>LDYA L.MSG.SKTERR
>SYSCALL printf
pla
sec
rts
*--------------------------------------
CS.RUN.IOERR pha
>PUSHA
>PUSHBI 1
>LDYA L.MSG.IOERR
>SYSCALL printf
pla
sec
rts
*--------------------------------------
CS.RUN.USER >LDYA L.MSG.USER
>SYSCALL puts
lda #0
sec
rts
*--------------------------------------
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 hSocket
beq .1
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
.1 >LDA.G hBuf
beq .2
>SYSCALL freemem
.2 lda hLIBTCPIP
beq .8
>SYSCALL UnloadLib
.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
LIBTCPIP .AZ "libtcpip"
hLIBTCPIP .BS 1
MSG.IPKO .AZ "TCP/IP Not Loaded/Configured."
MSG.USAGE .AZ "Usage : TELNET <ip|host> [port]"
MSG.UNKNOWN .AZ "%s: Unknown host\r\n"
MSG.HOSTOK .AZ "Connecting to %d.%d.%d.%d:%D (%s)..."
MSG.SKTKO .AZ "Failed to Open Socket."
MSG.SKTOK .AZ "Connected\r\n(Exit key is Ctrl-T)\r\n"
MSG.SKTERR .AZ "Socket Error : $%h\r\n"
MSG.IOERR .AZ "I/O Error : $%h\r\n"
MSG.USER .AZ "User interrupt."
*--------------------------------------
SA.LOCAL .DA #AF.INET S.SOCKADDR.AF
.BS 1
.BS 4 S.SOCKADDR.ADDR
.BS 2 S.SOCKADDR.PORT
*--------------------------------------
SA.REMOTE .DA #AF.INET S.SOCKADDR.AF
.BS 1
.BS 4 S.SOCKADDR.ADDR
.DA TCP.PORT.TELNET
*--------------------------------------
.DUMMY
.OR 0
DS.START
hBuf .BS 1
hSocket .BS 1
TimeOut .BS 1
DS.END
.ED
*--------------------------------------
MAN
SAVE USR/SRC/BIN/TELNET.S
ASM