A2osX/LIB/LIBTCPIP.S.SKT.txt
2016-01-16 23:04:22 +01:00

225 lines
3.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
*--------------------------------------
SKT.NEW >PULLW ZPPtrSKT
stz bFound
ldy #S.SOCKET.SRC.PORT+1
lda (ZPPtrSKT),y
dey
ora (ZPPtrSKT),y
bne .1
jsr GetDynPort
sta (ZPPtrSKT),y
txa
iny
sta (ZPPtrSKT),y
.1 >LDYA L.SKT.TABLE
>STYA ZPTmpPtr1
ldx #0
.2 lda (ZPTmpPtr1)
beq .4
ldy #S.SOCKET.SRC.PORT+1
.3 lda (ZPPtrSKT),y
cmp (ZPTmpPtr1),y
bne .5
dey
bpl .3
lda ERR.SBUSY
sec
rts
.4 bit bFound
bmi .5
sec
ror bFound
stx hSocket
>LDYA ZPTmpPtr1
>STYA ZPTmpPtr2
.5 lda ZPTmpPtr1
clc
adc #S.SOCKET
sta ZPTmpPtr1
bcc .6
inc ZPTmpPtr1+1
.6 inx
cpx #K.SKTTABLE.SIZE
bne .2
bit bFound
bpl .9
ldy #S.SOCKET-1
.7 lda (ZPPtrSKT),y
sta (ZPTmpPtr2),y
dey
bpl .7
lda hSocket
clc
rts
.9 lda ERR.OOS
sec
rts
*--------------------------------------
SKT.LISTEN
sec
rts
*--------------------------------------
SKT.ACCEPT
sec
rts
*--------------------------------------
SKT.SENDA
sec
rts
*--------------------------------------
SKT.SEND >PULLB hSocket
pha
>PULLW ZPDataPtr
>PULLW ZPDataLen
pla
jsr SKT.GetA
bcs .9
cmp #S.SOCKET.SOCK.DGRAM
beq SKT.SEND.UDP
bra *
sec
.9 rts
*--------------------------------------
SKT.SEND.UDP jsr NEW.UDP.FRAME
bcs .9
>STYA ZPFrameBase1
lda #S.UDP
clc
adc ZPDataLen
sta ZPFrameLen1
lda /S.UDP
adc ZPDataLen+1
sta ZPFrameLen1+1
ldy #S.SOCKET.SRC.PORT
lda (ZPPtrSKT),y
tax
iny
lda (ZPPtrSKT),y
ldy #S.UDP.SRCPORT
sta (ZPFrameBase1),y
iny
txa
sta (ZPFrameBase1),y
ldy #S.SOCKET.SRC.ADDR
ldx #4
.1 lda (ZPPtrSKT),y
pha
iny
dex
bne .1
ldy #S.IP.DST+3
ldx #4
.2 pla
sta (ZPFrameBase1),y
dey
dex
bne .2
ldy #S.SOCKET.DST.PORT
lda (ZPPtrSKT),y
tax
iny
lda (ZPPtrSKT),y
ldy #S.UDP.DSTPORT
sta (ZPFrameBase1),y
iny
txa
sta (ZPFrameBase1),y
lda #S.UDP
clc
adc ZPFrameBase1
sta ZPTmpPtr1
lda /S.UDP
adc ZPFrameBase1+1
sta ZPTmpPtr1+1
ldy #0
.3 jsr DecDataLen
beq .4
lda (ZPDataPtr),y
sta (ZPTmpPtr1),y
iny
bne .3
inc ZPDataPtr
inc ZPTmpPtr1
bra .3
.4 jmp SEND.UDP.FRAME.I
.9 rts
*--------------------------------------
SKT.RCVDA
sec
rts
*--------------------------------------
SKT.RCVD
sec
rts
*--------------------------------------
SKT.CLOSE
sec
rts
*--------------------------------------
SKT.GETTABLE >LDYA L.SKT.TABLE
clc
rts
*--------------------------------------
SKT.GetA stz ZPPtrSKT+1
asl
rol ZPPtrSKT+1
asl
rol ZPPtrSKT+1
asl
rol ZPPtrSKT+1
asl
rol ZPPtrSKT+1
adc L.SKT.TABLE
sta ZPPtrSKT
lda ZPPtrSKT+1
adc L.SKT.TABLE+1
sta ZPPtrSKT+1
lda (ZPPtrSKT)
beq .9
rts CC
.9 lda #ERR.SBAD
sec
rts
*--------------------------------------
MAN
SAVE LIB/LIBTCPIP.S.SKT
LOAD LIB/LIBTCPIP.S
ASM