Wiring.c with Bootloader Button combo support

I wrote a modified version of wiring.c

By adding this wiring.c file to your sketch folder or by putting it in into the Arduboy(2)\src folder, a special feature will be added to your sketch:

By pressing the UP + DOWN buttons (and no other buttons) for approxemately 1.5 seconds will exit the sketch and enter the FX Loader menu (bootloader mode)

Techy details:
interrupt service routine for timer0 is rewritten in assembly and optimized.
consumes 8 bytes of extra PROGMEM
frees 3 bytes of ram (1 byte extra ram used. But ISR uses 4 less stack pushes)

So, for games that use literally every last byte of PROGMEM. (I think, Arduventure? And a couple others?) are there any options?

Shit, also, this will probably break sound/music or if they are using delay?

The compiler and Arduboy2 library have been optimized since. (Arduventure takes 95% of PROGMEM) Shouldn’t be a problem.
But If there is then I’ve got another wiring.c up my sleeve with more optimisations as used in my homemade package (but some may concider it as unsafe)

No it doesn’t.

I’d suggest making the hold time longer; say at least 5 seconds. There could be sketches that use UP + DOWN for some action. Even if the required press or hold time for that combination in the sketch is shorter than 1.5 seconds, you wouldn’t want someone who held for a bit too long to have their current game ruined.

For instance, my ArduboyLife sketch uses UP + DOWN to toggle sound on and off. The status info, which includes whether sound is on or off, is only displayed while the buttons are held, so even though only a short press is required, you tend to hold them longer to read what’s displayed.

AFAIK there are no games that require Pressing UP+DOWN for that long and 1.5 seconds feels like ages while pressing the buttons down for that long.

As for ArduboyLife when toggling sound you press the buttons briefly there is no need hold the buttons down for that long (you actually need to press one of the up/down buttons first before you press the other one) and you don’t need to press UP+DOWN to show status info. Pressing a single button is enough.

Something else you might want to consider (which, in retrospect, I didn’t for ArduboyLife) is that with homemade systems that use a true single piece D-pad instead of individual buttons, it will be impossible to press both (and only) UP + DOWN at the same time.

Homemade Arduboy’s can be easily equiped with a reset button.

Real Arduboys can be easily reset with the power switch.

I’ve tried holding both up and down buttons at the same time and it’s almost impossible to do as an accident it’s only going to be an issue of a game actually uses that and I can’t see that there really is one except some very strange edge cases.

Ie, probably only your life sketch I’m sorry.

We will go through a beta test to see what people’s feedback is.

The dark side is a pathway to powers some might consider to be… Unnatural

Cooked up a new version of wiring.c The Timer0 ISR with Bootloader button combo now takes up the same space as the original C++ version.

I also updated the flash-builder.py script that automatically patches flashimages with this new ISR. Hower some games that alread use (one of my previous) custom wiring.c can’t be patched. for uniform a UP+DOWN for ~2 seconds it would be nice if these games could be updated with this version (@filmote, @JayGarcia)


Does the script detect which games that already use a custom wiring.c?

Yes it does. But It’s just not smart enough to see if that custom ISR has a exit to bootloader button yet (something I still wanna add)

currently there are three games that can’t be patched right now:

  • curse of astarok (using one of my non button optimized wiring.c)
  • Evade 2 (uses also one of my custom wiring.c with LEFT+UP+A+B button combo)
  • Starduino (custom ISR that seems to do something completely different. But this game is not allowed to be redistributed)

So it’s only Curse of Astarok that is an issue at this moment?

@filmote I’m sure can update his game?

Yep … we used every last byte though from memory. If it is no larger then I am pretty sure we can do it.


yeaaaah… you won’t have much luck patching it since I’m not using the Arduboy library at all. :stuck_out_tongue:

Yeah I noticed the timer0 ISR looked totaly different.