-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.c
144 lines (124 loc) · 2.58 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
#include <gb/gb.h>
#include "gamestate.h"
#include "main.h"
#include "ram.h"
#include "sound.h"
#include "mmlgb/driver/music.h"
#include "logos.h"
#include "intro.h"
#include "title.h"
#include "select.h"
#include "game.h"
#include "winscreen.h"
#include "highscore.h"
#include "unlocked.h"
#include "jukebox.h"
#include "ending.h"
#include "wipe.h"
#include "minigamescore.h"
const UBYTE RAM_SIG[8] = {'T','O','B','U','T','O','B','U'};
void initRAM(UBYTE force_clear) {
UBYTE initialized, i;
ENABLE_RAM_MBC1;
SWITCH_RAM_MBC1(0);
// Check for signature
initialized = 1U;
for(i = 0U; i != 8U; ++i) {
if(ram_data[RAM_SIG_ADDR + i] != RAM_SIG[i]) {
initialized = 0U;
break;
}
}
// Initialize memory
if(initialized == 0U || force_clear) {
for(i = 0U; i != 64U; ++i) {
ram_data[i] = 0U;
}
for(i = 0U; i != 8U; ++i) {
ram_data[RAM_SIG_ADDR + i] = RAM_SIG[i];
}
ram_data[RAM_DASHCOUNTER] = 1U;
}
// Load values from ram
for(levels_completed = 0U; levels_completed != 4U; ++levels_completed) {
if(ram_data[levels_completed << 4] == 0U) break;
}
show_dashcounter = ram_data[RAM_DASHCOUNTER];
DISABLE_RAM_MBC1;
}
void vbl_update() {
++vbl_count;
}
void main() {
disable_interrupts();
initRAM(0U);
snd_init();
vbl_count = 0U;
joystate = oldjoystate = 0U;
level = 1U;
unlocked_bits = 0U;
player_skin = 1U;
ending_flags = 0U;
last_highscore_level = 0U;
last_highscore_slot = 5U;
last_progress = 0U;
selection = level = 1U;
gamestate = GAMESTATE_LOGOS;
SWITCH_16_8_MODE_MBC1;
add_TIM(updateMusic);
add_VBL(vbl_update);
set_interrupts(TIM_IFLAG | VBL_IFLAG);
enable_interrupts();
while(1U) {
switch(gamestate) {
case GAMESTATE_LOGOS:
setGameBank(9U);
enterLogos();
break;
case GAMESTATE_INGAME:
setGameBank(1U);
enterGame();
break;
case GAMESTATE_TITLE:
setGameBank(8U);
enterTitle();
break;
case GAMESTATE_SELECT:
setGameBank(2U);
enterSelect();
break;
case GAMESTATE_HIGHSCORE:
setGameBank(2U);
enterHighscore();
break;
case GAMESTATE_UNLOCKED:
setGameBank(2U);
enterUnlocked();
break;
case GAMESTATE_INTRO:
setGameBank(3U);
enterIntro();
break;
case GAMESTATE_ENDING:
setGameBank(3U);
enterEnding();
break;
case GAMESTATE_JUKEBOX:
setGameBank(4U);
enterJukebox();
break;
case GAMESTATE_WINSCREEN:
setGameBank(7U);
enterWinscreen();
break;
case GAMESTATE_WIPE:
setGameBank(1U);
enterWipe();
break;
case GAMESTATE_MINIGAME_SCORE:
setGameBank(1U);
enterMinigamescore();
break;
}
}
}