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