-
Notifications
You must be signed in to change notification settings - Fork 0
/
menuFunc.c
213 lines (178 loc) · 3.67 KB
/
menuFunc.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "rfuDefine.h"
#include <AgbDefine.h>
#include <AgbMemoryMap.h>
#include <AgbMacro.h>
#include <AgbSystemCall.h>
#include <AgbRFU_LL.h>
#include "myFunc.h"
#include "data.h"
#include "sound.h"
// This function is not delcared in myFunc.h, giving it an implicit prototype
extern void mf_clearGame(int pos);
static void menu_STC_drawGame(u16 pos,rfuTgtData *tgt);
u8 menu_drawGameList(void)
{
u8 x;
u8 y;
u8 GamesOld;
u8 GamesNew;
u16 pos;
// Find out which games are already in the list, and which ones aren't
GamesOld=0;
GamesNew=0;
for(x=0;x<rfuLinkStatus.findParentCount;x++) {
if(rfuLinkStatus.partner[x].id&&
rfuLinkStatus.partner[x].mboot_flag&&
rfuLinkStatus.partner[x].slot<4) {
for(y=0;y<4;y++) {
if(GameList[y].id!=rfuLinkStatus.partner[x].id)
continue;
GamesOld|=1<<y;
break;
}
if(y==4)
GamesNew|=1<<x;
}
}
// Remove any games that don't exist anymore from the list
for(x=0;x<4;x++)
if(!(GamesOld & 1<<x))
GameList[x].id=0;
// Copy new games into the games list
GameListBitsNew=0;
for(x=0;x<4;x++) {
if(!(GamesNew & 1<<x))
continue;
for(y=0;y<4;y++) {
if(GameList[y].id)
continue;
CpuCopy(&rfuLinkStatus.partner[x],GameList+y,sizeof(rfuTgtData),16);
GameListBitsNew|=1<<y;
break;
}
}
// If any new game was found, play a ditty
if(GameListBitsNew!=0)
snd_play(1);
// Draw the game list
mf_clearRect(0xe3,8,0x19);
pos=0xe3;
for(x=0;x<4;x++) {
if(GameList[x].id!=0)
menu_STC_drawGame(pos,GameList+x);
pos+=0x40;
}
return GamesOld | GamesNew;
}
void menu_clearGameList(void)
{
u8 x;
for(x=0;x<4;x++) {
if(x==SearchMenuCursor)
continue;
GameList[x].id=0;
mf_clearRect(x*0x40+0xe3,1,0x19);
}
}
void menu_initGameList(void)
{
MenuBusy=0;
mf_clearRect(0xe3,8,0x19);
CpuClear(0,GameList,sizeof(GameList),16);
}
void menu_blinkGame(u8 blink)
{
u8 x;
u16 pos;
for(pos=0xe3,x=0;x<4;pos+=0x40,x++) {
if(!(GameListBitsNew & 1<<x))
continue;
if(!blink||(blink_counter & 0x20)==0)
menu_STC_drawGame(pos,GameList+x);
else
mf_clearRect(pos,1,0x19);
}
blink_counter++;
}
static void menu_STC_drawGame(u16 pos,rfuTgtData *tgt)
{
if(!tgt->gname[0])
mf_clearGame(pos);
else
mf_drawString(pos,0,tgt->gname);
if(!tgt->uname[0])
mf_clearGame(pos+15);
else
mf_drawString(pos+15,0,tgt->uname);
}
void menu_checkError(u16 state)
{
if(!state)
return;
if(my_state==10)
my_state=0xc2;
else if(my_state==0)
my_state=0xc5;
else
my_state=0xc1;
SearchMenuErrorMsg=4;
}
void menu_playErrorSFX(void)
{
u8 x;
u8 count;
count=0;
snd_play(6);
for(x=0;x<3*60;x++) {
VBlankIntrWait();
// Play the SFX twice
if(sndStatic.time==(u8)-1&&count<1) {
count++;
snd_play(6);
}
}
}
void menu_drawMessage(u8 msg,u16 pltt)
{
mf_clearRect(MenuMsg->pos[msg] & -0x20,2,0x20);
mf_drawString(MenuMsg->pos[msg],pltt,MenuMsg->msg[msg]);
}
void menu_initBlinkCounter(void)
{
blink_counter=0;
}
void menu_blinkMessage(u8 msg,u8 rate)
{
if(msg==6)
mf_clearRect(MenuMsg->pos[6],2,0x20);
else
mf_clearRect(0x200,2,0x20);
if((blink_counter & rate)==0)
menu_drawMessage(msg,0);
blink_counter++;
}
void menu_initGameName(void)
{
u8 i;
u8 sum;
vu8 *cst;
// Calculate rom checksum
sum=0x19;
cst=(vu8 *)ROM_BANK0+0xa0;
while(cst!=(vu8 *)ROM_BANK0+0xbd)
sum+=*cst++;
sum=~sum+1; // sum=-sum;
// Initialize the game name
for(i=0;i<sizeof(GameName);i++) {
if(i<sizeof(str_my_gname_mboot))
GameName[i]=str_my_gname_mboot[i];
else
GameName[i]=0;
}
// If a valid game is inserted, append the game code
if(*cst==sum) {
cst=(vu8 *)(ROM_BANK0 + 0xac);
for(i=sizeof(str_my_gname_mboot);i<sizeof(GameName);i++)
GameName[i]=*cst++;
}
}