Jump to content

ivop's Blog

  • entries
    16
  • comments
    25
  • views
    45,645

SID Emulation, siddasm2 and shasm65

ivop

1,300 views

Long time, no blog.

 

Let's start at the beginning. In 2009 I wrote my first version of a SID Emulator, running directly on the Atari 8-bit hardware. The emulation loop ran in the main loop and synchronisation was done with STA WSYNC. I had created a raw register dump of a .sid file with a modified version of TinySid and every frame I left the main loop a few times for a few cycles to stuff the SID emulation engine with new values. I didn't take long to realize I didn't have quite enough time to do much else.

 

I wanted to ditch the idea of playing a register dump. Even RLE compressed it took way too much memory to store a decently sized song. I wanted to run the original C64 player routine. That led me to the source code of siddasm and a rewrite with more features, which I called siddasm2 (really original).

 

I moved the emulation code to page zero to save some cycles, but that did not really help enough. At the same time, I stumbled upon a bug in Atasm and instead of fixing that, I ended up writing my own assembler. I had always wanted to do that. I won't go into details here. See my previous blog entries on shasm65 and siddasm2.

 

After that, I kind of lost interrest, but a few weeks ago I continued this project. I completely rewrote my SID emulator in shasm65. Now the emulation engine was running of a timer interrupt, leaving the main loop free to periodically call a C64 player routine. This routine had to be patched though to write to shadow SID registers instead of the C64 hardware registers.

 

This is where siddasm2 came in again. Early in the process of disassembling Laxity's song "Freeze" I noticed that the resulting assembly code couldn't be assembled again by atasm AT ALL. Which shouldn't be the case. I fixed a few bugs in siddasm2 and shortly after that I was able to recreate the .sid file from source code with the help of atasm -r and unix dd (for the header). So far, so good.

 

Now I was able to patch the source code of 'Freeze' and run it alongside my sid emulation code. I added code that converted the shadow sid registers to values my engine could work with, added ADSR envelope handling, everything I used to do in my modified TinySid. A few debugging sessions later, I had it all working! After that, I disassembled and patched the International Karate tune. This triggered a new bug in my emulation, which is now fixed.

 

I sent out an example to Freddy (F#Ready on AA), which he turned into a youtube video and posted a link on AA to see what all of you would think about it. And now I figured it's time to release the source code and a few binaries to play with :)

 

Attached you'll find version 2.1 of siddasm2.

A slightly modified shasm65 which is now verbose in hex instead of decimal (but the original shasm65 is still fine to assemble the code, too. The assembler itself did not change).

.xex binaries for Laxity's Freeze, Rob Hubbard's International Karate and Jeroen Tel's JT42.

The source code for everything.

 

Regards and have fun!



4 Comments


Recommended Comments

Note to those who want to use my sid-engine to play other tunes: some player routines toggle the gate bit in one frame, which means the conversion routines do NOT see it go to zero and back to one again. This means you have to patch the player at this point too (not just writing to shadow sid registers and possibly relocate the zero page addresses). Every write to sid control registers need to be redirected to a small subroutine that compares the previous value to the new value before writing to the shadow register. If the gate bit gets toggled, you need to reset the ADSR envelope phase of that voice to zero. Examples of such player routines are most songs by David Whitaker, Adam Gilmore and probably a whole lot more :)

Share this comment


Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...