diff options
74 files changed, 1877 insertions, 1877 deletions
diff --git a/engines/glk/blorb.cpp b/engines/glk/blorb.cpp index 24340fa2e5..e298e1ccc3 100644 --- a/engines/glk/blorb.cpp +++ b/engines/glk/blorb.cpp @@ -22,7 +22,7 @@ #include "glk/blorb.h" -namespace Gargoyle { +namespace Glk { #define giblorb_Inited_Magic 0xB7012BEDU @@ -540,4 +540,4 @@ bool Blorb::giblorb_is_resource_map(void) const { return _map != nullptr; } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/blorb.h b/engines/glk/blorb.h index 75f811ccfd..352d01aadc 100644 --- a/engines/glk/blorb.h +++ b/engines/glk/blorb.h @@ -26,7 +26,7 @@ #include "glk/glk_types.h" #include "glk/streams.h" -namespace Gargoyle { +namespace Glk { /** @@ -141,6 +141,6 @@ public: glui32 usage, glui32 *num, glui32 *min, glui32 *max); }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/conf.cpp b/engines/glk/conf.cpp index 45d6168a8f..ae99e6b09a 100644 --- a/engines/glk/conf.cpp +++ b/engines/glk/conf.cpp @@ -27,7 +27,7 @@ #include "common/config-manager.h" #include "common/system.h" -namespace Gargoyle { +namespace Glk { const byte WHITE[3] = { 0xff, 0xff, 0xff }; const byte BLUE[3] = { 0x00, 0x00, 0x60 }; @@ -251,4 +251,4 @@ void Conf::parseColor(const Common::String &str, byte *color) { } } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/conf.h b/engines/glk/conf.h index 6c9dbf9f56..fb684272a6 100644 --- a/engines/glk/conf.h +++ b/engines/glk/conf.h @@ -27,7 +27,7 @@ #include "glk/fonts.h" #include "glk/windows.h" -namespace Gargoyle { +namespace Glk { class Conf { private: @@ -131,6 +131,6 @@ public: extern Conf *g_conf; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/detection.cpp b/engines/glk/detection.cpp index 9266825fa2..893ed87177 100644 --- a/engines/glk/detection.cpp +++ b/engines/glk/detection.cpp @@ -20,7 +20,7 @@ * */ -#include "glk/gargoyle.h" +#include "glk/glk.h" #include "base/plugins.h" #include "common/md5.h" @@ -34,44 +34,44 @@ #define MAX_SAVES 99 -namespace Gargoyle { +namespace Glk { -struct GargoyleGameDescription { +struct GlkGameDescription { ADGameDescription _desc; Common::String _filename; InterpreterType _interpType; Common::String _md5; }; -const Common::String &GargoyleEngine::getFilename() const { +const Common::String &GlkEngine::getFilename() const { return _gameDescription->_filename; } -uint32 GargoyleEngine::getFeatures() const { +uint32 GlkEngine::getFeatures() const { return _gameDescription->_desc.flags; } -bool GargoyleEngine::isDemo() const { +bool GlkEngine::isDemo() const { return (bool)(_gameDescription->_desc.flags & ADGF_DEMO); } -Common::Language GargoyleEngine::getLanguage() const { +Common::Language GlkEngine::getLanguage() const { return _gameDescription->_desc.language; } -InterpreterType GargoyleEngine::getInterpreterType() const { +InterpreterType GlkEngine::getInterpreterType() const { return _gameDescription->_interpType; } -const Common::String &GargoyleEngine::getGameMD5() const { +const Common::String &GlkEngine::getGameMD5() const { return _gameDescription->_md5; } -} // End of namespace Gargoyle +} // End of namespace Glk #include "glk/frotz/detection_tables.h" -#define ZCODE(ID, NAME) { ID, Gargoyle::Frotz::NAME##_DESC } +#define ZCODE(ID, NAME) { ID, Glk::Frotz::NAME##_DESC } -static const PlainGameDescriptor gargoyleGames[] = { +static const PlainGameDescriptor glkGames[] = { {"zcode", "Zcode Games" }, {"scottadams", "Scott Adams Games"}, @@ -146,9 +146,9 @@ static const PlainGameDescriptor gargoyleGames[] = { #include "glk/scott/detection.h" #include "glk/scott/scott.h" -class GargoyleMetaEngine : public AdvancedMetaEngine { +class GlkMetaEngine : public AdvancedMetaEngine { public: - GargoyleMetaEngine() : AdvancedMetaEngine(Gargoyle::gameDescriptions, sizeof(Gargoyle::GargoyleGameDescription), gargoyleGames) { + GlkMetaEngine() : AdvancedMetaEngine(Glk::gameDescriptions, sizeof(Glk::GlkGameDescription), glkGames) { _maxScanDepth = 3; } @@ -172,7 +172,7 @@ public: virtual ADDetectedGames detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const override; }; -bool GargoyleMetaEngine::hasFeature(MetaEngineFeature f) const { +bool GlkMetaEngine::hasFeature(MetaEngineFeature f) const { return (f == kSupportsListSaves) || (f == kSupportsLoadingDuringStartup) || @@ -183,22 +183,22 @@ bool GargoyleMetaEngine::hasFeature(MetaEngineFeature f) const { (f == kSimpleSavesNames); } -bool Gargoyle::GargoyleEngine::hasFeature(EngineFeature f) const { +bool Glk::GlkEngine::hasFeature(EngineFeature f) const { return (f == kSupportsRTL) || (f == kSupportsLoadingDuringRuntime) || (f == kSupportsSavingDuringRuntime); } -bool GargoyleMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { - const Gargoyle::GargoyleGameDescription *gd = (const Gargoyle::GargoyleGameDescription *)desc; +bool GlkMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { + const Glk::GlkGameDescription *gd = (const Glk::GlkGameDescription *)desc; switch (gd->_interpType) { - case Gargoyle::INTERPRETER_FROTZ: - *engine = new Gargoyle::Frotz::Frotz(syst, gd); + case Glk::INTERPRETER_FROTZ: + *engine = new Glk::Frotz::Frotz(syst, gd); break; - case Gargoyle::INTERPRETER_SCOTT: - *engine = new Gargoyle::Scott::Scott(syst, gd); + case Glk::INTERPRETER_SCOTT: + *engine = new Glk::Scott::Scott(syst, gd); break; default: error("Unknown interpreter"); @@ -207,12 +207,12 @@ bool GargoyleMetaEngine::createInstance(OSystem *syst, Engine **engine, const AD return gd != 0; } -SaveStateList GargoyleMetaEngine::listSaves(const char *target) const { +SaveStateList GlkMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); Common::StringArray filenames; Common::String saveDesc; Common::String pattern = Common::String::format("%s.0##", target); - Gargoyle::SavegameHeader header; + Glk::SavegameHeader header; filenames = saveFileMan->listSavefiles(pattern); @@ -225,7 +225,7 @@ SaveStateList GargoyleMetaEngine::listSaves(const char *target) const { Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(*file); if (in) { - if (Gargoyle::FileStream::readSavegameHeader(in, header)) + if (Glk::FileStream::readSavegameHeader(in, header)) saveList.push_back(SaveStateDescriptor(slot, header._saveName)); delete in; @@ -238,22 +238,22 @@ SaveStateList GargoyleMetaEngine::listSaves(const char *target) const { return saveList; } -int GargoyleMetaEngine::getMaximumSaveSlot() const { +int GlkMetaEngine::getMaximumSaveSlot() const { return MAX_SAVES; } -void GargoyleMetaEngine::removeSaveState(const char *target, int slot) const { +void GlkMetaEngine::removeSaveState(const char *target, int slot) const { Common::String filename = Common::String::format("%s.%03d", target, slot); g_system->getSavefileManager()->removeSavefile(filename); } -SaveStateDescriptor GargoyleMetaEngine::querySaveMetaInfos(const char *target, int slot) const { +SaveStateDescriptor GlkMetaEngine::querySaveMetaInfos(const char *target, int slot) const { Common::String filename = Common::String::format("%s.%03d", target, slot); Common::InSaveFile *in = g_system->getSavefileManager()->openForLoading(filename); if (in) { - Gargoyle::SavegameHeader header; - if (Gargoyle::FileStream::readSavegameHeader(in, header)) { + Glk::SavegameHeader header; + if (Glk::FileStream::readSavegameHeader(in, header)) { // Create the return descriptor SaveStateDescriptor desc(slot, header._saveName); desc.setSaveDate(header._year, header._month, header._day); @@ -268,17 +268,17 @@ SaveStateDescriptor GargoyleMetaEngine::querySaveMetaInfos(const char *target, i return SaveStateDescriptor(); } -DetectedGames GargoyleMetaEngine::detectGames(const Common::FSList &fslist) const { +DetectedGames GlkMetaEngine::detectGames(const Common::FSList &fslist) const { DetectedGames detectedGames; - Gargoyle::Frotz::FrotzMetaEngine::detectGames(fslist, detectedGames); - Gargoyle::Scott::ScottMetaEngine::detectGames(fslist, detectedGames); + Glk::Frotz::FrotzMetaEngine::detectGames(fslist, detectedGames); + Glk::Scott::ScottMetaEngine::detectGames(fslist, detectedGames); return detectedGames; } -static Gargoyle::GargoyleGameDescription gameDescription; +static Glk::GlkGameDescription gameDescription; -ADDetectedGames GargoyleMetaEngine::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const { +ADDetectedGames GlkMetaEngine::detectGame(const Common::FSNode &parent, const FileMap &allFiles, Common::Language language, Common::Platform platform, const Common::String &extra) const { static char gameId[100]; strcpy(gameId, ConfMan.get("gameid").c_str()); Common::String filename = ConfMan.get("filename"); @@ -290,10 +290,10 @@ ADDetectedGames GargoyleMetaEngine::detectGame(const Common::FSNode &parent, con Common::File f; // Check each sub-engine for any detected games - if (Gargoyle::Frotz::FrotzMetaEngine::detectGames(fslist, detectedGames)) - gameDescription._interpType = Gargoyle::INTERPRETER_FROTZ; - else if (Gargoyle::Scott::ScottMetaEngine::detectGames(fslist, detectedGames)) - gameDescription._interpType = Gargoyle::INTERPRETER_SCOTT; + if (Glk::Frotz::FrotzMetaEngine::detectGames(fslist, detectedGames)) + gameDescription._interpType = Glk::INTERPRETER_FROTZ; + else if (Glk::Scott::ScottMetaEngine::detectGames(fslist, detectedGames)) + gameDescription._interpType = Glk::INTERPRETER_SCOTT; else // No match found, so return no results return results; @@ -317,7 +317,7 @@ ADDetectedGames GargoyleMetaEngine::detectGame(const Common::FSNode &parent, con } #if PLUGIN_ENABLED_DYNAMIC(GLK) -REGISTER_PLUGIN_DYNAMIC(GLK, PLUGIN_TYPE_ENGINE, GargoyleMetaEngine); +REGISTER_PLUGIN_DYNAMIC(GLK, PLUGIN_TYPE_ENGINE, GlkMetaEngine); #else -REGISTER_PLUGIN_STATIC(GLK, PLUGIN_TYPE_ENGINE, GargoyleMetaEngine); +REGISTER_PLUGIN_STATIC(GLK, PLUGIN_TYPE_ENGINE, GlkMetaEngine); #endif diff --git a/engines/glk/detection_tables.h b/engines/glk/detection_tables.h index 30491f6d9b..47a761e1f1 100644 --- a/engines/glk/detection_tables.h +++ b/engines/glk/detection_tables.h @@ -20,10 +20,10 @@ * */ -namespace Gargoyle { +namespace Glk { -static const GargoyleGameDescription gameDescriptions[] = { +static const GlkGameDescription gameDescriptions[] = { { AD_TABLE_END_MARKER, "", (InterpreterType)0, "" } }; -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/events.cpp b/engines/glk/events.cpp index 74a108e074..8f3d5ef190 100644 --- a/engines/glk/events.cpp +++ b/engines/glk/events.cpp @@ -22,13 +22,13 @@ #include "glk/events.h" #include "glk/conf.h" -#include "glk/gargoyle.h" +#include "glk/glk.h" #include "glk/screen.h" #include "glk/selection.h" #include "glk/windows.h" #include "graphics/cursorman.h" -namespace Gargoyle { +namespace Glk { const byte ARROW[] = { // byte 1: number of skipped pixels @@ -399,4 +399,4 @@ bool Events::isTimerExpired() const { return _timerMilli && g_system->getMillis() >= _timerTimeExpiry; } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/events.h b/engines/glk/events.h index 537813f314..f68fca9006 100644 --- a/engines/glk/events.h +++ b/engines/glk/events.h @@ -27,7 +27,7 @@ #include "graphics/surface.h" #include "glk/utils.h" -namespace Gargoyle { +namespace Glk { #define GAME_FRAME_RATE 100 #define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE) @@ -286,6 +286,6 @@ public: bool isTimerExpired() const; }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/fonts.cpp b/engines/glk/fonts.cpp index ee958b0e0c..bc699aff6e 100644 --- a/engines/glk/fonts.cpp +++ b/engines/glk/fonts.cpp @@ -23,13 +23,13 @@ #include "glk/fonts.h" #include "glk/glk_types.h" #include "glk/conf.h" -#include "glk/gargoyle.h" +#include "glk/glk.h" #include "common/memstream.h" #include "common/unzip.h" #include "graphics/fonts/ttf.h" #include "graphics/fontman.h" -namespace Gargoyle { +namespace Glk { #define FONTS_VERSION 1.0 #define FONTS_FILENAME "fonts.dat" @@ -154,4 +154,4 @@ size_t Fonts::stringWidthUni(int fontIdx, const Common::U32String &text, int spw return font->getStringWidth(text) * GLI_SUBPIX; } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/fonts.h b/engines/glk/fonts.h index db547aabc4..364b0239be 100644 --- a/engines/glk/fonts.h +++ b/engines/glk/fonts.h @@ -32,7 +32,7 @@ #include "common/ustr.h" #include "graphics/font.h" -namespace Gargoyle { +namespace Glk { #define FONTS_TOTAL 8 @@ -113,6 +113,6 @@ public: size_t stringWidthUni(int fontIdx, const Common::U32String &text, int spw = 0); }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/frotz/detection.cpp b/engines/glk/frotz/detection.cpp index 57965c8efb..36303d409b 100644 --- a/engines/glk/frotz/detection.cpp +++ b/engines/glk/frotz/detection.cpp @@ -26,7 +26,7 @@ #include "glk/frotz/detection_tables.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { bool FrotzMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) { @@ -77,4 +77,4 @@ bool FrotzMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g } } // End of namespace Frotz -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/detection.h b/engines/glk/frotz/detection.h index 7630cb3f0f..9cd9373b2b 100644 --- a/engines/glk/frotz/detection.h +++ b/engines/glk/frotz/detection.h @@ -26,7 +26,7 @@ #include "common/fs.h" #include "engines/game.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { class FrotzMetaEngine { @@ -38,6 +38,6 @@ public: }; } // End of namespace Frotz -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/frotz/detection_tables.cpp b/engines/glk/frotz/detection_tables.cpp index 3f619a5e4f..f52b099d75 100644 --- a/engines/glk/frotz/detection_tables.cpp +++ b/engines/glk/frotz/detection_tables.cpp @@ -22,7 +22,7 @@ #include "glk/frotz/detection_tables.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { const char *const AMFV_DESC = "A Mind Forever Voyaging"; @@ -82,4 +82,4 @@ const FrotzGameDescription FROTZ_GAMES[] = { } // End of namespace Frotz -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/detection_tables.h b/engines/glk/frotz/detection_tables.h index 48e0eb0a5a..51994ed967 100644 --- a/engines/glk/frotz/detection_tables.h +++ b/engines/glk/frotz/detection_tables.h @@ -23,7 +23,7 @@ #include "engines/advancedDetector.h" #include "common/language.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { /** @@ -82,4 +82,4 @@ extern const char *const ZORK3_DESC; extern const char *const ZTUU_DESC; } // End of namespace Frotz -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/frotz.cpp b/engines/glk/frotz/frotz.cpp index 0e516f0496..f30acd0a4b 100644 --- a/engines/glk/frotz/frotz.cpp +++ b/engines/glk/frotz/frotz.cpp @@ -24,12 +24,12 @@ #include "glk/frotz/frotz_types.h" #include "common/config-manager.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { Frotz *g_vm; -Frotz::Frotz(OSystem *syst, const GargoyleGameDescription *gameDesc) : +Frotz::Frotz(OSystem *syst, const GlkGameDescription *gameDesc) : Processor(syst, gameDesc) { g_vm = this; } @@ -95,4 +95,4 @@ Common::Error Frotz::saveGameState(int slot, const Common::String &desc) { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/frotz.h b/engines/glk/frotz/frotz.h index c1fe5dcab6..cecd88637a 100644 --- a/engines/glk/frotz/frotz.h +++ b/engines/glk/frotz/frotz.h @@ -25,7 +25,7 @@ #include "glk/frotz/processor.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { /** @@ -36,7 +36,7 @@ public: /** * Constructor */ - Frotz(OSystem *syst, const GargoyleGameDescription *gameDesc); + Frotz(OSystem *syst, const GlkGameDescription *gameDesc); /** * Destructor @@ -67,6 +67,6 @@ public: extern Frotz *g_vm; } // End of namespace Frotz -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/frotz/frotz_types.h b/engines/glk/frotz/frotz_types.h index 5aae3d07c3..e68f55e147 100644 --- a/engines/glk/frotz/frotz_types.h +++ b/engines/glk/frotz/frotz_types.h @@ -26,7 +26,7 @@ #include "glk/glk_types.h" #include "common/algorithm.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { #define MAX_UNDO_SLOTS 500 @@ -292,6 +292,6 @@ struct Redirect { }; } // End of namespace Frotz -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/frotz/glk_interface.cpp b/engines/glk/frotz/glk_interface.cpp index b2534385e4..da27382c04 100644 --- a/engines/glk/frotz/glk_interface.cpp +++ b/engines/glk/frotz/glk_interface.cpp @@ -22,11 +22,11 @@ #include "glk/frotz/glk_interface.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { -GlkInterface::GlkInterface(OSystem *syst, const GargoyleGameDescription *gameDesc) : - Glk(syst, gameDesc), +GlkInterface::GlkInterface(OSystem *syst, const GlkGameDescription *gameDesc) : + GlkAPI(syst, gameDesc), oldstyle(0), curstyle(0), cury(1), curx(1), fixforced(0), curr_fg(-2), curr_bg(-2), curr_font(1), prev_font(1), temp_font(0), curr_status_ht(0), mach_status_ht(0), gos_status(nullptr), gos_upper(nullptr), @@ -495,4 +495,4 @@ zchar GlkInterface::os_read_line(int max, zchar *buf, int timeout, int width, in } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/glk_interface.h b/engines/glk/frotz/glk_interface.h index e3fa2c9081..d78d49ffbb 100644 --- a/engines/glk/frotz/glk_interface.h +++ b/engines/glk/frotz/glk_interface.h @@ -23,10 +23,10 @@ #ifndef GLK_FROTZ_GLK_INTERFACE #define GLK_FROTZ_GLK_INTERFACE -#include "glk/glk.h" +#include "glk/glk_api.h" #include "glk/frotz/mem.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { enum SoundEffect { @@ -47,7 +47,7 @@ enum RestartAction { * Implements an intermediate interface on top of the GLK layer, providing screen * and sound effect handling */ -class GlkInterface : public Glk, public virtual UserOptions, public virtual Mem { +class GlkInterface : public GlkAPI, public virtual UserOptions, public virtual Mem { public: zchar statusline[256]; int oldstyle; @@ -181,7 +181,7 @@ public: /** * Constructor */ - GlkInterface(OSystem *syst, const GargoyleGameDescription *gameDesc); + GlkInterface(OSystem *syst, const GlkGameDescription *gameDesc); /** * Initialization @@ -190,6 +190,6 @@ public: }; } // End of namespace Frotz -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/frotz/mem.cpp b/engines/glk/frotz/mem.cpp index a7747f5698..378e49666d 100644 --- a/engines/glk/frotz/mem.cpp +++ b/engines/glk/frotz/mem.cpp @@ -25,7 +25,7 @@ #include "common/memstream.h" #include "common/textconsole.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { const Header::StoryEntry Header::RECORDS[25] = { @@ -416,4 +416,4 @@ void Mem::mem_undiff(zbyte *diff, long diff_length, zbyte *dest) { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/mem.h b/engines/glk/frotz/mem.h index de22006a33..43b272720e 100644 --- a/engines/glk/frotz/mem.h +++ b/engines/glk/frotz/mem.h @@ -25,7 +25,7 @@ #include "glk/frotz/frotz_types.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { #define SET_WORD(addr,v) zmp[addr] = hi(v); zmp[addr+1] = lo(v) @@ -275,6 +275,6 @@ public: }; } // End of namespace Frotz -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/frotz/processor.cpp b/engines/glk/frotz/processor.cpp index 1cdc67a589..a7cbad0427 100644 --- a/engines/glk/frotz/processor.cpp +++ b/engines/glk/frotz/processor.cpp @@ -23,7 +23,7 @@ #include "glk/frotz/processor.h" #include "glk/frotz/frotz.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { // TODO: Stubs to replace with actual code @@ -131,7 +131,7 @@ Opcode Processor::ext_opcodes[64] = { &Processor::z_buffer_screen, // spec 1.1 }; -Processor::Processor(OSystem *syst, const GargoyleGameDescription *gameDesc) : +Processor::Processor(OSystem *syst, const GlkGameDescription *gameDesc) : GlkInterface(syst, gameDesc), _finished(0), _sp(nullptr), _fp(nullptr), _frameCount(0), zargc(0), _decoded(nullptr), _encoded(nullptr), _resolution(0), @@ -661,4 +661,4 @@ void Processor::z_restore_undo(void) { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/processor.h b/engines/glk/frotz/processor.h index b5c113def0..4bd9d2c5af 100644 --- a/engines/glk/frotz/processor.h +++ b/engines/glk/frotz/processor.h @@ -28,7 +28,7 @@ #include "glk/frotz/frotz_types.h" #include "common/stack.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { #define TEXT_BUFFER_SIZE 200 @@ -1522,7 +1522,7 @@ public: /** * Constructor */ - Processor(OSystem *syst, const GargoyleGameDescription *gameDesc); + Processor(OSystem *syst, const GlkGameDescription *gameDesc); /** * Initialization @@ -1579,6 +1579,6 @@ public: }; } // End of namespace Frotz -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/frotz/processor_buffer.cpp b/engines/glk/frotz/processor_buffer.cpp index faec6ef33d..c4eaeaa42e 100644 --- a/engines/glk/frotz/processor_buffer.cpp +++ b/engines/glk/frotz/processor_buffer.cpp @@ -24,7 +24,7 @@ #include "common/algorithm.h" #include "common/textconsole.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { const char *const Processor::ERR_MESSAGES[ERR_NUM_ERRORS] = { @@ -189,4 +189,4 @@ void Processor::runtimeError(ErrorCode errNum) { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/processor_input.cpp b/engines/glk/frotz/processor_input.cpp index 6dda853fa0..af5c7dc42c 100644 --- a/engines/glk/frotz/processor_input.cpp +++ b/engines/glk/frotz/processor_input.cpp @@ -22,7 +22,7 @@ #include "glk/frotz/processor.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { #define INPUT_BUFFER_SIZE 200 @@ -220,4 +220,4 @@ void Processor::z_read_mouse(){ } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/processor_maths.cpp b/engines/glk/frotz/processor_maths.cpp index 90e09ca8b9..5a2a522cc2 100644 --- a/engines/glk/frotz/processor_maths.cpp +++ b/engines/glk/frotz/processor_maths.cpp @@ -22,7 +22,7 @@ #include "glk/frotz/processor.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { void Processor::z_add() { @@ -102,4 +102,4 @@ void Processor::z_test() { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/processor_mem.cpp b/engines/glk/frotz/processor_mem.cpp index 7c7af0d2f5..dec7520084 100644 --- a/engines/glk/frotz/processor_mem.cpp +++ b/engines/glk/frotz/processor_mem.cpp @@ -22,7 +22,7 @@ #include "glk/frotz/processor.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { void Processor::flagsChanged(zbyte value) { @@ -215,4 +215,4 @@ void Processor::memory_close(void) { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/processor_objects.cpp b/engines/glk/frotz/processor_objects.cpp index 7e1fe6de0c..13e8a11518 100644 --- a/engines/glk/frotz/processor_objects.cpp +++ b/engines/glk/frotz/processor_objects.cpp @@ -22,7 +22,7 @@ #include "glk/frotz/processor.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { #define MAX_OBJECT 2000 @@ -729,4 +729,4 @@ void Processor::z_test_attr() { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/processor_screen.cpp b/engines/glk/frotz/processor_screen.cpp index 87c190f3c5..6c25ef9a0d 100644 --- a/engines/glk/frotz/processor_screen.cpp +++ b/engines/glk/frotz/processor_screen.cpp @@ -22,7 +22,7 @@ #include "glk/frotz/processor.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { void Processor::screen_mssg_on() { @@ -525,4 +525,4 @@ void Processor::z_split_window() { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/processor_streams.cpp b/engines/glk/frotz/processor_streams.cpp index b7b23b2db9..8413f4bb6e 100644 --- a/engines/glk/frotz/processor_streams.cpp +++ b/engines/glk/frotz/processor_streams.cpp @@ -23,7 +23,7 @@ #include "glk/frotz/processor.h" #include "glk/frotz/quetzal.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { zchar Processor::console_read_input(int max, zchar *buf, zword timeout, bool continued) { @@ -783,4 +783,4 @@ void Processor::z_verify() { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/processor_table.cpp b/engines/glk/frotz/processor_table.cpp index bb163899af..c586355038 100644 --- a/engines/glk/frotz/processor_table.cpp +++ b/engines/glk/frotz/processor_table.cpp @@ -22,7 +22,7 @@ #include "glk/frotz/processor.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { void Processor::z_copy_table() { @@ -117,4 +117,4 @@ void Processor::z_storew() { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/processor_text.cpp b/engines/glk/frotz/processor_text.cpp index e05879398e..3cfe50b44a 100644 --- a/engines/glk/frotz/processor_text.cpp +++ b/engines/glk/frotz/processor_text.cpp @@ -22,7 +22,7 @@ #include "glk/frotz/processor.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { zchar Processor::ZSCII_TO_LATIN1[] = { @@ -883,4 +883,4 @@ void Processor::z_tokenise() { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/processor_variables.cpp b/engines/glk/frotz/processor_variables.cpp index 0162f84d17..6e6a19191e 100644 --- a/engines/glk/frotz/processor_variables.cpp +++ b/engines/glk/frotz/processor_variables.cpp @@ -22,7 +22,7 @@ #include "glk/frotz/processor.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { void Processor::z_dec() { @@ -196,4 +196,4 @@ void Processor::z_store() { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/quetzal.cpp b/engines/glk/frotz/quetzal.cpp index a7b48fc699..9ff33ab8ae 100644 --- a/engines/glk/frotz/quetzal.cpp +++ b/engines/glk/frotz/quetzal.cpp @@ -24,7 +24,7 @@ #include "glk/frotz/processor.h" #include "common/memstream.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { /** @@ -482,4 +482,4 @@ int Quetzal::restore(Common::SeekableReadStream *svf, Processor *proc) { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/frotz/quetzal.h b/engines/glk/frotz/quetzal.h index bbd4496a45..9d382abaf0 100644 --- a/engines/glk/frotz/quetzal.h +++ b/engines/glk/frotz/quetzal.h @@ -26,7 +26,7 @@ #include "glk/glk_types.h" #include "glk/frotz/frotz_types.h" -namespace Gargoyle { +namespace Glk { namespace Frotz { enum QueztalTag { @@ -92,6 +92,6 @@ public: }; } // End of namespace Frotz -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/gargoyle.cpp b/engines/glk/gargoyle.cpp deleted file mode 100644 index 702efe7443..0000000000 --- a/engines/glk/gargoyle.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* 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. - * - * 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 2 - * of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include "common/scummsys.h" -#include "common/config-manager.h" -#include "common/debug-channels.h" -#include "common/events.h" -#include "common/file.h" -#include "engines/util.h" -#include "graphics/scaler.h" -#include "graphics/thumbnail.h" -#include "glk/gargoyle.h" -#include "glk/conf.h" -#include "glk/events.h" -#include "glk/picture.h" -#include "glk/screen.h" -#include "glk/selection.h" -#include "glk/streams.h" -#include "glk/windows.h" - -namespace Gargoyle { - -GargoyleEngine *g_vm; - -GargoyleEngine::GargoyleEngine(OSystem *syst, const GargoyleGameDescription *gameDesc) : - _gameDescription(gameDesc), Engine(syst), _random("Gargoyle"), _clipboard(nullptr), - _conf(nullptr), _events(nullptr), _picList(nullptr), _screen(nullptr), - _selection(nullptr), _windows(nullptr), _copySelect(false), _terminated(false), - gli_unregister_obj(nullptr), gli_register_arr(nullptr), gli_unregister_arr(nullptr) { - g_vm = this; -} - -GargoyleEngine::~GargoyleEngine() { - delete _clipboard; - delete _conf; - delete _events; - delete _picList; - delete _screen; - delete _selection; - delete _streams; - delete _windows; -} - -void GargoyleEngine::initialize() { - // Set up debug channels - DebugMan.addDebugChannel(kDebugCore, "core", "Core engine debug level"); - DebugMan.addDebugChannel(kDebugScripts, "scripts", "Game scripts"); - DebugMan.addDebugChannel(kDebugGraphics, "graphics", "Graphics handling"); - DebugMan.addDebugChannel(kDebugSound, "sound", "Sound and Music handling"); - - initGraphicsMode(); - _conf = new Conf(); - _screen = new Screen(); - - _clipboard = new Clipboard(); - _events = new Events(); - _picList = new PicList(); - _selection = new Selection(); - _streams = new Streams(); - _windows = new Windows(_screen); -} - -void GargoyleEngine::initGraphicsMode() { - uint width = ConfMan.hasKey("width") ? ConfMan.getInt("width") : 640; - uint height = ConfMan.hasKey("height") ? ConfMan.getInt("height") : 480; - Common::List<Graphics::PixelFormat> formats = g_system->getSupportedFormats(); - Graphics::PixelFormat format = formats.front(); - - for (Common::List<Graphics::PixelFormat>::iterator i = formats.begin(); i != formats.end(); ++i) { - if ((*i).bytesPerPixel > 1) { - format = *i; - break; - } - } - - initGraphics(width, height, &format); -} - -Common::Error GargoyleEngine::run() { - initialize(); - - Common::File f; - if (f.open(getFilename())) - runGame(&f); - - return Common::kNoError; -} - -void GargoyleEngine::GUIError(const char *msg, ...) { - char buffer[STRINGBUFLEN]; - va_list va; - - // Generate the full error message - va_start(va, msg); - vsnprintf(buffer, STRINGBUFLEN, msg, va); - va_end(va); - - GUIErrorMessage(buffer); -} - -} // End of namespace Gargoyle diff --git a/engines/glk/gargoyle.h b/engines/glk/gargoyle.h deleted file mode 100644 index d3019ca039..0000000000 --- a/engines/glk/gargoyle.h +++ /dev/null @@ -1,193 +0,0 @@ -/* 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. - * - * 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 2 - * of the License, or (at your option) any later version. - * - * 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. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef GLK_GARGOLE_H -#define GLK_GARGOLE_H - -#include "common/scummsys.h" -#include "common/random.h" -#include "common/system.h" -#include "common/serializer.h" -#include "engines/advancedDetector.h" -#include "engines/engine.h" -#include "glk/glk_types.h" - -namespace Gargoyle { - -class Clipboard; -class Conf; -class Events; -class PicList; -class Screen; -class Selection; -class Streams; -class Windows; - -enum InterpreterType { - INTERPRETER_ADVSYS = 0, - INTERPRETER_AGILITY = 1, - INTERPRETER_ALAN2 = 2, - INTERPRETER_ALAN3 = 3, - INTERPRETER_BOCFEL = 4, - INTERPRETER_FROTZ = 5, - INTERPRETER_GEAS = 6, - INTERPRETER_HUGO = 7, - INTERPRETER_JACL = 8, - INTERPRETER_LEVEL9 = 9, - INTERPRETER_MAGNETIC = 10, - INTERPRETER_NITFOL = 11, - INTERPRETER_SCARE = 12, - INTERPRETER_SCOTT = 13, - INTERPRETER_TADS = 14 -}; - -enum GargoyleDebugChannels { - kDebugCore = 1 << 0, - kDebugScripts = 1 << 1, - kDebugGraphics = 1 << 2, - kDebugSound = 1 << 3 -}; - - -#define GLK_SAVEGAME_VERSION 1 - -struct GargoyleGameDescription; - -/** - * Base class for the different interpreters - */ -class GargoyleEngine : public Engine { -private: - /** - * Handles basic initialization - */ - void initialize(); - - /** - * Setup the video mode - */ - void initGraphicsMode(); -protected: - const GargoyleGameDescription *_gameDescription; - Common::RandomSource _random; - int _loadSaveSlot; - - // Engine APIs - virtual Common::Error run(); - - /** - * Returns true whether a given feature is supported by the engine - */ - virtual bool hasFeature(EngineFeature f) const; - - /** - * Main game loop for the individual interpreters - */ - virtual void runGame(Common::SeekableReadStream *gameFile) = 0; -public: - Clipboard *_clipboard; - Conf *_conf; - Events *_events; - PicList *_picList; - Screen *_screen; - Selection *_selection; - Streams *_streams; - Windows *_windows; - bool _copySelect; - bool _terminated; - void (*gli_unregister_obj)(void *obj, glui32 objclass, gidispatch_rock_t objrock); - gidispatch_rock_t (*gli_register_arr)(void *array, glui32 len, const char *typecode); - void (*gli_unregister_arr)(void *array, glui32 len, const char *typecode, gidispatch_rock_t objrock); - -public: - GargoyleEngine(OSystem *syst, const GargoyleGameDescription *gameDesc); - virtual ~GargoyleEngine(); - - /** - * Returns true if a savegame can be loaded - */ - virtual bool canLoadGameStateCurrently() override { - return true; - } - - /** - * Returns true if the game can be saved - */ - virtual bool canSaveGameStateCurrently() override { - return true; - } - - /** - * Returns the bitset of game features - */ - uint32 getFeatures() const; - - /** - * Returns whether the game is a demo - */ - bool isDemo() const; - - /** - * Returns the language - */ - Common::Language getLanguage() const; - - /** - * Returns the running interpreter type - */ - InterpreterType getInterpreterType() const; - - /** - * Returns the game's md5 - */ - const Common::String &getGameMD5() const; - - /** - * Returns the primary filename for the game - */ - const Common::String &getFilename() const; - - /** - * Return the game engine's target name - */ - const Common::String &getTargetName() const { - return _targetName; - } - - /** - * Return the filename for a given save slot - */ - Common::String getSaveName(uint slot) const { - return Common::String::format("%s.%.3u", getTargetName().c_str(), slot); - } - - /** - * Display a message in a GUI dialog - */ - void GUIError(const char *msg, ...); -}; - -extern GargoyleEngine *g_vm; - -} // End of namespace Gargoyle - -#endif diff --git a/engines/glk/glk.cpp b/engines/glk/glk.cpp index 77fb242b8b..a35f242f44 100644 --- a/engines/glk/glk.cpp +++ b/engines/glk/glk.cpp @@ -4,1171 +4,117 @@ * are too numerous to list here. Please refer to the COPYRIGHT * file distributed with this source distribution. * - * This program is free software{} you can redistribute it and/or + * 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 2 + * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY{} without even the implied warranty of + * 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. * * You should have received a copy of the GNU General Public License - * along with this program{} if not, write to the Free Software + * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * */ +#include "common/scummsys.h" +#include "common/config-manager.h" +#include "common/debug-channels.h" +#include "common/events.h" +#include "common/file.h" +#include "engines/util.h" +#include "graphics/scaler.h" +#include "graphics/thumbnail.h" #include "glk/glk.h" #include "glk/conf.h" #include "glk/events.h" #include "glk/picture.h" +#include "glk/screen.h" +#include "glk/selection.h" #include "glk/streams.h" -#include "glk/unicode.h" #include "glk/windows.h" -#include "glk/window_graphics.h" -#include "glk/window_text_buffer.h" -#include "glk/window_pair.h" - -namespace Gargoyle { - -Glk::Glk(OSystem *syst, const GargoyleGameDescription *gameDesc) : - GargoyleEngine(syst, gameDesc), _gliFirstEvent(false) { - // Set uppercase/lowercase tables - int ix, res; - for (ix = 0; ix < 256; ix++) { - _charToupperTable[ix] = ix; - _charTolowerTable[ix] = ix; - } - - for (ix = 0; ix < 256; ix++) { - if (ix >= 'A' && ix <= 'Z') - res = ix + ('a' - 'A'); - else if (ix >= 0xC0 && ix <= 0xDE && ix != 0xD7) - res = ix + 0x20; - else - res = 0; - - if (res) { - _charTolowerTable[ix] = res; - _charToupperTable[res] = ix; +namespace Glk { + +GlkEngine *g_vm; + +GlkEngine::GlkEngine(OSystem *syst, const GlkGameDescription *gameDesc) : + _gameDescription(gameDesc), Engine(syst), _random("Glk"), _clipboard(nullptr), + _conf(nullptr), _events(nullptr), _picList(nullptr), _screen(nullptr), + _selection(nullptr), _windows(nullptr), _copySelect(false), _terminated(false), + gli_unregister_obj(nullptr), gli_register_arr(nullptr), gli_unregister_arr(nullptr) { + g_vm = this; +} + +GlkEngine::~GlkEngine() { + delete _clipboard; + delete _conf; + delete _events; + delete _picList; + delete _screen; + delete _selection; + delete _streams; + delete _windows; +} + +void GlkEngine::initialize() { + // Set up debug channels + DebugMan.addDebugChannel(kDebugCore, "core", "Core engine debug level"); + DebugMan.addDebugChannel(kDebugScripts, "scripts", "Game scripts"); + DebugMan.addDebugChannel(kDebugGraphics, "graphics", "Graphics handling"); + DebugMan.addDebugChannel(kDebugSound, "sound", "Sound and Music handling"); + + initGraphicsMode(); + _conf = new Conf(); + _screen = new Screen(); + + _clipboard = new Clipboard(); + _events = new Events(); + _picList = new PicList(); + _selection = new Selection(); + _streams = new Streams(); + _windows = new Windows(_screen); +} + +void GlkEngine::initGraphicsMode() { + uint width = ConfMan.hasKey("width") ? ConfMan.getInt("width") : 640; + uint height = ConfMan.hasKey("height") ? ConfMan.getInt("height") : 480; + Common::List<Graphics::PixelFormat> formats = g_system->getSupportedFormats(); + Graphics::PixelFormat format = formats.front(); + + for (Common::List<Graphics::PixelFormat>::iterator i = formats.begin(); i != formats.end(); ++i) { + if ((*i).bytesPerPixel > 1) { + format = *i; + break; } } -} - -void Glk::glk_exit(void) { - glk_put_string("[ press any key to exit ]"); - _events->waitForPress(); - - quitGame(); -} - -void Glk::glk_set_interrupt_handler(void(*func)(void)) { - // This library doesn't handle interrupts. -} - -void Glk::glk_tick(void) { - // Nothing needed -} - -glui32 Glk::glk_gestalt(glui32 id, glui32 val) { - return glk_gestalt_ext(id, val, nullptr, 0); -} - -glui32 Glk::glk_gestalt_ext(glui32 id, glui32 val, glui32 *arr, glui32 arrlen) { - switch (id) { - case gestalt_Version: - return 0x00000703; - - case gestalt_LineInput: - if (val >= 32 && val < 0x10ffff) - return true; - else - return false; - - case gestalt_CharInput: - if (val >= 32 && val < 0x10ffff) - return true; - else if (val == keycode_Return) - return true; - else - return false; - - case gestalt_CharOutput: - if (val >= 32 && val < 0x10ffff) { - if (arr && arrlen >= 1) - arr[0] = 1; - return gestalt_CharOutput_ExactPrint; - } else { - // cheaply, we don't do any translation of printed characters, - // so the output is always one character even if it's wrong. - if (arr && arrlen >= 1) - arr[0] = 1; - return gestalt_CharOutput_CannotPrint; - } - - case gestalt_MouseInput: - if (val == wintype_TextGrid) - return true; - if (val == wintype_Graphics) - return true; - return false; - - case gestalt_Graphics: - case gestalt_GraphicsTransparency: - return g_conf->_graphics; - - case gestalt_DrawImage: - if (val == wintype_TextBuffer) - return g_conf->_graphics; - if (val == wintype_Graphics) - return g_conf->_graphics; - return false; - - case gestalt_Sound: - case gestalt_SoundVolume: - case gestalt_SoundMusic: - case gestalt_SoundNotify: - return g_conf->_sound; - - case gestalt_LineTerminatorKey: - return Window::checkTerminator(val); - - case gestalt_Timer: - case gestalt_Unicode: - case gestalt_UnicodeNorm: - case gestalt_Hyperlinks: - case gestalt_HyperlinkInput: - case gestalt_LineInputEcho: - case gestalt_LineTerminators: - case gestalt_DateTime: - case gestalt_GarglkText: - return true; - - case gestalt_Sound2: - default: - return false; - } -} -unsigned char Glk::glk_char_to_lower(unsigned char ch) { - return _charTolowerTable[ch]; + initGraphics(width, height, &format); } -unsigned char Glk::glk_char_to_upper(unsigned char ch) { - return _charToupperTable[ch]; -} +Common::Error GlkEngine::run() { + initialize(); -winid_t Glk::glk_window_get_root(void) const { - return _windows->getRoot(); -} + Common::File f; + if (f.open(getFilename())) + runGame(&f); -winid_t Glk::glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype, glui32 rock) const { - return _windows->windowOpen(split, method, size, wintype, rock); + return Common::kNoError; } -void Glk::glk_window_close(winid_t win, stream_result_t *result) { - if (win) { - _windows->windowClose(win, result); - } else { - warning("glk_window_close: invalid ref"); - } -} - -void Glk::glk_window_get_size(winid_t win, glui32 *width, glui32 *height) { - if (win) { - win->getSize(width, height); - } else { - warning("window_get_size: invalid ref"); - } -} +void GlkEngine::GUIError(const char *msg, ...) { + char buffer[STRINGBUFLEN]; + va_list va; -void Glk::glk_window_set_arrangement(winid_t win, glui32 method, glui32 size, winid_t keywin) { - if (win) { - win->setArrangement(method, size, keywin); - } else { - warning("window_set_arrangement: invalid ref"); - } -} - -void Glk::glk_window_get_arrangement(winid_t win, glui32 *method, - glui32 *size, winid_t *keyWin) { - if (win) { - win->getArrangement(method, size, keyWin); - } else { - warning("window_get_arrangement: invalid ref"); - } -} - -winid_t Glk::glk_window_iterate(winid_t win, glui32 *rock) { - win = win ? win->_next : _windows->getRoot(); - - if (win) { - if (rock) - *rock = win->_rock; - return win; - } - - if (rock) - *rock = 0; - - return nullptr; -} - -glui32 Glk::glk_window_get_rock(winid_t win) { - if (win) { - return win->_rock; - } else { - warning("window_get_rock: invalid ref."); - return 0; - } -} - -glui32 Glk::glk_window_get_type(winid_t win) { - if (win) { - return win->_type; - } else { - warning("window_get_parent: invalid ref"); - return 0; - } -} - -winid_t Glk::glk_window_get_parent(winid_t win) { - if (!win) { - warning("window_get_parent: invalid ref"); - return 0; - } - - return win->_parent; -} - -winid_t Glk::glk_window_get_sibling(winid_t win) { - if (!win) { - warning("window_get_sibling: invalid ref"); - return nullptr; - } - - PairWindow *parentWin = dynamic_cast<PairWindow *>(win->_parent); - if (!parentWin) - return nullptr; - - if (parentWin->_child1 == win) - return parentWin->_child2; - else if (parentWin->_child2 == win) - return parentWin->_child1; - - return nullptr; -} - -void Glk::glk_window_clear(winid_t win) { - if (!win) { - warning("window_clear: invalid ref"); - } else { - if (win->_lineRequest || win->_lineRequestUni) { - if (g_conf->_safeClicks && _events->_forceClick) { - glk_cancel_line_event(win, nullptr); - _events->_forceClick = false; - - win->clear(); - } else { - warning("window_clear: window has pending line request"); - return; - } - } - - // Clear the window - win->clear(); - } -} - -void Glk::glk_window_move_cursor(winid_t win, glui32 xpos, glui32 ypos) { - if (win) { - win->moveCursor(Point(xpos, ypos)); - } else { - warning("window_move_cursor: invalid ref"); - } -} - -strid_t Glk::glk_window_get_stream(winid_t win) { - if (win) { - return win->_stream; - } else { - warning("window_get_stream: invalid ref"); - return nullptr; - } -} - -void Glk::glk_window_set_echo_stream(winid_t win, strid_t str) { - if (win) { - win->_echoStream = str; - } else { - warning("window_set_echo_stream: invalid window id"); - } -} - -strid_t Glk::glk_window_get_echo_stream(winid_t win) { - if (!win) { - warning("window_get_echo_stream: invalid ref"); - return nullptr; - } - - return win->_echoStream; -} - -void Glk::glk_set_window(winid_t win) { - _streams->setCurrent(win ? win->_stream : nullptr); -} - -strid_t Glk::glk_stream_open_file(frefid_t fileref, FileMode fmode, glui32 rock) { - return _streams->openFileStream(fileref, fmode, rock, false); -} - -strid_t Glk::glk_stream_open_memory(char *buf, glui32 buflen, FileMode fmode, glui32 rock) { - return _streams->openMemoryStream(buf, buflen, fmode, rock, false); -} - -void Glk::glk_stream_close(strid_t str, stream_result_t *result) { - str->close(result); -} - -strid_t Glk::glk_stream_iterate(strid_t str, glui32 *rockptr) const { - return str ? str->getNext(rockptr) : _streams->getFirst(rockptr); -} - -glui32 Glk::glk_stream_get_rock(strid_t str) const { - if (!str) { - warning("stream_get_rock: invalid ref"); - return 0; - } - - return str->getRock(); -} - -void Glk::glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekMode) { - if (str) { - str->setPosition(pos, seekMode); - } else { - warning("stream_set_position: invalid ref"); - } -} + // Generate the full error message + va_start(va, msg); + vsnprintf(buffer, STRINGBUFLEN, msg, va); + va_end(va); -glui32 Glk::glk_stream_get_position(strid_t str) const { - if (str) { - return str->getPosition(); - } else { - warning("stream_get_position: invalid ref"); - return 0; - } -} - -void Glk::glk_stream_set_current(strid_t str) { - _streams->setCurrent(str); -} - -strid_t Glk::glk_stream_get_current(void) { - return _streams->getCurrent(); -} - -void Glk::glk_put_char(unsigned char ch) { - _streams->getCurrent()->putChar(ch); -} - -void Glk::glk_put_char_stream(strid_t str, unsigned char ch) { - if (str) { - str->putChar(ch); - } else { - warning("put_char_stream: invalid ref"); - } -} - -void Glk::glk_put_string(const char *s) { - _streams->getCurrent()->putBuffer(s, strlen(s)); -} - -void Glk::glk_put_string_stream(strid_t str, const char *s) { - str->putBuffer(s, strlen(s)); -} - -void Glk::glk_put_buffer(char *buf, glui32 len) { - _streams->getCurrent()->putBuffer(buf, len); -} - -void Glk::glk_put_buffer_stream(strid_t str, const char *buf, glui32 len) { - str->putBuffer(buf, len); -} - -void Glk::glk_set_style(glui32 styl) { - _streams->getCurrent()->setStyle(styl); -} - -void Glk::glk_set_style_stream(strid_t str, glui32 styl) { - if (str) { - str->setStyle(styl); - } else { - warning("set_style_stream: invalid ref"); - } -} - -glsi32 Glk::glk_get_char_stream(strid_t str) { - if (str) { - return str->getChar(); - } else { - warning("get_char_stream: invalid ref"); - return -1; - } -} - -glui32 Glk::glk_get_line_stream(strid_t str, char *buf, glui32 len) { - if (str) { - return str->getLine(buf, len); - } else { - warning("get_line_stream: invalid ref"); - return 0; - } -} - -glui32 Glk::glk_get_buffer_stream(strid_t str, char *buf, glui32 len) { - if (str) { - return str->getBuffer(buf, len); - } else { - warning("get_line_stream: invalid ref"); - return 0; - } -} - -void Glk::glk_stylehint_set(glui32 wintype, glui32 style, glui32 hint, glsi32 val) { - WindowStyle *styles; - bool p, b, i; - - if (wintype == wintype_AllTypes) { - glk_stylehint_set(wintype_TextGrid, style, hint, val); - glk_stylehint_set(wintype_TextBuffer, style, hint, val); - return; - } - - if (wintype == wintype_TextGrid) - styles = g_conf->_gStyles; - else if (wintype == wintype_TextBuffer) - styles = g_conf->_tStyles; - else - return; - - if (!g_conf->_styleHint) - return; - - switch (hint) { - case stylehint_TextColor: - styles[style].fg[0] = (val >> 16) & 0xff; - styles[style].fg[1] = (val >> 8) & 0xff; - styles[style].fg[2] = (val) & 0xff; - break; - - case stylehint_BackColor: - styles[style].bg[0] = (val >> 16) & 0xff; - styles[style].bg[1] = (val >> 8) & 0xff; - styles[style].bg[2] = (val) & 0xff; - break; - - case stylehint_ReverseColor: - styles[style].reverse = (val != 0); - break; - - case stylehint_Proportional: - if (wintype == wintype_TextBuffer) { - p = val > 0; - b = styles[style].isBold(); - i = styles[style].isItalic(); - styles[style].font = WindowStyle::makeFont(p, b, i); - } - break; - - case stylehint_Weight: - p = styles[style].isProp(); - b = val > 0; - i = styles[style].isItalic(); - styles[style].font = WindowStyle::makeFont(p, b, i); - break; - - case stylehint_Oblique: - p = styles[style].isProp(); - b = styles[style].isBold(); - i = val > 0; - styles[style].font = WindowStyle::makeFont(p, b, i); - break; - } - - if (wintype == wintype_TextBuffer && style == style_Normal && hint == stylehint_BackColor) { - memcpy(g_conf->_windowColor, styles[style].bg, 3); - } - - if (wintype == wintype_TextBuffer && style == style_Normal && hint == stylehint_TextColor) { - memcpy(g_conf->_moreColor, styles[style].fg, 3); - memcpy(g_conf->_caretColor, styles[style].fg, 3); - } -} - -void Glk::glk_stylehint_clear(glui32 wintype, glui32 style, glui32 hint) { - WindowStyle *styles; - const WindowStyle *defaults; - - if (wintype == wintype_AllTypes) { - glk_stylehint_clear(wintype_TextGrid, style, hint); - glk_stylehint_clear(wintype_TextBuffer, style, hint); - return; - } - - if (wintype == wintype_TextGrid) { - styles = g_conf->_gStyles; - defaults = g_conf->_gStylesDefault; - } else if (wintype == wintype_TextBuffer) { - styles = g_conf->_tStyles; - defaults = g_conf->_tStylesDefault; - } else { - return; - } - - if (!g_conf->_styleHint) - return; - - switch (hint) { - case stylehint_TextColor: - styles[style].fg[0] = defaults[style].fg[0]; - styles[style].fg[1] = defaults[style].fg[1]; - styles[style].fg[2] = defaults[style].fg[2]; - break; - - case stylehint_BackColor: - styles[style].bg[0] = defaults[style].bg[0]; - styles[style].bg[1] = defaults[style].bg[1]; - styles[style].bg[2] = defaults[style].bg[2]; - break; - - case stylehint_ReverseColor: - styles[style].reverse = defaults[style].reverse; - break; - - case stylehint_Proportional: - case stylehint_Weight: - case stylehint_Oblique: - styles[style].font = defaults[style].font; - break; - } -} - -glui32 Glk::glk_style_distinguish(winid_t win, glui32 style1, glui32 style2) { - const WindowStyle *styles = win->getStyles(); - if (!styles) - return false; - - return styles[style1] == styles[style2] ? 0 : 1; -} - -bool Glk::glk_style_measure(winid_t win, glui32 style, glui32 hint, glui32 *result) { - const WindowStyle *styles = win->getStyles(); - if (!styles) - return false; - - switch (hint) { - case stylehint_Indentation: - case stylehint_ParaIndentation: - *result = 0; - break; - - case stylehint_Justification: - *result = stylehint_just_LeftFlush; - break; - - case stylehint_Size: - *result = 1; - break; - - case stylehint_Weight: - *result = - (styles[style].font == PROPB || styles[style].font == PROPZ || - styles[style].font == MONOB || styles[style].font == MONOZ); - break; - - case stylehint_Oblique: - *result = - (styles[style].font == PROPI || styles[style].font == PROPZ || - styles[style].font == MONOI || styles[style].font == MONOZ); - break; - - case stylehint_Proportional: - *result = - (styles[style].font == PROPR || styles[style].font == PROPI || - styles[style].font == PROPB || styles[style].font == PROPZ); - break; - - case stylehint_TextColor: - *result = - (styles[style].fg[0] << 16) | (styles[style].fg[1] << 8) | (styles[style].fg[2]); - break; - - case stylehint_BackColor: - *result = - (styles[style].bg[0] << 16) | (styles[style].bg[1] << 8) | (styles[style].bg[2]); - break; - - case stylehint_ReverseColor: - *result = styles[style].reverse; - break; - - default: - return false; - } - - return true; -} - -frefid_t Glk::glk_fileref_create_temp(glui32 usage, glui32 rock) { - return _streams->createTemp(usage, rock); -} - -frefid_t Glk::glk_fileref_create_by_name(glui32 usage, const char *name, glui32 rock) { - // Take out all dangerous characters - Common::String tempName(name); - for (uint idx = 0; idx < tempName.size(); ++idx) { - if (tempName[idx] == '/' || tempName[idx] == '\\' || tempName[idx] == ':') - tempName.setChar(idx, '-'); - } - - return _streams->createRef(tempName, usage, rock); -} - -frefid_t Glk::glk_fileref_create_by_prompt(glui32 usage, FileMode fmode, glui32 rock) { - return _streams->createByPrompt(usage, fmode, rock); -} - -frefid_t Glk::glk_fileref_create_from_fileref(glui32 usage, frefid_t fref, glui32 rock) { - if (!fref) { - warning("fileref_create_from_fileref: invalid ref"); - return nullptr; - } else { - return _streams->createFromRef(fref, usage, rock); - } -} - -void Glk::glk_fileref_destroy(frefid_t fref) { - _streams->deleteRef(fref); -} - -frefid_t Glk::glk_fileref_iterate(frefid_t fref, glui32 *rockptr) { - return _streams->iterate(fref, rockptr); -} - -glui32 Glk::glk_fileref_get_rock(frefid_t fref) { - if (!fref) { - warning("fileref_get_rock: invalid ref."); - return 0; - } else { - return fref->_rock; - } -} - -void Glk::glk_fileref_delete_file(frefid_t fref) { - fref->deleteFile(); -} - -glui32 Glk::glk_fileref_does_file_exist(frefid_t fref) { - return fref->exists(); -} - -void Glk::glk_select(event_t *event) { - if (!_gliFirstEvent) { - _windows->inputGuessFocus(); - _gliFirstEvent = true; - } - - _events->getEvent(event, false); -} - -void Glk::glk_select_poll(event_t *event) { - if (!_gliFirstEvent) { - _windows->inputGuessFocus(); - _gliFirstEvent = true; - } - - _events->getEvent(event, true); -} - -void Glk::glk_request_timer_events(glui32 millisecs) { - _events->setTimerInterval(millisecs); -} - -void Glk::glk_request_line_event(winid_t win, char *buf, glui32 maxlen, glui32 initlen) { - if (!win) { - warning("request_line_event: invalid ref"); - } else if (win->_charRequest || win->_lineRequest || win->_charRequestUni - || win->_lineRequestUni) { - warning("request_line_event: window already has keyboard request"); - } else { - win->requestLineEvent(buf, maxlen, initlen); - } -} - -void Glk::glk_request_char_event(winid_t win) { - if (!win) { - warning("request_char_event: invalid ref"); - } else if (win->_charRequest || win->_lineRequest || win->_charRequestUni - || win->_lineRequestUni) { - warning("request_char_event: window already has keyboard request"); - } else { - win->requestCharEvent(); - } -} - -void Glk::glk_request_mouse_event(winid_t win) { - if (!win) { - warning("request_mouse_event: invalid ref"); - } else { - win->requestMouseEvent(); - } -} - -void Glk::glk_cancel_line_event(winid_t win, event_t *event) { - if (!win) { - warning("cancel_line_event: invalid ref"); - } else { - win->cancelLineEvent(event); - } -} - -void Glk::glk_cancel_char_event(winid_t win) { - if (!win) { - warning("glk_cancel_char_event: invalid ref"); - } else { - win->cancelCharEvent(); - } -} - -void Glk::glk_cancel_mouse_event(winid_t win) { - if (!win) { - warning("cancel_mouse_event: invalid ref"); - } else { - win->cancelMouseEvent(); - } -} - -void Glk::glk_set_echo_line_event(winid_t win, glui32 val) { - if (!win) { - warning("set_echo_line_event: invalid ref"); - } else { - win->setEchoLineEvent(val); - } -} - -void Glk::glk_set_terminators_line_event(winid_t win, glui32 *keycodes, glui32 count) { - if (!win) { - warning("set_terminators_line_event: invalid ref"); - } else { - win->setTerminatorsLineEvent(keycodes, count); - } -} - -glui32 Glk::glk_buffer_to_lower_case_uni(glui32 *buf, glui32 len, glui32 numchars) { - return bufferChangeCase(buf, len, numchars, CASE_LOWER, COND_ALL, true); -} - -glui32 Glk::glk_buffer_to_upper_case_uni(glui32 *buf, glui32 len, glui32 numchars) { - return bufferChangeCase(buf, len, numchars, CASE_UPPER, COND_ALL, true); -} - -glui32 Glk::glk_buffer_to_title_case_uni(glui32 *buf, glui32 len, - glui32 numchars, glui32 lowerrest) { - return bufferChangeCase(buf, len, numchars, CASE_TITLE, COND_LINESTART, lowerrest); -} - -void Glk::glk_put_char_uni(glui32 ch) { - _streams->getCurrent()->putCharUni(ch); -} - -void Glk::glk_put_string_uni(glui32 *s) { - _streams->getCurrent()->putBufferUni(s, strlen_uni(s)); -} - -void Glk::glk_put_buffer_uni(glui32 *buf, glui32 len) { - _streams->getCurrent()->putBufferUni(buf, len); -} - -void Glk::glk_put_char_stream_uni(strid_t str, glui32 ch) { - if (str) { - str->putCharUni(ch); - } else { - warning("put_char_stream_uni: invalid ref"); - } -} - -void Glk::glk_put_string_stream_uni(strid_t str, const glui32 *s) { - if (str) { - str->putBufferUni(s, strlen_uni(s)); - } else { - warning("put_string_stream_uni: invalid ref"); - } -} - -void Glk::glk_put_buffer_stream_uni(strid_t str, const glui32 *buf, glui32 len) { - if (str) { - str->putBufferUni(buf, len); - } else { - warning("put_buffer_stream_uni: invalid ref"); - } -} - -glsi32 Glk::glk_get_char_stream_uni(strid_t str) { - if (str) { - return str->getCharUni(); - } else { - warning("get_char_stream_uni: invalid ref"); - return -1; - } -} - -glui32 Glk::glk_get_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len) { - if (str) { - return str->getBufferUni(buf, len); - } else { - warning("get_buffer_stream_uni: invalid ref"); - return 0; - } -} - -glui32 Glk::glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len) { - if (str) { - return str->getLineUni(buf, len); - } else { - warning("get_line_stream_uni: invalid ref"); - return (glui32) - 1; - } -} - -strid_t Glk::glk_stream_open_file_uni(frefid_t fileref, FileMode fmode, glui32 rock) { - return _streams->openFileStream(fileref, fmode, rock, true); -} - -strid_t Glk::glk_stream_open_memory_uni(glui32 *buf, glui32 buflen, FileMode fmode, glui32 rock) { - return _streams->openMemoryStream(buf, buflen, fmode, rock, true); -} - -void Glk::glk_request_char_event_uni(winid_t win) { - if (!win) { - warning("request_char_event_uni: invalid ref"); - } else if (win->_charRequest || win->_lineRequest || win->_charRequestUni - || win->_lineRequestUni) { - warning("request_char_event_uni: window already has keyboard request"); - } else { - win->requestCharEvent(); - } -} - -void Glk::glk_request_line_event_uni(winid_t win, glui32 *buf, glui32 maxlen, glui32 initlen) { - if (!win) { - warning("request_line_event_uni: invalid ref"); - } else if (win->_charRequest || win->_lineRequest || win->_charRequestUni - || win->_lineRequestUni) { - warning("request_line_event_uni: window already has keyboard request"); - } else { - win->requestLineEventUni(buf, maxlen, initlen); - } -} - -glui32 Glk::glk_buffer_canon_decompose_uni(glui32 *buf, glui32 len, - glui32 numchars) { - // TODO - return 0; -} - -glui32 Glk::glk_buffer_canon_normalize_uni(glui32 *buf, glui32 len, glui32 numchars) { - return 0; -} - -glui32 Glk::glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2) { - if (!win) { - warning("image_draw: invalid ref"); - } else if (g_conf->_graphics) { - TextBufferWindow *textWin = dynamic_cast<TextBufferWindow *>(win); - GraphicsWindow *gfxWin = dynamic_cast<GraphicsWindow *>(win); - - if (textWin) - textWin->drawPicture(image, val1, false, 0, 0); - else if (gfxWin) - gfxWin->drawPicture(image, val1, val2, false, 0, 0); - } - - return false; -} - -glui32 Glk::glk_image_draw_scaled(winid_t win, glui32 image, glsi32 val1, glsi32 val2, - glui32 width, glui32 height) { - if (!win) { - warning("image_draw_scaled: invalid ref"); - } else if (g_conf->_graphics) { - TextBufferWindow *textWin = dynamic_cast<TextBufferWindow *>(win); - GraphicsWindow *gfxWin = dynamic_cast<GraphicsWindow *>(win); - - if (textWin) - textWin->drawPicture(image, val1, true, width, height); - else if (gfxWin) - gfxWin->drawPicture(image, val1, val2, true, width, height); - } - - return false; -} - -glui32 Glk::glk_image_get_info(glui32 image, glui32 *width, glui32 *height) { - if (!g_conf->_graphics) - return false; - - Picture *pic = Picture::load(image); - if (!pic) - return false; - - if (width) - *width = pic->w; - if (height) - *height = pic->h; - - return true; -} - -void Glk::glk_window_flow_break(winid_t win) { - if (!win) { - warning("window_erase_rect: invalid ref"); - } else { - win->flowBreak(); - } -} - -void Glk::glk_window_erase_rect(winid_t win, glsi32 left, glsi32 top, glui32 width, glui32 height) { - if (!win) { - warning("window_erase_rect: invalid ref"); - } else { - win->eraseRect(false, Rect(left, top, left + width, top + height)); - } -} - -void Glk::glk_window_fill_rect(winid_t win, glui32 color, glsi32 left, glsi32 top, - glui32 width, glui32 height) { - if (!win) { - warning("window_fill_rect: invalid ref"); - } else { - win->eraseRect(color, Rect(left, top, left + width, top + height)); - } -} - -void Glk::glk_window_set_background_color(winid_t win, glui32 color) { - if (!win) { - warning("window_set_background_color: invalid ref"); - } else { - win->setBackgroundColor(color); - } -} - -schanid_t Glk::glk_schannel_create(glui32 rock) { - // TODO - return nullptr; -} - -void Glk::glk_schannel_destroy(schanid_t chan) { - // TODO -} - -schanid_t Glk::glk_schannel_iterate(schanid_t chan, glui32 *rockptr) { - // TODO - return nullptr; -} - -glui32 Glk::glk_schannel_get_rock(schanid_t chan) { - // TODO - return 0; -} - -glui32 Glk::glk_schannel_play(schanid_t chan, glui32 snd) { - // TODO - return 0; -} - -glui32 Glk::glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) { - // TODO - return 0; -} - -void Glk::glk_schannel_stop(schanid_t chan) { - // TODO -} - -void Glk::glk_schannel_set_volume(schanid_t chan, glui32 vol) { - // TODO -} - -void Glk::glk_sound_load_hint(glui32 snd, glui32 flag) { - // TODO -} - -schanid_t Glk::glk_schannel_create_ext(glui32 rock, glui32 volume) { - // TODO - return nullptr; -} - -glui32 Glk::glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount, - glui32 *sndarray, glui32 soundcount, glui32 notify) { - // TODO - return 0; -} - -void Glk::glk_schannel_pause(schanid_t chan) { - // TODO -} - -void Glk::glk_schannel_unpause(schanid_t chan) { - // TODO -} - -void Glk::glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, - glui32 duration, glui32 notify) { - // TODO -} - -void Glk::glk_set_hyperlink(glui32 linkval) { - _streams->getCurrent()->setHyperlink(linkval); -} - -void Glk::glk_set_hyperlink_stream(strid_t str, glui32 linkval) { - if (str) - str->setHyperlink(linkval); -} - -void Glk::glk_request_hyperlink_event(winid_t win) { - if (!win) { - warning("request_hyperlink_event: invalid ref"); - } else { - win->requestHyperlinkEvent(); - } -} - -void Glk::glk_cancel_hyperlink_event(winid_t win) { - if (win) { - win->cancelHyperlinkEvent(); - } else { - warning("cancel_hyperlink_event: invalid ref"); - } -} - -/*--------------------------------------------------------------------------*/ - -void Glk::glk_current_time(glktimeval_t *time) { - TimeAndDate td; - *time = td; -} - -glsi32 Glk::glk_current_simple_time(glui32 factor) { - assert(factor); - TimeAndDate td; - - return td / factor; -} - -void Glk::glk_time_to_date_utc(const glktimeval_t *time, glkdate_t *date) { - // TODO: timezones aren't currently supported - *date = TimeAndDate(*time); -} - -void Glk::glk_time_to_date_local(const glktimeval_t *time, glkdate_t *date) { - *date = TimeAndDate(*time); -} - -void Glk::glk_simple_time_to_date_utc(glsi32 time, glui32 factor, glkdate_t *date) { - TimeSeconds secs = (int64)time * factor; - *date = TimeAndDate(secs); -} - -void Glk::glk_simple_time_to_date_local(glsi32 time, glui32 factor, glkdate_t *date) { - TimeSeconds secs = (int64)time * factor; - *date = TimeAndDate(secs); -} - -void Glk::glk_date_to_time_utc(const glkdate_t *date, glktimeval_t *time) { - // WORKAROUND: timezones aren't currently supported - *time = TimeAndDate(*date); -} - -void Glk::glk_date_to_time_local(const glkdate_t *date, glktimeval_t *time) { - *time = TimeAndDate(*date); -} - -glsi32 Glk::glk_date_to_simple_time_utc(const glkdate_t *date, glui32 factor) { - // WORKAROUND: timezones aren't currently supported - assert(factor); - TimeSeconds ts = TimeAndDate(*date); - return ts / factor; -} - -glsi32 Glk::glk_date_to_simple_time_local(const glkdate_t *date, glui32 factor) { - assert(factor); - TimeSeconds ts = TimeAndDate(*date); - return ts / factor; -} - -/*--------------------------------------------------------------------------*/ - -/* XXX non-official Glk functions */ - -const char *Glk::garglk_fileref_get_name(frefid_t fref) const { - return fref->_filename.c_str(); -} - -void Glk::garglk_set_program_name(const char *name) { - // Program name isn't displayed -} - -void Glk::garglk_set_program_info(const char *info) { - // Program info isn't displayed -} - -void Glk::garglk_set_story_name(const char *name) { - // Story name isn't displayed -} - -void Glk::garglk_set_story_title(const char *title) { - // Story title isn't displayed -} - -void Glk::garglk_set_config(const char *name) { - // No implementation -} - -void Glk::garglk_unput_string(const char *str) { - _streams->getCurrent()->unputBuffer(str, strlen(str)); -} - -void Glk::garglk_unput_string_uni(const glui32 *str) { - _streams->getCurrent()->unputBufferUni(str, strlen_uni(str)); -} - -void Glk::garglk_set_zcolors(glui32 fg, glui32 bg) { - _streams->getCurrent()->setZColors(fg, bg); -} - -void Glk::garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg) { - if (str) { - str->setZColors(fg, bg); - } else { - warning("set_style_stream: Invalid ref"); - } -} - -void Glk::garglk_set_reversevideo(glui32 reverse) { - _streams->getCurrent()->setReverseVideo(reverse != 0); -} - -void Glk::garglk_set_reversevideo_stream(strid_t str, glui32 reverse) { - if (str) { - str->setReverseVideo(reverse != 0); - } else { - warning("set_reversevideo: Invalid ref"); - } + GUIErrorMessage(buffer); } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/glk.h b/engines/glk/glk.h index f71ad764ac..92ea2aba91 100644 --- a/engines/glk/glk.h +++ b/engines/glk/glk.h @@ -23,270 +23,171 @@ #ifndef GLK_GLK_H #define GLK_GLK_H -#include "glk/gargoyle.h" +#include "common/scummsys.h" +#include "common/random.h" +#include "common/system.h" +#include "common/serializer.h" +#include "engines/advancedDetector.h" +#include "engines/engine.h" #include "glk/glk_types.h" -#include "glk/blorb.h" -#include "glk/time.h" -#include "glk/windows.h" -namespace Gargoyle { +namespace Glk { + +class Clipboard; +class Conf; +class Events; +class PicList; +class Screen; +class Selection; +class Streams; +class Windows; + +enum InterpreterType { + INTERPRETER_ADVSYS = 0, + INTERPRETER_AGILITY = 1, + INTERPRETER_ALAN2 = 2, + INTERPRETER_ALAN3 = 3, + INTERPRETER_BOCFEL = 4, + INTERPRETER_FROTZ = 5, + INTERPRETER_GEAS = 6, + INTERPRETER_HUGO = 7, + INTERPRETER_JACL = 8, + INTERPRETER_LEVEL9 = 9, + INTERPRETER_MAGNETIC = 10, + INTERPRETER_NITFOL = 11, + INTERPRETER_SCARE = 12, + INTERPRETER_SCOTT = 13, + INTERPRETER_TADS = 14 +}; -/** - * Implements the GLK interface - */ -class Glk : public GargoyleEngine, public Blorb { -private: - bool _gliFirstEvent; - unsigned char _charTolowerTable[256]; - unsigned char _charToupperTable[256]; -public: - /** - * Constructor - */ - Glk(OSystem *syst, const GargoyleGameDescription *gameDesc); +enum GlkDebugChannels { + kDebugCore = 1 << 0, + kDebugScripts = 1 << 1, + kDebugGraphics = 1 << 2, + kDebugSound = 1 << 3 +}; - void glk_exit(void); - void glk_set_interrupt_handler(void(*func)(void)); - void glk_tick(void); - glui32 glk_gestalt(glui32 id, glui32 val); - glui32 glk_gestalt_ext(glui32 id, glui32 val, glui32 *arr, glui32 arrlen); +#define GLK_SAVEGAME_VERSION 1 - unsigned char glk_char_to_lower(unsigned char ch); - unsigned char glk_char_to_upper(unsigned char ch); +struct GlkGameDescription; +/** + * Base class for the different interpreters + */ +class GlkEngine : public Engine { +private: /** - * Get the root window of the window hierarchy + * Handles basic initialization */ - winid_t glk_window_get_root(void) const; + void initialize(); /** - * Open a new window + * Setup the video mode */ - winid_t glk_window_open(winid_t split, glui32 method, glui32 size, - glui32 wintype, glui32 rock = 0) const; - - void glk_window_close(winid_t win, stream_result_t *result = nullptr); - void glk_window_get_size(winid_t win, glui32 *width, glui32 *height); - void glk_window_set_arrangement(winid_t win, glui32 method, - glui32 size, winid_t keyWin); - void glk_window_get_arrangement(winid_t win, glui32 *method, - glui32 *size, winid_t *keyWin); - winid_t glk_window_iterate(winid_t win, glui32 *rock = 0); - glui32 glk_window_get_rock(winid_t win); - glui32 glk_window_get_type(winid_t win); - winid_t glk_window_get_parent(winid_t win); - winid_t glk_window_get_sibling(winid_t win); - void glk_window_clear(winid_t win); - void glk_window_move_cursor(winid_t win, glui32 xpos, glui32 ypos); - - strid_t glk_window_get_stream(winid_t win); - void glk_window_set_echo_stream(winid_t win, strid_t str); - strid_t glk_window_get_echo_stream(winid_t win); - void glk_set_window(winid_t win); - - strid_t glk_stream_open_file(frefid_t fileref, FileMode fmode, glui32 rock = 0); - strid_t glk_stream_open_memory(char *buf, glui32 buflen, FileMode fmode, glui32 rock = 0); - void glk_stream_close(strid_t str, stream_result_t *result = nullptr); - strid_t glk_stream_iterate(strid_t str, glui32 *rockptr) const; - glui32 glk_stream_get_rock(strid_t str) const; - void glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekMode); - glui32 glk_stream_get_position(strid_t str) const; - void glk_stream_set_current(strid_t str); - strid_t glk_stream_get_current(void); - - void glk_put_char(unsigned char ch); - void glk_put_char_stream(strid_t str, unsigned char ch); - void glk_put_string(const char *s); - void glk_put_string_stream(strid_t str, const char *s); - void glk_put_buffer(char *buf, glui32 len); - void glk_put_buffer_stream(strid_t str, const char *buf, glui32 len); - void glk_set_style(glui32 styl); - void glk_set_style_stream(strid_t str, glui32 styl); - - glsi32 glk_get_char_stream(strid_t str); - glui32 glk_get_line_stream(strid_t str, char *buf, glui32 len); - glui32 glk_get_buffer_stream(strid_t str, char *buf, glui32 len); - - void glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint, - glsi32 val); - void glk_stylehint_clear(glui32 wintype, glui32 style, glui32 hint); - glui32 glk_style_distinguish(winid_t win, glui32 style1, glui32 style2); - bool glk_style_measure(winid_t win, glui32 style, glui32 hint, glui32 *result); + void initGraphicsMode(); +protected: + const GlkGameDescription *_gameDescription; + Common::RandomSource _random; + int _loadSaveSlot; - frefid_t glk_fileref_create_temp(glui32 usage, glui32 rock = 0); - frefid_t glk_fileref_create_by_name(glui32 usage, const char *name, glui32 rock = 0); - frefid_t glk_fileref_create_by_prompt(glui32 usage, FileMode fmode, glui32 rock = 0); - frefid_t glk_fileref_create_from_fileref(glui32 usage, frefid_t fref, glui32 rock = 0); - void glk_fileref_destroy(frefid_t fref); - frefid_t glk_fileref_iterate(frefid_t fref, glui32 *rockptr); - glui32 glk_fileref_get_rock(frefid_t fref); - void glk_fileref_delete_file(frefid_t fref); - glui32 glk_fileref_does_file_exist(frefid_t fref); + // Engine APIs + virtual Common::Error run(); - void glk_select(event_t *event); - void glk_select_poll(event_t *event); - - void glk_request_timer_events(glui32 millisecs); - - void glk_request_line_event(winid_t win, char *buf, glui32 maxlen, - glui32 initlen); - void glk_request_char_event(winid_t win); - void glk_request_mouse_event(winid_t win); - - void glk_cancel_line_event(winid_t win, event_t *event); - void glk_cancel_char_event(winid_t win); - void glk_cancel_mouse_event(winid_t win); - -#ifdef GLK_MODULE_LINE_ECHO - void glk_set_echo_line_event(winid_t win, glui32 val); -#endif /* GLK_MODULE_LINE_ECHO */ - -#ifdef GLK_MODULE_LINE_TERMINATORS - void glk_set_terminators_line_event(winid_t win, glui32 *keycodes, - glui32 count); -#endif /* GLK_MODULE_LINE_TERMINATORS */ + /** + * Returns true whether a given feature is supported by the engine + */ + virtual bool hasFeature(EngineFeature f) const; - /** \addtogroup Unicode - * @{ + /** + * Main game loop for the individual interpreters */ + virtual void runGame(Common::SeekableReadStream *gameFile) = 0; +public: + Clipboard *_clipboard; + Conf *_conf; + Events *_events; + PicList *_picList; + Screen *_screen; + Selection *_selection; + Streams *_streams; + Windows *_windows; + bool _copySelect; + bool _terminated; + void (*gli_unregister_obj)(void *obj, glui32 objclass, gidispatch_rock_t objrock); + gidispatch_rock_t (*gli_register_arr)(void *array, glui32 len, const char *typecode); + void (*gli_unregister_arr)(void *array, glui32 len, const char *typecode, gidispatch_rock_t objrock); - glui32 glk_buffer_to_lower_case_uni(glui32 *buf, glui32 len, - glui32 numchars); - glui32 glk_buffer_to_upper_case_uni(glui32 *buf, glui32 len, - glui32 numchars); - glui32 glk_buffer_to_title_case_uni(glui32 *buf, glui32 len, - glui32 numchars, glui32 lowerrest); - - void glk_put_char_uni(glui32 ch); - void glk_put_string_uni(glui32 *s); - void glk_put_buffer_uni(glui32 *buf, glui32 len); - void glk_put_char_stream_uni(strid_t str, glui32 ch); - void glk_put_string_stream_uni(strid_t str, const glui32 *s); - void glk_put_buffer_stream_uni(strid_t str, const glui32 *buf, glui32 len); - - glsi32 glk_get_char_stream_uni(strid_t str); - glui32 glk_get_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len); - glui32 glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len); - - strid_t glk_stream_open_file_uni(frefid_t fileref, FileMode fmode, glui32 rock = 0); - strid_t glk_stream_open_memory_uni(glui32 *buf, glui32 buflen, FileMode fmode, glui32 rock = 0); - - void glk_request_char_event_uni(winid_t win); - void glk_request_line_event_uni(winid_t win, glui32 *buf, - glui32 maxlen, glui32 initlen); - - /** @}*/ - -#ifdef GLK_MODULE_UNICODE_NORM - - glui32 glk_buffer_canon_decompose_uni(glui32 *buf, glui32 len, - glui32 numchars); - glui32 glk_buffer_canon_normalize_uni(glui32 *buf, glui32 len, - glui32 numchars); - -#endif /* GLK_MODULE_UNICODE_NORM */ - -#ifdef GLK_MODULE_IMAGE - - glui32 glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2); - glui32 glk_image_draw_scaled(winid_t win, glui32 image, - glsi32 val1, glsi32 val2, glui32 width, glui32 height); - glui32 glk_image_get_info(glui32 image, glui32 *width, glui32 *height); - - void glk_window_flow_break(winid_t win); - - void glk_window_erase_rect(winid_t win, - glsi32 left, glsi32 top, glui32 width, glui32 height); - void glk_window_fill_rect(winid_t win, glui32 color, - glsi32 left, glsi32 top, glui32 width, glui32 height); - void glk_window_set_background_color(winid_t win, glui32 color); - -#endif /* GLK_MODULE_IMAGE */ - -#ifdef GLK_MODULE_SOUND - - schanid_t glk_schannel_create(glui32 rock = 0); - void glk_schannel_destroy(schanid_t chan); - schanid_t glk_schannel_iterate(schanid_t chan, glui32 *rockptr); - glui32 glk_schannel_get_rock(schanid_t chan); - - glui32 glk_schannel_play(schanid_t chan, glui32 snd); - glui32 glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, - glui32 notify); - void glk_schannel_stop(schanid_t chan); - void glk_schannel_set_volume(schanid_t chan, glui32 vol); - - void glk_sound_load_hint(glui32 snd, glui32 flag); - -#ifdef GLK_MODULE_SOUND2 - /* Note that this section is nested inside the #ifdef GLK_MODULE_SOUND. - GLK_MODULE_SOUND must be defined if GLK_MODULE_SOUND2 is. */ - - schanid_t glk_schannel_create_ext(glui32 rock, glui32 volume); - glui32 glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount, - glui32 *sndarray, glui32 soundcount, glui32 notify); - void glk_schannel_pause(schanid_t chan); - void glk_schannel_unpause(schanid_t chan); - void glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, - glui32 duration, glui32 notify); - -#endif /* GLK_MODULE_SOUND2 */ -#endif /* GLK_MODULE_SOUND */ - -#ifdef GLK_MODULE_HYPERLINKS +public: + GlkEngine(OSystem *syst, const GlkGameDescription *gameDesc); + virtual ~GlkEngine(); - void glk_set_hyperlink(glui32 linkval); - void glk_set_hyperlink_stream(strid_t str, glui32 linkval); - void glk_request_hyperlink_event(winid_t win); - void glk_cancel_hyperlink_event(winid_t win); + /** + * Returns true if a savegame can be loaded + */ + virtual bool canLoadGameStateCurrently() override { + return true; + } -#endif /* GLK_MODULE_HYPERLINKS */ + /** + * Returns true if the game can be saved + */ + virtual bool canSaveGameStateCurrently() override { + return true; + } -#ifdef GLK_MODULE_DATETIME + /** + * Returns the bitset of game features + */ + uint32 getFeatures() const; - void glk_current_time(glktimeval_t *time); - glsi32 glk_current_simple_time(glui32 factor); - void glk_time_to_date_utc(const glktimeval_t *time, glkdate_t *date); - void glk_time_to_date_local(const glktimeval_t *time, glkdate_t *date); - void glk_simple_time_to_date_utc(glsi32 time, glui32 factor, glkdate_t *date); - void glk_simple_time_to_date_local(glsi32 time, glui32 factor, glkdate_t *date); - void glk_date_to_time_utc(const glkdate_t *date, glktimeval_t *time); - void glk_date_to_time_local(const glkdate_t *date, glktimeval_t *time); - glsi32 glk_date_to_simple_time_utc(const glkdate_t *date, glui32 factor); - glsi32 glk_date_to_simple_time_local(const glkdate_t *date, glui32 factor); + /** + * Returns whether the game is a demo + */ + bool isDemo() const; -#endif /* GLK_MODULE_DATETIME */ + /** + * Returns the language + */ + Common::Language getLanguage() const; - /* XXX non-official Glk functions that may or may not exist */ -#define GARGLK 1 + /** + * Returns the running interpreter type + */ + InterpreterType getInterpreterType() const; - const char *garglk_fileref_get_name(frefid_t fref) const; + /** + * Returns the game's md5 + */ + const Common::String &getGameMD5() const; - void garglk_set_program_name(const char *name); - void garglk_set_program_info(const char *info); - void garglk_set_story_name(const char *name); - void garglk_set_story_title(const char *title); - void garglk_set_config(const char *name); + /** + * Returns the primary filename for the game + */ + const Common::String &getFilename() const; /** - * Removes the specified string from the end of the output buffer, if - * indeed it is there. + * Return the game engine's target name */ - void garglk_unput_string(const char *str); + const Common::String &getTargetName() const { + return _targetName; + } /** - * Removes the specified string from the end of the output buffer, if - * indeed it is there. + * Return the filename for a given save slot */ - void garglk_unput_string_uni(const glui32 *str); + Common::String getSaveName(uint slot) const { + return Common::String::format("%s.%.3u", getTargetName().c_str(), slot); + } - void garglk_set_zcolors(glui32 fg, glui32 bg); - void garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg); - void garglk_set_reversevideo(glui32 reverse); - void garglk_set_reversevideo_stream(strid_t str, glui32 reverse); + /** + * Display a message in a GUI dialog + */ + void GUIError(const char *msg, ...); }; -} // End of namespace Gargoyle +extern GlkEngine *g_vm; + +} // End of namespace Glk #endif diff --git a/engines/glk/glk_api.cpp b/engines/glk/glk_api.cpp new file mode 100644 index 0000000000..c219cd1e3f --- /dev/null +++ b/engines/glk/glk_api.cpp @@ -0,0 +1,1174 @@ +/* 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. + * + * 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 2 + * of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program{} if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "glk/glk_api.h" +#include "glk/conf.h" +#include "glk/events.h" +#include "glk/picture.h" +#include "glk/streams.h" +#include "glk/unicode.h" +#include "glk/windows.h" +#include "glk/window_graphics.h" +#include "glk/window_text_buffer.h" +#include "glk/window_pair.h" + + +namespace Glk { + +GlkAPI::GlkAPI(OSystem *syst, const GlkGameDescription *gameDesc) : + GlkEngine(syst, gameDesc), _gliFirstEvent(false) { + // Set uppercase/lowercase tables + int ix, res; + for (ix = 0; ix < 256; ix++) { + _charToupperTable[ix] = ix; + _charTolowerTable[ix] = ix; + } + + for (ix = 0; ix < 256; ix++) { + if (ix >= 'A' && ix <= 'Z') + res = ix + ('a' - 'A'); + else if (ix >= 0xC0 && ix <= 0xDE && ix != 0xD7) + res = ix + 0x20; + else + res = 0; + + if (res) { + _charTolowerTable[ix] = res; + _charToupperTable[res] = ix; + } + } +} + +void GlkAPI::glk_exit(void) { + glk_put_string("[ press any key to exit ]"); + _events->waitForPress(); + + quitGame(); +} + +void GlkAPI::glk_set_interrupt_handler(void(*func)(void)) { + // This library doesn't handle interrupts. +} + +void GlkAPI::glk_tick(void) { + // Nothing needed +} + +glui32 GlkAPI::glk_gestalt(glui32 id, glui32 val) { + return glk_gestalt_ext(id, val, nullptr, 0); +} + +glui32 GlkAPI::glk_gestalt_ext(glui32 id, glui32 val, glui32 *arr, glui32 arrlen) { + switch (id) { + case gestalt_Version: + return 0x00000703; + + case gestalt_LineInput: + if (val >= 32 && val < 0x10ffff) + return true; + else + return false; + + case gestalt_CharInput: + if (val >= 32 && val < 0x10ffff) + return true; + else if (val == keycode_Return) + return true; + else + return false; + + case gestalt_CharOutput: + if (val >= 32 && val < 0x10ffff) { + if (arr && arrlen >= 1) + arr[0] = 1; + return gestalt_CharOutput_ExactPrint; + } else { + // cheaply, we don't do any translation of printed characters, + // so the output is always one character even if it's wrong. + if (arr && arrlen >= 1) + arr[0] = 1; + return gestalt_CharOutput_CannotPrint; + } + + case gestalt_MouseInput: + if (val == wintype_TextGrid) + return true; + if (val == wintype_Graphics) + return true; + return false; + + case gestalt_Graphics: + case gestalt_GraphicsTransparency: + return g_conf->_graphics; + + case gestalt_DrawImage: + if (val == wintype_TextBuffer) + return g_conf->_graphics; + if (val == wintype_Graphics) + return g_conf->_graphics; + return false; + + case gestalt_Sound: + case gestalt_SoundVolume: + case gestalt_SoundMusic: + case gestalt_SoundNotify: + return g_conf->_sound; + + case gestalt_LineTerminatorKey: + return Window::checkTerminator(val); + + case gestalt_Timer: + case gestalt_Unicode: + case gestalt_UnicodeNorm: + case gestalt_Hyperlinks: + case gestalt_HyperlinkInput: + case gestalt_LineInputEcho: + case gestalt_LineTerminators: + case gestalt_DateTime: + case gestalt_GarglkText: + return true; + + case gestalt_Sound2: + default: + return false; + } +} + +unsigned char GlkAPI::glk_char_to_lower(unsigned char ch) { + return _charTolowerTable[ch]; +} + +unsigned char GlkAPI::glk_char_to_upper(unsigned char ch) { + return _charToupperTable[ch]; +} + +winid_t GlkAPI::glk_window_get_root(void) const { + return _windows->getRoot(); +} + +winid_t GlkAPI::glk_window_open(winid_t split, glui32 method, glui32 size, glui32 wintype, glui32 rock) const { + return _windows->windowOpen(split, method, size, wintype, rock); +} + +void GlkAPI::glk_window_close(winid_t win, stream_result_t *result) { + if (win) { + _windows->windowClose(win, result); + } else { + warning("glk_window_close: invalid ref"); + } +} + +void GlkAPI::glk_window_get_size(winid_t win, glui32 *width, glui32 *height) { + if (win) { + win->getSize(width, height); + } else { + warning("window_get_size: invalid ref"); + } +} + +void GlkAPI::glk_window_set_arrangement(winid_t win, glui32 method, glui32 size, winid_t keywin) { + if (win) { + win->setArrangement(method, size, keywin); + } else { + warning("window_set_arrangement: invalid ref"); + } +} + +void GlkAPI::glk_window_get_arrangement(winid_t win, glui32 *method, + glui32 *size, winid_t *keyWin) { + if (win) { + win->getArrangement(method, size, keyWin); + } else { + warning("window_get_arrangement: invalid ref"); + } +} + +winid_t GlkAPI::glk_window_iterate(winid_t win, glui32 *rock) { + win = win ? win->_next : _windows->getRoot(); + + if (win) { + if (rock) + *rock = win->_rock; + return win; + } + + if (rock) + *rock = 0; + + return nullptr; +} + +glui32 GlkAPI::glk_window_get_rock(winid_t win) { + if (win) { + return win->_rock; + } else { + warning("window_get_rock: invalid ref."); + return 0; + } +} + +glui32 GlkAPI::glk_window_get_type(winid_t win) { + if (win) { + return win->_type; + } else { + warning("window_get_parent: invalid ref"); + return 0; + } +} + +winid_t GlkAPI::glk_window_get_parent(winid_t win) { + if (!win) { + warning("window_get_parent: invalid ref"); + return 0; + } + + return win->_parent; +} + +winid_t GlkAPI::glk_window_get_sibling(winid_t win) { + if (!win) { + warning("window_get_sibling: invalid ref"); + return nullptr; + } + + PairWindow *parentWin = dynamic_cast<PairWindow *>(win->_parent); + if (!parentWin) + return nullptr; + + if (parentWin->_child1 == win) + return parentWin->_child2; + else if (parentWin->_child2 == win) + return parentWin->_child1; + + return nullptr; +} + +void GlkAPI::glk_window_clear(winid_t win) { + if (!win) { + warning("window_clear: invalid ref"); + } else { + if (win->_lineRequest || win->_lineRequestUni) { + if (g_conf->_safeClicks && _events->_forceClick) { + glk_cancel_line_event(win, nullptr); + _events->_forceClick = false; + + win->clear(); + } else { + warning("window_clear: window has pending line request"); + return; + } + } + + // Clear the window + win->clear(); + } +} + +void GlkAPI::glk_window_move_cursor(winid_t win, glui32 xpos, glui32 ypos) { + if (win) { + win->moveCursor(Point(xpos, ypos)); + } else { + warning("window_move_cursor: invalid ref"); + } +} + +strid_t GlkAPI::glk_window_get_stream(winid_t win) { + if (win) { + return win->_stream; + } else { + warning("window_get_stream: invalid ref"); + return nullptr; + } +} + +void GlkAPI::glk_window_set_echo_stream(winid_t win, strid_t str) { + if (win) { + win->_echoStream = str; + } else { + warning("window_set_echo_stream: invalid window id"); + } +} + +strid_t GlkAPI::glk_window_get_echo_stream(winid_t win) { + if (!win) { + warning("window_get_echo_stream: invalid ref"); + return nullptr; + } + + return win->_echoStream; +} + +void GlkAPI::glk_set_window(winid_t win) { + _streams->setCurrent(win ? win->_stream : nullptr); +} + +strid_t GlkAPI::glk_stream_open_file(frefid_t fileref, FileMode fmode, glui32 rock) { + return _streams->openFileStream(fileref, fmode, rock, false); +} + +strid_t GlkAPI::glk_stream_open_memory(char *buf, glui32 buflen, FileMode fmode, glui32 rock) { + return _streams->openMemoryStream(buf, buflen, fmode, rock, false); +} + +void GlkAPI::glk_stream_close(strid_t str, stream_result_t *result) { + str->close(result); +} + +strid_t GlkAPI::glk_stream_iterate(strid_t str, glui32 *rockptr) const { + return str ? str->getNext(rockptr) : _streams->getFirst(rockptr); +} + +glui32 GlkAPI::glk_stream_get_rock(strid_t str) const { + if (!str) { + warning("stream_get_rock: invalid ref"); + return 0; + } + + return str->getRock(); +} + +void GlkAPI::glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekMode) { + if (str) { + str->setPosition(pos, seekMode); + } else { + warning("stream_set_position: invalid ref"); + } +} + +glui32 GlkAPI::glk_stream_get_position(strid_t str) const { + if (str) { + return str->getPosition(); + } else { + warning("stream_get_position: invalid ref"); + return 0; + } +} + +void GlkAPI::glk_stream_set_current(strid_t str) { + _streams->setCurrent(str); +} + +strid_t GlkAPI::glk_stream_get_current(void) { + return _streams->getCurrent(); +} + +void GlkAPI::glk_put_char(unsigned char ch) { + _streams->getCurrent()->putChar(ch); +} + +void GlkAPI::glk_put_char_stream(strid_t str, unsigned char ch) { + if (str) { + str->putChar(ch); + } else { + warning("put_char_stream: invalid ref"); + } +} + +void GlkAPI::glk_put_string(const char *s) { + _streams->getCurrent()->putBuffer(s, strlen(s)); +} + +void GlkAPI::glk_put_string_stream(strid_t str, const char *s) { + str->putBuffer(s, strlen(s)); +} + +void GlkAPI::glk_put_buffer(char *buf, glui32 len) { + _streams->getCurrent()->putBuffer(buf, len); +} + +void GlkAPI::glk_put_buffer_stream(strid_t str, const char *buf, glui32 len) { + str->putBuffer(buf, len); +} + +void GlkAPI::glk_set_style(glui32 styl) { + _streams->getCurrent()->setStyle(styl); +} + +void GlkAPI::glk_set_style_stream(strid_t str, glui32 styl) { + if (str) { + str->setStyle(styl); + } else { + warning("set_style_stream: invalid ref"); + } +} + +glsi32 GlkAPI::glk_get_char_stream(strid_t str) { + if (str) { + return str->getChar(); + } else { + warning("get_char_stream: invalid ref"); + return -1; + } +} + +glui32 GlkAPI::glk_get_line_stream(strid_t str, char *buf, glui32 len) { + if (str) { + return str->getLine(buf, len); + } else { + warning("get_line_stream: invalid ref"); + return 0; + } +} + +glui32 GlkAPI::glk_get_buffer_stream(strid_t str, char *buf, glui32 len) { + if (str) { + return str->getBuffer(buf, len); + } else { + warning("get_line_stream: invalid ref"); + return 0; + } +} + +void GlkAPI::glk_stylehint_set(glui32 wintype, glui32 style, glui32 hint, glsi32 val) { + WindowStyle *styles; + bool p, b, i; + + if (wintype == wintype_AllTypes) { + glk_stylehint_set(wintype_TextGrid, style, hint, val); + glk_stylehint_set(wintype_TextBuffer, style, hint, val); + return; + } + + if (wintype == wintype_TextGrid) + styles = g_conf->_gStyles; + else if (wintype == wintype_TextBuffer) + styles = g_conf->_tStyles; + else + return; + + if (!g_conf->_styleHint) + return; + + switch (hint) { + case stylehint_TextColor: + styles[style].fg[0] = (val >> 16) & 0xff; + styles[style].fg[1] = (val >> 8) & 0xff; + styles[style].fg[2] = (val) & 0xff; + break; + + case stylehint_BackColor: + styles[style].bg[0] = (val >> 16) & 0xff; + styles[style].bg[1] = (val >> 8) & 0xff; + styles[style].bg[2] = (val) & 0xff; + break; + + case stylehint_ReverseColor: + styles[style].reverse = (val != 0); + break; + + case stylehint_Proportional: + if (wintype == wintype_TextBuffer) { + p = val > 0; + b = styles[style].isBold(); + i = styles[style].isItalic(); + styles[style].font = WindowStyle::makeFont(p, b, i); + } + break; + + case stylehint_Weight: + p = styles[style].isProp(); + b = val > 0; + i = styles[style].isItalic(); + styles[style].font = WindowStyle::makeFont(p, b, i); + break; + + case stylehint_Oblique: + p = styles[style].isProp(); + b = styles[style].isBold(); + i = val > 0; + styles[style].font = WindowStyle::makeFont(p, b, i); + break; + } + + if (wintype == wintype_TextBuffer && style == style_Normal && hint == stylehint_BackColor) { + memcpy(g_conf->_windowColor, styles[style].bg, 3); + } + + if (wintype == wintype_TextBuffer && style == style_Normal && hint == stylehint_TextColor) { + memcpy(g_conf->_moreColor, styles[style].fg, 3); + memcpy(g_conf->_caretColor, styles[style].fg, 3); + } +} + +void GlkAPI::glk_stylehint_clear(glui32 wintype, glui32 style, glui32 hint) { + WindowStyle *styles; + const WindowStyle *defaults; + + if (wintype == wintype_AllTypes) { + glk_stylehint_clear(wintype_TextGrid, style, hint); + glk_stylehint_clear(wintype_TextBuffer, style, hint); + return; + } + + if (wintype == wintype_TextGrid) { + styles = g_conf->_gStyles; + defaults = g_conf->_gStylesDefault; + } else if (wintype == wintype_TextBuffer) { + styles = g_conf->_tStyles; + defaults = g_conf->_tStylesDefault; + } else { + return; + } + + if (!g_conf->_styleHint) + return; + + switch (hint) { + case stylehint_TextColor: + styles[style].fg[0] = defaults[style].fg[0]; + styles[style].fg[1] = defaults[style].fg[1]; + styles[style].fg[2] = defaults[style].fg[2]; + break; + + case stylehint_BackColor: + styles[style].bg[0] = defaults[style].bg[0]; + styles[style].bg[1] = defaults[style].bg[1]; + styles[style].bg[2] = defaults[style].bg[2]; + break; + + case stylehint_ReverseColor: + styles[style].reverse = defaults[style].reverse; + break; + + case stylehint_Proportional: + case stylehint_Weight: + case stylehint_Oblique: + styles[style].font = defaults[style].font; + break; + } +} + +glui32 GlkAPI::glk_style_distinguish(winid_t win, glui32 style1, glui32 style2) { + const WindowStyle *styles = win->getStyles(); + if (!styles) + return false; + + return styles[style1] == styles[style2] ? 0 : 1; +} + +bool GlkAPI::glk_style_measure(winid_t win, glui32 style, glui32 hint, glui32 *result) { + const WindowStyle *styles = win->getStyles(); + if (!styles) + return false; + + switch (hint) { + case stylehint_Indentation: + case stylehint_ParaIndentation: + *result = 0; + break; + + case stylehint_Justification: + *result = stylehint_just_LeftFlush; + break; + + case stylehint_Size: + *result = 1; + break; + + case stylehint_Weight: + *result = + (styles[style].font == PROPB || styles[style].font == PROPZ || + styles[style].font == MONOB || styles[style].font == MONOZ); + break; + + case stylehint_Oblique: + *result = + (styles[style].font == PROPI || styles[style].font == PROPZ || + styles[style].font == MONOI || styles[style].font == MONOZ); + break; + + case stylehint_Proportional: + *result = + (styles[style].font == PROPR || styles[style].font == PROPI || + styles[style].font == PROPB || styles[style].font == PROPZ); + break; + + case stylehint_TextColor: + *result = + (styles[style].fg[0] << 16) | (styles[style].fg[1] << 8) | (styles[style].fg[2]); + break; + + case stylehint_BackColor: + *result = + (styles[style].bg[0] << 16) | (styles[style].bg[1] << 8) | (styles[style].bg[2]); + break; + + case stylehint_ReverseColor: + *result = styles[style].reverse; + break; + + default: + return false; + } + + return true; +} + +frefid_t GlkAPI::glk_fileref_create_temp(glui32 usage, glui32 rock) { + return _streams->createTemp(usage, rock); +} + +frefid_t GlkAPI::glk_fileref_create_by_name(glui32 usage, const char *name, glui32 rock) { + // Take out all dangerous characters + Common::String tempName(name); + for (uint idx = 0; idx < tempName.size(); ++idx) { + if (tempName[idx] == '/' || tempName[idx] == '\\' || tempName[idx] == ':') + tempName.setChar(idx, '-'); + } + + return _streams->createRef(tempName, usage, rock); +} + +frefid_t GlkAPI::glk_fileref_create_by_prompt(glui32 usage, FileMode fmode, glui32 rock) { + return _streams->createByPrompt(usage, fmode, rock); +} + +frefid_t GlkAPI::glk_fileref_create_from_fileref(glui32 usage, frefid_t fref, glui32 rock) { + if (!fref) { + warning("fileref_create_from_fileref: invalid ref"); + return nullptr; + } else { + return _streams->createFromRef(fref, usage, rock); + } +} + +void GlkAPI::glk_fileref_destroy(frefid_t fref) { + _streams->deleteRef(fref); +} + +frefid_t GlkAPI::glk_fileref_iterate(frefid_t fref, glui32 *rockptr) { + return _streams->iterate(fref, rockptr); +} + +glui32 GlkAPI::glk_fileref_get_rock(frefid_t fref) { + if (!fref) { + warning("fileref_get_rock: invalid ref."); + return 0; + } else { + return fref->_rock; + } +} + +void GlkAPI::glk_fileref_delete_file(frefid_t fref) { + fref->deleteFile(); +} + +glui32 GlkAPI::glk_fileref_does_file_exist(frefid_t fref) { + return fref->exists(); +} + +void GlkAPI::glk_select(event_t *event) { + if (!_gliFirstEvent) { + _windows->inputGuessFocus(); + _gliFirstEvent = true; + } + + _events->getEvent(event, false); +} + +void GlkAPI::glk_select_poll(event_t *event) { + if (!_gliFirstEvent) { + _windows->inputGuessFocus(); + _gliFirstEvent = true; + } + + _events->getEvent(event, true); +} + +void GlkAPI::glk_request_timer_events(glui32 millisecs) { + _events->setTimerInterval(millisecs); +} + +void GlkAPI::glk_request_line_event(winid_t win, char *buf, glui32 maxlen, glui32 initlen) { + if (!win) { + warning("request_line_event: invalid ref"); + } else if (win->_charRequest || win->_lineRequest || win->_charRequestUni + || win->_lineRequestUni) { + warning("request_line_event: window already has keyboard request"); + } else { + win->requestLineEvent(buf, maxlen, initlen); + } +} + +void GlkAPI::glk_request_char_event(winid_t win) { + if (!win) { + warning("request_char_event: invalid ref"); + } else if (win->_charRequest || win->_lineRequest || win->_charRequestUni + || win->_lineRequestUni) { + warning("request_char_event: window already has keyboard request"); + } else { + win->requestCharEvent(); + } +} + +void GlkAPI::glk_request_mouse_event(winid_t win) { + if (!win) { + warning("request_mouse_event: invalid ref"); + } else { + win->requestMouseEvent(); + } +} + +void GlkAPI::glk_cancel_line_event(winid_t win, event_t *event) { + if (!win) { + warning("cancel_line_event: invalid ref"); + } else { + win->cancelLineEvent(event); + } +} + +void GlkAPI::glk_cancel_char_event(winid_t win) { + if (!win) { + warning("glk_cancel_char_event: invalid ref"); + } else { + win->cancelCharEvent(); + } +} + +void GlkAPI::glk_cancel_mouse_event(winid_t win) { + if (!win) { + warning("cancel_mouse_event: invalid ref"); + } else { + win->cancelMouseEvent(); + } +} + +void GlkAPI::glk_set_echo_line_event(winid_t win, glui32 val) { + if (!win) { + warning("set_echo_line_event: invalid ref"); + } else { + win->setEchoLineEvent(val); + } +} + +void GlkAPI::glk_set_terminators_line_event(winid_t win, glui32 *keycodes, glui32 count) { + if (!win) { + warning("set_terminators_line_event: invalid ref"); + } else { + win->setTerminatorsLineEvent(keycodes, count); + } +} + +glui32 GlkAPI::glk_buffer_to_lower_case_uni(glui32 *buf, glui32 len, glui32 numchars) { + return bufferChangeCase(buf, len, numchars, CASE_LOWER, COND_ALL, true); +} + +glui32 GlkAPI::glk_buffer_to_upper_case_uni(glui32 *buf, glui32 len, glui32 numchars) { + return bufferChangeCase(buf, len, numchars, CASE_UPPER, COND_ALL, true); +} + +glui32 GlkAPI::glk_buffer_to_title_case_uni(glui32 *buf, glui32 len, + glui32 numchars, glui32 lowerrest) { + return bufferChangeCase(buf, len, numchars, CASE_TITLE, COND_LINESTART, lowerrest); +} + +void GlkAPI::glk_put_char_uni(glui32 ch) { + _streams->getCurrent()->putCharUni(ch); +} + +void GlkAPI::glk_put_string_uni(glui32 *s) { + _streams->getCurrent()->putBufferUni(s, strlen_uni(s)); +} + +void GlkAPI::glk_put_buffer_uni(glui32 *buf, glui32 len) { + _streams->getCurrent()->putBufferUni(buf, len); +} + +void GlkAPI::glk_put_char_stream_uni(strid_t str, glui32 ch) { + if (str) { + str->putCharUni(ch); + } else { + warning("put_char_stream_uni: invalid ref"); + } +} + +void GlkAPI::glk_put_string_stream_uni(strid_t str, const glui32 *s) { + if (str) { + str->putBufferUni(s, strlen_uni(s)); + } else { + warning("put_string_stream_uni: invalid ref"); + } +} + +void GlkAPI::glk_put_buffer_stream_uni(strid_t str, const glui32 *buf, glui32 len) { + if (str) { + str->putBufferUni(buf, len); + } else { + warning("put_buffer_stream_uni: invalid ref"); + } +} + +glsi32 GlkAPI::glk_get_char_stream_uni(strid_t str) { + if (str) { + return str->getCharUni(); + } else { + warning("get_char_stream_uni: invalid ref"); + return -1; + } +} + +glui32 GlkAPI::glk_get_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len) { + if (str) { + return str->getBufferUni(buf, len); + } else { + warning("get_buffer_stream_uni: invalid ref"); + return 0; + } +} + +glui32 GlkAPI::glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len) { + if (str) { + return str->getLineUni(buf, len); + } else { + warning("get_line_stream_uni: invalid ref"); + return (glui32) - 1; + } +} + +strid_t GlkAPI::glk_stream_open_file_uni(frefid_t fileref, FileMode fmode, glui32 rock) { + return _streams->openFileStream(fileref, fmode, rock, true); +} + +strid_t GlkAPI::glk_stream_open_memory_uni(glui32 *buf, glui32 buflen, FileMode fmode, glui32 rock) { + return _streams->openMemoryStream(buf, buflen, fmode, rock, true); +} + +void GlkAPI::glk_request_char_event_uni(winid_t win) { + if (!win) { + warning("request_char_event_uni: invalid ref"); + } else if (win->_charRequest || win->_lineRequest || win->_charRequestUni + || win->_lineRequestUni) { + warning("request_char_event_uni: window already has keyboard request"); + } else { + win->requestCharEvent(); + } +} + +void GlkAPI::glk_request_line_event_uni(winid_t win, glui32 *buf, glui32 maxlen, glui32 initlen) { + if (!win) { + warning("request_line_event_uni: invalid ref"); + } else if (win->_charRequest || win->_lineRequest || win->_charRequestUni + || win->_lineRequestUni) { + warning("request_line_event_uni: window already has keyboard request"); + } else { + win->requestLineEventUni(buf, maxlen, initlen); + } +} + +glui32 GlkAPI::glk_buffer_canon_decompose_uni(glui32 *buf, glui32 len, + glui32 numchars) { + // TODO + return 0; +} + +glui32 GlkAPI::glk_buffer_canon_normalize_uni(glui32 *buf, glui32 len, glui32 numchars) { + return 0; +} + +glui32 GlkAPI::glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2) { + if (!win) { + warning("image_draw: invalid ref"); + } else if (g_conf->_graphics) { + TextBufferWindow *textWin = dynamic_cast<TextBufferWindow *>(win); + GraphicsWindow *gfxWin = dynamic_cast<GraphicsWindow *>(win); + + if (textWin) + textWin->drawPicture(image, val1, false, 0, 0); + else if (gfxWin) + gfxWin->drawPicture(image, val1, val2, false, 0, 0); + } + + return false; +} + +glui32 GlkAPI::glk_image_draw_scaled(winid_t win, glui32 image, glsi32 val1, glsi32 val2, + glui32 width, glui32 height) { + if (!win) { + warning("image_draw_scaled: invalid ref"); + } else if (g_conf->_graphics) { + TextBufferWindow *textWin = dynamic_cast<TextBufferWindow *>(win); + GraphicsWindow *gfxWin = dynamic_cast<GraphicsWindow *>(win); + + if (textWin) + textWin->drawPicture(image, val1, true, width, height); + else if (gfxWin) + gfxWin->drawPicture(image, val1, val2, true, width, height); + } + + return false; +} + +glui32 GlkAPI::glk_image_get_info(glui32 image, glui32 *width, glui32 *height) { + if (!g_conf->_graphics) + return false; + + Picture *pic = Picture::load(image); + if (!pic) + return false; + + if (width) + *width = pic->w; + if (height) + *height = pic->h; + + return true; +} + +void GlkAPI::glk_window_flow_break(winid_t win) { + if (!win) { + warning("window_erase_rect: invalid ref"); + } else { + win->flowBreak(); + } +} + +void GlkAPI::glk_window_erase_rect(winid_t win, glsi32 left, glsi32 top, glui32 width, glui32 height) { + if (!win) { + warning("window_erase_rect: invalid ref"); + } else { + win->eraseRect(false, Rect(left, top, left + width, top + height)); + } +} + +void GlkAPI::glk_window_fill_rect(winid_t win, glui32 color, glsi32 left, glsi32 top, + glui32 width, glui32 height) { + if (!win) { + warning("window_fill_rect: invalid ref"); + } else { + win->eraseRect(color, Rect(left, top, left + width, top + height)); + } +} + +void GlkAPI::glk_window_set_background_color(winid_t win, glui32 color) { + if (!win) { + warning("window_set_background_color: invalid ref"); + } else { + win->setBackgroundColor(color); + } +} + +schanid_t GlkAPI::glk_schannel_create(glui32 rock) { + // TODO + return nullptr; +} + +void GlkAPI::glk_schannel_destroy(schanid_t chan) { + // TODO +} + +schanid_t GlkAPI::glk_schannel_iterate(schanid_t chan, glui32 *rockptr) { + // TODO + return nullptr; +} + +glui32 GlkAPI::glk_schannel_get_rock(schanid_t chan) { + // TODO + return 0; +} + +glui32 GlkAPI::glk_schannel_play(schanid_t chan, glui32 snd) { + // TODO + return 0; +} + +glui32 GlkAPI::glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, glui32 notify) { + // TODO + return 0; +} + +void GlkAPI::glk_schannel_stop(schanid_t chan) { + // TODO +} + +void GlkAPI::glk_schannel_set_volume(schanid_t chan, glui32 vol) { + // TODO +} + +void GlkAPI::glk_sound_load_hint(glui32 snd, glui32 flag) { + // TODO +} + +schanid_t GlkAPI::glk_schannel_create_ext(glui32 rock, glui32 volume) { + // TODO + return nullptr; +} + +glui32 GlkAPI::glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount, + glui32 *sndarray, glui32 soundcount, glui32 notify) { + // TODO + return 0; +} + +void GlkAPI::glk_schannel_pause(schanid_t chan) { + // TODO +} + +void GlkAPI::glk_schannel_unpause(schanid_t chan) { + // TODO +} + +void GlkAPI::glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, + glui32 duration, glui32 notify) { + // TODO +} + +void GlkAPI::glk_set_hyperlink(glui32 linkval) { + _streams->getCurrent()->setHyperlink(linkval); +} + +void GlkAPI::glk_set_hyperlink_stream(strid_t str, glui32 linkval) { + if (str) + str->setHyperlink(linkval); +} + +void GlkAPI::glk_request_hyperlink_event(winid_t win) { + if (!win) { + warning("request_hyperlink_event: invalid ref"); + } else { + win->requestHyperlinkEvent(); + } +} + +void GlkAPI::glk_cancel_hyperlink_event(winid_t win) { + if (win) { + win->cancelHyperlinkEvent(); + } else { + warning("cancel_hyperlink_event: invalid ref"); + } +} + +/*--------------------------------------------------------------------------*/ + +void GlkAPI::glk_current_time(glktimeval_t *time) { + TimeAndDate td; + *time = td; +} + +glsi32 GlkAPI::glk_current_simple_time(glui32 factor) { + assert(factor); + TimeAndDate td; + + return td / factor; +} + +void GlkAPI::glk_time_to_date_utc(const glktimeval_t *time, glkdate_t *date) { + // TODO: timezones aren't currently supported + *date = TimeAndDate(*time); +} + +void GlkAPI::glk_time_to_date_local(const glktimeval_t *time, glkdate_t *date) { + *date = TimeAndDate(*time); +} + +void GlkAPI::glk_simple_time_to_date_utc(glsi32 time, glui32 factor, glkdate_t *date) { + TimeSeconds secs = (int64)time * factor; + *date = TimeAndDate(secs); +} + +void GlkAPI::glk_simple_time_to_date_local(glsi32 time, glui32 factor, glkdate_t *date) { + TimeSeconds secs = (int64)time * factor; + *date = TimeAndDate(secs); +} + +void GlkAPI::glk_date_to_time_utc(const glkdate_t *date, glktimeval_t *time) { + // WORKAROUND: timezones aren't currently supported + *time = TimeAndDate(*date); +} + +void GlkAPI::glk_date_to_time_local(const glkdate_t *date, glktimeval_t *time) { + *time = TimeAndDate(*date); +} + +glsi32 GlkAPI::glk_date_to_simple_time_utc(const glkdate_t *date, glui32 factor) { + // WORKAROUND: timezones aren't currently supported + assert(factor); + TimeSeconds ts = TimeAndDate(*date); + return ts / factor; +} + +glsi32 GlkAPI::glk_date_to_simple_time_local(const glkdate_t *date, glui32 factor) { + assert(factor); + TimeSeconds ts = TimeAndDate(*date); + return ts / factor; +} + +/*--------------------------------------------------------------------------*/ + +/* XXX non-official Glk functions */ + +const char *GlkAPI::garglk_fileref_get_name(frefid_t fref) const { + return fref->_filename.c_str(); +} + +void GlkAPI::garglk_set_program_name(const char *name) { + // Program name isn't displayed +} + +void GlkAPI::garglk_set_program_info(const char *info) { + // Program info isn't displayed +} + +void GlkAPI::garglk_set_story_name(const char *name) { + // Story name isn't displayed +} + +void GlkAPI::garglk_set_story_title(const char *title) { + // Story title isn't displayed +} + +void GlkAPI::garglk_set_config(const char *name) { + // No implementation +} + +void GlkAPI::garglk_unput_string(const char *str) { + _streams->getCurrent()->unputBuffer(str, strlen(str)); +} + +void GlkAPI::garglk_unput_string_uni(const glui32 *str) { + _streams->getCurrent()->unputBufferUni(str, strlen_uni(str)); +} + +void GlkAPI::garglk_set_zcolors(glui32 fg, glui32 bg) { + _streams->getCurrent()->setZColors(fg, bg); +} + +void GlkAPI::garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg) { + if (str) { + str->setZColors(fg, bg); + } else { + warning("set_style_stream: Invalid ref"); + } +} + +void GlkAPI::garglk_set_reversevideo(glui32 reverse) { + _streams->getCurrent()->setReverseVideo(reverse != 0); +} + +void GlkAPI::garglk_set_reversevideo_stream(strid_t str, glui32 reverse) { + if (str) { + str->setReverseVideo(reverse != 0); + } else { + warning("set_reversevideo: Invalid ref"); + } +} + +} // End of namespace Glk diff --git a/engines/glk/glk_api.h b/engines/glk/glk_api.h new file mode 100644 index 0000000000..f864ac9dc3 --- /dev/null +++ b/engines/glk/glk_api.h @@ -0,0 +1,292 @@ +/* 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. + * + * 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 2 + * of the License, or (at your option) any later version. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef GLK_GLK_API_H +#define GLK_GLK_API_H + +#include "glk/glk.h" +#include "glk/glk_types.h" +#include "glk/blorb.h" +#include "glk/time.h" +#include "glk/windows.h" + +namespace Glk { + +/** + * Implements the GLK interface + */ +class GlkAPI : public GlkEngine, public Blorb { +private: + bool _gliFirstEvent; + unsigned char _charTolowerTable[256]; + unsigned char _charToupperTable[256]; +public: + /** + * Constructor + */ + GlkAPI(OSystem *syst, const GlkGameDescription *gameDesc); + + void glk_exit(void); + void glk_set_interrupt_handler(void(*func)(void)); + void glk_tick(void); + + glui32 glk_gestalt(glui32 id, glui32 val); + glui32 glk_gestalt_ext(glui32 id, glui32 val, glui32 *arr, glui32 arrlen); + + unsigned char glk_char_to_lower(unsigned char ch); + unsigned char glk_char_to_upper(unsigned char ch); + + /** + * Get the root window of the window hierarchy + */ + winid_t glk_window_get_root(void) const; + + /** + * Open a new window + */ + winid_t glk_window_open(winid_t split, glui32 method, glui32 size, + glui32 wintype, glui32 rock = 0) const; + + void glk_window_close(winid_t win, stream_result_t *result = nullptr); + void glk_window_get_size(winid_t win, glui32 *width, glui32 *height); + void glk_window_set_arrangement(winid_t win, glui32 method, + glui32 size, winid_t keyWin); + void glk_window_get_arrangement(winid_t win, glui32 *method, + glui32 *size, winid_t *keyWin); + winid_t glk_window_iterate(winid_t win, glui32 *rock = 0); + glui32 glk_window_get_rock(winid_t win); + glui32 glk_window_get_type(winid_t win); + winid_t glk_window_get_parent(winid_t win); + winid_t glk_window_get_sibling(winid_t win); + void glk_window_clear(winid_t win); + void glk_window_move_cursor(winid_t win, glui32 xpos, glui32 ypos); + + strid_t glk_window_get_stream(winid_t win); + void glk_window_set_echo_stream(winid_t win, strid_t str); + strid_t glk_window_get_echo_stream(winid_t win); + void glk_set_window(winid_t win); + + strid_t glk_stream_open_file(frefid_t fileref, FileMode fmode, glui32 rock = 0); + strid_t glk_stream_open_memory(char *buf, glui32 buflen, FileMode fmode, glui32 rock = 0); + void glk_stream_close(strid_t str, stream_result_t *result = nullptr); + strid_t glk_stream_iterate(strid_t str, glui32 *rockptr) const; + glui32 glk_stream_get_rock(strid_t str) const; + void glk_stream_set_position(strid_t str, glsi32 pos, glui32 seekMode); + glui32 glk_stream_get_position(strid_t str) const; + void glk_stream_set_current(strid_t str); + strid_t glk_stream_get_current(void); + + void glk_put_char(unsigned char ch); + void glk_put_char_stream(strid_t str, unsigned char ch); + void glk_put_string(const char *s); + void glk_put_string_stream(strid_t str, const char *s); + void glk_put_buffer(char *buf, glui32 len); + void glk_put_buffer_stream(strid_t str, const char *buf, glui32 len); + void glk_set_style(glui32 styl); + void glk_set_style_stream(strid_t str, glui32 styl); + + glsi32 glk_get_char_stream(strid_t str); + glui32 glk_get_line_stream(strid_t str, char *buf, glui32 len); + glui32 glk_get_buffer_stream(strid_t str, char *buf, glui32 len); + + void glk_stylehint_set(glui32 wintype, glui32 styl, glui32 hint, + glsi32 val); + void glk_stylehint_clear(glui32 wintype, glui32 style, glui32 hint); + glui32 glk_style_distinguish(winid_t win, glui32 style1, glui32 style2); + bool glk_style_measure(winid_t win, glui32 style, glui32 hint, glui32 *result); + + frefid_t glk_fileref_create_temp(glui32 usage, glui32 rock = 0); + frefid_t glk_fileref_create_by_name(glui32 usage, const char *name, glui32 rock = 0); + frefid_t glk_fileref_create_by_prompt(glui32 usage, FileMode fmode, glui32 rock = 0); + frefid_t glk_fileref_create_from_fileref(glui32 usage, frefid_t fref, glui32 rock = 0); + void glk_fileref_destroy(frefid_t fref); + frefid_t glk_fileref_iterate(frefid_t fref, glui32 *rockptr); + glui32 glk_fileref_get_rock(frefid_t fref); + void glk_fileref_delete_file(frefid_t fref); + glui32 glk_fileref_does_file_exist(frefid_t fref); + + void glk_select(event_t *event); + void glk_select_poll(event_t *event); + + void glk_request_timer_events(glui32 millisecs); + + void glk_request_line_event(winid_t win, char *buf, glui32 maxlen, + glui32 initlen); + void glk_request_char_event(winid_t win); + void glk_request_mouse_event(winid_t win); + + void glk_cancel_line_event(winid_t win, event_t *event); + void glk_cancel_char_event(winid_t win); + void glk_cancel_mouse_event(winid_t win); + +#ifdef GLK_MODULE_LINE_ECHO + void glk_set_echo_line_event(winid_t win, glui32 val); +#endif /* GLK_MODULE_LINE_ECHO */ + +#ifdef GLK_MODULE_LINE_TERMINATORS + void glk_set_terminators_line_event(winid_t win, glui32 *keycodes, + glui32 count); +#endif /* GLK_MODULE_LINE_TERMINATORS */ + + /** \addtogroup Unicode + * @{ + */ + + glui32 glk_buffer_to_lower_case_uni(glui32 *buf, glui32 len, + glui32 numchars); + glui32 glk_buffer_to_upper_case_uni(glui32 *buf, glui32 len, + glui32 numchars); + glui32 glk_buffer_to_title_case_uni(glui32 *buf, glui32 len, + glui32 numchars, glui32 lowerrest); + + void glk_put_char_uni(glui32 ch); + void glk_put_string_uni(glui32 *s); + void glk_put_buffer_uni(glui32 *buf, glui32 len); + void glk_put_char_stream_uni(strid_t str, glui32 ch); + void glk_put_string_stream_uni(strid_t str, const glui32 *s); + void glk_put_buffer_stream_uni(strid_t str, const glui32 *buf, glui32 len); + + glsi32 glk_get_char_stream_uni(strid_t str); + glui32 glk_get_buffer_stream_uni(strid_t str, glui32 *buf, glui32 len); + glui32 glk_get_line_stream_uni(strid_t str, glui32 *buf, glui32 len); + + strid_t glk_stream_open_file_uni(frefid_t fileref, FileMode fmode, glui32 rock = 0); + strid_t glk_stream_open_memory_uni(glui32 *buf, glui32 buflen, FileMode fmode, glui32 rock = 0); + + void glk_request_char_event_uni(winid_t win); + void glk_request_line_event_uni(winid_t win, glui32 *buf, + glui32 maxlen, glui32 initlen); + + /** @}*/ + +#ifdef GLK_MODULE_UNICODE_NORM + + glui32 glk_buffer_canon_decompose_uni(glui32 *buf, glui32 len, + glui32 numchars); + glui32 glk_buffer_canon_normalize_uni(glui32 *buf, glui32 len, + glui32 numchars); + +#endif /* GLK_MODULE_UNICODE_NORM */ + +#ifdef GLK_MODULE_IMAGE + + glui32 glk_image_draw(winid_t win, glui32 image, glsi32 val1, glsi32 val2); + glui32 glk_image_draw_scaled(winid_t win, glui32 image, + glsi32 val1, glsi32 val2, glui32 width, glui32 height); + glui32 glk_image_get_info(glui32 image, glui32 *width, glui32 *height); + + void glk_window_flow_break(winid_t win); + + void glk_window_erase_rect(winid_t win, + glsi32 left, glsi32 top, glui32 width, glui32 height); + void glk_window_fill_rect(winid_t win, glui32 color, + glsi32 left, glsi32 top, glui32 width, glui32 height); + void glk_window_set_background_color(winid_t win, glui32 color); + +#endif /* GLK_MODULE_IMAGE */ + +#ifdef GLK_MODULE_SOUND + + schanid_t glk_schannel_create(glui32 rock = 0); + void glk_schannel_destroy(schanid_t chan); + schanid_t glk_schannel_iterate(schanid_t chan, glui32 *rockptr); + glui32 glk_schannel_get_rock(schanid_t chan); + + glui32 glk_schannel_play(schanid_t chan, glui32 snd); + glui32 glk_schannel_play_ext(schanid_t chan, glui32 snd, glui32 repeats, + glui32 notify); + void glk_schannel_stop(schanid_t chan); + void glk_schannel_set_volume(schanid_t chan, glui32 vol); + + void glk_sound_load_hint(glui32 snd, glui32 flag); + +#ifdef GLK_MODULE_SOUND2 + /* Note that this section is nested inside the #ifdef GLK_MODULE_SOUND. + GLK_MODULE_SOUND must be defined if GLK_MODULE_SOUND2 is. */ + + schanid_t glk_schannel_create_ext(glui32 rock, glui32 volume); + glui32 glk_schannel_play_multi(schanid_t *chanarray, glui32 chancount, + glui32 *sndarray, glui32 soundcount, glui32 notify); + void glk_schannel_pause(schanid_t chan); + void glk_schannel_unpause(schanid_t chan); + void glk_schannel_set_volume_ext(schanid_t chan, glui32 vol, + glui32 duration, glui32 notify); + +#endif /* GLK_MODULE_SOUND2 */ +#endif /* GLK_MODULE_SOUND */ + +#ifdef GLK_MODULE_HYPERLINKS + + void glk_set_hyperlink(glui32 linkval); + void glk_set_hyperlink_stream(strid_t str, glui32 linkval); + void glk_request_hyperlink_event(winid_t win); + void glk_cancel_hyperlink_event(winid_t win); + +#endif /* GLK_MODULE_HYPERLINKS */ + +#ifdef GLK_MODULE_DATETIME + + void glk_current_time(glktimeval_t *time); + glsi32 glk_current_simple_time(glui32 factor); + void glk_time_to_date_utc(const glktimeval_t *time, glkdate_t *date); + void glk_time_to_date_local(const glktimeval_t *time, glkdate_t *date); + void glk_simple_time_to_date_utc(glsi32 time, glui32 factor, glkdate_t *date); + void glk_simple_time_to_date_local(glsi32 time, glui32 factor, glkdate_t *date); + void glk_date_to_time_utc(const glkdate_t *date, glktimeval_t *time); + void glk_date_to_time_local(const glkdate_t *date, glktimeval_t *time); + glsi32 glk_date_to_simple_time_utc(const glkdate_t *date, glui32 factor); + glsi32 glk_date_to_simple_time_local(const glkdate_t *date, glui32 factor); + +#endif /* GLK_MODULE_DATETIME */ + + /* XXX non-official Glk functions that may or may not exist */ +#define GARGLK 1 + + const char *garglk_fileref_get_name(frefid_t fref) const; + + void garglk_set_program_name(const char *name); + void garglk_set_program_info(const char *info); + void garglk_set_story_name(const char *name); + void garglk_set_story_title(const char *title); + void garglk_set_config(const char *name); + + /** + * Removes the specified string from the end of the output buffer, if + * indeed it is there. + */ + void garglk_unput_string(const char *str); + + /** + * Removes the specified string from the end of the output buffer, if + * indeed it is there. + */ + void garglk_unput_string_uni(const glui32 *str); + + void garglk_set_zcolors(glui32 fg, glui32 bg); + void garglk_set_zcolors_stream(strid_t str, glui32 fg, glui32 bg); + void garglk_set_reversevideo(glui32 reverse); + void garglk_set_reversevideo_stream(strid_t str, glui32 reverse); +}; + +} // End of namespace Glk + +#endif diff --git a/engines/glk/glk_types.h b/engines/glk/glk_types.h index 32b0968761..1745178a74 100644 --- a/engines/glk/glk_types.h +++ b/engines/glk/glk_types.h @@ -26,7 +26,7 @@ #include "common/scummsys.h" #include "common/stream.h" -namespace Gargoyle { +namespace Glk { typedef uint32 glui32; typedef int32 glsi32; @@ -203,6 +203,6 @@ union gidispatch_rock_t { void *ptr; }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/module.mk b/engines/glk/module.mk index e3fa26b684..3fd88ef011 100644 --- a/engines/glk/module.mk +++ b/engines/glk/module.mk @@ -6,8 +6,8 @@ MODULE_OBJS := \ detection.o \ events.o \ fonts.o \ - gargoyle.o \ glk.o \ + glk_api.o \ picture.o \ screen.o \ selection.o \ diff --git a/engines/glk/picture.cpp b/engines/glk/picture.cpp index 444589bde8..b87b1297eb 100644 --- a/engines/glk/picture.cpp +++ b/engines/glk/picture.cpp @@ -22,7 +22,7 @@ #include "glk/picture.h" -namespace Gargoyle { +namespace Glk { void PicList::increment() { // TODO @@ -60,4 +60,4 @@ void Picture::drawPicture(int x0, int y0, int dx0, int dy0, int dx1, int dy1) { } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/picture.h b/engines/glk/picture.h index e29d420bdf..3ca615b84f 100644 --- a/engines/glk/picture.h +++ b/engines/glk/picture.h @@ -25,7 +25,7 @@ #include "graphics/surface.h" -namespace Gargoyle { +namespace Glk { class PicList { public: @@ -68,6 +68,6 @@ public: void drawPicture(int x0, int y0, int dx0, int dy0, int dx1, int dy1); }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/scott/detection.cpp b/engines/glk/scott/detection.cpp index 900f6507fc..7afdf93bba 100644 --- a/engines/glk/scott/detection.cpp +++ b/engines/glk/scott/detection.cpp @@ -24,7 +24,7 @@ #include "common/file.h" #include "common/md5.h" -namespace Gargoyle { +namespace Glk { namespace Scott { struct ScottGame { @@ -106,4 +106,4 @@ bool ScottMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &g } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/scott/detection.h b/engines/glk/scott/detection.h index cd487bdfdd..2c187cdc4a 100644 --- a/engines/glk/scott/detection.h +++ b/engines/glk/scott/detection.h @@ -26,7 +26,7 @@ #include "common/fs.h" #include "engines/game.h" -namespace Gargoyle { +namespace Glk { namespace Scott { class ScottMetaEngine { @@ -38,6 +38,6 @@ public: }; } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/scott/scott.cpp b/engines/glk/scott/scott.cpp index a5e866796a..2def1a2a74 100644 --- a/engines/glk/scott/scott.cpp +++ b/engines/glk/scott/scott.cpp @@ -23,10 +23,10 @@ #include "glk/scott/scott.h" #include "common/config-manager.h" -namespace Gargoyle { +namespace Glk { namespace Scott { -Scott::Scott(OSystem *syst, const GargoyleGameDescription *gameDesc) : Glk(syst, gameDesc), +Scott::Scott(OSystem *syst, const GlkGameDescription *gameDesc) : GlkAPI(syst, gameDesc), Items(nullptr), Rooms(nullptr), Verbs(nullptr), Nouns(nullptr), Messages(nullptr), Actions(nullptr), CurrentCounter(0), SavedRoom(0), Options(0), Width(0), TopHeight(0), split_screen(true), Bottom(0), Top(0), BitFlags(0), _saveSlot(-1) { @@ -1260,4 +1260,4 @@ void Scott::readInts(Common::SeekableReadStream *f, size_t count, ...) { } } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/scott/scott.h b/engines/glk/scott/scott.h index ec6a8601ba..68994855fb 100644 --- a/engines/glk/scott/scott.h +++ b/engines/glk/scott/scott.h @@ -28,9 +28,9 @@ */ #include "common/scummsys.h" -#include "glk/glk.h" +#include "glk/glk_api.h" -namespace Gargoyle { +namespace Glk { namespace Scott { #define LIGHT_SOURCE 9 // Always 9 how odd @@ -109,7 +109,7 @@ struct Tail { /** * Scott Adams game interpreter */ -class Scott : public Glk { +class Scott : public GlkAPI { private: Header GameHeader; Item *Items; @@ -167,7 +167,7 @@ public: /** * Constructor */ - Scott(OSystem *syst, const GargoyleGameDescription *gameDesc); + Scott(OSystem *syst, const GlkGameDescription *gameDesc); /** * Execute the game @@ -186,6 +186,6 @@ public: }; } // End of namespace Scott -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/screen.cpp b/engines/glk/screen.cpp index ff46f1b57b..1a76ac8382 100644 --- a/engines/glk/screen.cpp +++ b/engines/glk/screen.cpp @@ -23,7 +23,7 @@ #include "glk/screen.h" #include "glk/conf.h" -namespace Gargoyle { +namespace Glk { void Screen::fill(const byte *rgb) { uint color = format.RGBToColor(rgb[0], rgb[1], rgb[2]); @@ -69,4 +69,4 @@ void Screen::drawCaret(const Point &pos) { } } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/screen.h b/engines/glk/screen.h index e81cf9faa4..0020d86f19 100644 --- a/engines/glk/screen.h +++ b/engines/glk/screen.h @@ -26,7 +26,7 @@ #include "graphics/screen.h" #include "glk/fonts.h" -namespace Gargoyle { +namespace Glk { enum CaretShape { SMALL_DOT = 0, FAT_DOT = 1, THIN_LINE = 2, FAT_LINE = 3, BLOCK = 4 @@ -60,6 +60,6 @@ public: void drawCaret(const Point &pos); }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/selection.cpp b/engines/glk/selection.cpp index f1c5bb86dc..2bc4fb81cb 100644 --- a/engines/glk/selection.cpp +++ b/engines/glk/selection.cpp @@ -22,11 +22,11 @@ #include "glk/selection.h" #include "glk/conf.h" -#include "glk/gargoyle.h" +#include "glk/glk.h" #include "glk/windows.h" #include "common/system.h" -namespace Gargoyle { +namespace Glk { void Clipboard::clipboardStore(const Common::U32String &text) { _text = text; @@ -318,4 +318,4 @@ bool Selection::getSelection(const Rect &r, int *rx0, int *rx1) const { return (rx0 && rx1); } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/selection.h b/engines/glk/selection.h index aa44a1d115..4497d68539 100644 --- a/engines/glk/selection.h +++ b/engines/glk/selection.h @@ -29,7 +29,7 @@ #include "common/rect.h" #include "common/ustr.h" -namespace Gargoyle { +namespace Glk { enum ClipSource { PRIMARY = 0, CLIPBOARD = 1 }; @@ -115,6 +115,6 @@ public: bool getSelection(const Rect &r, int *rx0, int *rx1) const; }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/speech.h b/engines/glk/speech.h index 5f9255565a..df4a89edc5 100644 --- a/engines/glk/speech.h +++ b/engines/glk/speech.h @@ -26,7 +26,7 @@ #include "common/events.h" #include "glk/glk_types.h" -namespace Gargoyle { +namespace Glk { /** * Currently not implemented @@ -44,6 +44,6 @@ protected: void gli_free_tts(void) {} }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/streams.cpp b/engines/glk/streams.cpp index d53f5d72a1..801cd549a8 100644 --- a/engines/glk/streams.cpp +++ b/engines/glk/streams.cpp @@ -23,14 +23,14 @@ #include "glk/streams.h" #include "glk/conf.h" #include "glk/events.h" -#include "glk/gargoyle.h" +#include "glk/glk.h" #include "glk/windows.h" #include "gui/saveload.h" #include "common/file.h" #include "common/savefile.h" #include "common/translation.h" -namespace Gargoyle { +namespace Glk { Stream::Stream(Streams *streams, bool readable, bool writable, uint32 rock, bool unicode) : _streams(streams), _readable(readable), _writable(writable), _readCount(0), @@ -1589,4 +1589,4 @@ void FileReference::deleteFile() { g_system->getSavefileManager()->removeSavefile(filename); } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/streams.h b/engines/glk/streams.h index 24ecc68eb5..32bde70887 100644 --- a/engines/glk/streams.h +++ b/engines/glk/streams.h @@ -29,7 +29,7 @@ #include "common/str.h" #include "glk/glk_types.h" -namespace Gargoyle { +namespace Glk { #define SAVEGAME_VERSION 1 @@ -634,6 +634,6 @@ public: frefid_t iterate(frefid_t fref, glui32 *rock); }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/time.cpp b/engines/glk/time.cpp index 9442102779..df09716a7f 100644 --- a/engines/glk/time.cpp +++ b/engines/glk/time.cpp @@ -23,7 +23,7 @@ #include "glk/time.h" #include "common/system.h" -namespace Gargoyle { +namespace Glk { TimeAndDate::TimeAndDate() { ::TimeDate t; @@ -117,4 +117,4 @@ TimeSeconds TimeAndDate::getTime() const { return totalMinutes * 60 + second; } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/time.h b/engines/glk/time.h index 119fab76e5..8e68328dcf 100644 --- a/engines/glk/time.h +++ b/engines/glk/time.h @@ -25,7 +25,7 @@ #include "glk/glk_types.h" -namespace Gargoyle { +namespace Glk { typedef int64 TimeSeconds; @@ -88,6 +88,6 @@ public: }; typedef TimeAndDate glkdate_t; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/unicode.cpp b/engines/glk/unicode.cpp index dd88c9571a..d9f2ee111f 100644 --- a/engines/glk/unicode.cpp +++ b/engines/glk/unicode.cpp @@ -24,7 +24,7 @@ #include "glk/unicode_gen.h" #include "common/textconsole.h" -namespace Gargoyle { +namespace Glk { size_t strlen_uni(const uint32 *s) { size_t len = 0; @@ -148,4 +148,4 @@ glui32 bufferChangeCase(glui32 *buf, glui32 len, glui32 numchars, BufferChangeCa return outcount; } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/unicode.h b/engines/glk/unicode.h index 249ab5dade..3165d398b3 100644 --- a/engines/glk/unicode.h +++ b/engines/glk/unicode.h @@ -25,7 +25,7 @@ #include "glk/glk_types.h" -namespace Gargoyle { +namespace Glk { typedef glui32 gli_case_block_t[2]; /* upper, lower */ enum BufferChangeCase { CASE_UPPER = 0, CASE_LOWER = 1, CASE_TITLE = 2, CASE_IDENT = 3 }; @@ -46,6 +46,6 @@ size_t strlen_uni(const uint32 *s); extern glui32 bufferChangeCase(glui32 *buf, glui32 len, glui32 numchars, BufferChangeCase destcase, BufferChangeCond cond, int changerest); -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/unicode_gen.cpp b/engines/glk/unicode_gen.cpp index ac8a149f7e..9c6785959a 100644 --- a/engines/glk/unicode_gen.cpp +++ b/engines/glk/unicode_gen.cpp @@ -27,7 +27,7 @@ #include "glk/unicode_gen.h" -namespace Gargoyle { +namespace Glk { gli_case_block_t unigen_case_block_0x0[256] = { { 0x0, 0x0 }, @@ -11823,4 +11823,4 @@ gli_decomp_block_t unigen_decomp_block_0x2fa[256] = { *countptr = 0; \ } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/unicode_gen.h b/engines/glk/unicode_gen.h index f601bf6b92..6822d699f4 100644 --- a/engines/glk/unicode_gen.h +++ b/engines/glk/unicode_gen.h @@ -25,7 +25,7 @@ #include "glk/glk_types.h" -namespace Gargoyle { +namespace Glk { #define GET_CASE_BLOCK(ch, blockptr) \ switch ((glui32)(ch) >> 8) { \ @@ -558,6 +558,6 @@ extern gli_case_special_t unigen_special_0xfb16; extern gli_case_special_t unigen_special_0xfb17; extern glui32 unigen_special_array[]; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/utils.cpp b/engines/glk/utils.cpp index 12f9e304e5..07c0a4d540 100644 --- a/engines/glk/utils.cpp +++ b/engines/glk/utils.cpp @@ -23,7 +23,7 @@ #include "glk/utils.h" #include "common/textconsole.h" -namespace Gargoyle { +namespace Glk { int strToInt(const char *s) { if (!*s) @@ -41,4 +41,4 @@ int strToInt(const char *s) { return (int)tmp; } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/utils.h b/engines/glk/utils.h index 361c65fa20..3655f57c33 100644 --- a/engines/glk/utils.h +++ b/engines/glk/utils.h @@ -26,7 +26,7 @@ #include "common/rect.h" #include "glk/glk_types.h" -namespace Gargoyle { +namespace Glk { typedef Common::Point Point; @@ -46,6 +46,6 @@ public: */ int strToInt(const char *s); -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/window_graphics.cpp b/engines/glk/window_graphics.cpp index 4eea5c0316..e80fc8e8a8 100644 --- a/engines/glk/window_graphics.cpp +++ b/engines/glk/window_graphics.cpp @@ -22,10 +22,10 @@ #include "glk/window_graphics.h" #include "glk/conf.h" -#include "glk/gargoyle.h" +#include "glk/glk.h" #include "glk/screen.h" -namespace Gargoyle { +namespace Glk { GraphicsWindow::GraphicsWindow(Windows *windows, uint32 rock) : Window(windows, rock), _w(0), _h(0), _dirty(false), _surface(nullptr) { @@ -269,4 +269,4 @@ void GraphicsWindow::click(const Point &newPos) { } } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/window_graphics.h b/engines/glk/window_graphics.h index 1ddc26c1cc..c2f4a556a3 100644 --- a/engines/glk/window_graphics.h +++ b/engines/glk/window_graphics.h @@ -26,7 +26,7 @@ #include "glk/windows.h" #include "glk/picture.h" -namespace Gargoyle { +namespace Glk { /** * Graphics window @@ -108,6 +108,6 @@ public: virtual void setBackgroundColor(glui32 color) override; }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/window_pair.cpp b/engines/glk/window_pair.cpp index 56e5b453e0..a0fdbb440b 100644 --- a/engines/glk/window_pair.cpp +++ b/engines/glk/window_pair.cpp @@ -22,10 +22,10 @@ #include "glk/window_pair.h" #include "glk/conf.h" -#include "glk/gargoyle.h" +#include "glk/glk.h" #include "glk/screen.h" -namespace Gargoyle { +namespace Glk { PairWindow::PairWindow(Windows *windows, glui32 method, Window *key, glui32 size) : Window(windows, 0), @@ -233,4 +233,4 @@ void PairWindow::click(const Point &newPos) { _child2->click(newPos); } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/window_pair.h b/engines/glk/window_pair.h index 11b4e499ee..f77ae9243b 100644 --- a/engines/glk/window_pair.h +++ b/engines/glk/window_pair.h @@ -25,7 +25,7 @@ #include "glk/windows.h" -namespace Gargoyle { +namespace Glk { /** * Pair window @@ -68,6 +68,6 @@ public: virtual void click(const Point &newPos) override; }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/window_text_buffer.cpp b/engines/glk/window_text_buffer.cpp index 1506f4e163..36d8c6e298 100644 --- a/engines/glk/window_text_buffer.cpp +++ b/engines/glk/window_text_buffer.cpp @@ -22,12 +22,12 @@ #include "glk/window_text_buffer.h" #include "glk/conf.h" -#include "glk/gargoyle.h" +#include "glk/glk.h" #include "glk/screen.h" #include "glk/selection.h" #include "glk/unicode.h" -namespace Gargoyle { +namespace Glk { /** * @@ -1633,4 +1633,4 @@ TextBufferWindow::TextBufferRow::TextBufferRow() : _len(0), _newLine(0), _dirty( Common::fill(&_chars[0], &_chars[TBLINELEN], 0); } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/window_text_buffer.h b/engines/glk/window_text_buffer.h index a26a95b5bc..4384986640 100644 --- a/engines/glk/window_text_buffer.h +++ b/engines/glk/window_text_buffer.h @@ -27,7 +27,7 @@ #include "glk/picture.h" #include "glk/speech.h" -namespace Gargoyle { +namespace Glk { /** * Text Buffer window @@ -240,6 +240,6 @@ public: } }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/window_text_grid.cpp b/engines/glk/window_text_grid.cpp index 963083659f..e16c9bd79a 100644 --- a/engines/glk/window_text_grid.cpp +++ b/engines/glk/window_text_grid.cpp @@ -22,11 +22,11 @@ #include "glk/window_text_grid.h" #include "glk/conf.h" -#include "glk/gargoyle.h" +#include "glk/glk.h" #include "glk/selection.h" #include "glk/screen.h" -namespace Gargoyle { +namespace Glk { TextGridWindow::TextGridWindow(Windows *windows, uint32 rock) : Window(windows, rock) { _type = wintype_TextGrid; @@ -651,4 +651,4 @@ void TextGridWindow::TextGridRow::resize(size_t newSize) { Common::fill(&_chars[0], &_chars[0] + newSize, ' '); } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/window_text_grid.h b/engines/glk/window_text_grid.h index acfd366cb2..30a0f79b25 100644 --- a/engines/glk/window_text_grid.h +++ b/engines/glk/window_text_grid.h @@ -25,7 +25,7 @@ #include "glk/windows.h" -namespace Gargoyle { +namespace Glk { /** * Text Grid window @@ -190,6 +190,6 @@ public: } }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif diff --git a/engines/glk/windows.cpp b/engines/glk/windows.cpp index d982f6ccb5..02298ad79e 100644 --- a/engines/glk/windows.cpp +++ b/engines/glk/windows.cpp @@ -26,13 +26,13 @@ #include "glk/window_text_buffer.h" #include "glk/window_text_grid.h" #include "glk/conf.h" -#include "glk/gargoyle.h" +#include "glk/glk.h" #include "glk/screen.h" #include "glk/streams.h" #include "common/algorithm.h" #include "common/textconsole.h" -namespace Gargoyle { +namespace Glk { bool Windows::_overrideReverse; bool Windows::_overrideFgSet; @@ -770,4 +770,4 @@ byte *Attributes::attrFg(WindowStyle *styles) { } } -} // End of namespace Gargoyle +} // End of namespace Glk diff --git a/engines/glk/windows.h b/engines/glk/windows.h index 5bf5f2aa32..98f0d2d6df 100644 --- a/engines/glk/windows.h +++ b/engines/glk/windows.h @@ -33,7 +33,7 @@ #include "glk/selection.h" #include "glk/streams.h" -namespace Gargoyle { +namespace Glk { class Window; class PairWindow; @@ -536,6 +536,6 @@ public: BlankWindow(Windows *windows, uint32 rock); }; -} // End of namespace Gargoyle +} // End of namespace Glk #endif |