It is currently Wed Oct 18, 2017 10:40 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: Sun Jun 21, 2015 10:21 pm 
Offline

Joined: Sun Jun 21, 2015 10:18 pm
Posts: 1
Hey guys,

I just need some general information about how the NES communicates with the standard controllers.

Are the gamepads polled in most games (i.e. within the gameloop) or do they generate an interrupt to the CPU (like the V-blanking period)?

I have been looking at various spec sheets, and they explain that the data from the gamepads can be read from by strobing addresses $4016 and $4017. It would seem that doing this, they could be read from at any time, suggesting that they are polled. However, this would make periodic communication between the gamepads and the CPU very unlikely.


Top
 Profile  
 
PostPosted: Sun Jun 21, 2015 10:39 pm 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3943
Only polled. The joypad can't generate any interrupts at all.
Usually, the joypad's full state is read once per frame.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
PostPosted: Sun Jun 21, 2015 10:48 pm 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19099
Location: NE Indiana, USA (NTSC)
NES gamepads are polled. It's essentially bit-banged SPI through a couple buffers on the mainboard.

The only connection between interrupts and NES gamepads is that some games may use an interrupt elsewhere in the system to trigger polling. This is almost always NMI, which the PPU asserts every vertical blank (60.1 or 50 times a second depending on region). But it can also be the APU timer IRQ (a 60 Hz time base possibly intended for arcade use without a PPU), or even the DMC IRQ (an abuse of the sampled sound playback hardware as a crude programmable interval timer for sub-frame events).

Super NES gamepads can be polled the same way, but they're usually read with the auto-reader hardware on the S-CPU die. Auto-reading happens in the background every vertical blank and takes a couple scanlines of time (one scanline is roughly 64 microseconds) to read all 16 bits (12 buttons and one identification nibble) from both controllers.


Top
 Profile  
 
PostPosted: Mon Jun 22, 2015 8:14 am 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3943
While joypad polling could be driven by any interrupt source, in practice it is done by either the game's NMI handler, or by the regular frame-by-frame execution of the game logic. Some games don't even poll the joypad if the player has no control during a cutscene or something, or during the wait for a copyright screen to go away.
If the game's NMI handler does the joypad polling, there is the possibility of race conditions. For race conditions to happen, the code must be running slower than one frame (you'd see slowdown), and the game code must look at the stored joypad state both early and late in the game logic code.

Also, the DMC channel can corrupt joypad input, so games which use it must read the joystick twice and see if it matches.

APU frame IRQ is only used by 3 NES games I know of, and that's to drive the music engine of Dragon Quest 1, 2, and Door Door. The US versions of Dragon Quest changed it to use the NMI instead. For almost all other games, APU frame IRQs are an unwanted glitch that can mess with a game. For example, Ironsword and Time Lord mess up/crash if any frame IRQs ever happen. Ironsword relies on dummy reads to disable frame IRQs, and Time Lord relies on the powerup state starting at scanline 0, making those games good test cases for obscure behavior.

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
PostPosted: Fri Nov 11, 2016 6:14 am 
Offline

Joined: Fri Nov 11, 2016 6:12 am
Posts: 1
NES gamepads were polled.


Top
 Profile  
 
PostPosted: Fri Nov 11, 2016 7:05 am 
Offline

Joined: Sun Mar 19, 2006 9:44 pm
Posts: 913
Location: Japan
We've got a sophisticated spambot here!

_________________
http://www.chrismcovell.com


Top
 Profile  
 
PostPosted: Fri Nov 11, 2016 2:57 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7230
Location: Chexbres, VD, Switzerland
Yep, it manages to say something on topic that happens to be true. Impressive. And scary. Probably it's a indian guy paid to spam rather than a bot, or something like that.


Top
 Profile  
 
PostPosted: Fri Nov 11, 2016 5:54 pm 
Offline
Formerly ~J-@D!~
User avatar

Joined: Sun Mar 12, 2006 12:36 am
Posts: 445
Location: Rive nord de Montréal
Am I the sophisticated spambot? My post disappeared!


Top
 Profile  
 
PostPosted: Fri Nov 11, 2016 8:26 pm 
Offline
Site Admin
User avatar

Joined: Mon Sep 20, 2004 6:04 am
Posts: 3470
Location: Indianapolis
After banning the account, I immediately regret the decision. Well maybe not, too much danger of them mass-sending PMs or something. A while back I imagined that spammers might actually learn a bit of NES programming so they can post spam with a legit account. It's kind-of happening!


Top
 Profile  
 
PostPosted: Fri Nov 11, 2016 8:33 pm 
Offline

Joined: Mon Sep 27, 2004 2:57 pm
Posts: 1248
NES gamepads are polled and read serially, giving them a lot of flexibility. There are pretty creative ways to mitigate DMC glitches discussed on this forum, but first, take a look at these totally sweet watches!


Top
 Profile  
 
PostPosted: Sat Nov 12, 2016 12:11 am 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3943
Because copy-pasting the first sentence from the second most recent post but replacing words with past tense is advanced spamming?

_________________
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!


Top
 Profile  
 
PostPosted: Sat Nov 12, 2016 12:37 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
(We're now massively off-topic; normally this subject is something discussed under the moderators board, so apologies to anyone reading the thread wanting to know about the NES controller protocol)

Memblers wrote:
After banning the account, I immediately regret the decision. Well maybe not, too much danger of them mass-sending PMs or something. A while back I imagined that spammers might actually learn a bit of NES programming so they can post spam with a legit account. It's kind-of happening!

The more we talk about the tactics/what we key off of/what we notice, the more they learn. This is why I prefer not to talk about the problem or methodologies or *anything* about it on the forum itself -- to think they don't read it is ignorant. :)

As I established years ago, the problematics are the outfits (companies usually in Pakistan, India, Russia, and the Asias) operated by human beings making accounts (sometimes through tools) and then registering + posting manually, let things sit for a little bit (sometimes days), then unleash a flurry of crap. Humans can (will) eventually figure out the signup questions, so it's kind of a cat vs. mouse game; the spammers get through, the forum changes things, months go by and it happens again, and the cycle continues.

There's no 100% failsafe methodology other than making the forum entirely private, or implementing (this would have to be coded; AFAIK there isn't a phpBB extension for this) something similar like what's on the wiki, re: reading is available to everyone, but signing up + editing isn't available until manually approved. (The problem with manual approval methodologies is that if a bot or automated software begins to spam the hell out of account creation, the person reviewing/approving has to sift through them all; i.e. the same problem happens (in effect) but the persons affected are only those who have to review created accounts for approval. Let's just say that if I woke up one morning to find 700 Emails consisting of account creation approvals/reviews, I'd say "screw this" ;-) ).

An alternate approach: consider asking what the romhacking.net forum folks (mods/admins) do about the problem. The justification being: ask what they do and share advice/approaches.


Top
 Profile  
 
PostPosted: Sat Nov 12, 2016 6:48 am 
Offline
Formerly ~J-@D!~
User avatar

Joined: Sun Mar 12, 2006 12:36 am
Posts: 445
Location: Rive nord de Montréal
Dwedit wrote:
Because copy-pasting the first sentence from the second most recent post but replacing words with past tense is advanced spamming?

I was being pedantic and referred to the thread that does the controller read synchronized with the APU to avoid having the read being corrupted by the DMC. Nothing like you describe.


Top
 Profile  
 
PostPosted: Sat Nov 12, 2016 9:52 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2962
Location: Tampere, Finland
If Jarhmander's post has been deleted, that was definitely a moderator making a mistake (or a glitch in the matrix). Whodunit?

_________________
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Sat Nov 12, 2016 9:59 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19099
Location: NE Indiana, USA (NTSC)
I apologize.

Now I'll make excuses as a means of brainstorming ways to learn from the mistake. If there are seven spam posts, and I have to delete them one at a time, I might occasionally end up deleting one too many. If I had my way, I'd open all the delete confirmation pages for all the spam posts in new tabs. But somehow only one confirmation token is allowed to be active per user session, which causes phpBB to cancel all other delete submissions as cross-site request forgery (CSRF) attempts.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group