Commodore 64 experiments part-2 (SID)
NOTE: I wrote the majority of this post (and the implementation) about a month ago but never got around to publish it until now.
After the last post’s progress of getting the system to boot and being able to run small test programs I felt motivated to carry on. While perhaps it would have been wiser focus on the core system I instead turned my attention to the SID chip.
Again, since I did not really do much with my C64 back in the day, and have had no reason to study it afterwards, my pre-existing knowledge about the SID was pretty limited. I basically only knew “it was the chip that made the sounds”.
To get an idea what the SID sounds like the most convenient solution is proably to head over to the online player at DeepSID where there is a huge collection of C64 music from games and demos that will play right in your browser.
So the SID player plays SID files, but what exactly is a .sid
file? Well
unlike modern audio formats it does not contain PCM samples (e.g. WAV or
compressed formats like MP3) nor does it contain the tones/or notes like a MIDI
file does. Instead it actually contains 6502 machine code that writes values
into SID registers to produce the desired sound. As such a SID player is
essentially a scaled down C64 emulator. For a complete description of the SID
file format see this
link
but for our purposes it suffices to say that it contain two entry points. One
entry point for an initialization routine that will prepare to play a given
song (SID files contain many) and a second entry point for the play routine
that is to be called repeatedly (usually at 60Hz).
Now while this format plays directly in a SID player it requires some
scaffolding and relocation to play on actual C64 hardware. This is where
PSID64 utility comes in, it will provide this
scaffolding and relocation and basically converts a .sid
file to a .prg
that can be loaded and run on a C64.
A huge collection of SID files can be found at the High Voltage SID Collection (HVSC) and convinently their downloads page also provide an archive of the HVSC collection converted to PSID64 format.
Getting the PSID64 .prg
to run on MyC64 required some work but it mostly
boiled down to finally implementing bank switching.
Let’s try and fire up the good old Bubble Bobble tune
./myc64-sim --cmd-load-prg=130:./MUSICIANS/C/Clarke_Peter/Bubble_Bobble.prg --cmd-inject-keys=135:"LIST<RETURN>RUN<RETURN>"
So now that we have something to test the SID with we can move our focus to try and emulate the actual chip.
For those like me who don’t know anything about music synthesis the following videos (< 10min in total) proved helpful to intorduce the basic concepts
- What’s Synthesis and Sound Design? Part 1: Oscillators & Waveforms (Music Theory)
- What’s Synthesis and Sound Design? Part 2: Subtractive Synthesis & Filters (Music Theory)
- What’s Synthesis and Sound Design? Part 3: Envelopes & ADSR (Music Theory)
After that I suggest the following souces for details about the SID
A very basic implementation based on that was started in
rtl/myc64/sid.v.
As usual it is far from complete but it is able to produce some basic tunes.
Modifying myc64-sim
to store the generated audio signal into a .wav
file
allowed us to capture Bubble Bobble - MyC64
SID. This admittedly sounds quite a
bit off (especially in frequency) compared to Bubble Bobble - VICE 8580
ReSID generated by the well
known VICE emulator. Still it is good
enough as a first approximation and allows us to move on an focus on other
areas. That concludes this post. As always if you have questions or feedback -
leave a comment below!