-
Notifications
You must be signed in to change notification settings - Fork 3
/
MEM.PAS
161 lines (149 loc) · 4.44 KB
/
MEM.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
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
{ @author: Sylvain Maltais ([email protected])
@created: 2022
@website(https://www.gladir.com/msdos0)
@abstract(Target: Turbo Pascal)
}
Program MEM;
Uses DOS;
Type
XMSRegs=Record
AX,BX,DX,SI,Segment:Word;
End;
Var
Language:(_French,_English,_Germany,_Italian,_Spain);
TmpLanguage:String;
XMSPtr:Pointer;
XMSErr:Byte;
Used:Integer;
TotalSize,TotalUsed,TotalFree:LongInt;
Function StrToUpper(S:String):String;
Var
I:Byte;
Begin
For I:=1 to Length(S)do Begin
If S[I] in['a'..'z']Then S[I]:=Chr(Ord(S[I])-32);
End;
StrToUpper:=S;
End;
Function GetConvMemory:Word;
Var
Regs:Registers;
Begin
Regs.AX:=0;
Intr($12,Regs);
GetConvMemory:=Regs.AX;
End;
Function XMSInit:Boolean;
Var
Regs:Registers;
xr:XMSRegs;
Begin
Regs.AX:=$4300;
Intr($2F,Regs);
If(Regs.AL=$80)Then Begin
Regs.AX:=$4310;
Intr($2F,Regs);
XMSPtr:=Ptr(Regs.ES,Regs.BX);
XMSErr:=0;
XMSInit:=True;
End
Else
XMSInit:=False;
End;
Procedure XMSCall(NumFonc:Byte;Var XRegs:XMSRegs);Begin
Inline ( $8C / $D9 / { mov cx,ds *}
$51 / { push cx *}
$C5 / $BE / $04 / $00 / { lds di,[bp+0004] *}
$8A / $66 / $08 / { mov ah,[bp+0008] *}
$8B / $9D / $02 / $00 / { mov bx,[di+0002] *}
$8B / $95 / $04 / $00 / { mov dx,[di+0004] *}
$8B / $B5 / $06 / $00 / { mov si,[di+0006] *}
$8E / $5D / $08 / { mov ds,[di+08] *}
$8E / $C1 / { mov es,cx *}
$26 / $FF / $1E / XMSPtr / { call es:[XMSPtr] *}
$8C / $D9 / { mov cx,ds *}
$C5 / $7E / $04 / { lds di,[bp+04] *}
$89 / $05 / { mov [di],ax *}
$89 / $5D / $02 / { mov [di+02],bx *}
$89 / $55 / $04 / { mov [di+04],dx *}
$89 / $75 / $06 / { mov [di+06],si *}
$89 / $4D / $08 / { mov [di+08],cx *}
$1F { pop ds *}
);
If(XRegs.AX = 0)and(XRegs.BX >= 128)Then Begin
XMSErr:=Lo(XRegs.BX)
End
else
XMSErr:=0;
End;
Function XMSUsed:Integer;
Var
Used:Integer;
Handle:Word;
Xr:XMSRegs;
Begin
Used:=0;
For Handle:=0 to 65520 do Begin
Xr.DX:=Handle;
XmsCall(14,Xr);
If Xr.AX=0 Then Break;
Inc(Used,Xr.DX);
End;
XMSUsed:=Used;
End;
Function XMSFree:Integer;
Var
Xr:XMSRegs;
Begin
XmsCall(8,Xr);
XMSFree:=Xr.AX;
End;
BEGIN
Language:=_French;
TmpLanguage:=GetEnv('LANGUAGE');
If TmpLanguage<>''Then Begin
If TmpLanguage[1]='"'Then TmpLanguage:=Copy(TmpLanguage,2,255);
If StrToUpper(Copy(TmpLanguage,1,2))='EN'Then Language:=_English Else
If StrToUpper(Copy(TmpLanguage,1,2))='GR'Then Language:=_Germany Else
If StrToUpper(Copy(TmpLanguage,1,2))='IT'Then Language:=_Italian Else
If StrToUpper(Copy(TmpLanguage,1,2))='SP'Then Language:=_Spain;
End;
If(ParamStr(1)='/?')or(ParamStr(1)='--help')or(ParamStr(1)='-h')Then Begin
Case Language of
_Germany:Begin
WriteLn('Zeigh die GrӇe des belegten und noch freinen Arbeitsspeichers im System an.');
WriteLn;
WriteLn('MEM');
End;
_English:Begin
WriteLn('Displays the amount of used and free memory in your system.');
WriteLn;
WriteLn('MEM');
End;
Else Begin
WriteLn('MEM : Cette commande permet d''afficher les informations sur la mémoire.');
WriteLn;
WriteLn('Syntaxe : MEM');
End;
End;
End
Else
Begin
TotalSize:=0;TotalUsed:=0;TotalFree:=0;
WriteLn('Type de memoire Total = Utilise + Libre');
WriteLn('------------------- --------- ------- --------- ');
Inc(TotalSize,GetConvMemory);
Inc(TotalUsed,GetConvMemory-(MemAvail shr 10));
Inc(TotalFree,MemAvail shr 10);
WriteLn('Conventionnel ',GetConvMemory:5,'K',GetConvMemory-(MemAvail shr 10):9,'K',MemAvail shr 10:11,'K');
If(XMSInit)Then Begin
Used:=XMSUsed;
Inc(TotalSize,Used+XMSFree);
Inc(TotalUsed,Used);
Inc(TotalFree,XMSFree);
WriteLn('Etendue (XMS) ',Used+XMSFree:5,'K',Used:9,'K',XMSFree:11,'K');
End;
WriteLn('------------------- --------- ------- --------- ');
WriteLn('Memoire total ',TotalSize:5,'K',TotalUsed:9,'K',TotalFree:11,'K');
End;
END.