Hacking Gamecube to Classic Controller Converter 2 questions

qwertymodo

Well-Known Member
Member
Joined
Feb 1, 2010
Messages
827
Trophies
0
Age
34
Website
qwertymodo.com
XP
520
Country
United States
My idea involved not disabling interrupts at all. It would look something like this:

Replace
Code:
noInterrupts();
 
GCPad_send(cmd, 3);
GCPad_recv(raw_joy_data, 64);

with

Code:
do {
  GlobalFlagWasInterrupted = false;
  GCPad_send(cmd, 3);
  GCPad_recv(raw_joy_data, 64);
} while (GlobalFlagWasInterrupted == true);

And then add this line to all of your interrupt service routines:

Code:
EveryInterruptTriggeredFunction() {
  GlobalFlagWasInterrupted = true;
  //rest of function
}

That way, if the GC read gets interrupted, it just retries the read after the interrupt returns. This would allow interrupts to behave normally, as well as avoid garbage data being returned due to interrupted timing. Basically, rather than disabling interrupts, you simply delay the read until the interrupt has been serviced. Interrupts aren't sent from the Wiimote very often, so that shouldn't be a big deal.
 

qwertymodo

Well-Known Member
Member
Joined
Feb 1, 2010
Messages
827
Trophies
0
Age
34
Website
qwertymodo.com
XP
520
Country
United States
Just to reiterate and clarify, since I've had several people ask. Cost for the GC adapters is $25 each + shipping. I have parts for 25 and have started a reservation list for those 25. When I have the adapters built, I will contact those on the reservation list, and if they are not able to pay at that time, I will bump them to the end of the list (or perhaps to the start of the batch 2 list, I haven't decided). This is just so I can fund a second batch, if need be, as quickly as possible. I will almost be willing to guarantee that everyone who wishes to order one will be able to (basically, I'll keep doing it unless I get way more orders than expected and can't keep up with them... so far, that's not an issue, though it would be a nice problem to have :P). I will keep making them as long as people want to order them, so don't be too worried about it. Also, I currently have 3 people on the list, for a total of 4 of the adapters (someone ordered 2). If I don't sell all 25, none of this will really matter anyway... but yeah, just thought I'd put that here since people have been asking.
 
  • Like
Reactions: bezem

bootsector

Well-Known Member
Member
Joined
Oct 2, 2008
Messages
198
Trophies
0
XP
275
Country
Brazil
I might be overlooking something, but I don't see this working at all.

Wiimote talks to the extension using Fast I2C, which means a frequency of 400Khz. So yeah, interrupts are happening all the time and with a very high frequency!

With that in mind, and by looking at the code snippets you provided, there's nothing preventing that an interrupt happens in the middle of the GCPad_send and GCPad_recv functions, which are very time sensitive, leading to garbage data being read from the GC/N64 pads.

I really think the solution will be related to putting the slave in a state where the master simply waits for it indefnitely, without braking the bus, before disabling interrupts. But for that, we must find out if I2C interrupts must still be on so the master is aware of that state the slave is.

bootsector
 

qwertymodo

Well-Known Member
Member
Joined
Feb 1, 2010
Messages
827
Trophies
0
Age
34
Website
qwertymodo.com
XP
520
Country
United States
My point was doesn't matter if garbage is sent/received between the microcontroller and GC/N64 controller, so long as that garbage data isn't passed on to the Wiimote. So if you send/receive garbage (which would be indicated by the flag getting set during that time period, because the interrupt routines would set that flag), then try to send/receive from the GC/N64 again until you get a clean, uninterrupted read. Because of where that loop is placed, you don't affect the data that is actually sent to the Wiimote until you break out of that loop. The only potential issue is if that routine gets interrupted so frequently that it is always retrying a ton of times and ends up lagging really badly as a result.
 

qwertymodo

Well-Known Member
Member
Joined
Feb 1, 2010
Messages
827
Trophies
0
Age
34
Website
qwertymodo.com
XP
520
Country
United States
As far as implementing clock stretching, I would think that would be achieved by setting the SCL pin as an output, then setting it low. Then, to release the clock line, just set the pin back to being an input. However, depending on how it's being driven by the Wiimote, it may require a pull-down resistor to properly hold it low. All said and done, clock stretching, if possible, is most likely going to be a better solution than either of the ones we've proposed thus far. Disabling interrupts doesn't seem like a very good solution.
 

bootsector

Well-Known Member
Member
Joined
Oct 2, 2008
Messages
198
Trophies
0
XP
275
Country
Brazil
I don't think we would be able to access the SCL pin (PC5) directly when TWI hardware is enabled:

"When the TWEN bit in TWCR is set (one) to enable the 2-wire Serial Interface, pin PC5 is disconnected from the port and becomes the Serial Clock I/O
pin for the 2-wire Serial Interface."


In this case, the correct way to deal with SCL and SDA pins when when using TWI hardware is via TWI registers, such as the TWCR register:

"Bit 7 – TWINT: TWI Interrupt Flag
This bit is set by hardware when the TWI hasfinished its current job and expects application
software response. If the I-bit inSREG and TWIE in TWCR are set, the MCU will jump to the
TWI Interrupt Vector. While the TWINT Flag is set, the SCL low period is stretched. The TWINT
Flag must be cleared by software by writing a logic one to it. Note that this flag is not automati-cally cleared by hardware when executing the interrupt routine. Also note that clearing this flag
starts the operation of the TWI, so all accesses to the TWI Address Register (TWAR), TWI Sta-tus Register (TWSR), and TWI Data Register (TWDR) must be complete before clearing this
flag."


On my solution above, I'm trying to make sure that interrupts are not disabled while the WRA is sending data to the Wiimote: remember that only a single byte is transferred per TWI interrupt call. So I don't want the GCPad_read routine to disable interrupts while we are only half way of the response transmission. That would, for sure, make the Wiimote to receive garbage because we're messing with the TWI timing.

So what I'm doind is checking if we're done transmitting ALL the response bytes to the Wiimote before we proceed to reading the GC pad. When execution flow reaches the noInterrupts() instruction, this would be the status of the TWCR register:

TWCR = _BV(TWEN) | _BV(TWIE) | _BV(TWINT) | _BV(TWEA);


Status above is set by the twi_reply(1) instruction in Wire/utility/twi.c line 470 right before leaving the TWI interrupt handler. We have the TWINT bit set on it, which means, by reading the TWINT bit description above:

"While the TWINT Flag is set, the SCL low period is stretched."

Bingo! We're under clock stretching when GCPad_read is executed!

About my tests here, so far so good! No garbage has been sent to the Wiimote so far. :)

I'll keep testing this possible fix and I will let you guys know about the results!

I would also love to hear reports from people who are able to test the newest code.

Edit:

Ok, by reading this again The "TWINT Flag must be cleared by software by writing a logic one to it." it looks like we're clearing the TWINT flag by writing a 1 to it? Now I'm confused and not sure if I'm under clock stretching when calling GCPad_read. In any case, everything seems to be working as it should so far...

bootsector
 

bootsector

Well-Known Member
Member
Joined
Oct 2, 2008
Messages
198
Trophies
0
XP
275
Country
Brazil
Ok, just found the final and definitive solution:

https://gitorious.org/wii-retropad-...mmit/3fb9660a70eeeb9e2e23d235a865cd26b82c370d

Commit message:

GC/N64 pad readings are now done inside the TWI ISR. Since inside ISR
functions interrupts are disabled, there will be no timing issues
reading the controllers. No Wire library hack is needed anymore. It
seems to be the cleanest and definitive solution for the case! :)

I had to break the GC and N64 reading functions in two different sets: one for reading the pad and another for retrieving the data. The first ones has a parameter which now makes disabling interrupts optional. Since inside ISR functions interrupts are disabled, I had to make this optional. In any case, for reading GC and N64 pads it's necessary having interrupts disabled!

Phew! :)

Edit:

Oops! Small correction:

https://gitorious.org/wii-retropad-...mmit/28c2770adc822771f3a00bb79331d5b80375863c

;)

bootsector
 

qwertymodo

Well-Known Member
Member
Joined
Feb 1, 2010
Messages
827
Trophies
0
Age
34
Website
qwertymodo.com
XP
520
Country
United States
Sweet :) I've been super swamped with schoolwork and didn't have time to dig into the datasheets that much, so I was basically just spouting off whatever ideas came to mind. I'll definitely test it out once I get my order of nunchucks in. I'm currently without a spare nunchuck cable, since the one I had went into the SNES controller...
 

ROMKILLA

Member
Newcomer
Joined
Jan 15, 2013
Messages
8
Trophies
0
Age
42
XP
97
Country
France
Hello guys, how can i play gamecube games on wiiu? Have You create a module that can make this appen? Sorry for bad english( iam french)
 

qwertymodo

Well-Known Member
Member
Joined
Feb 1, 2010
Messages
827
Trophies
0
Age
34
Website
qwertymodo.com
XP
520
Country
United States
Just got in new iron tips for my soldering station, and got to try out proper drag soldering with a flat bevel tip for the first time. Holy frak, it is a beautiful thing. 5 QFP's in no time flat with 0 shorts... I am really loving my new soldering iron :)
 

qwertymodo

Well-Known Member
Member
Joined
Feb 1, 2010
Messages
827
Trophies
0
Age
34
Website
qwertymodo.com
XP
520
Country
United States
Hello guys, how can i play gamecube games on wiiu? Have You create a module that can make this appen? Sorry for bad english( iam french)
You can't yet. You will have to wait and see if tueidj updates Devolution for the WiiU. He has already shown that it's possible, but it will require Wiimote support as well as a new verification method, since the WiiU won't accept the smaller discs.
 

qwertymodo

Well-Known Member
Member
Joined
Feb 1, 2010
Messages
827
Trophies
0
Age
34
Website
qwertymodo.com
XP
520
Country
United States
Here's a question for everyone. Would you prefer to have a button combination (currently DPAD Up + Start for GC, Start + Select for SNES) act as a Home Button press, or not? Personally, I'd rather not have it, because it's not like it's hard to hit the home button on the Wiimote itself, and sometimes you might actually have a use for any given button combination...

I suppose if anybody wanted a specific mapping, it wouldn't be hard to do on a case-by case basis, but I'd like to get a feel for people's opinions on the matter.
 

mike333

Well-Known Member
Member
Joined
Aug 30, 2010
Messages
718
Trophies
0
XP
233
Country
Poland
Here's a question for everyone. Would you prefer to have a button combination (currently DPAD Up + Start for GC, Start + Select for SNES) act as a Home Button press, or not? Personally, I'd rather not have it, because it's not like it's hard to hit the home button on the Wiimote itself, and sometimes you might actually have a use for any given button combination...

I suppose if anybody wanted a specific mapping, it wouldn't be hard to do on a case-by case basis, but I'd like to get a feel for people's opinions on the matter.
Konami code in reverse?
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • Veho @ Veho:
    Mkay.
  • Veho @ Veho:
    I just ordered another package from China just to spite you.
  • SylverReZ @ SylverReZ:
    Communism lol
  • SylverReZ @ SylverReZ:
    OUR products
  • The Real Jdbye @ The Real Jdbye:
    @LeoTCK actually good quality products are dying out because they can't compete with dropshipped chinese crap
    +2
  • BakerMan @ BakerMan:
    @LeoTCK is your partner the sascrotch or smth?
  • Xdqwerty @ Xdqwerty:
    Good morning
  • Xdqwerty @ Xdqwerty:
    Out of nowhere I got several scars on my forearm and part of my arm and it really itches.
  • AdRoz78 @ AdRoz78:
    Hey, I bought a modchip today and it says "New 2040plus" in the top left corner. Is this a legit chip or was I scammed?
  • Veho @ Veho:
    @AdRoz78 start a thread and post a photo of the chip.
    +2
  • Xdqwerty @ Xdqwerty:
    Yawn
  • S @ salazarcosplay:
    and good morning everyone
    +1
  • K3Nv2 @ K3Nv2:
    @BakerMan, his partner is Luke
  • Sicklyboy @ Sicklyboy:
    Sup nerds
    +1
  • Flame @ Flame:
    oh hi, Sickly
  • K3Nv2 @ K3Nv2:
    Oh hi flame
  • S @ salazarcosplay:
    @K3Nv2 what was your ps4 situation
  • S @ salazarcosplay:
    did you always have a ps4 you never updated
  • S @ salazarcosplay:
    or were you able to get new ps4 tracking it \
    as soon as the hack was announced
  • S @ salazarcosplay:
    or did you have to find a used one with the lower firm ware that was not updated
  • K3Nv2 @ K3Nv2:
    I got this ps4 at launch and never updated since 9.0
  • K3Nv2 @ K3Nv2:
    You got a good chance of buying a used one and asking the seller how often they used or even ask for a Pic of fw and telling them not to update
    K3Nv2 @ K3Nv2: You got a good chance of buying a used one and asking the seller how often they used or even ask...