Proton Arduboy Simulator
What does it do?
It's a harness to run code written for the Arduboy in Visual C++ 2005. It fakes the Arduboy API (Both V1.1 and V1.2 of the Arduboy library) so I can test and debug my stuff in my favorite development environment. The identical code can then be run on the real Arduboy.
Features/Good stuff
- Runs the Arduboy examples at full speed
- Can interact with the mouse (click the buttons, easy) or the keyboard
- Pixel perfect simulation, includes AbPrinter, WCharacter, WString, etc
- Even code pieces that lacks reentrancy (like a giant while loop until a key is pressed) work ok
Issues/Bad stuff
- This is NOT an emulator that can run Arduino binaries. It's a simulator that can compile Arduboy Arduino sketches - so this is only useful if you are a developer!
- No EEPROM simulation (eeprom.h exists but it just stubs stuff out to avoid errors)
- No audio simulation (ArduboyPlaytune.h exists but it just stubs stuff out to avoid errors)
- No LED light simulation, those commands will just do nothing
- Somewhat hacky, only works with Windows. Wouldn't be tough to fix that and make it worth with other things though, for example, a html5 export shouldn't be too hard hard
- Unfortunately optimized stuff like TEAM a.r.g's games won't run because they don't use the original Arduboy.h/cpp class. You'd have to modify Arglib.* in a similar way as I did for Ardoboy.* for it to work, or add any missing things to my version of the Arduboy class.
How to compile and run it as is
* The Proton ArduboySim/win subdirectory contains the Visual C++ solution to open. This is included with the main Proton distribution which you can get here. (What's Proton SDK? It's kind of like SDL but you include all the .cpp files rather than use a library)
By default I've included a slightly modified version of Arduboy's breakout example. To run it, open the Visual Studio project and compile the “Debug GL” or “Release GL” configuration.
In addition to clicking the visual direction pad/buttons, you can also use the keyboard arrow keys and the Ctrl and Z keys for A and B respectively.
How to convert your own Arduboy code/sketch to run
- Add your sketch files to <proton install dir>/ArduboySim/Arduboy. (you should probably delete breakout_bitmaps.* as your sketch likely doesn't use them)
- Replace ardu_main.cpp with the contents of your .ino file. Delete your .ino file, you won't need it anymore, Arduboy.ino will be used instead
- Rename begin() and loop() to main_being() and main_loop()
- Disable precompiled headers for your added files in VC++ (Select the .cpp files you added, right click and choose properties, set configuration to All Configurations, then under C/C++→Precompiled Headers, set Create/Use Precompiled Header to “Not using Precompiled Headers”)
- You can now try compiling. Likely it will fail with a bunch of errors because Visual C++ isn't automatically creating function declarations like the Arduino IDE does - it's just a normal .cpp file. Create your own (example: void myfunction();) and paste them at the top of the .cpp or in its .h file.
- Your thing might run now! If not, it's probably because of something I'm not simulating yet and you'll have to add it
How to run your converted sketch on the real Arduino
Just double click <proton install dir>/ArduboySim/Arduboy/Arduboy.ino and compile and install like usual in the Arduino IDE, it should work. You can zip up just that dir if you want to give the Sketch source to somebody, it works the same as usual despite the tweaks.
Thoughts/Notes
- Maybe there is a better way than the dummy .ino file calling main_begin() and main_loop(), dunno, but this does work.
- Most code is copied from the Arduboy & Arduino projects and not mine. Feel free to use/steal any the stuff I wrote in the ArduboySim or /shared/Arduboy directory trees as needed.
- Why am I still using VC++ 2005? I dunno, I just like the IDE more than the 2015 version and use it when I can. VC++ 2015 should work too but you'd have to update the solution file, I didn't try it
- I made a thread on arduboy.com if you have a question or comment about this
– Updates/Changes
- June 2nd 2016: Now plays simple tones (to use, Switch build to “SDL Debug GL”, you'll need SDL 2 libs), display more accurately simulated, supports HTML5 web version, just run /html5/build_release.bat to make it. (More info on HTML5 setup)
- June 7th 2016: Can now compile both arduboylib 1.1 and 1.2 code, 1.1 is now default and ardubreakout was changed to the 1.1 version. Should define RT_ARDU_DEV_BRANCH for 1.2 code, will fix timing to match 1.2
- June 8th 2016: Landscape mode support: ArduboySim's App.cpp adjusted, uncomment #define RT_ARDU_LANDSCAPE and you can play sideways