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 || pad.ly < 64) {
48 input |= 1 << GUI_INPUT_UP;
49 }
50 if (pad.buttons & PSP2_CTRL_DOWN || pad.ly >= 192) {
51 input |= 1 << GUI_INPUT_DOWN;
52 }
53 if (pad.buttons & PSP2_CTRL_LEFT || pad.lx < 64) {
54 input |= 1 << GUI_INPUT_LEFT;
55 }
56 if (pad.buttons & PSP2_CTRL_RIGHT || pad.lx >= 192) {
57 input |= 1 << GUI_INPUT_RIGHT;
58 }
59
60 return input;
61}
62
63int main() {
64 printf("%s initializing", projectName);
65
66 vita2d_init();
67 struct GUIFont* font = GUIFontCreate();
68 struct GBAGUIRunner runner = {
69 .params = {
70 PSP2_HORIZONTAL_PIXELS, PSP2_VERTICAL_PIXELS,
71 font, "cache0:", _drawStart, _drawEnd, _pollInput, 0, 0,
72
73 GUI_PARAMS_TRAIL
74 },
75 .setup = GBAPSP2Setup,
76 .teardown = GBAPSP2Teardown,
77 .gameLoaded = GBAPSP2LoadROM,
78 .gameUnloaded = GBAPSP2UnloadROM,
79 .prepareForFrame = GBAPSP2PrepareForFrame,
80 .drawFrame = GBAPSP2Draw,
81 .pollGameInput = GBAPSP2PollInput
82 };
83
84 GBAGUIInit(&runner, 0);
85 GBAGUIRunloop(&runner);
86 GBAGUIDeinit(&runner);
87
88 GUIFontDestroy(font);
89 vita2d_fini();
90
91 sceKernelExitProcess(0);
92 return 0;
93}