10.3. Import of SID Files

The script language knows the format of SID files. This means that you can import files directly from the HVSC (High Voltage Sid Collection) which uses this format. To do this you use the LoadSid function which returns a value that represents the sidfile.

.var music = LoadSid("C:/c64/HVSC_44-all-of-them/C64Music/Tel_Jeroen/Closing_In.sid")

From this you can extract data such as the init address, the play address, info about the music and the song data.

Table 10.2. SIDFileValue Properties

Attribute/Function Description
header The sid file type (PSID or RSID)
version The header version
location The location of the song
init The address of the init routine
play The address of the play routine
songs The number of songs
startSong The default song
name A string containing the name of the module
author A string containing the name of the author
copyright A string containing copyright information
speed The speed flags (Consult the Sid format for details)
flags flags (Consult the Sid format for details)
startpage Startpage (Consult the Sid format for details)
pagelength Pagelength (Consult the Sid format for details)
size The data size in bytes
getData(n) Returns the n'th byte of the module. Use this function together with the size variable to store the modules binary data into the memory.

Here is an example of use:

//---------------------------------------------------------
//---------------------------------------------------------
//                     SID Player
//---------------------------------------------------------
//---------------------------------------------------------
        .var music = LoadSid("Nightshift.sid")
        BasicUpstart2(start)
start:
        lda #$00
        sta $d020
        sta $d021
        ldx #0
        ldy #0
        lda #music.startSong-1
        jsr music.init
        sei
        lda #<irq1
        sta $0314
        lda #>irq1
        sta $0315
        asl $d019
        lda #$7b
        sta $dc0d
        lda #$81
        sta $d01a
        lda #$1b
        sta $d011
        lda #$80
        sta $d012
        cli
        jmp *
//---------------------------------------------------------
irq1:
        asl $d019
        inc $d020
        jsr music.play 
        dec $d020
        pla
        tay
        pla
        tax
        pla
        rti
//---------------------------------------------------------
        *=music.location "Music"
        .fill music.size, music.getData(i)

//----------------------------------------------------------
// Print the music info while assembling
.print ""
.print "SID Data"
.print "--------"
.print "location=$"+toHexString(music.location)
.print "init=$"+toHexString(music.init)
.print "play=$"+toHexString(music.play)
.print "songs="+music.songs
.print "startSong="+music.startSong
.print "size=$"+toHexString(music.size)
.print "name="+music.name
.print "author="+music.author
.print "copyright="+music.copyright

.print ""
.print "Additional tech data"
.print "--------------------"
.print "header="+music.header
.print "header version="+music.version
.print "flags="+toBinaryString(music.flags)
.print "speed="+toBinaryString(music.speed)
.print "startpage="+music.startpage
.print "pagelength="+music.pagelength

Assembling the above code will create a musicplayer for the given sidfile and print the information in the music file while assembling:

  SID Data
  --------
  location=$1000
  init=$1d70
  play=$1003
  songs=1.0
  startSong=1.0
  size=$d78
  name=Nightshift
  author=Ari Yliaho (Agemixer)
  copyright=2001 Scallop

  Additional tech data
  --------------------
  header=PSID
  header version=2.0
  flags=100100
  speed=0
  startpage=0.0

TIP: If you use the –libdir option to point to your HVSC main directory, you don’t have to write long filenames. For example:

.var music = LoadSid("C:/c64/HVSC_44-all-of-them/C64Music/Tel_Jeroen/Closing_In.sid")

will be

.var music = LoadSid("Tel_Jeroen/Closing_In.sid")