all repos — mgba @ 74e3826b13c76a1cc4e8088a65968bd177050760

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