2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2006-10-07 00:31:33 +00:00
|
|
|
*
|
2021-12-26 18:47:58 +01:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-02-18 02:34:19 +01:00
|
|
|
*
|
2006-10-07 00:31:33 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 02:34:19 +01:00
|
|
|
*
|
2006-10-07 00:31:33 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-10-07 00:31:33 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2021-09-23 23:01:39 +02:00
|
|
|
#define FORBIDDEN_SYMBOL_ALLOW_ALL
|
|
|
|
|
2010-11-29 16:18:43 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
|
2011-04-20 22:30:01 +02:00
|
|
|
#if defined(DYNAMIC_MODULES)
|
2006-10-07 00:31:33 +00:00
|
|
|
|
|
|
|
#include "backends/plugins/dynamic-plugin.h"
|
2008-09-30 16:34:38 +00:00
|
|
|
#include "common/fs.h"
|
2006-10-07 00:31:33 +00:00
|
|
|
|
|
|
|
#include "dcloader.h"
|
2021-10-30 16:35:56 +02:00
|
|
|
#include "dcutils.h"
|
2011-04-20 23:43:33 +02:00
|
|
|
|
|
|
|
static void drawPluginProgress(const Common::String &filename)
|
|
|
|
{
|
2021-10-30 16:35:56 +02:00
|
|
|
TextureStack txstack;
|
2011-04-29 22:22:58 +02:00
|
|
|
const char *fn = filename.c_str();
|
2011-04-20 23:43:33 +02:00
|
|
|
Label lab1, lab2, lab3;
|
|
|
|
char buf[32];
|
|
|
|
unsigned memleft = 0x8cf00000-((unsigned)sbrk(0));
|
|
|
|
float ffree = memleft*(1.0/(16<<20));
|
|
|
|
int fcol = (memleft < (1<<20)? 0xffff0000:
|
|
|
|
(memleft < (4<<20)? 0xffffff00: 0xff00ff00));
|
|
|
|
snprintf(buf, sizeof(buf), "%dK free memory", memleft>>10);
|
2011-04-29 22:22:58 +02:00
|
|
|
if (fn[0] == '/') fn++;
|
2011-04-20 23:43:33 +02:00
|
|
|
lab1.create_texture("Loading plugins, please wait...");
|
2011-04-29 22:22:58 +02:00
|
|
|
lab2.create_texture(fn);
|
2011-04-20 23:43:33 +02:00
|
|
|
lab3.create_texture(buf);
|
|
|
|
ta_begin_frame();
|
2011-04-29 22:22:58 +02:00
|
|
|
draw_solid_quad(80.0, 270.0, 560.0, 300.0,
|
2011-04-20 23:43:33 +02:00
|
|
|
0xff808080, 0xff808080, 0xff808080, 0xff808080);
|
2011-06-20 00:59:48 +02:00
|
|
|
draw_solid_quad(85.0, 275.0, 555.0, 295.0,
|
2011-04-20 23:43:33 +02:00
|
|
|
0xff202020, 0xff202020, 0xff202020, 0xff202020);
|
2011-04-29 22:22:58 +02:00
|
|
|
draw_solid_quad(85.0, 275.0, 85.0+470.0*ffree, 295.0,
|
2011-04-20 23:43:33 +02:00
|
|
|
fcol, fcol, fcol, fcol);
|
|
|
|
ta_commit_end();
|
2011-04-29 22:22:58 +02:00
|
|
|
lab1.draw(100.0, 150.0, 0xffffffff);
|
|
|
|
lab2.draw(100.0, 190.0, 0xffaaffaa);
|
|
|
|
lab3.draw(100.0, 230.0, 0xffffffff);
|
2011-04-20 23:43:33 +02:00
|
|
|
ta_commit_frame();
|
2021-09-23 23:01:39 +02:00
|
|
|
}
|
|
|
|
|
2011-04-20 22:30:01 +02:00
|
|
|
class OSystem_Dreamcast::DCPlugin : public DynamicPlugin {
|
2006-10-07 00:31:33 +00:00
|
|
|
protected:
|
|
|
|
void *_dlHandle;
|
2021-09-23 23:01:39 +02:00
|
|
|
DiscLabel _label;
|
2006-10-07 00:31:33 +00:00
|
|
|
|
|
|
|
virtual VoidFunc findSymbol(const char *symbol) {
|
|
|
|
void *func = dlsym(_dlHandle, symbol);
|
|
|
|
if (!func)
|
|
|
|
warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), dlerror());
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-10-07 00:31:33 +00:00
|
|
|
// FIXME HACK: This is a HACK to circumvent a clash between the ISO C++
|
|
|
|
// standard and POSIX: ISO C++ disallows casting between function pointers
|
|
|
|
// and data pointers, but dlsym always returns a void pointer. For details,
|
|
|
|
// see e.g. <http://www.trilithium.com/johan/2004/12/problem-with-dlsym/>.
|
|
|
|
assert(sizeof(VoidFunc) == sizeof(func));
|
|
|
|
VoidFunc tmp;
|
|
|
|
memcpy(&tmp, &func, sizeof(VoidFunc));
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2021-09-23 23:01:39 +02:00
|
|
|
void checkDisc(const DiscLabel &);
|
|
|
|
|
2006-10-07 00:31:33 +00:00
|
|
|
public:
|
|
|
|
DCPlugin(const Common::String &filename)
|
2010-12-29 15:25:21 +00:00
|
|
|
: DynamicPlugin(filename), _dlHandle(0) {}
|
2006-10-07 00:31:33 +00:00
|
|
|
|
|
|
|
bool loadPlugin() {
|
|
|
|
assert(!_dlHandle);
|
2021-09-23 23:01:39 +02:00
|
|
|
DiscLabel original;
|
|
|
|
checkDisc(_label);
|
2011-04-20 23:43:33 +02:00
|
|
|
drawPluginProgress(_filename);
|
2006-10-07 00:31:33 +00:00
|
|
|
_dlHandle = dlopen(_filename.c_str(), RTLD_LAZY);
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-10-07 00:31:33 +00:00
|
|
|
if (!_dlHandle) {
|
2021-09-23 23:01:39 +02:00
|
|
|
checkDisc(original);
|
2006-10-07 00:31:33 +00:00
|
|
|
warning("Failed loading plugin '%s' (%s)", _filename.c_str(), dlerror());
|
|
|
|
return false;
|
|
|
|
}
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-10-07 00:31:33 +00:00
|
|
|
bool ret = DynamicPlugin::loadPlugin();
|
2008-01-27 19:47:41 +00:00
|
|
|
|
2006-10-07 00:31:33 +00:00
|
|
|
if (ret)
|
|
|
|
dlforgetsyms(_dlHandle);
|
|
|
|
|
2021-09-23 23:01:39 +02:00
|
|
|
checkDisc(original);
|
2006-10-07 00:31:33 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2008-05-02 14:30:06 +00:00
|
|
|
|
2006-10-07 00:31:33 +00:00
|
|
|
void unloadPlugin() {
|
2008-02-04 07:38:42 +00:00
|
|
|
DynamicPlugin::unloadPlugin();
|
2006-10-07 00:31:33 +00:00
|
|
|
if (_dlHandle) {
|
|
|
|
if (dlclose(_dlHandle) != 0)
|
|
|
|
warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror());
|
2006-10-07 01:05:12 +00:00
|
|
|
_dlHandle = 0;
|
2006-10-07 00:31:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-23 23:01:39 +02:00
|
|
|
void OSystem_Dreamcast::DCPlugin::checkDisc(const DiscLabel &target)
|
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
DiscLabel current;
|
|
|
|
if (current == target)
|
|
|
|
return;
|
|
|
|
|
|
|
|
char buf[32+24];
|
2022-10-02 20:50:14 +02:00
|
|
|
Common::strcpy_s(buf, "Please insert disc '");
|
2021-09-23 23:01:39 +02:00
|
|
|
target.get(buf+strlen(buf));
|
2022-10-02 20:50:14 +02:00
|
|
|
Common::strcat_s(buf, "'");
|
2021-10-30 16:35:56 +02:00
|
|
|
DiscSwap(buf, 0xffffffff).run();
|
2021-09-23 23:01:39 +02:00
|
|
|
}
|
|
|
|
}
|
2006-10-07 00:31:33 +00:00
|
|
|
|
2011-04-20 22:30:01 +02:00
|
|
|
Plugin* OSystem_Dreamcast::createPlugin(const Common::FSNode &node) const {
|
2008-09-30 16:34:38 +00:00
|
|
|
return new DCPlugin(node.getPath());
|
2006-10-07 00:31:33 +00:00
|
|
|
}
|
|
|
|
|
2011-04-20 22:30:01 +02:00
|
|
|
bool OSystem_Dreamcast::isPluginFilename(const Common::FSNode &node) const {
|
2008-05-13 13:24:49 +00:00
|
|
|
// Check the plugin suffix
|
2008-09-30 16:34:38 +00:00
|
|
|
Common::String filename = node.getName();
|
2008-05-13 13:24:49 +00:00
|
|
|
if (!filename.hasSuffix(".PLG"))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-17 13:00:29 +02:00
|
|
|
void OSystem_Dreamcast::addCustomDirectories(Common::FSList &dirs) const
|
|
|
|
{
|
|
|
|
FilePluginProvider::addCustomDirectories(dirs);
|
|
|
|
if (pluginCustomDirectory != NULL)
|
2021-04-15 21:20:04 +02:00
|
|
|
dirs.push_back(Common::FSNode(pluginCustomDirectory));
|
2018-07-17 13:00:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginList OSystem_Dreamcast::getPlugins()
|
|
|
|
{
|
|
|
|
pluginCustomDirectory = NULL;
|
|
|
|
PluginList list = FilePluginProvider::getPlugins();
|
|
|
|
if (list.empty()) {
|
2021-04-15 21:20:04 +02:00
|
|
|
Common::String selection;
|
|
|
|
if (selectPluginDir(selection, Common::FSNode("plugins"))) {
|
|
|
|
pluginCustomDirectory = selection.c_str();
|
|
|
|
list = FilePluginProvider::getPlugins();
|
|
|
|
pluginCustomDirectory = NULL;
|
|
|
|
}
|
2018-07-17 13:00:29 +02:00
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-20 22:30:01 +02:00
|
|
|
#endif // defined(DYNAMIC_MODULES)
|