A2osX/BIN/TELNET.S.txt

330 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
2021-05-19 12:44:47 +00:00
.DA CS.DOEVENT
2018-07-24 16:00:24 +00:00
.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
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
2018-07-24 16:00:24 +00:00
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
2021-05-19 12:44:47 +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
2018-11-01 08:53:47 +00:00
ldy #S.IPCFG.IP+3
ldx #3
2018-11-01 08:53:47 +00:00
.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
2021-05-19 12:44:47 +00:00
2019-10-05 17:24:41 +00:00
>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
2021-05-19 12:44:47 +00:00
2018-09-05 06:18:50 +00:00
>PUSHBI 8
2020-02-28 07:21:46 +00:00
>SYSCALL PrintF
2021-05-19 12:44:47 +00:00
CS.RUN.OPENSKT >PUSHBI S.SOCKET.T.STREAM
>PUSHBI 0 no protocol
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Socket
bcs .9
.1 sta hSocket
2019-05-05 17:15:37 +00:00
2021-05-19 12:44:47 +00:00
>PUSHA
2018-10-10 15:39:22 +00:00
>PUSHW L.SA.LOCAL
>LIBCALL hLIBTCPIP,LIBTCPIP.Bind
2018-07-24 16:00:24 +00:00
bcc .2
2019-10-05 17:24:41 +00:00
.9 jmp CS.RUN.SKTERR
2019-10-05 17:24:41 +00:00
.2 lda #TIMEOUT.MAX
sta TimeOut
.3 >SLEEP
2021-05-19 12:44:47 +00:00
>PUSHB hSocket
2019-10-05 17:24:41 +00:00
>PUSHW L.SA.REMOTE
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Connect
2019-10-05 21:07:53 +00:00
bcc .4
2021-05-19 12:44:47 +00:00
2019-10-05 17:24:41 +00:00
cmp #ERR.SKT.NOCONN
bne .9
2021-05-19 12:44:47 +00:00
2019-10-05 17:24:41 +00:00
lda TimeOut
bne .3
2021-05-19 12:44:47 +00:00
2019-10-05 17:24:41 +00:00
lda #ERR.SKT.NOCONN
bra .9
2021-05-19 12:44:47 +00:00
.4 >LDYA L.MSG.SKTOK
>SYSCALL Puts
2021-05-19 12:44:47 +00:00
2018-08-27 15:26:01 +00:00
>LDYAI BUFSIZE
2020-02-28 07:21:46 +00:00
>SYSCALL GetMem
bcc .5
2021-05-19 12:44:47 +00:00
.5 >STYA ZPBufPtr
2019-05-05 17:15:37 +00:00
stx hBuf
*--------------------------------------
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 CS.RUN.SKTERR
2021-05-14 20:58:20 +00:00
2019-05-02 09:52:32 +00:00
tay
bne .2 EOF, no char
lda hSocket
jsr CS.RUN.PushRead
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Read
bcs CS.RUN.SKTERR
2020-05-05 20:54:25 +00:00
2021-05-19 12:44:47 +00:00
>STYA ZPBufLen
2018-08-27 15:26:01 +00:00
ldy #S.PS.hStdOut
2020-02-28 07:21:46 +00:00
lda (pPS),y
jsr CS.RUN.PushWrite
2020-08-17 20:47:31 +00:00
>SYSCALL FWrite
bcs CS.RUN.IOERR
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
2020-08-17 20:47:31 +00:00
>SYSCALL FEOF
bcs CS.RUN.IOERR
2021-05-14 20:58:20 +00:00
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
ldy #S.PS.hStdIn
2020-02-28 07:21:46 +00:00
lda (pPS),y
jsr CS.RUN.PushRead
2020-08-17 20:47:31 +00:00
>SYSCALL FRead
bcs CS.RUN.IOERR
2019-10-05 17:24:41 +00:00
>STYA ZPBufLen
2021-05-19 12:44:47 +00:00
2018-09-03 06:01:07 +00:00
lda (ZPBufPtr)
2019-10-05 17:24:41 +00:00
cmp #$14 Ctrl-T
beq CS.RUN.USERINT
2019-10-05 17:24:41 +00:00
lda hSocket
jsr CS.RUN.PushWrite
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Write
bcc CS.RUN.LOOP
2018-09-09 08:11:42 +00:00
*--------------------------------------
CS.RUN.SKTERR ldx #0
bra CS.RUN.ERR
2018-09-09 08:11:42 +00:00
*--------------------------------------
CS.RUN.IOERR ldx #2
CS.RUN.ERR pha
>PUSHW L.MSG.SKTERR,x
2020-05-04 20:46:21 +00:00
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.USERINT >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.RUN.PushRead >PUSHA
>PUSHW ZPBufPtr
>PUSHWI BUFSIZE
rts
*--------------------------------------
CS.RUN.PushWrite
>PUSHA
>PUSHW ZPBufPtr
>PUSHW ZPBufLen
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)..."
MSG.SKTOK .AS "Connected"
.DA #C.CR,#C.LF
.AZ "(Exit key is Ctrl-T)"
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
2018-07-24 16:00:24 +00:00
*--------------------------------------
MAN
2020-08-17 20:47:31 +00:00
SAVE usr/src/bin/telnet.s
2018-07-24 16:00:24 +00:00
ASM