1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/*
* stdio.h implementation for PSXSDK
*/
#ifndef _STDIO_H
#define _STDIO_H
#ifdef _PSXSDK_WRAPPER
/*
* Dirty hack...
*/
#include "/usr/include/stdio.h"
#else
#include <types.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C"
{
#endif
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#define EOF -1
enum stdio_directions
{
STDIO_DIRECTION_BIOS,
STDIO_DIRECTION_SIO
};
enum file_devices
{
FDEV_UNKNOWN,
FDEV_CDROM,
FDEV_MEMCARD,
FDEV_CONSOLE
};
extern int __stdio_direction;
/**
* File stream
*/
typedef struct
{
/** File descriptor, as returned by open() */
int fildes;
/** Current file position */
unsigned int pos;
/** File access mode */
unsigned int mode;
/** Device ID */
unsigned int dev;
/** Size in bytes */
unsigned int size;
/** Used internally by fopen(), 0 if free, 1 if occupied */
unsigned int used;
/** End-of-File marker */
unsigned int eof;
/** Error marker */
unsigned int error;
/** Sector buffer. */
unsigned char *const buf;
/** Last used sector for reading. */
size_t last_sect;
/** Sector buffer can be used for reading. */
unsigned int cache_available;
}FILE;
extern FILE *const stdin, *const stdout, *const stderr;
/* Console functions */
int putchar(int c);
int puts(const char *str);
/**
* BIOS printf() implementation. Does not support floating point.
* NOTE: when redirect_stdio_to_sio() is used, PSXSDK's internal implementation is used instead.
*/
extern int printf(const char *format, ...);
int fprintf(FILE *fd, const char *format, ...);
#ifdef __IN_LIBPSX
// Only for code in libpsx
// If PSXSDK_DEBUG is defined, dprintf() calls are turned into printf() calls
// otherwise they are left out
#ifdef PSXSDK_DEBUG
#define dprintf printf
#else
#define dprintf(fmt, ...)
#endif
#endif
int vsnprintf(char *string, size_t size, const char *fmt, va_list ap);
int vsprintf(char *string, const char *fmt, va_list ap);
int sprintf(char *string, const char *fmt, ...);
int snprintf(char *string, size_t size, const char *fmt, ...);
int vprintf(const char *fmt, va_list ap);
FILE *fdopen(int fildes, const char *mode);
FILE *fopen(const char *path, const char *mode);
int fclose(FILE *stream);
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite(void *ptr, size_t size, size_t nmemb, FILE *stream);
int fgetc(FILE *f);
int ftell(FILE *f);
int fseek(FILE *f, int offset, int whence);
void rewind(FILE *f);
int fputs(const char *str, FILE *stream);
void clearerr(FILE *stream);
int feof(FILE *stream);
int ferror(FILE *stream);
int fileno(FILE *stream);
void perror(const char *s);
#define getc(f) fgetc(f)
int rename(const char *oldname, const char *newname);
int remove(const char *filename);
#ifndef __cplusplus
// Define delete(x) to be remove(x) only when compiling plain C.
#define delete(x) remove(x)
#endif
/**
* Redirects STDIO to SIO (serial port)
*/
void redirect_stdio_to_sio(void);
/**
* Sets whether a carriage return must be written before a line feed.
* In simpler words, whether '\n' must be translated to a '\r\n' sequence.
* If you come from the Unix world, you most likely want to set this.
*
* @param setting New status of the setting (0 = disabled, 1 = enabled)
*/
void sio_stdio_mapcr(unsigned int setting);
/**
* scanf and friends
*/
int vsscanf(const char *str, const char *fmt, va_list ap);
int sscanf(const char *str, const char *fmt, ...);
/**
* STDIO for SIO
*/
int sio_putchar(int c);
int sio_puts(const char *str);
int sio_printf(const char *fmt, ...);
int sio_vprintf(const char *fmt, va_list ap);
#endif
#ifdef __cplusplus
}
#endif
#endif
|