A2osX/BIN/PING.S.txt

397 lines
7.6 KiB
Plaintext
Raw Normal View History

NEW
2018-11-17 17:17:13 +00:00
PREFIX
2017-12-22 21:24:30 +00:00
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
2018-07-23 15:28:42 +00:00
.TF BIN/PING
*--------------------------------------
2018-07-23 15:28:42 +00:00
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/ETH.I
.INB INC/LIBTCPIP.I
*--------------------------------------
2018-11-15 07:08:20 +00:00
TIMEOUT.MAX .EQ 100 10 sec.
*--------------------------------------
2018-09-11 13:32:56 +00:00
ZPIPCfgPtr .EQ ZPBIN
ZPTmpPtr .EQ ZPBIN+2
*--------------------------------------
2015-06-03 18:30:57 +00:00
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
2015-06-03 18:30:57 +00:00
.DA #$61 6502,Level 1 (65c02)
.DA #1 BIN Layout Version 1
2018-09-11 13:32:56 +00:00
.DA #S.PS.F.EVENT S.PS.F
.DA #0
2015-06-03 18:30:57 +00:00
.DA CS.END-CS.START Code Length To Relocate
.DA DS.END-DS.START Data Segment to Allocate
2018-08-23 15:16:20 +00:00
.DA #64 SS
2018-09-11 13:32:56 +00:00
.DA #4 ZP
2015-06-03 18:30:57 +00:00
.DA 0
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
2015-06-03 18:30:57 +00:00
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP
2018-11-05 07:12:31 +00:00
L.SA.LOCAL .DA SA.LOCAL
L.SA.REMOTE .DA SA.REMOTE
L.SA.REMOTE.AD .DA SA.REMOTE+S.SOCKADDR.ADDR
L.ICMP.Request .DA ICMP.Request
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.REPLY .DA MSG.REPLY
L.MSG.UNREACH .DA MSG.UNREACH
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBTCPIP
2018-07-19 15:33:55 +00:00
>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 ?
>STYA ZPIPCfgPtr
lda (ZPIPCfgPtr) Configured ?
bmi CS.RUN.IPOK
>LDYA L.MSG.IPKO
2018-08-23 15:16:20 +00:00
>SYSCALL puts
2018-10-21 20:54:07 +00:00
lda #E.SYN
sec
2017-01-29 21:47:19 +00:00
rts
2018-09-11 13:32:56 +00:00
CS.RUN.IPOK
.1 >INC.G ArgIndex
2018-10-16 15:48:03 +00:00
>SYSCALL ArgV
2018-09-11 13:32:56 +00:00
bcs .8
>STYA ZPTmpPtr
lda (ZPTmpPtr)
cmp #'-'
2018-11-05 07:12:31 +00:00
bne .21
2017-12-22 21:24:30 +00:00
2018-09-11 13:32:56 +00:00
ldy #1
lda (ZPTmpPtr),y
beq .9
2018-09-11 13:32:56 +00:00
cmp #'0'
bcc .9
cmp #'9'+1
bcs .9
and #$0F
>STA.G PingCount
bra .1
2018-11-05 07:12:31 +00:00
.21 jsr Init.Timeout
2018-09-11 13:32:56 +00:00
2018-11-05 07:12:31 +00:00
.2 >PUSHW L.SA.REMOTE.AD
2018-09-11 13:32:56 +00:00
>PUSHW ZPTmpPtr
>LIBCALL hLIBTCPIP,LIBTCPIP.HST.GETBYNAME
2018-09-11 13:32:56 +00:00
bcc .3
>SLEEP
jsr Wait.Timeout
bcc .2
2018-09-11 13:32:56 +00:00
>PUSHW ZPTmpPtr
2018-08-25 11:23:59 +00:00
>PUSHBI 2
>LDYA L.MSG.UNKNOWN
bra .99
2018-09-11 13:32:56 +00:00
.3 >LDA.G ArgIndex
>STA.G ArgHostName
jmp .1
2018-11-05 07:12:31 +00:00
.8 lda SA.REMOTE+S.SOCKADDR.ADDR
2018-09-11 13:32:56 +00:00
bne CS.RUN.ARGSOK
.9 >PUSHBI 0
>LDYA L.MSG.USAGE
.99 >SYSCALL printf
2018-08-25 11:23:59 +00:00
2018-10-21 20:54:07 +00:00
lda #E.SYN
sec
rts
2018-09-11 13:32:56 +00:00
CS.RUN.ARGSOK >LDA.G ArgHostName
2018-10-16 15:48:03 +00:00
>SYSCALL ArgV
>PUSHYA
ldx #3
2018-11-05 07:12:31 +00:00
.1 lda SA.REMOTE+S.SOCKADDR.ADDR,x
>PUSHA
dex
bpl .1
2018-08-23 15:16:20 +00:00
>PUSHBI 6
>LDYA L.MSG.HOSTOK
2018-06-21 15:12:10 +00:00
>SYSCALL printf
CS.RUN.OPENSKT ldx #3
ldy #S.IPCFG.IP+3
.1 lda (ZPIPCfgPtr),y
2018-11-05 07:12:31 +00:00
sta SA.LOCAL+S.SOCKADDR.ADDR,x
dey
dex
bpl .1
ldy #Identifier
lda A2OSX.RANDOM16
2018-11-06 07:09:44 +00:00
sta SA.LOCAL+S.SOCKADDR.PORT
2018-11-05 07:12:31 +00:00
sta SA.REMOTE+S.SOCKADDR.PORT
sta (pData),y
iny
lda A2OSX.RANDOM16+1
2018-11-06 07:09:44 +00:00
sta SA.LOCAL+S.SOCKADDR.PORT+1
2018-11-05 07:12:31 +00:00
sta SA.REMOTE+S.SOCKADDR.PORT+1
sta (pData),y
2018-11-05 07:12:31 +00:00
>PUSHBI S.IP.PROTOCOL.ICMP
lda #S.SOCKET.T.RAW
2018-10-29 08:41:10 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.socket
2018-11-05 16:28:40 +00:00
bcs .9
2018-11-05 16:28:40 +00:00
>STA.G hSocket
2018-11-05 07:12:31 +00:00
pha
>PUSHW L.SA.LOCAL
pla
>LIBCALL hLIBTCPIP,LIBTCPIP.Bind
2018-11-05 16:28:40 +00:00
bcs .9
>PUSHW L.SA.REMOTE
>LDA.G hSocket
2018-11-07 21:48:48 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Connect
2018-11-05 16:28:40 +00:00
2018-11-05 07:12:31 +00:00
bcc CS.RUN.SEND.ECHO
2018-11-05 16:28:40 +00:00
.9 >LDYA L.MSG.SKTKO
>SYSCALL puts
lda #E.SYN
sec
2018-11-05 07:12:31 +00:00
rts
CS.RUN.SEND.ECHO
2018-11-12 09:22:06 +00:00
>LDA.G Identifier
sta ICMP.Request.ID
iny
2015-06-03 18:30:57 +00:00
lda (pData),y
sta ICMP.Request.ID+1
2015-06-03 18:30:57 +00:00
2018-11-12 09:22:06 +00:00
>LDA.G Sequence
sec
adc #0
sta (pData),y
sta ICMP.Request.SQ
iny
lda (pData),y
adc #0
sta (pData),y
sta ICMP.Request.SQ+1
jsr Init.Timeout
2017-02-13 07:26:18 +00:00
>PUSHWI ICMP.RequestLen
2018-09-17 15:42:38 +00:00
>PUSHW L.ICMP.Request
>LDA.G hSocket
2018-10-29 08:41:10 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.send
bcs CS.RUN.ERR
jsr Init.Timeout
CS.RUN.WAIT.REPLY
>SLEEP
2017-12-22 21:24:30 +00:00
>SYSCALL GetChar
bcs .1
cmp #3 Ctrl-C
2018-09-11 13:32:56 +00:00
beq CS.RUN.ERR CS
2018-09-11 13:32:56 +00:00
.1 >LDA.G hSocket
2018-10-29 08:41:10 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Recv
2018-09-11 13:32:56 +00:00
bcc .2
jsr Wait.Timeout
bcc CS.RUN.WAIT.REPLY
jsr CS.Print.UNREACH
bcs CS.RUN.ERR
bra .7
2018-09-11 13:32:56 +00:00
.2 >STA.G hFrame
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
2018-09-11 13:32:56 +00:00
>STYA ZPTmpPtr
jsr CS.Print.REPLY
bcs CS.RUN.ERR
2018-09-11 13:32:56 +00:00
>LDA.G hFrame
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
2018-09-11 13:32:56 +00:00
>STZ.G hFrame
2018-09-11 13:32:56 +00:00
.7 >LDA.G PingCount
beq .8
dec
beq .9 A=0
sta (pData),y
2018-09-11 13:32:56 +00:00
.8 jmp CS.RUN.SEND.ECHO
2018-09-11 13:32:56 +00:00
.9 sec
CS.RUN.ERR rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
2018-09-11 13:32:56 +00:00
>LDA.G TimeOut
beq .9
dec
2015-06-03 18:30:57 +00:00
sta (pData),y
.9 sec do not discard TIMER event
rts
*--------------------------------------
CS.Print.UNREACH
2018-11-05 07:12:31 +00:00
ldx #3
2018-08-23 15:16:20 +00:00
2018-11-06 07:09:44 +00:00
.1 >PUSHB SA.REMOTE+S.SOCKADDR.ADDR,x
2018-08-23 15:16:20 +00:00
dex
2018-11-05 07:12:31 +00:00
bpl .1
2018-08-23 15:16:20 +00:00
>PUSHBI 4
>LDYA L.MSG.UNREACH
2018-06-21 15:12:10 +00:00
>SYSCALL printf
rts
*--------------------------------------
CS.Print.REPLY lda #TIMEOUT.MAX
sec
ldy #TimeOut
sbc (pData),y
2018-08-23 15:16:20 +00:00
>STZ.G TimeOut.ms
>STA.G TimeOut.ms+1
2018-09-11 13:32:56 +00:00
tax
beq .3
2018-08-23 15:16:20 +00:00
.1 >LDA.G TimeOut.ms
clc
adc #100
2018-08-23 15:16:20 +00:00
>STA.G TimeOut.ms
bcc .2
2018-08-23 15:16:20 +00:00
>INC.G TimeOut.ms+1
2018-09-11 13:32:56 +00:00
.2 dex
bne .1
2018-08-23 15:16:20 +00:00
.3 >PUSHW.G TimeOut.ms
ldy #S.IP.TTL
2018-09-11 13:32:56 +00:00
>PUSHB (ZPTmpPtr),y
ldy #S.ICMP.SEQUENCE+1
2018-09-11 13:32:56 +00:00
>PUSHB (ZPTmpPtr),y
dey
2018-09-11 13:32:56 +00:00
>PUSHB (ZPTmpPtr),y
2018-08-23 15:16:20 +00:00
ldx #4
ldy #S.IP.SRC+3
2018-08-23 15:16:20 +00:00
2018-09-11 13:32:56 +00:00
.4 >PUSHB (ZPTmpPtr),y
dey
2018-08-23 15:16:20 +00:00
dex
bne .4
2018-08-23 15:16:20 +00:00
>PUSHBI 9
>LDYA L.MSG.REPLY
2018-06-21 15:12:10 +00:00
>SYSCALL printf
rts
*--------------------------------------
2018-09-11 13:32:56 +00:00
CS.QUIT >LDA.G hFrame
beq .1
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
2018-09-11 13:32:56 +00:00
.1 >LDA.G hSocket
beq .2
2018-07-24 06:24:23 +00:00
2018-11-06 07:09:44 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.Shutdown
2018-09-11 13:32:56 +00:00
.2 lda hLIBTCPIP
beq .8
2018-07-20 14:10:10 +00:00
>SYSCALL UnloadLib
2018-09-11 13:32:56 +00:00
.8 clc
rts
*--------------------------------------
2018-09-11 13:32:56 +00:00
Init.Timeout lda #TIMEOUT.MAX
>STA.G TimeOut
rts
*--------------------------------------
Wait.TimeOut sec
2018-09-11 13:32:56 +00:00
>LDA.G TimeOut
beq .9
2017-01-29 21:47:19 +00:00
clc
.9 rts
*--------------------------------------
CS.END
2018-10-29 08:41:10 +00:00
LIBTCPIP .AZ "libtcpip"
2018-08-23 15:16:20 +00:00
MSG.IPKO .AZ "TCP/IP Not Loaded/Configured."
2018-09-11 13:32:56 +00:00
MSG.USAGE .AS "Usage : PING <ip|host>\r\n"
.AZ " -1-9 : Ping Count\r\n"
MSG.UNKNOWN .AZ "%s: Unknown host\r\n"
MSG.HOSTOK .AZ "PING %d.%d.%d.%d (%s)\r\n"
2018-08-23 15:16:20 +00:00
MSG.SKTKO .AZ "Failed to Open Socket."
MSG.UNREACH .AZ "%d.%d.%d.%d: TimeOut/Host unreachable\r\n"
MSG.REPLY .AZ "32 bytes from %d.%d.%d.%d, icmp_seq=%D, ttl=%d, time=%D ms\r\n"
hLIBTCPIP .BS 1
2018-08-23 15:16:20 +00:00
*--------------------------------------
2018-11-05 07:12:31 +00:00
SA.LOCAL .DA #AF.INET S.SOCKADDR.AF
.BS 1
2018-11-05 07:12:31 +00:00
.BS 4 S.SOCKADDR.ADDR
.BS 2 S.SOCKADDR.PORT
*--------------------------------------
SA.REMOTE .DA #AF.INET S.SOCKADDR.AF
.BS 1
2018-11-05 07:12:31 +00:00
.BS 4 S.SOCKADDR.ADDR
.BS 2
*--------------------------------------
ICMP.Request .DA #S.ICMP.TYPE.ECHOREQ
.DA #0 CODE
.DA 0 CHECKSUM
ICMP.Request.ID .BS 2
ICMP.Request.SQ .BS 2
.AS "ABCDEFGHIJKLMNOP"
.AS "QRSTUVWXYZ012345"
ICMP.RequestLen .EQ *-ICMP.Request
2015-06-03 18:30:57 +00:00
*--------------------------------------
.DUMMY
.OR 0
DS.START
2018-09-11 13:32:56 +00:00
ArgIndex .BS 1
PingCount .BS 1
ArgHostName .BS 1
hSocket .BS 1
hFrame .BS 1
Identifier .BS 2
Sequence .BS 2
TimeOut .BS 1
2018-08-23 15:16:20 +00:00
TimeOut.ms .BS 2
DS.END
2015-06-03 18:30:57 +00:00
.ED
*--------------------------------------
MAN
2019-01-16 21:51:57 +00:00
SAVE USR/SRC/BIN/PING.S
ASM