PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
sior.c
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9#
10# IOP exception handling.
11*/
12
13#include <stdarg.h>
14
15#include "types.h"
16#include "defs.h"
17#include "irx.h"
18
19#include "sior.h"
20#include "xprintf.h"
21
22#include "irx_imports.h"
23IRX_ID("sioremote_driver", 1, 1);
24
25extern struct irx_export_table _exp_sior;
26
27static struct t_SifRpcClientData cd0;
28static union siorCommsData buffer;
29static char tbuf[2048];
30
31void sio_init(u32 baudrate, u8 lcr_ueps, u8 lcr_upen, u8 lcr_usbl, u8 lcr_umode) {
32 struct siorInitArgs * i = &buffer.init;
33 i->baudrate = baudrate;
34 i->lcr_ueps = lcr_ueps;
35 i->lcr_upen = lcr_upen;
36 i->lcr_usbl = lcr_usbl;
37 i->lcr_umode = lcr_umode;
38 SifCallRpc(&cd0, SIOR_INIT, 0, &buffer, sizeof(struct siorInitArgs), NULL, 0, NULL, NULL);
39}
40
41int sio_putc(int c) {
42 buffer.result = c;
43 SifCallRpc(&cd0, SIOR_PUTC, 0, &buffer, sizeof(int), &buffer, sizeof(int), NULL, NULL);
44 return buffer.result;
45}
46
47int sio_getc(void) {
48 SifCallRpc(&cd0, SIOR_GETC, 0, 0, 0, &buffer, sizeof(int), NULL, NULL);
49 return buffer.result;
50}
51
52int sio_getc_block(void) {
53 SifCallRpc(&cd0, SIOR_GETCBLOCK, 0, 0, 0, &buffer, sizeof(int), NULL, NULL);
54 return buffer.result;
55}
56
57size_t sio_write(const char *buf, size_t size) {
58 buffer.write.buf = buf;
59 buffer.write.len = size;
60 SifCallRpc(&cd0, SIOR_WRITE, 0, &buffer, 8, &buffer, 4, NULL, NULL);
61 return buffer.result;
62}
63
64size_t sio_read(char *buf, size_t size) {
65 buffer.read.buf = buf;
66 buffer.read.len = size;
67 SifCallRpc(&cd0, SIOR_READ, 0, &buffer, 8, &buffer, 4, NULL, NULL);
68 return buffer.result;
69}
70
71int sio_puts(const char * str) {
72 buffer.cstr = str;
73 SifCallRpc(&cd0, SIOR_PUTS, 0, &buffer, 4, &buffer, 4, NULL, NULL);
74 return buffer.result;
75}
76
77int sio_putsn(const char * str) {
78 buffer.cstr = str;
79 SifCallRpc(&cd0, SIOR_PUTSN, 0, &buffer, 4, &buffer, 4, NULL, NULL);
80 return buffer.result;
81}
82
83char *sio_gets(char * str) {
84 buffer.str = str;
85 SifCallRpc(&cd0, SIOR_GETS, 0, &buffer, 4, &buffer, 4, NULL, NULL);
86 return buffer.str;
87}
88
89void sio_flush(void) {
90 SifCallRpc(&cd0, SIOR_FLUSH, 0, NULL, 0, NULL, 0, NULL, NULL);
91}
92
93int sio_vprintf(const char * str, va_list args) {
94 int res;
95
96 res = vsnprintf(tbuf, sizeof(tbuf), str, args);
97 printf("%s", tbuf);
98 sio_putsn(tbuf);
99
100 return res;
101}
102
103int sio_printf(const char * str, ...) {
104 int res;
105 va_list args;
106
107 va_start(args, str);
108 res = sio_vprintf(str, args);
109 va_end(args);
110
111 return res;
112}
113
114int _start(int argc, char *argv[])
115{
116 int retries;
117
118 (void)argc;
119 (void)argv;
120
121 memset(&cd0, 0, sizeof(cd0));
122
123 for (retries = 0; retries < 15; retries++) {
124 printf("Binding RPC.\n");
125 if (SifBindRpc(&cd0, SIOR_IRX, 0) < 0) {
126 printf("Failed!\n");
127 return MODULE_NO_RESIDENT_END;
128 }
129 if (cd0.server != 0) {
130 printf("Registering library.\n");
131 if (RegisterLibraryEntries(&_exp_sior)) {
132 printf("Couldn't register.\n");
133 return MODULE_NO_RESIDENT_END;
134 }
135 return MODULE_RESIDENT_END;
136 }
137 printf("Huh, not available, retrying... ?\n");
138 DelayThread(1000);
139 }
140
141 printf("Giving up.\n");
142
143 return MODULE_NO_RESIDENT_END;
144}
void sio_flush(void)
Definition sior.c:89
int sio_getc_block(void)
Definition sior.c:52
size_t sio_read(void *buf, size_t size)
char * sio_gets(char *str)
Definition sior.c:83
size_t sio_write(void *buf, size_t size)