summaryrefslogtreecommitdiffstats
path: root/apps/plugins/rockboy.c
blob: f571894717fa24c192483d19e7f6d33051ee21cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2005 Jens Arnold
 *
 * Overlay loader for rockboy on Archos
 *
 * All files in this archive are subject to the GNU General Public License.
 * See the file COPYING in the source tree root for full license agreement.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/
#include "plugin.h"

#if MEM <= 8 && !defined(SIMULATOR)

PLUGIN_HEADER

#define OVL_NAME "/.rockbox/viewers/rockboy.ovl"
#define OVL_DISPLAYNAME "RockBoy"

struct plugin_api* rb;
unsigned char *audiobuf;
int audiobuf_size;

/* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
    int fd, readsize;
    struct plugin_header header;

    rb = api;

    fd = rb->open(OVL_NAME, O_RDONLY);
    if (fd < 0)
    {
        rb->splash(2*HZ, true, "Can't open " OVL_NAME);
        return PLUGIN_ERROR;
    }
    readsize = rb->read(fd, &header, sizeof(header));
    rb->close(fd);
    /* Close for now. Less code than doing it in all error checks.
     * Would need to seek back anyway. */

    if (readsize != sizeof(header))
    {
        rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed.");
        return PLUGIN_ERROR;
    }
    if (header.magic != PLUGIN_MAGIC || header.target_id != TARGET_ID)
    {
        rb->splash(2*HZ, true, OVL_DISPLAYNAME 
                               " overlay: Incompatible model.");
        return PLUGIN_ERROR;
    }
    if (header.api_version != PLUGIN_API_VERSION) 
    {
        rb->splash(2*HZ, true, OVL_DISPLAYNAME
                               " overlay: Incompatible version.");
        return PLUGIN_ERROR;
    }

    audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size);
    if (header.load_addr < audiobuf ||
        header.end_addr > audiobuf + audiobuf_size)
    {
        rb->splash(2*HZ, true, OVL_DISPLAYNAME 
                               " overlay doesn't fit into memory.");
        return PLUGIN_ERROR;
    }
    rb->memset(header.load_addr, 0, header.end_addr - header.load_addr);

    fd = rb->open(OVL_NAME, O_RDONLY);
    if (fd < 0)
    {
        rb->splash(2*HZ, true, "Can't open " OVL_NAME);
        return PLUGIN_ERROR;
    }
    readsize = rb->read(fd, header.load_addr, header.end_addr - header.load_addr);
    rb->close(fd);

    if (readsize < 0)
    {
        rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed.");
        return PLUGIN_ERROR;
    }
    return header.entry_point(api, parameter);
}
#endif