/ \ / \ A ton of type-ins this month! One is long and possibly / \ loud; the rest are short and spectacular. We hope you like T Y P E - I N S the section's new look. Keep them coming. /_________________\ _____ _ __ _ __ | | __ _ __ ___ _/_ __ _ __ /\ _ __ ___ __ | __| |-- __\ | <__ | / \ | /__\ | | \ / \ | / | _|___| <__| _|_ ___> _|_ \__/ _|_ / \ _|_ _| | \__/ _|_ \__| SOUND DIGITIZER by Richard Monteiro With this amazing listing Arnold can speak with your voice - or mimic Frankie Goes To Hollywood - or reproduce any sound a microphone can record on an ordinary cassette. The program is a simple sound sampler. When you play the audio tape on the 464's datacorder or a tapedeck plugged into the 664 or 6128, the sounds are converted to the digitized form that Arnold can remember. With a simple command you can reproduce it out of his speaker. Imagine what your computer could say at strategic points in your games. (Don't be too rude, now!) A lot of hard work is in store for you with all this typing. Type in the listing carefully. It's best to get a friend to dictate while you type - goes more quickly saves losing your place by looking back and forth from paper to screen. The data statements actually consist of machine-code produced using the Maxam assembler. You won't need an assembler because the Basic program simply pokes the numbers to memory, starting at location &9000. The listing contains an elementary checksum routine: all the numbers have to add up to 57871 or you have made a typing mistake. It may help to realize the data is made up of hexadecimal numbers, so you shouldn't be typing anything other than the numbers 0 to 9 and A to F - always two digits, comma, two digits. Save the program before you run it, or you might lose your work! Instructions for saving it are tagged onto the end of the listing as REM statements. You need not type these in, but it's not a bad idea to keep the directions in the program in case you can't find this printed page in a year's time. When you run it, one of two things could happen. If you get the message 'Error in data,' it's back to the start and check all those data statements again. If all is correct you will see 'Data OK - well done' and the cursor returned for your control. You will now have some new commands to play with, issued via Resident System Extensions (RSXs), commands preceded by the bar, '|', which shares a key with '@'. (Yes that's right, bar-commands: two pints of lager and a packet of crisps, please!) |RSOUND has to have several commas and numbers following it - parameters - to instruct the program on the correct course of action. The computer needs to know location and length: where in memory to load the sound data and how much of it. These two parameters must be present, otherwise the noisy message 'Parameter error' will present itself. A third optional variable controls speed or rate of data entry into memory. Before deploying this command, insert a cassette with music, your voice or any other sound into the datacorder. A message will surface asking you to 'Press a key.' Do as requested and the sound data will load. The format of this command and the other commands is shown below. |PSOUND is similar to |RSOUND in that the first two parameters must be present. That is where the similarity ends, as |PSOUND instructs the computer to output through the Amstrad's internal loudspeaker any data it may have picked up during the execution of |RSOUND. Again there is a third possible parameter; this time it controls the loudness at which that sound will be output. |R and |P are identical to |RSOUND and |PSOUND. These are for all incredibly lazy people who hate long commands - I am just too kind! Due to the programming technique employed, it is not possible to speed up or slow down the rate at which the sound data is output - this is constant. You will get that type of effect only if, when recording into memory (using |RSOUND or |R), you alter the third parameter from its default value of 13. This number can range between 1 and 255. The larger the number, the slower the sound data will be read into the computer; consequently when playing back (using either |PSOUND or |P), the sound will seem to have been speeded up. This may sound rather daunting. Don't worry if you have not fully grasped the situation: trial-and-error is the best method of teaching yourself. Now follows the promised layout of the commands: |PSOUND, location, length, rate of data entry |RSOUND, location, length, loudness location can be between 0 and 65536 (&FFFF) length can be between 0 and 65536 (&FFFF) rate of data entry can be between 1 and 255 (&FF) loudness can be between 1 and 15 (&F); 15 is the loudest To summarize, follow these short steps: 1. Place the cassette with your voice, music or anything into tapedeck 2. Type in direct mode: |RSOUND,&3000,&5000 (Return) 3. Follow the prompts 4. When 'Ready' appears, type: |PSOUND,&3000,&5000 (Return) 5. Wow! 6. Read the article again - try something more adventurous. __________________________ | | | [Listing - DIGITIZE.BAS] | |__________________________| Further bright sound ideas After typing in the first listing, and playing around with it for a while, you may become stuck for ideas. Following is a program that will allow you to record, play back, load and save any digitized sounds. It is essential that you run the main digitizer program primarily. This loads all the machine-code into memory, which contains the routines to load in the sound data and output it again through the Amstrad's built-in speaker. The Sampler program allows three separate sounds to be loaded from tape into memory and played back individually. The sample time for each is approximately four seconds - taking up about 5k of RAM. If feeling adventurous you could expand on this skeletal program, giving the possibility for more samples, variable-length samples and so on. This program is intended to stimulate your own ideas toward formulating a program incorporating digitized speech. One such application could be password protection for your program: If someone enters an incorrect code, a harsh voice (yours) comes booming through the speaker telling him to 'Get Lost!' Or you could set up keys to say their name when pressed - might be useful for verifying input, or for teaching a toddler to recognize numbers. The possibilities are endless. __________________________ | | | [Listing - SAMPLER.BAS] | |__________________________| Motor control Here is a listing that will add two RSX commands, proving especially useful for users of the 664 or 6128. Depending on the tapedeck, some have to type |TAPE then CAT just to be able to rewind a tape - all a bit awkward. Alex Aird of Birmingham has come up with a helpful soloution to this problem. Type in the listing, and if all has been entered correctly, a message telling you that you have 'extra commands available' will appear. These extra commands are |ON and |OFF. Their action is simply to start and stop the cassette motor - nice and neat! __________________________ | | | [Listing - ONOFF.BAS] | |__________________________| Kaleidoscope Alex Gough of Hastings, Sussex, has sent a marvellous listing. There are virtually endless variations of patterns. A great deal can be user-controlled; the best idea is to try different parameters yourself. Trying to explain what each option could do would take a lifetime. Once each pattern has been completed, the computer will beep rudely at you. Pressing N takes you to the beginning of the program; S will save the screen picture to tape or disk. __________________________ | | | [Listing - KALEIDO.BAS] | |__________________________| Patterns An interesting program from Mr P Tunstall of Kingsbury, Staffs; its small size does it no justice. By typing in various parameters, the computer rapidly draws complex designs on the screen. __________________________ | | | [Listing - PATTERNS.BAS] | |__________________________| Hypnotic Simon Tully from Cornwall has produced a listing which is nothing short of hypnotic. Warning: Amstrad Action is not responsible for any ill effects resulting to readers through misuse of this program! __________________________ | | | [Listing - HYPNOTIC.BAS] | |__________________________| Spiralu Mr B A Knight from Mortimer,Berkshire, has sent a fairly short routine which takes a very long time to execute - ample time to cook your lunch and eat it! Nevertheless, this is an interesting listing worthy to be typed in. It shows good use of the CPC's mathematical functions and what they are capable of. __________________________ | | | [Listing - SPIRALU.BAS] | |__________________________| Spirald is a variant of Spiralu. The lines listed are the only ones that need to be altered. _____________________________ | | | 1 ' Spirald | | 20 FOR a=110 TO 539 STEP 10 | | 50 z=75*SIN(a/639*PI*6) | | 80 FOR b=320 TO 629 STEP 10 | | 110 z=75*SIN(a/639*PI*6) | |_____________________________| Stained glass This fine offering from Alastair Scott of Grangemouth, Stirlingshire, shows off the powerful Fill command available on version 1.1 of Locomotive Basic (664 and 6128 owners only, I'm afraid). The program itself takes several minutes drawing everything up; the wait is well worth it, though! __________________________ | | | [Listing - STAINED.BAS] | |__________________________| Double height Great stuff from Leighton Derrick of Port Talbot. He has shown that it is possible to print double-height characters using only Basic commands - no need to revert to machine-code. Well done. Unfortunately it is rather slow, but then that's Basic for you. Following Leighton's offering is a machine-code alternative - note the speed difference! The message you want printed in double height must be inserted within the quotes on lines 40 and 110. The number 26 in line 50 indicates that the character(s) to be displayed total 13*2; therefore if your sentence comes to 20 characters, the number will be 20*2 which is 40. Following the 26 in line 50 are the symbols '*1'. The figure after the multiplication sign ('*' in Basic) will have to be altered depending which screen mode you are using. As it is set up, it's ready to use in Mode 1; changing the number to 0.5 will allow you to use it in Mode 2, and a 2 allows use of Mode 0. __________________________ | | | [Listing - DHEIGHT.BAS] | |__________________________| Following is the machine-code double-height routine. Type it in. If entered correctly, a message will be returned in double height; otherwise you get an error message - in normal height! The letters you wish to print in double height must be held in a string (for example, a$="WELCOME TO DOUBLE HEIGHT"). Follow this with a call to the machine-code program which prints the contents of the string: CALL &8000,@a$ in line 60. __________________________ | | | [Listing - DHEIGHT2.BAS] | |__________________________| Arrows and hats, we made a hash Do you have a problem with your printer giving £ when you want #? So did we. Line 10 of the first listing in Problem Attic last month first came out as £0 in two places. Eagle-eyed editor noticed it at 3 a.m. and printed out #0 on two itsy-bitsy papers to be stuck over. Unfortunately at 4 a.m. Toot pasted one of them upside-down. So 0# should be #0. CPC Basic uses the # - in computerese the sign is called hash - to mean the following number is a 'stream director'. Try looking that up in your handbook's handy index. Ha. Streams 1 to 7 are screen windows; stream 0 is the full screen. Stream 8 is the printer and 9 is a disk or cassette file. The system assumes 0 unless you say otherwise. So the function POS(#0) in that Problem Attic program tells which screen column the cursor is in. In assembly language # is used to mean the following number is a value rather than a memory location. The ^ and up-arrow cause similar confusion. On CPC keyboards it's the key shared with £ (the pound sign) two east of the zero. (On the PCW, after a half-hour's messing about, you can get it by pressing Extra and + together. Not very friendly.) Some printers show it as ^ (called caret or circumflex or even hat). Basic understands both - they have the same Ascii code - to mean index or exponent or power. By hand you would write two cubed as 2³ = 8, and on a steam-powered typewriter you could roll the paper back a bit. Neither is possible on screen, so you use the up-arrow. Now, if all this comes back correct from the typesetter, I think we have permanently licked the problem. And AA listings in future will be much cleaner in appearance than was possible on the dot-matrix printer. * We neglected to mention in the Simon listing (November Type-ins) that it was for the 664 and 6128 only. Apologies to any frustrated 464 users. * The GIGO program was correct as listed (October), but dozens of readers wrote or rang with problems. The most common mistake was confusing the number '1' with a lower-case 'l' used as a variable name around line 330 - our new style guide will avoid this in future. Data statements had other pitfalls: typing fullstops instead of commas or numbers larger than 255. _____________________________________________________________________________ | | | Some Amstrad Action Type-in guidelines | | | | One daunting task confronting all type-in freaks is that of deciphering | | listings. | | To make matters simpler for the typist - who is probably not an expert | | programmer - we have set out a few pointers on style that we would like you | | to follow if you plan to send a type-in listing to Amstrad Action. Setting | | out your listings in this way will give you more of a chance of seeing your | | masterpiece on one of these pages. | | 1 Most important of all is sensible use of variable names or letters. | | DO | | * use lower-case for variable names, rather than capitals | | * use short but meaningful variable names | | * use integer variables (for example, a%) if you want to speed up execution | | time | | DON'T | | X use letters that can be confused with numbers. Especially avoid the small | | letter 'l' or capital 'I' and both small 'o' and capital 'O'. Even 'B' can | | look like '8' on some printers. | | X use variable names identical to command words (you can't) | | 2 It is very useful to have adequate REM statements in the listing. | | For one thing, it makes it easier for human beings to read. Six months | | later someone with a pile of tapes can remember what any one is about and | | where to find the AA article about it. | | DO | | * put the program name, source and date at the beginning of the program | | * put a REM statement before every subroutine to outline its purpose | | DON'T | | X go mad putting REMs after every line | | X put your life story in REM statements | | 3 Avoid long multi-statement lines. They are difficult to follow, and | | just invite typing errors. Short lines make debugging easier too: 'Error in | | line 432' is only half helpful if line 432 is half a mile long. | | DO | | * split up complicated mathematical routines | | * keep lines short - 40 characters is a good maximum | | DON'T | | X have long lines of DATA statements (keep 'em short) | | X put command words and REM statements on the same line | | 4 Structure your programs - divide them into sensible procedures. This | | makes it easier for us to follow, easier for you to debug, and in the long | | run will develop your programming skills. | | And need we say ... If you send us anything, please make sure your name | | and address (in human-readable form!) is on every single piece, especially | | the label of the cassette or disk. And keep a copy. | |_____________________________________________________________________________| __________________________________________________ | ___ ___ | | | | | | o | | | | ___ _|_ _|_ __ __ ___ ____ | | |----| / \ | | | |/ \ < | | | | | | | | | | | \ | | _|_ _|_ \___/ \_ \_ _|_ |\___/ ____> | | | | | _|_ | | | | Welcome to this new section. Have you an | | astounding new hint to pass on? A trick you've | | discovered Arnold can or can't do? Share your | | tips with the world. This is the place to send | | them. | |__________________________________________________| Sorting colours on the Grafpad When the Grafpad was first released, reviews said, 'Good piece of hardware, but no indication of how to use your pictures in your own program.' In fact, this is very simple. When saved, your picture is 17k long and called 'filename.pic'. One thing to note, however, is that the default colour C1 on the Grafpad and the colour in Ink 0 on the Amstrad are not identical. I have written a short program that will allow you to load a Grafpad picture using the correct colours. [Listing - GRAFPAD.BAS] Mick Ellick Nailsea, Bristol Dazzling border Here is a quickie for you: [Listing - DAZZLE.BAS] Blast the bankman After several sleepless nights, I have finally found a way of incorporating the Bankmanager routine into your Basic listing. This avoids the need to load Bankmanager before running your own program. Just insert the short routine somewhere into your own listing: [Listing - BANKMAN.BAS] J Andrews (by telephone) Printer dump for Screen Designer I enclose a poke that enables screens drawn by Amsoft's Screen Designer to be dumped to a printer using any screen-dump package (Tascopy is my preference). Follow this procedure: 1. Run Tascopy (or equivalent) 2. Run the program below 3. Follow prompts, and insert cassette with pic. The picture will load as normal. On completion, a copy will be dumped to the printer. [Listing - SCRDUMP.BAS] Peter Walklett Leuchars, Fife