home *** CD-ROM | disk | FTP | other *** search
/ Black Art of 3D Game Programming / Black_Art_of_3D_Game_Programming.iso / source / msc / library / black4.h < prev    next >
Text File  |  1994-11-28  |  9KB  |  245 lines

  1.  
  2. // HEADER FILE FOR BLACK4.C
  3.  
  4. // D E F I N E S  ////////////////////////////////////////////////////////////
  5.  
  6. #define SCREEN_WIDTH      (unsigned int)320 // mode 13h screen dimensions
  7. #define SCREEN_HEIGHT     (unsigned int)200
  8.  
  9. // screen transition commands
  10.  
  11. #define SCREEN_DARKNESS  0         // fade to black
  12. #define SCREEN_WHITENESS 1         // fade to white
  13. #define SCREEN_WARP      2         // warp the screen image
  14. #define SCREEN_SWIPE_X   3         // do a horizontal swipe
  15. #define SCREEN_SWIPE_Y   4         // do a vertical swipe
  16. #define SCREEN_DISOLVE   5         // a pixel disolve
  17.  
  18. #define VGA_INPUT_STATUS_1   0x3DA // VGA input status register number 1
  19.                                    // D3 is vertical retrace bit
  20.                                    // 1 - retrace in progress
  21.                                    // 0 - no retrace
  22.  
  23. #define VGA_VRETRACE_MASK 0x08     // masks off unwanted bit of status reg
  24.  
  25. #define SPRITE_WIDTH      16       // default width of a sprite
  26. #define SPRITE_HEIGHT     16       // default height of a sprite
  27.  
  28. #define MAX_SPRITE_FRAMES 32
  29.  
  30. // sprite states
  31.  
  32. #define SPRITE_DEAD       0
  33. #define SPRITE_ALIVE      1
  34. #define SPRITE_DYING      2
  35.  
  36. // mode Z page stuff
  37.  
  38. #define PAGE_0            0
  39. #define PAGE_1            1
  40.  
  41. // these are used to change the visual page of the VGA
  42.  
  43. #define CRT_ADDR_LOW      0x0D // the index of the low byte of the start address
  44. #define CRT_ADDR_HI       0x0C // the index of the hi byte of the start address
  45.  
  46. // M A C R O S ///////////////////////////////////////////////////////////////
  47.  
  48. #define SET_SPRITE_SIZE(w,h) {sprite_width=w; sprite_height=h;}
  49.  
  50. // S T R U C T U R E S ///////////////////////////////////////////////////////
  51.  
  52. // the PCX file structure
  53.  
  54. typedef struct pcx_header_typ
  55.         {
  56.         char manufacturer;          // the manufacturer of the file
  57.         char version;               // the file format version
  58.         char encoding;              // type of compression
  59.         char bits_per_pixel;        // number of bits per pixel
  60.         int x,y;                    // starting location of image
  61.         int width,height;           // size of image
  62.         int horz_res;               // resolution in DPI (dots per inch)
  63.         int vert_res;
  64.         char ega_palette[48];       // the old EGA palette (usually ignored)
  65.         char reserved;              // don't care
  66.         char num_color_planes;      // number of color planes
  67.         int bytes_per_line;         // number of bytes per line of the image
  68.         int palette_type;           // 1 for color, 2 for grey scale palette
  69.         char padding[58];           // extra bytes
  70.  
  71.         } pcx_header, *pcx_header_ptr;
  72.  
  73. // this holds the PCX header and the actual image
  74.  
  75. typedef struct pcx_picture_typ
  76.         {
  77.         pcx_header header;          // the header of the PCX file
  78.         RGB_color palette[256];     // the palette data
  79.         unsigned char far *buffer;  // a pointer to the 64,000 byte buffer
  80.                                     // holding the decompressed image
  81.  
  82.         } pcx_picture, *pcx_picture_ptr;
  83.  
  84.  
  85. // this is a sprite structure
  86.  
  87. typedef struct sprite_typ
  88.         {
  89.         int x,y;            // position of sprite
  90.         int width,height;   // dimensions of sprite in pixels
  91.  
  92.         int counter_1;      // some counters for timing and animation
  93.         int counter_2;
  94.         int counter_3;
  95.  
  96.         int threshold_1;    // thresholds for the counters (if needed)
  97.         int threshold_2;
  98.         int threshold_3;
  99.  
  100.         unsigned char far *frames[MAX_SPRITE_FRAMES]; // array of pointers to
  101.                                                       // the images
  102.  
  103.         int curr_frame;                // current frame being displayed
  104.         int num_frames;                // total number of frames
  105.         int state;                     // state of sprite, alive, dead...
  106.         unsigned char far *background; // image under the sprite
  107.  
  108.         int x_clip,y_clip;             // clipped position of sprite
  109.         int width_clip,height_clip;    // clipped size of sprite
  110.         int visible;                   // used by sprite engine to flag
  111.                                        // if a sprite was invisible last
  112.                                        // time it was drawn hence the background
  113.                                        // need not be replaced
  114.  
  115.         } sprite, *sprite_ptr;
  116.  
  117. // this is the typedef for a bitmap
  118.  
  119. typedef struct bitmap_typ
  120.         {
  121.         int x,y;                    // position of bitmap
  122.         int width,height;           // size of bitmap
  123.         unsigned char far *buffer;  // buffer holding image
  124.  
  125.         } bitmap, *bitmap_ptr;
  126.  
  127. // this is a typdef used for the layers in parallax scrolling
  128. // note it is identical to a bitmap, but we'll make a separate typedef
  129. // in the event we later need to add fields to it
  130.  
  131. typedef struct layer_typ
  132.         {
  133.         int x,y;           // used to hold position information
  134.                            // no specific function
  135.  
  136.         int width,height;  // size of layer,note:width must be divisible by 2
  137.  
  138.         unsigned char far *buffer;  // the layer buffer
  139.  
  140.         } layer, *layer_ptr;
  141.  
  142. // E X T E R N A L S /////////////////////////////////////////////////////////
  143.  
  144. extern unsigned char far *double_buffer;     // the double buffer
  145.  
  146. extern unsigned int double_buffer_height;    // height of double buffer
  147.  
  148. extern unsigned int double_buffer_size;      // total size of buffer in bytes
  149.  
  150. extern unsigned int sprite_width;            // width of a sprite
  151.  
  152. extern unsigned int sprite_height;           // of a sprite
  153.  
  154. extern unsigned char far *page_0_buffer;     // pointer to mode z page 0
  155.  
  156. extern unsigned char far *page_1_buffer;     // pointer to mode z page 0
  157.  
  158. extern int mode_z_page;                      // current mode z page
  159.  
  160. // P R O T O T Y P E S ///////////////////////////////////////////////////////
  161.  
  162. int  PCX_Init(pcx_picture_ptr image);
  163.  
  164. int  PCX_Load(char *filename, pcx_picture_ptr image,int enable_palette);
  165.  
  166. void PCX_Delete(pcx_picture_ptr image);
  167.  
  168. void PCX_Show_Buffer(pcx_picture_ptr image);
  169.  
  170. void PCX_Copy_To_Buffer(pcx_picture_ptr image,unsigned char far *buffer);
  171.  
  172. void PCX_Get_Sprite(pcx_picture_ptr image,
  173.                      sprite_ptr sprite,
  174.                      int sprite_frame,
  175.                      int cell_x, int cell_y);
  176.  
  177. void Sprite_Init(sprite_ptr sprite,int x,int y, int width, int height,
  178.                                    int c1,int c2,int c3,
  179.                                    int t1,int t2,int t3);
  180.  
  181. void Sprite_Delete(sprite_ptr sprite);
  182.  
  183. void Sprite_Under(sprite_ptr sprite, unsigned char far *buffer);
  184.  
  185. void Sprite_Erase(sprite_ptr sprite, unsigned char far *buffer);
  186.  
  187. void Sprite_Draw(sprite_ptr sprite, unsigned char far *buffer,int transparent);
  188.  
  189.  
  190. void Sprite_Under_Clip(sprite_ptr sprite, unsigned char far *buffer);
  191.  
  192. void Sprite_Erase_Clip(sprite_ptr sprite, unsigned char far *buffer);
  193.  
  194. void Sprite_Draw_Clip(sprite_ptr sprite, unsigned char far *buffer,int transparent);
  195.  
  196. int  Sprite_Collide(sprite_ptr sprite_1, sprite_ptr sprite_2);
  197.  
  198. void Display_Double_Buffer(unsigned char far *buffer,int y);
  199.  
  200. int  Create_Double_Buffer(int num_lines);
  201.  
  202. void Fill_Double_Buffer(int color);
  203.  
  204. void Delete_Double_Buffer(void);
  205.  
  206. void Screen_Transition(int effect);
  207.  
  208. void Wait_For_Vertical_Retrace(void);
  209.  
  210. void fwordcpy(void far *destination, void far *source,int num_words);
  211.  
  212. void Bitmap_Get(bitmap_ptr image, unsigned char far *source);
  213.  
  214. void Bitmap_Put(bitmap_ptr image, unsigned char far *destination,int transparent);
  215.  
  216. int Bitmap_Allocate(bitmap_ptr image, int width, int height);
  217.  
  218. void Bitmap_Delete(bitmap_ptr the_bitmap);
  219.  
  220. int Layer_Create(layer_ptr dest_layer, int width, int height);
  221.  
  222. void Layer_Build(layer_ptr dest_layer,int dest_x, int dest_y,
  223.                 unsigned char far *source_buffer,int source_x,int source_y,
  224.                 int width,int height);
  225.  
  226. void Layer_Draw(layer_ptr source_layer, int source_x, int source_y,
  227.                 unsigned char far *dest_buffer,int dest_y,int dest_height,
  228.                 int transparent);
  229.  
  230. void Layer_Delete(layer_ptr the_layer);
  231.  
  232. void Print_Char_DB(int xc,int yc,char c,int color,int transparent);
  233.  
  234. void Print_String_DB(int x,int y,int color, char *string,int transparent);
  235.  
  236. void Write_Pixel_DB(int x,int y,int color);
  237.  
  238. int Read_Pixel_DB(int x,int y);
  239.  
  240. void Set_Working_Page_Mode_Z(int page);
  241.  
  242. void Set_Visual_Page_Mode_Z(int page);
  243.  
  244.  
  245.