3 * Purpose: This file contains routines for manipulating the VGA palette.
\r
10 static void fadePalette(byte fade, byte start, word iter, byte *palette);
\r
11 static byte tmppal[PAL_SIZE];
\r
13 /* fade and flash */
\r
15 fadeOn(word fade, byte *palette) {
\r
16 fadePalette(-fade, 64, 64/fade+1, palette);
\r
21 fadeOff(word fade, byte *palette) {
\r
22 fadePalette(fade, 0, 64/fade+1, palette);
\r
27 flashOn(word fade, byte *palette) {
\r
28 fadePalette(fade, -64, 64/fade+1, palette);
\r
33 flashOff(word fade, byte *palette) {
\r
34 fadePalette(-fade, 0, 64/fade+1, palette);
\r
39 fadePalette(byte fade, byte start, word iter, byte *palette) {
\r
43 /* handle the case where we just update */
\r
49 while(iter > 0) { /* FadeLoop */
\r
50 for(i=0; i<PAL_SIZE; i++) { /* loadpal_loop */
\r
51 tmppal[i] = palette[i] - dim;
\r
52 if(tmppal[i] > 127) {
\r
54 } else if(tmppal[i] > 63) {
\r
67 palSave(byte *palette) {
\r
70 outp(PEL_READ_REG, 0); /* start at palette entry 0 */
\r
71 for(i=0; i<PAL_SIZE; i++) {
\r
72 palette[i] = inp(PEL_DATA_REG); /* read the palette data */
\r
80 ptr = malloc(PAL_SIZE);
\r
84 printf("Could not allocate palette.\n");
\r
93 loadPaletteFile(byte *filename, byte **palette) {
\r
97 /* free the palette if it exists */
\r
102 /* allocate the new palette */
\r
103 *palette = newPal();
\r
105 /* open the file */
\r
106 file = fopen(filename, "rb");
\r
108 printf("Could not open palette file: %s\n", filename);
\r
112 /* read the file */
\r
114 while(!feof(file)) {
\r
115 *ptr++ = fgetc(file);
\r
125 fadePalette(-1, 64, 1, tmppal);
\r
131 fadePalette(-1, -64, 1, tmppal);
\r
137 palUpdate(byte *p) {
\r
140 outp(PEL_WRITE_REG, 0); /* start at the beginning of palette */
\r
141 for(i=0; i<PAL_SIZE/2; i++) {
\r
142 outp(PEL_DATA_REG, p[i]);
\r
144 waitborder(); /* waits one retrace -- less flicker */
\r
145 for(i=PAL_SIZE/2; i<PAL_SIZE; i++) {
\r
146 outp(PEL_DATA_REG, p[i]);
\r
153 while(inp(INPUT_STATUS_1) & 8) {
\r
157 while(!(inp(INPUT_STATUS_1) & 8)) {
\r