home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / BATTLE.ZIP / INSTALL.ZIP / GRAPHICS.H < prev    next >
Text File  |  1996-05-16  |  15KB  |  421 lines

  1.  
  2. // Header file GRAPHICS.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 4
  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.  
  47. #define GRAPHICS_MODE13     0x13  // 320x200x256
  48. #define TEXT_MODE           0x03  // 80x25 text mode
  49.  
  50. #define COLOR_MASK        0x3C6 // the bit mask register
  51. #define COLOR_REGISTER_RD 0x3C7 // set read index at this I/O
  52. #define COLOR_REGISTER_WR 0x3C8 // set write index at this I/O
  53. #define COLOR_DATA        0x3C9 // the R/W data is here
  54.  
  55. // size of the "tech" font used in intro
  56.  
  57. #define TECH_FONT_WIDTH         4   // width of high tech font
  58. #define TECH_FONT_HEIGHT        7   // height of high tech font
  59. #define NUM_TECH_FONT           64  // number of characters in tech font
  60.  
  61. // ROM character set stuff
  62.  
  63. #define ROM_CHAR_SET_SEG 0xF000   // segment of 8x8 ROM character set
  64. #define ROM_CHAR_SET_OFF 0xFA6E   // begining offset of 8x8 ROM character set
  65.  
  66. #define ROM_CHAR_WIDTH      8     // width of ROM 8x8 character set in pixels
  67. #define ROM_CHAR_HEIGHT     8     // height of ROM 8x8 character set in pixels
  68.  
  69. #define MODE13_WIDTH   (unsigned int)320 // mode 13h screen dimensions
  70. #define MODE13_HEIGHT  (unsigned int)200
  71.  
  72. // the VGA card controller ports
  73.  
  74. #define SEQUENCER             0x3C4    // the sequencer's index port
  75. #define CRT_CONTROLLER        0x3D4    // the crt controller's index port
  76. #define GFX_CONTROLLER        0x3CE    // the graphics controller's index port
  77. #define ATTR_CONTROLLER_FF    0x3DA    // the attribute controller's Flip Flop
  78. #define ATTR_CONTROLLER_DATA  0x3C0    // the attribute controller's data port
  79.  
  80. // defines for the CRT controller registers of interest
  81.  
  82. #define CRT_MAX_SCANLINE      0x09     // the maximum scanline register
  83.                                        // used to select how many scanlines
  84.                                        // per row
  85.  
  86. #define CRT_ADDR_MODE         0x14     // the address mode register
  87.                                        // used to select byte addressing
  88.                                        // for VGA
  89.                                        // also known as the underline register
  90.  
  91. #define CRT_MODE_CONTROL      0x17     // the mode control register
  92.                                        // used to select single byte addressing
  93.  
  94.  
  95. // defines for the GFX controller registers of interest
  96.  
  97. #define GFX_WRITE_MODE       0x05      // the memory write mode register
  98.                                        // used to deselect even/odd plane
  99.                                        // addressing
  100.  
  101. #define GFX_MISC             0x06      // the miscellaneous register
  102.                                        // used to deselect the chaining
  103.                                        // of memory
  104.  
  105.  
  106. // defines for the SEQUENCER registers of interest
  107.  
  108. #define SEQ_PLANE_ENABLE     0x02      // plane enable register, used to select
  109.                                        // which planes are written to by a
  110.                                        // CPU write
  111. #define SEQ_MEMORY_MODE      0x04      // the memory mode register
  112.                                        // used to deselect memory chain mode
  113.                                        // and odd/even memory addressing
  114.  
  115. // M A C R O S ///////////////////////////////////////////////////////////////
  116.  
  117. #define SET_BITS(x,bits)   (x | bits)
  118. #define RESET_BITS(x,bits) (x & ~bits)
  119. #define SET_SPRITE_SIZE(w,h) {sprite_width=w; sprite_height=h;}
  120.  
  121. // S T R U C T U R E S ///////////////////////////////////////////////////////
  122.  
  123. typedef struct grid_typ
  124. {
  125.     int beenShotAt;
  126.     int coveredByShip;
  127.     int * coveredByWhat;
  128. } gridSquare, *gridSquare_ptr;
  129.  
  130.  
  131. typedef struct shipSquare_typ
  132. {
  133.     int x;
  134.     int y;
  135.     int hit;
  136. } shipSquare, *shipSquare_ptr;
  137.  
  138.  
  139. // this structure holds a RGB triple in three unsigned bytes
  140.  
  141. typedef struct RGB_color_typ
  142.         {
  143.  
  144.         unsigned char red;    // red   component of color 0-63
  145.         unsigned char green;  // green component of color 0-63
  146.         unsigned char blue;   // blue  component of color 0-63
  147.  
  148.         } RGB_color, *RGB_color_ptr;
  149.  
  150. // this structure holds an entire color palette
  151.  
  152. typedef struct RGB_palette_typ
  153.         {
  154.         int start_reg;   // index of the starting register that is save
  155.         int end_reg;     // index of the ending registe that is saved
  156.  
  157.         RGB_color colors[256];   // the storage area for the palette
  158.  
  159.         } RGB_palette, *RGB_palette_ptr;
  160.  
  161. // the PCX file structure
  162.  
  163. typedef struct pcx_header_typ
  164.         {
  165.         char manufacturer;          // the manufacturer of the file
  166.         char version;               // the file format version
  167.         char encoding;              // type of compression
  168.         char bits_per_pixel;        // number of bits per pixel
  169.         int x,y;                    // starting location of image
  170.         int width,height;           // size of image
  171.         int horz_res;               // resolution in DPI (dots per inch)
  172.         int vert_res;
  173.         char ega_palette[48];       // the old EGA palette (usually ignored)
  174.         char reserved;              // don't care
  175.         char num_color_planes;      // number of color planes
  176.         int bytes_per_line;         // number of bytes per line of the image
  177.         int palette_type;           // 1 for color, 2 for grey scale palette
  178.         char padding[58];           // extra bytes
  179.  
  180.         } pcx_header, *pcx_header_ptr;
  181.  
  182. // this holds the PCX header and the actual image
  183.  
  184. typedef struct pcx_picture_typ
  185.         {
  186.         pcx_header header;          // the header of the PCX file
  187.         RGB_color palette[256];     // the palette data
  188.         unsigned char far *buffer;  // a pointer to the 64,000 byte buffer                            // holding the decompressed image
  189.         } pcx_picture, *pcx_picture_ptr;
  190.  
  191.  
  192. // this is a sprite structure
  193.  
  194. typedef struct sprite_typ
  195.         {
  196.         int x,y, x_old, y_old;            // position of sprite
  197.         int width,height;   // dimensions of sprite in pixels
  198.  
  199.         int counter_1;      // some counters for timing and animation
  200.         int counter_2;
  201.         int counter_3;
  202.  
  203.         int howManyTimesHit;
  204.  
  205.         shipSquare coveredSquare1;
  206.         shipSquare coveredSquare2;
  207.         shipSquare coveredSquare3;
  208.  
  209. /*
  210.         int threshold_1;    // thresholds for the counters (if needed)
  211.         int threshold_2;
  212.         int threshold_3;
  213. */
  214.         unsigned char far *frames[MAX_SPRITE_FRAMES]; // array of pointers to
  215.                                                        // the images
  216.  
  217.         int curr_frame;                // current frame being displayed
  218.         int num_frames;                // total number of frames
  219.         int state;                     // state of sprite, alive, dead...
  220.         unsigned char far *background; // image under the sprite
  221.  
  222.         int x_clip,y_clip;             // clipped position of sprite
  223.         int width_clip,height_clip;    // clipped size of sprite
  224.         int visible;                   // used by sprite engine to flag
  225.                                        // if a sprite was invisible last
  226.                                        // time it was drawn hence the background
  227.                                        // need not be replaced
  228.         int verticalOrHorizantal;
  229.         } sprite, *sprite_ptr;
  230.  
  231. // this is the typedef for a bitmap
  232.  
  233. typedef struct bitmap_typ
  234.         {
  235.         int x,y;                    // position of bitmap
  236.         int width,height;           // size of bitmap
  237.         unsigned char far *buffer;  // buffer holding image
  238.  
  239.         } bitmap, *bitmap_ptr;
  240.  
  241. // this is a typdef used for the layers in parallax scrolling
  242. // note it is identical to a bitmap, but we'll make a separate typedef
  243. // in the event we later need to add fields to it
  244.  
  245. typedef struct layer_typ
  246.         {
  247.         int x,y;           // used to hold position information
  248.                            // no specific function
  249.  
  250.         int width,height;  // size of layer,note:width must be divisible by 2
  251.  
  252.         unsigned char far *buffer;  // the layer buffer
  253.  
  254.         } layer, *layer_ptr;
  255.  
  256.  
  257.  
  258. // P R O T O T Y P E S ///////////////////////////////////////////////////////
  259.  
  260. void Print_Char(int xc,int yc,char c,int color,int transparent);
  261.  
  262. void Print_String(int x,int y,int color, char *string,int transparent);
  263.  
  264. void Write_Pixel(int x,int y,int color);
  265.  
  266. int Read_Pixel(int x,int y);
  267.  
  268. void Set_Graphics_Mode(int mode);
  269.  
  270. void Time_Delay(int clicks);
  271.  
  272. void Line_H(int x1,int x2,int y,int color);
  273.  
  274. void Line_V(int y1,int y2,int x,int color);
  275.  
  276. void Write_Color_Reg(int index, RGB_color_ptr color);
  277.  
  278. void Read_Palette(int start_reg,int end_reg, RGB_palette_ptr the_palette);
  279.  
  280. void Write_Palette(int start_reg,int end_reg, RGB_palette_ptr the_palette);
  281.  
  282. RGB_color_ptr Read_Color_Reg(int index, RGB_color_ptr color);
  283.  
  284. void Draw_Rectangle(int x1,int y1,int x2,int y2,int color);
  285.  
  286. void Fill_Screen(int color);
  287.  
  288. void Fill_Screen_Z(int color);
  289.  
  290. void Write_Pixel_Z(int x,int y,int color);
  291.  
  292. void Set_Mode_Z(void);
  293.  
  294. extern void Fill_da_screen(void);
  295.  
  296. int  PCX_Init(pcx_picture_ptr image);
  297.  
  298. int PCX_Load(char *filename, pcx_picture_ptr image, int load_palette);
  299.  
  300. void PCX_Delete(pcx_picture_ptr image);
  301.  
  302. void PCX_Show_Buffer(pcx_picture_ptr image, int appear_from_black);
  303.  
  304. void PCX_Copy_To_Buffer(pcx_picture_ptr image,unsigned char far *buffer);
  305.  
  306. void PCX_Get_Sprite(pcx_picture_ptr image,
  307.                      sprite_ptr sprite,
  308.                      int sprite_frame,
  309.                      int cell_x, int cell_y);
  310.  
  311. void Sprite_Init(sprite_ptr sprite,int x,int y, int x_old, int y_old, int width, int height,
  312.                                    int c1,int c2,int c3,
  313.                                    int xGrid, int yGrid);
  314.  
  315. void Sprite_Delete(sprite_ptr sprite);
  316.  
  317. void Sprite_Under(sprite_ptr sprite, unsigned char far *buffer);
  318.  
  319. void Sprite_Erase(sprite_ptr sprite, unsigned char far *buffer);
  320.  
  321. void Sprite_Draw(sprite_ptr sprite, unsigned char far *buffer,int transparent);
  322.  
  323.  
  324. void Sprite_Under_Clip(sprite_ptr sprite, unsigned char far *buffer);
  325.  
  326. void Sprite_Erase_Clip(sprite_ptr sprite, unsigned char far *buffer);
  327.  
  328. void Sprite_Draw_Clip(sprite_ptr sprite, unsigned char far *buffer,int transparent);
  329.  
  330. int  Sprite_Collide(sprite_ptr sprite_1, sprite_ptr sprite_2);
  331.  
  332. void Display_Double_Buffer(unsigned char far *buffer,int y);
  333.  
  334. int  Create_Double_Buffer(int num_lines);
  335.  
  336. void Fill_Double_Buffer(int color);
  337.  
  338. void Delete_Double_Buffer(void);
  339.  
  340. void Screen_Transition(int effect);
  341.  
  342. void Wait_For_Vertical_Retrace(void);
  343.  
  344. void fwordcpy(void far *destination, void far *source,int num_words);
  345.  
  346. void Bitmap_Get(bitmap_ptr image, unsigned char far *source);
  347.  
  348. void Bitmap_Put(bitmap_ptr image, unsigned char far *destination,int transparent);
  349.  
  350. int Bitmap_Allocate(bitmap_ptr image, int width, int height);
  351.  
  352. void Bitmap_Delete(bitmap_ptr the_bitmap);
  353.  
  354. int Layer_Create(layer_ptr dest_layer, int width, int height);
  355.  
  356. void Layer_Build(layer_ptr dest_layer,int dest_x, int dest_y,
  357.                 unsigned char far *source_buffer,int source_x,int source_y,
  358.                 int width,int height);
  359.  
  360. void Layer_Draw(layer_ptr source_layer, int source_x, int source_y,
  361.                 unsigned char far *dest_buffer,int dest_y,int dest_height,
  362.                 int transparent);
  363.  
  364. void Layer_Delete(layer_ptr the_layer);
  365.  
  366. void Print_Char_DB(int xc,int yc,char c,int color,int transparent);
  367.  
  368. void Print_String_DB(int x,int y,int color, char *string,int transparent);
  369.  
  370. void Write_Pixel_DB(int x,int y,int color);
  371.  
  372. int Read_Pixel_DB(int x,int y);
  373.  
  374. void Set_Working_Page_Mode_Z(int page);
  375.  
  376. void Set_Visual_Page_Mode_Z(int page);
  377.  
  378. extern void PCX_show_da_buffer(void);
  379.  
  380. extern void Display_da_double_buffer(void);
  381.  
  382. extern void Fill_da_double_buffer(void);
  383.  
  384. extern void copy_da_fword(void);
  385.  
  386. void Tech_Print(int x,int y,char *string,unsigned char far *destination);
  387.  
  388. void Font_Engine_1(int x,int y,
  389.                    int font,int color,
  390.                    char *string,unsigned char far *destination);
  391.  
  392.  
  393. // E X T E R N A L S /////////////////////////////////////////////////////////////
  394.  
  395. extern unsigned char far *video_buffer;   // video ram byte ptr
  396. extern unsigned char far *rom_char_set;   // rom characters 8x8
  397. extern unsigned char far *double_buffer;     // the double buffer
  398.  
  399. extern unsigned int double_buffer_height;    // height of double buffer
  400.  
  401. extern unsigned int double_buffer_size;      // total size of buffer in bytes
  402.  
  403. extern unsigned int sprite_width;            // width of a sprite
  404.  
  405. extern unsigned int sprite_height;           // of a sprite
  406.  
  407. extern unsigned char far *page_0_buffer;     // pointer to mode z page 0
  408.  
  409. extern unsigned char far *page_1_buffer;     // pointer to mode z page 0
  410.  
  411. extern int mode_z_page;                      // current mode z page
  412.  
  413. extern int raw_key;                  // the global raw keyboard data aquired from the ISR
  414. extern int key_table[4]; // the key state table for the motion keys
  415. extern unsigned int far *clock; // pointer to internal
  416.  
  417. extern sprite shell;
  418. extern pcx_picture background, shell_back, ships_back;
  419. extern bitmap tech_font[NUM_TECH_FONT];
  420.  
  421.