/* ************************************************ */ /* METAGRAPHICS SOFTWARE CORPORATION (c) 1989-1992 */ /* Enables 256 level greyscale on ATI mach32 boards */ /* ************************************************ */ #include #include #include #include #include #include #include #include "metawndo.h" /* master MetaWINDOW include file */ /* special stack size declaration if using Turbo or Borland C++ */ #ifdef TurboC extern unsigned _stklen = 14336U; /* stack size 14K */ #endif /* global variables */ palData palColors[256]; long max_colors; /* function prototypes */ void quit(char*, int ); void draw_palette( void ); void C_WritePalette( int palnum, int start, int end, palData *pdata ); int ATI_Mach32_DAC8( int ); void main( int argc, char *argv[] ) { int i, color; rect scrnR; /* init the system */ i = InitGraphics(ATI640x480X); if( i != 0 ) exit(i); SetDisplay( GrafPg0 ); ScreenRect( &scrnR ); EraseRect( &scrnR ); /* set a virtual coordinate system of 1000x1000 */ SetRect( &scrnR, 0, 0, 1000, 1000 ); VirtualRect( &scrnR ); max_colors= QueryColors(); /* draw the palette */ draw_palette(); /* program palette for 256 level grey scale */ for( i = 0; i < 256; i++ ) { color = i << 8; // scale up to 0 thru FFFF palColors[i].palRed = color; palColors[i].palGreen = color; palColors[i].palBlue = color; } // enable 8 bit dacs if( !ATI_Mach32_DAC8( 1 ) ) quit("No 8 bit DAC on board!",0); /* set the palette */ C_WritePalette( 0, 0,max_colors, &palColors[0] ); getch(); // disable 8 bit dacs ATI_Mach32_DAC8( 0 ); quit("Normal End",0); } /* C version of write palette that uses upper 8 bits of paldata */ void C_WritePalette( int palnum, int start, int end, palData *pdata ) { #define DAC_INDEX 0x03C8 #define DAC_DATA 0x03C9 int i; for( i = start; i <= end; i++ ) { // even though the index port auto increments, // set it each time (interrupts may clober it) disable(); // cli outportb( DAC_INDEX, i ); outportb( DAC_DATA, pdata->palRed >> 8 ); outportb( DAC_DATA, pdata->palGreen >> 8 ); outportb( DAC_DATA, pdata->palBlue >> 8 ); enable(); // sti pdata++; } } // enable 8 bit dac on an ATI Mach32 chipset int ATI_Mach32_DAC8(int on ) { #define CONFIG_STATUS_1 0x12EE #define EXT_GE_CONFIG 0x7AEE #define DAC_MASK 0x02EA #define ATI68830_DAC 0x0 #define SIERRA_DAC 0x200 #define TI_DAC 0x400 #define BROOKTREE_DAC 0x600 #define ATT_DAC 0x800 int dacType; // what kind of DAC on board ? dacType = inport( CONFIG_STATUS_1 ); dacType &= 0x0E00; switch( dacType ) { case ATT_DAC: // ATT20C491 or Brooktree Bt481/482 break; case TI_DAC: // TI TLC34075 or ATI ATI34075 break; default: // not a 8 bit DAC return 0; } if( on ) outport( EXT_GE_CONFIG, 0x401A ); else outport( EXT_GE_CONFIG, 0x1A ); outportb( DAC_MASK, 0xFF ); return 1; } /* Draw a screen full of boxes, one for each color combination */ void draw_palette() { int color; int deltaX, deltaY, sizeX, sizeY; rect r; char buf[10]; MoveTo( 0,0 ); /* size the boxes */ if( max_colors > 16) { deltaX = 40; deltaY = 50; sizeX = 30; sizeY = 40; } else { deltaX = 150; deltaY = 200; sizeX = 100; sizeY = 100; } SetRect( &r, 0, 0, sizeX, sizeY ); for( color = 0; color <= max_colors; color++ ) { PenColor( color ); PaintRect( &r ); PenColor( White ); FrameRect( &r ); /* label the color if it will fit on the screen */ if( max_colors <= 16) { MoveTo( r.Xmin + 49, r.Ymax + 35 ); sprintf( buf, "%d", color ); DrawString( buf ); } OffsetRect( &r, deltaX, 0 ); if( r.Xmax > 640 ) { r.Xmin = 0; r.Xmax = sizeX; OffsetRect( &r, 0, deltaY ); } } } /* ** Standardized exit routine. Provides for a safe, orderly shutdown. ** Display a final msg, and returns the passed error code to DOS. */ void quit( char *msgptr, int err ) { int i; StopMouse(); StopEvent(); SetDisplay(TextPg0); if(err) putch(07); printf("\n\n%s",msgptr); i=QueryError(); printf("\nQueryError=%d/%d",i >> 7,i & 127); if(err) i=err; StopGraphics(); exit(i); }