Subversion Repositories freemyipod

Rev

Rev 848 | 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
};
843 theseven 50
static const char* theme_arg = "--run-as-theme";
528 theseven 51
 
660 theseven 52
 
835 theseven 53
static void main(int argc, const char** argv)
660 theseven 54
{
843 theseven 55
    int buttons = clickwheel_get_state() & 0x1f;
808 theseven 56
 
843 theseven 57
    if (buttons != 6)
58
    {
59
        bool success = false;
60
        void* buffer = NULL;
61
        int fd = file_open("/.apps/bootmenu/theme.emcoreapp", O_RDONLY);
62
        if (fd > 0)
660 theseven 63
        {
843 theseven 64
            int size = filesize(fd);
65
            if (size > 0)
66
            {
67
                buffer = memalign(0x10, size);
68
                if (buffer)
69
                {
70
                    if (read(fd, buffer, size) == size) success = true;
71
                    else free(buffer);
72
                }
73
            }
74
            close(fd);
660 theseven 75
        }
848 theseven 76
        if (success && execimage(buffer, false, 1, &theme_arg) != NULL) return;
843 theseven 77
    }
660 theseven 78
 
848 theseven 79
    settings_init();
80
 
81
    struct emcorelib_header* libboot = loadlib(LIBBOOT_IDENTIFIER,
82
                                               LIBBOOT_API_VERSION, "libboot ");
83
    boot = (struct libboot_api*)libboot->api;
84
 
85
    if (!buttons)
86
        switch (settings.fastboot_item)
87
        {
88
            case 1:
89
                fastboot_rockbox();
90
                break;
91
 
92
            case 2:
919 user890104 93
                fastboot_diskmode();
94
                break;
95
 
96
            case 3:
848 theseven 97
                fastboot_umsboot();
98
                break;
99
 
919 user890104 100
            case 4:
848 theseven 101
                bootinfo.valid = true;
102
                break;
103
        }
104
 
834 theseven 105
    if (!bootinfo.valid)
660 theseven 106
    {
848 theseven 107
        struct emcorelib_header* libpng = loadlib(LIBPNG_IDENTIFIER,
108
                                                  LIBPNG_API_VERSION, "libpng  ");
109
        struct libpng_api* png = (struct libpng_api*)libpng->api;
110
        bg = loadpng(png, background_png, background_png_size,
111
                     (void* (*)(struct png_info*))(png->png_decode_rgb));
112
        icons = loadpng(png, icons_png, icons_png_size,
113
                        (void* (*)(struct png_info*))(png->png_decode_rgba));
114
        rbxlogo = loadpng(png, rockbox_png, rockbox_png_size,
115
                          (void* (*)(struct png_info*))(png->png_decode_rgb));
116
        release_library(libpng);
117
        library_unload(libpng);
808 theseven 118
 
848 theseven 119
        struct emcorelib_header* libui = loadlib(LIBUI_IDENTIFIER,
120
                                                 LIBUI_API_VERSION, "libui   ");
121
        ui = (struct libui_api*)libui->api;
808 theseven 122
 
848 theseven 123
        framebuf = malloc(320 * 240 * 3);
124
        if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
125
        framebuf2 = malloc(320 * 240 * 3);
126
        if (!framebuf2) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer 2!");
660 theseven 127
 
848 theseven 128
        mainchooser_init();
129
        toolchooser_init();
130
        settingchooser_init();
131
        confirmchooser_init();
132
 
133
        run_mainchooser();
134
 
135
        free(framebuf2);
136
        free(framebuf);
137
        free(rbxlogo);
138
        free(icons);
139
        free(bg);
140
        release_library(libui);
141
        library_unload(libui);
142
    }
528 theseven 143
 
848 theseven 144
    release_library(libboot);
145
    library_unload(libboot);
843 theseven 146
 
834 theseven 147
    if (bootinfo.firmware)
528 theseven 148
    {
149
        shutdown(false);
834 theseven 150
        execfirmware((void*)0x08000000, bootinfo.firmware, bootinfo.size);
528 theseven 151
    }
834 theseven 152
    else if (bootinfo.app) execimage(bootinfo.app, false, bootinfo.argc, bootinfo.argv);
528 theseven 153
    else cputs(3, "Dropped into emCORE console.\n");
154
}
155
 
156
EMCORE_APP_HEADER("Boot menu", main, 127)