home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 1
/
FREEWARE.BIN
/
gunix
/
cpc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-10-17
|
4KB
|
180 lines
/*
* cpc.c ----- change palette color.
*
*
* Usage: cpc -{c,m}
*
* -c : Resets to the dafault color of console.
* -m : Resets to the dafault color of MSDOS.
*
* cpc color b [r [g] ]
*
* color : palette number ( 0 - 16 ).
* b : Blue value ( 0 - 255 ).
* r : Red value ( 0 - 255 ).
* g : Green value ( 0 - 255 ).
*
*/
#include <stdio.h>
#include <dos.h>
#include <ctype.h>
#define P_ADDR 0x0fd90
#define P_BLUE 0x0fd92
#define P_RED 0x0fd94
#define P_GREEN 0x0fd96
#define VAL0 0
#define VAL1 255
#define VAL2 64
#define VAL3 128
#define FAIL -1
/* console default color */
static unsigned char p0[16][3]= {
VAL2, VAL2, VAL2, /* 0 gray */
VAL1, VAL1, VAL1, /* 1 white */
VAL2, VAL2, VAL2, /* 2 gray */
VAL1, VAL1, VAL1, /* 3 white */
VAL0, VAL1, VAL1, /* 4 yellow */
VAL0, VAL1, VAL1, /* 5 yellow */
VAL0, VAL1, VAL1, /* 6 yellow */
VAL0, VAL0, VAL0, /* 7 black */
VAL0, VAL1, VAL0, /* 8 red */
VAL0, VAL0, VAL0, /* 9 black */
VAL0, VAL1, VAL0, /* 10 red */
VAL0, VAL0, VAL0, /* 11 black */
VAL0, VAL1, VAL0, /* 12 red */
VAL0, VAL0, VAL0, /* 13 black */
VAL0, VAL1, VAL0, /* 14 red */
VAL0, VAL0, VAL0 /* 15 black */
};
/* MSDOS default color */
static unsigned char p1[16][3]= {
VAL0, VAL0, VAL0, /* 0 Black */
VAL3, VAL0, VAL0, /* 1 Blue */
VAL0, VAL3, VAL0, /* 2 Red */
VAL0, VAL0, VAL3, /* 3 Green */
VAL0, VAL3, VAL3, /* 4 Yellow */
VAL3, VAL3, VAL0, /* 5 sky blue */
VAL3, VAL0, VAL3, /* 6 cyian */
VAL3, VAL3, VAL3, /* 7 White */
VAL0, VAL0, VAL0, /* 8 Black */
VAL1, VAL0, VAL0, /* 9 Blue with hilight*/
VAL0, VAL1, VAL0, /* 10 Red with hilight*/
VAL0, VAL0, VAL1, /* 11 Green with hilight*/
VAL0, VAL1, VAL1, /* 12 Yellow with hilight*/
VAL1, VAL1, VAL0, /* 13 Sky Blue with hilight*/
VAL1, VAL0, VAL1, /* 14 Cyian with hilight*/
VAL1, VAL1, VAL1 /* 15 White with hilight*/
};
main( ac, av )
char **av;
{
int color, b, r, g, i, c;
switch( ac ){
case 2:
if ( av[1][0] == '-' ){
c = tolower( av[1][1] );
if ( c == 'c' ){
/* console dafault */
for( i=0; i<16; i++ ){
outp(P_ADDR,i);
outp(P_BLUE, p0[i][0]);
outp(P_RED, p0[i][1]);
outp(P_GREEN,p0[i][2]);
}
exit(0);
}
else if ( c == 'm' ){
/* msdos dafault */
for( i=0; i<16; i++ ){
outp(P_ADDR,i);
outp(P_BLUE, p1[i][0]);
outp(P_RED, p1[i][1]);
outp(P_GREEN,p1[i][2]);
}
exit(0);
}
}
break;
case 3:
if ( (color=str_digit(av[1])) != FAIL &&
(b=str_digit(av[2])) != FAIL){
g = r = b;
set_palette( color, b, r, g );
exit(0);
}
break;
case 4:
if ( (color=str_digit(av[1])) != FAIL &&
(b=str_digit(av[2])) != FAIL &&
(r=str_digit(av[3])) != FAIL){
g = r;
set_palette( color, b, r, g );
exit(0);
}
break;
case 5:
if ( (color=str_digit(av[1])) != FAIL &&
(b=str_digit(av[2])) != FAIL &&
(r=str_digit(av[3])) != FAIL &&
(g=str_digit(av[4])) != FAIL){
set_palette( color, b, r, g );
exit(0);
}
break;
default:
break;
}
/* Start Interractive processing */
printf("Change Pallete Color for DMYCON or Console (Gunix)\n");
printf("Copyright (C) Panic Corp 1989. All rights reserved ではありません\n");
printf(" ^C to quit\n");
while(1){
printf("Color : Coloe code ( 0 --> 15 )\n");
printf("Blue : Blue Value ( 0 --> 255 )\n");
printf("Red : Red Value ( 0 --> 255 )\n");
printf("Green : Green Value ( 0 --> 255 )\n");
printf("Color, Blue, Red, Green ===>> ");
scanf("%d %d %d %d", &color, &b, &r, &g);
set_palette( color, b, r, g );
}
}
str_digit( str )
char *str;
{
char *p=str;
int digit;
while( *p ){
if ( !isdigit( *p ) )
return FAIL;
p++;
}
sscanf( str, "%d", &digit );
return digit;
}
set_palette( color, b, r, g )
{
outp(P_ADDR,(char)color);
outp(P_BLUE, (char)b);
outp(P_RED, (char)r);
outp(P_GREEN, (char)g);
}