home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------
- * FLOW.C
- *
- * Written by Eric Fogelin
- * September 19, 1988
- *
- * Demonstrates mouse functions and EGA animation using paging
- *
- * C 5.1 Make File:
- *
- * flow.exe: flow.c
- * cl flow.c
- *
- * QuickC Program List:
- *
- * FLOW.C
- *
- *--------------------------------------------------------------------*/
-
- #include <bios.h>
- #include <dos.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <graph.h>
-
- #define VIDEO 0x10
- #define MOUSE 0x33
- #define LBUTTON 1
- #define RBUTTON 2
-
- #define MINBOXSIZE 8
- #define MAXBOXSIZE 48
-
- void delay(int);
-
- int delta = 1;
- int box = 16;
-
- char far paltable[16];
-
- main ()
- {
- union REGS inregs, outregs;
- struct SREGS segregs;
- unsigned int i, x, y;
- unsigned int color;
-
- _setvideomode( _ERESCOLOR ); /* EGA 640x350 16 color */
-
- /* Check that EGA Register Interface installed */
- inregs.h.ah = 0xfa; /* Interrogate driver */
- inregs.x.bx = 0;
- int86x( VIDEO, &inregs, &outregs, &segregs );
- if ( outregs.x.bx == 0 )
- {
- printf( "EGA Register Interface not installed\n" );
- exit( 1 );
- }
-
- inregs.x.ax = 0; /* Initialize Mouse */
- int86( MOUSE, &inregs, &outregs );
-
- inregs.x.ax = 1; /* Show Mouse */
- int86( MOUSE, &inregs, &outregs );
-
- /* Read palette write-only registers in EGA mode */
- 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 );
-
- /* Now that we got 'em, print 'em out */
- printf( "Default Palette Set\n\n" );
- for( i = 0; i < 16; i++ )
- printf( "Palette reg.%x: %x\n", i, paltable[i] & 0xff );
- printf( "\nClick and drag using left mouse button..." );
-
- /* Wait until left button on mouse is held down */
- do
- {
- inregs.x.ax = 3; /* Check button status */
- int86( MOUSE, &inregs, &outregs );
- } while( !(outregs.x.bx & LBUTTON) ); /* Loop 'til left pressed */
-
- inregs.x.ax = 2; /* Hide Mouse */
- int86( MOUSE, &inregs, &outregs );
-
- _clearscreen( _GCLEARSCREEN ); /* Clear display */
-
- inregs.x.ax = 1; /* Show Mouse */
- int86( MOUSE, &inregs, &outregs );
-
- /* Initialize and get current mouse position. */
- x = y = color = 0;
- inregs.x.ax = 3;
- int86( MOUSE, &inregs, &outregs );
-
- /* Draw rectangles at current mouse position while changing colors */
- do
- {
- /* Only draw new rectangle in new color if mouse has moved */
- if ( (x != outregs.x.cx) || (y != outregs.x.dx) )
- {
-
- /* Bump up color, but only cyle from 1-14. Do not affect
- palette registers 0 (black) and 15 (intense white). */
- color++;
- if (color >= 15)
- color = 1;
- _setcolor( color );
-
- /* Save current mouse position for later use */
- x = outregs.x.cx;
- y = outregs.x.dx;
-
- box += delta;
- if ((box < MINBOXSIZE) || (box > MAXBOXSIZE))
- delta = -delta;
-
- inregs.x.ax = 2; /* Hide Mouse */
- int86( MOUSE, &inregs, &outregs );
-
- _rectangle( _GFILLINTERIOR, x, y, x+box, y+box );
-
- inregs.x.ax = 1; /* Show Mouse */
- int86( MOUSE, &inregs, &outregs );
- }
-
- inregs.x.ax = 3; /* Check button status */
- int86( MOUSE, &inregs, &outregs );
-
- } while( outregs.x.bx & LBUTTON ); /* Loop 'til left released */
-
- /* Cycle palette registers 1-14. Do not affect palette register
- 0 (black) and palette register 15 (intense white). */
-
- do
- {
-
- /* Setup palette change using EGA.SYS */
- 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) )
- ;
-
- /* Now we are guaranteed to be in vertical retrace period.
- Now is the time to make the palette register changes. */
- int86x( VIDEO, &inregs, &outregs, &segregs );
-
- /* Assure EGA's ACR is pointing to AAR */
- inp( 0x3da );
-
- /* Activate new palette */
- outp( 0x3c0, 0x20 );
-
- /* Rotate only palette registers 1-14, leave 0 and 15 be */
- for( i=15; i>1; i-- )
- paltable[i] = paltable[i-1];
-
- paltable[1] = paltable[15];
-
- /* Put intense white (0x3f) back into reg. 15 */
- paltable[15] = 0x3f;
-
- /* Delay for 1/18.2 second */
- delay( 1 );
-
- inregs.x.ax = 3; /* Get mouse status */
- int86( MOUSE, &inregs, &outregs );
-
- } while( !(outregs.x.bx & RBUTTON) ); /* Loop 'til right pressed */
-
- inregs.x.ax = 2; /* Hide Mouse cursor */
- int86( MOUSE, &inregs, &outregs );
-
- _clearscreen( _GCLEARSCREEN );
- _setvideomode( _DEFAULTMODE );
- }
-
-
- /* Delay for a number of clock ticks */
- void delay( ticks )
- int ticks;
- {
- long end_tick, now_tick;
- unsigned midnight_flag;
-
- _bios_timeofday( _TIME_GETCLOCK, &now_tick );
- end_tick = now_tick + (long) ticks;
-
- do
- {
- midnight_flag = _bios_timeofday( _TIME_GETCLOCK, &now_tick );
- if ( midnight_flag )
- end_tick -= 1573040;
- }
- while ( now_tick < end_tick );
- }
-