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;
|
2020-06-25 12:18:33 +02:00
|
|
|
dword alloc;
|
|
|
|
dword count;
|
|
|
|
dword size;
|
|
|
|
void revise(void);
|
|
|
|
void getTime(void);
|
|
|
|
dword set(dword,dword,byte);
|
|
|
|
dword clear(dword);
|
2020-05-29 11:37:24 +02:00
|
|
|
};
|
|
|
|
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
|
2020-06-25 12:18:33 +02:00
|
|
|
:Timers Timer = {0};
|
2020-05-29 11:37:24 +02:00
|
|
|
inline dword setTimeout(dword function, time)
|
|
|
|
{
|
2020-06-25 12:18:33 +02:00
|
|
|
RETURN Timer.set(function, time, 0);
|
2020-05-29 11:37:24 +02:00
|
|
|
}
|
|
|
|
inline dword setInterval(dword function, time)
|
|
|
|
{
|
2020-06-25 12:18:33 +02:00
|
|
|
RETURN Timer.set(function, time, 1);
|
2020-05-29 11:37:24 +02:00
|
|
|
}
|
|
|
|
inline dword clearTimeout(dword id)
|
|
|
|
{
|
2020-06-25 12:18:33 +02:00
|
|
|
RETURN Timer.clear(id);
|
2020-05-29 11:37:24 +02:00
|
|
|
}
|
|
|
|
inline dword clearInterval(dword id)
|
|
|
|
{
|
2020-06-25 12:18:33 +02:00
|
|
|
RETURN Timer.clear(id);
|
2020-05-29 11:37:24 +02:00
|
|
|
}
|