-
Notifications
You must be signed in to change notification settings - Fork 1
/
EMS.CPP
203 lines (188 loc) · 4.07 KB
/
EMS.CPP
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
#include <dos.h>
#include "famegraf.h"
#include "ems.h"
int EmsError=-1; //®è¨¡ª -á®áâ EMS ¤¯ ©¢¥à
int EmsPresent=0; //®è¨¡ª -á®áâ EMS ¤¯ ©¢¥à
int EmsInstalled(void) {
//¥áâì «¨ EMS 4.0?
static char *EmmName="EMMXXXX0";
block EmmPtr;
_AX=0x3567;
geninterrupt(0x21);
EmmPtr=(block)MK_FP(_ES,0x0a);
while( *EmmName ) {
if( *EmmName++ != *EmmPtr++ )
return (EmsError=NOTINSTALLED);
}
EmsPresent=1;
return (EmsError=NOERROR);
}
int EmsVersion(void) {
//®¯à¥¤ N ¢¥àᨨ EMS
if( EmsPresent==0 ) {
return 0;
}
_AH=0x46;
geninterrupt(0x67);
if( _AH ) {
EmsError=_AH;
return 0;
}
EmsError=0;
return _AL;
}
int EmsPagesAvail(void) {
//¢ë¤ ¥â ª®«-¢® ᢮¡®¤ëå «®£¨ç áâà ¨æ
if( EmsPresent==0 ) {
return -1;
}
_AH=0x42;
geninterrupt(0x67);
if( _AH ) {
EmsError=_AH;
return -1;
}
EmsError=0;
return _BX;
}
int EmsAlloc(int Pages) {
//¢®ááâ map ⥪ handle ¢® ¢. ®¡« EMS
if( EmsPresent==0 ) {
return -1;
}
_BX=Pages;
_AH=0x43;
geninterrupt(0x67);
if( _AH ) {
EmsError=_AH;
return -1;
}
EmsError=0;
return (_DX);
}
block EmsFrameAdr(void) {
//¢®ááâ map ⥪ handle ¢® ¢. ®¡« EMS
if( EmsPresent==0 ) {
return NULL;
}
_AH=0x41;
geninterrupt(0x67);
if( _AH ) {
EmsError=_AH;
return (block)0;
}
EmsError=0;
return (block)MK_FP(_BX,0);
}
int EmsMap(int Handle, int Pages[]) {
//®â®¡à ¦ «®£¨ç áâà ¨æ á n ¨§ pages[]
register int i;
if( EmsPresent==0 ) {
return -1;
}
//¯®áâà ª àâë ®â®¡à ¦ ¤«ï 4å áâà ¨æ
for( i=0; i<4; ++i ) {
_BX=Pages[i];
_DX=Handle;
_AH=0x44;
_AL=(char)i;
geninterrupt(0x67);
if( _AH ) {
EmsError=_AH;
return -1;
}
}
EmsError=0;
return 0;
}
int EmsFree(int Handle) {
//®á¢®¡®¤¨âì «®£¨ç áâà . § handle
if( EmsPresent==0 ) {
return -1;
}
_DX=Handle;
_AH=0x45;
geninterrupt(0x67);
if( _AH ) {
EmsError=_AH;
return -1;
}
EmsError=0;
return 0;
}
int EmsSave(int Handle) {
//á®åà ⥪ map ⥪ handle ¢® ¢. ®¡« EMS
if( EmsPresent==0 ) {
return -1;
}
_DX=Handle;
_AH=0x47;
geninterrupt(0x67);
if( _AH ) {
EmsError=_AH;
return -1;
}
EmsError=0;
return 0;
}
int EmsRestore(int Handle) {
//¢®ááâ map ⥪ handle ¢® ¢. ®¡« EMS
if( EmsPresent==0 ) {
return -1;
}
_DX=Handle;
_AH=0x48;
geninterrupt(0x67);
if( _AH ) {
EmsError=_AH;
return -1;
}
EmsError=0;
return 0;
}
char * EMMerror[]=
{
"Internal error in EMM driver",
"EMS memory board hardware malfunction",
"EMM is busy",
"Invalid handle",
"Undefined function requested",
"No more EMM handles available",
"Error in save or restore of mapping context",
"Allocation request was larger than total EMS memory",
"Allocation request was larger than available pages",
"You can't open a handle with a page count of 0",
"Your handle doesn't own that many pages",
"Illegal mapping. Only physical pages 0-3 are defined",
"Mapping context save area is full",
"You can save context only once per handle",
"You can't restore context without a prior save",
"Subfunction parameter in AL not defined",
/* EMS 4.0 new error codes */
"Attribute type undefined",
"Non-volatility not supported",
"Source and dest overlap in EMS RAM (warning, not error)",
"Destination area in handle too small",
"Conventional memory overlaps EMS RAM",
"Offset too large in block move",
"Block size too large; ie, > 1M",
"Source and dest are in same handle and overlap",
"Source or dest memory type invalid (in offset 4 of packet)",
"Alternate map register set in not supported",
"All alternate map/DMA register sets are all allocated",
"All alternate map/DMA register sets are not supported",
"Specified alternate map/DMA register set invalid or in use",
"Dedicated DMA channels are not supported",
"Specified DMA channel is not supported",
"No handle matches specified name",
"The specified name already exists",
"Source offset+region length > 1M (attempted to wrap)",
"Contents of specified data packet are corrupted or invalid",
"Access to this function has been denied (bad access key)"
};
char *getEMMerror(int errnum){
if(!errnum) return "¥â ®è¨¡®ª";
if(errnum<0x80 || errnum>0xA4) return "¥¨§¢¥áâ ï ®è¨¡ª ";
return EMMerror[errnum-0x80];
}