By Neil Halliday
The SNDH file format was created in the mid 90’s by BDC of Aura Crew to unify replay routines for the multiple sound players that existed at the time. This meant hundreds of music files could be played using a single consistent interface. The files themselves contain the original reply source code, but with an SNDH wrapper around them to not only make replay simpler, but to contain meta data about the file too.
Load the SNDHPLAY.BAS file from the _STOS directory in the archive and follow the below text.
100 erase 12 : reserve as work 12,40960 : bload “verminat.snd”,12 : S12 = START(12)
So here we create 40kb of working space in bank 12. This is just me being really lazy and not bothering to find out the uncompressed size of the file and copying it to a different bank etc. most music files come in around 20kb or so, with the odd one being large, so 40kb will cover most files. We then load the SNDH file into bank 12 using the bload command, and set the S12 variable to the memory address of the start of bank 12.
110 d crunch S12
Now we d crunch the file using the GBP Extension. The extension will determine the packer that was used, and automatically decompress using the appropriate code. As GBP uses A0->A0 decompression, it means the uncompressed data overwrites the compressed data. Make sure that the memory bank has sufficient space reserved, otherwise you will be overwriting memory!
140 dreg(0)=1 : Call S12 : loke $4D2,S12+8
For those that don’t know, the DREG & AREG commands within STOS let you interact directly with the registers of the CPU. D standing for data and A standing for address. Here we are setting data register 0 to 1. This is because the replay routine uses the contents of D0 to hold the tune number that we want to play (a single SNDH file can have multiple pieces of music in it).
We then CALL S12. This is a direct call to the code at the beginning of bank 12. In this instance, it relates to the init_music_driver call which initialises the replay routine.
Once the driver is initialised, we install the VBL replay routine. This can be done actually in STOS code if we want. To do this we would just use CALL S12+8 after each WAITVBL command, but if our program isn’t running in 1 VBL, then neither will the music – it will slow down! Therefore the best way to call the music is to put it on the VBL List. The VBL list is a series of addresses that are executed every VBL, with priority over everything else. Therefore, we can guarantee that this code is executed every VBL and maintain it’s proper speed. There are a number of VBL list addresses, I’ve chosen $4D2. Once the address is loked to the VBL list, we can forget about it, and let it tinkle away whilst we get on with other things.
350 loke $4D2,0 : silence : call S12+4
Once we are done with our routine, we need to clear the VBL List. We do that by resetting the $4D2 address with 0. We use the SILENCE command from STOS to clear the sound registers, although we could do that manually if we wanted. The final CALL S12+4 calls the exit_music_driver routine provided by SNDH. This will clean everything up for us.
And that’s all there is to it!
The SNDH Format
All the files are generally compressed. I’ve found the ones that I’ve looked at so far have all been compressed using the Ice Packer. It doesn’t really matter which packer they are compressed with, my GBP Extension can cope with it. So, first of all we need to reserve some space for the uncompressed file.
In the zip file, you will find the current SNDH archive that was last updated in January 2018. Along with all the files is a _STOS directory where I have written a quick and dirty replay routine used in the above tutorial. This works with pretty much all the files in the archive, but there are a few drivers that don’t seem to work (the Spaz Crikey Wot a Scorcher for example don’t seem to work). If and when I figure these out, I’ll repost. Note that some of the sampled replay routines don’t conform properly to the specs, leaving the interrupts active. As I said, this is a quick and dirty replay routine, so I’ve not dealt with that!
Have fun listening to all the classic tunes, and enjoy the trip down memory lane using all the files in your STOS productions!
For more SNDH updates, visit the SNDH Archive Web Site.