- 
                Notifications
    You must be signed in to change notification settings 
- Fork 176
Improve auto-joypad polling timing #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
51bf15a
              a60c9e4
              6e07142
              d8ae2aa
              45fa018
              e2d7b51
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -202,45 +202,54 @@ auto CPU::dmaEdge() -> void { | |
|  | ||
| //called every 128 clocks from inside the CPU::stepOnce() function | ||
| auto CPU::joypadEdge() -> void { | ||
| //it is not yet confirmed if polling can be stopped early and/or (re)started later | ||
| if(!io.autoJoypadPoll) return; | ||
|  | ||
| if(vcounter() == ppu.vdisp() && hcounter() >= 130 && hcounter() <= 256) { | ||
| if(vcounter() == ppu.vdisp() && (counter.cpu & 255) == 0 && hcounter() >= 130 && hcounter() <= 384) { | ||
| //begin new polling sequence | ||
| status.autoJoypadCounter = 0; | ||
| } | ||
| } else { | ||
| //stop after polling has been completed for this frame | ||
| if(status.autoJoypadCounter >= 33) return; | ||
|  | ||
| //stop after polling has been completed for this frame | ||
| if(status.autoJoypadCounter >= 33) return; | ||
| status.autoJoypadCounter++; | ||
| } | ||
|  | ||
| if(status.autoJoypadCounter == 0) { | ||
| //latch controller states on the first polling cycle | ||
| controllerPort1.device->latch(1); | ||
| controllerPort2.device->latch(1); | ||
| status.autoJoypadLatch = io.autoJoypadPoll; | ||
| controllerPort1.device->latch(status.autoJoypadLatch | status.cpuLatch); | ||
| controllerPort2.device->latch(status.autoJoypadLatch | status.cpuLatch); | ||
| if(io.autoJoypadPoll) { | ||
| //shift registers are cleared to zero at start of auto-joypad polling | ||
| io.joy1 = 0; | ||
| io.joy2 = 0; | ||
| io.joy3 = 0; | ||
| io.joy4 = 0; | ||
| } | ||
| } | ||
|  | ||
| if(status.autoJoypadCounter == 1) { | ||
| //release latch and begin reading on the second cycle | ||
| controllerPort1.device->latch(0); | ||
| controllerPort2.device->latch(0); | ||
| status.autoJoypadLatch = 0; | ||
| controllerPort1.device->latch(status.autoJoypadLatch | status.cpuLatch); | ||
| controllerPort2.device->latch(status.autoJoypadLatch | status.cpuLatch); | ||
| } | ||
|  | ||
| //shift registers are cleared to zero at start of auto-joypad polling | ||
| io.joy1 = 0; | ||
| io.joy2 = 0; | ||
| io.joy3 = 0; | ||
| io.joy4 = 0; | ||
| if(status.autoJoypadCounter != 1 && !io.autoJoypadPoll) { | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right that this seems peculiar but it does appear to be accurate. Without this condition the tests  The implication of this condition is that disabling auto-joypad polling during this one cycle has no effect, so it could for example be toggled off and toggled on again without affecting the auto-joypad polling sequence at all during this specific timing window. As far as I understand that's precisely what the blip-autojoy-timing-test intends to test: It waits until  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fiskbit and I noticed that temporary disabling ( 
 Quoting my notes from that day: 
 For the  | ||
| // if auto-joypad polling is disabled at this point skip the rest of the polling | ||
| status.autoJoypadCounter = 33; | ||
| return; | ||
| } | ||
|  | ||
| if(status.autoJoypadCounter >= 2 && !(status.autoJoypadCounter & 1)) { | ||
| if(status.autoJoypadCounter >= 2) { | ||
| //sixteen bits are shifted into joy{1-4}, one bit per 256 clocks | ||
| uint2 port0 = controllerPort1.device->data(); | ||
| uint2 port1 = controllerPort2.device->data(); | ||
|  | ||
| io.joy1 = io.joy1 << 1 | port0.bit(0); | ||
| io.joy2 = io.joy2 << 1 | port1.bit(0); | ||
| io.joy3 = io.joy3 << 1 | port0.bit(1); | ||
| io.joy4 = io.joy4 << 1 | port1.bit(1); | ||
| //the bits are read on one 128-clock cycle and written on the next | ||
| if ((status.autoJoypadCounter & 1) == 0) { | ||
| status.autoJoypadPort0 = controllerPort1.device->data(); | ||
| status.autoJoypadPort1 = controllerPort2.device->data(); | ||
| } else { | ||
| io.joy1 = io.joy1 << 1 | status.autoJoypadPort0.bit(0); | ||
| io.joy2 = io.joy2 << 1 | status.autoJoypadPort1.bit(0); | ||
| io.joy3 = io.joy3 << 1 | status.autoJoypadPort0.bit(1); | ||
| io.joy4 = io.joy4 << 1 | status.autoJoypadPort1.bit(1); | ||
| } | ||
| } | ||
|  | ||
| status.autoJoypadCounter++; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we change what's being serialised, we should also bump the serialisation version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, and that's one thing I was contemplating while making the serialization and struct changes. But I looked at the last time serialization was changed (34af95d) and the version wasn't bumped after that either. Should I just bump it to something like
115.1?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the previous idea was that the serialisation version only needed to be changed once per release, so if it had been changed since the previous release there was no need to change it again. Given releases are a lot further apart now, it seems prudent to change the number more regularly.
115.1seems like a good choice, yeah.