Skip to content

Commit 97717ae

Browse files
committed
fix
1 parent 76eb19d commit 97717ae

16 files changed

+248
-30
lines changed

Makefile

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
SOURCES8=$(wildcard src/*.s)
22
OBJECTS8=$(SOURCES8:.s=.o)
33

4+
5+
46
ifeq ($(CC65_HOME),)
57
CC = cl65
68
AS = ca65
@@ -13,22 +15,26 @@ else
1315
AR = $(CC65_HOME)/bin/ar65
1416
endif
1517

16-
all: init $(SOURCES8) $(OBJECTS8)
18+
all: init $(SOURCES8) $(OBJECTS8) test
1719

1820
init: $(SOURCE)
1921
./configure
2022

2123
$(OBJECTS8): $(SOURCES8)
2224
@mkdir target/telestrat/lib/ -p
23-
@$(AS) -ttelestrat $(@:.o=.s) -o $@ --include-dir src/include
25+
@$(AS) -ttelestrat $(@:.o=.s) -o $@ --include-dir src/include -I libs/usr/include/asm/
2426
@$(AR) r socket.lib $@
2527
@mkdir -p build/lib8
26-
@mkdir -p build/usr/include/
28+
@mkdir -p build/usr/include/sys
2729
@mkdir -p build/usr/include/asm
28-
@cp src/include/socket.h build/usr/include/
30+
@cp src/socket.mac build/usr/include/asm
31+
@cp src/include/socket.h build/usr/include/sys/
2932
@cp src/include/socket.inc build/usr/include/asm/
3033
@cp socket.lib build/lib8/
3134

35+
test:
36+
@$(CC) -I src/include -ttelestrat test/gethttp.c libs/lib8/inet.lib socket.lib -o gethttp/
37+
3238
# tool:
3339
# @mkdir -p target/telestrat/ch395cfg/
3440
# $(CC) -ttelestrat -I src/include tools/ch395cfg/src/main.c target/telestrat/lib/ch395-8.lib -o target/telestrat/ch395cfg/ch395cfg

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Socket lib
2+
3+
## Documentation
4+
5+
## Repository
6+
7+
## Dependencies
8+

configure

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
mkdir libs
2-
curl --insecure -o libs/ch395lib.tgz http://repo.orix.oric.org/dists/2024.1/tgz/6502/ch395lib.tgz
2+
curl --insecure -o libs/ch395lib.tgz http://repo.orix.oric.org/dists/2024.2/tgz/6502/ch395lib.tgz
33
cd libs/ && tar xvfz ch395lib.tgz && cd ..
44
rm libs/ch395lib.tgz
5+
mkdir libs
6+
curl --insecure -o libs/inetlib.tgz http://repo.orix.oric.org/dists/2024.2/tgz/6502/inetlib.tgz
7+
cd libs/ && tar xvfz inetlib.tgz && cd ..
8+
rm libs/inetlib.tgz
9+

src/_connect.s

Whitespace-only changes.

src/_recv.s

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.export _recv
2+
3+
.import recv
4+
5+
.import popax
6+
.import popa
7+
8+
.proc _recv
9+
;;@proto ssize_t recv(unsigned char s, void *buf, unsigned char len, unsigned char flags);
10+
11+
; Drop flag
12+
jsr popax ; Get length
13+
jsr popax ; Get ptr
14+
jsr popa ; Get socket id
15+
16+
17+
jmp recv
18+
.endproc

src/_send.s

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.export _send
2+
.import send
3+
4+
.proc _send
5+
;;@proto unsigned int recv(int s, void *buf, unsigned int len, unsigned char flags);
6+
jmp send
7+
.endproc

src/_socket.s

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
.include "ch395.inc"
2+
.include "include/socket.inc"
3+
.include "../dependencies/orix-sdk/macros/SDK_print.mac"
4+
.include "../dependencies/orix-sdk/macros/SDK_conio.mac"
5+
.include "telestrat.inc"
6+
7+
.import socket_state
8+
.import socket_protocol
9+
10+
SOCKET_DEBUG = 1
11+
12+
.import socket
13+
.export _socket
14+
15+
.import ch395_set_ipraw_pro_sn
16+
.import ch395_set_proto_type_sn
17+
18+
.import popa
19+
20+
.proc _socket
21+
;;@brief Open a socket
22+
;;@proto unsigned char socket (unsigned char domain, unsigned char __type, unsigned char protocol);
23+
; Protocol
24+
;sta RES
25+
jsr popa
26+
sta RES+1 ; type
27+
jsr popa ; domain
28+
29+
tax
30+
31+
lda #$00
32+
ldy RES+1
33+
34+
.endproc
35+
36+
37+
38+
39+
.ifdef SOCKET_DEBUG
40+
41+
str_opening_socket:
42+
.byte "[libsocket/socket.s] Opening socket ",$0A,$0D,$00
43+
44+
str_socket_overflow:
45+
.byte "[libsocket/socket.s] id Socket overflow",$0A,$0D,$00
46+
47+
str_allocating_socket_id:
48+
.byte "[libsocket/socket.s] Allocating socket id : ",$00
49+
50+
debug_save_A:
51+
.res 1
52+
53+
debug_save_X:
54+
.res 1
55+
56+
debug_save_Y:
57+
.res 1
58+
.endif

src/_socket_close.s

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.export _socket_close
2+
.import socket_close
3+
4+
.proc _socket_close
5+
rts
6+
.endproc

src/bind.s

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
.include "telestrat.inc"
2-
32
.include "../dependencies/orix-sdk/macros/SDK_print.mac"
4-
5-
.include "../libs/usr/include/asm/ch395.inc"
3+
.include "ch395.inc"
64

75
.export bind
86

src/include/socket.h

+34-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
#define AF_UNSPEC 0
2-
#define AF_UNIX 1 /* Unix domain sockets */
2+
#define AF_UNIX 1 /* Unix domain sockets */
3+
#define AF_INET 2 /* Internet IP Protocol */
4+
5+
/* Socket types. */
6+
#define SOCK_STREAM 1 /* stream (connection) socket */
7+
#define SOCK_DGRAM 2 /* datagram (conn.less) socket */
8+
#define SOCK_RAW 3 /* raw socket */
9+
#define SOCK_RDM 4 /* reliably-delivered message */
10+
#define SOCK_SEQPACKET 5 /* sequential packet socket */
11+
#define SOCK_PACKET 10 /* linux specific way of */
12+
13+
struct sockaddr_in {
14+
unsigned char sin_family; // e.g. AF_INET
15+
unsigned int sin_port; // e.g. htons(3490)
16+
unsigned long sin_addr; // see struct in_addr, below
17+
char sin_zero[8]; // zero this if you want to
18+
};
19+
20+
21+
struct sockaddr {
22+
unsigned char sa_family; /* Address family */
23+
char sa_data[]; /* Socket address */
24+
};
325

426
/* Create a new socket of type TYPE in domain DOMAIN, using
527
protocol PROTOCOL. If PROTOCOL is zero, one is chosen automatically.
628
Returns a file descriptor for the new socket, or -1 for errors. */
7-
unsigned char socket (unsigned char domain, unsigned char __type, unsigned char protocol);
8-
unsigned char bind(int socket, const struct sockaddr* addr, socklen_t addrlen);
29+
unsigned char socket (unsigned char domain, unsigned char type, unsigned char protocol);
30+
unsigned char bind(int socket, const struct sockaddr_in* addr, unsigned int addrlen);
931
unsigned char listen(unsigned char socket, unsigned char backlog);
10-
unsigned char accept(int socket, struct sockaddr* addr, socklen_t* addrlen);
32+
unsigned char accept(int socket, struct sockaddr_in* addr, unsigned int addrlen);
33+
34+
35+
unsigned int recv(int s, void *buf, unsigned int len, unsigned char flags);
36+
unsigned int send(unsigned char sockfd, const void buf[], unsigned int len, unsigned char flags);
37+
38+
unsigned int socket_close(unsigned char sockfd);
39+
40+
int connect(unsigned int sockfd, const struct sockaddr *addr, unsigned int addrlen);

src/socket_recv.s src/recv.s

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
; Y error
77
; Timemout => (#ETIMEDOUT)
88
; OK => (#EOK) - A and X contains the length
9-
.include "include/socket.inc"
10-
.include "../libs/usr/include/asm/ch395.inc"
9+
.include "socket.inc"
10+
.include "ch395.inc"
11+
12+
.export recv
1113

1214
.import ch395_get_glob_int_status
1315
.import ch395_get_int_status_sn
@@ -18,7 +20,7 @@
1820

1921
.include "errno.inc"
2022

21-
.proc socket_recv
23+
.proc recv
2224
;;@brief Get socket data
2325
;;@inputX Socket id
2426
;;@inputA Low ptr to store the buffer
@@ -172,7 +174,7 @@ CH395_GINT_STAT_SOCKX:
172174
.byte CH395_GINT_STAT_SOCK1
173175
.byte CH395_GINT_STAT_SOCK2
174176
.byte CH395_GINT_STAT_SOCK3
175-
.byte CH395_GINT_STAT_SOCK4
176-
.byte CH395_GINT_STAT_SOCK5
177-
.byte CH395_GINT_STAT_SOCK6
178-
.byte CH395_GINT_STAT_SOCK7
177+
; .byte CH395_GINT_STAT_SOCK4
178+
; .byte CH395_GINT_STAT_SOCK5
179+
; .byte CH395_GINT_STAT_SOCK6
180+
; .byte CH395_GINT_STAT_SOCK7

src/socket_send.s src/send.s

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.include "telestrat.inc"
22

3-
.include "../libs/usr/include/asm/ch395.inc"
4-
.include "include/socket.inc"
3+
.include "ch395.inc"
4+
.include "socket.inc"
55

66
.include "../dependencies/orix-sdk/macros/SDK_print.mac"
77
.include "../dependencies/orix-sdk/macros/SDK_conio.mac"
@@ -11,7 +11,9 @@
1111

1212
.importzp ptr1
1313

14-
.proc socket_send
14+
.export send
15+
16+
.proc send
1517
;;@brief Send data into socket
1618
;;@inputX Socket id
1719
;;@inputA Low ptr of the buffer
@@ -22,8 +24,13 @@
2224
;;@returnsX High byte of the length
2325
;;@returnsY Error type
2426

25-
sta ptr1
26-
sty ptr1+1
27+
;;@```ca65
28+
;;@`; Use SENDTO macro
29+
;;@` SENDTO current_socket, str_password, 11
30+
;;@` rts
31+
32+
sta RESB
33+
sty RESB+1
2734
stx save_socket_id
2835

2936
ldy RES

src/socket.mac

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525

2626
lda #<buf
2727
ldy #>buf
28-
jsr socket_send
28+
jsr send
2929
.endmacro
3030

3131
.macro RECVFROM socket, buffer, len
3232
ldx socket
3333
lda #<buffer
3434
ldy #>buffer
35-
jsr socket_recv
35+
jsr recv
3636
.endmacro
3737

3838
.macro SOCKETCLOSE socket_id

src/socket.s

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
; ldx #AF_INET
1212
; ldy #SOCK_DGRAM
1313
; jsr socket
14-
.include "../libs/usr/include/asm/ch395.inc"
15-
.include "include/socket.inc"
14+
.include "ch395.inc"
15+
.include "socket.inc"
1616
.include "../dependencies/orix-sdk/macros/SDK_print.mac"
1717
.include "../dependencies/orix-sdk/macros/SDK_conio.mac"
1818
.include "telestrat.inc"
@@ -30,8 +30,14 @@ SOCKET_DEBUG = 1
3030
;;@brief Open a socket
3131
;;@returnsX The socket id
3232
;;@returnsA if != -1 socket id
33+
3334
;;@```ca65
3435
;;@` ; or use Macro (socket.mac) SOCKET domain, type, protocol
36+
;;@` SOCKET AF_INET, SOCK_STREAM, 0
37+
;;@`
38+
;;@```
39+
40+
;;@```ca65
3541
;;@` lda #$00
3642
;;@` ldx #AF_INET
3743
;;@` ldy #SOCK_STREAM

src/socket_open_test.s

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
;debug_socket = 1
22
.include "errno.inc"
3-
.include "../libs/usr/include/asm/ch395.inc"
4-
.include "include/socket.inc"
3+
.include "ch395.inc"
4+
.include "socket.inc"
55
.include "../dependencies/orix-sdk/macros/SDK_print.mac"
66
.include "../dependencies/orix-sdk/macros/SDK_conio.mac"
77
.include "telestrat.inc"

0 commit comments

Comments
 (0)