-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCGA_OVER.PAS
108 lines (97 loc) · 2.5 KB
/
CGA_OVER.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
unit CGA_OVERLAY;
{must get overlay manager initialized before all others}
{{$DEFINE EMSWTF}
interface
implementation
Uses
Overlay;
{support} {do NOT overlay this unit or ovrinit will fail!}
const
OvrMaxSize:longint=128*1024; {choose a default max size of 128K}
(*ProgMemNeeds=16*1024; {amount of memory to leave for the program}*)
ProgMemNeeds=8*1024; {amount of memory to leave for the program}
AcceptableBufSize=40*1024;
ovrname='CGA_COMP.OVR';
foo:longint=0;
Function FileExists(filename:String):Boolean;
Var
f:File;
Begin
Assign(f,filename);
{$I-}
Reset(f);
Close(f); {need this or you run out of file handles calling me repeatedly!}
{$I+}
FileExists:=(IOResult = 0);
End;
Function SizeOfFile(filename:string):longint;
Var
f:File;
foo:LongInt;
Begin
If fileexists(filename) Then Begin
Assign(f,filename);
Reset(f,1);
foo:=FileSize(f);
Close(f);
sizeoffile:=foo;
End Else SizeOfFile:=-1;
End;
Function KeyPressed:Boolean; Assembler;
Asm
mov ah, 01h
int 16h
mov ax, 00h
jz @1
inc ax
@1:
end;
Function ReadKeyChar:Char; Assembler;
Asm
mov ah, 00h
int 16h
cmp al,0
jne @endit
mov al,ah
@endit:
end;
Procedure ReportError;
begin
case OvrResult of
ovrOK :Writeln('Overlay successful.');
ovrNotFound :Writeln('Overlay missing!');
ovrNoMemory :Writeln('Not enough memory to alter cache.');
ovrIOError :Writeln('I/O error!');
{$IFDEF EMSWTF}
ovrNoEMSDriver :Writeln('No EMS driver installed.');
ovrNoEMSMemory :Writeln('Not enough EMS available.');}
{$ENDIF}
else
Writeln('Unknown error.');
end; {case}
end;
begin
{First, initialize the overlay, since we can't continue until this succeeds.}
Writeln('Initializing overlay manager...');
OvrInit('CGA_COMP.OVR');
if OvrResult <> ovrOk then begin
ReportError;
Halt(1);
end;
{$IFDEF EMSWTF}
OvrInitEMS;
{$ENDIF}
{if we can see our overlay file, make the max overlay buffer big enough to hold it}
if fileexists(ovrname)
then OvrMaxSize:=sizeoffile(ovrname);
if maxavail > (OvrMaxSize+ProgMemNeeds)
then foo:=OvrMaxSize {try to max it out}
else foo:=maxavail - ProgMemNeeds;
OvrSetBuf(foo);
if OvrResult <> ovrOk then ReportError;
if OvrGetBuf < AcceptableBufSize then begin
Writeln('Not enough memory to increase cache area.');
Writeln('Cache size: ',OvrGetBuf div 1024,'KB. Operation will be sluggish. Press a key.');
repeat until keypressed; while keypressed do readkeychar;
end;
end.