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

  1. {****************************************************************************}
  2. {                 S  T  A  Y  S  A  V  E  .  I  N  C                         }
  3. {                                                                            }
  4. {           This is the Staysave.Inc file included above                     }
  5. {                                                                            }
  6. {      Separate the code out into a file or replace the $I Staysave.320      }
  7. {                statement above with this code.                             }
  8. {****************************************************************************}
  9.  
  10. {This Inline routine will save the regs and Stack for Stay resident programs.
  11.  It restores Ds and Ss from the previously saved integer constants "OurDseg"
  12.   and "OurSSeg". This is important since Dos is not re-entrant and any attempt
  13.   to use Interrupt I/O services will clobber the very stack on which the
  14.   Resident Turbo program just saved its regs. Thus, on the final return, you
  15.   and Toto will end up somewhere other than Kansas and without your Ruby Reds.
  16.    }
  17.  
  18. { Arthor:      Lane Ferris
  19.               - The Hunter's Helper -
  20.  
  21.        Distributed to the Public Domain for use without profit.
  22.                     Original Version 5.15.85
  23. }
  24.                                    { On entry the Stack will already contain: }
  25.                                    {  1) Sp for Dos                           }
  26.                                    {  2) Bp for Dos                           }
  27.                                    {  3) Ip for Dos                           }
  28.                                    {  4) Cs for Dos                           }
  29.                                    {  5) Flags for Dos                        }
  30.   Inline (
  31.  
  32.  { The following routine avoids the overhead of saving the DOS stack         }
  33.  { when the INT 16 function was not for a character request. This happens    }
  34.  { often (every four chars) as DOS checks on ^S/^Q/^C/Keypressed  ad.nausea  }
  35.  
  36.    $80/$FC/$00/                        {Cmp Ah,00     If Char request,       }
  37.    $74/$07/                            {Je   ChrRqst  enter Staysave code    }
  38.    $5D/$5D/                            {Pop  Bp/Pop Bp    Restore Bp         }
  39.    $2E/
  40.    $FF/$2E/User_IntIP/                 {Jmp Far Cs:[User_IntIp]              }
  41.  
  42. {ChrRqst: }
  43.     $FA /                              {  Cli       Stop all interrupts       }
  44.                                        { Bp and Sp aready saved at Begin Stmt }
  45.     $55/                               {Push   Bp  Save again for Regpak      }
  46.     $BD/Regs/                          {Mov    Bp,offset REGS}
  47.     $2E/$89/$46/$00/                   {CS:Mov [Bp+0],AX}
  48.     $2E/$89/$5E/$02/                   {Cs:Mov [Bp+2],Bx}
  49.     $2E/$89/$4E/$04/                   {CS:Mov [Bp+4],CX}
  50.     $2E/$89/$56/$06/                   {CS:Mov [Bp+6],DX}
  51.     $2E/$8F/$46/$08/                   {Pop    Cs:[Bp+8] Fetch Bp from stack  }
  52.     $2E/$89/$76/$0A/                   {CS:Mov [Bp+A],SI}
  53.     $2E/$89/$7E/$0C/                   {CS:Mov [Bp+C],DI}
  54.     $2E/$8C/$5E/$0E/                   {CS:Mov [Bp+E],DS}
  55.     $2E/$8C/$46/$10/                   {CS:Mov [Bp+10],ES}
  56.     $9C/                               {PUSHF  put Flags on stack to retrieve }
  57.     $2E/$8F/$46/$12/                   {POP Cs:[Bp+12]}
  58.  
  59.     { If Current SS := [OurSseg] or Inuse = True, then dont save the stack. }
  60.     { This program is being recursive.                                      }
  61.  
  62.      $2E/$80/$3E/Inuse/$01/   {Cmp  Cs:[Inuse],1                          }
  63.      $74/$57/                 {Je   ReCurin             -J-U-M-P-         }
  64.  
  65.  
  66.      $2E/$8C/$16/DosSSeg/     {Mov  Cs:DosSSeg,SS Save Dos Stack Segment    }
  67.      $8C/$D6/                 {Mov  Si,SS         If this is our Stack Seg  }
  68.      $8E/$C6/                 {Mov  Es,Si         Get Dos StackSeg          }
  69.      $2E/$8E/$16/OurSSeg/     {Mov  SS,Cs:OurSSeg Get our Stack segment     }
  70.      $2E/$8E/$1E/OurDseg/     {Mov  Ds,Cs:Our_Ds  Setup our Data Segment    }
  71.  
  72.  
  73.      $2E/$3B/$36/OurSSeg/     {Cmp  Si,Cs:OurSSeg ..use current Stack ptr   }
  74.      $89/$E6/                 {Mov  Si,Sp         ..value..else reset stack }
  75.      $74/$05/                 {Je   $+5           ..to original Turbo stack }
  76.      $3E/$8B/$36/$74/$01/     {Mov  Si,Ds:[174]   ..(cf. code at B2B 3.0x)  }
  77.  
  78.      $87/$F4/                 {Xchg Sp,Si         Set new  Stack Pointer    }
  79.                                           { Save Dos/User regs for Exit     }
  80.      $2E/$FF/$76/$00/         {Push [Bp+0]  Save Ax                         }
  81.      $2E/$FF/$76/$02/         {Push [Bp+2]  Save Bx                         }
  82.      $2E/$FF/$76/$04/         {Push [Bp+4]  Save Cx                         }
  83.      $2E/$FF/$76/$06/         {Push [Bp+6]  Save Dx                         }
  84.                               {Push [Bp+8]  Save Bp                         }
  85.      $2E/$FF/$76/$0A/         {Push [Bp+A]  Save Si                         }
  86.      $2E/$FF/$76/$0C/         {Push [Bp+C]  Save Di                         }
  87.      $2E/$FF/$76/$0E/         {Push [Bp+E]  Save Ds                         }
  88.      $2E/$FF/$76/$10/         {Push [Bp+10] Save Es                         }
  89.  
  90.     { Now save 40 Words from the Dos Stack before performing any         }
  91.     { I/O or re-using the Dos stack                                      }
  92.  
  93.      $B9/>$0028/              {Mov  Cx,40  Save 40 Dos Stack words for Retn }
  94.  {Restack:}
  95.      $26/$FF/$34/             {Push Es:[Si] Our Stack := Dos Es:Si          }
  96.      $46/$46/                 {Inc  Si/Inc Si Get Next Dos Stack Word       }
  97.      $E2/$F9/                 {Loop to Restack                              }
  98.  
  99.      $2E/$8E/$16/OurSSeg/     {Mov  SS,Cs:OurSSeg Set up our Stack          }
  100.      $56/                     {Push Si            Save bottom of Dos Stack  }
  101.      $2E/$8C/$5E/$0E/         {Mov  Cs:[Bp+E],Ds  Set New Data Segmt in regs}
  102. {Recurin                                            Jump here if Recursion  }
  103.      $FB                      {Sti Enable Interrupts                        }
  104.  
  105.        ) ;
  106. {...........................................................................}