A2osX/BIN/ARP.S.txt
2018-08-22 17:23:27 +02:00

241 lines
4.6 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.

NEW
PREFIX /A2OSX.BUILD
AUTO 4,1
.LIST OFF
.OP 65C02
.OR $2000
.TF BIN/ARP
*--------------------------------------
.INB INC/MACROS.I
.INB INC/A2OSX.I
.INB INC/ETH.I
.INB INC/LIBTCPIP.I
*--------------------------------------
TIMEOUT.MAX .EQ 40 40*100ms = 4 sec.
*--------------------------------------
ZPPTR1 .EQ ZPBIN
*--------------------------------------
* 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 CS
.DA DS.END-DS.START DS
.DA #16 SS
.DA #2 ZP
.DA 0
*--------------------------------------
* Relocation Table
*--------------------------------------
.1 .DA CS.INIT
.DA CS.RUN
.DA CS.DOEVENT
.DA CS.QUIT
L.LIBTCPIP .DA LIBTCPIP
L.SSCANF.IP .DA SSCANF.IP
L.SSCANF.MAC .DA SSCANF.MAC
L.MSG0 .DA MSG0
L.MSG1 .DA MSG1
L.MSG2 .DA MSG2
.DA 0
*--------------------------------------
CS.INIT >LDYA L.LIBTCPIP
>SYSCALL LoadLib
bcs .9
sta hLIBTCPIP
lda (pPs)
ora #S.PS.F.EVENT Now accept events
sta (pPs)
clc
.9 rts
*--------------------------------------
CS.RUN ldy #S.PS.ARGC
lda (pPs),y
bne .1
jmp CS.RUN.DUMP
.1 >PUSHEA.G DST.IP+3
>PUSHEA.G DST.IP+2
>PUSHEA.G DST.IP+1
>PUSHEA.G DST.IP
>PUSHW L.SSCANF.IP
lda #1
>SYSCALL GetArg
>SYSCALL sscanf
bcs .9
ldy #S.PS.ARGC
lda (pPs),y
cmp #1
beq CS.RUN.QUERY
cmp #2
beq CS.RUN.ADD
.9 lda #K.E.SYN
sec
rts
*--------------------------------------
CS.RUN.QUERY jsr Init.Timeout
.1 >PUSHEA.G DST.MAC
>PUSHEA.G DST.IP
>LIBCALL hLIBTCPIP,LIBTCPIP.ARP.QUERY
bcc .2 success, print & exit
jsr Wait.TimeOut
bcs .9
>SLEEP
>SYSCALL GetChar
bcs .1
cmp #3
beq .8
bra .1
.2 ldy #5
.3 >PUSHB.G DST.MAC,y
dey
bpl .3
ldy #3
.4 >PUSHB.G DST.IP,y
dey
bpl .4
>PUSHBI 10
>LDYA L.MSG2
>SYSCALL printf
.8 lda #0
.9 sec
rts
*--------------------------------------
CS.RUN.ADD >PUSHEA.G DST.MAC+5
>PUSHEA.G DST.MAC+4
>PUSHEA.G DST.MAC+3
>PUSHEA.G DST.MAC+2
>PUSHEA.G DST.MAC+1
>PUSHEA.G DST.MAC
>PUSHW L.SSCANF.MAC
lda #2
>SYSCALL GetArg
>SYSCALL sscanf
bcs .9
>PUSHEA.G DST.MAC
>PUSHEA.G DST.IP
>LIBCALL hLIBTCPIP,LIBTCPIP.ARP.ADD
bcc CS.RUN.DUMP
rts
.9 lda #K.E.SYN
.99 sec
rts
*--------------------------------------
CS.RUN.DUMP >LIBCALL hLIBTCPIP,LIBTCPIP.ARP.GETCACHE
>STYA ZPPTR1
>LDYA L.MSG0
>SYSCALL puts
ldx #K.ARPCACHE.SIZE
.1 lda (ZPPTR1)
beq .4
ldy #S.ARPCACHE.IP+4
.2 dey
>PUSHB (ZPPTR1),y
cpy #S.ARPCACHE.IP
bne .2
ldy #S.ARPCACHE.MAC+6
.3 dey
>PUSHB (ZPPTR1),y
cpy #S.ARPCACHE.MAC
bne .3
ldy #S.ARPCACHE.TTL+1
>PUSHB (ZPPTR1),y
dey
>PUSHB (ZPPTR1),y
>PUSHB (ZPPTR1)
>PUSHBI 13
>LDYA L.MSG1
phx
>SYSCALL printf
plx
.4 lda ZPPTR1
clc
adc #S.ARPCACHE
sta ZPPTR1
bcc .5
inc ZPPTR1+1
.5 dex
bne .1
.8 lda #0 tell TSKMGR that all done ok, but
sec we do not want to stay in memory
rts
*--------------------------------------
CS.DOEVENT lda (pEvent)
bpl .9 is it a TIMER event?
ldy #TimeOut
lda (pData),y
beq .9
dec
sta (pData),y
.9 sec do not discard TIMER event
rts
*--------------------------------------
CS.QUIT lda hLIBTCPIP
>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
clc
.9 rts
*--------------------------------------
CS.END
LIBTCPIP .AZ "libtcpip.o"
SSCANF.IP .AZ "%d.%d.%d.%d"
SSCANF.MAC .AZ "%h:%h:%h:%h:%h:%h"
MSG0 .AZ "STS TTL MAC Address IP Address"
MSG1 .AZ "$%h %5D %h:%h:%h:%h:%h:%h %d.%d.%d.%d\r\n"
MSG2 .AZ "%d.%d.%d.%d is at %h:%h:%h:%h:%h:%h\r\n"
hLIBTCPIP .BS 1
*--------------------------------------
DS.START
DST.IP .BS 4
DST.MAC .BS 6
TimeOut .BS 1
DS.END
*--------------------------------------
MAN
SAVE /A2OSX.SRC/BIN/ARP.S
ASM