forked from Cpasjuste/uae4all2
-
Notifications
You must be signed in to change notification settings - Fork 10
/
menu_helper.cpp
executable file
·287 lines (255 loc) · 10.2 KB
/
menu_helper.cpp
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#include "sysconfig.h"
#include "sysdeps.h"
#include "config.h"
#include "uae.h"
#include "options.h"
#include "menu.h"
#include "menu_config.h"
#include "sound.h"
#include "disk.h"
#include "memory-uae.h"
#include "custom.h"
#include "xwin.h"
#include "drawing.h"
#if defined(ANDROID)
#include <SDL_screenkeyboard.h>
#include <android/log.h>
#endif
#ifdef __PSP2__
#include "psp2_shader.h"
#include "vita2d_fbo/includes/vita2d.h"
PSP2Shader *shader = NULL;
extern int mainMenu_shader;
#ifndef PRIVATE_HW_DATA
#define PRIVATE_HW_DATA
typedef struct private_hwdata {
vita2d_texture *texture;
SDL_Rect dst;
} private_hwdata;
#endif //PRIVATE_HW_DATA
#endif
extern int screenWidth;
extern int mainMenu_case;
extern int lastCpuSpeed;
extern int ntsc;
extern char launchDir[300];
extern char currentDir[300];
int saveAdfDir() {
char path[300];
snprintf(path, 300, "%s/conf/adfdir.conf", launchDir);
FILE *f = fopen(path, "w");
if (!f) return 0;
char buffer[310];
snprintf((char *) buffer, 310, "path=%s\n", currentDir);
fputs(buffer, f);
fclose(f);
return 1;
}
void extractFileName(char *str, char *buffer) {
char *p = str + strlen(str) - 1;
while (*p != '/')
p--;
p++;
strcpy(buffer, p);
}
#ifdef ANDROIDSDL
void update_onscreen()
{
SDL_ANDROID_SetScreenKeyboardFloatingJoystick(mainMenu_FloatingJoystick);
if (mainMenu_case != MAIN_MENU_CASE_DISPLAY && mainMenu_case != MAIN_MENU_CASE_MEMDISK && mainMenu_onScreen==0)
{
SDL_ANDROID_SetScreenKeyboardShown(0);
}
else
{
SDL_ANDROID_SetScreenKeyboardShown(1);
SDL_Rect pos_textinput, pos_dpad, pos_button1, pos_button2, pos_button3, pos_button4, pos_button5, pos_button6;
pos_textinput.x = mainMenu_pos_x_textinput*(SDL_ListModes(NULL, 0)[0]->w/(float)480);
pos_textinput.y = mainMenu_pos_y_textinput*(SDL_ListModes(NULL, 0)[0]->h/(float)360);
pos_textinput.h=SDL_ListModes(NULL, 0)[0]->h / (float)10 * mainMenu_button_size;
pos_textinput.w=pos_textinput.h;
SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, &pos_textinput);
pos_dpad.x = mainMenu_pos_x_dpad*(SDL_ListModes(NULL, 0)[0]->w/(float)480);
pos_dpad.y = mainMenu_pos_y_dpad*(SDL_ListModes(NULL, 0)[0]->h/(float)360);
pos_dpad.h=SDL_ListModes(NULL, 0)[0]->h / (float)2.5 * mainMenu_button_size;
pos_dpad.w=pos_dpad.h;
SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD, &pos_dpad);
pos_button1.x = mainMenu_pos_x_button1*(SDL_ListModes(NULL, 0)[0]->w/(float)480);
pos_button1.y = mainMenu_pos_y_button1*(SDL_ListModes(NULL, 0)[0]->h/(float)360);
pos_button1.h=SDL_ListModes(NULL, 0)[0]->h / (float)5 * mainMenu_button_size;
pos_button1.w=pos_button1.h;
SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, &pos_button1);
pos_button2.x = mainMenu_pos_x_button2*(SDL_ListModes(NULL, 0)[0]->w/(float)480);
pos_button2.y = mainMenu_pos_y_button2*(SDL_ListModes(NULL, 0)[0]->h/(float)360);
pos_button2.h=SDL_ListModes(NULL, 0)[0]->h / (float)5 * mainMenu_button_size;
pos_button2.w=pos_button2.h;
SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_1, &pos_button2);
pos_button3.x = mainMenu_pos_x_button3*(SDL_ListModes(NULL, 0)[0]->w/(float)480);
pos_button3.y = mainMenu_pos_y_button3*(SDL_ListModes(NULL, 0)[0]->h/(float)360);
pos_button3.h=SDL_ListModes(NULL, 0)[0]->h / (float)5 * mainMenu_button_size;
pos_button3.w=pos_button3.h;
SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, &pos_button3);
pos_button4.x = mainMenu_pos_x_button4*(SDL_ListModes(NULL, 0)[0]->w/(float)480);
pos_button4.y = mainMenu_pos_y_button4*(SDL_ListModes(NULL, 0)[0]->h/(float)360);
pos_button4.h=SDL_ListModes(NULL, 0)[0]->h / (float)5 * mainMenu_button_size;
pos_button4.w=pos_button4.h;
SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_3, &pos_button4);
pos_button5.x = mainMenu_pos_x_button5*(SDL_ListModes(NULL, 0)[0]->w/(float)480);
pos_button5.y = mainMenu_pos_y_button5*(SDL_ListModes(NULL, 0)[0]->h/(float)360);
pos_button5.h=SDL_ListModes(NULL, 0)[0]->h / (float)5 * mainMenu_button_size;
pos_button5.w=pos_button5.h;
SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_4, &pos_button5);
pos_button6.x = mainMenu_pos_x_button6*(SDL_ListModes(NULL, 0)[0]->w/(float)480);
pos_button6.y = mainMenu_pos_y_button6*(SDL_ListModes(NULL, 0)[0]->h/(float)360);
pos_button6.h=SDL_ListModes(NULL, 0)[0]->h / (float)5 * mainMenu_button_size;
pos_button6.w=pos_button6.h;
SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_5, &pos_button6);
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, mainMenu_onScreen_textinput);
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD, mainMenu_onScreen_dpad);
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, mainMenu_onScreen_button1);
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_1, mainMenu_onScreen_button2);
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, mainMenu_onScreen_button3);
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_3, mainMenu_onScreen_button4);
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_4, mainMenu_onScreen_button5);
SDL_ANDROID_SetScreenKeyboardButtonShown(SDL_ANDROID_SCREENKEYBOARD_BUTTON_5, mainMenu_onScreen_button6);
}
}
#endif
void update_display() {
char layersize[20];
snprintf(layersize, 20, "%dx480", screenWidth);
#ifndef WIN32
#ifndef __PSP2__
setenv("SDL_OMAP_LAYER_SIZE",layersize,1);
#endif
#endif
char bordercut[20];
snprintf(bordercut, 20, "%d,%d,0,0", mainMenu_cutLeft, mainMenu_cutRight);
#ifndef WIN32
#ifndef __PSP2__
setenv("SDL_OMAP_BORDER_CUT",bordercut,1);
#endif
#endif
#ifdef ANDROIDSDL
update_onscreen();
#endif
#ifdef __PSP2__
if (prSDLScreen != NULL) {
for (int i=0; i<10; i++)
{
SDL_FillRect(prSDLScreen,NULL,0);
SDL_Flip(prSDLScreen);
}
vita2d_wait_rendering_done();
vita2d_free_texture(prSDLScreen->hwdata->texture);
SDL_free(prSDLScreen->hwdata);
prSDLScreen->hwdata = NULL;
prSDLScreen->pixels = NULL;
SDL_FreeSurface(prSDLScreen);
prSDLScreen = NULL;
}
// speed up rendering
vita2d_texture_set_alloc_memblock_type(SCE_KERNEL_MEMBLOCK_TYPE_USER_RW);
prSDLScreen = SDL_SetVideoMode(visibleAreaWidth, mainMenu_displayedLines, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
printf("update_display: SDL_SetVideoMode(%i, %i, 16)\n", visibleAreaWidth, mainMenu_displayedLines);
float sh;
float sw;
int x;
int y;
//is a shader active?
if (mainMenu_shader != 0)
{
sh = 544;
if (mainMenu_displayHires)
sw = (0.5f*(float)visibleAreaWidth*((float)544/(float)mainMenu_displayedLines));
else
sw = ((float)visibleAreaWidth*((float)544/(float)mainMenu_displayedLines));
x = (960 - sw) / 2;
y = (544 - sh) / 2;
//This requires a recent SDL-Vita branch SDL12 for example
//https://github.com/rsn8887/SDL-Vita/tree/SDL12
//to compile
SDL_SetVideoModeScaling(x, y, sw, sh);
SDL_SetVideoModeBilinear(1);
}
else //otherwise do regular integer 2* scaling without filtering to ensure good picture quality
{
sh = (float) (2 * mainMenu_displayedLines);
if (mainMenu_displayHires)
sw = (float) (1 * visibleAreaWidth);
else
sw = (float) (2 * visibleAreaWidth);
x = (960 - sw) / 2;
y = (544 - sh) / 2;
SDL_SetVideoModeScaling(x, y, sw, sh);
SDL_SetVideoModeBilinear(0);
}
printf("update_display: SDL_SetVideoModeScaling(%i, %i, %i, %i)\n", x, y, (int)sw, (int)sh);
SDL_SetVideoModeSync(1);
// set vita2d shader
if(shader != NULL) {
delete(shader);
shader = NULL;
}
shader = new PSP2Shader((PSP2Shader::Shader)mainMenu_shader);
#else
#if defined(PANDORA) && !(defined(WIN32) || defined(AROS))
prSDLScreen = SDL_SetVideoMode(visibleAreaWidth, mainMenu_displayedLines, 16, SDL_SWSURFACE|SDL_FULLSCREEN|SDL_DOUBLEBUF);
#elif defined(PANDORA) && (defined(WIN32) || defined(AROS))
prSDLScreen = SDL_SetVideoMode(visibleAreaWidth, mainMenu_displayedLines, 16, SDL_SWSURFACE|SDL_DOUBLEBUF);
#else
prSDLScreen = SDL_SetVideoMode(visibleAreaWidth, mainMenu_displayedLines, 16, SDL_SWSURFACE|SDL_FULLSCREEN);
#endif
#endif
SDL_ShowCursor(SDL_DISABLE);
if (mainMenu_displayHires)
InitDisplayArea(visibleAreaWidth >> 1);
else
InitDisplayArea(visibleAreaWidth);
}
static bool cpuSpeedChanged = false;
void setCpuSpeed() {
#ifndef __PSP2__
char speedCmd[128];
if(mainMenu_cpuSpeed != lastCpuSpeed)
{
snprintf((char*)speedCmd, 128, "unset DISPLAY; echo y | sudo -n /usr/pandora/scripts/op_cpuspeed.sh %d", mainMenu_cpuSpeed);
system(speedCmd);
lastCpuSpeed = mainMenu_cpuSpeed;
cpuSpeedChanged = true;
}
if(mainMenu_ntsc != ntsc)
{
ntsc = mainMenu_ntsc;
if(ntsc)
system("sudo /usr/pandora/scripts/op_lcdrate.sh 60");
else
system("sudo /usr/pandora/scripts/op_lcdrate.sh 50");
}
update_display();
#endif
}
#ifdef PANDORA
void resetCpuSpeed(void) {
if (cpuSpeedChanged) {
FILE *f = fopen("/etc/pandora/conf/cpu.conf", "rt");
if (f) {
char line[128];
for (int i = 0; i < 6; ++i) {
fscanf(f, "%s\n", &line);
if (strncmp(line, "default:", 8) == 0) {
int value = 0;
sscanf(line, "default:%d", &value);
if (value > 500 && value < 1200) {
lastCpuSpeed = value - 10;
mainMenu_cpuSpeed = value;
setCpuSpeed();
printf("CPU speed reset to %d\n", value);
}
}
}
fclose(f);
}
}
}
#endif