home *** CD-ROM | disk | FTP | other *** search
- { SPX Library Version 1.0 Copyright 1993 Scott D. Ramsay }
-
- SPX_VGA is the main graphics kernel. All the graphic primitives
- are here.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure MatteVsp(var from,too);
-
- Create a matte for a sprite file. Uses the SET thdmat to determine
- which colors will be transparent.
-
- FROM: Sprite to convert;
- TOO: Created masked sprite
-
- NOTE: The buffer "too" must be pre-allocated.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure VSinc;
-
- Waits for a vertical retrace to occur.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure SetDefaultColors;
-
- Sets the VGA palette to the default SPX library colors.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Switch(var a,b:integer);
-
- Exchanges the values of A and B.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Parse(var x,y:integer);
-
- Clips the point (x,y). to the legal range.
-
- X: Column coordinate 0..319;
- Y: Row coordinate 0..199
-
- ───────────────────────────────────────────────────────────────────────────
- function BuffSize(x,y:integer):word;
-
- Returns the size of the buffer needed for a sprite size of (x,y).
-
- X: Width of the sprite;
- Y: Height of the sprite
-
- ───────────────────────────────────────────────────────────────────────────
- function ImageSize(var image):word;
-
- Returns the size of the memory used by the sprite.
-
- IMAGE: Sprite
-
- ───────────────────────────────────────────────────────────────────────────
- procedure ImageDims(var image;var x,y:integer);
-
- Returns the width and height of a sprite.
-
- IMAGE: Sprite;
- X: Width of the sprite;
- Y: Height of the sprite
-
- ───────────────────────────────────────────────────────────────────────────
- procedure SetPtr(var i:PtrRec;var buff);
-
- Returns a PtrRec (Segment:offset) of a given buffer.
-
- I: Returning record;
- BUFF: Any memory buffer or variable
-
- ───────────────────────────────────────────────────────────────────────────
- function pt(x,y:integer):word;
-
- Returns the offset of the location (x,y).
-
- X: Column position;
- Y: Row position
-
- ───────────────────────────────────────────────────────────────────────────
- procedure OpenMode(npages:byte);
-
- Sets the VGA to 320x200x256 mode and allocates virtual pages.
-
- NPAGES: Number of pages to use
-
- NOTE: Page 1 is always the visual page. Pages 2..n are created
- dynamically on the heap.
-
- ───────────────────────────────────────────────────────────────────────────
- function Point(x,y:integer;pg:byte):byte;
-
- Returns the color value of a location on a page.
-
- X: Column position;
- Y: Row position;
- PG: Page to retrieve the color
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Pset(x,y:integer;n:byte);
-
- Draw a point onto the active page.
-
- X: Column position;
- Y: Row position;
- n: Color
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fPcopy(var from,too);
-
- Copies one page to another.
-
- FROM: Buffer location of the source page;
- TOO: Buffer location of the destination page
-
- NOTE: If 386 or later processor is present, 386 copies will be used.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Pcopy(from,too:byte);
-
- Same as fPcopy, copies only predefined virtual pages.
-
- FROM: Page number of the source page;
- TOO: Page number of the destination page
-
- ───────────────────────────────────────────────────────────────────────────
- procedure CopyRect(x1,y1,x2,y2:integer;var from,too);
-
- Copy a rectangular region from one page to another.
-
- X1,Y1: Top-left coordinate of the region;
- X2,Y2: Bottom-right coordinate of the region;
- FROM: Buffer location of the source page;
- TOO: Buffer location of the destination page
-
- EXAMPLE:
-
- CopyRect(100,100,200,140,pages[2]^,pages[1]^);
-
- Copies a region on page 2 to the visual page.
-
- NOTE: If 386 or later processor is present, 386 copies wiil be used.
- Unpredictable results will happen if the source and destination page
- are the same.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fwCopyRect(x1,y1,x2,y2:integer;var from,too);
-
- Same as CopyRect. Forces even amount width moves.
-
- X1,Y1: Top-left coordinate of the region;
- X2,Y2: Bottom-right coordinate of the region;
- FROM: Buffer location of the source page;
- TOO: Buffer location of the destination page
-
- NOTE: Make sure that (X2-X1+1) is an even number. Unpredictable results
- will happen if the source and destination page are the same.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure SwapRect(x1,y1,x2,y2:integer;from,too:byte);
-
- Exchange regions from two pages.
-
- X1,Y1: Top-left coordinate of the region;
- X2,Y2: Bottom-right coordinate of the region;
- FROM: Page number of the source page;
- TOO: Page number of the destination page
-
- NOTE: Unpredictable results will happen if the source and destination
- page are the same.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Line_clip(x1,y1,x2,y2:integer;n:byte);
-
- Draws a line on the active page. Clips the line according to
- WinMinX, WinMinY, WinMaxX, WinMaxY.
-
- X1,Y1: Coordinate one of the line;
- X2,Y2: Coordinate two of the line;
- n: Color of line
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Line(x1,y1,x2,y2:integer;n:byte);
-
- Draw a line on the active page. DOES NOT preform any clipping. Faster
- than the Line_clip procedure.
-
- X1,Y1: Coordinate one of the line;
- X2,Y2: Coordinate two of the line;
- n: Color of line
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Bar(x1,y1,x2,y2:integer;n:byte);
-
- Draws a filled rectangle on the active page.
-
- X1,Y1: Coordinate one of the bar;
- X2,Y2: Coordinate two of the bar;
- n: Color of bar
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Rectangle(x1,y1,x2,y2:integer;n:byte);
-
- Draws a rectangle on the active page.
-
- X1,Y1: Coordinate one of the rectangle;
- X2,Y2: Coordinate two of the rectangle;
- n: Color of bar
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Circle(x1,y1,r:integer;n:byte);
-
- Draws a circle on the active page.
-
- X1,Y1: Center coordinate of the circle;
- R: Radius of the circle;
- N: Color of circle
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Ellipse(xc,yc,a0,b0:integer;c:byte);
-
- Draws an ellipse on the active page.
-
- XC,YC: Center coordinate of the ellipse;
- A0: Height radius of ellipse;
- B0: Width radius of ellipse;
- C: Color of ellipse
-
- ───────────────────────────────────────────────────────────────────────────
- procedure ftput(x,y:integer;var buff;center:boolean);
-
- Displays a sprite on the active page with color 0 as a transparent
- color. Does NOT preform any clipping.
-
- X,Y: Coordinate to display top-left of sprite. If CENTER is TRUE
- X,Y is the coordinate of the center of the sprite;
- BUFF: Sprite;
- CENTER: Set to TRUE to display sprite centered on X,Y
-
- ───────────────────────────────────────────────────────────────────────────
- procedure ftput_clip(x,y:integer;var buff;center:boolean);
-
- Displays a sprite on the active page with color 0 as a transparent
- color. Clips the sprite according to WinMinX, WinMinY, WinMaxX, WinMaxY.
-
- X,Y: Coordinate to place top-left of sprite. If CENTER is TRUE
- X,Y is the coordinate of the center of the sprite;
- BUFF: Sprite;
- CENTER: Set to TRUE to display sprite centered on X,Y
-
- ───────────────────────────────────────────────────────────────────────────
- procedure cls(b:byte);
-
- Clears the active page.
-
- B: The color to clear the active page
-
- ───────────────────────────────────────────────────────────────────────────
- procedure CloseMode;
-
- Restores the video mode and deallocates virtual pages.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fget(x1,y1,x2,y2:integer;var image);
-
- Grabs a sprite from the active page.
-
- X1,Y1: Coordinate one of the region;
- X2,Y2: Coordinate two of the region;
- IMAGE: Sprite to create
-
- NOTE: IMAGE must be pre-allocated
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fput(x1,y1:integer;var image;center:boolean);
-
- Displays a sprite on the active page.
-
- X1,Y1: Coordinate to place top-left of sprite. If CENTER is TRUE
- X1,Y1 is the coordinate of the center of the sprite;
- IMAGE: Sprite;
- CENTER: Set to TRUE to display sprite centered on X1,Y1
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fput_mask(x1,y1:integer;var image;rmw:byte);
-
- Displays a sprite on the active page.
-
- X1,Y1: Coordinate to place top-left of sprite.
- IMAGE: Sprite;
- RMW: Type of display method
-
- CopyPut : Use normal copy. (fput recommened instead)
- XORPut : XOR the sprite with the active display
- OrPut : OR the sprite with the active display
- AndPut : AND the sprite with the active display
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fput_clip(x,y:integer;var buff;center:boolean);
-
- Displays a sprite on the active page. Clips the sprite according
- to WinMinX, WinMinY, WinMaxX, WinMaxY.
-
- X,Y: Coordinate to place top-left of sprite. If CENTER is TRUE
- X,Y is the coordinate of the center of the sprite;
- buff: Sprite;
- CENTER: Set to TRUE to display sprite centered on X,Y
-
- ───────────────────────────────────────────────────────────────────────────
- procedure SetPageActive(page:byte);
-
- Changes the active page.
-
- PAGE: New page number to become active.
-
- NOTE: If allocated memory for virtual page. Use SCNSEG:SCNOFS to
- change the active page.
-
- EXAMPLE:
- var
- MyVirt : pointer;
- .
- .
- .
-
- Getmem(MyVirt,64000); { Allocate a virtual page }
- SetPageActive(1); { Sets the active page to page 1 }
-
- SCNSEG := seg(MyVirt^); { Sets the active page to MyVirt }
- SCNOFS := ofs(MyVirt^);
-
- ───────────────────────────────────────────────────────────────────────────
- procedure GetColor(num:byte;var red,green,blue:byte);
-
- Retrieves a color from the current palette.
-
- NUM: Color number;
- RED: Red componet of the color;
- GREEN: Green componet of the color;
- BLUE: Blue componet of the color
-
- ───────────────────────────────────────────────────────────────────────────
- procedure SetColor(num,red,green,blue:byte);
-
- Sets a color of the current palette.
-
- NUM: Color number;
- RED: Red componet of the color;
- GREEN: Green componet of the color;
- BLUE: Blue componet of the color
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fSetColors(var colors);
-
- Sets all the colors of the current palette.
-
- COLORS: A buffer which contains a red, green and blue componet for
- each of the 256 colors
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fGetColors(var colors);
-
- Retrieves all the colors from the current palette.
-
- COLORS: A buffer which will contain a red, green and blue componet for
- each of the 256 colors
-
- NOTE: Can be used repeatedly for custom fades. (Does not flicker)
-
- ───────────────────────────────────────────────────────────────────────────
- procedure FadeIn(steps:word;var color);
-
- Fade the screen from black to the palette specified.
-
- STEPS: Speed of the fade;
- COLOR: Final palette after the fade
-
- ───────────────────────────────────────────────────────────────────────────
- procedure FadeOut(steps:word;var color);
-
- Fade the screen from palette specified to black.
-
- STEPS: Speed of the fade;
- COLOR: Palette before the fade, (Usually is the current palette)
-
- EXAMPLE:
-
- var
- Apal : RGBlist;
-
- fgetcolors(Apal); { grab the current palette }
- FadeOut(30,Apal); { Fade the screen to black }
-
- ───────────────────────────────────────────────────────────────────────────
- procedure ColorsChange(var color:rgblist;filter:rgbtype);
-
- Change the color palette using a color filter.
-
- COLOR: Palette to change;
- FILTER: Red, green, blue componets of the filter
-
- EXAMPLE:
-
- TanFilter : RGBtype;
- Apal : RBGlist;
-
- TanFilter.red := 63;
- TanFilter.green := 30;
- TanFilter.blue := 13;
- fgetcolors(Apal); { grab the current palette }
- ChangeColors(Apal,TanFilter);
- fsetcolors(Apal); { change the palette to tan screen }
-
- ───────────────────────────────────────────────────────────────────────────
- procedure ColorCycle(var colors:rgblist;start:byte;count:integer;fwd:boolean);
-
- Cycles a range of colors one step forward or backwards.
-
- COLORS: Palette to change;
- START: Starting color index;
- COUNT: Number of colors to rotate;
- FWD: Set to TRUE to cycle forward
-
- EXAMPLE:
-
- var
- Apal : RGBlist;
-
- fgetcolors(Apal);
- repeat
- ColorCycle(Apal,0,256,true); { Cycle the entire palette }
- fsetcolors(Apal); { using fsetcolors to set the palette }
- until crt.Keypressed; { until a key is pressed }
-
- ───────────────────────────────────────────────────────────────────────────
- function LoadColors(filename:string;var colors;count:integer):integer;
-
- Load a color palette from disk.
-
- FILENAME: Palette dos file name;
- COLORS: Buffer to store the palette;
- COUNT: Number of color entries to load. "256 to load the entire palette"
-
- ───────────────────────────────────────────────────────────────────────────
- function SaveColors(filename:string;var colors;count:integer):integer;
-
- Save a color palette to disk.
-
- FILENAME: Palette dos file name;
- COLORS: Palette to save;
- COUNT: Number of color entries to load. "256 to load the entire palette"
-
- ───────────────────────────────────────────────────────────────────────────
- procedure Paint(x,y:integer;n:byte);
-
- Flood fills a region.
-
- X,Y: The location to start filling;
- N: The color to fill
-
- NOTE: This procedure does not use the a border algorthim. It fills
- the area with color (n) that has the occurances of the color at
- location (X,Y)
-
- ───────────────────────────────────────────────────────────────────────────
- procedure CopyTo(x1,y1,x2,y2,x,y:integer;var from,too);
-
- Copies a region to another area.
-
- X1,Y1: Top-left coordinate of the source region;
- X2,Y2: Bottom-right coordinate of the source region;
- X,Y: Top-left coordinate of the destination region;
- FROM: Buffer location of the source page;
- TOO: Buffer location of the destination page
-
- NOTE: Unpredictable results will happen if the source and destination page
- are the same and the region overlapps.
-
- ───────────────────────────────────────────────────────────────────────────
- function LoadVSP(fn:string;var buff):integer;
-
- Load a sprite file.
-
- FN: DOS file name of the .VSP file;
- BUFF: An array of pointer to hold the sprites
-
- NOTE: Buff MUST be a pointer, or an array of pointer. And they can NOT
- be preallocated. Does not check the array is smaller that the number
- of sprites in the file. Returns the number of sprites loaded.
-
- EXAMPLE:
-
- var
- asprite : pointer;
- sprites : array[0..19] of pointer;
- moresp : array[0..20] of pointer;
-
- { below are legal statements }
-
- loadvsp('onevsp.vsp',asprite);
- loadvsp('20vsps.vsp',sprites);
- loadvsp('onevsp.vsp',moresp[10]);
-
- ───────────────────────────────────────────────────────────────────────────
- function FileVSP(var fil:file;var buff;size:longint):integer;
-
- Loads sprites from an open file.
-
- FIL: Binary file that contains sprites;
- BUFF: An array of pointer to hold the sprites;
- SIZE: Size of the sprites in the area.
-
- NOTE: Does not close the file. Returns the number of sprites loaded.
- Be sure that SIZE corresponds to the exact size of the sprites to
- load.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure ScaleVSP(var src,dest;nx,ny:word);
-
- Stretches or shrinks a sprite to a new size.
-
- SRC: Sprite to scale;
- DEST: New sprite scaled;
- NX,NY: Width and Height of the new sprite
-
- NOTE: DEST must be preallocated.
-
- EXAMPLE:
-
- var
- MySprite,
- NewSize : pointer;
-
- .
- .
- .
- getmem(NewSize,buffsize(16,16));
- ScaleVSP(MySprite^,NewSize^,16,16); { Changes MySprite to be size 16x16 }
-
- ───────────────────────────────────────────────────────────────────────────
- function AnalyzeScreen:byte;
-
- Returns the color number that is used the most on the active page.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure MemWrite(var source,dest;size:word;var off:longint);
-
- Copies data from SOURCE to DEST.
-
- SOURCE: Source buffer;
- DEST: Destination buffer;
- SIZE: Number of bytes to copy;
- OFF: Offset in DEST to start the copy
-
- NOTE: Upon returning OFF = OFF+SIZE
-
- ───────────────────────────────────────────────────────────────────────────
- procedure MemRead(var source,dest;size:word;var off:longint);
-
- Copies data from SOURCE to DEST.
-
- SOURCE: Source buffer;
- DEST: Destination buffer;
- SIZE: Number of bytes to copy;
- OFF: Offset in SOURCE to start the copy
-
- NOTE: Upon returning OFF = OFF+SIZE
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fwput(x1,y1:integer;var image);
-
- Displays a sprite on the active page. Forces even amount width moves.
-
- X1,Y1: Coordinate to place top-left of sprite.
- IMAGE: Sprite;
-
- ───────────────────────────────────────────────────────────────────────────
- procedure moveDW(var source,dest;size:word);
-
- Same as Turbo Pascal's move procedure. Uses 386 instructions.
-
- SOURCE: Source buffer;
- DEST: Destination buffer;
- SIZE: Size in bytes of memory to copy
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fputDW(x:word;var buff);
-
- Displays a sprite on the active page. Forces 386 instructions. Does
- not preform any clipping.
-
- X: Offset of the active page. E.G. = pt(x,y);
- BUFF: Sprite to display
-
- NOTE: This is the fastest sprite drawing routine. The width of the
- sprite must be divisible by 4.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure PcopyDW(var from,too);
-
- Same a fPcopy. Forces 386 instructions. Copies one page to another.
-
- FROM: Buffer location of the source page;
- TOO: Buffer location of the destination page
-
- ───────────────────────────────────────────────────────────────────────────
- procedure fillDW(var dest;c:word;v:byte);
-
- Fills a memory region with the value V. Forces 386 instructions.
-
- DEST: The memory area to fill;
- C: Number of bytes to fill;
- V: Value to fill
-
- ───────────────────────────────────────────────────────────────────────────
- procedure clsDW(c:byte);
-
- Same as CLS. Clears the active page. Forces 386 instructions.
-
- C: The color to clear the active page
-
- ───────────────────────────────────────────────────────────────────────────
- procedure displayer(x,y:integer;var pic,virt;plv:byte);
-
- Displays a Sprite (pic) on the current page. Based on the sprite's level
- (plv). The (virt) is the virtual page that keeps track of all of the
- sprites currently on the screen.
-
- Think of the display having 256 layers. Layer 0 is furthest back and
- layer 255 is the top layer. For example, a sprite "Displayer" with
- plv=4 will only overwrite sprites that have been written with a plv
- value less than 4. Sprites greater than 4 will be unaffected.
-
- The how DispLayer works:
- Functions the same as ftput, except that it also checks the
- screen location on the "virt" page. If that pixel value is less
- than the "plv" value, then the pixel is drawn.
-
- Use the "DispLayer" function with DispVirt to update the virtual page.
-
-
- X,Y: Top-left position of sprite;
- PIC: Sprite to display;
- VIRT: Virtual page for sprite levels;
- PLV: Sprite level value
-
- See the file DEMO3.PAS for an example.
-
- ───────────────────────────────────────────────────────────────────────────
- procedure eraselayer(x,y:integer;bkpage:byte;var pic,virt;plv:byte);
-
- Erases a sprite on the current page.
-
- X,Y: Coordinates to place the sprite;
- BKPAGE: Backgroun page to write to the current screen;
- PIC: Sprite to erase;
- VIRT: Virtual page for sprite levels;
- PLV: Sprite level value
-
- Erases each sprite pixel when the byte on the (virt) page is
- less than or equal to (plv).
-
- ───────────────────────────────────────────────────────────────────────────
- procedure dispvirt(x,y:integer;var pic,virt;plv:byte);
-
- Updates the virtual page with the sprite level value.
-
- X,Y: Coordinates of the sprite;
- PIC: Sprite to update;
- VIRT: Virtual page to be updated;
- PLV: Sprite level value
-
- ───────────────────────────────────────────────────────────────────────────
- procedure erasevirt(x,y:integer;var pic,virt;plv:byte);
-
- Erases the virtual page with the sprite level value.
-
- X,Y: Coordinates of the sprite;
- PIC: Sprite to update;
- VIRT: Virtual page to be erased;
- PLV: Sprite level value
-
- ───────────────────────────────────────────────────────────────────────────
- procedure copyvirt(x,y:integer;var pic,v1,v2;plv:byte);
-
- Copies a virtual area to another virtual page
-
- X,Y: Coordinates of the sprite;
- PIC: Sprite to update;
- V1: Virtual page source;
- V1: Virtual page destination;
- PLV: Sprite level value
-
- ───────────────────────────────────────────────────────────────────────────
-