diff options
author | Jens Arnold <amiconn@rockbox.org> | 2006-02-23 20:46:33 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2006-02-23 20:46:33 +0000 |
commit | eeec278d21ae258da9108bbbccf04d977c3d3bfa (patch) | |
tree | bcb651133b076f9adc62f25f72369db32bfdf4f8 /apps/plugins/lib/overlay.c | |
parent | df25cd5376a34898702b173e4d52badc088afa9f (diff) | |
download | rockbox-eeec278d21ae258da9108bbbccf04d977c3d3bfa.tar.gz rockbox-eeec278d21ae258da9108bbbccf04d977c3d3bfa.zip |
Made the overlay loader code part of the plugin library.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8813 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib/overlay.c')
-rwxr-xr-x | apps/plugins/lib/overlay.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/apps/plugins/lib/overlay.c b/apps/plugins/lib/overlay.c new file mode 100755 index 0000000000..31c2b00f91 --- /dev/null +++ b/apps/plugins/lib/overlay.c | |||
@@ -0,0 +1,106 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Overlay loader | ||
11 | * | ||
12 | * Copyright (C) 2006 Jens Arnold | ||
13 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef SIMULATOR | ||
23 | #include "plugin.h" | ||
24 | |||
25 | /* load and run a plugin linked as an overlay. | ||
26 | |||
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 | ||
32 | |||
33 | result: | ||
34 | return value from the overlay | ||
35 | |||
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. | ||
39 | |||
40 | If the overlayed plugin *does* use the audiobuffer itself, it needs | ||
41 | to make sure not to overwrite itself. | ||
42 | |||
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. */ | ||
45 | |||
46 | enum plugin_status run_overlay(struct plugin_api* rb, void* parameter, | ||
47 | unsigned char *filename, unsigned char *name) | ||
48 | { | ||
49 | int fd, readsize; | ||
50 | int audiobuf_size; | ||
51 | unsigned char *audiobuf; | ||
52 | static struct plugin_header header; | ||
53 | |||
54 | fd = rb->open(filename, O_RDONLY); | ||
55 | if (fd < 0) | ||
56 | { | ||
57 | rb->splash(2*HZ, true, "Can't open %s", filename); | ||
58 | return PLUGIN_ERROR; | ||
59 | } | ||
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. */ | ||
64 | |||
65 | if (readsize != sizeof(header)) | ||
66 | { | ||
67 | rb->splash(2*HZ, true, "Reading %s overlay failed.", name); | ||
68 | return PLUGIN_ERROR; | ||
69 | } | ||
70 | if (header.magic != PLUGIN_MAGIC || header.target_id != TARGET_ID) | ||
71 | { | ||
72 | rb->splash(2*HZ, true, "%s overlay: Incompatible model.", name); | ||
73 | return PLUGIN_ERROR; | ||
74 | } | ||
75 | if (header.api_version != PLUGIN_API_VERSION) | ||
76 | { | ||
77 | rb->splash(2*HZ, true, "%s overlay: Incompatible version.", name); | ||
78 | return PLUGIN_ERROR; | ||
79 | } | ||
80 | |||
81 | audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size); | ||
82 | if (header.load_addr < audiobuf || | ||
83 | header.end_addr > audiobuf + audiobuf_size) | ||
84 | { | ||
85 | rb->splash(2*HZ, true, "%s overlay doesn't fit into memory.", name); | ||
86 | return PLUGIN_ERROR; | ||
87 | } | ||
88 | rb->memset(header.load_addr, 0, header.end_addr - header.load_addr); | ||
89 | |||
90 | fd = rb->open(filename, O_RDONLY); | ||
91 | if (fd < 0) | ||
92 | { | ||
93 | rb->splash(2*HZ, true, "Can't open %s", filename); | ||
94 | return PLUGIN_ERROR; | ||
95 | } | ||
96 | readsize = rb->read(fd, header.load_addr, header.end_addr - header.load_addr); | ||
97 | rb->close(fd); | ||
98 | |||
99 | if (readsize < 0) | ||
100 | { | ||
101 | rb->splash(2*HZ, true, "Reading %s overlay failed.", name); | ||
102 | return PLUGIN_ERROR; | ||
103 | } | ||
104 | return header.entry_point(rb, parameter); | ||
105 | } | ||
106 | #endif | ||