Skip to content

Commit

Permalink
FIX: SGB packet bits being written directly instead of through a byte…
Browse files Browse the repository at this point in the history
… buffer. Recently discovered quirk.

gbdev/pandocs#509
  • Loading branch information
binarycounter committed Nov 11, 2023
1 parent 1a5cadb commit 78f0b54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Core/SNES/Coprocessors/SGB/SuperGameboy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,27 @@ void SuperGameboy::ProcessInputPortWrite(uint8_t value)
LogPacket();
}
} else {
_packetData[_packetByte] &= ~(1 << _packetBit);

_packetByteBuffer &= ~(1 << _packetBit);
}
_packetBit++;
if(_packetBit == 8) {
_packetData[_packetByte] = _packetByteBuffer;
_packetBit = 0;
_packetByte++;
_packetByte++;
}


} else if(value == 0x10) {
//1 bit
if(_packetByte >= 16) {
//Invalid bit
_listeningForPacket = false;
} else {
_packetData[_packetByte] |= (1 << _packetBit);
_packetByteBuffer |= (1 << _packetBit);
_packetBit++;
if(_packetBit == 8) {
_packetData[_packetByte] = _packetByteBuffer;
_packetBit = 0;
_packetByte++;
}
Expand Down
1 change: 1 addition & 0 deletions Core/SNES/Coprocessors/SGB/SuperGameboy.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class SuperGameboy : public BaseCoprocessor, public IAudioProvider
uint64_t _inputWriteClock = 0;
uint8_t _inputValue = 0;
uint8_t _packetData[16] = {};
uint8_t _packetByteBuffer = 0x00;
uint8_t _packetByte = 0;
uint8_t _packetBit = 0;

Expand Down

0 comments on commit 78f0b54

Please sign in to comment.