home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c329 / 2.img / EXAMPLES / CDEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-15  |  29.2 KB  |  875 lines

  1. /*   Program to demonstrate video graphics functions
  2.        using NDP C-386 graphics extension library
  3.  
  4.        MicroWay, Inc.
  5.        P.O. Box 79
  6.        Kingston, MA 02364
  7.        (508) 746-7341
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <math.h>
  12.  
  13. #include <grex.h>  /* graphic functions must be declared */
  14.  
  15. int show_video_systems();
  16. int nint();
  17.  
  18. #define nint(a) ( (((int)a) % 2 == 1) ? (int)a+0.5 : (int)a )
  19. #define min0(x,y) ((x < y) ? x : y)
  20. #define max0(x,y) ((x > y) ? x : y)
  21.  
  22. main()
  23. {
  24.     int i, j, k, ier;
  25.     int mode;
  26.     int new_mode;
  27.     int code;
  28.     int limx, limy, max_color;
  29.     int xmin, xmax, ymin, ymax;
  30.     int video_system[4];
  31.     int ix, iy, ih, iv;
  32.     int jx, jy, L;
  33.     int new_color, key;
  34.     char pal [17];
  35.     char prompt [64], string [64];
  36.     static char buffer [4096];
  37.     static char text_buffer [4096];
  38.  
  39.     static unsigned dash_patterns [16] = {0xFFFFFFFF,0x00FFFFFF,0x0000FFFF,
  40.          0x000000FF,0xF0F0F0F0,0x0F0F0F0F,0xFF00FF00,0x00FF00FF,0xF00FF00F,
  41.          0xF6F6F6F6,0x11111111,0x33333333,0x55555555,0x77777777,0x99999999,
  42.          0xAAAAAAAA};
  43.  
  44.     printf("\nNDP C-386 Graphics Extension test program\n\n");
  45.  
  46.     printf("MicroWay, Inc.\nP.O. Box 79\nKingston, MA 02364\n(508) 746-7341\n\n");
  47.  
  48.     mode = video_configuration(video_system);
  49.  
  50.     printf("Video system codes: %d %d %d %d\n",video_system[0],
  51.                                                video_system[1],
  52.                                                video_system[2],
  53.                                                video_system[3]);
  54.  
  55.     printf("Suggested graphic mode: %d\n",mode);
  56.  
  57.     while ( (new_mode = show_video_systems()) != 0)
  58.     {
  59.         if ( new_mode < 0)
  60.         {
  61.             printf ("If other than 800 horizontal pixels, enter horizontal pixel count: ");
  62.             gets (string);
  63.             if (strlen(string) == 0)
  64.             {
  65.                 limx = 800;
  66.             }
  67.             else
  68.             {
  69.                 sscanf (string,"%d",&limx);
  70.             }
  71.             printf ("If other than 600 vertical pixels, enter vertical pixel count: ");
  72.             gets (string);
  73.             if (strlen(string) == 0)
  74.             {
  75.                 limy = 600;
  76.             }
  77.             else
  78.             {
  79.                 sscanf (string,"%d",&limy);
  80.             }
  81.             new_mode = super_vga (-new_mode,limx,limy);
  82.             ier = new_mode;
  83.         }
  84.         else
  85.         {
  86.             ier = graphics_mode (new_mode);
  87.         }
  88.  
  89.         if ( ier != 0)
  90.         {
  91.             get_device_limits(&limx,&limy,&max_color);
  92.  
  93. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  94.  
  95. /*  Test 1: Set pixels                                                  */
  96.  
  97.             clear();
  98.  
  99.             set_color(6);
  100.  
  101.             for (i = 100; i <= 150; i++)
  102.             {
  103.                 j = i;
  104.                 set_pixel(i,j);
  105.             }
  106.  
  107.             graphic_text("Test 1: Setting pixels",10,limy-20,14);
  108.             graphic_text("Press a key to continue",10,limy-10,14);
  109.  
  110.             pause();
  111.  
  112. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  113.  
  114. /*  Test 2: Draw lines                                                  */
  115.  
  116.             set_color(1);
  117.  
  118.             move(100,100);
  119.             draw(150,100);
  120.             draw(150,150);
  121.             draw(100,150);
  122.             draw(100,100);
  123.  
  124.             move(101,101);
  125.             draw(149,101);
  126.             draw(149,149);
  127.             draw(101,149);
  128.             draw(101,101);
  129.  
  130.             set_color(4);
  131.  
  132.             move ( 99, 99);
  133.             draw (151, 99);
  134.             draw (151,151);
  135.             draw ( 99,151);
  136.             draw ( 99, 99);
  137.  
  138.             move ( 98, 98);
  139.             draw (152, 98);
  140.             draw (152,152);
  141.             draw ( 98,152);
  142.             draw ( 98, 98);
  143.  
  144.             set_color (0);
  145.             filled_rectangle (0, limy-20, limx, limy);
  146.  
  147.             graphic_text("Test 2: drawing lines",10,limy-20,14);
  148.             graphic_text("Press a key to continue",10,limy-10,14);
  149.  
  150.             pause();
  151.  
  152. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  153.  
  154. /*  Test 3. Circles                                                      */
  155.  
  156.             ix = 240;
  157.             iy = 100;
  158.             ih  =  30 * aspect_ratio(new_mode)/100;
  159.             iv  =  30;
  160.  
  161.             set_color (2);
  162.             open_ellipse (ix,iy,ih,iv);
  163.             filled_ellipse (ix+2*ih,iy+iv,ih,iv);
  164.  
  165.             set_color (0);
  166.             filled_rectangle (0, limy-20, limx, limy);
  167.  
  168.             graphic_text("Test 3: Circles",10,limy-20,14);
  169.             graphic_text("Press a key to continue",10,limy-10,14);
  170.  
  171.             pause();
  172.  
  173. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  174.  
  175. /*  Test 4: Saving and restoring windows                                 */
  176.  
  177.             set_color (0);
  178.             filled_rectangle (0,limy-30,limx,limy);
  179.  
  180.             graphic_text("Test 4: Saving and restoring windows",10,limy-30,14);
  181.  
  182.             save_window (98,98,152,152,buffer);
  183.             restore_window (38,98,92,152,buffer);
  184.  
  185.             pause();
  186.  
  187.             strcpy (string,"Saved window; press a key to restore");
  188.             L = strlen(string);
  189.             ix = 19;
  190.             iy = 120;
  191.             jx = 25+8*L;
  192.             jy = 131;
  193.             save_window (ix, iy, jx, jy, buffer);
  194.             set_color (0);
  195.             filled_rectangle (ix, iy, jx, jy);
  196.             set_color (11);
  197.             move (ix,iy);
  198.             draw (jx,iy);
  199.             draw (jx,jy);
  200.             draw (ix,jy);
  201.             draw (ix,iy);
  202.             graphic_text (string, ix+5, iy+2, 11);
  203.             pause ();
  204.             restore_window (ix, iy, jx, jy, buffer);
  205.  
  206.             graphic_text ("Move window using arrow keys", 10, limy-20, 14);
  207.             graphic_text ("Press <Enter> to begin the next test", 10, limy-10, 14);
  208.  
  209.             strcpy (string,"Text window");
  210.             L = strlen(string);
  211.             ix = 16;
  212.             iy = 120;
  213.             jx = 25+8*L;
  214.             jy = 131;
  215.             save_window (ix, iy, jx, jy, buffer);
  216.             set_color (0);
  217.             filled_rectangle (ix, iy, jx, jy);
  218.             set_color (11);
  219.             move (ix,iy);
  220.             draw (jx,iy);
  221.             draw (jx,jy);
  222.             draw (ix,jy);
  223.             draw (ix,iy);
  224.             graphic_text (string, ix+5, iy+2, 11);
  225.  
  226.             save_window (ix, iy, jx, jy, text_buffer);
  227.             while ( (key = pause()) != 13 )
  228.             {
  229.                 restore_window (ix, iy, jx, jy, buffer);
  230.  
  231.                 if ( key == -71 ) {ix -= 8; iy -= 2; jx -= 8; jy -= 2;}
  232.                 if ( key == -72 ) {         iy -= 2;          jy -= 2;}
  233.                 if ( key == -73 ) {ix += 8; iy -= 2; jx += 8; jy -= 2;}
  234.                 if ( key == -75 ) {ix -= 8;          jx -= 8;         }
  235.                 if ( key == -77 ) {ix += 8;          jx += 8;         }
  236.                 if ( key == -79 ) {ix -= 8; iy += 2; jx -= 8; jy += 2;}
  237.                 if ( key == -80 ) {         iy += 2;          jy += 2;}
  238.                 if ( key == -81 ) {ix += 8; iy += 2; jx += 8; jy += 2;}
  239.  
  240.                 if (ix < 0) {jx += 8; ix += 8;}
  241.                 if (iy < 0) {jy += 2; iy += 2;}
  242.                 if (jx > limx) {ix -= 8; jx -= 8;}
  243.                 if (jy > limy) {iy -= 2; jy -= 2;}
  244.  
  245.                 save_window (ix, iy, jx, jy, buffer);
  246.                 restore_window (ix, iy, jx, jy, text_buffer);
  247.             }
  248.  
  249.             restore_window (ix, iy, jx, jy, buffer);
  250.  
  251. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  252.  
  253. /*  Test 5: Move a cursor and fill regions                              */
  254.  
  255.             set_color(0);
  256.             filled_rectangle(10,limy-30,limx,limy);
  257.             graphic_text("Test 5: Cursor movement and region fill",10,limy-30,14);
  258.             graphic_text("Move cursor using arrow keys",10,limy-20,14);
  259.             graphic_text("Press R to fill red, B = blue, G = green",10,limy-10,14);
  260.             ix = 240;
  261.             iy = 100;
  262.             i = ix;
  263.             j = iy;
  264.             while ( (k = crawl(&i,&j)) != 13 )
  265.             {
  266.                 if (k == 'b' || k == 'B') flood_fill (i,j,1,1);
  267.                 if (k == 'g' || k == 'G') flood_fill (i,j,2,2);
  268.                 if (k == 'r' || k == 'R') flood_fill (i,j,4,4);
  269.             }
  270.  
  271. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  272.  
  273. /*  Test 6: Cursor movement in a clipping window                         */
  274.  
  275.             set_color (0);
  276.             filled_rectangle (10,limy-30,limx,limy);
  277.             graphic_text("Test 6: Clipping window (Quarter-screen, centered)",10,limy-30,14);
  278.             graphic_text ("Move cursor using arrow keys",10,limy-20,14);
  279.             graphic_text ("Press a key to continue",10,limy-10,14);
  280.             set_clip_limits (limx/4,limy/4,3*limx/4,3*limy/4);
  281.             get_clip_limits (&xmin,&ymin,&xmax,&ymax);
  282.             i = (xmin + xmax)/2;
  283.             j = (ymin + ymax)/2;
  284.             crawl (&i,&j);
  285.             get_device_limits (&limx,&limy,&max_color);
  286.             set_clip_limits (0,0,limx,limy);
  287.  
  288. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  289.  
  290. /*  Test 7: Show colors available in this mode                           */
  291.  
  292.             get_clip_limits(&xmin,&ymin,&xmax,&ymax);
  293.             k = xmin;
  294.             for (i=0; i <= max_color; i++)
  295.             {
  296.                 set_color(i);
  297.                 j = k+1;
  298.                 k = j + xmax/(max_color+1);
  299.                 filled_rectangle(j,ymin,k,ymax);
  300.             }
  301.             graphic_text("Test 7: Available colors", xmin+10, ymax-10, 15);
  302.  
  303.             pause();
  304.  
  305. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  306.  
  307. /*  Test 8: Line clipping                                                */
  308.  
  309.             clear ();
  310.             set_color (12);
  311.             move (-100,-100);
  312.             draw ( 800, 100);
  313.             draw ( 300, 500);
  314.             draw (-100, 200);
  315.             graphic_text ("Test 8: Clipped lines",10,limy-10,9);
  316.  
  317.             pause();
  318.  
  319. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  320.  
  321. /*  Test 9: Graphic pages                                                */
  322.  
  323.             clear();
  324.  
  325.             if ( graphic_page_count() > 1 )
  326.             {
  327.                 graphic_text ("Test 9: Graphic pages", 10, limy-30, 14);
  328.                 graphic_text ("Page Zero",10,limy-20,10);
  329.                 graphic_text ("Press 1 to see page one, <Enter> to continue", 10, limy-10, 14);
  330.                 set_color (4);
  331.                 ix = limx/2;
  332.                 iy = limy/2;
  333.                 iv = limy/4;
  334.                 ih = iv * aspect_ratio(new_mode)/100;
  335.                 filled_ellipse (ix, iy, ih, iv);
  336.  
  337.                 set_active_page (1);
  338.                 clear ();
  339.                 graphic_text ("Test 9: Graphic pages", 10, limy-30, 14);
  340.                 graphic_text ("Page One", 100, limy-20, 12);
  341.                 graphic_text ("Press 0 to see page zero, <Enter> to continue", 10, limy-10, 14);
  342.                 set_color (1);
  343.                 ix = limx/4;
  344.                 iy = limy/4;
  345.                 jx = 3*ix;
  346.                 jy = 3*iy;
  347.                 filled_rectangle (ix, iy, jx, jy);
  348.  
  349.                 while ( ( k = pause()) != 13 )
  350.                 {
  351.                     set_display_page(k);
  352.                 }
  353.                 set_active_page(0);
  354.                 set_display_page(0);
  355.             }
  356.             else
  357.             {
  358.                 graphic_text("Test 9: Graphic pages",10,limy-30,14);
  359.                 graphic_text("Only one page is available in this mode",10,limy-20,14);
  360.                 graphic_text("Press a key to continue",10,limy-10,14);
  361.                 pause();
  362.             }
  363.  
  364. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  365.  
  366. /*  Test 10: Graphic text I/O                                            */
  367.  
  368.             clear ();
  369.  
  370.             graphic_text ("Test 10: Graphic text", 10, limy-30, 14);
  371.             graphic_text ("Use <Backspace> to fix mistakes", 10, limy-20, 14);
  372.             graphic_text ("Press <Enter> to continue", 10, limy-10, 14);
  373.  
  374.             strcpy (prompt,"Please enter your name:");
  375.             get_string (10,0,prompt,string);
  376.             graphic_text (string,10,10,12);
  377.             pause();
  378.  
  379. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  380.  
  381. /* Test 11: XOR functions                                                */
  382.  
  383.             clear();
  384.  
  385.             graphic_text("Test 11: XOR functions", 10, limy-20, 14);
  386.             graphic_text("Press any key to continue", 10, limy-10, 14);
  387.  
  388.             ix = 0;
  389.             iy = 0;
  390.             jx = limx/2;
  391.             jy = limy/2;
  392.  
  393.             set_color (1);
  394.             filled_rectangle (ix, iy, jx, jy);
  395.  
  396.             pause();
  397.  
  398.             ix = limx/4;
  399.             iy = limy/4;
  400.             jx = 3*ix;
  401.             jy = 3*iy;
  402.  
  403.             set_color (2);
  404.             set_xor (1);
  405.             filled_rectangle (ix, iy, jx, jy);
  406.             set_xor (0);
  407.  
  408.             pause();
  409.  
  410.             ix = 0;
  411.             iy = 0;
  412.  
  413.             set_color (4);
  414.             set_xor (1);
  415.             move (ix, iy);
  416.             draw (jx, jy);
  417.             set_xor (0);
  418.  
  419.             pause();
  420.  
  421.             ix = limx/4 - 40;
  422.             iy = limy/2 - 8;
  423.  
  424.             set_xor (1);
  425.             graphic_text("MicroWay GREX library supports XOR",ix,iy,15);
  426.             set_xor (0);
  427.  
  428.             pause();
  429.  
  430. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  431.  
  432. /* Test 12: Vertical text                                                */
  433.  
  434.             clear();
  435.  
  436.             ix = limx/8;
  437.             iy = 7 * limy/8;
  438.  
  439.             vertical_text ("MicroWay GREX", ix, iy, 12);
  440.             vertical_text ("does vertical text", ix+10, iy, 12);
  441.  
  442.             graphic_text ("Test 12: Vertical text and magnification", 10, limy-20, 14);
  443.             graphic_text ("Press any key to continue", 10, limy-10, 14);
  444.  
  445.             magnify_text (1,1);
  446.             ix = 10;
  447.             iy = limy/4;
  448.             graphic_text ("Normal graphic text",ix,iy,7);
  449.             magnify_text (2,1);
  450.             iy += 20;
  451.             graphic_text ("Double-width graphic text",ix,iy,14);
  452.             graphic_text ("Double-width graphic text",ix+1,iy,14);
  453.             magnify_text (1,2);
  454.             iy += 20;
  455.             graphic_text ("Double-height graphic text",ix,iy,14);
  456.             graphic_text ("Double-height graphic text",ix,iy+1,14);
  457.             magnify_text (2,2);
  458.             iy += 20;
  459.             graphic_text ("Double-size graphic text",ix  ,iy  ,14);
  460.             graphic_text ("Double-size graphic text",ix+1,iy  ,14);
  461.             graphic_text ("Double-size graphic text",ix  ,iy+1,14);
  462.             graphic_text ("Double-size graphic text",ix+1,iy+1,14);
  463.             iy += 20;
  464.             graphic_text ("Double-size graphic text",ix  ,iy  ,14);
  465.  
  466.             magnify_text (1,1);
  467.             ix = 2*limx/3;
  468.             iy = limy-10;
  469.             vertical_text ("Normal vertical text",ix,iy,7);
  470.             magnify_text (2,1);
  471.             ix += 20;
  472.             vertical_text ("Double-width vertical text",ix,iy  ,14);
  473.             vertical_text ("Double-width vertical text",ix,iy+1,14);
  474.             magnify_text (1,2);
  475.             ix += 20;
  476.             vertical_text ("Double-height vertical text",ix  ,iy,14);
  477.             vertical_text ("Double-height vertical text",ix+1,iy,14);
  478.             magnify_text (2,2);
  479.             ix += 20;
  480.             vertical_text ("Double-size vertical text",ix  ,iy  ,14);
  481.             vertical_text ("Double-size vertical text",ix+1,iy  ,14);
  482.             vertical_text ("Double-size vertical text",ix  ,iy+1,14);
  483.             vertical_text ("Double-size vertical text",ix+1,iy+1,14);
  484.             ix += 20;
  485.             vertical_text ("Double-size vertical text",ix  ,iy  ,14);
  486.             magnify_text(1,1);
  487.  
  488.             pause();
  489.  
  490. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  491.  
  492. /* Test 13: dashed lines                                                 */
  493.  
  494.             clear();
  495.  
  496.             graphic_text("Test 13: dashed lines",10,limy-20,14);
  497.             graphic_text("Press any key to begin next test",10,limy-10,14);
  498.  
  499.             ix = 0;
  500.             iy = 0;
  501.  
  502.             for (i=0; i < 16; i++)
  503.             {
  504.                 move (ix,iy);
  505.                 set_color (i+1);
  506.                 set_dash (dash_patterns[i]);
  507.                 jx = limx;
  508.                 jy = i*limy/8;
  509.                 draw (jx,jy);
  510.             }
  511.  
  512.             set_dash (-1);
  513.  
  514.             pause();
  515.             
  516. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  517.  
  518. /* Test 14: define_color                                                 */
  519.  
  520.             clear();
  521.  
  522.             graphic_text("Test 14: define_color function",10,limy-20,14);
  523.            
  524.             graphic_text("Press <Esc> to begin next test",10,limy-10,14);
  525.  
  526.             if (new_mode == 64 || max_color > 15)
  527.             {
  528.                 set_color (0);
  529.                 filled_rectangle (10, limy-10, limx, limy);
  530.                 graphic_text ("Not supported in this mode", 10, limy-10, 14);
  531.                 pause ();
  532.             }
  533.             else
  534.             {
  535.                 ix = limx/4;
  536.                 iy = limy/4;
  537.                 jx = 3 * ix;
  538.                 jy = 3 * iy;
  539.  
  540.                 set_color (1);
  541.                 filled_rectangle (ix, iy, jx, jy);
  542.  
  543.                 iy = jy+3;
  544.                 graphic_text ("Enter new color code: ", ix, iy, 15);
  545.                 key = 0;
  546.                 while (key != 27)
  547.                 {
  548.                     ix = limx/4 + 23 * 8;
  549.                     j = 0;
  550.                     string [0] = 0;
  551.                     new_color = 1;
  552.                     while ( (key = pause()) != 13)
  553.                     {
  554.                         if (key == 27) break;
  555.                         if (key == 8)
  556.                         {
  557.                             if (j > 0)
  558.                             {
  559.                                 ix -= 8;
  560.                                 j--;
  561.                                 set_xor (1);
  562.                                 graphic_text ( & string [j], ix, iy, 12 );
  563.                                 set_xor (0);
  564.                                 string [j] = 0;
  565.                             }
  566.                         }
  567.                                         /* enter only numbers, not letters */
  568.                         if ( key > 47 && key < 58 )
  569.                         {
  570.                             if (j < 64) /* maximum length of string */
  571.                             {
  572.                                 string [j] = key;
  573.                                 string [j+1] = 0;
  574.                                 graphic_text ( & string [j], ix, iy, 12 );
  575.                                 ix += 8;
  576.                                 j++;
  577.                             }
  578.                         }
  579.                     }
  580.                     /* read the number from string using sscanf               */
  581.                     sscanf ( string, "%d", &new_color );
  582.                     define_color (1, new_color);
  583.                     ix = limx/4 + 23 * 8;
  584.                     set_xor (1);
  585.                     graphic_text (string,ix,iy,12);
  586.                     set_xor (0);
  587.                 }
  588.             }
  589.  
  590.  
  591. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  592.  
  593. /* Test 15: set_palette                                                  */
  594.  
  595.             clear ();
  596.  
  597.             if (new_mode == 64 || max_color > 15)
  598.             {
  599.                 graphic_text ("Test 15: set_palette function", 10, limy-30, 14 );
  600.                 graphic_text ("not available in this mode", 10, limy-20, 14 );
  601.                 graphic_text ("Press a key to continue", 10, limy-10, 14 );
  602.                 pause();
  603.             }
  604.             else
  605.             {
  606.                 key = 0;
  607.                 while ( key != 27)
  608.                 {
  609.                     ix = limx/5;        /* draw a bunch of bars of different colors */
  610.                     iy = limy/5;
  611.                     jx = 4 * ix;
  612.                     jy = 4 * iy - 10;
  613.  
  614.                     k = ix;
  615.                     for (i=0; i < max_color+1 ; i++)
  616.                     {
  617.                         set_color ( i );
  618.                         j = k+1;
  619.                         k = j + (jx-ix)/(max_color+1);
  620.                         filled_rectangle ( j, iy, k, jy );
  621.                     }
  622.  
  623.                     ix = 10;                    /* write numbers on the screen edge */
  624.                     for (i=0; i < 17; i++)
  625.                     {
  626.                         pal [i] = 0;
  627.                         iy = 10 * (i+1);
  628.                         sprintf (string,"%2d\0",i);
  629.                         graphic_text (string, ix, iy, 11 );
  630.                     }
  631.  
  632.                     graphic_text ("Test 15: set_palette function", 60, limy-50, 14 );
  633.                     graphic_text ("Select a new color value for each palette register", 60, limy-40, 14 );
  634.                     graphic_text ("use <Backspace> to correct, <Enter> to move to next value.", 60, limy-30, 14 );
  635.                     graphic_text ("The new palette will be set after you complete the list.", 60, limy-20, 14 );
  636.                     graphic_text (">> Press <Esc> to move on to the next test", 60, limy-10, 14 );
  637.  
  638.                     i = 0;          /* i is the palette register number */
  639.                     iy = 10;
  640.                     while ( i < 17)     /* there are 16, and also the overscan */
  641.                     {
  642.                         ix = 35;
  643.                         graphic_text ( "\020", 0, iy, 12 ); /* place arrow */
  644.  
  645.                         j = 0;                  /* j is the digit counter */
  646.                         strcpy (string," ");
  647.                         while ( (key = pause()) != 13)  /* until user hits Enter */
  648.                         {
  649.                             if (key == 27) break;       /* or Escape */
  650.  
  651.                             if (key == 8)       /* on backspace, delete left */
  652.                             {
  653.                                 if (j > 0)   /* if there is a character to delete */
  654.                                 {
  655.                                     ix -= 8;
  656.                                     j--;
  657.                                     set_xor (1);
  658.                                     graphic_text ( & string [j], ix, iy, 12 );
  659.                                     set_xor (0);
  660.                                     string [j] = 0;
  661.                                 }
  662.                             }
  663.                                         /* enter only numbers, not letters */
  664.                             if ( key > 47 && key < 58 )
  665.                             {
  666.                                 if (j < 64) /* maximum length of string */
  667.                                 {
  668.                                     string [j] = key;
  669.                                     string [j+1] = 0;
  670.                                     graphic_text ( & string [j], ix, iy, 12 );
  671.                                     ix += 8;
  672.                                     j++;
  673.                                 }
  674.                             }
  675.                         }
  676.                         if (key == 27) break;
  677.  
  678.                         /* read the number from string using sscanf               */
  679.                         sscanf ( string, "%d", &new_color );
  680.                         pal [i] = new_color;            /* store as character     */
  681.                         iy += 10;                       /* move to next position  */
  682.                         i++;                /* increment palette register counter */
  683.                         set_xor(1);
  684.                         graphic_text ("\020", 0, iy-10, 12 );      /* erase arrow */
  685.                         set_xor(0);
  686.                     }
  687.                     set_palette (pal);  /* after all registers have been entered  */
  688.                     clear ();           /* set palette and clear screen           */
  689.                 }
  690.             }
  691.  
  692. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  693.  
  694. /*  End of tests. Return to text mode.                                   */
  695.  
  696.             text_mode();
  697.         }
  698.     }
  699. }
  700.  
  701. show_video_systems()
  702. {
  703.     int video_system[4];
  704.     int mode;
  705.     int card,crt;
  706.     int new_mode;
  707.     char *number;
  708.     char buffer[8];
  709.  
  710.     mode = video_configuration(&video_system[0]);
  711.  
  712.     printf("\nAvailable video systems:\n");
  713.  
  714.     card = video_system[0];
  715.     crt = video_system[1];
  716.     if (card == 0)
  717.     {
  718.         printf("No video adapter present\n");
  719.         return (0);
  720.     }
  721.     printf("Active: ");
  722.     if (card ==  1) printf("MDA: Monochrome Display Adapter");
  723.     if (card ==  2) printf("CGA: Color Graphics Adapter");
  724.     if (card ==  3) printf("EGA: Enhanced Graphics Adapter");
  725.     if (card ==  4) printf("MCGA: Multi Color Gate Array");
  726.     if (card ==  5) printf("VGA: Video Graphics Array");
  727.     if (card == 64) printf("HGC: Hercules Graphics Card");
  728.  
  729.     if (crt  ==  1) printf(" with MDA-compatible monochrome display\n");
  730.     if (crt  ==  2) printf(" with CGA-compatible color display\n");
  731.     if (crt  ==  3) printf(" with EGA-compatible color display\n");
  732.     if (crt  ==  4) printf(" with PS/2-compatible monochrome display\n");
  733.     if (crt  ==  5) printf(" with PS/2-compatible color display\n");
  734.  
  735.     card = video_system[2];
  736.     crt = video_system[3];
  737.     printf("Inactive: ");
  738.  
  739.     if (card == 0) printf("Not installed\n");
  740.  
  741.     if (card ==  1) printf("MDA: Monochrome Display Adapter");
  742.     if (card ==  2) printf("CGA: Color Graphics Adapter");
  743.     if (card ==  3) printf("EGA: Enhanced Graphics Adapter");
  744.     if (card ==  4) printf("MCGA: Multi Color Gate Array");
  745.     if (card ==  5) printf("VGA: Video Graphics Array");
  746.     if (card == 64) printf("HGC: Hercules Graphics Card");
  747.  
  748.     if (crt  ==  1) printf(" with MDA-compatible monochrome display\n");
  749.     if (crt  ==  2) printf(" with CGA-compatible color display\n");
  750.     if (crt  ==  3) printf(" with EGA-compatible color display\n");
  751.     if (crt  ==  4) printf(" with PS/2-compatible monochrome display\n");
  752.     if (crt  ==  5) printf(" with PS/2-compatible color display\n");
  753.  
  754.     printf ("\nEnter requested video mode (press <Enter> to quit): ");
  755.     number = gets (buffer);
  756.     new_mode = 0;
  757.     sscanf (number,"%d",&new_mode);
  758.     return (new_mode);
  759. }
  760.  
  761. int crawl(x,y)
  762. int *x,*y;
  763. {
  764.     int xmin,ymin,xmax,ymax;
  765.     int k,j,step;
  766.     int ix,iy,jx,jy;
  767.     char cv[16];
  768.     get_clip_limits(&xmin,&ymin,&xmax,&ymax);
  769.     ix = xmax - 98;
  770.     jx = xmax - 2;
  771.     iy = ymax - 10;
  772.     jy = ymax - 2;
  773.     step = 4;
  774.  
  775.     move_cursor(*x,*y);
  776.     j = get_pixel(*x,*y);
  777.     sprintf(cv," %d %d %d",*x,*y,j);
  778.     set_color(0);
  779.     filled_rectangle(ix,iy,jx,jy);
  780.     graphic_text(cv,ix,iy,9);
  781.     k = pause();
  782.  
  783.     while (k < 0)
  784.     {
  785.         k = -k;
  786.         if(k == 83) step = step-1;
  787.         if(k == 82) step = step+1;
  788.         step = max0(step,1);
  789.         step = min0(step,100);
  790.  
  791.         if(k == 71 || k == 72 || k == 73) *y = *y - step;
  792.         if(k == 79 || k == 80 || k == 81) *y = *y + step;
  793.         if(k == 71 || k == 75 || k == 79) *x = *x - step;
  794.         if(k == 73 || k == 77 || k == 81) *x = *x + step;
  795.  
  796.         if(*x < xmin) *x = xmax + *x - xmin + 1;
  797.         if(*y < ymin) *y = ymax + *y - ymin + 1;
  798.         if(*x > xmax) *x = xmax - *x + xmin + 1;
  799.         if(*y > ymax) *y = ymax - *y + ymin + 1;
  800.  
  801.         move_cursor(*x,*y);
  802.         j = get_pixel(*x,*y);
  803.         sprintf(cv," %d %d %d",*x,*y,j);
  804.         set_color(0);
  805.         filled_rectangle(ix,iy,jx,jy);
  806.         graphic_text(cv,ix,iy,9);
  807.         k = pause();
  808.     }
  809.  
  810.     move_cursor(-1,-1);
  811.     set_color(0);
  812.     filled_rectangle(ix,iy,jx,jy);
  813.     return (k);
  814. }
  815.  
  816. get_string (x,y,prompt,string)
  817. int x,y;
  818. char prompt [], string [];
  819. {
  820.  
  821. /*
  822.     Routine to get a string from the user interactively, displaying
  823.     the results on screen, and allowing the user to backspace over
  824.     mistakes.  Return or line feed terminate the procedure.         */
  825.  
  826.     int ix,iy,key,ic,ier;
  827.     int xmin,ymin,xmax,ymax;
  828.     char letter [2];
  829.  
  830.     letter [0] = 0;
  831.     letter [1] = 0;
  832.  
  833.     ix = x;
  834.     iy = y;
  835.     graphic_text(prompt,ix,iy,14);
  836.  
  837.     ix += 8 * (1 + strlen(prompt) );
  838.  
  839.     get_clip_limits (&xmin,&ymin,&xmax,&ymax);
  840.     ix = min0 (ix,xmax);
  841.  
  842.     string [0] = 0;
  843.     ic = 0;
  844.  
  845.     while ( ( (key = pause()) != 13) && (key != 10) )
  846.     {
  847.         if (key > 0)
  848.         {
  849.             if (key == 8)
  850.             {
  851.                 if (ic > 0)
  852.                 {
  853.                     ix -= 8;
  854.                     ic--;
  855.                     letter [0] = string [ic];
  856.                     set_xor (1);
  857.                     graphic_text (letter,ix,iy,10);
  858.                     set_xor (0);
  859.                     string [ic] = 0;
  860.                 }
  861.             }
  862.             if (key != 8)
  863.             {
  864.                 letter [0] = key;
  865.                 graphic_text (letter,ix,iy,10);
  866.                 ix += 8;
  867.                 string [ic] = key;
  868.                 ic++;
  869.                 ic = min0 (ic,63);
  870.                 string [ic] = 0;
  871.             }
  872.         }
  873.     }
  874. }
  875.