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

Thomas Schatzl tom_at_work at yline.com
Sat May 5 13:52:46 CEST 2001


Hi again,

> > > 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.

I did some tests with W2k and it seems as if the DOS idle call is not
supported anymore (because it's not DOS the program is running). It might be
some programming mistake too though:

{delay of n ticks releasing cpu}
uses go32;

var
 timer : byte absolute $0040:$006C ;
var
 r : registers;

procedure dlay(n : integer) ;
const t : byte = 0 { static! saves some stack space } ;
begin
 while n > 0 do begin
         t := timer ;
         repeat
        // call DOS idle interrupt (my IR list from Ralf Brown says it's int
28h)
        // since the register structures' ss:sp is zero on entry the dpmi
host
        // automatically provides a real mode stack
          realintr($28, r);
         until timer<>t ;
         Dec(n) ;
        end;
end;

begin
// wait approx. 5 secs
 dlay(18*5);
end.

This program drives the cpu usage meter to 100% here.... it seems to me that
the DOS idle call is just a more elaborate way to accomplish a 'nop'.

Could anyone try with W9x ?

Btw, isn't the accuracy of the delay quite bad when using the timer IR ?
Because It only changes ~18.2 times per second giving a resolution of ~54
ms. The variance of the result is also quite high; +- a full timer tick
depending on the spot within a timer tick the timer is read first....
Although it's usually not that serious if the default delay is off a few ms
this is imho a little bit too much.

Regards,
    Thomas





More information about the fpc-pascal mailing list