Skip to content

Commit

Permalink
reboot: fixes for compiler strictness around enum conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesDunne committed Nov 27, 2023
1 parent c7ff107 commit 67cdea3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
10 changes: 5 additions & 5 deletions iovm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions iovm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -291,15 +289,15 @@ 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;
} rd;
// 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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 67cdea3

Please sign in to comment.