-
Notifications
You must be signed in to change notification settings - Fork 5
/
compiler.h
121 lines (91 loc) · 2.69 KB
/
compiler.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
//
//
// Copyright (C) 2023-2024 Frenkel Smeijers
//
// 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, see <https://www.gnu.org/licenses/>.
//
#ifndef __COMPILER__
#define __COMPILER__
#if defined _M_I86
//16-bit
#include <i86.h>
#define D_MK_FP MK_FP
#define D_FP_SEG FP_SEG
#if defined __WATCOMC__
#define D_FP_OFF FP_OFF
#else
#define D_FP_OFF(p) ((uint16_t)((uint32_t)(p)))
#endif
typedef uint16_t segment_t;
#define SIZE_OF_SEGMENT_T 2
#else
//32-bit
#define D_MK_FP(s,o) (void*)((s<<4)+o)
#define D_FP_SEG(p) (((uint32_t)p)>>4)
#define D_FP_OFF(p) (((uint32_t)p)&15)
typedef uint32_t segment_t;
#define SIZE_OF_SEGMENT_T 4
#define __far
#define _fmemchr memchr
#define _fmemcpy memcpy
#define _fmemset memset
#define _fstrcpy strcpy
#define _fstrlen strlen
#endif
#if defined __IA16_SYS_MSDOS
//gcc-ia16
#define _chain_intr(func) func()
#endif
#if defined __DJGPP__
//DJGPP
#include <dpmi.h>
#include <go32.h>
#include <sys/nearptr.h>
//DJGPP doesn't inline inp, outp and outpw,
//but it does inline inportb, outportb and outportw
#define inp(port) inportb(port)
#define outp(port,data) outportb(port,data)
#define __interrupt
#define replaceInterrupt(OldInt,NewInt,vector,handler) \
_go32_dpmi_get_protected_mode_interrupt_vector(vector, &OldInt); \
\
NewInt.pm_selector = _go32_my_cs(); \
NewInt.pm_offset = (int32_t)handler; \
_go32_dpmi_allocate_iret_wrapper(&NewInt); \
_go32_dpmi_set_protected_mode_interrupt_vector(vector, &NewInt)
#define restoreInterrupt(vector,OldInt,NewInt) \
_go32_dpmi_set_protected_mode_interrupt_vector(vector, &OldInt); \
_go32_dpmi_free_iret_wrapper(&NewInt);
#define _chain_intr(OldInt) \
asm \
( \
"cli \n" \
"pushfl \n" \
"lcall *%0" \
: \
: "m" (OldInt.pm_offset) \
)
#else
//Watcom and gcc-ia16
#define __djgpp_nearptr_enable()
#define __djgpp_conventional_base 0
#if defined _M_I386
#define int86 int386
#endif
#define replaceInterrupt(OldInt,NewInt,vector,handler) \
OldInt = _dos_getvect(vector); \
_dos_setvect(vector, handler)
#define restoreInterrupt(vector,OldInt,NewInt) _dos_setvect(vector,OldInt)
#endif
#endif