A2osX/BIN/PING.S.txt

431 lines
7.6 KiB
Plaintext
Raw Normal View History

PR#3
2015-06-03 18:30:57 +00:00
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
2015-06-03 18:30:57 +00:00
.TF /A2OSX.BOOT/BIN/PING
*--------------------------------------
.INB /A2OSX.DEV/INC/MACROS.I
.INB /A2OSX.DEV/INC/A2OSX.I
.INB /A2OSX.DEV/INC/LIBTCPIP.I
*--------------------------------------
2016-04-04 20:54:55 +00:00
TIMEOUT.MAX .EQ 20 2 sec.
*--------------------------------------
ZPFrameBase1 .EQ ZPBIN
ZPFrameLen1 .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
.DA 0
.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.MSG0 .DA MSG0
L.MSG1 .DA MSG1
L.MSG2 .DA MSG2
L.MSG3 .DA MSG3
.DA 0
*--------------------------------------
CS.INIT >SYSCALL GetArgC
2016-08-17 06:25:58 +00:00
cmp #1
bne .1
2016-08-17 06:25:58 +00:00
lda #SYSMGR.ERRSYN
sec
rts
.1 >LDYA L.LIBTCPIP
>SYSCALL LoadLibYA
sta hLIBTCPIP
>LIBCALL hLIBTCPIP,LIBTCPIP.GET.IPCFG is TCPIP loaded ?
bcs .9
>STYA ZPIPCfgPtr
lda (ZPIPCfgPtr) Configured ?
bpl .9
ldy #S.IPCFG.HDEV
lda (ZPIPCfgPtr),y
sta hDev
lda A2OSX.RANDOM16
2015-06-03 18:30:57 +00:00
ldy #Identifier
sta (pData),y
lda A2OSX.RANDOM16+1
2015-06-03 18:30:57 +00:00
iny
sta (pData),y
2015-06-03 18:30:57 +00:00
lda #0
ldy #Sequence
sta (pData),y
iny
sta (pData),y
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 jsr Init.Timeout
2015-06-03 18:30:57 +00:00
.1 >PUSHW pData DST.IP
2016-08-17 06:25:58 +00:00
lda #1
>SYSCALL GetArgA
>PUSHYA
>LIBCALL hLIBTCPIP,LIBTCPIP.HST.GETBYNAME
bcc .2
>SYSCALL Sleep
jsr Wait.Timeout
bcc .1
2016-08-17 06:25:58 +00:00
lda #1
>SYSCALL GetArgA
>PUSHYA
>LDYA L.MSG0
>SYSCALL CPrintFYA
lda #1
sec
rts
2016-08-17 06:25:58 +00:00
.2 lda #1
>SYSCALL GetArgA
>PUSHYA
2015-06-03 18:30:57 +00:00
ldy #3
>PUSHB (pData),y DST.IP+3
dey
>PUSHB (pData),y DST.IP+2
dey
>PUSHB (pData),y DST.IP+1
>PUSHB (pData) DST.IP
>LDYA L.MSG1
>SYSCALL CPrintFYA
CS.RUN.ECHO >LIBCALL hLIBTCPIP,LIBTCPIP.NEW.ICMP.FRAME
>STYA ZPFrameBase1
2015-06-03 18:30:57 +00:00
txa
ldy #hFrame
sta (pData),y
lda #S.ICMP+32-2
sta (ZPFrameBase1)
lda /S.ICMP+32-2
ldy #1
sta (ZPFrameBase1),y
2015-06-03 18:30:57 +00:00
ldx #3
ldy #0
.10 lda (pData),y
pha
iny
dex
bpl .10
ldx #3
ldy #S.IP.DST+3
2015-06-03 18:30:57 +00:00
.1 pla
sta (ZPFrameBase1),y
dey
dex
bpl .1
ldy #S.ICMP.TYPE
lda #S.ICMP.TYPE.ECHOREQ
sta (ZPFrameBase1),y
2015-06-03 18:30:57 +00:00
ldy #Identifier
lda (pData),y
tax
iny
2015-06-03 18:30:57 +00:00
lda (pData),y
ldy #S.ICMP.IDENTIFIER+1
sta (ZPFrameBase1),y
dey
txa
sta (ZPFrameBase1),y
2015-06-03 18:30:57 +00:00
ldy #Sequence+1
lda (pData),y
tax
dey
lda (pData),y
inc
sta (pData),y
bne .2
2015-06-03 18:30:57 +00:00
pha
inx
txa
sta (pData),y
pla
.2 ldy #S.ICMP.SEQUENCE
sta (ZPFrameBase1),y
iny
2015-06-03 18:30:57 +00:00
txa
sta (ZPFrameBase1),y
ldx #31
ldy #S.ICMP+31
.21 txa
and #$0f
ora #$60
sta (ZPFrameBase1),y
dey
dex
bpl .21
jsr Init.Timeout
.3 ldy #hFrame
2015-06-03 18:30:57 +00:00
lda (pData),y
>SYSCALL GetMemPtrA
>PUSHYA
>LIBCALL hLIBTCPIP,LIBTCPIP.SEND.ICMP.FRAME
bcc .4
>SYSCALL Sleep
jsr Wait.Timeout
bcc .3
2015-06-03 18:30:57 +00:00
.4 ldy #hFrame
lda (pData),y
>SYSCALL FreeMemA
2015-06-03 18:30:57 +00:00
ldy #bReply
lda #0
sta (pData),y
jsr Init.Timeout
CS.RUN.WAIT >SYSCALL Sleep
2015-06-03 18:30:57 +00:00
ldy #bReply
lda (pData),y
bne .1
2015-06-03 18:30:57 +00:00
ldy #bCTRLC
lda (pData),y
bne CS.RUN.ERROR
jsr Wait.Timeout
bcc CS.RUN.WAIT
2015-06-03 18:30:57 +00:00
ldy #3
>PUSHB (pData),y DST.IP+3
dey
>PUSHB (pData),y DST.IP+2
dey
>PUSHB (pData),y DST.IP+1
>PUSHB (pData) DST.IP
>LDYA L.MSG2
>SYSCALL CPrintFYA
2015-06-03 18:30:57 +00:00
.1 ldy #bCTRLC
lda (pData),y
bne CS.RUN.ERROR
2015-06-03 18:30:57 +00:00
ldy #TimeOut
lda (pData),y
beq .2
>SYSCALL Sleep
bra .1
.2 jmp CS.RUN.ECHO
CS.RUN.ERROR sec
rts
*--------------------------------------
2015-06-03 18:30:57 +00:00
CS.DOEVENT lda (pEvent)
bpl .1 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
sec do not discard TIMER event
rts
.1 lda (pEvent)
and #S.EVT.F.KEY is it a KEY event?
beq .2
ldy #S.EVT.hDEV is Event from active IN device?
lda (pEvent),y
ldy #S.PS.hINDEV
2015-06-03 18:30:57 +00:00
cmp (pPs),y
bne .9
ldy #S.EVT.DATAHI is it an O or SAPPLE key ?
lda (pEvent),y
bne .9
ldy #S.EVT.DATALO
lda (pEvent),y
cmp #$03 Ctrl-C
bne .8
lda #$FF
2015-06-03 18:30:57 +00:00
ldy #bCTRLC
sta (pData),y
bra .8
.2 lda (pEvent)
and #S.EVT.F.NET
beq .9
ldy #S.EVT.hDEV
lda (pEvent),y
cmp hDev
bne .9
ldy #S.EVT.DATALO Get Frame hMem
lda (pEvent),y
>SYSCALL GetMemPtrA
>STYA ZPFrameBase1
ldy #S.IP.PROTOCOL
lda (ZPFrameBase1),y
cmp #S.IP.PROTOCOL.ICMP
bne .9
ldy #S.ICMP.TYPE
lda (ZPFrameBase1),y
cmp #S.ICMP.TYPE.ECHOREP
bne .9
ldy #S.ICMP.IDENTIFIER
lda (ZPFrameBase1),y
2015-06-03 18:30:57 +00:00
tax
iny
lda (ZPFrameBase1),y
2015-06-03 18:30:57 +00:00
ldy #Identifier+1
cmp (pData),y
bne .9
2015-06-03 18:30:57 +00:00
dey
txa
cmp (pData),y
bne .9
jsr CS.EVENT.REPLY
2015-06-03 18:30:57 +00:00
.8 clc
rts
.9 sec
rts
*--------------------------------------
CS.EVENT.REPLY lda #TIMEOUT.MAX
sec
ldy #TimeOut
sbc (pData),y
stz TimeOut.ms
stz TimeOut.ms+1
tay
beq .3
.1 lda TimeOut.ms
clc
adc #100
sta TimeOut.ms
bcc .2
2015-06-03 18:30:57 +00:00
inc TimeOut
.2 dey
bne .1
.3 >PUSHW TimeOut.ms
ldy #S.IP.TTL
>PUSHB (ZPFrameBase1),y
ldy #S.ICMP.SEQUENCE+1
>PUSHB (ZPFrameBase1),y
dey
>PUSHB (ZPFrameBase1),y
ldy #S.IP.SRC+3
>PUSHB (ZPFrameBase1),y
dey
>PUSHB (ZPFrameBase1),y
dey
>PUSHB (ZPFrameBase1),y
dey
>PUSHB (ZPFrameBase1),y
>LDYA L.MSG3
>SYSCALL CPrintFYA
2015-06-03 18:30:57 +00:00
ldy #bReply
lda (pData),y
inc
sta (pData),y
rts
*--------------------------------------
CS.QUIT lda hLIBTCPIP
>SYSCALL UnloadLibA
clc
rts
*--------------------------------------
Init.Timeout ldy #TimeOut
lda #TIMEOUT.MAX
sta (pData),y
rts
*--------------------------------------
Wait.TimeOut sec
ldy #TimeOut
lda (pData),y
beq .9
ldy #bCTRLC
lda (pData),y
bmi .9
clc
.9 rts
*--------------------------------------
CS.END
LIBTCPIP >PSTR "libtcpip.o"
MSG0 >CSTR "%S: Unknown host\n"
MSG1 >CSTR "PING %d.%d.%d.%d (%S)\n"
MSG2 >CSTR "%d.%d.%d.%d: TimeOut/Host unreachable\n"
MSG3 >CSTR "32 bytes from %d.%d.%d.%d, icmp_seq=%D, ttl=%d, time=%D ms\n"
hLIBTCPIP .BS 1
hDev .BS 1
2015-06-03 18:30:57 +00:00
TimeOut.ms .BS 2
*--------------------------------------
.DUMMY
.OR 0
DS.START
DST.IP .BS 4
hFrame .BS 1
TimeOut .BS 1
Identifier .BS 2
Sequence .BS 2
bCTRLC .BS 1
bReply .BS 1
DS.END
2015-06-03 18:30:57 +00:00
.ED
*--------------------------------------
MAN
SAVE BIN/PING.S
ASM