From ffa28fc962b68e707bf3a50bf19ea0f816f884fa Mon Sep 17 00:00:00 2001 From: pavelyakov Date: Thu, 25 Jun 2020 10:18:33 +0000 Subject: [PATCH] fix error and add new example git-svn-id: svn://kolibrios.org@8043 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/examples/timers.c | 42 ++++++++++++++++++++++++++++++++++ programs/cmm/lib/kolibri.h | 5 ++-- programs/cmm/lib/timers.h | 24 +++++++++---------- 3 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 programs/cmm/examples/timers.c diff --git a/programs/cmm/examples/timers.c b/programs/cmm/examples/timers.c new file mode 100644 index 0000000000..a04c8d2dab --- /dev/null +++ b/programs/cmm/examples/timers.c @@ -0,0 +1,42 @@ +#define MEMSIZE 4096*10 + +#include "../lib/io.h" +#include "../lib/window.h" +#include "../lib/timers.h" + +window win1=0; +dword timeID = 0; +int t = 0; +void intervalTest() +{ + t++; + if (t==10) clearInterval(timeID); + DrawBar(100, 70, 100, 100, 0xDED7CE); + WriteText(100,70,0x90,0,itoa(t)); +} +void main() +{ + word id=0; + timeID = setInterval(#intervalTest, 100); // 100 => 1s + loop() + { + switch(WaitEventTimeout(1)) + { + case evButton: + id=GetButtonID(); + IF (id==1) ExitProcess(); + break; + + case evKey: + GetKeys(); + break; + + case evReDraw: + DefineAndDrawWindow(20,30,500,600,WINDOW_NORMAL,0xDED7CE,"Window",0); + if (!t) WriteText(100,70,0x90,0,"Start!"); + break; + } + Timer.revise(); + } +} + diff --git a/programs/cmm/lib/kolibri.h b/programs/cmm/lib/kolibri.h index 049f1aa7ae..e61d559831 100644 --- a/programs/cmm/lib/kolibri.h +++ b/programs/cmm/lib/kolibri.h @@ -94,9 +94,10 @@ inline fastcall dword CheckEvent() $int 0x40 } -inline fastcall dword WaitEventTimeout(EBX) +inline dword WaitEventTimeout(dword time) { EAX = 23; + EBX = time; $int 0x40 } @@ -667,4 +668,4 @@ ______STOP______: #ifndef INCLUDE_IPC_H #include "../lib/ipc.h" -#endif \ No newline at end of file +#endif diff --git a/programs/cmm/lib/timers.h b/programs/cmm/lib/timers.h index 6b251f612b..35748db2bb 100644 --- a/programs/cmm/lib/timers.h +++ b/programs/cmm/lib/timers.h @@ -12,13 +12,13 @@ :struct Timers { dword time; - dword alloc; - dword count; - dword size; - void revise(void); - void getTime(void); - dword set(dword,dword,byte); - dword clear(dword); + dword alloc; + dword count; + dword size; + void revise(void); + void getTime(void); + dword set(dword,dword,byte); + dword clear(dword); }; void Timers::getTime(void) { @@ -88,20 +88,20 @@ dword Timers::clear(dword id) } // Analogs JS Functions -:Timers Time = {0}; +:Timers Timer = {0}; inline dword setTimeout(dword function, time) { - RETURN Time.set(function, time, 0); + RETURN Timer.set(function, time, 0); } inline dword setInterval(dword function, time) { - RETURN Time.set(function, time, 1); + RETURN Timer.set(function, time, 1); } inline dword clearTimeout(dword id) { - RETURN Time.clear(id); + RETURN Timer.clear(id); } inline dword clearInterval(dword id) { - RETURN Time.clear(id); + RETURN Timer.clear(id); }