A2osX/LIB/LIBTCPIP.S.SKT.txt

1211 lines
22 KiB
Plaintext
Raw Normal View History

PR#3
PREFIX /A2OSX.SRC
LOMEM $A00
INC 1
AUTO 6
.LIST OFF
*/--------------------------------------
* #SKT.New
2017-02-13 07:26:18 +00:00
* 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
2017-02-10 07:29:58 +00:00
.1 lda hSocketTable
>SYSCALL GetMemPtrA
>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.New.TCB
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
jsr TCP.OUT.SYN Only for CLIENT conn!!!!
bcs .99
ldy #S.SOCKET.TCP.STATUS
lda #S.SOCKET.TCP.STATUS.SYNSENT
sta (ZPPtrSKT),y
2017-02-10 07:29:58 +00:00
.8 ldx TmpOffset
>LDYA ZPTmpPtr3
clc
rts
.9 lda #ERR.SKT.OOS
sec
2017-02-10 07:29:58 +00:00
.99 rts
*--------------------------------------
SKT.New.TCB >PUSHWI S.TCB
>PUSHBI S.MEM.F.INIT0
>SYSCALL GetMem
bcs .9
>STYA .4+1
txa
ldy #S.SOCKET.SQ.hTCB
2017-02-10 07:29:58 +00:00
sta (ZPTmpPtr3),y
2017-02-10 07:29:58 +00:00
lda #K.TCP.WSIZE
sta SKT.TCBCache+S.TCB.INFREE
sta SKT.TCBCache+S.TCB.OUTFREE
2017-02-10 07:29:58 +00:00
lda /K.TCP.WSIZE
sta SKT.TCBCache+S.TCB.INFREE+1
sta SKT.TCBCache+S.TCB.OUTFREE+1
2017-02-10 07:29:58 +00:00
ldx #3
.2 lda A2osX.TIMER16,x
sta SKT.TCBCache+S.TCB.SEQNUM,x
dex
bpl .2
>PUSHWI K.TCP.WSIZE
2017-02-10 07:29:58 +00:00
>PUSHBI 0
>SYSCALL GetMem
bcs .9
txa
ldy #S.SOCKET.SQ.hInMem
2017-02-10 07:29:58 +00:00
sta (ZPTmpPtr3),y
>PUSHWI K.TCP.WSIZE
2017-02-10 07:29:58 +00:00
>PUSHBI 0
>SYSCALL GetMem
bcs .9
txa
ldy #S.SOCKET.SQ.hOutMem
2017-02-10 07:29:58 +00:00
sta (ZPTmpPtr3),y
ldx #S.TCB-1
.3 lda SKT.TCBCache,x
.4 sta $ffff,x
dex
bpl .3
2017-02-10 07:29:58 +00:00
clc
.9 rts
2017-02-13 07:26:18 +00:00
*/--------------------------------------
* #SKT.CloseA
* Close socket
* ##In :
* A = hSocket
* ##Out :
*\--------------------------------------
SKT.CloseA cmp #K.SKTTABLE.SIZE
bcs .9
jsr SKT.GetA.I
bcs .9
cmp #S.SOCKET.SOCK.DGRAM
beq .1
cmp #S.SOCKET.SOCK.RAW
beq .1
2017-03-09 07:11:44 +00:00
cmp #S.SOCKET.SOCK.STREAM
bne .9
2017-03-09 07:11:44 +00:00
ldy #S.SOCKET.SO
lda (ZPPtrSKT),y
bit #S.SOCKET.SO.ACCEPTCONN
2017-03-09 07:11:44 +00:00
bne *
2017-03-09 07:11:44 +00:00
ldy #S.SOCKET.TCP.OPTIONS
lda (ZPPtrSKT),y
ora #S.TCP.OPTIONS.FIN
sta (ZPPtrSKT),y
jsr TCP.OUT Try to push FIN
2017-03-09 07:11:44 +00:00
clc
rts
.9 lda #ERR.SKT.BAD
sec
rts
.1 ldy #S.SOCKET.HQ.TAIL
lda (ZPPtrSKT),y
ldy #S.SOCKET.HQ.HEAD
cmp (ZPPtrSKT),y
beq .8
pha
clc
adc #S.SOCKET.HQ
tax
pla
inx
cmp #S.SOCKET.HQ.MAX
beq .2
lda #0
.2
ldy #S.SOCKET.HQ.TAIL
sta (ZPPtrSKT),y
txa
>SYSCALL FreeMemA
bra .1
.8 lda #0
sta (ZPPtrSKT)
clc
rts
*/--------------------------------------
* #SKT.GetA
* Get Ptr to socket
* ##In :
* A = hSocket
* ##Out :
* Y,A = pS.SOCKET
*\--------------------------------------
SKT.GetA cmp #K.SKTTABLE.SIZE
bcs SKT.GetA.9
jsr SKT.GetA.I
bcs SKT.GetA.9
>LDYA ZPPtrSKT
rts
SKT.GetA.I pha
lda hSocketTable
>SYSCALL GetMemPtrA
>STYA ZPPtrSKT
plx
beq .8
.1 lda ZPPtrSKT
clc
adc #S.SOCKET
sta ZPPtrSKT
bcc .2
inc ZPPtrSKT+1
.2 dex
bne .1
.8 lda (ZPPtrSKT)
beq SKT.GetA.9
clc
rts
SKT.GetA.9 lda #ERR.SKT.BAD
sec
rts
*/--------------------------------------
* #SKT.GetTable
* Get socket table
* ##In :
* ##Out :
* Y,A = pS.SOCKET
*\--------------------------------------
SKT.GetTable lda hSocketTable
>SYSCALL GetMemPtrA
clc
rts
*/--------------------------------------
2017-02-13 07:26:18 +00:00
* #SKT.AcceptA
* Check for an incoming connection
* ##In :
* A = hListeningSocket
* ##Out :
* 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
* ##In :
* A = hSocket
* ##Out :
* A = hFile
*\--------------------------------------
SKT.MkNodA
sec
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
* ##In :
* PUSHB = hSocket
* PUSHW = pBuf
* PUSHW = len
* ##Out :
*\--------------------------------------
SKT.Write >PULLW ZPDataInLen
>PULLW ZPDataInPtr
>PULLA
2017-02-13 07:26:18 +00:00
SKT.Write.I 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.STREAM
bne .1
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
.1 cmp #S.SOCKET.SOCK.RAW
bne .99
jmp SKT.Write.RAW
2017-02-13 07:26:18 +00:00
.99 lda #ERR.SKT.BAD
sec
.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
*--------------------------------------
SKT.Write.RAW ldy #S.SOCKET.RAW.PROTO
2017-02-13 07:26:18 +00:00
lda (ZPPtrSKT),y
tax
>LDYA ZPDataInLen
jsr FRM.NewIP
bcs .9
jsr SKT.SetFrameOutDstIP
jsr SKT.CopyDataInToOut
jmp FRM.SendIP
2017-02-13 07:26:18 +00:00
.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
bcs .90
jsr TCP.OUT try to push, ignore error....
clc
rts
.90 lda #0 no data transfered
sec
rts
.91 lda #MLI.ERR.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
>PULLA
ldx #1
stx ZPDataOutLen
stz ZPDataOutLen+1
ldx L.TmpByte
stx ZPDataOutPtr
ldx L.TmpByte+1
stx ZPDataOutPtr+1
jmp SKT.Write.I
*/--------------------------------------
* #SKT.PutS (STREAM)
* Write Line in pBuf
* ##In :
* PUSHB = hSocket
* PUSHW = PSTR
* ##Out :
*\--------------------------------------
SKT.PutS >PULLW ZPDataOutPtr
lda (ZPDataOutPtr)
sta ZPDataOutLen
stz ZPDataOutLen+1
inc ZPDataOutPtr
bne .1
inc ZPDataOutPtr+1
.1 jmp SKT.Write.I
*/--------------------------------------
* #SKT.GetCA (STREAM)
* Read a Char From Stream in A
2017-02-10 07:29:58 +00:00
* ##In :
* A = hSocket
* ##Out :
* A = char
*\--------------------------------------
SKT.GetCA 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
2017-02-10 07:29:58 +00:00
* ##Out :
* 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
* ##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
bne .91 IO err
jsr SKT.GetDataFromSktIn
rts if CS, No data...
.90 lda #ERR.SKT.BAD
sec
rts
.91 lda #MLI.ERR.IO
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 : A,X
* Dst : hOutMem/OUTTAIL
*--------------------------------------
SKT.AckDataToSktOut
ldy #S.TCP.ACK.NUMBER+3 Get new ACK number from FrameIn...
ldx #3 Substract old SEQ from socket
sec
.1 lda (ZPFrameInPtr),y
pha
sbc SKT.TCBCache+S.TCB.SEQNUM,x
sta TmpDWord,x
pla
sta SKT.TCBCache+S.TCB.SEQNUM,x
dey
dex
bpl .1
lda SKT.TCBCache+S.TCB.OUTTAIL
clc
adc TmpDWord
sta SKT.TCBCache+S.TCB.OUTTAIL
lda SKT.TCBCache+S.TCB.OUTTAIL+1
adc TmpDWord+1
and /K.TCP.WSIZE-1
sta SKT.TCBCache+S.TCB.OUTTAIL+1
lda SKT.TCBCache+S.TCB.OUTFREE
clc
adc TmpDWord
sta SKT.TCBCache+S.TCB.OUTFREE
lda SKT.TCBCache+S.TCB.OUTFREE+1
adc TmpDWord+1
sta SKT.TCBCache+S.TCB.OUTFREE+1
lda SKT.TCBCache+S.TCB.OUTUSED
sec
sbc TmpDWord
sta SKT.TCBCache+S.TCB.OUTUSED
lda SKT.TCBCache+S.TCB.OUTUSED+1
sbc TmpDWord+1
sta SKT.TCBCache+S.TCB.OUTUSED+1
clc
rts
*--------------------------------------
* From TCP.IN
* Src : ZPDataInPtr/ZPDataInLen
* Dst : hInMem/INHEAD
*--------------------------------------
SKT.AddDataToSktIn
jsr SKT.GetTCB
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.SOCKET.SQ.hInMem
lda (ZPPtrSKT),y
>SYSCALL GetMemPtrA
>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
.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
jmp SKT.StoreTCB
*--------------------------------------
* From SKT.Write.TCP
* Src : ZPDataInPtr/ZPDataInLen
* Dst : hOutMem/OUTHEAD
*--------------------------------------
SKT.AddDataToSktOut
jsr SKT.GetTCB
ldx ZPDataInLen
cpx SKT.TCBCache+S.TCB.OUTFREE
lda ZPDataInLen+1
sbc SKT.TCBCache+S.TCB.OUTFREE+1
bcc .9 Not enough room in Q
ldy #S.SOCKET.SQ.hOutMem
lda (ZPPtrSKT),y
>SYSCALL GetMemPtrA
>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
jmp SKT.StoreTCB
*--------------------------------------
* From TCP.OUT
* Src : hOutMem/OUTTAIL
* Dst : ZPDataOutPtr/ZPDataOutLen
*--------------------------------------
SKT.GetDataFromSktOut
ldy #S.SOCKET.SQ.hOutMem
lda (ZPPtrSKT),y
>SYSCALL GetMemPtrA
>STYA ZPTmpPtr1 Make ZPTmpPtr1=buffer base
lda ZPTmpPtr1
clc
adc SKT.TCBCache+S.TCB.OUTTAIL
sta ZPTmpPtr2
lda ZPTmpPtr1+1
adc SKT.TCBCache+S.TCB.OUTTAIL+1
sta ZPTmpPtr2+1
lda ZPDataOutLen
eor #$FF
tax
lda ZPDataOutLen+1
eor #$FF
pha
ldy #0
.1 inx
bne .2
pla
inc
beq .5
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.OUTTAIL
bne .1
inc SKT.TCBCache+S.TCB.OUTTAIL+1
lda SKT.TCBCache+S.TCB.OUTTAIL+1
cmp /K.TCP.WSIZE
bne .1
stz SKT.TCBCache+S.TCB.OUTTAIL+1
lda ZPTmpPtr1 Dst Ptr=Buffer Base
sta ZPTmpPtr2
lda ZPTmpPtr1+1
sta ZPTmpPtr2+1
bra .1
.5 lda SKT.TCBCache+S.TCB.OUTFREE
clc
adc ZPDataInLen
sta SKT.TCBCache+S.TCB.OUTFREE
lda SKT.TCBCache+S.TCB.OUTFREE+1
adc ZPDataInLen+1
sta SKT.TCBCache+S.TCB.OUTFREE+1
lda SKT.TCBCache+S.TCB.OUTUSED
sec
sbc ZPDataInLen
sta SKT.TCBCache+S.TCB.OUTUSED
lda SKT.TCBCache+S.TCB.OUTUSED+1
sbc ZPDataInLen+1
sta SKT.TCBCache+S.TCB.OUTUSED+1
lda SKT.TCBCache+S.TCB.SEQNUM
clc
adc ZPDataInLen
sta SKT.TCBCache+S.TCB.SEQNUM
lda SKT.TCBCache+S.TCB.SEQNUM+1
adc ZPDataInLen+1
sta SKT.TCBCache+S.TCB.SEQNUM+1
bcc .8
inc SKT.TCBCache+S.TCB.SEQNUM+2
bne .8
inc SKT.TCBCache+S.TCB.SEQNUM+3
.8 clc
rts
*--------------------------------------
* From SKT.Read
* In:
* Src : hInMem/INTAIL
* Dst : ZPDataOutPtr/ZPDataOutLen
* CS : Text Mode
* CC : Binary Mode
* Out:
* Y,A = bytes read
*--------------------------------------
SKT.GetDataFromSktIn
ldy #S.SOCKET.SQ.hInMem
lda (ZPPtrSKT),y
>SYSCALL GetMemPtrA
>STYA ZPTmpPtr1 Make ZPTmpPtr1=buffer base
jsr SKT.GetTCB
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
2017-02-10 07:29:58 +00:00
ldy #0
2017-02-10 07:29:58 +00:00
.1 inx Check if room left in dest buffer
bne .2
pla
inc
beq .8
pha
2017-02-10 07:29:58 +00:00
.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
2017-02-10 07:29:58 +00:00
stz SKT.TCBCache+S.TCB.INTAIL+1
lda ZPTmpPtr1
sta ZPTmpPtr2
lda ZPTmpPtr1+1
sta ZPTmpPtr2+1
bra .5
2017-02-10 07:29:58 +00:00
.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?
eor 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.ACKNUM
clc
adc ZPTmpPtr3
sta SKT.TCBCache+S.TCB.ACKNUM
lda SKT.TCBCache+S.TCB.ACKNUM+1
adc ZPTmpPtr3+1
sta SKT.TCBCache+S.TCB.ACKNUM+1
bcc .80
inc SKT.TCBCache+S.TCB.ACKNUM+2
bne .80
inc SKT.TCBCache+S.TCB.ACKNUM+3
.80 jsr SKT.StoreTCB
ldy #S.SOCKET.TCP.OPTIONS
lda (ZPPtrSKT),y
ora #S.TCP.OPTIONS.ACK
sta (ZPPtrSKT),y
jsr TCP.OUT.I
>LDYA ZPTmpPtr3
clc
rts
.9 lda #0 NO DATA
sec
rts
*--------------------------------------
SKT.GetTCB ldy #S.SOCKET.SQ.hTCB
lda (ZPPtrSKT),y
>SYSCALL GetMemPtrA
>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 GetMemPtrA
>STYA .2+1
ldx #S.TCB-1
.1 lda SKT.TCBCache,x
.2 sta $ffff,x
dex
bpl .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.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 LIB/LIBTCPIP.S.SKT
LOAD LIB/LIBTCPIP.S
ASM