sdk-world
v2026.11.05
PS2 SDK - world tier (copyleft-allowed, non-essential packages)
Toggle main menu visibility
Loading...
Searching...
No Matches
SIOCookie.c
1
#define _GNU_SOURCE
2
#include <sys/types.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <unistd.h>
6
#include <string.h>
7
#include <sio.h>
8
enum
EE_SIO_START_RETCODES
9
{
10
EESIO_SUCESS = 0,
11
EESIO_COOKIE_OPEN_IS_NULL
,
12
EESIO_BUFFER_ALLOC_IS_NULL
13
};
14
// GLOBAL
15
FILE *
EE_SIO
;
16
cookie_io_functions_t COOKIE_FNCTS;
17
18
ssize_t cookie_sio_write(
void
*c,
const
char
*buf,
size_t
size);
19
ssize_t cookie_sio_read(
void
*c,
char
*buf,
size_t
size);
20
// int cookie_sio_seek(void *c, _off64_t *offset, int whence);
21
// int cookie_sio_close(void *c);
22
23
int
ee_sio_start
(u32 baudrate, u8 lcr_ueps, u8 lcr_upen, u8 lcr_usbl, u8 lcr_umode,
int
hook_stdout)
24
{
25
sio_init(baudrate, lcr_ueps, lcr_upen, lcr_usbl, lcr_umode);
26
27
COOKIE_FNCTS.read = cookie_sio_read;
28
COOKIE_FNCTS.close = NULL;
29
COOKIE_FNCTS.seek = NULL;
30
COOKIE_FNCTS.write = cookie_sio_write;
31
EE_SIO
= fopencookie(NULL,
"w"
, COOKIE_FNCTS);
32
if
(hook_stdout)
33
{
34
sio_putsn(
"hooking std streams...\n"
);
35
sio_putsn(
"\tstdout...\n"
);
36
stdout = fopencookie(NULL,
"w"
, COOKIE_FNCTS);
37
setvbuf(stdout, NULL, _IOFBF, 0);
// no buffering
38
sio_putsn(
"\treplacing stderr with stdout...\n"
);
39
stderr = stdout;
40
sio_putsn(
"\treplacing EE_SIO with stdout...\n"
);
41
EE_SIO
= stdout;
42
}
else
{
43
setvbuf(
EE_SIO
, NULL, _IOFBF, 0);
// no buffering for this bad boy
44
}
45
if
(
EE_SIO
== NULL) {
46
printf(
"EE_SIO stream is NULL\n"
);
47
return
EESIO_COOKIE_OPEN_IS_NULL
;
48
}
49
fprintf(
EE_SIO
,
"%s: successfully started with:\n\t"
50
"baudrate=%d\n\t"
51
"lcr_ueps=%d\n\t"
52
"lcr_upen=%d\n\t"
53
"lcr_usbl=%d\n\t"
54
"lcr_umode=%d\n"
55
, __func__, baudrate, lcr_ueps, lcr_upen, lcr_usbl, lcr_umode);
56
return
EESIO_SUCESS;
57
}
58
59
60
ssize_t cookie_sio_write(
void
*c,
const
char
*buf,
size_t
size)
61
{
62
return
sio_putsn(buf);
63
}
64
65
ssize_t cookie_sio_read(
void
*c,
char
*buf,
size_t
size)
66
{
67
return
sio_read(buf, size);
68
}
69
/*
70
int cookie_sio_seek(void *c, _off64_t *offset, int whence)
71
{
72
DPRINTF("%s: start", __func__);
73
return 0;
74
}
75
76
int cookie_sio_close(void *c)
77
{
78
DPRINTF("%s: start", __func__);
79
return 0;
80
} */
EE_SIO_START_RETCODES
EE_SIO_START_RETCODES
Return values for ee_sio_start.
Definition
SIOCookie.h:33
EESIO_BUFFER_ALLOC_IS_NULL
@ EESIO_BUFFER_ALLOC_IS_NULL
Definition
SIOCookie.h:36
EESIO_COOKIE_OPEN_IS_NULL
@ EESIO_COOKIE_OPEN_IS_NULL
Definition
SIOCookie.h:35
EE_SIO
FILE * EE_SIO
custom stream to print data to the EE serial port. must call ee_sio_start() first to make it work
Definition
SIOCookie.c:15
ee_sio_start
int ee_sio_start(u32 baudrate, u8 lcr_ueps, u8 lcr_upen, u8 lcr_usbl, u8 lcr_umode, int hook_stdout)
initializes both the serial port comunication and the EE_SIO custom stream to print data trough it
Definition
SIOCookie.c:23
siocookie
src
SIOCookie.c
Generated by
1.18.0