-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.c
73 lines (65 loc) · 2.25 KB
/
state.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "state.h"
#include "global.h"
#include <string.h>
RootState rootState;
/**
* Sets up initial configuration for N64 - Gameboy button map.
* @out buttonMap map of N64 to Gameboy buttons.
* @private
*/
static void initialiseButtonMap(GbButton* map) {
GbButton buttons[N64_BUTTON_COUNT];
memset(buttons, 0x00, sizeof(GbButton) * N64_BUTTON_COUNT);
buttons[NoButton] = GbNoButton;
buttons[A] = GbA;
buttons[B] = GbB;
buttons[Up] = GbUp;
buttons[Down] = GbDown;
buttons[Left] = GbLeft;
buttons[Right] = GbRight;
// Start, Select and SystemMenu should be configurable
buttons[Start] = GbStart;
buttons[R] = GbSelect;
buttons[L] = GbSystemMenu;
memcpy(map, &buttons, sizeof(GbButton) * N64_BUTTON_COUNT);
}
/**
* Sets a Gameboy button to a particular N64 button, unsetting it from the previous mapping.
* @param playerState state containing controller mapping to update.
* @param gbButton gameboy button to set.
* @param n64Button n64 button to set gb button to.
*/
void setButtonToMap(PlayerState* playerState, const GbButton gbButton, const N64Button n64Button) {
// Unset old mapping
for (byte i = 0; i < N64_BUTTON_COUNT; i++) {
if (playerState->ButtonMap[i] == gbButton) {
playerState->ButtonMap[i] = GbNoButton;
}
}
// Set new mapping.
playerState->ButtonMap[n64Button] = gbButton;
if (gbButton == GbSystemMenu) {
playerState->SystemMenuButton = n64Button;
}
}
/**
* Initialises a new player state struct with default values.
* @out playerState PlayerState struct to initialise.
*/
void generatePlayerState(PlayerState* playerState) {
playerState->SelectedBorder = BorderNone;
playerState->AudioEnabled = true;
playerState->ActiveMode = Init;
playerState->MenuCursorRow = -1;
playerState->MenuCursorColumn = 0;
initialiseButtonMap(playerState->ButtonMap);
for (byte i = 0; i < N64_BUTTON_COUNT; i++) {
if (playerState->ButtonMap[i] == GbSystemMenu) {
playerState->SystemMenuButton = i;
} else if (playerState->ButtonMap[i] == GbStart) {
playerState->GbStartButton = i;
} else if (playerState->ButtonMap[i] == GbSelect) {
playerState->GbSelectButton = i;
}
}
}