home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / c / other / learn / syscall.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-28  |  1.8 KB  |  58 lines

  1. /* SYSCALL.C illustrates system calls to DOS and BIOS interrupts using
  2.  * functions:
  3.  *      intdos          intdosx         bdos
  4.  *      int86           int86x          segread
  5.  *
  6.  * The int86x call is not specifically shown in the example, but it is
  7.  * the same as intdosx except that an interrupt number must be supplied.
  8.  */
  9.  
  10. #include <dos.h>
  11. #include <stdio.h>
  12. #define LPT1 0
  13.  
  14. union REGS inregs, outregs;
  15. struct SREGS segregs;
  16.  
  17. main()
  18. {
  19.     const char far *buffer = "Dollar-sign terminated string\n\r$";
  20.     char far *p;
  21.  
  22.     /* Print a $-terminated string on the screen using DOS function 0x9. */
  23.     inregs.h.ah = 0x9;
  24.     inregs.x.dx = FP_OFF( buffer );
  25.     segregs.ds = FP_SEG( buffer );
  26.     intdosx( &inregs, &outregs, &segregs );
  27.  
  28.     /* Get DOS version using DOS function 0x30. */
  29.     inregs.h.ah = 0x30;
  30.     intdos( &inregs, &outregs );
  31.     printf( "\nMajor: %d\tMinor: %d\tOEM number: %d\n\n",
  32.             outregs.h.al, outregs.h.ah, outregs.h.bh );
  33.  
  34.     segread( &segregs );
  35.     printf( "Segments:\n\tCS\t%.4x\n\tDS\t%.4x\n\tES\t%.4x\n\tSS\t%.4x\n\n",
  36.             segregs.cs, segregs.ds, segregs.es, segregs.ss );
  37.  
  38.     /* Make sure printer is available. Fail if any error bit is on,
  39.      * or if either operation bit is off.
  40.      */
  41.     inregs.h.ah = 0x2;
  42.     inregs.x.dx = LPT1;
  43.     int86( 0x17, &inregs, &outregs );
  44.     if(  (outregs.h.ah & 0x29) || !(outregs.h.ah & 0x80) ||
  45.                                   !(outregs.h.ah & 0x10) )
  46.         printf( "Printer not available." );
  47.     else
  48.     {
  49.         /* Output a string to the printer using DOS function 0x5. */
  50.         for( p = buffer; *p != '$'; p++ )
  51.             bdos( 0x05, *p, 0 );
  52.  
  53.         /* Do print screen. */
  54.         inregs.h.ah = 0x05;
  55.         int86( 0x05, &inregs, &outregs );
  56.     }
  57. }
  58.