Close

Mother's Day Slide Puzzle

A project log for Dodo: 6502 Game System

Handheld Game System featuring the 6502

Peter NoyesPeter Noyes 05/14/2016 at 16:121 Comment

For Mother's Day a few weeks ago I made my wife a game on Dodo! It is basically one of those plastic slide puzzle games like this:

The picture for the puzzle is of our two kids. My wife loves big band music so I set the background to 'Moonlight Serenade', which is her favorite. That era of music reminds her of her Grandparents. The game is written in 'C' and is only a few hundred lines of code. The screen is 128x64, so the puzzle is rectangular instead of square. At first I sliced the image up so that the puzzle would be 8x4 (32 pieces). This proved to be very difficult to solve, especially with the image being low resolution and dithered. Each piece is completely unrecognizable until it forms the final image and you look at it from a distance. I then changed it to 4x2 (8 pieces) which felt about right in terms of difficulty.

To load the image I found this great little project on Github that simulates the Atkinson Dithering from early the early Macs. I use this to create the bitonal image needed for Dodo.

http://gazs.github.io/canvas-atkinson-dither/

The game has the concept of a Cursor. If you click 'A' while the Cursor is on a piece next to the hole, the piece then moves to occupy that hole. To support the cursor I added the XOR drawing mode to the sprite drawing function. Repeatadly drawing a white block in XOR mode over the piece causes it to flash.

The music is encoded by hand in the following manner:

#define Cs1 224
#define D1  210
#define E1  188
#define F1  177
#define Fs1 168
#define G1  158
#define Gs1 149
#define A1  140
#define Bb1 133
#define C2  118
#define D2  104

static byte const _music[92] = { Cs1, 12, D1, 40, E1, 4, F1, 4, D1, 40, E1, 4, F1, 4, D1, 16, E1, 4, F1, 4, D1, 16, E1 ...

I have defined the various notes needed by the music. Each represents a number that is used by the VIA shift register to ultimately output the correct frequency. The music is a byte array alternating between notes and durations. A duration of 1 amounts to 50ms. For the tempo of the song, and to make it possible to encode triplets, I chose that a quarter note will be represented by 12.

Looking at the sheet music it starts with a quarter note of C#, which is encoded by Cs1, 12. The next note is tricky. It is a dotted half note that is connected to the first note in the triplet. A triplet as a whole is meant to fill the space of a quarter note. So the duration of each note in the triplet is 4 (12/3). The dotted half note is meant to then represent 3/4 of the total measure. Each measure is a total duration of 48, so the dotted half note should be 36, however because it is connected to the triplet it gets 4 added for a total duration of 40, the next two notes complete the triplet and have a duration of 4.

If a note of 0 is output, it represents silence.

As you can see, encoding music can be a touch complicated, but to me, it is actually pretty fun!

Thankfully my wife loved the present. I gave it to her on a game cartridge in a card! Here is the finished project:

Discussions

Jon Thomasson wrote 06/02/2016 at 22:48 point

This is really impressive. Good work!

  Are you sure? yes | no