-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathemsc.cpp
More file actions
executable file
·104 lines (95 loc) · 2.44 KB
/
emsc.cpp
File metadata and controls
executable file
·104 lines (95 loc) · 2.44 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
#include"ems.hpp"
EMS::EMS(unsigned pageCount)
{
REGS regs ;
// first set to "none values"
handle = 0xffff ;
noPages = 0 ;
//if EMS memory not present, give up now
if( EMSPresent() == 0 )
return ;
//otherwise allocate that many from EMS handler
regs.x.bx = pageCount ;
if( EMSCall(0x43,regs) == 0 ) { // if okay ...
handle = regs.x.dx ; // ... save handle
noPages=pageCount ;
}
}
EMS::~EMS()
{
union REGS regs ;
//give the EMS member back ( if we have any )
if((regs.x.dx = handle) != 0xffff)
EMSCall(0x45,regs) ;
}
// amp the specified page into the specified frame slot
// return a 0 if succesful
unsigned EMS::map(unsigned page , unsigned frameSlot)
{
union REGS regs ;
regs.x.bx = page ;
regs.h.al = (char)frameSlot ;
if( (regs.x.dx = handle) == 0xffff )
return 0xffff ;
return EMSCall(0x44,regs) ;
}
unsigned EMS::status()
{
if( handle == 0xffff)
//cout<<0xffff ;
//getch() ;
return 0xffff ;
return EMSStatus() ;
}
// -------- Implementation of the general functions ---------
// EMSPresent - return a 0 if EMS handler is present ;
// otherwise, return the page frame address
void far * EMSPresent()
{
REGS regs ;
SREGS sregs ;
const char EMSName[] = "EMMXXXX0" ;
struct EMSHandler {
char padding[0x0a] ;
char name[9] ;
} far * EMSPtr ;
// get the address of the EMS handler ( with 0 offset )
regs.h.al = EMSInt ;
regs.h.ah = 0x35 ;
int86x(0x21,®s,®s,&sregs) ;
//int86(0x21,®s,®s,&sregs) ;
EMSPtr = ( EMSHandler far * )MK_FP(sregs.es,0) ;
// now check for the name of the EMS handler
for(int i=0;i<8;i++)
if( EMSPtr->name[i] != EMSName[i] )
return (void *) 0 ;
// okay , it's there
if( EMSCall(0x41,regs) )
return (void *) 0 ;
EMS::frameSegment = regs.x.bx ;
return EMSSlotAddr(0) ; //return page frame addr
}
// EMSSlotAddr - given a frame slot number calculate its address.
void far * EMSSlotAddr(unsigned slotnum)
{
const unsigned frameOffsets[] = {
0x0000 , 0x4000 , 0x8000 , 0xC000
} ;
if(slotnum>3)
return 0 ;
return MK_FP(EMS::frameSegment , frameOffsets[slotnum]) ;
}
// EMSStatus - return the status of the EMS handler
unsigned EMSStatus()
{
REGS regs ;
return EMSCall(0x40,regs) ;
}
// EMS_pagecount - return unallocated page count
unsigned EMSPageCount()
{
REGS regs ;
if(EMSCall(0x42,regs))
return 0 ;
return regs.x.bx ;
}