A2osX/BIN/TELNET.S.txt

324 lines
6.3 KiB
Plaintext
Raw Normal View History

2018-07-24 16:00:24 +00:00
NEW
2018-11-17 17:17:13 +00:00
PREFIX
2018-07-24 16:00:24 +00:00
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
2018-10-10 15:39:22 +00:00
.INB INC/NET.TELNET.I
2018-07-24 16:00:24 +00:00
*--------------------------------------
2018-09-11 21:15:15 +00:00
TIMEOUT.MAX .EQ 40 4 sec.
2018-08-27 15:26:01 +00:00
BUFSIZE .EQ 256
2018-07-24 16:00:24 +00:00
*--------------------------------------
2018-08-27 15:26:01 +00:00
ZPIPCfgPtr .EQ ZPBIN
ZPBufPtr .EQ ZPBIN+2
2018-09-03 06:01:07 +00:00
ZPBufLen .EQ ZPBIN+4
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
2018-07-24 16:00:24 +00:00
.DA CS.END-CS.START Code Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
.DA #16 SS
2018-09-03 06:01:07 +00:00
.DA #6 ZP
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
>LDYA L.MSG.IPKO
2018-08-27 05:39:42 +00:00
>SYSCALL puts
2018-10-21 20:54:07 +00:00
lda #E.SYN
2018-07-24 16:00:24 +00:00
sec
rts
CS.RUN.IPOK ldy #S.PS.ARGC
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
2018-07-24 16:00:24 +00:00
jsr Init.Timeout
2018-10-10 15:39:22 +00:00
.2 >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
>LIBCALL hLIBTCPIP,LIBTCPIP.HST.GETBYNAME
2018-09-05 06:18:50 +00:00
bcc CS.RUN.HOSTOK
>SLEEP
2018-07-24 16:00:24 +00:00
jsr Wait.Timeout
bcc .2
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
2018-07-24 16:00:24 +00:00
>LDYA L.MSG.UNKNOWN
2018-08-28 15:28:34 +00:00
>SYSCALL printf
2018-07-24 16:00:24 +00:00
bra .99
.9 >LDYA L.MSG.USAGE
2018-08-28 15:28:34 +00:00
>SYSCALL puts
2018-08-27 15:26:01 +00:00
2018-10-21 20:54:07 +00:00
.99 lda #E.SYN
2018-07-24 16:00:24 +00:00
sec
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
2018-09-05 06:18:50 +00:00
>SYSCALL atoi
2018-10-10 15:39:22 +00:00
>STYA SA.REMOTE+S.SOCKADDR.PORT
2018-09-05 06:18:50 +00:00
CS.RUN.PORTOK lda #1
2018-10-16 15:48:03 +00:00
>SYSCALL ArgV
2018-07-24 16:00:24 +00:00
>PUSHYA
2018-10-10 15:39:22 +00:00
>PUSHW SA.REMOTE+S.SOCKADDR.PORT
2018-09-05 06:18:50 +00:00
2018-07-24 16:00:24 +00:00
ldx #3
2018-10-10 15:39:22 +00:00
.1 >PUSHB SA.REMOTE+S.SOCKADDR.ADDR,x
2018-07-24 16:00:24 +00:00
dex
bpl .1
2018-09-05 06:18:50 +00:00
>PUSHBI 8
2018-07-24 16:00:24 +00:00
>LDYA L.MSG.HOSTOK
>SYSCALL printf
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
>STA.G hSocket
pha
>PUSHW L.SA.LOCAL
pla
>LIBCALL hLIBTCPIP,LIBTCPIP.Bind
2018-07-24 16:00:24 +00:00
bcc .2
2018-10-10 15:39:22 +00:00
.9 >LDYA L.MSG.SKTKO
2018-08-27 05:39:42 +00:00
>SYSCALL puts
2018-10-21 20:54:07 +00:00
lda #E.SYN
2018-07-24 16:00:24 +00:00
sec
2018-10-10 15:39:22 +00:00
rts
2018-07-24 16:00:24 +00:00
2018-10-10 15:39:22 +00:00
.2 >PUSHW L.SA.REMOTE
>LDA.G hSocket
>LIBCALL hLIBTCPIP,LIBTCPIP.Connect
2018-11-01 08:53:47 +00:00
bcs .9
2018-08-27 15:26:01 +00:00
>LDYA L.MSG.SKTOK
>SYSCALL puts
>LDYAI BUFSIZE
>SYSCALL getmem
bcs .9
>STYA ZPBufPtr
txa
>STA.G hBuf
2018-09-03 06:01:07 +00:00
CS.RUN.LOOP >SLEEP
2018-08-27 15:26:01 +00:00
>PUSHWI BUFSIZE
2018-09-11 21:15:15 +00:00
>PUSHW ZPBufPtr
>LDA.G hSocket
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Read
2018-08-27 15:26:01 +00:00
bcc .1
2018-09-03 06:01:07 +00:00
2018-08-27 15:26:01 +00:00
tay
beq .2 no char
2018-09-09 08:11:42 +00:00
jmp CS.RUN.SKTERR
2018-08-27 15:26:01 +00:00
.1 >PUSHYA len
>PUSHW ZPBufPtr
ldy #S.PS.hStdOut
lda (pPs),y
2018-11-01 08:53:47 +00:00
>SYSCALL fwrite
2018-09-09 08:11:42 +00:00
bcs .11
2018-08-27 15:26:01 +00:00
.2 >PUSHWI BUFSIZE
>PUSHW ZPBufPtr
ldy #S.PS.hStdIn
lda (pPs),y
2018-11-01 08:53:47 +00:00
>SYSCALL fread
2018-08-27 15:26:01 +00:00
bcc .3
tay
2018-09-09 08:11:42 +00:00
beq CS.RUN.LOOP no char from STDIN
2018-09-03 06:01:07 +00:00
2018-09-09 08:11:42 +00:00
.11 jmp CS.RUN.IOERR
2018-08-27 15:26:01 +00:00
2018-09-03 06:01:07 +00:00
.3 >STYA ZPBufLen
lda (ZPBufPtr)
2018-11-21 13:08:11 +00:00
cmp #$14 Ctrl-T
2018-09-09 08:11:42 +00:00
beq CS.RUN.USER
2018-09-03 06:01:07 +00:00
2018-11-01 08:53:47 +00:00
.4 >PUSHW ZPBufLen
2018-09-11 21:15:15 +00:00
>PUSHW ZPBufPtr
>LDA.G hSocket
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Write
2018-09-18 06:28:51 +00:00
2018-11-01 08:53:47 +00:00
bcc .8
tay
bne CS.RUN.SKTERR
* >SLEEP
* bra .4
2018-08-27 15:26:01 +00:00
2018-11-01 08:53:47 +00:00
.8 jmp CS.RUN.LOOP
2018-07-24 16:00:24 +00:00
.9 lda #0
sec
2018-09-09 08:11:42 +00:00
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 #3
sec
rts
2018-07-24 16:00:24 +00:00
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
2018-11-12 09:22:06 +00:00
>LDA.G TimeOut
2018-07-24 16:00:24 +00:00
beq .9
dec
sta (pData),y
.9 sec do not discard TIMER event
rts
*--------------------------------------
2018-09-03 06:01:07 +00:00
CS.QUIT >LDA.G hSocket
2018-07-24 16:00:24 +00:00
beq .1
2018-10-10 15:39:22 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
2018-07-24 16:00:24 +00:00
2018-08-27 15:26:01 +00:00
.1 >LDA.G hBuf
beq .2
>SYSCALL freemem
.2 lda hLIBTCPIP
2018-11-12 09:22:06 +00:00
beq .8
2018-07-24 16:00:24 +00:00
>SYSCALL UnloadLib
2018-11-12 09:22:06 +00:00
.8 clc
2018-07-24 16:00:24 +00:00
rts
*--------------------------------------
2018-11-12 09:22:06 +00:00
Init.Timeout lda #TIMEOUT.MAX
>STA.G TimeOut
2018-07-24 16:00:24 +00:00
rts
*--------------------------------------
Wait.TimeOut sec
2018-11-12 09:22:06 +00:00
>LDA.G TimeOut
2018-07-24 16:00:24 +00:00
beq .9
clc
.9 rts
*--------------------------------------
CS.END
2018-10-11 06:09:35 +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."
2018-11-21 13:08:11 +00:00
MSG.SKTOK .AZ "Connected, 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
2018-08-27 15:26:01 +00:00
hBuf .BS 1
2018-07-24 16:00:24 +00:00
hSocket .BS 1
TimeOut .BS 1
DS.END
.ED
*--------------------------------------
MAN
2019-01-16 21:51:57 +00:00
SAVE USR/SRC/BIN/TELNET.S
2018-07-24 16:00:24 +00:00
ASM