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
|
/* **************************************
* Includes *
* *************************************/
#include "LoadMenu.h"
/* **************************************
* Defines *
* *************************************/
/* **************************************
* Structs and enums *
* *************************************/
enum
{
SMALL_FONT_SIZE = 8,
SMALL_FONT_SIZE_BITSHIFT = 3,
SMALL_FONT_SPACING = 6
};
enum
{
BG_BLUE_TARGET_VALUE = 0xC0,
BG_WHITE_TARGET_VALUE = /*0x40*/ 0,
BG_INCREASE_STEP = 0x10
};
enum
{
LOADING_BAR_X = 64,
LOADING_BAR_Y = 200,
LOADING_BAR_N_LINES = 4,
LOADING_BAR_WIDTH = 256,
LOADING_BAR_HEIGHT = 16,
LOADING_BAR_LUMINANCE_TARGET = NORMAL_LUMINANCE,
LOADING_BAR_LUMINANCE_STEP = 10
};
enum
{
LOADING_TITLE_CLUT_X = 384,
LOADING_TITLE_CLUT_Y = 496,
LOADING_TITLE_X = 128,
LOADING_TITLE_Y = 32,
LOADING_TITLE_U = 0,
LOADING_TITLE_V = 0,
LOADING_TITLE_LUMINANCE_STEP = 10,
LOADING_TITLE_LUMINANCE_TARGET = NORMAL_LUMINANCE
};
enum
{
PLANE_START_X = 56,
PLANE_START_Y = 200,
PLANE_U = 0,
PLANE_V = 32,
PLANE_SIZE = 16,
PLANE_LUMINANCE_STEP = 0x10,
PLANE_LUMINANCE_TARGET_VALUE = NORMAL_LUMINANCE
};
/* *************************************
* Local Prototypes
* *************************************/
static void LoadMenuLoadFileList( char* fileList[], void * dest[],
uint8_t szFileList, uint8_t szDestList);
/* *************************************
* Local Variables
* *************************************/
static char* LoadMenuFiles[] = { "cdrom:\\DATA\\FONTS\\FONT_2.FNT;1" };
static void * LoadMenuDest[] = { (TYPE_FONT*)&SmallFont };
static char* strCurrentFile;
// Flags to communicate with ISR state
// * startup_flag: background fades in from black to blue.
// * end_flag: tells the background to fade out to black.
// * isr_ended: background has totally faded out to black.
// * isr_started: tells the ISR has finished starting up.
static volatile bool startup_flag;
static volatile bool isr_started;
static volatile bool end_flag;
static volatile bool isr_ended;
// Set to true when LoadMenuInit() has been called, and set to false
// once LoadMenuEnd() is called.
// It's used when multiple modules call LoadMenu() at the same time,
// so load menu does not have to be initialised each time;
static bool load_menu_running;
void LoadMenuInit(void)
{
static bool first_load = false;
if(first_load == false)
{
first_load = true;
LoadMenuLoadFileList( LoadMenuFiles,
LoadMenuDest,
sizeof(LoadMenuFiles) / sizeof(char*),
sizeof(LoadMenuDest) / sizeof(void*));
}
FontSetSize(&SmallFont, SMALL_FONT_SIZE, SMALL_FONT_SIZE_BITSHIFT);
FontSetSpacing(&SmallFont, SMALL_FONT_SPACING);
SmallFont.spr.r = 0;
SmallFont.spr.g = 0;
SmallFont.spr.b = 0;
GfxSetGlobalLuminance(NORMAL_LUMINANCE);
}
void LoadMenu( char* fileList[],
void * dest[],
uint8_t szFileList , uint8_t szDestList)
{
if(load_menu_running == false)
{
LoadMenuInit();
}
LoadMenuLoadFileList(fileList,dest,szFileList,szDestList);
}
void LoadMenuLoadFileList( char* fileList[], void * dest[],
uint8_t szFileList, uint8_t szDestList)
{
char aux_file_name[100];
char* extension;
uint8_t fileLoadedCount;
if(szFileList != szDestList)
{
dprintf("File list size different from dest list size! %d vs %d\n",
szFileList, szDestList);
return;
}
for(fileLoadedCount = 0; fileLoadedCount < szFileList ; fileLoadedCount++)
{
if(fileList[fileLoadedCount] == NULL)
{
continue;
}
strCurrentFile = fileList[fileLoadedCount];
//dprintf("Files %d / %d loaded. New plane X = %d.\n",fileLoadedCount,szFileList,LoadMenuPlaneSpr.x);
// Backup original file path
strncpy(aux_file_name,fileList[fileLoadedCount],100);
//We want to get file extension, so split into tokens
strtok(fileList[fileLoadedCount],".;");
extension = strtok(NULL,".;");
dprintf("File extension: .%s\n",extension);
//Restore original file path in order to load file
strncpy(fileList[fileLoadedCount],aux_file_name,100);
if(strncmp(extension,"TIM",3) == 0)
{
if(GfxSpriteFromFile(fileList[fileLoadedCount], dest[fileLoadedCount]) == false)
{
dprintf("Could not load image file \"%s\"!\n",fileList[fileLoadedCount]);
}
}
else if(strncmp(extension,"CLT",3) == 0)
{
if(dest[fileLoadedCount] != NULL)
{
dprintf("WARNING: File %s linked to non-NULL destination pointer!\n", dest[fileLoadedCount]);
}
if(GfxCLUTFromFile(fileList[fileLoadedCount]) == false)
{
dprintf("Could not load CLUT file \"%s\"!\n",fileList[fileLoadedCount]);
}
}
else if(strncmp(extension,"FNT",3) == 0)
{
if(FontLoadImage(fileList[fileLoadedCount], dest[fileLoadedCount]) == false)
{
dprintf("Could not load font file \"%s\"!\n",fileList[fileLoadedCount]);
}
}
else
{
dprintf("LoadMenu does not recognize following extension: %s\n",extension);
}
}
}
|