Blitz:Blitz Mode

From Amiga Coding
Revision as of 18:02, 15 September 2015 by Daedalus (talk | contribs) (The Slice Library)
Jump to: navigation, search

The Amiga OS is a great operating system, but with the limited power available when the Amiga was released first it made sense to bypass the OS and use the hardware directly. This disabled multitasking and took over the machine, but allowed games to run faster and with more colours without worrying about other tasks needing access to resources.

Blitz Basic / AmiBlitz can use a special mode called "Blitz Mode" which suspends the OS like this and allows full, unrestricted access to the Amiga's features by using a special set of commands. Your program can swap in and out of Blitz mode at will, but bear in mind that any OS features that rely on other tasks, e.g. intuition, file access etc. will be unavailable in Blitz mode.

Generally, freezing the OS like this is considered antisocial on a multitasking OS, so please be sure you really need to use it. Also, bear in mind that it will only work on "real" Amigas with the custom chipsets since it uses the chips directly, so using Blitz mode automatically rules your program out of working on a next-gen Amiga system.

Switching Modes

To switch to Blitz mode, the keyword Blitz is simply used. When your program reaches this command, the OS is instantly suspended and the screen will go blank. Everything the system does from this point on must be done by accessing the chips directly.

To switch back to normal mode, use the keyword Amiga. This will restore the OS to normal running mode, and Intuition will redraw the screen as it was before Blitz mode was entered. Please remember however, that even though operation is resumed, if some task was unexpectedly interrupted when Blitz mode was activated, some unexpected behavior could result. For example, writing to a file on disk could result in a corrupted file, or even a corrupted partition. For this reason, always ensure nothing else is happening when using Blitz mode. There isn't a 100% safe way of doing this, so generally it's just an idea to not use Blitz mode at all if you want your software to be used in a multitasking environment, and if you must use Blitz mode, add a small delay before entering Blitz mode to allow any disk caches to be flushed: VWait 250 BLITZ This will pause for 5 seconds (on a PAL machine; 4 seconds on an NTSC Amiga) before entering Blitz mode.

QAmiga Mode

This is a special mode that is useful when your program mostly runs in Blitz mode. It switches the Amiga back to a limited Amiga mode, keeping the Blitz display and custom chip registers intact. This allows your program to use OS functions for accessing files without reverting to the standard OS display. The Blitz display can't be updated in this mode however, instead will appear frozen until your program returns to Blitz mode.

As with other mode switch commands, simply executing the command QAmiga will enter the QAmiga mode, and executing the Blitz command will return your program to Blitz mode where it left off.

Creating a Blitz Mode Display

Blitz Basic supports two separate systems for creating displays in Blitz mode: the Slice library and the Display library. The Slice library is inherited from older versions of Blitz Basic, and supports the capabilities of the OCS/ECS chipsets only. The Display Library was introduced in Blitz Basic 2 as a replacement for the Slice library that also includes more flexibility and support for the AGA chipset. If you only need to support OCS/ECS graphics then either library can be used, however to use AGA graphics you'll have to use the Display library. Note that you can only use one library or the other - commands from the Slice library won't work with a display built using the Display library for example.

The Slice Library

Slices are Blitz mode's rough equivalent to screens in Amiga mode. Setting them up is easy with the Slice command: Slice 0, 44, 5 This simple form of the command takes just three parameters: The 0 is the Slice object ID to create. 44 is the vertical position of the slice from the start of the actual display drawing process, and 44 is a typical value to have the slice located at the top of the visible area. Finally, 5 is the number of bitplanes to use, which can be anything from 1 to 6. This example will give us a 320x256 display on a PAL Amiga, or 320x200 on an NTSC Amiga, with 32 colours available. You can add 8 to the depth to open a high res screen instead, in which case the horizontal resolution will be increased to 640.

A more comprehensive version of this command is also available, with the following template: Slice Slice#, Y, Width, Height, Flags, BitPlanes, Sprites, Colours, w1, w2 These parameters allow you to set up more specific slice parameters. Slice # and Y are the same as before - the new Slice ID and the vertical position (typically 44). Width and Height are the dimensions of the slice to create in pixels. Flags sets the properties of the slice, including screenmode and other special flags. More information is available in the Blitz manual, however these are probably the most useful flag values:

Value Slice Properties
$FFF8 Standard, low resolution
$FFF9 Standard, high resolution
$FFFA Dual playfield, low resolution
$FFFB Dual playfield, high resolution

The bitplanes parameter sets how many bitplanes you wish to use for the bitmaps you will be displaying with this slice, and can be 1 to 6. Sprites is the number of sprite channels you want to use with this slice, and should normally be set to 8 to prevent flickering caused by unused sprite channels. Colours is the total number of pens to have available in the palette for this slice, up to 32. Finally, w1 and w2 are the widths of the bitmaps you wish to display on this slice, w1 being the foreground bitmap width andw2 being the background bitmap width. If you're not using a dual-playfield display, you should set both of these values to the same number. Bitmaps larger than the screen can be displayed and scrolled around easily by setting this value to the width of the bitmap or bitmaps.

More than one slice can be created on the same display by using multiple Slice commands with unique IDs and different Y values. However, unlike screens, they can't overlap, and depending on the situation (number of colours, chipset etc.), 2 or more blank lines may be required between slices.

Like many other Blitz objects, the current slice can be set by using the command: Use Slice 0 After which slice 0 will be the currently used slice. Slices can also be freed similarly to other Blitz objects: Free Slice 0 This disposes of the slice and frees the memory taken up by it. No more operations should be carried out on a freed slice!

Displaying Bitmaps

Bitmaps can be displayed on the currently used slice by using the Show, ShowB or ShowF commands. Show is used for a standard slice: Show 0 Displays bitmap 0 on the current slice. The top left of the bitmap will be positioned at the top left of the slice. ShowB works the same way except it displays the bitmap as the background of a dual playfield slice. ShowF is again similar, except it displays the bitmap as the foreground of a dual playfield slice.

Optionally, X and Y coordinates can be provided to any of the Show commands above. If they're given, the bitmap will be shown with these coordinates at the top left of the slice instead of with 0, 0 at the top left.

The Display Library