home *** CD-ROM | disk | FTP | other *** search
- Unit DataAcc;
- { This unit will interface the Type declaration for the }
- { information that is stored in the OBJ file. It has also }
- { interfaced a routine to access the data. This is done }
- { because as soon as we make a call to the accessing routine, }
- { we have guaranteed that the data also resides in the }
- { overlay buffer. }
-
- {$O+,F+} { Set the necessary compiler directives. }
-
- Interface
-
- Type
- DataType = Array[1..100] of Word; { Data Type in OBJ file }
- DataTypePtr = ^DataType; { Pointer to data type }
-
- Function ReturnWord( Index : Word ) : Word;
-
- Implementation
-
- Procedure DummyProc;
- { This is simply a dummy procedure that only exists to }
- { determine if this unit has been overlayed. If it is, then }
- { the address of this procedure should contain a JMP }
- { instruction. Otherwise, it will contain the first byte of }
- { the entry code to the procedure. }
- Begin
- End;
-
- Procedure DataProc; External;
- {$L Data.obj} { This is the actual data file }
-
- Function UnitIsOverlayed : Boolean;
- { THis function will determine if this unit has been }
- { overlayed by any program that uses this unit. }
- Var
- P : ^Byte; { Used in overlay determination }
-
- Begin
- P := @DummyProc; { Look at First Byte of Proc. }
- If( P^ = 234 ) Then { Is it a JMP instruction? }
- UnitIsOverlayed := True { If so, this is overlayed }
- Else
- UnitIsOverlayed := False;{ Otherwise it is not overlayed }
- End;
-
- Function GetDataAddr : Pointer;
- { This function will return the address of where the data }
- { actually begins in memory. If the unit is overlayed, then }
- { referring to @@DataProc will point to the actual data within }
- { the code segment. Otherwise, it will point return the }
- { location of the data within the overlay buffer. }
- Var
- P : Pointer; { Pointer to look at DataProc }
- Offset, Segment : Word;{ Address words of location }
-
- Begin
- P := @DataProc; { Get address of Stub or actual data }
- If UnitIsOverlayed Then
- Begin { Calculate the location of the data within Buffer }
- Offset := ( Mem[Seg( P^ ):( Ofs( P^ ) + 2 )] * 256 ) +
- ( Mem[Seg( P^ ):( Ofs( P^ ) + 1 )] );
- Segment := ( Mem[Seg( P^ ):( Ofs( P^ ) + 4 )] * 256 ) +
- ( Mem[Seg( P^ ):( Ofs( P^ ) + 3 )] );
- GetDataAddr := Ptr( Segment, Offset ); { Calc the address }
- End
- Else
- GetDataAddr := @DataProc;{ We have actual memory location }
- End;
-
- Function ReturnWord( Index : Word ) : Word;
- { This function will return the Indexed data item from the }
- { data procedure. }
- Var
- P : DataTypePtr; { Pointer type to exact data type }
-
- Begin
- P := DataTypePtr( GetDataAddr );{ Find the address of data }
- ReturnWord := P^[Index]; { Return the requested item }
- End;
-
- End.
-