-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathportab.h
More file actions
396 lines (347 loc) · 12.5 KB
/
portab.h
File metadata and controls
396 lines (347 loc) · 12.5 KB
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
390
391
392
393
394
395
396
/****************************************************************/
/* */
/* portab.h */
/* */
/* DOS-C portability typedefs, etc. */
/* */
/* May 1, 1995 */
/* */
/* Copyright (c) 1995 */
/* Pasquale J. Villani */
/* All Rights Reserved */
/* */
/* This file is part of DOS-C. */
/* */
/* DOS-C 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, or (at your option) any later version. */
/* */
/* DOS-C 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 DOS-C; see the file COPYING. If not, */
/* write to the Free Software Foundation, 675 Mass Ave, */
/* Cambridge, MA 02139, USA. */
/****************************************************************/
#ifdef MAIN
#ifdef VERSION_STRINGS
static char *portab_hRcsId =
"$Id: portab.h 1121 2005-03-15 15:25:08Z perditionc $";
#endif
#endif
/****************************************************************/
/* */
/* Machine dependant portable types. Note that this section is */
/* used primarily for segmented architectures. Common types and */
/* types used relating to segmented operations are found here. */
/* */
/* Be aware that segmented architectures impose on linear */
/* architectures because they require special types to be used */
/* throught the code that must be reduced to empty preprocessor */
/* replacements in the linear machine. */
/* */
/* #ifdef <segmeted machine> */
/* # define FAR far */
/* # define NEAR near */
/* #endif */
/* */
/* #ifdef <linear machine> */
/* # define FAR */
/* # define NEAR */
/* #endif */
/* */
/****************************************************************/
/* commandline overflow - removing -DI86 TE */
#if defined(__TURBOC__)
#define I86
#define CDECL cdecl
#if __TURBOC__ > 0x202
/* printf callers do the right thing for tc++ 1.01 but not tc 2.01 */
#define VA_CDECL
#else
#define VA_CDECL cdecl
#endif
#define PASCAL pascal
void __int__(int);
#ifndef FORSYS
void __emit__(char, ...);
#define disable() __emit__(0xfa)
#define enable() __emit__(0xfb)
#endif
#elif defined(_MSC_VER)
#define I86
#define asm __asm
#pragma warning(disable: 4761) /* "integral size mismatch in argument;
conversion supplied" */
#define CDECL _cdecl
#define VA_CDECL
#define PASCAL pascal
#define __int__(intno) asm int intno;
#define disable() asm cli
#define enable() asm sti
#define _CS getCS()
static unsigned short __inline getCS(void)
{
asm mov ax, cs;
}
#define _SS getSS()
static unsigned short __inline getSS(void)
{
asm mov ax, ss;
}
#elif defined(__WATCOMC__) /* don't know a better way */
#if defined(_M_I86)
#define I86
#define __int__(intno) asm int intno;
void disable(void);
#pragma aux disable = "cli" __modify __exact [];
void enable(void);
#pragma aux enable = "sti" __modify __exact [];
#define asm __asm
#define far __far
#define CDECL __cdecl
#define VA_CDECL
#define PASCAL pascal
#define _CS getCS()
unsigned short getCS(void);
#pragma aux getCS = "mov dx,cs" __value [__dx] __modify __exact[__dx];
#define _SS getSS()
unsigned short getSS(void);
#pragma aux getSS = "mov dx,ss" __value [__dx] __modify __exact[__dx];
#if !defined(FORSYS) && !defined(EXEFLAT) && _M_IX86 >= 300
#pragma aux __default __parm [__ax __dx __cx] __modify [__ax __dx __es __fs] /* min.unpacked size */
#endif
/* enable Possible loss of precision warning for compatibility with Borland */
#pragma enable_message(130)
#else
/* workaround for building some utils with OpenWatcom (flat model) */
#define MC68K
#endif
#elif defined (_MYMC68K_COMILER_)
#define MC68K
#elif defined(__GNUC__)
#ifdef __FAR
#define I86
#define STRINGIFY(x) #x
#define __int__(intno) asm volatile(STRINGIFY(int $##intno))
static inline void disable(void)
{
asm volatile("cli");
}
static inline void enable(void)
{
asm volatile("sti");
}
#define far __far
#define CDECL __attribute__((cdecl))
#define VA_CDECL
#define PASCAL
#define _CS getCS()
static inline unsigned short getCS(void)
{
unsigned short ret;
asm volatile("mov %%cs, %0" : "=r"(ret));
return ret;
}
#define _SS getSS()
static inline unsigned short getSS(void)
{
unsigned short ret;
asm volatile("mov %%ss, %0" : "=r"(ret));
return ret;
}
extern char DosDataSeg[];
#else
/* for warnings only ! */
#define MC68K
#endif
#else
#error Unknown compiler
We might even deal with a pre-ANSI compiler. This will certainly not compile.
#endif
#ifdef I86
#if _M_IX86 >= 300 || defined(M_I386)
#ifndef I386
#define I386
#endif
#elif _M_IX86 >= 100 || defined(M_I286)
#ifndef I186
#define I186
#endif
#endif
#endif
#ifdef MC68K
#define far /* No far type */
#define interrupt /* No interrupt type */
#define VOID void
#define FAR /* linear architecture */
#define NEAR /* " " */
#define INRPT interrupt
#define REG register
#define API int /* linear architecture */
#define NONNATIVE
#define PARASIZE 4096 /* "paragraph" size */
#define CDECL
#define PASCAL
#ifdef __GNUC__
#define CONST const
#define PROTO
typedef __SIZE_TYPE__ size_t;
#else
#define CONST
#if !(defined(_SIZE_T) || defined(_SIZE_T_DEFINED) || defined(__SIZE_T_DEFINED))
typedef unsigned size_t;
#endif
#endif
#endif
#if defined(I86) && !defined(MC68K)
#define VOID void
#define FAR far /* segment architecture */
#define NEAR near /* " " */
#define INRPT interrupt
#define CONST const
#define REG register
#define API int far pascal /* segment architecture */
#define NATIVE
#define PARASIZE 16 /* "paragraph" size */
typedef unsigned size_t;
#endif
/* functions, that are shared between C and ASM _must_
have a certain calling standard. These are declared
as 'ASMCFUNC', and is (and will be ?-) cdecl */
#define ASMCFUNC CDECL
#define ASMPASCAL PASCAL
#if defined(__GNUC__)
#define ASM
#else
#define ASM ASMCFUNC
#endif
/* variables that can be near or far: redefined in init-dat.h */
#define DOSFAR
#define DOSTEXTFAR
/* */
/* Boolean type & definitions of TRUE and FALSE boolean values */
/* */
typedef int BOOL;
#define FALSE (1==0)
#define TRUE (1==1)
/* */
/* Common pointer types */
/* */
#ifndef NULL
#define NULL 0
#endif
/* */
/* Convienence defines */
/* */
#define FOREVER while(TRUE)
#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
/* */
/* Common byte, 16 bit and 32 bit types */
/* */
typedef char BYTE;
typedef short WORD;
typedef long DWORD;
typedef unsigned char UBYTE;
typedef unsigned short UWORD;
typedef unsigned long UDWORD;
typedef short SHORT;
typedef unsigned int BITS; /* for use in bit fields(!) */
typedef int COUNT;
typedef unsigned int UCOUNT;
typedef unsigned long ULONG;
#ifdef WITHFAT32
typedef unsigned long CLUSTER;
#else
typedef unsigned short CLUSTER;
#endif
typedef unsigned short UNICODE;
#if defined(STATICS) || defined(__WATCOMC__) || defined(__GNUC__)
#define STATIC static /* local calls inside module */
#else
#define STATIC
#endif
#ifdef UNIX
typedef char FAR *ADDRESS;
#else
typedef void FAR *ADDRESS;
#endif
#ifdef STRICT
typedef signed long LONG;
#else
#define LONG long
#endif
#if USHRT_MAX == 0xFFFF
# define loword(v) ((unsigned short)(v))
#else
# define loword(v) (0xFFFF & (unsigned)(v))
#endif
#define hiword(v) loword ((v) >> 16u)
#define MK_UWORD(hib,lob) (((UWORD)(hib) << 8u) | (UBYTE)(lob))
#define MK_ULONG(hiw,low) (((ULONG)(hiw) << 16u) | (UWORD)(low))
/* General far pointer macros */
#ifdef I86
#ifndef MK_FP
#if defined(__WATCOMC__)
#define MK_FP(seg,ofs) (((UWORD)(seg)):>((VOID *)(ofs)))
#elif defined(__TURBOC__) && (__TURBOC__ > 0x202)
#define MK_FP(seg,ofs) ((void _seg *)(seg) + (void near *)(ofs))
#else
#define MK_FP(seg,ofs) ((void FAR *)(((ULONG)(seg)<<16)|(UWORD)(ofs)))
#endif
#define pokeb(seg, ofs, b) (*((unsigned char far *)MK_FP(seg,ofs)) = b)
#define poke(seg, ofs, w) (*((unsigned far *)MK_FP(seg,ofs)) = w)
#define pokew poke
#define pokel(seg, ofs, l) (*((unsigned long far *)MK_FP(seg,ofs)) = l)
#define peekb(seg, ofs) (*((unsigned char far *)MK_FP(seg,ofs)))
#define peek(seg, ofs) (*((unsigned far *)MK_FP(seg,ofs)))
#define peekw peek
#define peekl(seg, ofs) (*((unsigned long far *)MK_FP(seg,ofs)))
#if defined(__TURBOC__) && (__TURBOC__ > 0x202)
#define FP_SEG(fp) ((unsigned)(void _seg *)(void far *)(fp))
#else
#define FP_SEG(fp) ((unsigned)((ULONG)(VOID FAR *)(fp)>>16))
#endif
#if defined(__GNUC__) && defined(__BUILTIN_IA16_FP_OFF)
#define FP_OFF(fp) __builtin_ia16_FP_OFF(fp)
#else
#define FP_OFF(fp) ((unsigned)(fp))
#endif
#endif
#endif
#ifdef MC68K
#define MK_FP(seg,ofs) ((VOID *)(&(((BYTE *)(size_t)(seg))[(ofs)])))
#define FP_SEG(fp) (0)
#define FP_OFF(fp) ((size_t)(fp))
#endif
#if defined(__GNUC__) && defined(__FAR)
typedef VOID FAR *intvec;
#else
typedef VOID (FAR ASMCFUNC * intvec) (void);
#endif
#define MK_PTR(type,seg,ofs) ((type FAR*) MK_FP (seg, ofs))
#if __TURBOC__ > 0x202
# define MK_SEG_PTR(type,seg) ((type _seg*) (seg))
#else
# define _seg FAR
# define MK_SEG_PTR(type,seg) MK_PTR (type, seg, 0)
#endif
/*
this suppresses the warning
unreferenced parameter 'x'
and (hopefully) generates no code
*/
#define UNREFERENCED_PARAMETER(x) (void)x;
#ifdef I86 /* commandline overflow - removing /DPROTO TE */
#define PROTO
#endif
#define LENGTH(x) (sizeof(x)/sizeof(x[0]))