14: AMAL 176 ---------------------------- If you wish to generate the smooth movement required in an arcade game, it's necessary to move each object on the screen dozens of times a second. This is a real struggle even in machine code and it's way beyond the abilities of the fastest version of Basic. AMOS sidesteps this problem by incorporating a powerful animation language which is executed independently of your Basic programs. This is capable of generating high speed animation effects which would be impossible in standard Basic. The (AM)os (A)nimation (L)anguage (AMAL) is unique to AMOS Basic. In can be used to animate anything from a sprite to an entire scren at incredible speed. Up to 16 AMAL programs can be executed simultaneously using interrupts. Each program controls the movements of a single object on the screen. Objects may be moved in complex predefined attack patterns, created from a separate editor accessory. You can also control your objects directly from the mouse or joystick if required. The sheer versatility of the AMAL system has to be seen to be believed. AMAL principles =============== AMAL is effectively just a simple version of Basic which has been carefully optimised for the maximum possible speed. As with Basic, there are instructions for program control (Jump), making decisions (If) and repeating sections of code in loops (For...Next). The real punch comes when AMAL program is run. Not only are the commands lightning fast but all AMAL programs are *compiled* before run-time. AMAL commands are entered using short keywords consisting of one or more capital letters. Anything in lowercase is ignored completely. This allows you to pad out your AMAL instructions into something more readable. So the M command might be entered as Move or the L instruction as Let. AMAL instructions can be separated by parctically any unused characters including spaces. You can't however, use the colon ":" for this purpose, as it's needed to define a label. We advise you to use a semi-colon ";" to separate commands to avoid possible AMAL headaches. There are two ways of creating your AMAL programs. The first is to produce your animation sequences with the AMAL accessory program and save them into a memory bank or you can define your animations inside AMOS Basic using the AMAL command. The general format of this function is: AMAL n,a$ "n" is the identification number of your new AMAL program. As a default all programs are assigned to the relevant hardware sprite. So the first AMAL program controls sprite number one, the second sprite number two, and so on. You can change this selection at any time using a separate CHANNEL command. a$ is a string containing a list of AMAL instructions to be performed in your program. Here's a simple example: Load "AMOS_DATA:Sprites/Monkey_right.abk" Get Sprite Palette Sprite 8,130,50,1 177 Amal 8,"S: M 300,200,100 ; M -300,200,100 J S" Amal On 8 : Rem Activate AMAL program number eight Direct The program returns you straight back to direct mode with the DIRECT command. Try typing a few Basic commands at this point. You can see the movement pattern continues regardless, without interfering with the rest of the AMOS system. Also note we have used sprite 8 to force the use of a computed sprite. All computed sprites from 8 to 15 are automatically assigned to the equivalent channel number by the AMAL system. So there's no need for any special initialisation procedures. Unless you wish to restrict the amount of hardware sprites it's safest to stick to just computed sprites in your programs. Notice how we've activated the AMAL program using the AMAL ON command. This has the format: AMAL ON [prog] "prog" is the number of a single AMAL program. If it's omitted, then *all* your AMAL programs will be executed at once! AMAL tutorial ============= We'll now provide you with a guided tour of the AMAL system. This allows you to slowly familiarise yourself with the mechanics of AMAL programs, without having to worry about too many technical details. For the time being we'll be concentrating on sprite movements, but the same principles can also be applied to bob or screen animations. Start off by loading some examples into memory. These can be found in in the SPRITES folder on the AMOS data disc. To get a directory of Sprite files type the following from the direct windows: Dir "AMOS_DATA:" To load a sprite file, type a line like: Load "AMOS_DATA:Sprites/Octopus.abk" Moving an object ---------------- As you would expect from a dedicated animation language, AMAL allows you to move your objects in a variety of different ways. The simplest of these involves the use of the Move command. Move (move object) - M w,h,n The M command moves an object w units to the right and h units down in exactly n movement steps. If the coordinates of your subject were (X,Y), then the object would progressively move to X+W,Y+H. Supposing you have a sprite at coordinates 100,100. The instruction M 100,100,100 would move it to 200,200. The speed of this motion 178 depends on the number of movement steps. If n is large then each individual sprite movement will be small and the sprite will move very slowly. Conversely, a small value for n results in a large movement steps which jerk the sprite across the screen at high speed. Here are some examples of the Move command. Rem This moves an octopus down the screen using AMAL Load "AMOS_DATA:Sprites/Octopus.abk" : Get Sprite Palette Sprite 8,300,0,1 Amal 8,"M 0,250,50" : Amal On 8 : Wait Key Rem Moves octopus down and across the screen Load "AMOS_DATA:Sprites/Octopus.abk" : Get Sprite Palette Sprite 10,150,150,1 Amal 10,"M 300,-100,50" : Amal On 10 : Wait Key Rem Demonstrates multiple Move commands. Load "AMOS_DATA:Sprites/Octopus.abk" : Get Sprite Palette M$="Move 300,0,50 ; Move -300,0,50" Sprite 11,150,150,1 Amal 11,M$ : Amal On 11 : Wait Key Notice how we've expanded M to Move in above program. Since the letters "ove" are in lower case, they will be ignored by the AMAL system. At first glance, Move is a powerful but unexciting little instruction. It's ideal for moving objects such as missiles, but otherwise it's pretty uninspiring. Actually nothing could be further from the truth. That's because the parameters in the move instruction are not limited to simple numbers. You can also use complex arithmetical expressions incorporating one of a variety of useful AMAL functions. Example: Load "AMOS_DATA:Sprites/Octopus.abk" : Get Sprite Palette Sprite 12,150,150,1 : Amal 12,"Move XM-X,YM-Y,32" Amal On 12 : Wait Key This smoothly moves computed sprite 12 to the current mouse position. X and Y hold the coordinates of your sprite, and XM and YM are functions returning the current coordinates of the mouse. It's possible to exploit this effect in games like Pac-Man to make your objects chase the player's character. Example: Load Iff "AMOS_DATA:IFF/Frog_Screen.IFF",1 Channel 1 To Screen Display 1 179 Amal 1,"Move 0,-200,50 ; Move 0,200,50" Amal On 1 : Direct Channel assigns an AMOS program to a particular object. We'll be discussing this command in detail slightly later, but the basic format is: CHANNEL p TO object n "p" is the number of your AMAL program. Allowable values range from 0 to 63, although only the first 16 of these programs can be performed using interrupts. "object" specifies the type of object you with to control with your AMAL program. This is indicated using one of the following statements: Sprite (values >7 refer to computed sprites) Bob (blitter object) Screen Display (used to move the screen display) Screen Offset (Hardware scrolling) Screen Size (Changes the screen size using interrupts) Rainbow (Animates a rainbow effect) "n" is the number of the object to be animated. This object needs to be subsequently defined using the SPRITE, BOB or SCREEN open instructions. Animation --------- Anim (animate an object) - A n,(image,delay)(image,delay)... The Anim instruction cycles an object through a sequence of images, producing a smotth animation effect. "n" is the number of times the animation cycle is to be repeated. A value of zero for this parameter will perform the animation continuously. "image" sprcifies the number of an image to be used for each frame of your animation. "delay" determines the length of time this image is to be displayed on the screen, measured in units of a 50th of a second. Example: Load "AMOS_DATA:Sprites/Monkey_right.abk" : Get Sprite Palette Sprite 9,150,50,11 M$="Anim 12, (1,4)(2,4)(3,4)(4,4)(5,4)(6,4) ;" 180 M$=M$+"Move 300,150,150 ; Move -300,-150,75" Amal 9,M$ Amal On 9 Direct This program combines a sprite movement with an animation. Notice how we've separated the commands with a semi-colon. This ensures that the two operations are totally independent of each other. Once the animation sequence has been defined, AMAL will immediatly jump to the next instruction, and the animation will begin. It's important to realize that Anim only works in conjunction with sprites and bobs. So it's not possible to animate entire screen with this command. Simple Loops ------------ Jump (redirects an AMAL program) - J label Jump provides a simple way of moving from one part of an AMAL program to another. "label" is the target of your jump, and must have been defined elsewhere in your current program. All AMAL labels are defined using a single uppercase followed by a colon. like instructions, you can pad them out with lower case to improve readability. Remember that each label is deinfed using just a *single* letter. So "S:" and "Swoop:" refer to the same label! If you attempt to define two labels starting with an identical letter, you'll be presented with a "label already defined in animation string" error. Each AMAL program can have its own unique set of labels. It's perfectly acceptable to use the identical labels in several different programs. Example: Load "AMOS_DATA:Sprites/Octopus.abk" Get Sprite Palette For S=8 to 20 Step 2 : Rem Set up 7 computed sprites Sprite S,200,(S-7)*13+40,1 Next S Rem : Now let's create seven AMAL programs For S=1 to 7 Channel S To Sprite 6+(S*2) M$="Anim 0,(1,2)(2,2)(3,2)(4,2) ; Label: Move "+Str$(S*2)"+,0,7 ;" Amal S,M$ Next S Rem Okay, now animate it all! Amal On : Direct Since AMAL commands are performed using interrupts, infinite lopos 181 could be disasterous. So a special counter is automatically kept of the number of jumps in your program. When the counter exceeds ten, any further jumps will be totally ignored by the AMAL system. NOTE: if you rely on this system, and allow your programs to loop continually, uou'll waste a great deal of the Amiga's computer power. In practice, it's much more effecient to limit yourself to just a single jump per VBL. This can be achieved by adding a simple PAUSE comand before each Jump in your program. See PAUSE for more details. Variables and expressions ------------------------- Let (assigns a value to a register) - L register=expression The L instruction assigns a value to an AMAL register. The action is very similar to normal Basic, except that all expressions are evaluated strictly from left to right. Registers are integer variables used to hold the intermediate values in your AMAL programs. Allowable numbers range between -32768 to +32768. There are three basic types of register: Internal registers - - - - - - - - - Every AMAL program has its own set of 10 internal registers. The names of these registers start with the letter R, followed by one of the digits from 0 to 9 (R0-R9). Internal registers are like the local variables inside an AMOS Basic procedure. External registers - - - - - - - - - Ecternal registers are rather different because they retain their values between separate AMAL programs. This allows you to use these registers to pass information between several AMAL routines. AMAL provides you with up to 26 external registers, with names ranging from RA to RZ. The contents of any internal or external register can be accessed directly from your Basic program using the AMREG function. Special registers 182 - - - - - - - - - Special registers are a set of three values which determine the status of your object. X,Y contain the coordinates of your object. By changing these registers you can move your object around on the screen. Example: Load "AMOS_DATA:Sprites/Frog_Sprites.abk" : Channel 1 To Bob 1 Flash Off : Get Sprite Palette : Bob 1,0,0,1 Amal 1,"Loop: Let X=X+1 ; Let Y=Y+1; Pause; Jump Loop" Amal On 1 : Direct "A" stores the number of the image which is displayed by a sprite or bob. You can alter this value to generate your own animation sequences like so: Load "AMOS_DATA:Sprites/Frog_Sprites.abk" : Get Sprite Palette Flash Off : Channel 2 To Bob 1 : Bob 1,300,100,1 M$="Loop: Let A=A+1 ; " M$=M$+"For R0=1 To 5 ; Next R0 ; Jump Loop" Amal 2,M$ Amal On 2 : Direct The For To Next lop will be explained in more detail below. It is used here to slow down each change to Bob 1's image. When the "Next" of the loop is executed, AMAL won't continue until a vertical blank has occurred. Also note the use of ";" to separate the AMAL instructions - although a space " " will serve just as well. Operators --------- AMAL expressions can include all the normal arithmetic operations, except MOD. You can also use the following logical operatoins in your calculations: & Logical AND | Logical OR Note that it's not possible to change the order of evaluation using brackets "()" as this would slow down your calculations considerably and thus reduce the allowable time in the interrupt. Type the following example: Load "AMOS_DATA:Sprites/Octopus.abk" : Hide Get Sprite Palette Sprite 8,X Mouse,Y Mouse,1 Amal 8,"Loop: Let X=XM ; Let Y=YM ; Pause ; Jump Loop" Amal On 8 Load "AMOS_DATA:Sprites/Octopus.abk" : Hide Get Sprite Palette Sprite 8,X Mouse,Y Mouse,1 Amal 8,"Anim 0,(1,4)(2,4)(3,4)(4,4) ; Loop: Let X=XM ; Let Y=YM ; Pause ; Jump Loop" Amal On The above examples effectively mimic the CHANGE MOUSE command. However this system is much more powerful as you can easily move bobs, computed sprites, or even screens using exactly the same technique. Making decisions 183 ---------------- If (branch within an AMAL string) If test Jump L This instruction allows you to perform simple tests in your AMAL programs. If the expression test is -1 (true) the program will jump to label L, otherwise AMAL will immediately progress to the next instruction. Note that unlike it's equivalent, you're limited to a single jump operation after the test. It's common practice to pad out this instruction with lowercase commands like "then" or "else". This makes the action of the command rather more obvious. Here's an example: If X>100 then Jump Label else Let X=X+1 - - - - "test" can be any logical expression you like, and may include: <> Not equals < Less than > Greater than = Equals Example: Load "AMOS_DATA:Sprits/Octopus.abk" Get Sprite Palette Sprite 8,130,50,1 C$="Main: If XM>100 Jump Test: " C$=C$+"Let X=XM " C$=C$+"Test: If YM>100 Jump Main " C$=C$+"Let Y=YM Jump Main" Amal 8,C$ : Amal On : Direct WARNING! Don't try to combine several tests into a single AMAL expression using "&" or "|". Since expressions are evaluated from left to right, this will generate an error. Take the expression: X>100|Y>100. This is intended to check whether X>100 OR Y>100. In practice, the expression will be evaluated in the following order: X>100 May be TRUE or FALSE 184 |Y OR result with Y >100 Check if (Y>100|Y)>100) The result from the above expression will obviously be no relation to the expected value. Technically-minded users can avoid this problem by using boolean algebra. First assign each test to an single AMAL register like so: Let R0=X>100; Let R1=Y>100 Now combine these tests into a single expression using | and & and use it directly in your If statement. If R0 | R1 Jump L ... This may look a little crazy, but it works beautifully in practice. For To Next (loop within AMAL) - - - For reg=start To end : : Next reg This implements a standard FOR...NEXT loop which is almost identical to its Basic equivalent. These loops can be exploited in your programs to move objects in complex visual patterns. "reg" may be any normal AMAL register (R0-R9 or RA-RZ). However you can't use special registers for this purpose. As with Basic, the register after the Next must match with the counter you specified in the For, otherwise you'll get an AMAL syntax error. Also note that the step size is always set to one. Additionally, it's possible to "nest" any number of loops inside each other. Note that each animation channel will only perform a single loop per VBL. This synchronizes the effects of your loops with the screen display, and avoids the need to add an explicit Pause command before each Next. Generating an attack wave for a game ------------------------------------ These lopos can be used to create some quite complex movement patterns. The easiest type of motion is in a straight line. This can be generated using a single For...Next loop like so: Load "AMOS_DATA:Sprites/Octopus.abk" : Get Sprite Palette Sprite 8,130,60,1 C$=For R0=1 To 320 ; Let X=X+1 ; Next R0" : Rem Move sprite Amal 8,C$ : Amal On 8 : Direct You can now expand this program to sweep the object back and forth across the screen. Load "AMOS_SATA:Sprites/Octopus.abk" : Get Sprite Palette Sprite 8,130,60,1 C$="Loop: For R0=1 To 320 ; Let X=X+1 ; Next R0 ;" 185 C$=C$+" For R0=1 To 320 ; Let X=X-1 ; Next R0 ; Jump Loop" Amal 8,C$ : Amal On 8 : Direct The first loop moves the object from left to right, and the second from right to left. So far the pattern has been restricted to just horizontal movements. In order to create a realistic attack wave, it's necessary to incorporate a vertical component to this motion as well. This can be achieved by enclosing your program with yet another loop. Load "AMOS_DATA:Sprites/Octopus.abk" : Get Sprite Palette Sprite 8,130,60,1 : C$=For R1=0 To 10 ;" C$=C$+"For R0=1 To 320 ; Let X=X+1 ; Next R0 ; " C$=C$+"Let Y=Y+8 ; " C$=C$+"For R0=1 To 320 ; Let X=X-1 ; Next R0 ; " C$=C$+"Let Y=Y+8 ; Next R1" Amal 8,C$ : Amal On 8 The above programs generates a smooth but quite basic attack pattern. A further demonstration can be found in EXAMPLE 14.1 in the MANUAL folder. Recording a complex movement sequence ------------------------------------- PLay -- PLay path If you've looked at the smooth attack waves in a modern arcade game, and thought them forever beyond your reach, think again. The AMAL Play command allows you freely animate your objects through practically any sequence of movements you can imagine. It works by playing a previously defined movement pattern stored in the AMAL memory bank. These patterns are created from the AMAL accessory on the AMOS program disc. This simply records a sequence of mouse movements and enters them directly into the amal memory bank. Once you've created your patterns in this way, you can effortlessly assign them to any object on the screen, reproducing your original patterns perfectly. Both the speed and direction of your movement can be changed at any time from your AMOS Basic program. The first time AMAL encounters a Play command, it checks the AMAL bank to find the recorded movement you specified using the "path" parameter. "path" is simply a number ranging from one to the maximum number of patterns in the bank. If a problem crops up during this phase, AMAL will abort the play instruction completely, and will skip to the next instruction in your animation string. After the pattern has been initialised, register R0 will be loaded with the tempo of the movement. This determines the time interval between each individual movement step. All timings are measured in units of a 50th of a second. By changing this register within your AMAL program, you can speed up or slow down your object movements accordingly. Note that each movement step is *added* to the current coordinates of your object. So if an object is subsequently moved using the Sprite or Bob instructions, it will continue its manoeuvres unaffected, starting from the new screen position. It's therefore possible to animate dozens of different objects on the screen using a single sequence of movements. Register R1 now contains the flag which sets the direction of your 186 movements. There are three possible situations: * R1>0 Forward A value of one for R1 specifies that the movement pattern will be replayed from start to finish, in exactly the order it was created (this is the default). * R1=0 Backward Many animation sequences require your objects to move back and forth across the screen in a complex pattern. To change direction, simply load R1 with a zero. Your object will now turn around and execute your original movement steps in reverse. * R1=-1 Exit If a collision has been detected from your AMOS program, you'll need to stop your object completely, and generate an explosion effect. This can be accomplished by setting R1 to a value of minus one. AMAL will now abort the play instruction, and immediately jump to the next instruction in your animation sequence. The clever thing about these registers is that they can be changed directly from AMOS Basic. This lets you control your movement patterns directly from within your main program. There's even a special AMPLAY instruction to make things easier for you. The PLay comand is perfect for controlling the aliens in an arcade game. In fact, it's the single most powerful instruction in AMAL. AMAL (call an AMAL program) AMAL n,a$ AMAL n,p AMAL n,a$ to address The AMAL command assigns an AMAL program to an animation channel. This program can be taken either from a string in a$ or directly from the AMAL bank. The first version of the instruction loads your program from the string a$ and assigns it to channel n. a$ can contain any list of AMAL instructions. Alternatively you can load your program from a memory bank stored in bank number 4. n is the number of an animation channel ranging from 0 to 63. Each AMOS channel can be independently assigned to either a bob, a sprite or a screen. Only the first 16 AMAL programs can be performed using interrupts. In order to exceed this limit you need execute your programs directly from Basic using the SYNCHRO command. The final version of the AMAL insturction is provided for advanced users. Instead of moving an actual object, this simply copies the contents of registers X,Y and A into a specific area of memory. You can now use this information directly in your own Basic routines. It's 187 therefore possible to exploit the AMAL system to animate anything from a Block to a character. The format is: AMAL n,a$ To address "address" must be EVEN and must point to safe region of memory, preferably in an AMOS string or a memory bank. Every time your AMAL program is executed (50 times per second), the following values will be written into this memory area: Location Effect -------- ------ Address Bit 0 is set to 1 if the X has changed Bit 1 indicates that Y has been altered Bit 2 will be set if the image (A) has changed since the last interrupt. Address+2 Is a *word* containing the latest value of X Address+4 Holds the current value of Y Address+6 Stores the value of A These values can be accessed from your program using a simple DEEK. NOTE: This option totally overrides any previous CHANNEL assignments. AMAL commands ============= Here is a full list of the available amal commands: M (Move) Move deltaX, deltaY, steps A (Anim) Anim cycles,(image,delay)(image,delay)... L (Let) Let reg=exp 188 J (Jump) Jump L I (If) If exp Jump L For To Next For Reg=start To end ...Next Reg PL (PLay) PLay path 189 P (Pause) Pause AU (AUtotest) AU (list of tests) See the Autotest System 190 X (eXit) eXit Exits from an AUtotest and re-enters the current AMAL program. W (Wait) Wait Freezes your AMAL program and only executes the AUtotest. O (On) On Activates the main program after a Wait. D (Direct) Direct Sets the section of the main program to be executed after an autotest. AMAL functions 191 ============== =XM Returns the X coordinate of the mouse =YM Returns the Y coordinate of the mouse =K1 Status of left mouse key (-1, if pressed, otherwise 0) =K2 Status of right mouse key =J0 Test right joystick. Result in bit-map. =J1 Test left joystick. See the JOY command. =Z(n) Random number. Returns a random number between -32767 to 32768. This number can be limited to a specific range using the bit-mask n. A logical AND operation is performed between the bit mask n and the random number to generate the final result. So setting n to a value of 255 will ensure that the numbers will be returned in the range 0 to 255. Since this function has been optimized for speed, the number returned isn't totally random. If you need really random numbers, you would be better to generate your values using Basic's RND and then load them into an external AMAL register with the AMREG function. =XH(s,x) Converts a screen x coordinate into a hardware coordinate. 192 =YH(s,y) Converts a screen y coordinate into hardware format. =XS(s,x) Hardware to screen conversion =YS(s,y) Hardware to screen conversion =BC(n,s,e) Check for collisions between bobs. BC is identical to the equivalent AMOS Basic BOB COL instruction. It checks bob number n for collisions between bobs s to e. If a collision has been detected, then BC will return a value of -1, otherwise 0. This instruction may NOT be performed within an iterrupt. So it's only available when you are executing your AMAL routines directly from Basic with the SYNCHRO instruction. =SC(n,s,e) This is equivalent to the SPRITE COL function. Like BC function, it's only allows in conjuction with the SYNCHRO instruction. =V(v) VU-meter. The VU function samples one of the sound channels and returns the intensity of the current voice. This is a number in the range 0-255. You can use this information to animate your objects in time to the music. An example of this can be found in EXAMPLE 14.3. Also see the VUMETER function from AMOS Basic Controlling AMAL from Basic 193 =========================== AMAL ON/OFF (start/stop an AMAL program) AMAL ON [n] Once you've defined your AMAL program you need to execute it using the AMAL ON command. This activates the AMAL system and starts your programs from the first instruction. AMAL ON activates all your programs. The optional parameter n allows you start just one routine at a time. AMAL OFF [n] Stops one or all AMAL programs from executing. These programs are erased from meomry. They can only be restarted by redefining them again using the AMAL instruction. AMAL FREEZE (temporarily freeze an amal program) AMAL FREEZE [n] Stops one or more AMAL programs for running. Your programs can be restarted at any time using a simple call to AMAL ON. Note that this instruction should always be used to stop AMAL before a command such as DIR is executed, otherwise problems with timing can cause visual mishaps. =AMREG= (get the value of an external AMAL register) r=AMGER(n, [channel]) AMREG(n, [channel])=expression The AMREG function allows you to access the contents of internal and external AMAL register directly from within your Basic program. "n" is the number of the register. Possible values range from 0 to 25 with zero representing register RA and twenty-five denoting RZ. By using the optional "channel" parameter you can reference any AMAL internal register. In this mode "n" ranges between 0 and 9 representing R0 to R9. The following examples shows how it is possible to retrieve a sprite's current X-position from Basic: Load "AMOS_DATA:Sprites/Octopus.abk" : Get Sprite Palette Channel 1 To Sprite 8 : Sprite 8,100,100,1 A$="Loop: Let RX=X+1; Let X=RX; Pause; Jump Loop" Amal 1,A$ : Amal On : Curs Off Do Locate 0,0 Z=Asc("X")-65 : Rem Note the use of ASC to get the register # Print Amreg(Asc("X")-65) Loop AMPLAY (control an animation 194 produced with PLay) AMPLAY tempo,direction [start TO end]) Any movement sequences you've produced using the AMAL PL command are controlled through the internal registers R0 and R1. Each object will be assigned it's own unique set of AMAL registers. So if you're animating several objects, you'll often need to load a number of these registers with exactly the same values. Although this can be achieved using the standard AMREG function, it would obviously be much easier if there was a single instruction which allowed you to change R0 and R1 for a whole batch of objects at a time. That's the purpose of the AMPLAY command. AMPLAY takes the "tempo" and "direction" of your movements, and loads them into the registers R0 and R1 in the selected channels. "tempo" controls the speed of your object on the screen. It sets a delay (in 50ths of a second) between each successive movement step. "direction" changes the direction of the motion. Here's a list of the various different options.: Value Direction ----- --------- >0 Move the selected object in the original movement direction. 0 Reverses the motion and moves the object backwards -1 Aborts movement pattern and jumps to the following instruction in your AMAL animation sequence. As a default, this instruction will affect all current animation channels. This can be changed by adding some explicit "start" and "end" points to the command. "start" is the channel number of the first object to be adjusted. "end" holds the channel number assigned to the last object in your list. Note that either the "tempo" or the "direction" can be omitted as required. Examples: Amplay ,0 : Rem reverse your objects Amplay 2, : Rem Slow down your movement patterns Amplay ,-1 3 To 6 : Rem stop movements on channels 3,4,5 and 6. =CHANAN (test AMAL animation) 195 s=CHANAN(channel) This is a simple function which checks the status of an AMAL animation sequence and returns -1 (true) if it's currently active or 0 if the animation is complete. "channel" holds the number of the channel to be tested. =CHANMV (checks whether an object is still moving) s=CHANMV(channel) Returns a value of -1 if the object assigned to "channel" is currently moving, otherwise 0 (false). This command can be used in conjunction with the AMAL Move instruction to check whether a movement sequence has "run out" of steps. You can now restart the sequence at the new position with an appropriate movement string if required. Example: Load "AMOS_DATA:Sprites/Monkey_right.abk" : Get Sprite Palette Sprite 9,150,50,11 M$=Move 300,150,150; Move -300,-150,75" Amal 9,M$ : Amal On While Chanmv(9) Wend Print "Movement complete" AMAL errors =========== =AMALERR (return the position of an error) p=AMALERR Returns the position in the current animation string where an error has occurred. Careful inspection of this string will allow you to quickly correct your mistakes. Example: Load "AMOS_DATA:Sprites/Octopus.abk" Sprite 8,100,100,1 A$="L: IF X=300 then Jump L else X=X+1; Jump L" Amal 8,A$ This program will generate a syntax error because IF will be interpreted as the two instructions I and F. To find the position in the animation string of this error, type the following instruction from the direct window. Print Mid$(A$,Amalerr,Amaller+5) Error messages 196 -------------- If you make a mistake in one of your AMAL programs, AMOS will exit back to Basic with an appropriate error message. Here's a full list of the errors which can be generated by this system, along with an explanation of their most likely causes. Bank not reserved: This error is caused if you attempt to call the PLay instruction without first loading a bank containing the movement data into memory. This should be created with the AMAL accessory program. If you're not using PLay at all then check that you've correctly separated any Pause and Let instructions. Insturction only valid in Autotest: You've inadvertently called either the Direct or the eXit instructions from your main AMAL program. Illegal instruction in Autotest: Autotest may only be used in conjunction with a limited range of AMAL commands. It's not possible to move or animate our objects in any way inside an autotest. So check for erroneous commands like Move, Anim or For...Next. Jump To/Within Autotest in animation string: The commands inside an autotest function are completely separate from your main AMAL program. So AMAL does not allow you to jump directly inside an AUtotest procedure. To leave an autotest, and return to your main AMAL program you must use either eXit or Direct. Label already defined in animation string: You've attempted to define the same label twice in your AMAL program. All AMAL labels consist of just a single CAPITAL letter. So "Test" and "Total" are just different versions of the same label (T). This error is also generated if you have accidentally separated two instructions by a ":" (colon). Use a semi-colon instead. Label not defined in animation string: This error is generated when you try to jump to a label which doesn't currently exist in your animation string. Next without For in animation string: Like it's Basic equivalent each For command should be matched by a corresponding Next statement. Check any nested loops for an spurious Next command. Syntax error in animation string: You've made a typing mistake in one of your animation strings. It's easy to cause this error by accidentally entering an AMAL instruction in full, just like its Basic equivalent. Animation channels 197 ================== Amos allows you to execute up to 64 different AMAL programs simultaneously. Each program is assigned to a specific animation channel. Only the first 16 channels can be performed using interrupts. If you need to animate more objects you'll have to turn off the interrupts using SYNCHRO OFF. You can now execute the AMAL programs step by step using an explicit call to the SYNCHRO command in yur main program loop. As a default, all interrupt channels are assigned to the relevant hardware sprite. CHANNEL (assign an object to an AMAL channel) CHANNEL n TO object s The CHANNEL command assigns an animation channel to a particular screen related "object". In AMAL, you're not restricted to a single channel per object. Any single screen object can be safely animated with several channels if required. There are various different forms of this instruction. Animating a computed sprite --------------------------- CHANNEL n TO SPRITE s This assigns sprite number s to channel n. As a default, channels 0-7 are automatically allocated to the equivalent hardware sprite, and 8-15 are reserved for the appropriate computed sprites. In order to animate the computed sprites from 16 onwards, you'll need to allocate them directly to an animation channel with the CHANNEL command. As normal , sprite numbers from 8 to 63 specify a computed sprite rather than a single hardware sprite. For example; Channel 5 To Sprite 8 : Rem Animates Computed sprite 8 using Channel 5. The X,Y registers in your AMAL program now refer to the hardware coordinates of the selected sprite. Similarly the current sprite image is held in register A. Animating a blitter object -------------------------- CHANNEL n TO BOB b Allocates blitter object b to animation channel n. This object will be treated in an identical way to the equivalent hardware sprite. The only difference is that registers X and Y now contain the position of your bob in *screen* coordinates. Note that if you've activated screen switching with the DOUBLE BUFFER command, this will be automatically used for all bob animations. Moving a screen 198 --------------- AMOS Basic allows you to freely position the current screen anywhere on your TV display. Normally this is controlled with the SCREEN DISPLAY instruction. However, sometimes it's useful to be able to move the screen using interrupts. CHANNEL n TO SCREEN DISPLAY d This sets the channel n to screen number d. Screen d can be defined anywhere in your program. You'll only get an error if the screen hasn't been opened when you start your animation. The X and Y variables in AMAL now hold the position of your screen in hardware coordinates. Register A is *not* used by this option and you can't animate screens using Anim. Otherwise all standard AMAL instructions can be performed as normal. So you can easily use this system to "bounce" the picture aroud the display. Examples: Load Iff "AMOS_DATA:IFF/Frog_screen.IFF",1 Channel 0 To Screen Display 1 Amal 0,"Loop: Move 0,200,100 ; Move 0,-200,100 ; Jump Loop" Amal On 0 : Direct Load Iff "AMOS_DATA:IFF/Frog_screen.IFF",1 Channel 0 To Screen Display 1 Rem Screen can only be displayed at certain positions in the X Amal 0,"Loop: Let X=XM; Let Y=YM; Pause; Jump Loop" Amal On : Direct For a further example of this technique, load EXAMPLE 14.4. This demonstrates how the SCREEN DISPLAY can be used in conjunction with the menu commands to slide the menu screen up and down your display. It's similar to the display system found in Magnetic Scrolls' excellent series of adventures. Hardware scrolling ------------------ Although hardware scrolling can be performed using AMOS Basic's SCREEN OFFSET command, it's often easiest to animate your screens using AMAL instead as this generates a much smoother effect. CHANNEL n TO SCREEN OFFSET d This assigns AMAL program number n to a screen d, for the purpose of hardware scrolling. The X and Y registers now refer to the section of the screen which is to be displayed through your TV. Changing these registers will scroll the visible screen area around the display. Here's an example: Screen Open 0,320,500,32,lowres : Rem Open an extra tall screen Screen Display 0,,45,320,250 Load Iff "AMOS_DATA:IFF/Magic_screen.IFF" Screen copy 0,0,0,320,250 To 0,0,251 Screen 0 : Flash Off : Get Palette (0) Channel 0 to Screen Offset 0 Amal 0,"Loop: Let X=XM-128; Let Y=YM-45; Pause; Jump Loop" Amal On : Wait Key This program allows you to scroll through the screen using the mouse. Try moving the mouse in direct mode. For a further example of hardware scrolling, see EXAMPLE 14.5 Changing the screen size 199 ------------------------ CHANNEL n TO SCREEN SIZE s This allows you to change the size of a screen using AMAL. s is the number of the screen to be manipulated. Registers X and Y now control the width and height of your screen respectively. They're similar to the W and H parameters used by the SCREEN DISPLAY command. Example: Load Iff "AMOS_DATA:IFF/Magic_screen.IFF",0 Channel 0 to Screen Size 0 Screen display 0,,,320,1 : Rem set the screen size to 1 A$=Loop: For R0=0 To 255 ; Let Y=R0 ; Next R0; " A$=A$+"For R0=0 To 254; Let Y=255-R0; Next R0; J Loop" Amal 0,A$ : Amal On : Direct Rainbows -------- CHANNEL n TO RAINBOW r This option generates a rainbow effect within an AMAL program. As usual n is the number of an animation channel from 0 to 63. r is an identification number of your rainbow (0-3). X holds the current BASE of your rainbow. This is the first colour of your rainbow palette to be displayed. Changing it will make the rainbow appear to turn. Y contains the line on the screen at which the rainbow effect will start. If you alter this value, the rainbow effect will move up or down. All coordinates are measured in *hardware* format. Register A stores the height of your rainbow on the screen. See the AMOS Basic RAINBOW command fore more details. Advanced tehcniques =================== The AUTOTEST system ------------------- Normally all AMAL programs are performed in strict order from start to finish. Inevitably some commands such as Move and For...Next will take several seconds to complete. Although this will be fine in the vast majority of cases it may lead to significant delays in the running of certain programs. Take the following simple program: Load "AMOS_DATA:Sprites/Octopus.abk" : Get Sprite Palette Sprite 8,130,50,1 Amal 8,"Loop: Let R0=XM-X; Let R1=YM-Y; Move R0,R1,50; Jump Loop" Amal On : Direct As you move the mouse, the sprite is supposed to follow it around on the screen. However in practice the response time is quite sluggish, because the new values of XM and YM are only entered after the sprite movement has totally finished. Try moving the mouse in a circle. The octopus is completely fooled! Autotest solves this problem by performing your tests at the start of every VBL, before continuing with the current program. You tests now occur at regular 1/50 intervals, leading to a practically instantanous response! Autotest commands 200 ----------------- The syntax of Autotest is: AUtotest (tests) -- "tests" can consist of any of the following AMAL commands. Let reg=exp - This is the standard AMAL Let instruction. It assigns the result of an expression to register "reg". Jump label - The Jump command jumps to another part of the current autotest. "label" is defined using the colon ":" and *MUST* lie inside the autotest brackets. eXit - Leaves the autotest and re-enters the main program from the point it left off. Wait - Wait turns off the main AMAL program completely, and only executes the Autotest. If - In order to simplify the testing process inside an autotest routine there's a specially extended version of the AMAL If statement. This allows you to perform one of three actions depending on the result of the logical expression "exp". If exp Jump L (Jumps to another part of the autotest) If exp Direct L (Chooses part of the prog to be executed after AU) 201 If exp eXit (Leaves autotest) On - Restarts the main program after a previous Wait instruction. This lets you wait for a specific event such as a mouse click without wasting processor time. Direct label - Direct changes the point at which the main program will be resumed after your test. AMAL will now jump to this point automatically at the next vertical blank period. Note that label *must* be defined outside the Autotest brackets. Inside Autotest --------------- Here's the previous example rewritten using the Autotest feature Load "AMOS_DATA:Sprites/octopus.abk" Sprite 8,130,50,1 : Get Sprite Palette A$="AUtotest (If R0<>XM Jump Update" A$=A$+"If R1<>YM Jump Update else eXit" A$=A$+"Update: Let R0=XM; Let R1=YM; Direct M)" : Rem End of AU A$=A$+"M: Move R0-X,R1-Y,20 Wait;" : Rem Try changing 20 to different values! Amal 8,A$ : Amal On The sprite now smoothly follows your mouse, no matter how fast you move it. The action of this program is as follows: Every 50th of a sec the mouse coordinates are tested using the XM and YM functions. If they are unchanged since the last test, the Autotest is aborted using the eXit command. The main program now resumes precisely where it left off. However if the mouse has been moved, the autotest routine will restart the main program again from the beginning (label M) using the new coordinates in XM and YM respectively. Timing considerations --------------------- UPDATE EVERY (save some time for your Basic programs) UPDATE EVERY n Although most AMAL programs are performed practically instantaneously, any objects they manipulate need to be explicity drawn on the Amiga's screen. The amount of time required for this updating procedure is unpredictable and can vary during the course or your program. This can lead to an annoying jitter in the movement patterns of certain objects. The UPDATE EVERY command slows down the updating process so that even the largest object can be redrawn during a single screen update. This regulates the animation system and generates delightfully smooth movement effects. n is the number of vertical blank periods between each screen update. In practice you should start off with a value of two, and gradually increase it until movement is smooth. One useful side effect of UPDATE EVERY, is to reserve more time for Basic to execute your programs. With a judicious use of this instruction, it's sometimes possible to speed up your programs by as much as 30%, without destroying the smoothness of your animation sequences. Beating the 16 object limit 202 --------------------------- SYNCHRO (execute an AMAL program directly) SYNCHRO [ON/OFF] Normally AMOS Basic will allow you to execute up to 16 different AMAL programs at a time. This limit is determined by the overall speed of the Amiga's hardware. Each AMAL program takes its own slice of the available processor time. So if you're using the standard interrupt system, there's only enough time to execute around 16 separate programs. The SYNCHRO command allows you to exceed this restriction by executing your AMAL programs directly from Basic. Instead of using interrupts, all AMAL programs are now run using a single call to the SYNCHRO command. Since AMAL programs execute far faster than the equivalent Basic routines, your animations will still be delightfully smooth. But you will now able to decide when and where yur AMAL routines will be performed in your program. One additional bonus is that you can now include collision detection commands such as Bob Col or Sprite Col directly in your AMAL routines. These are not available from the interrupt system as they make use of the Amiga's blitter chip. This would be impossible using iterrupts. Before calling SYNCHRO you first need to turn off the interrupts with SYNCHRO OFF. It's imporatnt to do this *before* defining your AMAL programs, otherwise you won't be allowed to use channel numbers greater than 15 without an error. Due of the sheer power of the animation system, it's nearly possible to write entire arcade games completely in AMAL. This leaves your Basic program with simple jobs such as managing the hi-score table and loading your attack waves from the disc. The results will be indistinguishable from pure machine code. A good example is Cartoon Capers, the first commercial games release that's written entirely in AMOS. A demonstration of SYNCHRO can be found in EXAMPLE 14.6. STOS compatible animation commands ---------------------------------- The original STOS Basic included a powerful animation system which allowed you to move your sprites in quite complex patterns using interrupts. At the time, these commands were hailed as a breakthrough. Although they've now been overshadowed by the AMAL system, they do 203 provide a simple introduction to animation on the Amiga. So AMOS provides you with the entire STOS animation system as an extra bonus! If you're indenting to convert STOS programs to AMOS, you'll need to note the following points: * Unlike STOS, the movement patterns in AMOS Basic can be assigned to any animation channel you like. The Move commands can therefore be used to move bobs, sprites or screens, using exactly the same techniques. As a default, all animation channels are assigned to the equivalent hardware sprites. In practice you may find it easier to substitute blitter objects as these are much close to the standard STOS Basic sprites. Add a sequence of CHANNEL commands to start of your program like so: Channel 1 to bob 1 Channel 2 to bob 2 : : Don't forget to call DOUBLE BUFFER during your initialisation procedure, otherwise your bobs will flicker annoyingly when they're moved. * The same channel can be used for both STOS animations and AMAL programs. So it's easy to extend your programs once they've been succesfully converted into AMOS Basic. The order of execution is: AMAL MOVE X MOVE Y ANIM MOVE X (move a sprite horizontally) MOVE X n,m$ Defines a list of horizontal movements which will be subsequently performed on animation channel number n. n can range from 0 to 15 and refers to an object you have previously assigned using the CHANNEL command. m$ contains a sequence of instructions which together determine both the speed and direction of your object. These commands are enclosed between brackets and are entered using the following format: (speed,step,count) There's no limit to the number of commands you can include in a single movement string, other than the amount of available memory. "speed" sets a delay in 50ths of a second between each successive movement step. The speed can vary from 1 (very fast) to 32767 (incredibly slow). "step" specifies the number of pixels the object will be moved during each operation. If the step is positive the sprite will move to the 204 right, and if it is negative it will move left. The apparent speed of the object depends on a combination of the speed and step size. Large displacements coupled with a moderate speed will move the object quickly but jerkily across the screen. Similarly a small step size combined with a high speed will also move the object rapidly, but the motion will be much smoother. The fastest speeds can be obtained with a displacements of about 10 (or -10). "count" determines the number of times the movement will be repeated. Possible values range from 0 to 32767. A count of 0 performs the movement pattern indefinitely. In addition to the above commands, you can also add one of the following directives at the end of your movement string. The most important of these extensios is the L instruction (for loop), which jumps back to the start of the string and returns the entire sequence again from the beginning. Example: Load "AMOS_DATA:Sprits/Octopus.abk" : Get Sprite Palette Sprite 1,130,100,1 : Rem Define Sprite 5 Move X 1,"(1,5,60)(1,-5,60)L" Move On The E option allows you to stop your object when it reaches a specific point on the screen. Change the second to last line in the above example to: Move X 1,"(1,5,30)E100" Note that these end-points will only work if the x coordinate of the object exactly reaches the value you originally designated in the instruction. If this increment is badly chosen the object will leap past the end-point in a single bound, and the test will fail. Example: Load "AMOS_DATA:Sprites/Octopus.abk" : Get Sprite Palette Channel 1 To Sprite 8 : Channel 2 To Sprite 10 Print At(0,5)+"Looping OK" Sprite 8,130,100,1 Move X 1,"(1,10,30)(1,-10,30)L" Move On Print At(0,10)+"Now press a key" : Wait Key Sprite 10,140,150,2 Move X 2,"(1,15,20)L" : Move On 2 Print At(0,15)+"Oh dear!" : Wait Key MOVE Y (Move an vertical object) MOVE Y n,m$ This instruction complements the MOVE X command by enabling you to move an object vertically along the screen. As before, n refers to the number of an animation sequence you've allocated using the CHANNEL command, and ranges between 0 and 15. m$ holds a movement string in an identical format to MOVE X. Positive displacements now correspond to a downward motion, and negative values result in an upward movement. Examples: Load "AMOS_DATA:Sprites/Octopus.abk" : Get Sprite Palette 205 Channel 1 to Sprite 8 : Sprite 8,130,10,1 Move Y 1,"10(1,1,180)L" Channel 2 To Screen Display 0 Move Y 2,"(1,4,25)(1,-4,25) Move On : Wait Key MOVE ON/OFF (start/stop movements) MOVE ON/OFF [n] Before your movement patterns will be executed they need to be activated using the MOVE ON command. "n" refers to the animation sequence you wish to start, and can range from 0 to 15. If it's omitted then all your movements will be activated simultaneously. MOVE OFF has exactly the opposite effect: It stops the relecant movement sequences in their tracks. MOVE FREEZE (temporatily suspend sprite movements) MOVE FREEZE [n] The MOVE FREEZE command temporarily halts the movements of one or more objects on the screen. These objects can be restarted again using MOVE ON. "n" is completely optional and specifiew the number of a single object to be suspended by this instruction. =MOVON (return movement status) x=MOVON(n) MOVON checks whether a particular object is being moved by the MOVE X and MOVE Y instructions. It returns -1 if object n is in motion, and 0 if it's stationary. Do not confuse this with the MOVE ON command. Also note that MOVON searches for movement patterns generated using the MOVE commands, so it will not detect any animations generated by AMAL. ANIM (animate an object) ANIM n,a$ Automatically flicks an object through a sequence of images creating a smooth animation effect on the screen. These animations are performed 50 times a second using interrupts, so they can be executed simultaneously with your Basic programs. "n" is the number of the channel which specifies a sprite or bob to be animated by this instruction. "a$" contains a series of instructions which define your animation sequence. Each operation is split into two separate components enclosed between round brackets. "image" is number of the image to be displayed during each frame of 206 the animation. "delay" specifies the length of time this image will be hled on the screen (in 50ths of a sec.). Example: Load "AMOS_DATA:Sprites/Octopus.abk" : Get Sprite Palette Channel 1 to Sprite 8 : Sprite 8,200,100,1 Anim 1,"(1,10)(2,10)(3,10)(4,10)" Anim On : Wait Key Just as with the MOVE instruction, there's also an L directive which enables you to repeat your animations continuously. So just change the ANIM command in the previous example to the following: Anim 1,"(1,10)(2,10)(3,10)(4,10)L" ANIM ON/OFF (start an animation) ANIM ON/OFF [n] ANIM ON activates a series of animations which have been previously created using the ANIM command. n specifies the number of an individual animation sequence to be initialised. If it's omitted, then all current animation sequences will be started immediately. ANIM OFF [n] Halts one or more animation sequences started by ANIM ON. ANIM FREEZE (freeze an animation) ANIM FREEZE [n] Temporarily freezes the current animation sequence on the screen. n chooses a single animation sequence to be suspended. If it's not included, all current animations will be affected. They can be restarted at any time with a simple call to the ANIM ON instruction. 15: BACKGROUND GRAPHICS 207 ------------------------------ Nowadays, it's not uncommon for an arcade game to contain hunderds of different screens. With compaction, it's possible to crap a single 32 colour screen into about 30k of memory. So 100 screens would be the equivalent of about 3 Megabytes of data. Imagine how difficult this would be to fit into a standard A500! The classic way of avoiding this restriction, is to construct your backgrounds out of a set of simple building blocks. Once these "tiles" have been created, they can be placed on the screen in any order you like. So the same set of tiles can be reused to generate a vast number of potential screens. Each screen is now stored as a simple list of its components, and requires a tiny fraction of the original memory. In order to exploit this system, you'll obviously need some way of defining your various screen maps. As you might have guessed, we've helpfully provided you with a powerful map definer accessory on the AMOS program disc. Full details can be found in the accompanying documentation file. AMOS Basic also includes a number of special instructions for drawing your tiles on the screen. These make it easy to generate the fast scrolling backgrounds that are the hallmark of a modern arcade game. Icons ===== Icons are separate images which have been especially designed for producing your background screens. Once you've drawn an icon, it's fixed permanently into place. So you can't move it to a new position using the AMAL animation system. All icons are stored in their own AMOS memory bank (#2). This bank is created using the Sprite definer accessory (on the AMOS Program disk), and will be automatically saved along with your Basic programs. Like Bobs, Icons are displayed using the Amiga's amazing Blitter chip. But since Icons are essentally static objects, they are usually drawn in REPLACE mode. Your icons will therefore totally erase any existing graphics at the current screen position. PASTE ICON (draw an icon) PASTE ICON x,y,n Draws icon number n on the screen at GRAPHIC coordinates x,y. n is the number of the icon which is to be displayed. This must have been previously stored in the ICON bank. Icons can be freely positioned anywhere on the screen, subject to the normal clipping rules. Example: Load "AMOS_DATA:Icons/Map_icons.abk" Screem Open 0,320,256,32,Lowres : Cls 0 : Get Icon Palette For X=1 To 11 : Paste Icon X*32,0,1 : Next X For Y=1 To 6 : Paste Icon 0,Y*32+11 : Paste Icon 288,Y*32,1 Next Y For X=1 To 11 : Paste Icon X*32,223,1 : Next X Note that if you're using double buffering, a copy of your icons will be drawn into both the physical and logical screens. Since this is rather slow, it's common practive to add a call to AUTOBACK 0 before drawing your icons on the screen. This restricts straight to the physical screen using SCREEN COPY, saving a considerable amount of time. For a further example, see the MAPVIEW program on the AMOS DATA disc. This displays a background screen you've created using the AMOS Map Editor. GET ICON (create an icon) 208 GET ICON [s,] i,tx,ty TO bx,by Captures an image from the screen and loads it into icon "i". If this icon does not presently exist, it will be created for you in bank 2. This bank will be automatically reserved by the system if required. i is the number of your icon, starting from 1. tx,ty to bx,by define the rectangular zone which encloses the selected region. s determines the number of the screen which will be used as the source of your image. If it's omitted, the image will be taken from the current screen instead. Example: Erase 2 F$=Fsel$("*.*","","Load a screen") : If F$="" Then Direct If Exist(f$) Then Load Iff f$,0 Else Direct SH=Screen Height : H=SH/32-1 : SW=Screen Width : W=SW/32-1 For Y=0 to H For X=0 to W Get Icon X+Y*W+1,X*32,Y*32 To X*32+31,Y*32+31 Next X Next Y Cls 0 Do Paste Icon Rnd(Sw-1),Rnd(SH-1),Rnd/(H*W)+1 Loop GET ICON PALETTE (get icon colours) GET ICON PALETTE Grabs the colours of the icon images in bank 2, and loads them into the current screen palette. This command is normally used to initialize the screen after you'be loaded some icons from the disc. Example: Load "AMOS_DATA:Icons/Map_icons.abk" Get Icon Palette Paste Icon 100,100,1 DEL ICON (deletes icons) 209 DEL ICON n[ TO m] Deletes one or more icons from the icon bank. n is the number of the first icon to be removed. m is the optional number of the last icon to be deleted in the list. If it's included all the icons from first to last will be erased one after another. When the final icon in a bank has been deleted, the entire bank will be removed from memory. MAKE ICON MASK (set colour zero to transparent) MAKE ICON MASK [n] Normally, any icons you draw on the screen will completely replace the existing background. The icon will seem to be displayed in a rectangular box filled with colour zero. If you want to avoid this effect and overlay your icons directly over the current graphics, you'll need to create a *mask* for your icons. This informs AMOS that colour zero should be treated as transparent. n is the number of the icon to be affected. If it's omitted, a mask will be defined for all icons in the bank. See EXAMPLE 15.1 Screen blocks ============= AMOS Basic supplies you with a set of powerful BLOCK commands which allow you to grab part of an image into memory and paste it anywhere on the screen. These instructions are mainly used for holding temporary data, since your blocks cannot be saved along with your Basic programs. Blocks are especially effective in the construction of dialogue boxes, as they can be used to save the background areas before displaying your new graphics. They can also be exploited in puzzle games like Split Personalities. Each block can be loaded with a single section of your image. You can then jumble your pictures by rearranging the blocks on the screen with PUT BLOCK. GET BLOCK (grab a screen block into memory) GET BLOCK n,tx,ty,w,h[,mask] GET BLOCK grabs a rectangular area in block number n, starting at coordinates tx,ty. n is the number of the block ranging from 1-65535. tx, ty set the coordinates of the top left hand corner of your block. w,y hold the width and height of the block respectively. "mask" is a flag which chooses whether a mask will be created for your new block. mask=0 Replace mode. When the block is drawn on the screen, it will totally destroy any graphics at that current position. mask=1 Calculates a mask for the block. Colour zero will now be treated as if it were transparent. PUT BLOCK (copies a previously created 210 block onto the screen) PUT BLOCK n[,x,y] PUT BLOCK n,x,y,planes[,minterms] PUT BLOCK copies block number n to the current screen. x,y specify the position of your new block on the screen. If they are omitted the block will be redrawn at its original screen coordinates. Note that all drawing operations will be clipped to fit into the current screen, starting from the nearest 16 pixel boundary. For a demostration of the BLOCK commands see the routine in EXAMPLE 15.2. We've also provided experienced programmers with a couple of optional extras. These are not needed for the vast majority of applications, they're only required when you want to achieve weird special effects on the screen! "planes" holds a bit-map which sets the range of colours which will be drawn in your block. The Amiga's screen is divided up into segments known as bit-planes. Each plane contains a single bit for every point on the Amiga's screen. When the Amiga's hardware displays this point, it combines the bits from each plane to calculate the required colour number. Each bit in "planes" represents the status of a single bit-plane. If it's set to one, then the selected plane will be drawn by the instruction, otherwise it will be completely ignored. The first plane is represented by bit zero, the second by bit one, etc. Usually, the block will be displayed in all the available bit-planes. The corresponds to a bit-pattern of %111111 "minterm" selects the blitter mode used to copy your block on the screen. A full description of the possible drawing modes can be found in the section on SCREEN COPY. The best way to loearn about these options is to experiment! DEL BLOCK (delete a screen block) DEL BLOCK n Deletes one or more blocks and restores the memory used to AMOS Basic. DEL BLOCK Erases *all* current blocks DEL BLOCK n Deletes block number n. GET CBLOCK (save and compact a screen image) 211 GET BLOCK n,x,y,sx,sy The GET BLOCK command saves and compacts a rectangular area of the screen. The compaction system used by this command has been especially optimized for speed. So it's nowhere near as efficient as the dedicated AMOS compression routines provided by the PACK or SPACK instructions. CBLOCKS are often used to grab the area underneath your dialogue boxes. After the dialogue has been completed, the screen can quickly restored back to its original state. See EXAMPLE 15.3. n specifies the number of your block and can range between 1-65535. x,y are the top left coordinates. The x coordinate is rouded to the nearest multiple of 8. w,h hold the dimensios of the area to be saved. The width is always rounded to an exact multiple of 8. PUT CBLOCK (displays a block created using CBLOCK) PUT CBLOCK n [,x,y] Places block n on the current screen at coordinates x,y. If the target coordinates are omitted, the block will be redrawn at its original screen position. Also note that x is automatically rounded to the nearest eight pixel boundary. DEL CBLOCK (deletes a screen block defined with GET CBLOCK) DEL CBLOCK [n] Erases all blocks from memory. If n is present only block n will be deleted.