Subversion Repositories freemyipod

Rev

Rev 843 | Details | Compare with Previous | Last modification | View Log | RSS feed

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