all repos — mgba @ 18403682f7824b7fa76fac4ada63386c5e0e34dc

mGBA Game Boy Advance Emulator

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	memset(vita2d_texture_get_datap(tex[0]), 0xFF, 256 * toPow2(height) * 4);
332	memset(vita2d_texture_get_datap(tex[1]), 0xFF, 256 * toPow2(height) * 4);
333
334	runner->core->setVideoBuffer(runner->core, vita2d_texture_get_datap(tex[currentTex]), 256);
335	runner->core->setAudioBufferSize(runner->core, PSP2_SAMPLES);
336
337	rotation.d.sample = _sampleRotation;
338	rotation.d.readTiltX = _readTiltX;
339	rotation.d.readTiltY = _readTiltY;
340	rotation.d.readGyroZ = _readGyroZ;
341	runner->core->setPeripheral(runner->core, mPERIPH_ROTATION, &rotation.d);
342
343	rumble.d.setRumble = _setRumble;
344	CircleBufferInit(&rumble.history, RUMBLE_PWM);
345	runner->core->setPeripheral(runner->core, mPERIPH_RUMBLE, &rumble.d);
346
347	camera.d.startRequestImage = _startRequestImage;
348	camera.d.stopRequestImage = _stopRequestImage;
349	camera.d.requestImage = _requestImage;
350	camera.buffer = NULL;
351	camera.cam = 1;
352	runner->core->setPeripheral(runner->core, mPERIPH_IMAGE_SOURCE, &camera.d);
353
354
355	stream.videoDimensionsChanged = NULL;
356	stream.postAudioFrame = NULL;
357	stream.postAudioBuffer = _postAudioBuffer;
358	stream.postVideoFrame = NULL;
359	runner->core->setAVStream(runner->core, &stream);
360
361	frameLimiter = true;
362	backdrop = vita2d_load_PNG_buffer(_binary_backdrop_png_start);
363
364	unsigned mode;
365	if (mCoreConfigGetUIntValue(&runner->config, "screenMode", &mode) && mode < SM_MAX) {
366		screenMode = mode;
367	}
368	if (mCoreConfigGetUIntValue(&runner->config, "camera", &mode)) {
369		camera.cam = mode;
370	}
371	int fakeBool;
372	if (mCoreConfigGetIntValue(&runner->config, "sgb.borderCrop", &fakeBool)) {
373		sgbCrop = fakeBool;
374	}
375}
376
377void mPSP2LoadROM(struct mGUIRunner* runner) {
378	float rate = 60.0f / 1.001f;
379	sceDisplayGetRefreshRate(&rate);
380	double ratio = GBAAudioCalculateRatio(1, rate, 1);
381	blip_set_rates(runner->core->getAudioChannel(runner->core, 0), runner->core->frequency(runner->core), 48000 * ratio);
382	blip_set_rates(runner->core->getAudioChannel(runner->core, 1), runner->core->frequency(runner->core), 48000 * ratio);
383
384	switch (runner->core->platform(runner->core)) {
385#ifdef M_CORE_GBA
386	case PLATFORM_GBA:
387		if (((struct GBA*) runner->core->board)->memory.hw.devices & (HW_TILT | HW_GYRO)) {
388			sceMotionStartSampling();
389		}
390		break;
391#endif
392#ifdef M_CORE_GB
393	case PLATFORM_GB:
394		if (((struct GB*) runner->core->board)->memory.mbcType == GB_MBC7) {
395			sceMotionStartSampling();
396		}
397		break;
398#endif
399	default:
400		break;
401	}
402
403	int fakeBool;
404	if (mCoreConfigGetIntValue(&runner->config, "interframeBlending", &fakeBool)) {
405		interframeBlending = fakeBool;
406	}
407
408	// Backcompat: Old versions of mGBA use an older binding system that has different mappings for L/R
409	if (!sceKernelIsPSVitaTV()) {
410		int key = mInputMapKey(&runner->core->inputMap, PSP2_INPUT, __builtin_ctz(SCE_CTRL_L2));
411		if (key >= 0) {
412			mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_L1, key);
413		}
414		key = mInputMapKey(&runner->core->inputMap, PSP2_INPUT, __builtin_ctz(SCE_CTRL_R2));
415		if (key >= 0) {
416			mPSP2MapKey(&runner->core->inputMap, SCE_CTRL_R1, key);
417		}
418	}
419
420	MutexInit(&audioContext.mutex);
421	ConditionInit(&audioContext.cond);
422	memset(audioContext.buffer, 0, sizeof(audioContext.buffer));
423	audioContext.readOffset = 0;
424	audioContext.writeOffset = 0;
425	audioContext.running = true;
426	ThreadCreate(&audioThread, _audioThread, &audioContext);
427}
428
429
430void mPSP2UnloadROM(struct mGUIRunner* runner) {
431	switch (runner->core->platform(runner->core)) {
432#ifdef M_CORE_GBA
433	case PLATFORM_GBA:
434		if (((struct GBA*) runner->core->board)->memory.hw.devices & (HW_TILT | HW_GYRO)) {
435			sceMotionStopSampling();
436		}
437		break;
438#endif
439#ifdef M_CORE_GB
440	case PLATFORM_GB:
441		if (((struct GB*) runner->core->board)->memory.mbcType == GB_MBC7) {
442			sceMotionStopSampling();
443		}
444		break;
445#endif
446	default:
447		break;
448	}
449	audioContext.running = false;
450	ThreadJoin(&audioThread);
451}
452
453void mPSP2Paused(struct mGUIRunner* runner) {
454	UNUSED(runner);
455	struct SceCtrlActuator state = {
456		0,
457		0
458	};
459	sceCtrlSetActuator(1, &state);
460	frameLimiter = true;
461}
462
463void mPSP2Unpaused(struct mGUIRunner* runner) {
464	unsigned mode;
465	if (mCoreConfigGetUIntValue(&runner->config, "screenMode", &mode) && mode != screenMode) {
466		screenMode = mode;
467	}
468
469	if (mCoreConfigGetUIntValue(&runner->config, "camera", &mode)) {
470		if (mode != camera.cam) {
471			if (camera.buffer) {
472				sceCameraStop(camera.cam - 1);
473				sceCameraClose(camera.cam - 1);
474			}
475			camera.cam = mode;
476			if (camera.buffer) {
477				_resetCamera(&camera);
478			}
479		}
480	}
481
482	int fakeBool;
483	if (mCoreConfigGetIntValue(&runner->config, "interframeBlending", &fakeBool)) {
484		interframeBlending = fakeBool;
485	}
486
487	if (mCoreConfigGetIntValue(&runner->config, "sgb.borderCrop", &fakeBool)) {
488		sgbCrop = fakeBool;
489	}
490}
491
492void mPSP2Teardown(struct mGUIRunner* runner) {
493	UNUSED(runner);
494	CircleBufferDeinit(&rumble.history);
495	vita2d_free_texture(tex[0]);
496	vita2d_free_texture(tex[1]);
497	vita2d_free_texture(screenshot);
498	frameLimiter = true;
499}
500
501void _drawTex(vita2d_texture* t, unsigned width, unsigned height, bool faded, bool interframe) {
502	unsigned w = width;
503	unsigned h = height;
504	// Get greatest common divisor
505	while (w != 0) {
506		int temp = h % w;
507		h = w;
508		w = temp;
509	}
510	int gcd = h;
511	int aspectw = width / gcd;
512	int aspecth = height / gcd;
513	float scalex;
514	float scaley;
515
516	unsigned tint = 0x1FFFFFFF;
517	if (!faded) {
518		if (interframe) {
519			tint |= 0x60000000;
520		} else {
521			tint |= 0xE0000000;
522		}
523	} else if (!interframe) {
524		tint |= 0x20000000;
525	}
526
527	switch (screenMode) {
528	case SM_BACKDROP:
529	default:
530		vita2d_draw_texture_tint(backdrop, 0, 0, tint);
531		// Fall through
532	case SM_PLAIN:
533		if (sgbCrop && width == 256 && height == 224) {
534			w = 768;
535			h = 672;
536			scalex = 3;
537			scaley = 3;
538			break;
539		}
540		w = 960 / width;
541		h = 544 / height;
542		if (w * height > 544) {
543			scalex = h;
544			w = width * h;
545			h = height * h;
546		} else {
547			scalex = w;
548			w = width * w;
549			h = height * w;
550		}
551		scaley = scalex;
552		break;
553	case SM_ASPECT:
554		if (sgbCrop && width == 256 && height == 224) {
555			w = 967;
556			h = 846;
557			scalex = 34.0f / 9.0f;
558			scaley = scalex;
559			break;
560		}
561		w = 960 / aspectw;
562		h = 544 / aspecth;
563		if (w * aspecth > 544) {
564			w = aspectw * h;
565			h = aspecth * h;
566		} else {
567			w = aspectw * w;
568			h = aspecth * w;
569		}
570		scalex = w / (float) width;
571		scaley = scalex;
572		break;
573	case SM_FULL:
574		w = 960;
575		h = 544;
576		scalex = 960.0f / width;
577		scaley = 544.0f / height;
578		break;
579	}
580	vita2d_draw_texture_tint_part_scale(t,
581	                                    (960.0f - w) / 2.0f, (544.0f - h) / 2.0f,
582	                                    0, 0, width, height,
583	                                    scalex, scaley,
584	                                    tint);
585}
586
587void mPSP2Swap(struct mGUIRunner* runner) {
588	bool frameAvailable = true;
589	switch (runner->core->platform(runner->core)) {
590#ifdef M_CORE_GBA
591	case PLATFORM_GBA:
592		frameAvailable = ((struct GBA*) runner->core->board)->video.frameskipCounter <= 0;
593		break;
594#endif
595#ifdef M_CORE_GB
596	case PLATFORM_GB:
597		frameAvailable = ((struct GB*) runner->core->board)->video.frameskipCounter <= 0;
598		break;
599#endif
600	default:
601		break;
602	}
603	if (frameAvailable) {
604		currentTex = !currentTex;
605		runner->core->setVideoBuffer(runner->core, vita2d_texture_get_datap(tex[currentTex]), 256);
606	}
607}
608
609void mPSP2Draw(struct mGUIRunner* runner, bool faded) {
610	unsigned width, height;
611	runner->core->desiredVideoDimensions(runner->core, &width, &height);
612	if (interframeBlending) {
613		_drawTex(tex[!currentTex], width, height, faded, false);
614	}
615	_drawTex(tex[currentTex], width, height, faded, interframeBlending);
616}
617
618void mPSP2DrawScreenshot(struct mGUIRunner* runner, const uint32_t* pixels, unsigned width, unsigned height, bool faded) {
619	UNUSED(runner);
620	uint32_t* texpixels = vita2d_texture_get_datap(screenshot);
621	unsigned y;
622	for (y = 0; y < height; ++y) {
623		memcpy(&texpixels[256 * y], &pixels[width * y], width * 4);
624	}
625	_drawTex(screenshot, width, height, faded, false);
626}
627
628void mPSP2IncrementScreenMode(struct mGUIRunner* runner) {
629	screenMode = (screenMode + 1) % SM_MAX;
630	mCoreConfigSetUIntValue(&runner->config, "screenMode", screenMode);
631}
632
633bool mPSP2SystemPoll(struct mGUIRunner* runner) {
634	SceAppMgrSystemEvent event;
635	if (sceAppMgrReceiveSystemEvent(&event) < 0) {
636		return true;
637	}
638	if (event.systemEvent == SCE_APPMGR_SYSTEMEVENT_ON_RESUME) {
639		mLOG(GUI_PSP2, INFO, "Suspend detected, reloading save");
640		mCoreAutoloadSave(runner->core);
641	}
642	return true;
643}
644
645__attribute__((noreturn, weak)) void __assert_func(const char* file, int line, const char* func, const char* expr) {
646	printf("ASSERT FAILED: %s in %s at %s:%i\n", expr, func, file, line);
647	exit(1);
648}