I’ve made a demo showing Mega Man running to the right against a background! It looks very much like the image above, except fully animated. It’s greyscale (or a flickery attempt at it) with two shades of grey along with black and white. It also plays a two channel song. The graphics and music are both from Mega Man 2, Wily’s Castle stage 1, on the NES. This stage, with this music.
The d-pad changes the display mode. Pressing left is the default, showing two shades of grey. Pressing right shows only one shade of grey (this actually looks worse and more flickery on my dev kit). Pressing up changes it to black and white only, which is incredibly smooth and very pretty.
The buttons change the sound mode. The A button (the left one) mutes the music, while the B button restarts it. If you turn on the unit while holding A, it will start up muted.
It’s a fairly simple demo but it brings a lot of stuff together to be a good demonstration of what the Arduboy is capable of! Get it here on GitHub.
Video courtesy of @Wozza!
Some technical info:
As of the 5/27/2015 version of this demo,
Sketch uses 18,622 bytes (64%) of program storage space. Maximum is 28,672 bytes.
Global variables use 1,249 bytes (48%) of dynamic memory, leaving 1,311 bytes for local variables. Maximum is 2,560 bytes.
This includes a font that isn’t used which takes up 1,275 bytes of ROM. The song alone is 5,319 bytes. The graphics are 1,536 bytes, which includes Mega Man’s transparency masks, and one repeated sprite in Mega Man’s run animation in order to simplify the code.
An older version of the demo before the music code and data was introduced, and with the font commented out, resulted in this:
Sketch uses 10,030 bytes (34%) of program storage space. Maximum is 28,672 bytes.
Global variables use 1,221 bytes (47%) of dynamic memory, leaving 1,339 bytes for local variables. Maximum is 2,560 bytes.
Music handling is fairly hefty, though we may be able to compress it in the future.
The music code is part of an updated Arduboy library provided to us on IRC by GoatKing, the Arduboy team’s programmer. It’s a modification of a library called playtune, intended for playing music on Arduino with piezo speakers. The author of playtune also wrote a companion program called miditones that converts a midi file to playtune’s format, which I used to create the included song. You can download his software here. Since the speaker has only two channels and the NES has more than that, I had to eliminate some of the channels from the music. I chose to keep the lead and bass, sacrificing the harmony and drums, and it sounds pretty good in my opinion.
I modified the arduboy library’s drawbitmap function to overwrite pixels in the screen buffer instead of ORing them. This way, every frame I could draw the background slices over everything else, “wallpapering” over what was there before, and not needing to clear the screen buffer first. It’s wasteful of some cycles to draw on top of what’s already been drawn, but for a simple demo like this it’s not a huge deal.
I also copied drawbitmap to create a second function, drawmaskedbitmap, which can draw transparent sprites over existing background. First, the mask is ANDed with the background, which creates a black silhouette where the sprite will be drawn and leaves the rest of the background alone. Then the sprite is XORed over the top, which fills in the silhouette with Mega Man, in this case.