10:SCREENS The default screen Whenever you run an AMOS Basic program a default screen is created as screen zero. This forms a standard display which will be used for all your normal drawing operations. The system defaults to a 16-colour screen with dimensions 320x200, which can easily be altered from within your program. In addition, you can also define up to seven further screen with power SCREEN OPEN command. Defining a screen SCREEN OPEN (open a screen) SCREEN OPEN n, w, h, nc, mode SCREEN OPEN opens a screen, and reserves some memory it. The new screen will now be used as the destination of all subsequent text and graphical operations in your program. n is the identification number of the screen which is to be created by this instruction. Possible values range from 0-7. If this screen already exists, it will be totally replaced by your new definition. w holds the width of the screen in pixels. This is not limited to the physical size of your display. It's perfectly lefal to define extra large screens which may be manupulated using SCREEN OFFSET. h sets the height of your screen using the same system. Providing you've enough memory, you can easily create screens which are much larger than the visible screen area. These screens can be used in conjunction with all the normal screen operations. So you can construct your images off-screen, and scroll them into view with the SCREEN OFFSET command. nc requests the number of colours required for the new screen. The range of available colours varies from 2 to 64 (EHB). You can also access the Amiga's special HAM mode with a value of 4096. "mode" allows you to choose the width of the individual points on the screen. The Amiga supports screen widths of either 320 or 640 pixels. You can select the required width by setting "mode" either LOWRES (0) or HIRES ($8000). Here's a list of the possible screen options along with an indication of the amount of memory they consume. RESOLUTIONS 2 320 x 200 8 k Paper=0 Pen=1 Crsr=1, no flash 640 x 200 16 k " " " " 4 320 x 200 16 k Paper=1 Pen=2 Crsr=3, flash=3 640 x 200 32 k " " " " 8 320 x 200 24 k " " " " 640 x 200 48 k " " " " 16 320 x 200 32 k This is a default screen 0 640 x 200 64 k 32 320 x 200 40 k 64 320 x 200 48 k Extra Half-Bright mode (EHB) 4096 320 x 200 48 k Hold and Modify mode (HAM) Note that the memory sizes in the table only apply to a standard screen. If you create taller of wider screens, the amount of memory is consumed will obviously be considerable greater. Screen zero is equivalent to: SCREEN OPEN 0,320,200,16,Lowres SCREEN CLOSE (erase a screen) SCREEN CLOSE n SCREEN CLOSE deletes screen number n, and frees the memory for use. AUTO VIEW ON/OFF (control viewing mode) AUTO VIEW OFF WHen you open a screen using SCREEN OPEN the new screen is usualyy displayed immediately. This can be very incovenient during the initialisation stages of your programs. The AUTO VIEW OFF command provides you with full control over the updating process. It turns off the automatic display system copletely. You can then update the screen display at a convenient point in your program using the VIEW instruction. AUTO VIEW ON activates automatic screen updating. DEFAULT (reset screen to its default) DEFAULT Closes all current open screens and restores the display back to its original default setting. Example: Load Iff "AMOS_DATA:IFF/Amospic.IFF",0 Wait Key Defaul VIEW (display the current screen settings) VIEW Displays any changes to the current screen settings at the next vertical blank period. You only have to use this command when AUTOVIEW is OFF. Special screen modes The colour of every point on the screen is determined by a value held in one of the Amiga's 32 colour registers. Each register can be loaded from a selection of 4096 different colours. Although 32 colours may seem rather a lot, particularly by ST standards, it wasn't enough for the Amiga's designers. The easiest solution would have been to increase the number of colour registers, but this was quickly ruled out from reasons of cost. Instead, they invented two special graphics modes which cleveroly exploited the existing registers to increase the maximum number of colours on the screen. You've propably encountered these modes already. They're the infamous Extra Half Bright and HAM modes. AMOS Basic provides full support for both HAM and Half Bright modes. Here's a brief explanation. Extra Half Bright mode (EHB) Doubles the maximum colours on the screen to a grand total of 64. It works by generating two colours for each of the 32 possible colour registers. The first 32 colours load the colour value directly from one of the registers. Each register contains a value between 0 and 4095 which sets the precise shade of the final colour. The second group of colours, with numbers from 32 to 63, take one of the previous registers and divide its contents by two. This produces 32 extra colours which are exactly half as bright as the normal colour registers. In order to exploit EHB mode to the full, it's necessary to load the 32 registers with the brightest shades in your palette. This will automatically generate a list of intermediate tones in colours 32-63. Aside from t Hold and Modigy mode (HAM) The Amiga's hardware currently limits you to a maximum of six bit planes per screen. This allows you to display up to 64 different colours on the screen at once. If you wanted to display a photograph though, you'd require hunderds or even thousands of colours on the screen. This was the problem faced by Jay Miner when he was designing the Amiga's display system. His solution was to exploit a trick which has been known by artists for centuries. If a professional aritst had to take every conceivable colour on an assignment, he would be faced with an impossible task. It's therefore common parctice to mix the exact shade on the spot, out of a small set of basic colours. This provides millions of potential shades, without the need to carry several large lorry loads worth of paint. The same technique can also be applied to a computer screen. Instead of specifying each colour individually, you can take an existing colour and modify it slightly. This increases the number of available colours tremendously, and forms the basis of the Amiga's powerfl Hold And Modify mode. Each colour value on the Amiga is created from a mixture of the three separate components. These determine the relative strength of the primary colours Red, Green and Blue in the final colour. Possible intenses range from 0 to 15. Ham mode splits the Amiga's colour values into four separate groups: * Colour registers 0-15: The first 16 colour take a value directly from a colour register. These colours are treadted just like those on a standard 16 colour screen. * Red components 16-31: However, if a point is set to a colour number in the range 16 to 31, the colour value is loaded from the pixel to its immediate left. The Red component of this colour is now replaced with a value from 0 to 15 which is calculated from the formula: Intensity=Colour index - 16  * Green components 32-47: Similarly, a colour number from 32 to 47 takes the current shade, and changes the green component. The intensity of this component is set to a value of colour - 32. * Blue components 48-63: These colour numbers grab the colour value from the point on the left of the current pixel, and load a new blue component from your colour number like so: Intensity = Colour Index - 48 The colour of a particular point therefore depends on the colours of all the points to the left of it. This allows you to create smooth gradiations of colour which are ideal for flesh tones. However, you can't choose the colour of each point on the screen independently. In practice, it takes a maximum of three pixles to shift from one colour to another. When the Amiga was first released, Ham initially was regarded as little more than curiosity. Nowadays, the situation is very different, with the advent of excellent Ham graphics packages such as Photon Paint. AMOS allows you to perform the full range text and graphics operations directly on to a Ham screen. EXAMPLE 10.1 provides you with a simple example of how you can generate an entire screen in just a few lines of Basic code. Another point to consider, is that Ham screens are manipulated using the normal SCREEN DISPLAY and SCREEN OFFSET commands. Here are some simple guidelines to their use: * The first point in each horizontal line should be set to a colour number from 0 to 15. This will serve as the starting colour for all the shades on the current line. * Don't attempt to subject your Ham screens to horizontal scrolling. If you try to scroll one of these screens, you'll get colour fringes at the sides of your picture. These are generated by the changes in the starting colours for each line. There are no such restrictions to vertical scrolling. * Fringing effects can also be produced by SCREEN COPY. The solution is to ensure that the border of your zone is drawn using a colour from 0 to 15. This will ensure that your Ham screens will be redrawn at their new position with their original colours. Loading a screen LOAD IFF (load an IFF screen from the disc) LOAD IFF "filename"[,screen] Loads an IFF format picture from the disc. "Screen" indicates the number of the screen which is to be loaded with your picture. This screen will be opened automatically for your use, if it didn't exist. Anything already inside your screen will be totally erased. To load the picture into the present screen, omit the "screen" parameter altogether. Example: Load Iff "AMOS_DATA:IFF/AMOSPIC.IFF",1 Saving a screen SAVE IFF (save an IFF scree) SAVE IFF "filename"[,compression] Saves the current screen as an IFF picture file on the disc. "compression" is a flag which allows you to choose whether your file will be compacted before it's saved. A value of one specifies that the standard file compressiong system is to be employed and zero saves the picture as it stands. As a default all AMOS screens are compressed. SAVE IFF automatically appends a small IFF "chunck" to your picture file. This stores the present screen settings including SCREEN DISPLAY, SCREEN OFFSET and SCREEN HIDE/SHOW. When you load this file back into AMOS Basic it will be returned to exactly its original condition. This extra IFF data will be completely ignored by external graphics packages such as DPaint 3. Note that it's possible to save double buffered or dual playfield screens with this command. Moving a screen SCREEN DISPLAY (position a screen) SCREEN DISPLAY n [, x, y, w, h] Once you have defined your screen with SCREEN OPEN, you'll need to position it on your screen. Unlike most other computers, the Amiga is capable of displaying a picture anywhere you like on the TV screen. This can be easily exploited to produce amazing "bouncing" screen effects. With AMOS Basic, it's even possible to perform these animations using interrupts (see AMAL). Another aplication is to overlay several screens alongside each other. This allows you to create your display out of a combination of different screen modes. "n" indicates the number of the screen to be positioned. "x" and "y" specify the location of the screen in hardware coordinates. The x coordinates of a screen can range from 0 to 448 and are automatically rounded down to the nearest 16-pixel boundary. Only the positions between 112 and 448 actually visible on your TV though, and you are strongly advised to avoid using an x coordinate below 112. The y coordinates of your screen can range between 0 and 312. The visible range will largely depend on your TV or monitor, but you'll propably find that coordinates between 30 and 300 are satisfactory for the majority of systems. At the time of writing, there appears to be a minor bug in the Amiga's HAM mode. These pictures cannot be displayed with a Y coordinate of exactly 256. So set your coordinates to intermediate values such as 255 or 257 instead. We're not sure if it's a hardware or software fault yet but it won't restrict you by any means. "w" holds the width of your screen in pixels. If this is different from the original setting, only a part of your image will be shown, starting from the top left corner of the display. Like the x coordinates, the screen width will be rounded to the nearest 16 pixel boundary. Similarly, "h" sets the apparent height of the screen. Changing this value will reduce the depth of your image. Generally SCREEN OPEN will automatically select the display position for you using a standard setting in the AMOS configuration file. If a screen is larger than the display then AMOS sets the screen into overscan. SCREEN DISPLAY provides you with a simple way of changing these values from the default. Any of the parameters x,y,h and w may be omitted as appropriate. The unused values will be automatically assigned to the default settings, and should be separated by commas. Screen Display 0,112,45,, : Rem position the screen at 112,45. When you are positioning your screens, try to ensure that the screen starts at the left of the display and ends towards the right. This is essential if the Amiga's hardware is to interpret your screen correctly. In practice, you may need to experiment a little to get the precise effect you want. Fortunately, the worst that can happen is that you'll get a silly looking display. The Amiga won't crash if you make a mistake. here are some guidelines to help you along: * Only a single screen can be displayed on each horizontal line. However, you can safely place several screens on top of each other. All will be well, providing only one of the screens visible. * There will always be a one pixel thick "dead zone" between each pair of screens. This is generated by the copper list and is completely unavoidable. The dead zone will be noticeable whenever you move a sprite between the screens. As an example, try moving the mouse pointer from the editor window to the menu line. You should see a small black line through your mouse pointer at the border between the two screens. SCREEN OFFSET (hardware scrolling) SCREEN OFFSET n,x,y The Amiga's display is not just limited to the visible dimensios of your TV screen. There's absolutely nothing stopping you from generating images which are much larger than the actual screen. It's obviously not possible to display such pictures in their entirety, but you can easily view a section of your image using the SCREEN OFFSET command. "n" is the number of the screen to be displayed. x,y measure the offset from the top left hand corner of the screen to the starting point for your display. x and y are specified in units of a single pixel, so there's nothing stopping you from generating some delightfully smooth scrolls. You can also use negative offsets with this instruction, allowing you to display any part of the Amiga's memory on the screen. See EXAMPLE 10.2 for a full demonstration of this command. Screen control commands SCREEN CLONE (clone a screen) SCREEN CLONE n The SCREEN CLONE command assigns a second version of the current screen to screen number n. This clone uses exactly the same memory area as the original screen. Normally, the cloned screen is displayed at the same place as its parent. However it can be manupulated separately using any of the normal screen operations such as SCREEN DISPLAY and SCREEN OFFSET. Since there's only a *single* copy of the original screen data in memory, you can't access a clone with the SCREEN command. You'll get an "illegal screen parameter" error if you rty. Another point to consider is that any colour flash sequences you've set up on the original screen will NOT be copied during the cloning operation. See EXAMPLE 10.3. Notice the use of the WAIT VBL command. This ensures that the clone is repositioned off-screen and keeps the movements running smoothly. If you experiment with SCREEN CLONE, you'll quickly find that there's a real limit to the amount of movement you can perform without spoiling the effect completely. Even something as trivial as an extra calculation to your movement routine can often introduce an unacceptable delay into your animations. The screen display can also be adjusted directrly from the AMAL animation language. This is capable of animating large numbers of screens smoothly and easily. See EXAMPLE 10.4 for a demonstration. DUAL PLAYFIELD (combine two screens into dual playfield) DUAL PLAYFIELD screen1, screen2 The Amiga's dual playfield mode allows you to display two complete screens simultaneously at the same x and y coordinates. It's almost as if you'd drawn eaxh screen on cellophane and overlayed them on top of each other. Each screen can be manipulated totally independently. You can exploit this to produce a smooth parallax effect which is ideal for screen scrolling games such as Silkworm. The two components of a dual playfield are treated just like any other AMOS screen and can be written to in the normal way. They can even be animated within AMAL or double buffered. "screen1" and "screen2" refer to screens which have been previously defined with the SCREEN OPEN command. Only certain screen combinations are acceptable. Both screens MUST use the same resolution, as it's illegal to use hires(meaning actually MedRes) and lowres in the same playfield. Here is a list of the possibilities Screen 1 Screen 2 Notes #of colours #of colours 2 2 4 2 4 4 8 4 LowRes only 8 8 LowRes only Although the colour ranges are predefined, the sizes of the two screens can be completely different. By creating a background screen which is larger than the foreground you can create a delightfully realistic parallax effect. The colours of these screens are all taken from the palette of screen1 with colour zero being treated as transparent. Screen Colour indexes (from screen 1) 1 0 - 7 2 8 - 15 When you are drawing to the second screen, AMOS Basic will automatically convert your colour index to the appropriate number before using it. So INK 2 will use colour nine from the first palette. This conversion process does not apply to the assignment statements such as COLOUR or PALETTE. It's important to remember this when you are changing the colour settings, otherwise your new colours will not be reflected on the actual screen. Always make "screen1" the current screen before changing your colour assignments. There are a couple of important opints which you must be aware of before setting up a dual playfield screen: * The screen offsets for both screens must never be set to zero. * If you set a dual playfield screen up and then want to position it with SCREEN OFFSET be sure to specify dual screen 1 not the second. DUAL PLAYFIELD is an extremely powerful instruction. A full demostration can be found in EXAMPLE 10.5. DUAL PRIORITY (choose order of dual playfield screens) DUAL PRIORITY screen1,screen2 The first screen of a dual playfield is normally displayed directrly over the second. The DUAL PRIORITY command allows you to change this order around so that screen2 appears in front if screen1 WARNING! This instruction only changes the order of the display. It has *NO* effect on the screen organization. The first screen in the dual playfield list should therefore still be used for all colour assignments and with SCREEN DISPLAY. SCREEN (set current screen) SCREEN n The SCREEN command allows you to direct all graphical and text operations to screen number n. =SCREEN (get the current screen #) s=SCREEN Returns the number of the currently active screen. SCREEN TO FRONT (moves screen to front of display) SCREEN TO FRONT [s] This instruction moves screen "s" to the front of the TV display. If the parameter is omitted, then the current screen will be used instead. Note: if the AUTOVIEW system has been turned off, you'll need to call the VIEW command before the effect will be visible on the screen. SCREEN TO BACK (move screen to back of display) SCREEN TO BACK [n] SCREEN TO BACK moves a screen to the background of your display. If there is another screen at the same coordinate this will now be displayed in front of the selected screen. SCREEN HIDE (temporarily hide a screen) SCREEN HIDE [n] Removes a selected screen from view copletely. This screen can be redisplayed using a call to SCREEN SHOW. If n is omitted, this instruction will hide the current screen. SCREEN SHOW (restore a screen) SCREEN SHOW [n] Screen SHOW returns a screen onto the display after it has been hidden with the SCREEN HIDE command. =SCREEN HEIGHT (return height of screen) h=SCREEN HEIGHT [n] Returns the height of an AMOS screen. If you don't include the parameter n, the height will be returned for the current screen. =SCREEN WIDTH (return the width of screen) w=SCREEN WIDTH [n] SCREEN WIDTH retrieves the width of either the current screen or screen number n. Example: Print Screen Width =SCREEN COLOUR (return the number of colours) c=SCREEN COLOUR Returns the maximum numbers of colours in the currently active screen. =SCIN (returns screen number at a selected position) s=SCIN(x,y) Returns the number of screen which is underneath the *hardware* coordinates x,y. If this screen does not exist, then s will be loaded with a negative value (null). SCIN is normally used in conjuction with the X MOUSE and Y MOUSE functions to check whether the mouse cursor has entered a particular screen. Example: Print Scin(X Mouse, Y Mouse) Defining the screen colours DEFAULT PALETTE (load screen with standard palette) DEFAULT PALETTE c1,c2,c3,,,c6,,-> up to 32 colours This command simplifies the process of opening many screens with the same palette. It defines a list of colours which will be used for all subsequent screens which you create with the SCREEN OPEN instruction. As usual, the allowable colour values range from $000 to $FFF. GET PALETTE (set the palette from a screen) GET PALETTE n [,mask] The GET PALETTE instruction copies the colours from screen n and loads them into the current screen. This can be very useful when you're moving information from one screen to another with SCREEN COPY, as it's usually vital that both the source and destination screens share the same colour settings. The optional "mask" parameter allows you to load just a selection of the colours. See GET SPRITE PALETTE for full details of mask. Clearing the screen CLS (clear the screen) CLS erases all or part of the current screen. There are three possible formats of this command: CLS Clears the current screen by filling it with colour zero and clears any windows which may have been set up. CLS col Fills your screen with colour col. CLS col,x1,y1 to x2,y2 Replaces the rectangular region at coordinates x1,y1,x2,y2 with a block of colour col. Col can take any value from 0 to the max. number of available colours. x1,y1,x2,y2 hold the coordinates for top left and bottom right corners of the area to be cleared by this command. Example: Cls : Circle 100,09,09 : Cls 1,50,50 To 150,150 Manipulating the contents of a screen SCREEN COPY (copy sections of the screen) SCREEN COPY scr1 TO scr2 SCREEN COPY scr1,x1,y1,x2,y2 TO scr2,x3,y3 [,mode] SCREEN COPY makes it possible to copy large sections of a screen from one place to another at amazing speed. "scr1" holds the screen used as the source of your image. This can be either a standard screen number or the number of a logical or physical screen generated using the LOGIC and PHYSIC commands. "scr2" selects an optional destination screen into which this data will be copied. If it's omitted, the area will be copied into the current screen. x1,y1 and x2,y2 hold the dimensios of a rectangular source area, and x3,y3 contain the coordinates of the destination. There are no limitions to these coordinates whatsoever. Any parts of your image which lie outside the current screen area will be automatically clipped as appropriate. The optional "mode" parameter chooses which of the 255 possible blitter modes will be used for your copying operation. These modes determine how your source and destination areas will be combined together on the screen. The mode is set using a bit-pattern in the following format: Mode Bit Source Bit Destination Bit 4 0 0 5 0 1 6 1 0 7 1 1 Note that the bottom four bits in the pattern are not used by this instruction and should always be set to zero. Each bit in "mode" represents a single combination of bits in the source and destination areas. If a mode bit is set to one, then the associated bit on the screen will also be loaded with a one, otherwise the result will be zero. In order to select the correct drawing mode for you application, you simply decide which combinations should result in a one and set the appropriate bits in the "mode" parameter accordingly. Supposing you only wanted to set a bit on the screen if both the source and destination bits were the same. You would look the table for the points where your requirement was satisfied. This would produce the following vaue for "mode": %10010000 If you're not familiar with binary notation, you may find this command a little opaque. Rather than boring you silly with an explanation of binay we'll now provide you with a detailed list of the more common requirements along with the associated bit-maps. Mode Effect Bit-pattern REPLACE Replaces the destination with a direct %11000000 copy of the source image (default). INVERT Replaces the destination image by a %00110000 reversed copy of the source image. AND Combines the source and destination %10000000 with a logical AND operation. OR OR's the source with the destination %11100000 image. XOR Combines the source and destination %01100000 area with an Exclusive OR. Technically-minded users should note that SCREEN COPY combines the source and destination using blitter areas B and C and that blitter area A is not used by the system at all. Scrolling the screen DEF SCROLL (define a scroll zone) DEF SCROLL n,x1,y1 to x2,y2,dx,dy Allows you to define up to 16 different scrolling zones. Each of these zones can be associated with a specific scrolling operation which is determined by the variables dx and dy. n holds the number of the zone and can range from 1 to 16. x1,y1 refer to the coordinates of the top left-hand corner of the area to be scrolled and x2,y2 to the point diagonally opposite. dx signifies the number of pixels the zone will be shifted to the right in each operation. Negative numbers indicate that the scrolling will be from right to left, and positive numbers from left to right. Similarly, dy holds the number of pixels the zone will be advanced up or down during the scroll. In this case negative values of dy are used to indicate an upward movement and positive values a downward motion. SCROLL (scroll the screen) SCROLL n The SCROLL command scrolls the screen using the settings you have specified with the DEF SCROLL instruction. n refers to the number of the zone you wish to scroll. Load Iff "AMOS_DATA:IFF/Frog_Leap.IFF",2 Def Scroll 1,0,0, to 320,200,1,0 Do Scroll 1 Loop Larger examples can be found in EXAMPLE 10.7 and EXAMPLE 10.8. The variable s holds the number of points the picture will be moved during each SCROLL. Note the use of screen switching to improve the quality of the motion. Screen switching In order to produce the smooth movement effects found in a computer game, it's necessery to complete all the drawing operations within a time span of no more than a 15th of a second. This represents a real challenge for the fastest computer, and it's often impossible to achieve even on the Amiga. If the animation is complex, your graphics will therefore tend to flicker annoyingly as they are being drawn. Fortunately, there's a solution at hand which has been succesfully exploited in the vast majority of modern arcade games. This *screen switching* technique can easily generate flicker-free screen animation using just a fraction of Amiga's computing power. The basic idea is extremely simple. Instead of constructing your images on the actual screen, you perform all your drawing operations on a separate logical screen, which is copletely invisible to the user. This is distinct from the *physical screen* which is currently being displayed on your TV. Once the graphics have been completed, you can then swap the logical and physical screen to produce a smooth transition between the two screen images. The old physical screen now becomes the new logical screen, and is used to construct the next picture in your sequence. At fist glance, this process looks pretty complicated, but it's all performed automatically by the AMOS Basic DOUBLE BUFFER command. This forces all drawing operations to be performed directly on the logical screen without affecting the current display. All you need to do within your program is to synchronise your drawing operations with the screen switches. This can be achieved with the help of SCREEN SWAP instruction. SCREEN SWAP (swap the logical and physical screens) SCREEN SWAP [n] SCREEN SWAP swaps the physical and logical screens. This enables you to instananeously switch the physical display between the two screens. If you're using DOUBLE BUFFER, these screens will have been created for you already. However, you will need to switch off the automatic screen switching system with BOB UPDATE OFF, as otherwise the screens will be swapped 50 times a second, and will interfere with your own drawing operations. It's also necessary to kill the autoback feature with AUTOBACK OFF. This normally copies your graphical operatoins onto both physical and logical screens. It's useful when you wish to combine simple graphics with moving bobs, but it destroys the effect of your screen switching operations totally. As an illustration of the power of this command, have a look at the programs EXAMPLE 10.9 and EXAMPLE 10.10. =LOGBASE (return the address of part of part of the logical screen) address=LOGBASE(plane) The LOGBASE function is aimed at expert programmers who wish to access the Amiga's screen memory directly. "plane" referes one of the six possible bit-planes which make up the current screen. After LOGBASE has been called, "address" will contain either the address of the required bit-plane, or zero if it doesn't exist. =PHYSBASE (return the address of the current screen) address=PHYBASE PHYBASE returns the address in memory of bit-plane number "plane" for the current screen. If this plane does not exist, then a value of zero will be returned by this function. Example: Loke Phybase(0),0 : Rem pokes a thin line directly onto the screen. =PHYSIC (return identifier of the physical screen) =PHYSIC =PHYSIC(s) The PHYSIC function returns an identification number for the current physical screen. This number allows you to directly access the physical image which is being displayed by the double buffering system. The result of this function can be substituted for the screen number in the ZOOM, APPEAR and SCREEN COPY commands. "s" is the number of an AMOS screen. If it's omitted, then the present screen will be used instead. Don NOT confuse with the LOGBASE function. =LOGIC (return identifier of the logical screen) =LOGIC =LOGIC(s) Returns an identification number of a logical screen. This can be used in conjunction with the SCREEN COPY, APPEAR and ZOOM commands to change your image off-screen, without affecting the current display. Screen synchronisation Like most home computers the AMIGA uses a memory-mapped display. This is a technical term for a concept you are almost certainly already familiar with. Put simply, a memory-mapped display is one which uses special hardware to convert en image stored in memory into a signal which can be displayed to your TV screen. Whenever AMOS Basic accesses the scren it does so through the medium of this screen memory. The screen display is updated by the hardware every 50th of a second. Once a screen has been drawn, the electron beam turns off and returns to the top left of the screen. This process is called the vertical blank period VBL. At the same time, AMOS Basic performs a number of important tasks, such as moving the sprites and switching the physical screen address if it has changed. The actions of instructions such as ANIM or SCREEN SWAP will therefore only be fully completed when the screen is redrawn. Since a 50th of a second is a quite long time for AMOS Basic, this can lead to a serious lack of coordination between your program and the screen, which is especially noticeable in tight program loops. The best way of avoiding this is difficulty, is to wait until the screen has been updated before you execute the next Basic command. WAIT VBL (wait for a vertical blank) The WAIT WBL instruction halts the AMIGA until ne next vertical blank period. It is commonly used after either a PUT BOB insturction or a SCREEN SWAP Special effects APPEAR (fade between two pictures) APPEAR source TO destination, effect [,pixels] The APPEAR command enables you to produce fancy fades between the "source" and "destination" screens. Source and destination are simply the numbers of screens you've previously opened using SCREEN OPEN. You can also substitute the LOGIC and PHYSIC functions in these positions if required. "effect" determines the type of fade which will be produced by this insturction. The size of this parameter can vary from 1 to the number of pixels in you current screen. "pixels" specifies the number of points which are to affected. Normally this value is set to the TOTAL screen area, but you can reduce it to fade only a part of the screen. All screens are drawn in strict order from the top of the screen to the bottom. The appearance of your fades will naturally vary depending on the screen mode you are using. A program is provided in EXAMPLE 10.11 to allow you to experiment with the various possibilities. FADE (blend one or more colours to new colour values) FADE speed [,colour list] FADE speed TO screen [,mask] The FADE command allows you to smoothly change the entire palette from one set of colours to another. This can be used to generate professional-looking fade effects for your loading screens. The standard version of the instruction takes the current palette, and slowly dissolves the screen colours to zero. Each colour value is successively reduced by one until they reach zero. Example: Fade 15 : Wait 225 "speed" is the number of vertical blank periods that must occur before the next colour change is performed. Since the fadig effects are executed using interrupts, it's best to wait until the operation has completely finished before proceeding to the nexy Basic instruction. The time taken for the fade WAIT can be calculated by the formula: wait value = fade speed * 15 Fade can be extended to generate a new palette directly from a list of colour values. Fade 15,$100,$200,$200,$300 Any number of colours can be specified in this instruction, up to the maximum allowed in the current graphics mode. Like most AMOS commands, it's possible to omit selected parameters completely. These colours will be totally unaffected fy the FADE command. Fade 15,,$100,$800,$F00 The most powerful form of FADE smoothly transforms the colours from the current screen into a palette taken from an existing screen. Fade speed TO s [,mask] The present colours are slowly converted into the palette of screen s. It's also possible to load the palette from the sprite bank using the same technique. Simply use a negative value for the screen number s. "mask" is a bit-pattern which specifies which colours should be loaded. Each colour is associated with a single bit in this pattern numbered from 0 to 15. If a bit is set to 1, then the relevant colour will be changed. See EXAMPLE 10.12. FLASH (set flashing colour sequence) This command gives you the ability to periodically change the colour assigned to any colour index. It does this with an interrupt similar to that used by the sprite and the music instructions. The format of the flash instruction is: FLASH index,"(colour,delay)(colour,delay)(colour,delay)..." "index" is the number of the colour which is to be animated. Delay is set in units of a 50th of a second. Colour is stored in the standard RGB format (See COLOUR) for mode details. The action of FLASH is to take each new colour from the list in turn, and then load it into the index for a length of time specified by the delay. When the end of this list is reached, the entire sequence of colours is repeated from the start. Note that you are only allows to use a max. of 16 colour changes in any one FLASH instruction. Here is a small example: Flash 1,"(007,10)(000,10)" This alternates colour number 1 between blue and black every 10/50th of a second. FLASH OFF Turns off the flashing. Note that on start-up, colour number 3 is automatically assigned a flash sequence for use by the cursor. It's a good idea to turn this off before loading any pictures from the disc. SHIFT UP (colour rotation) SHIFT UP delay,first,last,flag The SHIFT UP command rotates the values held in the colour registers from the "first" to "last". The "first" colour in the list is copied into the second, and the second into the third, and so on, until the "last" colour in the series is reached. Each AMOS screen can have its own unique set of colour animations. Colour shifts can be used to create amazing hyperspace sequences similar to those found in Captain Blood and Elite. Since these animations are performed using interrupts, they can be executed while your program is running, without affecting it in the slightest. "delay" is the time interval between each stage of the rotation, measured in 50ths of a second. "flag" controls the type of rotation. If it's ste to one, the last colour index in the list will be copied into the first, and the first to the last. So the colours will rotate continuously on the screen. When "flag" is set to zero, the contents of the first and last indexes will be discarded, and the region between first and last will be replaced by a copy of the first colour in the list. For example: SHIFT UP 100,1,15,1 SHIFT UP 10,1,15,0 SHIFT DOWN (colour rotation) This is similar to the SHIFT UP, except it rotates the colours in the opposite direction. SHIFT OFF (stops col.rotation for the current screen) SHIFT OFF Immediately terminates all colour rotations produced by the SHIFT UP or SHIFT DOWN instructions SET RAINBOW (define a rainbow effect) Defines an attractive rainbow effect which can be subsequently displayed using the RAINBOW command. It works by changing the shade of a colour according to a series of simple rules. "n" is the number of your rainbow. Possible values range from 0 to 3. "colour" is a colour index which will be changed by the instruction. This colour can be assigned a different value for each horizonal sreen line (or scan line). Note that only colours 0-15 can be manipulated using this system. "length" sets the size of table to store your colours. There's one entry in this table for each colour value on the screen. The size of this table can range from 16 to 54400. If "length" is less than the physical height of your rainbow, then the colour pattern will be repeated several times on the screen. The r$,g$,b$ command strings, progressibely change the intensities of the red, green and blue components of your final colour. These values are loaded into a special colour table. Each colour in the table determines the appearance of a single horizontal scan line on the screen. At the start of the rainbow, all the components in your colour are initially loaded with a value of zero. This will be changed according to the information held in the colour table. Any command string may be omitted if required, but you'll still have to include the quotes and the commas in their expected positions. Each string can contain a whole list of commands. These will be cycled continually to produce the final rainbow pattern. The format is: (n,step,count) "n" sets the number of lintes to be assigned to a specific colour value in the rainbow. Increasing this number will change the height of each individual rainbow line. "step" holds a number to be added to the component. This number will be used to generate the colour of the succeeding line on the screen. A positive step will increase the intensity of colour component, and a negative value will reduce it. Whenever a particular component exceeds the maximum of 15, a new value will be calculated from the formula: new component = old component Mod 15 "count" is the number of times the current operation is to be repeated. The best way to demonstrate this command is with an example: Set Rainbow 0,1,64,"(8,2,8)","","" Rainbow 0,56,1,255 Wait Key This creates a new rainbow with number zero using colour index one. As you can see, SET RAINBOW only defines your rainbow. In order to display it on the screen you need to make use of the RAINBOW command. The rainbow effects first loads your colour with a value of zero. Every four scan-lines, the red component will be automatically incremented by two. So the contents of colour zero will progressively change from $000 to $E00. WHen the component exceeds the maximum of 15, its remainder will be calculated, and the colour will be returned to its starting point (zero). The pattern will now be repeated down the screen. By defining a separate pattern for eaxh of the red, green and blue components of your colour, you can easily generate some starling patterns on the screen. Since each rainbow only uses a single colour index, there's nothing stopping you from creating the same effects using just two colour screens. These are ideal from the backgrounds of an arcade game, as they consume very little memory. Example: Screen Open 0,320,256,2,Lowres Set Rainbow 0,1,128,"8,1,8)","(8,1,8)","" Rainbow 0,1,30,128 Colour 1,0 : Curs Off : Cls 1 : Flash Off Locate 0,2 : Centre "Amos Basic" : Wait Key For further demonstration of the superb effects that can be achieved with this instruction load up EXAMPLE 10.13. Rainbows can also be animated using a powerful interrupt system. See the section on AMAL for more details. RAINBOW (create a rainbow effect) RAINBOW n,base,y,h Displays rainbow number n on the screen. If AUTOVIEW is set to OFF, the rainbow will only appear when you next call the VIEW command. "base" is an offset in the first colour in the table you created with SET RAINBOW. Changing this value will cycle the rainbow on the screen. y holds the vertical position of the rainbow in hardware coordinates. The minimum calue for this coordinate is 40. If you attempt to use a coordinate below this point, the rainbow will be displayed from line 40 onwards. h sets the height of your rainbow scan lines. Rainbows are totally compatible with the AMOS system including bobs and sprits. However, don't attempt to rainbow a colour which is currently being changed using the FLASH or SHIFT instructions, as this will lead to unpredictable screen effects. Note that only a single rainbow effect can be displayed on a particular scan line, even if they use different colours on the screen. Normally the rainbow with the highest screen position will be displayed first. But if several rainbows start from the same scan line, then the rainbow with the lowest identification number will be drawn in front of the others. =RAIN (change the colour of an individual rainbow line) RAIN(n,line)=c c=RAIN(n,line) This is the most powerful of all the rainbow creation commands, as it allows to change the colour of an individual rainbow line to any value you like. n is the number of the rainbow you wish to access. "line" is the individual scan line to be changed. Example: Curs Off : Centre "Securitate Stinks!" Set Rainbow 1,1,4097,"","","" For Y=0 To 4095 Rain(1,Y)=Y Next Y For C=0 to 4095-255 Rainbow 1,C,40,255 Next C Wait Key ZOOM (magnify a section of the screen) ZOOM source,x1,y1,x2,y2 TO dest,x3,y3,x4,y4 ZOOM is a simple instruction which allows you to change the size of any rectangular region of the screen. "source" is the number of a screen from which your picture will be taken. You can also use the LOGIC function to grab your image from the appropriate logical screen. The rectangular area to be affected by this instruction is entered using the coordinates x1,y1,x2,y2. "dest" holds the destination screen for your image. Like the source, it can be either a screen number, or a logical screen specified using LOGIC. The dimensios of this screen are taken from the cordinates x3,y3 and x4,y4. These hold the dimensios of the rectangle into which the screen segment will be compressed. The effect of this instruction depends on the relative sizes of the source and destination rectanges. The source image is automatically resized to fit exactly into the destination rectangle. So the same instruction can be used to reduce or enlarge your images as required. See EXAMPLE 10.14 for a further demonstration. Changing the copper list The Amiga's co-processor (copper) provides total control over the appearance of every line on your screen. This copper is a separate processor with its own internal memory and unique set of instructions. By programming the copper it's possible to freely generate a massive variety of different screen effects. Normally the copper is managed automatically by the AMOS system. Each of the available copper effects can be performed directly from within AMOS Basic without the need to indulge in complicated machine-level programming. In practive these intructions will be more than sufficient for the vast majority of applications. Obviously, no one can think of everything though. Expert programmers may wish to access the copper directly to create their own special screen modes. Be warned: The copper list is notoriously difficult to program, and if you don't know precisely what you are doing, you'll almost certainly crash your Amiga. Before embarking on your copper experiments for the first time, you are therefore adviced to read one of the many reference books on the subject. A good explanation can be found the "Amiga System Programmers Guite" from Abacus. COPPER OFF (turn of the standard copper list) COPPER OFF Freezes the current AMOS copper list and turns off the screen display copletely. You can now create your own display using a series of COP MOVE and COP WAIT instructions. As a default, all user-defined copper lists are limited to a maximum of 12k. On average, each copper instruction takes up two bytes. So there's a space for around 6000 instructions. This may be increased if required, using a special option from the CONFIG utility. Note that all copper instructions are written to a separate logical list which is not displayed on the screen. This stops your program corrupting the display while the copper list is being created. To activate your new screen, you'll need to swap the physical and logical lists around with the COP SWAP command. It's also important to generate your copper lists in strict order, starting from the top left of your screen and progressing downward to the bottom right. See EXAMPLE 10.15. COPPER ON (restart the copper list) COPPER ON Restarts the AMOS copper list calculations and displays the current AMOS screens. COP MOVE (write a MOVE instruction into the logical copper list) COP MOVE addr,value Generates a MOVE instruction in the logical copper list. "addr" is an address of a 16 bit register to be changed. This must lie within the normal copper DATA ZONE ($7F-$1BE). "value" is a word-sized integer to be loaded into the requested register. COP MOVEL (write a long MOVE instruction into copper list) COP MOVEL addr,value This is identical to the COP MOVE, except that "addr" now refers to a 32-bit copper register. "value" contains a long word intereger. COP WAIT (copper WAIT instruction) COP WAIT x,y [,x mask, y mask] COP WAIT writes a WAIT instruction into your copper list. The copper waits until the hardware coordinates x,y have been reached and returns control to the main processor. Note that line 255 is automatically managed by AMOS. So you don't have to worry about it at all. x mask and y mask are bit maps which allow you to wait until just a certain combination of bits in the screen coordinates have been set. As a default both masks are automatically assignet to $1FF. COP RESET (reset copper list pointers) COP RESET Restores the address used by the next copper instruction to the start of the copper list. =COP LOGIC (address of copper list) addr=COP LOGIC This function returns the absolute address in memory of the logical copper list. This allows you to poke your COPPER instructions directly into the buffer, possibly using assembly language. Hints and tips * Before creating a screen with a user defined copper list, you'll first need to allocate some memory for the appropriate bit-maps. Although you can use RESERVE for this purpose, it's much easier to define a dummy screen with the SCREEN OPEN command instead. The copper registers can be loaded with the addresses of the required bit-maps using the LOGBASE function. You'll now be able to access your screen using all the standard AMOS drawing features. In order to reserve the correct amount of memory, set the number of colours to the MAXIMUM used in the new screen. This may be a little wasteful, but simplifies things enormously. * It's perfectly acceptable to combine user-defined screens with AMOS bobs. If you're using double buffering though, you'll have to define a separate copper list for both the logical and physical screens. This may be achieved using the following procedure; 1 Define your copper list for the first screen 2 Swap the logical and physical copper lists with COP SWAP 3 Swap the physical and logical screens with SCREEN SWAP 4 Define your copper list for the second screen This will ensure that your bobs will updated correctly on your new screens. All the normal AMOS commands can be used including AMAL.