Subversion Repositories freemyipod

Rev

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