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#include <psp2/touch.h>
19
20#include <vita2d.h>
21
22PSP2_MODULE_INFO(0, 0, "mGBA");
23
24static void _drawStart(void) {
25 vita2d_start_drawing();
26 vita2d_clear_screen();
27}
28
29static void _drawEnd(void) {
30 vita2d_end_drawing();
31 vita2d_swap_buffers();
32}
33
34static uint32_t _pollInput(void) {
35 SceCtrlData pad;
36 sceCtrlPeekBufferPositive(0, &pad, 1);
37 int input = 0;
38 if (pad.buttons & PSP2_CTRL_TRIANGLE) {
39 input |= 1 << GUI_INPUT_CANCEL;
40 }
41 if (pad.buttons & PSP2_CTRL_SQUARE) {
42 input |= 1 << GBA_GUI_INPUT_SCREEN_MODE;
43 }
44 if (pad.buttons & PSP2_CTRL_CIRCLE) {
45 input |= 1 << GUI_INPUT_BACK;
46 }
47 if (pad.buttons & PSP2_CTRL_CROSS) {
48 input |= 1 << GUI_INPUT_SELECT;
49 }
50
51 if (pad.buttons & PSP2_CTRL_UP || pad.ly < 64) {
52 input |= 1 << GUI_INPUT_UP;
53 }
54 if (pad.buttons & PSP2_CTRL_DOWN || pad.ly >= 192) {
55 input |= 1 << GUI_INPUT_DOWN;
56 }
57 if (pad.buttons & PSP2_CTRL_LEFT || pad.lx < 64) {
58 input |= 1 << GUI_INPUT_LEFT;
59 }
60 if (pad.buttons & PSP2_CTRL_RIGHT || pad.lx >= 192) {
61 input |= 1 << GUI_INPUT_RIGHT;
62 }
63
64 return input;
65}
66
67static enum GUICursorState _pollCursor(int* x, int* y) {
68 SceTouchData touch;
69 sceTouchPeek(0, &touch, 1);
70 if (touch.reportNum < 1) {
71 return GUI_CURSOR_NOT_PRESENT;
72 }
73 *x = touch.report[0].x / 2;
74 *y = touch.report[0].y / 2;
75 return GUI_CURSOR_DOWN;
76}
77
78
79int main() {
80 vita2d_init();
81 struct GUIFont* font = GUIFontCreate();
82 struct GBAGUIRunner runner = {
83 .params = {
84 PSP2_HORIZONTAL_PIXELS, PSP2_VERTICAL_PIXELS,
85 font, "cache0:", _drawStart, _drawEnd,
86 _pollInput, _pollCursor,
87 0, 0,
88
89 GUI_PARAMS_TRAIL
90 },
91 .setup = GBAPSP2Setup,
92 .teardown = GBAPSP2Teardown,
93 .gameLoaded = GBAPSP2LoadROM,
94 .gameUnloaded = GBAPSP2UnloadROM,
95 .prepareForFrame = GBAPSP2PrepareForFrame,
96 .drawFrame = GBAPSP2Draw,
97 .paused = 0,
98 .unpaused = 0,
99 .incrementScreenMode = GBAPSP2IncrementScreenMode,
100 .pollGameInput = GBAPSP2PollInput
101 };
102
103 GBAGUIInit(&runner, 0);
104 GBAGUIRunloop(&runner);
105 GBAGUIDeinit(&runner);
106
107 GUIFontDestroy(font);
108 vita2d_fini();
109
110 sceKernelExitProcess(0);
111 return 0;
112}