Subversion Repositories freemyipod

Rev

Rev 843 | 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
        }
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:
93
                fastboot_umsboot();
94
                break;
95
 
96
            case 3:
97
                bootinfo.valid = true;
98
                break;
99
        }
100
 
834 theseven 101
    if (!bootinfo.valid)
660 theseven 102
    {
848 theseven 103
        struct emcorelib_header* libpng = loadlib(LIBPNG_IDENTIFIER,
104
                                                  LIBPNG_API_VERSION, "libpng  ");
105
        struct libpng_api* png = (struct libpng_api*)libpng->api;
106
        bg = loadpng(png, background_png, background_png_size,
107
                     (void* (*)(struct png_info*))(png->png_decode_rgb));
108
        icons = loadpng(png, icons_png, icons_png_size,
109
                        (void* (*)(struct png_info*))(png->png_decode_rgba));
110
        rbxlogo = loadpng(png, rockbox_png, rockbox_png_size,
111
                          (void* (*)(struct png_info*))(png->png_decode_rgb));
112
        release_library(libpng);
113
        library_unload(libpng);
808 theseven 114
 
848 theseven 115
        struct emcorelib_header* libui = loadlib(LIBUI_IDENTIFIER,
116
                                                 LIBUI_API_VERSION, "libui   ");
117
        ui = (struct libui_api*)libui->api;
808 theseven 118
 
848 theseven 119
        framebuf = malloc(320 * 240 * 3);
120
        if (!framebuf) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer!");
121
        framebuf2 = malloc(320 * 240 * 3);
122
        if (!framebuf2) panicf(PANIC_KILLTHREAD, "Could not allocate framebuffer 2!");
660 theseven 123
 
848 theseven 124
        mainchooser_init();
125
        toolchooser_init();
126
        settingchooser_init();
127
        confirmchooser_init();
128
 
129
        run_mainchooser();
130
 
131
        free(framebuf2);
132
        free(framebuf);
133
        free(rbxlogo);
134
        free(icons);
135
        free(bg);
136
        release_library(libui);
137
        library_unload(libui);
138
    }
528 theseven 139
 
848 theseven 140
    release_library(libboot);
141
    library_unload(libboot);
843 theseven 142
 
834 theseven 143
    if (bootinfo.firmware)
528 theseven 144
    {
145
        shutdown(false);
834 theseven 146
        execfirmware((void*)0x08000000, bootinfo.firmware, bootinfo.size);
528 theseven 147
    }
834 theseven 148
    else if (bootinfo.app) execimage(bootinfo.app, false, bootinfo.argc, bootinfo.argv);
528 theseven 149
    else cputs(3, "Dropped into emCORE console.\n");
150
}
151
 
152
EMCORE_APP_HEADER("Boot menu", main, 127)