Subversion Repositories freemyipod

Rev

Rev 838 | Details | Compare with Previous | 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;
838 theseven 42
struct bootinfo_t bootinfo =
43
{
44
    .valid = false,
45
    .firmware = NULL,
46
    .size = 0,
47
    .app = NULL,
48
    .argc = 0,
49
    .argv = NULL
50
};
528 theseven 51
 
671 theseven 52
 
835 theseven 53
static void main(int argc, const char** argv)
671 theseven 54
{
828 theseven 55
    settings_init();
56
 
57
    struct emcorelib_header* libboot = loadlib(LIBBOOT_IDENTIFIER,
58
                                               LIBBOOT_API_VERSION, "libboot ");
59
    boot = (struct libboot_api*)libboot->api;
671 theseven 60
 
828 theseven 61
    if (!(clickwheel_get_state() & 0x1f))
62
        switch (settings.fastboot_item)
671 theseven 63
        {
828 theseven 64
            case 1:
838 theseven 65
                fastboot_crapple();
828 theseven 66
                break;
67
 
68
            case 2:
838 theseven 69
                fastboot_rockbox();
828 theseven 70
                break;
71
 
72
            case 3:
838 theseven 73
                fastboot_diskmode();
828 theseven 74
                break;
75
 
76
            case 4:
838 theseven 77
                fastboot_umsboot();
828 theseven 78
                break;
79
 
80
            case 5:
838 theseven 81
                bootinfo.valid = true;
828 theseven 82
                break;
671 theseven 83
        }
84
 
838 theseven 85
    if (!bootinfo.valid)
671 theseven 86
    {
828 theseven 87
        struct emcorelib_header* libpng = loadlib(LIBPNG_IDENTIFIER, LIBPNG_API_VERSION, "libpng  ");
88
        struct libpng_api* png = (struct libpng_api*)libpng->api;
89
        bg = loadpng(png, background_png, background_png_size, (void* (*)(struct png_info*))(png->png_decode_rgb));
90
        icons = loadpng(png, icons_png, icons_png_size, (void* (*)(struct png_info*))(png->png_decode_rgba));
91
        rbxlogo = loadpng(png, rockbox_png, rockbox_png_size, (void* (*)(struct png_info*))(png->png_decode_rgb));
92
        crapple = loadpng(png, crapple_png, crapple_png_size, (void* (*)(struct png_info*))(png->png_decode_rgba));
93
        release_library(libpng);
94
        library_unload(libpng);
95
 
96
        struct emcorelib_header* libui = loadlib(LIBUI_IDENTIFIER, LIBUI_API_VERSION, "libui   ");
97
        ui = (struct libui_api*)libui->api;
98
 
99
        framebuf = malloc(176 * 132 * 3);
100
        if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
101
        framebuf2 = malloc(176 * 132 * 3);
102
        if (!framebuf2) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer 2!");
671 theseven 103
 
828 theseven 104
        mainchooser_init();
105
        toolchooser_init();
106
        settingchooser_init();
838 theseven 107
        confirmchooser_init();
108
        snow_init();
828 theseven 109
 
838 theseven 110
        run_mainchooser();
828 theseven 111
 
835 theseven 112
        free(framebuf2);
828 theseven 113
        free(framebuf);
114
        free(rbxlogo);
115
        free(icons);
116
        free(bg);
117
        release_library(libui);
118
        library_unload(libui);
671 theseven 119
    }
120
 
545 theseven 121
    release_library(libboot);
528 theseven 122
    library_unload(libboot);
671 theseven 123
 
838 theseven 124
    if (bootinfo.firmware)
528 theseven 125
    {
126
        shutdown(false);
838 theseven 127
        execfirmware((void*)0x08000000, bootinfo.firmware, bootinfo.size);
528 theseven 128
    }
838 theseven 129
    else if (bootinfo.app) execimage(bootinfo.app, false, bootinfo.argc, bootinfo.argv);
528 theseven 130
    else cputs(3, "Dropped into emCORE console.\n");
131
}
132
 
133
EMCORE_APP_HEADER("Boot menu", main, 127)