Subversion Repositories freemyipod

Rev

Rev 838 | Go to most recent revision | 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
        }
843 theseven 77
        if (success && execimage(buffer, false, 1, &theme_arg) != NULL)
78
            bootinfo.valid = true;
79
    }
671 theseven 80
 
838 theseven 81
    if (!bootinfo.valid)
671 theseven 82
    {
843 theseven 83
        settings_init();
828 theseven 84
 
843 theseven 85
        struct emcorelib_header* libboot = loadlib(LIBBOOT_IDENTIFIER,
86
                                                   LIBBOOT_API_VERSION, "libboot ");
87
        boot = (struct libboot_api*)libboot->api;
828 theseven 88
 
843 theseven 89
        if (!buttons)
90
            switch (settings.fastboot_item)
91
            {
92
                case 1:
93
                    fastboot_crapple();
94
                    break;
95
 
96
                case 2:
97
                    fastboot_rockbox();
98
                    break;
99
 
100
                case 3:
101
                    fastboot_diskmode();
102
                    break;
103
 
104
                case 4:
105
                    fastboot_umsboot();
106
                    break;
107
 
108
                case 5:
109
                    bootinfo.valid = true;
110
                    break;
111
            }
671 theseven 112
 
843 theseven 113
        if (!bootinfo.valid)
114
        {
115
            struct emcorelib_header* libpng = loadlib(LIBPNG_IDENTIFIER,
116
                                                      LIBPNG_API_VERSION, "libpng  ");
117
            struct libpng_api* png = (struct libpng_api*)libpng->api;
118
            bg = loadpng(png, background_png, background_png_size,
119
                         (void* (*)(struct png_info*))(png->png_decode_rgb));
120
            icons = loadpng(png, icons_png, icons_png_size,
121
                            (void* (*)(struct png_info*))(png->png_decode_rgba));
122
            rbxlogo = loadpng(png, rockbox_png, rockbox_png_size,
123
                              (void* (*)(struct png_info*))(png->png_decode_rgb));
124
            crapple = loadpng(png, crapple_png, crapple_png_size,
125
                              (void* (*)(struct png_info*))(png->png_decode_rgba));
126
            release_library(libpng);
127
            library_unload(libpng);
128
 
129
            struct emcorelib_header* libui = loadlib(LIBUI_IDENTIFIER,
130
                                                     LIBUI_API_VERSION, "libui   ");
131
            ui = (struct libui_api*)libui->api;
132
 
133
            framebuf = malloc(176 * 132 * 3);
134
            if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
135
            framebuf2 = malloc(176 * 132 * 3);
136
            if (!framebuf2) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer 2!");
671 theseven 137
 
843 theseven 138
            mainchooser_init();
139
            toolchooser_init();
140
            settingchooser_init();
141
            confirmchooser_init();
142
 
143
            run_mainchooser();
144
 
145
            free(framebuf2);
146
            free(framebuf);
147
            free(rbxlogo);
148
            free(icons);
149
            free(bg);
150
            release_library(libui);
151
            library_unload(libui);
152
        }
671 theseven 153
 
843 theseven 154
        release_library(libboot);
155
        library_unload(libboot);
156
    }
157
 
838 theseven 158
    if (bootinfo.firmware)
528 theseven 159
    {
160
        shutdown(false);
838 theseven 161
        execfirmware((void*)0x08000000, bootinfo.firmware, bootinfo.size);
528 theseven 162
    }
838 theseven 163
    else if (bootinfo.app) execimage(bootinfo.app, false, bootinfo.argc, bootinfo.argv);
528 theseven 164
    else cputs(3, "Dropped into emCORE console.\n");
165
}
166
 
167
EMCORE_APP_HEADER("Boot menu", main, 127)