Category Archives: HW emulation
an old player revisited
Ten years after my first sc68 web port I thought it might be time to update the code base to the latest sc68 dev version. This new version supposedly has improved SNDH playback capabilities and I used the occasion to play with WEBGL and also add a visualization of the emulation’s internal voice streams. A live demo can be found here: http://www.wothke.ch/webSC68
PS: I updated PlayMOD to now also use this version.
m68k reminiscences
I had done the original Web port of UADE back in 2014 without bothering about its existing implementation. Though I had owned an Amiga back in the nineties, I had never actually written much software on that machine. And though I had done some m68k assembly programming on the AtariST I cannot say that I still remembered much about the respective Motorola 680×0 CPUs.
But it bothered me that UADE’s emulation still doesn’t support certain Eagleplayers – after all these years (i.e. it is incapable to play certain Amiga music files). So I decided that it might be a fun exercise to fix at least some of those flaws myself.. “If you want something done right, do it yourself”… right? 😉
The linked page shows my resulting webuade+ version: As compared to the original, this version has an added “audio.device” implementation, added multi-tasking support and added support for shared library loading (in addition to various small fixes). It supports (at least) these additional players: Andrew Parton, Ashley Hogg, PlayAY (except ZXAYEMUL), Digital Sound Creations, FaceTheMusic, G&T Game Systems, Janne Salmijarvi Optimizer, Kim Christensen, Mosh Packer, Music-X Driver, Nick Pelling Packer, TimeTracker Titanics Packer, UFO and some Custom modules.
While this little “project” was a fun “code reviewing” exercise (trying to make sense of UADE’s original m68k ASM and C code based emulator implementation), with some reverse engineering (disassembling portions the Amiga’s Kickstart OS) thrown in, it was also a stark reminder of what it meant to program back in the days..
webSID-Pi
In previous posts I had documented some “Raspberry Pi 4B” related ramblings and this post here may clarify why I was interested in that device in the first place.
It’s been some years that I’d created a C64/SID music emulator for the Web called webSID (see https://bitbucket.org/wothke/websid). I still have somewhat fond childhood memories of my respective 80ies home computer which had started my career in software engineering (particularly memories of its signature music creation capabilities).
If you have ever written any sort of music hardware emulation you are certainly well aware that there is absolutely no shortage of “fanboys” that know exactly what some original hardware sounded like and who are happy to tell you that your pretentious emulation sounds egregiously wrong. In the case of the SID sound chip, the manufacturer MOS had produced various models (6581 vs 8580) and revisions (of those models) that had different hardware designs (and production tolerances related differences) affecting the chip’s actual audio output. Consequently the opinions of “fanboys” here tend to be somewhat useless, since they may well be based on one particular chip revision.
Obviously the only authoritative reference is the use of the actual SID sound chips. One way to go about testing respective chips would be to use an old C64. However this approach has some obvious drawbacks: By today’s standards the respective hardware is an extremely slow piece of garbage and it takes forever to even load/run the minuscule programs. Respective 40 year old hardware components (power supply, CPU, PLA and VIC II chips) are prone to die and are more and more difficult to find replacements for. Different songs may require an NTSC or a PAL version C64 (affecting the used clock rate and the behavior of the VIC II chip). Different SID models require different hardware environments, e.g. different supply voltages (9V vs 12V) was well as different filter capacitors.
Given that my webSID emulation already covers all the required runtime environments I decided to ditch the respective non-SID legacy hardware and connect the SID chips directly to a “Raspberry Pi 4B” and drive it via the available GPIO pins.
The below image shows my respective prototype board. The design is actually fairly simple: The SID chip is dropped into the prototyping socket in the center. A boostconverter (red PCB) is used to create the 9V or 12V supply for the SID chip based on the Pi’s 5V. The filter capacitors suitable for the used SID model are plugged in (see green caps between SID and the boostconverter). (I had originally also used a hardwired 1 MHz crystal oscillator but later replaced it with the Pi’s built-in clock signal generator.)

The main problem with running a SID chip from a C64 emulation on a Raspberry PI is that the available operating system is not meant for realtime applications: By default various processes used by the OS are preemptively scheduled to run on the available CPU cores.
Ideally you would want to let the emulation step through the ~1Mhz clock cycles of the emulated C64 hardware one by one in realtime, and you’d have to somehow synchronize that processing with the actual processing speed of the Raspberry (though the overhead for synchronizing each 1MHz cycle would be excessive). The processing cost of different cycles also might vary, and though fast enough on average, sporadic peaks might potentially exceed the available time window for some of the cycles.
Fortunately for practical SID playback purposes the timing constraints can be somewhat relaxed: All of the SID’s timing is directly driven via the Pi’s hardware clock signal and when SID registers are updated respective player routines usually expect to make updates with 50Hz to maybe 200Hz frequency. Even if an update is slightly out of sync, it will usually not be noticeable here. The most timing critical interaction comes from songs that use the C64 CPU to trigger SID changes for the purpose of playing digi-samples. Respective samples may then be played (worst case) with a frequency of about 30kHz (meaning that updates should then ideally occur every 33 micros, i.e. there is some margin as compared to the ~1 micro clock timing).
I decided to go for a two-threaded buffered design: One CPU core is reserved for the emulation thread that generates a batch of SID updates (with respective target timestamps) for the next time window. And a second CPU core is dedicated to a playback thread that consumes the output of the emulation thread and that polls for the current time to perform the SID updates when the time is right.
As a first attempt I configured the program to run exclusively in user space and it actually ran good enough for regular SID songs. Unfortunately the preemtive multi-tasking used by the Linux OS causes timing glitches that are quite noticable in songs that use “digi-samples” tricks.
I tried to limit undesirable interference effects from other programs by isolating use of the relevant CPUs (see isolcpus, rcu_nocbs, rcu_nocb_poll and nohz_full) but unfortunately the remaining 100Hz “arch_timer” IRQs still seem to prevent a clean playback.
As a workaround I then created a kernel module for the playback thread and that version indeed plays nicely without any glitches. But eventhough the respective version may sometimes run fine for multiple minutes, there still seems to be some part of the kernel that sporadically crashes the system – probably due to the “playback” thread completely blocking “its” dedicated CPU core. The test results suggest that this problem might be fixed if the component that triggers the crash can be identified and disabled. Unfortunately I am not familiar with the respective Linux kernel implementation and I currently don’t feel like looking for that needle in the haystack. (Please let me know in case you have an idea how I might hack the kernel to work around the issue.)
Here the results created by the respective programs:
PS: More information on this project can be found here: https://bitbucket.org/wothke/websid/src/master/raspi/
PlayMOD online chiptune music player
My voyage into the realm of legacy computer music had originally started with my webSID music player and later continued with my extended webUADE version of the uade Amiga music emulator.
I still have fond childhood memories of my respective C64 and Amiga home computers since these devices ultimately triggered my career in software engineering. Whereas most of the capabilities of respective 40 years old home computers obviously look quite lacking from today’s perspective, their audio features have aged rather gracefully and I feel that the audio stuff is much better suited to preserve the nostalgia – e.g. as compared to the blocky pixel graphics or underwhelming computing power.
I later learned that even though the above devices where obviously the best that ever existed (cough), other people share similar nostalgia but with regard to other devices. In many cases emulators for respective devices already existed on some platform and all that was missing were respective ports so that it would be possible to use them on a Web page. Since this is basically the same thing that I had already done for my webSID and webUADE players I started to also port some of the existing 3rd party emulators (many of which I somewhat enhanced in the process).
Over the years the number of respective JavaScript/WebAssembly based music emulators in my toolbox has grown to around 30 and it was time to put them to good use: PlayMOD combines all of “my” Web emulators within one UI to provide “all-in-one” online browsing and music playback for some of the largest “legacy computer music” collections available on the Internet:
The modland.com collection contains about 455’000 music files from various legacy home computer and game consoles and the vgmrips.net collection adds another 62’000 primarily arcade system songs. The PlayMOD project derives its name from “module files” (MOD) music – which signifies computer music that has been created using some kind of tracker software (the term “tracker” goes back to Karsten Obarski’s Ultimate SoundTracker on the Commodore Amiga from 1987). However, in addition to actual MOD-files the used collections also provide a large number of other music formats, e.g. many of the older stuff would be usually referred to as “chiptune music” today. You may use the Basics tab directly on the PlayMOD page for more background information.
When looking for a MOD or chiptune player, PlayMOD provides the best coverage available due to its combined use of different emulators/player engines. PlayMOD is probably the only comprehensive cross-platform online player in existence today.
There are hundreds of different legacy music file formats involved and the emulators available in PlayMOD currently allow to play more than 99.9% of what is available in the two collections. This avoids having to manually find and install a suitable player for each exotic format (which otherwise may be a tedious task, and a player may not even exist for the platform of your choice, e.g. see Ixalance).
The PlayMOD web page allows to browse the folder/files available in the respective collections but it does not host any of the music files. In order to play a song, the user’s browser will directly retrieve the selected file from the respective collections (see links above) and then play it. Consequently the page will only be able to play the music while the ‘modland’ and ‘vgmrips’ servers are available.
The respective modland and vgmrips collections document the evolution of computer music during the past 40+ years. Having everything consolidated in one place allows to easily compare the capabilities of respective legacy sound systems (e.g. by comparing how the compositions of the same composer sounded on different platforms) or to just indulge in reminiscences.

The PlayMOD user interface is based on the design/codebase originally created by JCH for his DeepSID. I wasn’t keen on creating a UI from scratch so I am glad that I could reuse JCH’s already existing stuff – eventhough it had to be heavily modified. The PlayMOD UI is still in a prototype/proof-of concept stage and the quality of the used meta data (e.g. composer information) leaves a lot to be desired due to it having been automatically generated based on questionable quality raw data.
Obviously, legacy computer music could also be preserved by just creating some recording from the original hardware, and as can be seen on youtube, many people already use that approach. Indeed the approach of using an emulator will not always be as accurate as the use of the original HW (on the other hand recordings may suffer from lossy data compression – a problem that an emulation does not have). As compared to the original music files, recordings may use up much more memory and consequently network bandwidth, but today that isn’t the issue that it might have been 10 years ago. However emulation avoids the additional recording/publishing step and new music files can immediately be listened to – without having to wait for somebody with the suitable infrastructure to provide such a recording. (There actually are still “scenes” where people create new music for legacy systems today.)
From a “legacy computer music preservation” perspective the emulation approach also has the benefit that it not only preserves the end result but also the steps taken to achieve it. It allows for interactions that would not be possible with a simple recording. (Mileage may vary depending on the “original” music file format.)
Example: The “Scope” tab in the below screenshot shows the output of the different channels that some “Farbrausch V2” song internally uses to create its stereo output, i.e. an emulation approach allows to look at the “magic” that is happening behind the scenes.

Similarly a respective emulation could still be tweaked during playback, e.g. by turning certain features on/off, or by using different chip models.
part three..
And to complete the trilogy here another bit of fractal fun (in case your PC is not equipped with a fast enough graphics accelerator you can find a video recording here: https://youtu.be/PzTwOfoZp0E):
the beauty of numbers..
I just did a little revival of my old WebGL fractal stuff. The two below screens use the latest version of my Commodore C64 emulator to play two fitting music creations by Markus Klein.
vu meters?
Just a little experiment for how to synchronize visualization of additional data streams with the the playback of WebAudio music: The music samples are generated on the fly using a ScriptProcessorNode emulating some legacy AtariST. In addition to the stereo output the respective ScriptProcessorNode also generates three streams containing “playback volume” for the AtariST’s internal sound-chip voices:
just for fun a more psychedelic WebGL based rendering of the same data (the WebGL here combines an orbit trap fractal with an inverse distortion, and the “music volume” is used to parameterize the rendering):
unaligned “packed structs”…
are certainly not a good idea if a program is supposed to be portable. Unfortunately that is exactly what ZXTune is using to parse the different binary music files.
“One of the rules of packed structs is that you have to access them directly through the packed struct type. In other words, you can’t, in general, take the address of a packed field and then access the field through that pointer, because the pointer type won’t reflect the packed attribute.” (sunfishcode)
Unfortunately ZXTune used boost::array instances within the various packed structs.. Problem: when methods are invoked on boost::array (or std::array, etc). The ‘this’ argument to the boost::array functions may be misaligned, but the boost::array functions themselves don’t know this.
On CPUs which don’t mind unaligned memory access you may get away within without realizing that there is a problem.. and in this case it was my attempt to cross-compile the program using Emscripten that revealed the issue. Not wanting to rewrite too much of the foreign code I opted for a quick-fix: replacing the boost::array with a built-in array fixed the immediate problem…
Naturally a clean implementation should better refrain from depending on unaligned memory access at all… not all the CPUs are as forgiving as Emscripten.
(click on the below image for a live demo).
AdLibido – the wonders of early PC music ;-)
It was back “in the old days” and I remember my relief when some day I found out that all PCs were not necessarily mute: Thanks to some “walking frame” called “AdLib” they could actually make sounds… and a bit later things became pretty neat with the rise of Sound Blaster…
AdPlug plays sound data, originally created for the AdLib (OPL2) and Sound Blaster (Dual OPL2/OPL3) audio boards, directly from its original format on top of an emulator.
My latest bit of Xmas tinkering is a HTML5/WebAudio version of AdPlug (Thanks to Simon Peter and the other authors of AdPlug.). For a live demo click on the below image..
update: The respective page has meanwhile been updated and the used link therefore no longer corresponds to the original screenshot (you’ll need a browser with WEBGL support to use it).
after all those years..
To complete the set of chip-music emulators, here my WebAudio version of SC68 – an AtariST Â music emulator (that plays files like *.sc68 or *.sndh).
Even tough I had done some programming on the MegaST 4 back in the 90ies, I have to admit that at the time I had not realized that the machine had anything resembling a sound chip. Those were the days of 68k assembler, DSP machine code and GFA-Basic.. and we were just doing a Paintbox software for the “CHILI” frame-grabber and real-time video-effects extension card… 🙂
But it seems the ST not only did have a MIDI interface but also a built-in sound chip…
Thanks to Photon Storm for sponsoring this little project.
update: The respective page has meanwhile been updated and the used link therefore no longer corresponds to the original screenshot (you’ll need a browser with WEBGL support to use it).






