home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / MADTRB33.ZIP / FAR2.INC < prev    next >
Encoding:
Text File  |  1986-02-10  |  3.3 KB  |  89 lines

  1.  
  2.   PROCEDURE SetupJumpTable;
  3.       {-initialize the names and offsets of the near procedures}
  4.       {
  5.       ***************************************************
  6.       * The programmer must maintain the lists below to *
  7.       * include all global procedure names that may be  *
  8.       * called from the MAIN code segment.              *
  9.       * This procedure should never be called directly  *
  10.       * within its own program.                         *
  11.       ***************************************************
  12.       }
  13.     CONST
  14.       {following string must be here to allow address to be found from Main Code}
  15.       idstring : BigTurboString = 'SETJUMPTABLE FOLLOWS';
  16.     BEGIN
  17.       {
  18.       *** EXAMPLES and COMMENTS ********************************************
  19.       * Order is unimportant, except that procedures which are called most *
  20.       *  often from far segment should be first in list.                   *
  21.       * Case of the string is important. Must be same as string passed to  *
  22.       *  MakeLongCall (avoids overhead time of uppercasing every call).    *
  23.       * Fill in your own procedure names below.                            *
  24.       **********************************************************************
  25.       }
  26.       pnames[1] := 'farproc1';
  27.       poffsets[1] := Ofs(farproc1);
  28.       pnames[2] := 'farproc2';
  29.       poffsets[2] := Ofs(farproc2);
  30.  
  31.       {restore stack and do a FAR return to the main segment}
  32.       INLINE(
  33.         $8B/$E5/              {mov sp,bp}
  34.         $5D/                  {pop bp}
  35.         $CB                   {ret far}
  36.         );
  37.     END;                      {SetupJumpTable}
  38.  
  39.   PROCEDURE FarCallHandler;
  40.       {-pick up control from a far call and transfer to near procedure}
  41.     CONST
  42.       {following string must be here to allow address to be found from Main Code}
  43.       idstring : BigTurboString = 'FARCALLHANDLER FOLLOWS';
  44.     VAR
  45.       i : Integer;
  46.       procofs : Integer;
  47.       procname : BigTurboString;
  48.     BEGIN
  49.       {get procname from the es:si pointer passed in}
  50.       INLINE(
  51.         $31/$C9/              {XOR    CX,CX}
  52.         $26/                  {ES:    }
  53.         $8A/$0C/              {MOV    CL,[SI]}
  54.         $FE/$C1/              {INC    CL}
  55.         $BF/procname/         {MOV    DI,ofs(procname)}
  56.         $FC/                  {CLD    }
  57.         $26/                  {ES:    }
  58.         $AC/                  {LODSB    }
  59.         $88/$03/              {MOV    [BP+DI],AL}
  60.         $47/                  {INC    DI}
  61.         $E2/$F9               {LOOP    010B}
  62.         );
  63.       {match against the stored procnames}
  64.       i := 0;
  65.       REPEAT
  66.         i := i+1;
  67.       UNTIL (i > MaxNumProcs) OR (pnames[i] = procname);
  68.       {error check}
  69.       IF i > MaxNumProcs THEN BEGIN
  70.         WriteLn(Con);
  71.         WriteLn(Con, 'Far procedure ', procname, ' not found....');
  72.         Halt;
  73.       END;
  74.       {check for stack space, later}
  75.       {call the procedure}
  76.       procofs := poffsets[i];
  77.       INLINE(
  78.         $C4/$46/< procofs/    {LES    AX,procofs[BP]}
  79.         $FF/$D0               {CALL    AX}
  80.         );
  81.  
  82.       {restore stack and FAR return}
  83.       INLINE(
  84.         $8B/$E5/              {mov sp,bp}
  85.         $5D/                  {pop bp}
  86.         $CB                   {ret far}
  87.         );
  88.     END;                      {FarCallHandler}
  89.