ImportingSIDs - LTVA1/klystrack GitHub Wiki

The SID file import feature is able to import a handful of Rob Hubbard SID's by scanning the files for the actual song data. Many (if not almost every) Hubbard SID has the note data and the instrument data in a very similar way. The algorithm can find the pattern data in some cases and in some cases you will need to disassemble the song using a tool and enter the addresses by yourself. If the import dialog shows FFFF as any of the addresses, it means the address could not be deduced and the import will not work correctly.

Some supported SIDs:

  • Commando.sid
  • Lightforce.sid
  • ACES_II.sid
  • Monty_on_the_Run.sid

The playback routine contained in the SID is not analyzed at all, so only basic instrument features like "arpeggio" (a simple octave arpeggio) and "drum" (rapid portamento down) are supported. This should at least give a general idea which instrument is which - the imported song will need cleanup in any case.

The imported sequence and patterns also need cleaning up: things like portamentos (note slides) and volumes need adjustment so that they sound like the original. Song speed is not read from the SID at all, that also needs manual adjustment.

Sometimes (e.g. Human_Race.sid) the song only uses two channels. This has to be manually set in the import dialog, otherwise the algorithm will try to read extra data for the missing channel.

Developers

Everyone interested in the subject should start with this primer to Rob Hubbard's routine. In short, you should understand the data structure:

  • Pattern pointers to the pattern data (low and high)
  • Instrument table
  • Sequence for every channel
  • Subsong table

The algorithm uses simple heuristics to find matching patterns in the SID code and tries to find addresses the code refers to. E.g.:

LDA pattern_pointer_low,X
STA current_pattern_pointer_low
LDA pattern_pointer_hi,X
STA current_pattern_pointer_hi
LDA (current_pattern_pointer_low),Y
STA current_pattern_data
...

In the SID there might be a routine that fetches the pattern data pointer and stores it in a temporary address and uses that to load the actual pattern data for the current time in the song. The code is usually unique enough to appear in the SID only once and usually even different versions of the Hubbard song routine do exactly the same thing. It is then easy to make a wildcard search to find pattern_pointer_low and the rest of the pointers.

When there is only one subsong in the SID, the song table will not be there. Also, some SIDs have the song selection done by code without a table. In such cases the subsong selection will not work.