Subversion Repositories freemyipod

Rev

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