Skip to content

Commit 78f0b54

Browse files
committed
FIX: SGB packet bits being written directly instead of through a byte buffer. Recently discovered quirk.
gbdev/pandocs#509
1 parent 1a5cadb commit 78f0b54

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

Diff for: Core/SNES/Coprocessors/SGB/SuperGameboy.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -163,22 +163,27 @@ void SuperGameboy::ProcessInputPortWrite(uint8_t value)
163163
LogPacket();
164164
}
165165
} else {
166-
_packetData[_packetByte] &= ~(1 << _packetBit);
166+
167+
_packetByteBuffer &= ~(1 << _packetBit);
167168
}
168169
_packetBit++;
169170
if(_packetBit == 8) {
171+
_packetData[_packetByte] = _packetByteBuffer;
170172
_packetBit = 0;
171-
_packetByte++;
173+
_packetByte++;
172174
}
175+
176+
173177
} else if(value == 0x10) {
174178
//1 bit
175179
if(_packetByte >= 16) {
176180
//Invalid bit
177181
_listeningForPacket = false;
178182
} else {
179-
_packetData[_packetByte] |= (1 << _packetBit);
183+
_packetByteBuffer |= (1 << _packetBit);
180184
_packetBit++;
181185
if(_packetBit == 8) {
186+
_packetData[_packetByte] = _packetByteBuffer;
182187
_packetBit = 0;
183188
_packetByte++;
184189
}

Diff for: Core/SNES/Coprocessors/SGB/SuperGameboy.h

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class SuperGameboy : public BaseCoprocessor, public IAudioProvider
4040
uint64_t _inputWriteClock = 0;
4141
uint8_t _inputValue = 0;
4242
uint8_t _packetData[16] = {};
43+
uint8_t _packetByteBuffer = 0x00;
4344
uint8_t _packetByte = 0;
4445
uint8_t _packetBit = 0;
4546

0 commit comments

Comments
 (0)