-
Notifications
You must be signed in to change notification settings - Fork 0
/
psp_main.c
executable file
·90 lines (75 loc) · 1.81 KB
/
psp_main.c
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
/*
GP2X-ATARI: Porting of Atari800
Ludovic Jacomme <[email protected]>
*/
#include <stdio.h>
#include <zlib.h>
#include "global.h"
#include <SDL/SDL.h>
#include <stdlib.h>
#include <stdio.h>
#include "cpulcd.h"
#include "gp2x_psp.h"
#define STDOUT_FILE "stdout.txt"
#define STDERR_FILE "stderr.txt"
extern int SDL_main(int argc, char *argv[]);
static void cleanup_output(void);
/* Remove the output files if there was no output written */
static void cleanup_output(void)
{
#ifndef NO_STDIO_REDIRECT
FILE *file;
int empty;
#endif
/* Flush the output in case anything is queued */
fclose(stdout);
fclose(stderr);
#ifndef NO_STDIO_REDIRECT
/* See if the files have any output in them */
file = fopen(STDOUT_FILE, "rb");
if ( file ) {
empty = (fgetc(file) == EOF) ? 1 : 0;
fclose(file);
if ( empty ) {
remove(STDOUT_FILE);
}
}
file = fopen(STDERR_FILE, "rb");
if ( file ) {
empty = (fgetc(file) == EOF) ? 1 : 0;
fclose(file);
if ( empty ) {
remove(STDERR_FILE);
}
}
#endif
#if defined(WIZ_MODE) || defined(GP2X_MODE)
gp2xRmmodMMUhack();
set_speed_clock(CPU_CLOCK_STD);
cpulcd_deinit();
sync();
chdir("/usr/gp2x");
execl("/usr/gp2x/gp2xmenu", "/usr/gp2x/gp2xmenu", NULL);
#endif
}
int
main(int argc, char *argv[])
{
#if defined(WIZ_MODE) || defined(GP2X_MODE)
cpulcd_init();
#endif
#ifndef NO_STDIO_REDIRECT
/* Redirect standard output and standard error. */
/* TODO: Error checking. */
freopen(STDOUT_FILE, "w", stdout);
freopen(STDERR_FILE, "w", stderr);
setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */
setbuf(stderr, NULL); /* No buffering */
#endif /* NO_STDIO_REDIRECT */
atexit(cleanup_output);
#if defined(WIZ_MODE) || defined(GP2X_MODE)
gp2xInsmodMMUhack();
#endif
SDL_main(argc,argv);
return 0;
}