LDA $00

How to Music on GameBoy

Your childhood might have been spent listening to the bleeps and bloops coming from a small grey box with a small LCD screen and tiny speaker inside. Maybe you heard exciting tunes as the enemy chose their next monster to face your own, or maybe you sat, stranded on a beach listening to the tunes floating about in the fresh, ocean air. But, how does one even make these tunes? How does it all work?

This will be a guide to some insight on my part and even some investigation together diving into the subject of programming sound on the GameBoy. I hope we can tackle the general ideas and follow my development of a sound driver for Gameboy written entirely in assembly.

So how does sound work on the GameBoy?

Okay, so the sound system on the Gameboy is pretty basic. It's just four channels: Pulse/Square 1, Pulse/Square 2, Wave, and the Noise channel. Each channel can play a single noise at a time so at the most, you can have 4 noises going on.

To control these channels, you need to read and write to a series of registers. Basically you write values into these registers and then the GameBoy will do the rest.

The GameBoy PanDoc has everything you need to know on the sound controller registers.

But How Would you Music?

It's pretty simple. All you've got to do is modify these registers to a tempo according to the music score... Easier said than done I think.

I think the first issue to tackle is the tempo. You need to keep a regular beat for a typical musical store. There's probably a few ways of doing this on the GameBoy but I've chosen to use the screen refresh update as a time keeper for my music driver. The screen refreshes at a nearly 60 Hz rate so I can use that for a regular update as I need to.

halt
nop
call DMARoutine
call UpdateMusic