A2osX/BIN/TELNET.S.txt

327 lines
6.3 KiB
Plaintext
Raw Normal View History

2018-07-24 16:00:24 +00:00
NEW
2019-05-02 09:52:32 +00:00
AUTO 3,1
2018-07-24 16:00:24 +00:00
.LIST OFF
.OP 65C02
.OR $2000
2020-05-04 20:46:21 +00:00
.TF bin/telnet
2018-07-24 16:00:24 +00:00
*--------------------------------------
2020-08-17 20:47:31 +00:00
.INB inc/macros.i
.INB inc/a2osx.i
.INB inc/eth.i
.INB inc/libtcpip.i
.INB inc/net.telnet.i
2018-07-24 16:00:24 +00:00
*--------------------------------------
2019-10-05 17:24:41 +00:00
TIMEOUT.MAX .EQ 200 20 sec.
2018-08-27 15:26:01 +00:00
BUFSIZE .EQ 256
2018-07-24 16:00:24 +00:00
*--------------------------------------
2019-05-05 17:15:37 +00:00
.DUMMY
.OR ZPBIN
ZS.START
ZPIPCfgPtr .BS 2
ZPBufPtr .BS 2
ZPBufLen .BS 2
hBuf .BS 1
hSocket .BS 1
TimeOut .BS 1
2020-08-17 20:47:31 +00:00
ZS.END .ED
2018-07-24 16:00:24 +00:00
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
2018-09-19 15:25:42 +00:00
.DA #S.PS.F.EVENT S.PS.F
.DA #0
2019-05-05 17:15:37 +00:00
.DA CS.END-CS.START Code Size (without Constants)
.DA DS.END-DS.START Data Segment Size
.DA #64 Stack Size
.DA #ZS.END-ZS.START Zero Page Size
2018-07-24 16:00:24 +00:00
.DA 0
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP
2018-10-10 15:39:22 +00:00
L.SA.LOCAL .DA SA.LOCAL
L.SA.REMOTE .DA SA.REMOTE
L.SA.REMOTE.AD .DA SA.REMOTE+S.SOCKADDR.ADDR
2018-07-24 16:00:24 +00:00
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
2018-08-27 15:26:01 +00:00
L.MSG.SKTOK .DA MSG.SKTOK
2018-09-03 06:01:07 +00:00
L.MSG.SKTERR .DA MSG.SKTERR
2018-09-09 08:11:42 +00:00
L.MSG.IOERR .DA MSG.IOERR
L.MSG.USER .DA MSG.USER
2018-07-24 16:00:24 +00:00
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBTCPIP
>SYSCALL LoadLib
bcs .9
sta hLIBTCPIP
.9 rts
*--------------------------------------
2019-01-16 21:51:57 +00:00
CS.RUN >LIBCALL hLIBTCPIP,LIBTCPIP.GETCFG is TCPIP loaded ?
2018-07-24 16:00:24 +00:00
>STYA ZPIPCfgPtr
lda (ZPIPCfgPtr) Configured ?
bmi CS.RUN.IPOK
2019-10-05 17:24:41 +00:00
2018-07-24 16:00:24 +00:00
>LDYA L.MSG.IPKO
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2018-10-21 20:54:07 +00:00
lda #E.SYN
2019-10-03 06:25:27 +00:00
sec
2018-07-24 16:00:24 +00:00
rts
2019-10-05 17:24:41 +00:00
2018-07-24 16:00:24 +00:00
CS.RUN.IPOK ldy #S.PS.ARGC
2020-02-28 07:21:46 +00:00
lda (pPS),y
2018-11-23 16:20:19 +00:00
cmp #1
2018-11-01 08:53:47 +00:00
bcc .9
ldy #S.IPCFG.IP+3
ldx #3
.1 lda (ZPIPCfgPtr),y
sta SA.LOCAL+S.SOCKADDR.ADDR,x
dey
dex
bpl .1
2019-10-05 17:24:41 +00:00
2019-05-05 17:15:37 +00:00
lda #TIMEOUT.MAX
sta TimeOut
2018-07-24 16:00:24 +00:00
2019-10-05 17:24:41 +00:00
.2 >SLEEP
>PUSHW L.SA.REMOTE.AD
2018-07-24 16:00:24 +00:00
lda #1
2018-10-16 15:48:03 +00:00
>SYSCALL ArgV
2018-07-24 16:00:24 +00:00
>PUSHYA
2020-08-17 20:47:31 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.HST.GetByName
2018-09-05 06:18:50 +00:00
bcc CS.RUN.HOSTOK
2020-08-17 20:47:31 +00:00
lda TimeOut
2019-05-05 17:15:37 +00:00
bne .2
2018-07-24 16:00:24 +00:00
2020-05-04 20:46:21 +00:00
>PUSHW L.MSG.UNKNOWN
2018-07-24 16:00:24 +00:00
lda #1
2018-10-16 15:48:03 +00:00
>SYSCALL ArgV
2018-07-24 16:00:24 +00:00
>PUSHYA
2018-09-05 06:18:50 +00:00
>PUSHBI 2
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2018-07-24 16:00:24 +00:00
bra .99
2019-10-05 17:24:41 +00:00
2018-07-24 16:00:24 +00:00
.9 >LDYA L.MSG.USAGE
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2018-08-27 15:26:01 +00:00
2018-10-21 20:54:07 +00:00
.99 lda #E.SYN
2019-10-03 06:25:27 +00:00
sec
2018-07-24 16:00:24 +00:00
rts
2018-11-01 08:53:47 +00:00
CS.RUN.HOSTOK lda #2
2018-10-16 15:48:03 +00:00
>SYSCALL ArgV
2018-11-01 08:53:47 +00:00
bcs CS.RUN.PORTOK
2020-08-17 20:47:31 +00:00
>SYSCALL AToI
2018-10-10 15:39:22 +00:00
>STYA SA.REMOTE+S.SOCKADDR.PORT
2019-10-05 17:24:41 +00:00
2020-05-04 20:46:21 +00:00
CS.RUN.PORTOK >PUSHW L.MSG.HOSTOK
ldx #0
2019-10-05 17:24:41 +00:00
2018-10-10 15:39:22 +00:00
.1 >PUSHB SA.REMOTE+S.SOCKADDR.ADDR,x
2020-05-04 20:46:21 +00:00
inx
cpx #4
bne .1
2019-10-05 17:24:41 +00:00
2020-05-04 20:46:21 +00:00
>PUSHW SA.REMOTE+S.SOCKADDR.PORT
lda #1
>SYSCALL ArgV
>PUSHYA
2018-09-05 06:18:50 +00:00
>PUSHBI 8
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2018-07-24 16:00:24 +00:00
2018-10-10 15:39:22 +00:00
CS.RUN.OPENSKT >PUSHBI 0 no protocol
lda #S.SOCKET.T.STREAM
>LIBCALL hLIBTCPIP,LIBTCPIP.Socket
bcs .9
2019-05-05 17:15:37 +00:00
sta hSocket
2018-10-10 15:39:22 +00:00
>PUSHW L.SA.LOCAL
2019-05-05 17:15:37 +00:00
lda hSocket
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Bind
2018-07-24 16:00:24 +00:00
bcc .2
2019-10-05 17:24:41 +00:00
.9 pha
>LDYA L.MSG.SKTKO
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2019-10-05 17:24:41 +00:00
pla
2019-10-03 06:25:27 +00:00
sec
2019-10-05 17:24:41 +00:00
.99 rts
.2 lda #TIMEOUT.MAX
sta TimeOut
.3 >SLEEP
>PUSHW L.SA.REMOTE
2019-05-05 17:15:37 +00:00
lda hSocket
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Connect
2019-10-05 21:07:53 +00:00
bcc .4
2019-10-05 17:24:41 +00:00
cmp #ERR.SKT.NOCONN
bne .9
lda TimeOut
bne .3
lda #ERR.SKT.NOCONN
bra .9
2020-05-04 20:46:21 +00:00
.4 >PUSHW L.MSG.SKTOK
>PUSHBI 0
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2020-05-04 20:46:21 +00:00
2018-08-27 15:26:01 +00:00
>LDYAI BUFSIZE
2020-02-28 07:21:46 +00:00
>SYSCALL GetMem
2019-10-05 17:24:41 +00:00
bcs .99
2018-08-27 15:26:01 +00:00
>STYA ZPBufPtr
2019-05-05 17:15:37 +00:00
stx hBuf
2018-08-27 15:26:01 +00:00
2018-09-03 06:01:07 +00:00
CS.RUN.LOOP >SLEEP
2019-02-23 22:01:58 +00:00
2019-05-05 17:15:37 +00:00
lda hSocket
2019-05-02 09:52:32 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.EOF
bcs .99
tay
bne .2 EOF, no char
2018-08-27 15:26:01 +00:00
>PUSHWI BUFSIZE
2018-09-11 21:15:15 +00:00
>PUSHW ZPBufPtr
2019-05-05 17:15:37 +00:00
lda hSocket
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Read
2020-05-05 20:54:25 +00:00
2019-05-02 09:52:32 +00:00
.99 bcs .9
2020-05-04 20:46:21 +00:00
2019-05-02 18:34:47 +00:00
>PUSHYA len
2018-08-27 15:26:01 +00:00
>PUSHW ZPBufPtr
ldy #S.PS.hStdOut
2020-02-28 07:21:46 +00:00
lda (pPS),y
2020-08-17 20:47:31 +00:00
>SYSCALL FWrite
2018-09-09 08:11:42 +00:00
bcs .11
2019-10-05 21:07:53 +00:00
2019-02-23 22:01:58 +00:00
.2 ldy #S.PS.hStdIn
2020-02-28 07:21:46 +00:00
lda (pPS),y
2018-11-01 08:53:47 +00:00
2020-08-17 20:47:31 +00:00
>SYSCALL FEOF
2019-05-01 13:35:41 +00:00
bcs .11 CS.RUN.IOERR
2018-08-27 15:26:01 +00:00
tay
2019-05-02 09:52:32 +00:00
bne CS.RUN.LOOP EOF = true, no char from STDIN
2019-05-01 13:35:41 +00:00
2019-02-23 22:01:58 +00:00
>PUSHWI BUFSIZE
>PUSHW ZPBufPtr
ldy #S.PS.hStdIn
2020-02-28 07:21:46 +00:00
lda (pPS),y
2020-08-17 20:47:31 +00:00
>SYSCALL FRead
2019-02-23 22:01:58 +00:00
.11 bcs CS.RUN.IOERR
2019-10-05 17:24:41 +00:00
2018-09-03 06:01:07 +00:00
.3 >STYA ZPBufLen
lda (ZPBufPtr)
2019-10-05 17:24:41 +00:00
cmp #$14 Ctrl-T
2018-09-09 08:11:42 +00:00
beq CS.RUN.USER
2019-10-05 17:24:41 +00:00
2019-05-02 09:52:32 +00:00
>PUSHW ZPBufLen
2018-09-11 21:15:15 +00:00
>PUSHW ZPBufPtr
2019-05-05 17:15:37 +00:00
lda hSocket
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Write
2018-09-18 06:28:51 +00:00
2019-05-02 09:52:32 +00:00
.9 bcs CS.RUN.SKTERR
jmp CS.RUN.LOOP
2018-09-09 08:11:42 +00:00
*--------------------------------------
CS.RUN.SKTERR pha
2020-05-04 20:46:21 +00:00
>PUSHW L.MSG.SKTERR
pla
pha
2018-09-09 08:11:42 +00:00
>PUSHA
>PUSHBI 1
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2018-09-09 08:11:42 +00:00
pla
sec
rts
*--------------------------------------
CS.RUN.IOERR pha
2020-05-04 20:46:21 +00:00
>PUSHW L.MSG.IOERR
pla
pha
2018-09-09 08:11:42 +00:00
>PUSHA
>PUSHBI 1
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2018-09-09 08:11:42 +00:00
pla
sec
rts
*--------------------------------------
CS.RUN.USER >LDYA L.MSG.USER
2020-02-28 07:21:46 +00:00
>SYSCALL PutS
2019-02-23 22:01:58 +00:00
lda #0
2018-09-09 08:11:42 +00:00
sec
rts
2018-07-24 16:00:24 +00:00
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
2019-05-05 17:15:37 +00:00
lda TimeOut
2018-07-24 16:00:24 +00:00
beq .9
2019-05-05 17:15:37 +00:00
dec TimeOut
2018-07-24 16:00:24 +00:00
.9 sec do not discard TIMER event
rts
*--------------------------------------
2019-05-05 17:15:37 +00:00
CS.QUIT lda hSocket
2018-07-24 16:00:24 +00:00
beq .1
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
2019-10-05 17:24:41 +00:00
2019-05-05 17:15:37 +00:00
.1 lda hBuf
2018-08-27 15:26:01 +00:00
beq .2
2019-10-05 17:24:41 +00:00
2020-02-28 07:21:46 +00:00
>SYSCALL FreeMem
2019-10-05 17:24:41 +00:00
2018-08-27 15:26:01 +00:00
.2 lda hLIBTCPIP
2018-11-12 09:22:06 +00:00
beq .8
2019-10-05 17:24:41 +00:00
2018-07-24 16:00:24 +00:00
>SYSCALL UnloadLib
2019-10-05 17:24:41 +00:00
2018-11-12 09:22:06 +00:00
.8 clc
2018-07-24 16:00:24 +00:00
rts
*--------------------------------------
CS.END
2019-12-03 15:42:17 +00:00
LIBTCPIP .AZ "libtcpip"
2018-08-27 15:26:01 +00:00
hLIBTCPIP .BS 1
2018-08-27 05:39:42 +00:00
MSG.IPKO .AZ "TCP/IP Not Loaded/Configured."
MSG.USAGE .AZ "Usage : TELNET <ip|host> [port]"
2018-07-24 16:00:24 +00:00
MSG.UNKNOWN .AZ "%s: Unknown host\r\n"
2018-09-11 21:15:15 +00:00
MSG.HOSTOK .AZ "Connecting to %d.%d.%d.%d:%D (%s)..."
2018-08-27 05:39:42 +00:00
MSG.SKTKO .AZ "Failed to Open Socket."
2019-02-23 22:01:58 +00:00
MSG.SKTOK .AZ "Connected\r\n(Exit key is Ctrl-T)\r\n"
2018-09-03 06:01:07 +00:00
MSG.SKTERR .AZ "Socket Error : $%h\r\n"
2018-09-09 08:11:42 +00:00
MSG.IOERR .AZ "I/O Error : $%h\r\n"
MSG.USER .AZ "User interrupt."
2018-08-27 15:26:01 +00:00
*--------------------------------------
2018-10-10 15:39:22 +00:00
SA.LOCAL .DA #AF.INET S.SOCKADDR.AF
2018-08-29 15:01:02 +00:00
.BS 1
2018-10-10 15:39:22 +00:00
.BS 4 S.SOCKADDR.ADDR
.BS 2 S.SOCKADDR.PORT
*--------------------------------------
SA.REMOTE .DA #AF.INET S.SOCKADDR.AF
2018-07-24 16:00:24 +00:00
.BS 1
2018-10-10 15:39:22 +00:00
.BS 4 S.SOCKADDR.ADDR
.DA TCP.PORT.TELNET
2018-07-24 16:00:24 +00:00
*--------------------------------------
.DUMMY
.OR 0
DS.START
DS.END
.ED
*--------------------------------------
MAN
2020-08-17 20:47:31 +00:00
SAVE usr/src/bin/telnet.s
2018-07-24 16:00:24 +00:00
ASM