• PicŪ Basic


  • Simple SID chip emulator

    Collecting 1970's and 1980's computers is one of my hobbies, although, not so much these days as I've run out of places to put them in the house, unless it's a particularly rare or pristine condition one.

    One of the most popular computers of the 1980's was the Commodore64, not only because it had a great graphics chip, but also because it had a great sound chip, namely the "SID chip", or to give its technical name, the MOS6581, later changed to the MOS8580. See http://en.wikipedia.org/wiki/MOS_Technology_SID

    There are several microcontroller emulators for the SID chip knocking around the internet, some are created using 32-bit processors or FPGAs, but some are created using 8-bit microcontrollers, and all based upon the Atmel AVR types for some unknown reason. In fact, for some strange and disturbing reason, most really interesting creations with 8-bit microcontrollers seem to be based upon the AVR, and have been for many years now!

    However, to readdress the balance in some small way, I've produced a simple SID chip sound emulator using Proton BASIC, which I think is the first of its kind for a PICmicro, and certainly for an 8-bit device written in BASIC, which just goes to illustrate the power and flexability of the language

    There are limitations, in that the SID emulator does not support the filters that the original SID chip contained. This is not a hardware issue, or a language issue, but the fact that I don't fully understand the theory and practice of IIR or FIR filters enough to create them with any efficiency. So if anyone with a knowledge of IIR or FIR filters is prepared to pick up the baton and create the filters required within the code, they would be more than welcome to do so.

    However, even without the filters, the sound produced is pretty good. Take a listen to this mp3 file of the sounds created by the simple emulator: Bombjack.mp3

    Or how about these:
    1942.mp3, Ghost and Goblins1.mp3, Ghost and Goblins 2.mp3

    I originally wrote the emulator some time ago for the Amicus18 platform, but never released it. However, as you know, Amicus18 is only the Proton compiler restricted to 2 devices. i.e. the 18F25K20 and the 18F25K22, so adapting it to Proton was simpicity itself.

    Because it is based upon the Amicus18, I've left the code for use with the 18F25K20 device using a 16MHz crystal, internally boosted to 64MHz by the PLL. However, there is no reason that the code could not be adapted for any of the larger 18FxxK devices.

    The code can be downloaded from here: Simple_SID.zip

    The firmware uses the PICmicro's hardware PWM as a DAC, so all that is required is a simple R/C low pass filter connected from PORTC.2 (CCP1) to the input of an amplifier. Headphones will suffice, but the volume will be low.

    The firmware for the SID emulator looks complex, but in fact it's rather simple. The reason it looks complex is because it has been rolled out in order to increase readability and speed of execution. It consists of a Timer0 overflow interrupt to create and mix the 3 channels of sound, a channel waveform creator, and an ADSR. The player code also looks complicated, and I must admit, it is more complicated than it should be, and could be simpified. However, all it does is read the sequence of SID registers from a very large data table, pass these to the SID emulator, create non-blocking delays, and trigger the ADSR at the appropriate times. The player is not perfect, and could be improved upon significantly, but it served its purpose of testing the main emulator code.

    A SID chip emulator is of limited use if the original SID tunes cannot be played, so I created a very simple Delphi application that converts the output of another, third partly, application into Cdata statements that Proton can understand. The Delphi application, and its source code is included in the zip file. The third party application is named Sid2midiw.exe, however, not only does the application produce midi files based upon actual SID tunes, it also produces a txt file that contains the register changes required for the SID chip for a particular tune. This is what the Delphi application uses for its conversion. This is also included in the zip file along with some txt files produced by it, ready for conversion to Cdata tables.

    To convert a tune ready for the emulator and player:

    1). Download some SID tunes from the internet. There are literally hundreds, if not thousands, of SID tunes out there.
    2). Run Sid2midiw.exe and create a .txt file for the chosen .SID file.
    3). Place the .txt file into the Delphi application's "Raw Tunes" folder.
    4). Run the Delphi app SID_MusicConverter.exe. Press the convert button and point to the file to be converted.
    5). The .inc include file ready to place into proton will be produced in the application's "Converted Tunes" folder.

    That's it!

    Important
    The code is only suitable for the Pre-release Proton compiler version 3.5.2.6 onwards, downloadable from the beta section of the forum.

    It's also important to note that because of a combination of the lack of filters within the emulator, and the Sid2midiw.exe application not always producing the exact output, and my player firmware's simplistic nature, not all SID tunes will be re-created as they originally sounded on the Commodore64. This is something that could be cured, but it would take time, time that I don't have at the moment, which is one of the reasons that I've passed the code onto you. Hopefully, you will be able to improve on the code over time, and give it an output that mimics the SID chip in all its, rightly deserved, glory.

    Over to you.....
    This article was originally published in forum thread: Simple SID chip emulator started by Les View original post