-
Notifications
You must be signed in to change notification settings - Fork 0
/
psp_init.c
159 lines (129 loc) · 2.75 KB
/
psp_init.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
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
/*
* Copyright (C) 2006 Zx / Ludovic Jacomme ([email protected])
*/
#include "std.h"
#include "util.h"
#include <pspumd.h>
# include "psp_init.h"
# include "nlh.h"
#include <stdarg.h>
char *psp_home_dir = (char *)0;
unsigned short htons(unsigned short wIn)
{
u8 bHi = (wIn >> 8) & 0xFF;
u8 bLo = wIn & 0xFF;
return ((unsigned short)bLo << 8) | bHi;
}
# ifdef DEBUG
static FILE *pspDebugFd = (FILE *)0;
void
pspDebugPrintf(const char *Format, ...)
{
va_list Args;
va_start( Args, Format );
if (pspDebugFd == (FILE *)0) {
pspDebugFd = fopen("ms0:/psp/game/debug.log", "w");
if (! pspDebugFd) {
pspDebugScreenPrintf("can\'t open debug file !\n");
sceKernelExitGame();
}
}
vfprintf(pspDebugFd, Format, Args);
va_end( Args );
}
# endif
char *
my_dirname(char *filename)
{
char *dirname = (char *)0;
int index = strlen(filename);
while (index >= 0) {
if (filename[index] == '/') break;
index--;
}
if (index >= 0) {
dirname = (char *)malloc(sizeof(char) * (index + 1));
strncpy(dirname, filename, index);
dirname[index] = '\0';
} else {
dirname = (char *)malloc(sizeof(char) * 2);
dirname[0] = '.';
dirname[1] = '\0';
}
return dirname;
}
void
kbd_wait_start(void)
{
while (1)
{
SceCtrlData c;
sceCtrlReadBufferPositive(&c, 1);
if (c.Buttons & PSP_CTRL_START) break;
}
}
int
psp_exit(int status)
{
if (status) {
pspDebugScreenPrintf("exit with status %d!\n Press Start to contine\n", status);
kbd_wait_start();
} else {
}
# ifdef DEBUG
if (pspDebugFd) {
fclose(pspDebugFd);
pspDebugFd = (FILE *)0;
}
# endif
sceKernelExitGame();
return 0;
}
int
psp_exit_callback(int arg1, int arg2, void *arg3)
{
pspDebugScreenPrintf("exit call back call !\n");
psp_exit(0);
return 0;
}
int
psp_power_callback(int arg1, int arg2, void *arg3)
{
pspDebugScreenPrintf("power call back call !\n");
psp_exit(0);
return 0;
}
int
psp_callback_thread(SceSize args, void *argp)
{
int cid;
cid = sceKernelCreateCallback("Exit Call Back", psp_exit_callback, NULL);
sceKernelRegisterExitCallback(cid);
sceKernelSleepThreadCB();
return 0;
}
int
psp_setup_callbacks()
{
int thid = 0;
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
thid = sceKernelCreateThread("update_thread", psp_callback_thread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
void
psp_init_stuff(int argc, char **argv)
{
int check_umd;
psp_home_dir = my_dirname(argv[0]);
sceIoUnassign("disc0:");
sceIoAssign("disc0:", "umd0:0,0", "umdfat0:", 0, NULL, 0);
check_umd = sceUmdCheckMedium(0);
if (check_umd) {
sceUmdActivate(1,"disc0:");
sceUmdWaitDriveStat(UMD_WAITFORINIT);
}
}