TECH TIPS

Simon Goodwin brings up more Excuses and Exclusives on the Spectrum 128 and Cheetah SpecDrum — plus all you ever wanted to know about Interrupt Mode 2!

Well! What can I say? Part of last month’s TECH TIPS vanished into a wormhole in space (somewhere between Editorial and the Art Room, actually) and our whizzo scoop on SpecDrum sounds ended up bereft of a listing and a table.

At least, I hope it was a wormhole.

Besides catching up on the missing bits of last month’s column, this month I’ve got more dirt on the Cheetah SpecDrum. I explain how to vary the volume of drums and produce a Fairlight-style graph of every sound. There’s enough information (Art permitting!) for you to make up your own drums, or add effects to the sounds Cheetah supply. The results turn your £30 drum box into a gadget that can out-perform semi-pro devices in the £100–£200 price bracket.

Having saved at least £140, you can rush out and buy a Spectrum 128. At long last the CRASH machine has arrived at chez Goodwin; in this issue I’ve got information on RAM paging (including an exclusive trick which lets you access all 128K from BASIC) and an in-depth analysis of the real difference between the new machine and its predecessor. I’ve only had the Spectrum 128 for a few days, so I’m still finding out about its inner workings. Next month I should have a copy of the Spectrum 128 Technical Guide, so I’ll really be able to blind you with science.

KEY INFORMATION

If you want the extra editing functions of the keypad, but don’t want to pay the £20 that Sinclair Research were asking, I can tell you how to get the same effect from the normal keyboard... the add-on keypad gives you new editing functions on single keys. The Spectrum 128 has to recognise these somehow; it uses the key-codes which follow the normal Spectrum user-defined graphics. On a 48K machine you can type letters from A to U in GRAPHICS MODE to get the corresponding 21 user-defined characters. Letters from V to Z are ignored.

But the 128 treats those ‘spare’ codes as editing commands. In each case, in the absence of a keypad, you have to press the GRAPH key — near the top left comer of the keyboard — before and after the appropriate letter. The first press selects GRAPHICS MODE, so that the keys have their special effects, and the second press switches the mode off, so that you can type normally thereafter. Annoyingly, unlike the 48K machine, the 128 doesn’t change the cursor when GRAPHICS MODE is selected.

GRAPH V GRAPH instantly moves the cursor to the start of the last line of your program. GRAPH W GRAPH takes you to the very beginning. GRAPH X GRAPH propels you to the end of the line — very useful that one — and GRAPH Y GRAPH moves the cursor to the start. The last ‘secret’ key-code, GRAPH Z GRAPH, toggles the editor display between the top and bottom parts of the screen.

ROM WRONGS

These functions only work when you’re in 128 mode, but they have a lingering effect when you try to use 48K software. When the new machine is put into 48K mode it ‘hides’ the extra 80K of memory and the 16K utility ROM, but it still doesn’t behave exactly like a Spectrum or Spectrum Plus. The main incompatability has the unfortunate effect of stopping Kempston (and compatible) joysticks from working in many games. The explanation is a bit technical, but here goes...

A ‘heartbeat’ signal generated inside the Spectrum causes it to stop what ever else it is doing and run a short machine-code program, 50 times a second. Normally this program just reads the keyboard and updates the computer’s internal clock. The routine is buried inside the Spectrum ROM, so you can’t change it.

However, it is possible to divert the effect so that another routine gets called every 1/50 second. Many popular games use this effect to read the joystick or keys, move sprites or generate sound effects. The diversion involves setting a software ‘switch’ inside the Z80 processor, so that it jumps to a routine indicated by the programmer instead of the normal ROM routine.

Unfortunately this mode — Interrupt Mode 2 — gives external devices control over which routine gets executed. Devices can alter the diversion by presenting different values on the computer bus — the connector at the back.

Games programmers don’t want this — they want the same routine to run regardless of the value on the bus. But the Kempston joystick interface upsets things by presenting values when it shouldn’t, diverting the machine-code in the process.

This, in case you are wondering, is why Tornado Low Level used to crash if you tried to play it with a Kempston stick connected — the interface made the processor look in the wrong place at every heartbeat.

Values on the bus can range from 0 to 255, so the processor can fetch the routine’s address from up to 256 different places. In 1983 Quicksilva’s John Hollis realised that a table of 257 identical bytes will always send the processor to the same address. (257 identical bytes, because an address takes 2 bytes.) Such a table is a bit wasteful (for some reason, John actually used about 700 bytes!) and the possible destinations are a bit limited, but you can be sure of a reliable call 50 times a second, whatever is plugged into the back of the computer. In Aquaplane this effect is used to give a two-colour border (sky and sea) by changing the colour as the TV re-draws the picture, 50 times a second.

This technique worked, but it used quite a lot of memory. Ian Oliver of Realtime Software had the fiendish idea of using the ‘empty’ locations in the old Spectrum ROM instead of a table in RAM. These happen to contain the right value (255) to direct the computer to the very top of memory. A relative jump instruction at address 65535 interacts with the -13 value at the start of the ROM (logically, the ‘next’ address) to send the processor to address 65524, where you can put a jump to anywhere you like. The whole trick uses just 12 bytes of RAM, and it is totally impervious to the effects of the Kempston interface. It’s very efficient, very clever, and programmers love it. Dozens of top games use the technique.

But... Sinclair have put routines to read the keypad into the previously-unused area of ROM in the 128! The ‘blank’ area is now full of code, so the trick won’t work. The problem can be cured if software houses go back to the old John Hollis method, but that needs much more space, in rather inconvenient places. Many games already use every byte on the 48K machine...

It’s hard to see what can be done to get around this problem, in the short term. Amstrad only show their ignorance by complaining that Spectrum programmers should “follow the rules”. Sinclair never published any rules about what should and shouldn’t be done on the Spectrum. If programmers had stuck to the information in the Orange manual we’d still be playing 3D Tanx and Mined Out...

128K FROM BASIC

The Z80 processor in all versions of the Spectrum can only address 64K of memory at a time. 16K is used for ROM and 48K for RAM. Older peripherals — such as Interface 1, ZX LPRINT, the VTX modem and so on — used a technique called paging to disable the ZX BASIC ROM and replace it, temporarily, with another.

A similar technique is used on the 128, to allow 128K of RAM to fit into the 48K space. Of course, you can still only have 48K at a time. As supplied, the Spectrum 128 uses 16K as workspace when programs are being edited, and the remaining spare 64K as a RAM disc — an area of memory into which you can SAVE programs or data. Unless you want to mess around with files, your program is stuck within the confines of the usual 48K.

CRASH EXCLUSIVE

But that’s just what Sinclair said. Contrary to what you may have read in other magazines, it is easy to switch the 128K around from BASIC. All you need is one POKE instruction! Before I spill the beans, I’d better explain how the 128K is arranged.

The memory in the new machine is treated as eight 16K pages, numbered from 0 to 7 in classic computer programmer tradition. Page 5 contains the normal screen memory and what would be present on a 16K Spectrum — addresses from 16384 to 32767. Page 2 contains the next 16K, from 32768 to 49151. Then things get interesting.

All the other six pages — 0, 1, 3, 4, 6 and 7 — fit into the space from 49152 to 65535. Of course, only one page can be accessed at a time. You select the page by storing the number of the page you want, plus 16, at address 23388.

Before you go swapping pages you should type CLEAR 49151, so that ZX BASIC doesn’t try to store information in the ‘top’ 16K — otherwise it will get very confused when the information vanishes and a new page appears!

I’m still waiting for the technical details of the 128, so I’m not sure WHY this POKE works — but it does. Normally page 0 occupies the top 16K. As soon as your BASIC program stops, page 0 re-appears and something POKEs 16 back to 23388 — but you can PEEK or POKE, LDIR or whatever in the ‘new’ pages while your BASIC program runs.

For example, write a program that starts with POKE 23388, 17 (page 1) and then examines the contents of memory from 49152 onwards. You will see the contents of the first quarter of the RAM disk. The next three quarters are in pages 3, 4 and 6; they can be accessed by POKEing 19, 20 and 22 (16 plus 6) respectively. You can look at the editor’s workspace, and the RAM disk directory, by selecting page 7 with POKE 23388,23.

Most amazingly, you can even end up with the same page of RAM in two places! Try this line:

1 CLEAR 49151: POKE 23388,21: POKE 49152,255: PAUSE 0

This moves page 5 into the top 16K, and then POKEs 255 at the start of the page. However, video information from 16384 upwards is still being read from page 5. The POKE to 49152 puts a line on the screen — even though the screen is at 16384. The same memory is appearing in two places!

You can do the same with page 2 — normally 32768 to 49151 — but you should be wary of POKEing it as you might corrupt your BASIC program.

It’s a fiddle to gain access to all 128K, but it can be done. Unfortunately you can’t divert RAM into the bottom page — where the ROM normally appears — and switch the video memory out of the normal 64K completely. So you can’t run the CP/M business operating system on the Spectrum as you can on the ‘other’ Amstrad machines. Still, who cares?

HARD FAULTS

The edge-connector at the back of the 128 is missing a few signals, compared with the Spectrum. It is no surprise that the old display signals (U, V, Y and VIDEO) are unconnected, as the new machine has an RGB and Composite video output socket.

More importantly, the IORQGE signal has gone. This used to allow external devices to ‘turn off’ the Spectrum ULA so that they could imitate the keyboard. The original version of the Comcon joystick interface, among others, used IORQGE, and wouldn’t work on the 128. A new 128-compatible version is now available.

128K INSTANT INTERFACE

The other joystick interfaces I got working were an ancient Stonechip programmable port, an Interface 2 (after pressing RESET) and — of course! — the Instant Interface, documented in the December 1985 TECH TIPS.

You’ll need a copy of the original article to fit the port, but here are some new points to remember. There are eight screws on the underside of the machine — three long ones, by the metal heat-sink, a sharp edged one by the edge connector, three on the right hand side and one on the bottom lip. As ever, remember that you invalidate your warranty by pulling your machine apart.

The six wires from the joystick go onto the backs of the keyboard connectors; these have been moved, but are otherwise identical to the ones on the 48K machine. The new circuit board is held in by two very short screws near the front edge of the machine. Leave the three screws by the heat sink alone.

You must unplug the regulator, on the right, by pulling gently on its white connector. Prise the reset switch vertically out of its slot, and then turn the board upside down for soldering. When you put things back together, note that the regulator wires should be coloured Green, White, Red from left to right as you view the machine with the edge-connector pointing away from you. Don’t try to test the machine until you’ve re-connected the regulator!

MORE TESTING

I tried a few other peripherals on the 128. There seems to be a general problem with devices that use input ports — the Datel sound sampler was able to produce noises (via port 127) but I couldn’t read anything back from the same port. Perhaps the ‘strobe’ port — number 191 — was not working properly.

Amazingly, my Currah Microspeech worked first time, automatically selecting 48K mode and chattering away quite happily on the new machine. Microspeech is available at a silly price nowadays, and it is good to see that it works on the new machine. The BETA Disk system is definitely NOT compatible with the 128, and I hear that the VTX-5000 modem won’t work either.

I found that a ZX LPRINT 2 parallel printer interface worked fine on the 128 in 48K mode. In 128 mode you MUST use a printer connected to the serial port — the ZX Printer won’t work in that mode, not least because some of the new System Variables are stored in the ZX printer buffer!

If you’ve got a Centronics printer you may be interested to hear that serial to parallel convertors for the QL work perfectly on the 128. The plugs (for once) are the same. I tested this with a Connexions QL interface, bought at Boots, and it worked straight away. COPY generates codes for a EPSON FX (or compatible) printer. The Miracle Systems QL interface should also work.

The Cheetah SpecDrum seemed to suffer from software, rather than hardware, incompatibility. I could push the cones of my speakers back and forth by sending different values to port 31 from 128 BASIC, but the drum software wouldn’t work in 128 or 48 mode. This is a shame, because the SpecDrum could do a lot with extra RAM — you could have about 40 different drums loaded at once, using the page-flipping technique explained earlier.

SPECDRUM REVISITED

Back to humble 48K Spectrum users now, with further hints about Cheetah’s SpecDrum. The SAMPLE EDITOR program, which went missing last month, lets you load any drum sound into memory. You’ll need to use the Cheetah Kit Editor to extract individual drums from a kit, but you can load the RIM and HI TOM sounds directly.

The extra lines from 600 to 620 print out the name and type of a sample, once you’ve loaded it. Of course, you can change any of this information with POKEs.

DRUM TUNING

Once you’ve got a sample in memory you can tailor the sound, in just about any way. Each sample is made up of 2–3,000-odd numbers, representing back and forth movements of a wave (or speaker cone). The computer plays these back at high speed, and electronics in the SpecDrum convert the numbers into a changing voltage. 20,480 numbers are processed by the hardware every second, which explains the high quality — the bandwidth or tonal range of the system is about the same as a good cassette recorder or a Medium Wave radio station.

The SpecDrum is an eight-bit system, which means that it can cope with 256 different levels. There’s only one hardware channel, but the effect of three sounds at once can be produced by adding together the level for each sound.

To make the adding easier, each byte is stored as a signed value, between -128 and 127. The Spectrum’s PEEK command treats negative values as if they had 256 added to them, so a little code is needed to correct things. POKE copes perfectly happily with signed values.

ACOUSTIC SIGNATURES

Line 700 scans through an entire sample. The sample should be loaded with the other program, to set the value of the variable (the sample type). Line 710 converts each PEEK into a signed value.

The first line 720 just plots the graph of the sound across the Spectrum display. If you want to see this work well, try plotting the KICK D from the Latin kit. The scale is compressed, to fit the entire sound on the screen; you may find it is better to look at only part of a high pitched sample, by removing the INT, brackets and /12 in line 720. The plot will stop with an error-message when the edge of the screen is reached.

EMPHASIS

Unlike the SpecDrum, most real drummers bash away at varying levels as they play. The SpecDrum only plays each drum at one volume, and this is very limiting musically. Upmarket drum synths have an emphasis button which can be used to make certain beats extra-loud.

You can adjust the levels of the SpecDrum samples by multiplying or dividing the stored values. Large factors lead to distortion, but a factor of 2 is barely discernible to the ear, so I find I get best results by contrasting doubled and halved samples. Simple rhythms played on one drum, alternatively using two levels, sound great.

To change the level of a sample, use line 700 and 710 to read each value and add the second line 720. Set FACTOR to 2 or 0.5 before you GO TO 700, and the sample will be turned up or down respectively. You can check this by re-printing the graph. I POKE a ‘plus’ or ‘minus’ character into the names of samples which have been processed in this way, to remind me what I’ve done when I come to re-load the sound.

The waveform drawn on screen by the output that normally sounds like the Kick Drum in the SPECDRUM Kit. Note the STOP statement that concludes the artistry...

 
SAMPLE EDITOR LISTING:
100 CLEAR 26767
110 FOR I=26768 TO 26704
120 READ C: POKE I, C: NEXT I
130 PRINT "Play drum tape."
140 POKE 26780, 136: POKE 26781,5
150 GO TO 300
200 PRINT "Tap a key to save." : PAUSE 0
220 POKE 26780, 194: POKE 26781, 4
300 POKE 26771, 165: POKE 26774, 8
310 POKE 26775, 0: POKE 26777, 0
320 RANDOMIZE USR 26768
330 LET T=PEEK 26789
400 POKE 26771, 175: POKE 26774, 0
410 POKE 26775, 8+-4*(T=130 OR T=132)
420 POKE 26777, 255
430 RANDOMIZE USR 26768: STOP
500 DATA 175, 221, 33, 0, 104, 17, 0, 0
510 DATA 62, 0, 55, 205, 0, 0, 245, 193, 201

EXTRA ROUTINES:
Display drum details:
600 PRINT "Drum type: "; PEEK 26789; " . Name " ;
610 FOR I=26790 TO 26796: PRINT CHRS$ PEEK I;
620 NEXT I: PRINT: STOP

Graph sample:
700 FOR I=26799 TO 28846+1024*(T=130 OR T=132)
710 LET L=PEEK I : IF L>127 THEN LET L=L-256
720 PLOT INT ((I-26799)/12), 88+L: NEXT I

Adjust emphasis (suggested FACTORs 0.5, 2):
720 POKE I, L*FACTOR: NEXT I

TABLE 1: SpecDrum channels, drum positions & sample sizes.

Position  1   2   3   4   5   6   7   8
Sample    2K  3K  3K  3K  2K  2K  3K  3K
Channel   1   2   2   2   3   3   3   3
File type 129 130 130 130 131 131 132 132

CLIPPING

It is important that the total level of all the drums being played never exceeds 127 or drops below -12, or the sound will be badly distorted. This can never happen when you use the standard drums, because they are recorded so that the total of all the loudest drum levels is within a safe range (the Bass drum gets the most range, and the other two channels share the rest).

If you adjust the volume of drums you obviously run the risk that you’ll exceed the proper range. It’s up to you to avoid combinations that do this — it’s very easy to tell when clipping takes place, because the sound is awful!

Once you’ve got a sample in memory you can play about with it to your heart’s content. You can add the first part onto the second, giving an echo result, or POKE a made-up waveform into memory. You can get a good idea of the shape of sounds by plotting the graph of the Cheetah drums.

THE END

Well, this month’s column has been very technical but I hope you’ve found it interesting nonetheless. The Spectrum may be four years old but it’s certainly far from played out as an enthusiasts’ machine. Next month I’ll take a look at the Genius assembler from Oasis/Ocean, which promises to beat all other Spectrum machine code systems hands-down (really!). I’ll also explain more about the inner workings of the 128, including — hopefully — a fix for some of the problems mentioned this month.

Your letters, on any Spectrum-technical subject, are welcome. A parcel of letters was lost, early in April, between CRASH and my Black Country hideout, so I must apologise on behalf of the Post Office and ask anyone who wrote in then to try again — as far as I know I’m up to date with all the readers letters that have reached me, and we’ll use Registered post from now on.

The address, as ever, is: TECH TIPS, CRASH, Ludlow.