A2osX/BIN/RPCINFO.S.txt
2015-11-22 23:30:06 +01:00

402 lines
7.5 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
.OP 65C02
.OR $2000
.TF /A2OSX.BOOT/BIN/RPCINFO
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/LIBSTR.I
.INB INC/LIBTCPIP.I
*--------------------------------------
RPCINFO.TIMEOUT .EQ 40 40*100ms = 4 sec.
*--------------------------------------
ZPFrameBase1 .EQ ZPBIN
ZPFrameLen1 .EQ ZPBIN+2
ZPFramePtr1 .EQ ZPBIN+4
ZPIPCfgPtr .EQ ZPBIN+6
*--------------------------------------
* File Header (16 Bytes)
*--------------------------------------
CS.START cld
jmp (.1,x)
.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
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBSTR .DA LIBSTR
L.LIBTCPIP .DA LIBTCPIP
L.SSCANF.IP .DA SSCANF.IP
L.MSG0 .DA MSG0
L.MSG1 .DA MSG1
L.MSG2 .DA MSG2
L.MSG3 .DA MSG3
.DA 0
*--------------------------------------
CS.INIT ldy #S.PS.hARGS
lda (pPs),y
bne .1
lda #SYSMGR.ERRSYN
sec
rts
.1 >LDYA L.LIBSTR
>SYSCALL SYS.LoadLibYA
sta hLIBSTR
>LDYA L.LIBTCPIP
>SYSCALL SYS.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
ldy #XID
sta (pData),y
lda A2OSX.RANDOM16+1
iny
sta (pData),y
lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
.9 rts
*--------------------------------------
CS.RUN >PUSHW pData DST.IP
>PUSHW L.SSCANF.IP
ldy #S.PS.hARGS
lda (pPs),y
>SYSCALL SYS.GetMemPtrA
>PUSHYA
>LIBCALL hLIBSTR,LIBSTR.SSCANF
bcc CS.RUN.IPOK
lda #RPCINFO.TIMEOUT
ldy #TimeOut
sta (pData),y
CS.RUN.DNSQUERY >PUSHW pData DST.IP
ldy #S.PS.hARGS
lda (pPs),y
>SYSCALL SYS.GetMemPtrA
>PUSHYA
>LIBCALL hLIBTCPIP,LIBTCPIP.DNS.QUERY
bcc CS.RUN.IPOK
jsr A2osX.SLEEP
ldy #TimeOut
lda (pData),y
bne CS.RUN.DNSQUERY
ldy #S.PS.hARGS
lda (pPs),y
>SYSCALL SYS.GetMemPtrA
>PUSHYA
>PUSHW L.MSG0
>LIBCALL hLIBSTR,LIBSTR.PRINTF
sec
CS.RUN.RTS rts
CS.RUN.IPOK ldy #S.PS.hARGS
lda (pPs),y
>SYSCALL SYS.GetMemPtrA
>PUSHYA
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
>PUSHW L.MSG1
>LIBCALL hLIBSTR,LIBSTR.PRINTF
CS.RUN.RPCCALL >LIBCALL hLIBTCPIP,LIBTCPIP.NEW.UDP.FRAME
bcs CS.RUN.RTS
>STYA ZPFrameBase1
txa
ldy #hFrame
sta (pData),y
ldx #3
ldy #DST.IP
.10 lda (pData),y
pha
iny
dex
bpl .10
ldx #3
ldy #S.IP.DST+3
.1 pla
sta (ZPFrameBase1),y
dey
dex
bpl .1
ldy #S.UDP.SRCPORT
lda #UDP.PORT.PMAP
sta (ZPFrameBase1),y
ldy #S.UDP.DSTPORT
sta (ZPFrameBase1),y
ldy #XID
lda (pData),y
tax
iny
lda (pData),y
ldy #S.RPC.XID+1
sta (ZPFrameBase1),y
dey
txa
sta (ZPFrameBase1),y
.3 >PUSHWI S.RPC+32
ldy #hFrame
lda (pData),y
>SYSCALL SYS.GetMemPtrA
>PUSHYA
>LIBCALL hLIBTCPIP,LIBTCPIP.SEND.UDP.FRAME
bcc .4
jsr A2osX.SLEEP
ldy #TimeOut
lda (pData),y
bne .3
.4 ldy #hFrame
lda (pData),y
>SYSCALL SYS.FreeMemA
ldy #bReply
lda #0
sta (pData),y
lda #RPCINFO.TIMEOUT
ldy #TimeOut
sta (pData),y
CS.RUN.WAIT jsr A2osX.SLEEP
ldy #bReply
lda (pData),y
bne .1
ldy #bCTRLC
lda (pData),y
bne CS.RUN.ERROR
ldy #TimeOut
lda (pData),y
bne CS.RUN.WAIT
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
>PUSHW L.MSG2
>LIBCALL hLIBSTR,LIBSTR.PRINTF
.1 ldy #bCTRLC
lda (pData),y
bne CS.RUN.ERROR
ldy #TimeOut
lda (pData),y
beq .2
jsr A2osX.SLEEP
bra .1
.2
CS.RUN.ERROR sec
rts
*--------------------------------------
CS.DOEVENT lda (pEvent)
and #S.EVT.F.TIMER is it a TIMER event?
beq .1 no....
ldy #TimeOut
lda (pData),y
beq .10
dec
sta (pData),y
.10 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
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
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 SYS.GetMemPtrA
>STYA ZPFrameBase1
ldy #S.IP.PROTOCOL
lda (ZPFrameBase1),y
cmp #S.IP.PROTOCOL.UDP
bne .9
ldy #S.UDP.DSTPORT
lda (ZPFrameBase1),y
cmp #S.ICMP.TYPE.ECHOREP
bne .9
ldy #S.RPC.XID
lda (ZPFrameBase1),y
tax
iny
lda (ZPFrameBase1),y
ldy #XID+1
cmp (pData),y
bne .9
dey
txa
cmp (pData),y
bne .9
jsr CS.EVENT.REPLY
.8 clc
rts
.9 sec
rts
*--------------------------------------
CS.EVENT.REPLY lda #RPCINFO.TIMEOUT
sec
sbc TimeOut
stz TimeOut.ms
stz TimeOut.ms+1
tay
beq .3
.1 lda TimeOut.ms
clc
adc #K.TIMER16RESOLUTION*20
sta TimeOut.ms
bcc .2
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
>PUSHW L.MSG3
>LIBCALL hLIBSTR,LIBSTR.PRINTF
ldy #bReply
lda (pData),y
inc
sta (pData),y
rts
*--------------------------------------
CS.QUIT lda hLIBTCPIP
>SYSCALL SYS.UnloadLibA
lda hLIBSTR
>SYSCALL SYS.UnloadLibA
clc
rts
*--------------------------------------
CS.END
LIBSTR >PSTRING "libstr.o"
LIBTCPIP >PSTRING "libtcpip.o"
SSCANF.IP >PSTRING "%d.%d.%d.%d"
MSG0 >CSTRING "%S: Unknown host\n"
MSG1 >CSTRING "PING %d.%d.%d.%d (%S)\n"
MSG2 >CSTRING "%d.%d.%d.%d: TimeOut/Host unreachable\n"
MSG3 >CSTRING "32 bytes from %d.%d.%d.%d, icmp_seq=%D, ttl=%d, time=%D ms\n"
hLIBSTR .BS 1
hLIBTCPIP .BS 1
hDev .BS 1
TimeOut.ms .BS 2
*--------------------------------------
.DUMMY
.OR 0
DS.START
DST.IP .BS 4
hFrame .BS 1
TimeOut .BS 1
XID .BS 4
bCTRLC .BS 1
bReply .BS 1
DS.END
.ED
*--------------------------------------
MAN
SAVE BIN/RPCINFO.S
ASM