GBA: Eliminate bitpacked struct for GPIO devices

This commit is contained in:
Jeffrey Pfau 2015-03-14 01:05:33 -07:00
parent f80406efb0
commit dd17c6f8b0
2 changed files with 16 additions and 31 deletions

View File

@ -139,13 +139,13 @@ void _rtcReadPins(struct GBACartridgeHardware* hw) {
} }
break; break;
case 2: case 2:
if (!hw->p0) { if (!(hw->pinState & 1)) {
hw->rtc.bits &= ~(1 << hw->rtc.bitsRead); hw->rtc.bits &= ~(1 << hw->rtc.bitsRead);
hw->rtc.bits |= hw->p1 << hw->rtc.bitsRead; hw->rtc.bits |= ((hw->pinState & 2) >> 1) << hw->rtc.bitsRead;
} else { } else {
if (hw->p2) { if (hw->pinState & 4) {
// GPIO direction should always != reading // GPIO direction should always != reading
if (hw->dir1) { if (hw->direction & 2) {
if (RTCCommandDataIsReading(hw->rtc.command)) { if (RTCCommandDataIsReading(hw->rtc.command)) {
GBALog(hw->p, GBA_LOG_GAME_ERROR, "Attempting to write to RTC while in read mode"); GBALog(hw->p, GBA_LOG_GAME_ERROR, "Attempting to write to RTC while in read mode");
} }
@ -292,7 +292,7 @@ void _gyroReadPins(struct GBACartridgeHardware* hw) {
return; return;
} }
if (hw->p0) { if (hw->pinState & 1) {
if (gyro->sample) { if (gyro->sample) {
gyro->sample(gyro); gyro->sample(gyro);
} }
@ -302,14 +302,14 @@ void _gyroReadPins(struct GBACartridgeHardware* hw) {
hw->gyroSample = (sample >> 21) + 0x6C0; // Crop off an extra bit so that we can't go negative hw->gyroSample = (sample >> 21) + 0x6C0; // Crop off an extra bit so that we can't go negative
} }
if (hw->gyroEdge && !hw->p1) { if (hw->gyroEdge && !(hw->pinState & 2)) {
// Write bit on falling edge // Write bit on falling edge
unsigned bit = hw->gyroSample >> 15; unsigned bit = hw->gyroSample >> 15;
hw->gyroSample <<= 1; hw->gyroSample <<= 1;
_outputPins(hw, bit << 2); _outputPins(hw, bit << 2);
} }
hw->gyroEdge = hw->p1; hw->gyroEdge = !!(hw->pinState & 2);
} }
// == Rumble // == Rumble
@ -324,7 +324,7 @@ void _rumbleReadPins(struct GBACartridgeHardware* hw) {
return; return;
} }
rumble->setRumble(rumble, hw->p3); rumble->setRumble(rumble, !!(hw->pinState & 8));
} }
// == Light sensor // == Light sensor
@ -337,11 +337,11 @@ void GBAHardwareInitLight(struct GBACartridgeHardware* hw) {
} }
void _lightReadPins(struct GBACartridgeHardware* hw) { void _lightReadPins(struct GBACartridgeHardware* hw) {
if (hw->p2) { if (hw->pinState & 4) {
// Boktai chip select // Boktai chip select
return; return;
} }
if (hw->p1) { if (hw->pinState & 2) {
struct GBALuminanceSource* lux = hw->p->luminanceSource; struct GBALuminanceSource* lux = hw->p->luminanceSource;
GBALog(hw->p, GBA_LOG_DEBUG, "[SOLAR] Got reset"); GBALog(hw->p, GBA_LOG_DEBUG, "[SOLAR] Got reset");
hw->lightCounter = 0; hw->lightCounter = 0;
@ -352,10 +352,10 @@ void _lightReadPins(struct GBACartridgeHardware* hw) {
hw->lightSample = 0xFF; hw->lightSample = 0xFF;
} }
} }
if (hw->p0 && hw->lightEdge) { if ((hw->pinState & 1) && hw->lightEdge) {
++hw->lightCounter; ++hw->lightCounter;
} }
hw->lightEdge = !hw->p0; hw->lightEdge = !(hw->pinState & 1);
bool sendBit = hw->lightCounter >= hw->lightSample; bool sendBit = hw->lightCounter >= hw->lightSample;
_outputPins(hw, sendBit << 3); _outputPins(hw, sendBit << 3);

View File

@ -87,31 +87,16 @@ struct GBARumble {
void (*setRumble)(struct GBARumble*, int enable); void (*setRumble)(struct GBARumble*, int enable);
}; };
DECL_BITFIELD(GPIOPin, uint16_t);
struct GBACartridgeHardware { struct GBACartridgeHardware {
struct GBA* p; struct GBA* p;
int devices; int devices;
enum GPIODirection readWrite; enum GPIODirection readWrite;
uint16_t* gpioBase; uint16_t* gpioBase;
union { uint16_t pinState;
struct { uint16_t direction;
unsigned p0 : 1;
unsigned p1 : 1;
unsigned p2 : 1;
unsigned p3 : 1;
};
uint16_t pinState;
};
union {
struct {
unsigned dir0 : 1;
unsigned dir1 : 1;
unsigned dir2 : 1;
unsigned dir3 : 1;
};
uint16_t direction;
};
struct GBARTC rtc; struct GBARTC rtc;