home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / ACVT.C < prev    next >
Text File  |  1996-03-14  |  3KB  |  80 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   acvt.c                                                                  */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*   Converts flat address to sel:off form and vice versa.                   */
  8. /*                                                                           */
  9. /*   !!!!use these for data conversions only!!!!                             */
  10. /*   !!!!call dosdebug to convert code addresses!!!!                         */
  11. /*                                                                           */
  12. /*                                                                           */
  13. /* History:                                                                  */
  14. /*                                                                           */
  15. /*****************************************************************************/
  16. #include "all.h"
  17.  
  18. #define Flat2Sel(p)         ((SEL)((HiFlat(p)<<3) | 7))
  19.  
  20. void Data_Flat2SelOff(ULONG addr,USHORT *pSelector,USHORT *pOffset)
  21. {
  22.  USHORT Selector = 0;
  23.  USHORT Offset   = 0;
  24.  
  25.  
  26.  Code_Flat2SelOff(addr, &Selector, &Offset);
  27.  if( Selector == 0 )
  28.  {
  29.   *pSelector = Flat2Sel( addr );
  30.   *pOffset   = LoFlat  ( addr );
  31.  }
  32. }
  33.  
  34. #define SelOff2Flat(s,o)    (((ULONG)(((USHORT)s)>>3))<<16)|(ULONG)o
  35.  
  36. ULONG Data_SelOff2Flat (USHORT Selector, USHORT Offset)
  37. {
  38.  ULONG    addr = 0;
  39.  
  40.  addr = Code_SelOff2Flat(Selector, Offset);
  41.  if( addr == 0 )
  42.   addr = SelOff2Flat( Selector, Offset );
  43.  
  44.  return( addr );
  45. }
  46.  
  47. void Code_Flat2SelOff(ULONG addr,USHORT *pSelector,USHORT *pOffset)
  48. {
  49.  DEBFILE *pdf;
  50.  ULONG    LoadAddr;
  51.  USHORT   LoadSel;
  52.  USHORT   LoadOff;
  53.  
  54.  *pSelector = 0;
  55.  *pOffset   = 0;
  56.  
  57.  pdf = FindExeOrDllWithAddr(addr);
  58.  if( pdf )
  59.   if(MapFlatAddrToBase(pdf, addr, &LoadAddr, &LoadSel, &LoadOff) == 0 )
  60.   {
  61.    *pSelector = LoadSel;
  62.    *pOffset = LoadOff + (USHORT)(addr - LoadAddr);
  63.   }
  64. }
  65.  
  66. ULONG Code_SelOff2Flat (ushort Selector,ushort Offset)
  67. {
  68.  DEBFILE *pdf;
  69.  ULONG    addr = 0;
  70.  ULONG    LoadAddr;
  71.  USHORT   LoadOff;
  72.  
  73.  pdf = FindExeOrDllWithSelOff(Selector,Offset);
  74.  if( pdf )
  75.   if( MapSelOffToBase(pdf, Selector, Offset, &LoadAddr, &LoadOff) == 0)
  76.    addr = LoadAddr + (Offset - LoadOff);
  77.  
  78.  return( addr );
  79. }
  80.