forked from keendreams/keen
-
Notifications
You must be signed in to change notification settings - Fork 2
/
id_vw.h
389 lines (298 loc) · 10.4 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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/* Keen Dreams (SDL2/Steam Port) Source Code
* Copyright (C) 2014 Javier M. Chavez
* Copyright (C) 2015 David Gow <[email protected]>
*
* 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 VW_MMAP_RINGBUFFER
#define G_P_SHIFT 4 // global >> ?? = pixels
#if GRMODE == EGAGR
#define SCREENWIDTH 64*8
#define CHARWIDTH 8
#define TILEWIDTH 16
#endif
#if GRMODE == CGAGR
#define SCREENWIDTH 128
#define CHARWIDTH 2
#define TILEWIDTH 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 8
#define WHITE (fakecga?3:15) // graphics mode independant colors
#define BLACK 0
#define FIRSTCOLOR 1
#define SECONDCOLOR (fakecga?2:12)
#define F_WHITE 0 // for XOR font drawing
#define F_BLACK (fakecga?3:15)
#define F_FIRSTCOLOR (fakecga?2:14)
#define F_SECONDCOLOR (fakecga?1:3)
#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
//===========================================================================
typedef enum {NOcard,MDAcard,CGAcard,EGAcard,MCGAcard,VGAcard,
HGCcard=0x80,HGCPcard,HICcard} cardtype;
PACKED(spritetabletype)
{
int16_t width,
height,
orgx,orgy,
xl,yl,xh,yh,
shifts;
} spritetabletype;
PACKED(pictabletype)
{
int16_t width,height;
} pictabletype;
PACKED(fontstruct)
{
int16_t height;
int16_t 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 boolean fakecga; // is fake cga mode enabled (cga pallete + behaviour)
extern boolean aspectcorrect; // Correct aspect ratio.
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
#define VW_VIDEOMEM_SIZE (4096 * 128) // This must be a multiple of PAGE_SIZE
extern uint8_t *vw_videomem;
extern unsigned screenseg; // normally 0xa000 or buffer segment
extern unsigned linewidth;
extern unsigned ylookup[VIRTUALHEIGHT];
extern boolean screenfaded;
extern pictabletype *pictable;
extern pictabletype *picmtable;
extern spritetabletype *spritetable;
extern int px,py;
extern byte pdrawmode,fontcolor;
//
// asm globals
//
extern word **shifttabletable;
extern uint8_t VW_CurrentRGBPalette[16][3];
//===========================================================================
extern unsigned lastdrawnbuffer;
extern unsigned lastdrawnpan;
void VW_GL_UpdateGLBuffer();
//===========================================================================
void VW_Startup (void);
void VW_Shutdown (void);
cardtype VW_VideoID (void);
//
// EGA hardware routines
//
// XXX: See Abrash's Black Book for details as to what was here
#define EGAWRITEMODE(x)
#define EGABITMASK(x)
#define EGAMAPMASK(x)
void VW_SetLineWidth(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_SetDefaultColors(void);
void VW_FadeOut(void);
void VW_FadeIn(void);
void VW_FadeUp(void);
void VW_FadeDown(void);
//
// 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_ScreenToMem(unsigned source,memptr dest,unsigned width,unsigned height);
void VW_ScreenToScreen(unsigned source,unsigned dest,unsigned width,unsigned height);
void VW_RawMemToScreen(memptr source,unsigned dest,unsigned width,unsigned height);
void VW_RawScreenToMem(unsigned source,memptr dest,unsigned width,unsigned height);
void VW_RawBlitToScreen(memptr source, unsigned dest, unsigned wide, 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),8,8,8)
#define VW_DrawTile16(x,y,t) \
VW_MemToScreen(grsegs[STARTTILE16+t],bufferofs+ylookup[y]+(x),16,16)
#define VW_DrawTile16M(x,y,t) \
VW_MaskBlock(grsegs[STARTTILE16M],(t)*160,bufferofs+ylookup[y]+(x),16,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_DrawMPic(unsigned x, unsigned 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);
extern boolean cursorhw; // Are we using a hardware cursor?
extern int cursorvisible;
//
// 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);
//===========================================================================
//
// Video memory mapping functions
//
void VWL_SetupVideoMemory();
//===========================================================================
//
// Omnispeak conversion utility functions.
//
void VW_UnmaskedToPAL8(void *src,void *dest, int x, int y, int pitch, int w, int h);
void VW_UnmaskedSubRectToPAL8(void *src,void *dest, int x, int y, int pitch, int w, int h, int planesize, int planepitch);
void VW_MaskedToRGBA(void *src,void *dest, int x, int y, int pitch, int w, int h);
void VW_MaskedToPAL8(void *src,void *dest, int x, int y, int pitch, int w, int h);
void VW_MaskedBlitToPAL8(void *src,void *dest, int x, int y, int pitch, int w, int h);
void VW_MaskedBlitWPlaneSizeToPAL8(void *src,void *dest, int x, int y, int pitch, int w, int h, int planesize);
void VW_1bppXorWithPAL8(void *src,void *dest, int x, int y, int pitch, int w, int h, int colour);
void VW_PAL8ScaleToRGBA(void *src,void *dest, int xscale, int yscale, int pitch, int w, int h);
//===========================================================================
//
// GL blitting
//
void VW_GL_Init();
void VW_GL_UpdateLineWidth();
void VW_GL_UpdateGLBuffer();
void VW_GL_GetViewport(int *x, int *y, int *w, int *h);
void VW_GL_Present();
//===========================================================================