aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-22 11:14:06 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-22 11:14:06 +0200
commitcd866d68cf1bf6ea928cc48a4f2b753c0b1baa6f (patch)
treef50ad0087e90e301240b6c93dcd267cbe49b282d /src/core
parent8b72e391c7185e3da0dfbf0ab60068ac37e4d5cc (diff)
downloadnissy-core-cd866d68cf1bf6ea928cc48a4f2b753c0b1baa6f.tar.gz
nissy-core-cd866d68cf1bf6ea928cc48a4f2b753c0b1baa6f.zip
Updated tests and added fixed =A to B32 output
Diffstat (limited to 'src/core')
-rw-r--r--src/core/cube.h34
1 files changed, 11 insertions, 23 deletions
diff --git a/src/core/cube.h b/src/core/cube.h
index 798c99c..a045e55 100644
--- a/src/core/cube.h
+++ b/src/core/cube.h
@@ -178,33 +178,18 @@ getcube(int64_t ep, int64_t eo, int64_t cp, int64_t co)
178 178
179/******************************************************************************/ 179/******************************************************************************/
180 180
181STATIC cube_t readcube(const char *, const char *); 181STATIC cube_t readcube(const char *);
182STATIC int64_t writecube(const char *, cube_t, size_t n, char [n]); 182STATIC int64_t writecube(cube_t, size_t n, char [n]);
183STATIC uint8_t readco(const char *); 183STATIC uint8_t readco(const char *);
184STATIC uint8_t readcp(const char *); 184STATIC uint8_t readcp(const char *);
185STATIC uint8_t readeo(const char *); 185STATIC uint8_t readeo(const char *);
186STATIC uint8_t readep(const char *); 186STATIC uint8_t readep(const char *);
187 187
188STATIC cube_t readcube_B32(const char *);
189STATIC int64_t writecube_B32(cube_t, size_t n, char [n]);
190
191STATIC uint8_t b32toedge(char); 188STATIC uint8_t b32toedge(char);
192STATIC uint8_t b32tocorner(char); 189STATIC uint8_t b32tocorner(char);
193STATIC char edgetob32(uint8_t); 190STATIC char edgetob32(uint8_t);
194STATIC char cornertob32(uint8_t); 191STATIC char cornertob32(uint8_t);
195 192
196STATIC cube_t
197readcube(const char *format, const char *buf)
198{
199 return readcube_B32(buf);
200}
201
202STATIC int64_t
203writecube(const char *format, cube_t cube, size_t buf_size, char buf[buf_size])
204{
205 return writecube_B32(cube, buf_size, buf);
206}
207
208STATIC uint8_t 193STATIC uint8_t
209readco(const char *str) 194readco(const char *str)
210{ 195{
@@ -259,7 +244,7 @@ readep(const char *str)
259} 244}
260 245
261STATIC cube_t 246STATIC cube_t
262readcube_B32(const char *buf) 247readcube(const char *buf)
263{ 248{
264 int i; 249 int i;
265 uint8_t c[8], e[12]; 250 uint8_t c[8], e[12];
@@ -267,7 +252,7 @@ readcube_B32(const char *buf)
267 for (i = 0; i < 8; i++) { 252 for (i = 0; i < 8; i++) {
268 c[i] = b32tocorner(buf[i]); 253 c[i] = b32tocorner(buf[i]);
269 if (c[i] == UINT8_ERROR) { 254 if (c[i] == UINT8_ERROR) {
270 LOG("Error reading B32 corner %d ", i); 255 LOG("Error reading corner %d ", i);
271 if (buf[i] == 0) { 256 if (buf[i] == 0) {
272 LOG("(string terminated early)\n"); 257 LOG("(string terminated early)\n");
273 } else { 258 } else {
@@ -278,7 +263,7 @@ readcube_B32(const char *buf)
278 } 263 }
279 264
280 if (buf[8] != '=') { 265 if (buf[8] != '=') {
281 LOG("Error reading B32 separator: a single '=' " 266 LOG("Error reading separator: a single '=' "
282 "must be used to separate edges and corners\n"); 267 "must be used to separate edges and corners\n");
283 return ZERO_CUBE; 268 return ZERO_CUBE;
284 } 269 }
@@ -286,7 +271,7 @@ readcube_B32(const char *buf)
286 for (i = 0; i < 12; i++) { 271 for (i = 0; i < 12; i++) {
287 e[i] = b32toedge(buf[i+9]); 272 e[i] = b32toedge(buf[i+9]);
288 if (e[i] == UINT8_ERROR) { 273 if (e[i] == UINT8_ERROR) {
289 LOG("Error reading B32 edge %d ", i); 274 LOG("Error reading edge %d ", i);
290 if (buf[i+9] == 0) { 275 if (buf[i+9] == 0) {
291 LOG("(string terminated early)\n"); 276 LOG("(string terminated early)\n");
292 } else { 277 } else {
@@ -300,7 +285,7 @@ readcube_B32(const char *buf)
300} 285}
301 286
302STATIC int64_t 287STATIC int64_t
303writecube_B32(cube_t cube, size_t buf_size, char buf[buf_size]) 288writecube(cube_t cube, size_t buf_size, char buf[buf_size])
304{ 289{
305 int i; 290 int i;
306 uint8_t corner[8], edge[12]; 291 uint8_t corner[8], edge[12];
@@ -322,7 +307,10 @@ writecube_B32(cube_t cube, size_t buf_size, char buf[buf_size])
322 for (i = 0; i < 12; i++) 307 for (i = 0; i < 12; i++)
323 buf[i+9] = edgetob32(edge[i]); 308 buf[i+9] = edgetob32(edge[i]);
324 309
325 buf[21] = '\0'; 310/* TODO */
311 buf[21] = '=';
312 buf[22] = 'A';
313 buf[23] = '\0';
326 314
327 return NISSY_OK; 315 return NISSY_OK;
328} 316}

Generated with cgit - Back to sebastiano.tronto.net