A2osX/LIB/LIBTCPIP.S.SKT.txt

1298 lines
24 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
PREFIX /A2OSX.BUILD
2017-12-22 21:24:30 +00:00
AUTO 4,1
.LIST OFF
*/--------------------------------------
* # SKT.New
2017-02-13 07:26:18 +00:00
* Create a new socket
2018-06-18 08:44:02 +00:00
* **In:**
* PUSHW = PTR to S.SOCKET template
2018-06-18 08:44:02 +00:00
* **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
2017-02-10 07:29:58 +00:00
.1 lda hSocketTable
>SYSCALL GetMemPtr.A
>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
2017-02-13 07:26:18 +00:00
.7 lda (ZPTmpPtr1),y
sta (ZPTmpPtr3),y
dey
bpl .7
2017-02-10 07:29:58 +00:00
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
2017-02-10 07:29:58 +00:00
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
2017-02-10 07:29:58 +00:00
.99 rts
2017-02-13 07:26:18 +00:00
*/--------------------------------------
* # SKT.CloseA
* Close socket
2018-06-18 08:44:02 +00:00
* **In:**
* A = hSocket
2018-06-18 08:44:02 +00:00
* **Out:**
*\--------------------------------------
2018-06-18 06:22:50 +00:00
SKT.CloseA jsr SKT.GetA.I get SKT in ZPPtrSKT, S.SOCKET.SOCK in A
bcs .99
2017-03-09 07:11:44 +00:00
cmp #S.SOCKET.SOCK.STREAM
2018-06-18 06:22:50 +00:00
beq .10 TCP
bcc .9 no #S.SOCKET.SOCK.DGRAM, nor #S.SOCKET.SOCK.RAW
2017-03-09 07:11:44 +00:00
.1 ldy #S.SOCKET.HQ.TAIL
lda (ZPPtrSKT),y
ldy #S.SOCKET.HQ.HEAD
cmp (ZPPtrSKT),y
2018-06-18 06:22:50 +00:00
beq .8 No frame in Queue, close..
2018-06-18 06:22:50 +00:00
pha save tail...
clc
adc #S.SOCKET.HQ
tax
pla
inc
cmp #S.SOCKET.HQ.MAX
beq .2
lda #0
2018-06-18 06:22:50 +00:00
.2 ldy #S.SOCKET.HQ.TAIL
sta (ZPPtrSKT),y
txa
tay
lda (ZPPtrSKT),y
>SYSCALL FreeMem.A
bra .1
.8 lda #0
sta (ZPPtrSKT)
clc
rts
2018-06-18 06:22:50 +00:00
.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
2018-06-18 08:44:02 +00:00
* **In:**
* A = hSocket
2018-06-18 08:44:02 +00:00
* **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.A
>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
2018-06-18 08:44:02 +00:00
* **In:**
* **Out:**
* Y,A = pS.SOCKET
*\--------------------------------------
SKT.GetTable lda hSocketTable
>SYSCALL GetMemPtr.A
clc
rts
*/--------------------------------------
* # SKT.AcceptA
2017-02-13 07:26:18 +00:00
* Check for an incoming connection
2018-06-18 08:44:02 +00:00
* **In:**
2017-02-13 07:26:18 +00:00
* A = hListeningSocket
2018-06-18 08:44:02 +00:00
* **Out:**
2017-02-13 07:26:18 +00:00
* A = hSocket
*\--------------------------------------
2017-02-10 07:29:58 +00:00
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
2017-02-13 07:26:18 +00:00
pha save tail...
inc
cmp #S.SOCKET.HQ.MAX
bne .1
2017-02-13 07:26:18 +00:00
lda #0
2017-02-13 07:26:18 +00:00
.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
2018-06-18 08:44:02 +00:00
* **In:**
* A = hSocket
2018-06-18 08:44:02 +00:00
* **Out:**
* A = hFile
*\--------------------------------------
SKT.MkNodA sta .1+1
>LDYAI S.NODE.SSOCK
>SYSCALL GetMem0.YA
bcs .9
>STYA ZPTmpPtr1
ldy #S.NODE.T
lda #S.NODE.T.SSOCK
sta (ZPTmpPtr1),y
ldy #S.NODE.SSOCK.HSKT
.1 lda #$ff
sta (ZPTmpPtr1),y
>LDYA ZPTmpPtr1
rts
bcs .9
>STYA ZPTmpPtr1
ldy #S.NODE.SSOCK-1
.2 lda NODE.SSOCK,y
sta (ZPTmpPtr1),y
dey
bpl .2
txa
* clc
.9 rts
2017-02-13 07:26:18 +00:00
*/--------------------------------------
* # SKT.Write (DGRAM,STREAM,RAW)
2017-02-13 07:26:18 +00:00
* Send block of data
2018-06-18 08:44:02 +00:00
* **In:**
2017-02-13 07:26:18 +00:00
* PUSHB = hSocket
* PUSHW = pBuf
* PUSHW = len
2018-06-18 08:44:02 +00:00
* **Out:**
2017-02-13 07:26:18 +00:00
*\--------------------------------------
SKT.Write >PULLW ZPDataInLen
>PULLW ZPDataInPtr
>PULLA
2017-02-13 07:26:18 +00:00
jsr SKT.GetA.I
bcs .9
2017-02-13 07:26:18 +00:00
cmp #S.SOCKET.SOCK.DGRAM
beq SKT.Write.UDP
2017-02-13 07:26:18 +00:00
cmp #S.SOCKET.SOCK.RAW
beq SKT.Write.RAW
cmp #S.SOCKET.SOCK.STREAM
bne .99
2017-02-13 07:26:18 +00:00
ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
and #S.SOCKET.SO.ACCEPTCONN
bne .99
jmp SKT.Write.TCP
2017-02-13 07:26:18 +00:00
.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
2017-02-13 07:26:18 +00:00
>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
2017-02-13 07:26:18 +00:00
jsr SKT.CopyDataInToOut
jmp FRM.SendIP
.9 rts
2017-02-13 07:26:18 +00:00
*--------------------------------------
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)
2018-06-18 08:44:02 +00:00
* **In:**
* A = hSocket
2018-06-18 08:44:02 +00:00
* **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
2018-06-18 08:44:02 +00:00
* **In:**
* PUSHB = hSocket
* PUSHB = Char
2018-06-18 08:44:02 +00:00
* **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
2018-06-18 08:44:02 +00:00
* **In:**
* PUSHB = hSocket
* PUSHW = PSTR
2018-06-18 08:44:02 +00:00
* **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
2018-06-18 08:44:02 +00:00
* **In:**
* A = hSocket
2018-06-18 08:44:02 +00:00
* **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
2018-06-18 08:44:02 +00:00
* **In:**
* PUSHB = hSocket
* PUSHW = pBuf
* PUSHW = len
2018-06-18 08:44:02 +00:00
* **Out:**
2017-02-10 07:29:58 +00:00
* Y,A = bytes read
*\--------------------------------------
SKT.GetS sec
.HS 90 bcc
2017-02-10 07:29:58 +00:00
*/--------------------------------------
* # SKT.Read (STREAM)
* Read data in pBuf
2018-06-18 08:44:02 +00:00
* **In:**
* PUSHB = hSocket
* PUSHW = pBuf
* PUSHW = len
2018-06-18 08:44:02 +00:00
* **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
2018-06-18 06:22:50 +00:00
.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.A
>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.A
>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.A
>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
2017-02-10 07:29:58 +00:00
lda ZPTmpPtr1 Dst Ptr=Buffer Base
sta ZPTmpPtr2
lda ZPTmpPtr1+1
sta ZPTmpPtr2+1
bra .1
.9 sec
rts
2017-02-10 07:29:58 +00:00
.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.A
>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.YA
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.YA
bcs .9
txa
ldy #S.SOCKET.SQ.hInMem
sta (ZPTmpPtr3),y
>LDYAI K.TCP.WSIZE
>SYSCALL GetMem.YA
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.A
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.A
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.A
.1 ldy #S.SOCKET.SQ.hInMem
lda (ZPPtrSKT),y
beq .2
>SYSCALL FreeMem.A
.2 ldy #S.SOCKET.SQ.hTCB
lda (ZPPtrSKT),y
beq .3
>SYSCALL FreeMem.A
.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
2017-02-13 07:26:18 +00:00
lda ZPDataInPtr+1
pha
lda ZPDataOutPtr+1
pha
lda ZPDataInLen
eor #$ff
2017-02-13 07:26:18 +00:00
tax
lda ZPDataInLen+1
eor #$ff
2017-02-13 07:26:18 +00:00
pha
ldy #0
2017-02-13 07:26:18 +00:00
.1 inx
bne .2
2017-02-13 07:26:18 +00:00
pla
inc
beq .9
2017-02-13 07:26:18 +00:00
pha
.2 lda (ZPDataInPtr),y
sta (ZPDataOutPtr),y
iny
bne .1
inc ZPDataInPtr+1
inc ZPDataOutPtr+1
bne .1
2017-02-13 07:26:18 +00:00
.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