aboutsummaryrefslogtreecommitdiff
path: root/src/core/io_moves.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-08-18 14:26:45 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-08-18 14:26:45 +0200
commit18c9a8b8905304cf5f8fc15825769046a3144866 (patch)
treea7807bb32b0a5d9ded7d3cedccc598f64a9b00fe /src/core/io_moves.h
parentf25a10e19eca294c4e6a99e4f80ce5cfd11a0e5f (diff)
downloadnissy-core-18c9a8b8905304cf5f8fc15825769046a3144866.tar.gz
nissy-core-18c9a8b8905304cf5f8fc15825769046a3144866.zip
Reorganized folder structure
Diffstat (limited to 'src/core/io_moves.h')
-rw-r--r--src/core/io_moves.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/core/io_moves.h b/src/core/io_moves.h
new file mode 100644
index 0000000..eb6290e
--- /dev/null
+++ b/src/core/io_moves.h
@@ -0,0 +1,62 @@
1_static uint8_t readmove(char);
2_static uint8_t readmodifier(char);
3_static int writemoves(uint8_t *, int, char *);
4
5_static uint8_t
6readmove(char c)
7{
8 switch (c) {
9 case 'U':
10 return _move_U;
11 case 'D':
12 return _move_D;
13 case 'R':
14 return _move_R;
15 case 'L':
16 return _move_L;
17 case 'F':
18 return _move_F;
19 case 'B':
20 return _move_B;
21 default:
22 return _error;
23 }
24}
25
26_static uint8_t
27readmodifier(char c)
28{
29 switch (c) {
30 case '1': /* Fallthrough */
31 case '2': /* Fallthrough */
32 case '3':
33 return c - '0' - 1;
34 case '\'':
35 return 2;
36 default:
37 return 0;
38 }
39}
40
41_static int
42writemoves(uint8_t *m, int n, char *buf)
43{
44 int i;
45 size_t len;
46 const char *s;
47 char *b;
48
49 for (i = 0, b = buf; i < n; i++, b++) {
50 s = movestr[m[i]];
51 len = strlen(s);
52 memcpy(b, s, len);
53 b += len;
54 *b = ' ';
55 }
56
57 if (b != buf)
58 b--; /* Remove last space */
59 *b = '\0';
60
61 return b - buf;
62}

Generated with cgit - Back to sebastiano.tronto.net