A2osX/LIB/LIBTCPIP.S.SKT.txt

1527 lines
27 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
2019-05-05 17:15:37 +00:00
AUTO 3,1
*/--------------------------------------
2018-10-10 15:39:22 +00:00
* # Socket
2018-09-26 15:36:32 +00:00
* Create a new socket
* ## C
2018-09-28 15:24:44 +00:00
* `hFD socket(short int type, short int protocol);`
2018-09-26 15:36:32 +00:00
* ## ASM
* **In:**
2021-05-19 12:44:47 +00:00
* `>PUSHB type`
2018-09-28 15:24:44 +00:00
* `>PUSHB protocol`
2018-09-26 15:36:32 +00:00
* `>LIBCALL hLIBTCPIP,LIBTCPIP.socket`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-09-26 15:36:32 +00:00
* CC: A = hSOCKET
* CS: A = EC
*\--------------------------------------
2021-05-19 12:44:47 +00:00
SKT.Socket >PULLA get protocol (RAW)
pha
>PULLA
tax
pla
2018-10-01 15:52:58 +00:00
SKT.Socket.I jmp (J.SKT.Socket,x)
2018-11-01 08:53:47 +00:00
SKT.Socket.RAW ldy #S.SOCKET
2018-10-01 15:52:58 +00:00
bra SKT.Socket.DSOCK
2018-09-28 05:58:24 +00:00
SKT.Socket.DGRAM
2018-09-28 15:24:44 +00:00
lda #S.IP.PROTOCOL.UDP
2018-11-01 08:53:47 +00:00
ldy #S.SOCKET
2018-10-01 15:52:58 +00:00
SKT.Socket.DSOCK
stx FD.DSOCK+S.SOCKET.T save type
sta FD.DSOCK+S.SOCKET.PROTO ICMP,UDP,TCP
2019-10-24 05:55:42 +00:00
2018-10-01 15:52:58 +00:00
jsr SKT.Socket.FindFree
2020-09-03 15:19:25 +00:00
bcs SKT.Socket.RTS
2018-10-01 15:52:58 +00:00
2020-01-30 14:59:40 +00:00
ldy #0
2018-11-01 08:53:47 +00:00
2018-10-01 15:52:58 +00:00
.1 lda FD.DSOCK,y
sta (ZPTmpPtr1),y
2020-01-30 14:59:40 +00:00
iny
cpy #FD.DSOCK.SIZE
bne .1
2018-11-01 08:53:47 +00:00
2020-09-03 15:19:25 +00:00
bra SKT.Socket.ZERO
2020-05-30 20:38:47 +00:00
2020-06-07 08:06:51 +00:00
SKT.Socket.SEQPKT
2018-10-01 15:52:58 +00:00
SKT.Socket.STREAM
lda #S.IP.PROTOCOL.TCP
ldy #S.SOCKET.TCP
stx FD.SSOCK+S.SOCKET.T save type
2018-11-01 08:53:47 +00:00
sta FD.SSOCK+S.SOCKET.PROTO
2018-10-01 15:52:58 +00:00
jsr SKT.Socket.FindFree
2020-09-03 15:19:25 +00:00
bcs SKT.Socket.RTS
2018-11-07 21:48:48 +00:00
2020-01-30 14:59:40 +00:00
ldy #0
2018-11-07 21:48:48 +00:00
2018-10-01 15:52:58 +00:00
.1 lda FD.SSOCK,y
sta (ZPTmpPtr1),y
2020-01-30 14:59:40 +00:00
iny
cpy #FD.SSOCK.SIZE
bne .1
2020-09-03 15:19:25 +00:00
SKT.Socket.ZERO lda #0
.1 sta (ZPTmpPtr1),y
2020-01-30 14:59:40 +00:00
iny
cpy TmpDWord
2020-09-03 15:19:25 +00:00
bne .1
2018-11-07 21:48:48 +00:00
2018-10-01 15:52:58 +00:00
txa
clc
2020-09-03 15:19:25 +00:00
SKT.Socket.RTS rts
*--------------------------------------
2018-10-01 15:52:58 +00:00
SKT.Socket.FindFree
2020-09-03 15:19:25 +00:00
sty TmpDWord Y = socket.size
ldx #0
.1 lda SKT.TABLE,x
2018-09-28 15:24:44 +00:00
beq .2
2020-09-03 15:19:25 +00:00
inx
cpx #K.SKTTABLE.SIZE
2018-09-28 15:24:44 +00:00
bne .1
2020-09-03 15:19:25 +00:00
2018-10-21 20:54:07 +00:00
lda #E.OOH
2020-09-03 15:19:25 +00:00
* sec
2018-10-01 15:52:58 +00:00
rts
2018-09-28 15:24:44 +00:00
2020-09-03 15:19:25 +00:00
.2 stx .8+1
* lda #0 Y,A = socket.size
>SYSCALL2 GetMem
bcs SKT.Socket.RTS
>STYA ZPTmpPtr1
txa
.8 ldy #$FF SELF MODIFIED
2018-09-28 15:24:44 +00:00
sta SKT.TABLE,y
2021-05-19 12:44:47 +00:00
2020-09-03 15:19:25 +00:00
* clc
2018-09-28 15:24:44 +00:00
rts
2018-09-26 15:36:32 +00:00
*/--------------------------------------
2018-10-10 15:39:22 +00:00
* # Bind
2018-09-28 15:24:44 +00:00
* bind a name to a socket
2018-09-26 15:36:32 +00:00
* ## C
* `int bind(hFD fd, const struct sockaddr *addr);`
* ## ASM
* **In:**
2021-05-19 12:44:47 +00:00
* `>PUSHB fd`
2018-09-26 15:36:32 +00:00
* `>PUSHW addr`
* `>LIBCALL hLIBTCPIP,LIBTCPIP.socket`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-09-26 15:36:32 +00:00
* CC: A = hSOCKET
* CS: A = EC
*\--------------------------------------
2021-05-19 12:44:47 +00:00
SKT.bind jsr SKT.PullLocAddr
jsr SKT.PullhFD
2018-11-01 08:53:47 +00:00
2018-10-01 05:48:42 +00:00
lda SKT.LOC.ADDR+S.SOCKADDR.PORT
2019-06-17 15:40:26 +00:00
ora SKT.LOC.ADDR+S.SOCKADDR.PORT+1
2018-10-01 05:48:42 +00:00
bne .1
2018-11-01 08:53:47 +00:00
2018-10-01 05:48:42 +00:00
jsr GetDynPort
2018-11-01 08:53:47 +00:00
2018-10-10 15:39:22 +00:00
sta SKT.LOC.ADDR+S.SOCKADDR.PORT
stx SKT.LOC.ADDR+S.SOCKADDR.PORT+1
2018-11-01 08:53:47 +00:00
2018-11-09 13:29:23 +00:00
.1 ldx #0
2018-11-01 08:53:47 +00:00
2018-11-09 13:29:23 +00:00
.2 lda SKT.TABLE,x
beq .7
2018-10-09 15:47:06 +00:00
2018-11-09 13:29:23 +00:00
phx
2019-05-05 17:15:37 +00:00
>SYSCALL2 GetMemPtr
2018-11-09 13:29:23 +00:00
>STYA ZPTmpPtr1
plx
ldy #S.SOCKET.AF
lda (ZPTmpPtr1),y
cmp #AF.INET
bne .7
ldy #S.SOCKET.LOC.ADDR
.3 lda (ZPTmpPtr1),y
cmp SKT.LOC.ADDR+S.SOCKADDR.ADDR-S.SOCKET.LOC.ADDR,y
bne .7
iny
cpy #S.SOCKET.LOC.PORT+2
bne .3
lda #ERR.SKT.BUSY
* sec
2018-09-28 15:24:44 +00:00
rts
2020-09-03 15:19:25 +00:00
2018-11-09 13:29:23 +00:00
.7 inx
cpx #K.SKTTABLE.SIZE
bne .2
jmp SKT.SetLocAddr
2018-09-26 15:36:32 +00:00
*/--------------------------------------
2018-10-10 15:39:22 +00:00
* # Connect
2018-11-01 08:53:47 +00:00
* Initiate a connection on a socket
2018-09-26 15:36:32 +00:00
* ## C
* `int connect(hFD fd, const struct sockaddr *addr);`
* ## ASM
* **In:**
2021-05-19 12:44:47 +00:00
* `>PUSHB fd`
2018-09-26 15:36:32 +00:00
* `>PUSHW addr`
* `>LIBCALL hLIBTCPIP,LIBTCPIP.socket`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-09-26 15:36:32 +00:00
* CC: A = hSOCKET
* CS: A = EC
*\--------------------------------------
2021-05-19 12:44:47 +00:00
SKT.connect jsr SKT.PullRemAddr
jsr SKT.PullhFD
2018-11-07 21:48:48 +00:00
2018-09-28 15:24:44 +00:00
ldy #S.SOCKET.T
2018-10-01 05:48:42 +00:00
lda (ZPPtrSKT),y
2018-09-27 15:34:38 +00:00
tax
jmp (J.SKT.connect,x)
2019-10-05 17:24:41 +00:00
2018-09-27 15:34:38 +00:00
SKT.connect.RAW
SKT.connect.DGRAM
2018-11-06 16:31:13 +00:00
jmp SKT.SetRemAddr
2019-10-05 17:24:41 +00:00
2018-10-01 05:48:42 +00:00
SKT.connect.STREAM
2020-06-07 08:06:51 +00:00
SKT.connect.SEQPKT
2019-10-05 17:24:41 +00:00
ldy #S.SOCKET.TCP.S
lda (ZPPtrSKT),y
beq .1
2020-09-03 15:19:25 +00:00
2019-10-05 17:24:41 +00:00
cmp #S.SOCKET.TCP.S.ESTBLSH
2019-10-28 16:20:40 +00:00
beq SKT.listen.8
2019-10-05 17:24:41 +00:00
bcs .9
2020-09-03 15:19:25 +00:00
2019-10-05 17:24:41 +00:00
cmp #S.SOCKET.TCP.S.OPENED
beq .2
2020-09-03 15:19:25 +00:00
2019-10-05 17:24:41 +00:00
cmp #S.SOCKET.TCP.S.SYNSENT
2019-10-28 16:20:40 +00:00
beq .99
.9 lda #ERR.SKT.BAD
sec
rts
2020-09-03 15:19:25 +00:00
2019-10-05 17:24:41 +00:00
.1 jsr SKT.SetRemAddr
2018-11-01 08:53:47 +00:00
jsr SKT.NewTCB
2019-06-17 06:35:54 +00:00
bcs SKT.listen.RTS
2019-10-05 17:24:41 +00:00
lda #S.SOCKET.TCP.S.OPENED
jsr SKT.StoreTCB.S
2019-10-04 06:38:42 +00:00
2019-10-05 17:24:41 +00:00
.2 lda #S.TCP.OPTIONS.SYN
2018-10-01 05:48:42 +00:00
jsr TCP.OUT.SendOptA Send SYN
2019-10-28 16:20:40 +00:00
bcs .99
2020-09-03 15:19:25 +00:00
2018-10-01 05:48:42 +00:00
lda #S.SOCKET.TCP.S.SYNSENT
2021-03-11 21:40:55 +00:00
jsr SKT.StoreTCB.S
2020-09-03 15:19:25 +00:00
2019-10-28 16:20:40 +00:00
.99 lda #ERR.SKT.NOCONN
2019-10-05 17:24:41 +00:00
sec
rts
2018-10-01 05:48:42 +00:00
*/--------------------------------------
2018-10-10 15:39:22 +00:00
* # Listen
2018-10-01 05:48:42 +00:00
* Listen for connections on a socket
* ## C
* `int listen(hFD fd);`
* ## ASM
* **In:**
* `lda fd`
* `>LIBCALL hLIBTCPIP,LIBTCPIP.listen`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-10-01 05:48:42 +00:00
* CS: A = EC
*\--------------------------------------
2021-05-19 12:44:47 +00:00
SKT.listen jsr SKT.GetFD
2018-10-09 15:47:06 +00:00
2018-10-01 05:48:42 +00:00
ldy #S.SOCKET.T
lda (ZPPtrSKT),y
2020-06-07 08:06:51 +00:00
cmp #S.SOCKET.T.SEQPKT
2019-10-28 16:20:40 +00:00
bcc SKT.listen.9
2018-10-01 05:48:42 +00:00
ldy #S.SOCKET.TCP.S
lda (ZPPtrSKT),y
2019-10-28 16:20:40 +00:00
bne SKT.listen.9
2018-10-09 15:47:06 +00:00
2018-10-01 05:48:42 +00:00
lda #S.SOCKET.TCP.S.LISTEN
sta (ZPPtrSKT),y
2018-10-09 15:47:06 +00:00
2018-10-01 05:48:42 +00:00
ldy #S.SOCKET.O
lda #S.SOCKET.O.ACCEPTCONN
2018-08-29 15:01:02 +00:00
sta (ZPPtrSKT),y
2018-09-27 06:00:22 +00:00
2019-10-28 16:20:40 +00:00
SKT.listen.8 clc
2018-10-01 05:48:42 +00:00
rts
2018-10-09 15:47:06 +00:00
2019-10-28 16:20:40 +00:00
SKT.listen.9 lda #ERR.SKT.BAD
2018-10-01 05:48:42 +00:00
sec
2019-10-03 06:25:27 +00:00
SKT.listen.RTS rts
2018-10-01 05:48:42 +00:00
*/--------------------------------------
2018-10-10 15:39:22 +00:00
* # Accept
2018-10-01 05:48:42 +00:00
* Accept a connection on a socket
* ## C
* `hFD Accept(hFD fd);`
* ## ASM
2020-09-03 15:19:25 +00:00
* **In:**
2018-10-01 05:48:42 +00:00
* `lda fd`
* `>LIBCALL hLIBTCPIP,LIBTCPIP.accept`
2020-09-03 15:19:25 +00:00
* ## RETURN VALUE
2018-10-01 05:48:42 +00:00
* A = hSocket
*\--------------------------------------
2021-05-19 12:44:47 +00:00
SKT.Accept jsr SKT.GetFD
2018-10-09 15:47:06 +00:00
2018-09-28 15:24:44 +00:00
ldy #S.SOCKET.O
2018-09-25 15:31:35 +00:00
lda (ZPPtrSKT),y
2018-09-28 15:24:44 +00:00
and #S.SOCKET.O.ACCEPTCONN
2020-09-03 15:19:25 +00:00
beq SKT.listen.9
*--------------------------------------
SKT.GetFromQueue
ldy #S.SOCKET.HQ.TAIL
lda (ZPPtrSKT),y
iny #S.SOCKET.HQ.HEAD
cmp (ZPPtrSKT),y
beq .9 CS
2018-10-09 15:47:06 +00:00
2020-09-03 15:19:25 +00:00
pha
inc
cmp #S.SOCKET.HQ.MAX
bne .1
lda #0
.1 dey #S.SOCKET.HQ.TAIL
sta (ZPPtrSKT),y
pla
clc
adc #S.SOCKET.HQ
tay
lda (ZPPtrSKT),y
* clc
2018-10-09 15:47:06 +00:00
2018-10-01 05:48:42 +00:00
.9 rts
2017-02-13 07:26:18 +00:00
*/--------------------------------------
2018-10-10 15:39:22 +00:00
* # Shutdown
2018-10-01 05:48:42 +00:00
* Close socket
* ## C
2018-10-10 15:39:22 +00:00
* `int shutdown(int fd);`
2018-10-01 05:48:42 +00:00
* ## ASM
* **In:**
* `lda fd`
2018-10-10 15:39:22 +00:00
* `>LIBCALL hLIBTCPIP,LIBTCPIP.shutdown`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
*\--------------------------------------
2018-11-06 16:31:13 +00:00
SKT.shutdown pha
2021-05-19 12:44:47 +00:00
jsr SKT.GetFD
2018-10-09 15:47:06 +00:00
2018-11-06 16:31:13 +00:00
ldy #S.SOCKET.O
2018-11-06 07:09:44 +00:00
lda (ZPPtrSKT),y
2018-11-06 16:31:13 +00:00
and #S.SOCKET.O.ACCEPTCONN
bne SKT.shutdown.HQ
2018-11-07 21:48:48 +00:00
2018-11-06 16:31:13 +00:00
ldy #S.SOCKET.T
lda (ZPPtrSKT),y
2020-06-07 08:06:51 +00:00
cmp #S.SOCKET.T.SEQPKT
bcc SKT.shutdown.HQ
2020-06-05 19:26:34 +00:00
2020-09-03 20:52:37 +00:00
ldy #S.SOCKET.TCP.S
lda (ZPPtrSKT),y
cmp #S.SOCKET.TCP.S.CLWAIT
bne .10
lda #S.SOCKET.TCP.S.TIMEWT
sta (ZPPtrSKT),y
2020-06-05 19:26:34 +00:00
pla
clc
rts
*--------------------------------------
.10 pla
2020-09-03 20:52:37 +00:00
jsr SKT.GetTCB
ldy #S.SOCKET.TCP.S
lda (ZPPtrSKT),y
cmp #S.SOCKET.TCP.S.ESTBLSH
bne .1
jsr SKT.OUT.SendFINACK
2020-09-03 15:19:25 +00:00
2020-09-03 20:52:37 +00:00
lda #S.SOCKET.TCP.S.FINWT1
jmp SKT.StoreTCB.S
.1 cmp #S.SOCKET.TCP.S.FINWT2
bne .2
jsr SKT.OUT.SendFINACK
lda #S.SOCKET.TCP.S.LASTACK
jmp SKT.StoreTCB.S
2020-09-03 20:52:37 +00:00
.2 lda #S.TCP.OPTIONS.RST
jsr TCP.OUT.SendOptA Send RST
.3 lda #S.SOCKET.TCP.S.TIMEWT
jmp SKT.StoreTCB.S
2019-10-03 06:25:27 +00:00
*--------------------------------------
SKT.shutdown.HQ jsr SKT.GetFromQueue
2020-09-03 06:24:36 +00:00
bcs .3
2020-09-03 15:19:25 +00:00
2019-05-05 17:15:37 +00:00
>SYSCALL2 FreeMem
bra SKT.shutdown.HQ
2018-10-09 15:47:06 +00:00
2018-11-06 16:31:13 +00:00
.3 pla get hFD...
2018-11-07 21:48:48 +00:00
2018-11-06 16:31:13 +00:00
ldx #0
2018-11-07 21:48:48 +00:00
2018-11-06 16:31:13 +00:00
.4 cmp SKT.TABLE,x
beq .5
2018-11-07 21:48:48 +00:00
2018-11-06 16:31:13 +00:00
inx
cpx #K.SKTTABLE.SIZE
bne .4
2018-11-07 21:48:48 +00:00
2018-11-06 16:31:13 +00:00
.5 stz SKT.TABLE,x
2019-05-05 17:15:37 +00:00
>SYSCALL2 freemem
2019-06-17 15:40:26 +00:00
* clc
rts
*/--------------------------------------
2018-10-10 15:39:22 +00:00
* # Read (STREAM)
2018-09-11 21:15:15 +00:00
* ## C
* `int skt.read(hFD fd, void *buf, int count);`
* ## ASM
* **In:**
2021-05-19 12:44:47 +00:00
* `>PUSHB fd`
2018-09-11 21:15:15 +00:00
* `>PUSHW buf`
2021-05-19 12:44:47 +00:00
* `>PUSHW count`
2019-03-02 20:47:58 +00:00
* `>LIBCALL hLIBTCPIP,LIBTCPIP.read`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-09-11 21:15:15 +00:00
* CC: Y,A = bytes read
* CS: A = EC
2018-08-29 15:01:02 +00:00
*\--------------------------------------
2018-11-09 13:29:23 +00:00
SKT.Read jsr SKT.PullhFDDataInPtrLen
2018-10-09 15:47:06 +00:00
jsr SKT.GetTCB
2019-05-10 18:41:17 +00:00
ldy #S.SOCKET.TCP.INUSED
lda (ZPPtrSKT),y
2019-06-05 15:34:49 +00:00
tax
2019-05-10 18:41:17 +00:00
iny
ora (ZPPtrSKT),y
beq .8 no data, go check SKT status
2018-08-29 15:01:02 +00:00
2019-06-05 15:34:49 +00:00
cpx ZPDataInLen XA = Data in pipe
lda (ZPPtrSKT),y
sbc ZPDataInLen+1
bcs SKT.GetDataFromSktIn more data in pipe, get full buffer of data
2019-10-28 16:20:40 +00:00
2019-06-08 18:40:11 +00:00
stx ZPDataInLen less data than INUSED, Get only INUSED data
2019-06-05 15:34:49 +00:00
lda (ZPPtrSKT),y
2019-06-08 18:40:11 +00:00
sta ZPDataInLen+1
2019-06-05 15:34:49 +00:00
bra SKT.GetDataFromSktIn
2021-05-19 12:44:47 +00:00
.8 jsr SKT.CheckStream
2019-06-05 15:34:49 +00:00
bcs .99 I/O error
2019-05-10 18:41:17 +00:00
2019-06-05 15:34:49 +00:00
lda #E.NODATA
2019-05-12 20:45:11 +00:00
sec
2019-05-05 17:15:37 +00:00
.99 rts
*--------------------------------------
* In:
* Src : hInMem/INTAIL
* Dst : ZPDataOutPtr/ZPDataOutLen
* Out:
* Y,A = bytes read
*--------------------------------------
SKT.GetDataFromSktIn
ldy #S.SOCKET.SQ.hInMem
lda (ZPPtrSKT),y
2019-06-19 15:56:59 +00:00
.DO AUXPIPE=1
>SYSCALL2 GetStkObjPtr
.ELSE
2019-05-05 17:15:37 +00:00
>SYSCALL2 GetMemPtr
2019-06-19 15:56:59 +00:00
.FIN
2019-06-17 15:40:26 +00:00
sty ZPTmpPtr1
2019-05-05 17:15:37 +00:00
2019-06-05 15:34:49 +00:00
* clc
2019-05-05 17:15:37 +00:00
adc SKT.Cache+S.SOCKET.TCP.INTAIL+1
2019-06-17 15:40:26 +00:00
sta ZPTmpPtr1+1
2019-05-05 17:15:37 +00:00
2019-07-19 06:41:33 +00:00
jsr SKT.GetNotDataInLen
2019-05-05 17:15:37 +00:00
pha
2019-06-19 15:56:59 +00:00
.DO AUXPIPE=1
jsr SKT.SetupZPCode
.FIN
2019-06-17 15:40:26 +00:00
ldy SKT.Cache+S.SOCKET.TCP.INTAIL
2019-05-05 17:15:37 +00:00
.1 inx Check if room left in dest buffer
bne .2
2019-05-05 17:15:37 +00:00
pla
inc
beq .8
pha
2019-06-19 15:56:59 +00:00
.2 .DO AUXPIPE=1
jsr ZPCode
.ELSE
lda (ZPTmpPtr1),y
.FIN
2019-06-17 15:40:26 +00:00
sta (ZPDataInPtr)
inc ZPDataInPtr
2019-05-05 17:15:37 +00:00
bne .3
2019-06-05 15:34:49 +00:00
inc ZPDataInPtr+1
2019-05-05 17:15:37 +00:00
2019-06-17 15:40:26 +00:00
.3 iny
bne .1
2019-06-17 15:40:26 +00:00
inc ZPTmpPtr1+1
2019-05-05 17:15:37 +00:00
inc SKT.Cache+S.SOCKET.TCP.INTAIL+1
lda SKT.Cache+S.SOCKET.TCP.INTAIL+1
cmp /K.TCP.WSIZE
2019-06-17 15:40:26 +00:00
bne .1
2019-05-05 17:15:37 +00:00
stz SKT.Cache+S.SOCKET.TCP.INTAIL+1
2019-06-18 06:43:58 +00:00
lda ZPTmpPtr1+1
* sec
sbc /K.TCP.WSIZE
sta ZPTmpPtr1+1
2019-05-05 17:15:37 +00:00
bra .1
2019-06-17 15:40:26 +00:00
.8 sty SKT.Cache+S.SOCKET.TCP.INTAIL
2019-08-06 07:14:22 +00:00
* >ADC16 SKT.Cache+S.SOCKET.TCP.INFREE,ZPDataInLen
ldx #S.SOCKET.TCP.INFREE
jsr SKT.AddDataInLenAtSktX
* >SBC16 SKT.Cache+S.SOCKET.TCP.INUSED,ZPDataInLen
ldx #S.SOCKET.TCP.INUSED
jsr SKT.SubDataInLenAtSktX
2019-05-05 17:15:37 +00:00
lda ZPDataInLen
ldy ZPDataInLen+1
ldx #S.SOCKET.TCP.INACKNUM
jsr TCP.AddAYToSktCacheAtX
2019-06-11 15:47:18 +00:00
jsr SKT.StoreTCB
lda #S.TCP.OPTIONS.ACK
jsr TCP.SetSocketTCPO
2019-05-13 21:10:09 +00:00
2019-06-05 15:34:49 +00:00
>LDYA ZPDataInLen
2019-06-11 15:47:18 +00:00
clc
rts
*--------------------------------------
* From TCP.IN
* Src : ZPDataInPtr/ZPDataInLen
* Dst : hInMem/INHEAD
*--------------------------------------
SKT.AddDataToSktIn
lda SKT.Cache+S.SOCKET.TCP.INFREE
sec
sbc ZPDataInLen
tax
lda SKT.Cache+S.SOCKET.TCP.INFREE+1
sbc ZPDataInLen+1
bcc .9 Not enough room in Q
stx SKT.Cache+S.SOCKET.TCP.INFREE
sta SKT.Cache+S.SOCKET.TCP.INFREE+1
ldy #S.SOCKET.SQ.hInMem
lda (ZPPtrSKT),y
2019-06-19 15:56:59 +00:00
.DO AUXPIPE=1
>SYSCALL2 GetStkObjPtr
.ELSE
2019-06-11 15:47:18 +00:00
>SYSCALL2 GetMemPtr
2019-06-19 15:56:59 +00:00
.FIN
2019-06-17 15:40:26 +00:00
sty ZPTmpPtr1
2019-06-11 15:47:18 +00:00
* clc
adc SKT.Cache+S.SOCKET.TCP.INHEAD+1
2019-06-17 15:40:26 +00:00
sta ZPTmpPtr1+1
2019-06-11 15:47:18 +00:00
2019-07-19 06:41:33 +00:00
jsr SKT.GetNotDataInLen
2019-06-11 15:47:18 +00:00
pha
2019-06-17 15:40:26 +00:00
ldy SKT.Cache+S.SOCKET.TCP.INHEAD
2019-06-11 15:47:18 +00:00
2019-06-17 15:40:26 +00:00
.1 .DO AUXPIPE=1
sta SETWRITEAUX
.FIN
.2 inx
bne .3
2019-06-11 15:47:18 +00:00
pla
inc
beq .8
pha
2019-06-17 15:40:26 +00:00
.3 lda (ZPDataInPtr)
sta (ZPTmpPtr1),y
inc ZPDataInPtr
bne .4
2019-06-11 15:47:18 +00:00
inc ZPDataInPtr+1
2019-06-17 15:40:26 +00:00
.4 iny
bne .2
2019-06-17 15:40:26 +00:00
.DO AUXPIPE=1
sta CLRWRITEAUX
.FIN
inc ZPTmpPtr1+1
2019-06-11 15:47:18 +00:00
inc SKT.Cache+S.SOCKET.TCP.INHEAD+1
lda SKT.Cache+S.SOCKET.TCP.INHEAD+1
cmp /K.TCP.WSIZE
2019-06-17 15:40:26 +00:00
bne .1
2019-06-11 15:47:18 +00:00
stz SKT.Cache+S.SOCKET.TCP.INHEAD+1
lda ZPTmpPtr1+1
2019-06-17 15:40:26 +00:00
* sec
sbc /K.TCP.WSIZE
sta ZPTmpPtr1+1
2019-06-11 15:47:18 +00:00
bra .1
2019-06-11 15:47:18 +00:00
.9 sec
rts
2019-06-17 15:40:26 +00:00
.8 .DO AUXPIPE=1
sta CLRWRITEAUX
.FIN
sty SKT.Cache+S.SOCKET.TCP.INHEAD
2019-08-06 07:14:22 +00:00
* >ADC16 SKT.Cache+S.SOCKET.TCP.INUSED,ZPDataInLen
ldx #S.SOCKET.TCP.INUSED
jsr SKT.AddDataInLenAtSktX
2019-06-11 15:47:18 +00:00
2019-05-05 17:15:37 +00:00
clc
2019-05-04 21:13:50 +00:00
rts
2018-08-29 15:01:02 +00:00
*/--------------------------------------
2018-10-10 15:39:22 +00:00
* # Write (STREAM)
2018-09-11 21:15:15 +00:00
* ## C
* `int skt.write(hFD fd, const void *buf, int count);`
* ## ASM
* **In:**
2021-05-19 12:44:47 +00:00
* `>PUSHB fd`
2018-09-11 21:15:15 +00:00
* `>PUSHW buf`
2021-05-19 12:44:47 +00:00
* `>PUSHW count`
2019-03-02 20:47:58 +00:00
* `>LIBCALL hLIBTCPIP,LIBTCPIP.write`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-09-11 21:15:15 +00:00
* CC: Y,A = bytes written
* CS: A = EC
2017-02-13 07:26:18 +00:00
*\--------------------------------------
2018-11-09 13:29:23 +00:00
SKT.Write jsr SKT.PullhFDDataInPtrLen
2017-02-13 07:26:18 +00:00
2019-03-02 20:47:58 +00:00
jsr SKT.CheckStream
2019-05-03 13:08:12 +00:00
bcs .99
2021-05-19 12:44:47 +00:00
2019-06-10 08:19:13 +00:00
jsr SKT.GetTCB
2019-05-03 13:08:12 +00:00
ldx SKT.Cache+S.SOCKET.TCP.OUTFREE
cpx ZPDataInLen
lda SKT.Cache+S.SOCKET.TCP.OUTFREE+1
sbc ZPDataInLen+1
2019-05-05 17:15:37 +00:00
bcs SKT.AddDataToSktOut
2019-05-12 20:45:11 +00:00
lda #E.NODATA Not enough room in Q,no data transfered
sec
2019-05-05 17:15:37 +00:00
.99 rts
*--------------------------------------
* Src : ZPDataInPtr/ZPDataInLen
* Dst : hOutMem/OUTHEAD
*--------------------------------------
SKT.AddDataToSktOut
ldy #S.SOCKET.SQ.hOutMem
lda (ZPPtrSKT),y
2019-06-19 15:56:59 +00:00
.DO AUXPIPE=1
>SYSCALL2 GetStkObjPtr
.ELSE
2019-05-05 17:15:37 +00:00
>SYSCALL2 GetMemPtr
2019-06-19 15:56:59 +00:00
.FIN
2019-06-17 15:40:26 +00:00
sty ZPTmpPtr1
2019-05-05 17:15:37 +00:00
2019-06-05 15:34:49 +00:00
* clc
2019-05-05 17:15:37 +00:00
adc SKT.Cache+S.SOCKET.TCP.OUTHEAD+1
2019-06-17 15:40:26 +00:00
sta ZPTmpPtr1+1
ldy SKT.Cache+S.SOCKET.TCP.OUTHEAD
2019-05-05 17:15:37 +00:00
2019-07-19 06:41:33 +00:00
jsr SKT.GetNotDataInLen
2019-05-05 17:15:37 +00:00
pha
2019-06-17 15:40:26 +00:00
.1 .DO AUXPIPE=1
sta SETWRITEAUX
.FIN
2019-05-05 17:15:37 +00:00
2019-06-17 15:40:26 +00:00
.2 inx
bne .3
2019-05-05 17:15:37 +00:00
pla
inc
beq .8
pha
2019-06-17 15:40:26 +00:00
.3 lda (ZPDataInPtr)
sta (ZPTmpPtr1),y
2019-05-05 17:15:37 +00:00
2019-06-17 15:40:26 +00:00
inc ZPDataInPtr
2019-05-05 17:15:37 +00:00
bne .4
2019-06-17 15:40:26 +00:00
inc ZPDataInPtr+1
.4 iny
bne .2
2019-06-17 15:40:26 +00:00
inc ZPTmpPtr1+1
.DO AUXPIPE=1
sta CLRWRITEAUX
.FIN
2019-05-05 17:15:37 +00:00
inc SKT.Cache+S.SOCKET.TCP.OUTHEAD+1
lda SKT.Cache+S.SOCKET.TCP.OUTHEAD+1
cmp /K.TCP.WSIZE
2019-06-17 15:40:26 +00:00
bne .1
2019-05-05 17:15:37 +00:00
2019-06-05 15:34:49 +00:00
stz SKT.Cache+S.SOCKET.TCP.OUTHEAD+1
2019-06-17 15:40:26 +00:00
2019-05-05 17:15:37 +00:00
lda ZPTmpPtr1+1
2019-06-17 15:40:26 +00:00
* sec
sbc /K.TCP.WSIZE
sta ZPTmpPtr1+1
2019-05-05 17:15:37 +00:00
bra .1
2019-05-03 13:08:12 +00:00
2019-06-17 15:40:26 +00:00
.8 .DO AUXPIPE=1
sta CLRWRITEAUX
.FIN
sty SKT.Cache+S.SOCKET.TCP.OUTHEAD
2019-06-05 15:34:49 +00:00
2019-08-06 07:14:22 +00:00
* >SBC16 SKT.Cache+S.SOCKET.TCP.OUTFREE,ZPDataInLen
ldx #S.SOCKET.TCP.OUTFREE
jsr SKT.SubDataInLenAtSktX
* >ADC16 SKT.Cache+S.SOCKET.TCP.OUTUSED,ZPDataInLen
ldx #S.SOCKET.TCP.OUTUSED
jsr SKT.AddDataInLenAtSktX
* >ADC16 SKT.Cache+S.SOCKET.TCP.OUTTOSEND,ZPDataInLen
ldx #S.SOCKET.TCP.OUTTOSEND
jsr SKT.AddDataInLenAtSktX
2019-05-05 17:15:37 +00:00
jsr SKT.StoreTCB
2019-06-10 08:19:13 +00:00
>LDYA ZPDataInLen
2019-06-11 15:47:18 +00:00
clc
rts
*--------------------------------------
2019-08-06 07:14:22 +00:00
SKT.AddDataInLenAtSktX
clc
lda SKT.Cache,x
adc ZPDataInLen
sta SKT.Cache,x
inx
lda SKT.Cache,x
adc ZPDataInLen+1
sta SKT.Cache,x
rts
*--------------------------------------
SKT.SubDataInLenAtSktX
sec
lda SKT.Cache,x
sbc ZPDataInLen
sta SKT.Cache,x
inx
lda SKT.Cache,x
sbc ZPDataInLen+1
sta SKT.Cache,x
rts
*--------------------------------------
2019-06-11 15:47:18 +00:00
* From TCP.OUT
* Src : hOutMem/OUTTAIL
* Dst : ZPDataOutPtr/ZPDataOutLen
*--------------------------------------
SKT.GetDataFromSktOut
ldy #S.SOCKET.SQ.hOutMem
lda (ZPPtrSKT),y
2019-06-19 15:56:59 +00:00
.DO AUXPIPE=1
>SYSCALL2 GetStkObjPtr
.ELSE
2019-06-11 15:47:18 +00:00
>SYSCALL2 GetMemPtr
2019-06-19 15:56:59 +00:00
.FIN
2019-06-17 15:40:26 +00:00
sty ZPTmpPtr1
2019-06-11 15:47:18 +00:00
* clc
2019-06-17 06:35:54 +00:00
adc SKT.Cache+S.SOCKET.TCP.OUTTAILSENT+1
2019-06-17 15:40:26 +00:00
sta ZPTmpPtr1+1
2019-06-11 15:47:18 +00:00
lda ZPDataOutLen
eor #$FF
tax
lda ZPDataOutLen+1
eor #$FF
pha
2019-06-19 15:56:59 +00:00
.DO AUXPIPE=1
jsr SKT.SetupZPCode
.FIN
2019-06-17 15:40:26 +00:00
ldy SKT.Cache+S.SOCKET.TCP.OUTTAILSENT
2019-06-11 15:47:18 +00:00
.1 inx
bne .2
2021-05-19 12:44:47 +00:00
2019-06-11 15:47:18 +00:00
pla
inc
beq .8
pha
2019-06-19 15:56:59 +00:00
.2 .DO AUXPIPE=1
jsr ZPCode
.ELSE
lda (ZPTmpPtr1),y
.FIN
2019-06-17 15:40:26 +00:00
sta (ZPDataOutPtr)
inc ZPDataOutPtr
2019-06-11 15:47:18 +00:00
bne .3
2021-05-19 12:44:47 +00:00
2019-06-11 15:47:18 +00:00
inc ZPDataOutPtr+1
2019-06-17 15:40:26 +00:00
.3 iny
bne .1
2019-06-17 15:40:26 +00:00
inc ZPTmpPtr1+1
2019-06-17 06:35:54 +00:00
inc SKT.Cache+S.SOCKET.TCP.OUTTAILSENT+1
lda SKT.Cache+S.SOCKET.TCP.OUTTAILSENT+1
2019-06-11 15:47:18 +00:00
cmp /K.TCP.WSIZE
2019-06-17 15:40:26 +00:00
bne .1
2021-05-19 12:44:47 +00:00
2019-06-17 06:35:54 +00:00
stz SKT.Cache+S.SOCKET.TCP.OUTTAILSENT+1
2019-06-17 15:40:26 +00:00
2019-06-11 15:47:18 +00:00
lda ZPTmpPtr1+1
2019-06-17 15:40:26 +00:00
* sec
sbc /K.TCP.WSIZE
sta ZPTmpPtr1+1
2019-06-11 15:47:18 +00:00
bra .1
2019-06-17 15:40:26 +00:00
.8 sty SKT.Cache+S.SOCKET.TCP.OUTTAILSENT
2019-06-11 15:47:18 +00:00
2019-06-17 15:40:26 +00:00
>SBC16 SKT.Cache+S.SOCKET.TCP.OUTTOSEND,ZPDataOutLen
2019-06-11 15:47:18 +00:00
clc
rts
*/--------------------------------------
* # RecvFrom (RAW,DGRAM)
2018-10-08 15:41:00 +00:00
* ## C
* `hMem recvfrom(hFD fd, struct sockaddr *addr);`
2018-10-01 05:48:42 +00:00
* ## ASM
* **In:**
2021-05-19 12:44:47 +00:00
* `>PUSHB fd`
2018-10-01 05:48:42 +00:00
* `>PUSHW addr` (RecvFrom)
2019-03-02 20:47:58 +00:00
* `>LIBCALL hLIBTCPIP,LIBTCPIP.Recv`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-10-01 05:48:42 +00:00
* CC: A = hMem
* CS: A = EC
*\--------------------------------------
2021-05-19 12:44:47 +00:00
SKT.RecvFrom >PULLW ZPTmpPtr1 addr
>PULLA
2018-11-01 08:53:47 +00:00
sec
2018-10-01 15:52:58 +00:00
.HS 90 BCC
2021-05-19 12:44:47 +00:00
*/--------------------------------------
* # Recv (RAW,DGRAM,SEQPKT)
* ## C
* `hMem recv(hFD fd);`
* ## ASM
* **In:**
* `lda fd`
* `>LIBCALL hLIBTCPIP,LIBTCPIP.Recv`
* ## RETURN VALUE
* CC: A = hMem
* CS: A = EC
*\--------------------------------------
2018-10-01 15:52:58 +00:00
SKT.Recv clc
2018-11-01 08:53:47 +00:00
php
2021-05-19 12:44:47 +00:00
jsr SKT.GetFD
2018-10-09 15:47:06 +00:00
2018-10-01 15:52:58 +00:00
ldy #S.SOCKET.T
lda (ZPPtrSKT),y
2020-06-07 13:47:00 +00:00
cmp #S.SOCKET.T.SEQPKT
2020-09-07 20:40:50 +00:00
bcc .10 RAW,DGRAM
bne .98 STREAM
2020-09-03 15:19:25 +00:00
2020-09-07 20:40:50 +00:00
jsr SKT.GetFromQueue SEQPKT
bcs .1
2021-05-19 12:44:47 +00:00
pha
>SYSCALL2 GetMemPtr
>STYA ZPFrameInPtr
jsr TCP.IN.SetDataInPtrAndLen
jsr SKT.GetTCB
lda ZPDataInLen
ldy ZPDataInLen+1
ldx #S.SOCKET.TCP.INACKNUM
jsr TCP.AddAYToSktCacheAtX
jsr SKT.StoreTCB
lda #S.TCP.OPTIONS.ACK
* jsr TCP.OUT.SendOptA
jsr TCP.SetSocketTCPO
pla
plp
clc
rts
.1 jsr SKT.CheckTCP
2020-06-07 13:47:00 +00:00
bcs .91
2018-10-01 15:52:58 +00:00
2020-09-09 06:11:45 +00:00
.90 lda #E.NODATA
2022-03-18 17:59:39 +00:00
.91 plp
2020-09-07 20:40:50 +00:00
sec
rts
2021-05-19 12:44:47 +00:00
.98 plp
.99 lda #ERR.SKT.BAD
sec
rts
*--------------------------------------
2020-09-03 06:24:36 +00:00
.10 jsr SKT.GetFromQueue
2020-09-09 06:11:45 +00:00
bcs .90
2021-05-19 12:44:47 +00:00
plp if CS, RecvFrom
2020-09-07 20:40:50 +00:00
bcc .9 CC, Recv : Exit with CC and A=hFrame
2018-11-01 08:53:47 +00:00
2018-10-01 15:52:58 +00:00
pha
2019-05-05 17:15:37 +00:00
>SYSCALL2 GetMemPtr
2018-10-01 15:52:58 +00:00
>STYA ZPFrameInPtr
2018-10-09 15:47:06 +00:00
ldy #S.IP.SRC
.2 lda (ZPFrameInPtr),y
sta SA.REMOTE+S.SOCKADDR.ADDR-S.IP.SRC,y
iny
cpy #S.IP.SRC+4
bne .2
ldy #S.IP.PROTOCOL
lda (ZPFrameInPtr),y
cmp #S.IP.PROTOCOL.ICMP
bne .3
ldy #S.ICMP.IDENTIFIER
bra .7
.3 cmp #S.IP.PROTOCOL.TCP
beq .6
2021-01-17 21:48:54 +00:00
2018-10-09 15:47:06 +00:00
cmp #S.IP.PROTOCOL.UDP
bne .8
.6 ldy #S.TCPUDP.SRCPORT
.7 lda (ZPFrameInPtr),y
sta SA.REMOTE+S.SOCKADDR+1
iny
lda (ZPFrameInPtr),y
sta SA.REMOTE+S.SOCKADDR
2021-06-03 17:43:28 +00:00
.8 ldy #S.SOCKADDR-1
2018-10-09 15:47:06 +00:00
.80 lda SA.REMOTE,y
sta (ZPTmpPtr1),y
dey
bpl .80
2018-10-01 15:52:58 +00:00
pla
clc
.9 rts
*/--------------------------------------
2020-06-07 08:06:51 +00:00
* # SendTo (RAW,DGRAM,SEQPKT)
2018-09-17 15:42:38 +00:00
* ## C
2018-10-01 05:48:42 +00:00
* `int skt.sendto(hFD fd, const void *buf, int count, const struct sockaddr *addr);`
2018-09-17 15:42:38 +00:00
* ## ASM
* **In:**
2021-05-19 12:44:47 +00:00
* `>PUSHB fd`
* `>PUSHW buf`
2018-09-17 15:42:38 +00:00
* `>PUSHWI count`
2021-05-19 12:44:47 +00:00
* `>PUSHW addr`
* `>LIBCALL hLIBTCPIP,LIBTCPIP.sendto`
* ## RETURN VALUE
* CC: Y,A = bytes written
* CS: A = EC
*\--------------------------------------
SKT.SendTo jsr SKT.PullRemAddr
*/--------------------------------------
* # Send (RAW,DGRAM,SEQPKT)
* ## C
* `int skt.send(hFD fd, const void *buf, int count);`
* ## ASM
* **In:**
* `>PUSHB fd`
2018-09-17 15:42:38 +00:00
* `>PUSHW buf`
2021-05-19 12:44:47 +00:00
* `>PUSHWI count`
2019-03-02 20:47:58 +00:00
* `>LIBCALL hLIBTCPIP,LIBTCPIP.send`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-09-17 15:42:38 +00:00
* CC: Y,A = bytes written
* CS: A = EC
*\--------------------------------------
2021-05-19 12:44:47 +00:00
SKT.Send jsr SKT.PullhFDDataInPtrLen
2019-11-17 14:39:55 +00:00
2021-05-19 12:44:47 +00:00
ldy #S.SOCKET.T
2018-10-01 05:48:42 +00:00
lda (ZPPtrSKT),y
cmp #S.SOCKET.T.STREAM
bcs *
2018-10-01 15:52:58 +00:00
tax
2018-11-07 21:48:48 +00:00
jmp (J.SKT.send,x)
2018-08-29 15:01:02 +00:00
*--------------------------------------
2018-10-08 15:41:00 +00:00
SKT.Send.RAW ldy #S.SOCKET.PROTO
2018-08-29 15:01:02 +00:00
lda (ZPPtrSKT),y
tax
>LDYA ZPDataInLen
jsr FRM.NewIP
2019-07-07 20:48:57 +00:00
bcc SKT.Send.8
2019-07-07 20:48:57 +00:00
rts
2018-08-29 15:01:02 +00:00
*--------------------------------------
2018-10-01 15:52:58 +00:00
SKT.Send.DGRAM ldx #S.IP.PROTOCOL.UDP
2019-10-03 06:25:27 +00:00
>LDYA ZPDataInLen
2018-08-29 15:01:02 +00:00
jsr FRM.NewIP
2018-09-17 15:42:38 +00:00
bcs SKT.Send.9
2018-09-17 15:42:38 +00:00
jsr SKT.SetFrameOutTCPUDPPorts
2019-07-07 20:48:57 +00:00
SKT.Send.8 jsr SKT.SetFrameOutDstIP
2018-11-07 21:48:48 +00:00
jsr SKT.CopyDataInToOut
2019-07-07 20:48:57 +00:00
clc Queue if fail
2018-08-29 15:01:02 +00:00
jmp FRM.SendIP
2018-10-01 15:52:58 +00:00
*--------------------------------------
2020-06-07 13:47:00 +00:00
SKT.Send.SEQPKT jsr SKT.CheckTCP
bcs SKT.Send.9
2019-07-07 20:48:57 +00:00
>LDYA ZPDataInLen
jsr TCP.NewFrame
bcs SKT.Send.9
2019-10-29 06:32:04 +00:00
jsr SKT.GetTCB
2019-07-07 20:48:57 +00:00
jsr SKT.CopyDataInToOut
2020-09-03 15:19:25 +00:00
2020-06-05 19:26:34 +00:00
jmp TCP.OUT.SEQSEND
*--------------------------------------
SKT.Send.STREAM lda #ERR.SKT.BAD
sec
SKT.Send.9 rts
2018-10-01 05:48:42 +00:00
*/--------------------------------------
2018-11-08 14:23:06 +00:00
* # GetSockOpt
* Set Socket Options
2018-10-01 05:48:42 +00:00
* ## C
2018-11-08 14:23:06 +00:00
* `int getsockopt(hFD fd);`
2018-10-01 05:48:42 +00:00
* ## ASM
* **In:**
2018-11-08 14:23:06 +00:00
* `lda fd`
* `>LIBCALL hLIBTCPIP,LIBTCPIP.GetSockOpt`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-10-01 05:48:42 +00:00
*\--------------------------------------
2021-05-19 12:44:47 +00:00
SKT.getsockopt jsr SKT.GetFD
2018-11-08 14:23:06 +00:00
ldy #S.SOCKET.O
lda (ZPPtrSKT),y
* clc
2018-10-01 05:48:42 +00:00
rts
2018-11-07 21:48:48 +00:00
*/--------------------------------------
* # SetSockOpt
* Set Socket Options
* ## C
* `int setsockopt(hFD fd, short int opts);`
* ## ASM
* **In:**
2021-05-19 12:44:47 +00:00
* `>PUSHB fd`
* `>PUSHB opts`
2018-11-07 21:48:48 +00:00
* `>LIBCALL hLIBTCPIP,LIBTCPIP.SetSockOpt`
* ## RETURN VALUE
*\--------------------------------------
2021-05-19 12:44:47 +00:00
SKT.setsockopt >PULLA
pha
jsr SKT.PullhFD
pla
2018-11-07 21:48:48 +00:00
ldy #S.SOCKET.O
sta (ZPPtrSKT),y
2018-11-08 14:23:06 +00:00
* clc
rts
2019-05-02 09:52:32 +00:00
*/--------------------------------------
* # EOF
* End Of File
* ## C
* `int eof(hFD fd);`
* ## ASM
* **In:**
* `lda fd`
* `>LIBCALL hLIBTCPIP,LIBTCPIP.EOF`
* ## RETURN VALUE
* CC : A = 0 if some data, A = $ff if EOF
* CS : A = Socket Error
*\--------------------------------------
2021-05-19 12:44:47 +00:00
SKT.EOF jsr SKT.GetFD
2019-03-02 20:47:58 +00:00
2021-05-19 12:44:47 +00:00
ldy #S.SOCKET.TCP.INUSED
2019-03-01 14:36:20 +00:00
lda (ZPPtrSKT),y
iny
ora (ZPPtrSKT),y
2019-05-02 09:52:32 +00:00
bne .8 some DATA...
2020-06-26 19:34:12 +00:00
2019-03-02 20:47:58 +00:00
jsr SKT.CheckStream
bcs .9
2020-06-29 05:49:24 +00:00
2019-05-02 09:52:32 +00:00
lda #$ff no DATA, EOF = true
2019-06-17 15:40:26 +00:00
* clc
2019-05-01 13:35:41 +00:00
rts
2020-06-29 05:49:24 +00:00
2019-05-02 09:52:32 +00:00
.8 lda #0 ...EOF = false
2021-05-19 12:44:47 +00:00
* clc
2019-03-02 20:47:58 +00:00
.9 rts
*--------------------------------------
2020-06-07 13:47:00 +00:00
SKT.CheckStream lda #S.SOCKET.T.STREAM
2020-09-03 15:19:25 +00:00
2020-06-07 13:47:00 +00:00
ldy #S.SOCKET.T
cmp (ZPPtrSKT),y
bne SKT.BAD
2019-03-02 20:47:58 +00:00
2020-06-07 13:47:00 +00:00
SKT.CheckTCP ldy #S.SOCKET.O
2019-03-02 20:47:58 +00:00
lda (ZPPtrSKT),y
and #S.SOCKET.O.ACCEPTCONN
2021-01-12 21:14:13 +00:00
bne SKT.BAD
2019-03-02 20:47:58 +00:00
2020-09-03 15:19:25 +00:00
ldy #S.SOCKET.TCP.S
2019-03-02 20:47:58 +00:00
lda (ZPPtrSKT),y
2019-10-05 17:24:41 +00:00
cmp #S.SOCKET.TCP.S.ESTBLSH
beq .8
2020-06-29 05:49:24 +00:00
2021-01-12 21:14:13 +00:00
bcc .9
2020-09-03 15:19:25 +00:00
2019-10-24 05:55:42 +00:00
lda #MLI.E.IO
* sec
rts
2019-10-05 17:24:41 +00:00
2019-05-04 21:13:50 +00:00
.8 lda #0
2019-07-07 20:48:57 +00:00
clc
2019-07-09 06:03:49 +00:00
rts
2019-03-02 20:47:58 +00:00
2021-01-12 21:14:13 +00:00
.9 lda #ERR.SKT.NOCONN
2019-10-05 17:24:41 +00:00
sec
rts
2020-06-07 13:47:00 +00:00
2019-07-07 20:48:57 +00:00
SKT.BAD lda #ERR.SKT.BAD
2019-03-02 20:47:58 +00:00
sec
2019-03-01 14:36:20 +00:00
rts
2018-11-08 14:23:06 +00:00
*/--------------------------------------
* # GetTable
* Get socket table
* ## C
* `void * gettable();`
* ## ASM
* **In:**
* `>LIBCALL hLIBTCPIP,LIBTCPIP.GetTable`
* ## RETURN VALUE
*\--------------------------------------
SKT.GetTable >LDYA L.SKT.Table
2018-11-07 21:48:48 +00:00
clc
rts
*--------------------------------------
2018-11-09 13:29:23 +00:00
SKT.PullhFDDataInPtrLen
>PULLW ZPDataInLen !!!use DataInPtr/Len
2021-05-19 12:44:47 +00:00
>PULLW ZPDataInPtr !!!DataOut trashed when sending ACK in TCP.OUT
SKT.PullhFD >PULLA
SKT.GetFD >SYSCALL2 GetMemPtr
>STYA ZPPtrSKT
2018-11-09 13:29:23 +00:00
rts
*--------------------------------------
2019-10-06 12:50:43 +00:00
SKT.PullLocAddr clc
.HS B0 BCS
2018-11-07 21:48:48 +00:00
*--------------------------------------
2019-10-06 12:50:43 +00:00
SKT.PullRemAddr sec
>PULLW ZPTmpPtr1
2018-10-01 05:48:42 +00:00
ldy #S.SOCKADDR-1
2019-10-05 17:24:41 +00:00
2019-10-06 12:50:43 +00:00
ldx #S.SOCKADDR-1
bcc .1
2021-05-19 12:44:47 +00:00
2019-10-06 12:50:43 +00:00
ldx #S.SOCKADDR+S.SOCKADDR-1
2018-10-01 05:48:42 +00:00
.1 lda (ZPTmpPtr1),y
2019-10-06 12:50:43 +00:00
sta SKT.LOC.ADDR,x
dex
2018-10-01 05:48:42 +00:00
dey
2018-10-10 15:39:22 +00:00
bpl .1
2019-10-05 17:24:41 +00:00
2018-10-01 05:48:42 +00:00
rts
*--------------------------------------
2018-11-06 16:31:13 +00:00
SKT.SetLocAddr ldy #S.SOCKET.LOC.PORT+1
2019-10-05 17:24:41 +00:00
2018-10-10 15:39:22 +00:00
.1 lda SKT.LOC.ADDR+S.SOCKADDR.ADDR-S.SOCKET.LOC.ADDR,y
2018-10-01 05:48:42 +00:00
sta (ZPPtrSKT),y
2018-11-06 16:31:13 +00:00
dey
cpy #S.SOCKET.LOC.ADDR
bcs .1
2019-10-05 17:24:41 +00:00
2018-10-01 05:48:42 +00:00
rts
*--------------------------------------
2018-11-06 16:31:13 +00:00
SKT.SetRemAddr ldy #S.SOCKET.REM.PORT+1
2019-10-05 17:24:41 +00:00
2018-10-10 15:39:22 +00:00
.1 lda SKT.REM.ADDR+S.SOCKADDR.ADDR-S.SOCKET.REM.ADDR,y
2018-10-01 05:48:42 +00:00
sta (ZPPtrSKT),y
2018-11-06 16:31:13 +00:00
dey
cpy #S.SOCKET.REM.ADDR
bcs .1
2019-10-05 17:24:41 +00:00
2018-10-01 05:48:42 +00:00
rts
*--------------------------------------
2020-09-03 15:19:25 +00:00
* SKT.REM.ADDR = Incoming Frame SRC
* SKT.LOC.ADDR = Incoming Frame DST
2019-07-07 20:48:57 +00:00
*--------------------------------------
2018-10-01 05:48:42 +00:00
SKT.FindMatchingLocRem
ldx #0
2018-11-01 08:53:47 +00:00
2018-10-01 05:48:42 +00:00
.1 lda SKT.TABLE,x
beq .8
2018-11-01 08:53:47 +00:00
2018-10-09 15:47:06 +00:00
phx
2021-05-19 12:44:47 +00:00
jsr SKT.GetFD
2018-10-09 15:47:06 +00:00
plx
2018-11-01 08:53:47 +00:00
ldy #S.SOCKET.AF
2018-11-08 14:23:06 +00:00
lda (ZPPtrSKT),y
2018-11-01 08:53:47 +00:00
cmp #AF.INET
bne .8
2019-07-07 20:48:57 +00:00
ldy #S.SOCKET.PROTO
lda (ZPPtrSKT),y
2019-10-03 06:25:27 +00:00
ldy #S.IP.PROTOCOL
2019-07-07 20:48:57 +00:00
cmp (ZPFrameInPtr),y
bne .8
2019-10-28 16:20:40 +00:00
2018-11-01 08:53:47 +00:00
ldy #S.SOCKET.LOC.ADDR
2018-11-08 14:23:06 +00:00
.2 lda (ZPPtrSKT),y
2018-10-01 05:48:42 +00:00
bne .4
2018-11-01 08:53:47 +00:00
2018-11-07 21:48:48 +00:00
ldy #S.SOCKET.LOC.PORT bound to 0.0.0.0,check only LOC port
2018-10-01 05:48:42 +00:00
2018-11-08 14:23:06 +00:00
.3 lda (ZPPtrSKT),y
2018-11-01 08:53:47 +00:00
2018-10-10 15:39:22 +00:00
.4 cmp SKT.LOC.ADDR+S.SOCKADDR.ADDR-S.SOCKET.LOC.ADDR,y
2018-10-01 05:48:42 +00:00
bne .8
2019-10-28 16:20:40 +00:00
2018-10-01 05:48:42 +00:00
iny
2018-11-01 08:53:47 +00:00
cpy #S.SOCKET.LOC.PORT+2
2018-10-01 05:48:42 +00:00
bne .3
2018-11-01 08:53:47 +00:00
ldy #S.SOCKET.O
2018-11-08 14:23:06 +00:00
lda (ZPPtrSKT),y
2018-11-01 08:53:47 +00:00
and #S.SOCKET.O.ACCEPTCONN
beq .6
2018-11-07 21:48:48 +00:00
2018-11-01 08:53:47 +00:00
ldy #S.TCP.OPTIONS Listening, only SYN packet....
lda (ZPFrameInPtr),y
cmp #S.TCP.OPTIONS.SYN
2020-03-16 06:50:15 +00:00
beq .7 SYN received on a LISTEN socket, ok
2018-11-01 08:53:47 +00:00
bne .8 bad packet for this listening
.6 lda SKT.REM.ADDR+S.SOCKADDR.ADDR
2019-07-07 20:48:57 +00:00
cmp #$ff incoming frame is FF.FF.FF.FF, Broadcast ?
2018-11-01 08:53:47 +00:00
bne .41
2019-07-07 20:48:57 +00:00
2018-11-01 08:53:47 +00:00
* ldy #S.SOCKET.O
2018-11-08 14:23:06 +00:00
lda (ZPPtrSKT),y
2018-10-01 05:48:42 +00:00
and #S.SOCKET.O.BROADCAST
2019-07-07 20:48:57 +00:00
bne .43
2019-10-03 06:25:27 +00:00
* sec
2019-10-28 16:20:40 +00:00
rts this socket does not accept broadcast
2018-10-01 05:48:42 +00:00
2018-11-01 08:53:47 +00:00
.41 ldy #S.SOCKET.REM.ADDR
2018-11-07 21:48:48 +00:00
2019-07-07 20:48:57 +00:00
lda (ZPPtrSKT),y
bne .44
2019-12-07 17:53:45 +00:00
2019-07-07 20:48:57 +00:00
.43 ldy #S.SOCKET.REM.PORT Frame is Broadcast, or listening is 0.0.0.0 check port only
2020-09-03 15:19:25 +00:00
2018-11-09 07:45:36 +00:00
.42 lda (ZPPtrSKT),y
2019-07-07 20:48:57 +00:00
.44 cmp SKT.REM.ADDR+S.SOCKADDR.ADDR-S.SOCKET.REM.ADDR,y
2018-11-01 08:53:47 +00:00
bne .8 wrong remote host, exit....
2019-12-07 17:53:45 +00:00
2018-10-01 05:48:42 +00:00
iny
cpy #S.SOCKET.REM.PORT+2
2018-11-09 07:45:36 +00:00
bne .42
2018-10-01 05:48:42 +00:00
.7 clc x = SKT.TABLE index
2018-10-01 05:48:42 +00:00
rts
2018-11-01 08:53:47 +00:00
2018-10-01 05:48:42 +00:00
.8 inx
cpx #K.SKTTABLE.SIZE
bne .1
2018-11-01 08:53:47 +00:00
2019-12-07 17:53:45 +00:00
* sec
2018-10-01 05:48:42 +00:00
rts
*--------------------------------------
2018-11-01 08:53:47 +00:00
SKT.AddToQueueA pha
ldy #S.SOCKET.HQ.HEAD
lda (ZPPtrSKT),y
tax
2020-09-03 15:19:25 +00:00
inc
cmp #S.SOCKET.HQ.MAX
bne .1
2020-06-07 13:47:00 +00:00
lda #0
2018-11-01 08:53:47 +00:00
2020-09-03 06:24:36 +00:00
.1 dey #S.SOCKET.HQ.TAIL
cmp (ZPPtrSKT),y
beq .9 Queue full!!
2018-11-01 08:53:47 +00:00
2020-09-03 06:24:36 +00:00
iny #S.SOCKET.HQ.HEAD
sta (ZPPtrSKT),y
txa
clc
adc #S.SOCKET.HQ
tay
2018-11-01 08:53:47 +00:00
pla
sta (ZPPtrSKT),y
clc
rts
2018-11-01 08:53:47 +00:00
.9 pla dicard hFrame
* sec
rts
*--------------------------------------
2019-07-07 20:48:57 +00:00
SKT.NewTCB ldx #S.SOCKET.TCP.INSEQNUM
2019-10-28 16:20:40 +00:00
2018-11-08 14:23:06 +00:00
.1 stz SKT.Cache,x
2018-11-01 08:53:47 +00:00
inx
cpx #S.SOCKET.TCP
2018-10-08 15:41:00 +00:00
bne .1
2019-10-28 16:20:40 +00:00
ldx #3
.2 lda A2osX.TIMER16,x
sta SKT.Cache+S.SOCKET.TCP.OUTNEXTSEQ,x
dex
bpl .2
2020-09-03 15:19:25 +00:00
2019-10-28 16:20:40 +00:00
ldy #S.SOCKET.T
lda (ZPPtrSKT),y
2020-06-07 08:06:51 +00:00
cmp #S.SOCKET.T.SEQPKT
2019-10-28 16:20:40 +00:00
bcc .8
2020-09-03 15:19:25 +00:00
2020-05-30 20:38:47 +00:00
tax
2020-09-03 15:19:25 +00:00
2018-11-01 08:53:47 +00:00
>LDYAI K.TCP.WSIZE
2018-11-08 14:23:06 +00:00
>STYA SKT.Cache+S.SOCKET.TCP.INFREE
2020-09-03 15:19:25 +00:00
2020-05-30 20:38:47 +00:00
cpx #S.SOCKET.T.STREAM
bcc .8
2020-09-03 15:19:25 +00:00
2019-06-17 15:40:26 +00:00
.DO AUXPIPE=1
>SYSCALL2 NewStkObj
.ELSE
2019-05-05 17:15:37 +00:00
>SYSCALL2 getmem
2019-06-17 15:40:26 +00:00
.FIN
2018-11-11 22:05:04 +00:00
bcs .9
2019-10-28 16:20:40 +00:00
2018-11-01 08:53:47 +00:00
txa
ldy #S.SOCKET.SQ.hInMem
sta (ZPPtrSKT),y
2018-10-08 15:41:00 +00:00
2020-05-30 20:38:47 +00:00
>LDYAI K.TCP.WSIZE
>STYA SKT.Cache+S.SOCKET.TCP.OUTFREE
2019-06-17 15:40:26 +00:00
.DO AUXPIPE=1
>SYSCALL2 NewStkObj
.ELSE
2019-05-05 17:15:37 +00:00
>SYSCALL2 getmem
2019-06-17 15:40:26 +00:00
.FIN
2018-11-11 22:05:04 +00:00
bcs .9
2019-10-28 16:20:40 +00:00
2018-11-01 08:53:47 +00:00
txa
ldy #S.SOCKET.SQ.hOutMem
2018-10-08 15:41:00 +00:00
sta (ZPPtrSKT),y
2019-10-28 16:20:40 +00:00
.8
2019-10-03 06:25:27 +00:00
* clc
2018-11-11 22:05:04 +00:00
.9 rts
2018-11-01 08:53:47 +00:00
*--------------------------------------
2019-07-07 20:48:57 +00:00
SKT.GetTCB ldy #S.SOCKET.TCP.INSEQNUM
2021-01-12 21:14:13 +00:00
2019-05-05 17:15:37 +00:00
.1 lda (ZPPtrSKT),y
sta SKT.Cache,y
iny
cpy #S.SOCKET.TCP
bne .1
2021-01-12 21:14:13 +00:00
2019-05-05 17:15:37 +00:00
rts
*--------------------------------------
2018-11-11 22:05:04 +00:00
SKT.StoreTCB.S ldy #S.SOCKET.TCP.S
sta (ZPPtrSKT),y
2019-07-07 20:48:57 +00:00
SKT.StoreTCB ldy #S.SOCKET.TCP.INSEQNUM
2021-01-12 21:14:13 +00:00
2018-11-08 14:23:06 +00:00
.1 lda SKT.Cache,y
2018-11-01 08:53:47 +00:00
sta (ZPPtrSKT),y
iny
cpy #S.SOCKET.TCP
bne .1
2021-01-12 21:14:13 +00:00
2018-11-07 21:48:48 +00:00
clc
2018-11-01 08:53:47 +00:00
rts
*--------------------------------------
SKT.SetFrameOutDstIP
2019-07-07 20:48:57 +00:00
ldx #3
2018-11-01 08:53:47 +00:00
2019-08-06 07:14:22 +00:00
ldy #S.SOCKET.REM.ADDR
lda (ZPPtrSKT),y
beq .3 Socket Bound to 0.0.0.0...
.1 lda (ZPPtrSKT),y
pha
iny
dex
2019-07-07 20:48:57 +00:00
bpl .1
2018-11-01 08:53:47 +00:00
ldy #S.IP.DST+3
2019-07-07 20:48:57 +00:00
ldx #3
2018-11-01 08:53:47 +00:00
.2 pla
sta (ZPFrameOutPtr),y
dey
dex
2019-07-07 20:48:57 +00:00
bpl .2
rts
2019-08-06 07:14:22 +00:00
.3 ldy #S.IP.DST+3 ...sent to provided SentTo ADDR
2019-07-07 20:48:57 +00:00
.4 lda SKT.REM.ADDR+S.SOCKADDR.ADDR,x
sta (ZPFrameOutPtr),y
dey
dex
bpl .4
rts
*--------------------------------------
2018-09-17 15:42:38 +00:00
SKT.SetFrameOutTCPUDPPorts
2018-10-01 05:48:42 +00:00
ldy #S.SOCKET.LOC.PORT
2018-09-17 15:42:38 +00:00
lda (ZPPtrSKT),y
tax
iny
lda (ZPPtrSKT),y
ldy #S.TCPUDP.SRCPORT
sta (ZPFrameOutPtr),y
iny
txa
sta (ZPFrameOutPtr),y
2018-11-07 21:48:48 +00:00
2018-10-01 05:48:42 +00:00
ldy #S.SOCKET.REM.PORT
2018-09-17 15:42:38 +00:00
lda (ZPPtrSKT),y
2019-07-07 20:48:57 +00:00
beq .1
2018-09-17 15:42:38 +00:00
tax
iny
lda (ZPPtrSKT),y
2019-07-07 20:48:57 +00:00
bra .2
2019-07-07 20:48:57 +00:00
.1 lda SKT.REM.ADDR+S.SOCKADDR.PORT+1
ldx SKT.REM.ADDR+S.SOCKADDR.PORT
2020-09-03 15:19:25 +00:00
2019-07-07 20:48:57 +00:00
.2 ldy #S.TCPUDP.DSTPORT
2018-09-17 15:42:38 +00:00
sta (ZPFrameOutPtr),y
iny
txa
sta (ZPFrameOutPtr),y
rts
*--------------------------------------
2019-07-19 06:41:33 +00:00
SKT.GetNotDataInLen
lda ZPDataInLen
eor #$FF
tax
lda ZPDataInLen+1
eor #$FF
rts
*--------------------------------------
SKT.CopyDataInToOut
2017-02-13 07:26:18 +00:00
lda ZPDataInPtr+1
pha
lda ZPDataOutPtr+1
pha
2018-11-07 21:48:48 +00:00
2019-07-19 06:41:33 +00:00
jsr SKT.GetNotDataInLen
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
2018-10-09 15:47:06 +00:00
.2 lda (ZPDataInPtr),y
sta (ZPDataOutPtr),y
iny
bne .1
inc ZPDataInPtr+1
inc ZPDataOutPtr+1
bne .1
2018-11-07 21:48:48 +00:00
2017-02-13 07:26:18 +00:00
.9 pla
sta ZPDataOutPtr+1
pla
sta ZPDataInPtr+1
rts
2019-06-19 15:56:59 +00:00
*--------------------------------------
.DO AUXPIPE=1
SKT.SetupZPCode ldy #ZP.CODE.Len-1
.1 lda ZP.CODE,y
sta ZPCode,y
dey
bpl .1
2019-06-19 15:56:59 +00:00
rts
.FIN
2019-05-05 17:15:37 +00:00
*--------------------------------------
MAN
2020-06-07 08:06:51 +00:00
SAVE usr/src/lib/libtcpip.s.skt
LOAD usr/src/lib/libtcpip.s
ASM