Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jedeoric committed Apr 25, 2024
1 parent 0ea9764 commit fb5dbe2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
4 changes: 4 additions & 0 deletions docs/code/index.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
This lib is used to manage socket for Orix

```ca65
.include "socket.inc"
```
4 changes: 1 addition & 3 deletions src/_socket.s
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,5 @@
lda #$00
ldy RES+1

jsr socket
ldx #$00
rts
jmp socket
.endproc
2 changes: 1 addition & 1 deletion src/_socket_close.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
.import socket_close

.proc _socket_close
rts
jmp socket_close
.endproc
18 changes: 16 additions & 2 deletions src/socket.s
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@

ldx #$00

@search_another_socket:
@L1:
lda socket_state,x
beq socketfound
beq @socketfound
inx
cpx #NETWORK_MAX_SOCKET
bne @L1
Expand All @@ -56,9 +57,22 @@
lda #INVALID_SOCKET
rts

socketfound:
@socketfound:
; X contains the id of the socket
;
; We are looking if the state of the socket is still established (Because when it's closed,
; there is some delay if delay ti close tcp socket

txa
pha
jsr CMD_GET_SOCKET_STATUS_SN
cmp #CH395_SOCKET_CLOSED
bne @search_another_socket

pla
tax


lda RES ; Get Domain
sta socket_domain,x ; Save domain
; X contains the id of the socket here
Expand Down
17 changes: 6 additions & 11 deletions src/socket_close.s
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,18 @@
;;@brief Close socket
;;@inputX The socket id

lda socket_state,x
cmp #SOCK_STREAM
bne @is_not_tcp_connexion
;CMD_CLOSE_SOCKET_SN
;This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is
;closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still
;reserved, and you just need to open the Socket again when using the Socket the next time.
;In TCP mode, CH395 will automatically disconnect TCP before turning off Socket

txa
jsr ch395_tcp_disconnect_sn ; Modify Y and A in v2024.2 ch395 lib

@is_not_tcp_connexion:
lda #$00
sta socket_state,x

txa
; Flush buffers
pha
jsr ch395_clear_recv_buf_sn
; Close socket
pla

jsr ch395_close_socket_sn

rts
Expand Down

0 comments on commit fb5dbe2

Please sign in to comment.