-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathWEMEMORY.PAS
115 lines (104 loc) · 1.7 KB
/
WEMEMORY.PAS
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
UNIT WEMemory;
{$I WEGLOBAL.PAS}
INTERFACE
FUNCTION malloc(size:word):pointer;
PROCEDURE MapPages;
PROCEDURE MemCleanup;
IMPLEMENTATION
USES ExecSwap;
CONST
EMMInt = $67;
VAR
count:word;
Handle: word;
PageFrame: word;
BytesFree : LongInt;
FreeBottom : pointer;
PROCEDURE MemCleanup;
BEGIN
IF Count > 0 THEN
DeallocateEmsHandle(Handle);
Count:=0;
END;
FUNCTION GetUnallocPageCount : WORD;
BEGIN asm
mov ah,$42
int EMMInt
mov @result,bx
end END;
FUNCTION Malloc(size:word):Pointer;
VAR
x:pointer;
Segx,Off: word;
w : word;
BEGIN
x:=NIL;
IF BytesFree>=size THEN
BEGIN
BytesFree := BytesFree - size;
x:=FreeBottom;
Segx:=Seg(x^);
Off:=Ofs(x^)+size;
IF off > $f THEN BEGIN
w:=Off div 16;
Off:=Off mod 16;
Segx := Segx + w;
FreeBottom:=ptr(Segx,Off);
END
END ELSE
GetMem(x,size);
Malloc:=x;
END;
PROCEDURE MapPages;
BEGIN
IF Count > 0 THEN
asm
mov ax,$4400
xor bx,bx
mov dx,handle
int EMMInt
end;
IF Count > 1 THEN
asm
mov ax,$4401
mov bx,1
mov dx,handle
int EMMInt
end;
IF Count > 2 THEN
asm
mov ax,$4402
mov bx,2
mov dx,handle
int EMMInt
end;
IF Count > 3 THEN
asm
mov ax,$4403
mov bx,3
mov dx,handle
int EMMInt
end;
END;
BEGIN
count:=0;
BytesFree:=0;
{$IFDEF USE_EMS}
IF EMSInstalled THEN
BEGIN
PageFrame:=EmsPageFrame;
count:=GetUnallocPageCount;
IF Count>4 THEN count:=4;
IF Count>0 THEN
BEGIN
Handle:=AllocateEmsPages(count);
FreeBottom:=ptr(PageFrame,0);
BytesFree := count*LongInt(16384);
MapPages;
END ELSE BEGIN
handle:=65535;
BytesFree:=0;
END;
END;
{$ENDIF}
END.