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