Core, GUI, Platform: Disuse GBAContext

This commit is contained in:
Jeffrey Pfau 2016-02-07 13:47:12 -08:00
parent 0d088f6e99
commit 7a1f8ec86f
11 changed files with 287 additions and 281 deletions

View File

@ -5,6 +5,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gui-config.h"
#include "core/config.h"
#include "core/core.h"
#include "gba/gba.h"
#include "gba/gui/gui-runner.h"
#include "gba/gui/remap.h"
#include "util/gui/file-select.h"
@ -14,7 +17,7 @@
#define GUI_MAX_INPUTS 7
#endif
void GBAGUIShowConfig(struct GBAGUIRunner* runner, struct GUIMenuItem* extra, size_t nExtra) {
void mGUIShowConfig(struct mGUIRunner* runner, struct GUIMenuItem* extra, size_t nExtra) {
struct GUIMenu menu = {
.title = "Configure",
.index = 0,
@ -93,7 +96,7 @@ void GBAGUIShowConfig(struct GBAGUIRunner* runner, struct GUIMenuItem* extra, si
if (!item->validStates || !item->data) {
continue;
}
mCoreConfigGetUIntValue(&runner->context.config, item->data, &item->state);
mCoreConfigGetUIntValue(&runner->core->config, item->data, &item->state);
}
while (true) {
@ -103,20 +106,20 @@ void GBAGUIShowConfig(struct GBAGUIRunner* runner, struct GUIMenuItem* extra, si
}
if (!strcmp(item->data, "*SAVE")) {
if (biosPath[0]) {
mCoreConfigSetValue(&runner->context.config, "bios", biosPath);
mCoreConfigSetValue(&runner->core->config, "bios", biosPath);
}
for (i = 0; i < GUIMenuItemListSize(&menu.items); ++i) {
item = GUIMenuItemListGetPointer(&menu.items, i);
if (!item->validStates || !item->data) {
continue;
}
mCoreConfigSetUIntValue(&runner->context.config, item->data, item->state);
mCoreConfigSetUIntValue(&runner->core->config, item->data, item->state);
}
mCoreConfigSave(&runner->context.config);
mCoreConfigSave(&runner->core->config);
break;
}
if (!strcmp(item->data, "*REMAP")) {
GBAGUIRemapKeys(&runner->params, &runner->context.inputMap, &runner->keySources[item->state]);
mGUIRemapKeys(&runner->params, &runner->core->inputMap, &runner->keySources[item->state]);
continue;
}
if (!strcmp(item->data, "bios")) {

View File

@ -8,8 +8,8 @@
#include "util/common.h"
struct GBAGUIRunner;
struct mGUIRunner;
struct GUIMenuItem;
void GBAGUIShowConfig(struct GBAGUIRunner* runner, struct GUIMenuItem* extra, size_t nExtra);
void mGUIShowConfig(struct mGUIRunner* runner, struct GUIMenuItem* extra, size_t nExtra);
#endif

View File

@ -5,7 +5,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gui-runner.h"
#include "gba/core.h"
#include "gba/gui/gui-config.h"
#include "gba/input.h"
#include "gba/interface.h"
#include "gba/serialize.h"
#include "util/gui/file-select.h"
@ -47,21 +49,21 @@ enum {
static void _drawBackground(struct GUIBackground* background, void* context) {
UNUSED(context);
struct GBAGUIBackground* gbaBackground = (struct GBAGUIBackground*) background;
struct mGUIBackground* gbaBackground = (struct mGUIBackground*) background;
if (gbaBackground->p->drawFrame) {
gbaBackground->p->drawFrame(gbaBackground->p, true);
}
}
static void _drawState(struct GUIBackground* background, void* id) {
struct GBAGUIBackground* gbaBackground = (struct GBAGUIBackground*) background;
struct mGUIBackground* gbaBackground = (struct mGUIBackground*) background;
int stateId = ((int) id) >> 16;
if (gbaBackground->p->drawScreenshot) {
if (gbaBackground->screenshot && gbaBackground->screenshotId == (int) id) {
gbaBackground->p->drawScreenshot(gbaBackground->p, gbaBackground->screenshot, true);
return;
}
struct VFile* vf = GBAGetState(gbaBackground->p->context.gba, gbaBackground->p->context.dirs.state, stateId, false);
struct VFile* vf = GBAGetState(gbaBackground->p->core->board, gbaBackground->p->core->dirs.state, stateId, false);
uint32_t* pixels = gbaBackground->screenshot;
if (!pixels) {
pixels = anonymousMemoryMap(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4);
@ -96,7 +98,7 @@ static void _updateLux(struct GBALuminanceSource* lux) {
}
static uint8_t _readLux(struct GBALuminanceSource* lux) {
struct GBAGUIRunnerLux* runnerLux = (struct GBAGUIRunnerLux*) lux;
struct mGUIRunnerLux* runnerLux = (struct mGUIRunnerLux*) lux;
int value = 0x16;
if (runnerLux->luxLevel > 0) {
value += GBA_LUX_LEVELS[runnerLux->luxLevel - 1];
@ -104,13 +106,16 @@ static uint8_t _readLux(struct GBALuminanceSource* lux) {
return 0xFF - value;
}
void GBAGUIInit(struct GBAGUIRunner* runner, const char* port) {
void mGUIInit(struct mGUIRunner* runner, const char* port) {
GUIInit(&runner->params);
GBAContextInit(&runner->context, port);
runner->core = GBACoreCreate();
runner->core->init(runner->core);
mInputMapInit(&runner->core->inputMap, &GBAInputInfo);
mCoreInitConfig(runner->core, port);
runner->luminanceSource.d.readLuminance = _readLux;
runner->luminanceSource.d.sample = _updateLux;
runner->luminanceSource.luxLevel = 0;
runner->context.gba->luminanceSource = &runner->luminanceSource.d;
((struct GBA*) runner->core->board)->luminanceSource = &runner->luminanceSource.d;
runner->background.d.draw = _drawBackground;
runner->background.p = runner;
runner->fps = 0;
@ -121,33 +126,33 @@ void GBAGUIInit(struct GBAGUIRunner* runner, const char* port) {
runner->setup(runner);
}
if (runner->context.config.port && runner->keySources) {
if (runner->core->config.port && runner->keySources) {
size_t i;
for (i = 0; runner->keySources[i].id; ++i) {
mInputMapLoad(&runner->context.inputMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->context.config));
mInputMapLoad(&runner->core->inputMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->core->config));
}
}
}
void GBAGUIDeinit(struct GBAGUIRunner* runner) {
void mGUIDeinit(struct mGUIRunner* runner) {
if (runner->teardown) {
runner->teardown(runner);
}
if (runner->context.config.port) {
if (runner->core->config.port) {
if (runner->keySources) {
size_t i;
for (i = 0; runner->keySources[i].id; ++i) {
mInputMapSave(&runner->context.inputMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->context.config));
mInputMapSave(&runner->core->inputMap, runner->keySources[i].id, mCoreConfigGetInput(&runner->core->config));
}
}
mCoreConfigSave(&runner->context.config);
mCoreConfigSave(&runner->core->config);
}
CircleBufferDeinit(&runner->fpsBuffer);
GBAContextDeinit(&runner->context);
runner->core->deinit(runner->core);
}
void GBAGUIRun(struct GBAGUIRunner* runner, const char* path) {
struct GBAGUIBackground drawState = {
void mGUIRun(struct mGUIRunner* runner, const char* path) {
struct mGUIBackground drawState = {
.d = {
.draw = _drawState
},
@ -213,9 +218,9 @@ void GBAGUIRun(struct GBAGUIRunner* runner, const char* path) {
}
runner->params.drawEnd();
if (!GBAContextLoadROM(&runner->context, path, true)) {
if (!mCoreLoadFile(runner->core, path)) {
int i;
for (i = 0; i < 300; ++i) {
for (i = 0; i < 240; ++i) {
runner->params.drawStart();
if (runner->params.guiPrepare) {
runner->params.guiPrepare();
@ -228,7 +233,9 @@ void GBAGUIRun(struct GBAGUIRunner* runner, const char* path) {
}
return;
}
bool running = GBAContextStart(&runner->context);
mCoreAutoloadSave(runner->core);
runner->core->reset(runner->core);
bool running = true;
if (runner->gameLoaded) {
runner->gameLoaded(runner);
}
@ -252,27 +259,28 @@ void GBAGUIRun(struct GBAGUIRunner* runner, const char* path) {
if (guiKeys & (1 << GUI_INPUT_CANCEL)) {
break;
}
if (guiKeys & (1 << GBA_GUI_INPUT_INCREASE_BRIGHTNESS)) {
if (guiKeys & (1 << mGUI_INPUT_INCREASE_BRIGHTNESS)) {
if (runner->luminanceSource.luxLevel < 10) {
++runner->luminanceSource.luxLevel;
}
}
if (guiKeys & (1 << GBA_GUI_INPUT_DECREASE_BRIGHTNESS)) {
if (guiKeys & (1 << mGUI_INPUT_DECREASE_BRIGHTNESS)) {
if (runner->luminanceSource.luxLevel > 0) {
--runner->luminanceSource.luxLevel;
}
}
if (guiKeys & (1 << GBA_GUI_INPUT_SCREEN_MODE) && runner->incrementScreenMode) {
if (guiKeys & (1 << mGUI_INPUT_SCREEN_MODE) && runner->incrementScreenMode) {
runner->incrementScreenMode(runner);
}
uint16_t keys = runner->pollGameInput(runner);
if (runner->prepareForFrame) {
runner->prepareForFrame(runner);
}
GBAContextFrame(&runner->context, keys);
runner->core->setKeys(runner->core, keys);
runner->core->runFrame(runner->core);
if (runner->drawFrame) {
int drawFps = false;
mCoreConfigGetIntValue(&runner->context.config, "fpsCounter", &drawFps);
mCoreConfigGetIntValue(&runner->core->config, "fpsCounter", &drawFps);
runner->params.drawStart();
runner->drawFrame(runner, false);
@ -287,7 +295,7 @@ void GBAGUIRun(struct GBAGUIRunner* runner, const char* path) {
}
runner->params.drawEnd();
if (runner->context.gba->video.frameCounter % FPS_GRANULARITY == 0) {
if (runner->core->frameCounter(runner->core) % FPS_GRANULARITY == 0) {
if (drawFps) {
struct timeval tv;
gettimeofday(&tv, 0);
@ -319,35 +327,26 @@ void GBAGUIRun(struct GBAGUIRunner* runner, const char* path) {
struct GUIMenuItem* item;
enum GUIMenuExitReason reason = GUIShowMenu(&runner->params, &pauseMenu, &item);
if (reason == GUI_MENU_EXIT_ACCEPT) {
struct VFile* vf;
switch (((int) item->data) & RUNNER_COMMAND_MASK) {
case RUNNER_EXIT:
running = false;
keys = 0;
break;
case RUNNER_RESET:
GBAContextReset(&runner->context);
runner->core->reset(runner->core);
break;
case RUNNER_SAVE_STATE:
vf = GBAGetState(runner->context.gba, runner->context.dirs.state, ((int) item->data) >> 16, true);
if (vf) {
GBASaveStateNamed(runner->context.gba, vf, SAVESTATE_SCREENSHOT);
vf->close(vf);
}
mCoreSaveState(runner->core, ((int) item->data) >> 16, SAVESTATE_SCREENSHOT);
break;
case RUNNER_LOAD_STATE:
vf = GBAGetState(runner->context.gba, runner->context.dirs.state, ((int) item->data) >> 16, false);
if (vf) {
GBALoadStateNamed(runner->context.gba, vf, SAVESTATE_SCREENSHOT);
vf->close(vf);
}
mCoreLoadState(runner->core, ((int) item->data) >> 16, SAVESTATE_SCREENSHOT);
break;
case RUNNER_SCREENSHOT:
GBATakeScreenshot(runner->context.gba, runner->context.dirs.screenshot);
// TODO: Put back screenshots
break;
case RUNNER_CONFIG:
GBAGUIShowConfig(runner, runner->configExtra, runner->nConfigExtra);
mCoreConfigGetIntValue(&runner->context.config, "frameskip", &runner->context.gba->video.frameskip);
mGUIShowConfig(runner, runner->configExtra, runner->nConfigExtra);
mCoreConfigGetIntValue(&runner->core->config, "frameskip", &((struct GBA*) runner->core->board)->video.frameskip);
break;
case RUNNER_CONTINUE:
break;
@ -366,11 +365,10 @@ void GBAGUIRun(struct GBAGUIRunner* runner, const char* path) {
runner->unpaused(runner);
}
}
GBAContextStop(&runner->context);
if (runner->gameUnloaded) {
runner->gameUnloaded(runner);
}
GBAContextUnloadROM(&runner->context);
runner->core->unloadROM(runner->core);
drawState.screenshotId = 0;
if (drawState.screenshot) {
mappedMemoryFree(drawState.screenshot, VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4);
@ -380,12 +378,12 @@ void GBAGUIRun(struct GBAGUIRunner* runner, const char* path) {
GUIMenuItemListDeinit(&stateLoadMenu.items);
}
void GBAGUIRunloop(struct GBAGUIRunner* runner) {
void mGUIRunloop(struct mGUIRunner* runner) {
while (true) {
char path[PATH_MAX];
if (!GUISelectFile(&runner->params, path, sizeof(path), 0)) {
break;
}
GBAGUIRun(runner, path);
mGUIRun(runner, path);
}
}

View File

@ -6,36 +6,39 @@
#ifndef GUI_RUNNER_H
#define GUI_RUNNER_H
#include "gba/context/context.h"
#include "util/common.h"
#include "gba/gui/remap.h"
#include "gba/hardware.h"
#include "util/circle-buffer.h"
#include "util/gui.h"
enum GBAGUIInput {
GBA_GUI_INPUT_INCREASE_BRIGHTNESS = GUI_INPUT_USER_START,
GBA_GUI_INPUT_DECREASE_BRIGHTNESS,
GBA_GUI_INPUT_SCREEN_MODE,
enum mGUIInput {
mGUI_INPUT_INCREASE_BRIGHTNESS = GUI_INPUT_USER_START,
mGUI_INPUT_DECREASE_BRIGHTNESS,
mGUI_INPUT_SCREEN_MODE,
};
struct GBAGUIBackground {
struct mGUIBackground {
struct GUIBackground d;
struct GBAGUIRunner* p;
struct mGUIRunner* p;
uint32_t* screenshot;
int screenshotId;
};
struct GBAGUIRunnerLux {
struct mCore;
struct mGUIRunnerLux {
struct GBALuminanceSource d;
int luxLevel;
};
struct GBAGUIRunner {
struct GBAContext context;
struct mGUIRunner {
struct mCore* core;
struct GUIParams params;
struct GBAGUIBackground background;
struct GBAGUIRunnerLux luminanceSource;
struct mGUIBackground background;
struct mGUIRunnerLux luminanceSource;
struct GUIMenuItem* configExtra;
size_t nConfigExtra;
@ -47,22 +50,22 @@ struct GBAGUIRunner {
int32_t totalDelta;
struct CircleBuffer fpsBuffer;
void (*setup)(struct GBAGUIRunner*);
void (*teardown)(struct GBAGUIRunner*);
void (*gameLoaded)(struct GBAGUIRunner*);
void (*gameUnloaded)(struct GBAGUIRunner*);
void (*prepareForFrame)(struct GBAGUIRunner*);
void (*drawFrame)(struct GBAGUIRunner*, bool faded);
void (*drawScreenshot)(struct GBAGUIRunner*, const uint32_t* pixels, bool faded);
void (*paused)(struct GBAGUIRunner*);
void (*unpaused)(struct GBAGUIRunner*);
void (*incrementScreenMode)(struct GBAGUIRunner*);
uint16_t (*pollGameInput)(struct GBAGUIRunner*);
void (*setup)(struct mGUIRunner*);
void (*teardown)(struct mGUIRunner*);
void (*gameLoaded)(struct mGUIRunner*);
void (*gameUnloaded)(struct mGUIRunner*);
void (*prepareForFrame)(struct mGUIRunner*);
void (*drawFrame)(struct mGUIRunner*, bool faded);
void (*drawScreenshot)(struct mGUIRunner*, const uint32_t* pixels, bool faded);
void (*paused)(struct mGUIRunner*);
void (*unpaused)(struct mGUIRunner*);
void (*incrementScreenMode)(struct mGUIRunner*);
uint16_t (*pollGameInput)(struct mGUIRunner*);
};
void GBAGUIInit(struct GBAGUIRunner*, const char* port);
void GBAGUIDeinit(struct GBAGUIRunner*);
void GBAGUIRun(struct GBAGUIRunner*, const char* path);
void GBAGUIRunloop(struct GBAGUIRunner*);
void mGUIInit(struct mGUIRunner*, const char* port);
void mGUIDeinit(struct mGUIRunner*);
void mGUIRun(struct mGUIRunner*, const char* path);
void mGUIRunloop(struct mGUIRunner*);
#endif

View File

@ -9,7 +9,7 @@
#include "util/gui.h"
#include "util/gui/menu.h"
void GBAGUIRemapKeys(struct GUIParams* params, struct mInputMap* map, const struct GUIInputKeys* keys) {
void mGUIRemapKeys(struct GUIParams* params, struct mInputMap* map, const struct GUIInputKeys* keys) {
struct GUIMenu menu = {
.title = "Remap keys",
.index = 0,

View File

@ -18,6 +18,6 @@ struct GUIInputKeys {
struct GUIParams;
struct mInputMap;
void GBAGUIRemapKeys(struct GUIParams*, struct mInputMap*, const struct GUIInputKeys*);
void mGUIRemapKeys(struct GUIParams*, struct mInputMap*, const struct GUIInputKeys*);
#endif

View File

@ -4,9 +4,9 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gba/renderers/video-software.h"
#include "gba/context/context.h"
#include "gba/gba.h"
#include "gba/gui/gui-runner.h"
#include "gba/input.h"
#include "gba/video.h"
#include "util/gui.h"
#include "util/gui/file-select.h"
@ -51,7 +51,7 @@ static enum {
} hasSound;
// TODO: Move into context
static struct GBAVideoSoftwareRenderer renderer;
static void* outputBuffer;
static struct GBAAVStream stream;
static int16_t* audioLeft = 0;
static int16_t* audioRight = 0;
@ -81,8 +81,8 @@ enum {
extern bool allocateRomBuffer(void);
static void _cleanup(void) {
if (renderer.outputBuffer) {
linearFree(renderer.outputBuffer);
if (outputBuffer) {
linearFree(outputBuffer);
}
if (gbaOutputTexture.data) {
@ -248,48 +248,46 @@ static void _guiFinish(void) {
screenCleanup |= SCREEN_CLEANUP_BOTTOM;
}
static void _setup(struct GBAGUIRunner* runner) {
runner->context.gba->rotationSource = &rotation.d;
static void _setup(struct mGUIRunner* runner) {
((struct GBA*) runner->core->board)->rotationSource = &rotation.d;
if (hasSound != NO_SOUND) {
runner->context.gba->stream = &stream;
((struct GBA*) runner->core->board)->stream = &stream;
}
_map3DSKey(&runner->context.inputMap, KEY_A, GBA_KEY_A);
_map3DSKey(&runner->context.inputMap, KEY_B, GBA_KEY_B);
_map3DSKey(&runner->context.inputMap, KEY_START, GBA_KEY_START);
_map3DSKey(&runner->context.inputMap, KEY_SELECT, GBA_KEY_SELECT);
_map3DSKey(&runner->context.inputMap, KEY_UP, GBA_KEY_UP);
_map3DSKey(&runner->context.inputMap, KEY_DOWN, GBA_KEY_DOWN);
_map3DSKey(&runner->context.inputMap, KEY_LEFT, GBA_KEY_LEFT);
_map3DSKey(&runner->context.inputMap, KEY_RIGHT, GBA_KEY_RIGHT);
_map3DSKey(&runner->context.inputMap, KEY_L, GBA_KEY_L);
_map3DSKey(&runner->context.inputMap, KEY_R, GBA_KEY_R);
_map3DSKey(&runner->core->inputMap, KEY_A, GBA_KEY_A);
_map3DSKey(&runner->core->inputMap, KEY_B, GBA_KEY_B);
_map3DSKey(&runner->core->inputMap, KEY_START, GBA_KEY_START);
_map3DSKey(&runner->core->inputMap, KEY_SELECT, GBA_KEY_SELECT);
_map3DSKey(&runner->core->inputMap, KEY_UP, GBA_KEY_UP);
_map3DSKey(&runner->core->inputMap, KEY_DOWN, GBA_KEY_DOWN);
_map3DSKey(&runner->core->inputMap, KEY_LEFT, GBA_KEY_LEFT);
_map3DSKey(&runner->core->inputMap, KEY_RIGHT, GBA_KEY_RIGHT);
_map3DSKey(&runner->core->inputMap, KEY_L, GBA_KEY_L);
_map3DSKey(&runner->core->inputMap, KEY_R, GBA_KEY_R);
GBAVideoSoftwareRendererCreate(&renderer);
renderer.outputBuffer = linearMemAlign(256 * VIDEO_VERTICAL_PIXELS * 2, 0x80);
renderer.outputBufferStride = 256;
runner->context.renderer = &renderer.d;
outputBuffer = linearMemAlign(256 * VIDEO_VERTICAL_PIXELS * 2, 0x80);
runner->core->setVideoBuffer(runner->core, outputBuffer, 256);
unsigned mode;
if (mCoreConfigGetUIntValue(&runner->context.config, "screenMode", &mode) && mode < SM_MAX) {
if (mCoreConfigGetUIntValue(&runner->core->config, "screenMode", &mode) && mode < SM_MAX) {
screenMode = mode;
}
GBAAudioResizeBuffer(&runner->context.gba->audio, AUDIO_SAMPLES);
GBAAudioResizeBuffer(&((struct GBA*) runner->core->board)->audio, AUDIO_SAMPLES);
}
static void _gameLoaded(struct GBAGUIRunner* runner) {
if (runner->context.gba->memory.hw.devices & HW_TILT) {
static void _gameLoaded(struct mGUIRunner* runner) {
if (((struct GBA*) runner->core->board)->memory.hw.devices & HW_TILT) {
HIDUSER_EnableAccelerometer();
}
if (runner->context.gba->memory.hw.devices & HW_GYRO) {
if (((struct GBA*) runner->core->board)->memory.hw.devices & HW_GYRO) {
HIDUSER_EnableGyroscope();
}
osSetSpeedupEnable(true);
double ratio = GBAAudioCalculateRatio(1, 59.8260982880808, 1);
blip_set_rates(runner->context.gba->audio.psg.left, GBA_ARM7TDMI_FREQUENCY, 32768 * ratio);
blip_set_rates(runner->context.gba->audio.psg.right, GBA_ARM7TDMI_FREQUENCY, 32768 * ratio);
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), GBA_ARM7TDMI_FREQUENCY, 32768 * ratio);
blip_set_rates(runner->core->getAudioChannel(runner->core, 1), GBA_ARM7TDMI_FREQUENCY, 32768 * ratio);
if (hasSound != NO_SOUND) {
audioPos = 0;
}
@ -302,13 +300,13 @@ static void _gameLoaded(struct GBAGUIRunner* runner) {
memset(audioLeft, 0, AUDIO_SAMPLE_BUFFER * 2 * sizeof(int16_t));
}
unsigned mode;
if (mCoreConfigGetUIntValue(&runner->context.config, "screenMode", &mode) && mode != screenMode) {
if (mCoreConfigGetUIntValue(&runner->core->config, "screenMode", &mode) && mode != screenMode) {
screenMode = mode;
screenCleanup |= SCREEN_CLEANUP_BOTTOM | SCREEN_CLEANUP_TOP;
}
}
static void _gameUnloaded(struct GBAGUIRunner* runner) {
static void _gameUnloaded(struct mGUIRunner* runner) {
if (hasSound == CSND_SUPPORTED) {
CSND_SetPlayState(8, 0);
CSND_SetPlayState(9, 0);
@ -316,10 +314,10 @@ static void _gameUnloaded(struct GBAGUIRunner* runner) {
}
osSetSpeedupEnable(false);
if (runner->context.gba->memory.hw.devices & HW_TILT) {
if (((struct GBA*) runner->core->board)->memory.hw.devices & HW_TILT) {
HIDUSER_DisableAccelerometer();
}
if (runner->context.gba->memory.hw.devices & HW_GYRO) {
if (((struct GBA*) runner->core->board)->memory.hw.devices & HW_GYRO) {
HIDUSER_DisableGyroscope();
}
}
@ -361,10 +359,9 @@ static void _drawTex(bool faded) {
ctrAddRectScaled(color, x, y, w, h, 0, 0, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS);
}
static void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
static void _drawFrame(struct mGUIRunner* runner, bool faded) {
UNUSED(runner);
void* outputBuffer = renderer.outputBuffer;
struct ctrTexture* tex = &gbaOutputTexture;
GSPGPU_FlushDataCache(outputBuffer, 256 * VIDEO_VERTICAL_PIXELS * 2);
@ -376,8 +373,8 @@ static void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
GX_TRANSFER_OUT_TILED(1) | GX_TRANSFER_FLIP_VERT(1));
if (hasSound == NO_SOUND) {
blip_clear(runner->context.gba->audio.psg.left);
blip_clear(runner->context.gba->audio.psg.right);
blip_clear(runner->core->getAudioChannel(runner->core, 0));
blip_clear(runner->core->getAudioChannel(runner->core, 1));
}
gspWaitForPPF();
@ -385,7 +382,7 @@ static void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
_drawTex(faded);
}
static void _drawScreenshot(struct GBAGUIRunner* runner, const uint32_t* pixels, bool faded) {
static void _drawScreenshot(struct mGUIRunner* runner, const uint32_t* pixels, bool faded) {
UNUSED(runner);
struct ctrTexture* tex = &gbaOutputTexture;
@ -419,21 +416,21 @@ static void _drawScreenshot(struct GBAGUIRunner* runner, const uint32_t* pixels,
_drawTex(faded);
}
static uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
static uint16_t _pollGameInput(struct mGUIRunner* runner) {
UNUSED(runner);
hidScanInput();
uint32_t activeKeys = hidKeysHeld();
uint16_t keys = mInputMapKeyBits(&runner->context.inputMap, _3DS_INPUT, activeKeys, 0);
uint16_t keys = mInputMapKeyBits(&runner->core->inputMap, _3DS_INPUT, activeKeys, 0);
keys |= (activeKeys >> 24) & 0xF0;
return keys;
}
static void _incrementScreenMode(struct GBAGUIRunner* runner) {
static void _incrementScreenMode(struct mGUIRunner* runner) {
UNUSED(runner);
screenCleanup |= SCREEN_CLEANUP_TOP | SCREEN_CLEANUP_BOTTOM;
screenMode = (screenMode + 1) % SM_MAX;
mCoreConfigSetUIntValue(&runner->context.config, "screenMode", screenMode);
mCoreConfigSetUIntValue(&runner->core->config, "screenMode", screenMode);
}
static uint32_t _pollInput(void) {
@ -444,7 +441,7 @@ static uint32_t _pollInput(void) {
keys |= 1 << GUI_INPUT_CANCEL;
}
if (activeKeys & KEY_Y) {
keys |= 1 << GBA_GUI_INPUT_SCREEN_MODE;
keys |= 1 << mGUI_INPUT_SCREEN_MODE;
}
if (activeKeys & KEY_B) {
keys |= 1 << GUI_INPUT_BACK;
@ -465,10 +462,10 @@ static uint32_t _pollInput(void) {
keys |= 1 << GUI_INPUT_DOWN;
}
if (activeKeys & KEY_CSTICK_UP) {
keys |= 1 << GBA_GUI_INPUT_INCREASE_BRIGHTNESS;
keys |= 1 << mGUI_INPUT_INCREASE_BRIGHTNESS;
}
if (activeKeys & KEY_CSTICK_DOWN) {
keys |= 1 << GBA_GUI_INPUT_DECREASE_BRIGHTNESS;
keys |= 1 << mGUI_INPUT_DECREASE_BRIGHTNESS;
}
return keys;
}
@ -510,8 +507,8 @@ static int32_t _readGyroZ(struct mRotationSource* source) {
static void _postAudioBuffer(struct GBAAVStream* stream, struct GBAAudio* audio) {
UNUSED(stream);
if (hasSound == CSND_SUPPORTED) {
blip_read_samples(audio->left, &audioLeft[audioPos], AUDIO_SAMPLES, false);
blip_read_samples(audio->right, &audioRight[audioPos], AUDIO_SAMPLES, false);
blip_read_samples(audio->psg.left, &audioLeft[audioPos], AUDIO_SAMPLES, false);
blip_read_samples(audio->psg.right, &audioRight[audioPos], AUDIO_SAMPLES, false);
GSPGPU_FlushDataCache(&audioLeft[audioPos], AUDIO_SAMPLES * sizeof(int16_t));
GSPGPU_FlushDataCache(&audioRight[audioPos], AUDIO_SAMPLES * sizeof(int16_t));
audioPos = (audioPos + AUDIO_SAMPLES) % AUDIO_SAMPLE_BUFFER;
@ -529,8 +526,8 @@ static void _postAudioBuffer(struct GBAAVStream* stream, struct GBAAudio* audio)
while (dspBuffer[bufferId].status == NDSP_WBUF_QUEUED || dspBuffer[bufferId].status == NDSP_WBUF_PLAYING) {
bufferId = (bufferId + 1) & (DSP_BUFFERS - 1);
if (bufferId == startId) {
blip_clear(audio->left);
blip_clear(audio->right);
blip_clear(audio->psg.left);
blip_clear(audio->psg.right);
return;
}
}
@ -538,8 +535,8 @@ static void _postAudioBuffer(struct GBAAVStream* stream, struct GBAAudio* audio)
memset(&dspBuffer[bufferId], 0, sizeof(dspBuffer[bufferId]));
dspBuffer[bufferId].data_pcm16 = tmpBuf;
dspBuffer[bufferId].nsamples = AUDIO_SAMPLES;
blip_read_samples(audio->left, dspBuffer[bufferId].data_pcm16, AUDIO_SAMPLES, true);
blip_read_samples(audio->right, dspBuffer[bufferId].data_pcm16 + 1, AUDIO_SAMPLES, true);
blip_read_samples(audio->psg.left, dspBuffer[bufferId].data_pcm16, AUDIO_SAMPLES, true);
blip_read_samples(audio->psg.right, dspBuffer[bufferId].data_pcm16 + 1, AUDIO_SAMPLES, true);
DSP_FlushDataCache(dspBuffer[bufferId].data_pcm16, AUDIO_SAMPLES * 2 * sizeof(int16_t));
ndspChnWaveBufAdd(0, &dspBuffer[bufferId]);
}
@ -628,7 +625,7 @@ int main() {
return 1;
}
struct GBAGUIRunner runner = {
struct mGUIRunner runner = {
.params = {
320, 240,
font, "/",
@ -708,9 +705,9 @@ int main() {
.pollGameInput = _pollGameInput
};
GBAGUIInit(&runner, "3ds");
GBAGUIRunloop(&runner);
GBAGUIDeinit(&runner);
mGUIInit(&runner, "3ds");
mGUIRunloop(&runner);
mGUIDeinit(&runner);
_cleanup();
return 0;

View File

@ -45,7 +45,7 @@ static uint32_t _pollInput(void) {
input |= 1 << GUI_INPUT_CANCEL;
}
if (pad.buttons & SCE_CTRL_SQUARE) {
input |= 1 << GBA_GUI_INPUT_SCREEN_MODE;
input |= 1 << mGUI_INPUT_SCREEN_MODE;
}
if (pad.buttons & SCE_CTRL_CIRCLE) {
input |= 1 << GUI_INPUT_BACK;
@ -95,7 +95,7 @@ static int _batteryState(void) {
int main() {
vita2d_init();
struct GUIFont* font = GUIFontCreate();
struct GBAGUIRunner runner = {
struct mGUIRunner runner = {
.params = {
PSP2_HORIZONTAL_PIXELS, PSP2_VERTICAL_PIXELS,
font, "cache0:", _drawStart, _drawEnd,
@ -159,9 +159,9 @@ int main() {
.pollGameInput = GBAPSP2PollInput
};
GBAGUIInit(&runner, "psvita");
GBAGUIRunloop(&runner);
GBAGUIDeinit(&runner);
mGUIInit(&runner, "psvita");
mGUIRunloop(&runner);
mGUIDeinit(&runner);
GUIFontDestroy(font);
vita2d_fini();

View File

@ -5,9 +5,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "psp2-context.h"
#include "core/core.h"
#include "gba/gba.h"
#include "gba/audio.h"
#include "gba/context/context.h"
#include "gba/gui/gui-runner.h"
#include "gba/input.h"
@ -36,7 +37,7 @@ static enum ScreenMode {
SM_MAX
} screenMode;
static struct GBAVideoSoftwareRenderer renderer;
static void* outputBuffer;
static vita2d_texture* tex;
static vita2d_texture* screenshot;
static Thread audioThread;
@ -111,72 +112,70 @@ static int32_t _readGyroZ(struct mRotationSource* source) {
return rotation->state.gyro.z * 0x10000000;
}
uint16_t GBAPSP2PollInput(struct GBAGUIRunner* runner) {
uint16_t GBAPSP2PollInput(struct mGUIRunner* runner) {
SceCtrlData pad;
sceCtrlPeekBufferPositive(0, &pad, 1);
int activeKeys = mInputMapKeyBits(&runner->context.inputMap, PSP2_INPUT, pad.buttons, 0);
enum GBAKey angles = mInputMapAxis(&runner->context.inputMap, PSP2_INPUT, 0, pad.ly);
int activeKeys = mInputMapKeyBits(&runner->core->inputMap, PSP2_INPUT, pad.buttons, 0);
enum GBAKey angles = mInputMapAxis(&runner->core->inputMap, PSP2_INPUT, 0, pad.ly);
if (angles != GBA_KEY_NONE) {
activeKeys |= 1 << angles;
}
angles = mInputMapAxis(&runner->context.inputMap, PSP2_INPUT, 1, pad.lx);
angles = mInputMapAxis(&runner->core->inputMap, PSP2_INPUT, 1, pad.lx);
if (angles != GBA_KEY_NONE) {
activeKeys |= 1 << angles;
}
angles = mInputMapAxis(&runner->context.inputMap, PSP2_INPUT, 2, pad.ry);
angles = mInputMapAxis(&runner->core->inputMap, PSP2_INPUT, 2, pad.ry);
if (angles != GBA_KEY_NONE) {
activeKeys |= 1 << angles;
}
angles = mInputMapAxis(&runner->context.inputMap, PSP2_INPUT, 3, pad.rx);
angles = mInputMapAxis(&runner->core->inputMap, PSP2_INPUT, 3, pad.rx);
if (angles != GBA_KEY_NONE) {
activeKeys |= 1 << angles;
}
return activeKeys;
}
void GBAPSP2Setup(struct GBAGUIRunner* runner) {
void GBAPSP2Setup(struct mGUIRunner* runner) {
scePowerSetArmClockFrequency(80);
_mapVitaKey(&runner->context.inputMap, SCE_CTRL_CROSS, GBA_KEY_A);
_mapVitaKey(&runner->context.inputMap, SCE_CTRL_CIRCLE, GBA_KEY_B);
_mapVitaKey(&runner->context.inputMap, SCE_CTRL_START, GBA_KEY_START);
_mapVitaKey(&runner->context.inputMap, SCE_CTRL_SELECT, GBA_KEY_SELECT);
_mapVitaKey(&runner->context.inputMap, SCE_CTRL_UP, GBA_KEY_UP);
_mapVitaKey(&runner->context.inputMap, SCE_CTRL_DOWN, GBA_KEY_DOWN);
_mapVitaKey(&runner->context.inputMap, SCE_CTRL_LEFT, GBA_KEY_LEFT);
_mapVitaKey(&runner->context.inputMap, SCE_CTRL_RIGHT, GBA_KEY_RIGHT);
_mapVitaKey(&runner->context.inputMap, SCE_CTRL_LTRIGGER, GBA_KEY_L);
_mapVitaKey(&runner->context.inputMap, SCE_CTRL_RTRIGGER, GBA_KEY_R);
_mapVitaKey(&runner->core->inputMap, SCE_CTRL_CROSS, GBA_KEY_A);
_mapVitaKey(&runner->core->inputMap, SCE_CTRL_CIRCLE, GBA_KEY_B);
_mapVitaKey(&runner->core->inputMap, SCE_CTRL_START, GBA_KEY_START);
_mapVitaKey(&runner->core->inputMap, SCE_CTRL_SELECT, GBA_KEY_SELECT);
_mapVitaKey(&runner->core->inputMap, SCE_CTRL_UP, GBA_KEY_UP);
_mapVitaKey(&runner->core->inputMap, SCE_CTRL_DOWN, GBA_KEY_DOWN);
_mapVitaKey(&runner->core->inputMap, SCE_CTRL_LEFT, GBA_KEY_LEFT);
_mapVitaKey(&runner->core->inputMap, SCE_CTRL_RIGHT, GBA_KEY_RIGHT);
_mapVitaKey(&runner->core->inputMap, SCE_CTRL_LTRIGGER, GBA_KEY_L);
_mapVitaKey(&runner->core->inputMap, SCE_CTRL_RTRIGGER, GBA_KEY_R);
struct mInputAxis desc = { GBA_KEY_DOWN, GBA_KEY_UP, 192, 64 };
mInputBindAxis(&runner->context.inputMap, PSP2_INPUT, 0, &desc);
mInputBindAxis(&runner->core->inputMap, PSP2_INPUT, 0, &desc);
desc = (struct mInputAxis) { GBA_KEY_RIGHT, GBA_KEY_LEFT, 192, 64 };
mInputBindAxis(&runner->context.inputMap, PSP2_INPUT, 1, &desc);
mInputBindAxis(&runner->core->inputMap, PSP2_INPUT, 1, &desc);
tex = vita2d_create_empty_texture_format(256, 256, SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR);
screenshot = vita2d_create_empty_texture_format(256, 256, SCE_GXM_TEXTURE_FORMAT_X8U8U8U8_1BGR);
GBAVideoSoftwareRendererCreate(&renderer);
renderer.outputBuffer = vita2d_texture_get_datap(tex);
renderer.outputBufferStride = 256;
runner->context.renderer = &renderer.d;
outputBuffer = vita2d_texture_get_datap(tex);
runner->core->setVideoBuffer(runner->core, outputBuffer, 256);
rotation.d.sample = _sampleRotation;
rotation.d.readTiltX = _readTiltX;
rotation.d.readTiltY = _readTiltY;
rotation.d.readGyroZ = _readGyroZ;
runner->context.gba->rotationSource = &rotation.d;
((struct GBA*) runner->core->board)->rotationSource = &rotation.d;
backdrop = vita2d_load_PNG_buffer(_binary_backdrop_png_start);
}
void GBAPSP2LoadROM(struct GBAGUIRunner* runner) {
void GBAPSP2LoadROM(struct mGUIRunner* runner) {
scePowerSetArmClockFrequency(444);
double ratio = GBAAudioCalculateRatio(1, 60, 1);
blip_set_rates(runner->context.gba->audio.psg.left, GBA_ARM7TDMI_FREQUENCY, 48000 * ratio);
blip_set_rates(runner->context.gba->audio.psg.right, GBA_ARM7TDMI_FREQUENCY, 48000 * ratio);
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), GBA_ARM7TDMI_FREQUENCY, 48000 * ratio);
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), GBA_ARM7TDMI_FREQUENCY, 48000 * ratio);
if (runner->context.gba->memory.hw.devices & (HW_TILT | HW_GYRO)) {
if (((struct GBA*) runner->core->board)->memory.hw.devices & (HW_TILT | HW_GYRO)) {
sceMotionStartSampling();
}
@ -187,15 +186,15 @@ void GBAPSP2LoadROM(struct GBAGUIRunner* runner) {
ThreadCreate(&audioThread, _audioThread, &audioContext);
}
void GBAPSP2PrepareForFrame(struct GBAGUIRunner* runner) {
void GBAPSP2PrepareForFrame(struct mGUIRunner* runner) {
MutexLock(&audioContext.mutex);
while (blip_samples_avail(runner->context.gba->audio.psg.left) >= PSP2_SAMPLES) {
while (blip_samples_avail(runner->core->getAudioChannel(runner->core, 0)) >= PSP2_SAMPLES) {
if (CircleBufferSize(&audioContext.buffer) + PSP2_SAMPLES * sizeof(struct GBAStereoSample) > CircleBufferCapacity(&audioContext.buffer)) {
break;
}
struct GBAStereoSample samples[PSP2_SAMPLES];
blip_read_samples(runner->context.gba->audio.psg.left, &samples[0].left, PSP2_SAMPLES, true);
blip_read_samples(runner->context.gba->audio.psg.right, &samples[0].right, PSP2_SAMPLES, true);
blip_read_samples(runner->core->getAudioChannel(runner->core, 0), &samples[0].left, PSP2_SAMPLES, true);
blip_read_samples(runner->core->getAudioChannel(runner->core, 1), &samples[0].right, PSP2_SAMPLES, true);
int i;
for (i = 0; i < PSP2_SAMPLES; ++i) {
CircleBufferWrite16(&audioContext.buffer, samples[i].left);
@ -206,19 +205,19 @@ void GBAPSP2PrepareForFrame(struct GBAGUIRunner* runner) {
MutexUnlock(&audioContext.mutex);
}
void GBAPSP2UnloadROM(struct GBAGUIRunner* runner) {
if (runner->context.gba->memory.hw.devices & (HW_TILT | HW_GYRO)) {
void GBAPSP2UnloadROM(struct mGUIRunner* runner) {
if (((struct GBA*) runner->core->board)->memory.hw.devices & (HW_TILT | HW_GYRO)) {
sceMotionStopSampling();
}
scePowerSetArmClockFrequency(80);
}
void GBAPSP2Teardown(struct GBAGUIRunner* runner) {
void GBAPSP2Teardown(struct mGUIRunner* runner) {
vita2d_free_texture(tex);
vita2d_free_texture(screenshot);
}
void GBAPSP2Draw(struct GBAGUIRunner* runner, bool faded) {
void GBAPSP2Draw(struct mGUIRunner* runner, bool faded) {
UNUSED(runner);
switch (screenMode) {
case SM_BACKDROP:
@ -234,7 +233,7 @@ void GBAPSP2Draw(struct GBAGUIRunner* runner, bool faded) {
}
}
void GBAPSP2DrawScreenshot(struct GBAGUIRunner* runner, const uint32_t* pixels, bool faded) {
void GBAPSP2DrawScreenshot(struct mGUIRunner* runner, const uint32_t* pixels, bool faded) {
UNUSED(runner);
uint32_t* texpixels = vita2d_texture_get_datap(screenshot);
int y;
@ -255,13 +254,13 @@ void GBAPSP2DrawScreenshot(struct GBAGUIRunner* runner, const uint32_t* pixels,
}
}
void GBAPSP2IncrementScreenMode(struct GBAGUIRunner* runner) {
void GBAPSP2IncrementScreenMode(struct mGUIRunner* runner) {
unsigned mode;
if (mCoreConfigGetUIntValue(&runner->context.config, "screenMode", &mode) && mode != screenMode) {
if (mCoreConfigGetUIntValue(&runner->core->config, "screenMode", &mode) && mode != screenMode) {
screenMode = mode;
} else {
screenMode = (screenMode + 1) % SM_MAX;
mCoreConfigSetUIntValue(&runner->context.config, "screenMode", screenMode);
mCoreConfigSetUIntValue(&runner->core->config, "screenMode", screenMode);
}
}

View File

@ -9,16 +9,16 @@
#include "psp2-common.h"
#include "util/gui.h"
struct GBAGUIRunner;
void GBAPSP2Setup(struct GBAGUIRunner* runner);
void GBAPSP2Teardown(struct GBAGUIRunner* runner);
struct mGUIRunner;
void GBAPSP2Setup(struct mGUIRunner* runner);
void GBAPSP2Teardown(struct mGUIRunner* runner);
void GBAPSP2LoadROM(struct GBAGUIRunner* runner);
void GBAPSP2UnloadROM(struct GBAGUIRunner* runner);
void GBAPSP2PrepareForFrame(struct GBAGUIRunner* runner);
void GBAPSP2Draw(struct GBAGUIRunner* runner, bool faded);
void GBAPSP2DrawScreenshot(struct GBAGUIRunner* runner, const uint32_t* pixels, bool faded);
void GBAPSP2IncrementScreenMode(struct GBAGUIRunner* runner);
uint16_t GBAPSP2PollInput(struct GBAGUIRunner* runner);
void GBAPSP2LoadROM(struct mGUIRunner* runner);
void GBAPSP2UnloadROM(struct mGUIRunner* runner);
void GBAPSP2PrepareForFrame(struct mGUIRunner* runner);
void GBAPSP2Draw(struct mGUIRunner* runner, bool faded);
void GBAPSP2DrawScreenshot(struct mGUIRunner* runner, const uint32_t* pixels, bool faded);
void GBAPSP2IncrementScreenMode(struct mGUIRunner* runner);
uint16_t GBAPSP2PollInput(struct mGUIRunner* runner);
#endif

View File

@ -14,9 +14,11 @@
#include "util/common.h"
#include "gba/renderers/video-software.h"
#include "gba/context/context.h"
#include "core/core.h"
#include "gba/audio.h"
#include "gba/gba.h"
#include "gba/gui/gui-runner.h"
#include "gba/input.h"
#include "util/gui.h"
#include "util/gui/file-select.h"
#include "util/gui/font.h"
@ -63,17 +65,17 @@ static enum GUICursorState _pollCursor(unsigned* x, unsigned* y);
static void _guiPrepare(void);
static void _guiFinish(void);
static void _setup(struct GBAGUIRunner* runner);
static void _gameLoaded(struct GBAGUIRunner* runner);
static void _gameUnloaded(struct GBAGUIRunner* runner);
static void _unpaused(struct GBAGUIRunner* runner);
static void _drawFrame(struct GBAGUIRunner* runner, bool faded);
static uint16_t _pollGameInput(struct GBAGUIRunner* runner);
static void _setup(struct mGUIRunner* runner);
static void _gameLoaded(struct mGUIRunner* runner);
static void _gameUnloaded(struct mGUIRunner* runner);
static void _unpaused(struct mGUIRunner* runner);
static void _drawFrame(struct mGUIRunner* runner, bool faded);
static uint16_t _pollGameInput(struct mGUIRunner* runner);
static s8 WPAD_StickX(u8 chan, u8 right);
static s8 WPAD_StickY(u8 chan, u8 right);
static struct GBAVideoSoftwareRenderer renderer;
static void* outputBuffer;
static struct mRumble rumble;
static struct mRotationSource rotation;
static GXRModeObj* vmode;
@ -96,7 +98,7 @@ static volatile int currentAudioBuffer = 0;
static struct GUIFont* font;
static void reconfigureScreen(GXRModeObj* vmode) {
static void reconfigureScreen(struct mCore* core, GXRModeObj* vmode) {
free(framebuffer[0]);
free(framebuffer[1]);
@ -122,12 +124,17 @@ static void reconfigureScreen(GXRModeObj* vmode) {
GX_SetCopyFilter(vmode->aa, vmode->sample_pattern, GX_TRUE, vmode->vfilter);
GX_SetFieldMode(vmode->field_rendering, ((vmode->viHeight == 2 * vmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));
int hfactor = vmode->fbWidth / VIDEO_HORIZONTAL_PIXELS;
int vfactor = vmode->efbHeight / VIDEO_VERTICAL_PIXELS;
if (hfactor > vfactor) {
scaleFactor = vfactor;
} else {
scaleFactor = hfactor;
if (core) {
unsigned width = VIDEO_HORIZONTAL_PIXELS;
unsigned height = VIDEO_VERTICAL_PIXELS;
core->desiredVideoDimensions(core, &width, &height);
int hfactor = vmode->fbWidth / width;
int vfactor = vmode->efbHeight / height;
if (hfactor > vfactor) {
scaleFactor = vfactor;
} else {
scaleFactor = hfactor;
}
}
};
@ -154,7 +161,7 @@ int main(int argc, char* argv[]) {
GX_Init(fifo, 0x40000);
GX_SetCopyClear(bg, 0x00FFFFFF);
reconfigureScreen(vmode);
reconfigureScreen(NULL, vmode);
GX_SetCullMode(GX_CULL_NONE);
GX_SetDispCopyGamma(GX_GM_1_0);
@ -204,7 +211,7 @@ int main(int argc, char* argv[]) {
rotation.readTiltY = _readTiltY;
rotation.readGyroZ = _readGyroZ;
struct GBAGUIRunner runner = {
struct mGUIRunner runner = {
.params = {
vmode->fbWidth * GUI_SCALE, vmode->efbHeight * GUI_SCALE,
font, "",
@ -357,17 +364,17 @@ int main(int argc, char* argv[]) {
.unpaused = _unpaused,
.pollGameInput = _pollGameInput
};
GBAGUIInit(&runner, "wii");
mGUIInit(&runner, "wii");
if (argc > 1) {
GBAGUIRun(&runner, argv[1]);
mGUIRun(&runner, argv[1]);
} else {
GBAGUIRunloop(&runner);
mGUIRunloop(&runner);
}
GBAGUIDeinit(&runner);
mGUIDeinit(&runner);
free(fifo);
free(renderer.outputBuffer);
free(outputBuffer);
GUIFontDestroy(font);
free(framebuffer[0]);
@ -514,70 +521,69 @@ void _guiFinish(void) {
}
}
void _setup(struct GBAGUIRunner* runner) {
runner->context.gba->rumble = &rumble;
runner->context.gba->rotationSource = &rotation;
void _setup(struct mGUIRunner* runner) {
((struct GBA*) runner->core->board)->rumble = &rumble;
((struct GBA*) runner->core->board)->rotationSource = &rotation;
_mapKey(&runner->context.inputMap, GCN1_INPUT, PAD_BUTTON_A, GBA_KEY_A);
_mapKey(&runner->context.inputMap, GCN1_INPUT, PAD_BUTTON_B, GBA_KEY_B);
_mapKey(&runner->context.inputMap, GCN1_INPUT, PAD_BUTTON_START, GBA_KEY_START);
_mapKey(&runner->context.inputMap, GCN1_INPUT, PAD_BUTTON_X, GBA_KEY_SELECT);
_mapKey(&runner->context.inputMap, GCN2_INPUT, PAD_BUTTON_Y, GBA_KEY_SELECT);
_mapKey(&runner->context.inputMap, GCN1_INPUT, PAD_BUTTON_UP, GBA_KEY_UP);
_mapKey(&runner->context.inputMap, GCN1_INPUT, PAD_BUTTON_DOWN, GBA_KEY_DOWN);
_mapKey(&runner->context.inputMap, GCN1_INPUT, PAD_BUTTON_LEFT, GBA_KEY_LEFT);
_mapKey(&runner->context.inputMap, GCN1_INPUT, PAD_BUTTON_RIGHT, GBA_KEY_RIGHT);
_mapKey(&runner->context.inputMap, GCN1_INPUT, PAD_TRIGGER_L, GBA_KEY_L);
_mapKey(&runner->context.inputMap, GCN1_INPUT, PAD_TRIGGER_R, GBA_KEY_R);
_mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_A, GBA_KEY_A);
_mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_B, GBA_KEY_B);
_mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_START, GBA_KEY_START);
_mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_X, GBA_KEY_SELECT);
_mapKey(&runner->core->inputMap, GCN2_INPUT, PAD_BUTTON_Y, GBA_KEY_SELECT);
_mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_UP, GBA_KEY_UP);
_mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_DOWN, GBA_KEY_DOWN);
_mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_LEFT, GBA_KEY_LEFT);
_mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_BUTTON_RIGHT, GBA_KEY_RIGHT);
_mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_TRIGGER_L, GBA_KEY_L);
_mapKey(&runner->core->inputMap, GCN1_INPUT, PAD_TRIGGER_R, GBA_KEY_R);
_mapKey(&runner->context.inputMap, WIIMOTE_INPUT, WPAD_BUTTON_2, GBA_KEY_A);
_mapKey(&runner->context.inputMap, WIIMOTE_INPUT, WPAD_BUTTON_1, GBA_KEY_B);
_mapKey(&runner->context.inputMap, WIIMOTE_INPUT, WPAD_BUTTON_PLUS, GBA_KEY_START);
_mapKey(&runner->context.inputMap, WIIMOTE_INPUT, WPAD_BUTTON_MINUS, GBA_KEY_SELECT);
_mapKey(&runner->context.inputMap, WIIMOTE_INPUT, WPAD_BUTTON_RIGHT, GBA_KEY_UP);
_mapKey(&runner->context.inputMap, WIIMOTE_INPUT, WPAD_BUTTON_LEFT, GBA_KEY_DOWN);
_mapKey(&runner->context.inputMap, WIIMOTE_INPUT, WPAD_BUTTON_UP, GBA_KEY_LEFT);
_mapKey(&runner->context.inputMap, WIIMOTE_INPUT, WPAD_BUTTON_DOWN, GBA_KEY_RIGHT);
_mapKey(&runner->context.inputMap, WIIMOTE_INPUT, WPAD_BUTTON_B, GBA_KEY_L);
_mapKey(&runner->context.inputMap, WIIMOTE_INPUT, WPAD_BUTTON_A, GBA_KEY_R);
_mapKey(&runner->core->inputMap, WIIMOTE_INPUT, WPAD_BUTTON_2, GBA_KEY_A);
_mapKey(&runner->core->inputMap, WIIMOTE_INPUT, WPAD_BUTTON_1, GBA_KEY_B);
_mapKey(&runner->core->inputMap, WIIMOTE_INPUT, WPAD_BUTTON_PLUS, GBA_KEY_START);
_mapKey(&runner->core->inputMap, WIIMOTE_INPUT, WPAD_BUTTON_MINUS, GBA_KEY_SELECT);
_mapKey(&runner->core->inputMap, WIIMOTE_INPUT, WPAD_BUTTON_RIGHT, GBA_KEY_UP);
_mapKey(&runner->core->inputMap, WIIMOTE_INPUT, WPAD_BUTTON_LEFT, GBA_KEY_DOWN);
_mapKey(&runner->core->inputMap, WIIMOTE_INPUT, WPAD_BUTTON_UP, GBA_KEY_LEFT);
_mapKey(&runner->core->inputMap, WIIMOTE_INPUT, WPAD_BUTTON_DOWN, GBA_KEY_RIGHT);
_mapKey(&runner->core->inputMap, WIIMOTE_INPUT, WPAD_BUTTON_B, GBA_KEY_L);
_mapKey(&runner->core->inputMap, WIIMOTE_INPUT, WPAD_BUTTON_A, GBA_KEY_R);
_mapKey(&runner->context.inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_A, GBA_KEY_A);
_mapKey(&runner->context.inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_B, GBA_KEY_B);
_mapKey(&runner->context.inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_PLUS, GBA_KEY_START);
_mapKey(&runner->context.inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_MINUS, GBA_KEY_SELECT);
_mapKey(&runner->context.inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_UP, GBA_KEY_UP);
_mapKey(&runner->context.inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_DOWN, GBA_KEY_DOWN);
_mapKey(&runner->context.inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_LEFT, GBA_KEY_LEFT);
_mapKey(&runner->context.inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_RIGHT, GBA_KEY_RIGHT);
_mapKey(&runner->context.inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_FULL_L, GBA_KEY_L);
_mapKey(&runner->context.inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_FULL_R, GBA_KEY_R);
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_A, GBA_KEY_A);
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_B, GBA_KEY_B);
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_PLUS, GBA_KEY_START);
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_MINUS, GBA_KEY_SELECT);
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_UP, GBA_KEY_UP);
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_DOWN, GBA_KEY_DOWN);
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_LEFT, GBA_KEY_LEFT);
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_RIGHT, GBA_KEY_RIGHT);
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_FULL_L, GBA_KEY_L);
_mapKey(&runner->core->inputMap, CLASSIC_INPUT, WPAD_CLASSIC_BUTTON_FULL_R, GBA_KEY_R);
struct mInputAxis desc = { GBA_KEY_RIGHT, GBA_KEY_LEFT, 0x20, -0x20 };
mInputBindAxis(&runner->context.inputMap, GCN1_INPUT, 0, &desc);
mInputBindAxis(&runner->context.inputMap, CLASSIC_INPUT, 0, &desc);
mInputBindAxis(&runner->core->inputMap, GCN1_INPUT, 0, &desc);
mInputBindAxis(&runner->core->inputMap, CLASSIC_INPUT, 0, &desc);
desc = (struct mInputAxis) { GBA_KEY_UP, GBA_KEY_DOWN, 0x20, -0x20 };
mInputBindAxis(&runner->context.inputMap, GCN1_INPUT, 1, &desc);
mInputBindAxis(&runner->context.inputMap, CLASSIC_INPUT, 1, &desc);
mInputBindAxis(&runner->core->inputMap, GCN1_INPUT, 1, &desc);
mInputBindAxis(&runner->core->inputMap, CLASSIC_INPUT, 1, &desc);
GBAVideoSoftwareRendererCreate(&renderer);
renderer.outputBuffer = memalign(32, 256 * 256 * BYTES_PER_PIXEL);
renderer.outputBufferStride = 256;
runner->context.renderer = &renderer.d;
outputBuffer = memalign(32, 256 * 256 * BYTES_PER_PIXEL);
runner->core->setVideoBuffer(runner->core, outputBuffer, 256);
GBAAudioResizeBuffer(&runner->context.gba->audio, SAMPLES);
GBAAudioResizeBuffer(&((struct GBA*) runner->core->board)->audio, SAMPLES);
double ratio = GBAAudioCalculateRatio(1, 60 / 1.001, 1);
blip_set_rates(runner->context.gba->audio.psg.left, GBA_ARM7TDMI_FREQUENCY, 48000 * ratio);
blip_set_rates(runner->context.gba->audio.psg.right, GBA_ARM7TDMI_FREQUENCY, 48000 * ratio);
blip_set_rates(runner->core->getAudioChannel(runner->core, 0), GBA_ARM7TDMI_FREQUENCY, 48000 * ratio);
blip_set_rates(runner->core->getAudioChannel(runner->core, 1), GBA_ARM7TDMI_FREQUENCY, 48000 * ratio);
}
void _gameUnloaded(struct GBAGUIRunner* runner) {
void _gameUnloaded(struct mGUIRunner* runner) {
UNUSED(runner);
AUDIO_StopDMA();
}
void _gameLoaded(struct GBAGUIRunner* runner) {
if (runner->context.gba->memory.hw.devices & HW_GYRO) {
void _gameLoaded(struct mGUIRunner* runner) {
reconfigureScreen(runner->core, vmode);
if (((struct GBA*) runner->core->board)->memory.hw.devices & HW_GYRO) {
int i;
for (i = 0; i < 6; ++i) {
u32 result = WPAD_SetMotionPlus(0, 1);
@ -590,17 +596,17 @@ void _gameLoaded(struct GBAGUIRunner* runner) {
_unpaused(runner);
}
void _unpaused(struct GBAGUIRunner* runner) {
void _unpaused(struct mGUIRunner* runner) {
u32 level = 0;
_CPU_ISR_Disable(level);
referenceRetraceCount = retraceCount;
_CPU_ISR_Restore(level);
unsigned mode;
if (mCoreConfigGetUIntValue(&runner->context.config, "screenMode", &mode) && mode < SM_MAX) {
if (mCoreConfigGetUIntValue(&runner->core->config, "screenMode", &mode) && mode < SM_MAX) {
screenMode = mode;
}
if (mCoreConfigGetUIntValue(&runner->context.config, "filter", &mode) && mode < FM_MAX) {
if (mCoreConfigGetUIntValue(&runner->core->config, "filter", &mode) && mode < FM_MAX) {
switch (mode) {
case FM_NEAREST:
default:
@ -614,16 +620,16 @@ void _unpaused(struct GBAGUIRunner* runner) {
_guiFinish();
}
void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
int available = blip_samples_avail(runner->context.gba->audio.psg.left);
void _drawFrame(struct mGUIRunner* runner, bool faded) {
int available = blip_samples_avail(runner->core->getAudioChannel(runner->core, 0));
if (available + audioBufferSize > SAMPLES) {
available = SAMPLES - audioBufferSize;
}
available &= ~((32 / sizeof(struct GBAStereoSample)) - 1); // Force align to 32 bytes
if (available > 0) {
// These appear to be reversed for AUDIO_InitDMA
blip_read_samples(runner->context.gba->audio.psg.left, &audioBuffer[currentAudioBuffer][audioBufferSize].right, available, true);
blip_read_samples(runner->context.gba->audio.psg.right, &audioBuffer[currentAudioBuffer][audioBufferSize].left, available, true);
blip_read_samples(runner->core->getAudioChannel(runner->core, 0), &audioBuffer[currentAudioBuffer][audioBufferSize].right, available, true);
blip_read_samples(runner->core->getAudioChannel(runner->core, 1), &audioBuffer[currentAudioBuffer][audioBufferSize].left, available, true);
audioBufferSize += available;
}
if (audioBufferSize == SAMPLES && !AUDIO_GetDMAEnableFlag()) {
@ -637,7 +643,7 @@ void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
}
size_t x, y;
uint64_t* texdest = (uint64_t*) texmem;
uint64_t* texsrc = (uint64_t*) renderer.outputBuffer;
uint64_t* texsrc = (uint64_t*) outputBuffer;
for (y = 0; y < VIDEO_VERTICAL_PIXELS; y += 4) {
for (x = 0; x < VIDEO_HORIZONTAL_PIXELS >> 2; ++x) {
texdest[0 + x * 4 + y * 64] = texsrc[0 + x + y * 64];
@ -682,7 +688,7 @@ void _drawFrame(struct GBAGUIRunner* runner, bool faded) {
GX_End();
}
uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
uint16_t _pollGameInput(struct mGUIRunner* runner) {
UNUSED(runner);
PAD_ScanPads();
u16 padkeys = PAD_ButtonsHeld(0);
@ -690,25 +696,25 @@ uint16_t _pollGameInput(struct GBAGUIRunner* runner) {
u32 wiiPad = WPAD_ButtonsHeld(0);
u32 ext = 0;
WPAD_Probe(0, &ext);
uint16_t keys = mInputMapKeyBits(&runner->context.inputMap, GCN1_INPUT, padkeys, 0);
keys |= mInputMapKeyBits(&runner->context.inputMap, GCN2_INPUT, padkeys, 0);
keys |= mInputMapKeyBits(&runner->context.inputMap, WIIMOTE_INPUT, wiiPad, 0);
uint16_t keys = mInputMapKeyBits(&runner->core->inputMap, GCN1_INPUT, padkeys, 0);
keys |= mInputMapKeyBits(&runner->core->inputMap, GCN2_INPUT, padkeys, 0);
keys |= mInputMapKeyBits(&runner->core->inputMap, WIIMOTE_INPUT, wiiPad, 0);
enum GBAKey angles = mInputMapAxis(&runner->context.inputMap, GCN1_INPUT, 0, PAD_StickX(0));
enum GBAKey angles = mInputMapAxis(&runner->core->inputMap, GCN1_INPUT, 0, PAD_StickX(0));
if (angles != GBA_KEY_NONE) {
keys |= 1 << angles;
}
angles = mInputMapAxis(&runner->context.inputMap, GCN1_INPUT, 1, PAD_StickY(0));
angles = mInputMapAxis(&runner->core->inputMap, GCN1_INPUT, 1, PAD_StickY(0));
if (angles != GBA_KEY_NONE) {
keys |= 1 << angles;
}
if (ext == WPAD_EXP_CLASSIC) {
keys |= mInputMapKeyBits(&runner->context.inputMap, CLASSIC_INPUT, wiiPad, 0);
angles = mInputMapAxis(&runner->context.inputMap, CLASSIC_INPUT, 0, WPAD_StickX(0, 0));
keys |= mInputMapKeyBits(&runner->core->inputMap, CLASSIC_INPUT, wiiPad, 0);
angles = mInputMapAxis(&runner->core->inputMap, CLASSIC_INPUT, 0, WPAD_StickX(0, 0));
if (angles != GBA_KEY_NONE) {
keys |= 1 << angles;
}
angles = mInputMapAxis(&runner->context.inputMap, CLASSIC_INPUT, 1, WPAD_StickY(0, 0));
angles = mInputMapAxis(&runner->core->inputMap, CLASSIC_INPUT, 1, WPAD_StickY(0, 0));
if (angles != GBA_KEY_NONE) {
keys |= 1 << angles;
}