Subversion Repositories freemyipod

Rev

Rev 651 | Rev 707 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 651 Rev 671
Line -... Line 1...
-
 
1
//
-
 
2
//
-
 
3
//    Copyright 2011 TheSeven
-
 
4
//
-
 
5
//
-
 
6
//    This file is part of emCORE.
-
 
7
//
-
 
8
//    emCORE is free software: you can redistribute it and/or
-
 
9
//    modify it under the terms of the GNU General Public License as
-
 
10
//    published by the Free Software Foundation, either version 2 of the
-
 
11
//    License, or (at your option) any later version.
-
 
12
//
-
 
13
//    emCORE is distributed in the hope that it will be useful,
-
 
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
-
 
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
 
16
//    See the GNU General Public License for more details.
-
 
17
//
-
 
18
//    You should have received a copy of the GNU General Public License along
-
 
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
-
 
20
//
-
 
21
//
-
 
22
 
-
 
23
 
1
#include "emcoreapp.h"
24
#include "emcoreapp.h"
2
#include "libboot.h"
25
#include "libboot.h"
3
#include "libpng.h"
26
#include "libpng.h"
4
#include "libui.h"
27
#include "libui.h"
-
 
28
#include "libmkfat32.h"
5
 
29
 
6
 
-
 
-
 
30
struct libpng_api* png;
-
 
31
struct libboot_api* boot;
-
 
32
struct libui_api* ui;
7
void* framebuf;
33
void* framebuf;
-
 
34
void* framebuf2;
-
 
35
void* bg;
-
 
36
void* icons;
-
 
37
void* rbxlogo;
-
 
38
void* crapple;
-
 
39
 
-
 
40
static struct emcorelib_header* loadlib(uint32_t identifier, uint32_t version, char* filename)
-
 
41
{
-
 
42
    struct emcorelib_header* lib = get_library(identifier, version, LIBSOURCE_BOOTFLASH, filename);
-
 
43
    if (!lib) panicf(PANIC_KILLTHREAD, "Could not load %s", filename);
-
 
44
    return lib;
-
 
45
}
-
 
46
 
-
 
47
static void* loadpng(const char* filename, void* (*decoder)(struct png_info* handle))
-
 
48
{
-
 
49
    int size = bootflash_filesize(filename);
-
 
50
    if (size == -1) panicf(PANIC_KILLTHREAD, "Could not load %s", filename);
-
 
51
    void* buf = memalign(0x10, size);
-
 
52
    if (!buf) panicf(PANIC_KILLTHREAD, "Could not allocate buffer for %s", filename);
-
 
53
    bootflash_read(filename, buf, 0, size);
-
 
54
    struct png_info* handle = png->png_open(buf, size);
-
 
55
    if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse %s", filename);
-
 
56
    void* out = decoder(handle);
-
 
57
    if (!out) panicf(PANIC_KILLTHREAD, "Could not decode %s", filename);
-
 
58
    png->png_destroy(handle);
-
 
59
    free(buf);
-
 
60
    return out;
-
 
61
}
-
 
62
 
-
 
63
static void message(int x, const char* line1, const char* line2)
-
 
64
{
-
 
65
    rendertext(framebuf, x, 73, 176, 0xff3333ff, 0xa0000000, line1);
-
 
66
    rendertext(framebuf, x, 81, 176, 0xff3333ff, 0xa0000000, line2);
-
 
67
    displaylcd(0, 0, 176, 132, framebuf, 0, 0, 176);
-
 
68
    sleep(5000000);
-
 
69
}
-
 
70
 
-
 
71
struct chooser_renderer_list_itemdata toolchooser_rparams_mainchooser =
-
 
72
{
-
 
73
    .size = LIBUI_POINT(160, 10),
-
 
74
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(160, 10)),
-
 
75
    .fill_color = 0xa0000000,
-
 
76
    .fill_color_selected = 0x60ffffff,
-
 
77
    .icon_pos = LIBUI_POINT(0, 0),
-
 
78
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
79
                          LIBUI_POINT(0, 0)),
-
 
80
    .icon_opacity = 0,
-
 
81
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
82
                                   LIBUI_POINT(0, 0)),
-
 
83
    .icon_selected_opacity = 0,
-
 
84
    .text = "Return to main menu",
-
 
85
    .text_pos = LIBUI_POINT(1, 1),
-
 
86
    .text_color = 0xffffffff,
-
 
87
    .text_color_selected = 0xff7fffff
-
 
88
};
-
 
89
 
-
 
90
struct chooser_renderer_list_itemdata toolchooser_rparams_umsboot =
-
 
91
{
-
 
92
    .size = LIBUI_POINT(160, 10),
-
 
93
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(160, 10)),
-
 
94
    .fill_color = 0xa0000000,
-
 
95
    .fill_color_selected = 0x60ffffff,
-
 
96
    .icon_pos = LIBUI_POINT(0, 0),
-
 
97
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
98
                          LIBUI_POINT(0, 0)),
-
 
99
    .icon_opacity = 0,
-
 
100
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
101
                                   LIBUI_POINT(0, 0)),
-
 
102
    .icon_selected_opacity = 0,
-
 
103
    .text = "Run UMSboot",
-
 
104
    .text_pos = LIBUI_POINT(1, 1),
-
 
105
    .text_color = 0xffffffff,
-
 
106
    .text_color_selected = 0xff7fffff
-
 
107
};
-
 
108
 
-
 
109
void run_umsboot(void** firmware, void** app, int* size)
-
 
110
{
-
 
111
    boot->load_from_flash(firmware, size, false, "umsboot ", 0x10000);
-
 
112
    if (!*firmware)
-
 
113
    {
-
 
114
        memcpy(framebuf, bg, 176 * 132 * 3);
-
 
115
        message(19, "Loading UMSboot failed!", "Returning to main menu.");
-
 
116
    }
-
 
117
}
-
 
118
 
-
 
119
struct chooser_renderer_list_itemdata toolchooser_rparams_diagmode =
-
 
120
{
-
 
121
    .size = LIBUI_POINT(160, 10),
-
 
122
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(160, 10)),
-
 
123
    .fill_color = 0xa0000000,
-
 
124
    .fill_color_selected = 0x60ffffff,
-
 
125
    .icon_pos = LIBUI_POINT(0, 0),
-
 
126
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
127
                          LIBUI_POINT(0, 0)),
-
 
128
    .icon_opacity = 0,
-
 
129
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
130
                                   LIBUI_POINT(0, 0)),
-
 
131
    .icon_selected_opacity = 0,
-
 
132
    .text = "Run diagnostics mode",
-
 
133
    .text_pos = LIBUI_POINT(1, 1),
-
 
134
    .text_color = 0xffffffff,
-
 
135
    .text_color_selected = 0xff7fffff
-
 
136
};
-
 
137
 
-
 
138
void run_diagmode(void** firmware, void** app, int* size)
-
 
139
{
-
 
140
    boot->load_from_flash(firmware, size, false, "diagmode", 0x100000);
-
 
141
    if (!*firmware)
-
 
142
    {
-
 
143
        memcpy(framebuf, bg, 176 * 132 * 3);
-
 
144
        message(16, "Loading diag mode failed!", " Returning to main menu. ");
-
 
145
    }
-
 
146
}
-
 
147
 
-
 
148
struct chooser_renderer_list_itemdata toolchooser_rparams_rockbox_fallback =
-
 
149
{
-
 
150
    .size = LIBUI_POINT(160, 10),
-
 
151
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(160, 10)),
-
 
152
    .fill_color = 0xa0000000,
-
 
153
    .fill_color_selected = 0x60ffffff,
-
 
154
    .icon_pos = LIBUI_POINT(0, 0),
-
 
155
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
156
                          LIBUI_POINT(0, 0)),
-
 
157
    .icon_opacity = 0,
-
 
158
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
159
                                   LIBUI_POINT(0, 0)),
-
 
160
    .icon_selected_opacity = 0,
-
 
161
    .text = "Run Rockbox fallback image",
-
 
162
    .text_pos = LIBUI_POINT(1, 1),
-
 
163
    .text_color = 0xffffffff,
-
 
164
    .text_color_selected = 0xff7fffff
-
 
165
};
-
 
166
 
-
 
167
void run_rockbox_fallback(void** firmware, void** app, int* size)
-
 
168
{
-
 
169
    boot->load_from_flash(firmware, size, true, "rockbox ", 0x100000);
-
 
170
    if (!*firmware)
8
    
171
    {
-
 
172
        memcpy(framebuf, bg, 176 * 132 * 3);
-
 
173
        message(19, "Loading Rockbox failed!", "Returning to main menu.");
9
    
174
    }
-
 
175
}
-
 
176
 
-
 
177
struct chooser_renderer_list_itemdata toolchooser_rparams_clearcfg =
-
 
178
{
-
 
179
    .size = LIBUI_POINT(160, 10),
-
 
180
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(160, 10)),
-
 
181
    .fill_color = 0xa0000000,
-
 
182
    .fill_color_selected = 0x60ffffff,
-
 
183
    .icon_pos = LIBUI_POINT(0, 0),
-
 
184
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
185
                          LIBUI_POINT(0, 0)),
-
 
186
    .icon_opacity = 0,
-
 
187
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
188
                                   LIBUI_POINT(0, 0)),
-
 
189
    .icon_selected_opacity = 0,
-
 
190
    .text = "Clear Rockbox configuration",
-
 
191
    .text_pos = LIBUI_POINT(1, 1),
-
 
192
    .text_color = 0xffffffff,
-
 
193
    .text_color_selected = 0xff7fffff
-
 
194
};
-
 
195
 
-
 
196
void run_clearcfg(void** firmware, void** app, int* size)
-
 
197
{
-
 
198
    remove("/.rockbox/config.cfg");
-
 
199
    memcpy(framebuf, bg, 176 * 132 * 3);
-
 
200
    message(25, "Rockbox configuration", "  has been cleared.  ");
-
 
201
}
-
 
202
 
-
 
203
struct chooser_renderer_list_itemdata toolchooser_rparams_cleardb =
-
 
204
{
-
 
205
    .size = LIBUI_POINT(160, 10),
-
 
206
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(160, 10)),
-
 
207
    .fill_color = 0xa0000000,
-
 
208
    .fill_color_selected = 0x60ffffff,
-
 
209
    .icon_pos = LIBUI_POINT(0, 0),
-
 
210
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
211
                          LIBUI_POINT(0, 0)),
-
 
212
    .icon_opacity = 0,
-
 
213
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
214
                                   LIBUI_POINT(0, 0)),
-
 
215
    .icon_selected_opacity = 0,
-
 
216
    .text = "Clear Rockbox database",
-
 
217
    .text_pos = LIBUI_POINT(1, 1),
-
 
218
    .text_color = 0xffffffff,
-
 
219
    .text_color_selected = 0xff7fffff
-
 
220
};
-
 
221
 
-
 
222
void run_cleardb(void** firmware, void** app, int* size)
-
 
223
{
-
 
224
    remove("/.rockbox/database_0.tcd");
-
 
225
    remove("/.rockbox/database_1.tcd");
-
 
226
    remove("/.rockbox/database_2.tcd");
-
 
227
    remove("/.rockbox/database_3.tcd");
-
 
228
    remove("/.rockbox/database_4.tcd");
-
 
229
    remove("/.rockbox/database_5.tcd");
-
 
230
    remove("/.rockbox/database_6.tcd");
-
 
231
    remove("/.rockbox/database_7.tcd");
-
 
232
    remove("/.rockbox/database_8.tcd");
-
 
233
    remove("/.rockbox/database_9.tcd");
-
 
234
    remove("/.rockbox/database_idx.tcd");
-
 
235
    remove("/.rockbox/database_tmp.tcd");
-
 
236
    remove("/.rockbox/database_state.tcd");
-
 
237
    remove("/.rockbox/database_changelog.txt");
-
 
238
    memcpy(framebuf, bg, 176 * 132 * 3);
-
 
239
    message(37, "Rockbox  database", "has been cleared.");
-
 
240
}
-
 
241
 
-
 
242
struct chooser_renderer_list_itemdata toolchooser_rparams_reformat =
-
 
243
{
-
 
244
    .size = LIBUI_POINT(160, 10),
-
 
245
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(160, 10)),
-
 
246
    .fill_color = 0xa0000000,
-
 
247
    .fill_color_selected = 0x60ffffff,
-
 
248
    .icon_pos = LIBUI_POINT(0, 0),
-
 
249
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
250
                          LIBUI_POINT(0, 0)),
-
 
251
    .icon_opacity = 0,
-
 
252
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
253
                                   LIBUI_POINT(0, 0)),
-
 
254
    .icon_selected_opacity = 0,
-
 
255
    .text = "Reformat data partition",
-
 
256
    .text_pos = LIBUI_POINT(1, 1),
-
 
257
    .text_color = 0xffffffff,
-
 
258
    .text_color_selected = 0xff7fffff
-
 
259
};
-
 
260
 
-
 
261
void fat32_progressbar_init(void* user, int max)
-
 
262
{
-
 
263
    progressbar_init((struct progressbar_state*)user,
-
 
264
                     10, 165, 74, 83, 0x77ff, 0xe8, 0x125f, 0, max);
-
 
265
}
-
 
266
 
-
 
267
void fat32_progressbar_update(void* user, int current)
-
 
268
{
-
 
269
    progressbar_setpos((struct progressbar_state*)user, current, false);
-
 
270
}
-
 
271
 
-
 
272
void run_reformat(void** firmware, void** app, int* size)
-
 
273
{
-
 
274
    memcpy(framebuf, bg, 176 * 132 * 3);
-
 
275
    rendertext(framebuf, 7, 65, 176, 0xff7fffff, 0, "Reformatting data partition");
-
 
276
    displaylcd(0, 0, 176, 132, framebuf, 0, 0, 176);
-
 
277
    struct emcorelib_header* libmkfat32 = loadlib(LIBMKFAT32_IDENTIFIER,
-
 
278
                                                  LIBMKFAT32_API_VERSION, "libmkf32");
-
 
279
    struct libmkfat32_api* mf32 = (struct libmkfat32_api*)libmkfat32->api;
-
 
280
    struct storage_info storageinfo;
-
 
281
    storage_get_info(0, &storageinfo);
-
 
282
    struct progressbar_state progressbar;
-
 
283
    int rc = mf32->mkfat32(0, 0, storageinfo.num_sectors, 2048, 1, "iPod Nano2G",
-
 
284
                           &progressbar, fat32_progressbar_init, fat32_progressbar_update);
-
 
285
    if (rc < 0) panicf(PANIC_KILLTHREAD, "Error formatting data partition: %08X", rc);
-
 
286
    release_library(libmkfat32);
-
 
287
    library_unload(libmkfat32);
-
 
288
    memcpy(framebuf, bg, 176 * 132 * 3);
-
 
289
    message(34, "Data partition has", "been  reformatted.");
-
 
290
}
-
 
291
 
-
 
292
struct chooser_renderer_list_itemdata toolchooser_rparams_uninstaller =
-
 
293
{
-
 
294
    .size = LIBUI_POINT(160, 10),
-
 
295
    .fill_box = LIBUI_BOX(LIBUI_POINT(0, 0), LIBUI_POINT(160, 10)),
-
 
296
    .fill_color = 0xa0000000,
-
 
297
    .fill_color_selected = 0x60ffffff,
-
 
298
    .icon_pos = LIBUI_POINT(0, 0),
-
 
299
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
300
                          LIBUI_POINT(0, 0)),
-
 
301
    .icon_opacity = 0,
-
 
302
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
303
                                   LIBUI_POINT(0, 0)),
-
 
304
    .icon_selected_opacity = 0,
-
 
305
    .text = "Uninstall emCORE",
-
 
306
    .text_pos = LIBUI_POINT(1, 1),
-
 
307
    .text_color = 0xffffffff,
-
 
308
    .text_color_selected = 0xff7fffff
-
 
309
};
-
 
310
 
-
 
311
void run_uninstaller(void** firmware, void** app, int* size)
-
 
312
{
-
 
313
    boot->load_from_flash(app, size, false, "uninst  ", 0);
-
 
314
    if (!*app)
-
 
315
    {
-
 
316
        memcpy(framebuf, bg, 176 * 132 * 3);
-
 
317
        message(7, "Loading uninstaller failed!", "  Returning to main menu.  ");
-
 
318
    }
-
 
319
}
-
 
320
 
-
 
321
struct chooser_renderer_list_params toolchooser_rparams =
-
 
322
{
-
 
323
    .version = CHOOSER_RENDERER_LIST_PARAMS_VERSION,
-
 
324
    .copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
-
 
325
    .copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
-
 
326
                              LIBUI_POINT(176, 132)),
-
 
327
    .bg_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
328
    .bg_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
329
                            LIBUI_POINT(0, 0)),
-
 
330
    .bg_opacity = 0,
-
 
331
    .fill_dest = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
-
 
332
                               LIBUI_POINT(0, 0)),
-
 
333
    .fill_color = 0,
-
 
334
    .viewport = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(7, 30)),
-
 
335
                              LIBUI_POINT(162, 80)),
-
 
336
    .blit_dest = LIBUI_POINT(0, 0),
-
 
337
    .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
-
 
338
                              LIBUI_POINT(176, 132)),
-
 
339
    .preblit = NULL,
-
 
340
    .postblit = NULL
-
 
341
};
-
 
342
 
-
 
343
struct chooser_action_handler_wheel_params toolchooser_aparams =
-
 
344
{
-
 
345
    .version = CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION,
-
 
346
    .stepsperitem = 128,
-
 
347
    .eventfilter = NULL,
-
 
348
    .timeout_initial = TIMEOUT_BLOCK,
-
 
349
    .timeout_idle = TIMEOUT_BLOCK,
-
 
350
    .timeout_item = 0,
-
 
351
    .tick_force_redraw = false,
-
 
352
    .buttoncount = 5,
-
 
353
    .buttonmap =
-
 
354
    {
-
 
355
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
-
 
356
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
-
 
357
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV,
-
 
358
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
-
 
359
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV
-
 
360
    }
-
 
361
};
-
 
362
 
-
 
363
struct chooser_info toolchooser =
-
 
364
{
-
 
365
    .version = CHOOSER_INFO_VERSION,
-
 
366
    .actionhandler = NULL,
-
 
367
    .actionhandlerparams = &toolchooser_aparams,
-
 
368
    .renderer = NULL,
-
 
369
    .rendererparams = &toolchooser_rparams,
-
 
370
    .userparams = NULL,
-
 
371
    .tickinterval = 10000000,
-
 
372
    .itemcount = 8,
-
 
373
    .defaultitem = 0,
-
 
374
    .items =
-
 
375
    {
-
 
376
        {
-
 
377
            .user = NULL,
-
 
378
            .actionparams = NULL,
-
 
379
            .renderparams = &toolchooser_rparams_mainchooser
-
 
380
        },
-
 
381
        {
-
 
382
            .user = run_umsboot,
-
 
383
            .actionparams = NULL,
-
 
384
            .renderparams = &toolchooser_rparams_umsboot
-
 
385
        },
-
 
386
        {
-
 
387
            .user = run_diagmode,
-
 
388
            .actionparams = NULL,
-
 
389
            .renderparams = &toolchooser_rparams_diagmode
-
 
390
        },
-
 
391
        {
-
 
392
            .user = run_rockbox_fallback,
-
 
393
            .actionparams = NULL,
-
 
394
            .renderparams = &toolchooser_rparams_rockbox_fallback
-
 
395
        },
-
 
396
        {
-
 
397
            .user = run_clearcfg,
-
 
398
            .actionparams = NULL,
-
 
399
            .renderparams = &toolchooser_rparams_clearcfg
-
 
400
        },
-
 
401
        {
-
 
402
            .user = run_cleardb,
-
 
403
            .actionparams = NULL,
-
 
404
            .renderparams = &toolchooser_rparams_cleardb
-
 
405
        },
-
 
406
        {
-
 
407
            .user = run_reformat,
-
 
408
            .actionparams = NULL,
-
 
409
            .renderparams = &toolchooser_rparams_reformat
-
 
410
        },
-
 
411
        {
-
 
412
            .user = run_uninstaller,
-
 
413
            .actionparams = NULL,
-
 
414
            .renderparams = &toolchooser_rparams_uninstaller
-
 
415
        }
-
 
416
    }
-
 
417
};
-
 
418
 
10
bool mychooser_preblit(struct chooser_data* data)
419
bool mainchooser_preblit(struct chooser_data* data)
11
{
420
{
12
    char buf[4];
421
    char buf[4];
13
    struct chooser_action_handler_wheel_data* adata;
422
    struct chooser_action_handler_wheel_data* adata;
14
    adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
423
    adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
15
    snprintf(buf, sizeof(buf), "%3d", adata->timeout_remaining / 1000000);
424
    snprintf(buf, sizeof(buf), "%3d", adata->timeout_remaining / 1000000);
16
    rendertext(framebuf, 158, 124, 176, 0xffffcccc, 0, buf);
425
    rendertext(framebuf, 158, 124, 176, 0xffffcccc, 0, buf);
17
    return false;
426
    return false;
18
}
427
}
19
 
428
 
20
 
-
 
21
struct chooser_renderer_iconflow_itemdata mychooser_rparams_0 =
429
struct chooser_renderer_iconflow_itemdata mainchooser_rparams_powerdown =
22
{
430
{
23
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 31)),
431
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 31)),
24
                          LIBUI_POINT(44, 40)),
432
                          LIBUI_POINT(44, 44)),
25
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 31)),
433
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 31)),
26
                                   LIBUI_POINT(44, 40)),
434
                                   LIBUI_POINT(44, 44)),
27
    .text = "Power off",
435
    .text = "Power off",
28
    .text_color = 0xffffcccc,
436
    .text_color = 0xffffcccc,
29
};
437
};
30
 
438
 
31
struct chooser_renderer_iconflow_itemdata mychooser_rparams_1 =
439
void run_powerdown(void** firmware, void** app, int* size)
32
{
440
{
-
 
441
    shutdown(true);
-
 
442
    power_off();
-
 
443
}
-
 
444
 
-
 
445
struct chooser_renderer_iconflow_itemdata mainchooser_rparams_crapple =
-
 
446
{
33
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 177)),
447
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 123)),
34
                          LIBUI_POINT(44, 43)),
448
                          LIBUI_POINT(44, 43)),
35
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 177)),
449
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 123)),
36
                                   LIBUI_POINT(44, 43)),
450
                                   LIBUI_POINT(44, 43)),
37
    .text = "Original firmware",
451
    .text = "Original firmware",
38
    .text_color = 0xffffcccc,
452
    .text_color = 0xffffcccc,
39
};
453
};
40
 
454
 
-
 
455
void run_crapple(void** firmware, void** app, int* size)
-
 
456
{
-
 
457
    int i;
-
 
458
    for (i = 23; i <= 115; i += 23)
-
 
459
    {
-
 
460
        if (i < 115)
-
 
461
            ui->blend(176, 132, 50, framebuf, 0, 0, 176,
-
 
462
                      framebuf, 0, 0, 176, bg, 0, 0, 176);
-
 
463
        else memcpy(framebuf, bg, 176 * 132 * 3);
-
 
464
        memcpy(framebuf2, framebuf, 176 * 132 * 3);
-
 
465
        ui->blenda(111, i, 255, framebuf2, 32, 0, 176,
-
 
466
                   framebuf2, 32, 0, 176, crapple, 0, 115 - i, 111);
-
 
467
        displaylcd(0, 0, 176, 132, framebuf2, 0, 0, 176);
-
 
468
    }
-
 
469
    boot->load_from_file(firmware, size, false, "/.boot/appleos.ucl", 0x800000);
-
 
470
    if (!*firmware) boot->load_from_file(firmware, size, false, "/.boot/appleos.bin", 0);
-
 
471
    if (!*firmware) message(7, "Loading appleos.bin failed!", "  Returning to main menu.  ");
-
 
472
}
-
 
473
 
41
struct chooser_renderer_iconflow_itemdata mychooser_rparams_2 =
474
struct chooser_renderer_iconflow_itemdata mainchooser_rparams_rockbox =
42
{
475
{
43
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 0)),
476
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 0)),
44
                          LIBUI_POINT(44, 14)),
477
                          LIBUI_POINT(44, 14)),
45
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 0)),
478
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 0)),
46
                                   LIBUI_POINT(44, 14)),
479
                                   LIBUI_POINT(44, 14)),
47
    .text = "Rockbox",
480
    .text = "Rockbox",
48
    .text_color = 0xffffcccc,
481
    .text_color = 0xffffcccc,
49
};
482
};
50
 
483
 
-
 
484
void run_rockbox(void** firmware, void** app, int* size)
-
 
485
{
-
 
486
    int i;
-
 
487
    for (i = 2; i <= 52; i += 10)
-
 
488
    {
-
 
489
        if (i < 52)
-
 
490
            ui->blend(176, 132, 50, framebuf, 0, 0, 176,
-
 
491
                      framebuf, 0, 0, 176, bg, 0, 0, 176);
-
 
492
        else memcpy(framebuf, bg, 176 * 132 * 3);
-
 
493
        ui->blit(154, MIN(47, i), 3, framebuf, 11, MAX(0, i - 47), 176,
-
 
494
                 rbxlogo, 0, MAX(0, 47 - i), 154);
-
 
495
        displaylcd(0, 0, 176, 132, framebuf, 0, 0, 176);
-
 
496
    }
-
 
497
    boot->load_from_file(firmware, size, true, "/.rockbox/rockbox.ipod", 0);
-
 
498
    if (!*firmware)
-
 
499
    {
-
 
500
        message(4, "Loading rockbox.ipod failed!", "  Trying fallback image...  ");
-
 
501
        boot->load_from_flash(firmware, size, true, "rockbox ", 0x100000);
-
 
502
    }
-
 
503
    if (!*firmware)
-
 
504
    {
-
 
505
        memcpy(framebuf, bg, 176 * 132 * 3);
-
 
506
        message(19, "Loading Rockbox failed!", "Returning to main menu.");
-
 
507
    }
-
 
508
}
-
 
509
 
51
struct chooser_renderer_iconflow_itemdata mychooser_rparams_3 =
510
struct chooser_renderer_iconflow_itemdata mainchooser_rparams_console =
52
{
511
{
53
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 14)),
512
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 14)),
54
                          LIBUI_POINT(44, 17)),
513
                          LIBUI_POINT(44, 17)),
55
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 14)),
514
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 14)),
56
                                   LIBUI_POINT(44, 17)),
515
                                   LIBUI_POINT(44, 17)),
57
    .text = "emCORE console",
516
    .text = "emCORE console",
58
    .text_color = 0xffffcccc,
517
    .text_color = 0xffffcccc,
59
};
518
};
60
 
519
 
61
struct chooser_renderer_iconflow_itemdata mychooser_rparams_4 =
520
struct chooser_renderer_iconflow_itemdata mainchooser_rparams_diskmode =
62
{
521
{
63
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 71)),
522
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 166)),
64
                          LIBUI_POINT(44, 31)),
523
                          LIBUI_POINT(44, 31)),
65
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 71)),
524
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 166)),
66
                                   LIBUI_POINT(44, 31)),
525
                                   LIBUI_POINT(44, 31)),
67
    .text = "UMSboot",
526
    .text = "Disk mode",
68
    .text_color = 0xffffcccc,
527
    .text_color = 0xffffcccc,
69
};
528
};
70
 
529
 
71
struct chooser_renderer_iconflow_itemdata mychooser_rparams_5 =
530
void run_diskmode(void** firmware, void** app, int* size)
72
{
531
{
73
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 133)),
532
    boot->load_from_flash(firmware, size, false, "diskmode", 0x100000);
74
                          LIBUI_POINT(44, 44)),
533
    if (!*firmware)
75
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 133)),
-
 
-
 
534
    {
76
                                   LIBUI_POINT(44, 44)),
535
        memcpy(framebuf, bg, 176 * 132 * 3);
77
    .text = "Diagnostics mode",
536
        message(13, "Loading disk mode failed!", " Returning to main menu. ");
78
    .text_color = 0xffffcccc,
537
    }
79
};
538
}
80
 
539
 
81
struct chooser_renderer_iconflow_itemdata mychooser_rparams_6 =
540
struct chooser_renderer_iconflow_itemdata mainchooser_rparams_toolchooser =
82
{
541
{
83
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 102)),
542
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 75)),
84
                          LIBUI_POINT(44, 31)),
543
                          LIBUI_POINT(44, 48)),
85
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 102)),
544
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 75)),
86
                                   LIBUI_POINT(44, 31)),
545
                                   LIBUI_POINT(44, 48)),
87
    .text = "Disk mode",
546
    .text = "Tools",
88
    .text_color = 0xffffcccc,
547
    .text_color = 0xffffcccc,
89
};
548
};
90
 
549
 
91
struct chooser_renderer_iconflow_params mychooser_rparams =
550
static void run_toolchooser(void** firmware, void** app, int* size)
92
{
551
{
-
 
552
    const struct chooser_item* result = ui->chooser_run(&toolchooser);
-
 
553
    if (!result->user) return;
-
 
554
    void (*selected_function)(void** firmware, void** app, int* size);
-
 
555
    selected_function = (void(*)(void** firmware, void** app, int* size))(result->user);
-
 
556
    selected_function(firmware, app, size);
-
 
557
}
-
 
558
 
-
 
559
struct chooser_renderer_iconflow_params mainchooser_rparams =
-
 
560
{
93
    .version = CHOOSER_RENDERER_LIST_PARAMS_VERSION,
561
    .version = CHOOSER_RENDERER_ICONFLOW_PARAMS_VERSION,
94
    .copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
562
    .copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
95
    .copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
563
    .copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
96
                              LIBUI_POINT(176, 132)),
564
                              LIBUI_POINT(176, 132)),
97
    .bg_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
565
    .bg_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
98
    .bg_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
566
    .bg_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 0), LIBUI_POINT(0, 0)),
Line 108... Line 576...
108
    .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
576
    .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
109
                              LIBUI_POINT(176, 132)),
577
                              LIBUI_POINT(176, 132)),
110
    .smoothness = 500000,
578
    .smoothness = 500000,
111
    .startposition = -3,
579
    .startposition = -3,
112
    .iconsinview = 4,
580
    .iconsinview = 4,
113
    .preblit = mychooser_preblit,
581
    .preblit = mainchooser_preblit,
114
    .postblit = NULL
582
    .postblit = NULL
115
};
583
};
116
 
584
 
117
struct chooser_action_handler_wheel_params mychooser_aparams =
585
struct chooser_action_handler_wheel_params mainchooser_aparams =
118
{
586
{
119
    .version = CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION,
587
    .version = CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION,
120
    .stepsperitem = 512,
588
    .stepsperitem = 512,
121
    .eventfilter = NULL,
589
    .eventfilter = NULL,
122
    .timeout_initial = 30500000,
590
    .timeout_initial = 30500000,
Line 130... Line 598...
130
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
598
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
131
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV
599
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV
132
    }
600
    }
133
};
601
};
134
 
602
 
135
struct chooser_info mychooser =
603
struct chooser_info mainchooser =
136
{
604
{
137
    .version = CHOOSER_INFO_VERSION,
605
    .version = CHOOSER_INFO_VERSION,
138
    .actionhandler = NULL,
606
    .actionhandler = NULL,
139
    .actionhandlerparams = &mychooser_aparams,
607
    .actionhandlerparams = &mainchooser_aparams,
140
    .renderer = NULL,
608
    .renderer = NULL,
141
    .rendererparams = &mychooser_rparams,
609
    .rendererparams = &mainchooser_rparams,
142
    .userparams = NULL,
610
    .userparams = NULL,
143
    .tickinterval = 990000,
611
    .tickinterval = 990000,
144
    .itemcount = 7,
612
    .itemcount = 6,
145
    .defaultitem = 2,
613
    .defaultitem = 2,
146
    .items =
614
    .items =
147
    {
615
    {
148
        {
616
        {
149
            .user = (void*)0,
617
            .user = run_powerdown,
150
            .actionparams = NULL,
618
            .actionparams = NULL,
151
            .renderparams = &mychooser_rparams_0
619
            .renderparams = &mainchooser_rparams_powerdown
152
        },
620
        },
153
        {
621
        {
154
            .user = (void*)1,
622
            .user = run_crapple,
155
            .actionparams = NULL,
623
            .actionparams = NULL,
156
            .renderparams = &mychooser_rparams_1
624
            .renderparams = &mainchooser_rparams_crapple
157
        },
625
        },
158
        {
626
        {
159
            .user = (void*)2,
627
            .user = run_rockbox,
160
            .actionparams = NULL,
628
            .actionparams = NULL,
161
            .renderparams = &mychooser_rparams_2
629
            .renderparams = &mainchooser_rparams_rockbox
162
        },
630
        },
163
        {
631
        {
164
            .user = (void*)3,
632
            .user = NULL,
165
            .actionparams = NULL,
633
            .actionparams = NULL,
166
            .renderparams = &mychooser_rparams_3
634
            .renderparams = &mainchooser_rparams_console
167
        },
635
        },
168
        {
636
        {
169
            .user = (void*)4,
637
            .user = run_diskmode,
170
            .actionparams = NULL,
638
            .actionparams = NULL,
171
            .renderparams = &mychooser_rparams_4
639
            .renderparams = &mainchooser_rparams_diskmode
172
        },
640
        },
173
        {
641
        {
174
            .user = (void*)5,
642
            .user = run_toolchooser,
175
            .actionparams = NULL,
643
            .actionparams = NULL,
176
            .renderparams = &mychooser_rparams_5
644
            .renderparams = &mainchooser_rparams_toolchooser
177
        },
-
 
178
        {
-
 
179
            .user = (void*)6,
-
 
180
            .actionparams = NULL,
-
 
181
            .renderparams = &mychooser_rparams_6
-
 
182
        }
645
        }
183
    }
646
    }
184
};
647
};
185
 
648
 
-
 
649
static void run_mainchooser(void** firmware, void** app, int* size)
-
 
650
{
-
 
651
    while (!*firmware && !*app)
-
 
652
    {
-
 
653
        const struct chooser_item* result = ui->chooser_run(&mainchooser);
-
 
654
        if (!result->user) return;
-
 
655
        void (*selected_function)(void** firmware, void** app, int* size);
-
 
656
        selected_function = (void(*)(void** firmware, void** app, int* size))(result->user);
-
 
657
        selected_function(firmware, app, size);
-
 
658
    }
-
 
659
}
186
 
660
 
187
static void main()
661
static void main()
188
{
662
{
189
    struct emcorelib_header* libboot = get_library(LIBBOOT_IDENTIFIER, LIBBOOT_API_VERSION, LIBSOURCE_BOOTFLASH, "libboot ");
-
 
190
    if (!libboot) panicf(PANIC_KILLTHREAD, "Could not load booting library!");
-
 
191
    struct libboot_api* boot = (struct libboot_api*)libboot->api;
-
 
192
    struct emcorelib_header* libpng = get_library(LIBPNG_IDENTIFIER, LIBPNG_API_VERSION, LIBSOURCE_BOOTFLASH, "libpng  ");
663
    struct emcorelib_header* libpng = loadlib(LIBPNG_IDENTIFIER, LIBPNG_API_VERSION, "libpng  ");
193
    if (!libpng) panicf(PANIC_KILLTHREAD, "Could not load PNG decoder library!");
-
 
194
    struct libpng_api* png = (struct libpng_api*)libpng->api;
664
    png = (struct libpng_api*)libpng->api;
195
    struct emcorelib_header* libui = get_library(LIBUI_IDENTIFIER, LIBUI_API_VERSION, LIBSOURCE_BOOTFLASH, "libui   ");
-
 
196
    if (!libui) panicf(PANIC_KILLTHREAD, "Could not load user interface library!");
665
    bg = loadpng("backgrnd", (void* (*)(struct png_info*))(png->png_decode_rgb));
197
    struct libui_api* ui = (struct libui_api*)libui->api;
-
 
198
    int size = bootflash_filesize("backgrnd");
-
 
199
    if (size == -1) panicf(PANIC_KILLTHREAD, "Could not find background image!");
666
    icons = loadpng("iconset ", (void* (*)(struct png_info*))(png->png_decode_rgba));
200
    void* buf = memalign(0x10, size);
-
 
201
    if (!buf) panicf(PANIC_KILLTHREAD, "Could not allocate buffer for background image!");
667
    rbxlogo = loadpng("rbxlogo ", (void* (*)(struct png_info*))(png->png_decode_rgb));
202
    bootflash_read("backgrnd", buf, 0, size);
-
 
203
    struct png_info* handle = png->png_open(buf, size);
-
 
204
    if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse background image!");
-
 
205
    struct png_rgb* bg = png->png_decode_rgb(handle);
668
    crapple = loadpng("crapple ", (void* (*)(struct png_info*))(png->png_decode_rgba));
206
    if (!bg) panicf(PANIC_KILLTHREAD, "Could not decode background image!");
-
 
207
    png->png_destroy(handle);
669
    release_library(libpng);
208
    free(buf);
-
 
209
    size = bootflash_filesize("iconset ");
-
 
210
    if (size == -1) panicf(PANIC_KILLTHREAD, "Could not find icon set!");
-
 
211
    buf = memalign(0x10, size);
670
    library_unload(libpng);
212
    if (!buf) panicf(PANIC_KILLTHREAD, "Could not allocate buffer for icon set!");
-
 
213
    bootflash_read("iconset ", buf, 0, size);
-
 
214
    handle = png->png_open(buf, size);
-
 
215
    if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse icon set!");
-
 
216
    struct png_rgba* icons = png->png_decode_rgba(handle);
671
    struct emcorelib_header* libboot = loadlib(LIBBOOT_IDENTIFIER,
217
    if (!icons) panicf(PANIC_KILLTHREAD, "Could not decode icon set!");
-
 
218
    png->png_destroy(handle);
-
 
219
    free(buf);
-
 
220
    size = bootflash_filesize("rbxlogo ");
-
 
221
    if (size == -1) panicf(PANIC_KILLTHREAD, "Could not find Rockbox logo!");
672
                                               LIBBOOT_API_VERSION, "libboot ");
222
    buf = memalign(0x10, size);
-
 
223
    if (!buf) panicf(PANIC_KILLTHREAD, "Could not allocate buffer for Rockbox logo!");
-
 
224
    bootflash_read("rbxlogo ", buf, 0, size);
673
    boot = (struct libboot_api*)libboot->api;
225
    handle = png->png_open(buf, size);
-
 
226
    if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse Rockbox logo!");
-
 
227
    struct png_rgb* rbxlogo = png->png_decode_rgb(handle);
-
 
228
    if (!rbxlogo) panicf(PANIC_KILLTHREAD, "Could not decode Rockbox logo!");
674
    struct emcorelib_header* libui = loadlib(LIBUI_IDENTIFIER, LIBUI_API_VERSION, "libui   ");
229
    png->png_destroy(handle);
-
 
230
    free(buf);
-
 
231
    size = bootflash_filesize("crapple ");
675
    ui = (struct libui_api*)libui->api;
232
    if (size == -1) panicf(PANIC_KILLTHREAD, "Could not find OF logo!");
-
 
233
    buf = memalign(0x10, size);
-
 
234
    if (!buf) panicf(PANIC_KILLTHREAD, "Could not allocate buffer for OF logo!");
-
 
235
    bootflash_read("crapple ", buf, 0, size);
-
 
236
    handle = png->png_open(buf, size);
-
 
237
    if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse OF logo!");
-
 
238
    struct png_rgba* crapple = png->png_decode_rgba(handle);
-
 
239
    if (!rbxlogo) panicf(PANIC_KILLTHREAD, "Could not decode OF logo!");
-
 
240
    png->png_destroy(handle);
-
 
241
    free(buf);
-
 
242
    framebuf = malloc(176 * 132 * 3);
676
    framebuf = malloc(176 * 132 * 3);
243
    if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
677
    if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
244
    void* framebuf2 = malloc(176 * 132 * 3);
678
    framebuf2 = malloc(176 * 132 * 3);
245
    if (!framebuf2) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer 2!");
679
    if (!framebuf2) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer 2!");
246
    mychooser.actionhandler = ui->chooser_action_handler_wheel;
680
    mainchooser.actionhandler = ui->chooser_action_handler_wheel;
247
    mychooser.renderer = ui->chooser_renderer_iconflow;
681
    mainchooser.renderer = ui->chooser_renderer_iconflow;
248
    mychooser_rparams.copy_dest.buf.addr = framebuf;
682
    mainchooser_rparams.copy_dest.buf.addr = framebuf;
249
    mychooser_rparams.copy_src.loc.buf.addr = bg;
683
    mainchooser_rparams.copy_src.loc.buf.addr = bg;
250
    mychooser_rparams.viewport.loc.buf.addr = framebuf;
684
    mainchooser_rparams.viewport.loc.buf.addr = framebuf;
251
    mychooser_rparams.blit_src.loc.buf.addr = framebuf;
685
    mainchooser_rparams.blit_src.loc.buf.addr = framebuf;
252
    mychooser_rparams_0.icon.loc.buf.addr = icons;
686
    mainchooser_rparams_powerdown.icon.loc.buf.addr = icons;
253
    mychooser_rparams_0.icon_selected.loc.buf.addr = icons;
687
    mainchooser_rparams_powerdown.icon_selected.loc.buf.addr = icons;
254
    mychooser_rparams_1.icon.loc.buf.addr = icons;
688
    mainchooser_rparams_crapple.icon.loc.buf.addr = icons;
255
    mychooser_rparams_1.icon_selected.loc.buf.addr = icons;
689
    mainchooser_rparams_crapple.icon_selected.loc.buf.addr = icons;
256
    mychooser_rparams_2.icon.loc.buf.addr = icons;
690
    mainchooser_rparams_rockbox.icon.loc.buf.addr = icons;
257
    mychooser_rparams_2.icon_selected.loc.buf.addr = icons;
691
    mainchooser_rparams_rockbox.icon_selected.loc.buf.addr = icons;
258
    mychooser_rparams_3.icon.loc.buf.addr = icons;
692
    mainchooser_rparams_console.icon.loc.buf.addr = icons;
259
    mychooser_rparams_3.icon_selected.loc.buf.addr = icons;
693
    mainchooser_rparams_console.icon_selected.loc.buf.addr = icons;
260
    mychooser_rparams_4.icon.loc.buf.addr = icons;
694
    mainchooser_rparams_diskmode.icon.loc.buf.addr = icons;
261
    mychooser_rparams_4.icon_selected.loc.buf.addr = icons;
695
    mainchooser_rparams_diskmode.icon_selected.loc.buf.addr = icons;
262
    mychooser_rparams_5.icon.loc.buf.addr = icons;
696
    mainchooser_rparams_toolchooser.icon.loc.buf.addr = icons;
263
    mychooser_rparams_5.icon_selected.loc.buf.addr = icons;
697
    mainchooser_rparams_toolchooser.icon_selected.loc.buf.addr = icons;
-
 
698
 
-
 
699
    toolchooser.actionhandler = ui->chooser_action_handler_wheel;
-
 
700
    toolchooser.renderer = ui->chooser_renderer_list;
-
 
701
    toolchooser_rparams.copy_dest.buf.addr = framebuf;
264
    mychooser_rparams_6.icon.loc.buf.addr = icons;
702
    toolchooser_rparams.copy_src.loc.buf.addr = bg;
-
 
703
    toolchooser_rparams.viewport.loc.buf.addr = framebuf;
265
    mychooser_rparams_6.icon_selected.loc.buf.addr = icons;
704
    toolchooser_rparams.blit_src.loc.buf.addr = framebuf;
-
 
705
 
266
    backlight_set_brightness(177);
706
    backlight_set_brightness(177);
267
    void* firmware = NULL;
707
    void* firmware = NULL;
268
    while (!firmware)
-
 
269
    {
-
 
270
        const struct chooser_item* result = ui->chooser_run(&mychooser);
-
 
271
        switch ((int)(result->user))
-
 
272
        {
-
 
273
        case 0:
-
 
274
            shutdown(true);
-
 
275
            power_off();
-
 
276
            break;
-
 
277
        case 1:
-
 
278
        {
-
 
279
            int i;
-
 
280
            for (i = 23; i <= 115; i += 23)
-
 
281
            {
-
 
282
                if (i < 115)
-
 
283
                    ui->blend(176, 132, 50, framebuf, 0, 0, 176,
-
 
284
                              framebuf, 0, 0, 176, bg, 0, 0, 176);
-
 
285
                else memcpy(framebuf, bg, 176 * 132 * 3);
-
 
286
                memcpy(framebuf2, framebuf, 176 * 132 * 3);
-
 
287
                ui->blenda(111, i, 255, framebuf2, 32, 0, 176,
-
 
288
                           framebuf2, 32, 0, 176, crapple, 0, 115 - i, 111);
-
 
289
                displaylcd(0, 0, 176, 132, framebuf2, 0, 0, 176);
-
 
290
            }
-
 
291
            int fd = file_open("/.boot/appleos.bin", O_RDONLY);
-
 
292
            if (fd > 0)
-
 
293
            {
-
 
294
                size = filesize(fd);
-
 
295
                if (size > 0)
-
 
296
                {
-
 
297
                    void* buf = memalign(0x10, size);
-
 
298
                    if (buf)
-
 
299
                    {
-
 
300
                        if (read(fd, buf, size) == size) firmware = buf;
-
 
301
                        else free(buf);
-
 
302
                    }
-
 
303
                }
-
 
304
                close(fd);
-
 
305
            }
-
 
306
            if (!firmware)
-
 
307
            {
-
 
308
                rendertext(framebuf2, 7, 73, 176, 0xff3333ff, 0xa0000000, "Loading appleos.bin failed!");
-
 
309
                rendertext(framebuf2, 7, 81, 176, 0xff3333ff, 0xa0000000, "  Returning to main menu.  ");
-
 
310
                displaylcd(0, 0, 176, 132, framebuf2, 0, 0, 176);
-
 
311
                sleep(5000000);
-
 
312
            }
-
 
313
            break;
-
 
314
        }
-
 
315
        case 2:
-
 
316
        {
-
 
317
            int i;
-
 
318
            for (i = 2; i <= 52; i += 10)
-
 
319
            {
-
 
320
                if (i < 52)
-
 
321
                    ui->blend(176, 132, 50, framebuf, 0, 0, 176,
-
 
322
                              framebuf, 0, 0, 176, bg, 0, 0, 176);
-
 
323
                else memcpy(framebuf, bg, 176 * 132 * 3);
-
 
324
                ui->blit(154, MIN(47, i), 3, framebuf, 11, MAX(0, i - 47), 176,
-
 
325
                         rbxlogo, 0, MAX(0, 47 - i), 154);
-
 
326
                displaylcd(0, 0, 176, 132, framebuf, 0, 0, 176);
-
 
327
            }
-
 
328
            int fd = file_open("/.rockbox/rockbox.ipod", O_RDONLY);
-
 
329
            if (fd > 0)
-
 
330
            {
-
 
331
                size = filesize(fd);
-
 
332
                if (size > 0)
-
 
333
                {
-
 
334
                    void* buf = memalign(0x10, size);
-
 
335
                    if (buf)
-
 
336
                    {
-
 
337
                        if (read(fd, buf, size) == size)
-
 
338
                            if (!boot->verify_rockbox_checksum(buf, size))
-
 
339
                                firmware = buf;
-
 
340
                        if (!firmware) free(buf);
-
 
341
                    }
-
 
342
                }
-
 
343
                close(fd);
-
 
344
            }
-
 
345
            if (!firmware)
-
 
346
            {
-
 
347
                rendertext(framebuf, 4, 73, 176, 0xff3333ff, 0xa0000000, "Loading rockbox.ipod failed!");
-
 
348
                rendertext(framebuf, 4, 81, 176, 0xff3333ff, 0xa0000000, "  Trying fallback image...  ");
-
 
349
                displaylcd(0, 0, 176, 132, framebuf, 0, 0, 132);
-
 
350
                sleep(5000000);
-
 
351
                size = bootflash_filesize("rockbox ");
-
 
352
                if (size > 0)
-
 
353
                {
-
 
354
                    void* buf = memalign(0x10, size);
-
 
355
                    if (buf)
-
 
356
                    {
-
 
357
                        bootflash_read("rockbox ", buf, 0, size);
-
 
358
                        if (bootflash_attributes("rockbox ") & 0x800)
-
 
359
                        {
-
 
360
                            void* buf2 = malloc(0x100000);
-
 
361
                            if (buf2)
-
 
362
                            {
-
 
363
                                if (!ucl_decompress(buf, size, buf2, (uint32_t*)&size))
-
 
364
                                {
-
 
365
                                    free(buf);
-
 
366
                                    buf = realloc(buf2, size);
-
 
367
                                    if (!buf) buf = buf2;
-
 
368
                                    if (!boot->verify_rockbox_checksum(buf, size))
-
 
369
                                        firmware = buf;
-
 
370
                                    else free(buf);
-
 
371
                                }
-
 
372
                                else
-
 
373
                                {
-
 
374
                                    free(buf2);
-
 
375
                                    free(buf);
-
 
376
                                }
-
 
377
                            }
-
 
378
                            else free(buf);
-
 
379
                        }
-
 
380
                        else
-
 
381
                        {
-
 
382
                            if (!boot->verify_rockbox_checksum(buf, size)) firmware = buf;
-
 
383
                            else free(buf);
-
 
384
                        }
-
 
385
                    }
708
    void* app = NULL;
386
                }
-
 
387
            }
-
 
388
            if (!firmware)
-
 
389
            {
-
 
390
                memcpy(framebuf, bg, 176 * 132 * 3);
-
 
391
                rendertext(framebuf, 19, 73, 176, 0xff3333ff, 0xa0000000, "Loading Rockbox failed!");
-
 
392
                rendertext(framebuf, 19, 81, 176, 0xff3333ff, 0xa0000000, "Returning to main menu.");
-
 
393
                displaylcd(0, 0, 176, 132, framebuf, 0, 0, 176);
-
 
394
                sleep(5000000);
-
 
395
            }
-
 
396
            break;
-
 
397
        }
-
 
398
        case 3:
-
 
399
            goto leave;
-
 
400
        case 4:
-
 
401
            size = bootflash_filesize("umsboot ");
-
 
402
            if (size > 0)
-
 
403
            {
709
    int size;
404
                void* buf = memalign(0x10, size);
710
    run_mainchooser(&firmware, &app, &size);
405
                if (buf)
-
 
406
                {
-
 
407
                    bootflash_read("umsboot ", buf, 0, size);
-
 
408
                    if (bootflash_attributes("umsboot ") & 0x800)
-
 
409
                    {
-
 
410
                        void* buf2 = malloc(0x10000);
-
 
411
                        if (buf2)
-
 
412
                        {
-
 
413
                            if (!ucl_decompress(buf, size, buf2, (uint32_t*)&size))
-
 
414
                            {
-
 
415
                                free(buf);
-
 
416
                                buf = realloc(buf2, size);
-
 
417
                                if (!buf) buf = buf2;
-
 
418
                                firmware = buf;
-
 
419
                            }
-
 
420
                            else
-
 
421
                            {
-
 
422
                                free(buf2);
-
 
423
                                free(buf);
-
 
424
                            }
-
 
425
                        }
-
 
426
                        else free(buf);
-
 
427
                    }
-
 
428
                    else firmware = buf;
-
 
429
                }
-
 
430
            }
-
 
431
            if (!firmware)
-
 
432
            {
-
 
433
                memcpy(framebuf, bg, 176 * 132 * 3);
-
 
434
                rendertext(framebuf, 19, 73, 176, 0xff3333ff, 0xa0000000, "Loading UMSboot failed!");
-
 
435
                rendertext(framebuf, 19, 81, 176, 0xff3333ff, 0xa0000000, "Returning to main menu.");
-
 
436
                displaylcd(0, 0, 176, 132, framebuf, 0, 0, 132);
-
 
437
                sleep(5000000);
-
 
438
            }
-
 
439
            break;
-
 
440
        case 5:
-
 
441
            size = bootflash_filesize("diagmode");
-
 
442
            if (size > 0)
-
 
443
            {
-
 
444
                void* buf = memalign(0x10, size);
-
 
445
                if (buf)
-
 
446
                {
-
 
447
                    bootflash_read("diagmode", buf, 0, size);
-
 
448
                    if (bootflash_attributes("diagmode") & 0x800)
-
 
449
                    {
-
 
450
                        void* buf2 = malloc(0x80000);
-
 
451
                        if (buf2)
-
 
452
                        {
-
 
453
                            if (!ucl_decompress(buf, size, buf2, (uint32_t*)&size))
-
 
454
                            {
-
 
455
                                free(buf);
-
 
456
                                buf = realloc(buf2, size);
-
 
457
                                if (!buf) buf = buf2;
-
 
458
                                firmware = buf;
-
 
459
                            }
-
 
460
                            else
-
 
461
                            {
-
 
462
                                free(buf2);
-
 
463
                                free(buf);
-
 
464
                            }
-
 
465
                        }
-
 
466
                        else free(buf);
-
 
467
                    }
-
 
468
                    else firmware = buf;
-
 
469
                }
-
 
470
            }
-
 
471
            if (!firmware)
-
 
472
            {
-
 
473
                memcpy(framebuf, bg, 176 * 132 * 3);
-
 
474
                rendertext(framebuf, 13, 73, 176, 0xff3333ff, 0xa0000000, "Loading diag mode failed!");
-
 
475
                rendertext(framebuf, 13, 81, 176, 0xff3333ff, 0xa0000000, " Returning to main menu. ");
-
 
476
                displaylcd(0, 0, 176, 132, framebuf, 0, 0, 176);
-
 
477
                sleep(5000000);
-
 
478
            }
-
 
479
            break;
-
 
480
        case 6:
-
 
481
            size = bootflash_filesize("diskmode");
-
 
482
            if (size > 0)
-
 
483
            {
-
 
484
                void* buf = memalign(0x10, size);
-
 
485
                if (buf)
-
 
486
                {
-
 
487
                    bootflash_read("diskmode", buf, 0, size);
-
 
488
                    if (bootflash_attributes("diskmode") & 0x800)
-
 
489
                    {
-
 
490
                        void* buf2 = malloc(0x80000);
-
 
491
                        if (buf2)
-
 
492
                        {
-
 
493
                            if (!ucl_decompress(buf, size, buf2, (uint32_t*)&size))
-
 
494
                            {
-
 
495
                                free(buf);
-
 
496
                                buf = realloc(buf2, size);
-
 
497
                                if (!buf) buf = buf2;
-
 
498
                                firmware = buf;
-
 
499
                            }
-
 
500
                            else
-
 
501
                            {
-
 
502
                                free(buf2);
-
 
503
                                free(buf);
-
 
504
                            }
-
 
505
                        }
-
 
506
                        else free(buf);
-
 
507
                    }
-
 
508
                    else firmware = buf;
-
 
509
                }
-
 
510
            }
-
 
511
            if (!firmware)
-
 
512
            {
-
 
513
                memcpy(framebuf, bg, 176 * 132 * 3);
-
 
514
                rendertext(framebuf, 13, 73, 176, 0xff3333ff, 0xa0000000, "Loading disk mode failed!");
-
 
515
                rendertext(framebuf, 13, 81, 176, 0xff3333ff, 0xa0000000, " Returning to main menu. ");
-
 
516
                displaylcd(0, 0, 176, 132, framebuf, 0, 0, 176);
-
 
517
                sleep(5000000);
-
 
518
            }
-
 
519
            break;
-
 
520
        }
-
 
521
    }
711
 
522
leave:
-
 
523
    free(framebuf2);
712
    free(framebuf2);
524
    free(framebuf);
713
    free(framebuf);
525
    free(crapple);
714
    free(crapple);
526
    free(rbxlogo);
715
    free(rbxlogo);
527
    free(icons);
716
    free(icons);
528
    free(bg);
717
    free(bg);
529
    release_library(libui);
718
    release_library(libui);
530
    release_library(libpng);
-
 
531
    release_library(libboot);
719
    release_library(libboot);
532
    library_unload(libui);
720
    library_unload(libui);
533
    library_unload(libpng);
-
 
534
    library_unload(libboot);
721
    library_unload(libboot);
-
 
722
 
535
    if (firmware)
723
    if (firmware)
536
    {
724
    {
537
        shutdown(false);
725
        shutdown(false);
538
        execfirmware((void*)0x08000000, firmware, size);
726
        execfirmware((void*)0x08000000, firmware, size);
539
    }
727
    }
-
 
728
    else if (app) execimage(app, false);
540
    else cputs(3, "Dropped into emCORE console.\n");
729
    else cputs(3, "Dropped into emCORE console.\n");
541
}
730
}
542
 
731
 
543
 
732
 
544
EMCORE_APP_HEADER("Boot menu", main, 127)
733
EMCORE_APP_HEADER("Boot menu", main, 127)