Improve SDL port 'configure --prefix' error message
[kugel-rb.git] / apps / plugins / lib / overlay.c
blobf64df2982374d592369ed2b0ce66568f860003a0
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Overlay loader
12 * Copyright (C) 2006 Jens Arnold
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
24 #include "plugin.h"
25 #include "overlay.h"
27 /* load and run a plugin linked as an overlay.
29 arguments:
30 parameter = plugin parameter, passed on to the overlay
31 filename = overlay file name, absolute path as usual
32 name = overlay display name
34 result:
35 return value from the overlay
37 As long as a large plugin to be overlayed doesn't use the audiobuffer
38 itself, no adjustments in the plugin source code are necessary to make
39 it work as an overlay, it only needs an adapted linker script.
41 If the overlayed plugin *does* use the audiobuffer itself, it needs
42 to make sure not to overwrite itself.
44 The linker script for the overlay should use a base address towards the
45 end of the audiobuffer, just low enough to make the overlay fit. */
47 enum plugin_status run_overlay(const void* parameter,
48 unsigned char *filename, unsigned char *name)
50 size_t audiobuf_size;
51 unsigned char *audiobuf;
52 void *handle;
53 struct plugin_header *p_hdr;
54 struct lc_header *hdr;
56 audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size);
57 if (!audiobuf)
59 rb->splash(2*HZ, "Can't optain memory");
60 goto error;
63 handle = rb->lc_open(filename, audiobuf, audiobuf_size);
64 if (!handle)
66 rb->splashf(2*HZ, "Can't open %s", filename);
67 goto error;
70 p_hdr = rb->lc_get_header(handle);
71 if (!p_hdr)
73 rb->splash(2*HZ, "Can't get header");
74 goto error_close;
76 else
77 hdr = &p_hdr->lc_hdr;
79 if (hdr->magic != PLUGIN_MAGIC || hdr->target_id != TARGET_ID)
81 rb->splashf(2*HZ, "%s overlay: Incompatible model.", name);
82 goto error_close;
86 if (hdr->api_version > PLUGIN_API_VERSION
87 || hdr->api_version < PLUGIN_MIN_API_VERSION)
89 rb->splashf(2*HZ, "%s overlay: Incompatible version.", name);
90 goto error_close;
93 rb->lc_close(handle);
95 *(p_hdr->api) = rb;
96 return p_hdr->entry_point(parameter);
98 error_close:
99 rb->lc_close(handle);
100 error:
101 return PLUGIN_ERROR;