Pages

Friday, 25 March 2016

The... castle... is alive, with the sound of music!

Very quick update - sound is fully implemented and (I think) fully working!

Details to follow...

UPDATE: Knight Lore uses the ZX Spectrum 1-bit sound output to produce, well, rather ordinary sound if we're being honest here. The sound was often criticised back in the day, but it still adds to the game play. Sound programming was never my strong suit, but it didn't take much to coax some beeps out of the Coco's 1-bit interface that sounded vaguely familiar.

I started with the music, reasoning that would be the easiest to compare playback speed. There's a table of notes in the code and each of the 4 tunes consists of an array of bytes that correspond to notes and a few bits of duration. It was straightforward to reverse-engineer and similarly trivial to re-implement in 6809. First cut sounded like music - just not a lot like Knight Lore music.

Not being able to see the issue in my code, I turned to MESS and recorded the main menu theme from both the original and my port. Loading them both up in Audacity, and aligning them approximately, I could confirm which counters were working and which weren't, as well as see the frequency difference. It wasn't too long before I spotted the bug in my code and viola - unmistakably the same tune! And as an added bonus, adding a single NOP in the inner loops slowed the speed to pretty much perfectly match the original.

With the low-level sound I/O and music done, it was a simple matter of working my way through the dozen or so sound routines, most fairly trivial and most worked first time.

There was one minor sticking point that resulted in a discussion with a few Coco gurus via FB. A couple of routines used the Z80 RLCA/RRCA instructions, an 8-bit rotate. The 6809, OTOH, only has 9-bit rotation instructions - all through the Carry bit. It wasn't too long during my aforementioned discussion that I'd hit upon a solution; if both accumulators on the 6809 have the same value, then LSLA, ROLB will effect a single RLCA. And as it happens, one routine used five (5) consecutive RRCA instructions, which I could replace with just 3 consecutive LSLA, ROLB instructions.

Although I haven't painstakingly compared all the sound effects just yet, what's there is pretty close and given the nature of the original effects, largely sufficient in any case.

Overall, I'm pretty happy that I was able to implement all the sound in a single day. I wasn't sure whether it would make the cut for the CocoFEST demo, but there it is!

No comments:

Post a Comment