NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode


SubjectCan someone please answer a joypad question? new  
Posted by777Nes
Posted on3/15/02 8:11 PM
From IP152.30.110.194  



I'm at my wits end with input. I've got mappers 0, 1, 2, 3, and 9 in my emu, but I can't get any of the joysticks to work. I can't ever test these games because, I can't ever hit start. I've been working on this for days and I'm tired of watching in game demos to see if some "functionality" is working (that is if the game provides an in game demo).

I would have thought that getting basic player 1 input would have been the trivial part of my emu. This is how I'm doing input. Please let me know if you see any problems with this....

I have 8 boolean variables. (one for each of the 8 buttons on joypad 1)
These are called A_Down, B_Down, Start_Down, etc.......

After I refresh my screen, I check for input from the keyboard. If for instance, the number "2" was pressed, I set "B_Down = true". I follow this logic for all 8 buttons.

I have a counter in my cpu core that increments at each read of 0x4016. When this counter hits "8", I reset it to 0.

In my cpu core, if I get a read from 0x4016, I check the value of the above counter. If the value is a "0" (i.e. first read from 0x4016), and A_Down = true, then I retrun 0x41, otherwise I return 0x40. Then I increment the counter so that the next 0x4016 access reads the state of button "B". And so on, and so on.......

I don't do anything with writes to 0x4016 (the whole 0, 1 strobing business). Should I be? I've noticed that nearly all games write 0 and then 1 to 4016, then they do 8 consecutive reads from 4016....then write 0, 1, 8 more reads...etc...

This approach works for Baltron, Golf, Galaga, and Starforce. The other 300 games that work on my emu do nothing with this input approach.
How does the nes even know the joypad is connected? Yoshi's doc has like 24 reads where read 17 or something is whether joypad 1 is connected or not...I tried this approach, but it still didn't work...

Am I doing it all wrong? How did you guys do input in your emu's?




SubjectRe: Can someone please answer a joypad question? new  
Posted byzero soul
Posted on3/15/02 10:03 PM



try returning just 0x00 if the button is not pressed and 0x01 if it is. games may expect all but the lowest bit to be clear; if they use the zero flag to test if a button is pressed (for example:

 LDA A_BUTTON_READ
BEQ BUTTON_NOT_PRESSED
), then using 0x40/0x41 will screw it up. (because the zero flag will always be reset if either value is LDA'd).
also, games that shift data to keep all the button presses in one byte (eg., they load the a-button read, ASL A, ORA $4016 to get the b-button read, etc) will be screwed up if one bit is always set.

and why do you return 0x40/0x41 anyway? the other bits are only used for the light gun thing. yes, one bit is set if the trigger is released, and reset if the trigger is pulled, but the only games that would actually check this are games that are expecting you to use the light gun. all other games will expect- and rightfully so- all but the low bit to always be 0.

ideally, games should LDA $4016 and then do AND #$01, but not all games do. I don't do it in *my* demos; I just read it and store it as-is.

and about the 'strobing' business: if nothing else, you should reset the counter to zero after a game strobes the joystick, although it sounds like, from your description, that games will always do the full 8 reads. but still.


...just another vision... Studios


SubjectRe: Can someone please answer a joypad question? new  
Posted by777Nes
Posted on3/15/02 11:25 PM
From IP152.30.110.194  



I use 0x41 and 0x40 becuase I read in Marats doc that bit 6 should always have a 1. I reset my counter on a full strobe, and even tried flip flopping return values...but to no avail.....

Maybe there is some bug in my emu that's stopping all this....All my games can be divided into 3 classes.

Games that handle input properly (about 4 games)
Games that seem to go haywire when I load them (like I'm pressing start constantly...even though I havn't pressed any keys yet) (maybe 20 games)

Games that do nothing at the title screen but in game demos (300 games)

Input on the "RGB" demo won't work either..
Do you know any demo's that I can use to test my input (other than RGB or Sokoban) The cart.nes always fails on the PPU RAM chack so I never get past that screen (where there are joystick tests).




SubjectRe: Can someone please answer a joypad question?  
Posted bymcmartin
Posted on3/16/02 04:41 AM
From IP12.234.29.87  



I have two NES programs that take input up at http://hkn.berkeley.edu/~mcmartin/retro/ - tutor.nes reads up, down, and A, while Galaxy Patrol checks left, right, select, and start, at various points. The ship in Galaxy Patrol is always moving left or right, though, so if you're trying to track "no buttons pressed" it won't help much.

(Galaxy Patrol isn't really "releasable" yet because the fuel balance is still off.)

-- Michael




SubjectRe: Can someone please answer a joypad question? new  
Posted by777Nes
Posted on3/16/02 06:03 AM
From IP152.30.110.194  



tutor.nes works great. My input is very responsive and smooth. I couldn't get galaxy.nes to work however. Button "A" is supposed to reverse direction of the ball? Up and down change velocity?




SubjectRe: Can someone please answer a joypad question? new  
Posted byzero soul
Posted on3/16/02 08:23 AM



"Games that seem to go haywire when I load them (like I'm pressing start constantly...even though I havn't pressed any keys yet)"

see? those games are probably the ones that are expecting bit 6 to never be set. they'll read the joystick input and store each press to a separate byte, and check it by loading it and using BNE or BEQ. with your system, whether or not start is pressed, the game will always interpret it as pressed because it's checking to see if it's zero or not; if start isn't pressed, it'll wind up checking 0x40, which is not zero, so it assumes it's pressed.

I haven't read any documents that say so-and-so byte should *always* be set when reading $4016. I still think you should at least try returning 0x00/0x01 instead of 0x40/0x41. I'm willing to bet that'll solve a lot of your problems.


...just another vision... Studios


SubjectRe: Can someone please answer a joypad question? new  
Posted byJsr
Posted on3/16/02 11:08 PM
From IP195.100.248.183  



I am returning $41 for button pressed and $40 for no button in
my emulator, and I have never met an input problem.

Could you maybe tell me what games that don't work, so I can test.
But anyway, it should work.




SubjectRe: Can someone please answer a joypad question? new  
Posted bymcmartin
Posted on3/17/02 04:44 AM
From IP12.234.29.87  



Galaxy Patrol uses select and start on the main menu, then just left and right in game to set your direction. You always are moving, though, so it's not that your controller never lets up.

You may wish to grab an emulator like FCE Ultra or NESten and compare results, if you're unsure of fine points. Not a big deal for something like this, but




SubjectI fixed the problem... new  
Posted by777Nes
Posted on3/18/02 7:36 PM
From IP152.30.110.194  



Thankx guys..I fixed my problem. It was in my ROL and ROR functios. I wasn't saving the Carry bit before setting the new Carry value. Minor error, but it has fixed the problems in all but 2 games.

Dr Mario and Tetris. These will work if I return 0 for button pressed and 1 for not pressed (reversed values). The controls work then but they are reversed...i.e left moves the blocks right...etc...




Previous ThreadView All ThreadsNext Thread*Show in Threaded Mode
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo