/* OnePlane.c - program to steal bottom bitplane from workbench screen Ethan Dicks (c) 15-Nov-1988 Version 1.1 (c) 14-Dec-1988 Version 1.2 (c) 24-Feb-1989 Version 1.3 (c) 26-Feb-1990 This program is *not* in the public domain, but may be freely redistributed on the condition that it is not sold, nor used in any commercial or shareware package without the express written permission of the author. This program may be included in a freely redistributable library, including, but not limited to the Fred Fish library collection. In other words, selling this program is right out, but giving it away is encouraged. I got the encouragement for this program from the discussion on comp.sys.amiga regarding fast text scrolling. Someone called for a program to reduce the Workbench screen to 1 bitplane to enhance the speed of CON: output. COMPILATION INSTUCTIONS: This code will compile under either Lattice C, V4.01, V5.00, or V5.02, although V5.0x will produce a 28 byte smaller executable. Currently, Lattice V4.01 produces a 468 byte executable, V5.00 produces a 440 byte executable. With some minor code changes, this program now weighs in at 256 bytes, if compiled under V5.02. Who says C has to be bloated! Now, as of V1.3 on 26-Feb-90, with better compilation switches, this code compiles to xxx bytes under Lattice 5.04! To compile, either use LMK and the provided Makefile or use the commands: lc -b -r -v -y oneplane.c blink oneplane.o SC SD ND This is why some of the structure looks odd; I don't link with any external files, not even startup code. I know that the program could be made even smaller, but what do want for a one night's hack? (With a few minor touchups) HOW IT WORKS: In the structure GfxBase, there is a field, ActView, which describes the current ViewPort. This program uses the active viewport information to aquire the active BitPlane structure, which contains information about how many bitplanes are in use, their location in memory, the number of rows in the bitplane, and the number of bytes in each row. With this information, is it trival to change the number of bitplanes down by one, and to free up the memory held by the highest bitplane. The request is checked in case this is the only bitplane allocated. The advantage of this system is that the number of bitplanes can be increased and decreased at will, without fear of a visit from the GURU. Most of the information I got came from the RKM graphic primitives section, in the Libraries and Devices volume, especially the examples, and most of the rest came from picking apart the include files. */ #include #include #include #include #include #include #include #define MIN_DEPTH 1 #pragma libcall ExecBase FreeMem d2 0902 #pragma libcall IntuitionBase RemakeDisplay 180 00 #pragma libcall ExecBase CloseLibrary 19e 901 #pragma libcall ExecBase OpenLibrary 228 0902 /* Here goes nuthin' */ void main() { /* Set up structure pointers to make Intuition happy */ register struct GfxBase *GfxBase; register struct IntuitionBase *IntuitionBase; struct ExecBase **SysBase; register struct ExecBase *ExecBase; /* Keep the pointer to the current BitMap structure in a register for faster access and smaller code */ register struct BitMap *b; /* pointer to current BitMap */ /* Set the ExecBase pointer manually, since we do not link with anybody */ SysBase = (struct ExecBase **)(4L); ExecBase = *SysBase; /* Open the graphics.library and the intuition.library */ /* error checking not done, because if they won't open, the system is hosed */ GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0); IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0); /* Here goes with the pointer game... the idea is to end up at the BitMap */ b = GfxBase -> ActiView -> ViewPort -> RasInfo -> BitMap; /* And here is where we fiddle with the numbers */ /* ---> ONLY DO THIS IF THERE ARE BITPLANES LEFT TO REMOVE <--- */ if ( (b -> Depth) > MIN_DEPTH) { FreeMem( (b -> Planes)[--(b -> Depth)], (b-> Rows) * (b -> BytesPerRow) ); } /* Now that we are done fiddling with it, redraw the display */ RemakeDisplay(); /* Now clean up and go home */ CloseLibrary((struct Library *)GfxBase); CloseLibrary((struct Library *)IntuitionBase); }