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
|
/*******************************************************************
*
* gfs_dos.c graphics utility fullscreen Dos driver. 1.0
*
* This is the driver for fullscreen Dos display, used by the
* graphics utility of the FreeType test suite.
*
* Copyright 1996-2002 by
* David Turner, Robert Wilhelm, and Werner Lemberg.
*
* This file is part of the FreeType project, and may only be used
* modified and distributed under the terms of the FreeType project
* license, LICENSE.TXT. By continuing to use, modify or distribute
* this file you indicate that you have read the license and
* understand and accept it fully.
*
******************************************************************/
#include <stdio.h>
#include <stdlib.h>
#if defined( __STDC__ ) || defined( __TURBOC__ )
#include <string.h>
#else
#include <memory.h>
#endif
#include "gdriver.h"
#include "gevents.h"
#include "gmain.h"
/* The following #ifdef are used to define the following macros : */
/* */
/* - int86 : function to call an interrupt */
/* - reg_ax : the 'ax' register as stored in the REGS struct */
/* */
/* ---- DJGPP dos compiler support --------------------------------------- */
#if defined( __DJGPP__ ) || defined( __DJGPP ) || defined( __GO32__ )
#undef __STRICT_ANSI__
#ifndef DJGPP
#define DJGPP
#endif
#include <dos.h>
#include <conio.h>
#include <go32.h>
#if !defined( __DJGPP__ )
/* DJGPP v1.x */
const int djgpp_use_nearpointers = 0; /* V.1 did not know about them */
#else
/* DJGPP v2.x */
#ifdef DJGPP_NEAR_POINTERS
#include <sys/nearptr.h>
int djgpp_use_nearpointers = -1; /* to be tested if they works */
#else
const int djgpp_use_nearpointers = 0; /* don't even try */
#endif
#endif /* DJGPP v.? */
#define int86( a, b, c ) int86( a, b, c )
#define reg_ax regs.x.ax
#endif
/* ---- Microsoft C compilers support ------------------------------------ */
#if defined( M_I86 ) || defined( _M_I86 )
#include <dos.h>
#include <conio.h>
#define reg_ax regs.x.ax
#ifdef _M_I86 /* a recent compiler, which do not pollute name spaces */
#define getch() _getch()
#define REGS _REGS
#define int86( a, b, c ) _int86( a, b, c )
#else
#define int86( a, b, c ) int86( a, b, c )
#endif
#ifndef MK_FP
#ifdef _MK_FP
#define MK_FP( seg, ofs ) _MK_FP( seg, ofs )
#else
#ifndef _M_I86 /* old versions */
#define __far _far
#endif
#define MK_FP( seg, offset ) (void __far *)( ((unsigned long)seg << 16) + \
(unsigned long)(unsigned)offset )
#endif /* _MK_FP */
#endif /* MK_FP */
#endif /* Microsoft compilers */
/* ---- Borland C compiler support --------------------------------------- */
#ifdef __TURBOC__
#ifdef __STDC__
#error "MK_FP is incompatible with ANSI mode. Use the `-A-' switch."
#endif
#include <dos.h> /* Includes the declaration of int86 */
#include <conio.h> /* for getch */
#define reg_ax regs.x.ax
#define int86( a, b, c ) int86( a, b, c )
#endif
/* ---- Phar Lap 286|DOS extender support -------------------------------- */
#ifdef DOSX286
/* The symbol DOSX286 must be specified on the command line. */
#include <phapi.h>
#ifndef FP_SEG
#define FP_SEG(fp) (*((unsigned __far *)&(fp) + 1))
#endif
#endif
/* ---- EMX/Dos compiler support ----------------------------------------- */
#ifdef __EMX__
#include <dos.h>
#include <sys/hw.h>
#include <conio.h> /* for getch */
extern _read_kbd(); /* to avoid an ANSI warning during compilation */
#define int86 _int86
#define reg_ax regs.x.ax
#endif
/* ---- WATCOM Dos/16 & Dos/32 support ----------------------------------- */
#ifdef __WATCOMC__
#include <i86.h>
#define reg_ax regs.w.ax
#ifdef __386__
#define int86 int386
#endif
#endif
#if !defined( reg_ax ) || !defined( int86 )
#error "Your compiler is not (yet) supported. Check the source file!"
#endif
typedef struct _Translator
{
char key;
GEvent event_class;
int event_info;
} Translator;
#define NUM_Translators 20
static const Translator trans[NUM_Translators] =
{
{ (char)27, event_Quit, 0 },
{ 'q', event_Quit, 0 },
{ 'x', event_Rotate_Glyph, -1 },
{ 'c', event_Rotate_Glyph, 1 },
{ 'v', event_Rotate_Glyph, -16 },
{ 'b', event_Rotate_Glyph, 16 },
{ '{', event_Change_Glyph, -10000 },
{ '}', event_Change_Glyph, 10000 },
{ '(', event_Change_Glyph, -1000 },
{ ')', event_Change_Glyph, 1000 },
{ '9', event_Change_Glyph, -100 },
{ '0', event_Change_Glyph, 100 },
{ 'i', event_Change_Glyph, -10 },
{ 'o', event_Change_Glyph, 10 },
{ 'k', event_Change_Glyph, -1 },
{ 'l', event_Change_Glyph, 1 },
{ '+', event_Scale_Glyph, 10 },
{ '-', event_Scale_Glyph, -10 },
{ 'u', event_Scale_Glyph, 1 },
{ 'j', event_Scale_Glyph, -1 }
};
/* Set Graphics Mode */
int Driver_Set_Graphics( int mode )
{
union REGS regs;
switch ( mode )
{
case Graphics_Mode_Mono: /* Standard VGA 640x480x16 mode */
reg_ax = 0x12;
int86( 0x10, ®s, ®s );
vio_ScanLineWidth = 80;
vio_Width = 640;
vio_Height = 480;
break;
case Graphics_Mode_Gray: /* Standard VGA 320x200x256 mode */
reg_ax = 0x13;
int86( 0x10, ®s, ®s );
vio_ScanLineWidth = 320;
vio_Width = 320;
vio_Height = 200;
/* default gray_palette takes the gray levels of the standard VGA */
/* 256 colors mode */
gray_palette[0] = 0;
gray_palette[1] = 23;
gray_palette[2] = 27;
gray_palette[3] = 29;
gray_palette[4] = 31;
break;
default:
return 0; /* failure */
}
#if defined( __EMX__ )
Vio = _memaccess( 0xA0000, 0xAFFFF, 1 );
#elif defined( DJGPP )
Vio = (char *)0xA0000;
#elif defined( __WATCOMC__ ) && defined( __386__ )
Vio = (char *)0xA0000;
#elif defined( DOSX286 )
{
unsigned short sel;
if ( DosMapRealSeg( 0xA000, (long)vio_ScanLineWidth*vio_Height, &sel ) )
return 0; /* failure */
Vio = (char*)MK_FP( sel, 0 );
}
#else
Vio = (char*)MK_FP( 0xA000, 0 );
#endif
return 1; /* success */
}
/* Revert to text mode */
int Driver_Restore_Mode()
{
union REGS regs;
reg_ax = 0x3;
int86( 0x10, ®s, ®s );
#ifdef DOSX286
DosFreeSeg( FP_SEG( Vio ) );
#endif
return 1; /* success */
}
int Driver_Display_Bitmap( char* buffer, int line, int col )
{
int y, used_col;
char* target;
#ifdef DJGPP
char cbuf = 0;
int i;
#endif
#ifdef DJGPP_USE_NEAR_POINTERS
if( djgpp_use_nearpointers )
if( ! __djgpp_nearptr_enable() )
/* doesn't work, probably under some real OS like NT or dosemu! */
djgpp_use_nearpointers = 0;
else
Vio += __djgpp_conventional_base;
#endif
#ifdef DJGPP
if( !djgpp_use_nearpointers )
for( i = 0; i < vio_Height*vio_ScanLineWidth; i++ )
dosmemput( &cbuf, 1, (unsigned long) Vio+i );
else
/*FALLTHROUGH*/
#endif
memset( Vio, 0, vio_Height * vio_ScanLineWidth );
if ( line > vio_Height )
line = vio_Height;
if ( col > vio_ScanLineWidth )
used_col = vio_ScanLineWidth;
else
used_col = col;
target = Vio + ( line - 1 ) * vio_ScanLineWidth;
for ( y = 0; y < line; y++ )
{
#ifdef DJGPP
if( !djgpp_use_nearpointers )
dosmemput( buffer, used_col, (unsigned long)target );
else
/*FALLTHROUGH*/
#endif
memcpy( target, buffer, used_col );
target -= vio_ScanLineWidth;
buffer += col;
}
#ifdef DJGPP_USE_NEAR_POINTERS
if( djgpp_use_nearpointers )
{
Vio -= __djgpp_conventional_base;
__djgpp_nearptr_disable();
}
#endif
return 1; /* success */
}
void Get_Event( TEvent* event )
{
int i;
int c;
c = getch();
for ( i = 0; i < NUM_Translators; i++ )
{
if ( c == trans[i].key )
{
event->what = trans[i].event_class;
event->info = trans[i].event_info;
return;
}
}
/* unrecognized keystroke */
event->what = event_Keyboard;
event->info = (int)c;
return;
}
/* End */
|