forked from KolibriOS/kolibrios
Addition new functions Timers
git-svn-id: svn://kolibrios.org@7997 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
717f2f2b9f
commit
3feca3e420
100
programs/cmm/lib/timers.c
Normal file
100
programs/cmm/lib/timers.c
Normal file
@ -0,0 +1,100 @@
|
||||
/* TIMERS PaulCodeman */
|
||||
|
||||
#define offsetSizeTimers 4*3+1
|
||||
#define defaultMaxTimers 1000
|
||||
:struct Timers
|
||||
{
|
||||
dword time;
|
||||
dword alloc;
|
||||
dword count;
|
||||
dword size;
|
||||
void watch(void);
|
||||
void getTime();
|
||||
dword set(dword,dword,byte);
|
||||
dword clear(dword);
|
||||
};
|
||||
void Timers::getTime(void)
|
||||
{
|
||||
EAX = 26;
|
||||
EBX = 9;
|
||||
$int 0x40
|
||||
time = EAX;
|
||||
}
|
||||
void Timers::watch(void)
|
||||
{
|
||||
dword position = 0;
|
||||
dword i = 0;
|
||||
IF (!alloc) RETURN;
|
||||
getTime();
|
||||
i = count;
|
||||
position = alloc;
|
||||
WHILE(i)
|
||||
{
|
||||
IF (DSDWORD[position])
|
||||
{
|
||||
IF (DSDWORD[position+4]<=time)
|
||||
{
|
||||
$call DSDWORD[position];
|
||||
IF (DSBYTE[position+12]) DSDWORD[position+4] = time+DSDWORD[position+8];
|
||||
ELSE
|
||||
{
|
||||
DSDWORD[position] = 0;
|
||||
count--;
|
||||
}
|
||||
}
|
||||
i--;
|
||||
}
|
||||
position+=offsetSizeTimers;
|
||||
}
|
||||
}
|
||||
dword Timers::set(dword function, newTime, byte repeat)
|
||||
{
|
||||
dword position = 0;
|
||||
dword i = 0;
|
||||
IF (!alloc)
|
||||
{
|
||||
size = defaultMaxTimers*offsetSizeTimers;
|
||||
alloc = malloc(size);
|
||||
}
|
||||
i = count;
|
||||
position = alloc;
|
||||
WHILE(i)
|
||||
{
|
||||
IF (!DSDWORD[position]) BREAK;
|
||||
position+=offsetSizeTimers;
|
||||
i--;
|
||||
}
|
||||
count++;
|
||||
getTime();
|
||||
DSDWORD[position] = function;
|
||||
DSDWORD[position+4] = time+newTime;
|
||||
DSBYTE[position+8] = newTime;
|
||||
DSBYTE[position+12] = repeat;
|
||||
RETURN position;
|
||||
}
|
||||
dword Timers::clear(dword id)
|
||||
{
|
||||
IF (!alloc) || (!DSDWORD[id]) RETURN 0;
|
||||
count--;
|
||||
DSDWORD[id] = 0;
|
||||
RETURN id;
|
||||
}
|
||||
|
||||
// Analogs JS Functions
|
||||
:Timers Time = {0};
|
||||
inline dword setTimeout(dword function, time)
|
||||
{
|
||||
RETURN Time.set(function, time, 0);
|
||||
}
|
||||
inline dword setInterval(dword function, time)
|
||||
{
|
||||
RETURN Time.set(function, time, 1);
|
||||
}
|
||||
inline dword clearTimeout(dword id)
|
||||
{
|
||||
RETURN Time.clear(id);
|
||||
}
|
||||
inline dword clearInterval(dword id)
|
||||
{
|
||||
RETURN Time.clear(id);
|
||||
}
|
Loading…
Reference in New Issue
Block a user