home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 201_01 / ansidemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-01  |  20.6 KB  |  469 lines

  1. /** ANSIDEMO.c
  2. *
  3. *   ANSIDEMO.C
  4. *   (C) Copyright 1985 Don F. Ridgway
  5. *   All Rights Reserved.
  6. *   This program may be copied for
  7. *   personal, non-profit use only.
  8. *
  9. *   Don F. Ridgway
  10. *   Owner & Chief Programmer/Analyst
  11. *   A-1 IBM Programming & Training Service
  12. *   Custom Business Programs
  13. *   119 Plantation Court, Suite D
  14. *   Temple Terrace, FL  33617-3731
  15. *   Ph: (813) 985-3342  (10:00am - 2:00pm EST)
  16. *
  17. *   Written, compiled and tested in Microsoft C,
  18. *   ver. 2.03, and Lattice C, ver. 2.15, under
  19. *   PC-DOS 2.1 on a Compaq w/640Kb RAM & 8087
  20. *   using the PC-DOS 3.0 LINK and the TURBO
  21. *   Pascal 3.0 screen editor.
  22. *
  23. *   (470 lines of code.)
  24. *
  25. *   This program demonstrates the features and
  26. *   capabilities of my C programming language
  27. *   header/module file named "ANSISYS.c", which
  28. *   activates and implements the MS/PC-DOS
  29. *   "ANSI.SYS" device driver for extended screen
  30. *   and keyboard functions and control sequences.
  31. *
  32. *   NOTICE:  To run this program you MUST have booted
  33. *   up with the DOS "ANSI.SYS" file on your boot disk
  34. *   with a "CONFIG.SYS" file containing the statement
  35. *   "device = ansi.sys" on your boot disk.  (Other-
  36. *   wise you'll get meaningless numbers and symbols
  37. *   across your screen.  If so, hit F10 or '0' to exit,
  38. *   then boot up properly.  See the introduction to
  39. *   ANSISYS.C for instructions on how to make the
  40. *   CONFIG.SYS file.)
  41. *
  42. *   The "ANSISYS.c" file is to be #included in
  43. *   your C programs to give them "smart" cursor
  44. *   control and eye-catching "turtlegraphics"-type
  45. *   screen/graphics display capability.
  46. *
  47. **/
  48.  
  49. #include <stdio.h>
  50. #include "ansisys.c"                   /* this is the file to #include in all   */
  51.                                        /* your C programs from now on to enable */
  52. main()                                 /* all of the following fabulous screen, */
  53.    {                                   /* cursor and keyboard features          */
  54.    int dd,key1;
  55.    dd=0;
  56.    while (key1 != 196 && key1 != 48)   /* while key1 not equal to F10 or '0' */
  57.       {                                /*            show main menu          */
  58.       if (dd==0)
  59.          mainmenu();
  60.       XKPROMPT(20,29,key1);
  61.       dd=0;
  62.       switch(key1)
  63.          {
  64.          case 187:                     /* F1 key -- Set Screen & Graphics    */
  65.          case 49:                      /* '1' key -- just in case some jelly */
  66.                                        /*       spilled on the Function keys */
  67.                   shoscreen();
  68.                   break;
  69.          case 188:                     /* F2 key -- Set Display & Color */
  70.          case 50:                      /* '2' key */
  71.                   shodisplay();
  72.                   break;
  73.          case 189:                     /* F3 key -- Extended Keyboard demo */
  74.          case 51:                      /* '3' key */
  75.                   xkeyboard();
  76.                   break;
  77.          case 190:                     /* F4 key -- Arrow Keys demo */
  78.          case 52:                      /* '4' key */
  79.                   cursarrow();
  80.                   break;
  81.          case 191:                     /* F5 key -- DRAW function demo */
  82.          case 53:                      /* '5' key */
  83.                   showdraw();
  84.                   break;
  85.          case 192:                     /* F6 key -- FILL function demo */
  86.          case 54:                      /* '6' key */
  87.                   showfill();
  88.                   break;
  89.          case 193:                     /* F7 key -- WINDOW function demo */
  90.          case 55:                      /* '7' key */
  91.                   showindow();
  92.                   break;
  93.          case 196:                     /* F10 key -- to exit program */
  94.          case 48:                      /* '0' key */
  95.                   break;
  96.          default:
  97.                   dd=1;                /* any other key loops back around */
  98.                   break;
  99.          }                             /* end switch */
  100.       }                                /* end while */
  101.  
  102.    XYPRINTF(23,1,"Goom\nbye!");
  103.    BEEP;
  104.    exit(0);
  105.    }                                   /* end main ANSIDEMO.c */
  106.  
  107. /*
  108. * ------------------------------------------------------------------------
  109. */
  110.  
  111. mainmenu()                             /* draw Main Menu */
  112.    {
  113.    CLS;                                /* clear screen */
  114.    DRAW(3,19,23,61,213);               /* draw distinctive one/two line border */
  115.    HLON;                               /* turn high-intensity display on */
  116.    DRAW(4,21,22,59,178);               /* draw artistic inside border to offset */
  117.    XYPRINTF(2,31,"A N S I D E M O . c");
  118.    XYPRINTF(24,29,"(c) 1985 Don F. Ridgway");
  119.    HLOFF;                              /* turn high-intensity off */
  120.    XYPRINTF(6,28,"F1)  Set Screen/Graphics");
  121.    XYPRINTF(8,28,"F2)  Set Display/Color");
  122.    XYPRINTF(10,28,"F3)  Extended Keyboard Keys");
  123.    XYPRINTF(12,28,"F4)  Cursor Arrow Keys");
  124.    XYPRINTF(14,28,"F5)  DRAW Border,Line,Point");
  125.    XYPRINTF(16,28,"F6)  FILL macro/function");
  126.    XYPRINTF(18,28,"F7)  WINDOW macro/function");
  127.    XYPRINTF(20,28,"   <---- (F10 to Exit)");
  128.    return(0);
  129.    }                                   /* return to main program */
  130.  
  131. /*
  132. * ------------------------------------------------------------------------
  133. */
  134.  
  135. shoscreen()                                      /* Set Screen Graphics demo */
  136.    {
  137.    int c;
  138.  
  139.    CLS;                                          /* clear screen */
  140.    while (c!=9)                                  /* while not number 9 */
  141.       {
  142.       DRAW(1,1,1,80,178);
  143.       XCTRPRINTF(5,"This is Set Screen - Set Graphics Demo");
  144.       XCTRPRINTF(7,"0=40x25 monochrome,1=40x25 color, 2=80x25 mono,  3=80x25 color,    ");
  145.       XCTRPRINTF(9,"4=320x200 color,   5=320x200 mono,6=640x200 mono,7=enable word-wrap");
  146.       c=' ';
  147.       XYPRINTF(12,5,"Enter # of Graphics Mode desired  ( 9 => Exit) : ");
  148.       scanf("%d",&c);
  149.       if (c==9) break;                           /* if 9 break out of loop */
  150.       SETSCREEN(c);
  151.       XYPRINTF(15,1,"ABCDEFGHIJKLabcdefghijkl");
  152.       XCTRPRINTF(18,"1234567890");
  153.       }
  154.  
  155.    return(0);
  156.    }                                             /* return to main menu */
  157.  
  158. /*
  159. * ------------------------------------------------------------------------
  160. */
  161.  
  162. shodisplay()                           /* Set Display/Color attributes demo */
  163.    {
  164.    int c,d,e;
  165.  
  166.    CLS;
  167.    while (c!=9)                                  /* while not number 9 */
  168.       {
  169.       DRAW(1,1,1,80,178);
  170.       XCTRPRINTF(3,"This is Set Display/Color Attributes Demo");
  171.       XCTRPRINTF(5,"Set screen display attributes and colors:");
  172. XYPRINTF(7,1," 0 = default,           1 = high-intensity, 4 = underline,");
  173. XYPRINTF(8,1," 5 = blink,             7 = inverse,        8 = invisible (black-on-black),");
  174. XYPRINTF(10,1,"30 = FOREGROUND black, 31 = fore red,      32 = fore green, 33 = fore yellow,");
  175. XYPRINTF(11,1,"34 = fore blue,        35 = fore magenta,  36 = fore cyan,  37 = fore white, ");
  176. XYPRINTF(13,1,"40 = BACKGROUND black, 41 = back red,      42 = back green, 43 = back yellow,");
  177. XYPRINTF(14,1,"44 = back blue,        45 = back magenta,  46 = back white.");
  178.       c=d=e=' ';
  179.       XYPRINTF(16,1,"Enter three numbers, seperated by SPACES of Display/Color desired");
  180.       XYPRINTF(17,1,"putting numbers in right-hand columns first, e.g., 0 0 5 is BLINK");
  181.       XYPRINTF(18,1,"(A '9'in any column will Exit)  '0 0 0' resets to normal  ");
  182.       XY(18,58);
  183.       scanf("%d %d %d",&c,&d,&e);                /* careful! no error-trapping here! */
  184.       if (c==9||d==9||e==9) break;               /* if any number 9, break out */
  185.       SETDISPLAY(c,d,e);
  186.       DRAW(18,58,18,80,255);
  187.       XCTRPRINTF(20,"Is this what you wanted?");
  188.       }
  189.  
  190.    return(0);
  191.    }                                             /* return to main menu */
  192.  
  193. /*
  194. * ------------------------------------------------------------------------
  195. */
  196.  
  197. xkeyboard()                                      /* Extended Keyboard demo */
  198.    {
  199.    int c;
  200.  
  201.    CLS;
  202.    HLON;
  203.    DRAW(1,1,1,80,178);
  204.    HLOFF;
  205.    printf("\nHello there, This is Extended Keyboard Demo ('*'= Exit )\n\n\n");
  206.  
  207.    while (c!='*')                                /* while not '*' */
  208.       {
  209.       printf("\n ----> Press ANY key on the keyboard: ");
  210.       XKREAD(c);                                 /* no-echo read */
  211.       printf("  The extended-keyboard-read code =  %d",c);
  212.       }
  213.  
  214.    return(0);
  215.    }                                             /* return to main menu */
  216.  
  217. /*
  218. * ------------------------------------------------------------------------
  219. */
  220.  
  221. cursarrow()                            /* Display use of cursor arrow keys */
  222.    {
  223.    int key;
  224.  
  225.    CLS;                                /* clear screen */
  226.    HLON;
  227.    DRAW(1,1,1,80,178);
  228.    HLOFF;
  229.    XCTRPRINTF(3,"Move cursor with ARROW keys, HOME and END  ('*'= Exit )");
  230.    XY(12,40);
  231.    SAVCURS;                            /* save cursor position (12,40) for later */
  232.  
  233.    while (key != '*')                  /* while not '*' */
  234.       {
  235.       XKREAD(key);                     /* read keystroke, no echo */
  236.  
  237.       switch(key)
  238.          {
  239.          case 199:                     /* HOME key */
  240.                   XY(1,1);
  241.                   break;
  242.          case 200:                     /* UP arrow key */
  243.                   printf("\033[1A\b"); /* --> NOTE: When utilizing these macros     */
  244.                /* CURSUP(1); */        /* from the actual keyboard, as we are doing */
  245.                                        /* in this demo, they need a '\b' backspace  */
  246.                   break;               /* because hitting the key moves it forward  */
  247.          case 203:                     /* LEFT arrow key */
  248.                   CURSBCK(2);          /* NOTE the (2) per above reason (need two  */
  249.                   break;               /* spaces back to overcome the one forward) */
  250.          case 205:                     /* RIGHT arrow */
  251.                /* CURSFWD(1);*/        /* NOTE letting it move forward by itself */
  252.                   break;               /* because of the physical keystroke      */
  253.          case 207:                     /* END (of screen) key */
  254.                   XY(24,79);
  255.                   break;
  256.          case 208:
  257.                   printf("\033[1B\b"); /* DOWN key */
  258.                /* CURSDWN(1);*/        /* see NOTE on UP arrow key */
  259.                   break;
  260.          case 42:                      /* hit '*' to quit program */
  261.                   break;
  262.          default:                      /* Any other key, while not doing any- */
  263.                   CURSBCK(1);          /* thing, nevertheless needs to be moved */
  264.                   break;               /* back where it was.  See NOTE UP arrow */
  265.          }                             /* end switch */
  266.       }                                /* end while */
  267.       RECALLCURS;                      /* recall cursor (to 12,40) */
  268.       puts("Press any key to return to Main Menu");   /* then print message */
  269.       XKREAD(key);
  270.       CLS;
  271.       return(0);
  272.    }                                   /* end cursarrow demo */
  273.  
  274. /*
  275. * ------------------------------------------------------------------------
  276. */
  277.  
  278. showdraw()                             /* DRAW(row1,col1,row2,col2,icon) demo */
  279.    {
  280.    int a,b,c,d,e,key;
  281.    char *greet;
  282.    greet="Hi there -- I'm Fast-draw Demo!";
  283.  
  284.    CLS;
  285.    XCTRPRINTF(2,"Demo of DRAW(row1,col1,row2,col2,icon)");
  286.    DRAW(5,9,20,71,205);                          /* little demo display */
  287.    DRAW(6,11,19,69,176);
  288.    DRAW(7,12,18,68,177);
  289.    DRAW(8,13,17,67,178);
  290.    DRAW(9,14,16,66,219);
  291.    DRAW(11,20,14,60,196);
  292.    HLON;
  293.    XCTRPRINTF(12,greet);
  294.    DRAW(21,3,21,77,207);
  295.    DRAW(22,3,22,77,178);
  296.    DRAW(8,4,8,4,14);
  297.    DRAW(16,4,16,4,2);
  298.    DRAW(8,76,16,76,219);
  299.    DRAW(8,75,16,75,182);
  300.    HLOFF;
  301.    CURSPOSPRTF(24,46,"Press any key to continue ");
  302.    XKREAD(key);
  303.    key=99;
  304.    CLS;
  305.    while (key!=81&&key!=113)     /* while not Capital Q or lower case q q)uit */
  306.                                  /* NOTE: The possibility of upper or lower case data */
  307.                                  /* entry is handled throughout in this fashion so    */
  308.                                  /* this program could more "stand on its own" and    */
  309.                                  /* not require the islower() or toupper() functions  */
  310.                                  /* to be #included from ctype.h header file          */
  311.       {
  312.       if (key==99||key==67)                      /* if C)learscreen */
  313.          {
  314.          XCTRPRINTF(1,"Demonstration of DRAW(row1,col1,row2,col2,icon)");
  315.          SETDISPLAY(0,0,1);                      /* high intensity */
  316.          DRAW(3,1,3,80,196);                     /* border line    */
  317.          SETDISPLAY(0,0,0);
  318.       CURSPOSPRTF(2,3,"-> Enter row1,col1,row2,col2,icon, SPACES delimiting: ");
  319.  XCTRPRINTF(4,"Try: 10 25 15 55 205, 5 9 20 71 178, 13 1 13 80 219, 9 24 16 56 213");
  320.          };
  321.       key=a=b=c=d=e=0;                           /* initialize         */
  322.       CURSPOSPRTF(2,59,".. .. .. .. ...");       /* little input guide -- don't have  */
  323.       CURSPOS(2,59);                             /* to follow exactly but just space  */
  324.       scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);    /* between entries and hit carriage  */
  325.                                                  /* return at end.  If goof, do ^C    */
  326.                                                  /* to start all over again. [solly]  */
  327.       DRAW(a,b,c,d,e);                           /* Careful! No input error-checking  */
  328.       CURSPOSPRTF(24,46,"A)nother E)raselast C)LS Q)uit?");
  329.       SETDISPLAY(0,0,5);
  330.       CPR(24,46,65);                             /* blink the   */
  331.       CPR(24,55,69);                             /* A,E,C and Q */
  332.       CPR(24,66,67);
  333.       CPR(24,71,81);
  334.       CURSPOS(24,79);
  335.       SETDISPLAY(0,0,0);
  336.       XKREADE(key);                              /* extended keyboard read */
  337.       if (key==97||key==65)                      /* do A)nother */
  338.          DRAW(24,46,24,80,255);
  339.       else if (key==99||key==67)                 /* C)learScreen,restart */
  340.          CLS;
  341.       else if (key==101||key==69)                /* E)rase last figure */
  342.          {
  343.          DRAW(a,b,c,d,255);                      /* redraw with blanks */
  344.          DRAW(24,46,24,80,255);
  345.          }                                       /* Q)uit falls through */
  346.       }                                          /* end while           */
  347.    CLS;
  348.    return(0);
  349.    }                                             /* end of Showdraw Demo */
  350.  
  351. /*
  352. * ------------------------------------------------------------------------
  353. */
  354.  
  355. showfill()                             /* Demo of FILL(row1,col1,row2,col2,fill) */
  356.    {
  357.    int a,b,c,d,e,key;
  358.    CLS;
  359.    XCTRPRINTF(2,"Demo of FILL(row1,col1,row2,col2,fill)");
  360.    FILL(10,25,15,55,219);                        /* little razzledazzle */
  361.    FILL(5,9,20,71,197);
  362.    FILL(4,40,24,40,221);
  363.    FILL(5,41,20,71,255);
  364.    FILL(10,45,15,75,219);
  365.    CURSPOSPRTF(24,46,"Press any key to continue ");
  366.    XKREAD(key);
  367.    key=99;
  368.    CLS;
  369.    while (key!=81&&key!=113)                     /* while not Q)uit */
  370.       {
  371.       if (key==99||key==67)                      /* if C)learscreen */
  372.          {
  373.          XCTRPRINTF(1,"Demonstration of FILL(row1,col1,row2,col2,fill)");
  374.          SETDISPLAY(0,0,1);                      /* high intensity */
  375.          DRAW(3,1,3,80,196);                     /* border line    */
  376.          SETDISPLAY(0,0,0);
  377.       CURSPOSPRTF(2,3,"-> Enter row1,col1,row2,col2,fill, SPACES delimiting: ");
  378. XCTRPRINTF(4,"Try: 10 25 15 55 219, 5 9 20 71 197, 4 40 24 40 221, 9 24 16 56 178");
  379.          };
  380.       key=a=b=c=d=e=0;                           /* initialize         */
  381.       CURSPOSPRTF(2,59,".. .. .. .. ...");       /* little input guide */
  382.       CURSPOS(2,59);
  383.       scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
  384.       FILL(a,b,c,d,e);                           /* careful! -- no input */
  385.                                                  /* error-checking here! */
  386.       CURSPOSPRTF(24,46,"A)nother E)raselast C)LS Q)uit?");
  387.       SETDISPLAY(0,0,5);
  388.       CPR(24,46,65);                             /* blink the   */
  389.       CPR(24,55,69);                             /* A,E,C and Q */
  390.       CPR(24,66,67);
  391.       CPR(24,71,81);
  392.       CURSPOS(24,79);
  393.       SETDISPLAY(0,0,0);
  394.       XKREADE(key);                              /* extended keyboard read */
  395.       if (key==97||key==65)                      /* do A)nother */
  396.          XYEOL(24,46);
  397.       else if (key==99||key==67)                 /* C)learScreen,restart */
  398.          CLS;
  399.       else if (key==101||key==69)                /* E)rase last figure */
  400.          {
  401.          FILL(a,b,c,d,255);                      /* refill with blanks */
  402.          XYEOL(24,46);
  403.          }                                       /* Q)uit falls through */
  404.       }                                          /* end while           */
  405.    CLS;
  406.    return(0);
  407.    }                                             /* end of Showfill Demo */
  408.  
  409. /*
  410. * ------------------------------------------------------------------------
  411. */
  412.  
  413. showindow()                            /* WINDOW(row1,col1,row2,col2,fill,bord) demo */
  414.    {
  415.    int a,b,c,d,e,f,key;
  416.    CLS;                                          /* clearscreen       */
  417.    XCTRPRINTF(2,"Demo of WINDOW(row1,col1,row2,col2,fill,bord)");
  418.    WINDOW(10,25,15,55,219,205);                  /* ----------------- */
  419.    WINDOW(8,23,19,59,178,213);                   /*   if you got it   */
  420.    WINDOW(5,65,10,75,219,196);                   /*   -------------   */
  421.    WINDOW(15,5,20,15,254,205);                   /*     flaunt it!    */
  422.    WINDOW(5,1,7,63,14,219);                      /* ----------------- */
  423.    WINDOW(15,70,15,70,7,2);
  424.    CURSPOSPRTF(24,46,"Press any key to continue ");
  425.    XKREAD(key);
  426.    key=99;
  427.    CLS;
  428.    while (key!=81&&key!=113)                     /* while not Q)uit do  */
  429.       {                                          /* note upper/lowercase */
  430.       if (key==99||key==67)                      /* if screen's cleared */
  431.          {                                       /* redraw header-menu  */
  432.       XCTRPRINTF(1,"Demonstration of WINDOW(row1,col1,row2,col2,fill,bord)");
  433.          SETDISPLAY(0,0,1);                      /* set high intensity  */
  434.          DRAW(3,1,3,80,196);                     /* border line         */
  435.          SETDISPLAY(0,0,0);                      /* set display normal  */
  436.       CURSPOSPRTF(2,1,"-> Enter coordinates & fill & border with SPACE delimit: ");
  437. XCTRPRINTF(4,"Try: 10 25 15 55 219 205, 5 65 10 75 219 196, 9 24 16 56 219 213");
  438.          };
  439.       key=a=b=c=d=e=f=0;                         /* initialize          */
  440.       CURSPOSPRTF(2,59,".. .. .. .. ... ...");   /* little input guide  */
  441.       CURSPOS(2,59);                             /* position cursor     */
  442.       scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f); /* BE CAREFUL!!! -- no  */
  443.       WINDOW(a,b,c,d,e,f);                          /* error-checking here! */
  444.       CURSPOSPRTF(24,46,"A)nother E)raselast C)LS Q)uit?");
  445.       SETDISPLAY(0,0,5);                         /* set display to blink */
  446.       CPR(24,46,65);                             /* print/blink the 'A' */
  447.       CPR(24,55,69);                             /* blink 'E'           */
  448.       CPR(24,66,67);                             /* blink 'C'           */
  449.       CPR(24,71,81);                             /* blink 'Q'           */
  450.       CURSPOS(24,79);                            /* position cursor     */
  451.       SETDISPLAY(0,0,0);                         /* set display normal  */
  452.       XKREADE(key);                              /* extended keyboard read */
  453.       if (key==97||key==65)                      /* do A)nother         */
  454.          XYEOL(24,46);                           /* erase line 24 menu  */
  455.       else if (key==101||key==69)                /* E)rase last figure  */
  456.          {
  457.          FILL(a,b,c,d,255);                      /* refill with blanks  */
  458.          DRAW(24,46,24,80,255);                  /* erase line 24 menu  */
  459.          }
  460.       else if (key==99||key==67)                 /* C)learscreen,restart */
  461.          CLS;                                    /* Q)uit falls through */
  462.       }                                          /* end while           */
  463.    CLS;                                          /* clear screen so image */
  464.    return(0);                                    /* ends with program   */
  465.    }                                             /* end of WINDOW Demo */
  466.  
  467. /*
  468. ***  the end of ANSIDEMO.c  --  hope you liked it! --  C you again sometime?  ***
  469. */