Home | Forums | What's new | Resources | |
joypad polling |
patroclus02 - May 16, 2006 |
patroclus02 | May 16, 2006 | |||
That's what I do. I poll once per VBlank. BUT, when I detect a button pressed, I call a Wait for all button are release in a loop before going on. this is to get rid of repetitive button detection. I just want to detect once per button pressed. then you need to release the button and press again. This is the easier scheme I found... The only problem is what happends if the software is in the loop waiting for teh buttons to be realesed, and 50 new VBlank interrupt (PAL) come every second... It works well, though, but I wonder what happends if a new interrupt comes when we are already in a VBlank interrupt... do you know?? By the, the problem I mentioned is a Gens' bug. It works well in a real system (I tested it today). |
cgfm2 | May 17, 2006 | ||||
If you want to remove repetitive button presses, you need to keep track of the old and new button states and calculate the changed buttons between those states. I'm too lazy to do it in 68K asm but here's the "C" pseudocode: joy_old = joy_new; // save old state from last frame joy_new = poll_joypad(); // get new state joy_delta = (joy_new ^ joy_old) & joy_new; // calculate changed bits and keep only those that were just pressed You'd want to carry out the above sequence once per frame and examine joy_delta to get the newly pressed buttons (where the user wasn't pressing it last frame, but was pressing it now) and joy_new to get the currently pressed buttons (where the user is pressing them right now). If you are checking buttons in a short loop without V-Blank timing, call poll_joypad() before you enter the loop to initialize the variables. I'm just mentioning this because it took a while to figure out in a 68000 exception handler menu that I wrote. |
patroclus02 | May 17, 2006 | |||
Yes, I was thinking on making that. That is waht I do for more complex projects, I just wanted to make something easy for now, but it definitively is the best choice. By the way, do you know what happends if a nes VBlank int comes while running the last VBlank int handler?? |
cgfm2 | May 17, 2006 | ||||
Take a look at the 68000 programmer's manual, which explains all of this in detail in section 6.3.2. As long as you don't modify SR during the V-Blank routine, other level 4 interrupts will be ignored until RTE is executed. When the interrupt is accepted, SR is changed to $0400 to mask level 4 and lower interrupts. |