From 67cdea3bb20161c9c0dd80ad208b5b62936caaae Mon Sep 17 00:00:00 2001 From: jsd1982 Date: Sun, 26 Nov 2023 19:07:26 -0600 Subject: [PATCH] reboot: fixes for compiler strictness around enum conversion --- iovm.c | 10 +++++----- iovm.h | 12 +++++------- test.c | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/iovm.c b/iovm.c index e663784..9b84f6a 100644 --- a/iovm.c +++ b/iovm.c @@ -61,7 +61,7 @@ enum iovm1_error iovm1_exec_reset(struct iovm1_t *vm) { return IOVM1_SUCCESS; } -enum iovm1_error host_memory_try_read_byte(struct iovm1_t *vn, iovm1_memory_chip_t c, uint24_t a, uint8_t *b); +enum iovm1_error host_memory_try_read_byte(struct iovm1_t *vn, enum iovm1_memory_chip c, uint24_t a, uint8_t *b); // executes the next IOVM instruction enum iovm1_error iovm1_exec(struct iovm1_t *vm) { @@ -172,7 +172,7 @@ enum iovm1_error iovm1_exec(struct iovm1_t *vm) { vm->next_off = vm->m.off + 5; // memory chip identifier: - vm->rd.c = vm->m.ptr[vm->m.off++]; + vm->rd.c = (enum iovm1_memory_chip)vm->m.ptr[vm->m.off++]; // 24-bit address: uint24_t lo = (uint24_t)(vm->m.ptr[vm->m.off++]); uint24_t hi = (uint24_t)(vm->m.ptr[vm->m.off++]) << 8; @@ -193,7 +193,7 @@ enum iovm1_error iovm1_exec(struct iovm1_t *vm) { vm->next_off = vm->m.off + 5; // memory chip identifier: - vm->wr.c = vm->m.ptr[vm->m.off++]; + vm->wr.c = (enum iovm1_memory_chip)vm->m.ptr[vm->m.off++]; // 24-bit address: uint24_t lo = (uint24_t)(vm->m.ptr[vm->m.off++]); uint24_t hi = (uint24_t)(vm->m.ptr[vm->m.off++]) << 8; @@ -220,7 +220,7 @@ enum iovm1_error iovm1_exec(struct iovm1_t *vm) { vm->wa.q = IOVM1_INST_CMP_OPERATOR(x); // memory chip identifier: - vm->wa.c = vm->m.ptr[vm->m.off++]; + vm->wa.c = (enum iovm1_memory_chip)vm->m.ptr[vm->m.off++]; // 24-bit address: uint24_t lo = (uint24_t)(vm->m.ptr[vm->m.off++]); uint24_t hi = (uint24_t)(vm->m.ptr[vm->m.off++]) << 8; @@ -243,7 +243,7 @@ enum iovm1_error iovm1_exec(struct iovm1_t *vm) { enum iovm1_cmp_operator q = IOVM1_INST_CMP_OPERATOR(x); // memory chip identifier: - iovm1_memory_chip_t c = vm->m.ptr[vm->m.off++]; + enum iovm1_memory_chip c = (enum iovm1_memory_chip)vm->m.ptr[vm->m.off++]; // 24-bit address: uint24_t lo = (uint24_t)(vm->m.ptr[vm->m.off++]); uint24_t hi = (uint24_t)(vm->m.ptr[vm->m.off++]) << 8; diff --git a/iovm.h b/iovm.h index bd3e0ee..7b7603f 100644 --- a/iovm.h +++ b/iovm.h @@ -209,8 +209,6 @@ enum iovm1_memory_chip { MEM_SNES_SRAM, }; -typedef enum iovm1_memory_chip iovm1_memory_chip_t; - enum iovm1_state { IOVM1_STATE_INIT, IOVM1_STATE_LOADED, @@ -261,7 +259,7 @@ extern enum iovm1_error host_memory_write_state_machine(struct iovm1_t *vm); extern enum iovm1_error host_memory_wait_state_machine(struct iovm1_t *vm); // try to read a byte from a memory chip, return byte in `*b` if successful -extern enum iovm1_error host_memory_try_read_byte(struct iovm1_t *vm, iovm1_memory_chip_t c, uint24_t a, uint8_t *b); +extern enum iovm1_error host_memory_try_read_byte(struct iovm1_t *vm, enum iovm1_memory_chip c, uint24_t a, uint8_t *b); // send a program-end message to the client extern void host_send_end(struct iovm1_t *vm); @@ -291,7 +289,7 @@ struct iovm1_t { // read struct { enum iovm1_opstate os; - iovm1_memory_chip_t c; + enum iovm1_memory_chip c; uint24_t a; uint8_t l_raw; int l; @@ -299,7 +297,7 @@ struct iovm1_t { // write struct { enum iovm1_opstate os; - iovm1_memory_chip_t c; + enum iovm1_memory_chip c; uint24_t a; uint8_t l_raw; int l; @@ -309,7 +307,7 @@ struct iovm1_t { // wait struct { enum iovm1_opstate os; - iovm1_memory_chip_t c; + enum iovm1_memory_chip c; uint24_t a; uint8_t v; uint8_t k; @@ -351,7 +349,7 @@ static inline bool iovm1_memory_cmp(enum iovm1_cmp_operator q, uint8_t a, uint8_ // tests the read byte `b` with the current wait operation's comparison function and bit mask static inline bool iovm1_memory_wait_test_byte(struct iovm1_t *vm, uint8_t a) { - return iovm1_memory_cmp(vm->wa.q & 7, a & vm->wa.k, vm->wa.v); + return iovm1_memory_cmp(vm->wa.q, a & vm->wa.k, vm->wa.v); } #ifdef __cplusplus diff --git a/test.c b/test.c index c62d8b2..7969478 100644 --- a/test.c +++ b/test.c @@ -18,7 +18,7 @@ int tests_failed = 0; /////////////////////////////////////////////////////////////////////////////////////////// struct fake { - iovm1_memory_chip_t c; + enum iovm1_memory_chip c; uint24_t a; uint8_t l; @@ -39,7 +39,7 @@ void fake_init_test(struct iovm1_t *vm) { // host interface implementation: // initialize memory controller to point at specific memory chip and a starting address within it -enum iovm1_error host_memory_init(struct iovm1_t *vm, iovm1_memory_chip_t c, uint24_t a) { +enum iovm1_error host_memory_init(struct iovm1_t *vm, enum iovm1_memory_chip c, uint24_t a) { fake_host.c = c; fake_host.a = a; return IOVM1_SUCCESS;