home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------
- * EGALIB.C
- *
- * Demonstrates functions F1, F2, and F3 of the EGA Register
- * Interface. Each EGA color plane is filled with random bits.
- * Beofre quitting, the program shuffles the colors extremely
- * quickly while the left mouse button is held down.
- *
- * C 5.1 Make File:
- *
- * egalib.exe: egalib.c
- * cl egalib.c
- *
- * QuickC Program List:
- *
- * EGALIB.C (Note: turn off pointer checking)
- *
- *--------------------------------------------------------------------*/
-
- #include <dos.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
-
- #define MOUSE 0x33
- #define VIDEO 0x10
-
- char far paltable[16] = {0, 1, 2, 3, 4, 5, 0x14, 7, 0x38, 0x39,
- 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f};
-
- main ()
- {
- union REGS inregs, outregs;
- struct SREGS segregs;
- int i, mode, answer, limit, offset, plane;
- char c;
- unsigned int far *videoptr;
-
- printf ("Enter video mode (13, 14, 16) or 0 to end: ");
- scanf ("%d", &mode);
-
- while ((mode == 13) || (mode == 14) || (mode == 16))
- {
-
- /* set the video mode */
- inregs.x.ax = mode;
- int86 (VIDEO, &inregs, &outregs);
-
- /* reset the mouse */
- inregs.x.ax = 0;
- int86 (MOUSE, &inregs, &outregs);
-
- /* show the cursor */
- inregs.x.ax = 1;
- int86 (MOUSE, &inregs, &outregs);
-
- /* Write Register Range */
- inregs.h.ah = 0xf3;
- inregs.x.cx = 0x0010;
- inregs.x.dx = 0x18;
- segregs.es = (unsigned int)(((unsigned long)paltable >> 16) & 0xffff);
- inregs.x.bx = (unsigned int)(((unsigned long)paltable) & 0xffff);
-
- /* Make sure not in vertical retrace */
- while (inp(0x3da) & 8)
- ;
-
- /* Wait for beginning of vertical retrace */
- while (!(inp(0x3da) & 8))
- ;
-
- /* Make the palette register changes */
- int86x (VIDEO, &inregs, &outregs, &segregs);
-
- /* Write One Register */
- inregs.h.ah = 0xf1;
- inregs.h.bl = 0x20;
- inregs.x.dx = 0x18;
-
- /* Make sure not in vertical retrace */
- while (inp(0x3da) & 8)
- ;
-
- /* Wait for beginning of vertical retrace */
- while (!(inp(0x3da) & 8))
- ;
-
- /* Call the EGA Register Interface */
- int86x (VIDEO, &inregs, &outregs, &segregs);
-
- switch (mode)
- {
- case 13:
- limit = 3999;
- break;
- case 14:
- limit = 7999;
- break;
- default:
- limit = 13999;
- }
-
- for (plane = 1; plane < 9; plane *= 2)
- {
-
- /* Write One Register */
- inregs.x.ax = 0xf100;
- inregs.x.bx = plane * 256 + 2;
- inregs.x.dx = 8;
- int86 (VIDEO, &inregs, &outregs);
-
- /* hide mouse cursor */
- inregs.x.ax = 2;
- int86 (MOUSE, &inregs, &outregs);
-
- for (videoptr = (unsigned int far *)0xa0000000;
- videoptr <= (unsigned int far *)0xa0000000 + limit;
- videoptr++)
- *videoptr = rand() + rand();
-
- /* show mouse cursor */
- inregs.x.ax = 1;
- int86 (MOUSE, &inregs, &outregs);
-
- /* loop, getting the mouse status */
- do
- {
- inregs.x.ax = 3;
- int86 (MOUSE, &inregs, &outregs);
-
- /* until either mouse button is pressed */
- } while (!(outregs.x.bx & 3));
- }
-
- printf ("Enter video mode (13, 14, 16) or 0 to end: ");
- scanf ("%d", &mode);
- }
-
- printf("Press and hold left button\n");
- printf("Press right button to quit\n");
-
- do
- {
-
- /* shuffle the color shades */
- for (i=0; i<16; i++)
- paltable[i] = (char)rand() & 0x7f;
-
- /* Write Register Range */
- inregs.h.ah = 0xf3;
- inregs.x.cx = 0x0010;
- inregs.x.dx = 0x18;
- segregs.es = (unsigned int)(((unsigned long)paltable >> 16) & 0xffff);
- inregs.x.bx = (unsigned int)(((unsigned long)paltable) & 0xffff);
-
- /* Make sure not in vertical retrace */
- while (inp(0x3da) & 8)
- ;
-
- /* Wait for beginning of vertical retrace */
- while (!(inp(0x3da) & 8))
- ;
-
- /* Make the palette register changes */
- int86x (VIDEO, &inregs, &outregs, &segregs);
-
- /* Write One Register */
- inregs.h.ah = 0xf1;
- inregs.h.bl = 0x20;
- inregs.x.dx = 0x18;
-
- /* Make sure not in vertical retrace */
- while (inp(0x3da) & 8)
- ;
-
- /* Wait for beginning of vertical retrace */
- while (!(inp(0x3da) & 8))
- ;
-
- /* Call the EGA Register Interface */
- int86x (VIDEO, &inregs, &outregs, &segregs);
-
- do
- {
-
- /* get mouse status */
- inregs.x.ax = 3;
- int86 (MOUSE, &inregs, &outregs);
-
- /* loop until either button is pressed */
- } while (!(outregs.x.bx & 3));
-
- /* quit if right button was pressed */
- } while (!(outregs.x.bx & 2));
-
- /* Read Register Range */
- inregs.h.ah = 0xf2;
- inregs.x.cx = 0x0010;
- inregs.x.dx = 0x18;
- segregs.es = (unsigned int)(((unsigned long)paltable >> 16) & 0xffff);
- inregs.x.bx = (unsigned int)(((unsigned long)paltable) & 0xffff);
- int86x (VIDEO, &inregs, &outregs, &segregs);
-
- /* hide the mouse cursor */
- inregs.x.ax = 2;
- int86 (VIDEO, &inregs, &outregs);
-
- /* printout the palette colors */
- for (i = 0; i < 16; i++)
- printf ("Palette reg.%x: %x\n", i, paltable[i] & 0xff);
- }