summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2006-02-23 20:46:33 +0000
committerJens Arnold <amiconn@rockbox.org>2006-02-23 20:46:33 +0000
commiteeec278d21ae258da9108bbbccf04d977c3d3bfa (patch)
treebcb651133b076f9adc62f25f72369db32bfdf4f8
parentdf25cd5376a34898702b173e4d52badc088afa9f (diff)
downloadrockbox-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
-rw-r--r--apps/plugins/lib/Makefile4
-rw-r--r--apps/plugins/lib/SOURCES9
-rwxr-xr-xapps/plugins/lib/overlay.c106
-rwxr-xr-xapps/plugins/lib/overlay.h34
-rw-r--r--apps/plugins/rockboy.c71
5 files changed, 152 insertions, 72 deletions
diff --git a/apps/plugins/lib/Makefile b/apps/plugins/lib/Makefile
index 9b4b0b6286..ca9c3f3576 100644
--- a/apps/plugins/lib/Makefile
+++ b/apps/plugins/lib/Makefile
@@ -17,8 +17,8 @@ ifdef APPEXTRA
17 INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA))) 17 INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA)))
18endif 18endif
19 19
20CFLAGS = $(GCCOPTS) \ 20CFLAGS = $(GCCOPTS) $(INCLUDES) $(TARGET) $(EXTRA_DEFINES) \
21$(INCLUDES) $(TARGET) $(EXTRA_DEFINES) -DMEM=${MEMORYSIZE} -DPLUGIN 21 -DTARGET_ID=$(TARGET_ID) -DMEM=${MEMORYSIZE} -DPLUGIN
22 22
23# Sectioned compilation for target 23# Sectioned compilation for target
24ifndef SIMVER 24ifndef SIMVER
diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES
index d9eb00ca4d..291bc21a1d 100644
--- a/apps/plugins/lib/SOURCES
+++ b/apps/plugins/lib/SOURCES
@@ -1,5 +1,4 @@
1configfile.c 1configfile.c
2highscore.c
3#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) && !defined(SIMULATOR) && \ 2#if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) && !defined(SIMULATOR) && \
4 (CONFIG_LCD != LCD_IPOD2BPP) 3 (CONFIG_LCD != LCD_IPOD2BPP)
5gray_core.c 4gray_core.c
@@ -7,8 +6,9 @@ gray_draw.c
7gray_parm.c 6gray_parm.c
8gray_scroll.c 7gray_scroll.c
9#endif 8#endif
10#ifdef HAVE_LCD_BITMAP 9highscore.c
11xlcd.c 10#ifndef SIMULATOR
11overlay.c
12#endif 12#endif
13#ifdef HAVE_LCD_CHARCELLS 13#ifdef HAVE_LCD_CHARCELLS
14playergfx.c 14playergfx.c
@@ -16,3 +16,6 @@ playergfx.c
16#ifdef RB_PROFILE 16#ifdef RB_PROFILE
17profile_plugin.c 17profile_plugin.c
18#endif 18#endif
19#ifdef HAVE_LCD_BITMAP
20xlcd.c
21#endif
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
46enum 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
diff --git a/apps/plugins/lib/overlay.h b/apps/plugins/lib/overlay.h
new file mode 100755
index 0000000000..bbf7549274
--- /dev/null
+++ b/apps/plugins/lib/overlay.h
@@ -0,0 +1,34 @@
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 __OVERLAY_H__
23#define __OVERLAY_H__
24
25#ifndef SIMULATOR
26#include "plugin.h"
27
28/* load and run a plugin linked as an overlay. */
29enum plugin_status run_overlay(struct plugin_api* api, void* parameter,
30 unsigned char *filename, unsigned char *name);
31
32#endif /* !SIMULATOR */
33#endif /* __OVERLAY_H__ */
34
diff --git a/apps/plugins/rockboy.c b/apps/plugins/rockboy.c
index f571894717..9ff176cd25 100644
--- a/apps/plugins/rockboy.c
+++ b/apps/plugins/rockboy.c
@@ -9,7 +9,7 @@
9 * 9 *
10 * Copyright (C) 2005 Jens Arnold 10 * Copyright (C) 2005 Jens Arnold
11 * 11 *
12 * Overlay loader for rockboy on Archos 12 * Overlay loader stub plugin for rockboy on Archos
13 * 13 *
14 * All files in this archive are subject to the GNU General Public License. 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. 15 * See the file COPYING in the source tree root for full license agreement.
@@ -22,76 +22,13 @@
22 22
23#if MEM <= 8 && !defined(SIMULATOR) 23#if MEM <= 8 && !defined(SIMULATOR)
24 24
25PLUGIN_HEADER 25#include "overlay.h"
26
27#define OVL_NAME "/.rockbox/viewers/rockboy.ovl"
28#define OVL_DISPLAYNAME "RockBoy"
29 26
30struct plugin_api* rb; 27PLUGIN_HEADER
31unsigned char *audiobuf;
32int audiobuf_size;
33 28
34/* this is the plugin entry point */ 29/* this is the plugin entry point */
35enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 30enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
36{ 31{
37 int fd, readsize; 32 return run_overlay(api, parameter, "/.rockbox/viewers/rockboy.ovl", "RockBoy");
38 struct plugin_header header;
39
40 rb = api;
41
42 fd = rb->open(OVL_NAME, O_RDONLY);
43 if (fd < 0)
44 {
45 rb->splash(2*HZ, true, "Can't open " OVL_NAME);
46 return PLUGIN_ERROR;
47 }
48 readsize = rb->read(fd, &header, sizeof(header));
49 rb->close(fd);
50 /* Close for now. Less code than doing it in all error checks.
51 * Would need to seek back anyway. */
52
53 if (readsize != sizeof(header))
54 {
55 rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed.");
56 return PLUGIN_ERROR;
57 }
58 if (header.magic != PLUGIN_MAGIC || header.target_id != TARGET_ID)
59 {
60 rb->splash(2*HZ, true, OVL_DISPLAYNAME
61 " overlay: Incompatible model.");
62 return PLUGIN_ERROR;
63 }
64 if (header.api_version != PLUGIN_API_VERSION)
65 {
66 rb->splash(2*HZ, true, OVL_DISPLAYNAME
67 " overlay: Incompatible version.");
68 return PLUGIN_ERROR;
69 }
70
71 audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size);
72 if (header.load_addr < audiobuf ||
73 header.end_addr > audiobuf + audiobuf_size)
74 {
75 rb->splash(2*HZ, true, OVL_DISPLAYNAME
76 " overlay doesn't fit into memory.");
77 return PLUGIN_ERROR;
78 }
79 rb->memset(header.load_addr, 0, header.end_addr - header.load_addr);
80
81 fd = rb->open(OVL_NAME, O_RDONLY);
82 if (fd < 0)
83 {
84 rb->splash(2*HZ, true, "Can't open " OVL_NAME);
85 return PLUGIN_ERROR;
86 }
87 readsize = rb->read(fd, header.load_addr, header.end_addr - header.load_addr);
88 rb->close(fd);
89
90 if (readsize < 0)
91 {
92 rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed.");
93 return PLUGIN_ERROR;
94 }
95 return header.entry_point(api, parameter);
96} 33}
97#endif 34#endif