Message-Id: <1.5.4.32.19970514125351.00315e3c@ubeclu.unibe.ch> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Wed, 14 May 1997 14:53:51 +0200 To: djgpp AT delorie DOT com From: Roger Noss Subject: Allegro example skips vertical retraces Precedence: bulk Forget Win95/NT -- I scrounged a 486 with DOS 6.22 and decided to let Allegro do the timing, but something is amiss. I started with Allegro example #7 (ex7.c), configured the 1st timer for 1 ms and removed the other two. In a loop I wait for the vertical retrace using Allegro function _vga_vsync() and quickly store the timer's counter. Every 100 samples I print the differences. Aside from removing a 5-second counting demo, those are the only other changes, honest. Many vertical retraces are missed. What am I doing wrong? I doubt it is "void main()" despite the raging and vital discussion over main's return type. The code follows. I compiled it with "gcc myex7.c -lalleg" and ran a.exe. Roger Noss /* * Example program for the Allegro library, by Shawn Hargreaves. * * This program demonstrates how to use the timer routines. * These can be a bit of a pain, because you have to be sure you lock * all the memory that is used inside your interrupt handlers. */ /* modified to measure vertical retrace May 14, 1997, by Roger Noss */ #include #include #include "allegro.h" /* these must be declared volatile so the optimiser doesn't mess up */ volatile int x = 0; /* timer interrupt handler */ void inc_x() { x++; } END_OF_FUNCTION(inc_x); void main() { int i; int xvec[100]; allegro_init(); install_keyboard(); install_timer(); printf("\nPress a key to set up interrupt handlers\n"); readkey(); /* all variables and code used inside interrupt handlers must be locked */ LOCK_VARIABLE(x); LOCK_FUNCTION(inc_x); /* the speed can be specified in milliseconds (this is once a ms) */ install_int(inc_x, 1); /* the interrupts are now active... */ i=0; while (!keypressed()) { _vga_vsync(); xvec[i++] = x; if (i == 100) { for ( i=1; i<100; i++ ) printf("%d ", xvec[i]-xvec[i-1] ); printf("\n"); i=0; } } exit(0); }