Arduboy Emulation on GBA?

Been wanting to try my hand at writing an emulator for the Gameboy Advance that could play arduboy .hex files from a flash cart. If successful, the flash cart should be able to hold every arduboy game made a few times over, and should look rather interesting on the old screens. Only issue is I have next to no experience with building emulators or coding with the GBA :sweat_smile: So this could be ultimately fruitless.

However, I’m confident the GBA can handle arduboy instructions from a hardware perspective, and I’ve seen people make new emulators for ez-flash omega(arguably the best flash cart on the market) firmware, so that NES, Game Gear, SG-1000, Master System, etc games could be played just by copying the unmodified rom of whatever game from those consoles to the SD card. Then they could be selected like any other GBA game. This is the ultimate goal. Write a version of the ez-flash omega firmware that can emulate arduboy, so that an arduboy folder can be placed on the SD card and any game can just be selected to play it.

Normally I would wait until I’ve made some progress already before posting about a project like this, but since I don’t have much experience I thought I’d share the idea, in case someone else on here knows a thing or two about anything related or if someone else wants to try their hand at it first!

Some good resources so far that I’ve found:
GBAdev (collection of gba devevlopment resources)
TONC (library and full guide to gba coding, not wonderfully written, but very in-depth)
GBA Hardware Architecture (lots of information on GBA specs)
Arduboy emulator (@obono 's, written in java)
ProjectABE (another arduboy emulator, written in html5)
C++ arduboy Emulator (haven’t tested, but is c++)
EZ-Flash Custom Firmware Thread (started as a simple theme upgrade, but turned into much more over time! Is able to use a myriad of file types thanks to PogoShell plugins)
EZ-Flash CFW Source (source, includes plugins and such)
PogoShell (archived website where pogoshell comes from)

EDIT: I’ve also decided to host the last version of the PogoShell source code available on my github, as the license permits this and right now the source code can only be found through an archived version of the author’s website. So here’s the source code on my github if you want to take a look. Most of it is a little beyond me but I’m sure I’ll keep picking it apart until I understand it (see y’all next decade :sweat_smile:)

5 Likes

Nice idea. I don’t have experience with HW emulation but another option you could do is to write the Arduboy API library for GBA, then you can compile each Arduboy game for GBA.

1 Like

Not a bad idea! That does seem like a more approachable method (for me) at the moment, even if the user would have to compile each game as a .gba file. It would also allow for pretty easy arduboy development through a gameboy, so there may be some advantage there as well :thinking:

From what I understand about the pogoshell plugins they load files through an association system, allowing someone to write custom programs for how to deal with certain file types it finds on the SD card. So in theory we should be able to write a pogoshell plugin that can read .hex files and emulate the arduboy’s behavior with screen, sounds, and buttons (let’s leave those poor little LEDs out of it for now).

Option 3 would be midway of both previous options: a transpiler, converting
Hex to .gba. I imagine with the limited ISA and the progmem and ram split, that could be relatively easy

1 Like

That would be interesting! If it sounds easy to you then be my guest, I’ve got a fairly shaky grasp on all of those concepts as it is :sweat_smile: :stuck_out_tongue_winking_eye:

Write a CHIP8 emulator first. Use this and this for reference.
It might seem like a big ask to write another emulator first, but it’ll teach you a lot of skills you’ll need in the process and frankly if you can’t pull off a CHIP8 emulator then you won’t have much hope with a 32u4 emulator.

Sadly I can’t help much with that one.
If I could write software for the GBA, I’d probably be writing a game for it.
The GBA is still one of my favourite consoles.

I can point you to this though.

A lot of what the GBA’s graphics chip can do you won’t need to know about for an Arduboy emulator since most of it will just be pushing pixels to the background bitmap.

Having skimmed it, I can make sense of a fair chunk of it, but you defintely wouldn’t be able to understand it all without at least knowledge of things like ARM assembly and semaphores, and some decent knowledge of GBA hardware.

The way some of it is written doesn’t help though, to be honest.

Lots of variables declared long before they’re actually needed, abbreviated names, single-letter names, and large chunks of code that probably should have been split into separate functions. (Not to mention the C-isms, like if(!*name), *p-- = 0; followed shortly by *(--p) = '-';, the refusal to acknowledge that _Bool exists, and return -1 everywhere.)

I’m just glad it actually has comments, otherwise it would be a lot harder to make sense of.

For the stuff that’s only implementing the C standard library, you’re better off finding some documentation of what the functions are supposed to do. E.g. Null-terminated byte strings - cppreference.com


Though to be honest I think you might have an easier time just porting the Arduboy2 library than writing an emulator. I presume there are some C++11 compliant compilers for GBA somewhere. If not, it should be possible to chain a C++11 to C transpiler with a C compiler.

The biggest problem with both an AVR to ARM transpiler and an AVR emulator is going to be the hardware control sequences.

An emulator would have to actually emulate e.g. the serial commands, the screen commands sent over SPI, whilst a transpiler would have to be able to recognise sequences of instructions that correspond to hardware communication and replace them with the appropriate function calls or hardware manipulation instructions for a GBA.

If you’ve got code that’s calling Arduboy2 library functions and it’s easy enough to tell that’s what it’s doing then it wouldn’t be too hard because you could just swap the functions out, but what complicates that is the optimisation phases that might e.g. inline important functions and optimise them to the point of being unrecognisable.

Which is why both I and @drummyfish say reimplementing Arduboy2 for GBA might be easier.

But that depends on whether you can get tools that will compile C++11 for GBA. Even then, it would be complicated by games that are relying on compiler-specific behaviour introduced by compiler extensions and the dreaded -fpermissive flag. Anything adhering to standard C++11 would be fine though, which I would hope is at least 70-80% of games.

1 Like

You might be interested in this C++ library for GBA software, compatible with Tonclib and libGBA

1 Like