home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume6
/
ega-wanderer
/
patch1
/
386ix_ega.c
next >
Wrap
C/C++ Source or Header
|
1989-02-24
|
11KB
|
429 lines
/*
* EGA replacement console driver for VENIX SVR2
* Hacked for user mode 386/ix use.
*
* Copyright 1987 PC Research, Inc. All Rights Reserved.
*
* Modified June 1988 for use from 386/ix user mode
*
* Hacked again Feb 1989 for use with Wanderer
*
* Permission granted to use this routine in the game
* "WANDERER" is hereby granted to everbody.
*
* -Rick Richardson, PC Research, Inc.
*/
#define ADDR_6845 0x3d4
#define ega EGAaddr
#include <sys/inline.h>
splx(){} /* No way from user mode */
spl7(){}
extern char *ega;
typedef struct
{
char cols; /* Text columns */
char rows; /* Text Rows */
char pels; /* Pel rows per character */
int pagelen; /* Length of text page in bytes */
char seq[5]; /* 5 values for sequencer */
char misc; /* misc output register */
char crt[25]; /* CRT controller */
char atr[20]; /* Attribute controller */
char graph[9]; /* Graphics controller */
} CRTC;
static CRTC ega_parms[19] =
{
{ /* EGA Mode 0: 25 x 40 sixteen color text */
/**/ 40, 25, 14, 0x0800,
/*seq*/ { 0x01, 0x0b, 0x03, 0, 0x03 },
/*misc*/ 0xa7,
/*crt*/ { 0x2d, 0x27, 0x2b, 0x2d, 0x28, 0x6d,
0x6c, 0x1f, 0, 0x0d, 0x06, 0x07,
0, 0, 0, 0, 0x5e, 0x2b,
0x5d, 0x14, 0x0f, 0x5e, 0x0a, 0xa3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x14, 0x07, 0x38, 0x39, 0x3a, 0x3b,
0x3c, 0x3d, 0x3e, 0x3f, 0x08, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0x10,
0x0e, 0, 0xff}
},
{ /* EGA Mode 1: 25 x 40 sixteen color text */
/**/ 40, 25, 14, 0x0800,
/*seq*/ { 0x01, 0x0b, 0x03, 0, 0x03 },
/*misc*/ 0xa7,
/*crt*/ { 0x2d, 0x27, 0x2b, 0x2d, 0x28, 0x6d,
0x6c, 0x1f, 0, 0x0d, 0x06, 0x07,
0, 0, 0, 0, 0x5e, 0x2b,
0x5d, 0x14, 0x0f, 0x5e, 0x0a, 0xa3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x14, 0x07, 0x38, 0x39, 0x3a, 0x3b,
0x3c, 0x3d, 0x3e, 0x3f, 0x08, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0x10,
0x0e, 0, 0xff}
},
{ /* EGA Mode 2: 25 x 80 sixteen color text */
/**/ 80, 25, 14, 0x1000,
/*seq*/ { 0x01, 0x01, 0x03, 0, 0x03 },
/*misc*/ 0xa7,
/*crt*/ { 0x5b, 0x4f, 0x53, 0x37, 0x51, 0x5b,
0x6c, 0x1f, 0, 0x0d, 0x06, 0x07,
0, 0, 0, 0, 0x5e, 0x2b,
0x5d, 0x28, 0x0f, 0x5e, 0x0a, 0xa3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x14, 0x07, 0x38, 0x39, 0x3a, 0x3b,
0x3c, 0x3d, 0x3e, 0x3f, 0x08, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0x10,
0x0e, 0, 0xff}
},
{ /* EGA Mode 3: 25 x 80 sixteen color text */
/**/ 80, 25, 14, 0x1000,
/*seq*/ { 0x01, 0x01, 0x03, 0, 0x03 },
/*misc*/ 0xa7,
/*crt*/ { 0x5b, 0x4f, 0x53, 0x37, 0x51, 0x5b,
0x6c, 0x1f, 0, 0x0d, 0x0b, 0x0c,
0, 0, 0, 0, 0x5e, 0x2b,
0x5d, 0x28, 0x0f, 0x5e, 0x0a, 0xa3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x14, 0x07, 0x38, 0x39, 0x3a, 0x3b,
0x3c, 0x3d, 0x3e, 0x3f, 0x08, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0x10,
0x0e, 0, 0xff}
},
{ /* EGA Mode 4: 320x200 four color graphics */
/**/ 40, 25, 8, 0x4000,
/*seq*/ { 0x01, 0x0b, 0x03, 0, 0x02 },
/*misc*/ 0x23,
/*crt*/ { 0x37, 0x27, 0x2d, 0x37, 0x30, 0x14,
0x04, 0x11, 0, 0x01, 0, 0,
0, 0, 0, 0, 0xe1, 0x24,
0xc7, 0x14, 0, 0xe0, 0xf0, 0xa2,
0xff },
/*atr*/ { 0, 0x13, 0x15, 0x17, 0x02, 0x04,
0x06, 0x07, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x01, 0,
0x03, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0x30,
0x0f, 0, 0xff}
},
{ /* EGA Mode 5: 320x200 four color graphics */
/**/ 40, 25, 8, 0x4000,
/*seq*/ { 0x01, 0x0b, 0x03, 0, 0x02 },
/*misc*/ 0x23,
/*crt*/ { 0x37, 0x27, 0x2d, 0x37, 0x30, 0x14,
0x04, 0x11, 0, 0x01, 0, 0,
0, 0, 0, 0, 0xe1, 0x24,
0xc7, 0x14, 0, 0xe0, 0xf0, 0xa2,
0xff },
/*atr*/ { 0, 0x13, 0x15, 0x17, 0x02, 0x04,
0x06, 0x07, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x01, 0,
0x03, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0x30,
0x0f, 0, 0xff}
},
{ /* EGA Mode 6: 640x200 two color graphics */
/**/ 80, 25, 8, 0x4000,
/*seq*/ { 0x01, 0x01, 0x01, 0, 0x06 },
/*misc*/ 0x23,
/*crt*/ { 0x70, 0x4f, 0x59, 0x2d, 0x5e, 0x06,
0x04, 0x11, 0, 0x01, 0, 0,
0, 0, 0, 0, 0xe0, 0x23,
0xc7, 0x28, 0, 0xdf, 0xef, 0xc2,
0xff },
/*atr*/ { 0, 0x17, 0x17, 0x17, 0x17, 0x17,
0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
0x17, 0x17, 0x17, 0x17, 0x01, 0,
0x01, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0,
0x0d, 0, 0xff}
},
{ /* EGA Mode 7: 80x25 monochrome text */
/**/ 80, 25, 14, 0x1000,
/*seq*/ { 0x01, 0, 0x03, 0, 0x03 },
/*misc*/ 0xa6,
/*crt*/ { 0x60, 0x4f, 0x56, 0x3a, 0x51, 0x60,
0x70, 0x01, 0, 0x0d, 0x0b, 0x0c,
0, 0, 0, 0, 0x5e, 0x2e,
0x5d, 0x28, 0x0d, 0x5e, 0x6e, 0xa3,
0xff },
/*atr*/ { 0, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x10, 0x18, 0x18, 0x18,
0x18, 0x18, 0x18, 0x18, 0x0e, 0,
0x0f, 0x08 },
/*graf*/{ 0, 0, 0, 0, 0, 0x10,
0x0a, 0, 0xff}
},
{ /* EGA Mode 8: reserved */
/**/ 40, 25, 8, 0x4000,
/*seq*/ { 0x01, 0, 0, 0, 0x03 },
/*misc*/ 0x23,
/*crt*/ { 0x37, 0x27, 0x2d, 0x37, 0x31, 0x15,
0x04, 0x11, 0, 0x07, 0x06, 0x07,
0, 0, 0, 0, 0xe1, 0x24,
0xc7, 0x14, 0x08, 0xe0, 0xf0, 0xa3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x08, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0x10,
0x0e, 0, 0xff}
},
{ /* EGA Mode 9: reserved */
/**/ 40, 25, 8, 0x4000,
/*seq*/ { 0x01, 0, 0, 0, 0x03 },
/*misc*/ 0x23,
/*crt*/ { 0x37, 0x27, 0x2d, 0x37, 0x31, 0x15,
0x04, 0x11, 0, 0x07, 0x06, 0x07,
0, 0, 0, 0, 0xe1, 0x24,
0xc7, 0x14, 0x08, 0xe0, 0xf0, 0xa3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x08, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0x10,
0x0e, 0, 0xff}
},
{ /* EGA Mode A: reserved */
/**/ 40, 25, 8, 0x4000,
/*seq*/ { 0x01, 0, 0, 0, 0x03 },
/*misc*/ 0x23,
/*crt*/ { 0x37, 0x27, 0x2d, 0x37, 0x31, 0x15,
0x04, 0x11, 0, 0x07, 0x06, 0x07,
0, 0, 0, 0, 0xe1, 0x24,
0xc7, 0x14, 0x08, 0xe0, 0xf0, 0xa3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x08, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0x10,
0x0e, 0, 0xff}
},
{ /* EGA Mode B: reserved, internal use */
/**/ 80, 25, 8, 0x1000,
/*seq*/ { 0x01, 0x01, 0x04, 0, 0x07 },
/*misc*/ 0x23,
/*crt*/ { 0x70, 0x4f, 0x5c, 0x2f, 0x5f, 0x07,
0x04, 0x11, 0, 0x07, 0x06, 0x07,
0, 0, 0, 0, 0xe1, 0x24,
0xc7, 0x28, 0x08, 0xe0, 0xf0, 0xa3,
0xff },
/*atr*/ { 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0,
0x04, 0, 0xff}
},
{ /* EGA Mode C: reserved, internal use */
/**/ 80, 25, 14, 0x1000,
/*seq*/ { 0x01, 0, 0x04, 0, 0x07 },
/*misc*/ 0xa6,
/*crt*/ { 0x60, 0x4f, 0x56, 0x3a, 0x51, 0x60,
0x70, 0x01, 0, 0x0d, 0x0b, 0x0c,
0, 0, 0, 0, 0x5e, 0x2e,
0x5d, 0x28, 0x0d, 0x5e, 0x6e, 0xa3,
0xff },
/*atr*/ { 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0x0e, 0,
0x0f, 0x08 },
/*graf*/{ 0, 0, 0, 0, 0, 0,
0x04, 0, 0xff}
},
{ /* EGA Mode D: 320 x 200 sixteen color graphics */
/**/ 40, 25, 8, 0x2000,
/*seq*/ { 0x01, 0x0b, 0x0f, 0, 0x06 },
/*misc*/ 0x23,
/*crt*/ { 0x37, 0x27, 0x2d, 0x37, 0x30, 0x14,
0x04, 0x11, 0, 0, 0, 0,
0, 0, 0, 0, 0xe1, 0x24,
0xc7, 0x14, 0, 0xe0, 0xf0, 0xe3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x01, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0,
0x05, 0x0f, 0xff}
},
{ /* EGA Mode E: 640 x 200 sixteen color graphics */
/**/ 80, 25, 8, 0x4000,
/*seq*/ { 0x01, 0x01, 0x0f, 0, 0x06 },
/*misc*/ 0x23,
/*crt*/ { 0x70, 0x4f, 0x59, 0x2d, 0x5e, 0x06,
0x04, 0x11, 0, 0, 0, 0,
0, 0, 0, 0, 0xe0, 0x23,
0xc7, 0x28, 0, 0xdf, 0xef, 0xe3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x06, 0x07, 0x10, 0x11, 0x12, 0x13,
0x14, 0x15, 0x16, 0x17, 0x01, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0,
0x05, 0x0f, 0xff}
},
{ /* EGA Mode F: 640 x 350 monochrome graphics */
/**/ 80, 25, 14, 0x8000,
/*seq*/ { 0x01, 0x05, 0x0f, 0, 0x00 },
/*misc*/ 0xa2,
/*crt*/ { 0x60, 0x4f, 0x56, 0x1a, 0x50, 0xe0,
0x70, 0x01, 0, 0, 0, 0,
0, 0, 0, 0, 0x5e, 0x2e,
0x5d, 0x14, 0x0d, 0x5e, 0x6e, 0x8b,
0xff },
/*atr*/ { 0, 0x08, 0, 0, 0x18, 0x18,
0, 0, 0, 0x08, 0, 0,
0, 0x18, 0, 0, 0x0b, 0,
0x05, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0x10,
0x07, 0x0f, 0xff}
},
{ /* EGA Mode 10: 640 x 350 sixteen color graphics */
/**/ 80, 25, 14, 0x8000,
/*seq*/ { 0x01, 0x01, 0x0f, 0, 0x06 },
/*misc*/ 0xa7,
/*crt*/ { 0x5b, 0x4f, 0x53, 0x37, 0x52, 0,
0x6c, 0x1f, 0, 0, 0, 0,
0, 0, 0, 0, 0x5e, 0x2b,
0x5d, 0x28, 0x0f, 0x5f, 0x0a, 0xe3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x14, 0x07, 0x38, 0x39, 0x3a, 0x3b,
0x3c, 0x3d, 0x3e, 0x3f, 0x01, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0,
0x05, 0x0f, 0xff}
},
{ /* EGA Mode 11: 43 x 80 sixteen color text */
/**/ 80, 42, 8, 0x2000,
/*seq*/ { 0x01, 0x01, 0x03, 0x05, 0x03 }, /* used cgen2 */
/*misc*/ 0xa7,
/*crt*/ { 0x5b, 0x4f, 0x53, 0x37, 0x51, 0x5b,
0x6c, 0x1f, 0, 0x07, 0x06, 0x07,
0, 0, 0, 0, 0x5e, 0x2b,
0x58, 0x28, 0x0f, 0x5e, 0x0a, 0xa3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x14, 0x07, 0x38, 0x39, 0x3a, 0x3b,
0x3c, 0x3d, 0x3e, 0x3f, 0x08, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0x10,
0x0e, 0, 0xff}
},
{ /* EGA Mode 12: 640 x 480 sixteen color graphics */
/* PEGA Mode 50: 640 x 480 sixteen color graphics */
/**/ 80, 29, 16, 0xc800,
/*seq*/ { 0x01, 0x01, 0x0f, 0, 0x06 },
/*misc*/ 0xab,
/*crt*/ { 0x66, 0x4f, 0x53, 0x3d, 0x55, 0x1f,
0xfa, 0x1f, 0, 0, 0, 0,
0, 0, 0, 0, 0xe1, 0x29,
0xdf, 0x28, 0x0f, 0xe0, 0x1a, 0xe3,
0xff },
/*atr*/ { 0, 0x01, 0x02, 0x03, 0x04, 0x05,
0x14, 0x07, 0x38, 0x39, 0x3a, 0x3b,
0x3c, 0x3d, 0x3e, 0x3f, 0x01, 0,
0x0f, 0x00 },
/*graf*/{ 0, 0, 0, 0, 0, 0,
0x05, 0x0f, 0xff}
},
};
/*
* ega_setregs(mode):
* program EGA chips for "mode"
*/
ega_setregs(mode)
{
register CRTC *cp = &ega_parms[mode];
register int j;
register int x;
x = spl7(); /* Int's off */
for (j = 0; j < 5; ++j) /* Program sequencer */
{
outb(0x3c4, j);
outb(0x3c4 + 1, cp->seq[j]);
}
outb(0x3c2, cp->misc ); /* Program misc register */
outb(0x3c4, 0); outb(0x3c5, 3); /* Turn off sequencer reset */
splx(x); /* Int's back on (maybe) */
for( j = 0; j < 25; j++ ) /* Program CRT controller */
{
outb(ADDR_6845, j);
outb(ADDR_6845+1, cp->crt[j]);
}
inb(ADDR_6845+6 ); /* Reset Atr ctrl state */
for( j = 0; j < 20; j++ ) /* Program Atr controller */
{
outb(0x3c0, j);
outb(0x3c0, cp->atr[j]);
}
outb(0x3c0, 0 );
outb(0x3cc, 0 ); /* Program Grafix 1 position */
outb(0x3ca, 1 ); /* Program Grafix 2 position */
for( j = 0; j < 9; j++ ) /* Program Grafix controller */
{
outb(0x3ce, j);
outb(0x3ce+1, cp->graph[j]);
}
}
ega_palset(pal, color)
{
register int x;
register int areg = 0x3c0;
x = spl7();
while ((inb(ADDR_6845+6) & 0x08) == 0)
; /* Wait for vert retrace */
outb(areg, pal);
outb(areg, color);
outb(areg, 0x20);
splx(x);
}
/*
* Enable the display, must be called after a ega_setregs();
*/
ega_enable()
{
inb(ADDR_6845+6 ); outb(0x3c0, 0x20 ); /* Enable display */
}