A2osX/BIN/PING.S.txt

376 lines
7.1 KiB
Plaintext
Raw Normal View History

NEW
2017-12-22 21:24:30 +00:00
PREFIX /A2OSX.BUILD
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
*--------------------------------------
2016-04-04 20:54:55 +00:00
TIMEOUT.MAX .EQ 20 2 sec.
*--------------------------------------
ZPFrameBase .EQ ZPBIN
2017-01-29 21:47:19 +00:00
ZPFrameLen .EQ ZPBIN+2
ZPFramePtr1 .EQ ZPBIN+4
ZPIPCfgPtr .EQ ZPBIN+6
*--------------------------------------
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
.DA 0
.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
2017-12-22 21:24:30 +00:00
.DA #8 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
L.Socket .DA Socket
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
2015-06-03 18:30:57 +00:00
lda (pPs)
ora #S.PS.F.EVENT Now accept events
2015-06-03 18:30:57 +00:00
sta (pPs)
clc
.9 rts
*--------------------------------------
CS.RUN >LIBCALL hLIBTCPIP,LIBTCPIP.GET.IPCFG 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
lda #K.E.SYN
sec
2017-01-29 21:47:19 +00:00
rts
2017-12-22 21:24:30 +00:00
CS.RUN.IPOK ldy #S.PS.ARGC
lda (pPs),y
beq .9
jsr Init.Timeout
2015-06-03 18:30:57 +00:00
.2 >PUSHW pData DST.IP
2016-08-17 06:25:58 +00:00
lda #1
2018-07-18 15:30:42 +00:00
>SYSCALL GetArg
>PUSHYA
>LIBCALL hLIBTCPIP,LIBTCPIP.HST.GETBYNAME
bcc CS.RUN.HOSTOK
>SLEEP
jsr Wait.Timeout
bcc .2
2016-08-17 06:25:58 +00:00
lda #1
2018-07-18 15:30:42 +00:00
>SYSCALL GetArg
>PUSHYA
2018-08-25 11:23:59 +00:00
>PUSHBI 2
>LDYA L.MSG.UNKNOWN
2018-08-25 11:23:59 +00:00
>SYSCALL printf
bra .99
.9 >LDYA L.MSG.USAGE
2018-08-25 11:23:59 +00:00
>SYSCALL puts
.99 lda #K.E.SYN
sec
rts
CS.RUN.HOSTOK lda #1
2018-07-18 15:30:42 +00:00
>SYSCALL GetArg
>PUSHYA
ldy #DST.IP+3
ldx #3
.1 lda (pData),y
sta Socket.Dst.Addr,x
>PUSHA
dey
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
sta Socket.Src.Addr,x
dey
dex
bpl .1
ldy #Identifier
lda A2OSX.RANDOM16
sta Socket.Dst.Port
sta (pData),y
iny
lda A2OSX.RANDOM16+1
sta Socket.Dst.Port+1
sta (pData),y
>PUSHW L.Socket
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.New
bcc .2
>LDYA L.MSG.SKTKO
2018-08-23 15:16:20 +00:00
>SYSCALL puts
lda #K.E.SYN
sec
rts
.2 txa
ldy #hSocket
sta (pData),y
CS.RUN.SEND.ECHO
2015-06-03 18:30:57 +00:00
ldy #Identifier
lda (pData),y
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
ldy #Sequence
sec
lda (pData),y
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
ldy #hSocket
>PUSHB (pData),y
2017-02-13 07:26:18 +00:00
>PUSHW L.ICMP.Request
>PUSHWI ICMP.RequestLen
2018-08-29 15:01:02 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.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
beq .9
.1 ldy #hSocket
2015-06-03 18:30:57 +00:00
lda (pData),y
2018-08-29 15:01:02 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.Rcvd
bcs .2
ldy #hFrame
sta (pData),y
2018-07-18 15:30:42 +00:00
>SYSCALL GetMemPtr
>STYA ZPFrameBase
jsr CS.Print.REPLY
bcs CS.RUN.ERR
ldy #hFrame
lda (pData),y
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
ldy #hFrame
lda #0
sta (pData),y
jmp CS.RUN.SEND.ECHO
.2 jsr Wait.Timeout
bcc CS.RUN.WAIT.REPLY
jsr CS.Print.UNREACH
bcs CS.RUN.ERR
jmp CS.RUN.SEND.ECHO
.9 lda #0
sec
CS.RUN.ERR rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
2015-06-03 18:30:57 +00:00
ldy #TimeOut
lda (pData),y
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-08-23 15:16:20 +00:00
ldx #4
ldy #DST.IP+3
2018-08-23 15:16:20 +00:00
.1 >PUSHB (pData),y
dey
2018-08-23 15:16:20 +00:00
dex
bne .1
>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
tay
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
.2 dey
bne .1
2018-08-23 15:16:20 +00:00
.3 >PUSHW.G TimeOut.ms
ldy #S.IP.TTL
2017-01-29 21:47:19 +00:00
>PUSHB (ZPFrameBase),y
ldy #S.ICMP.SEQUENCE+1
2017-01-29 21:47:19 +00:00
>PUSHB (ZPFrameBase),y
dey
2017-01-29 21:47:19 +00:00
>PUSHB (ZPFrameBase),y
2018-08-23 15:16:20 +00:00
ldx #4
ldy #S.IP.SRC+3
2018-08-23 15:16:20 +00:00
.4 >PUSHB (ZPFrameBase),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
*--------------------------------------
CS.QUIT ldy #hFrame
lda (pData),y
beq .1
2018-07-18 15:30:42 +00:00
>SYSCALL FreeMem
.1 ldy #hSocket
lda (pData),y
2018-07-24 06:24:23 +00:00
2018-07-23 15:28:42 +00:00
>LIBCALL hLIBTCPIP,LIBTCPIP.SKT.Close
lda hLIBTCPIP
2018-07-20 14:10:10 +00:00
>SYSCALL UnloadLib
clc
rts
*--------------------------------------
Init.Timeout ldy #TimeOut
lda #TIMEOUT.MAX
sta (pData),y
rts
*--------------------------------------
Wait.TimeOut sec
ldy #TimeOut
lda (pData),y
beq .9
2017-01-29 21:47:19 +00:00
clc
.9 rts
*--------------------------------------
CS.END
LIBTCPIP .AZ "libtcpip.o"
2018-08-23 15:16:20 +00:00
MSG.IPKO .AZ "TCP/IP Not Loaded/Configured."
MSG.USAGE .AZ "Usage : PING <ip|host>"
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
*--------------------------------------
Socket .DA #S.SOCKET.SOCK.RAW
.BS 1
.DA #S.IP.PROTOCOL.ICMP
.BS 1
Socket.Src.Addr .BS 4
Socket.Src.Port .DA 0 Dynamic
Socket.Dst.Addr .BS 4
Socket.Dst.Port .DA 0 Identifier
*--------------------------------------
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
DST.IP .BS 4
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
SAVE /A2OSX.SRC/BIN/PING.S
ASM