kolibrios-fun/programs/develop/cedit/SRC/Timer.ob07

80 lines
1.7 KiB
Plaintext
Raw Normal View History

(*
Copyright 2021 Anton Krotov
This file is part of CEdit.
CEdit is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CEdit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CEdit. If not, see <http://www.gnu.org/licenses/>.
*)
MODULE Timer;
IMPORT SYSTEM, K := KolibriOS, KOSAPI, Ini;
VAR
stack: ARRAY 1024*64 OF INTEGER;
ID*, n*, time, cnt: INTEGER;
enabled: BOOLEAN;
msg: ARRAY 3 OF INTEGER;
PROCEDURE kill*;
BEGIN
enabled := FALSE;
INC(n)
END kill;
PROCEDURE [stdcall] main (mainTID: INTEGER);
CONST
step = 5;
BEGIN
msg[0] := ID;
msg[1] := 12;
WHILE TRUE DO
K.Pause(step);
IF KOSAPI.sysfunc3(18, 21, mainTID) = 0 THEN
ID := 0;
K.Exit
END;
IF enabled THEN
DEC(cnt, step);
IF cnt <= 0 THEN
KOSAPI.sysfunc5(60, 2, mainTID, SYSTEM.ADR(msg[0]), msg[1]);
cnt := time
END
END
END
END main;
PROCEDURE create* (mainTID: INTEGER);
BEGIN
time := Ini.blink;
cnt := time;
enabled := TRUE;
IF ID = 0 THEN
stack[LEN(stack) - 1] := mainTID;
ID := K.CreateThread(SYSTEM.ADR(main), stack)
ELSE
INC(n);
msg[2] := n
END
END create;
BEGIN
ID := 0;
msg[2] := 0;
n := 0;
END Timer.