all repos — mgba @ fafcfebf2efa65db88d5fadc80d0a19ef06f8111

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