|
Post by levievre on Dec 4, 2023 9:06:13 GMT 1
Hello Jos, I'm trying to create an event handler in my turbo pascal app. I'd like my app to do something if there is no keyboard input after a period of time (10 mn for example) So instead of simply wait for a key input, I now have a loop waiting for a keypressed every time. Since this loop makes my cpu very busy, i wanted to insert a delay instruction in my loop to sleep the processor for few milliseconds. I use this delay function ... Procedure MyDelay(ms : Word); Assembler; Asm mov ax, 1000; mul ms; mov cx, dx; mov dx, ax; mov ah, $86; int $15; end;
... but Inserting this delay instruction changes nothing, because it does not work like the windows sleep command.
Is there a way for my dos delay function to work like a sleep command ?
Thank you, Levievre.
|
|
|
Post by Jos on Dec 4, 2023 10:25:02 GMT 1
Int 15-86h isn’t supported, until now no one asked (used) that. And it isn’t that straightforward, can’t just put vDos to sleep. It still has to be responsive to Windows messages.
Don’t know, but for instance:
loop: mov ah,11 int 16 jz loop
Still triggers vDos to go idle within a few seconds. And suspend all operations after some 30 seconds. You could eventually add a timeout by testing the system clock (INT 21-2Ch or INT 1A/0h).
Jos
|
|
|
Post by levievre on Dec 4, 2023 11:16:11 GMT 1
I know ... this is not a pascal forum. But this is what my loop try to do :
VAR BiosTimer : longint absolute $40:$6C;
FUNCTION MyReadkey : CHAR;
VAR WakeUp : BOOLEAN; i,x,y : BYTE; Time_Start, Time_Stop, Time_Now : LONGINT;
BEGIN Time_Start:=BiosTimer; Time_Stop:=Time_Start+ROUND(DelayinMinutes*60*18.2);{bios ticks : 18,2 / sec} REPEAT {Would like an instruction here to relinquish the CPU for X milliseconds} {something like sleep(10)} Time_Now:=BiosTimer; IF Time_Now<Time_Start THEN BEGIN DEC(Time_Start,$1800B0);{bios ticks : $1800B0 / day} DEC(Time_Stop,$1800B0); END; IF (Time_Now>Time_Stop) THEN BEGIN x:=wherex; y:=wherey; {Message : app will close in 30 sec.} InitProgressBar('Closing the app ... '); WakeUp:=false; i:=0; WHILE (NOT WakeUp) AND (i<30) DO BEGIN WakeUp:=pause(1)<>'#'; {true if a key is pressed otherwise wait for 1 second} INC(i); FillProgressbar(i,30); END; CloseProgressBar; IF NOT WakeUp THEN {If no user action, program stops} Halt(1) ELSE BEGIN Time_Start:=BiosTimer; Time_Stop:=Time_Start+ROUND(DelayinMinutes*60*18.2); gotoxy(x,y); END; END; UNTIL Keypressed; MyReadkey:=Readkey; END;
Thank you.
|
|
|
Post by Jos on Dec 4, 2023 12:27:38 GMT 1
If we concentrate on the outer loop w/o the timeout/key check:
BEGIN Time_Start:=BiosTimer; Time_Stop:=Time_Start+ROUND(DelayinMinutes*60*18.2);{bios ticks : 18,2 / sec} REPEAT Time_Now:=BiosTimer; IF Time_Now<Time_Start THEN BEGIN DEC(Time_Start,$1800B0);{bios ticks : $1800B0 / day} DEC(Time_Stop,$1800B0); END; UNTIL Keypressed; MyReadkey:=Readkey; END;
This should still trigger vDos to go idle. So the CPU usage drops to zero. Eventually send me a simple test program to demonstrate it doesn't.
Jos
|
|