Adapt the remaining plugins to put the greyscale isr on cop. Now they can be used...
[Rockbox.git] / apps / plugins / lib / overlay.c
blob6abde85fee05dcd74e26d6a3823301b05727f411
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Overlay loader
12 * Copyright (C) 2006 Jens Arnold
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef SIMULATOR
23 #include "plugin.h"
25 /* load and run a plugin linked as an overlay.
27 arguments:
28 rb = pointer to plugin api, also passed on to the overlay
29 parameter = plugin parameter, passed on to the overlay
30 filename = overlay file name, absolute path as usual
31 name = overlay display name
33 result:
34 return value from the overlay
36 As long as a large plugin to be overlayed doesn't use the audiobuffer
37 itself, no adjustments in the plugin source code are necessary to make
38 it work as an overlay, it only needs an adapted linker script.
40 If the overlayed plugin *does* use the audiobuffer itself, it needs
41 to make sure not to overwrite itself.
43 The linker script for the overlay should use a base address towards the
44 end of the audiobuffer, just low enough to make the overlay fit. */
46 enum plugin_status run_overlay(struct plugin_api* rb, void* parameter,
47 unsigned char *filename, unsigned char *name)
49 int fd, readsize;
50 ssize_t audiobuf_size;
51 unsigned char *audiobuf;
52 static struct plugin_header header;
54 fd = rb->open(filename, O_RDONLY);
55 if (fd < 0)
57 rb->splash(2*HZ, "Can't open %s", filename);
58 return PLUGIN_ERROR;
60 readsize = rb->read(fd, &header, sizeof(header));
61 rb->close(fd);
62 /* Close for now. Less code than doing it in all error checks.
63 * Would need to seek back anyway. */
65 if (readsize != sizeof(header))
67 rb->splash(2*HZ, "Reading %s overlay failed.", name);
68 return PLUGIN_ERROR;
70 if (header.magic != PLUGIN_MAGIC || header.target_id != TARGET_ID)
72 rb->splash(2*HZ, "%s overlay: Incompatible model.", name);
73 return PLUGIN_ERROR;
75 if (header.api_version != PLUGIN_API_VERSION)
77 rb->splash(2*HZ, "%s overlay: Incompatible version.", name);
78 return PLUGIN_ERROR;
81 audiobuf = rb->plugin_get_audio_buffer((size_t *)&audiobuf_size);
82 if (header.load_addr < audiobuf ||
83 header.end_addr > audiobuf + audiobuf_size)
85 rb->splash(2*HZ, "%s overlay doesn't fit into memory.", name);
86 return PLUGIN_ERROR;
89 fd = rb->open(filename, O_RDONLY);
90 if (fd < 0)
92 rb->splash(2*HZ, "Can't open %s", filename);
93 return PLUGIN_ERROR;
95 readsize = rb->read(fd, header.load_addr, header.end_addr - header.load_addr);
96 rb->close(fd);
98 if (readsize < 0)
100 rb->splash(2*HZ, "Reading %s overlay failed.", name);
101 return PLUGIN_ERROR;
103 /* Zero out bss area */
104 rb->memset(header.load_addr + readsize, 0,
105 header.end_addr - (header.load_addr + readsize));
107 return header.entry_point(rb, parameter);
109 #endif