home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / MADTRB32.ZIP / STAYRSTR.310 < prev    next >
Encoding:
Text File  |  1985-09-05  |  4.4 KB  |  91 lines

  1. {****************************************************************************}
  2. {                  S  T  A  Y  R  S  T  R  .  I  N  C                        }
  3. {                                                                            }
  4. {           This is the StayRstr.Inc file included above                     }
  5. {       Separate the code out into a file or replace the $I StayRstr.310     }
  6. {                  statement above with this code.                           }
  7. {****************************************************************************}
  8.  
  9. { Inline Code to restore the stack and regs moved to the Turbo Resident
  10.   Program Stack to allow re-entrancy into the Dos Code for I/O and
  11.   recursion from built-in Turbo functions.
  12.  
  13. ; Arthor:      L.H. Ferris
  14.  
  15. ; Distributed to the Public Domain for use without profit.
  16. ; Original Version 5.15.85
  17.  
  18. ;----------------------------------------------------------------------;
  19. ;        Restore the Dos Regs and Stack
  20. ;----------------------------------------------------------------------;
  21.  
  22. ; On entry the Stack will already contain:
  23. ;
  24. ;        1) Bottom of Dos Stack Ptr
  25. ;        2) Dos Flags
  26. ;        3) Dos Code Segment
  27. ;        4) Dos Instruction Ptr
  28. ;        5) Dos Base Pointer
  29. ;        6) Dos Original Stack Ptr
  30. }
  31.     inline(
  32.  
  33.     $BD/Regs/                          {Mov    Bp,offset REGS}
  34.     $2E/$8B/$46/$00/                   {CS:Mov Ax,[Bp+0]}
  35.     $2E/$8B/$5E/$02/                   {Cs:Mov Bx,[Bp+2]}
  36.     $2E/$8B/$4E/$04/                   {CS:Mov Cx,[Bp+4]}
  37.     $2E/$8B/$56/$06/                   {CS:Mov Dx,[Bp+6]}
  38.  
  39.     $2E/$8B/$76/$0A/                   {CS:Mov Si,[Bp+A]}
  40.     $2E/$8B/$7E/$0C/                   {CS:Mov Di,[Bp+C]}
  41.     $2E/$8E/$5E/$0E/                   {CS:Mov DS,[Bp+E]}
  42.     $2E/$8E/$46/$10/                   {CS:Mov ES,[Bp+10]}
  43.     $2E/$FF/$76/$12/                   {Push Cs:[Bp+12]}
  44.     $9D/                               {Popf}
  45.  
  46.     { If [Cs:InUse]:= True,  then dont restore the stack. This program is   }
  47.     { being recursive. Else restore  Dos Stack and Program Entry registers  }
  48.  
  49.      $2E/$80/$3E/Inuse/$01/   {Cmp  byte ptr Cs:[Inuse],1                   }
  50.      $74/$23/                 {Je   ReCurOut                                }
  51.  
  52.       $FA /                   { Cli      ; Stop all interrupts    }
  53.  
  54.     {  Move 40 words of our stack back to Dos Stack                }
  55.  
  56.     $5E/                     {Pop Si     Bottom of Dos Stack              }
  57.     $B9/>$0028/              {Mov Cx,40  Return 40 Dos Stack Words        }
  58.     $2E/$8E/$06/DosSSeg/     {Mov ES,Cs:DosSSeg Get Dos StackSegment      }
  59.   {Restack:}
  60.     $4E/$4E/                 {Dec Si/Dec Si     Backup Dos Stack          }
  61.     $26/$8F/$04/             {Pop Es:[Si]       Dos Stack := Our Stack    }
  62.     $E2/$F9/                 {Loop to Restack                             }
  63.     $89/$F5/                 {Mov Bp,Si         Save Dos Sp across Pops   }
  64.  
  65.  
  66.     $07/                     {Pop  Es                                     }
  67.     $1F/                     {Pop  Ds                                     }
  68.     $5F/                     {Pop  Di                                     }
  69.     $5E/                     {Pop  Si                                     }
  70.     $5A/                     {Pop  Dx                                     }
  71.     $59/                     {Pop  Cx                                     }
  72.     $5B/                     {Pop  Bx                                     }
  73.     $44/$44/                 {Inc sp/Inc sp Thow old Ax value away        }
  74.  
  75.     $89/$EC/                  {Mov  Sp,Bp         Setup Dos Stack Ptr     }
  76.     $2E/$8E/$16/DosSSeg/      {Mov  SS,Cs:DosSSeg Give back Dos Stack     }
  77.  
  78. {RecurOut                                 Clean up the Stack              }
  79.  
  80.     $5D/                               {Pop Bp     Throw away old dos Sp  }
  81.  
  82.     $BD/Regs/                          {Mov    Bp,offset REGS             }
  83.     $2E/$FF/$76/$12/                   {Push Cs:[Bp+12]                   }
  84.     $9D/                               {Popf                              }
  85.     $5D/                               {Pop Bp  Retrieve old BP           }
  86.  
  87.     $FB/                               {Sti     Enable interrupts      }
  88.     $CA/$02/$00                        {Ret Far 002                    }
  89.         );
  90. {.......................................................................}
  91.