Core: Refactor several input callbacks
jump to
@@ -0,0 +1,34 @@
+/* Copyright (c) 2013-2015 Jeffrey Pfau + * + * This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ +#ifndef CORE_INTERFACE_H +#define CORE_INTERFACE_H + +#include "util/common.h" + +struct mKeyCallback { + uint16_t (*readKeys)(struct mKeyCallback*); +}; + +struct mStopCallback { + void (*stop)(struct mStopCallback*); +}; + +struct mRotationSource { + void (*sample)(struct mRotationSource*); + + int32_t (*readTiltX)(struct mRotationSource*); + int32_t (*readTiltY)(struct mRotationSource*); + + int32_t (*readGyroZ)(struct mRotationSource*); +}; + +struct mRTCSource { + void (*sample)(struct mRTCSource*); + + time_t (*unixTime)(struct mRTCSource*); +}; + +#endif
@@ -96,9 +96,9 @@
int springIRQ; uint32_t biosChecksum; int* keySource; - struct GBARotationSource* rotationSource; + struct mRotationSource* rotationSource; struct GBALuminanceSource* luminanceSource; - struct GBARTCSource* rtcSource; + struct mRTCSource* rtcSource; struct GBARumble* rumble; struct GBARRContext* rr;@@ -114,8 +114,8 @@
GBALogHandler logHandler; enum GBALogLevel logLevel; struct GBAAVStream* stream; - struct GBAKeyCallback* keyCallback; - struct GBAStopCallback* stopCallback; + struct mKeyCallback* keyCallback; + struct mStopCallback* stopCallback; enum GBAIdleLoopOptimization idleOptimization; uint32_t idleLoop;
@@ -21,7 +21,7 @@ static void _rtcProcessByte(struct GBACartridgeHardware* hw);
static void _rtcUpdateClock(struct GBACartridgeHardware* hw); static unsigned _rtcBCD(unsigned value); -static time_t _rtcGenericCallback(struct GBARTCSource* source); +static time_t _rtcGenericCallback(struct mRTCSource* source); static void _gyroReadPins(struct GBACartridgeHardware* hw);@@ -29,7 +29,7 @@ static void _rumbleReadPins(struct GBACartridgeHardware* hw);
static void _lightReadPins(struct GBACartridgeHardware* hw); -static uint16_t _gbpRead(struct GBAKeyCallback*); +static uint16_t _gbpRead(struct mKeyCallback*); static uint16_t _gbpSioWriteRegister(struct GBASIODriver* driver, uint32_t address, uint16_t value); static int32_t _gbpSioProcessEvents(struct GBASIODriver* driver, int32_t cycles);@@ -271,7 +271,7 @@ }
void _rtcUpdateClock(struct GBACartridgeHardware* hw) { time_t t; - struct GBARTCSource* rtc = hw->p->rtcSource; + struct mRTCSource* rtc = hw->p->rtcSource; if (rtc) { if (rtc->sample) { rtc->sample(rtc);@@ -302,7 +302,7 @@ counter += (value % 10) << 4;
return counter; } -time_t _rtcGenericCallback(struct GBARTCSource* source) { +time_t _rtcGenericCallback(struct mRTCSource* source) { struct GBARTCGenericSource* rtc = (struct GBARTCGenericSource*) source; switch (rtc->override) { case RTC_NO_OVERRIDE:@@ -332,7 +332,7 @@ hw->gyroEdge = 0;
} void _gyroReadPins(struct GBACartridgeHardware* hw) { - struct GBARotationSource* gyro = hw->p->rotationSource; + struct mRotationSource* gyro = hw->p->rotationSource; if (!gyro || !gyro->readGyroZ) { return; }@@ -428,7 +428,7 @@ break;
case 0x8100: if (value == 0xAA && hw->tiltState == 1) { hw->tiltState = 0; - struct GBARotationSource* rotationSource = hw->p->rotationSource; + struct mRotationSource* rotationSource = hw->p->rotationSource; if (!rotationSource || !rotationSource->readTiltX || !rotationSource->readTiltY) { return; }@@ -535,7 +535,7 @@ GBASIOSetDriver(&gba->sio, &gba->memory.hw.gbpDriver.d, SIO_NORMAL_32);
} } -uint16_t _gbpRead(struct GBAKeyCallback* callback) { +uint16_t _gbpRead(struct mKeyCallback* callback) { struct GBAGBPKeyCallback* gbpCallback = (struct GBAGBPKeyCallback*) callback; if (gbpCallback->p->gbpInputsPosted == 2) { return 0x30F;
@@ -16,7 +16,7 @@
#define IS_GPIO_REGISTER(reg) ((reg) == GPIO_REG_DATA || (reg) == GPIO_REG_DIRECTION || (reg) == GPIO_REG_CONTROL) struct GBARTCGenericSource { - struct GBARTCSource d; + struct mRTCSource d; struct GBA* p; enum { RTC_NO_OVERRIDE,@@ -85,7 +85,7 @@ void (*setRumble)(struct GBARumble*, int enable);
}; struct GBAGBPKeyCallback { - struct GBAKeyCallback d; + struct mKeyCallback d; struct GBACartridgeHardware* p; };
@@ -8,6 +8,8 @@ #define INTERFACE_H
#include "util/common.h" +#include "core/interface.h" + enum GBALogLevel { GBA_LOG_FATAL = 0x01, GBA_LOG_ERROR = 0x02,@@ -62,35 +64,12 @@ void (*postAudioFrame)(struct GBAAVStream*, int16_t left, int16_t right);
void (*postAudioBuffer)(struct GBAAVStream*, struct GBAAudio*); }; -struct GBAKeyCallback { - uint16_t (*readKeys)(struct GBAKeyCallback*); -}; - -struct GBAStopCallback { - void (*stop)(struct GBAStopCallback*); -}; - -struct GBARotationSource { - void (*sample)(struct GBARotationSource*); - - int32_t (*readTiltX)(struct GBARotationSource*); - int32_t (*readTiltY)(struct GBARotationSource*); - - int32_t (*readGyroZ)(struct GBARotationSource*); -}; - extern const int GBA_LUX_LEVELS[10]; struct GBALuminanceSource { void (*sample)(struct GBALuminanceSource*); uint8_t (*readLuminance)(struct GBALuminanceSource*); -}; - -struct GBARTCSource { - void (*sample)(struct GBARTCSource*); - - time_t (*unixTime)(struct GBARTCSource*); }; struct GBASIODriver {
@@ -128,11 +128,11 @@ }
} struct GBAThreadStop { - struct GBAStopCallback d; + struct mStopCallback d; struct GBAThread* p; }; -static void _stopCallback(struct GBAStopCallback* stop) { +static void _stopCallback(struct mStopCallback* stop) { struct GBAThreadStop* callback = (struct GBAThreadStop*) stop; if (callback->p->stopCallback(callback->p)) { _changeState(callback->p, THREAD_EXITING, false);
@@ -39,7 +39,7 @@
FS_Archive sdmcArchive; static struct GBA3DSRotationSource { - struct GBARotationSource d; + struct mRotationSource d; accelVector accel; angularRate gyro; } rotation;
@@ -41,7 +41,7 @@ static vita2d_texture* tex;
static vita2d_texture* screenshot; static Thread audioThread; static struct GBASceRotationSource { - struct GBARotationSource d; + struct mRotationSource d; struct SceMotionSensorState state; } rotation;
@@ -217,7 +217,7 @@ #endif
return nullptr; } -GBARotationSource* InputController::rotationSource() { +mRotationSource* InputController::rotationSource() { #ifdef BUILD_SDL if (m_playerAttached) { return &m_sdlPlayer.rotation.d;
@@ -80,7 +80,7 @@ void stealFocus(QWidget* focus);
void releaseFocus(QWidget* focus); GBARumble* rumble(); - GBARotationSource* rotationSource(); + mRotationSource* rotationSource(); signals: void profileLoaded(const QString& profile);
@@ -13,7 +13,7 @@ #include <functional>
#include "ui_SensorView.h" -struct GBARotationSource; +struct mRotationSource; namespace QGBA {@@ -43,7 +43,7 @@
std::function<void(int)> m_jiggered; GameController* m_controller; InputController* m_input; - GBARotationSource* m_rotation; + mRotationSource* m_rotation; QTimer m_timer; void jiggerer(QAbstractButton*, void (InputController::*)(int));
@@ -29,10 +29,10 @@
#if SDL_VERSION_ATLEAST(2, 0, 0) static void _GBASDLSetRumble(struct GBARumble* rumble, int enable); #endif -static int32_t _GBASDLReadTiltX(struct GBARotationSource* rumble); -static int32_t _GBASDLReadTiltY(struct GBARotationSource* rumble); -static int32_t _GBASDLReadGyroZ(struct GBARotationSource* rumble); -static void _GBASDLRotationSample(struct GBARotationSource* source); +static int32_t _GBASDLReadTiltX(struct mRotationSource* rumble); +static int32_t _GBASDLReadTiltY(struct mRotationSource* rumble); +static int32_t _GBASDLReadGyroZ(struct mRotationSource* rumble); +static void _GBASDLRotationSample(struct mRotationSource* source); bool GBASDLInitEvents(struct GBASDLEvents* context) { #if SDL_VERSION_ATLEAST(2, 0, 4)@@ -605,23 +605,23 @@ }
return SDL_JoystickGetAxis(player->joystick->joystick, axis) * 0x3800; } -static int32_t _GBASDLReadTiltX(struct GBARotationSource* source) { +static int32_t _GBASDLReadTiltX(struct mRotationSource* source) { struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; return _readTilt(rotation->p, rotation->axisX); } -static int32_t _GBASDLReadTiltY(struct GBARotationSource* source) { +static int32_t _GBASDLReadTiltY(struct mRotationSource* source) { struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; return _readTilt(rotation->p, rotation->axisY); } -static int32_t _GBASDLReadGyroZ(struct GBARotationSource* source) { +static int32_t _GBASDLReadGyroZ(struct mRotationSource* source) { struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; float z = rotation->zDelta; return z * rotation->gyroSensitivity; } -static void _GBASDLRotationSample(struct GBARotationSource* source) { +static void _GBASDLRotationSample(struct mRotationSource* source) { struct GBASDLRotation* rotation = (struct GBASDLRotation*) source; SDL_JoystickUpdate(); if (!rotation->p->joystick) {
@@ -65,7 +65,7 @@ } rumble;
#endif struct GBASDLRotation { - struct GBARotationSource d; + struct mRotationSource d; struct GBASDLPlayer* p; // Tilt
@@ -51,10 +51,10 @@ static void _retraceCallback(u32 count);
static void _audioDMA(void); static void _setRumble(struct GBARumble* rumble, int enable); -static void _sampleRotation(struct GBARotationSource* source); -static int32_t _readTiltX(struct GBARotationSource* source); -static int32_t _readTiltY(struct GBARotationSource* source); -static int32_t _readGyroZ(struct GBARotationSource* source); +static void _sampleRotation(struct mRotationSource* source); +static int32_t _readTiltX(struct mRotationSource* source); +static int32_t _readTiltY(struct mRotationSource* source); +static int32_t _readGyroZ(struct mRotationSource* source); static void _drawStart(void); static void _drawEnd(void);@@ -75,7 +75,7 @@ static s8 WPAD_StickY(u8 chan, u8 right);
static struct GBAVideoSoftwareRenderer renderer; static struct GBARumble rumble; -static struct GBARotationSource rotation; +static struct mRotationSource rotation; static GXRModeObj* vmode; static Mtx model, view, modelview; static uint16_t* texmem;@@ -731,7 +731,7 @@ PAD_ControlMotor(0, PAD_MOTOR_STOP);
} } -void _sampleRotation(struct GBARotationSource* source) { +void _sampleRotation(struct mRotationSource* source) { UNUSED(source); vec3w_t accel; WPAD_Accel(0, &accel);@@ -749,17 +749,17 @@ gyroZ = exp.mp.rz - 0x1FA0;
gyroZ <<= 18; } -int32_t _readTiltX(struct GBARotationSource* source) { +int32_t _readTiltX(struct mRotationSource* source) { UNUSED(source); return tiltX; } -int32_t _readTiltY(struct GBARotationSource* source) { +int32_t _readTiltY(struct mRotationSource* source) { UNUSED(source); return tiltY; } -int32_t _readGyroZ(struct GBARotationSource* source) { +int32_t _readGyroZ(struct mRotationSource* source) { UNUSED(source); return gyroZ; }