home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 1 / FREEWARE.BIN / gunix / cscc.c < prev    next >
C/C++ Source or Header  |  1989-10-17  |  3KB  |  140 lines

  1. /* 
  2.  *    cscc.c ------ Change Screen Color for the Console Environment. 
  3.  * 
  4.  *        Written by Masaya  Oct/2/89 
  5.  * 
  6.  */ 
  7.  
  8. #include <stdio.h>
  9. #include <dos.h>
  10. #include <ctype.h>
  11.  
  12. #define P_ADDR        0x0fd90
  13. #define P_BLUE        0x0fd92
  14. #define P_RED         0x0fd94
  15. #define P_GREEN        0x0fd96
  16.  
  17. #define    BACKGROUND    0     /* background color */
  18. #define    FORGROUND    1     /* forground color */
  19. #define    OUTLINE        2     /* boader color */
  20. #define    NOTICE        3     /* notice color */
  21. #define    DEBUGMSG     5    /* debug message color */
  22.  
  23. static    int    ptbl[5][6]={ 
  24.     {0,   2,  EOF, EOF, EOF, EOF},     /* Background */
  25.     {1,   3,  EOF, EOF, EOF, EOF},     /* Forground */
  26.     {4,   5,    6, EOF, EOF, EOF},     /* Boarder */
  27.     {8,  10,   12,  14, EOF, EOF},     /* Notice */
  28.     {7,   9,   11,  13,  15, EOF}     /* Debug Message */
  29. }; 
  30.  
  31. usage() 
  32.     printf("Color.0 : Background     (Gray)\n"); 
  33.     printf("Color.1 : Forground      (White)\n"); 
  34.     printf("Color.2 : Outline Boader (Yellow)\n"); 
  35.     printf("Color.3 : Notice         (Red)\n"); 
  36.     printf("Color.4 : Debug Message  (Black)\n"); 
  37.     printf("Blue Red Green           ( 0 - 255)\n"); 
  38.  
  39. set_color_value( plane, ac, av ) 
  40. char    **av; 
  41.     int    b, r, g, color, i;
  42.  
  43.     sscanf( av[ac+1], "%d", &b); 
  44.     sscanf( av[ac+2], "%d", &r); 
  45.     sscanf( av[ac+3], "%d", &g); 
  46.  
  47.     for( i=0; i<5; i++ ){ 
  48.         if ( ptbl[plane][i] == EOF ) 
  49.             break; 
  50.         color = ptbl[plane][i]; 
  51.         outp(P_ADDR,(char)color);
  52.         outp(P_BLUE, (char)b);
  53.         outp(P_RED, (char)r);
  54.         outp(P_GREEN, (char)g);
  55.     } 
  56.  
  57. main( ac, av )
  58. char    **av; 
  59. {
  60.     int    plane=EOF, b, r, g, i, color, c;
  61.  
  62.     for ( i=1; i<ac; i++ ){
  63.         if ( av[i][0] == '-' ){ 
  64.             c = tolower( av[i][1] ); 
  65.             switch( c ){ 
  66.             case 'b': 
  67.             case '0': 
  68.                 plane = BACKGROUND; 
  69.                 set_color_value( plane, i, av ); 
  70.                 i+=3; 
  71.                 break; 
  72.             case 'f': 
  73.             case '1': 
  74.                 plane = FORGROUND; 
  75.                 set_color_value( plane, i, av ); 
  76.                 i+=3; 
  77.                 break; 
  78.             case 'o': 
  79.             case '2': 
  80.                 plane = OUTLINE; 
  81.                 set_color_value( plane, i, av ); 
  82.                 i+=3; 
  83.                 break; 
  84.             case 'n': 
  85.             case '3': 
  86.                 plane = NOTICE; 
  87.                 set_color_value( plane, i, av ); 
  88.                 i+=3; 
  89.                 break; 
  90.             case 'd': 
  91.             case '4': 
  92.                 plane = DEBUGMSG; 
  93.                 set_color_value( plane, i, av ); 
  94.                 i+=3; 
  95.                 break; 
  96.             default: 
  97.                 usage(); 
  98.                 exit(1); 
  99.             } 
  100.         } 
  101.         else{ 
  102.             usage(); 
  103.             exit(1); 
  104.         } 
  105.     } 
  106.  
  107.     if ( plane != EOF ) 
  108.         exit(0); 
  109.  
  110.     /* Start Interractive processing */ 
  111.     printf("Change Screen Color for the Console (Gunix)\n"); 
  112.     printf("Copyright (C)  Panic Corp 1989. All rights reserved  ではありません\n"); 
  113.  
  114.     while(1){
  115.         printf("       ^C to exit\n"); 
  116.         usage(); 
  117.         printf("Color Blue Red Green ===>> "); 
  118.         scanf("%d %d %d %d", &plane, &b, &r, &g); 
  119.         if ( plane >= 0 && plane < 5 ){ 
  120.             for( i=0; i<5; i++ ){ 
  121.                 if ( ptbl[plane][i] == EOF ) 
  122.                     break; 
  123.                 color = ptbl[plane][i]; 
  124.                 outp(P_ADDR,(char)color);
  125.                 outp(P_BLUE, (char)b);
  126.                 outp(P_RED, (char)r);
  127.                 outp(P_GREEN, (char)g);
  128.             } 
  129.         } 
  130.         else{
  131.             printf("\nInvalid Color [%d]\n", plane ); 
  132.         } 
  133.     }
  134.     /* Not reached hear */ 
  135. }
  136.