home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST0812.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-31  |  3.0 KB  |  84 lines

  1. Unit DataAcc;
  2. { This unit will interface the Type declaration for the       }
  3. { information that is stored in the OBJ file.  It has also    }
  4. { interfaced a routine to access the data.  This is done      }
  5. { because as soon as we make a call to the accessing routine, }
  6. { we have guaranteed that the data also resides in the        }
  7. { overlay buffer.                                             }
  8.  
  9. {$O+,F+}          { Set the necessary compiler directives.    }
  10.  
  11. Interface
  12.  
  13. Type
  14.   DataType = Array[1..100] of Word;  { Data Type in OBJ file  }
  15.   DataTypePtr = ^DataType;           { Pointer to data type   }
  16.  
  17. Function ReturnWord( Index : Word ) : Word;
  18.  
  19. Implementation
  20.  
  21. Procedure DummyProc;
  22. { This is simply a dummy procedure that only exists to        }
  23. { determine if this unit has been overlayed.  If it is, then  }
  24. { the address of this procedure should contain a JMP          }
  25. { instruction.  Otherwise, it will contain the first byte of  }
  26. { the entry code to the procedure.                            }
  27. Begin
  28. End;
  29.  
  30. Procedure DataProc; External;
  31. {$L Data.obj}                { This is the actual data file   }
  32.  
  33. Function UnitIsOverlayed : Boolean;
  34. { THis function will determine if this unit has been          }
  35. { overlayed by any program that uses this unit.               }
  36. Var
  37.   P : ^Byte;                 { Used in overlay determination  }
  38.  
  39. Begin
  40.   P := @DummyProc;           { Look at First Byte of Proc.    }
  41.   If( P^ = 234 ) Then        { Is it a JMP instruction?       }
  42.     UnitIsOverlayed := True  { If so, this is overlayed       }
  43.   Else
  44.     UnitIsOverlayed := False;{ Otherwise it is not overlayed  }
  45. End;
  46.  
  47. Function GetDataAddr : Pointer;
  48. { This function will return the address of where the data     }
  49. { actually begins in memory.  If the unit is overlayed, then  }
  50. { referring to @@DataProc will point to the actual data within }
  51. { the code segment.  Otherwise, it will point return the      }
  52. { location of the data within the overlay buffer.             }
  53. Var
  54.   P : Pointer;          { Pointer to look at DataProc         }
  55.   Offset, Segment : Word;{ Address words of location          }
  56.  
  57. Begin
  58.   P := @DataProc;       { Get address of Stub or actual data  }
  59.   If UnitIsOverlayed Then
  60.   Begin { Calculate the location of the data within Buffer    }
  61.     Offset := ( Mem[Seg( P^ ):( Ofs( P^ ) + 2 )] * 256 ) +
  62.               ( Mem[Seg( P^ ):( Ofs( P^ ) + 1 )] );
  63.     Segment := ( Mem[Seg( P^ ):( Ofs( P^ ) + 4 )] * 256 ) +
  64.                ( Mem[Seg( P^ ):( Ofs( P^ ) + 3 )] );
  65.     GetDataAddr := Ptr( Segment, Offset ); { Calc the address }
  66.   End
  67.   Else
  68.     GetDataAddr := @DataProc;{ We have actual memory location }
  69. End;
  70.  
  71. Function ReturnWord( Index : Word ) : Word;
  72. { This function will return the Indexed data item from the    }
  73. { data procedure.                                             }
  74. Var
  75.   P : DataTypePtr;  { Pointer type to exact data type         }
  76.  
  77. Begin
  78.   P := DataTypePtr( GetDataAddr );{ Find the address of data  }
  79.   ReturnWord := P^[Index];        { Return the requested item }
  80. End;
  81.  
  82. End.
  83.  
  84.