-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
102 lines (78 loc) · 2.77 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "gba.h"
#include "logic.h"
#include "graphics.h"
// TA-TODO: Include any header files for title screen or exit
// screen images generated by nin10kit. Example for the provided garbage
// image:
//#include "images/garbage.h"
#include <stdio.h>
#include <stdlib.h>
// AppState enum definition
typedef enum {
// TA-TODO: Add any additional states you need for your app.
START,
START_NODRAW,
APP_INIT,
APP,
APP_EXIT,
APP_EXIT_NODRAW,
} GBAState;
int main(void) {
// TA-TODO: Manipulate REG_DISPCNT here to set Mode 3.
GBAState state = START;
// We store the "previous" and "current" states.
AppState currentAppState, nextAppState;
// We store the current and previous values of the button input.
u32 previousButtons = BUTTONS;
u32 currentButtons = BUTTONS;
while(1) {
// Load the current state of the buttons
currentButtons = BUTTONS;
// TA-TODO: Manipulate the state machine below as needed.
switch(state) {
case START:
// Wait for VBlank
waitForVBlank();
// TA-TODO: Draw the start state here.
state = START_NODRAW;
break;
case START_NODRAW:
// TA-TODO: Check for a button press here to start the app.
// Start the app by switching the state to APP_INIT.
break;
case APP_INIT:
// Initialize the app. Switch to the APP state.
initializeAppState(¤tAppState);
// Draw the initial state of the app
fullDrawAppState(¤tAppState);
state = APP;
break;
case APP:
// Process the app for one frame, store the next state
nextAppState = processAppState(¤tAppState, previousButtons, currentButtons);
// Wait for VBlank before we do any drawing.
waitForVBlank();
// Undraw the previous state
undrawAppState(¤tAppState);
// Draw the current state
drawAppState(&nextAppState);
// Now set the current state as the next state for the next iter.
currentAppState = nextAppState;
// Check if the app is exiting. If it is, then go to the exit state.
if (nextAppState.gameOver) state = APP_EXIT;
break;
case APP_EXIT:
// Wait for VBlank
waitForVBlank();
// TA-TODO: Draw the exit / gameover screen
state = APP_EXIT_NODRAW;
break;
case APP_EXIT_NODRAW:
// TA-TODO: Check for a button press here to go back to the start screen
break;
}
// Store the current state of the buttons
previousButtons = currentButtons;
}
return 0;
}