-
Notifications
You must be signed in to change notification settings - Fork 1
/
dwordcolumn.c
280 lines (257 loc) · 7.33 KB
/
dwordcolumn.c
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#include "dwordcolumn.h"
unsigned int dwordcolumn_commit(DwordColumn *prCol) {
unsigned int value = 0;
if (prCol != NULL) {
value = prCol->value;
dwordcolumn_set_editing(prCol, 0);
}
return value;
}
int dwordcolumn_decrement(DwordColumn* prCol) {
unsigned int incr = 0;
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
unsigned int value = prCol->value;
incr = dwordcolumn_get_increment(prCol);
value -= incr;
if (value < prCol->min) {
value = prCol->min;
}
dwordcolumn_setvalue(prCol, value);
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_edit(DwordColumn* prCol, unsigned int value) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
dwordcolumn_setvalue(prCol, value);
dwordcolumn_set_editing(prCol, 1);
dwordcolumn_set_digit(prCol, 0);
return DWORDCOLUMN_SUCCESS;
}
ColorConfig* dwordcolumn_get_digitcolor(DwordColumn* prCol) {
ColorConfig* prColor = NULL;
if (prCol != NULL) {
prColor = &prCol->editdigit;
}
return prColor;
}
ColorConfig* dwordcolumn_get_displaycolor(DwordColumn *prCol) {
ColorConfig* prColor = NULL;
if (prCol != NULL) {
prColor = &prCol->color;
}
return prColor;
}
ColorConfig* dwordcolumn_get_editcolor(DwordColumn *prCol) {
ColorConfig* prColor = NULL;
if (prCol != NULL) {
prColor = &prCol->edit;
}
return prColor;
}
unsigned int dwordcolumn_get_increment(DwordColumn *prCol) {
unsigned int incr = 0;
int digit = 0;
if (prCol != NULL) {
digit = prCol->digit;
incr = prCol->increments[digit];
}
return incr;
}
int dwordcolumn_increment(DwordColumn* prCol) {
unsigned int incr = 0;
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
unsigned int value = prCol->value;
incr = dwordcolumn_get_increment(prCol);
value += incr;
if (value > prCol->max) {
value = prCol->max;
}
dwordcolumn_setvalue(prCol, value);
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_init(DwordColumn* prCol) {
ColorConfig* prColor = NULL;
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
prColor = dwordcolumn_get_displaycolor(prCol);
colorconfig_setcolor(prColor, (u32)0xFF000000, (u32)0xFFFFFFFF);
prColor = dwordcolumn_get_editcolor(prCol);
colorconfig_setcolor(prColor, (u32)0xFFFFFFFF, (u32)0xFF000000);
prColor = dwordcolumn_get_digitcolor(prCol);
colorconfig_setcolor(prColor, (u32)0xFF000000, (u32)0xFFFFFFFF);
dwordcolumn_set_digit(prCol, 0);
dwordcolumn_set_increment(prCol, 0, 0x10000000);
dwordcolumn_set_increment(prCol, 1, 0x01000000);
dwordcolumn_set_increment(prCol, 2, 0x00100000);
dwordcolumn_set_increment(prCol, 3, 0x00010000);
dwordcolumn_set_increment(prCol, 4, 0x00001000);
dwordcolumn_set_increment(prCol, 5, 0x00000100);
dwordcolumn_set_increment(prCol, 6, 0x00000010);
dwordcolumn_set_increment(prCol, 7, 0x00000001);
dwordcolumn_set_editing(prCol, 0);
dwordcolumn_set_max(prCol, 0xFFFFFFFF);
dwordcolumn_set_min(prCol, 0x00000000);
dwordcolumn_set_prefixed(prCol, 1);
dwordcolumn_setvalue(prCol, prCol->min);
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_invalidate(DwordColumn* prCol) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
prCol->dirty = 1;
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_is_editing(DwordColumn* prCol) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
return (prCol->inedit != 0);
}
int dwordcolumn_is_prefixed(DwordColumn* prCol) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
return (prCol->prefix != 0);
}
int dwordcolumn_nextdigit(DwordColumn* prCol) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
int digit = prCol->digit;
digit++;
if (digit > 7) {
digit = 7;
}
dwordcolumn_set_digit(prCol, digit);
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_prevdigit(DwordColumn* prCol) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
int digit = prCol->digit;
digit--;
if (digit < 0) {
digit = 0;
}
dwordcolumn_set_digit(prCol, digit);
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_redraw(DwordColumn* prCol) {
char buf[11];
int i = 0;
int pc = 0;
int di = 0;
u32 bg = 0;
u32 fg = 0;
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
if (prCol->dirty == 0) {
return DWORDCOLUMN_SUCCESS;
}
if (prCol->prefix == 1) {
sprintf(buf, "0x%08X", prCol->value);
pc = 2;
} else {
sprintf(buf, "%08X", prCol->value);
}
if (!dwordcolumn_is_editing(prCol)) {
pspDebugScreenSetBackColor(prCol->color.background);
pspDebugScreenSetTextColor(prCol->color.text);
pspDebugScreenPuts(buf);
prCol->dirty = 0;
return DWORDCOLUMN_SUCCESS;
}
if (dwordcolumn_is_prefixed(prCol)) {
pspDebugScreenSetBackColor(prCol->edit.background);
pspDebugScreenSetTextColor(prCol->edit.text);
pspDebugScreenPuts("0x");
}
for (i = 0; i < 8; i++) {
di = i + pc;
bg = prCol->edit.background;
fg = prCol->edit.text;
if (prCol->digit == i) {
bg = prCol->editdigit.background;
fg = prCol->editdigit.text;
}
pspDebugScreenSetBackColor(bg);
pspDebugScreenSetTextColor(fg);
pspDebugScreenKprintf("%c", buf[di]);
}
prCol->dirty = 0;
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_set_digit(DwordColumn* prCol, int digit) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
if ((digit < 0) || (digit > 7)) {
return DWORDCOLUMN_FAILURE;
}
prCol->digit = digit;
dwordcolumn_invalidate(prCol);
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_set_editing(DwordColumn* prCol, int editing) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
prCol->inedit = (editing != 0);
dwordcolumn_invalidate(prCol);
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_set_increment(DwordColumn* prCol, int digit,
unsigned int amount) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
if ((digit < 0) || (digit > 7)) {
return DWORDCOLUMN_FAILURE;
}
prCol->increments[digit] = amount;
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_set_max(DwordColumn* prCol, unsigned int max) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
prCol->max = max & 0xFFFFFFFF;
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_set_min(DwordColumn* prCol, unsigned int min) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
prCol->min = min & 0xFFFFFFFF;
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_set_prefixed(DwordColumn* prCol, int prefixed) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
prCol->prefix = (prefixed != 0);
dwordcolumn_invalidate(prCol);
return DWORDCOLUMN_SUCCESS;
}
int dwordcolumn_setvalue(DwordColumn* prCol, unsigned int value) {
if (prCol == NULL) {
return DWORDCOLUMN_NULLPTR;
}
if ((value < prCol->min) || (value > prCol->max)) {
return DWORDCOLUMN_FAILURE;
}
if (value != prCol->value) {
prCol->value = value;
dwordcolumn_invalidate(prCol);
}
return DWORDCOLUMN_SUCCESS;
}