aboutsummaryrefslogtreecommitdiff
path: root/src/core/io_cube.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-09-05 08:53:38 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-09-05 08:55:25 +0200
commitfd5ddb3db9f50411ca579d84f225f265ca35b56a (patch)
treeb659112cc0e2abd6c7edb08b0938c0d2de4ca066 /src/core/io_cube.h
parentc9e2d6466e42d6b779ac9ffa7c5ee9a9c7558df8 (diff)
downloadnissy-core-fd5ddb3db9f50411ca579d84f225f265ca35b56a.tar.gz
nissy-core-fd5ddb3db9f50411ca579d84f225f265ca35b56a.zip
Rename constants from _underscore to CAPS
Diffstat (limited to 'src/core/io_cube.h')
-rw-r--r--src/core/io_cube.h98
1 files changed, 49 insertions, 49 deletions
diff --git a/src/core/io_cube.h b/src/core/io_cube.h
index 956494d..cb0e4c7 100644
--- a/src/core/io_cube.h
+++ b/src/core/io_cube.h
@@ -1,23 +1,23 @@
1_static uint8_t readco(const char *); 1STATIC uint8_t readco(const char *);
2_static uint8_t readcp(const char *); 2STATIC uint8_t readcp(const char *);
3_static uint8_t readeo(const char *); 3STATIC uint8_t readeo(const char *);
4_static uint8_t readep(const char *); 4STATIC uint8_t readep(const char *);
5_static cube_t readcube_B32(const char *); 5STATIC cube_t readcube_B32(const char *);
6_static cube_t readcube_H48(const char *); 6STATIC cube_t readcube_H48(const char *);
7_static uint8_t readpiece_LST(const char **); 7STATIC uint8_t readpiece_LST(const char **);
8_static cube_t readcube_LST(const char *); 8STATIC cube_t readcube_LST(const char *);
9 9
10_static int writepiece_LST(uint8_t, char *); 10STATIC int writepiece_LST(uint8_t, char *);
11_static void writecube_B32(cube_t, char *); 11STATIC void writecube_B32(cube_t, char *);
12_static void writecube_H48(cube_t, char *); 12STATIC void writecube_H48(cube_t, char *);
13_static void writecube_LST(cube_t, char *); 13STATIC void writecube_LST(cube_t, char *);
14 14
15_static uint8_t b32toedge(char); 15STATIC uint8_t b32toedge(char);
16_static uint8_t b32tocorner(char); 16STATIC uint8_t b32tocorner(char);
17_static char edgetob32(uint8_t); 17STATIC char edgetob32(uint8_t);
18_static char cornertob32(uint8_t); 18STATIC char cornertob32(uint8_t);
19 19
20_static struct { 20STATIC struct {
21 const char *name; 21 const char *name;
22 cube_t (*read)(const char *); 22 cube_t (*read)(const char *);
23 void (*write)(cube_t, char *); 23 void (*write)(cube_t, char *);
@@ -72,21 +72,21 @@ writecube_error:
72 buf[len+1] = '\0'; 72 buf[len+1] = '\0';
73} 73}
74 74
75_static uint8_t 75STATIC uint8_t
76readco(const char *str) 76readco(const char *str)
77{ 77{
78 if (*str == '0') 78 if (*str == '0')
79 return 0; 79 return 0;
80 if (*str == '1') 80 if (*str == '1')
81 return _ctwist_cw; 81 return CTWIST_CW;
82 if (*str == '2') 82 if (*str == '2')
83 return _ctwist_ccw; 83 return CTWIST_CCW;
84 84
85 LOG("Error reading CO\n"); 85 LOG("Error reading CO\n");
86 return _error; 86 return UINT8_ERROR;
87} 87}
88 88
89_static uint8_t 89STATIC uint8_t
90readcp(const char *str) 90readcp(const char *str)
91{ 91{
92 uint8_t c; 92 uint8_t c;
@@ -97,22 +97,22 @@ readcp(const char *str)
97 return c; 97 return c;
98 98
99 LOG("Error reading CP\n"); 99 LOG("Error reading CP\n");
100 return _error; 100 return UINT8_ERROR;
101} 101}
102 102
103_static uint8_t 103STATIC uint8_t
104readeo(const char *str) 104readeo(const char *str)
105{ 105{
106 if (*str == '0') 106 if (*str == '0')
107 return 0; 107 return 0;
108 if (*str == '1') 108 if (*str == '1')
109 return _eflip; 109 return EFLIP;
110 110
111 LOG("Error reading EO\n"); 111 LOG("Error reading EO\n");
112 return _error; 112 return UINT8_ERROR;
113} 113}
114 114
115_static uint8_t 115STATIC uint8_t
116readep(const char *str) 116readep(const char *str)
117{ 117{
118 uint8_t e; 118 uint8_t e;
@@ -122,10 +122,10 @@ readep(const char *str)
122 return e; 122 return e;
123 123
124 LOG("Error reading EP\n"); 124 LOG("Error reading EP\n");
125 return _error; 125 return UINT8_ERROR;
126} 126}
127 127
128_static cube_t 128STATIC cube_t
129readcube_B32(const char *buf) 129readcube_B32(const char *buf)
130{ 130{
131 int i; 131 int i;
@@ -146,7 +146,7 @@ readcube_B32(const char *buf)
146 return cubefromarray(c, e); 146 return cubefromarray(c, e);
147} 147}
148 148
149_static cube_t 149STATIC cube_t
150readcube_H48(const char *buf) 150readcube_H48(const char *buf)
151{ 151{
152 int i; 152 int i;
@@ -158,10 +158,10 @@ readcube_H48(const char *buf)
158 for (i = 0; i < 12; i++) { 158 for (i = 0; i < 12; i++) {
159 while (*b == ' ' || *b == '\t' || *b == '\n') 159 while (*b == ' ' || *b == '\t' || *b == '\n')
160 b++; 160 b++;
161 if ((piece = readep(b)) == _error) 161 if ((piece = readep(b)) == UINT8_ERROR)
162 return zero; 162 return zero;
163 b += 2; 163 b += 2;
164 if ((orient = readeo(b)) == _error) 164 if ((orient = readeo(b)) == UINT8_ERROR)
165 return zero; 165 return zero;
166 b++; 166 b++;
167 e[i] = piece | orient; 167 e[i] = piece | orient;
@@ -169,10 +169,10 @@ readcube_H48(const char *buf)
169 for (i = 0; i < 8; i++) { 169 for (i = 0; i < 8; i++) {
170 while (*b == ' ' || *b == '\t' || *b == '\n') 170 while (*b == ' ' || *b == '\t' || *b == '\n')
171 b++; 171 b++;
172 if ((piece = readcp(b)) == _error) 172 if ((piece = readcp(b)) == UINT8_ERROR)
173 return zero; 173 return zero;
174 b += 3; 174 b += 3;
175 if ((orient = readco(b)) == _error) 175 if ((orient = readco(b)) == UINT8_ERROR)
176 return zero; 176 return zero;
177 b++; 177 b++;
178 c[i] = piece | orient; 178 c[i] = piece | orient;
@@ -181,7 +181,7 @@ readcube_H48(const char *buf)
181 return cubefromarray(c, e); 181 return cubefromarray(c, e);
182} 182}
183 183
184_static uint8_t 184STATIC uint8_t
185readpiece_LST(const char **b) 185readpiece_LST(const char **b)
186{ 186{
187 uint8_t ret; 187 uint8_t ret;
@@ -195,10 +195,10 @@ readpiece_LST(const char **b)
195 ret = ret * 10 + (**b) - '0'; 195 ret = ret * 10 + (**b) - '0';
196 } 196 }
197 197
198 return read ? ret : _error; 198 return read ? ret : UINT8_ERROR;
199} 199}
200 200
201_static cube_t 201STATIC cube_t
202readcube_LST(const char *buf) 202readcube_LST(const char *buf)
203{ 203{
204 int i; 204 int i;
@@ -213,7 +213,7 @@ readcube_LST(const char *buf)
213 return cubefromarray(c, e); 213 return cubefromarray(c, e);
214} 214}
215 215
216_static int 216STATIC int
217writepiece_LST(uint8_t piece, char *buf) 217writepiece_LST(uint8_t piece, char *buf)
218{ 218{
219 char digits[3]; 219 char digits[3];
@@ -237,7 +237,7 @@ writepiece_LST(uint8_t piece, char *buf)
237 return len+2; 237 return len+2;
238} 238}
239 239
240_static void 240STATIC void
241writecube_B32(cube_t cube, char *buf) 241writecube_B32(cube_t cube, char *buf)
242{ 242{
243 int i; 243 int i;
@@ -256,7 +256,7 @@ writecube_B32(cube_t cube, char *buf)
256 buf[21] = '\0'; 256 buf[21] = '\0';
257} 257}
258 258
259_static void 259STATIC void
260writecube_H48(cube_t cube, char *buf) 260writecube_H48(cube_t cube, char *buf)
261{ 261{
262 uint8_t piece, perm, orient, corner[8], edge[12]; 262 uint8_t piece, perm, orient, corner[8], edge[12];
@@ -266,8 +266,8 @@ writecube_H48(cube_t cube, char *buf)
266 266
267 for (i = 0; i < 12; i++) { 267 for (i = 0; i < 12; i++) {
268 piece = edge[i]; 268 piece = edge[i];
269 perm = piece & _pbits; 269 perm = piece & PBITS;
270 orient = (piece & _eobit) >> _eoshift; 270 orient = (piece & EOBIT) >> EOSHIFT;
271 buf[4*i ] = edgestr[perm][0]; 271 buf[4*i ] = edgestr[perm][0];
272 buf[4*i + 1] = edgestr[perm][1]; 272 buf[4*i + 1] = edgestr[perm][1];
273 buf[4*i + 2] = orient + '0'; 273 buf[4*i + 2] = orient + '0';
@@ -275,8 +275,8 @@ writecube_H48(cube_t cube, char *buf)
275 } 275 }
276 for (i = 0; i < 8; i++) { 276 for (i = 0; i < 8; i++) {
277 piece = corner[i]; 277 piece = corner[i];
278 perm = piece & _pbits; 278 perm = piece & PBITS;
279 orient = (piece & _cobits) >> _coshift; 279 orient = (piece & COBITS) >> COSHIFT;
280 buf[48 + 5*i ] = cornerstr[perm][0]; 280 buf[48 + 5*i ] = cornerstr[perm][0];
281 buf[48 + 5*i + 1] = cornerstr[perm][1]; 281 buf[48 + 5*i + 1] = cornerstr[perm][1];
282 buf[48 + 5*i + 2] = cornerstr[perm][2]; 282 buf[48 + 5*i + 2] = cornerstr[perm][2];
@@ -287,7 +287,7 @@ writecube_H48(cube_t cube, char *buf)
287 buf[48+39] = '\0'; 287 buf[48+39] = '\0';
288} 288}
289 289
290_static void 290STATIC void
291writecube_LST(cube_t cube, char *buf) 291writecube_LST(cube_t cube, char *buf)
292{ 292{
293 int i; 293 int i;
@@ -310,7 +310,7 @@ writecube_LST(cube_t cube, char *buf)
310 *(buf+ptr-2) = 0; 310 *(buf+ptr-2) = 0;
311} 311}
312 312
313_static uint8_t 313STATIC uint8_t
314b32toedge(char c) 314b32toedge(char c)
315{ 315{
316 if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f'))) 316 if (!((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'f')))
@@ -319,7 +319,7 @@ b32toedge(char c)
319 return c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26; 319 return c <= 'Z' ? (uint8_t)(c - 'A') : (uint8_t)(c - 'a') + 26;
320} 320}
321 321
322_static uint8_t 322STATIC uint8_t
323b32tocorner(char c) { 323b32tocorner(char c) {
324 uint8_t val; 324 uint8_t val;
325 325
@@ -331,13 +331,13 @@ b32tocorner(char c) {
331 return (val & 7) | ((val & 24) << 2); 331 return (val & 7) | ((val & 24) << 2);
332} 332}
333 333
334_static char 334STATIC char
335edgetob32(uint8_t edge) 335edgetob32(uint8_t edge)
336{ 336{
337 return edge < 26 ? 'A' + (char)edge : 'a' + (char)(edge - 26); 337 return edge < 26 ? 'A' + (char)edge : 'a' + (char)(edge - 26);
338} 338}
339 339
340_static char 340STATIC char
341cornertob32(uint8_t corner) 341cornertob32(uint8_t corner)
342{ 342{
343 uint8_t val; 343 uint8_t val;

Generated with cgit - Back to sebastiano.tronto.net