Sound effects Kai Weber, Reading, Berkshire. One of the better features of the now defunct Dragon was its Play command which allowed the user to simply enter music as a string rather than lots of confusing numbers as with the Spectrum's Beep command. The program I have written for the 48K Spectrum imitates the Play command but instead of using the Rom subroutine to produce the notes, it makes use of a clever piece of machine code which generates music more like that heard on a Commodore 64 or BBC Micro, greatly enhancing any program by giving it that professional touch. The program is written entirely in machine code, but the hex is held in Basic Data statements so that it can easily be Merged with any of your programs. In order to store the notes to be played, the routine reserves a string variable, namely T$. Each time you want the computer to scan T$ and play the notes held within, you should enter: RANDOMIZE USR 65070 The note generator has a range of three octaves and for the sake of argument I shall refer to them as upper, middle and lower. When called, the routine scans the contents of T$ one character at a time and depending on the character it finds it will act accordingly: 1. Characters in the range A to G - must be upper case - will cause the corresponding notes to be played. If the letter is followed by a hash symbol, the note will be played as a sharp and similarly if it is followed by a lower case b then the note will be played as a flat. 2. The characters 1, 2 and 3 are used to change octave. Character 1 will change the current octave to upper, 2 changes to middle and 3 changes to lower. If the character represents the current octave then no change is made. It should be noted that each time the routine is called, it will always start off in the upper octave. 3. The letter T - or t - is used to change the duration of each individual note. The code of the character follo- wing this letter is taken as the new duration and can therefore be in the range 0-255 thanks to a bit of string slicing. Because of the way the CPU works, a value of 0 is equi- valent to 255, 1 being the fastest possible. At the place where you want any following notes to have a duration of, say, 50, you should have something like this in the reser- ved variable, T$: "T"+CHR$ 50+"REST OF STRING" This is the simplest way to specify a new duration - if you are unhappy with a duration of 50 you just change the number following the CHR$ function either by editing the appropriate line or by using LET T$(XX+1)=CHR$ new duration where XX is the number of characters in T$ up to and inclu- ding the letter T. The routine will remember the duration that was used last time it was called to save you having to keep using the T command - the first time it is called it takes the duration to be 0, the slowest. 4. The letter P - or p - will make the computer pause for a very short period of time after each note has been played. 5. The letter O - or o - will turn off the pause between notes described above. The computer will remember whether it was on or off from the previous time it was called - the first time the routine is called the pause is on. 6. H - or h - will halt the computer for one fifth of a second whatever the status of the pause command described above. This command is, in effect, a manual pause and can be used to provide a lengthy gap between, say, two diffe- rent tunes by placing lots of Hs together. Five Hs will pause for one second. In addition to the above, pressing Break at any time will stop the routine with report D, Break - Cont repeats. By specifying a very short duration with no pause between notes, much better sound effects can be generated than are possible using Beep. For example, try something like this: LET T$="T"+CHR$ 5+"O3CDEFGAB2 CDEFGAB1CDEFGAB": RANDOMIZE USR 65070