Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
671 theseven 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
 
528 theseven 24
#include "emcoreapp.h"
828 theseven 25
#include "resources.h"
26
#include "main.h"
27
#include "boot.h"
28
#include "settings.h"
29
#include "mainchooser.h"
30
#include "settingchooser.h"
31
#include "util.h"
528 theseven 32
 
768 user890104 33
 
671 theseven 34
struct libboot_api* boot;
35
struct libui_api* ui;
36
void* framebuf;
37
void* framebuf2;
38
void* bg;
39
void* icons;
40
void* rbxlogo;
41
void* crapple;
528 theseven 42
 
671 theseven 43
 
828 theseven 44
static void main()
671 theseven 45
{
828 theseven 46
    settings_init();
47
 
48
    struct emcorelib_header* libboot = loadlib(LIBBOOT_IDENTIFIER,
49
                                               LIBBOOT_API_VERSION, "libboot ");
50
    boot = (struct libboot_api*)libboot->api;
671 theseven 51
 
828 theseven 52
    bool terminate = false;
53
    void* firmware = NULL;
54
    void* app = NULL;
55
    int size;
671 theseven 56
 
828 theseven 57
    if (!(clickwheel_get_state() & 0x1f))
58
        switch (settings.fastboot_item)
671 theseven 59
        {
828 theseven 60
            case 1:
61
                fastboot_crapple(&firmware, &app, &size);
62
                break;
63
 
64
            case 2:
65
                fastboot_rockbox(&firmware, &app, &size);
66
                break;
67
 
68
            case 3:
69
                fastboot_diskmode(&firmware, &app, &size);
70
                break;
71
 
72
            case 4:
73
                fastboot_umsboot(&firmware, &app, &size);
74
                break;
75
 
76
            case 5:
77
                terminate = true;
78
                break;
671 theseven 79
        }
80
 
828 theseven 81
    if (!firmware && !app && !terminate)
671 theseven 82
    {
828 theseven 83
        struct emcorelib_header* libpng = loadlib(LIBPNG_IDENTIFIER, LIBPNG_API_VERSION, "libpng  ");
84
        struct libpng_api* png = (struct libpng_api*)libpng->api;
85
        bg = loadpng(png, background_png, background_png_size, (void* (*)(struct png_info*))(png->png_decode_rgb));
86
        icons = loadpng(png, icons_png, icons_png_size, (void* (*)(struct png_info*))(png->png_decode_rgba));
87
        rbxlogo = loadpng(png, rockbox_png, rockbox_png_size, (void* (*)(struct png_info*))(png->png_decode_rgb));
88
        crapple = loadpng(png, crapple_png, crapple_png_size, (void* (*)(struct png_info*))(png->png_decode_rgba));
89
        release_library(libpng);
90
        library_unload(libpng);
91
 
92
        struct emcorelib_header* libui = loadlib(LIBUI_IDENTIFIER, LIBUI_API_VERSION, "libui   ");
93
        ui = (struct libui_api*)libui->api;
94
 
95
        framebuf = malloc(176 * 132 * 3);
96
        if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
97
        framebuf2 = malloc(176 * 132 * 3);
98
        if (!framebuf2) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer 2!");
671 theseven 99
 
828 theseven 100
        mainchooser_init();
101
        toolchooser_init();
102
        settingchooser_init();
103
 
104
        run_mainchooser(&firmware, &app, &size);
105
 
106
        free(framebuf);
107
        free(rbxlogo);
108
        free(icons);
109
        free(bg);
110
        release_library(libui);
111
        library_unload(libui);
671 theseven 112
    }
113
 
545 theseven 114
    release_library(libboot);
528 theseven 115
    library_unload(libboot);
671 theseven 116
 
528 theseven 117
    if (firmware)
118
    {
119
        shutdown(false);
120
        execfirmware((void*)0x08000000, firmware, size);
121
    }
671 theseven 122
    else if (app) execimage(app, false);
528 theseven 123
    else cputs(3, "Dropped into emCORE console.\n");
124
}
125
 
126
EMCORE_APP_HEADER("Boot menu", main, 127)