diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-08-18 14:26:45 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-08-18 14:26:45 +0200 |
| commit | 18c9a8b8905304cf5f8fc15825769046a3144866 (patch) | |
| tree | a7807bb32b0a5d9ded7d3cedccc598f64a9b00fe /src/core/io_moves.h | |
| parent | f25a10e19eca294c4e6a99e4f80ce5cfd11a0e5f (diff) | |
| download | nissy-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.h | 62 |
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 | ||
| 6 | readmove(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 | ||
| 27 | readmodifier(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 | ||
| 42 | writemoves(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 | } | ||
