2020-05-29 11:37:24 +02:00
|
|
|
/* TIMERS PaulCodeman */
|
2020-05-29 15:36:50 +02:00
|
|
|
/**
|
|
|
|
void Timers::revise(void) -> This function revising all timers.
|
|
|
|
void Timers::getTime(void) -> This function updating current time for timers.
|
|
|
|
dword set(dword,dword,byte); -> This function seting timer for function Timers::revise.
|
|
|
|
dword clear(dword); -> This function clearning anything timer.
|
|
|
|
---------
|
|
|
|
The functions setTimeout,setInterval,clearInterval,clearTimeout implementing functional JavaScript.
|
|
|
|
*/
|
2020-05-29 11:37:24 +02:00
|
|
|
#define offsetSizeTimers 4*3+1
|
|
|
|
#define defaultMaxTimers 1000
|
|
|
|
:struct Timers
|
|
|
|
{
|
|
|
|
dword time;
|
|
|
|
dword alloc;
|
|
|
|
dword count;
|
|
|
|
dword size;
|
2020-05-29 15:36:50 +02:00
|
|
|
void revise(void);
|
|
|
|
void getTime(void);
|
2020-05-29 11:37:24 +02:00
|
|
|
dword set(dword,dword,byte);
|
|
|
|
dword clear(dword);
|
|
|
|
};
|
|
|
|
void Timers::getTime(void)
|
|
|
|
{
|
|
|
|
EAX = 26;
|
|
|
|
EBX = 9;
|
|
|
|
$int 0x40
|
|
|
|
time = EAX;
|
|
|
|
}
|
2020-05-29 15:36:50 +02:00
|
|
|
void Timers::revise(void)
|
2020-05-29 11:37:24 +02:00
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2020-05-29 15:36:50 +02:00
|
|
|
IF (!alloc) || (!id) || (!DSDWORD[id]) RETURN 0;
|
2020-05-29 11:37:24 +02:00
|
|
|
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);
|
|
|
|
}
|