home *** CD-ROM | disk | FTP | other *** search
-
- TTTTTT UU UU GGGG UU UU
- TT UU UU GG UU UU
- TT UU UU GG GGG UU UU
- TT UU UU GG GG UU UU
- TT UUUU GGGG UUUU
-
- The Ultimate Graphics Unit v1.0
-
- Released April 5, 1995
-
- Created by Jason Rennie (quasi@locke.ccil.org)
- and
- Elliot Waingold (fortran.god@bitbytes.clark.net)
-
- SFVGA (the new standard) - SuperFast VGA
-
- WWW home page - http://www.ccil.org/~quasi/homepage.html
-
- * Code copyright 1995 by Elliot Waingold and Jason Rennie *
-
- Below is a quick listing of all the routines included in TUGU for your
- reference. Further in this document is a long listing of each
- individual routine, including a detailed description of what it is
- used for.
-
- Procedure SetMode(mode : integer); { video mode stuff }
- Procedure VGAMode;
-
- Function NewBuf : pointer;
- Procedure KillBuf(Buffer : pointer); { buffer stuff }
- Procedure SetCurBuf(Buffer : pointer);
- Procedure BufToScreen(buffer : pointer);
- Procedure ScreenToBuf(buffer : pointer);
-
- Procedure SetRGBPal(Var palette : palarray);
- Procedure GetRGBPal(Var palette : palarray);
- Procedure SetRGBPalette(r,g,b,color : byte); { palette stuff }
- Procedure GetRGBPalette(Var r,g,b : byte; color : byte);
- Procedure ClrPal(Var palette : palarray);
- Procedure SmoothBlend(Var palette : palarray; Start, Finish : integer);
- Procedure RainbowPal(Var palette : palarray);
- Procedure RotateForward(Var palette : palarray);
- Procedure RotateBackward(Var palette : palarray);
- Procedure FadeIn(palette : palarray; speed : integer);
- Procedure FadeOut(palette : palarray; speed : integer);
- Procedure PaletteMerge(Pic1 : pointer; var Pal1 : PalArray;
- Pic2 : pointer; var Pal2, NewPal : PalArray);
-
- Procedure WaitRetrace;
- Procedure WaitRefresh;
-
- Procedure PutPix(x,y : integer);
- Function GetPix(x,y : integer) : byte;
- Procedure ClrBuf(color : byte); { plotting stuff }
- Procedure line(x1,y1,x2,y2 : integer);
- Procedure Rectangle(x1,y1,x2,y2 : integer);
- Procedure rectanglefill(x1,y1,x2,y2 : integer);
- Procedure Circle(Cx,Cy,y : integer);
-
- Procedure PCXLoad(filename : string; Var palette : palarray; x,y : integer);
- Function PCXLoadImage(filename : string; Var palette : palarray) : pointer;
- Procedure PCXSave(filename : string; palette : palarray; x1,y1,x2,y2 : integer);
- Procedure PCXSaveImage(filename : string; palette : palarray; ImagePtr : pointer); { image stuff }
- Procedure GetImage(x1, y1, x2, y2 : integer; imageptr : pointer);
- Procedure PutImage(x, y : integer; ImagePtr : pointer);
- Procedure PutTransparent(x, y : integer; tcolor : byte; ImagePtr : pointer);
- Procedure KillImage(ImagePtr : pointer);
-
- Procedure InitSprite(var NewSprite : SpriteType; XSize, YSize : integer);
- Procedure InsertSpriteImage(var Sprite : SpriteType; ImagePtr : pointer;
- FrameNum : byte);
- Procedure DrawSprite(x, y : integer; var Sprite : SpriteType);
- Procedure UndrawSprite(x, y : integer; var Sprite : SpriteType); { sprite }
- Procedure SetFrame(var Sprite : SpriteType; FrameNum : integer); { stuff }
- Procedure NextFrame(var Sprite : SpriteType);
- Procedure PrevFrame(var Sprite : SpriteType);
- Procedure KillSpriteFrame(var Sprite : SpriteType; FrameNum : integer);
- Procedure KillSprite(var Sprite : SpriteType);
-
- Procedure LoadFont(Var font : pointer; fontname : string);
- Procedure Textxy(font : pointer; Var text2 : string; x,y : integer; size : byte); { font stuff }
-
- There are also many constants and variable types which go along with
- TUGU:
-
- SW = 320;
- SH = 200;
- xmax = 319;
- ymax = 199;
-
- Anywhere you need the size of the screen or the maximum x or y values,
- you may use the above constants.
-
- NC = 256;
- ColorMax = NC-1;
-
- Anywhere you need the number of colors for the video mode or the maximum
- color value, you may use the above constants.
-
- MaxFrames = 16;
-
- The maxiumum number of frames that may be used in conjuction with the
- sprite routines found in TUGU is 16.
-
- VidPtr = ptr($A000, 0);
-
- Any time you need a pointer to the video memory, you may use VidPtr
- instead of having to create a new pointer
-
- palarray = array [0..ColorMax,1..3] of byte;
-
- If you would ever want to create your own palette or access palette
- values individually, use the following format. To set up your own,
- put "mypal : palarray" in the "Var" section of your program. A default
- palette "pal" is provided for your convenience.
-
- SpriteType = record
- CurFrame, NumFrames : byte;
- Width, Height : integer;
- FramePtr : array[0..MaxFrames-1] of pointer;
- BackGround : pointer;
- end;
-
- The above is the format used for the sprite. Any time you want to set
- up a new sprite, use "mysprite : SpriteType" in the "Var" section of your
- program.
-
- color : byte; { Current drawing color }
-
- Instead of forcing you to include the desired drawing color with every
- procedure you want to execute, we have set up a global variable called
- "color" for you to use. To change the current drawing color, simply
- set "color" to the number you desire.
-
- CurBuf : pointer; { Pointer to current drawing buffer }
-
- This is another global variable meant to make things easier on you, the
- programmer. This variable controls where all data is sent to. By
- default, all data is sent to the video screen, but if you want to set
- up your own video pages, you may use this in conjuction with the buffer
- routines to do so.
-
- time : longint absolute $0046:$c; { accesses internal timer }
-
- This is simply a nice useful variable which I stuck in to make it easy
- to access the internal timer. If you ever need to access it, you simply
- need to set a variable equal to "time" and that variable will hold the
- number of clock ticks that have elapsed since midnight. One second is
- equal to 18.2 clock ticks, so to convert from ticks to seconds, you should
- divide by 18.2
-
-
- Procedure SetMode(mode : integer);
-
- This procedure will set the screen to any non-VESA mode. All standard
- modes up to VGA are included within this field. SVGA can be set with
- this procedure, but are limited to those specific to the graphics card.
- Each card type has different numbers for the various SVGA modes. This
- is primarily used to move back into text mode from graphics. The number
- for the standard 80x25 color text mode is 3.
-
-
- Procedure VGAMode;
-
- This procedure automatically sets the video mode to 13h (320x200x256),
- the mode that this graphics unit was built for. This is essentially
- the initialization line for this unit.
-
-
- Function NewBuf : pointer;
-
- Setting a pointer equal to NewBuf will allocate the necessary memory to
- hold a page of video memory (64k). Using a buffering system allows
- the least amount of flicker and choppiness.
-
-
- Procedure KillBuf(buffer : pointer);
-
- This procedure will deallocate the memory for a buffer and allow the extra
- memory to be used once again.
-
-
- Procedure SetCurBuf(buffer : pointer);
-
- This procedure tells TUGU on which buffer to perform graphics operations.
- This allows the programmer to send information to a buffer and then when
- all the necessary drawing is done, use BufToScreen to quickly present the
- picture on the screen. Redrawing the screen without using a buffering
- system will often cause flickering when the animation becomes more
- complex.
-
-
- Procedure BufToScreen(buffer : pointer);
-
- This will simply copy the virtual screen in the selected buffer to the
- video screen with blazing speed.
-
-
- Procedure ScreenToBuf(buffer : pointer);
-
- This does the opposite of the above procedure, copying the information
- in the video memory to a buffer.
-
-
- Procedure SetRGBPal(Var palette : palarray);
-
- This will set the entire VGA palette very quickly. The palette is
- composed of 256 colors each broken down into red, green and blue values,
- hence the variable type palarray : array [0..255,1..3] of byte;
- Each value can range from 0 to 63, 63 being full intensity.
- If you intend to set only a portion of the palette, it is recommended
- that you first get the standard palette using the below procedure.
-
-
- Procedure GetRGBPal(Var palette : palarray);
-
- The variable "pal" is NOT automatically set to the default palette. This
- procedure allows you to get the default palette and then deal with it
- however you like. As long as you use only SetRGBPal for setting the
- palette, there are few other uses for this procedure.
-
-
- Procedure SetRGBPalette(r,g,b,color : byte);
-
- This procedure was included primarily to allow compatibility with the
- BGI routines and also allow a simpler way to set the palette. 'r' is the
- red value, 'g' is the green value, 'b' is the blue value and 'color' is
- the color number.
-
- Procedure GetRGBPalette(Var r,g,b : byte; color : byte);
-
- Gets the RGB values for a specified color value.
-
-
- Procedure ClrPal(Var palette : palarray);
-
- This will set all values of the "palette" variable to 0. This procedure
- will NOT set the actual video palette. SetRGBPal must be used in
- conjunction to set the palette.
-
-
- Procedure SmoothBlend(Var palette : palarray; start, finish : integer);
-
- This procedure takes the RGB values of the "start" and "finish" colors
- and makes a smooth transition of colors between them and stores those
- new colors in the "palette" array. Once again, SetRGBPal must be used
- to set the palette.
-
-
- Procedure RainbowPal(Var palette : palarray);
-
- This will create a palette which moves through all the colors in a
- rainbow. The following colors are set and then SmoothBlend is used to
- make transition between them:
-
- 0 black
- 1 red
- 43 yellow
- 86 green
- 128 cyan
- 171 blue
- 213 purple
- 255 red
-
- The palette is NOT set during the calling of the procedure. To set the
- palette, send the same variable to SetRGBPal.
-
-
- Procedure RotateForward(Var palette : palarray; start, finish : byte);
-
- This procedure will move each of the RGB values of palette ahead one color
- value starting with "start" and ending with "finish". The color in the
- "finish" position is moved to the "start" position. This does not set the
- actual video palette.
-
-
- Procedure RotateBackward(Var palette : palarray; start, finish : byte);
-
- Same as above except backwards.
-
-
- Procedure FadeIn(palette : palarray; lag : integer);
-
- Given a palette and a lag, this procedure will turn the screen
- completely black and then gradually increase the intensity until it
- reaches the specifications dictated in the palette. The smaller the
- lag (to a minimum of 0), the quicker the fade will occur. NOTE:
- the global variable "pal" is used in changing the palette. When the
- fade is completed, "pal" will hold the current value of the palette.
-
-
- Procedure FadeOut(palette : palarray; lag : integer);
-
- See above. Changes from full intensity palette to complete black.
-
-
- Procedure PaletteMerge(pic1 : pointer; var pal1 : palarray;
- pic2 : pointer; var pal2, newpal : palarray);
-
- Often when you load pictures or images, you are likely to find that you
- will want to load two pictures at the same time and find that each of
- the pictures has a completely different palette. This procedure is the
- solution to your troubles. It will intelligently search through the
- pictures finding which colors are most common in each of the pictures,
- giving those colors priority in the new palette. Each of the two
- pictures must be images and must have their own separate palette.
- Each image will be changed to accomodate for the new palette which will
- be given in "newpal." After a call to PaletteMerge, you can slap both
- images on the screen and set the palette to newpal, and see that both
- have proper coloring.
- A quick note: color #0 is assumed to be black and will cause problems
- if not.
-
-
- Procedure WaitRetrace;
-
- This waits until the current vertical retrace has been finished.
- Using this procedure before updating the video screen will prevent snow
- on older machines. This would primarily be used in front of SetRGBPal
- and BufToScreen statements.
-
-
- Procedure WaitRefresh;
-
- Similar to WaitRetrace, except that this pauses through an entire
- vertical retrace, ensuring that whatever was last in the video memory
- was completely seen on the video screen.
-
-
- Procedure PutPix(x,y : integer);
-
- Plots a pixel in the current drawing color. This is one of the quickest
- ways to plot a single pixel to the video screen, but should only be used
- when a smaller number of pixels needs to be drawn. As far as time per
- pixel goes, routines such as PutImage or ClrBuf are MUCH faster.
-
-
- Function GetPix(x,y : integer) : byte;
-
- Returns the color of the pixel at (x,y) in the current drawing buffer.
-
-
- Procedure ClrBuf(color : byte);
-
- A VERY quick way to turn the entire screen to a single color. The
- perfect way to clear the screen.
-
-
- Procedure Line(x1,y1,x2,y2 : integer);
-
- Your standard line procedure, drawing a line of width one between the
- two points. This is an EXTREMELY efficient procedure, rewritten entirely
- in assembler, using a separately developed algorithm which parallels
- Bresenham for speed. Clipping is implemented (if part of the line is not
- on the screen, it will not be drawn).
-
-
- Procedure Rectangle(x1,y1,x2,y2 : integer);
-
- Very quickly draws a rectangle in the current drawing color. The upper
- left corner of the rectangle is given by (x1,y1). The lower right corner
- of the rectangle is given by (x2,y2). If one of the points is off the
- screen, it will be moved as little as possible so that it is displayed
- on the screen. Example : point (-15,20) would be moved to (0,20). If
- both points are off the screen, the rectangle will not be displayed.
-
-
- Procedure RectangleFill(x1,y1,x2,y2 : integer);
-
- Draws a rectangle similar to above, except that it is filled.
-
-
- Procedure Circle(cx,cy,r : integer);
-
- Takes (cx,cy) as the center and draws a circle of radius "r" in the
- current drawing color around the center. This procedure again uses
- Bresenham's circle algorithm and is very quick.
-
-
- Procedure PCXLoad(filename : string; Var palette : palarray; x,y : integer);
-
- The procedure loads the PCX file "filename" into the current drawing
- buffer at location (x,y). It does not set the palette, but rather
- returns the palette of the image in the variable "palette." This
- procedure uses very quick file procedures and can load pcx images quite
- speedily.
- When loading PCX files it is suggested that you set the palette to black
- before you load the file and then when it has been loaded, set the
- palette with the appropriate variable.
-
-
- Function PCXLoadImage(filename : string; Var palette : palarray) : pointer;
-
- PCXLoadImage is similar to PCXLoad in that it loads a PCX file, but
- instead of loading directly into the current drawing buffer, it will
- create an image out of the PCX file. The function will return the
- pointer of the image which holds the PCX image. This image may then
- be displayed using PutImage.
-
-
- Procedure PCXSave(filename : string; palette : palarray; x1,y1,x2,y2 : integer);
-
- This procedure will save the image which spans the current drawing buffer
- from point (x1,y1) to (x2,y2) into the file "filename." It will also
- save the palette which is sent in "palette."
-
-
- Procedure PCXSaveImage(filename : string; palette : palarray; ImagePtr : pointer);
-
- Considering what you know of PCXLoadImage & PCXSave, you can probably
- guess what this routine does.
- It takes the image stored at the location in memory pointed to by
- "ImagePtr" and saves that along with "palette" into the file indicated by
- "filename."
-
-
- Procedure GetImage(x1,y1,x2,y2 : integer; ImagePtr : pointer);
-
- This procedure does pretty much what it says. It takes the picture
- enclosed by (x1,y1) and (x2,y2) and stores it in memory at the location
- indicated by ImagePtr.
-
- (very important) NOTE : this procedure will NOT set up the memory space
- for your image. In other words, you will have to call a getmem procedure
- to reserve space for your image. The size reserved for the image must be
- equal to (xsize * ysize + 4).
-
- Example:
-
- getmem(mypointer,(x2-x1)*(y2-y1)+4);
- getimage(x1,y1,x2,y2,mypointer);
-
- The image format used by TUGU is a very simple one. It is simply the
- xsize and ysize followed by the information contained in the image (each
- color is equal to one byte). The reason you must add four to the size of
- the image is that "xsize" and "ysize" are stored as word variables, which
- each take up two bytes of memory.
-
-
- Procedure PutImage(x,y : integer; ImagePtr : pointer);
-
- As it says, this procedure will take a image held in memory at location
- "ImagePtr" and display it in the current drawing buffer at location (x,y).
- It is done very quickly and efficiently, but has no special effects
- included.
-
-
- Procedure PutTransparent(x,y : integer; tcolor : byte; ImagePtr : pointer);
-
- This procedure is similar to PutImage except that it will ignore and
- therefore not plot all colors that are equal to "tcolor." This can be
- extremely useful for animation and images that do not conform to the
- basic rectangular shape. If you do any work with the mouse, you will
- instantly see the benefits of this procedure.
-
-
- Procedure KillImage(Imageptr : pointer);
-
- If you ever want to free some memory that is being held by an image
- that will no longer be used, this is the procedure for you. Simply
- send it the pointer for the image you want to trash and it shall be
- destroyed.
-
-
- Procedure InitSprite(var NewSprite : spritetype; xsize,ysize : integer);
-
- This is the procedure for initialization of a SpriteType variable. It
- resets the current frame to zero and the number of frames to zero. Also,
- it sets the width and height of the sprite frames.
-
-
- Procedure InsertSpriteImage(Var sprite : spritetype; imageptr : pointer;
- framenum : byte);
-
- This is the most important routine for building a sprite. It inserts the
- image pointed to by ImagePtr as frame number FrameNum in Sprite. When
- building an animated sprite, call this routine repeatedly until all
- of the desired frames have been inserted. The number of frames in the
- sprite is updated if necessary. NOTE: Make sure that image dimensions
- match sprite dimensions set with InitSprite. Also, Sprite must have been
- previously initialized before passing it to this procedure.
-
-
- Procedure DrawSprite(x,y :integer; Var sprite : spritetype);
-
- This procedure draws the current frame of Sprite in the buffer/screen
- (whichever is currently active) with upper left corner at (x,y). Color
- 0 is treated as transparent. This routine saves the background overwritten
- by the sprite.
-
-
- Procedure UndrawSprite(x,y :integer; Var sprite : spritetype);
-
- This is where the background that was saved by DrawSprite is put to use.
- This routine provides an easy way to restore what was behind a sprite before
- is was drawn on the screen/buffer. Use this after drawing one frame of the
- sprite but before drawing the next. The background is redrawn at (x,y).
-
-
- Procedure SetFrame(var sprite : spritetype; framenum : integer);
-
- Use this to set the frame that will be drawn next when DrawSprite is
- called.
-
-
- Procedure NextFrame(var Sprite : SpriteType);
-
- Use this to set the current frame to be drawn by DrawSprite to the next
- frame. This effectively increments the current frame, going back to the
- first if the current one is the last. By loading up to sixteen different
- sprite frames, one could use this procedure in conjunction with the other
- sprite routines to "flip" through the animated sprite, perhaps moving it
- around the screen at the same time.
-
-
- Procedure PrevFrame(var Sprite : SpriteType);
-
- This is similar to NextFrame, except it sets the current frame index to the
- previous frame, going to the last one if current is the first.
-
-
- Procedure KillSpriteFrame(var Sprite : SpriteType; FrameNum : integer);
-
- Use this to remove a frame from Sprite and deallocate its memory. I give
- you the dire warning that if you kill a sprite frame, then you MUST
- reinsert one at the same location before attempting to do ANYTHING else
- with Sprite, including KillSprite. This procedure should only be used
- in conjunction with InsertSpriteImage to modify a frame.
-
-
- Procedure KillSprite(var Sprite : SpriteType);
-
- This is the antithesis of InitSprite. It deallocates all memory used by
- Sprite and leaves it unitialized. Therefore, one cannot again use Sprite
- until it is run through InitSprite again.
-
-
- Procedure LoadFont(Var font : pointer; fontname : string);
-
- This procedure is essentially the initialization for the TUGU font
- engine. It works similar to the way files do. The pointer does NOT
- need to be initialized, any old pointer will do. Also needed is the
- filename where the font is stored (usually ending in ".tf").
- You may load numerous fonts for one program as long as there is enough
- memory, but you need to used different pointers for the different fonts.
- When you want to display any of the fonts, you will send the pointer
- which was initialized for that font to "Textxy".
-
-
- Procedure Textxy(font : pointer; Var text2 : string; x,y : integer; size : byte);
-
- "Font" is the pointer which points to the location in memory where a
- the information for a font is found. "Text2" is the string that you want
- to display. "Textxy" will only display characters which are defined in
- the font which is loaded. If a character is not defined, a blank space
- will be left in its place. (x,y) is the location of the upper left
- corner of where you want the font to appear on the screen. Built in to
- this procedure is a routine to enlarge the font if so desired. The
- procedure will multiply the font's size according to the number left
- in "size." If the normal size is desired, "size" should be set to 1.