all repos — mgba @ ade940257846eeed35116398849499acc0e1043f

mGBA Game Boy Advance Emulator

src/platform/psp2/main.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 "util/gui.h"
 9#include "util/gui/font.h"
10#include "util/gui/file-select.h"
11
12#include <psp2/ctrl.h>
13#include <psp2/kernel/processmgr.h>
14#include <psp2/moduleinfo.h>
15
16#include <vita2d.h>
17
18PSP2_MODULE_INFO(0, 0, "mGBA");
19
20static void _drawStart(void) {
21	vita2d_start_drawing();
22	vita2d_clear_screen();
23}
24
25static void _drawEnd(void) {
26	vita2d_end_drawing();
27	vita2d_swap_buffers();
28}
29
30static int _pollInput(void) {
31	SceCtrlData pad;
32	sceCtrlPeekBufferPositive(0, &pad, 1);
33	int input = 0;
34	if (pad.buttons & PSP2_CTRL_TRIANGLE) {
35		input |= 1 << GUI_INPUT_CANCEL;
36	}
37	if (pad.buttons & PSP2_CTRL_CIRCLE) {
38		input |= 1 << GUI_INPUT_BACK;
39	}
40	if (pad.buttons & PSP2_CTRL_CROSS) {
41		input |= 1 << GUI_INPUT_SELECT;
42	}
43
44	if (pad.buttons & PSP2_CTRL_UP) {
45		input |= 1 << GUI_INPUT_UP;
46	}
47	if (pad.buttons & PSP2_CTRL_DOWN) {
48		input |= 1 << GUI_INPUT_DOWN;
49	}
50	if (pad.buttons & PSP2_CTRL_LEFT) {
51		input |= 1 << GUI_INPUT_LEFT;
52	}
53	if (pad.buttons & PSP2_CTRL_RIGHT) {
54		input |= 1 << GUI_INPUT_RIGHT;
55	}
56	return input;
57}
58
59int main() {
60	printf("%s initializing", projectName);
61
62	vita2d_init();
63	struct GUIFont* font = GUIFontCreate();
64	GBAPSP2Setup();
65	struct GUIParams params = {
66		PSP2_HORIZONTAL_PIXELS, PSP2_VERTICAL_PIXELS,
67		font, _drawStart, _drawEnd, _pollInput
68	};
69
70	while (true) {
71		char path[256];
72		if (!selectFile(&params, "cache0:", path, sizeof(path), "gba")) {
73			break;
74		}
75		GBAPSP2LoadROM(path);
76		GBAPSP2Runloop();
77		GBAPSP2UnloadROM();
78	}
79
80	GBAPSP2Teardown();
81
82	GUIFontDestroy(font);
83	vita2d_fini();
84
85	sceKernelExitProcess(0);
86	return 0;
87}