home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / quikc21.zip / QINITEST.C < prev    next >
Text File  |  1989-07-06  |  15KB  |  398 lines

  1. /*===========================================================================*\
  2. | QINITEST.C                                               ver 2.1, 07-06-89  |
  3. |                                                                             |
  4. | Tests your system configuration                                             |
  5. |                                                                             |
  6. |  Copyright (c) 1988,1989 by James H. LeMay, All rights reserved.            |
  7. |                                                                             |
  8. |  Conversion to C by Jordan Gallagher / Wisdom Research                      |
  9. \*===========================================================================*/
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <conio.h>
  14. #include <string.h>
  15. #include <dos.h>
  16.  
  17. #include "qwikc21.h"
  18.  
  19. /* un-comment the line below to include IBM's submodel ID detection */
  20. /* #define ADD_SUBMODEL */
  21.  
  22. char newmode, oldmode;
  23. char strng[80];
  24. char ch;
  25. int cursor_delay=1500;
  26.  
  27. #ifndef __TURBOC__
  28. union REGS mr;
  29. #define textmode(m)     { mr.h.ah=0; mr.h.al=m; int86(0x10,&mr,&mr); }
  30. #endif
  31.  
  32.  
  33. /******************************| check_zenith |*****************************\
  34. Since Zenith doesn't have snow on any CGAs, turn off snow checking.
  35. \***************************************************************************/
  36. void check_zenith(void)
  37. {
  38.     char tmp[10];
  39.  
  40.     movedata( 0xF000u, 0x800Cu, (unsigned)(((char far *)tmp)+1),
  41.                                 (unsigned)((char far *)tmp),     8 );
  42.     if(qsnow && (strncmp( tmp, "ZDS CORP", 8 )) == 0) {
  43.         qsnow=0;
  44.         cardsnow=0;
  45.     }
  46. }
  47.  
  48.  
  49. /********************************| clearscr |*******************************\
  50. Clears the screen using the yellow on blue attribute.
  51. \***************************************************************************/
  52. void clearscr(void)
  53. {
  54.     qfill( 1, 1, crt_rows, crt_cols, YELLOW+BLUE_BG, ' ' );
  55. }
  56.  
  57.  
  58. /*********************************| init |***********************************\
  59. Initializes by checking for Zenith and clearing the screen.
  60. \****************************************************************************/
  61. void init(void)
  62. {
  63.     qreinit();
  64.     check_zenith();
  65.     setmultitask();
  66. #ifdef __TURBOC__
  67.     if(inmultask) directvideo=0;
  68. #endif
  69.     clearscr();
  70. }
  71.  
  72.  
  73. /********************************| btoa |************************************\
  74. Converts a long to a string.  The target string contains the long in
  75. binary form, i.e. "10100101101101010010010110110101".
  76. The parameter bitcnt specifies the number of bits to be processed.
  77. The return value is a pointer to the target string.
  78. \****************************************************************************/
  79. char *btoa( long val, char bitcnt, char *string )
  80. {
  81.     char bit;
  82.  
  83.     for(bit=0; bit < bitcnt; bit++) {
  84.         string[bit] = ((val >> bit) & 1) + 48;
  85.     }
  86.     string[bit]=0;
  87.  
  88.     return(string);
  89. }
  90.  
  91.  
  92. /********************************| htoa |************************************\
  93. Converts a long to a string.  The target string contains the long in
  94. hexadecimal form, i.e. "21CF89A5".
  95. The parameter hcnt specifies the amount of characters the target
  96. string should contain.
  97. The return value is a pointer to the target string.
  98. \****************************************************************************/
  99. char *htoa( long val, char hcnt, char *string )
  100. {
  101.     if(hcnt > 4)
  102.         sprintf( string, "0x%*lX", hcnt, val );
  103.     else
  104.     if(hcnt > 2)
  105.         sprintf( string, "0x%0*X", hcnt, (int) val );
  106.     else
  107.     if(hcnt <= 2)
  108.         sprintf( string, "0x%0*hX", hcnt, (unsigned char) val );
  109.  
  110.     return(string);
  111. }
  112.  
  113.  
  114. /*********************************| stryn |**********************************\
  115. Places the string "YES" or "NO" in the str parameter based on whether
  116. the specified int is 1 or 0.
  117. \****************************************************************************/
  118. char *stryn( int val, char *str )
  119. {
  120.     return(strcpy( str, val ? "YES" : "NO" ));
  121. }
  122.  
  123.  
  124. /******************************| display_dev |*******************************\
  125. Sets the global variable "strng" based on the specified display device's
  126. number.
  127. \****************************************************************************/
  128. void display_dev( char dd )
  129. {
  130.     switch(dd) {
  131.         case 0x00: strcpy( strng, "No display" );                  break;
  132.         case 0x01: strcpy( strng, "MDA with 5151 monochrome" );    break;
  133.         case 0x02: strcpy( strng, "CGA with 5153/4 color" );       break;
  134.         case 0x04: strcpy( strng, "EGA with 5153/4 color" );       break;
  135.         case 0x05: strcpy( strng, "EGA with 5151 monochrome" );    break;
  136.         case 0x06: strcpy( strng, "PGC with 5175 color" );         break;
  137.         case 0x07: strcpy( strng, "VGA with analog monochrome" );  break;
  138.         case 0x08: strcpy( strng, "VGA with analog color" );       break;
  139.         case 0x0B: strcpy( strng, "MCGA with analog monochrome" ); break;
  140.         case 0x0C: strcpy( strng, "MCGA with analog color" );      break;
  141.         default:   strcpy( strng, "Reserved" );
  142.     }
  143. }
  144.  
  145.  
  146. /*****************************| do_setcursor |*******************************\
  147. Calls setcursor with the cursor parameter, and displays the specified
  148. message along with a hexadecimal version of the cursor word.
  149. \****************************************************************************/
  150. void do_setcursor( char *msg, unsigned cursor )
  151. {
  152.     char msg1[80],msg2[80];
  153.  
  154.     strcpy( msg1, msg );
  155.     htoa( (long) cursor, 4, msg2 );
  156.  
  157.     setcursor( cursor );
  158.     qwriteeos( SAMEATTR, strcat( msg1, msg2 ) );
  159.     gotoeos();
  160. #ifdef __TURBOC__
  161.     delay( cursor_delay );
  162. #else
  163.     suspend( cursor_delay );
  164. #endif
  165.     eosln();
  166. }
  167.  
  168.  
  169. /*****************************| do_modcursor |*******************************\
  170. Calls modcursor with the cursor parameter, and displays the specified
  171. message along with a hexadecimal version of the cursor's word after
  172. being set by modcursor.
  173. \****************************************************************************/
  174. void do_modcursor( char *msg, int cursor )
  175. {
  176.     char msg1[30],msg2[10],msg3[10];
  177.  
  178.     modcursor( cursor );
  179.     strcpy( msg1, msg );
  180.     htoa( (long) cursor, 4, msg2 );
  181.     htoa( (long) getcursor(), 4, msg3 );
  182.     strcat( msg1, msg2 );
  183.     strcat( msg1, " " );
  184.     strcat( msg1, msg3 );
  185.  
  186.     qwriteeos( SAMEATTR, msg1 );
  187.     gotoeos();
  188. #ifdef __TURBOC__
  189.     delay( cursor_delay );
  190. #else
  191.     suspend( cursor_delay );
  192. #endif
  193.     eosln();
  194. }
  195.  
  196.  
  197. /*******************************| waitkey |**********************************\
  198. Waits for a keypress, eliminating extra key-ahead if an extended key
  199. is pressed, generating an escape sequence.
  200. \****************************************************************************/
  201. void waitkey(void)
  202. {
  203.     qwrite( crt_rows, 1, SAMEATTR, "Press any key..." );
  204.     gotoeos();
  205.  
  206.     do ch=getch(); while(kbhit());
  207. }
  208.  
  209.  
  210. /*********************************| main |***********************************\
  211. The main block.
  212. \****************************************************************************/
  213. void main()
  214. {
  215.     char s[80];
  216.  
  217.     qinit();
  218.     init();
  219.  
  220.     oldmode=qvideo_mode;
  221.  
  222.     qwrite( 1, 1, SAMEATTR, "Which text mode (0,1,2,3,7) ? " );
  223.     gotoeos();
  224.  
  225.     while( strchr( "01237", (ch=getch()) )==NULL );
  226.     newmode=ch-'0';
  227.  
  228.     if(newmode != oldmode) {
  229.         textmode( newmode );
  230.         qreinit();
  231.     }
  232.  
  233.     init();
  234.  
  235.     switch( cpuid ) {
  236.         case cpu8086:  strcpy( strng, "Intel 8086/88"   ); break;
  237.         case cpu80186: strcpy( strng, "Intel 80186/188" ); break;
  238.         case cpu80286: strcpy( strng, "Intel 80286"     ); break;
  239.         case cpu80386: strcpy( strng, "Intel 80386"     ); break;
  240.     }
  241.  
  242.     qwrite( 1, 1, SAMEATTR, "CPU ident         = " );
  243.     qwriteeos( SAMEATTR, strng );
  244.  
  245. #ifdef ADD_SUBMODEL
  246.     get_submodel_id();           /* Check docs before using this function. */
  247. #endif
  248.  
  249.     switch(system_id) {
  250.         case 0xFF: strcpy( strng, "IBM PC"    ); break;
  251.         case 0xFE: strcpy( strng, "IBM PC XT" ); break;
  252.         case 0xFD: strcpy( strng, "IBM PCjr"  ); break;
  253.         case 0xFC:
  254.             switch(submodel_id) {
  255.                 case 0:  strcpy( strng, "IBM PC AT (6 MHz)" ); break;
  256.                 case 1:  strcpy( strng, "IBM PC AT (8 MHz)" ); break;
  257.                 case 2:  strcpy( strng, "IBM PC XT (286)"   ); break;
  258.                 case 4:  strcpy( strng, "IBM PS/2 Model 50" ); break;
  259.                 case 5:  strcpy( strng, "IBM PS/2 Model 60" ); break;
  260.                 default: strcpy( strng, "IBM PS/2 VGA type" ); break;
  261.             } break;
  262.         case 0xFB: strcpy( strng, "IBM PC XT (256/640)" ); break;
  263.         case 0xFA:
  264.             switch(submodel_id) {
  265.                 case 0:  strcpy( strng, "IBM PS/2 Model 30" );
  266.                 case 1:  strcpy( strng, "IBM PS/2 Model 25" );
  267.                 default: strcpy( strng, "IBM PS/2 MCGA type" );
  268.             } break;
  269.         case 0xF9: strcpy( strng, "IBM PC convertible" ); break;
  270.         case 0xF8:
  271.             switch(submodel_id) {
  272.                 case 0:  strcpy( strng, "IBM PS/2 Model 80 (16 MHz)" ); break;
  273.                 case 1:  strcpy( strng, "IBM PS/2 Model 80 (20 MHz)" ); break;
  274.                 case 9:  strcpy( strng, "IBM PS/2 Model 70 (16 MHz)" ); break;
  275.                 default: strcpy( strng, "IBM PS/2 Model 70/80 type"  ); break;
  276.             } break;
  277.         default: strcpy( strng, "Unknown, not an IBM" ); break;
  278.     }
  279.  
  280.     qwrite( 2, 1, SAMEATTR, "System ID         = " );
  281.     qwriteeos( SAMEATTR, htoa( (long) system_id, 2, s ) );
  282.  
  283.     qwrite( 3, 1, SAMEATTR, "Submodel ID       = " );
  284.  
  285. #ifdef ADD_SUBMODEL
  286.     qwriteeos( SAMEATTR, itoa( submodel_id, s, 10 ) );
  287. #else
  288.     qwriteeos( SAMEATTR, "??" );
  289.     strcpy( strng, "(detection disabled - see QINITEST.C)" );
  290. #endif
  291.  
  292.     qwrite( 4, 3,  SAMEATTR, strng );
  293.     qwrite( 5, 1,  SAMEATTR, "Have PS/2 video   = " );
  294.     qwriteeos(     SAMEATTR, stryn( have_ps2, s ) );
  295.     qwrite( 6, 1,  SAMEATTR, "IBM 3270 PC       = " );
  296.     qwriteeos(     SAMEATTR, stryn( have_3270, s ) );
  297.     qwrite( 7, 1,  SAMEATTR, "Prior video mode  = " );
  298.     qwriteeos(     SAMEATTR, itoa( oldmode, s, 10 ) );
  299.     qwrite( 8, 1,  SAMEATTR, "Video mode now    = " );
  300.     qwriteeos(     SAMEATTR, itoa( qvideo_mode, s, 10 ) );
  301.     qwrite( 9, 1,  SAMEATTR, "Wait-for-retrace  = " );
  302.     qwriteeos(     SAMEATTR, stryn( qsnow, s ) );
  303.     qwrite( 10, 1, SAMEATTR, "Max page #        = " );
  304.     qwriteeos(     SAMEATTR, itoa( maxpage, s, 10 ) );
  305.  
  306.     if(have_3270) {
  307.         qwrite( 11, 1, SAMEATTR, "Disp dev 3270     = " );
  308.         qwriteeos( SAMEATTR, htoa( (long) active_disp_dev_3270, 2, s ) );
  309.  
  310.         switch( active_disp_dev_3270 ) {
  311.           case 0: strcpy(strng, "5151 or 5272 display and adapter");     break;
  312.           case 1: strcpy(strng, "3295 display and adapter");             break;
  313.           case 2: strcpy(strng, "5151 or 5272, adapter, XGA graphics");  break;
  314.           case 3: strcpy(strng, "5279 display, 3270 PC G adapter");      break;
  315.           case 4: strcpy(strng, "5379 C01 display, 3270 PC GX adapter"); break;
  316.           case 5: strcpy(strng, "5379 M01 display, 3270 PC GX adapter"); break;
  317.           case 0xFF: strcpy(strng, "Unknown, not a 3270 PC");            break;
  318.           default: strcpy( strng, "Reserved" );                          break;
  319.         }
  320.  
  321.         qwrite( 12, 3, SAMEATTR, strng );
  322.     } else {
  323.         display_dev( active_disp_dev );
  324.         qwrite( 11, 1, SAMEATTR, "Active Disp Dev   = " );
  325.         qwriteeos(     SAMEATTR, itoa( active_disp_dev, s, 10 ) );
  326.         qwrite( 12, 3, SAMEATTR, strng );
  327.  
  328.         if(system_id == 0xF9) {       /* PC convertible */
  329.             qwrite( 13, 1, SAMEATTR, "Alt Disp Dev PC Conv = " );
  330.             qwriteeos(     SAMEATTR, itoa( alt_disp_dev_pcc, s, 10 ) );
  331.         } else {
  332.             display_dev( alt_disp_dev );
  333.             qwrite( 13, 1, SAMEATTR, "Alt Disp Dev      = " );
  334.             qwriteeos(     SAMEATTR, itoa( alt_disp_dev, s, 10 ) );
  335.             qwrite( 14, 3, SAMEATTR, strng );
  336.         }
  337.  
  338.         qwrite( 15, 1, SAMEATTR, "Hercules model    = " );
  339.         qwriteeos(     SAMEATTR, itoa( herc_model, s, 10 ) );
  340.  
  341.         switch(herc_model) {
  342.             case 0: strcpy( strng, "No Hercules card" );             break;
  343.             case 1: strcpy( strng, "Hercules Graphics Card" );       break;
  344.             case 2: strcpy( strng, "Hercules Graphics Card Plus" );  break;
  345.             case 3: strcpy( strng, "Hercules InColor Card" );        break;
  346.         }
  347.  
  348.         qwrite( 16, 3, SAMEATTR, strng );
  349.     }
  350.  
  351.     qwrite( 17, 1, SAMEATTR, "CRT rows          = " );
  352.     qwriteeos(     SAMEATTR, itoa( crt_rows, s, 10 ) );
  353.     qwrite( 18, 1, SAMEATTR, "CRT columns       = " );
  354.     qwriteeos(     SAMEATTR, itoa( crt_cols, s, 10 ) );
  355.     qwrite( 19, 1, SAMEATTR, "Cursor start      = " );
  356.     qwriteeos(     SAMEATTR, itoa( (char) cursor_initial, s, 16 ) );
  357.     qwrite( 20, 1, SAMEATTR, "Cursor end        = " );
  358.     qwriteeos(     SAMEATTR, itoa( (char) cursor_initial >> 4, s, 16 ) );
  359.  
  360.     if(active_disp_dev >= ega_color && active_disp_dev <= mcga_color) {
  361.         qwrite( 21, 1, SAMEATTR, "EGA rows          = " );
  362.         qwriteeos(     SAMEATTR, itoa( egarows, s, 10 ) );
  363.         qwrite( 22, 1, SAMEATTR, "EGA FontSize      = " );
  364.         qwriteeos(     SAMEATTR, itoa( egafontsize, s, 10 ) );
  365.         qwrite( 23, 1, SAMEATTR, "EGA Info          = " );
  366.         qwriteeos(     SAMEATTR, btoa( (long) egainfo, 8, s ) );
  367.         qwrite( 24, 1, SAMEATTR, "EGA Switches      = " );
  368.         qwriteeos(     SAMEATTR, btoa( (long) ega_switches, 8, s ) );
  369.     }
  370.  
  371.     waitkey();
  372.     clearscr();
  373.  
  374.     qwritec( 1, 1, crt_cols, SAMEATTR, "Cursor Modes Test:" );
  375.     qwrite( 3, 1, SAMEATTR, "SET              MODE" );
  376.     qwrite( 4, 1, SAMEATTR, "-------------   ------" );
  377.     eosln();
  378.  
  379.     do_setcursor( "Initial       = ", cursor_initial );
  380.     do_setcursor( "Underline     = ", cursor_underline );
  381.     do_setcursor( "Half-block    = ", cursor_halfblock );
  382.     do_setcursor( "Block         = ", cursor_block );
  383.     eosln();
  384.  
  385.     qwriteeos( SAMEATTR, "MODIFY           MASK   MODE" );
  386.     qwrite( eosr()+1, 1, SAMEATTR, "-------------   ------ ------" );
  387.     eosln();
  388.  
  389.     do_modcursor( "Off           = ", cursor_off );
  390.     do_modcursor( "On            = ", cursor_on );
  391.     do_modcursor( "Erratic Blink = ", cursor_blink );
  392.  
  393.     setcursor( cursor_initial );
  394.     waitkey();
  395.     textmode( oldmode );
  396. }
  397.  
  398.