Rev 7997 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7997 | Rev 8000 | ||
---|---|---|---|
1 | /* TIMERS PaulCodeman */ |
1 | /* TIMERS PaulCodeman */ |
- | 2 | /** |
|
- | 3 | void Timers::revise(void) -> This function revising all timers. |
|
- | 4 | void Timers::getTime(void) -> This function updating current time for timers. |
|
- | 5 | dword set(dword,dword,byte); -> This function seting timer for function Timers::revise. |
|
- | 6 | dword clear(dword); -> This function clearning anything timer. |
|
- | 7 | --------- |
|
- | 8 | The functions setTimeout,setInterval,clearInterval,clearTimeout implementing functional JavaScript. |
|
2 | 9 | */ |
|
3 | #define offsetSizeTimers 4*3+1 |
10 | #define offsetSizeTimers 4*3+1 |
4 | #define defaultMaxTimers 1000 |
11 | #define defaultMaxTimers 1000 |
5 | :struct Timers |
12 | :struct Timers |
6 | { |
13 | { |
7 | dword time; |
14 | dword time; |
8 | dword alloc; |
15 | dword alloc; |
9 | dword count; |
16 | dword count; |
10 | dword size; |
17 | dword size; |
11 | void watch(void); |
18 | void revise(void); |
12 | void getTime(); |
19 | void getTime(void); |
13 | dword set(dword,dword,byte); |
20 | dword set(dword,dword,byte); |
14 | dword clear(dword); |
21 | dword clear(dword); |
15 | }; |
22 | }; |
16 | void Timers::getTime(void) |
23 | void Timers::getTime(void) |
17 | { |
24 | { |
18 | EAX = 26; |
25 | EAX = 26; |
19 | EBX = 9; |
26 | EBX = 9; |
20 | $int 0x40 |
27 | $int 0x40 |
21 | time = EAX; |
28 | time = EAX; |
22 | } |
29 | } |
23 | void Timers::watch(void) |
30 | void Timers::revise(void) |
24 | { |
31 | { |
25 | dword position = 0; |
32 | dword position = 0; |
26 | dword i = 0; |
33 | dword i = 0; |
27 | IF (!alloc) RETURN; |
34 | IF (!alloc) RETURN; |
28 | getTime(); |
35 | getTime(); |
29 | i = count; |
36 | i = count; |
30 | position = alloc; |
37 | position = alloc; |
31 | WHILE(i) |
38 | WHILE(i) |
32 | { |
39 | { |
33 | IF (DSDWORD[position]) |
40 | IF (DSDWORD[position]) |
34 | { |
41 | { |
35 | IF (DSDWORD[position+4]<=time) |
42 | IF (DSDWORD[position+4]<=time) |
36 | { |
43 | { |
37 | $call DSDWORD[position]; |
44 | $call DSDWORD[position]; |
38 | IF (DSBYTE[position+12]) DSDWORD[position+4] = time+DSDWORD[position+8]; |
45 | IF (DSBYTE[position+12]) DSDWORD[position+4] = time+DSDWORD[position+8]; |
39 | ELSE |
46 | ELSE |
40 | { |
47 | { |
41 | DSDWORD[position] = 0; |
48 | DSDWORD[position] = 0; |
42 | count--; |
49 | count--; |
43 | } |
50 | } |
44 | } |
51 | } |
45 | i--; |
52 | i--; |
46 | } |
53 | } |
47 | position+=offsetSizeTimers; |
54 | position+=offsetSizeTimers; |
48 | } |
55 | } |
49 | } |
56 | } |
50 | dword Timers::set(dword function, newTime, byte repeat) |
57 | dword Timers::set(dword function, newTime, byte repeat) |
51 | { |
58 | { |
52 | dword position = 0; |
59 | dword position = 0; |
53 | dword i = 0; |
60 | dword i = 0; |
54 | IF (!alloc) |
61 | IF (!alloc) |
55 | { |
62 | { |
56 | size = defaultMaxTimers*offsetSizeTimers; |
63 | size = defaultMaxTimers*offsetSizeTimers; |
57 | alloc = malloc(size); |
64 | alloc = malloc(size); |
58 | } |
65 | } |
59 | i = count; |
66 | i = count; |
60 | position = alloc; |
67 | position = alloc; |
61 | WHILE(i) |
68 | WHILE(i) |
62 | { |
69 | { |
63 | IF (!DSDWORD[position]) BREAK; |
70 | IF (!DSDWORD[position]) BREAK; |
64 | position+=offsetSizeTimers; |
71 | position+=offsetSizeTimers; |
65 | i--; |
72 | i--; |
66 | } |
73 | } |
67 | count++; |
74 | count++; |
68 | getTime(); |
75 | getTime(); |
69 | DSDWORD[position] = function; |
76 | DSDWORD[position] = function; |
70 | DSDWORD[position+4] = time+newTime; |
77 | DSDWORD[position+4] = time+newTime; |
71 | DSBYTE[position+8] = newTime; |
78 | DSBYTE[position+8] = newTime; |
72 | DSBYTE[position+12] = repeat; |
79 | DSBYTE[position+12] = repeat; |
73 | RETURN position; |
80 | RETURN position; |
74 | } |
81 | } |
75 | dword Timers::clear(dword id) |
82 | dword Timers::clear(dword id) |
76 | { |
83 | { |
77 | IF (!alloc) || (!DSDWORD[id]) RETURN 0; |
84 | IF (!alloc) || (!id) || (!DSDWORD[id]) RETURN 0; |
78 | count--; |
85 | count--; |
79 | DSDWORD[id] = 0; |
86 | DSDWORD[id] = 0; |
80 | RETURN id; |
87 | RETURN id; |
81 | } |
88 | } |
82 | 89 | ||
83 | // Analogs JS Functions |
90 | // Analogs JS Functions |
84 | :Timers Time = {0}; |
91 | :Timers Time = {0}; |
85 | inline dword setTimeout(dword function, time) |
92 | inline dword setTimeout(dword function, time) |
86 | { |
93 | { |
87 | RETURN Time.set(function, time, 0); |
94 | RETURN Time.set(function, time, 0); |
88 | } |
95 | } |
89 | inline dword setInterval(dword function, time) |
96 | inline dword setInterval(dword function, time) |
90 | { |
97 | { |
91 | RETURN Time.set(function, time, 1); |
98 | RETURN Time.set(function, time, 1); |
92 | } |
99 | } |
93 | inline dword clearTimeout(dword id) |
100 | inline dword clearTimeout(dword id) |
94 | { |
101 | { |
95 | RETURN Time.clear(id); |
102 | RETURN Time.clear(id); |
96 | } |
103 | } |
97 | inline dword clearInterval(dword id) |
104 | inline dword clearInterval(dword id) |
98 | { |
105 | { |
99 | RETURN Time.clear(id); |
106 | RETURN Time.clear(id); |
100 | }=time) |
107 | }=time) |
101 | > |
108 | > |