[fpc-pascal]dos approx delay fn that releases cpu

Lee, John LeeJ at logica.com
Tue May 1 15:01:19 CEST 2001

Anyone know anything better than the code below (from John Stockton's site),
comments from [fpc-devel] , which releases cpu that will work for win95 and
win 2000? this is results so far from fpc developers...

I've noticed that although this seems to work mostly in fpc dos
program under win2000 it sometimes crashes & creates an exception...Under
win95 it _always_ seems to work, so assume win2000 problem is the dos
emulator...The code relies on the timer interupt working correctly as in
real dos. 

What is the 'best' fpc dos code (including the dos_idle pls which
does approx delay w/o wasting cputime and can be compiled with go32v2 . TIA
{delay of n ticks releasing cpu}
procedure dlay(n : integer) ;
   const t : byte = 0 { static! saves some stack space } ;
   var timer : byte absolute $0040:$006C ;
   begin while n > 0 do begin
       t := timer ;
       repeat  asm  hlt  end  until timer<>t ;
       Dec(n) ;
       end end ;
> > Stockton's site) that works in tp (under win95 and on win2000)
> > and releases cpu time. Is there an equivalent that'll work in fpc?
> It may be possible to add this to the go32v2 crt unit's
> current delay function (simply add a "hlt" in both the initdelay and
> delay functions internal loop). It might cause a loss of accuracy
> though...

 _If_ we decide to add something similar to the delay unit, we should
replace the halt instruction with the DOS idle call, because that many TSRs
use this one under plain DOS and it's still supported under Wxx to lower the
CPU load.

More information about the fpc-pascal mailing list