home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / msdos / programm / 12384 < prev    next >
Encoding:
Text File  |  1993-01-24  |  4.9 KB  |  184 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!cs.utexas.edu!torn!news.ccs.queensu.ca!slip207.telnet1.QueensU.CA!dmurdoch
  3. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  4. Subject: Re: Causing the compter to stop from the config.sys file
  5. Message-ID: <dmurdoch.337.727832892@mast.queensu.ca>
  6. Lines: 172
  7. Sender: news@knot.ccs.queensu.ca (Netnews control)
  8. Organization: Queen's University
  9. References: <1993Jan21.231925.46627@kuhub.cc.ukans.edu> <1993Jan23.173306.1751@borland.com>
  10. Date: Sat, 23 Jan 1993 23:48:13 GMT
  11.  
  12. In article <1993Jan23.173306.1751@borland.com> dave@borland.com (Dave) writes:
  13. >In article <1993Jan21.231925.46627@kuhub.cc.ukans.edu>
  14. >christos@kuhub.cc.ukans.edu writes:
  15.  
  16. >>        I was wondering if it is possible to cause a pause inside the 
  17. >>config.sys file in a similar way we can do this in the autoexec.bat file.
  18. >>I would appreciate any relevant resposne....
  19.  
  20. >Yes. Get DR DOS and you will be all set. The actual line you
  21. >would add could be as follows:
  22.  
  23. >?REM
  24.  
  25. It hardly seems worth getting DR DOS for such a tiny little utility.  It 
  26. took about an hour to write one in Turbo Pascal; the source code is below.  
  27.  
  28. I'll be uploading this to garbo.uwasa.fi; look for an announcement on comp.
  29. archives.msdos.announce (I expect it'll be called pausedev.zip, and should 
  30. end up in /pc/turbopas, since it's more of a demonstration of how to write 
  31. a device driver than a useful utility.)
  32.  
  33. Compile it to PAUSEDEV.EXE, then put
  34.  
  35.   DEVICE=d:\path\PAUSEDEV.EXE
  36.  
  37. into your CONFIG.SYS wherever you want a pause.
  38.  
  39. Duncan Murdoch
  40. dmurdoch@mast.queensu.ca
  41.  
  42. --------- PAUSEDEV.PAS -----------
  43.   {$S-,F-}         { Stack checking wouldn't work here, and we assume near calls
  44. }
  45.   {$X+}            { Extended syntax }
  46.   {$M $1000,0,0}   { We won't use the heap or stack. }
  47.  
  48.   program pausedev;
  49.   { This program implements a PAUSE command either as DEVICE=PAUSEDEV.EXE
  50.     or executed from the command line. }
  51.  
  52.   uses opint,  { OPro interrupt services, needed for stack switching }
  53.        crt;    { Standard I/O unit that doesn't rely on DOS }
  54.  
  55.   procedure strategy_routine(bp:word); interrupt; forward;
  56.   procedure interrupt_routine(bp:word); interrupt; forward;
  57.   procedure call_Main_Block; forward;
  58.  
  59.   { This procedure must come first!!! }
  60.  
  61.   procedure header;
  62.   assembler;
  63.   asm
  64.     dd $FFFFFFFF    { next driver }
  65.     dw $8000        { attributes of simple character device }
  66.     dw offset strategy_routine
  67.     dw offset interrupt_routine
  68.     db 'PAUSE   '
  69.   end;
  70.  
  71.   const
  72.     stDone = $100;
  73.     stBusy = $200;
  74.  
  75.     cmInit = 0;
  76.  
  77.     device_driver : boolean = false;
  78.  
  79.   type
  80.     request_header = record
  81.       request_length : byte;
  82.       subunit: byte;
  83.       command_code : byte;
  84.       status : word;
  85.       reserved: array[1..8] of byte;
  86.       num_units : byte;
  87.       first_free : pointer;
  88.       args : ^char;
  89.       drive_num : byte;
  90.     end;
  91.  
  92.   var
  93.     local_stack : array[1..4000] of byte;
  94.     end_of_stack : byte;
  95.     request : ^request_header;
  96.  
  97.   procedure handler(var regs : intregisters);
  98.   { This routine is called by the strategy routine, and handles all requests.
  99.     The data segment is okay, and we're running on the local_stack so we've got
  100.     plenty of space.  Remember:  the init sections haven't been called yet!
  101.   }
  102.   begin
  103.     with request^ do
  104.     begin
  105.       case command_code of
  106.       cmInit: begin
  107.                 device_driver := true;
  108.                 Call_Main_Block;
  109.                 first_free := ptr(cseg,0); { Release everything!! }
  110.                 status := stDone;
  111.               end;
  112.       else
  113.         status := stBusy;
  114.       end;
  115.     end;
  116.   end;
  117.  
  118.   procedure RetFar; assembler;
  119.   { Replacement for the IRET code that ends the interrupt routines below }
  120.   asm
  121.     mov sp,bp
  122.     pop bp
  123.     pop es
  124.     pop ds
  125.     pop di
  126.     pop si
  127.     pop dx
  128.     pop cx
  129.     pop bx
  130.     pop ax
  131.     retf
  132.   end;
  133.  
  134.   procedure strategy_routine(bp:word);
  135.   var
  136.     regs : intregisters absolute bp;
  137.   begin
  138.     with regs do
  139.       request := ptr(es,bx);
  140.     RetFar;
  141.   end;
  142.  
  143.   procedure interrupt_routine(bp:word);
  144.   var
  145.     regs : intregisters absolute bp;
  146.   begin
  147.     SwapStackandCallNear(Ofs(handler),@end_of_stack,regs);
  148.     RetFar;
  149.   end;
  150.  
  151.   procedure do_pause;
  152.   begin
  153.     while keypressed do readkey;
  154.     writeln('Press any key to continue....');
  155.     repeat until keypressed;
  156.   end;
  157.  
  158.   procedure Ret_From_Main_Block; assembler;  { Must have declaration just
  159.                                                 like Call_Main_Block }
  160.   asm
  161.   end;
  162.  
  163.   procedure Call_Main_Block; assembler;      { Must come just before main
  164.                                                   entry point }
  165.   asm
  166.     db $eb, 6                                { Jump over the Ret instruction
  167.                                                and System init }
  168.   end;
  169.  
  170.   begin
  171.     do_pause;
  172.  
  173.     if Device_Driver then
  174.       asm
  175.         pop bp
  176.         jmp Ret_From_Main_Block;
  177.       end
  178.     else
  179.       halt;
  180.  
  181.     header;    { This line is never reached, but it fools the linker
  182.                  so that everything is loaded properly. }
  183.   end.
  184.