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