Hewson looks at the new RAM
AS I WRITE Sinclair has announced its new machine. I have known about it for some time, in common with a number of other software companies in the UK. However, we have all been bound by agreements not to breathe a word about it to the public.
Now the gag is off I thought you might like to know a bit more about using the machine for writing programs. The principle advantages are the extra memory which is available, the second screen memory and the new sound chip.
The extra RAM memory is a little difficult to get at, even when writing in machine code. This is because the total of 128K of RAM is divided into eight banks of 16K but the Z80 microprocessor can only address 64K of memory at a time, and that includes the 16K of ROM at the bottom of the address space.
In the new computer there are ten possible banks of 16K to be addressed, two banks of ROM and eight banks of RAM. The bottom 16K of address space is always used by one or other of the two ROMs, the next 16K can only be used by RAM bank number five, the next by RAM bank number two and the top 16K by any one of the eight RAM banks. Thus it is possible, although not particularly sensible, to have either of RAM bank numbers five and two accessible to the Z80 at different places in the memory simultaneously.
What would be more useful would be to have any one of the eight RAM banks appearing at any one of the three possible positions above the ROM, or, better still, appearing instead of one of the ROMs. Instead we are stuck with shuffling data back and forth via the top 16K of the memory map.
A new facility which will be of interest to machine code programmers is the second bank of RAM which may be used to hold the screen display. In the Spectrum the screen always resides at address 16348 - hex 4000. In the new machine this part of memory is in RAM bank number five. However, the new machine also supports the use of RAM bank number seven for screen memory.
Unfortunately RAM bank number seven may only appear at the top of memory as explained above. This does suggest the possibility of building a picture off-screen and switching it in more or less instantaneously, rather than copying it laboriously to 16384.
Those readers who are well-informed about machine-code programming will know that, because the hardware needs to get at the screen memory to maintain the screen picture 50 times per second, programs run more slowly when placed in the lowest RAM bank. This problem affects only one of three banks of RAM in the ordinary Spectrum but four out of the eight banks in the 128.
The new sound chip is a great blessing because it allows the programmer to set up some effects and then go away and get on with executing some other code rather than, as with the Spectrum, forever having to go back and toggle the loudspeaker at the correct moment. The effect transmitted through the TV speaker is also rather better than the old telephone-in-a-card board-box generated by the Spectrum.
Of course the price to pay for better sound is the extra work involved in setting up the registers with channel, amplitude, tone and envelope data. The manufacturers have identified a n entry point in the second ROM by which the machine code programmer can access the music system provided by the new Basic Play command. That is similar in principal to the way in which RST 16 can be used in the ordinary Spectrum ROM to use the facilities of the Print command from machine code.
|
How random is random?THIS MONTH'S LOOK at the system variables focuses on the SEED variable stored at address 23670. This number is used by the RND function to kick off the next random number calculation. Creating random numbers in a computer is a funny business because strictly speaking it cannot be done at all. A computer is a machine which executes a series of stored instructions and given that the starting point is the same and the instructions are the same it will always obtain the same result. A random element is not permitted to creep in. The usual way of getting round this problem is to use a sequence of instructions, or algorithm, which when fed a number, chops it around and rearranges its component parts rather like shuffling a pack of cards. ln the jargon of the trade this is called 'hashing.' The aim is to create a pseudo random number and a seed number. The seed can then be fed through the same algorithm to produce the next random number. Sometimes the seed for the next calculation is the preceding random number. Mathematicians have had fun in the past devising a number of hashing algorithms and then proving that the sequence of numbers created by them are more or less random. The Spectrum random number generator uses the calculation: Random number=(75*(SEED+1)-1)/65536 You can prove that by choosing some whole number as a seed and then comparing the result of the calculation with: 10 RANDOMIZE SEED 20 PRINT RND To finish off the exercise keep an eye on the SEED system variable at address 23670. You will see that, as its name suggests, it is this location which is used to store the seed for the next calculation. |