A2osX/LIB/LIBTCPIP.S.SKT.txt
2018-07-23 08:28:47 +02:00

1298 lines
24 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
*/--------------------------------------
* # SKT.New
* Create a new socket
* **In:**
* PUSHW = PTR to S.SOCKET template
* **Out:**
* YA = PTR to new S.SOCKET
* X = hSocket
*\--------------------------------------
SKT.New clc
.HS B0 BCS
SKT.New.Listen sec
ror
sta .71+1
>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 lda hSocketTable
>SYSCALL GetMemPtr
>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.HDR-1
.7 lda (ZPTmpPtr1),y
sta (ZPTmpPtr3),y
dey
bpl .7
lda (ZPTmpPtr1)
cmp #S.SOCKET.SOCK.STREAM
bne .8
ldy #S.SOCKET.SO
lda (ZPTmpPtr1),y
and #S.SOCKET.SO.ACCEPTCONN
bne .8
jsr SKT.NewTCB
bcs .99
.71 lda #$ff
bmi .8 From Listen, do not send SYN packet
>LDYA ZPTmpPtr3
>STYA ZPPtrSKT
lda #S.TCP.OPTIONS.SYN
jsr TCP.OUT.SendOptA Send SYN,Only for CLIENT conn!!!!
bcs .99
ldy #S.SOCKET.TCP.STATUS
lda #S.SOCKET.TCP.STATUS.SYNSENT
sta (ZPPtrSKT),y
.8 lda TmpOffset
ora #$80
tax
>LDYA ZPTmpPtr3
clc
rts
.9 lda #ERR.SKT.OOS
sec
.99 rts
*/--------------------------------------
* # SKT.CloseA
* Close socket
* **In:**
* A = hSocket
* **Out:**
*\--------------------------------------
SKT.CloseA jsr SKT.GetA.I get SKT in ZPPtrSKT, S.SOCKET.SOCK in A
bcs .99
cmp #S.SOCKET.SOCK.STREAM
beq .10 TCP
bcc .9 no #S.SOCKET.SOCK.DGRAM, nor #S.SOCKET.SOCK.RAW
.1 ldy #S.SOCKET.HQ.TAIL
lda (ZPPtrSKT),y
ldy #S.SOCKET.HQ.HEAD
cmp (ZPPtrSKT),y
beq .8 No frame in Queue, close..
pha save tail...
clc
adc #S.SOCKET.HQ
tax
pla
inc
cmp #S.SOCKET.HQ.MAX
beq .2
lda #0
.2 ldy #S.SOCKET.HQ.TAIL
sta (ZPPtrSKT),y
txa
tay
lda (ZPPtrSKT),y
>SYSCALL FreeMem
bra .1
.8 lda #0
sta (ZPPtrSKT)
clc
rts
.9 lda #ERR.SKT.BAD
sec
.99 rts
.10 ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
bit #S.SOCKET.SO.ACCEPTCONN
bne * TO DO: Listening socket
ldy #S.SOCKET.TCP.OPTIONS
lda (ZPPtrSKT),y
ora #S.TCP.OPTIONS.FIN
sta (ZPPtrSKT),y
jsr TCP.OUT SKT.Close, Try to push FIN
clc
rts
*/--------------------------------------
* # SKT.GetA
* Get Ptr to socket
* **In:**
* A = hSocket
* **Out:**
* Y,A = pS.SOCKET
*\--------------------------------------
SKT.GetA jsr SKT.GetA.I
bcs .9
>LDYA ZPPtrSKT
.9 rts
SKT.GetA.I and #$7f
cmp #K.SKTTABLE.SIZE
bcs .9
pha
lda hSocketTable
>SYSCALL GetMemPtr
>STYA ZPPtrSKT
pla
beq .8
stz .1+1
lsr
ror .1+1
lsr
ror .1+1
lsr
ror .1+1
pha
lda ZPPtrSKT
clc
.1 adc #$ff
sta ZPPtrSKT
pla
adc ZPPtrSKT+1
sta ZPPtrSKT+1
.8 lda (ZPPtrSKT)
beq .9
clc
rts
.9 lda #ERR.SKT.BAD
sec
rts
*/--------------------------------------
* # SKT.GetTable
* Get socket table
* **In:**
* **Out:**
* Y,A = pS.SOCKET
*\--------------------------------------
SKT.GetTable lda hSocketTable
>SYSCALL GetMemPtr
clc
rts
*/--------------------------------------
* # SKT.AcceptA
* Check for an incoming connection
* **In:**
* A = hListeningSocket
* **Out:**
* A = hSocket
*\--------------------------------------
SKT.AcceptA jsr SKT.GetA.I
bcs .9
ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
and #S.SOCKET.SO.ACCEPTCONN
beq .99
ldy #S.SOCKET.HQ.TAIL
lda (ZPPtrSKT),y
ldy #S.SOCKET.HQ.HEAD
cmp (ZPPtrSKT),y Queue Empty
beq .9 CS
pha save tail...
inc
cmp #S.SOCKET.HQ.MAX
bne .1
lda #0
.1 ldy #S.SOCKET.HQ.TAIL
sta (ZPPtrSKT),y
pla
clc
adc #S.SOCKET.HQ
tay
lda (ZPPtrSKT),y
clc
rts
.99 lda #ERR.SKT.BAD
sec
.9 rts
*/--------------------------------------
* # SKT.MkNodA
* Create a new file from TCP socket
* **In:**
* A = hSocket
* **Out:**
* A = hFile
*\--------------------------------------
SKT.MkNodA sta .1+1
>LDYAI S.FD.SSOCK
>SYSCALL getmem0
bcs .9
>STYA ZPTmpPtr1
ldy #S.FD.T
lda #S.FD.T.SSOCK
sta (ZPTmpPtr1),y
ldy #S.FD.SSOCK.HSKT
.1 lda #$ff
sta (ZPTmpPtr1),y
>LDYA ZPTmpPtr1
rts
bcs .9
>STYA ZPTmpPtr1
ldy #S.FD.SSOCK-1
.2 lda FD.SSOCK,y
sta (ZPTmpPtr1),y
dey
bpl .2
txa
* clc
.9 rts
*/--------------------------------------
* # SKT.Write (DGRAM,STREAM,RAW)
* Send block of data
* **In:**
* PUSHB = hSocket
* PUSHW = pBuf
* PUSHW = len
* **Out:**
*\--------------------------------------
SKT.Write >PULLW ZPDataInLen
>PULLW ZPDataInPtr
>PULLA
jsr SKT.GetA.I
bcs .9
cmp #S.SOCKET.SOCK.DGRAM
beq SKT.Write.UDP
cmp #S.SOCKET.SOCK.RAW
beq SKT.Write.RAW
cmp #S.SOCKET.SOCK.STREAM
bne .99
ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
and #S.SOCKET.SO.ACCEPTCONN
bne .99
jmp SKT.Write.TCP
.99 lda #ERR.SKT.BAD
sec
.9 rts
*--------------------------------------
SKT.Write.RAW ldy #S.SOCKET.RAW.PROTO
lda (ZPPtrSKT),y
tax
>LDYA ZPDataInLen
jsr FRM.NewIP
bcs .9
jsr SKT.SetFrameOutDstIP
jsr SKT.CopyDataInToOut
jmp FRM.SendIP
.9 rts
*--------------------------------------
SKT.Write.UDP ldx #S.IP.PROTOCOL.UDP
>LDYA ZPDataInLen
jsr FRM.NewIP
bcs .9
jsr SKT.SetFrameOutDstIP
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
jsr SKT.CopyDataInToOut
jmp FRM.SendIP
.9 rts
*--------------------------------------
SKT.Write.TCP ldy #S.SOCKET.TCP.STATUS
lda (ZPPtrSKT),y
cmp #S.SOCKET.TCP.STATUS.ESTBLSH
bne .91
jsr SKT.AddDataToSktOut will call SKT.GetTCB
bcs .90
jsr TCP.OUT.I SKT.GetTCB called, try to push, ignore error....
clc
rts
.90 lda #0 no data transfered
sec
rts
.91 lda #MLI.E.IO
sec
.99 rts
*/--------------------------------------
* # SKT.ReadA (DGRAM,RAW)
* **In:**
* A = hSocket
* **Out:**
* A = hFrame
*\--------------------------------------
SKT.ReadA 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.PutC (STREAM)
* Write a Char To Stream
* **In:**
* PUSHB = hSocket
* PUSHB = Char
* **Out:**
*\--------------------------------------
SKT.PutC >PULLB TmpByte
ldx #1
stx ZPDataInLen
stz ZPDataInLen+1
ldx L.TmpByte
stx ZPDataInPtr
ldx L.TmpByte+1
stx ZPDataInPtr+1
bra SKT.PutS.1
*/--------------------------------------
* # SKT.PutS (STREAM)
* Write Line in pBuf
* **In:**
* PUSHB = hSocket
* PUSHW = PSTR
* **Out:**
*\--------------------------------------
SKT.PutS >PULLW ZPDataOutPtr
lda (ZPDataInPtr)
sta ZPDataInLen
stz ZPDataInLen+1
inc ZPDataInPtr
bne SKT.PutS.1
inc ZPDataInPtr+1
SKT.PutS.1 >PULLA
jsr SKT.GetA.I
bcs .9
cmp #S.SOCKET.SOCK.STREAM
bne .9
jmp SKT.Write.TCP
.9 lda #ERR.SKT.BAD
sec
rts
*/--------------------------------------
* # SKT.GetC.A (STREAM)
* Read a Char From Stream in A
* **In:**
* A = hSocket
* **Out:**
* A = char
*\--------------------------------------
SKT.GetC.A stz bTextMode
ldx #1
stx ZPDataOutLen
stz ZPDataOutLen+1
ldx L.TmpByte
stx ZPDataOutPtr
ldx L.TmpByte+1
stx ZPDataOutPtr+1
jsr SKT.Read.I
bcs .9
lda TmpByte
.9 rts
*/--------------------------------------
* # SKT.GetS (STREAM)
* Read a CR terminated Line in pBuf
* **In:**
* PUSHB = hSocket
* PUSHW = pBuf
* PUSHW = len
* **Out:**
* Y,A = bytes read
*\--------------------------------------
SKT.GetS sec
.HS 90 bcc
*/--------------------------------------
* # SKT.Read (STREAM)
* Read data in pBuf
* **In:**
* PUSHB = hSocket
* PUSHW = pBuf
* PUSHW = len
* **Out:**
* Y,A = bytes transfered
*\--------------------------------------
SKT.Read clc
ror bTextMode
>PULLW ZPDataOutLen
>PULLW ZPDataOutPtr
>PULLA
SKT.Read.I jsr SKT.GetA.I
bcs .99
cmp #S.SOCKET.SOCK.STREAM
bne .90 bad skt
ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
and #S.SOCKET.SO.ACCEPTCONN
bne .90 Bad Skt
ldy #S.SOCKET.TCP.STATUS
lda (ZPPtrSKT),y
cmp #S.SOCKET.TCP.STATUS.ESTBLSH
bcc .92 Not yet established...no data
bne .91 closing...IO err
jsr SKT.GetDataFromSktIn
rts if CS, No data...
.90 lda #ERR.SKT.BAD
sec
rts
.91 lda #MLI.E.IO
sec
rts
.92 lda #0
sec
.99 rts
*--------------------------------------
* PRIVATE
*--------------------------------------
* 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
*--------------------------------------
* From TCP.IN
* Src : ZPDataInPtr/ZPDataInLen
* Dst : hInMem/INHEAD
*--------------------------------------
SKT.AddDataToSktIn
ldx SKT.TCBCache+S.TCB.INFREE
cpx ZPDataInLen
lda SKT.TCBCache+S.TCB.INFREE+1
sbc ZPDataInLen+1
bcc .9 Not enough room in Q
ldy #S.TCP.SEQNUM+3
ldx #3
.10 lda (ZPFrameInPtr),y
eor SKT.TCBCache+S.TCB.INLASTSEQNUM,x
bne .9
dey
dex
bpl .10
ldy #S.SOCKET.SQ.hInMem
lda (ZPPtrSKT),y
>SYSCALL GetMemPtr
>STYA ZPTmpPtr1 Make ZPTmpPtr1=buffer base
lda ZPTmpPtr1
clc
adc SKT.TCBCache+S.TCB.INHEAD
sta ZPTmpPtr2
lda ZPTmpPtr1+1
adc SKT.TCBCache+S.TCB.INHEAD+1
sta ZPTmpPtr2+1 Make ZPTmpPtr2=base+Tail
lda ZPDataInLen
eor #$FF
tax
lda ZPDataInLen+1
eor #$FF
pha
ldy #0
.1 inx
bne .2
pla
inc
beq .8
pha
.2 lda (ZPDataInPtr),y
sta (ZPTmpPtr2)
iny
bne .3
inc ZPDataInPtr+1
.3 inc ZPTmpPtr2
bne .4
inc ZPTmpPtr2+1
.4 inc SKT.TCBCache+S.TCB.INHEAD
bne .1
inc SKT.TCBCache+S.TCB.INHEAD+1
lda SKT.TCBCache+S.TCB.INHEAD+1
cmp /K.TCP.WSIZE
bne .1
stz SKT.TCBCache+S.TCB.INHEAD+1
lda ZPTmpPtr1 Dst Ptr=Buffer Base
sta ZPTmpPtr2
lda ZPTmpPtr1+1
sta ZPTmpPtr2+1
bra .1
.9 sec
rts
.8 lda SKT.TCBCache+S.TCB.INFREE
sec
sbc ZPDataInLen
sta SKT.TCBCache+S.TCB.INFREE
lda SKT.TCBCache+S.TCB.INFREE+1
sbc ZPDataInLen+1
sta SKT.TCBCache+S.TCB.INFREE+1
lda SKT.TCBCache+S.TCB.INUSED
clc
adc ZPDataInLen
sta SKT.TCBCache+S.TCB.INUSED
lda SKT.TCBCache+S.TCB.INUSED+1
adc ZPDataInLen+1
sta SKT.TCBCache+S.TCB.INUSED+1
clc
lda SKT.TCBCache+S.TCB.INLASTSEQNUM+3
adc ZPDataInLen
sta SKT.TCBCache+S.TCB.INLASTSEQNUM+3
lda SKT.TCBCache+S.TCB.INLASTSEQNUM+2
adc ZPDataInLen+1
sta SKT.TCBCache+S.TCB.INLASTSEQNUM+2
bcc .80
inc SKT.TCBCache+S.TCB.INLASTSEQNUM+1
bne .80
inc SKT.TCBCache+S.TCB.INLASTSEQNUM
.80 clc
rts
*--------------------------------------
* From SKT.Read
* In:
* Src : hInMem/INTAIL
* Dst : ZPDataOutPtr/ZPDataOutLen
* bTextMode
* Out:
* Y,A = bytes read
*--------------------------------------
SKT.GetDataFromSktIn
jsr SKT.GetTCB
lda SKT.TCBCache+S.TCB.INUSED
ora SKT.TCBCache+S.TCB.INUSED+1
bne .10
sec
rts A=0,NO DATA
.10 ldy #S.SOCKET.SQ.hInMem
lda (ZPPtrSKT),y
>SYSCALL GetMemPtr
>STYA ZPTmpPtr1 Make ZPTmpPtr1=buffer base
lda ZPTmpPtr1
clc
adc SKT.TCBCache+S.TCB.INTAIL
sta ZPTmpPtr2
lda ZPTmpPtr1+1
adc SKT.TCBCache+S.TCB.INTAIL+1
sta ZPTmpPtr2+1
lda ZPDataOutLen
eor #$FF
tax
lda ZPDataOutLen+1
eor #$FF
pha
stz ZPTmpPtr3 Reset byte counter
stz ZPTmpPtr3+1
ldy #0
.1 inx Check if room left in dest buffer
bne .2
pla
inc
beq .8
pha
.2 lda SKT.TCBCache+S.TCB.INTAIL
eor SKT.TCBCache+S.TCB.INHEAD
bne .3
lda SKT.TCBCache+S.TCB.INTAIL+1
eor SKT.TCBCache+S.TCB.INHEAD+1
beq .7 no more data....
.3 lda (ZPTmpPtr2)
pha
inc SKT.TCBCache+S.TCB.INTAIL
bne .5
inc SKT.TCBCache+S.TCB.INTAIL+1
lda SKT.TCBCache+S.TCB.INTAIL+1
cmp /K.TCP.WSIZE
bne .4
stz SKT.TCBCache+S.TCB.INTAIL+1
lda ZPTmpPtr1
sta ZPTmpPtr2
lda ZPTmpPtr1+1
sta ZPTmpPtr2+1
bra .5
.4 inc ZPTmpPtr2
bne .5
inc ZPTmpPtr2+1
.5 pla get back data....
bit bTextMode do we need to check CR ?
bpl .6
cmp #13
beq .7
.6 sta (ZPDataOutPtr),y
iny
bne .61
inc ZPDataOutPtr+1
.61 inc ZPTmpPtr3
bne .1
inc ZPTmpPtr3+1
bra .1
.7 pla discard byte counter HI
.8 bit bTextMode here, bacause dst buf full....
bmi .9 ....and TextMode selected, NO ending CR found
lda ZPTmpPtr3 Do we have transfered something?
ora ZPTmpPtr3+1
beq .9
lda SKT.TCBCache+S.TCB.INFREE
clc
adc ZPTmpPtr3
sta SKT.TCBCache+S.TCB.INFREE
lda SKT.TCBCache+S.TCB.INFREE+1
adc ZPTmpPtr3+1
sta SKT.TCBCache+S.TCB.INFREE+1
lda SKT.TCBCache+S.TCB.INUSED
sec
sbc ZPTmpPtr3
sta SKT.TCBCache+S.TCB.INUSED
lda SKT.TCBCache+S.TCB.INUSED+1
sbc ZPTmpPtr3+1
sta SKT.TCBCache+S.TCB.INUSED+1
lda SKT.TCBCache+S.TCB.OUTACKNUM+3
clc
adc ZPTmpPtr3
sta SKT.TCBCache+S.TCB.OUTACKNUM+3
lda SKT.TCBCache+S.TCB.OUTACKNUM+2
adc ZPTmpPtr3+1
sta SKT.TCBCache+S.TCB.OUTACKNUM+2
bcc .80
inc SKT.TCBCache+S.TCB.OUTACKNUM+1
bne .80
inc SKT.TCBCache+S.TCB.OUTACKNUM
.80 jsr SKT.StoreTCB
ldy #S.SOCKET.TCP.OPTIONS
lda (ZPPtrSKT),y
ora #S.TCP.OPTIONS.ACK
sta (ZPPtrSKT),y
jsr TCP.OUT.I SKT.GetTCB already called, Try to ACK read DATA
>LDYA ZPTmpPtr3
clc
rts
.9 lda #0 NO DATA
sec
rts
*--------------------------------------
* From SKT.Write.TCP
* Src : ZPDataInPtr/ZPDataInLen
* Dst : hOutMem/OUTHEAD
*--------------------------------------
SKT.AddDataToSktOut
jsr SKT.GetTCB
ldx SKT.TCBCache+S.TCB.OUTFREE
cpx ZPDataInLen
lda SKT.TCBCache+S.TCB.OUTFREE+1
sbc ZPDataInLen+1
bcc .9 Not enough room in Q
ldy #S.SOCKET.SQ.hOutMem
lda (ZPPtrSKT),y
>SYSCALL GetMemPtr
>STYA ZPTmpPtr1 Make ZPTmpPtr1=buffer base
lda ZPTmpPtr1
clc
adc SKT.TCBCache+S.TCB.OUTHEAD
sta ZPTmpPtr2
lda ZPTmpPtr1+1
adc SKT.TCBCache+S.TCB.OUTHEAD+1
sta ZPTmpPtr2+1 Make ZPTmpPtr2=base+Tail
lda ZPDataInLen
eor #$FF
tax
lda ZPDataInLen+1
eor #$FF
pha
ldy #0
.1 inx
bne .2
pla
inc
beq .8
pha
.2 lda (ZPDataInPtr),y
sta (ZPTmpPtr2)
iny
bne .3
inc ZPDataInPtr+1
.3 inc ZPTmpPtr2
bne .4
inc ZPTmpPtr2+1
.4 inc SKT.TCBCache+S.TCB.OUTHEAD
bne .1
inc SKT.TCBCache+S.TCB.OUTHEAD+1
lda SKT.TCBCache+S.TCB.OUTHEAD+1
cmp /K.TCP.WSIZE
bne .1
stz SKT.TCBCache+S.TCB.OUTHEAD+1
lda ZPTmpPtr1 Dst Ptr=Buffer Base
sta ZPTmpPtr2
lda ZPTmpPtr1+1
sta ZPTmpPtr2+1
bra .1
.9 sec
rts
.8 lda SKT.TCBCache+S.TCB.OUTFREE
sec
sbc ZPDataInLen
sta SKT.TCBCache+S.TCB.OUTFREE
lda SKT.TCBCache+S.TCB.OUTFREE+1
sbc ZPDataInLen+1
sta SKT.TCBCache+S.TCB.OUTFREE+1
lda SKT.TCBCache+S.TCB.OUTUSED
clc
adc ZPDataInLen
sta SKT.TCBCache+S.TCB.OUTUSED
lda SKT.TCBCache+S.TCB.OUTUSED+1
adc ZPDataInLen+1
sta SKT.TCBCache+S.TCB.OUTUSED+1
lda SKT.TCBCache+S.TCB.OUTTOSEND
clc
adc ZPDataInLen
sta SKT.TCBCache+S.TCB.OUTTOSEND
lda SKT.TCBCache+S.TCB.OUTTOSEND+1
adc ZPDataInLen+1
sta SKT.TCBCache+S.TCB.OUTTOSEND+1
jsr SKT.StoreTCB
rts
*--------------------------------------
* From TCP.OUT
* Src : hOutMem/OUTTAIL
* Dst : ZPDataOutPtr/ZPDataOutLen
*--------------------------------------
SKT.GetDataFromSktOut
ldy #S.SOCKET.SQ.hOutMem
lda (ZPPtrSKT),y
>SYSCALL GetMemPtr
>STYA ZPTmpPtr1 Make ZPTmpPtr1=buffer base
lda ZPTmpPtr1
clc
adc SKT.TCBCache+S.TCB.OUTTAILNEXT
sta ZPTmpPtr2 Make ZPTmpPtr2=base+nexttail
lda ZPTmpPtr1+1
adc SKT.TCBCache+S.TCB.OUTTAILNEXT+1
sta ZPTmpPtr2+1
lda ZPDataOutLen
eor #$FF
tax
lda ZPDataOutLen+1
eor #$FF
pha
ldy #0
.1 inx
bne .2
pla
inc
beq .8
pha
.2 lda (ZPTmpPtr2)
sta (ZPDataOutPtr),y
iny
bne .3
inc ZPDataOutPtr+1
.3 inc ZPTmpPtr2
bne .4
inc ZPTmpPtr2+1
.4 inc SKT.TCBCache+S.TCB.OUTTAILNEXT
bne .1
inc SKT.TCBCache+S.TCB.OUTTAILNEXT+1
lda SKT.TCBCache+S.TCB.OUTTAILNEXT+1
cmp /K.TCP.WSIZE
bne .1
stz SKT.TCBCache+S.TCB.OUTTAILNEXT+1
lda ZPTmpPtr1 Dst Ptr=Buffer Base
sta ZPTmpPtr2
lda ZPTmpPtr1+1
sta ZPTmpPtr2+1
bra .1
.8 lda SKT.TCBCache+S.TCB.OUTTOSEND
sec
sbc ZPDataOutLen
sta SKT.TCBCache+S.TCB.OUTTOSEND
lda SKT.TCBCache+S.TCB.OUTTOSEND+1
sbc ZPDataOutLen+1
sta SKT.TCBCache+S.TCB.OUTTOSEND+1
clc
rts
*--------------------------------------
* From TCP.IN
* Src : A,X
* Dst : hOutMem/OUTTAIL
*--------------------------------------
SKT.AckDataToSktOut
ldy #S.TCP.ACKNUM+3 Get new ACK number from FrameIn...
ldx #3 Substract old ACK from socket
sec
.1 lda (ZPFrameInPtr),y
pha
sbc SKT.TCBCache+S.TCB.OUTSEQNUM,x
sta TmpDWord,x
pla ....and Set SEQ = new SEQ
sta SKT.TCBCache+S.TCB.OUTSEQNUM,x
dey
dex
bpl .1
lda TmpDWord+3
ldx TmpDWord+2
bne .2
tay
beq .8
.2 clc
adc SKT.TCBCache+S.TCB.OUTTAIL
sta SKT.TCBCache+S.TCB.OUTTAIL
txa
adc SKT.TCBCache+S.TCB.OUTTAIL+1
and /K.TCP.WSIZE-1
sta SKT.TCBCache+S.TCB.OUTTAIL+1
lda SKT.TCBCache+S.TCB.OUTFREE
clc
adc TmpDWord+3
sta SKT.TCBCache+S.TCB.OUTFREE
lda SKT.TCBCache+S.TCB.OUTFREE+1
adc TmpDWord+2
sta SKT.TCBCache+S.TCB.OUTFREE+1
lda SKT.TCBCache+S.TCB.OUTUSED
sec
sbc TmpDWord+3
sta SKT.TCBCache+S.TCB.OUTUSED
lda SKT.TCBCache+S.TCB.OUTUSED+1
sbc TmpDWord+2
sta SKT.TCBCache+S.TCB.OUTUSED+1
.8 rts
*--------------------------------------
SKT.NewTCB >LDYAI S.TCB
>SYSCALL getmem0
bcs .9
>STYA .4+1
txa
ldy #S.SOCKET.SQ.hTCB
sta (ZPTmpPtr3),y
lda #K.TCP.WSIZE
sta SKT.TCBCache+S.TCB.INFREE
sta SKT.TCBCache+S.TCB.OUTFREE
lda /K.TCP.WSIZE
sta SKT.TCBCache+S.TCB.INFREE+1
sta SKT.TCBCache+S.TCB.OUTFREE+1
ldx #3
.2 lda A2osX.TIMER16,x
sta SKT.TCBCache+S.TCB.OUTNEXTSEQ,x
dex
bpl .2
>LDYAI K.TCP.WSIZE
>SYSCALL getmem
bcs .9
txa
ldy #S.SOCKET.SQ.hInMem
sta (ZPTmpPtr3),y
>LDYAI K.TCP.WSIZE
>SYSCALL getmem
bcs .9
txa
ldy #S.SOCKET.SQ.hOutMem
sta (ZPTmpPtr3),y
ldx #S.TCB-1
.3 lda SKT.TCBCache,x
.4 sta $ffff,x
dex
bpl .3
clc
.9 rts
*--------------------------------------
SKT.GetTCB ldy #S.SOCKET.SQ.hTCB
lda (ZPPtrSKT),y
>SYSCALL GetMemPtr
bcs *
>STYA .1+1
ldx #S.TCB-1
.1 lda $ffff,x
sta SKT.TCBCache,x
dex
bpl .1
rts
*--------------------------------------
SKT.StoreTCB ldy #S.SOCKET.SQ.hTCB
lda (ZPPtrSKT),y
>SYSCALL GetMemPtr
bcs *
>STYA .2+1
ldx #S.TCB-1
.1 lda SKT.TCBCache,x
.2 sta $ffff,x
dex
bpl .1
rts
*--------------------------------------
SKT.Destroy ldy #S.SOCKET.SQ.hOutMem
lda (ZPPtrSKT),y
beq .1
>SYSCALL FreeMem
.1 ldy #S.SOCKET.SQ.hInMem
lda (ZPPtrSKT),y
beq .2
>SYSCALL FreeMem
.2 ldy #S.SOCKET.SQ.hTCB
lda (ZPPtrSKT),y
beq .3
>SYSCALL FreeMem
.3 lda #0
sta (ZPPtrSKT)
clc
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.CopyDataInToOut
lda ZPDataInPtr+1
pha
lda ZPDataOutPtr+1
pha
lda ZPDataInLen
eor #$ff
tax
lda ZPDataInLen+1
eor #$ff
pha
ldy #0
.1 inx
bne .2
pla
inc
beq .9
pha
.2 lda (ZPDataInPtr),y
sta (ZPDataOutPtr),y
iny
bne .1
inc ZPDataInPtr+1
inc ZPDataOutPtr+1
bne .1
.9 pla
sta ZPDataOutPtr+1
pla
sta ZPDataInPtr+1
rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/LIB/LIBTCPIP.S.SKT
LOAD /A2OSX.SRC/LIB/LIBTCPIP.S
ASM