aboutsummaryrefslogtreecommitdiff
path: root/src/io_move_trans.h
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-06-09 20:06:19 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-06-09 20:06:19 +0200
commit0b1930307f41db3ea7552d6b2f4666b33c64d26a (patch)
tree6a2558e391f5cc14fa22770cb2791e4a85d84e5e /src/io_move_trans.h
parentb218c803ae1110b08b4896be0a59177e280c9091 (diff)
downloadnissy-core-0b1930307f41db3ea7552d6b2f4666b33c64d26a.tar.gz
nissy-core-0b1930307f41db3ea7552d6b2f4666b33c64d26a.zip
More cleanup
Diffstat (limited to 'src/io_move_trans.h')
-rw-r--r--src/io_move_trans.h87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/io_move_trans.h b/src/io_move_trans.h
new file mode 100644
index 0000000..e36b8e5
--- /dev/null
+++ b/src/io_move_trans.h
@@ -0,0 +1,87 @@
1_static uint8_t readmove(char);
2_static uint8_t readmodifier(char);
3_static uint8_t readtrans(const char *);
4_static int writemoves(uint8_t *, int, char *);
5_static void writetrans(uint8_t, char *);
6
7_static uint8_t
8readmove(char c)
9{
10 switch (c) {
11 case 'U':
12 return _move_U;
13 case 'D':
14 return _move_D;
15 case 'R':
16 return _move_R;
17 case 'L':
18 return _move_L;
19 case 'F':
20 return _move_F;
21 case 'B':
22 return _move_B;
23 default:
24 return _error;
25 }
26}
27
28_static uint8_t
29readmodifier(char c)
30{
31 switch (c) {
32 case '1': /* Fallthrough */
33 case '2': /* Fallthrough */
34 case '3':
35 return c - '0' - 1;
36 case '\'':
37 return 2;
38 default:
39 return 0;
40 }
41}
42
43_static uint8_t
44readtrans(const char *buf)
45{
46 uint8_t t;
47
48 for (t = 0; t < 48; t++)
49 if (!strncmp(buf, transstr[t], 11))
50 return t;
51
52 DBG_LOG("readtrans error\n");
53 return _error;
54}
55
56_static int
57writemoves(uint8_t *m, int n, char *buf)
58{
59 int i;
60 size_t len;
61 const char *s;
62 char *b;
63
64 for (i = 0, b = buf; i < n; i++, b++) {
65 s = movestr[m[i]];
66 len = strlen(s);
67 memcpy(b, s, len);
68 b += len;
69 *b = ' ';
70 }
71
72 if (b != buf)
73 b--; /* Remove last space */
74 *b = '\0';
75
76 return b - buf;
77}
78
79_static void
80writetrans(uint8_t t, char *buf)
81{
82 if (t >= 48)
83 memcpy(buf, "error trans", 11);
84 else
85 memcpy(buf, transstr[t], 11);
86 buf[11] = '\0';
87}

Generated with cgit - Back to sebastiano.tronto.net