New inputs API

This commit is contained in:
Lior Halphon 2021-12-02 11:23:44 +02:00
parent b770bbea2e
commit 8660e20eeb
2 changed files with 44 additions and 0 deletions

View File

@ -91,3 +91,31 @@ void GB_set_key_state_for_player(GB_gameboy_t *gb, GB_key_t index, unsigned play
gb->keys[player][index] = pressed;
GB_update_joyp(gb);
}
void GB_set_key_mask(GB_gameboy_t *gb, GB_key_mask_t mask)
{
memset(gb->keys, 0, sizeof(gb->keys));
bool *key = &gb->keys[0][0];
while (mask) {
if (mask & 1) {
*key = true;
}
mask >>= 1;
}
GB_update_joyp(gb);
}
void GB_set_key_mask_for_player(GB_gameboy_t *gb, GB_key_mask_t mask, unsigned player)
{
memset(gb->keys[player], 0, sizeof(gb->keys[player]));
bool *key = gb->keys[player];
while (mask) {
if (mask & 1) {
*key = true;
}
mask >>= 1;
}
GB_update_joyp(gb);
}

View File

@ -15,8 +15,24 @@ typedef enum {
GB_KEY_MAX
} GB_key_t;
typedef enum {
GB_KEY_RIGHT_MASK = 1 << GB_KEY_RIGHT,
GB_KEY_LEFT_MASK = 1 << GB_KEY_LEFT,
GB_KEY_UP_MASK = 1 << GB_KEY_UP,
GB_KEY_DOWN_MASK = 1 << GB_KEY_DOWN,
GB_KEY_A_MASK = 1 << GB_KEY_A,
GB_KEY_B_MASK = 1 << GB_KEY_B,
GB_KEY_SELECT_MASK = 1 << GB_KEY_SELECT,
GB_KEY_START_MASK = 1 << GB_KEY_START,
} GB_key_mask_t;
// For example, for player 2's (0-based; logical player 3) A button, use GB_MASK_FOR_PLAYER(GB_KEY_A_MASK, 2)
#define GB_MASK_FOR_PLAYER(mask, player) ((x) << (player * 8))
void GB_set_key_state(GB_gameboy_t *gb, GB_key_t index, bool pressed);
void GB_set_key_state_for_player(GB_gameboy_t *gb, GB_key_t index, unsigned player, bool pressed);
void GB_set_key_mask(GB_gameboy_t *gb, GB_key_mask_t mask);
void GB_set_key_mask_for_player(GB_gameboy_t *gb, GB_key_mask_t mask, unsigned player);
void GB_icd_set_joyp(GB_gameboy_t *gb, uint8_t value);
#ifdef GB_INTERNAL