Skip to content

Commit

Permalink
sgb: revisit JOYP handling (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinacker committed Feb 10, 2020
1 parent b769e9d commit c7a3bac
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
18 changes: 13 additions & 5 deletions supergameboy/interface/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,19 @@ void SuperGameBoy::joyp_write(bool p15, bool p14) {
//===============

if(p15 == 1 && p14 == 1) {
if(joyp_lock == 0) {
joyp_lock = 1;
if(joyp14lock == 0) {
joyp14lock = 1;
joyp_id = (joyp_id + 1) & mmio.mlt_req;
}
}

if(p14 == 1 && p15 == 0) joyp_lock ^= 1;
if(p15 == 0) {
if(joyp15lock == 1) {
joyp14lock ^= 1;
}
}

joyp15lock = p15;

//===============
//packet handling
Expand Down Expand Up @@ -217,7 +223,8 @@ void SuperGameBoy::serialize(nall::serializer &s) {
s.integer(packetsize);

s.integer(joyp_id);
s.integer(joyp_lock);
s.integer(joyp15lock);
s.integer(joyp14lock);
s.integer(pulselock);
s.integer(strobelock);
s.integer(packetlock);
Expand Down Expand Up @@ -350,7 +357,8 @@ void SuperGameBoy::mmio_reset() {
memset(vram, 0, 320*4);

joyp_id = 0;
joyp_lock = 0;
joyp15lock = 0;
joyp14lock = 0;
pulselock = true;
}

Expand Down
3 changes: 2 additions & 1 deletion supergameboy/interface/interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class SuperGameBoy : public gambatte::InputGetter, public gambatte::DebugHandler
unsigned packetsize;

unsigned joyp_id;
bool joyp_lock;
bool joyp15lock;
bool joyp14lock;
bool pulselock;
bool strobelock;
bool packetlock;
Expand Down
2 changes: 1 addition & 1 deletion supergameboy/libgambatte/src/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,8 +719,8 @@ void Memory::nontrivial_ff_write(unsigned const p, unsigned data, unsigned long

switch (p & 0xFF) {
case 0x00:
supergameboy.joyp_write(data & 0x20, data & 0x10);
if ((data ^ ioamhram_[0x100]) & 0x30) {
supergameboy.joyp_write(data & 0x20, data & 0x10);
ioamhram_[0x100] = (ioamhram_[0x100] & ~0x30u) | (data & 0x30);
updateInput();
}
Expand Down

0 comments on commit c7a3bac

Please sign in to comment.