-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.c
195 lines (152 loc) · 3.51 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include <nusys.h>
#include "main.h"
#include "credits.h"
#include "betweenstages.h"
#include "dialogue.h"
#include "displaytext.h"
#include "cutscene.h"
#include "gameaudio.h"
#include "levelselect.h"
#include "stage00.h"
#include "splashscreen.h"
#include "titlescreen.h"
#include "jinglescreen.h"
#include <segmentinfo.h>
ScreenInfo gameplayStage = {
initStage00,
updateGame00,
makeDL00
};
ScreenInfo levelSelectStage = {
initLevelSelect,
updateLevelSelect,
makeLevelSelectDisplayList
};
ScreenInfo cutsceneStage = {
initCutscene,
updateCutscene,
makeCutsceneDisplaylist
};
ScreenInfo titleScreenStage = {
initTitleScreen,
updateTitleScreen,
makeTitleScreenDL
};
ScreenInfo betweenStagesStage = {
initBetweenStages,
updateBetweenStages,
makeBetweenStagesDisplaylist
};
ScreenInfo creditsStage = {
initCredits,
updateCredits,
makeCreditsDisplaylist
};
ScreenInfo splashScreenStage = {
initSplashScreen,
updateSplashScreen,
makeSplashScreenDL
};
ScreenInfo jingleScreenStage = {
initJingleScreen,
updateJingleScreen,
makeJingleScreenDL
};
ScreenInfo* currentStage;
volatile ScreenInfo* nextStage;
/* The global variable */
NUContData contdata[1]; /* Read data of 1 controller */
u8 contPattern; /* The pattern connected to the controller */
OSTime time = 0;
OSTime delta = 0;
float deltaTimeSeconds;
float ingameFOV;
u8 flashingProjectiles;
u32 currentLevel;
u32 wonGameFlag;
u32 stickDeadzone;
volatile u32 changeScreensFlag;
void updateTime() {
OSTime newTime = OS_CYCLES_TO_USEC(osGetTime());
delta = newTime - time;
time = newTime;
deltaTimeSeconds = delta * 0.000001f;
}
void initalizeGameData() {
changeScreensFlag = 1;
currentStage = NULL;
nextStage = &jingleScreenStage;
loadDisplayText();
cutsceneToLoad = "test_scene";
currentLevel = 0;
wonGameFlag = 0;
stickDeadzone = DEFAULT_STICK_DEADZONE;
ingameFOV = FOV_60;
flashingProjectiles = 1;
time = OS_CYCLES_TO_USEC(osGetTime());
updateTime();
initalizeDialogue();
}
void tickCurrentStage(int pendingGfx) {
if (changeScreensFlag) {
return;
}
updateTime();
updateDialogue();
/* Provide the display process if 2 or less RCP tasks are processing or
waiting for the process. */
if(pendingGfx < 3) {
currentStage->makeDL();
}
/* The process of game progress */
currentStage->update();
}
#ifdef PAL_ROM
void callback_prenmi()
{
osViSetYScale(1);
nuGfxDisplayOff();
}
#endif
void mainproc(void)
{
initalizeGameData();
/* The initialization of graphic */
nuGfxInit();
#ifdef PAL_ROM
osViSetMode(&osViModeTable[OS_VI_FPAL_LPN1]);
osViSetSpecialFeatures(OS_VI_DITHER_FILTER_OFF
| OS_VI_GAMMA_OFF
| OS_VI_GAMMA_DITHER_OFF
| OS_VI_DIVOT_OFF);
osViSetYScale(FPAL_Y_SCALE);
nuPreNMIFuncSet((NUScPreNMIFunc)callback_prenmi);
#else
osViSetMode(&osViModeTable[OS_VI_NTSC_LPN1]);
osViSetSpecialFeatures(OS_VI_DITHER_FILTER_OFF
| OS_VI_GAMMA_OFF
| OS_VI_GAMMA_DITHER_OFF
| OS_VI_DIVOT_OFF);
osViBlack(TRUE);
#endif
/* The initialization of the controller manager */
contPattern = nuContInit();
initializeAudio();
while (1) {
currentStage = (ScreenInfo*)nextStage;
nextStage = 0x0;
changeScreensFlag = 0;
currentStage->init();
nuGfxFuncSet((NUGfxFunc)tickCurrentStage);
nuGfxDisplayOn();
#ifdef PAL_ROM
osViSetYScale(FPAL_Y_SCALE);
#endif
while(changeScreensFlag == 0);
#ifdef PAL_ROM
osViSetYScale(1);
#endif
nuGfxDisplayOff();
nuGfxFuncRemove();
}
}