#include #include #include #include #include #include #include "modex16.h" byte far* VGA=(byte far*) 0xA0000000; /* this points to video memory. */ static void fadePalette(sbyte fade, sbyte start, word iter, byte *palette); static byte tmppal[PAL_SIZE]; static struct pcxHeader { byte id; byte version; byte encoding; byte bpp; word xmin; word ymin; word xmax; word ymax; word hres; word vres; byte pal16[48]; byte res1; word bpplane; word palType; word hScreenSize; word vScreenSize; byte padding[54]; }; static void vgaSetMode(byte mode) { union REGS regs; regs.h.ah = SET_MODE; regs.h.al = mode; int86(VIDEO_INT, ®s, ®s); } /* -========================= Entry Points ==========================- */ void modexEnter() { word i; dword far*ptr=(dword far*)VGA; /* used for faster screen clearing */ word CRTParms[] = { 0x0d06, /* vertical total */ 0x3e07, /* overflow (bit 8 of vertical counts) */ 0x4109, /* cell height (2 to double-scan */ 0xea10, /* v sync start */ 0xac11, /* v sync end and protect cr0-cr7 */ 0xdf12, /* vertical displayed */ 0x0014, /* turn off dword mode */ 0xe715, /* v blank start */ 0x0616, /* v blank end */ 0xe317 /* turn on byte mode */ }; int CRTParmCount = sizeof(CRTParms) / sizeof(CRTParms[0]); /* TODO save current video mode and palette */ vgaSetMode(VGA_256_COLOR_MODE); /* disable chain4 mode */ outpw(SC_INDEX, 0x0604); /* synchronous reset while setting Misc Output */ outpw(SC_INDEX, 0x0100); /* select 25 MHz dot clock & 60 Hz scanning rate */ outp(MISC_OUTPUT, 0xe3); /* undo reset (restart sequencer) */ outpw(SC_INDEX, 0x0300); /* reprogram the CRT controller */ outp(CRTC_INDEX, 0x11); /* VSync End reg contains register write prot */ outp(CRTC_DATA, 0x7f); /* get current write protect on varios regs */ /* send the CRTParms */ for(i=0; iwidth; px+=4) { offset=px; for(py=0; pyheight; py++) { if(!sprite || bmp->data[offset]) page[PAGE_OFFSET(x+px, y+py)] = bmp->data[offset]; offset+=bmp->width; } } } } /* fade and flash */ void modexFadeOn(word fade, byte *palette) { fadePalette(-fade, 64, 64/fade+1, palette); } void modexFadeOff(word fade, byte *palette) { fadePalette(fade, 0, 64/fade+1, palette); } void modexFlashOn(word fade, byte *palette) { fadePalette(fade, -64, 64/fade+1, palette); } void modexFlashOff(word fade, byte *palette) { fadePalette(-fade, 0, 64/fade+1, palette); } static void fadePalette(sbyte fade, sbyte start, word iter, byte *palette) { word i; byte dim = start; /* handle the case where we just update */ if(iter == 0) { modexPalUpdate(palette); return; } while(iter > 0) { /* FadeLoop */ for(i=0; i 127) { tmppal[i] = 0; } else if(tmppal[i] > 63) { tmppal[i] = 63; } } modexPalUpdate(tmppal); iter--; dim += fade; } } /* save and load */ void modexPalSave(byte *palette) { int i; outp(PAL_READ_REG, 0); /* start at palette entry 0 */ for(i=0; i> 2; } } else { /* use the 16 color palette */ for(index=0; index<48; index++) { result.palette[index] = head.pal16[index]; } } fclose(file); return result; }