-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.cpp
112 lines (94 loc) · 1.24 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#define BTST(a, b) (((a) & (b)) != 0)
#define BSET(a, b) ((a) |= (b))
#define BCLR(a, b) ((a) &= ~(b))
bool BTST_AND_CLR(int& a, int b)
{
auto ret = BTST(a, b);
BCLR(a, b);
return ret;
}
bool BTST_AND_SET(int& a, int b)
{
auto ret = BTST(a, b);
BSET(a, b);
return ret;
}
// bne
template<typename T>
bool TimerZero(T& timer)
{
timer--;
return timer == 0;
}
template<typename T>
bool TimerZero(T& timer, T reload)
{
timer--;
if(timer == 0)
{
timer = reload;
return true;
}
return false;
}
// bpl
template<typename T>
bool TimerNeg(T& timer)
{
timer--;
return timer < 0;
}
template<typename T>
bool TimerNeg(T& timer, T reload)
{
timer--;
if(timer < 0)
{
timer = reload;
return true;
}
return false;
}
template<typename T>
bool DecToZero(T& val)
{
if(val > 0)
val--;
return val == 0;
}
template<typename T>
bool DecTo(T& val, T limit)
{
if(val > limit)
val--;
return val == limit;
}
template<typename T>
bool IncTo(T& val, T limit)
{
if(val < limit)
val++;
return val == limit;
}
template<typename T>
T DecWrap(T& val, T max)
{
if(val == 0)
{
val = max;
return 0;
}
else
return val--;
}
template<typename T>
T IncWrap(T& val, T max)
{
if(val == max)
{
val = 0;
return max;
}
else
return val++;
}