It is Halloween and Octobers Program of the Month is right on time. When I pulled the listing for The Haunting from my stack I knew it would be perfect. Although short, I knew Id be challenged as this program of the month requires something I hadnt needed before. That something was sound.
Fortunately, I was pretty sure the emulator I use, EightyOne, supported sound. Unfortunately, my Mac had just updated to El Capitan and guess what, my emulator crashed on start. After a half hour of forum searching I figured out how to upgrade my Wineskin wrapper and engine. Back in business, I quickly determined that indeed EightOne supported sound. To be specific, it had a sound output option that emulated the cassette plug sound I needed. No, not the XY board or other add-in. I needed the original sound output used to read/write programs to cassettes.
The original ZX81, not modified, doesnt support sound like most other programs. There is no sound chip or way to make music using BASIC or even machine language. At least, not the kind of stuff you and I would call music. However, the ZX81 did send a constant hum out of the tape port. That hum is the from the ULA chip and isnt something you normally use unless saving a program.
However, the ZX81 is unique in that it has a FAST and SLOW mode. The tape hum will change to a higher pitch when switching to FAST mode. Switching back to slow drops the hum back to a lower pitch. Switching between the two modes allows you to almost emulate a note. I say almost because the results arent always the best, but its better than nothing.
The program, although small, has a couple of parts. To start, it sets up a variable of fifty notes. It then proceeds to load that variable from a string array of numbers. The routine loops through the string, converting those numbers to integers in sequences of three. For example, the first nine numbers of A$ are 764100150 which becomes the numbers 764, 100, and 150. The program loads those three numbers into the first three slots of the numeric array variable A.
The second section then walks through the fifty notes. For each note, the program loops for the length of the note oscillating between SLOW and FAST modes. This is the routine that The Haunting uses to generate music on the ZX81.
At the end, the program prints THE HAUNTING and then plays the song again. I must not have played the song much because if you let the program keep running it will eventually die with an error. You can only print 22 lines of text before it will stop, unable to print another line of text.
Making the ZX81 play music this way is ingenious and not something I figured out. I read about the technique in a book and thought it would be fun to try. Sadly, it sucks. The music is horrible. I guess it is fitting for Halloween, but I really think I could have done better.