Input: Reading the controller while the strobe signal is high should always return the state of button A

Fixed an edge case that occurred when setting strobe bit after reading $4016 once and then reading $4016 again
This commit is contained in:
Sour 2019-12-23 20:47:10 -05:00
parent 1d03eb7859
commit c3b1b3effc
12 changed files with 16 additions and 15 deletions

View file

@ -62,9 +62,9 @@ public:
uint8_t ReadRAM(uint16_t addr) override uint8_t ReadRAM(uint16_t addr) override
{ {
if(addr == 0x4016) { if(addr == 0x4016) {
StrobeProcessRead();
uint8_t output = (_stateBuffer & 0x01) << 1; uint8_t output = (_stateBuffer & 0x01) << 1;
_stateBuffer >>= 1; _stateBuffer >>= 1;
StrobeProcessRead();
return output; return output;
} else { } else {
return (IsLightFound() ? 0 : 0x08) | (IsPressed(BandaiHyperShot::ZapperButtons::Fire) ? 0x10 : 0x00); return (IsLightFound() ? 0 : 0x08) | (IsPressed(BandaiHyperShot::ZapperButtons::Fire) ? 0x10 : 0x00);

View file

@ -29,6 +29,7 @@ public:
uint8_t ReadRAM(uint16_t addr) override uint8_t ReadRAM(uint16_t addr) override
{ {
StrobeProcessRead();
uint8_t output = 0; uint8_t output = 0;
if(addr == 0x4016) { if(addr == 0x4016) {
output = _signature4016 & 0x01; output = _signature4016 & 0x01;
@ -37,7 +38,6 @@ public:
output = _signature4017 & 0x01; output = _signature4017 & 0x01;
_signature4017 >>= 1; _signature4017 >>= 1;
} }
StrobeProcessRead();
return output; return output;
} }

View file

@ -25,9 +25,9 @@ public:
{ {
uint8_t output = 0; uint8_t output = 0;
if(addr == 0x4016) { if(addr == 0x4016) {
StrobeProcessRead();
output = (_stateBuffer & 0x01) << 1; output = (_stateBuffer & 0x01) << 1;
_stateBuffer >>= 1; _stateBuffer >>= 1;
StrobeProcessRead();
} }
return output; return output;
} }

View file

@ -39,9 +39,9 @@ public:
uint8_t ReadRAM(uint16_t addr) override uint8_t ReadRAM(uint16_t addr) override
{ {
if(addr == 0x4017) { if(addr == 0x4017) {
StrobeProcessRead();
uint8_t value = (_stateBuffer & 0x01) << 1; uint8_t value = (_stateBuffer & 0x01) << 1;
_stateBuffer >>= 1; _stateBuffer >>= 1;
StrobeProcessRead();
return value; return value;
} }
return 0; return 0;

View file

@ -29,9 +29,9 @@ public:
{ {
uint8_t output = 0; uint8_t output = 0;
if(addr == 0x4016) { if(addr == 0x4016) {
StrobeProcessRead();
output = (_stateBuffer & 0x01) << 1; output = (_stateBuffer & 0x01) << 1;
_stateBuffer >>= 1; _stateBuffer >>= 1;
StrobeProcessRead();
} }
return output; return output;
} }

View file

@ -40,10 +40,10 @@ public:
uint8_t ReadRAM(uint16_t addr) override uint8_t ReadRAM(uint16_t addr) override
{ {
if(addr == 0x4017) { if(addr == 0x4017) {
StrobeProcessRead();
if(_readCount < 2) { if(_readCount < 2) {
uint8_t value = (_stateBuffer & 0x7) << 2; uint8_t value = (_stateBuffer & 0x7) << 2;
_stateBuffer >>= 3; _stateBuffer >>= 3;
StrobeProcessRead();
_readCount++; _readCount++;
return value; return value;
} else { } else {

View file

@ -61,14 +61,14 @@ public:
{ {
uint8_t output = 0; uint8_t output = 0;
if(IsCurrentPort(addr)) { if(IsCurrentPort(addr)) {
StrobeProcessRead();
output = ((_stateBufferH & 0x01) << 4) | ((_stateBufferL & 0x01) << 3); output = ((_stateBufferH & 0x01) << 4) | ((_stateBufferL & 0x01) << 3);
_stateBufferL >>= 1; _stateBufferL >>= 1;
_stateBufferH >>= 1; _stateBufferH >>= 1;
_stateBufferL |= 0x80; _stateBufferL |= 0x80;
_stateBufferH |= 0x80; _stateBufferH |= 0x80;
StrobeProcessRead();
} }
return output; return output;
} }

View file

@ -85,13 +85,13 @@ public:
uint8_t output = 0; uint8_t output = 0;
if(IsCurrentPort(addr)) { if(IsCurrentPort(addr)) {
StrobeProcessRead();
output = _stateBuffer & 0x01; output = _stateBuffer & 0x01;
_stateBuffer >>= 1; _stateBuffer >>= 1;
//"All subsequent reads will return D=1 on an authentic controller but may return D=0 on third party controllers." //"All subsequent reads will return D=1 on an authentic controller but may return D=0 on third party controllers."
_stateBuffer |= 0x8000; _stateBuffer |= 0x8000;
StrobeProcessRead();
} }
return output; return output;

View file

@ -49,6 +49,8 @@ public:
{ {
uint8_t output = 0; uint8_t output = 0;
if((addr == 0x4016 && (_port & 0x01) == 0) || (addr == 0x4017 && (_port & 0x01) == 1)) { if((addr == 0x4016 && (_port & 0x01) == 0) || (addr == 0x4017 && (_port & 0x01) == 1)) {
StrobeProcessRead();
if(_strobe) { if(_strobe) {
_sensitivity = (_sensitivity + 1) % 3; _sensitivity = (_sensitivity + 1) % 3;
} }
@ -58,7 +60,6 @@ public:
output <<= 1; output <<= 1;
} }
_stateBuffer <<= 1; _stateBuffer <<= 1;
StrobeProcessRead();
} }
return output; return output;
} }

View file

@ -111,6 +111,8 @@ public:
uint8_t output = 0; uint8_t output = 0;
if((addr == 0x4016 && (_port & 0x01) == 0) || (addr == 0x4017 && (_port & 0x01) == 1)) { if((addr == 0x4016 && (_port & 0x01) == 0) || (addr == 0x4017 && (_port & 0x01) == 1)) {
StrobeProcessRead();
output = _stateBuffer & 0x01; output = _stateBuffer & 0x01;
if(_port >= 2 && _console->GetSettings()->GetConsoleType() == ConsoleType::Famicom) { if(_port >= 2 && _console->GetSettings()->GetConsoleType() == ConsoleType::Famicom) {
//Famicom outputs P3 & P4 on bit 1 //Famicom outputs P3 & P4 on bit 1
@ -120,8 +122,6 @@ public:
//"All subsequent reads will return D=1 on an authentic controller but may return D=0 on third party controllers." //"All subsequent reads will return D=1 on an authentic controller but may return D=0 on third party controllers."
_stateBuffer |= 0x80000000; _stateBuffer |= 0x80000000;
StrobeProcessRead();
} }
if(addr == 0x4016 && IsPressed(StandardController::Buttons::Microphone)) { if(addr == 0x4016 && IsPressed(StandardController::Buttons::Microphone)) {

View file

@ -44,12 +44,12 @@ public:
{ {
uint8_t output = 0; uint8_t output = 0;
if((addr == 0x4016 && (_port & 0x01) == 0) || (addr == 0x4017 && (_port & 0x01) == 1)) { if((addr == 0x4016 && (_port & 0x01) == 0) || (addr == 0x4017 && (_port & 0x01) == 1)) {
StrobeProcessRead();
output = (_stateBuffer & 0x80) >> 7; output = (_stateBuffer & 0x80) >> 7;
if(_port >= 2) { if(_port >= 2) {
output <<= 1; output <<= 1;
} }
_stateBuffer <<= 1; _stateBuffer <<= 1;
StrobeProcessRead();
} }
return output; return output;
} }

View file

@ -27,9 +27,9 @@ public:
uint8_t ReadRAM(uint16_t addr) override uint8_t ReadRAM(uint16_t addr) override
{ {
if(IsCurrentPort(addr)) { if(IsCurrentPort(addr)) {
StrobeProcessRead();
uint8_t returnValue = _stateBuffer & 0x01; uint8_t returnValue = _stateBuffer & 0x01;
_stateBuffer >>= 1; _stateBuffer >>= 1;
StrobeProcessRead();
return returnValue; return returnValue;
} }