home *** CD-ROM | disk | FTP | other *** search
/ A.C.E. 2 / ACE CD 2.iso / FILES / DOCS / AMOSDOC.LHA / AmosPart1.doc < prev    next >
Encoding:
Text File  |  1994-11-27  |  87.8 KB  |  2,177 lines

  1.                          AMOS FULL DOCUMENTATION
  2.  
  3. Typed in by MR.SPAGHETTO/ACCESSION. Edited by PARASITE.
  4.  
  5.  
  6. How was it all done?
  7. AMOS Basic was designed and progrqammed by François Lionet. His clever
  8. ideas and inspirational work have produced what we feel to be by far
  9. the best high-level programming language available on the amiga to
  10. date.
  11.  
  12. AMOS was developed using the following programs:
  13.         DEVPAC II Assembler - HiSoft
  14.         Deluxe Paint III - Electronic Arts
  15.         Pix Mate - Progressive Peripherals & Software
  16.         Cross-Dos - Consultron
  17.         Mini Office Professional Communications - Database Software
  18.  
  19. Mandarin Software would like to thank the following people for their
  20. kind help during the development of AMOS:
  21.  
  22. Allistair Brimble, Aaron and Adam Fothergill of Shadow Software, Peter
  23. Hickman, Rico Holmes, Commodre UK for the international keyboard
  24. layouts (an the Amiga), Commodore France for the help with the A1000
  25. problem, 17-Bit Software for samples and demos, Martyn Brown for fonts
  26. and support, Virus Free PD for Soundtracker, Simon Cook for his
  27. constructive comments and bugfinding, Lee, Alex, all other AMOS
  28. developers for their kind help and all of you who have waited patienly
  29. for this software. We hope, like us, you feel it was well worth the
  30. wait.
  31.  
  32. This manual (the original , not this ASCII file) was written using
  33. WriteNow on the Apple Macintosh and paged up with Page Maker.
  34.  
  35. Copyright Notice
  36. Amos will enable you to create some very impressive software. It is
  37. very important that you acknowledge AMOS in your programs using a
  38. phrase such as "Written by John Smith using AMOS", and, where possible,
  39. include the AMOS Sprite.
  40.  
  41. If your program is released commercially, the words
  42. " AMOS © 1990 Mandarin/Jawx " must be included on the back of the
  43. packaging and in the printer instructions.
  44.  
  45. 1: INTRODUCTION
  46. WELCOME to the exciting world of AMOS - The Creator! As you know, the
  47. Amiga is a truly amazing computer. For the first time, all that power
  48. is at your fingertips.
  49.  
  50.   In Septemper 1988, Mandarin Software released STOS Basic for ST. This
  51. made history as the first programming language to reach number one in
  52. the ST Gallup games charts! Now STOS has been rewritten from the gound
  53. up to produce AMOS Basic for the Amiga. AMOS Basic includes a vast
  54. range of over 500 commands - many of which are staggeringly powerful.
  55. You can, for instance, bounce a screen, or animate a sprite using just
  56. a single Basic instruction.
  57.  
  58.   AMOS is not just another version of Basic - it's a dedicated games
  59. creation system which comes with its own built-in Animation Language
  60. (AMAL). AMAL programs are executed 50 times a second using a powerful
  61. interrupt system. They can be used to generate anything from the attack
  62. waves in an arcade game, to a silky-smooth hardware scrolling efect. At
  63. the same time, your Basic program can be doing something completely
  64. different!
  65.  
  66.   Whatever you knowledge of programming, AMOS has something to offer
  67. you. If you have newer written a game before, the prospect of creating
  68. your first game may be quite daunting. But do bear in mind that many of
  69. the all-time classics are uncomplicated programs with one or two
  70. original features - just look at Tetris for example. The strength of
  71. your game will depend on the quality of your ideas, and not just your
  72. programming skill. With a little help from AMOS, you'll be able to
  73. produce professional-looking games with just a fraction of the normal
  74. effort. All you really need is imagination.
  75.  
  76.   If you've written a game in AMOS basic, don't keep it to yourself.
  77. Mandarin Software is very keen to publish any program written using
  78. AMOS. Don't worry if your programming is a little rough. If your ideas
  79. are good enough, you could have a real future as a professional games
  80. writer. So please send us your programs. Mandarin would also be
  81. delighted to hear your comments or suggestions for the AMOS system.
  82. Several features in AMOS were taken directly from the ideas which were
  83. sent to us from existing STOS users. Address your correspondence for
  84. the attention of Richard Vanner, Development Manager, Mandarin
  85. Software, Adlington Park, Adlington, Macclesfield SK10 4NP.
  86.  
  87. 2: GETTING STARTED
  88. AMOS Basic is a truly remarkable package, capable of creating games
  89. which were previously beyond your wildest dreams. All this powerful
  90. features which make the Amiga so irresistible have been incorporated
  91. into this amazing system. With help of AMOS Basic you can develop
  92. programs which would tax the skills of even the most expert assembly
  93. language programmer.
  94.  
  95.   You can for instance, effortlessly animate up to 56 hardware sprites
  96. simultaneously! This is a real achievement, especially when you
  97. consider that the Amiga's hardware only actually provides you with
  98. eight.
  99.  
  100.   If you need even more action on the screen, you can use the Amiga's
  101. blitter chip as well. Blitter objects can be created in any graphics
  102. mode you like, including HAM! The only limit to the number of bobs on
  103. the screen is the amount of available memory.
  104.  
  105.   Any combination of the Amiga's graphics modes can be displayed on the
  106. screen at once. Hardware scrolling isn't jsut possible, it's easy!
  107. There's a built-in SCREEN OFFSET command which allows you to perform
  108. the entire process directly.
  109.  
  110.   In fact, the only hard part of AMOS Basic is knowing where to start!
  111. AMOS supports over 500 Basic commands, and if you're never used Basic
  112. before, you may feel a little overawed by the sheer scale of this
  113. system. When you're in unfamiliar territory, it's always useful to have
  114. a *GUIDE* (Thanks to me!, Mr.Spaghetto ;-) to show you around and point
  115. out some of the notable landmarks. That's the purpose of this chapter.
  116.  
  117. Backup AMOS *now* !
  118. Before continuing however, it's vital that you back up the entire AMOS
  119. Basic package on fresh discs. This will safeguard your copy of AMOS
  120. against accidental mistakes. You'll now be able to play around with the
  121. system as much as you like, without the risk of destroying something
  122. important.
  123.  
  124.   If the worst comes to the worst, we at Mandarin will be happy to
  125. replace your disc for a nominal handing charge. But you'll obviously be
  126. deprived of AMOS Basic while it's being re-duplicated.
  127.  
  128.   The installation procedure varies depending on your precies set-up,
  129. but it can usually be accomplished in a matter of minutes.
  130.  
  131. How to backup?
  132. If you have got this Ascii file into your hands, you propably also
  133. have some cool copy-prog, for example; X-Copy, D-Copy or other...
  134.  
  135. Place the originals into a safe place and use the fresh copies now.
  136.  
  137. Loading AMOS Basic
  138. As you might expect, AMOS Basic can be executed in a variety of
  139. different ways. You can, for instance, load AMOS directly from the
  140. Workbench by selecting its icon with the left mouse button. Once you've
  141. entered AMOS in this way, you will be able to flick back and foth to
  142. the Workbench by pressing the Amiga and A keys from the keyboard.
  143.  
  144.   In practive however, the Workbench consumes valuable memory which
  145. would be better used to hold your Basic programs. So if you're a
  146. serious user, you'll propably prefer to boot up AMOS as part of your
  147. normal start-up sequence. This will allow you to achieve the maximum
  148. possible results from the AMOS system.
  149.  
  150. To load AMOS Basic:
  151.   *  Turn off your Amiga and wait for about ten secs.
  152.   *  Place a backup of the AMOS program disc (disc 1) into DF0:
  153.   *  Now switch on your Amiga. AMOS will load into memory
  154.      automatically.
  155.   *  Hit a key to remove the information box and thus enter the
  156.      AMOS system.
  157.  
  158. AMOS tutorial
  159. The first thing you'll see when you enter AMOS Basic is the editor
  160. window. This is extremely easy to use, and if you've a little previous
  161. experience with computers it should be self-explanatory. Feel free to
  162. experiment as much as you like. The AMOS editor is quite intelligent,
  163. and you are unlikely to make any serious mistakes.
  164.  
  165.   Now you've seen the editor window, It's time to explore some of the
  166. features that make AMOS Basic really stand out from the crowd.
  167.  
  168. Loading a program
  169. We'll start off by showing you how you can load one of the terrific
  170. games from the AMOS data disc. We'll take the Number Leap game as an
  171. example:
  172.  
  173.   * Insert the AMOS_DATA disc into drive DF0:
  174.   * Hold down an Amiga key on the keyboard and press "L". This will
  175.     bring up a standard file selector on the screen.
  176.   * Click on the disc drice label DF0 to inform AMOS that you have
  177.     changed the disc.
  178.   * At the centre of the file selector there will be a list of
  179.     programs which can be loaded into AMOS Basic.
  180.   * To select the Number Leap program, just position the mouse pointer
  181.     over the file:
  182.  
  183.     Number_Leap.AMOS
  184.  
  185.     The file you have chosen will be highlighted accordingly.
  186.  
  187.   * Once you've chosen your file, you can load it by clicking twice
  188.     on the left mouse button. Your game will now be entered from the
  189.     AMOS DATA disc and you will be returned to the original editor
  190.     screen. The contents of this window will be updated to display
  191.     your new program listing.
  192.  
  193.   * You can run this program by selecting the RUN button from the main
  194.     menu area (or hit F1 if you're feeling lazy).
  195.  
  196.   The editor screen will now disappear completely and Number_Leap will
  197. be executed in front of your eyes. After you've played with this game
  198. to your satisfaction, you can exit to AMOS Basic by pressing the CTRL
  199. and C simultaneously.
  200.  
  201.   CTRL+C provides an effective way of breaking into the vast majority
  202. of AMOS programs. It can be disabled from within your program using a
  203. BREAK OFF command for extra security. When the program has been broken
  204. into yu can flick straight back to the editor by pressing the Spacebar
  205. key from the keyboard.
  206.  
  207. Deleting a program
  208. Now that we've finished with the Number Leap program, we can erase it
  209. from memory with the NEW command. You won't find this option on the
  210. main menu, as it's been placed in a separate SYSTEM menu. This can be
  211. brought into view by moving the mouse pointer over the menu window and
  212. holding down the right mouse button.
  213.  
  214. To delete a program:
  215.  
  216.  * Ensure the mouse pointer is over is over the menu area.
  217.  * Hold the Right mouse button down to bring up the SYSTEM menu.
  218.  * While the button is depressed, move the pointer over the NEW option
  219.    and select it with the Left mouse key. Alternatively, you can
  220.    execute this option directly from the keyboard by pressing
  221.    Shift+F9.
  222.  * Type Y to confirm the operation or N to abort.
  223.  * If the current program hasn't been saved, you'll been asked whether
  224.    to store it onto the disc. If you select the YES option, you'll
  225.    be presented with an AMOS file selector. Otherwise your program
  226.    will be totally erased.
  227.  
  228. Direct mode
  229. We'll now have a quick look at the direct mode. This forms the centre
  230. of the AMOS Basic package and allows you to experiment with your
  231. routines and immediately observe the effects.
  232.  
  233.   It's important to recognize that all the screens, sprites, and music
  234. defined in your program are completely separate from the Editor window.
  235. So no matter what you do in direct mode, you'll be able to return to
  236. your listing with just a single keypress.
  237.  
  238.   * Enter direct mode by pressing ESCape. The editor window will slide
  239.     away and you'll be presented with the main program display.
  240.  
  241. Towards the bottom of this area will be a small screen which can be
  242. used to enter your direct mode commands. Try typing the following line,
  243. pressing Return to "execute".
  244.  
  245.         Print "Your name"
  246.  
  247. Insert your name between the quotes to print your names on the Amiga's
  248. screen. Now press the UP and DOWN arrows from the keyboard to move the
  249. window around the display area. As you can see, the Direct mode window
  250. is totally independent of the main program screen.
  251.  
  252. Animation!                                                                  7
  253. So much for the Direct mode. Let's experiment with some of the AMOS
  254. Basic sprite instructions. Before we can use these commands, we'll need
  255. to load a set of sprite images into memory. Stay in direct mode and
  256. enter the indented lines in bold as you come to them.
  257.  
  258. Listing the sprite files
  259. We'll begin by listing all the available sprite files to the Amiga's
  260. screen.
  261.          * Ensure that the AMOS DATA disc is still in the DF0:
  262.          * Display the disc file directory with the line:
  263.  
  264.         Dir "AMOS_DATA:Sprites/"
  265.  
  266. This will display the sprite files we've supplied on the AMOS data
  267. disc. These files contain all the images which are used in the various
  268. example programs. You can create your own images using the Sprite
  269. definer accessory on the AMOS Program disc.
  270.  
  271.   The sprite definer incorporates a host of powerful drawing features
  272. which make it extremely easy to generate professional-quality animation
  273. sequences in your games.
  274.  
  275. Loading a sprite file
  276. We can now load these sprites using the LOAD command. The sprites will
  277. load into a special memory bank so don't except to see any sprites to
  278. appear yet! Let's enter the sprites used by the Number Leap game with
  279. the following command:
  280.  
  281.         Load "AMOS_DATA:Sprites/Frog_Sprites.abk"
  282.  
  283. If you make a mistake, hit F1 to get your previous line. This line can
  284. be then edited using the normal cursor keys and may be re-executed by
  285. pressing Return.
  286.  
  287.   Now let's also load up a music file using a similar load command:
  288.  
  289.         Load "AMOS_DATA_Sprites/Funkey.abk"
  290.  
  291. In order to check whether the sprites and music have been succesfully
  292. loaded into memory, we'll call up the LISTBANK instruction like so:
  293.  
  294.         Listbank
  295.  
  296. This prints a line like:
  297.  
  298.         1 - Sprites       S:$0682B0  L:000040
  299.         3 - Music         S:$043878  L:0081FE
  300.  
  301. Don't worry if the numbers do not correspond as they will change
  302. depending on the available memory. The number of sprites we've just
  303. loaded can be returned directly with the LENGTH function.
  304.  
  305.         Print Length(1)
  306. ( result: 64 )
  307.  
  308. Setting the sprite colours
  309. Each set of sprite images has its own set of colour values stored on
  310. the disc. Since these can be very different from your current screen
  311. colours, it's useful to be able to GRAB the colours from the sprite
  312. bank and copy them into an existing screen. This can be accomplished
  313. with the GET SPRITE PALETTE command. Enter the line:
  314.  
  315.         Get Sprite Palette
  316.  
  317. All the colours in the main program screen will change immediately, but
  318. the direct mode window will be completely unaffected because it's been
  319. assigned its own separate list of colour values by the AMOS system.
  320.  
  321. Displaying a sprite
  322. Sprites can be displayed anywhere on the screen using a simple AMOS
  323. Basic sprite command. Here's an example:
  324.  
  325.         Sprite 8,129,50,62
  326.  
  327. Animating a sprite
  328. Let's animate this object using The "AMos Animation Language". AMAL is
  329. a unique animation system which can be used to move or animate your
  330. objects at incredible speed.
  331.  
  332.   Note that when you're entering the following example programs, it's
  333. essential to type each line *exactly* as its appreas in the listing, as
  334. otherwise you may get an unexpected syntax error.
  335.  
  336.         Sprite 8,129,150,62
  337.         Amal 8,"Anim 0,(62,5)(63,5)(64,5);" : Amal On
  338.  
  339. The program above animates a small duck on the screen. Whilst it's
  340. being manupulated, the sprite cn be moved around using the SPRITE
  341. command. Example:
  342.  
  343.         Sprite 8,300,50,
  344.  
  345. Moving a sprite
  346. Now for some movement!
  347.  
  348.         Sprite 8,129,150,62 : A$="Anim 0,(62,5)(63,5)(64,5);"
  349.         A$=A$+"Loop: Move 320,0,100; Move -320,0,100; Jump Loop"
  350.         Amal 8,A$ : Amal On
  351.  
  352. This programs animates the duck and moves it back and forth across the
  353. screen, using just three lines!
  354.  
  355.   Although the instructions between the quotes may look like Basic,
  356. they're actually written in AMAL. All AMAL programs are executed 50
  357. times a second and they can be exploited to produce silky smooth
  358. animation effects independently of your Basic programs.
  359.  
  360.   Just to prove how amazing AMAL really is, hit ESC to jump back to the
  361. Basic editor. After a few moments, return to direct mode. Your sprite
  362. will still be bouncing accross the screen as if nothing had happened!
  363.  
  364. Music maestro!
  365. For a finale, let's play the music! Ensure you're still in direct mode,
  366. turn up the volume on your monitor and start the music running the
  367. MUSIC command like so:
  368.  
  369.         Music 1
  370.  
  371. By the way, you can stop the music with the command:
  372.  
  373.         Music Off
  374.  
  375. The joyrney continues
  376. Hopefully, you'll now have a pretty good idea of what AMOS Basic can
  377. achieve. But so fat we've only looked at a tiny fraction of AMOS
  378. Basic's power. As you experiment with the AMOS package, you'll quickly
  379. discover a whole new world, full of exciting possibilities.
  380.  
  381.   AMOS Basic can't, of course, transform you into an expert games
  382. programmer overnight. Like any programming language, it does take a
  383. little time to familiarise yourself with the entire repertoire of
  384. commands. We'll therefore end this section with a few guidelines to
  385. help you on your way.
  386.  
  387. Hints and tips
  388.   * The best way to learn about AMOS is to create small programs to
  389.     animate sprites, scroll screens or generate hi-score tables. Once
  390. you've created a little confidence, you'll then be able to incorporate
  391. these routines into an actual game.
  392.  
  393.   * Don't be overawed by the sheer size of the AMOS Basic language. In
  394.     practive, you can achieve terrific effects with only a tiny
  395. fraction of the 500 or so commands available from AMOS. Start by
  396. mastering just a couple of instructions such as SPRITE and BOB, and
  397. then work slowly through the various sections. As you progress, you'll
  398. gradually build-up a detailed knowledge of the AMOS system.
  399.  
  400.   * Although we've attempted to make this package as easy to use as
  401.     possible, a thorough groundging of the general principles of Basic
  402. programming is invaluable. If you're new to Basic, you may find it
  403. helpful to purchase an introductory text such as "Alcock's Illustrating
  404. Basic. (Cambridge University Press.)
  405.  
  406.   * Plan your games carefully on paper. It's amazing how many problems
  407.     can be completely avoided at the early design stages. Never attempt
  408. to tackle really large projects without prior preparation. It's the
  409. easiest way to get permanently lost.
  410.  
  411.   * When you're writing a game, try to concentrate on the quality of
  412.     the game play rather than the special effects. The graphics and
  413. music can always be added later if the idea's are good enough.
  414.  
  415. 3: THE EDITOR
  416. The AMOS editor provides you with a massive range of editing
  417. facilities. Not only is it exceptionally powerful, but it's also
  418. delightfully easy to use. All commands can be executed either directly
  419. from the screen, or via an impressive range of simple keyboard
  420. alternatives. It's so friendly in fact, that if you've a little
  421. experience with computers, you'll propably be able to use it straight
  422. out of the box.
  423.  
  424.   One of the most exciting features of this sytem, is that the listing
  425. is displayed completely separately from your main program screen. So
  426. you can instantly flick from your program display to the editor window
  427. using a single keypress (ESCape).
  428.  
  429.   If you've plenty of memory, it's also possible to load several
  430. programs in AMOS Basic at a time. Each program can be edited totally
  431. independently, and it's possible to efforlessly switch between the
  432. various programs in memory by pressing just two keys from the editor.
  433.  
  434.   The first thing you see after AMOS has loaded into memory is a
  435. standard credit screen. Applause applause! Press a key to remove this
  436. window and enter the editor.
  437.  
  438. The menu window
  439. At the top of the screen, there's a menu window containing a list of
  440. the currently available commands. This forms the gateway to all AMOS
  441. Basic's powerful editing features. Command can be quickly executed by
  442. moving the mouse pointer over an item, and hitting the left mouse
  443. button. Each command is also assigned to a particular function key.
  444.  
  445.   In addition to the main menu, there are also a number of other menus.
  446. The most important of these menus is the SYSTEM menu. This can be
  447. brought into view by either holding down the right mouse button, or
  448. pressing the shift key from the keyboard.
  449.  
  450.   The SYSTEM manu contains a range of options such as LOAD, SAVE, NEW,
  451. etc. Like the main menu, all options can be executed using either the
  452. left mouse button, or by pressing an appropriate function key.
  453.  
  454. The information line
  455. I  L=1  C=1   Text=40000    Chip=91000    Fast=0    Edit:example
  456.  
  457. The markers at the far left display the editor mode ((I)nsert or
  458. (O)verwrite). There's also an indication of the (L)ine and (C)olumn you
  459. are presently editing. Alongside these markers is a list of three
  460. numbers:
  461.  
  462. TEXT: Measures the amount of memory which has been assigned to the
  463. editor window. This can be adjusted within AMOS Basic using a simple
  464. SET BUFFER command from the SEARCH MENU.
  465.  
  466. CHIP: Free Chipmem                                                          12
  467.  
  468. FAST: Free Fastmem; Whenever possible, this will be used.
  469.  
  470. EDIT: Displays the name of the program you are currently editing.
  471. Initially this area will totally blank, but when you load or save a
  472. program to disc, the new filename will be automatically entered to the
  473. information line.
  474.  
  475. The editor window
  476. The editor window forms the heart of the AMOS system, and allows you to
  477. type your Basic program listings directly from the keyboard. All text
  478. is inserted at the current cursor position, which is indicated by a
  479. flashing horizontal line.
  480.  
  481.   At the start of your session, the cursor will always be placed at the
  482. top left hand corner of the editing window. It can be moved around the
  483. current line using the left and right cursor keys.
  484.  
  485.   Your line can be edited on a character by character basis using the
  486. Delete and Backspace keys. Delete erases the character immediately
  487. underneath the cursor, whereas Backspace deletes the character to the
  488. left of this cursor. As an example, type the line:
  489.  
  490.    print "AMOS"
  491.  
  492. When you press Return, your new line will be entered into AMOS Basic.
  493. Anything AMOS recognices as a command will be immediately converted to
  494. special format. All Basic commands begin with a Capital letter and
  495. continue in lower case. So the previous line will be displayed as:
  496.  
  497.    Print "AMOS"
  498.  
  499. Similarly, all AMOS variables and procedures are displayed in CAPITALS.
  500. This lets you quickly check whether you've made a mistake in one of
  501. your program lines. Supposing for instance, you'd entered a line like:
  502.  
  503.    inpit "What's your name;";name$
  504.  
  505. This would be displayed as:
  506.  
  507.    Inpit "What's your name;";NAME$
  508.  
  509. Since INPIT is in UPPER case, it's immediately obvious that you've made
  510. an error of some sort.
  511.  
  512.   Ok. Now for a little fun. Move the cursor under the Print command you
  513. entered a few moments ago and type in the following lines of Basic
  514. Instructions.
  515.  
  516.    centre "<Touch 'n' Type Demo>                                            13
  517.    do
  518.      x$=inkey$ : if x$ <> "" then print x$
  519.    loop
  520.  
  521. Don't forget to press the Return key after each and every line. Now
  522. move the cursor through your new program using the arrow keys. Finally,
  523. press the F1 to run this program.
  524.  
  525.   The EDITOR WINDOW will disappear and a separate PROGRAM display will
  526. flip into place. The program now expects you to type in some text from
  527. the keyboard. As you can see, the program screen has its own
  528. independent cursor line. This is totally separate to the one used by
  529. the editor. So you can play about as much as you like, without changing
  530. your current editing position.
  531.  
  532.   After you've finished, press CTRL+C to abort the program. A thin line
  533. will now be displayed over the screen. This can moved using the up and
  534. down cursor arrows.
  535.  
  536.      Program Interrupted at line 4
  537.   >>>Loop
  538.  
  539. Pressing the space bar at this point would return you back to editor.
  540. But since we've already seen the editor, let's have a brief look at the
  541. Direct mode instead. Hit the ESCape key to flip this mode into place.
  542.  
  543. An introduction to Direct mode
  544. DIRECT mode provides you with an easy way of testing your Basic
  545. programs. For the time being, we'll examine just a couple of its more
  546. interesting features.
  547.  
  548.   All direct mode commands are entered into a special screen which is
  549. completely indepentent from the program display. You can move this
  550. screen up or down using the arrow keys.
  551.  
  552.   At the top of the window, there's a list of 20 function key
  553. assignments. These represent a list of commands which have been
  554. previously assigned to the various function keys. They can be accessed
  555. by hitting the left or right Amiga-keys in combination with one of the
  556. various function keys.
  557.  
  558.   Whilst you're in direct mode, you can execute any Basic instructions
  559. you like. The only exceptions are things like loops or procedures. As
  560. with the editor, all commands should be entered into the computer by
  561. pressing the Return key. Here are some examples:
  562.  
  563.    Print 42
  564.    ANSWER=6. Print ANSWER*9
  565.    Curs Off
  566.    Close Workbench               (Saves around 40k but ABORTS multi-
  567.                                   tasking operations!)
  568.  
  569. It's important to recognize that no matter what you do in direct mode,
  570. there will be absolutely no effect on the current program listing. So
  571. you can mess about to your heart's content, with no risk of deleting
  572. something in your Basic program.
  573.  
  574.   It's now time to return to the Editor window. So wave a fond farewell
  575. to Direct mode, and enter the editor by pressing ESCape.
  576.  
  577. Loading a program
  578. We'll now discuss the various procedures for loading and saving your
  579. programs on the disc. As usual, these options can be executed either
  580. from the MENU window or using a range of simple two-key commands from
  581. the editor. The fastest way to load a program is to hold down either of
  582. Amiga keys, and press the letter L.
  583.  
  584.   You'll now be presented with the standard AMOS file selector window.
  585. Nowadays, file selectors have become a familiar part of most packages
  586. available on the Amiga. So if you've used one before, the AMOS system
  587. will hold no real surprises. However, since the file-selector is such
  588. an integral part of AMOS Basic, it's well worth explaining it in some
  589. detail.
  590.  
  591. The AMOS file selector
  592. Selecting a file from the disc couldn't be easier. Simply move the
  593. cursor over the required filename so that it's highlighted in reversed
  594. text. To load this file into memory, click twice on the left mouse
  595. button. Alternatively, you can enter the name straight from the
  596. keyboard, and just press Return.
  597.  
  598.   If you make a mistake, and wish to leave the selector without loading
  599. a file, move the mouse over the Quit button and select it with the left
  600. button. AMOS will abort your operation and display a "Not Done" message
  601. on the information line.
  602.  
  603.   As an example, place you COPY of the AMOS program disc into the
  604. internal drive and press AMIGA+L to load a file. If you've been
  605. following out tutorial, AMOS will give you the option of saving the
  606. existing program first. Unless you've made any interesting changes,
  607. press "N" to anter the file-selector. Otherwise, see "saving a program"
  608. for further instructions.
  609.  
  610.   When the file selector appears, look out for a file with the name
  611. "Hithere.AMOS". Once you've found it, load it. The following listing
  612. will be loaded to amos basic.
  613.  
  614.         Rem Hi there AMOS users
  615.         Cls 0 : Rem Clear the screen with colour zero
  616.         Do
  617.           Rem get some random numbers
  618.           X=Rnd(320):Y=Rnd(200):I=Rnd(15):P=Rnd(15)
  619.           Ink I,P : Rem add a little colour
  620.           Text X,Y,"Hi there!" : Rem graphic text
  621.         Loop
  622.  
  623. Move the text cursor over the text "Hi There!" and insert you own
  624. message. Now press F1 to run the program. The program display will
  625. rapidly fill up with dozens of copies of your text. Press CTRL+C to
  626. exit from this routine.
  627.  
  628. Saving a Basic program
  629. Return to the editor window, and type ALT+S to save your current
  630. program onto the disc. If you feel like a change, hold down the right
  631. mouse key and click on the "Save as" option from the SYSTEM menu with
  632. the left button. Either way you'll jump straight back to the AMOS file
  633. selector window.
  634.  
  635.   You should now enter the name of your new file straight from the
  636. keyboard. As you type, your letters will appear in a small window at
  637. the bottom of the selector. Like the editor, there's a cursor at the
  638. current typing position. This cursor can be moved around using all the
  639. normal editing keys Finally, press Return to save your prog to disc.
  640.  
  641. Scrolling through your files
  642. If your disc is reasonably full, the standard selection window won't be
  643. able to list the entire contents of your disc at once. You can page
  644. through the listing using the scroll bar to the left of the selection
  645. window.
  646.  
  647. Changing the current drive
  648. To the right of the file window, there's a list of drive names. The
  649. precise contents of the window will naturally depend on the devices
  650. you've connected to your Amiga. If you have several drives, you can
  651. switch between them by simply clicking on the appropriate name. The
  652. directory of this drive wlil now be entered into the selection window.
  653.  
  654. Changing the directory
  655. When you search through the directly listing, you'll discover several
  656. names with an asterix character "*" in front of them. These are not
  657. files at all. They are entire directories in their own right.
  658.  
  659.   You can enter one of these folders by selecting them with the left
  660. mouse button. You may then choose your files directly from this folder.
  661. Note that only the files with the current extension ".AMOS" will be
  662. displayed.
  663.  
  664.   Once you've opened a directory, you can set it as the default using
  665. the SETDIR button. The next time you enter the file selector or obtain
  666. a directory listing with DIR, your chosen folder will be entered
  667. automatically. Similarly, you can move back to the previous directory
  668. by clicking on the PARENT button.
  669.  
  670. Setting the search path
  671. Normally, AMOS will search for all filenames with the extension
  672. ".AMOS". If you want to laod a file with another extension such as
  673. .BAK, you can edit the search pattern directly. This can be acomplished
  674. in the following way.
  675.  
  676.   Move the text cursor to the PATH window by pressing with the up arrow
  677. from the keyboard. Now type your new path and hist Return. A full
  678. description of the required syntax can be found in the section on the
  679. DIR command.
  680.  
  681.   WARNING!: AMOS uses its own individual search patterns which are very
  682. different from the standard Amiga Dos System. If you're unsure, delete
  683. the entire line up to the current VOLUME or DRIVE name and hit Return.
  684. This will present you with a full list of ALL the files on the present
  685. disc.
  686.  
  687. Using the file selector
  688. Interestingly enough, it's also possible to call this file-selector
  689. directly from your own programs. For a demonstration, enter DIRECT mode
  690. and type the following line:
  691.  
  692.     Print Fsel$(*.*)
  693.  
  694. After you've chosen a file, the name you've selected will be printed
  695. straight onto screen! See FSEL$ for a detailed explanation of this
  696. command.
  697.  
  698. Editor tutorial
  699. We'll now have a brief look at some of the more advanced editing
  700. features available from the AMOS editor. We'll start by loading an
  701. example program from the disc. Just for a challenge, we've placed this
  702. in a separate MANUAL folder on the AMOS program disc.
  703.  
  704.   Insert your COPY of the program disc into your Amiga'
  705.  
  706. Scrolling through a listing
  707. Alongside the main editor window are two "scroll bars". These allow you
  708. to page through your listing with the mouse.
  709.  
  710.   Move the mouse pointer over the Vertical bar and hold down the left
  711. button. Now drag the bar down the screen. The editor window will
  712. scrolls moothly downwards through the listing. You can also scroll the
  713. program using the Arrow Icons at the top and bottom of this bar.
  714. Clicking on these icons moves the line exactly one place in the
  715. required direction.
  716.  
  717.   At the far bottom of the editor window, there's a horizonal scroll
  718. bar. This can be used to move the window left and right in exactly the
  719. same way.
  720.  
  721.   If you prefer to use the keyboard for your editing, you'll be pleased
  722. to discover that there are dozens of equivalent keyboard options as
  723. well. For example;
  724.  
  725.   CTRL+UP Arrow    shift the listing to the previous page.
  726.   CTRL+DOWN Arrow  moves the listing to the next page
  727.  
  728. All the keyboard options obey the same basic principles. So once you've
  729. familiarised yourself with one command, the rest are easy. A full list
  730. of these commands can be found towards the end of this chapter.
  731.  
  732.   Now we've looked at the program. It's time to actually change
  733. something. Search through the program listing until you find the line:
  734.  
  735.         ALERT[50,"Alert box","","Ok","Cancel",1,2]
  736.  
  737. This calls a Basic procedure which displays a working alert box on the
  738. screen. The format of this procedure is:
  739.  
  740.         ALERT[Y coord,Title 1$,Title 2$,Button 1$,Button 2$,Paper,Ink]
  741.  
  742. Let's change this alert to something a little more exciting. Move the
  743. cursor over the above statement, and edit the line with the cursor keys
  744. so that it look like so:
  745.  
  746.         ALERT[50,"Exterminate!","Securitate","Yep!","Yep!",1,3]
  747.  
  748. Execute the program by pressing F1 or selecting RUN from the main menu.
  749. You'll be given the unique option of stopping the lamest Amiga-group in
  750. the World in its tracks. Select a button with the mouse and make your
  751. choice!
  752.  
  753.   In practive, you can change the title and the buttons to literally
  754. anything you like. Feel free to use this routine in your own progs.
  755.  
  756.   Hopefully, the above example will have provided you with a real spur
  757. to use procedures in your own programs. In order to aid you in this
  758. task, we've built a powerful range of special editing features into the
  759. AMOS editor.
  760.  
  761. Label/procedure searches
  762. If your program is very long, it can be quite hard to find the starting
  763. points of your various procedure definitions. We've therefore included
  764. the ability to jump straight to the next procedure definition in your
  765. program, using just two keys (Alt+Arrow)
  766.  
  767.   For an example, place the cursor at the start of the listing and
  768. press Alt+down arrow. Your cursor will be immediately moved to the
  769. beginning of the first procedure definition in the current program
  770. (ALERT). You can repeat this process to jump to each procedure
  771. definition in turn.
  772.  
  773.   This system is not just limited to procedures of course. It also
  774. works equally well with Labels or line numbers. So even if you don't
  775. need procedures, you'll still find a use for this feature.
  776.  
  777. Folding a procedure definition
  778. If you build up your programs out of a list of frequently used
  779. procedures, your lisings an easily be cluttered with the definitions of
  780. all your various library routines.
  781.  
  782.   Fortunately, help is at hand. With a simple call to the Fold command,
  783. you can hide away any of your procedure definitions from your listings.
  784. These routines can be used in your program as normal, but their
  785. definitions will be replaced by a single Procedures statement. Example:
  786.  
  787.   Position the cursor anywhere in the definition of ALERT and click on
  788. the Fold/Unfold option from the menu window. Bing! The contents of your
  789. procedure will vanish into thin air! Despite this, you can run the
  790. program with no ill effects. The only change has been in the appearance
  791. of the listing in the editor window.
  792.  
  793.   Just select Fold/Unfold again, and your procedure will be expanded to
  794. it's fully glory.
  795.  
  796.   It's also possible to fold ALL the procedures in your program at
  797. once. This uses an option on the SEARCH menu called "Close All". To
  798. bring the Search menu onto the screen, click on the button with the
  799. same name, or press F5 from the keyboard. Now select the Close All
  800. button to remove the procedure definitions from the current program.
  801.  
  802.   The effect on EXAMPLE 3.1  is dramatic! The entire program now fits
  803. into just a single screen. So you can instantly see the procedures
  804. we've been using in the program. Each procedure definition can be
  805. edited individually by expanding it with the Fold/Unfold button. Or you
  806. can unfold the whole program with "Open All" from the Search menu.
  807.  
  808. Search/Replace
  809. The search/replace commands provided by the AMOS Basic editor are
  810. accessed through a special Search menu which can be called up either
  811. from the menu window or by pressing function key F4.
  812.  
  813. Finding an item
  814. We will continue our tutorial with a brief look at of some of the
  815. Search/replace instructions. Let's start with the FIND command.
  816.  
  817.   This can be executed either directly from the Search menu or using
  818. the keys CTRL+F. When you select this command, you'll be asked to enter
  819. the search string.
  820.  
  821.   For example, hit CTRL+F and type "Rem" at the prompt. AMOS ill now
  822. search for the next "Rem" statement in your program, starting from the
  823. current cursor position. If the search is succesful, then cursor will
  824. be replaced over the requested item.
  825.  
  826.   The search can now be repeated from this point with the "Find Next"
  827. option (CTRL+N).
  828.  
  829. Replace
  830. Supposing we wanted to change all the Rem statements in a program with
  831. the equivalent "'" characters. This could be accomplished with the
  832. "Replace" command.
  833.  
  834.   In order to use this option, it's necessary to define the replacement
  835. string. So the first time you call up replace, you will always be asked
  836. to enter this string from the keyboard.
  837.  
  838.   Press CTRL+R, type in ' (apostophe) at the prompt and hit the return
  839. key to enter it into the computer. You now set the search string with
  840. the "Find" option like so:
  841.  
  842.   * Press CTRL+F to select the FIND option.
  843.   * Type "Rem" into the information line.
  844.   * The cursor will then be moved straight to the next Rem statement in
  845.     your program listing.
  846.  
  847. To change this to the replacement string and jump to the next
  848. occurrence, select Replace (CTRL+R) once again. Alternatively, if the
  849. Rem is in the middle of the line, you'll need to skip it, because AMOS
  850. only allows you to substitute a quote for this command at the start of
  851. a line. You can avoid this problem and jump directly to the next item
  852. in your program using "Find Next".
  853.  
  854. Cut and paste
  855. The AMOS Block commands allow you to cut out parts of your programs and
  856. save them in memory for future use. Once you've created a block, you
  857. can copy it anywhere you like in the current listing.
  858.  
  859.   Here's an example of this feature in action. Let's take the previous
  860. ALERT program, and cut out a single procedure. Place the mouse pointer
  861. over the first line of the INVERT procedure, and depress the right
  862. mouse button. We can now enter this procedure into a block using the
  863. mouse. As you move the mouse, the selected area will be highlighted in
  864. reverse.
  865.  
  866.   We can now grab this area into memory using "Cut". When you press
  867. CTRL+C from the keyboard, the procedure will be removed from the
  868. listing and stored into memory. It's now possible to paste this block
  869. anywhere you like in your program. For the purposes of our example,
  870. move the text cursor down to the bottom of the listing, and call the
  871. Paste optin with CTRL+P. The INVERT procedure wlil now be copied to the
  872. current cursor position.
  873.  
  874. Multiple programs and accessories
  875.  
  876. Multiple programs
  877. Although AMOS only allows you to edit a single program at a time,
  878. there's no limit to the number of programs which can be installed into
  879. memory, other than the amount of available storage space. Once you've
  880. installed a program in this way, you can execute it straight from
  881. Editor window with the "Run Other" option.
  882.  
  883.   Supposing, for instance, you encounter a problem in one of your
  884. programs. AMOS will let you effortlessly swap your existing program
  885. into memory so that you can freely experiment with the various
  886. possibilities until you find a solution. After you've finished, you can
  887. now grab your new routine into memory with the cut option, and flick
  888. back into your original program by pressing just two keys! The new
  889. routine can the be pasted into position, and you can continue with your
  890. program as before. The ability to stop everything and try out your
  891. ideas immediately, is incredibly valuable in practice.
  892.  
  893.   Another possibility is to permanently keep all the most commondly
  894. neede utilities such as the sprite definer or the map editor in the
  895. memory. You can now access these utilities instantaneously, whenever
  896. you need them.
  897.  
  898.   In fact, AMOS includes a special ACCESSORY system which makes this
  899. even easier. The utility programs can be given total access to all the
  900. memory banks in your main programs. So the sprite definer can grab the
  901. images straight from your current program, and modify them directly.
  902. This tehcnuque speeds up the overall development process by an amazing
  903. degree!
  904.  
  905.   Let's have a quick demonstration of these facilities. Enter the
  906. following small prog into the editor:
  907.  
  908.         Print "This is program One"
  909.         Boom
  910.  
  911. We can now push this program into memory using the push command. This
  912. is called up by pressing AMIGA+P. You'll then be asked to enter the
  913. name of your program from the information line. Type in a name like
  914. "Program1" at this point. The edit screen will be cleared completely.
  915. The new window is totally separated from your original program. As a
  916. demonstration, enter a second routine like so:
  917.  
  918.         Print "This is program Two"
  919.         Shoot
  920.  
  921. This program can now be executed from the editor window using RUN (F1).
  922. but when your return you can immediately jump to the old one with the
  923. "Flick" option. Try pressing AMIGA+F. As before, you'll be asked to
  924. enter a name for your program. Use a name like "program2" for this
  925. purpose. The editor will now jump straight to your original program as
  926. if by magic. It's possible to repeat this process to jump back and
  927. forth between the two programs. Each program is entirely independent
  928. and can have it's list of own banks and program screens.
  929.  
  930.   So far, we've only discussed how you can use two programs at a time.
  931. However, you can actually have as many program in memory as you like.
  932. These programs can be selected individually using the "Run Other" and
  933. "Edit Other" options from the Menu window. When you call these
  934. commands, a special "program" selector will be displayed on the screen.
  935.  
  936.   The program selector is almost identical to the familiar AMOS file
  937. selector. The only difference is that it allows you to choose a program
  938. from memory rather than from the disc. You can select a program by
  939. simply highlighting it with the mouse cursor and clicking once on the
  940. left button.
  941.  
  942. Accessories
  943. In order to distinguish accessories from normal Basic programs, they're
  944. assigned a ".ACC" extension instead of the more usual ".AMOS".
  945. Accessories can be loaded into memory like any normal program using the
  946. "Load Other" command.
  947.  
  948.   Load Other presents you with a normal fileselector which can be used
  949. to load an accessory program from the disc. After the accessory has
  950. been installed into memory you will be returned straight back to your
  951. current program. You can now run this accessory at any time using the
  952. Run Other option from the menu window. Simply move the mouse pointer
  953. over your required accessory and press the left button.
  954.  
  955.   Alternatively, you can load all the accessories from the current disc
  956. using the Accnes/Load feature. This option can be found on the System
  957. menu which is displayed when you hold down the right mouse button.
  958. Accnew/Load erases all existing accessories and loads a new set from
  959. the current disc.
  960.  
  961.   For a demonstration, place the AMOS Program disc into your drive, and
  962. click on the Accnew/Load button from the System menu.
  963.  
  964.  The HELP accessory will be quickly loaded into memory. HELP is a
  965. special accessory because it can be called up directly by pressing the
  966. HLEP key. We've packed this program with all the information you'll
  967. need about the accessor yprograms supplied with AMOS Basic. All you
  968. need to do, is just follow the prompts which will be displayed on the
  969. screen.
  970.  
  971. Direct mode
  972. The Direct mode window can be entered from the editor by pressing the
  973. ESCape key at any time. As a default, the window is displayed in the
  974. lower half of the screen, with the program screen in the background.
  975.  
  976.   If you run a program that changes the screen format, displays
  977. windows, animates sprites etc, then all this screen data will remain
  978. intact. So you can move the DIRECT window around or flip back to the
  979. editor to make program changes without destroying the current program
  980. screen. This DIRECT mode window is totally independent and is displayed
  981. on its own front level screen.
  982.  
  983.   Whilst you're within direct mode you can type any line of AMOS Basic
  984. you wish. The only commands you cannot use are loops and branch
  985. instructions. You only have access to normal variables (as distinct
  986. from the loca bariables defined in a procedure).
  987.  
  988. Direct mode editor keys
  989.  
  990.         ESCape          Jump to the editor window
  991.         Return          Executes the current line of commands
  992.         DELete          Delete character under cursor/
  993.         Backspage       Delete character to the left of the cursor
  994.         Left Arrow      Move cursor left
  995.         Right Arrow     Move cursor right
  996.         Shift+Left      Skip a word to the left
  997.         Shift+Right     Skip a word to the right
  998.         Shift DELete    Deletes entire line.
  999.         Shift BACK      Ditto
  1000.         Help            Displays the function key definitions to the
  1001.                          direct window.
  1002.         F1  to F10      These keys remember the last 10 lines you've
  1003.                         entered from the direct mode. F1 displays the
  1004. latest one entered, F2 the second to last, etc. The memory area used by
  1005. this system is always cleared when you return to the editor window or
  1006. run one of your programs.
  1007.  
  1008. The menu window
  1009. There's a detailed explanation of all the options which are available
  1010. from the main menu window.
  1011.  
  1012. Default menu
  1013. This gives you various commands that allow you to operate the editor,
  1014. plus give you access to the block and search menus.
  1015.  
  1016. RUN         (F1) Runs the current program in memory
  1017. TEST        (F2) Cheks the program syntax
  1018. INDENT      (F3) Takes the current program and indents the listing.
  1019. BLOCKS MENU (F4) Displays the Blocks menu.
  1020. SEARCH MENU (F5) Displays the Search menu
  1021. RUN OTHER   (F6) Runs a program or accessory in memory
  1022. EDIT OTHER  (F7) Edits a program which has previously installed into
  1023.                  memory using the "Load Other" or "Accnew/Load".
  1024. OVERWRITE   (F8) Toggles between insert and overwrite -editing modes.
  1025. FOLD/UNFOLD (F9) Takes a procedure definition and folds it away inside
  1026.                  your program listing.
  1027.  
  1028.   Normally, it's possible to re-open a folded procedure by repeating
  1029. the process. Place the cursor over a folded procedure and click on
  1030. FOLD/UNFOLD. If you feel the need for extra security you can also call
  1031. up a special LOCK accessory from the AMOS Program disc. This will ask
  1032. for a code word, and will lock your procedures so that they can't be
  1033. subsequently examined from AMOS Basic. Simply fold your required
  1034. proceduers and load FOLD.ACC using the LOAD OTHERS command. Full
  1035. instructions are included with the utility.
  1036.  
  1037.   The real beauty of this system is that it allows you to create whole
  1038. libraries of your routines on the disc. These can be loaded into memory
  1039. as a separate program (See LOAD OTHER). You can now cut out the routine
  1040. you need and copy them directly into your main program. So once you've
  1041. written a routine, ou can place it into a procedure and reuse it again
  1042. and again.
  1043.  
  1044.   If you're intending to use this sytem, there are several points to
  1045. concider.
  1046.  
  1047.   * Whenever you fold or unfold a procedure a syntax check is made of
  1048.     the entire program. If an error occurs the operatoni will not be
  1049.     performed. So it's vital that you keep back-up copies of all your
  1050.     procedures in Unfo
  1051.  
  1052. The system menu                                                             24
  1053. LOAD        (SFT+F1 / AMIGA+L) Loads an AMOS Basic Program
  1054. SAVE        (SFT+F2 / AMIGA+S) Saves the current Basic Program
  1055. SAVE AS     (SFT+F3 /SFT+AM+S) Saves the prog with another name
  1056. MERGE       (SHIFT+F4)         Enters the chosen prog at the current
  1057.                          csrs position without erasing the current
  1058.                          program.
  1059. MERGE ASCII (SHIFT+F5)   Merges an Ascii version of an AMOS Basic           25
  1060.                          program with the existing program in memory
  1061. AC.NEW/LOAD (SHIFT+F6)   Enters a new accessory set from the disc
  1062. LOAD OTHERS (SHIFT+F7)   Loads a single accessory from the disc
  1063. NEW OTHERS  (SHIFT+F8)   Erases accessorie(s) from memory
  1064. NEW         (SHIFT+F9)   Erases the current program from memory
  1065. QUIT        (SHIFT+F10)  Exits AMOS and returns control to the CLI
  1066.  
  1067. The blocks menu
  1068. BLOCK START (CTRL + B/F1) Sets the starting point for the current block
  1069. BLOCK END   (CTRL + E/F6) Defines the end of a block
  1070. BLOCK CUT   (CTRL + C/F2) Removes the selected block into memory            26
  1071. BLOCK PASTE (CTRL + P/F7) Pastes the block to the current csrs position
  1072. BLOCK MOVE  (CTRL + M/F3) Move the block to the current cursor position
  1073.                           erasing the original version completely
  1074. BLOCK STORE (CTRL + S/F8) Copies the block into memory.
  1075. BLOCK HIDE  (CTRL + H/F4) Deselects the block you've highlighted
  1076. BLOCK SAVE  (CTRL + F9 )  Saves the current block on the disc as an
  1077.                           AMOS program
  1078. SAVE ASCII  (CTRL + F5 )  Stores your selected block on the disc as
  1079.                           a normal text file.
  1080. BLOCK PRINT (CTRL + F10)  Outputs the selected block to the printer
  1081.  
  1082. The search menu
  1083. FIND        (ALT + F1)    Enters a string of up to 32 chars and
  1084.                           searches through your text until a match is
  1085.                           found.
  1086. FIND NEXT   (ALT + F2)    Searches for the next match you specified
  1087. FIND TOP    (ALT + F3)    Searches from the top of program the string
  1088.                           rather than starting from the crsr position
  1089. REPLACE     (ALT + F4)    Activates REPLACE mode. The effect of this
  1090.                           command varies depending when it's used:
  1091.    * Before a FIND
  1092.                    You'll now be asked to enter the replacement
  1093.                    string from the keyboard
  1094.    * After a FIND
  1095.                   If the search operation was succesful, the text and
  1096.                   the current cursor position will be swapped with the
  1097.                   replacement string. REPLACE will now jump to the next
  1098.                   occurrence of the search string.
  1099.  
  1100. REPLACE ALL (ALT + F5)    Replaces ALL copies of a word in your prog.
  1101. LOW <> UP   (ALT + F6)    Changes the case sensitivity used in search
  1102.                           commands
  1103. OPEN ALL    (ALT + F7)    Opens all closed procedures in your program
  1104. CLOSE ALL   (ALT + F8)    CLoses all procedures in your program
  1105. SET TEXT B  (ALT + F9)    SET TEXT BUFFER. Changes the # of chars
  1106.                           available to hold your listings.
  1107. SET TAB     (ALT + F10)   Sets the number of chars which the crsr will
  1108.                           be moved when the user presses the TAB key.
  1109.  
  1110. Keyboard macros
  1111.                    =KEY$= (define a keyboard macro)
  1112.  
  1113. KEY$(n)=command$
  1114. command$)=KEY$(n)
  1115.  
  1116. KEY$ assigns the contents of command$ to function key number n. (1-20)
  1117. Keys from one to ten are accessed by pressing the function key in
  1118. conjuction with the left Amiga button. Similarly, numbers from eleven
  1119. onwards are called with a right Amiga Fn combination.
  1120.  
  1121.   Command$ can be any string of text you wish, up to maximum of 20
  1122. characters. There are two special characters which are directly
  1123. interpreted by this function:
  1124.  
  1125. ' (Alt+Quote)     Generates a Return code
  1126. ' (single Quote)  Encloses a comment. This is only displayed in your
  1127.                   key lists. It's totally ignored by the macro routine.
  1128.                   Examples:
  1129.  
  1130.    ? Key$(1)
  1131.    Key$(2)="Default"
  1132.    Alt+F2
  1133.  
  1134.    Key$(3)="'Comment print"
  1135.  
  1136. In practice, this macro system can prove incredibly useful. Not only
  1137. can you speed up the process of entering you Basic programs, but you
  1138. can also define a list of standard inputs for your Basic programs.
  1139. These would be extremely effective in an adventure game, as can be seen
  1140. from the program EXAMPLE 3.2 in the MANUAL folder.
  1141.  
  1142.   If you wish to generate a keypress which has no ASCII equivalent such
  1143. as up arrow, you can optionally include a scancode in these macros.
  1144. This is achieved using the SCAN$ function.
  1145.  
  1146.              =SCAN$ (return a scan code for use with KEY$)
  1147.  
  1148. x$=Scan$(n,[,m])
  1149.  
  1150. n is the scancode of a key to be used in one of your macro definitions.
  1151. m is an optional mask which sets the special keys such as CTRL or Alt,
  1152. in the following format:
  1153.  
  1154.         Bit  Key Tested     Notes
  1155.         0    Left SHIFT
  1156.         1    Right SHIFT
  1157.         2    Caps Lock      Either ON or OFF
  1158.         3    CTRL
  1159.         4    Left ALT
  1160.         5    RIght ALT
  1161.         6    Left AMIGA     Commodore key on some keyboards
  1162.         7    Right AMIGA
  1163.  
  1164. If a bit is set to a one, then the associated button is depressed in
  1165. your macro. Examples:
  1166.  
  1167.         KEY$(4)="Wheee!"+Scan$($4C)
  1168.         KEY$(5)="Page Up!"+Scan$($4C,%00010000)
  1169.  
  1170. Conserving memory
  1171.                 CLOSE WORKBENCH (closes the workbench)
  1172.  
  1173. CLOSE WORKBENCH
  1174. Closes the workbench screen saving around 40K of memory for your
  1175. programs! Example:
  1176.  
  1177.         Print Chip Free,Fast Free
  1178.         Close Workbench
  1179.         Print Chip Free,Fast Free
  1180.  
  1181. CLOSE WORKBENCH can be executed either from direct mode, or inside on
  1182. of your Basic programs. A Typical program line might be:
  1183.  
  1184.         If Fast Free=0 Then Close Workbench
  1185.  
  1186. This would check for a memory expansion and close the Workbench if
  1187. extra memory was not available.
  1188.  
  1189.                   CLOSE EDITOR (close editor window)
  1190.  
  1191. CLOSE EDITOR
  1192. Closes the Editor window while your program is running, saving you more
  1193. than 28K of memory. Furthermore, there's absolutely NO effect on your
  1194. program listings!
  1195.  
  1196.   If there's not enough memory to reopen the window after your program
  1197. has finished, AMOS will simply erase your current display and revert
  1198. back to the standard DEFAULT screen. You'll now be able to effortlessly
  1199. jump back to the Editor with the ESCape key as normal. What a terrific
  1200. little instruction!
  1201.  
  1202. Inside accessories
  1203. We'll now explore the general techniques required to write your own
  1204. accessory programs. These are really just specialised form of the
  1205. multiple programs we discussed a little earlier. As you would expect,
  1206. they can incorporate all the standard Basic instructions.
  1207.  
  1208.   Accessories are displayed directly over your current program screen
  1209. and the music, sprite, or bob animations are automatically removed from
  1210. the screen.
  1211.  
  1212.   Your accessory should therefore check the dimensions and type of this
  1213. screen using the SCREEN HEIGHT, SCREEN WIDTH and SCREEN COLOUR commands
  1214. during its initialisation phase. If the current screen isn't
  1215. acceptable, you may be forced to open a new screen for the accessory
  1216. window or to erase the existing screens altogether with a DEFAULT
  1217. instruction.
  1218.  
  1219.   Any memory banks used by your accessory are totally independent of
  1220. the main program. If it's necessary to change the banks from the
  1221. current program, you can call a special BGRAB command.
  1222.  
  1223.           BGRAB (grabs the banks used by the current program)
  1224.  
  1225. BGRAB b
  1226. BGRAB "borrows" a bank from the current program and copies it into the
  1227. same bank in your accessory. If this accessory bank already exists, it
  1228. will be totally erased. When the accessory returns to the editor, the
  1229. bank you have grabbed will be automatically returned to your main
  1230. program along with any changes. b is the number of a bank from 1 to 16.
  1231.  
  1232.   Note that this instruction can only be used inside an accessory. If
  1233. you try to include it in normal program, you'll get an appropriate
  1234. error message.
  1235.  
  1236.                    PRUN (run a program from memory)
  1237.  
  1238. PRUN "name"
  1239. Executes a Basic program which has been previously installed in the
  1240. Amiga's memory. This command can be used either from the direct mode,
  1241. or within a program! In effect, PRUN is very similar to a standard
  1242. procedure call, except that any bobs, sprites or music will be totally
  1243. suspended.
  1244.  
  1245.   Note that it's impossible to call the same program twice in the same
  1246. session. After you've called it once, any further attempts will ignored
  1247. completely.
  1248.  
  1249.         =PRG FIRST$ (read the first program loaded into memory)
  1250.  
  1251. p$=PRG FIRST$
  1252. This returns the name of the first Basic program installed in the
  1253. Amiga's memory. It's used in conjunction with the PRG NEXT$ command to
  1254. create a full list of all the currently available programs.
  1255.  
  1256.        =PRG NEXT$ (returns the next program installed in memory)
  1257.  
  1258. p$=PRG NEXT$
  1259. PRG NETX$ is used after a PRG FIRST$ command to page through all the
  1260. programs installed in Amiga's memory. When the end of the list is
  1261. reached, a value of "" will be returned by this function. Example:
  1262.  
  1263.         N$=Prg First$
  1264.         While N$<>""
  1265.           Print "Program" ";N$
  1266.           N$=Prg Next$
  1267.         Wend
  1268.  
  1269.                     =PSEL$ (call program selector)
  1270.  
  1271. n$=PSEL$("filter"[default$,title1$,title2$]
  1272. PSEL$ calls up a program selector which is indential to the one used by
  1273. the Run Other, Edit Other, Load Others, and New Others commands. This
  1274. can be used to select a program in the usual way. The name of this
  1275. program will be returned in n$. If the user has aborted from the
  1276. selector, n$ will be set to an emptry string "".
  1277.  
  1278.   "filter" sets the type of programs which will be listed by
  1279. instruction. Typical values are:
  1280.  
  1281.         "*.ACC"    List all the accessories in memory
  1282.         "*.AMOS"   Only displays the AMOS programs which have been
  1283.                    installed.
  1284.         "*.*"      List all programs currently in memory.
  1285.  
  1286. For further details of the system see the DIR command.
  1287.  
  1288.          default$        holds the name of a program which will be
  1289.                          used as a default.
  1290.          title1$,title$  Contains up to two lines of text which will be
  1291.                          displayed at the top of the selector.
  1292.  
  1293. See EXAMPLE 3.4  in the MANUAL folder for a demonstration.
  1294.  
  1295. The HELP accessory
  1296. Whenever the HELP key is pressed from the Editor window, AMOS
  1297. automatically executes an accessory with the name HELP.ACC if it's
  1298. available. Unlike normal accessories, this is displayed directly over
  1299. the editor window. Special access is provided to the current word you
  1300. are editing. The address of this word is placed in an address register
  1301. and can be read using the AREG function.
  1302.  
  1303. The editor control keys
  1304. Finally, here's a full list of the various control keys and effects:
  1305.  
  1306. Special keys
  1307. ESC             Takes you to direct mode
  1308.  
  1309. Editing keys
  1310. Backspace       Deletes the character to the immediate left of crsr.
  1311. DELete          Deletes the character underneath the cursor
  1312. RETURN          Tokenises the current line. If you move onto a line
  1313.                 and press RETURN it will split the line
  1314. SFT+BCKS/CTRL+Y Deletes current line
  1315. CTRL+U          Undo. Return the last line when in overwrite mode.
  1316. CTRL+Q          Erase the rest of chars in the line from crsr position
  1317. CTRL+I          Insert a line at the current position
  1318.  
  1319. The cursor arrows
  1320. Left,Right       Moves cursor one space to the left/right
  1321. Up,Down          Moves cursor one line up/down
  1322. SHIFT+Left,Right Positions the cursor over the previous/next word
  1323. SHIFT+up,down    Move cursor to the top/bottom line of the current page
  1324. CTRL+up,down     Displays the previous/next page of program
  1325. SHIFT+CTRL+up,dn Move to start/end of text
  1326. AMIGA+up         Scrolls text up without moving the cursor
  1327. AMIGA+down       Scrolls text down under the cursor
  1328. AMIGA+left,right Scroll program to the left/right on the current line
  1329.  
  1330. Program control
  1331. AMIGA+S         Saves your program under a new name
  1332. AMIGA+SHIFT+S     "           "          current name
  1333. AMIGA+L         Loads a program
  1334. AMIGA+P         Pushes the current program into a mem and creates a new
  1335.                 program.
  1336. AMIGA+F         Flips between two progs stored in memory
  1337. AMIGA+T         Displays next program in memory.
  1338.  
  1339. Cut and Paste
  1340. CTRL+B          Set the beginning of a block
  1341. CTRL+E          Set end point of a block
  1342. CTRL+C          Cut block
  1343. CTRL+M          Block move
  1344. CTRL+S          Saves the block in memory without erasing it first
  1345. CTRL+P          Paste block at current cursor position
  1346. CTRL+H          Hide block.
  1347.  
  1348. Marks
  1349. CTRL+SHIFT+(0-9)  Defines a marker at the present cursor position.
  1350. CTRL+(0-9)        Jumps to a mark
  1351.  
  1352. Search/Replace
  1353. ALT+UP Arrow    Searches backwards through your program to the next
  1354.                 line which contains a label or procedure definition.
  1355. ALT+DOWN Arrow  Searches down through yur program to find the next
  1356.                 label or procedure definition
  1357. CTRL+F          Find
  1358. CRTL+N          Find Next
  1359. CTRL+R          Replace
  1360.  
  1361. Tabs
  1362. TAB             Move the entire line at the cursor to the next TAB pos.
  1363. SHIFT+TAB       Move the line to the previous Tab position
  1364. CTRL+TAB        Sets the TAB value
  1365.  
  1366. 4: BASIC PRINCIPLES
  1367. This chapter discusses the ground rules used to construct AMOS Basic
  1368. programs and shows you how to improve your programming style with the
  1369. help of AMOS Basic procedures.
  1370.  
  1371. Variables
  1372. Variables are the names used to refer to storage locations inside a
  1373. computer. These locations hold the results of the calculations
  1374. performed in one of your programs.
  1375.  
  1376.   The choise of variable names is entirely up to you, and can include
  1377. any string of letters or numbers. There are only a couple of
  1378. restrictions. All variable names MUST begin with a letter and cannot
  1379. commence with an existing AMOS Basic instruction. However it is
  1380. perfectly permissible to use these keywords inside a name. So variables
  1381. such as VPRINT or SCORE are fine.
  1382.  
  1383.   Variable names must be continuous, and may not contain embedded
  1384. spaces. If a space is required, it's a possible to substitute a "_"
  1385. character instead.
  1386.  
  1387. Here are some examples of illegal names. The illegal bits are
  1388. underlined to make things clearer.
  1389.  
  1390.         WHILE$, 5C, MODERN#, TOAD
  1391.         -----   -   ---      --
  1392.  
  1393. Types of variables
  1394. AMOS Basic allows you to use three different types of variables in your
  1395. programs.
  1396.  
  1397. Integers
  1398. Unlike most other Basics, AMOS initially assumes that all variables are
  1399. integers. Integers are whole numbers such as 1,3 or 8, and are ideal
  1400. for holding the values used in your games.
  1401.  
  1402.   Since integer arithmetic is much faster than the normal floating
  1403. point operations, using integers in you programs can lead to dramatic
  1404. improvements in speed. Each integer is stored in four bytes and can
  1405. range from -147'483'648 to +147'483'648. Examples of integer variables:
  1406.  
  1407.         A, NUMBER, SCORE, LIVES
  1408.  
  1409. Real numbers
  1410. In AMOS Basic these variables are always followed by a hash (#)
  1411. character. Real numbers can hold fractional values such as 3.1 or 1.5.
  1412. They correspond directly to the standard variables used in most other
  1413. versions of Basic. Each real variable is stored in four bytes and can
  1414. range between 1E-14 and 1E-15. All values are accurate to a precision
  1415. of seven decimal digits. Examples:
  1416.  
  1417.         P#, NUMBER#, TEST#
  1418.  
  1419. String variables
  1420. String variables contain text rather than numbers. They are
  1421. distinguished from normal variables by the $ character at the end. The
  1422. length of your text can be anything from 0 to 65'500 characters.
  1423. Examples of string variables:
  1424.  
  1425.         NAME$, PATH$, ALIEN$
  1426.  
  1427. Giving a variable a value
  1428. Assigning a value to a variable is easy. Simply choose an appropriate
  1429. name and assign it to value using the "=" statement.
  1430.  
  1431.         VAR=10
  1432.  
  1433. This loads the variable VAR with a value of 10.
  1434.  
  1435.         A$="Hello"
  1436.  
  1437. This assigns string "Hello" to a variable A$.
  1438.  
  1439. Arrays
  1440. Any list of variables can be combined together in the form of an array.
  1441. Arrays are created using the DIM instruction.
  1442.  
  1443.                        DIM (dimension an array)
  1444.  
  1445. DIM var(x,y,z,...)
  1446.  
  1447. DIM defines a table of variables in your AMOS Basic program. These
  1448. tables may have as manu dimensions as you want, but each dimension is
  1449. limited to a maximum of 65'000 elements. Example:
  1450.  
  1451.         Dim A$(10),B(10,10),C#(10,10,10)
  1452.  
  1453. In order to access an element in the array you simply type the array
  1454. name followed by the index numbers. These numbers are separated by
  1455. commas and are enclosed between round brackets (). Note that the
  1456. element numbers of these arrays always start from zero. Example:
  1457.  
  1458.         Dim ARRAY(10)
  1459.         ARRAY(0)=10:ARRAY(1)=15
  1460.         Print ARRAY(1);ARRAY(0)
  1461. ( result: 15 10 )
  1462.  
  1463. Constants
  1464. Constants are simply numbers or strings which are assigned to a
  1465. variable or used in one of your calculations. They are called constants
  1466. because they don't charge during the course of your program. The
  1467. following values are all constants:
  1468.  
  1469.         1, 42, 3.141, "Hello"
  1470.  
  1471. As a default, all numeric constants are treated as integers. Any
  1472. floating point assignments to an integer variable are automatically
  1473. converted to a whole number before use. Examples:
  1474.  
  1475.         A=3.141:Print A
  1476. ( result: 3)
  1477.         Print 19/2
  1478. ( result: 9)
  1479.  
  1480. Constants can also be input using binary or hexadecimal notation.
  1481. Binary numbers are signified by preceding them with a % character, and
  1482. hexadecimal numbers are denoted by a $ sign. Here's number 255:
  1483.  
  1484.         Decimal:        255
  1485.         Hexadecimal:    $FF
  1486.         Binary:         $11111111
  1487.  
  1488. Note that any numbers you type in AMOS Basic are automatically
  1489. converted to special internal format. When you list your program these
  1490. numbers are expanded back into their original form. Since AMOS Basic
  1491. prints all numbers in a standard way, this will often lead to minor
  1492. discrepancies between the number you entered and the number which is
  1493. displayed in your listing. However the value of the number will remain
  1494. exactly the same. Floating point constants are distinguished from
  1495. integers by a decimal point. If this point is not used, the number will
  1496. always be assumed to be an integer, even if this number occurs inside a
  1497. floating point expression. Take the following example:
  1498.  
  1499.         For X=1 To 10000
  1500.           A#=A#+2
  1501.         Next X
  1502.  
  1503. Every time the expression in this program is evaluated, the "2" will be
  1504. laboriously converted into a real number. So this routine will be
  1505. inherently slower than the equivalent program below:
  1506.  
  1507.         For X=1 To 10000
  1508.           A#=A#+2.0
  1509.         Next X
  1510.  
  1511. This program executes over 25% faster than the original one because the
  1512. constant is now stored directly in floating point format. You should
  1513. always remember to place a decimal oint after a floating point constant
  1514. even if it is a whole number. Incidentally, if you mix floating point
  1515. numbers and integers, the result will always be returned as a real
  1516. number. Example:
  1517.  
  1518.         Print 19.0/2
  1519. ( result: 9.5 )
  1520.         Print 3.141+10
  1521. ( result: 13.141 )
  1522.  
  1523. Arithmetic operations
  1524. The following arithmetic operations can be used in a numeric
  1525. expression:
  1526.  
  1527.         ^       power
  1528.         / *     divide and multiply
  1529.         MOD     modulo operator (remainder of a division)
  1530.         + -     plus and minus
  1531.         AND     logical AND
  1532.         OR      logical OR
  1533.         NOT     logical NOT
  1534.  
  1535. We've listed these operations in descending order of their priority.
  1536. This priority refers to the sequence in which the various sections of
  1537. an arithmetic expressions are evaluated. Operations with the highest
  1538. priority are always calculated first.
  1539.  
  1540.                   INC (add 1 to an integer variable)
  1541.  
  1542. INC var
  1543.  
  1544. INC adds 1 to an integer variable using a single 68000 instruction. It
  1545. is logically equivalent to the expression var=var+1, but faster.
  1546. Example:
  1547.  
  1548.         A=10:Inc A:Print A
  1549. ( result: 11 )
  1550.  
  1551.                DEC (subtract 1 from an integer variable)
  1552.  
  1553. DEC var
  1554.  
  1555. This instruction subtracts 1 from the integer variable var. Example:
  1556.  
  1557.         A=2:Dec A:Print A
  1558. ( result: 1 )
  1559.  
  1560.                       ADD (fast integer addition)
  1561.  
  1562. ADD v,exp [,base TO top]
  1563.  
  1564. The standard from of this instruction immediately adds the result of
  1565. the expression exp to the integer variable v. It's equivalent to the
  1566. line: V=V+EXP
  1567.  
  1568.   The only significant difference between the two statements is that
  1569. ADD performs around 40% faster. Note that the variable v must be an
  1570. integer. Example:
  1571.  
  1572.         Timer=0
  1573.         For X=1 To 1000
  1574.           Add T,X
  1575.         Next X
  1576.         Print T,Timer
  1577. ( result: 500500 7 )
  1578.  
  1579. The second version of ADD is a little more complicated. It is
  1580. effectively identical to the following code (but faster):
  1581.  
  1582.         V=V+A
  1583.         If V<Base Then V=Top
  1584.         If V>Base Then V=Base
  1585.  
  1586. Example:
  1587.         Dim A(10)
  1588.         For X=0 To 10:A(X)=X:Next X
  1589.         V=0
  1590.         Repeat
  1591.           Add V,1,1 To 10
  1592.           Print A(V)
  1593.         Until V=100:rem This is an infinite loop as V is always less
  1594.                         than 10!
  1595.  
  1596. As you can see, ADD is ideal for handing circular or repetitive loops
  1597. in your games.
  1598.  
  1599. String operations
  1600. Like most versions of Basic, AMOS will happily allow you to add two
  1601. strings together.
  1602.  
  1603.         A$="AMOS"+" Basic"
  1604.         Print A$
  1605. ( result: AMOS Basic )
  1606.  
  1607. But AMOS also lets you perform subtraction as well. This operation
  1608. works by removing all occurrences of the second string from the first.
  1609.  
  1610.         Print "AMOS BASIC"-"AMO"
  1611. ( result: S BASIC )
  1612.  
  1613. Comparisons between two strings are performed on a character by
  1614. character basis using the Ascii values of the appropriate letters:
  1615.  
  1616.         "AA"<"BB"
  1617.         "Filename"="Filename"
  1618.         "X&">"X#"
  1619.         "HELLO"<"hello"
  1620.  
  1621. Parameters
  1622. The values you enter into an AMOS Basic instruction are known as
  1623. parameters. i.e
  1624.  
  1625.         Inc N
  1626.         Add A,10
  1627.         Ink 1,2,3
  1628.  
  1629. The parameters in the above instructions are N,A,10,1,2 and 3
  1630. respectively. Occasionally, some of the parameters of a command can be
  1631. ommitted from an instruction. In this case, any unused values will
  1632. automatically be assigned a number by default. Example:
  1633.  
  1634.         Ink 5,,
  1635.  
  1636. This changes the ink colour without affecting either the paper or
  1637. outline colours.
  1638.  
  1639. Line numbers and labels
  1640.  
  1641. Labels
  1642. Labels are just a convenient way of marking a point in your AMOS Basic
  1643. programs. They consist of a string of characters formed using the same
  1644. rules as AMOS variables. Labels should always be placed at the start of
  1645. the line, and must be followed immediately by a ":" character. There
  1646. should be no spaces between the label and the colon. Example:
  1647.  
  1648.         TESTLABEL:
  1649.         Print "Hi There!"
  1650.         Goto TESTLABEL
  1651.  
  1652. This program can be aborted by pressing CTRL+C...
  1653.  
  1654. Procedures
  1655. Procedures allow you to concentrate your efforts on just one problem at
  1656. a time without the distractions provided by the rest of your program.
  1657. Once you've written your procedures you can then quickly combine them
  1658. in your finished program. AMOS procedures are totally independent
  1659. program modules which can have their own program lines, variables, and
  1660. even data statements.
  1661.  
  1662.               PROCEDURE (create an AMOS Basic procedure)
  1663.  
  1664. Procedure NAME[parameter list]
  1665. :     :
  1666. End Proc[Expression]
  1667.  
  1668. This defines an AMOS Basic procedure called NAME. NAME is a string of
  1669. characters which identify the procedure. It is constructed in exactly
  1670. the same way as a normal Basic variable. Note that it's perfectly
  1671. acceptable t ouse identical names for procedures, variables and labels.
  1672. AMOS will automatically work out which object you are referring to from
  1673. the context of the line.
  1674.  
  1675.   Procedures are similar to the GOSUB commands found in earlier
  1676. versions of Basic. Here's an example of a simple AMOS procedure:
  1677.  
  1678.         Procedure ANSWER
  1679.           Print "Forty-Two!"
  1680.         End Proc
  1681.  
  1682. See how the procedure has been terminated with an END PROC statement.
  1683. You should also note that the Procedure and the End Proc directives are
  1684. both placed on their own separate lines. This is compulsory.
  1685.  
  1686.   If you type the previous procedure into AMOS Basic as it stands, and
  1687. attempt to run it, nothing will happen. That's because you haven't
  1688. actually called the new procedure from your Basic Program. This can be
  1689. achieved by simply entering its name at the appropriate point in the
  1690. program. As an example, enter the following line at the start of the
  1691. program and run it to see the result of the procedure.
  1692.  
  1693.         ANSWER
  1694. IMPORTANT! When you are using several procedures on the same line, it's
  1695. advisable to add an extra space at the end of each statement. This will
  1696. avoid the risk of the procedure being confused with a label. For
  1697. example:
  1698.  
  1699.         TEST : TEST : TEST      Performs the test three times.
  1700.         TEST:TEST:TEST          Defines Label TEST and executes test 2x
  1701.  
  1702. Alternatively, you can preclude your Procedure calls with a Proc
  1703. statement like so:
  1704.  
  1705.         Proc ANSWER
  1706.  
  1707. Example:
  1708.  
  1709.         Proc ANSWER
  1710.         Procedure ANSWER
  1711.           Print "Forty-Two"
  1712.         End Proc
  1713.  
  1714. If you run this program again, the procedure will be entered, and the
  1715. answer will be printed out on the screen. Although the procedure
  1716. definition is positioned at the end of the program, it's possible to
  1717. place it absolutely anywhere. Whenever AMOS encouters a Procedure
  1718. statement, it installs the procedure and immediately jumps to the final
  1719. End Proc. This means there is no danger of accidentally executing your
  1720. procedure by mistake. Once you've created a procedure, and tested it to
  1721. your satisfaction, you can suppress it in your listings using the fold
  1722. option from the main menu.
  1723.  
  1724.   These folding procedures reduce the apparent complexity of your
  1725. listings and allow you to debug large programs without the distractions
  1726. of unimportant details. You can restore your procedure listings to the
  1727. screen at any time by selecting the 'unfold menu option'.
  1728.  
  1729. Local and global variables
  1730. All the variables you define inside your procedures are independent of
  1731. any other variables used in your program. These variables are said to
  1732. be "local" to your particular procedure. Here's an example which
  1733. illustrates this:
  1734.  
  1735.         A=1000:B=42
  1736.         TEST
  1737.         Print A,B
  1738.         Procedure TEST
  1739.         Print A,B
  1740.         End Proc
  1741.  
  1742. It should be apparent that the names A and B refer to completely
  1743. different variable depending on whether they are used inside or outside
  1744. the procedure TEST. The variables which occur outside a procedure are
  1745. "global" and cannot be accessed from within it. Let's take another
  1746. example:
  1747.  
  1748.         Dim A(100)
  1749.         For V=1 To 100: A(V)=V:Next V
  1750.         TEST_FLAG=1
  1751.         APRINT
  1752.         End
  1753.         Procedure APRINT
  1754.           If TEST_FLAG=1
  1755.            For P=1 To 100
  1756.              Print A(P)
  1757.            Next P
  1758.           Endif
  1759.         End Proc
  1760.  
  1761. This program may look pretty harmess but it contains two fatal errors.
  1762.  
  1763.   Firstly, the value of TEST_FLAG inside the procedure will always have
  1764. a value of zero. So the loop between the IF and the ENDIF will never be
  1765. performed. That's because the version of TEST_FLAG within the procedure
  1766. is completely separate from the copy defined in the main program. Like
  1767. all variables, it's automatically assigned to zero the fist time it's
  1768. used.
  1769.  
  1770.   Furthermore, the program won't even run! Since the global array a()
  1771. has been defined outside ARPINT, AMOS Basic will immediately report an
  1772. "array not dimensioned" error at the line:
  1773.  
  1774.         Print A(P)
  1775.  
  1776. This type of error is extremely easy tomake. So it's vital that you
  1777. treat procedures as separate programs with their own independent set of
  1778. variables and instrcutions.
  1779.  
  1780.   There are a couple of extensions to this system which make it easy
  1781. for you to transfer information between a procedure and your main
  1782. program. Once you're familiar with these commands you'll have few
  1783. problems in using procedures successfully in your programs.
  1784.  
  1785. Parameters and procedures
  1786. One possibility is to include a list of "parameter definitions" in your
  1787. procedure. This creates a group of local variables which can be loaded
  1788. directly from the main program. Here's an example:
  1789.  
  1790.         Procedure HELLO[NAME$]
  1791.           Print "Hello ";NAME$
  1792.         End Proc
  1793.  
  1794. The value to be loaded into NAME$ is entered between square brackets as
  1795. part of the procedure call. So the HELLO procedure could be performed
  1796. in the following ways:
  1797.  
  1798.         Rem Loads N$ into NAME$ and enters procedure
  1799.         Input "What's your name";n$
  1800.         HELLO[N$]
  1801.         HELLO["Stephen"]
  1802.  
  1803. As you can see, the parameter system is general purpose and works
  1804. equally well with either variables or constants. Only the type of the
  1805. variables are significant.
  1806.  
  1807.   This process can be used to transfer integer, real or string
  1808. variables. However you cannot pass entire arrays with this function. If
  1809. you want to enter several parameters you should separate your variables
  1810. using commas. For example:
  1811.  
  1812.         Procedure POWER[A,B]
  1813.         Procudure MERGE[A$,B$,C$]
  1814.  
  1815. These procedures might by called using lines like:
  1816.  
  1817.         POWER[10,3]
  1818.         MERGE["One","Two","Three"]
  1819.  
  1820. Shared variables
  1821. Another way of passing data between a procedure and the main program is
  1822. to use the SHARED instruction.
  1823.  
  1824.               SHARED (defina a list of global variables)
  1825.  
  1826. SHARED variable list
  1827.  
  1828. SHARED is placed inside a procedure definition and takes a list of AMOS
  1829. Basic variables separated by commas. These variables are now treated as
  1830. global variables., and can be accessed directly from the main program.
  1831. Any arrays which you declare in this way should of course have been
  1832. previously dimensioned in your main program. Example:
  1833.  
  1834.         A=1000:B=42
  1835.         TEST
  1836.         Print A,B
  1837.         Procudure Test
  1838.           Shared A,B
  1839.           A=A+B:B=B+10
  1840.         End Proc
  1841.  
  1842. TEST can now read and write information to the global variables A and
  1843. B. If you want to share an array you should define it like so:
  1844.  
  1845.         Shared A(),B#(),C$() : Rem Share arrays A,B# and C$
  1846.  
  1847.               GLOBAL (declare a list of global variables
  1848.                         from the main program)
  1849.  
  1850. GLOBAL variable list
  1851.  
  1852. When you're writing a large program, it's commonplace for a number of
  1853. procedures to share the same set of global variables. This provides a
  1854. simple method of transferring large amounts of information between your
  1855. various procedures. In order to simplify this process, we've included a
  1856. single command which can be used directly in your main program. GLOBAL
  1857. defines a list variables which can be accessed anywhere inside your
  1858. Basic program, without the need for an explicit SHARED statement in
  1859. your procedure.
  1860.  
  1861. Returning values from a procedure
  1862. If a procedure needs to return a value which is only local to itself,
  1863. it must use the following command so that it can inform the calling
  1864. PROCEDURE command where to find the local variable
  1865.  
  1866.               PARAM (return a parameter from a procedure)
  1867.  
  1868. PARAM
  1869. The PARAM functions provide you with a simple way of returning a result
  1870. from a procedure. They take the result of an optional expression in the
  1871. END PROC statement, and return it in one of the variables PARAM,
  1872. PARAM#, or PARAM$ depending on its type. Example:
  1873.  
  1874.         MERGE_STRINGS["Amos"," ","Basic"]
  1875.         Print PARAM$
  1876.         Procedure MERGE_STRINGS[A$,B$,C$]
  1877.           Print A$,B$,C$
  1878.         End Proc
  1879.  
  1880. Note that END PROC may only return a single parameter in this way. The
  1881. PARAM functions will always contain the result of the most recently
  1882. executed procedure. Here's another example, this time showing the use
  1883. of the PARAM# function.
  1884.  
  1885.         CUBE[3,0]
  1886.         Print Param#
  1887.         Procedure CUBE[A#]
  1888.           C#=CUBE#*CUBE#*CUBE#
  1889.         EndProc[C#]
  1890.  
  1891. Leaving a procedure
  1892.  
  1893.                POP PROC (leave a procedure immediately)
  1894.  
  1895. POP PROC
  1896.  
  1897. Normally, procedures will only return to the main program when the END
  1898. PROC instruction is reached. Sometimes, however, you need to exit a
  1899. procedure in a hurry. IN this case you can use the POP PROC function to
  1900. exit immediately.
  1901.  
  1902. Local DATA statements
  1903. Any data statements defined inside one of your procedures are held
  1904. completely separately from those in the main program. This means each
  1905. procedure can have its own individual data areas.
  1906.  
  1907. Hints and tips
  1908. Here are a few guidelines which will help you make the most out of your
  1909. AMOS Basic procedures:
  1910.  
  1911.   * It's perfectly legal for a proceduces to call itself, but this
  1912.     recursion is limited by the amount of space used to store the local
  1913.     variables. If your program runs out of memory you'll get an
  1914.     appropriate error.
  1915.  
  1916.   * All local variables are automatically discarded after the procedure
  1917.     has finished executing.
  1918.  
  1919. Memory banks
  1920. AMOS Basic includes a number of powerful facilities for manipulating
  1921. sprites, bobs and music. The data required by these functions needs to
  1922. be stored along with the Basic program. AMOS Basic uses a special set
  1923. of 15 sections of memory for this purpose called "banks".
  1924.  
  1925.   Each bank is referred to by a unique number ranging from 1 to 15.
  1926. Many of these banks can be used for all types of data, but some are
  1927. dedicated solely to one sort of information such as sprite definitions.
  1928. All sprite images are stored in bank 1. They can be loaded into memory
  1929. using a line like:
  1930.  
  1931.         Load "AMOS_DATA:Sprites/Octopus.abk"
  1932.  
  1933. There are two different forms of memory bank: Permanent and temprorary.
  1934. Permanent banks only need to be defined once, and are subsequently
  1935. saved along with your program automatically. Temporary banks are much
  1936. more volatile and are reinitialized every time a program is run.
  1937. Furthermore, unlike permanent banks, temporary banks can be erased from
  1938. memory using the CLEAR command.
  1939.  
  1940. Types of memory bank
  1941. AMOS Basic supports the following types of memory bank:
  1942.  
  1943.         Class     Stores                      Restrictions  Type
  1944.         Sprites   Sprite or bob definitions   Only bank 1   Permanent
  1945.         Icons     Holds icon definitions      Only bank 2   Permanent
  1946.         Music     Contains sound track data   Only bank 3   Permanent
  1947.         Amal      Used for AMAL data          Only bank 4   Permanent
  1948.         Samples   The Sample Data             banks 1-15    Permanent
  1949.         Menu      Stores MENU definition      banks 1-15    Permanent
  1950.         Chip work Temporary workspace         banks 1-15    Temporary
  1951.         Chip data Permanent workspace         banks 1-15    Permanent
  1952.         Fast work Temporary workspace         banks 1-15    Temporary
  1953.         Fast data Permanent workspace         banks 1-15    Permanent
  1954.  
  1955. RESERVE (reserve a bank)
  1956.  
  1957. RESERVE AS type,bank,length
  1958. The banks used by your sprites or bobs are allocated automatically by
  1959. AMOS. The RESERVE command allows you to create any other banks which
  1960. you might require. Each different type of bank has its own unique
  1961. version of the RESERVE instruction.
  1962.  
  1963. RESERVE AS WORK bankno,length
  1964. Reserves "length" bytes for use as a temporary workspace. Whenever
  1965. possible this memory area will be allocated using fast memory, so you
  1966. shoudn't call this command in conjunction with instructions which need
  1967. to access to Amiga's blitter chip.
  1968.  
  1969. RESERCE AS CHIP WORK bankno,length
  1970. Allocates a workspace of size "length" using chip ram. You can check
  1971. whether there's enough chip ram available with the CHIP FREE function.
  1972.  
  1973. RESERCE AS CHIP DATA bankno,length
  1974. Reserves "length" bytes of memory from chip ram. This bank will be
  1975. automatically saved along with your AMOS programs.
  1976.  
  1977.   Bank may be any number between 1 and 15. Since banks 1 to 5 are
  1978. normally reserved by the system, it's wisest to leave them alone. Note
  1979. that the only limit to the length of a bank is the amount of available
  1980. memory.
  1981.  
  1982.                    LISTBANK (list the banks in use)
  1983.  
  1984. LISTBANK lists the numbers of the banks currently reserved by a
  1985. program, along with their location and size. The listing is produced in
  1986. the following format:
  1987.  
  1988.         Number    Type    Start    Length
  1989.  
  1990. Normally the length of a bank is returned in bytes, but in case of
  1991. sprites and icons the value represents the total number of images in
  1992. the bank instead. The reason for this is that the storage of each image
  1993. can be anywhere in the Amiga's memory, the bank is therefore not a
  1994. continuous block of memory. So don't BSAVE a sprite bank, simply use
  1995. SAVE "filename.abk"
  1996.  
  1997. Deleting banks
  1998. During the course of a program you may need to clear some banks from
  1999. the memory so as to load in additional data. Sprites may need to change
  2000. for a new part of a game or a special piece of music is required to be
  2001. played. The ERASE command gives you quick control for data deletion.
  2002.  
  2003.                          ERASE (delete a bank)
  2004.  
  2005. ERASE b
  2006.  
  2007. ERASE deletes the contents of a memory bank. The bank number b can
  2008. range from 1 to 15. Note that any memory used by this bank is
  2009. subsequently freed for use by your program.
  2010.  
  2011. Bank parameter functions
  2012. If you want to have direct access to the bank data using commands such
  2013. as poke, doke and loke then use these commands to find a bank's address
  2014. in memory and its size.
  2015.  
  2016.                =START (get the start address of a bank)
  2017.  
  2018. s=START(b)
  2019.  
  2020. This function returns the start address of bank unmber b. Once it's
  2021. been removed, the location of the bank will never subsequently change.
  2022. So the result of this function will remain fixed for the lifetime of
  2023. the bank. Example:
  2024.  
  2025.         Reserve As Work 3,2000
  2026.         Print Start(3)
  2027.  
  2028.                   =LENGTH (Get the length of a bank)
  2029.  
  2030. l=length(b)
  2031.  
  2032. The LENGTH function returns the length in bytes of bank number b. If
  2033. the bank contains sprites then the number of sprites or icons will be
  2034. returned instead. A value of zero indicates that bank b does not exist.
  2035. Exaple:
  2036.  
  2037.         Reserve as work 6,1000
  2038.         Print Length(6)
  2039.         Erase 6
  2040.         Print Length(6)
  2041.  
  2042. Loading and saving banks
  2043. Some programs will require many banks of information, a good example is
  2044. an adventure. This would need to load various graphics and sounds for
  2045. the different locations within the games domain. An Amiga 500 would
  2046. have great difficulty holding all this data at once and so it's best to
  2047. simply load the data at the appropriate time of use.
  2048.  
  2049.                      LOAD (Load one or more banks)
  2050.  
  2051. LOAD "filename"[,n]
  2052.  
  2053. The effect of this command varies depending on the type of file you are
  2054. loading. If the file holds several banks, then ALL current memory banks
  2055. will be erased before the new banks are loaded from the disc. However
  2056. if you're loading just a single bank, only this bank will replaced. The
  2057. optional destination point specifies the bank which is to be loaded
  2058. with your data. If it's omitted, then the data will be loaded into the
  2059. bank from which it was originally saved.
  2060.  
  2061.   Sprite banks are treated slightly differently. In this case the
  2062. parameter n toggles between two separate loading modes. If n is omitted
  2063. or is assigned a value of zero, the current bank will completely
  2064. overwritten by the new sprites. Any other value for n forces the new
  2065. sprites to be *appended* to this bank. This allows you to combine
  2066. several sprite files into the same program. Example:
  2067.  
  2068.         LOAD "AMOS_DATA:Sprites/Octopus.abk"
  2069.  
  2070.               SAVE (Save one or more banks onto the disc)
  2071.  
  2072. SAVE "filenami"[,n]
  2073.  
  2074. The SAVE command saves your memory banks onto the disc. There are two
  2075. possible formats:
  2076.  
  2077.         SAVE "filename.ABK"
  2078.  
  2079. This saves *ALL* currently defined banks into a single file onto your
  2080. disc.
  2081.  
  2082.         SAVE "filename.ABK",n
  2083.  
  2084. The expanded form just saves memory bank number n. One should also be
  2085. sure to use the extension ABK at the end of the filename as this will
  2086. ensure you can identify that the file contains one or more memory
  2087. banks.
  2088.  
  2089.                    BSAVE (Save an unformatted block
  2090.                            in binary format)
  2091.  
  2092. BSAVE file$, start TO end
  2093.  
  2094. The memory stored between "start" and "end" is saved on the disc in
  2095. file$. This data is saved with no special formatting. Example:
  2096.  
  2097.         BSAVE "Test",Start(7) TO Start(7)+Length(7)
  2098.  
  2099. The above example saves the data in memory bank 7 to disc. The
  2100. difference between this file and a saved file as a normal bank is that
  2101. SAVE writes out a special blank header that contains information
  2102. concerning the bank. This header is not present with a BSAVED file so
  2103. it cannot be loaded using LOAD.
  2104. WARNING: The sprites an icon banks are not stored as one chunk of
  2105. memory. Each object can reside anywhere in memory. Because AMOS uses
  2106. this flexible system of data storage you simply can't save the memory
  2107. bank using BSAVE.
  2108.  
  2109.                   BLOAD (load binary information into
  2110.                      a specified address or bank)
  2111.  
  2112. BLOAD file$, addr
  2113.  
  2114. The BLOAD command loads a file of binary data into memory. It does not
  2115. alter the incoming information in any way. There are two forms of this
  2116. function.
  2117.  
  2118.         BLOAD file$, addr
  2119.  
  2120. File$ will be loaded from the disc into the address addr.
  2121.  
  2122.         BLOAD file$, bank
  2123.  
  2124. File$ will be loaded into bank. This bank must have been previously
  2125. reserved, otherwise an error will be generated. Also be sure not to
  2126. load a file that is larger than the reserved bank, otherwise it will
  2127. over run the bank and start corrputing other areas of memory!
  2128.  
  2129. Memory fragmentation
  2130. Sometimes, after a busy editing session, you may get an "Out of Memory"
  2131. error, even though the information line implie
  2132.  
  2133. Finding space for your variables
  2134. As a default, all variables are stored in a memory area of exactly 8k
  2135. in length. Although this may seem incredibly meagre, it's easily
  2136. capable of holding around 2 pages of normal text, or 2000 numbers.
  2137. We've intentionally set it as small as possible so as to maximize the
  2138. amount of space available for your screens and memory banks.
  2139.  
  2140.             SET BUFFER (set the size of the variable area)
  2141.  
  2142. SET BUFFER n
  2143.  
  2144. Sets the size of the variable area in your current program to "n"
  2145. kilobytes. This must be the FIRST instruction in your program
  2146. (excluding Rems). Otherwise you'll get an appropriate error message.
  2147. For an example of this feature see EXAMPLE 4.1  in the MANUAL folder.
  2148.  
  2149.   SET BUFFER should be used in your program whenever you get an "out of
  2150. string space error". Increase the value in 5k increments until the
  2151. error disappears. If you run out of memory during this process, you'll
  2152. propably need to reduce the requirements of your program in some way.
  2153. See the CLOSE WORKBENCH and CLOSE EDITOR commands for more details.
  2154.  
  2155.       =FREE (return the amount of free mem. in the variable area)
  2156.  
  2157. f=FREE
  2158.  
  2159. FREE returns the number of bytes which are currently available to hold
  2160. your variables. This value can be increased as required using the
  2161. previous SET BUFFER command.
  2162.  
  2163.   Whenever FREE is called, the variable area is reorganized to provide
  2164. the maximum space for your variables. This process is known as "garbage
  2165. collection", and is normally performed automatically.
  2166.  
  2167.   Due to the power of AMOS Basic, the entire procedure is usually
  2168. accomplished practically instantaneously. But if your variable area is
  2169. bery large and you're using a lot of strings, the garbage collection
  2170. routine might take several seconds to complete. Conceivably, this could
  2171. lead to a unexpected delay in the execution of your programs. Since the
  2172. garbage collection is totally essential, you may need to add an
  2173. explicit call to the FREE command when it will cause the least amount
  2174. of harm in your program.
  2175.  
  2176. NOW LOAD PART TWO...
  2177.