home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------
- * DANCE.C
- *
- * Demonstrates mouse functions and EGA animation using paging
- *
- * C 5.1 Make File:
- *
- * dance.exe: dance.c
- * cl dance.c
- *
- * QuickC Program List:
- *
- * DANCE.C
- *
- *--------------------------------------------------------------------*/
-
- #include <dos.h>
- #include <bios.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <graph.h>
-
- #define MOUSE 0x33
-
- void delay(int);
-
- main ()
- {
- union REGS inregs, outregs;
- unsigned int i, j, page, color, box;
- int row, col, x, y;
-
- /* Set 320 x 200, 16 color graphics mode */
- _setvideomode( _MRES16COLOR );
-
- /* Initialize Mouse */
- inregs.x.ax = 0;
- int86 (MOUSE, &inregs, &outregs);
-
- /* Draw squares on all 8 pages */
- row = 100;
- col = 160;
- color = rand() & 0xf;
- page = 0;
- do
- {
- do
- {
- x = (rand() & 0x7) - 4;
- y = (rand() & 0x7) - 3;
- box = (rand() & 0xf) + 1;
- if ((x == 0) && (y == 0))
- y = -3;
- } while (((abs(y) * 8) <= box) || ((abs(y) * 8) <= box));
-
- do
- {
- if (((box+row) < 200) && ((box + col) < 320))
- {
- _setcolor( color );
- _setactivepage( page );
- _rectangle( _GFILLINTERIOR,col,row,col + box,row + box);
- }
-
- page++;
- if (page > 7)
- page = 0;
-
- row += y;
- col += x;
-
- } while ((!(col > 319)) && (!(col < 0)) &&
- (!(row < 0)) && (!(row > 199)));
-
- color = rand() & 0xf;
- col = (rand() & 0xff) + 32;
- row = (rand() & 0x7f) + 36;
-
- /* Check button status */
- inregs.x.ax = 3;
- int86 (MOUSE, &inregs, &outregs);
-
- /* Loop 'til left pressed */
- } while (!(outregs.x.bx & 1));
-
- /* Loop and display each page */
- page = 0;
- do
- {
- page++;
-
- if (page > 7)
- page = 0;
-
- _setvisualpage( page );
-
- /* Delay for about 1/18.2 seconds */
- delay(1);
-
- /* Check button status */
- inregs.x.ax = 3;
- int86 (MOUSE, &inregs, &outregs);
-
- /* Loop 'til right pressed */
- } while (!(outregs.x.bx & 2));
-
- /* Hide Mouse cursor */
- inregs.x.ax = 2;
- 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 );
- }
-