mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-23 07:35:19 +00:00
435 lines
7.4 KiB
Plaintext
435 lines
7.4 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
LOMEM $A00
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
*/--------------------------------------
|
||
* #SKT.New
|
||
* ##In :
|
||
* PUSHW = PTR to S.SOCKET template
|
||
* ##Out :
|
||
* YA = PTR to new S.SOCKET
|
||
* X = hSocket
|
||
*\--------------------------------------
|
||
SKT.New >PULLW ZPTmpPtr1
|
||
|
||
ldy #S.SOCKET.SRC.PORT+1
|
||
lda (ZPTmpPtr1),y
|
||
dey
|
||
ora (ZPTmpPtr1),y
|
||
bne .1
|
||
|
||
jsr GetDynPort
|
||
sta (ZPTmpPtr1),y
|
||
txa
|
||
iny
|
||
sta (ZPTmpPtr1),y
|
||
|
||
.1 >LDYA L.SKT.TABLE
|
||
>STYA ZPTmpPtr2
|
||
|
||
lda #$ff
|
||
sta TmpOffset to keep track of any free slot
|
||
|
||
ldx #0
|
||
|
||
.2 lda (ZPTmpPtr2)
|
||
beq .4 empty!!!
|
||
|
||
cmp (ZPTmpPtr1)
|
||
bne .5 not same SKT type...try next
|
||
|
||
ldy #S.SOCKET.SRC.ADDR
|
||
|
||
.3 lda (ZPTmpPtr1),y
|
||
cmp (ZPTmpPtr2),y
|
||
bne .5
|
||
iny
|
||
cpy #S.SOCKET.DST.PORT+2
|
||
bne .3
|
||
|
||
lda #ERR.SKT.BUSY same one!!!!! busy...
|
||
sec
|
||
rts
|
||
|
||
.4 lda TmpOffset
|
||
bpl .5 already found an empty slot....
|
||
|
||
>LDYA ZPTmpPtr2 found one...
|
||
>STYA ZPTmpPtr3 save it!
|
||
stx TmpOffset
|
||
|
||
.5 lda ZPTmpPtr2
|
||
clc
|
||
adc #S.SOCKET
|
||
sta ZPTmpPtr2
|
||
bcc .6
|
||
inc ZPTmpPtr2+1
|
||
.6 inx
|
||
cpx #K.SKTTABLE.SIZE
|
||
bne .2
|
||
|
||
lda TmpOffset Did we found an empty slot ?
|
||
bmi .9
|
||
|
||
ldy #S.SOCKET-1
|
||
.7 lda (ZPTmpPtr1),y
|
||
sta (ZPTmpPtr3),y
|
||
dey
|
||
bpl .7
|
||
|
||
ldx TmpOffset
|
||
>LDYA ZPTmpPtr3
|
||
clc
|
||
rts
|
||
|
||
.9 lda #ERR.SKT.OOS
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
SKT.ACCEPTA jsr SKT.GetA.I
|
||
bcs .9
|
||
ldy #S.SOCKET.SO
|
||
lda (ZPPtrSKT),y
|
||
and #S.SOCKET.SO.ACCEPTCONN
|
||
bne .99
|
||
|
||
ldy #S.SOCKET.HQ.HEAD
|
||
lda (ZPPtrSKT),y
|
||
ldy #S.SOCKET.HQ.TAIL
|
||
cmp (ZPPtrSKT),y Queue Empty
|
||
beq .9 CC
|
||
pha
|
||
inc
|
||
cmp #S.SOCKET.HQ.MAX
|
||
bne .1
|
||
lda #0
|
||
.1 sta (ZPPtrSKT),y
|
||
pla
|
||
clc
|
||
adc #S.SOCKET.HQ
|
||
tay
|
||
lda (ZPPtrSKT),y
|
||
clc
|
||
rts
|
||
|
||
.99 lda #ERR.SKT.BAD
|
||
sec
|
||
.9 rts
|
||
*--------------------------------------
|
||
* SKT.Send
|
||
*--------------------------------------
|
||
SKT.Send >PULLB hSocket
|
||
pha
|
||
>PULLW ZPDataInPtr
|
||
>PULLW ZPDataInLen
|
||
|
||
pla
|
||
jsr SKT.GetA.I
|
||
bcs .9
|
||
and #S.SOCKET.SOCK.MASK
|
||
cmp #S.SOCKET.SOCK.DGRAM
|
||
beq SKT.SEND.UDP
|
||
|
||
cmp #S.SOCKET.SOCK.STREAM
|
||
bne .1
|
||
jmp SKT.SEND.TCP
|
||
|
||
.1 cmp #S.SOCKET.SOCK.RAW
|
||
bne .99
|
||
jmp SKT.SEND.RAW
|
||
|
||
.99 sec
|
||
.9 rts
|
||
*--------------------------------------
|
||
SKT.SEND.UDP lda #S.IP.PROTOCOL.UDP
|
||
jsr FRM.NewA
|
||
bcs .9
|
||
|
||
>LDAXI S.UDP-2
|
||
jsr SKT.SetFrameOutLenAX
|
||
|
||
>LDAXI S.UDP
|
||
jsr SKT.SetDataOutPtrAX
|
||
|
||
jsr SKT.SetFrameOutDstIP
|
||
|
||
jsr SKT.SetFrameOutPorts
|
||
|
||
jsr SKT.CopyDataInToOut
|
||
|
||
jmp FRM.SendUDP
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
SKT.SEND.TCP ldy #S.SOCKET.STREAM.hOutMem
|
||
lda (ZPPtrSKT),y
|
||
>SYSCALL GetMemPtrA
|
||
>STYA ZPTmpPtr1 Make ZPTmpPtr1=buffer base
|
||
|
||
ldy #S.SOCKET.SQ.OUTHEAD
|
||
lda (ZPPtrSKT),y
|
||
* clc
|
||
adc ZPDataInLen
|
||
tax
|
||
|
||
iny
|
||
lda (ZPPtrSKT),y
|
||
adc ZPDataInLen+1
|
||
|
||
|
||
clc
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
SKT.SEND.RAW ldy #S.SOCKET.RAW.PROTO
|
||
lda (ZPPtrSKT),y
|
||
|
||
jsr FRM.NewA
|
||
bcs .9
|
||
|
||
>LDAXI S.IP-2
|
||
jsr SKT.SetFrameOutLenAX
|
||
|
||
>LDAXI S.IP
|
||
jsr SKT.SetDataOutPtrAX
|
||
|
||
jsr SKT.SetFrameOutDstIP
|
||
|
||
jsr SKT.CopyDataInToOut
|
||
|
||
ldy #S.SOCKET.RAW.PROTO
|
||
lda (ZPPtrSKT),y
|
||
cmp #S.IP.PROTOCOL.ICMP
|
||
bne .1
|
||
jmp FRM.SendICMP
|
||
.1 jmp FRM.SendIP
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
SKT.RCVDA jsr SKT.GetA.I
|
||
bcs .9
|
||
|
||
ldy #S.SOCKET.HQ.TAIL
|
||
lda (ZPPtrSKT),y
|
||
tax
|
||
|
||
ldy #S.SOCKET.HQ.HEAD
|
||
cmp (ZPPtrSKT),y
|
||
beq .99
|
||
|
||
inc
|
||
cmp #S.SOCKET.HQ.MAX
|
||
bne .1
|
||
lda #0
|
||
|
||
.1 ldy #S.SOCKET.HQ.TAIL
|
||
sta (ZPPtrSKT),y
|
||
|
||
txa
|
||
clc
|
||
adc #S.SOCKET.HQ
|
||
tay
|
||
lda (ZPPtrSKT),y
|
||
clc
|
||
rts
|
||
|
||
.99 sec
|
||
.9 rts
|
||
*--------------------------------------
|
||
SKT.CLOSEA cmp #K.SKTTABLE.SIZE
|
||
bcs SKT.GetA.9
|
||
|
||
jsr SKT.GetA.I
|
||
bcs .9
|
||
|
||
and #S.SOCKET.SOCK.MASK
|
||
cmp #S.SOCKET.SOCK.DGRAM
|
||
beq .8
|
||
|
||
cmp #S.SOCKET.SOCK.RAW
|
||
beq .8
|
||
|
||
ldy #S.SOCKET.SO
|
||
lda (ZPPtrSKT),y
|
||
bit #S.SOCKET.SO.ACCEPTCONN
|
||
|
||
beq *
|
||
|
||
|
||
.8 lda #0
|
||
sta (ZPPtrSKT)
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
SKT.GetA cmp #K.SKTTABLE.SIZE
|
||
bcs SKT.GetA.9
|
||
jsr SKT.GetA.I
|
||
bcs SKT.GetA.9
|
||
>LDYA ZPPtrSKT
|
||
rts
|
||
|
||
SKT.GetA.I stz ZPPtrSKT
|
||
|
||
lsr
|
||
ror ZPPtrSKT
|
||
lsr
|
||
ror ZPPtrSKT
|
||
lsr
|
||
ror ZPPtrSKT
|
||
|
||
pha
|
||
|
||
lda ZPPtrSKT
|
||
adc L.SKT.TABLE
|
||
sta ZPPtrSKT
|
||
pla
|
||
adc L.SKT.TABLE+1
|
||
sta ZPPtrSKT+1
|
||
|
||
lda (ZPPtrSKT)
|
||
beq SKT.GetA.9
|
||
|
||
rts CC
|
||
|
||
SKT.GetA.9 lda #ERR.SKT.BAD
|
||
sec
|
||
rts
|
||
*--------------------------------------
|
||
* ZPPtrSKT -> actual socket
|
||
* A = hSocket or hFrame
|
||
*--------------------------------------
|
||
SKT.AddToQueueA sta .2+1
|
||
ldy #S.SOCKET.HQ.HEAD
|
||
lda (ZPPtrSKT),y
|
||
tax
|
||
inc
|
||
cmp #S.SOCKET.HQ.MAX
|
||
bne .1
|
||
lda #0
|
||
.1 ldy #S.SOCKET.HQ.TAIL
|
||
cmp (ZPPtrSKT),y
|
||
beq .9 Queue full!!
|
||
|
||
ldy #S.SOCKET.HQ.HEAD
|
||
sta (ZPPtrSKT),y
|
||
txa
|
||
clc
|
||
adc #S.SOCKET.HQ
|
||
tay
|
||
|
||
.2 lda #$ff
|
||
sta (ZPPtrSKT),y
|
||
clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
SKT.GETTABLE >LDYA L.SKT.TABLE
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
SKT.AddToQueueS
|
||
clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
SKT.SetFrameOutLenAX
|
||
clc
|
||
adc ZPDataInLen
|
||
sta (ZPFrameOutPtr)
|
||
sta ZPFrameOutLen
|
||
|
||
txa
|
||
adc ZPDataInLen+1
|
||
ldy #1
|
||
sta (ZPFrameOutPtr),y
|
||
sta ZPFrameOutLen+1
|
||
rts
|
||
*--------------------------------------
|
||
SKT.SetDataOutPtrAX
|
||
clc
|
||
adc ZPFrameOutPtr
|
||
sta ZPDataOutPtr
|
||
txa
|
||
adc ZPFrameOutPtr+1
|
||
sta ZPDataOutPtr+1
|
||
rts
|
||
*--------------------------------------
|
||
SKT.SetFrameOutDstIP
|
||
ldy #S.SOCKET.DST.ADDR
|
||
ldx #4
|
||
|
||
.1 lda (ZPPtrSKT),y
|
||
pha
|
||
iny
|
||
dex
|
||
bne .1
|
||
|
||
ldy #S.IP.DST+3
|
||
ldx #4
|
||
|
||
.2 pla
|
||
sta (ZPFrameOutPtr),y
|
||
dey
|
||
dex
|
||
bne .2
|
||
rts
|
||
*--------------------------------------
|
||
SKT.SetFrameOutPorts
|
||
ldy #S.SOCKET.SRC.PORT
|
||
lda (ZPPtrSKT),y
|
||
tax
|
||
iny
|
||
lda (ZPPtrSKT),y
|
||
ldy #S.UDP.SRCPORT
|
||
sta (ZPFrameOutPtr),y
|
||
iny
|
||
txa
|
||
sta (ZPFrameOutPtr),y
|
||
|
||
ldy #S.SOCKET.DST.PORT
|
||
lda (ZPPtrSKT),y
|
||
tax
|
||
iny
|
||
lda (ZPPtrSKT),y
|
||
ldy #S.UDP.DSTPORT
|
||
sta (ZPFrameOutPtr),y
|
||
iny
|
||
txa
|
||
sta (ZPFrameOutPtr),y
|
||
*--------------------------------------
|
||
SKT.CopyDataInToOut
|
||
lda ZPDataInLen
|
||
eor #$ff
|
||
sta ZPDataInLen
|
||
lda ZPDataInLen+1
|
||
eor #$ff
|
||
tax
|
||
|
||
ldy #0
|
||
|
||
.1 inc ZPDataInLen
|
||
bne .2
|
||
inx
|
||
beq .9
|
||
|
||
.2 lda (ZPDataInPtr),y
|
||
sta (ZPDataOutPtr),y
|
||
iny
|
||
bne .1
|
||
inc ZPDataInPtr+1
|
||
inc ZPDataOutPtr+1
|
||
bne .1
|
||
.9 rts
|
||
|
||
MAN
|
||
SAVE LIB/LIBTCPIP.S.SKT
|
||
LOAD LIB/LIBTCPIP.S
|
||
ASM
|