home *** CD-ROM | disk | FTP | other *** search
- /*
- SG C Tools 1.2
-
- (C) 1993 Steve Goldsmith
- All Rights Reserved
-
- VDC Demo shows how to use some of the text and graphics features available
- with SG C Tools.
-
- Compiled with HI-TECH C 3.09 (CP/M-80).
-
- To compile with HI-TECH C and SG C Tools source on same disk use:
- C VDCDEMO.C -LC128
- */
-
- #include <ctype.h>
- #include <hitech.h>
- #include <conio.h>
- #include <vdc.h>
-
- /* 64k vdc locations */
-
- #define appBitMapMem 0x4000
- #define appAttrMem 0x8000
-
- /* colors used by this app */
-
- #define appDeskCo vdcAltChrSet+vdcMediumGray
- #define appMenuScrCo vdcDarkBlue
- #define appMenuTxtCo vdcAltChrSet+vdcLightCyan
- #define appMenuWinCo vdcAltChrSet+vdcLightBlue
- #define appIDeskCo vdcAltChrSet+vdcMediumGray
- #define appIWinTxtCo vdcAltChrSet
- #define appIWinCo vdcAltChrSet
- #define appGrTextCo (vdcDarkGray << 4) | vdcWhite
-
- extern uchar vdcScrHorz;
- extern ushort vdcDispMem;
- extern ushort vdcAttrMem;
- extern ushort vdcCharMem;
- extern ushort vdcCharMemSize;
-
- void initbitmap64k(void);
- void initbitmap16k(void);
- uchar savechrsets(void);
- void restorechrsets(void);
- void draw16khelp(uchar Rect[]);
- void drawmenu(uchar Rect[]);
- void colordisp(void);
- void graphicsview(void);
- void set64kmode(void);
- void ilace80x50text(void);
- void drawlines(void);
- void drawtext(void);
- void drawcircles(void);
- void drawrect(int Rect[]);
- void drawhouse(void);
- void drawcolors(void);
- void run(void);
- void done(void);
-
- uchar *appChSetBufPtr; /* char set buffer pointer */
- uchar appColors[] = /* colors for 64k graphics */
- {
- vdcDarkGray,
- vdcDarkBlue,
- vdcLightBlue,
- vdcLightBlue,
- vdcDarkCyan,
- vdcDarkCyan,
- vdcDarkCyan,
- vdcLightCyan,
- vdcLightCyan,
- vdcLightCyan,
- vdcMediumGray,
- vdcMediumGray,
- vdcWhite,
- vdcMediumGray,
- vdcMediumGray,
- vdcLightCyan,
- vdcLightCyan,
- vdcLightCyan,
- vdcDarkCyan,
- vdcDarkCyan,
- vdcDarkCyan,
- vdcLightBlue,
- vdcLightBlue,
- vdcDarkBlue,
- vdcDarkGray
- };
-
- uchar appMenuRect[] = {10,1,69,10}; /* menu window location */
- uchar app16KRect[] = {24,13,56,20}; /* 16k help window location */
-
- main()
- {
- appChSetBufPtr = NULL;
- srand(9);
- savevdc();
- mapvdc();
- run();
- done();
- }
-
- void initbitmap64k(void)
- {
- setcursorvdc(0,0,vdcCurNone); /* turn cursor off */
- outvdc(vdcFgBgColor,vdcBlack); /* black screen */
- attrsoffvdc(); /* disable attrs */
- setbitmapvdc(appBitMapMem,appAttrMem,vdcBlack,vdcBlack); /* black fg bg */
- mapvdc(); /* set global vdc vars to reflect changes */
- clrattrvdc(vdcBlack);
- clrbitmapvdc(0); /* clear bit map */
- attrsonvdc(); /* enable attrs */
- }
-
- void initbitmap16k(void)
- {
- setcursorvdc(0,0,vdcCurNone); /* turn cursor off */
- outvdc(vdcFgBgColor,vdcBlack); /* black screen */
- attrsoffvdc(); /* disable attrs to work on 16k vdc */
- setbitmapvdc(vdcDispMem,vdcAttrMem,vdcWhite,vdcBlack);
- clrbitmapvdc(0); /* clear bit map */
- }
-
- uchar savechrsets(void)
- {
- if(is64kvdc())
- return(1);
- else
- {
- puts("\nSaving character sets to buffer...");
- appChSetBufPtr = memtobufvdc(vdcCharMem,vdcCharMemSize);
- if (appChSetBufPtr != NULL)
- return(1);
- else
- return(0);
- }
- }
-
- void restorechrsets(void)
- {
- if(appChSetBufPtr != NULL)
- {
- outvdc(vdcFgBgColor,vdcBlack); /* set foreground-background to black */
- attrsoffvdc(); /* disable attrs */
- buftomemvdc(appChSetBufPtr,vdcCharMem,vdcCharMemSize);
- }
- }
-
- void draw16khelp(uchar Rect[])
- {
- winvdc(Rect[0],Rect[1],Rect[2],Rect[3],appMenuWinCo,"16K Help");
- printstrvdc(Rect[0]+2,Rect[1]+2,appMenuTxtCo,"DO NOT select [S] option");
- printstrvdc(Rect[0]+2,Rect[1]+3,appMenuTxtCo,"if your C128 does not have a");
- printstrvdc(Rect[0]+2,Rect[1]+4,appMenuTxtCo,"64K VDC. If you do have 64K");
- printstrvdc(Rect[0]+2,Rect[1]+5,appMenuTxtCo,"use [S] to get color and text");
- printstrvdc(Rect[0]+2,Rect[1]+6,appMenuTxtCo,"in graphics mode!");
- }
-
- void drawmenu(uchar Rect[])
- {
- outvdc(vdcFgBgColor,appMenuScrCo); /* set new screen color */
- setcursorvdc(0,0,vdcCurNone); /* turn cursor off */
- clrattrvdc(appDeskCo); /* draw desk top */
- clrscrvdc(137);
- winvdc(Rect[0],Rect[1],Rect[2],Rect[3],appMenuWinCo,"SG C Tools 1.2 VDC Demo");
- printstrvdc(Rect[0]+2,Rect[1]+2,appMenuTxtCo,"[A] 80 X 50 interlaced text");
- if(is64kvdc())
- {
- printstrvdc(Rect[0]+2,Rect[1]+3,appMenuTxtCo,"[B] 640 X 200 lines, 8 X 8 color and text");
- printstrvdc(Rect[0]+2,Rect[1]+4,appMenuTxtCo,"[C] 640 X 200 circles, 8 X 8 color and text");
- printstrvdc(Rect[0]+2,Rect[1]+5,appMenuTxtCo,"[D] 640 X 200 houses, 8 X 8 color and text");
- printstrvdc(Rect[0]+2,Rect[1]+6,appMenuTxtCo,"[E] 640 X 200 chart 8 X 8 color");
- }
- else
- {
- printstrvdc(Rect[0]+2,Rect[1]+3,appMenuTxtCo,"[B] 640 X 200 lines, mono");
- printstrvdc(Rect[0]+2,Rect[1]+4,appMenuTxtCo,"[C] 640 X 200 circles, mono");
- printstrvdc(Rect[0]+2,Rect[1]+5,appMenuTxtCo,"[D] 640 X 200 houses, mono");
- printstrvdc(Rect[0]+2,Rect[3]-2,appMenuTxtCo,"[S] Set 64K mode");
- draw16khelp(app16KRect);
- }
- printstrvdc(Rect[0]+2,Rect[3]-1,appMenuTxtCo,"[X] Exit to CP/M");
- }
-
- void colordisp(void) /* colors for 64k graphics */
- {
- uchar I;
-
- for(I = 0; I <= sizeof(appColors); I++)
- fillattrvdc(0,I,vdcScrHorz,appColors[I]);
- }
-
- void graphicsview(void) /* view graphics until key pressed */
- {
- while (!(kbhit()));
- getch();
- outvdc(vdcFgBgColor,vdcBlack);
- attrsoffvdc();
- restorechrsets();
- restorevdc();
- mapvdc();
- drawmenu(appMenuRect);
- }
-
- void set64kmode(void)
- {
- if(!(is64kvdc()) && appChSetBufPtr != NULL)
- {
- restorevdc(); /* make sure all registers are default value */
- set64kvdc(); /* set 64k mode */
- savevdc(); /* reflect change to reg 28 */
- restorechrsets(); /* restore char sets destroyed by setting 64k mode */
- free(appChSetBufPtr); /* dispose buffer */
- appChSetBufPtr = NULL;
- restorevdc();
- mapvdc();
- drawmenu(appMenuRect);
- }
- }
-
- void ilace80x50text(void)
- {
- uchar I;
-
- setdsppagevdc(vdcDispMem,vdcAttrMem << 1); /* disp and attrs use 8k */
- set80x50textvdc();
- mapvdc(); /* map changes */
- clrattrvdc(appIDeskCo);
- clrscrvdc(137);
- winvdc(10,5,69,44,appIWinCo,"Interlace 80 X 50 Mode");
- printstrvdc(11,43,appIWinTxtCo,
- "All functions that operate in 80 X 25 work in 80 X 50 too!");
- for (I = 1; I <= 36; I++) /* scroll window */
- scrollupvdc(11,7,68,43);
- while (!(kbhit()));
- getch();
- restorevdc();
- mapvdc();
- drawmenu(appMenuRect);
- }
-
- void drawlines(void)
- {
- int I;
-
- if(is64kvdc())
- {
- initbitmap64k();
- colordisp();
- }
- else
- initbitmap16k();
- for(I = 0; I <= 639; I += 40)
- {
- linevdc(319,0,I,199);
- linevdc(I,0,319,199);
- }
- if(is64kvdc())
- printbmvdc(12,1,appGrTextCo,
- "SG C Tools makes it easy to use text in GRAPHICS mode!");
- graphicsview();
- }
-
- void drawcircles(void)
- {
- int I;
-
- if(is64kvdc())
- {
- initbitmap64k();
- colordisp();
- printbmvdc(27,11,appGrTextCo,"Graphics merge with text!");
- }
- else
- initbitmap16k();
- for(I = 0; I <= 199; I += 32)
- {
- circlevdc(319,99,I);
- }
- if(is64kvdc())
- printbmvdc(28,13,appGrTextCo,"Text overlays graphics!");
- graphicsview();
- }
-
- void drawrect(int Rect[])
- {
- linevdc(Rect[0],Rect[1],Rect[2],Rect[1]);
- linevdc(Rect[0],Rect[3],Rect[2],Rect[3]);
- linevdc(Rect[0],Rect[1],Rect[0],Rect[3]);
- linevdc(Rect[2],Rect[1],Rect[2],Rect[3]);
- }
-
- void drawhouse(void)
- {
- int DX, DY, I, HseRect[4];
-
- HseRect[0] = 0;
- HseRect[1] = 0;
- HseRect[2] = 0;
- HseRect[3] = 0;
- if(is64kvdc())
- {
- initbitmap64k();
- colordisp();
- printbmvdc(28,1,appGrTextCo," Houses under the moon ");
- }
- else
- initbitmap16k();
- for(I = 1; I < 5; I++)
- {
- HseRect[0] = I*110;
- HseRect[1] = I*30;
- HseRect[2] = HseRect[0]+I*15;
- HseRect[3] = HseRect[1]+I*5;
- DX = HseRect[2]-HseRect[0];
- DY = HseRect[3]-HseRect[1];
- drawrect(HseRect);
- linevdc(HseRect[0],HseRect[1],HseRect[0]+(DX >> 1),HseRect[1]-DY);
- linevdc(HseRect[2],HseRect[1],HseRect[0]+(DX >> 1),HseRect[1]-DY);
- linevdc(HseRect[0],HseRect[3],HseRect[0]-DX,HseRect[3]-DY);
- linevdc(HseRect[0]-DX,HseRect[3]-DY,HseRect[0]-DX,HseRect[3]-(DY << 1));
- linevdc(HseRect[0],HseRect[1],HseRect[0]-DX,HseRect[1]-DY);
- linevdc(HseRect[0]-DX,HseRect[1]-DY,HseRect[0]-(DX >> 1),HseRect[1]-(DY << 1));
- linevdc(HseRect[0]+(DX >> 1),HseRect[1]-DY,HseRect[0]-(DX >> 1),HseRect[1]-(DY << 1));
- }
- for(I = 0; I <= 30; I++)
- {
- circlevdc(500,50,I);
- }
- graphicsview();
- }
-
- void drawcolors(void)
- {
- uchar X, Y;
-
- if(is64kvdc())
- {
- initbitmap64k();
- clrattrvdc(vdcBlack);
- printbmvdc(32,2,appGrTextCo,"Bit map colors");
- for (Y = 0; Y < 16; Y++)
- for (X = 0; X < 16; X++)
- printbmvdc(X+31,Y+4,(Y << 4) | X,"*");
- graphicsview();
- }
- }
-
- void run(void)
- {
- char InKey;
-
- if(savechrsets()) /* check if vdc in 16k mode */
- {
- drawmenu(appMenuRect);
- do
- {
- InKey = toupper(getch());
- switch (InKey)
- {
- case 'A':
- ilace80x50text();
- break;
- case 'B':
- drawlines();
- break;
- case 'C':
- drawcircles();
- break;
- case 'D':
- drawhouse();
- break;
- case 'E':
- drawcolors();
- break;
- case 'S':
- set64kmode();
- break;
- }
- }
- while (InKey != 'X');
- }
- }
-
- void done(void)
- {
- if(appChSetBufPtr != NULL)
- free(appChSetBufPtr);
- restorevdc(); /* restore registers saved by savevdc() */
- putchar(0x1A); /* adm-3a clear-home cursor */
- }
-