-
Notifications
You must be signed in to change notification settings - Fork 1
/
OSSYSTEM.TXT
746 lines (497 loc) · 24.8 KB
/
OSSYSTEM.TXT
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
UNIT OSSystem
---------------------------------------------------------------------------
These routines are used to detect operating system parameters at
startup, and also to support time slicing routines under different PC
operating systems.
This unit will only run in DOS version 3.0+ or greater, otherwise it
will print an error message (in English) and abort.
Targets: Real, Protected.
GLOBAL Variables
These Variables are automatically set when this unit is used:
(The high byte returns major version number, and the low byte returns)
(minor version number).
TestDPMI: word
Returns the DPMI version or 0 if not running under a DPMI server.
TestXMS : word
Returns the XMS Driver version or 0 if not running an XMS server.
TestEMS : word
Returns the EMS driver version or 0 if not running an EMS server.
TestShell:word
Returns the type of running shell.
TestOS : word
Returns the type of running operating system.
TestTame : boolean
Return TRUE if running TAME multitasking enhancer
CONSTANTS
---------------------------------------------------------------------------
The following constants are defined
Possible values in the TestShell variable
ShellNone $00 Running standard Shell
ShellNDos $01 Running NDOS/4DOS Shell
ShellNovell $02 Running Novell under standard shell
ShellNDosNovell $03 Running Novell under NDOS/4DOS
Possible TestOS values
OSNone $00 Running Under DOS / DOS 5.0+
OSOS2 $01 Running Under OS/2 Version 2.x
OSWindows $02 Running Under Windows/386
OSDesqview $03 Running Desqview / Topview
OSDoubleDos $04 Running DoubleDOS
OSCPMDOS $05 Running Concurrent DOS MultiUser
OSDPMI $06 Running DPMI Host V1.0+
---------------------------------------------------------------------------
DetectShell Function
---------------------------------------------------------------------------
Purpose Returns the type of shell and operating system running
Declaration DetectShell
Result Type Word
Remarks The low byte returns the type of shell running on top
of the operating system.
The returned shell values are represented
mnemonically by the ShellXXXX constants.
The high byte returns the type of operating system
detected.
The returned operating system type are represented
mnemonically by the OSXXXX constants.
You should check the TestShell and TestOS
Variables instead of calling this routine.
Restrictions The following operating systems are NOT detected by
this routine: MultiDOS, CSwitch, MultiLink.
Targets Real, Protected.
---------------------------------------------------------------------------
GetAltKey function (ASM)
---------------------------------------------------------------------------
Purpose Verifies if the Alt Key is pressed.
Declaration GetAltKey
Result Type Boolean
Remarks This function returns true if the Alt key of the
keyboard is being pressed, otherwise the function
returns false.
This procedure is used in the modified Turbo Vision
package (HandleEvent Method), to put the cursor in the
menu bar when only the Alt key is pressed. (to
simulate MS-DOS's Edit).
Targets Real, Protected.
Example Procedure TMyApp.HandleEvent(Var Event: TEvent);
Begin { Calls the menu Object when the Alt key is pressed }
If GetAltKey and (Event.KeyCode = KbNoKey) then
Begin
Event.What:= evCommand;
Event.Command := cmMenu; { Execute Menu Command }
Event.InfoPtr := nil;
PutEvent(Event);
end;
Inherited HandleEvent(Event);
ClearEvent(Event);
end;
Var i:Word;
Begin
Repeat
If GetAltKey then
WriteLn('The Alt Key is being pressed');
i:=i+1;
Until i = 65535;
end.
---------------------------------------------------------------------------
GetDPMIVersion Function
---------------------------------------------------------------------------
Purpose Returns the DPMI driver version.
Declaration GetDPMIVersion
Result Type Word
Remarks This routine returns the DPMI driver version. The High byte
contains the major version number while the Low byte returns
the minor version number.
You should check the TestDPMI variable instead of calling
this routine.
Restrictions This routine is used internally by some of the procedures
herein.
Targets Real, Protected.
Example Begin
If VerifyDPMIPresent then
WriteLn('Version:'Hi(GetDPMIVersion),'.',Lo(GetDPMIVersion));
end.
---------------------------------------------------------------------------
GetEMSVersion Function
---------------------------------------------------------------------------
Purpose Returns the EMS driver version.
Declaration GetEMSVersion
Result Type Word
Remarks This routine returns the EMS driver version. The High byte
contains the major version number while the Low byte returns
the minor version number.
You should check the TestEMS variable instead of calling
this routine.
Restrictions This routine is used internally by some of the procedures
herein.
In protected mode, the version number of the driver returned
is the EMS server in protected mode. (if there is one).
Targets Real, Protected.
---------------------------------------------------------------------------
GetXMSVersion Function
---------------------------------------------------------------------------
Purpose Returns the XMS driver version.
Declaration GetXMSVersion
Result Type Word
Remarks This routine returns the XMS driver version. The High byte
contains the major version number while the Low byte returns
the minor version number.
You should check the TestXMS variable instead of calling
this routine.
Restrictions This routine is used internally by some of the procedures
herein.
In protected mode, the version number of the driver
returned is the XMS server in protected mode. (if
there is one).
Targets Real, Protected.
---------------------------------------------------------------------------
GetFreeEMS Function
---------------------------------------------------------------------------
Purpose Returns the largest memory block available in EMS.
Declaration GetFreeEMS
Result Type Word
Remarks This routine returns the largest available block of memory in
kilobytes that can be allocated.
Targets Real.
Example Begin
If VerifyEMSPresent then
WriteLn(GetFreeEMS,' Kbytes in largest block');
end.
---------------------------------------------------------------------------
GetFreeXMS Function
---------------------------------------------------------------------------
Purpose Returns the largest memory block available in XMS.
Declaration GetFreeXMS
Result Type Word
Remarks This routine returns the largest available block of memory in
kilobytes that can be allocated.
Targets Real.
Example Begin
If VerifyXMSPresent then
WriteLn(GetFreeXMS,' Kbytes in largest block');
end.
---------------------------------------------------------------------------
MakeFileBackUp procedure
---------------------------------------------------------------------------
Purpose Writes data to disk and creates a backup of the file on the
disk if it already exists.
Declaration Procedure MakeFileBackup(Const BackOn:Boolean;
FName:FNameStr;Buf:Pointer; Size:Word);
Variables: BackOn: Boolean -> If True there will be a backup of the
file
(with extension. bak) if the FName already exists to disk.
Fname: FNameStr -> Name of the file to write to disk.
Buf: Pointer -> Address of the data to be written to
disk.
Size: Word -> size of the data to be written to disk.
Remarks This File writes Size bytes to disk (using a file name of
Fname) starting at memory location Buf. If BackOn is true,
the procedure will first verify if the file already exists
on disk, if so then it will first be renamed with an
extension of .BAK and then the data will be written to disk.
If BackOn is false data will simply be written to disk.
(even though it may overwrite an existing file).
Restriction Maximum Size of the Data to be written is 64K (65535 Bytes).
There is no length checking so you should use SizeOf to
determine the number of bytes to write to disk.
Targets Real, Protected.
Example Type
MyArray = Array[1..200] of Longint;
Var
MyVar:MyArray;
i:Word;
Begin
Randomize;
For i:=1 to 200 do { Fill the array with random data }
MyVar[i]:=Abs(Random(5));
MakeFileBackup(True,'Myarray.Dat',@MyVar,SizeOf(MyArray));
{ Writes the data to disk, if the file already exists }
{ it is renamed as Myarray.bak before the data is }
{ written to disk. }
end.
---------------------------------------------------------------------------
TameInstalled Function
---------------------------------------------------------------------------
Purpose Verifies if the TAME multitasking enhancer is installed in
memory.
Declaration Function TameInstalled
Result Type Boolean
Remarks This routine returns TRUE if tame is installed in memory,
otherwise it returns FALSE.
You should check the TestTame variable instead of calling
this routine.
Targets Real, Protected.
---------------------------------------------------------------------------
VerifyFilePresence function
---------------------------------------------------------------------------
Purpose Verifies if a file is in the current active directory.
Declaration Function VerifyFilePresence(FName: FNameStr)
Result Type Boolean
Variables FName: FNameStr -> Name of the file to check. (file.ext
format)
Remarks Verifies if the file FName is present in the current active
directory. If it is, the function returns true, otherwise
the function returns false.
Targets Real, Protected.
Example Var S: String;
Begin
S:='myfile.bak';
If VerifyFilePresence(S) then
WriteLn('The file is present')
else
WriteLn('The file is missing');
end.
---------------------------------------------------------------------------
VerifyDPMIPresent Function
---------------------------------------------------------------------------
Purpose Check if a DPMI Driver is present in memory.
Declaration VerifyDPMIPresent
Result Type Boolean
Remarks This routine returns True if a Dos Protected mode interface
is present in memory. Otherwise the function returns false.
You should check the TestDPMI variable instead of calling
this routine.
Restrictions This routine is used internally by some of the procedures
herein.
Targets Real, Protected.
Example Begin
If VerifyDPMIPresent then
WriteLn('You have a DPMI server on your system');
else
WriteLn('You do not have enough memory.');
end.
---------------------------------------------------------------------------
VerifyEMSPresent Function
---------------------------------------------------------------------------
Purpose Checks if an EMS Driver is present in memory.
Declaration VerifyEMSPresent
Result Type Boolean
Remarks This routine returns True if an Expanded Memory manager is
present in memory. Otherwise the function returns false.
In Protected mode, the EMS driver checked is the one
available in protected mode.
You should check the TestEMS variable instead of calling
this routine.
Targets Real, Protected.
Example Begin
If VerifyEMSPresent then
WriteLn('You have EMS on your system');
else
WriteLn('You do not have enough memory.');
end.
---------------------------------------------------------------------------
VerifyXMSPresent Function
---------------------------------------------------------------------------
Purpose Check if an XMS Driver is present in memory.
Declaration VerifyXMSPresent
Result Type Boolean
Remarks This routine returns True if an Extended Memory manager is
present in memory. Otherwise the function returns false.
You should check the TestXMS variable instead of calling
this routine.
Targets Real, Protected.
Restrictions This routine is used internally by some of the procedures
herein.
In Protected mode, the XMS driver checked is the one
available in protected mode.
Example Begin
If VerifyXMSPresent then
WriteLn('You have XMS on your system');
else
WriteLn('You do not have enough memory.');
end.
TMultiTask
---------------------------------------------------------------------------
Tmultitask and its derived classes are objects which permit using the
enhanced capabilities of multitasking environments.
The following derived objects are available:
TMultiDOS - Object to use when running under MultiDOS
TDoubleDOS - Object to use when running under DoubleDOS
TCSwitch - Object to use when Running under CSwitch
TMultilink - Object to use when running under Multilink
TWindows - Object to use when running under Windows/386
TMultiUserDOS - Object to use when running under Cocurrent DOS multiuser
TDesqview - Object to use when running under Desqview/Topview/TaskView
FIELDS ---------------------------------------------------------------------
Universal: Boolean;
TRUE if the universal time-slicing mechanism is supported
(see Ralph Brown's interrupt list for more info.)
METHODS -------------------------------------------------------------------
Init constructor Init;
Verifies if the universal time slicing routine is supported,
if so sets Universal to TRUE.
GiveTimeSlice procedure GiveTimeSlice; virtual;
If Universal is true calls the universal time-slicing
interrupt.
If universal is false and we are running under Novell
Netware, call that time slicing interrupt.
OS/2 and Windows/386 both support the universal time slicing
routine.
BeginCritical procedure BeginCritical; virtual;
The base object method does nothing, but depending on the
derived class, this routine disables task-switching until
the EndCritical routine is called.
EndCritical procedure EndCritical; virtual;
Resumes Task-switching.
Done destructor Done; virtual;
This routine presently does nothing.
---------------------------------------------------------------------------
XglobalDOSAlloc Function
---------------------------------------------------------------------------
Purpose Allocate some real mode memory in protected mode.
Declaration XGlobalDOSAlloc(size: longint; var p: Pointer)
Result Type word
(real mode segment of allocated memory block)
Variables size: longint -> number of memory bytes requested
P: Pointer -> Selector:Offset of allocated memory
block (on return).
Remarks This routine allocates some real mode conventional memory, it is
mainly used to call real mode interrupt routines requiring real
mode adresses.
If the real mode segment return address is zero, this
indicates that the memory could not be allocated for a
reason or another.
The memory is already locked when allocated, the protected
mode server automatically locks it into place for you. (i.e
it is guaranteed not to move)
The real mode allocated memory block always has an offset of
zero.
Targets Protected.
Restrictions Real mode memory is a scarse ressource and should be freed
as soon as you have finished using it. (cf XGlobalDOSFree).
---------------------------------------------------------------------------
XglobalDOSFree Function
---------------------------------------------------------------------------
Purpose Free up some real mode memory allocated by the
XGlobalDOSAlloc routine.
Declaration XGlobalDOSFree(Var p: Pointer)
Variables P: Pointer -> Selector:Offset of allocated memory
block to Free (zero if function was successfull).
Remarks This routine frees some real mode memory which was
previously allocated using the XGlobalDOSAlloc routine.
If the selector of P is zero on return then the function was
successfull, otherwise the DPMI server could not free up the
memory for one reason or another.
Targets Protected.
---------------------------------------------------------------------------
RealModeInt Procedure
---------------------------------------------------------------------------
Purpose Call a real mode interrupt in protected mode
Declaration RealModeInt(IntNo: word; Var Regs: TDPMIRegisters)
Variables IntNo: word -> real mode Interrupt (0-255) to call
Regs: TDPMIRegisters -> Registers to call interrupt
with
Remarks This routine tells the protected mode server to switch to real
mode and call a real mode interrupt before returning to protected
mode.
On return, the regs parameters will be changed accordingly
to the interrupt called.
Targets Protected.
Restrictions all unused REGS should be set to zero on entry to this
procedure (DPMI server requirement).
regs which contain adresses must point to REAL MODE segments
offsets pairs. Not selector:offsets pairs!
Calling real mode interrupts in protected mode
As you may know, real mode adressing on the personal computer has always
been done on segment:offset pairs which are governed by some strange laws.
(these strange laws indicate that a segment cannot exceed 64K in size, as
well as having a limited direct adressing capability of 1 Meg of RAM)
When protected mode was presented to the public in 286 computers a while
back, then you could access up to 16 megs of ram by hardware! An industry
standard, the DOS Protected mode interface was introduced to take advantage
of this. This interface was used to manage protected mode memory and
interrupts. In other words the computer would run in another mode that we
were used to, when programs called for it! In the protected mode
environment,each address would have a selector: offset pair, and these
would not be equal to the physical memory!! In other words the computer
would have the real mode and the protected mode! (two worlds apart), each
one having its own interrupt vectors as well as its own adressing scheme.
But the DPMI standard only indicated that the basic interrupts should be
available in protected mode (i.e DOS, and basic BIOS interrupts), so today
depending on the protected mode server you chose for your programs, the
interrupts you wish to use, may or may not be implemented in protected mode.
What to do in that case ? Simple! You simply need to call the real mode
interrupt instead! To do that you must call the DPMI server and tell it
to switch to real mode and execute the interrupt you specified. But
watch out, the parameters you must pass on to these real mode interrupts
must use real mode adresses if they require them!! That is where
XGlobalDOSAlloc and XGlobalDOSFree come in handy.
Calling interrupts in protected mode:
If you wish to call a basic interrupt:
- check if the server supports the protected mode version of the
interrupt. All servers should support DOS functions as well as basic
BIOS interrupt directly. In that case simply call the interrupt
as you would do it in real mode (the addresses, if required will
be in selector:offset pairs, but this will be taken care by
the DPMI server).
The borland DPMI server does not seem to support BIOS routines
which require adresses as parameters (such as get BIOS font pointers,
etc..)
- if the protected mode version of the interrupt is not supported
by the server, then call the RealModeInt procedure:
example:
Var regs: TDPMIregisters;
{ this will check if 4DOS is resident in memory }
{ set up all TDPMIregisters to zero }
FillChar(Regs, SizeOf(Regs), #0);
{ set up parameters of registers as usual }
Regs.EAX := $D44D;
Regs.EBX := $0000;
{ call real mode interrupt }
RealModeInt($2F, Regs);
{ check return values (if applicable) }
If Regs.EAX = $44DD then
ShellVal := ShellNDos
else
ShellVal := ShellNone;
...
The RealModeInt procedure simply calls the DPMI server, telling it to
switch to real mode, call the real mode interrupt, and to
switch back to protected mode.
- if you are required to call a real mode interrupt which
must have some adresses as parameters, you must do the
following:
- let us say you must send a record memory address:
- Set up the record as usual in pascal
- allocate some real mode memory
- copy the record to this area of allocated
memory
- set up the registers accordingly (the address registers
should contain the segment:offset address returned when
the real mode memory was allocated).
- call RealModeInt
- check the results
- free up the real mode memory
example:
Procedure ChangeVGAChar(Var AChar: TVGAChar; CharNum: Byte);
{ This routine changes the VGA character CharNum to the }
{ bit pattern stored in TVGAChar }
Var
DPMIRegs: TDPMIRegisters; { Registers }
APtr: Pointer; { Selector: Offset of allocated mem }
Segment: Word; { Segment of allocated memory }
Begin
{ Allocate some real mode memory }
{ Segment and APtr point to the same memory address }
{ Segment in real mode and APtr in protected mode }
Segment := XGlobalDOSAlloc(16*9, APtr);
If Segment <> 0 then
{ verify if allocation was successfull }
Begin
{ Move bit patterns to protected mode address }
{ APtr^ }
Move(Achar ,APtr^, 16*9);
{ Set up the registers }
FillChar(DPMIRegs, SizeOf(DPMIRegs), #0);
{ Set up function call }
DPMIRegs.EAX := $1100;
DPMIRegs.EBX := $1000;
DPMIRegs.ECX := $01;
DPMIRegs.EDX := CharNum;
{ Address of bit pattern - REAL MODE address! }
DPMIRegs.ES := Segment;
{ offset is always is zero when using XGlobalDOSAlloc }
DPMIRegs.EBP := $0000;
{ Call interrupt }
RealModeInt($10, DPMIRegs);
{ Free up the real mode memory }
XGlobalDosFree(APtr);
end;