Home

LEARN PROGRAMMING - FOR FUN AND THE FUTURE

image

Contents

1. e c Ee 9 a M 880 __ 9 _ _ ee me _ _ 2 AA as o e c Es adi 0 9 0 2 oe NI T LEARN PROGRAMMING FOR FUN AND T
2. I4 COMPUTER COURSE IN WEEKLY PARTS EXE T a c cocum i sS ae ee ee ae lt lt 0 ale e i ai N R ayes cx ite uil tope ime lilt d d ae t AMMING FOR F 4 A T 1 Lo 4 Y tn M 1 230 T SSS TE e MH d EE o Lo PRESE ceo Ee o miss SE SSS a c coca eee a RE me LE ura Le eC EE eee a ce a Ree 5 cmo OH _ See Cc SS er e m e c A C O S Ew M lt a 0 sym 8 ae E Se SS a E SSS Oe e See Re od mtd OdE a ee as gt am lt ae a RR COME E lt a Com EE ee con COT rae poem iS Ode ELI Re SS Eum ee ee t c o M ME _ cam EL SS co m _ _ ER n nERR ME O ea Vol 2 No 14 BASIC PROGRAMMING 31 Making visual displays from your data BASIC PROGRAMMING 32 Useful for graphics or programming shorthand GAMES PROGRAMMING 14 Working up your own ideas MACHINE CODE 15 Fast moving graphics for these machines BASIC PROGRAMMING 33 For
3. 7X 81 Easy machine code graphics bn the Spectrum Commodore 64 BBC Micro Electron Dragon and Tandy have been covered in earlier chapters Now it is the turn of Vic 20 and ZX81 owners Neither of these two computers have the sophisticated graphics acilities of the others and in fact they cannot really be considered Praphics computers at all But there are ways of using machine code to generate simple but impressive on screen effects a 1 he Vic 20 does not use sprite graphics like e Commodore 64 nor do you have to define a grid before you start building UDGs Vic graphics are done by redefining the character set Each number letter of the alphabet and symbol that appears on the keyboard appears on the screen as a pattern of pixels These are normally laid out in 8x8 squares Those pixels which are on lit on the screen form the pattern which makes up the symbol The rest the pixels which are off or not alight make up the background To build up some design of your own all you have to do is redefine which pixels are alight in a particular letter to form part of the design then build up the whole figure by PRINTing these redefined characters next to each other The number of characters you MOVING Peo d deo DL DIT ae Here s a chance for Vic 20 and ZX81 owners to create some simple animated graphics Use the routines as t
4. K9 1 1330 K K 1 K9 Q IFPS 3THENPRINT 1340 RETURN 1350 1360 IFC lt gt 380 1370 X X LEFT C 1 C MIDS C 2 GOTO1360 1380 IFC lt gt 1390 FORQ2 1TOW IFX Z Q2 THEN 1410 1400 NEXT W W 1 2 W 02 W RR W 23000 1410 RETURN 1420 CLS MOTORON PRINT 161 POSITION TAPE PRESS ANY KEY AND THEN PRESS PLAY ON TAPE 1430 US INKEYS IFUS 1430 1440 1 L LOADING PROGRAM INPUT 1 N FORJ 1TON INPUT 1 5 J NEXT CLOSE 1 RETURN 1450 CLS MOTORON PRINT 161 POSITION TAPE PRESS RECORD ON O C TAPE THEN PRESS ANY KEY 1460 US INKEYS IFUS 460 1470 0 1 SAVING PROGRAM PRINT 1 N FORJ 1TON PRINT 1 T J NEXT CLOSE 1 RETURN 1480 PRINT 1 N FORJ 1TON PRINT 1 T J NEXT CLOSE 1 RETURN 1490 PRINT O PLEASE INPUT LINE NUMBERO O C O O O PRESENT LINES NUMBERED IN TENS 1500 INPUTK CLS 1510 K2 K 10 IFK2 NCITHENK2 N 1 1 1 2 PRINT 2480 1520 IFK2 lt 1THENK2 1 1530 IFK2 INT K2 THEN1550 1540 K2 INT K2 1 FOR K3 TOK2 1 STEP 1 T K3 1 TS K3 NEXT N N 4 1 T K2 1550 P1 1478 P0 P1 P2 0 1560 PRINT 448 P2 K TAB 6 T K2 P9 P LEN T K
5. You know that the PRINT AT coordinates of INPUT are 10 10 You also know that the top line of the border is one line higher than this So you subtract one from the first number 10 to give your first coordinate 9 You want the border to start one space before the word so you also subtract one from the second number of the INPUT coordi nates to give 8 Try to work out the numbers for the other parts of the border and check your answers against the coordinates given in the program above The program finishes the screen display by PRINTing a copyright message to remind users that it is illegal to copy programs and telling them to press any key to continue In fact when you do press a key instead of a game starting or you being presented with instructions for a game as might happen in a game program you are presented with a section of the INPUT part one index What happens when you press a key is that The finished display the Spectrum clears the screen and PRINTs the message INPUT PART 1 INDEX at the top of the screen As you can see if you look at the program there is no PRINT AT or TAB com mand so why is the message in the middle of the line Since only five free character squares are needed to place the message in the middle of the line spaces are put at the start of the PRINT statement inside the inverted commas instead of using a PRINT AT command After this the computer PRINTs a line of b
6. K2 INT K2 K1 K 10 K2 K2 10 1790 IFK2 gt N THENK2 N 1800 IFK1 lt 1 1 1810 2 lt ANDK2 N THENRETURN 1820 IFK2 lt THENCLS PRINT OBAD SET OF LINES GOTO1770 1830 CLS PRINT 96 FORK3 K1 TOK2 PRINTK3 10 C1 TS K3 NEXT 1840 RETURN 1850 2 1 1 K2 1 K2 K1 K IF N 76QELSE1 790 1860 NU 0 R 0 1870 S 1 1880 IFADS THENRETURN Debugging long programs Even the most experienced programmer has trouble keying in a long program like this assembler No matter how deft your fingers you are bound to introduce a bug somewhere Of course you ll spot many of these errors when you read over the program And the computer s own error messages will help you track down others if you are clever enough to work out what they mean But in a long program these error mes sages are sometimes not enough to help you locate the error in question line might be executed many times during a program but only falter when a variable has been set to an acceptable value by a rogue line elsewhere Luckily the Dragon and the Tandy both have trace programs which will help you diagnose problems with your long programs Switch on the trace by keying in TRON This is a direct statement and does not require a line number Then RUN your problem program and the trace will fill blank areas of the screen with the numbers of the line of BASIC being execu
7. Tie t 4 1 it IE Fey a L lt 6171 E HUC 211 L i d E mmm A NS A f C Cc EM ni Having sorted out the grid you can progress to entering your own set of location descriptions on the machine They should replace the existing location descriptions after Line 5000 Follow each location description with the line containing the possible exits as in the original program The variables N S E and W correspond to north south east and west They can be set to 0 or 1 0 means that there is no exit in that direction while 1 means that there is a way out The extra effort of typing in REM lines with the location numbers is well worth it Next change the GOSUBs in Lines 330 to 350 The first number following GOSUB in Line 330 is the line number where the computer will find the description of location 1 If there isn t a location 1 in the adventure you don t have to use all the squares on the grid then zero is entered instead The next number is the line number of the description of the second location and so on There must be a number for all of the locations in the grid MOVING AROUND If you have designed an adventure which is based on a different size grid from that used for the INPUT adventure you ll need to alter the movement routine at Lines 1000 to 1040 More specifically the north and south lines Lines 1010 a
8. and by specifying SCREEN 0 0 you can switch the screen back to green again Each time the program executes the loop the screen back ground colour is changed So that you can see the colours alternating a short pause is inserted by Line 100 The loop is completed by Line 120 If any key is pressed while the title page is being displayed Line 110 causes the program to go on to the next section The screen colour is changed to red by Line 130 Line 170 and the FOR NEXT loop in Lines 150 and 180 do the work of displaying the data read from Line 190 Each time the loop is executed a new line is used for the subject and page references The LEFT in the second part of the Line makes sure that the page numbers always appear in the same size panel The display will look a lot neater that Way One last nice touch is the loop in Line 200 This may seem to be absolutely pointless but its role is quite important Without Line 200 the program ends causing the message OK to appear against a green screen ruining your red 436 background MEN DRAGON TANDY tubo al into machine code hex when that s ASSE MBLER exactly the sort of mechanical process your computer is good at The assembler for the Dragon and Tandy is a little longer than the one for the Spectrum But this is because it includes an editor Although there are a good deal fewer instructions for the Dragon s 680
9. iB ET em j ic gt 5 5 Mites 15 PMODE3 1 20 PCLS 25 SCREEN1 1 30 DRAW BM 95 40 FOR T TO 40 ATN 1 STEP 06 50 LINE 8 T 95 40 SIN T PSET 60 NEXT 150 GOTO 150 This program plots a sine wave which has many applications in science and technology in music and in graphics displays Line 40 specifies a wave of five cycles each cycle is twice PI and Line 50 specifies how the wave is drawn See pages 302 to 308 for a fuller explanation of what is going on here By varying the values in these lines you can alter the shape of the wave considerably Only a few functions are stored in your micro s memory but you can plot any func tion provided you define it in the program Add these next few lines to the last program and RUN it again 70 PLOT 0 60 80 FOR 1 TO 220 STEP 5 90 DRAW 5 110 n 15 200 100 NEXT n 110 PLOT 0 100 120 FOR n 1 TO 220 STEP 5 130 DRAW 5 110 n 15 200 140 NEXT n 10 D 1 E 100 70 2 80 XX 80 20 3 85 T 20 YY T T 5 D4 E 90 FOR T 20 TO 20 100 LINE XX YY 80 T 3 T T 5 D4 E C 105 XX 80 T 3 YY TT 5 D E 110 NEXT T 120 IF D 1 THEN 999 130 D 1 E 120 C 3 607080 140 GOTO 80 10 D 1 E 256 70 REGION 5 80 POINT 2 140 500 D E 90 FOR T 100 TO 100 100 DRAW 2 TO 540 T T T 20 120 IF D2 1 THEN END 130 D 1 E E 512 REGION 2 140 GOTO 8
10. 1 ASR 119 3 RTI 59 m AUTOMATIC TRANSLATION OF ASSEMBLY LANGUAGE INTO MACHINE CODE CALCULATING JUMPS AND BRANCHES SBCA 178 1 NOP 18 NEG 112 3 90 DATA BITA 181 1 BGE 44 4 BGT 46 4 BHI 34 4 BLE 47 4 BLS 35 4 BLT 45 4 BRN 33 4 BVC 40 4 BVS 41 4 EXG 30 1 TFR 31 1 100 DATA COM 115 3 CWAI 108 1 DAA 25 0RA 186 1 TST 125 3 LEAS 66 3 LEAU 67 3 LEAX 64 3 LEAY 65 3 MUL 61 EORA 184 1 0RB 250 1 110 DATA ORCC 74 1 SEX 29 SWI 63 SWI2 4159 SWI3 4415 SYNC 19 EQU 1 2 FCB 2 1 FDB 3 2 RMB 4 JMP 126 3 120 DIMX 13 V 14 KK 13 YS 13 130 FORC 0TO12 READXS C V C KK C Y C NEXT 140 DATA PCR 253 7 PC 253 8 D 243 1 X 5242 1 Y X 159 U Y 191 S U 223 PC 150 DATA 5 255 241 1 240 1 A A 246 1 B B 245 1 CC D 251 1 DP 160 FORJ T09 READPUS J PU J NEXT 170 DATA PC 128 U 64 S 64 Y 32 X 16 DP 8 D 6 B 4 A 2 CC 1 180 CLS PRINT 43 assembler RSRS TAB 8 G GET FROM TAPE RSRSTAB 8 S SAVE ON TAPE RSRSTAB 8 ASSEMBLE 190 PRINT 2 296 E EDIT LINE RSR TAB 8 D DELETE LINE RSRSTAB 8 L LIST ON SCREEN 200 AS INKEYS IFAS 200 210 JJ INSTR GSEDLA AS 220 IFJJ OTHENPRINT lt A gt not understood FORJ 1701000 GOTO180 230 CLS ON JJ GOSUB1420 1450 1490 1710 1760 280 240 PRINT 1 PRESS enter TO CONTINUE ANYO O CJ LC OTHER KEY FOR MAIN MENU 2
11. TRON command Dragon Tandy du U UDGs Vic 20 428 429 V Variables list of for adventure game Acorn Commodore 64 Dragon Tandy Vic 20 425 Spectrum 427 W Words in adventures 424 426 The publishers accept no responsibility for unsolicited material sent for publication in INPUT tapes and written material should be accompanied by a stamped self addressed envelope LI Worried about pirates learning the secrets of your program techniques Find out how to PROTECT YOUR PROGRAMS LJ UDGs versatile and varied Discover how to use them in large numbers and how to CUSTOMIZE THE CHARACTER SET LI BAR GRAPHS AND PIE CHARTS are an attractive alternative to linear displays Learn the techniques of plotting them LA Enhance the playability of your games programs when you employ routines for JOYSTICK CONTROL FROM BASIC LI If yowve ever had screen problems take a good look at our guide to the pros and cons of TVS AND MONITORS A MARSHALL CAVENDISH 15 COMPUTER COURSE IN WEEKLY PARTS E Jil i 0 M 2 we ee ee ee ee ee s eee o e _ e Lh unl _ A 00 lt gt ae ee 9 er ee ins diii a a I dias ill i LZ o e e E 0 mee
12. a suitable The uses of Commodore graphics symbols extend far beyond just making pictures They are also frequently employed as a form of programming shorthand colour at each location where a graphic ap pears Remember that the screen code values are different from the ASCII code values QUOTE MODE Low resolution graphics are useful for supple menting high resolution graphics but are no alternative And this is really a secondary role to the use of symbolic graphics obtained in a line such as this by typing and after the first quotes 10 PRINT J The reverse heart symbol makes an ap pearance only after you ve entered quote mode or insert mode You enter quote mode simply by typing and exit by typing again The next time you type you re enter quote mode and exit it with the next and so on CLR the screen and try typing in the line without the first set of quotes While you ve got a clear screen try some thing else enter insert mode by pressing and keys simultaneously then press and simultaneously Lo and behold the reverse heart again Enter quote mode you can do this in direct mode simply by typing and find out what symbols you get when SHIFTled and un SHIFT ed cursor keys are pressed when the key is used to access the colours and reverse obtained on keys 1 to 0 and when the function keys are pressed EDITING PROGRAMS effect of quote mode and insert mode are superficial
13. be lengthened by 19 characters When the first program has been RUN and all the lines except the first REM statement have been deleted you have to modify the second program so that it will call the inverse routine This is done simply by adding 155 IF AS 1 THEN RAND USR 16606 memory location 16606 is where this new piece of programming starts and that routine will be called when you press the I key Press the I key once and the alien will change from black to white and its background will go from white to black Press it again and it will change back Hold the I key down to make it flash PSEUDO HI RES GRAPHICS As you no doubt know the ZX81 will not display high resolution graphics But there is a way of producing what look like hi res graphics using machine code This simple program POKEs numbers into the first five memory locations in a REM statement then calls the machine code program formed that Way 20 POKE 16514 62 30 POKE 16516 237 40 POKE 16517 71 50 16518 201 60 FOR 0 TO 30 70 16515 N 80 RAND USR 16514 90 NEXT N This will give you something on the screen that looks very much like hi res graphics Unfortunately there is no easy way you can move or control them IMPROVING YOUR DISPLAYS The title page and other screen displays in your program need to be carefully planned and constructed if you want a really professional look Here s how t
14. but that is very inefficient Line 160 controls the PRINTing of the DATA and sets the PRINT position The PRINT TAB command is used here to align the entries and page numbers so that they all start in the same column and look neat PRINTing an index is an ideal use for PRINT TAB as the row is automatically changed by the computer with every different PRINT state ment and the TAB sets just the position along the line The entries are PRINTed at the third column in from the left which is set by TAB3 numbers are then PRINTed in the same line but starting 25 columns in Using PRINT TAB both must be PRINTed with one PRINT command if you look at the program Line 160 has just one PRINT and separates each part with semi colons If a colon was used followed by another PRINT com mand the numbers would be PRINTed one line below their respective entries which would be rather confusing If you change the TAB 25 to TAB 25 32 or TAB 57 then there would be no difference This is because the TAB command moves the cursor to the specified column and if the number after TAB is more than 32 it is divided by 32 to leave the remainder It always stays on the same line unless backspacing is needed Backspacing is only needed if you try to PRINT TAB a number less than the column where the cursor is When you do this the Spectrum moves on to the next line of the screen and PRINTs there Try changing the TAB number to get a rough
15. end Now that the machine code has been POKEd in and is protected by the REM statement you can delete all of this program except the line containing the REM statement itself Then you can key in the following program which will make the graphic move around the screen 10 LET X214 20 LET Y 8 30 POKE 16571 1 40 POKE 16572 Y 50 POKE 16573 X 60 RAND USR 16514 100 LET A INKEYS 110 IF A THEN GOTO 100 120 IF AS 27 AND X 0 THEN LET 1 130 IF A X X 1 140 IF A AND Y gt THEN LET YzY 1 150 IF A L AND Y 20 THEN LET Y Y 1 160 POKE 16571 0 170 RAND USR 16514 180 GOTO 30 X AND X 28 THEN LET Lines 10 and 20 start the alien off in the middle of the screen Line 30 POKEs the number 1 into the machine code program which tells it to print the graphic rather than a blank space Lines 40 and 50 POKE the Y and X coordinates of the graphic which specify where it is on the screen into the next two bytes of the program The program is then called and the graphic is printed on the screen Lines 100 to 150 contain the standard routine to move something around the screen see page 57 When the program is RUN pressing the Z key will move the alien left pressing X moves it right P up and L down Line 160 POKEs into the machine code program and when Line 170 calls the program again it tells the computer to print blank spaces instead of the graphic This is to rub
16. idea of what various numbers actually mean in terms of screen positions Remember that there are 32 characters in each line PRINT AT and PRINT TAB do very similar functions but in different circumstances Whenever you want to PRINT a list of words or numbers on the screen such as an index or a high score table you should use PRINT TAB as this is more efficient you do not need to repeat it or to specify the row PRINT AT on the other hand is very useful for PRINTing a small number of items or if you want to change the height of an item on the screen Creating an attractive display is a piece of cake on the Commodore 64 and Vic 20 There s a vast number of ROM graphics symbols and easily embedded cursor and colour control symbols which can be included within parts of any PRINT statement Take a look at this version of the earlier opening page program 5 POKE 53280 5 POKE 53281 0 10 PRINT 7 Je Ed TAB 8 20 PRINT TAB ari L MARSHALLUJ CAVENDISH 700 30 PRINT 10 28 02 35 PRINT TAB 10 sa C1 COPYRIGHT LI C 2198402 40 PRINT 6 fy PRESS SPACE BAR TO CONTINUE 50 POKE 198 0 60 POKE 646 8 0 1 6 2 70 IF PEEK 197 60 THEN PRINT 53280 14 POKE 53281 6 END 80 T RND 1 7 PRINT e e e ed el 13 7 90 PRINT TAB 13 T T INPUT T 100 PR
17. pages 130 and 131 of the user manual iii ADVENTURES THE INEXT STEP By now you should have a fully functioning adventure game stored on tape In exploring its development you have seen how all the elements which make it up were brought together starting with just a bare outline of a story And this time you ll see how that game can be used as a basis for your own home grown adventures Some hints about altering the adventure have been scattered throughout the series of articles but this time you ll see in greater depth what has to be done It won t always be possible to be specific about the alterations because many of them will depend totally on the adventure you are writing but many alterations are simple to do if you follow the instructions later in the article Some of the techniques may seem a little daunting at first but if you try to write a simple short advent re to start with you should soon pick up the principles In the early stages don t try to make too many alterations simultaneously just work through the sections of this article systematically and you shouldn t go far wrong If you are a little puzzled by some of the BASIC in the program you can try looking in Basic Programming where many of the more common keywords have already been covered b ERN v EN b Vic 20 and 16K Spectrum owners will not be able to extend the adventure too much becaus
18. routines which can be used in any adventure such as the GET and DROP routines These can be used unchanged in any adventure that you write unless it s something very innovative Similarly INVENTORY Lines 1070 to 1130 is the same in any adventure so you can use the routine with no alterations as long as the array is the same and NB the number of objects has the same meaning in the new adventure Other routines which might find another home would include the lamp lighting routine as lighting lamps is quite a common occup ation in adventures The routine is at Lines 1490 to 1530 The remaining routines are probably not general enough for large scale poaching but when you write your own verb routines there are a few points to bear in mind The routines are basically there to check if the adventurer is trying to do something to the correct object and in the right location If the location is wrong then the program should display a message that s appropriate to the situation such as NOT HERE Whatever the outcome make sure that the adventurer knows what the effect of the last instruction was in other words whatever anyone tells the machine to do there must be a printed response on the screen When you have worked out your verb routines enter them in the program With the program numbered similarly to the INPUT adventure the place for these routines is between Lines 1070 and 2999 The computer has to be able to select
19. that the Spectrum PRINTs a clear line before PRINTing PRESENTS You can also get the Spectrum to PRINT a blank line just by entering the command PRINT with a suitable line number on its own The program PAUSEs for one second after this to give more emphasis to the next item to PRINTed the name INPUT Lines 50 60 and 70 PRINT INPUT with the FLASHing red and yellow border The border is made up of ROM graphics as you can see from the program which FLASH red and yellow A first attempt These Lines use a series of PRINT AT commands and show how flexible this com mand is You don t need to repeat the PRINT so longas you don t putasemi coloninthe Linein between the items you want to PRINT The various ATs are separated by semi colons They could equally well be separated by commas except that a comma would cause half a line of spaces to be PRINTed which might blank out what was on the screen already and so it is a good idea always to use semi colons unless of course you want to blank out what was on the screen at that position Working out the PRINT AT coordinates for the FLASHing border cannot be done using the calculations above since the border is not at the centre of the lines To work out the positions then you must take the coordinates from the word inside the border and try to add or subtract something to get the numbers for the border For example take the top line of the border
20. the adventurer will instruct the computer to do during the adventure You are interested in the verbs at this stage verbs as far as adventures are con cerned are not just limited to the strict gram matical definition but are either the first work in a pair or those words that will be used on their own Group the words together accord ing to their meanings the words which have the same effect on the adventure such as GET and TAKE or KILL and SHOOT Each group will need a number so note that down The verbs and their numbers are put in the DATA statements in Lines 140 and 150 Don t forget to enclose all the verbs with inverted commas Follow each verb with its number according to the meanings table Don t forget to re DIMension the arrays in Line 120 and adjust the NEXT loop in 2 C Line 130 according to the total number of v words you wish to use 9X The DIMensions of the array will depend on 3 how many lines of data there are and how many items of data there are in the longest line first subscript is the number of pieces of data in the longest line and the second subscript is the number of lines of data Feed all the data into Lines 40 to 70 if you have a lot of data create some new lines between these line numbers In any case count how many pieces of data are in the longest line In the unlikely case that all the lines are the same length yo
21. words so that the statement is exactly in the centre of the line first count how many character spaces the statement will take up Subtract this length from 32 and divide the number by two so that the remaining space on the line will be split evenly between the two sides of the line and add the answer to the number of the first space in the line You ll have to round up or down any halves The number you have left is the number of the first space that you will use in the PRINT statement Try to work out the PRINT numbers for a variety of screen positions and a variety of words of different lengths You can check your answers by PRINTing 0 them and seeing if the words that appear are where you want them 435 You might like to start PRINTing at a certain fraction of the line say half or one third of the way through the line This is very easy divide 32 by the relevant number 2 for a half 3 for a third and add this to the number of the first space in the line just as before Wherever you want to PRINT a position which is not exactly half way through a line but is at some obscure position you just have to guess roughly what the number 15 Just experiment until the result looks right You can use a grid like the one in the user manual and actually plan your PRINTing on that then all you need to do is to read off the PRINT numbers from the scales along each side The trouble with this is that it ta
22. 0 10 D 1 E 256 70 80 MOVE240 500 D E 90 FOR T 100 TO 100 100 DRAW640 T 4 T T 20 D E 110 NEXT 120 IF D 1 THEN END 130 D 1 E E 512 6 010 2 140 GOTO 80 10 D 1 E 64 70 COLOR3 80 DRAW BM STRS INT 109 D E 90 FOR T 127 TO 128 100 LINE 127 T T T 150 D E PSET 110 NEXT 120 IF D 1 THEN 150 130 D 1 E E 64 COLOR2 140 GOTO 80 RUN the whole program to see as well as the sine wave two parabolas one inverted and the other upright In all these cases the data to be plotted is specified in a FOR NEXT loop For example the Spectrum program uses one loop for the sine wave and one for each of the two parabolas IRREGULAR GRAPH FORMS Most of the graphs you are likely to plot however will be from data that have no mathematical relationship These data could be figures for annual rainfall or for the profits and sales of a business any of which can change unpredictably or for seasonal reasons If you were plotting the graph manually the first thing you would do is to set up the axes so let this be the first part of the program Type NEW then enter and RUN these lines 140 DRAW 0 175 150 PLOT 0 0 160 DRAW 255 0 10 HIRES 0 1 MULTI 2 4 6 140 LINE 0 0 0 200 1 150 LINE 0 200 360 200 1 999 GOTO 999 10 GRAPHIC 2 140 DRAW 2 0 0 TO 0 1023 TO 1023 1023 10 MODE 1 140 DRAW 0 1024 150 MOVE 0 0 160 DRAW 1280 0 LE 5 PMODE3 1 10 PCLS
23. 15 SCREEN1 1 140 LINE 0 0 0 191 PSET 160 LINE 0 191 255 191 PSET 200 GOTO 200 In these lines the program selects a graphics mode except for the Spectrum where this is not necessary and then places the Y axis along the left hand edge and the X axis along the bottom This is one of the commonest arrangements for the axes but you may have to be prepared to shift them according to the range of the data For example if you are plotting things like profits and loss or temperatures you may have negative values so the X axis needs to be some way up the screen instead of at the bottom Another reason for shifting the axes 1s to leave room for numbers division marks and labels called legends which are useful details to have on a graph There is no rule about the amount of space you should leave it depends on how much information you wish to display Change the program as below to see the effect 130 PLOT 20 10 140 DRAW 0 155 150 PLOT 20 10 160 DRAW 235 0 10 HIRES 0 1 MULTI 2 4 6 140 LINE 10 0 10 190 1 150 LINE 10 190 360 190 1 999 GOTO 999 10 GRAPHIC 2 140 DRAW 2 100 0 TO 100 923 TO 1023 923 10 MODE 1 130 MOVE 200 150 140 DRAW 200 1024 150 MOVE 200 150 160 DRAW 1280 150 LE 5 PMODE3 1 10 PCLS 15 SCREENI 1 135 COLOR2 140 LINE 20 0 20 160 PSET 160 LINE 20 80 255 80 PSET 200 GOTO 200 RUN the program and notice that there margins to the le
24. 2 1565 IFLEN T K2 PO gt 1503THEN PQ PQ 32 P2 P2 32 P1 P1 32 GOTO1565 1570 IFP1 lt P THENP1 PO 1580 IFP1 gt P9 P1 1 1590 P8 PEEK P1 POKEP1 63ANDP8 1600 P7 0 A INKEYS IFAS 1600 1610 IFAS RS THENPOKEP1 P8 RETURN 1620 IFAS 9 8 P1 P1 1 G0TO1580 1630 CHR 8 THENPOKEP1 P8 P1 P1 1 60701570 1640 CHRS 10 THENAS 60701670 1650 IFAS CHR 94 THENAS O MID T K2 P1 P 1 1 P7 1 GOTO1670 1660 IFAS lt 1600 1670 IFP1 P 1 LEN TS K2 THENTS K2 LEFT T K2 P1 P AS GOTO1690 1680 T K2 LEFTS TS K2 P1 PO A RIGHTS TS K2 LEN TS K2 P1 P0 1 1690 P1 P1 LEN AS gt 0 P7 GOTO1560 1700 PRINT 32 K K 10 GOTO1510 1710 IFN OTHENCLS PRINT C nothing to delete FORC 1701000 RETURN 1720 CLS PRINT C PLEASE INPUT LINE noooooooooooo PRESENT LINES NUMBERED IN TENS 1730 INPUTK K2 K 10 1740 IFK2 gt ORK2 lt 10RK2 lt gt INT K2 THENPRINT THIS LINE DOES NOT EXIST RETURN 1750 KO FORK3 K2 TON T K3 T K3 1 NEXT N N 1 PRINT 295 K 10 C1 C 5T K RETURN 1760 IFN OTHENPRINT NOTHING TO LIST FORC 1T01000 NEXT RETURN 1770 PRINT PLEASE INPUT FIRST LAST LINE NO PRESENT LINES NUMBERED IN TENS 1780 INPUTK K2 K INT K
25. 40 6 150 CLS 160 PRINTTAB 11 2 INPUT PART 1 INDEX 170 PRINT 180 FOR 1 TO 7 190 READ A B 200 5 30 8 210 NEXT 220 DATA Animation 26 32 Basic Programming 2 7 use of 7 26 27 CLEAR 10 27 14 4 15 explanation 27 Spectrum 8 The program sets up the title page and stops but don t be alarmed there is more Line 140 causes the computer to stop and wait If you obey the instruction PRINTed by Line 120 the program will continue The screen is cleared Line 150 and a title is PRINTed at the top centre Line 160 of the screen So that the title stands out and is separated from the rest of the display Line 170 PRINTS three blank lines To leave a single line space you would just use PRINT on its own Notice that you cannot use a double quotation mark to leave the spaces or you will get an error The rest of the program READs in two columns of data Line 190 from Line 220 Each time round the FOR NEXT loop starting at Line 180 two pieces of data are read a two line space is left by PRINT and the data is PRINTed Notice that only one coordinate is used in each TAB statement In the absence of the second coordinate the micro takes this to be the X coordinate so the first piece of data is PRINTed five units along the X axis and the second is PRINTed 30 units also from the left han
26. 50 AS INKEYS IFAS 250 260 IFAS lt gt 180 270 ON JJ GOSUB1420 1450 1700 1710 1850 290 G0TO240 280 0 K9 0 0 0 290 5 0 300 PS PS 1 IFPS lt ATHENK K P PO PRINT 21 START OF PASS PS GOTO 330 310 P P RETURN WORKING OUT POSTBYTES COPING WITH LABELS D POKEING THE HEX INTO MEMORY 320 IFPS 3 THENPRINT C postbyte error 330 605081320 340 GOSUB1260 0P C IFLEFTS OPS 1 ANDPS 3THENPRINTOPS 350 IFLEFT OP 1 THEN330 360 IFOPS END ANDPS 3THENPRINT PRINT CJ LI END LAST ADDR P 1 370 IFOP END THEN300 380 IFOP lt gt ORG THEN420 390 GOSUB1260 S IFLEFT C 1 THENS P C MID C 2 400 P VAL C S IFPS 3THENPRINT PRINT CJ CJ 0 00 6 410 GOTO330 420 IFP ANDPS 3THENPRINT O you forgot org P 35000 430 CC 0 DF 0 440 C INSTR SK CC OP IFC lt 0 THENGOSUB530 GOTO570 450 C INSTR SK CC LEFTS OPS 3 lt gt OANDRIGHTS OP 1 lt C AND MIDS SK CC C 3 1 lt A THENGOSUB 530 GOTO540 460 lt gt ANDRIGHT OP 1 GOSUB530 GOTO560 470 C NSTR SK CC RIGHTS OPS 3 IFC lt gt ANDLEFTS O0P 1 L GOSUB 530 GOTO550 480 CC CC 4 1 IFCC lt 2THEN440 490 IFPS 500 GOSUB1350 03 Q2 RR Q2 P IFC THEN340 510 IFPS 3THENPRINT this line not recognized 520 GOT
27. 650 128 10 POKE 36867 24 35865 0 22 POKE36860254 4 gt 1 s S pude ert _ 120 POKE 36879 109 POKE 36878 15 d y 1425 2 120 PRINT C7 TAB Z C G 0 20 GET 7 22 210 PRINT EJ TAB Z __ 220 IF Z THEN C A 2 2 Z4 1 IF 22126 THEN Z 126 PRINT C7 TAB 2 230 IF Z 5 THEN C B 2 2Z 1 IFZ 111 THEN Z 111 PRINT CZ TAB Z 3 240 IF Z 0 60 0 300 T 245 W K RND 1 19 250 POKE 6400 INT RND 1 8 1 W 260 PRINT C 270lF G 1 THEN 320 280 GOTO 200 7 38400 X 1 POKE 36875 ees 5 Le Xem f f j jS c Ex mA Ear OPEN AND G 0 THEN G 1 p 300 THEN X 2 4 Qi Sz The program is much the same as the stunt X bike s In this case it is the full stop and the comma gut Nd turn BE tia around it n p key J ress isis anim om p 16 n n the b backgrc 1d mechanism When the space bar is pushed the vt computer jumps to the fire routine Lines 300 and 310 look at which way the submarine is facing and decide which way round the tor pedo should be where it should start from and which way it should run Line 320 moves the torpedo across the screen The POKE 7680 X 32 rubs out behind the torpedo by overprinting the old image with a space The POKE 38400 X 1 then POKEs the backg
28. 8 200 GOTO 200 The programs starts by changing the screen colour to blue in Line 1 see page 374 for a full explanation of how you can change the screen colour using CLS The remainder of the line sets B equal to a black square Lines 20 and 40 print out the words in reverse characters using B as a space Re member that the reverse characters on the Dragon and Tandy screen appear as lower case characters on program listings Line 30 is similar except that the word PRESENTS is less important and so is dis played as normal upper case characters In the centre of the screen is the title INPUT surrounded by coloured block graphics The graphics and title are displayed by Lines 50 to 70 The range of block graphics that are avail able to you are shown in the user manual They are made up of black and green areas but the green parts can be changed to yellow blue red buff cyan magenta or orange by adding a multiple of 16 to any of the block graphic character codes Parts of the screen display are coloured green These areas are where the screen background colour shows through It s very easy to change the green screen colour to orange and produce a flashing screen display Line 90 uses the SCREEN command to swap between the green and orange screen in a very similar fashion to the way you switched be tween colour sets when using high resolution graphics By specifying 5 0 1 the screen colour can be switched to orange
29. 9 than for the Spectrum s Z80 chip the Dragon s assembler has to make three passes instead of the Spectrum s two in case there are any 16 bit instructions In spite of the three passes the Dragon and Tandy assembler is still almost three times faster than the Spectrum s because it uses INSTR to search for the opcodes But you will still have to wait a bit if you are assembling a long program On the Tandy change the POKE in Line 10 to POKE 146 1 This line may give an FC error when it is first RUN but don t worry just RUN it again and it should be fine THE ASSEMBLER 10 PMODEQ PCLEAR1 CLEAR3000 CLS PRINT 233 initializing R CHR 13 POKE144 1 20 DIMSK 1 K1 94 K2 94 7 200 RR 100 Z 100 30 FORCC 1TO94 READKS K CC K2 CC CC 49 SK C SK C RIGHTS 5 8 2 KG NEXT 40 DATA ADCA 185 1 ADDA 187 1 ADDD 243 2 ASL 120 3 CLR 127 3 CMPA 177 1 CMPD 4275 2 CMPY 4284 2 BCC 36 4 BCS 37 4 BEQ 39 4 50 DATA BHS 36 4 BLO 37 4 BMI 43 4 BNE 38 4 BPL 42 4 BRA 32 4 LBRA 22 5 BSR 141 4 LBSR 23 5 CMPX 188 2 CMPU 4531 2 CMPS 4540 2 DEC 122 3 60 DATA INC 124 3 JSR 189 3 LDA 182 1 LDB 246 1 LDD 252 2 LDS 4350 3 LDU 254 3 LDX 190 3 LDY 4286 3 LSL 120 3 LSR 116 3 70 DATA PSHS 52 1 PSHU 54 1 PULS 53 1 PULU 55 1 ROL 121 3 ROR 118 3 RTS 57 STA 183 3 STB 247 3 STD 253 3 STS 4351 3 STU 255 3 80 DATA STX 191 3 STY 4287 3 SUBA 176 1 SUBD 179 1 ANDA 180 1 ABX 440 58 ANDCC 76
30. 90 and 2999 The computer has to be able to select these routines according to the verb the adventurer has used In the Spectrum program the location descrip tion and verb routine lines are stored in the array G The next stage in writing your new program is to feed all of the line numbers into G Lines mI s NUIT 40 to 70 contain the line numbers The first three lines are the location descriptions and the last line contains all the starting lines for the verb routines With G filled with line numbers Lines 330 to 350 will pick out the correct location description by picking out the correct element in the array The second subscript corresponds to the array row that the number is in so you should make sure that the subscript is correct in each of your GOTO lines especially if you have added some extra data lines MOVING AROUND Ifthe grid for your adventure is a different size from that used for the INPUT adventure you ll need to alter the movement routine at Lines 1000 to 1040 More specifically the north and south lines Lines 1010 and 1030 will have to be altered if the grid is no longer six squares wide Simply count how many squares there are across the top of your new grid and change the number 6 to the width of the grid THE OBJECTS You will have to make quite extensive changes to Lines 160 to 260 because the objects in your new adventure will almost certainly be very different from those in the NPU
31. E 1024 Z Z 30 POKE 55296 Z 1 40 NEXT Z 10 FOR Z 0 TO 255 20 POKE 1024 Z Z 30 POKE 38400 Z 0 40 NEXT Z As you can see when you RUN this there are two sets of characters the second series simp ly takes the reverse form of the first PROGRAM GRAPHICS The simplest way to use graphics from within a program is to incorporate them within PRINT statements as in the helicopter program on page 31 But this may be laborious Each of the graphic characters has its own particular Commodore ASCII code and you can use this value to create screen displays using CHR see pages 314 to 320 This short program prints out 63 of the graphics charac ters available from the keyboard 10 LO 96 127 20 FOR LP LO TO HI 30 PRINT LP CHRS LP 40 GET AS IF THEN 40 50 NEXT LP 60 IF LO 161 THEN STOP 7010 1161 191 80 GOTO 20 Every time you press a key you ll see another graphics character along with the ASCII value used as the CHR argument A third way of accessing graphics from within a program is to use Commodore s special screen display codes as used for the first set of programs in this article These screen codes can take the value to 255 the reverse graphics used as symbols having values above 128 There are actually two character sets these relate to the U G and U L modes and only one set at a time can be displayed on the screen Note that colour memory has to be POKEd with
32. IF BANDN1 lt gt BANDN2 THEN320 920 R 16 N1 N2 K2 1 GOTO1140 930 FORJ 1T012 IFY J USTHENH J 940 NEXT RETURN 950 C2 C 1 FORJ 0TO12 L LEN X J IF MIDS AD C2 L lt gt X J THEN980 960 IF BLIORV J AND239 lt lt 239THEN320 970 C2 C2 L B BLJANDV J IFKK J THENK2 KK J 1 980 IFJ 9THENJ2 C2 C2 C2 C2 1 K2 6 990 NEXT 1000 IF 15ANDB 15THENB B 6 1130 IF 31ANDB 8AND R lt 160RR gt 239 THENB B 136 0R 31ANDR K2 0 1140 IFPS 3THENPRINTTAB 20 1150 IFOP gt OTHENBY OP 256 GOSUB 1220 BY OP GOSUB1230 1160 IFB lt gt 239THENBY B GOSUB1230 1170 IFK2 OTHEN330 1180 GOSUB1200 IFK2 2THENBY R 256 GOSUB1230 1190 BY 256 INT R 256 GOSUB 1 2390 GOTO330 1200 IFPS 1210 RETURN 1220 IFINT BY OTHENRETURN 1230 P P 1 IFPS 3THENPOKEP 1 255 ANDBY 1240 BY 255ANDBY IFPS 3THENPRINT RIGHTS 0 2 1250 RETURN 1260 IFK gt N END RETURN 1270 K1 K9 1 IFK9 gt LEN T K THEN C CI missing mnemonic RETURN 1280 K9 K1 IFMID TS K K1 1 THEN1270 1290 IFK9 gt LEN TS K THENCS MIDS T K K1 K9 K1 RETURN 1300 IFMIDS T K K9 1 lt gt CO THEN K9 K9 1 G0TO1290 1310 C MID T K K1 K9 K1 RETURN 1320 IFK9 lt LEN T K ANDPS 3THEN PRINTRIGHT T K LEN T K
33. INT TAB 13 T IHEBBEBHBEI 110 PRINT ES E TAB 11 RND 1 2 COPORDED SOEONOTOSO GOTO 60 5 POKE 36879 11 POKE36865 150 POKE 36878 15 10 PRINT fig a3 MARSHALL CAVENDISH LTD 20 PRINT pai 360 e 30 30 Oe E C COPYRIGHT 1984 m 30 PRINT TAB 5 x z PRESS ANY KEY 40 PRINT 6 I amp TO CONTINUE POKE 198 0 50 FOR Z 150 TO 38 STEP 1 POKE 36865 2 GOSUB 100 60 POKE 36876 255 Z POKE 36877 100 Z NEXT POKE 36877 0 POKE 36876 0 70 POKE 646 RND 1 6 2 GOSUB 100 80 IF PEEK 197 lt gt 64 THEN PRINT 7 99 POKE 36879 27 END 90 GOTO 70 100 T RND 1 7 PRINT 4 BHBH 110 PRINT 4 120 PRINT TAB 4 2 T HFSEJIEIES EJ EJ ET 130 PRINT lt Je Je 2 1 2 SLIELINLITLISC RETURN RUN the program to display a simply construc ted but nevertheless eye catching display which makes good use of the features of the Commodore graphic set first line is the familiar set of POKEs to change border and screen colours Line 10 clears the screen and PRINTS in yellow one of the more useful ROM graphics in an applic ation such as this the thin base line obtained by pressing the 0 and keys simulta neously T wenty four of these are required adding a thin cont
34. LOUR2 40 PRINTTAB 9 2 MARSHALL CAVENDISH LTD 50 PRINTTAB 15 5 PRESENTS 60 COLOUR3 70 FOR T 0 T0 3 80 PRINTTAB 15 11 T 2 ONoOPOUOT 90 NEXT 100 COLOUR 110 PRINTTAB 11 24 COPYRIGHT c 1984 120 PRINTTAB 7 28 PRESS ANY KEY TO CONTINUE 130 MOVE464 688 DRAW464 432 DRAW784 432 DRAW 784 688 DRAW 464 689 RUN this program and notice the vastly impro ved title page use of colour is accentuated by the use of repetition and by flashing parts of the display The program starts by selecting a mode that supports four colours as well as graphics Line 10 Line 20 changes one of the four colours colour 3 to flashing colour 10 green magenta Notice that you could have selected MODE 2 at Line 10 which supports all the colours but that the size and shape of the letters would be rather difficult to read The first two lines of the display are positioned and printed Lines 40 and 50 in yellow selected at Line 30 Line 60 then selects the redefined colour COLOUR3 flashing green magenta in which to print the next three lines These are positioned by the FOR NEXT loop between Lines 70 and 90 On the first pass round this loop Line 80 PRINTs the word INPUT at position X 15 and Y 11 On subsequent passes the word is PRINTed two lines down the screen giving altogether four printings with two lines be tween each To PRINT each line in a different colour you could put in a short rou
35. M y 12 40 FOR n 1 TO 12 50 INPUT Enter Y Value 1 y n LET y n y n 10 60 NEXT n CLS 70 LET n 10 80 PLOT 20 n 90 FOR x 1 TO 12 100 DRAW 18 y x n 105 LET n y x 110 NEXT x Cx 10 DIM Y 11 40 FOR N TO 11 50 PRINT Z N INPUT y N IF Y N lt OR Y N gt 190 THEN 50 60 NEXT N HIRES 9 1 MULTI 2 4 6 70 XX 10 YY 190 80 N 0 90 FOR X 10 TO 11 10 2 10 STEP 10 100 LINE XX YY X 190 Y N RND 1 3 1 105 XX X YY 190 Y N 110 N N 1 120 NEXT X 999 GOTO 999 Cx DIM_Y 11 10 FOF TO 11 50 PRINT C IF Y N lt OR Y THEN 50 60 NEXT N GRAPHIC 2 70 POINT 2 100 923 80 N 0 90 FOR 170 TO STEP 70 100 DRAW 110 NN PUT Y N gt 923 2 70 100 X 923 Y N 20 DIM Y 11 40 FOR N 0 TO 11 50 INPUT ENTER Y VALUELJ Y N Y N Y N 150 60 NEXT CLS 70 MOVE 200 0 80 1 90 FOR X 280 TO 11 80 200 STEP 80 100 DRAW X Y N 110 N N 1 120 NEXT 20 DIMY 11 40 FORN 07011 50 INPUT ENTER Y VALUED Y N 60 NEXT 70 DRA 90 FOR X 20 TO 11 20 20 100 LINE X Y N PSET 10 N N 1 120 When you RUN the program you first loop through the input routine from Line 40 to 60 12 times entering the Y values These values are stored in the array Y as variables Y 1 ough Y 12 on the Spectrum and 0 ough Y 11 on the others If instead of 12 s you w
36. O330 530 C VAL MIDS SKS CC C 2 2 RETURN 540 OP K1 C 32 16 RIGHTS OPS 1 A K2 0 GOTO580 550 OP K1 C 4096 K2 5 GOTO580 560 OP K1 C 64 K2 1 GOTO580 570 OP K1 C K2 K2 C 580 IFPS 3THENBY P 256 GOSUB1240 BY P 32768 GOSUB1240 PRINT O OPS 590 IFOP gt 1THEN740 600 GOSUB1260 AD C IFPS 3 THEN PRINT C3 LEFT AD 10 610 ON OPL1GOTO620 630 660 730 620 GOSUB1860 IFNU OTHENRR Q3 R GOTO330 ELSE1050 1010 IFPS 3ANDJ2 lt LEN AD ANDK2 2 6 gt 129 AND 630 IFPS 3THENPRINTTAB 20 lt gt 7THENPRINT indexing error lt 128 K2 K2 3 640 GOSUB690 BY 255ANDR GOSUB1230 GOTO330 1080 IFB 239ANDK2 3THENK2 2 IFR 650 IFBS ADSTHEN330ELSE640 1020 IF K2 ANDC gt 2 OR MIDS ADS lt 256ANDDF 2 1 0P OP 32 660 IFPS 3THENPRINTTAB 20 J2 1 lt gt ANDPS IF 240ANDOP 80THENOP OP 80 670 GOSUB690 BY INT R 256 GOSUB PRINT address error GOTO330 1090 IFPS 3AND OP gt 31ANDOP lt 48 0R 1230 BY R 256 BY GOSUB1230 1030 AD LEFT AD C 1 IFJ2 C OP 141 AND R lt 1280RR gt 127 THEN 680 ADSTHEN330ELSE670 THENR 0 60701060 PRINT branch out of range 6070330 690 NN INSTR AD IFNN 1040 GOSUB1860 IFNU 060 1100 IFB 255THENB 159 K2 2 B AD GOTO710 1050 IFPS 3THENPRINT
37. T adventure Count how many objects there are and the length of both the longest short description and the longest long description The number of objects should be your first piece of data in Line 200 and will be used as one subscript when DlMensioning the arrays in Line 180 and to set up NEXT loops elsewhere in the program The second subscript in array B is the length of the longest short description and the second subscript in 5 is the length of the longest long description It s clearest to use a separate DATA line for each object but if you ve written a game needing a large number of objects you may find that it s better to have more than one object per line Whichever way you decide to enter the data the order must be correct as each of the three pieces of data are fed into different arrays The order then is location number short description long description If the object only appears later on in the adven ture perhaps after the adventurer has found it or it is something which appears randomly like the tax inspector the location number should be zero final routine that you should turn your attention to is the HELP routine Consider where the adventurer might need a hint and use an IF THEN line to give the hint Other odds and ends such as the Line which makes the tax inspector appear Line 320 may have to be altered or deleted according to the demands of your adventure Also att
38. TA 98000 STEP 90 Y YS 3 abad 33 2 gt Placing numbers on the graphics screen of these machines is a little more difficult Yo cannot PRINT the standard character set bu instead have to DRAW each letter individually The routine to do it is too long to be reproduced here but it has been dealt with on page 192 and can be incorporated into the program with suitable adjustment to the line numbers FINISHING TOUCHES All that remains is to add the finishing touches such as and labels These are not essential but they help to make an attractive display As an exercise try adding these urself using GCOL COLOUR and PRINT TAB or PRINT AT statements These commands and how to use them are covered for each machine on pages 84 to 91 and 117 to 123 COMMODORE KEYBOARD SYMBOLS One of the most perplexing problems facing a newcomer to Commodore computers is the extensive use of on board graphics many of which find their wav into program listings as symbols for other functions ROM GRAPHICS The Commodores have a rich selection of on board ROM read only memory graphics which are accessible for any kind of screen display What you can access depends on which screen display mode you re in upper case capitals and graphics mode referred to here as U 4 G or upper case and lower case mode U L A greater number are available when the computer is in U G mode to which
39. TA 28 24 60 80 79 143 143 30 246 190 252 240 128 0 0 0 24 DATA 128 96 248 240 224 192 112 168 168 136 112 0 0 0 0 0 100 FOR Z2 0 TO 15 7 16 READX POKE 6144 Z X NEXT 105 FOR 2 0 TO 15 POKE 6656 Z 0 110 POKE 36867 255 36869 254 IM EM EFC C Le D 12 POKE 36879 25 POKE 36878 15 125 PRINT 7 200 FOR Z 0 TO 255 GET Z 210 PRINT 2 1 646 RND 1 3 2 PRINTMIDS C RND 1 2 1 1 220 IF Z THEN PRINT 36877 200 RND 1 5 5 S 4 20 230 IF Z B AND 2 lt 230 THEN PRINT 7 Z 2 Z 4 22 PRINT 2 Sl AS GOTO 260 240 IF Z AND Z 30 THEN PRINT 7 Z Z 22 PRINT TAB Z O SD BS GOTO 260 250 IF Z lt gt THEN PRINT 36877 240 RND 1 5 IF 5 gt 0 THEN S2 S 40 260 FOR C 1 TO S NEXT C Z GOTO 125 Lines 10 to 24 contain the DATA which defines the shape of the image Each line defines a different character so there are 16 DATA entries in each one If you want to change the image you can alter the DATA here to redefine each Li CREATING A BIKE AND SUBMARINE ON THE VIC MOVING THE CHARACTERS B A FLASHING ALIEN ON THE 2 81 PSEUDO HI RES GRAPHICS character and so what is being displayed on the screen Line 100 READs the DATA and POKEs it into memory locations 6 144 to 6 271 Line 105 fills the space character with zeros to ensure that you have a bla
40. UTINES f EXTENDING THE GRID LIST OF VARIABLES 09 Finally how about something that s very EX fopical an adventure set after a nuclear Seer holocaust The possibilities are wide mutants finding radiation suits marauding bands of starving bandits trying to find unpolluted food and water and so on MORE ROOMS The INPUT adventure is very small by any standards so you ll soon find that your own adventures will outgrow this program Follow the instructions on pages 296 to 301 and you should have a grid suitable for programming The INPUT grid is 6x4 locations 24 in all of which only 12 are used If you decide to work within this you can then either alter the existing program which 1s less work but harder to follow or type in a whole new program more effort but perhaps less confusing Depending on which you choose you can either LOAD the existing program from tape or if you have a printer list it on to r annara eee gt 2 paper The adaptations that follow depend Y AN ib the size of grid you find yourself using If you mom Ar XA have 24 locations or less you can use the Jic i existing grid as it stands and draw your map on that If your map requires a larger grid draw this out and number it as before 4 PUT T Baas sh um y 5 3 TOME PA 7 XL gh a
41. XX 10 X XS YY 190 Y X YS XT X 140 0 10 190 1 150 LINE 10 190 360 190 1 999 GOTO 996 1000 DATA 4000 2000 6000 3000 8000 1000 5000 2000 6000 1500 3000 500 10 GRAPHIC 2 20 DIM Y 12 30 XS 70 YS 1 10 40 FOR N 1 TO 12 50 READ Y N 60 NEXT N 80 POINT 2 100 XS 923 YS Y 1 90 FOR X 1 TO 12 100 DRAW 2 TO 100 X XS 923 Y X YS 110 NEXT X 140 DRAW 2 100 0 TO 100 923 TO 1023 923 1000 DATA 4000 2000 6000 3000 8000 1000 5000 2000 6000 1500 3000 500 10 MODE 1 20 DIM Y 11 50 YS 1 40 N 0 TO 11 50 READ Y h 60 N 70 VDU 29 200 80 MOVE YS Y 90 FOR X 0 TO 11 100 DRAW X XS Y X YS 120 NEXT 130 MOVE 0 0 140 DRAW 0 1024 150 MOVE 0 0 160 DRAW 1280 0 1000 DATA 4000 2000 6000 3000 8000 4000 5000 2000 6000 1500 3000 500 5 PMODE3 1 10 PCLS 20 DIMY 12 30 XS 20 YS 1 20 40 FORN 1 TO 12 50 READ Y N 60 NEXT 80 DRAW BM20 STRS INT YS Y 1 90 FOR X 1 TO 12 100 LINE X XS Y X YS PSET 110 NEXT 130 5 135 COLOR2 140 LINE 20 0 20 160 PSET 160 LINE 20 160 255 160 PSET 200 GOTO 200 1000 DATA 1600 1000 2500 3000 3200 2000 2500 1000 3000 750 1500 250 The program plots a graph of the values in the DATA statement at Line 1000 This method of input is used to save you having to type in the values repeatedly but you could revert to
42. You simply put this number of cursor rights at the beginning of your PRINT statement and the word or words will appear in the correct position in the line different symbols for cursor up down or whatever can be very confusing So have a look at pages 420 and 421 for more inform ation on what the symbols look like and what they do The Commodore does have a more limited alternative you can use PRINT SPC or PRINT TAB Both of these commands refer solely to the horizontal position of the PRINT statement although by using numbers larger than 40 after them you can get limited vertical control as well The more common PRINT TAB is followed by a number between 0 and 255 It moves the cursor to the right The number after the command dictates how many character squares to the right the cursor moves In fact the computer counts every PRINT TAB from the beginning of the line rather than from the current cursor position PRINT SPC is very similar The only dif ference in fact is that PRINT SPC counts its cursor rights from the current cursor position If you want to position the PRINTed words so that they are in the centre of the screen as before you follow the same set of calculations and use the resulting number as the number in the brackets after the PRINT TAB or SPC You might expect these two types of PRINT statements especially the PRINT SPC to PRINT the relevant number of spaces but in fact this I
43. address not 1110 IFB lt gt 239THENOP OP 16 1 2 3 700 B LEFT AD NN 1 AD MID understood THENK2 2 IFABS R 5 lt 128THEN ADS NN 1 1060 IFK2 7THENK2 3 60701080 2 1 1 R 255ANDR 710 IFLEFTS B 1 THENR VAL 1070 IFK2 gt 3THENR 2 0 gt 1120 IF 15ANDB 8ANDR amp H MID B 2 ELSER VAL B 255 lt gt 239 K2 4 B 4 k2 0 720 RETURN 730 GOSUB1860 IFNU OTHENP P GOTO330 ELSE1050 740 B 239 IFK2 THEN1 140 750 GOSUB1260 AD C IFPS 3THEN PRINT C1 LEFT AD 9 760 IFK2 gt 3THEN1040 770 IF K2 lt gt 3OR LEFTS OP 2 10 ANDLEFTS AD 1 zz gt THENADS MID AD 2 DF 1 0P OP 48 GOTO1040 780 IFRIGHT AD 1 8 MID AD 2 LEN AD 2 B 16 790 IFOP lt 520ROP gt 55 THEN870 800 K2 1 R AA 0 810 NN INSTR AAS IFNN U AA GOTO830 820 U LEFT AA NN 1 MID AAS NN 1 830 IF U 1 320 840 NN 1 FORJ 0709 1 0 PUS J THENNN J 850 NEXT IFNN OTHEN320 860 RLJIORPU NN IFU AASTHEN 1140ELSE810 870 2 3 INSTR AD 5 IFC O THEN1040 880 IFOP lt gt 30ANDOP lt gt 31THEN95 890 NN INSTR AD 5 U LEFT AD NN 1 GOSUB930 N1 H 1 IFH OTHEN320 900 U MIDS ADS NN 1 GOSUB930 H 1 IFH THEN320 910
44. agon 14 15 explanation of 27 CODE Spectrum 8 The first thing to notice about this Spectrum program is that it changes the colour of the screen and BORDER and clears the screen It does not matter what colours you choose for the screen except that if you can avoid the normal white BORDER and PAPER with black ink it usually looks better simply because it is different You should make the display as easy to read as possible which means having an INK colour which stands out from the PAPER Also some colour combinations are considerably more pleasant than others POSITIONING Lines 20 and 30 PRINT the words MARSHALL CAVENDISH PRESENTS But the words are not all on the same line the name of the company Marshall Cavendish is on the top line with the word presents two lines beneath This makes the text on the screen look much clearer The program uses PRINT AT to position these words in the centre of the screen Try to work out what the PRINT AT numbers should be using the calculations given above They should be the same as those in the program You can see the advantages of putting these words in their correct positions when you RUN the program unlike the previous program the words look as if they are in the right place You could have used PRINT TAB to PRINT the same words by changing Line 39 to 30 PRINT TAB 10 INVERSE 1 PRESENTS There is an apostrophe before the TAB 10 so
45. ant to PRINT at a position other than the middle of the screen you can either estimate what you think the coordinates are or you can use graph paper and work out the exact numbers Spectrum owners should remember that the Spectrum s PRINT AT command works slightly differently to other computers The difference is that the Spectrum uses the first number after the PRINT AT command as the vertical y coordinate and the second one as the horiz ontal x coordinate When PLOTting though the x coordinate comes first as is more usual With both computers the position 0 0 is at the top left hand corner when PRINTing but at the bottom left hand corner when PLOTting and DRAWing Cx Cx Commodore BASIC has no PRINT AT com mand but lets you move the cursor position so that the next PRINT position comes where you want it to This means that you do not have to work out the numbers to go after a PRINT AT statement you just include however many cursor ups downs lefts rights in your PRINT statements as you want If you are trying to position the PRINT statement so that it appears in the middle of the line follow this simple procedure subtract the length of the statement from 40 for the 64 or 22 for the Vic there are 40 characters in a line on the 64 and 22 in a line on the Vic and divide the answer by two The number you end up with is the number of spaces there should be either side of the PRINTed statement on your screen
46. anted some other number you wou erely redimension the array for the required number The screen is then cleared STRS INT Y 0 and the cursor is moved to the first X Y position Lines 70 and 80 The rest of the program plotssthe graph from X values at Line 90 and Y values at Lines 100 to 110 SCALING FACTORS The figures for thi they fit conveniently axes and the screen wish to plot will rarely b too large or too small sc them to bring them within rang method of scaling is to stud decide the factor by which the multiplied to bring them within rang the complete new program with changes made 20 DIM y 12 30 LET xs 2 LET 1 50 40 FOR n 1 TO 12 50 READ y n 60 NEXT n CLS 70 LET n 8 80 PLOT 40 aph were chosen so that ithin the range of the iever the values you st right but either need to scale he simplest alues and hould be is e 90 FOR 1 TO 12 100 DRAW 8 xs y x n ys 105 LET n y x 110 NEXT x 130 PLOT 40 8 140 DRAW 0 167 150 PLOT 40 8 160 DRAW 210 0 1000 DATA 4000 2000 6000 3000 8000 4000 5000 2000 6000 1500 3000 500 3 10 HIRES 0 1 MULTI 2 4 6 20 DIM Y 12 30 XS 10 YS 1 60 40 FOR N 1 TO 12 50 READ Y N 60 NEXT N 80 XX 10 XS YY 190 YS Y 1 90 FOR X 1 TO 12 100 LINE XX YY 10 X XS 190 Y X YS RND 1 3 1 105
47. d margin The DATA statement too at Line 220 has some important punctuations Normally each piece of data is separated by a comma On this line however some of the data includes a comma so to PRINT the data as they are double quotation marks are used These are also necessary when you wish to PRINT a BASIC keyword such as CHR reli CENE Type in the following program and you ll see how PRINT can be used to produce a pro perly formatted title page 10 CLS3 B 128 20 PRINT 68 B marshall B cavendish B Itd BS 30 PRINT 138 PRESENTS 40 PRINT 358 B copyright BS B B 1984 BS 50 PRINT 232 CHRS 190 STRINGS 11 CHR 188 CHRS 189 60 PRINT 3 264 CHR 234 ClMONOPOUOTO CHR 229 70 PRINT 296 CHR 155 STRINGS 11 CHR 147 CHRS 151 80 PRINT 450 C PRESS ANY KEY TO CONTINUEL 90 J 1 J SCREEN0 J 100 FORK 1T0200 NEXT 110 IF INKEYS lt gt THEN 130 120 GOTO 50 130 CLS4 140 PRINT 7 input PART 1 INDEX 150 FOR X23 TO 12 160 READ D E 170 PRINT 32 X 1 D PRINT 32 X 25 LEFT O E 4 000 007 7 190 DATA 26 32 BASIC PROGRAMMING 2 7 dragon 7 CASSETTES 25 CASSETTE RECORDERS 24 CHR use of 26 27 CLEAR 510 27 CLOAD dragon 14 CLS explanation 27 spectrum
48. e screen When you work out the length of your phrase don t forget to include all the spaces between words To work out the horizontal coordinate of the start position of your phrase subtract the length of the phrase here 10 from the total number of characters in the line here 32 and divide the result by 2 You divide the result by two so that you get an equal number of spaces either side of the PRINTed phrase In this example the answer is 11 Because 0 is counted as a number the first character space is numbered 0 So subtract one from the answer above 11 to get the horizontal PRINT AT position or the PRINT TAB position Sometimes you may wish to PRINT some thing only about two or three characters in from the left hand side of the screen In this case it is probably easier to include that number of spaces inside the PRINT statement than to use a PRINT TAB or AT statement But don t do this if you need to use lots of spaces as it tends to be very wasteful of memory You can work out the vertical position in the same way as you did the horizontal if you want the phrase in the middle line of the screen work out how many lines the message will cover Subtract this number from the total number of lines in the screen and divide the answer by two As before subtract one from this to compensate for the fact that the computer counts 0 as a number and the result is the line number at which you want to PRINT If you w
49. e they will soon run out of memory But that is not to say that there is no scope at all for extending the events in the adventure or that adventures with many more locations cannot be written Should you wish to write an adventure with more rooms on these machines for example then it would be quite possible to trade off some other feature in favour of the extra rooms It really depends on what you want from your adventure YOUR OWN ADVENTURE THEMES Before you can write your own adventures you will have to invent a suitable plot or story The structure of a successful adventure story is usually a very traditional one there is a beginning a middle and an end with a structure imposed by the order in which the puzzles are meant to be solved It s lucky though that you don t really have to be an Agatha Christie to write adventure games There are lots of existing sources for ideas as you saw earlier but to make it a little easier in the early stages here are a few suggestions You could structure an adventure around a Whodunnit The start could be a room with a dead body with a knife sticking out of it and the point of the whole game would be to find out who the murderer is Perhaps you could Aa A SS ll N Adventures are like cigarettes they re addictive can be bought packaged or you can roll your own Here s how to use the adventure as a basis for your own use a butler character instead of the ta
50. end to the start location in Line 280 VARIABLES ETC So that you can get inside the adventure program here s a list of the variables and arrays and what they re used for G array containing the line numbers of the location descriptions and the verb routines R array containing verbs and responses R array containing verb numbers Corresponding elements in the two arrays above are the pairs of verbs and meanings B array containing the location of each object BS array containing the short object descriptions array containing the long object descriptions Corresponding elements in the arrays above contain information about a single object NB the number of objects in the ad venture Used to DIMension arrays and set up FOR NEXT loops L current location of the adventurer LA lamp status flag Set at 1 when the lamp is on and when it is off 5 E W exit directions Set at 1 if there 15 an exit and to if there isn t I the whole input before it s split into verbs and nouns V the verb part of I N the noun part of I number corresponding to a parti cular verb meaning Used to check if a particular verb has been used at some stages during the program IN the number of objects in the INVENTORY the answer to DO YOU WANT ANOTHER GO G the number of the object drop ped G is the element in array B 15 MACHINE CODE 15
51. es 1420 and 1450 HOW IT WORKS Don t forget to CLEAR enough room for your machine code program before you RUN the assembler see page 278 When you have keyed in the program RUN it Once the assembler has initialized it will display a menu The various options are spelt out there To enter a program press E for edit The program will then ask you for a line number With this assembler you have to give a BASIC line number with each instruction The line numbers should be in tens and there should be no more than one instruction with its as sociated data and addresses on one line The first line should specify an origin or starting place for the machine code This must be above where you have CLEARed to To specify the origin key in ORG followed by the start address If you don t specify an origin the assembler will take 35 000 as a default value and try to assemble your program in ROM Of course it won t work there as the machine code values can t be POKEd into ROM But if it defaulted to any other value it might corrupt the program When it has assembled at the default value the program tells you origin not found Standard 6809 mnemonics are used Hex numbers should be prefixed with a binary numbers should have a 96 in front If no prefix is used the assembler will assume that any number it comes across is decimal Some assemblers for the Dragon and Tandy will recognize ASCII codes if they are prefixed with or b
52. ft and bottom of the screen To vary the size of the margin change the values in Lines 130 to 160 but note that on the Spectrum and Acorn micros Lines 130 and 150 should be identical Enter the next few lines to continue with the program 60 LET 10 70 PLOT 20 80 FOR x21 TO 12 90 READ y 100 DRAW 18 y n 105 LET n2 y 110 NEXT x 1000 DATA 50 70 60 100 80 120 100 130 70 140 90 110 70 XX 10 YY 190 80 FOR X 10 TO 11 10 10 STEP 10 90 READ Y 100 LINE XX YY X 190 Y 2 105 XX 2 2190 Y 110 NEXT X 1000 DATA 190 10 130 50 160 0 100 70 90 50 50 0 70 2 100 923 80 FOR 100 11 70 100 STEP 70 90 READ Y 100 DRAW 2 TO X923 Y 110 NEXT X 1000 DATA 500 600 410 800 300 923 50 700 500 600 25 923 70 200 150 80 FOR 200 TO 11 80 200 STEP 80 90 READ Y 100 DRAW X Y 110 NEXT 1000 DATA 250 400 300 700 500 900 750 950 500 1000 700 850 70 DRAW BM20 160 80 FOR X 20 TO 20 4 11720 STEP 20 90 READ Y 100 LINE X Y PSET 110 NEXT 160 LINE 20 160 255 160 PSET 1000 DATA 140 123 148 45 100 10 20 8 45 8 45 30 The program plots 12 points taking the X values from Line 80 and Y values from Line 1000 and joins them to form a stepped graph The first value in the DATA statement is plotted at the far left along the Y axis but you could have this plotted at the first X division month 1 maybe by changing the init
53. hey are or follow the instructions to create your own characters need is governed by the complexity of the whole image and how much detail you can get into each character When building up a figure like the motor bike stunt rider shown below you could divide the whole figure up into eight small 8x8 squares and build the pattern up that way But the Vic 20 has a facility that will give you double height characters Using this facility you only need to redefine four 8 x 16 charac ters for each figure Each normal sized character is defined by eight numbers one for each row of pixels These numbers are worked out in exactly the same way as the numbers defining the UDGs on the other home computers see page 38 But 16 numbers are needed to define a double height character again one for each row These are still worked out in exactly the same Way The numbers are READ into a protected area of the Vic s memory and stored there as machine code then they are manipulated by lines of BASIC to move the figure around The following program creates and moves the stunt rider around the screen 10 DATA 0 0 0 0 0 0 24 3 248 3 24 0 0 0 0 0 3 12 DATA 0 0 0 0 0 0 0 64 127 127 19 114 171 191 136 112 14 DATA 0 0 0 14 12 62 72 132 15 31 254 220 253 249 65 0 16 DATA 0 0 0 0 0 128 96 240 248 240 128 224 80 80 16 224 18 DATA 0 0 0 0 0 27 0 13 48 198 0 0 0 0 0 0 CO 20 DATA 0 0 0 0 0 0 0 71 63 63 4 26 43 37 18 12 22 DA
54. hing ZX81 430 431 Arrays in adventure games 425 427 ASCII codes 420 421 Assembler Dragon Tandy 440 444 Axes for graphs setting up 415 416 B Basic programming plotting graphs 413 419 formatting 433 439 Commodore 64 graphics 420 421 BASIC Simons Commodore 64 414 C Character sets Commodore 64 420 Colour for screen displays 433 434 Commodore key 420 Cursor control keys Commodore 64 420 421 D Data storage 413 Descriptions location adventure games 425 Displays improving 433 439 colour 433 434 positioning 434 439 Dragon assembler 440 444 how it works 444 testing 444 Dragon speed POKE 444 Drop routines adventure games 426 E Editing programs Commodore 64 420 Extra locations adventure games 423 Extending the grid adventure games 423 424 F FLASH command Spectrum 434 Flashing alien ZX81 430 431 G Games programming adventures planning your own 422 427 GET routines adventure games 426 Graphics ROM Commodore 64 420 Graphs standard forms 414 irregular forms 415 axes 415 416 legends 416 scaling 417 418 scaling factors 418 finishing touches 419 negative and positive values 419 H Help routine in adventure games Acorn Commodore 64 Dragon Tandy Vic 20 425 Spectrum 427 Inventory adventure games 426 Inversing the screen ZX81 432 L Legends for graphs 416 M Machine code graphics Vic 20 428 430 7 81 430 432 Machine code programming anima
55. hing colours or from changing the colours of certain words or objects if your computer does not have a FLASH command or flashing colours provides a form of motion to your picture which is more interesting to watch than a simple static display POSITIONING As well as trying to follow these basic guide lines you should always position words on the screen so that they look as if they are where they should be For example type in the following short program and RUN it This is how NOT to make a title screen for your program The words are all over the place none are co ordinated with any other words and so the result is a display which looks a mess Later on you ll see how to sort this out 10 PRINT here is a new game caled input 20 PRINT AT 5 17 01984 30 PRINT AT 12 13 by MarshallCavendish 40 PRINT 18 25 key 50 PAUSE 100 60 CLS STOP Cx Cx 10 PRINT TAB 27 MARSHALLCAVENDISH TAB 99 PRESENTS 7 20 PRINT 10 4 30 PRINT jad JN COPYRIGHT C 211029078074 40 FOR Z 1 TO 2000 Z PRINT g 5 CLS 10 20 20 BY marSHALLcaVENDISH PRINT c 1984 20 FORT 1 TO 2000 NEXT CLS T 10 CLS4 20 PRINT 40 INPUT 30 PRINT 136 copyright marshallcavendish 40 PRINT 228 PRESENTS 50 FOR T 1 TO 2000 NEXT CLS You can see how unimpressive this display 15 There are several things
56. ial position to which the cursor is moved On all except the Spectrum this position is specified at Line 70 the Spectrum is in Line 60 The use of a DATA statement to store the values is a good idea when the same values are to be plotted many times but if you wish to plot different values each time there is a better method using INPUTs Add this line to the existing program It replaces the existing line 90 This works for all users of the micros covered here except the Commodores which do not print an INPUT statement while in graphics mode 90 INPUT 1 LET y y 10 Cx Since Line 10 selects graphics mode an INPUT statement would not appear on the screen so because of this the DATA statement is the easiest method 90 INPUT Y VALUELT Y Y Y 4 150 T First delete Line 15 then alter 90 INPUT Y VALUED Y 130 SCREEN1 1 When you RUN the program it waits for you to enter the first Y value Enter it and notice that the program executes the first round of the NEXT loop at Line 80 Again the micro waits for you to enter the next value and so on until all 12 values are plotted use the ones in the DATA statement at Line 1000 now deleted The program works well except that the graph is cluttered with the input routine printed by Line 90 Commodore users will not have this problem Enter the lines below to overwrite Lines 70 to 110 then RUN the program again 20 DI
57. inuous line at the top of the display MARSHALL CAVENDISH created by the PRINT statement in the line below The same technique is used in Line 30 to provide a topping for the copyright message in Line 35 Twenty base lines are needed here Line 50 contains a POKE which clears the keyboard input buffer This is a simple error avoidance technique which stops the program careering onwards if a rogue keypress had been lurking in the buffer when a specific piece of information is awaited Location 646 used in the POKE in the next line regulates the current character colour A random value is chosen but within the range which excludes black and white thus the 2 so you don t get the colour value or 1 Nor does it exceed 8 because too many colour switches in the flashing display routine which follows would be self defeating Line 70 waits for the C key to be pressed in response to the main display prompt clearing and then resetting the screen before terminat ing the program Until the C keypress the program loops round an interesting variation on a static display Look at how the TAB value is adjusted by the ever changing value of T This gives a shifting effect to the complete INPUT mes sage which is formed by the PRINT statement of Lines 80 90 and 100 Finally in Line 110 is a different version of the variable TAB an arrangement where the RND element forms part of the argument 10 MODE 20 VDU19 3 10 0 0 0 30 CO
58. it is set on power up You can toggle out of this mode and into U L mode by pressing the key and the Commodore key simultaneously In direct mode you simply press either the or the C key in conjunction with the required key to obtain one of the two graphics shown on the front of the key With Ck you can get the graphics shown on the left hand of the key whether the display is in U G or U L modes The key naturally produces capital letters when used in U L mode but can be used to access the right hand key graphics U mode If you are unfamiliar with the ROM graphics switch on your computer and try out the various keys Pressing a key on its own should result in its face value being displayed but with two important exceptions which we ll get to shortly quote and insert modes So avoid pressing or using for the moment Now press the same keys while holding down the Ck key Then do the same while holding down the key A whole series of graphics should be displayed Don t clear the screen yet Now toggle the display into U L mode and note that only the graphics which had been produced with the Ck key remain unchanged Direct mode graphics serve no function other than to display what s available in ROM although this can be useful if you re using them actually within a program to construct an appealing screen display This short program displays what s available 10 FOR 2 0 TO 255 20 POK
59. kes a long time and so is not really worth doing unless you have quite a few different statements to work out BETTER DISPLAY The following programs give you a better title page although they do not need any more complex programming techniques They put right all that was wrong in the last program and add colour and motion to try to make the screen a little more interesting You should note especially the use of PRINT AT and PRINT TAB or for the Commodore cursor control characters as these are needed for almost any PRINTing that you will do 5 LET X 1 10 BORDER 1 PAPER 1 INK 7 CLS 20 PRINT INVERSE 1 AT 3 3 O MARSHALL CAVENDISH LTD LI 30 PRINT INVERSE 1 AT 5 10 O PRESENTS 0O 40 PAUSE 50 50 PRINT PAPER 6 INK 1 AT 10 10 DIONOPOUOTO 6 PRINT PAPER 6 INK 2 FLASH 1 AT 9 95 m mnm mm m 110 a 70 PRINT PAPER 6 INK 2 FLASH 1 AT 10 9 10 1 80 PRINT PAPER 5 INK 0 15 2 COPYRIGHT AUDIO VISUAL 1984 90 PRINT OPRESS ANY KEY TO CONTINUE 100 PAUSE 0 110 CLS 120 PRINT O 1 C1 COINPUT PART 1 INDEX 130 PRINT 140 FOR X 1 TO 10 150 READ a 155 READ b 160 PRINT TAB 3 a TAB 25 b 170 NEXT X 180 DATA 26 32 Basic programming 2 7 BREAK Dragon 7 Cassettes 25 Cassette recorders 24 use 26 27 CLEAR 10 27 CLOAD Dr
60. lank spaces PRINT on its own does this Line 130 The NEXT loop which follows reads two string variables from the DATA in line 180 You might think it strange that the page numbers are stored in a string variable form The reason for this is that some of the entries have more than one number Animation for example is on pages 26 32 You could store 26 32 in a numeric variable but when the computer PRINTs it it would treat it as a subtraction and PRINT 6 That would really confuse any user On top of this some of the entries have page numbers separated by a comma and as you know a comma is the punctuation mark used for separating different items in a list of DATA so the two page numbers although they refer to the same entry would be treated as if they belonged to two entries You might also think that it would be clearer to store the DATA for the entries in a separate Line to the one used for storing the page numbers The RESTORE command would en able the program to switch between the two separate Lines and all would be fine Wouldn t it In fact the answer is no because the RESTORE command sends the computer to the beginning of the relevant Line of DATA and so the computer would PRINT out the same entry and the same page number every time which is all very well if you want to know where Animation is but not otherwise Of course one way round this is to use a separate Line for each item of DATA
61. lt or which hasn t been thought out properly For example you may have noticed how many otherwise very good games make such mistakes as PRINTing you have one lives left This particular case is easily put right with a simple IF THEN statement of the form IF L 1 THEN PRINT life and it reflects badly on the programmer for not changing it Make sure that you remove any bugs of this type from your programs before you start to worry about the format You will probably find it helpful to keep a few guidelines in mind when you are creating a screen display The most important thing to aim for is clarity If words are too close together then they will be hard to read so space out the different lines carefully Make sure too that none of the words are split onto two lines If this cannot be avoided you should put a hyphen at the end of the first half of the word and make the break at a logical point If you need to PRINT something which is INPUTted by the user such as the name on a hall of fame you must ensure that what is PRINTed does not interfere with the rest of the screen To do this you could include a routine which either doesn t allow names of more than a certain number of letters see page 377 for an error trapping procedure to do this or which makes sure that whatever the length of the name it is put in a position that does not affect the position of the score or other PRINTed information on
62. ly identical but the latter works only once after going into insert mode Quote mode works until the next set of quotes or until a program line terminates By itself this is not really much of a problem Things change though when it comes to editing a program line For example press the cursor down key ten times after you enter the first quotes in the following line 10 PRINT Press RETURN to enter the line then return to its midpoint as if to do some editing say to change some of these to cursor right symbols 2 gt Ar fiM o 4 gt PICTORIAL GRAPHICS PROGRAMMING GRAPHICS HOW TO OBTAIN SYMBOLS EDITING REFERENCE CHART COMMODORE PROGRAM SYMBOLS What you want Keys to press ASCII Appearance Cursors so that HELLO is displayed away from the left cursor down CRSR 1 17 E hand edge of the screen cursor up SHIFT and CRSR f 145 All that happens when you try overwriting cursor right CRSR 29 the cursor down symbols is the cursor moves cursor left SHIFT and CRSR 157 to the right Matters don t improve if you try CLR HOME EUR ANS SIS a Cursor to top left CLR HOME 19 E Ditto plus clear SHIFT and CLR HOME 147 0 as this It s simplest actually to enter quote mode again by placing the cursor over the first INST DEL quote marks Then retype the quotes and the Delete character CTRL a
63. matting a neat text page MACHINE CODE 16 To take the hard work out of assembly INDEX The last part of INPUT Part 52 will contain a complete cross referenced index For easy access to your growing collection a cumulative index to the contents of each issue is contained on the inside back cover PICTURE CREDITS Front cover Digital Arts Page 413 Howard Kingsnorth Page 414 Tudor Art Studios Page 416 Kuo Kang Chen Page 421 Digital Arts Pages 422 424 426 427 Paddy Mounter Page 428 Jeremy Gower Chris Lyon Page 430 Chris Lyon Page 432 Richard Prideaux Pages 433 435 438 Colin Mier Pages 436 437 Peter Reilly Pages 440 442 Artist Partners Gino D Achille Marshall Cavendish Limited 1984 5 6 All worldwide rights reserved The contents of this publication including software codes listings graphics illustrations and text are the exclusive property and copyright of Marshall Cavendish Limited and may not be copied reproduced transmitted hired lent distributed stored or modified in any form whatsoever without the prior approval of the Copyright holder Published by Marshall Cavendish Partworks Ltd 58 Old Compton Street London W1V SPA England Printed by Artisan Presss Leicester and Howard Hunt Litho London HOW TO ORDER YOUR BINDERS UK and Republic of Ireland Send 4 95 inc p amp p IR 5 95 for each binder to the address below Marshall Cavendish Services Ltd Department 980 Ne
64. n only answer specific queries and please do not telephone Send your queries to INPUT Queries Marshall Cavendish Partworks Ltd 58 Old Compton Street London W1V SPA INPUTIS SPECIALLY DESIGNED FOR The SINCLAIR ZX SPECTRUM 16K 48K 128 and COMMODORE 64 and 128 ACORN ELECTRON BBC B and B and the DRAGON 32 and 64 In addition many of the programs and explanations are also suitable for the SINCLAIR ZX81 COMMODORE VIC 20 and TANDY COLOUR COMPUTER in 32K with extended BASIC Programs and text which are specifically for particular machines are indicated by the following symbols SPECTRUM 48K 128 n Ck ommosoes 64 end 128 BBC B and B MES 32 and 64 TANDY TRS80 Em nn vic 20 T COLOUR COMPUTER 4 Add your computer s data handling capacity to its graphics functions and you have the basis for a whole range of programs to display any information as a graph or chart Data storage and processing is something at which computers have always excelled But unfortunately it isn t so easy for a computer s user to assimilate a mass of information If you are presented with a list of perhaps a hundred figures it s very difficult to see an overall pattern For example take a close look at the following list of numbers 132 09 146 2 132 89 12392 147 01 15347 132 09 138 79 147 57 153 9 140 04 142 76 152 76 132 6 135 09 146 98 Now answer the follo
65. nd 1030 will have to be altered if the grid is no longer six squares wide since you add or subtract six to change row on the grid Simply count how many squares there are across the top of the grid and change the figure 6 to the width of your grid THE OBJECTS The objects in your new adventure will be different from those in the NPUT adven ture so you ll have to make quite extensive changes to Lines 160 to 260 Count how many objects you are going to use in the new adventure This number gives the value of NB and it should be the first piece of data in Line 200 and will be used to DIMension arrays in Line 180 and to set up FOR NEXT loops elsewhere in the program It s clearest to use a separate program line for each object but if you ve written a game needing a large number of objects you may find that 175 better to have more than one object per line Whichever way you decide to enter your data the order must be right as each of the three pieces of data are fed into different arrays The order then is location number short description long description If the object only appears later on in the adventure perhaps after the adventurer has found it or it is something that appears randomly like the tax inspector the location number should be zero CK 7 4e Wx 4 d Fc NEW WORDS Make a list of all the instructions that you will be expecting the adventurer to give d
66. nd T 20 rest of the PRINT statement including the Insert character SHIFT and INST DEL 148 g amendments you wish to make Rovdss made Alternatively position the cursor to delete R CTRL and 9 18 i everse on an unwanted symbols and when you ve done this CTRL and 0 146 am use to create extra spaces for the new symbols or characters you wish to incorporate Text Colour Each use of allows one entry in insert Black CTRL and 1 144 mode White CTRL and 2 5 E If during the course of editing you lose Red CTRL and 3 28 E track of what you are doing or for instance Cyan CTRL and 4 159 b you enter quote or insert mode unintention Purple CTRL and 5 156 5 ally simply the line and start editing Green CTRL and 6 30 it again Or retype the whole line from scratch Blue CTRL and 7 31 ud Yellow CTRL and 8 158 TOKENS Orange CK and1 The last 129 a The last thing for which the graphics symbols Brown and2 eight items in 149 are used on the 64 is for abbreviating the Light Red and3 column two will 150 keywords Most of the reserved words have an Dark Grey and 4 work on the 151 abbreviation and generally this consists of Medium Grey land 5 Vic 20 152 A typing the first letter and then and the Light Green and 6 153 second letter A full list of the abbreviations Light Blue and 7 154 how they look and what to press to get them is Light Grey C and 8 155 a 421 given on
67. next few lines and RUN the program 210 FOR x 0 TO 12 STEP 2 220 PRINT 21 2 4 230 NEXT x 300 FOR 0 TO 8000 STEP 2000 310 PRINT AT 8000 y 400 0 y 320 NEXT y Lines 210 to 230 loop through the even numbers from to 12 which are PRINTed just below the X axis by Line 220 Similarly th numbers along the Y axis are PRINTed Lines 300 to 320 3 106 TEXT 2 X XS 191 STRS 3 1 3 120 TEXT 2 50 8000 3 1 7 Line 106 PRINTs the numbe below the X axis and Lir largest value 8000 at tl Cx 120 CHAR 18 2 402 122 CHAR 18 10 124 CHAR 18 126 CHAR 2 Lines 120 bela le 0 to 12 just 20 PRINTs the op of the Y axis 127 8000 2 and 124 PRINT 0 6 and 12 just X axis and Line 126 PRINTs the value at the top of the Y axis You ll to change these numbers to suit each set of DATA 00 VDU 5 IR X 2 TO 12 STEP 2 1 XS 24 15 220 MOV 230 PRINT X 240 NEXT 300 FOR Y 2 20 2000 310 MOVE 320 PR 330 NE VDU 4 ines 210 to 240 loop through the even numbers from 2 to 12 which are PRINTed just below the X axis by Line 230 The numbers are PRINTed at positions given by Line 220 Notice that the negative quantities are nece ssary to align the numbers with the axis Similarly the numbers along the Y axis in this case 2000 to 8000 in steps of 2000 are PRINTed by Lines 300 to 330 Change these numbers for different sets of DA
68. nking out routine where nothing is PRINTed on the background In Line 110 POKEing 36867 with 255 switches on the double height character facil ity and POKEing 36869 with 254 redirects the start of character memory pointer to ensure that the particular character set you have redefined is being used There are two other character sets starting at 5 120 and 7 168 which can be accessed by POKEing 253 and 255 respectively into 36869 A and B put the characters ABC and EFG together to make up the two figures of the stunt rider one driving normally the other doing a wheelie as shown in below The reverse arrow at the front end of these strings tells the Vic to make the motorbike blue The string C contains the two flame characters On Line 120 POKEing 36879 with 25 turns the screen border white and POKEing 36878 with 15 sets the sound volume Line 125 clears the screen Line 200 sets up the NEXT loop which moves the motorbike across the screen while the GET readies the machine for the keypresses which control the bike s movement PRINTing a reverse S at the beginning of Line 210 homes the cursor which prevents the screen scrolling POKEing 646 changes the colour of the next character in this case randomly and the rest of the line PRINTs randomly either of the two flame characters The next five lines PRINT and move the bike along Press the left right cursor key and the bike will travel down the screen while pres
69. o do it From the user s point of view there are several things that make the difference between a program which seems well designed and easy to use and one which does not Of course the first thing which will make the difference between a professional looking program and an amateurish one is that it must work pro perly without any bugs or awkward user routines And at a more theoretical level the program itself should be well structured and easy to follow The techniques you need to ensure good structure and freedom from errors have already been covered on pages 173 217 334 and 375 But even the best written program is going to look sloppy and amateurish if it isn t well presented in particular if the screen display is not neat and easy to follow This is fairly simple to ensure but it does mean that you need to give careful thought to formatting the display This means positioning PRINT and INPUT statements correctly to create a neat and interesting layout on the screen The article on page 117 explained the various BASIC commands available on your computer to control the position of characters on the screen Now you will see how to use them to set up a title page for an imaginary game INPUT Similar techniques can also be used for displaying instructions a menu or a prompt and the first thing to do is to look at tidying these up CLEAR INSTRUCTIONS Nothing looks sloppier than a screen display which is mis spe
70. out the graphic so that it can move without leaving a trail on the screen Line 180 sends the com puter back round the circuit so that the graphic can be reprinted in its new position INVERSING THE SCREEN There are several other useful things you can do with the ZX81 screen with machine code The following program inverses the screen that is it changes everything that is black into white and everything that is white into black It can be fed in using your machine code monitor page 280 although the routine should be called from within a BASIC program 2A OC 40 06 17 23 7E FE 76 28 05 C6 80 77 18 F5 10 F3 C9 Call this with the command RAND USR start address direct command RAND USR without a line number clears the screen first so the effect of the routine is not terribly impress ive But even a simple program like 20 LIST 30 RAND USR will do where RAND USR is followed by the start address of the machine code routine You could of course add this routine to the alien program above The line of machine code data should be added to the first program the one that creates the alien as part of AS in a line like 40 LET A A 240 400617237 EFE762805C6807718F510F3C9 Note that this time the bytes are closed up with no space between them Line 50 must be altered to POKE the extra data into the REM statement and should read 50 LET N 16514 TO 16624 And the REM statement in Line 1 should also
71. round colour into the space And POKE 36875 gives you the sound Line 322 checks to see when the torpedo has reached the edge of the screen area turns off the sound again and cancels the torpedo graphic by setting to When the torpedo hits the border Line 330 gives different sounds by POKEing 36877 with a succession of different values and flashes the border by POKEing 36879 Line 335 just POKEs the torpedo graphic onto the screen with POKE 7680 4 X CH and it red by TOES 30400 X with 2 way to PE on the screen with the ZX81 is to PRI graphic symbols shown on the keyboard pv can be useful here too 7 Vue following program creates an dico E Rcs n here e is the t torpedo f iring ie 4 10 LET A 2 0 40223 4047112100 00280319 15 LET A A 10 04016005 F1911BE403ABBAQFE 20 LET A A 00280311 400604 C506041A77231310 25 LET A AS 01100009 110 0 9010000 30 LET AS AS 0000000000000000 0000000000000000 35 LET AS A 8788880480850580 02808001 06850586 50 FOR N 16514 TO 16605 60 POKE N 16 CODE A CODE A 2 476 70 LET A A 3 TO 2E o program which are entered in this BASIC program as the character string A Lines 10 to 25 contain the machine c which actually prints the alien on the screen And the 05 16 byte
72. rts for example Note that the routines covered in this article are beyond the scope of the ZX81 so there are no programs for this machine And because you cannot directly access the graphics func tions in Commodore BASIC the Commodore 64 programs use the Simons BASIC cartridge while Vic 20 owners need to use the Super Expander cartridge STANDARD GRAPH FORMS structure of your program depends on the form of the information you wish to display Where there is a mathematical relationship linking the data you can make use of the mathematical functions stored in your micro s memory For example your micro is pro grammed with the trigonometric ratios such as sine cosine and tangent so it is simple to plot cyclical graphs as was explained in the article on pages 302to 308 or as demonstrated by the following program 30 PLOT 0 76 40 FOR t TO 10 STEP 3 50 DRAW 2 COS t 15 60 NEXT t 20 HIRES 0 1 MULTI 2 4 6 30 XX 0 100 40 FOR T 0 TO 710 STEP 3 50 LINE XX YY T 5 SIN T 50 1 100 1 55 XX T 5 YY SIN T 50 100 60 NEXT T 999 GOTO 999 20 GRAPHIC 2 30 POINT 2 0 512 40 FOR T TO 710 STEP 3 50 DRAW 2 TO T 40 SIN T 250 512 60 NEXT T 20 MODE 30 0 512 40 FOR T 0 TO 10 STEP 3 50 DRAWT 40 SIN T 150 512 E MET er CU 3 A z RA 22 ys M le amp D i nii zy 25 a TAS TS p d
73. s ing the up down cursor key and the bike will do a wheelie and move up the screen Pressing any other key makes it speed up move forward and do a wheelie The reverse sign makes the flame red when moving up or down random colour otherwise POKEing 36877 produces the sound effects And the variable S controls how fast the computer goes round the loop which in turn controls how fast the bike moves across the screen gt 15 MACHINECODE 15 THE SUBMARINE the data are fed in a character at ai im time you only need eight number er Sto c construct the ER Aie rapid program m only needs half as much data The graphici is only eight pixels deep so you do not need to use double height characters Again but this defir eth 422 0 IF G 0 vere cia POKE 36877 D 130 POKE 36879 _D POKE36877 230 D NEXT 59 character The ten ite ms ot di data it e used to create putem P Ds Au 9 43 Dex TS Me EM i s t NT 277 5 FOR Z TO 9 READK Z NEXT DATA 0 128 64 32 16 8 4 2 1 0 10 DATA 0 0 0 0 127 255 127 63 12 DATA 4 7 31 31 255 255 255 255 14 DATA 0 0 0 0 254 237 254 252 16 DATA 0 0 128 0 62 62 0 128 18 DATA 0 0 1 0 124 124 0 1 20 DATA 0 0 0 0 127 233 127 63 22 DATA 32 224 248 248 255 2995 255 255 M ES 52 mr OR Z 0 TO 7 7 8 RE ESI P PORE 144 EXNER 105 FOR Z 0 TO 7 POKE NEXT POKE
74. s for the program The save option S on the main menu only saves the assembly language mnenomics or source code To save the assembler itself use the normal save routine see page 23 To save the machine code program or object code you have to get out of the program by pressing the key Then key in CSAVEM NAME START END DEFEXEC Here NAME is the name of the program which must be in quotes START is the start address of the program given as the origin And END is the end address which the assembler gave you when it finished assembling The last number you must give it DEFEXEC tells the Dragon where to start when you tell it to EXECute the machine code program In other words it DEFines the EXEC command Usually this will be the same as the start address Now you are ready to assemble any rou tines and assembly language programs To test your assembler try keying in the assembly language right scrolling program given on page 327 Whether you hand as semble that program or feed it into your assembler the machine code should read 8E 06 00 E6 82 34 04 C6 1F A6 82 A7 01 5A 26 F9 35 04 E7 84 8C 04 00 2E EA 39 CUMULATIVE INDEX An interim index will be published each week There will be a complete index in the last issue of NPUT Abbreviating keywords 421 Adventure stories structure 422 characters in 422 sources of inspiration 422 424 Adventure themes plots and storylines 422 423 Alien flas
75. s not the case they just move the cursor As with many commands on the Commo dore you can achieve the same effects with certain POKE commands These two POKEs move the cursor to the specified position POKE 781 desired horizontal position POKE 782 desired vertical position If you use these two POKEs to move the cursor you should place this command in front of every PRINT statement which uses them SACIA DD AAAAIAIS L SIC P ROGRAMMING SYS 65520 Following this call PRINTing starts at positions set by the POKEs As there are 25 lines in the Commodore s screen POKEing the second of these POKEs with a number greater than 25 causes the computer to start at the top of the screen once it is at 25 and count down again The same happens if you POKE the first number with a value greater than 40 The number after the PRINT command as you probably know refers to a character square on the computer s text screen As there are only 512 squares on the screen this number cannot be more than 511 or an error message will appear You can work out the number of the character square at which you want to start PRINTing quite simply The first thing to do is to decide which line you want to PRINT remember to count from Line Then multiply this number by 32 the number of characters in a line Then add a number between 0 and 31 to this to find the number of the square you want If you want to PRINT a word or
76. s of them in all in Line 30 overprint the graphic with blank spaces when you move it IR CE B B E E EFE E Line 35 contains the details of the alien itself If you look at the string byte by byte a pair of digits at a time and compare them gt with the character set in Appendix A of your NS VOR RM N pw ZX81 manual you will see that they corre SWAT EDITOR fois Gre vor ER spond to the graphic and inverse characters MEN D These characters build up the alien block D REL wo SENT MD ede by block in an 8 x 8 square starting at the top APER GINS SOT RS Use Ra left and working across and down to the en 5 PRR a gt e Ga Mert V gar Cee bottom right As the graphics characters them AA OUR Ucet tk FO x I a i ica epis MEE cheracier sce into DUM 2 4 it Try designing your own alien on an 8x8grid Then put the appropriate numbers into Line 35 5 When you RUN this program Lines 50 to 80 POKE the data in the strings into the space occupied by the REM statement And if you LIST the program again you will see the symbols corresponding to the machine code appear in the REM statement The last part of it will show you the graphics characters that build up the alien end to
77. t 1 when the lamp is and when it is off TA tax inspector flag E SW exit directions Set at 1 if there is an exit and to if there isn t I the whole input before it s split into verbs and nouns V the verb part of I N the noun part of I number corresponding to parti cular verb meaning Used to pick out the correct routine the one that handles that particular verb IN the number of objects in the INVENTORY A the answer to DO YOU WANT ANOTHER GO G the number of the object dropped element G in array OB The Spectrum programs work a little differ ently from the others owing to Spectrum BASIC s lack of ON GOSUB and ON GOTO They are no great loss though the program still works just as well and isn t any more complicated to extend LOCATION DESCRIPTIONS The first step in altering the Spectrum program is to enter all the location descriptions from your grid The descriptions are put at the end of the program just as in the INPUT adventure Enter all the location descriptions in order each followed by the line containing the exit direction information the variables N S E and W refer to north south east and west and the values 0 and 1 refer to no exit and an exit respectively Don t forget to enter the REM lines which will enable you to keep track of the location numbers which refer to the location descriptions NEW WORDS Make a list of all the things
78. ted as they are executed You can compare these against the published program To switch the trace off key in TROFF 1890 X LEFT AD 1 BD MID AD 2 IFX THENR PS ADS BD GOT01870 1900 IFX THENADS BD GOTO 1880 1910 IFX THENADS BD S S GOTO1880 1920 0 Q IFX lt gt THEN1950 1930 IFBD gt 0 ANDBDS lt 2 THEN Q Q 2 ASC BDS 48 BD MIDS BD 2 GOTO1930 1940 R R Q S ADS BD GOTO1870 1950 IFX lt gt S ORBDS lt 0 0880 gt G THEN1980 1960 Q2 VAL amp H LEFT BD 1 BD MID BD 2 0 0 16 Q2 X LEFTS BDS 1 1970 IF X gt lt gt ANDX lt gt 960 ELSER R Q S AD 0 60701870 1980 IFX lt gt 2 2010 1990 C AD GOSUB1350 IFC lt gt GOSUB1390 2000 R R RR Q2 S AD 60701870 2010 lt 0 gt 9 THENR 0 NU 1 RETURN 2020 IFADS gt ANDADS lt Q 10 ASC AD 48 AD MIDS AD 2 GOTO2020 2030 R R S 0 GOTO1870 SPEED UP THE ASSEMBLER It is possible to speed up the assembler by adding the speed poke POKE 65495 0 to the start of Line 180 If you do this you ll also have to change two other lines to slow down the computer again before saving the data to tape So add POKE 65494 0 to the start of Lin
79. the correct routine according to the verb that the adventurer has used In order that the com puter can do this Line 510 will have to be altered All you have to do is to look at your verb numbers list Now using that numerical order enter the start lines of the routine for each verb after the GOTO HELP ROUTINE The final routine that you should turn your attention to is the HELP routine Consider where the adventure might need a hint and use an IF THEN line to give the hint Other odds and ends such as the line which makes the tax inspector appear Line 320 may need to be altered or deleted according to the demands of your adventure Also attend to the start location set in Line 280 VARIABLES ETC So that you get inside the adventure program here s a list of the variables and arrays and what they re used for array containing the verbs and responses R array of response numbers Corresponding elements in the two arrays above are the pairs of verbs and meanings OB array containing the location num ber of each object OB array containing the short object descriptions SIS array containing the long object descriptions Corresponding elements in the arrays above contain information about a single object NB the number of objects in the ad venture Used to DIMension arrays and set up FOR NEXT loops L current location of the adventurer LA lamp status flag Set a
80. the other method as explained above The scale factors are set at Line 30 Line 80 moves the cursor to the first X Y position and the points are plotted by the loop at Lines 90 to 110 Lines 130 to 160 draw the axes This graph does not make full use of the space available on the screen so it might be worth changing the scale factors at Line 30 Iry halving them or doubling them then RUN program to see the different effects To he axes as well as the graph add the scale he lines that draw them as below scal factor 140 DRAW 0 2000 ys 160 DRAW 12 xs Cx 140 LINE 10 190 8000 YS 10 190 1 150 LINE 10 190 12 XS 10 19 140 DRAW 2 100 923 8000 YS TQ TO 12 XS 100 923 140 DRAW 08 140 LINE 20 0 20 3200 YS PSET 160 LINE 20 YS 3200 255 YS 3200 PSET RUN the program and notice the axes extend only to the maximum values The effect will be more noticeable if you replace the initial values in Line 30 Now you can cope with any value provided you change the scale values at Line 30 accordingly Try some different values in the DATA statement and practise varying the scale factors With very large numbers you need to leave a larger margin along the Y axis Alternatively you could retain the same mar gin but PRINT a factor for example x10 by which values along the Y axis are multiplied To place some legends on the graph enter the
81. the screen PLANNING THE DISPLAY ON THE SCREEN IMPROVING THE LAYOUT 5 PLANNING THE DISPLAY a HOW TO POSITION TEXT E ik ADDING COLOUR Where you have a list again such as a high score table you should PRINT each line starting at the same column This may seem obvious but even some commercial programs do not do this The second thing to bear in mind when you are designing a display is that you should not try to cram too much information onto the screen at once If you do put too much on the program user will not be able to remember it all and so will not be able to make the most of your program At the same time do not put so little information onto the screen that you need to PRINT a large number of screens The hard part is to get the balance right Of course just what this balance is depends on the program the simpler your program is the better the user wil be able to understand it and the less instructions you will have to display USING COLOUR Try and make the screen interesting If you can have a variety of colours on the screen at once do so it brightens up the display and so makes it easier for the user to read or to pick out particular elements You can choose whether to colour the text or the background or both or just have a coloured border Spectrum is lucky here in that it has a very versatile FLASH command The chang ing picture that results from using flas
82. tine between Lines 80 and 90 The last two lines are positioned and PRINTed Lines 110 and 120 in red Line 100 So far all positions have been selected by PRINT TAB statements To decide what values they should have you need to know how many characters are printed across and down the screen in the mode in which you are working In MODE 1 this is 40 across and 32 down So if you want to print INPUT at the centre of the screen you would key PRINT TAB 17 15 These positions are easily reckoned on the Text Planning Sheet included at the back of the User Manual The finishing touch to this title page is added by Line 130 which DRAWs a rectangle around the four sides of the word INPUT You will also find it easy to reckon the position of each of the corners of the rectangle by referring to the Graphics Planning Sheets at the back of the User Manual The PRINT TAB statement is useful when you want to place text at a position on the screen but when you wish to leave spaces to form a pleasant display you need a simpler technique Enter and RUN the next section of program na 2 2 2 1
83. tion Vic 20 ZX81 428 432 assembler Dragon Tandy 430 444 Maximum values graph axes 419 Memory considerations for adventures 422 Minimum values graph axes 419 Moving around the adventure grid Acorn Commodore 64 Dragon Tandy Vic 20 424 Spectrum 427 O Objects in adventures Acorn Commodore 64 Dragon Tandy Vic 20 424 Spectrum 427 On board graphics Commodore 64 420 Parabolas drawing 415 Planning screen displays 433 439 Postbytes 6809 Processor 440 444 PRINT Acorn Commodore 64 Spectrum Vic 20 434 PRINT AT Acorn 434 Spectrum 434 436 PRINT SPC Commodore 64 Vic 20 434 435 PRINT TAB Acorn 434 438 Commodore 64 Vic 20 435 Spectrum 434 PRINT Dragon Tandy 435 Processor 6809 440 Professional looking programs 433 439 Program graphics Commodore 64 420 Program symbols Commodore 64 420 Pseudo hi res graphics ZX81 432 Q Quote mode Commodore 64 420 R Reverse graphics symbols Commodore 64 420 ROM graphics Commodore 64 420 5 Scaling a graph 417 418 factors 418 SCREEN command Dragon Tandy 439 Sine waves 415 Speed POKE Dragon Tandy 444 Stunt rider UDG Vic 20 429 Submarine UDG Vic 20 430 Superexpander cartridge Vic 20 414 T Tandy assembler 440 444 how it works 444 testing 444 Tandy speed POKE 444 Title pages for games 433 439 Toggling the screen display Commodore 64 420 Tokens Commodore 64 421 TROFF command Dragon Tandy 444
84. u do not have to take any action If they are not all the same length you will have to fill up all the shorter lines with zeros to make them up to the same length as the longest or else the program will not work correctly VERB ROUTINES Each of your separate categories of verb will need a separate routine It is difficult to give explicit instructions on how to write these routines because a large proportion of them will be only applicable to one particular adventure However the INPUT adventure has a number of routines which will be useful as they stand in most if not all adventures For example there are GET and DROP routines which can be copied straight into any adventure because they are fundamental rout ines if you are to use any objects in the game INVENTORY will be suitable for use in most games too it s up to you whether you incorpo rate such a facility in the game but it would be a rather strange adventure without it The rest of the routines depend on the requirements of the adventure Take your lead from how the routines are structured for the rest of the existing program Bear in mind where and to what a certain verb could apply Check that the instruction has been applied to the correct location and to the correct object Try to think through which wrong instructions the adventurer could give and structure the routines accordingly Once you have written all the routines you should enter them between Lines 13
85. uring the adventure The list should include single words such as the directions and HELP and INVENTORY and two word commands like GET LAMP or KILL LANDLORD The two word inputs are split into V and N verb and noun although these are not always strictly according to their grammatical definition You are interested in all the single words and the first word in each of the pairs For the program s purposes these are the verbs V s Group the verbs together accord ing to their meanings CHEW and EAT or SMELL and SNIFF should be grouped tog ether for example Each of these groups will need a number so note that down too It doesn t matter what the number is as long as you know which number refers to which particular group of words Y M NV GN Sy id Now alter the program The routine that deals with verbs is from Line 110 to 150 The verbs and their numbers are entered as data in Lines 140 and 150 set out as pairs with the numbers following the verbs Don t forget to re DIMension the arrays in Line 120 and to adjust the NEXT loop in Line 130 according to the total number of verbs you wish to use VERB ROUTINES Each of the separate verb categories numbers will need a separate routine It s difficult to give explicit instructions on how to write these routines because a good proportion of the routines in any adventure will not be of any use elsewhere But there are some
86. ut ASCII codes cannot be used with this assembler In consequence the as sembler directive FCC which manipulates ASCII characters cannot be used To edit a line before it has been entered use the cursor controls The left arrow and right MM arrow move the cursor along the line The up arrow can be used to insert something the down arrow deletes Otherwise you can simply overwrite the line last line of any program should say END but the assembler will put one in if you forget If instead of pressing after a line you press another key the program will take you back to the menu If you then press L your mnemonics will be listed for you to check If something is wrong return to the menu and press E again then specify the number of the line you want to change If you want to insert a line go into the edit mode and give your new line a number which falls between the numbers of the lines you want to put it between When you list the program again it will have shoved the sub sequent lines along and renumbered them so that they are in tens again Only insert one line at a time this way though To delete a line go to the main menu and press D then specify the number of the line you want to delete When you are satisfied that the program is okay return to the main menu and press A program will then be assembled When it has finished it will give you an end addres
87. w ing questions a Which is the highest number in the list b What is its position in the list c How many numbers are there below 135 5 This isn t particularly easy but imagine how ESO Tee 17 7 MEM m cmM i f EX LS ET i d i difficult it would be if there were five times as many entries in the list The traditional answer to this sort of pro blem is to display the information graphically When the same data is presented as a chart it 15 easy to see which point is the highest and how far along it comes Or by ruling off at a particular point you can check all those values which are above or below a certain level Of course you could also get your computer to make these checks for you and print out a result but this will not give you any feel for the 31 BASIGPROGRAMMING overall trends and more often than not will just result in another mass of incomprehen sible data for you to sort out In Applications on page 257 you have already seen one example of a program which allows you to enter data which is then dis played in the form of a bar chart on the screen 7 This article covers what s involved in writing your own programs to draw linear graphs And in a later article we take a closer look at the other types of display histograms and pie cha
88. which ought to be improved Firstly capitals could be used to good effect the Spectrum version uses almost ent irely lower case letters even for the first word of the display and for the name of the game Capitals can be used to stress important words or even for all the words in order to give the display a more professional appearance Secondly the screen should always be cleared before PRINTing a new message Other wise as with the program above the remain der of anything already on the screen stays in sight making the display untidy There is no space in between the two words Marshall and Cavendish There should be and it looks especially untidy with the words PRINTed as they are now with Cavendish overflowing onto the next line See below to find how you can position your PRINTs correctly program does not wait for you to press a key before continuing so that you have not really got enough time to read the screen properly before it is wiped off This should not happen and there ought to be a line of text telling you what to do when you want to continue You can work out where you want to PRINT things on the screen quite easily from the dimensions of your computer s screen and the number of characters in the words For example suppose your computer has a screen with 22 lines of 32 characters and you want to PRINT a phrase 10 characters long in the middle of a line one line from the top of th
89. wtown Road Hove Sussex BN3 7DN Australia See inserts for details or write to INPUT Times Consultants PO Box 213 Alexandria NSW 2015 New Zealand See inserts for details or write to INPUT Gordon and Gotch NZ Ltd PO Box 1595 Wellington Malta Binders are available from local newsagents There are four binders each holding 13 issues BACK NUMBERS Back numbers are supplied at the regular cover price subject to availability UK and Republic of Ireland INPUT Dept AN Marshall Cavendish Services Newtown Road Hove BN3 7DN Australia New Zealand and Malta Back numbers are available through your local newsagent COPIES BY POST Our Subscription Department can supply copies to any UK address regularly at 1 00 each For example the cost of 26 issues is 26 00 for any other quantity simply multiply the number of issues required by 1 00 Send your order with payment to Subscription Department Marshall Cavendish Services Ltd Newtown Road Hove Sussex BN3 7DN Please state the title of the publication and the part from which you wish to start HOW TO PAY Readers in UK and Republic of Ireland All chequesor postal orders for binders back numbers and copies by post should be made payable to Marshall Cavendish Partworks Ltd QUERIES When writing in please give the make and model of your computer as well as the Part No page and line where the program is rejected or where it does not work We ca
90. x inspector His role could be either to help or hinder the adventurer There are various ways you could use a castaway theme in your adventure Try using traditional pirate type castaway or you could have your adventurer being the sole survivor of a jumbo jet crash Setting the adventure in the future you could have a disaster in space leading to the adventurer being marooned on a hostile planet light years from civilisation with a defective rocket The object of the adventure could be to contrive some way to escape The locals could very well be hostile and there is plenty of scope for imaginative and hidden escape routes Other escape plots could include escaping from Alcatraz or Colditz or Dartmoor you name it Sources of inspiration could be any one of a number of Escape from books that have been written and if you can get a map of the real place so much the better for planning out your locations Spies either traditional ones or even in dustrial espionage stealing a rival s com puter design perhaps are likely to be a very happy hunting ground for the adventure writer y You could plunder stories from history The Crusades are an obvious setting for an adven ture game or any military campaign dixe fu M 14 GAMESPROGRAMMING 14 THINKING ABOUTA NEW W ADVENTURE ADVENTURE POSSIBLE THEMES W NEW WORDS EXTRA LOCATIONS WRITING VERB RO

Download Pdf Manuals

image

Related Search

Related Contents

Samsung ML-5100A Manuel de l'utilisateur  31100662 GVC 71013NB-S  MANUEL DU PROPRIÉTAIRE  Sun SPARC Enterprise T5120 and T5220 Server  Betriebsanleitung  Mode d`emploi  POWER USER`S MANUAL  MANUAL DE USUARIO  Lexmark X952dte  f7d2102-user-manual-it  

Copyright © All rights reserved.
Failed to retrieve file