home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / CBGRX102 / MODETEST.C < prev    next >
Text File  |  1992-08-12  |  6KB  |  203 lines

  1. /**
  2.  ** MODETEST.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "../include/grx.h"
  25. #include "../include/mousex.h"
  26. #include "../include/grdriver.h"
  27. #include <string.h>
  28. #include <stdlib.h>
  29. #include <ctype.h>
  30. #include <dos.h>
  31.  
  32. #ifdef __TURBOC__
  33. #define ENV_VAR "GRXDRV"
  34. #endif
  35.  
  36. #ifdef __GNUC__
  37. #define ENV_VAR "GO32"
  38. #endif
  39.  
  40. GR_DRIVER_MODE_ENTRY far *ttab,*gtab;
  41. int txt_modes,gra_modes;
  42.  
  43. void list_modes(void)
  44. {
  45.     char buf[20];
  46.     char tentry[100];
  47.     char gentry[100];
  48.     char *env = getenv(ENV_VAR);
  49.     int  mode;
  50.  
  51.     if(env != NULL)
  52.         printf("Value of environment variable \"%s\" is:\n\"%s\"\n\n",ENV_VAR,env);
  53.     printf("%-32s%s\n\n","Available text modes:","Available graphics modes:");
  54.     txt_modes = 0;
  55.     gra_modes = 0;
  56.     while((ttab[txt_modes].width != 0) || (gtab[gra_modes].width != 0)) {
  57.         tentry[0] = '\0';
  58.         gentry[0] = '\0';
  59.         if(ttab[txt_modes].width != 0) {
  60.         mode = ttab[txt_modes].BIOS_mode +
  61.             (ttab[txt_modes].special << 8);
  62.         sprintf(tentry,
  63.             "(t%d%s  %3dx%-2d C:%-2d %s",
  64.             txt_modes+1,
  65.             ((txt_modes < 9) ? ") " : ")"),
  66.             ttab[txt_modes].width,
  67.             ttab[txt_modes].height,
  68.             ttab[txt_modes].number_of_colors,
  69.             ((ttab[txt_modes].BIOS_mode == 0xff) ?
  70.             "Disabled" :
  71.             (sprintf(buf,"BIOS:%03xh",mode),buf)
  72.         ));
  73.         if(ttab[txt_modes].special) strcat(tentry," *");
  74.         txt_modes++;
  75.         }
  76.         if(gtab[gra_modes].width != 0) {
  77.         mode = gtab[gra_modes].BIOS_mode +
  78.             (gtab[gra_modes].special << 8);
  79.         sprintf(gentry,
  80.             "(g%d%s  %4dx%-3d C:%-5u %s",
  81.             gra_modes+1,
  82.             ((gra_modes < 9) ? ") " : ")"),
  83.             gtab[gra_modes].width,
  84.             gtab[gra_modes].height,
  85.             gtab[gra_modes].number_of_colors,
  86.             ((gtab[gra_modes].BIOS_mode == 0xff) ?
  87.             "Disabled" :
  88.             (sprintf(buf,"BIOS:%03xh",mode),buf)
  89.         ));
  90.         if(gtab[gra_modes].special) strcat(gentry," *");
  91.         gra_modes++;
  92.         }
  93.         printf("%-32s%s\n",tentry,gentry);
  94.     }
  95.     printf("\nEnter mode to test or 'Q' to quit: ");
  96.     fflush(stdout);
  97. }
  98.  
  99. void test_textmode(int mode)
  100. {
  101.     int ii;
  102.  
  103.     if(mode < 0) return;
  104.     if(mode >= txt_modes) return;
  105.     if(ttab[mode].BIOS_mode == 0xff) return;
  106.     GrSetMode(GR_width_height_text,ttab[mode].width,ttab[mode].height);
  107.     do {
  108.         printf("\n\nThis is a text mode of width=%d by height=%d\n",
  109.         ttab[mode].width,
  110.         ttab[mode].height
  111.         );
  112.         for(ii = 4; ii < 512; ii += 4) printf("%4d",ii);
  113.         printf("\nPress any key to abort this test...");
  114.         fflush(stdout);
  115. #ifdef __TURBOC__
  116.         delay(2000);
  117. #endif
  118. #ifdef __GNUC__
  119.         sleep(2);
  120. #endif
  121.     } while(!kbhit());
  122.     getkey();
  123. }
  124.  
  125. #define XP(x)    (int)((((long)(x) * (long)xsize) / 100L) + xpos)
  126. #define YP(y)    (int)((((long)(y) * (long)ysize) / 100L) + ypos)
  127.  
  128. void drawing(int xpos,int ypos,int xsize,int ysize,int fg,int bg)
  129. {
  130.     int ii;
  131.  
  132.     if(bg != GrNOCOLOR) {
  133.         GrFilledBox(xpos,ypos,xpos+xsize-1,ypos+ysize-1,bg);
  134.     }
  135.     GrLine(XP(10),YP(10),XP(40),YP(40),fg);
  136.     GrLine(XP(40),YP(10),XP(10),YP(40),fg);
  137.     GrLine(XP(35),YP(10),XP(65),YP(40),fg);
  138.     GrLine(XP(35),YP(40),XP(65),YP(10),fg);
  139.     GrLine(XP(70),YP(10),XP(90),YP(40),fg);
  140.     GrLine(XP(70),YP(40),XP(90),YP(10),fg);
  141.     for(ii = 0; ii < 5; ii++) {
  142.         GrBox(XP(70+2*ii),YP(10+3*ii),XP(90-2*ii),YP(40-3*ii),fg);
  143.     }
  144.     GrFilledBox(XP(10),YP(50),XP(60),YP(90),fg);
  145.     GrBox(XP(70),YP(50),XP(90),YP(90),fg);
  146.     for(ii = 0; ii < 100; ii++) {
  147.         GrPlot(XP((random() % 20) + 70),YP((random() % 40) + 50),fg);
  148.     }
  149. }
  150.  
  151. void test_graphicsmode(int mode)
  152. {
  153.     char buf[100];
  154.  
  155.     if(mode < 0) return;
  156.     if(mode >= gra_modes) return;
  157.     if(gtab[mode].BIOS_mode == 0xff) return;
  158.     GrSetMode(GR_width_height_color_graphics,
  159.         gtab[mode].width,
  160.         gtab[mode].height,
  161.         gtab[mode].number_of_colors
  162.     );
  163.     sprintf(buf,
  164.         "%dx%d graphics with %d colors",
  165.         GrSizeX(),
  166.         GrSizeY(),
  167.         GrNumColors()
  168.     );
  169.     GrClearScreen(GrBlack());
  170.     drawing(0,0,GrSizeX(),GrSizeY()-35,GrWhite(),GrNOCOLOR);
  171.     GrTextXY(0,GrSizeY()-32,buf,GrWhite(),GrNOCOLOR);
  172.     GrTextXY(0,GrSizeY()-16,"Press any key to continue...",GrWhite(),GrNOCOLOR);
  173.     getkey();
  174. }
  175.  
  176. void main(void)
  177. {
  178.     char reply[80];
  179.  
  180.     GrSetMode(GR_80_25_text);
  181.     GrGetDriverModes(&ttab,>ab);
  182.     if(!ttab || !gtab) {
  183.         printf("MODETEST will work only with a new format driver\n");
  184.         exit(0);
  185.     }
  186.     for( ; ; ) {
  187.         GrSetMode(GR_80_25_text);
  188.         list_modes();
  189.         gets(reply);
  190.         switch(tolower(reply[0])) {
  191.           case 't':
  192.         test_textmode(atoi(&reply[1]) - 1);
  193.         break;
  194.           case 'g':
  195.         test_graphicsmode(atoi(&reply[1]) - 1);
  196.         break;
  197.           case 'q':
  198.         exit(0);
  199.         }
  200.     }
  201. }
  202.  
  203.