2005-03-02 23:49:38 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* 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)
|
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
PLUGIN_HEADER
|
|
|
|
|
2005-03-02 23:49:38 +00:00
|
|
|
#define OVL_NAME "/.rockbox/viewers/rockboy.ovl"
|
|
|
|
#define OVL_DISPLAYNAME "RockBoy"
|
|
|
|
|
|
|
|
struct plugin_api* rb;
|
2005-04-05 11:33:58 +00:00
|
|
|
unsigned char *audiobuf;
|
|
|
|
int audiobuf_size;
|
2005-03-02 23:49:38 +00:00
|
|
|
|
|
|
|
/* this is the plugin entry point */
|
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|
|
|
{
|
2006-01-16 18:51:12 +00:00
|
|
|
int fd, readsize;
|
|
|
|
struct plugin_header header;
|
2005-03-02 23:49:38 +00:00
|
|
|
|
|
|
|
rb = api;
|
|
|
|
|
2006-01-16 18:51:12 +00:00
|
|
|
fd = rb->open(OVL_NAME, O_RDONLY);
|
|
|
|
if (fd < 0)
|
2005-03-02 23:49:38 +00:00
|
|
|
{
|
2006-01-16 18:51:12 +00:00
|
|
|
rb->splash(2*HZ, true, "Can't open " OVL_NAME);
|
2005-03-02 23:49:38 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
2006-01-16 18:51:12 +00:00
|
|
|
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))
|
2005-03-02 23:49:38 +00:00
|
|
|
{
|
2006-01-16 18:51:12 +00:00
|
|
|
rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed.");
|
2005-03-02 23:49:38 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
2006-01-16 18:51:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-04-05 11:33:58 +00:00
|
|
|
audiobuf = rb->plugin_get_audio_buffer(&audiobuf_size);
|
2006-01-16 18:51:12 +00:00
|
|
|
if (header.load_addr < audiobuf ||
|
2005-04-05 11:33:58 +00:00
|
|
|
header.end_addr > audiobuf + audiobuf_size)
|
2005-03-02 23:49:38 +00:00
|
|
|
{
|
|
|
|
rb->splash(2*HZ, true, OVL_DISPLAYNAME
|
2006-01-16 18:51:12 +00:00
|
|
|
" 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);
|
2005-03-02 23:49:38 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
2006-01-16 18:51:12 +00:00
|
|
|
readsize = rb->read(fd, header.load_addr, header.end_addr - header.load_addr);
|
|
|
|
rb->close(fd);
|
2006-01-08 23:45:29 +00:00
|
|
|
|
2006-01-16 18:51:12 +00:00
|
|
|
if (readsize < 0)
|
2005-03-02 23:49:38 +00:00
|
|
|
{
|
2006-01-16 18:51:12 +00:00
|
|
|
rb->splash(2*HZ, true, "Reading" OVL_DISPLAYNAME " overlay failed.");
|
2005-03-02 23:49:38 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
return header.entry_point(api, parameter);
|
|
|
|
}
|
|
|
|
#endif
|