home *** CD-ROM | disk | FTP | other *** search
/ Boston 2 / boston-2.iso / DOS / PROGRAM / C / ANSI_C / ANSIDEMO.C next >
Text File  |  1993-12-01  |  21KB  |  477 lines

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