src/platform/psp2/psp2-context.c (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#include "psp2-context.h"
7
8#include <mgba/core/blip_buf.h>
9#include <mgba/core/core.h>
10
11#ifdef M_CORE_GBA
12#include <mgba/internal/gba/gba.h>
13#endif
14#ifdef M_CORE_GB
15#include <mgba/internal/gb/gb.h>
16#endif
17
18#include "feature/gui/gui-runner.h"
19#include <mgba/internal/gba/input.h>
20
21#include <mgba-util/memory.h>
22#include <mgba-util/circle-buffer.h>
23#include <mgba-util/math.h>
24#include <mgba-util/threading.h>
25#include <mgba-util/vfs.h>
26#include <mgba-util/platform/psp2/sce-vfs.h>
27
28#include <psp2/appmgr.h>
29#include <psp2/audioout.h>
30#include <psp2/camera.h>
31#include <psp2/ctrl.h>
32#include <psp2/display.h>
33#include <psp2/gxm.h>
34#include <psp2/kernel/sysmem.h>
35#include <psp2/motion.h>
36
37#include <vita2d.h>
38
39#define RUMBLE_PWM 8
40#define CDRAM_ALIGN 0x40000
41
42mLOG_DECLARE_CATEGORY(GUI_PSP2);
43mLOG_DEFINE_CATEGORY(GUI_PSP2, "Vita", "gui.psp2");
44
45static enum ScreenMode {
46 SM_BACKDROP,
47 SM_PLAIN,
48 SM_FULL,
49 SM_ASPECT,
50 SM_MAX
51} screenMode;
52
53static int currentTex;
54static vita2d_texture* tex[2];
55static vita2d_texture* screenshot;
56static Thread audioThread;
57static bool interframeBlending = false;
58static bool sgbCrop = false;
59
60static struct mSceRotationSource {
61 struct mRotationSource d;
62 struct SceMotionSensorState state;
63} rotation;
64
65static struct mSceRumble {
66 struct mRumble d;
67 struct CircleBuffer history;
68 int current;
69} rumble;
70
71static struct mSceImageSource {
72 struct mImageSource d;
73 SceUID memblock;
74 void* buffer;
75 unsigned cam;
76 size_t bufferOffset;
77} camera;
78
79static struct mAVStream stream;
80
81bool frameLimiter = true;
82
83extern const uint8_t _binary_backdrop_png_start[];
84static vita2d_texture* backdrop = 0;
85
86#define PSP2_SAMPLES 512
87#define PSP2_AUDIO_BUFFER_SIZE (PSP2_SAMPLES * 16)
88
89static struct mPSP2AudioContext {
90 struct GBAStereoSample buffer[PSP2_AUDIO_BUFFER_SIZE];
91 size_t writeOffset;
92 size_t readOffset;
93 size_t samples;
94 Mutex mutex;
95 Condition cond;
96 bool running;
97} audioContext;
98
99void mPSP2MapKey(struct mInputMap* map, int pspKey, int key) {
100 mInputBindKey(map, PSP2_INPUT, __builtin_ctz(pspKey), key);
101}
102
103static THREAD_ENTRY _audioThread(void* context) {
104 struct mPSP2AudioContext* audio = (struct mPSP2AudioContext*) context;
105 uint32_t zeroBuffer[PSP2_SAMPLES] = {0};
106 void* buffer = zeroBuffer;
107 int audioPort = sceAudioOutOpenPort(SCE_AUDIO_OUT_PORT_TYPE_MAIN, PSP2_SAMPLES, 48000, SCE_AUDIO_OUT_MODE_STEREO);
108 while (audio->running) {
109 MutexLock(&audio->mutex);
110 if (buffer != zeroBuffer) {
111 // Can only happen in successive iterations
112 audio->samples -= PSP2_SAMPLES;
113 ConditionWake(&audio->cond);
114 }
115 if (audio->samples >= PSP2_SAMPLES) {
116 buffer = &audio->buffer[audio->readOffset];
117 audio->readOffset += PSP2_SAMPLES;
118 if (audio->readOffset >= PSP2_AUDIO_BUFFER_SIZE) {
119 audio->readOffset = 0;
120 }
121 // Don't mark samples as read until the next loop iteration to prevent
122 // writing to the buffer while being read (see above)
123 } else {
124 buffer = zeroBuffer;
125 }
126 MutexUnlock(&audio->mutex);
127
128 sceAudioOutOutput(audioPort, buffer);
129 }
130 sceAudioOutReleasePort(audioPort);
131 return 0;
132}
133
134static void _sampleRotation(struct mRotationSource* source) {
135 struct mSceRotationSource* rotation = (struct mSceRotationSource*) source;
136 sceMotionGetSensorState(&rotation->state, 1);
137}
138
139static int32_t _readTiltX(struct mRotationSource* source) {
140 struct mSceRotationSource* rotation = (struct mSceRotationSource*) source;
141 return rotation->state.accelerometer.x * 0x30000000;
142}
143
144static int32_t _readTiltY(struct mRotationSource* source) {
145 struct mSceRotationSource* rotation = (struct mSceRotationSource*) source;
146 return rotation->state.accelerometer.y * -0x30000000;
147}
148
149static int32_t _readGyroZ(struct mRotationSource* source) {
150 struct mSceRotationSource* rotation = (struct mSceRotationSource*) source;
151 return rotation->state.gyro.z * -0x10000000;
152}
153
154static void _setRumble(struct mRumble* source, int enable) {
155 struct mSceRumble* rumble = (struct mSceRumble*) source;
156 rumble->current += enable;
157 if (CircleBufferSize(&rumble->history) == RUMBLE_PWM) {
158 int8_t oldLevel;
159 CircleBufferRead8(&rumble->history, &oldLevel);
160 rumble->current -= oldLevel;
161 }
162 CircleBufferWrite8(&rumble->history, enable);
163 int small = (rumble->current << 21) / 65793;
164 int big = ((rumble->current * rumble->current) << 18) / 65793;
165 struct SceCtrlActuator state = {
166 small,
167 big
168 };
169 sceCtrlSetActuator(1, &state);
170}
171
172static void _resetCamera(struct mSceImageSource* imageSource) {
173 if (!imageSource->cam) {
174 return;
175 }
176
177 sceCameraOpen(imageSource->cam - 1, &(SceCameraInfo) {
178 .size = sizeof(SceCameraInfo),
179 .format = 5, // SCE_CAMERA_FORMAT_ABGR
180 .resolution = SCE_CAMERA_RESOLUTION_176_144,
181 .framerate = SCE_CAMERA_FRAMERATE_30_FPS,
182 .sizeIBase = 176 * 144 * 4,
183 .pitch = 0,
184 .pIBase = imageSource->buffer,
185 });
186 sceCameraStart(imageSource->cam - 1);
187}
188
189static void _startRequestImage(struct mImageSource* source, unsigned w, unsigned h, int colorFormats) {
190 UNUSED(colorFormats);
191 struct mSceImageSource* imageSource = (struct mSceImageSource*) source;
192
193 if (!imageSource->buffer) {
194 imageSource->memblock = sceKernelAllocMemBlock("camera", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, CDRAM_ALIGN, NULL);
195 sceKernelGetMemBlockBase(imageSource->memblock, &imageSource->buffer);
196 }
197
198 if (!imageSource->cam) {
199 return;
200 }
201
202 _resetCamera(imageSource);
203 imageSource->bufferOffset = (176 - w) / 2 + (144 - h) * 176 / 2;
204
205 SceCameraRead read = {
206 sizeof(SceCameraRead),
207 1
208 };
209 sceCameraRead(imageSource->cam - 1, &read);
210}
211
212static void _stopRequestImage(struct mImageSource* source) {
213 struct mSceImageSource* imageSource = (struct mSceImageSource*) source;
214 if (imageSource->cam) {
215 sceCameraStop(imageSource->cam - 1);
216 sceCameraClose(imageSource->cam - 1);
217 }
218 sceKernelFreeMemBlock(imageSource->memblock);
219 imageSource->buffer = NULL;
220}
221
222
223static void _requestImage(struct mImageSource* source, const void** buffer, size_t* stride, enum mColorFormat* colorFormat) {
224 struct mSceImageSource* imageSource = (struct mSceImageSource*) source;
225
226 if (!imageSource->cam) {
227 memset(imageSource->buffer, 0, 176 * 144 * 4);
228 *buffer = (uint32_t*) imageSource->buffer;
229 *stride = 176;
230 *colorFormat = mCOLOR_XBGR8;
231 return;
232 }
233
234 *buffer = (uint32_t*) imageSource->buffer + imageSource->bufferOffset;
235 *stride = 176;
236 *colorFormat = mCOLOR_XBGR8;
237
238 SceCameraRead read = {
239 sizeof(SceCameraRead),
240 1
241 };
242 sceCameraRead(imageSource->cam - 1, &read);
243}
244
245static void _postAudioBuffer(struct mAVStream* stream, blip_t* left, blip_t* right) {
246 UNUSED(stream);
247 MutexLock(&audioContext.mutex);
248 while (audioContext.samples + PSP2_SAMPLES >= PSP2_AUDIO_BUFFER_SIZE) {
249 if (!frameLimiter) {
250 blip_clear(left);
251 blip_clear(right);
252 MutexUnlock(&audioContext.mutex);
253 return;
254 }
255 ConditionWait(&audioContext.cond, &audioContext.mutex);
256 }
257 struct GBAStereoSample* samples = &audioContext.buffer[audioContext.writeOffset];
258 blip_read_samples(left, &samples[0].left, PSP2_SAMPLES, true);
259 blip_read_samples(right, &samples[0].right, PSP2_SAMPLES, true);
260 audioContext.samples += PSP2_SAMPLES;
261 audioContext.writeOffset += PSP2_SAMPLES;
262 if (audioContext.writeOffset >= PSP2_AUDIO_BUFFER_SIZE) {
263 audioContext.writeOffset = 0;
264 }
265 MutexUnlock(&audioContext.mutex);
266}
267
268uint16_t mPSP2PollInput(struct mGUIRunner* runner) {
269 SceCtrlData pad;
270 sceCtrlPeekBufferPositiveExt2(0, &pad, 1);
271
272 int activeKeys = mInputMapKeyBits(&runner->core->inputMap, PSP2_INPUT, pad.buttons, 0);
273 int angles = mInputMapAxis(&runner->core->inputMap, PSP2_INPUT, 0, pad.ly);
274 if (angles != GBA_KEY_NONE) {
275 activeKeys |= 1 << angles;
276 }
277 angles = mInputMapAxis(&runner->core->inputMap, PSP2_INPUT, 1, pad.lx);
278 if (angles != GBA_KEY_NONE) {
279 activeKeys |= 1 << angles;
280 }
281 angles = mInputMapAxis(&runner->core->inputMap, PSP2_INPUT, 2, pad.ry);
282 if (angles != GBA_KEY_NONE) {
283 activeKeys |= 1 << angles;
284 }
285 angles = mInputMapAxis(&runner->core->inputMap, PSP2_INPUT, 3, pad.rx);
286 if (angles != GBA_KEY_NONE) {
287 activeKeys |= 1 << angles;
288 }
289 return activeKeys;
290}
291
292void mPSP2SetFrameLimiter(struct mGUIRunner* runner, bool limit) {
293 UNUSED(runner);
294 if (!frameLimiter && limit) {
295 MutexLock(&audioContext.mutex);
296 while (audioContext.samples) {
297 ConditionWait(&audioContext.cond, &audioContext.mutex);
298 }
299 MutexUnlock(&audioContext.mutex);
300 }
301 frameLimiter = limit;
302}
303
304void mPSP2Setup(struct mGUIRunner* runner) {
305 mCoreConfigSetDefaultIntValue(&runner->config, "threadedVideo", 1);
306 mCoreLoadForeignConfig(runner->core, &runner->config);
307
308 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_CROSS, GBA_KEY_A);
309 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_CIRCLE, GBA_KEY_B);
310 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_START, GBA_KEY_START);
311 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_SELECT, GBA_KEY_SELECT);
312 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_UP, GBA_KEY_UP);
313 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_DOWN, GBA_KEY_DOWN);
314 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_LEFT, GBA_KEY_LEFT);
315 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_RIGHT, GBA_KEY_RIGHT);
316 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_L1, GBA_KEY_L);
317 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_R1, GBA_KEY_R);
318
319 struct mInputAxis desc = { GBA_KEY_DOWN, GBA_KEY_UP, 192, 64 };
320 mInputBindAxis(&runner->core->inputMap, PSP2_INPUT, 0, &desc);
321 desc = (struct mInputAxis) { GBA_KEY_RIGHT, GBA_KEY_LEFT, 192, 64 };
322 mInputBindAxis(&runner->core->inputMap, PSP2_INPUT, 1, &desc);
323
324 unsigned width, height;
325 runner->core->desiredVideoDimensions(runner->core, &width, &height);
326 tex[0] = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR);
327 tex[1] = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR);
328 currentTex = 0;
329 screenshot = vita2d_create_empty_texture_format(256, toPow2(height), SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR);
330
331 runner->core->setVideoBuffer(runner->core, vita2d_texture_get_datap(tex[currentTex]), 256);
332 runner->core->setAudioBufferSize(runner->core, PSP2_SAMPLES);
333
334 rotation.d.sample = _sampleRotation;
335 rotation.d.readTiltX = _readTiltX;
336 rotation.d.readTiltY = _readTiltY;
337 rotation.d.readGyroZ = _readGyroZ;
338 runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation.d);
339
340 rumble.d.setRumble = _setRumble;
341 CircleBufferInit(&rumble.history, RUMBLE_PWM);
342 runner->core->setPeripheral(runner->core, mPERIPH_RUMBLE, &rumble.d);
343
344 camera.d.startRequestImage = _startRequestImage;
345 camera.d.stopRequestImage = _stopRequestImage;
346 camera.d.requestImage = _requestImage;
347 camera.buffer = NULL;
348 camera.cam = 1;
349 runner->core->setPeripheral(runner->core, mPERIPH_IMAGE_SOURCE, &camera.d);
350
351
352 stream.videoDimensionsChanged = NULL;
353 stream.postAudioFrame = NULL;
354 stream.postAudioBuffer = _postAudioBuffer;
355 stream.postVideoFrame = NULL;
356 runner->core->setAVStream(runner->core, &stream);
357
358 frameLimiter = true;
359 backdrop = vita2d_load_PNG_buffer(_binary_backdrop_png_start);
360
361 unsigned mode;
362 if (mCoreConfigGetUIntValue(&runner->config, "screenMode", &mode) && mode < SM_MAX) {
363 screenMode = mode;
364 }
365 if (mCoreConfigGetUIntValue(&runner->config, "camera", &mode)) {
366 camera.cam = mode;
367 }
368 int fakeBool;
369 if (mCoreConfigGetIntValue(&runner->config, "sgb.borderCrop", &fakeBool)) {
370 sgbCrop = fakeBool;
371 }
372}
373
374void mPSP2LoadROM(struct mGUIRunner* runner) {
375 float rate = 60.0f / 1.001f;
376 sceDisplayGetRefreshRate(&rate);
377 double ratio = GBAAudioCalculateRatio(1, rate, 1);
378 blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), 48000 * ratio);
379 blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), 48000 * ratio);
380
381 switch (runner->core->platform(runner->core)) {
382#ifdef M_CORE_GBA
383 case PLATFORM_GBA:
384 if (((struct GBA*) runner->core->board)->memory.hw.devices & (HW_TILT | HW_GYRO)) {
385 sceMotionStartSampling();
386 }
387 break;
388#endif
389#ifdef M_CORE_GB
390 case PLATFORM_GB:
391 if (((struct GB*) runner->core->board)->memory.mbcType == GB_MBC7) {
392 sceMotionStartSampling();
393 }
394 break;
395#endif
396 default:
397 break;
398 }
399
400 int fakeBool;
401 if (mCoreConfigGetIntValue(&runner->config, "interframeBlending", &fakeBool)) {
402 interframeBlending = fakeBool;
403 }
404
405 // Backcompat: Old versions of mGBA use an older binding system that has different mappings for L/R
406 if (!sceKernelIsPSVitaTV()) {
407 int key = mInputMapKey(&runner->core->inputMap, PSP2_INPUT, __builtin_ctz(SCE_CTRL_L2));
408 if (key >= 0) {
409 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_L1, key);
410 }
411 key = mInputMapKey(&runner->core->inputMap, PSP2_INPUT, __builtin_ctz(SCE_CTRL_R2));
412 if (key >= 0) {
413 mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_R1, key);
414 }
415 }
416
417 MutexInit(&audioContext.mutex);
418 ConditionInit(&audioContext.cond);
419 memset(audioContext.buffer, 0, sizeof(audioContext.buffer));
420 audioContext.readOffset = 0;
421 audioContext.writeOffset = 0;
422 audioContext.running = true;
423 ThreadCreate(&audioThread, _audioThread, &audioContext);
424}
425
426
427void mPSP2UnloadROM(struct mGUIRunner* runner) {
428 switch (runner->core->platform(runner->core)) {
429#ifdef M_CORE_GBA
430 case PLATFORM_GBA:
431 if (((struct GBA*) runner->core->board)->memory.hw.devices & (HW_TILT | HW_GYRO)) {
432 sceMotionStopSampling();
433 }
434 break;
435#endif
436#ifdef M_CORE_GB
437 case PLATFORM_GB:
438 if (((struct GB*) runner->core->board)->memory.mbcType == GB_MBC7) {
439 sceMotionStopSampling();
440 }
441 break;
442#endif
443 default:
444 break;
445 }
446 audioContext.running = false;
447 ThreadJoin(&audioThread);
448}
449
450void mPSP2Paused(struct mGUIRunner* runner) {
451 UNUSED(runner);
452 struct SceCtrlActuator state = {
453 0,
454 0
455 };
456 sceCtrlSetActuator(1, &state);
457 frameLimiter = true;
458}
459
460void mPSP2Unpaused(struct mGUIRunner* runner) {
461 unsigned mode;
462 if (mCoreConfigGetUIntValue(&runner->config, "screenMode", &mode) && mode != screenMode) {
463 screenMode = mode;
464 }
465
466 if (mCoreConfigGetUIntValue(&runner->config, "camera", &mode)) {
467 if (mode != camera.cam) {
468 if (camera.buffer) {
469 sceCameraStop(camera.cam - 1);
470 sceCameraClose(camera.cam - 1);
471 }
472 camera.cam = mode;
473 if (camera.buffer) {
474 _resetCamera(&camera);
475 }
476 }
477 }
478
479 int fakeBool;
480 if (mCoreConfigGetIntValue(&runner->config, "interframeBlending", &fakeBool)) {
481 interframeBlending = fakeBool;
482 }
483
484 if (mCoreConfigGetIntValue(&runner->config, "sgb.borderCrop", &fakeBool)) {
485 sgbCrop = fakeBool;
486 }
487}
488
489void mPSP2Teardown(struct mGUIRunner* runner) {
490 UNUSED(runner);
491 CircleBufferDeinit(&rumble.history);
492 vita2d_free_texture(tex[0]);
493 vita2d_free_texture(tex[1]);
494 vita2d_free_texture(screenshot);
495 frameLimiter = true;
496}
497
498void _drawTex(vita2d_texture* t, unsigned width, unsigned height, bool faded, bool interframe) {
499 unsigned w = width;
500 unsigned h = height;
501 // Get greatest common divisor
502 while (w != 0) {
503 int temp = h % w;
504 h = w;
505 w = temp;
506 }
507 int gcd = h;
508 int aspectw = width / gcd;
509 int aspecth = height / gcd;
510 float scalex;
511 float scaley;
512
513 unsigned tint = 0x1FFFFFFF;
514 if (!faded) {
515 if (interframe) {
516 tint |= 0x60000000;
517 } else {
518 tint |= 0xE0000000;
519 }
520 } else if (!interframe) {
521 tint |= 0x20000000;
522 }
523
524 switch (screenMode) {
525 case SM_BACKDROP:
526 default:
527 vita2d_draw_texture_tint(backdrop, 0, 0, tint);
528 // Fall through
529 case SM_PLAIN:
530 if (sgbCrop && width == 256 && height == 224) {
531 w = 768;
532 h = 672;
533 scalex = 3;
534 scaley = 3;
535 break;
536 }
537 w = 960 / width;
538 h = 544 / height;
539 if (w * height > 544) {
540 scalex = h;
541 w = width * h;
542 h = height * h;
543 } else {
544 scalex = w;
545 w = width * w;
546 h = height * w;
547 }
548 scaley = scalex;
549 break;
550 case SM_ASPECT:
551 if (sgbCrop && width == 256 && height == 224) {
552 w = 967;
553 h = 846;
554 scalex = 34.0f / 9.0f;
555 scaley = scalex;
556 break;
557 }
558 w = 960 / aspectw;
559 h = 544 / aspecth;
560 if (w * aspecth > 544) {
561 w = aspectw * h;
562 h = aspecth * h;
563 } else {
564 w = aspectw * w;
565 h = aspecth * w;
566 }
567 scalex = w / (float) width;
568 scaley = scalex;
569 break;
570 case SM_FULL:
571 w = 960;
572 h = 544;
573 scalex = 960.0f / width;
574 scaley = 544.0f / height;
575 break;
576 }
577 vita2d_draw_texture_tint_part_scale(t,
578 (960.0f - w) / 2.0f, (544.0f - h) / 2.0f,
579 0, 0, width, height,
580 scalex, scaley,
581 tint);
582}
583
584void mPSP2Swap(struct mGUIRunner* runner) {
585 bool frameAvailable = true;
586 switch (runner->core->platform(runner->core)) {
587#ifdef M_CORE_GBA
588 case PLATFORM_GBA:
589 frameAvailable = ((struct GBA*) runner->core->board)->video.frameskipCounter <= 0;
590 break;
591#endif
592#ifdef M_CORE_GB
593 case PLATFORM_GB:
594 frameAvailable = ((struct GB*) runner->core->board)->video.frameskipCounter <= 0;
595 break;
596#endif
597 default:
598 break;
599 }
600 if (frameAvailable) {
601 currentTex = !currentTex;
602 runner->core->setVideoBuffer(runner->core, vita2d_texture_get_datap(tex[currentTex]), 256);
603 }
604}
605
606void mPSP2Draw(struct mGUIRunner* runner, bool faded) {
607 unsigned width, height;
608 runner->core->desiredVideoDimensions(runner->core, &width, &height);
609 if (interframeBlending) {
610 _drawTex(tex[!currentTex], width, height, faded, false);
611 }
612 _drawTex(tex[currentTex], width, height, faded, interframeBlending);
613}
614
615void mPSP2DrawScreenshot(struct mGUIRunner* runner, const uint32_t* pixels, unsigned width, unsigned height, bool faded) {
616 UNUSED(runner);
617 uint32_t* texpixels = vita2d_texture_get_datap(screenshot);
618 unsigned y;
619 for (y = 0; y < height; ++y) {
620 memcpy(&texpixels[256 * y], &pixels[width * y], width * 4);
621 }
622 _drawTex(screenshot, width, height, faded, false);
623}
624
625void mPSP2IncrementScreenMode(struct mGUIRunner* runner) {
626 screenMode = (screenMode + 1) % SM_MAX;
627 mCoreConfigSetUIntValue(&runner->config, "screenMode", screenMode);
628}
629
630bool mPSP2SystemPoll(struct mGUIRunner* runner) {
631 SceAppMgrSystemEvent event;
632 if (sceAppMgrReceiveSystemEvent(&event) < 0) {
633 return true;
634 }
635 if (event.systemEvent == SCE_APPMGR_SYSTEMEVENT_ON_RESUME) {
636 mLOG(GUI_PSP2, INFO, "Suspend detected, reloading save");
637 mCoreAutoloadSave(runner->core);
638 }
639 return true;
640}
641
642__attribute__((noreturn, weak)) void __assert_func(const char* file, int line, const char* func, const char* expr) {
643 printf("ASSERT FAILED: %s in %s at %s:%i\n", expr, func, file, line);
644 exit(1);
645}