ID_VW.H 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. /* Catacomb Armageddon Source Code
  2. * Copyright (C) 1993-2014 Flat Rock Software
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. // ID_VW.H
  19. #ifndef __TYPES__
  20. #include "ID_TYPES.H"
  21. #endif
  22. #ifndef __ID_MM__
  23. #include "ID_MM.H"
  24. #endif
  25. #ifndef __ID_GLOB__
  26. #include "ID_GLOB.H"
  27. #endif
  28. #define __ID_VW__
  29. //===========================================================================
  30. #define G_P_SHIFT 4 // global >> ?? = pixels
  31. #if GRMODE == EGAGR
  32. #define SCREENWIDTH 40
  33. #define CHARWIDTH 1
  34. #define TILEWIDTH 2
  35. #define GRPLANES 4
  36. #define BYTEPIXELS 8
  37. #endif
  38. #if GRMODE == CGAGR
  39. #define SCREENWIDTH 128
  40. #define CHARWIDTH 2
  41. #define TILEWIDTH 4
  42. #define GRPLANES 1
  43. #define BYTEPIXELS 4
  44. #endif
  45. #define VIRTUALHEIGHT 300
  46. #define VIRTUALWIDTH 512
  47. #if GRMODE == CGAGR
  48. #define MAXSHIFTS 1
  49. #define WHITE 3 // graphics mode independant colors
  50. #define BLACK 0
  51. #define FIRSTCOLOR 1
  52. #define SECONDCOLOR 2
  53. #define F_WHITE 0 // for XOR font drawing
  54. #define F_BLACK 3
  55. #define F_FIRSTCOLOR 2
  56. #define F_SECONDCOLOR 1
  57. #endif
  58. #if GRMODE == EGAGR
  59. #define MAXSHIFTS 4
  60. #define WHITE 15 // graphics mode independant colors
  61. #define BLACK 0
  62. #define LT_GREY 7
  63. #define FIRSTCOLOR 1
  64. #define SECONDCOLOR 12
  65. #define F_WHITE 0 // for XOR font drawing
  66. #define F_BLACK 15
  67. #define F_FIRSTCOLOR 14
  68. #define F_SECONDCOLOR 3
  69. #endif
  70. #if GRMODE == EGAGR
  71. #define SCREENXMASK (~7)
  72. #define SCREENXPLUS (7)
  73. #define SCREENXDIV (8)
  74. #endif
  75. #if GRMODE == CGAGR
  76. #define SCREENXMASK (~3)
  77. #define SCREENXDIV (4)
  78. #endif
  79. //===========================================================================
  80. #define SC_INDEX 0x3C4
  81. #define SC_RESET 0
  82. #define SC_CLOCK 1
  83. #define SC_MAPMASK 2
  84. #define SC_CHARMAP 3
  85. #define SC_MEMMODE 4
  86. #define CRTC_INDEX 0x3D4
  87. #define CRTC_H_TOTAL 0
  88. #define CRTC_H_DISPEND 1
  89. #define CRTC_H_BLANK 2
  90. #define CRTC_H_ENDBLANK 3
  91. #define CRTC_H_RETRACE 4
  92. #define CRTC_H_ENDRETRACE 5
  93. #define CRTC_V_TOTAL 6
  94. #define CRTC_OVERFLOW 7
  95. #define CRTC_ROWSCAN 8
  96. #define CRTC_MAXSCANLINE 9
  97. #define CRTC_CURSORSTART 10
  98. #define CRTC_CURSOREND 11
  99. #define CRTC_STARTHIGH 12
  100. #define CRTC_STARTLOW 13
  101. #define CRTC_CURSORHIGH 14
  102. #define CRTC_CURSORLOW 15
  103. #define CRTC_V_RETRACE 16
  104. #define CRTC_V_ENDRETRACE 17
  105. #define CRTC_V_DISPEND 18
  106. #define CRTC_OFFSET 19
  107. #define CRTC_UNDERLINE 20
  108. #define CRTC_V_BLANK 21
  109. #define CRTC_V_ENDBLANK 22
  110. #define CRTC_MODE 23
  111. #define CRTC_LINECOMPARE 24
  112. #define GC_INDEX 0x3CE
  113. #define GC_SETRESET 0
  114. #define GC_ENABLESETRESET 1
  115. #define GC_COLORCOMPARE 2
  116. #define GC_DATAROTATE 3
  117. #define GC_READMAP 4
  118. #define GC_MODE 5
  119. #define GC_MISCELLANEOUS 6
  120. #define GC_COLORDONTCARE 7
  121. #define GC_BITMASK 8
  122. #define ATR_INDEX 0x3c0
  123. #define ATR_MODE 16
  124. #define ATR_OVERSCAN 17
  125. #define ATR_COLORPLANEENABLE 18
  126. #define ATR_PELPAN 19
  127. #define ATR_COLORSELECT 20
  128. #define STATUS_REGISTER_1 0x3da
  129. //===========================================================================
  130. typedef enum {NOcard,MDAcard,CGAcard,EGAcard,MCGAcard,VGAcard,
  131. HGCcard=0x80,HGCPcard,HICcard} cardtype;
  132. typedef struct
  133. {
  134. int width,
  135. height,
  136. orgx,orgy,
  137. xl,yl,xh,yh,
  138. shifts;
  139. } spritetabletype;
  140. typedef struct
  141. {
  142. unsigned sourceoffset[MAXSHIFTS];
  143. unsigned planesize[MAXSHIFTS];
  144. unsigned width[MAXSHIFTS];
  145. byte data[];
  146. } spritetype; // the memptr for each sprite points to this
  147. typedef struct
  148. {
  149. int width,height;
  150. } pictabletype;
  151. typedef struct
  152. {
  153. int height;
  154. int location[256];
  155. char width[256];
  156. } fontstruct;
  157. typedef enum {CGAgr,EGAgr,VGAgr} grtype;
  158. //===========================================================================
  159. extern cardtype videocard; // set by VW_Startup
  160. extern grtype grmode; // CGAgr, EGAgr, VGAgr
  161. extern unsigned bufferofs; // hidden port to draw to before displaying
  162. extern unsigned displayofs; // origin of port on visable screen
  163. extern unsigned panx,pany; // panning adjustments inside port in pixels
  164. extern unsigned pansx,pansy;
  165. extern unsigned panadjust; // panx/pany adjusted by screen resolution
  166. extern unsigned screenseg; // normally 0xa000 or buffer segment
  167. extern unsigned linewidth;
  168. extern unsigned ylookup[VIRTUALHEIGHT];
  169. extern boolean screenfaded;
  170. extern char colors[7][17]; // pallets for fades
  171. extern pictabletype _seg *pictable;
  172. extern pictabletype _seg *picmtable;
  173. extern spritetabletype _seg *spritetable;
  174. extern unsigned fontnumber; // 0 based font number for drawing
  175. extern int px,py;
  176. extern byte pdrawmode,fontcolor;
  177. extern int bordercolor;
  178. //
  179. // asm globals
  180. //
  181. extern unsigned *shifttabletable[8];
  182. extern unsigned bufferwidth,bufferheight,screenspot; // used by font drawing stuff
  183. //===========================================================================
  184. void VW_Startup (void);
  185. void VW_Shutdown (void);
  186. cardtype VW_VideoID (void);
  187. //
  188. // EGA hardware routines
  189. //
  190. #define EGAWRITEMODE(x) asm{cli;mov dx,GC_INDEX;mov ax,GC_MODE+256*x;out dx,ax;sti;}
  191. #define EGABITMASK(x) asm{cli;mov dx,GC_INDEX;mov ax,GC_BITMASK+256*x;out dx,ax;sti;}
  192. #define EGAMAPMASK(x) asm{cli;mov dx,SC_INDEX;mov ax,SC_MAPMASK+x*256;out dx,ax;sti;}
  193. #define EGAREADMAP(x) asm{cli;mov dx,GC_INDEX;mov ax,GC_READMAP+x*256;out dx,ax;sti;}
  194. void VW_SetLineWidth(int width);
  195. void VW_SetSplitScreen(int width);
  196. void VW_SetScreen (unsigned CRTC, unsigned pelpan);
  197. void VW_SetScreenMode (int grmode);
  198. void VW_ClearVideo (int color);
  199. void VW_WaitVBL (int number);
  200. void VW_ColorBorder (int color);
  201. void VW_SetPalette(byte *palette);
  202. void VW_SetDefaultColors(void);
  203. void VW_FadeOut(void);
  204. void VW_FadeIn(void);
  205. void VW_FadeUp(void);
  206. void VW_FadeDown(void);
  207. void VW_SetAtrReg (int reg, int value);
  208. //
  209. // block primitives
  210. //
  211. void VW_MaskBlock(memptr segm,unsigned ofs,unsigned dest,
  212. unsigned wide,unsigned height,unsigned planesize);
  213. void VW_MemToScreen(memptr source,unsigned dest,unsigned width,unsigned height);
  214. void VW_MemToScreen2x(memptr source,unsigned dest,unsigned width,unsigned height);
  215. void VW_ScreenToMem(unsigned source,memptr dest,unsigned width,unsigned height);
  216. void VW_ScreenToScreen(unsigned source,unsigned dest,unsigned width,unsigned height);
  217. //
  218. // block addressable routines
  219. //
  220. void VW_DrawTile8(unsigned x, unsigned y, unsigned tile);
  221. #if GRMODE == EGAGR
  222. #define VW_DrawTile8M(x,y,t) \
  223. VW_MaskBlock(grsegs[STARTTILE8M],(t)*40,bufferofs+ylookup[y]+(x),1,8,8)
  224. #define VW_DrawTile16(x,y,t) \
  225. VW_MemToScreen(grsegs[STARTTILE16+t],bufferofs+ylookup[y]+(x),2,16)
  226. #define VW_DrawTile16M(x,y,t) \
  227. VW_MaskBlock(grsegs[STARTTILE16M],(t)*160,bufferofs+ylookup[y]+(x),2,16,32)
  228. #endif
  229. #if GRMODE == CGAGR
  230. #define VW_DrawTile8M(x,y,t) \
  231. VW_MaskBlock(grsegs[STARTTILE8M],(t)*32,bufferofs+ylookup[y]+(x),2,8,16)
  232. #define VW_DrawTile16(x,y,t) \
  233. VW_MemToScreen(grsegs[STARTTILE16+t],bufferofs+ylookup[y]+(x),4,16)
  234. #define VW_DrawTile16M(x,y,t) \
  235. VW_MaskBlock(grsegs[STARTTILE16M],(t)*128,bufferofs+ylookup[y]+(x),4,16,64)
  236. #endif
  237. void VW_DrawPic(unsigned x, unsigned y, unsigned chunknum);
  238. void VW_DrawPic2x(unsigned x, unsigned y, unsigned chunknum);
  239. void VW_DrawMPic(unsigned x, unsigned y, unsigned chunknum);
  240. void VW_ClipDrawMPic(unsigned x, int y, unsigned chunknum);
  241. //
  242. // pixel addressable routines
  243. //
  244. void VW_MeasurePropString (char far *string, word *width, word *height);
  245. void VW_MeasureMPropString (char far *string, word *width, word *height);
  246. void VW_DrawPropString (char far *string);
  247. void VW_DrawMPropString (char far *string);
  248. void VW_DrawSprite(int x, int y, unsigned sprite);
  249. void VW_Plot(unsigned x, unsigned y, unsigned color);
  250. void VW_Hlin(unsigned xl, unsigned xh, unsigned y, unsigned color);
  251. void VW_Vlin(unsigned yl, unsigned yh, unsigned x, unsigned color);
  252. void VW_Bar (unsigned x, unsigned y, unsigned width, unsigned height,
  253. unsigned color);
  254. //===========================================================================
  255. //
  256. // Double buffer management routines
  257. //
  258. void VW_InitDoubleBuffer (void);
  259. void VW_FixRefreshBuffer (void);
  260. int VW_MarkUpdateBlock (int x1, int y1, int x2, int y2);
  261. void VW_UpdateScreen (void);
  262. void VW_CGAFullUpdate (void);
  263. //
  264. // cursor
  265. //
  266. void VW_ShowCursor (void);
  267. void VW_HideCursor (void);
  268. void VW_MoveCursor (int x, int y);
  269. void VW_SetCursor (int spritenum);
  270. void VW_FreeCursor (void);
  271. //
  272. // mode independant routines
  273. // coordinates in pixels, rounded to best screen res
  274. // regions marked in double buffer
  275. //
  276. void VWB_DrawTile8 (int x, int y, int tile);
  277. void VWB_DrawTile8M (int x, int y, int tile);
  278. void VWB_DrawTile16 (int x, int y, int tile);
  279. void VWB_DrawTile16M (int x, int y, int tile);
  280. void VWB_DrawPic (int x, int y, int chunknum);
  281. void VWB_DrawMPic(int x, int y, int chunknum);
  282. void VWB_Bar (int x, int y, int width, int height, int color);
  283. void VWB_DrawPropString (char far *string);
  284. void VWB_DrawMPropString (char far *string);
  285. void VWB_DrawSprite (int x, int y, int chunknum);
  286. void VWB_Plot (int x, int y, int color);
  287. void VWB_Hlin (int x1, int x2, int y, int color);
  288. void VWB_Vlin (int y1, int y2, int x, int color);
  289. void VWL_MeasureString (char far *string, word *width, word *height, fontstruct _seg *font);
  290. //===========================================================================