1 /* Reconstructed Commander Keen 4-6 Source Code
\r
2 * Copyright (C) 2021 K1n9_Duk3
\r
4 * This file is primarily based on:
\r
5 * Catacomb 3-D Source Code
\r
6 * Copyright (C) 1993-2014 Flat Rock Software
\r
8 * This program is free software; you can redistribute it and/or modify
\r
9 * it under the terms of the GNU General Public License as published by
\r
10 * the Free Software Foundation; either version 2 of the License, or
\r
11 * (at your option) any later version.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
16 * GNU General Public License for more details.
\r
18 * You should have received a copy of the GNU General Public License along
\r
19 * with this program; if not, write to the Free Software Foundation, Inc.,
\r
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
26 #include "ID_TYPES.H"
\r
34 #include "ID_GLOB.H"
\r
39 //===========================================================================
\r
41 #define G_P_SHIFT 4 // global >> ?? = pixels
\r
45 #define SCREENWIDTH 40
\r
47 #define SCREENWIDTH 64
\r
52 #define BYTEPIXELS 8
\r
56 #define SCREENWIDTH 128
\r
60 #define BYTEPIXELS 4
\r
63 #define VIRTUALHEIGHT 300
\r
64 #define VIRTUALWIDTH 512
\r
71 #define WHITE 3 // graphics mode independant colors
\r
73 #define FIRSTCOLOR 1
\r
74 #define SECONDCOLOR 2
\r
75 #define F_WHITE 0 // for XOR font drawing
\r
77 #define F_FIRSTCOLOR 2
\r
78 #define F_SECONDCOLOR 1
\r
86 #define WHITE 15 // graphics mode independant colors
\r
88 #define FIRSTCOLOR 1
\r
89 #define SECONDCOLOR 12
\r
90 #define F_WHITE 0 // for XOR font drawing
\r
92 #define F_FIRSTCOLOR 14
\r
93 #define F_SECONDCOLOR 3
\r
98 #define SCREENXMASK (~7)
\r
99 #define SCREENXPLUS (7)
\r
100 #define SCREENXDIV (8)
\r
103 #if GRMODE == CGAGR
\r
104 #define SCREENXMASK (~3)
\r
105 #define SCREENXDIV (4)
\r
108 //===========================================================================
\r
111 #define SC_INDEX 0x3C4
\r
114 #define SC_MAPMASK 2
\r
115 #define SC_CHARMAP 3
\r
116 #define SC_MEMMODE 4
\r
118 #define CRTC_INDEX 0x3D4
\r
119 #define CRTC_H_TOTAL 0
\r
120 #define CRTC_H_DISPEND 1
\r
121 #define CRTC_H_BLANK 2
\r
122 #define CRTC_H_ENDBLANK 3
\r
123 #define CRTC_H_RETRACE 4
\r
124 #define CRTC_H_ENDRETRACE 5
\r
125 #define CRTC_V_TOTAL 6
\r
126 #define CRTC_OVERFLOW 7
\r
127 #define CRTC_ROWSCAN 8
\r
128 #define CRTC_MAXSCANLINE 9
\r
129 #define CRTC_CURSORSTART 10
\r
130 #define CRTC_CURSOREND 11
\r
131 #define CRTC_STARTHIGH 12
\r
132 #define CRTC_STARTLOW 13
\r
133 #define CRTC_CURSORHIGH 14
\r
134 #define CRTC_CURSORLOW 15
\r
135 #define CRTC_V_RETRACE 16
\r
136 #define CRTC_V_ENDRETRACE 17
\r
137 #define CRTC_V_DISPEND 18
\r
138 #define CRTC_OFFSET 19
\r
139 #define CRTC_UNDERLINE 20
\r
140 #define CRTC_V_BLANK 21
\r
141 #define CRTC_V_ENDBLANK 22
\r
142 #define CRTC_MODE 23
\r
143 #define CRTC_LINECOMPARE 24
\r
146 #define GC_INDEX 0x3CE
\r
147 #define GC_SETRESET 0
\r
148 #define GC_ENABLESETRESET 1
\r
149 #define GC_COLORCOMPARE 2
\r
150 #define GC_DATAROTATE 3
\r
151 #define GC_READMAP 4
\r
153 #define GC_MISCELLANEOUS 6
\r
154 #define GC_COLORDONTCARE 7
\r
155 #define GC_BITMASK 8
\r
157 #define ATR_INDEX 0x3c0
\r
158 #define ATR_MODE 16
\r
159 #define ATR_OVERSCAN 17
\r
160 #define ATR_COLORPLANEENABLE 18
\r
161 #define ATR_PELPAN 19
\r
162 #define ATR_COLORSELECT 20
\r
164 #define STATUS_REGISTER_1 0x3da
\r
166 //===========================================================================
\r
168 typedef enum {NOcard,MDAcard,CGAcard,EGAcard,MCGAcard,VGAcard,
\r
169 HGCcard=0x80,HGCPcard,HICcard} cardtype;
\r
182 unsigned sourceoffset[MAXSHIFTS];
\r
183 unsigned planesize[MAXSHIFTS];
\r
184 unsigned width[MAXSHIFTS];
\r
186 } spritetype; // the memptr for each sprite points to this
\r
202 typedef enum {CGAgr,EGAgr,VGAgr} grtype;
\r
204 //===========================================================================
\r
206 extern cardtype videocard; // set by VW_Startup
\r
207 extern grtype grmode; // CGAgr, EGAgr, VGAgr
\r
209 extern unsigned bufferofs; // hidden port to draw to before displaying
\r
210 extern unsigned displayofs; // origin of port on visable screen
\r
211 extern unsigned panx,pany; // panning adjustments inside port in pixels
\r
212 extern unsigned pansx,pansy;
\r
213 extern unsigned panadjust; // panx/pany adjusted by screen resolution
\r
215 extern unsigned screenseg; // normally 0xa000 or buffer segment
\r
217 extern unsigned linewidth;
\r
218 extern unsigned ylookup[VIRTUALHEIGHT];
\r
220 extern boolean screenfaded;
\r
221 extern char colors[7][17]; // pallets for fades
\r
223 extern pictabletype _seg *pictable;
\r
224 extern pictabletype _seg *picmtable;
\r
225 extern spritetabletype _seg *spritetable;
\r
227 extern unsigned fontnumber; // 0 based font number for drawing
\r
229 extern byte pdrawmode,fontcolor;
\r
231 extern int bordercolor;
\r
232 extern boolean nopan;
\r
238 extern unsigned *shifttabletable[8];
\r
239 extern unsigned bufferwidth,bufferheight,screenspot; // used by font drawing stuff
\r
243 //===========================================================================
\r
246 void VW_Startup (void);
\r
247 void VW_Shutdown (void);
\r
249 cardtype VW_VideoID (void);
\r
252 // EGA hardware routines
\r
255 #define EGAWRITEMODE(x) asm{cli;mov dx,GC_INDEX;mov ax,GC_MODE+256*x;out dx,ax;sti;}
\r
256 #define EGABITMASK(x) asm{cli;mov dx,GC_INDEX;mov ax,GC_BITMASK+256*x;out dx,ax;sti;}
\r
257 #define EGAMAPMASK(x) asm{cli;mov dx,SC_INDEX;mov ax,SC_MAPMASK+x*256;out dx,ax;sti;}
\r
258 #define EGAREADMAP(x) asm{cli;mov dx,GC_INDEX;mov ax,GC_READMAP+x*256;out dx,ax;sti;}
\r
260 void VW_SetLineWidth(int width);
\r
261 void VW_SetSplitScreen(int width);
\r
262 void VW_SetScreen (unsigned CRTC, unsigned pelpan);
\r
264 void VW_SetScreenMode (int grmode);
\r
265 void VW_ClearVideo (int color);
\r
266 void VW_WaitVBL (int number);
\r
268 void VW_ColorBorder (int color);
\r
269 void VW_SetPalette(byte *palette);
\r
270 void VW_SetDefaultColors(void);
\r
271 void VW_FadeOut(void);
\r
272 void VW_FadeIn(void);
\r
273 void VW_FadeUp(void);
\r
274 void VW_FadeDown(void);
\r
276 void VW_SetAtrReg (int reg, int value);
\r
279 // block primitives
\r
282 void VW_MaskBlock(memptr segm,unsigned ofs,unsigned dest,
\r
283 unsigned wide,unsigned height,unsigned planesize);
\r
284 void VW_InverseMask(memptr segm,unsigned ofs,unsigned dest,
\r
285 unsigned wide,unsigned height);
\r
286 void VW_MemToScreen(memptr source,unsigned dest,unsigned width,unsigned height);
\r
287 void VW_ScreenToMem(unsigned source,memptr dest,unsigned width,unsigned height);
\r
288 void VW_ScreenToScreen(unsigned source,unsigned dest,unsigned width,unsigned height);
\r
292 // block addressable routines
\r
295 void VW_DrawTile8(unsigned x, unsigned y, unsigned tile);
\r
297 #if GRMODE == EGAGR
\r
299 #define VW_DrawTile8M(x,y,t) \
\r
300 VW_MaskBlock(grsegs[STARTTILE8M],(t)*40,bufferofs+ylookup[y]+(x),1,8,8)
\r
301 #define VW_DrawTile16(x,y,t) \
\r
302 VW_MemToScreen(grsegs[STARTTILE16+t],bufferofs+ylookup[y]+(x),2,16)
\r
303 #define VW_DrawTile16M(x,y,t) \
\r
304 VW_MaskBlock(grsegs[STARTTILE16M],(t)*160,bufferofs+ylookup[y]+(x),2,16,32)
\r
308 #if GRMODE == CGAGR
\r
310 #define VW_DrawTile8M(x,y,t) \
\r
311 VW_MaskBlock(grsegs[STARTTILE8M],(t)*32,bufferofs+ylookup[y]+(x),2,8,16)
\r
312 #define VW_DrawTile16(x,y,t) \
\r
313 VW_MemToScreen(grsegs[STARTTILE16+t],bufferofs+ylookup[y]+(x),4,16)
\r
314 #define VW_DrawTile16M(x,y,t) \
\r
315 VW_MaskBlock(grsegs[STARTTILE16M],(t)*128,bufferofs+ylookup[y]+(x),4,16,64)
\r
319 void VW_DrawPic(unsigned x, unsigned y, unsigned chunknum);
\r
320 void VW_DrawMPic(unsigned x, unsigned y, unsigned chunknum);
\r
321 void VW_ClipDrawMPic(unsigned x, int y, unsigned chunknum);
\r
324 // pixel addressable routines
\r
326 void VW_MeasurePropString (char far *string, word *width, word *height);
\r
327 void VW_MeasureMPropString (char far *string, word *width, word *height);
\r
329 void VW_DrawPropString (char far *string);
\r
330 void VW_DrawMPropString (char far *string);
\r
331 void VW_DrawSprite(int x, int y, unsigned sprite);
\r
332 void VW_Plot(unsigned x, unsigned y, unsigned color);
\r
333 void VW_Hlin(unsigned xl, unsigned xh, unsigned y, unsigned color);
\r
334 void VW_Vlin(unsigned yl, unsigned yh, unsigned x, unsigned color);
\r
335 void VW_Bar (unsigned x, unsigned y, unsigned width, unsigned height,
\r
338 //===========================================================================
\r
341 // Double buffer management routines
\r
344 void VW_InitDoubleBuffer (void);
\r
345 void VW_FixRefreshBuffer (void);
\r
346 int VW_MarkUpdateBlock (int x1, int y1, int x2, int y2);
\r
347 void VW_UpdateScreen (void);
\r
348 void VW_CGAFullUpdate (void);
\r
354 void VW_ShowCursor (void);
\r
355 void VW_HideCursor (void);
\r
356 void VW_MoveCursor (int x, int y);
\r
357 void VW_SetCursor (int spritenum);
\r
358 void VW_FreeCursor (void);
\r
361 // mode independant routines
\r
362 // coordinates in pixels, rounded to best screen res
\r
363 // regions marked in double buffer
\r
366 void VWB_DrawTile8 (int x, int y, int tile);
\r
367 void VWB_DrawTile8M (int x, int y, int tile);
\r
368 void VWB_DrawTile16 (int x, int y, int tile);
\r
369 void VWB_DrawTile16M (int x, int y, int tile);
\r
370 void VWB_DrawPic (int x, int y, int chunknum);
\r
371 void VWB_DrawMPic(int x, int y, int chunknum);
\r
372 void VWB_Bar (int x, int y, int width, int height, int color);
\r
374 void VWB_DrawPropString (char far *string);
\r
375 void VWB_DrawMPropString (char far *string);
\r
376 void VWB_DrawSprite (int x, int y, int chunknum);
\r
377 void VWB_Plot (int x, int y, int color);
\r
378 void VWB_Hlin (int x1, int x2, int y, int color);
\r
379 void VWB_Vlin (int y1, int y2, int x, int color);
\r
381 //===========================================================================
\r