Subversion Repositories freemyipod

Rev

Rev 838 | Rev 848 | Go to most recent revision | 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
        }
843 theseven 76
        if (success && execimage(buffer, false, 1, &theme_arg) != NULL)
77
            bootinfo.valid = true;
78
    }
660 theseven 79
 
834 theseven 80
    if (!bootinfo.valid)
660 theseven 81
    {
843 theseven 82
        settings_init();
808 theseven 83
 
843 theseven 84
        struct emcorelib_header* libboot = loadlib(LIBBOOT_IDENTIFIER,
85
                                                   LIBBOOT_API_VERSION, "libboot ");
86
        boot = (struct libboot_api*)libboot->api;
808 theseven 87
 
843 theseven 88
        if (!buttons)
89
            switch (settings.fastboot_item)
90
            {
91
                case 1:
92
                    fastboot_rockbox();
93
                    break;
94
 
95
                case 2:
96
                    fastboot_umsboot();
97
                    break;
98
 
99
                case 3:
100
                    bootinfo.valid = true;
101
                    break;
102
            }
660 theseven 103
 
843 theseven 104
        if (!bootinfo.valid)
105
        {
106
            struct emcorelib_header* libpng = loadlib(LIBPNG_IDENTIFIER,
107
                                                      LIBPNG_API_VERSION, "libpng  ");
108
            struct libpng_api* png = (struct libpng_api*)libpng->api;
109
            bg = loadpng(png, background_png, background_png_size,
110
                         (void* (*)(struct png_info*))(png->png_decode_rgb));
111
            icons = loadpng(png, icons_png, icons_png_size,
112
                            (void* (*)(struct png_info*))(png->png_decode_rgba));
113
            rbxlogo = loadpng(png, rockbox_png, rockbox_png_size,
114
                              (void* (*)(struct png_info*))(png->png_decode_rgb));
115
            release_library(libpng);
116
            library_unload(libpng);
117
 
118
            struct emcorelib_header* libui = loadlib(LIBUI_IDENTIFIER,
119
                                                     LIBUI_API_VERSION, "libui   ");
120
            ui = (struct libui_api*)libui->api;
121
 
122
            framebuf = malloc(320 * 240 * 3);
123
            if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
124
            framebuf2 = malloc(320 * 240 * 3);
125
            if (!framebuf2) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer 2!");
528 theseven 126
 
843 theseven 127
            mainchooser_init();
128
            toolchooser_init();
129
            settingchooser_init();
130
            confirmchooser_init();
131
 
132
            run_mainchooser();
133
 
134
            free(framebuf2);
135
            free(framebuf);
136
            free(rbxlogo);
137
            free(icons);
138
            free(bg);
139
            release_library(libui);
140
            library_unload(libui);
141
        }
660 theseven 142
 
843 theseven 143
        release_library(libboot);
144
        library_unload(libboot);
145
    }
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)