1 /*----------------
2 Stuff to finish:
3 redo config stuff + add support for per game config files
4 decide how to add the sound code via the sound interface
5 add config options for video and sound
6 add dat.cpp and sshot.cpp
7
8
9 ------------------*/
10 #include <psppower.h>
11 #include <pspgu.h>
12 #include <pspkernel.h>
13 #include <pspdebug.h>
14 #include <pspctrl.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 //#include <unistd.h>
18 //#include <fcntl.h>
19 #include <string.h>
20 #include <math.h>
21 #include "burner.h"
22
23
24 int nAppVirtualFps = 6000; // App fps * 100
25 bool bRunPause=0;
26 bool bAlwaysProcessKeyboardInput=0;
27
28
29 /* Define the module info section */
30 PSP_MODULE_INFO("fbapsp", 0, 1, 0);
31 PSP_HEAP_SIZE_MAX();
32
33
34 #ifdef logging_build
35
36 static FILE *fp;
37
38
log_printf(const char * format,...)39 void log_printf(const char *format, ...)
40 {
41 va_list ap;
42 va_start(ap, format);
43 fprintf(fp, format, ap);
44 va_end(ap);
45 // fflush(fp);
46
47 }
48
49 #endif
50
51 /* Exit callback */
exit_callback(int arg1,int arg2,void * common)52 int exit_callback(int arg1, int arg2, void *common)
53 {
54 //need to cleanup here
55 #ifdef logging_build
56 fflush(fp);
57 fclose(fp);
58 #endif
59 scePowerSetClockFrequency(222,222,111);
60 sceKernelExitGame();
61
62 return 0;
63 }
64
65 /* Callback thread */
CallbackThread(SceSize args,void * argp)66 int CallbackThread(SceSize args, void *argp)
67 {
68 int cbid;
69
70 cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
71 sceKernelRegisterExitCallback(cbid);
72
73 sceKernelSleepThreadCB();
74
75 return 0;
76 }
77
78 /* Sets up the callback thread and returns its thread id */
SetupCallbacks(void)79 int SetupCallbacks(void)
80 {
81 int thid = 0;
82
83 thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, THREAD_ATTR_USER, 0);
84 if(thid >= 0)
85 {
86 sceKernelStartThread(thid, 0, 0);
87 }
88
89 return thid;
90 }
91
92
init_emu(unsigned int gamenum)93 void init_emu(unsigned int gamenum)
94 {
95 bCheatsAllowed=false;
96 // ConfigAppLoad();
97 // ConfigAppSave();
98 //CreateDirectory(".:\\cfg", NULL);
99 //CreateDirectory(".:\\state", NULL);
100 DrvInit(gamenum,0);
101 }
102
103
104
fbamain()105 void fbamain()
106 {
107 unsigned int i=0;
108 int menureturn=0;
109
110 #ifdef logging_build
111 fp = fopen("fbalog.txt", "a");
112 #endif
113 scePowerSetClockFrequency(333,333,166);
114
115 BurnLibInit();
116 // samsho 317
117 // ffight 131
118 // 2020bb 14
119 nBurnDrvSelect = 131; // game to start
120
121 InputInit();
122 init_emu(nBurnDrvSelect);
123
124 RunMessageLoop();
125
126 DrvExit();
127 InputExit();
128
129 ConfigAppSave();
130 BurnLibExit();
131
132 }
133
user_main(SceSize args,void * argp)134 int user_main(SceSize args, void *argp)
135 {
136 SetupCallbacks();
137
138 scePowerSetClockFrequency(333,333,166);
139
140 sceCtrlSetSamplingCycle( 0 );
141 sceCtrlSetSamplingMode( 1 );
142
143 fbamain();
144
145 scePowerSetClockFrequency(222,222,111);
146 sceKernelExitGame();
147
148 return 0;
149 }
150
main(int argc,char * argv[])151 int main(int argc, char* argv[])
152 {
153
154 // create user thread, tweek stack size here if necessary
155 SceUID thid = sceKernelCreateThread("User Mode Thread", user_main, 0x11,256 * 1024, PSP_THREAD_ATTR_USER, NULL);
156 // start user thread, then wait for it to do everything else
157 sceKernelStartThread(thid, 0, 0);
158 sceKernelWaitThreadEnd(thid, NULL);
159 return 0;
160 }
161
162
163
ANSIToTCHAR(const char * pszInString,TCHAR * pszOutString,int nOutSize)164 /* const */ TCHAR* ANSIToTCHAR(const char* pszInString, TCHAR* pszOutString, int nOutSize)
165 {
166 #if defined (UNICODE)
167 static TCHAR szStringBuffer[1024];
168
169 TCHAR* pszBuffer = pszOutString ? pszOutString : szStringBuffer;
170 int nBufferSize = pszOutString ? nOutSize * 2 : sizeof(szStringBuffer);
171
172 if (MultiByteToWideChar(CP_ACP, 0, pszInString, -1, pszBuffer, nBufferSize)) {
173 return pszBuffer;
174 }
175
176 return NULL;
177 #else
178 if (pszOutString) {
179 _tcscpy(pszOutString, pszInString);
180 return pszOutString;
181 }
182
183 return (TCHAR*)pszInString;
184 #endif
185 }
186
187
TCHARToANSI(const TCHAR * pszInString,char * pszOutString,int nOutSize)188 /* const */ char* TCHARToANSI(const TCHAR* pszInString, char* pszOutString, int nOutSize)
189 {
190 #if defined (UNICODE)
191 static char szStringBuffer[1024];
192 memset(szStringBuffer, 0, sizeof(szStringBuffer));
193
194 char* pszBuffer = pszOutString ? pszOutString : szStringBuffer;
195 int nBufferSize = pszOutString ? nOutSize * 2 : sizeof(szStringBuffer);
196
197 if (WideCharToMultiByte(CP_ACP, 0, pszInString, -1, pszBuffer, nBufferSize, NULL, NULL)) {
198 return pszBuffer;
199 }
200
201 return NULL;
202 #else
203 if (pszOutString) {
204 strcpy(pszOutString, pszInString);
205 return pszOutString;
206 }
207
208 return (char*)pszInString;
209 #endif
210 }
211
212
AppProcessKeyboardInput()213 bool AppProcessKeyboardInput()
214 {
215 return true;
216 }
217