A2osX/LIB/LIBTCPIP.S.UDP.txt

169 lines
2.9 KiB
Plaintext
Raw Normal View History

PR#3
PREFIX /A2OSX.SRC
NEW
INC 1
AUTO 6
.LIST OFF
*--------------------------------------
UDP.IN ldy #S.IP.SRC+3
ldx #3
.1 lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.DST.ADDR,x
dey
dex
bpl .1
ldy #S.UDP.SRCPORT
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.DST.PORT+1
iny
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.DST.PORT
ldy #S.IP.DST+3
ldx #3
.2 lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.SRC.ADDR,x
dey
dex
bpl .2
ldy #S.UDP.DSTPORT
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.SRC.PORT+1
iny
lda (ZPFrameBase1),y
sta TmpSocket+S.SOCKET.SRC.PORT
>LDYA L.SKT.TABLE
>STYA ZPPtrSKT
ldx #0
.3 lda (ZPPtrSKT)
beq .7
cmp #S.SOCKET.SOCK.DGRAM
bne .7
ldy #S.SOCKET.SRC.ADDR
.4 lda TmpSocket,y
cmp (ZPPtrSKT),y
bne .7
iny
cpy #S.SOCKET.DST.PORT+2
bne .4
jsr SKT.AddToQueueD
bcs .99
lda (pEvent) Make sure kernel not discard frame...
and #$FF^S.EVT.F.hMEM1
sta (pEvent)
clc ...when clearing event!!!!
rts
.7 lda ZPPtrSKT
clc
adc #S.SOCKET
sta ZPPtrSKT
bcc .8
inc ZPPtrSKT+1
.8 inx
cpx #K.SKTTABLE.SIZE
bne .3
.9 sec
.99 rts
*--------------------------------------
UDP.ComputeChecksum
lda #0 RESET.TCP.CHECKSUM
ldy #S.UDP.CHECKSUM
sta (ZPFrameBase1),y
iny
sta (ZPFrameBase1),y
>LDYA ZPFrameBase1
>STYA ZPTmpPtr1
lda ZPFrameLen1
sec
sbc #S.IP-2
sta ZPDataLen
lda ZPFrameLen1+1
sbc /S.IP-2
sta ZPDataLen+1
clc
ldy #S.UDP.LENGTH
lda (ZPFrameBase1),y
* adc #0 RESERVED (all zero)
sta IP.CHECKSUM
iny
lda (ZPFrameBase1),y
adc #S.IP.PROTOCOL.UDP
sta IP.CHECKSUM+1
ldy #S.IP.SRC
ldx #4 4 words for SRC & DST IP
.10 lda (ZPFrameBase1),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
lda (ZPFrameBase1),y
adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
dex
bne .10
ldy #S.IP
.1 jsr DecDataLen
beq .8
lda (ZPTmpPtr1),y
adc IP.CHECKSUM
sta IP.CHECKSUM
iny
bne .20
inc ZPTmpPtr1+1
.20 jsr DecDataLen
bne .2
lda #0
bra .21
.2 lda (ZPTmpPtr1),y
.21 adc IP.CHECKSUM+1
sta IP.CHECKSUM+1
iny
bne .1
inc ZPTmpPtr1+1
bra .1
.8 ldy #S.UDP.CHECKSUM
lda IP.CHECKSUM
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameBase1),y
iny
lda IP.CHECKSUM+1
adc #0 Don't forget to add last carry!!!
eor #$FF
sta (ZPFrameBase1),y
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.UDP
LOAD LIB/LIBTCPIP.S
ASM