home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / SGTOOL12.ARC / EXAMPLES.ARC / VDCDEMO.C < prev    next >
C/C++ Source or Header  |  1993-08-09  |  10KB  |  394 lines

  1. /*
  2. SG C Tools 1.2
  3.  
  4. (C) 1993 Steve Goldsmith
  5. All Rights Reserved
  6.  
  7. VDC Demo shows how to use some of the text and graphics features available
  8. with SG C Tools.
  9.  
  10. Compiled with HI-TECH C 3.09 (CP/M-80).
  11.  
  12. To compile with HI-TECH C and SG C Tools source on same disk use:
  13. C VDCDEMO.C -LC128
  14. */
  15.  
  16. #include <ctype.h>
  17. #include <hitech.h>
  18. #include <conio.h>
  19. #include <vdc.h>
  20.  
  21. /* 64k vdc locations */
  22.  
  23. #define appBitMapMem 0x4000
  24. #define appAttrMem   0x8000
  25.  
  26. /* colors used by this app */
  27.  
  28. #define appDeskCo    vdcAltChrSet+vdcMediumGray
  29. #define appMenuScrCo vdcDarkBlue
  30. #define appMenuTxtCo vdcAltChrSet+vdcLightCyan
  31. #define appMenuWinCo vdcAltChrSet+vdcLightBlue
  32. #define appIDeskCo   vdcAltChrSet+vdcMediumGray
  33. #define appIWinTxtCo vdcAltChrSet
  34. #define appIWinCo    vdcAltChrSet
  35. #define appGrTextCo  (vdcDarkGray << 4) | vdcWhite
  36.  
  37. extern uchar  vdcScrHorz;
  38. extern ushort vdcDispMem;
  39. extern ushort vdcAttrMem;
  40. extern ushort vdcCharMem;
  41. extern ushort vdcCharMemSize;
  42.  
  43. void initbitmap64k(void);
  44. void initbitmap16k(void);
  45. uchar savechrsets(void);
  46. void restorechrsets(void);
  47. void draw16khelp(uchar Rect[]);
  48. void drawmenu(uchar Rect[]);
  49. void colordisp(void);
  50. void graphicsview(void);
  51. void set64kmode(void);
  52. void ilace80x50text(void);
  53. void drawlines(void);
  54. void drawtext(void);
  55. void drawcircles(void);
  56. void drawrect(int Rect[]);
  57. void drawhouse(void);
  58. void drawcolors(void);
  59. void run(void);
  60. void done(void);
  61.  
  62. uchar *appChSetBufPtr; /* char set buffer pointer */
  63. uchar appColors[] =    /* colors for 64k graphics */
  64. {
  65. vdcDarkGray,
  66. vdcDarkBlue,
  67. vdcLightBlue,
  68. vdcLightBlue,
  69. vdcDarkCyan,
  70. vdcDarkCyan,
  71. vdcDarkCyan,
  72. vdcLightCyan,
  73. vdcLightCyan,
  74. vdcLightCyan,
  75. vdcMediumGray,
  76. vdcMediumGray,
  77. vdcWhite,
  78. vdcMediumGray,
  79. vdcMediumGray,
  80. vdcLightCyan,
  81. vdcLightCyan,
  82. vdcLightCyan,
  83. vdcDarkCyan,
  84. vdcDarkCyan,
  85. vdcDarkCyan,
  86. vdcLightBlue,
  87. vdcLightBlue,
  88. vdcDarkBlue,
  89. vdcDarkGray
  90. };
  91.  
  92. uchar appMenuRect[] = {10,1,69,10};  /* menu window location */
  93. uchar app16KRect[]  = {24,13,56,20}; /* 16k help window location */
  94.  
  95. main()
  96. {
  97.   appChSetBufPtr = NULL;
  98.   srand(9);
  99.   savevdc();
  100.   mapvdc();
  101.   run();
  102.   done();
  103. }
  104.  
  105. void initbitmap64k(void)
  106. {
  107.   setcursorvdc(0,0,vdcCurNone);    /* turn cursor off */
  108.   outvdc(vdcFgBgColor,vdcBlack);   /* black screen */
  109.   attrsoffvdc();                   /* disable attrs */
  110.   setbitmapvdc(appBitMapMem,appAttrMem,vdcBlack,vdcBlack); /* black fg bg */
  111.   mapvdc();                        /* set global vdc vars to reflect changes */
  112.   clrattrvdc(vdcBlack);
  113.   clrbitmapvdc(0);                 /* clear bit map */
  114.   attrsonvdc();                    /* enable attrs */
  115. }
  116.  
  117. void initbitmap16k(void)
  118. {
  119.   setcursorvdc(0,0,vdcCurNone);    /* turn cursor off */
  120.   outvdc(vdcFgBgColor,vdcBlack);   /* black screen */
  121.   attrsoffvdc();                   /* disable attrs to work on 16k vdc */
  122.   setbitmapvdc(vdcDispMem,vdcAttrMem,vdcWhite,vdcBlack);
  123.   clrbitmapvdc(0);                 /* clear bit map */
  124. }
  125.  
  126. uchar savechrsets(void)
  127. {
  128.   if(is64kvdc())
  129.     return(1);
  130.   else
  131.   {
  132.     puts("\nSaving character sets to buffer...");
  133.     appChSetBufPtr = memtobufvdc(vdcCharMem,vdcCharMemSize);
  134.     if (appChSetBufPtr != NULL)
  135.       return(1);
  136.     else
  137.       return(0);
  138.   }
  139. }
  140.  
  141. void restorechrsets(void)
  142. {
  143.   if(appChSetBufPtr != NULL)
  144.   {
  145.     outvdc(vdcFgBgColor,vdcBlack); /* set foreground-background to black */
  146.     attrsoffvdc();                 /* disable attrs */
  147.     buftomemvdc(appChSetBufPtr,vdcCharMem,vdcCharMemSize);
  148.   }
  149. }
  150.  
  151. void draw16khelp(uchar Rect[])
  152. {
  153.   winvdc(Rect[0],Rect[1],Rect[2],Rect[3],appMenuWinCo,"16K Help");
  154.   printstrvdc(Rect[0]+2,Rect[1]+2,appMenuTxtCo,"DO NOT select [S] option");
  155.   printstrvdc(Rect[0]+2,Rect[1]+3,appMenuTxtCo,"if your C128 does not have a");
  156.   printstrvdc(Rect[0]+2,Rect[1]+4,appMenuTxtCo,"64K VDC.  If you do have 64K");
  157.   printstrvdc(Rect[0]+2,Rect[1]+5,appMenuTxtCo,"use [S] to get color and text");
  158.   printstrvdc(Rect[0]+2,Rect[1]+6,appMenuTxtCo,"in graphics mode!");
  159. }
  160.  
  161. void drawmenu(uchar Rect[])
  162. {
  163.   outvdc(vdcFgBgColor,appMenuScrCo); /* set new screen color */
  164.   setcursorvdc(0,0,vdcCurNone);     /* turn cursor off */
  165.   clrattrvdc(appDeskCo);            /* draw desk top */
  166.   clrscrvdc(137);
  167.   winvdc(Rect[0],Rect[1],Rect[2],Rect[3],appMenuWinCo,"SG C Tools 1.2 VDC Demo");
  168.   printstrvdc(Rect[0]+2,Rect[1]+2,appMenuTxtCo,"[A]  80 X  50 interlaced text");
  169.   if(is64kvdc())
  170.   {
  171.     printstrvdc(Rect[0]+2,Rect[1]+3,appMenuTxtCo,"[B] 640 X 200 lines,   8 X 8 color and text");
  172.     printstrvdc(Rect[0]+2,Rect[1]+4,appMenuTxtCo,"[C] 640 X 200 circles, 8 X 8 color and text");
  173.     printstrvdc(Rect[0]+2,Rect[1]+5,appMenuTxtCo,"[D] 640 X 200 houses,  8 X 8 color and text");
  174.     printstrvdc(Rect[0]+2,Rect[1]+6,appMenuTxtCo,"[E] 640 X 200 chart    8 X 8 color");
  175.   }
  176.   else
  177.   {
  178.     printstrvdc(Rect[0]+2,Rect[1]+3,appMenuTxtCo,"[B] 640 X 200 lines,   mono");
  179.     printstrvdc(Rect[0]+2,Rect[1]+4,appMenuTxtCo,"[C] 640 X 200 circles, mono");
  180.     printstrvdc(Rect[0]+2,Rect[1]+5,appMenuTxtCo,"[D] 640 X 200 houses,  mono");
  181.     printstrvdc(Rect[0]+2,Rect[3]-2,appMenuTxtCo,"[S] Set 64K mode");
  182.     draw16khelp(app16KRect);
  183.   }
  184.   printstrvdc(Rect[0]+2,Rect[3]-1,appMenuTxtCo,"[X] Exit to CP/M");
  185. }
  186.  
  187. void colordisp(void) /* colors for 64k graphics */
  188. {
  189.   uchar I;
  190.  
  191.   for(I = 0; I <= sizeof(appColors); I++)
  192.     fillattrvdc(0,I,vdcScrHorz,appColors[I]);
  193. }
  194.  
  195. void graphicsview(void) /* view graphics until key pressed */
  196. {
  197.   while (!(kbhit()));
  198.   getch();
  199.   outvdc(vdcFgBgColor,vdcBlack);
  200.   attrsoffvdc();
  201.   restorechrsets();
  202.   restorevdc();
  203.   mapvdc();
  204.   drawmenu(appMenuRect);
  205. }
  206.  
  207. void set64kmode(void)
  208. {
  209.   if(!(is64kvdc()) && appChSetBufPtr != NULL)
  210.   {
  211.     restorevdc();         /* make sure all registers are default value */
  212.     set64kvdc();          /* set 64k mode */
  213.     savevdc();            /* reflect change to reg 28 */
  214.     restorechrsets();     /* restore char sets destroyed by setting 64k mode */
  215.     free(appChSetBufPtr); /* dispose buffer */
  216.     appChSetBufPtr = NULL;
  217.     restorevdc();
  218.     mapvdc();
  219.     drawmenu(appMenuRect);
  220.   }
  221. }
  222.  
  223. void ilace80x50text(void)
  224. {
  225.   uchar I;
  226.  
  227.   setdsppagevdc(vdcDispMem,vdcAttrMem << 1); /* disp and attrs use 8k */
  228.   set80x50textvdc();
  229.   mapvdc();                                  /* map changes */
  230.   clrattrvdc(appIDeskCo);
  231.   clrscrvdc(137);
  232.   winvdc(10,5,69,44,appIWinCo,"Interlace 80 X 50 Mode");
  233.   printstrvdc(11,43,appIWinTxtCo,
  234.   "All functions that operate in 80 X 25 work in 80 X 50 too!");
  235.   for (I = 1; I <= 36; I++)                  /* scroll window */
  236.     scrollupvdc(11,7,68,43);
  237.   while (!(kbhit()));
  238.   getch();
  239.   restorevdc();
  240.   mapvdc();
  241.   drawmenu(appMenuRect);
  242. }
  243.  
  244. void drawlines(void)
  245. {
  246.   int I;
  247.  
  248.   if(is64kvdc())
  249.   {
  250.     initbitmap64k();
  251.     colordisp();
  252.   }
  253.   else
  254.     initbitmap16k();
  255.   for(I = 0; I <= 639; I += 40)
  256.   {
  257.     linevdc(319,0,I,199);
  258.     linevdc(I,0,319,199);
  259.   }
  260.   if(is64kvdc())
  261.     printbmvdc(12,1,appGrTextCo,
  262.     "SG C Tools makes it easy to use text in GRAPHICS mode!");
  263.   graphicsview();
  264. }
  265.  
  266. void drawcircles(void)
  267. {
  268.   int I;
  269.  
  270.   if(is64kvdc())
  271.   {
  272.     initbitmap64k();
  273.     colordisp();
  274.     printbmvdc(27,11,appGrTextCo,"Graphics merge with text!");
  275.   }
  276.   else
  277.     initbitmap16k();
  278.   for(I = 0; I <= 199; I += 32)
  279.   {
  280.     circlevdc(319,99,I);
  281.   }
  282.   if(is64kvdc())
  283.     printbmvdc(28,13,appGrTextCo,"Text overlays graphics!");
  284.   graphicsview();
  285. }
  286.  
  287. void drawrect(int Rect[])
  288. {
  289.   linevdc(Rect[0],Rect[1],Rect[2],Rect[1]);
  290.   linevdc(Rect[0],Rect[3],Rect[2],Rect[3]);
  291.   linevdc(Rect[0],Rect[1],Rect[0],Rect[3]);
  292.   linevdc(Rect[2],Rect[1],Rect[2],Rect[3]);
  293. }
  294.  
  295. void drawhouse(void)
  296. {
  297.   int DX, DY, I, HseRect[4];
  298.  
  299.   HseRect[0] = 0;
  300.   HseRect[1] = 0;
  301.   HseRect[2] = 0;
  302.   HseRect[3] = 0;
  303.   if(is64kvdc())
  304.   {
  305.     initbitmap64k();
  306.     colordisp();
  307.     printbmvdc(28,1,appGrTextCo," Houses under the moon ");
  308.   }
  309.   else
  310.     initbitmap16k();
  311.   for(I = 1; I < 5; I++)
  312.   {
  313.     HseRect[0] = I*110;
  314.     HseRect[1] = I*30;
  315.     HseRect[2] = HseRect[0]+I*15;
  316.     HseRect[3] = HseRect[1]+I*5;
  317.     DX = HseRect[2]-HseRect[0];
  318.     DY = HseRect[3]-HseRect[1];
  319.     drawrect(HseRect);
  320.     linevdc(HseRect[0],HseRect[1],HseRect[0]+(DX >> 1),HseRect[1]-DY);
  321.     linevdc(HseRect[2],HseRect[1],HseRect[0]+(DX >> 1),HseRect[1]-DY);
  322.     linevdc(HseRect[0],HseRect[3],HseRect[0]-DX,HseRect[3]-DY);
  323.     linevdc(HseRect[0]-DX,HseRect[3]-DY,HseRect[0]-DX,HseRect[3]-(DY << 1));
  324.     linevdc(HseRect[0],HseRect[1],HseRect[0]-DX,HseRect[1]-DY);
  325.     linevdc(HseRect[0]-DX,HseRect[1]-DY,HseRect[0]-(DX >> 1),HseRect[1]-(DY << 1));
  326.     linevdc(HseRect[0]+(DX >> 1),HseRect[1]-DY,HseRect[0]-(DX >> 1),HseRect[1]-(DY << 1));
  327.   }
  328.   for(I = 0; I <= 30; I++)
  329.   {
  330.     circlevdc(500,50,I);
  331.   }
  332.   graphicsview();
  333. }
  334.  
  335. void drawcolors(void)
  336. {
  337.   uchar X, Y;
  338.  
  339.   if(is64kvdc())
  340.   {
  341.     initbitmap64k();
  342.     clrattrvdc(vdcBlack);
  343.     printbmvdc(32,2,appGrTextCo,"Bit map colors");
  344.     for (Y = 0; Y < 16; Y++)
  345.       for (X = 0; X < 16; X++)
  346.         printbmvdc(X+31,Y+4,(Y << 4) | X,"*");
  347.     graphicsview();
  348.   }
  349. }
  350.  
  351. void run(void)
  352. {
  353.   char  InKey;
  354.  
  355.   if(savechrsets())     /* check if vdc in 16k mode */
  356.   {
  357.     drawmenu(appMenuRect);
  358.     do
  359.     {
  360.       InKey = toupper(getch());
  361.       switch (InKey)
  362.       {
  363.         case 'A':
  364.           ilace80x50text();
  365.           break;
  366.         case 'B':
  367.           drawlines();
  368.           break;
  369.         case 'C':
  370.           drawcircles();
  371.           break;
  372.         case 'D':
  373.           drawhouse();
  374.           break;
  375.         case 'E':
  376.           drawcolors();
  377.           break;
  378.         case 'S':
  379.           set64kmode();
  380.           break;
  381.       }
  382.     }
  383.     while (InKey != 'X');
  384.   }
  385. }
  386.  
  387. void done(void)
  388. {
  389.   if(appChSetBufPtr != NULL)
  390.     free(appChSetBufPtr);
  391.   restorevdc();     /* restore registers saved by savevdc() */
  392.   putchar(0x1A);    /* adm-3a clear-home cursor */
  393. }
  394.