Maya Grab [Day 8] – Playing sound

Wrapping up the text input routine by adding sound while typing. This is also the only place where sound effects are used. Some basic instructions how the SID sound chip can be programmed can be found here. Of course, it’s impossible to replicate 100% the same sound that’s used in the original game just by hearing it playing. Nevertheless, Thomas Langenkamp, the author of Maya-Grab, has programmed another game called Ratefix which is released in the same Input-64 issue and which uses exactly the same sound as Maya-Grab. The listing of Ratefix isn’t protected, so it’s very easy to find out all necessary parameters. Let’s take a look at the code:

51000 :
51005 REM – PLAY SOUND —————-
51010 :
51015 POKE S+1,SH
51020 POKE S+4,21
51025 POKE S+5,9
51030 POKE S+15,30
51035 :
51040 POKE S+24,15
51045 :
51050 POKE S+4,20
51055 RETURN

Sounds on the C64 can be produced by writing values to the first 24 registers beginning at address 54272 ($D400); there are 4 additional registers but they are used for something else. First three pokes are setting the sound for channel 1: frequency (S+1), waveform (S+4) and decay (S+5). The next one is setting the frequency for voice 3; I’m not really understand the logic behind it and why Thomas did it, but it fixed a waveform issue which appears from time to time when playing the sound multiple times. Next poke sets the master volume (S+24), and after that, the waveform is changed again immediately to make the sound short.

Program size: 8505 bytes, on disk 5842 bytes or 23 blocks
Free BASIC memory: 30406 bytes
Used BASIC commands: GOSUB

Source code

* * * * *