diff options
Diffstat (limited to 'yhtz.c')
| -rw-r--r-- | yhtz.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -20,9 +20,10 @@ typedef struct { uint16_t seed; } yhtz_state; +/* Note: all macros take in a yhtz_state* as input 's' */ /* ROLLS */ -#define GET_ROLL(s) ((uint8_t)((s & 0xC0) >> 6)) /* top 2 bits */ -#define SET_ROLL(s, x) (s & 0x3F | ((uint8_t)x << 6)) +#define GET_ROLL(s) ((uint8_t)((s->topflag_w_roll & 0xC0) >> 6)) /* top 2 bits */ +#define SET_ROLL(s, x) (s->topflag_w_roll = (s->topflag_w_roll & 0x3F | ((uint8_t)x << 6))) /* TOP NUMBERS */ #define GET_NUM(s, x) ((uint8_t)((s & (1 << x)) >> x)) @@ -113,7 +114,7 @@ void ask_for_rerolls(yhtz_state* state) { } void do_turn(yhtz_state* state) { - int roll = GET_ROLL(state->topflag_w_roll); + int roll = GET_ROLL(state); bool reset = false; // if we're out of rolls, reset @@ -127,7 +128,7 @@ void do_turn(yhtz_state* state) { state->dice = SET_D(state->dice, i, roll_die(&(state->seed))); } } - state->topflag_w_roll = SET_ROLL(state->topflag_w_roll, ++roll); + SET_ROLL(state, ++roll); } void init_yhtz_state(yhtz_state* state) { @@ -155,7 +156,7 @@ void main() { do_turn(&y); - printf("new roll: %d\n", GET_ROLL(y.topflag_w_roll)); + printf("new roll: %d\n", GET_ROLL((&y))); printf("new d1: %d\n", GET_D0(y.dice)); printf("new d2: %d\n", GET_D1(y.dice)); printf("new d3: %d\n", GET_D2(y.dice)); @@ -166,7 +167,7 @@ void main() { ask_for_rerolls(&y); do_turn(&y); - printf("newer roll: %d\n", GET_ROLL(y.topflag_w_roll)); + printf("newer roll: %d\n", GET_ROLL((&y))); printf("newer d1: %d\n", GET_D0(y.dice)); printf("newer d2: %d\n", GET_D1(y.dice)); printf("newer d3: %d\n", GET_D2(y.dice)); |
