Presenting Tada! Beethoven

Author(s): Paul Ruiterman
Publication: ZX-Appeal
Date: November 1985
Pages: 14-15

BEETHOVEN

Or rather, the opportunity for you to behave like him on your ZX81. Yes indeed I have the privilege to present to you a devilishly clever little program which turns your ZX81 into an acceptable organ, an organ by the way which can be tuned by you. I do not know where I got this program from, I found it among my stack of machine language listings copied from a book or a magazine.

As you can see I have adapted the program in such a way that the BASIC,s among you can play along with the best of them.

In order for you to turn your ZX into an organ just enter the BASIC program as you see it and RUN it. Just make sure you reserve at least 80 bytes in the number one REM statement before you RUN, after you RUN the program once the REM statement should look as in the listing.

The layout of the keyboard mimics that of a real keyed instrument, you have two octaves to play with, the letters with the “´” beside it represent the black keys on your piano.

The music will come out of the speaker of your TV, You might have to tune your TV a bit. If you use a monitor or are looking for a better quality sound the signal is also available at your “mic” port, after all it is the “LOAD” routine that we are messing around with here,to make sound,in the first place.

In order to tune the individual notes you can change the values in the A$ at line 100, these values are ofcourse in hex and you can see in the accompanying table what key corresponds to what value. In order to increase the frequency of a note you must decrease the value in A$. To get out of the program after your composing session press Shift 1. You all have fun now.

ZX81 keyboard overlay with organ notes
ZX81 keyboard overlay with organ notes
Line 1 REM after RUN (machine code shown as tokens)
Line 1 REM after RUN (machine code shown as tokens)
1 REM [machine code - see figure]
5 FAST
10 CLEAR
30 LET I=16514
40 GOTO 100
50 FOR N=1 TO LEN A$ STEP 2
60 POKE I,(CODE A$(N)-28)*16+CODE A$(N+1)-28
70 LET I=I+1
80 NEXT N
90 RETURN
100 LET A$="9B89736900937E005E003B3128240000362C0000000F161E000A0C121A000000414C00383C4653"
110 GOSUB 50
120 LET A$="783D20FDC9CDBB02444D511428F73EFCBCC8CDBD071104401946AFB828E7DBFFCDA940D3FFCDA94018DB"
130 GOSUB 50
200 RAND USR 16558
9999 STOP
40A9   78         LD    A,B
40AA 3D DEC A
40AB 20 FD JR NZ,40AA
40AD C9 RET
40AE CD BB 02 CALL 02BB
40B1 44 LD B,H
40B2 4D LD C,L
40B3 51 LD D,C
40B4 14 INC D
40B5 28 F7 JR Z,40AE
40B7 3E FC LD A,FC
40B9 BC CP H
40BA C8 RET Z
40BB CD BD 07 CALL 07BD
40BE 11 04 40 LD DE,4004
40C1 19 ADD HL,DE
40C2 46 LD B,(HL)
40C3 AF XOR A
40C4 B8 CP B
40C5 28 E7 JR Z,40AE
40C7 DB FF IN A,(FF)
40C9 CD A9 40 CALL 40A9
40CC D3 FF OUT (FF),A
40CE CD A9 40 CALL 40A9
40D1 18 DB JR 40AE
A$ (line 100)  KEY  NOTE  OCTAVE
9B              Z    C     LOW
89              X    D     L
73              C    E     L
69              V    F     L
00              A    -     L
93              S    C´    L
7E              D    D´    L
00              F    -
5E              G    F´    L
00              Q    -     HIGH
3B              W    C     H
31              E    D     H
28              R    E     H
24              T    F     H
00              1    -     H
00              2    -     H
36              3    C´    H
2C              4    D´    H
00              5    -     H
00              0    -     H
00              9    -     H
0F              8    A´    H
16              7    G´    H
1E              6    F´    H
00              P    -     H
0A              O    C     H
0C              I    B     H
12              U    A     H
1A              Y    G     H
00              nl   -     LOW
00              L    -     L
00              K    -     L
41              J    A´    L
AC              H    G´    L
00              sp   -     L
38              .    C     L
3C              M    B     L
46              N    A     L
53              B    G     L

THE WORKS.

For those of you `into it´ here comes the explanation of `the works´.

At 40A9 we find a delayloop which is called from 40C9 and again from 40CE. The length of the delay depends on what is in `B´ which in turns depends on what key the player is pressing. Yes it is possible to use a DJNZ but it will screw up the timing.

40AE is our entry point. We start with a ROMcall which scans the keyboard, we load the result of the scan into `BC´ and check if a key was actually pressed. Let me backup a little here, note that we load `L´ into `C´ and then `C´ into `D´ we then increment `D´ and rescan the keyboard if the result of the increment was 00. It turns out that if no key was pressed during the keyscan `L´ would have held FF and since incrementing FF turns into 00 you can see what the game is here.

If a key was pressed we check `H´ to see if it holds FC, if it does a shifted 1 (or some other shifted key) was detected and we jump out of the program via the RET Z.

If all is well we use an other ROMcall which upon return will have loaded `HL´ with an address. This address points at the correct keycode in the keytable in ROM.

However we are not interested in the keycode, we have our own table of values. By adding 4004 (held in `DE´) to `HL´we end up with an address right in our own value table which starts at 4082.

We now load the value `HL´ points at into `B´ and check that it is not 0 ( if it is we return to 40AE). With the correct value in `B´ we now instruct the SLC to output signals on the TV/Cassette port for the duration of `B´ and voila, joyful sounds .

And that is how its done.

Paul R

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.