Cube64-DX - Ameliored GC controller to N64 adapter.

Discussion in 'Nintendo Game Development' started by DarthCloud, Mar 29, 2011.

  1. APE

    APE Site Supporter 2015

    Joined:
    Dec 5, 2005
    Messages:
    6,416
    Likes Received:
    138
    I wouldn't mind building these but every time someone says "PIC" I re-realize I don't have any programmers and get all Sad Panda-y.
     
  2. link83

    link83 Enthusiastic Member

    Joined:
    Mar 22, 2008
    Messages:
    526
    Likes Received:
    8
    As far as I understand it, although the data is 8bits for each axis and could theoretically give 256 steps (-128 to 127) the actual analog sticks resolution is only 168 steps :rolleyes: Its discussed in this thread:-
    http://nfggames.com/forum2/index.php?topic=3574.0

    168 steps seems to be the upper limit, theres a video on youtube by micro which shows the N64 analog sticks resolution in real time:-
    http://www.youtube.com/watch?v=sGbzKzpL9gY

    If you try and use 256 steps (eg 1:1) the controls in certain games mess up, like Blast Corps as you can hopefully see in the above video.

    In the thread I linked above micro used the following equation to get 168 steps from 256 steps:-

    256*4=1024
    1024*21/128=168 steps

    There is also one more thing I recently noticed which confirms micro's discovery. I thought that if 168 steps is the actual N64 analog sticks resolution then surely emulator authors have to take this into account...and in fact they do! If you load up Project64 with the N-Rage input plugin and select 'Configure Controller Plugin' then you can see that the default analog sticks range is set to 66%, and considering that most analog sticks have a resolution of 256 steps you can work out that 66% of 256 equals 168.96 steps - almost exactly what micro said was the upper limit.

    I really appreciate your hard work DarthCloud, cant wait to try using a Wavebird on the N64 :)
     
    Last edited: Mar 31, 2011
  3. DarthCloud

    DarthCloud Fiery Member

    Joined:
    Dec 26, 2007
    Messages:
    874
    Likes Received:
    14
    Thank for the information!!!

    I tried Turok 1 and yes the adapter does suffer from this bug.

    So bug open, will likely fix this tonight!

    And Blast Corps ordered ;)
     
  4. link83

    link83 Enthusiastic Member

    Joined:
    Mar 22, 2008
    Messages:
    526
    Likes Received:
    8
    Glad I could help :)

    I should mention that I added the first line of the equation I showed, since I think micro's code actually reads 1024 steps directly from the replacement analog sticks potentiometer - but of course thats not possible for this since the GameCube data only gives you 256 steps. There might be an even shorter equation to give 168 steps from 256 steps? :confused:
    <EDIT> In fact you could use the following equation instead:-

    256*21/32=168 steps

    Dont know why I didnt think of that before! I'm not that great at maths, so there still might be an even shorter/better way?

    Also, I dont see this mentioned a lot, but there is plenty of really interesting/useful information in Nintendo's patents, for instance here are some patents for the N64 controller, and on page 20 of the first link it shows the N64 controller data layout:-
    http://www.google.com/patents?id=XjoYAAAAEBAJ&printsec=abstract&zoom=4
    http://www.google.com/patents?id=jIEDAAAAEBAJ&printsec=abstract&zoom=4
    http://www.google.com/patents?id=mVgHAAAAEBAJ&printsec=abstract&zoom=4
    http://www.google.com/patents?id=bhQIAAAAEBAJ&printsec=abstract&zoom=4
    http://www.google.com/patents?id=7wcLAAAAEBAJ&printsec=abstract&zoom=4

    N64 Analog Stick:-
    http://www.google.com/patents?id=NH4WAAAAEBAJ&printsec=abstract&zoom=4
    http://www.google.com/patents?id=rVUIAAAAEBAJ&printsec=abstract&zoom=4

    N64 Controller Pak:-
    http://www.google.com/patents?id=gqsYAAAAEBAJ&printsec=abstract&zoom=4
    http://www.google.com/patents?id=GW0FAAAAEBAJ&printsec=abstract&zoom=4

    N64 Rumble Pak:-
    http://www.google.com/patents?id=4rwQAAAAEBAJ&printsec=abstract&zoom=4

    Some info about the GameCube Controller interface?:-
    http://www.google.com/patents?id=VH4QAAAAEBAJ&printsec=abstract&zoom=4

    GameCube Wavebird Controller:-
    http://www.google.com/patents?id=sYUUAAAAEBAJ&printsec=abstract&zoom=4

    There are many more patents available, and many have different/extra information, so it might be worth searching through google patents?
     
    Last edited: Mar 31, 2011
  5. DarthCloud

    DarthCloud Fiery Member

    Joined:
    Dec 26, 2007
    Messages:
    874
    Likes Received:
    14
    Keep it mind I must implement this on a micro with limited instruction, no multiplication, no divide, not even a proper shift left/right instruction. ;)

    I will also need to work on 16bit on a 8bit micro.

    It will look something like this

    (GC_Value*16+GC_Value*4+GC_Value) / 32

    Why this way? Cause multiplying and dividing with nice binary number allow to only shift the number to the left to multiply and shift then to the right to divide.

    divide 0b0100 by 2? shift right => 0b0010
    multiply 0b0100 by 2? shift left => 0b1000

    Since the pic only have a rotation command that put back to the LSB the bit kick out of the MSB I will need to used some mask to clear it. And since I need to work on 16bit I will need to copy the kick out bit of the LSByte to the first bit of the MSByte.

    I already see the headache coming ;)
     
  6. link83

    link83 Enthusiastic Member

    Joined:
    Mar 22, 2008
    Messages:
    526
    Likes Received:
    8
    I see, so will you have to use 160 steps instead of 168 steps?

    Good luck with the coding :nod:
     
  7. DarthCloud

    DarthCloud Fiery Member

    Joined:
    Dec 26, 2007
    Messages:
    874
    Likes Received:
    14
    No I will still get a resolution of -84 to 83 (168 step)
     
  8. link83

    link83 Enthusiastic Member

    Joined:
    Mar 22, 2008
    Messages:
    526
    Likes Received:
    8
    Oh good, I just thought when I saw this equation:-
    That it would only give 160 steps :redface:

    I look forward to building the adaptor :thumbsup:
     
  9. DarthCloud

    DarthCloud Fiery Member

    Joined:
    Dec 26, 2007
    Messages:
    874
    Likes Received:
    14
    Finaly fixed it, but it was a bit harder since the GameCube too do not used the full 8bit range, it use only ~[24, 232].

    I must admit this quite challenged my ASM writing skill ;) It's working great! Games like Cruis'n USA that was very sensitive with the adapter feel like normal with this fix :).

    I guess the code could be optimise, but I don't see how currently ;) anyway it's working.

     
    Last edited: Apr 2, 2011
  10. derekb

    derekb Well Known Member

    Joined:
    Jan 7, 2009
    Messages:
    1,964
    Likes Received:
    44
    I look forward to link83 building me an adapter...... ;)
     
  11. link83

    link83 Enthusiastic Member

    Joined:
    Mar 22, 2008
    Messages:
    526
    Likes Received:
    8
    Great work DarthCloud :)

    Wow, how interesting! I wonder why nobody realised this before?

    I just have a few questions if you dont mind:-
    - Did you test the analog stick range on multiple GameCube controllers? (Just in case one is worn out)
    - Is it just a coincidence that 24+232=256? (Maybe 24 is in the 'deadzone' which can vary from controller to controller?)
    - Is the GameCube analog sticks 208 step range caused by the octagonal restrictor plate?
    - Do all controller analog sticks not allow the full range? (Wii, PlayStation, Xbox, etc) :confused:

    [EDIT] I just found this site:-
    http://wiki.dolphin-emulator.com/index.php?title=GameCube_pad
    It seems to confirm that the 24 reading is within the GameCube analog sticks deadzone, so perhaps it is important to keep all 256 steps, otherwise some third party GameCube controllers might malfunction?
    Also N64 analog stick should have similar deadzone area according to the patents, so using 256 steps might give it a more accurate feel? (Both should have deadzone area of 0-15% where no movement will occur)

    Also just thought you might want to know in the code you quoted:-
    I think it should be [-84, 83] so that it equals 168 including the zero?

    Lastly, is there any chance the google code page could have the ASM/HEX file as a direct download on the downloads page?:-
    http://code.google.com/p/cube64-dx/downloads/list
    Just thought it might make it easier.

    Sorry but I am really busy at the moment, I havent even got time to build one for myself at the second :DOH: Plus its going to take a while for me to get all the parts together (PIC, extension cables, etc)
     
    Last edited: Apr 2, 2011
  12. derekb

    derekb Well Known Member

    Joined:
    Jan 7, 2009
    Messages:
    1,964
    Likes Received:
    44
    :(
     
    Last edited: Apr 2, 2011
  13. DarthCloud

    DarthCloud Fiery Member

    Joined:
    Dec 26, 2007
    Messages:
    874
    Likes Received:
    14
    Since it's easy to see while sniffing with a LA I guess no one bothered to document this.

    24 & 232 are the highest value I've read. The adapter do compensate allready if the joystick do not center at 0x80 by adding an offset. Game will not seak for exact value anyway, they check if you are between a range to determine speed.. etc...

    No coincidence 24 is the highest value I saw and yes it may change between controller, but again the sitck calibration compensate for this anyway.

    Joystick are just variable resistor so they have an infinite range value. So what matter is the ADC used to know the resolution. If the plastic block the stick then yes you might not reach the biggest value. But again it don'T matter because games use a range which take into consideration the octagonal shape.

    That's likely the case

    If those controller don't include the dead zone then those controller might create problem similar to the one the adapter is actually creating in Blast Corps. Btw, if a controller is not licensed by nintendo I don't care if it work or not ;) :)

    But keeping the whole gc range is what I've done first but it's was making it impossible to reach max speed once translated to n64. If the GC never reach 256, and you map 256 as 168 for the n64.. then you can never reach max value on the n64...

    Too feel like a real controller you must used the real range value otherwise you get the feeling that the stick is too sensitive.
    This was just an aproximation

    Yes will add this once the how to done.
     
    Last edited: Apr 2, 2011
  14. sanni

    sanni Intrepid Member

    Joined:
    May 30, 2008
    Messages:
    653
    Likes Received:
    77
    Will this run on Atmega8?
    Since I can't find a cheap and easy to build pic programmer :(
     
  15. DarthCloud

    DarthCloud Fiery Member

    Joined:
    Dec 26, 2007
    Messages:
    874
    Likes Received:
    14
    No, PIC12F683 only for all feature and also 12F629/18F84A with reduced feature set.

    Don't waste time building a programmer get a cheap JDM prorgammer on ebay.

    And use WinPic800 as software to program.
     
  16. Annoying_one

    Annoying_one Peppy Member

    Joined:
    Dec 24, 2006
    Messages:
    338
    Likes Received:
    9
    eabay has some 10-15 dollar programmers with one free PIC12F683
     
  17. DarthCloud

    DarthCloud Fiery Member

    Joined:
    Dec 26, 2007
    Messages:
    874
    Likes Received:
    14
    Found some bugs today in my Wavebird implementation. Fixing will need some big change.

    http://code.google.com/p/cube64-dx/issues/detail?id=8

     
  18. Nully

    Nully Dauntless Member

    Joined:
    Nov 23, 2010
    Messages:
    738
    Likes Received:
    102
    Any news on that tutorial, man?
     
  19. DarthCloud

    DarthCloud Fiery Member

    Joined:
    Dec 26, 2007
    Messages:
    874
    Likes Received:
    14
    Pictures taken, but I prefer fixing the Wavebird init bug before doing the tuto. I also want to wait receive my BlastCorps cart to make sure the joystick fix work well.

    If you look at the Wiki section on the project page I already uploaded some Tutorial. Only the one about building the adapter is missing.

    I need to update schematic too. Same thing but with 12F683 shown.
     
    Last edited: Apr 4, 2011
  20. da66en

    da66en Newly Registered

    Joined:
    Apr 4, 2011
    Messages:
    3
    Likes Received:
    0
    Have you measured how much current the rumble on the GCN controller takes?

    How much current can you draw from N64's 3.3V line? Has anyone tried pushing that yet?
     
sonicdude10
Draft saved Draft deleted
Insert every image as a...
  1.  0%

Share This Page