From c545ebd0d5d1b0690e16f7472048e7ffde40d934 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 8 Jun 2011 00:01:44 +0200 Subject: [PATCH 001/276] CGE: Add minimal engine and detection --- base/plugins.cpp | 3 + configure | 1 + engines/cge/cge.cpp | 68 ++++++++++ engines/cge/cge.h | 67 ++++++++++ engines/cge/console.cpp | 34 +++++ engines/cge/console.h | 43 +++++++ engines/cge/detection.cpp | 255 ++++++++++++++++++++++++++++++++++++++ engines/cge/module.mk | 17 +++ engines/engines.mk | 5 + 9 files changed, 493 insertions(+) create mode 100644 engines/cge/cge.cpp create mode 100644 engines/cge/cge.h create mode 100644 engines/cge/console.cpp create mode 100644 engines/cge/console.h create mode 100644 engines/cge/detection.cpp create mode 100644 engines/cge/module.mk diff --git a/base/plugins.cpp b/base/plugins.cpp index 4a3b2017142..a838414da32 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -94,6 +94,9 @@ public: #if PLUGIN_ENABLED_STATIC(AGOS) LINK_PLUGIN(AGOS) #endif + #if PLUGIN_ENABLED_STATIC(CGE) + LINK_PLUGIN(CGE) + #endif #if PLUGIN_ENABLED_STATIC(CINE) LINK_PLUGIN(CINE) #endif diff --git a/configure b/configure index b436a3822db..711bd6eaee9 100755 --- a/configure +++ b/configure @@ -79,6 +79,7 @@ add_engine he "HE71+ games" yes add_engine agi "AGI" yes add_engine agos "AGOS" yes "agos2" add_engine agos2 "AGOS 2 games" yes +add_engine cge "CGE" no add_engine cine "Cinematique evo 1" yes add_engine cruise "Cinematique evo 2" yes add_engine draci "Dragon History" yes diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp new file mode 100644 index 00000000000..e7c462e7726 --- /dev/null +++ b/engines/cge/cge.cpp @@ -0,0 +1,68 @@ +/* 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.h" +#include "common/debug-channels.h" +#include "common/error.h" +#include "common/EventRecorder.h" +#include "common/file.h" +#include "common/fs.h" + +#include "engines/util.h" + +#include "cge/cge.h" + +namespace CGE { + +CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) + : Engine(syst), _gameDescription(gameDescription) { + + DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel"); + _console = new CGEConsole(this); + + debug("CGEEngine::CGEEngine"); +} + +CGEEngine::~CGEEngine() { + debug("CGEEngine::~CGEEngine"); + + // Remove all of our debug levels here + DebugMan.clearAllDebugChannels(); +} + +Common::Error CGEEngine::run() { + // Initialize graphics using following: + initGraphics(320, 200, false); + + // Create debugger console. It requires GFX to be initialized + _console = new CGEConsole(this); + + // Additional setup. + debug("CGEEngine::init"); + + return Common::kNoError; +} + +} // End of namespace CGE diff --git a/engines/cge/cge.h b/engines/cge/cge.h new file mode 100644 index 00000000000..fac4f2c6cc4 --- /dev/null +++ b/engines/cge/cge.h @@ -0,0 +1,67 @@ +/* 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 CGE_H +#define CGE_H + +#include "common/random.h" +#include "engines/engine.h" +#include "gui/debugger.h" +#include "graphics/surface.h" +#include "engines/advancedDetector.h" +#include "cge/console.h" + +#define CGE_SAVEGAME_VERSION 1 + +namespace CGE { + +class Console; + +// our engine debug channels +enum { + kCGEDebug = 1 << 0 +}; + +class CGEEngine : public Engine { +public: + CGEEngine(OSystem *syst, const ADGameDescription *gameDescription); + ~CGEEngine(); + + const ADGameDescription *_gameDescription; + + virtual Common::Error run(); + GUI::Debugger *getDebugger() { return _console; } + +private: + CGEConsole *_console; +}; + +// Example console class +class Console : public GUI::Debugger { +public: + Console(CGEEngine *vm) {} + virtual ~Console(void) {} +}; + +} // End of namespace CGE + +#endif diff --git a/engines/cge/console.cpp b/engines/cge/console.cpp new file mode 100644 index 00000000000..71eedf34eab --- /dev/null +++ b/engines/cge/console.cpp @@ -0,0 +1,34 @@ +/* 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 "cge/console.h" +#include "cge/cge.h" + +namespace CGE { + +CGEConsole::CGEConsole(CGEEngine *vm) : GUI::Debugger(), _vm(vm) { +} + +CGEConsole::~CGEConsole() { +} + +} // End of namespace CGE diff --git a/engines/cge/console.h b/engines/cge/console.h new file mode 100644 index 00000000000..7f265202ea7 --- /dev/null +++ b/engines/cge/console.h @@ -0,0 +1,43 @@ +/* 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 CGE_CONSOLE_H +#define CGE_CONSOLE_H + +#include "gui/debugger.h" + +namespace CGE { + +class CGEEngine; + +class CGEConsole : public GUI::Debugger { +public: + CGEConsole(CGEEngine *vm); + virtual ~CGEConsole(void); + +private: + CGEEngine *_vm; +}; + +} // End of namespace CGE + +#endif diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp new file mode 100644 index 00000000000..7d7a82a82ba --- /dev/null +++ b/engines/cge/detection.cpp @@ -0,0 +1,255 @@ +/* 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/config-manager.h" +#include "engines/advancedDetector.h" +#include "common/savefile.h" +#include "common/system.h" +#include "base/plugins.h" +#include "graphics/thumbnail.h" +#include "cge/cge.h" + +static const PlainGameDescriptor CGEGames[] = { + { "soltys", "Soltys" }, + { 0, 0 } +}; + +namespace CGE { + +using Common::GUIO_NONE; + +static const ADGameDescription gameDescriptions[] = { + + { + "soltys", "", + { + {"vol.cat", 0, "0c33e2c304821a2444d297fc5e2d67c6", 50176}, + {"vol.dat", 0, "f9ae2e7f8f7cac91378cdafca43faf1e", 8437572}, + AD_LISTEND + }, + Common::PL_POL, Common::kPlatformPC, ADGF_NO_FLAGS, GUIO_NONE + }, + { + "soltys", "Soltys Freeware", + { + {"vol.cat", 0, "0c33e2c304821a2444d297fc5e2d67c6", 50176}, + {"vol.dat", 0, "f9ae2e7f8f7cac91378cdafca43faf1e", 8437676}, + AD_LISTEND + }, + Common::PL_POL, Common::kPlatformPC, ADGF_NO_FLAGS, GUIO_NONE + }, + { + "soltys", "Soltys Demo", + { + {"vol.cat", 0, "1e077c8ff58109a187f07ac54b0c873a", 18788}, + {"vol.dat", 0, "75d385a6074c58b69f7730481f256051", 1796710}, + AD_LISTEND + }, + Common::PL_POL, Common::kPlatformPC, ADGF_NO_FLAGS, GUIO_NONE + }, + { + "soltys", "Soltys Demo", + { + {"vol.cat", 0, "f17987487fab1ebddd781d8d02fedecc", 7168}, + {"vol.dat", 0, "c5d9b15863cab61dc125551576dece04", 1075272}, + AD_LISTEND + }, + Common::PL_POL, Common::kPlatformPC, ADGF_NO_FLAGS, GUIO_NONE + }, + AD_TABLE_END_MARKER +}; + +static const ADFileBasedFallback fileBasedFallback[] = { + { &gameDescriptions[0], { "vol.cat", "vol.dat", 0 } }, + { 0, { 0 } } +}; + +} // End of namespace CGE + +static const ADParams detectionParams = { + // Pointer to ADGameDescription or its superset structure + (const byte *)CGE::gameDescriptions, + // Size of that superset structure + sizeof(ADGameDescription), + // Number of bytes to compute MD5 sum for + 5000, + // List of all engine targets + CGEGames, + // Structure for autoupgrading obsolete targets + 0, + // Name of single gameid (optional) + "Soltys", + // List of files for file-based fallback detection (optional) + CGE::fileBasedFallback, + // Flags + 0, + // Additional GUI options (for every game} + Common::GUIO_NONE, + // Maximum directory depth + 0, + // List of directory globs + NULL +}; + +class CGEMetaEngine : public AdvancedMetaEngine { +public: + CGEMetaEngine() : AdvancedMetaEngine(detectionParams) {} + + virtual const char *getName() const { + return "CGE"; + } + + virtual const char *getOriginalCopyright() const { + return "Soltys (c) 1994-1996 L.K. Avalon"; + } + + virtual bool hasFeature(MetaEngineFeature f) const; + virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; + virtual int getMaximumSaveSlot() const; + virtual SaveStateList listSaves(const char *target) const; + SaveStateDescriptor querySaveMetaInfos(const char *target, int slot) const; + virtual void removeSaveState(const char *target, int slot) const; +}; + +bool CGEMetaEngine::hasFeature(MetaEngineFeature f) const { + return + (f == kSupportsListSaves) || + (f == kSupportsLoadingDuringStartup) || + (f == kSupportsDeleteSave) || + (f == kSavesSupportMetaInfo) || + (f == kSavesSupportThumbnail) || + (f == kSavesSupportCreationDate); +} + +void CGEMetaEngine::removeSaveState(const char *target, int slot) const { + Common::String fileName = Common::String::format("%s.%03d", target, slot); + g_system->getSavefileManager()->removeSavefile(fileName); +} + +int CGEMetaEngine::getMaximumSaveSlot() const { return 99; } + +SaveStateList CGEMetaEngine::listSaves(const char *target) const { + Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); + Common::StringArray filenames; + Common::String pattern = target; + pattern += ".???"; + + filenames = saveFileMan->listSavefiles(pattern); + sort(filenames.begin(), filenames.end()); // Sort (hopefully ensuring we are sorted numerically..) + + SaveStateList saveList; + int slotNum = 0; + for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { + // Obtain the last 3 digits of the filename, since they correspond to the save slot + slotNum = atoi(filename->c_str() + filename->size() - 3); + + if (slotNum >= 0 && slotNum <= 99) { + Common::InSaveFile *file = saveFileMan->openForLoading(*filename); + if (file) { + int32 version = file->readSint32BE(); + if (version != CGE_SAVEGAME_VERSION) { + delete file; + continue; + } + + // read name + uint16 nameSize = file->readUint16BE(); + if (nameSize >= 255) { + delete file; + continue; + } + char name[256]; + file->read(name, nameSize); + name[nameSize] = 0; + + saveList.push_back(SaveStateDescriptor(slotNum, name)); + delete file; + } + } + } + + return saveList; +} + +SaveStateDescriptor CGEMetaEngine::querySaveMetaInfos(const char *target, int slot) const { + Common::String fileName = Common::String::format("%s.%03d", target, slot); + Common::InSaveFile *file = g_system->getSavefileManager()->openForLoading(fileName); + + if (file) { + + int32 version = file->readSint32BE(); + if (version != CGE_SAVEGAME_VERSION) { + delete file; + return SaveStateDescriptor(); + } + + uint32 saveNameLength = file->readUint16BE(); + char saveName[256]; + file->read(saveName, saveNameLength); + saveName[saveNameLength] = 0; + + SaveStateDescriptor desc(slot, saveName); + + Graphics::Surface *thumbnail = new Graphics::Surface(); + assert(thumbnail); + if (!Graphics::loadThumbnail(*file, *thumbnail)) { + delete thumbnail; + thumbnail = 0; + } + desc.setThumbnail(thumbnail); + + desc.setDeletableFlag(true); + desc.setWriteProtectedFlag(false); + + uint32 saveDate = file->readUint32BE(); + uint16 saveTime = file->readUint16BE(); + + int day = (saveDate >> 24) & 0xFF; + int month = (saveDate >> 16) & 0xFF; + int year = saveDate & 0xFFFF; + + desc.setSaveDate(year, month, day); + + int hour = (saveTime >> 8) & 0xFF; + int minutes = saveTime & 0xFF; + + desc.setSaveTime(hour, minutes); + + delete file; + return desc; + } + + return SaveStateDescriptor(); +} + +bool CGEMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { + if (desc) { + *engine = new CGE::CGEEngine(syst, desc); + } + return desc != 0; +} + +#if PLUGIN_ENABLED_DYNAMIC(CGE) + REGISTER_PLUGIN_DYNAMIC(CGE, PLUGIN_TYPE_ENGINE, CGEMetaEngine); +#else + REGISTER_PLUGIN_STATIC(CGE, PLUGIN_TYPE_ENGINE, CGEMetaEngine); +#endif diff --git a/engines/cge/module.mk b/engines/cge/module.mk new file mode 100644 index 00000000000..62ddd9d3623 --- /dev/null +++ b/engines/cge/module.mk @@ -0,0 +1,17 @@ +MODULE := engines/cge + +MODULE_OBJS := \ + cge.o \ + console.o \ + detection.o + +MODULE_DIRS += \ + engines/cge + +# This module can be built as a plugin +ifeq ($(ENABLE_CGE), DYNAMIC_PLUGIN) +PLUGIN := 1 +endif + +# Include common rules +include $(srcdir)/rules.mk diff --git a/engines/engines.mk b/engines/engines.mk index f8ff823c13e..63e4665d286 100644 --- a/engines/engines.mk +++ b/engines/engines.mk @@ -26,6 +26,11 @@ DEFINES += -DENABLE_AGOS2 endif endif +ifdef ENABLE_CGE +DEFINES += -DENABLE_CGE=$(ENABLE_CGE) +MODULES += engines/cge +endif + ifdef ENABLE_CINE DEFINES += -DENABLE_CINE=$(ENABLE_CINE) MODULES += engines/cine From 01a7e7ad60819d247bfe815a8e2183a46c1c6437 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 9 Jun 2011 08:20:53 +0200 Subject: [PATCH 002/276] CGE: Add several sources based on headers --- engines/cge/bitmap.cpp | 433 ++++++++ engines/cge/bitmap.h | 60 + engines/cge/bitmaps.cpp | 214 ++++ engines/cge/bitmaps.h | 18 + engines/cge/boot.h | 49 + engines/cge/cfile.cpp | 332 ++++++ engines/cge/cfile.h | 56 + engines/cge/cge.cpp | 5 +- engines/cge/cge.h | 2 +- engines/cge/cge_main.cpp | 2232 ++++++++++++++++++++++++++++++++++++++ engines/cge/cge_main.h | 181 ++++ engines/cge/drop.h | 1 + engines/cge/game.cpp | 91 ++ engines/cge/game.h | 40 + engines/cge/general.h | 241 ++++ engines/cge/gettext.cpp | 110 ++ engines/cge/gettext.h | 35 + engines/cge/ident.h | 14 + engines/cge/jbw.h | 149 +++ engines/cge/keybd.cpp | 114 ++ engines/cge/keybd.h | 31 + engines/cge/mixer.cpp | 129 +++ engines/cge/mixer.h | 31 + engines/cge/module.mk | 19 +- engines/cge/mouse.cpp | 207 ++++ engines/cge/mouse.h | 58 + engines/cge/snail.cpp | 1280 ++++++++++++++++++++++ engines/cge/snail.h | 98 ++ engines/cge/snddrv.h | 104 ++ engines/cge/sound.cpp | 293 +++++ engines/cge/sound.h | 61 ++ engines/cge/startup.cpp | 168 +++ engines/cge/startup.h | 52 + engines/cge/talk.cpp | 376 +++++++ engines/cge/talk.h | 81 ++ engines/cge/text.cpp | 291 +++++ engines/cge/text.h | 60 + engines/cge/vga13h.cpp | 1775 ++++++++++++++++++++++++++++++ engines/cge/vga13h.h | 310 ++++++ engines/cge/vmenu.cpp | 149 +++ engines/cge/vmenu.h | 45 + engines/cge/vol.cpp | 79 ++ engines/cge/vol.h | 64 ++ engines/cge/wav.h | 109 ++ 44 files changed, 10244 insertions(+), 3 deletions(-) create mode 100644 engines/cge/bitmap.cpp create mode 100644 engines/cge/bitmap.h create mode 100644 engines/cge/bitmaps.cpp create mode 100644 engines/cge/bitmaps.h create mode 100644 engines/cge/boot.h create mode 100644 engines/cge/cfile.cpp create mode 100644 engines/cge/cfile.h create mode 100644 engines/cge/cge_main.cpp create mode 100644 engines/cge/cge_main.h create mode 100644 engines/cge/drop.h create mode 100644 engines/cge/game.cpp create mode 100644 engines/cge/game.h create mode 100644 engines/cge/general.h create mode 100644 engines/cge/gettext.cpp create mode 100644 engines/cge/gettext.h create mode 100644 engines/cge/ident.h create mode 100644 engines/cge/jbw.h create mode 100644 engines/cge/keybd.cpp create mode 100644 engines/cge/keybd.h create mode 100644 engines/cge/mixer.cpp create mode 100644 engines/cge/mixer.h create mode 100644 engines/cge/mouse.cpp create mode 100644 engines/cge/mouse.h create mode 100644 engines/cge/snail.cpp create mode 100644 engines/cge/snail.h create mode 100644 engines/cge/snddrv.h create mode 100644 engines/cge/sound.cpp create mode 100644 engines/cge/sound.h create mode 100644 engines/cge/startup.cpp create mode 100644 engines/cge/startup.h create mode 100644 engines/cge/talk.cpp create mode 100644 engines/cge/talk.h create mode 100644 engines/cge/text.cpp create mode 100644 engines/cge/text.h create mode 100644 engines/cge/vga13h.cpp create mode 100644 engines/cge/vga13h.h create mode 100644 engines/cge/vmenu.cpp create mode 100644 engines/cge/vmenu.h create mode 100644 engines/cge/vol.cpp create mode 100644 engines/cge/vol.h create mode 100644 engines/cge/wav.h diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp new file mode 100644 index 00000000000..f3a7f853313 --- /dev/null +++ b/engines/cge/bitmap.cpp @@ -0,0 +1,433 @@ +#include "bitmap.h" +#include + +#ifdef VOL + #include "vol.h" +#endif + +#ifdef DROP_H + #include "drop.h" +#endif + + +#include +#include +#include +#include + + +//-------------------------------------------------------------------------- + + + + +DAC far * BITMAP::Pal = NULL; + + + +#pragma argsused +BITMAP::BITMAP (const char * fname, Boolean rem) +: M(NULL), V(NULL) +{ + char pat[MAXPATH]; + + ForceExt(pat, fname, ".VBM"); + + #if (BMP_MODE < 2) + if (rem && PIC_FILE::Exist(pat)) + { + PIC_FILE file(pat); + if (file.Error == 0) + if (! VBMLoad(&file)) + DROP("Bad VBM", fname); + } + else + #endif + { + #if (BMP_MODE) + ForceExt(pat, fname, ".BMP"); + PIC_FILE file(pat); + if (file.Error == 0) + { + if (BMPLoad(&file)) + { + Code(); + if (rem) + { + farfree(M); + M = NULL; + } + } + else DROP("Bad BMP", fname); + } + #else + DROP("Bad VBM", fname); + #endif + } +} + + + + + +BITMAP::BITMAP (word w, word h, byte far * map) +: W(w), H(h), M(map), V(NULL) +{ + if (map) Code(); +} + + + + +// following routine creates filled rectangle +// immediately as VGA video chunks, in near memory as fast as possible, +// especially for text line real time display + +BITMAP::BITMAP (word w, word h, byte fill) +: W((w + 3) & ~3), // only full dwords allowed! + H(h), + M(NULL) +{ + word dsiz = W >> 2; // data size (1 plane line size) + word lsiz = 2 + dsiz + 2; // word for line header, word for gap + word psiz = H * lsiz; // - last gape, but + plane trailer + byte * v = new byte[4 * psiz // the same for 4 planes + + H * sizeof(*B)]; // + room for wash table + if (v == NULL) DROP("No core", NULL); + + * (word *) v = CPY | dsiz; // data chunk hader + memset(v+2, fill, dsiz); // data bytes + * (word *) (v + lsiz - 2) = SKP | ((SCR_WID / 4) - dsiz); // gap + memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines + * (word *) (v + psiz - 2) = EOI; // plane trailer word + memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes + HideDesc * b = (HideDesc *) (v + 4 * psiz); + b->skip = (SCR_WID - W) >> 2; + b->hide = W >> 2; + memcpy(b+1, b, (H-1) * sizeof(*b)); // tricky fill entire table + b->skip = 0; // fix the first entry + V = v; + B = b; +} + + + + + + + +BITMAP::BITMAP (const BITMAP& bmp) +: W(bmp.W), H(bmp.H), + M(NULL), V(NULL) +{ + byte far * v0 = bmp.V; + if (v0) + { + word vsiz = FP_OFF(bmp.B) - FP_OFF(v0); + word siz = vsiz + H * sizeof(HideDesc); + byte far * v1 = farnew(byte, siz); + if (v1 == NULL) DROP("No core", NULL); + _fmemcpy(v1, v0, siz); + B = (HideDesc far *) ((V = v1) + vsiz); + } +} + + + + + +BITMAP::~BITMAP (void) +{ + switch (MemType(M)) + { + case FAR_MEM : farfree(M); break; + } + switch (MemType(V)) + { + case NEAR_MEM : delete[] (byte *) V; break; + case FAR_MEM : farfree(V); break; + } +} + + + +BITMAP& BITMAP::operator = (const BITMAP& bmp) +{ + byte far * v0 = bmp.V; + W = bmp.W; + H = bmp.H; + M = NULL; + if (MemType(V) == FAR_MEM) farfree(V); + if (v0 == NULL) V = NULL; + else + { + word vsiz = FP_OFF(bmp.B) - FP_OFF(v0); + word siz = vsiz + H * sizeof(HideDesc); + byte far * v1 = farnew(byte, siz); + if (v1 == NULL) DROP("No core", NULL); + _fmemcpy(v1, v0, siz); + B = (HideDesc far *) ((V = v1) + vsiz); + } + return *this; +} + + + + + +word BITMAP::MoveVmap (byte far * buf) +{ + if (V) + { + word vsiz = FP_OFF(B) - FP_OFF(V); + word siz = vsiz + H * sizeof(HideDesc); + _fmemcpy(buf, V, siz); + if (MemType(V) == FAR_MEM) farfree(V); + B = (HideDesc far *) ((V = buf) + vsiz); + return siz; + } + return 0; +} + + + + + + + +BMP_PTR BITMAP::Code (void) +{ + if (M) + { + word i, cnt; + + if (V) // old X-map exists, so remove it + { + switch (MemType(V)) + { + case NEAR_MEM : delete[] (byte *) V; break; + case FAR_MEM : farfree(V); break; + } + V = NULL; + } + + while (TRUE) // at most 2 times: for (V == NULL) & for allocated block; + { + byte far * im = V+2; + word far * cp = (word far *) V; + int bpl; + + if (V) // 2nd pass - fill the hide table + { + for (i = 0; i < H; i ++) + { + B[i].skip = 0xFFFF; + B[i].hide = 0x0000; + } + } + for (bpl = 0; bpl < 4; bpl ++) // once per each bitplane + { + byte far * bm = M; + Boolean skip = (bm[bpl] == TRANS); + word j; + + cnt = 0; + for (i = 0; i < H; i ++) // once per each line + { + byte pix; + for (j = bpl; j < W; j += 4) + { + pix = bm[j]; + if (V && pix != TRANS) + { + if (j < B[i].skip) B[i].skip = j; + if (j >= B[i].hide) B[i].hide = j+1; + } + if ((pix == TRANS) != skip || cnt >= 0x3FF0) // end of block + { + cnt |= (skip) ? SKP : CPY; + if (V) + { + *cp = cnt; // store block description word + } + cp = (word far *) im; + im += 2; + skip = (pix == TRANS); + cnt = 0; + } + if (! skip) + { + if (V) * im = pix; + ++ im; + } + ++ cnt; + } + + bm += W; + if (W < SCR_WID) + { + if (skip) + { + cnt += (SCR_WID - j + 3) / 4; + } + else + { + cnt |= CPY; + if (V) + { + *cp = cnt; + } + cp = (word far *) im; + im += 2; + skip = TRUE; + cnt = (SCR_WID - j + 3) / 4; + } + } + } + if (cnt && ! skip) + { + cnt |= CPY; + if (V) + { + *cp = cnt; + } + cp = (word far *) im; + im += 2; + } + if (V) *cp = EOI; + cp = (word far *) im; + im += 2; + } + if (V) break; + word sizV = (word) (im - 2 - V); + V = farnew(byte, sizV + H * sizeof(*B)); + if (! V) + { + DROP("No core", NULL); + } + B = (HideDesc far *) (V + sizV); + } + cnt = 0; + for (i = 0; i < H; i ++) + { + if (B[i].skip == 0xFFFF) // whole line is skipped + { + B[i].skip = (cnt + SCR_WID) >> 2; + cnt = 0; + } + else + { + word s = B[i].skip & ~3; + word h = (B[i].hide + 3) & ~3; + B[i].skip = (cnt + s) >> 2; + B[i].hide = (h - s) >> 2; + cnt = SCR_WID - h; + } + } + } + return this; +} + + + + + + +Boolean BITMAP::SolidAt (int x, int y) +{ + byte far * m; + word r, n, n0; + + if (x >= W || y >= H) return FALSE; + + m = V; + r = x % 4; + n0 = (SCR_WID * y + x) / 4, n = 0; + + while (r) + { + word w, t; + + w = * (word far *) m; + m += 2; + t = w & 0xC000; + w &= 0x3FFF; + + switch (t) + { + case EOI : -- r; + case SKP : w = 0; break; + case REP : w = 1; break; + } + m += w; + } + + while (TRUE) + { + word w, t; + + w = * (word far *) m; + m += 2; + t = w & 0xC000; + w &= 0x3FFF; + + if (n > n0) return FALSE; + n += w; + switch (t) + { + case EOI : return FALSE; + case SKP : w = 0; break; + case REP : + case CPY : if (n-w <= n0 && n > n0) return TRUE; break; + } + m += (t == REP) ? 1 : w; + } +} + + + + + + +Boolean BITMAP::VBMSave (XFILE * f) +{ + word p = (Pal != NULL), + n = ((word) (((byte far *)B) - V)) + H * sizeof(HideDesc); + if (f->Error == 0) f->Write((byte far *)&p, sizeof(p)); + if (f->Error == 0) f->Write((byte far *)&n, sizeof(n)); + if (f->Error == 0) f->Write((byte far *)&W, sizeof(W)); + if (f->Error == 0) f->Write((byte far *)&H, sizeof(H)); + if (f->Error == 0) if (p) f->Write((byte far *)Pal, 256 * sizeof(DAC)); + if (f->Error == 0) f->Write(V, n); + return (f->Error == 0); +} + + + + + +Boolean BITMAP::VBMLoad (XFILE * f) +{ + word p, n; + if (f->Error == 0) f->Read((byte far *)&p, sizeof(p)); + if (f->Error == 0) f->Read((byte far *)&n, sizeof(n)); + if (f->Error == 0) f->Read((byte far *)&W, sizeof(W)); + if (f->Error == 0) f->Read((byte far *)&H, sizeof(H)); + if (f->Error == 0) + { + if (p) + { + if (Pal) f->Read((byte far *)Pal, 256 * sizeof(DAC)); + else f->Seek(f->Mark() + 256 * sizeof(DAC)); + } + } + if ((V = farnew(byte, n)) == NULL) return FALSE; + if (f->Error == 0) f->Read(V, n); + B = (HideDesc far *) (V + n - H * sizeof(HideDesc)); + return (f->Error == 0); +} + + + + + diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h new file mode 100644 index 00000000000..10d85430dc8 --- /dev/null +++ b/engines/cge/bitmap.h @@ -0,0 +1,60 @@ +#ifndef __BITMAP__ +#define __BITMAP__ + +#include + +#define EOI 0x0000 +#define SKP 0x4000 +#define REP 0x8000 +#define CPY 0xC000 + +#define TRANS 0xFE + + +typedef struct { word b : 2; + word B : 6; + word g : 2; + word G : 6; + word r : 2; + word R : 6; + word Z : 8; + } BGR4; + + +typedef struct { word skip; word hide; } HideDesc; + + + + +class BITMAP +{ + Boolean BMPLoad (XFILE * f); + Boolean VBMLoad (XFILE * f); +public: + static DAC far * Pal; + word W, H; + byte far * M, far * V; HideDesc far * B; + BITMAP (const char * fname, Boolean rem = TRUE); + BITMAP (word w, word h, byte far * map); + BITMAP (word w, word h, byte fill); + BITMAP (const BITMAP& bmp); + ~BITMAP (void); + BITMAP * FlipH (void); + BITMAP * Code (); + BITMAP& operator = (const BITMAP& bmp); + void Hide (int x, int y); + void Show (int x, int y); + void XShow (int x, int y); + Boolean SolidAt (int x, int y); + Boolean VBMSave (XFILE * f); + word MoveVmap (byte far * buf); +}; + + + +typedef BITMAP * BMP_PTR; + + + + +#endif \ No newline at end of file diff --git a/engines/cge/bitmaps.cpp b/engines/cge/bitmaps.cpp new file mode 100644 index 00000000000..2f79599c877 --- /dev/null +++ b/engines/cge/bitmaps.cpp @@ -0,0 +1,214 @@ +#include "bitmaps.h" +/* + +#define W 255, +#define x 252, +#define _ TRANS, +#define o 0, +#define L LGRAY, +#define G GRAY, +#define D DGRAY, + +static byte MCDesign0[]= { W W W W W W _ + W W W W W o _ + W W W W o _ _ + W W W W W _ _ + W W o W W W _ + W o _ o W W W + o _ _ _ o W W + _ _ _ _ _ o o }; + + +static byte MCDesign1[]= { _ }; + + + +static byte SLDesign[] = { G G G G G G G G G _ _ _ _ _ _ + L G G G G G G G G D _ _ _ _ _ + _ L G G G G G G G D _ _ _ _ _ + _ _ L G G G G G G G D _ _ _ _ + _ _ _ L G G G G G G D _ _ _ _ + _ _ _ _ L G G G G G D _ _ _ _ + _ _ _ _ _ L G G G G G D _ _ _ + _ _ _ _ _ _ L G G G G D _ _ _ + _ _ _ _ _ _ _ L G G G D _ _ _ + _ _ _ _ _ _ _ _ L G G G D _ _ + _ _ _ _ _ _ _ _ _ L G G D _ _ + _ _ _ _ _ _ _ _ _ _ L G D _ _ + _ _ _ _ _ _ _ _ _ _ _ L G D _ + _ _ _ _ _ _ _ _ _ _ _ _ L D _ + _ _ _ _ _ _ _ _ _ _ _ _ _ L D + _ _ _ _ _ _ _ _ _ _ _ _ _ _ D + }; + +static byte SRDesign[] = { _ _ _ _ _ _ G G G G G G G G G + _ _ _ _ _ L G G G G G G G G D + _ _ _ _ _ L G G G G G G G D _ + _ _ _ _ L G G G G G G G D _ _ + _ _ _ _ L G G G G G G D _ _ _ + _ _ _ _ L G G G G G D _ _ _ _ + _ _ _ L G G G G G D _ _ _ _ _ + _ _ _ L G G G G D _ _ _ _ _ _ + _ _ _ L G G G D _ _ _ _ _ _ _ + _ _ L G G G D _ _ _ _ _ _ _ _ + _ _ L G G D _ _ _ _ _ _ _ _ _ + _ _ L G D _ _ _ _ _ _ _ _ _ _ + _ L G D _ _ _ _ _ _ _ _ _ _ _ + _ L D _ _ _ _ _ _ _ _ _ _ _ _ + L D _ _ _ _ _ _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ _ _ _ _ _ _ _ _ + }; + +static byte MapBrick[] = { L L L L L L L G + L G G G G G G D + L G G G G G G D + G D D D D D D D + }; + +#undef W +#undef _ +#undef x +#undef o +#undef L +#undef G +#undef D + + +#if 0 + +#define _ TRANS, +#define A 213, +#define B 207, +#define C 225, +#define D 219, +#define E 231, + +static byte PRDesign[] = { A E E E C C D A B + C _ _ _ _ _ _ D A + C _ _ _ _ _ _ D A + C _ _ _ _ _ _ D A + C _ _ _ _ _ _ D A + C _ _ _ _ _ _ D A + C _ _ _ _ _ _ D A + B A A A A A A A B + B B B B B B B B B + }; + +#else + +#define _ TRANS, +#define A 213, +#define B 207, +#define C 225, // DGRAY +#define D 219, +#define E 231, +#define F 237, + +static byte PRDesign[] = { D D D D D D D D _ + D D D D D D D D _ + D _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ C _ + D C C C C C C C _ + _ _ _ _ _ _ _ _ _ + }; +#endif + + +#undef _ +#undef A +#undef B +#undef C +#undef D +#undef E + + + +#define _ 0x00, +#define x 0xFF, +#define A _ x _ x _ x _ x +#define B A A A A A A A A + +static byte HLDesign[] = { B B B B B }; + +#undef _ +#undef x +#undef A +#undef B + + +// 228 yellow +// 211 red +// 226 light green +// 221 blue + +#define A 208, +#define B 214, +#define C 220, +#define D 226, +#define E 255, + +static byte LIDesign[][9] = { { A A A + A B A + A A A }, + + { A B A + B C B + A B A }, + + { B C B + C D C + B C B }, + + { C D C + D E D + C D C }, + }; + +#undef A +#undef B +#undef C +#undef D +#undef E + + +#define R 211, +#define G 0, +//226, + +static byte MEDesign[][9] = { { R R R R R R R R R }, // 0 + { R R R R R R R R G }, // 1 + { R R R R R R R G G }, // 2 + { R R R R R R G G G }, // 3 + { R R R R R G G G G }, // 4 + { R R R R G G G G G }, // 5 + { R R R G G G G G G }, // 6 + { R R G G G G G G G }, // 7 + { R G G G G G G G G }, // 8 + { G G G G G G G G G }, // 9 + }; + +#undef R +#undef G +*/ + +#ifdef DEBUG + BMP_PTR MB[] = { new BITMAP("BRICK"), NULL }; + BMP_PTR HL[] = { new BITMAP("HLINE"), NULL }; +#endif + + BMP_PTR MC[] = { new BITMAP("MOUSE"), + new BITMAP("DUMMY"), + NULL }; + BMP_PTR PR[] = { new BITMAP("PRESS"), NULL }; + BMP_PTR SP[] = { new BITMAP("SPK_L"), + new BITMAP("SPK_R"), + NULL }; + BMP_PTR LI[] = { new BITMAP("LITE0"), + new BITMAP("LITE1"), + new BITMAP("LITE2"), + new BITMAP("LITE3"), + NULL }; diff --git a/engines/cge/bitmaps.h b/engines/cge/bitmaps.h new file mode 100644 index 00000000000..ef02c034e13 --- /dev/null +++ b/engines/cge/bitmaps.h @@ -0,0 +1,18 @@ +#ifndef __BITMAPS__ +#define __BITMAPS__ + +#include "vga13h.h" + +#ifdef DEBUG + extern BITMAP * MB[]; + extern BITMAP * HL[]; +#endif + +extern BITMAP * MC[]; +extern BITMAP * PR[]; +extern BITMAP * SP[]; +extern BITMAP * LI[]; + + +#endif + \ No newline at end of file diff --git a/engines/cge/boot.h b/engines/cge/boot.h new file mode 100644 index 00000000000..18c7cd2499b --- /dev/null +++ b/engines/cge/boot.h @@ -0,0 +1,49 @@ +#ifndef __BOOT__ +#define __BOOT__ + +#include + +#define BOOTSECT_SIZ 512 +#define BOOTHEAD_SIZ 62 +#define BOOTCODE_SIZ BOOTSECT_SIZ-BOOTHEAD_SIZ +#define FreeBoot(b) free(b) + +#ifndef EC + #define EC +#endif + +typedef struct { + byte Jmp[3]; // NEAR jump machine code + char OEM_ID[8]; // OEM name and version + word SectSize; // bytes per sector + byte ClustSize; // sectors per cluster + word ResSecs; // sectors before 1st FAT + byte FatCnt; // number of FATs + word RootSize; // root directory entries + word TotSecs; // total sectors on disk + byte Media; // media descriptor byte + word FatSize; // sectors per FAT + word TrkSecs; // sectors per track + word HeadCnt; // number of sufraces + word HidnSecs; // special hidden sectors + word _; // (unknown: reserved?) + dword lTotSecs; // total number of sectors + word DriveNum; // physical drive number + byte XSign; // extended boot signature + dword Serial; // volume serial number + char Label[11]; // volume label + char FileSysID[8]; // file system ID + char Code[BOOTCODE_SIZ-8]; // 8 = length of following + dword Secret; // long secret number + byte BootCheck; // boot sector checksum + byte BootFlags; // secret flags + word BootSig; // boot signature 0xAA55 + } Boot; + + +EC Boot * ReadBoot (int drive); +EC byte CheckBoot (Boot * boot); +EC Boolean WriteBoot (int drive, Boot * boot); + + +#endif \ No newline at end of file diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp new file mode 100644 index 00000000000..53b845b89fb --- /dev/null +++ b/engines/cge/cfile.cpp @@ -0,0 +1,332 @@ +#include +#include +#include +#include +#include + +#ifdef DROP_H + #include "drop.h" +#else + #include + #include + #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } +#endif + + + + +IOBUF::IOBUF (IOMODE mode, CRYPT * crpt) +: IOHAND(mode, crpt), + BufMark(0), + Ptr(0), + Lim(0) +{ + Buff = farnew(byte, IOBUF_SIZE); + if (Buff == NULL) DROP("No core for I/O", NULL); +} + + + + + + + + + +IOBUF::IOBUF (const char * name, IOMODE mode, CRYPT * crpt) +: IOHAND(name, mode, crpt), + BufMark(0), + Ptr(0), + Lim(0) +{ + Buff = farnew(byte, IOBUF_SIZE); + if (Buff == NULL) DROP("No core for I/O", name); +} + + + + + + + + + +IOBUF::~IOBUF (void) +{ + if (Mode > REA) WriteBuff(); + if (Buff) farfree(Buff); +} + + + + + + +void IOBUF::ReadBuff (void) +{ + BufMark = IOHAND::Mark(); + Lim = IOHAND::Read(Buff, IOBUF_SIZE); + Ptr = 0; +} + + + + + +void IOBUF::WriteBuff (void) +{ + if (Lim) + { + IOHAND::Write(Buff, Lim); + BufMark = IOHAND::Mark(); + Lim = 0; + } +} + + + + + +word IOBUF::Read (void far * buf, word len) +{ + word total = 0; + while (len) + { + if (Ptr >= Lim) ReadBuff(); + word n = Lim - Ptr; + if (n) + { + if (len < n) n = len; + _fmemcpy(buf, Buff+Ptr, n); + (byte far *) buf += n; + len -= n; + total += n; + Ptr += n; + } + else break; + } + return total; +} + + + + + + +word IOBUF::Read (byte far * buf) +{ + word total = 0; + + while (total < LINE_MAX-2) + { + if (Ptr >= Lim) ReadBuff(); + byte far * p = Buff + Ptr; + word n = Lim - Ptr; + if (n) + { + if (total + n >= LINE_MAX-2) n = LINE_MAX-2 - total; + byte far * eol = (byte far *) _fmemchr(p, '\r', n); + if (eol) n = (word) (eol - p); + byte far * eof = (byte far *) _fmemchr(p, '\32', n); + if (eof) // end-of-file + { + n = (word) (eof - p); + Ptr = (word) (eof - Buff); + } + if (n) _fmemcpy(buf, p, n); + buf += n; + total += n; + if (eof) break; + Ptr += n; + if (eol) + { + ++ Ptr; + * (buf ++) = '\n'; + ++ total; + if (Ptr >= Lim) ReadBuff(); + if (Ptr < Lim) if (Buff[Ptr] == '\n') ++ Ptr; + break; + } + } + else break; + } + *buf = '\0'; + return total; +} + + + + + + + +word IOBUF::Write (void far * buf, word len) +{ + word tot = 0; + while (len) + { + word n = IOBUF_SIZE - Lim; + if (n > len) n = len; + if (n) + { + _fmemcpy(Buff+Lim, buf, n); + Lim += n; + len -= n; + (byte far *) buf += n; + tot += n; + } + else WriteBuff(); + } + return tot; +} + + + + + + +word IOBUF::Write (byte far * buf) +{ + word len = 0; + if (buf) + { + len = _fstrlen((const char far *) buf); + if (len) if (buf[len-1] == '\n') -- len; + len = Write(buf, len); + if (len) + { + static char EOL[] = "\r\n"; + word n = Write(EOL, sizeof(EOL)-1); + len += n; + } + } + return len; +} + + + + + + +int IOBUF::Read (void) +{ + if (Ptr >= Lim) + { + ReadBuff(); + if (Lim == 0) return -1; + } + return Buff[Ptr ++]; +} + + + + + + +void IOBUF::Write (byte b) +{ + if (Lim >= IOBUF_SIZE) + { + WriteBuff(); + } + Buff[Lim ++] = b; +} + + + + + + + word CFILE::MaxLineLen = LINE_MAX; + + + + + + + + +CFILE::CFILE (const char near * name, IOMODE mode, CRYPT * crpt) +: IOBUF(name, mode, crpt) +{ +} + + + + + + + + + +CFILE::~CFILE (void) +{ +} + + + + + + +void CFILE::Flush (void) +{ + if (Mode > REA) WriteBuff(); + else Lim = 0; + _BX = Handle; + _AH = 0x68; // Flush buffer + asm int 0x21 +} + + + + + +long CFILE::Mark (void) +{ + return BufMark + ((Mode > REA) ? Lim : Ptr); +} + + + + + +long CFILE::Seek (long pos) +{ + if (pos >= BufMark && pos < BufMark + Lim) + { + ((Mode == REA) ? Ptr : Lim) = (word) (pos - BufMark); + return pos; + } + else + { + if (Mode > REA) + { + WriteBuff(); + } + else + { + Lim = 0; + } + Ptr = 0; + return BufMark = IOHAND::Seek(pos); + } +} + + + + + + +void CFILE::Append (CFILE& f) +{ + Seek(Size()); + if (f.Error == 0) + { + while (TRUE) + { + if ((Lim = f.IOHAND::Read(Buff, IOBUF_SIZE)) == IOBUF_SIZE) WriteBuff(); + else break; + if ((Error = f.Error) != 0) break; + } + } +} diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h new file mode 100644 index 00000000000..57ff38831cd --- /dev/null +++ b/engines/cge/cfile.h @@ -0,0 +1,56 @@ +#ifndef __CFILE__ +#define __CFILE__ + +#include +#include + + +#define LINE_MAX 512 + +#ifndef IOBUF_SIZE + #define IOBUF_SIZE K(2) +#endif + +#define CFREAD(x) Read((byte far *)(x),sizeof(*(x))) + + + + +class IOBUF : public IOHAND +{ +protected: + byte far * Buff; + word Ptr, Lim; + long BufMark; + word Seed; + CRYPT * Crypt; + virtual void ReadBuff (void); + virtual void WriteBuff (void); +public: + IOBUF (IOMODE mode, CRYPT * crpt = NULL); + IOBUF (const char * name, IOMODE mode, CRYPT * crpt = NULL); + virtual ~IOBUF (void); + word Read (void far * buf, word len); + word Read (char far * buf); + int Read (void); + word Write (void far * buf, word len); + word Write (byte far * buf); + void Write (byte b); +}; + + + +class CFILE : public IOBUF +{ +public: + static word MaxLineLen; + CFILE (const char near * name, IOMODE mode = REA, CRYPT * crpt = NULL); + virtual ~CFILE (void); + void Flush (void); + long Mark (void); + long Seek (long pos); + void Append (CFILE& f); +}; + + +#endif diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index e7c462e7726..5613c3bb686 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -33,6 +33,7 @@ #include "engines/util.h" #include "cge/cge.h" +#include "cge/cge_main.h" namespace CGE { @@ -61,7 +62,9 @@ Common::Error CGEEngine::run() { // Additional setup. debug("CGEEngine::init"); - + + cge_main(); + return Common::kNoError; } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index fac4f2c6cc4..cb2c507ffae 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -40,7 +40,7 @@ class Console; enum { kCGEDebug = 1 << 0 }; - + class CGEEngine : public Engine { public: CGEEngine(OSystem *syst, const ADGameDescription *gameDescription); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp new file mode 100644 index 00000000000..23865ec3868 --- /dev/null +++ b/engines/cge/cge_main.cpp @@ -0,0 +1,2232 @@ +#include "cge\general.h" +#include "cge\boot.h" +#include "cge\ident.h" +#include "cge\sound.h" +#include "cge\startup.h" +#include "cge\config.h" +#include "cge\vga13h.h" +#include "cge\snail.h" +#include "cge\text.h" +#include "cge\game.h" +#include "cge\mouse.h" +#include "cge\keybd.h" +#include "cge\cfile.h" +#include "cge\vol.h" +#include "cge\talk.h" +#include "cge\vmenu.h" +#include "cge\gettext.h" +#include "cge\mixer.h" +#include "cge\cge_main.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define STACK_SIZ (K(2)) +#define SVGCHKSUM (1956+Now+OldLev+Game+Music+DemoText) + +#ifdef DEMO + #ifdef DEBUG + #define SVG0NAME ("{{INIT}}" SVG_EXT) + #else + #define SVG0NAME (ProgName(SVG_EXT)) + #endif +#else + #define SVG0NAME ("{{INIT}}" SVG_EXT) +#endif + +#ifdef DEBUG + #define SVG0FILE CFILE +#else + #define SVG0FILE INI_FILE +#endif + +extern word _stklen = (STACK_SIZ * 2); + +// 0.75 - 17II95 - full sound support +// 0.76 - 18II95 - small MiniEMS in DEMO, +// unhide CavLight in SNLEVEL +// keyclick suppress in startup +// keyclick on key service in: SYSTEM, GET_TEXT +// 1.01 - 17VII95 - default savegame with sound ON +// coditionals EVA for 2-month evaluation version + +/* + char Copr[] = "Common Game Engine " + #ifdef EVA + "ú" + #else + #ifdef CD + "ù" + #else + " " + #endif + #endif + " version 1.05 [" + #if sizeof(INI_FILE) == sizeof(VFILE) + "I" + #else + "i" + #endif + #if sizeof(PIC_FILE) == sizeof(VFILE) + "B" + #else + "b" + #endif + "]\n" + "Copyright (c) 1994 by Janusz B. Wi$niewski"; +*/ + char Copr[] = "To be fixed - Copr[]"; + +static char UsrFnam[15] = "\0ɱ%^þúȼ´ ÇÉ"; +static int OldLev = 0; +static int DemoText = DEMO_TEXT; + +//-------------------------------------------------------------------------- + + Boolean JBW = FALSE; + DAC *SysPal = farnew(DAC, PAL_CNT); + +//------------------------------------------------------------------------- + SPRITE PocLight = LI; + SPRITE * Pocket[POCKET_NX]={ NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, }; + int PocPtr = 0; +//------------------------------------------------------------------------- +//extern SPRITE * PocLight; +//extern SPRITE * Pocket[]; +//extern int PocPtr; +//------------------------------------------------------------------------- + + MOUSE Mouse; +static SPRITE * Sprite = NULL; +static SPRITE * MiniCave = NULL; +static SPRITE * Shadow = NULL; + +static VGA Vga = M13H; +static EMS * Mini = MiniEmm.Alloc((word)MINI_EMM_SIZE); +static BMP_PTR * MiniShpList = NULL; +static BMP_PTR MiniShp[] = { NULL, NULL }; +static KEYBOARD Keyboard; +static Boolean Finis = FALSE; +static int Startup = 1; +static int OffUseCount = atoi(Text[OFF_USE_COUNT]); + word * intStackPtr = FALSE; + + + HXY HeroXY[CAVE_MAX] = {{0,0}}; + BAR Barriers[1+CAVE_MAX] = { { 0xFF, 0xFF } }; + + +extern int FindPocket (SPRITE *); + +extern DAC StdPal[58]; + +#ifdef DEBUG +static SPRITE HorzLine = HL; +#endif + + + +void FeedSnail (SPRITE * spr, SNLIST snq); // defined in SNAIL + +//-------------------------------------------------------------------------- + + + + +byte CLUSTER::Map[MAP_ZCNT][MAP_XCNT]; + + + +byte & CLUSTER::Cell (void) +{ + return Map[B][A]; +} + + + + + + + + +Boolean CLUSTER::Protected (void) +{ + if (A == Barriers[Now].Vert || B == Barriers[Now].Horz) return TRUE; + + _DX = (MAP_ZCNT << 8) + MAP_XCNT; + _BX = (word) this; + + asm mov ax,1 + asm mov cl,[bx].(COUPLE)A + asm mov ch,[bx].(COUPLE)B + asm test cx,0x8080 // (A < 0) || (B < 0) + asm jnz xit + + asm cmp cl,dl + asm jge xit + asm cmp ch,dh + asm jge xit + +// if (A < 0 || A >= MAP_XCNT || B < 0 || B >= MAP_ZCNT) return TRUE; + + asm mov al,dl + asm mul ch + asm xor ch,ch + asm add ax,cx + asm mov bx,ax + _BX += (word) Map; + //asm add bx,offset CLUSTER::Map + asm mov al,[bx] + asm and ax,0xFF + asm jz xit + asm mov ax,1 + +// return Map[B][A] != 0; + + xit: return _AX; +} + + + + + +CLUSTER XZ (int x, int y) +{ + if (y < MAP_TOP) y = MAP_TOP; + if (y > MAP_TOP + MAP_HIG - MAP_ZGRID) y = MAP_TOP + MAP_HIG - MAP_ZGRID; + return CLUSTER(x / MAP_XGRID, (y-MAP_TOP) / MAP_ZGRID); +} + + + + +CLUSTER XZ (COUPLE xy) +{ + signed char x, y; + xy.Split(x, y); + return XZ(x, y); +} + + + + + + + +//-------------------------------------------------------------------------- + + + int pocref[POCKET_NX]; + byte volume[2]; + struct SAVTAB { void * Ptr; int Len; byte Flg; } SavTab[] = + {{ &Now, sizeof(Now), 1 }, + { &OldLev, sizeof(OldLev), 1 }, + { &DemoText, sizeof(DemoText), 1 }, + { &Game, sizeof(Game), 1 }, + { &Game, sizeof(Game), 1 }, // spare 1 + { &Game, sizeof(Game), 1 }, // spare 2 + { &Game, sizeof(Game), 1 }, // spare 3 + { &Game, sizeof(Game), 1 }, // spare 4 + { &VGA::Mono, sizeof(VGA::Mono), 0 }, + { &Music, sizeof(Music), 1 }, + { volume, sizeof(volume), 1 }, + + { Flag, sizeof(Flag), 1 }, + { HeroXY, sizeof(HeroXY), 1 }, + { Barriers, sizeof(Barriers), 1 }, + { pocref, sizeof(pocref), 1 }, + { NULL, 0, 0 } }; + + + + + +static void LoadGame (XFILE& file, Boolean tiny = FALSE) +{ + SAVTAB * st; + SPRITE * spr; + int i; + + for (st = SavTab; st->Ptr; st ++) + { + if (file.Error) VGA::Exit("Bad SVG"); + file.Read((byte far *) ((tiny || st->Flg) ? st->Ptr : &i), st->Len); + } + + file.Read((byte far *) &i, sizeof(i)); + if (i != SVGCHKSUM) VGA::Exit(BADSVG_TEXT); + if (STARTUP::Core < CORE_HIG) Music = FALSE; + if (STARTUP::SoundOk == 1 && STARTUP::Mode == 0) + { + SNDDrvInfo.VOL2.D = volume[0]; + SNDDrvInfo.VOL2.M = volume[1]; + SNDSetVolume(); + } + + if (! tiny) // load sprites & pocket + { + while (! file.Error) + { + SPRITE S(NULL); + word n = file.Read((byte far *) &S, sizeof(S)); + + if (n != sizeof(S)) break; + S.Prev = S.Next = NULL; + spr = (stricmp(S.File+2, "MUCHA") == 0) ? new FLY(NULL) + : new SPRITE(NULL); + if (spr == NULL) VGA::Exit("No core"); + *spr = S; + VGA::SpareQ.Append(spr); + } + + for (i = 0; i < POCKET_NX; i ++) + { + register int r = pocref[i]; + Pocket[i] = (r < 0) ? NULL : VGA::SpareQ.Locate(r); + } + } +} + + + + +static void SaveSound (void) +{ + CFILE cfg(UsrPath(ProgName(CFG_EXT)), WRI); + if (! cfg.Error) cfg.Write(&SNDDrvInfo,sizeof(SNDDrvInfo)-sizeof(SNDDrvInfo.VOL2)); +} + + + + + + +static void SaveGame (XFILE& file) +{ + SAVTAB * st; + SPRITE * spr; + int i; + + for (i = 0; i < POCKET_NX; i ++) + { + register SPRITE * s = Pocket[i]; + pocref[i] = (s) ? s->Ref : -1; + } + + volume[0] = SNDDrvInfo.VOL2.D; + volume[1] = SNDDrvInfo.VOL2.M; + + for (st = SavTab; st->Ptr; st ++) + { + if (file.Error) VGA::Exit("Bad SVG"); + file.Write((byte far *) st->Ptr, st->Len); + } + + file.Write((byte far *) &(i = SVGCHKSUM), sizeof(i)); + + for (spr = VGA::SpareQ.First(); spr; spr = spr->Next) + if (spr->Ref >= 1000) + if (!file.Error) file.Write((byte far *)spr, sizeof(*spr)); +} + + + + + + + +static void HeroCover (int cvr) +{ + SNPOST(SNCOVER, 1, cvr, NULL); +} + + + + +static void Trouble (int seq, int txt) +{ + Hero->Park(); + SNPOST(SNWAIT, -1, -1, Hero); + SNPOST(SNSEQ, -1, seq, Hero); + SNPOST(SNSOUND, -1, 2, Hero); + SNPOST(SNWAIT, -1, -1, Hero); + SNPOST(SNSAY, 1, txt, Hero); +} + + + +static void OffUse (void) +{ + Trouble(OFF_USE, OFF_USE_TEXT+random(OffUseCount)); +} + + + + +static void TooFar (void) +{ + Trouble(TOO_FAR, TOO_FAR_TEXT); +} + + + + +static void NoWay (void) +{ + Trouble(NO_WAY, NO_WAY_TEXT); +} + + + + + +static void LoadHeroXY (void) +{ + INI_FILE cf(ProgName(".HXY")); + memset(HeroXY, 0, sizeof(HeroXY)); + if (! cf.Error) cf.CFREAD(&HeroXY); +} + + + + + +static void LoadMapping (void) +{ + if (Now <= CAVE_MAX) + { + INI_FILE cf(ProgName(".TAB")); + if (! cf.Error) + { + memset(CLUSTER::Map, 0, sizeof(CLUSTER::Map)); + cf.Seek((Now - 1) * sizeof(CLUSTER::Map)); + cf.Read((byte far *) CLUSTER::Map, sizeof(CLUSTER::Map)); + } + } +} + + + + + + +//-------------------------------------------------------------------------- + +CLUSTER Trace[MAX_FIND_LEVEL]; +int FindLevel; + + + + + + + + +WALK::WALK (BMP_PTR * shpl) +: SPRITE(shpl), Dir(NO_DIR), TracePtr(-1) +{ +} + + + + + +void WALK::Tick (void) +{ + if (Flags.Hide) return; + + Here = XZ(X+W/2, Y+H); + + if (Dir != NO_DIR) + { + SPRITE * spr; + SYSTEM::FunTouch(); + for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) + { + if (Distance(spr) < 2) + { + if (! spr->Flags.Near) + { + FeedSnail(spr, NEAR); + spr->Flags.Near = TRUE; + } + } + else spr->Flags.Near = FALSE; + } + } + + if (Flags.Hold || TracePtr < 0) Park(); + else + { + if (Here == Trace[TracePtr]) + { + if (-- TracePtr < 0) Park(); + } + else + { + signed char dx, dz; + (Trace[TracePtr] - Here).Split(dx, dz); + DIR d = (dx) ? ((dx > 0) ? EE : WW) : ((dz > 0) ? SS : NN); + Turn(d); + } + } + Step(); + if ((Dir == WW && X <= 0) || + (Dir == EE && X + W >= SCR_WID) || + (Dir == SS && Y + W >= WORLD_HIG-2)) Park(); + else + { + signed char x; // dummy var + Here.Split(x, Z); // take current Z position + SNPOST_(SNZTRIM, -1, 0, this); // update Hero's pos in show queue + } +} + + + + + + +int WALK::Distance (SPRITE * spr) +{ + int dx, dz; + dx = spr->X - (X+W-WALKSIDE); + if (dx < 0) dx = (X+WALKSIDE) - (spr->X+spr->W); + if (dx < 0) dx = 0; + dx /= MAP_XGRID; + dz = spr->Z - Z; + if (dz < 0) dz = - dz; + dx = dx * dx + dz * dz; + for (dz = 1; dz * dz < dx; dz ++) ; + return dz-1; +} + + + + + + + + + + +void WALK::Turn (DIR d) +{ + DIR dir = (Dir == NO_DIR) ? SS : Dir; + if (d != Dir) + { + Step((d == dir) ? (1 + dir + dir) : (9 + 4 * dir + d)); + Dir = d; + } +} + + + + + +void WALK::Park (void) +{ + if (Time == 0) ++ Time; + if (Dir != NO_DIR) + { + Step(9 + 4 * Dir + Dir); + Dir = NO_DIR; + TracePtr = -1; + } +} + + + + + + + +void WALK::FindWay (CLUSTER c) +{ + Boolean Find1Way(void); + extern word Target; + + if (c != Here) + { + for (FindLevel = 1; FindLevel <= MAX_FIND_LEVEL; FindLevel ++) + { + signed char x, z; + Here.Split(x, z); + Target = (z << 8) | x; + c.Split(x, z); + _CX = (z << 8) | x; + if (Find1Way()) break; + } + TracePtr = (FindLevel > MAX_FIND_LEVEL) ? -1 : (FindLevel - 1); + if (TracePtr < 0) NoWay(); + Time = 1; + } +} + + + + + + +void WALK::FindWay (SPRITE * spr) +{ + if (spr && spr != this) + { + int x = spr->X, z = spr->Z; + if (spr->Flags.East) x += spr->W + W/2 - WALKSIDE; + else x -= W/2 - WALKSIDE; + FindWay(CLUSTER((x/MAP_XGRID), + ((z < MAP_ZCNT-MAX_DISTANCE) ? (z+1) + : (z-1)))); + } +} + + + + + + +Boolean WALK::Lower (SPRITE * spr) +{ + return (spr->Y > Y + (H * 3) / 5); +} + + + + + + +void WALK::Reach (SPRITE * spr, int mode) +{ + if (spr) + { + Hero->FindWay(spr); + if (mode < 0) + { + mode = spr->Flags.East; + if (Lower(spr)) mode += 2; + } + } + // note: insert SNAIL commands in reverse order + SNINSERT(SNPAUSE, -1, 64, NULL); + SNINSERT(SNSEQ, -1, TSEQ + mode, this); + if (spr) + { + SNINSERT(SNWAIT, -1, -1, Hero); /////--------$$$$$$$ + //SNINSERT(SNWALK, -1, -1, spr); + } + // sequence is not finished, + // now it is just at sprite appear (disappear) point +} + + + + + + +//-------------------------------------------------------------------------- + + + +#ifdef DEBUG + + +class SQUARE : public SPRITE +{ +public: + SQUARE (void); + void Touch (word mask, int x, int y); +}; + + + + + + +SQUARE::SQUARE (void) +: SPRITE(MB) +{ + Flags.Kill = TRUE; + Flags.BDel = FALSE; +} + + + + + + + + +void SQUARE::Touch (word mask, int x, int y) +{ + SPRITE::Touch(mask, x, y); + if (mask & L_UP) + { + XZ(X+x, Y+y).Cell() = 0; + SNPOST_(SNKILL, -1, 0, this); + } +} + + + + + + +static void SetMapBrick (int x, int z) +{ + SQUARE * s = new SQUARE; + if (s) + { + static char n[] = "00:00"; + s->Goto(x * MAP_XGRID, MAP_TOP + z * MAP_ZGRID); + wtom(x, n+0, 10, 2); + wtom(z, n+3, 10, 2); + CLUSTER::Map[z][x] = 1; + s->SetName(n); + VGA::ShowQ.Insert(s, VGA::ShowQ.First()); + } +} + + +#endif + + + +//-------------------------------------------------------------------------- + +void dummy (void) { } +void SwitchMapping (void); +void SwitchColorMode (void); +void StartCountDown (void); +Debug( void SwitchDebug (void); ) +void SwitchMusic (void); +void KillSprite (void); +void PushSprite (void); +void PullSprite (void); +void BackPaint (void); +void NextStep (void); +void SaveMapping (void); + + + WALK * Hero = NULL; +static INFO_LINE InfoLine = INFO_W; + +static HEART Heart; + +static SPRITE CavLight = PR; + + + + + +static void KeyClick (void) +{ + SNPOST_(SNSOUND, -1, 5, NULL); +} + + + +static void ResetQSwitch (void) +{ + SNPOST_(SNSEQ, 123, 0, NULL); + KeyClick(); +} + + + + +static void Quit (void) +{ + static CHOICE QuitMenu[]={ { NULL, StartCountDown }, + { NULL, ResetQSwitch }, + { NULL, dummy } }; + + if (Snail.Idle() && ! Hero->Flags.Hide) + { + if (VMENU::Addr) + { + SNPOST_(SNKILL, -1, 0, VMENU::Addr); + ResetQSwitch(); + } + else + { + QuitMenu[0].Text = Text[QUIT_TEXT]; + QuitMenu[1].Text = Text[NOQUIT_TEXT]; + (new VMENU(QuitMenu, -1, -1))->SetName(Text[QUIT_TITLE]); + SNPOST_(SNSEQ, 123, 1, NULL); + KeyClick(); + } + } +} + + + + +static void AltCtrlDel (void) +{ + #if 0 + //def DEBUG + if (KEYBOARD::Key[LSHIFT] || KEYBOARD::Key[RSHIFT]) + { + PostFlag = 0x1234; + POST(); + } + else + #endif + SNPOST_(SNSAY, -1, A_C_D_TEXT, Hero); +} + + + + +static void MiniStep (int stp) +{ + if (stp < 0) MiniCave->Flags.Hide = TRUE; + else + { + &*Mini; + *MiniShp[0] = *MiniShpList[stp]; + if (Fx.Current) &*(Fx.Current->EAddr()); + MiniCave->Flags.Hide = FALSE; + } +} + + + + + +static void PostMiniStep (int stp) +{ + static int recent = -2; + if (MiniCave && stp != recent) SNPOST_(SNEXEC, -1, recent = stp, (void *) MiniStep); +} + + + +//-------------------------------------------------------------------------- + + + +int SYSTEM::FunDel = HEROFUN0; + + + + +void SYSTEM::SetPal (void) +{ + int i; + DAC far * p = SysPal + 256-ArrayCount(StdPal); + for (i = 0; i < ArrayCount(StdPal); i ++) + { + p[i].R = StdPal[i].R >> 2; + p[i].G = StdPal[i].G >> 2; + p[i].B = StdPal[i].B >> 2; + } +} + + + + + +void SYSTEM::FunTouch (void) +{ + word n = (PAIN) ? HEROFUN1 : HEROFUN0; + if (Talk == NULL || n > FunDel) FunDel = n; +} + + + + + + +static void ShowBak (int ref) +{ + SPRITE * spr = VGA::SpareQ.Locate(ref); + if (spr) + { + BITMAP::Pal = SysPal; + spr->Expand(); + BITMAP::Pal = NULL; + spr->Show(2); + VGA::CopyPage(1, 2); + SYSTEM::SetPal(); + spr->Contract(); + } +} + + + + + + +static void CaveUp (void) +{ + int BakRef = 1000 * Now; + if (Music) LoadMIDI(Now); + ShowBak(BakRef); + LoadMapping(); + Text.Preload(BakRef, BakRef+1000); + SPRITE * spr = VGA::SpareQ.First(); + while (spr) + { + SPRITE * n = spr->Next; + if (spr->Cave == Now || spr->Cave == 0) + if (spr->Ref != BakRef) + { + if (spr->Flags.Back) spr->BackShow(); + else ExpandSprite(spr); + } + spr = n; + } + if (SNDDrvInfo.DDEV) + { + Sound.Stop(); + Fx.Clear(); + Fx.Preload(0); + Fx.Preload(BakRef); + } + + if (Hero) + { + Hero->Goto(HeroXY[Now-1].X, HeroXY[Now-1].Y); + // following 2 lines trims Hero's Z position! + Hero->Tick(); + Hero->Time = 1; + Hero->Flags.Hide = FALSE; + } + + if (! Dark) Vga.Sunset(); + VGA::CopyPage(0, 1); + SelectPocket(-1); + if (Hero) VGA::ShowQ.Insert(VGA::ShowQ.Remove(Hero)); + if (Shadow) + { + VGA::ShowQ.Remove(Shadow); + Shadow->MakeXlat(Glass(SysPal, 204, 204, 204)); + VGA::ShowQ.Insert(Shadow, Hero); + Shadow->Z = Hero->Z; + } + FeedSnail(VGA::ShowQ.Locate(BakRef+999), TAKE); + Vga.Show(); + Vga.CopyPage(1, 0); + Vga.Show(); + Vga.Sunrise(SysPal); + Dark = FALSE; + if (! Startup) Mouse.On(); + HEART::Enable = TRUE; +} + + + + + +static void CaveDown (void) +{ + SPRITE * spr; + Debug( if (! HorzLine.Flags.Hide) SwitchMapping(); ) + + for (spr = VGA::ShowQ.First(); spr; ) + { + SPRITE * n = spr->Next; + if (spr->Ref >= 1000 /*&& spr->Cave*/) + { + if (spr->Ref % 1000 == 999) FeedSnail(spr, TAKE); + VGA::SpareQ.Append(VGA::ShowQ.Remove(spr)); + } + spr = n; + } + Text.Clear(1000); +} + + + + + +static void XCave (void) +{ + CaveDown(); + CaveUp(); +} + + + + +static void QGame (void) +{ + CaveDown(); + OldLev = Lev; + SaveSound(); + SaveGame(CFILE(UsrPath(UsrFnam), WRI, RCrypt)); + Vga.Sunset(); + Finis = TRUE; +} + + + + +void SwitchCave (int cav) +{ + if (cav != Now) + { + HEART::Enable = FALSE; + if (cav < 0) + { + SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint + SNPOST(SNEXEC, -1, 0, (void *) QGame); // switch cave + } + else + { + Now = cav; + Mouse.Off(); + if (Hero) + { + Hero->Park(); + Hero->Step(0); + #ifndef DEMO + ///// protection: auto-destruction on! ---------------------- + VGA::SpareQ.Show = STARTUP::Summa * (cav <= CAVE_MAX); + /////-------------------------------------------------------- + #endif + } + CavLight.Goto(CAVE_X + ((Now-1) % CAVE_NX) * CAVE_DX + CAVE_SX, + CAVE_Y + ((Now-1) / CAVE_NX) * CAVE_DY + CAVE_SY); + KillText(); + if (! Startup) KeyClick(); + SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint + SNPOST(SNEXEC, 0, 0, (void *) XCave); // switch cave + } + } +} + + + + + + +void SYSTEM::Touch (word mask, int x, int y) +{ + static int pp = 0; + void SwitchCave (int cav); + int cav = 0; + + FunTouch(); + + if (mask & KEYB) + { + int pp0; + KeyClick(); + KillText(); + if (Startup == 1) + { + SNPOST(SNCLEAR, -1, 0, NULL); + return; + } + pp0 = pp; + switch (x) + { + case Del : if (KEYBOARD::Key[ALT] && + KEYBOARD::Key[CTRL]) AltCtrlDel(); + Debug ( else KillSprite(); ) + break; + case 'F' : if (KEYBOARD::Key[ALT]) + { + SPRITE * m = VGA::ShowQ.Locate(17001); + if (m) + { + m->Step(1); + m->Time = 216; // 3s + } + } + break; + + #ifdef DEBUG + case PgUp : PushSprite(); break; + case PgDn : PullSprite(); break; + case '+' : NextStep(); break; + case '`' : if (KEYBOARD::Key[ALT]) SaveMapping(); else SwitchMapping(); break; + case F1 : SwitchDebug(); break; + case F3 : Hero->Step(TSEQ + 4); break; + case F4 : Hero->Step(TSEQ + 5); break; + case F5 : Hero->Step(TSEQ + 0); break; + case F6 : Hero->Step(TSEQ + 1); break; + case F7 : Hero->Step(TSEQ + 2); break; + case F8 : Hero->Step(TSEQ + 3); break; + case F9 : SYSTEM::FunDel = 1; break; + case 'X' : if (KEYBOARD::Key[ALT]) Finis = TRUE; break; + case '0' : + case '1' : + case '2' : + case '3' : + case '4' : if (KEYBOARD::Key[ALT]) { SNPOST(SNLEVEL, -1, x - '0', NULL); break; } + case '5' : + case '6' : + case '7' : + case '8' : + case '9' : if (Sprite) Sprite->Step(x - '0'); break; + #else + case '1' : + case '2' : + case '3' : + case '4' : + case '5' : + case '6' : + case '7' : + case '8' : SelectPocket(x - '1'); break; + #endif + + case F10 : if (Snail.Idle() && ! Hero->Flags.Hide) + StartCountDown(); + break; + case 'J' : if (pp == 0) ++ pp; break; + case 'B' : if (pp == 1) ++ pp; break; + case 'W' : if (pp == 2) JBW = !JBW; break; + } + if (pp == pp0) pp = 0; + } + else + { + if (Startup) return; + InfoLine.Update(NULL); + if (y >= WORLD_HIG) + { + if (x < BUTTON_X) // select cave? + { + if (y >= CAVE_Y && y < CAVE_Y + CAVE_NY * CAVE_DY && + x >= CAVE_X && x < CAVE_X + CAVE_NX * CAVE_DX && ! Game) + { + cav = ((y-CAVE_Y) / CAVE_DY) * CAVE_NX + (x-CAVE_X) / CAVE_DX + 1; + if (cav > MaxCave) cav = 0; + } + else + { + cav = 0; + } + } + else if (mask & L_UP) + { + if (y >= POCKET_Y && y < POCKET_Y + POCKET_NY * POCKET_DY && + x >= POCKET_X && x < POCKET_X + POCKET_NX * POCKET_DX) + { + int n = ((y-POCKET_Y) / POCKET_DY) * POCKET_NX + (x-POCKET_X) / POCKET_DX; + SelectPocket(n); + } + } + } + + PostMiniStep(cav-1); + + if (mask & L_UP) + { + if (cav && Snail.Idle() && Hero->TracePtr < 0) + { + SwitchCave(cav); + } + #ifdef DEBUG + if (! HorzLine.Flags.Hide) + { + if (y >= MAP_TOP && y < MAP_TOP+MAP_HIG) + { + signed char x1, z1; + XZ(x, y).Split(x1, z1); + CLUSTER::Map[z1][x1] = 1; + SetMapBrick(x1, z1); + } + } + else + #endif + { + if (! Talk && Snail.Idle() && Hero + && y >= MAP_TOP && y < MAP_TOP+MAP_HIG && ! Game) + { + Hero->FindWay(XZ(x, y)); + } + } + } + } +} + + + + + + + +void SYSTEM::Tick (void) +{ + if (! Startup) if (-- FunDel == 0) + { + KillText(); + if (Snail.Idle()) + { + if (PAIN) HeroCover(9); + else if (STARTUP::Core >= CORE_MID) + { + int n = random(100); + if (n > 96) HeroCover(6+(Hero->X+Hero->W/2 < SCR_WID/2)); + else + { + if (n > 90) HeroCover(5); + else + { + if (n > 60) HeroCover(4); + else HeroCover(3); + } + } + } + } + FunTouch(); + } + Time = SYSTIMERATE; +} + + + + + + + + + + +//-------------------------------------------------------------------------- + + + +/* +static void SpkOpen (void) +{ + asm in al,0x61 + asm or al,0x03 + asm out 0x61,al + asm mov al,0x90 + asm out 0x43,al +} + + + + + +static void SpkClose (void) +{ + asm in al,0x61 + asm and al,0xFC + asm out 0x61,al +} + +*/ + + + +static void SwitchColorMode (void) +{ + SNPOST_(SNSEQ, 121, VGA::Mono = ! VGA::Mono, NULL); + KeyClick(); + VGA::SetColors(SysPal, 64); +} + + + +static void SwitchMusic (void) +{ + if (KEYBOARD::Key[ALT]) + { + if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); + else + { + SNPOST_(SNSEQ, 122, (Music = FALSE), NULL); + SNPOST(SNEXEC, -1, 0, (void *) SelectSound); + } + } + else + { + if (STARTUP::Core < CORE_HIG) SNPOST(SNINF, -1, NOMUSIC_TEXT, NULL); + else + { + SNPOST_(SNSEQ, 122, (Music = ! Music), NULL); + KeyClick(); + } + } + if (Music) LoadMIDI(Now); + else KillMIDI(); +} + + + + + +static void StartCountDown (void) +{ + //SNPOST(SNSEQ, 123, 0, NULL); + SwitchCave(-1); +} + + + + +#ifndef DEMO +static void TakeName (void) +{ + if (GET_TEXT::Ptr) SNPOST_(SNKILL, -1, 0, GET_TEXT::Ptr); + else + { + GET_TEXT * tn = new GET_TEXT(Text[GETNAME_PROMPT], UsrFnam, 8, KeyClick); + if (tn) + { + tn->SetName(Text[GETNAME_TITLE]); + tn->Center(); + tn->Goto(tn->X, tn->Y - 10); + tn->Z = 126; + VGA::ShowQ.Insert(tn); + } + } +} +#endif + + + + + +#ifdef DEBUG + + +static void SwitchMapping (void) +{ + if (HorzLine.Flags.Hide) + { + int i; + for (i = 0; i < MAP_ZCNT; i ++) + { + int j; + for (j = 0; j < MAP_XCNT; j ++) + { + if (CLUSTER::Map[i][j]) + SetMapBrick(j, i); + } + } + } + else + { + SPRITE * s; + for (s = VGA::ShowQ.First(); s; s = s->Next) + if (s->W == MAP_XGRID && s->H == MAP_ZGRID) + SNPOST_(SNKILL, -1, 0, s); + } + HorzLine.Flags.Hide = ! HorzLine.Flags.Hide; +} + + + + + +static void KillSprite (void) +{ + Sprite->Flags.Kill = TRUE; + Sprite->Flags.BDel = TRUE; + SNPOST_(SNKILL, -1, 0, Sprite); + Sprite = NULL; +} + + + + + +static void PushSprite (void) +{ + SPRITE * spr = Sprite->Prev; + if (spr) + { + VGA::ShowQ.Insert(VGA::ShowQ.Remove(Sprite), spr); + while (Sprite->Z > Sprite->Next->Z) -- Sprite->Z; + } + else SNPOST_(SNSOUND, -1, 2, NULL); +} + + + + + +static void PullSprite (void) +{ + Boolean ok = FALSE; + SPRITE * spr = Sprite->Next; + if (spr) + { + spr = spr->Next; + if (spr) + { + ok = (! spr->Flags.Slav); + } + } + if (ok) + { + VGA::ShowQ.Insert(VGA::ShowQ.Remove(Sprite), spr); + if (Sprite->Prev) + while (Sprite->Z < Sprite->Prev->Z) ++ Sprite->Z; + } + else SNPOST_(SNSOUND, -1, 2, NULL); +} + + + + + + +static void NextStep (void) +{ + SNPOST_(SNSTEP, 0, 0, Sprite); +} + + + + + + + + + +static void SaveMapping (void) +{ + { + IOHAND cf(ProgName(".TAB"), UPD); + if (! cf.Error) + { + cf.Seek((Now-1) * sizeof(CLUSTER::Map)); + cf.Write((byte far *) CLUSTER::Map, sizeof(CLUSTER::Map)); + } + } + { + IOHAND cf(ProgName(".HXY"), WRI); + if (! cf.Error) + { + HeroXY[Now-1].X = Hero->X; + HeroXY[Now-1].Y = Hero->Y; + cf.Write((byte far *) HeroXY, sizeof(HeroXY)); + } + } +} + +#endif + + + +//-------------------------------------------------------------------------- + + + + + + + + + +#ifdef DEBUG + + + + // 1111111111222222222233333333 334444444444555555555566666666667777777777 + // 01234567890123456789012345678901234567 890123456789012345678901234567890123456789 +static char DebugText[] = " N=00000 F=000000 X=000 Y=000 FPS=0000\0S=00:00 000:000:000 000:000 00 "; + +#define NFRE (DebugText + 3) +#define FFRE (DebugText + 11) +#define ABSX (DebugText + 20) +#define ABSY (DebugText + 26) +#define FRPS (DebugText + 34) +#define XSPR (DebugText + 38) +#define SP_N (DebugText + 41) +#define SP_S (DebugText + 44) + +#define SP_X (DebugText + 47) +#define SP_Y (DebugText + 51) +#define SP_Z (DebugText + 55) +#define SP_W (DebugText + 59) +#define SP_H (DebugText + 63) +#define SP_F (DebugText + 67) +#define SP__ (DebugText + 70) + +INFO_LINE DebugLine(SCR_WID); + +static void SayDebug (void) +{ + if (! DebugLine.Flags.Hide) + { + static long t = -1L; + long t1 = Timer(); + + if (t1 - t >= 18) + { + static dword old = 0L; + dword now = Vga.FrmCnt; + dwtom(now - old, FRPS, 10, 4); + old = now; + t = t1; + } + + dwtom(Mouse.X, ABSX, 10, 3); + dwtom(Mouse.Y, ABSY, 10, 3); + dwtom(coreleft(), NFRE, 10, 5); + dwtom(farcoreleft(), FFRE, 10, 6); + + // sprite queue size + word n = 0; + SPRITE * spr; + for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) + { + ++ n; + if (spr == Sprite) + { + *XSPR = ' '; + dwtom(n, SP_N, 10, 2); + dwtom(Sprite->X, SP_X, 10, 3); + dwtom(Sprite->Y, SP_Y, 10, 3); + dwtom(Sprite->Z, SP_Z, 10, 3); + dwtom(Sprite->W, SP_W, 10, 3); + dwtom(Sprite->H, SP_H, 10, 3); + dwtom(*(word *) (&Sprite->Flags), SP_F, 16, 2); + } + } + dwtom(n, SP_S, 10, 2); + *SP__ = (heapcheck() < 0) ? '!' : ' '; + DebugLine.Update(DebugText); + } +} + + + + + +static void SwitchDebug (void) +{ + DebugLine.Flags.Hide = ! DebugLine.Flags.Hide; +} + + + +#endif + + + + + + +static void OptionTouch (int opt, word mask) +{ + switch (opt) + { + case 1 : if (mask & L_UP) SwitchColorMode(); break; + case 2 : if (mask & L_UP) SwitchMusic(); + else + if (mask & R_UP) + if (! MIXER::Appear) + { + MIXER::Appear = TRUE; + new MIXER(BUTTON_X, BUTTON_Y); + } + break; + case 3 : if (mask & L_UP) Quit(); break; + } +} + + + + + +#pragma argsused +void SPRITE::Touch (word mask, int x, int y) +{ + SYSTEM::FunTouch(); + if ((mask & ATTN) == 0) + { + InfoLine.Update(Name()); + if (mask & (R_DN | L_DN)) Sprite = this; // DEBUG mode only? + if (Ref/10 == 12) + { + OptionTouch(Ref % 10, mask); + return; + } + if (Flags.Syst) return; // cannot access system sprites + if (Game) if (mask & L_UP) { mask &= ~L_UP; mask |= R_UP; } + if ((mask & R_UP) && Snail.Idle()) + { + SPRITE * ps = (PocLight.SeqPtr) ? Pocket[PocPtr] : NULL; + if (ps) + { + if (Flags.Kept || Hero->Distance(this) < MAX_DISTANCE) + { + if (Works(ps)) + { + FeedSnail(ps, TAKE); + } + else OffUse(); + SelectPocket(-1); + } + else TooFar(); + } + else + { + if (Flags.Kept) mask |= L_UP; + else + { + if (Hero->Distance(this) < MAX_DISTANCE) + {/// + if (Flags.Port) + { + if (FindPocket(NULL) < 0) PocFul(); + else + { + SNPOST(SNREACH, -1, -1, this); + SNPOST(SNKEEP, -1, -1, this); + Flags.Port = FALSE; + } + } + else + { + if (TakePtr != NO_PTR) + { + if (SnList(TAKE)[TakePtr].Com == SNNEXT) OffUse(); + else FeedSnail(this, TAKE); + } + else OffUse(); + } + }/// + else TooFar(); + } + } + } + if ((mask & L_UP) && Snail.Idle()) + { + if (Flags.Kept) + { + int n; + for (n = 0; n < POCKET_NX; n ++) + { + if (Pocket[n] == this) + { + SelectPocket(n); + break; + } + } + } + else SNPOST(SNWALK, -1, -1, this); // Hero->FindWay(this); + } + } +} + + + + + + + +//-------------------------------------------------------------------------- +//-------------------------------------------------------------------------- + + + + + + +static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int row = 0, int pos = 0) +{ + static char * Comd[] = { "Name", "Type", "Phase", "East", + "Left", "Right", "Top", "Bottom", + "Seq", "Near", "Take", + "Portable", "Transparent", + NULL }; + static char * Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS", + "FLY", NULL }; + char line[LINE_MAX]; + + int shpcnt = 0; + int type = 0; // DEAD + Boolean east = FALSE; + Boolean port = FALSE; + Boolean tran = FALSE; + int i, lcnt = 0; + word len; + + MergeExt(line, fname, SPR_EXT); + if (INI_FILE::Exist(line)) // sprite description file exist + { + INI_FILE sprf(line); + if (sprf.Error) + { + VGA::Exit("Bad SPR", line); + } + + while ((len = sprf.Read(line)) != 0) + { + ++ lcnt; + if (len && line[len-1] == '\n') line[-- len] = '\0'; + if (len == 0 || *line == '.') continue; + + if ((i = TakeEnum(Comd, strtok(line, " =\t"))) < 0) + { + VGA::Exit(NumStr("Bad line ######", lcnt), fname); + } + + switch (i) + { + case 0 : // Name - will be taken in Expand routine + break; + case 1 : // Type + if ((type = TakeEnum(Type, strtok(NULL, " \t,;/"))) < 0) + VGA::Exit(NumStr("Bad line ######", lcnt), fname); + break; + case 2 : // Phase + ++ shpcnt; + break; + case 3 : // East + east = (atoi(strtok(NULL, " \t,;/")) != 0); + break; + case 11 : // Portable + port = (atoi(strtok(NULL, " \t,;/")) != 0); + break; + case 12 : // Transparent + tran = (atoi(strtok(NULL, " \t,;/")) != 0); + break; + } + } + if (! shpcnt) + { + VGA::Exit("No shapes", fname); + } + } + else // no sprite description: mono-shaped sprite with only .BMP file + { + ++ shpcnt; + } + + // make sprite of choosen type + switch (type) + { + case 1 : // AUTO + Sprite = new SPRITE(NULL); + if (Sprite) + { + Sprite->Goto(col, row); + //Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$ + } + break; + case 2 : // WALK + WALK * w = new WALK(NULL); + if (w && ref == 1) + { + w->Goto(col, row); + if (Hero) + { + VGA::Exit("2nd HERO", fname); + } + Hero = w; + } + Sprite = w; + break; + /* + case 3 : // NEWTON + NEWTON * n = new NEWTON(NULL); + if (n) + { + n->Ay = (bottom-n->H); + n->By = 90; + n->Cy = 3; + n->Bx = 99; + n->Cx = 3; + n->Goto(col, row); + } + Sprite = n; + break; + */ + case 4 : // LISSAJOUS + VGA::Exit("Bad type", fname); + /* + LISSAJOUS * l = new LISSAJOUS(NULL); + if (l) + { + l->Ax = SCR_WID/2; + l->Ay = SCR_HIG/2; + l->Bx = 7; + l->By = 13; + l->Cx = 300; + l->Cy = 500; + * (long *) &l->Dx = 0; // movex * cnt + l->Goto(col, row); + } + Sprite = l; + */ + break; + case 5 : // FLY + FLY * f = new FLY(NULL); + Sprite = f; + //////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$ + break; + default: // DEAD + Sprite = new SPRITE(NULL); + if (Sprite) Sprite->Goto(col, row); + break; + } + if (Sprite) + { + Sprite->Ref = ref; + Sprite->Cave = cav; + Sprite->Z = pos; + Sprite->Flags.East = east; + Sprite->Flags.Port = port; + Sprite->Flags.Tran = tran; + Sprite->Flags.Kill = TRUE; + Sprite->Flags.BDel = TRUE; + fnsplit(fname, NULL, NULL, Sprite->File, NULL); + Sprite->ShpCnt = shpcnt; + VGA::SpareQ.Append(Sprite); + } +} + + + + + + +static void LoadScript (const char *fname) +{ + char line[LINE_MAX]; + char * SpN; + int SpI, SpA, SpX, SpY, SpZ; + Boolean BkG = FALSE; + INI_FILE scrf(fname); + int lcnt = 0; + Boolean ok = TRUE; + + if (scrf.Error) return; + + while (scrf.Read(line) != 0) + { + char *p; + + ++ lcnt; + if (*line == 0 || *line == '\n' || *line == '.') continue; + + ok = FALSE; // not OK if break + // sprite ident number + if ((p = strtok(line, " \t\n")) == NULL) break; + SpI = atoi(p); + // sprite file name + if ((SpN = strtok(NULL, " ,;/\t\n")) == NULL) break; + // sprite cave + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; + SpA = atoi(p); + // sprite column + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; + SpX = atoi(p); + // sprite row + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; + SpY = atoi(p); + // sprite Z pos + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; + SpZ = atoi(p); + // sprite life + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; + BkG = atoi(p) == 0; + + ok = TRUE; // no break: OK + + Sprite = NULL; + LoadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); + if (Sprite && BkG) Sprite->Flags.Back = TRUE; + } + if (! ok) + { + VGA::Exit(NumStr("Bad INI line ######", lcnt), fname); + } +} + + + + +static void MainLoop (void) +{ +#if 0 +//def DEBUG + static VgaRegBlk Mode[] = { + + { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode + + { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 + { 0x05, VGAGRA, 0x03, 0x00 }, // R/W mode = 0 + { 0x06, VGAGRA, 0x02, 0x00 }, // misc + + { 0x14, VGACRT, 0x40, 0x00 }, // underline + { 0x13, VGACRT, 0xFF, 0x28 }, // screen width + { 0x17, VGACRT, 0xFF, 0xC3 }, // mode control + + { 0x11, VGACRT, 0x80, 0x00 }, // vert retrace end + { 0x09, VGACRT, 0xEF, 0x01 }, // max scan line + + { 0x30, VGAATR, 0x00, 0x20 }, // 256 color mode + +// { 0x12, VGACRT, 0xFF, 0x6E }, // vert display end +// { 0x15, VGACRT, 0xFF, 0x7F }, // start vb +// { 0x10, VGACRT, 0xFF, 0x94 }, // start vr + + { 0x00 } }; + + Vga.Setup(Mode); +#endif + + Debug( SayDebug(); ) + + #ifdef DEMO + #define TIM ((182L*6L) * 5L) + static dword tc = 0; + if (TimerCount - tc >= TIM && Talk == NULL && Snail.Idle()) + { + if (Text[DemoText]) + { + SNPOST(SNSOUND, -1, 4, NULL); // drumla + SNPOST(SNINF, -1, DemoText, NULL); + SNPOST(SNLABEL, -1, -1, NULL); + if (Text[++ DemoText] == NULL) DemoText = DEMO_TEXT + 1; + } + tc = TimerCount; + } + #undef TIM + #endif + + Vga.Show(); + Snail_.RunCom(); + Snail.RunCom(); +} + + + + + +void LoadUser (void) +{ + // set scene + if (STARTUP::Mode == 0) // user .SVG file found + { + LoadGame(CFILE(UsrPath(UsrFnam), REA, RCrypt)); + } + else + { + if (STARTUP::Mode == 1) LoadGame(SVG0FILE(SVG0NAME)); + else + { + LoadScript(ProgName(INI_EXT)); + Music = TRUE; + SaveGame(CFILE(SVG0NAME, WRI)); + VGA::Exit("Ok", SVG0NAME); + } + } + LoadScript(ProgName(IN0_EXT)); +} + + + + + +static void RunGame (void) +{ + Text.Clear(); + Text.Preload(100, 1000); + LoadHeroXY(); + + CavLight.Flags.Tran = TRUE; + VGA::ShowQ.Append(&CavLight); + CavLight.Flags.Hide = TRUE; + + static SEQ PocSeq[] = { { 0, 0, 0, 0, 20 }, + { 1, 2, 0, 0, 4 }, + { 2, 3, 0, 0, 4 }, + { 3, 4, 0, 0, 16 }, + { 2, 5, 0, 0, 4 }, + { 1, 6, 0, 0, 4 }, + { 0, 1, 0, 0, 16 }, + }; + PocLight.SetSeq(PocSeq); + PocLight.Flags.Tran = TRUE; + PocLight.Time = 1; + PocLight.Z = 120; + VGA::ShowQ.Append(&PocLight); + SelectPocket(-1); + + VGA::ShowQ.Append(&Mouse); + +// ___________ + LoadUser(); +// ~~~~~~~~~~~ + + if ((Sprite = VGA::SpareQ.Locate(121)) != NULL) + SNPOST_(SNSEQ, -1, VGA::Mono, Sprite); + if ((Sprite = VGA::SpareQ.Locate(122)) != NULL) Sprite->Step(Music); + SNPOST_(SNSEQ, -1, Music, Sprite); + if (! Music) KillMIDI(); + + if (Mini && INI_FILE::Exist("MINI.SPR")) + { + byte far * ptr = (byte far *) &*Mini; + if (ptr != NULL) + { + LoadSprite("MINI", -1, 0, MINI_X, MINI_Y); + ExpandSprite(MiniCave = Sprite); // NULL is ok + if (MiniCave) + { + MiniCave->Flags.Hide = TRUE; + MiniCave->MoveShapes(ptr); + MiniShp[0] = new BITMAP(*MiniCave->Shp()); + MiniShpList = MiniCave->SetShapeList(MiniShp); + PostMiniStep(-1); + } + } + } + + if (Hero) + { + ExpandSprite(Hero); + Hero->Goto(HeroXY[Now-1].X, HeroXY[Now-1].Y); + if (INI_FILE::Exist("00SHADOW.SPR")) + { + LoadSprite("00SHADOW", -1, 0, Hero->X + 14, Hero->Y + 51); + if ((Shadow = Sprite) != NULL) + { + Shadow->Ref = 2; + Shadow->Flags.Tran = TRUE; + Hero->Flags.Shad = TRUE; + VGA::ShowQ.Insert(VGA::SpareQ.Remove(Shadow), Hero); + } + } + } + + InfoLine.Goto(INFO_X, INFO_Y); + InfoLine.Flags.Tran = TRUE; + InfoLine.Update(NULL); + VGA::ShowQ.Insert(&InfoLine); + + #ifdef DEBUG + DebugLine.Z = 126; + VGA::ShowQ.Insert(&DebugLine); + + HorzLine.Y = MAP_TOP - (MAP_TOP > 0); + HorzLine.Z = 126; + VGA::ShowQ.Insert(&HorzLine); + #endif + + Mouse.Busy = VGA::SpareQ.Locate(BUSY_REF); + if (Mouse.Busy) ExpandSprite(Mouse.Busy); + + Startup = 0; + + SNPOST(SNLEVEL, -1, OldLev, &CavLight); + CavLight.Goto(CAVE_X + ((Now-1) % CAVE_NX) * CAVE_DX + CAVE_SX, + CAVE_Y + ((Now-1) / CAVE_NX) * CAVE_DY + CAVE_SY); + CaveUp(); + + KEYBOARD::SetClient(Sys); + // main loop + while (! Finis) + { + if (FINIS) SNPOST(SNEXEC, -1, 0, (void *) QGame); + MainLoop(); + } + + KEYBOARD::SetClient(NULL); + HEART::Enable = FALSE; + SNPOST(SNCLEAR, -1, 0, NULL); + SNPOST_(SNCLEAR, -1, 0, NULL); + Mouse.Off(); + VGA::ShowQ.Clear(); + VGA::SpareQ.Clear(); + Hero = NULL; + Shadow = NULL; +} + + + + +void Movie (const char * ext) +{ + const char * fn = ProgName(ext); + if (INI_FILE::Exist(fn)) + { + LoadScript(fn); + ExpandSprite(VGA::SpareQ.Locate(999)); + FeedSnail(VGA::ShowQ.Locate(999), TAKE); + VGA::ShowQ.Append(&Mouse); + HEART::Enable = TRUE; + KEYBOARD::SetClient(Sys); + while (! Snail.Idle()) + { + MainLoop(); + } + KEYBOARD::SetClient(NULL); + HEART::Enable = FALSE; + SNPOST(SNCLEAR, -1, 0, NULL); + SNPOST_(SNCLEAR, -1, 0, NULL); + VGA::ShowQ.Clear(); + VGA::SpareQ.Clear(); + } +} + + + + + + +Boolean ShowTitle (const char * name) +{ + BITMAP::Pal = SysPal; + BMP_PTR LB[] = { new BITMAP(name), NULL }; + BITMAP::Pal = NULL; + Boolean usr_ok = FALSE; + + SPRITE D(LB); + D.Flags.Kill = TRUE; + D.Flags.BDel = TRUE; + D.Center(); + D.Show(2); + + if (STARTUP::Mode == 2) + { + Inf(SVG0NAME); + Talk->Show(2); + } + + Vga.Sunset(); + VGA::CopyPage(1, 2); + VGA::CopyPage(0, 1); + SelectPocket(-1); + Vga.Sunrise(SysPal); + + if (STARTUP::Mode < 2 && ! STARTUP::SoundOk) + { + VGA::CopyPage(1, 2); + VGA::CopyPage(0, 1); + VGA::ShowQ.Append(&Mouse); + HEART::Enable = TRUE; + Mouse.On(); + for (SelectSound(); ! Snail.Idle() || VMENU::Addr; ) MainLoop(); + Mouse.Off(); + HEART::Enable = FALSE; + VGA::ShowQ.Clear(); + VGA::CopyPage(0, 2); + STARTUP::SoundOk = 2; + if (Music) LoadMIDI(0); + } + + if (STARTUP::Mode < 2) + { + #ifdef DEMO + strcpy(UsrFnam, ProgName(SVG_EXT)); + usr_ok = TRUE; + #else + //----------------------------------------- + #ifndef EVA + #ifdef CD + STARTUP::Summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; + #else + Boot * b = ReadBoot(getdisk()); + dword sn = (b->XSign == 0x29) ? b->Serial : b->lTotSecs; + free(b); + sn -= ((IDENT *)Copr)->disk; + STARTUP::Summa |= Lo(sn) | Hi(sn); + #endif + #endif + //----------------------------------------- + Movie("X00"); // paylist + VGA::CopyPage(1, 2); + VGA::CopyPage(0, 1); + VGA::ShowQ.Append(&Mouse); + //Mouse.On(); + HEART::Enable = TRUE; + for (TakeName(); GET_TEXT::Ptr; ) MainLoop(); + HEART::Enable = FALSE; + if (KEYBOARD::Last() == Enter && *UsrFnam) usr_ok = TRUE; + if (usr_ok) strcat(UsrFnam, SVG_EXT); + //Mouse.Off(); + VGA::ShowQ.Clear(); + VGA::CopyPage(0, 2); + #endif + if (usr_ok && STARTUP::Mode == 0) + { + const char *n = UsrPath(UsrFnam); + if (CFILE::Exist(n)) + { + LoadGame(CFILE(n, REA, RCrypt), TRUE); // only system vars + VGA::SetColors(SysPal, 64); + Vga.Update(); + if (FINIS) + { + ++ STARTUP::Mode; + FINIS = FALSE; + } + } + else ++ STARTUP::Mode; + } + } + + if (STARTUP::Mode < 2) Movie("X01"); // wink + + VGA::CopyPage(0, 2); + + #ifdef DEMO + return TRUE; + #else + return (STARTUP::Mode == 2 || usr_ok); + #endif +} + + + + +/* +#ifdef DEBUG +void StkDump (void) +{ + CFILE f("!STACK.DMP", BFW); + f.Write((byte far *) (intStackPtr-STACK_SIZ/2), STACK_SIZ*2); +} +#endif +*/ + + + + +void cge_main (void) +{ + word intStack[STACK_SIZ/2]; + intStackPtr = intStack; + + //Debug( memset((void *) (-K(2)), 0, K(1)); ) + //Debug( memset((void *) (-K(4)), 0, K(1)); ) + memset(Barriers, 0xFF, sizeof(Barriers)); + + if (! Mouse.Exist) VGA::Exit(NO_MOUSE_TEXT); + if (! SVG0FILE::Exist(SVG0NAME)) STARTUP::Mode = 2; + + Debug( DebugLine.Flags.Hide = TRUE; ) + Debug( HorzLine.Flags.Hide = TRUE; ) + + srand((word) Timer()); + Sys = new SYSTEM; + + if (Music && STARTUP::SoundOk) LoadMIDI(0); + if (STARTUP::Mode < 2) Movie(LGO_EXT); + if (ShowTitle("WELCOME")) + { + #ifndef DEMO + if (STARTUP::Mode == 1) Movie("X02"); // intro + #endif + RunGame(); + Startup = 2; + if (FINIS) Movie("X03"); + } + else Vga.Sunset(); + VGA::Exit(EXIT_OK_TEXT+FINIS); +} diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h new file mode 100644 index 00000000000..f5c104600ad --- /dev/null +++ b/engines/cge/cge_main.h @@ -0,0 +1,181 @@ +#ifndef __CGE__ +#define __CGE__ + +#include "cge\wav.h" + +namespace CGE { + +#define TSEQ 96 +#define HTALK (TSEQ+4) +#define TOO_FAR (TSEQ+5) +#define NO_WAY (TSEQ+5) +#define POC_FUL (TSEQ+5) +#define OFF_USE (TSEQ+6) + +#define EXIT_OK_TEXT 40 +#define NOMUSIC_TEXT 98 +#define BADSVG_TEXT 99 +#define OFF_USE_COUNT 600 +#define OFF_USE_TEXT 601 +#define NO_WAY_TEXT 671 +#define TOO_FAR_TEXT 681 +#define POC_FUL_TEXT 691 +#define A_C_D_TEXT 777 + +#define GETNAME_PROMPT 50 +#define GETNAME_TITLE 51 + +#define QUIT_TITLE 200 +#define QUIT_TEXT 201 +#define NOQUIT_TEXT 202 +#define DEMO_TEXT 300 +#define NOSOUND_TEXT 310 + +#define PAN_HIG 40 +#define WORLD_HIG (SCR_HIG-PAN_HIG) + +#define INFO_X 177 +#define INFO_Y 164 +#define INFO_W 140 + +#if defined(DEMO) + #define CAVE_X 4 + #define CAVE_Y 166 + #define CAVE_SX 0 + #define CAVE_SY 0 + #define CAVE_DX 23 + #define CAVE_DY 29 + #define CAVE_NX 3 + #define CAVE_NY 1 +#else + #define CAVE_X 4 + #define CAVE_Y 166 + #define CAVE_SX 0 + #define CAVE_SY 0 + #define CAVE_DX 9 + #define CAVE_DY 10 + #define CAVE_NX 8 + #define CAVE_NY 3 +#endif + +#define BUTTON_X 151 +#define BUTTON_Y 164 +#define BUTTON_DX 19 +#define BUTTON_DY 11 +#define BUTTON_NX 1 +#define BUTTON_NY 3 + +#define MINI_X 86 +#define MINI_Y 162 + +//#define MAP_XCNT 16 +//#define MAP_ZCNT 4 +#define MAP_XCNT 40 +#define MAP_ZCNT 20 +#define MAP_TOP 80 +#define MAP_HIG 80 +#define MAP_XGRID (SCR_WID / MAP_XCNT) +#define MAP_ZGRID (MAP_HIG / MAP_ZCNT) + +//#if SCR_WID % MAP_XGRID +// #error Illegal horizontal grid size or count +//#endif + +//#if MAP_HIG % MAP_ZGRID +// #error Illegal vertical grid size or count +//#endif + +#define LINE_MAX 512 +#define USER_MAX 100 +#define SHP_MAX 1024 +#define STD_DELAY 3 +#define LEV_MAX 5 +#define CAVE_MAX (CAVE_NX*CAVE_NY) +#define MAX_FIND_LEVEL 3 +#define MAX_DISTANCE 3 + +#define INI_EXT ".INI" +#define IN0_EXT ".IN0" +#define LGO_EXT ".LGO" +#define SVG_EXT ".SVG" + +#define WALKSIDE 10 + +#define BUSY_REF 500 + +#define SYSTIMERATE 6 // 12 Hz +#define HEROFUN0 (40*12) +#define HEROFUN1 ( 2*12) +#define PAIN (Flag[0]) +#define FINIS (Flag[3]) + + +//-------------------------------------------------------------------------- + + +class SYSTEM : public SPRITE +{ + int lum; +public: + static int FunDel; + static void SetPal (void); + static void FunTouch (void); + SYSTEM (void) : SPRITE(NULL) { SetPal(); Tick(); } + void Touch (word mask, int x, int y); + void Tick (void); +}; + + + + +//-------------------------------------------------------------------------- + + + + +class CLUSTER : public COUPLE +{ +public: + static byte Map[MAP_ZCNT][MAP_XCNT]; + byte &Cell (void); + CLUSTER (void) : COUPLE () { } + CLUSTER (int a, int b) : COUPLE (a, b) { } + Boolean Protected (void); +}; + + + + +class WALK : public SPRITE +{ +public: + CLUSTER Here; + enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; + int TracePtr; + WALK (BMP_PTR * shpl); + void Tick (void); + void FindWay(CLUSTER c); + void FindWay(SPRITE * spr); + int Distance (SPRITE * spr); + void Turn (DIR d); + void Park (void); + Boolean Lower (SPRITE * spr); + void Reach (SPRITE * spr, int mode = -1); +}; + + + + + CLUSTER XZ (int x, int y); + CLUSTER XZ (COUPLE xy); + + +extern WALK * Hero; + + + void ExpandSprite (SPRITE * spr); + void ContractSprite (SPRITE * spr); + void cge_main(void); + +} // End of CGE +#endif diff --git a/engines/cge/drop.h b/engines/cge/drop.h new file mode 100644 index 00000000000..e79b2eb8992 --- /dev/null +++ b/engines/cge/drop.h @@ -0,0 +1 @@ +#include "vga13h.h" diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp new file mode 100644 index 00000000000..4ac27651b72 --- /dev/null +++ b/engines/cge/game.cpp @@ -0,0 +1,91 @@ +#include "game.h" +#include "mouse.h" +#include +#include + + + + + +byte * Glass (DAC far * pal, byte r, byte g, byte b) +{ + byte * x = new byte[256]; + if (x) + { + word i; + for (i = 0; i < 256; i ++) + { + x[i] = Closest(pal, MkDAC(((word)(pal[i].R) * r) / 255, + ((word)(pal[i].G) * g) / 255, + ((word)(pal[i].B) * b) / 255)); + } + } + return x; +} + + + + + +byte * Mark (DAC far * pal) +{ + #define f(c) (c ^ 63) + byte * x = new byte[256]; + if (x) + { + word i; + for (i = 0; i < 256; i ++) + { + x[i] = Closest(pal, MkDAC(f(pal[i].R), + f(pal[i].G), + f(pal[i].B)) ); + } + } + return x; + #undef f +} + + + + + +//-------------------------------------------------------------------------- + + + +int FLY::L = 20, + FLY::T = 40, + FLY::R = 110, + FLY::B = 100; + + + +FLY::FLY (BITMAP ** shpl) +: SPRITE(shpl), Tx(0), Ty(0) +{ + Step(random(2)); + Goto(L+random(R-L-W), T+random(B-T-H)); +} + + + + +void FLY::Tick (void) +{ + Step(); + if (! Flags.Kept) + { + if (random(10) < 1) + { + Tx = random(3) - 1; + Ty = random(3) - 1; + } + if (X + Tx < L || X + Tx + W > R) Tx = -Tx; + if (Y + Ty < T || Y + Ty + H > B) Ty = -Ty; + Goto(X + Tx, Y + Ty); + } +} + + +//-------------------------------------------------------------------------- + diff --git a/engines/cge/game.h b/engines/cge/game.h new file mode 100644 index 00000000000..92ad49b2a44 --- /dev/null +++ b/engines/cge/game.h @@ -0,0 +1,40 @@ +#ifndef __GAME__ +#define __GAME__ + +#include "vga13h.h" +#include "bitmaps.h" + + + +#define PAN_HIG 40 +#define LBound(s) (s->X <= 0) +#define RBound(s) (s->X+s->W >= SCR_WID) +#define TBound(s) (s->Y <= 0) +#define BBound(s) (s->Y+s->H >= SCR_HIG - PAN_HIG) + + + +extern SPRITE * Sys; + +int Sinus (long x); +byte * Glass (DAC far * pal, byte r, byte g, byte b); +byte * Mark (DAC far * pal); + + + + + +class FLY : public SPRITE +{ + static int L, T, R, B; +public: + int Tx, Ty; + FLY (BITMAP ** shpl); + void Tick (void); +}; + + + + + +#endif \ No newline at end of file diff --git a/engines/cge/general.h b/engines/cge/general.h new file mode 100644 index 00000000000..7e9551e0769 --- /dev/null +++ b/engines/cge/general.h @@ -0,0 +1,241 @@ +#ifndef __GENERAL__ +#define __GENERAL__ + +#include "cge\jbw.h" +#include + +#define SEED 0xA5 + +#define SCR_WID_ 320 +#define SCR_HIG_ 200 +#define SCR_WID ((word)SCR_WID_) +#define SCR_HIG ((word)SCR_HIG_) +#define SCR_SEG 0xA000 +#define SCR_ADR ((byte far *) MK_FP(SCR_SEG, 0)) + + + +enum CPU { _8086, _80186, _80286, _80386, _80486 }; +enum MEM_TYPE { BAD_MEM, EMS_MEM, NEAR_MEM, FAR_MEM }; +enum ALLOC_MODE { FIRST_FIT, BEST_FIT, LAST_FIT }; +enum IOMODE { REA, WRI, UPD }; + +typedef struct { + byte R, G, B; + } DAC; + +typedef word CRYPT (void far * buf, word siz, word seed); + + + + + + +class COUPLE +{ +protected: + signed char A; + signed char B; +public: + COUPLE (void) { } + COUPLE (const signed char a, const signed char b) : A(a), B(b) { } + COUPLE operator + (COUPLE c) { return COUPLE(A+c.A, B+c.B); } + void operator += (COUPLE c) { A += c.A; B += c.B; } + COUPLE operator - (COUPLE c) { return COUPLE(A-c.A, B-c.B); } + void operator -= (COUPLE c) { A -= c.A; B -= c.B; } + Boolean operator == (COUPLE c) { return ((A - c.A) | (B - c.B)) == 0; } + Boolean operator != (COUPLE c) { return ! (operator == (c)); } + void Split (signed char& a, signed char& b) { a = A; b = B; } +}; + + +//------------------------------------------------------------------------- + + + +class ENGINE +{ +protected: + static void interrupt (far * OldTimer) (...); + static void interrupt NewTimer (...); +public: + ENGINE (word tdiv); + ~ENGINE (void); +}; + + + + +//------------------------------------------------------------------------- + + +class EMS; + + + +class EMM +{ + friend EMS; + Boolean Test (void); + long Top, Lim; + EMS * List; + int Han; + static void _seg * Frame; +public: + EMM::EMM (long size = 0); + EMM::~EMM (void); + EMS * Alloc (word siz); + void Release (void); +}; + + + + + +class EMS +{ + friend EMM; + EMM * Emm; + long Ptr; + word Siz; + EMS * Nxt; +public: + EMS (void); + void far * operator & () const; + word Size (void); +}; + + + +//------------------------------------------------------------------------- + + + + +template +void Swap (T& A, T& B) +{ + T a = A; + A = B; + B = a; +}; + + + + + +#ifdef __cplusplus + + +template +T max (T A, T B) +{ + return (A > B) ? A : B; +}; + + + +template +T min (T A, T B) +{ + return (A < B) ? A : B; +}; + + +#endif + + + + + + + +class XFILE +{ +public: + IOMODE Mode; + word Error; + XFILE (void) : Mode(REA), Error(0) { } + XFILE (IOMODE mode) : Mode(mode), Error(0) { } + virtual word Read (void far * buf, word len) = 0; + virtual word Write (void far * buf, word len) = 0; + virtual long Mark (void) = 0; + virtual long Size (void) = 0; + virtual long Seek (long pos) = 0; +}; + + + + + +template +inline word XRead (XFILE * xf, T * t) +{ + return xf->Read((byte far *) t, sizeof(*t)); +}; + + + + + +class IOHAND : public XFILE +{ +protected: + int Handle; + word Seed; + CRYPT * Crypt; +public: + IOHAND (const char near * name, IOMODE mode = REA, CRYPT crypt = NULL); + IOHAND (IOMODE mode = REA, CRYPT * crpt = NULL); + virtual ~IOHAND (void); + static Boolean Exist (const char * name); + word Read (void far * buf, word len); + word Write (void far * buf, word len); + long Mark (void); + long Size (void); + long Seek (long pos); + ftime Time (void); + void SetTime (ftime t); +}; + + + + + +CRYPT XCrypt; +CRYPT RXCrypt; +CRYPT RCrypt; + +MEM_TYPE MemType (void far * mem); +unsigned FastRand (void); +unsigned FastRand (unsigned s); +CPU Cpu (void); +ALLOC_MODE SetAllocMode (ALLOC_MODE am); +word atow (const char * a); +word xtow (const char * x); +char * wtom (word val, char * str, int radix, int len); +char * dwtom (dword val, char * str, int radix, int len); +char * DateTimeString (void); +void StdLog (const char *msg, const char *nam = NULL); +void StdLog (const char *msg, word w); +void StdLog (const char *msg, dword d); +int TakeEnum (const char ** tab, const char * txt); +word ChkSum (void far * m, word n); +long Timer (void); +long TimerLimit (word t); +Boolean TimerLimitGone (long t); +char * MergeExt (char * buf, const char * nam, const char * ext); +char * ForceExt (char * buf, const char * nam, const char * ext); +inline const char * ProgPath (void); +const char * ProgName (const char * ext = NULL); +int DriveFixed (unsigned drv); +int DriveRemote (unsigned drv); +int DriveCD (unsigned drv); +Boolean IsVga (void); + +EC void _fqsort (void far *base, word nelem, word width, + int (*fcmp)(const void far *, const void far *)); + + + +#endif diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp new file mode 100644 index 00000000000..69350b5fc8e --- /dev/null +++ b/engines/cge/gettext.cpp @@ -0,0 +1,110 @@ +#include "gettext.h" +#include "keybd.h" +#include "mouse.h" +#include + + + + + +GET_TEXT * GET_TEXT::Ptr = NULL; + + + +GET_TEXT::GET_TEXT (const char * info, char * text, int size, void (*click)(void)) +: Text(text), Size(min(size, GTMAX)), Len(min(Size, strlen(text))), + Cntr(GTBLINK), Click(click), OldKeybClient(KEYBOARD::SetClient(this)) +{ + int i = 2 * TEXT_HM + Font.Width(info); + Ptr = this; + Mode = RECT; + TS[0] = Box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); + SetShapeList(TS); + Flags.BDel = TRUE; + Flags.Kill = TRUE; + memcpy(Buff, text, Len); + Buff[Len] = ' '; + Buff[Len+1] = '\0'; + PutLine(0, info); + Tick(); +} + + + + + + +GET_TEXT::~GET_TEXT (void) +{ + KEYBOARD::SetClient(OldKeybClient); + Ptr = NULL; +} + + + + + + +void GET_TEXT::Tick (void) +{ + if (++ Cntr >= GTBLINK) + { + Buff[Len] ^= (' ' ^ '_'); + Cntr = 0; + } + PutLine(1, Buff); + Time = GTTIME; +} + + + + +void GET_TEXT::Touch (word mask, int x, int y) +{ + static char ogon[] = "•œ¥£˜ ¡"; + static char bezo[] = "ACELNOSXZ"; + char * p; + + if (mask & KEYB) + { + if (Click) Click(); + switch (x) + { + case Enter : Buff[Len] = '\0'; strcpy(Text, Buff); + for (p = Text; *p; p ++) + { + char * q = strchr(ogon, *p); + if (q) *p = bezo[q-ogon]; + } + case Esc : SNPOST_(SNKILL, -1, 0, this); break; + case BSp : if (Len) + { + -- Len; + Buff[Len] = Buff[Len+1]; + Buff[Len+1] = Buff[Len+2]; + } + break; + default : if (x < 'A' || x > 'Z') + { + if (OldKeybClient) + OldKeybClient->Touch(mask, x, y); + } + else + { + if (KEYBOARD::Key[ALT]) + { + p = strchr(bezo, x); + if (p) x = ogon[p-bezo]; + } + if (Len < Size && 2 * TEXT_HM + Font.Width(Buff) + Font.Wid[x] <= W) + { + Buff[Len+2] = Buff[Len+1]; + Buff[Len+1] = Buff[Len]; + Buff[Len ++] = x; + } + } + break; + } + } + else SPRITE::Touch(mask, x, y); +} diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h new file mode 100644 index 00000000000..8d4e15c6cb8 --- /dev/null +++ b/engines/cge/gettext.h @@ -0,0 +1,35 @@ +#ifndef __GETTEXT__ +#define __GETTEXT__ + +#include +#include "talk.h" + + +#define GTMAX 24 +#define GTBLINK 6 +#define GTTIME 6 + + + + + + + +class GET_TEXT : public TALK +{ + char Buff[GTMAX+2], * Text; + word Size, Len; + word Cntr; + SPRITE * OldKeybClient; + void (*Click)(void); +public: + static GET_TEXT * Ptr; + GET_TEXT (const char * info, char * text, int size, void (*click)(void) = NULL); + ~GET_TEXT (void); + void Touch (word mask, int x, int y); + void Tick (void); +}; + + + +#endif diff --git a/engines/cge/ident.h b/engines/cge/ident.h new file mode 100644 index 00000000000..5370b9638cf --- /dev/null +++ b/engines/cge/ident.h @@ -0,0 +1,14 @@ +#ifndef __IDENT__ +#define __IDENT__ + + +struct IDENT + { + char copr[83]; + char fill[8]; + unsigned long disk; + unsigned char cork; + }; + + +#endif diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h new file mode 100644 index 00000000000..98ce9e27b5c --- /dev/null +++ b/engines/cge/jbw.h @@ -0,0 +1,149 @@ +#ifndef __JBW__ +#define __JBW__ + +#define BEL 7 +#define BS 8 +#define HT 9 +#define LF 10 +#define FF 12 +#define CR 13 + +#define NULL 0 +#define TRUE (1==1) +#define FALSE (!TRUE) +#define OFF FALSE +#define ON TRUE + +#define IsWhite(c) ((c) == ' ' || (c) == '\t' || (c) == '\n') +#define IsUpper(c) ((c) >= 'A' && (c) <= 'Z') +#define IsLower(c) ((c) >= 'a' && (c) <= 'z') +#define IsDigit(c) ((c) >= '0' && (c) <= '9') +#define IsAlpha(c) (IsLower(c) || IsUpper(c) || (c) == '_') +#define IsAlNum(c) (IsAlpha(c) || IsDigit(c)) +#define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) + +#define farnew(t,n) ((t far *) farmalloc(sizeof(t) * (n))) +#define ArrayCount(a) (sizeof(a)/sizeof((a)[0])) +#define MAX_TIMER 0x1800B0L + +typedef unsigned char BYTE; +typedef unsigned int WORD; +typedef unsigned long DWORD; + +typedef int Boolean; +typedef unsigned char byte; +typedef unsigned int word; +typedef unsigned long dword; +typedef void (far _loadds MouseFunType)(void); + +#define Lo(d) (((int *) &d)[0]) +#define Hi(d) (((int *) &d)[1]) +#define LoWord(d) ((word) Lo(d)) +#define HiWord(d) ((word) Hi(d)) +#define K(n) (1024*(n)) +#define MASK(n) ((1< + + +SPRITE * KEYBOARD::Client = NULL; +byte KEYBOARD::Key[0x60] = { 0 }; +word KEYBOARD::Current = 0; +word KEYBOARD::Code[0x60] = { 0,Esc,'1','2','3','4','5','6','7','8','9','0', + '-','+',BSp,Tab,'Q','W','E','R','T','Y','U', + 'I','O','P','[',']',Enter,0/*Ctrl*/,'A','S', + 'D','F','G','H','J','K','L',';','\'','`', + 0/*LShift*/,'\\','Z','X','C','V','B','N','M', + ',','.','/',0/*RShift*/,'*',0/*Alt*/,' ', + 0/*Caps*/,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10, + 0/*NumLock*/,0/*ScrollLock*/,Home,Up,PgUp, + '-',Left,Ctr,Right,'+',End,Down,PgDn,Ins,Del, + 0*0x54,0*0x55,0*0x56,F11,F12,0*0x59,0*0x5A, + 0*0x5B,0*0x5C,0*0x5D,0*0x5E,0*0x5F + }; +void interrupt (far * KEYBOARD::OldKeyboard) (...); + + + +KEYBOARD::KEYBOARD (void) +{ + // steal keyboard interrupt + OldKeyboard = getvect(KEYBD_INT); + setvect(KEYBD_INT, NewKeyboard); +} + + + + +KEYBOARD::~KEYBOARD (void) +{ + // bring back keyboard interrupt + setvect(KEYBD_INT, OldKeyboard); +} + + + + +SPRITE * KEYBOARD::SetClient (SPRITE * spr) +{ + Swap(Client, spr); + return spr; +} + + + + + +void interrupt KEYBOARD::NewKeyboard (...) +{ + // table address + _SI = (word) Key; + + // take keyboard code + asm in al,60h + asm mov bl,al + asm and bx,007Fh + asm cmp bl,60h + asm jae xit + asm cmp al,bl + asm je ok // key pressed + + // key released... + asm cmp [si+bx],bh // BH == 0 + asm jne ok + // ...but not pressed: call the original service + OldKeyboard(); + return; + + ok: + asm shl ax,1 + asm and ah,1 + asm xor ah,1 + asm mov [si+bx],ah + asm jz xit // released: exit + + // pressed: lock ASCII code + _SI = (word) Code; + asm add bx,bx // word size + asm mov ax,[si+bx] + asm or ax,ax + asm jz xit // zero means NO KEY + Current = _AX; + + _SI = (word) Client; + asm or si,si + asm jz xit // if (Client) ... +//--- fill current event entry with mask, key code and sprite + asm mov bx,EvtHead // take queue head pointer + asm inc byte ptr EvtHead // update queue head pointer + asm shl bx,3 // * 8 + _AX = Current; + asm mov Evt[bx].(struct EVENT)X,ax // key code + asm mov ax,KEYB // event mask + asm mov Evt[bx].(struct EVENT)Msk,ax // event mask + //asm mov Evt[bx].(struct EVENT)Y,dx // row + asm mov Evt[bx].(struct EVENT)Ptr,si // SPRITE pointer + + xit: + + asm in al,61h // kbd control lines + asm push ax // save it + asm or al,80h // set the "enable kbd" bit + asm out 61h,al // and write it out + asm pop ax // original control port value + asm out 61h,al // write it back + asm mov al,20h // send End-Of-Interrupt + asm out 20h,al // to the 8259 IC +} diff --git a/engines/cge/keybd.h b/engines/cge/keybd.h new file mode 100644 index 00000000000..744dc8c8acf --- /dev/null +++ b/engines/cge/keybd.h @@ -0,0 +1,31 @@ +#ifndef __KEYBD__ +#define __KEYBD__ + +#include +#include "vga13h.h" + + +#define KEYBD_INT 9 +#define LSHIFT 42 +#define RSHIFT 54 +#define CTRL 29 +#define ALT 56 + + +class KEYBOARD +{ + static void interrupt (far * OldKeyboard) (...); + static void interrupt NewKeyboard (...); + static word Code[0x60]; + static word Current; + static SPRITE * Client; +public: + static byte Key[0x60]; + static word Last (void) { _AX = Current; Current = 0; return _AX; } + static SPRITE * SetClient (SPRITE * spr); + KEYBOARD (void); + ~KEYBOARD (void); +}; + + +#endif diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp new file mode 100644 index 00000000000..7a494d0b904 --- /dev/null +++ b/engines/cge/mixer.cpp @@ -0,0 +1,129 @@ +#include "mixer.h" +#include "text.h" +#include "snail.h" +#include "mouse.h" +#include +#include +#include + +//-------------------------------------------------------------------------- + + +extern MOUSE Mouse; + + Boolean MIXER::Appear = FALSE; + + + +MIXER::MIXER (int x, int y) +: SPRITE(NULL), Fall(MIX_FALL) +{ + int i; + Appear = TRUE; + mb[0] = new BITMAP("VOLUME"); + mb[1] = NULL; + SetShapeList(mb); + SetName(Text[MIX_NAME]); + Flags.Syst = TRUE; + Flags.Kill = TRUE; + Flags.BDel = TRUE; + Goto(x, y); + Z = MIX_Z; + + // slaves + + for (i = 0; i < MIX_MAX; i ++) + { + static char fn[] = "V00"; + wtom(i, fn+1, 10, 2); + lb[i] = new BITMAP(fn); + ls[i].Now = ls[i].Next = i; + ls[i].Dx = ls[i].Dy = ls[i].Dly = 0; + } + lb[i] = NULL; + + for (i = 0; i < ArrayCount(Led); i ++) + { + register SPRITE * spr = new SPRITE(lb); + spr->SetSeq(ls); + spr->Goto(x+2+12*i, y+8); + spr->Flags.Tran = TRUE; + spr->Flags.Kill = TRUE; + spr->Flags.BDel = FALSE; + spr->Z = MIX_Z; + Led[i] = spr; + } + Led[ArrayCount(Led)-1]->Flags.BDel = TRUE; + + VGA::ShowQ.Insert(this); + for (i = 0; i < ArrayCount(Led); i ++) VGA::ShowQ.Insert(Led[i]); + + //--- reset balance + i = (SNDDrvInfo.VOL4.ML + SNDDrvInfo.VOL4.MR) / 2; + SNDDrvInfo.VOL4.ML = i; + SNDDrvInfo.VOL4.MR = i; + i = (SNDDrvInfo.VOL4.DL + SNDDrvInfo.VOL4.DR) / 2; + SNDDrvInfo.VOL4.DL = i; + SNDDrvInfo.VOL4.DR = i; + Update(); + Time = MIX_DELAY; +} + + + + +MIXER::~MIXER (void) +{ + Appear = FALSE; +} + + + +#pragma argsused +void MIXER::Touch (word mask, int x, int y) +{ + SPRITE::Touch(mask, x, y); + if (mask & L_UP) + { + byte * vol = (&SNDDrvInfo.VOL2.D) + (x < W/2); + if (y < MIX_BHIG) { if (*vol < 0xFF) *vol += 0x11; } + else if (y >= H-MIX_BHIG) { if (*vol > 0x00) *vol -= 0x11; } + Update(); + } +} + + + +void MIXER::Tick (void) +{ + int x = Mouse.X, y = Mouse.Y; + if (SpriteAt(x, y) == this) + { + Fall = MIX_FALL; + if (Flags.Hold) Touch(L_UP, x-X, y-Y); + } + else + { + if (Fall) -- Fall; + else + { + int i; + for (i = 0; i < ArrayCount(Led); i ++) + { + SNPOST_(SNKILL, -1, 0, Led[i]); + } + SNPOST_(SNKILL, -1, 0, this); + } + } + Time = MIX_DELAY; +} + + + + +void MIXER::Update (void) +{ + Led[0]->Step(SNDDrvInfo.VOL4.ML); + Led[1]->Step(SNDDrvInfo.VOL4.DL); + SNPOST_(SNEXEC, -1, 0, SNDSetVolume); +} diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h new file mode 100644 index 00000000000..8ee2bb6f805 --- /dev/null +++ b/engines/cge/mixer.h @@ -0,0 +1,31 @@ +#ifndef __MIXER__ +#define __MIXER__ + +#include "vga13h.h" + +#define MIX_MAX 16 // count of Leds +#define MIX_Z 64 // mixer Z position +#define MIX_DELAY 12 // 6/s +#define MIX_FALL 6 // in MIX_DELAY units +#define MIX_BHIG 6 // mixer button high +#define MIX_NAME 105 // sprite name + +class MIXER : public SPRITE +{ + BMP_PTR mb[2]; + BMP_PTR lb[MIX_MAX+1]; + SEQ ls[MIX_MAX]; + SPRITE * Led[2]; + int Fall; + void Update (void); +public: + static Boolean Appear; + MIXER (int x, int y); + ~MIXER (void); + void Touch (word mask, int x, int y); + void Tick (void); +}; + + + +#endif diff --git a/engines/cge/module.mk b/engines/cge/module.mk index 62ddd9d3623..7424c8bc38f 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -1,9 +1,26 @@ MODULE := engines/cge MODULE_OBJS := \ + bitmap.o \ + bitmaps.o \ + cfile.o \ cge.o \ + cge_main.o \ console.o \ - detection.o + detection.o \ + game.o \ + gettext.o \ + keybd.o \ + mixer.o \ + mouse.o \ + snail.o \ + sound.o \ + startup.o \ + talk.o \ + text.o \ + vga13h.o \ + vmenu.o \ + vol.o MODULE_DIRS += \ engines/cge diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp new file mode 100644 index 00000000000..703fd80f652 --- /dev/null +++ b/engines/cge/mouse.cpp @@ -0,0 +1,207 @@ +#include "mouse.h" +#include "text.h" +#include + + + + EVENT Evt[EVT_MAX]; + + word EvtHead = 0, EvtTail = 0; +//-------------------------------------------------------------------------- + +MOUSE_FUN * MOUSE::OldMouseFun = NULL; +word MOUSE::OldMouseMask = 0; + + + +//-------------------------------------------------------------------------- + + + + + +MOUSE::MOUSE (BITMAP ** shpl) + : SPRITE(shpl), Busy(NULL), Hold(NULL), hx(0) +{ + static SEQ ms[] = { { 0,0,0,0,1 }, { 1,1,0,0,1 } }; + SetSeq(ms); + + // Mouse reset + _AX = 0x0000; // soft & hard reset (0x0021 soft reset does not work) + __int__(0x33); + Exist = (_AX != 0); + Buttons = _BX; + + Goto(SCR_WID/2, SCR_HIG/2); + Z = 127; + Step(1); +} + + + + +MOUSE::~MOUSE (void) +{ + Off(); +} + + + + + +//void MOUSE::SetFun (void) +//{ +//} + + + + + +void MOUSE::On (void) +{ + if (SeqPtr && Exist) + { + _CX = X + X; // horizontal position + _DX = Y; // vertical position + _AX = 0x0004; // Set Mouse Position + __int__(0x33); + // set new mouse fun + _ES = FP_SEG(NewMouseFun); + _DX = FP_OFF(NewMouseFun); + _CX = 0x001F; // 11111b = all events + _AX = 0x0014; // Swap User-Interrupt Vector + __int__(0x33); + // save old mouse fun + OldMouseMask = _CX; + OldMouseFun = (MOUSE_FUN *) MK_FP(_ES, _DX); + + // set X bounds + _DX = (SCR_WID - W) * 2; // right limit + _CX = 0; // left limit + _AX = 0x0007; // note: each pixel = 2 + __int__(0x33); + + // set Y bounds + _DX = SCR_HIG - H; // bottom limit + _CX = 0; // top limit + _AX = 0x0008; + __int__(0x33); + + Step(0); + if (Busy) Busy->Step(0); + } +} + + + + + + +void MOUSE::Off (void) +{ + if (SeqPtr == 0) + { + if (Exist) + { + // bring back old mouse fun + _ES = FP_SEG(OldMouseFun); + _DX = FP_OFF(OldMouseFun); + _CX = OldMouseMask; + _AX = 0x0014; // Swap User-Interrupt Vector + __int__(0x33); + } + Step(1); + if (Busy) Busy->Step(1); + } +} + + + + + + +void MOUSE::ClrEvt (SPRITE * spr) +{ + if (spr) + { + word e; + for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) + if (Evt[e].Ptr == spr) Evt[e].Msk = 0; + } + else EvtTail = EvtHead; +} + + + + + + +void MOUSE::Tick (void) +{ + Step(); + while (EvtTail != EvtHead) + { + EVENT e = Evt[EvtTail]; + if (e.Msk) + { + if (Hold && e.Ptr != Hold) + { + Hold->Touch(e.Msk | ATTN, e.X - Hold->X, e.Y - Hold->Y); + } + + // update mouse cursor position + if (e.Msk & ROLL) + { + Goto(e.X, e.Y); + } + + // activate current touched SPRITE + if (e.Ptr) + { + if (e.Msk & KEYB) e.Ptr->Touch(e.Msk, e.X, e.Y); + else e.Ptr->Touch(e.Msk, e.X - e.Ptr->X, e.Y - e.Ptr->Y); + } + else if (Sys) Sys->Touch(e.Msk, e.X, e.Y); + + if (e.Msk & L_DN) + { + Hold = e.Ptr; + if (Hold) + { + Hold->Flags.Hold = TRUE; + #ifndef DEBUG + if (Hold->Flags.Drag) + #endif + { + hx = e.X - Hold->X; + hy = e.Y - Hold->Y; + } + } + } + + if (e.Msk & L_UP) + { + if (Hold) + { + Hold->Flags.Hold = FALSE; + Hold = NULL; + } + } + ///Touched = e.Ptr; + + // discard Text if button released + if (e.Msk & (L_UP | R_UP)) KillText(); + } + EvtTail = (EvtTail + 1) % EVT_MAX; + } + if (Hold) + #ifndef DEBUG + if (Hold->Flags.Drag) + #endif + Hold->Goto(X-hx, Y-hy); +} + + + +//-------------------------------------------------------------------------- + diff --git a/engines/cge/mouse.h b/engines/cge/mouse.h new file mode 100644 index 00000000000..9f51456baf9 --- /dev/null +++ b/engines/cge/mouse.h @@ -0,0 +1,58 @@ +#ifndef __MOUSE__ +#define __MOUSE__ + +#include "game.h" +#include "talk.h" + +#define EVT_MAX 256 + +#define ROLL 0x01 +#define L_DN 0x02 +#define L_UP 0x04 +#define R_DN 0x08 +#define R_UP 0x10 +#define ATTN 0x20 +// 0x40 +#define KEYB 0x80 + + +extern TALK * Talk; + +struct EVENT { word Msk; + word X, Y; + SPRITE * Ptr; + }; +extern EVENT Evt[EVT_MAX]; +extern word EvtHead, EvtTail; +typedef void (far MOUSE_FUN) (void); + + + + + +class MOUSE : public SPRITE +{ + static MOUSE_FUN * OldMouseFun; + static MOUSE_FUN NewMouseFun; + static word OldMouseMask; + SPRITE * Hold; + int hx, hy; + //void SetFun (void); + //void ResetFun (void); +public: + Boolean Exist; + int Buttons; + SPRITE * Busy; + //SPRITE * Touched; + MOUSE (BITMAP ** shpl = MC); + ~MOUSE (void); + void On (void); + void Off (void); + static void ClrEvt (SPRITE * spr = NULL); + void Tick (void); +}; + + + + +#endif diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp new file mode 100644 index 00000000000..d6b2528310f --- /dev/null +++ b/engines/cge/snail.cpp @@ -0,0 +1,1280 @@ +#include +#include "sound.h" +#include "snail.h" +#include "vga13h.h" +#include "bitmaps.h" +#include "text.h" +#include "mouse.h" +#include "cge.h" +#include +#include +#include +#include +#include + +#include "keybd.h" + + int MaxCave = 0; + + SCB Scb = { NULL, 0, NULL }; + Boolean Flag[4]; + Boolean Dark = FALSE; + Boolean Game = FALSE; + int Now = 1; + int Lev = -1; + SNAIL Snail = FALSE; + SNAIL Snail_ = TRUE; + +extern SPRITE PocLight; + +//------------------------------------------------------------------------- +// SPRITE * Pocket[POCKET_NX]={ NULL, NULL, NULL, NULL, +// NULL, NULL, NULL, NULL, }; +// int PocPtr = 0; +//------------------------------------------------------------------------- +extern SPRITE * Pocket[]; +extern int PocPtr; +//------------------------------------------------------------------------- + +extern DAC far * SysPal; +extern MOUSE Mouse; + + + +//------------------------------------------------------------------------- + + +static void SNGame (SPRITE * spr, int num) +{ + switch (num) + { + //-------------------------------------------------------------------- + case 1 : + { + #define STAGES 8 + #define DRESSED 3 + static SPRITE * dup[3] = { NULL, NULL, NULL }; + int buref; + int Stage; + + for (dup[0] = VGA::ShowQ.First(); dup[0]; dup[0] = dup[0]->Next) + { + buref = dup[0]->Ref; + if (buref / 1000 == 16 && buref % 100 == 6) + { + Stage = (buref / 100) % 10; + break; + } + } + if (dup[1] == NULL) + { + dup[1] = VGA::ShowQ.Locate(16003); // pan + dup[2] = VGA::ShowQ.Locate(16004); // pani + } + + if (Game) // continue game + { + int i = random(3), hand = (dup[0]->ShpCnt == 6); + ++ Stage; + if (hand && Stage > DRESSED) ++ hand; + if ( + Debug( i >= 0 || ) + dup[i] == spr && random(3) == 0) + { + SNPOST(SNSEQ, -1, 3, dup[0]); // yes + SNPOST(SNSEQ, -1, 3, dup[1]); // yes + SNPOST(SNSEQ, -1, 3, dup[2]); // yes + SNPOST(SNTNEXT, -1, 0, dup[0]); // reset Take + SNPOST(SNTNEXT, -1, 0, dup[1]); // reset Take + SNPOST(SNTNEXT, -1, 0, dup[2]); // reset Take + SNPOST(SNNNEXT, -1, 0, dup[0]); // reset Near + SNPOST(SNPAUSE, -1, 72, NULL); // little rest + SNPOST(SNSAY, 1, 16009, NULL); // hura + SNPOST(SNSAY, buref, 16010, NULL); // siadaj + SNPOST(SNSAY, 1, 16011, NULL); // postoj‘ + + if (hand) + { + SNPOST(SNSEND, 16060+hand, 16, NULL); // dawaj r‘k‘ + SNPOST(SNSEQ, buref, 4, NULL); // zdejmowanie + SNPOST(SNSEQ, 16060+hand, 1, NULL); // ruch + SNPOST(SNSOUND, 16060+hand, 16002, NULL); // szelest + SNPOST(SNWAIT, 16060+hand, 3, NULL); // podniesie + SNPOST(SNSWAP, buref, buref+100, NULL); // rozdziana + SNPOST(SNSEQ, 16016, Stage, NULL); // rožnie kupa + SNPOST(SNSEND, 16060+hand, -1, NULL); // chowaj r‘k‘ + SNPOST(SNWAIT, 16060+hand, -1, NULL); // r‘ka zamar’a + } + else + { + SNPOST(SNSEQ, buref, 4, NULL); // zdejmowanie + SNPOST(SNSOUND, 16060+hand, 16002, NULL); // szelest + SNPOST(SNWAIT, buref, -1, NULL); // zdejmie + SNPOST(SNSWAP, buref, buref+100, NULL); // rozdziana + SNPOST(SNSEQ, 16016, Stage, NULL); // rožnie kupa + } + //SNPOST(SNSEQ, buref+100, 0, NULL); // reset + SNPOST(SNPAUSE, -1, 72, NULL); // chwilk‘... + + SNPOST(SNSEQ, -1, 0, dup[1]); // odstaw Go + SNPOST(SNSETXY, -1, 203 + SCR_WID * 49, dup[1]); + SNPOST(SNSETZ, -1, 7, dup[1]); + + SNPOST(SNSEQ, -1, 0, dup[2]); // odstaw J† + SNPOST(SNSETXY, -1, 182 + SCR_WID * 62, dup[2]); + SNPOST(SNSETZ, -1, 9, dup[2]); + Game = 0; + return; + } + else + { + SNPOST(SNSEQ, -1, 2, dup[0]); // no + SNPOST(SNSEQ, -1, 2, dup[1]); // no + SNPOST(SNSEQ, -1, 2, dup[2]); // no + SNPOST(SNPAUSE, -1, 72, NULL); // 1 sec + } + } + SNPOST(SNWALK, 198, 134, NULL); // na miejsce + SNPOST(SNWAIT, 1, -1, NULL); // stoi + SNPOST(SNCOVER, 1, 16101, NULL); // ch’op do bicia + SNPOST(SNSEQ, 16101, 1, NULL); // wystaw + SNPOST(SNWAIT, 16101, 5, NULL); // czekaj + SNPOST(SNPAUSE, 16101, 24, NULL); // czekaj chwil‘ + SNPOST(SNSEQ, 16040, 1, NULL); // plask + SNPOST(SNSOUND, 16101, 16001, NULL); // plask! + SNPOST(SNPAUSE, 16101, 24, NULL); // czekaj chwil‘ + SNPOST(SNSEQ, 16040, 0, NULL); // schowaj plask + SNPOST(SNWAIT, 16101, -1, NULL); // stoi + SNPOST(SNUNCOVER, 1, 16101, NULL); // SDS + if (! Game) + { + SNPOST(SNSAY, buref, 16008, NULL); // zgadnij! + Game = TRUE; + } + #undef STEPS + #undef DRESSED + } break; + //-------------------------------------------------------------------- + case 2 : + { + static SPRITE * k = NULL, * k1, * k2, * k3; + static int count = 0; + Boolean hit; + + if (k == NULL) + { + k = VGA::ShowQ.Locate(20700); + k1 = VGA::ShowQ.Locate(20701); + k2 = VGA::ShowQ.Locate(20702); + k3 = VGA::ShowQ.Locate(20703); + } + + if (! Game) // init + { + SNPOST(SNGAME, 20002, 2, NULL); + Game = TRUE; + } + else // cont + { + k1->Step(random(6)); + k2->Step(random(6)); + k3->Step(random(6)); + ///-------------------- + if (spr->Ref == 1 && KEYBOARD::Key[ALT]) + { + k1->Step(5); + k2->Step(5); + k3->Step(5); + } + ///-------------------- + SNPOST(SNSETZ, 20700, 0, NULL); + hit = (k1->SeqPtr + k2->SeqPtr + k3->SeqPtr == 15); + if (hit) + { + if (spr->Ref == 1) + { + SNPOST(SNSAY, 1, 20003, NULL); // hura! + SNPOST(SNSEQ, 20011, 2, NULL); // kamera won + SNPOST(SNSEND, 20701, -1, NULL); // k1 won + SNPOST(SNSEND, 20702, -1, NULL); // k2 won + SNPOST(SNSEND, 20703, -1, NULL); // k3 won + SNPOST(SNSEND, 20700, -1, NULL); // tv won + SNPOST(SNKEEP, 20007, 0, NULL); // do kieszeni + SNPOST(SNSEND, 20006, 20, NULL); // bilon + SNPOST(SNSOUND,20006, 20002, NULL); // bilon! + SNPOST(SNSAY, 20002, 20004, NULL); + SNPOST(SNSEND, 20010, 20, NULL); // papier + SNPOST(SNSOUND,20010, 20003, NULL); // papier! + SNPOST(SNSAY, 20001, 20005, NULL); + Game = FALSE; + return; + } + else k3->Step(random(5)); + } + if (count < 100) + { + switch (count) + { + case 15 : SNPOST(SNSAY, 20003, 20021, NULL); break; + case 30 : + case 45 : + case 60 : + case 75 : SNPOST(SNSAY, 20003, 20022, NULL); break; + } + ++ count; + } + switch (spr->Ref) + { + case 1 : SNPOST(SNSAY, 20001, 20011, NULL); // zapro + SNPOST(SNSEQ, 20001, 1, NULL); // rzu + SNPOST(SNWAIT, 20001, 1, NULL); // czekaj + SNPOST(SNSETZ, 20700, 2, NULL); // skryj k + SNPOST(SNHIDE, 20007, 1, NULL); // skryj k + SNPOST(SNWAIT, 20001, 16, NULL); // czekaj + SNPOST(SNSEQ, 20007, 1, NULL); // lec† + SNPOST(SNHIDE, 20007, 0, NULL); // poka§ + SNPOST(SNSOUND,20007, 20001, NULL); // grzech + SNPOST(SNWAIT, 20007, -1, NULL); // koniec + SNPOST(SNGAME, 20001, 2, NULL); // again! + break; + case 20001 : SNPOST(SNSAY, 20002, 20012, NULL); // zapro + SNPOST(SNSEQ, 20002, 1, NULL); // rzu + SNPOST(SNWAIT, 20002, 3, NULL); // czekaj + SNPOST(SNSETZ, 20700, 2, NULL); // skryj k + SNPOST(SNHIDE, 20007, 1, NULL); // skryj k + SNPOST(SNWAIT, 20002, 10, NULL); // czekaj + SNPOST(SNSEQ, 20007, 2, NULL); // lec† + SNPOST(SNHIDE, 20007, 0, NULL); // poka§ + SNPOST(SNSOUND,20007, 20001, NULL); // grzech + SNPOST(SNWAIT, 20007, -1, NULL); // koniec + SNPOST(SNGAME, 20002, 2, NULL); // again! + break; + case 20002 : SNPOST(SNSAY, 20002, 20010, NULL); // zapro + SNPOST(SNWALK, 20005, -1, NULL); // do stol + SNPOST(SNWAIT, 1, -1, NULL); // stoi + SNPOST(SNCOVER, 1, 20101, NULL); // grasol + SNPOST(SNSEQ, 20101, 1, NULL); // rzu + SNPOST(SNWAIT, 20101, 5, NULL); // czekaj + SNPOST(SNSETZ, 20700, 2, NULL); // skryj k + SNPOST(SNHIDE, 20007, 1, NULL); // skryj k + SNPOST(SNWAIT, 20101, 15, NULL); // czekaj + SNPOST(SNSEQ, 20007, 1, NULL); // lec† + SNPOST(SNHIDE, 20007, 0, NULL); // poka§ + SNPOST(SNSOUND,20007, 20001, NULL); // grzech + SNPOST(SNWAIT, 20101, -1, NULL); // koniec + SNPOST(SNUNCOVER, 1, 20101, NULL); // SDS + SNPOST(SNGAME, 1, 2, NULL); // again! + break; + } + } + } break; + //-------------------------------------------------------------------- + } +} + + +//------------------------------------------------------------------------- + + + + +void ExpandSprite (SPRITE * spr) +{ + if (spr) VGA::ShowQ.Insert(VGA::SpareQ.Remove(spr)); +} + + + + + +void ContractSprite (SPRITE * spr) +{ + if (spr) VGA::SpareQ.Append(VGA::ShowQ.Remove(spr)); +} + + + + + + + +int FindPocket (SPRITE * spr) +{ + int i; + for (i = 0; i < POCKET_NX; i ++) if (Pocket[i] == spr) return i; + return -1; +} + + + + + +void SelectPocket (int n) +{ + if (n < 0 || (PocLight.SeqPtr && PocPtr == n)) + { + PocLight.Step(0); + n = FindPocket(NULL); + if (n >= 0) PocPtr = n; + } + else + { + if (Pocket[n] != NULL) + { + PocPtr = n; + PocLight.Step(1); + } + } + PocLight.Goto(POCKET_X+PocPtr*POCKET_DX+POCKET_SX, POCKET_Y+POCKET_SY); +} + + + + + +void PocFul (void) +{ + Hero->Park(); + SNPOST(SNWAIT, -1, -1, Hero); + SNPOST(SNSEQ, -1, POC_FUL, Hero); + SNPOST(SNSOUND, -1, 2, Hero); + SNPOST(SNWAIT, -1, -1, Hero); + SNPOST(SNSAY, 1, POC_FUL_TEXT, Hero); +} + + + + +void Hide1 (SPRITE * spr) +{ + SNPOST_(SNGHOST, -1, 0, spr->Ghost()); +} + + + + +void SNGhost (BITMAP * bmp) +{ + bmp->Hide(FP_OFF(bmp->M), FP_SEG(bmp->M)); + bmp->M = NULL; + delete bmp; +} + + + + +void FeedSnail (SPRITE * spr, SNLIST snq) +{ + if (spr) if (spr->Active()) + { + byte ptr = (snq == TAKE) ? spr->TakePtr : spr->NearPtr; + + if (ptr != NO_PTR) + { + SNAIL::COM * comtab = spr->SnList(snq); + SNAIL::COM * c = comtab + ptr; + + if (FindPocket(NULL) < 0) // no empty pockets? + { + SNAIL::COM * p; + for (p = c; p->Com != SNNEXT; p ++) // find KEEP command + { + if (p->Com == SNKEEP) + { + PocFul(); + return; + } + if (p->Ptr) break; + } + } + while (TRUE) + { + if (c->Com == SNTALK) + { + if ((Snail.TalkEnable = (c->Val != 0)) == FALSE) KillText(); + } + if (c->Com == SNNEXT) + { + SPRITE * s = (c->Ref < 0) ? spr : Locate(c->Ref); + if (s) + { + byte * idx = (snq == TAKE) ? &s->TakePtr : &s->NearPtr; + if (*idx != NO_PTR) + { + int v; + switch (c->Val) + { + case -1 : v = c - comtab + 1; break; + case -2 : v = c - comtab; break; + case -3 : v = -1; break; + default : v = c->Val; break; + } + if (v >= 0) *idx = v; + } + } + if (s == spr) break; + } + if (c->Com == SNIF) + { + SPRITE * s = (c->Ref < 0) ? spr : Locate(c->Ref); + if (s) // sprite extsts + { + if (! s->SeqTest(-1)) c = comtab + c->Val; // not parked + else ++ c; + } + else ++ c; + } + else + { + SNPOST(c->Com, c->Ref, c->Val, spr); + if (c->Ptr) break; + else ++ c; + } + } + } + } +} + + + + + + +//-------------------------------------------------------------------------- + +char * SNAIL::ComTxt[] = { "LABEL", "PAUSE", "WAIT", "LEVEL", + "HIDE", "SAY", "INF", "TIME", + "CAVE", "KILL", "RSEQ", + "SEQ", "SEND", "SWAP", "KEEP", "GIVE", + "IF", "GAME", "SETX0", "SETY0", "SLAVE", + "SETXY", "RELX", "RELY", "RELZ", + "SETX", "SETY", "SETZ", "TRANS", "PORT", + "NEXT","NNEXT", "TNEXT", "RNNEXT", "RTNEXT", + "RMNEAR", "RMTAKE", "FLAG", "SETREF", + "BACKPT", "FLASH", "LIGHT", + "SETHB", "SETVB", + "WALK", "REACH", "COVER", "UNCOVER", + "CLEAR", "TALK", "MOUSE", + "SOUND", "COUNT", + NULL }; + + + +SNAIL::SNAIL (Boolean turbo) +: Turbo(turbo), Busy(FALSE), TextDelay(FALSE), + Pause(0), TalkEnable(TRUE), + Head(0), Tail(0), SNList(farnew(COM, 256)) +{ +} + + + + + + +SNAIL::~SNAIL (void) +{ + if (SNList) farfree(SNList); +} + + + + + + +void SNAIL::AddCom (SNCOM com, int ref, int val, void * ptr) +{ + _disable(); + COM far * snc = &SNList[Head ++]; + snc->Com = com; + snc->Ref = ref; + snc->Val = val; + snc->Ptr = ptr; + if (com == SNCLEAR) + { + Tail = Head; + KillText(); + Pause = 0; + } + _enable(); +} + + + + +void SNAIL::InsCom (SNCOM com, int ref, int val, void * ptr) +{ + COM far * snc; + + _disable(); + if (Busy) + { + SNList[(Tail-1)&0xFF] = SNList[Tail]; + snc = &SNList[Tail]; + } + else snc = &SNList[(Tail-1)&0xFF]; + -- Tail; + snc->Com = com; + snc->Ref = ref; + snc->Val = val; + snc->Ptr = ptr; + if (com == SNCLEAR) + { + Tail = Head; + KillText(); + Pause = 0; + } + _enable(); +} + + + + + + + +static void SNNNext(SPRITE * sprel, int p) +{ + if (sprel) if (sprel->NearPtr != NO_PTR) sprel->NearPtr = p; +} + + + + + + +static void SNTNext(SPRITE * sprel, int p) +{ + if (sprel) if (sprel->TakePtr != NO_PTR) sprel->TakePtr = p; +} + + + + + + +static void SNRNNext(SPRITE * sprel, int p) +{ + if (sprel) if (sprel->NearPtr != NO_PTR) sprel->NearPtr += p; +} + + + + + + +static void SNRTNext(SPRITE * sprel, int p) +{ + if (sprel) if (sprel->TakePtr != NO_PTR) sprel->TakePtr += p; +} + + + + + + +static void SNZTrim (SPRITE * spr) +{ + if (spr) if (spr->Active()) + { + Boolean en = HEART::Enable; + SPRITE * s; + HEART::Enable = FALSE; + s = (spr->Flags.Shad) ? spr->Prev : NULL; + VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr)); + if (s) + { + s->Z = spr->Z; + VGA::ShowQ.Insert(VGA::ShowQ.Remove(s), spr); + } + HEART::Enable = en; + } +} + + + + + + +static void SNHide (SPRITE * spr, int val) +{ + if (spr) + { + spr->Flags.Hide = (val >= 0) ? (val != 0) : (! spr->Flags.Hide); + if (spr->Flags.Shad) spr->Prev->Flags.Hide = spr->Flags.Hide; + } +} + + + + + +static void SNRmNear (SPRITE * spr) +{ + if (spr) spr->NearPtr = NO_PTR; +} + + + + + +static void SNRmTake (SPRITE * spr) +{ + if (spr) spr->TakePtr = NO_PTR; +} + + + + + +void SNSeq (SPRITE * spr, int val) +{ + if (spr) + { + if (spr == Hero && val == 0) Hero->Park(); + else spr->Step(val); + } +} + + + + + +void SNRSeq (SPRITE * spr, int val) +{ + if (spr) SNSeq(spr, spr->SeqPtr + val); +} + + + + + +void SNSend (SPRITE * spr, int val) +{ + if (spr) + { + int was = spr->Cave; + Boolean was1 = (was == 0 || was == Now); + Boolean val1 = (val == 0 || val == Now); + spr->Cave = val; + if (val1 != was1) + { + if (was1) + { + if (spr->Flags.Kept) + { + int n = FindPocket(spr); + if (n >= 0) Pocket[n] = NULL; + } + Hide1(spr); + ContractSprite(spr); + spr->Flags.Slav = FALSE; + } + else + { + if (spr->Ref % 1000 == 0) BITMAP::Pal = SysPal; + if (spr->Flags.Back) spr->BackShow(TRUE); + else ExpandSprite(spr); + BITMAP::Pal = NULL; + } + } + } +} + + + + + +void SNSwap (SPRITE * spr, int xref) +{ + SPRITE * xspr = Locate(xref); + if (spr && xspr) + { + int was = spr->Cave; + int xwas = xspr->Cave; + Boolean was1 = (was == 0 || was == Now); + Boolean xwas1 = (xwas == 0 || xwas == Now); + + Swap(spr->Cave, xspr->Cave); + Swap(spr->X, xspr->X); + Swap(spr->Y, xspr->Y); + Swap(spr->Z, xspr->Z); + if (spr->Flags.Kept) + { + int n = FindPocket(spr); + if (n >= 0) Pocket[n] = xspr; + xspr->Flags.Kept = TRUE; + xspr->Flags.Port = FALSE; + } + if (xwas1 != was1) + { + if (was1) + { + Hide1(spr); + ContractSprite(spr); + } + else ExpandSprite(spr); + if (xwas1) + { + Hide1(xspr); + ContractSprite(xspr); + } + else ExpandSprite(xspr); + } + } +} + + + + + +void SNCover (SPRITE * spr, int xref) +{ + SPRITE * xspr = Locate(xref); + if (spr && xspr) + { + spr->Flags.Hide = TRUE; + xspr->Z = spr->Z; + xspr->Cave = spr->Cave; + xspr->Goto(spr->X, spr->Y); + ExpandSprite(xspr); + if ((xspr->Flags.Shad = spr->Flags.Shad) == TRUE) + { + VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr->Prev), xspr); + spr->Flags.Shad = FALSE; + } + FeedSnail(xspr, NEAR); + } +} + + + + + +void SNUncover (SPRITE * spr, SPRITE * xspr) +{ + if (spr && xspr) + { + spr->Flags.Hide = FALSE; + spr->Cave = xspr->Cave; + spr->Goto(xspr->X, xspr->Y); + if ((spr->Flags.Shad = xspr->Flags.Shad) == TRUE) + { + VGA::ShowQ.Insert(VGA::ShowQ.Remove(xspr->Prev), spr); + xspr->Flags.Shad = FALSE; + } + spr->Z = xspr->Z; + SNSend(xspr, -1); + if (spr->Time == 0) ++ spr->Time; + } +} + + + + + +void SNSetX0 (int cav, int x0) +{ + HeroXY[cav-1].X = x0; +} + + + + + +void SNSetY0 (int cav, int y0) +{ + HeroXY[cav-1].Y = y0; +} + + + + + +void SNSetXY (SPRITE * spr, word xy) +{ + if (spr) + { + spr->Goto(xy % SCR_WID, xy / SCR_WID); + } +} + + + + + +void SNRelX (SPRITE * spr, int x) +{ + if (spr && Hero) + { + spr->Goto(Hero->X + x, spr->Y); + } +} + + + + + +void SNRelY (SPRITE * spr, int y) +{ + if (spr && Hero) + { + spr->Goto(spr->X, Hero->Y + y); + } +} + + + + + +void SNRelZ (SPRITE * spr, int z) +{ + if (spr && Hero) + { + spr->Z = Hero->Z + z; + SNZTrim(spr); + } +} + + + + + +void SNSetX (SPRITE * spr, int x) +{ + if (spr) + { + spr->Goto(x, spr->Y); + } +} + + + + + +void SNSetY (SPRITE * spr, int y) +{ + if (spr) + { + spr->Goto(spr->X, y); + } +} + + + + + +void SNSetZ (SPRITE * spr, int z) +{ + if (spr) + { + spr->Z = z; + //SNPOST_(SNZTRIM, -1, 0, spr); + SNZTrim(spr); + } +} + + + + + +void SNSlave (SPRITE * spr, int ref) +{ + SPRITE * slv = Locate(ref); + if (spr && slv) + { + if (spr->Active()) + { + SNSend(slv, spr->Cave); + slv->Flags.Slav = TRUE; + slv->Z = spr->Z; + VGA::ShowQ.Insert(VGA::ShowQ.Remove(slv), spr->Next); + } + } +} + + + + + +void SNTrans (SPRITE * spr, int trans) +{ + if (spr) + { + spr->Flags.Tran = (trans < 0) ? !spr->Flags.Tran : (trans != 0); + } +} + + + + + +void SNPort (SPRITE * spr, int port) +{ + if (spr) + { + spr->Flags.Port = (port < 0) ? !spr->Flags.Port : (port != 0); + } +} + + + + + +void SNKill (SPRITE * spr) +{ + if (spr) + { + if (spr->Flags.Kept) + { + int n = FindPocket(spr); + if (n >= 0) Pocket[n] = NULL; + } + SPRITE * nx = spr->Next; + Hide1(spr); + VGA::ShowQ.Remove(spr); + MOUSE::ClrEvt(spr); + if (spr->Flags.Kill) delete spr; + else + { + spr->Cave = -1; + VGA::SpareQ.Append(spr); + } + if (nx) if (nx->Flags.Slav) SNKill(nx); + } +} + + + + + +static void SNSound (SPRITE * spr, int wav, int cnt) +{ + if (SNDDrvInfo.DDEV) + { + if (wav == -1) Sound.Stop(); + else + Sound.Play(Fx[wav], (spr) ? ((spr->X+spr->W/2)/(SCR_WID/16)) : 8, cnt); + } +} + + + + + +void SNKeep (SPRITE * spr, int stp) +{ + SelectPocket(-1); + if (spr && ! spr->Flags.Kept && Pocket[PocPtr] == NULL) + { + SNSound(spr, 3, 1); + Pocket[PocPtr] = spr; + spr->Cave = 0; + spr->Flags.Kept = TRUE; + spr->Goto(POCKET_X + POCKET_DX*PocPtr + POCKET_DX/2 - spr->W/2, + POCKET_Y + POCKET_DY/2 - spr->H/2); + if (stp >= 0) spr->Step(stp); + } + SelectPocket(-1); +} + + + + + + +void SNGive (SPRITE * spr, int stp) +{ + if (spr) + { + int p = FindPocket(spr); + if (p >= 0) + { + Pocket[p] = NULL; + spr->Cave = Now; + spr->Flags.Kept = FALSE; + if (stp >= 0) spr->Step(stp); + } + } + SelectPocket(-1); +} + + + + +static void SNBackPt (SPRITE * spr, int stp) +{ + if (spr) + { + if (stp >= 0) spr->Step(stp); + spr->BackShow(TRUE); + } +} + + + + + +static void SNLevel (SPRITE * spr, int lev) +{ + #ifdef DEMO + static int maxcav[] = { CAVE_MAX }; + #else + static int maxcav[] = { 1, 8, 16, 23, 24 }; + #endif + while (Lev < lev) + { + SPRITE * spr; + ++ Lev; + spr = VGA::SpareQ.Locate(100+Lev); + if (spr) + { + spr->BackShow(TRUE); + spr->Cave = 0; + } + } + MaxCave = maxcav[Lev]; + if (spr) spr->Flags.Hide = FALSE; +} + + + + + + +static void SNFlag (int fn, Boolean v) +{ + Flag[fn] = v; +} + + + + + + +static void SNSetRef (SPRITE * spr, int nr) +{ + if (spr) + { + spr->Ref = nr; + } +} + + + + +void SNFlash (Boolean on) +{ + if (on) + { + DAC far * pal = farnew(DAC, PAL_CNT); + if (pal) + { + int i; + _fmemcpy(pal, SysPal, PAL_SIZ); + for (i = 0; i < PAL_CNT; i ++) + { + register int c; + c = pal[i].R << 1; pal[i].R = (c < 64) ? c : 63; + c = pal[i].G << 1; pal[i].G = (c < 64) ? c : 63; + c = pal[i].B << 1; pal[i].B = (c < 64) ? c : 63; + } + VGA::SetColors(pal, 64); + } + } + else VGA::SetColors(SysPal, 64); + Dark = FALSE; +} + + + + + +static void SNLight (Boolean in) +{ + if (in) VGA::Sunrise(SysPal); + else VGA::Sunset(); + Dark = ! in; +} + + + + + +static void SNBarrier (int cav, int bar, Boolean horz) +{ + ((byte *) (Barriers + ((cav > 0) ? cav : Now)))[horz] = bar; +} + + + + + +static void SNWalk (SPRITE * spr, int x, int y) +{ + if (Hero) + { + if (spr && y < 0) Hero->FindWay(spr); + else Hero->FindWay(XZ(x, y)); + } +} + + + + + +static void SNReach (SPRITE * spr, int mode) +{ + if (Hero) Hero->Reach(spr, mode); +} + + + + + + +static void SNMouse (Boolean on) +{ + if (on) Mouse.On(); + else Mouse.Off(); +} + + + + + + +void SNAIL::RunCom (void) +{ + static int count = 1; + extern void SwitchCave(int); + if (! Busy) + { + Busy = TRUE; + byte tmphea = Head; + while (Tail != tmphea) + { + COM far * snc = &SNList[Tail]; + + if (! Turbo) // only for the slower one + { + if (Pause) break; + else + { + if (TextDelay) + { + KillText(); + TextDelay = FALSE; + } + } + if (Talk && snc->Com != SNPAUSE) break; + } + + SPRITE * sprel = ((snc->Ref >= 0) ? Locate(snc->Ref) + : ((SPRITE *) snc->Ptr)); + switch (snc->Com) + { + case SNLABEL : break; + case SNPAUSE : HEART::SetXTimer(&Pause, snc->Val); + if (Talk) TextDelay = TRUE; break; + case SNWAIT : if (sprel) + { + if (sprel->SeqTest(snc->Val) && + (snc->Val >= 0 || sprel != Hero || Hero->TracePtr < 0)) + { + HEART::SetXTimer(&Pause, sprel->Time); + } + else goto xit; + } + break; + case SNLEVEL : SNLevel(sprel, snc->Val); break; + case SNHIDE : SNHide(sprel, snc->Val); break; + case SNSAY : if (sprel && TalkEnable) + { + if (sprel == Hero && sprel->SeqTest(-1)) + sprel->Step(HTALK); + Say(Text[snc->Val], sprel); + SYSTEM::FunDel = HEROFUN0; + } + break; + case SNINF : if (TalkEnable) + { + Inf(Text[snc->Val]); + SYSTEM::FunDel = HEROFUN0; + } + break; + case SNTIME : if (sprel && TalkEnable) + { + if (sprel == Hero && sprel->SeqTest(-1)) + sprel->Step(HTALK); + SayTime(sprel); + } + break; + case SNCAVE : SwitchCave(snc->Val); break; + case SNKILL : SNKill(sprel); break; + case SNSEQ : SNSeq(sprel, snc->Val); break; + case SNRSEQ : SNRSeq(sprel, snc->Val); break; + case SNSEND : SNSend(sprel, snc->Val); break; + case SNSWAP : SNSwap(sprel, snc->Val); break; + case SNCOVER : SNCover(sprel, snc->Val); break; + case SNUNCOVER : SNUncover(sprel, (snc->Val >= 0) ? Locate(snc->Val) + : ((SPRITE *) snc->Ptr)); + break; + case SNKEEP : SNKeep(sprel, snc->Val); break; + case SNGIVE : SNGive(sprel, snc->Val); break; + case SNGAME : SNGame(sprel, snc->Val); break; + case SNSETX0 : SNSetX0(snc->Ref, snc->Val); break; + case SNSETY0 : SNSetY0(snc->Ref, snc->Val); break; + case SNSETXY : SNSetXY(sprel, snc->Val); break; + case SNRELX : SNRelX(sprel, snc->Val); break; + case SNRELY : SNRelY(sprel, snc->Val); break; + case SNRELZ : SNRelZ(sprel, snc->Val); break; + case SNSETX : SNSetX(sprel, snc->Val); break; + case SNSETY : SNSetY(sprel, snc->Val); break; + case SNSETZ : SNSetZ(sprel, snc->Val); break; + case SNSLAVE : SNSlave(sprel, snc->Val); break; + case SNTRANS : SNTrans(sprel, snc->Val); break; + case SNPORT : SNPort(sprel, snc->Val); break; + case SNNEXT : break; + case SNIF : break; + case SNTALK : break; + case SNMOUSE : SNMouse(snc->Val != 0); break; + case SNNNEXT : SNNNext(sprel, snc->Val); break; + case SNTNEXT : SNTNext(sprel, snc->Val); break; + case SNRNNEXT : SNRNNext(sprel, snc->Val); break; + case SNRTNEXT : SNRTNext(sprel, snc->Val); break; + case SNRMNEAR : SNRmNear(sprel); break; + case SNRMTAKE : SNRmTake(sprel); break; + case SNFLAG : SNFlag(snc->Ref & 3, snc->Val != 0); break; + case SNSETREF : SNSetRef(sprel, snc->Val); break; + case SNBACKPT : SNBackPt(sprel, snc->Val); break; + case SNFLASH : SNFlash(snc->Val != 0); break; + case SNLIGHT : SNLight(snc->Val != 0); break; + case SNSETHB : SNBarrier(snc->Ref, snc->Val, TRUE); break; + case SNSETVB : SNBarrier(snc->Ref, snc->Val, FALSE); break; + case SNWALK : SNWalk(sprel, snc->Ref, snc->Val); break; + case SNREACH : SNReach(sprel, snc->Val); break; + case SNSOUND : SNSound(sprel, snc->Val, count); count = 1; break; + case SNCOUNT : count = snc->Val; break; + + case SNEXEC : ((void(*)(int)) (snc->Ptr))(snc->Val); break; + case SNSTEP : sprel->Step(); break; + case SNZTRIM : SNZTrim(sprel); break; + case SNGHOST : SNGhost((BITMAP *) snc->Ptr); break; + } + ++ Tail; + if (! Turbo) break; + } + xit: + Busy = FALSE; + } +} + + + + + +Boolean SNAIL::Idle (void) +{ + return (Head == Tail); +} diff --git a/engines/cge/snail.h b/engines/cge/snail.h new file mode 100644 index 00000000000..f1b0ab762f5 --- /dev/null +++ b/engines/cge/snail.h @@ -0,0 +1,98 @@ +#ifndef __SNAIL__ +#define __SNAIL__ + +#include + +#define POCKET_X 174 +#define POCKET_Y 176 +#define POCKET_DX 18 +#define POCKET_DY 22 +#define POCKET_NX 8 +#define POCKET_NY 1 + +#define POCKET_SX 8 +#define POCKET_SY 3 + +#define SNINSERT(c,r,v,p) Snail.InsCom(c,r,v,p) +#define SNPOST(c,r,v,p) Snail.AddCom(c,r,v,p) +#define SNPOST_(c,r,v,p) Snail_.AddCom(c,r,v,p) + + + +typedef struct { byte Horz, Vert; } BAR; + + + +struct SCB +{ + byte far * Ptr; + word Siz; + SCB * Nxt; +}; + + + +enum SNCOM { SNLABEL, SNPAUSE, SNWAIT, SNLEVEL, + SNHIDE, SNSAY, SNINF, SNTIME, + SNCAVE, SNKILL, SNRSEQ, + SNSEQ, SNSEND, SNSWAP, SNKEEP, SNGIVE, + SNIF, SNGAME, SNSETX0, SNSETY0, SNSLAVE, + SNSETXY, SNRELX, SNRELY, SNRELZ, + SNSETX, SNSETY, SNSETZ, SNTRANS, SNPORT, + SNNEXT, SNNNEXT, SNTNEXT, SNRNNEXT, SNRTNEXT, + SNRMNEAR, SNRMTAKE, SNFLAG, SNSETREF, + SNBACKPT, SNFLASH, SNLIGHT, + SNSETHB, SNSETVB, + SNWALK, SNREACH, SNCOVER, SNUNCOVER, + SNCLEAR, SNTALK, SNMOUSE, + SNSOUND, SNCOUNT, + SNEXEC, SNSTEP, SNZTRIM, + SNGHOST + }; + +enum SNLIST { NEAR, TAKE }; + +class SNAIL +{ + struct COM { SNCOM Com; int Ref; int Val; void * Ptr; } far * SNList; + byte Head, Tail; + Boolean Turbo, Busy, TextDelay; + word Pause; +public: + static char * ComTxt[]; + Boolean TalkEnable; + SNAIL (Boolean turbo = FALSE); + ~SNAIL (void); + void RunCom (void); + void AddCom (SNCOM com, int ref = 0, int val = 0, void * ptr = NULL); + void InsCom (SNCOM com, int ref = 0, int val = 0, void * ptr = NULL); + Boolean Idle (void); +}; + + + + + +void SelectPocket (int n); +void PocFul (void); + + + + + + + +extern SCB Scb; +extern Boolean Flag[4]; +extern Boolean Game; +extern Boolean Dark; +extern SNAIL Snail; +extern SNAIL Snail_; +extern int Now; +extern int Lev; +extern int MaxCave; +extern int PocPtr; +extern BAR Barriers[]; +extern struct HXY { int X; int Y; } HeroXY[]; + +#endif diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h new file mode 100644 index 00000000000..69ea3c2b158 --- /dev/null +++ b/engines/cge/snddrv.h @@ -0,0 +1,104 @@ +// ****************************************************** +// * Sound Driver by Hedges (c) 1995 LK AVALON * +// * Ver 1.00: 01-Mar-95 * +// * Ver 1.10: 03-Mar-95 * +// * Ver 1.20: 07-Mar-95 * +// * Ver 1.30: 09-Mar-95 * +// * Ver 1.40: 11-Mar-95 * +// ****************************************************** + +#ifndef __SNDDRV__ +#define __SNDDRV__ + +// ****************************************************** +// * Constants * +// ****************************************************** +// available devices + +enum DEV_TYPE { DEV_AUTO = -1, // auto-detect mode + DEV_QUIET, // disable sound + DEV_SB, // sb/pro/16/awe32 + DEV_GUS, // gus/max + DEV_GM // general midi + }; + +#define SERR_OK 0 // no error +#define SERR_INITFAIL 1 // couldn't initialize +#define SERR_BADDDEV 128 // bad device + +// driver info +struct DRVINFO +{ + DEV_TYPE DDEV; // digi device + DEV_TYPE MDEV; // midi device + WORD DBASE; // digi base port + WORD DDMA; // digi dma no + WORD DIRQ; // digi irq no + WORD MBASE; // midi base port + union + { + struct + { + WORD DR : 4; + WORD DL : 4; + WORD MR : 4; + WORD ML : 4; + } VOL4; + struct + { + BYTE D; // digi volume + BYTE M; // midi volume + } VOL2; + }; +}; + +// sample info +struct SMPINFO +{ + BYTE far * saddr; // address + WORD slen; // length + WORD span; // left/right pan (0-15) + int sflag; // flag +}; + +// ****************************************************** +// * Data * +// ****************************************************** +// driver info +extern DRVINFO SNDDrvInfo; + +// midi player flag (1 means we are playing) +extern WORD MIDIPlayFlag; + +// midi song end flag (1 means we have crossed end mark) +extern WORD MIDIEndFlag; + +// ****************************************************** +// * Driver Code * +// ****************************************************** +// Init Digi Device +EC void SNDInit (void); + +// Close Digi Device +EC void SNDDone (void); + +// Set Volume +EC void SNDSetVolume (void); + +// Start Digi +EC void SNDDigiStart (SMPINFO *PSmpInfo); + +// Stop Digi +EC void SNDDigiStop (SMPINFO *PSmpInfo); + +// Start MIDI File +EC void SNDMIDIStart (BYTE far *MIDFile); + +// Stop MIDI File +EC void SNDMIDIStop (void); + +// Play MIDI File (to be called while interrupting) +// WARNING: Uses ALL registers! +EC void SNDMIDIPlay (void); + +#endif diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp new file mode 100644 index 00000000000..f4fc27ddd7a --- /dev/null +++ b/engines/cge/sound.cpp @@ -0,0 +1,293 @@ +#include +#include "startup.h" +#include "sound.h" + +#ifdef DROP_H + #include "drop.h" +#else + #include + #include + #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } +#endif + +#include "text.h" +#include +#include "vol.h" +#include + + + Boolean Music = TRUE; + FX Fx = 16; // must precede SOUND!! + SOUND Sound; + + + +SOUND::SOUND (void) +{ + if (STARTUP::SoundOk) Open(); +} + + + + +SOUND::~SOUND (void) +{ + Close(); +} + + + + + +void SOUND::Close (void) +{ + KillMIDI(); + SNDDone(); +} + + + + + +void SOUND::Open (void) +{ + SNDInit(); + Play(Fx[30000], 8); +} + + + + +void SOUND::Play (DATACK * wav, int pan, int cnt) +{ + if (wav) + { + Stop(); + smpinf.saddr = (char far *) &*(wav->EAddr()); + smpinf.slen = (word)wav->Size(); + smpinf.span = pan; + smpinf.sflag = cnt; + SNDDigiStart(&smpinf); + } +} + + + + +void SOUND::Stop (void) +{ + SNDDigiStop(&smpinf); +} + + +//------------------------------------------------------------------------ + + + + + + + + +FX::FX (int size) +: Emm(0L), Current(NULL) +{ + Cache = new HAN[size]; + for (Size = 0; Size < size; Size ++) + { + Cache[Size].Ref = 0; + Cache[Size].Wav = NULL; + } +} + + + + +FX::~FX (void) +{ + Clear(); + delete[] Cache; +} + + + + + +void FX::Clear (void) +{ + HAN * p, * q; + for (p = Cache, q = p+Size; p < q; p ++) + { + if (p->Ref) + { + p->Ref = 0; + delete p->Wav; + p->Wav = NULL; + } + } + Emm.Release(); + Current = NULL; +} + + + + + +int FX::Find (int ref) +{ + HAN * p, * q; + int i = 0; + for (p = Cache, q = p+Size; p < q; p ++) + { + if (p->Ref == ref) break; + else ++ i; + } + return i; +} + + + + + + + + + + + +void FX::Preload (int ref0) +{ + HAN * CacheLim = Cache + Size; + int ref; + + for (ref = ref0; ref < ref0+10; ref ++) + { + static char fname[] = "FX00000.WAV"; + wtom(ref, fname+2, 10, 5); + DATACK * wav = LoadWave(&INI_FILE(fname), &Emm); + if (wav) + { + HAN * p = &Cache[Find(0)]; + if (p >= CacheLim) break; + p->Wav = wav; + p->Ref = ref; + } + } +} + + + + + +DATACK * FX::Load (int idx, int ref) +{ + static char fname[] = "FX00000.WAV"; + wtom(ref, fname+2, 10, 5); + + DATACK * wav = LoadWave(&INI_FILE(fname), &Emm); + if (wav) + { + HAN * p = &Cache[idx]; + p->Wav = wav; + p->Ref = ref; + } + return wav; +} + + + + +DATACK * FX::operator [] (int ref) +{ + int i; + if ((i = Find(ref)) < Size) Current = Cache[i].Wav; + else + { + if ((i = Find(0)) >= Size) + { + Clear(); + i = 0; + } + Current = Load(i, ref); + } + return Current; +} + + + + +//------------------------------------------------------------------------- + + +static byte far * midi = NULL; + + + +void KillMIDI (void) +{ + SNDMIDIStop(); + if (midi) + { + delete[] midi; + midi = NULL; + } +} + + + + + +void LoadMIDI (int ref) +{ + static char fn[] = "00.MID"; + wtom(ref, fn, 10, 2); + if (INI_FILE::Exist(fn)) + { + KillMIDI(); + INI_FILE mid = fn; + if (mid.Error == 0) + { + word siz = (word) mid.Size(); + midi = new far byte[siz]; + if (midi) + { + mid.Read(midi, siz); + if (mid.Error) KillMIDI(); + else + { + SNDMIDIStart(midi); + } + } + } + } +} + + + + + + +EC void far * Patch (int pat) +{ + void far * p = NULL; + static char fn[] = "PATCH000.SND"; + + wtom(pat, fn+5, 10, 3); + INI_FILE snd = fn; + if (! snd.Error) + { + word siz = (word) snd.Size(); + p = (byte far *) farmalloc(siz); + if (p) + { + snd.Read(p, siz); + if (snd.Error) + { + farfree(p); + p = NULL; + } + } + } + return p; +} + diff --git a/engines/cge/sound.h b/engines/cge/sound.h new file mode 100644 index 00000000000..b4efd998087 --- /dev/null +++ b/engines/cge/sound.h @@ -0,0 +1,61 @@ +#ifndef __SOUND__ +#define __SOUND__ + +#include +#include + + +#define BAD_SND_TEXT 97 +#define BAD_MIDI_TEXT 98 + + + + +class SOUND +{ +public: + SMPINFO smpinf; + SOUND (void); + ~SOUND (void); + void Open (void); + void Close (void); + void Play (DATACK * wav, int pan, int cnt = 1); + void Stop (void); +}; + + + + + +class FX +{ + EMM Emm; + struct HAN { int Ref; DATACK * Wav; } * Cache; + int Size; + DATACK * Load (int idx, int ref); + int Find (int ref); +public: + DATACK * Current; + FX (int size = 16); + ~FX (void); + void Clear (void); + void Preload (int ref0); + DATACK * operator[] (int ref); +}; + + + + + + +extern Boolean Music; +extern SOUND Sound; +extern FX Fx; + + +void LoadMIDI (int ref); +void KillMIDI (void); + + +#endif + diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp new file mode 100644 index 00000000000..3557891a036 --- /dev/null +++ b/engines/cge/startup.cpp @@ -0,0 +1,168 @@ +#include "startup.h" +#include "text.h" +#include "sound.h" +#include "ident.h" +#include +#include +#include +#include +#include +#include +#include + +#ifdef DEBUG + #include +#endif + +extern char Copr[]; + +#define id (*(IDENT*)Copr) + + + EMM MiniEmm = MINI_EMM_SIZE; + +static STARTUP StartUp; + + + int STARTUP::Mode = 0; + int STARTUP::Core; + int STARTUP::SoundOk = 0; + word STARTUP::Summa; + + + +void quit_now (int ref) +{ + fputs(Text[ref], stderr); + fputc('\n', stderr); + _exit(1); +} + + + +Boolean STARTUP::get_parms (void) +{ + int i = _argc; + while (i > 1) + { + static char *PrmTab[] = { "NEW", "MK0SVG", "QUIET", "SB", "GUS", "MIDI", + "P", "D", "I", "M" }; + int n = TakeEnum(PrmTab, strtok(_argv[--i], " =:(")); + word p = xtow(strtok(NULL, " h,)")); + switch (n) + { + case 0 : if (Mode != 2) Mode = 1; break; + case 1 : Mode = 2; break; + case 2 : SNDDrvInfo.DDEV = DEV_QUIET; break; + case 3 : SNDDrvInfo.DDEV = DEV_SB; break; + case 4 : SNDDrvInfo.DDEV = DEV_GUS; break; + case 5 : SNDDrvInfo.MDEV = DEV_GM; break; + case 6 : SNDDrvInfo.DBASE = p; break; + case 7 : SNDDrvInfo.DDMA = p; break; + case 8 : SNDDrvInfo.DIRQ = p; break; + case 9 : SNDDrvInfo.MBASE = p; + SNDDrvInfo.MDEV = DEV_GM; break; + default: return FALSE; + } + if (n >= 2) SoundOk = 2; + } + #ifdef DEMO + // protection disabled + Summa = 0; + #else + #ifdef EVA + { + union { dosdate_t d; dword n; } today; + _dos_getdate(&today.d); + id.disk += (id.disk < today.n); + } + #endif + #ifdef CD + Summa = 0; + #else + // disk signature checksum + Summa = ChkSum(Copr, sizeof(IDENT)); + #endif + #endif + if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; + return TRUE; +} + + + + +STARTUP::STARTUP (void) +{ + dword m = farcoreleft() >> 10; + if (m < 0x7FFF) Core = (int) m; else Core = 0x7FFF; + + if (! IsVga()) quit_now(NOT_VGA_TEXT); + if (Cpu() < _80286) quit_now(BAD_CHIP_TEXT); + if (100 * _osmajor + _osminor < 330) quit_now(BAD_DOS_TEXT); + + #ifndef DEBUG + if (Core < CORE_LOW) quit_now(NO_CORE_TEXT); + if (Core < CORE_HIG) + { + SNDDrvInfo.MDEV = DEV_QUIET; + Music = FALSE; + } + #endif + if (! get_parms()) quit_now(BAD_ARG_TEXT); + //--- load sound configuration + const char * fn = UsrPath(ProgName(CFG_EXT)); + if (! STARTUP::SoundOk && CFILE::Exist(fn)) + { + CFILE cfg(fn, REA); + if (! cfg.Error) + { + cfg.Read(&SNDDrvInfo, sizeof(SNDDrvInfo)-sizeof(SNDDrvInfo.VOL2)); + if (! cfg.Error) STARTUP::SoundOk = 1; + } + } +} + + + + + + +const char *UsrPath (const char *nam) +{ + static char buf[MAXPATH] = ".\\", *p = buf+2; + #if defined(CD) + if (DriveCD(0)) + { + Boolean ok = FALSE; + CFILE ini = Text[CDINI_FNAME]; + if (!ini.Error) + { + char *key = Text[GAME_ID]; + int i = strlen(key); + while (ini.Read(buf) && !ok) + { + int j = strlen(buf); + if (j) if (buf[--j] == '\n') buf[j] = '\0'; + if (memicmp(buf, key, i) == 0) ok = TRUE; + } + if (ok) + { + strcpy(buf, buf+i); + p = buf + strlen(buf); + if (*(p-1) != '\\') *(p++) = '\\'; + strcpy(p, "NUL"); + if (_dos_open(buf, 0, &i) == 0) _dos_close(i); + else ok = FALSE; + } + } + if (!ok) quit_now(BADCD_TEXT); + } + #endif + strcpy(p, nam); + return buf; +} + + + + + diff --git a/engines/cge/startup.h b/engines/cge/startup.h new file mode 100644 index 00000000000..6db566a7812 --- /dev/null +++ b/engines/cge/startup.h @@ -0,0 +1,52 @@ +#ifndef __STARTUP__ +#define __STARTUP__ + + +#include + +#define GAME_ID 45 +#define CDINI_FNAME 46 + +#define NOT_VGA_TEXT 90 +#define BAD_CHIP_TEXT 91 +#define BAD_DOS_TEXT 92 +#define NO_CORE_TEXT 93 +#define BAD_MIPS_TEXT 94 +#define NO_MOUSE_TEXT 95 +#define BAD_ARG_TEXT 96 +#define BADCD_TEXT 97 + +#define CFG_EXT ".CFG" + +#if defined(DEMO) + #define MINI_EMM_SIZE 0x00004000L + #define CORE_HIG 400 +#else + #define MINI_EMM_SIZE 0x00010000L + #define CORE_HIG 450 +#endif + +#define CORE_MID (CORE_HIG-20) +#define CORE_LOW (CORE_MID-20) + + +class STARTUP +{ + static Boolean get_parms (void); +public: + static int Mode; + static int Core; + static int SoundOk; + static word Summa; + STARTUP (void); +}; + + + + +extern EMM MiniEmm; + +const char *UsrPath (const char *nam); + + +#endif diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp new file mode 100644 index 00000000000..a018761000f --- /dev/null +++ b/engines/cge/talk.cpp @@ -0,0 +1,376 @@ +#include +#include "talk.h" +#include "vol.h" +#include "game.h" +#include "mouse.h" +#include +#include +#include + +#define WID_SIZ 256 +#define POS_SIZ 256 +#define MAP_SIZ (256*8) + + +//-------------------------------------------------------------------------- + + + +//byte FONT::Wid[WID_SIZ]; +//word FONT::Pos[POS_SIZ]; +//byte FONT::Map[MAP_SIZ]; + + + + + + + +FONT::FONT (const char * name) +{ + Map = farnew(byte, MAP_SIZ); + Pos = farnew(word, POS_SIZ); + Wid = farnew(byte, WID_SIZ); + if (Map == NULL || Pos == NULL || Wid == NULL) DROP("No core", NULL); + MergeExt(Path, name, FONT_EXT); + Load(); +} + + + + +FONT::~FONT (void) +{ + farfree(Map); + farfree(Pos); + farfree(Wid); +} + + + + +void FONT::Load (void) +{ + INI_FILE f(Path); + if (! f.Error) + { + f.Read(Wid, WID_SIZ); + if (! f.Error) + { + word i, p = 0; + for (i = 0; i < POS_SIZ; i ++) + { + Pos[i] = p; + p += Wid[i]; + } + f.Read(Map, p); + } + } +} + + + + + +word FONT::Width (const char * text) +{ + word w = 0; + if (text) while (* text) w += Wid[*(text ++)]; + return w; +} + + + +/* +void FONT::Save (void) +{ + CFILE f((const char *) Path, WRI); + if (! f.Error) + { + f.Write(Wid, WID_SIZ); + if (! f.Error) + { + f.Write(Map, Pos[POS_SIZ-1] + Wid[WID_SIZ-1]); + } + } +} +*/ + + + + +//-------------------------------------------------------------------------- + + + +FONT TALK::Font(ProgName()); + + + +TALK::TALK (const char * tx, TBOX_STYLE mode) +: SPRITE(NULL), Mode(mode) +{ + TS[0] = TS[1] = NULL; + Flags.Syst = TRUE; + Update(tx); +} + + + + + +TALK::TALK (void) +: SPRITE(NULL), Mode(PURE) +{ + TS[0] = TS[1] = NULL; + Flags.Syst = TRUE; +} + + + + + +/* +TALK::~TALK (void) +{ + word i; + for (i = 0; i < ShpCnt; i ++) + { + if (FP_SEG(ShpList[i]) != _DS) // small model: always FALSE + { + delete ShpList[i]; + ShpList[i] = NULL; + } + } +} +*/ + + + +void TALK::Update (const char * tx) +{ + word vmarg = (Mode) ? TEXT_VM : 0; + word hmarg = (Mode) ? TEXT_HM : 0; + word mw, mh, ln = vmarg; + const char * p; + byte far * m; + + if (! TS[0]) + { + word k = 2 * hmarg; + mh = 2 * vmarg + FONT_HIG; + mw = 0; + for (p = tx; *p; p ++) + { + if (*p == '|' || *p == '\n') + { + mh += FONT_HIG + TEXT_LS; + if (k > mw) mw = k; + k = 2 * hmarg; + } + else k += Font.Wid[*p]; + } + if (k > mw) mw = k; + TS[0] = Box(mw, mh); + } + + m = TS[0]->M + ln * mw + hmarg; + + while (* tx) + { + if (*tx == '|' || *tx == '\n') + m = TS[0]->M + (ln += FONT_HIG + TEXT_LS) * mw + hmarg; + else + { + int cw = Font.Wid[*tx], i; + char far * f = Font.Map + Font.Pos[*tx]; + for (i = 0; i < cw; i ++) + { + char far * p = m; + word n; + register word b = * (f ++); + for (n = 0; n < FONT_HIG; n ++) + { + if (b & 1) * p = TEXT_FG; + b >>= 1; + p += mw; + } + ++ m; + } + } + ++ tx; + } + TS[0]->Code(); + SetShapeList(TS); +} + + + + +BITMAP * TALK::Box (word w, word h) +{ + byte far * b, far * p, far * q; + word n, r = (Mode == ROUND) ? TEXT_RD : 0; + int i; + + if (w < 8) w = 8; + if (h < 8) h = 8; + b = farnew(byte, n = w * h); + if (! b) VGA::Exit("No core"); + _fmemset(b, TEXT_BG, n); + + if (Mode) + { + p = b; q = b + n - w; + _fmemset(p, LGRAY, w); + _fmemset(q, DGRAY, w); + while (p < q) + { + p += w; + * (p-1) = DGRAY; + * p = LGRAY; + } + p = b; + for (i = 0; i < r; i ++) + { + int j; + for (j = 0; j < r-i; j ++) + { + p[ j ] = TRANS; + p[w-j-1] = TRANS; + q[ j ] = TRANS; + q[w-j-1] = TRANS; + } + p[ j ] = LGRAY; + p[w-j-1] = DGRAY; + q[ j ] = LGRAY; + q[w-j-1] = DGRAY; + p += w; + q -= w; + } + } + return new BITMAP(w, h, b); +} + + + + + +void TALK::PutLine (int line, const char * text) +// Note: (TS[0].W % 4) have to be 0 +{ + word w = TS[0]->W, h = TS[0]->H; + byte far * v = TS[0]->V, far * p; + word dsiz = w >> 2; // data size (1 plane line size) + word lsiz = 2 + dsiz + 2; // word for line header, word for gap + word psiz = h * lsiz; // - last gap, but + plane trailer + word size = 4 * psiz; // whole map size + word rsiz = FONT_HIG * lsiz; // length of whole text row map + + // set desired line pointer + v += (TEXT_VM + (FONT_HIG + TEXT_LS) * line) * lsiz; + + // clear whole rectangle + p = v; // assume blanked line above text + _fmemcpy(p, p-lsiz, rsiz); p += psiz; // tricky replicate lines for plane 0 + _fmemcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 1 + _fmemcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 2 + _fmemcpy(p, p-lsiz, rsiz); // same for plane 3 + + // paint text line + if (text) + { + byte far * q; + p = v + 2 + TEXT_HM/4 + (TEXT_HM%4)*psiz; + q = v + size; + + while (* text) + { + word cw = Font.Wid[*text], i; + byte far * fp = Font.Map + Font.Pos[*text]; + + for (i = 0; i < cw; i ++) + { + register word b = fp[i]; + word n; + for (n = 0; n < FONT_HIG; n ++) + { + if (b & 1) *p = TEXT_FG; + b >>= 1; + p += lsiz; + } + p = p - rsiz + psiz; + if (p >= q) p = p - size + 1; + } + ++ text; + } + } +} + + + + + + +//-------------------------------------------------------------------------- + + + + +INFO_LINE::INFO_LINE (word w) +: OldTxt(NULL) +{ + TS[0] = new BITMAP(w, FONT_HIG, TEXT_BG); + SetShapeList(TS); +} + + + + + + +void INFO_LINE::Update (const char * tx) +{ + if (tx != OldTxt) + { + word w = TS[0]->W, h = TS[0]->H; + byte * v = (byte near *) TS[0]->V; + word dsiz = w >> 2; // data size (1 plane line size) + word lsiz = 2 + dsiz + 2; // word for line header, word for gap + word psiz = h * lsiz; // - last gape, but + plane trailer + word size = 4 * psiz; // whole map size + + // claer whole rectangle + memset(v+2, TEXT_BG, dsiz); // data bytes + memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines + * (word *) (v + psiz - 2) = EOI; // plane trailer word + memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes + + // paint text line + if (tx) + { + byte * p = v + 2, * q = p + size; + + while (* tx) + { + word cw = Font.Wid[*tx], i; + byte far * fp = Font.Map + Font.Pos[*tx]; + + for (i = 0; i < cw; i ++) + { + register word b = fp[i]; + word n; + for (n = 0; n < FONT_HIG; n ++) + { + if (b & 1) *p = TEXT_FG; + b >>= 1; + p += lsiz; + } + if (p >= q) p = p - size + 1; + } + ++ tx; + } + } + OldTxt = tx; + } +} diff --git a/engines/cge/talk.h b/engines/cge/talk.h new file mode 100644 index 00000000000..12b0b94dde5 --- /dev/null +++ b/engines/cge/talk.h @@ -0,0 +1,81 @@ +#ifndef __TALK__ +#define __TALK__ + +#include "vga13h.h" +#include + + + +#define TEXT_FG DARK // foreground color +#define TEXT_BG GRAY // background color +#define TEXT_HM (6&~1) // EVEN horizontal margins! +#define TEXT_VM 5 // vertical margins +#define TEXT_LS 2 // line spacing +#define TEXT_RD 3 // rounded corners + +#define FONT_HIG 8 +#define FONT_EXT ".CFT" + + + + + +class FONT +{ + char Path[MAXPATH]; + void Load (void); +public: +// static byte Wid[256]; +// static word Pos[256]; +// static byte Map[256*8]; + byte far * Wid; + word far * Pos; + byte far * Map; + FONT (const char * name); + ~FONT (void); + word Width (const char * text); + void Save (void); +}; + + + + + +enum TBOX_STYLE { PURE, RECT, ROUND }; + + + +class TALK : public SPRITE +{ +protected: + TBOX_STYLE Mode; + BITMAP * TS[2]; + BITMAP * Box(word w, word h); +public: + static FONT Font; + TALK (const char * tx, TBOX_STYLE mode = PURE); + TALK (void); + //~TALK (void); + virtual void Update (const char * tx); + virtual void Update (void) {} + void PutLine (int line, const char * text); +}; + + + + + + + +class INFO_LINE : public TALK +{ + const char * OldTxt; +public: + INFO_LINE (word wid); + void Update (const char * tx); +}; + + + + +#endif \ No newline at end of file diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp new file mode 100644 index 00000000000..a18eec5baf4 --- /dev/null +++ b/engines/cge/text.cpp @@ -0,0 +1,291 @@ +#include +#include "text.h" +#include "talk.h" +#include "vol.h" +#include "bitmaps.h" +#include "game.h" +#include "snail.h" +#include +#include +#include +#include + + + + TEXT Text = ProgName(); + TALK * Talk = NULL; + + + + + +TEXT::TEXT (const char * fname, int size) +{ + Cache = new HAN[size]; + MergeExt(FileName, fname, SAY_EXT); + if (! INI_FILE::Exist(FileName)) + { + fputs("No talk\n", stderr); + _exit(1); + } + for (Size = 0; Size < size; Size ++) + { + Cache[Size].Ref = 0; + Cache[Size].Txt = NULL; + } +} + + + + +TEXT::~TEXT (void) +{ + Clear(); + delete[] Cache; +} + + + + + +void TEXT::Clear (int from, int upto) +{ + HAN * p, * q; + for (p = Cache, q = p+Size; p < q; p ++) + { + if (p->Ref && p->Ref >= from && p->Ref < upto) + { + p->Ref = 0; + delete p->Txt; + p->Txt = NULL; + } + } +} + + + + + +int TEXT::Find (int ref) +{ + HAN * p, * q; + int i = 0; + for (p = Cache, q = p+Size; p < q; p ++) + { + if (p->Ref == ref) break; + else ++ i; + } + return i; +} + + + + + + + + + + + +void TEXT::Preload (int from, int upto) +{ + INI_FILE tf = FileName; + if (! tf.Error) + { + HAN * CacheLim = Cache + Size; + char line[LINE_MAX+1]; + int n; + + while ((n = tf.Read(line)) != 0) + { + char * s; + int ref; + + if (line[n-1] == '\n') line[-- n] = '\0'; + if ((s = strtok(line, " =,;/\t\n")) == NULL) continue; + if (! IsDigit(*s)) continue; + ref = atoi(s); + if (ref && ref >= from && ref < upto) + { + HAN * p; + + p = &Cache[Find(ref)]; + if (p < CacheLim) + { + delete[] p->Txt; + p->Txt = NULL; + } + else p = &Cache[Find(0)]; + if (p >= CacheLim) break; + s += strlen(s); + if (s < line + n) ++ s; + if ((p->Txt = new char[strlen(s) + 1]) == NULL) break; + p->Ref = ref; + strcpy(p->Txt, s); + } + } + } +} + + + + + +char * TEXT::Load (int idx, int ref) +{ + INI_FILE tf = FileName; + if (! tf.Error) + { + HAN * p = &Cache[idx]; + char line[LINE_MAX+1]; + int n; + + while ((n = tf.Read(line)) != 0) + { + char * s; + + if (line[n-1] == '\n') line[-- n] = '\0'; + if ((s = strtok(line, " =,;/\t\n")) == NULL) continue; + if (! IsDigit(*s)) continue; + + int r = atoi(s); + if (r < ref) continue; + if (r > ref) break; + // (r == ref) + s += strlen(s); + if (s < line + n) ++ s; + p->Ref = ref; + if ((p->Txt = new char[strlen(s) + 1]) == NULL) return NULL; + return strcpy(p->Txt, s); + } + } + return NULL; +} + + + + +char * TEXT::operator [] (int ref) +{ + int i; + if ((i = Find(ref)) < Size) return Cache[i].Txt; + + if ((i = Find(0)) >= Size) + { + Clear(SYSTXT_MAX); // clear non-system + if ((i = Find(0)) >= Size) + { + Clear(); // clear all + i = 0; + } + } + return Load(i, ref); +} + + + + + + +void Say (const char * txt, SPRITE * spr) +{ + KillText(); + Talk = new TALK(txt, ROUND); + if (Talk) + { + Boolean east = spr->Flags.East; + int x = (east) ? (spr->X+spr->W-2) : (spr->X+2); + int y = spr->Y+2; + SPRITE * spike = new SPRITE(SP); + word sw = spike->W; + + if (east) + { + if (x + sw + TEXT_RD + 5 >= SCR_WID) east = FALSE; + } + else + { + if (x <= 5 + TEXT_RD + sw) east = TRUE; + } + x = (east) ? (spr->X+spr->W-2) : (spr->X+2-sw); + if (spr->Ref == 1) x += (east) ? -10 : 10; // Hero + + Talk->Flags.Kill = TRUE; + Talk->Flags.BDel = TRUE; + Talk->SetName(Text[SAY_NAME]); + Talk->Goto(x - (Talk->W - sw) / 2 - 3 + 6 * east, y - spike->H - Talk->H+1); + Talk->Z = 125; + Talk->Ref = SAY_REF; + + spike->Goto(x, Talk->Y + Talk->H - 1); + spike->Z = 126; + spike->Flags.Slav = TRUE; + spike->Flags.Kill = TRUE; + spike->SetName(Text[SAY_NAME]); + spike->Step(east); + spike->Ref = SAY_REF; + + VGA::ShowQ.Insert(Talk, VGA::ShowQ.Last()); + VGA::ShowQ.Insert(spike, VGA::ShowQ.Last()); + } +} + + + + + + + +void Inf (const char * txt) +{ + KillText(); + Talk = new TALK(txt, RECT); + if (Talk) + { + Talk->Flags.Kill = TRUE; + Talk->Flags.BDel = TRUE; + Talk->SetName(Text[INF_NAME]); + Talk->Center(); + Talk->Goto(Talk->X, Talk->Y - 20); + Talk->Z = 126; + Talk->Ref = INF_REF; + VGA::ShowQ.Insert(Talk, VGA::ShowQ.Last()); + } +} + + + + + + + +void SayTime (SPRITE * spr) +{ + static char t[] = "00:00"; + struct time ti; + gettime(&ti); + wtom(ti.ti_hour, t+0, 10, 2); + wtom(ti.ti_min, t+3, 10, 2); + Say((*t == '0') ? (t+1) : t, spr); +} + + + + + + +void KillText (void) +{ + if (Talk) + { + SNPOST_(SNKILL, -1, 0, Talk); + Talk = NULL; + } +} + + + + + +//------------------------------------------------------------------------- diff --git a/engines/cge/text.h b/engines/cge/text.h new file mode 100644 index 00000000000..d960fbef912 --- /dev/null +++ b/engines/cge/text.h @@ -0,0 +1,60 @@ +#ifndef __TEXT__ +#define __TEXT__ + +#include "talk.h" +#include +#include + + + + +#ifndef SYSTXT_MAX + #define SYSTXT_MAX 1000 +#endif + +#define SAY_EXT ".SAY" + +#define NOT_VGA_TEXT 90 +#define BAD_CHIP_TEXT 91 +#define BAD_DOS_TEXT 92 +#define NO_CORE_TEXT 93 +#define BAD_MIPS_TEXT 94 +#define NO_MOUSE_TEXT 95 + + +#define INF_NAME 101 +#define SAY_NAME 102 + +#define INF_REF 301 +#define SAY_REF 302 + + +class TEXT +{ + struct HAN { int Ref; char * Txt; } * Cache; + int Size; + char FileName[MAXPATH]; + char * Load (int idx, int ref); + int Find (int ref); +public: + TEXT (const char * fname, int size = 128); + ~TEXT (void); + void Clear (int from = 1, int upto = 0x7FFF); + void Preload (int from = 1, int upto = 0x7FFF); + char * operator[] (int ref); +}; + + + +extern TALK * Talk; +extern TEXT Text; + + +void Say (const char * txt, SPRITE * spr); +void SayTime (SPRITE * spr); +void Inf (const char * txt); +void KillText (void); + + + +#endif \ No newline at end of file diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp new file mode 100644 index 00000000000..227304668b9 --- /dev/null +++ b/engines/cge/vga13h.cpp @@ -0,0 +1,1775 @@ +#include +#include "vga13h.h" +#include "bitmap.h" +#include "vol.h" +#include "text.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef DEBUG +#define REPORT +#endif + +#define OK(f) ((f).Error==0) +#define FADE_STEP 2 + +#define TMR_DIV ((0x8000/TMR_RATE)*2) + + +//-------------------------------------------------------------------------- + +#ifdef REPORT +static char Report[] = "NearHeap=..... FarHeap=......\n"; +#define NREP 9 +#define FREP 24 +#endif + + + +static VgaRegBlk VideoMode[] = { + + { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode + + { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 + { 0x05, VGAGRA, 0x03, 0x00 }, // R/W mode = 0 + { 0x06, VGAGRA, 0x02, 0x00 }, // misc + + { 0x14, VGACRT, 0x40, 0x00 }, // underline + { 0x13, VGACRT, 0xFF, 0x28 }, // screen width + { 0x17, VGACRT, 0xFF, 0xC3 }, // mode control + + { 0x11, VGACRT, 0x80, 0x00 }, // vert retrace end + { 0x09, VGACRT, 0xEF, 0x01 }, // max scan line + + { 0x30, VGAATR, 0x00, 0x20 }, // 256 color mode + +// { 0x12, VGACRT, 0xFF, 0x6E }, // vert display end +// { 0x15, VGACRT, 0xFF, 0x7F }, // start vb +// { 0x10, VGACRT, 0xFF, 0x94 }, // start vr + + { 0x00 } }; + + + Boolean SpeedTest = FALSE; + SEQ Seq1[] = { { 0, 0, 0, 0, 0 } }; + SEQ Seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; + SPRITE * Sys = NULL; + +extern "C" void SNDMIDIPlay (void); + + + + + + +char * NumStr (char * str, int num) +{ + char * p = strchr(str, '#'); + if (p) wtom(num, p, 10, 5); + return str; +} + + + + + + + + +static void Video (void) +{ + static word SP_S; + + asm push bx + asm push bp + asm push si + asm push di + asm push es + asm xor bx,bx // video page #0 + SP_S = _SP; + asm int VIDEO + _SP = SP_S; + asm pop es + asm pop di + asm pop si + asm pop bp + asm pop bx +} + + + + + + +word far * SaveScreen (void) +{ + word cxy, cur, siz, far * scr = NULL, far * sav; + + // horizontal size of text mode screen + asm mov ah,0x0F // get current video mode + Video(); // BIOS video service + asm xchg ah,al // answer in ah + asm push ax // preserve width + + // vertical size of text mode screen + asm mov dl,24 // last row on std screen + asm xor bx,bx // valid request in BH + asm mov ax,0x1130 // get EGA's last row # + Video(); // BIOS video service + asm inc dl // # of rows = last+1 + + // compute screen size in words + asm pop ax // restore width + asm mul dl // width * height + + siz = _AX; + + asm mov ax,0x40 // system data segment + asm mov es,ax + asm mov ax,0B000H // Mono + asm cmp byte ptr es:[0x49],0x07 + asm je sto + asm mov ax,0B800H // Color + sto: // store screen address + asm mov word ptr scr+2,ax + + _AH = 0x0F; Video(); // active page + + // take cursor shape + _AH = 0x03; Video(); // get cursor size + cur = _CX; + + // take cursor position + _DH = 0; + _AH = 0x03; Video(); // get cursor + cxy = _DX; + + sav = farnew(word, siz+3); // +3 extra words for size and cursor + if (sav) + { + sav[0] = siz; + sav[1] = cur; + sav[2] = cxy; + _fmemcpy(sav+3, scr, siz * 2); + } + return sav; +} + + + + + +void RestoreScreen (word far * &sav) +{ + word far * scr = NULL; + + asm mov ax,0x40 // system data segment + asm mov es,ax + asm mov ax,0B000H // Mono + asm cmp byte ptr es:[0x49],0x07 + asm je sto + asm mov ax,0B800H // Color + sto: // store screen address + asm mov word ptr scr+2,ax + + _fmemcpy(scr, sav+3, sav[0] * 2); + + _AH = 0x0F; Video(); // active page + + // set cursor shape + _CX = sav[1]; + _AH = 0x01; Video(); // set cursor size + + // set cursor position + _DX = sav[2]; + _AH = 0x02; Video(); // set cursor + + farfree(sav); + sav = NULL; +} + + + + + + +DAC MkDAC (byte r, byte g, byte b) +{ + static DAC x; + x.R = r; + x.G = g; + x.B = b; + return x; +} + + + + +RGB MkRGB (byte r, byte g, byte b) +{ + static TRGB x; + x.dac.R = r; + x.dac.G = g; + x.dac.B = b; + return x.rgb; +} + + + + + + +SPRITE * Locate (int ref) +{ + SPRITE * spr = VGA::ShowQ.Locate(ref); + return (spr) ? spr : VGA::SpareQ.Locate(ref); +} + + + + + +//-------------------------------------------------------------------------- + + +Boolean HEART::Enable = FALSE; +word * HEART::XTimer = NULL; + + + + +HEART::HEART (void) +: ENGINE(TMR_DIV) +{ +} + + +/* +extern "C" void TimerProc (void) +{ + static SPRITE * spr; + static byte run = 0; + + // decrement external timer word + if (HEART::XTimer) + if (*HEART::XTimer) -- *HEART::XTimer; + else HEART::XTimer = NULL; + + if (! run && HEART::Enable) // check overrun flag + { + static word oldSP, oldSS; + + ++ run; // disable 2nd call until current lasts + asm mov ax,ds + asm mov oldSS,ss + asm mov oldSP,sp + asm mov ss,ax + asm mov sp,0xFF80 + + // system pseudo-sprite + if (Sys) if (Sys->Time) if (-- Sys->Time == 0) Sys->Tick(); + + for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) + { + if (spr->Time) if (!spr->Flags.Hide) if (-- spr->Time == 0) spr->Tick(); + } + asm mov ss,oldSS + asm mov sp,oldSP + -- run; + } +} +*/ + + +void interrupt ENGINE::NewTimer (...) +{ + static SPRITE * spr; + static byte run = 0, cntr1 = TMR_RATE1, cntr2 = TMR_RATE2; + + ___1152_Hz___: + + SNDMIDIPlay(); + asm dec cntr1 + asm jz ___72_Hz___ + asm mov al,0x20 // send... + asm out 0x020,al // ...e-o-i + return; + + ___72_Hz___: + + asm mov cntr1,TMR_RATE1 + asm dec cntr2 + asm jnz my_eoi + + ___18_Hz___: + + OldTimer(); + asm mov cntr2,TMR_RATE2 + asm jmp short my_int + + // send E-O-I + my_eoi: + asm mov al,0x20 + asm out 0x020,al + asm sti // enable interrupts + + my_int: //------72Hz-------// + + // decrement external timer word + if (HEART::XTimer) + if (*HEART::XTimer) -- *HEART::XTimer; + else HEART::XTimer = NULL; + + if (! run && HEART::Enable) // check overrun flag + { + static word oldSP, oldSS; + + ++ run; // disable 2nd call until current lasts + asm mov ax,ds + asm mov oldSS,ss + asm mov oldSP,sp + asm mov ss,ax + asm mov sp,0xFF80 + + // system pseudo-sprite + if (Sys) if (Sys->Time) if (-- Sys->Time == 0) Sys->Tick(); + + for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) + { + if (spr->Time) if (!spr->Flags.Hide) if (-- spr->Time == 0) spr->Tick(); + } + asm mov ss,oldSS + asm mov sp,oldSP + -- run; + } +} + + + + + +void HEART::SetXTimer (word * ptr) +{ + if (XTimer && ptr != XTimer) *XTimer = 0; + XTimer = ptr; +} + + + + +void HEART::SetXTimer (word * ptr, word time) +{ + SetXTimer(ptr); + *ptr = time; +} + + + + +//-------------------------------------------------------------------------- + + + + + + + +SPRITE::SPRITE (BMP_PTR * shp) +: X(0), Y(0), Z(0), NearPtr(0), TakePtr(0), + Next(NULL), Prev(NULL), SeqPtr(NO_SEQ), Time(0), //Delay(0), + Ext(NULL), Ref(-1), Cave(0) +{ + memset(File, 0, sizeof(File)); + *((word *)&Flags) = 0; + SetShapeList(shp); +} + + + + + + +SPRITE::~SPRITE (void) +{ + Contract(); +} + + + + +BMP_PTR SPRITE::Shp (void) +{ + register SPREXT * e = Ext; + if (e) if (e->Seq) + { + int i = e->Seq[SeqPtr].Now; + #ifdef DEBUG + if (i >= ShpCnt) + { + //char s[256]; + //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", + // Seq, ShpCnt, SeqPtr, Seq[SeqPtr].Now, Seq[SeqPtr].Next); + //VGA::Exit(s, File); + VGA::Exit("Invalid PHASE in SPRITE::Shp()", File); + } + #endif + return e->ShpList[i]; + } + return NULL; +} + + + + + +BMP_PTR * SPRITE::SetShapeList (BMP_PTR * shp) +{ + BMP_PTR * r = (Ext) ? Ext->ShpList : NULL; + + ShpCnt = 0; + W = 0; + H = 0; + + if (shp) + { + BMP_PTR * p; + for (p = shp; *p; p ++) + { + BMP_PTR b = (*p); // ->Code(); + if (b->W > W) W = b->W; + if (b->H > H) H = b->H; + ++ ShpCnt; + } + Expand(); + Ext->ShpList = shp; + if (! Ext->Seq) SetSeq((ShpCnt < 2) ? Seq1 : Seq2); + } + return r; +} + + + + + +void SPRITE::MoveShapes (byte far * buf) +{ + BMP_PTR * p; + for (p = Ext->ShpList; *p; p ++) + { + buf += (*p)->MoveVmap(buf); + } +} + + + + + +Boolean SPRITE::Works (SPRITE * spr) +{ + if (spr) if (spr->Ext) + { + SNAIL::COM * c = spr->Ext->Take; + if (c != NULL) + { + c += spr->TakePtr; + if (c->Ref == Ref) + if (c->Com != SNLABEL || (c->Val == 0 || c->Val == Now)) + return TRUE; + } + } + return FALSE; +} + + + + + +SEQ * SPRITE::SetSeq (SEQ * seq) +{ + Expand(); + register SEQ * s = Ext->Seq; + Ext->Seq = seq; + if (SeqPtr == NO_SEQ) Step(0); + else + if (Time == 0) Step(SeqPtr); + return s; +} + + + + + + +Boolean SPRITE::SeqTest (int n) +{ + if (n >= 0) return (SeqPtr == n); + if (Ext) return (Ext->Seq[SeqPtr].Next == SeqPtr); + return TRUE; +} + + + + + + +SNAIL::COM * SPRITE::SnList (SNLIST type) +{ + register SPREXT * e = Ext; + if (e) return (type == NEAR) ? e->Near : e->Take; + return NULL; +} + + + + + + +void SPRITE::SetName (char * n) +{ + if (Ext) + { + if (Ext->Name) + { + delete[] Ext->Name; + Ext->Name = NULL; + } + if (n) + { + if ((Ext->Name = new char[strlen(n)+1]) != NULL) strcpy(Ext->Name, n); + else VGA::Exit("No core", n); + } + } +} + + + + + +SPRITE * SPRITE::Expand (void) +{ + if (! Ext) + { + Boolean enbl = HEART::Enable; + HEART::Enable = FALSE; + if ((Ext = new SPREXT) == NULL) DROP("No core", NULL); + if (*File) + { + static char * Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; + char line[LINE_MAX], fname[MAXPATH]; + BMP_PTR * shplist = new BMP_PTR [ShpCnt+1]; + SEQ * seq = NULL; + int shpcnt = 0, + seqcnt = 0, + neacnt = 0, + takcnt = 0, + maxnow = 0, + maxnxt = 0, + lcnt = 0, + len; + + SNAIL::COM * nea = NULL; + SNAIL::COM * tak = NULL; + MergeExt(fname, File, SPR_EXT); + if (INI_FILE::Exist(fname)) // sprite description file exist + { + INI_FILE sprf(fname); + if (! OK(sprf)) + { + VGA::Exit("Bad SPR", fname); + } + + while ((len = sprf.Read(line)) != 0) + { + ++ lcnt; + if (len && line[len-1] == '\n') line[-- len] = '\0'; + if (len == 0 || *line == '.') continue; + + switch (TakeEnum(Comd, strtok(line, " =\t"))) + { + case 0 : // Name + SetName(strtok(NULL, "")); break; + case 1 : // Phase + shplist[shpcnt ++] = new BITMAP(strtok(NULL, " \t,;/")); + break; + case 2 : // Seq + seq = (SEQ *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); + if (seq == NULL) + VGA::Exit("No core", fname); + SEQ * s = &seq[seqcnt ++]; + s->Now = atoi(strtok(NULL, " \t,;/")); + if (s->Now > maxnow) maxnow = s->Now; + s->Next = atoi(strtok(NULL, " \t,;/")); + switch (s->Next) + { + case 0xFF : s->Next = seqcnt; break; + case 0xFE : s->Next = seqcnt-1; break; + } + if (s->Next > maxnxt) maxnxt = s->Next; + s->Dx = atoi(strtok(NULL, " \t,;/")); + s->Dy = atoi(strtok(NULL, " \t,;/")); + s->Dly = atoi(strtok(NULL, " \t,;/")); + break; + case 3 : // Near + if (NearPtr != NO_PTR) + { + nea = (SNAIL::COM *) realloc(nea, (neacnt + 1) * sizeof(*nea)); + if (nea == NULL) VGA::Exit("No core", fname); + else + { + SNAIL::COM * c = &nea[neacnt ++]; + if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) + VGA::Exit(NumStr("Bad NEAR in ######", lcnt), fname); + c->Ref = atoi(strtok(NULL, " \t,;/")); + c->Val = atoi(strtok(NULL, " \t,;/")); + c->Ptr = NULL; + } + } + break; + case 4 : // Take + if (TakePtr != NO_PTR) + { + tak = (SNAIL::COM *) realloc(tak, (takcnt + 1) * sizeof(*tak)); + if (tak == NULL) VGA::Exit("No core", fname); + else + { + SNAIL::COM * c = &tak[takcnt ++]; + if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) + VGA::Exit(NumStr("Bad NEAR in ######", lcnt), fname); + c->Ref = atoi(strtok(NULL, " \t,;/")); + c->Val = atoi(strtok(NULL, " \t,;/")); + c->Ptr = NULL; + } + } + break; + } + } + } + else // no sprite description: try to read immediately from .BMP + { + shplist[shpcnt ++] = new BITMAP(File); + } + shplist[shpcnt] = NULL; + if (seq) + { + if (maxnow >= shpcnt) VGA::Exit("Bad PHASE in SEQ", fname); + if (maxnxt >= seqcnt) VGA::Exit("Bad JUMP in SEQ", fname); + SetSeq(seq); + } + else SetSeq((ShpCnt == 1) ? Seq1 : Seq2); + disable(); + + SetShapeList(shplist); + enable(); + if (nea) nea[neacnt-1].Ptr = Ext->Near = nea; else NearPtr = NO_PTR; + if (tak) tak[takcnt-1].Ptr = Ext->Take = tak; else TakePtr = NO_PTR; + } + HEART::Enable = enbl; + } + return this; +} + + + + +SPRITE * SPRITE::Contract (void) +{ + register SPREXT * e = Ext; + if (e) + { + if (e->Name) delete[] e->Name; + if (Flags.BDel && e->ShpList) + { + int i; + for (i = 0; e->ShpList[i]; i ++) delete e->ShpList[i]; + if (MemType(e->ShpList) == NEAR_MEM) delete[] e->ShpList; + } + if (MemType(e->Seq) == NEAR_MEM) free(e->Seq); + if (e->Near) free(e->Near); + if (e->Take) free(e->Take); + delete e; + Ext = NULL; + } + return this; +} + + + + + + +SPRITE * SPRITE::BackShow (Boolean fast) +{ + Expand(); + Show(2); + Show(1); + if (fast) Show(0); + Contract(); + return this; +} + + + + + + + + +void SPRITE::Step (int nr) +{ + if (nr >= 0) SeqPtr = nr; + if (Ext) + { + SEQ * seq; + if (nr < 0) SeqPtr = Ext->Seq[SeqPtr].Next; + seq = Ext->Seq + SeqPtr; + if (seq->Dly >= 0) + { + Goto(X + (seq->Dx), Y + (seq->Dy)); + Time = seq->Dly; + } + } +} + + + + + + +void SPRITE::Tick (void) +{ + Step(); +} + + + + + +void SPRITE::MakeXlat (byte far * x) +{ + if (Ext) + { + BMP_PTR * b; + + if (Flags.Xlat) KillXlat(); + for (b = Ext->ShpList; *b; b ++) (*b)->M = x; + Flags.Xlat = TRUE; + } +} + + + + + +void SPRITE::KillXlat (void) +{ + if (Flags.Xlat && Ext) + { + BMP_PTR * b; + byte far * m = (*Ext->ShpList)->M; + + switch (MemType(m)) + { + case NEAR_MEM : delete[] (byte *) m; break; + case FAR_MEM : farfree(m); break; + } + for (b = Ext->ShpList; *b; b ++) (*b)->M = NULL; + Flags.Xlat = FALSE; + } +} + + + + + +void SPRITE::Goto (int x, int y) +{ + int xo = X, yo = Y; + if (W < SCR_WID) + { + if (x < 0) x = 0; + if (x + W > SCR_WID) x = (SCR_WID - W); + X = x; + } + if (H < SCR_HIG) + { + if (y < 0) y = 0; + if (y + H > SCR_HIG) y = (SCR_HIG - H); + Y = y; + } + if (Next) if (Next->Flags.Slav) Next->Goto(Next->X-xo+X, Next->Y-yo+Y); + if (Flags.Shad) Prev->Goto(Prev->X-xo+X, Prev->Y-yo+Y); +} + + + + + + + + + + + + +void SPRITE::Center (void) +{ + Goto((SCR_WID - W) / 2, (SCR_HIG - H) / 2); +} + + + + + + + + +void SPRITE::Show (void) +{ + register SPREXT * e; + asm cli // critic section... + e = Ext; + e->x0 = e->x1; + e->y0 = e->y1; + e->b0 = e->b1; + e->x1 = X; + e->y1 = Y; + e->b1 = Shp(); + asm sti // ...done! + if (! Flags.Hide) + { + if (Flags.Xlat) e->b1->XShow(e->x1, e->y1); + else e->b1->Show(e->x1, e->y1); + } +} + + + + + + + +void SPRITE::Show (word pg) +{ + byte far * a = VGA::Page[1]; + VGA::Page[1] = VGA::Page[pg & 3]; + Shp()->Show(X, Y); + VGA::Page[1] = a; +} + + + + + + + + +void SPRITE::Hide (void) +{ + register SPREXT * e = Ext; + if (e->b0) e->b0->Hide(e->x0, e->y0); +} + + + + +BMP_PTR SPRITE::Ghost (void) +{ + register SPREXT * e = Ext; + if (e->b1) + { + BMP_PTR bmp = new BITMAP(0, 0, (byte far *)NULL); + if (bmp == NULL) VGA::Exit("No core"); + bmp->W = e->b1->W; + bmp->H = e->b1->H; + if ((bmp->B = farnew(HideDesc, bmp->H)) == NULL) VGA::Exit("No Core"); + bmp->V = (byte far *) _fmemcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); + bmp->M = (byte far *) MK_FP(e->y1, e->x1); + return bmp; + } + return NULL; +} + + + + + + +SPRITE * SpriteAt (int x, int y) +{ + SPRITE * spr = NULL, * tail = VGA::ShowQ.Last(); + if (tail) + { + for (spr = tail->Prev; spr; spr = spr->Prev) + if (! spr->Flags.Hide && ! spr->Flags.Tran) + if (spr->Shp()->SolidAt(x-spr->X, y-spr->Y)) + break; + } + return spr; +} + + + + + +//-------------------------------------------------------------------------- + + + + + + +QUEUE::QUEUE (Boolean show) +: Head(NULL), Tail(NULL), Show(show) +{ +} + + + + +QUEUE::~QUEUE (void) +{ + Clear(); +} + + + + +void QUEUE::Clear (void) +{ + while (Head) + { + SPRITE * s = Remove(Head); + if (s->Flags.Kill) delete s; + } +} + + + + +void QUEUE::ForAll (void (*fun)(SPRITE *)) +{ + SPRITE * s = Head; + while (s) + { + SPRITE * n = s->Next; + fun(s); + s = n; + } +} + + + + + +void QUEUE::Append (SPRITE * spr) +{ + if (Tail) + { + spr->Prev = Tail; + Tail->Next = spr; + } + else Head = spr; + Tail = spr; + if (Show) spr->Expand(); + else spr->Contract(); +} + + + + + +void QUEUE::Insert (SPRITE * spr, SPRITE * nxt) +{ + if (nxt == Head) + { + spr->Next = Head; + Head = spr; + if (! Tail) Tail = spr; + } + else + { + spr->Next = nxt; + spr->Prev = nxt->Prev; + if (spr->Prev) spr->Prev->Next = spr; + } + if (spr->Next) spr->Next->Prev = spr; + if (Show) spr->Expand(); + else spr->Contract(); +} + + + + + +void QUEUE::Insert (SPRITE * spr) +{ + SPRITE * s; + for (s = Head; s; s = s->Next) + if (s->Z > spr->Z) + break; + if (s) Insert(spr, s); + else Append(spr); + if (Show) spr->Expand(); + else spr->Contract(); +} + + + + + +SPRITE * QUEUE::Remove (SPRITE * spr) +{ + if (spr == Head) Head = spr->Next; + if (spr == Tail) Tail = spr->Prev; + if (spr->Next) spr->Next->Prev = spr->Prev; + if (spr->Prev) spr->Prev->Next = spr->Next; + spr->Prev = NULL; + spr->Next = NULL; + return spr; +} + + + + + +SPRITE * QUEUE::Locate (int ref) +{ + SPRITE * spr; + for (spr = Head; spr; spr = spr->Next) if (spr->Ref == ref) return spr; + return NULL; +} + + + + + +//-------------------------------------------------------------------------- + + + + +word VGA::StatAdr = VGAST1_; +word VGA::OldMode = 0; +word far * VGA::OldScreen = NULL; +const char * VGA::Msg = NULL; +const char * VGA::Nam = NULL; +DAC far * VGA::OldColors = NULL; +DAC far * VGA::NewColors = NULL; +Boolean VGA::SetPal = FALSE; +int VGA::Mono = 0; +QUEUE VGA::ShowQ = TRUE, VGA::SpareQ = FALSE; +byte far * VGA::Page[4] = { (byte far *) MK_FP(SCR_SEG, 0x0000), + (byte far *) MK_FP(SCR_SEG, 0x4000), + (byte far *) MK_FP(SCR_SEG, 0x8000), + (byte far *) MK_FP(SCR_SEG, 0xC000) }; + + + + +VGA::VGA (int mode) +: FrmCnt(0) +{ + extern const char Copr[]; + Boolean std = TRUE; + int i; + for (i = 10; i < 20; i ++) + { + char * txt = Text[i]; + if (txt) + { + puts(txt); + #ifndef DEBUG + std = FALSE; + #endif + } + } + if (std) puts(Copr); + SetStatAdr(); + if (StatAdr != VGAST1_) ++ Mono; + if (IsVga()) + { + OldColors = farnew(DAC, 256); + NewColors = farnew(DAC, 256); + OldScreen = SaveScreen(); + GetColors(OldColors); + Sunset(); + OldMode = SetMode(mode); + SetColors(); + Setup(VideoMode); + Clear(); + } +} + + + + + +VGA::~VGA (void) +{ + Mono = 0; + if (IsVga()) + { + Clear(); + SetMode(OldMode); + SetColors(); + RestoreScreen(OldScreen); + Sunrise(OldColors); + if (OldColors) farfree(OldColors); + if (NewColors) farfree(NewColors); + if (Msg) fputs(Msg, stderr); + if (Nam) + { + fputs(" [", stderr); + fputs(Nam, stderr); + fputc(']', stderr); + } + if (Msg || Nam) fputc('\n', stderr); + #ifdef REPORT + fputs(Report, stderr); + #endif + } +} + + + + + +void VGA::SetStatAdr (void) +{ + asm mov dx,VGAMIr_ + asm in al,dx + asm test al,1 // CGA addressing mode flag + asm mov ax,VGAST1_ // CGA addressing + asm jnz set_mode_adr + asm xor al,0x60 // MDA addressing + set_mode_adr: + StatAdr = _AX; +} + + + + + + +#pragma argsused +void VGA::WaitVR (Boolean on) +{ + _DX = StatAdr; + _AH = (on) ? 0x00 : 0x08; + + asm mov cx,2 + // wait for vertical retrace on (off) + wait: + asm in al,dx + asm xor al,ah + asm test al,0x08 + asm jnz wait + asm xor ah,0x08 + asm loop wait +} + + + + + + +void VGA::Setup (VgaRegBlk * vrb) +{ + WaitVR(); // *--LOOK!--* resets VGAATR logic + asm cld + asm mov si, vrb // take address of parameter table + asm mov dh,0x03 // higher byte of I/O address is always 3 + + s: + asm lodsw // take lower byte of I/O address and index + asm or ah,ah // 0 = end of table + asm jz xit // no more: exit + asm or al,al // indexed register? + asm js single // 7th bit set means single register + asm mov dl,ah // complete I/O address + asm out dx,al // put index into control register + asm inc dx // data register is next to control + asm in al,dx // take old data + + write: + asm mov cl,al // preserve old data + asm lodsw // take 2 masks from table + asm xor al,0xFF // invert mask bits + asm and al,cl // clear bits with "clr" mask + asm or al,ah // set bits with "set" mask + asm cmp dl,0xC1 // special case? + asm jne std2 // no: standard job, otherwise... + asm dec dx // data out reg shares address with index + std2: + asm out dx,al // write new value to register + asm jmp s + + single: // read address in al, write address in ah + asm mov dl,al // complete I/O read address + asm in al,dx // take old data + asm mov dl,ah // complete I/O write address + asm jmp write // continue standard routine + + xit: +} + + + + + + +int VGA::SetMode (int mode) +{ + Clear(); + // get current mode + asm mov ah,0x0F + Video(); // BIOS video service + asm xor ah,ah + asm push ax + + // wait for v-retrace + WaitVR(); + + // set mode + asm xor ah,ah + asm mov al,byte ptr mode + Video(); // BIOS video service + SetStatAdr(); + // return previous mode + asm pop ax + return _AX; +} + + + + + + +void VGA::GetColors (DAC far * tab) +{ + asm cld + asm les di,tab // color table + asm mov dx,0x3C7 // PEL address read mode register + asm xor al,al // start from address 0 + asm out dx,al // put address + asm mov cx,256*3 // # of colors + asm mov dl,0xC9 // PEL data register + +// asm rep insb // very fast! + + gc: // much slower: + asm in al,dx // take 1 color + asm jmp sto // little delay + sto: + asm stosb // store 1 color + asm loop gc // next one? +} + + + + +void VGA::SetColors (DAC far * tab, int lum) +{ + DAC far * des = NewColors; + asm push ds + + asm les di,des + asm lds si,tab + asm mov cx,256*3 + asm xor bx,bx + asm mov dx,lum + + copcol: + asm mov al,[si+bx] + asm mul dl + asm shr ax,6 + asm mov es:[di+bx],al + asm inc bx + asm cmp bx,cx + asm jb copcol + + asm pop ds + + if (Mono) + { + asm add cx,di + mono: + asm xor dx,dx + asm mov al,77 // 30% R + asm mul byte ptr es:[di].0 + asm add dx,ax + asm mov al,151 // 59% G + asm mul byte ptr es:[di].1 + asm add dx,ax + asm mov al,28 // 11% B + asm mul byte ptr es:[di].2 + asm add dx,ax + + asm mov es:[di].0,dh + asm mov es:[di].1,dh + asm mov es:[di].2,dh + + asm add di,3 + asm cmp di,cx + asm jb mono + } + SetPal = TRUE; +} + + + + + + +void VGA::SetColors (void) +{ + _fmemset(NewColors, 0, PAL_SIZ); + UpdateColors(); +} + + + + + + +void VGA::Sunrise (DAC far * tab) +{ + int i; + for (i = 0; i <= 64; i += FADE_STEP) + { + SetColors(tab, i); + WaitVR(); + UpdateColors(); + } +} + + + + + + +void VGA::Sunset (void) +{ + DAC tab[256]; + int i; + GetColors(tab); + for (i = 64; i >= 0; i -= FADE_STEP) + { + SetColors(tab, i); + WaitVR(); + UpdateColors(); + } +} + + + + + + + + + +void VGA::Show (void) +{ + SPRITE * spr = ShowQ.First(); + + for (spr = ShowQ.First(); spr; spr = spr->Next) spr->Show(); + Update(); + for (spr = ShowQ.First(); spr; spr = spr->Next) spr->Hide(); + + ++ FrmCnt; +} + + + + +void VGA::UpdateColors (void) +{ + DAC far * tab = NewColors; + + asm push ds + asm cld + asm lds si,tab // color table + asm mov dx,0x3C8 // PEL address write mode register + asm xor al,al // start from address 0 + asm out dx,al // put address + asm mov cx,256*3 // # of colors + asm mov dl,0xC9 // PEL data register + +// asm rep outsb // very fast! + + // the slower version of above: + sc: + asm lodsb // take 1/3 color + asm out dx,al // put 1/3 color + asm jmp loop // little delay + loop: + asm loop sc // next one? + + + asm pop ds +} + + + + + + + +void VGA::Update (void) +{ + byte far * p = Page[1]; + Page[1] = Page[0]; + Page[0] = p; + + asm mov dx,VGACRT_ + asm mov al,0x0D + asm mov ah,byte ptr p + asm out dx,ax + asm dec al + asm mov ah,byte ptr p+1 + asm out dx,ax + + if (! SpeedTest) WaitVR(); + + if (SetPal) + { + UpdateColors(); + SetPal = FALSE; + } +} + + + + + + + + +void VGA::Clear (byte color) +{ + byte far * a = (byte far *) MK_FP(SCR_SEG, 0); + + asm mov dx,VGASEQ_ + asm mov ax,0x0F02 // map mask register - enable all planes + asm out dx,ax + asm les di,a + asm cld + + asm mov cx,0xFFFF + asm mov al,color + asm rep stosb + asm stosb +} + + + + + + +void VGA::CopyPage (word d, word s) +{ + byte far * S = Page[s & 3], far * D = Page[d & 3]; + + asm mov dx,VGAGRA_ + asm mov al,0x05 // R/W mode + asm out dx,al + asm inc dx + asm in al,dx + asm and al,0xF4 + asm push ax + asm push dx + asm or al,0x01 + asm out dx,al + + asm mov dx,VGASEQ_ + asm mov ax,0x0F02 // map mask register - enable all planes + asm out dx,ax + + asm push ds + + asm les di,D + asm lds si,S + asm cld + asm mov cx,0x4000 + asm rep movsb + + asm pop ds + + asm pop dx + asm pop ax + asm out dx,al // end of copy mode +} + + + + + + + +void VGA::Exit (const char * txt, const char * name) +{ + Msg = txt; + Nam = name; + #ifdef REPORT + wtom(coreleft(), Report + NREP, 10, 5); + dwtom(farcoreleft(), Report + FREP, 10, 6); + #endif + exit(0); +} + + + + +void VGA::Exit (int tref, const char * name) +{ + Exit(Text[tref], name); +} + + + + +//-------------------------------------------------------------------------- + + + + +void BITMAP::XShow (int x, int y) +{ + byte rmsk = x % 4, + mask = 1 << rmsk, + far * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; + byte near * m = (char *) M; + byte far * v = V; + + asm push bx + asm push si + asm push ds + + asm cld + asm les di,scr + asm lds si,v + asm mov bx,m + + + + asm mov al,0x02 // map mask register + asm mov ah,mask + + plane: + // enable output plane + asm mov dx,VGASEQ_ + asm out dx,ax + asm push ax + + // select input plane + asm mov dx,VGAGRA_ + asm mov al,0x04 // read map select register + asm mov ah,rmsk + asm out dx,ax + + asm push di + + block: + asm lodsw + asm mov cx,ax + asm and ch,0x3F + asm test ah,0xC0 + asm jz endpl + asm jns skip + asm jnp incsi // replicate? + asm add si,cx // skip over data block + asm dec si // fix it before following inc + + incsi: + asm inc si + tint: + asm mov al,es:[di] + //----------------------------------------------- + // asm xlat ss:0 // unsupported with BASM! + __emit__(0x36, 0xD7); // this stands for above! + //----------------------------------------------- + asm stosb + asm loop tint + asm jmp block + + skip: + asm add di,cx + asm jmp block + + endpl: + asm pop di + asm pop ax + asm inc rmsk + asm shl ah,1 + asm test ah,0x10 + asm jz x_chk + asm mov ah,0x01 + asm mov rmsk,0 + asm inc di + x_chk: + asm cmp ah,mask + asm jne plane + asm pop ds + asm pop si + asm pop bx +} + + + + + + +void BITMAP::Show (int x, int y) +{ + byte mask = 1 << (x & 3), + far * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); + byte far * v = V; + + asm push ds // preserve DS + + asm cld // normal direction + asm les di,scr // screen address + asm lds si,v // picture address + asm mov dx,VGASEQ_ // VGA reg + asm mov al,0x02 + asm mov ah,mask + + plane: + asm out dx,ax + asm push ax + asm push di + + block: + asm mov cx,[si] // with ADD faster then LODSW + asm add si,2 + asm test ch,0xC0 + asm jns skip // 1 (SKP) or 0 (EOI) + asm jpo repeat // 2 (REP) + + copy: // 3 (CPY) + asm and ch,0x3F + asm shr cx,1 + asm rep movsw + asm jnc block + asm movsb + asm jmp block + + repeat: + asm and ch,0x3F + asm mov al,[si] + asm inc si + asm mov ah,al + asm shr cx,1 + asm rep stosw + asm jnc block + asm mov es:[di],al + asm inc di + asm jmp block + + skip: + asm jz endpl + asm and ch,0x3F + asm add di,cx + asm jmp block + + endpl: + asm pop di + asm pop ax + asm shl ah,1 + asm test ah,0x10 + asm jz x_chk + asm mov ah,0x01 + asm inc di + x_chk: + asm cmp ah,mask + asm jne plane + asm pop ds +} + + + + + +void BITMAP::Hide (int x, int y) +{ + byte far * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; + word d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); + HideDesc far * b = B; + word extra = ((x & 3) != 0); + word h = H; + +// asm push bx + asm push si + asm push ds + + asm cld + asm les di,scr + asm mov si,di + asm add si,d // take bytes from background page + asm lds bx,b + + asm mov dx,VGAGRA_ + asm mov al,0x05 // R/W mode + asm out dx,al + asm inc dx + asm in al,dx + asm and al,0xF4 + asm push ax + asm push dx + asm or al,0x01 + asm out dx,al + + asm mov dx,VGASEQ_ + asm mov ax,0x0F02 // enable all planes + asm out dx,ax + + asm mov dx,ds // save DS + + row: +// skip block + asm mov cx,[bx] + asm add si,cx + asm add di,cx + asm mov cx,[bx+2] + asm add bx,4 + asm add cx,extra + + asm push es + asm pop ds // set DS to video seg + asm rep movsb // move bytes fast + asm sub si,extra + asm sub di,extra + asm mov ds,dx // restore DS + + asm dec h + asm jnz row + + asm pop dx + asm pop ax + asm out dx,al // end of copy mode + + + asm pop ds + asm pop si +// asm pop bx +} + + + + + + + +//-------------------------------------------------------------------------- + + + diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h new file mode 100644 index 00000000000..f3c17fa73e9 --- /dev/null +++ b/engines/cge/vga13h.h @@ -0,0 +1,310 @@ +#ifndef __VGA13H__ +#define __VGA13H__ + +#include +#include +#include +#include "bitmap.h" +#include "snail.h" + + +#define TMR_RATE1 16 +#define TMR_RATE2 4 +#define TMR_RATE (TMR_RATE1*TMR_RATE2) + +#define MAX_NAME 20 +#define VIDEO 0x10 + +#define NO_CLEAR 0x80 +#define TEXT_MODE 0x03 +#define M13H 0x13 + +#ifndef SCR_WID + #define SCR_WID 320 +#endif + +#ifndef SCR_HIG + #define SCR_HIG 200 +#endif + + +#if 0 + #define LIGHT 0xFF + #define DARK 0x00 + #define DGRAY 0xF6 + #define GRAY 0xFC + #define LGRAY 0xFF +#else + #define LIGHT 0xFF + #define DARK 207 + #define DGRAY 225 /*219*/ + #define GRAY 231 + #define LGRAY 237 +#endif + +#define NO_SEQ (-1) +#define NO_PTR ((byte)-1) + +#define SPR_EXT ".SPR" + +#define IsFile(s) (access(s,0)==0) +#define IsWrit(s) (access(s,2)==0) + + + +typedef struct { word r : 2; word R : 6; + word g : 2; word G : 6; + word b : 2; word B : 6; + } RGB; + +typedef union { + DAC dac; + RGB rgb; + } TRGB; + +typedef struct { byte idx, adr; byte clr, set; } VgaRegBlk; + +typedef struct { byte Now, Next; signed char Dx, Dy; int Dly; } SEQ; + +extern SEQ Seq1[]; +extern SEQ Seq2[]; +//extern SEQ * Compass[]; +//extern SEQ TurnToS[]; + + +#define PAL_CNT 256 +#define PAL_SIZ (PAL_CNT*sizeof(DAC)) + +#define VGAATR_ 0x3C0 +#define VGAMIw_ 0x3C0 +#define VGASEQ_ 0x3C4 +#define VGAMIr_ 0x3CC +#define VGAGRA_ 0x3CE +#define VGACRT_ 0x3D4 +#define VGAST1_ 0x3DA +#define VGAATR (VGAATR_ & 0xFF) +#define VGAMIw (VGAMIw_ & 0xFF) +#define VGASEQ (VGASEQ_ & 0xFF) +#define VGAMIr (VGAMIr_ & 0xFF) +#define VGAGRA (VGAGRA_ & 0xFF) +#define VGACRT (VGACRT_ & 0xFF) +#define VGAST1 (VGAST1_ & 0xFF) + + + + + + +class HEART : public ENGINE +{ + friend ENGINE; +public: + static Boolean Enable; + static word * XTimer; + static void SetXTimer (word * ptr); + static void SetXTimer (word * ptr, word time); + HEART (void); +}; + + + + + +class SPREXT +{ +public: + int x0, y0; + int x1, y1; + BMP_PTR b0, b1; + BMP_PTR * ShpList; + SEQ * Seq; + char * Name; + SNAIL::COM * Near, * Take; + SPREXT (void) : + x0(0), y0(0), + x1(0), y1(0), + b0(NULL), b1(NULL), + ShpList(NULL), Seq(NULL), + Name(NULL), Near(NULL), Take(NULL) + {} +}; + + + + +class SPRITE +{ +protected: + SPREXT * Ext; +public: + int Ref; + signed char Cave; + struct FLAGS { word Hide : 1; // general visibility switch + word Near : 1; // Near action lock + word Drag : 1; // sprite is moveable + word Hold : 1; // sprite is held with mouse + word ____ : 1; // intrrupt driven animation + word Slav : 1; // slave object + word Syst : 1; // system object + word Kill : 1; // dispose memory after remove + word Xlat : 1; // 2nd way display: xlat table + word Port : 1; // portable + word Kept : 1; // kept in pocket + word East : 1; // talk to east (in opposite to west) + word Shad : 1; // shadow + word Back : 1; // 'send to background' request + word BDel : 1; // delete bitmaps in ~SPRITE + word Tran : 1; // transparent (untouchable) + } Flags; + int X, Y; + signed char Z; + word W, H; + word Time; + byte NearPtr, TakePtr; + int SeqPtr; + int ShpCnt; + char File[MAXFILE]; + SPRITE * Prev, * Next; + Boolean Works (SPRITE * spr); + Boolean SeqTest (int n); + inline Boolean Active (void) { return Ext != NULL; } + SPRITE (BMP_PTR * shp); + virtual ~SPRITE (void); + BMP_PTR Shp (void); + BMP_PTR * SetShapeList (BMP_PTR * shp); + void MoveShapes (byte far * buf); + SPRITE * Expand (void); + SPRITE * Contract (void); + SPRITE * BackShow (Boolean fast = FALSE); + void SetName(char * n); + inline char * Name(void) { return (Ext) ? Ext->Name : NULL; } + void Goto (int x, int y); + void Center (void); + void Show (void); + void Hide (void); + BMP_PTR Ghost (void); + void Show (word pg); + void MakeXlat (byte far * x); + void KillXlat (void); + void Step (int nr = -1); + SEQ * SetSeq (SEQ * seq); + SNAIL::COM * SnList(SNLIST type); + virtual void Touch (word mask, int x, int y); + virtual void Tick (void); +}; + + + + + + +class QUEUE +{ + SPRITE * Head, * Tail; +public: + Boolean Show; + QUEUE (Boolean show = FALSE); + ~QUEUE (void); + void Append (SPRITE * spr); + void Insert (SPRITE * spr, SPRITE * nxt); + void Insert (SPRITE * spr); + SPRITE * Remove (SPRITE * spr); + void ForAll (void (*fun)(SPRITE *)); + SPRITE * First (void) { return Head; } + SPRITE * Last (void) { return Tail; } + SPRITE * Locate (int ref); + void Clear (void); +}; + + + + + + +class VGA +{ + static word OldMode; + static word far * OldScreen; + static word StatAdr; + static Boolean SetPal; + static DAC far * OldColors, far * NewColors; + static int SetMode (int mode); + static void UpdateColors (void); + static void SetColors (void); + static const char * Msg; + static const char * Nam; + static void SetStatAdr (void); + static void WaitVR (Boolean on = TRUE); +public: + dword FrmCnt; + static QUEUE ShowQ, SpareQ; + static int Mono; + static byte far * Page[4]; + VGA (int mode = M13H); + ~VGA (void); + void Setup (VgaRegBlk * vrb); + static void GetColors (DAC far * tab); + static void SetColors (DAC far * tab, int lum); + static void Clear (byte color = 0); + static void Exit (const char * txt = NULL, const char * name = NULL); + static void Exit (int tref, const char * name = NULL); + static void CopyPage (word d, word s = 3); + static void Sunrise (DAC far * tab); + static void Sunset (void); + void Show (void); + void Update (void); +}; + + + +DAC MkDAC (byte r, byte g, byte b); +RGB MkRGB (byte r, byte g, byte b); + + + + +template +byte Closest (CBLK far * pal, CBLK x) +{ + #define f(col,lum) ((((word)(col))<<8)/lum) + word i, dif = 0xFFFF, found; + word L = x.R + x.G + x.B; if (! L) ++ L; + word R = f(x.R, L), G = f(x.G, L), B = f(x.B, L); + for (i = 0; i < 256; i ++) + { + word l = pal[i].R + pal[i].G + pal[i].B; if (! l) ++ l; + int r = f(pal[i].R, l), g = f(pal[i].G, l), b = f(pal[i].B, l); + word D = ((r > R) ? (r - R) : (R - r)) + + ((g > G) ? (g - G) : (G - g)) + + ((b > B) ? (b - B) : (B - b)) + + ((l > L) ? (l - L) : (L - l)) * 10 ; + + if (D < dif) + { + found = i; + dif = D; + if (D == 0) break; // exact! + } + } + return found; + #undef f +}; + + + + + + + + char * NumStr (char * str, int num); + void Video (void); + word far * SaveScreen (void); + void RestoreScreen (word far * &sav); + SPRITE * SpriteAt (int x, int y); + SPRITE * Locate (int ref); + +extern Boolean SpeedTest; + + +#endif + \ No newline at end of file diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp new file mode 100644 index 00000000000..5dd3efb191e --- /dev/null +++ b/engines/cge/vmenu.cpp @@ -0,0 +1,149 @@ +#include "vmenu.h" +#include "mouse.h" +#include +#include + +//-------------------------------------------------------------------------- + + +#define RELIEF 1 +#if RELIEF + #define MB_LT LGRAY + #define MB_RB DGRAY +#else + #define MB_LT DGRAY + #define MB_RB LGRAY +#endif + + + + +MENU_BAR::MENU_BAR (word w) +{ + int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h; + byte far * p = farnew(byte, i), far * p1, far * p2; + + _fmemset(p+w, TRANS, i-2*w); + _fmemset(p, MB_LT, w); + _fmemset(p+i-w, MB_RB, w); + p1 = p; + p2 = p+i-1; + for (i = 0; i < h; i ++) + { + * p1 = MB_LT; + * p2 = MB_RB; + p1 += w; + p2 -= w; + } + TS[0] = new BITMAP(w, h, p); + SetShapeList(TS); + Flags.Slav = TRUE; + Flags.Tran = TRUE; + Flags.Kill = TRUE; + Flags.BDel = TRUE; +} + + + +//-------------------------------------------------------------------------- + +static char * vmgt; + + + +char * VMGather (CHOICE * list) +{ + CHOICE * cp; + int len = 0, h = 0; + + for (cp = list; cp->Text; cp ++) + { + len += strlen(cp->Text); + ++ h; + } + vmgt = new byte[len+h]; + if (vmgt) + { + *vmgt = '\0'; + for (cp = list; cp->Text; cp ++) + { + if (*vmgt) strcat(vmgt, "|"); + strcat(vmgt, cp->Text); + ++ h; + } + } + return vmgt; +} + + + + +VMENU * VMENU::Addr = NULL; +int VMENU::Recent = -1; + + + + +VMENU::VMENU (CHOICE * list, int x, int y) +: TALK(VMGather(list), RECT), Menu(list), Bar(NULL) +{ + CHOICE * cp; + + Addr = this; + delete[] vmgt; + Items = 0; + for (cp = list; cp->Text; cp ++) ++ Items; + Flags.BDel = TRUE; + Flags.Kill = TRUE; + if (x < 0 || y < 0) Center(); + else Goto(x - W / 2, y - (TEXT_VM + FONT_HIG / 2)); + VGA::ShowQ.Insert(this, VGA::ShowQ.Last()); + Bar = new MENU_BAR(W - 2 * TEXT_HM); + Bar->Goto(X + TEXT_HM - MB_HM, Y + TEXT_VM - MB_VM); + VGA::ShowQ.Insert(Bar, VGA::ShowQ.Last()); +} + + + + +VMENU::~VMENU (void) +{ + Addr = NULL; +} + + + + +void VMENU::Touch (word mask, int x, int y) +{ +#define h (FONT_HIG+TEXT_LS) + int n = 0; + Boolean ok = FALSE; + + if (Items) + { + SPRITE::Touch(mask, x, y); + + y -= TEXT_VM-1; + //if + if (y >= 0) + { + n = y / h; + if (n < Items) ok = (x >= TEXT_HM && x < W - TEXT_HM/* && y % h < FONT_HIG*/); + else n = Items-1; + } + + Bar->Goto(X + TEXT_HM - MB_HM, Y + TEXT_VM + n * h - MB_VM); + + if (ok && (mask & L_UP)) + { + Items = 0; + SNPOST_(SNKILL, -1, 0, this); + Menu[Recent = n].Proc(); + } + } +#undef h +} + + + diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h new file mode 100644 index 00000000000..c4d3a8df181 --- /dev/null +++ b/engines/cge/vmenu.h @@ -0,0 +1,45 @@ +#ifndef __VMENU__ +#define __VMENU__ + +#include "talk.h" + +#define MB_VM 1 +#define MB_HM 3 + + + +typedef struct { char * Text; void (* Proc)(void); } CHOICE; + + + + + + +class MENU_BAR : public TALK +{ +public: + MENU_BAR (word w); +}; + + + + + + + +class VMENU : public TALK +{ + word Items; + CHOICE * Menu; +public: + static VMENU * Addr; + static int Recent; + MENU_BAR * Bar; + VMENU (CHOICE * list, int x, int y); + ~VMENU (void); + void Touch (word mask, int x, int y); +}; + + + +#endif diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp new file mode 100644 index 00000000000..d0d8dce35ca --- /dev/null +++ b/engines/cge/vol.cpp @@ -0,0 +1,79 @@ +#include "vol.h" +#include +#include +#include +#include + +#ifdef DROP_H + #include "drop.h" +#else + #include + #define DROP(m,n) { printf("%s [%s]\n", (m), (n)); _exit(1); } +#endif + + + + +#ifdef VOL_UPD +BTFILE VFILE::Cat(CAT_NAME, UPD, CRP); +VOLBASE DAT::File(DAT_NAME, UPD, CRP); +#else +BTFILE VFILE::Cat(CAT_NAME, REA, CRP); +VOLBASE DAT::File(DAT_NAME, REA, CRP); +#endif +DAT VFILE::Dat; +VFILE * VFILE::Recent = NULL; + + + + + +VFILE::VFILE (const char * name, IOMODE mode) +: IOBUF(mode) +{ + if (mode == REA) + { + if (Dat.File.Error || Cat.Error) DROP("Bad volume data", NULL); + BT_KEYPACK far * kp = Cat.Find(name); + if (_fstricmp(kp->Key, name) != 0) Error = ENOFILE; + EndMark = (BufMark = BegMark = kp->Mark) + kp->Size; + } + #ifdef VOL_UPD + else Make(name); + #endif +} + + + + + +VFILE::~VFILE (void) +{ + if (Recent == this) Recent = NULL; +} + + + + + +Boolean VFILE::Exist (const char * name) +{ + return _fstricmp(Cat.Find(name)->Key, name) == 0; +} + + + + +void VFILE::ReadBuff (void) +{ + if (Recent != this) + { + Dat.File.Seek(BufMark + Lim); + Recent = this; + } + BufMark = Dat.File.Mark(); + long n = EndMark - BufMark; + if (n > IOBUF_SIZE) n = IOBUF_SIZE; + Lim = Dat.File.Read(Buff, (word) n); + Ptr = 0; +} diff --git a/engines/cge/vol.h b/engines/cge/vol.h new file mode 100644 index 00000000000..347b0b48fe4 --- /dev/null +++ b/engines/cge/vol.h @@ -0,0 +1,64 @@ +#ifndef __VOL__ +#define __VOL__ + + +#include +#include "btfile.h" +#include "cfile.h" + +#define CAT_NAME "VOL.CAT" +#define DAT_NAME "VOL.DAT" + +#ifndef CRP + #define CRP XCrypt +#endif + +#define XMASK 0xA5 + +#ifdef VOL_UPD +#define VOLBASE IOHAND +#else +#define VOLBASE CFILE +#endif + + + +class DAT +{ + friend VFILE; + static VOLBASE File; +public: + static Boolean Append (byte far * buf, word len); + static Boolean Write (CFILE& f); + static Boolean Read (long org, word len, byte far * buf); +}; + + + + + + + +class VFILE : public IOBUF +{ + static DAT Dat; + static BTFILE Cat; + static VFILE * Recent; + long BegMark, EndMark; + void ReadBuff (void); + void WriteBuff (void) { } + void Make(const char * fspec); +public: + VFILE (const char * name, IOMODE mode = REA); + ~VFILE (void); + static Boolean Exist (const char * name); + static const char * Next (void); + long Mark (void) { return (BufMark+Ptr) - BegMark; } + long Size (void) { return EndMark - BegMark; } + long Seek (long pos) { Recent = NULL; Lim = 0; return (BufMark = BegMark+pos); } +}; + + + + +#endif diff --git a/engines/cge/wav.h b/engines/cge/wav.h new file mode 100644 index 00000000000..c32178420c0 --- /dev/null +++ b/engines/cge/wav.h @@ -0,0 +1,109 @@ +#ifndef __WAV__ +#define __WAV__ + +#include +#include + +#define WAVE_FORMAT_PCM 0x0001 +#define IBM_FORMAT_MULAW 0x0101 +#define IBM_FORMAT_ALAW 0x0102 +#define IBM_FORMAT_ADPCM 0x0103 + + + +typedef char FOURCC[4]; // Four-character code +typedef dword CKSIZE; // 32-bit unsigned size + + +class CKID // Chunk type identifier +{ + union { FOURCC Tx; dword Id; }; +protected: + static XFILE * ckFile; +public: + CKID (FOURCC t) { memcpy(Tx, t, sizeof(Tx)); } + CKID (dword d) { Id = d; } + CKID (XFILE * xf) { (ckFile = xf)->Read(Tx, sizeof(Tx)); } + Boolean operator !=(CKID& X) { return Id != X.Id; } + Boolean operator ==(CKID& X) { return Id == X.Id; } + const char * Name (void); +}; + + + + +class CKHEA : public CKID +{ +protected: + CKSIZE ckSize; // Chunk size field (size of ckData) +public: + CKHEA (XFILE * xf) : CKID(xf) { XRead(xf, &ckSize); } + CKHEA (char id[]) : CKID(id), ckSize(0) { } + void Skip (void); + CKSIZE Size (void) { return ckSize; } +}; + + + + + +class FMTCK : public CKHEA +{ + struct WAV + { + word wFormatTag; // Format category + word wChannels; // Number of channels + dword dwSamplesPerSec; // Sampling rate + dword dwAvgBytesPerSec; // For buffer estimation + word wBlockAlign; // Data block size + } Wav; + + union + { + struct PCM + { + word wBitsPerSample; // Sample size + } Pcm; + }; +public: + FMTCK (CKHEA& hea); + inline word Channels (void) { return Wav.wChannels; } + inline dword SmplRate (void) { return Wav.dwSamplesPerSec; } + inline dword ByteRate (void) { return Wav.dwAvgBytesPerSec; } + inline word BlckSize (void) { return Wav.wBlockAlign; } + inline word SmplSize (void) { return Pcm.wBitsPerSample; } +}; + + + + + +class DATACK : public CKHEA +{ + Boolean e; + union + { + byte far * Buf; + EMS * EBuf; + }; +public: + DATACK (CKHEA& hea); + DATACK (CKHEA& hea, EMM * emm); + DATACK (int first, int last); + ~DATACK (void); + inline byte far * Addr (void) { return Buf; } + inline EMS * EAddr (void) { return EBuf; } +}; + + + +extern CKID RIFF; +extern CKID WAVE; +extern CKID FMT; +extern CKID DATA; + + +DATACK * LoadWave (XFILE * file, EMM * emm = NULL); + + +#endif From 03c540abffe39a7ea32173c2cf8f5e70d371588b Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 10 Jun 2011 07:45:18 +0200 Subject: [PATCH 003/276] CGE: Add default header, fix some includes --- engines/cge/bitmap.cpp | 35 +++++++++++++++++++--- engines/cge/bitmap.h | 29 +++++++++++++++++- engines/cge/bitmaps.cpp | 29 +++++++++++++++++- engines/cge/bitmaps.h | 29 +++++++++++++++++- engines/cge/boot.h | 29 +++++++++++++++++- engines/cge/cfile.cpp | 29 +++++++++++++++++- engines/cge/cfile.h | 29 +++++++++++++++++- engines/cge/cge_main.cpp | 65 ++++++++++++++++++++++++++++------------ engines/cge/cge_main.h | 27 +++++++++++++++++ engines/cge/drop.h | 29 +++++++++++++++++- engines/cge/game.cpp | 31 +++++++++++++++++-- engines/cge/game.h | 31 +++++++++++++++++-- engines/cge/general.h | 37 +++++++++++++++++++---- engines/cge/gettext.cpp | 33 ++++++++++++++++++-- engines/cge/gettext.h | 31 +++++++++++++++++-- engines/cge/ident.h | 27 +++++++++++++++++ engines/cge/jbw.h | 29 +++++++++++++++++- engines/cge/keybd.cpp | 31 +++++++++++++++++-- engines/cge/keybd.h | 31 +++++++++++++++++-- engines/cge/mixer.cpp | 35 +++++++++++++++++++--- engines/cge/mixer.h | 29 +++++++++++++++++- engines/cge/mouse.cpp | 31 +++++++++++++++++-- engines/cge/mouse.h | 31 +++++++++++++++++-- engines/cge/snail.cpp | 45 ++++++++++++++++++++++------ engines/cge/snail.h | 29 +++++++++++++++++- engines/cge/snddrv.h | 27 +++++++++++++++++ engines/cge/sound.cpp | 41 ++++++++++++++++++++----- engines/cge/sound.h | 31 +++++++++++++++++-- engines/cge/startup.cpp | 39 ++++++++++++++++++++---- engines/cge/startup.h | 29 +++++++++++++++++- engines/cge/talk.cpp | 37 +++++++++++++++++++---- engines/cge/talk.h | 29 +++++++++++++++++- engines/cge/text.cpp | 41 ++++++++++++++++++++----- engines/cge/text.h | 31 +++++++++++++++++-- engines/cge/vga13h.cpp | 37 +++++++++++++++++++---- engines/cge/vga13h.h | 33 ++++++++++++++++++-- engines/cge/vmenu.cpp | 31 +++++++++++++++++-- engines/cge/vmenu.h | 29 +++++++++++++++++- engines/cge/vol.cpp | 31 +++++++++++++++++-- engines/cge/vol.h | 31 +++++++++++++++++-- engines/cge/wav.h | 29 +++++++++++++++++- 41 files changed, 1222 insertions(+), 115 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index f3a7f853313..d493f29f561 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -1,12 +1,39 @@ -#include "bitmap.h" -#include +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/bitmap.h" +#include "cge/cfile.h" #ifdef VOL - #include "vol.h" + #include "cge/vol.h" #endif #ifdef DROP_H - #include "drop.h" + #include "cge/drop.h" #endif diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 10d85430dc8..a6a3dc75398 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -1,7 +1,34 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __BITMAP__ #define __BITMAP__ -#include +#include "cge/general.h" #define EOI 0x0000 #define SKP 0x4000 diff --git a/engines/cge/bitmaps.cpp b/engines/cge/bitmaps.cpp index 2f79599c877..4749430c5b6 100644 --- a/engines/cge/bitmaps.cpp +++ b/engines/cge/bitmaps.cpp @@ -1,4 +1,31 @@ -#include "bitmaps.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/bitmaps.h" /* #define W 255, diff --git a/engines/cge/bitmaps.h b/engines/cge/bitmaps.h index ef02c034e13..65f586a3555 100644 --- a/engines/cge/bitmaps.h +++ b/engines/cge/bitmaps.h @@ -1,7 +1,34 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __BITMAPS__ #define __BITMAPS__ -#include "vga13h.h" +#include "cge/vga13h.h" #ifdef DEBUG extern BITMAP * MB[]; diff --git a/engines/cge/boot.h b/engines/cge/boot.h index 18c7cd2499b..6b9b2c88ecc 100644 --- a/engines/cge/boot.h +++ b/engines/cge/boot.h @@ -1,7 +1,34 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __BOOT__ #define __BOOT__ -#include +#include "cge/jbw.h" #define BOOTSECT_SIZ 512 #define BOOTHEAD_SIZ 62 diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 53b845b89fb..03df3032453 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -1,3 +1,30 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #include #include #include @@ -5,7 +32,7 @@ #include #ifdef DROP_H - #include "drop.h" + #include "cge/drop.h" #else #include #include diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index 57ff38831cd..56a249d9c0e 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -1,7 +1,34 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __CFILE__ #define __CFILE__ -#include +#include "cge/general.h" #include diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 23865ec3868..bc19156ad5b 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1,22 +1,49 @@ -#include "cge\general.h" -#include "cge\boot.h" -#include "cge\ident.h" -#include "cge\sound.h" -#include "cge\startup.h" -#include "cge\config.h" -#include "cge\vga13h.h" -#include "cge\snail.h" -#include "cge\text.h" -#include "cge\game.h" -#include "cge\mouse.h" -#include "cge\keybd.h" -#include "cge\cfile.h" -#include "cge\vol.h" -#include "cge\talk.h" -#include "cge\vmenu.h" -#include "cge\gettext.h" -#include "cge\mixer.h" -#include "cge\cge_main.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/general.h" +#include "cge/boot.h" +#include "cge/ident.h" +#include "cge/sound.h" +#include "cge/startup.h" +#include "cge/config.h" +#include "cge/vga13h.h" +#include "cge/snail.h" +#include "cge/text.h" +#include "cge/game.h" +#include "cge/mouse.h" +#include "cge/keybd.h" +#include "cge/cfile.h" +#include "cge/vol.h" +#include "cge/talk.h" +#include "cge/vmenu.h" +#include "cge/gettext.h" +#include "cge/mixer.h" +#include "cge/cge_main.h" #include #include #include diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index f5c104600ad..7a213429b1c 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -1,3 +1,30 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __CGE__ #define __CGE__ diff --git a/engines/cge/drop.h b/engines/cge/drop.h index e79b2eb8992..bdd08b6810f 100644 --- a/engines/cge/drop.h +++ b/engines/cge/drop.h @@ -1 +1,28 @@ -#include "vga13h.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/vga13h.h" diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 4ac27651b72..bf7bd850f59 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -1,5 +1,32 @@ -#include "game.h" -#include "mouse.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/game.h" +#include "cge/mouse.h" #include #include diff --git a/engines/cge/game.h b/engines/cge/game.h index 92ad49b2a44..e675d15a7ce 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -1,8 +1,35 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __GAME__ #define __GAME__ -#include "vga13h.h" -#include "bitmaps.h" +#include "cge/vga13h.h" +#include "cge/bitmaps.h" diff --git a/engines/cge/general.h b/engines/cge/general.h index 7e9551e0769..71d9d96bdf2 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -1,3 +1,30 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __GENERAL__ #define __GENERAL__ @@ -24,7 +51,7 @@ typedef struct { byte R, G, B; } DAC; -typedef word CRYPT (void far * buf, word siz, word seed); +typedef word CRYPT (void *buf, word siz, word seed); @@ -206,7 +233,7 @@ CRYPT XCrypt; CRYPT RXCrypt; CRYPT RCrypt; -MEM_TYPE MemType (void far * mem); +MEM_TYPE MemType (void *mem); unsigned FastRand (void); unsigned FastRand (unsigned s); CPU Cpu (void); @@ -220,7 +247,7 @@ void StdLog (const char *msg, const char *nam = NULL); void StdLog (const char *msg, word w); void StdLog (const char *msg, dword d); int TakeEnum (const char ** tab, const char * txt); -word ChkSum (void far * m, word n); +word ChkSum (void *m, word n); long Timer (void); long TimerLimit (word t); Boolean TimerLimitGone (long t); @@ -233,8 +260,8 @@ int DriveRemote (unsigned drv); int DriveCD (unsigned drv); Boolean IsVga (void); -EC void _fqsort (void far *base, word nelem, word width, - int (*fcmp)(const void far *, const void far *)); +EC void _fqsort (void *base, word nelem, word width, + int (*fcmp)(const void*, const void*)); diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 69350b5fc8e..5d6c8ce1bf9 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -1,6 +1,33 @@ -#include "gettext.h" -#include "keybd.h" -#include "mouse.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/gettext.h" +#include "cge/keybd.h" +#include "cge/mouse.h" #include diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h index 8d4e15c6cb8..2fbd6f5da66 100644 --- a/engines/cge/gettext.h +++ b/engines/cge/gettext.h @@ -1,8 +1,35 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __GETTEXT__ #define __GETTEXT__ -#include -#include "talk.h" +#include "cge/general.h" +#include "cge/talk.h" #define GTMAX 24 diff --git a/engines/cge/ident.h b/engines/cge/ident.h index 5370b9638cf..fa3011b49c1 100644 --- a/engines/cge/ident.h +++ b/engines/cge/ident.h @@ -1,3 +1,30 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __IDENT__ #define __IDENT__ diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 98ce9e27b5c..cb2cb54fece 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -1,3 +1,30 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __JBW__ #define __JBW__ @@ -34,7 +61,7 @@ typedef int Boolean; typedef unsigned char byte; typedef unsigned int word; typedef unsigned long dword; -typedef void (far _loadds MouseFunType)(void); +typedef void (_loadds MouseFunType)(void); #define Lo(d) (((int *) &d)[0]) #define Hi(d) (((int *) &d)[1]) diff --git a/engines/cge/keybd.cpp b/engines/cge/keybd.cpp index 9986ad0b5d4..37a1e1d798d 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/keybd.cpp @@ -1,5 +1,32 @@ -#include "keybd.h" -#include "mouse.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/keybd.h" +#include "cge/mouse.h" #include diff --git a/engines/cge/keybd.h b/engines/cge/keybd.h index 744dc8c8acf..42c80f88e1b 100644 --- a/engines/cge/keybd.h +++ b/engines/cge/keybd.h @@ -1,8 +1,35 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __KEYBD__ #define __KEYBD__ -#include -#include "vga13h.h" +#include "cge/jbw.h" +#include "cge/vga13h.h" #define KEYBD_INT 9 diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 7a494d0b904..1e7aa7a1816 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -1,7 +1,34 @@ -#include "mixer.h" -#include "text.h" -#include "snail.h" -#include "mouse.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/mixer.h" +#include "cge/text.h" +#include "cge/snail.h" +#include "cge/mouse.h" #include #include #include diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index 8ee2bb6f805..bf5d79b67f5 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -1,7 +1,34 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __MIXER__ #define __MIXER__ -#include "vga13h.h" +#include "cge/vga13h.h" #define MIX_MAX 16 // count of Leds #define MIX_Z 64 // mixer Z position diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index 703fd80f652..b9a03868012 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -1,5 +1,32 @@ -#include "mouse.h" -#include "text.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/mouse.h" +#include "cge/text.h" #include diff --git a/engines/cge/mouse.h b/engines/cge/mouse.h index 9f51456baf9..f3b83f3f2e1 100644 --- a/engines/cge/mouse.h +++ b/engines/cge/mouse.h @@ -1,8 +1,35 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __MOUSE__ #define __MOUSE__ -#include "game.h" -#include "talk.h" +#include "cge/game.h" +#include "cge/talk.h" #define EVT_MAX 256 diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index d6b2528310f..82f9416af7c 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -1,18 +1,45 @@ -#include -#include "sound.h" -#include "snail.h" -#include "vga13h.h" -#include "bitmaps.h" -#include "text.h" -#include "mouse.h" -#include "cge.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/general.h" +#include "cge/sound.h" +#include "cge/snail.h" +#include "cge/vga13h.h" +#include "cge/bitmaps.h" +#include "cge/text.h" +#include "cge/mouse.h" +#include "cge/cge_main.h" #include #include #include #include #include -#include "keybd.h" +#include "cge/keybd.h" int MaxCave = 0; diff --git a/engines/cge/snail.h b/engines/cge/snail.h index f1b0ab762f5..66a40e8382d 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -1,7 +1,34 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __SNAIL__ #define __SNAIL__ -#include +#include "cge/jbw.h" #define POCKET_X 174 #define POCKET_Y 176 diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 69ea3c2b158..910148c71eb 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -1,3 +1,30 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + // ****************************************************** // * Sound Driver by Hedges (c) 1995 LK AVALON * // * Ver 1.00: 01-Mar-95 * diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index f4fc27ddd7a..cd0101204d8 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -1,18 +1,45 @@ -#include -#include "startup.h" -#include "sound.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/general.h" +#include "cge/startup.h" +#include "cge/sound.h" #ifdef DROP_H - #include "drop.h" + #include "cge/drop.h" #else #include #include #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } #endif -#include "text.h" -#include -#include "vol.h" +#include "cge/text.h" +#include "cge/cfile.h" +#include "cge/vol.h" #include diff --git a/engines/cge/sound.h b/engines/cge/sound.h index b4efd998087..b43a85dd413 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -1,8 +1,35 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __SOUND__ #define __SOUND__ -#include -#include +#include "cge/wav.h" +#include "cge/snddrv.h" #define BAD_SND_TEXT 97 diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 3557891a036..a92e899ee22 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -1,9 +1,36 @@ -#include "startup.h" -#include "text.h" -#include "sound.h" -#include "ident.h" -#include -#include +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/startup.h" +#include "cge/text.h" +#include "cge/sound.h" +#include "cge/ident.h" +#include "cge/cfile.h" +#include "cge/snddrv.h" #include #include #include diff --git a/engines/cge/startup.h b/engines/cge/startup.h index 6db566a7812..bdb2647ab12 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -1,8 +1,35 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __STARTUP__ #define __STARTUP__ -#include +#include "cge/general.h" #define GAME_ID 45 #define CDINI_FNAME 46 diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index a018761000f..3a4ea5bbc2f 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -1,8 +1,35 @@ -#include -#include "talk.h" -#include "vol.h" -#include "game.h" -#include "mouse.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/general.h" +#include "cge/talk.h" +#include "cge/vol.h" +#include "cge/game.h" +#include "cge/mouse.h" #include #include #include diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 12b0b94dde5..8129b01bd97 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -1,7 +1,34 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __TALK__ #define __TALK__ -#include "vga13h.h" +#include "cge/vga13h.h" #include diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index a18eec5baf4..b4b6e9b23ca 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -1,10 +1,37 @@ -#include -#include "text.h" -#include "talk.h" -#include "vol.h" -#include "bitmaps.h" -#include "game.h" -#include "snail.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/general.h" +#include "cge/text.h" +#include "cge/talk.h" +#include "cge/vol.h" +#include "cge/bitmaps.h" +#include "cge/game.h" +#include "cge/snail.h" #include #include #include diff --git a/engines/cge/text.h b/engines/cge/text.h index d960fbef912..c6e6a1491ee 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -1,8 +1,35 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __TEXT__ #define __TEXT__ -#include "talk.h" -#include +#include "cge/talk.h" +#include "cge/jbw.h" #include diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 227304668b9..404b4f8bf85 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1,8 +1,35 @@ -#include -#include "vga13h.h" -#include "bitmap.h" -#include "vol.h" -#include "text.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/general.h" +#include "cge/vga13h.h" +#include "cge/bitmap.h" +#include "cge/vol.h" +#include "cge/text.h" #include #include #include diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index f3c17fa73e9..a749b482b77 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -1,11 +1,38 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __VGA13H__ #define __VGA13H__ -#include +#include "cge/general.h" #include #include -#include "bitmap.h" -#include "snail.h" +#include "cge/bitmap.h" +#include "cge/snail.h" #define TMR_RATE1 16 diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 5dd3efb191e..ccfe273923e 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -1,5 +1,32 @@ -#include "vmenu.h" -#include "mouse.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/vmenu.h" +#include "cge/mouse.h" #include #include diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index c4d3a8df181..23c354b504f 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -1,7 +1,34 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __VMENU__ #define __VMENU__ -#include "talk.h" +#include "cge/talk.h" #define MB_VM 1 #define MB_HM 3 diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index d0d8dce35ca..6816f2de901 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -1,11 +1,38 @@ -#include "vol.h" +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/vol.h" #include #include #include #include #ifdef DROP_H - #include "drop.h" + #include "cge/drop.h" #else #include #define DROP(m,n) { printf("%s [%s]\n", (m), (n)); _exit(1); } diff --git a/engines/cge/vol.h b/engines/cge/vol.h index 347b0b48fe4..80cd759a470 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -1,10 +1,37 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __VOL__ #define __VOL__ #include -#include "btfile.h" -#include "cfile.h" +#include "cge/btfile.h" +#include "cge/cfile.h" #define CAT_NAME "VOL.CAT" #define DAT_NAME "VOL.DAT" diff --git a/engines/cge/wav.h b/engines/cge/wav.h index c32178420c0..22dd79c4f58 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -1,7 +1,34 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + #ifndef __WAV__ #define __WAV__ -#include +#include "cge/general.h" #include #define WAVE_FORMAT_PCM 0x0001 From a5c569eff2c4e2f30ef0523169ab22ed92f9894a Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 10 Jun 2011 09:14:43 +0200 Subject: [PATCH 004/276] CGE: Remove far and near keywords --- engines/cge/bitmap.cpp | 66 ++++++++++++++++++++-------------------- engines/cge/bitmap.h | 8 ++--- engines/cge/cfile.cpp | 22 +++++++------- engines/cge/cfile.h | 14 ++++----- engines/cge/cge_main.cpp | 24 +++++++-------- engines/cge/game.cpp | 4 +-- engines/cge/game.h | 4 +-- engines/cge/general.h | 18 +++++------ engines/cge/jbw.h | 12 ++++---- engines/cge/keybd.cpp | 2 +- engines/cge/keybd.h | 2 +- engines/cge/mouse.h | 2 +- engines/cge/snail.cpp | 10 +++--- engines/cge/snail.h | 4 +-- engines/cge/snddrv.h | 4 +-- engines/cge/sound.cpp | 12 ++++---- engines/cge/talk.cpp | 18 +++++------ engines/cge/talk.h | 6 ++-- engines/cge/vga13h.cpp | 66 ++++++++++++++++++++-------------------- engines/cge/vga13h.h | 22 +++++++------- engines/cge/vmenu.cpp | 2 +- engines/cge/vol.cpp | 2 +- engines/cge/vol.h | 4 +-- engines/cge/wav.h | 4 +-- 24 files changed, 166 insertions(+), 166 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index d493f29f561..697eb4a9e3d 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -48,7 +48,7 @@ -DAC far * BITMAP::Pal = NULL; +DAC * BITMAP::Pal = NULL; @@ -97,7 +97,7 @@ BITMAP::BITMAP (const char * fname, Boolean rem) -BITMAP::BITMAP (word w, word h, byte far * map) +BITMAP::BITMAP (word w, word h, byte * map) : W(w), H(h), M(map), V(NULL) { if (map) Code(); @@ -147,15 +147,15 @@ BITMAP::BITMAP (const BITMAP& bmp) : W(bmp.W), H(bmp.H), M(NULL), V(NULL) { - byte far * v0 = bmp.V; + byte * v0 = bmp.V; if (v0) { word vsiz = FP_OFF(bmp.B) - FP_OFF(v0); word siz = vsiz + H * sizeof(HideDesc); - byte far * v1 = farnew(byte, siz); + byte * v1 = farnew(byte, siz); if (v1 == NULL) DROP("No core", NULL); _fmemcpy(v1, v0, siz); - B = (HideDesc far *) ((V = v1) + vsiz); + B = (HideDesc *) ((V = v1) + vsiz); } } @@ -180,7 +180,7 @@ BITMAP::~BITMAP (void) BITMAP& BITMAP::operator = (const BITMAP& bmp) { - byte far * v0 = bmp.V; + byte * v0 = bmp.V; W = bmp.W; H = bmp.H; M = NULL; @@ -190,10 +190,10 @@ BITMAP& BITMAP::operator = (const BITMAP& bmp) { word vsiz = FP_OFF(bmp.B) - FP_OFF(v0); word siz = vsiz + H * sizeof(HideDesc); - byte far * v1 = farnew(byte, siz); + byte * v1 = farnew(byte, siz); if (v1 == NULL) DROP("No core", NULL); _fmemcpy(v1, v0, siz); - B = (HideDesc far *) ((V = v1) + vsiz); + B = (HideDesc *) ((V = v1) + vsiz); } return *this; } @@ -202,7 +202,7 @@ BITMAP& BITMAP::operator = (const BITMAP& bmp) -word BITMAP::MoveVmap (byte far * buf) +word BITMAP::MoveVmap (byte * buf) { if (V) { @@ -210,7 +210,7 @@ word BITMAP::MoveVmap (byte far * buf) word siz = vsiz + H * sizeof(HideDesc); _fmemcpy(buf, V, siz); if (MemType(V) == FAR_MEM) farfree(V); - B = (HideDesc far *) ((V = buf) + vsiz); + B = (HideDesc *) ((V = buf) + vsiz); return siz; } return 0; @@ -240,8 +240,8 @@ BMP_PTR BITMAP::Code (void) while (TRUE) // at most 2 times: for (V == NULL) & for allocated block; { - byte far * im = V+2; - word far * cp = (word far *) V; + byte * im = V+2; + word * cp = (word *) V; int bpl; if (V) // 2nd pass - fill the hide table @@ -254,7 +254,7 @@ BMP_PTR BITMAP::Code (void) } for (bpl = 0; bpl < 4; bpl ++) // once per each bitplane { - byte far * bm = M; + byte * bm = M; Boolean skip = (bm[bpl] == TRANS); word j; @@ -277,7 +277,7 @@ BMP_PTR BITMAP::Code (void) { *cp = cnt; // store block description word } - cp = (word far *) im; + cp = (word *) im; im += 2; skip = (pix == TRANS); cnt = 0; @@ -304,7 +304,7 @@ BMP_PTR BITMAP::Code (void) { *cp = cnt; } - cp = (word far *) im; + cp = (word *) im; im += 2; skip = TRUE; cnt = (SCR_WID - j + 3) / 4; @@ -318,11 +318,11 @@ BMP_PTR BITMAP::Code (void) { *cp = cnt; } - cp = (word far *) im; + cp = (word *) im; im += 2; } if (V) *cp = EOI; - cp = (word far *) im; + cp = (word *) im; im += 2; } if (V) break; @@ -332,7 +332,7 @@ BMP_PTR BITMAP::Code (void) { DROP("No core", NULL); } - B = (HideDesc far *) (V + sizV); + B = (HideDesc *) (V + sizV); } cnt = 0; for (i = 0; i < H; i ++) @@ -362,7 +362,7 @@ BMP_PTR BITMAP::Code (void) Boolean BITMAP::SolidAt (int x, int y) { - byte far * m; + byte * m; word r, n, n0; if (x >= W || y >= H) return FALSE; @@ -375,7 +375,7 @@ Boolean BITMAP::SolidAt (int x, int y) { word w, t; - w = * (word far *) m; + w = * (word *) m; m += 2; t = w & 0xC000; w &= 0x3FFF; @@ -393,7 +393,7 @@ Boolean BITMAP::SolidAt (int x, int y) { word w, t; - w = * (word far *) m; + w = * (word *) m; m += 2; t = w & 0xC000; w &= 0x3FFF; @@ -419,12 +419,12 @@ Boolean BITMAP::SolidAt (int x, int y) Boolean BITMAP::VBMSave (XFILE * f) { word p = (Pal != NULL), - n = ((word) (((byte far *)B) - V)) + H * sizeof(HideDesc); - if (f->Error == 0) f->Write((byte far *)&p, sizeof(p)); - if (f->Error == 0) f->Write((byte far *)&n, sizeof(n)); - if (f->Error == 0) f->Write((byte far *)&W, sizeof(W)); - if (f->Error == 0) f->Write((byte far *)&H, sizeof(H)); - if (f->Error == 0) if (p) f->Write((byte far *)Pal, 256 * sizeof(DAC)); + n = ((word) (((byte *)B) - V)) + H * sizeof(HideDesc); + if (f->Error == 0) f->Write((byte *)&p, sizeof(p)); + if (f->Error == 0) f->Write((byte *)&n, sizeof(n)); + if (f->Error == 0) f->Write((byte *)&W, sizeof(W)); + if (f->Error == 0) f->Write((byte *)&H, sizeof(H)); + if (f->Error == 0) if (p) f->Write((byte *)Pal, 256 * sizeof(DAC)); if (f->Error == 0) f->Write(V, n); return (f->Error == 0); } @@ -436,21 +436,21 @@ Boolean BITMAP::VBMSave (XFILE * f) Boolean BITMAP::VBMLoad (XFILE * f) { word p, n; - if (f->Error == 0) f->Read((byte far *)&p, sizeof(p)); - if (f->Error == 0) f->Read((byte far *)&n, sizeof(n)); - if (f->Error == 0) f->Read((byte far *)&W, sizeof(W)); - if (f->Error == 0) f->Read((byte far *)&H, sizeof(H)); + if (f->Error == 0) f->Read((byte *)&p, sizeof(p)); + if (f->Error == 0) f->Read((byte *)&n, sizeof(n)); + if (f->Error == 0) f->Read((byte *)&W, sizeof(W)); + if (f->Error == 0) f->Read((byte *)&H, sizeof(H)); if (f->Error == 0) { if (p) { - if (Pal) f->Read((byte far *)Pal, 256 * sizeof(DAC)); + if (Pal) f->Read((byte *)Pal, 256 * sizeof(DAC)); else f->Seek(f->Mark() + 256 * sizeof(DAC)); } } if ((V = farnew(byte, n)) == NULL) return FALSE; if (f->Error == 0) f->Read(V, n); - B = (HideDesc far *) (V + n - H * sizeof(HideDesc)); + B = (HideDesc *) (V + n - H * sizeof(HideDesc)); return (f->Error == 0); } diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index a6a3dc75398..738b3ab4efd 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -58,11 +58,11 @@ class BITMAP Boolean BMPLoad (XFILE * f); Boolean VBMLoad (XFILE * f); public: - static DAC far * Pal; + static DAC * Pal; word W, H; - byte far * M, far * V; HideDesc far * B; + byte * M, * V; HideDesc * B; BITMAP (const char * fname, Boolean rem = TRUE); - BITMAP (word w, word h, byte far * map); + BITMAP (word w, word h, byte * map); BITMAP (word w, word h, byte fill); BITMAP (const BITMAP& bmp); ~BITMAP (void); @@ -74,7 +74,7 @@ public: void XShow (int x, int y); Boolean SolidAt (int x, int y); Boolean VBMSave (XFILE * f); - word MoveVmap (byte far * buf); + word MoveVmap (byte * buf); }; diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 03df3032453..0aa7c20a891 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -114,7 +114,7 @@ void IOBUF::WriteBuff (void) -word IOBUF::Read (void far * buf, word len) +word IOBUF::Read (void *buf, word len) { word total = 0; while (len) @@ -125,7 +125,7 @@ word IOBUF::Read (void far * buf, word len) { if (len < n) n = len; _fmemcpy(buf, Buff+Ptr, n); - (byte far *) buf += n; + (byte *) buf += n; len -= n; total += n; Ptr += n; @@ -140,21 +140,21 @@ word IOBUF::Read (void far * buf, word len) -word IOBUF::Read (byte far * buf) +word IOBUF::Read (byte * buf) { word total = 0; while (total < LINE_MAX-2) { if (Ptr >= Lim) ReadBuff(); - byte far * p = Buff + Ptr; + byte * p = Buff + Ptr; word n = Lim - Ptr; if (n) { if (total + n >= LINE_MAX-2) n = LINE_MAX-2 - total; - byte far * eol = (byte far *) _fmemchr(p, '\r', n); + byte * eol = (byte *) _fmemchr(p, '\r', n); if (eol) n = (word) (eol - p); - byte far * eof = (byte far *) _fmemchr(p, '\32', n); + byte * eof = (byte *) _fmemchr(p, '\32', n); if (eof) // end-of-file { n = (word) (eof - p); @@ -187,7 +187,7 @@ word IOBUF::Read (byte far * buf) -word IOBUF::Write (void far * buf, word len) +word IOBUF::Write (void * buf, word len) { word tot = 0; while (len) @@ -199,7 +199,7 @@ word IOBUF::Write (void far * buf, word len) _fmemcpy(Buff+Lim, buf, n); Lim += n; len -= n; - (byte far *) buf += n; + (byte *) buf += n; tot += n; } else WriteBuff(); @@ -212,12 +212,12 @@ word IOBUF::Write (void far * buf, word len) -word IOBUF::Write (byte far * buf) +word IOBUF::Write (byte * buf) { word len = 0; if (buf) { - len = _fstrlen((const char far *) buf); + len = _fstrlen((const char *) buf); if (len) if (buf[len-1] == '\n') -- len; len = Write(buf, len); if (len) @@ -273,7 +273,7 @@ void IOBUF::Write (byte b) -CFILE::CFILE (const char near * name, IOMODE mode, CRYPT * crpt) +CFILE::CFILE (const char * name, IOMODE mode, CRYPT * crpt) : IOBUF(name, mode, crpt) { } diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index 56a249d9c0e..5903d605ed4 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -38,7 +38,7 @@ #define IOBUF_SIZE K(2) #endif -#define CFREAD(x) Read((byte far *)(x),sizeof(*(x))) +#define CFREAD(x) Read((byte *)(x),sizeof(*(x))) @@ -46,7 +46,7 @@ class IOBUF : public IOHAND { protected: - byte far * Buff; + byte * Buff; word Ptr, Lim; long BufMark; word Seed; @@ -57,11 +57,11 @@ public: IOBUF (IOMODE mode, CRYPT * crpt = NULL); IOBUF (const char * name, IOMODE mode, CRYPT * crpt = NULL); virtual ~IOBUF (void); - word Read (void far * buf, word len); - word Read (char far * buf); + word Read (void * buf, word len); + word Read (char * buf); int Read (void); - word Write (void far * buf, word len); - word Write (byte far * buf); + word Write (void * buf, word len); + word Write (byte * buf); void Write (byte b); }; @@ -71,7 +71,7 @@ class CFILE : public IOBUF { public: static word MaxLineLen; - CFILE (const char near * name, IOMODE mode = REA, CRYPT * crpt = NULL); + CFILE (const char * name, IOMODE mode = REA, CRYPT * crpt = NULL); virtual ~CFILE (void); void Flush (void); long Mark (void); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index bc19156ad5b..2bb7ac5c65e 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -285,10 +285,10 @@ static void LoadGame (XFILE& file, Boolean tiny = FALSE) for (st = SavTab; st->Ptr; st ++) { if (file.Error) VGA::Exit("Bad SVG"); - file.Read((byte far *) ((tiny || st->Flg) ? st->Ptr : &i), st->Len); + file.Read((byte *) ((tiny || st->Flg) ? st->Ptr : &i), st->Len); } - file.Read((byte far *) &i, sizeof(i)); + file.Read((byte *) &i, sizeof(i)); if (i != SVGCHKSUM) VGA::Exit(BADSVG_TEXT); if (STARTUP::Core < CORE_HIG) Music = FALSE; if (STARTUP::SoundOk == 1 && STARTUP::Mode == 0) @@ -303,7 +303,7 @@ static void LoadGame (XFILE& file, Boolean tiny = FALSE) while (! file.Error) { SPRITE S(NULL); - word n = file.Read((byte far *) &S, sizeof(S)); + word n = file.Read((byte *) &S, sizeof(S)); if (n != sizeof(S)) break; S.Prev = S.Next = NULL; @@ -354,14 +354,14 @@ static void SaveGame (XFILE& file) for (st = SavTab; st->Ptr; st ++) { if (file.Error) VGA::Exit("Bad SVG"); - file.Write((byte far *) st->Ptr, st->Len); + file.Write((byte *) st->Ptr, st->Len); } - file.Write((byte far *) &(i = SVGCHKSUM), sizeof(i)); + file.Write((byte *) &(i = SVGCHKSUM), sizeof(i)); for (spr = VGA::SpareQ.First(); spr; spr = spr->Next) if (spr->Ref >= 1000) - if (!file.Error) file.Write((byte far *)spr, sizeof(*spr)); + if (!file.Error) file.Write((byte *)spr, sizeof(*spr)); } @@ -435,7 +435,7 @@ static void LoadMapping (void) { memset(CLUSTER::Map, 0, sizeof(CLUSTER::Map)); cf.Seek((Now - 1) * sizeof(CLUSTER::Map)); - cf.Read((byte far *) CLUSTER::Map, sizeof(CLUSTER::Map)); + cf.Read((byte *) CLUSTER::Map, sizeof(CLUSTER::Map)); } } } @@ -850,7 +850,7 @@ int SYSTEM::FunDel = HEROFUN0; void SYSTEM::SetPal (void) { int i; - DAC far * p = SysPal + 256-ArrayCount(StdPal); + DAC * p = SysPal + 256-ArrayCount(StdPal); for (i = 0; i < ArrayCount(StdPal); i ++) { p[i].R = StdPal[i].R >> 2; @@ -1426,7 +1426,7 @@ static void SaveMapping (void) if (! cf.Error) { cf.Seek((Now-1) * sizeof(CLUSTER::Map)); - cf.Write((byte far *) CLUSTER::Map, sizeof(CLUSTER::Map)); + cf.Write((byte *) CLUSTER::Map, sizeof(CLUSTER::Map)); } } { @@ -1435,7 +1435,7 @@ static void SaveMapping (void) { HeroXY[Now-1].X = Hero->X; HeroXY[Now-1].Y = Hero->Y; - cf.Write((byte far *) HeroXY, sizeof(HeroXY)); + cf.Write((byte *) HeroXY, sizeof(HeroXY)); } } } @@ -1998,7 +1998,7 @@ static void RunGame (void) if (Mini && INI_FILE::Exist("MINI.SPR")) { - byte far * ptr = (byte far *) &*Mini; + byte * ptr = (byte *) &*Mini; if (ptr != NULL) { LoadSprite("MINI", -1, 0, MINI_X, MINI_Y); @@ -2217,7 +2217,7 @@ Boolean ShowTitle (const char * name) void StkDump (void) { CFILE f("!STACK.DMP", BFW); - f.Write((byte far *) (intStackPtr-STACK_SIZ/2), STACK_SIZ*2); + f.Write((byte *) (intStackPtr-STACK_SIZ/2), STACK_SIZ*2); } #endif */ diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index bf7bd850f59..620e988c361 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -34,7 +34,7 @@ -byte * Glass (DAC far * pal, byte r, byte g, byte b) +byte * Glass (DAC * pal, byte r, byte g, byte b) { byte * x = new byte[256]; if (x) @@ -54,7 +54,7 @@ byte * Glass (DAC far * pal, byte r, byte g, byte b) -byte * Mark (DAC far * pal) +byte * Mark (DAC * pal) { #define f(c) (c ^ 63) byte * x = new byte[256]; diff --git a/engines/cge/game.h b/engines/cge/game.h index e675d15a7ce..7a5efd9844f 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -44,8 +44,8 @@ extern SPRITE * Sys; int Sinus (long x); -byte * Glass (DAC far * pal, byte r, byte g, byte b); -byte * Mark (DAC far * pal); +byte * Glass (DAC * pal, byte r, byte g, byte b); +byte * Mark (DAC * pal); diff --git a/engines/cge/general.h b/engines/cge/general.h index 71d9d96bdf2..0a73de98a2c 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -38,7 +38,7 @@ #define SCR_WID ((word)SCR_WID_) #define SCR_HIG ((word)SCR_HIG_) #define SCR_SEG 0xA000 -#define SCR_ADR ((byte far *) MK_FP(SCR_SEG, 0)) +#define SCR_ADR ((byte *) MK_FP(SCR_SEG, 0)) @@ -83,7 +83,7 @@ public: class ENGINE { protected: - static void interrupt (far * OldTimer) (...); + static void interrupt (* OldTimer) (...); static void interrupt NewTimer (...); public: ENGINE (word tdiv); @@ -128,7 +128,7 @@ class EMS EMS * Nxt; public: EMS (void); - void far * operator & () const; + void * operator & () const; word Size (void); }; @@ -184,8 +184,8 @@ public: word Error; XFILE (void) : Mode(REA), Error(0) { } XFILE (IOMODE mode) : Mode(mode), Error(0) { } - virtual word Read (void far * buf, word len) = 0; - virtual word Write (void far * buf, word len) = 0; + virtual word Read (void * buf, word len) = 0; + virtual word Write (void * buf, word len) = 0; virtual long Mark (void) = 0; virtual long Size (void) = 0; virtual long Seek (long pos) = 0; @@ -198,7 +198,7 @@ public: template inline word XRead (XFILE * xf, T * t) { - return xf->Read((byte far *) t, sizeof(*t)); + return xf->Read((byte *) t, sizeof(*t)); }; @@ -212,12 +212,12 @@ protected: word Seed; CRYPT * Crypt; public: - IOHAND (const char near * name, IOMODE mode = REA, CRYPT crypt = NULL); + IOHAND (const char * name, IOMODE mode = REA, CRYPT crypt = NULL); IOHAND (IOMODE mode = REA, CRYPT * crpt = NULL); virtual ~IOHAND (void); static Boolean Exist (const char * name); - word Read (void far * buf, word len); - word Write (void far * buf, word len); + word Read (void * buf, word len); + word Write (void * buf, word len); long Mark (void); long Size (void); long Seek (long pos); diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index cb2cb54fece..99e87a38200 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -49,7 +49,7 @@ #define IsAlNum(c) (IsAlpha(c) || IsDigit(c)) #define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) -#define farnew(t,n) ((t far *) farmalloc(sizeof(t) * (n))) +#define farnew(t,n) ((t *) farmalloc(sizeof(t) * (n))) #define ArrayCount(a) (sizeof(a)/sizeof((a)[0])) #define MAX_TIMER 0x1800B0L @@ -138,11 +138,11 @@ struct KeyStatStruct #define CGA_Cursor 0x0607 #define OFF_Cursor 0x2000 -#define TimerCount (* ((volatile long far *) ((void _seg *) 0x40 + (void near *) 0x6C))) -#define KeyStat (* ((volatile struct KeyStatStruct far *) ((void _seg *) 0x40 + (void near *) 0x17))) -#define BreakFlag (* ((volatile byte far *) ((void _seg *) 0x40 + (void near *) 0x71))) -#define PostFlag (* ((volatile word far *) ((void _seg *) 0x40 + (void near *) 0x72))) -#define POST ((void far (*)(void)) ((void _seg *) 0xF000 + (void near *) 0xFFF0)) +#define TimerCount (* ((volatile long *) ((void _seg *) 0x40 + (void *) 0x6C))) +#define KeyStat (* ((volatile struct KeyStatStruct *) ((void _seg *) 0x40 + (void *) 0x17))) +#define BreakFlag (* ((volatile byte *) ((void _seg *) 0x40 + (void *) 0x71))) +#define PostFlag (* ((volatile word *) ((void _seg *) 0x40 + (void *) 0x72))) +#define POST ((void (*)(void)) ((void _seg *) 0xF000 + (void *) 0xFFF0)) #define SLIF if (KeyStat.ScrollLock) #define FOR(i,n) for(i=0;i<(n);i++) diff --git a/engines/cge/keybd.cpp b/engines/cge/keybd.cpp index 37a1e1d798d..63a37a348e0 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/keybd.cpp @@ -45,7 +45,7 @@ word KEYBOARD::Code[0x60] = { 0,Esc,'1','2','3','4','5','6','7','8','9','0', 0*0x54,0*0x55,0*0x56,F11,F12,0*0x59,0*0x5A, 0*0x5B,0*0x5C,0*0x5D,0*0x5E,0*0x5F }; -void interrupt (far * KEYBOARD::OldKeyboard) (...); +void interrupt (* KEYBOARD::OldKeyboard) (...); diff --git a/engines/cge/keybd.h b/engines/cge/keybd.h index 42c80f88e1b..7aa93b232f9 100644 --- a/engines/cge/keybd.h +++ b/engines/cge/keybd.h @@ -41,7 +41,7 @@ class KEYBOARD { - static void interrupt (far * OldKeyboard) (...); + static void interrupt (* OldKeyboard) (...); static void interrupt NewKeyboard (...); static word Code[0x60]; static word Current; diff --git a/engines/cge/mouse.h b/engines/cge/mouse.h index f3b83f3f2e1..8e69232c5c0 100644 --- a/engines/cge/mouse.h +++ b/engines/cge/mouse.h @@ -51,7 +51,7 @@ struct EVENT { word Msk; }; extern EVENT Evt[EVT_MAX]; extern word EvtHead, EvtTail; -typedef void (far MOUSE_FUN) (void); +typedef void (MOUSE_FUN) (void); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 82f9416af7c..4c041653a4d 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -63,7 +63,7 @@ extern SPRITE * Pocket[]; extern int PocPtr; //------------------------------------------------------------------------- -extern DAC far * SysPal; +extern DAC * SysPal; extern MOUSE Mouse; @@ -512,7 +512,7 @@ SNAIL::~SNAIL (void) void SNAIL::AddCom (SNCOM com, int ref, int val, void * ptr) { _disable(); - COM far * snc = &SNList[Head ++]; + COM * snc = &SNList[Head ++]; snc->Com = com; snc->Ref = ref; snc->Val = val; @@ -531,7 +531,7 @@ void SNAIL::AddCom (SNCOM com, int ref, int val, void * ptr) void SNAIL::InsCom (SNCOM com, int ref, int val, void * ptr) { - COM far * snc; + COM * snc; _disable(); if (Busy) @@ -1094,7 +1094,7 @@ void SNFlash (Boolean on) { if (on) { - DAC far * pal = farnew(DAC, PAL_CNT); + DAC * pal = farnew(DAC, PAL_CNT); if (pal) { int i; @@ -1181,7 +1181,7 @@ void SNAIL::RunCom (void) byte tmphea = Head; while (Tail != tmphea) { - COM far * snc = &SNList[Tail]; + COM * snc = &SNList[Tail]; if (! Turbo) // only for the slower one { diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 66a40e8382d..309f9b5a296 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -52,7 +52,7 @@ typedef struct { byte Horz, Vert; } BAR; struct SCB { - byte far * Ptr; + byte * Ptr; word Siz; SCB * Nxt; }; @@ -81,7 +81,7 @@ enum SNLIST { NEAR, TAKE }; class SNAIL { - struct COM { SNCOM Com; int Ref; int Val; void * Ptr; } far * SNList; + struct COM { SNCOM Com; int Ref; int Val; void * Ptr; } * SNList; byte Head, Tail; Boolean Turbo, Busy, TextDelay; word Pause; diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 910148c71eb..a445465dc86 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -82,7 +82,7 @@ struct DRVINFO // sample info struct SMPINFO { - BYTE far * saddr; // address + BYTE * saddr; // address WORD slen; // length WORD span; // left/right pan (0-15) int sflag; // flag @@ -119,7 +119,7 @@ EC void SNDDigiStart (SMPINFO *PSmpInfo); EC void SNDDigiStop (SMPINFO *PSmpInfo); // Start MIDI File -EC void SNDMIDIStart (BYTE far *MIDFile); +EC void SNDMIDIStart (BYTE *MIDFile); // Stop MIDI File EC void SNDMIDIStop (void); diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index cd0101204d8..e8b2a8f4cf0 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -90,7 +90,7 @@ void SOUND::Play (DATACK * wav, int pan, int cnt) if (wav) { Stop(); - smpinf.saddr = (char far *) &*(wav->EAddr()); + smpinf.saddr = (char *) &*(wav->EAddr()); smpinf.slen = (word)wav->Size(); smpinf.span = pan; smpinf.sflag = cnt; @@ -246,7 +246,7 @@ DATACK * FX::operator [] (int ref) //------------------------------------------------------------------------- -static byte far * midi = NULL; +static byte * midi = NULL; @@ -275,7 +275,7 @@ void LoadMIDI (int ref) if (mid.Error == 0) { word siz = (word) mid.Size(); - midi = new far byte[siz]; + midi = new byte[siz]; if (midi) { mid.Read(midi, siz); @@ -294,9 +294,9 @@ void LoadMIDI (int ref) -EC void far * Patch (int pat) +EC void * Patch (int pat) { - void far * p = NULL; + void * p = NULL; static char fn[] = "PATCH000.SND"; wtom(pat, fn+5, 10, 3); @@ -304,7 +304,7 @@ EC void far * Patch (int pat) if (! snd.Error) { word siz = (word) snd.Size(); - p = (byte far *) farmalloc(siz); + p = (byte *) farmalloc(siz); if (p) { snd.Read(p, siz); diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 3a4ea5bbc2f..2e247336ab2 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -180,7 +180,7 @@ void TALK::Update (const char * tx) word hmarg = (Mode) ? TEXT_HM : 0; word mw, mh, ln = vmarg; const char * p; - byte far * m; + byte * m; if (! TS[0]) { @@ -210,10 +210,10 @@ void TALK::Update (const char * tx) else { int cw = Font.Wid[*tx], i; - char far * f = Font.Map + Font.Pos[*tx]; + char * f = Font.Map + Font.Pos[*tx]; for (i = 0; i < cw; i ++) { - char far * p = m; + char * p = m; word n; register word b = * (f ++); for (n = 0; n < FONT_HIG; n ++) @@ -236,7 +236,7 @@ void TALK::Update (const char * tx) BITMAP * TALK::Box (word w, word h) { - byte far * b, far * p, far * q; + byte * b, * p, * q; word n, r = (Mode == ROUND) ? TEXT_RD : 0; int i; @@ -287,7 +287,7 @@ void TALK::PutLine (int line, const char * text) // Note: (TS[0].W % 4) have to be 0 { word w = TS[0]->W, h = TS[0]->H; - byte far * v = TS[0]->V, far * p; + byte * v = TS[0]->V, * p; word dsiz = w >> 2; // data size (1 plane line size) word lsiz = 2 + dsiz + 2; // word for line header, word for gap word psiz = h * lsiz; // - last gap, but + plane trailer @@ -307,14 +307,14 @@ void TALK::PutLine (int line, const char * text) // paint text line if (text) { - byte far * q; + byte * q; p = v + 2 + TEXT_HM/4 + (TEXT_HM%4)*psiz; q = v + size; while (* text) { word cw = Font.Wid[*text], i; - byte far * fp = Font.Map + Font.Pos[*text]; + byte * fp = Font.Map + Font.Pos[*text]; for (i = 0; i < cw; i ++) { @@ -361,7 +361,7 @@ void INFO_LINE::Update (const char * tx) if (tx != OldTxt) { word w = TS[0]->W, h = TS[0]->H; - byte * v = (byte near *) TS[0]->V; + byte * v = (byte *) TS[0]->V; word dsiz = w >> 2; // data size (1 plane line size) word lsiz = 2 + dsiz + 2; // word for line header, word for gap word psiz = h * lsiz; // - last gape, but + plane trailer @@ -381,7 +381,7 @@ void INFO_LINE::Update (const char * tx) while (* tx) { word cw = Font.Wid[*tx], i; - byte far * fp = Font.Map + Font.Pos[*tx]; + byte * fp = Font.Map + Font.Pos[*tx]; for (i = 0; i < cw; i ++) { diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 8129b01bd97..c84891f7a06 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -55,9 +55,9 @@ public: // static byte Wid[256]; // static word Pos[256]; // static byte Map[256*8]; - byte far * Wid; - word far * Pos; - byte far * Map; + byte * Wid; + word * Pos; + byte * Map; FONT (const char * name); ~FONT (void); word Width (const char * text); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 404b4f8bf85..84dbd802fdb 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -136,9 +136,9 @@ static void Video (void) -word far * SaveScreen (void) +word * SaveScreen (void) { - word cxy, cur, siz, far * scr = NULL, far * sav; + word cxy, cur, siz, * scr = NULL, * sav; // horizontal size of text mode screen asm mov ah,0x0F // get current video mode @@ -194,9 +194,9 @@ word far * SaveScreen (void) -void RestoreScreen (word far * &sav) +void RestoreScreen (word * &sav) { - word far * scr = NULL; + word * scr = NULL; asm mov ax,0x40 // system data segment asm mov es,ax @@ -486,7 +486,7 @@ BMP_PTR * SPRITE::SetShapeList (BMP_PTR * shp) -void SPRITE::MoveShapes (byte far * buf) +void SPRITE::MoveShapes (byte * buf) { BMP_PTR * p; for (p = Ext->ShpList; *p; p ++) @@ -779,7 +779,7 @@ void SPRITE::Tick (void) -void SPRITE::MakeXlat (byte far * x) +void SPRITE::MakeXlat (byte * x) { if (Ext) { @@ -800,7 +800,7 @@ void SPRITE::KillXlat (void) if (Flags.Xlat && Ext) { BMP_PTR * b; - byte far * m = (*Ext->ShpList)->M; + byte * m = (*Ext->ShpList)->M; switch (MemType(m)) { @@ -885,7 +885,7 @@ void SPRITE::Show (void) void SPRITE::Show (word pg) { - byte far * a = VGA::Page[1]; + byte * a = VGA::Page[1]; VGA::Page[1] = VGA::Page[pg & 3]; Shp()->Show(X, Y); VGA::Page[1] = a; @@ -912,13 +912,13 @@ BMP_PTR SPRITE::Ghost (void) register SPREXT * e = Ext; if (e->b1) { - BMP_PTR bmp = new BITMAP(0, 0, (byte far *)NULL); + BMP_PTR bmp = new BITMAP(0, 0, (byte *)NULL); if (bmp == NULL) VGA::Exit("No core"); bmp->W = e->b1->W; bmp->H = e->b1->H; if ((bmp->B = farnew(HideDesc, bmp->H)) == NULL) VGA::Exit("No Core"); - bmp->V = (byte far *) _fmemcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); - bmp->M = (byte far *) MK_FP(e->y1, e->x1); + bmp->V = (byte *) _fmemcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); + bmp->M = (byte *) MK_FP(e->y1, e->x1); return bmp; } return NULL; @@ -1085,18 +1085,18 @@ SPRITE * QUEUE::Locate (int ref) word VGA::StatAdr = VGAST1_; word VGA::OldMode = 0; -word far * VGA::OldScreen = NULL; +word * VGA::OldScreen = NULL; const char * VGA::Msg = NULL; const char * VGA::Nam = NULL; -DAC far * VGA::OldColors = NULL; -DAC far * VGA::NewColors = NULL; +DAC * VGA::OldColors = NULL; +DAC * VGA::NewColors = NULL; Boolean VGA::SetPal = FALSE; int VGA::Mono = 0; QUEUE VGA::ShowQ = TRUE, VGA::SpareQ = FALSE; -byte far * VGA::Page[4] = { (byte far *) MK_FP(SCR_SEG, 0x0000), - (byte far *) MK_FP(SCR_SEG, 0x4000), - (byte far *) MK_FP(SCR_SEG, 0x8000), - (byte far *) MK_FP(SCR_SEG, 0xC000) }; +byte * VGA::Page[4] = { (byte *) MK_FP(SCR_SEG, 0x0000), + (byte *) MK_FP(SCR_SEG, 0x4000), + (byte *) MK_FP(SCR_SEG, 0x8000), + (byte *) MK_FP(SCR_SEG, 0xC000) }; @@ -1280,7 +1280,7 @@ int VGA::SetMode (int mode) -void VGA::GetColors (DAC far * tab) +void VGA::GetColors (DAC * tab) { asm cld asm les di,tab // color table @@ -1303,9 +1303,9 @@ void VGA::GetColors (DAC far * tab) -void VGA::SetColors (DAC far * tab, int lum) +void VGA::SetColors (DAC * tab, int lum) { - DAC far * des = NewColors; + DAC * des = NewColors; asm push ds asm les di,des @@ -1367,7 +1367,7 @@ void VGA::SetColors (void) -void VGA::Sunrise (DAC far * tab) +void VGA::Sunrise (DAC * tab) { int i; for (i = 0; i <= 64; i += FADE_STEP) @@ -1420,7 +1420,7 @@ void VGA::Show (void) void VGA::UpdateColors (void) { - DAC far * tab = NewColors; + DAC * tab = NewColors; asm push ds asm cld @@ -1453,7 +1453,7 @@ void VGA::UpdateColors (void) void VGA::Update (void) { - byte far * p = Page[1]; + byte * p = Page[1]; Page[1] = Page[0]; Page[0] = p; @@ -1483,7 +1483,7 @@ void VGA::Update (void) void VGA::Clear (byte color) { - byte far * a = (byte far *) MK_FP(SCR_SEG, 0); + byte * a = (byte *) MK_FP(SCR_SEG, 0); asm mov dx,VGASEQ_ asm mov ax,0x0F02 // map mask register - enable all planes @@ -1504,7 +1504,7 @@ void VGA::Clear (byte color) void VGA::CopyPage (word d, word s) { - byte far * S = Page[s & 3], far * D = Page[d & 3]; + byte * S = Page[s & 3], * D = Page[d & 3]; asm mov dx,VGAGRA_ asm mov al,0x05 // R/W mode @@ -1573,9 +1573,9 @@ void BITMAP::XShow (int x, int y) { byte rmsk = x % 4, mask = 1 << rmsk, - far * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; - byte near * m = (char *) M; - byte far * v = V; + * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; + byte * m = (char *) M; + byte * v = V; asm push bx asm push si @@ -1658,8 +1658,8 @@ void BITMAP::XShow (int x, int y) void BITMAP::Show (int x, int y) { byte mask = 1 << (x & 3), - far * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); - byte far * v = V; + * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); + byte * v = V; asm push ds // preserve DS @@ -1728,9 +1728,9 @@ void BITMAP::Show (int x, int y) void BITMAP::Hide (int x, int y) { - byte far * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; + byte * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; word d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); - HideDesc far * b = B; + HideDesc * b = B; word extra = ((x & 3) != 0); word h = H; diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index a749b482b77..4f172cb3ea1 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -199,7 +199,7 @@ public: virtual ~SPRITE (void); BMP_PTR Shp (void); BMP_PTR * SetShapeList (BMP_PTR * shp); - void MoveShapes (byte far * buf); + void MoveShapes (byte * buf); SPRITE * Expand (void); SPRITE * Contract (void); SPRITE * BackShow (Boolean fast = FALSE); @@ -211,7 +211,7 @@ public: void Hide (void); BMP_PTR Ghost (void); void Show (word pg); - void MakeXlat (byte far * x); + void MakeXlat (byte * x); void KillXlat (void); void Step (int nr = -1); SEQ * SetSeq (SEQ * seq); @@ -251,10 +251,10 @@ public: class VGA { static word OldMode; - static word far * OldScreen; + static word * OldScreen; static word StatAdr; static Boolean SetPal; - static DAC far * OldColors, far * NewColors; + static DAC * OldColors, * NewColors; static int SetMode (int mode); static void UpdateColors (void); static void SetColors (void); @@ -266,17 +266,17 @@ public: dword FrmCnt; static QUEUE ShowQ, SpareQ; static int Mono; - static byte far * Page[4]; + static byte * Page[4]; VGA (int mode = M13H); ~VGA (void); void Setup (VgaRegBlk * vrb); - static void GetColors (DAC far * tab); - static void SetColors (DAC far * tab, int lum); + static void GetColors (DAC * tab); + static void SetColors (DAC * tab, int lum); static void Clear (byte color = 0); static void Exit (const char * txt = NULL, const char * name = NULL); static void Exit (int tref, const char * name = NULL); static void CopyPage (word d, word s = 3); - static void Sunrise (DAC far * tab); + static void Sunrise (DAC * tab); static void Sunset (void); void Show (void); void Update (void); @@ -291,7 +291,7 @@ RGB MkRGB (byte r, byte g, byte b); template -byte Closest (CBLK far * pal, CBLK x) +byte Closest (CBLK * pal, CBLK x) { #define f(col,lum) ((((word)(col))<<8)/lum) word i, dif = 0xFFFF, found; @@ -325,8 +325,8 @@ byte Closest (CBLK far * pal, CBLK x) char * NumStr (char * str, int num); void Video (void); - word far * SaveScreen (void); - void RestoreScreen (word far * &sav); + word * SaveScreen (void); + void RestoreScreen (word * &sav); SPRITE * SpriteAt (int x, int y); SPRITE * Locate (int ref); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index ccfe273923e..4ca3708eaca 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -48,7 +48,7 @@ MENU_BAR::MENU_BAR (word w) { int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h; - byte far * p = farnew(byte, i), far * p1, far * p2; + byte * p = farnew(byte, i), * p1, * p2; _fmemset(p+w, TRANS, i-2*w); _fmemset(p, MB_LT, w); diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 6816f2de901..f0365867ee4 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -61,7 +61,7 @@ VFILE::VFILE (const char * name, IOMODE mode) if (mode == REA) { if (Dat.File.Error || Cat.Error) DROP("Bad volume data", NULL); - BT_KEYPACK far * kp = Cat.Find(name); + BT_KEYPACK * kp = Cat.Find(name); if (_fstricmp(kp->Key, name) != 0) Error = ENOFILE; EndMark = (BufMark = BegMark = kp->Mark) + kp->Size; } diff --git a/engines/cge/vol.h b/engines/cge/vol.h index 80cd759a470..74b4a2b648b 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -55,9 +55,9 @@ class DAT friend VFILE; static VOLBASE File; public: - static Boolean Append (byte far * buf, word len); + static Boolean Append (byte * buf, word len); static Boolean Write (CFILE& f); - static Boolean Read (long org, word len, byte far * buf); + static Boolean Read (long org, word len, byte * buf); }; diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 22dd79c4f58..3266af95d5a 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -110,7 +110,7 @@ class DATACK : public CKHEA Boolean e; union { - byte far * Buf; + byte * Buf; EMS * EBuf; }; public: @@ -118,7 +118,7 @@ public: DATACK (CKHEA& hea, EMM * emm); DATACK (int first, int last); ~DATACK (void); - inline byte far * Addr (void) { return Buf; } + inline byte * Addr (void) { return Buf; } inline EMS * EAddr (void) { return EBuf; } }; From 68f7ff111536c2d7f5a8869252ba8ad31507a380 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 10 Jun 2011 13:06:03 +0200 Subject: [PATCH 005/276] CGE: Replace Boolean, TRUE and FALSE by bool, true, false --- engines/cge/bitmap.cpp | 26 ++++---- engines/cge/bitmap.h | 10 +-- engines/cge/boot.h | 2 +- engines/cge/cfile.cpp | 2 +- engines/cge/cge_main.cpp | 128 +++++++++++++++++++-------------------- engines/cge/cge_main.h | 4 +- engines/cge/general.h | 12 ++-- engines/cge/gettext.cpp | 4 +- engines/cge/jbw.h | 7 +-- engines/cge/mixer.cpp | 22 +++---- engines/cge/mixer.h | 2 +- engines/cge/mouse.cpp | 4 +- engines/cge/mouse.h | 2 +- engines/cge/snail.cpp | 98 +++++++++++++++--------------- engines/cge/snail.h | 14 ++--- engines/cge/sound.cpp | 2 +- engines/cge/sound.h | 2 +- engines/cge/startup.cpp | 14 ++--- engines/cge/startup.h | 2 +- engines/cge/talk.cpp | 6 +- engines/cge/text.cpp | 18 +++--- engines/cge/vga13h.cpp | 40 ++++++------ engines/cge/vga13h.h | 20 +++--- engines/cge/vmenu.cpp | 14 ++--- engines/cge/vol.cpp | 2 +- engines/cge/vol.h | 8 +-- engines/cge/wav.h | 6 +- 27 files changed, 234 insertions(+), 237 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 697eb4a9e3d..a9ded67e451 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -53,7 +53,7 @@ DAC * BITMAP::Pal = NULL; #pragma argsused -BITMAP::BITMAP (const char * fname, Boolean rem) +BITMAP::BITMAP (const char * fname, bool rem) : M(NULL), V(NULL) { char pat[MAXPATH]; @@ -238,7 +238,7 @@ BMP_PTR BITMAP::Code (void) V = NULL; } - while (TRUE) // at most 2 times: for (V == NULL) & for allocated block; + while (true) // at most 2 times: for (V == NULL) & for allocated block; { byte * im = V+2; word * cp = (word *) V; @@ -255,7 +255,7 @@ BMP_PTR BITMAP::Code (void) for (bpl = 0; bpl < 4; bpl ++) // once per each bitplane { byte * bm = M; - Boolean skip = (bm[bpl] == TRANS); + bool skip = (bm[bpl] == TRANS); word j; cnt = 0; @@ -306,7 +306,7 @@ BMP_PTR BITMAP::Code (void) } cp = (word *) im; im += 2; - skip = TRUE; + skip = true; cnt = (SCR_WID - j + 3) / 4; } } @@ -360,12 +360,12 @@ BMP_PTR BITMAP::Code (void) -Boolean BITMAP::SolidAt (int x, int y) +bool BITMAP::SolidAt (int x, int y) { byte * m; word r, n, n0; - if (x >= W || y >= H) return FALSE; + if (x >= W || y >= H) return false; m = V; r = x % 4; @@ -389,7 +389,7 @@ Boolean BITMAP::SolidAt (int x, int y) m += w; } - while (TRUE) + while (true) { word w, t; @@ -398,14 +398,14 @@ Boolean BITMAP::SolidAt (int x, int y) t = w & 0xC000; w &= 0x3FFF; - if (n > n0) return FALSE; + if (n > n0) return false; n += w; switch (t) { - case EOI : return FALSE; + case EOI : return false; case SKP : w = 0; break; case REP : - case CPY : if (n-w <= n0 && n > n0) return TRUE; break; + case CPY : if (n-w <= n0 && n > n0) return true; break; } m += (t == REP) ? 1 : w; } @@ -416,7 +416,7 @@ Boolean BITMAP::SolidAt (int x, int y) -Boolean BITMAP::VBMSave (XFILE * f) +bool BITMAP::VBMSave (XFILE * f) { word p = (Pal != NULL), n = ((word) (((byte *)B) - V)) + H * sizeof(HideDesc); @@ -433,7 +433,7 @@ Boolean BITMAP::VBMSave (XFILE * f) -Boolean BITMAP::VBMLoad (XFILE * f) +bool BITMAP::VBMLoad (XFILE * f) { word p, n; if (f->Error == 0) f->Read((byte *)&p, sizeof(p)); @@ -448,7 +448,7 @@ Boolean BITMAP::VBMLoad (XFILE * f) else f->Seek(f->Mark() + 256 * sizeof(DAC)); } } - if ((V = farnew(byte, n)) == NULL) return FALSE; + if ((V = farnew(byte, n)) == NULL) return false; if (f->Error == 0) f->Read(V, n); B = (HideDesc *) (V + n - H * sizeof(HideDesc)); return (f->Error == 0); diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 738b3ab4efd..de2214fd632 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -55,13 +55,13 @@ typedef struct { word skip; word hide; } HideDesc; class BITMAP { - Boolean BMPLoad (XFILE * f); - Boolean VBMLoad (XFILE * f); + bool BMPLoad (XFILE * f); + bool VBMLoad (XFILE * f); public: static DAC * Pal; word W, H; byte * M, * V; HideDesc * B; - BITMAP (const char * fname, Boolean rem = TRUE); + BITMAP (const char * fname, bool rem = true); BITMAP (word w, word h, byte * map); BITMAP (word w, word h, byte fill); BITMAP (const BITMAP& bmp); @@ -72,8 +72,8 @@ public: void Hide (int x, int y); void Show (int x, int y); void XShow (int x, int y); - Boolean SolidAt (int x, int y); - Boolean VBMSave (XFILE * f); + bool SolidAt (int x, int y); + bool VBMSave (XFILE * f); word MoveVmap (byte * buf); }; diff --git a/engines/cge/boot.h b/engines/cge/boot.h index 6b9b2c88ecc..1715fd02ecb 100644 --- a/engines/cge/boot.h +++ b/engines/cge/boot.h @@ -70,7 +70,7 @@ typedef struct { EC Boot * ReadBoot (int drive); EC byte CheckBoot (Boot * boot); -EC Boolean WriteBoot (int drive, Boot * boot); +EC bool WriteBoot (int drive, Boot * boot); #endif \ No newline at end of file diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 0aa7c20a891..7d222d101d5 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -349,7 +349,7 @@ void CFILE::Append (CFILE& f) Seek(Size()); if (f.Error == 0) { - while (TRUE) + while (true) { if ((Lim = f.IOHAND::Read(Buff, IOBUF_SIZE)) == IOBUF_SIZE) WriteBuff(); else break; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 2bb7ac5c65e..1f621948c2d 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -117,7 +117,7 @@ static int DemoText = DEMO_TEXT; //-------------------------------------------------------------------------- - Boolean JBW = FALSE; + bool JBW = false; DAC *SysPal = farnew(DAC, PAL_CNT); //------------------------------------------------------------------------- @@ -141,10 +141,10 @@ static EMS * Mini = MiniEmm.Alloc((word)MINI_EMM_SIZE); static BMP_PTR * MiniShpList = NULL; static BMP_PTR MiniShp[] = { NULL, NULL }; static KEYBOARD Keyboard; -static Boolean Finis = FALSE; +static bool Finis = false; static int Startup = 1; static int OffUseCount = atoi(Text[OFF_USE_COUNT]); - word * intStackPtr = FALSE; + word *intStackPtr = false; HXY HeroXY[CAVE_MAX] = {{0,0}}; @@ -184,9 +184,9 @@ byte & CLUSTER::Cell (void) -Boolean CLUSTER::Protected (void) +bool CLUSTER::Protected (void) { - if (A == Barriers[Now].Vert || B == Barriers[Now].Horz) return TRUE; + if (A == Barriers[Now].Vert || B == Barriers[Now].Horz) return true; _DX = (MAP_ZCNT << 8) + MAP_XCNT; _BX = (word) this; @@ -202,7 +202,7 @@ Boolean CLUSTER::Protected (void) asm cmp ch,dh asm jge xit -// if (A < 0 || A >= MAP_XCNT || B < 0 || B >= MAP_ZCNT) return TRUE; +// if (A < 0 || A >= MAP_XCNT || B < 0 || B >= MAP_ZCNT) return true; asm mov al,dl asm mul ch @@ -276,7 +276,7 @@ CLUSTER XZ (COUPLE xy) -static void LoadGame (XFILE& file, Boolean tiny = FALSE) +static void LoadGame (XFILE& file, bool tiny = false) { SAVTAB * st; SPRITE * spr; @@ -290,7 +290,7 @@ static void LoadGame (XFILE& file, Boolean tiny = FALSE) file.Read((byte *) &i, sizeof(i)); if (i != SVGCHKSUM) VGA::Exit(BADSVG_TEXT); - if (STARTUP::Core < CORE_HIG) Music = FALSE; + if (STARTUP::Core < CORE_HIG) Music = false; if (STARTUP::SoundOk == 1 && STARTUP::Mode == 0) { SNDDrvInfo.VOL2.D = volume[0]; @@ -483,10 +483,10 @@ void WALK::Tick (void) if (! spr->Flags.Near) { FeedSnail(spr, NEAR); - spr->Flags.Near = TRUE; + spr->Flags.Near = true; } } - else spr->Flags.Near = FALSE; + else spr->Flags.Near = false; } } @@ -578,7 +578,7 @@ void WALK::Park (void) void WALK::FindWay (CLUSTER c) { - Boolean Find1Way(void); + bool Find1Way(void); extern word Target; if (c != Here) @@ -621,7 +621,7 @@ void WALK::FindWay (SPRITE * spr) -Boolean WALK::Lower (SPRITE * spr) +bool WALK::Lower (SPRITE * spr) { return (spr->Y > Y + (H * 3) / 5); } @@ -681,8 +681,8 @@ public: SQUARE::SQUARE (void) : SPRITE(MB) { - Flags.Kill = TRUE; - Flags.BDel = FALSE; + Flags.Kill = true; + Flags.BDel = false; } @@ -816,13 +816,13 @@ static void AltCtrlDel (void) static void MiniStep (int stp) { - if (stp < 0) MiniCave->Flags.Hide = TRUE; + if (stp < 0) MiniCave->Flags.Hide = true; else { &*Mini; *MiniShp[0] = *MiniShpList[stp]; if (Fx.Current) &*(Fx.Current->EAddr()); - MiniCave->Flags.Hide = FALSE; + MiniCave->Flags.Hide = false; } } @@ -927,7 +927,7 @@ static void CaveUp (void) // following 2 lines trims Hero's Z position! Hero->Tick(); Hero->Time = 1; - Hero->Flags.Hide = FALSE; + Hero->Flags.Hide = false; } if (! Dark) Vga.Sunset(); @@ -946,9 +946,9 @@ static void CaveUp (void) Vga.CopyPage(1, 0); Vga.Show(); Vga.Sunrise(SysPal); - Dark = FALSE; + Dark = false; if (! Startup) Mouse.On(); - HEART::Enable = TRUE; + HEART::Enable = true; } @@ -993,7 +993,7 @@ static void QGame (void) SaveSound(); SaveGame(CFILE(UsrPath(UsrFnam), WRI, RCrypt)); Vga.Sunset(); - Finis = TRUE; + Finis = true; } @@ -1003,7 +1003,7 @@ void SwitchCave (int cav) { if (cav != Now) { - HEART::Enable = FALSE; + HEART::Enable = false; if (cav < 0) { SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint @@ -1087,7 +1087,7 @@ void SYSTEM::Touch (word mask, int x, int y) case F7 : Hero->Step(TSEQ + 2); break; case F8 : Hero->Step(TSEQ + 3); break; case F9 : SYSTEM::FunDel = 1; break; - case 'X' : if (KEYBOARD::Key[ALT]) Finis = TRUE; break; + case 'X' : if (KEYBOARD::Key[ALT]) Finis = true; break; case '0' : case '1' : case '2' : @@ -1268,7 +1268,7 @@ static void SwitchMusic (void) if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); else { - SNPOST_(SNSEQ, 122, (Music = FALSE), NULL); + SNPOST_(SNSEQ, 122, (Music = false), NULL); SNPOST(SNEXEC, -1, 0, (void *) SelectSound); } } @@ -1355,8 +1355,8 @@ static void SwitchMapping (void) static void KillSprite (void) { - Sprite->Flags.Kill = TRUE; - Sprite->Flags.BDel = TRUE; + Sprite->Flags.Kill = true; + Sprite->Flags.BDel = true; SNPOST_(SNKILL, -1, 0, Sprite); Sprite = NULL; } @@ -1382,7 +1382,7 @@ static void PushSprite (void) static void PullSprite (void) { - Boolean ok = FALSE; + bool ok = false; SPRITE * spr = Sprite->Next; if (spr) { @@ -1554,7 +1554,7 @@ static void OptionTouch (int opt, word mask) if (mask & R_UP) if (! MIXER::Appear) { - MIXER::Appear = TRUE; + MIXER::Appear = true; new MIXER(BUTTON_X, BUTTON_Y); } break; @@ -1611,7 +1611,7 @@ void SPRITE::Touch (word mask, int x, int y) { SNPOST(SNREACH, -1, -1, this); SNPOST(SNKEEP, -1, -1, this); - Flags.Port = FALSE; + Flags.Port = false; } } else @@ -1674,9 +1674,9 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro int shpcnt = 0; int type = 0; // DEAD - Boolean east = FALSE; - Boolean port = FALSE; - Boolean tran = FALSE; + bool east = false; + bool port = false; + bool tran = false; int i, lcnt = 0; word len; @@ -1807,8 +1807,8 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro Sprite->Flags.East = east; Sprite->Flags.Port = port; Sprite->Flags.Tran = tran; - Sprite->Flags.Kill = TRUE; - Sprite->Flags.BDel = TRUE; + Sprite->Flags.Kill = true; + Sprite->Flags.BDel = true; fnsplit(fname, NULL, NULL, Sprite->File, NULL); Sprite->ShpCnt = shpcnt; VGA::SpareQ.Append(Sprite); @@ -1825,10 +1825,10 @@ static void LoadScript (const char *fname) char line[LINE_MAX]; char * SpN; int SpI, SpA, SpX, SpY, SpZ; - Boolean BkG = FALSE; + bool BkG = false; INI_FILE scrf(fname); int lcnt = 0; - Boolean ok = TRUE; + bool ok = true; if (scrf.Error) return; @@ -1839,7 +1839,7 @@ static void LoadScript (const char *fname) ++ lcnt; if (*line == 0 || *line == '\n' || *line == '.') continue; - ok = FALSE; // not OK if break + ok = false; // not OK if break // sprite ident number if ((p = strtok(line, " \t\n")) == NULL) break; SpI = atoi(p); @@ -1861,11 +1861,11 @@ static void LoadScript (const char *fname) if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; BkG = atoi(p) == 0; - ok = TRUE; // no break: OK + ok = true; // no break: OK Sprite = NULL; LoadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); - if (Sprite && BkG) Sprite->Flags.Back = TRUE; + if (Sprite && BkG) Sprite->Flags.Back = true; } if (! ok) { @@ -1947,7 +1947,7 @@ void LoadUser (void) else { LoadScript(ProgName(INI_EXT)); - Music = TRUE; + Music = true; SaveGame(CFILE(SVG0NAME, WRI)); VGA::Exit("Ok", SVG0NAME); } @@ -1965,9 +1965,9 @@ static void RunGame (void) Text.Preload(100, 1000); LoadHeroXY(); - CavLight.Flags.Tran = TRUE; + CavLight.Flags.Tran = true; VGA::ShowQ.Append(&CavLight); - CavLight.Flags.Hide = TRUE; + CavLight.Flags.Hide = true; static SEQ PocSeq[] = { { 0, 0, 0, 0, 20 }, { 1, 2, 0, 0, 4 }, @@ -1978,7 +1978,7 @@ static void RunGame (void) { 0, 1, 0, 0, 16 }, }; PocLight.SetSeq(PocSeq); - PocLight.Flags.Tran = TRUE; + PocLight.Flags.Tran = true; PocLight.Time = 1; PocLight.Z = 120; VGA::ShowQ.Append(&PocLight); @@ -2005,7 +2005,7 @@ static void RunGame (void) ExpandSprite(MiniCave = Sprite); // NULL is ok if (MiniCave) { - MiniCave->Flags.Hide = TRUE; + MiniCave->Flags.Hide = true; MiniCave->MoveShapes(ptr); MiniShp[0] = new BITMAP(*MiniCave->Shp()); MiniShpList = MiniCave->SetShapeList(MiniShp); @@ -2024,15 +2024,15 @@ static void RunGame (void) if ((Shadow = Sprite) != NULL) { Shadow->Ref = 2; - Shadow->Flags.Tran = TRUE; - Hero->Flags.Shad = TRUE; + Shadow->Flags.Tran = true; + Hero->Flags.Shad = true; VGA::ShowQ.Insert(VGA::SpareQ.Remove(Shadow), Hero); } } } InfoLine.Goto(INFO_X, INFO_Y); - InfoLine.Flags.Tran = TRUE; + InfoLine.Flags.Tran = true; InfoLine.Update(NULL); VGA::ShowQ.Insert(&InfoLine); @@ -2064,7 +2064,7 @@ static void RunGame (void) } KEYBOARD::SetClient(NULL); - HEART::Enable = FALSE; + HEART::Enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); Mouse.Off(); @@ -2086,14 +2086,14 @@ void Movie (const char * ext) ExpandSprite(VGA::SpareQ.Locate(999)); FeedSnail(VGA::ShowQ.Locate(999), TAKE); VGA::ShowQ.Append(&Mouse); - HEART::Enable = TRUE; + HEART::Enable = true; KEYBOARD::SetClient(Sys); while (! Snail.Idle()) { MainLoop(); } KEYBOARD::SetClient(NULL); - HEART::Enable = FALSE; + HEART::Enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); VGA::ShowQ.Clear(); @@ -2106,16 +2106,16 @@ void Movie (const char * ext) -Boolean ShowTitle (const char * name) +bool ShowTitle (const char * name) { BITMAP::Pal = SysPal; BMP_PTR LB[] = { new BITMAP(name), NULL }; BITMAP::Pal = NULL; - Boolean usr_ok = FALSE; + bool usr_ok = false; SPRITE D(LB); - D.Flags.Kill = TRUE; - D.Flags.BDel = TRUE; + D.Flags.Kill = true; + D.Flags.BDel = true; D.Center(); D.Show(2); @@ -2136,11 +2136,11 @@ Boolean ShowTitle (const char * name) VGA::CopyPage(1, 2); VGA::CopyPage(0, 1); VGA::ShowQ.Append(&Mouse); - HEART::Enable = TRUE; + HEART::Enable = true; Mouse.On(); for (SelectSound(); ! Snail.Idle() || VMENU::Addr; ) MainLoop(); Mouse.Off(); - HEART::Enable = FALSE; + HEART::Enable = false; VGA::ShowQ.Clear(); VGA::CopyPage(0, 2); STARTUP::SoundOk = 2; @@ -2151,7 +2151,7 @@ Boolean ShowTitle (const char * name) { #ifdef DEMO strcpy(UsrFnam, ProgName(SVG_EXT)); - usr_ok = TRUE; + usr_ok = true; #else //----------------------------------------- #ifndef EVA @@ -2171,10 +2171,10 @@ Boolean ShowTitle (const char * name) VGA::CopyPage(0, 1); VGA::ShowQ.Append(&Mouse); //Mouse.On(); - HEART::Enable = TRUE; + HEART::Enable = true; for (TakeName(); GET_TEXT::Ptr; ) MainLoop(); - HEART::Enable = FALSE; - if (KEYBOARD::Last() == Enter && *UsrFnam) usr_ok = TRUE; + HEART::Enable = false; + if (KEYBOARD::Last() == Enter && *UsrFnam) usr_ok = true; if (usr_ok) strcat(UsrFnam, SVG_EXT); //Mouse.Off(); VGA::ShowQ.Clear(); @@ -2185,13 +2185,13 @@ Boolean ShowTitle (const char * name) const char *n = UsrPath(UsrFnam); if (CFILE::Exist(n)) { - LoadGame(CFILE(n, REA, RCrypt), TRUE); // only system vars + LoadGame(CFILE(n, REA, RCrypt), true); // only system vars VGA::SetColors(SysPal, 64); Vga.Update(); if (FINIS) { ++ STARTUP::Mode; - FINIS = FALSE; + FINIS = false; } } else ++ STARTUP::Mode; @@ -2203,7 +2203,7 @@ Boolean ShowTitle (const char * name) VGA::CopyPage(0, 2); #ifdef DEMO - return TRUE; + return true; #else return (STARTUP::Mode == 2 || usr_ok); #endif @@ -2237,8 +2237,8 @@ void cge_main (void) if (! Mouse.Exist) VGA::Exit(NO_MOUSE_TEXT); if (! SVG0FILE::Exist(SVG0NAME)) STARTUP::Mode = 2; - Debug( DebugLine.Flags.Hide = TRUE; ) - Debug( HorzLine.Flags.Hide = TRUE; ) + Debug( DebugLine.Flags.Hide = true; ) + Debug( HorzLine.Flags.Hide = true; ) srand((word) Timer()); Sys = new SYSTEM; diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 7a213429b1c..4f610897b1d 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -167,7 +167,7 @@ public: byte &Cell (void); CLUSTER (void) : COUPLE () { } CLUSTER (int a, int b) : COUPLE (a, b) { } - Boolean Protected (void); + bool Protected (void); }; @@ -186,7 +186,7 @@ public: int Distance (SPRITE * spr); void Turn (DIR d); void Park (void); - Boolean Lower (SPRITE * spr); + bool Lower (SPRITE * spr); void Reach (SPRITE * spr, int mode = -1); }; diff --git a/engines/cge/general.h b/engines/cge/general.h index 0a73de98a2c..03c34d70584 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -70,8 +70,8 @@ public: void operator += (COUPLE c) { A += c.A; B += c.B; } COUPLE operator - (COUPLE c) { return COUPLE(A-c.A, B-c.B); } void operator -= (COUPLE c) { A -= c.A; B -= c.B; } - Boolean operator == (COUPLE c) { return ((A - c.A) | (B - c.B)) == 0; } - Boolean operator != (COUPLE c) { return ! (operator == (c)); } + bool operator == (COUPLE c) { return ((A - c.A) | (B - c.B)) == 0; } + bool operator != (COUPLE c) { return ! (operator == (c)); } void Split (signed char& a, signed char& b) { a = A; b = B; } }; @@ -103,7 +103,7 @@ class EMS; class EMM { friend EMS; - Boolean Test (void); + bool Test (void); long Top, Lim; EMS * List; int Han; @@ -215,7 +215,7 @@ public: IOHAND (const char * name, IOMODE mode = REA, CRYPT crypt = NULL); IOHAND (IOMODE mode = REA, CRYPT * crpt = NULL); virtual ~IOHAND (void); - static Boolean Exist (const char * name); + static bool Exist (const char * name); word Read (void * buf, word len); word Write (void * buf, word len); long Mark (void); @@ -250,7 +250,7 @@ int TakeEnum (const char ** tab, const char * txt); word ChkSum (void *m, word n); long Timer (void); long TimerLimit (word t); -Boolean TimerLimitGone (long t); +bool TimerLimitGone (long t); char * MergeExt (char * buf, const char * nam, const char * ext); char * ForceExt (char * buf, const char * nam, const char * ext); inline const char * ProgPath (void); @@ -258,7 +258,7 @@ const char * ProgName (const char * ext = NULL); int DriveFixed (unsigned drv); int DriveRemote (unsigned drv); int DriveCD (unsigned drv); -Boolean IsVga (void); +bool IsVga (void); EC void _fqsort (void *base, word nelem, word width, int (*fcmp)(const void*, const void*)); diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 5d6c8ce1bf9..ad9f885bb92 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -47,8 +47,8 @@ GET_TEXT::GET_TEXT (const char * info, char * text, int size, void (*click)(void Mode = RECT; TS[0] = Box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); SetShapeList(TS); - Flags.BDel = TRUE; - Flags.Kill = TRUE; + Flags.BDel = true; + Flags.Kill = true; memcpy(Buff, text, Len); Buff[Len] = ' '; Buff[Len+1] = '\0'; diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 99e87a38200..22110bc832c 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -36,10 +36,8 @@ #define CR 13 #define NULL 0 -#define TRUE (1==1) -#define FALSE (!TRUE) -#define OFF FALSE -#define ON TRUE +#define OFF false +#define ON true #define IsWhite(c) ((c) == ' ' || (c) == '\t' || (c) == '\n') #define IsUpper(c) ((c) >= 'A' && (c) <= 'Z') @@ -57,7 +55,6 @@ typedef unsigned char BYTE; typedef unsigned int WORD; typedef unsigned long DWORD; -typedef int Boolean; typedef unsigned char byte; typedef unsigned int word; typedef unsigned long dword; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 1e7aa7a1816..56a8c5f335a 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -29,7 +29,7 @@ #include "cge/text.h" #include "cge/snail.h" #include "cge/mouse.h" -#include +#include "cge/snddrv.h" #include #include @@ -38,7 +38,7 @@ extern MOUSE Mouse; - Boolean MIXER::Appear = FALSE; + bool MIXER::Appear = false; @@ -46,14 +46,14 @@ MIXER::MIXER (int x, int y) : SPRITE(NULL), Fall(MIX_FALL) { int i; - Appear = TRUE; + Appear = true; mb[0] = new BITMAP("VOLUME"); mb[1] = NULL; SetShapeList(mb); SetName(Text[MIX_NAME]); - Flags.Syst = TRUE; - Flags.Kill = TRUE; - Flags.BDel = TRUE; + Flags.Syst = true; + Flags.Kill = true; + Flags.BDel = true; Goto(x, y); Z = MIX_Z; @@ -74,13 +74,13 @@ MIXER::MIXER (int x, int y) register SPRITE * spr = new SPRITE(lb); spr->SetSeq(ls); spr->Goto(x+2+12*i, y+8); - spr->Flags.Tran = TRUE; - spr->Flags.Kill = TRUE; - spr->Flags.BDel = FALSE; + spr->Flags.Tran = true; + spr->Flags.Kill = true; + spr->Flags.BDel = false; spr->Z = MIX_Z; Led[i] = spr; } - Led[ArrayCount(Led)-1]->Flags.BDel = TRUE; + Led[ArrayCount(Led)-1]->Flags.BDel = true; VGA::ShowQ.Insert(this); for (i = 0; i < ArrayCount(Led); i ++) VGA::ShowQ.Insert(Led[i]); @@ -101,7 +101,7 @@ MIXER::MIXER (int x, int y) MIXER::~MIXER (void) { - Appear = FALSE; + Appear = false; } diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index bf5d79b67f5..e2377ff7814 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -46,7 +46,7 @@ class MIXER : public SPRITE int Fall; void Update (void); public: - static Boolean Appear; + static bool Appear; MIXER (int x, int y); ~MIXER (void); void Touch (word mask, int x, int y); diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index b9a03868012..5fdaf08995d 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -195,7 +195,7 @@ void MOUSE::Tick (void) Hold = e.Ptr; if (Hold) { - Hold->Flags.Hold = TRUE; + Hold->Flags.Hold = true; #ifndef DEBUG if (Hold->Flags.Drag) #endif @@ -210,7 +210,7 @@ void MOUSE::Tick (void) { if (Hold) { - Hold->Flags.Hold = FALSE; + Hold->Flags.Hold = false; Hold = NULL; } } diff --git a/engines/cge/mouse.h b/engines/cge/mouse.h index 8e69232c5c0..e30abcaa944 100644 --- a/engines/cge/mouse.h +++ b/engines/cge/mouse.h @@ -67,7 +67,7 @@ class MOUSE : public SPRITE //void SetFun (void); //void ResetFun (void); public: - Boolean Exist; + bool Exist; int Buttons; SPRITE * Busy; //SPRITE * Touched; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 4c041653a4d..06824c5b126 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -44,13 +44,13 @@ int MaxCave = 0; SCB Scb = { NULL, 0, NULL }; - Boolean Flag[4]; - Boolean Dark = FALSE; - Boolean Game = FALSE; + bool Flag[4]; + bool Dark = false; + bool Game = false; int Now = 1; int Lev = -1; - SNAIL Snail = FALSE; - SNAIL Snail_ = TRUE; + SNAIL Snail = false; + SNAIL Snail_ = true; extern SPRITE PocLight; @@ -176,7 +176,7 @@ static void SNGame (SPRITE * spr, int num) if (! Game) { SNPOST(SNSAY, buref, 16008, NULL); // zgadnij! - Game = TRUE; + Game = true; } #undef STEPS #undef DRESSED @@ -186,7 +186,7 @@ static void SNGame (SPRITE * spr, int num) { static SPRITE * k = NULL, * k1, * k2, * k3; static int count = 0; - Boolean hit; + bool hit; if (k == NULL) { @@ -199,7 +199,7 @@ static void SNGame (SPRITE * spr, int num) if (! Game) // init { SNPOST(SNGAME, 20002, 2, NULL); - Game = TRUE; + Game = true; } else // cont { @@ -233,7 +233,7 @@ static void SNGame (SPRITE * spr, int num) SNPOST(SNSEND, 20010, 20, NULL); // papier SNPOST(SNSOUND,20010, 20003, NULL); // papier! SNPOST(SNSAY, 20001, 20005, NULL); - Game = FALSE; + Game = false; return; } else k3->Step(random(5)); @@ -414,11 +414,11 @@ void FeedSnail (SPRITE * spr, SNLIST snq) if (p->Ptr) break; } } - while (TRUE) + while (true) { if (c->Com == SNTALK) { - if ((Snail.TalkEnable = (c->Val != 0)) == FALSE) KillText(); + if ((Snail.TalkEnable = (c->Val != 0)) == false) KillText(); } if (c->Com == SNNEXT) { @@ -487,9 +487,9 @@ char * SNAIL::ComTxt[] = { "LABEL", "PAUSE", "WAIT", "LEVEL", -SNAIL::SNAIL (Boolean turbo) -: Turbo(turbo), Busy(FALSE), TextDelay(FALSE), - Pause(0), TalkEnable(TRUE), +SNAIL::SNAIL (bool turbo) +: Turbo(turbo), Busy(false), TextDelay(false), + Pause(0), TalkEnable(true), Head(0), Tail(0), SNList(farnew(COM, 256)) { } @@ -604,9 +604,9 @@ static void SNZTrim (SPRITE * spr) { if (spr) if (spr->Active()) { - Boolean en = HEART::Enable; + bool en = HEART::Enable; SPRITE * s; - HEART::Enable = FALSE; + HEART::Enable = false; s = (spr->Flags.Shad) ? spr->Prev : NULL; VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr)); if (s) @@ -681,8 +681,8 @@ void SNSend (SPRITE * spr, int val) if (spr) { int was = spr->Cave; - Boolean was1 = (was == 0 || was == Now); - Boolean val1 = (val == 0 || val == Now); + bool was1 = (was == 0 || was == Now); + bool val1 = (val == 0 || val == Now); spr->Cave = val; if (val1 != was1) { @@ -695,12 +695,12 @@ void SNSend (SPRITE * spr, int val) } Hide1(spr); ContractSprite(spr); - spr->Flags.Slav = FALSE; + spr->Flags.Slav = false; } else { if (spr->Ref % 1000 == 0) BITMAP::Pal = SysPal; - if (spr->Flags.Back) spr->BackShow(TRUE); + if (spr->Flags.Back) spr->BackShow(true); else ExpandSprite(spr); BITMAP::Pal = NULL; } @@ -719,8 +719,8 @@ void SNSwap (SPRITE * spr, int xref) { int was = spr->Cave; int xwas = xspr->Cave; - Boolean was1 = (was == 0 || was == Now); - Boolean xwas1 = (xwas == 0 || xwas == Now); + bool was1 = (was == 0 || was == Now); + bool xwas1 = (xwas == 0 || xwas == Now); Swap(spr->Cave, xspr->Cave); Swap(spr->X, xspr->X); @@ -730,8 +730,8 @@ void SNSwap (SPRITE * spr, int xref) { int n = FindPocket(spr); if (n >= 0) Pocket[n] = xspr; - xspr->Flags.Kept = TRUE; - xspr->Flags.Port = FALSE; + xspr->Flags.Kept = true; + xspr->Flags.Port = false; } if (xwas1 != was1) { @@ -760,15 +760,15 @@ void SNCover (SPRITE * spr, int xref) SPRITE * xspr = Locate(xref); if (spr && xspr) { - spr->Flags.Hide = TRUE; + spr->Flags.Hide = true; xspr->Z = spr->Z; xspr->Cave = spr->Cave; xspr->Goto(spr->X, spr->Y); ExpandSprite(xspr); - if ((xspr->Flags.Shad = spr->Flags.Shad) == TRUE) + if ((xspr->Flags.Shad = spr->Flags.Shad) == true) { VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr->Prev), xspr); - spr->Flags.Shad = FALSE; + spr->Flags.Shad = false; } FeedSnail(xspr, NEAR); } @@ -782,13 +782,13 @@ void SNUncover (SPRITE * spr, SPRITE * xspr) { if (spr && xspr) { - spr->Flags.Hide = FALSE; + spr->Flags.Hide = false; spr->Cave = xspr->Cave; spr->Goto(xspr->X, xspr->Y); - if ((spr->Flags.Shad = xspr->Flags.Shad) == TRUE) + if ((spr->Flags.Shad = xspr->Flags.Shad) == true) { VGA::ShowQ.Insert(VGA::ShowQ.Remove(xspr->Prev), spr); - xspr->Flags.Shad = FALSE; + xspr->Flags.Shad = false; } spr->Z = xspr->Z; SNSend(xspr, -1); @@ -913,7 +913,7 @@ void SNSlave (SPRITE * spr, int ref) if (spr->Active()) { SNSend(slv, spr->Cave); - slv->Flags.Slav = TRUE; + slv->Flags.Slav = true; slv->Z = spr->Z; VGA::ShowQ.Insert(VGA::ShowQ.Remove(slv), spr->Next); } @@ -997,7 +997,7 @@ void SNKeep (SPRITE * spr, int stp) SNSound(spr, 3, 1); Pocket[PocPtr] = spr; spr->Cave = 0; - spr->Flags.Kept = TRUE; + spr->Flags.Kept = true; spr->Goto(POCKET_X + POCKET_DX*PocPtr + POCKET_DX/2 - spr->W/2, POCKET_Y + POCKET_DY/2 - spr->H/2); if (stp >= 0) spr->Step(stp); @@ -1019,7 +1019,7 @@ void SNGive (SPRITE * spr, int stp) { Pocket[p] = NULL; spr->Cave = Now; - spr->Flags.Kept = FALSE; + spr->Flags.Kept = false; if (stp >= 0) spr->Step(stp); } } @@ -1034,7 +1034,7 @@ static void SNBackPt (SPRITE * spr, int stp) if (spr) { if (stp >= 0) spr->Step(stp); - spr->BackShow(TRUE); + spr->BackShow(true); } } @@ -1056,12 +1056,12 @@ static void SNLevel (SPRITE * spr, int lev) spr = VGA::SpareQ.Locate(100+Lev); if (spr) { - spr->BackShow(TRUE); + spr->BackShow(true); spr->Cave = 0; } } MaxCave = maxcav[Lev]; - if (spr) spr->Flags.Hide = FALSE; + if (spr) spr->Flags.Hide = false; } @@ -1069,7 +1069,7 @@ static void SNLevel (SPRITE * spr, int lev) -static void SNFlag (int fn, Boolean v) +static void SNFlag (int fn, bool v) { Flag[fn] = v; } @@ -1090,7 +1090,7 @@ static void SNSetRef (SPRITE * spr, int nr) -void SNFlash (Boolean on) +void SNFlash (bool on) { if (on) { @@ -1110,14 +1110,14 @@ void SNFlash (Boolean on) } } else VGA::SetColors(SysPal, 64); - Dark = FALSE; + Dark = false; } -static void SNLight (Boolean in) +static void SNLight (bool in) { if (in) VGA::Sunrise(SysPal); else VGA::Sunset(); @@ -1128,7 +1128,7 @@ static void SNLight (Boolean in) -static void SNBarrier (int cav, int bar, Boolean horz) +static void SNBarrier (int cav, int bar, bool horz) { ((byte *) (Barriers + ((cav > 0) ? cav : Now)))[horz] = bar; } @@ -1160,7 +1160,7 @@ static void SNReach (SPRITE * spr, int mode) -static void SNMouse (Boolean on) +static void SNMouse (bool on) { if (on) Mouse.On(); else Mouse.Off(); @@ -1177,7 +1177,7 @@ void SNAIL::RunCom (void) extern void SwitchCave(int); if (! Busy) { - Busy = TRUE; + Busy = true; byte tmphea = Head; while (Tail != tmphea) { @@ -1191,7 +1191,7 @@ void SNAIL::RunCom (void) if (TextDelay) { KillText(); - TextDelay = FALSE; + TextDelay = false; } } if (Talk && snc->Com != SNPAUSE) break; @@ -1203,7 +1203,7 @@ void SNAIL::RunCom (void) { case SNLABEL : break; case SNPAUSE : HEART::SetXTimer(&Pause, snc->Val); - if (Talk) TextDelay = TRUE; break; + if (Talk) TextDelay = true; break; case SNWAIT : if (sprel) { if (sprel->SeqTest(snc->Val) && @@ -1277,8 +1277,8 @@ void SNAIL::RunCom (void) case SNBACKPT : SNBackPt(sprel, snc->Val); break; case SNFLASH : SNFlash(snc->Val != 0); break; case SNLIGHT : SNLight(snc->Val != 0); break; - case SNSETHB : SNBarrier(snc->Ref, snc->Val, TRUE); break; - case SNSETVB : SNBarrier(snc->Ref, snc->Val, FALSE); break; + case SNSETHB : SNBarrier(snc->Ref, snc->Val, true); break; + case SNSETVB : SNBarrier(snc->Ref, snc->Val, false); break; case SNWALK : SNWalk(sprel, snc->Ref, snc->Val); break; case SNREACH : SNReach(sprel, snc->Val); break; case SNSOUND : SNSound(sprel, snc->Val, count); count = 1; break; @@ -1293,7 +1293,7 @@ void SNAIL::RunCom (void) if (! Turbo) break; } xit: - Busy = FALSE; + Busy = false; } } @@ -1301,7 +1301,7 @@ void SNAIL::RunCom (void) -Boolean SNAIL::Idle (void) +bool SNAIL::Idle (void) { return (Head == Tail); } diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 309f9b5a296..f7e19290e6e 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -83,17 +83,17 @@ class SNAIL { struct COM { SNCOM Com; int Ref; int Val; void * Ptr; } * SNList; byte Head, Tail; - Boolean Turbo, Busy, TextDelay; + bool Turbo, Busy, TextDelay; word Pause; public: static char * ComTxt[]; - Boolean TalkEnable; - SNAIL (Boolean turbo = FALSE); + bool TalkEnable; + SNAIL (bool turbo = false); ~SNAIL (void); void RunCom (void); void AddCom (SNCOM com, int ref = 0, int val = 0, void * ptr = NULL); void InsCom (SNCOM com, int ref = 0, int val = 0, void * ptr = NULL); - Boolean Idle (void); + bool Idle (void); }; @@ -110,9 +110,9 @@ void PocFul (void); extern SCB Scb; -extern Boolean Flag[4]; -extern Boolean Game; -extern Boolean Dark; +extern bool Flag[4]; +extern bool Game; +extern bool Dark; extern SNAIL Snail; extern SNAIL Snail_; extern int Now; diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index e8b2a8f4cf0..b3c13a0211e 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -43,7 +43,7 @@ #include - Boolean Music = TRUE; + bool Music = true; FX Fx = 16; // must precede SOUND!! SOUND Sound; diff --git a/engines/cge/sound.h b/engines/cge/sound.h index b43a85dd413..993bd05fca0 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -75,7 +75,7 @@ public: -extern Boolean Music; +extern bool Music; extern SOUND Sound; extern FX Fx; diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index a92e899ee22..5555c12b161 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -67,7 +67,7 @@ void quit_now (int ref) -Boolean STARTUP::get_parms (void) +bool STARTUP::get_parms (void) { int i = _argc; while (i > 1) @@ -89,7 +89,7 @@ Boolean STARTUP::get_parms (void) case 8 : SNDDrvInfo.DIRQ = p; break; case 9 : SNDDrvInfo.MBASE = p; SNDDrvInfo.MDEV = DEV_GM; break; - default: return FALSE; + default: return false; } if (n >= 2) SoundOk = 2; } @@ -112,7 +112,7 @@ Boolean STARTUP::get_parms (void) #endif #endif if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; - return TRUE; + return true; } @@ -132,7 +132,7 @@ STARTUP::STARTUP (void) if (Core < CORE_HIG) { SNDDrvInfo.MDEV = DEV_QUIET; - Music = FALSE; + Music = false; } #endif if (! get_parms()) quit_now(BAD_ARG_TEXT); @@ -160,7 +160,7 @@ const char *UsrPath (const char *nam) #if defined(CD) if (DriveCD(0)) { - Boolean ok = FALSE; + bool ok = false; CFILE ini = Text[CDINI_FNAME]; if (!ini.Error) { @@ -170,7 +170,7 @@ const char *UsrPath (const char *nam) { int j = strlen(buf); if (j) if (buf[--j] == '\n') buf[j] = '\0'; - if (memicmp(buf, key, i) == 0) ok = TRUE; + if (memicmp(buf, key, i) == 0) ok = true; } if (ok) { @@ -179,7 +179,7 @@ const char *UsrPath (const char *nam) if (*(p-1) != '\\') *(p++) = '\\'; strcpy(p, "NUL"); if (_dos_open(buf, 0, &i) == 0) _dos_close(i); - else ok = FALSE; + else ok = false; } } if (!ok) quit_now(BADCD_TEXT); diff --git a/engines/cge/startup.h b/engines/cge/startup.h index bdb2647ab12..27507a7122c 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -59,7 +59,7 @@ class STARTUP { - static Boolean get_parms (void); + static bool get_parms (void); public: static int Mode; static int Core; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 2e247336ab2..d941dba274a 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -138,7 +138,7 @@ TALK::TALK (const char * tx, TBOX_STYLE mode) : SPRITE(NULL), Mode(mode) { TS[0] = TS[1] = NULL; - Flags.Syst = TRUE; + Flags.Syst = true; Update(tx); } @@ -150,7 +150,7 @@ TALK::TALK (void) : SPRITE(NULL), Mode(PURE) { TS[0] = TS[1] = NULL; - Flags.Syst = TRUE; + Flags.Syst = true; } @@ -163,7 +163,7 @@ TALK::~TALK (void) word i; for (i = 0; i < ShpCnt; i ++) { - if (FP_SEG(ShpList[i]) != _DS) // small model: always FALSE + if (FP_SEG(ShpList[i]) != _DS) // small model: always false { delete ShpList[i]; ShpList[i] = NULL; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index b4b6e9b23ca..34b99ac7eb1 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -221,7 +221,7 @@ void Say (const char * txt, SPRITE * spr) Talk = new TALK(txt, ROUND); if (Talk) { - Boolean east = spr->Flags.East; + bool east = spr->Flags.East; int x = (east) ? (spr->X+spr->W-2) : (spr->X+2); int y = spr->Y+2; SPRITE * spike = new SPRITE(SP); @@ -229,17 +229,17 @@ void Say (const char * txt, SPRITE * spr) if (east) { - if (x + sw + TEXT_RD + 5 >= SCR_WID) east = FALSE; + if (x + sw + TEXT_RD + 5 >= SCR_WID) east = false; } else { - if (x <= 5 + TEXT_RD + sw) east = TRUE; + if (x <= 5 + TEXT_RD + sw) east = true; } x = (east) ? (spr->X+spr->W-2) : (spr->X+2-sw); if (spr->Ref == 1) x += (east) ? -10 : 10; // Hero - Talk->Flags.Kill = TRUE; - Talk->Flags.BDel = TRUE; + Talk->Flags.Kill = true; + Talk->Flags.BDel = true; Talk->SetName(Text[SAY_NAME]); Talk->Goto(x - (Talk->W - sw) / 2 - 3 + 6 * east, y - spike->H - Talk->H+1); Talk->Z = 125; @@ -247,8 +247,8 @@ void Say (const char * txt, SPRITE * spr) spike->Goto(x, Talk->Y + Talk->H - 1); spike->Z = 126; - spike->Flags.Slav = TRUE; - spike->Flags.Kill = TRUE; + spike->Flags.Slav = true; + spike->Flags.Kill = true; spike->SetName(Text[SAY_NAME]); spike->Step(east); spike->Ref = SAY_REF; @@ -270,8 +270,8 @@ void Inf (const char * txt) Talk = new TALK(txt, RECT); if (Talk) { - Talk->Flags.Kill = TRUE; - Talk->Flags.BDel = TRUE; + Talk->Flags.Kill = true; + Talk->Flags.BDel = true; Talk->SetName(Text[INF_NAME]); Talk->Center(); Talk->Goto(Talk->X, Talk->Y - 20); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 84dbd802fdb..386ccca1403 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -85,7 +85,7 @@ static VgaRegBlk VideoMode[] = { { 0x00 } }; - Boolean SpeedTest = FALSE; + bool SpeedTest = false; SEQ Seq1[] = { { 0, 0, 0, 0, 0 } }; SEQ Seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; SPRITE * Sys = NULL; @@ -267,7 +267,7 @@ SPRITE * Locate (int ref) //-------------------------------------------------------------------------- -Boolean HEART::Enable = FALSE; +bool HEART::Enable = false; word * HEART::XTimer = NULL; @@ -499,7 +499,7 @@ void SPRITE::MoveShapes (byte * buf) -Boolean SPRITE::Works (SPRITE * spr) +bool SPRITE::Works (SPRITE * spr) { if (spr) if (spr->Ext) { @@ -509,10 +509,10 @@ Boolean SPRITE::Works (SPRITE * spr) c += spr->TakePtr; if (c->Ref == Ref) if (c->Com != SNLABEL || (c->Val == 0 || c->Val == Now)) - return TRUE; + return true; } } - return FALSE; + return false; } @@ -535,11 +535,11 @@ SEQ * SPRITE::SetSeq (SEQ * seq) -Boolean SPRITE::SeqTest (int n) +bool SPRITE::SeqTest (int n) { if (n >= 0) return (SeqPtr == n); if (Ext) return (Ext->Seq[SeqPtr].Next == SeqPtr); - return TRUE; + return true; } @@ -584,8 +584,8 @@ SPRITE * SPRITE::Expand (void) { if (! Ext) { - Boolean enbl = HEART::Enable; - HEART::Enable = FALSE; + bool enbl = HEART::Enable; + HEART::Enable = false; if ((Ext = new SPREXT) == NULL) DROP("No core", NULL); if (*File) { @@ -732,7 +732,7 @@ SPRITE * SPRITE::Contract (void) -SPRITE * SPRITE::BackShow (Boolean fast) +SPRITE * SPRITE::BackShow (bool fast) { Expand(); Show(2); @@ -787,7 +787,7 @@ void SPRITE::MakeXlat (byte * x) if (Flags.Xlat) KillXlat(); for (b = Ext->ShpList; *b; b ++) (*b)->M = x; - Flags.Xlat = TRUE; + Flags.Xlat = true; } } @@ -808,7 +808,7 @@ void SPRITE::KillXlat (void) case FAR_MEM : farfree(m); break; } for (b = Ext->ShpList; *b; b ++) (*b)->M = NULL; - Flags.Xlat = FALSE; + Flags.Xlat = false; } } @@ -953,7 +953,7 @@ SPRITE * SpriteAt (int x, int y) -QUEUE::QUEUE (Boolean show) +QUEUE::QUEUE (bool show) : Head(NULL), Tail(NULL), Show(show) { } @@ -1090,9 +1090,9 @@ const char * VGA::Msg = NULL; const char * VGA::Nam = NULL; DAC * VGA::OldColors = NULL; DAC * VGA::NewColors = NULL; -Boolean VGA::SetPal = FALSE; +bool VGA::SetPal = false; int VGA::Mono = 0; -QUEUE VGA::ShowQ = TRUE, VGA::SpareQ = FALSE; +QUEUE VGA::ShowQ = true, VGA::SpareQ = false; byte * VGA::Page[4] = { (byte *) MK_FP(SCR_SEG, 0x0000), (byte *) MK_FP(SCR_SEG, 0x4000), (byte *) MK_FP(SCR_SEG, 0x8000), @@ -1105,7 +1105,7 @@ VGA::VGA (int mode) : FrmCnt(0) { extern const char Copr[]; - Boolean std = TRUE; + bool std = true; int i; for (i = 10; i < 20; i ++) { @@ -1114,7 +1114,7 @@ VGA::VGA (int mode) { puts(txt); #ifndef DEBUG - std = FALSE; + std = false; #endif } } @@ -1187,7 +1187,7 @@ void VGA::SetStatAdr (void) #pragma argsused -void VGA::WaitVR (Boolean on) +void VGA::WaitVR (bool on) { _DX = StatAdr; _AH = (on) ? 0x00 : 0x08; @@ -1348,7 +1348,7 @@ void VGA::SetColors (DAC * tab, int lum) asm cmp di,cx asm jb mono } - SetPal = TRUE; + SetPal = true; } @@ -1470,7 +1470,7 @@ void VGA::Update (void) if (SetPal) { UpdateColors(); - SetPal = FALSE; + SetPal = false; } } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 4f172cb3ea1..d7ef11f36d1 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -126,7 +126,7 @@ class HEART : public ENGINE { friend ENGINE; public: - static Boolean Enable; + static bool Enable; static word * XTimer; static void SetXTimer (word * ptr); static void SetXTimer (word * ptr, word time); @@ -192,9 +192,9 @@ public: int ShpCnt; char File[MAXFILE]; SPRITE * Prev, * Next; - Boolean Works (SPRITE * spr); - Boolean SeqTest (int n); - inline Boolean Active (void) { return Ext != NULL; } + bool Works (SPRITE * spr); + bool SeqTest (int n); + inline bool Active (void) { return Ext != NULL; } SPRITE (BMP_PTR * shp); virtual ~SPRITE (void); BMP_PTR Shp (void); @@ -202,7 +202,7 @@ public: void MoveShapes (byte * buf); SPRITE * Expand (void); SPRITE * Contract (void); - SPRITE * BackShow (Boolean fast = FALSE); + SPRITE * BackShow (bool fast = false); void SetName(char * n); inline char * Name(void) { return (Ext) ? Ext->Name : NULL; } void Goto (int x, int y); @@ -229,8 +229,8 @@ class QUEUE { SPRITE * Head, * Tail; public: - Boolean Show; - QUEUE (Boolean show = FALSE); + bool Show; + QUEUE (bool show = false); ~QUEUE (void); void Append (SPRITE * spr); void Insert (SPRITE * spr, SPRITE * nxt); @@ -253,7 +253,7 @@ class VGA static word OldMode; static word * OldScreen; static word StatAdr; - static Boolean SetPal; + static bool SetPal; static DAC * OldColors, * NewColors; static int SetMode (int mode); static void UpdateColors (void); @@ -261,7 +261,7 @@ class VGA static const char * Msg; static const char * Nam; static void SetStatAdr (void); - static void WaitVR (Boolean on = TRUE); + static void WaitVR (bool on = true); public: dword FrmCnt; static QUEUE ShowQ, SpareQ; @@ -330,7 +330,7 @@ byte Closest (CBLK * pal, CBLK x) SPRITE * SpriteAt (int x, int y); SPRITE * Locate (int ref); -extern Boolean SpeedTest; +extern bool SpeedTest; #endif diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 4ca3708eaca..f7314e18ea0 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -64,10 +64,10 @@ MENU_BAR::MENU_BAR (word w) } TS[0] = new BITMAP(w, h, p); SetShapeList(TS); - Flags.Slav = TRUE; - Flags.Tran = TRUE; - Flags.Kill = TRUE; - Flags.BDel = TRUE; + Flags.Slav = true; + Flags.Tran = true; + Flags.Kill = true; + Flags.BDel = true; } @@ -120,8 +120,8 @@ VMENU::VMENU (CHOICE * list, int x, int y) delete[] vmgt; Items = 0; for (cp = list; cp->Text; cp ++) ++ Items; - Flags.BDel = TRUE; - Flags.Kill = TRUE; + Flags.BDel = true; + Flags.Kill = true; if (x < 0 || y < 0) Center(); else Goto(x - W / 2, y - (TEXT_VM + FONT_HIG / 2)); VGA::ShowQ.Insert(this, VGA::ShowQ.Last()); @@ -145,7 +145,7 @@ void VMENU::Touch (word mask, int x, int y) { #define h (FONT_HIG+TEXT_LS) int n = 0; - Boolean ok = FALSE; + bool ok = false; if (Items) { diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index f0365867ee4..503c6cab917 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -83,7 +83,7 @@ VFILE::~VFILE (void) -Boolean VFILE::Exist (const char * name) +bool VFILE::Exist (const char * name) { return _fstricmp(Cat.Find(name)->Key, name) == 0; } diff --git a/engines/cge/vol.h b/engines/cge/vol.h index 74b4a2b648b..1357c248143 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -55,9 +55,9 @@ class DAT friend VFILE; static VOLBASE File; public: - static Boolean Append (byte * buf, word len); - static Boolean Write (CFILE& f); - static Boolean Read (long org, word len, byte * buf); + static bool Append (byte * buf, word len); + static bool Write (CFILE& f); + static bool Read (long org, word len, byte * buf); }; @@ -78,7 +78,7 @@ class VFILE : public IOBUF public: VFILE (const char * name, IOMODE mode = REA); ~VFILE (void); - static Boolean Exist (const char * name); + static bool Exist (const char * name); static const char * Next (void); long Mark (void) { return (BufMark+Ptr) - BegMark; } long Size (void) { return EndMark - BegMark; } diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 3266af95d5a..1998672bedf 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -51,8 +51,8 @@ public: CKID (FOURCC t) { memcpy(Tx, t, sizeof(Tx)); } CKID (dword d) { Id = d; } CKID (XFILE * xf) { (ckFile = xf)->Read(Tx, sizeof(Tx)); } - Boolean operator !=(CKID& X) { return Id != X.Id; } - Boolean operator ==(CKID& X) { return Id == X.Id; } + bool operator !=(CKID& X) { return Id != X.Id; } + bool operator ==(CKID& X) { return Id == X.Id; } const char * Name (void); }; @@ -107,7 +107,7 @@ public: class DATACK : public CKHEA { - Boolean e; + bool e; union { byte * Buf; From 7d88b9e4cde321ec210c5da022046639a316179b Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 10 Jun 2011 19:02:13 +0200 Subject: [PATCH 006/276] CGE: Suppress typedef for byte, word and dword. --- engines/cge/bitmap.cpp | 116 +++++++++++++++++++-------------------- engines/cge/bitmap.h | 26 ++++----- engines/cge/bitmaps.cpp | 20 +++---- engines/cge/boot.h | 44 +++++++-------- engines/cge/cfile.cpp | 50 ++++++++--------- engines/cge/cfile.h | 20 +++---- engines/cge/cge_main.cpp | 72 ++++++++++++------------ engines/cge/cge_main.h | 6 +- engines/cge/game.cpp | 18 +++--- engines/cge/game.h | 4 +- engines/cge/general.h | 52 +++++++++--------- engines/cge/gettext.cpp | 2 +- engines/cge/gettext.h | 6 +- engines/cge/jbw.h | 19 ++----- engines/cge/keybd.cpp | 14 ++--- engines/cge/keybd.h | 8 +-- engines/cge/mixer.cpp | 4 +- engines/cge/mixer.h | 2 +- engines/cge/mouse.cpp | 6 +- engines/cge/mouse.h | 8 +-- engines/cge/snail.cpp | 10 ++-- engines/cge/snail.h | 10 ++-- engines/cge/snddrv.h | 32 +++++------ engines/cge/sound.cpp | 12 ++-- engines/cge/startup.cpp | 8 +-- engines/cge/startup.h | 2 +- engines/cge/talk.cpp | 92 +++++++++++++++---------------- engines/cge/talk.h | 18 +++--- engines/cge/text.cpp | 2 +- engines/cge/vga13h.cpp | 96 ++++++++++++++++---------------- engines/cge/vga13h.h | 100 ++++++++++++++++----------------- engines/cge/vmenu.cpp | 8 +-- engines/cge/vmenu.h | 6 +- engines/cge/vol.cpp | 2 +- engines/cge/vol.h | 4 +- engines/cge/wav.h | 32 +++++------ 36 files changed, 462 insertions(+), 469 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index a9ded67e451..9845c4a2dad 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -97,7 +97,7 @@ BITMAP::BITMAP (const char * fname, bool rem) -BITMAP::BITMAP (word w, word h, byte * map) +BITMAP::BITMAP (uint16 w, uint16 h, uint8 * map) : W(w), H(h), M(map), V(NULL) { if (map) Code(); @@ -110,23 +110,23 @@ BITMAP::BITMAP (word w, word h, byte * map) // immediately as VGA video chunks, in near memory as fast as possible, // especially for text line real time display -BITMAP::BITMAP (word w, word h, byte fill) -: W((w + 3) & ~3), // only full dwords allowed! +BITMAP::BITMAP (uint16 w, uint16 h, uint8 fill) +: W((w + 3) & ~3), // only full uint32 allowed! H(h), M(NULL) { - word dsiz = W >> 2; // data size (1 plane line size) - word lsiz = 2 + dsiz + 2; // word for line header, word for gap - word psiz = H * lsiz; // - last gape, but + plane trailer - byte * v = new byte[4 * psiz // the same for 4 planes + uint16 dsiz = W >> 2; // data size (1 plane line size) + uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap + uint16 psiz = H * lsiz; // - last gape, but + plane trailer + uint8 * v = new uint8[4 * psiz // the same for 4 planes + H * sizeof(*B)]; // + room for wash table if (v == NULL) DROP("No core", NULL); - * (word *) v = CPY | dsiz; // data chunk hader + * (uint16 *) v = CPY | dsiz; // data chunk hader memset(v+2, fill, dsiz); // data bytes - * (word *) (v + lsiz - 2) = SKP | ((SCR_WID / 4) - dsiz); // gap + * (uint16 *) (v + lsiz - 2) = SKP | ((SCR_WID / 4) - dsiz); // gap memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines - * (word *) (v + psiz - 2) = EOI; // plane trailer word + * (uint16 *) (v + psiz - 2) = EOI; // plane trailer uint16 memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes HideDesc * b = (HideDesc *) (v + 4 * psiz); b->skip = (SCR_WID - W) >> 2; @@ -147,12 +147,12 @@ BITMAP::BITMAP (const BITMAP& bmp) : W(bmp.W), H(bmp.H), M(NULL), V(NULL) { - byte * v0 = bmp.V; + uint8 * v0 = bmp.V; if (v0) { - word vsiz = FP_OFF(bmp.B) - FP_OFF(v0); - word siz = vsiz + H * sizeof(HideDesc); - byte * v1 = farnew(byte, siz); + uint16 vsiz = FP_OFF(bmp.B) - FP_OFF(v0); + uint16 siz = vsiz + H * sizeof(HideDesc); + uint8 * v1 = farnew(uint8, siz); if (v1 == NULL) DROP("No core", NULL); _fmemcpy(v1, v0, siz); B = (HideDesc *) ((V = v1) + vsiz); @@ -171,7 +171,7 @@ BITMAP::~BITMAP (void) } switch (MemType(V)) { - case NEAR_MEM : delete[] (byte *) V; break; + case NEAR_MEM : delete[] (uint8 *) V; break; case FAR_MEM : farfree(V); break; } } @@ -180,7 +180,7 @@ BITMAP::~BITMAP (void) BITMAP& BITMAP::operator = (const BITMAP& bmp) { - byte * v0 = bmp.V; + uint8 * v0 = bmp.V; W = bmp.W; H = bmp.H; M = NULL; @@ -188,9 +188,9 @@ BITMAP& BITMAP::operator = (const BITMAP& bmp) if (v0 == NULL) V = NULL; else { - word vsiz = FP_OFF(bmp.B) - FP_OFF(v0); - word siz = vsiz + H * sizeof(HideDesc); - byte * v1 = farnew(byte, siz); + uint16 vsiz = FP_OFF(bmp.B) - FP_OFF(v0); + uint16 siz = vsiz + H * sizeof(HideDesc); + uint8 * v1 = farnew(uint8, siz); if (v1 == NULL) DROP("No core", NULL); _fmemcpy(v1, v0, siz); B = (HideDesc *) ((V = v1) + vsiz); @@ -202,12 +202,12 @@ BITMAP& BITMAP::operator = (const BITMAP& bmp) -word BITMAP::MoveVmap (byte * buf) +uint16 BITMAP::MoveVmap (uint8 * buf) { if (V) { - word vsiz = FP_OFF(B) - FP_OFF(V); - word siz = vsiz + H * sizeof(HideDesc); + uint16 vsiz = FP_OFF(B) - FP_OFF(V); + uint16 siz = vsiz + H * sizeof(HideDesc); _fmemcpy(buf, V, siz); if (MemType(V) == FAR_MEM) farfree(V); B = (HideDesc *) ((V = buf) + vsiz); @@ -226,13 +226,13 @@ BMP_PTR BITMAP::Code (void) { if (M) { - word i, cnt; + uint16 i, cnt; if (V) // old X-map exists, so remove it { switch (MemType(V)) { - case NEAR_MEM : delete[] (byte *) V; break; + case NEAR_MEM : delete[] (uint8 *) V; break; case FAR_MEM : farfree(V); break; } V = NULL; @@ -240,8 +240,8 @@ BMP_PTR BITMAP::Code (void) while (true) // at most 2 times: for (V == NULL) & for allocated block; { - byte * im = V+2; - word * cp = (word *) V; + uint8 * im = V+2; + uint16 * cp = (uint16 *) V; int bpl; if (V) // 2nd pass - fill the hide table @@ -254,14 +254,14 @@ BMP_PTR BITMAP::Code (void) } for (bpl = 0; bpl < 4; bpl ++) // once per each bitplane { - byte * bm = M; + uint8 * bm = M; bool skip = (bm[bpl] == TRANS); - word j; + uint16 j; cnt = 0; for (i = 0; i < H; i ++) // once per each line { - byte pix; + uint8 pix; for (j = bpl; j < W; j += 4) { pix = bm[j]; @@ -275,9 +275,9 @@ BMP_PTR BITMAP::Code (void) cnt |= (skip) ? SKP : CPY; if (V) { - *cp = cnt; // store block description word + *cp = cnt; // store block description uint16 } - cp = (word *) im; + cp = (uint16 *) im; im += 2; skip = (pix == TRANS); cnt = 0; @@ -304,7 +304,7 @@ BMP_PTR BITMAP::Code (void) { *cp = cnt; } - cp = (word *) im; + cp = (uint16 *) im; im += 2; skip = true; cnt = (SCR_WID - j + 3) / 4; @@ -318,16 +318,16 @@ BMP_PTR BITMAP::Code (void) { *cp = cnt; } - cp = (word *) im; + cp = (uint16 *) im; im += 2; } if (V) *cp = EOI; - cp = (word *) im; + cp = (uint16 *) im; im += 2; } if (V) break; - word sizV = (word) (im - 2 - V); - V = farnew(byte, sizV + H * sizeof(*B)); + uint16 sizV = (uint16) (im - 2 - V); + V = farnew(uint8, sizV + H * sizeof(*B)); if (! V) { DROP("No core", NULL); @@ -344,8 +344,8 @@ BMP_PTR BITMAP::Code (void) } else { - word s = B[i].skip & ~3; - word h = (B[i].hide + 3) & ~3; + uint16 s = B[i].skip & ~3; + uint16 h = (B[i].hide + 3) & ~3; B[i].skip = (cnt + s) >> 2; B[i].hide = (h - s) >> 2; cnt = SCR_WID - h; @@ -362,8 +362,8 @@ BMP_PTR BITMAP::Code (void) bool BITMAP::SolidAt (int x, int y) { - byte * m; - word r, n, n0; + uint8 * m; + uint16 r, n, n0; if (x >= W || y >= H) return false; @@ -373,9 +373,9 @@ bool BITMAP::SolidAt (int x, int y) while (r) { - word w, t; + uint16 w, t; - w = * (word *) m; + w = * (uint16 *) m; m += 2; t = w & 0xC000; w &= 0x3FFF; @@ -391,9 +391,9 @@ bool BITMAP::SolidAt (int x, int y) while (true) { - word w, t; + uint16 w, t; - w = * (word *) m; + w = * (uint16 *) m; m += 2; t = w & 0xC000; w &= 0x3FFF; @@ -418,13 +418,13 @@ bool BITMAP::SolidAt (int x, int y) bool BITMAP::VBMSave (XFILE * f) { - word p = (Pal != NULL), - n = ((word) (((byte *)B) - V)) + H * sizeof(HideDesc); - if (f->Error == 0) f->Write((byte *)&p, sizeof(p)); - if (f->Error == 0) f->Write((byte *)&n, sizeof(n)); - if (f->Error == 0) f->Write((byte *)&W, sizeof(W)); - if (f->Error == 0) f->Write((byte *)&H, sizeof(H)); - if (f->Error == 0) if (p) f->Write((byte *)Pal, 256 * sizeof(DAC)); + uint16 p = (Pal != NULL), + n = ((uint16) (((uint8 *)B) - V)) + H * sizeof(HideDesc); + if (f->Error == 0) f->Write((uint8 *)&p, sizeof(p)); + if (f->Error == 0) f->Write((uint8 *)&n, sizeof(n)); + if (f->Error == 0) f->Write((uint8 *)&W, sizeof(W)); + if (f->Error == 0) f->Write((uint8 *)&H, sizeof(H)); + if (f->Error == 0) if (p) f->Write((uint8 *)Pal, 256 * sizeof(DAC)); if (f->Error == 0) f->Write(V, n); return (f->Error == 0); } @@ -435,20 +435,20 @@ bool BITMAP::VBMSave (XFILE * f) bool BITMAP::VBMLoad (XFILE * f) { - word p, n; - if (f->Error == 0) f->Read((byte *)&p, sizeof(p)); - if (f->Error == 0) f->Read((byte *)&n, sizeof(n)); - if (f->Error == 0) f->Read((byte *)&W, sizeof(W)); - if (f->Error == 0) f->Read((byte *)&H, sizeof(H)); + uint16 p, n; + if (f->Error == 0) f->Read((uint8 *)&p, sizeof(p)); + if (f->Error == 0) f->Read((uint8 *)&n, sizeof(n)); + if (f->Error == 0) f->Read((uint8 *)&W, sizeof(W)); + if (f->Error == 0) f->Read((uint8 *)&H, sizeof(H)); if (f->Error == 0) { if (p) { - if (Pal) f->Read((byte *)Pal, 256 * sizeof(DAC)); + if (Pal) f->Read((uint8 *)Pal, 256 * sizeof(DAC)); else f->Seek(f->Mark() + 256 * sizeof(DAC)); } } - if ((V = farnew(byte, n)) == NULL) return false; + if ((V = farnew(uint8, n)) == NULL) return false; if (f->Error == 0) f->Read(V, n); B = (HideDesc *) (V + n - H * sizeof(HideDesc)); return (f->Error == 0); diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index de2214fd632..2ce849cc2b5 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -38,17 +38,17 @@ #define TRANS 0xFE -typedef struct { word b : 2; - word B : 6; - word g : 2; - word G : 6; - word r : 2; - word R : 6; - word Z : 8; +typedef struct { uint16 b : 2; + uint16 B : 6; + uint16 g : 2; + uint16 G : 6; + uint16 r : 2; + uint16 R : 6; + uint16 Z : 8; } BGR4; -typedef struct { word skip; word hide; } HideDesc; +typedef struct { uint16 skip; uint16 hide; } HideDesc; @@ -59,11 +59,11 @@ class BITMAP bool VBMLoad (XFILE * f); public: static DAC * Pal; - word W, H; - byte * M, * V; HideDesc * B; + uint16 W, H; + uint8 * M, * V; HideDesc * B; BITMAP (const char * fname, bool rem = true); - BITMAP (word w, word h, byte * map); - BITMAP (word w, word h, byte fill); + BITMAP (uint16 w, uint16 h, uint8 * map); + BITMAP (uint16 w, uint16 h, uint8 fill); BITMAP (const BITMAP& bmp); ~BITMAP (void); BITMAP * FlipH (void); @@ -74,7 +74,7 @@ public: void XShow (int x, int y); bool SolidAt (int x, int y); bool VBMSave (XFILE * f); - word MoveVmap (byte * buf); + uint16 MoveVmap (uint8 * buf); }; diff --git a/engines/cge/bitmaps.cpp b/engines/cge/bitmaps.cpp index 4749430c5b6..0cdae18cab0 100644 --- a/engines/cge/bitmaps.cpp +++ b/engines/cge/bitmaps.cpp @@ -36,7 +36,7 @@ #define G GRAY, #define D DGRAY, -static byte MCDesign0[]= { W W W W W W _ +static uint8 MCDesign0[]= { W W W W W W _ W W W W W o _ W W W W o _ _ W W W W W _ _ @@ -46,11 +46,11 @@ static byte MCDesign0[]= { W W W W W W _ _ _ _ _ _ o o }; -static byte MCDesign1[]= { _ }; +static uint8 MCDesign1[]= { _ }; -static byte SLDesign[] = { G G G G G G G G G _ _ _ _ _ _ +static uint8 SLDesign[] = { G G G G G G G G G _ _ _ _ _ _ L G G G G G G G G D _ _ _ _ _ _ L G G G G G G G D _ _ _ _ _ _ _ L G G G G G G G D _ _ _ _ @@ -68,7 +68,7 @@ static byte SLDesign[] = { G G G G G G G G G _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ D }; -static byte SRDesign[] = { _ _ _ _ _ _ G G G G G G G G G +static uint8 SRDesign[] = { _ _ _ _ _ _ G G G G G G G G G _ _ _ _ _ L G G G G G G G G D _ _ _ _ _ L G G G G G G G D _ _ _ _ _ L G G G G G G G D _ _ @@ -86,7 +86,7 @@ static byte SRDesign[] = { _ _ _ _ _ _ G G G G G G G G G D _ _ _ _ _ _ _ _ _ _ _ _ _ _ }; -static byte MapBrick[] = { L L L L L L L G +static uint8 MapBrick[] = { L L L L L L L G L G G G G G G D L G G G G G G D G D D D D D D D @@ -110,7 +110,7 @@ static byte MapBrick[] = { L L L L L L L G #define D 219, #define E 231, -static byte PRDesign[] = { A E E E C C D A B +static uint8 PRDesign[] = { A E E E C C D A B C _ _ _ _ _ _ D A C _ _ _ _ _ _ D A C _ _ _ _ _ _ D A @@ -131,7 +131,7 @@ static byte PRDesign[] = { A E E E C C D A B #define E 231, #define F 237, -static byte PRDesign[] = { D D D D D D D D _ +static uint8 PRDesign[] = { D D D D D D D D _ D D D D D D D D _ D _ _ _ _ _ _ _ _ D _ _ _ _ _ _ _ _ @@ -159,7 +159,7 @@ static byte PRDesign[] = { D D D D D D D D _ #define A _ x _ x _ x _ x #define B A A A A A A A A -static byte HLDesign[] = { B B B B B }; +static uint8 HLDesign[] = { B B B B B }; #undef _ #undef x @@ -178,7 +178,7 @@ static byte HLDesign[] = { B B B B B }; #define D 226, #define E 255, -static byte LIDesign[][9] = { { A A A +static uint8 LIDesign[][9] = { { A A A A B A A A A }, @@ -206,7 +206,7 @@ static byte LIDesign[][9] = { { A A A #define G 0, //226, -static byte MEDesign[][9] = { { R R R R R R R R R }, // 0 +static uint8 MEDesign[][9] = { { R R R R R R R R R }, // 0 { R R R R R R R R G }, // 1 { R R R R R R R G G }, // 2 { R R R R R R G G G }, // 3 diff --git a/engines/cge/boot.h b/engines/cge/boot.h index 1715fd02ecb..3a22e896614 100644 --- a/engines/cge/boot.h +++ b/engines/cge/boot.h @@ -40,36 +40,36 @@ #endif typedef struct { - byte Jmp[3]; // NEAR jump machine code + uint8 Jmp[3]; // NEAR jump machine code char OEM_ID[8]; // OEM name and version - word SectSize; // bytes per sector - byte ClustSize; // sectors per cluster - word ResSecs; // sectors before 1st FAT - byte FatCnt; // number of FATs - word RootSize; // root directory entries - word TotSecs; // total sectors on disk - byte Media; // media descriptor byte - word FatSize; // sectors per FAT - word TrkSecs; // sectors per track - word HeadCnt; // number of sufraces - word HidnSecs; // special hidden sectors - word _; // (unknown: reserved?) - dword lTotSecs; // total number of sectors - word DriveNum; // physical drive number - byte XSign; // extended boot signature - dword Serial; // volume serial number + uint16 SectSize; // bytes per sector + uint8 ClustSize; // sectors per cluster + uint16 ResSecs; // sectors before 1st FAT + uint8 FatCnt; // number of FATs + uint16 RootSize; // root directory entries + uint16 TotSecs; // total sectors on disk + uint8 Media; // media descriptor byte + uint16 FatSize; // sectors per FAT + uint16 TrkSecs; // sectors per track + uint16 HeadCnt; // number of sufraces + uint16 HidnSecs; // special hidden sectors + uint16 _; // (unknown: reserved?) + uint32 lTotSecs; // total number of sectors + uint16 DriveNum; // physical drive number + uint8 XSign; // extended boot signature + uint32 Serial; // volume serial number char Label[11]; // volume label char FileSysID[8]; // file system ID char Code[BOOTCODE_SIZ-8]; // 8 = length of following - dword Secret; // long secret number - byte BootCheck; // boot sector checksum - byte BootFlags; // secret flags - word BootSig; // boot signature 0xAA55 + uint32 Secret; // long secret number + uint8 BootCheck; // boot sector checksum + uint8 BootFlags; // secret flags + uint16 BootSig; // boot signature 0xAA55 } Boot; EC Boot * ReadBoot (int drive); -EC byte CheckBoot (Boot * boot); +EC uint8 CheckBoot (Boot * boot); EC bool WriteBoot (int drive, Boot * boot); diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 7d222d101d5..efc922b2323 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -48,7 +48,7 @@ IOBUF::IOBUF (IOMODE mode, CRYPT * crpt) Ptr(0), Lim(0) { - Buff = farnew(byte, IOBUF_SIZE); + Buff = farnew(uint8, IOBUF_SIZE); if (Buff == NULL) DROP("No core for I/O", NULL); } @@ -66,7 +66,7 @@ IOBUF::IOBUF (const char * name, IOMODE mode, CRYPT * crpt) Ptr(0), Lim(0) { - Buff = farnew(byte, IOBUF_SIZE); + Buff = farnew(uint8, IOBUF_SIZE); if (Buff == NULL) DROP("No core for I/O", name); } @@ -114,18 +114,18 @@ void IOBUF::WriteBuff (void) -word IOBUF::Read (void *buf, word len) +uint16 IOBUF::Read (void *buf, uint16 len) { - word total = 0; + uint16 total = 0; while (len) { if (Ptr >= Lim) ReadBuff(); - word n = Lim - Ptr; + uint16 n = Lim - Ptr; if (n) { if (len < n) n = len; _fmemcpy(buf, Buff+Ptr, n); - (byte *) buf += n; + (uint8 *) buf += n; len -= n; total += n; Ptr += n; @@ -140,25 +140,25 @@ word IOBUF::Read (void *buf, word len) -word IOBUF::Read (byte * buf) +uint16 IOBUF::Read (uint8 * buf) { - word total = 0; + uint16 total = 0; while (total < LINE_MAX-2) { if (Ptr >= Lim) ReadBuff(); - byte * p = Buff + Ptr; - word n = Lim - Ptr; + uint8 * p = Buff + Ptr; + uint16 n = Lim - Ptr; if (n) { if (total + n >= LINE_MAX-2) n = LINE_MAX-2 - total; - byte * eol = (byte *) _fmemchr(p, '\r', n); - if (eol) n = (word) (eol - p); - byte * eof = (byte *) _fmemchr(p, '\32', n); + uint8 * eol = (uint8 *) _fmemchr(p, '\r', n); + if (eol) n = (uint16) (eol - p); + uint8 * eof = (uint8 *) _fmemchr(p, '\32', n); if (eof) // end-of-file { - n = (word) (eof - p); - Ptr = (word) (eof - Buff); + n = (uint16) (eof - p); + Ptr = (uint16) (eof - Buff); } if (n) _fmemcpy(buf, p, n); buf += n; @@ -187,19 +187,19 @@ word IOBUF::Read (byte * buf) -word IOBUF::Write (void * buf, word len) +uint16 IOBUF::Write (void * buf, uint16 len) { - word tot = 0; + uint16 tot = 0; while (len) { - word n = IOBUF_SIZE - Lim; + uint16 n = IOBUF_SIZE - Lim; if (n > len) n = len; if (n) { _fmemcpy(Buff+Lim, buf, n); Lim += n; len -= n; - (byte *) buf += n; + (uint8 *) buf += n; tot += n; } else WriteBuff(); @@ -212,9 +212,9 @@ word IOBUF::Write (void * buf, word len) -word IOBUF::Write (byte * buf) +uint16 IOBUF::Write (uint8 * buf) { - word len = 0; + uint16 len = 0; if (buf) { len = _fstrlen((const char *) buf); @@ -223,7 +223,7 @@ word IOBUF::Write (byte * buf) if (len) { static char EOL[] = "\r\n"; - word n = Write(EOL, sizeof(EOL)-1); + uint16 n = Write(EOL, sizeof(EOL)-1); len += n; } } @@ -250,7 +250,7 @@ int IOBUF::Read (void) -void IOBUF::Write (byte b) +void IOBUF::Write (uint8 b) { if (Lim >= IOBUF_SIZE) { @@ -264,7 +264,7 @@ void IOBUF::Write (byte b) - word CFILE::MaxLineLen = LINE_MAX; + uint16 CFILE::MaxLineLen = LINE_MAX; @@ -321,7 +321,7 @@ long CFILE::Seek (long pos) { if (pos >= BufMark && pos < BufMark + Lim) { - ((Mode == REA) ? Ptr : Lim) = (word) (pos - BufMark); + ((Mode == REA) ? Ptr : Lim) = (uint16) (pos - BufMark); return pos; } else diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index 5903d605ed4..bbb45a9e85f 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -38,7 +38,7 @@ #define IOBUF_SIZE K(2) #endif -#define CFREAD(x) Read((byte *)(x),sizeof(*(x))) +#define CFREAD(x) Read((uint8 *)(x),sizeof(*(x))) @@ -46,10 +46,10 @@ class IOBUF : public IOHAND { protected: - byte * Buff; - word Ptr, Lim; + uint8 * Buff; + uint16 Ptr, Lim; long BufMark; - word Seed; + uint16 Seed; CRYPT * Crypt; virtual void ReadBuff (void); virtual void WriteBuff (void); @@ -57,12 +57,12 @@ public: IOBUF (IOMODE mode, CRYPT * crpt = NULL); IOBUF (const char * name, IOMODE mode, CRYPT * crpt = NULL); virtual ~IOBUF (void); - word Read (void * buf, word len); - word Read (char * buf); + uint16 Read (void * buf, uint16 len); + uint16 Read (char * buf); int Read (void); - word Write (void * buf, word len); - word Write (byte * buf); - void Write (byte b); + uint16 Write (void * buf, uint16 len); + uint16 Write (uint8 * buf); + void Write (uint8 b); }; @@ -70,7 +70,7 @@ public: class CFILE : public IOBUF { public: - static word MaxLineLen; + static uint16 MaxLineLen; CFILE (const char * name, IOMODE mode = REA, CRYPT * crpt = NULL); virtual ~CFILE (void); void Flush (void); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 1f621948c2d..d8829247a4b 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -74,7 +74,7 @@ #define SVG0FILE INI_FILE #endif -extern word _stklen = (STACK_SIZ * 2); +extern uint16 _stklen = (STACK_SIZ * 2); // 0.75 - 17II95 - full sound support // 0.76 - 18II95 - small MiniEMS in DEMO, @@ -137,14 +137,14 @@ static SPRITE * MiniCave = NULL; static SPRITE * Shadow = NULL; static VGA Vga = M13H; -static EMS * Mini = MiniEmm.Alloc((word)MINI_EMM_SIZE); +static EMS * Mini = MiniEmm.Alloc((uint16)MINI_EMM_SIZE); static BMP_PTR * MiniShpList = NULL; static BMP_PTR MiniShp[] = { NULL, NULL }; static KEYBOARD Keyboard; static bool Finis = false; static int Startup = 1; static int OffUseCount = atoi(Text[OFF_USE_COUNT]); - word *intStackPtr = false; + uint16 *intStackPtr = false; HXY HeroXY[CAVE_MAX] = {{0,0}}; @@ -168,11 +168,11 @@ void FeedSnail (SPRITE * spr, SNLIST snq); // defined in SNAIL -byte CLUSTER::Map[MAP_ZCNT][MAP_XCNT]; +uint8 CLUSTER::Map[MAP_ZCNT][MAP_XCNT]; -byte & CLUSTER::Cell (void) +uint8 & CLUSTER::Cell (void) { return Map[B][A]; } @@ -189,7 +189,7 @@ bool CLUSTER::Protected (void) if (A == Barriers[Now].Vert || B == Barriers[Now].Horz) return true; _DX = (MAP_ZCNT << 8) + MAP_XCNT; - _BX = (word) this; + _BX = (uint16) this; asm mov ax,1 asm mov cl,[bx].(COUPLE)A @@ -209,7 +209,7 @@ bool CLUSTER::Protected (void) asm xor ch,ch asm add ax,cx asm mov bx,ax - _BX += (word) Map; + _BX += (uint16) Map; //asm add bx,offset CLUSTER::Map asm mov al,[bx] asm and ax,0xFF @@ -252,8 +252,8 @@ CLUSTER XZ (COUPLE xy) int pocref[POCKET_NX]; - byte volume[2]; - struct SAVTAB { void * Ptr; int Len; byte Flg; } SavTab[] = + uint8 volume[2]; + struct SAVTAB { void * Ptr; int Len; uint8 Flg; } SavTab[] = {{ &Now, sizeof(Now), 1 }, { &OldLev, sizeof(OldLev), 1 }, { &DemoText, sizeof(DemoText), 1 }, @@ -285,10 +285,10 @@ static void LoadGame (XFILE& file, bool tiny = false) for (st = SavTab; st->Ptr; st ++) { if (file.Error) VGA::Exit("Bad SVG"); - file.Read((byte *) ((tiny || st->Flg) ? st->Ptr : &i), st->Len); + file.Read((uint8 *) ((tiny || st->Flg) ? st->Ptr : &i), st->Len); } - file.Read((byte *) &i, sizeof(i)); + file.Read((uint8 *) &i, sizeof(i)); if (i != SVGCHKSUM) VGA::Exit(BADSVG_TEXT); if (STARTUP::Core < CORE_HIG) Music = false; if (STARTUP::SoundOk == 1 && STARTUP::Mode == 0) @@ -303,7 +303,7 @@ static void LoadGame (XFILE& file, bool tiny = false) while (! file.Error) { SPRITE S(NULL); - word n = file.Read((byte *) &S, sizeof(S)); + uint16 n = file.Read((uint8 *) &S, sizeof(S)); if (n != sizeof(S)) break; S.Prev = S.Next = NULL; @@ -354,14 +354,14 @@ static void SaveGame (XFILE& file) for (st = SavTab; st->Ptr; st ++) { if (file.Error) VGA::Exit("Bad SVG"); - file.Write((byte *) st->Ptr, st->Len); + file.Write((uint8 *) st->Ptr, st->Len); } - file.Write((byte *) &(i = SVGCHKSUM), sizeof(i)); + file.Write((uint8 *) &(i = SVGCHKSUM), sizeof(i)); for (spr = VGA::SpareQ.First(); spr; spr = spr->Next) if (spr->Ref >= 1000) - if (!file.Error) file.Write((byte *)spr, sizeof(*spr)); + if (!file.Error) file.Write((uint8 *)spr, sizeof(*spr)); } @@ -435,7 +435,7 @@ static void LoadMapping (void) { memset(CLUSTER::Map, 0, sizeof(CLUSTER::Map)); cf.Seek((Now - 1) * sizeof(CLUSTER::Map)); - cf.Read((byte *) CLUSTER::Map, sizeof(CLUSTER::Map)); + cf.Read((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); } } } @@ -579,7 +579,7 @@ void WALK::Park (void) void WALK::FindWay (CLUSTER c) { bool Find1Way(void); - extern word Target; + extern uint16 Target; if (c != Here) { @@ -670,7 +670,7 @@ class SQUARE : public SPRITE { public: SQUARE (void); - void Touch (word mask, int x, int y); + void Touch (uint16 mask, int x, int y); }; @@ -692,7 +692,7 @@ SQUARE::SQUARE (void) -void SQUARE::Touch (word mask, int x, int y) +void SQUARE::Touch (uint16 mask, int x, int y) { SPRITE::Touch(mask, x, y); if (mask & L_UP) @@ -865,7 +865,7 @@ void SYSTEM::SetPal (void) void SYSTEM::FunTouch (void) { - word n = (PAIN) ? HEROFUN1 : HEROFUN0; + uint16 n = (PAIN) ? HEROFUN1 : HEROFUN0; if (Talk == NULL || n > FunDel) FunDel = n; } @@ -1038,7 +1038,7 @@ void SwitchCave (int cav) -void SYSTEM::Touch (word mask, int x, int y) +void SYSTEM::Touch (uint16 mask, int x, int y) { static int pp = 0; void SwitchCave (int cav); @@ -1426,7 +1426,7 @@ static void SaveMapping (void) if (! cf.Error) { cf.Seek((Now-1) * sizeof(CLUSTER::Map)); - cf.Write((byte *) CLUSTER::Map, sizeof(CLUSTER::Map)); + cf.Write((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); } } { @@ -1435,7 +1435,7 @@ static void SaveMapping (void) { HeroXY[Now-1].X = Hero->X; HeroXY[Now-1].Y = Hero->Y; - cf.Write((byte *) HeroXY, sizeof(HeroXY)); + cf.Write((uint8 *) HeroXY, sizeof(HeroXY)); } } } @@ -1490,8 +1490,8 @@ static void SayDebug (void) if (t1 - t >= 18) { - static dword old = 0L; - dword now = Vga.FrmCnt; + static uint32 old = 0L; + uint32 now = Vga.FrmCnt; dwtom(now - old, FRPS, 10, 4); old = now; t = t1; @@ -1503,7 +1503,7 @@ static void SayDebug (void) dwtom(farcoreleft(), FFRE, 10, 6); // sprite queue size - word n = 0; + uint16 n = 0; SPRITE * spr; for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { @@ -1517,7 +1517,7 @@ static void SayDebug (void) dwtom(Sprite->Z, SP_Z, 10, 3); dwtom(Sprite->W, SP_W, 10, 3); dwtom(Sprite->H, SP_H, 10, 3); - dwtom(*(word *) (&Sprite->Flags), SP_F, 16, 2); + dwtom(*(uint16 *) (&Sprite->Flags), SP_F, 16, 2); } } dwtom(n, SP_S, 10, 2); @@ -1544,7 +1544,7 @@ static void SwitchDebug (void) -static void OptionTouch (int opt, word mask) +static void OptionTouch (int opt, uint16 mask) { switch (opt) { @@ -1567,7 +1567,7 @@ static void OptionTouch (int opt, word mask) #pragma argsused -void SPRITE::Touch (word mask, int x, int y) +void SPRITE::Touch (uint16 mask, int x, int y) { SYSTEM::FunTouch(); if ((mask & ATTN) == 0) @@ -1678,7 +1678,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro bool port = false; bool tran = false; int i, lcnt = 0; - word len; + uint16 len; MergeExt(line, fname, SPR_EXT); if (INI_FILE::Exist(line)) // sprite description file exist @@ -1910,7 +1910,7 @@ static void MainLoop (void) #ifdef DEMO #define TIM ((182L*6L) * 5L) - static dword tc = 0; + static uint32 tc = 0; if (TimerCount - tc >= TIM && Talk == NULL && Snail.Idle()) { if (Text[DemoText]) @@ -1998,7 +1998,7 @@ static void RunGame (void) if (Mini && INI_FILE::Exist("MINI.SPR")) { - byte * ptr = (byte *) &*Mini; + uint8 * ptr = (uint8 *) &*Mini; if (ptr != NULL) { LoadSprite("MINI", -1, 0, MINI_X, MINI_Y); @@ -2159,7 +2159,7 @@ bool ShowTitle (const char * name) STARTUP::Summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; #else Boot * b = ReadBoot(getdisk()); - dword sn = (b->XSign == 0x29) ? b->Serial : b->lTotSecs; + uint32 sn = (b->XSign == 0x29) ? b->Serial : b->lTotSecs; free(b); sn -= ((IDENT *)Copr)->disk; STARTUP::Summa |= Lo(sn) | Hi(sn); @@ -2217,7 +2217,7 @@ bool ShowTitle (const char * name) void StkDump (void) { CFILE f("!STACK.DMP", BFW); - f.Write((byte *) (intStackPtr-STACK_SIZ/2), STACK_SIZ*2); + f.Write((uint8 *) (intStackPtr-STACK_SIZ/2), STACK_SIZ*2); } #endif */ @@ -2227,7 +2227,7 @@ void StkDump (void) void cge_main (void) { - word intStack[STACK_SIZ/2]; + uint16 intStack[STACK_SIZ/2]; intStackPtr = intStack; //Debug( memset((void *) (-K(2)), 0, K(1)); ) @@ -2240,7 +2240,7 @@ void cge_main (void) Debug( DebugLine.Flags.Hide = true; ) Debug( HorzLine.Flags.Hide = true; ) - srand((word) Timer()); + srand((uint16) Timer()); Sys = new SYSTEM; if (Music && STARTUP::SoundOk) LoadMIDI(0); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 4f610897b1d..c1155eb6506 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -148,7 +148,7 @@ public: static void SetPal (void); static void FunTouch (void); SYSTEM (void) : SPRITE(NULL) { SetPal(); Tick(); } - void Touch (word mask, int x, int y); + void Touch (uint16 mask, int x, int y); void Tick (void); }; @@ -163,8 +163,8 @@ public: class CLUSTER : public COUPLE { public: - static byte Map[MAP_ZCNT][MAP_XCNT]; - byte &Cell (void); + static uint8 Map[MAP_ZCNT][MAP_XCNT]; + uint8 &Cell (void); CLUSTER (void) : COUPLE () { } CLUSTER (int a, int b) : COUPLE (a, b) { } bool Protected (void); diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 620e988c361..cc80a8f7fab 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -34,17 +34,17 @@ -byte * Glass (DAC * pal, byte r, byte g, byte b) +uint8 * Glass (DAC * pal, uint8 r, uint8 g, uint8 b) { - byte * x = new byte[256]; + uint8 * x = new uint8[256]; if (x) { - word i; + uint16 i; for (i = 0; i < 256; i ++) { - x[i] = Closest(pal, MkDAC(((word)(pal[i].R) * r) / 255, - ((word)(pal[i].G) * g) / 255, - ((word)(pal[i].B) * b) / 255)); + x[i] = Closest(pal, MkDAC(((uint16)(pal[i].R) * r) / 255, + ((uint16)(pal[i].G) * g) / 255, + ((uint16)(pal[i].B) * b) / 255)); } } return x; @@ -54,13 +54,13 @@ byte * Glass (DAC * pal, byte r, byte g, byte b) -byte * Mark (DAC * pal) +uint8 * Mark (DAC * pal) { #define f(c) (c ^ 63) - byte * x = new byte[256]; + uint8 * x = new uint8[256]; if (x) { - word i; + uint16 i; for (i = 0; i < 256; i ++) { x[i] = Closest(pal, MkDAC(f(pal[i].R), diff --git a/engines/cge/game.h b/engines/cge/game.h index 7a5efd9844f..cda24512e38 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -44,8 +44,8 @@ extern SPRITE * Sys; int Sinus (long x); -byte * Glass (DAC * pal, byte r, byte g, byte b); -byte * Mark (DAC * pal); +uint8 * Glass (DAC * pal, uint8 r, uint8 g, uint8 b); +uint8 * Mark (DAC * pal); diff --git a/engines/cge/general.h b/engines/cge/general.h index 03c34d70584..75f754d0a37 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -35,10 +35,10 @@ #define SCR_WID_ 320 #define SCR_HIG_ 200 -#define SCR_WID ((word)SCR_WID_) -#define SCR_HIG ((word)SCR_HIG_) +#define SCR_WID ((uint16)SCR_WID_) +#define SCR_HIG ((uint16)SCR_HIG_) #define SCR_SEG 0xA000 -#define SCR_ADR ((byte *) MK_FP(SCR_SEG, 0)) +#define SCR_ADR ((uint8 *) MK_FP(SCR_SEG, 0)) @@ -48,10 +48,10 @@ enum ALLOC_MODE { FIRST_FIT, BEST_FIT, LAST_FIT }; enum IOMODE { REA, WRI, UPD }; typedef struct { - byte R, G, B; + uint8 R, G, B; } DAC; -typedef word CRYPT (void *buf, word siz, word seed); +typedef uint16 CRYPT (void *buf, uint16 siz, uint16 seed); @@ -86,7 +86,7 @@ protected: static void interrupt (* OldTimer) (...); static void interrupt NewTimer (...); public: - ENGINE (word tdiv); + ENGINE (uint16 tdiv); ~ENGINE (void); }; @@ -111,7 +111,7 @@ class EMM public: EMM::EMM (long size = 0); EMM::~EMM (void); - EMS * Alloc (word siz); + EMS * Alloc (uint16 siz); void Release (void); }; @@ -124,12 +124,12 @@ class EMS friend EMM; EMM * Emm; long Ptr; - word Siz; + uint16 Siz; EMS * Nxt; public: EMS (void); void * operator & () const; - word Size (void); + uint16 Size (void); }; @@ -181,11 +181,11 @@ class XFILE { public: IOMODE Mode; - word Error; + uint16 Error; XFILE (void) : Mode(REA), Error(0) { } XFILE (IOMODE mode) : Mode(mode), Error(0) { } - virtual word Read (void * buf, word len) = 0; - virtual word Write (void * buf, word len) = 0; + virtual uint16 Read (void * buf, uint16 len) = 0; + virtual uint16 Write (void * buf, uint16 len) = 0; virtual long Mark (void) = 0; virtual long Size (void) = 0; virtual long Seek (long pos) = 0; @@ -196,9 +196,9 @@ public: template -inline word XRead (XFILE * xf, T * t) +inline uint16 XRead (XFILE * xf, T * t) { - return xf->Read((byte *) t, sizeof(*t)); + return xf->Read((uint8 *) t, sizeof(*t)); }; @@ -209,15 +209,15 @@ class IOHAND : public XFILE { protected: int Handle; - word Seed; + uint16 Seed; CRYPT * Crypt; public: IOHAND (const char * name, IOMODE mode = REA, CRYPT crypt = NULL); IOHAND (IOMODE mode = REA, CRYPT * crpt = NULL); virtual ~IOHAND (void); static bool Exist (const char * name); - word Read (void * buf, word len); - word Write (void * buf, word len); + uint16 Read (void * buf, uint16 len); + uint16 Write (void * buf, uint16 len); long Mark (void); long Size (void); long Seek (long pos); @@ -238,18 +238,18 @@ unsigned FastRand (void); unsigned FastRand (unsigned s); CPU Cpu (void); ALLOC_MODE SetAllocMode (ALLOC_MODE am); -word atow (const char * a); -word xtow (const char * x); -char * wtom (word val, char * str, int radix, int len); -char * dwtom (dword val, char * str, int radix, int len); +uint16 atow (const char * a); +uint16 xtow (const char * x); +char * wtom (uint16 val, char * str, int radix, int len); +char * dwtom (uint32 val, char * str, int radix, int len); char * DateTimeString (void); void StdLog (const char *msg, const char *nam = NULL); -void StdLog (const char *msg, word w); -void StdLog (const char *msg, dword d); +void StdLog (const char *msg, uint16 w); +void StdLog (const char *msg, uint32 d); int TakeEnum (const char ** tab, const char * txt); -word ChkSum (void *m, word n); +uint16 ChkSum (void *m, uint16 n); long Timer (void); -long TimerLimit (word t); +long TimerLimit (uint16 t); bool TimerLimitGone (long t); char * MergeExt (char * buf, const char * nam, const char * ext); char * ForceExt (char * buf, const char * nam, const char * ext); @@ -260,7 +260,7 @@ int DriveRemote (unsigned drv); int DriveCD (unsigned drv); bool IsVga (void); -EC void _fqsort (void *base, word nelem, word width, +EC void _fqsort (void *base, uint16 nelem, uint16 width, int (*fcmp)(const void*, const void*)); diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index ad9f885bb92..623374fe7df 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -86,7 +86,7 @@ void GET_TEXT::Tick (void) -void GET_TEXT::Touch (word mask, int x, int y) +void GET_TEXT::Touch (uint16 mask, int x, int y) { static char ogon[] = "•œ¥£˜ ¡"; static char bezo[] = "ACELNOSXZ"; diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h index 2fbd6f5da66..d08e09a5bb1 100644 --- a/engines/cge/gettext.h +++ b/engines/cge/gettext.h @@ -45,15 +45,15 @@ class GET_TEXT : public TALK { char Buff[GTMAX+2], * Text; - word Size, Len; - word Cntr; + uint16 Size, Len; + uint16 Cntr; SPRITE * OldKeybClient; void (*Click)(void); public: static GET_TEXT * Ptr; GET_TEXT (const char * info, char * text, int size, void (*click)(void) = NULL); ~GET_TEXT (void); - void Touch (word mask, int x, int y); + void Touch (uint16 mask, int x, int y); void Tick (void); }; diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 22110bc832c..87760042734 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -51,19 +51,12 @@ #define ArrayCount(a) (sizeof(a)/sizeof((a)[0])) #define MAX_TIMER 0x1800B0L -typedef unsigned char BYTE; -typedef unsigned int WORD; -typedef unsigned long DWORD; - -typedef unsigned char byte; -typedef unsigned int word; -typedef unsigned long dword; typedef void (_loadds MouseFunType)(void); #define Lo(d) (((int *) &d)[0]) #define Hi(d) (((int *) &d)[1]) -#define LoWord(d) ((word) Lo(d)) -#define HiWord(d) ((word) Hi(d)) +#define LoWord(d) ((uint16) Lo(d)) +#define HiWord(d) ((uint16) Hi(d)) #define K(n) (1024*(n)) #define MASK(n) ((1<= H-MIX_BHIG) { if (*vol > 0x00) *vol -= 0x11; } Update(); diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index e2377ff7814..c770f0a7940 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -49,7 +49,7 @@ public: static bool Appear; MIXER (int x, int y); ~MIXER (void); - void Touch (word mask, int x, int y); + void Touch (uint16 mask, int x, int y); void Tick (void); }; diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index 5fdaf08995d..3c17e3632c6 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -33,11 +33,11 @@ EVENT Evt[EVT_MAX]; - word EvtHead = 0, EvtTail = 0; + uint16 EvtHead = 0, EvtTail = 0; //-------------------------------------------------------------------------- MOUSE_FUN * MOUSE::OldMouseFun = NULL; -word MOUSE::OldMouseMask = 0; +uint16 MOUSE::OldMouseMask = 0; @@ -151,7 +151,7 @@ void MOUSE::ClrEvt (SPRITE * spr) { if (spr) { - word e; + uint16 e; for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) if (Evt[e].Ptr == spr) Evt[e].Msk = 0; } diff --git a/engines/cge/mouse.h b/engines/cge/mouse.h index e30abcaa944..42a6bf6c214 100644 --- a/engines/cge/mouse.h +++ b/engines/cge/mouse.h @@ -45,12 +45,12 @@ extern TALK * Talk; -struct EVENT { word Msk; - word X, Y; +struct EVENT { uint16 Msk; + uint16 X, Y; SPRITE * Ptr; }; extern EVENT Evt[EVT_MAX]; -extern word EvtHead, EvtTail; +extern uint16 EvtHead, EvtTail; typedef void (MOUSE_FUN) (void); @@ -61,7 +61,7 @@ class MOUSE : public SPRITE { static MOUSE_FUN * OldMouseFun; static MOUSE_FUN NewMouseFun; - static word OldMouseMask; + static uint16 OldMouseMask; SPRITE * Hold; int hx, hy; //void SetFun (void); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 06824c5b126..4c15dc6a0c3 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -394,7 +394,7 @@ void FeedSnail (SPRITE * spr, SNLIST snq) { if (spr) if (spr->Active()) { - byte ptr = (snq == TAKE) ? spr->TakePtr : spr->NearPtr; + uint8 ptr = (snq == TAKE) ? spr->TakePtr : spr->NearPtr; if (ptr != NO_PTR) { @@ -425,7 +425,7 @@ void FeedSnail (SPRITE * spr, SNLIST snq) SPRITE * s = (c->Ref < 0) ? spr : Locate(c->Ref); if (s) { - byte * idx = (snq == TAKE) ? &s->TakePtr : &s->NearPtr; + uint8 * idx = (snq == TAKE) ? &s->TakePtr : &s->NearPtr; if (*idx != NO_PTR) { int v; @@ -818,7 +818,7 @@ void SNSetY0 (int cav, int y0) -void SNSetXY (SPRITE * spr, word xy) +void SNSetXY (SPRITE * spr, uint16 xy) { if (spr) { @@ -1130,7 +1130,7 @@ static void SNLight (bool in) static void SNBarrier (int cav, int bar, bool horz) { - ((byte *) (Barriers + ((cav > 0) ? cav : Now)))[horz] = bar; + ((uint8 *) (Barriers + ((cav > 0) ? cav : Now)))[horz] = bar; } @@ -1178,7 +1178,7 @@ void SNAIL::RunCom (void) if (! Busy) { Busy = true; - byte tmphea = Head; + uint8 tmphea = Head; while (Tail != tmphea) { COM * snc = &SNList[Tail]; diff --git a/engines/cge/snail.h b/engines/cge/snail.h index f7e19290e6e..b3268341d88 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -46,14 +46,14 @@ -typedef struct { byte Horz, Vert; } BAR; +typedef struct { uint8 Horz, Vert; } BAR; struct SCB { - byte * Ptr; - word Siz; + uint8 * Ptr; + uint16 Siz; SCB * Nxt; }; @@ -82,9 +82,9 @@ enum SNLIST { NEAR, TAKE }; class SNAIL { struct COM { SNCOM Com; int Ref; int Val; void * Ptr; } * SNList; - byte Head, Tail; + uint8 Head, Tail; bool Turbo, Busy, TextDelay; - word Pause; + uint16 Pause; public: static char * ComTxt[]; bool TalkEnable; diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index a445465dc86..809f73c3a7f 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -58,23 +58,23 @@ struct DRVINFO { DEV_TYPE DDEV; // digi device DEV_TYPE MDEV; // midi device - WORD DBASE; // digi base port - WORD DDMA; // digi dma no - WORD DIRQ; // digi irq no - WORD MBASE; // midi base port + uint16 DBASE; // digi base port + uint16 DDMA; // digi dma no + uint16 DIRQ; // digi irq no + uint16 MBASE; // midi base port union { struct { - WORD DR : 4; - WORD DL : 4; - WORD MR : 4; - WORD ML : 4; + uint16 DR : 4; + uint16 DL : 4; + uint16 MR : 4; + uint16 ML : 4; } VOL4; struct { - BYTE D; // digi volume - BYTE M; // midi volume + uint8 D; // digi volume + uint8 M; // midi volume } VOL2; }; }; @@ -82,9 +82,9 @@ struct DRVINFO // sample info struct SMPINFO { - BYTE * saddr; // address - WORD slen; // length - WORD span; // left/right pan (0-15) + uint8 * saddr; // address + uint16 slen; // length + uint16 span; // left/right pan (0-15) int sflag; // flag }; @@ -95,10 +95,10 @@ struct SMPINFO extern DRVINFO SNDDrvInfo; // midi player flag (1 means we are playing) -extern WORD MIDIPlayFlag; +extern uint16 MIDIPlayFlag; // midi song end flag (1 means we have crossed end mark) -extern WORD MIDIEndFlag; +extern uint16 MIDIEndFlag; // ****************************************************** // * Driver Code * @@ -119,7 +119,7 @@ EC void SNDDigiStart (SMPINFO *PSmpInfo); EC void SNDDigiStop (SMPINFO *PSmpInfo); // Start MIDI File -EC void SNDMIDIStart (BYTE *MIDFile); +EC void SNDMIDIStart (uint8 *MIDFile); // Stop MIDI File EC void SNDMIDIStop (void); diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index b3c13a0211e..03ba231feca 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -91,7 +91,7 @@ void SOUND::Play (DATACK * wav, int pan, int cnt) { Stop(); smpinf.saddr = (char *) &*(wav->EAddr()); - smpinf.slen = (word)wav->Size(); + smpinf.slen = (uint16)wav->Size(); smpinf.span = pan; smpinf.sflag = cnt; SNDDigiStart(&smpinf); @@ -246,7 +246,7 @@ DATACK * FX::operator [] (int ref) //------------------------------------------------------------------------- -static byte * midi = NULL; +static uint8 * midi = NULL; @@ -274,8 +274,8 @@ void LoadMIDI (int ref) INI_FILE mid = fn; if (mid.Error == 0) { - word siz = (word) mid.Size(); - midi = new byte[siz]; + uint16 siz = (uint16) mid.Size(); + midi = new uint8[siz]; if (midi) { mid.Read(midi, siz); @@ -303,8 +303,8 @@ EC void * Patch (int pat) INI_FILE snd = fn; if (! snd.Error) { - word siz = (word) snd.Size(); - p = (byte *) farmalloc(siz); + uint16 siz = (uint16) snd.Size(); + p = (uint8 *) farmalloc(siz); if (p) { snd.Read(p, siz); diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 5555c12b161..18fd06d1ec3 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -54,7 +54,7 @@ static STARTUP StartUp; int STARTUP::Mode = 0; int STARTUP::Core; int STARTUP::SoundOk = 0; - word STARTUP::Summa; + uint16 STARTUP::Summa; @@ -75,7 +75,7 @@ bool STARTUP::get_parms (void) static char *PrmTab[] = { "NEW", "MK0SVG", "QUIET", "SB", "GUS", "MIDI", "P", "D", "I", "M" }; int n = TakeEnum(PrmTab, strtok(_argv[--i], " =:(")); - word p = xtow(strtok(NULL, " h,)")); + uint16 p = xtow(strtok(NULL, " h,)")); switch (n) { case 0 : if (Mode != 2) Mode = 1; break; @@ -99,7 +99,7 @@ bool STARTUP::get_parms (void) #else #ifdef EVA { - union { dosdate_t d; dword n; } today; + union { dosdate_t d; uint32 n; } today; _dos_getdate(&today.d); id.disk += (id.disk < today.n); } @@ -120,7 +120,7 @@ bool STARTUP::get_parms (void) STARTUP::STARTUP (void) { - dword m = farcoreleft() >> 10; + uint32 m = farcoreleft() >> 10; if (m < 0x7FFF) Core = (int) m; else Core = 0x7FFF; if (! IsVga()) quit_now(NOT_VGA_TEXT); diff --git a/engines/cge/startup.h b/engines/cge/startup.h index 27507a7122c..1c946508b59 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -64,7 +64,7 @@ public: static int Mode; static int Core; static int SoundOk; - static word Summa; + static uint16 Summa; STARTUP (void); }; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index d941dba274a..822bc18de34 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -43,9 +43,9 @@ -//byte FONT::Wid[WID_SIZ]; -//word FONT::Pos[POS_SIZ]; -//byte FONT::Map[MAP_SIZ]; +//uint8 FONT::Wid[WID_SIZ]; +//uint16 FONT::Pos[POS_SIZ]; +//uint8 FONT::Map[MAP_SIZ]; @@ -55,9 +55,9 @@ FONT::FONT (const char * name) { - Map = farnew(byte, MAP_SIZ); - Pos = farnew(word, POS_SIZ); - Wid = farnew(byte, WID_SIZ); + Map = farnew(uint8, MAP_SIZ); + Pos = farnew(uint16, POS_SIZ); + Wid = farnew(uint8, WID_SIZ); if (Map == NULL || Pos == NULL || Wid == NULL) DROP("No core", NULL); MergeExt(Path, name, FONT_EXT); Load(); @@ -84,7 +84,7 @@ void FONT::Load (void) f.Read(Wid, WID_SIZ); if (! f.Error) { - word i, p = 0; + uint16 i, p = 0; for (i = 0; i < POS_SIZ; i ++) { Pos[i] = p; @@ -99,9 +99,9 @@ void FONT::Load (void) -word FONT::Width (const char * text) +uint16 FONT::Width (const char * text) { - word w = 0; + uint16 w = 0; if (text) while (* text) w += Wid[*(text ++)]; return w; } @@ -160,7 +160,7 @@ TALK::TALK (void) /* TALK::~TALK (void) { - word i; + uint16 i; for (i = 0; i < ShpCnt; i ++) { if (FP_SEG(ShpList[i]) != _DS) // small model: always false @@ -176,15 +176,15 @@ TALK::~TALK (void) void TALK::Update (const char * tx) { - word vmarg = (Mode) ? TEXT_VM : 0; - word hmarg = (Mode) ? TEXT_HM : 0; - word mw, mh, ln = vmarg; + uint16 vmarg = (Mode) ? TEXT_VM : 0; + uint16 hmarg = (Mode) ? TEXT_HM : 0; + uint16 mw, mh, ln = vmarg; const char * p; - byte * m; + uint8 * m; if (! TS[0]) { - word k = 2 * hmarg; + uint16 k = 2 * hmarg; mh = 2 * vmarg + FONT_HIG; mw = 0; for (p = tx; *p; p ++) @@ -214,8 +214,8 @@ void TALK::Update (const char * tx) for (i = 0; i < cw; i ++) { char * p = m; - word n; - register word b = * (f ++); + uint16 n; + register uint16 b = * (f ++); for (n = 0; n < FONT_HIG; n ++) { if (b & 1) * p = TEXT_FG; @@ -234,15 +234,15 @@ void TALK::Update (const char * tx) -BITMAP * TALK::Box (word w, word h) +BITMAP * TALK::Box (uint16 w, uint16 h) { - byte * b, * p, * q; - word n, r = (Mode == ROUND) ? TEXT_RD : 0; + uint8 * b, * p, * q; + uint16 n, r = (Mode == ROUND) ? TEXT_RD : 0; int i; if (w < 8) w = 8; if (h < 8) h = 8; - b = farnew(byte, n = w * h); + b = farnew(uint8, n = w * h); if (! b) VGA::Exit("No core"); _fmemset(b, TEXT_BG, n); @@ -286,13 +286,13 @@ BITMAP * TALK::Box (word w, word h) void TALK::PutLine (int line, const char * text) // Note: (TS[0].W % 4) have to be 0 { - word w = TS[0]->W, h = TS[0]->H; - byte * v = TS[0]->V, * p; - word dsiz = w >> 2; // data size (1 plane line size) - word lsiz = 2 + dsiz + 2; // word for line header, word for gap - word psiz = h * lsiz; // - last gap, but + plane trailer - word size = 4 * psiz; // whole map size - word rsiz = FONT_HIG * lsiz; // length of whole text row map + uint16 w = TS[0]->W, h = TS[0]->H; + uint8 * v = TS[0]->V, * p; + uint16 dsiz = w >> 2; // data size (1 plane line size) + uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap + uint16 psiz = h * lsiz; // - last gap, but + plane trailer + uint16 size = 4 * psiz; // whole map size + uint16 rsiz = FONT_HIG * lsiz; // length of whole text row map // set desired line pointer v += (TEXT_VM + (FONT_HIG + TEXT_LS) * line) * lsiz; @@ -307,19 +307,19 @@ void TALK::PutLine (int line, const char * text) // paint text line if (text) { - byte * q; + uint8 * q; p = v + 2 + TEXT_HM/4 + (TEXT_HM%4)*psiz; q = v + size; while (* text) { - word cw = Font.Wid[*text], i; - byte * fp = Font.Map + Font.Pos[*text]; + uint16 cw = Font.Wid[*text], i; + uint8 * fp = Font.Map + Font.Pos[*text]; for (i = 0; i < cw; i ++) { - register word b = fp[i]; - word n; + register uint16 b = fp[i]; + uint16 n; for (n = 0; n < FONT_HIG; n ++) { if (b & 1) *p = TEXT_FG; @@ -344,7 +344,7 @@ void TALK::PutLine (int line, const char * text) -INFO_LINE::INFO_LINE (word w) +INFO_LINE::INFO_LINE (uint16 w) : OldTxt(NULL) { TS[0] = new BITMAP(w, FONT_HIG, TEXT_BG); @@ -360,33 +360,33 @@ void INFO_LINE::Update (const char * tx) { if (tx != OldTxt) { - word w = TS[0]->W, h = TS[0]->H; - byte * v = (byte *) TS[0]->V; - word dsiz = w >> 2; // data size (1 plane line size) - word lsiz = 2 + dsiz + 2; // word for line header, word for gap - word psiz = h * lsiz; // - last gape, but + plane trailer - word size = 4 * psiz; // whole map size + uint16 w = TS[0]->W, h = TS[0]->H; + uint8 * v = (uint8 *) TS[0]->V; + uint16 dsiz = w >> 2; // data size (1 plane line size) + uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap + uint16 psiz = h * lsiz; // - last gape, but + plane trailer + uint16 size = 4 * psiz; // whole map size // claer whole rectangle memset(v+2, TEXT_BG, dsiz); // data bytes memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines - * (word *) (v + psiz - 2) = EOI; // plane trailer word + * (uint16 *) (v + psiz - 2) = EOI; // plane trailer uint16 memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes // paint text line if (tx) { - byte * p = v + 2, * q = p + size; + uint8 * p = v + 2, * q = p + size; while (* tx) { - word cw = Font.Wid[*tx], i; - byte * fp = Font.Map + Font.Pos[*tx]; + uint16 cw = Font.Wid[*tx], i; + uint8 * fp = Font.Map + Font.Pos[*tx]; for (i = 0; i < cw; i ++) { - register word b = fp[i]; - word n; + register uint16 b = fp[i]; + uint16 n; for (n = 0; n < FONT_HIG; n ++) { if (b & 1) *p = TEXT_FG; diff --git a/engines/cge/talk.h b/engines/cge/talk.h index c84891f7a06..dff61eaf4b3 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -52,15 +52,15 @@ class FONT char Path[MAXPATH]; void Load (void); public: -// static byte Wid[256]; -// static word Pos[256]; -// static byte Map[256*8]; - byte * Wid; - word * Pos; - byte * Map; +// static uint8 Wid[256]; +// static uint16 Pos[256]; +// static uint8 Map[256*8]; + uint8 * Wid; + uint16 * Pos; + uint8 * Map; FONT (const char * name); ~FONT (void); - word Width (const char * text); + uint16 Width (const char * text); void Save (void); }; @@ -77,7 +77,7 @@ class TALK : public SPRITE protected: TBOX_STYLE Mode; BITMAP * TS[2]; - BITMAP * Box(word w, word h); + BITMAP * Box(uint16 w, uint16 h); public: static FONT Font; TALK (const char * tx, TBOX_STYLE mode = PURE); @@ -98,7 +98,7 @@ class INFO_LINE : public TALK { const char * OldTxt; public: - INFO_LINE (word wid); + INFO_LINE (uint16 wid); void Update (const char * tx); }; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 34b99ac7eb1..bb4757e541c 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -225,7 +225,7 @@ void Say (const char * txt, SPRITE * spr) int x = (east) ? (spr->X+spr->W-2) : (spr->X+2); int y = spr->Y+2; SPRITE * spike = new SPRITE(SP); - word sw = spike->W; + uint16 sw = spike->W; if (east) { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 386ccca1403..e2588b74f50 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -113,7 +113,7 @@ char * NumStr (char * str, int num) static void Video (void) { - static word SP_S; + static uint16 SP_S; asm push bx asm push bp @@ -136,9 +136,9 @@ static void Video (void) -word * SaveScreen (void) +uint16 * SaveScreen (void) { - word cxy, cur, siz, * scr = NULL, * sav; + uint16 cxy, cur, siz, * scr = NULL, * sav; // horizontal size of text mode screen asm mov ah,0x0F // get current video mode @@ -179,7 +179,7 @@ word * SaveScreen (void) _AH = 0x03; Video(); // get cursor cxy = _DX; - sav = farnew(word, siz+3); // +3 extra words for size and cursor + sav = farnew(uint16, siz+3); // +3 extra uint16s for size and cursor if (sav) { sav[0] = siz; @@ -194,9 +194,9 @@ word * SaveScreen (void) -void RestoreScreen (word * &sav) +void RestoreScreen (uint16 * &sav) { - word * scr = NULL; + uint16 * scr = NULL; asm mov ax,0x40 // system data segment asm mov es,ax @@ -228,7 +228,7 @@ void RestoreScreen (word * &sav) -DAC MkDAC (byte r, byte g, byte b) +DAC MkDAC (uint8 r, uint8 g, uint8 b) { static DAC x; x.R = r; @@ -240,7 +240,7 @@ DAC MkDAC (byte r, byte g, byte b) -RGB MkRGB (byte r, byte g, byte b) +RGB MkRGB (uint8 r, uint8 g, uint8 b) { static TRGB x; x.dac.R = r; @@ -268,7 +268,7 @@ SPRITE * Locate (int ref) bool HEART::Enable = false; -word * HEART::XTimer = NULL; +uint16 * HEART::XTimer = NULL; @@ -283,16 +283,16 @@ HEART::HEART (void) extern "C" void TimerProc (void) { static SPRITE * spr; - static byte run = 0; + static uint8 run = 0; - // decrement external timer word + // decrement external timer uint16 if (HEART::XTimer) if (*HEART::XTimer) -- *HEART::XTimer; else HEART::XTimer = NULL; if (! run && HEART::Enable) // check overrun flag { - static word oldSP, oldSS; + static uint16 oldSP, oldSS; ++ run; // disable 2nd call until current lasts asm mov ax,ds @@ -319,7 +319,7 @@ extern "C" void TimerProc (void) void interrupt ENGINE::NewTimer (...) { static SPRITE * spr; - static byte run = 0, cntr1 = TMR_RATE1, cntr2 = TMR_RATE2; + static uint8 run = 0, cntr1 = TMR_RATE1, cntr2 = TMR_RATE2; ___1152_Hz___: @@ -350,14 +350,14 @@ void interrupt ENGINE::NewTimer (...) my_int: //------72Hz-------// - // decrement external timer word + // decrement external timer uint16 if (HEART::XTimer) if (*HEART::XTimer) -- *HEART::XTimer; else HEART::XTimer = NULL; if (! run && HEART::Enable) // check overrun flag { - static word oldSP, oldSS; + static uint16 oldSP, oldSS; ++ run; // disable 2nd call until current lasts asm mov ax,ds @@ -383,7 +383,7 @@ void interrupt ENGINE::NewTimer (...) -void HEART::SetXTimer (word * ptr) +void HEART::SetXTimer (uint16 * ptr) { if (XTimer && ptr != XTimer) *XTimer = 0; XTimer = ptr; @@ -392,7 +392,7 @@ void HEART::SetXTimer (word * ptr) -void HEART::SetXTimer (word * ptr, word time) +void HEART::SetXTimer (uint16 * ptr, uint16 time) { SetXTimer(ptr); *ptr = time; @@ -415,7 +415,7 @@ SPRITE::SPRITE (BMP_PTR * shp) Ext(NULL), Ref(-1), Cave(0) { memset(File, 0, sizeof(File)); - *((word *)&Flags) = 0; + *((uint16 *)&Flags) = 0; SetShapeList(shp); } @@ -486,7 +486,7 @@ BMP_PTR * SPRITE::SetShapeList (BMP_PTR * shp) -void SPRITE::MoveShapes (byte * buf) +void SPRITE::MoveShapes (uint8 * buf) { BMP_PTR * p; for (p = Ext->ShpList; *p; p ++) @@ -779,7 +779,7 @@ void SPRITE::Tick (void) -void SPRITE::MakeXlat (byte * x) +void SPRITE::MakeXlat (uint8 * x) { if (Ext) { @@ -800,11 +800,11 @@ void SPRITE::KillXlat (void) if (Flags.Xlat && Ext) { BMP_PTR * b; - byte * m = (*Ext->ShpList)->M; + uint8 * m = (*Ext->ShpList)->M; switch (MemType(m)) { - case NEAR_MEM : delete[] (byte *) m; break; + case NEAR_MEM : delete[] (uint8 *) m; break; case FAR_MEM : farfree(m); break; } for (b = Ext->ShpList; *b; b ++) (*b)->M = NULL; @@ -883,9 +883,9 @@ void SPRITE::Show (void) -void SPRITE::Show (word pg) +void SPRITE::Show (uint16 pg) { - byte * a = VGA::Page[1]; + uint8 * a = VGA::Page[1]; VGA::Page[1] = VGA::Page[pg & 3]; Shp()->Show(X, Y); VGA::Page[1] = a; @@ -912,13 +912,13 @@ BMP_PTR SPRITE::Ghost (void) register SPREXT * e = Ext; if (e->b1) { - BMP_PTR bmp = new BITMAP(0, 0, (byte *)NULL); + BMP_PTR bmp = new BITMAP(0, 0, (uint8 *)NULL); if (bmp == NULL) VGA::Exit("No core"); bmp->W = e->b1->W; bmp->H = e->b1->H; if ((bmp->B = farnew(HideDesc, bmp->H)) == NULL) VGA::Exit("No Core"); - bmp->V = (byte *) _fmemcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); - bmp->M = (byte *) MK_FP(e->y1, e->x1); + bmp->V = (uint8 *) _fmemcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); + bmp->M = (uint8 *) MK_FP(e->y1, e->x1); return bmp; } return NULL; @@ -1083,9 +1083,9 @@ SPRITE * QUEUE::Locate (int ref) -word VGA::StatAdr = VGAST1_; -word VGA::OldMode = 0; -word * VGA::OldScreen = NULL; +uint16 VGA::StatAdr = VGAST1_; +uint16 VGA::OldMode = 0; +uint16 * VGA::OldScreen = NULL; const char * VGA::Msg = NULL; const char * VGA::Nam = NULL; DAC * VGA::OldColors = NULL; @@ -1093,10 +1093,10 @@ DAC * VGA::NewColors = NULL; bool VGA::SetPal = false; int VGA::Mono = 0; QUEUE VGA::ShowQ = true, VGA::SpareQ = false; -byte * VGA::Page[4] = { (byte *) MK_FP(SCR_SEG, 0x0000), - (byte *) MK_FP(SCR_SEG, 0x4000), - (byte *) MK_FP(SCR_SEG, 0x8000), - (byte *) MK_FP(SCR_SEG, 0xC000) }; +uint8 * VGA::Page[4] = { (uint8 *) MK_FP(SCR_SEG, 0x0000), + (uint8 *) MK_FP(SCR_SEG, 0x4000), + (uint8 *) MK_FP(SCR_SEG, 0x8000), + (uint8 *) MK_FP(SCR_SEG, 0xC000) }; @@ -1453,7 +1453,7 @@ void VGA::UpdateColors (void) void VGA::Update (void) { - byte * p = Page[1]; + uint8 * p = Page[1]; Page[1] = Page[0]; Page[0] = p; @@ -1481,9 +1481,9 @@ void VGA::Update (void) -void VGA::Clear (byte color) +void VGA::Clear (uint8 color) { - byte * a = (byte *) MK_FP(SCR_SEG, 0); + uint8 * a = (uint8 *) MK_FP(SCR_SEG, 0); asm mov dx,VGASEQ_ asm mov ax,0x0F02 // map mask register - enable all planes @@ -1502,9 +1502,9 @@ void VGA::Clear (byte color) -void VGA::CopyPage (word d, word s) +void VGA::CopyPage (uint16 d, uint16 s) { - byte * S = Page[s & 3], * D = Page[d & 3]; + uint8 * S = Page[s & 3], * D = Page[d & 3]; asm mov dx,VGAGRA_ asm mov al,0x05 // R/W mode @@ -1571,11 +1571,11 @@ void VGA::Exit (int tref, const char * name) void BITMAP::XShow (int x, int y) { - byte rmsk = x % 4, + uint8 rmsk = x % 4, mask = 1 << rmsk, * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; - byte * m = (char *) M; - byte * v = V; + uint8 * m = (char *) M; + uint8 * v = V; asm push bx asm push si @@ -1657,9 +1657,9 @@ void BITMAP::XShow (int x, int y) void BITMAP::Show (int x, int y) { - byte mask = 1 << (x & 3), + uint8 mask = 1 << (x & 3), * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); - byte * v = V; + uint8 * v = V; asm push ds // preserve DS @@ -1728,11 +1728,11 @@ void BITMAP::Show (int x, int y) void BITMAP::Hide (int x, int y) { - byte * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; - word d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); + uint8 * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; + uint16 d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); HideDesc * b = B; - word extra = ((x & 3) != 0); - word h = H; + uint16 extra = ((x & 3) != 0); + uint16 h = H; // asm push bx asm push si diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index d7ef11f36d1..b3b411096ed 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -70,7 +70,7 @@ #endif #define NO_SEQ (-1) -#define NO_PTR ((byte)-1) +#define NO_PTR ((uint8)-1) #define SPR_EXT ".SPR" @@ -79,9 +79,9 @@ -typedef struct { word r : 2; word R : 6; - word g : 2; word G : 6; - word b : 2; word B : 6; +typedef struct { uint16 r : 2; uint16 R : 6; + uint16 g : 2; uint16 G : 6; + uint16 b : 2; uint16 B : 6; } RGB; typedef union { @@ -89,9 +89,9 @@ typedef union { RGB rgb; } TRGB; -typedef struct { byte idx, adr; byte clr, set; } VgaRegBlk; +typedef struct { uint8 idx, adr; uint8 clr, set; } VgaRegBlk; -typedef struct { byte Now, Next; signed char Dx, Dy; int Dly; } SEQ; +typedef struct { uint8 Now, Next; signed char Dx, Dy; int Dly; } SEQ; extern SEQ Seq1[]; extern SEQ Seq2[]; @@ -127,9 +127,9 @@ class HEART : public ENGINE friend ENGINE; public: static bool Enable; - static word * XTimer; - static void SetXTimer (word * ptr); - static void SetXTimer (word * ptr, word time); + static uint16 * XTimer; + static void SetXTimer (uint16 * ptr); + static void SetXTimer (uint16 * ptr, uint16 time); HEART (void); }; @@ -166,28 +166,28 @@ protected: public: int Ref; signed char Cave; - struct FLAGS { word Hide : 1; // general visibility switch - word Near : 1; // Near action lock - word Drag : 1; // sprite is moveable - word Hold : 1; // sprite is held with mouse - word ____ : 1; // intrrupt driven animation - word Slav : 1; // slave object - word Syst : 1; // system object - word Kill : 1; // dispose memory after remove - word Xlat : 1; // 2nd way display: xlat table - word Port : 1; // portable - word Kept : 1; // kept in pocket - word East : 1; // talk to east (in opposite to west) - word Shad : 1; // shadow - word Back : 1; // 'send to background' request - word BDel : 1; // delete bitmaps in ~SPRITE - word Tran : 1; // transparent (untouchable) + struct FLAGS { uint16 Hide : 1; // general visibility switch + uint16 Near : 1; // Near action lock + uint16 Drag : 1; // sprite is moveable + uint16 Hold : 1; // sprite is held with mouse + uint16 ____ : 1; // intrrupt driven animation + uint16 Slav : 1; // slave object + uint16 Syst : 1; // system object + uint16 Kill : 1; // dispose memory after remove + uint16 Xlat : 1; // 2nd way display: xlat table + uint16 Port : 1; // portable + uint16 Kept : 1; // kept in pocket + uint16 East : 1; // talk to east (in opposite to west) + uint16 Shad : 1; // shadow + uint16 Back : 1; // 'send to background' request + uint16 BDel : 1; // delete bitmaps in ~SPRITE + uint16 Tran : 1; // transparent (untouchable) } Flags; int X, Y; signed char Z; - word W, H; - word Time; - byte NearPtr, TakePtr; + uint16 W, H; + uint16 Time; + uint8 NearPtr, TakePtr; int SeqPtr; int ShpCnt; char File[MAXFILE]; @@ -199,7 +199,7 @@ public: virtual ~SPRITE (void); BMP_PTR Shp (void); BMP_PTR * SetShapeList (BMP_PTR * shp); - void MoveShapes (byte * buf); + void MoveShapes (uint8 * buf); SPRITE * Expand (void); SPRITE * Contract (void); SPRITE * BackShow (bool fast = false); @@ -210,13 +210,13 @@ public: void Show (void); void Hide (void); BMP_PTR Ghost (void); - void Show (word pg); - void MakeXlat (byte * x); + void Show (uint16 pg); + void MakeXlat (uint8 * x); void KillXlat (void); void Step (int nr = -1); SEQ * SetSeq (SEQ * seq); SNAIL::COM * SnList(SNLIST type); - virtual void Touch (word mask, int x, int y); + virtual void Touch (uint16 mask, int x, int y); virtual void Tick (void); }; @@ -250,9 +250,9 @@ public: class VGA { - static word OldMode; - static word * OldScreen; - static word StatAdr; + static uint16 OldMode; + static uint16 * OldScreen; + static uint16 StatAdr; static bool SetPal; static DAC * OldColors, * NewColors; static int SetMode (int mode); @@ -263,19 +263,19 @@ class VGA static void SetStatAdr (void); static void WaitVR (bool on = true); public: - dword FrmCnt; + uint32 FrmCnt; static QUEUE ShowQ, SpareQ; static int Mono; - static byte * Page[4]; + static uint8 * Page[4]; VGA (int mode = M13H); ~VGA (void); void Setup (VgaRegBlk * vrb); static void GetColors (DAC * tab); static void SetColors (DAC * tab, int lum); - static void Clear (byte color = 0); + static void Clear (uint8 color = 0); static void Exit (const char * txt = NULL, const char * name = NULL); static void Exit (int tref, const char * name = NULL); - static void CopyPage (word d, word s = 3); + static void CopyPage (uint16 d, uint16 s = 3); static void Sunrise (DAC * tab); static void Sunset (void); void Show (void); @@ -284,24 +284,24 @@ public: -DAC MkDAC (byte r, byte g, byte b); -RGB MkRGB (byte r, byte g, byte b); +DAC MkDAC (uint8 r, uint8 g, uint8 b); +RGB MkRGB (uint8 r, uint8 g, uint8 b); template -byte Closest (CBLK * pal, CBLK x) +uint8 Closest (CBLK * pal, CBLK x) { - #define f(col,lum) ((((word)(col))<<8)/lum) - word i, dif = 0xFFFF, found; - word L = x.R + x.G + x.B; if (! L) ++ L; - word R = f(x.R, L), G = f(x.G, L), B = f(x.B, L); + #define f(col,lum) ((((uint16)(col))<<8)/lum) + uint16 i, dif = 0xFFFF, found; + uint16 L = x.R + x.G + x.B; if (! L) ++ L; + uint16 R = f(x.R, L), G = f(x.G, L), B = f(x.B, L); for (i = 0; i < 256; i ++) { - word l = pal[i].R + pal[i].G + pal[i].B; if (! l) ++ l; + uint16 l = pal[i].R + pal[i].G + pal[i].B; if (! l) ++ l; int r = f(pal[i].R, l), g = f(pal[i].G, l), b = f(pal[i].B, l); - word D = ((r > R) ? (r - R) : (R - r)) + + uint16 D = ((r > R) ? (r - R) : (R - r)) + ((g > G) ? (g - G) : (G - g)) + ((b > B) ? (b - B) : (B - b)) + ((l > L) ? (l - L) : (L - l)) * 10 ; @@ -325,8 +325,8 @@ byte Closest (CBLK * pal, CBLK x) char * NumStr (char * str, int num); void Video (void); - word * SaveScreen (void); - void RestoreScreen (word * &sav); + uint16 * SaveScreen (void); + void RestoreScreen (uint16 * &sav); SPRITE * SpriteAt (int x, int y); SPRITE * Locate (int ref); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index f7314e18ea0..1459314ba00 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -45,10 +45,10 @@ -MENU_BAR::MENU_BAR (word w) +MENU_BAR::MENU_BAR (uint16 w) { int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h; - byte * p = farnew(byte, i), * p1, * p2; + uint8 * p = farnew(uint8, i), * p1, * p2; _fmemset(p+w, TRANS, i-2*w); _fmemset(p, MB_LT, w); @@ -88,7 +88,7 @@ char * VMGather (CHOICE * list) len += strlen(cp->Text); ++ h; } - vmgt = new byte[len+h]; + vmgt = new uint8[len+h]; if (vmgt) { *vmgt = '\0'; @@ -141,7 +141,7 @@ VMENU::~VMENU (void) -void VMENU::Touch (word mask, int x, int y) +void VMENU::Touch (uint16 mask, int x, int y) { #define h (FONT_HIG+TEXT_LS) int n = 0; diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index 23c354b504f..d2b70145dfe 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -45,7 +45,7 @@ typedef struct { char * Text; void (* Proc)(void); } CHOICE; class MENU_BAR : public TALK { public: - MENU_BAR (word w); + MENU_BAR (uint16 w); }; @@ -56,7 +56,7 @@ public: class VMENU : public TALK { - word Items; + uint16 Items; CHOICE * Menu; public: static VMENU * Addr; @@ -64,7 +64,7 @@ public: MENU_BAR * Bar; VMENU (CHOICE * list, int x, int y); ~VMENU (void); - void Touch (word mask, int x, int y); + void Touch (uint16 mask, int x, int y); }; diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 503c6cab917..b0cf1c068c8 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -101,6 +101,6 @@ void VFILE::ReadBuff (void) BufMark = Dat.File.Mark(); long n = EndMark - BufMark; if (n > IOBUF_SIZE) n = IOBUF_SIZE; - Lim = Dat.File.Read(Buff, (word) n); + Lim = Dat.File.Read(Buff, (uint16) n); Ptr = 0; } diff --git a/engines/cge/vol.h b/engines/cge/vol.h index 1357c248143..99284fddd57 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -55,9 +55,9 @@ class DAT friend VFILE; static VOLBASE File; public: - static bool Append (byte * buf, word len); + static bool Append (uint8 * buf, uint16 len); static bool Write (CFILE& f); - static bool Read (long org, word len, byte * buf); + static bool Read (long org, uint16 len, uint8 * buf); }; diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 1998672bedf..0fc2ab4d0d1 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -39,17 +39,17 @@ typedef char FOURCC[4]; // Four-character code -typedef dword CKSIZE; // 32-bit unsigned size +typedef uint32 CKSIZE; // 32-bit unsigned size class CKID // Chunk type identifier { - union { FOURCC Tx; dword Id; }; + union { FOURCC Tx; uint32 Id; }; protected: static XFILE * ckFile; public: CKID (FOURCC t) { memcpy(Tx, t, sizeof(Tx)); } - CKID (dword d) { Id = d; } + CKID (uint32 d) { Id = d; } CKID (XFILE * xf) { (ckFile = xf)->Read(Tx, sizeof(Tx)); } bool operator !=(CKID& X) { return Id != X.Id; } bool operator ==(CKID& X) { return Id == X.Id; } @@ -78,27 +78,27 @@ class FMTCK : public CKHEA { struct WAV { - word wFormatTag; // Format category - word wChannels; // Number of channels - dword dwSamplesPerSec; // Sampling rate - dword dwAvgBytesPerSec; // For buffer estimation - word wBlockAlign; // Data block size + uint16 wFormatTag; // Format category + uint16 wChannels; // Number of channels + uint32 dwSamplesPerSec; // Sampling rate + uint32 dwAvgBytesPerSec; // For buffer estimation + uint16 wBlockAlign; // Data block size } Wav; union { struct PCM { - word wBitsPerSample; // Sample size + uint16 wBitsPerSample; // Sample size } Pcm; }; public: FMTCK (CKHEA& hea); - inline word Channels (void) { return Wav.wChannels; } - inline dword SmplRate (void) { return Wav.dwSamplesPerSec; } - inline dword ByteRate (void) { return Wav.dwAvgBytesPerSec; } - inline word BlckSize (void) { return Wav.wBlockAlign; } - inline word SmplSize (void) { return Pcm.wBitsPerSample; } + inline uint16 Channels (void) { return Wav.wChannels; } + inline uint32 SmplRate (void) { return Wav.dwSamplesPerSec; } + inline uint32 ByteRate (void) { return Wav.dwAvgBytesPerSec; } + inline uint16 BlckSize (void) { return Wav.wBlockAlign; } + inline uint16 SmplSize (void) { return Pcm.wBitsPerSample; } }; @@ -110,7 +110,7 @@ class DATACK : public CKHEA bool e; union { - byte * Buf; + uint8 * Buf; EMS * EBuf; }; public: @@ -118,7 +118,7 @@ public: DATACK (CKHEA& hea, EMM * emm); DATACK (int first, int last); ~DATACK (void); - inline byte * Addr (void) { return Buf; } + inline uint8 * Addr (void) { return Buf; } inline EMS * EAddr (void) { return EBuf; } }; From 29065d302a9bf8bcaa18c4225e27b218bde67242 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 10 Jun 2011 22:57:09 +0200 Subject: [PATCH 007/276] CGE: Add namespaces --- engines/cge/bitmap.cpp | 6 ++---- engines/cge/bitmap.h | 6 ++++-- engines/cge/bitmaps.cpp | 4 ++++ engines/cge/bitmaps.h | 4 +++- engines/cge/boot.h | 5 ++++- engines/cge/cfile.cpp | 10 +++++++--- engines/cge/cfile.h | 2 ++ engines/cge/cge_main.cpp | 4 ++++ engines/cge/cge_main.h | 3 ++- engines/cge/game.cpp | 2 ++ engines/cge/game.h | 5 +++-- engines/cge/general.h | 5 +++++ engines/cge/gettext.cpp | 6 +++--- engines/cge/gettext.h | 8 ++------ engines/cge/ident.h | 2 ++ engines/cge/jbw.h | 3 +++ engines/cge/keybd.cpp | 3 +++ engines/cge/keybd.h | 2 ++ engines/cge/mixer.cpp | 5 +++-- engines/cge/mixer.h | 4 +++- engines/cge/mouse.cpp | 7 ++----- engines/cge/mouse.h | 5 +++-- engines/cge/snail.cpp | 5 ++++- engines/cge/snail.h | 12 ++++-------- engines/cge/snddrv.h | 4 ++++ engines/cge/sound.cpp | 8 +++++++- engines/cge/sound.h | 2 ++ engines/cge/startup.cpp | 7 +++---- engines/cge/startup.h | 3 +++ engines/cge/talk.cpp | 4 ++++ engines/cge/talk.h | 4 ++-- engines/cge/text.cpp | 8 ++------ engines/cge/text.h | 5 ++--- engines/cge/vga13h.cpp | 13 +++---------- engines/cge/vga13h.h | 3 ++- engines/cge/vmenu.cpp | 6 +++--- engines/cge/vmenu.h | 14 +++----------- engines/cge/vol.cpp | 7 ++++++- engines/cge/vol.h | 4 +++- engines/cge/wav.h | 4 ++++ 40 files changed, 129 insertions(+), 85 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 9845c4a2dad..e9a9bbe220e 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -36,12 +36,12 @@ #include "cge/drop.h" #endif - #include #include #include #include +namespace CGE { //-------------------------------------------------------------------------- @@ -455,6 +455,4 @@ bool BITMAP::VBMLoad (XFILE * f) } - - - +} // End of namespace CGE diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 2ce849cc2b5..90f94b1b325 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -30,6 +30,8 @@ #include "cge/general.h" +namespace CGE { + #define EOI 0x0000 #define SKP 0x4000 #define REP 0x8000 @@ -82,6 +84,6 @@ public: typedef BITMAP * BMP_PTR; +} // End of namespace CGE - -#endif \ No newline at end of file +#endif diff --git a/engines/cge/bitmaps.cpp b/engines/cge/bitmaps.cpp index 0cdae18cab0..1eba1b55ea5 100644 --- a/engines/cge/bitmaps.cpp +++ b/engines/cge/bitmaps.cpp @@ -222,6 +222,8 @@ static uint8 MEDesign[][9] = { { R R R R R R R R R }, // 0 #undef G */ +namespace CGE { + #ifdef DEBUG BMP_PTR MB[] = { new BITMAP("BRICK"), NULL }; BMP_PTR HL[] = { new BITMAP("HLINE"), NULL }; @@ -239,3 +241,5 @@ static uint8 MEDesign[][9] = { { R R R R R R R R R }, // 0 new BITMAP("LITE2"), new BITMAP("LITE3"), NULL }; + +} // End of namespace CGE diff --git a/engines/cge/bitmaps.h b/engines/cge/bitmaps.h index 65f586a3555..3ca2bababdc 100644 --- a/engines/cge/bitmaps.h +++ b/engines/cge/bitmaps.h @@ -30,6 +30,8 @@ #include "cge/vga13h.h" +namespace CGE { + #ifdef DEBUG extern BITMAP * MB[]; extern BITMAP * HL[]; @@ -40,6 +42,6 @@ extern BITMAP * PR[]; extern BITMAP * SP[]; extern BITMAP * LI[]; +} // End of namespace CGE #endif - \ No newline at end of file diff --git a/engines/cge/boot.h b/engines/cge/boot.h index 3a22e896614..d09afb6d1bc 100644 --- a/engines/cge/boot.h +++ b/engines/cge/boot.h @@ -30,6 +30,8 @@ #include "cge/jbw.h" +namespace CGE { + #define BOOTSECT_SIZ 512 #define BOOTHEAD_SIZ 62 #define BOOTCODE_SIZ BOOTSECT_SIZ-BOOTHEAD_SIZ @@ -72,5 +74,6 @@ EC Boot * ReadBoot (int drive); EC uint8 CheckBoot (Boot * boot); EC bool WriteBoot (int drive, Boot * boot); +// End of namespace CGE -#endif \ No newline at end of file +#endif diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index efc922b2323..499a7033ac2 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -25,7 +25,7 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include +#include "cge/cfile.h" #include #include #include @@ -36,11 +36,13 @@ #else #include #include - #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } #endif +namespace CGE { - +#ifndef DROP_H + #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } +#endif IOBUF::IOBUF (IOMODE mode, CRYPT * crpt) : IOHAND(mode, crpt), @@ -357,3 +359,5 @@ void CFILE::Append (CFILE& f) } } } + +} // End of namespace CGE diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index bbb45a9e85f..b08dc833b0c 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -31,6 +31,7 @@ #include "cge/general.h" #include +namespace CGE { #define LINE_MAX 512 @@ -79,5 +80,6 @@ public: void Append (CFILE& f); }; +} // End of namespace CGE #endif diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index d8829247a4b..36053d926c6 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -55,6 +55,8 @@ #include #include +namespace CGE { + #define STACK_SIZ (K(2)) #define SVGCHKSUM (1956+Now+OldLev+Game+Music+DemoText) @@ -2257,3 +2259,5 @@ void cge_main (void) else Vga.Sunset(); VGA::Exit(EXIT_OK_TEXT+FINIS); } + +} // End of namespace CGE diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index c1155eb6506..8605d17c55b 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -204,5 +204,6 @@ extern WALK * Hero; void ContractSprite (SPRITE * spr); void cge_main(void); -} // End of CGE +} // End of namespace CGE + #endif diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index cc80a8f7fab..d9bcf916bbb 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -31,6 +31,7 @@ #include +namespace CGE { @@ -116,3 +117,4 @@ void FLY::Tick (void) //-------------------------------------------------------------------------- +} // End of namespace CGE diff --git a/engines/cge/game.h b/engines/cge/game.h index cda24512e38..1f45667b6bc 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -31,6 +31,7 @@ #include "cge/vga13h.h" #include "cge/bitmaps.h" +namespace CGE { #define PAN_HIG 40 @@ -62,6 +63,6 @@ public: +} // End of namespace CGE - -#endif \ No newline at end of file +#endif diff --git a/engines/cge/general.h b/engines/cge/general.h index 75f754d0a37..ac45f4b4add 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -28,9 +28,13 @@ #ifndef __GENERAL__ #define __GENERAL__ +#include "common/system.h" + #include "cge\jbw.h" #include +namespace CGE { + #define SEED 0xA5 #define SCR_WID_ 320 @@ -264,5 +268,6 @@ EC void _fqsort (void *base, uint16 nelem, uint16 width, int (*fcmp)(const void*, const void*)); +} // End of namespace CGE #endif diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 623374fe7df..f8de84f5fc6 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -30,9 +30,7 @@ #include "cge/mouse.h" #include - - - +namespace CGE { GET_TEXT * GET_TEXT::Ptr = NULL; @@ -135,3 +133,5 @@ void GET_TEXT::Touch (uint16 mask, int x, int y) } else SPRITE::Touch(mask, x, y); } + +} // End of namespace CGE diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h index d08e09a5bb1..02dbabe9c6b 100644 --- a/engines/cge/gettext.h +++ b/engines/cge/gettext.h @@ -31,17 +31,13 @@ #include "cge/general.h" #include "cge/talk.h" +namespace CGE { #define GTMAX 24 #define GTBLINK 6 #define GTTIME 6 - - - - - class GET_TEXT : public TALK { char Buff[GTMAX+2], * Text; @@ -57,6 +53,6 @@ public: void Tick (void); }; - +} // End of namespace CGE #endif diff --git a/engines/cge/ident.h b/engines/cge/ident.h index fa3011b49c1..96e04f4e20d 100644 --- a/engines/cge/ident.h +++ b/engines/cge/ident.h @@ -28,6 +28,7 @@ #ifndef __IDENT__ #define __IDENT__ +namespace CGE { struct IDENT { @@ -37,5 +38,6 @@ struct IDENT unsigned char cork; }; +} // End of namespace CGE #endif diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 87760042734..236a2e6ddb2 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -28,6 +28,8 @@ #ifndef __JBW__ #define __JBW__ +namespace CGE { + #define BEL 7 #define BS 8 #define HT 9 @@ -162,5 +164,6 @@ struct KeyStatStruct extern uint16 _stklen; extern uint16 _heaplen; +} // End of namespace CGE #endif diff --git a/engines/cge/keybd.cpp b/engines/cge/keybd.cpp index c644473c534..dbbc06bcb22 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/keybd.cpp @@ -29,6 +29,7 @@ #include "cge/mouse.h" #include +namespace CGE { SPRITE * KEYBOARD::Client = NULL; uint8 KEYBOARD::Key[0x60] = { 0 }; @@ -139,3 +140,5 @@ void interrupt KEYBOARD::NewKeyboard (...) asm mov al,20h // send End-Of-Interrupt asm out 20h,al // to the 8259 IC } + +} // End of namespace CGE diff --git a/engines/cge/keybd.h b/engines/cge/keybd.h index dfbd4398051..b38481f7d37 100644 --- a/engines/cge/keybd.h +++ b/engines/cge/keybd.h @@ -31,6 +31,7 @@ #include "cge/jbw.h" #include "cge/vga13h.h" +namespace CGE { #define KEYBD_INT 9 #define LSHIFT 42 @@ -54,5 +55,6 @@ public: ~KEYBOARD (void); }; +} // End of namespace CGE #endif diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 25d6eed32af..2ebede93bee 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -33,8 +33,7 @@ #include #include -//-------------------------------------------------------------------------- - +namespace CGE { extern MOUSE Mouse; @@ -154,3 +153,5 @@ void MIXER::Update (void) Led[1]->Step(SNDDrvInfo.VOL4.DL); SNPOST_(SNEXEC, -1, 0, SNDSetVolume); } + +} // End of namespace CGE diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index c770f0a7940..30beaf2f5d2 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -30,6 +30,8 @@ #include "cge/vga13h.h" +namespace CGE { + #define MIX_MAX 16 // count of Leds #define MIX_Z 64 // mixer Z position #define MIX_DELAY 12 // 6/s @@ -53,6 +55,6 @@ public: void Tick (void); }; - +} // End of namespace CGE #endif diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index 3c17e3632c6..94f7cbf0ac1 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -29,7 +29,7 @@ #include "cge/text.h" #include - +namespace CGE { EVENT Evt[EVT_MAX]; @@ -228,7 +228,4 @@ void MOUSE::Tick (void) Hold->Goto(X-hx, Y-hy); } - - -//-------------------------------------------------------------------------- - +} // End of namespace CGE diff --git a/engines/cge/mouse.h b/engines/cge/mouse.h index 42a6bf6c214..20015b058f5 100644 --- a/engines/cge/mouse.h +++ b/engines/cge/mouse.h @@ -31,8 +31,9 @@ #include "cge/game.h" #include "cge/talk.h" -#define EVT_MAX 256 +namespace CGE { +#define EVT_MAX 256 #define ROLL 0x01 #define L_DN 0x02 #define L_UP 0x04 @@ -80,6 +81,6 @@ public: }; - +} // End of namespace CGE #endif diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 4c15dc6a0c3..67a16a8563b 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -38,9 +38,10 @@ #include #include #include - #include "cge/keybd.h" +namespace CGE { + int MaxCave = 0; SCB Scb = { NULL, 0, NULL }; @@ -1305,3 +1306,5 @@ bool SNAIL::Idle (void) { return (Head == Tail); } + +} // End of namespace CGE diff --git a/engines/cge/snail.h b/engines/cge/snail.h index b3268341d88..bf47fa13d43 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -30,6 +30,8 @@ #include "cge/jbw.h" +namespace CGE { + #define POCKET_X 174 #define POCKET_Y 176 #define POCKET_DX 18 @@ -97,18 +99,10 @@ public: }; - - - void SelectPocket (int n); void PocFul (void); - - - - - extern SCB Scb; extern bool Flag[4]; extern bool Game; @@ -122,4 +116,6 @@ extern int PocPtr; extern BAR Barriers[]; extern struct HXY { int X; int Y; } HeroXY[]; +} // End of namespace CGE + #endif diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 809f73c3a7f..662d4807780 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -37,6 +37,8 @@ #ifndef __SNDDRV__ #define __SNDDRV__ +namespace CGE { + // ****************************************************** // * Constants * // ****************************************************** @@ -128,4 +130,6 @@ EC void SNDMIDIStop (void); // WARNING: Uses ALL registers! EC void SNDMIDIPlay (void); +// End of namespace CGE + #endif diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 03ba231feca..81dd4576039 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -34,7 +34,6 @@ #else #include #include - #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } #endif #include "cge/text.h" @@ -43,6 +42,12 @@ #include +namespace CGE { + +#ifndef DROP_H + #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } +#endif + bool Music = true; FX Fx = 16; // must precede SOUND!! SOUND Sound; @@ -318,3 +323,4 @@ EC void * Patch (int pat) return p; } +} // End of namespace CGE diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 993bd05fca0..79c9bf563d8 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -31,6 +31,7 @@ #include "cge/wav.h" #include "cge/snddrv.h" +namespace CGE { #define BAD_SND_TEXT 97 #define BAD_MIDI_TEXT 98 @@ -83,6 +84,7 @@ extern FX Fx; void LoadMIDI (int ref); void KillMIDI (void); +} // End of namespace CGE #endif diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 18fd06d1ec3..0e45e65b73b 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -41,6 +41,8 @@ #include #endif +namespace CGE { + extern char Copr[]; #define id (*(IDENT*)Copr) @@ -189,7 +191,4 @@ const char *UsrPath (const char *nam) return buf; } - - - - +} // End of namespace CGE diff --git a/engines/cge/startup.h b/engines/cge/startup.h index 1c946508b59..2f1b5faa0bd 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -31,6 +31,8 @@ #include "cge/general.h" +namespace CGE { + #define GAME_ID 45 #define CDINI_FNAME 46 @@ -75,5 +77,6 @@ extern EMM MiniEmm; const char *UsrPath (const char *nam); +} // End of namespace CGE #endif diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 822bc18de34..9c15ac1b651 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -34,6 +34,8 @@ #include #include +namespace CGE { + #define WID_SIZ 256 #define POS_SIZ 256 #define MAP_SIZ (256*8) @@ -401,3 +403,5 @@ void INFO_LINE::Update (const char * tx) OldTxt = tx; } } + +} // End of namespace CGE diff --git a/engines/cge/talk.h b/engines/cge/talk.h index dff61eaf4b3..fb1d450f2d9 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -31,7 +31,7 @@ #include "cge/vga13h.h" #include - +namespace CGE { #define TEXT_FG DARK // foreground color #define TEXT_BG GRAY // background color @@ -103,6 +103,6 @@ public: }; - +} // End of namespace CGE #endif \ No newline at end of file diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index bb4757e541c..df8ca4cfe5a 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -37,7 +37,7 @@ #include #include - +namespace CGE { TEXT Text = ProgName(); TALK * Talk = NULL; @@ -311,8 +311,4 @@ void KillText (void) } } - - - - -//------------------------------------------------------------------------- +} // End of namespace CGE diff --git a/engines/cge/text.h b/engines/cge/text.h index c6e6a1491ee..7394e04b3f1 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -32,8 +32,7 @@ #include "cge/jbw.h" #include - - +namespace CGE { #ifndef SYSTXT_MAX #define SYSTXT_MAX 1000 @@ -82,6 +81,6 @@ void SayTime (SPRITE * spr); void Inf (const char * txt); void KillText (void); - +} // End of namespace CGE #endif \ No newline at end of file diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index e2588b74f50..415bff72252 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -41,6 +41,8 @@ #include #include +namespace CGE { + #ifdef DEBUG #define REPORT #endif @@ -1790,13 +1792,4 @@ void BITMAP::Hide (int x, int y) // asm pop bx } - - - - - - -//-------------------------------------------------------------------------- - - - +} // End of namespace CGE diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index b3b411096ed..d8e22735576 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -34,6 +34,7 @@ #include "cge/bitmap.h" #include "cge/snail.h" +namespace CGE { #define TMR_RATE1 16 #define TMR_RATE2 4 @@ -332,6 +333,6 @@ uint8 Closest (CBLK * pal, CBLK x) extern bool SpeedTest; +} // End if namespace CGE #endif - \ No newline at end of file diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 1459314ba00..81788685784 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -30,8 +30,9 @@ #include #include -//-------------------------------------------------------------------------- +namespace CGE { +//-------------------------------------------------------------------------- #define RELIEF 1 #if RELIEF @@ -172,5 +173,4 @@ void VMENU::Touch (uint16 mask, int x, int y) #undef h } - - +} // End of namespace CGE diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index d2b70145dfe..cdbabf9966f 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -30,18 +30,15 @@ #include "cge/talk.h" +namespace CGE { + #define MB_VM 1 #define MB_HM 3 - typedef struct { char * Text; void (* Proc)(void); } CHOICE; - - - - class MENU_BAR : public TALK { public: @@ -49,11 +46,6 @@ public: }; - - - - - class VMENU : public TALK { uint16 Items; @@ -67,6 +59,6 @@ public: void Touch (uint16 mask, int x, int y); }; - +} // End of namespace CGE #endif diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index b0cf1c068c8..8a94dbe8af2 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -35,10 +35,13 @@ #include "cge/drop.h" #else #include - #define DROP(m,n) { printf("%s [%s]\n", (m), (n)); _exit(1); } #endif +namespace CGE { +#ifndef DROP_H + #define DROP(m,n) { printf("%s [%s]\n", (m), (n)); _exit(1); } +#endif #ifdef VOL_UPD @@ -104,3 +107,5 @@ void VFILE::ReadBuff (void) Lim = Dat.File.Read(Buff, (uint16) n); Ptr = 0; } + +} // End of namespace CGE diff --git a/engines/cge/vol.h b/engines/cge/vol.h index 99284fddd57..a98dbbeee28 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -33,6 +33,8 @@ #include "cge/btfile.h" #include "cge/cfile.h" +namespace CGE { + #define CAT_NAME "VOL.CAT" #define DAT_NAME "VOL.DAT" @@ -86,6 +88,6 @@ public: }; - +} // End of namespace CGE #endif diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 0fc2ab4d0d1..0d1408ccf68 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -31,6 +31,8 @@ #include "cge/general.h" #include +namespace CGE { + #define WAVE_FORMAT_PCM 0x0001 #define IBM_FORMAT_MULAW 0x0101 #define IBM_FORMAT_ALAW 0x0102 @@ -133,4 +135,6 @@ extern CKID DATA; DATACK * LoadWave (XFILE * file, EMM * emm = NULL); +// End of namespace CGE + #endif From 15d98b2a5479967590c3eba82e349f642c4ca7cf Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 11 Jun 2011 09:33:17 +0200 Subject: [PATCH 008/276] CGE: Add a couple of missing files --- engines/cge/bitmap.cpp | 7 +- engines/cge/btfile.cpp | 208 ++++++++++++++++++++++++++ engines/cge/btfile.h | 99 +++++++++++++ engines/cge/cfile.cpp | 3 +- engines/cge/config.cpp | 322 +++++++++++++++++++++++++++++++++++++++++ engines/cge/config.h | 37 +++++ engines/cge/module.mk | 2 + engines/cge/talk.h | 2 +- engines/cge/vga13h.h | 2 +- engines/cge/vol.cpp | 3 +- engines/cge/vol.h | 2 +- 11 files changed, 679 insertions(+), 8 deletions(-) create mode 100644 engines/cge/btfile.cpp create mode 100644 engines/cge/btfile.h create mode 100644 engines/cge/config.cpp create mode 100644 engines/cge/config.h diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index e9a9bbe220e..5c416500d6b 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -36,10 +36,11 @@ #include "cge/drop.h" #endif -#include +//#include +//#include +//#include #include -#include -#include +#include "common/system.h" namespace CGE { diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp new file mode 100644 index 00000000000..4068f323a0a --- /dev/null +++ b/engines/cge/btfile.cpp @@ -0,0 +1,208 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/btfile.h" +//#include +#include "common/system.h" +#include + + + +#ifdef DROP_H + #include "cge/drop.h" +#else + #include + #include +#endif + +namespace CGE { + +#ifndef DROP_H + #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } +#endif + +#ifndef BT_SIZE + #define BT_SIZE K(1) +#endif + +#ifndef BT_KEYLEN + #define BT_KEYLEN 13 +#endif + + + + + +BTFILE::BTFILE (const char * name, IOMODE mode, CRYPT * crpt) +: IOHAND(name, mode, crpt) +{ + int i; + for (i = 0; i < BT_LEVELS; i ++) + { + Buff[i].Page = new BT_PAGE; + Buff[i].PgNo = BT_NONE; + Buff[i].Indx = -1; + Buff[i].Updt = FALSE; + if (Buff[i].Page == NULL) DROP("No core", NULL); + } +} + + + + + + + + + +BTFILE::~BTFILE (void) +{ + int i; + for (i = 0; i < BT_LEVELS; i ++) + { + PutPage(i); + delete Buff[i].Page; + } +} + + + + + + +void BTFILE::PutPage (int lev, bool hard) +{ + if (hard || Buff[lev].Updt) + { + Seek(Buff[lev].PgNo * sizeof(BT_PAGE)); + Write((uint8 *) Buff[lev].Page, sizeof(BT_PAGE)); + Buff[lev].Updt = FALSE; + } +} + + + + + + +BT_PAGE * BTFILE::GetPage (int lev, uint16 pgn) +{ + if (Buff[lev].PgNo != pgn) + { + uint32 pos = pgn * sizeof(BT_PAGE); + PutPage(lev); + Buff[lev].PgNo = pgn; + if (Size() > pos) + { + Seek((uint32) pgn * sizeof(BT_PAGE)); + Read((uint8 *) Buff[lev].Page, sizeof(BT_PAGE)); + Buff[lev].Updt = FALSE; + } + else + { + Buff[lev].Page->Hea.Count = 0; + Buff[lev].Page->Hea.Down = BT_NONE; + _fmemset(Buff[lev].Page->Data, '\0', sizeof(Buff[lev].Page->Data)); + Buff[lev].Updt = TRUE; + } + Buff[lev].Indx = -1; + } + return Buff[lev].Page; +} + + + + + +BT_KEYPACK * BTFILE::Find (const uint8 * key) +{ + int lev = 0; + uint16 nxt = BT_ROOT; + while (! Error) + { + BT_PAGE * pg = GetPage(lev, nxt); + // search + if (pg->Hea.Down != BT_NONE) + { + int i; + for (i = 0; i < pg->Hea.Count; i ++) + if (_fmemicmp(key, pg->Inn[i].Key, BT_KEYLEN) < 0) + break; + nxt = (i) ? pg->Inn[i-1].Down : pg->Hea.Down; + Buff[lev].Indx = i-1; + ++ lev; + } + else + { + int i; + for (i = 0; i < pg->Hea.Count-1; i ++) + if (_fstricmp(key, pg->Lea[i].Key) <= 0) + break; + Buff[lev].Indx = i; + return &pg->Lea[i]; + } + } + return NULL; +} + + + + +int keycomp (const void * k1, const void * k2) +{ + return _fmemicmp(k1, k2, BT_KEYLEN); +} + + + +void BTFILE::Make(BT_KEYPACK * keypack, uint16 count) +{ + #if BT_LEVELS != 2 + #error This tiny BTREE implementation works with exactly 2 levels! + #endif + _fqsort(keypack, count, sizeof(*keypack), keycomp); + uint16 n = 0; + BT_PAGE * Root = GetPage(0, n ++), + * Leaf = GetPage(1, n); + Root->Hea.Down = n; + PutPage(0, TRUE); + while (count --) + { + if (Leaf->Hea.Count >= ArrayCount(Leaf->Lea)) + { + PutPage(1, TRUE); // save filled page + Leaf = GetPage(1, ++n); // take empty page + _fmemcpy(Root->Inn[Root->Hea.Count].Key, keypack->Key, BT_KEYLEN); + Root->Inn[Root->Hea.Count ++].Down = n; + Buff[0].Updt = TRUE; + } + Leaf->Lea[Leaf->Hea.Count ++] = * (keypack ++); + Buff[1].Updt = TRUE; + } +} + +} // End of namespace CGE diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h new file mode 100644 index 00000000000..0599bee72a6 --- /dev/null +++ b/engines/cge/btfile.h @@ -0,0 +1,99 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef __BTFILE__ +#define __BTFILE__ + +#include "cge/general.h" + +namespace CGE { + +#define BT_SIZE K(1) +#define BT_KEYLEN 13 +#define BT_LEVELS 2 + +#define BT_NONE 0xFFFF +#define BT_ROOT 0 + + +struct BT_KEYPACK +{ + uint8 Key[BT_KEYLEN]; + uint32 Mark; + uint16 Size; +}; + + + +struct BT_PAGE +{ + struct HEA + { + uint16 Count; + uint16 Down; + } Hea; + union + { + // dummy filler to make proper size of union + uint8 Data[BT_SIZE-sizeof(HEA)]; + // inner version of data: key + word-sized page link + struct INNER + { + uint8 Key[BT_KEYLEN]; + uint16 Down; + } Inn[(BT_SIZE-sizeof(HEA))/sizeof(INNER)]; + // leaf version of data: key + all user data + BT_KEYPACK Lea[(BT_SIZE-sizeof(HEA))/sizeof(BT_KEYPACK)]; + }; +}; + + + + + +class BTFILE : public IOHAND +{ + struct + { + BT_PAGE * Page; + uint16 PgNo; + int Indx; + bool Updt; + } Buff[BT_LEVELS]; + void PutPage (int lev, bool hard = FALSE); + BT_PAGE * GetPage (int lev, uint16 pgn); +public: + BTFILE (const char * name, IOMODE mode = REA, CRYPT * crpt = NULL); + virtual ~BTFILE (void); + BT_KEYPACK * Find(const byte * key); + BT_KEYPACK * Next(void); + void Make(BT_KEYPACK * keypack, uint16 count); +}; + +} // End of namespace CGE + +#endif diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 499a7033ac2..56383ca92e5 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -29,7 +29,8 @@ #include #include #include -#include +//#include +#include "common/system.h" #ifdef DROP_H #include "cge/drop.h" diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp new file mode 100644 index 00000000000..4add18bd431 --- /dev/null +++ b/engines/cge/config.cpp @@ -0,0 +1,322 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/config.h" +#include "cge/sound.h" +#include "cge/vmenu.h" +#include "cge/text.h" +#include "cge/cge_main.h" + +namespace CGE { + +/* + 51=wska§ typ posiadanej karty d¦wi‘kowej + 52=wybierz numer portu dla karty d¦wi‘kowej + 53=wybierz numer przerwania dla karty d¦wi‘kowej + 54=wybierz numer kana’u DMA dla karty d¦wi‘kowej + 55=wybierz numer portu dla General MIDI + 55=konfiguracja karty d¦wi‘kowej +*/ +#define STYPE_TEXT 51 +#define SPORT_TEXT 52 +#define SIRQ_TEXT 53 +#define SDMA_TEXT 54 +#define MPORT_TEXT 55 +#define MENU_TEXT 56 + +#define NONE_TEXT 60 +#define SB_TEXT 61 +#define SBM_TEXT 62 +#define GUS_TEXT 63 +#define GUSM_TEXT 64 +#define MIDI_TEXT 65 +#define AUTO_TEXT 66 + +#define DETECT 0xFFFF + + +void NONE (void); +void SB (void); +void SBM (void); +void GUS (void); +void GUSM (void); +void MIDI (void); +void AUTO (void); +void SetPortD (void); +void SetPortM (void); +void SetIRQ (void); +void SetDMA (void); + + +static int DevName[] = { NONE_TEXT, SB_TEXT, SBM_TEXT, + GUS_TEXT, GUSM_TEXT, + MIDI_TEXT, AUTO_TEXT }; + +static CHOICE DevMenu[]={ { NULL, NONE }, + { NULL, SB }, + { NULL, SBM }, + { NULL, GUS }, + { NULL, GUSM }, + { NULL, MIDI }, + { NULL, AUTO }, + { NULL, NULL } }; + + +static CHOICE DigiPorts[]={ { " 210h", SetPortD }, + { " 220h", SetPortD }, + { " 230h", SetPortD }, + { " 240h", SetPortD }, + { " 250h", SetPortD }, + { " 260h", SetPortD }, + { "AUTO ", SetPortD }, + { NULL, NULL } }; + +static CHOICE MIDIPorts[]={ { " 220h", SetPortM }, + { " 230h", SetPortM }, + { " 240h", SetPortM }, + { " 250h", SetPortM }, + { " 300h", SetPortM }, + { " 320h", SetPortM }, + { " 330h", SetPortM }, + { " 340h", SetPortM }, + { " 350h", SetPortM }, + { " 360h", SetPortM }, + { "AUTO ", SetPortM }, + { NULL, NULL } }; + +static CHOICE BlsterIRQ[]={ { "IRQ 2", SetIRQ }, + { "IRQ 5", SetIRQ }, + { "IRQ 7", SetIRQ }, + { "IRQ 10", SetIRQ }, + { "AUTO ", SetIRQ }, + { NULL, NULL } }; + +static CHOICE GravisIRQ[]={ { "IRQ 2", SetIRQ }, + { "IRQ 5", SetIRQ }, + { "IRQ 7", SetIRQ }, + { "IRQ 11", SetIRQ }, + { "IRQ 12", SetIRQ }, + { "IRQ 15", SetIRQ }, + { "AUTO ", SetIRQ }, + { NULL, NULL } }; + +static CHOICE GravisDMA[]={ { "DMA 1", SetDMA }, + { "DMA 3", SetDMA }, + { "DMA 5", SetDMA }, + { "DMA 6", SetDMA }, + { "DMA 7", SetDMA }, + { "AUTO ", SetDMA }, + { NULL, NULL } }; + +static CHOICE BlsterDMA[]={ { "DMA 0", SetDMA }, + { "DMA 1", SetDMA }, + { "DMA 3", SetDMA }, + { "AUTO ", SetDMA }, + { NULL, NULL } }; + + + + +void SelectSound (void) +{ + int i; + Sound.Close(); + if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); + Inf(Text[STYPE_TEXT]); + Talk->Goto(Talk->X, FONT_HIG/2); + for (i = 0; i < ArrayCount(DevName); i ++) + DevMenu[i].Text = Text[DevName[i]]; + (new VMENU(DevMenu, SCR_WID/2, Talk->Y+Talk->H+TEXT_VM+FONT_HIG))->SetName(Text[MENU_TEXT]); +} + + + + +static void Reset (void) +{ + SNDDrvInfo.DBASE = SNDDrvInfo.DIRQ = SNDDrvInfo.DDMA = SNDDrvInfo.MBASE = DETECT; +} + + + + + +static uint16 deco (const char * str, uint16 (*dco)(const char *)) +{ + while (*str && ! IsDigit(*str)) ++ str; + if (*str) return dco(str); + else return DETECT; +} + + + + +static uint16 ddeco (const char * str) +{ + return deco(str, atow); +} + + + + +static uint16 xdeco (const char * str) +{ + return deco(str, xtow); +} + + + + +static CHOICE * Cho; +static int Hlp; + +static void SNSelect (void) +{ + Inf(Text[Hlp]); + Talk->Goto(Talk->X, FONT_HIG / 2); + (new VMENU(Cho, SCR_WID/2, Talk->Y+Talk->H+TEXT_VM+FONT_HIG))->SetName(Text[MENU_TEXT]); +} + + + + +static void Select (CHOICE * cho, int hlp) +{ + Cho = cho; + Hlp = hlp; + SNPOST(SNEXEC, -1, 0, (void *) SNSelect); +} + + + + + + +static void NONE (void) +{ + SNDDrvInfo.DDEV = DEV_QUIET; + SNDDrvInfo.MDEV = DEV_QUIET; + Sound.Open(); +} + + + +static void SB (void) +{ + SNDDrvInfo.DDEV = DEV_SB; + SNDDrvInfo.MDEV = DEV_SB; + Reset(); + Select(DigiPorts, SPORT_TEXT); +} + + + +static void SBM (void) +{ + SNDDrvInfo.DDEV = DEV_SB; + SNDDrvInfo.MDEV = DEV_GM; + Reset(); + Select(DigiPorts, SPORT_TEXT); +} + + +static void GUS (void) +{ + SNDDrvInfo.DDEV = DEV_GUS; + SNDDrvInfo.MDEV = DEV_GUS; + Reset(); + Select(DigiPorts, SPORT_TEXT); +} + + + +static void GUSM (void) +{ + SNDDrvInfo.DDEV = DEV_GUS; + SNDDrvInfo.MDEV = DEV_GM; + Reset(); + Select(DigiPorts, SPORT_TEXT); +} + + +static void MIDI (void) +{ + SNDDrvInfo.DDEV = DEV_QUIET; + SNDDrvInfo.MDEV = DEV_GM; + SNDDrvInfo.MBASE = DETECT; + Select(MIDIPorts, MPORT_TEXT); +} + + + +static void AUTO (void) +{ + SNDDrvInfo.DDEV = DEV_AUTO; + SNDDrvInfo.MDEV = DEV_AUTO; + Reset(); + Sound.Open(); +} + + + + + + +static void SetPortD (void) +{ + SNDDrvInfo.DBASE = xdeco(DigiPorts[VMENU::Recent].Text); + Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ, SIRQ_TEXT); +} + + + +static void SetPortM (void) +{ + SNDDrvInfo.MBASE = xdeco(MIDIPorts[VMENU::Recent].Text); + Sound.Open(); +} + + + + +static void SetIRQ (void) +{ + SNDDrvInfo.DIRQ = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ)[VMENU::Recent].Text); + Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA, SDMA_TEXT); +} + + + + +static void SetDMA (void) +{ + SNDDrvInfo.DDMA = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA)[VMENU::Recent].Text); + if (SNDDrvInfo.MDEV != SNDDrvInfo.DDEV) Select(MIDIPorts, MPORT_TEXT); + else Sound.Open(); +} + +} // End of namespace CGE diff --git a/engines/cge/config.h b/engines/cge/config.h new file mode 100644 index 00000000000..1e692afc4d6 --- /dev/null +++ b/engines/cge/config.h @@ -0,0 +1,37 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef __CONFIG__ +#define __CONFIG__ + +namespace CGE { + +void SelectSound (void); + +} // End of namespace CGE + +#endif diff --git a/engines/cge/module.mk b/engines/cge/module.mk index 7424c8bc38f..e028d7feb4a 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -3,9 +3,11 @@ MODULE := engines/cge MODULE_OBJS := \ bitmap.o \ bitmaps.o \ + btfile.o \ cfile.o \ cge.o \ cge_main.o \ + config.o \ console.o \ detection.o \ game.o \ diff --git a/engines/cge/talk.h b/engines/cge/talk.h index fb1d450f2d9..76539fbcf97 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -29,7 +29,7 @@ #define __TALK__ #include "cge/vga13h.h" -#include +//#include namespace CGE { diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index d8e22735576..e5c34d238f1 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -30,7 +30,7 @@ #include "cge/general.h" #include -#include +//#include #include "cge/bitmap.h" #include "cge/snail.h" diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 8a94dbe8af2..9f4391cc9a9 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -26,7 +26,8 @@ */ #include "cge/vol.h" -#include +//#include +#include "common/system.h" #include #include #include diff --git a/engines/cge/vol.h b/engines/cge/vol.h index a98dbbeee28..b63b08e7a18 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -29,7 +29,7 @@ #define __VOL__ -#include +//#include #include "cge/btfile.h" #include "cge/cfile.h" From 11264a60a7dc8e3e04b5b73f6794269f097010ff Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 11 Jun 2011 22:35:21 +0200 Subject: [PATCH 009/276] CGE: Stubbing and cleanup made by SylvainTV --- engines/cge/bitmap.cpp | 36 ++++++---- engines/cge/boot.h | 2 +- engines/cge/btfile.cpp | 17 +++-- engines/cge/btfile.h | 4 +- engines/cge/cfile.cpp | 26 ++++--- engines/cge/cfile.h | 2 +- engines/cge/cge_main.cpp | 106 ++++++++++++++++++---------- engines/cge/cge_main.h | 1 + engines/cge/config.cpp | 25 +++---- engines/cge/game.cpp | 10 +-- engines/cge/general.h | 16 +++-- engines/cge/gettext.cpp | 2 +- engines/cge/jbw.h | 18 ++++- engines/cge/keybd.cpp | 13 +++- engines/cge/keybd.h | 8 +-- engines/cge/mixer.cpp | 6 +- engines/cge/mouse.cpp | 8 +++ engines/cge/snail.cpp | 32 +++++---- engines/cge/snail.h | 4 +- engines/cge/snddrv.h | 3 +- engines/cge/sound.cpp | 14 ++-- engines/cge/startup.cpp | 15 ++-- engines/cge/talk.cpp | 28 ++++---- engines/cge/talk.h | 6 +- engines/cge/text.cpp | 16 +++-- engines/cge/text.h | 4 +- engines/cge/vga13h.cpp | 147 ++++++++++++++++++++++++++++----------- engines/cge/vga13h.h | 2 +- engines/cge/vmenu.cpp | 10 +-- engines/cge/vol.cpp | 10 ++- engines/cge/vol.h | 2 +- engines/cge/wav.h | 3 +- 32 files changed, 382 insertions(+), 214 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 5c416500d6b..10f19029d64 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -27,19 +27,25 @@ #include "cge/bitmap.h" #include "cge/cfile.h" +#include "cge/jbw.h" #ifdef VOL #include "cge/vol.h" #endif -#ifdef DROP_H - #include "cge/drop.h" + +#ifndef DROP_H +// TODO replace printf by scummvm equivalent +#define DROP(m,n) {} +//#define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } #endif + //#include //#include //#include #include +#include "cge/cfile.h" #include "common/system.h" namespace CGE { @@ -51,7 +57,7 @@ namespace CGE { DAC * BITMAP::Pal = NULL; - +#define MAXPATH 128 #pragma argsused BITMAP::BITMAP (const char * fname, bool rem) @@ -82,7 +88,7 @@ BITMAP::BITMAP (const char * fname, bool rem) Code(); if (rem) { - farfree(M); + free(M); M = NULL; } } @@ -151,11 +157,11 @@ BITMAP::BITMAP (const BITMAP& bmp) uint8 * v0 = bmp.V; if (v0) { - uint16 vsiz = FP_OFF(bmp.B) - FP_OFF(v0); + uint16 vsiz = (uint8*)(bmp.B) - (uint8*)(v0); uint16 siz = vsiz + H * sizeof(HideDesc); uint8 * v1 = farnew(uint8, siz); if (v1 == NULL) DROP("No core", NULL); - _fmemcpy(v1, v0, siz); + memcpy(v1, v0, siz); B = (HideDesc *) ((V = v1) + vsiz); } } @@ -168,12 +174,12 @@ BITMAP::~BITMAP (void) { switch (MemType(M)) { - case FAR_MEM : farfree(M); break; + case FAR_MEM : free(M); break; } switch (MemType(V)) { case NEAR_MEM : delete[] (uint8 *) V; break; - case FAR_MEM : farfree(V); break; + case FAR_MEM : free(V); break; } } @@ -185,15 +191,15 @@ BITMAP& BITMAP::operator = (const BITMAP& bmp) W = bmp.W; H = bmp.H; M = NULL; - if (MemType(V) == FAR_MEM) farfree(V); + if (MemType(V) == FAR_MEM) free(V); if (v0 == NULL) V = NULL; else { - uint16 vsiz = FP_OFF(bmp.B) - FP_OFF(v0); + uint16 vsiz = (uint8*)bmp.B - (uint8*)v0; uint16 siz = vsiz + H * sizeof(HideDesc); uint8 * v1 = farnew(uint8, siz); if (v1 == NULL) DROP("No core", NULL); - _fmemcpy(v1, v0, siz); + memcpy(v1, v0, siz); B = (HideDesc *) ((V = v1) + vsiz); } return *this; @@ -207,10 +213,10 @@ uint16 BITMAP::MoveVmap (uint8 * buf) { if (V) { - uint16 vsiz = FP_OFF(B) - FP_OFF(V); + uint16 vsiz = (uint8*)B - (uint8*)V; uint16 siz = vsiz + H * sizeof(HideDesc); - _fmemcpy(buf, V, siz); - if (MemType(V) == FAR_MEM) farfree(V); + memcpy(buf, V, siz); + if (MemType(V) == FAR_MEM) free(V); B = (HideDesc *) ((V = buf) + vsiz); return siz; } @@ -234,7 +240,7 @@ BMP_PTR BITMAP::Code (void) switch (MemType(V)) { case NEAR_MEM : delete[] (uint8 *) V; break; - case FAR_MEM : farfree(V); break; + case FAR_MEM : free(V); break; } V = NULL; } diff --git a/engines/cge/boot.h b/engines/cge/boot.h index d09afb6d1bc..bc78b0e7fb5 100644 --- a/engines/cge/boot.h +++ b/engines/cge/boot.h @@ -74,6 +74,6 @@ EC Boot * ReadBoot (int drive); EC uint8 CheckBoot (Boot * boot); EC bool WriteBoot (int drive, Boot * boot); -// End of namespace CGE +} // End of namespace CGE #endif diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 4068f323a0a..1851068e2d3 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -28,6 +28,7 @@ #include "cge/btfile.h" //#include #include "common/system.h" +#include "common/str.h" #include @@ -42,7 +43,9 @@ namespace CGE { #ifndef DROP_H - #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } + // TODO replace printf by scummvm equivalent +#define DROP(m,n) + //#define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } #endif #ifndef BT_SIZE @@ -126,7 +129,7 @@ BT_PAGE * BTFILE::GetPage (int lev, uint16 pgn) { Buff[lev].Page->Hea.Count = 0; Buff[lev].Page->Hea.Down = BT_NONE; - _fmemset(Buff[lev].Page->Data, '\0', sizeof(Buff[lev].Page->Data)); + memset(Buff[lev].Page->Data, '\0', sizeof(Buff[lev].Page->Data)); Buff[lev].Updt = TRUE; } Buff[lev].Indx = -1; @@ -138,7 +141,7 @@ BT_PAGE * BTFILE::GetPage (int lev, uint16 pgn) -BT_KEYPACK * BTFILE::Find (const uint8 * key) +BT_KEYPACK * BTFILE::Find (const char * key) { int lev = 0; uint16 nxt = BT_ROOT; @@ -150,7 +153,7 @@ BT_KEYPACK * BTFILE::Find (const uint8 * key) { int i; for (i = 0; i < pg->Hea.Count; i ++) - if (_fmemicmp(key, pg->Inn[i].Key, BT_KEYLEN) < 0) + if (memicmp(key, pg->Inn[i].Key, BT_KEYLEN) < 0) break; nxt = (i) ? pg->Inn[i-1].Down : pg->Hea.Down; Buff[lev].Indx = i-1; @@ -160,7 +163,7 @@ BT_KEYPACK * BTFILE::Find (const uint8 * key) { int i; for (i = 0; i < pg->Hea.Count-1; i ++) - if (_fstricmp(key, pg->Lea[i].Key) <= 0) + if (scumm_stricmp((const char*)key, (const char*)pg->Lea[i].Key) <= 0) break; Buff[lev].Indx = i; return &pg->Lea[i]; @@ -174,7 +177,7 @@ BT_KEYPACK * BTFILE::Find (const uint8 * key) int keycomp (const void * k1, const void * k2) { - return _fmemicmp(k1, k2, BT_KEYLEN); + return memicmp(k1, k2, BT_KEYLEN); } @@ -196,7 +199,7 @@ void BTFILE::Make(BT_KEYPACK * keypack, uint16 count) { PutPage(1, TRUE); // save filled page Leaf = GetPage(1, ++n); // take empty page - _fmemcpy(Root->Inn[Root->Hea.Count].Key, keypack->Key, BT_KEYLEN); + memcpy(Root->Inn[Root->Hea.Count].Key, keypack->Key, BT_KEYLEN); Root->Inn[Root->Hea.Count ++].Down = n; Buff[0].Updt = TRUE; } diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 0599bee72a6..0df96365738 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -42,7 +42,7 @@ namespace CGE { struct BT_KEYPACK { - uint8 Key[BT_KEYLEN]; + char Key[BT_KEYLEN]; uint32 Mark; uint16 Size; }; @@ -89,7 +89,7 @@ class BTFILE : public IOHAND public: BTFILE (const char * name, IOMODE mode = REA, CRYPT * crpt = NULL); virtual ~BTFILE (void); - BT_KEYPACK * Find(const byte * key); + BT_KEYPACK * Find(const char * key); BT_KEYPACK * Next(void); void Make(BT_KEYPACK * keypack, uint16 count); }; diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 56383ca92e5..4d555c979d3 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -42,7 +42,9 @@ namespace CGE { #ifndef DROP_H - #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } + //TODO Replace by scummvm printf +#define DROP(m,n) {} + //#define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } #endif IOBUF::IOBUF (IOMODE mode, CRYPT * crpt) @@ -84,7 +86,7 @@ IOBUF::IOBUF (const char * name, IOMODE mode, CRYPT * crpt) IOBUF::~IOBUF (void) { if (Mode > REA) WriteBuff(); - if (Buff) farfree(Buff); + if (Buff) free(Buff); } @@ -127,8 +129,8 @@ uint16 IOBUF::Read (void *buf, uint16 len) if (n) { if (len < n) n = len; - _fmemcpy(buf, Buff+Ptr, n); - (uint8 *) buf += n; + memcpy(buf, Buff+Ptr, n); + buf = (uint8 *)buf + n; len -= n; total += n; Ptr += n; @@ -155,15 +157,15 @@ uint16 IOBUF::Read (uint8 * buf) if (n) { if (total + n >= LINE_MAX-2) n = LINE_MAX-2 - total; - uint8 * eol = (uint8 *) _fmemchr(p, '\r', n); + uint8 * eol = (uint8 *) memchr(p, '\r', n); if (eol) n = (uint16) (eol - p); - uint8 * eof = (uint8 *) _fmemchr(p, '\32', n); + uint8 * eof = (uint8 *) memchr(p, '\32', n); if (eof) // end-of-file { n = (uint16) (eof - p); Ptr = (uint16) (eof - Buff); } - if (n) _fmemcpy(buf, p, n); + if (n) memcpy(buf, p, n); buf += n; total += n; if (eof) break; @@ -199,10 +201,10 @@ uint16 IOBUF::Write (void * buf, uint16 len) if (n > len) n = len; if (n) { - _fmemcpy(Buff+Lim, buf, n); + memcpy(Buff+Lim, buf, n); Lim += n; len -= n; - (uint8 *) buf += n; + buf = (uint8 *)buf + n; tot += n; } else WriteBuff(); @@ -220,7 +222,7 @@ uint16 IOBUF::Write (uint8 * buf) uint16 len = 0; if (buf) { - len = _fstrlen((const char *) buf); + len = strlen((const char *) buf); if (len) if (buf[len-1] == '\n') -- len; len = Write(buf, len); if (len) @@ -302,9 +304,13 @@ void CFILE::Flush (void) { if (Mode > REA) WriteBuff(); else Lim = 0; + + // TODO replace by scummvm files. + /* _BX = Handle; _AH = 0x68; // Flush buffer asm int 0x21 + */ } diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index b08dc833b0c..e8d494c2f9a 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -59,7 +59,7 @@ public: IOBUF (const char * name, IOMODE mode, CRYPT * crpt = NULL); virtual ~IOBUF (void); uint16 Read (void * buf, uint16 len); - uint16 Read (char * buf); + uint16 Read (uint8 * buf); int Read (void); uint16 Write (void * buf, uint16 len); uint16 Write (uint8 * buf); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 36053d926c6..ebf3f3f9fd4 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -44,17 +44,19 @@ #include "cge/gettext.h" #include "cge/mixer.h" #include "cge/cge_main.h" -#include +//#include #include #include #include #include #include -#include +//#include #include -#include +//#include #include +#include "common/str.h" + namespace CGE { #define STACK_SIZ (K(2)) @@ -189,7 +191,8 @@ uint8 & CLUSTER::Cell (void) bool CLUSTER::Protected (void) { if (A == Barriers[Now].Vert || B == Barriers[Now].Horz) return true; - + // TODO AsM + /* _DX = (MAP_ZCNT << 8) + MAP_XCNT; _BX = (uint16) this; @@ -221,6 +224,8 @@ bool CLUSTER::Protected (void) // return Map[B][A] != 0; xit: return _AX; + */ + return TRUE; } @@ -309,7 +314,7 @@ static void LoadGame (XFILE& file, bool tiny = false) if (n != sizeof(S)) break; S.Prev = S.Next = NULL; - spr = (stricmp(S.File+2, "MUCHA") == 0) ? new FLY(NULL) + spr = (scumm_stricmp(S.File+2, "MUCHA") == 0) ? new FLY(NULL) : new SPRITE(NULL); if (spr == NULL) VGA::Exit("No core"); *spr = S; @@ -394,7 +399,7 @@ static void Trouble (int seq, int txt) static void OffUse (void) { - Trouble(OFF_USE, OFF_USE_TEXT+random(OffUseCount)); + Trouble(OFF_USE, OFF_USE_TEXT+new_random(OffUseCount)); } @@ -580,6 +585,8 @@ void WALK::Park (void) void WALK::FindWay (CLUSTER c) { + // TODO : Find1Way in ASM +/* bool Find1Way(void); extern uint16 Target; @@ -598,6 +605,7 @@ void WALK::FindWay (CLUSTER c) if (TracePtr < 0) NoWay(); Time = 1; } +*/ } @@ -732,17 +740,17 @@ static void SetMapBrick (int x, int z) //-------------------------------------------------------------------------- void dummy (void) { } -void SwitchMapping (void); -void SwitchColorMode (void); -void StartCountDown (void); -Debug( void SwitchDebug (void); ) -void SwitchMusic (void); -void KillSprite (void); -void PushSprite (void); -void PullSprite (void); -void BackPaint (void); -void NextStep (void); -void SaveMapping (void); +static void SwitchMapping (void); +static void SwitchColorMode (void); +static void StartCountDown (void); +Debug(static void SwitchDebug (void); ) +static void SwitchMusic (void); +static void KillSprite (void); +static void PushSprite (void); +static void PullSprite (void); +static void BackPaint (void); +static void NextStep (void); +static void SaveMapping (void); WALK * Hero = NULL; @@ -835,7 +843,8 @@ static void MiniStep (int stp) static void PostMiniStep (int stp) { static int recent = -2; - if (MiniCave && stp != recent) SNPOST_(SNEXEC, -1, recent = stp, (void *) MiniStep); + //TODO Change the SNPOST message send to a special way to send function pointer + //if (MiniCave && stp != recent) SNPOST_(SNEXEC, -1, recent = stp, (void *)&MiniStep); } @@ -993,7 +1002,8 @@ static void QGame (void) CaveDown(); OldLev = Lev; SaveSound(); - SaveGame(CFILE(UsrPath(UsrFnam), WRI, RCrypt)); + CFILE file = CFILE(UsrPath(UsrFnam), WRI, RCrypt); + SaveGame(file); Vga.Sunset(); Finis = true; } @@ -1009,7 +1019,8 @@ void SwitchCave (int cav) if (cav < 0) { SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - SNPOST(SNEXEC, -1, 0, (void *) QGame); // switch cave + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST(SNEXEC, -1, 0, (void *)&QGame); // switch cave } else { @@ -1030,7 +1041,8 @@ void SwitchCave (int cav) KillText(); if (! Startup) KeyClick(); SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - SNPOST(SNEXEC, 0, 0, (void *) XCave); // switch cave + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST(SNEXEC, 0, 0, (void *)&XCave); // switch cave } } } @@ -1198,7 +1210,7 @@ void SYSTEM::Tick (void) if (PAIN) HeroCover(9); else if (STARTUP::Core >= CORE_MID) { - int n = random(100); + int n = new_random(100); if (n > 96) HeroCover(6+(Hero->X+Hero->W/2 < SCR_WID/2)); else { @@ -1271,7 +1283,8 @@ static void SwitchMusic (void) else { SNPOST_(SNSEQ, 122, (Music = false), NULL); - SNPOST(SNEXEC, -1, 0, (void *) SelectSound); + //TODO Change the SNPOST message send to a special way to send function pointer + // SNPOST(SNEXEC, -1, 0, (void *)&SelectSound); } } else @@ -1665,12 +1678,12 @@ void SPRITE::Touch (uint16 mask, int x, int y) static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int row = 0, int pos = 0) { - static char * Comd[] = { "Name", "Type", "Phase", "East", + static const char * Comd[] = { "Name", "Type", "Phase", "East", "Left", "Right", "Top", "Bottom", "Seq", "Near", "Take", "Portable", "Transparent", NULL }; - static char * Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS", + static const char * Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS", "FLY", NULL }; char line[LINE_MAX]; @@ -1691,7 +1704,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro VGA::Exit("Bad SPR", line); } - while ((len = sprf.Read(line)) != 0) + while ((len = sprf.Read((uint8*)line)) != 0) { ++ lcnt; if (len && line[len-1] == '\n') line[-- len] = '\0'; @@ -1738,6 +1751,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro switch (type) { case 1 : // AUTO + { Sprite = new SPRITE(NULL); if (Sprite) { @@ -1745,7 +1759,9 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro //Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$ } break; + } case 2 : // WALK + { WALK * w = new WALK(NULL); if (w && ref == 1) { @@ -1758,6 +1774,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro } Sprite = w; break; + } /* case 3 : // NEWTON NEWTON * n = new NEWTON(NULL); @@ -1774,6 +1791,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro break; */ case 4 : // LISSAJOUS + { VGA::Exit("Bad type", fname); /* LISSAJOUS * l = new LISSAJOUS(NULL); @@ -1791,15 +1809,20 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro Sprite = l; */ break; + } case 5 : // FLY + { FLY * f = new FLY(NULL); Sprite = f; //////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$ break; + } default: // DEAD + { Sprite = new SPRITE(NULL); if (Sprite) Sprite->Goto(col, row); break; + } } if (Sprite) { @@ -1811,8 +1834,10 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro Sprite->Flags.Tran = tran; Sprite->Flags.Kill = true; Sprite->Flags.BDel = true; - fnsplit(fname, NULL, NULL, Sprite->File, NULL); - Sprite->ShpCnt = shpcnt; + // TODO : Get Filename from entire path + //fnsplit(fname, NULL, NULL, Sprite->File, NULL); + + Sprite->ShpCnt = shpcnt; VGA::SpareQ.Append(Sprite); } } @@ -1834,7 +1859,7 @@ static void LoadScript (const char *fname) if (scrf.Error) return; - while (scrf.Read(line) != 0) + while (scrf.Read((uint8*)line) != 0) { char *p; @@ -1941,16 +1966,22 @@ void LoadUser (void) // set scene if (STARTUP::Mode == 0) // user .SVG file found { - LoadGame(CFILE(UsrPath(UsrFnam), REA, RCrypt)); + CFILE cfile = CFILE(UsrPath(UsrFnam), REA, RCrypt); + LoadGame(cfile); } else { - if (STARTUP::Mode == 1) LoadGame(SVG0FILE(SVG0NAME)); + if (STARTUP::Mode == 1) + { + SVG0FILE file = SVG0FILE(SVG0NAME); + LoadGame(file); + } else { LoadScript(ProgName(INI_EXT)); Music = true; - SaveGame(CFILE(SVG0NAME, WRI)); + CFILE file = CFILE(SVG0NAME, WRI); + SaveGame(file); VGA::Exit("Ok", SVG0NAME); } } @@ -2061,7 +2092,8 @@ static void RunGame (void) // main loop while (! Finis) { - if (FINIS) SNPOST(SNEXEC, -1, 0, (void *) QGame); + //TODO Change the SNPOST message send to a special way to send function pointer + // if (FINIS) SNPOST(SNEXEC, -1, 0, (void *)&QGame); MainLoop(); } @@ -2160,7 +2192,8 @@ bool ShowTitle (const char * name) #ifdef CD STARTUP::Summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; #else - Boot * b = ReadBoot(getdisk()); + // TODO : do good boot... + Boot * b = ReadBoot(0); //getdisk()); uint32 sn = (b->XSign == 0x29) ? b->Serial : b->lTotSecs; free(b); sn -= ((IDENT *)Copr)->disk; @@ -2187,7 +2220,8 @@ bool ShowTitle (const char * name) const char *n = UsrPath(UsrFnam); if (CFILE::Exist(n)) { - LoadGame(CFILE(n, REA, RCrypt), true); // only system vars + CFILE file = CFILE(n, REA, RCrypt); + LoadGame(file, true); // only system vars VGA::SetColors(SysPal, 64); Vga.Update(); if (FINIS) @@ -2242,7 +2276,7 @@ void cge_main (void) Debug( DebugLine.Flags.Hide = true; ) Debug( HorzLine.Flags.Hide = true; ) - srand((uint16) Timer()); + //srand((uint16) Timer()); Sys = new SYSTEM; if (Music && STARTUP::SoundOk) LoadMIDI(0); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 8605d17c55b..30a07dd67e9 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -29,6 +29,7 @@ #define __CGE__ #include "cge\wav.h" +#include "cge\vga13h.h" namespace CGE { diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 4add18bd431..38da4cda589 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -59,17 +59,17 @@ namespace CGE { #define DETECT 0xFFFF -void NONE (void); -void SB (void); -void SBM (void); -void GUS (void); -void GUSM (void); -void MIDI (void); -void AUTO (void); -void SetPortD (void); -void SetPortM (void); -void SetIRQ (void); -void SetDMA (void); +static void NONE (void); +static void SB (void); +static void SBM (void); +static void GUS (void); +static void GUSM (void); +static void MIDI (void); +static void AUTO (void); +static void SetPortD (void); +static void SetPortM (void); +static void SetIRQ (void); +static void SetDMA (void); static int DevName[] = { NONE_TEXT, SB_TEXT, SBM_TEXT, @@ -208,7 +208,8 @@ static void Select (CHOICE * cho, int hlp) { Cho = cho; Hlp = hlp; - SNPOST(SNEXEC, -1, 0, (void *) SNSelect); + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST(SNEXEC, -1, 0, (void *)&SNSelect); } diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index d9bcf916bbb..b6530323e4f 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -91,8 +91,8 @@ int FLY::L = 20, FLY::FLY (BITMAP ** shpl) : SPRITE(shpl), Tx(0), Ty(0) { - Step(random(2)); - Goto(L+random(R-L-W), T+random(B-T-H)); + Step(new_random(2)); + Goto(L+new_random(R-L-W), T+new_random(B-T-H)); } @@ -103,10 +103,10 @@ void FLY::Tick (void) Step(); if (! Flags.Kept) { - if (random(10) < 1) + if (new_random(10) < 1) { - Tx = random(3) - 1; - Ty = random(3) - 1; + Tx = new_random(3) - 1; + Ty = new_random(3) - 1; } if (X + Tx < L || X + Tx + W > R) Tx = -Tx; if (Y + Ty < T || Y + Ty + H > B) Ty = -Ty; diff --git a/engines/cge/general.h b/engines/cge/general.h index ac45f4b4add..4633ba2d3ce 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -29,6 +29,9 @@ #define __GENERAL__ #include "common/system.h" +#include "common/random.h" +#include "common/textconsole.h" +#include "common/str.h" #include "cge\jbw.h" #include @@ -57,8 +60,9 @@ typedef struct { typedef uint16 CRYPT (void *buf, uint16 siz, uint16 seed); +extern Common::RandomSource randSrc; - +#define new_random(a) (randSrc.getRandomNumber(a)) @@ -87,8 +91,8 @@ public: class ENGINE { protected: - static void interrupt (* OldTimer) (...); - static void interrupt NewTimer (...); + static void (* OldTimer) (...); + static void NewTimer (...); public: ENGINE (uint16 tdiv); ~ENGINE (void); @@ -111,7 +115,7 @@ class EMM long Top, Lim; EMS * List; int Han; - static void _seg * Frame; + static void * Frame; public: EMM::EMM (long size = 0); EMM::~EMM (void); @@ -225,8 +229,8 @@ public: long Mark (void); long Size (void); long Seek (long pos); - ftime Time (void); - void SetTime (ftime t); + //timeb Time (void); + // void SetTime (timeb t); }; diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index f8de84f5fc6..892ef5ee735 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -37,7 +37,7 @@ GET_TEXT * GET_TEXT::Ptr = NULL; GET_TEXT::GET_TEXT (const char * info, char * text, int size, void (*click)(void)) -: Text(text), Size(min(size, GTMAX)), Len(min(Size, strlen(text))), +: Text(text), Size(min(size, GTMAX)), Len(min(Size, strlen(text))), Cntr(GTBLINK), Click(click), OldKeybClient(KEYBOARD::SetClient(this)) { int i = 2 * TEXT_HM + Font.Width(info); diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 236a2e6ddb2..8f6e0ea44e3 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -28,8 +28,17 @@ #ifndef __JBW__ #define __JBW__ +#include "common/scummsys.h" + namespace CGE { +#define VOL +#define INI_FILE VFILE +#define PIC_FILE VFILE +#define BMP_MODE 0 +#define DROP {} // TODO error handling +#define DROP_H + #define BEL 7 #define BS 8 #define HT 9 @@ -37,6 +46,11 @@ namespace CGE { #define FF 12 #define CR 13 +#define TRUE 1 +#define FALSE 0 + +#define MAXFILE 128 + #define NULL 0 #define OFF false #define ON true @@ -49,11 +63,11 @@ namespace CGE { #define IsAlNum(c) (IsAlpha(c) || IsDigit(c)) #define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) -#define farnew(t,n) ((t *) farmalloc(sizeof(t) * (n))) +#define farnew(t,n) ((t *) malloc(sizeof(t) * (n))) #define ArrayCount(a) (sizeof(a)/sizeof((a)[0])) #define MAX_TIMER 0x1800B0L -typedef void (_loadds MouseFunType)(void); +typedef void (MouseFunType)(void); #define Lo(d) (((int *) &d)[0]) #define Hi(d) (((int *) &d)[1]) diff --git a/engines/cge/keybd.cpp b/engines/cge/keybd.cpp index dbbc06bcb22..e4858d1d047 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/keybd.cpp @@ -46,15 +46,17 @@ uint16 KEYBOARD::Code[0x60] = { 0,Esc,'1','2','3','4','5','6','7','8','9','0', 0*0x54,0*0x55,0*0x56,F11,F12,0*0x59,0*0x5A, 0*0x5B,0*0x5C,0*0x5D,0*0x5E,0*0x5F }; -void interrupt (* KEYBOARD::OldKeyboard) (...); +void (* KEYBOARD::OldKeyboard) (...); KEYBOARD::KEYBOARD (void) { // steal keyboard interrupt + /* TODO replace totally by scummvm handling OldKeyboard = getvect(KEYBD_INT); setvect(KEYBD_INT, NewKeyboard); + */ } @@ -63,7 +65,9 @@ KEYBOARD::KEYBOARD (void) KEYBOARD::~KEYBOARD (void) { // bring back keyboard interrupt - setvect(KEYBD_INT, OldKeyboard); + /* TODO replace totally by scummvm handling + setvect(KEYBD_INT, OldKeyboard); + */ } @@ -79,9 +83,11 @@ SPRITE * KEYBOARD::SetClient (SPRITE * spr) -void interrupt KEYBOARD::NewKeyboard (...) +void KEYBOARD::NewKeyboard (...) { // table address + // TODO keyboard ASM + /* _SI = (uint16) Key; // take keyboard code @@ -139,6 +145,7 @@ void interrupt KEYBOARD::NewKeyboard (...) asm out 61h,al // write it back asm mov al,20h // send End-Of-Interrupt asm out 20h,al // to the 8259 IC + */ } } // End of namespace CGE diff --git a/engines/cge/keybd.h b/engines/cge/keybd.h index b38481f7d37..5e6c9ac5347 100644 --- a/engines/cge/keybd.h +++ b/engines/cge/keybd.h @@ -42,14 +42,14 @@ namespace CGE { class KEYBOARD { - static void interrupt (* OldKeyboard) (...); - static void interrupt NewKeyboard (...); +public: + static void (* OldKeyboard) (...); + static void NewKeyboard (...); static uint16 Code[0x60]; static uint16 Current; static SPRITE * Client; -public: static uint8 Key[0x60]; - static uint16 Last (void) { _AX = Current; Current = 0; return _AX; } + static uint16 Last (void) { uint16 cur = Current; Current = 0; return cur; } static SPRITE * SetClient (SPRITE * spr); KEYBOARD (void); ~KEYBOARD (void); diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 2ebede93bee..346631b08a9 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -31,7 +31,7 @@ #include "cge/mouse.h" #include "cge/snddrv.h" #include -#include +//#include namespace CGE { @@ -151,7 +151,9 @@ void MIXER::Update (void) { Led[0]->Step(SNDDrvInfo.VOL4.ML); Led[1]->Step(SNDDrvInfo.VOL4.DL); - SNPOST_(SNEXEC, -1, 0, SNDSetVolume); + + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST_(SNEXEC, -1, 0, (void*)&SNDSetVolume); } } // End of namespace CGE diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index 94f7cbf0ac1..dff2a0ff8b1 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -53,6 +53,7 @@ MOUSE::MOUSE (BITMAP ** shpl) static SEQ ms[] = { { 0,0,0,0,1 }, { 1,1,0,0,1 } }; SetSeq(ms); + /* TODO Mouse handling // Mouse reset _AX = 0x0000; // soft & hard reset (0x0021 soft reset does not work) __int__(0x33); @@ -62,6 +63,7 @@ MOUSE::MOUSE (BITMAP ** shpl) Goto(SCR_WID/2, SCR_HIG/2); Z = 127; Step(1); + */ } @@ -86,6 +88,8 @@ MOUSE::~MOUSE (void) void MOUSE::On (void) { + // TODO Mouse +/* if (SeqPtr && Exist) { _CX = X + X; // horizontal position @@ -117,6 +121,7 @@ void MOUSE::On (void) Step(0); if (Busy) Busy->Step(0); } +*/ } @@ -126,6 +131,8 @@ void MOUSE::On (void) void MOUSE::Off (void) { +//TODO MOuse ASM + /* if (SeqPtr == 0) { if (Exist) @@ -140,6 +147,7 @@ void MOUSE::Off (void) Step(1); if (Busy) Busy->Step(1); } + */ } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 67a16a8563b..733acb2398d 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -34,8 +34,8 @@ #include "cge/mouse.h" #include "cge/cge_main.h" #include -#include -#include +//#include +//#include #include #include #include "cge/keybd.h" @@ -102,12 +102,12 @@ static void SNGame (SPRITE * spr, int num) if (Game) // continue game { - int i = random(3), hand = (dup[0]->ShpCnt == 6); + int i = new_random(3), hand = (dup[0]->ShpCnt == 6); ++ Stage; if (hand && Stage > DRESSED) ++ hand; if ( Debug( i >= 0 || ) - dup[i] == spr && random(3) == 0) + dup[i] == spr && new_random(3) == 0) { SNPOST(SNSEQ, -1, 3, dup[0]); // yes SNPOST(SNSEQ, -1, 3, dup[1]); // yes @@ -204,9 +204,9 @@ static void SNGame (SPRITE * spr, int num) } else // cont { - k1->Step(random(6)); - k2->Step(random(6)); - k3->Step(random(6)); + k1->Step(new_random(6)); + k2->Step(new_random(6)); + k3->Step(new_random(6)); ///-------------------- if (spr->Ref == 1 && KEYBOARD::Key[ALT]) { @@ -237,7 +237,7 @@ static void SNGame (SPRITE * spr, int num) Game = false; return; } - else k3->Step(random(5)); + else k3->Step(new_random(5)); } if (count < 100) { @@ -383,7 +383,8 @@ void Hide1 (SPRITE * spr) void SNGhost (BITMAP * bmp) { - bmp->Hide(FP_OFF(bmp->M), FP_SEG(bmp->M)); + // TODO : Get x and y from M but not using segment / offset + //bmp->Hide(FP_OFF(bmp->M), FP_SEG(bmp->M)); bmp->M = NULL; delete bmp; } @@ -470,7 +471,7 @@ void FeedSnail (SPRITE * spr, SNLIST snq) //-------------------------------------------------------------------------- -char * SNAIL::ComTxt[] = { "LABEL", "PAUSE", "WAIT", "LEVEL", +const char * SNAIL::ComTxt[] = { "LABEL", "PAUSE", "WAIT", "LEVEL", "HIDE", "SAY", "INF", "TIME", "CAVE", "KILL", "RSEQ", "SEQ", "SEND", "SWAP", "KEEP", "GIVE", @@ -502,7 +503,7 @@ SNAIL::SNAIL (bool turbo) SNAIL::~SNAIL (void) { - if (SNList) farfree(SNList); + if (SNList) free(SNList); } @@ -766,7 +767,7 @@ void SNCover (SPRITE * spr, int xref) xspr->Cave = spr->Cave; xspr->Goto(spr->X, spr->Y); ExpandSprite(xspr); - if ((xspr->Flags.Shad = spr->Flags.Shad) == true) + if ((xspr->Flags.Shad = spr->Flags.Shad) == TRUE) { VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr->Prev), xspr); spr->Flags.Shad = false; @@ -786,7 +787,7 @@ void SNUncover (SPRITE * spr, SPRITE * xspr) spr->Flags.Hide = false; spr->Cave = xspr->Cave; spr->Goto(xspr->X, xspr->Y); - if ((spr->Flags.Shad = xspr->Flags.Shad) == true) + if ((spr->Flags.Shad = xspr->Flags.Shad) == TRUE) { VGA::ShowQ.Insert(VGA::ShowQ.Remove(xspr->Prev), spr); xspr->Flags.Shad = false; @@ -1099,7 +1100,7 @@ void SNFlash (bool on) if (pal) { int i; - _fmemcpy(pal, SysPal, PAL_SIZ); + memcpy(pal, SysPal, PAL_SIZ); for (i = 0; i < PAL_CNT; i ++) { register int c; @@ -1285,7 +1286,8 @@ void SNAIL::RunCom (void) case SNSOUND : SNSound(sprel, snc->Val, count); count = 1; break; case SNCOUNT : count = snc->Val; break; - case SNEXEC : ((void(*)(int)) (snc->Ptr))(snc->Val); break; + // TODO: Handle correctly the execution of function pointer coming from Message send SNPOST + //case SNEXEC : ((void(*)(int)) (snc->Ptr))(snc->Val); break; case SNSTEP : sprel->Step(); break; case SNZTRIM : SNZTrim(sprel); break; case SNGHOST : SNGhost((BITMAP *) snc->Ptr); break; diff --git a/engines/cge/snail.h b/engines/cge/snail.h index bf47fa13d43..88bb5f09dd0 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -83,12 +83,12 @@ enum SNLIST { NEAR, TAKE }; class SNAIL { +public: struct COM { SNCOM Com; int Ref; int Val; void * Ptr; } * SNList; uint8 Head, Tail; bool Turbo, Busy, TextDelay; uint16 Pause; -public: - static char * ComTxt[]; + static const char * ComTxt[]; bool TalkEnable; SNAIL (bool turbo = false); ~SNAIL (void); diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 662d4807780..8d29a807d7d 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -130,6 +130,7 @@ EC void SNDMIDIStop (void); // WARNING: Uses ALL registers! EC void SNDMIDIPlay (void); -// End of namespace CGE +} // End of namespace CGE + #endif diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 81dd4576039..11385c12e39 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -39,7 +39,7 @@ #include "cge/text.h" #include "cge/cfile.h" #include "cge/vol.h" -#include +//#include namespace CGE { @@ -95,7 +95,7 @@ void SOUND::Play (DATACK * wav, int pan, int cnt) if (wav) { Stop(); - smpinf.saddr = (char *) &*(wav->EAddr()); + smpinf.saddr = (uint8 *) &*(wav->EAddr()); smpinf.slen = (uint16)wav->Size(); smpinf.span = pan; smpinf.sflag = cnt; @@ -196,7 +196,8 @@ void FX::Preload (int ref0) { static char fname[] = "FX00000.WAV"; wtom(ref, fname+2, 10, 5); - DATACK * wav = LoadWave(&INI_FILE(fname), &Emm); + INI_FILE file = INI_FILE(fname); + DATACK * wav = LoadWave(&file, &Emm); if (wav) { HAN * p = &Cache[Find(0)]; @@ -216,7 +217,8 @@ DATACK * FX::Load (int idx, int ref) static char fname[] = "FX00000.WAV"; wtom(ref, fname+2, 10, 5); - DATACK * wav = LoadWave(&INI_FILE(fname), &Emm); + INI_FILE file = INI_FILE(fname); + DATACK * wav = LoadWave(&file, &Emm); if (wav) { HAN * p = &Cache[idx]; @@ -309,13 +311,13 @@ EC void * Patch (int pat) if (! snd.Error) { uint16 siz = (uint16) snd.Size(); - p = (uint8 *) farmalloc(siz); + p = (uint8 *) malloc(siz); if (p) { snd.Read(p, siz); if (snd.Error) { - farfree(p); + free(p); p = NULL; } } diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 0e45e65b73b..7e5ac71782c 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +//#include #include #ifdef DEBUG @@ -60,17 +60,16 @@ static STARTUP StartUp; -void quit_now (int ref) -{ - fputs(Text[ref], stderr); - fputc('\n', stderr); - _exit(1); +void quit_now(int ref){ + error("%d\n", Text[ref]); } bool STARTUP::get_parms (void) { + // TODO do params + /* int i = _argc; while (i > 1) { @@ -114,6 +113,7 @@ bool STARTUP::get_parms (void) #endif #endif if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; + */ return true; } @@ -122,6 +122,8 @@ bool STARTUP::get_parms (void) STARTUP::STARTUP (void) { + //TOdO startup in scummvm + /* uint32 m = farcoreleft() >> 10; if (m < 0x7FFF) Core = (int) m; else Core = 0x7FFF; @@ -149,6 +151,7 @@ STARTUP::STARTUP (void) if (! cfg.Error) STARTUP::SoundOk = 1; } } + */ } diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 9c15ac1b651..d305d1d27ea 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -31,8 +31,8 @@ #include "cge/game.h" #include "cge/mouse.h" #include -#include -#include +//#include +//#include namespace CGE { @@ -70,9 +70,9 @@ FONT::FONT (const char * name) FONT::~FONT (void) { - farfree(Map); - farfree(Pos); - farfree(Wid); + free(Map); + free(Pos); + free(Wid); } @@ -212,10 +212,10 @@ void TALK::Update (const char * tx) else { int cw = Font.Wid[*tx], i; - char * f = Font.Map + Font.Pos[*tx]; + uint8 * f = Font.Map + Font.Pos[*tx]; for (i = 0; i < cw; i ++) { - char * p = m; + uint8 * p = m; uint16 n; register uint16 b = * (f ++); for (n = 0; n < FONT_HIG; n ++) @@ -246,13 +246,13 @@ BITMAP * TALK::Box (uint16 w, uint16 h) if (h < 8) h = 8; b = farnew(uint8, n = w * h); if (! b) VGA::Exit("No core"); - _fmemset(b, TEXT_BG, n); + memset(b, TEXT_BG, n); if (Mode) { p = b; q = b + n - w; - _fmemset(p, LGRAY, w); - _fmemset(q, DGRAY, w); + memset(p, LGRAY, w); + memset(q, DGRAY, w); while (p < q) { p += w; @@ -301,10 +301,10 @@ void TALK::PutLine (int line, const char * text) // clear whole rectangle p = v; // assume blanked line above text - _fmemcpy(p, p-lsiz, rsiz); p += psiz; // tricky replicate lines for plane 0 - _fmemcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 1 - _fmemcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 2 - _fmemcpy(p, p-lsiz, rsiz); // same for plane 3 + memcpy(p, p-lsiz, rsiz); p += psiz; // tricky replicate lines for plane 0 + memcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 1 + memcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 2 + memcpy(p, p-lsiz, rsiz); // same for plane 3 // paint text line if (text) diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 76539fbcf97..aab6834c284 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -29,6 +29,8 @@ #define __TALK__ #include "cge/vga13h.h" +#include "cge/general.h" +#include "cge/jbw.h" //#include namespace CGE { @@ -45,7 +47,7 @@ namespace CGE { - +#define MAXPATH 128 class FONT { @@ -105,4 +107,4 @@ public: } // End of namespace CGE -#endif \ No newline at end of file +#endif diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index df8ca4cfe5a..9ee6244f222 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -50,11 +50,10 @@ TEXT::TEXT (const char * fname, int size) { Cache = new HAN[size]; MergeExt(FileName, fname, SAY_EXT); - if (! INI_FILE::Exist(FileName)) - { - fputs("No talk\n", stderr); - _exit(1); - } + if (! INI_FILE::Exist(FileName)) { + error("No talk\n"); + } + for (Size = 0; Size < size; Size ++) { Cache[Size].Ref = 0; @@ -124,7 +123,7 @@ void TEXT::Preload (int from, int upto) char line[LINE_MAX+1]; int n; - while ((n = tf.Read(line)) != 0) + while ((n = tf.Read((uint8*)line)) != 0) { char * s; int ref; @@ -168,7 +167,7 @@ char * TEXT::Load (int idx, int ref) char line[LINE_MAX+1]; int n; - while ((n = tf.Read(line)) != 0) + while ((n = tf.Read((uint8*)line)) != 0) { char * s; @@ -289,12 +288,15 @@ void Inf (const char * txt) void SayTime (SPRITE * spr) { +//TODO Get Time +/* static char t[] = "00:00"; struct time ti; gettime(&ti); wtom(ti.ti_hour, t+0, 10, 2); wtom(ti.ti_min, t+3, 10, 2); Say((*t == '0') ? (t+1) : t, spr); + */ } diff --git a/engines/cge/text.h b/engines/cge/text.h index 7394e04b3f1..222a3abf7d4 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -30,7 +30,7 @@ #include "cge/talk.h" #include "cge/jbw.h" -#include +//#include namespace CGE { @@ -83,4 +83,4 @@ void KillText (void); } // End of namespace CGE -#endif \ No newline at end of file +#endif diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 415bff72252..86b04bfe0c2 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -30,15 +30,15 @@ #include "cge/bitmap.h" #include "cge/vol.h" #include "cge/text.h" -#include +//#include #include #include #include #include #include -#include +//#include #include -#include +//#include #include namespace CGE { @@ -112,11 +112,13 @@ char * NumStr (char * str, int num) - +// TODO Video ASM +/* static void Video (void) { static uint16 SP_S; + asm push bx asm push bp asm push si @@ -131,8 +133,9 @@ static void Video (void) asm pop si asm pop bp asm pop bx -} +} + */ @@ -140,6 +143,7 @@ static void Video (void) uint16 * SaveScreen (void) { + /* TODO ASM uint16 cxy, cur, siz, * scr = NULL, * sav; // horizontal size of text mode screen @@ -187,9 +191,11 @@ uint16 * SaveScreen (void) sav[0] = siz; sav[1] = cur; sav[2] = cxy; - _fmemcpy(sav+3, scr, siz * 2); + memcpy(sav+3, scr, siz * 2); } return sav; + */ + return 0; } @@ -198,6 +204,8 @@ uint16 * SaveScreen (void) void RestoreScreen (uint16 * &sav) { + // TODO RestoreScreen ASM + /* uint16 * scr = NULL; asm mov ax,0x40 // system data segment @@ -209,7 +217,7 @@ void RestoreScreen (uint16 * &sav) sto: // store screen address asm mov word ptr scr+2,ax - _fmemcpy(scr, sav+3, sav[0] * 2); + memcpy(scr, sav+3, sav[0] * 2); _AH = 0x0F; Video(); // active page @@ -221,8 +229,9 @@ void RestoreScreen (uint16 * &sav) _DX = sav[2]; _AH = 0x02; Video(); // set cursor - farfree(sav); + free(sav); sav = NULL; + */ } @@ -318,11 +327,12 @@ extern "C" void TimerProc (void) */ -void interrupt ENGINE::NewTimer (...) +void ENGINE::NewTimer (...) { static SPRITE * spr; static uint8 run = 0, cntr1 = TMR_RATE1, cntr2 = TMR_RATE2; - + // TODO Timer ASM + /* ___1152_Hz___: SNDMIDIPlay(); @@ -379,6 +389,8 @@ void interrupt ENGINE::NewTimer (...) asm mov sp,oldSP -- run; } + + */ } @@ -591,7 +603,7 @@ SPRITE * SPRITE::Expand (void) if ((Ext = new SPREXT) == NULL) DROP("No core", NULL); if (*File) { - static char * Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; + static const char * Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; char line[LINE_MAX], fname[MAXPATH]; BMP_PTR * shplist = new BMP_PTR [ShpCnt+1]; SEQ * seq = NULL; @@ -615,7 +627,7 @@ SPRITE * SPRITE::Expand (void) VGA::Exit("Bad SPR", fname); } - while ((len = sprf.Read(line)) != 0) + while ((len = sprf.Read((uint8*)line)) != 0) { ++ lcnt; if (len && line[len-1] == '\n') line[-- len] = '\0'; @@ -624,11 +636,16 @@ SPRITE * SPRITE::Expand (void) switch (TakeEnum(Comd, strtok(line, " =\t"))) { case 0 : // Name + { SetName(strtok(NULL, "")); break; + } case 1 : // Phase + { shplist[shpcnt ++] = new BITMAP(strtok(NULL, " \t,;/")); break; + } case 2 : // Seq + { seq = (SEQ *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); if (seq == NULL) VGA::Exit("No core", fname); @@ -646,7 +663,9 @@ SPRITE * SPRITE::Expand (void) s->Dy = atoi(strtok(NULL, " \t,;/")); s->Dly = atoi(strtok(NULL, " \t,;/")); break; + } case 3 : // Near + { if (NearPtr != NO_PTR) { nea = (SNAIL::COM *) realloc(nea, (neacnt + 1) * sizeof(*nea)); @@ -661,8 +680,10 @@ SPRITE * SPRITE::Expand (void) c->Ptr = NULL; } } + } break; case 4 : // Take + { if (TakePtr != NO_PTR) { tak = (SNAIL::COM *) realloc(tak, (takcnt + 1) * sizeof(*tak)); @@ -678,6 +699,7 @@ SPRITE * SPRITE::Expand (void) } } break; + } } } } @@ -693,10 +715,10 @@ SPRITE * SPRITE::Expand (void) SetSeq(seq); } else SetSeq((ShpCnt == 1) ? Seq1 : Seq2); - disable(); + //disable(); // disable interupt SetShapeList(shplist); - enable(); + //enable(); // enable interupt if (nea) nea[neacnt-1].Ptr = Ext->Near = nea; else NearPtr = NO_PTR; if (tak) tak[takcnt-1].Ptr = Ext->Take = tak; else TakePtr = NO_PTR; } @@ -807,7 +829,7 @@ void SPRITE::KillXlat (void) switch (MemType(m)) { case NEAR_MEM : delete[] (uint8 *) m; break; - case FAR_MEM : farfree(m); break; + case FAR_MEM : free(m); break; } for (b = Ext->ShpList; *b; b ++) (*b)->M = NULL; Flags.Xlat = false; @@ -863,7 +885,7 @@ void SPRITE::Center (void) void SPRITE::Show (void) { register SPREXT * e; - asm cli // critic section... + // asm cli // critic section... e = Ext; e->x0 = e->x1; e->y0 = e->y1; @@ -871,7 +893,7 @@ void SPRITE::Show (void) e->x1 = X; e->y1 = Y; e->b1 = Shp(); - asm sti // ...done! +// asm sti // ...done! if (! Flags.Hide) { if (Flags.Xlat) e->b1->XShow(e->x1, e->y1); @@ -919,8 +941,9 @@ BMP_PTR SPRITE::Ghost (void) bmp->W = e->b1->W; bmp->H = e->b1->H; if ((bmp->B = farnew(HideDesc, bmp->H)) == NULL) VGA::Exit("No Core"); - bmp->V = (uint8 *) _fmemcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); - bmp->M = (uint8 *) MK_FP(e->y1, e->x1); + bmp->V = (uint8 *) memcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); + // TODO offset correctly in the surface using y1 pitch and x1 and not via offset segment + //bmp->M = (uint8 *) MK_FP(e->y1, e->x1); return bmp; } return NULL; @@ -1095,11 +1118,16 @@ DAC * VGA::NewColors = NULL; bool VGA::SetPal = false; int VGA::Mono = 0; QUEUE VGA::ShowQ = true, VGA::SpareQ = false; + +// TODO: Was direct mapping to VGA buffers.. need to create scummvm surfaces for that +uint8 * VGA::Page[4] = { 0, 0, 0, 0 }; + +/* uint8 * VGA::Page[4] = { (uint8 *) MK_FP(SCR_SEG, 0x0000), (uint8 *) MK_FP(SCR_SEG, 0x4000), (uint8 *) MK_FP(SCR_SEG, 0x8000), (uint8 *) MK_FP(SCR_SEG, 0xC000) }; - +*/ @@ -1114,13 +1142,16 @@ VGA::VGA (int mode) char * txt = Text[i]; if (txt) { - puts(txt); - #ifndef DEBUG +// puts(txt); + warning(txt); + #ifndef DEBUG std = false; #endif } } - if (std) puts(Copr); + if (std) +// puts(Copr); + warning(Copr); SetStatAdr(); if (StatAdr != VGAST1_) ++ Mono; if (IsVga()) @@ -1146,33 +1177,27 @@ VGA::~VGA (void) Mono = 0; if (IsVga()) { + Common::String buffer = ""; Clear(); SetMode(OldMode); SetColors(); RestoreScreen(OldScreen); Sunrise(OldColors); - if (OldColors) farfree(OldColors); - if (NewColors) farfree(NewColors); - if (Msg) fputs(Msg, stderr); + if (OldColors) free(OldColors); + if (NewColors) free(NewColors); + if (Msg) + buffer = Common::String(Msg); if (Nam) - { - fputs(" [", stderr); - fputs(Nam, stderr); - fputc(']', stderr); - } - if (Msg || Nam) fputc('\n', stderr); - #ifdef REPORT - fputs(Report, stderr); - #endif + buffer = buffer + " [" + Nam + "]"; + + warning(buffer.c_str()); } } - - - void VGA::SetStatAdr (void) { + /* TODO SetStatADR ASM asm mov dx,VGAMIr_ asm in al,dx asm test al,1 // CGA addressing mode flag @@ -1181,6 +1206,7 @@ void VGA::SetStatAdr (void) asm xor al,0x60 // MDA addressing set_mode_adr: StatAdr = _AX; + */ } @@ -1191,6 +1217,8 @@ void VGA::SetStatAdr (void) #pragma argsused void VGA::WaitVR (bool on) { + // TODO Wait vertical retrace ASM +/* _DX = StatAdr; _AH = (on) ? 0x00 : 0x08; @@ -1203,6 +1231,7 @@ void VGA::WaitVR (bool on) asm jnz wait asm xor ah,0x08 asm loop wait + */ } @@ -1212,6 +1241,7 @@ void VGA::WaitVR (bool on) void VGA::Setup (VgaRegBlk * vrb) { +/* TODO VGA setup WaitVR(); // *--LOOK!--* resets VGAATR logic asm cld asm mov si, vrb // take address of parameter table @@ -1248,6 +1278,7 @@ void VGA::Setup (VgaRegBlk * vrb) asm jmp write // continue standard routine xit: + */ } @@ -1257,6 +1288,8 @@ void VGA::Setup (VgaRegBlk * vrb) int VGA::SetMode (int mode) { + /* TODO VGA Set Mode + Clear(); // get current mode asm mov ah,0x0F @@ -1275,6 +1308,8 @@ int VGA::SetMode (int mode) // return previous mode asm pop ax return _AX; + */ + return 0; } @@ -1284,6 +1319,7 @@ int VGA::SetMode (int mode) void VGA::GetColors (DAC * tab) { + /* TODO GetColors ASM asm cld asm les di,tab // color table asm mov dx,0x3C7 // PEL address read mode register @@ -1300,6 +1336,8 @@ void VGA::GetColors (DAC * tab) sto: asm stosb // store 1 color asm loop gc // next one? + + */ } @@ -1307,6 +1345,9 @@ void VGA::GetColors (DAC * tab) void VGA::SetColors (DAC * tab, int lum) { + + /* TODO SetColors + DAC * des = NewColors; asm push ds @@ -1350,6 +1391,7 @@ void VGA::SetColors (DAC * tab, int lum) asm cmp di,cx asm jb mono } + */ SetPal = true; } @@ -1360,7 +1402,7 @@ void VGA::SetColors (DAC * tab, int lum) void VGA::SetColors (void) { - _fmemset(NewColors, 0, PAL_SIZ); + memset(NewColors, 0, PAL_SIZ); UpdateColors(); } @@ -1422,6 +1464,7 @@ void VGA::Show (void) void VGA::UpdateColors (void) { + /* TODO UpdateColors ASM DAC * tab = NewColors; asm push ds @@ -1445,6 +1488,7 @@ void VGA::UpdateColors (void) asm pop ds + */ } @@ -1455,6 +1499,8 @@ void VGA::UpdateColors (void) void VGA::Update (void) { + // TODO VGA Update + /* uint8 * p = Page[1]; Page[1] = Page[0]; Page[0] = p; @@ -1466,7 +1512,7 @@ void VGA::Update (void) asm dec al asm mov ah,byte ptr p+1 asm out dx,ax - +*/ if (! SpeedTest) WaitVR(); if (SetPal) @@ -1485,6 +1531,7 @@ void VGA::Update (void) void VGA::Clear (uint8 color) { + /* TODO Clear ASM uint8 * a = (uint8 *) MK_FP(SCR_SEG, 0); asm mov dx,VGASEQ_ @@ -1497,6 +1544,7 @@ void VGA::Clear (uint8 color) asm mov al,color asm rep stosb asm stosb + */ } @@ -1506,6 +1554,7 @@ void VGA::Clear (uint8 color) void VGA::CopyPage (uint16 d, uint16 s) { + /* TODO CopyPage uint8 * S = Page[s & 3], * D = Page[d & 3]; asm mov dx,VGAGRA_ @@ -1536,6 +1585,7 @@ void VGA::CopyPage (uint16 d, uint16 s) asm pop dx asm pop ax asm out dx,al // end of copy mode + */ } @@ -1546,13 +1596,17 @@ void VGA::CopyPage (uint16 d, uint16 s) void VGA::Exit (const char * txt, const char * name) { + // TODO Properly exit + /* Msg = txt; Nam = name; - #ifdef REPORT + + #ifdef REPORT wtom(coreleft(), Report + NREP, 10, 5); dwtom(farcoreleft(), Report + FREP, 10, 6); #endif exit(0); + */ } @@ -1573,6 +1627,8 @@ void VGA::Exit (int tref, const char * name) void BITMAP::XShow (int x, int y) { + // TODO XShow ASM + /* uint8 rmsk = x % 4, mask = 1 << rmsk, * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; @@ -1650,6 +1706,8 @@ void BITMAP::XShow (int x, int y) asm pop ds asm pop si asm pop bx + + */ } @@ -1659,6 +1717,9 @@ void BITMAP::XShow (int x, int y) void BITMAP::Show (int x, int y) { + + // TODO Show ASM + /* uint8 mask = 1 << (x & 3), * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); uint8 * v = V; @@ -1722,6 +1783,7 @@ void BITMAP::Show (int x, int y) asm cmp ah,mask asm jne plane asm pop ds + */ } @@ -1730,6 +1792,8 @@ void BITMAP::Show (int x, int y) void BITMAP::Hide (int x, int y) { + // TODO Bitmap Hide ASM + /* uint8 * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; uint16 d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); HideDesc * b = B; @@ -1790,6 +1854,7 @@ void BITMAP::Hide (int x, int y) asm pop ds asm pop si // asm pop bx +*/ } } // End of namespace CGE diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index e5c34d238f1..40dfc41a124 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -325,7 +325,7 @@ uint8 Closest (CBLK * pal, CBLK x) char * NumStr (char * str, int num); - void Video (void); + //static void Video (void); uint16 * SaveScreen (void); void RestoreScreen (uint16 * &sav); SPRITE * SpriteAt (int x, int y); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 81788685784..46bb45e9c9c 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -28,7 +28,7 @@ #include "cge/vmenu.h" #include "cge/mouse.h" #include -#include +//#include namespace CGE { @@ -51,9 +51,9 @@ MENU_BAR::MENU_BAR (uint16 w) int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h; uint8 * p = farnew(uint8, i), * p1, * p2; - _fmemset(p+w, TRANS, i-2*w); - _fmemset(p, MB_LT, w); - _fmemset(p+i-w, MB_RB, w); + memset(p+w, TRANS, i-2*w); + memset(p, MB_LT, w); + memset(p+i-w, MB_RB, w); p1 = p; p2 = p+i-1; for (i = 0; i < h; i ++) @@ -89,7 +89,7 @@ char * VMGather (CHOICE * list) len += strlen(cp->Text); ++ h; } - vmgt = new uint8[len+h]; + vmgt = new char[len+h]; if (vmgt) { *vmgt = '\0'; diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 9f4391cc9a9..40490f2271d 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -28,6 +28,7 @@ #include "cge/vol.h" //#include #include "common/system.h" +#include "common/str.h" #include #include #include @@ -41,7 +42,10 @@ namespace CGE { #ifndef DROP_H - #define DROP(m,n) { printf("%s [%s]\n", (m), (n)); _exit(1); } + // TODO Replace printf by scummvm equivalent + + #define DROP(m,n) { } + //#define DROP(m,n) { printf("%s [%s]\n", (m), (n)); _exit(1); } #endif @@ -66,7 +70,7 @@ VFILE::VFILE (const char * name, IOMODE mode) { if (Dat.File.Error || Cat.Error) DROP("Bad volume data", NULL); BT_KEYPACK * kp = Cat.Find(name); - if (_fstricmp(kp->Key, name) != 0) Error = ENOFILE; + if (scumm_stricmp(kp->Key, name) != 0) Error = 1; EndMark = (BufMark = BegMark = kp->Mark) + kp->Size; } #ifdef VOL_UPD @@ -89,7 +93,7 @@ VFILE::~VFILE (void) bool VFILE::Exist (const char * name) { - return _fstricmp(Cat.Find(name)->Key, name) == 0; + return scumm_stricmp(Cat.Find(name)->Key, name) == 0; } diff --git a/engines/cge/vol.h b/engines/cge/vol.h index b63b08e7a18..421bd7593cd 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -54,7 +54,7 @@ namespace CGE { class DAT { - friend VFILE; + friend class VFILE; static VOLBASE File; public: static bool Append (uint8 * buf, uint16 len); diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 0d1408ccf68..a8da4f9e722 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -135,6 +135,7 @@ extern CKID DATA; DATACK * LoadWave (XFILE * file, EMM * emm = NULL); -// End of namespace CGE +} // End of namespace CGE + #endif From 92076d464148d2d6ecab544076bc10718a463c7b Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 11 Jun 2011 23:27:27 +0200 Subject: [PATCH 010/276] CGE: Remove DROP() macro --- engines/cge/bitmap.cpp | 31 ++++++++++++------------------- engines/cge/btfile.cpp | 18 ++---------------- engines/cge/cfile.cpp | 20 ++++---------------- engines/cge/drop.h | 28 ---------------------------- engines/cge/jbw.h | 2 -- engines/cge/snail.cpp | 4 ++-- engines/cge/sound.cpp | 12 ------------ engines/cge/talk.cpp | 6 +++--- engines/cge/vga13h.cpp | 3 ++- engines/cge/vga13h.h | 2 +- engines/cge/vol.cpp | 18 ++---------------- 11 files changed, 28 insertions(+), 116 deletions(-) delete mode 100644 engines/cge/drop.h diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 10f19029d64..1201b84fc67 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -33,17 +33,6 @@ #include "cge/vol.h" #endif - -#ifndef DROP_H -// TODO replace printf by scummvm equivalent -#define DROP(m,n) {} -//#define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } -#endif - - -//#include -//#include -//#include #include #include "cge/cfile.h" #include "common/system.h" @@ -73,7 +62,7 @@ BITMAP::BITMAP (const char * fname, bool rem) PIC_FILE file(pat); if (file.Error == 0) if (! VBMLoad(&file)) - DROP("Bad VBM", fname); + error("Bad VBM [%s]", fname); } else #endif @@ -92,10 +81,11 @@ BITMAP::BITMAP (const char * fname, bool rem) M = NULL; } } - else DROP("Bad BMP", fname); + else + error("Bad BMP [%s]", fname); } #else - DROP("Bad VBM", fname); + error("Bad VBM [%s]", fname); #endif } } @@ -127,7 +117,8 @@ BITMAP::BITMAP (uint16 w, uint16 h, uint8 fill) uint16 psiz = H * lsiz; // - last gape, but + plane trailer uint8 * v = new uint8[4 * psiz // the same for 4 planes + H * sizeof(*B)]; // + room for wash table - if (v == NULL) DROP("No core", NULL); + if (v == NULL) + error("No core"); * (uint16 *) v = CPY | dsiz; // data chunk hader memset(v+2, fill, dsiz); // data bytes @@ -160,7 +151,8 @@ BITMAP::BITMAP (const BITMAP& bmp) uint16 vsiz = (uint8*)(bmp.B) - (uint8*)(v0); uint16 siz = vsiz + H * sizeof(HideDesc); uint8 * v1 = farnew(uint8, siz); - if (v1 == NULL) DROP("No core", NULL); + if (v1 == NULL) + error("No core"); memcpy(v1, v0, siz); B = (HideDesc *) ((V = v1) + vsiz); } @@ -198,7 +190,8 @@ BITMAP& BITMAP::operator = (const BITMAP& bmp) uint16 vsiz = (uint8*)bmp.B - (uint8*)v0; uint16 siz = vsiz + H * sizeof(HideDesc); uint8 * v1 = farnew(uint8, siz); - if (v1 == NULL) DROP("No core", NULL); + if (v1 == NULL) + error("No core"); memcpy(v1, v0, siz); B = (HideDesc *) ((V = v1) + vsiz); } @@ -337,7 +330,7 @@ BMP_PTR BITMAP::Code (void) V = farnew(uint8, sizV + H * sizeof(*B)); if (! V) { - DROP("No core", NULL); + error("No core"); } B = (HideDesc *) (V + sizV); } @@ -442,7 +435,7 @@ bool BITMAP::VBMSave (XFILE * f) bool BITMAP::VBMLoad (XFILE * f) { - uint16 p, n; + uint16 p = 0, n = 0; if (f->Error == 0) f->Read((uint8 *)&p, sizeof(p)); if (f->Error == 0) f->Read((uint8 *)&n, sizeof(n)); if (f->Error == 0) f->Read((uint8 *)&W, sizeof(W)); diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 1851068e2d3..7c61157ebae 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -31,23 +31,8 @@ #include "common/str.h" #include - - -#ifdef DROP_H - #include "cge/drop.h" -#else - #include - #include -#endif - namespace CGE { -#ifndef DROP_H - // TODO replace printf by scummvm equivalent -#define DROP(m,n) - //#define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } -#endif - #ifndef BT_SIZE #define BT_SIZE K(1) #endif @@ -70,7 +55,8 @@ BTFILE::BTFILE (const char * name, IOMODE mode, CRYPT * crpt) Buff[i].PgNo = BT_NONE; Buff[i].Indx = -1; Buff[i].Updt = FALSE; - if (Buff[i].Page == NULL) DROP("No core", NULL); + if (Buff[i].Page == NULL) + error("No core"); } } diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 4d555c979d3..1a23c3d0f98 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -29,24 +29,10 @@ #include #include #include -//#include #include "common/system.h" -#ifdef DROP_H - #include "cge/drop.h" -#else - #include - #include -#endif - namespace CGE { -#ifndef DROP_H - //TODO Replace by scummvm printf -#define DROP(m,n) {} - //#define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } -#endif - IOBUF::IOBUF (IOMODE mode, CRYPT * crpt) : IOHAND(mode, crpt), BufMark(0), @@ -54,7 +40,8 @@ IOBUF::IOBUF (IOMODE mode, CRYPT * crpt) Lim(0) { Buff = farnew(uint8, IOBUF_SIZE); - if (Buff == NULL) DROP("No core for I/O", NULL); + if (Buff == NULL) + error("No core for I/O"); } @@ -72,7 +59,8 @@ IOBUF::IOBUF (const char * name, IOMODE mode, CRYPT * crpt) Lim(0) { Buff = farnew(uint8, IOBUF_SIZE); - if (Buff == NULL) DROP("No core for I/O", name); + if (Buff == NULL) + error("No core for I/O [%s]", name); } diff --git a/engines/cge/drop.h b/engines/cge/drop.h deleted file mode 100644 index bdd08b6810f..00000000000 --- a/engines/cge/drop.h +++ /dev/null @@ -1,28 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/vga13h.h" diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 8f6e0ea44e3..bb01017d00f 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -36,8 +36,6 @@ namespace CGE { #define INI_FILE VFILE #define PIC_FILE VFILE #define BMP_MODE 0 -#define DROP {} // TODO error handling -#define DROP_H #define BEL 7 #define BS 8 diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 733acb2398d..c63ba824b46 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -82,8 +82,8 @@ static void SNGame (SPRITE * spr, int num) #define STAGES 8 #define DRESSED 3 static SPRITE * dup[3] = { NULL, NULL, NULL }; - int buref; - int Stage; + int buref = 0; + int Stage = 0; for (dup[0] = VGA::ShowQ.First(); dup[0]; dup[0] = dup[0]->Next) { diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 11385c12e39..d40789beeef 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -29,25 +29,13 @@ #include "cge/startup.h" #include "cge/sound.h" -#ifdef DROP_H - #include "cge/drop.h" -#else - #include - #include -#endif - #include "cge/text.h" #include "cge/cfile.h" #include "cge/vol.h" -//#include namespace CGE { -#ifndef DROP_H - #define DROP(m,n) { printf("%s [%s]\n", m, n); _exit(1); } -#endif - bool Music = true; FX Fx = 16; // must precede SOUND!! SOUND Sound; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index d305d1d27ea..851b96cf992 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -60,7 +60,8 @@ FONT::FONT (const char * name) Map = farnew(uint8, MAP_SIZ); Pos = farnew(uint16, POS_SIZ); Wid = farnew(uint8, WID_SIZ); - if (Map == NULL || Pos == NULL || Wid == NULL) DROP("No core", NULL); + if (Map == NULL || Pos == NULL || Wid == NULL) + error("No core"); MergeExt(Path, name, FONT_EXT); Load(); } @@ -180,7 +181,7 @@ void TALK::Update (const char * tx) { uint16 vmarg = (Mode) ? TEXT_VM : 0; uint16 hmarg = (Mode) ? TEXT_HM : 0; - uint16 mw, mh, ln = vmarg; + uint16 mw = 0, mh, ln = vmarg; const char * p; uint8 * m; @@ -188,7 +189,6 @@ void TALK::Update (const char * tx) { uint16 k = 2 * hmarg; mh = 2 * vmarg + FONT_HIG; - mw = 0; for (p = tx; *p; p ++) { if (*p == '|' || *p == '\n') diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 86b04bfe0c2..d95be1d94cd 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -600,7 +600,8 @@ SPRITE * SPRITE::Expand (void) { bool enbl = HEART::Enable; HEART::Enable = false; - if ((Ext = new SPREXT) == NULL) DROP("No core", NULL); + if ((Ext = new SPREXT) == NULL) + error("No core"); if (*File) { static const char * Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 40dfc41a124..0b9fa8596d7 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -295,7 +295,7 @@ template uint8 Closest (CBLK * pal, CBLK x) { #define f(col,lum) ((((uint16)(col))<<8)/lum) - uint16 i, dif = 0xFFFF, found; + uint16 i, dif = 0xFFFF, found = 0; uint16 L = x.R + x.G + x.B; if (! L) ++ L; uint16 R = f(x.R, L), G = f(x.G, L), B = f(x.B, L); for (i = 0; i < 256; i ++) diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 40490f2271d..9af2efe8f30 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -26,29 +26,14 @@ */ #include "cge/vol.h" -//#include #include "common/system.h" #include "common/str.h" #include #include #include -#ifdef DROP_H - #include "cge/drop.h" -#else - #include -#endif - namespace CGE { -#ifndef DROP_H - // TODO Replace printf by scummvm equivalent - - #define DROP(m,n) { } - //#define DROP(m,n) { printf("%s [%s]\n", (m), (n)); _exit(1); } -#endif - - #ifdef VOL_UPD BTFILE VFILE::Cat(CAT_NAME, UPD, CRP); VOLBASE DAT::File(DAT_NAME, UPD, CRP); @@ -68,7 +53,8 @@ VFILE::VFILE (const char * name, IOMODE mode) { if (mode == REA) { - if (Dat.File.Error || Cat.Error) DROP("Bad volume data", NULL); + if (Dat.File.Error || Cat.Error) + error("Bad volume data"); BT_KEYPACK * kp = Cat.Find(name); if (scumm_stricmp(kp->Key, name) != 0) Error = 1; EndMark = (BufMark = BegMark = kp->Mark) + kp->Size; From 3bef49c003a888b935dc2aeaf2aa00e66249e71c Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 12 Jun 2011 01:13:44 +0200 Subject: [PATCH 011/276] CGE: Suppress VGA::Exit, some cleanup, add one missing source --- engines/cge/cge_main.cpp | 56 ++++++++++++------------ engines/cge/general.h | 4 +- engines/cge/module.mk | 1 + engines/cge/stdpal.cpp | 92 ++++++++++++++++++++++++++++++++++++++++ engines/cge/talk.cpp | 3 +- engines/cge/vga13h.cpp | 66 ++++++++-------------------- engines/cge/vga13h.h | 2 - 7 files changed, 142 insertions(+), 82 deletions(-) create mode 100644 engines/cge/stdpal.cpp diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index ebf3f3f9fd4..4c3611650c6 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -44,15 +44,12 @@ #include "cge/gettext.h" #include "cge/mixer.h" #include "cge/cge_main.h" -//#include #include #include #include #include #include -//#include #include -//#include #include #include "common/str.h" @@ -191,7 +188,7 @@ uint8 & CLUSTER::Cell (void) bool CLUSTER::Protected (void) { if (A == Barriers[Now].Vert || B == Barriers[Now].Horz) return true; - // TODO AsM + warning("STUB: CLUSTER::Protected()"); /* _DX = (MAP_ZCNT << 8) + MAP_XCNT; _BX = (uint16) this; @@ -291,12 +288,14 @@ static void LoadGame (XFILE& file, bool tiny = false) for (st = SavTab; st->Ptr; st ++) { - if (file.Error) VGA::Exit("Bad SVG"); + if (file.Error) + error("Bad SVG"); file.Read((uint8 *) ((tiny || st->Flg) ? st->Ptr : &i), st->Len); } file.Read((uint8 *) &i, sizeof(i)); - if (i != SVGCHKSUM) VGA::Exit(BADSVG_TEXT); + if (i != SVGCHKSUM) + error(Text[BADSVG_TEXT]); if (STARTUP::Core < CORE_HIG) Music = false; if (STARTUP::SoundOk == 1 && STARTUP::Mode == 0) { @@ -316,7 +315,8 @@ static void LoadGame (XFILE& file, bool tiny = false) S.Prev = S.Next = NULL; spr = (scumm_stricmp(S.File+2, "MUCHA") == 0) ? new FLY(NULL) : new SPRITE(NULL); - if (spr == NULL) VGA::Exit("No core"); + if (spr == NULL) + error("No core"); *spr = S; VGA::SpareQ.Append(spr); } @@ -360,7 +360,8 @@ static void SaveGame (XFILE& file) for (st = SavTab; st->Ptr; st ++) { - if (file.Error) VGA::Exit("Bad SVG"); + if (file.Error) + error("Bad SVG"); file.Write((uint8 *) st->Ptr, st->Len); } @@ -585,7 +586,7 @@ void WALK::Park (void) void WALK::FindWay (CLUSTER c) { - // TODO : Find1Way in ASM + warning("STUB: Find1Way"); /* bool Find1Way(void); extern uint16 Target; @@ -845,6 +846,7 @@ static void PostMiniStep (int stp) static int recent = -2; //TODO Change the SNPOST message send to a special way to send function pointer //if (MiniCave && stp != recent) SNPOST_(SNEXEC, -1, recent = stp, (void *)&MiniStep); + warning("STUB: PostMiniStep()"); } @@ -1021,6 +1023,7 @@ void SwitchCave (int cav) SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint //TODO Change the SNPOST message send to a special way to send function pointer //SNPOST(SNEXEC, -1, 0, (void *)&QGame); // switch cave + warning("SwitchCave() - SNPOST"); } else { @@ -1043,6 +1046,7 @@ void SwitchCave (int cav) SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint //TODO Change the SNPOST message send to a special way to send function pointer //SNPOST(SNEXEC, 0, 0, (void *)&XCave); // switch cave + warning("SwitchCave() - SNPOST"); } } } @@ -1285,6 +1289,7 @@ static void SwitchMusic (void) SNPOST_(SNSEQ, 122, (Music = false), NULL); //TODO Change the SNPOST message send to a special way to send function pointer // SNPOST(SNEXEC, -1, 0, (void *)&SelectSound); + warning("SwitchMusic() - SNPOST"); } } else @@ -1699,9 +1704,8 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro if (INI_FILE::Exist(line)) // sprite description file exist { INI_FILE sprf(line); - if (sprf.Error) - { - VGA::Exit("Bad SPR", line); + if (sprf.Error) { + error("Bad SPR [%s]", line); } while ((len = sprf.Read((uint8*)line)) != 0) @@ -1710,9 +1714,8 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro if (len && line[len-1] == '\n') line[-- len] = '\0'; if (len == 0 || *line == '.') continue; - if ((i = TakeEnum(Comd, strtok(line, " =\t"))) < 0) - { - VGA::Exit(NumStr("Bad line ######", lcnt), fname); + if ((i = TakeEnum(Comd, strtok(line, " =\t"))) < 0) { + error("%s [%s]", NumStr("Bad line ######", lcnt), fname); } switch (i) @@ -1721,7 +1724,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro break; case 1 : // Type if ((type = TakeEnum(Type, strtok(NULL, " \t,;/"))) < 0) - VGA::Exit(NumStr("Bad line ######", lcnt), fname); + error("%s [%s]", NumStr("Bad line ######", lcnt), fname); break; case 2 : // Phase ++ shpcnt; @@ -1738,9 +1741,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro } } if (! shpcnt) - { - VGA::Exit("No shapes", fname); - } + error("No shapes [%s]", fname); } else // no sprite description: mono-shaped sprite with only .BMP file { @@ -1767,9 +1768,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro { w->Goto(col, row); if (Hero) - { - VGA::Exit("2nd HERO", fname); - } + error("2nd HERO [%s]", fname); Hero = w; } Sprite = w; @@ -1792,7 +1791,7 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro */ case 4 : // LISSAJOUS { - VGA::Exit("Bad type", fname); + error("Bad type [%s]", fname); /* LISSAJOUS * l = new LISSAJOUS(NULL); if (l) @@ -1895,9 +1894,7 @@ static void LoadScript (const char *fname) if (Sprite && BkG) Sprite->Flags.Back = true; } if (! ok) - { - VGA::Exit(NumStr("Bad INI line ######", lcnt), fname); - } + error("%s [%s]", NumStr("Bad INI line ######", lcnt), fname); } @@ -1982,7 +1979,7 @@ void LoadUser (void) Music = true; CFILE file = CFILE(SVG0NAME, WRI); SaveGame(file); - VGA::Exit("Ok", SVG0NAME); + error("Ok [%s]", SVG0NAME); } } LoadScript(ProgName(IN0_EXT)); @@ -2270,7 +2267,8 @@ void cge_main (void) //Debug( memset((void *) (-K(4)), 0, K(1)); ) memset(Barriers, 0xFF, sizeof(Barriers)); - if (! Mouse.Exist) VGA::Exit(NO_MOUSE_TEXT); + if (! Mouse.Exist) + error("%s", Text[NO_MOUSE_TEXT]); if (! SVG0FILE::Exist(SVG0NAME)) STARTUP::Mode = 2; Debug( DebugLine.Flags.Hide = true; ) @@ -2291,7 +2289,7 @@ void cge_main (void) if (FINIS) Movie("X03"); } else Vga.Sunset(); - VGA::Exit(EXIT_OK_TEXT+FINIS); + error("%s", Text[EXIT_OK_TEXT+FINIS]); } } // End of namespace CGE diff --git a/engines/cge/general.h b/engines/cge/general.h index 4633ba2d3ce..0d06d9b93d4 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -49,7 +49,7 @@ namespace CGE { -enum CPU { _8086, _80186, _80286, _80386, _80486 }; +//enum CPU { _8086, _80186, _80286, _80386, _80486 }; enum MEM_TYPE { BAD_MEM, EMS_MEM, NEAR_MEM, FAR_MEM }; enum ALLOC_MODE { FIRST_FIT, BEST_FIT, LAST_FIT }; enum IOMODE { REA, WRI, UPD }; @@ -244,7 +244,7 @@ CRYPT RCrypt; MEM_TYPE MemType (void *mem); unsigned FastRand (void); unsigned FastRand (unsigned s); -CPU Cpu (void); +//CPU Cpu (void); ALLOC_MODE SetAllocMode (ALLOC_MODE am); uint16 atow (const char * a); uint16 xtow (const char * x); diff --git a/engines/cge/module.mk b/engines/cge/module.mk index e028d7feb4a..a74eb1a469a 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -18,6 +18,7 @@ MODULE_OBJS := \ snail.o \ sound.o \ startup.o \ + stdpal.o \ talk.o \ text.o \ vga13h.o \ diff --git a/engines/cge/stdpal.cpp b/engines/cge/stdpal.cpp new file mode 100644 index 00000000000..8ceeddae3cc --- /dev/null +++ b/engines/cge/stdpal.cpp @@ -0,0 +1,92 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/general.h" + +namespace CGE { + + DAC StdPal[] = {// R G B + { 0, 60, 0}, // 198 + { 0, 104, 0}, // 199 + { 20, 172, 0}, // 200 + { 82, 82, 0}, // 201 + { 0, 132, 82}, // 202 + { 132, 173, 82}, // 203 + { 82, 0, 0}, // 204 + { 206, 0, 24}, // 205 + { 255, 33, 33}, // 206 + { 123, 41, 0}, // 207 + { 0, 41, 0}, // 208 + { 0, 0, 82}, // 209 + { 132, 0, 0}, // 210 + { 255, 0, 0}, // 211 + { 255, 66, 66}, // 212 + { 148, 66, 16}, // 213 + { 0, 82, 0}, // 214 + { 0, 0,132}, // 215 + { 173, 0, 0}, // 216 + { 255, 49, 0}, // 217 + { 255, 99, 99}, // 218 + { 181, 107, 49}, // 219 + { 0, 132, 0}, // 220 + { 0, 0,255}, // 221 + { 173, 41, 0}, // 222 + { 255, 82, 0}, // 223 + { 255, 132,132}, // 224 + { 214, 148, 74}, // 225 + { 41, 214, 0}, // 226 + { 0, 82,173}, // 227 + { 255, 214, 0}, // 228 + { 247, 132, 49}, // 229 + { 255, 165,165}, // 230 + { 239, 198,123}, // 231 + { 173, 214, 0}, // 232 + { 0, 132,214}, // 233 + { 57, 57, 57}, // 234 + { 247, 189, 74}, // 235 + { 255, 198,198}, // 236 + { 255, 239,173}, // 237 + { 214, 255,173}, // 238 + { 82, 173,255}, // 239 + { 107, 107,107}, // 240 + { 247, 222, 99}, // 241 + { 255, 0,255}, // 242 + { 255, 132,255}, // 243 + { 132, 132,173}, // 244 + { 148, 247,255}, // 245 + { 148, 148,148}, // 246 + { 82, 0, 82}, // 247 + { 112, 68,112}, // 248 + { 176, 88,144}, // 249 + { 214, 132,173}, // 250 + { 206, 247,255}, // 251 + { 198, 198,198}, // 252 + { 0, 214,255}, // 253 + { 96, 224,96 }, // 254 + { 255, 255,255}, // 255 + }; +} // End of namespace CGE diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 851b96cf992..9fd32ab7d27 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -245,7 +245,8 @@ BITMAP * TALK::Box (uint16 w, uint16 h) if (w < 8) w = 8; if (h < 8) h = 8; b = farnew(uint8, n = w * h); - if (! b) VGA::Exit("No core"); + if (! b) + error("No core"); memset(b, TEXT_BG, n); if (Mode) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d95be1d94cd..6e08a9790d1 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -585,7 +585,8 @@ void SPRITE::SetName (char * n) if (n) { if ((Ext->Name = new char[strlen(n)+1]) != NULL) strcpy(Ext->Name, n); - else VGA::Exit("No core", n); + else + error("No core [%s]", n); } } } @@ -624,9 +625,7 @@ SPRITE * SPRITE::Expand (void) { INI_FILE sprf(fname); if (! OK(sprf)) - { - VGA::Exit("Bad SPR", fname); - } + error("Bad SPR [%s]", fname); while ((len = sprf.Read((uint8*)line)) != 0) { @@ -649,7 +648,7 @@ SPRITE * SPRITE::Expand (void) { seq = (SEQ *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); if (seq == NULL) - VGA::Exit("No core", fname); + error("No core [%s]", fname); SEQ * s = &seq[seqcnt ++]; s->Now = atoi(strtok(NULL, " \t,;/")); if (s->Now > maxnow) maxnow = s->Now; @@ -670,12 +669,13 @@ SPRITE * SPRITE::Expand (void) if (NearPtr != NO_PTR) { nea = (SNAIL::COM *) realloc(nea, (neacnt + 1) * sizeof(*nea)); - if (nea == NULL) VGA::Exit("No core", fname); + if (nea == NULL) + error("No core [%s]", fname); else { SNAIL::COM * c = &nea[neacnt ++]; if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) - VGA::Exit(NumStr("Bad NEAR in ######", lcnt), fname); + error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), fname); c->Ref = atoi(strtok(NULL, " \t,;/")); c->Val = atoi(strtok(NULL, " \t,;/")); c->Ptr = NULL; @@ -688,12 +688,13 @@ SPRITE * SPRITE::Expand (void) if (TakePtr != NO_PTR) { tak = (SNAIL::COM *) realloc(tak, (takcnt + 1) * sizeof(*tak)); - if (tak == NULL) VGA::Exit("No core", fname); + if (tak == NULL) + error("No core [%s]", fname); else { SNAIL::COM * c = &tak[takcnt ++]; if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) - VGA::Exit(NumStr("Bad NEAR in ######", lcnt), fname); + error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), fname); c->Ref = atoi(strtok(NULL, " \t,;/")); c->Val = atoi(strtok(NULL, " \t,;/")); c->Ptr = NULL; @@ -711,8 +712,10 @@ SPRITE * SPRITE::Expand (void) shplist[shpcnt] = NULL; if (seq) { - if (maxnow >= shpcnt) VGA::Exit("Bad PHASE in SEQ", fname); - if (maxnxt >= seqcnt) VGA::Exit("Bad JUMP in SEQ", fname); + if (maxnow >= shpcnt) + error("Bad PHASE in SEQ [%s]", fname); + if (maxnxt >= seqcnt) + error("Bad JUMP in SEQ [%s]", fname); SetSeq(seq); } else SetSeq((ShpCnt == 1) ? Seq1 : Seq2); @@ -938,10 +941,12 @@ BMP_PTR SPRITE::Ghost (void) if (e->b1) { BMP_PTR bmp = new BITMAP(0, 0, (uint8 *)NULL); - if (bmp == NULL) VGA::Exit("No core"); + if (bmp == NULL) + error("No core"); bmp->W = e->b1->W; bmp->H = e->b1->H; - if ((bmp->B = farnew(HideDesc, bmp->H)) == NULL) VGA::Exit("No Core"); + if ((bmp->B = farnew(HideDesc, bmp->H)) == NULL) + error("No Core"); bmp->V = (uint8 *) memcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); // TODO offset correctly in the surface using y1 pitch and x1 and not via offset segment //bmp->M = (uint8 *) MK_FP(e->y1, e->x1); @@ -1589,43 +1594,8 @@ void VGA::CopyPage (uint16 d, uint16 s) */ } - - - - - - -void VGA::Exit (const char * txt, const char * name) -{ - // TODO Properly exit - /* - Msg = txt; - Nam = name; - - #ifdef REPORT - wtom(coreleft(), Report + NREP, 10, 5); - dwtom(farcoreleft(), Report + FREP, 10, 6); - #endif - exit(0); - */ -} - - - - -void VGA::Exit (int tref, const char * name) -{ - Exit(Text[tref], name); -} - - - - //-------------------------------------------------------------------------- - - - void BITMAP::XShow (int x, int y) { // TODO XShow ASM diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 0b9fa8596d7..f1a4b498c40 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -274,8 +274,6 @@ public: static void GetColors (DAC * tab); static void SetColors (DAC * tab, int lum); static void Clear (uint8 color = 0); - static void Exit (const char * txt = NULL, const char * name = NULL); - static void Exit (int tref, const char * name = NULL); static void CopyPage (uint16 d, uint16 s = 3); static void Sunrise (DAC * tab); static void Sunset (void); From b1df7ca7340ccf43817894eedcaea6d211eeb6dd Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 12 Jun 2011 22:06:44 +0200 Subject: [PATCH 012/276] CGE: Add missing file, and STUB some missing functions in general.cpp --- engines/cge/cge_main.cpp | 3 +- engines/cge/ems.cpp | 240 +++++++++++++++++++++++++++ engines/cge/game.cpp | 2 +- engines/cge/general.cpp | 346 +++++++++++++++++++++++++++++++++++++++ engines/cge/general.h | 29 ++-- engines/cge/module.mk | 3 +- engines/cge/snddrv.h | 6 +- engines/cge/stdpal.cpp | 92 ----------- engines/cge/vga13h.cpp | 10 +- engines/cge/vol.cpp | 8 +- 10 files changed, 613 insertions(+), 126 deletions(-) create mode 100644 engines/cge/ems.cpp create mode 100644 engines/cge/general.cpp delete mode 100644 engines/cge/stdpal.cpp diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 4c3611650c6..9a2ce931f00 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -297,8 +297,7 @@ static void LoadGame (XFILE& file, bool tiny = false) if (i != SVGCHKSUM) error(Text[BADSVG_TEXT]); if (STARTUP::Core < CORE_HIG) Music = false; - if (STARTUP::SoundOk == 1 && STARTUP::Mode == 0) - { + if (STARTUP::SoundOk == 1 && STARTUP::Mode == 0) { SNDDrvInfo.VOL2.D = volume[0]; SNDDrvInfo.VOL2.M = volume[1]; SNDSetVolume(); diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp new file mode 100644 index 00000000000..abf118bda2b --- /dev/null +++ b/engines/cge/ems.cpp @@ -0,0 +1,240 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/general.h" + +namespace CGE { + +#define EMS_INT 0x67 +#define PAGE_MASK 0x3FFF +#define SIZ(n) ((n) ? ((long)n) : (0x10000L)) + + +enum EMM_FUN { GET_STATUS = 0x40, + GET_FRAME, + GET_SIZE, + OPEN_HANDLE, + MAP_PAGE, + CLOSE_HANDLE, + GET_VER, + SAVE_CONTEXT, + REST_CONTEXT, + GET_PAGES = 0x4B, + GET_HANDLES, + GET_INFO, + CONTROL }; + + +void *EMM::Frame = NULL; + + +EMM::EMM (long size): Han(-1), Top(0), Lim(0), List(NULL) { +/* + if (Test()) + { + asm mov ah,GET_FRAME // get EMS frame segment + asm int EMS_INT // do it! + asm or ah,ah // see status + asm jnz xit // abort on error + Frame = (void _seg *) _BX; // save frame segment + + if (size == 0) + { + asm mov ah,GET_SIZE // get EMS memory size + asm int EMS_INT // do it! + asm or ah,ah // see status + asm jnz xit // abort on error + asm or bx,bx // test page count + asm jz xit // abort if no free pages + // number of available pages in BX is ready to use by OPEN + } + else _BX = (uint16) ((size + PAGE_MASK) >> 14); + asm mov ah,OPEN_HANDLE // open EMM handle + asm int EMS_INT // do it! + asm or ah,ah // see status + asm jnz xit // abort on error + Han = _DX; + Lim = _BX; + Lim <<= 14; + _DX = Han; + asm mov ah,SAVE_CONTEXT // save mapping context + asm int EMS_INT // do it! + } + xit: +*/ + warning("STUB: EMM:EMM"); +} + + +EMM::~EMM(void) { +/* + Release(); + if (Han >= 0) + { + _DX = Han; + asm mov ah,REST_CONTEXT + asm int EMS_INT + asm mov ah,CLOSE_HANDLE + asm int EMS_INT + } +*/ + warning("STUB: EMM::~EMM"); +} + + + +bool EMM::Test(void) { +/* + static char e[] = "EMMXXXX0"; + + asm mov ax,0x3D40 + asm mov dx,offset e + asm int 0x21 + asm jc fail + + asm push ax + asm mov bx,ax + asm mov ax,0x4407 + asm int 0x21 + + asm pop bx + asm push ax + asm mov ax,0x3E00 + asm int 0x21 + asm pop ax + + asm cmp al,0x00 + asm je fail + + success: + return TRUE; + fail: + return FALSE; +*/ + warning("EMM::Test"); + return FALSE; +} + + +EMS * EMM::Alloc (uint16 siz) { +/* + long size = SIZ(siz), + top = Top; + + uint16 pgn = (uint16) (top >> 14), + cnt = (uint16) ((top + size + PAGE_MASK) >> 14) - pgn; + + if (cnt > 4) + { + top = (top + PAGE_MASK) & 0xFFFFC000L; + ++ pgn; + -- cnt; + } + + if (size <= Lim - top) + { + EMS * e = new EMS, * f; + + if (e) + { + Top = (e->Ptr = top) + (e->Siz = siz); + e->Emm = this; + + if (List) + { + for (f = List; f->Nxt; f = f->Nxt); + return (f->Nxt = e); // existing list: link to the end + } + else + { + return (List = e); // empty list: link to the head + } + } + } + fail: return NULL; +*/ + warning("STUB: EMM::Alloc"); + return NULL; +} + + +void EMM::Release (void) { + while (List) + { + EMS * e = List; + List = e->Nxt; + delete e; + } + Top = 0; +} + + +EMS::EMS (void) +: Ptr(0), Siz(0), Nxt(NULL) +{ +} + + +void * EMS::operator & () const +{ +/* + uint16 pgn = (uint16) (Ptr >> 14), + off = (uint16) Ptr & PAGE_MASK, + cnt = (uint16) ((Ptr + SIZ(Siz) + PAGE_MASK) >> 14) - pgn, + cmd = MAP_PAGE << 8; + + _DX = Emm->Han; // take EMM handle + asm dec cnt // prapare for deferred checking + asm or dx,dx // see if valid + asm jns more // negative handle = unavailable + + fail: return NULL; + + more: + asm mov ax,cmd // command + page frame index + asm mov bx,pgn // logical page number + asm int EMS_INT // do it! + asm or ah,ah // check error code + asm jnz fail // exit on error + asm inc cmd // advance page frame index + asm inc pgn // advance logical page number + asm cmp al,byte ptr cnt // all pages? + asm jb more + + return (void *) (EMM::Frame + (void *) off); +*/ + warning("STUB: EMS::operator &"); + return NULL; +} + + +uint16 EMS::Size (void) +{ + return Siz; +} + +} // End of namespace CGE diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index b6530323e4f..86e1324e0b5 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -92,7 +92,7 @@ FLY::FLY (BITMAP ** shpl) : SPRITE(shpl), Tx(0), Ty(0) { Step(new_random(2)); - Goto(L+new_random(R-L-W), T+new_random(B-T-H)); + Goto(L + new_random(R - L - W), T + new_random(B - T - H)); } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp new file mode 100644 index 00000000000..f023bb1e0fd --- /dev/null +++ b/engines/cge/general.cpp @@ -0,0 +1,346 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "cge/boot.h" +#include "cge/general.h" +#include "cge/snddrv.h" +#include "cge/wav.h" + +namespace CGE { + + DAC StdPal[] = {// R G B + { 0, 60, 0}, // 198 + { 0, 104, 0}, // 199 + { 20, 172, 0}, // 200 + { 82, 82, 0}, // 201 + { 0, 132, 82}, // 202 + { 132, 173, 82}, // 203 + { 82, 0, 0}, // 204 + { 206, 0, 24}, // 205 + { 255, 33, 33}, // 206 + { 123, 41, 0}, // 207 + { 0, 41, 0}, // 208 + { 0, 0, 82}, // 209 + { 132, 0, 0}, // 210 + { 255, 0, 0}, // 211 + { 255, 66, 66}, // 212 + { 148, 66, 16}, // 213 + { 0, 82, 0}, // 214 + { 0, 0,132}, // 215 + { 173, 0, 0}, // 216 + { 255, 49, 0}, // 217 + { 255, 99, 99}, // 218 + { 181, 107, 49}, // 219 + { 0, 132, 0}, // 220 + { 0, 0,255}, // 221 + { 173, 41, 0}, // 222 + { 255, 82, 0}, // 223 + { 255, 132,132}, // 224 + { 214, 148, 74}, // 225 + { 41, 214, 0}, // 226 + { 0, 82,173}, // 227 + { 255, 214, 0}, // 228 + { 247, 132, 49}, // 229 + { 255, 165,165}, // 230 + { 239, 198,123}, // 231 + { 173, 214, 0}, // 232 + { 0, 132,214}, // 233 + { 57, 57, 57}, // 234 + { 247, 189, 74}, // 235 + { 255, 198,198}, // 236 + { 255, 239,173}, // 237 + { 214, 255,173}, // 238 + { 82, 173,255}, // 239 + { 107, 107,107}, // 240 + { 247, 222, 99}, // 241 + { 255, 0,255}, // 242 + { 255, 132,255}, // 243 + { 132, 132,173}, // 244 + { 148, 247,255}, // 245 + { 148, 148,148}, // 246 + { 82, 0, 82}, // 247 + { 112, 68,112}, // 248 + { 176, 88,144}, // 249 + { 214, 132,173}, // 250 + { 206, 247,255}, // 251 + { 198, 198,198}, // 252 + { 0, 214,255}, // 253 + { 96, 224,96 }, // 254 + { 255, 255,255}, // 255 + }; + +EC void _fqsort (void *base, uint16 nelem, uint16 width, int (*fcmp)(const void*, const void*)) { + warning("STUB: _fqsort"); +} + +const char * ProgName (const char * ext) { + warning("STUB: ProgName"); + return NULL; +} + +char *MergeExt (char *buf, const char *nam, const char *ext) { +// char dr[MAXDRIVE], di[MAXDIR], na[MAXFILE], ex[MAXEXT]; +// fnmerge(buf, dr, di, na, (fnsplit(nam, dr, di, na, ex) & EXTENSION) ? ex : ext); +// return buf; + warning("STUB: MergeExt"); + return buf; +} + +char *ForceExt (char *buf, const char *nam, const char* ext) { +// char dr[MAXDRIVE], di[MAXDIR], na[MAXFILE], ex[MAXEXT]; +// fnsplit(nam, dr, di, na, ex); +// fnmerge(buf, dr, di, na, ext); +// return buf; + warning("STUB: ForceExt"); + return buf; +} + + +#define BUF ((uint8 *) buf) +static unsigned Seed = 1; + +unsigned FastRand (void) { return Seed = 257 * Seed + 817; } +unsigned FastRand (unsigned s) { return Seed = 257 * s + 817; } + +uint16 RCrypt (void * buf, uint16 siz, uint16 seed) { +/* + if (buf && siz) { + uint8 * q = BUF + (siz-1); + seed = FastRand(seed); + * (BUF ++) ^= seed; + while (buf < q) * (BUF ++) ^= FastRand(); + if (buf == q) * BUF ^= (seed = FastRand()); + } + return seed; +*/ + warning("STUB: RCrypt"); + return 0; +} + +uint16 XCrypt (void *buf, uint16 siz, uint16 seed) { +// for (uint16 i = 0; i < siz; i ++) +// *(BUF ++) ^= seed; + warning("STUB: XCrypt"); + return seed; +} + +uint16 atow (const char *a) { + uint16 w = 0; + if (a) + while (IsDigit(*a)) + w = (10 * w) + (*(a ++) & 0xF); + return w; +} + +uint16 xtow (const char *x) { + uint16 w = 0; + if (x) { + while (IsHxDig(*x)) { + register uint16 d = * (x ++); + if (d > '9') + d -= 'A' - ('9' + 1); + w = (w << 4) | (d & 0xF); + } + } + return w; +} + +char *wtom (uint16 val, char *str, int radix, int len) { + while (-- len >= 0) { + uint16 w = val % radix; + if (w > 9) w += ('A' - ('9'+1)); + str[len] = '0' + w; + val /= radix; + } + return str; +} + +IOHAND::IOHAND (IOMODE mode, CRYPT * crpt) +: XFILE(mode), Handle(-1), Crypt(crpt), Seed(SEED) +{ +} + +IOHAND::IOHAND (const char *name, IOMODE mode, CRYPT *crpt) +: XFILE(mode), Crypt(crpt), Seed(SEED) +{ +/* switch (mode) + { + case REA : Error = _dos_open(name, O_RDONLY | O_DENYNONE, &Handle); break; + case WRI : Error = _dos_creat(name, FA_ARCH, &Handle); break; + case UPD : Error = _dos_open(name, O_RDWR | O_DENYALL, &Handle); break; + } + if (Error) Handle = -1; +*/ + warning("STUB: IOHAND::IOHAND"); +} + +IOHAND::~IOHAND(void) { +/* + if (Handle != -1) + { + Error = _dos_close(Handle); + Handle = -1; + } +*/ + warning("STUB: IOHAND::~IOHAND"); +} + +uint16 IOHAND::Read(void *buf, uint16 len) { +/* + if (Mode == WRI || Handle < 0) return 0; + if (len) Error = _dos_read(Handle, buf, len, &len); + if (Crypt) Seed = Crypt(buf, len, Seed); + return len; +*/ + warning("STUB: IOHAND::Read"); + return 0; +} + +uint16 IOHAND::Write(void *buf, uint16 len) { +/* + if (len) { + if (Mode == REA || Handle < 0) return 0; + if (Crypt) Seed = Crypt(buf, len, Seed); + Error = _dos_write(Handle, buf, len, &len); + if (Crypt) Seed = Crypt(buf, len, Seed); //------$$$$$$$ + } + return len; +*/ + warning("STUB: IOHAND::Write"); + return 0; +} + +long IOHAND::Mark (void) +{ + return (Handle < 0) ? 0 : tell(Handle); +} + +long IOHAND::Seek (long pos) +{ + if (Handle < 0) return 0; + lseek(Handle, pos, SEEK_SET); + return tell(Handle); +} + +long IOHAND::Size (void) +{ + if (Handle < 0) return 0; + return filelength(Handle); +} + +bool IOHAND::Exist (const char * name) { + return access(name, 0) == 0; +} + +//#define EMS_ADR(a) (FP_SEG(a) > 0xA000) +//#define HNODE_OK(p) (heapchecknode(p)==4) + +MEM_TYPE MemType (void *mem) { +/* if (FP_SEG(mem) == _DS) { + if (heapchecknode((void *)mem)==4) + return NEAR_MEM; + } else { + if (FP_SEG(mem) > 0xA000) + return EMS_MEM; + else if (farheapchecknode(mem)==4) + return FAR_MEM; + } + return BAD_MEM; +*/ + warning("STUB: MemType"); + return FAR_MEM; +} + +bool IsVga() { + return true; +} + +EC void SNDInit() { + warning("STUB: SNDInit"); +} + +EC void SNDDone() { + warning("STUB: SNDDone"); +} + +EC void SNDSetVolume() { + warning("STUB: SNDSetVolume"); +} + +EC void SNDDigiStart(SMPINFO *PSmpInfo) { + warning("STUB: SNDDigitStart"); +} + +EC void SNDDigiStop(SMPINFO *PSmpInfo) { + warning("STUB: SNDDigiStop"); +} + +EC void SNDMIDIStart(uint8 *MIDFile) { + warning("STUB: SNDMIDIStart"); +} + +EC void SNDMIDIStop() { + warning("STUB: SNDMIDIStop"); +} + +DATACK *LoadWave(XFILE * file, EMM * emm) { + warning("STUB: LoadWave"); + return NULL; +} + +int TakeEnum(const char **tab, const char *txt) { + const char **e; + if (txt) + { + for (e = tab; *e; e ++) + { + if (scumm_stricmp(txt, *e) == 0) + { + return e - tab; + } + } + } + return -1; +} + +Boot *ReadBoot(int drive) { +/* + struct fatinfo fi; Boot *b; + getfat(drive+1, &fi); + if (fi.fi_sclus & 0x80) return NULL; + if ((b = malloc(fi.fi_bysec)) == NULL) return NULL; + // read boot sector + if (absread(drive, 1, 0L, b) == 0) return b; + free(b); + return NULL; +*/ + warning("STUB: ReadBoot"); + return NULL; +} + +} // End of namespace CGE + diff --git a/engines/cge/general.h b/engines/cge/general.h index 0d06d9b93d4..62919328ed9 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -64,8 +64,6 @@ extern Common::RandomSource randSrc; #define new_random(a) (randSrc.getRandomNumber(a)) - - class COUPLE { protected: @@ -238,39 +236,32 @@ public: CRYPT XCrypt; -CRYPT RXCrypt; CRYPT RCrypt; MEM_TYPE MemType (void *mem); -unsigned FastRand (void); -unsigned FastRand (unsigned s); -//CPU Cpu (void); -ALLOC_MODE SetAllocMode (ALLOC_MODE am); uint16 atow (const char * a); uint16 xtow (const char * x); char * wtom (uint16 val, char * str, int radix, int len); char * dwtom (uint32 val, char * str, int radix, int len); -char * DateTimeString (void); -void StdLog (const char *msg, const char *nam = NULL); -void StdLog (const char *msg, uint16 w); -void StdLog (const char *msg, uint32 d); int TakeEnum (const char ** tab, const char * txt); uint16 ChkSum (void *m, uint16 n); long Timer (void); -long TimerLimit (uint16 t); -bool TimerLimitGone (long t); char * MergeExt (char * buf, const char * nam, const char * ext); char * ForceExt (char * buf, const char * nam, const char * ext); -inline const char * ProgPath (void); -const char * ProgName (const char * ext = NULL); -int DriveFixed (unsigned drv); -int DriveRemote (unsigned drv); int DriveCD (unsigned drv); bool IsVga (void); -EC void _fqsort (void *base, uint16 nelem, uint16 width, - int (*fcmp)(const void*, const void*)); +// MISSING FUNCTIONS +EC void _fqsort (void *base, uint16 nelem, uint16 width, int (*fcmp)(const void*, const void*)); +const char *ProgName (const char *ext = NULL); +char *MergeExt (char *buf, const char *nam, const char *ext); +char *ForceExt (char *buf, const char *nam, const char *ext); +unsigned FastRand (void); +unsigned FastRand (unsigned s); +uint16 RCrypt (void * buf, uint16 siz, uint16 seed); +uint16 atow (const char *a); +uint16 xtow (const char *x); } // End of namespace CGE diff --git a/engines/cge/module.mk b/engines/cge/module.mk index a74eb1a469a..552cddb5002 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -10,7 +10,9 @@ MODULE_OBJS := \ config.o \ console.o \ detection.o \ + ems.o \ game.o \ + general.o \ gettext.o \ keybd.o \ mixer.o \ @@ -18,7 +20,6 @@ MODULE_OBJS := \ snail.o \ sound.o \ startup.o \ - stdpal.o \ talk.o \ text.o \ vga13h.o \ diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 8d29a807d7d..fc6c1aa143a 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -94,13 +94,13 @@ struct SMPINFO // * Data * // ****************************************************** // driver info -extern DRVINFO SNDDrvInfo; +extern DRVINFO SNDDrvInfo; // midi player flag (1 means we are playing) -extern uint16 MIDIPlayFlag; +extern uint16 MIDIPlayFlag; // midi song end flag (1 means we have crossed end mark) -extern uint16 MIDIEndFlag; +extern uint16 MIDIEndFlag; // ****************************************************** // * Driver Code * diff --git a/engines/cge/stdpal.cpp b/engines/cge/stdpal.cpp deleted file mode 100644 index 8ceeddae3cc..00000000000 --- a/engines/cge/stdpal.cpp +++ /dev/null @@ -1,92 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/general.h" - -namespace CGE { - - DAC StdPal[] = {// R G B - { 0, 60, 0}, // 198 - { 0, 104, 0}, // 199 - { 20, 172, 0}, // 200 - { 82, 82, 0}, // 201 - { 0, 132, 82}, // 202 - { 132, 173, 82}, // 203 - { 82, 0, 0}, // 204 - { 206, 0, 24}, // 205 - { 255, 33, 33}, // 206 - { 123, 41, 0}, // 207 - { 0, 41, 0}, // 208 - { 0, 0, 82}, // 209 - { 132, 0, 0}, // 210 - { 255, 0, 0}, // 211 - { 255, 66, 66}, // 212 - { 148, 66, 16}, // 213 - { 0, 82, 0}, // 214 - { 0, 0,132}, // 215 - { 173, 0, 0}, // 216 - { 255, 49, 0}, // 217 - { 255, 99, 99}, // 218 - { 181, 107, 49}, // 219 - { 0, 132, 0}, // 220 - { 0, 0,255}, // 221 - { 173, 41, 0}, // 222 - { 255, 82, 0}, // 223 - { 255, 132,132}, // 224 - { 214, 148, 74}, // 225 - { 41, 214, 0}, // 226 - { 0, 82,173}, // 227 - { 255, 214, 0}, // 228 - { 247, 132, 49}, // 229 - { 255, 165,165}, // 230 - { 239, 198,123}, // 231 - { 173, 214, 0}, // 232 - { 0, 132,214}, // 233 - { 57, 57, 57}, // 234 - { 247, 189, 74}, // 235 - { 255, 198,198}, // 236 - { 255, 239,173}, // 237 - { 214, 255,173}, // 238 - { 82, 173,255}, // 239 - { 107, 107,107}, // 240 - { 247, 222, 99}, // 241 - { 255, 0,255}, // 242 - { 255, 132,255}, // 243 - { 132, 132,173}, // 244 - { 148, 247,255}, // 245 - { 148, 148,148}, // 246 - { 82, 0, 82}, // 247 - { 112, 68,112}, // 248 - { 176, 88,144}, // 249 - { 214, 132,173}, // 250 - { 206, 247,255}, // 251 - { 198, 198,198}, // 252 - { 0, 214,255}, // 253 - { 96, 224,96 }, // 254 - { 255, 255,255}, // 255 - }; -} // End of namespace CGE diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 6e08a9790d1..f771767c7b7 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1137,10 +1137,11 @@ uint8 * VGA::Page[4] = { (uint8 *) MK_FP(SCR_SEG, 0x0000), +//extern const char Copr[]; + VGA::VGA (int mode) : FrmCnt(0) { - extern const char Copr[]; bool std = true; int i; for (i = 10; i < 20; i ++) @@ -1155,9 +1156,10 @@ VGA::VGA (int mode) #endif } } - if (std) -// puts(Copr); - warning(Copr); +// if (std) +// warning(Copr); + warning("TODO: Fix Copr"); + SetStatAdr(); if (StatAdr != VGAST1_) ++ Mono; if (IsVga()) diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 9af2efe8f30..4f39cd61864 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -25,12 +25,12 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/vol.h" +#include "cge/vol.h" #include "common/system.h" #include "common/str.h" -#include -#include -#include +#include +#include +#include namespace CGE { From ccd934e4bfaa2997bf2dcec6818e0c418a11624f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 13 Jun 2011 00:40:19 +0200 Subject: [PATCH 013/276] CGE: Add a couple of STUB warnings --- engines/cge/cfile.cpp | 2 +- engines/cge/cge_main.cpp | 8 +- engines/cge/config.cpp | 1 + engines/cge/keybd.cpp | 4 +- engines/cge/mixer.cpp | 1 + engines/cge/snail.cpp | 2 + engines/cge/startup.cpp | 12 +- engines/cge/text.cpp | 2 +- engines/cge/vga13h.cpp | 314 +++++---------------------------------- 9 files changed, 61 insertions(+), 285 deletions(-) diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 1a23c3d0f98..fdbd6ad3152 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -293,12 +293,12 @@ void CFILE::Flush (void) if (Mode > REA) WriteBuff(); else Lim = 0; - // TODO replace by scummvm files. /* _BX = Handle; _AH = 0x68; // Flush buffer asm int 0x21 */ + warning("FIXME: CFILE::Flush"); } diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 9a2ce931f00..cdbb94f785b 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1832,8 +1832,8 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro Sprite->Flags.Tran = tran; Sprite->Flags.Kill = true; Sprite->Flags.BDel = true; - // TODO : Get Filename from entire path //fnsplit(fname, NULL, NULL, Sprite->File, NULL); + warning("LoadSprite: use of fnsplit"); Sprite->ShpCnt = shpcnt; VGA::SpareQ.Append(Sprite); @@ -2090,6 +2090,7 @@ static void RunGame (void) { //TODO Change the SNPOST message send to a special way to send function pointer // if (FINIS) SNPOST(SNEXEC, -1, 0, (void *)&QGame); + warning("RunGame: problematic use of SNPOST"); MainLoop(); } @@ -2188,8 +2189,9 @@ bool ShowTitle (const char * name) #ifdef CD STARTUP::Summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; #else - // TODO : do good boot... - Boot * b = ReadBoot(0); //getdisk()); +// Boot * b = ReadBoot(getdisk()); + warning("ShowTitle: FIXME ReadBoot"); + Boot * b = ReadBoot(0); uint32 sn = (b->XSign == 0x29) ? b->Serial : b->lTotSecs; free(b); sn -= ((IDENT *)Copr)->disk; diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 38da4cda589..ee4d1771f9a 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -210,6 +210,7 @@ static void Select (CHOICE * cho, int hlp) Hlp = hlp; //TODO Change the SNPOST message send to a special way to send function pointer //SNPOST(SNEXEC, -1, 0, (void *)&SNSelect); + warning("STUB: Select"); } diff --git a/engines/cge/keybd.cpp b/engines/cge/keybd.cpp index e4858d1d047..95899bed55d 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/keybd.cpp @@ -57,6 +57,7 @@ KEYBOARD::KEYBOARD (void) OldKeyboard = getvect(KEYBD_INT); setvect(KEYBD_INT, NewKeyboard); */ + warning("STUB: KEYBOARD::KEYBOARD"); } @@ -68,6 +69,7 @@ KEYBOARD::~KEYBOARD (void) /* TODO replace totally by scummvm handling setvect(KEYBD_INT, OldKeyboard); */ + warning("STUB: KEYBOARD::~KEYBOARD"); } @@ -86,7 +88,6 @@ SPRITE * KEYBOARD::SetClient (SPRITE * spr) void KEYBOARD::NewKeyboard (...) { // table address - // TODO keyboard ASM /* _SI = (uint16) Key; @@ -146,6 +147,7 @@ void KEYBOARD::NewKeyboard (...) asm mov al,20h // send End-Of-Interrupt asm out 20h,al // to the 8259 IC */ + warning("STUB: KEYBOARD::NewKeyboard"); } } // End of namespace CGE diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 346631b08a9..385634d4b8f 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -154,6 +154,7 @@ void MIXER::Update (void) //TODO Change the SNPOST message send to a special way to send function pointer //SNPOST_(SNEXEC, -1, 0, (void*)&SNDSetVolume); + warning("FIXME: MIXER::Update"); } } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index c63ba824b46..82ec4c596d3 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -387,6 +387,7 @@ void SNGhost (BITMAP * bmp) //bmp->Hide(FP_OFF(bmp->M), FP_SEG(bmp->M)); bmp->M = NULL; delete bmp; + warning("STUB: SNGhost"); } @@ -1288,6 +1289,7 @@ void SNAIL::RunCom (void) // TODO: Handle correctly the execution of function pointer coming from Message send SNPOST //case SNEXEC : ((void(*)(int)) (snc->Ptr))(snc->Val); break; + case SNEXEC : warning("STUB: SNEXEC code"); case SNSTEP : sprel->Step(); break; case SNZTRIM : SNZTrim(sprel); break; case SNGHOST : SNGhost((BITMAP *) snc->Ptr); break; diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 7e5ac71782c..c2badee266f 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -66,10 +66,9 @@ void quit_now(int ref){ -bool STARTUP::get_parms (void) +bool STARTUP::get_parms(void) { - // TODO do params - /* +/* int i = _argc; while (i > 1) { @@ -114,16 +113,16 @@ bool STARTUP::get_parms (void) #endif if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; */ + warning("STUB: STARTUP::get_parms"); return true; } -STARTUP::STARTUP (void) +STARTUP::STARTUP(void) { - //TOdO startup in scummvm - /* +/* uint32 m = farcoreleft() >> 10; if (m < 0x7FFF) Core = (int) m; else Core = 0x7FFF; @@ -152,6 +151,7 @@ STARTUP::STARTUP (void) } } */ + warning("STUB: STARTUP::STARTUP"); } diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 9ee6244f222..5b79131a260 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -288,7 +288,6 @@ void Inf (const char * txt) void SayTime (SPRITE * spr) { -//TODO Get Time /* static char t[] = "00:00"; struct time ti; @@ -297,6 +296,7 @@ void SayTime (SPRITE * spr) wtom(ti.ti_min, t+3, 10, 2); Say((*t == '0') ? (t+1) : t, spr); */ + warning("STUB: SayTime"); } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index f771767c7b7..01441c85a38 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -30,15 +30,12 @@ #include "cge/bitmap.h" #include "cge/vol.h" #include "cge/text.h" -//#include #include #include #include #include #include -//#include #include -//#include #include namespace CGE { @@ -143,7 +140,7 @@ static void Video (void) uint16 * SaveScreen (void) { - /* TODO ASM +/* uint16 cxy, cur, siz, * scr = NULL, * sav; // horizontal size of text mode screen @@ -195,17 +192,14 @@ uint16 * SaveScreen (void) } return sav; */ + warning("STUB: SaveScreen"); return 0; } - - - void RestoreScreen (uint16 * &sav) { - // TODO RestoreScreen ASM - /* +/* uint16 * scr = NULL; asm mov ax,0x40 // system data segment @@ -232,13 +226,10 @@ void RestoreScreen (uint16 * &sav) free(sav); sav = NULL; */ + warning("STUB: RestoreScreen"); } - - - - DAC MkDAC (uint8 r, uint8 g, uint8 b) { static DAC x; @@ -249,8 +240,6 @@ DAC MkDAC (uint8 r, uint8 g, uint8 b) } - - RGB MkRGB (uint8 r, uint8 g, uint8 b) { static TRGB x; @@ -261,10 +250,6 @@ RGB MkRGB (uint8 r, uint8 g, uint8 b) } - - - - SPRITE * Locate (int ref) { SPRITE * spr = VGA::ShowQ.Locate(ref); @@ -272,18 +257,10 @@ SPRITE * Locate (int ref) } - - - -//-------------------------------------------------------------------------- - - bool HEART::Enable = false; uint16 * HEART::XTimer = NULL; - - HEART::HEART (void) : ENGINE(TMR_DIV) { @@ -327,11 +304,10 @@ extern "C" void TimerProc (void) */ -void ENGINE::NewTimer (...) +void ENGINE::NewTimer(...) { static SPRITE * spr; static uint8 run = 0, cntr1 = TMR_RATE1, cntr2 = TMR_RATE2; - // TODO Timer ASM /* ___1152_Hz___: @@ -391,12 +367,10 @@ void ENGINE::NewTimer (...) } */ + warning("STUB: ENGINE::NewTimer"); } - - - void HEART::SetXTimer (uint16 * ptr) { if (XTimer && ptr != XTimer) *XTimer = 0; @@ -404,8 +378,6 @@ void HEART::SetXTimer (uint16 * ptr) } - - void HEART::SetXTimer (uint16 * ptr, uint16 time) { SetXTimer(ptr); @@ -413,16 +385,6 @@ void HEART::SetXTimer (uint16 * ptr, uint16 time) } - - -//-------------------------------------------------------------------------- - - - - - - - SPRITE::SPRITE (BMP_PTR * shp) : X(0), Y(0), Z(0), NearPtr(0), TakePtr(0), Next(NULL), Prev(NULL), SeqPtr(NO_SEQ), Time(0), //Delay(0), @@ -434,18 +396,12 @@ SPRITE::SPRITE (BMP_PTR * shp) } - - - - SPRITE::~SPRITE (void) { Contract(); } - - BMP_PTR SPRITE::Shp (void) { register SPREXT * e = Ext; @@ -459,7 +415,7 @@ BMP_PTR SPRITE::Shp (void) //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", // Seq, ShpCnt, SeqPtr, Seq[SeqPtr].Now, Seq[SeqPtr].Next); //VGA::Exit(s, File); - VGA::Exit("Invalid PHASE in SPRITE::Shp()", File); + error("Invalid PHASE in SPRITE::Shp() %s", File); } #endif return e->ShpList[i]; @@ -468,9 +424,6 @@ BMP_PTR SPRITE::Shp (void) } - - - BMP_PTR * SPRITE::SetShapeList (BMP_PTR * shp) { BMP_PTR * r = (Ext) ? Ext->ShpList : NULL; @@ -497,9 +450,6 @@ BMP_PTR * SPRITE::SetShapeList (BMP_PTR * shp) } - - - void SPRITE::MoveShapes (uint8 * buf) { BMP_PTR * p; @@ -510,9 +460,6 @@ void SPRITE::MoveShapes (uint8 * buf) } - - - bool SPRITE::Works (SPRITE * spr) { if (spr) if (spr->Ext) @@ -530,9 +477,6 @@ bool SPRITE::Works (SPRITE * spr) } - - - SEQ * SPRITE::SetSeq (SEQ * seq) { Expand(); @@ -545,10 +489,6 @@ SEQ * SPRITE::SetSeq (SEQ * seq) } - - - - bool SPRITE::SeqTest (int n) { if (n >= 0) return (SeqPtr == n); @@ -557,10 +497,6 @@ bool SPRITE::SeqTest (int n) } - - - - SNAIL::COM * SPRITE::SnList (SNLIST type) { register SPREXT * e = Ext; @@ -569,10 +505,6 @@ SNAIL::COM * SPRITE::SnList (SNLIST type) } - - - - void SPRITE::SetName (char * n) { if (Ext) @@ -592,9 +524,6 @@ void SPRITE::SetName (char * n) } - - - SPRITE * SPRITE::Expand (void) { if (! Ext) @@ -732,8 +661,6 @@ SPRITE * SPRITE::Expand (void) } - - SPRITE * SPRITE::Contract (void) { register SPREXT * e = Ext; @@ -756,10 +683,6 @@ SPRITE * SPRITE::Contract (void) } - - - - SPRITE * SPRITE::BackShow (bool fast) { Expand(); @@ -771,12 +694,6 @@ SPRITE * SPRITE::BackShow (bool fast) } - - - - - - void SPRITE::Step (int nr) { if (nr >= 0) SeqPtr = nr; @@ -794,19 +711,12 @@ void SPRITE::Step (int nr) } - - - - void SPRITE::Tick (void) { Step(); } - - - void SPRITE::MakeXlat (uint8 * x) { if (Ext) @@ -820,9 +730,6 @@ void SPRITE::MakeXlat (uint8 * x) } - - - void SPRITE::KillXlat (void) { if (Flags.Xlat && Ext) @@ -841,9 +748,6 @@ void SPRITE::KillXlat (void) } - - - void SPRITE::Goto (int x, int y) { int xo = X, yo = Y; @@ -864,28 +768,12 @@ void SPRITE::Goto (int x, int y) } - - - - - - - - - - void SPRITE::Center (void) { Goto((SCR_WID - W) / 2, (SCR_HIG - H) / 2); } - - - - - - void SPRITE::Show (void) { register SPREXT * e; @@ -906,11 +794,6 @@ void SPRITE::Show (void) } - - - - - void SPRITE::Show (uint16 pg) { uint8 * a = VGA::Page[1]; @@ -920,12 +803,6 @@ void SPRITE::Show (uint16 pg) } - - - - - - void SPRITE::Hide (void) { register SPREXT * e = Ext; @@ -933,8 +810,6 @@ void SPRITE::Hide (void) } - - BMP_PTR SPRITE::Ghost (void) { register SPREXT * e = Ext; @@ -956,10 +831,6 @@ BMP_PTR SPRITE::Ghost (void) } - - - - SPRITE * SpriteAt (int x, int y) { SPRITE * spr = NULL, * tail = VGA::ShowQ.Last(); @@ -974,32 +845,18 @@ SPRITE * SpriteAt (int x, int y) } - - - -//-------------------------------------------------------------------------- - - - - - - QUEUE::QUEUE (bool show) : Head(NULL), Tail(NULL), Show(show) { } - - QUEUE::~QUEUE (void) { Clear(); } - - void QUEUE::Clear (void) { while (Head) @@ -1010,8 +867,6 @@ void QUEUE::Clear (void) } - - void QUEUE::ForAll (void (*fun)(SPRITE *)) { SPRITE * s = Head; @@ -1024,9 +879,6 @@ void QUEUE::ForAll (void (*fun)(SPRITE *)) } - - - void QUEUE::Append (SPRITE * spr) { if (Tail) @@ -1041,9 +893,6 @@ void QUEUE::Append (SPRITE * spr) } - - - void QUEUE::Insert (SPRITE * spr, SPRITE * nxt) { if (nxt == Head) @@ -1064,9 +913,6 @@ void QUEUE::Insert (SPRITE * spr, SPRITE * nxt) } - - - void QUEUE::Insert (SPRITE * spr) { SPRITE * s; @@ -1080,9 +926,6 @@ void QUEUE::Insert (SPRITE * spr) } - - - SPRITE * QUEUE::Remove (SPRITE * spr) { if (spr == Head) Head = spr->Next; @@ -1095,9 +938,6 @@ SPRITE * QUEUE::Remove (SPRITE * spr) } - - - SPRITE * QUEUE::Locate (int ref) { SPRITE * spr; @@ -1106,14 +946,6 @@ SPRITE * QUEUE::Locate (int ref) } - - - -//-------------------------------------------------------------------------- - - - - uint16 VGA::StatAdr = VGAST1_; uint16 VGA::OldMode = 0; uint16 * VGA::OldScreen = NULL; @@ -1177,9 +1009,6 @@ VGA::VGA (int mode) } - - - VGA::~VGA (void) { Mono = 0; @@ -1205,7 +1034,7 @@ VGA::~VGA (void) void VGA::SetStatAdr (void) { - /* TODO SetStatADR ASM + /* asm mov dx,VGAMIr_ asm in al,dx asm test al,1 // CGA addressing mode flag @@ -1215,17 +1044,13 @@ void VGA::SetStatAdr (void) set_mode_adr: StatAdr = _AX; */ + warning("STUB: VGA::SetStatADR"); } - - - - #pragma argsused void VGA::WaitVR (bool on) { - // TODO Wait vertical retrace ASM /* _DX = StatAdr; _AH = (on) ? 0x00 : 0x08; @@ -1240,16 +1065,13 @@ void VGA::WaitVR (bool on) asm xor ah,0x08 asm loop wait */ + warning("STUB: VGA::WaitVR"); } - - - - void VGA::Setup (VgaRegBlk * vrb) { -/* TODO VGA setup +/* WaitVR(); // *--LOOK!--* resets VGAATR logic asm cld asm mov si, vrb // take address of parameter table @@ -1287,17 +1109,13 @@ void VGA::Setup (VgaRegBlk * vrb) xit: */ + warning("STUB: VGA::Setup"); } - - - - -int VGA::SetMode (int mode) +int VGA::SetMode(int mode) { - /* TODO VGA Set Mode - +/* Clear(); // get current mode asm mov ah,0x0F @@ -1317,17 +1135,14 @@ int VGA::SetMode (int mode) asm pop ax return _AX; */ + warning("STUB: VGA::SetMode"); return 0; } - - - - -void VGA::GetColors (DAC * tab) +void VGA::GetColors(DAC * tab) { - /* TODO GetColors ASM +/* asm cld asm les di,tab // color table asm mov dx,0x3C7 // PEL address read mode register @@ -1344,18 +1159,14 @@ void VGA::GetColors (DAC * tab) sto: asm stosb // store 1 color asm loop gc // next one? - */ + warning("STUB: VGA::GetColors"); } - - -void VGA::SetColors (DAC * tab, int lum) +void VGA::SetColors(DAC * tab, int lum) { - - /* TODO SetColors - +/* DAC * des = NewColors; asm push ds @@ -1401,13 +1212,10 @@ void VGA::SetColors (DAC * tab, int lum) } */ SetPal = true; + warning("STUB: VGA::SetColors"); } - - - - void VGA::SetColors (void) { memset(NewColors, 0, PAL_SIZ); @@ -1415,10 +1223,6 @@ void VGA::SetColors (void) } - - - - void VGA::Sunrise (DAC * tab) { int i; @@ -1431,10 +1235,6 @@ void VGA::Sunrise (DAC * tab) } - - - - void VGA::Sunset (void) { DAC tab[256]; @@ -1449,13 +1249,6 @@ void VGA::Sunset (void) } - - - - - - - void VGA::Show (void) { SPRITE * spr = ShowQ.First(); @@ -1468,11 +1261,9 @@ void VGA::Show (void) } - - -void VGA::UpdateColors (void) +void VGA::UpdateColors(void) { - /* TODO UpdateColors ASM +/* DAC * tab = NewColors; asm push ds @@ -1497,18 +1288,13 @@ void VGA::UpdateColors (void) asm pop ds */ + warning("STUB: VGA::UpdateColors"); } - - - - - -void VGA::Update (void) +void VGA::Update(void) { - // TODO VGA Update - /* +/* uint8 * p = Page[1]; Page[1] = Page[0]; Page[0] = p; @@ -1528,18 +1314,13 @@ void VGA::Update (void) UpdateColors(); SetPal = false; } + warning("STUB: VGA::Update"); } - - - - - - -void VGA::Clear (uint8 color) +void VGA::Clear(uint8 color) { - /* TODO Clear ASM +/* uint8 * a = (uint8 *) MK_FP(SCR_SEG, 0); asm mov dx,VGASEQ_ @@ -1553,16 +1334,13 @@ void VGA::Clear (uint8 color) asm rep stosb asm stosb */ + warning("STUB: VGA::Clear"); } - - - - -void VGA::CopyPage (uint16 d, uint16 s) +void VGA::CopyPage(uint16 d, uint16 s) { - /* TODO CopyPage +/* uint8 * S = Page[s & 3], * D = Page[d & 3]; asm mov dx,VGAGRA_ @@ -1594,14 +1372,14 @@ void VGA::CopyPage (uint16 d, uint16 s) asm pop ax asm out dx,al // end of copy mode */ + warning("STUB: VGA::CopyPage"); } //-------------------------------------------------------------------------- -void BITMAP::XShow (int x, int y) +void BITMAP::XShow(int x, int y) { - // TODO XShow ASM - /* +/* uint8 rmsk = x % 4, mask = 1 << rmsk, * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; @@ -1617,8 +1395,6 @@ void BITMAP::XShow (int x, int y) asm lds si,v asm mov bx,m - - asm mov al,0x02 // map mask register asm mov ah,mask @@ -1679,19 +1455,13 @@ void BITMAP::XShow (int x, int y) asm pop ds asm pop si asm pop bx - */ + warning("STUB: BITMAP::XShow"); } - - - - -void BITMAP::Show (int x, int y) +void BITMAP::Show(int x, int y) { - - // TODO Show ASM /* uint8 mask = 1 << (x & 3), * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); @@ -1757,16 +1527,13 @@ void BITMAP::Show (int x, int y) asm jne plane asm pop ds */ + warning("STUB: BITMAP::Show"); } - - - -void BITMAP::Hide (int x, int y) +void BITMAP::Hide(int x, int y) { - // TODO Bitmap Hide ASM - /* +/* uint8 * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; uint16 d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); HideDesc * b = B; @@ -1828,6 +1595,7 @@ void BITMAP::Hide (int x, int y) asm pop si // asm pop bx */ + warning("STUB: BITMAP::Hide"); } } // End of namespace CGE From ffc2aa4e4f41aa679d773ccafdec87bf8d7b5e85 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 13 Jun 2011 11:57:24 +0200 Subject: [PATCH 014/276] CGE: Format code --- engines/cge/bitmap.cpp | 687 ++++--- engines/cge/bitmap.h | 86 +- engines/cge/bitmaps.cpp | 347 ++-- engines/cge/bitmaps.h | 18 +- engines/cge/boot.h | 76 +- engines/cge/btfile.cpp | 244 +-- engines/cge/btfile.h | 95 +- engines/cge/cfile.cpp | 489 ++--- engines/cge/cfile.h | 71 +- engines/cge/cge.cpp | 31 +- engines/cge/cge.h | 20 +- engines/cge/cge_main.cpp | 3575 +++++++++++++++++-------------------- engines/cge/cge_main.h | 272 ++- engines/cge/config.cpp | 401 ++--- engines/cge/config.h | 6 +- engines/cge/detection.cpp | 10 +- engines/cge/ems.cpp | 292 ++- engines/cge/game.cpp | 118 +- engines/cge/game.h | 43 +- engines/cge/general.cpp | 397 ++-- engines/cge/general.h | 311 ++-- engines/cge/gettext.cpp | 174 +- engines/cge/gettext.h | 38 +- engines/cge/ident.h | 17 +- engines/cge/jbw.h | 195 +- engines/cge/keybd.cpp | 195 +- engines/cge/keybd.h | 45 +- engines/cge/mixer.cpp | 195 +- engines/cge/mixer.h | 43 +- engines/cge/module.mk | 7 +- engines/cge/mouse.cpp | 310 ++-- engines/cge/mouse.h | 88 +- engines/cge/snail.cpp | 2332 +++++++++++------------- engines/cge/snail.h | 140 +- engines/cge/snddrv.h | 86 +- engines/cge/sound.cpp | 408 ++--- engines/cge/sound.h | 76 +- engines/cge/startup.cpp | 274 ++- engines/cge/startup.h | 61 +- engines/cge/talk.cpp | 588 +++--- engines/cge/talk.h | 92 +- engines/cge/text.cpp | 423 ++--- engines/cge/text.h | 76 +- engines/cge/vga13h.cpp | 2449 +++++++++++++------------ engines/cge/vga13h.h | 477 +++-- engines/cge/vmenu.cpp | 230 ++- engines/cge/vmenu.h | 39 +- engines/cge/vol.cpp | 85 +- engines/cge/vol.h | 84 +- engines/cge/wav.h | 173 +- 50 files changed, 7870 insertions(+), 9119 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 1201b84fc67..1e5310a8e79 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -25,434 +25,389 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/bitmap.h" -#include "cge/cfile.h" -#include "cge/jbw.h" - -#ifdef VOL - #include "cge/vol.h" -#endif - -#include +#include "cge/bitmap.h" +#include "cge/cfile.h" +#include "cge/jbw.h" +#include "cge/vol.h" +#include #include "cge/cfile.h" #include "common/system.h" namespace CGE { -//-------------------------------------------------------------------------- - - - - -DAC * BITMAP::Pal = NULL; - +DAC *BITMAP::Pal = NULL; #define MAXPATH 128 #pragma argsused -BITMAP::BITMAP (const char * fname, bool rem) -: M(NULL), V(NULL) -{ - char pat[MAXPATH]; +BITMAP::BITMAP(const char *fname, bool rem) : M(NULL), V(NULL) { + char pat[MAXPATH]; + ForceExt(pat, fname, ".VBM"); - ForceExt(pat, fname, ".VBM"); - - #if (BMP_MODE < 2) - if (rem && PIC_FILE::Exist(pat)) - { - PIC_FILE file(pat); - if (file.Error == 0) - if (! VBMLoad(&file)) - error("Bad VBM [%s]", fname); - } - else - #endif - { - #if (BMP_MODE) - ForceExt(pat, fname, ".BMP"); - PIC_FILE file(pat); - if (file.Error == 0) +#if (BMP_MODE < 2) + if (rem && PIC_FILE::Exist(pat)) { + PIC_FILE file(pat); + if ((file.Error == 0) && (!VBMLoad(&file))) + error("Bad VBM [%s]", fname); + } else +#endif { - if (BMPLoad(&file)) - { - Code(); - if (rem) - { - free(M); - M = NULL; +#if (BMP_MODE) + ForceExt(pat, fname, ".BMP"); + PIC_FILE file(pat); + if (file.Error == 0) { + if (BMPLoad(&file)) { + Code(); + if (rem) { + free(M); + M = NULL; + } + } else + error("Bad BMP [%s]", fname); } - } - else - error("Bad BMP [%s]", fname); +#else + error("Bad VBM [%s]", fname); +#endif } - #else - error("Bad VBM [%s]", fname); - #endif - } } - - - -BITMAP::BITMAP (uint16 w, uint16 h, uint8 * map) -: W(w), H(h), M(map), V(NULL) -{ - if (map) Code(); +BITMAP::BITMAP(uint16 w, uint16 h, uint8 *map) : W(w), H(h), M(map), V(NULL) { + if (map) + Code(); } - - // following routine creates filled rectangle // immediately as VGA video chunks, in near memory as fast as possible, // especially for text line real time display +BITMAP::BITMAP(uint16 w, uint16 h, uint8 fill) + : W((w + 3) & ~3), // only full uint32 allowed! + H(h), + M(NULL) { + uint16 dsiz = W >> 2; // data size (1 plane line size) + uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap + uint16 psiz = H * lsiz; // - last gape, but + plane trailer + uint8 *v = new uint8[4 * psiz + H * sizeof(*B)];// the same for 4 planes + // + room for wash table + if (v == NULL) + error("No core"); -BITMAP::BITMAP (uint16 w, uint16 h, uint8 fill) -: W((w + 3) & ~3), // only full uint32 allowed! - H(h), - M(NULL) -{ - uint16 dsiz = W >> 2; // data size (1 plane line size) - uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap - uint16 psiz = H * lsiz; // - last gape, but + plane trailer - uint8 * v = new uint8[4 * psiz // the same for 4 planes - + H * sizeof(*B)]; // + room for wash table - if (v == NULL) - error("No core"); - - * (uint16 *) v = CPY | dsiz; // data chunk hader - memset(v+2, fill, dsiz); // data bytes - * (uint16 *) (v + lsiz - 2) = SKP | ((SCR_WID / 4) - dsiz); // gap - memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines - * (uint16 *) (v + psiz - 2) = EOI; // plane trailer uint16 - memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes - HideDesc * b = (HideDesc *) (v + 4 * psiz); - b->skip = (SCR_WID - W) >> 2; - b->hide = W >> 2; - memcpy(b+1, b, (H-1) * sizeof(*b)); // tricky fill entire table - b->skip = 0; // fix the first entry - V = v; - B = b; + *(uint16 *) v = CPY | dsiz; // data chunk hader + memset(v + 2, fill, dsiz); // data bytes + *(uint16 *)(v + lsiz - 2) = SKP | ((SCR_WID / 4) - dsiz); // gap + memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines + *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 + memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes + HideDesc *b = (HideDesc *)(v + 4 * psiz); + b->skip = (SCR_WID - W) >> 2; + b->hide = W >> 2; + memcpy(b + 1, b, (H - 1) * sizeof(*b)); // tricky fill entire table + b->skip = 0; // fix the first entry + V = v; + B = b; } - - - - - -BITMAP::BITMAP (const BITMAP& bmp) -: W(bmp.W), H(bmp.H), - M(NULL), V(NULL) -{ - uint8 * v0 = bmp.V; - if (v0) - { - uint16 vsiz = (uint8*)(bmp.B) - (uint8*)(v0); - uint16 siz = vsiz + H * sizeof(HideDesc); - uint8 * v1 = farnew(uint8, siz); - if (v1 == NULL) - error("No core"); - memcpy(v1, v0, siz); - B = (HideDesc *) ((V = v1) + vsiz); - } -} - - - - - -BITMAP::~BITMAP (void) -{ - switch (MemType(M)) - { - case FAR_MEM : free(M); break; - } - switch (MemType(V)) - { - case NEAR_MEM : delete[] (uint8 *) V; break; - case FAR_MEM : free(V); break; - } -} - - - -BITMAP& BITMAP::operator = (const BITMAP& bmp) -{ - uint8 * v0 = bmp.V; - W = bmp.W; - H = bmp.H; - M = NULL; - if (MemType(V) == FAR_MEM) free(V); - if (v0 == NULL) V = NULL; - else - { - uint16 vsiz = (uint8*)bmp.B - (uint8*)v0; - uint16 siz = vsiz + H * sizeof(HideDesc); - uint8 * v1 = farnew(uint8, siz); - if (v1 == NULL) - error("No core"); - memcpy(v1, v0, siz); - B = (HideDesc *) ((V = v1) + vsiz); - } - return *this; -} - - - - - -uint16 BITMAP::MoveVmap (uint8 * buf) -{ - if (V) - { - uint16 vsiz = (uint8*)B - (uint8*)V; - uint16 siz = vsiz + H * sizeof(HideDesc); - memcpy(buf, V, siz); - if (MemType(V) == FAR_MEM) free(V); - B = (HideDesc *) ((V = buf) + vsiz); - return siz; - } - return 0; -} - - - - - - - -BMP_PTR BITMAP::Code (void) -{ - if (M) - { - uint16 i, cnt; - - if (V) // old X-map exists, so remove it - { - switch (MemType(V)) - { - case NEAR_MEM : delete[] (uint8 *) V; break; - case FAR_MEM : free(V); break; - } - V = NULL; +BITMAP::BITMAP(const BITMAP &bmp) : W(bmp.W), H(bmp.H), M(NULL), V(NULL) { + uint8 *v0 = bmp.V; + if (v0) { + uint16 vsiz = (uint8 *)(bmp.B) - (uint8 *)(v0); + uint16 siz = vsiz + H * sizeof(HideDesc); + uint8 *v1 = farnew(uint8, siz); + if (v1 == NULL) + error("No core"); + memcpy(v1, v0, siz); + B = (HideDesc *)((V = v1) + vsiz); } +} - while (true) // at most 2 times: for (V == NULL) & for allocated block; - { - uint8 * im = V+2; - uint16 * cp = (uint16 *) V; - int bpl; - if (V) // 2nd pass - fill the hide table - { - for (i = 0; i < H; i ++) - { - B[i].skip = 0xFFFF; - B[i].hide = 0x0000; +BITMAP::~BITMAP(void) { + if (MemType(M) == FAR_MEM) + free(M); + + switch (MemType(V)) { + case NEAR_MEM : + delete[](uint8 *) V; + break; + case FAR_MEM : + free(V); + break; + } +} + + +BITMAP &BITMAP::operator = (const BITMAP &bmp) { + uint8 *v0 = bmp.V; + W = bmp.W; + H = bmp.H; + M = NULL; + if (MemType(V) == FAR_MEM) + free(V); + if (v0 == NULL) + V = NULL; + else { + uint16 vsiz = (uint8 *)bmp.B - (uint8 *)v0; + uint16 siz = vsiz + H * sizeof(HideDesc); + uint8 *v1 = farnew(uint8, siz); + if (v1 == NULL) + error("No core"); + memcpy(v1, v0, siz); + B = (HideDesc *)((V = v1) + vsiz); + } + return *this; +} + + +uint16 BITMAP::MoveVmap(uint8 *buf) { + if (V) { + uint16 vsiz = (uint8 *)B - (uint8 *)V; + uint16 siz = vsiz + H * sizeof(HideDesc); + memcpy(buf, V, siz); + if (MemType(V) == FAR_MEM) + free(V); + B = (HideDesc *)((V = buf) + vsiz); + return siz; + } + return 0; +} + + +BMP_PTR BITMAP::Code(void) { + if (M) { + uint16 i, cnt; + + if (V) { // old X-map exists, so remove it + switch (MemType(V)) { + case NEAR_MEM : + delete[](uint8 *) V; + break; + case FAR_MEM : + free(V); + break; + } + V = NULL; } - } - for (bpl = 0; bpl < 4; bpl ++) // once per each bitplane - { - uint8 * bm = M; - bool skip = (bm[bpl] == TRANS); - uint16 j; - cnt = 0; - for (i = 0; i < H; i ++) // once per each line - { - uint8 pix; - for (j = bpl; j < W; j += 4) - { - pix = bm[j]; - if (V && pix != TRANS) - { - if (j < B[i].skip) B[i].skip = j; - if (j >= B[i].hide) B[i].hide = j+1; - } - if ((pix == TRANS) != skip || cnt >= 0x3FF0) // end of block - { - cnt |= (skip) ? SKP : CPY; - if (V) - { - *cp = cnt; // store block description uint16 - } - cp = (uint16 *) im; - im += 2; - skip = (pix == TRANS); - cnt = 0; - } - if (! skip) - { - if (V) * im = pix; - ++ im; - } - ++ cnt; - } + while (true) { // at most 2 times: for (V == NULL) & for allocated block; + uint8 *im = V + 2; + uint16 *cp = (uint16 *) V; + int bpl; - bm += W; - if (W < SCR_WID) - { - if (skip) - { - cnt += (SCR_WID - j + 3) / 4; + if (V) { // 2nd pass - fill the hide table + for (i = 0; i < H; i ++) { + B[i].skip = 0xFFFF; + B[i].hide = 0x0000; + } } - else - { - cnt |= CPY; - if (V) - { - *cp = cnt; - } - cp = (uint16 *) im; - im += 2; - skip = true; - cnt = (SCR_WID - j + 3) / 4; + for (bpl = 0; bpl < 4; bpl ++) { // once per each bitplane + uint8 *bm = M; + bool skip = (bm[bpl] == TRANS); + uint16 j; + + cnt = 0; + for (i = 0; i < H; i ++) { // once per each line + uint8 pix; + for (j = bpl; j < W; j += 4) { + pix = bm[j]; + if (V && pix != TRANS) { + if (j < B[i].skip) + B[i].skip = j; + + if (j >= B[i].hide) + B[i].hide = j + 1; + } + if ((pix == TRANS) != skip || cnt >= 0x3FF0) { // end of block + cnt |= (skip) ? SKP : CPY; + if (V) + *cp = cnt; // store block description uint16 + + cp = (uint16 *) im; + im += 2; + skip = (pix == TRANS); + cnt = 0; + } + if (! skip) { + if (V) + *im = pix; + ++ im; + } + ++ cnt; + } + + bm += W; + if (W < SCR_WID) { + if (skip) { + cnt += (SCR_WID - j + 3) / 4; + } else { + cnt |= CPY; + if (V) + *cp = cnt; + + cp = (uint16 *) im; + im += 2; + skip = true; + cnt = (SCR_WID - j + 3) / 4; + } + } + } + if (cnt && ! skip) { + cnt |= CPY; + if (V) + *cp = cnt; + + cp = (uint16 *) im; + im += 2; + } + if (V) + *cp = EOI; + cp = (uint16 *) im; + im += 2; } - } + if (V) + break; + + uint16 sizV = (uint16)(im - 2 - V); + V = farnew(uint8, sizV + H * sizeof(*B)); + if (! V) + error("No core"); + + B = (HideDesc *)(V + sizV); } - if (cnt && ! skip) - { - cnt |= CPY; - if (V) - { - *cp = cnt; - } - cp = (uint16 *) im; - im += 2; + cnt = 0; + for (i = 0; i < H; i ++) { + if (B[i].skip == 0xFFFF) { // whole line is skipped + B[i].skip = (cnt + SCR_WID) >> 2; + cnt = 0; + } else { + uint16 s = B[i].skip & ~3; + uint16 h = (B[i].hide + 3) & ~3; + B[i].skip = (cnt + s) >> 2; + B[i].hide = (h - s) >> 2; + cnt = SCR_WID - h; + } } - if (V) *cp = EOI; - cp = (uint16 *) im; - im += 2; - } - if (V) break; - uint16 sizV = (uint16) (im - 2 - V); - V = farnew(uint8, sizV + H * sizeof(*B)); - if (! V) - { - error("No core"); - } - B = (HideDesc *) (V + sizV); } - cnt = 0; - for (i = 0; i < H; i ++) - { - if (B[i].skip == 0xFFFF) // whole line is skipped - { - B[i].skip = (cnt + SCR_WID) >> 2; - cnt = 0; - } - else - { - uint16 s = B[i].skip & ~3; - uint16 h = (B[i].hide + 3) & ~3; - B[i].skip = (cnt + s) >> 2; - B[i].hide = (h - s) >> 2; - cnt = SCR_WID - h; - } - } - } - return this; + return this; } +bool BITMAP::SolidAt(int x, int y) { + uint8 *m; + uint16 r, n, n0; + if ((x >= W) || (y >= H)) + return false; + m = V; + r = x % 4; + n0 = (SCR_WID * y + x) / 4, n = 0; + while (r) { + uint16 w, t; -bool BITMAP::SolidAt (int x, int y) -{ - uint8 * m; - uint16 r, n, n0; + w = *(uint16 *) m; + m += 2; + t = w & 0xC000; + w &= 0x3FFF; - if (x >= W || y >= H) return false; - - m = V; - r = x % 4; - n0 = (SCR_WID * y + x) / 4, n = 0; - - while (r) - { - uint16 w, t; - - w = * (uint16 *) m; - m += 2; - t = w & 0xC000; - w &= 0x3FFF; - - switch (t) - { - case EOI : -- r; - case SKP : w = 0; break; - case REP : w = 1; break; + switch (t) { + case EOI : + -- r; + case SKP : + w = 0; + break; + case REP : + w = 1; + break; + } + m += w; } - m += w; - } - while (true) - { - uint16 w, t; + while (true) { + uint16 w, t; - w = * (uint16 *) m; - m += 2; - t = w & 0xC000; - w &= 0x3FFF; + w = * (uint16 *) m; + m += 2; + t = w & 0xC000; + w &= 0x3FFF; - if (n > n0) return false; - n += w; - switch (t) - { - case EOI : return false; - case SKP : w = 0; break; - case REP : - case CPY : if (n-w <= n0 && n > n0) return true; break; + if (n > n0) + return false; + + n += w; + switch (t) { + case EOI : + return false; + case SKP : + w = 0; + break; + case REP : + case CPY : + if (n - w <= n0 && n > n0) + return true; + break; + } + m += (t == REP) ? 1 : w; } - m += (t == REP) ? 1 : w; - } } +bool BITMAP::VBMSave(XFILE *f) { + uint16 p = (Pal != NULL), + n = ((uint16)(((uint8 *)B) - V)) + H * sizeof(HideDesc); + if (f->Error == 0) + f->Write((uint8 *)&p, sizeof(p)); + if (f->Error == 0) + f->Write((uint8 *)&n, sizeof(n)); + if (f->Error == 0) + f->Write((uint8 *)&W, sizeof(W)); + if (f->Error == 0) + f->Write((uint8 *)&H, sizeof(H)); -bool BITMAP::VBMSave (XFILE * f) -{ - uint16 p = (Pal != NULL), - n = ((uint16) (((uint8 *)B) - V)) + H * sizeof(HideDesc); - if (f->Error == 0) f->Write((uint8 *)&p, sizeof(p)); - if (f->Error == 0) f->Write((uint8 *)&n, sizeof(n)); - if (f->Error == 0) f->Write((uint8 *)&W, sizeof(W)); - if (f->Error == 0) f->Write((uint8 *)&H, sizeof(H)); - if (f->Error == 0) if (p) f->Write((uint8 *)Pal, 256 * sizeof(DAC)); - if (f->Error == 0) f->Write(V, n); - return (f->Error == 0); + if (f->Error == 0) + if (p) + f->Write((uint8 *)Pal, 256 * sizeof(DAC)); + + if (f->Error == 0) + f->Write(V, n); + + return (f->Error == 0); } +bool BITMAP::VBMLoad(XFILE *f) { + uint16 p = 0, n = 0; + if (f->Error == 0) + f->Read((uint8 *)&p, sizeof(p)); + if (f->Error == 0) + f->Read((uint8 *)&n, sizeof(n)); + if (f->Error == 0) + f->Read((uint8 *)&W, sizeof(W)); -bool BITMAP::VBMLoad (XFILE * f) -{ - uint16 p = 0, n = 0; - if (f->Error == 0) f->Read((uint8 *)&p, sizeof(p)); - if (f->Error == 0) f->Read((uint8 *)&n, sizeof(n)); - if (f->Error == 0) f->Read((uint8 *)&W, sizeof(W)); - if (f->Error == 0) f->Read((uint8 *)&H, sizeof(H)); - if (f->Error == 0) - { - if (p) - { - if (Pal) f->Read((uint8 *)Pal, 256 * sizeof(DAC)); - else f->Seek(f->Mark() + 256 * sizeof(DAC)); + if (f->Error == 0) + f->Read((uint8 *)&H, sizeof(H)); + + if (f->Error == 0) { + if (p) { + if (Pal) + f->Read((uint8 *)Pal, 256 * sizeof(DAC)); + else + f->Seek(f->Mark() + 256 * sizeof(DAC)); + } } - } - if ((V = farnew(uint8, n)) == NULL) return false; - if (f->Error == 0) f->Read(V, n); - B = (HideDesc *) (V + n - H * sizeof(HideDesc)); - return (f->Error == 0); + if ((V = farnew(uint8, n)) == NULL) + return false; + + if (f->Error == 0) + f->Read(V, n); + + B = (HideDesc *)(V + n - H * sizeof(HideDesc)); + return (f->Error == 0); } - - } // End of namespace CGE diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 90f94b1b325..eca3be70e8c 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -25,64 +25,64 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __BITMAP__ -#define __BITMAP__ +#ifndef __BITMAP__ +#define __BITMAP__ -#include "cge/general.h" +#include "cge/general.h" namespace CGE { -#define EOI 0x0000 -#define SKP 0x4000 -#define REP 0x8000 -#define CPY 0xC000 +#define EOI 0x0000 +#define SKP 0x4000 +#define REP 0x8000 +#define CPY 0xC000 -#define TRANS 0xFE +#define TRANS 0xFE -typedef struct { uint16 b : 2; - uint16 B : 6; - uint16 g : 2; - uint16 G : 6; - uint16 r : 2; - uint16 R : 6; - uint16 Z : 8; - } BGR4; +typedef struct { + uint16 b : 2; + uint16 B : 6; + uint16 g : 2; + uint16 G : 6; + uint16 r : 2; + uint16 R : 6; + uint16 Z : 8; +} BGR4; -typedef struct { uint16 skip; uint16 hide; } HideDesc; +typedef struct { + uint16 skip; + uint16 hide; +} HideDesc; - - -class BITMAP -{ - bool BMPLoad (XFILE * f); - bool VBMLoad (XFILE * f); +class BITMAP { + bool BMPLoad(XFILE *f); + bool VBMLoad(XFILE *f); public: - static DAC * Pal; - uint16 W, H; - uint8 * M, * V; HideDesc * B; - BITMAP (const char * fname, bool rem = true); - BITMAP (uint16 w, uint16 h, uint8 * map); - BITMAP (uint16 w, uint16 h, uint8 fill); - BITMAP (const BITMAP& bmp); - ~BITMAP (void); - BITMAP * FlipH (void); - BITMAP * Code (); - BITMAP& operator = (const BITMAP& bmp); - void Hide (int x, int y); - void Show (int x, int y); - void XShow (int x, int y); - bool SolidAt (int x, int y); - bool VBMSave (XFILE * f); - uint16 MoveVmap (uint8 * buf); + static DAC *Pal; + uint16 W, H; + uint8 *M, * V; + HideDesc *B; + BITMAP(const char *fname, bool rem = true); + BITMAP(uint16 w, uint16 h, uint8 *map); + BITMAP(uint16 w, uint16 h, uint8 fill); + BITMAP(const BITMAP &bmp); + ~BITMAP(void); + BITMAP *FlipH(void); + BITMAP *Code(); + BITMAP &operator = (const BITMAP &bmp); + void Hide(int x, int y); + void Show(int x, int y); + void XShow(int x, int y); + bool SolidAt(int x, int y); + bool VBMSave(XFILE *f); + uint16 MoveVmap(uint8 *buf); }; - -typedef BITMAP * BMP_PTR; - +typedef BITMAP *BMP_PTR; } // End of namespace CGE diff --git a/engines/cge/bitmaps.cpp b/engines/cge/bitmaps.cpp index 1eba1b55ea5..8e1b7ce5e90 100644 --- a/engines/cge/bitmaps.cpp +++ b/engines/cge/bitmaps.cpp @@ -25,146 +25,146 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/bitmaps.h" +#include "cge/bitmaps.h" /* -#define W 255, -#define x 252, -#define _ TRANS, -#define o 0, -#define L LGRAY, -#define G GRAY, -#define D DGRAY, +#define W 255, +#define x 252, +#define _ TRANS, +#define o 0, +#define L LGRAY, +#define G GRAY, +#define D DGRAY, -static uint8 MCDesign0[]= { W W W W W W _ - W W W W W o _ - W W W W o _ _ - W W W W W _ _ - W W o W W W _ - W o _ o W W W - o _ _ _ o W W - _ _ _ _ _ o o }; +static uint8 MCDesign0[]= { W W W W W W _ + W W W W W o _ + W W W W o _ _ + W W W W W _ _ + W W o W W W _ + W o _ o W W W + o _ _ _ o W W + _ _ _ _ _ o o }; -static uint8 MCDesign1[]= { _ }; +static uint8 MCDesign1[]= { _ }; -static uint8 SLDesign[] = { G G G G G G G G G _ _ _ _ _ _ - L G G G G G G G G D _ _ _ _ _ - _ L G G G G G G G D _ _ _ _ _ - _ _ L G G G G G G G D _ _ _ _ - _ _ _ L G G G G G G D _ _ _ _ - _ _ _ _ L G G G G G D _ _ _ _ - _ _ _ _ _ L G G G G G D _ _ _ - _ _ _ _ _ _ L G G G G D _ _ _ - _ _ _ _ _ _ _ L G G G D _ _ _ - _ _ _ _ _ _ _ _ L G G G D _ _ - _ _ _ _ _ _ _ _ _ L G G D _ _ - _ _ _ _ _ _ _ _ _ _ L G D _ _ - _ _ _ _ _ _ _ _ _ _ _ L G D _ - _ _ _ _ _ _ _ _ _ _ _ _ L D _ - _ _ _ _ _ _ _ _ _ _ _ _ _ L D - _ _ _ _ _ _ _ _ _ _ _ _ _ _ D - }; +static uint8 SLDesign[] = { G G G G G G G G G _ _ _ _ _ _ + L G G G G G G G G D _ _ _ _ _ + _ L G G G G G G G D _ _ _ _ _ + _ _ L G G G G G G G D _ _ _ _ + _ _ _ L G G G G G G D _ _ _ _ + _ _ _ _ L G G G G G D _ _ _ _ + _ _ _ _ _ L G G G G G D _ _ _ + _ _ _ _ _ _ L G G G G D _ _ _ + _ _ _ _ _ _ _ L G G G D _ _ _ + _ _ _ _ _ _ _ _ L G G G D _ _ + _ _ _ _ _ _ _ _ _ L G G D _ _ + _ _ _ _ _ _ _ _ _ _ L G D _ _ + _ _ _ _ _ _ _ _ _ _ _ L G D _ + _ _ _ _ _ _ _ _ _ _ _ _ L D _ + _ _ _ _ _ _ _ _ _ _ _ _ _ L D + _ _ _ _ _ _ _ _ _ _ _ _ _ _ D + }; -static uint8 SRDesign[] = { _ _ _ _ _ _ G G G G G G G G G - _ _ _ _ _ L G G G G G G G G D - _ _ _ _ _ L G G G G G G G D _ - _ _ _ _ L G G G G G G G D _ _ - _ _ _ _ L G G G G G G D _ _ _ - _ _ _ _ L G G G G G D _ _ _ _ - _ _ _ L G G G G G D _ _ _ _ _ - _ _ _ L G G G G D _ _ _ _ _ _ - _ _ _ L G G G D _ _ _ _ _ _ _ - _ _ L G G G D _ _ _ _ _ _ _ _ - _ _ L G G D _ _ _ _ _ _ _ _ _ - _ _ L G D _ _ _ _ _ _ _ _ _ _ - _ L G D _ _ _ _ _ _ _ _ _ _ _ - _ L D _ _ _ _ _ _ _ _ _ _ _ _ - L D _ _ _ _ _ _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ _ _ _ _ _ _ _ _ - }; +static uint8 SRDesign[] = { _ _ _ _ _ _ G G G G G G G G G + _ _ _ _ _ L G G G G G G G G D + _ _ _ _ _ L G G G G G G G D _ + _ _ _ _ L G G G G G G G D _ _ + _ _ _ _ L G G G G G G D _ _ _ + _ _ _ _ L G G G G G D _ _ _ _ + _ _ _ L G G G G G D _ _ _ _ _ + _ _ _ L G G G G D _ _ _ _ _ _ + _ _ _ L G G G D _ _ _ _ _ _ _ + _ _ L G G G D _ _ _ _ _ _ _ _ + _ _ L G G D _ _ _ _ _ _ _ _ _ + _ _ L G D _ _ _ _ _ _ _ _ _ _ + _ L G D _ _ _ _ _ _ _ _ _ _ _ + _ L D _ _ _ _ _ _ _ _ _ _ _ _ + L D _ _ _ _ _ _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ _ _ _ _ _ _ _ _ + }; -static uint8 MapBrick[] = { L L L L L L L G - L G G G G G G D - L G G G G G G D - G D D D D D D D - }; +static uint8 MapBrick[] = { L L L L L L L G + L G G G G G G D + L G G G G G G D + G D D D D D D D + }; -#undef W -#undef _ -#undef x -#undef o -#undef L -#undef G -#undef D +#undef W +#undef _ +#undef x +#undef o +#undef L +#undef G +#undef D #if 0 -#define _ TRANS, -#define A 213, -#define B 207, -#define C 225, -#define D 219, -#define E 231, +#define _ TRANS, +#define A 213, +#define B 207, +#define C 225, +#define D 219, +#define E 231, -static uint8 PRDesign[] = { A E E E C C D A B - C _ _ _ _ _ _ D A - C _ _ _ _ _ _ D A - C _ _ _ _ _ _ D A - C _ _ _ _ _ _ D A - C _ _ _ _ _ _ D A - C _ _ _ _ _ _ D A - B A A A A A A A B - B B B B B B B B B - }; +static uint8 PRDesign[] = { A E E E C C D A B + C _ _ _ _ _ _ D A + C _ _ _ _ _ _ D A + C _ _ _ _ _ _ D A + C _ _ _ _ _ _ D A + C _ _ _ _ _ _ D A + C _ _ _ _ _ _ D A + B A A A A A A A B + B B B B B B B B B + }; #else -#define _ TRANS, -#define A 213, -#define B 207, -#define C 225, // DGRAY -#define D 219, -#define E 231, -#define F 237, +#define _ TRANS, +#define A 213, +#define B 207, +#define C 225, // DGRAY +#define D 219, +#define E 231, +#define F 237, -static uint8 PRDesign[] = { D D D D D D D D _ - D D D D D D D D _ - D _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ C _ - D C C C C C C C _ - _ _ _ _ _ _ _ _ _ - }; +static uint8 PRDesign[] = { D D D D D D D D _ + D D D D D D D D _ + D _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ _ _ + D _ _ _ _ _ _ C _ + D C C C C C C C _ + _ _ _ _ _ _ _ _ _ + }; #endif -#undef _ -#undef A -#undef B -#undef C -#undef D -#undef E +#undef _ +#undef A +#undef B +#undef C +#undef D +#undef E -#define _ 0x00, -#define x 0xFF, -#define A _ x _ x _ x _ x -#define B A A A A A A A A +#define _ 0x00, +#define x 0xFF, +#define A _ x _ x _ x _ x +#define B A A A A A A A A -static uint8 HLDesign[] = { B B B B B }; +static uint8 HLDesign[] = { B B B B B }; -#undef _ -#undef x -#undef A -#undef B +#undef _ +#undef x +#undef A +#undef B // 228 yellow @@ -172,74 +172,93 @@ static uint8 HLDesign[] = { B B B B B }; // 226 light green // 221 blue -#define A 208, -#define B 214, -#define C 220, -#define D 226, -#define E 255, +#define A 208, +#define B 214, +#define C 220, +#define D 226, +#define E 255, -static uint8 LIDesign[][9] = { { A A A - A B A - A A A }, +static uint8 LIDesign[][9] = { { A A A + A B A + A A A }, - { A B A - B C B - A B A }, + { A B A + B C B + A B A }, - { B C B - C D C - B C B }, + { B C B + C D C + B C B }, - { C D C - D E D - C D C }, - }; + { C D C + D E D + C D C }, + }; -#undef A -#undef B -#undef C -#undef D -#undef E +#undef A +#undef B +#undef C +#undef D +#undef E -#define R 211, -#define G 0, +#define R 211, +#define G 0, //226, -static uint8 MEDesign[][9] = { { R R R R R R R R R }, // 0 - { R R R R R R R R G }, // 1 - { R R R R R R R G G }, // 2 - { R R R R R R G G G }, // 3 - { R R R R R G G G G }, // 4 - { R R R R G G G G G }, // 5 - { R R R G G G G G G }, // 6 - { R R G G G G G G G }, // 7 - { R G G G G G G G G }, // 8 - { G G G G G G G G G }, // 9 - }; +static uint8 MEDesign[][9] = { { R R R R R R R R R }, // 0 + { R R R R R R R R G }, // 1 + { R R R R R R R G G }, // 2 + { R R R R R R G G G }, // 3 + { R R R R R G G G G }, // 4 + { R R R R G G G G G }, // 5 + { R R R G G G G G G }, // 6 + { R R G G G G G G G }, // 7 + { R G G G G G G G G }, // 8 + { G G G G G G G G G }, // 9 + }; -#undef R -#undef G +#undef R +#undef G */ namespace CGE { #ifdef DEBUG - BMP_PTR MB[] = { new BITMAP("BRICK"), NULL }; - BMP_PTR HL[] = { new BITMAP("HLINE"), NULL }; +BMP_PTR MB[] = { + new BITMAP("BRICK"), + NULL +}; + +BMP_PTR HL[] = { + new BITMAP("HLINE"), + NULL +}; #endif - BMP_PTR MC[] = { new BITMAP("MOUSE"), - new BITMAP("DUMMY"), - NULL }; - BMP_PTR PR[] = { new BITMAP("PRESS"), NULL }; - BMP_PTR SP[] = { new BITMAP("SPK_L"), - new BITMAP("SPK_R"), - NULL }; - BMP_PTR LI[] = { new BITMAP("LITE0"), - new BITMAP("LITE1"), - new BITMAP("LITE2"), - new BITMAP("LITE3"), - NULL }; +BMP_PTR MC[] = { + new BITMAP("MOUSE"), + new BITMAP("DUMMY"), + NULL +}; + +BMP_PTR PR[] = { + new BITMAP("PRESS"), + NULL +}; + +BMP_PTR SP[] = { + new BITMAP("SPK_L"), + new BITMAP("SPK_R"), + NULL +}; + +BMP_PTR LI[] = { + new BITMAP("LITE0"), + new BITMAP("LITE1"), + new BITMAP("LITE2"), + new BITMAP("LITE3"), + NULL +}; } // End of namespace CGE diff --git a/engines/cge/bitmaps.h b/engines/cge/bitmaps.h index 3ca2bababdc..5023c2e6572 100644 --- a/engines/cge/bitmaps.h +++ b/engines/cge/bitmaps.h @@ -25,22 +25,22 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __BITMAPS__ -#define __BITMAPS__ +#ifndef __BITMAPS__ +#define __BITMAPS__ -#include "cge/vga13h.h" +#include "cge/vga13h.h" namespace CGE { #ifdef DEBUG - extern BITMAP * MB[]; - extern BITMAP * HL[]; +extern BITMAP *MB[]; +extern BITMAP *HL[]; #endif -extern BITMAP * MC[]; -extern BITMAP * PR[]; -extern BITMAP * SP[]; -extern BITMAP * LI[]; +extern BITMAP *MC[]; +extern BITMAP *PR[]; +extern BITMAP *SP[]; +extern BITMAP *LI[]; } // End of namespace CGE diff --git a/engines/cge/boot.h b/engines/cge/boot.h index bc78b0e7fb5..ab4dcde0e23 100644 --- a/engines/cge/boot.h +++ b/engines/cge/boot.h @@ -25,54 +25,54 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __BOOT__ -#define __BOOT__ +#ifndef __BOOT__ +#define __BOOT__ -#include "cge/jbw.h" +#include "cge/jbw.h" namespace CGE { -#define BOOTSECT_SIZ 512 -#define BOOTHEAD_SIZ 62 -#define BOOTCODE_SIZ BOOTSECT_SIZ-BOOTHEAD_SIZ -#define FreeBoot(b) free(b) +#define BOOTSECT_SIZ 512 +#define BOOTHEAD_SIZ 62 +#define BOOTCODE_SIZ BOOTSECT_SIZ-BOOTHEAD_SIZ +#define FreeBoot(b) free(b) -#ifndef EC - #define EC +#ifndef EC +#define EC #endif typedef struct { - uint8 Jmp[3]; // NEAR jump machine code - char OEM_ID[8]; // OEM name and version - uint16 SectSize; // bytes per sector - uint8 ClustSize; // sectors per cluster - uint16 ResSecs; // sectors before 1st FAT - uint8 FatCnt; // number of FATs - uint16 RootSize; // root directory entries - uint16 TotSecs; // total sectors on disk - uint8 Media; // media descriptor byte - uint16 FatSize; // sectors per FAT - uint16 TrkSecs; // sectors per track - uint16 HeadCnt; // number of sufraces - uint16 HidnSecs; // special hidden sectors - uint16 _; // (unknown: reserved?) - uint32 lTotSecs; // total number of sectors - uint16 DriveNum; // physical drive number - uint8 XSign; // extended boot signature - uint32 Serial; // volume serial number - char Label[11]; // volume label - char FileSysID[8]; // file system ID - char Code[BOOTCODE_SIZ-8]; // 8 = length of following - uint32 Secret; // long secret number - uint8 BootCheck; // boot sector checksum - uint8 BootFlags; // secret flags - uint16 BootSig; // boot signature 0xAA55 - } Boot; + uint8 Jmp[3]; // NEAR jump machine code + char OEM_ID[8]; // OEM name and version + uint16 SectSize; // bytes per sector + uint8 ClustSize; // sectors per cluster + uint16 ResSecs; // sectors before 1st FAT + uint8 FatCnt; // number of FATs + uint16 RootSize; // root directory entries + uint16 TotSecs; // total sectors on disk + uint8 Media; // media descriptor byte + uint16 FatSize; // sectors per FAT + uint16 TrkSecs; // sectors per track + uint16 HeadCnt; // number of sufraces + uint16 HidnSecs; // special hidden sectors + uint16 _; // (unknown: reserved?) + uint32 lTotSecs; // total number of sectors + uint16 DriveNum; // physical drive number + uint8 XSign; // extended boot signature + uint32 Serial; // volume serial number + char Label[11]; // volume label + char FileSysID[8]; // file system ID + char Code[BOOTCODE_SIZ - 8]; // 8 = length of following + uint32 Secret; // long secret number + uint8 BootCheck; // boot sector checksum + uint8 BootFlags; // secret flags + uint16 BootSig; // boot signature 0xAA55 +} Boot; -EC Boot * ReadBoot (int drive); -EC uint8 CheckBoot (Boot * boot); -EC bool WriteBoot (int drive, Boot * boot); +EC Boot *ReadBoot(int drive); +EC uint8 CheckBoot(Boot *boot); +EC bool WriteBoot(int drive, Boot *boot); } // End of namespace CGE diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 7c61157ebae..b5e59e09882 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -25,173 +25,125 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/btfile.h" -//#include +#include "cge/btfile.h" #include "common/system.h" #include "common/str.h" -#include +#include namespace CGE { -#ifndef BT_SIZE - #define BT_SIZE K(1) +#ifndef BT_SIZE +#define BT_SIZE K(1) #endif -#ifndef BT_KEYLEN - #define BT_KEYLEN 13 +#ifndef BT_KEYLEN +#define BT_KEYLEN 13 #endif - - - - -BTFILE::BTFILE (const char * name, IOMODE mode, CRYPT * crpt) -: IOHAND(name, mode, crpt) -{ - int i; - for (i = 0; i < BT_LEVELS; i ++) - { - Buff[i].Page = new BT_PAGE; - Buff[i].PgNo = BT_NONE; - Buff[i].Indx = -1; - Buff[i].Updt = FALSE; - if (Buff[i].Page == NULL) - error("No core"); - } -} - - - - - - - - - -BTFILE::~BTFILE (void) -{ - int i; - for (i = 0; i < BT_LEVELS; i ++) - { - PutPage(i); - delete Buff[i].Page; - } -} - - - - - - -void BTFILE::PutPage (int lev, bool hard) -{ - if (hard || Buff[lev].Updt) - { - Seek(Buff[lev].PgNo * sizeof(BT_PAGE)); - Write((uint8 *) Buff[lev].Page, sizeof(BT_PAGE)); - Buff[lev].Updt = FALSE; - } -} - - - - - - -BT_PAGE * BTFILE::GetPage (int lev, uint16 pgn) -{ - if (Buff[lev].PgNo != pgn) - { - uint32 pos = pgn * sizeof(BT_PAGE); - PutPage(lev); - Buff[lev].PgNo = pgn; - if (Size() > pos) - { - Seek((uint32) pgn * sizeof(BT_PAGE)); - Read((uint8 *) Buff[lev].Page, sizeof(BT_PAGE)); - Buff[lev].Updt = FALSE; +BTFILE::BTFILE(const char *name, IOMODE mode, CRYPT *crpt) + : IOHAND(name, mode, crpt) { + for (int i = 0; i < BT_LEVELS; i ++) { + Buff[i].Page = new BT_PAGE; + Buff[i].PgNo = BT_NONE; + Buff[i].Indx = -1; + Buff[i].Updt = FALSE; + if (Buff[i].Page == NULL) + error("No core"); } - else - { - Buff[lev].Page->Hea.Count = 0; - Buff[lev].Page->Hea.Down = BT_NONE; - memset(Buff[lev].Page->Data, '\0', sizeof(Buff[lev].Page->Data)); - Buff[lev].Updt = TRUE; - } - Buff[lev].Indx = -1; - } - return Buff[lev].Page; } - - - -BT_KEYPACK * BTFILE::Find (const char * key) -{ - int lev = 0; - uint16 nxt = BT_ROOT; - while (! Error) - { - BT_PAGE * pg = GetPage(lev, nxt); - // search - if (pg->Hea.Down != BT_NONE) - { - int i; - for (i = 0; i < pg->Hea.Count; i ++) - if (memicmp(key, pg->Inn[i].Key, BT_KEYLEN) < 0) - break; - nxt = (i) ? pg->Inn[i-1].Down : pg->Hea.Down; - Buff[lev].Indx = i-1; - ++ lev; +BTFILE::~BTFILE(void) { + for (int i = 0; i < BT_LEVELS; i ++) { + PutPage(i); + delete Buff[i].Page; } - else - { - int i; - for (i = 0; i < pg->Hea.Count-1; i ++) - if (scumm_stricmp((const char*)key, (const char*)pg->Lea[i].Key) <= 0) - break; - Buff[lev].Indx = i; - return &pg->Lea[i]; - } - } - return NULL; } - - -int keycomp (const void * k1, const void * k2) -{ - return memicmp(k1, k2, BT_KEYLEN); +void BTFILE::PutPage(int lev, bool hard) { + if (hard || Buff[lev].Updt) { + Seek(Buff[lev].PgNo * sizeof(BT_PAGE)); + Write((uint8 *) Buff[lev].Page, sizeof(BT_PAGE)); + Buff[lev].Updt = FALSE; + } } - -void BTFILE::Make(BT_KEYPACK * keypack, uint16 count) -{ - #if BT_LEVELS != 2 - #error This tiny BTREE implementation works with exactly 2 levels! - #endif - _fqsort(keypack, count, sizeof(*keypack), keycomp); - uint16 n = 0; - BT_PAGE * Root = GetPage(0, n ++), - * Leaf = GetPage(1, n); - Root->Hea.Down = n; - PutPage(0, TRUE); - while (count --) - { - if (Leaf->Hea.Count >= ArrayCount(Leaf->Lea)) - { - PutPage(1, TRUE); // save filled page - Leaf = GetPage(1, ++n); // take empty page - memcpy(Root->Inn[Root->Hea.Count].Key, keypack->Key, BT_KEYLEN); - Root->Inn[Root->Hea.Count ++].Down = n; - Buff[0].Updt = TRUE; +BT_PAGE *BTFILE::GetPage(int lev, uint16 pgn) { + if (Buff[lev].PgNo != pgn) { + uint32 pos = pgn * sizeof(BT_PAGE); + PutPage(lev); + Buff[lev].PgNo = pgn; + if (Size() > pos) { + Seek((uint32) pgn * sizeof(BT_PAGE)); + Read((uint8 *) Buff[lev].Page, sizeof(BT_PAGE)); + Buff[lev].Updt = FALSE; + } else { + Buff[lev].Page->Hea.Count = 0; + Buff[lev].Page->Hea.Down = BT_NONE; + memset(Buff[lev].Page->Data, '\0', sizeof(Buff[lev].Page->Data)); + Buff[lev].Updt = TRUE; + } + Buff[lev].Indx = -1; + } + return Buff[lev].Page; +} + + +BT_KEYPACK *BTFILE::Find(const char *key) { + int lev = 0; + uint16 nxt = BT_ROOT; + while (! Error) { + BT_PAGE *pg = GetPage(lev, nxt); + // search + if (pg->Hea.Down != BT_NONE) { + int i; + for (i = 0; i < pg->Hea.Count; i ++) + if (memicmp(key, pg->Inn[i].Key, BT_KEYLEN) < 0) + break; + nxt = (i) ? pg->Inn[i - 1].Down : pg->Hea.Down; + Buff[lev].Indx = i - 1; + ++ lev; + } else { + int i; + for (i = 0; i < pg->Hea.Count - 1; i ++) + if (scumm_stricmp((const char *)key, (const char *)pg->Lea[i].Key) <= 0) + break; + Buff[lev].Indx = i; + return &pg->Lea[i]; + } + } + return NULL; +} + + +int keycomp(const void *k1, const void *k2) { + return memicmp(k1, k2, BT_KEYLEN); +} + + +void BTFILE::Make(BT_KEYPACK *keypack, uint16 count) { +#if BT_LEVELS != 2 +#error This tiny BTREE implementation works with exactly 2 levels! +#endif + _fqsort(keypack, count, sizeof(*keypack), keycomp); + uint16 n = 0; + BT_PAGE *Root = GetPage(0, n++), + *Leaf = GetPage(1, n); + Root->Hea.Down = n; + PutPage(0, TRUE); + while (count --) { + if (Leaf->Hea.Count >= ArrayCount(Leaf->Lea)) { + PutPage(1, TRUE); // save filled page + Leaf = GetPage(1, ++n); // take empty page + memcpy(Root->Inn[Root->Hea.Count].Key, keypack->Key, BT_KEYLEN); + Root->Inn[Root->Hea.Count ++].Down = n; + Buff[0].Updt = TRUE; + } + Leaf->Lea[Leaf->Hea.Count ++] = * (keypack ++); + Buff[1].Updt = TRUE; } - Leaf->Lea[Leaf->Hea.Count ++] = * (keypack ++); - Buff[1].Updt = TRUE; - } } } // End of namespace CGE diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 0df96365738..c55891cae4d 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -25,73 +25,62 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __BTFILE__ -#define __BTFILE__ +#ifndef __BTFILE__ +#define __BTFILE__ -#include "cge/general.h" +#include "cge/general.h" namespace CGE { -#define BT_SIZE K(1) -#define BT_KEYLEN 13 -#define BT_LEVELS 2 +#define BT_SIZE K(1) +#define BT_KEYLEN 13 +#define BT_LEVELS 2 -#define BT_NONE 0xFFFF -#define BT_ROOT 0 +#define BT_NONE 0xFFFF +#define BT_ROOT 0 -struct BT_KEYPACK -{ - char Key[BT_KEYLEN]; - uint32 Mark; - uint16 Size; +struct BT_KEYPACK { + char Key[BT_KEYLEN]; + uint32 Mark; + uint16 Size; }; - -struct BT_PAGE -{ - struct HEA - { - uint16 Count; - uint16 Down; - } Hea; - union - { - // dummy filler to make proper size of union - uint8 Data[BT_SIZE-sizeof(HEA)]; - // inner version of data: key + word-sized page link - struct INNER - { - uint8 Key[BT_KEYLEN]; - uint16 Down; - } Inn[(BT_SIZE-sizeof(HEA))/sizeof(INNER)]; - // leaf version of data: key + all user data - BT_KEYPACK Lea[(BT_SIZE-sizeof(HEA))/sizeof(BT_KEYPACK)]; - }; +struct BT_PAGE { + struct HEA { + uint16 Count; + uint16 Down; + } Hea; + union { + // dummy filler to make proper size of union + uint8 Data[BT_SIZE - sizeof(HEA)]; + // inner version of data: key + word-sized page link + struct INNER { + uint8 Key[BT_KEYLEN]; + uint16 Down; + } Inn[(BT_SIZE - sizeof(HEA)) / sizeof(INNER)]; + // leaf version of data: key + all user data + BT_KEYPACK Lea[(BT_SIZE - sizeof(HEA)) / sizeof(BT_KEYPACK)]; + }; }; - - - -class BTFILE : public IOHAND -{ - struct - { - BT_PAGE * Page; - uint16 PgNo; - int Indx; - bool Updt; - } Buff[BT_LEVELS]; - void PutPage (int lev, bool hard = FALSE); - BT_PAGE * GetPage (int lev, uint16 pgn); +class BTFILE : public IOHAND { + struct { + BT_PAGE *Page; + uint16 PgNo; + int Indx; + bool Updt; + } Buff[BT_LEVELS]; + void PutPage(int lev, bool hard = FALSE); + BT_PAGE *GetPage(int lev, uint16 pgn); public: - BTFILE (const char * name, IOMODE mode = REA, CRYPT * crpt = NULL); - virtual ~BTFILE (void); - BT_KEYPACK * Find(const char * key); - BT_KEYPACK * Next(void); - void Make(BT_KEYPACK * keypack, uint16 count); + BTFILE(const char *name, IOMODE mode = REA, CRYPT *crpt = NULL); + virtual ~BTFILE(void); + BT_KEYPACK *Find(const char *key); + BT_KEYPACK *Next(void); + void Make(BT_KEYPACK *keypack, uint16 count); }; } // End of namespace CGE diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index fdbd6ad3152..7c4f689e309 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -25,334 +25,239 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/cfile.h" -#include -#include -#include +#include "cge/cfile.h" +#include +#include +#include #include "common/system.h" namespace CGE { -IOBUF::IOBUF (IOMODE mode, CRYPT * crpt) -: IOHAND(mode, crpt), - BufMark(0), - Ptr(0), - Lim(0) -{ - Buff = farnew(uint8, IOBUF_SIZE); - if (Buff == NULL) - error("No core for I/O"); +IOBUF::IOBUF(IOMODE mode, CRYPT *crpt) + : IOHAND(mode, crpt), + BufMark(0), + Ptr(0), + Lim(0) { + Buff = farnew(uint8, IOBUF_SIZE); + if (Buff == NULL) + error("No core for I/O"); } +IOBUF::IOBUF(const char *name, IOMODE mode, CRYPT *crpt) + : IOHAND(name, mode, crpt), + BufMark(0), + Ptr(0), + Lim(0) { + Buff = farnew(uint8, IOBUF_SIZE); + if (Buff == NULL) + error("No core for I/O [%s]", name); +} - - - - - - -IOBUF::IOBUF (const char * name, IOMODE mode, CRYPT * crpt) -: IOHAND(name, mode, crpt), - BufMark(0), - Ptr(0), - Lim(0) -{ - Buff = farnew(uint8, IOBUF_SIZE); - if (Buff == NULL) - error("No core for I/O [%s]", name); +IOBUF::~IOBUF(void) { + if (Mode > REA) + WriteBuff(); + if (Buff) + free(Buff); } - - - - - - - -IOBUF::~IOBUF (void) -{ - if (Mode > REA) WriteBuff(); - if (Buff) free(Buff); +void IOBUF::ReadBuff(void) { + BufMark = IOHAND::Mark(); + Lim = IOHAND::Read(Buff, IOBUF_SIZE); + Ptr = 0; } - - - - -void IOBUF::ReadBuff (void) -{ - BufMark = IOHAND::Mark(); - Lim = IOHAND::Read(Buff, IOBUF_SIZE); - Ptr = 0; -} - - - - - -void IOBUF::WriteBuff (void) -{ - if (Lim) - { - IOHAND::Write(Buff, Lim); - BufMark = IOHAND::Mark(); - Lim = 0; - } -} - - - - - -uint16 IOBUF::Read (void *buf, uint16 len) -{ - uint16 total = 0; - while (len) - { - if (Ptr >= Lim) ReadBuff(); - uint16 n = Lim - Ptr; - if (n) - { - if (len < n) n = len; - memcpy(buf, Buff+Ptr, n); - buf = (uint8 *)buf + n; - len -= n; - total += n; - Ptr += n; +void IOBUF::WriteBuff(void) { + if (Lim) { + IOHAND::Write(Buff, Lim); + BufMark = IOHAND::Mark(); + Lim = 0; } - else break; - } - return total; } - - - - -uint16 IOBUF::Read (uint8 * buf) -{ - uint16 total = 0; - - while (total < LINE_MAX-2) - { - if (Ptr >= Lim) ReadBuff(); - uint8 * p = Buff + Ptr; - uint16 n = Lim - Ptr; - if (n) - { - if (total + n >= LINE_MAX-2) n = LINE_MAX-2 - total; - uint8 * eol = (uint8 *) memchr(p, '\r', n); - if (eol) n = (uint16) (eol - p); - uint8 * eof = (uint8 *) memchr(p, '\32', n); - if (eof) // end-of-file - { - n = (uint16) (eof - p); - Ptr = (uint16) (eof - Buff); - } - if (n) memcpy(buf, p, n); - buf += n; - total += n; - if (eof) break; - Ptr += n; - if (eol) - { - ++ Ptr; - * (buf ++) = '\n'; - ++ total; - if (Ptr >= Lim) ReadBuff(); - if (Ptr < Lim) if (Buff[Ptr] == '\n') ++ Ptr; - break; - } +uint16 IOBUF::Read(void *buf, uint16 len) { + uint16 total = 0; + while (len) { + if (Ptr >= Lim) + ReadBuff(); + uint16 n = Lim - Ptr; + if (n) { + if (len < n) + n = len; + memcpy(buf, Buff + Ptr, n); + buf = (uint8 *)buf + n; + len -= n; + total += n; + Ptr += n; + } else + break; } - else break; - } - *buf = '\0'; - return total; + return total; } +uint16 IOBUF::Read(uint8 *buf) { + uint16 total = 0; - - - - -uint16 IOBUF::Write (void * buf, uint16 len) -{ - uint16 tot = 0; - while (len) - { - uint16 n = IOBUF_SIZE - Lim; - if (n > len) n = len; - if (n) - { - memcpy(Buff+Lim, buf, n); - Lim += n; - len -= n; - buf = (uint8 *)buf + n; - tot += n; + while (total < LINE_MAX - 2) { + if (Ptr >= Lim) + ReadBuff(); + uint8 *p = Buff + Ptr; + uint16 n = Lim - Ptr; + if (n) { + if (total + n >= LINE_MAX - 2) + n = LINE_MAX - 2 - total; + uint8 *eol = (uint8 *) memchr(p, '\r', n); + if (eol) + n = (uint16)(eol - p); + uint8 *eof = (uint8 *) memchr(p, '\32', n); + if (eof) { // end-of-file + n = (uint16)(eof - p); + Ptr = (uint16)(eof - Buff); + } + if (n) + memcpy(buf, p, n); + buf += n; + total += n; + if (eof) + break; + Ptr += n; + if (eol) { + ++ Ptr; + * (buf ++) = '\n'; + ++ total; + if (Ptr >= Lim) + ReadBuff(); + if (Ptr < Lim) + if (Buff[Ptr] == '\n') + ++Ptr; + break; + } + } else + break; } - else WriteBuff(); - } - return tot; + *buf = '\0'; + return total; } - - - - -uint16 IOBUF::Write (uint8 * buf) -{ - uint16 len = 0; - if (buf) - { - len = strlen((const char *) buf); - if (len) if (buf[len-1] == '\n') -- len; - len = Write(buf, len); - if (len) - { - static char EOL[] = "\r\n"; - uint16 n = Write(EOL, sizeof(EOL)-1); - len += n; +uint16 IOBUF::Write(void *buf, uint16 len) { + uint16 tot = 0; + while (len) { + uint16 n = IOBUF_SIZE - Lim; + if (n > len) + n = len; + if (n) { + memcpy(Buff + Lim, buf, n); + Lim += n; + len -= n; + buf = (uint8 *)buf + n; + tot += n; + } else + WriteBuff(); } - } - return len; + return tot; } - - - - -int IOBUF::Read (void) -{ - if (Ptr >= Lim) - { - ReadBuff(); - if (Lim == 0) return -1; - } - return Buff[Ptr ++]; -} - - - - - - -void IOBUF::Write (uint8 b) -{ - if (Lim >= IOBUF_SIZE) - { - WriteBuff(); - } - Buff[Lim ++] = b; -} - - - - - - - uint16 CFILE::MaxLineLen = LINE_MAX; - - - - - - - - -CFILE::CFILE (const char * name, IOMODE mode, CRYPT * crpt) -: IOBUF(name, mode, crpt) -{ -} - - - - - - - - - -CFILE::~CFILE (void) -{ -} - - - - - - -void CFILE::Flush (void) -{ - if (Mode > REA) WriteBuff(); - else Lim = 0; - - /* - _BX = Handle; - _AH = 0x68; // Flush buffer - asm int 0x21 - */ - warning("FIXME: CFILE::Flush"); -} - - - - - -long CFILE::Mark (void) -{ - return BufMark + ((Mode > REA) ? Lim : Ptr); -} - - - - - -long CFILE::Seek (long pos) -{ - if (pos >= BufMark && pos < BufMark + Lim) - { - ((Mode == REA) ? Ptr : Lim) = (uint16) (pos - BufMark); - return pos; - } - else - { - if (Mode > REA) - { - WriteBuff(); +uint16 IOBUF::Write(uint8 *buf) { + uint16 len = 0; + if (buf) { + len = strlen((const char *) buf); + if (len) + if (buf[len - 1] == '\n') + --len; + len = Write(buf, len); + if (len) { + static char EOL[] = "\r\n"; + uint16 n = Write(EOL, sizeof(EOL) - 1); + len += n; + } } - else - { - Lim = 0; - } - Ptr = 0; - return BufMark = IOHAND::Seek(pos); - } + return len; } - - - - -void CFILE::Append (CFILE& f) -{ - Seek(Size()); - if (f.Error == 0) - { - while (true) - { - if ((Lim = f.IOHAND::Read(Buff, IOBUF_SIZE)) == IOBUF_SIZE) WriteBuff(); - else break; - if ((Error = f.Error) != 0) break; +int IOBUF::Read(void) { + if (Ptr >= Lim) { + ReadBuff(); + if (Lim == 0) + return -1; + } + return Buff[Ptr ++]; +} + + +void IOBUF::Write(uint8 b) { + if (Lim >= IOBUF_SIZE) + WriteBuff(); + Buff[Lim ++] = b; +} + + +uint16 CFILE::MaxLineLen = LINE_MAX; + + +CFILE::CFILE(const char *name, IOMODE mode, CRYPT *crpt) + : IOBUF(name, mode, crpt) { +} + + +CFILE::~CFILE(void) { +} + + +void CFILE::Flush(void) { + if (Mode > REA) + WriteBuff(); + else + Lim = 0; + + /* + _BX = Handle; + _AH = 0x68; // Flush buffer + asm int 0x21 + */ + warning("FIXME: CFILE::Flush"); +} + + +long CFILE::Mark(void) { + return BufMark + ((Mode > REA) ? Lim : Ptr); +} + + +long CFILE::Seek(long pos) { + if (pos >= BufMark && pos < BufMark + Lim) { + ((Mode == REA) ? Ptr : Lim) = (uint16)(pos - BufMark); + return pos; + } else { + if (Mode > REA) + WriteBuff(); + else + Lim = 0; + + Ptr = 0; + return BufMark = IOHAND::Seek(pos); + } +} + + +void CFILE::Append(CFILE &f) { + Seek(Size()); + if (f.Error == 0) { + while (true) { + if ((Lim = f.IOHAND::Read(Buff, IOBUF_SIZE)) == IOBUF_SIZE) + WriteBuff(); + else + break; + if ((Error = f.Error) != 0) + break; + } } - } } } // End of namespace CGE diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index e8d494c2f9a..d2d5320ae55 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -25,59 +25,54 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CFILE__ -#define __CFILE__ +#ifndef __CFILE__ +#define __CFILE__ -#include "cge/general.h" -#include +#include "cge/general.h" +#include namespace CGE { -#define LINE_MAX 512 +#define LINE_MAX 512 -#ifndef IOBUF_SIZE - #define IOBUF_SIZE K(2) +#ifndef IOBUF_SIZE +#define IOBUF_SIZE K(2) #endif -#define CFREAD(x) Read((uint8 *)(x),sizeof(*(x))) +#define CFREAD(x) Read((uint8 *)(x),sizeof(*(x))) - - -class IOBUF : public IOHAND -{ +class IOBUF : public IOHAND { protected: - uint8 * Buff; - uint16 Ptr, Lim; - long BufMark; - uint16 Seed; - CRYPT * Crypt; - virtual void ReadBuff (void); - virtual void WriteBuff (void); + uint8 *Buff; + uint16 Ptr, Lim; + long BufMark; + uint16 Seed; + CRYPT *Crypt; + virtual void ReadBuff(void); + virtual void WriteBuff(void); public: - IOBUF (IOMODE mode, CRYPT * crpt = NULL); - IOBUF (const char * name, IOMODE mode, CRYPT * crpt = NULL); - virtual ~IOBUF (void); - uint16 Read (void * buf, uint16 len); - uint16 Read (uint8 * buf); - int Read (void); - uint16 Write (void * buf, uint16 len); - uint16 Write (uint8 * buf); - void Write (uint8 b); + IOBUF(IOMODE mode, CRYPT *crpt = NULL); + IOBUF(const char *name, IOMODE mode, CRYPT *crpt = NULL); + virtual ~IOBUF(void); + uint16 Read(void *buf, uint16 len); + uint16 Read(uint8 *buf); + int Read(void); + uint16 Write(void *buf, uint16 len); + uint16 Write(uint8 *buf); + void Write(uint8 b); }; - -class CFILE : public IOBUF -{ +class CFILE : public IOBUF { public: - static uint16 MaxLineLen; - CFILE (const char * name, IOMODE mode = REA, CRYPT * crpt = NULL); - virtual ~CFILE (void); - void Flush (void); - long Mark (void); - long Seek (long pos); - void Append (CFILE& f); + static uint16 MaxLineLen; + CFILE(const char *name, IOMODE mode = REA, CRYPT *crpt = NULL); + virtual ~CFILE(void); + void Flush(void); + long Mark(void); + long Seek(long pos); + void Append(CFILE &f); }; } // End of namespace CGE diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 5613c3bb686..0d0df4ea9cf 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -21,7 +21,6 @@ */ #include "common/scummsys.h" - #include "common/config-manager.h" #include "common/debug.h" #include "common/debug-channels.h" @@ -29,43 +28,41 @@ #include "common/EventRecorder.h" #include "common/file.h" #include "common/fs.h" - #include "engines/util.h" - #include "cge/cge.h" #include "cge/cge_main.h" - + namespace CGE { - + CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) - : Engine(syst), _gameDescription(gameDescription) { - + : Engine(syst), _gameDescription(gameDescription) { + DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel"); - _console = new CGEConsole(this); + _console = new CGEConsole(this); debug("CGEEngine::CGEEngine"); } - + CGEEngine::~CGEEngine() { debug("CGEEngine::~CGEEngine"); - + // Remove all of our debug levels here DebugMan.clearAllDebugChannels(); } - + Common::Error CGEEngine::run() { // Initialize graphics using following: initGraphics(320, 200, false); - - // Create debugger console. It requires GFX to be initialized + + // Create debugger console. It requires GFX to be initialized _console = new CGEConsole(this); - + // Additional setup. debug("CGEEngine::init"); - + cge_main(); - + return Common::kNoError; } - + } // End of namespace CGE diff --git a/engines/cge/cge.h b/engines/cge/cge.h index cb2c507ffae..c6d9a099bf6 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -22,7 +22,7 @@ #ifndef CGE_H #define CGE_H - + #include "common/random.h" #include "engines/engine.h" #include "gui/debugger.h" @@ -33,12 +33,12 @@ #define CGE_SAVEGAME_VERSION 1 namespace CGE { - + class Console; - + // our engine debug channels enum { - kCGEDebug = 1 << 0 + kCGEDebug = 1 << 0 }; class CGEEngine : public Engine { @@ -49,19 +49,21 @@ public: const ADGameDescription *_gameDescription; virtual Common::Error run(); - GUI::Debugger *getDebugger() { return _console; } - + GUI::Debugger *getDebugger() { + return _console; + } + private: CGEConsole *_console; }; - + // Example console class class Console : public GUI::Debugger { public: Console(CGEEngine *vm) {} virtual ~Console(void) {} }; - + } // End of namespace CGE - + #endif diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index cdbb94f785b..62936e8c9c8 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -25,57 +25,57 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/general.h" -#include "cge/boot.h" -#include "cge/ident.h" -#include "cge/sound.h" -#include "cge/startup.h" -#include "cge/config.h" -#include "cge/vga13h.h" -#include "cge/snail.h" -#include "cge/text.h" -#include "cge/game.h" -#include "cge/mouse.h" -#include "cge/keybd.h" -#include "cge/cfile.h" -#include "cge/vol.h" -#include "cge/talk.h" -#include "cge/vmenu.h" -#include "cge/gettext.h" -#include "cge/mixer.h" -#include "cge/cge_main.h" -#include -#include -#include -#include -#include -#include -#include +#include "cge/general.h" +#include "cge/boot.h" +#include "cge/ident.h" +#include "cge/sound.h" +#include "cge/startup.h" +#include "cge/config.h" +#include "cge/vga13h.h" +#include "cge/snail.h" +#include "cge/text.h" +#include "cge/game.h" +#include "cge/mouse.h" +#include "cge/keybd.h" +#include "cge/cfile.h" +#include "cge/vol.h" +#include "cge/talk.h" +#include "cge/vmenu.h" +#include "cge/gettext.h" +#include "cge/mixer.h" +#include "cge/cge_main.h" +#include +#include +#include +#include +#include +#include +#include #include "common/str.h" namespace CGE { -#define STACK_SIZ (K(2)) -#define SVGCHKSUM (1956+Now+OldLev+Game+Music+DemoText) +#define STACK_SIZ (K(2)) +#define SVGCHKSUM (1956+Now+OldLev+Game+Music+DemoText) -#ifdef DEMO - #ifdef DEBUG - #define SVG0NAME ("{{INIT}}" SVG_EXT) - #else - #define SVG0NAME (ProgName(SVG_EXT)) - #endif +#ifdef DEMO +#ifdef DEBUG +#define SVG0NAME ("{{INIT}}" SVG_EXT) #else - #define SVG0NAME ("{{INIT}}" SVG_EXT) +#define SVG0NAME (ProgName(SVG_EXT)) +#endif +#else +#define SVG0NAME ("{{INIT}}" SVG_EXT) #endif -#ifdef DEBUG - #define SVG0FILE CFILE +#ifdef DEBUG +#define SVG0FILE CFILE #else - #define SVG0FILE INI_FILE +#define SVG0FILE INI_FILE #endif -extern uint16 _stklen = (STACK_SIZ * 2); +extern uint16 _stklen = (STACK_SIZ * 2); // 0.75 - 17II95 - full sound support // 0.76 - 18II95 - small MiniEMS in DEMO, @@ -86,1715 +86,1398 @@ extern uint16 _stklen = (STACK_SIZ * 2); // coditionals EVA for 2-month evaluation version /* - char Copr[] = "Common Game Engine " - #ifdef EVA - "ú" - #else - #ifdef CD - "ù" - #else - " " - #endif - #endif - " version 1.05 [" - #if sizeof(INI_FILE) == sizeof(VFILE) - "I" - #else - "i" - #endif - #if sizeof(PIC_FILE) == sizeof(VFILE) - "B" - #else - "b" - #endif - "]\n" - "Copyright (c) 1994 by Janusz B. Wi$niewski"; + char Copr[] = "Common Game Engine " + #ifdef EVA + "ú" + #else + #ifdef CD + "ù" + #else + " " + #endif + #endif + " version 1.05 [" + #if sizeof(INI_FILE) == sizeof(VFILE) + "I" + #else + "i" + #endif + #if sizeof(PIC_FILE) == sizeof(VFILE) + "B" + #else + "b" + #endif + "]\n" + "Copyright (c) 1994 by Janusz B. Wi$niewski"; */ - char Copr[] = "To be fixed - Copr[]"; +char Copr[] = "To be fixed - Copr[]"; -static char UsrFnam[15] = "\0ɱ%^þúȼ´ ÇÉ"; -static int OldLev = 0; -static int DemoText = DEMO_TEXT; +static char UsrFnam[15] = "\0ɱ%^þúȼ´ ÇÉ"; +static int OldLev = 0; +static int DemoText = DEMO_TEXT; //-------------------------------------------------------------------------- - bool JBW = false; - DAC *SysPal = farnew(DAC, PAL_CNT); +bool JBW = false; +DAC *SysPal = farnew(DAC, PAL_CNT); //------------------------------------------------------------------------- - SPRITE PocLight = LI; - SPRITE * Pocket[POCKET_NX]={ NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, }; - int PocPtr = 0; -//------------------------------------------------------------------------- -//extern SPRITE * PocLight; -//extern SPRITE * Pocket[]; -//extern int PocPtr; -//------------------------------------------------------------------------- +SPRITE PocLight = LI; +SPRITE *Pocket[POCKET_NX] = { NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, + }; +int PocPtr = 0; - MOUSE Mouse; -static SPRITE * Sprite = NULL; -static SPRITE * MiniCave = NULL; -static SPRITE * Shadow = NULL; +MOUSE Mouse; +static SPRITE *Sprite = NULL; +static SPRITE *MiniCave = NULL; +static SPRITE *Shadow = NULL; -static VGA Vga = M13H; -static EMS * Mini = MiniEmm.Alloc((uint16)MINI_EMM_SIZE); -static BMP_PTR * MiniShpList = NULL; -static BMP_PTR MiniShp[] = { NULL, NULL }; -static KEYBOARD Keyboard; -static bool Finis = false; -static int Startup = 1; -static int OffUseCount = atoi(Text[OFF_USE_COUNT]); - uint16 *intStackPtr = false; +static VGA Vga = M13H; +static EMS *Mini = MiniEmm.Alloc((uint16)MINI_EMM_SIZE); +static BMP_PTR *MiniShpList = NULL; +static BMP_PTR MiniShp[] = { NULL, NULL }; +static KEYBOARD Keyboard; +static bool Finis = false; +static int Startup = 1; +static int OffUseCount = atoi(Text[OFF_USE_COUNT]); +uint16 *intStackPtr = false; - HXY HeroXY[CAVE_MAX] = {{0,0}}; - BAR Barriers[1+CAVE_MAX] = { { 0xFF, 0xFF } }; +HXY HeroXY[CAVE_MAX] = {{0, 0}}; +BAR Barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; -extern int FindPocket (SPRITE *); +extern int FindPocket(SPRITE *); -extern DAC StdPal[58]; +extern DAC StdPal[58]; -#ifdef DEBUG -static SPRITE HorzLine = HL; +#ifdef DEBUG +static SPRITE HorzLine = HL; #endif +void FeedSnail(SPRITE *spr, SNLIST snq); // defined in SNAIL +uint8 CLUSTER::Map[MAP_ZCNT][MAP_XCNT]; -void FeedSnail (SPRITE * spr, SNLIST snq); // defined in SNAIL - -//-------------------------------------------------------------------------- - - - - -uint8 CLUSTER::Map[MAP_ZCNT][MAP_XCNT]; - - - -uint8 & CLUSTER::Cell (void) -{ - return Map[B][A]; +uint8 &CLUSTER::Cell(void) { + return Map[B][A]; } - - - - - - -bool CLUSTER::Protected (void) -{ - if (A == Barriers[Now].Vert || B == Barriers[Now].Horz) return true; - warning("STUB: CLUSTER::Protected()"); - /* - _DX = (MAP_ZCNT << 8) + MAP_XCNT; - _BX = (uint16) this; - - asm mov ax,1 - asm mov cl,[bx].(COUPLE)A - asm mov ch,[bx].(COUPLE)B - asm test cx,0x8080 // (A < 0) || (B < 0) - asm jnz xit - - asm cmp cl,dl - asm jge xit - asm cmp ch,dh - asm jge xit - -// if (A < 0 || A >= MAP_XCNT || B < 0 || B >= MAP_ZCNT) return true; - - asm mov al,dl - asm mul ch - asm xor ch,ch - asm add ax,cx - asm mov bx,ax - _BX += (uint16) Map; - //asm add bx,offset CLUSTER::Map - asm mov al,[bx] - asm and ax,0xFF - asm jz xit - asm mov ax,1 - -// return Map[B][A] != 0; - - xit: return _AX; - */ - return TRUE; -} - - - - - -CLUSTER XZ (int x, int y) -{ - if (y < MAP_TOP) y = MAP_TOP; - if (y > MAP_TOP + MAP_HIG - MAP_ZGRID) y = MAP_TOP + MAP_HIG - MAP_ZGRID; - return CLUSTER(x / MAP_XGRID, (y-MAP_TOP) / MAP_ZGRID); -} - - - - -CLUSTER XZ (COUPLE xy) -{ - signed char x, y; - xy.Split(x, y); - return XZ(x, y); -} - - - - - - - -//-------------------------------------------------------------------------- - - - int pocref[POCKET_NX]; - uint8 volume[2]; - struct SAVTAB { void * Ptr; int Len; uint8 Flg; } SavTab[] = - {{ &Now, sizeof(Now), 1 }, - { &OldLev, sizeof(OldLev), 1 }, - { &DemoText, sizeof(DemoText), 1 }, - { &Game, sizeof(Game), 1 }, - { &Game, sizeof(Game), 1 }, // spare 1 - { &Game, sizeof(Game), 1 }, // spare 2 - { &Game, sizeof(Game), 1 }, // spare 3 - { &Game, sizeof(Game), 1 }, // spare 4 - { &VGA::Mono, sizeof(VGA::Mono), 0 }, - { &Music, sizeof(Music), 1 }, - { volume, sizeof(volume), 1 }, - - { Flag, sizeof(Flag), 1 }, - { HeroXY, sizeof(HeroXY), 1 }, - { Barriers, sizeof(Barriers), 1 }, - { pocref, sizeof(pocref), 1 }, - { NULL, 0, 0 } }; - - - - - -static void LoadGame (XFILE& file, bool tiny = false) -{ - SAVTAB * st; - SPRITE * spr; - int i; - - for (st = SavTab; st->Ptr; st ++) - { - if (file.Error) - error("Bad SVG"); - file.Read((uint8 *) ((tiny || st->Flg) ? st->Ptr : &i), st->Len); - } - - file.Read((uint8 *) &i, sizeof(i)); - if (i != SVGCHKSUM) - error(Text[BADSVG_TEXT]); - if (STARTUP::Core < CORE_HIG) Music = false; - if (STARTUP::SoundOk == 1 && STARTUP::Mode == 0) { - SNDDrvInfo.VOL2.D = volume[0]; - SNDDrvInfo.VOL2.M = volume[1]; - SNDSetVolume(); - } - - if (! tiny) // load sprites & pocket - { - while (! file.Error) - { - SPRITE S(NULL); - uint16 n = file.Read((uint8 *) &S, sizeof(S)); - - if (n != sizeof(S)) break; - S.Prev = S.Next = NULL; - spr = (scumm_stricmp(S.File+2, "MUCHA") == 0) ? new FLY(NULL) - : new SPRITE(NULL); - if (spr == NULL) - error("No core"); - *spr = S; - VGA::SpareQ.Append(spr); - } - - for (i = 0; i < POCKET_NX; i ++) - { - register int r = pocref[i]; - Pocket[i] = (r < 0) ? NULL : VGA::SpareQ.Locate(r); - } - } -} - - - - -static void SaveSound (void) -{ - CFILE cfg(UsrPath(ProgName(CFG_EXT)), WRI); - if (! cfg.Error) cfg.Write(&SNDDrvInfo,sizeof(SNDDrvInfo)-sizeof(SNDDrvInfo.VOL2)); -} - - - - - - -static void SaveGame (XFILE& file) -{ - SAVTAB * st; - SPRITE * spr; - int i; - - for (i = 0; i < POCKET_NX; i ++) - { - register SPRITE * s = Pocket[i]; - pocref[i] = (s) ? s->Ref : -1; - } - - volume[0] = SNDDrvInfo.VOL2.D; - volume[1] = SNDDrvInfo.VOL2.M; - - for (st = SavTab; st->Ptr; st ++) - { - if (file.Error) - error("Bad SVG"); - file.Write((uint8 *) st->Ptr, st->Len); - } - - file.Write((uint8 *) &(i = SVGCHKSUM), sizeof(i)); - - for (spr = VGA::SpareQ.First(); spr; spr = spr->Next) - if (spr->Ref >= 1000) - if (!file.Error) file.Write((uint8 *)spr, sizeof(*spr)); -} - - - - - - - -static void HeroCover (int cvr) -{ - SNPOST(SNCOVER, 1, cvr, NULL); -} - - - - -static void Trouble (int seq, int txt) -{ - Hero->Park(); - SNPOST(SNWAIT, -1, -1, Hero); - SNPOST(SNSEQ, -1, seq, Hero); - SNPOST(SNSOUND, -1, 2, Hero); - SNPOST(SNWAIT, -1, -1, Hero); - SNPOST(SNSAY, 1, txt, Hero); -} - - - -static void OffUse (void) -{ - Trouble(OFF_USE, OFF_USE_TEXT+new_random(OffUseCount)); -} - - - - -static void TooFar (void) -{ - Trouble(TOO_FAR, TOO_FAR_TEXT); -} - - - - -static void NoWay (void) -{ - Trouble(NO_WAY, NO_WAY_TEXT); -} - - - - - -static void LoadHeroXY (void) -{ - INI_FILE cf(ProgName(".HXY")); - memset(HeroXY, 0, sizeof(HeroXY)); - if (! cf.Error) cf.CFREAD(&HeroXY); -} - - - - - -static void LoadMapping (void) -{ - if (Now <= CAVE_MAX) - { - INI_FILE cf(ProgName(".TAB")); - if (! cf.Error) - { - memset(CLUSTER::Map, 0, sizeof(CLUSTER::Map)); - cf.Seek((Now - 1) * sizeof(CLUSTER::Map)); - cf.Read((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); - } - } -} - - - - - - -//-------------------------------------------------------------------------- - -CLUSTER Trace[MAX_FIND_LEVEL]; -int FindLevel; - - - - - - - - -WALK::WALK (BMP_PTR * shpl) -: SPRITE(shpl), Dir(NO_DIR), TracePtr(-1) -{ -} - - - - - -void WALK::Tick (void) -{ - if (Flags.Hide) return; - - Here = XZ(X+W/2, Y+H); - - if (Dir != NO_DIR) - { - SPRITE * spr; - SYSTEM::FunTouch(); - for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) - { - if (Distance(spr) < 2) - { - if (! spr->Flags.Near) - { - FeedSnail(spr, NEAR); - spr->Flags.Near = true; - } - } - else spr->Flags.Near = false; - } - } - - if (Flags.Hold || TracePtr < 0) Park(); - else - { - if (Here == Trace[TracePtr]) - { - if (-- TracePtr < 0) Park(); - } - else - { - signed char dx, dz; - (Trace[TracePtr] - Here).Split(dx, dz); - DIR d = (dx) ? ((dx > 0) ? EE : WW) : ((dz > 0) ? SS : NN); - Turn(d); - } - } - Step(); - if ((Dir == WW && X <= 0) || - (Dir == EE && X + W >= SCR_WID) || - (Dir == SS && Y + W >= WORLD_HIG-2)) Park(); - else - { - signed char x; // dummy var - Here.Split(x, Z); // take current Z position - SNPOST_(SNZTRIM, -1, 0, this); // update Hero's pos in show queue - } -} - - - - - - -int WALK::Distance (SPRITE * spr) -{ - int dx, dz; - dx = spr->X - (X+W-WALKSIDE); - if (dx < 0) dx = (X+WALKSIDE) - (spr->X+spr->W); - if (dx < 0) dx = 0; - dx /= MAP_XGRID; - dz = spr->Z - Z; - if (dz < 0) dz = - dz; - dx = dx * dx + dz * dz; - for (dz = 1; dz * dz < dx; dz ++) ; - return dz-1; -} - - - - - - - - - - -void WALK::Turn (DIR d) -{ - DIR dir = (Dir == NO_DIR) ? SS : Dir; - if (d != Dir) - { - Step((d == dir) ? (1 + dir + dir) : (9 + 4 * dir + d)); - Dir = d; - } -} - - - - - -void WALK::Park (void) -{ - if (Time == 0) ++ Time; - if (Dir != NO_DIR) - { - Step(9 + 4 * Dir + Dir); - Dir = NO_DIR; - TracePtr = -1; - } -} - - - - - - - -void WALK::FindWay (CLUSTER c) -{ - warning("STUB: Find1Way"); +bool CLUSTER::Protected(void) { /* - bool Find1Way(void); - extern uint16 Target; + if (A == Barriers[Now].Vert || B == Barriers[Now].Horz) + return true; - if (c != Here) - { - for (FindLevel = 1; FindLevel <= MAX_FIND_LEVEL; FindLevel ++) - { - signed char x, z; - Here.Split(x, z); - Target = (z << 8) | x; - c.Split(x, z); - _CX = (z << 8) | x; - if (Find1Way()) break; + _DX = (MAP_ZCNT << 8) + MAP_XCNT; + _BX = (uint16) this; + + asm mov ax,1 + asm mov cl,[bx].(COUPLE)A + asm mov ch,[bx].(COUPLE)B + asm test cx,0x8080 // (A < 0) || (B < 0) + asm jnz xit + + asm cmp cl,dl + asm jge xit + asm cmp ch,dh + asm jge xit + + // if (A < 0 || A >= MAP_XCNT || B < 0 || B >= MAP_ZCNT) return true; + + asm mov al,dl + asm mul ch + asm xor ch,ch + asm add ax,cx + asm mov bx,ax + _BX += (uint16) Map; + //asm add bx,offset CLUSTER::Map + asm mov al,[bx] + asm and ax,0xFF + asm jz xit + asm mov ax,1 + + // return Map[B][A] != 0; + + xit: return _AX; + */ + + warning("STUB: CLUSTER::Protected()"); + return TRUE; +} + + +CLUSTER XZ(int x, int y) { + if (y < MAP_TOP) + y = MAP_TOP; + + if (y > MAP_TOP + MAP_HIG - MAP_ZGRID) + y = MAP_TOP + MAP_HIG - MAP_ZGRID; + + return CLUSTER(x / MAP_XGRID, (y - MAP_TOP) / MAP_ZGRID); +} + + +CLUSTER XZ(COUPLE xy) { + signed char x, y; + xy.Split(x, y); + return XZ(x, y); +} + + +int pocref[POCKET_NX]; +uint8 volume[2]; + +struct SAVTAB { + void *Ptr; + int Len; + uint8 Flg; +} SavTab[] = { + { &Now, sizeof(Now), 1 }, + { &OldLev, sizeof(OldLev), 1 }, + { &DemoText, sizeof(DemoText), 1 }, + { &Game, sizeof(Game), 1 }, + { &Game, sizeof(Game), 1 }, // spare 1 + { &Game, sizeof(Game), 1 }, // spare 2 + { &Game, sizeof(Game), 1 }, // spare 3 + { &Game, sizeof(Game), 1 }, // spare 4 + { &VGA::Mono, sizeof(VGA::Mono), 0 }, + { &Music, sizeof(Music), 1 }, + { volume, sizeof(volume), 1 }, + { Flag, sizeof(Flag), 1 }, + { HeroXY, sizeof(HeroXY), 1 }, + { Barriers, sizeof(Barriers), 1 }, + { pocref, sizeof(pocref), 1 }, + { NULL, 0, 0 } +}; + + +static void LoadGame(XFILE &file, bool tiny = false) { + SAVTAB *st; + SPRITE *spr; + int i; + + for (st = SavTab; st->Ptr; st ++) { + if (file.Error) + error("Bad SVG"); + file.Read((uint8 *)((tiny || st->Flg) ? st->Ptr : &i), st->Len); + } + + file.Read((uint8 *) &i, sizeof(i)); + if (i != SVGCHKSUM) + error(Text[BADSVG_TEXT]); + + if (STARTUP::Core < CORE_HIG) + Music = false; + + if (STARTUP::SoundOk == 1 && STARTUP::Mode == 0) { + SNDDrvInfo.VOL2.D = volume[0]; + SNDDrvInfo.VOL2.M = volume[1]; + SNDSetVolume(); + } + + if (! tiny) { // load sprites & pocket + while (! file.Error) { + SPRITE S(NULL); + uint16 n = file.Read((uint8 *) &S, sizeof(S)); + + if (n != sizeof(S)) + break; + + S.Prev = S.Next = NULL; + spr = (scumm_stricmp(S.File + 2, "MUCHA") == 0) ? new FLY(NULL) + : new SPRITE(NULL); + if (spr == NULL) + error("No core"); + *spr = S; + VGA::SpareQ.Append(spr); + } + + for (i = 0; i < POCKET_NX; i ++) { + register int r = pocref[i]; + Pocket[i] = (r < 0) ? NULL : VGA::SpareQ.Locate(r); + } + } +} + + +static void SaveSound(void) { + CFILE cfg(UsrPath(ProgName(CFG_EXT)), WRI); + if (! cfg.Error) cfg.Write(&SNDDrvInfo, sizeof(SNDDrvInfo) - sizeof(SNDDrvInfo.VOL2)); +} + + +static void SaveGame(XFILE &file) { + SAVTAB *st; + SPRITE *spr; + int i; + + for (i = 0; i < POCKET_NX; i ++) { + register SPRITE *s = Pocket[i]; + pocref[i] = (s) ? s->Ref : -1; + } + + volume[0] = SNDDrvInfo.VOL2.D; + volume[1] = SNDDrvInfo.VOL2.M; + + for (st = SavTab; st->Ptr; st ++) { + if (file.Error) + error("Bad SVG"); + file.Write((uint8 *) st->Ptr, st->Len); + } + + file.Write((uint8 *) & (i = SVGCHKSUM), sizeof(i)); + + for (spr = VGA::SpareQ.First(); spr; spr = spr->Next) + if (spr->Ref >= 1000) + if (!file.Error) + file.Write((uint8 *)spr, sizeof(*spr)); +} + + +static void HeroCover(int cvr) { + SNPOST(SNCOVER, 1, cvr, NULL); +} + + +static void Trouble(int seq, int txt) { + Hero->Park(); + SNPOST(SNWAIT, -1, -1, Hero); + SNPOST(SNSEQ, -1, seq, Hero); + SNPOST(SNSOUND, -1, 2, Hero); + SNPOST(SNWAIT, -1, -1, Hero); + SNPOST(SNSAY, 1, txt, Hero); +} + + +static void OffUse(void) { + Trouble(OFF_USE, OFF_USE_TEXT + new_random(OffUseCount)); +} + + +static void TooFar(void) { + Trouble(TOO_FAR, TOO_FAR_TEXT); +} + + +static void NoWay(void) { + Trouble(NO_WAY, NO_WAY_TEXT); +} + + +static void LoadHeroXY(void) { + INI_FILE cf(ProgName(".HXY")); + memset(HeroXY, 0, sizeof(HeroXY)); + if (! cf.Error) + cf.CFREAD(&HeroXY); +} + + +static void LoadMapping(void) { + if (Now <= CAVE_MAX) { + INI_FILE cf(ProgName(".TAB")); + if (! cf.Error) { + memset(CLUSTER::Map, 0, sizeof(CLUSTER::Map)); + cf.Seek((Now - 1) * sizeof(CLUSTER::Map)); + cf.Read((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); + } + } +} + + +CLUSTER Trace[MAX_FIND_LEVEL]; +int FindLevel; + + +WALK::WALK(BMP_PTR *shpl) + : SPRITE(shpl), Dir(NO_DIR), TracePtr(-1) { +} + + +void WALK::Tick(void) { + if (Flags.Hide) + return; + + Here = XZ(X + W / 2, Y + H); + + if (Dir != NO_DIR) { + SPRITE *spr; + SYSTEM::FunTouch(); + for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { + if (Distance(spr) < 2) { + if (! spr->Flags.Near) { + FeedSnail(spr, NEAR); + spr->Flags.Near = true; + } + } else spr->Flags.Near = false; + } + } + + if (Flags.Hold || TracePtr < 0) + Park(); + else { + if (Here == Trace[TracePtr]) { + if (-- TracePtr < 0) + Park(); + } else { + signed char dx, dz; + (Trace[TracePtr] - Here).Split(dx, dz); + DIR d = (dx) ? ((dx > 0) ? EE : WW) : ((dz > 0) ? SS : NN); + Turn(d); + } + } + Step(); + if ((Dir == WW && X <= 0) || + (Dir == EE && X + W >= SCR_WID) || + (Dir == SS && Y + W >= WORLD_HIG - 2)) + Park(); + else { + signed char x; // dummy var + Here.Split(x, Z); // take current Z position + SNPOST_(SNZTRIM, -1, 0, this); // update Hero's pos in show queue + } +} + + +int WALK::Distance(SPRITE *spr) { + int dx, dz; + dx = spr->X - (X + W - WALKSIDE); + if (dx < 0) + dx = (X + WALKSIDE) - (spr->X + spr->W); + + if (dx < 0) + dx = 0; + + dx /= MAP_XGRID; + dz = spr->Z - Z; + if (dz < 0) + dz = - dz; + + dx = dx * dx + dz * dz; + for (dz = 1; dz * dz < dx; dz ++) + ; + + return dz - 1; +} + + +void WALK::Turn(DIR d) { + DIR dir = (Dir == NO_DIR) ? SS : Dir; + if (d != Dir) { + Step((d == dir) ? (1 + dir + dir) : (9 + 4 * dir + d)); + Dir = d; + } +} + + +void WALK::Park(void) { + if (Time == 0) + ++Time; + + if (Dir != NO_DIR) { + Step(9 + 4 * Dir + Dir); + Dir = NO_DIR; + TracePtr = -1; + } +} + + +void WALK::FindWay(CLUSTER c) { + warning("STUB: Find1Way"); + /* + bool Find1Way(void); + extern uint16 Target; + + if (c != Here) { + for (FindLevel = 1; FindLevel <= MAX_FIND_LEVEL; FindLevel ++) { + signed char x, z; + Here.Split(x, z); + Target = (z << 8) | x; + c.Split(x, z); + _CX = (z << 8) | x; + if (Find1Way()) + break; + } + TracePtr = (FindLevel > MAX_FIND_LEVEL) ? -1 : (FindLevel - 1); + if (TracePtr < 0) + NoWay(); + Time = 1; } - TracePtr = (FindLevel > MAX_FIND_LEVEL) ? -1 : (FindLevel - 1); - if (TracePtr < 0) NoWay(); - Time = 1; - } */ } - - - - -void WALK::FindWay (SPRITE * spr) -{ - if (spr && spr != this) - { - int x = spr->X, z = spr->Z; - if (spr->Flags.East) x += spr->W + W/2 - WALKSIDE; - else x -= W/2 - WALKSIDE; - FindWay(CLUSTER((x/MAP_XGRID), - ((z < MAP_ZCNT-MAX_DISTANCE) ? (z+1) - : (z-1)))); - } -} - - - - - - -bool WALK::Lower (SPRITE * spr) -{ - return (spr->Y > Y + (H * 3) / 5); -} - - - - - - -void WALK::Reach (SPRITE * spr, int mode) -{ - if (spr) - { - Hero->FindWay(spr); - if (mode < 0) - { - mode = spr->Flags.East; - if (Lower(spr)) mode += 2; +void WALK::FindWay(SPRITE *spr) { + if (spr && spr != this) { + int x = spr->X, z = spr->Z; + if (spr->Flags.East) + x += spr->W + W / 2 - WALKSIDE; + else + x -= W / 2 - WALKSIDE; + FindWay(CLUSTER((x / MAP_XGRID), + ((z < MAP_ZCNT - MAX_DISTANCE) ? (z + 1) + : (z - 1)))); } - } - // note: insert SNAIL commands in reverse order - SNINSERT(SNPAUSE, -1, 64, NULL); - SNINSERT(SNSEQ, -1, TSEQ + mode, this); - if (spr) - { - SNINSERT(SNWAIT, -1, -1, Hero); /////--------$$$$$$$ - //SNINSERT(SNWALK, -1, -1, spr); - } - // sequence is not finished, - // now it is just at sprite appear (disappear) point } +bool WALK::Lower(SPRITE *spr) { + return (spr->Y > Y + (H * 3) / 5); +} - - -//-------------------------------------------------------------------------- - +void WALK::Reach(SPRITE *spr, int mode) { + if (spr) { + Hero->FindWay(spr); + if (mode < 0) { + mode = spr->Flags.East; + if (Lower(spr)) + mode += 2; + } + } + // note: insert SNAIL commands in reverse order + SNINSERT(SNPAUSE, -1, 64, NULL); + SNINSERT(SNSEQ, -1, TSEQ + mode, this); + if (spr) { + SNINSERT(SNWAIT, -1, -1, Hero); /////--------$$$$$$$ + //SNINSERT(SNWALK, -1, -1, spr); + } + // sequence is not finished, + // now it is just at sprite appear (disappear) point +} #ifdef DEBUG - -class SQUARE : public SPRITE -{ +class SQUARE : public SPRITE { public: - SQUARE (void); - void Touch (uint16 mask, int x, int y); + SQUARE(void); + void Touch(uint16 mask, int x, int y); }; - - - - -SQUARE::SQUARE (void) -: SPRITE(MB) -{ - Flags.Kill = true; - Flags.BDel = false; +SQUARE::SQUARE(void) + : SPRITE(MB) { + Flags.Kill = true; + Flags.BDel = false; } - - - - - - -void SQUARE::Touch (uint16 mask, int x, int y) -{ - SPRITE::Touch(mask, x, y); - if (mask & L_UP) - { - XZ(X+x, Y+y).Cell() = 0; - SNPOST_(SNKILL, -1, 0, this); - } +void SQUARE::Touch(uint16 mask, int x, int y) { + SPRITE::Touch(mask, x, y); + if (mask & L_UP) { + XZ(X + x, Y + y).Cell() = 0; + SNPOST_(SNKILL, -1, 0, this); + } } - - - - -static void SetMapBrick (int x, int z) -{ - SQUARE * s = new SQUARE; - if (s) - { - static char n[] = "00:00"; - s->Goto(x * MAP_XGRID, MAP_TOP + z * MAP_ZGRID); - wtom(x, n+0, 10, 2); - wtom(z, n+3, 10, 2); - CLUSTER::Map[z][x] = 1; - s->SetName(n); - VGA::ShowQ.Insert(s, VGA::ShowQ.First()); - } +static void SetMapBrick(int x, int z) { + SQUARE *s = new SQUARE; + if (s) { + static char n[] = "00:00"; + s->Goto(x * MAP_XGRID, MAP_TOP + z * MAP_ZGRID); + wtom(x, n + 0, 10, 2); + wtom(z, n + 3, 10, 2); + CLUSTER::Map[z][x] = 1; + s->SetName(n); + VGA::ShowQ.Insert(s, VGA::ShowQ.First()); + } } - #endif - -//-------------------------------------------------------------------------- - -void dummy (void) { } -static void SwitchMapping (void); -static void SwitchColorMode (void); -static void StartCountDown (void); -Debug(static void SwitchDebug (void); ) -static void SwitchMusic (void); -static void KillSprite (void); -static void PushSprite (void); -static void PullSprite (void); -static void BackPaint (void); -static void NextStep (void); -static void SaveMapping (void); +void dummy(void) {} +static void SwitchMapping(void); +static void SwitchColorMode(void); +static void StartCountDown(void); +Debug(static void SwitchDebug(void);) +static void SwitchMusic(void); +static void KillSprite(void); +static void PushSprite(void); +static void PullSprite(void); +static void BackPaint(void); +static void NextStep(void); +static void SaveMapping(void); - WALK * Hero = NULL; -static INFO_LINE InfoLine = INFO_W; - -static HEART Heart; - -static SPRITE CavLight = PR; +WALK *Hero = NULL; +static INFO_LINE InfoLine = INFO_W; +static HEART Heart; +static SPRITE CavLight = PR; - - - -static void KeyClick (void) -{ - SNPOST_(SNSOUND, -1, 5, NULL); +static void KeyClick(void) { + SNPOST_(SNSOUND, -1, 5, NULL); } - -static void ResetQSwitch (void) -{ - SNPOST_(SNSEQ, 123, 0, NULL); - KeyClick(); +static void ResetQSwitch(void) { + SNPOST_(SNSEQ, 123, 0, NULL); + KeyClick(); } +static void Quit(void) { + static CHOICE QuitMenu[] = { { NULL, StartCountDown }, + { NULL, ResetQSwitch }, + { NULL, dummy } + }; - -static void Quit (void) -{ - static CHOICE QuitMenu[]={ { NULL, StartCountDown }, - { NULL, ResetQSwitch }, - { NULL, dummy } }; - - if (Snail.Idle() && ! Hero->Flags.Hide) - { - if (VMENU::Addr) - { - SNPOST_(SNKILL, -1, 0, VMENU::Addr); - ResetQSwitch(); + if (Snail.Idle() && ! Hero->Flags.Hide) { + if (VMENU::Addr) { + SNPOST_(SNKILL, -1, 0, VMENU::Addr); + ResetQSwitch(); + } else { + QuitMenu[0].Text = Text[QUIT_TEXT]; + QuitMenu[1].Text = Text[NOQUIT_TEXT]; + (new VMENU(QuitMenu, -1, -1))->SetName(Text[QUIT_TITLE]); + SNPOST_(SNSEQ, 123, 1, NULL); + KeyClick(); + } } - else - { - QuitMenu[0].Text = Text[QUIT_TEXT]; - QuitMenu[1].Text = Text[NOQUIT_TEXT]; - (new VMENU(QuitMenu, -1, -1))->SetName(Text[QUIT_TITLE]); - SNPOST_(SNSEQ, 123, 1, NULL); - KeyClick(); +} + + +static void AltCtrlDel(void) { +#if 0 + //def DEBUG + if (KEYBOARD::Key[LSHIFT] || KEYBOARD::Key[RSHIFT]) { + PostFlag = 0x1234; + POST(); + } else +#endif + SNPOST_(SNSAY, -1, A_C_D_TEXT, Hero); +} + + +static void MiniStep(int stp) { + if (stp < 0) + MiniCave->Flags.Hide = true; + else { + &*Mini; + *MiniShp[0] = *MiniShpList[stp]; + if (Fx.Current) + &*(Fx.Current->EAddr()); + + MiniCave->Flags.Hide = false; } - } } - - -static void AltCtrlDel (void) -{ - #if 0 - //def DEBUG - if (KEYBOARD::Key[LSHIFT] || KEYBOARD::Key[RSHIFT]) - { - PostFlag = 0x1234; - POST(); - } - else - #endif - SNPOST_(SNSAY, -1, A_C_D_TEXT, Hero); +static void PostMiniStep(int stp) { + static int recent = -2; + //TODO Change the SNPOST message send to a special way to send function pointer + //if (MiniCave && stp != recent) SNPOST_(SNEXEC, -1, recent = stp, (void *)&MiniStep); + warning("STUB: PostMiniStep()"); } +int SYSTEM::FunDel = HEROFUN0; -static void MiniStep (int stp) -{ - if (stp < 0) MiniCave->Flags.Hide = true; - else - { - &*Mini; - *MiniShp[0] = *MiniShpList[stp]; - if (Fx.Current) &*(Fx.Current->EAddr()); - MiniCave->Flags.Hide = false; - } -} - - - - - -static void PostMiniStep (int stp) -{ - static int recent = -2; - //TODO Change the SNPOST message send to a special way to send function pointer - //if (MiniCave && stp != recent) SNPOST_(SNEXEC, -1, recent = stp, (void *)&MiniStep); - warning("STUB: PostMiniStep()"); -} - - - -//-------------------------------------------------------------------------- - - - -int SYSTEM::FunDel = HEROFUN0; - - - - -void SYSTEM::SetPal (void) -{ - int i; - DAC * p = SysPal + 256-ArrayCount(StdPal); - for (i = 0; i < ArrayCount(StdPal); i ++) - { - p[i].R = StdPal[i].R >> 2; - p[i].G = StdPal[i].G >> 2; - p[i].B = StdPal[i].B >> 2; - } -} - - - - - -void SYSTEM::FunTouch (void) -{ - uint16 n = (PAIN) ? HEROFUN1 : HEROFUN0; - if (Talk == NULL || n > FunDel) FunDel = n; -} - - - - - - -static void ShowBak (int ref) -{ - SPRITE * spr = VGA::SpareQ.Locate(ref); - if (spr) - { - BITMAP::Pal = SysPal; - spr->Expand(); - BITMAP::Pal = NULL; - spr->Show(2); - VGA::CopyPage(1, 2); - SYSTEM::SetPal(); - spr->Contract(); - } -} - - - - - - -static void CaveUp (void) -{ - int BakRef = 1000 * Now; - if (Music) LoadMIDI(Now); - ShowBak(BakRef); - LoadMapping(); - Text.Preload(BakRef, BakRef+1000); - SPRITE * spr = VGA::SpareQ.First(); - while (spr) - { - SPRITE * n = spr->Next; - if (spr->Cave == Now || spr->Cave == 0) - if (spr->Ref != BakRef) - { - if (spr->Flags.Back) spr->BackShow(); - else ExpandSprite(spr); - } - spr = n; - } - if (SNDDrvInfo.DDEV) - { - Sound.Stop(); - Fx.Clear(); - Fx.Preload(0); - Fx.Preload(BakRef); - } - - if (Hero) - { - Hero->Goto(HeroXY[Now-1].X, HeroXY[Now-1].Y); - // following 2 lines trims Hero's Z position! - Hero->Tick(); - Hero->Time = 1; - Hero->Flags.Hide = false; - } - - if (! Dark) Vga.Sunset(); - VGA::CopyPage(0, 1); - SelectPocket(-1); - if (Hero) VGA::ShowQ.Insert(VGA::ShowQ.Remove(Hero)); - if (Shadow) - { - VGA::ShowQ.Remove(Shadow); - Shadow->MakeXlat(Glass(SysPal, 204, 204, 204)); - VGA::ShowQ.Insert(Shadow, Hero); - Shadow->Z = Hero->Z; - } - FeedSnail(VGA::ShowQ.Locate(BakRef+999), TAKE); - Vga.Show(); - Vga.CopyPage(1, 0); - Vga.Show(); - Vga.Sunrise(SysPal); - Dark = false; - if (! Startup) Mouse.On(); - HEART::Enable = true; -} - - - - - -static void CaveDown (void) -{ - SPRITE * spr; - Debug( if (! HorzLine.Flags.Hide) SwitchMapping(); ) - - for (spr = VGA::ShowQ.First(); spr; ) - { - SPRITE * n = spr->Next; - if (spr->Ref >= 1000 /*&& spr->Cave*/) - { - if (spr->Ref % 1000 == 999) FeedSnail(spr, TAKE); - VGA::SpareQ.Append(VGA::ShowQ.Remove(spr)); +void SYSTEM::SetPal(void) { + int i; + DAC *p = SysPal + 256 - ArrayCount(StdPal); + for (i = 0; i < ArrayCount(StdPal); i ++) { + p[i].R = StdPal[i].R >> 2; + p[i].G = StdPal[i].G >> 2; + p[i].B = StdPal[i].B >> 2; } - spr = n; - } - Text.Clear(1000); } - - - -static void XCave (void) -{ - CaveDown(); - CaveUp(); +void SYSTEM::FunTouch(void) { + uint16 n = (PAIN) ? HEROFUN1 : HEROFUN0; + if (Talk == NULL || n > FunDel) + FunDel = n; } - - -static void QGame (void) -{ - CaveDown(); - OldLev = Lev; - SaveSound(); - CFILE file = CFILE(UsrPath(UsrFnam), WRI, RCrypt); - SaveGame(file); - Vga.Sunset(); - Finis = true; -} - - - - -void SwitchCave (int cav) -{ - if (cav != Now) - { - HEART::Enable = false; - if (cav < 0) - { - SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - //TODO Change the SNPOST message send to a special way to send function pointer - //SNPOST(SNEXEC, -1, 0, (void *)&QGame); // switch cave - warning("SwitchCave() - SNPOST"); +static void ShowBak(int ref) { + SPRITE *spr = VGA::SpareQ.Locate(ref); + if (spr) { + BITMAP::Pal = SysPal; + spr->Expand(); + BITMAP::Pal = NULL; + spr->Show(2); + VGA::CopyPage(1, 2); + SYSTEM::SetPal(); + spr->Contract(); } - else - { - Now = cav; - Mouse.Off(); - if (Hero) - { - Hero->Park(); - Hero->Step(0); - #ifndef DEMO - ///// protection: auto-destruction on! ---------------------- - VGA::SpareQ.Show = STARTUP::Summa * (cav <= CAVE_MAX); - /////-------------------------------------------------------- - #endif - } - CavLight.Goto(CAVE_X + ((Now-1) % CAVE_NX) * CAVE_DX + CAVE_SX, - CAVE_Y + ((Now-1) / CAVE_NX) * CAVE_DY + CAVE_SY); - KillText(); - if (! Startup) KeyClick(); - SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - //TODO Change the SNPOST message send to a special way to send function pointer - //SNPOST(SNEXEC, 0, 0, (void *)&XCave); // switch cave - warning("SwitchCave() - SNPOST"); - } - } } +static void CaveUp(void) { + int BakRef = 1000 * Now; + if (Music) + LoadMIDI(Now); - - - -void SYSTEM::Touch (uint16 mask, int x, int y) -{ - static int pp = 0; - void SwitchCave (int cav); - int cav = 0; - - FunTouch(); - - if (mask & KEYB) - { - int pp0; - KeyClick(); - KillText(); - if (Startup == 1) - { - SNPOST(SNCLEAR, -1, 0, NULL); - return; + ShowBak(BakRef); + LoadMapping(); + Text.Preload(BakRef, BakRef + 1000); + SPRITE *spr = VGA::SpareQ.First(); + while (spr) { + SPRITE *n = spr->Next; + if (spr->Cave == Now || spr->Cave == 0) + if (spr->Ref != BakRef) { + if (spr->Flags.Back) + spr->BackShow(); + else + ExpandSprite(spr); + } + spr = n; } - pp0 = pp; - switch (x) - { - case Del : if (KEYBOARD::Key[ALT] && - KEYBOARD::Key[CTRL]) AltCtrlDel(); - Debug ( else KillSprite(); ) - break; - case 'F' : if (KEYBOARD::Key[ALT]) - { - SPRITE * m = VGA::ShowQ.Locate(17001); - if (m) - { - m->Step(1); - m->Time = 216; // 3s - } + if (SNDDrvInfo.DDEV) { + Sound.Stop(); + Fx.Clear(); + Fx.Preload(0); + Fx.Preload(BakRef); + } + + if (Hero) { + Hero->Goto(HeroXY[Now - 1].X, HeroXY[Now - 1].Y); + // following 2 lines trims Hero's Z position! + Hero->Tick(); + Hero->Time = 1; + Hero->Flags.Hide = false; + } + + if (! Dark) + Vga.Sunset(); + + VGA::CopyPage(0, 1); + SelectPocket(-1); + if (Hero) + VGA::ShowQ.Insert(VGA::ShowQ.Remove(Hero)); + + if (Shadow) { + VGA::ShowQ.Remove(Shadow); + Shadow->MakeXlat(Glass(SysPal, 204, 204, 204)); + VGA::ShowQ.Insert(Shadow, Hero); + Shadow->Z = Hero->Z; + } + FeedSnail(VGA::ShowQ.Locate(BakRef + 999), TAKE); + Vga.Show(); + Vga.CopyPage(1, 0); + Vga.Show(); + Vga.Sunrise(SysPal); + Dark = false; + if (! Startup) + Mouse.On(); + + HEART::Enable = true; +} + + +static void CaveDown(void) { + SPRITE *spr; + Debug(if (! HorzLine.Flags.Hide) SwitchMapping();) + + for (spr = VGA::ShowQ.First(); spr;) { + SPRITE *n = spr->Next; + if (spr->Ref >= 1000 /*&& spr->Cave*/) { + if (spr->Ref % 1000 == 999) + FeedSnail(spr, TAKE); + + VGA::SpareQ.Append(VGA::ShowQ.Remove(spr)); + } + spr = n; + } + Text.Clear(1000); +} + + +static void XCave(void) { + CaveDown(); + CaveUp(); +} + + +static void QGame(void) { + CaveDown(); + OldLev = Lev; + SaveSound(); + CFILE file = CFILE(UsrPath(UsrFnam), WRI, RCrypt); + SaveGame(file); + Vga.Sunset(); + Finis = true; +} + + +void SwitchCave(int cav) { + if (cav != Now) { + HEART::Enable = false; + if (cav < 0) { + SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST(SNEXEC, -1, 0, (void *)&QGame); // switch cave + warning("SwitchCave() - SNPOST"); + } else { + Now = cav; + Mouse.Off(); + if (Hero) { + Hero->Park(); + Hero->Step(0); +#ifndef DEMO + ///// protection: auto-destruction on! ---------------------- + VGA::SpareQ.Show = STARTUP::Summa * (cav <= CAVE_MAX); + /////-------------------------------------------------------- +#endif + } + CavLight.Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, + CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); + KillText(); + if (! Startup) KeyClick(); + SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST(SNEXEC, 0, 0, (void *)&XCave); // switch cave + warning("SwitchCave() - SNPOST"); + } + } +} + + +void SYSTEM::Touch(uint16 mask, int x, int y) { + static int pp = 0; + void SwitchCave(int cav); + int cav = 0; + + FunTouch(); + + if (mask & KEYB) { + int pp0; + KeyClick(); + KillText(); + if (Startup == 1) { + SNPOST(SNCLEAR, -1, 0, NULL); + return; + } + pp0 = pp; + switch (x) { + case Del: + if (KEYBOARD::Key[ALT] && + KEYBOARD::Key[CTRL]) AltCtrlDel(); + Debug(else KillSprite();) + break; + case 'F': + if (KEYBOARD::Key[ALT]) { + SPRITE *m = VGA::ShowQ.Locate(17001); + if (m) { + m->Step(1); + m->Time = 216; // 3s } - break; + } + break; - #ifdef DEBUG - case PgUp : PushSprite(); break; - case PgDn : PullSprite(); break; - case '+' : NextStep(); break; - case '`' : if (KEYBOARD::Key[ALT]) SaveMapping(); else SwitchMapping(); break; - case F1 : SwitchDebug(); break; - case F3 : Hero->Step(TSEQ + 4); break; - case F4 : Hero->Step(TSEQ + 5); break; - case F5 : Hero->Step(TSEQ + 0); break; - case F6 : Hero->Step(TSEQ + 1); break; - case F7 : Hero->Step(TSEQ + 2); break; - case F8 : Hero->Step(TSEQ + 3); break; - case F9 : SYSTEM::FunDel = 1; break; - case 'X' : if (KEYBOARD::Key[ALT]) Finis = true; break; - case '0' : - case '1' : - case '2' : - case '3' : - case '4' : if (KEYBOARD::Key[ALT]) { SNPOST(SNLEVEL, -1, x - '0', NULL); break; } - case '5' : - case '6' : - case '7' : - case '8' : - case '9' : if (Sprite) Sprite->Step(x - '0'); break; - #else - case '1' : - case '2' : - case '3' : - case '4' : - case '5' : - case '6' : - case '7' : - case '8' : SelectPocket(x - '1'); break; - #endif +#ifdef DEBUG + case PgUp: + PushSprite(); + break; + case PgDn: + PullSprite(); + break; + case '+': + NextStep(); + break; + case '`': + if (KEYBOARD::Key[ALT]) + SaveMapping(); + else + SwitchMapping(); + break; + case F1: + SwitchDebug(); + break; + case F3: + Hero->Step(TSEQ + 4); + break; + case F4: + Hero->Step(TSEQ + 5); + break; + case F5: + Hero->Step(TSEQ + 0); + break; + case F6: + Hero->Step(TSEQ + 1); + break; + case F7: + Hero->Step(TSEQ + 2); + break; + case F8: + Hero->Step(TSEQ + 3); + break; + case F9: + SYSTEM::FunDel = 1; + break; + case 'X': + if (KEYBOARD::Key[ALT]) + Finis = true; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + if (KEYBOARD::Key[ALT]) { + SNPOST(SNLEVEL, -1, x - '0', NULL); + break; + } + case '5': + case '6': + case '7': + case '8': + case '9': + if (Sprite) + Sprite->Step(x - '0'); + break; +#else + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + SelectPocket(x - '1'); + break; +#endif - case F10 : if (Snail.Idle() && ! Hero->Flags.Hide) + case F10 : + if (Snail.Idle() && ! Hero->Flags.Hide) StartCountDown(); - break; - case 'J' : if (pp == 0) ++ pp; break; - case 'B' : if (pp == 1) ++ pp; break; - case 'W' : if (pp == 2) JBW = !JBW; break; - } - if (pp == pp0) pp = 0; - } - else - { - if (Startup) return; - InfoLine.Update(NULL); - if (y >= WORLD_HIG) - { - if (x < BUTTON_X) // select cave? - { - if (y >= CAVE_Y && y < CAVE_Y + CAVE_NY * CAVE_DY && - x >= CAVE_X && x < CAVE_X + CAVE_NX * CAVE_DX && ! Game) - { - cav = ((y-CAVE_Y) / CAVE_DY) * CAVE_NX + (x-CAVE_X) / CAVE_DX + 1; - if (cav > MaxCave) cav = 0; + break; + case 'J': + if (pp == 0) + ++pp; + break; + case 'B': + if (pp == 1) + ++pp; + break; + case 'W': + if (pp == 2) + JBW = !JBW; + break; } - else - { - cav = 0; - } - } - else if (mask & L_UP) - { - if (y >= POCKET_Y && y < POCKET_Y + POCKET_NY * POCKET_DY && - x >= POCKET_X && x < POCKET_X + POCKET_NX * POCKET_DX) - { - int n = ((y-POCKET_Y) / POCKET_DY) * POCKET_NX + (x-POCKET_X) / POCKET_DX; - SelectPocket(n); - } - } - } + if (pp == pp0) + pp = 0; + } else { + if (Startup) + return; - PostMiniStep(cav-1); + InfoLine.Update(NULL); + if (y >= WORLD_HIG) { + if (x < BUTTON_X) { // select cave? + if (y >= CAVE_Y && y < CAVE_Y + CAVE_NY * CAVE_DY && + x >= CAVE_X && x < CAVE_X + CAVE_NX * CAVE_DX && ! Game) { + cav = ((y - CAVE_Y) / CAVE_DY) * CAVE_NX + (x - CAVE_X) / CAVE_DX + 1; + if (cav > MaxCave) + cav = 0; + } else { + cav = 0; + } + } else if (mask & L_UP) { + if (y >= POCKET_Y && y < POCKET_Y + POCKET_NY * POCKET_DY && + x >= POCKET_X && x < POCKET_X + POCKET_NX * POCKET_DX) { + int n = ((y - POCKET_Y) / POCKET_DY) * POCKET_NX + (x - POCKET_X) / POCKET_DX; + SelectPocket(n); + } + } + } - if (mask & L_UP) - { - if (cav && Snail.Idle() && Hero->TracePtr < 0) - { - SwitchCave(cav); - } - #ifdef DEBUG - if (! HorzLine.Flags.Hide) - { - if (y >= MAP_TOP && y < MAP_TOP+MAP_HIG) - { - signed char x1, z1; - XZ(x, y).Split(x1, z1); - CLUSTER::Map[z1][x1] = 1; - SetMapBrick(x1, z1); + PostMiniStep(cav - 1); + + if (mask & L_UP) { + if (cav && Snail.Idle() && Hero->TracePtr < 0) + SwitchCave(cav); + +#ifdef DEBUG + if (!HorzLine.Flags.Hide) { + if (y >= MAP_TOP && y < MAP_TOP + MAP_HIG) { + signed char x1, z1; + XZ(x, y).Split(x1, z1); + CLUSTER::Map[z1][x1] = 1; + SetMapBrick(x1, z1); + } + } else +#endif + { + if (! Talk && Snail.Idle() && Hero + && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && ! Game) { + Hero->FindWay(XZ(x, y)); + } + } } - } - else - #endif - { - if (! Talk && Snail.Idle() && Hero - && y >= MAP_TOP && y < MAP_TOP+MAP_HIG && ! Game) - { - Hero->FindWay(XZ(x, y)); - } - } } - } } - - - - - -void SYSTEM::Tick (void) -{ - if (! Startup) if (-- FunDel == 0) - { - KillText(); - if (Snail.Idle()) - { - if (PAIN) HeroCover(9); - else if (STARTUP::Core >= CORE_MID) - { - int n = new_random(100); - if (n > 96) HeroCover(6+(Hero->X+Hero->W/2 < SCR_WID/2)); - else - { - if (n > 90) HeroCover(5); - else - { - if (n > 60) HeroCover(4); - else HeroCover(3); - } +void SYSTEM::Tick(void) { + if (! Startup) if (-- FunDel == 0) { + KillText(); + if (Snail.Idle()) { + if (PAIN) + HeroCover(9); + else if (STARTUP::Core >= CORE_MID) { + int n = new_random(100); + if (n > 96) + HeroCover(6 + (Hero->X + Hero->W / 2 < SCR_WID / 2)); + else { + if (n > 90) + HeroCover(5); + else { + if (n > 60) + HeroCover(4); + else + HeroCover(3); + } + } + } + } + FunTouch(); } - } - } - FunTouch(); - } - Time = SYSTIMERATE; + Time = SYSTIMERATE; } - - - - - - - - -//-------------------------------------------------------------------------- - - - /* -static void SpkOpen (void) -{ - asm in al,0x61 - asm or al,0x03 - asm out 0x61,al - asm mov al,0x90 - asm out 0x43,al +static void SpkOpen(void) { + asm in al,0x61 + asm or al,0x03 + asm out 0x61,al + asm mov al,0x90 + asm out 0x43,al } - - - -static void SpkClose (void) -{ - asm in al,0x61 - asm and al,0xFC - asm out 0x61,al +static void SpkClose(void) { + asm in al,0x61 + asm and al,0xFC + asm out 0x61,al } */ - -static void SwitchColorMode (void) -{ - SNPOST_(SNSEQ, 121, VGA::Mono = ! VGA::Mono, NULL); - KeyClick(); - VGA::SetColors(SysPal, 64); +static void SwitchColorMode(void) { + SNPOST_(SNSEQ, 121, VGA::Mono = ! VGA::Mono, NULL); + KeyClick(); + VGA::SetColors(SysPal, 64); } -static void SwitchMusic (void) -{ - if (KEYBOARD::Key[ALT]) - { - if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); - else - { - SNPOST_(SNSEQ, 122, (Music = false), NULL); - //TODO Change the SNPOST message send to a special way to send function pointer - // SNPOST(SNEXEC, -1, 0, (void *)&SelectSound); - warning("SwitchMusic() - SNPOST"); +static void SwitchMusic(void) { + if (KEYBOARD::Key[ALT]) { + if (VMENU::Addr) + SNPOST_(SNKILL, -1, 0, VMENU::Addr); + else { + SNPOST_(SNSEQ, 122, (Music = false), NULL); + //TODO Change the SNPOST message send to a special way to send function pointer + // SNPOST(SNEXEC, -1, 0, (void *)&SelectSound); + warning("SwitchMusic() - SNPOST"); + } + } else { + if (STARTUP::Core < CORE_HIG) + SNPOST(SNINF, -1, NOMUSIC_TEXT, NULL); + else { + SNPOST_(SNSEQ, 122, (Music = ! Music), NULL); + KeyClick(); + } } - } - else - { - if (STARTUP::Core < CORE_HIG) SNPOST(SNINF, -1, NOMUSIC_TEXT, NULL); - else - { - SNPOST_(SNSEQ, 122, (Music = ! Music), NULL); - KeyClick(); - } - } - if (Music) LoadMIDI(Now); - else KillMIDI(); + if (Music) + LoadMIDI(Now); + else + KillMIDI(); } - - - -static void StartCountDown (void) -{ - //SNPOST(SNSEQ, 123, 0, NULL); - SwitchCave(-1); +static void StartCountDown(void) { + //SNPOST(SNSEQ, 123, 0, NULL); + SwitchCave(-1); } - - -#ifndef DEMO -static void TakeName (void) -{ - if (GET_TEXT::Ptr) SNPOST_(SNKILL, -1, 0, GET_TEXT::Ptr); - else - { - GET_TEXT * tn = new GET_TEXT(Text[GETNAME_PROMPT], UsrFnam, 8, KeyClick); - if (tn) - { - tn->SetName(Text[GETNAME_TITLE]); - tn->Center(); - tn->Goto(tn->X, tn->Y - 10); - tn->Z = 126; - VGA::ShowQ.Insert(tn); +#ifndef DEMO +static void TakeName(void) { + if (GET_TEXT::Ptr) + SNPOST_(SNKILL, -1, 0, GET_TEXT::Ptr); + else { + GET_TEXT *tn = new GET_TEXT(Text[GETNAME_PROMPT], UsrFnam, 8, KeyClick); + if (tn) { + tn->SetName(Text[GETNAME_TITLE]); + tn->Center(); + tn->Goto(tn->X, tn->Y - 10); + tn->Z = 126; + VGA::ShowQ.Insert(tn); + } } - } } #endif - - - #ifdef DEBUG - - -static void SwitchMapping (void) -{ - if (HorzLine.Flags.Hide) - { - int i; - for (i = 0; i < MAP_ZCNT; i ++) - { - int j; - for (j = 0; j < MAP_XCNT; j ++) - { - if (CLUSTER::Map[i][j]) - SetMapBrick(j, i); - } +static void SwitchMapping(void) { + if (HorzLine.Flags.Hide) { + int i; + for (i = 0; i < MAP_ZCNT; i ++) { + int j; + for (j = 0; j < MAP_XCNT; j ++) { + if (CLUSTER::Map[i][j]) + SetMapBrick(j, i); + } + } + } else { + SPRITE *s; + for (s = VGA::ShowQ.First(); s; s = s->Next) + if (s->W == MAP_XGRID && s->H == MAP_ZGRID) + SNPOST_(SNKILL, -1, 0, s); } - } - else - { - SPRITE * s; - for (s = VGA::ShowQ.First(); s; s = s->Next) - if (s->W == MAP_XGRID && s->H == MAP_ZGRID) - SNPOST_(SNKILL, -1, 0, s); - } - HorzLine.Flags.Hide = ! HorzLine.Flags.Hide; + HorzLine.Flags.Hide = ! HorzLine.Flags.Hide; } - - - -static void KillSprite (void) -{ - Sprite->Flags.Kill = true; - Sprite->Flags.BDel = true; - SNPOST_(SNKILL, -1, 0, Sprite); - Sprite = NULL; +static void KillSprite(void) { + Sprite->Flags.Kill = true; + Sprite->Flags.BDel = true; + SNPOST_(SNKILL, -1, 0, Sprite); + Sprite = NULL; } - - - -static void PushSprite (void) -{ - SPRITE * spr = Sprite->Prev; - if (spr) - { - VGA::ShowQ.Insert(VGA::ShowQ.Remove(Sprite), spr); - while (Sprite->Z > Sprite->Next->Z) -- Sprite->Z; - } - else SNPOST_(SNSOUND, -1, 2, NULL); +static void PushSprite(void) { + SPRITE *spr = Sprite->Prev; + if (spr) { + VGA::ShowQ.Insert(VGA::ShowQ.Remove(Sprite), spr); + while (Sprite->Z > Sprite->Next->Z) + --Sprite->Z; + } else + SNPOST_(SNSOUND, -1, 2, NULL); } - - - -static void PullSprite (void) -{ - bool ok = false; - SPRITE * spr = Sprite->Next; - if (spr) - { - spr = spr->Next; - if (spr) - { - ok = (! spr->Flags.Slav); +static void PullSprite(void) { + bool ok = false; + SPRITE *spr = Sprite->Next; + if (spr) { + spr = spr->Next; + if (spr) + ok = (!spr->Flags.Slav); } - } - if (ok) - { - VGA::ShowQ.Insert(VGA::ShowQ.Remove(Sprite), spr); - if (Sprite->Prev) - while (Sprite->Z < Sprite->Prev->Z) ++ Sprite->Z; - } - else SNPOST_(SNSOUND, -1, 2, NULL); + if (ok) { + VGA::ShowQ.Insert(VGA::ShowQ.Remove(Sprite), spr); + if (Sprite->Prev) + while (Sprite->Z < Sprite->Prev->Z) + ++Sprite->Z; + } else + SNPOST_(SNSOUND, -1, 2, NULL); } - - - - -static void NextStep (void) -{ - SNPOST_(SNSTEP, 0, 0, Sprite); +static void NextStep(void) { + SNPOST_(SNSTEP, 0, 0, Sprite); } - - - - - - - -static void SaveMapping (void) -{ - { - IOHAND cf(ProgName(".TAB"), UPD); - if (! cf.Error) - { - cf.Seek((Now-1) * sizeof(CLUSTER::Map)); - cf.Write((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); - } - } - { - IOHAND cf(ProgName(".HXY"), WRI); - if (! cf.Error) - { - HeroXY[Now-1].X = Hero->X; - HeroXY[Now-1].Y = Hero->Y; - cf.Write((uint8 *) HeroXY, sizeof(HeroXY)); - } - } +static void SaveMapping(void) { + { + IOHAND cf(ProgName(".TAB"), UPD); + if (!cf.Error) { + cf.Seek((Now - 1) * sizeof(CLUSTER::Map)); + cf.Write((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); + } + } + { + IOHAND cf(ProgName(".HXY"), WRI); + if (!cf.Error) { + HeroXY[Now - 1].X = Hero->X; + HeroXY[Now - 1].Y = Hero->Y; + cf.Write((uint8 *) HeroXY, sizeof(HeroXY)); + } + } } #endif +#ifdef DEBUG +// 1111111111222222222233333333 334444444444555555555566666666667777777777 +// 01234567890123456789012345678901234567 890123456789012345678901234567890123456789 +static char DebugText[] = " N=00000 F=000000 X=000 Y=000 FPS=0000\0S=00:00 000:000:000 000:000 00 "; -//-------------------------------------------------------------------------- +#define NFRE (DebugText + 3) +#define FFRE (DebugText + 11) +#define ABSX (DebugText + 20) +#define ABSY (DebugText + 26) +#define FRPS (DebugText + 34) +#define XSPR (DebugText + 38) +#define SP_N (DebugText + 41) +#define SP_S (DebugText + 44) - - - - - - - - -#ifdef DEBUG - - - - // 1111111111222222222233333333 334444444444555555555566666666667777777777 - // 01234567890123456789012345678901234567 890123456789012345678901234567890123456789 -static char DebugText[] = " N=00000 F=000000 X=000 Y=000 FPS=0000\0S=00:00 000:000:000 000:000 00 "; - -#define NFRE (DebugText + 3) -#define FFRE (DebugText + 11) -#define ABSX (DebugText + 20) -#define ABSY (DebugText + 26) -#define FRPS (DebugText + 34) -#define XSPR (DebugText + 38) -#define SP_N (DebugText + 41) -#define SP_S (DebugText + 44) - -#define SP_X (DebugText + 47) -#define SP_Y (DebugText + 51) -#define SP_Z (DebugText + 55) -#define SP_W (DebugText + 59) -#define SP_H (DebugText + 63) -#define SP_F (DebugText + 67) +#define SP_X (DebugText + 47) +#define SP_Y (DebugText + 51) +#define SP_Z (DebugText + 55) +#define SP_W (DebugText + 59) +#define SP_H (DebugText + 63) +#define SP_F (DebugText + 67) #define SP__ (DebugText + 70) -INFO_LINE DebugLine(SCR_WID); +INFO_LINE DebugLine(SCR_WID); -static void SayDebug (void) -{ - if (! DebugLine.Flags.Hide) - { - static long t = -1L; - long t1 = Timer(); +static void SayDebug(void) { + if (!DebugLine.Flags.Hide) { + static long t = -1L; + long t1 = Timer(); - if (t1 - t >= 18) - { - static uint32 old = 0L; - uint32 now = Vga.FrmCnt; - dwtom(now - old, FRPS, 10, 4); - old = now; - t = t1; + if (t1 - t >= 18) { + static uint32 old = 0L; + uint32 now = Vga.FrmCnt; + dwtom(now - old, FRPS, 10, 4); + old = now; + t = t1; + } + + dwtom(Mouse.X, ABSX, 10, 3); + dwtom(Mouse.Y, ABSY, 10, 3); +// dwtom(coreleft(), NFRE, 10, 5); +// dwtom(farcoreleft(), FFRE, 10, 6); + + // sprite queue size + uint16 n = 0; + SPRITE *spr; + for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { + ++ n; + if (spr == Sprite) { + *XSPR = ' '; + dwtom(n, SP_N, 10, 2); + dwtom(Sprite->X, SP_X, 10, 3); + dwtom(Sprite->Y, SP_Y, 10, 3); + dwtom(Sprite->Z, SP_Z, 10, 3); + dwtom(Sprite->W, SP_W, 10, 3); + dwtom(Sprite->H, SP_H, 10, 3); + dwtom(*(uint16 *)(&Sprite->Flags), SP_F, 16, 2); + } + } + dwtom(n, SP_S, 10, 2); +// *SP__ = (heapcheck() < 0) ? '!' : ' '; + DebugLine.Update(DebugText); } - - dwtom(Mouse.X, ABSX, 10, 3); - dwtom(Mouse.Y, ABSY, 10, 3); - dwtom(coreleft(), NFRE, 10, 5); - dwtom(farcoreleft(), FFRE, 10, 6); - - // sprite queue size - uint16 n = 0; - SPRITE * spr; - for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) - { - ++ n; - if (spr == Sprite) - { - *XSPR = ' '; - dwtom(n, SP_N, 10, 2); - dwtom(Sprite->X, SP_X, 10, 3); - dwtom(Sprite->Y, SP_Y, 10, 3); - dwtom(Sprite->Z, SP_Z, 10, 3); - dwtom(Sprite->W, SP_W, 10, 3); - dwtom(Sprite->H, SP_H, 10, 3); - dwtom(*(uint16 *) (&Sprite->Flags), SP_F, 16, 2); - } - } - dwtom(n, SP_S, 10, 2); - *SP__ = (heapcheck() < 0) ? '!' : ' '; - DebugLine.Update(DebugText); - } } - - - -static void SwitchDebug (void) -{ - DebugLine.Flags.Hide = ! DebugLine.Flags.Hide; +static void SwitchDebug(void) { + DebugLine.Flags.Hide = ! DebugLine.Flags.Hide; } - - #endif - - - - -static void OptionTouch (int opt, uint16 mask) -{ - switch (opt) - { - case 1 : if (mask & L_UP) SwitchColorMode(); break; - case 2 : if (mask & L_UP) SwitchMusic(); - else - if (mask & R_UP) - if (! MIXER::Appear) - { - MIXER::Appear = true; - new MIXER(BUTTON_X, BUTTON_Y); - } - break; - case 3 : if (mask & L_UP) Quit(); break; - } +static void OptionTouch(int opt, uint16 mask) { + switch (opt) { + case 1 : + if (mask & L_UP) + SwitchColorMode(); + break; + case 2 : + if (mask & L_UP) + SwitchMusic(); + else if (mask & R_UP) + if (! MIXER::Appear) { + MIXER::Appear = true; + new MIXER(BUTTON_X, BUTTON_Y); + } + break; + case 3 : + if (mask & L_UP) + Quit(); + break; + } } - - - #pragma argsused -void SPRITE::Touch (uint16 mask, int x, int y) -{ - SYSTEM::FunTouch(); - if ((mask & ATTN) == 0) - { - InfoLine.Update(Name()); - if (mask & (R_DN | L_DN)) Sprite = this; // DEBUG mode only? - if (Ref/10 == 12) - { - OptionTouch(Ref % 10, mask); - return; - } - if (Flags.Syst) return; // cannot access system sprites - if (Game) if (mask & L_UP) { mask &= ~L_UP; mask |= R_UP; } - if ((mask & R_UP) && Snail.Idle()) - { - SPRITE * ps = (PocLight.SeqPtr) ? Pocket[PocPtr] : NULL; - if (ps) - { - if (Flags.Kept || Hero->Distance(this) < MAX_DISTANCE) - { - if (Works(ps)) - { - FeedSnail(ps, TAKE); - } - else OffUse(); - SelectPocket(-1); +void SPRITE::Touch(uint16 mask, int x, int y) { + SYSTEM::FunTouch(); + if ((mask & ATTN) == 0) { + InfoLine.Update(Name()); + if (mask & (R_DN | L_DN)) + Sprite = this; // DEBUG mode only? + if (Ref / 10 == 12) { + OptionTouch(Ref % 10, mask); + return; } - else TooFar(); - } - else - { - if (Flags.Kept) mask |= L_UP; - else - { - if (Hero->Distance(this) < MAX_DISTANCE) - {/// - if (Flags.Port) - { - if (FindPocket(NULL) < 0) PocFul(); - else - { - SNPOST(SNREACH, -1, -1, this); - SNPOST(SNKEEP, -1, -1, this); - Flags.Port = false; - } + if (Flags.Syst) + return; // cannot access system sprites + if (Game) if (mask & L_UP) { + mask &= ~L_UP; + mask |= R_UP; } - else - { - if (TakePtr != NO_PTR) - { - if (SnList(TAKE)[TakePtr].Com == SNNEXT) OffUse(); - else FeedSnail(this, TAKE); - } - else OffUse(); + if ((mask & R_UP) && Snail.Idle()) { + SPRITE *ps = (PocLight.SeqPtr) ? Pocket[PocPtr] : NULL; + if (ps) { + if (Flags.Kept || Hero->Distance(this) < MAX_DISTANCE) { + if (Works(ps)) { + FeedSnail(ps, TAKE); + } else + OffUse(); + SelectPocket(-1); + } else + TooFar(); + } else { + if (Flags.Kept) + mask |= L_UP; + else { + if (Hero->Distance(this) < MAX_DISTANCE) { + /// + if (Flags.Port) { + if (FindPocket(NULL) < 0) + PocFul(); + else { + SNPOST(SNREACH, -1, -1, this); + SNPOST(SNKEEP, -1, -1, this); + Flags.Port = false; + } + } else { + if (TakePtr != NO_PTR) { + if (SnList(TAKE)[TakePtr].Com == SNNEXT) + OffUse(); + else + FeedSnail(this, TAKE); + } else + OffUse(); + } + }/// + else + TooFar(); + } } - }/// - else TooFar(); } - } - } - if ((mask & L_UP) && Snail.Idle()) - { - if (Flags.Kept) - { - int n; - for (n = 0; n < POCKET_NX; n ++) - { - if (Pocket[n] == this) - { - SelectPocket(n); - break; - } + if ((mask & L_UP) && Snail.Idle()) { + if (Flags.Kept) { + int n; + for (n = 0; n < POCKET_NX; n ++) { + if (Pocket[n] == this) { + SelectPocket(n); + break; + } + } + } else + SNPOST(SNWALK, -1, -1, this); // Hero->FindWay(this); } - } - else SNPOST(SNWALK, -1, -1, this); // Hero->FindWay(this); } - } } +static void LoadSprite(const char *fname, int ref, int cav, int col = 0, int row = 0, int pos = 0) { + static const char *Comd[] = { "Name", "Type", "Phase", "East", + "Left", "Right", "Top", "Bottom", + "Seq", "Near", "Take", + "Portable", "Transparent", + NULL + }; + static const char *Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS", + "FLY", NULL + }; + char line[LINE_MAX]; + + int shpcnt = 0; + int type = 0; // DEAD + bool east = false; + bool port = false; + bool tran = false; + int i, lcnt = 0; + uint16 len; + + MergeExt(line, fname, SPR_EXT); + if (INI_FILE::Exist(line)) { // sprite description file exist + INI_FILE sprf(line); + if (sprf.Error) + error("Bad SPR [%s]", line); + + while ((len = sprf.Read((uint8 *)line)) != 0) { + ++ lcnt; + if (len && line[len - 1] == '\n') + line[-- len] = '\0'; + if (len == 0 || *line == '.') + continue; + + if ((i = TakeEnum(Comd, strtok(line, " =\t"))) < 0) + error("%s [%s]", NumStr("Bad line ######", lcnt), fname); - - - -//-------------------------------------------------------------------------- -//-------------------------------------------------------------------------- - - - - - - -static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int row = 0, int pos = 0) -{ - static const char * Comd[] = { "Name", "Type", "Phase", "East", - "Left", "Right", "Top", "Bottom", - "Seq", "Near", "Take", - "Portable", "Transparent", - NULL }; - static const char * Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS", - "FLY", NULL }; - char line[LINE_MAX]; - - int shpcnt = 0; - int type = 0; // DEAD - bool east = false; - bool port = false; - bool tran = false; - int i, lcnt = 0; - uint16 len; - - MergeExt(line, fname, SPR_EXT); - if (INI_FILE::Exist(line)) // sprite description file exist - { - INI_FILE sprf(line); - if (sprf.Error) { - error("Bad SPR [%s]", line); + switch (i) { + case 0 : // Name - will be taken in Expand routine + break; + case 1 : // Type + if ((type = TakeEnum(Type, strtok(NULL, " \t,;/"))) < 0) + error("%s [%s]", NumStr("Bad line ######", lcnt), fname); + break; + case 2 : // Phase + ++ shpcnt; + break; + case 3 : // East + east = (atoi(strtok(NULL, " \t,;/")) != 0); + break; + case 11 : // Portable + port = (atoi(strtok(NULL, " \t,;/")) != 0); + break; + case 12 : // Transparent + tran = (atoi(strtok(NULL, " \t,;/")) != 0); + break; + } + } + if (! shpcnt) + error("No shapes [%s]", fname); + } else { // no sprite description: mono-shaped sprite with only .BMP file + ++shpcnt; } - while ((len = sprf.Read((uint8*)line)) != 0) + // make sprite of choosen type + switch (type) { + case 1 : { // AUTO + Sprite = new SPRITE(NULL); + if (Sprite) { + Sprite->Goto(col, row); + //Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$ + } + break; + } + case 2 : { // WALK + WALK *w = new WALK(NULL); + if (w && ref == 1) { + w->Goto(col, row); + if (Hero) + error("2nd HERO [%s]", fname); + Hero = w; + } + Sprite = w; + break; + } + /* + case 3 : // NEWTON + NEWTON * n = new NEWTON(NULL); + if (n) { - ++ lcnt; - if (len && line[len-1] == '\n') line[-- len] = '\0'; - if (len == 0 || *line == '.') continue; - - if ((i = TakeEnum(Comd, strtok(line, " =\t"))) < 0) { - error("%s [%s]", NumStr("Bad line ######", lcnt), fname); - } - - switch (i) - { - case 0 : // Name - will be taken in Expand routine - break; - case 1 : // Type - if ((type = TakeEnum(Type, strtok(NULL, " \t,;/"))) < 0) - error("%s [%s]", NumStr("Bad line ######", lcnt), fname); - break; - case 2 : // Phase - ++ shpcnt; - break; - case 3 : // East - east = (atoi(strtok(NULL, " \t,;/")) != 0); - break; - case 11 : // Portable - port = (atoi(strtok(NULL, " \t,;/")) != 0); - break; - case 12 : // Transparent - tran = (atoi(strtok(NULL, " \t,;/")) != 0); - break; - } - } - if (! shpcnt) - error("No shapes [%s]", fname); - } - else // no sprite description: mono-shaped sprite with only .BMP file - { - ++ shpcnt; - } - - // make sprite of choosen type - switch (type) - { - case 1 : // AUTO - { - Sprite = new SPRITE(NULL); - if (Sprite) - { - Sprite->Goto(col, row); - //Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$ - } - break; - } - case 2 : // WALK - { - WALK * w = new WALK(NULL); - if (w && ref == 1) - { - w->Goto(col, row); - if (Hero) - error("2nd HERO [%s]", fname); - Hero = w; - } - Sprite = w; - break; - } - /* - case 3 : // NEWTON - NEWTON * n = new NEWTON(NULL); - if (n) - { - n->Ay = (bottom-n->H); - n->By = 90; - n->Cy = 3; - n->Bx = 99; - n->Cx = 3; - n->Goto(col, row); - } - Sprite = n; - break; - */ - case 4 : // LISSAJOUS - { - error("Bad type [%s]", fname); - /* - LISSAJOUS * l = new LISSAJOUS(NULL); - if (l) - { + n->Ay = (bottom-n->H); + n->By = 90; + n->Cy = 3; + n->Bx = 99; + n->Cx = 3; + n->Goto(col, row); + } + Sprite = n; + break; + */ + case 4 : { // LISSAJOUS + error("Bad type [%s]", fname); + /* + LISSAJOUS * l = new LISSAJOUS(NULL); + if (l) + { l->Ax = SCR_WID/2; l->Ay = SCR_HIG/2; l->Bx = 7; @@ -1804,448 +1487,416 @@ static void LoadSprite (const char *fname, int ref, int cav, int col = 0, int ro * (long *) &l->Dx = 0; // movex * cnt l->Goto(col, row); } - Sprite = l; - */ - break; - } - case 5 : // FLY - { - FLY * f = new FLY(NULL); - Sprite = f; - //////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$ - break; - } - default: // DEAD - { - Sprite = new SPRITE(NULL); - if (Sprite) Sprite->Goto(col, row); - break; - } - } - if (Sprite) - { - Sprite->Ref = ref; - Sprite->Cave = cav; - Sprite->Z = pos; - Sprite->Flags.East = east; - Sprite->Flags.Port = port; - Sprite->Flags.Tran = tran; - Sprite->Flags.Kill = true; - Sprite->Flags.BDel = true; - //fnsplit(fname, NULL, NULL, Sprite->File, NULL); - warning("LoadSprite: use of fnsplit"); - - Sprite->ShpCnt = shpcnt; - VGA::SpareQ.Append(Sprite); - } + Sprite = l; + */ + break; + } + case 5 : { // FLY + FLY *f = new FLY(NULL); + Sprite = f; + //////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$ + break; + } + default: { // DEAD + Sprite = new SPRITE(NULL); + if (Sprite) + Sprite->Goto(col, row); + break; + } + } + if (Sprite) { + Sprite->Ref = ref; + Sprite->Cave = cav; + Sprite->Z = pos; + Sprite->Flags.East = east; + Sprite->Flags.Port = port; + Sprite->Flags.Tran = tran; + Sprite->Flags.Kill = true; + Sprite->Flags.BDel = true; + //fnsplit(fname, NULL, NULL, Sprite->File, NULL); + warning("LoadSprite: use of fnsplit"); + + Sprite->ShpCnt = shpcnt; + VGA::SpareQ.Append(Sprite); + } } +static void LoadScript(const char *fname) { + char line[LINE_MAX]; + char *SpN; + int SpI, SpA, SpX, SpY, SpZ; + bool BkG = false; + INI_FILE scrf(fname); + int lcnt = 0; + bool ok = true; + if (scrf.Error) + return; + while (scrf.Read((uint8 *)line) != 0) { + char *p; + ++lcnt; + if (*line == 0 || *line == '\n' || *line == '.') + continue; -static void LoadScript (const char *fname) -{ - char line[LINE_MAX]; - char * SpN; - int SpI, SpA, SpX, SpY, SpZ; - bool BkG = false; - INI_FILE scrf(fname); - int lcnt = 0; - bool ok = true; + ok = false; // not OK if break + // sprite ident number + if ((p = strtok(line, " \t\n")) == NULL) + break; + SpI = atoi(p); + // sprite file name + if ((SpN = strtok(NULL, " ,;/\t\n")) == NULL) + break; + // sprite cave + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + break; + SpA = atoi(p); + // sprite column + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + break; + SpX = atoi(p); + // sprite row + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + break; + SpY = atoi(p); + // sprite Z pos + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + break; + SpZ = atoi(p); + // sprite life + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + break; + BkG = atoi(p) == 0; - if (scrf.Error) return; + ok = true; // no break: OK - while (scrf.Read((uint8*)line) != 0) - { - char *p; - - ++ lcnt; - if (*line == 0 || *line == '\n' || *line == '.') continue; - - ok = false; // not OK if break - // sprite ident number - if ((p = strtok(line, " \t\n")) == NULL) break; - SpI = atoi(p); - // sprite file name - if ((SpN = strtok(NULL, " ,;/\t\n")) == NULL) break; - // sprite cave - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpA = atoi(p); - // sprite column - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpX = atoi(p); - // sprite row - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpY = atoi(p); - // sprite Z pos - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpZ = atoi(p); - // sprite life - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - BkG = atoi(p) == 0; - - ok = true; // no break: OK - - Sprite = NULL; - LoadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); - if (Sprite && BkG) Sprite->Flags.Back = true; - } - if (! ok) - error("%s [%s]", NumStr("Bad INI line ######", lcnt), fname); + Sprite = NULL; + LoadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); + if (Sprite && BkG) + Sprite->Flags.Back = true; + } + if (! ok) + error("%s [%s]", NumStr("Bad INI line ######", lcnt), fname); } - - -static void MainLoop (void) -{ +static void MainLoop(void) { #if 0 //def DEBUG - static VgaRegBlk Mode[] = { + static VgaRegBlk Mode[] = { - { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode + { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode - { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 - { 0x05, VGAGRA, 0x03, 0x00 }, // R/W mode = 0 - { 0x06, VGAGRA, 0x02, 0x00 }, // misc + { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 + { 0x05, VGAGRA, 0x03, 0x00 }, // R/W mode = 0 + { 0x06, VGAGRA, 0x02, 0x00 }, // misc - { 0x14, VGACRT, 0x40, 0x00 }, // underline - { 0x13, VGACRT, 0xFF, 0x28 }, // screen width - { 0x17, VGACRT, 0xFF, 0xC3 }, // mode control + { 0x14, VGACRT, 0x40, 0x00 }, // underline + { 0x13, VGACRT, 0xFF, 0x28 }, // screen width + { 0x17, VGACRT, 0xFF, 0xC3 }, // mode control - { 0x11, VGACRT, 0x80, 0x00 }, // vert retrace end - { 0x09, VGACRT, 0xEF, 0x01 }, // max scan line + { 0x11, VGACRT, 0x80, 0x00 }, // vert retrace end + { 0x09, VGACRT, 0xEF, 0x01 }, // max scan line - { 0x30, VGAATR, 0x00, 0x20 }, // 256 color mode + { 0x30, VGAATR, 0x00, 0x20 }, // 256 color mode -// { 0x12, VGACRT, 0xFF, 0x6E }, // vert display end -// { 0x15, VGACRT, 0xFF, 0x7F }, // start vb -// { 0x10, VGACRT, 0xFF, 0x94 }, // start vr +// { 0x12, VGACRT, 0xFF, 0x6E }, // vert display end +// { 0x15, VGACRT, 0xFF, 0x7F }, // start vb +// { 0x10, VGACRT, 0xFF, 0x94 }, // start vr - { 0x00 } }; + { 0x00 } + }; - Vga.Setup(Mode); + Vga.Setup(Mode); #endif - Debug( SayDebug(); ) + Debug(SayDebug();) - #ifdef DEMO - #define TIM ((182L*6L) * 5L) - static uint32 tc = 0; - if (TimerCount - tc >= TIM && Talk == NULL && Snail.Idle()) - { - if (Text[DemoText]) - { - SNPOST(SNSOUND, -1, 4, NULL); // drumla - SNPOST(SNINF, -1, DemoText, NULL); - SNPOST(SNLABEL, -1, -1, NULL); - if (Text[++ DemoText] == NULL) DemoText = DEMO_TEXT + 1; - } - tc = TimerCount; - } - #undef TIM - #endif - - Vga.Show(); - Snail_.RunCom(); - Snail.RunCom(); -} - - - - - -void LoadUser (void) -{ - // set scene - if (STARTUP::Mode == 0) // user .SVG file found - { - CFILE cfile = CFILE(UsrPath(UsrFnam), REA, RCrypt); - LoadGame(cfile); - } - else - { - if (STARTUP::Mode == 1) - { - SVG0FILE file = SVG0FILE(SVG0NAME); - LoadGame(file); - } - else - { - LoadScript(ProgName(INI_EXT)); - Music = true; - CFILE file = CFILE(SVG0NAME, WRI); - SaveGame(file); - error("Ok [%s]", SVG0NAME); +#ifdef DEMO +#define TIM ((182L*6L) * 5L) + static uint32 tc = 0; + if (TimerCount - tc >= TIM && Talk == NULL && Snail.Idle()) { + if (Text[DemoText]) { + SNPOST(SNSOUND, -1, 4, NULL); // drumla + SNPOST(SNINF, -1, DemoText, NULL); + SNPOST(SNLABEL, -1, -1, NULL); + if (Text[++ DemoText] == NULL) DemoText = DEMO_TEXT + 1; + } + tc = TimerCount; } - } - LoadScript(ProgName(IN0_EXT)); +#undef TIM +#endif + + Vga.Show(); + Snail_.RunCom(); + Snail.RunCom(); } +void LoadUser(void) { + // set scene + if (STARTUP::Mode == 0) { // user .SVG file found + CFILE cfile = CFILE(UsrPath(UsrFnam), REA, RCrypt); + LoadGame(cfile); + } else { + if (STARTUP::Mode == 1) { + SVG0FILE file = SVG0FILE(SVG0NAME); + LoadGame(file); + } else { + LoadScript(ProgName(INI_EXT)); + Music = true; + CFILE file = CFILE(SVG0NAME, WRI); + SaveGame(file); + error("Ok [%s]", SVG0NAME); + } + } + LoadScript(ProgName(IN0_EXT)); +} +static void RunGame(void) { + Text.Clear(); + Text.Preload(100, 1000); + LoadHeroXY(); -static void RunGame (void) -{ - Text.Clear(); - Text.Preload(100, 1000); - LoadHeroXY(); + CavLight.Flags.Tran = true; + VGA::ShowQ.Append(&CavLight); + CavLight.Flags.Hide = true; - CavLight.Flags.Tran = true; - VGA::ShowQ.Append(&CavLight); - CavLight.Flags.Hide = true; + static SEQ PocSeq[] = { { 0, 0, 0, 0, 20 }, + { 1, 2, 0, 0, 4 }, + { 2, 3, 0, 0, 4 }, + { 3, 4, 0, 0, 16 }, + { 2, 5, 0, 0, 4 }, + { 1, 6, 0, 0, 4 }, + { 0, 1, 0, 0, 16 }, + }; + PocLight.SetSeq(PocSeq); + PocLight.Flags.Tran = true; + PocLight.Time = 1; + PocLight.Z = 120; + VGA::ShowQ.Append(&PocLight); + SelectPocket(-1); - static SEQ PocSeq[] = { { 0, 0, 0, 0, 20 }, - { 1, 2, 0, 0, 4 }, - { 2, 3, 0, 0, 4 }, - { 3, 4, 0, 0, 16 }, - { 2, 5, 0, 0, 4 }, - { 1, 6, 0, 0, 4 }, - { 0, 1, 0, 0, 16 }, - }; - PocLight.SetSeq(PocSeq); - PocLight.Flags.Tran = true; - PocLight.Time = 1; - PocLight.Z = 120; - VGA::ShowQ.Append(&PocLight); - SelectPocket(-1); - - VGA::ShowQ.Append(&Mouse); + VGA::ShowQ.Append(&Mouse); // ___________ - LoadUser(); + LoadUser(); // ~~~~~~~~~~~ - if ((Sprite = VGA::SpareQ.Locate(121)) != NULL) - SNPOST_(SNSEQ, -1, VGA::Mono, Sprite); - if ((Sprite = VGA::SpareQ.Locate(122)) != NULL) Sprite->Step(Music); - SNPOST_(SNSEQ, -1, Music, Sprite); - if (! Music) KillMIDI(); + if ((Sprite = VGA::SpareQ.Locate(121)) != NULL) + SNPOST_(SNSEQ, -1, VGA::Mono, Sprite); + if ((Sprite = VGA::SpareQ.Locate(122)) != NULL) + Sprite->Step(Music); + SNPOST_(SNSEQ, -1, Music, Sprite); + if (! Music) + KillMIDI(); - if (Mini && INI_FILE::Exist("MINI.SPR")) - { - uint8 * ptr = (uint8 *) &*Mini; - if (ptr != NULL) - { - LoadSprite("MINI", -1, 0, MINI_X, MINI_Y); - ExpandSprite(MiniCave = Sprite); // NULL is ok - if (MiniCave) - { - MiniCave->Flags.Hide = true; - MiniCave->MoveShapes(ptr); - MiniShp[0] = new BITMAP(*MiniCave->Shp()); - MiniShpList = MiniCave->SetShapeList(MiniShp); - PostMiniStep(-1); - } + if (Mini && INI_FILE::Exist("MINI.SPR")) { + uint8 *ptr = (uint8 *) &*Mini; + if (ptr != NULL) { + LoadSprite("MINI", -1, 0, MINI_X, MINI_Y); + ExpandSprite(MiniCave = Sprite); // NULL is ok + if (MiniCave) { + MiniCave->Flags.Hide = true; + MiniCave->MoveShapes(ptr); + MiniShp[0] = new BITMAP(*MiniCave->Shp()); + MiniShpList = MiniCave->SetShapeList(MiniShp); + PostMiniStep(-1); + } + } } - } - if (Hero) - { - ExpandSprite(Hero); - Hero->Goto(HeroXY[Now-1].X, HeroXY[Now-1].Y); - if (INI_FILE::Exist("00SHADOW.SPR")) - { - LoadSprite("00SHADOW", -1, 0, Hero->X + 14, Hero->Y + 51); - if ((Shadow = Sprite) != NULL) - { - Shadow->Ref = 2; - Shadow->Flags.Tran = true; - Hero->Flags.Shad = true; - VGA::ShowQ.Insert(VGA::SpareQ.Remove(Shadow), Hero); - } + if (Hero) { + ExpandSprite(Hero); + Hero->Goto(HeroXY[Now - 1].X, HeroXY[Now - 1].Y); + if (INI_FILE::Exist("00SHADOW.SPR")) { + LoadSprite("00SHADOW", -1, 0, Hero->X + 14, Hero->Y + 51); + if ((Shadow = Sprite) != NULL) { + Shadow->Ref = 2; + Shadow->Flags.Tran = true; + Hero->Flags.Shad = true; + VGA::ShowQ.Insert(VGA::SpareQ.Remove(Shadow), Hero); + } + } } - } - InfoLine.Goto(INFO_X, INFO_Y); - InfoLine.Flags.Tran = true; - InfoLine.Update(NULL); - VGA::ShowQ.Insert(&InfoLine); + InfoLine.Goto(INFO_X, INFO_Y); + InfoLine.Flags.Tran = true; + InfoLine.Update(NULL); + VGA::ShowQ.Insert(&InfoLine); - #ifdef DEBUG - DebugLine.Z = 126; - VGA::ShowQ.Insert(&DebugLine); +#ifdef DEBUG + DebugLine.Z = 126; + VGA::ShowQ.Insert(&DebugLine); - HorzLine.Y = MAP_TOP - (MAP_TOP > 0); - HorzLine.Z = 126; - VGA::ShowQ.Insert(&HorzLine); - #endif + HorzLine.Y = MAP_TOP - (MAP_TOP > 0); + HorzLine.Z = 126; + VGA::ShowQ.Insert(&HorzLine); +#endif - Mouse.Busy = VGA::SpareQ.Locate(BUSY_REF); - if (Mouse.Busy) ExpandSprite(Mouse.Busy); + Mouse.Busy = VGA::SpareQ.Locate(BUSY_REF); + if (Mouse.Busy) + ExpandSprite(Mouse.Busy); - Startup = 0; + Startup = 0; - SNPOST(SNLEVEL, -1, OldLev, &CavLight); - CavLight.Goto(CAVE_X + ((Now-1) % CAVE_NX) * CAVE_DX + CAVE_SX, - CAVE_Y + ((Now-1) / CAVE_NX) * CAVE_DY + CAVE_SY); - CaveUp(); + SNPOST(SNLEVEL, -1, OldLev, &CavLight); + CavLight.Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, + CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); + CaveUp(); - KEYBOARD::SetClient(Sys); - // main loop - while (! Finis) - { - //TODO Change the SNPOST message send to a special way to send function pointer - // if (FINIS) SNPOST(SNEXEC, -1, 0, (void *)&QGame); - warning("RunGame: problematic use of SNPOST"); - MainLoop(); - } + KEYBOARD::SetClient(Sys); + // main loop + while (! Finis) { + //TODO Change the SNPOST message send to a special way to send function pointer + // if (FINIS) SNPOST(SNEXEC, -1, 0, (void *)&QGame); + warning("RunGame: problematic use of SNPOST"); + MainLoop(); + } - KEYBOARD::SetClient(NULL); - HEART::Enable = false; - SNPOST(SNCLEAR, -1, 0, NULL); - SNPOST_(SNCLEAR, -1, 0, NULL); - Mouse.Off(); - VGA::ShowQ.Clear(); - VGA::SpareQ.Clear(); - Hero = NULL; - Shadow = NULL; + KEYBOARD::SetClient(NULL); + HEART::Enable = false; + SNPOST(SNCLEAR, -1, 0, NULL); + SNPOST_(SNCLEAR, -1, 0, NULL); + Mouse.Off(); + VGA::ShowQ.Clear(); + VGA::SpareQ.Clear(); + Hero = NULL; + Shadow = NULL; } - - -void Movie (const char * ext) -{ - const char * fn = ProgName(ext); - if (INI_FILE::Exist(fn)) - { - LoadScript(fn); - ExpandSprite(VGA::SpareQ.Locate(999)); - FeedSnail(VGA::ShowQ.Locate(999), TAKE); - VGA::ShowQ.Append(&Mouse); - HEART::Enable = true; - KEYBOARD::SetClient(Sys); - while (! Snail.Idle()) - { - MainLoop(); +void Movie(const char *ext) { + const char *fn = ProgName(ext); + if (INI_FILE::Exist(fn)) { + LoadScript(fn); + ExpandSprite(VGA::SpareQ.Locate(999)); + FeedSnail(VGA::ShowQ.Locate(999), TAKE); + VGA::ShowQ.Append(&Mouse); + HEART::Enable = true; + KEYBOARD::SetClient(Sys); + while (! Snail.Idle()) { + MainLoop(); + } + KEYBOARD::SetClient(NULL); + HEART::Enable = false; + SNPOST(SNCLEAR, -1, 0, NULL); + SNPOST_(SNCLEAR, -1, 0, NULL); + VGA::ShowQ.Clear(); + VGA::SpareQ.Clear(); } - KEYBOARD::SetClient(NULL); - HEART::Enable = false; - SNPOST(SNCLEAR, -1, 0, NULL); - SNPOST_(SNCLEAR, -1, 0, NULL); - VGA::ShowQ.Clear(); - VGA::SpareQ.Clear(); - } } +bool ShowTitle(const char *name) { + BITMAP::Pal = SysPal; + BMP_PTR LB[] = { new BITMAP(name), NULL }; + BITMAP::Pal = NULL; + bool usr_ok = false; + SPRITE D(LB); + D.Flags.Kill = true; + D.Flags.BDel = true; + D.Center(); + D.Show(2); + if (STARTUP::Mode == 2) { + Inf(SVG0NAME); + Talk->Show(2); + } + Vga.Sunset(); + VGA::CopyPage(1, 2); + VGA::CopyPage(0, 1); + SelectPocket(-1); + Vga.Sunrise(SysPal); -bool ShowTitle (const char * name) -{ - BITMAP::Pal = SysPal; - BMP_PTR LB[] = { new BITMAP(name), NULL }; - BITMAP::Pal = NULL; - bool usr_ok = false; + if (STARTUP::Mode < 2 && ! STARTUP::SoundOk) { + VGA::CopyPage(1, 2); + VGA::CopyPage(0, 1); + VGA::ShowQ.Append(&Mouse); + HEART::Enable = true; + Mouse.On(); + for (SelectSound(); ! Snail.Idle() || VMENU::Addr;) + MainLoop(); + Mouse.Off(); + HEART::Enable = false; + VGA::ShowQ.Clear(); + VGA::CopyPage(0, 2); + STARTUP::SoundOk = 2; + if (Music) + LoadMIDI(0); + } - SPRITE D(LB); - D.Flags.Kill = true; - D.Flags.BDel = true; - D.Center(); - D.Show(2); - - if (STARTUP::Mode == 2) - { - Inf(SVG0NAME); - Talk->Show(2); - } - - Vga.Sunset(); - VGA::CopyPage(1, 2); - VGA::CopyPage(0, 1); - SelectPocket(-1); - Vga.Sunrise(SysPal); - - if (STARTUP::Mode < 2 && ! STARTUP::SoundOk) - { - VGA::CopyPage(1, 2); - VGA::CopyPage(0, 1); - VGA::ShowQ.Append(&Mouse); - HEART::Enable = true; - Mouse.On(); - for (SelectSound(); ! Snail.Idle() || VMENU::Addr; ) MainLoop(); - Mouse.Off(); - HEART::Enable = false; - VGA::ShowQ.Clear(); - VGA::CopyPage(0, 2); - STARTUP::SoundOk = 2; - if (Music) LoadMIDI(0); - } - - if (STARTUP::Mode < 2) - { - #ifdef DEMO - strcpy(UsrFnam, ProgName(SVG_EXT)); - usr_ok = true; - #else - //----------------------------------------- - #ifndef EVA - #ifdef CD - STARTUP::Summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; - #else + if (STARTUP::Mode < 2) { +#ifdef DEMO + strcpy(UsrFnam, ProgName(SVG_EXT)); + usr_ok = true; +#else + //----------------------------------------- +#ifndef EVA +#ifdef CD + STARTUP::Summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; +#else // Boot * b = ReadBoot(getdisk()); warning("ShowTitle: FIXME ReadBoot"); - Boot * b = ReadBoot(0); - uint32 sn = (b->XSign == 0x29) ? b->Serial : b->lTotSecs; - free(b); - sn -= ((IDENT *)Copr)->disk; - STARTUP::Summa |= Lo(sn) | Hi(sn); - #endif - #endif - //----------------------------------------- - Movie("X00"); // paylist - VGA::CopyPage(1, 2); - VGA::CopyPage(0, 1); - VGA::ShowQ.Append(&Mouse); - //Mouse.On(); - HEART::Enable = true; - for (TakeName(); GET_TEXT::Ptr; ) MainLoop(); - HEART::Enable = false; - if (KEYBOARD::Last() == Enter && *UsrFnam) usr_ok = true; - if (usr_ok) strcat(UsrFnam, SVG_EXT); - //Mouse.Off(); - VGA::ShowQ.Clear(); - VGA::CopyPage(0, 2); - #endif - if (usr_ok && STARTUP::Mode == 0) - { - const char *n = UsrPath(UsrFnam); - if (CFILE::Exist(n)) - { - CFILE file = CFILE(n, REA, RCrypt); - LoadGame(file, true); // only system vars - VGA::SetColors(SysPal, 64); - Vga.Update(); - if (FINIS) - { - ++ STARTUP::Mode; - FINIS = false; + Boot *b = ReadBoot(0); + uint32 sn = (b->XSign == 0x29) ? b->Serial : b->lTotSecs; + free(b); + sn -= ((IDENT *)Copr)->disk; + STARTUP::Summa |= Lo(sn) | Hi(sn); +#endif +#endif + //----------------------------------------- + Movie("X00"); // paylist + VGA::CopyPage(1, 2); + VGA::CopyPage(0, 1); + VGA::ShowQ.Append(&Mouse); + //Mouse.On(); + HEART::Enable = true; + for (TakeName(); GET_TEXT::Ptr;) + MainLoop(); + HEART::Enable = false; + if (KEYBOARD::Last() == Enter && *UsrFnam) + usr_ok = true; + if (usr_ok) + strcat(UsrFnam, SVG_EXT); + //Mouse.Off(); + VGA::ShowQ.Clear(); + VGA::CopyPage(0, 2); +#endif + if (usr_ok && STARTUP::Mode == 0) { + const char *n = UsrPath(UsrFnam); + if (CFILE::Exist(n)) { + CFILE file = CFILE(n, REA, RCrypt); + LoadGame(file, true); // only system vars + VGA::SetColors(SysPal, 64); + Vga.Update(); + if (FINIS) { + ++ STARTUP::Mode; + FINIS = false; + } + } else + ++STARTUP::Mode; } - } - else ++ STARTUP::Mode; } - } - if (STARTUP::Mode < 2) Movie("X01"); // wink + if (STARTUP::Mode < 2) + Movie("X01"); // wink - VGA::CopyPage(0, 2); + VGA::CopyPage(0, 2); - #ifdef DEMO - return true; - #else - return (STARTUP::Mode == 2 || usr_ok); - #endif +#ifdef DEMO + return true; +#else + return (STARTUP::Mode == 2 || usr_ok); +#endif } - - /* #ifdef DEBUG void StkDump (void) @@ -2257,40 +1908,40 @@ void StkDump (void) */ +void cge_main(void) { + uint16 intStack[STACK_SIZ / 2]; + intStackPtr = intStack; + //Debug( memset((void *) (-K(2)), 0, K(1)); ) + //Debug( memset((void *) (-K(4)), 0, K(1)); ) + memset(Barriers, 0xFF, sizeof(Barriers)); -void cge_main (void) -{ - uint16 intStack[STACK_SIZ/2]; - intStackPtr = intStack; + if (! Mouse.Exist) + error("%s", Text[NO_MOUSE_TEXT]); + if (! SVG0FILE::Exist(SVG0NAME)) + STARTUP::Mode = 2; - //Debug( memset((void *) (-K(2)), 0, K(1)); ) - //Debug( memset((void *) (-K(4)), 0, K(1)); ) - memset(Barriers, 0xFF, sizeof(Barriers)); + Debug(DebugLine.Flags.Hide = true;) + Debug(HorzLine.Flags.Hide = true;) - if (! Mouse.Exist) - error("%s", Text[NO_MOUSE_TEXT]); - if (! SVG0FILE::Exist(SVG0NAME)) STARTUP::Mode = 2; + //srand((uint16) Timer()); + Sys = new SYSTEM; - Debug( DebugLine.Flags.Hide = true; ) - Debug( HorzLine.Flags.Hide = true; ) - - //srand((uint16) Timer()); - Sys = new SYSTEM; - - if (Music && STARTUP::SoundOk) LoadMIDI(0); - if (STARTUP::Mode < 2) Movie(LGO_EXT); - if (ShowTitle("WELCOME")) - { - #ifndef DEMO - if (STARTUP::Mode == 1) Movie("X02"); // intro - #endif - RunGame(); - Startup = 2; - if (FINIS) Movie("X03"); - } - else Vga.Sunset(); - error("%s", Text[EXIT_OK_TEXT+FINIS]); + if (Music && STARTUP::SoundOk) + LoadMIDI(0); + if (STARTUP::Mode < 2) + Movie(LGO_EXT); + if (ShowTitle("WELCOME")) { +#ifndef DEMO + if (STARTUP::Mode == 1) Movie("X02"); // intro +#endif + RunGame(); + Startup = 2; + if (FINIS) + Movie("X03"); + } else + Vga.Sunset(); + error("%s", Text[EXIT_OK_TEXT + FINIS]); } } // End of namespace CGE diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 30a07dd67e9..a67cd290000 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -25,185 +25,163 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE__ -#define __CGE__ +#ifndef __CGE__ +#define __CGE__ -#include "cge\wav.h" -#include "cge\vga13h.h" +#include "cge\wav.h" +#include "cge\vga13h.h" namespace CGE { -#define TSEQ 96 -#define HTALK (TSEQ+4) -#define TOO_FAR (TSEQ+5) -#define NO_WAY (TSEQ+5) -#define POC_FUL (TSEQ+5) -#define OFF_USE (TSEQ+6) +#define TSEQ 96 +#define HTALK (TSEQ+4) +#define TOO_FAR (TSEQ+5) +#define NO_WAY (TSEQ+5) +#define POC_FUL (TSEQ+5) +#define OFF_USE (TSEQ+6) -#define EXIT_OK_TEXT 40 -#define NOMUSIC_TEXT 98 -#define BADSVG_TEXT 99 -#define OFF_USE_COUNT 600 -#define OFF_USE_TEXT 601 -#define NO_WAY_TEXT 671 -#define TOO_FAR_TEXT 681 -#define POC_FUL_TEXT 691 -#define A_C_D_TEXT 777 +#define EXIT_OK_TEXT 40 +#define NOMUSIC_TEXT 98 +#define BADSVG_TEXT 99 +#define OFF_USE_COUNT 600 +#define OFF_USE_TEXT 601 +#define NO_WAY_TEXT 671 +#define TOO_FAR_TEXT 681 +#define POC_FUL_TEXT 691 +#define A_C_D_TEXT 777 -#define GETNAME_PROMPT 50 -#define GETNAME_TITLE 51 +#define GETNAME_PROMPT 50 +#define GETNAME_TITLE 51 -#define QUIT_TITLE 200 -#define QUIT_TEXT 201 -#define NOQUIT_TEXT 202 -#define DEMO_TEXT 300 -#define NOSOUND_TEXT 310 - -#define PAN_HIG 40 -#define WORLD_HIG (SCR_HIG-PAN_HIG) - -#define INFO_X 177 -#define INFO_Y 164 -#define INFO_W 140 +#define QUIT_TITLE 200 +#define QUIT_TEXT 201 +#define NOQUIT_TEXT 202 +#define DEMO_TEXT 300 +#define NOSOUND_TEXT 310 + +#define PAN_HIG 40 +#define WORLD_HIG (SCR_HIG-PAN_HIG) + +#define INFO_X 177 +#define INFO_Y 164 +#define INFO_W 140 #if defined(DEMO) - #define CAVE_X 4 - #define CAVE_Y 166 - #define CAVE_SX 0 - #define CAVE_SY 0 - #define CAVE_DX 23 - #define CAVE_DY 29 - #define CAVE_NX 3 - #define CAVE_NY 1 -#else - #define CAVE_X 4 - #define CAVE_Y 166 - #define CAVE_SX 0 - #define CAVE_SY 0 - #define CAVE_DX 9 - #define CAVE_DY 10 - #define CAVE_NX 8 - #define CAVE_NY 3 +#define CAVE_X 4 +#define CAVE_Y 166 +#define CAVE_SX 0 +#define CAVE_SY 0 +#define CAVE_DX 23 +#define CAVE_DY 29 +#define CAVE_NX 3 +#define CAVE_NY 1 +#else +#define CAVE_X 4 +#define CAVE_Y 166 +#define CAVE_SX 0 +#define CAVE_SY 0 +#define CAVE_DX 9 +#define CAVE_DY 10 +#define CAVE_NX 8 +#define CAVE_NY 3 #endif -#define BUTTON_X 151 -#define BUTTON_Y 164 -#define BUTTON_DX 19 -#define BUTTON_DY 11 -#define BUTTON_NX 1 -#define BUTTON_NY 3 +#define BUTTON_X 151 +#define BUTTON_Y 164 +#define BUTTON_DX 19 +#define BUTTON_DY 11 +#define BUTTON_NX 1 +#define BUTTON_NY 3 + +#define MINI_X 86 +#define MINI_Y 162 -#define MINI_X 86 -#define MINI_Y 162 +//#define MAP_XCNT 16 +//#define MAP_ZCNT 4 +#define MAP_XCNT 40 +#define MAP_ZCNT 20 +#define MAP_TOP 80 +#define MAP_HIG 80 +#define MAP_XGRID (SCR_WID / MAP_XCNT) +#define MAP_ZGRID (MAP_HIG / MAP_ZCNT) -//#define MAP_XCNT 16 -//#define MAP_ZCNT 4 -#define MAP_XCNT 40 -#define MAP_ZCNT 20 -#define MAP_TOP 80 -#define MAP_HIG 80 -#define MAP_XGRID (SCR_WID / MAP_XCNT) -#define MAP_ZGRID (MAP_HIG / MAP_ZCNT) +#define LINE_MAX 512 +#define USER_MAX 100 +#define SHP_MAX 1024 +#define STD_DELAY 3 +#define LEV_MAX 5 +#define CAVE_MAX (CAVE_NX*CAVE_NY) +#define MAX_FIND_LEVEL 3 +#define MAX_DISTANCE 3 -//#if SCR_WID % MAP_XGRID -// #error Illegal horizontal grid size or count -//#endif - -//#if MAP_HIG % MAP_ZGRID -// #error Illegal vertical grid size or count -//#endif - -#define LINE_MAX 512 -#define USER_MAX 100 -#define SHP_MAX 1024 -#define STD_DELAY 3 -#define LEV_MAX 5 -#define CAVE_MAX (CAVE_NX*CAVE_NY) -#define MAX_FIND_LEVEL 3 -#define MAX_DISTANCE 3 - -#define INI_EXT ".INI" -#define IN0_EXT ".IN0" -#define LGO_EXT ".LGO" -#define SVG_EXT ".SVG" - -#define WALKSIDE 10 - -#define BUSY_REF 500 - -#define SYSTIMERATE 6 // 12 Hz -#define HEROFUN0 (40*12) -#define HEROFUN1 ( 2*12) -#define PAIN (Flag[0]) -#define FINIS (Flag[3]) +#define INI_EXT ".INI" +#define IN0_EXT ".IN0" +#define LGO_EXT ".LGO" +#define SVG_EXT ".SVG" + +#define WALKSIDE 10 + +#define BUSY_REF 500 + +#define SYSTIMERATE 6 // 12 Hz +#define HEROFUN0 (40*12) +#define HEROFUN1 ( 2*12) +#define PAIN (Flag[0]) +#define FINIS (Flag[3]) -//-------------------------------------------------------------------------- - - -class SYSTEM : public SPRITE -{ - int lum; +class SYSTEM : public SPRITE { + int lum; public: - static int FunDel; - static void SetPal (void); - static void FunTouch (void); - SYSTEM (void) : SPRITE(NULL) { SetPal(); Tick(); } - void Touch (uint16 mask, int x, int y); - void Tick (void); + static int FunDel; + static void SetPal(void); + static void FunTouch(void); + SYSTEM(void) : SPRITE(NULL) { + SetPal(); + Tick(); + } + void Touch(uint16 mask, int x, int y); + void Tick(void); }; - - -//-------------------------------------------------------------------------- - - - - -class CLUSTER : public COUPLE -{ +class CLUSTER : public COUPLE { public: - static uint8 Map[MAP_ZCNT][MAP_XCNT]; - uint8 &Cell (void); - CLUSTER (void) : COUPLE () { } - CLUSTER (int a, int b) : COUPLE (a, b) { } - bool Protected (void); + static uint8 Map[MAP_ZCNT][MAP_XCNT]; + uint8 &Cell(void); + CLUSTER(void) : COUPLE() { } + CLUSTER(int a, int b) : COUPLE(a, b) { } + bool Protected(void); }; - - -class WALK : public SPRITE -{ +class WALK : public SPRITE { public: - CLUSTER Here; - enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; - int TracePtr; - WALK (BMP_PTR * shpl); - void Tick (void); - void FindWay(CLUSTER c); - void FindWay(SPRITE * spr); - int Distance (SPRITE * spr); - void Turn (DIR d); - void Park (void); - bool Lower (SPRITE * spr); - void Reach (SPRITE * spr, int mode = -1); + CLUSTER Here; + enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; + int TracePtr; + WALK(BMP_PTR *shpl); + void Tick(void); + void FindWay(CLUSTER c); + void FindWay(SPRITE *spr); + int Distance(SPRITE *spr); + void Turn(DIR d); + void Park(void); + bool Lower(SPRITE *spr); + void Reach(SPRITE *spr, int mode = -1); }; +CLUSTER XZ(int x, int y); +CLUSTER XZ(COUPLE xy); - CLUSTER XZ (int x, int y); - CLUSTER XZ (COUPLE xy); +extern WALK *Hero; -extern WALK * Hero; - - - void ExpandSprite (SPRITE * spr); - void ContractSprite (SPRITE * spr); - void cge_main(void); +void ExpandSprite(SPRITE *spr); +void ContractSprite(SPRITE *spr); +void cge_main(void); } // End of namespace CGE diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index ee4d1771f9a..c1e9ae4762b 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -25,11 +25,11 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/config.h" -#include "cge/sound.h" -#include "cge/vmenu.h" -#include "cge/text.h" -#include "cge/cge_main.h" +#include "cge/config.h" +#include "cge/sound.h" +#include "cge/vmenu.h" +#include "cge/text.h" +#include "cge/cge_main.h" namespace CGE { @@ -41,284 +41,255 @@ namespace CGE { 55=wybierz numer portu dla General MIDI 55=konfiguracja karty d¦wi‘kowej */ -#define STYPE_TEXT 51 -#define SPORT_TEXT 52 -#define SIRQ_TEXT 53 -#define SDMA_TEXT 54 -#define MPORT_TEXT 55 -#define MENU_TEXT 56 +#define STYPE_TEXT 51 +#define SPORT_TEXT 52 +#define SIRQ_TEXT 53 +#define SDMA_TEXT 54 +#define MPORT_TEXT 55 +#define MENU_TEXT 56 -#define NONE_TEXT 60 -#define SB_TEXT 61 -#define SBM_TEXT 62 -#define GUS_TEXT 63 -#define GUSM_TEXT 64 -#define MIDI_TEXT 65 -#define AUTO_TEXT 66 +#define NONE_TEXT 60 +#define SB_TEXT 61 +#define SBM_TEXT 62 +#define GUS_TEXT 63 +#define GUSM_TEXT 64 +#define MIDI_TEXT 65 +#define AUTO_TEXT 66 -#define DETECT 0xFFFF +#define DETECT 0xFFFF -static void NONE (void); -static void SB (void); -static void SBM (void); -static void GUS (void); -static void GUSM (void); -static void MIDI (void); -static void AUTO (void); -static void SetPortD (void); -static void SetPortM (void); -static void SetIRQ (void); -static void SetDMA (void); +static void NONE(void); +static void SB(void); +static void SBM(void); +static void GUS(void); +static void GUSM(void); +static void MIDI(void); +static void AUTO(void); +static void SetPortD(void); +static void SetPortM(void); +static void SetIRQ(void); +static void SetDMA(void); -static int DevName[] = { NONE_TEXT, SB_TEXT, SBM_TEXT, - GUS_TEXT, GUSM_TEXT, - MIDI_TEXT, AUTO_TEXT }; +static int DevName[] = { + NONE_TEXT, SB_TEXT, SBM_TEXT, GUS_TEXT, GUSM_TEXT, + MIDI_TEXT, AUTO_TEXT +}; -static CHOICE DevMenu[]={ { NULL, NONE }, - { NULL, SB }, - { NULL, SBM }, - { NULL, GUS }, - { NULL, GUSM }, - { NULL, MIDI }, - { NULL, AUTO }, - { NULL, NULL } }; +static CHOICE DevMenu[] = { + { NULL, NONE }, + { NULL, SB }, + { NULL, SBM }, + { NULL, GUS }, + { NULL, GUSM }, + { NULL, MIDI }, + { NULL, AUTO }, + { NULL, NULL } +}; -static CHOICE DigiPorts[]={ { " 210h", SetPortD }, - { " 220h", SetPortD }, - { " 230h", SetPortD }, - { " 240h", SetPortD }, - { " 250h", SetPortD }, - { " 260h", SetPortD }, - { "AUTO ", SetPortD }, - { NULL, NULL } }; +static CHOICE DigiPorts[] = { + { " 210h", SetPortD }, + { " 220h", SetPortD }, + { " 230h", SetPortD }, + { " 240h", SetPortD }, + { " 250h", SetPortD }, + { " 260h", SetPortD }, + { "AUTO ", SetPortD }, + { NULL, NULL } +}; -static CHOICE MIDIPorts[]={ { " 220h", SetPortM }, - { " 230h", SetPortM }, - { " 240h", SetPortM }, - { " 250h", SetPortM }, - { " 300h", SetPortM }, - { " 320h", SetPortM }, - { " 330h", SetPortM }, - { " 340h", SetPortM }, - { " 350h", SetPortM }, - { " 360h", SetPortM }, - { "AUTO ", SetPortM }, - { NULL, NULL } }; +static CHOICE MIDIPorts[] = { + { " 220h", SetPortM }, + { " 230h", SetPortM }, + { " 240h", SetPortM }, + { " 250h", SetPortM }, + { " 300h", SetPortM }, + { " 320h", SetPortM }, + { " 330h", SetPortM }, + { " 340h", SetPortM }, + { " 350h", SetPortM }, + { " 360h", SetPortM }, + { "AUTO ", SetPortM }, + { NULL, NULL } +}; -static CHOICE BlsterIRQ[]={ { "IRQ 2", SetIRQ }, - { "IRQ 5", SetIRQ }, - { "IRQ 7", SetIRQ }, - { "IRQ 10", SetIRQ }, - { "AUTO ", SetIRQ }, - { NULL, NULL } }; +static CHOICE BlsterIRQ[] = { + { "IRQ 2", SetIRQ }, + { "IRQ 5", SetIRQ }, + { "IRQ 7", SetIRQ }, + { "IRQ 10", SetIRQ }, + { "AUTO ", SetIRQ }, + { NULL, NULL } +}; -static CHOICE GravisIRQ[]={ { "IRQ 2", SetIRQ }, - { "IRQ 5", SetIRQ }, - { "IRQ 7", SetIRQ }, - { "IRQ 11", SetIRQ }, - { "IRQ 12", SetIRQ }, - { "IRQ 15", SetIRQ }, - { "AUTO ", SetIRQ }, - { NULL, NULL } }; +static CHOICE GravisIRQ[] = { + { "IRQ 2", SetIRQ }, + { "IRQ 5", SetIRQ }, + { "IRQ 7", SetIRQ }, + { "IRQ 11", SetIRQ }, + { "IRQ 12", SetIRQ }, + { "IRQ 15", SetIRQ }, + { "AUTO ", SetIRQ }, + { NULL, NULL } +}; -static CHOICE GravisDMA[]={ { "DMA 1", SetDMA }, - { "DMA 3", SetDMA }, - { "DMA 5", SetDMA }, - { "DMA 6", SetDMA }, - { "DMA 7", SetDMA }, - { "AUTO ", SetDMA }, - { NULL, NULL } }; +static CHOICE GravisDMA[] = { + { "DMA 1", SetDMA }, + { "DMA 3", SetDMA }, + { "DMA 5", SetDMA }, + { "DMA 6", SetDMA }, + { "DMA 7", SetDMA }, + { "AUTO ", SetDMA }, + { NULL, NULL } +}; -static CHOICE BlsterDMA[]={ { "DMA 0", SetDMA }, - { "DMA 1", SetDMA }, - { "DMA 3", SetDMA }, - { "AUTO ", SetDMA }, - { NULL, NULL } }; +static CHOICE BlsterDMA[] = { + { "DMA 0", SetDMA }, + { "DMA 1", SetDMA }, + { "DMA 3", SetDMA }, + { "AUTO ", SetDMA }, + { NULL, NULL } +}; - - -void SelectSound (void) -{ - int i; - Sound.Close(); - if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); - Inf(Text[STYPE_TEXT]); - Talk->Goto(Talk->X, FONT_HIG/2); - for (i = 0; i < ArrayCount(DevName); i ++) - DevMenu[i].Text = Text[DevName[i]]; - (new VMENU(DevMenu, SCR_WID/2, Talk->Y+Talk->H+TEXT_VM+FONT_HIG))->SetName(Text[MENU_TEXT]); +void SelectSound(void) { + int i; + Sound.Close(); + if (VMENU::Addr) + SNPOST_(SNKILL, -1, 0, VMENU::Addr); + Inf(Text[STYPE_TEXT]); + Talk->Goto(Talk->X, FONT_HIG / 2); + for (i = 0; i < ArrayCount(DevName); i ++) + DevMenu[i].Text = Text[DevName[i]]; + (new VMENU(DevMenu, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text[MENU_TEXT]); } - - -static void Reset (void) -{ - SNDDrvInfo.DBASE = SNDDrvInfo.DIRQ = SNDDrvInfo.DDMA = SNDDrvInfo.MBASE = DETECT; +static void Reset(void) { + SNDDrvInfo.DBASE = SNDDrvInfo.DIRQ = SNDDrvInfo.DDMA = SNDDrvInfo.MBASE = DETECT; } - - - -static uint16 deco (const char * str, uint16 (*dco)(const char *)) -{ - while (*str && ! IsDigit(*str)) ++ str; - if (*str) return dco(str); - else return DETECT; +static uint16 deco(const char *str, uint16(*dco)(const char *)) { + while (*str && ! IsDigit(*str)) + ++str; + if (*str) + return dco(str); + else + return DETECT; } - - -static uint16 ddeco (const char * str) -{ - return deco(str, atow); +static uint16 ddeco(const char *str) { + return deco(str, atow); } - - -static uint16 xdeco (const char * str) -{ - return deco(str, xtow); +static uint16 xdeco(const char *str) { + return deco(str, xtow); } +static CHOICE *Cho; +static int Hlp; - -static CHOICE * Cho; -static int Hlp; - -static void SNSelect (void) -{ - Inf(Text[Hlp]); - Talk->Goto(Talk->X, FONT_HIG / 2); - (new VMENU(Cho, SCR_WID/2, Talk->Y+Talk->H+TEXT_VM+FONT_HIG))->SetName(Text[MENU_TEXT]); +static void SNSelect(void) { + Inf(Text[Hlp]); + Talk->Goto(Talk->X, FONT_HIG / 2); + (new VMENU(Cho, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text[MENU_TEXT]); } - - -static void Select (CHOICE * cho, int hlp) -{ - Cho = cho; - Hlp = hlp; - //TODO Change the SNPOST message send to a special way to send function pointer - //SNPOST(SNEXEC, -1, 0, (void *)&SNSelect); - warning("STUB: Select"); +static void Select(CHOICE *cho, int hlp) { + Cho = cho; + Hlp = hlp; + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST(SNEXEC, -1, 0, (void *)&SNSelect); + warning("STUB: Select"); } - - - - -static void NONE (void) -{ - SNDDrvInfo.DDEV = DEV_QUIET; - SNDDrvInfo.MDEV = DEV_QUIET; - Sound.Open(); +static void NONE(void) { + SNDDrvInfo.DDEV = DEV_QUIET; + SNDDrvInfo.MDEV = DEV_QUIET; + Sound.Open(); } - -static void SB (void) -{ - SNDDrvInfo.DDEV = DEV_SB; - SNDDrvInfo.MDEV = DEV_SB; - Reset(); - Select(DigiPorts, SPORT_TEXT); +static void SB(void) { + SNDDrvInfo.DDEV = DEV_SB; + SNDDrvInfo.MDEV = DEV_SB; + Reset(); + Select(DigiPorts, SPORT_TEXT); } - -static void SBM (void) -{ - SNDDrvInfo.DDEV = DEV_SB; - SNDDrvInfo.MDEV = DEV_GM; - Reset(); - Select(DigiPorts, SPORT_TEXT); +static void SBM(void) { + SNDDrvInfo.DDEV = DEV_SB; + SNDDrvInfo.MDEV = DEV_GM; + Reset(); + Select(DigiPorts, SPORT_TEXT); } -static void GUS (void) -{ - SNDDrvInfo.DDEV = DEV_GUS; - SNDDrvInfo.MDEV = DEV_GUS; - Reset(); - Select(DigiPorts, SPORT_TEXT); +static void GUS(void) { + SNDDrvInfo.DDEV = DEV_GUS; + SNDDrvInfo.MDEV = DEV_GUS; + Reset(); + Select(DigiPorts, SPORT_TEXT); } - -static void GUSM (void) -{ - SNDDrvInfo.DDEV = DEV_GUS; - SNDDrvInfo.MDEV = DEV_GM; - Reset(); - Select(DigiPorts, SPORT_TEXT); +static void GUSM(void) { + SNDDrvInfo.DDEV = DEV_GUS; + SNDDrvInfo.MDEV = DEV_GM; + Reset(); + Select(DigiPorts, SPORT_TEXT); } -static void MIDI (void) -{ - SNDDrvInfo.DDEV = DEV_QUIET; - SNDDrvInfo.MDEV = DEV_GM; - SNDDrvInfo.MBASE = DETECT; - Select(MIDIPorts, MPORT_TEXT); +static void MIDI(void) { + SNDDrvInfo.DDEV = DEV_QUIET; + SNDDrvInfo.MDEV = DEV_GM; + SNDDrvInfo.MBASE = DETECT; + Select(MIDIPorts, MPORT_TEXT); } - -static void AUTO (void) -{ - SNDDrvInfo.DDEV = DEV_AUTO; - SNDDrvInfo.MDEV = DEV_AUTO; - Reset(); - Sound.Open(); +static void AUTO(void) { + SNDDrvInfo.DDEV = DEV_AUTO; + SNDDrvInfo.MDEV = DEV_AUTO; + Reset(); + Sound.Open(); } - - - - -static void SetPortD (void) -{ - SNDDrvInfo.DBASE = xdeco(DigiPorts[VMENU::Recent].Text); - Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ, SIRQ_TEXT); +static void SetPortD(void) { + SNDDrvInfo.DBASE = xdeco(DigiPorts[VMENU::Recent].Text); + Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ, SIRQ_TEXT); } - -static void SetPortM (void) -{ - SNDDrvInfo.MBASE = xdeco(MIDIPorts[VMENU::Recent].Text); - Sound.Open(); +static void SetPortM(void) { + SNDDrvInfo.MBASE = xdeco(MIDIPorts[VMENU::Recent].Text); + Sound.Open(); } - - -static void SetIRQ (void) -{ - SNDDrvInfo.DIRQ = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ)[VMENU::Recent].Text); - Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA, SDMA_TEXT); +static void SetIRQ(void) { + SNDDrvInfo.DIRQ = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ)[VMENU::Recent].Text); + Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA, SDMA_TEXT); } - - -static void SetDMA (void) -{ - SNDDrvInfo.DDMA = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA)[VMENU::Recent].Text); - if (SNDDrvInfo.MDEV != SNDDrvInfo.DDEV) Select(MIDIPorts, MPORT_TEXT); - else Sound.Open(); +static void SetDMA(void) { + SNDDrvInfo.DDMA = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA)[VMENU::Recent].Text); + if (SNDDrvInfo.MDEV != SNDDrvInfo.DDEV) + Select(MIDIPorts, MPORT_TEXT); + else + Sound.Open(); } } // End of namespace CGE diff --git a/engines/cge/config.h b/engines/cge/config.h index 1e692afc4d6..e3fe094681a 100644 --- a/engines/cge/config.h +++ b/engines/cge/config.h @@ -25,12 +25,12 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CONFIG__ -#define __CONFIG__ +#ifndef __CONFIG__ +#define __CONFIG__ namespace CGE { -void SelectSound (void); +void SelectSound(void); } // End of namespace CGE diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index 7d7a82a82ba..f522f872c92 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -52,7 +52,7 @@ static const ADGameDescription gameDescriptions[] = { "soltys", "Soltys Freeware", { {"vol.cat", 0, "0c33e2c304821a2444d297fc5e2d67c6", 50176}, - {"vol.dat", 0, "f9ae2e7f8f7cac91378cdafca43faf1e", 8437676}, + {"vol.dat", 0, "f9ae2e7f8f7cac91378cdafca43faf1e", 8437676}, AD_LISTEND }, Common::PL_POL, Common::kPlatformPC, ADGF_NO_FLAGS, GUIO_NONE @@ -145,7 +145,9 @@ void CGEMetaEngine::removeSaveState(const char *target, int slot) const { g_system->getSavefileManager()->removeSavefile(fileName); } -int CGEMetaEngine::getMaximumSaveSlot() const { return 99; } +int CGEMetaEngine::getMaximumSaveSlot() const { + return 99; +} SaveStateList CGEMetaEngine::listSaves(const char *target) const { Common::SaveFileManager *saveFileMan = g_system->getSavefileManager(); @@ -249,7 +251,7 @@ bool CGEMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameD } #if PLUGIN_ENABLED_DYNAMIC(CGE) - REGISTER_PLUGIN_DYNAMIC(CGE, PLUGIN_TYPE_ENGINE, CGEMetaEngine); +REGISTER_PLUGIN_DYNAMIC(CGE, PLUGIN_TYPE_ENGINE, CGEMetaEngine); #else - REGISTER_PLUGIN_STATIC(CGE, PLUGIN_TYPE_ENGINE, CGEMetaEngine); +REGISTER_PLUGIN_STATIC(CGE, PLUGIN_TYPE_ENGINE, CGEMetaEngine); #endif diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp index abf118bda2b..b6540005538 100644 --- a/engines/cge/ems.cpp +++ b/engines/cge/ems.cpp @@ -24,217 +24,203 @@ * This code is based on original Soltys source code * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ - + #include "cge/general.h" namespace CGE { -#define EMS_INT 0x67 -#define PAGE_MASK 0x3FFF -#define SIZ(n) ((n) ? ((long)n) : (0x10000L)) +#define EMS_INT 0x67 +#define PAGE_MASK 0x3FFF +#define SIZ(n) ((n) ? ((long)n) : (0x10000L)) -enum EMM_FUN { GET_STATUS = 0x40, - GET_FRAME, - GET_SIZE, - OPEN_HANDLE, - MAP_PAGE, - CLOSE_HANDLE, - GET_VER, - SAVE_CONTEXT, - REST_CONTEXT, - GET_PAGES = 0x4B, - GET_HANDLES, - GET_INFO, - CONTROL }; +enum EMM_FUN { + GET_STATUS = 0x40, GET_FRAME, GET_SIZE, OPEN_HANDLE, MAP_PAGE, + CLOSE_HANDLE, GET_VER, SAVE_CONTEXT, REST_CONTEXT, GET_PAGES = 0x4B, + GET_HANDLES, GET_INFO, CONTROL +}; void *EMM::Frame = NULL; -EMM::EMM (long size): Han(-1), Top(0), Lim(0), List(NULL) { -/* - if (Test()) - { - asm mov ah,GET_FRAME // get EMS frame segment - asm int EMS_INT // do it! - asm or ah,ah // see status - asm jnz xit // abort on error - Frame = (void _seg *) _BX; // save frame segment +EMM::EMM(long size): Han(-1), Top(0), Lim(0), List(NULL) { + /* + if (Test()) + { + asm mov ah,GET_FRAME // get EMS frame segment + asm int EMS_INT // do it! + asm or ah,ah // see status + asm jnz xit // abort on error + Frame = (void _seg *) _BX; // save frame segment - if (size == 0) - { - asm mov ah,GET_SIZE // get EMS memory size - asm int EMS_INT // do it! - asm or ah,ah // see status - asm jnz xit // abort on error - asm or bx,bx // test page count - asm jz xit // abort if no free pages - // number of available pages in BX is ready to use by OPEN - } - else _BX = (uint16) ((size + PAGE_MASK) >> 14); - asm mov ah,OPEN_HANDLE // open EMM handle - asm int EMS_INT // do it! - asm or ah,ah // see status - asm jnz xit // abort on error - Han = _DX; - Lim = _BX; - Lim <<= 14; - _DX = Han; - asm mov ah,SAVE_CONTEXT // save mapping context - asm int EMS_INT // do it! - } - xit: -*/ + if (size == 0) + { + asm mov ah,GET_SIZE // get EMS memory size + asm int EMS_INT // do it! + asm or ah,ah // see status + asm jnz xit // abort on error + asm or bx,bx // test page count + asm jz xit // abort if no free pages + // number of available pages in BX is ready to use by OPEN + } + else _BX = (uint16) ((size + PAGE_MASK) >> 14); + asm mov ah,OPEN_HANDLE // open EMM handle + asm int EMS_INT // do it! + asm or ah,ah // see status + asm jnz xit // abort on error + Han = _DX; + Lim = _BX; + Lim <<= 14; + _DX = Han; + asm mov ah,SAVE_CONTEXT // save mapping context + asm int EMS_INT // do it! + } + xit: + */ warning("STUB: EMM:EMM"); } EMM::~EMM(void) { -/* - Release(); - if (Han >= 0) - { - _DX = Han; - asm mov ah,REST_CONTEXT - asm int EMS_INT - asm mov ah,CLOSE_HANDLE - asm int EMS_INT - } -*/ + /* + Release(); + if (Han >= 0) + { + _DX = Han; + asm mov ah,REST_CONTEXT + asm int EMS_INT + asm mov ah,CLOSE_HANDLE + asm int EMS_INT + } + */ warning("STUB: EMM::~EMM"); } - bool EMM::Test(void) { -/* - static char e[] = "EMMXXXX0"; + /* + static char e[] = "EMMXXXX0"; - asm mov ax,0x3D40 - asm mov dx,offset e - asm int 0x21 - asm jc fail + asm mov ax,0x3D40 + asm mov dx,offset e + asm int 0x21 + asm jc fail - asm push ax - asm mov bx,ax - asm mov ax,0x4407 - asm int 0x21 + asm push ax + asm mov bx,ax + asm mov ax,0x4407 + asm int 0x21 - asm pop bx - asm push ax - asm mov ax,0x3E00 - asm int 0x21 - asm pop ax + asm pop bx + asm push ax + asm mov ax,0x3E00 + asm int 0x21 + asm pop ax - asm cmp al,0x00 - asm je fail + asm cmp al,0x00 + asm je fail - success: - return TRUE; - fail: - return FALSE; -*/ + success: + return TRUE; + fail: + return FALSE; + */ warning("EMM::Test"); return FALSE; } -EMS * EMM::Alloc (uint16 siz) { -/* - long size = SIZ(siz), - top = Top; +EMS *EMM::Alloc(uint16 siz) { + /* + long size = SIZ(siz), + top = Top; - uint16 pgn = (uint16) (top >> 14), - cnt = (uint16) ((top + size + PAGE_MASK) >> 14) - pgn; + uint16 pgn = (uint16) (top >> 14), + cnt = (uint16) ((top + size + PAGE_MASK) >> 14) - pgn; - if (cnt > 4) - { - top = (top + PAGE_MASK) & 0xFFFFC000L; - ++ pgn; - -- cnt; - } - - if (size <= Lim - top) - { - EMS * e = new EMS, * f; - - if (e) - { - Top = (e->Ptr = top) + (e->Siz = siz); - e->Emm = this; - - if (List) + if (cnt > 4) { - for (f = List; f->Nxt; f = f->Nxt); - return (f->Nxt = e); // existing list: link to the end + top = (top + PAGE_MASK) & 0xFFFFC000L; + ++ pgn; + -- cnt; } - else + + if (size <= Lim - top) { - return (List = e); // empty list: link to the head + EMS * e = new EMS, * f; + + if (e) + { + Top = (e->Ptr = top) + (e->Siz = siz); + e->Emm = this; + + if (List) + { + for (f = List; f->Nxt; f = f->Nxt); + return (f->Nxt = e); // existing list: link to the end + } + else + { + return (List = e); // empty list: link to the head + } } - } - } - fail: return NULL; -*/ + } + fail: return NULL; + */ warning("STUB: EMM::Alloc"); return NULL; } -void EMM::Release (void) { - while (List) - { - EMS * e = List; - List = e->Nxt; - delete e; - } - Top = 0; +void EMM::Release(void) { + while (List) { + EMS *e = List; + List = e->Nxt; + delete e; + } + Top = 0; } -EMS::EMS (void) -: Ptr(0), Siz(0), Nxt(NULL) -{ +EMS::EMS(void) : Ptr(0), Siz(0), Nxt(NULL) { } -void * EMS::operator & () const -{ -/* - uint16 pgn = (uint16) (Ptr >> 14), - off = (uint16) Ptr & PAGE_MASK, - cnt = (uint16) ((Ptr + SIZ(Siz) + PAGE_MASK) >> 14) - pgn, - cmd = MAP_PAGE << 8; +void *EMS::operator & () const { + /* + uint16 pgn = (uint16) (Ptr >> 14), + off = (uint16) Ptr & PAGE_MASK, + cnt = (uint16) ((Ptr + SIZ(Siz) + PAGE_MASK) >> 14) - pgn, + cmd = MAP_PAGE << 8; - _DX = Emm->Han; // take EMM handle - asm dec cnt // prapare for deferred checking - asm or dx,dx // see if valid - asm jns more // negative handle = unavailable + _DX = Emm->Han; // take EMM handle + asm dec cnt // prapare for deferred checking + asm or dx,dx // see if valid + asm jns more // negative handle = unavailable - fail: return NULL; + fail: return NULL; - more: - asm mov ax,cmd // command + page frame index - asm mov bx,pgn // logical page number - asm int EMS_INT // do it! - asm or ah,ah // check error code - asm jnz fail // exit on error - asm inc cmd // advance page frame index - asm inc pgn // advance logical page number - asm cmp al,byte ptr cnt // all pages? - asm jb more + more: + asm mov ax,cmd // command + page frame index + asm mov bx,pgn // logical page number + asm int EMS_INT // do it! + asm or ah,ah // check error code + asm jnz fail // exit on error + asm inc cmd // advance page frame index + asm inc pgn // advance logical page number + asm cmp al,byte ptr cnt // all pages? + asm jb more - return (void *) (EMM::Frame + (void *) off); -*/ + return (void *) (EMM::Frame + (void *) off); + */ warning("STUB: EMS::operator &"); return NULL; } -uint16 EMS::Size (void) -{ - return Siz; +uint16 EMS::Size(void) { + return Siz; } } // End of namespace CGE diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 86e1324e0b5..25af315d988 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -25,96 +25,70 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/game.h" -#include "cge/mouse.h" -#include -#include +#include "cge/game.h" +#include "cge/mouse.h" +#include +#include namespace CGE { - - -uint8 * Glass (DAC * pal, uint8 r, uint8 g, uint8 b) -{ - uint8 * x = new uint8[256]; - if (x) - { - uint16 i; - for (i = 0; i < 256; i ++) - { - x[i] = Closest(pal, MkDAC(((uint16)(pal[i].R) * r) / 255, - ((uint16)(pal[i].G) * g) / 255, - ((uint16)(pal[i].B) * b) / 255)); +uint8 *Glass(DAC *pal, uint8 r, uint8 g, uint8 b) { + uint8 *x = new uint8[256]; + if (x) { + uint16 i; + for (i = 0; i < 256; i ++) { + x[i] = Closest(pal, MkDAC(((uint16)(pal[i].R) * r) / 255, + ((uint16)(pal[i].G) * g) / 255, + ((uint16)(pal[i].B) * b) / 255)); + } } - } - return x; + return x; } - - - -uint8 * Mark (DAC * pal) -{ - #define f(c) (c ^ 63) - uint8 * x = new uint8[256]; - if (x) - { - uint16 i; - for (i = 0; i < 256; i ++) - { - x[i] = Closest(pal, MkDAC(f(pal[i].R), - f(pal[i].G), - f(pal[i].B)) ); +uint8 *Mark(DAC *pal) { +#define f(c) (c ^ 63) + uint8 *x = new uint8[256]; + if (x) { + uint16 i; + for (i = 0; i < 256; i ++) { + x[i] = Closest(pal, MkDAC(f(pal[i].R), + f(pal[i].G), + f(pal[i].B))); + } } - } - return x; - #undef f + return x; +#undef f } +int FLY::L = 20, + FLY::T = 40, + FLY::R = 110, + FLY::B = 100; - -//-------------------------------------------------------------------------- - - - -int FLY::L = 20, - FLY::T = 40, - FLY::R = 110, - FLY::B = 100; - - - -FLY::FLY (BITMAP ** shpl) -: SPRITE(shpl), Tx(0), Ty(0) -{ - Step(new_random(2)); - Goto(L + new_random(R - L - W), T + new_random(B - T - H)); +FLY::FLY(BITMAP **shpl) + : SPRITE(shpl), Tx(0), Ty(0) { + Step(new_random(2)); + Goto(L + new_random(R - L - W), T + new_random(B - T - H)); } - - -void FLY::Tick (void) -{ - Step(); - if (! Flags.Kept) - { - if (new_random(10) < 1) - { - Tx = new_random(3) - 1; - Ty = new_random(3) - 1; +void FLY::Tick(void) { + Step(); + if (! Flags.Kept) { + if (new_random(10) < 1) { + Tx = new_random(3) - 1; + Ty = new_random(3) - 1; + } + if (X + Tx < L || X + Tx + W > R) + Tx = -Tx; + if (Y + Ty < T || Y + Ty + H > B) + Ty = -Ty; + Goto(X + Tx, Y + Ty); } - if (X + Tx < L || X + Tx + W > R) Tx = -Tx; - if (Y + Ty < T || Y + Ty + H > B) Ty = -Ty; - Goto(X + Tx, Y + Ty); - } } - -//-------------------------------------------------------------------------- - } // End of namespace CGE diff --git a/engines/cge/game.h b/engines/cge/game.h index 1f45667b6bc..1bc24e1fd9d 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -25,44 +25,37 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __GAME__ -#define __GAME__ +#ifndef __GAME__ +#define __GAME__ -#include "cge/vga13h.h" -#include "cge/bitmaps.h" +#include "cge/vga13h.h" +#include "cge/bitmaps.h" namespace CGE { -#define PAN_HIG 40 -#define LBound(s) (s->X <= 0) -#define RBound(s) (s->X+s->W >= SCR_WID) -#define TBound(s) (s->Y <= 0) -#define BBound(s) (s->Y+s->H >= SCR_HIG - PAN_HIG) +#define PAN_HIG 40 +#define LBound(s) (s->X <= 0) +#define RBound(s) (s->X+s->W >= SCR_WID) +#define TBound(s) (s->Y <= 0) +#define BBound(s) (s->Y+s->H >= SCR_HIG - PAN_HIG) +extern SPRITE *Sys; -extern SPRITE * Sys; - -int Sinus (long x); -uint8 * Glass (DAC * pal, uint8 r, uint8 g, uint8 b); -uint8 * Mark (DAC * pal); +int Sinus(long x); +uint8 *Glass(DAC *pal, uint8 r, uint8 g, uint8 b); +uint8 *Mark(DAC *pal); - - - -class FLY : public SPRITE -{ - static int L, T, R, B; +class FLY : public SPRITE { + static int L, T, R, B; public: - int Tx, Ty; - FLY (BITMAP ** shpl); - void Tick (void); + int Tx, Ty; + FLY(BITMAP **shpl); + void Tick(void); }; - - } // End of namespace CGE #endif diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index f023bb1e0fd..3a0114c672e 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -32,77 +32,77 @@ namespace CGE { - DAC StdPal[] = {// R G B - { 0, 60, 0}, // 198 - { 0, 104, 0}, // 199 - { 20, 172, 0}, // 200 - { 82, 82, 0}, // 201 - { 0, 132, 82}, // 202 - { 132, 173, 82}, // 203 - { 82, 0, 0}, // 204 - { 206, 0, 24}, // 205 - { 255, 33, 33}, // 206 - { 123, 41, 0}, // 207 - { 0, 41, 0}, // 208 - { 0, 0, 82}, // 209 - { 132, 0, 0}, // 210 - { 255, 0, 0}, // 211 - { 255, 66, 66}, // 212 - { 148, 66, 16}, // 213 - { 0, 82, 0}, // 214 - { 0, 0,132}, // 215 - { 173, 0, 0}, // 216 - { 255, 49, 0}, // 217 - { 255, 99, 99}, // 218 - { 181, 107, 49}, // 219 - { 0, 132, 0}, // 220 - { 0, 0,255}, // 221 - { 173, 41, 0}, // 222 - { 255, 82, 0}, // 223 - { 255, 132,132}, // 224 - { 214, 148, 74}, // 225 - { 41, 214, 0}, // 226 - { 0, 82,173}, // 227 - { 255, 214, 0}, // 228 - { 247, 132, 49}, // 229 - { 255, 165,165}, // 230 - { 239, 198,123}, // 231 - { 173, 214, 0}, // 232 - { 0, 132,214}, // 233 - { 57, 57, 57}, // 234 - { 247, 189, 74}, // 235 - { 255, 198,198}, // 236 - { 255, 239,173}, // 237 - { 214, 255,173}, // 238 - { 82, 173,255}, // 239 - { 107, 107,107}, // 240 - { 247, 222, 99}, // 241 - { 255, 0,255}, // 242 - { 255, 132,255}, // 243 - { 132, 132,173}, // 244 - { 148, 247,255}, // 245 - { 148, 148,148}, // 246 - { 82, 0, 82}, // 247 - { 112, 68,112}, // 248 - { 176, 88,144}, // 249 - { 214, 132,173}, // 250 - { 206, 247,255}, // 251 - { 198, 198,198}, // 252 - { 0, 214,255}, // 253 - { 96, 224,96 }, // 254 - { 255, 255,255}, // 255 - }; +DAC StdPal[] = {// R G B + { 0, 60, 0}, // 198 + { 0, 104, 0}, // 199 + { 20, 172, 0}, // 200 + { 82, 82, 0}, // 201 + { 0, 132, 82}, // 202 + { 132, 173, 82}, // 203 + { 82, 0, 0}, // 204 + { 206, 0, 24}, // 205 + { 255, 33, 33}, // 206 + { 123, 41, 0}, // 207 + { 0, 41, 0}, // 208 + { 0, 0, 82}, // 209 + { 132, 0, 0}, // 210 + { 255, 0, 0}, // 211 + { 255, 66, 66}, // 212 + { 148, 66, 16}, // 213 + { 0, 82, 0}, // 214 + { 0, 0, 132}, // 215 + { 173, 0, 0}, // 216 + { 255, 49, 0}, // 217 + { 255, 99, 99}, // 218 + { 181, 107, 49}, // 219 + { 0, 132, 0}, // 220 + { 0, 0, 255}, // 221 + { 173, 41, 0}, // 222 + { 255, 82, 0}, // 223 + { 255, 132, 132}, // 224 + { 214, 148, 74}, // 225 + { 41, 214, 0}, // 226 + { 0, 82, 173}, // 227 + { 255, 214, 0}, // 228 + { 247, 132, 49}, // 229 + { 255, 165, 165}, // 230 + { 239, 198, 123}, // 231 + { 173, 214, 0}, // 232 + { 0, 132, 214}, // 233 + { 57, 57, 57}, // 234 + { 247, 189, 74}, // 235 + { 255, 198, 198}, // 236 + { 255, 239, 173}, // 237 + { 214, 255, 173}, // 238 + { 82, 173, 255}, // 239 + { 107, 107, 107}, // 240 + { 247, 222, 99}, // 241 + { 255, 0, 255}, // 242 + { 255, 132, 255}, // 243 + { 132, 132, 173}, // 244 + { 148, 247, 255}, // 245 + { 148, 148, 148}, // 246 + { 82, 0, 82}, // 247 + { 112, 68, 112}, // 248 + { 176, 88, 144}, // 249 + { 214, 132, 173}, // 250 + { 206, 247, 255}, // 251 + { 198, 198, 198}, // 252 + { 0, 214, 255}, // 253 + { 96, 224, 96 }, // 254 + { 255, 255, 255}, // 255 +}; -EC void _fqsort (void *base, uint16 nelem, uint16 width, int (*fcmp)(const void*, const void*)) { +EC void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)) { warning("STUB: _fqsort"); } -const char * ProgName (const char * ext) { +const char *ProgName(const char *ext) { warning("STUB: ProgName"); return NULL; } -char *MergeExt (char *buf, const char *nam, const char *ext) { +char *MergeExt(char *buf, const char *nam, const char *ext) { // char dr[MAXDRIVE], di[MAXDIR], na[MAXFILE], ex[MAXEXT]; // fnmerge(buf, dr, di, na, (fnsplit(nam, dr, di, na, ex) & EXTENSION) ? ex : ext); // return buf; @@ -110,7 +110,7 @@ char *MergeExt (char *buf, const char *nam, const char *ext) { return buf; } -char *ForceExt (char *buf, const char *nam, const char* ext) { +char *ForceExt(char *buf, const char *nam, const char *ext) { // char dr[MAXDRIVE], di[MAXDIR], na[MAXFILE], ex[MAXEXT]; // fnsplit(nam, dr, di, na, ex); // fnmerge(buf, dr, di, na, ext); @@ -120,157 +120,168 @@ char *ForceExt (char *buf, const char *nam, const char* ext) { } -#define BUF ((uint8 *) buf) -static unsigned Seed = 1; +#define BUF ((uint8 *) buf) +static unsigned Seed = 1; -unsigned FastRand (void) { return Seed = 257 * Seed + 817; } -unsigned FastRand (unsigned s) { return Seed = 257 * s + 817; } +unsigned FastRand(void) { + return Seed = 257 * Seed + 817; +} +unsigned FastRand(unsigned s) { + return Seed = 257 * s + 817; +} -uint16 RCrypt (void * buf, uint16 siz, uint16 seed) { -/* - if (buf && siz) { - uint8 * q = BUF + (siz-1); - seed = FastRand(seed); - * (BUF ++) ^= seed; - while (buf < q) * (BUF ++) ^= FastRand(); - if (buf == q) * BUF ^= (seed = FastRand()); - } - return seed; -*/ +uint16 RCrypt(void *buf, uint16 siz, uint16 seed) { + /* + if (buf && siz) { + uint8 * q = BUF + (siz-1); + seed = FastRand(seed); + * (BUF ++) ^= seed; + while (buf < q) * (BUF ++) ^= FastRand(); + if (buf == q) * BUF ^= (seed = FastRand()); + } + return seed; + */ warning("STUB: RCrypt"); return 0; } -uint16 XCrypt (void *buf, uint16 siz, uint16 seed) { -// for (uint16 i = 0; i < siz; i ++) +uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { +// for (uint16 i = 0; i < siz; i ++) // *(BUF ++) ^= seed; warning("STUB: XCrypt"); return seed; } -uint16 atow (const char *a) { - uint16 w = 0; +uint16 atow(const char *a) { + uint16 w = 0; if (a) while (IsDigit(*a)) w = (10 * w) + (*(a ++) & 0xF); - return w; + return w; } -uint16 xtow (const char *x) { - uint16 w = 0; - if (x) { - while (IsHxDig(*x)) { - register uint16 d = * (x ++); - if (d > '9') - d -= 'A' - ('9' + 1); - w = (w << 4) | (d & 0xF); - } - } - return w; +uint16 xtow(const char *x) { + uint16 w = 0; + if (x) { + while (IsHxDig(*x)) { + register uint16 d = * (x ++); + if (d > '9') + d -= 'A' - ('9' + 1); + w = (w << 4) | (d & 0xF); + } + } + return w; } -char *wtom (uint16 val, char *str, int radix, int len) { - while (-- len >= 0) { - uint16 w = val % radix; - if (w > 9) w += ('A' - ('9'+1)); - str[len] = '0' + w; - val /= radix; - } - return str; +char *wtom(uint16 val, char *str, int radix, int len) { + while (--len >= 0) { + uint16 w = val % radix; + if (w > 9) + w += ('A' - ('9' + 1)); + str[len] = '0' + w; + val /= radix; + } + return str; } -IOHAND::IOHAND (IOMODE mode, CRYPT * crpt) -: XFILE(mode), Handle(-1), Crypt(crpt), Seed(SEED) -{ +char *dwtom(uint32 val, char *str, int radix, int len) { + while (--len >= 0) { + uint16 w = (uint16) (val % radix); + if (w > 9) + w += ('A' - ('9' + 1)); + str[len] = '0' + w; + val /= radix; + } + return str; } -IOHAND::IOHAND (const char *name, IOMODE mode, CRYPT *crpt) -: XFILE(mode), Crypt(crpt), Seed(SEED) -{ -/* switch (mode) - { - case REA : Error = _dos_open(name, O_RDONLY | O_DENYNONE, &Handle); break; - case WRI : Error = _dos_creat(name, FA_ARCH, &Handle); break; - case UPD : Error = _dos_open(name, O_RDWR | O_DENYALL, &Handle); break; - } - if (Error) Handle = -1; -*/ +IOHAND::IOHAND(IOMODE mode, CRYPT *crpt) + : XFILE(mode), Handle(-1), Crypt(crpt), Seed(SEED) { +} + +IOHAND::IOHAND(const char *name, IOMODE mode, CRYPT *crpt) + : XFILE(mode), Crypt(crpt), Seed(SEED) { + /* switch (mode) + { + case REA : Error = _dos_open(name, O_RDONLY | O_DENYNONE, &Handle); break; + case WRI : Error = _dos_creat(name, FA_ARCH, &Handle); break; + case UPD : Error = _dos_open(name, O_RDWR | O_DENYALL, &Handle); break; + } + if (Error) Handle = -1; + */ warning("STUB: IOHAND::IOHAND"); } IOHAND::~IOHAND(void) { -/* - if (Handle != -1) - { - Error = _dos_close(Handle); - Handle = -1; - } -*/ + /* + if (Handle != -1) + { + Error = _dos_close(Handle); + Handle = -1; + } + */ warning("STUB: IOHAND::~IOHAND"); } uint16 IOHAND::Read(void *buf, uint16 len) { -/* - if (Mode == WRI || Handle < 0) return 0; - if (len) Error = _dos_read(Handle, buf, len, &len); - if (Crypt) Seed = Crypt(buf, len, Seed); - return len; -*/ + /* + if (Mode == WRI || Handle < 0) return 0; + if (len) Error = _dos_read(Handle, buf, len, &len); + if (Crypt) Seed = Crypt(buf, len, Seed); + return len; + */ warning("STUB: IOHAND::Read"); return 0; } uint16 IOHAND::Write(void *buf, uint16 len) { -/* - if (len) { - if (Mode == REA || Handle < 0) return 0; - if (Crypt) Seed = Crypt(buf, len, Seed); - Error = _dos_write(Handle, buf, len, &len); - if (Crypt) Seed = Crypt(buf, len, Seed); //------$$$$$$$ - } - return len; -*/ + /* + if (len) { + if (Mode == REA || Handle < 0) return 0; + if (Crypt) Seed = Crypt(buf, len, Seed); + Error = _dos_write(Handle, buf, len, &len); + if (Crypt) Seed = Crypt(buf, len, Seed); //------$$$$$$$ + } + return len; + */ warning("STUB: IOHAND::Write"); return 0; } -long IOHAND::Mark (void) -{ - return (Handle < 0) ? 0 : tell(Handle); +long IOHAND::Mark(void) { + return (Handle < 0) ? 0 : tell(Handle); } -long IOHAND::Seek (long pos) -{ - if (Handle < 0) return 0; - lseek(Handle, pos, SEEK_SET); - return tell(Handle); +long IOHAND::Seek(long pos) { + if (Handle < 0) return 0; + lseek(Handle, pos, SEEK_SET); + return tell(Handle); } -long IOHAND::Size (void) -{ - if (Handle < 0) return 0; - return filelength(Handle); +long IOHAND::Size(void) { + if (Handle < 0) return 0; + return filelength(Handle); } -bool IOHAND::Exist (const char * name) { - return access(name, 0) == 0; +bool IOHAND::Exist(const char *name) { + return access(name, 0) == 0; } -//#define EMS_ADR(a) (FP_SEG(a) > 0xA000) -//#define HNODE_OK(p) (heapchecknode(p)==4) +//#define EMS_ADR(a) (FP_SEG(a) > 0xA000) +//#define HNODE_OK(p) (heapchecknode(p)==4) -MEM_TYPE MemType (void *mem) { -/* if (FP_SEG(mem) == _DS) { - if (heapchecknode((void *)mem)==4) - return NEAR_MEM; - } else { - if (FP_SEG(mem) > 0xA000) - return EMS_MEM; - else if (farheapchecknode(mem)==4) - return FAR_MEM; - } - return BAD_MEM; -*/ +MEM_TYPE MemType(void *mem) { + /* if (FP_SEG(mem) == _DS) { + if (heapchecknode((void *)mem)==4) + return NEAR_MEM; + } else { + if (FP_SEG(mem) > 0xA000) + return EMS_MEM; + else if (farheapchecknode(mem)==4) + return FAR_MEM; + } + return BAD_MEM; + */ warning("STUB: MemType"); return FAR_MEM; } @@ -307,40 +318,48 @@ EC void SNDMIDIStop() { warning("STUB: SNDMIDIStop"); } -DATACK *LoadWave(XFILE * file, EMM * emm) { +DATACK *LoadWave(XFILE *file, EMM *emm) { warning("STUB: LoadWave"); return NULL; } int TakeEnum(const char **tab, const char *txt) { - const char **e; - if (txt) - { - for (e = tab; *e; e ++) - { - if (scumm_stricmp(txt, *e) == 0) - { - return e - tab; - } + const char **e; + if (txt) { + for (e = tab; *e; e ++) { + if (scumm_stricmp(txt, *e) == 0) { + return e - tab; + } + } } - } - return -1; + return -1; } Boot *ReadBoot(int drive) { -/* - struct fatinfo fi; Boot *b; - getfat(drive+1, &fi); - if (fi.fi_sclus & 0x80) return NULL; - if ((b = malloc(fi.fi_bysec)) == NULL) return NULL; - // read boot sector - if (absread(drive, 1, 0L, b) == 0) return b; - free(b); - return NULL; -*/ + /* + struct fatinfo fi; Boot *b; + getfat(drive+1, &fi); + if (fi.fi_sclus & 0x80) return NULL; + if ((b = malloc(fi.fi_bysec)) == NULL) return NULL; + // read boot sector + if (absread(drive, 1, 0L, b) == 0) return b; + free(b); + return NULL; + */ warning("STUB: ReadBoot"); return NULL; } +long Timer(void) { +/* + asm mov ax,0x40 + asm mov es,ax + asm mov cx,es:[0x6C] + asm mov dx,es:[0x6E] + return ((long) _DX << 16) | _CX; +*/ + warning("STUB: Timer"); + return 0; +} } // End of namespace CGE diff --git a/engines/cge/general.h b/engines/cge/general.h index 62919328ed9..7c0bd7f7629 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -25,243 +25,218 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __GENERAL__ -#define __GENERAL__ +#ifndef __GENERAL__ +#define __GENERAL__ #include "common/system.h" #include "common/random.h" #include "common/textconsole.h" #include "common/str.h" - -#include "cge\jbw.h" -#include +#include "cge/jbw.h" +#include +#include "cge/boot.h" namespace CGE { -#define SEED 0xA5 +#define SEED 0xA5 -#define SCR_WID_ 320 -#define SCR_HIG_ 200 -#define SCR_WID ((uint16)SCR_WID_) -#define SCR_HIG ((uint16)SCR_HIG_) -#define SCR_SEG 0xA000 -#define SCR_ADR ((uint8 *) MK_FP(SCR_SEG, 0)) +#define SCR_WID_ 320 +#define SCR_HIG_ 200 +#define SCR_WID ((uint16)SCR_WID_) +#define SCR_HIG ((uint16)SCR_HIG_) +#define SCR_SEG 0xA000 +#define SCR_ADR ((uint8 *) MK_FP(SCR_SEG, 0)) -//enum CPU { _8086, _80186, _80286, _80386, _80486 }; -enum MEM_TYPE { BAD_MEM, EMS_MEM, NEAR_MEM, FAR_MEM }; -enum ALLOC_MODE { FIRST_FIT, BEST_FIT, LAST_FIT }; -enum IOMODE { REA, WRI, UPD }; +//enum CPU { _8086, _80186, _80286, _80386, _80486 }; +enum MEM_TYPE { BAD_MEM, EMS_MEM, NEAR_MEM, FAR_MEM }; +enum ALLOC_MODE { FIRST_FIT, BEST_FIT, LAST_FIT }; +enum IOMODE { REA, WRI, UPD }; -typedef struct { - uint8 R, G, B; - } DAC; +typedef struct { + uint8 R, G, B; +} DAC; -typedef uint16 CRYPT (void *buf, uint16 siz, uint16 seed); +typedef uint16 CRYPT(void *buf, uint16 siz, uint16 seed); extern Common::RandomSource randSrc; #define new_random(a) (randSrc.getRandomNumber(a)) -class COUPLE -{ +class COUPLE { protected: - signed char A; - signed char B; + signed char A; + signed char B; public: - COUPLE (void) { } - COUPLE (const signed char a, const signed char b) : A(a), B(b) { } - COUPLE operator + (COUPLE c) { return COUPLE(A+c.A, B+c.B); } - void operator += (COUPLE c) { A += c.A; B += c.B; } - COUPLE operator - (COUPLE c) { return COUPLE(A-c.A, B-c.B); } - void operator -= (COUPLE c) { A -= c.A; B -= c.B; } - bool operator == (COUPLE c) { return ((A - c.A) | (B - c.B)) == 0; } - bool operator != (COUPLE c) { return ! (operator == (c)); } - void Split (signed char& a, signed char& b) { a = A; b = B; } + COUPLE(void) { } + COUPLE(const signed char a, const signed char b) : A(a), B(b) { } + COUPLE operator + (COUPLE c) { + return COUPLE(A + c.A, B + c.B); + } + + void operator += (COUPLE c) { + A += c.A; + B += c.B; + } + + COUPLE operator - (COUPLE c) { + return COUPLE(A - c.A, B - c.B); + } + + void operator -= (COUPLE c) { + A -= c.A; + B -= c.B; + } + + bool operator == (COUPLE c) { + return ((A - c.A) | (B - c.B)) == 0; + } + + bool operator != (COUPLE c) { + return !(operator == (c)); + } + + void Split(signed char &a, signed char &b) { + a = A; + b = B; + } }; -//------------------------------------------------------------------------- - - - -class ENGINE -{ +class ENGINE { protected: - static void (* OldTimer) (...); - static void NewTimer (...); + static void (* OldTimer)(...); + static void NewTimer(...); public: - ENGINE (uint16 tdiv); - ~ENGINE (void); + ENGINE(uint16 tdiv); + ~ENGINE(void); }; - - -//------------------------------------------------------------------------- - - class EMS; - -class EMM -{ - friend EMS; - bool Test (void); - long Top, Lim; - EMS * List; - int Han; - static void * Frame; +class EMM { + friend EMS; + bool Test(void); + long Top, Lim; + EMS *List; + int Han; + static void *Frame; public: - EMM::EMM (long size = 0); - EMM::~EMM (void); - EMS * Alloc (uint16 siz); - void Release (void); + EMM::EMM(long size = 0); + EMM::~EMM(void); + EMS *Alloc(uint16 siz); + void Release(void); }; - - - -class EMS -{ - friend EMM; - EMM * Emm; - long Ptr; - uint16 Siz; - EMS * Nxt; +class EMS { + friend EMM; + EMM *Emm; + long Ptr; + uint16 Siz; + EMS *Nxt; public: - EMS (void); - void * operator & () const; - uint16 Size (void); + EMS(void); + void *operator & () const; + uint16 Size(void); }; - -//------------------------------------------------------------------------- - - - - template -void Swap (T& A, T& B) -{ - T a = A; - A = B; - B = a; +void Swap(T &A, T &B) { + T a = A; + A = B; + B = a; }; - - - #ifdef __cplusplus - - template -T max (T A, T B) -{ - return (A > B) ? A : B; +T max(T A, T B) { + return (A > B) ? A : B; }; - - template -T min (T A, T B) -{ - return (A < B) ? A : B; +T min(T A, T B) { + return (A < B) ? A : B; }; - - #endif - - - - - -class XFILE -{ +class XFILE { public: - IOMODE Mode; - uint16 Error; - XFILE (void) : Mode(REA), Error(0) { } - XFILE (IOMODE mode) : Mode(mode), Error(0) { } - virtual uint16 Read (void * buf, uint16 len) = 0; - virtual uint16 Write (void * buf, uint16 len) = 0; - virtual long Mark (void) = 0; - virtual long Size (void) = 0; - virtual long Seek (long pos) = 0; + IOMODE Mode; + uint16 Error; + XFILE(void) : Mode(REA), Error(0) { } + XFILE(IOMODE mode) : Mode(mode), Error(0) { } + virtual uint16 Read(void *buf, uint16 len) = 0; + virtual uint16 Write(void *buf, uint16 len) = 0; + virtual long Mark(void) = 0; + virtual long Size(void) = 0; + virtual long Seek(long pos) = 0; }; - - - template -inline uint16 XRead (XFILE * xf, T * t) -{ - return xf->Read((uint8 *) t, sizeof(*t)); +inline uint16 XRead(XFILE *xf, T *t) { + return xf->Read((uint8 *) t, sizeof(*t)); }; - - - -class IOHAND : public XFILE -{ +class IOHAND : public XFILE { protected: - int Handle; - uint16 Seed; - CRYPT * Crypt; + int Handle; + uint16 Seed; + CRYPT *Crypt; public: - IOHAND (const char * name, IOMODE mode = REA, CRYPT crypt = NULL); - IOHAND (IOMODE mode = REA, CRYPT * crpt = NULL); - virtual ~IOHAND (void); - static bool Exist (const char * name); - uint16 Read (void * buf, uint16 len); - uint16 Write (void * buf, uint16 len); - long Mark (void); - long Size (void); - long Seek (long pos); - //timeb Time (void); - // void SetTime (timeb t); + IOHAND(const char *name, IOMODE mode = REA, CRYPT crypt = NULL); + IOHAND(IOMODE mode = REA, CRYPT *crpt = NULL); + virtual ~IOHAND(void); + static bool Exist(const char *name); + uint16 Read(void *buf, uint16 len); + uint16 Write(void *buf, uint16 len); + long Mark(void); + long Size(void); + long Seek(long pos); + //timeb Time (void); +// void SetTime (timeb t); }; - - - -CRYPT XCrypt; -CRYPT RCrypt; - -MEM_TYPE MemType (void *mem); -uint16 atow (const char * a); -uint16 xtow (const char * x); -char * wtom (uint16 val, char * str, int radix, int len); -char * dwtom (uint32 val, char * str, int radix, int len); -int TakeEnum (const char ** tab, const char * txt); -uint16 ChkSum (void *m, uint16 n); -long Timer (void); -char * MergeExt (char * buf, const char * nam, const char * ext); -char * ForceExt (char * buf, const char * nam, const char * ext); -int DriveCD (unsigned drv); -bool IsVga (void); +CRYPT XCrypt; +CRYPT RCrypt; +MEM_TYPE MemType(void *mem); +uint16 atow(const char *a); +uint16 xtow(const char *x); +char *wtom(uint16 val, char *str, int radix, int len); +char *dwtom(uint32 val, char *str, int radix, int len); +int TakeEnum(const char **tab, const char *txt); +uint16 ChkSum(void *m, uint16 n); +long Timer(void); +char *MergeExt(char *buf, const char *nam, const char *ext); +char *ForceExt(char *buf, const char *nam, const char *ext); +int DriveCD(unsigned drv); +bool IsVga(void); // MISSING FUNCTIONS -EC void _fqsort (void *base, uint16 nelem, uint16 width, int (*fcmp)(const void*, const void*)); -const char *ProgName (const char *ext = NULL); -char *MergeExt (char *buf, const char *nam, const char *ext); -char *ForceExt (char *buf, const char *nam, const char *ext); -unsigned FastRand (void); -unsigned FastRand (unsigned s); -uint16 RCrypt (void * buf, uint16 siz, uint16 seed); -uint16 atow (const char *a); -uint16 xtow (const char *x); +EC void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)); +const char *ProgName(const char *ext = NULL); +char *MergeExt(char *buf, const char *nam, const char *ext); +char *ForceExt(char *buf, const char *nam, const char *ext); +unsigned FastRand(void); +unsigned FastRand(unsigned s); +uint16 RCrypt(void *buf, uint16 siz, uint16 seed); +uint16 atow(const char *a); +uint16 xtow(const char *x); +char *wtom(uint16 val, char *str, int radix, int len); +char *dwtom(uint32 val, char * str, int radix, int len); +int TakeEnum(const char **tab, const char *txt); +Boot *ReadBoot(int drive); +long Timer(void); } // End of namespace CGE diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 892ef5ee735..78cc0356a1c 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -25,113 +25,97 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/gettext.h" -#include "cge/keybd.h" -#include "cge/mouse.h" -#include +#include "cge/gettext.h" +#include "cge/keybd.h" +#include "cge/mouse.h" +#include namespace CGE { -GET_TEXT * GET_TEXT::Ptr = NULL; +GET_TEXT *GET_TEXT::Ptr = NULL; - -GET_TEXT::GET_TEXT (const char * info, char * text, int size, void (*click)(void)) -: Text(text), Size(min(size, GTMAX)), Len(min(Size, strlen(text))), - Cntr(GTBLINK), Click(click), OldKeybClient(KEYBOARD::SetClient(this)) -{ - int i = 2 * TEXT_HM + Font.Width(info); - Ptr = this; - Mode = RECT; - TS[0] = Box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); - SetShapeList(TS); - Flags.BDel = true; - Flags.Kill = true; - memcpy(Buff, text, Len); - Buff[Len] = ' '; - Buff[Len+1] = '\0'; - PutLine(0, info); - Tick(); +GET_TEXT::GET_TEXT(const char *info, char *text, int size, void (*click)(void)) + : Text(text), Size(min(size, GTMAX)), Len(min(Size, strlen(text))), + Cntr(GTBLINK), Click(click), OldKeybClient(KEYBOARD::SetClient(this)) { + int i = 2 * TEXT_HM + Font.Width(info); + Ptr = this; + Mode = RECT; + TS[0] = Box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); + SetShapeList(TS); + Flags.BDel = true; + Flags.Kill = true; + memcpy(Buff, text, Len); + Buff[Len] = ' '; + Buff[Len + 1] = '\0'; + PutLine(0, info); + Tick(); } - - - - -GET_TEXT::~GET_TEXT (void) -{ - KEYBOARD::SetClient(OldKeybClient); - Ptr = NULL; +GET_TEXT::~GET_TEXT(void) { + KEYBOARD::SetClient(OldKeybClient); + Ptr = NULL; } - - - - -void GET_TEXT::Tick (void) -{ - if (++ Cntr >= GTBLINK) - { - Buff[Len] ^= (' ' ^ '_'); - Cntr = 0; - } - PutLine(1, Buff); - Time = GTTIME; -} - - - - -void GET_TEXT::Touch (uint16 mask, int x, int y) -{ - static char ogon[] = "•œ¥£˜ ¡"; - static char bezo[] = "ACELNOSXZ"; - char * p; - - if (mask & KEYB) - { - if (Click) Click(); - switch (x) - { - case Enter : Buff[Len] = '\0'; strcpy(Text, Buff); - for (p = Text; *p; p ++) - { - char * q = strchr(ogon, *p); - if (q) *p = bezo[q-ogon]; - } - case Esc : SNPOST_(SNKILL, -1, 0, this); break; - case BSp : if (Len) - { - -- Len; - Buff[Len] = Buff[Len+1]; - Buff[Len+1] = Buff[Len+2]; - } - break; - default : if (x < 'A' || x > 'Z') - { - if (OldKeybClient) - OldKeybClient->Touch(mask, x, y); - } - else - { - if (KEYBOARD::Key[ALT]) - { - p = strchr(bezo, x); - if (p) x = ogon[p-bezo]; - } - if (Len < Size && 2 * TEXT_HM + Font.Width(Buff) + Font.Wid[x] <= W) - { - Buff[Len+2] = Buff[Len+1]; - Buff[Len+1] = Buff[Len]; - Buff[Len ++] = x; - } - } - break; +void GET_TEXT::Tick(void) { + if (++ Cntr >= GTBLINK) { + Buff[Len] ^= (' ' ^ '_'); + Cntr = 0; } - } - else SPRITE::Touch(mask, x, y); + PutLine(1, Buff); + Time = GTTIME; +} + + +void GET_TEXT::Touch(uint16 mask, int x, int y) { + static char ogon[] = "•œ¥£˜ ¡"; + static char bezo[] = "ACELNOSXZ"; + char *p; + + if (mask & KEYB) { + if (Click) + Click(); + switch (x) { + case Enter : + Buff[Len] = '\0'; + strcpy(Text, Buff); + for (p = Text; *p; p ++) { + char *q = strchr(ogon, *p); + if (q) + *p = bezo[q - ogon]; + } + case Esc : + SNPOST_(SNKILL, -1, 0, this); + break; + case BSp : + if (Len) { + --Len; + Buff[Len] = Buff[Len + 1]; + Buff[Len + 1] = Buff[Len + 2]; + } + break; + default : + if (x < 'A' || x > 'Z') { + if (OldKeybClient) + OldKeybClient->Touch(mask, x, y); + } else { + if (KEYBOARD::Key[ALT]) { + p = strchr(bezo, x); + if (p) + x = ogon[p - bezo]; + } + if (Len < Size && 2 * TEXT_HM + Font.Width(Buff) + Font.Wid[x] <= W) { + Buff[Len + 2] = Buff[Len + 1]; + Buff[Len + 1] = Buff[Len]; + Buff[Len ++] = x; + } + } + break; + } + } else + SPRITE::Touch(mask, x, y); } } // End of namespace CGE diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h index 02dbabe9c6b..3fc7e4ff34c 100644 --- a/engines/cge/gettext.h +++ b/engines/cge/gettext.h @@ -25,32 +25,30 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __GETTEXT__ -#define __GETTEXT__ +#ifndef __GETTEXT__ +#define __GETTEXT__ -#include "cge/general.h" -#include "cge/talk.h" +#include "cge/general.h" +#include "cge/talk.h" namespace CGE { -#define GTMAX 24 -#define GTBLINK 6 -#define GTTIME 6 +#define GTMAX 24 +#define GTBLINK 6 +#define GTTIME 6 - -class GET_TEXT : public TALK -{ - char Buff[GTMAX+2], * Text; - uint16 Size, Len; - uint16 Cntr; - SPRITE * OldKeybClient; - void (*Click)(void); +class GET_TEXT : public TALK { + char Buff[GTMAX + 2], * Text; + uint16 Size, Len; + uint16 Cntr; + SPRITE *OldKeybClient; + void (*Click)(void); public: - static GET_TEXT * Ptr; - GET_TEXT (const char * info, char * text, int size, void (*click)(void) = NULL); - ~GET_TEXT (void); - void Touch (uint16 mask, int x, int y); - void Tick (void); + static GET_TEXT *Ptr; + GET_TEXT(const char *info, char *text, int size, void (*click)(void) = NULL); + ~GET_TEXT(void); + void Touch(uint16 mask, int x, int y); + void Tick(void); }; } // End of namespace CGE diff --git a/engines/cge/ident.h b/engines/cge/ident.h index 96e04f4e20d..da36bfa682c 100644 --- a/engines/cge/ident.h +++ b/engines/cge/ident.h @@ -25,18 +25,17 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __IDENT__ -#define __IDENT__ +#ifndef __IDENT__ +#define __IDENT__ namespace CGE { -struct IDENT - { - char copr[83]; - char fill[8]; - unsigned long disk; - unsigned char cork; - }; +struct IDENT { + char copr[83]; + char fill[8]; + unsigned long disk; + unsigned char cork; +}; } // End of namespace CGE diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index bb01017d00f..73131d71e33 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -32,149 +32,150 @@ namespace CGE { +// Defines found in cge.mak +#define DEBUG #define VOL -#define INI_FILE VFILE +#define INI_FILE VFILE // Or is it CFILE? #define PIC_FILE VFILE #define BMP_MODE 0 +// -#define BEL 7 -#define BS 8 -#define HT 9 -#define LF 10 -#define FF 12 -#define CR 13 +#define BEL 7 +#define BS 8 +#define HT 9 +#define LF 10 +#define FF 12 +#define CR 13 -#define TRUE 1 -#define FALSE 0 +#define TRUE 1 +#define FALSE 0 -#define MAXFILE 128 +#define MAXFILE 128 -#define NULL 0 -#define OFF false -#define ON true +#define NULL 0 +#define OFF false +#define ON true -#define IsWhite(c) ((c) == ' ' || (c) == '\t' || (c) == '\n') -#define IsUpper(c) ((c) >= 'A' && (c) <= 'Z') -#define IsLower(c) ((c) >= 'a' && (c) <= 'z') -#define IsDigit(c) ((c) >= '0' && (c) <= '9') -#define IsAlpha(c) (IsLower(c) || IsUpper(c) || (c) == '_') -#define IsAlNum(c) (IsAlpha(c) || IsDigit(c)) -#define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) +#define IsWhite(c) ((c) == ' ' || (c) == '\t' || (c) == '\n') +#define IsUpper(c) ((c) >= 'A' && (c) <= 'Z') +#define IsLower(c) ((c) >= 'a' && (c) <= 'z') +#define IsDigit(c) ((c) >= '0' && (c) <= '9') +#define IsAlpha(c) (IsLower(c) || IsUpper(c) || (c) == '_') +#define IsAlNum(c) (IsAlpha(c) || IsDigit(c)) +#define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) -#define farnew(t,n) ((t *) malloc(sizeof(t) * (n))) -#define ArrayCount(a) (sizeof(a)/sizeof((a)[0])) -#define MAX_TIMER 0x1800B0L +#define farnew(t,n) ((t *) malloc(sizeof(t) * (n))) +#define ArrayCount(a) (sizeof(a)/sizeof((a)[0])) +#define MAX_TIMER 0x1800B0L -typedef void (MouseFunType)(void); +typedef void (MouseFunType)(void); -#define Lo(d) (((int *) &d)[0]) -#define Hi(d) (((int *) &d)[1]) -#define LoWord(d) ((uint16) Lo(d)) -#define HiWord(d) ((uint16) Hi(d)) -#define K(n) (1024*(n)) -#define MASK(n) ((1< +#include "cge/keybd.h" +#include "cge/mouse.h" +#include namespace CGE { -SPRITE * KEYBOARD::Client = NULL; +SPRITE *KEYBOARD::Client = NULL; uint8 KEYBOARD::Key[0x60] = { 0 }; uint16 KEYBOARD::Current = 0; -uint16 KEYBOARD::Code[0x60] = { 0,Esc,'1','2','3','4','5','6','7','8','9','0', - '-','+',BSp,Tab,'Q','W','E','R','T','Y','U', - 'I','O','P','[',']',Enter,0/*Ctrl*/,'A','S', - 'D','F','G','H','J','K','L',';','\'','`', - 0/*LShift*/,'\\','Z','X','C','V','B','N','M', - ',','.','/',0/*RShift*/,'*',0/*Alt*/,' ', - 0/*Caps*/,F1,F2,F3,F4,F5,F6,F7,F8,F9,F10, - 0/*NumLock*/,0/*ScrollLock*/,Home,Up,PgUp, - '-',Left,Ctr,Right,'+',End,Down,PgDn,Ins,Del, - 0*0x54,0*0x55,0*0x56,F11,F12,0*0x59,0*0x5A, - 0*0x5B,0*0x5C,0*0x5D,0*0x5E,0*0x5F - }; -void (* KEYBOARD::OldKeyboard) (...); +uint16 KEYBOARD::Code[0x60] = { + 0, Esc, '1', '2', '3', + '4', '5', '6', '7', '8', + '9', '0', '-', '+', BSp, + Tab, 'Q', 'W', 'E', 'R', + 'T', 'Y', 'U', 'I', 'O', + 'P', '[', ']', Enter, 0/*Ctrl*/, + 'A', 'S', 'D', 'F', 'G', + 'H', 'J', 'K', 'L', ';', + '\'', '`', 0/*LShift*/, '\\', 'Z', + 'X', 'C', 'V', 'B', 'N', + 'M', ',', '.', '/', 0/*RShift*/, + '*', 0/*Alt*/, ' ', 0/*Caps*/, F1, + F2, F3, F4, F5, F6, + F7, F8, F9, F10, 0/*NumLock*/, + 0/*ScrollLock*/, Home, Up, PgUp, '-', + Left, Ctr, Right, '+', End, + Down, PgDn, Ins, Del, 0 * 0x54, + 0 * 0x55, 0 * 0x56, F11, F12, 0 * 0x59, + 0 * 0x5A, 0 * 0x5B, 0 * 0x5C, 0 * 0x5D, 0 * 0x5E, + 0 * 0x5F +}; + +void (* KEYBOARD::OldKeyboard)(...); - -KEYBOARD::KEYBOARD (void) -{ - // steal keyboard interrupt - /* TODO replace totally by scummvm handling - OldKeyboard = getvect(KEYBD_INT); - setvect(KEYBD_INT, NewKeyboard); - */ - warning("STUB: KEYBOARD::KEYBOARD"); +KEYBOARD::KEYBOARD(void) { + // steal keyboard interrupt + /* TODO replace totally by scummvm handling + OldKeyboard = getvect(KEYBD_INT); + setvect(KEYBD_INT, NewKeyboard); + */ + warning("STUB: KEYBOARD::KEYBOARD"); } - - -KEYBOARD::~KEYBOARD (void) -{ - // bring back keyboard interrupt - /* TODO replace totally by scummvm handling +KEYBOARD::~KEYBOARD(void) { + // bring back keyboard interrupt + /* TODO replace totally by scummvm handling setvect(KEYBD_INT, OldKeyboard); - */ - warning("STUB: KEYBOARD::~KEYBOARD"); + */ + warning("STUB: KEYBOARD::~KEYBOARD"); } - - -SPRITE * KEYBOARD::SetClient (SPRITE * spr) -{ - Swap(Client, spr); - return spr; +SPRITE *KEYBOARD::SetClient(SPRITE *spr) { + Swap(Client, spr); + return spr; } - - - -void KEYBOARD::NewKeyboard (...) -{ - // table address +void KEYBOARD::NewKeyboard(...) { + // table address /* - _SI = (uint16) Key; + _SI = (uint16) Key; - // take keyboard code - asm in al,60h - asm mov bl,al - asm and bx,007Fh - asm cmp bl,60h - asm jae xit - asm cmp al,bl - asm je ok // key pressed + // take keyboard code + asm in al,60h + asm mov bl,al + asm and bx,007Fh + asm cmp bl,60h + asm jae xit + asm cmp al,bl + asm je ok // key pressed - // key released... - asm cmp [si+bx],bh // BH == 0 - asm jne ok - // ...but not pressed: call the original service - OldKeyboard(); - return; + // key released... + asm cmp [si+bx],bh // BH == 0 + asm jne ok + // ...but not pressed: call the original service + OldKeyboard(); + return; - ok: - asm shl ax,1 - asm and ah,1 - asm xor ah,1 - asm mov [si+bx],ah - asm jz xit // released: exit + ok: + asm shl ax,1 + asm and ah,1 + asm xor ah,1 + asm mov [si+bx],ah + asm jz xit // released: exit - // pressed: lock ASCII code - _SI = (uint16) Code; - asm add bx,bx // uint16 size - asm mov ax,[si+bx] - asm or ax,ax - asm jz xit // zero means NO KEY - Current = _AX; + // pressed: lock ASCII code + _SI = (uint16) Code; + asm add bx,bx // uint16 size + asm mov ax,[si+bx] + asm or ax,ax + asm jz xit // zero means NO KEY + Current = _AX; - _SI = (uint16) Client; - asm or si,si - asm jz xit // if (Client) ... -//--- fill current event entry with mask, key code and sprite - asm mov bx,EvtHead // take queue head pointer - asm inc byte ptr EvtHead // update queue head pointer - asm shl bx,3 // * 8 - _AX = Current; - asm mov Evt[bx].(struct EVENT)X,ax // key code - asm mov ax,KEYB // event mask - asm mov Evt[bx].(struct EVENT)Msk,ax // event mask - //asm mov Evt[bx].(struct EVENT)Y,dx // row - asm mov Evt[bx].(struct EVENT)Ptr,si // SPRITE pointer + _SI = (uint16) Client; + asm or si,si + asm jz xit // if (Client) ... + //--- fill current event entry with mask, key code and sprite + asm mov bx,EvtHead // take queue head pointer + asm inc byte ptr EvtHead // update queue head pointer + asm shl bx,3 // * 8 + _AX = Current; + asm mov Evt[bx].(struct EVENT)X,ax // key code + asm mov ax,KEYB // event mask + asm mov Evt[bx].(struct EVENT)Msk,ax // event mask + //asm mov Evt[bx].(struct EVENT)Y,dx // row + asm mov Evt[bx].(struct EVENT)Ptr,si // SPRITE pointer - xit: + xit: - asm in al,61h // kbd control lines - asm push ax // save it - asm or al,80h // set the "enable kbd" bit - asm out 61h,al // and write it out - asm pop ax // original control port value - asm out 61h,al // write it back - asm mov al,20h // send End-Of-Interrupt - asm out 20h,al // to the 8259 IC - */ - warning("STUB: KEYBOARD::NewKeyboard"); + asm in al,61h // kbd control lines + asm push ax // save it + asm or al,80h // set the "enable kbd" bit + asm out 61h,al // and write it out + asm pop ax // original control port value + asm out 61h,al // write it back + asm mov al,20h // send End-Of-Interrupt + asm out 20h,al // to the 8259 IC + */ + warning("STUB: KEYBOARD::NewKeyboard"); } } // End of namespace CGE diff --git a/engines/cge/keybd.h b/engines/cge/keybd.h index 5e6c9ac5347..f2fa595be2a 100644 --- a/engines/cge/keybd.h +++ b/engines/cge/keybd.h @@ -25,34 +25,37 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __KEYBD__ -#define __KEYBD__ +#ifndef __KEYBD__ +#define __KEYBD__ -#include "cge/jbw.h" -#include "cge/vga13h.h" +#include "cge/jbw.h" +#include "cge/vga13h.h" namespace CGE { -#define KEYBD_INT 9 -#define LSHIFT 42 -#define RSHIFT 54 -#define CTRL 29 -#define ALT 56 +#define KEYBD_INT 9 +#define LSHIFT 42 +#define RSHIFT 54 +#define CTRL 29 +#define ALT 56 -class KEYBOARD -{ +class KEYBOARD { public: - static void (* OldKeyboard) (...); - static void NewKeyboard (...); - static uint16 Code[0x60]; - static uint16 Current; - static SPRITE * Client; - static uint8 Key[0x60]; - static uint16 Last (void) { uint16 cur = Current; Current = 0; return cur; } - static SPRITE * SetClient (SPRITE * spr); - KEYBOARD (void); - ~KEYBOARD (void); + static void (* OldKeyboard)(...); + static void NewKeyboard(...); + static uint16 Code[0x60]; + static uint16 Current; + static SPRITE *Client; + static uint8 Key[0x60]; + static uint16 Last(void) { + uint16 cur = Current; + Current = 0; + return cur; + } + static SPRITE *SetClient(SPRITE *spr); + KEYBOARD(void); + ~KEYBOARD(void); }; } // End of namespace CGE diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 385634d4b8f..47a6e17fc9a 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -25,136 +25,119 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/mixer.h" -#include "cge/text.h" -#include "cge/snail.h" -#include "cge/mouse.h" -#include "cge/snddrv.h" -#include -//#include +#include "cge/mixer.h" +#include "cge/text.h" +#include "cge/snail.h" +#include "cge/mouse.h" +#include "cge/snddrv.h" +#include namespace CGE { -extern MOUSE Mouse; +extern MOUSE Mouse; - bool MIXER::Appear = false; +bool MIXER::Appear = false; +MIXER::MIXER(int x, int y) : SPRITE(NULL), Fall(MIX_FALL) { + Appear = true; + mb[0] = new BITMAP("VOLUME"); + mb[1] = NULL; + SetShapeList(mb); + SetName(Text[MIX_NAME]); + Flags.Syst = true; + Flags.Kill = true; + Flags.BDel = true; + Goto(x, y); + Z = MIX_Z; -MIXER::MIXER (int x, int y) -: SPRITE(NULL), Fall(MIX_FALL) -{ - int i; - Appear = true; - mb[0] = new BITMAP("VOLUME"); - mb[1] = NULL; - SetShapeList(mb); - SetName(Text[MIX_NAME]); - Flags.Syst = true; - Flags.Kill = true; - Flags.BDel = true; - Goto(x, y); - Z = MIX_Z; + // slaves - // slaves + int i; + for (i = 0; i < MIX_MAX; i ++) { + static char fn[] = "V00"; + wtom(i, fn + 1, 10, 2); + lb[i] = new BITMAP(fn); + ls[i].Now = ls[i].Next = i; + ls[i].Dx = ls[i].Dy = ls[i].Dly = 0; + } + lb[i] = NULL; - for (i = 0; i < MIX_MAX; i ++) - { - static char fn[] = "V00"; - wtom(i, fn+1, 10, 2); - lb[i] = new BITMAP(fn); - ls[i].Now = ls[i].Next = i; - ls[i].Dx = ls[i].Dy = ls[i].Dly = 0; - } - lb[i] = NULL; + for (i = 0; i < ArrayCount(Led); i ++) { + register SPRITE *spr = new SPRITE(lb); + spr->SetSeq(ls); + spr->Goto(x + 2 + 12 * i, y + 8); + spr->Flags.Tran = true; + spr->Flags.Kill = true; + spr->Flags.BDel = false; + spr->Z = MIX_Z; + Led[i] = spr; + } + Led[ArrayCount(Led) - 1]->Flags.BDel = true; - for (i = 0; i < ArrayCount(Led); i ++) - { - register SPRITE * spr = new SPRITE(lb); - spr->SetSeq(ls); - spr->Goto(x+2+12*i, y+8); - spr->Flags.Tran = true; - spr->Flags.Kill = true; - spr->Flags.BDel = false; - spr->Z = MIX_Z; - Led[i] = spr; - } - Led[ArrayCount(Led)-1]->Flags.BDel = true; + VGA::ShowQ.Insert(this); + for (i = 0; i < ArrayCount(Led); i ++) + VGA::ShowQ.Insert(Led[i]); - VGA::ShowQ.Insert(this); - for (i = 0; i < ArrayCount(Led); i ++) VGA::ShowQ.Insert(Led[i]); - - //--- reset balance - i = (SNDDrvInfo.VOL4.ML + SNDDrvInfo.VOL4.MR) / 2; - SNDDrvInfo.VOL4.ML = i; - SNDDrvInfo.VOL4.MR = i; - i = (SNDDrvInfo.VOL4.DL + SNDDrvInfo.VOL4.DR) / 2; - SNDDrvInfo.VOL4.DL = i; - SNDDrvInfo.VOL4.DR = i; - Update(); - Time = MIX_DELAY; + //--- reset balance + i = (SNDDrvInfo.VOL4.ML + SNDDrvInfo.VOL4.MR) / 2; + SNDDrvInfo.VOL4.ML = i; + SNDDrvInfo.VOL4.MR = i; + i = (SNDDrvInfo.VOL4.DL + SNDDrvInfo.VOL4.DR) / 2; + SNDDrvInfo.VOL4.DL = i; + SNDDrvInfo.VOL4.DR = i; + Update(); + Time = MIX_DELAY; } - - - -MIXER::~MIXER (void) -{ - Appear = false; +MIXER::~MIXER(void) { + Appear = false; } - #pragma argsused -void MIXER::Touch (uint16 mask, int x, int y) -{ - SPRITE::Touch(mask, x, y); - if (mask & L_UP) - { - uint8 * vol = (&SNDDrvInfo.VOL2.D) + (x < W/2); - if (y < MIX_BHIG) { if (*vol < 0xFF) *vol += 0x11; } - else if (y >= H-MIX_BHIG) { if (*vol > 0x00) *vol -= 0x11; } - Update(); - } -} - - - -void MIXER::Tick (void) -{ - int x = Mouse.X, y = Mouse.Y; - if (SpriteAt(x, y) == this) - { - Fall = MIX_FALL; - if (Flags.Hold) Touch(L_UP, x-X, y-Y); - } - else - { - if (Fall) -- Fall; - else - { - int i; - for (i = 0; i < ArrayCount(Led); i ++) - { - SNPOST_(SNKILL, -1, 0, Led[i]); - } - SNPOST_(SNKILL, -1, 0, this); +void MIXER::Touch(uint16 mask, int x, int y) { + SPRITE::Touch(mask, x, y); + if (mask & L_UP) { + uint8 *vol = (&SNDDrvInfo.VOL2.D) + (x < W / 2); + if (y < MIX_BHIG) { + if (*vol < 0xFF) + *vol += 0x11; + } else if (y >= H - MIX_BHIG) { + if (*vol > 0x00) + *vol -= 0x11; + } + Update(); } - } - Time = MIX_DELAY; } +void MIXER::Tick(void) { + int x = Mouse.X, y = Mouse.Y; + if (SpriteAt(x, y) == this) { + Fall = MIX_FALL; + if (Flags.Hold) + Touch(L_UP, x - X, y - Y); + } else { + if (Fall) + --Fall; + else { + for (int i = 0; i < ArrayCount(Led); i ++) + SNPOST_(SNKILL, -1, 0, Led[i]); + SNPOST_(SNKILL, -1, 0, this); + } + } + Time = MIX_DELAY; +} -void MIXER::Update (void) -{ - Led[0]->Step(SNDDrvInfo.VOL4.ML); - Led[1]->Step(SNDDrvInfo.VOL4.DL); +void MIXER::Update(void) { + Led[0]->Step(SNDDrvInfo.VOL4.ML); + Led[1]->Step(SNDDrvInfo.VOL4.DL); - //TODO Change the SNPOST message send to a special way to send function pointer - //SNPOST_(SNEXEC, -1, 0, (void*)&SNDSetVolume); - warning("FIXME: MIXER::Update"); + //TODO Change the SNPOST message send to a special way to send function pointer + //SNPOST_(SNEXEC, -1, 0, (void*)&SNDSetVolume); + warning("STUB: MIXER::Update"); } } // End of namespace CGE diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index 30beaf2f5d2..81bc7c7cdf9 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -25,34 +25,33 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __MIXER__ -#define __MIXER__ +#ifndef __MIXER__ +#define __MIXER__ -#include "cge/vga13h.h" +#include "cge/vga13h.h" namespace CGE { -#define MIX_MAX 16 // count of Leds -#define MIX_Z 64 // mixer Z position -#define MIX_DELAY 12 // 6/s -#define MIX_FALL 6 // in MIX_DELAY units -#define MIX_BHIG 6 // mixer button high -#define MIX_NAME 105 // sprite name +#define MIX_MAX 16 // count of Leds +#define MIX_Z 64 // mixer Z position +#define MIX_DELAY 12 // 6/s +#define MIX_FALL 6 // in MIX_DELAY units +#define MIX_BHIG 6 // mixer button high +#define MIX_NAME 105 // sprite name -class MIXER : public SPRITE -{ - BMP_PTR mb[2]; - BMP_PTR lb[MIX_MAX+1]; - SEQ ls[MIX_MAX]; - SPRITE * Led[2]; - int Fall; - void Update (void); +class MIXER : public SPRITE { + BMP_PTR mb[2]; + BMP_PTR lb[MIX_MAX + 1]; + SEQ ls[MIX_MAX]; + SPRITE *Led[2]; + int Fall; + void Update(void); public: - static bool Appear; - MIXER (int x, int y); - ~MIXER (void); - void Touch (uint16 mask, int x, int y); - void Tick (void); + static bool Appear; + MIXER(int x, int y); + ~MIXER(void); + void Touch(uint16 mask, int x, int y); + void Tick(void); }; } // End of namespace CGE diff --git a/engines/cge/module.mk b/engines/cge/module.mk index 552cddb5002..70967667a5b 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -1,5 +1,5 @@ MODULE := engines/cge - + MODULE_OBJS := \ bitmap.o \ bitmaps.o \ @@ -28,11 +28,12 @@ MODULE_OBJS := \ MODULE_DIRS += \ engines/cge - + # This module can be built as a plugin ifeq ($(ENABLE_CGE), DYNAMIC_PLUGIN) PLUGIN := 1 endif - + # Include common rules include $(srcdir)/rules.mk + diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index dff2a0ff8b1..d97a7eca7f4 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -25,215 +25,177 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/mouse.h" -#include "cge/text.h" -#include +#include "cge/mouse.h" +#include "cge/text.h" +#include namespace CGE { - EVENT Evt[EVT_MAX]; +EVENT Evt[EVT_MAX]; - uint16 EvtHead = 0, EvtTail = 0; -//-------------------------------------------------------------------------- +uint16 EvtHead = 0, EvtTail = 0; -MOUSE_FUN * MOUSE::OldMouseFun = NULL; -uint16 MOUSE::OldMouseMask = 0; +MOUSE_FUN *MOUSE::OldMouseFun = NULL; +uint16 MOUSE::OldMouseMask = 0; +MOUSE::MOUSE(BITMAP **shpl) : SPRITE(shpl), Busy(NULL), Hold(NULL), hx(0) { + static SEQ ms[] = { + { 0, 0, 0, 0, 1 }, + { 1, 1, 0, 0, 1 } + }; -//-------------------------------------------------------------------------- + SetSeq(ms); + /* TODO Mouse handling + // Mouse reset + _AX = 0x0000; // soft & hard reset (0x0021 soft reset does not work) + __int__(0x33); + Exist = (_AX != 0); + Buttons = _BX; - - - -MOUSE::MOUSE (BITMAP ** shpl) - : SPRITE(shpl), Busy(NULL), Hold(NULL), hx(0) -{ - static SEQ ms[] = { { 0,0,0,0,1 }, { 1,1,0,0,1 } }; - SetSeq(ms); - - /* TODO Mouse handling - // Mouse reset - _AX = 0x0000; // soft & hard reset (0x0021 soft reset does not work) - __int__(0x33); - Exist = (_AX != 0); - Buttons = _BX; - - Goto(SCR_WID/2, SCR_HIG/2); - Z = 127; - Step(1); - */ + Goto(SCR_WID/2, SCR_HIG/2); + Z = 127; + Step(1); + */ + warning("STUB: MOUSE::MOUSE"); } - - -MOUSE::~MOUSE (void) -{ - Off(); +MOUSE::~MOUSE(void) { + Off(); } - - - //void MOUSE::SetFun (void) //{ //} +void MOUSE::On(void) { + /* + if (SeqPtr && Exist) + { + _CX = X + X; // horizontal position + _DX = Y; // vertical position + _AX = 0x0004; // Set Mouse Position + __int__(0x33); + // set new mouse fun + _ES = FP_SEG(NewMouseFun); + _DX = FP_OFF(NewMouseFun); + _CX = 0x001F; // 11111b = all events + _AX = 0x0014; // Swap User-Interrupt Vector + __int__(0x33); + // save old mouse fun + OldMouseMask = _CX; + OldMouseFun = (MOUSE_FUN *) MK_FP(_ES, _DX); + // set X bounds + _DX = (SCR_WID - W) * 2; // right limit + _CX = 0; // left limit + _AX = 0x0007; // note: each pixel = 2 + __int__(0x33); + // set Y bounds + _DX = SCR_HIG - H; // bottom limit + _CX = 0; // top limit + _AX = 0x0008; + __int__(0x33); -void MOUSE::On (void) -{ - // TODO Mouse -/* - if (SeqPtr && Exist) - { - _CX = X + X; // horizontal position - _DX = Y; // vertical position - _AX = 0x0004; // Set Mouse Position - __int__(0x33); - // set new mouse fun - _ES = FP_SEG(NewMouseFun); - _DX = FP_OFF(NewMouseFun); - _CX = 0x001F; // 11111b = all events - _AX = 0x0014; // Swap User-Interrupt Vector - __int__(0x33); - // save old mouse fun - OldMouseMask = _CX; - OldMouseFun = (MOUSE_FUN *) MK_FP(_ES, _DX); - - // set X bounds - _DX = (SCR_WID - W) * 2; // right limit - _CX = 0; // left limit - _AX = 0x0007; // note: each pixel = 2 - __int__(0x33); - - // set Y bounds - _DX = SCR_HIG - H; // bottom limit - _CX = 0; // top limit - _AX = 0x0008; - __int__(0x33); - - Step(0); - if (Busy) Busy->Step(0); - } -*/ + Step(0); + if (Busy) Busy->Step(0); + } + */ + warning("STUB: MOUSE::On"); } - - - - -void MOUSE::Off (void) -{ -//TODO MOuse ASM - /* - if (SeqPtr == 0) - { - if (Exist) +void MOUSE::Off(void) { +/* + if (SeqPtr == 0) + { + if (Exist) { // bring back old mouse fun _ES = FP_SEG(OldMouseFun); _DX = FP_OFF(OldMouseFun); _CX = OldMouseMask; - _AX = 0x0014; // Swap User-Interrupt Vector + _AX = 0x0014; // Swap User-Interrupt Vector __int__(0x33); } - Step(1); - if (Busy) Busy->Step(1); - } - */ -} - - - - - - -void MOUSE::ClrEvt (SPRITE * spr) -{ - if (spr) - { - uint16 e; - for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) - if (Evt[e].Ptr == spr) Evt[e].Msk = 0; - } - else EvtTail = EvtHead; -} - - - - - - -void MOUSE::Tick (void) -{ - Step(); - while (EvtTail != EvtHead) - { - EVENT e = Evt[EvtTail]; - if (e.Msk) - { - if (Hold && e.Ptr != Hold) - { - Hold->Touch(e.Msk | ATTN, e.X - Hold->X, e.Y - Hold->Y); - } - - // update mouse cursor position - if (e.Msk & ROLL) - { - Goto(e.X, e.Y); - } - - // activate current touched SPRITE - if (e.Ptr) - { - if (e.Msk & KEYB) e.Ptr->Touch(e.Msk, e.X, e.Y); - else e.Ptr->Touch(e.Msk, e.X - e.Ptr->X, e.Y - e.Ptr->Y); - } - else if (Sys) Sys->Touch(e.Msk, e.X, e.Y); - - if (e.Msk & L_DN) - { - Hold = e.Ptr; - if (Hold) - { - Hold->Flags.Hold = true; - #ifndef DEBUG - if (Hold->Flags.Drag) - #endif - { - hx = e.X - Hold->X; - hy = e.Y - Hold->Y; - } - } - } - - if (e.Msk & L_UP) - { - if (Hold) - { - Hold->Flags.Hold = false; - Hold = NULL; - } - } - ///Touched = e.Ptr; - - // discard Text if button released - if (e.Msk & (L_UP | R_UP)) KillText(); + Step(1); + if (Busy) Busy->Step(1); } - EvtTail = (EvtTail + 1) % EVT_MAX; - } - if (Hold) - #ifndef DEBUG - if (Hold->Flags.Drag) - #endif - Hold->Goto(X-hx, Y-hy); + */ + warning("STUB: MOUSE::Off"); +} + + +void MOUSE::ClrEvt(SPRITE *spr) { + if (spr) { + uint16 e; + for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) + if (Evt[e].Ptr == spr) + Evt[e].Msk = 0; + } else + EvtTail = EvtHead; +} + + +void MOUSE::Tick(void) { + Step(); + while (EvtTail != EvtHead) { + EVENT e = Evt[EvtTail]; + if (e.Msk) { + if (Hold && e.Ptr != Hold) + Hold->Touch(e.Msk | ATTN, e.X - Hold->X, e.Y - Hold->Y); + + // update mouse cursor position + if (e.Msk & ROLL) + Goto(e.X, e.Y); + + // activate current touched SPRITE + if (e.Ptr) { + if (e.Msk & KEYB) + e.Ptr->Touch(e.Msk, e.X, e.Y); + else + e.Ptr->Touch(e.Msk, e.X - e.Ptr->X, e.Y - e.Ptr->Y); + } else if (Sys) + Sys->Touch(e.Msk, e.X, e.Y); + + if (e.Msk & L_DN) { + Hold = e.Ptr; + if (Hold) { + Hold->Flags.Hold = true; +#ifndef DEBUG + if (Hold->Flags.Drag) +#endif + { + hx = e.X - Hold->X; + hy = e.Y - Hold->Y; + } + } + } + + if (e.Msk & L_UP) { + if (Hold) { + Hold->Flags.Hold = false; + Hold = NULL; + } + } + ///Touched = e.Ptr; + + // discard Text if button released + if (e.Msk & (L_UP | R_UP)) + KillText(); + } + EvtTail = (EvtTail + 1) % EVT_MAX; + } + if (Hold) +#ifndef DEBUG + if (Hold->Flags.Drag) +#endif + Hold->Goto(X - hx, Y - hy); } } // End of namespace CGE diff --git a/engines/cge/mouse.h b/engines/cge/mouse.h index 20015b058f5..78f43665cd6 100644 --- a/engines/cge/mouse.h +++ b/engines/cge/mouse.h @@ -25,61 +25,57 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __MOUSE__ -#define __MOUSE__ +#ifndef __MOUSE__ +#define __MOUSE__ -#include "cge/game.h" -#include "cge/talk.h" +#include "cge/game.h" +#include "cge/talk.h" namespace CGE { -#define EVT_MAX 256 -#define ROLL 0x01 -#define L_DN 0x02 -#define L_UP 0x04 -#define R_DN 0x08 -#define R_UP 0x10 -#define ATTN 0x20 -// 0x40 -#define KEYB 0x80 +#define EVT_MAX 256 +#define ROLL 0x01 +#define L_DN 0x02 +#define L_UP 0x04 +#define R_DN 0x08 +#define R_UP 0x10 +#define ATTN 0x20 // 0x40 +#define KEYB 0x80 -extern TALK * Talk; +extern TALK *Talk; -struct EVENT { uint16 Msk; - uint16 X, Y; - SPRITE * Ptr; - }; -extern EVENT Evt[EVT_MAX]; -extern uint16 EvtHead, EvtTail; -typedef void (MOUSE_FUN) (void); - - - - - -class MOUSE : public SPRITE -{ - static MOUSE_FUN * OldMouseFun; - static MOUSE_FUN NewMouseFun; - static uint16 OldMouseMask; - SPRITE * Hold; - int hx, hy; - //void SetFun (void); - //void ResetFun (void); -public: - bool Exist; - int Buttons; - SPRITE * Busy; - //SPRITE * Touched; - MOUSE (BITMAP ** shpl = MC); - ~MOUSE (void); - void On (void); - void Off (void); - static void ClrEvt (SPRITE * spr = NULL); - void Tick (void); +struct EVENT { + uint16 Msk; + uint16 X, Y; + SPRITE *Ptr; }; +extern EVENT Evt[EVT_MAX]; +extern uint16 EvtHead, EvtTail; +typedef void (MOUSE_FUN)(void); + + +class MOUSE : public SPRITE { + static MOUSE_FUN *OldMouseFun; + static MOUSE_FUN NewMouseFun; + static uint16 OldMouseMask; + SPRITE *Hold; + int hx, hy; + //void SetFun (void); + //void ResetFun (void); +public: + bool Exist; + int Buttons; + SPRITE *Busy; + //SPRITE * Touched; + MOUSE(BITMAP **shpl = MC); + ~MOUSE(void); + void On(void); + void Off(void); + static void ClrEvt(SPRITE *spr = NULL); + void Tick(void); +}; } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 82ec4c596d3..952e0322222 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -25,1290 +25,1108 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/general.h" -#include "cge/sound.h" -#include "cge/snail.h" -#include "cge/vga13h.h" -#include "cge/bitmaps.h" -#include "cge/text.h" -#include "cge/mouse.h" -#include "cge/cge_main.h" -#include -//#include -//#include -#include -#include -#include "cge/keybd.h" +#include "cge/general.h" +#include "cge/sound.h" +#include "cge/snail.h" +#include "cge/vga13h.h" +#include "cge/bitmaps.h" +#include "cge/text.h" +#include "cge/mouse.h" +#include "cge/cge_main.h" +#include +#include +#include +#include "cge/keybd.h" namespace CGE { - int MaxCave = 0; +int MaxCave = 0; - SCB Scb = { NULL, 0, NULL }; - bool Flag[4]; - bool Dark = false; - bool Game = false; - int Now = 1; - int Lev = -1; - SNAIL Snail = false; - SNAIL Snail_ = true; +SCB Scb = { NULL, 0, NULL }; +bool Flag[4]; +bool Dark = false; +bool Game = false; +int Now = 1; +int Lev = -1; +SNAIL Snail = false; +SNAIL Snail_ = true; -extern SPRITE PocLight; +extern SPRITE PocLight; //------------------------------------------------------------------------- -// SPRITE * Pocket[POCKET_NX]={ NULL, NULL, NULL, NULL, +// SPRITE * Pocket[POCKET_NX]={ NULL, NULL, NULL, NULL, // NULL, NULL, NULL, NULL, }; -// int PocPtr = 0; +// int PocPtr = 0; //------------------------------------------------------------------------- -extern SPRITE * Pocket[]; -extern int PocPtr; -//------------------------------------------------------------------------- - -extern DAC * SysPal; -extern MOUSE Mouse; +extern SPRITE *Pocket[]; +extern int PocPtr; +extern DAC *SysPal; +extern MOUSE Mouse; +static void SNGame(SPRITE *spr, int num) { + switch (num) { + case 1 : { +#define STAGES 8 +#define DRESSED 3 + static SPRITE *dup[3] = { NULL, NULL, NULL }; + int buref = 0; + int Stage = 0; -//------------------------------------------------------------------------- - - -static void SNGame (SPRITE * spr, int num) -{ - switch (num) - { - //-------------------------------------------------------------------- - case 1 : - { - #define STAGES 8 - #define DRESSED 3 - static SPRITE * dup[3] = { NULL, NULL, NULL }; - int buref = 0; - int Stage = 0; - - for (dup[0] = VGA::ShowQ.First(); dup[0]; dup[0] = dup[0]->Next) - { - buref = dup[0]->Ref; - if (buref / 1000 == 16 && buref % 100 == 6) - { - Stage = (buref / 100) % 10; - break; - } - } - if (dup[1] == NULL) - { - dup[1] = VGA::ShowQ.Locate(16003); // pan - dup[2] = VGA::ShowQ.Locate(16004); // pani - } - - if (Game) // continue game - { - int i = new_random(3), hand = (dup[0]->ShpCnt == 6); - ++ Stage; - if (hand && Stage > DRESSED) ++ hand; - if ( - Debug( i >= 0 || ) - dup[i] == spr && new_random(3) == 0) - { - SNPOST(SNSEQ, -1, 3, dup[0]); // yes - SNPOST(SNSEQ, -1, 3, dup[1]); // yes - SNPOST(SNSEQ, -1, 3, dup[2]); // yes - SNPOST(SNTNEXT, -1, 0, dup[0]); // reset Take - SNPOST(SNTNEXT, -1, 0, dup[1]); // reset Take - SNPOST(SNTNEXT, -1, 0, dup[2]); // reset Take - SNPOST(SNNNEXT, -1, 0, dup[0]); // reset Near - SNPOST(SNPAUSE, -1, 72, NULL); // little rest - SNPOST(SNSAY, 1, 16009, NULL); // hura - SNPOST(SNSAY, buref, 16010, NULL); // siadaj - SNPOST(SNSAY, 1, 16011, NULL); // postoj‘ - - if (hand) - { - SNPOST(SNSEND, 16060+hand, 16, NULL); // dawaj r‘k‘ - SNPOST(SNSEQ, buref, 4, NULL); // zdejmowanie - SNPOST(SNSEQ, 16060+hand, 1, NULL); // ruch - SNPOST(SNSOUND, 16060+hand, 16002, NULL); // szelest - SNPOST(SNWAIT, 16060+hand, 3, NULL); // podniesie - SNPOST(SNSWAP, buref, buref+100, NULL); // rozdziana - SNPOST(SNSEQ, 16016, Stage, NULL); // rožnie kupa - SNPOST(SNSEND, 16060+hand, -1, NULL); // chowaj r‘k‘ - SNPOST(SNWAIT, 16060+hand, -1, NULL); // r‘ka zamar’a - } - else - { - SNPOST(SNSEQ, buref, 4, NULL); // zdejmowanie - SNPOST(SNSOUND, 16060+hand, 16002, NULL); // szelest - SNPOST(SNWAIT, buref, -1, NULL); // zdejmie - SNPOST(SNSWAP, buref, buref+100, NULL); // rozdziana - SNPOST(SNSEQ, 16016, Stage, NULL); // rožnie kupa - } - //SNPOST(SNSEQ, buref+100, 0, NULL); // reset - SNPOST(SNPAUSE, -1, 72, NULL); // chwilk‘... - - SNPOST(SNSEQ, -1, 0, dup[1]); // odstaw Go - SNPOST(SNSETXY, -1, 203 + SCR_WID * 49, dup[1]); - SNPOST(SNSETZ, -1, 7, dup[1]); - - SNPOST(SNSEQ, -1, 0, dup[2]); // odstaw J† - SNPOST(SNSETXY, -1, 182 + SCR_WID * 62, dup[2]); - SNPOST(SNSETZ, -1, 9, dup[2]); - Game = 0; - return; - } - else - { - SNPOST(SNSEQ, -1, 2, dup[0]); // no - SNPOST(SNSEQ, -1, 2, dup[1]); // no - SNPOST(SNSEQ, -1, 2, dup[2]); // no - SNPOST(SNPAUSE, -1, 72, NULL); // 1 sec - } - } - SNPOST(SNWALK, 198, 134, NULL); // na miejsce - SNPOST(SNWAIT, 1, -1, NULL); // stoi - SNPOST(SNCOVER, 1, 16101, NULL); // ch’op do bicia - SNPOST(SNSEQ, 16101, 1, NULL); // wystaw - SNPOST(SNWAIT, 16101, 5, NULL); // czekaj - SNPOST(SNPAUSE, 16101, 24, NULL); // czekaj chwil‘ - SNPOST(SNSEQ, 16040, 1, NULL); // plask - SNPOST(SNSOUND, 16101, 16001, NULL); // plask! - SNPOST(SNPAUSE, 16101, 24, NULL); // czekaj chwil‘ - SNPOST(SNSEQ, 16040, 0, NULL); // schowaj plask - SNPOST(SNWAIT, 16101, -1, NULL); // stoi - SNPOST(SNUNCOVER, 1, 16101, NULL); // SDS - if (! Game) - { - SNPOST(SNSAY, buref, 16008, NULL); // zgadnij! - Game = true; - } - #undef STEPS - #undef DRESSED - } break; - //-------------------------------------------------------------------- - case 2 : - { - static SPRITE * k = NULL, * k1, * k2, * k3; - static int count = 0; - bool hit; - - if (k == NULL) - { - k = VGA::ShowQ.Locate(20700); - k1 = VGA::ShowQ.Locate(20701); - k2 = VGA::ShowQ.Locate(20702); - k3 = VGA::ShowQ.Locate(20703); - } - - if (! Game) // init - { - SNPOST(SNGAME, 20002, 2, NULL); - Game = true; - } - else // cont - { - k1->Step(new_random(6)); - k2->Step(new_random(6)); - k3->Step(new_random(6)); - ///-------------------- - if (spr->Ref == 1 && KEYBOARD::Key[ALT]) - { - k1->Step(5); - k2->Step(5); - k3->Step(5); - } - ///-------------------- - SNPOST(SNSETZ, 20700, 0, NULL); - hit = (k1->SeqPtr + k2->SeqPtr + k3->SeqPtr == 15); - if (hit) - { - if (spr->Ref == 1) - { - SNPOST(SNSAY, 1, 20003, NULL); // hura! - SNPOST(SNSEQ, 20011, 2, NULL); // kamera won - SNPOST(SNSEND, 20701, -1, NULL); // k1 won - SNPOST(SNSEND, 20702, -1, NULL); // k2 won - SNPOST(SNSEND, 20703, -1, NULL); // k3 won - SNPOST(SNSEND, 20700, -1, NULL); // tv won - SNPOST(SNKEEP, 20007, 0, NULL); // do kieszeni - SNPOST(SNSEND, 20006, 20, NULL); // bilon - SNPOST(SNSOUND,20006, 20002, NULL); // bilon! - SNPOST(SNSAY, 20002, 20004, NULL); - SNPOST(SNSEND, 20010, 20, NULL); // papier - SNPOST(SNSOUND,20010, 20003, NULL); // papier! - SNPOST(SNSAY, 20001, 20005, NULL); - Game = false; - return; - } - else k3->Step(new_random(5)); - } - if (count < 100) - { - switch (count) - { - case 15 : SNPOST(SNSAY, 20003, 20021, NULL); break; - case 30 : - case 45 : - case 60 : - case 75 : SNPOST(SNSAY, 20003, 20022, NULL); break; - } - ++ count; - } - switch (spr->Ref) - { - case 1 : SNPOST(SNSAY, 20001, 20011, NULL); // zapro - SNPOST(SNSEQ, 20001, 1, NULL); // rzu - SNPOST(SNWAIT, 20001, 1, NULL); // czekaj - SNPOST(SNSETZ, 20700, 2, NULL); // skryj k - SNPOST(SNHIDE, 20007, 1, NULL); // skryj k - SNPOST(SNWAIT, 20001, 16, NULL); // czekaj - SNPOST(SNSEQ, 20007, 1, NULL); // lec† - SNPOST(SNHIDE, 20007, 0, NULL); // poka§ - SNPOST(SNSOUND,20007, 20001, NULL); // grzech - SNPOST(SNWAIT, 20007, -1, NULL); // koniec - SNPOST(SNGAME, 20001, 2, NULL); // again! - break; - case 20001 : SNPOST(SNSAY, 20002, 20012, NULL); // zapro - SNPOST(SNSEQ, 20002, 1, NULL); // rzu - SNPOST(SNWAIT, 20002, 3, NULL); // czekaj - SNPOST(SNSETZ, 20700, 2, NULL); // skryj k - SNPOST(SNHIDE, 20007, 1, NULL); // skryj k - SNPOST(SNWAIT, 20002, 10, NULL); // czekaj - SNPOST(SNSEQ, 20007, 2, NULL); // lec† - SNPOST(SNHIDE, 20007, 0, NULL); // poka§ - SNPOST(SNSOUND,20007, 20001, NULL); // grzech - SNPOST(SNWAIT, 20007, -1, NULL); // koniec - SNPOST(SNGAME, 20002, 2, NULL); // again! - break; - case 20002 : SNPOST(SNSAY, 20002, 20010, NULL); // zapro - SNPOST(SNWALK, 20005, -1, NULL); // do stol - SNPOST(SNWAIT, 1, -1, NULL); // stoi - SNPOST(SNCOVER, 1, 20101, NULL); // grasol - SNPOST(SNSEQ, 20101, 1, NULL); // rzu - SNPOST(SNWAIT, 20101, 5, NULL); // czekaj - SNPOST(SNSETZ, 20700, 2, NULL); // skryj k - SNPOST(SNHIDE, 20007, 1, NULL); // skryj k - SNPOST(SNWAIT, 20101, 15, NULL); // czekaj - SNPOST(SNSEQ, 20007, 1, NULL); // lec† - SNPOST(SNHIDE, 20007, 0, NULL); // poka§ - SNPOST(SNSOUND,20007, 20001, NULL); // grzech - SNPOST(SNWAIT, 20101, -1, NULL); // koniec - SNPOST(SNUNCOVER, 1, 20101, NULL); // SDS - SNPOST(SNGAME, 1, 2, NULL); // again! - break; - } - } - } break; - //-------------------------------------------------------------------- - } -} - - -//------------------------------------------------------------------------- - - - - -void ExpandSprite (SPRITE * spr) -{ - if (spr) VGA::ShowQ.Insert(VGA::SpareQ.Remove(spr)); -} - - - - - -void ContractSprite (SPRITE * spr) -{ - if (spr) VGA::SpareQ.Append(VGA::ShowQ.Remove(spr)); -} - - - - - - - -int FindPocket (SPRITE * spr) -{ - int i; - for (i = 0; i < POCKET_NX; i ++) if (Pocket[i] == spr) return i; - return -1; -} - - - - - -void SelectPocket (int n) -{ - if (n < 0 || (PocLight.SeqPtr && PocPtr == n)) - { - PocLight.Step(0); - n = FindPocket(NULL); - if (n >= 0) PocPtr = n; - } - else - { - if (Pocket[n] != NULL) - { - PocPtr = n; - PocLight.Step(1); - } - } - PocLight.Goto(POCKET_X+PocPtr*POCKET_DX+POCKET_SX, POCKET_Y+POCKET_SY); -} - - - - - -void PocFul (void) -{ - Hero->Park(); - SNPOST(SNWAIT, -1, -1, Hero); - SNPOST(SNSEQ, -1, POC_FUL, Hero); - SNPOST(SNSOUND, -1, 2, Hero); - SNPOST(SNWAIT, -1, -1, Hero); - SNPOST(SNSAY, 1, POC_FUL_TEXT, Hero); -} - - - - -void Hide1 (SPRITE * spr) -{ - SNPOST_(SNGHOST, -1, 0, spr->Ghost()); -} - - - - -void SNGhost (BITMAP * bmp) -{ - // TODO : Get x and y from M but not using segment / offset - //bmp->Hide(FP_OFF(bmp->M), FP_SEG(bmp->M)); - bmp->M = NULL; - delete bmp; - warning("STUB: SNGhost"); -} - - - - -void FeedSnail (SPRITE * spr, SNLIST snq) -{ - if (spr) if (spr->Active()) - { - uint8 ptr = (snq == TAKE) ? spr->TakePtr : spr->NearPtr; - - if (ptr != NO_PTR) - { - SNAIL::COM * comtab = spr->SnList(snq); - SNAIL::COM * c = comtab + ptr; - - if (FindPocket(NULL) < 0) // no empty pockets? - { - SNAIL::COM * p; - for (p = c; p->Com != SNNEXT; p ++) // find KEEP command - { - if (p->Com == SNKEEP) - { - PocFul(); - return; - } - if (p->Ptr) break; - } - } - while (true) - { - if (c->Com == SNTALK) - { - if ((Snail.TalkEnable = (c->Val != 0)) == false) KillText(); - } - if (c->Com == SNNEXT) - { - SPRITE * s = (c->Ref < 0) ? spr : Locate(c->Ref); - if (s) - { - uint8 * idx = (snq == TAKE) ? &s->TakePtr : &s->NearPtr; - if (*idx != NO_PTR) - { - int v; - switch (c->Val) - { - case -1 : v = c - comtab + 1; break; - case -2 : v = c - comtab; break; - case -3 : v = -1; break; - default : v = c->Val; break; - } - if (v >= 0) *idx = v; + for (dup[0] = VGA::ShowQ.First(); dup[0]; dup[0] = dup[0]->Next) { + buref = dup[0]->Ref; + if (buref / 1000 == 16 && buref % 100 == 6) { + Stage = (buref / 100) % 10; + break; } - } - if (s == spr) break; } - if (c->Com == SNIF) - { - SPRITE * s = (c->Ref < 0) ? spr : Locate(c->Ref); - if (s) // sprite extsts - { - if (! s->SeqTest(-1)) c = comtab + c->Val; // not parked - else ++ c; - } - else ++ c; + if (dup[1] == NULL) { + dup[1] = VGA::ShowQ.Locate(16003); // pan + dup[2] = VGA::ShowQ.Locate(16004); // pani } - else - { - SNPOST(c->Com, c->Ref, c->Val, spr); - if (c->Ptr) break; - else ++ c; + + if (Game) { // continue game + int i = new_random(3), hand = (dup[0]->ShpCnt == 6); + ++ Stage; + if (hand && Stage > DRESSED) + ++hand; + if (Debug(i >= 0 ||) + dup[i] == spr && new_random(3) == 0) { + SNPOST(SNSEQ, -1, 3, dup[0]); // yes + SNPOST(SNSEQ, -1, 3, dup[1]); // yes + SNPOST(SNSEQ, -1, 3, dup[2]); // yes + SNPOST(SNTNEXT, -1, 0, dup[0]); // reset Take + SNPOST(SNTNEXT, -1, 0, dup[1]); // reset Take + SNPOST(SNTNEXT, -1, 0, dup[2]); // reset Take + SNPOST(SNNNEXT, -1, 0, dup[0]); // reset Near + SNPOST(SNPAUSE, -1, 72, NULL); // little rest + SNPOST(SNSAY, 1, 16009, NULL); // hura + SNPOST(SNSAY, buref, 16010, NULL); // siadaj + SNPOST(SNSAY, 1, 16011, NULL); // postoj‘ + + if (hand) { + SNPOST(SNSEND, 16060 + hand, 16, NULL); // dawaj r‘k‘ + SNPOST(SNSEQ, buref, 4, NULL); // zdejmowanie + SNPOST(SNSEQ, 16060 + hand, 1, NULL); // ruch + SNPOST(SNSOUND, 16060 + hand, 16002, NULL); // szelest + SNPOST(SNWAIT, 16060 + hand, 3, NULL); // podniesie + SNPOST(SNSWAP, buref, buref + 100, NULL); // rozdziana + SNPOST(SNSEQ, 16016, Stage, NULL); // rožnie kupa + SNPOST(SNSEND, 16060 + hand, -1, NULL); // chowaj r‘k‘ + SNPOST(SNWAIT, 16060 + hand, -1, NULL); // r‘ka zamar’a + } else { + SNPOST(SNSEQ, buref, 4, NULL); // zdejmowanie + SNPOST(SNSOUND, 16060 + hand, 16002, NULL); // szelest + SNPOST(SNWAIT, buref, -1, NULL); // zdejmie + SNPOST(SNSWAP, buref, buref + 100, NULL); // rozdziana + SNPOST(SNSEQ, 16016, Stage, NULL); // rožnie kupa + } + //SNPOST(SNSEQ, buref+100, 0, NULL); // reset + SNPOST(SNPAUSE, -1, 72, NULL); // chwilk‘... + + SNPOST(SNSEQ, -1, 0, dup[1]); // odstaw Go + SNPOST(SNSETXY, -1, 203 + SCR_WID * 49, dup[1]); + SNPOST(SNSETZ, -1, 7, dup[1]); + + SNPOST(SNSEQ, -1, 0, dup[2]); // odstaw J† + SNPOST(SNSETXY, -1, 182 + SCR_WID * 62, dup[2]); + SNPOST(SNSETZ, -1, 9, dup[2]); + Game = 0; + return; + } else { + SNPOST(SNSEQ, -1, 2, dup[0]); // no + SNPOST(SNSEQ, -1, 2, dup[1]); // no + SNPOST(SNSEQ, -1, 2, dup[2]); // no + SNPOST(SNPAUSE, -1, 72, NULL); // 1 sec + } + } + SNPOST(SNWALK, 198, 134, NULL); // na miejsce + SNPOST(SNWAIT, 1, -1, NULL); // stoi + SNPOST(SNCOVER, 1, 16101, NULL); // ch’op do bicia + SNPOST(SNSEQ, 16101, 1, NULL); // wystaw + SNPOST(SNWAIT, 16101, 5, NULL); // czekaj + SNPOST(SNPAUSE, 16101, 24, NULL); // czekaj chwil‘ + SNPOST(SNSEQ, 16040, 1, NULL); // plask + SNPOST(SNSOUND, 16101, 16001, NULL); // plask! + SNPOST(SNPAUSE, 16101, 24, NULL); // czekaj chwil‘ + SNPOST(SNSEQ, 16040, 0, NULL); // schowaj plask + SNPOST(SNWAIT, 16101, -1, NULL); // stoi + SNPOST(SNUNCOVER, 1, 16101, NULL); // SDS + if (! Game) { + SNPOST(SNSAY, buref, 16008, NULL); // zgadnij! + Game = true; } - } +#undef STEPS +#undef DRESSED } - } -} - - - - - - -//-------------------------------------------------------------------------- - -const char * SNAIL::ComTxt[] = { "LABEL", "PAUSE", "WAIT", "LEVEL", - "HIDE", "SAY", "INF", "TIME", - "CAVE", "KILL", "RSEQ", - "SEQ", "SEND", "SWAP", "KEEP", "GIVE", - "IF", "GAME", "SETX0", "SETY0", "SLAVE", - "SETXY", "RELX", "RELY", "RELZ", - "SETX", "SETY", "SETZ", "TRANS", "PORT", - "NEXT","NNEXT", "TNEXT", "RNNEXT", "RTNEXT", - "RMNEAR", "RMTAKE", "FLAG", "SETREF", - "BACKPT", "FLASH", "LIGHT", - "SETHB", "SETVB", - "WALK", "REACH", "COVER", "UNCOVER", - "CLEAR", "TALK", "MOUSE", - "SOUND", "COUNT", - NULL }; - - - -SNAIL::SNAIL (bool turbo) -: Turbo(turbo), Busy(false), TextDelay(false), - Pause(0), TalkEnable(true), - Head(0), Tail(0), SNList(farnew(COM, 256)) -{ -} - - - - - - -SNAIL::~SNAIL (void) -{ - if (SNList) free(SNList); -} - - - - - - -void SNAIL::AddCom (SNCOM com, int ref, int val, void * ptr) -{ - _disable(); - COM * snc = &SNList[Head ++]; - snc->Com = com; - snc->Ref = ref; - snc->Val = val; - snc->Ptr = ptr; - if (com == SNCLEAR) - { - Tail = Head; - KillText(); - Pause = 0; - } - _enable(); -} - - - - -void SNAIL::InsCom (SNCOM com, int ref, int val, void * ptr) -{ - COM * snc; - - _disable(); - if (Busy) - { - SNList[(Tail-1)&0xFF] = SNList[Tail]; - snc = &SNList[Tail]; - } - else snc = &SNList[(Tail-1)&0xFF]; - -- Tail; - snc->Com = com; - snc->Ref = ref; - snc->Val = val; - snc->Ptr = ptr; - if (com == SNCLEAR) - { - Tail = Head; - KillText(); - Pause = 0; - } - _enable(); -} - - - - - - - -static void SNNNext(SPRITE * sprel, int p) -{ - if (sprel) if (sprel->NearPtr != NO_PTR) sprel->NearPtr = p; -} - - - - - - -static void SNTNext(SPRITE * sprel, int p) -{ - if (sprel) if (sprel->TakePtr != NO_PTR) sprel->TakePtr = p; -} - - - - - - -static void SNRNNext(SPRITE * sprel, int p) -{ - if (sprel) if (sprel->NearPtr != NO_PTR) sprel->NearPtr += p; -} - - - - - - -static void SNRTNext(SPRITE * sprel, int p) -{ - if (sprel) if (sprel->TakePtr != NO_PTR) sprel->TakePtr += p; -} - - - - - - -static void SNZTrim (SPRITE * spr) -{ - if (spr) if (spr->Active()) - { - bool en = HEART::Enable; - SPRITE * s; - HEART::Enable = false; - s = (spr->Flags.Shad) ? spr->Prev : NULL; - VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr)); - if (s) - { - s->Z = spr->Z; - VGA::ShowQ.Insert(VGA::ShowQ.Remove(s), spr); - } - HEART::Enable = en; - } -} - - - - - - -static void SNHide (SPRITE * spr, int val) -{ - if (spr) - { - spr->Flags.Hide = (val >= 0) ? (val != 0) : (! spr->Flags.Hide); - if (spr->Flags.Shad) spr->Prev->Flags.Hide = spr->Flags.Hide; - } -} - - - - - -static void SNRmNear (SPRITE * spr) -{ - if (spr) spr->NearPtr = NO_PTR; -} - - - - - -static void SNRmTake (SPRITE * spr) -{ - if (spr) spr->TakePtr = NO_PTR; -} - - - - - -void SNSeq (SPRITE * spr, int val) -{ - if (spr) - { - if (spr == Hero && val == 0) Hero->Park(); - else spr->Step(val); - } -} - - - - - -void SNRSeq (SPRITE * spr, int val) -{ - if (spr) SNSeq(spr, spr->SeqPtr + val); -} - - - - - -void SNSend (SPRITE * spr, int val) -{ - if (spr) - { - int was = spr->Cave; - bool was1 = (was == 0 || was == Now); - bool val1 = (val == 0 || val == Now); - spr->Cave = val; - if (val1 != was1) - { - if (was1) - { - if (spr->Flags.Kept) - { - int n = FindPocket(spr); - if (n >= 0) Pocket[n] = NULL; + break; + //-------------------------------------------------------------------- + case 2 : { + static SPRITE *k = NULL, * k1, * k2, * k3; + static int count = 0; + bool hit; + + if (k == NULL) { + k = VGA::ShowQ.Locate(20700); + k1 = VGA::ShowQ.Locate(20701); + k2 = VGA::ShowQ.Locate(20702); + k3 = VGA::ShowQ.Locate(20703); } - Hide1(spr); - ContractSprite(spr); - spr->Flags.Slav = false; - } - else - { - if (spr->Ref % 1000 == 0) BITMAP::Pal = SysPal; - if (spr->Flags.Back) spr->BackShow(true); - else ExpandSprite(spr); - BITMAP::Pal = NULL; - } - } - } -} - - - - -void SNSwap (SPRITE * spr, int xref) -{ - SPRITE * xspr = Locate(xref); - if (spr && xspr) - { - int was = spr->Cave; - int xwas = xspr->Cave; - bool was1 = (was == 0 || was == Now); - bool xwas1 = (xwas == 0 || xwas == Now); - - Swap(spr->Cave, xspr->Cave); - Swap(spr->X, xspr->X); - Swap(spr->Y, xspr->Y); - Swap(spr->Z, xspr->Z); - if (spr->Flags.Kept) - { - int n = FindPocket(spr); - if (n >= 0) Pocket[n] = xspr; - xspr->Flags.Kept = true; - xspr->Flags.Port = false; - } - if (xwas1 != was1) - { - if (was1) - { - Hide1(spr); - ContractSprite(spr); - } - else ExpandSprite(spr); - if (xwas1) - { - Hide1(xspr); - ContractSprite(xspr); - } - else ExpandSprite(xspr); - } - } -} - - - - - -void SNCover (SPRITE * spr, int xref) -{ - SPRITE * xspr = Locate(xref); - if (spr && xspr) - { - spr->Flags.Hide = true; - xspr->Z = spr->Z; - xspr->Cave = spr->Cave; - xspr->Goto(spr->X, spr->Y); - ExpandSprite(xspr); - if ((xspr->Flags.Shad = spr->Flags.Shad) == TRUE) - { - VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr->Prev), xspr); - spr->Flags.Shad = false; - } - FeedSnail(xspr, NEAR); - } -} - - - - - -void SNUncover (SPRITE * spr, SPRITE * xspr) -{ - if (spr && xspr) - { - spr->Flags.Hide = false; - spr->Cave = xspr->Cave; - spr->Goto(xspr->X, xspr->Y); - if ((spr->Flags.Shad = xspr->Flags.Shad) == TRUE) - { - VGA::ShowQ.Insert(VGA::ShowQ.Remove(xspr->Prev), spr); - xspr->Flags.Shad = false; - } - spr->Z = xspr->Z; - SNSend(xspr, -1); - if (spr->Time == 0) ++ spr->Time; - } -} - - - - - -void SNSetX0 (int cav, int x0) -{ - HeroXY[cav-1].X = x0; -} - - - - - -void SNSetY0 (int cav, int y0) -{ - HeroXY[cav-1].Y = y0; -} - - - - - -void SNSetXY (SPRITE * spr, uint16 xy) -{ - if (spr) - { - spr->Goto(xy % SCR_WID, xy / SCR_WID); - } -} - - - - - -void SNRelX (SPRITE * spr, int x) -{ - if (spr && Hero) - { - spr->Goto(Hero->X + x, spr->Y); - } -} - - - - - -void SNRelY (SPRITE * spr, int y) -{ - if (spr && Hero) - { - spr->Goto(spr->X, Hero->Y + y); - } -} - - - - - -void SNRelZ (SPRITE * spr, int z) -{ - if (spr && Hero) - { - spr->Z = Hero->Z + z; - SNZTrim(spr); - } -} - - - - - -void SNSetX (SPRITE * spr, int x) -{ - if (spr) - { - spr->Goto(x, spr->Y); - } -} - - - - - -void SNSetY (SPRITE * spr, int y) -{ - if (spr) - { - spr->Goto(spr->X, y); - } -} - - - - - -void SNSetZ (SPRITE * spr, int z) -{ - if (spr) - { - spr->Z = z; - //SNPOST_(SNZTRIM, -1, 0, spr); - SNZTrim(spr); - } -} - - - - - -void SNSlave (SPRITE * spr, int ref) -{ - SPRITE * slv = Locate(ref); - if (spr && slv) - { - if (spr->Active()) - { - SNSend(slv, spr->Cave); - slv->Flags.Slav = true; - slv->Z = spr->Z; - VGA::ShowQ.Insert(VGA::ShowQ.Remove(slv), spr->Next); - } - } -} - - - - - -void SNTrans (SPRITE * spr, int trans) -{ - if (spr) - { - spr->Flags.Tran = (trans < 0) ? !spr->Flags.Tran : (trans != 0); - } -} - - - - - -void SNPort (SPRITE * spr, int port) -{ - if (spr) - { - spr->Flags.Port = (port < 0) ? !spr->Flags.Port : (port != 0); - } -} - - - - - -void SNKill (SPRITE * spr) -{ - if (spr) - { - if (spr->Flags.Kept) - { - int n = FindPocket(spr); - if (n >= 0) Pocket[n] = NULL; - } - SPRITE * nx = spr->Next; - Hide1(spr); - VGA::ShowQ.Remove(spr); - MOUSE::ClrEvt(spr); - if (spr->Flags.Kill) delete spr; - else - { - spr->Cave = -1; - VGA::SpareQ.Append(spr); - } - if (nx) if (nx->Flags.Slav) SNKill(nx); - } -} - - - - - -static void SNSound (SPRITE * spr, int wav, int cnt) -{ - if (SNDDrvInfo.DDEV) - { - if (wav == -1) Sound.Stop(); - else - Sound.Play(Fx[wav], (spr) ? ((spr->X+spr->W/2)/(SCR_WID/16)) : 8, cnt); - } -} - - - - - -void SNKeep (SPRITE * spr, int stp) -{ - SelectPocket(-1); - if (spr && ! spr->Flags.Kept && Pocket[PocPtr] == NULL) - { - SNSound(spr, 3, 1); - Pocket[PocPtr] = spr; - spr->Cave = 0; - spr->Flags.Kept = true; - spr->Goto(POCKET_X + POCKET_DX*PocPtr + POCKET_DX/2 - spr->W/2, - POCKET_Y + POCKET_DY/2 - spr->H/2); - if (stp >= 0) spr->Step(stp); - } - SelectPocket(-1); -} - - - - - - -void SNGive (SPRITE * spr, int stp) -{ - if (spr) - { - int p = FindPocket(spr); - if (p >= 0) - { - Pocket[p] = NULL; - spr->Cave = Now; - spr->Flags.Kept = false; - if (stp >= 0) spr->Step(stp); - } - } - SelectPocket(-1); -} - - - - -static void SNBackPt (SPRITE * spr, int stp) -{ - if (spr) - { - if (stp >= 0) spr->Step(stp); - spr->BackShow(true); - } -} - - - - - -static void SNLevel (SPRITE * spr, int lev) -{ - #ifdef DEMO - static int maxcav[] = { CAVE_MAX }; - #else - static int maxcav[] = { 1, 8, 16, 23, 24 }; - #endif - while (Lev < lev) - { - SPRITE * spr; - ++ Lev; - spr = VGA::SpareQ.Locate(100+Lev); - if (spr) - { - spr->BackShow(true); - spr->Cave = 0; - } - } - MaxCave = maxcav[Lev]; - if (spr) spr->Flags.Hide = false; -} - - - - - - -static void SNFlag (int fn, bool v) -{ - Flag[fn] = v; -} - - - - - - -static void SNSetRef (SPRITE * spr, int nr) -{ - if (spr) - { - spr->Ref = nr; - } -} - - - - -void SNFlash (bool on) -{ - if (on) - { - DAC * pal = farnew(DAC, PAL_CNT); - if (pal) - { - int i; - memcpy(pal, SysPal, PAL_SIZ); - for (i = 0; i < PAL_CNT; i ++) - { - register int c; - c = pal[i].R << 1; pal[i].R = (c < 64) ? c : 63; - c = pal[i].G << 1; pal[i].G = (c < 64) ? c : 63; - c = pal[i].B << 1; pal[i].B = (c < 64) ? c : 63; - } - VGA::SetColors(pal, 64); - } - } - else VGA::SetColors(SysPal, 64); - Dark = false; -} - - - - - -static void SNLight (bool in) -{ - if (in) VGA::Sunrise(SysPal); - else VGA::Sunset(); - Dark = ! in; -} - - - - - -static void SNBarrier (int cav, int bar, bool horz) -{ - ((uint8 *) (Barriers + ((cav > 0) ? cav : Now)))[horz] = bar; -} - - - - - -static void SNWalk (SPRITE * spr, int x, int y) -{ - if (Hero) - { - if (spr && y < 0) Hero->FindWay(spr); - else Hero->FindWay(XZ(x, y)); - } -} - - - - - -static void SNReach (SPRITE * spr, int mode) -{ - if (Hero) Hero->Reach(spr, mode); -} - - - - - - -static void SNMouse (bool on) -{ - if (on) Mouse.On(); - else Mouse.Off(); -} - - - - - - -void SNAIL::RunCom (void) -{ - static int count = 1; - extern void SwitchCave(int); - if (! Busy) - { - Busy = true; - uint8 tmphea = Head; - while (Tail != tmphea) - { - COM * snc = &SNList[Tail]; - - if (! Turbo) // only for the slower one - { - if (Pause) break; - else - { - if (TextDelay) - { - KillText(); - TextDelay = false; - } + if (! Game) { // init + SNPOST(SNGAME, 20002, 2, NULL); + Game = true; + } else { // cont + k1->Step(new_random(6)); + k2->Step(new_random(6)); + k3->Step(new_random(6)); + ///-------------------- + if (spr->Ref == 1 && KEYBOARD::Key[ALT]) { + k1->Step(5); + k2->Step(5); + k3->Step(5); + } + ///-------------------- + SNPOST(SNSETZ, 20700, 0, NULL); + hit = (k1->SeqPtr + k2->SeqPtr + k3->SeqPtr == 15); + if (hit) { + if (spr->Ref == 1) { + SNPOST(SNSAY, 1, 20003, NULL); // hura! + SNPOST(SNSEQ, 20011, 2, NULL); // kamera won + SNPOST(SNSEND, 20701, -1, NULL); // k1 won + SNPOST(SNSEND, 20702, -1, NULL); // k2 won + SNPOST(SNSEND, 20703, -1, NULL); // k3 won + SNPOST(SNSEND, 20700, -1, NULL); // tv won + SNPOST(SNKEEP, 20007, 0, NULL); // do kieszeni + SNPOST(SNSEND, 20006, 20, NULL); // bilon + SNPOST(SNSOUND, 20006, 20002, NULL); // bilon! + SNPOST(SNSAY, 20002, 20004, NULL); + SNPOST(SNSEND, 20010, 20, NULL); // papier + SNPOST(SNSOUND, 20010, 20003, NULL); // papier! + SNPOST(SNSAY, 20001, 20005, NULL); + Game = false; + return; + } else + k3->Step(new_random(5)); + } + if (count < 100) { + switch (count) { + case 15 : + SNPOST(SNSAY, 20003, 20021, NULL); + break; + case 30 : + case 45 : + case 60 : + case 75 : + SNPOST(SNSAY, 20003, 20022, NULL); + break; + } + ++ count; + } + switch (spr->Ref) { + case 1 : + SNPOST(SNSAY, 20001, 20011, NULL); // zapro + SNPOST(SNSEQ, 20001, 1, NULL); // rzu + SNPOST(SNWAIT, 20001, 1, NULL); // czekaj + SNPOST(SNSETZ, 20700, 2, NULL); // skryj k + SNPOST(SNHIDE, 20007, 1, NULL); // skryj k + SNPOST(SNWAIT, 20001, 16, NULL); // czekaj + SNPOST(SNSEQ, 20007, 1, NULL); // lec† + SNPOST(SNHIDE, 20007, 0, NULL); // poka§ + SNPOST(SNSOUND, 20007, 20001, NULL); // grzech + SNPOST(SNWAIT, 20007, -1, NULL); // koniec + SNPOST(SNGAME, 20001, 2, NULL); // again! + break; + case 20001 : + SNPOST(SNSAY, 20002, 20012, NULL); // zapro + SNPOST(SNSEQ, 20002, 1, NULL); // rzu + SNPOST(SNWAIT, 20002, 3, NULL); // czekaj + SNPOST(SNSETZ, 20700, 2, NULL); // skryj k + SNPOST(SNHIDE, 20007, 1, NULL); // skryj k + SNPOST(SNWAIT, 20002, 10, NULL); // czekaj + SNPOST(SNSEQ, 20007, 2, NULL); // lec† + SNPOST(SNHIDE, 20007, 0, NULL); // poka§ + SNPOST(SNSOUND, 20007, 20001, NULL); // grzech + SNPOST(SNWAIT, 20007, -1, NULL); // koniec + SNPOST(SNGAME, 20002, 2, NULL); // again! + break; + case 20002 : + SNPOST(SNSAY, 20002, 20010, NULL); // zapro + SNPOST(SNWALK, 20005, -1, NULL); // do stol + SNPOST(SNWAIT, 1, -1, NULL); // stoi + SNPOST(SNCOVER, 1, 20101, NULL); // grasol + SNPOST(SNSEQ, 20101, 1, NULL); // rzu + SNPOST(SNWAIT, 20101, 5, NULL); // czekaj + SNPOST(SNSETZ, 20700, 2, NULL); // skryj k + SNPOST(SNHIDE, 20007, 1, NULL); // skryj k + SNPOST(SNWAIT, 20101, 15, NULL); // czekaj + SNPOST(SNSEQ, 20007, 1, NULL); // lec† + SNPOST(SNHIDE, 20007, 0, NULL); // poka§ + SNPOST(SNSOUND, 20007, 20001, NULL); // grzech + SNPOST(SNWAIT, 20101, -1, NULL); // koniec + SNPOST(SNUNCOVER, 1, 20101, NULL); // SDS + SNPOST(SNGAME, 1, 2, NULL); // again! + break; + } } - if (Talk && snc->Com != SNPAUSE) break; - } - - SPRITE * sprel = ((snc->Ref >= 0) ? Locate(snc->Ref) - : ((SPRITE *) snc->Ptr)); - switch (snc->Com) - { - case SNLABEL : break; - case SNPAUSE : HEART::SetXTimer(&Pause, snc->Val); - if (Talk) TextDelay = true; break; - case SNWAIT : if (sprel) - { - if (sprel->SeqTest(snc->Val) && - (snc->Val >= 0 || sprel != Hero || Hero->TracePtr < 0)) - { - HEART::SetXTimer(&Pause, sprel->Time); - } - else goto xit; - } - break; - case SNLEVEL : SNLevel(sprel, snc->Val); break; - case SNHIDE : SNHide(sprel, snc->Val); break; - case SNSAY : if (sprel && TalkEnable) - { - if (sprel == Hero && sprel->SeqTest(-1)) - sprel->Step(HTALK); - Say(Text[snc->Val], sprel); - SYSTEM::FunDel = HEROFUN0; - } - break; - case SNINF : if (TalkEnable) - { - Inf(Text[snc->Val]); - SYSTEM::FunDel = HEROFUN0; - } - break; - case SNTIME : if (sprel && TalkEnable) - { - if (sprel == Hero && sprel->SeqTest(-1)) - sprel->Step(HTALK); - SayTime(sprel); - } - break; - case SNCAVE : SwitchCave(snc->Val); break; - case SNKILL : SNKill(sprel); break; - case SNSEQ : SNSeq(sprel, snc->Val); break; - case SNRSEQ : SNRSeq(sprel, snc->Val); break; - case SNSEND : SNSend(sprel, snc->Val); break; - case SNSWAP : SNSwap(sprel, snc->Val); break; - case SNCOVER : SNCover(sprel, snc->Val); break; - case SNUNCOVER : SNUncover(sprel, (snc->Val >= 0) ? Locate(snc->Val) - : ((SPRITE *) snc->Ptr)); - break; - case SNKEEP : SNKeep(sprel, snc->Val); break; - case SNGIVE : SNGive(sprel, snc->Val); break; - case SNGAME : SNGame(sprel, snc->Val); break; - case SNSETX0 : SNSetX0(snc->Ref, snc->Val); break; - case SNSETY0 : SNSetY0(snc->Ref, snc->Val); break; - case SNSETXY : SNSetXY(sprel, snc->Val); break; - case SNRELX : SNRelX(sprel, snc->Val); break; - case SNRELY : SNRelY(sprel, snc->Val); break; - case SNRELZ : SNRelZ(sprel, snc->Val); break; - case SNSETX : SNSetX(sprel, snc->Val); break; - case SNSETY : SNSetY(sprel, snc->Val); break; - case SNSETZ : SNSetZ(sprel, snc->Val); break; - case SNSLAVE : SNSlave(sprel, snc->Val); break; - case SNTRANS : SNTrans(sprel, snc->Val); break; - case SNPORT : SNPort(sprel, snc->Val); break; - case SNNEXT : break; - case SNIF : break; - case SNTALK : break; - case SNMOUSE : SNMouse(snc->Val != 0); break; - case SNNNEXT : SNNNext(sprel, snc->Val); break; - case SNTNEXT : SNTNext(sprel, snc->Val); break; - case SNRNNEXT : SNRNNext(sprel, snc->Val); break; - case SNRTNEXT : SNRTNext(sprel, snc->Val); break; - case SNRMNEAR : SNRmNear(sprel); break; - case SNRMTAKE : SNRmTake(sprel); break; - case SNFLAG : SNFlag(snc->Ref & 3, snc->Val != 0); break; - case SNSETREF : SNSetRef(sprel, snc->Val); break; - case SNBACKPT : SNBackPt(sprel, snc->Val); break; - case SNFLASH : SNFlash(snc->Val != 0); break; - case SNLIGHT : SNLight(snc->Val != 0); break; - case SNSETHB : SNBarrier(snc->Ref, snc->Val, true); break; - case SNSETVB : SNBarrier(snc->Ref, snc->Val, false); break; - case SNWALK : SNWalk(sprel, snc->Ref, snc->Val); break; - case SNREACH : SNReach(sprel, snc->Val); break; - case SNSOUND : SNSound(sprel, snc->Val, count); count = 1; break; - case SNCOUNT : count = snc->Val; break; - - // TODO: Handle correctly the execution of function pointer coming from Message send SNPOST - //case SNEXEC : ((void(*)(int)) (snc->Ptr))(snc->Val); break; - case SNEXEC : warning("STUB: SNEXEC code"); - case SNSTEP : sprel->Step(); break; - case SNZTRIM : SNZTrim(sprel); break; - case SNGHOST : SNGhost((BITMAP *) snc->Ptr); break; - } - ++ Tail; - if (! Turbo) break; } - xit: - Busy = false; - } + break; + } } +void ExpandSprite(SPRITE *spr) { + if (spr) + VGA::ShowQ.Insert(VGA::SpareQ.Remove(spr)); +} +void ContractSprite(SPRITE *spr) { + if (spr) + VGA::SpareQ.Append(VGA::ShowQ.Remove(spr)); +} -bool SNAIL::Idle (void) -{ - return (Head == Tail); +int FindPocket(SPRITE *spr) { + for (int i = 0; i < POCKET_NX; i ++) + if (Pocket[i] == spr) + return i; + return -1; +} + + +void SelectPocket(int n) { + if (n < 0 || (PocLight.SeqPtr && PocPtr == n)) { + PocLight.Step(0); + n = FindPocket(NULL); + if (n >= 0) + PocPtr = n; + } else { + if (Pocket[n] != NULL) { + PocPtr = n; + PocLight.Step(1); + } + } + PocLight.Goto(POCKET_X + PocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY); +} + + +void PocFul(void) { + Hero->Park(); + SNPOST(SNWAIT, -1, -1, Hero); + SNPOST(SNSEQ, -1, POC_FUL, Hero); + SNPOST(SNSOUND, -1, 2, Hero); + SNPOST(SNWAIT, -1, -1, Hero); + SNPOST(SNSAY, 1, POC_FUL_TEXT, Hero); +} + + +void Hide1(SPRITE *spr) { + SNPOST_(SNGHOST, -1, 0, spr->Ghost()); +} + + +void SNGhost(BITMAP *bmp) { + // TODO : Get x and y from M but not using segment / offset + //bmp->Hide(FP_OFF(bmp->M), FP_SEG(bmp->M)); + bmp->M = NULL; + delete bmp; + warning("STUB: SNGhost"); +} + + +void FeedSnail(SPRITE *spr, SNLIST snq) { + if (spr) + if (spr->Active()) { + uint8 ptr = (snq == TAKE) ? spr->TakePtr : spr->NearPtr; + + if (ptr != NO_PTR) { + SNAIL::COM *comtab = spr->SnList(snq); + SNAIL::COM *c = comtab + ptr; + + if (FindPocket(NULL) < 0) { // no empty pockets? + SNAIL::COM *p; + for (p = c; p->Com != SNNEXT; p ++) { // find KEEP command + if (p->Com == SNKEEP) { + PocFul(); + return; + } + if (p->Ptr) + break; + } + } + while (true) { + if (c->Com == SNTALK) { + if ((Snail.TalkEnable = (c->Val != 0)) == false) + KillText(); + } + if (c->Com == SNNEXT) { + SPRITE *s = (c->Ref < 0) ? spr : Locate(c->Ref); + if (s) { + uint8 *idx = (snq == TAKE) ? &s->TakePtr : &s->NearPtr; + if (*idx != NO_PTR) { + int v; + switch (c->Val) { + case -1 : + v = c - comtab + 1; + break; + case -2 : + v = c - comtab; + break; + case -3 : + v = -1; + break; + default : + v = c->Val; + break; + } + if (v >= 0) + *idx = v; + } + } + if (s == spr) + break; + } + if (c->Com == SNIF) { + SPRITE *s = (c->Ref < 0) ? spr : Locate(c->Ref); + if (s) { // sprite extsts + if (! s->SeqTest(-1)) + c = comtab + c->Val; // not parked + else + ++c; + } else + ++c; + } else { + SNPOST(c->Com, c->Ref, c->Val, spr); + if (c->Ptr) + break; + else + ++c; + } + } + } + } +} + + +const char *SNAIL::ComTxt[] = { + "LABEL", "PAUSE", "WAIT", "LEVEL", "HIDE", + "SAY", "INF", "TIME", "CAVE", "KILL", + "RSEQ", "SEQ", "SEND", "SWAP", "KEEP", + "GIVE", "IF", "GAME", "SETX0", "SETY0", + "SLAVE", "SETXY", "RELX", "RELY", "RELZ", + "SETX", "SETY", "SETZ", "TRANS", "PORT", + "NEXT", "NNEXT", "TNEXT", "RNNEXT", "RTNEXT", + "RMNEAR", "RMTAKE", "FLAG", "SETREF", "BACKPT", + "FLASH", "LIGHT", "SETHB", "SETVB", "WALK", + "REACH", "COVER", "UNCOVER", "CLEAR", "TALK", + "MOUSE", "SOUND", "COUNT", NULL +}; + + +SNAIL::SNAIL(bool turbo) + : Turbo(turbo), Busy(false), TextDelay(false), + Pause(0), TalkEnable(true), + Head(0), Tail(0), SNList(farnew(COM, 256)) { +} + + +SNAIL::~SNAIL(void) { + if (SNList) + free(SNList); +} + + +void SNAIL::AddCom(SNCOM com, int ref, int val, void *ptr) { + _disable(); + COM *snc = &SNList[Head ++]; + snc->Com = com; + snc->Ref = ref; + snc->Val = val; + snc->Ptr = ptr; + if (com == SNCLEAR) { + Tail = Head; + KillText(); + Pause = 0; + } + _enable(); +} + + +void SNAIL::InsCom(SNCOM com, int ref, int val, void *ptr) { + COM *snc; + + _disable(); + if (Busy) { + SNList[(Tail - 1) & 0xFF] = SNList[Tail]; + snc = &SNList[Tail]; + } else + snc = &SNList[(Tail - 1) & 0xFF]; + --Tail; + snc->Com = com; + snc->Ref = ref; + snc->Val = val; + snc->Ptr = ptr; + if (com == SNCLEAR) { + Tail = Head; + KillText(); + Pause = 0; + } + _enable(); +} + + +static void SNNNext(SPRITE *sprel, int p) { + if (sprel) + if (sprel->NearPtr != NO_PTR) + sprel->NearPtr = p; +} + + +static void SNTNext(SPRITE *sprel, int p) { + if (sprel) + if (sprel->TakePtr != NO_PTR) + sprel->TakePtr = p; +} + + +static void SNRNNext(SPRITE *sprel, int p) { + if (sprel) + if (sprel->NearPtr != NO_PTR) + sprel->NearPtr += p; +} + + +static void SNRTNext(SPRITE *sprel, int p) { + if (sprel) + if (sprel->TakePtr != NO_PTR) + sprel->TakePtr += p; +} + + +static void SNZTrim(SPRITE *spr) { + if (spr) + if (spr->Active()) { + bool en = HEART::Enable; + SPRITE *s; + HEART::Enable = false; + s = (spr->Flags.Shad) ? spr->Prev : NULL; + VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr)); + if (s) { + s->Z = spr->Z; + VGA::ShowQ.Insert(VGA::ShowQ.Remove(s), spr); + } + HEART::Enable = en; + } +} + + +static void SNHide(SPRITE *spr, int val) { + if (spr) { + spr->Flags.Hide = (val >= 0) ? (val != 0) : (! spr->Flags.Hide); + if (spr->Flags.Shad) + spr->Prev->Flags.Hide = spr->Flags.Hide; + } +} + + +static void SNRmNear(SPRITE *spr) { + if (spr) + spr->NearPtr = NO_PTR; +} + + +static void SNRmTake(SPRITE *spr) { + if (spr) + spr->TakePtr = NO_PTR; +} + + +void SNSeq(SPRITE *spr, int val) { + if (spr) { + if (spr == Hero && val == 0) + Hero->Park(); + else + spr->Step(val); + } +} + + +void SNRSeq(SPRITE *spr, int val) { + if (spr) + SNSeq(spr, spr->SeqPtr + val); +} + + +void SNSend(SPRITE *spr, int val) { + if (spr) { + int was = spr->Cave; + bool was1 = (was == 0 || was == Now); + bool val1 = (val == 0 || val == Now); + spr->Cave = val; + if (val1 != was1) { + if (was1) { + if (spr->Flags.Kept) { + int n = FindPocket(spr); + if (n >= 0) + Pocket[n] = NULL; + } + Hide1(spr); + ContractSprite(spr); + spr->Flags.Slav = false; + } else { + if (spr->Ref % 1000 == 0) + BITMAP::Pal = SysPal; + if (spr->Flags.Back) + spr->BackShow(true); + else + ExpandSprite(spr); + BITMAP::Pal = NULL; + } + } + } +} + + +void SNSwap(SPRITE *spr, int xref) { + SPRITE *xspr = Locate(xref); + if (spr && xspr) { + int was = spr->Cave; + int xwas = xspr->Cave; + bool was1 = (was == 0 || was == Now); + bool xwas1 = (xwas == 0 || xwas == Now); + + Swap(spr->Cave, xspr->Cave); + Swap(spr->X, xspr->X); + Swap(spr->Y, xspr->Y); + Swap(spr->Z, xspr->Z); + if (spr->Flags.Kept) { + int n = FindPocket(spr); + if (n >= 0) + Pocket[n] = xspr; + xspr->Flags.Kept = true; + xspr->Flags.Port = false; + } + if (xwas1 != was1) { + if (was1) { + Hide1(spr); + ContractSprite(spr); + } else + ExpandSprite(spr); + if (xwas1) { + Hide1(xspr); + ContractSprite(xspr); + } else + ExpandSprite(xspr); + } + } +} + + +void SNCover(SPRITE *spr, int xref) { + SPRITE *xspr = Locate(xref); + if (spr && xspr) { + spr->Flags.Hide = true; + xspr->Z = spr->Z; + xspr->Cave = spr->Cave; + xspr->Goto(spr->X, spr->Y); + ExpandSprite(xspr); + if ((xspr->Flags.Shad = spr->Flags.Shad) == TRUE) { + VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr->Prev), xspr); + spr->Flags.Shad = false; + } + FeedSnail(xspr, NEAR); + } +} + + +void SNUncover(SPRITE *spr, SPRITE *xspr) { + if (spr && xspr) { + spr->Flags.Hide = false; + spr->Cave = xspr->Cave; + spr->Goto(xspr->X, xspr->Y); + if ((spr->Flags.Shad = xspr->Flags.Shad) == TRUE) { + VGA::ShowQ.Insert(VGA::ShowQ.Remove(xspr->Prev), spr); + xspr->Flags.Shad = false; + } + spr->Z = xspr->Z; + SNSend(xspr, -1); + if (spr->Time == 0) + ++spr->Time; + } +} + + +void SNSetX0(int cav, int x0) { + HeroXY[cav - 1].X = x0; +} + + +void SNSetY0(int cav, int y0) { + HeroXY[cav - 1].Y = y0; +} + + +void SNSetXY(SPRITE *spr, uint16 xy) { + if (spr) + spr->Goto(xy % SCR_WID, xy / SCR_WID); +} + + +void SNRelX(SPRITE *spr, int x) { + if (spr && Hero) + spr->Goto(Hero->X + x, spr->Y); +} + + +void SNRelY(SPRITE *spr, int y) { + if (spr && Hero) + spr->Goto(spr->X, Hero->Y + y); +} + + +void SNRelZ(SPRITE *spr, int z) { + if (spr && Hero) { + spr->Z = Hero->Z + z; + SNZTrim(spr); + } +} + + +void SNSetX(SPRITE *spr, int x) { + if (spr) + spr->Goto(x, spr->Y); +} + + +void SNSetY(SPRITE *spr, int y) { + if (spr) + spr->Goto(spr->X, y); +} + + +void SNSetZ(SPRITE *spr, int z) { + if (spr) { + spr->Z = z; + //SNPOST_(SNZTRIM, -1, 0, spr); + SNZTrim(spr); + } +} + + +void SNSlave(SPRITE *spr, int ref) { + SPRITE *slv = Locate(ref); + if (spr && slv) { + if (spr->Active()) { + SNSend(slv, spr->Cave); + slv->Flags.Slav = true; + slv->Z = spr->Z; + VGA::ShowQ.Insert(VGA::ShowQ.Remove(slv), spr->Next); + } + } +} + + +void SNTrans(SPRITE *spr, int trans) { + if (spr) + spr->Flags.Tran = (trans < 0) ? !spr->Flags.Tran : (trans != 0); +} + + +void SNPort(SPRITE *spr, int port) { + if (spr) + spr->Flags.Port = (port < 0) ? !spr->Flags.Port : (port != 0); +} + + +void SNKill(SPRITE *spr) { + if (spr) { + if (spr->Flags.Kept) { + int n = FindPocket(spr); + if (n >= 0) + Pocket[n] = NULL; + } + SPRITE *nx = spr->Next; + Hide1(spr); + VGA::ShowQ.Remove(spr); + MOUSE::ClrEvt(spr); + if (spr->Flags.Kill) + delete spr; + else { + spr->Cave = -1; + VGA::SpareQ.Append(spr); + } + if (nx) + if (nx->Flags.Slav) + SNKill(nx); + } +} + + +static void SNSound(SPRITE *spr, int wav, int cnt) { + if (SNDDrvInfo.DDEV) { + if (wav == -1) + Sound.Stop(); + else + Sound.Play(Fx[wav], (spr) ? ((spr->X + spr->W / 2) / (SCR_WID / 16)) : 8, cnt); + } +} + + +void SNKeep(SPRITE *spr, int stp) { + SelectPocket(-1); + if (spr && ! spr->Flags.Kept && Pocket[PocPtr] == NULL) { + SNSound(spr, 3, 1); + Pocket[PocPtr] = spr; + spr->Cave = 0; + spr->Flags.Kept = true; + spr->Goto(POCKET_X + POCKET_DX * PocPtr + POCKET_DX / 2 - spr->W / 2, + POCKET_Y + POCKET_DY / 2 - spr->H / 2); + if (stp >= 0) + spr->Step(stp); + } + SelectPocket(-1); +} + + +void SNGive(SPRITE *spr, int stp) { + if (spr) { + int p = FindPocket(spr); + if (p >= 0) { + Pocket[p] = NULL; + spr->Cave = Now; + spr->Flags.Kept = false; + if (stp >= 0) + spr->Step(stp); + } + } + SelectPocket(-1); +} + + +static void SNBackPt(SPRITE *spr, int stp) { + if (spr) { + if (stp >= 0) + spr->Step(stp); + spr->BackShow(true); + } +} + + +static void SNLevel(SPRITE *spr, int lev) { +#ifdef DEMO + static int maxcav[] = { CAVE_MAX }; +#else + static int maxcav[] = { 1, 8, 16, 23, 24 }; +#endif + while (Lev < lev) { + SPRITE *spr; + ++Lev; + spr = VGA::SpareQ.Locate(100 + Lev); + if (spr) { + spr->BackShow(true); + spr->Cave = 0; + } + } + MaxCave = maxcav[Lev]; + if (spr) + spr->Flags.Hide = false; +} + + +static void SNFlag(int fn, bool v) { + Flag[fn] = v; +} + + +static void SNSetRef(SPRITE *spr, int nr) { + if (spr) + spr->Ref = nr; +} + + +void SNFlash(bool on) { + if (on) { + DAC *pal = farnew(DAC, PAL_CNT); + if (pal) { + memcpy(pal, SysPal, PAL_SIZ); + for (int i = 0; i < PAL_CNT; i ++) { + register int c; + c = pal[i].R << 1; + pal[i].R = (c < 64) ? c : 63; + c = pal[i].G << 1; + pal[i].G = (c < 64) ? c : 63; + c = pal[i].B << 1; + pal[i].B = (c < 64) ? c : 63; + } + VGA::SetColors(pal, 64); + } + } else + VGA::SetColors(SysPal, 64); + Dark = false; +} + + +static void SNLight(bool in) { + if (in) + VGA::Sunrise(SysPal); + else + VGA::Sunset(); + Dark = ! in; +} + + +static void SNBarrier(int cav, int bar, bool horz) { + ((uint8 *)(Barriers + ((cav > 0) ? cav : Now)))[horz] = bar; +} + + +static void SNWalk(SPRITE *spr, int x, int y) { + if (Hero) { + if (spr && y < 0) + Hero->FindWay(spr); + else + Hero->FindWay(XZ(x, y)); + } +} + + +static void SNReach(SPRITE *spr, int mode) { + if (Hero) + Hero->Reach(spr, mode); +} + + +static void SNMouse(bool on) { + if (on) + Mouse.On(); + else + Mouse.Off(); +} + + +void SNAIL::RunCom(void) { + static int count = 1; + extern void SwitchCave(int); + if (! Busy) { + Busy = true; + uint8 tmphea = Head; + while (Tail != tmphea) { + COM *snc = &SNList[Tail]; + + if (! Turbo) { // only for the slower one + if (Pause) + break; + else { + if (TextDelay) { + KillText(); + TextDelay = false; + } + } + if (Talk && snc->Com != SNPAUSE) + break; + } + + SPRITE *sprel = ((snc->Ref >= 0) ? Locate(snc->Ref) : ((SPRITE *) snc->Ptr)); + switch (snc->Com) { + case SNLABEL : + break; + case SNPAUSE : + HEART::SetXTimer(&Pause, snc->Val); + if (Talk) + TextDelay = true; + break; + case SNWAIT : + if (sprel) { + if (sprel->SeqTest(snc->Val) && + (snc->Val >= 0 || sprel != Hero || Hero->TracePtr < 0)) { + HEART::SetXTimer(&Pause, sprel->Time); + } else + goto xit; + } + break; + case SNLEVEL : + SNLevel(sprel, snc->Val); + break; + case SNHIDE : + SNHide(sprel, snc->Val); + break; + case SNSAY : + if (sprel && TalkEnable) { + if (sprel == Hero && sprel->SeqTest(-1)) + sprel->Step(HTALK); + Say(Text[snc->Val], sprel); + SYSTEM::FunDel = HEROFUN0; + } + break; + case SNINF : + if (TalkEnable) { + Inf(Text[snc->Val]); + SYSTEM::FunDel = HEROFUN0; + } + break; + case SNTIME : + if (sprel && TalkEnable) { + if (sprel == Hero && sprel->SeqTest(-1)) + sprel->Step(HTALK); + SayTime(sprel); + } + break; + case SNCAVE : + SwitchCave(snc->Val); + break; + case SNKILL : + SNKill(sprel); + break; + case SNSEQ : + SNSeq(sprel, snc->Val); + break; + case SNRSEQ : + SNRSeq(sprel, snc->Val); + break; + case SNSEND : + SNSend(sprel, snc->Val); + break; + case SNSWAP : + SNSwap(sprel, snc->Val); + break; + case SNCOVER : + SNCover(sprel, snc->Val); + break; + case SNUNCOVER : + SNUncover(sprel, (snc->Val >= 0) ? Locate(snc->Val) : ((SPRITE *) snc->Ptr)); + break; + case SNKEEP : + SNKeep(sprel, snc->Val); + break; + case SNGIVE : + SNGive(sprel, snc->Val); + break; + case SNGAME : + SNGame(sprel, snc->Val); + break; + case SNSETX0 : + SNSetX0(snc->Ref, snc->Val); + break; + case SNSETY0 : + SNSetY0(snc->Ref, snc->Val); + break; + case SNSETXY : + SNSetXY(sprel, snc->Val); + break; + case SNRELX : + SNRelX(sprel, snc->Val); + break; + case SNRELY : + SNRelY(sprel, snc->Val); + break; + case SNRELZ : + SNRelZ(sprel, snc->Val); + break; + case SNSETX : + SNSetX(sprel, snc->Val); + break; + case SNSETY : + SNSetY(sprel, snc->Val); + break; + case SNSETZ : + SNSetZ(sprel, snc->Val); + break; + case SNSLAVE : + SNSlave(sprel, snc->Val); + break; + case SNTRANS : + SNTrans(sprel, snc->Val); + break; + case SNPORT : + SNPort(sprel, snc->Val); + break; + case SNNEXT : + break; + case SNIF : + break; + case SNTALK : + break; + case SNMOUSE : + SNMouse(snc->Val != 0); + break; + case SNNNEXT : + SNNNext(sprel, snc->Val); + break; + case SNTNEXT : + SNTNext(sprel, snc->Val); + break; + case SNRNNEXT : + SNRNNext(sprel, snc->Val); + break; + case SNRTNEXT : + SNRTNext(sprel, snc->Val); + break; + case SNRMNEAR : + SNRmNear(sprel); + break; + case SNRMTAKE : + SNRmTake(sprel); + break; + case SNFLAG : + SNFlag(snc->Ref & 3, snc->Val != 0); + break; + case SNSETREF : + SNSetRef(sprel, snc->Val); + break; + case SNBACKPT : + SNBackPt(sprel, snc->Val); + break; + case SNFLASH : + SNFlash(snc->Val != 0); + break; + case SNLIGHT : + SNLight(snc->Val != 0); + break; + case SNSETHB : + SNBarrier(snc->Ref, snc->Val, true); + break; + case SNSETVB : + SNBarrier(snc->Ref, snc->Val, false); + break; + case SNWALK : + SNWalk(sprel, snc->Ref, snc->Val); + break; + case SNREACH : + SNReach(sprel, snc->Val); + break; + case SNSOUND : + SNSound(sprel, snc->Val, count); + count = 1; + break; + case SNCOUNT : + count = snc->Val; + break; + case SNEXEC : + // TODO: Handle correctly the execution of function pointer coming from Message send SNPOST + // ((void(*)(int)) (snc->Ptr))(snc->Val); break; + warning("STUB: SNEXEC code"); + case SNSTEP : + sprel->Step(); + break; + case SNZTRIM : + SNZTrim(sprel); + break; + case SNGHOST : + SNGhost((BITMAP *) snc->Ptr); + break; + } + ++Tail; + if (!Turbo) + break; + } +xit: + Busy = false; + } +} + + +bool SNAIL::Idle(void) { + return (Head == Tail); } } // End of namespace CGE diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 88bb5f09dd0..f9b969a5545 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -25,96 +25,98 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __SNAIL__ -#define __SNAIL__ +#ifndef __SNAIL__ +#define __SNAIL__ -#include "cge/jbw.h" +#include "cge/jbw.h" namespace CGE { -#define POCKET_X 174 -#define POCKET_Y 176 -#define POCKET_DX 18 -#define POCKET_DY 22 -#define POCKET_NX 8 -#define POCKET_NY 1 +#define POCKET_X 174 +#define POCKET_Y 176 +#define POCKET_DX 18 +#define POCKET_DY 22 +#define POCKET_NX 8 +#define POCKET_NY 1 -#define POCKET_SX 8 -#define POCKET_SY 3 +#define POCKET_SX 8 +#define POCKET_SY 3 -#define SNINSERT(c,r,v,p) Snail.InsCom(c,r,v,p) -#define SNPOST(c,r,v,p) Snail.AddCom(c,r,v,p) -#define SNPOST_(c,r,v,p) Snail_.AddCom(c,r,v,p) +#define SNINSERT(c,r,v,p) Snail.InsCom(c,r,v,p) +#define SNPOST(c,r,v,p) Snail.AddCom(c,r,v,p) +#define SNPOST_(c,r,v,p) Snail_.AddCom(c,r,v,p) - -typedef struct { uint8 Horz, Vert; } BAR; +typedef struct { + uint8 Horz, Vert; +} BAR; - -struct SCB -{ - uint8 * Ptr; - uint16 Siz; - SCB * Nxt; +struct SCB { + uint8 *Ptr; + uint16 Siz; + SCB *Nxt; }; +enum SNCOM { + SNLABEL, SNPAUSE, SNWAIT, SNLEVEL, SNHIDE, + SNSAY, SNINF, SNTIME, SNCAVE, SNKILL, + SNRSEQ, SNSEQ, SNSEND, SNSWAP, SNKEEP, + SNGIVE, SNIF, SNGAME, SNSETX0, SNSETY0, + SNSLAVE, SNSETXY, SNRELX, SNRELY, SNRELZ, + SNSETX, SNSETY, SNSETZ, SNTRANS, SNPORT, + SNNEXT, SNNNEXT, SNTNEXT, SNRNNEXT, SNRTNEXT, + SNRMNEAR, SNRMTAKE, SNFLAG, SNSETREF, SNBACKPT, + SNFLASH, SNLIGHT, SNSETHB, SNSETVB, SNWALK, + SNREACH, SNCOVER, SNUNCOVER, SNCLEAR, SNTALK, + SNMOUSE, SNSOUND, SNCOUNT, SNEXEC, SNSTEP, + SNZTRIM, SNGHOST +}; -enum SNCOM { SNLABEL, SNPAUSE, SNWAIT, SNLEVEL, - SNHIDE, SNSAY, SNINF, SNTIME, - SNCAVE, SNKILL, SNRSEQ, - SNSEQ, SNSEND, SNSWAP, SNKEEP, SNGIVE, - SNIF, SNGAME, SNSETX0, SNSETY0, SNSLAVE, - SNSETXY, SNRELX, SNRELY, SNRELZ, - SNSETX, SNSETY, SNSETZ, SNTRANS, SNPORT, - SNNEXT, SNNNEXT, SNTNEXT, SNRNNEXT, SNRTNEXT, - SNRMNEAR, SNRMTAKE, SNFLAG, SNSETREF, - SNBACKPT, SNFLASH, SNLIGHT, - SNSETHB, SNSETVB, - SNWALK, SNREACH, SNCOVER, SNUNCOVER, - SNCLEAR, SNTALK, SNMOUSE, - SNSOUND, SNCOUNT, - SNEXEC, SNSTEP, SNZTRIM, - SNGHOST - }; +enum SNLIST { NEAR, TAKE }; -enum SNLIST { NEAR, TAKE }; - -class SNAIL -{ +class SNAIL { public: - struct COM { SNCOM Com; int Ref; int Val; void * Ptr; } * SNList; - uint8 Head, Tail; - bool Turbo, Busy, TextDelay; - uint16 Pause; - static const char * ComTxt[]; - bool TalkEnable; - SNAIL (bool turbo = false); - ~SNAIL (void); - void RunCom (void); - void AddCom (SNCOM com, int ref = 0, int val = 0, void * ptr = NULL); - void InsCom (SNCOM com, int ref = 0, int val = 0, void * ptr = NULL); - bool Idle (void); + struct COM { + SNCOM Com; + int Ref; + int Val; + void *Ptr; + } *SNList; + uint8 Head, Tail; + bool Turbo, Busy, TextDelay; + uint16 Pause; + static const char *ComTxt[]; + bool TalkEnable; + SNAIL(bool turbo = false); + ~SNAIL(void); + void RunCom(void); + void AddCom(SNCOM com, int ref = 0, int val = 0, void *ptr = NULL); + void InsCom(SNCOM com, int ref = 0, int val = 0, void *ptr = NULL); + bool Idle(void); }; -void SelectPocket (int n); -void PocFul (void); +void SelectPocket(int n); +void PocFul(void); -extern SCB Scb; -extern bool Flag[4]; -extern bool Game; -extern bool Dark; -extern SNAIL Snail; -extern SNAIL Snail_; -extern int Now; -extern int Lev; -extern int MaxCave; -extern int PocPtr; -extern BAR Barriers[]; -extern struct HXY { int X; int Y; } HeroXY[]; +extern SCB Scb; +extern bool Flag[4]; +extern bool Game; +extern bool Dark; +extern SNAIL Snail; +extern SNAIL Snail_; +extern int Now; +extern int Lev; +extern int MaxCave; +extern int PocPtr; +extern BAR Barriers[]; +extern struct HXY { + int X; + int Y; +} HeroXY[]; } // End of namespace CGE diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index fc6c1aa143a..3d1658e1e05 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -44,50 +44,45 @@ namespace CGE { // ****************************************************** // available devices -enum DEV_TYPE { DEV_AUTO = -1, // auto-detect mode - DEV_QUIET, // disable sound - DEV_SB, // sb/pro/16/awe32 - DEV_GUS, // gus/max - DEV_GM // general midi +enum DEV_TYPE { DEV_AUTO = -1, // auto-detect mode + DEV_QUIET, // disable sound + DEV_SB, // sb/pro/16/awe32 + DEV_GUS, // gus/max + DEV_GM // general midi }; -#define SERR_OK 0 // no error -#define SERR_INITFAIL 1 // couldn't initialize -#define SERR_BADDDEV 128 // bad device +#define SERR_OK 0 // no error +#define SERR_INITFAIL 1 // couldn't initialize +#define SERR_BADDDEV 128 // bad device // driver info -struct DRVINFO -{ - DEV_TYPE DDEV; // digi device - DEV_TYPE MDEV; // midi device - uint16 DBASE; // digi base port - uint16 DDMA; // digi dma no - uint16 DIRQ; // digi irq no - uint16 MBASE; // midi base port - union - { - struct - { - uint16 DR : 4; - uint16 DL : 4; - uint16 MR : 4; - uint16 ML : 4; - } VOL4; - struct - { - uint8 D; // digi volume - uint8 M; // midi volume - } VOL2; - }; +struct DRVINFO { + DEV_TYPE DDEV; // digi device + DEV_TYPE MDEV; // midi device + uint16 DBASE; // digi base port + uint16 DDMA; // digi dma no + uint16 DIRQ; // digi irq no + uint16 MBASE; // midi base port + union { + struct { + uint16 DR : 4; + uint16 DL : 4; + uint16 MR : 4; + uint16 ML : 4; + } VOL4; + struct { + uint8 D; // digi volume + uint8 M; // midi volume + } VOL2; + }; }; // sample info -struct SMPINFO -{ - uint8 * saddr; // address - uint16 slen; // length - uint16 span; // left/right pan (0-15) - int sflag; // flag +struct SMPINFO { + uint8 *saddr; // address + uint16 slen; // length + uint16 span; // left/right pan (0-15) + int sflag; // flag }; // ****************************************************** @@ -106,31 +101,30 @@ extern uint16 MIDIEndFlag; // * Driver Code * // ****************************************************** // Init Digi Device -EC void SNDInit (void); +EC void SNDInit(void); // Close Digi Device -EC void SNDDone (void); +EC void SNDDone(void); // Set Volume -EC void SNDSetVolume (void); +EC void SNDSetVolume(void); // Start Digi -EC void SNDDigiStart (SMPINFO *PSmpInfo); +EC void SNDDigiStart(SMPINFO *PSmpInfo); // Stop Digi -EC void SNDDigiStop (SMPINFO *PSmpInfo); +EC void SNDDigiStop(SMPINFO *PSmpInfo); // Start MIDI File -EC void SNDMIDIStart (uint8 *MIDFile); +EC void SNDMIDIStart(uint8 *MIDFile); // Stop MIDI File -EC void SNDMIDIStop (void); +EC void SNDMIDIStop(void); // Play MIDI File (to be called while interrupting) // WARNING: Uses ALL registers! -EC void SNDMIDIPlay (void); +EC void SNDMIDIPlay(void); } // End of namespace CGE - #endif diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index d40789beeef..397684849a0 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -25,292 +25,204 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/general.h" -#include "cge/startup.h" -#include "cge/sound.h" - -#include "cge/text.h" -#include "cge/cfile.h" -#include "cge/vol.h" +#include "cge/general.h" +#include "cge/startup.h" +#include "cge/sound.h" +#include "cge/text.h" +#include "cge/cfile.h" +#include "cge/vol.h" namespace CGE { - bool Music = true; - FX Fx = 16; // must precede SOUND!! - SOUND Sound; +bool Music = true; +FX Fx = 16; // must precede SOUND!! +SOUND Sound; - -SOUND::SOUND (void) -{ - if (STARTUP::SoundOk) Open(); +SOUND::SOUND(void) { + if (STARTUP::SoundOk) + Open(); } - - -SOUND::~SOUND (void) -{ - Close(); +SOUND::~SOUND(void) { + Close(); } - - - -void SOUND::Close (void) -{ - KillMIDI(); - SNDDone(); +void SOUND::Close(void) { + KillMIDI(); + SNDDone(); } - - - -void SOUND::Open (void) -{ - SNDInit(); - Play(Fx[30000], 8); +void SOUND::Open(void) { + SNDInit(); + Play(Fx[30000], 8); } - - -void SOUND::Play (DATACK * wav, int pan, int cnt) -{ - if (wav) - { - Stop(); - smpinf.saddr = (uint8 *) &*(wav->EAddr()); - smpinf.slen = (uint16)wav->Size(); - smpinf.span = pan; - smpinf.sflag = cnt; - SNDDigiStart(&smpinf); - } -} - - - - -void SOUND::Stop (void) -{ - SNDDigiStop(&smpinf); -} - - -//------------------------------------------------------------------------ - - - - - - - - -FX::FX (int size) -: Emm(0L), Current(NULL) -{ - Cache = new HAN[size]; - for (Size = 0; Size < size; Size ++) - { - Cache[Size].Ref = 0; - Cache[Size].Wav = NULL; - } -} - - - - -FX::~FX (void) -{ - Clear(); - delete[] Cache; -} - - - - - -void FX::Clear (void) -{ - HAN * p, * q; - for (p = Cache, q = p+Size; p < q; p ++) - { - if (p->Ref) - { - p->Ref = 0; - delete p->Wav; - p->Wav = NULL; +void SOUND::Play(DATACK *wav, int pan, int cnt) { + if (wav) { + Stop(); + smpinf.saddr = (uint8 *) &*(wav->EAddr()); + smpinf.slen = (uint16)wav->Size(); + smpinf.span = pan; + smpinf.sflag = cnt; + SNDDigiStart(&smpinf); } - } - Emm.Release(); - Current = NULL; } - - - -int FX::Find (int ref) -{ - HAN * p, * q; - int i = 0; - for (p = Cache, q = p+Size; p < q; p ++) - { - if (p->Ref == ref) break; - else ++ i; - } - return i; +void SOUND::Stop(void) { + SNDDigiStop(&smpinf); } - - - - - - - - - -void FX::Preload (int ref0) -{ - HAN * CacheLim = Cache + Size; - int ref; - - for (ref = ref0; ref < ref0+10; ref ++) - { - static char fname[] = "FX00000.WAV"; - wtom(ref, fname+2, 10, 5); - INI_FILE file = INI_FILE(fname); - DATACK * wav = LoadWave(&file, &Emm); - if (wav) - { - HAN * p = &Cache[Find(0)]; - if (p >= CacheLim) break; - p->Wav = wav; - p->Ref = ref; +FX::FX(int size) : Emm(0L), Current(NULL) { + Cache = new HAN[size]; + for (Size = 0; Size < size; Size ++) { + Cache[Size].Ref = 0; + Cache[Size].Wav = NULL; } - } } - - - -DATACK * FX::Load (int idx, int ref) -{ - static char fname[] = "FX00000.WAV"; - wtom(ref, fname+2, 10, 5); - - INI_FILE file = INI_FILE(fname); - DATACK * wav = LoadWave(&file, &Emm); - if (wav) - { - HAN * p = &Cache[idx]; - p->Wav = wav; - p->Ref = ref; - } - return wav; +FX::~FX(void) { + Clear(); + delete[] Cache; } - - -DATACK * FX::operator [] (int ref) -{ - int i; - if ((i = Find(ref)) < Size) Current = Cache[i].Wav; - else - { - if ((i = Find(0)) >= Size) - { - Clear(); - i = 0; - } - Current = Load(i, ref); - } - return Current; -} - - - - -//------------------------------------------------------------------------- - - -static uint8 * midi = NULL; - - - -void KillMIDI (void) -{ - SNDMIDIStop(); - if (midi) - { - delete[] midi; - midi = NULL; - } -} - - - - - -void LoadMIDI (int ref) -{ - static char fn[] = "00.MID"; - wtom(ref, fn, 10, 2); - if (INI_FILE::Exist(fn)) - { - KillMIDI(); - INI_FILE mid = fn; - if (mid.Error == 0) - { - uint16 siz = (uint16) mid.Size(); - midi = new uint8[siz]; - if (midi) - { - mid.Read(midi, siz); - if (mid.Error) KillMIDI(); - else - { - SNDMIDIStart(midi); +void FX::Clear(void) { + HAN *p, * q; + for (p = Cache, q = p + Size; p < q; p ++) { + if (p->Ref) { + p->Ref = 0; + delete p->Wav; + p->Wav = NULL; } - } } - } + Emm.Release(); + Current = NULL; } - - - - -EC void * Patch (int pat) -{ - void * p = NULL; - static char fn[] = "PATCH000.SND"; - - wtom(pat, fn+5, 10, 3); - INI_FILE snd = fn; - if (! snd.Error) - { - uint16 siz = (uint16) snd.Size(); - p = (uint8 *) malloc(siz); - if (p) - { - snd.Read(p, siz); - if (snd.Error) - { - free(p); - p = NULL; - } +int FX::Find(int ref) { + HAN *p, * q; + int i = 0; + for (p = Cache, q = p + Size; p < q; p ++) { + if (p->Ref == ref) + break; + else + ++i; } - } - return p; + return i; +} + + +void FX::Preload(int ref0) { + HAN *CacheLim = Cache + Size; + int ref; + + for (ref = ref0; ref < ref0 + 10; ref ++) { + static char fname[] = "FX00000.WAV"; + wtom(ref, fname + 2, 10, 5); + INI_FILE file = INI_FILE(fname); + DATACK *wav = LoadWave(&file, &Emm); + if (wav) { + HAN *p = &Cache[Find(0)]; + if (p >= CacheLim) + break; + p->Wav = wav; + p->Ref = ref; + } + } +} + + +DATACK *FX::Load(int idx, int ref) { + static char fname[] = "FX00000.WAV"; + wtom(ref, fname + 2, 10, 5); + + INI_FILE file = INI_FILE(fname); + DATACK *wav = LoadWave(&file, &Emm); + if (wav) { + HAN *p = &Cache[idx]; + p->Wav = wav; + p->Ref = ref; + } + return wav; +} + + +DATACK *FX::operator [](int ref) { + int i; + if ((i = Find(ref)) < Size) + Current = Cache[i].Wav; + else { + if ((i = Find(0)) >= Size) { + Clear(); + i = 0; + } + Current = Load(i, ref); + } + return Current; +} + + +static uint8 *midi = NULL; + + +void KillMIDI(void) { + SNDMIDIStop(); + if (midi) { + delete[] midi; + midi = NULL; + } +} + + +void LoadMIDI(int ref) { + static char fn[] = "00.MID"; + wtom(ref, fn, 10, 2); + if (INI_FILE::Exist(fn)) { + KillMIDI(); + INI_FILE mid = fn; + if (mid.Error == 0) { + uint16 siz = (uint16) mid.Size(); + midi = new uint8[siz]; + if (midi) { + mid.Read(midi, siz); + if (mid.Error) + KillMIDI(); + else + SNDMIDIStart(midi); + } + } + } +} + + +EC void *Patch(int pat) { + void *p = NULL; + static char fn[] = "PATCH000.SND"; + + wtom(pat, fn + 5, 10, 3); + INI_FILE snd = fn; + if (! snd.Error) { + uint16 siz = (uint16) snd.Size(); + p = (uint8 *) malloc(siz); + if (p) { + snd.Read(p, siz); + if (snd.Error) { + free(p); + p = NULL; + } + } + } + return p; } } // End of namespace CGE diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 79c9bf563d8..b617891268d 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -25,64 +25,56 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __SOUND__ -#define __SOUND__ +#ifndef __SOUND__ +#define __SOUND__ -#include "cge/wav.h" -#include "cge/snddrv.h" +#include "cge/wav.h" +#include "cge/snddrv.h" namespace CGE { -#define BAD_SND_TEXT 97 -#define BAD_MIDI_TEXT 98 +#define BAD_SND_TEXT 97 +#define BAD_MIDI_TEXT 98 - - -class SOUND -{ +class SOUND { public: - SMPINFO smpinf; - SOUND (void); - ~SOUND (void); - void Open (void); - void Close (void); - void Play (DATACK * wav, int pan, int cnt = 1); - void Stop (void); + SMPINFO smpinf; + SOUND(void); + ~SOUND(void); + void Open(void); + void Close(void); + void Play(DATACK *wav, int pan, int cnt = 1); + void Stop(void); }; - - - -class FX -{ - EMM Emm; - struct HAN { int Ref; DATACK * Wav; } * Cache; - int Size; - DATACK * Load (int idx, int ref); - int Find (int ref); +class FX { + EMM Emm; + struct HAN { + int Ref; + DATACK *Wav; + } *Cache; + int Size; + DATACK *Load(int idx, int ref); + int Find(int ref); public: - DATACK * Current; - FX (int size = 16); - ~FX (void); - void Clear (void); - void Preload (int ref0); - DATACK * operator[] (int ref); + DATACK *Current; + FX(int size = 16); + ~FX(void); + void Clear(void); + void Preload(int ref0); + DATACK *operator[](int ref); }; +extern bool Music; +extern SOUND Sound; +extern FX Fx; - - -extern bool Music; -extern SOUND Sound; -extern FX Fx; - - -void LoadMIDI (int ref); -void KillMIDI (void); +void LoadMIDI(int ref); +void KillMIDI(void); } // End of namespace CGE diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index c2badee266f..2bed51af971 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -25,173 +25,165 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/startup.h" -#include "cge/text.h" -#include "cge/sound.h" -#include "cge/ident.h" -#include "cge/cfile.h" -#include "cge/snddrv.h" -#include -#include -#include -//#include -#include +#include "cge/startup.h" +#include "cge/text.h" +#include "cge/sound.h" +#include "cge/ident.h" +#include "cge/cfile.h" +#include "cge/snddrv.h" +#include +#include +#include +#include -#ifdef DEBUG - #include +#ifdef DEBUG +#include #endif namespace CGE { -extern char Copr[]; +extern char Copr[]; -#define id (*(IDENT*)Copr) +#define id (*(IDENT*)Copr) - EMM MiniEmm = MINI_EMM_SIZE; +EMM MiniEmm = MINI_EMM_SIZE; -static STARTUP StartUp; +static STARTUP StartUp; - int STARTUP::Mode = 0; - int STARTUP::Core; - int STARTUP::SoundOk = 0; - uint16 STARTUP::Summa; +int STARTUP::Mode = 0; +int STARTUP::Core; +int STARTUP::SoundOk = 0; +uint16 STARTUP::Summa; - -void quit_now(int ref){ - error("%d\n", Text[ref]); +void quit_now(int ref) { + error("%d\n", Text[ref]); } - -bool STARTUP::get_parms(void) -{ -/* - int i = _argc; - while (i > 1) - { - static char *PrmTab[] = { "NEW", "MK0SVG", "QUIET", "SB", "GUS", "MIDI", - "P", "D", "I", "M" }; - int n = TakeEnum(PrmTab, strtok(_argv[--i], " =:(")); - uint16 p = xtow(strtok(NULL, " h,)")); - switch (n) - { - case 0 : if (Mode != 2) Mode = 1; break; - case 1 : Mode = 2; break; - case 2 : SNDDrvInfo.DDEV = DEV_QUIET; break; - case 3 : SNDDrvInfo.DDEV = DEV_SB; break; - case 4 : SNDDrvInfo.DDEV = DEV_GUS; break; - case 5 : SNDDrvInfo.MDEV = DEV_GM; break; - case 6 : SNDDrvInfo.DBASE = p; break; - case 7 : SNDDrvInfo.DDMA = p; break; - case 8 : SNDDrvInfo.DIRQ = p; break; - case 9 : SNDDrvInfo.MBASE = p; - SNDDrvInfo.MDEV = DEV_GM; break; - default: return false; - } - if (n >= 2) SoundOk = 2; - } - #ifdef DEMO - // protection disabled - Summa = 0; - #else - #ifdef EVA - { - union { dosdate_t d; uint32 n; } today; - _dos_getdate(&today.d); - id.disk += (id.disk < today.n); - } - #endif - #ifdef CD - Summa = 0; - #else - // disk signature checksum - Summa = ChkSum(Copr, sizeof(IDENT)); - #endif - #endif - if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; - */ - warning("STUB: STARTUP::get_parms"); - return true; +bool STARTUP::get_parms(void) { + /* + int i = _argc; + while (i > 1) + { + static char *PrmTab[] = { "NEW", "MK0SVG", "QUIET", "SB", "GUS", "MIDI", + "P", "D", "I", "M" }; + int n = TakeEnum(PrmTab, strtok(_argv[--i], " =:(")); + uint16 p = xtow(strtok(NULL, " h,)")); + switch (n) + { + case 0 : if (Mode != 2) Mode = 1; break; + case 1 : Mode = 2; break; + case 2 : SNDDrvInfo.DDEV = DEV_QUIET; break; + case 3 : SNDDrvInfo.DDEV = DEV_SB; break; + case 4 : SNDDrvInfo.DDEV = DEV_GUS; break; + case 5 : SNDDrvInfo.MDEV = DEV_GM; break; + case 6 : SNDDrvInfo.DBASE = p; break; + case 7 : SNDDrvInfo.DDMA = p; break; + case 8 : SNDDrvInfo.DIRQ = p; break; + case 9 : SNDDrvInfo.MBASE = p; + SNDDrvInfo.MDEV = DEV_GM; break; + default: return false; + } + if (n >= 2) SoundOk = 2; + } + #ifdef DEMO + // protection disabled + Summa = 0; + #else + #ifdef EVA + { + union { dosdate_t d; uint32 n; } today; + _dos_getdate(&today.d); + id.disk += (id.disk < today.n); + } + #endif + #ifdef CD + Summa = 0; + #else + // disk signature checksum + Summa = ChkSum(Copr, sizeof(IDENT)); + #endif + #endif + if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; + return true; + */ + warning("STUB: STARTUP::get_parms"); + return true; } +STARTUP::STARTUP(void) { + /* + uint32 m = farcoreleft() >> 10; + if (m < 0x7FFF) Core = (int) m; else Core = 0x7FFF; + if (! IsVga()) quit_now(NOT_VGA_TEXT); + if (Cpu() < _80286) quit_now(BAD_CHIP_TEXT); + if (100 * _osmajor + _osminor < 330) quit_now(BAD_DOS_TEXT); -STARTUP::STARTUP(void) -{ -/* - uint32 m = farcoreleft() >> 10; - if (m < 0x7FFF) Core = (int) m; else Core = 0x7FFF; - - if (! IsVga()) quit_now(NOT_VGA_TEXT); - if (Cpu() < _80286) quit_now(BAD_CHIP_TEXT); - if (100 * _osmajor + _osminor < 330) quit_now(BAD_DOS_TEXT); - - #ifndef DEBUG - if (Core < CORE_LOW) quit_now(NO_CORE_TEXT); - if (Core < CORE_HIG) - { - SNDDrvInfo.MDEV = DEV_QUIET; - Music = false; - } - #endif - if (! get_parms()) quit_now(BAD_ARG_TEXT); - //--- load sound configuration - const char * fn = UsrPath(ProgName(CFG_EXT)); - if (! STARTUP::SoundOk && CFILE::Exist(fn)) - { - CFILE cfg(fn, REA); - if (! cfg.Error) - { - cfg.Read(&SNDDrvInfo, sizeof(SNDDrvInfo)-sizeof(SNDDrvInfo.VOL2)); - if (! cfg.Error) STARTUP::SoundOk = 1; - } - } - */ + #ifndef DEBUG + if (Core < CORE_LOW) quit_now(NO_CORE_TEXT); + if (Core < CORE_HIG) + { + SNDDrvInfo.MDEV = DEV_QUIET; + Music = false; + } + #endif + if (! get_parms()) quit_now(BAD_ARG_TEXT); + //--- load sound configuration + const char * fn = UsrPath(ProgName(CFG_EXT)); + if (! STARTUP::SoundOk && CFILE::Exist(fn)) + { + CFILE cfg(fn, REA); + if (! cfg.Error) + { + cfg.Read(&SNDDrvInfo, sizeof(SNDDrvInfo)-sizeof(SNDDrvInfo.VOL2)); + if (! cfg.Error) STARTUP::SoundOk = 1; + } + } + */ warning("STUB: STARTUP::STARTUP"); } - - - - -const char *UsrPath (const char *nam) -{ - static char buf[MAXPATH] = ".\\", *p = buf+2; - #if defined(CD) - if (DriveCD(0)) - { - bool ok = false; - CFILE ini = Text[CDINI_FNAME]; - if (!ini.Error) - { - char *key = Text[GAME_ID]; - int i = strlen(key); - while (ini.Read(buf) && !ok) - { - int j = strlen(buf); - if (j) if (buf[--j] == '\n') buf[j] = '\0'; - if (memicmp(buf, key, i) == 0) ok = true; - } - if (ok) - { - strcpy(buf, buf+i); - p = buf + strlen(buf); - if (*(p-1) != '\\') *(p++) = '\\'; - strcpy(p, "NUL"); - if (_dos_open(buf, 0, &i) == 0) _dos_close(i); - else ok = false; - } +const char *UsrPath(const char *nam) { + static char buf[MAXPATH] = ".\\", *p = buf + 2; +#if defined(CD) + if (DriveCD(0)) { + bool ok = false; + CFILE ini = Text[CDINI_FNAME]; + if (!ini.Error) { + char *key = Text[GAME_ID]; + int i = strlen(key); + while (ini.Read(buf) && !ok) { + int j = strlen(buf); + if (j) + if (buf[--j] == '\n') + buf[j] = '\0'; + if (memicmp(buf, key, i) == 0) + ok = true; + } + if (ok) { + strcpy(buf, buf + i); + p = buf + strlen(buf); + if (*(p - 1) != '\\') + *(p++) = '\\'; + strcpy(p, "NUL"); + if (_dos_open(buf, 0, &i) == 0) + _dos_close(i); + else + ok = false; + } + } + if (!ok) + quit_now(BADCD_TEXT); } - if (!ok) quit_now(BADCD_TEXT); - } - #endif - strcpy(p, nam); - return buf; +#endif + strcpy(p, nam); + return buf; } } // End of namespace CGE diff --git a/engines/cge/startup.h b/engines/cge/startup.h index 2f1b5faa0bd..5bfa9876d67 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -25,57 +25,54 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __STARTUP__ -#define __STARTUP__ +#ifndef __STARTUP__ +#define __STARTUP__ -#include "cge/general.h" +#include "cge/general.h" namespace CGE { -#define GAME_ID 45 -#define CDINI_FNAME 46 +#define GAME_ID 45 +#define CDINI_FNAME 46 -#define NOT_VGA_TEXT 90 -#define BAD_CHIP_TEXT 91 -#define BAD_DOS_TEXT 92 -#define NO_CORE_TEXT 93 -#define BAD_MIPS_TEXT 94 -#define NO_MOUSE_TEXT 95 -#define BAD_ARG_TEXT 96 -#define BADCD_TEXT 97 +#define NOT_VGA_TEXT 90 +#define BAD_CHIP_TEXT 91 +#define BAD_DOS_TEXT 92 +#define NO_CORE_TEXT 93 +#define BAD_MIPS_TEXT 94 +#define NO_MOUSE_TEXT 95 +#define BAD_ARG_TEXT 96 +#define BADCD_TEXT 97 -#define CFG_EXT ".CFG" +#define CFG_EXT ".CFG" #if defined(DEMO) - #define MINI_EMM_SIZE 0x00004000L - #define CORE_HIG 400 +#define MINI_EMM_SIZE 0x00004000L +#define CORE_HIG 400 #else - #define MINI_EMM_SIZE 0x00010000L - #define CORE_HIG 450 +#define MINI_EMM_SIZE 0x00010000L +#define CORE_HIG 450 #endif -#define CORE_MID (CORE_HIG-20) -#define CORE_LOW (CORE_MID-20) +#define CORE_MID (CORE_HIG - 20) +#define CORE_LOW (CORE_MID - 20) -class STARTUP -{ - static bool get_parms (void); +class STARTUP { + static bool get_parms(void); public: - static int Mode; - static int Core; - static int SoundOk; - static uint16 Summa; - STARTUP (void); + static int Mode; + static int Core; + static int SoundOk; + static uint16 Summa; + STARTUP(void); }; +extern EMM MiniEmm; - -extern EMM MiniEmm; - -const char *UsrPath (const char *nam); +const char *UsrPath(const char *nam); } // End of namespace CGE diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 9fd32ab7d27..1dbcbad98da 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -25,384 +25,304 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/general.h" -#include "cge/talk.h" -#include "cge/vol.h" -#include "cge/game.h" -#include "cge/mouse.h" -#include -//#include -//#include +#include "cge/general.h" +#include "cge/talk.h" +#include "cge/vol.h" +#include "cge/game.h" +#include "cge/mouse.h" +#include namespace CGE { -#define WID_SIZ 256 -#define POS_SIZ 256 -#define MAP_SIZ (256*8) +#define WID_SIZ 256 +#define POS_SIZ 256 +#define MAP_SIZ (256*8) + +//uint8 FONT::Wid[WID_SIZ]; +//uint16 FONT::Pos[POS_SIZ]; +//uint8 FONT::Map[MAP_SIZ]; -//-------------------------------------------------------------------------- - - - -//uint8 FONT::Wid[WID_SIZ]; -//uint16 FONT::Pos[POS_SIZ]; -//uint8 FONT::Map[MAP_SIZ]; - - - - - - - -FONT::FONT (const char * name) -{ - Map = farnew(uint8, MAP_SIZ); - Pos = farnew(uint16, POS_SIZ); - Wid = farnew(uint8, WID_SIZ); - if (Map == NULL || Pos == NULL || Wid == NULL) - error("No core"); - MergeExt(Path, name, FONT_EXT); - Load(); +FONT::FONT(const char *name) { + Map = farnew(uint8, MAP_SIZ); + Pos = farnew(uint16, POS_SIZ); + Wid = farnew(uint8, WID_SIZ); + if ((Map == NULL) || (Pos == NULL) || (Wid == NULL)) + error("No core"); + MergeExt(Path, name, FONT_EXT); + Load(); } - - -FONT::~FONT (void) -{ - free(Map); - free(Pos); - free(Wid); +FONT::~FONT(void) { + free(Map); + free(Pos); + free(Wid); } - - -void FONT::Load (void) -{ - INI_FILE f(Path); - if (! f.Error) - { - f.Read(Wid, WID_SIZ); - if (! f.Error) - { - uint16 i, p = 0; - for (i = 0; i < POS_SIZ; i ++) - { - Pos[i] = p; - p += Wid[i]; - } - f.Read(Map, p); - } - } -} - - - - - -uint16 FONT::Width (const char * text) -{ - uint16 w = 0; - if (text) while (* text) w += Wid[*(text ++)]; - return w; -} - - - -/* -void FONT::Save (void) -{ - CFILE f((const char *) Path, WRI); - if (! f.Error) - { - f.Write(Wid, WID_SIZ); - if (! f.Error) - { - f.Write(Map, Pos[POS_SIZ-1] + Wid[WID_SIZ-1]); - } - } -} -*/ - - - - -//-------------------------------------------------------------------------- - - - -FONT TALK::Font(ProgName()); - - - -TALK::TALK (const char * tx, TBOX_STYLE mode) -: SPRITE(NULL), Mode(mode) -{ - TS[0] = TS[1] = NULL; - Flags.Syst = true; - Update(tx); -} - - - - - -TALK::TALK (void) -: SPRITE(NULL), Mode(PURE) -{ - TS[0] = TS[1] = NULL; - Flags.Syst = true; -} - - - - - -/* -TALK::~TALK (void) -{ - uint16 i; - for (i = 0; i < ShpCnt; i ++) - { - if (FP_SEG(ShpList[i]) != _DS) // small model: always false - { - delete ShpList[i]; - ShpList[i] = NULL; - } - } -} -*/ - - - -void TALK::Update (const char * tx) -{ - uint16 vmarg = (Mode) ? TEXT_VM : 0; - uint16 hmarg = (Mode) ? TEXT_HM : 0; - uint16 mw = 0, mh, ln = vmarg; - const char * p; - uint8 * m; - - if (! TS[0]) - { - uint16 k = 2 * hmarg; - mh = 2 * vmarg + FONT_HIG; - for (p = tx; *p; p ++) - { - if (*p == '|' || *p == '\n') - { - mh += FONT_HIG + TEXT_LS; - if (k > mw) mw = k; - k = 2 * hmarg; - } - else k += Font.Wid[*p]; - } - if (k > mw) mw = k; - TS[0] = Box(mw, mh); - } - - m = TS[0]->M + ln * mw + hmarg; - - while (* tx) - { - if (*tx == '|' || *tx == '\n') - m = TS[0]->M + (ln += FONT_HIG + TEXT_LS) * mw + hmarg; - else - { - int cw = Font.Wid[*tx], i; - uint8 * f = Font.Map + Font.Pos[*tx]; - for (i = 0; i < cw; i ++) - { - uint8 * p = m; - uint16 n; - register uint16 b = * (f ++); - for (n = 0; n < FONT_HIG; n ++) - { - if (b & 1) * p = TEXT_FG; - b >>= 1; - p += mw; +void FONT::Load(void) { + INI_FILE f(Path); + if (! f.Error) { + f.Read(Wid, WID_SIZ); + if (! f.Error) { + uint16 i, p = 0; + for (i = 0; i < POS_SIZ; i ++) { + Pos[i] = p; + p += Wid[i]; + } + f.Read(Map, p); } - ++ m; - } } - ++ tx; - } - TS[0]->Code(); - SetShapeList(TS); +} + + +uint16 FONT::Width(const char *text) { + uint16 w = 0; + if (text) + while (* text) + w += Wid[*(text ++)]; + return w; +} + + +/* +void FONT::Save(void) { + CFILE f((const char *) Path, WRI); + if (! f.Error) { + f.Write(Wid, WID_SIZ); + if (! f.Error) + f.Write(Map, Pos[POS_SIZ-1] + Wid[WID_SIZ-1]); + } +} +*/ + + +FONT TALK::Font(ProgName()); + + +TALK::TALK(const char *tx, TBOX_STYLE mode) + : SPRITE(NULL), Mode(mode) { + TS[0] = TS[1] = NULL; + Flags.Syst = true; + Update(tx); +} + + +TALK::TALK(void) + : SPRITE(NULL), Mode(PURE) { + TS[0] = TS[1] = NULL; + Flags.Syst = true; +} + + +/* +TALK::~TALK (void) { + for (uint16 i = 0; i < ShpCnt; i ++) { + if (FP_SEG(ShpList[i]) != _DS) { // small model: always false + delete ShpList[i]; + ShpList[i] = NULL; + } + } +} +*/ + + +void TALK::Update(const char *tx) { + uint16 vmarg = (Mode) ? TEXT_VM : 0; + uint16 hmarg = (Mode) ? TEXT_HM : 0; + uint16 mw = 0, mh, ln = vmarg; + const char *p; + uint8 *m; + + if (!TS[0]) { + uint16 k = 2 * hmarg; + mh = 2 * vmarg + FONT_HIG; + for (p = tx; *p; p ++) { + if (*p == '|' || *p == '\n') { + mh += FONT_HIG + TEXT_LS; + if (k > mw) + mw = k; + k = 2 * hmarg; + } else + k += Font.Wid[*p]; + } + if (k > mw) + mw = k; + TS[0] = Box(mw, mh); + } + + m = TS[0]->M + ln * mw + hmarg; + + while (* tx) { + if (*tx == '|' || *tx == '\n') + m = TS[0]->M + (ln += FONT_HIG + TEXT_LS) * mw + hmarg; + else { + int cw = Font.Wid[*tx], i; + uint8 *f = Font.Map + Font.Pos[*tx]; + for (i = 0; i < cw; i++) { + uint8 *p = m; + uint16 n; + register uint16 b = *(f++); + for (n = 0; n < FONT_HIG; n++) { + if (b & 1) + *p = TEXT_FG; + b >>= 1; + p += mw; + } + ++m; + } + } + ++tx; + } + TS[0]->Code(); + SetShapeList(TS); } -BITMAP * TALK::Box (uint16 w, uint16 h) -{ - uint8 * b, * p, * q; - uint16 n, r = (Mode == ROUND) ? TEXT_RD : 0; - int i; +BITMAP *TALK::Box(uint16 w, uint16 h) { + uint8 *b, * p, * q; + uint16 n, r = (Mode == ROUND) ? TEXT_RD : 0; - if (w < 8) w = 8; - if (h < 8) h = 8; - b = farnew(uint8, n = w * h); - if (! b) - error("No core"); - memset(b, TEXT_BG, n); + if (w < 8) + w = 8; + if (h < 8) + h = 8; + b = farnew(uint8, n = w * h); + if (! b) + error("No core"); + memset(b, TEXT_BG, n); - if (Mode) - { - p = b; q = b + n - w; - memset(p, LGRAY, w); - memset(q, DGRAY, w); - while (p < q) - { - p += w; - * (p-1) = DGRAY; - * p = LGRAY; + if (Mode) { + p = b; + q = b + n - w; + memset(p, LGRAY, w); + memset(q, DGRAY, w); + while (p < q) { + p += w; + *(p - 1) = DGRAY; + *p = LGRAY; + } + p = b; + for (int i = 0; i < r; i ++) { + int j; + for (j = 0; j < r - i; j ++) { + p[j] = TRANS; + p[w - j - 1] = TRANS; + q[j] = TRANS; + q[w - j - 1] = TRANS; + } + p[j] = LGRAY; + p[w - j - 1] = DGRAY; + q[j] = LGRAY; + q[w - j - 1] = DGRAY; + p += w; + q -= w; + } } - p = b; - for (i = 0; i < r; i ++) - { - int j; - for (j = 0; j < r-i; j ++) - { - p[ j ] = TRANS; - p[w-j-1] = TRANS; - q[ j ] = TRANS; - q[w-j-1] = TRANS; - } - p[ j ] = LGRAY; - p[w-j-1] = DGRAY; - q[ j ] = LGRAY; - q[w-j-1] = DGRAY; - p += w; - q -= w; - } - } - return new BITMAP(w, h, b); + return new BITMAP(w, h, b); } - - - -void TALK::PutLine (int line, const char * text) +void TALK::PutLine(int line, const char *text) { // Note: (TS[0].W % 4) have to be 0 -{ - uint16 w = TS[0]->W, h = TS[0]->H; - uint8 * v = TS[0]->V, * p; - uint16 dsiz = w >> 2; // data size (1 plane line size) - uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap - uint16 psiz = h * lsiz; // - last gap, but + plane trailer - uint16 size = 4 * psiz; // whole map size - uint16 rsiz = FONT_HIG * lsiz; // length of whole text row map + uint16 w = TS[0]->W, h = TS[0]->H; + uint8 *v = TS[0]->V, * p; + uint16 dsiz = w >> 2; // data size (1 plane line size) + uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap + uint16 psiz = h * lsiz; // - last gap, but + plane trailer + uint16 size = 4 * psiz; // whole map size + uint16 rsiz = FONT_HIG * lsiz; // length of whole text row map - // set desired line pointer - v += (TEXT_VM + (FONT_HIG + TEXT_LS) * line) * lsiz; + // set desired line pointer + v += (TEXT_VM + (FONT_HIG + TEXT_LS) * line) * lsiz; - // clear whole rectangle - p = v; // assume blanked line above text - memcpy(p, p-lsiz, rsiz); p += psiz; // tricky replicate lines for plane 0 - memcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 1 - memcpy(p, p-lsiz, rsiz); p += psiz; // same for plane 2 - memcpy(p, p-lsiz, rsiz); // same for plane 3 + // clear whole rectangle + p = v; // assume blanked line above text + memcpy(p, p - lsiz, rsiz); + p += psiz; // tricky replicate lines for plane 0 + memcpy(p, p - lsiz, rsiz); + p += psiz; // same for plane 1 + memcpy(p, p - lsiz, rsiz); + p += psiz; // same for plane 2 + memcpy(p, p - lsiz, rsiz); // same for plane 3 - // paint text line - if (text) - { - uint8 * q; - p = v + 2 + TEXT_HM/4 + (TEXT_HM%4)*psiz; - q = v + size; + // paint text line + if (text) { + uint8 *q; + p = v + 2 + TEXT_HM / 4 + (TEXT_HM % 4) * psiz; + q = v + size; - while (* text) - { - uint16 cw = Font.Wid[*text], i; - uint8 * fp = Font.Map + Font.Pos[*text]; + while (* text) { + uint16 cw = Font.Wid[*text], i; + uint8 *fp = Font.Map + Font.Pos[*text]; - for (i = 0; i < cw; i ++) - { - register uint16 b = fp[i]; - uint16 n; - for (n = 0; n < FONT_HIG; n ++) - { - if (b & 1) *p = TEXT_FG; - b >>= 1; - p += lsiz; + for (i = 0; i < cw; i ++) { + register uint16 b = fp[i]; + uint16 n; + for (n = 0; n < FONT_HIG; n ++) { + if (b & 1) + *p = TEXT_FG; + b >>= 1; + p += lsiz; + } + p = p - rsiz + psiz; + if (p >= q) + p = p - size + 1; + } + ++text; } - p = p - rsiz + psiz; - if (p >= q) p = p - size + 1; - } - ++ text; } - } } - - - - -//-------------------------------------------------------------------------- - - - - -INFO_LINE::INFO_LINE (uint16 w) -: OldTxt(NULL) -{ - TS[0] = new BITMAP(w, FONT_HIG, TEXT_BG); - SetShapeList(TS); +INFO_LINE::INFO_LINE(uint16 w) : OldTxt(NULL) { + TS[0] = new BITMAP(w, FONT_HIG, TEXT_BG); + SetShapeList(TS); } +void INFO_LINE::Update(const char *tx) { + if (tx != OldTxt) { + uint16 w = TS[0]->W, h = TS[0]->H; + uint8 *v = (uint8 *) TS[0]->V; + uint16 dsiz = w >> 2; // data size (1 plane line size) + uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap + uint16 psiz = h * lsiz; // - last gape, but + plane trailer + uint16 size = 4 * psiz; // whole map size + // claer whole rectangle + memset(v + 2, TEXT_BG, dsiz); // data bytes + memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines + * (uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 + memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes + // paint text line + if (tx) { + uint8 *p = v + 2, * q = p + size; + while (*tx) { + uint16 cw = Font.Wid[*tx]; + uint8 *fp = Font.Map + Font.Pos[*tx]; -void INFO_LINE::Update (const char * tx) -{ - if (tx != OldTxt) - { - uint16 w = TS[0]->W, h = TS[0]->H; - uint8 * v = (uint8 *) TS[0]->V; - uint16 dsiz = w >> 2; // data size (1 plane line size) - uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap - uint16 psiz = h * lsiz; // - last gape, but + plane trailer - uint16 size = 4 * psiz; // whole map size - - // claer whole rectangle - memset(v+2, TEXT_BG, dsiz); // data bytes - memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines - * (uint16 *) (v + psiz - 2) = EOI; // plane trailer uint16 - memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes - - // paint text line - if (tx) - { - uint8 * p = v + 2, * q = p + size; - - while (* tx) - { - uint16 cw = Font.Wid[*tx], i; - uint8 * fp = Font.Map + Font.Pos[*tx]; - - for (i = 0; i < cw; i ++) - { - register uint16 b = fp[i]; - uint16 n; - for (n = 0; n < FONT_HIG; n ++) - { - if (b & 1) *p = TEXT_FG; - b >>= 1; - p += lsiz; - } - if (p >= q) p = p - size + 1; + for (uint16 i = 0; i < cw; i++) { + register uint16 b = fp[i]; + for (uint16 n = 0; n < FONT_HIG; n ++) { + if (b & 1) + *p = TEXT_FG; + b >>= 1; + p += lsiz; + } + if (p >= q) + p = p - size + 1; + } + ++tx; + } } - ++ tx; - } + OldTxt = tx; } - OldTxt = tx; - } } } // End of namespace CGE diff --git a/engines/cge/talk.h b/engines/cge/talk.h index aab6834c284..568fd829641 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -25,86 +25,72 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __TALK__ -#define __TALK__ +#ifndef __TALK__ +#define __TALK__ -#include "cge/vga13h.h" -#include "cge/general.h" -#include "cge/jbw.h" -//#include +#include "cge/vga13h.h" +#include "cge/general.h" +#include "cge/jbw.h" namespace CGE { -#define TEXT_FG DARK // foreground color -#define TEXT_BG GRAY // background color -#define TEXT_HM (6&~1) // EVEN horizontal margins! -#define TEXT_VM 5 // vertical margins -#define TEXT_LS 2 // line spacing -#define TEXT_RD 3 // rounded corners +#define TEXT_FG DARK // foreground color +#define TEXT_BG GRAY // background color +#define TEXT_HM (6&~1) // EVEN horizontal margins! +#define TEXT_VM 5 // vertical margins +#define TEXT_LS 2 // line spacing +#define TEXT_RD 3 // rounded corners -#define FONT_HIG 8 -#define FONT_EXT ".CFT" +#define FONT_HIG 8 +#define FONT_EXT ".CFT" #define MAXPATH 128 -class FONT -{ - char Path[MAXPATH]; - void Load (void); +class FONT { + char Path[MAXPATH]; + void Load(void); public: // static uint8 Wid[256]; // static uint16 Pos[256]; // static uint8 Map[256*8]; - uint8 * Wid; - uint16 * Pos; - uint8 * Map; - FONT (const char * name); - ~FONT (void); - uint16 Width (const char * text); - void Save (void); + uint8 *Wid; + uint16 *Pos; + uint8 *Map; + FONT(const char *name); + ~FONT(void); + uint16 Width(const char *text); + void Save(void); }; +enum TBOX_STYLE { PURE, RECT, ROUND }; - -enum TBOX_STYLE { PURE, RECT, ROUND }; - - - -class TALK : public SPRITE -{ +class TALK : public SPRITE { protected: - TBOX_STYLE Mode; - BITMAP * TS[2]; - BITMAP * Box(uint16 w, uint16 h); + TBOX_STYLE Mode; + BITMAP *TS[2]; + BITMAP *Box(uint16 w, uint16 h); public: - static FONT Font; - TALK (const char * tx, TBOX_STYLE mode = PURE); - TALK (void); - //~TALK (void); - virtual void Update (const char * tx); - virtual void Update (void) {} - void PutLine (int line, const char * text); + static FONT Font; + TALK(const char *tx, TBOX_STYLE mode = PURE); + TALK(void); + //~TALK (void); + virtual void Update(const char *tx); + virtual void Update(void) {} + void PutLine(int line, const char *text); }; - - - - - -class INFO_LINE : public TALK -{ - const char * OldTxt; +class INFO_LINE : public TALK { + const char *OldTxt; public: - INFO_LINE (uint16 wid); - void Update (const char * tx); + INFO_LINE(uint16 wid); + void Update(const char *tx); }; - } // End of namespace CGE #endif diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 5b79131a260..71f4f156d53 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -25,292 +25,235 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/general.h" -#include "cge/text.h" -#include "cge/talk.h" -#include "cge/vol.h" -#include "cge/bitmaps.h" -#include "cge/game.h" -#include "cge/snail.h" -#include -#include -#include -#include +#include "cge/general.h" +#include "cge/text.h" +#include "cge/talk.h" +#include "cge/vol.h" +#include "cge/bitmaps.h" +#include "cge/game.h" +#include "cge/snail.h" +#include +#include +#include +#include namespace CGE { - TEXT Text = ProgName(); - TALK * Talk = NULL; +TEXT Text = ProgName(); +TALK *Talk = NULL; +TEXT::TEXT(const char *fname, int size) { + Cache = new HAN[size]; + MergeExt(FileName, fname, SAY_EXT); + if (!INI_FILE::Exist(FileName)) + error("No talk\n"); - - - -TEXT::TEXT (const char * fname, int size) -{ - Cache = new HAN[size]; - MergeExt(FileName, fname, SAY_EXT); - if (! INI_FILE::Exist(FileName)) { - error("No talk\n"); - } - - for (Size = 0; Size < size; Size ++) - { - Cache[Size].Ref = 0; - Cache[Size].Txt = NULL; - } -} - - - - -TEXT::~TEXT (void) -{ - Clear(); - delete[] Cache; -} - - - - - -void TEXT::Clear (int from, int upto) -{ - HAN * p, * q; - for (p = Cache, q = p+Size; p < q; p ++) - { - if (p->Ref && p->Ref >= from && p->Ref < upto) - { - p->Ref = 0; - delete p->Txt; - p->Txt = NULL; + for (Size = 0; Size < size; Size ++) { + Cache[Size].Ref = 0; + Cache[Size].Txt = NULL; } - } } - - - -int TEXT::Find (int ref) -{ - HAN * p, * q; - int i = 0; - for (p = Cache, q = p+Size; p < q; p ++) - { - if (p->Ref == ref) break; - else ++ i; - } - return i; +TEXT::~TEXT(void) { + Clear(); + delete[] Cache; } - - - - - - - - - -void TEXT::Preload (int from, int upto) -{ - INI_FILE tf = FileName; - if (! tf.Error) - { - HAN * CacheLim = Cache + Size; - char line[LINE_MAX+1]; - int n; - - while ((n = tf.Read((uint8*)line)) != 0) - { - char * s; - int ref; - - if (line[n-1] == '\n') line[-- n] = '\0'; - if ((s = strtok(line, " =,;/\t\n")) == NULL) continue; - if (! IsDigit(*s)) continue; - ref = atoi(s); - if (ref && ref >= from && ref < upto) - { - HAN * p; - - p = &Cache[Find(ref)]; - if (p < CacheLim) - { - delete[] p->Txt; - p->Txt = NULL; +void TEXT::Clear(int from, int upto) { + HAN *p, * q; + for (p = Cache, q = p + Size; p < q; p ++) { + if (p->Ref && p->Ref >= from && p->Ref < upto) { + p->Ref = 0; + delete p->Txt; + p->Txt = NULL; } - else p = &Cache[Find(0)]; - if (p >= CacheLim) break; - s += strlen(s); - if (s < line + n) ++ s; - if ((p->Txt = new char[strlen(s) + 1]) == NULL) break; - p->Ref = ref; - strcpy(p->Txt, s); - } } - } } - - - -char * TEXT::Load (int idx, int ref) -{ - INI_FILE tf = FileName; - if (! tf.Error) - { - HAN * p = &Cache[idx]; - char line[LINE_MAX+1]; - int n; - - while ((n = tf.Read((uint8*)line)) != 0) - { - char * s; - - if (line[n-1] == '\n') line[-- n] = '\0'; - if ((s = strtok(line, " =,;/\t\n")) == NULL) continue; - if (! IsDigit(*s)) continue; - - int r = atoi(s); - if (r < ref) continue; - if (r > ref) break; - // (r == ref) - s += strlen(s); - if (s < line + n) ++ s; - p->Ref = ref; - if ((p->Txt = new char[strlen(s) + 1]) == NULL) return NULL; - return strcpy(p->Txt, s); +int TEXT::Find(int ref) { + HAN *p, * q; + int i = 0; + for (p = Cache, q = p + Size; p < q; p ++) { + if (p->Ref == ref) + break; + else + ++i; } - } - return NULL; + return i; } +void TEXT::Preload(int from, int upto) { + INI_FILE tf = FileName; + if (! tf.Error) { + HAN *CacheLim = Cache + Size; + char line[LINE_MAX + 1]; + int n; + while ((n = tf.Read((uint8 *)line)) != 0) { + char *s; + int ref; -char * TEXT::operator [] (int ref) -{ - int i; - if ((i = Find(ref)) < Size) return Cache[i].Txt; + if (line[n - 1] == '\n') + line[-- n] = '\0'; + if ((s = strtok(line, " =,;/\t\n")) == NULL) + continue; + if (! IsDigit(*s)) + continue; + ref = atoi(s); + if (ref && ref >= from && ref < upto) { + HAN *p; - if ((i = Find(0)) >= Size) - { - Clear(SYSTXT_MAX); // clear non-system - if ((i = Find(0)) >= Size) - { - Clear(); // clear all - i = 0; + p = &Cache[Find(ref)]; + if (p < CacheLim) { + delete[] p->Txt; + p->Txt = NULL; + } else + p = &Cache[Find(0)]; + if (p >= CacheLim) + break; + s += strlen(s); + if (s < line + n) + ++s; + if ((p->Txt = new char[strlen(s) + 1]) == NULL) + break; + p->Ref = ref; + strcpy(p->Txt, s); + } + } } - } - return Load(i, ref); } +char *TEXT::Load(int idx, int ref) { + INI_FILE tf = FileName; + if (! tf.Error) { + HAN *p = &Cache[idx]; + char line[LINE_MAX + 1]; + int n; + while ((n = tf.Read((uint8 *)line)) != 0) { + char *s; + if (line[n - 1] == '\n') + line[-- n] = '\0'; + if ((s = strtok(line, " =,;/\t\n")) == NULL) + continue; + if (! IsDigit(*s)) + continue; - -void Say (const char * txt, SPRITE * spr) -{ - KillText(); - Talk = new TALK(txt, ROUND); - if (Talk) - { - bool east = spr->Flags.East; - int x = (east) ? (spr->X+spr->W-2) : (spr->X+2); - int y = spr->Y+2; - SPRITE * spike = new SPRITE(SP); - uint16 sw = spike->W; - - if (east) - { - if (x + sw + TEXT_RD + 5 >= SCR_WID) east = false; + int r = atoi(s); + if (r < ref) + continue; + if (r > ref) + break; + // (r == ref) + s += strlen(s); + if (s < line + n) + ++s; + p->Ref = ref; + if ((p->Txt = new char[strlen(s) + 1]) == NULL) + return NULL; + return strcpy(p->Txt, s); + } } - else - { - if (x <= 5 + TEXT_RD + sw) east = true; + return NULL; +} + + +char *TEXT::operator [](int ref) { + int i; + if ((i = Find(ref)) < Size) + return Cache[i].Txt; + + if ((i = Find(0)) >= Size) { + Clear(SYSTXT_MAX); // clear non-system + if ((i = Find(0)) >= Size) { + Clear(); // clear all + i = 0; + } } - x = (east) ? (spr->X+spr->W-2) : (spr->X+2-sw); - if (spr->Ref == 1) x += (east) ? -10 : 10; // Hero - - Talk->Flags.Kill = true; - Talk->Flags.BDel = true; - Talk->SetName(Text[SAY_NAME]); - Talk->Goto(x - (Talk->W - sw) / 2 - 3 + 6 * east, y - spike->H - Talk->H+1); - Talk->Z = 125; - Talk->Ref = SAY_REF; - - spike->Goto(x, Talk->Y + Talk->H - 1); - spike->Z = 126; - spike->Flags.Slav = true; - spike->Flags.Kill = true; - spike->SetName(Text[SAY_NAME]); - spike->Step(east); - spike->Ref = SAY_REF; - - VGA::ShowQ.Insert(Talk, VGA::ShowQ.Last()); - VGA::ShowQ.Insert(spike, VGA::ShowQ.Last()); - } + return Load(i, ref); } +void Say(const char *txt, SPRITE *spr) { + KillText(); + Talk = new TALK(txt, ROUND); + if (Talk) { + bool east = spr->Flags.East; + int x = (east) ? (spr->X + spr->W - 2) : (spr->X + 2); + int y = spr->Y + 2; + SPRITE *spike = new SPRITE(SP); + uint16 sw = spike->W; + if (east) { + if (x + sw + TEXT_RD + 5 >= SCR_WID) + east = false; + } else { + if (x <= 5 + TEXT_RD + sw) + east = true; + } + x = (east) ? (spr->X + spr->W - 2) : (spr->X + 2 - sw); + if (spr->Ref == 1) + x += (east) ? -10 : 10; // Hero + Talk->Flags.Kill = true; + Talk->Flags.BDel = true; + Talk->SetName(Text[SAY_NAME]); + Talk->Goto(x - (Talk->W - sw) / 2 - 3 + 6 * east, y - spike->H - Talk->H + 1); + Talk->Z = 125; + Talk->Ref = SAY_REF; + spike->Goto(x, Talk->Y + Talk->H - 1); + spike->Z = 126; + spike->Flags.Slav = true; + spike->Flags.Kill = true; + spike->SetName(Text[SAY_NAME]); + spike->Step(east); + spike->Ref = SAY_REF; + VGA::ShowQ.Insert(Talk, VGA::ShowQ.Last()); + VGA::ShowQ.Insert(spike, VGA::ShowQ.Last()); + } +} -void Inf (const char * txt) -{ - KillText(); - Talk = new TALK(txt, RECT); - if (Talk) - { - Talk->Flags.Kill = true; - Talk->Flags.BDel = true; - Talk->SetName(Text[INF_NAME]); - Talk->Center(); - Talk->Goto(Talk->X, Talk->Y - 20); - Talk->Z = 126; - Talk->Ref = INF_REF; - VGA::ShowQ.Insert(Talk, VGA::ShowQ.Last()); - } +void Inf(const char *txt) { + KillText(); + Talk = new TALK(txt, RECT); + if (Talk) { + Talk->Flags.Kill = true; + Talk->Flags.BDel = true; + Talk->SetName(Text[INF_NAME]); + Talk->Center(); + Talk->Goto(Talk->X, Talk->Y - 20); + Talk->Z = 126; + Talk->Ref = INF_REF; + VGA::ShowQ.Insert(Talk, VGA::ShowQ.Last()); + } } - - - - - -void SayTime (SPRITE * spr) -{ -/* - static char t[] = "00:00"; - struct time ti; - gettime(&ti); - wtom(ti.ti_hour, t+0, 10, 2); - wtom(ti.ti_min, t+3, 10, 2); - Say((*t == '0') ? (t+1) : t, spr); - */ - warning("STUB: SayTime"); +void SayTime(SPRITE *spr) { + /* + static char t[] = "00:00"; + struct time ti; + gettime(&ti); + wtom(ti.ti_hour, t+0, 10, 2); + wtom(ti.ti_min, t+3, 10, 2); + Say((*t == '0') ? (t+1) : t, spr); + */ + warning("STUB: SayTime"); } - - - - - -void KillText (void) -{ - if (Talk) - { - SNPOST_(SNKILL, -1, 0, Talk); - Talk = NULL; - } +void KillText(void) { + if (Talk) { + SNPOST_(SNKILL, -1, 0, Talk); + Talk = NULL; + } } } // End of namespace CGE diff --git a/engines/cge/text.h b/engines/cge/text.h index 222a3abf7d4..fe740ffacdd 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -25,61 +25,61 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __TEXT__ -#define __TEXT__ +#ifndef __TEXT__ +#define __TEXT__ -#include "cge/talk.h" -#include "cge/jbw.h" -//#include +#include "cge/talk.h" +#include "cge/jbw.h" namespace CGE { -#ifndef SYSTXT_MAX - #define SYSTXT_MAX 1000 +#ifndef SYSTXT_MAX +#define SYSTXT_MAX 1000 #endif -#define SAY_EXT ".SAY" +#define SAY_EXT ".SAY" -#define NOT_VGA_TEXT 90 -#define BAD_CHIP_TEXT 91 -#define BAD_DOS_TEXT 92 -#define NO_CORE_TEXT 93 -#define BAD_MIPS_TEXT 94 -#define NO_MOUSE_TEXT 95 +#define NOT_VGA_TEXT 90 +#define BAD_CHIP_TEXT 91 +#define BAD_DOS_TEXT 92 +#define NO_CORE_TEXT 93 +#define BAD_MIPS_TEXT 94 +#define NO_MOUSE_TEXT 95 -#define INF_NAME 101 -#define SAY_NAME 102 - -#define INF_REF 301 -#define SAY_REF 302 +#define INF_NAME 101 +#define SAY_NAME 102 + +#define INF_REF 301 +#define SAY_REF 302 -class TEXT -{ - struct HAN { int Ref; char * Txt; } * Cache; - int Size; - char FileName[MAXPATH]; - char * Load (int idx, int ref); - int Find (int ref); +class TEXT { + struct HAN { + int Ref; + char *Txt; + } *Cache; + int Size; + char FileName[MAXPATH]; + char *Load(int idx, int ref); + int Find(int ref); public: - TEXT (const char * fname, int size = 128); - ~TEXT (void); - void Clear (int from = 1, int upto = 0x7FFF); - void Preload (int from = 1, int upto = 0x7FFF); - char * operator[] (int ref); + TEXT(const char *fname, int size = 128); + ~TEXT(void); + void Clear(int from = 1, int upto = 0x7FFF); + void Preload(int from = 1, int upto = 0x7FFF); + char *operator[](int ref); }; - -extern TALK * Talk; -extern TEXT Text; +extern TALK *Talk; +extern TEXT Text; -void Say (const char * txt, SPRITE * spr); -void SayTime (SPRITE * spr); -void Inf (const char * txt); -void KillText (void); +void Say(const char *txt, SPRITE *spr); +void SayTime(SPRITE *spr); +void Inf(const char *txt); +void KillText(void); } // End of namespace CGE diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 01441c85a38..e7ed6d0402e 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -25,245 +25,219 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/general.h" -#include "cge/vga13h.h" -#include "cge/bitmap.h" -#include "cge/vol.h" -#include "cge/text.h" -#include -#include -#include -#include -#include -#include -#include +#include "cge/general.h" +#include "cge/vga13h.h" +#include "cge/bitmap.h" +#include "cge/vol.h" +#include "cge/text.h" +#include +#include +#include +#include +#include +#include +#include namespace CGE { #ifdef DEBUG -#define REPORT +#define REPORT #endif -#define OK(f) ((f).Error==0) -#define FADE_STEP 2 +#define OK(f) ((f).Error==0) +#define FADE_STEP 2 -#define TMR_DIV ((0x8000/TMR_RATE)*2) +#define TMR_DIV ((0x8000/TMR_RATE)*2) //-------------------------------------------------------------------------- -#ifdef REPORT +#ifdef REPORT static char Report[] = "NearHeap=..... FarHeap=......\n"; -#define NREP 9 -#define FREP 24 +#define NREP 9 +#define FREP 24 #endif -static VgaRegBlk VideoMode[] = { +static VgaRegBlk VideoMode[] = { - { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode - - { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 - { 0x05, VGAGRA, 0x03, 0x00 }, // R/W mode = 0 - { 0x06, VGAGRA, 0x02, 0x00 }, // misc - - { 0x14, VGACRT, 0x40, 0x00 }, // underline - { 0x13, VGACRT, 0xFF, 0x28 }, // screen width - { 0x17, VGACRT, 0xFF, 0xC3 }, // mode control - - { 0x11, VGACRT, 0x80, 0x00 }, // vert retrace end - { 0x09, VGACRT, 0xEF, 0x01 }, // max scan line - - { 0x30, VGAATR, 0x00, 0x20 }, // 256 color mode - -// { 0x12, VGACRT, 0xFF, 0x6E }, // vert display end -// { 0x15, VGACRT, 0xFF, 0x7F }, // start vb -// { 0x10, VGACRT, 0xFF, 0x94 }, // start vr - - { 0x00 } }; + { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode + { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 + { 0x05, VGAGRA, 0x03, 0x00 }, // R/W mode = 0 + { 0x06, VGAGRA, 0x02, 0x00 }, // misc + { 0x14, VGACRT, 0x40, 0x00 }, // underline + { 0x13, VGACRT, 0xFF, 0x28 }, // screen width + { 0x17, VGACRT, 0xFF, 0xC3 }, // mode control + { 0x11, VGACRT, 0x80, 0x00 }, // vert retrace end + { 0x09, VGACRT, 0xEF, 0x01 }, // max scan line + { 0x30, VGAATR, 0x00, 0x20 }, // 256 color mode +// { 0x12, VGACRT, 0xFF, 0x6E }, // vert display end +// { 0x15, VGACRT, 0xFF, 0x7F }, // start vb +// { 0x10, VGACRT, 0xFF, 0x94 }, // start vr + { 0x00 } +}; - bool SpeedTest = false; - SEQ Seq1[] = { { 0, 0, 0, 0, 0 } }; - SEQ Seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; - SPRITE * Sys = NULL; +bool SpeedTest = false; +SEQ Seq1[] = { { 0, 0, 0, 0, 0 } }; +SEQ Seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; +SPRITE *Sys = NULL; -extern "C" void SNDMIDIPlay (void); +extern "C" void SNDMIDIPlay(void); - - - - - -char * NumStr (char * str, int num) -{ - char * p = strchr(str, '#'); - if (p) wtom(num, p, 10, 5); - return str; +char *NumStr(char *str, int num) { + char *p = strchr(str, '#'); + if (p) + wtom(num, p, 10, 5); + return str; } - - - - - -// TODO Video ASM -/* -static void Video (void) +static void Video(void) { +/* static uint16 SP_S; - - asm push bx - asm push bp - asm push si - asm push di - asm push es - asm xor bx,bx // video page #0 + asm push bx + asm push bp + asm push si + asm push di + asm push es + asm xor bx,bx // video page #0 SP_S = _SP; - asm int VIDEO + asm int VIDEO _SP = SP_S; - asm pop es - asm pop di - asm pop si - asm pop bp - asm pop bx - + asm pop es + asm pop di + asm pop si + asm pop bp + asm pop bx +*/ + warning("STUB: Video"); } - */ +uint16 *SaveScreen(void) { + /* + uint16 cxy, cur, siz, * scr = NULL, * sav; + // horizontal size of text mode screen + asm mov ah,0x0F // get current video mode + Video(); // BIOS video service + asm xchg ah,al // answer in ah + asm push ax // preserve width + // vertical size of text mode screen + asm mov dl,24 // last row on std screen + asm xor bx,bx // valid request in BH + asm mov ax,0x1130 // get EGA's last row # + Video(); // BIOS video service + asm inc dl // # of rows = last+1 -uint16 * SaveScreen (void) -{ -/* - uint16 cxy, cur, siz, * scr = NULL, * sav; + // compute screen size in words + asm pop ax // restore width + asm mul dl // width * height - // horizontal size of text mode screen - asm mov ah,0x0F // get current video mode - Video(); // BIOS video service - asm xchg ah,al // answer in ah - asm push ax // preserve width + siz = _AX; - // vertical size of text mode screen - asm mov dl,24 // last row on std screen - asm xor bx,bx // valid request in BH - asm mov ax,0x1130 // get EGA's last row # - Video(); // BIOS video service - asm inc dl // # of rows = last+1 + asm mov ax,0x40 // system data segment + asm mov es,ax + asm mov ax,0B000H // Mono + asm cmp byte ptr es:[0x49],0x07 + asm je sto + asm mov ax,0B800H // Color + sto: // store screen address + asm mov word ptr scr+2,ax - // compute screen size in words - asm pop ax // restore width - asm mul dl // width * height + _AH = 0x0F; Video(); // active page - siz = _AX; + // take cursor shape + _AH = 0x03; Video(); // get cursor size + cur = _CX; - asm mov ax,0x40 // system data segment - asm mov es,ax - asm mov ax,0B000H // Mono - asm cmp byte ptr es:[0x49],0x07 - asm je sto - asm mov ax,0B800H // Color - sto: // store screen address - asm mov word ptr scr+2,ax + // take cursor position + _DH = 0; + _AH = 0x03; Video(); // get cursor + cxy = _DX; - _AH = 0x0F; Video(); // active page - - // take cursor shape - _AH = 0x03; Video(); // get cursor size - cur = _CX; - - // take cursor position - _DH = 0; - _AH = 0x03; Video(); // get cursor - cxy = _DX; - - sav = farnew(uint16, siz+3); // +3 extra uint16s for size and cursor - if (sav) - { - sav[0] = siz; - sav[1] = cur; - sav[2] = cxy; - memcpy(sav+3, scr, siz * 2); - } - return sav; - */ + sav = farnew(uint16, siz+3); // +3 extra uint16s for size and cursor + if (sav) + { + sav[0] = siz; + sav[1] = cur; + sav[2] = cxy; + memcpy(sav+3, scr, siz * 2); + } + return sav; + */ warning("STUB: SaveScreen"); return 0; } -void RestoreScreen (uint16 * &sav) -{ -/* - uint16 * scr = NULL; +void RestoreScreen(uint16 * &sav) { + /* + uint16 * scr = NULL; - asm mov ax,0x40 // system data segment - asm mov es,ax - asm mov ax,0B000H // Mono - asm cmp byte ptr es:[0x49],0x07 - asm je sto - asm mov ax,0B800H // Color - sto: // store screen address - asm mov word ptr scr+2,ax + asm mov ax,0x40 // system data segment + asm mov es,ax + asm mov ax,0B000H // Mono + asm cmp byte ptr es:[0x49],0x07 + asm je sto + asm mov ax,0B800H // Color + sto: // store screen address + asm mov word ptr scr+2,ax - memcpy(scr, sav+3, sav[0] * 2); + memcpy(scr, sav+3, sav[0] * 2); - _AH = 0x0F; Video(); // active page + _AH = 0x0F; Video(); // active page - // set cursor shape - _CX = sav[1]; - _AH = 0x01; Video(); // set cursor size + // set cursor shape + _CX = sav[1]; + _AH = 0x01; Video(); // set cursor size - // set cursor position - _DX = sav[2]; - _AH = 0x02; Video(); // set cursor + // set cursor position + _DX = sav[2]; + _AH = 0x02; Video(); // set cursor - free(sav); - sav = NULL; - */ + free(sav); + sav = NULL; + */ warning("STUB: RestoreScreen"); } -DAC MkDAC (uint8 r, uint8 g, uint8 b) -{ - static DAC x; - x.R = r; - x.G = g; - x.B = b; - return x; +DAC MkDAC(uint8 r, uint8 g, uint8 b) { + static DAC x; + x.R = r; + x.G = g; + x.B = b; + return x; } -RGB MkRGB (uint8 r, uint8 g, uint8 b) -{ - static TRGB x; - x.dac.R = r; - x.dac.G = g; - x.dac.B = b; - return x.rgb; +RGB MkRGB(uint8 r, uint8 g, uint8 b) { + static TRGB x; + x.dac.R = r; + x.dac.G = g; + x.dac.B = b; + return x.rgb; } -SPRITE * Locate (int ref) -{ - SPRITE * spr = VGA::ShowQ.Locate(ref); - return (spr) ? spr : VGA::SpareQ.Locate(ref); +SPRITE *Locate(int ref) { + SPRITE *spr = VGA::ShowQ.Locate(ref); + return (spr) ? spr : VGA::SpareQ.Locate(ref); } -bool HEART::Enable = false; -uint16 * HEART::XTimer = NULL; +bool HEART::Enable = false; +uint16 *HEART::XTimer = NULL; -HEART::HEART (void) -: ENGINE(TMR_DIV) -{ +HEART::HEART(void) + : ENGINE(TMR_DIV) { } @@ -278,1323 +252,1284 @@ extern "C" void TimerProc (void) if (*HEART::XTimer) -- *HEART::XTimer; else HEART::XTimer = NULL; - if (! run && HEART::Enable) // check overrun flag + if (! run && HEART::Enable) // check overrun flag { static uint16 oldSP, oldSS; - ++ run; // disable 2nd call until current lasts - asm mov ax,ds - asm mov oldSS,ss - asm mov oldSP,sp - asm mov ss,ax - asm mov sp,0xFF80 + ++ run; // disable 2nd call until current lasts + asm mov ax,ds + asm mov oldSS,ss + asm mov oldSP,sp + asm mov ss,ax + asm mov sp,0xFF80 // system pseudo-sprite if (Sys) if (Sys->Time) if (-- Sys->Time == 0) Sys->Tick(); for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) - { - if (spr->Time) if (!spr->Flags.Hide) if (-- spr->Time == 0) spr->Tick(); - } - asm mov ss,oldSS - asm mov sp,oldSP + { + if (spr->Time) if (!spr->Flags.Hide) if (-- spr->Time == 0) spr->Tick(); + } + asm mov ss,oldSS + asm mov sp,oldSP -- run; } } */ -void ENGINE::NewTimer(...) -{ - static SPRITE * spr; - static uint8 run = 0, cntr1 = TMR_RATE1, cntr2 = TMR_RATE2; - /* - ___1152_Hz___: +void ENGINE::NewTimer(...) { + static SPRITE *spr; + static uint8 run = 0, cntr1 = TMR_RATE1, cntr2 = TMR_RATE2; + /* + ___1152_Hz___: - SNDMIDIPlay(); - asm dec cntr1 - asm jz ___72_Hz___ - asm mov al,0x20 // send... - asm out 0x020,al // ...e-o-i - return; + SNDMIDIPlay(); + asm dec cntr1 + asm jz ___72_Hz___ + asm mov al,0x20 // send... + asm out 0x020,al // ...e-o-i + return; - ___72_Hz___: + ___72_Hz___: - asm mov cntr1,TMR_RATE1 - asm dec cntr2 - asm jnz my_eoi + asm mov cntr1,TMR_RATE1 + asm dec cntr2 + asm jnz my_eoi - ___18_Hz___: + ___18_Hz___: - OldTimer(); - asm mov cntr2,TMR_RATE2 - asm jmp short my_int + OldTimer(); + asm mov cntr2,TMR_RATE2 + asm jmp short my_int - // send E-O-I - my_eoi: - asm mov al,0x20 - asm out 0x020,al - asm sti // enable interrupts + // send E-O-I + my_eoi: + asm mov al,0x20 + asm out 0x020,al + asm sti // enable interrupts - my_int: //------72Hz-------// + my_int: //------72Hz-------// - // decrement external timer uint16 - if (HEART::XTimer) - if (*HEART::XTimer) -- *HEART::XTimer; - else HEART::XTimer = NULL; + // decrement external timer uint16 + if (HEART::XTimer) + if (*HEART::XTimer) -- *HEART::XTimer; + else HEART::XTimer = NULL; - if (! run && HEART::Enable) // check overrun flag - { - static uint16 oldSP, oldSS; + if (! run && HEART::Enable) // check overrun flag + { + static uint16 oldSP, oldSS; - ++ run; // disable 2nd call until current lasts - asm mov ax,ds - asm mov oldSS,ss - asm mov oldSP,sp - asm mov ss,ax - asm mov sp,0xFF80 + ++ run; // disable 2nd call until current lasts + asm mov ax,ds + asm mov oldSS,ss + asm mov oldSP,sp + asm mov ss,ax + asm mov sp,0xFF80 - // system pseudo-sprite - if (Sys) if (Sys->Time) if (-- Sys->Time == 0) Sys->Tick(); + // system pseudo-sprite + if (Sys) if (Sys->Time) if (-- Sys->Time == 0) Sys->Tick(); - for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) + for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { if (spr->Time) if (!spr->Flags.Hide) if (-- spr->Time == 0) spr->Tick(); } - asm mov ss,oldSS - asm mov sp,oldSP - -- run; - } + asm mov ss,oldSS + asm mov sp,oldSP + -- run; + } */ warning("STUB: ENGINE::NewTimer"); } -void HEART::SetXTimer (uint16 * ptr) -{ - if (XTimer && ptr != XTimer) *XTimer = 0; - XTimer = ptr; +void HEART::SetXTimer(uint16 *ptr) { + if (XTimer && ptr != XTimer) + *XTimer = 0; + XTimer = ptr; } -void HEART::SetXTimer (uint16 * ptr, uint16 time) -{ - SetXTimer(ptr); - *ptr = time; +void HEART::SetXTimer(uint16 *ptr, uint16 time) { + SetXTimer(ptr); + *ptr = time; } -SPRITE::SPRITE (BMP_PTR * shp) -: X(0), Y(0), Z(0), NearPtr(0), TakePtr(0), - Next(NULL), Prev(NULL), SeqPtr(NO_SEQ), Time(0), //Delay(0), - Ext(NULL), Ref(-1), Cave(0) -{ - memset(File, 0, sizeof(File)); - *((uint16 *)&Flags) = 0; - SetShapeList(shp); +SPRITE::SPRITE(BMP_PTR *shp) + : X(0), Y(0), Z(0), NearPtr(0), TakePtr(0), + Next(NULL), Prev(NULL), SeqPtr(NO_SEQ), Time(0), //Delay(0), + Ext(NULL), Ref(-1), Cave(0) { + memset(File, 0, sizeof(File)); + *((uint16 *)&Flags) = 0; + SetShapeList(shp); } -SPRITE::~SPRITE (void) -{ - Contract(); +SPRITE::~SPRITE(void) { + Contract(); } -BMP_PTR SPRITE::Shp (void) -{ - register SPREXT * e = Ext; - if (e) if (e->Seq) - { - int i = e->Seq[SeqPtr].Now; - #ifdef DEBUG - if (i >= ShpCnt) - { - //char s[256]; - //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", - // Seq, ShpCnt, SeqPtr, Seq[SeqPtr].Now, Seq[SeqPtr].Next); - //VGA::Exit(s, File); - error("Invalid PHASE in SPRITE::Shp() %s", File); - } - #endif - return e->ShpList[i]; - } - return NULL; -} - - -BMP_PTR * SPRITE::SetShapeList (BMP_PTR * shp) -{ - BMP_PTR * r = (Ext) ? Ext->ShpList : NULL; - - ShpCnt = 0; - W = 0; - H = 0; - - if (shp) - { - BMP_PTR * p; - for (p = shp; *p; p ++) - { - BMP_PTR b = (*p); // ->Code(); - if (b->W > W) W = b->W; - if (b->H > H) H = b->H; - ++ ShpCnt; - } - Expand(); - Ext->ShpList = shp; - if (! Ext->Seq) SetSeq((ShpCnt < 2) ? Seq1 : Seq2); - } - return r; -} - - -void SPRITE::MoveShapes (uint8 * buf) -{ - BMP_PTR * p; - for (p = Ext->ShpList; *p; p ++) - { - buf += (*p)->MoveVmap(buf); - } -} - - -bool SPRITE::Works (SPRITE * spr) -{ - if (spr) if (spr->Ext) - { - SNAIL::COM * c = spr->Ext->Take; - if (c != NULL) - { - c += spr->TakePtr; - if (c->Ref == Ref) - if (c->Com != SNLABEL || (c->Val == 0 || c->Val == Now)) - return true; - } - } - return false; -} - - -SEQ * SPRITE::SetSeq (SEQ * seq) -{ - Expand(); - register SEQ * s = Ext->Seq; - Ext->Seq = seq; - if (SeqPtr == NO_SEQ) Step(0); - else - if (Time == 0) Step(SeqPtr); - return s; -} - - -bool SPRITE::SeqTest (int n) -{ - if (n >= 0) return (SeqPtr == n); - if (Ext) return (Ext->Seq[SeqPtr].Next == SeqPtr); - return true; -} - - -SNAIL::COM * SPRITE::SnList (SNLIST type) -{ - register SPREXT * e = Ext; - if (e) return (type == NEAR) ? e->Near : e->Take; - return NULL; -} - - -void SPRITE::SetName (char * n) -{ - if (Ext) - { - if (Ext->Name) - { - delete[] Ext->Name; - Ext->Name = NULL; - } - if (n) - { - if ((Ext->Name = new char[strlen(n)+1]) != NULL) strcpy(Ext->Name, n); - else - error("No core [%s]", n); - } - } -} - - -SPRITE * SPRITE::Expand (void) -{ - if (! Ext) - { - bool enbl = HEART::Enable; - HEART::Enable = false; - if ((Ext = new SPREXT) == NULL) - error("No core"); - if (*File) - { - static const char * Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; - char line[LINE_MAX], fname[MAXPATH]; - BMP_PTR * shplist = new BMP_PTR [ShpCnt+1]; - SEQ * seq = NULL; - int shpcnt = 0, - seqcnt = 0, - neacnt = 0, - takcnt = 0, - maxnow = 0, - maxnxt = 0, - lcnt = 0, - len; - - SNAIL::COM * nea = NULL; - SNAIL::COM * tak = NULL; - MergeExt(fname, File, SPR_EXT); - if (INI_FILE::Exist(fname)) // sprite description file exist - { - INI_FILE sprf(fname); - if (! OK(sprf)) - error("Bad SPR [%s]", fname); - - while ((len = sprf.Read((uint8*)line)) != 0) - { - ++ lcnt; - if (len && line[len-1] == '\n') line[-- len] = '\0'; - if (len == 0 || *line == '.') continue; - - switch (TakeEnum(Comd, strtok(line, " =\t"))) - { - case 0 : // Name - { - SetName(strtok(NULL, "")); break; - } - case 1 : // Phase - { - shplist[shpcnt ++] = new BITMAP(strtok(NULL, " \t,;/")); - break; - } - case 2 : // Seq - { - seq = (SEQ *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); - if (seq == NULL) - error("No core [%s]", fname); - SEQ * s = &seq[seqcnt ++]; - s->Now = atoi(strtok(NULL, " \t,;/")); - if (s->Now > maxnow) maxnow = s->Now; - s->Next = atoi(strtok(NULL, " \t,;/")); - switch (s->Next) - { - case 0xFF : s->Next = seqcnt; break; - case 0xFE : s->Next = seqcnt-1; break; - } - if (s->Next > maxnxt) maxnxt = s->Next; - s->Dx = atoi(strtok(NULL, " \t,;/")); - s->Dy = atoi(strtok(NULL, " \t,;/")); - s->Dly = atoi(strtok(NULL, " \t,;/")); - break; - } - case 3 : // Near - { - if (NearPtr != NO_PTR) - { - nea = (SNAIL::COM *) realloc(nea, (neacnt + 1) * sizeof(*nea)); - if (nea == NULL) - error("No core [%s]", fname); - else - { - SNAIL::COM * c = &nea[neacnt ++]; - if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) - error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), fname); - c->Ref = atoi(strtok(NULL, " \t,;/")); - c->Val = atoi(strtok(NULL, " \t,;/")); - c->Ptr = NULL; - } - } - } - break; - case 4 : // Take - { - if (TakePtr != NO_PTR) - { - tak = (SNAIL::COM *) realloc(tak, (takcnt + 1) * sizeof(*tak)); - if (tak == NULL) - error("No core [%s]", fname); - else - { - SNAIL::COM * c = &tak[takcnt ++]; - if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) - error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), fname); - c->Ref = atoi(strtok(NULL, " \t,;/")); - c->Val = atoi(strtok(NULL, " \t,;/")); - c->Ptr = NULL; - } - } - break; - } - } +BMP_PTR SPRITE::Shp(void) { + register SPREXT *e = Ext; + if (e) + if (e->Seq) { + int i = e->Seq[SeqPtr].Now; +#ifdef DEBUG + if (i >= ShpCnt) { + //char s[256]; + //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", + // Seq, ShpCnt, SeqPtr, Seq[SeqPtr].Now, Seq[SeqPtr].Next); + //VGA::Exit(s, File); + error("Invalid PHASE in SPRITE::Shp() %s", File); + } +#endif + return e->ShpList[i]; } - } - else // no sprite description: try to read immediately from .BMP - { - shplist[shpcnt ++] = new BITMAP(File); - } - shplist[shpcnt] = NULL; - if (seq) - { - if (maxnow >= shpcnt) - error("Bad PHASE in SEQ [%s]", fname); - if (maxnxt >= seqcnt) - error("Bad JUMP in SEQ [%s]", fname); - SetSeq(seq); - } - else SetSeq((ShpCnt == 1) ? Seq1 : Seq2); - //disable(); // disable interupt + return NULL; +} - SetShapeList(shplist); - //enable(); // enable interupt - if (nea) nea[neacnt-1].Ptr = Ext->Near = nea; else NearPtr = NO_PTR; - if (tak) tak[takcnt-1].Ptr = Ext->Take = tak; else TakePtr = NO_PTR; + +BMP_PTR *SPRITE::SetShapeList(BMP_PTR *shp) { + BMP_PTR *r = (Ext) ? Ext->ShpList : NULL; + + ShpCnt = 0; + W = 0; + H = 0; + + if (shp) { + BMP_PTR *p; + for (p = shp; *p; p++) { + BMP_PTR b = (*p); // ->Code(); + if (b->W > W) + W = b->W; + if (b->H > H) + H = b->H; + ++ShpCnt; + } + Expand(); + Ext->ShpList = shp; + if (! Ext->Seq) + SetSeq((ShpCnt < 2) ? Seq1 : Seq2); } - HEART::Enable = enbl; - } - return this; + return r; } -SPRITE * SPRITE::Contract (void) -{ - register SPREXT * e = Ext; - if (e) - { - if (e->Name) delete[] e->Name; - if (Flags.BDel && e->ShpList) - { - int i; - for (i = 0; e->ShpList[i]; i ++) delete e->ShpList[i]; - if (MemType(e->ShpList) == NEAR_MEM) delete[] e->ShpList; +void SPRITE::MoveShapes(uint8 *buf) { + BMP_PTR *p; + for (p = Ext->ShpList; *p; p ++) { + buf += (*p)->MoveVmap(buf); } - if (MemType(e->Seq) == NEAR_MEM) free(e->Seq); - if (e->Near) free(e->Near); - if (e->Take) free(e->Take); - delete e; - Ext = NULL; - } - return this; } -SPRITE * SPRITE::BackShow (bool fast) -{ - Expand(); - Show(2); - Show(1); - if (fast) Show(0); - Contract(); - return this; +bool SPRITE::Works(SPRITE *spr) { + if (spr) + if (spr->Ext) { + SNAIL::COM *c = spr->Ext->Take; + if (c != NULL) { + c += spr->TakePtr; + if (c->Ref == Ref) + if (c->Com != SNLABEL || (c->Val == 0 || c->Val == Now)) + return true; + } + } + return false; } -void SPRITE::Step (int nr) -{ - if (nr >= 0) SeqPtr = nr; - if (Ext) - { - SEQ * seq; - if (nr < 0) SeqPtr = Ext->Seq[SeqPtr].Next; - seq = Ext->Seq + SeqPtr; - if (seq->Dly >= 0) - { - Goto(X + (seq->Dx), Y + (seq->Dy)); - Time = seq->Dly; +SEQ *SPRITE::SetSeq(SEQ *seq) { + Expand(); + register SEQ *s = Ext->Seq; + Ext->Seq = seq; + if (SeqPtr == NO_SEQ) + Step(0); + else if (Time == 0) + Step(SeqPtr); + return s; +} + + +bool SPRITE::SeqTest(int n) { + if (n >= 0) + return (SeqPtr == n); + if (Ext) + return (Ext->Seq[SeqPtr].Next == SeqPtr); + return true; +} + + +SNAIL::COM *SPRITE::SnList(SNLIST type) { + register SPREXT *e = Ext; + if (e) + return (type == NEAR) ? e->Near : e->Take; + return NULL; +} + + +void SPRITE::SetName(char *n) { + if (Ext) { + if (Ext->Name) { + delete[] Ext->Name; + Ext->Name = NULL; + } + if (n) { + if ((Ext->Name = new char[strlen(n) + 1]) != NULL) + strcpy(Ext->Name, n); + else + error("No core [%s]", n); + } } - } } -void SPRITE::Tick (void) -{ - Step(); -} +SPRITE *SPRITE::Expand(void) { + if (! Ext) { + bool enbl = HEART::Enable; + HEART::Enable = false; + if ((Ext = new SPREXT) == NULL) + error("No core"); + if (*File) { + static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; + char line[LINE_MAX], fname[MAXPATH]; + BMP_PTR *shplist = new BMP_PTR [ShpCnt + 1]; + SEQ *seq = NULL; + int shpcnt = 0, + seqcnt = 0, + neacnt = 0, + takcnt = 0, + maxnow = 0, + maxnxt = 0, + lcnt = 0, + len; + SNAIL::COM *nea = NULL; + SNAIL::COM *tak = NULL; + MergeExt(fname, File, SPR_EXT); + if (INI_FILE::Exist(fname)) { // sprite description file exist + INI_FILE sprf(fname); + if (! OK(sprf)) + error("Bad SPR [%s]", fname); -void SPRITE::MakeXlat (uint8 * x) -{ - if (Ext) - { - BMP_PTR * b; + while ((len = sprf.Read((uint8 *)line)) != 0) { + ++ lcnt; + if (len && line[len - 1] == '\n') + line[-- len] = '\0'; + if (len == 0 || *line == '.') + continue; - if (Flags.Xlat) KillXlat(); - for (b = Ext->ShpList; *b; b ++) (*b)->M = x; - Flags.Xlat = true; - } -} + switch (TakeEnum(Comd, strtok(line, " =\t"))) { + case 0 : { // Name + SetName(strtok(NULL, "")); + break; + } + case 1 : { // Phase + shplist[shpcnt ++] = new BITMAP(strtok(NULL, " \t,;/")); + break; + } + case 2 : { // Seq + seq = (SEQ *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); + if (seq == NULL) + error("No core [%s]", fname); + SEQ *s = &seq[seqcnt ++]; + s->Now = atoi(strtok(NULL, " \t,;/")); + if (s->Now > maxnow) + maxnow = s->Now; + s->Next = atoi(strtok(NULL, " \t,;/")); + switch (s->Next) { + case 0xFF : + s->Next = seqcnt; + break; + case 0xFE : + s->Next = seqcnt - 1; + break; + } + if (s->Next > maxnxt) + maxnxt = s->Next; + s->Dx = atoi(strtok(NULL, " \t,;/")); + s->Dy = atoi(strtok(NULL, " \t,;/")); + s->Dly = atoi(strtok(NULL, " \t,;/")); + break; + } + case 3 : { // Near + if (NearPtr != NO_PTR) { + nea = (SNAIL::COM *) realloc(nea, (neacnt + 1) * sizeof(*nea)); + if (nea == NULL) + error("No core [%s]", fname); + else { + SNAIL::COM *c = &nea[neacnt ++]; + if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) + error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), fname); + c->Ref = atoi(strtok(NULL, " \t,;/")); + c->Val = atoi(strtok(NULL, " \t,;/")); + c->Ptr = NULL; + } + } + } + break; + case 4 : { // Take + if (TakePtr != NO_PTR) { + tak = (SNAIL::COM *) realloc(tak, (takcnt + 1) * sizeof(*tak)); + if (tak == NULL) + error("No core [%s]", fname); + else { + SNAIL::COM *c = &tak[takcnt ++]; + if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) + error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), fname); + c->Ref = atoi(strtok(NULL, " \t,;/")); + c->Val = atoi(strtok(NULL, " \t,;/")); + c->Ptr = NULL; + } + } + break; + } + } + } + } else { // no sprite description: try to read immediately from .BMP + shplist[shpcnt ++] = new BITMAP(File); + } + shplist[shpcnt] = NULL; + if (seq) { + if (maxnow >= shpcnt) + error("Bad PHASE in SEQ [%s]", fname); + if (maxnxt >= seqcnt) + error("Bad JUMP in SEQ [%s]", fname); + SetSeq(seq); + } else + SetSeq((ShpCnt == 1) ? Seq1 : Seq2); + //disable(); // disable interupt - -void SPRITE::KillXlat (void) -{ - if (Flags.Xlat && Ext) - { - BMP_PTR * b; - uint8 * m = (*Ext->ShpList)->M; - - switch (MemType(m)) - { - case NEAR_MEM : delete[] (uint8 *) m; break; - case FAR_MEM : free(m); break; + SetShapeList(shplist); + //enable(); // enable interupt + if (nea) + nea[neacnt - 1].Ptr = Ext->Near = nea; + else + NearPtr = NO_PTR; + if (tak) + tak[takcnt - 1].Ptr = Ext->Take = tak; + else + TakePtr = NO_PTR; + } + HEART::Enable = enbl; } - for (b = Ext->ShpList; *b; b ++) (*b)->M = NULL; - Flags.Xlat = false; - } + return this; } -void SPRITE::Goto (int x, int y) -{ - int xo = X, yo = Y; - if (W < SCR_WID) - { - if (x < 0) x = 0; - if (x + W > SCR_WID) x = (SCR_WID - W); - X = x; - } - if (H < SCR_HIG) - { - if (y < 0) y = 0; - if (y + H > SCR_HIG) y = (SCR_HIG - H); - Y = y; - } - if (Next) if (Next->Flags.Slav) Next->Goto(Next->X-xo+X, Next->Y-yo+Y); - if (Flags.Shad) Prev->Goto(Prev->X-xo+X, Prev->Y-yo+Y); +SPRITE *SPRITE::Contract(void) { + register SPREXT *e = Ext; + if (e) { + if (e->Name) + delete[] e->Name; + if (Flags.BDel && e->ShpList) { + int i; + for (i = 0; e->ShpList[i]; i ++) + delete e->ShpList[i]; + if (MemType(e->ShpList) == NEAR_MEM) + delete[] e->ShpList; + } + if (MemType(e->Seq) == NEAR_MEM) + free(e->Seq); + if (e->Near) + free(e->Near); + if (e->Take) + free(e->Take); + delete e; + Ext = NULL; + } + return this; } -void SPRITE::Center (void) -{ - Goto((SCR_WID - W) / 2, (SCR_HIG - H) / 2); +SPRITE *SPRITE::BackShow(bool fast) { + Expand(); + Show(2); + Show(1); + if (fast) + Show(0); + Contract(); + return this; } -void SPRITE::Show (void) -{ - register SPREXT * e; - // asm cli // critic section... - e = Ext; - e->x0 = e->x1; - e->y0 = e->y1; - e->b0 = e->b1; - e->x1 = X; - e->y1 = Y; - e->b1 = Shp(); -// asm sti // ...done! - if (! Flags.Hide) - { - if (Flags.Xlat) e->b1->XShow(e->x1, e->y1); - else e->b1->Show(e->x1, e->y1); - } +void SPRITE::Step(int nr) { + if (nr >= 0) + SeqPtr = nr; + if (Ext) { + SEQ *seq; + if (nr < 0) + SeqPtr = Ext->Seq[SeqPtr].Next; + seq = Ext->Seq + SeqPtr; + if (seq->Dly >= 0) { + Goto(X + (seq->Dx), Y + (seq->Dy)); + Time = seq->Dly; + } + } } -void SPRITE::Show (uint16 pg) -{ - uint8 * a = VGA::Page[1]; - VGA::Page[1] = VGA::Page[pg & 3]; - Shp()->Show(X, Y); - VGA::Page[1] = a; +void SPRITE::Tick(void) { + Step(); } -void SPRITE::Hide (void) -{ - register SPREXT * e = Ext; - if (e->b0) e->b0->Hide(e->x0, e->y0); +void SPRITE::MakeXlat(uint8 *x) { + if (Ext) { + BMP_PTR *b; + + if (Flags.Xlat) + KillXlat(); + for (b = Ext->ShpList; *b; b ++) + (*b)->M = x; + Flags.Xlat = true; + } } -BMP_PTR SPRITE::Ghost (void) -{ - register SPREXT * e = Ext; - if (e->b1) - { - BMP_PTR bmp = new BITMAP(0, 0, (uint8 *)NULL); - if (bmp == NULL) - error("No core"); - bmp->W = e->b1->W; - bmp->H = e->b1->H; - if ((bmp->B = farnew(HideDesc, bmp->H)) == NULL) - error("No Core"); - bmp->V = (uint8 *) memcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); - // TODO offset correctly in the surface using y1 pitch and x1 and not via offset segment - //bmp->M = (uint8 *) MK_FP(e->y1, e->x1); - return bmp; - } - return NULL; +void SPRITE::KillXlat(void) { + if (Flags.Xlat && Ext) { + BMP_PTR *b; + uint8 *m = (*Ext->ShpList)->M; + + switch (MemType(m)) { + case NEAR_MEM : + delete[](uint8 *) m; + break; + case FAR_MEM : + free(m); + break; + } + for (b = Ext->ShpList; *b; b ++) + (*b)->M = NULL; + Flags.Xlat = false; + } } -SPRITE * SpriteAt (int x, int y) -{ - SPRITE * spr = NULL, * tail = VGA::ShowQ.Last(); - if (tail) - { - for (spr = tail->Prev; spr; spr = spr->Prev) - if (! spr->Flags.Hide && ! spr->Flags.Tran) - if (spr->Shp()->SolidAt(x-spr->X, y-spr->Y)) - break; - } - return spr; +void SPRITE::Goto(int x, int y) { + int xo = X, yo = Y; + if (W < SCR_WID) { + if (x < 0) + x = 0; + if (x + W > SCR_WID) + x = (SCR_WID - W); + X = x; + } + if (H < SCR_HIG) { + if (y < 0) + y = 0; + if (y + H > SCR_HIG) + y = (SCR_HIG - H); + Y = y; + } + if (Next) + if (Next->Flags.Slav) + Next->Goto(Next->X - xo + X, Next->Y - yo + Y); + if (Flags.Shad) + Prev->Goto(Prev->X - xo + X, Prev->Y - yo + Y); } -QUEUE::QUEUE (bool show) -: Head(NULL), Tail(NULL), Show(show) -{ +void SPRITE::Center(void) { + Goto((SCR_WID - W) / 2, (SCR_HIG - H) / 2); } -QUEUE::~QUEUE (void) -{ - Clear(); +void SPRITE::Show(void) { + register SPREXT *e; +// asm cli // critic section... + e = Ext; + e->x0 = e->x1; + e->y0 = e->y1; + e->b0 = e->b1; + e->x1 = X; + e->y1 = Y; + e->b1 = Shp(); +// asm sti // ...done! + if (! Flags.Hide) { + if (Flags.Xlat) e->b1->XShow(e->x1, e->y1); + else e->b1->Show(e->x1, e->y1); + } } -void QUEUE::Clear (void) -{ - while (Head) - { - SPRITE * s = Remove(Head); - if (s->Flags.Kill) delete s; - } +void SPRITE::Show(uint16 pg) { + uint8 *a = VGA::Page[1]; + VGA::Page[1] = VGA::Page[pg & 3]; + Shp()->Show(X, Y); + VGA::Page[1] = a; } -void QUEUE::ForAll (void (*fun)(SPRITE *)) -{ - SPRITE * s = Head; - while (s) - { - SPRITE * n = s->Next; - fun(s); - s = n; - } +void SPRITE::Hide(void) { + register SPREXT *e = Ext; + if (e->b0) + e->b0->Hide(e->x0, e->y0); } -void QUEUE::Append (SPRITE * spr) -{ - if (Tail) - { - spr->Prev = Tail; - Tail->Next = spr; - } - else Head = spr; - Tail = spr; - if (Show) spr->Expand(); - else spr->Contract(); +BMP_PTR SPRITE::Ghost(void) { + register SPREXT *e = Ext; + if (e->b1) { + BMP_PTR bmp = new BITMAP(0, 0, (uint8 *)NULL); + if (bmp == NULL) + error("No core"); + bmp->W = e->b1->W; + bmp->H = e->b1->H; + if ((bmp->B = farnew(HideDesc, bmp->H)) == NULL) + error("No Core"); + bmp->V = (uint8 *) memcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); + // TODO offset correctly in the surface using y1 pitch and x1 and not via offset segment + //bmp->M = (uint8 *) MK_FP(e->y1, e->x1); + warning("FIXME: SPRITE::Ghost"); + return bmp; + } + return NULL; } -void QUEUE::Insert (SPRITE * spr, SPRITE * nxt) -{ - if (nxt == Head) - { - spr->Next = Head; - Head = spr; - if (! Tail) Tail = spr; - } - else - { - spr->Next = nxt; - spr->Prev = nxt->Prev; - if (spr->Prev) spr->Prev->Next = spr; - } - if (spr->Next) spr->Next->Prev = spr; - if (Show) spr->Expand(); - else spr->Contract(); +SPRITE *SpriteAt(int x, int y) { + SPRITE *spr = NULL, * tail = VGA::ShowQ.Last(); + if (tail) { + for (spr = tail->Prev; spr; spr = spr->Prev) + if (! spr->Flags.Hide && ! spr->Flags.Tran) + if (spr->Shp()->SolidAt(x - spr->X, y - spr->Y)) + break; + } + return spr; } -void QUEUE::Insert (SPRITE * spr) -{ - SPRITE * s; - for (s = Head; s; s = s->Next) - if (s->Z > spr->Z) - break; - if (s) Insert(spr, s); - else Append(spr); - if (Show) spr->Expand(); - else spr->Contract(); +QUEUE::QUEUE(bool show) : Head(NULL), Tail(NULL), Show(show) { } -SPRITE * QUEUE::Remove (SPRITE * spr) -{ - if (spr == Head) Head = spr->Next; - if (spr == Tail) Tail = spr->Prev; - if (spr->Next) spr->Next->Prev = spr->Prev; - if (spr->Prev) spr->Prev->Next = spr->Next; - spr->Prev = NULL; - spr->Next = NULL; - return spr; +QUEUE::~QUEUE(void) { + Clear(); } -SPRITE * QUEUE::Locate (int ref) -{ - SPRITE * spr; - for (spr = Head; spr; spr = spr->Next) if (spr->Ref == ref) return spr; - return NULL; +void QUEUE::Clear(void) { + while (Head) { + SPRITE *s = Remove(Head); + if (s->Flags.Kill) + delete s; + } } -uint16 VGA::StatAdr = VGAST1_; -uint16 VGA::OldMode = 0; -uint16 * VGA::OldScreen = NULL; -const char * VGA::Msg = NULL; -const char * VGA::Nam = NULL; -DAC * VGA::OldColors = NULL; -DAC * VGA::NewColors = NULL; -bool VGA::SetPal = false; -int VGA::Mono = 0; -QUEUE VGA::ShowQ = true, VGA::SpareQ = false; +void QUEUE::ForAll(void (*fun)(SPRITE *)) { + SPRITE *s = Head; + while (s) { + SPRITE *n = s->Next; + fun(s); + s = n; + } +} + + +void QUEUE::Append(SPRITE *spr) { + if (Tail) { + spr->Prev = Tail; + Tail->Next = spr; + } else + Head = spr; + Tail = spr; + if (Show) + spr->Expand(); + else + spr->Contract(); +} + + +void QUEUE::Insert(SPRITE *spr, SPRITE *nxt) { + if (nxt == Head) { + spr->Next = Head; + Head = spr; + if (! Tail) + Tail = spr; + } else { + spr->Next = nxt; + spr->Prev = nxt->Prev; + if (spr->Prev) + spr->Prev->Next = spr; + } + if (spr->Next) + spr->Next->Prev = spr; + if (Show) + spr->Expand(); + else + spr->Contract(); +} + + +void QUEUE::Insert(SPRITE *spr) { + SPRITE *s; + for (s = Head; s; s = s->Next) + if (s->Z > spr->Z) + break; + if (s) + Insert(spr, s); + else + Append(spr); + if (Show) + spr->Expand(); + else + spr->Contract(); +} + + +SPRITE *QUEUE::Remove(SPRITE *spr) { + if (spr == Head) + Head = spr->Next; + if (spr == Tail) + Tail = spr->Prev; + if (spr->Next) + spr->Next->Prev = spr->Prev; + if (spr->Prev) + spr->Prev->Next = spr->Next; + spr->Prev = NULL; + spr->Next = NULL; + return spr; +} + + +SPRITE *QUEUE::Locate(int ref) { + SPRITE *spr; + for (spr = Head; spr; spr = spr->Next) + if (spr->Ref == ref) + return spr; + return NULL; +} + + +uint16 VGA::StatAdr = VGAST1_; +uint16 VGA::OldMode = 0; +uint16 *VGA::OldScreen = NULL; +const char *VGA::Msg = NULL; +const char *VGA::Nam = NULL; +DAC *VGA::OldColors = NULL; +DAC *VGA::NewColors = NULL; +bool VGA::SetPal = false; +int VGA::Mono = 0; +QUEUE VGA::ShowQ = true, VGA::SpareQ = false; // TODO: Was direct mapping to VGA buffers.. need to create scummvm surfaces for that -uint8 * VGA::Page[4] = { 0, 0, 0, 0 }; +uint8 *VGA::Page[4] = { 0, 0, 0, 0 }; /* -uint8 * VGA::Page[4] = { (uint8 *) MK_FP(SCR_SEG, 0x0000), - (uint8 *) MK_FP(SCR_SEG, 0x4000), - (uint8 *) MK_FP(SCR_SEG, 0x8000), - (uint8 *) MK_FP(SCR_SEG, 0xC000) }; +uint8 * VGA::Page[4] = { (uint8 *) MK_FP(SCR_SEG, 0x0000), + (uint8 *) MK_FP(SCR_SEG, 0x4000), + (uint8 *) MK_FP(SCR_SEG, 0x8000), + (uint8 *) MK_FP(SCR_SEG, 0xC000) }; */ - - //extern const char Copr[]; -VGA::VGA (int mode) -: FrmCnt(0) -{ - bool std = true; - int i; - for (i = 10; i < 20; i ++) - { - char * txt = Text[i]; - if (txt) - { +VGA::VGA(int mode) + : FrmCnt(0) { + bool std = true; + int i; + for (i = 10; i < 20; i ++) { + char *txt = Text[i]; + if (txt) { // puts(txt); - warning(txt); - #ifndef DEBUG - std = false; - #endif + warning(txt); +#ifndef DEBUG + std = false; +#endif + } } - } -// if (std) +// if (std) // warning(Copr); - warning("TODO: Fix Copr"); + warning("TODO: Fix Copr"); - SetStatAdr(); - if (StatAdr != VGAST1_) ++ Mono; - if (IsVga()) - { - OldColors = farnew(DAC, 256); - NewColors = farnew(DAC, 256); - OldScreen = SaveScreen(); - GetColors(OldColors); - Sunset(); - OldMode = SetMode(mode); - SetColors(); - Setup(VideoMode); - Clear(); - } + SetStatAdr(); + if (StatAdr != VGAST1_) + ++Mono; + if (IsVga()) { + OldColors = farnew(DAC, 256); + NewColors = farnew(DAC, 256); + OldScreen = SaveScreen(); + GetColors(OldColors); + Sunset(); + OldMode = SetMode(mode); + SetColors(); + Setup(VideoMode); + Clear(); + } } -VGA::~VGA (void) -{ - Mono = 0; - if (IsVga()) - { - Common::String buffer = ""; - Clear(); - SetMode(OldMode); - SetColors(); - RestoreScreen(OldScreen); - Sunrise(OldColors); - if (OldColors) free(OldColors); - if (NewColors) free(NewColors); - if (Msg) - buffer = Common::String(Msg); - if (Nam) - buffer = buffer + " [" + Nam + "]"; +VGA::~VGA(void) { + Mono = 0; + if (IsVga()) { + Common::String buffer = ""; + Clear(); + SetMode(OldMode); + SetColors(); + RestoreScreen(OldScreen); + Sunrise(OldColors); + if (OldColors) + free(OldColors); + if (NewColors) + free(NewColors); + if (Msg) + buffer = Common::String(Msg); + if (Nam) + buffer = buffer + " [" + Nam + "]"; - warning(buffer.c_str()); - } + warning(buffer.c_str()); + } } -void VGA::SetStatAdr (void) -{ +void VGA::SetStatAdr(void) { /* - asm mov dx,VGAMIr_ - asm in al,dx - asm test al,1 // CGA addressing mode flag - asm mov ax,VGAST1_ // CGA addressing - asm jnz set_mode_adr - asm xor al,0x60 // MDA addressing - set_mode_adr: - StatAdr = _AX; - */ + asm mov dx,VGAMIr_ + asm in al,dx + asm test al,1 // CGA addressing mode flag + asm mov ax,VGAST1_ // CGA addressing + asm jnz set_mode_adr + asm xor al,0x60 // MDA addressing + set_mode_adr: + StatAdr = _AX; + */ warning("STUB: VGA::SetStatADR"); } #pragma argsused -void VGA::WaitVR (bool on) -{ -/* - _DX = StatAdr; - _AH = (on) ? 0x00 : 0x08; +void VGA::WaitVR(bool on) { + /* + _DX = StatAdr; + _AH = (on) ? 0x00 : 0x08; - asm mov cx,2 - // wait for vertical retrace on (off) - wait: - asm in al,dx - asm xor al,ah - asm test al,0x08 - asm jnz wait - asm xor ah,0x08 - asm loop wait - */ + asm mov cx,2 + // wait for vertical retrace on (off) + wait: + asm in al,dx + asm xor al,ah + asm test al,0x08 + asm jnz wait + asm xor ah,0x08 + asm loop wait + */ warning("STUB: VGA::WaitVR"); } -void VGA::Setup (VgaRegBlk * vrb) -{ -/* - WaitVR(); // *--LOOK!--* resets VGAATR logic - asm cld - asm mov si, vrb // take address of parameter table - asm mov dh,0x03 // higher byte of I/O address is always 3 +void VGA::Setup(VgaRegBlk *vrb) { + /* + WaitVR(); // *--LOOK!--* resets VGAATR logic + asm cld + asm mov si, vrb // take address of parameter table + asm mov dh,0x03 // higher byte of I/O address is always 3 - s: - asm lodsw // take lower byte of I/O address and index - asm or ah,ah // 0 = end of table - asm jz xit // no more: exit - asm or al,al // indexed register? - asm js single // 7th bit set means single register - asm mov dl,ah // complete I/O address - asm out dx,al // put index into control register - asm inc dx // data register is next to control - asm in al,dx // take old data + s: + asm lodsw // take lower byte of I/O address and index + asm or ah,ah // 0 = end of table + asm jz xit // no more: exit + asm or al,al // indexed register? + asm js single // 7th bit set means single register + asm mov dl,ah // complete I/O address + asm out dx,al // put index into control register + asm inc dx // data register is next to control + asm in al,dx // take old data - write: - asm mov cl,al // preserve old data - asm lodsw // take 2 masks from table - asm xor al,0xFF // invert mask bits - asm and al,cl // clear bits with "clr" mask - asm or al,ah // set bits with "set" mask - asm cmp dl,0xC1 // special case? - asm jne std2 // no: standard job, otherwise... - asm dec dx // data out reg shares address with index - std2: - asm out dx,al // write new value to register - asm jmp s + write: + asm mov cl,al // preserve old data + asm lodsw // take 2 masks from table + asm xor al,0xFF // invert mask bits + asm and al,cl // clear bits with "clr" mask + asm or al,ah // set bits with "set" mask + asm cmp dl,0xC1 // special case? + asm jne std2 // no: standard job, otherwise... + asm dec dx // data out reg shares address with index + std2: + asm out dx,al // write new value to register + asm jmp s - single: // read address in al, write address in ah - asm mov dl,al // complete I/O read address - asm in al,dx // take old data - asm mov dl,ah // complete I/O write address - asm jmp write // continue standard routine + single: // read address in al, write address in ah + asm mov dl,al // complete I/O read address + asm in al,dx // take old data + asm mov dl,ah // complete I/O write address + asm jmp write // continue standard routine - xit: - */ + xit: + */ warning("STUB: VGA::Setup"); } -int VGA::SetMode(int mode) -{ -/* - Clear(); - // get current mode - asm mov ah,0x0F - Video(); // BIOS video service - asm xor ah,ah - asm push ax +int VGA::SetMode(int mode) { + /* + Clear(); + // get current mode + asm mov ah,0x0F + Video(); // BIOS video service + asm xor ah,ah + asm push ax - // wait for v-retrace - WaitVR(); + // wait for v-retrace + WaitVR(); - // set mode - asm xor ah,ah - asm mov al,byte ptr mode - Video(); // BIOS video service - SetStatAdr(); - // return previous mode - asm pop ax - return _AX; - */ - warning("STUB: VGA::SetMode"); + // set mode + asm xor ah,ah + asm mov al,byte ptr mode + Video(); // BIOS video service + SetStatAdr(); + // return previous mode + asm pop ax + return _AX; + */ + warning("STUB: VGA::SetMode"); return 0; } -void VGA::GetColors(DAC * tab) -{ -/* - asm cld - asm les di,tab // color table - asm mov dx,0x3C7 // PEL address read mode register - asm xor al,al // start from address 0 - asm out dx,al // put address - asm mov cx,256*3 // # of colors - asm mov dl,0xC9 // PEL data register +void VGA::GetColors(DAC *tab) { + /* + asm cld + asm les di,tab // color table + asm mov dx,0x3C7 // PEL address read mode register + asm xor al,al // start from address 0 + asm out dx,al // put address + asm mov cx,256*3 // # of colors + asm mov dl,0xC9 // PEL data register -// asm rep insb // very fast! + // asm rep insb // very fast! - gc: // much slower: - asm in al,dx // take 1 color - asm jmp sto // little delay - sto: - asm stosb // store 1 color - asm loop gc // next one? - */ + gc: // much slower: + asm in al,dx // take 1 color + asm jmp sto // little delay + sto: + asm stosb // store 1 color + asm loop gc // next one? + */ warning("STUB: VGA::GetColors"); } -void VGA::SetColors(DAC * tab, int lum) -{ -/* - DAC * des = NewColors; - asm push ds +void VGA::SetColors(DAC *tab, int lum) { + /* + DAC * des = NewColors; + asm push ds - asm les di,des - asm lds si,tab - asm mov cx,256*3 - asm xor bx,bx - asm mov dx,lum + asm les di,des + asm lds si,tab + asm mov cx,256*3 + asm xor bx,bx + asm mov dx,lum - copcol: - asm mov al,[si+bx] - asm mul dl - asm shr ax,6 - asm mov es:[di+bx],al - asm inc bx - asm cmp bx,cx - asm jb copcol + copcol: + asm mov al,[si+bx] + asm mul dl + asm shr ax,6 + asm mov es:[di+bx],al + asm inc bx + asm cmp bx,cx + asm jb copcol - asm pop ds + asm pop ds - if (Mono) - { - asm add cx,di - mono: - asm xor dx,dx - asm mov al,77 // 30% R - asm mul byte ptr es:[di].0 - asm add dx,ax - asm mov al,151 // 59% G - asm mul byte ptr es:[di].1 - asm add dx,ax - asm mov al,28 // 11% B - asm mul byte ptr es:[di].2 - asm add dx,ax + if (Mono) + { + asm add cx,di + mono: + asm xor dx,dx + asm mov al,77 // 30% R + asm mul byte ptr es:[di].0 + asm add dx,ax + asm mov al,151 // 59% G + asm mul byte ptr es:[di].1 + asm add dx,ax + asm mov al,28 // 11% B + asm mul byte ptr es:[di].2 + asm add dx,ax - asm mov es:[di].0,dh - asm mov es:[di].1,dh - asm mov es:[di].2,dh + asm mov es:[di].0,dh + asm mov es:[di].1,dh + asm mov es:[di].2,dh - asm add di,3 - asm cmp di,cx - asm jb mono - } + asm add di,3 + asm cmp di,cx + asm jb mono + } + */ + SetPal = true; + warning("STUB: VGA::SetColors"); +} + + +void VGA::SetColors(void) { + memset(NewColors, 0, PAL_SIZ); + UpdateColors(); +} + + +void VGA::Sunrise(DAC *tab) { + for (int i = 0; i <= 64; i += FADE_STEP) { + SetColors(tab, i); + WaitVR(); + UpdateColors(); + } +} + + +void VGA::Sunset(void) { + DAC tab[256]; + GetColors(tab); + for (int i = 64; i >= 0; i -= FADE_STEP) { + SetColors(tab, i); + WaitVR(); + UpdateColors(); + } +} + + +void VGA::Show(void) { + SPRITE *spr = ShowQ.First(); + + for (spr = ShowQ.First(); spr; spr = spr->Next) + spr->Show(); + Update(); + for (spr = ShowQ.First(); spr; spr = spr->Next) + spr->Hide(); + + ++ FrmCnt; +} + + +void VGA::UpdateColors(void) { + /* + DAC * tab = NewColors; + + asm push ds + asm cld + asm lds si,tab // color table + asm mov dx,0x3C8 // PEL address write mode register + asm xor al,al // start from address 0 + asm out dx,al // put address + asm mov cx,256*3 // # of colors + asm mov dl,0xC9 // PEL data register + + // asm rep outsb // very fast! + + // the slower version of above: + sc: + asm lodsb // take 1/3 color + asm out dx,al // put 1/3 color + asm jmp loop // little delay + loop: + asm loop sc // next one? + + + asm pop ds + */ + warning("STUB: VGA::UpdateColors"); +} + + +void VGA::Update(void) { + /* + uint8 * p = Page[1]; + Page[1] = Page[0]; + Page[0] = p; + + asm mov dx,VGACRT_ + asm mov al,0x0D + asm mov ah,byte ptr p + asm out dx,ax + asm dec al + asm mov ah,byte ptr p+1 + asm out dx,ax */ - SetPal = true; - warning("STUB: VGA::SetColors"); + if (! SpeedTest) WaitVR(); + + if (SetPal) { + UpdateColors(); + SetPal = false; + } + warning("STUB: VGA::Update"); } -void VGA::SetColors (void) -{ - memset(NewColors, 0, PAL_SIZ); - UpdateColors(); +void VGA::Clear(uint8 color) { + /* + uint8 * a = (uint8 *) MK_FP(SCR_SEG, 0); + + asm mov dx,VGASEQ_ + asm mov ax,0x0F02 // map mask register - enable all planes + asm out dx,ax + asm les di,a + asm cld + + asm mov cx,0xFFFF + asm mov al,color + asm rep stosb + asm stosb + */ + warning("STUB: VGA::Clear"); } -void VGA::Sunrise (DAC * tab) -{ - int i; - for (i = 0; i <= 64; i += FADE_STEP) - { - SetColors(tab, i); - WaitVR(); - UpdateColors(); - } -} +void VGA::CopyPage(uint16 d, uint16 s) { + /* + uint8 * S = Page[s & 3], * D = Page[d & 3]; + asm mov dx,VGAGRA_ + asm mov al,0x05 // R/W mode + asm out dx,al + asm inc dx + asm in al,dx + asm and al,0xF4 + asm push ax + asm push dx + asm or al,0x01 + asm out dx,al -void VGA::Sunset (void) -{ - DAC tab[256]; - int i; - GetColors(tab); - for (i = 64; i >= 0; i -= FADE_STEP) - { - SetColors(tab, i); - WaitVR(); - UpdateColors(); - } -} + asm mov dx,VGASEQ_ + asm mov ax,0x0F02 // map mask register - enable all planes + asm out dx,ax + asm push ds -void VGA::Show (void) -{ - SPRITE * spr = ShowQ.First(); + asm les di,D + asm lds si,S + asm cld + asm mov cx,0x4000 + asm rep movsb - for (spr = ShowQ.First(); spr; spr = spr->Next) spr->Show(); - Update(); - for (spr = ShowQ.First(); spr; spr = spr->Next) spr->Hide(); + asm pop ds - ++ FrmCnt; -} - - -void VGA::UpdateColors(void) -{ -/* - DAC * tab = NewColors; - - asm push ds - asm cld - asm lds si,tab // color table - asm mov dx,0x3C8 // PEL address write mode register - asm xor al,al // start from address 0 - asm out dx,al // put address - asm mov cx,256*3 // # of colors - asm mov dl,0xC9 // PEL data register - -// asm rep outsb // very fast! - - // the slower version of above: - sc: - asm lodsb // take 1/3 color - asm out dx,al // put 1/3 color - asm jmp loop // little delay - loop: - asm loop sc // next one? - - - asm pop ds - */ - warning("STUB: VGA::UpdateColors"); -} - - -void VGA::Update(void) -{ -/* - uint8 * p = Page[1]; - Page[1] = Page[0]; - Page[0] = p; - - asm mov dx,VGACRT_ - asm mov al,0x0D - asm mov ah,byte ptr p - asm out dx,ax - asm dec al - asm mov ah,byte ptr p+1 - asm out dx,ax -*/ - if (! SpeedTest) WaitVR(); - - if (SetPal) - { - UpdateColors(); - SetPal = false; - } - warning("STUB: VGA::Update"); -} - - -void VGA::Clear(uint8 color) -{ -/* - uint8 * a = (uint8 *) MK_FP(SCR_SEG, 0); - - asm mov dx,VGASEQ_ - asm mov ax,0x0F02 // map mask register - enable all planes - asm out dx,ax - asm les di,a - asm cld - - asm mov cx,0xFFFF - asm mov al,color - asm rep stosb - asm stosb - */ - warning("STUB: VGA::Clear"); -} - - -void VGA::CopyPage(uint16 d, uint16 s) -{ -/* - uint8 * S = Page[s & 3], * D = Page[d & 3]; - - asm mov dx,VGAGRA_ - asm mov al,0x05 // R/W mode - asm out dx,al - asm inc dx - asm in al,dx - asm and al,0xF4 - asm push ax - asm push dx - asm or al,0x01 - asm out dx,al - - asm mov dx,VGASEQ_ - asm mov ax,0x0F02 // map mask register - enable all planes - asm out dx,ax - - asm push ds - - asm les di,D - asm lds si,S - asm cld - asm mov cx,0x4000 - asm rep movsb - - asm pop ds - - asm pop dx - asm pop ax - asm out dx,al // end of copy mode - */ - warning("STUB: VGA::CopyPage"); + asm pop dx + asm pop ax + asm out dx,al // end of copy mode + */ + warning("STUB: VGA::CopyPage"); } //-------------------------------------------------------------------------- -void BITMAP::XShow(int x, int y) -{ -/* - uint8 rmsk = x % 4, - mask = 1 << rmsk, - * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; - uint8 * m = (char *) M; - uint8 * v = V; +void BITMAP::XShow(int x, int y) { + /* + uint8 rmsk = x % 4, + mask = 1 << rmsk, + * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; + uint8 * m = (char *) M; + uint8 * v = V; - asm push bx - asm push si - asm push ds + asm push bx + asm push si + asm push ds - asm cld - asm les di,scr - asm lds si,v - asm mov bx,m + asm cld + asm les di,scr + asm lds si,v + asm mov bx,m - asm mov al,0x02 // map mask register - asm mov ah,mask + asm mov al,0x02 // map mask register + asm mov ah,mask - plane: - // enable output plane - asm mov dx,VGASEQ_ - asm out dx,ax - asm push ax + plane: + // enable output plane + asm mov dx,VGASEQ_ + asm out dx,ax + asm push ax - // select input plane - asm mov dx,VGAGRA_ - asm mov al,0x04 // read map select register - asm mov ah,rmsk - asm out dx,ax + // select input plane + asm mov dx,VGAGRA_ + asm mov al,0x04 // read map select register + asm mov ah,rmsk + asm out dx,ax - asm push di + asm push di - block: - asm lodsw - asm mov cx,ax - asm and ch,0x3F - asm test ah,0xC0 - asm jz endpl - asm jns skip - asm jnp incsi // replicate? - asm add si,cx // skip over data block - asm dec si // fix it before following inc + block: + asm lodsw + asm mov cx,ax + asm and ch,0x3F + asm test ah,0xC0 + asm jz endpl + asm jns skip + asm jnp incsi // replicate? + asm add si,cx // skip over data block + asm dec si // fix it before following inc - incsi: - asm inc si - tint: - asm mov al,es:[di] - //----------------------------------------------- - // asm xlat ss:0 // unsupported with BASM! - __emit__(0x36, 0xD7); // this stands for above! - //----------------------------------------------- - asm stosb - asm loop tint - asm jmp block + incsi: + asm inc si + tint: + asm mov al,es:[di] + //----------------------------------------------- + // asm xlat ss:0 // unsupported with BASM! + __emit__(0x36, 0xD7); // this stands for above! + //----------------------------------------------- + asm stosb + asm loop tint + asm jmp block - skip: - asm add di,cx - asm jmp block + skip: + asm add di,cx + asm jmp block - endpl: - asm pop di - asm pop ax - asm inc rmsk - asm shl ah,1 - asm test ah,0x10 - asm jz x_chk - asm mov ah,0x01 - asm mov rmsk,0 - asm inc di - x_chk: - asm cmp ah,mask - asm jne plane - asm pop ds - asm pop si - asm pop bx - */ + endpl: + asm pop di + asm pop ax + asm inc rmsk + asm shl ah,1 + asm test ah,0x10 + asm jz x_chk + asm mov ah,0x01 + asm mov rmsk,0 + asm inc di + x_chk: + asm cmp ah,mask + asm jne plane + asm pop ds + asm pop si + asm pop bx + */ warning("STUB: BITMAP::XShow"); } -void BITMAP::Show(int x, int y) -{ +void BITMAP::Show(int x, int y) { /* - uint8 mask = 1 << (x & 3), - * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); - uint8 * v = V; + uint8 mask = 1 << (x & 3), + * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); + uint8 * v = V; - asm push ds // preserve DS + asm push ds // preserve DS - asm cld // normal direction - asm les di,scr // screen address - asm lds si,v // picture address - asm mov dx,VGASEQ_ // VGA reg - asm mov al,0x02 - asm mov ah,mask + asm cld // normal direction + asm les di,scr // screen address + asm lds si,v // picture address + asm mov dx,VGASEQ_ // VGA reg + asm mov al,0x02 + asm mov ah,mask - plane: - asm out dx,ax - asm push ax - asm push di + plane: + asm out dx,ax + asm push ax + asm push di - block: - asm mov cx,[si] // with ADD faster then LODSW - asm add si,2 - asm test ch,0xC0 - asm jns skip // 1 (SKP) or 0 (EOI) - asm jpo repeat // 2 (REP) + block: + asm mov cx,[si] // with ADD faster then LODSW + asm add si,2 + asm test ch,0xC0 + asm jns skip // 1 (SKP) or 0 (EOI) + asm jpo repeat // 2 (REP) - copy: // 3 (CPY) - asm and ch,0x3F - asm shr cx,1 - asm rep movsw - asm jnc block - asm movsb - asm jmp block + copy: // 3 (CPY) + asm and ch,0x3F + asm shr cx,1 + asm rep movsw + asm jnc block + asm movsb + asm jmp block - repeat: - asm and ch,0x3F - asm mov al,[si] - asm inc si - asm mov ah,al - asm shr cx,1 - asm rep stosw - asm jnc block - asm mov es:[di],al - asm inc di - asm jmp block + repeat: + asm and ch,0x3F + asm mov al,[si] + asm inc si + asm mov ah,al + asm shr cx,1 + asm rep stosw + asm jnc block + asm mov es:[di],al + asm inc di + asm jmp block - skip: - asm jz endpl - asm and ch,0x3F - asm add di,cx - asm jmp block + skip: + asm jz endpl + asm and ch,0x3F + asm add di,cx + asm jmp block - endpl: - asm pop di - asm pop ax - asm shl ah,1 - asm test ah,0x10 - asm jz x_chk - asm mov ah,0x01 - asm inc di - x_chk: - asm cmp ah,mask - asm jne plane - asm pop ds + endpl: + asm pop di + asm pop ax + asm shl ah,1 + asm test ah,0x10 + asm jz x_chk + asm mov ah,0x01 + asm inc di + x_chk: + asm cmp ah,mask + asm jne plane + asm pop ds */ warning("STUB: BITMAP::Show"); } -void BITMAP::Hide(int x, int y) -{ -/* - uint8 * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; - uint16 d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); - HideDesc * b = B; - uint16 extra = ((x & 3) != 0); - uint16 h = H; +void BITMAP::Hide(int x, int y) { + /* + uint8 * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; + uint16 d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); + HideDesc * b = B; + uint16 extra = ((x & 3) != 0); + uint16 h = H; -// asm push bx - asm push si - asm push ds + // asm push bx + asm push si + asm push ds - asm cld - asm les di,scr - asm mov si,di - asm add si,d // take bytes from background page - asm lds bx,b + asm cld + asm les di,scr + asm mov si,di + asm add si,d // take bytes from background page + asm lds bx,b - asm mov dx,VGAGRA_ - asm mov al,0x05 // R/W mode - asm out dx,al - asm inc dx - asm in al,dx - asm and al,0xF4 - asm push ax - asm push dx - asm or al,0x01 - asm out dx,al + asm mov dx,VGAGRA_ + asm mov al,0x05 // R/W mode + asm out dx,al + asm inc dx + asm in al,dx + asm and al,0xF4 + asm push ax + asm push dx + asm or al,0x01 + asm out dx,al - asm mov dx,VGASEQ_ - asm mov ax,0x0F02 // enable all planes - asm out dx,ax + asm mov dx,VGASEQ_ + asm mov ax,0x0F02 // enable all planes + asm out dx,ax - asm mov dx,ds // save DS + asm mov dx,ds // save DS - row: -// skip block - asm mov cx,[bx] - asm add si,cx - asm add di,cx - asm mov cx,[bx+2] - asm add bx,4 - asm add cx,extra + row: + // skip block + asm mov cx,[bx] + asm add si,cx + asm add di,cx + asm mov cx,[bx+2] + asm add bx,4 + asm add cx,extra - asm push es - asm pop ds // set DS to video seg - asm rep movsb // move bytes fast - asm sub si,extra - asm sub di,extra - asm mov ds,dx // restore DS + asm push es + asm pop ds // set DS to video seg + asm rep movsb // move bytes fast + asm sub si,extra + asm sub di,extra + asm mov ds,dx // restore DS - asm dec h - asm jnz row + asm dec h + asm jnz row - asm pop dx - asm pop ax - asm out dx,al // end of copy mode + asm pop dx + asm pop ax + asm out dx,al // end of copy mode - asm pop ds - asm pop si -// asm pop bx -*/ + asm pop ds + asm pop si + // asm pop bx + */ warning("STUB: BITMAP::Hide"); } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index f1a4b498c40..810e781808f 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -25,295 +25,290 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __VGA13H__ -#define __VGA13H__ +#ifndef __VGA13H__ +#define __VGA13H__ -#include "cge/general.h" -#include -//#include -#include "cge/bitmap.h" -#include "cge/snail.h" +#include "cge/general.h" +#include +#include "cge/bitmap.h" +#include "cge/snail.h" namespace CGE { -#define TMR_RATE1 16 -#define TMR_RATE2 4 -#define TMR_RATE (TMR_RATE1*TMR_RATE2) +#define TMR_RATE1 16 +#define TMR_RATE2 4 +#define TMR_RATE (TMR_RATE1 * TMR_RATE2) -#define MAX_NAME 20 -#define VIDEO 0x10 +#define MAX_NAME 20 +#define VIDEO 0x10 -#define NO_CLEAR 0x80 -#define TEXT_MODE 0x03 -#define M13H 0x13 +#define NO_CLEAR 0x80 +#define TEXT_MODE 0x03 +#define M13H 0x13 -#ifndef SCR_WID - #define SCR_WID 320 +#ifndef SCR_WID +#define SCR_WID 320 #endif -#ifndef SCR_HIG - #define SCR_HIG 200 +#ifndef SCR_HIG +#define SCR_HIG 200 #endif #if 0 - #define LIGHT 0xFF - #define DARK 0x00 - #define DGRAY 0xF6 - #define GRAY 0xFC - #define LGRAY 0xFF +#define LIGHT 0xFF +#define DARK 0x00 +#define DGRAY 0xF6 +#define GRAY 0xFC +#define LGRAY 0xFF #else - #define LIGHT 0xFF - #define DARK 207 - #define DGRAY 225 /*219*/ - #define GRAY 231 - #define LGRAY 237 +#define LIGHT 0xFF +#define DARK 207 +#define DGRAY 225 /*219*/ +#define GRAY 231 +#define LGRAY 237 #endif -#define NO_SEQ (-1) -#define NO_PTR ((uint8)-1) +#define NO_SEQ (-1) +#define NO_PTR ((uint8)-1) -#define SPR_EXT ".SPR" +#define SPR_EXT ".SPR" -#define IsFile(s) (access(s,0)==0) -#define IsWrit(s) (access(s,2)==0) +#define IsFile(s) (access(s, 0) == 0) +#define IsWrit(s) (access(s, 2) == 0) -typedef struct { uint16 r : 2; uint16 R : 6; - uint16 g : 2; uint16 G : 6; - uint16 b : 2; uint16 B : 6; - } RGB; +typedef struct { + uint16 r : 2; + uint16 R : 6; + uint16 g : 2; + uint16 G : 6; + uint16 b : 2; + uint16 B : 6; +} RGB; -typedef union { - DAC dac; - RGB rgb; - } TRGB; +typedef union { + DAC dac; + RGB rgb; +} TRGB; -typedef struct { uint8 idx, adr; uint8 clr, set; } VgaRegBlk; +typedef struct { + uint8 idx, adr; + uint8 clr, set; +} VgaRegBlk; -typedef struct { uint8 Now, Next; signed char Dx, Dy; int Dly; } SEQ; +typedef struct { + uint8 Now, Next; + signed char Dx, Dy; + int Dly; +} SEQ; -extern SEQ Seq1[]; -extern SEQ Seq2[]; -//extern SEQ * Compass[]; -//extern SEQ TurnToS[]; +extern SEQ Seq1[]; +extern SEQ Seq2[]; +//extern SEQ * Compass[]; +//extern SEQ TurnToS[]; -#define PAL_CNT 256 -#define PAL_SIZ (PAL_CNT*sizeof(DAC)) - -#define VGAATR_ 0x3C0 -#define VGAMIw_ 0x3C0 -#define VGASEQ_ 0x3C4 -#define VGAMIr_ 0x3CC -#define VGAGRA_ 0x3CE -#define VGACRT_ 0x3D4 -#define VGAST1_ 0x3DA -#define VGAATR (VGAATR_ & 0xFF) -#define VGAMIw (VGAMIw_ & 0xFF) -#define VGASEQ (VGASEQ_ & 0xFF) -#define VGAMIr (VGAMIr_ & 0xFF) -#define VGAGRA (VGAGRA_ & 0xFF) -#define VGACRT (VGACRT_ & 0xFF) -#define VGAST1 (VGAST1_ & 0xFF) +#define PAL_CNT 256 +#define PAL_SIZ (PAL_CNT * sizeof(DAC)) +#define VGAATR_ 0x3C0 +#define VGAMIw_ 0x3C0 +#define VGASEQ_ 0x3C4 +#define VGAMIr_ 0x3CC +#define VGAGRA_ 0x3CE +#define VGACRT_ 0x3D4 +#define VGAST1_ 0x3DA +#define VGAATR (VGAATR_ & 0xFF) +#define VGAMIw (VGAMIw_ & 0xFF) +#define VGASEQ (VGASEQ_ & 0xFF) +#define VGAMIr (VGAMIr_ & 0xFF) +#define VGAGRA (VGAGRA_ & 0xFF) +#define VGACRT (VGACRT_ & 0xFF) +#define VGAST1 (VGAST1_ & 0xFF) - - - - -class HEART : public ENGINE -{ - friend ENGINE; +class HEART : public ENGINE { + friend ENGINE; public: - static bool Enable; - static uint16 * XTimer; - static void SetXTimer (uint16 * ptr); - static void SetXTimer (uint16 * ptr, uint16 time); - HEART (void); + static bool Enable; + static uint16 *XTimer; + static void SetXTimer(uint16 *ptr); + static void SetXTimer(uint16 *ptr, uint16 time); + HEART(void); }; - - - -class SPREXT -{ +class SPREXT { public: - int x0, y0; - int x1, y1; - BMP_PTR b0, b1; - BMP_PTR * ShpList; - SEQ * Seq; - char * Name; - SNAIL::COM * Near, * Take; - SPREXT (void) : - x0(0), y0(0), - x1(0), y1(0), - b0(NULL), b1(NULL), - ShpList(NULL), Seq(NULL), - Name(NULL), Near(NULL), Take(NULL) - {} + int x0, y0; + int x1, y1; + BMP_PTR b0, b1; + BMP_PTR *ShpList; + SEQ *Seq; + char *Name; + SNAIL::COM *Near, * Take; + SPREXT(void) : + x0(0), y0(0), + x1(0), y1(0), + b0(NULL), b1(NULL), + ShpList(NULL), Seq(NULL), + Name(NULL), Near(NULL), Take(NULL) + {} }; - - -class SPRITE -{ +class SPRITE { protected: - SPREXT * Ext; + SPREXT *Ext; public: - int Ref; - signed char Cave; - struct FLAGS { uint16 Hide : 1; // general visibility switch - uint16 Near : 1; // Near action lock - uint16 Drag : 1; // sprite is moveable - uint16 Hold : 1; // sprite is held with mouse - uint16 ____ : 1; // intrrupt driven animation - uint16 Slav : 1; // slave object - uint16 Syst : 1; // system object - uint16 Kill : 1; // dispose memory after remove - uint16 Xlat : 1; // 2nd way display: xlat table - uint16 Port : 1; // portable - uint16 Kept : 1; // kept in pocket - uint16 East : 1; // talk to east (in opposite to west) - uint16 Shad : 1; // shadow - uint16 Back : 1; // 'send to background' request - uint16 BDel : 1; // delete bitmaps in ~SPRITE - uint16 Tran : 1; // transparent (untouchable) - } Flags; - int X, Y; - signed char Z; - uint16 W, H; - uint16 Time; - uint8 NearPtr, TakePtr; - int SeqPtr; - int ShpCnt; - char File[MAXFILE]; - SPRITE * Prev, * Next; - bool Works (SPRITE * spr); - bool SeqTest (int n); - inline bool Active (void) { return Ext != NULL; } - SPRITE (BMP_PTR * shp); - virtual ~SPRITE (void); - BMP_PTR Shp (void); - BMP_PTR * SetShapeList (BMP_PTR * shp); - void MoveShapes (uint8 * buf); - SPRITE * Expand (void); - SPRITE * Contract (void); - SPRITE * BackShow (bool fast = false); - void SetName(char * n); - inline char * Name(void) { return (Ext) ? Ext->Name : NULL; } - void Goto (int x, int y); - void Center (void); - void Show (void); - void Hide (void); - BMP_PTR Ghost (void); - void Show (uint16 pg); - void MakeXlat (uint8 * x); - void KillXlat (void); - void Step (int nr = -1); - SEQ * SetSeq (SEQ * seq); - SNAIL::COM * SnList(SNLIST type); - virtual void Touch (uint16 mask, int x, int y); - virtual void Tick (void); + int Ref; + signed char Cave; + struct FLAGS { + uint16 Hide : 1; // general visibility switch + uint16 Near : 1; // Near action lock + uint16 Drag : 1; // sprite is moveable + uint16 Hold : 1; // sprite is held with mouse + uint16 ____ : 1; // intrrupt driven animation + uint16 Slav : 1; // slave object + uint16 Syst : 1; // system object + uint16 Kill : 1; // dispose memory after remove + uint16 Xlat : 1; // 2nd way display: xlat table + uint16 Port : 1; // portable + uint16 Kept : 1; // kept in pocket + uint16 East : 1; // talk to east (in opposite to west) + uint16 Shad : 1; // shadow + uint16 Back : 1; // 'send to background' request + uint16 BDel : 1; // delete bitmaps in ~SPRITE + uint16 Tran : 1; // transparent (untouchable) + } Flags; + int X, Y; + signed char Z; + uint16 W, H; + uint16 Time; + uint8 NearPtr, TakePtr; + int SeqPtr; + int ShpCnt; + char File[MAXFILE]; + SPRITE *Prev, * Next; + bool Works(SPRITE *spr); + bool SeqTest(int n); + inline bool Active(void) { + return Ext != NULL; + } + SPRITE(BMP_PTR *shp); + virtual ~SPRITE(void); + BMP_PTR Shp(void); + BMP_PTR *SetShapeList(BMP_PTR *shp); + void MoveShapes(uint8 *buf); + SPRITE *Expand(void); + SPRITE *Contract(void); + SPRITE *BackShow(bool fast = false); + void SetName(char *n); + inline char *Name(void) { + return (Ext) ? Ext->Name : NULL; + } + void Goto(int x, int y); + void Center(void); + void Show(void); + void Hide(void); + BMP_PTR Ghost(void); + void Show(uint16 pg); + void MakeXlat(uint8 *x); + void KillXlat(void); + void Step(int nr = -1); + SEQ *SetSeq(SEQ *seq); + SNAIL::COM *SnList(SNLIST type); + virtual void Touch(uint16 mask, int x, int y); + virtual void Tick(void); }; - - - - -class QUEUE -{ - SPRITE * Head, * Tail; +class QUEUE { + SPRITE *Head, * Tail; public: - bool Show; - QUEUE (bool show = false); - ~QUEUE (void); - void Append (SPRITE * spr); - void Insert (SPRITE * spr, SPRITE * nxt); - void Insert (SPRITE * spr); - SPRITE * Remove (SPRITE * spr); - void ForAll (void (*fun)(SPRITE *)); - SPRITE * First (void) { return Head; } - SPRITE * Last (void) { return Tail; } - SPRITE * Locate (int ref); - void Clear (void); + bool Show; + QUEUE(bool show = false); + ~QUEUE(void); + void Append(SPRITE *spr); + void Insert(SPRITE *spr, SPRITE *nxt); + void Insert(SPRITE *spr); + SPRITE *Remove(SPRITE *spr); + void ForAll(void (*fun)(SPRITE *)); + SPRITE *First(void) { + return Head; + } + SPRITE *Last(void) { + return Tail; + } + SPRITE *Locate(int ref); + void Clear(void); }; - - - - -class VGA -{ - static uint16 OldMode; - static uint16 * OldScreen; - static uint16 StatAdr; - static bool SetPal; - static DAC * OldColors, * NewColors; - static int SetMode (int mode); - static void UpdateColors (void); - static void SetColors (void); - static const char * Msg; - static const char * Nam; - static void SetStatAdr (void); - static void WaitVR (bool on = true); +class VGA { + static uint16 OldMode; + static uint16 *OldScreen; + static uint16 StatAdr; + static bool SetPal; + static DAC *OldColors, * NewColors; + static int SetMode(int mode); + static void UpdateColors(void); + static void SetColors(void); + static const char *Msg; + static const char *Nam; + static void SetStatAdr(void); + static void WaitVR(bool on = true); public: - uint32 FrmCnt; - static QUEUE ShowQ, SpareQ; - static int Mono; - static uint8 * Page[4]; - VGA (int mode = M13H); - ~VGA (void); - void Setup (VgaRegBlk * vrb); - static void GetColors (DAC * tab); - static void SetColors (DAC * tab, int lum); - static void Clear (uint8 color = 0); - static void CopyPage (uint16 d, uint16 s = 3); - static void Sunrise (DAC * tab); - static void Sunset (void); - void Show (void); - void Update (void); + uint32 FrmCnt; + static QUEUE ShowQ, SpareQ; + static int Mono; + static uint8 *Page[4]; + VGA(int mode = M13H); + ~VGA(void); + void Setup(VgaRegBlk *vrb); + static void GetColors(DAC *tab); + static void SetColors(DAC *tab, int lum); + static void Clear(uint8 color = 0); + static void CopyPage(uint16 d, uint16 s = 3); + static void Sunrise(DAC *tab); + static void Sunset(void); + void Show(void); + void Update(void); }; - -DAC MkDAC (uint8 r, uint8 g, uint8 b); -RGB MkRGB (uint8 r, uint8 g, uint8 b); - - +DAC MkDAC(uint8 r, uint8 g, uint8 b); +RGB MkRGB(uint8 r, uint8 g, uint8 b); template -uint8 Closest (CBLK * pal, CBLK x) -{ - #define f(col,lum) ((((uint16)(col))<<8)/lum) - uint16 i, dif = 0xFFFF, found = 0; - uint16 L = x.R + x.G + x.B; if (! L) ++ L; - uint16 R = f(x.R, L), G = f(x.G, L), B = f(x.B, L); - for (i = 0; i < 256; i ++) - { - uint16 l = pal[i].R + pal[i].G + pal[i].B; if (! l) ++ l; - int r = f(pal[i].R, l), g = f(pal[i].G, l), b = f(pal[i].B, l); - uint16 D = ((r > R) ? (r - R) : (R - r)) + - ((g > G) ? (g - G) : (G - g)) + - ((b > B) ? (b - B) : (B - b)) + - ((l > L) ? (l - L) : (L - l)) * 10 ; +uint8 Closest(CBLK *pal, CBLK x) { +#define f(col, lum) ((((uint16)(col)) << 8) / lum) + uint16 i, dif = 0xFFFF, found = 0; + uint16 L = x.R + x.G + x.B; + if (!L) + ++L; + uint16 R = f(x.R, L), G = f(x.G, L), B = f(x.B, L); + for (i = 0; i < 256; i ++) { + uint16 l = pal[i].R + pal[i].G + pal[i].B; + if (! l) + ++l; + int r = f(pal[i].R, l), g = f(pal[i].G, l), b = f(pal[i].B, l); + uint16 D = ((r > R) ? (r - R) : (R - r)) + + ((g > G) ? (g - G) : (G - g)) + + ((b > B) ? (b - B) : (B - b)) + + ((l > L) ? (l - L) : (L - l)) * 10 ; - if (D < dif) - { - found = i; - dif = D; - if (D == 0) break; // exact! + if (D < dif) { + found = i; + dif = D; + if (D == 0) + break; // exact! + } } - } - return found; - #undef f + return found; +#undef f }; @@ -322,14 +317,14 @@ uint8 Closest (CBLK * pal, CBLK x) - char * NumStr (char * str, int num); - //static void Video (void); - uint16 * SaveScreen (void); - void RestoreScreen (uint16 * &sav); - SPRITE * SpriteAt (int x, int y); - SPRITE * Locate (int ref); +char *NumStr(char *str, int num); +//static void Video (void); +uint16 *SaveScreen(void); +void RestoreScreen(uint16 * &sav); +SPRITE *SpriteAt(int x, int y); +SPRITE *Locate(int ref); -extern bool SpeedTest; +extern bool SpeedTest; } // End if namespace CGE diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 46bb45e9c9c..a8da163b331 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -25,151 +25,131 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/vmenu.h" -#include "cge/mouse.h" -#include -//#include +#include "cge/vmenu.h" +#include "cge/mouse.h" +#include namespace CGE { -//-------------------------------------------------------------------------- -#define RELIEF 1 -#if RELIEF - #define MB_LT LGRAY - #define MB_RB DGRAY +#define RELIEF 1 +#if RELIEF +#define MB_LT LGRAY +#define MB_RB DGRAY #else - #define MB_LT DGRAY - #define MB_RB LGRAY +#define MB_LT DGRAY +#define MB_RB LGRAY #endif -MENU_BAR::MENU_BAR (uint16 w) -{ - int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h; - uint8 * p = farnew(uint8, i), * p1, * p2; +MENU_BAR::MENU_BAR(uint16 w) { + int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h; + uint8 *p = farnew(uint8, i), * p1, * p2; - memset(p+w, TRANS, i-2*w); - memset(p, MB_LT, w); - memset(p+i-w, MB_RB, w); - p1 = p; - p2 = p+i-1; - for (i = 0; i < h; i ++) - { - * p1 = MB_LT; - * p2 = MB_RB; - p1 += w; - p2 -= w; - } - TS[0] = new BITMAP(w, h, p); - SetShapeList(TS); - Flags.Slav = true; - Flags.Tran = true; - Flags.Kill = true; - Flags.BDel = true; -} - - - -//-------------------------------------------------------------------------- - -static char * vmgt; - - - -char * VMGather (CHOICE * list) -{ - CHOICE * cp; - int len = 0, h = 0; - - for (cp = list; cp->Text; cp ++) - { - len += strlen(cp->Text); - ++ h; - } - vmgt = new char[len+h]; - if (vmgt) - { - *vmgt = '\0'; - for (cp = list; cp->Text; cp ++) - { - if (*vmgt) strcat(vmgt, "|"); - strcat(vmgt, cp->Text); - ++ h; + memset(p + w, TRANS, i - 2 * w); + memset(p, MB_LT, w); + memset(p + i - w, MB_RB, w); + p1 = p; + p2 = p + i - 1; + for (i = 0; i < h; i ++) { + *p1 = MB_LT; + *p2 = MB_RB; + p1 += w; + p2 -= w; } - } - return vmgt; + TS[0] = new BITMAP(w, h, p); + SetShapeList(TS); + Flags.Slav = true; + Flags.Tran = true; + Flags.Kill = true; + Flags.BDel = true; } +static char *vmgt; -VMENU * VMENU::Addr = NULL; -int VMENU::Recent = -1; +char *VMGather(CHOICE *list) { + CHOICE *cp; + int len = 0, h = 0; - - - -VMENU::VMENU (CHOICE * list, int x, int y) -: TALK(VMGather(list), RECT), Menu(list), Bar(NULL) -{ - CHOICE * cp; - - Addr = this; - delete[] vmgt; - Items = 0; - for (cp = list; cp->Text; cp ++) ++ Items; - Flags.BDel = true; - Flags.Kill = true; - if (x < 0 || y < 0) Center(); - else Goto(x - W / 2, y - (TEXT_VM + FONT_HIG / 2)); - VGA::ShowQ.Insert(this, VGA::ShowQ.Last()); - Bar = new MENU_BAR(W - 2 * TEXT_HM); - Bar->Goto(X + TEXT_HM - MB_HM, Y + TEXT_VM - MB_VM); - VGA::ShowQ.Insert(Bar, VGA::ShowQ.Last()); -} - - - - -VMENU::~VMENU (void) -{ - Addr = NULL; -} - - - - -void VMENU::Touch (uint16 mask, int x, int y) -{ -#define h (FONT_HIG+TEXT_LS) - int n = 0; - bool ok = false; - - if (Items) - { - SPRITE::Touch(mask, x, y); - - y -= TEXT_VM-1; - //if - if (y >= 0) - { - n = y / h; - if (n < Items) ok = (x >= TEXT_HM && x < W - TEXT_HM/* && y % h < FONT_HIG*/); - else n = Items-1; + for (cp = list; cp->Text; cp ++) { + len += strlen(cp->Text); + ++h; } - - Bar->Goto(X + TEXT_HM - MB_HM, Y + TEXT_VM + n * h - MB_VM); - - if (ok && (mask & L_UP)) - { - Items = 0; - SNPOST_(SNKILL, -1, 0, this); - Menu[Recent = n].Proc(); + vmgt = new char[len + h]; + if (vmgt) { + *vmgt = '\0'; + for (cp = list; cp->Text; cp ++) { + if (*vmgt) + strcat(vmgt, "|"); + strcat(vmgt, cp->Text); + ++ h; + } + } + return vmgt; +} + + +VMENU *VMENU::Addr = NULL; +int VMENU::Recent = -1; + + +VMENU::VMENU(CHOICE *list, int x, int y) + : TALK(VMGather(list), RECT), Menu(list), Bar(NULL) { + CHOICE *cp; + + Addr = this; + delete[] vmgt; + Items = 0; + for (cp = list; cp->Text; cp ++) + ++Items; + Flags.BDel = true; + Flags.Kill = true; + if (x < 0 || y < 0) + Center(); + else + Goto(x - W / 2, y - (TEXT_VM + FONT_HIG / 2)); + VGA::ShowQ.Insert(this, VGA::ShowQ.Last()); + Bar = new MENU_BAR(W - 2 * TEXT_HM); + Bar->Goto(X + TEXT_HM - MB_HM, Y + TEXT_VM - MB_VM); + VGA::ShowQ.Insert(Bar, VGA::ShowQ.Last()); +} + + +VMENU::~VMENU(void) { + Addr = NULL; +} + + +void VMENU::Touch(uint16 mask, int x, int y) { +#define h (FONT_HIG + TEXT_LS) + int n = 0; + bool ok = false; + + if (Items) { + SPRITE::Touch(mask, x, y); + + y -= TEXT_VM - 1; + //if + if (y >= 0) { + n = y / h; + if (n < Items) + ok = (x >= TEXT_HM && x < W - TEXT_HM/* && y % h < FONT_HIG*/); + else + n = Items - 1; + } + + Bar->Goto(X + TEXT_HM - MB_HM, Y + TEXT_VM + n * h - MB_VM); + + if (ok && (mask & L_UP)) { + Items = 0; + SNPOST_(SNKILL, -1, 0, this); + Menu[Recent = n].Proc(); + } } - } #undef h } diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index cdbabf9966f..ecec9d51b58 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -25,38 +25,39 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __VMENU__ -#define __VMENU__ +#ifndef __VMENU__ +#define __VMENU__ -#include "cge/talk.h" +#include "cge/talk.h" namespace CGE { -#define MB_VM 1 -#define MB_HM 3 +#define MB_VM 1 +#define MB_HM 3 -typedef struct { char * Text; void (* Proc)(void); } CHOICE; +typedef struct { + char *Text; + void (* Proc)(void); +} CHOICE; -class MENU_BAR : public TALK -{ +class MENU_BAR : public TALK { public: - MENU_BAR (uint16 w); + MENU_BAR(uint16 w); }; -class VMENU : public TALK -{ - uint16 Items; - CHOICE * Menu; +class VMENU : public TALK { + uint16 Items; + CHOICE *Menu; public: - static VMENU * Addr; - static int Recent; - MENU_BAR * Bar; - VMENU (CHOICE * list, int x, int y); - ~VMENU (void); - void Touch (uint16 mask, int x, int y); + static VMENU *Addr; + static int Recent; + MENU_BAR *Bar; + VMENU(CHOICE *list, int x, int y); + ~VMENU(void); + void Touch(uint16 mask, int x, int y); }; } // End of namespace CGE diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 4f39cd61864..46282d2bbe6 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -35,68 +35,55 @@ namespace CGE { #ifdef VOL_UPD -BTFILE VFILE::Cat(CAT_NAME, UPD, CRP); -VOLBASE DAT::File(DAT_NAME, UPD, CRP); +BTFILE VFILE::Cat(CAT_NAME, UPD, CRP); +VOLBASE DAT::File(DAT_NAME, UPD, CRP); #else -BTFILE VFILE::Cat(CAT_NAME, REA, CRP); -VOLBASE DAT::File(DAT_NAME, REA, CRP); +BTFILE VFILE::Cat(CAT_NAME, REA, CRP); +VOLBASE DAT::File(DAT_NAME, REA, CRP); #endif -DAT VFILE::Dat; -VFILE * VFILE::Recent = NULL; +DAT VFILE::Dat; +VFILE *VFILE::Recent = NULL; - - - -VFILE::VFILE (const char * name, IOMODE mode) -: IOBUF(mode) -{ - if (mode == REA) - { - if (Dat.File.Error || Cat.Error) - error("Bad volume data"); - BT_KEYPACK * kp = Cat.Find(name); - if (scumm_stricmp(kp->Key, name) != 0) Error = 1; - EndMark = (BufMark = BegMark = kp->Mark) + kp->Size; - } - #ifdef VOL_UPD - else Make(name); - #endif +VFILE::VFILE(const char *name, IOMODE mode) + : IOBUF(mode) { + if (mode == REA) { + if (Dat.File.Error || Cat.Error) + error("Bad volume data"); + BT_KEYPACK *kp = Cat.Find(name); + if (scumm_stricmp(kp->Key, name) != 0) + Error = 1; + EndMark = (BufMark = BegMark = kp->Mark) + kp->Size; + } +#ifdef VOL_UPD + else + Make(name); +#endif } - - - -VFILE::~VFILE (void) -{ - if (Recent == this) Recent = NULL; +VFILE::~VFILE(void) { + if (Recent == this) + Recent = NULL; } - - - -bool VFILE::Exist (const char * name) -{ - return scumm_stricmp(Cat.Find(name)->Key, name) == 0; +bool VFILE::Exist(const char *name) { + return scumm_stricmp(Cat.Find(name)->Key, name) == 0; } - - -void VFILE::ReadBuff (void) -{ - if (Recent != this) - { - Dat.File.Seek(BufMark + Lim); - Recent = this; - } - BufMark = Dat.File.Mark(); - long n = EndMark - BufMark; - if (n > IOBUF_SIZE) n = IOBUF_SIZE; - Lim = Dat.File.Read(Buff, (uint16) n); - Ptr = 0; +void VFILE::ReadBuff(void) { + if (Recent != this) { + Dat.File.Seek(BufMark + Lim); + Recent = this; + } + BufMark = Dat.File.Mark(); + long n = EndMark - BufMark; + if (n > IOBUF_SIZE) + n = IOBUF_SIZE; + Lim = Dat.File.Read(Buff, (uint16) n); + Ptr = 0; } } // End of namespace CGE diff --git a/engines/cge/vol.h b/engines/cge/vol.h index 421bd7593cd..ea82e8bf6a5 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -25,66 +25,64 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __VOL__ -#define __VOL__ +#ifndef __VOL__ +#define __VOL__ - -//#include -#include "cge/btfile.h" -#include "cge/cfile.h" +#include "cge/btfile.h" +#include "cge/cfile.h" namespace CGE { -#define CAT_NAME "VOL.CAT" -#define DAT_NAME "VOL.DAT" +#define CAT_NAME "VOL.CAT" +#define DAT_NAME "VOL.DAT" -#ifndef CRP - #define CRP XCrypt +#ifndef CRP +#define CRP XCrypt #endif -#define XMASK 0xA5 +#define XMASK 0xA5 -#ifdef VOL_UPD -#define VOLBASE IOHAND +#ifdef VOL_UPD +#define VOLBASE IOHAND #else -#define VOLBASE CFILE +#define VOLBASE CFILE #endif - -class DAT -{ - friend class VFILE; - static VOLBASE File; +class DAT { + friend class VFILE; + static VOLBASE File; public: - static bool Append (uint8 * buf, uint16 len); - static bool Write (CFILE& f); - static bool Read (long org, uint16 len, uint8 * buf); + static bool Append(uint8 *buf, uint16 len); + static bool Write(CFILE &f); + static bool Read(long org, uint16 len, uint8 *buf); }; - - - - - -class VFILE : public IOBUF -{ - static DAT Dat; - static BTFILE Cat; - static VFILE * Recent; - long BegMark, EndMark; - void ReadBuff (void); - void WriteBuff (void) { } - void Make(const char * fspec); +class VFILE : public IOBUF { + static DAT Dat; + static BTFILE Cat; + static VFILE *Recent; + long BegMark, EndMark; + void ReadBuff(void); + void WriteBuff(void) { } + void Make(const char *fspec); public: - VFILE (const char * name, IOMODE mode = REA); - ~VFILE (void); - static bool Exist (const char * name); - static const char * Next (void); - long Mark (void) { return (BufMark+Ptr) - BegMark; } - long Size (void) { return EndMark - BegMark; } - long Seek (long pos) { Recent = NULL; Lim = 0; return (BufMark = BegMark+pos); } + VFILE(const char *name, IOMODE mode = REA); + ~VFILE(void); + static bool Exist(const char *name); + static const char *Next(void); + long Mark(void) { + return (BufMark + Ptr) - BegMark; + } + long Size(void) { + return EndMark - BegMark; + } + long Seek(long pos) { + Recent = NULL; + Lim = 0; + return (BufMark = BegMark + pos); + } }; diff --git a/engines/cge/wav.h b/engines/cge/wav.h index a8da4f9e722..6d46769cf99 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -25,117 +25,128 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __WAV__ -#define __WAV__ +#ifndef __WAV__ +#define __WAV__ -#include "cge/general.h" -#include +#include "cge/general.h" +#include namespace CGE { -#define WAVE_FORMAT_PCM 0x0001 -#define IBM_FORMAT_MULAW 0x0101 -#define IBM_FORMAT_ALAW 0x0102 -#define IBM_FORMAT_ADPCM 0x0103 +#define WAVE_FORMAT_PCM 0x0001 +#define IBM_FORMAT_MULAW 0x0101 +#define IBM_FORMAT_ALAW 0x0102 +#define IBM_FORMAT_ADPCM 0x0103 - -typedef char FOURCC[4]; // Four-character code -typedef uint32 CKSIZE; // 32-bit unsigned size +typedef char FOURCC[4]; // Four-character code +typedef uint32 CKSIZE; // 32-bit unsigned size -class CKID // Chunk type identifier -{ - union { FOURCC Tx; uint32 Id; }; +class CKID { // Chunk type identifier + union { + FOURCC Tx; + uint32 Id; + }; protected: - static XFILE * ckFile; + static XFILE *ckFile; public: - CKID (FOURCC t) { memcpy(Tx, t, sizeof(Tx)); } - CKID (uint32 d) { Id = d; } - CKID (XFILE * xf) { (ckFile = xf)->Read(Tx, sizeof(Tx)); } - bool operator !=(CKID& X) { return Id != X.Id; } - bool operator ==(CKID& X) { return Id == X.Id; } - const char * Name (void); + CKID(FOURCC t) { + memcpy(Tx, t, sizeof(Tx)); + } + CKID(uint32 d) { + Id = d; + } + CKID(XFILE *xf) { + (ckFile = xf)->Read(Tx, sizeof(Tx)); + } + bool operator !=(CKID &X) { + return Id != X.Id; + } + bool operator ==(CKID &X) { + return Id == X.Id; + } + const char *Name(void); }; - - -class CKHEA : public CKID -{ +class CKHEA : public CKID { protected: - CKSIZE ckSize; // Chunk size field (size of ckData) + CKSIZE ckSize; // Chunk size field (size of ckData) public: - CKHEA (XFILE * xf) : CKID(xf) { XRead(xf, &ckSize); } - CKHEA (char id[]) : CKID(id), ckSize(0) { } - void Skip (void); - CKSIZE Size (void) { return ckSize; } + CKHEA(XFILE *xf) : CKID(xf) { + XRead(xf, &ckSize); + } + CKHEA(char id[]) : CKID(id), ckSize(0) { } + void Skip(void); + CKSIZE Size(void) { + return ckSize; + } }; +class FMTCK : public CKHEA { + struct WAV { + uint16 wFormatTag; // Format category + uint16 wChannels; // Number of channels + uint32 dwSamplesPerSec; // Sampling rate + uint32 dwAvgBytesPerSec; // For buffer estimation + uint16 wBlockAlign; // Data block size + } Wav; - - -class FMTCK : public CKHEA -{ - struct WAV - { - uint16 wFormatTag; // Format category - uint16 wChannels; // Number of channels - uint32 dwSamplesPerSec; // Sampling rate - uint32 dwAvgBytesPerSec; // For buffer estimation - uint16 wBlockAlign; // Data block size - } Wav; - - union - { - struct PCM - { - uint16 wBitsPerSample; // Sample size - } Pcm; - }; + union { + struct PCM { + uint16 wBitsPerSample; // Sample size + } Pcm; + }; public: - FMTCK (CKHEA& hea); - inline uint16 Channels (void) { return Wav.wChannels; } - inline uint32 SmplRate (void) { return Wav.dwSamplesPerSec; } - inline uint32 ByteRate (void) { return Wav.dwAvgBytesPerSec; } - inline uint16 BlckSize (void) { return Wav.wBlockAlign; } - inline uint16 SmplSize (void) { return Pcm.wBitsPerSample; } + FMTCK(CKHEA &hea); + inline uint16 Channels(void) { + return Wav.wChannels; + } + inline uint32 SmplRate(void) { + return Wav.dwSamplesPerSec; + } + inline uint32 ByteRate(void) { + return Wav.dwAvgBytesPerSec; + } + inline uint16 BlckSize(void) { + return Wav.wBlockAlign; + } + inline uint16 SmplSize(void) { + return Pcm.wBitsPerSample; + } }; - - - -class DATACK : public CKHEA -{ - bool e; - union - { - uint8 * Buf; - EMS * EBuf; - }; +class DATACK : public CKHEA { + bool e; + union { + uint8 *Buf; + EMS *EBuf; + }; public: - DATACK (CKHEA& hea); - DATACK (CKHEA& hea, EMM * emm); - DATACK (int first, int last); - ~DATACK (void); - inline uint8 * Addr (void) { return Buf; } - inline EMS * EAddr (void) { return EBuf; } + DATACK(CKHEA &hea); + DATACK(CKHEA &hea, EMM *emm); + DATACK(int first, int last); + ~DATACK(void); + inline uint8 *Addr(void) { + return Buf; + } + inline EMS *EAddr(void) { + return EBuf; + } }; - -extern CKID RIFF; -extern CKID WAVE; -extern CKID FMT; -extern CKID DATA; +extern CKID RIFF; +extern CKID WAVE; +extern CKID FMT; +extern CKID DATA; -DATACK * LoadWave (XFILE * file, EMM * emm = NULL); - +DATACK *LoadWave(XFILE *file, EMM *emm = NULL); } // End of namespace CGE - #endif From 64f2ccca9bf4ba7fef87def8bee5209118d78ce8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 13 Jun 2011 13:07:45 +0200 Subject: [PATCH 015/276] CGE: Cleanup: remove trailing spaces --- engines/cge/bitmaps.cpp | 24 +++---- engines/cge/cfile.cpp | 48 ++++++------- engines/cge/cge_main.cpp | 72 +++++++++---------- engines/cge/cge_main.h | 16 +---- engines/cge/config.cpp | 28 ++++---- engines/cge/ems.cpp | 2 +- engines/cge/game.cpp | 4 +- engines/cge/general.cpp | 2 +- engines/cge/gettext.cpp | 8 +-- engines/cge/keybd.cpp | 40 +++++------ engines/cge/mixer.cpp | 10 +-- engines/cge/mouse.cpp | 18 ++--- engines/cge/snail.cpp | 152 +++++++++++++++++++-------------------- engines/cge/snail.h | 14 ++-- engines/cge/sound.cpp | 10 +-- engines/cge/startup.cpp | 14 ++-- engines/cge/talk.cpp | 24 +++---- engines/cge/text.cpp | 32 ++++----- engines/cge/text.h | 7 +- engines/cge/vga13h.cpp | 124 ++++++++++++++++---------------- engines/cge/vga13h.h | 6 +- engines/cge/vmenu.cpp | 12 ++-- engines/cge/vol.cpp | 4 +- 23 files changed, 327 insertions(+), 344 deletions(-) diff --git a/engines/cge/bitmaps.cpp b/engines/cge/bitmaps.cpp index 8e1b7ce5e90..77012c0488b 100644 --- a/engines/cge/bitmaps.cpp +++ b/engines/cge/bitmaps.cpp @@ -225,35 +225,35 @@ static uint8 MEDesign[][9] = { { R R R R R R R R R }, // 0 namespace CGE { #ifdef DEBUG -BMP_PTR MB[] = { - new BITMAP("BRICK"), - NULL +BMP_PTR MB[] = { + new BITMAP("BRICK"), + NULL }; -BMP_PTR HL[] = { - new BITMAP("HLINE"), - NULL +BMP_PTR HL[] = { + new BITMAP("HLINE"), + NULL }; #endif -BMP_PTR MC[] = { +BMP_PTR MC[] = { new BITMAP("MOUSE"), new BITMAP("DUMMY"), NULL }; -BMP_PTR PR[] = { - new BITMAP("PRESS"), - NULL +BMP_PTR PR[] = { + new BITMAP("PRESS"), + NULL }; -BMP_PTR SP[] = { +BMP_PTR SP[] = { new BITMAP("SPK_L"), new BITMAP("SPK_R"), NULL }; -BMP_PTR LI[] = { +BMP_PTR LI[] = { new BITMAP("LITE0"), new BITMAP("LITE1"), new BITMAP("LITE2"), diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 7c4f689e309..4fb0988d381 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -55,9 +55,9 @@ IOBUF::IOBUF(const char *name, IOMODE mode, CRYPT *crpt) } IOBUF::~IOBUF(void) { - if (Mode > REA) + if (Mode > REA) WriteBuff(); - if (Buff) + if (Buff) free(Buff); } @@ -81,18 +81,18 @@ void IOBUF::WriteBuff(void) { uint16 IOBUF::Read(void *buf, uint16 len) { uint16 total = 0; while (len) { - if (Ptr >= Lim) + if (Ptr >= Lim) ReadBuff(); uint16 n = Lim - Ptr; if (n) { - if (len < n) + if (len < n) n = len; memcpy(buf, Buff + Ptr, n); buf = (uint8 *)buf + n; len -= n; total += n; Ptr += n; - } else + } else break; } return total; @@ -103,40 +103,40 @@ uint16 IOBUF::Read(uint8 *buf) { uint16 total = 0; while (total < LINE_MAX - 2) { - if (Ptr >= Lim) + if (Ptr >= Lim) ReadBuff(); uint8 *p = Buff + Ptr; uint16 n = Lim - Ptr; if (n) { - if (total + n >= LINE_MAX - 2) + if (total + n >= LINE_MAX - 2) n = LINE_MAX - 2 - total; uint8 *eol = (uint8 *) memchr(p, '\r', n); - if (eol) + if (eol) n = (uint16)(eol - p); uint8 *eof = (uint8 *) memchr(p, '\32', n); if (eof) { // end-of-file n = (uint16)(eof - p); Ptr = (uint16)(eof - Buff); } - if (n) + if (n) memcpy(buf, p, n); buf += n; total += n; - if (eof) + if (eof) break; Ptr += n; if (eol) { ++ Ptr; * (buf ++) = '\n'; ++ total; - if (Ptr >= Lim) + if (Ptr >= Lim) ReadBuff(); - if (Ptr < Lim) - if (Buff[Ptr] == '\n') + if (Ptr < Lim) + if (Buff[Ptr] == '\n') ++Ptr; break; } - } else + } else break; } *buf = '\0'; @@ -148,7 +148,7 @@ uint16 IOBUF::Write(void *buf, uint16 len) { uint16 tot = 0; while (len) { uint16 n = IOBUF_SIZE - Lim; - if (n > len) + if (n > len) n = len; if (n) { memcpy(Buff + Lim, buf, n); @@ -156,7 +156,7 @@ uint16 IOBUF::Write(void *buf, uint16 len) { len -= n; buf = (uint8 *)buf + n; tot += n; - } else + } else WriteBuff(); } return tot; @@ -167,8 +167,8 @@ uint16 IOBUF::Write(uint8 *buf) { uint16 len = 0; if (buf) { len = strlen((const char *) buf); - if (len) - if (buf[len - 1] == '\n') + if (len) + if (buf[len - 1] == '\n') --len; len = Write(buf, len); if (len) { @@ -184,7 +184,7 @@ uint16 IOBUF::Write(uint8 *buf) { int IOBUF::Read(void) { if (Ptr >= Lim) { ReadBuff(); - if (Lim == 0) + if (Lim == 0) return -1; } return Buff[Ptr ++]; @@ -211,9 +211,9 @@ CFILE::~CFILE(void) { void CFILE::Flush(void) { - if (Mode > REA) + if (Mode > REA) WriteBuff(); - else + else Lim = 0; /* @@ -250,11 +250,11 @@ void CFILE::Append(CFILE &f) { Seek(Size()); if (f.Error == 0) { while (true) { - if ((Lim = f.IOHAND::Read(Buff, IOBUF_SIZE)) == IOBUF_SIZE) + if ((Lim = f.IOHAND::Read(Buff, IOBUF_SIZE)) == IOBUF_SIZE) WriteBuff(); - else + else break; - if ((Error = f.Error) != 0) + if ((Error = f.Error) != 0) break; } } diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 62936e8c9c8..24964da0fcc 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1322,19 +1322,19 @@ void SPRITE::Touch(uint16 mask, int x, int y) { if (Flags.Kept || Hero->Distance(this) < MAX_DISTANCE) { if (Works(ps)) { FeedSnail(ps, TAKE); - } else + } else OffUse(); SelectPocket(-1); - } else + } else TooFar(); } else { - if (Flags.Kept) + if (Flags.Kept) mask |= L_UP; else { if (Hero->Distance(this) < MAX_DISTANCE) { /// if (Flags.Port) { - if (FindPocket(NULL) < 0) + if (FindPocket(NULL) < 0) PocFul(); else { SNPOST(SNREACH, -1, -1, this); @@ -1343,15 +1343,15 @@ void SPRITE::Touch(uint16 mask, int x, int y) { } } else { if (TakePtr != NO_PTR) { - if (SnList(TAKE)[TakePtr].Com == SNNEXT) + if (SnList(TAKE)[TakePtr].Com == SNNEXT) OffUse(); - else + else FeedSnail(this, TAKE); - } else + } else OffUse(); } }/// - else + else TooFar(); } } @@ -1365,7 +1365,7 @@ void SPRITE::Touch(uint16 mask, int x, int y) { break; } } - } else + } else SNPOST(SNWALK, -1, -1, this); // Hero->FindWay(this); } } @@ -1400,9 +1400,9 @@ static void LoadSprite(const char *fname, int ref, int cav, int col = 0, int row while ((len = sprf.Read((uint8 *)line)) != 0) { ++ lcnt; - if (len && line[len - 1] == '\n') + if (len && line[len - 1] == '\n') line[-- len] = '\0'; - if (len == 0 || *line == '.') + if (len == 0 || *line == '.') continue; if ((i = TakeEnum(Comd, strtok(line, " =\t"))) < 0) @@ -1531,42 +1531,42 @@ static void LoadScript(const char *fname) { int lcnt = 0; bool ok = true; - if (scrf.Error) + if (scrf.Error) return; while (scrf.Read((uint8 *)line) != 0) { char *p; ++lcnt; - if (*line == 0 || *line == '\n' || *line == '.') + if (*line == 0 || *line == '\n' || *line == '.') continue; ok = false; // not OK if break // sprite ident number - if ((p = strtok(line, " \t\n")) == NULL) + if ((p = strtok(line, " \t\n")) == NULL) break; SpI = atoi(p); // sprite file name - if ((SpN = strtok(NULL, " ,;/\t\n")) == NULL) + if ((SpN = strtok(NULL, " ,;/\t\n")) == NULL) break; // sprite cave - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; SpA = atoi(p); // sprite column - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; SpX = atoi(p); // sprite row - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; SpY = atoi(p); // sprite Z pos - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; SpZ = atoi(p); // sprite life - if ((p = strtok(NULL, " ,;/\t\n")) == NULL) + if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; BkG = atoi(p) == 0; @@ -1574,7 +1574,7 @@ static void LoadScript(const char *fname) { Sprite = NULL; LoadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); - if (Sprite && BkG) + if (Sprite && BkG) Sprite->Flags.Back = true; } if (! ok) @@ -1688,10 +1688,10 @@ static void RunGame(void) { if ((Sprite = VGA::SpareQ.Locate(121)) != NULL) SNPOST_(SNSEQ, -1, VGA::Mono, Sprite); - if ((Sprite = VGA::SpareQ.Locate(122)) != NULL) + if ((Sprite = VGA::SpareQ.Locate(122)) != NULL) Sprite->Step(Music); SNPOST_(SNSEQ, -1, Music, Sprite); - if (! Music) + if (! Music) KillMIDI(); if (Mini && INI_FILE::Exist("MINI.SPR")) { @@ -1738,7 +1738,7 @@ static void RunGame(void) { #endif Mouse.Busy = VGA::SpareQ.Locate(BUSY_REF); - if (Mouse.Busy) + if (Mouse.Busy) ExpandSprite(Mouse.Busy); Startup = 0; @@ -1820,14 +1820,14 @@ bool ShowTitle(const char *name) { VGA::ShowQ.Append(&Mouse); HEART::Enable = true; Mouse.On(); - for (SelectSound(); ! Snail.Idle() || VMENU::Addr;) + for (SelectSound(); ! Snail.Idle() || VMENU::Addr;) MainLoop(); Mouse.Off(); HEART::Enable = false; VGA::ShowQ.Clear(); VGA::CopyPage(0, 2); STARTUP::SoundOk = 2; - if (Music) + if (Music) LoadMIDI(0); } @@ -1857,12 +1857,12 @@ bool ShowTitle(const char *name) { VGA::ShowQ.Append(&Mouse); //Mouse.On(); HEART::Enable = true; - for (TakeName(); GET_TEXT::Ptr;) + for (TakeName(); GET_TEXT::Ptr;) MainLoop(); HEART::Enable = false; - if (KEYBOARD::Last() == Enter && *UsrFnam) + if (KEYBOARD::Last() == Enter && *UsrFnam) usr_ok = true; - if (usr_ok) + if (usr_ok) strcat(UsrFnam, SVG_EXT); //Mouse.Off(); VGA::ShowQ.Clear(); @@ -1879,12 +1879,12 @@ bool ShowTitle(const char *name) { ++ STARTUP::Mode; FINIS = false; } - } else + } else ++STARTUP::Mode; } } - if (STARTUP::Mode < 2) + if (STARTUP::Mode < 2) Movie("X01"); // wink VGA::CopyPage(0, 2); @@ -1918,7 +1918,7 @@ void cge_main(void) { if (! Mouse.Exist) error("%s", Text[NO_MOUSE_TEXT]); - if (! SVG0FILE::Exist(SVG0NAME)) + if (! SVG0FILE::Exist(SVG0NAME)) STARTUP::Mode = 2; Debug(DebugLine.Flags.Hide = true;) @@ -1927,9 +1927,9 @@ void cge_main(void) { //srand((uint16) Timer()); Sys = new SYSTEM; - if (Music && STARTUP::SoundOk) + if (Music && STARTUP::SoundOk) LoadMIDI(0); - if (STARTUP::Mode < 2) + if (STARTUP::Mode < 2) Movie(LGO_EXT); if (ShowTitle("WELCOME")) { #ifndef DEMO @@ -1937,9 +1937,9 @@ void cge_main(void) { #endif RunGame(); Startup = 2; - if (FINIS) + if (FINIS) Movie("X03"); - } else + } else Vga.Sunset(); error("%s", Text[EXIT_OK_TEXT + FINIS]); } diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index a67cd290000..fa27274803e 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -39,7 +39,6 @@ namespace CGE { #define NO_WAY (TSEQ+5) #define POC_FUL (TSEQ+5) #define OFF_USE (TSEQ+6) - #define EXIT_OK_TEXT 40 #define NOMUSIC_TEXT 98 #define BADSVG_TEXT 99 @@ -49,19 +48,15 @@ namespace CGE { #define TOO_FAR_TEXT 681 #define POC_FUL_TEXT 691 #define A_C_D_TEXT 777 - #define GETNAME_PROMPT 50 #define GETNAME_TITLE 51 - #define QUIT_TITLE 200 #define QUIT_TEXT 201 #define NOQUIT_TEXT 202 #define DEMO_TEXT 300 #define NOSOUND_TEXT 310 - #define PAN_HIG 40 #define WORLD_HIG (SCR_HIG-PAN_HIG) - #define INFO_X 177 #define INFO_Y 164 #define INFO_W 140 @@ -75,7 +70,7 @@ namespace CGE { #define CAVE_DY 29 #define CAVE_NX 3 #define CAVE_NY 1 -#else +#else #define CAVE_X 4 #define CAVE_Y 166 #define CAVE_SX 0 @@ -92,19 +87,14 @@ namespace CGE { #define BUTTON_DY 11 #define BUTTON_NX 1 #define BUTTON_NY 3 - #define MINI_X 86 #define MINI_Y 162 - -//#define MAP_XCNT 16 -//#define MAP_ZCNT 4 #define MAP_XCNT 40 #define MAP_ZCNT 20 #define MAP_TOP 80 #define MAP_HIG 80 #define MAP_XGRID (SCR_WID / MAP_XCNT) #define MAP_ZGRID (MAP_HIG / MAP_ZCNT) - #define LINE_MAX 512 #define USER_MAX 100 #define SHP_MAX 1024 @@ -113,16 +103,12 @@ namespace CGE { #define CAVE_MAX (CAVE_NX*CAVE_NY) #define MAX_FIND_LEVEL 3 #define MAX_DISTANCE 3 - #define INI_EXT ".INI" #define IN0_EXT ".IN0" #define LGO_EXT ".LGO" #define SVG_EXT ".SVG" - #define WALKSIDE 10 - #define BUSY_REF 500 - #define SYSTIMERATE 6 // 12 Hz #define HEROFUN0 (40*12) #define HEROFUN1 ( 2*12) diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index c1e9ae4762b..19000935209 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -72,12 +72,12 @@ static void SetIRQ(void); static void SetDMA(void); -static int DevName[] = { +static int DevName[] = { NONE_TEXT, SB_TEXT, SBM_TEXT, GUS_TEXT, GUSM_TEXT, MIDI_TEXT, AUTO_TEXT }; -static CHOICE DevMenu[] = { +static CHOICE DevMenu[] = { { NULL, NONE }, { NULL, SB }, { NULL, SBM }, @@ -89,7 +89,7 @@ static CHOICE DevMenu[] = { }; -static CHOICE DigiPorts[] = { +static CHOICE DigiPorts[] = { { " 210h", SetPortD }, { " 220h", SetPortD }, { " 230h", SetPortD }, @@ -100,7 +100,7 @@ static CHOICE DigiPorts[] = { { NULL, NULL } }; -static CHOICE MIDIPorts[] = { +static CHOICE MIDIPorts[] = { { " 220h", SetPortM }, { " 230h", SetPortM }, { " 240h", SetPortM }, @@ -115,7 +115,7 @@ static CHOICE MIDIPorts[] = { { NULL, NULL } }; -static CHOICE BlsterIRQ[] = { +static CHOICE BlsterIRQ[] = { { "IRQ 2", SetIRQ }, { "IRQ 5", SetIRQ }, { "IRQ 7", SetIRQ }, @@ -124,7 +124,7 @@ static CHOICE BlsterIRQ[] = { { NULL, NULL } }; -static CHOICE GravisIRQ[] = { +static CHOICE GravisIRQ[] = { { "IRQ 2", SetIRQ }, { "IRQ 5", SetIRQ }, { "IRQ 7", SetIRQ }, @@ -135,7 +135,7 @@ static CHOICE GravisIRQ[] = { { NULL, NULL } }; -static CHOICE GravisDMA[] = { +static CHOICE GravisDMA[] = { { "DMA 1", SetDMA }, { "DMA 3", SetDMA }, { "DMA 5", SetDMA }, @@ -145,7 +145,7 @@ static CHOICE GravisDMA[] = { { NULL, NULL } }; -static CHOICE BlsterDMA[] = { +static CHOICE BlsterDMA[] = { { "DMA 0", SetDMA }, { "DMA 1", SetDMA }, { "DMA 3", SetDMA }, @@ -157,7 +157,7 @@ static CHOICE BlsterDMA[] = { void SelectSound(void) { int i; Sound.Close(); - if (VMENU::Addr) + if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); Inf(Text[STYPE_TEXT]); Talk->Goto(Talk->X, FONT_HIG / 2); @@ -173,11 +173,11 @@ static void Reset(void) { static uint16 deco(const char *str, uint16(*dco)(const char *)) { - while (*str && ! IsDigit(*str)) + while (*str && ! IsDigit(*str)) ++str; - if (*str) + if (*str) return dco(str); - else + else return DETECT; } @@ -286,9 +286,9 @@ static void SetIRQ(void) { static void SetDMA(void) { SNDDrvInfo.DDMA = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA)[VMENU::Recent].Text); - if (SNDDrvInfo.MDEV != SNDDrvInfo.DDEV) + if (SNDDrvInfo.MDEV != SNDDrvInfo.DDEV) Select(MIDIPorts, MPORT_TEXT); - else + else Sound.Open(); } diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp index b6540005538..7b0697cd8a0 100644 --- a/engines/cge/ems.cpp +++ b/engines/cge/ems.cpp @@ -34,7 +34,7 @@ namespace CGE { #define SIZ(n) ((n) ? ((long)n) : (0x10000L)) -enum EMM_FUN { +enum EMM_FUN { GET_STATUS = 0x40, GET_FRAME, GET_SIZE, OPEN_HANDLE, MAP_PAGE, CLOSE_HANDLE, GET_VER, SAVE_CONTEXT, REST_CONTEXT, GET_PAGES = 0x4B, GET_HANDLES, GET_INFO, CONTROL diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 25af315d988..4102e080b61 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -83,9 +83,9 @@ void FLY::Tick(void) { Tx = new_random(3) - 1; Ty = new_random(3) - 1; } - if (X + Tx < L || X + Tx + W > R) + if (X + Tx < L || X + Tx + W > R) Tx = -Tx; - if (Y + Ty < T || Y + Ty + H > B) + if (Y + Ty < T || Y + Ty + H > B) Ty = -Ty; Goto(X + Tx, Y + Ty); } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 3a0114c672e..e68533d0b2c 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -187,7 +187,7 @@ char *wtom(uint16 val, char *str, int radix, int len) { char *dwtom(uint32 val, char *str, int radix, int len) { while (--len >= 0) { uint16 w = (uint16) (val % radix); - if (w > 9) + if (w > 9) w += ('A' - ('9' + 1)); str[len] = '0' + w; val /= radix; diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 78cc0356a1c..4399a30916e 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -75,7 +75,7 @@ void GET_TEXT::Touch(uint16 mask, int x, int y) { char *p; if (mask & KEYB) { - if (Click) + if (Click) Click(); switch (x) { case Enter : @@ -83,7 +83,7 @@ void GET_TEXT::Touch(uint16 mask, int x, int y) { strcpy(Text, Buff); for (p = Text; *p; p ++) { char *q = strchr(ogon, *p); - if (q) + if (q) *p = bezo[q - ogon]; } case Esc : @@ -103,7 +103,7 @@ void GET_TEXT::Touch(uint16 mask, int x, int y) { } else { if (KEYBOARD::Key[ALT]) { p = strchr(bezo, x); - if (p) + if (p) x = ogon[p - bezo]; } if (Len < Size && 2 * TEXT_HM + Font.Width(Buff) + Font.Wid[x] <= W) { @@ -114,7 +114,7 @@ void GET_TEXT::Touch(uint16 mask, int x, int y) { } break; } - } else + } else SPRITE::Touch(mask, x, y); } diff --git a/engines/cge/keybd.cpp b/engines/cge/keybd.cpp index a4590f49804..35e6c72c112 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/keybd.cpp @@ -34,26 +34,26 @@ namespace CGE { SPRITE *KEYBOARD::Client = NULL; uint8 KEYBOARD::Key[0x60] = { 0 }; uint16 KEYBOARD::Current = 0; -uint16 KEYBOARD::Code[0x60] = { - 0, Esc, '1', '2', '3', - '4', '5', '6', '7', '8', - '9', '0', '-', '+', BSp, - Tab, 'Q', 'W', 'E', 'R', - 'T', 'Y', 'U', 'I', 'O', - 'P', '[', ']', Enter, 0/*Ctrl*/, - 'A', 'S', 'D', 'F', 'G', - 'H', 'J', 'K', 'L', ';', - '\'', '`', 0/*LShift*/, '\\', 'Z', - 'X', 'C', 'V', 'B', 'N', - 'M', ',', '.', '/', 0/*RShift*/, - '*', 0/*Alt*/, ' ', 0/*Caps*/, F1, - F2, F3, F4, F5, F6, - F7, F8, F9, F10, 0/*NumLock*/, - 0/*ScrollLock*/, Home, Up, PgUp, '-', - Left, Ctr, Right, '+', End, - Down, PgDn, Ins, Del, 0 * 0x54, - 0 * 0x55, 0 * 0x56, F11, F12, 0 * 0x59, - 0 * 0x5A, 0 * 0x5B, 0 * 0x5C, 0 * 0x5D, 0 * 0x5E, +uint16 KEYBOARD::Code[0x60] = { + 0, Esc, '1', '2', '3', + '4', '5', '6', '7', '8', + '9', '0', '-', '+', BSp, + Tab, 'Q', 'W', 'E', 'R', + 'T', 'Y', 'U', 'I', 'O', + 'P', '[', ']', Enter, 0/*Ctrl*/, + 'A', 'S', 'D', 'F', 'G', + 'H', 'J', 'K', 'L', ';', + '\'', '`', 0/*LShift*/, '\\', 'Z', + 'X', 'C', 'V', 'B', 'N', + 'M', ',', '.', '/', 0/*RShift*/, + '*', 0/*Alt*/, ' ', 0/*Caps*/, F1, + F2, F3, F4, F5, F6, + F7, F8, F9, F10, 0/*NumLock*/, + 0/*ScrollLock*/, Home, Up, PgUp, '-', + Left, Ctr, Right, '+', End, + Down, PgDn, Ins, Del, 0 * 0x54, + 0 * 0x55, 0 * 0x56, F11, F12, 0 * 0x59, + 0 * 0x5A, 0 * 0x5B, 0 * 0x5C, 0 * 0x5D, 0 * 0x5E, 0 * 0x5F }; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 47a6e17fc9a..83d9cd1be56 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -76,7 +76,7 @@ MIXER::MIXER(int x, int y) : SPRITE(NULL), Fall(MIX_FALL) { Led[ArrayCount(Led) - 1]->Flags.BDel = true; VGA::ShowQ.Insert(this); - for (i = 0; i < ArrayCount(Led); i ++) + for (i = 0; i < ArrayCount(Led); i ++) VGA::ShowQ.Insert(Led[i]); //--- reset balance @@ -101,10 +101,10 @@ void MIXER::Touch(uint16 mask, int x, int y) { if (mask & L_UP) { uint8 *vol = (&SNDDrvInfo.VOL2.D) + (x < W / 2); if (y < MIX_BHIG) { - if (*vol < 0xFF) + if (*vol < 0xFF) *vol += 0x11; } else if (y >= H - MIX_BHIG) { - if (*vol > 0x00) + if (*vol > 0x00) *vol -= 0x11; } Update(); @@ -116,10 +116,10 @@ void MIXER::Tick(void) { int x = Mouse.X, y = Mouse.Y; if (SpriteAt(x, y) == this) { Fall = MIX_FALL; - if (Flags.Hold) + if (Flags.Hold) Touch(L_UP, x - X, y - Y); } else { - if (Fall) + if (Fall) --Fall; else { for (int i = 0; i < ArrayCount(Led); i ++) diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index d97a7eca7f4..9bb9626deb4 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -40,9 +40,9 @@ uint16 MOUSE::OldMouseMask = 0; MOUSE::MOUSE(BITMAP **shpl) : SPRITE(shpl), Busy(NULL), Hold(NULL), hx(0) { - static SEQ ms[] = { - { 0, 0, 0, 0, 1 }, - { 1, 1, 0, 0, 1 } + static SEQ ms[] = { + { 0, 0, 0, 0, 1 }, + { 1, 1, 0, 0, 1 } }; SetSeq(ms); @@ -135,9 +135,9 @@ void MOUSE::ClrEvt(SPRITE *spr) { if (spr) { uint16 e; for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) - if (Evt[e].Ptr == spr) + if (Evt[e].Ptr == spr) Evt[e].Msk = 0; - } else + } else EvtTail = EvtHead; } @@ -156,11 +156,11 @@ void MOUSE::Tick(void) { // activate current touched SPRITE if (e.Ptr) { - if (e.Msk & KEYB) + if (e.Msk & KEYB) e.Ptr->Touch(e.Msk, e.X, e.Y); - else + else e.Ptr->Touch(e.Msk, e.X - e.Ptr->X, e.Y - e.Ptr->Y); - } else if (Sys) + } else if (Sys) Sys->Touch(e.Msk, e.X, e.Y); if (e.Msk & L_DN) { @@ -186,7 +186,7 @@ void MOUSE::Tick(void) { ///Touched = e.Ptr; // discard Text if button released - if (e.Msk & (L_UP | R_UP)) + if (e.Msk & (L_UP | R_UP)) KillText(); } EvtTail = (EvtTail + 1) % EVT_MAX; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 952e0322222..cc52ec63dc9 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -88,7 +88,7 @@ static void SNGame(SPRITE *spr, int num) { if (Game) { // continue game int i = new_random(3), hand = (dup[0]->ShpCnt == 6); ++ Stage; - if (hand && Stage > DRESSED) + if (hand && Stage > DRESSED) ++hand; if (Debug(i >= 0 ||) dup[i] == spr && new_random(3) == 0) { @@ -138,8 +138,8 @@ static void SNGame(SPRITE *spr, int num) { SNPOST(SNSEQ, -1, 2, dup[1]); // no SNPOST(SNSEQ, -1, 2, dup[2]); // no SNPOST(SNPAUSE, -1, 72, NULL); // 1 sec - } - } + } + } SNPOST(SNWALK, 198, 134, NULL); // na miejsce SNPOST(SNWAIT, 1, -1, NULL); // stoi SNPOST(SNCOVER, 1, 16101, NULL); // ch’op do bicia @@ -152,7 +152,7 @@ static void SNGame(SPRITE *spr, int num) { SNPOST(SNSEQ, 16040, 0, NULL); // schowaj plask SNPOST(SNWAIT, 16101, -1, NULL); // stoi SNPOST(SNUNCOVER, 1, 16101, NULL); // SDS - if (! Game) { + if (! Game) { SNPOST(SNSAY, buref, 16008, NULL); // zgadnij! Game = true; } @@ -200,13 +200,13 @@ static void SNGame(SPRITE *spr, int num) { SNPOST(SNKEEP, 20007, 0, NULL); // do kieszeni SNPOST(SNSEND, 20006, 20, NULL); // bilon SNPOST(SNSOUND, 20006, 20002, NULL); // bilon! - SNPOST(SNSAY, 20002, 20004, NULL); + SNPOST(SNSAY, 20002, 20004, NULL); SNPOST(SNSEND, 20010, 20, NULL); // papier SNPOST(SNSOUND, 20010, 20003, NULL); // papier! SNPOST(SNSAY, 20001, 20005, NULL); Game = false; return; - } else + } else k3->Step(new_random(5)); } if (count < 100) { @@ -237,7 +237,7 @@ static void SNGame(SPRITE *spr, int num) { SNPOST(SNWAIT, 20007, -1, NULL); // koniec SNPOST(SNGAME, 20001, 2, NULL); // again! break; - case 20001 : + case 20001: SNPOST(SNSAY, 20002, 20012, NULL); // zapro SNPOST(SNSEQ, 20002, 1, NULL); // rzu SNPOST(SNWAIT, 20002, 3, NULL); // czekaj @@ -249,8 +249,8 @@ static void SNGame(SPRITE *spr, int num) { SNPOST(SNSOUND, 20007, 20001, NULL); // grzech SNPOST(SNWAIT, 20007, -1, NULL); // koniec SNPOST(SNGAME, 20002, 2, NULL); // again! - break; - case 20002 : + break; + case 20002: SNPOST(SNSAY, 20002, 20010, NULL); // zapro SNPOST(SNWALK, 20005, -1, NULL); // do stol SNPOST(SNWAIT, 1, -1, NULL); // stoi @@ -276,19 +276,19 @@ static void SNGame(SPRITE *spr, int num) { void ExpandSprite(SPRITE *spr) { - if (spr) + if (spr) VGA::ShowQ.Insert(VGA::SpareQ.Remove(spr)); } void ContractSprite(SPRITE *spr) { - if (spr) + if (spr) VGA::SpareQ.Append(VGA::ShowQ.Remove(spr)); } int FindPocket(SPRITE *spr) { - for (int i = 0; i < POCKET_NX; i ++) - if (Pocket[i] == spr) + for (int i = 0; i < POCKET_NX; i ++) + if (Pocket[i] == spr) return i; return -1; } @@ -298,7 +298,7 @@ void SelectPocket(int n) { if (n < 0 || (PocLight.SeqPtr && PocPtr == n)) { PocLight.Step(0); n = FindPocket(NULL); - if (n >= 0) + if (n >= 0) PocPtr = n; } else { if (Pocket[n] != NULL) { @@ -335,7 +335,7 @@ void SNGhost(BITMAP *bmp) { void FeedSnail(SPRITE *spr, SNLIST snq) { - if (spr) + if (spr) if (spr->Active()) { uint8 ptr = (snq == TAKE) ? spr->TakePtr : spr->NearPtr; @@ -350,13 +350,13 @@ void FeedSnail(SPRITE *spr, SNLIST snq) { PocFul(); return; } - if (p->Ptr) + if (p->Ptr) break; } } while (true) { if (c->Com == SNTALK) { - if ((Snail.TalkEnable = (c->Val != 0)) == false) + if ((Snail.TalkEnable = (c->Val != 0)) == false) KillText(); } if (c->Com == SNNEXT) { @@ -379,27 +379,27 @@ void FeedSnail(SPRITE *spr, SNLIST snq) { v = c->Val; break; } - if (v >= 0) + if (v >= 0) *idx = v; } } - if (s == spr) + if (s == spr) break; } if (c->Com == SNIF) { SPRITE *s = (c->Ref < 0) ? spr : Locate(c->Ref); if (s) { // sprite extsts - if (! s->SeqTest(-1)) + if (! s->SeqTest(-1)) c = comtab + c->Val; // not parked - else + else ++c; - } else + } else ++c; } else { SNPOST(c->Com, c->Ref, c->Val, spr); - if (c->Ptr) + if (c->Ptr) break; - else + else ++c; } } @@ -408,17 +408,17 @@ void FeedSnail(SPRITE *spr, SNLIST snq) { } -const char *SNAIL::ComTxt[] = { - "LABEL", "PAUSE", "WAIT", "LEVEL", "HIDE", - "SAY", "INF", "TIME", "CAVE", "KILL", - "RSEQ", "SEQ", "SEND", "SWAP", "KEEP", - "GIVE", "IF", "GAME", "SETX0", "SETY0", +const char *SNAIL::ComTxt[] = { + "LABEL", "PAUSE", "WAIT", "LEVEL", "HIDE", + "SAY", "INF", "TIME", "CAVE", "KILL", + "RSEQ", "SEQ", "SEND", "SWAP", "KEEP", + "GIVE", "IF", "GAME", "SETX0", "SETY0", "SLAVE", "SETXY", "RELX", "RELY", "RELZ", "SETX", "SETY", "SETZ", "TRANS", "PORT", "NEXT", "NNEXT", "TNEXT", "RNNEXT", "RTNEXT", - "RMNEAR", "RMTAKE", "FLAG", "SETREF", "BACKPT", - "FLASH", "LIGHT", "SETHB", "SETVB", "WALK", - "REACH", "COVER", "UNCOVER", "CLEAR", "TALK", + "RMNEAR", "RMTAKE", "FLAG", "SETREF", "BACKPT", + "FLASH", "LIGHT", "SETHB", "SETVB", "WALK", + "REACH", "COVER", "UNCOVER", "CLEAR", "TALK", "MOUSE", "SOUND", "COUNT", NULL }; @@ -431,7 +431,7 @@ SNAIL::SNAIL(bool turbo) SNAIL::~SNAIL(void) { - if (SNList) + if (SNList) free(SNList); } @@ -459,7 +459,7 @@ void SNAIL::InsCom(SNCOM com, int ref, int val, void *ptr) { if (Busy) { SNList[(Tail - 1) & 0xFF] = SNList[Tail]; snc = &SNList[Tail]; - } else + } else snc = &SNList[(Tail - 1) & 0xFF]; --Tail; snc->Com = com; @@ -476,35 +476,35 @@ void SNAIL::InsCom(SNCOM com, int ref, int val, void *ptr) { static void SNNNext(SPRITE *sprel, int p) { - if (sprel) - if (sprel->NearPtr != NO_PTR) + if (sprel) + if (sprel->NearPtr != NO_PTR) sprel->NearPtr = p; } static void SNTNext(SPRITE *sprel, int p) { - if (sprel) - if (sprel->TakePtr != NO_PTR) + if (sprel) + if (sprel->TakePtr != NO_PTR) sprel->TakePtr = p; } static void SNRNNext(SPRITE *sprel, int p) { - if (sprel) - if (sprel->NearPtr != NO_PTR) + if (sprel) + if (sprel->NearPtr != NO_PTR) sprel->NearPtr += p; } static void SNRTNext(SPRITE *sprel, int p) { - if (sprel) - if (sprel->TakePtr != NO_PTR) + if (sprel) + if (sprel->TakePtr != NO_PTR) sprel->TakePtr += p; } static void SNZTrim(SPRITE *spr) { - if (spr) + if (spr) if (spr->Active()) { bool en = HEART::Enable; SPRITE *s; @@ -523,36 +523,36 @@ static void SNZTrim(SPRITE *spr) { static void SNHide(SPRITE *spr, int val) { if (spr) { spr->Flags.Hide = (val >= 0) ? (val != 0) : (! spr->Flags.Hide); - if (spr->Flags.Shad) + if (spr->Flags.Shad) spr->Prev->Flags.Hide = spr->Flags.Hide; } } static void SNRmNear(SPRITE *spr) { - if (spr) + if (spr) spr->NearPtr = NO_PTR; } static void SNRmTake(SPRITE *spr) { - if (spr) + if (spr) spr->TakePtr = NO_PTR; } void SNSeq(SPRITE *spr, int val) { if (spr) { - if (spr == Hero && val == 0) + if (spr == Hero && val == 0) Hero->Park(); - else + else spr->Step(val); } } void SNRSeq(SPRITE *spr, int val) { - if (spr) + if (spr) SNSeq(spr, spr->SeqPtr + val); } @@ -567,18 +567,18 @@ void SNSend(SPRITE *spr, int val) { if (was1) { if (spr->Flags.Kept) { int n = FindPocket(spr); - if (n >= 0) + if (n >= 0) Pocket[n] = NULL; } Hide1(spr); ContractSprite(spr); spr->Flags.Slav = false; } else { - if (spr->Ref % 1000 == 0) + if (spr->Ref % 1000 == 0) BITMAP::Pal = SysPal; - if (spr->Flags.Back) + if (spr->Flags.Back) spr->BackShow(true); - else + else ExpandSprite(spr); BITMAP::Pal = NULL; } @@ -601,7 +601,7 @@ void SNSwap(SPRITE *spr, int xref) { Swap(spr->Z, xspr->Z); if (spr->Flags.Kept) { int n = FindPocket(spr); - if (n >= 0) + if (n >= 0) Pocket[n] = xspr; xspr->Flags.Kept = true; xspr->Flags.Port = false; @@ -610,12 +610,12 @@ void SNSwap(SPRITE *spr, int xref) { if (was1) { Hide1(spr); ContractSprite(spr); - } else + } else ExpandSprite(spr); if (xwas1) { Hide1(xspr); ContractSprite(xspr); - } else + } else ExpandSprite(xspr); } } @@ -650,7 +650,7 @@ void SNUncover(SPRITE *spr, SPRITE *xspr) { } spr->Z = xspr->Z; SNSend(xspr, -1); - if (spr->Time == 0) + if (spr->Time == 0) ++spr->Time; } } @@ -742,21 +742,21 @@ void SNKill(SPRITE *spr) { if (spr) { if (spr->Flags.Kept) { int n = FindPocket(spr); - if (n >= 0) + if (n >= 0) Pocket[n] = NULL; } SPRITE *nx = spr->Next; Hide1(spr); VGA::ShowQ.Remove(spr); MOUSE::ClrEvt(spr); - if (spr->Flags.Kill) + if (spr->Flags.Kill) delete spr; else { spr->Cave = -1; VGA::SpareQ.Append(spr); } - if (nx) - if (nx->Flags.Slav) + if (nx) + if (nx->Flags.Slav) SNKill(nx); } } @@ -764,7 +764,7 @@ void SNKill(SPRITE *spr) { static void SNSound(SPRITE *spr, int wav, int cnt) { if (SNDDrvInfo.DDEV) { - if (wav == -1) + if (wav == -1) Sound.Stop(); else Sound.Play(Fx[wav], (spr) ? ((spr->X + spr->W / 2) / (SCR_WID / 16)) : 8, cnt); @@ -781,7 +781,7 @@ void SNKeep(SPRITE *spr, int stp) { spr->Flags.Kept = true; spr->Goto(POCKET_X + POCKET_DX * PocPtr + POCKET_DX / 2 - spr->W / 2, POCKET_Y + POCKET_DY / 2 - spr->H / 2); - if (stp >= 0) + if (stp >= 0) spr->Step(stp); } SelectPocket(-1); @@ -795,7 +795,7 @@ void SNGive(SPRITE *spr, int stp) { Pocket[p] = NULL; spr->Cave = Now; spr->Flags.Kept = false; - if (stp >= 0) + if (stp >= 0) spr->Step(stp); } } @@ -805,7 +805,7 @@ void SNGive(SPRITE *spr, int stp) { static void SNBackPt(SPRITE *spr, int stp) { if (spr) { - if (stp >= 0) + if (stp >= 0) spr->Step(stp); spr->BackShow(true); } @@ -828,7 +828,7 @@ static void SNLevel(SPRITE *spr, int lev) { } } MaxCave = maxcav[Lev]; - if (spr) + if (spr) spr->Flags.Hide = false; } @@ -860,14 +860,14 @@ void SNFlash(bool on) { } VGA::SetColors(pal, 64); } - } else + } else VGA::SetColors(SysPal, 64); Dark = false; } static void SNLight(bool in) { - if (in) + if (in) VGA::Sunrise(SysPal); else VGA::Sunset(); @@ -882,16 +882,16 @@ static void SNBarrier(int cav, int bar, bool horz) { static void SNWalk(SPRITE *spr, int x, int y) { if (Hero) { - if (spr && y < 0) + if (spr && y < 0) Hero->FindWay(spr); - else + else Hero->FindWay(XZ(x, y)); } } static void SNReach(SPRITE *spr, int mode) { - if (Hero) + if (Hero) Hero->Reach(spr, mode); } @@ -914,7 +914,7 @@ void SNAIL::RunCom(void) { COM *snc = &SNList[Tail]; if (! Turbo) { // only for the slower one - if (Pause) + if (Pause) break; else { if (TextDelay) { @@ -922,7 +922,7 @@ void SNAIL::RunCom(void) { TextDelay = false; } } - if (Talk && snc->Com != SNPAUSE) + if (Talk && snc->Com != SNPAUSE) break; } @@ -932,7 +932,7 @@ void SNAIL::RunCom(void) { break; case SNPAUSE : HEART::SetXTimer(&Pause, snc->Val); - if (Talk) + if (Talk) TextDelay = true; break; case SNWAIT : @@ -940,7 +940,7 @@ void SNAIL::RunCom(void) { if (sprel->SeqTest(snc->Val) && (snc->Val >= 0 || sprel != Hero || Hero->TracePtr < 0)) { HEART::SetXTimer(&Pause, sprel->Time); - } else + } else goto xit; } break; @@ -1116,7 +1116,7 @@ void SNAIL::RunCom(void) { break; } ++Tail; - if (!Turbo) + if (!Turbo) break; } xit: diff --git a/engines/cge/snail.h b/engines/cge/snail.h index f9b969a5545..4255ea4e616 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -61,16 +61,16 @@ struct SCB { enum SNCOM { SNLABEL, SNPAUSE, SNWAIT, SNLEVEL, SNHIDE, - SNSAY, SNINF, SNTIME, SNCAVE, SNKILL, - SNRSEQ, SNSEQ, SNSEND, SNSWAP, SNKEEP, - SNGIVE, SNIF, SNGAME, SNSETX0, SNSETY0, + SNSAY, SNINF, SNTIME, SNCAVE, SNKILL, + SNRSEQ, SNSEQ, SNSEND, SNSWAP, SNKEEP, + SNGIVE, SNIF, SNGAME, SNSETX0, SNSETY0, SNSLAVE, SNSETXY, SNRELX, SNRELY, SNRELZ, SNSETX, SNSETY, SNSETZ, SNTRANS, SNPORT, SNNEXT, SNNNEXT, SNTNEXT, SNRNNEXT, SNRTNEXT, - SNRMNEAR, SNRMTAKE, SNFLAG, SNSETREF, SNBACKPT, - SNFLASH, SNLIGHT, SNSETHB, SNSETVB, SNWALK, - SNREACH, SNCOVER, SNUNCOVER, SNCLEAR, SNTALK, - SNMOUSE, SNSOUND, SNCOUNT, SNEXEC, SNSTEP, + SNRMNEAR, SNRMTAKE, SNFLAG, SNSETREF, SNBACKPT, + SNFLASH, SNLIGHT, SNSETHB, SNSETVB, SNWALK, + SNREACH, SNCOVER, SNUNCOVER, SNCLEAR, SNTALK, + SNMOUSE, SNSOUND, SNCOUNT, SNEXEC, SNSTEP, SNZTRIM, SNGHOST }; diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 397684849a0..04e5d9464a3 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -41,7 +41,7 @@ SOUND Sound; SOUND::SOUND(void) { - if (STARTUP::SoundOk) + if (STARTUP::SoundOk) Open(); } @@ -115,7 +115,7 @@ int FX::Find(int ref) { for (p = Cache, q = p + Size; p < q; p ++) { if (p->Ref == ref) break; - else + else ++i; } return i; @@ -133,7 +133,7 @@ void FX::Preload(int ref0) { DATACK *wav = LoadWave(&file, &Emm); if (wav) { HAN *p = &Cache[Find(0)]; - if (p >= CacheLim) + if (p >= CacheLim) break; p->Wav = wav; p->Ref = ref; @@ -159,7 +159,7 @@ DATACK *FX::Load(int idx, int ref) { DATACK *FX::operator [](int ref) { int i; - if ((i = Find(ref)) < Size) + if ((i = Find(ref)) < Size) Current = Cache[i].Wav; else { if ((i = Find(0)) >= Size) { @@ -195,7 +195,7 @@ void LoadMIDI(int ref) { midi = new uint8[siz]; if (midi) { mid.Read(midi, siz); - if (mid.Error) + if (mid.Error) KillMIDI(); else SNDMIDIStart(midi); diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 2bed51af971..24aaf3e042a 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -160,25 +160,25 @@ const char *UsrPath(const char *nam) { int i = strlen(key); while (ini.Read(buf) && !ok) { int j = strlen(buf); - if (j) - if (buf[--j] == '\n') + if (j) + if (buf[--j] == '\n') buf[j] = '\0'; - if (memicmp(buf, key, i) == 0) + if (memicmp(buf, key, i) == 0) ok = true; } if (ok) { strcpy(buf, buf + i); p = buf + strlen(buf); - if (*(p - 1) != '\\') + if (*(p - 1) != '\\') *(p++) = '\\'; strcpy(p, "NUL"); - if (_dos_open(buf, 0, &i) == 0) + if (_dos_open(buf, 0, &i) == 0) _dos_close(i); - else + else ok = false; } } - if (!ok) + if (!ok) quit_now(BADCD_TEXT); } #endif diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 1dbcbad98da..e707e4e7056 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -79,8 +79,8 @@ void FONT::Load(void) { uint16 FONT::Width(const char *text) { uint16 w = 0; - if (text) - while (* text) + if (text) + while (* text) w += Wid[*(text ++)]; return w; } @@ -141,13 +141,13 @@ void TALK::Update(const char *tx) { for (p = tx; *p; p ++) { if (*p == '|' || *p == '\n') { mh += FONT_HIG + TEXT_LS; - if (k > mw) + if (k > mw) mw = k; k = 2 * hmarg; - } else + } else k += Font.Wid[*p]; } - if (k > mw) + if (k > mw) mw = k; TS[0] = Box(mw, mh); } @@ -165,7 +165,7 @@ void TALK::Update(const char *tx) { uint16 n; register uint16 b = *(f++); for (n = 0; n < FONT_HIG; n++) { - if (b & 1) + if (b & 1) *p = TEXT_FG; b >>= 1; p += mw; @@ -186,9 +186,9 @@ BITMAP *TALK::Box(uint16 w, uint16 h) { uint8 *b, * p, * q; uint16 n, r = (Mode == ROUND) ? TEXT_RD : 0; - if (w < 8) + if (w < 8) w = 8; - if (h < 8) + if (h < 8) h = 8; b = farnew(uint8, n = w * h); if (! b) @@ -263,13 +263,13 @@ void TALK::PutLine(int line, const char *text) { register uint16 b = fp[i]; uint16 n; for (n = 0; n < FONT_HIG; n ++) { - if (b & 1) + if (b & 1) *p = TEXT_FG; b >>= 1; p += lsiz; } p = p - rsiz + psiz; - if (p >= q) + if (p >= q) p = p - size + 1; } ++text; @@ -310,12 +310,12 @@ void INFO_LINE::Update(const char *tx) { for (uint16 i = 0; i < cw; i++) { register uint16 b = fp[i]; for (uint16 n = 0; n < FONT_HIG; n ++) { - if (b & 1) + if (b & 1) *p = TEXT_FG; b >>= 1; p += lsiz; } - if (p >= q) + if (p >= q) p = p - size + 1; } ++tx; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 71f4f156d53..92951196c7b 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -79,7 +79,7 @@ int TEXT::Find(int ref) { for (p = Cache, q = p + Size; p < q; p ++) { if (p->Ref == ref) break; - else + else ++i; } return i; @@ -111,14 +111,14 @@ void TEXT::Preload(int from, int upto) { if (p < CacheLim) { delete[] p->Txt; p->Txt = NULL; - } else + } else p = &Cache[Find(0)]; - if (p >= CacheLim) + if (p >= CacheLim) break; s += strlen(s); - if (s < line + n) + if (s < line + n) ++s; - if ((p->Txt = new char[strlen(s) + 1]) == NULL) + if ((p->Txt = new char[strlen(s) + 1]) == NULL) break; p->Ref = ref; strcpy(p->Txt, s); @@ -138,24 +138,24 @@ char *TEXT::Load(int idx, int ref) { while ((n = tf.Read((uint8 *)line)) != 0) { char *s; - if (line[n - 1] == '\n') + if (line[n - 1] == '\n') line[-- n] = '\0'; - if ((s = strtok(line, " =,;/\t\n")) == NULL) + if ((s = strtok(line, " =,;/\t\n")) == NULL) continue; - if (! IsDigit(*s)) + if (! IsDigit(*s)) continue; int r = atoi(s); - if (r < ref) + if (r < ref) continue; - if (r > ref) + if (r > ref) break; // (r == ref) s += strlen(s); - if (s < line + n) + if (s < line + n) ++s; p->Ref = ref; - if ((p->Txt = new char[strlen(s) + 1]) == NULL) + if ((p->Txt = new char[strlen(s) + 1]) == NULL) return NULL; return strcpy(p->Txt, s); } @@ -166,7 +166,7 @@ char *TEXT::Load(int idx, int ref) { char *TEXT::operator [](int ref) { int i; - if ((i = Find(ref)) < Size) + if ((i = Find(ref)) < Size) return Cache[i].Txt; if ((i = Find(0)) >= Size) { @@ -191,14 +191,14 @@ void Say(const char *txt, SPRITE *spr) { uint16 sw = spike->W; if (east) { - if (x + sw + TEXT_RD + 5 >= SCR_WID) + if (x + sw + TEXT_RD + 5 >= SCR_WID) east = false; } else { - if (x <= 5 + TEXT_RD + sw) + if (x <= 5 + TEXT_RD + sw) east = true; } x = (east) ? (spr->X + spr->W - 2) : (spr->X + 2 - sw); - if (spr->Ref == 1) + if (spr->Ref == 1) x += (east) ? -10 : 10; // Hero Talk->Flags.Kill = true; diff --git a/engines/cge/text.h b/engines/cge/text.h index fe740ffacdd..7cf3922c5ac 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -34,10 +34,10 @@ namespace CGE { #ifndef SYSTXT_MAX -#define SYSTXT_MAX 1000 +#define SYSTXT_MAX 1000 #endif -#define SAY_EXT ".SAY" +#define SAY_EXT ".SAY" #define NOT_VGA_TEXT 90 #define BAD_CHIP_TEXT 91 @@ -45,11 +45,8 @@ namespace CGE { #define NO_CORE_TEXT 93 #define BAD_MIPS_TEXT 94 #define NO_MOUSE_TEXT 95 - - #define INF_NAME 101 #define SAY_NAME 102 - #define INF_REF 301 #define SAY_REF 302 diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index e7ed6d0402e..3f303e7f29f 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -88,7 +88,7 @@ extern "C" void SNDMIDIPlay(void); char *NumStr(char *str, int num) { char *p = strchr(str, '#'); - if (p) + if (p) wtom(num, p, 10, 5); return str; } @@ -345,7 +345,7 @@ void ENGINE::NewTimer(...) { void HEART::SetXTimer(uint16 *ptr) { - if (XTimer && ptr != XTimer) + if (XTimer && ptr != XTimer) *XTimer = 0; XTimer = ptr; } @@ -374,7 +374,7 @@ SPRITE::~SPRITE(void) { BMP_PTR SPRITE::Shp(void) { register SPREXT *e = Ext; - if (e) + if (e) if (e->Seq) { int i = e->Seq[SeqPtr].Now; #ifdef DEBUG @@ -403,15 +403,15 @@ BMP_PTR *SPRITE::SetShapeList(BMP_PTR *shp) { BMP_PTR *p; for (p = shp; *p; p++) { BMP_PTR b = (*p); // ->Code(); - if (b->W > W) + if (b->W > W) W = b->W; - if (b->H > H) + if (b->H > H) H = b->H; ++ShpCnt; } Expand(); Ext->ShpList = shp; - if (! Ext->Seq) + if (! Ext->Seq) SetSeq((ShpCnt < 2) ? Seq1 : Seq2); } return r; @@ -427,7 +427,7 @@ void SPRITE::MoveShapes(uint8 *buf) { bool SPRITE::Works(SPRITE *spr) { - if (spr) + if (spr) if (spr->Ext) { SNAIL::COM *c = spr->Ext->Take; if (c != NULL) { @@ -445,18 +445,18 @@ SEQ *SPRITE::SetSeq(SEQ *seq) { Expand(); register SEQ *s = Ext->Seq; Ext->Seq = seq; - if (SeqPtr == NO_SEQ) + if (SeqPtr == NO_SEQ) Step(0); - else if (Time == 0) + else if (Time == 0) Step(SeqPtr); return s; } bool SPRITE::SeqTest(int n) { - if (n >= 0) + if (n >= 0) return (SeqPtr == n); - if (Ext) + if (Ext) return (Ext->Seq[SeqPtr].Next == SeqPtr); return true; } @@ -464,7 +464,7 @@ bool SPRITE::SeqTest(int n) { SNAIL::COM *SPRITE::SnList(SNLIST type) { register SPREXT *e = Ext; - if (e) + if (e) return (type == NEAR) ? e->Near : e->Take; return NULL; } @@ -477,7 +477,7 @@ void SPRITE::SetName(char *n) { Ext->Name = NULL; } if (n) { - if ((Ext->Name = new char[strlen(n) + 1]) != NULL) + if ((Ext->Name = new char[strlen(n) + 1]) != NULL) strcpy(Ext->Name, n); else error("No core [%s]", n); @@ -516,9 +516,9 @@ SPRITE *SPRITE::Expand(void) { while ((len = sprf.Read((uint8 *)line)) != 0) { ++ lcnt; - if (len && line[len - 1] == '\n') + if (len && line[len - 1] == '\n') line[-- len] = '\0'; - if (len == 0 || *line == '.') + if (len == 0 || *line == '.') continue; switch (TakeEnum(Comd, strtok(line, " =\t"))) { @@ -536,7 +536,7 @@ SPRITE *SPRITE::Expand(void) { error("No core [%s]", fname); SEQ *s = &seq[seqcnt ++]; s->Now = atoi(strtok(NULL, " \t,;/")); - if (s->Now > maxnow) + if (s->Now > maxnow) maxnow = s->Now; s->Next = atoi(strtok(NULL, " \t,;/")); switch (s->Next) { @@ -547,7 +547,7 @@ SPRITE *SPRITE::Expand(void) { s->Next = seqcnt - 1; break; } - if (s->Next > maxnxt) + if (s->Next > maxnxt) maxnxt = s->Next; s->Dx = atoi(strtok(NULL, " \t,;/")); s->Dy = atoi(strtok(NULL, " \t,;/")); @@ -598,19 +598,19 @@ SPRITE *SPRITE::Expand(void) { if (maxnxt >= seqcnt) error("Bad JUMP in SEQ [%s]", fname); SetSeq(seq); - } else + } else SetSeq((ShpCnt == 1) ? Seq1 : Seq2); //disable(); // disable interupt SetShapeList(shplist); //enable(); // enable interupt - if (nea) + if (nea) nea[neacnt - 1].Ptr = Ext->Near = nea; - else + else NearPtr = NO_PTR; - if (tak) + if (tak) tak[takcnt - 1].Ptr = Ext->Take = tak; - else + else TakePtr = NO_PTR; } HEART::Enable = enbl; @@ -622,20 +622,20 @@ SPRITE *SPRITE::Expand(void) { SPRITE *SPRITE::Contract(void) { register SPREXT *e = Ext; if (e) { - if (e->Name) + if (e->Name) delete[] e->Name; if (Flags.BDel && e->ShpList) { int i; - for (i = 0; e->ShpList[i]; i ++) + for (i = 0; e->ShpList[i]; i ++) delete e->ShpList[i]; - if (MemType(e->ShpList) == NEAR_MEM) + if (MemType(e->ShpList) == NEAR_MEM) delete[] e->ShpList; } - if (MemType(e->Seq) == NEAR_MEM) + if (MemType(e->Seq) == NEAR_MEM) free(e->Seq); - if (e->Near) + if (e->Near) free(e->Near); - if (e->Take) + if (e->Take) free(e->Take); delete e; Ext = NULL; @@ -648,7 +648,7 @@ SPRITE *SPRITE::BackShow(bool fast) { Expand(); Show(2); Show(1); - if (fast) + if (fast) Show(0); Contract(); return this; @@ -656,11 +656,11 @@ SPRITE *SPRITE::BackShow(bool fast) { void SPRITE::Step(int nr) { - if (nr >= 0) + if (nr >= 0) SeqPtr = nr; if (Ext) { SEQ *seq; - if (nr < 0) + if (nr < 0) SeqPtr = Ext->Seq[SeqPtr].Next; seq = Ext->Seq + SeqPtr; if (seq->Dly >= 0) { @@ -680,7 +680,7 @@ void SPRITE::MakeXlat(uint8 *x) { if (Ext) { BMP_PTR *b; - if (Flags.Xlat) + if (Flags.Xlat) KillXlat(); for (b = Ext->ShpList; *b; b ++) (*b)->M = x; @@ -712,23 +712,23 @@ void SPRITE::KillXlat(void) { void SPRITE::Goto(int x, int y) { int xo = X, yo = Y; if (W < SCR_WID) { - if (x < 0) + if (x < 0) x = 0; - if (x + W > SCR_WID) + if (x + W > SCR_WID) x = (SCR_WID - W); X = x; } if (H < SCR_HIG) { - if (y < 0) + if (y < 0) y = 0; - if (y + H > SCR_HIG) + if (y + H > SCR_HIG) y = (SCR_HIG - H); Y = y; } - if (Next) - if (Next->Flags.Slav) + if (Next) + if (Next->Flags.Slav) Next->Goto(Next->X - xo + X, Next->Y - yo + Y); - if (Flags.Shad) + if (Flags.Shad) Prev->Goto(Prev->X - xo + X, Prev->Y - yo + Y); } @@ -766,7 +766,7 @@ void SPRITE::Show(uint16 pg) { void SPRITE::Hide(void) { register SPREXT *e = Ext; - if (e->b0) + if (e->b0) e->b0->Hide(e->x0, e->y0); } @@ -815,7 +815,7 @@ QUEUE::~QUEUE(void) { void QUEUE::Clear(void) { while (Head) { SPRITE *s = Remove(Head); - if (s->Flags.Kill) + if (s->Flags.Kill) delete s; } } @@ -835,12 +835,12 @@ void QUEUE::Append(SPRITE *spr) { if (Tail) { spr->Prev = Tail; Tail->Next = spr; - } else + } else Head = spr; Tail = spr; - if (Show) + if (Show) spr->Expand(); - else + else spr->Contract(); } @@ -849,19 +849,19 @@ void QUEUE::Insert(SPRITE *spr, SPRITE *nxt) { if (nxt == Head) { spr->Next = Head; Head = spr; - if (! Tail) + if (! Tail) Tail = spr; } else { spr->Next = nxt; spr->Prev = nxt->Prev; - if (spr->Prev) + if (spr->Prev) spr->Prev->Next = spr; } - if (spr->Next) + if (spr->Next) spr->Next->Prev = spr; - if (Show) + if (Show) spr->Expand(); - else + else spr->Contract(); } @@ -871,25 +871,25 @@ void QUEUE::Insert(SPRITE *spr) { for (s = Head; s; s = s->Next) if (s->Z > spr->Z) break; - if (s) + if (s) Insert(spr, s); - else + else Append(spr); - if (Show) + if (Show) spr->Expand(); - else + else spr->Contract(); } SPRITE *QUEUE::Remove(SPRITE *spr) { - if (spr == Head) + if (spr == Head) Head = spr->Next; - if (spr == Tail) + if (spr == Tail) Tail = spr->Prev; - if (spr->Next) + if (spr->Next) spr->Next->Prev = spr->Prev; - if (spr->Prev) + if (spr->Prev) spr->Prev->Next = spr->Next; spr->Prev = NULL; spr->Next = NULL; @@ -899,8 +899,8 @@ SPRITE *QUEUE::Remove(SPRITE *spr) { SPRITE *QUEUE::Locate(int ref) { SPRITE *spr; - for (spr = Head; spr; spr = spr->Next) - if (spr->Ref == ref) + for (spr = Head; spr; spr = spr->Next) + if (spr->Ref == ref) return spr; return NULL; } @@ -948,7 +948,7 @@ VGA::VGA(int mode) warning("TODO: Fix Copr"); SetStatAdr(); - if (StatAdr != VGAST1_) + if (StatAdr != VGAST1_) ++Mono; if (IsVga()) { OldColors = farnew(DAC, 256); @@ -1194,10 +1194,10 @@ void VGA::Sunset(void) { void VGA::Show(void) { SPRITE *spr = ShowQ.First(); - for (spr = ShowQ.First(); spr; spr = spr->Next) + for (spr = ShowQ.First(); spr; spr = spr->Next) spr->Show(); Update(); - for (spr = ShowQ.First(); spr; spr = spr->Next) + for (spr = ShowQ.First(); spr; spr = spr->Next) spr->Hide(); ++ FrmCnt; diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 810e781808f..b7622689569 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -287,12 +287,12 @@ uint8 Closest(CBLK *pal, CBLK x) { #define f(col, lum) ((((uint16)(col)) << 8) / lum) uint16 i, dif = 0xFFFF, found = 0; uint16 L = x.R + x.G + x.B; - if (!L) + if (!L) ++L; uint16 R = f(x.R, L), G = f(x.G, L), B = f(x.B, L); for (i = 0; i < 256; i ++) { uint16 l = pal[i].R + pal[i].G + pal[i].B; - if (! l) + if (! l) ++l; int r = f(pal[i].R, l), g = f(pal[i].G, l), b = f(pal[i].B, l); uint16 D = ((r > R) ? (r - R) : (R - r)) + @@ -303,7 +303,7 @@ uint8 Closest(CBLK *pal, CBLK x) { if (D < dif) { found = i; dif = D; - if (D == 0) + if (D == 0) break; // exact! } } diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index a8da163b331..4287c12d638 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -83,7 +83,7 @@ char *VMGather(CHOICE *list) { if (vmgt) { *vmgt = '\0'; for (cp = list; cp->Text; cp ++) { - if (*vmgt) + if (*vmgt) strcat(vmgt, "|"); strcat(vmgt, cp->Text); ++ h; @@ -104,13 +104,13 @@ VMENU::VMENU(CHOICE *list, int x, int y) Addr = this; delete[] vmgt; Items = 0; - for (cp = list; cp->Text; cp ++) + for (cp = list; cp->Text; cp ++) ++Items; Flags.BDel = true; Flags.Kill = true; - if (x < 0 || y < 0) + if (x < 0 || y < 0) Center(); - else + else Goto(x - W / 2, y - (TEXT_VM + FONT_HIG / 2)); VGA::ShowQ.Insert(this, VGA::ShowQ.Last()); Bar = new MENU_BAR(W - 2 * TEXT_HM); @@ -136,9 +136,9 @@ void VMENU::Touch(uint16 mask, int x, int y) { //if if (y >= 0) { n = y / h; - if (n < Items) + if (n < Items) ok = (x >= TEXT_HM && x < W - TEXT_HM/* && y % h < FONT_HIG*/); - else + else n = Items - 1; } diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 46282d2bbe6..9b6489afab3 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -56,7 +56,7 @@ VFILE::VFILE(const char *name, IOMODE mode) EndMark = (BufMark = BegMark = kp->Mark) + kp->Size; } #ifdef VOL_UPD - else + else Make(name); #endif } @@ -80,7 +80,7 @@ void VFILE::ReadBuff(void) { } BufMark = Dat.File.Mark(); long n = EndMark - BufMark; - if (n > IOBUF_SIZE) + if (n > IOBUF_SIZE) n = IOBUF_SIZE; Lim = Dat.File.Read(Buff, (uint16) n); Ptr = 0; From aa1d8986a698ebf9b740ed1720baff4e5b091613 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 13 Jun 2011 13:13:39 +0200 Subject: [PATCH 016/276] CGE: Cleanup: also remove trailing tabs --- engines/cge/bitmap.cpp | 2 +- engines/cge/cfile.cpp | 2 +- engines/cge/general.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 1e5310a8e79..2763c00868d 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -125,7 +125,7 @@ BITMAP::BITMAP(const BITMAP &bmp) : W(bmp.W), H(bmp.H), M(NULL), V(NULL) { BITMAP::~BITMAP(void) { if (MemType(M) == FAR_MEM) free(M); - + switch (MemType(V)) { case NEAR_MEM : delete[](uint8 *) V; diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 4fb0988d381..72ec73030fd 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -239,7 +239,7 @@ long CFILE::Seek(long pos) { WriteBuff(); else Lim = 0; - + Ptr = 0; return BufMark = IOHAND::Seek(pos); } diff --git a/engines/cge/general.h b/engines/cge/general.h index 7c0bd7f7629..11468326237 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -74,7 +74,7 @@ public: COUPLE operator + (COUPLE c) { return COUPLE(A + c.A, B + c.B); } - + void operator += (COUPLE c) { A += c.A; B += c.B; From 9918344cdc596d211c2c03b5c31f669f06c89f0f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 13 Jun 2011 13:44:52 +0200 Subject: [PATCH 017/276] CGE: Fix several issues reported by CPPCHECK --- engines/cge/bitmap.cpp | 2 +- engines/cge/cge_main.cpp | 7 +++---- engines/cge/snail.cpp | 3 +-- engines/cge/text.cpp | 2 +- engines/cge/vga13h.cpp | 10 ++++------ engines/cge/vmenu.cpp | 3 +-- 6 files changed, 11 insertions(+), 16 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 2763c00868d..36723aba28e 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -348,7 +348,7 @@ bool BITMAP::SolidAt(int x, int y) { return true; break; } - m += (t == REP) ? 1 : w; + m += ((t == REP) ? 1 : w); } } diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 24964da0fcc..64a20293bd6 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -668,7 +668,7 @@ static void MiniStep(int stp) { static void PostMiniStep(int stp) { - static int recent = -2; + //static int recent = -2; //TODO Change the SNPOST message send to a special way to send function pointer //if (MiniCave && stp != recent) SNPOST_(SNEXEC, -1, recent = stp, (void *)&MiniStep); warning("STUB: PostMiniStep()"); @@ -843,7 +843,6 @@ void SwitchCave(int cav) { void SYSTEM::Touch(uint16 mask, int x, int y) { static int pp = 0; void SwitchCave(int cav); - int cav = 0; FunTouch(); @@ -968,7 +967,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { } else { if (Startup) return; - + int cav = 0; InfoLine.Update(NULL); if (y >= WORLD_HIG) { if (x < BUTTON_X) { // select cave? @@ -998,7 +997,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { #ifdef DEBUG if (!HorzLine.Flags.Hide) { if (y >= MAP_TOP && y < MAP_TOP + MAP_HIG) { - signed char x1, z1; + int8 x1, z1; XZ(x, y).Split(x1, z1); CLUSTER::Map[z1][x1] = 1; SetMapBrick(x1, z1); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index cc52ec63dc9..3fedeab04dc 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -164,7 +164,6 @@ static void SNGame(SPRITE *spr, int num) { case 2 : { static SPRITE *k = NULL, * k1, * k2, * k3; static int count = 0; - bool hit; if (k == NULL) { k = VGA::ShowQ.Locate(20700); @@ -188,7 +187,7 @@ static void SNGame(SPRITE *spr, int num) { } ///-------------------- SNPOST(SNSETZ, 20700, 0, NULL); - hit = (k1->SeqPtr + k2->SeqPtr + k3->SeqPtr == 15); + bool hit = (k1->SeqPtr + k2->SeqPtr + k3->SeqPtr == 15); if (hit) { if (spr->Ref == 1) { SNPOST(SNSAY, 1, 20003, NULL); // hura! diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 92951196c7b..9b79147cff0 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -199,7 +199,7 @@ void Say(const char *txt, SPRITE *spr) { } x = (east) ? (spr->X + spr->W - 2) : (spr->X + 2 - sw); if (spr->Ref == 1) - x += (east) ? -10 : 10; // Hero + x += ((east) ? -10 : 10); // Hero Talk->Flags.Kill = true; Talk->Flags.BDel = true; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 3f303e7f29f..72831e83cf2 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -279,9 +279,9 @@ extern "C" void TimerProc (void) void ENGINE::NewTimer(...) { + /* static SPRITE *spr; static uint8 run = 0, cntr1 = TMR_RATE1, cntr2 = TMR_RATE2; - /* ___1152_Hz___: SNDMIDIPlay(); @@ -502,9 +502,7 @@ SPRITE *SPRITE::Expand(void) { neacnt = 0, takcnt = 0, maxnow = 0, - maxnxt = 0, - lcnt = 0, - len; + maxnxt = 0; SNAIL::COM *nea = NULL; SNAIL::COM *tak = NULL; @@ -513,9 +511,9 @@ SPRITE *SPRITE::Expand(void) { INI_FILE sprf(fname); if (! OK(sprf)) error("Bad SPR [%s]", fname); - + int len = 0, lcnt = 0; while ((len = sprf.Read((uint8 *)line)) != 0) { - ++ lcnt; + ++lcnt; if (len && line[len - 1] == '\n') line[-- len] = '\0'; if (len == 0 || *line == '.') diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 4287c12d638..4e1a3334bf8 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -126,14 +126,13 @@ VMENU::~VMENU(void) { void VMENU::Touch(uint16 mask, int x, int y) { #define h (FONT_HIG + TEXT_LS) - int n = 0; bool ok = false; if (Items) { SPRITE::Touch(mask, x, y); y -= TEXT_VM - 1; - //if + int n = 0; if (y >= 0) { n = y / h; if (n < Items) From 44cf1872e22dc673dde422faa255a1fd7e6e78e8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 13 Jun 2011 18:23:48 +0200 Subject: [PATCH 018/276] CGE: Fix one linker error --- engines/cge/general.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index e68533d0b2c..03e5126436a 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -93,6 +93,8 @@ DAC StdPal[] = {// R G B { 255, 255, 255}, // 255 }; +DRVINFO SNDDrvInfo; + EC void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)) { warning("STUB: _fqsort"); } From 1ebe182ba1f707bbc10afb3626a30fed89ceb923 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 14 Jun 2011 23:54:59 +0200 Subject: [PATCH 019/276] CGE: Fix the remaining link errors. It now crashes instantly, most likely because of the VGA class --- engines/cge/general.cpp | 46 +++++++++++++++++++++++++++++++++++++++++ engines/cge/general.h | 6 +----- engines/cge/snail.cpp | 5 +++-- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 03e5126436a..73e5b4d21f4 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -363,5 +363,51 @@ long Timer(void) { warning("STUB: Timer"); return 0; } + +int new_random(int range) { + warning("STUB: new_random(a)"); + return 0; +} + +#define TIMER_INT 0x08 +//void interrupt (* ENGINE::OldTimer) (...) = NULL; + +ENGINE::ENGINE (uint16 tdiv) +{ +/* + // steal timer interrupt + OldTimer = getvect(TIMER_INT); + setvect(TIMER_INT, NewTimer); + + // set turbo-timer mode + asm mov al,0x36 + asm out 0x43,al + asm mov ax,TMR_DIV + asm out 0x40,al + asm mov al,ah + asm out 0x40,al +*/ + warning("STUB: ENGINE::ENGINE"); +} + +ENGINE::~ENGINE (void) +{ +/* + // reset timer + asm mov al,0x36 + asm out 0x43,al + asm xor al,al + asm out 0x40,al + asm out 0x40,al + // bring back timer interrupt + setvect(TIMER_INT, OldTimer); +*/ + warning("STUB: ENGINE::~ENGINE"); +} + +DATACK::~DATACK (void) +{ + if (!e && Buf) free(Buf); +} } // End of namespace CGE diff --git a/engines/cge/general.h b/engines/cge/general.h index 11468326237..1fc8bd0b0bc 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -60,10 +60,6 @@ typedef struct { typedef uint16 CRYPT(void *buf, uint16 siz, uint16 seed); -extern Common::RandomSource randSrc; - -#define new_random(a) (randSrc.getRandomNumber(a)) - class COUPLE { protected: signed char A; @@ -237,7 +233,7 @@ char *dwtom(uint32 val, char * str, int radix, int len); int TakeEnum(const char **tab, const char *txt); Boot *ReadBoot(int drive); long Timer(void); - +int new_random(int range); } // End of namespace CGE #endif diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 3fedeab04dc..b2f4648e101 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -905,7 +905,7 @@ static void SNMouse(bool on) { void SNAIL::RunCom(void) { static int count = 1; - extern void SwitchCave(int); +// extern void SwitchCave(int); if (! Busy) { Busy = true; uint8 tmphea = Head; @@ -971,7 +971,8 @@ void SNAIL::RunCom(void) { } break; case SNCAVE : - SwitchCave(snc->Val); + // SwitchCave(snc->Val); + warning("Problematic call of SwitchCave in SNAIL::RunCom"); break; case SNKILL : SNKill(sprel); From 77d5c25472f414c2b0c49a920329a6811d271281 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 18 Jun 2011 08:54:22 +0200 Subject: [PATCH 020/276] CGE: Suppress some defines, fix semi-columns in template definitions --- engines/cge/bitmaps.cpp | 2 - engines/cge/bitmaps.h | 3 - engines/cge/btfile.cpp | 16 ++--- engines/cge/btfile.h | 2 +- engines/cge/cge_main.cpp | 137 ++++++++------------------------------- engines/cge/ems.cpp | 2 +- engines/cge/general.h | 8 +-- engines/cge/jbw.h | 22 +------ engines/cge/mouse.cpp | 14 +--- engines/cge/snail.cpp | 7 +- engines/cge/startup.cpp | 11 ---- engines/cge/vga13h.cpp | 21 +----- engines/cge/vga13h.h | 2 +- 13 files changed, 52 insertions(+), 195 deletions(-) diff --git a/engines/cge/bitmaps.cpp b/engines/cge/bitmaps.cpp index 77012c0488b..cabe04b784f 100644 --- a/engines/cge/bitmaps.cpp +++ b/engines/cge/bitmaps.cpp @@ -224,7 +224,6 @@ static uint8 MEDesign[][9] = { { R R R R R R R R R }, // 0 namespace CGE { -#ifdef DEBUG BMP_PTR MB[] = { new BITMAP("BRICK"), NULL @@ -234,7 +233,6 @@ BMP_PTR HL[] = { new BITMAP("HLINE"), NULL }; -#endif BMP_PTR MC[] = { new BITMAP("MOUSE"), diff --git a/engines/cge/bitmaps.h b/engines/cge/bitmaps.h index 5023c2e6572..5ac878de3cf 100644 --- a/engines/cge/bitmaps.h +++ b/engines/cge/bitmaps.h @@ -32,11 +32,8 @@ namespace CGE { -#ifdef DEBUG extern BITMAP *MB[]; extern BITMAP *HL[]; -#endif - extern BITMAP *MC[]; extern BITMAP *PR[]; extern BITMAP *SP[]; diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index b5e59e09882..7bb835f704a 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -46,7 +46,7 @@ BTFILE::BTFILE(const char *name, IOMODE mode, CRYPT *crpt) Buff[i].Page = new BT_PAGE; Buff[i].PgNo = BT_NONE; Buff[i].Indx = -1; - Buff[i].Updt = FALSE; + Buff[i].Updt = false; if (Buff[i].Page == NULL) error("No core"); } @@ -65,7 +65,7 @@ void BTFILE::PutPage(int lev, bool hard) { if (hard || Buff[lev].Updt) { Seek(Buff[lev].PgNo * sizeof(BT_PAGE)); Write((uint8 *) Buff[lev].Page, sizeof(BT_PAGE)); - Buff[lev].Updt = FALSE; + Buff[lev].Updt = false; } } @@ -78,12 +78,12 @@ BT_PAGE *BTFILE::GetPage(int lev, uint16 pgn) { if (Size() > pos) { Seek((uint32) pgn * sizeof(BT_PAGE)); Read((uint8 *) Buff[lev].Page, sizeof(BT_PAGE)); - Buff[lev].Updt = FALSE; + Buff[lev].Updt = false; } else { Buff[lev].Page->Hea.Count = 0; Buff[lev].Page->Hea.Down = BT_NONE; memset(Buff[lev].Page->Data, '\0', sizeof(Buff[lev].Page->Data)); - Buff[lev].Updt = TRUE; + Buff[lev].Updt = true; } Buff[lev].Indx = -1; } @@ -132,17 +132,17 @@ void BTFILE::Make(BT_KEYPACK *keypack, uint16 count) { BT_PAGE *Root = GetPage(0, n++), *Leaf = GetPage(1, n); Root->Hea.Down = n; - PutPage(0, TRUE); + PutPage(0, true); while (count --) { if (Leaf->Hea.Count >= ArrayCount(Leaf->Lea)) { - PutPage(1, TRUE); // save filled page + PutPage(1, true); // save filled page Leaf = GetPage(1, ++n); // take empty page memcpy(Root->Inn[Root->Hea.Count].Key, keypack->Key, BT_KEYLEN); Root->Inn[Root->Hea.Count ++].Down = n; - Buff[0].Updt = TRUE; + Buff[0].Updt = true; } Leaf->Lea[Leaf->Hea.Count ++] = * (keypack ++); - Buff[1].Updt = TRUE; + Buff[1].Updt = true; } } diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index c55891cae4d..3ab4880585c 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -73,7 +73,7 @@ class BTFILE : public IOHAND { int Indx; bool Updt; } Buff[BT_LEVELS]; - void PutPage(int lev, bool hard = FALSE); + void PutPage(int lev, bool hard = false); BT_PAGE *GetPage(int lev, uint16 pgn); public: BTFILE(const char *name, IOMODE mode = REA, CRYPT *crpt = NULL); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 64a20293bd6..22168fe44c9 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -59,21 +59,8 @@ namespace CGE { #define STACK_SIZ (K(2)) #define SVGCHKSUM (1956+Now+OldLev+Game+Music+DemoText) -#ifdef DEMO -#ifdef DEBUG #define SVG0NAME ("{{INIT}}" SVG_EXT) -#else -#define SVG0NAME (ProgName(SVG_EXT)) -#endif -#else -#define SVG0NAME ("{{INIT}}" SVG_EXT) -#endif - -#ifdef DEBUG #define SVG0FILE CFILE -#else -#define SVG0FILE INI_FILE -#endif extern uint16 _stklen = (STACK_SIZ * 2); @@ -152,9 +139,7 @@ extern int FindPocket(SPRITE *); extern DAC StdPal[58]; -#ifdef DEBUG static SPRITE HorzLine = HL; -#endif void FeedSnail(SPRITE *spr, SNLIST snq); // defined in SNAIL uint8 CLUSTER::Map[MAP_ZCNT][MAP_XCNT]; @@ -204,7 +189,7 @@ bool CLUSTER::Protected(void) { */ warning("STUB: CLUSTER::Protected()"); - return TRUE; + return true; } @@ -548,8 +533,6 @@ void WALK::Reach(SPRITE *spr, int mode) { } -#ifdef DEBUG - class SQUARE : public SPRITE { public: SQUARE(void); @@ -586,14 +569,11 @@ static void SetMapBrick(int x, int z) { } } -#endif - - void dummy(void) {} static void SwitchMapping(void); static void SwitchColorMode(void); static void StartCountDown(void); -Debug(static void SwitchDebug(void);) +static void SwitchDebug(void); static void SwitchMusic(void); static void KillSprite(void); static void PushSprite(void); @@ -642,13 +622,6 @@ static void Quit(void) { static void AltCtrlDel(void) { -#if 0 - //def DEBUG - if (KEYBOARD::Key[LSHIFT] || KEYBOARD::Key[RSHIFT]) { - PostFlag = 0x1234; - POST(); - } else -#endif SNPOST_(SNSAY, -1, A_C_D_TEXT, Hero); } @@ -774,18 +747,18 @@ static void CaveUp(void) { static void CaveDown(void) { SPRITE *spr; - Debug(if (! HorzLine.Flags.Hide) SwitchMapping();) + if (! HorzLine.Flags.Hide) + SwitchMapping(); - for (spr = VGA::ShowQ.First(); spr;) { - SPRITE *n = spr->Next; - if (spr->Ref >= 1000 /*&& spr->Cave*/) { - if (spr->Ref % 1000 == 999) - FeedSnail(spr, TAKE); - - VGA::SpareQ.Append(VGA::ShowQ.Remove(spr)); - } - spr = n; + for (spr = VGA::ShowQ.First(); spr;) { + SPRITE *n = spr->Next; + if (spr->Ref >= 1000 /*&& spr->Cave*/) { + if (spr->Ref % 1000 == 999) + FeedSnail(spr, TAKE); + VGA::SpareQ.Append(VGA::ShowQ.Remove(spr)); } + spr = n; + } Text.Clear(1000); } @@ -857,10 +830,11 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { pp0 = pp; switch (x) { case Del: - if (KEYBOARD::Key[ALT] && - KEYBOARD::Key[CTRL]) AltCtrlDel(); - Debug(else KillSprite();) - break; + if (KEYBOARD::Key[ALT] && KEYBOARD::Key[CTRL]) + AltCtrlDel(); + else + KillSprite(); + break; case 'F': if (KEYBOARD::Key[ALT]) { SPRITE *m = VGA::ShowQ.Locate(17001); @@ -870,8 +844,6 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { } } break; - -#ifdef DEBUG case PgUp: PushSprite(); break; @@ -932,19 +904,6 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { if (Sprite) Sprite->Step(x - '0'); break; -#else - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - SelectPocket(x - '1'); - break; -#endif - case F10 : if (Snail.Idle() && ! Hero->Flags.Hide) StartCountDown(); @@ -994,7 +953,6 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { if (cav && Snail.Idle() && Hero->TracePtr < 0) SwitchCave(cav); -#ifdef DEBUG if (!HorzLine.Flags.Hide) { if (y >= MAP_TOP && y < MAP_TOP + MAP_HIG) { int8 x1, z1; @@ -1003,7 +961,6 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { SetMapBrick(x1, z1); } } else -#endif { if (! Talk && Snail.Idle() && Hero && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && ! Game) { @@ -1119,7 +1076,6 @@ static void TakeName(void) { #endif -#ifdef DEBUG static void SwitchMapping(void) { if (HorzLine.Flags.Hide) { int i; @@ -1200,10 +1156,6 @@ static void SaveMapping(void) { } } -#endif - - -#ifdef DEBUG // 1111111111222222222233333333 334444444444555555555566666666667777777777 // 01234567890123456789012345678901234567 890123456789012345678901234567890123456789 static char DebugText[] = " N=00000 F=000000 X=000 Y=000 FPS=0000\0S=00:00 000:000:000 000:000 00 "; @@ -1272,8 +1224,6 @@ static void SwitchDebug(void) { DebugLine.Flags.Hide = ! DebugLine.Flags.Hide; } -#endif - static void OptionTouch(int opt, uint16 mask) { switch (opt) { @@ -1304,7 +1254,7 @@ void SPRITE::Touch(uint16 mask, int x, int y) { if ((mask & ATTN) == 0) { InfoLine.Update(Name()); if (mask & (R_DN | L_DN)) - Sprite = this; // DEBUG mode only? + Sprite = this; if (Ref / 10 == 12) { OptionTouch(Ref % 10, mask); return; @@ -1582,50 +1532,20 @@ static void LoadScript(const char *fname) { static void MainLoop(void) { -#if 0 -//def DEBUG - static VgaRegBlk Mode[] = { - - { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode - - { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 - { 0x05, VGAGRA, 0x03, 0x00 }, // R/W mode = 0 - { 0x06, VGAGRA, 0x02, 0x00 }, // misc - - { 0x14, VGACRT, 0x40, 0x00 }, // underline - { 0x13, VGACRT, 0xFF, 0x28 }, // screen width - { 0x17, VGACRT, 0xFF, 0xC3 }, // mode control - - { 0x11, VGACRT, 0x80, 0x00 }, // vert retrace end - { 0x09, VGACRT, 0xEF, 0x01 }, // max scan line - - { 0x30, VGAATR, 0x00, 0x20 }, // 256 color mode - -// { 0x12, VGACRT, 0xFF, 0x6E }, // vert display end -// { 0x15, VGACRT, 0xFF, 0x7F }, // start vb -// { 0x10, VGACRT, 0xFF, 0x94 }, // start vr - - { 0x00 } - }; - - Vga.Setup(Mode); -#endif - - Debug(SayDebug();) + SayDebug(); #ifdef DEMO -#define TIM ((182L*6L) * 5L) static uint32 tc = 0; - if (TimerCount - tc >= TIM && Talk == NULL && Snail.Idle()) { + if (/* FIXME: TimerCount - tc >= ((182L*6L) * 5L) && */ Talk == NULL && Snail.Idle()) { if (Text[DemoText]) { SNPOST(SNSOUND, -1, 4, NULL); // drumla SNPOST(SNINF, -1, DemoText, NULL); SNPOST(SNLABEL, -1, -1, NULL); - if (Text[++ DemoText] == NULL) DemoText = DEMO_TEXT + 1; + if (Text[++ DemoText] == NULL) + DemoText = DEMO_TEXT + 1; } - tc = TimerCount; + //FIXME: tc = TimerCount; } -#undef TIM #endif Vga.Show(); @@ -1727,14 +1647,12 @@ static void RunGame(void) { InfoLine.Update(NULL); VGA::ShowQ.Insert(&InfoLine); -#ifdef DEBUG DebugLine.Z = 126; VGA::ShowQ.Insert(&DebugLine); HorzLine.Y = MAP_TOP - (MAP_TOP > 0); HorzLine.Z = 126; VGA::ShowQ.Insert(&HorzLine); -#endif Mouse.Busy = VGA::SpareQ.Locate(BUSY_REF); if (Mouse.Busy) @@ -1897,13 +1815,10 @@ bool ShowTitle(const char *name) { /* -#ifdef DEBUG -void StkDump (void) -{ +void StkDump (void) { CFILE f("!STACK.DMP", BFW); f.Write((uint8 *) (intStackPtr-STACK_SIZ/2), STACK_SIZ*2); } -#endif */ @@ -1920,8 +1835,8 @@ void cge_main(void) { if (! SVG0FILE::Exist(SVG0NAME)) STARTUP::Mode = 2; - Debug(DebugLine.Flags.Hide = true;) - Debug(HorzLine.Flags.Hide = true;) + DebugLine.Flags.Hide = true; + HorzLine.Flags.Hide = true; //srand((uint16) Timer()); Sys = new SYSTEM; diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp index 7b0697cd8a0..c21bc356dcb 100644 --- a/engines/cge/ems.cpp +++ b/engines/cge/ems.cpp @@ -127,7 +127,7 @@ bool EMM::Test(void) { return FALSE; */ warning("EMM::Test"); - return FALSE; + return false; } diff --git a/engines/cge/general.h b/engines/cge/general.h index 1fc8bd0b0bc..c1c417c2372 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -146,19 +146,19 @@ void Swap(T &A, T &B) { T a = A; A = B; B = a; -}; +} #ifdef __cplusplus template T max(T A, T B) { return (A > B) ? A : B; -}; +} template T min(T A, T B) { return (A < B) ? A : B; -}; +} #endif @@ -179,7 +179,7 @@ public: template inline uint16 XRead(XFILE *xf, T *t) { return xf->Read((uint8 *) t, sizeof(*t)); -}; +} class IOHAND : public XFILE { diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 73131d71e33..4a341fbbb7d 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -33,8 +33,8 @@ namespace CGE { // Defines found in cge.mak -#define DEBUG #define VOL +//#define DEMO #define INI_FILE VFILE // Or is it CFILE? #define PIC_FILE VFILE #define BMP_MODE 0 @@ -46,15 +46,8 @@ namespace CGE { #define LF 10 #define FF 12 #define CR 13 - -#define TRUE 1 -#define FALSE 0 - #define MAXFILE 128 - -#define NULL 0 -#define OFF false -#define ON true +#define NULL 0 #define IsWhite(c) ((c) == ' ' || (c) == '\t' || (c) == '\n') #define IsUpper(c) ((c) >= 'A' && (c) <= 'Z') @@ -148,17 +141,6 @@ struct KeyStatStruct { #define BreakFlag (* ((volatile uint8 *) ((void _seg *) 0x40 + (void *) 0x71))) #define PostFlag (* ((volatile uint16 *) ((void _seg *) 0x40 + (void *) 0x72))) #define POST ((void (*)(void)) ((void _seg *) 0xF000 + (void *) 0xFFF0)) -#define SLIF if (KeyStat.ScrollLock) - -#define FOR(i,n) for(i = 0; i < (n); i++) - -#define TRAP(x) { warning("STUB: TRAP"); /*if (x) asm { int 3 } */ } - -#ifdef DEBUG -#define Debug(x) x -#else -#define Debug(x) -#endif #ifdef DEMO #define Demo(x) x diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index 9bb9626deb4..601d02999ff 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -167,13 +167,8 @@ void MOUSE::Tick(void) { Hold = e.Ptr; if (Hold) { Hold->Flags.Hold = true; -#ifndef DEBUG - if (Hold->Flags.Drag) -#endif - { - hx = e.X - Hold->X; - hy = e.Y - Hold->Y; - } + hx = e.X - Hold->X; + hy = e.Y - Hold->Y; } } @@ -192,10 +187,7 @@ void MOUSE::Tick(void) { EvtTail = (EvtTail + 1) % EVT_MAX; } if (Hold) -#ifndef DEBUG - if (Hold->Flags.Drag) -#endif - Hold->Goto(X - hx, Y - hy); + Hold->Goto(X - hx, Y - hy); } } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index b2f4648e101..382b6dbc627 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -90,8 +90,7 @@ static void SNGame(SPRITE *spr, int num) { ++ Stage; if (hand && Stage > DRESSED) ++hand; - if (Debug(i >= 0 ||) - dup[i] == spr && new_random(3) == 0) { + if (i >= 0 || dup[i] == spr && new_random(3) == 0) { SNPOST(SNSEQ, -1, 3, dup[0]); // yes SNPOST(SNSEQ, -1, 3, dup[1]); // yes SNPOST(SNSEQ, -1, 3, dup[2]); // yes @@ -629,7 +628,7 @@ void SNCover(SPRITE *spr, int xref) { xspr->Cave = spr->Cave; xspr->Goto(spr->X, spr->Y); ExpandSprite(xspr); - if ((xspr->Flags.Shad = spr->Flags.Shad) == TRUE) { + if ((xspr->Flags.Shad = spr->Flags.Shad) == 1) { VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr->Prev), xspr); spr->Flags.Shad = false; } @@ -643,7 +642,7 @@ void SNUncover(SPRITE *spr, SPRITE *xspr) { spr->Flags.Hide = false; spr->Cave = xspr->Cave; spr->Goto(xspr->X, xspr->Y); - if ((spr->Flags.Shad = xspr->Flags.Shad) == TRUE) { + if ((spr->Flags.Shad = xspr->Flags.Shad) == 1) { VGA::ShowQ.Insert(VGA::ShowQ.Remove(xspr->Prev), spr); xspr->Flags.Shad = false; } diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 24aaf3e042a..10967afbc4b 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -35,10 +35,7 @@ #include #include #include - -#ifdef DEBUG #include -#endif namespace CGE { @@ -124,14 +121,6 @@ STARTUP::STARTUP(void) { if (Cpu() < _80286) quit_now(BAD_CHIP_TEXT); if (100 * _osmajor + _osminor < 330) quit_now(BAD_DOS_TEXT); - #ifndef DEBUG - if (Core < CORE_LOW) quit_now(NO_CORE_TEXT); - if (Core < CORE_HIG) - { - SNDDrvInfo.MDEV = DEV_QUIET; - Music = false; - } - #endif if (! get_parms()) quit_now(BAD_ARG_TEXT); //--- load sound configuration const char * fn = UsrPath(ProgName(CFG_EXT)); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 72831e83cf2..c1587fa45ae 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -40,25 +40,14 @@ namespace CGE { -#ifdef DEBUG -#define REPORT -#endif - -#define OK(f) ((f).Error==0) #define FADE_STEP 2 - #define TMR_DIV ((0x8000/TMR_RATE)*2) - //-------------------------------------------------------------------------- -#ifdef REPORT static char Report[] = "NearHeap=..... FarHeap=......\n"; #define NREP 9 #define FREP 24 -#endif - - static VgaRegBlk VideoMode[] = { @@ -377,7 +366,6 @@ BMP_PTR SPRITE::Shp(void) { if (e) if (e->Seq) { int i = e->Seq[SeqPtr].Now; -#ifdef DEBUG if (i >= ShpCnt) { //char s[256]; //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", @@ -385,7 +373,6 @@ BMP_PTR SPRITE::Shp(void) { //VGA::Exit(s, File); error("Invalid PHASE in SPRITE::Shp() %s", File); } -#endif return e->ShpList[i]; } return NULL; @@ -509,7 +496,7 @@ SPRITE *SPRITE::Expand(void) { MergeExt(fname, File, SPR_EXT); if (INI_FILE::Exist(fname)) { // sprite description file exist INI_FILE sprf(fname); - if (! OK(sprf)) + if (! (sprf.Error==0)) error("Bad SPR [%s]", fname); int len = 0, lcnt = 0; while ((len = sprf.Read((uint8 *)line)) != 0) { @@ -936,14 +923,12 @@ VGA::VGA(int mode) if (txt) { // puts(txt); warning(txt); -#ifndef DEBUG std = false; -#endif } } -// if (std) + if (std) // warning(Copr); - warning("TODO: Fix Copr"); + warning("TODO: Fix Copr"); SetStatAdr(); if (StatAdr != VGAST1_) diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index b7622689569..2660274c233 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -309,7 +309,7 @@ uint8 Closest(CBLK *pal, CBLK x) { } return found; #undef f -}; +} From 3871c71f0e6f5202e935ac7119fefedde1f8e449 Mon Sep 17 00:00:00 2001 From: eriktorbjorn Date: Sun, 19 Jun 2011 07:59:37 +0200 Subject: [PATCH 021/276] CGE: Fix compilation under GCC Unfortunately, I had to stub a few things but this all looks like code that will have to be rewritten later anyway. --- engines/cge/bitmap.cpp | 1 - engines/cge/btfile.cpp | 2 ++ engines/cge/btfile.h | 9 +++++---- engines/cge/cfile.cpp | 1 - engines/cge/cfile.h | 1 - engines/cge/cge_main.cpp | 3 --- engines/cge/cge_main.h | 4 ++-- engines/cge/game.cpp | 1 - engines/cge/general.cpp | 17 +++++++++++++++++ engines/cge/general.h | 9 ++++----- engines/cge/jbw.h | 1 - engines/cge/keybd.cpp | 1 - engines/cge/mouse.cpp | 1 - engines/cge/snail.cpp | 9 ++++++++- engines/cge/startup.cpp | 2 -- engines/cge/talk.cpp | 1 - engines/cge/text.cpp | 1 - engines/cge/vga13h.cpp | 3 --- engines/cge/vga13h.h | 2 +- engines/cge/wav.h | 2 +- 20 files changed, 40 insertions(+), 31 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 36723aba28e..b528b5578d5 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -29,7 +29,6 @@ #include "cge/cfile.h" #include "cge/jbw.h" #include "cge/vol.h" -#include #include "cge/cfile.h" #include "common/system.h" diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 7bb835f704a..3cdb3c71992 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -90,6 +90,8 @@ BT_PAGE *BTFILE::GetPage(int lev, uint16 pgn) { return Buff[lev].Page; } +// Does this work, or does it have to compare the entire buffer? +#define memicmp(s1, s2, n) scumm_strnicmp((const char *)s1, (const char *)s2, n) BT_KEYPACK *BTFILE::Find(const char *key) { int lev = 0; diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 3ab4880585c..6e6398f4de3 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -46,6 +46,10 @@ struct BT_KEYPACK { uint16 Size; }; +typedef struct { + uint8 Key[BT_KEYLEN]; + uint16 Down; +} INNER; struct BT_PAGE { struct HEA { @@ -56,10 +60,7 @@ struct BT_PAGE { // dummy filler to make proper size of union uint8 Data[BT_SIZE - sizeof(HEA)]; // inner version of data: key + word-sized page link - struct INNER { - uint8 Key[BT_KEYLEN]; - uint16 Down; - } Inn[(BT_SIZE - sizeof(HEA)) / sizeof(INNER)]; + INNER Inn[(BT_SIZE - sizeof(HEA)) / sizeof(INNER)]; // leaf version of data: key + all user data BT_KEYPACK Lea[(BT_SIZE - sizeof(HEA)) / sizeof(BT_KEYPACK)]; }; diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 72ec73030fd..da56587ebed 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -26,7 +26,6 @@ */ #include "cge/cfile.h" -#include #include #include #include "common/system.h" diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index d2d5320ae55..f045c48c0f1 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -29,7 +29,6 @@ #define __CFILE__ #include "cge/general.h" -#include namespace CGE { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 22168fe44c9..8cfa3a1cf6d 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -44,13 +44,10 @@ #include "cge/gettext.h" #include "cge/mixer.h" #include "cge/cge_main.h" -#include #include #include #include -#include #include -#include #include "common/str.h" diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index fa27274803e..3c9fede6fb9 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -28,8 +28,8 @@ #ifndef __CGE__ #define __CGE__ -#include "cge\wav.h" -#include "cge\vga13h.h" +#include "cge/wav.h" +#include "cge/vga13h.h" namespace CGE { diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 4102e080b61..655cfbe4ecf 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -28,7 +28,6 @@ #include "cge/game.h" #include "cge/mouse.h" #include -#include namespace CGE { diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 73e5b4d21f4..e547921bb50 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -251,22 +251,39 @@ uint16 IOHAND::Write(void *buf, uint16 len) { } long IOHAND::Mark(void) { + /* return (Handle < 0) ? 0 : tell(Handle); + */ + warning("STUB: IOHAND::Mark"); + return 0; } long IOHAND::Seek(long pos) { + /* if (Handle < 0) return 0; lseek(Handle, pos, SEEK_SET); return tell(Handle); + */ + warning("STUB: IOHAND::Seek"); + return 0; } long IOHAND::Size(void) { + /* if (Handle < 0) return 0; + return filelength(Handle); + */ + warning("STUB: IOHAND::Size"); + return 0; } bool IOHAND::Exist(const char *name) { + /* return access(name, 0) == 0; + */ + warning("STUB: IOHAND::Exist"); + return 0; } //#define EMS_ADR(a) (FP_SEG(a) > 0xA000) diff --git a/engines/cge/general.h b/engines/cge/general.h index c1c417c2372..16b0c1e2bf2 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -33,7 +33,6 @@ #include "common/textconsole.h" #include "common/str.h" #include "cge/jbw.h" -#include #include "cge/boot.h" namespace CGE { @@ -114,22 +113,22 @@ class EMS; class EMM { - friend EMS; + friend class EMS; bool Test(void); long Top, Lim; EMS *List; int Han; static void *Frame; public: - EMM::EMM(long size = 0); - EMM::~EMM(void); + EMM(long size = 0); + ~EMM(void); EMS *Alloc(uint16 siz); void Release(void); }; class EMS { - friend EMM; + friend class EMM; EMM *Emm; long Ptr; uint16 Siz; diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 4a341fbbb7d..82647ed49af 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -47,7 +47,6 @@ namespace CGE { #define FF 12 #define CR 13 #define MAXFILE 128 -#define NULL 0 #define IsWhite(c) ((c) == ' ' || (c) == '\t' || (c) == '\n') #define IsUpper(c) ((c) >= 'A' && (c) <= 'Z') diff --git a/engines/cge/keybd.cpp b/engines/cge/keybd.cpp index 35e6c72c112..c912555949b 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/keybd.cpp @@ -27,7 +27,6 @@ #include "cge/keybd.h" #include "cge/mouse.h" -#include namespace CGE { diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index 601d02999ff..78e686ff953 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -27,7 +27,6 @@ #include "cge/mouse.h" #include "cge/text.h" -#include namespace CGE { diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 382b6dbc627..ec1fae515c6 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -33,13 +33,20 @@ #include "cge/text.h" #include "cge/mouse.h" #include "cge/cge_main.h" -#include #include #include #include "cge/keybd.h" namespace CGE { +static void _enable() { + warning("STUB: _enable"); +} + +static void _disable() { + warning("STUB: _disable"); +} + int MaxCave = 0; SCB Scb = { NULL, 0, NULL }; diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 10967afbc4b..e534e042570 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -32,8 +32,6 @@ #include "cge/cfile.h" #include "cge/snddrv.h" #include -#include -#include #include #include diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index e707e4e7056..f4c0c1ac27b 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -30,7 +30,6 @@ #include "cge/vol.h" #include "cge/game.h" #include "cge/mouse.h" -#include namespace CGE { diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 9b79147cff0..3695c955f5e 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -35,7 +35,6 @@ #include #include #include -#include namespace CGE { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index c1587fa45ae..a7dd76273d1 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -30,13 +30,10 @@ #include "cge/bitmap.h" #include "cge/vol.h" #include "cge/text.h" -#include #include #include #include -#include #include -#include namespace CGE { diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 2660274c233..19453a4523d 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -129,7 +129,7 @@ extern SEQ Seq2[]; class HEART : public ENGINE { - friend ENGINE; + friend class ENGINE; public: static bool Enable; static uint16 *XTimer; diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 6d46769cf99..304c2827d8f 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -95,7 +95,7 @@ class FMTCK : public CKHEA { } Wav; union { - struct PCM { + struct { uint16 wBitsPerSample; // Sample size } Pcm; }; From ac3d66d3dd56837d55e9ba42a1d2f9481e7846c8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 19 Jun 2011 10:09:25 +0200 Subject: [PATCH 022/276] CGE: (Eriktorbjorn) Fix compilation for GCC --- engines/cge/btfile.cpp | 2 +- engines/cge/game.cpp | 1 - engines/cge/general.cpp | 50 ++++++++++++++++++++++------------------- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 3cdb3c71992..0552e78c1cc 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -92,7 +92,7 @@ BT_PAGE *BTFILE::GetPage(int lev, uint16 pgn) { // Does this work, or does it have to compare the entire buffer? #define memicmp(s1, s2, n) scumm_strnicmp((const char *)s1, (const char *)s2, n) - + BT_KEYPACK *BTFILE::Find(const char *key) { int lev = 0; uint16 nxt = BT_ROOT; diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 655cfbe4ecf..58334f2e532 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -29,7 +29,6 @@ #include "cge/mouse.h" #include - namespace CGE { uint8 *Glass(DAC *pal, uint8 r, uint8 g, uint8 b) { diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index e547921bb50..7e1653f61af 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -237,51 +237,55 @@ uint16 IOHAND::Read(void *buf, uint16 len) { } uint16 IOHAND::Write(void *buf, uint16 len) { - /* - if (len) { - if (Mode == REA || Handle < 0) return 0; - if (Crypt) Seed = Crypt(buf, len, Seed); - Error = _dos_write(Handle, buf, len, &len); - if (Crypt) Seed = Crypt(buf, len, Seed); //------$$$$$$$ - } - return len; - */ +/* + if (len) { + if (Mode == REA || Handle < 0) + return 0; + if (Crypt) + Seed = Crypt(buf, len, Seed); + Error = _dos_write(Handle, buf, len, &len); + if (Crypt) + Seed = Crypt(buf, len, Seed); //------$$$$$$$ + } + return len; +*/ warning("STUB: IOHAND::Write"); return 0; } long IOHAND::Mark(void) { - /* - return (Handle < 0) ? 0 : tell(Handle); - */ +/* + return (Handle < 0) ? 0 : tell(Handle); +*/ warning("STUB: IOHAND::Mark"); return 0; } long IOHAND::Seek(long pos) { - /* - if (Handle < 0) return 0; - lseek(Handle, pos, SEEK_SET); - return tell(Handle); - */ +/* + if (Handle < 0) + return 0; + lseek(Handle, pos, SEEK_SET); + return tell(Handle); +*/ warning("STUB: IOHAND::Seek"); return 0; } long IOHAND::Size(void) { - /* - if (Handle < 0) return 0; - +/* + if (Handle < 0) + return 0; return filelength(Handle); - */ +*/ warning("STUB: IOHAND::Size"); return 0; } bool IOHAND::Exist(const char *name) { - /* +/* return access(name, 0) == 0; - */ +*/ warning("STUB: IOHAND::Exist"); return 0; } From 78e3f2a57bc0442066e00c9b625bbdde3c80ddf9 Mon Sep 17 00:00:00 2001 From: eriktorbjorn Date: Sun, 19 Jun 2011 11:17:54 +0200 Subject: [PATCH 023/276] CGE: Get rid of some static initializing ScummVM itself (not the engine; I haven't tried that) now starts without crashing. It exits immediately, but as far as I can tell it does not crash. It still produces lots of Valgrind warnings, though... --- engines/cge/cge.cpp | 5 ++++ engines/cge/cge_main.cpp | 56 ++++++++++++++++++++-------------------- engines/cge/cge_main.h | 3 +++ engines/cge/config.cpp | 10 +++---- engines/cge/gettext.cpp | 4 +-- engines/cge/mixer.cpp | 2 +- engines/cge/snail.cpp | 4 +-- engines/cge/startup.cpp | 2 +- engines/cge/talk.cpp | 18 ++++++------- engines/cge/talk.h | 2 +- engines/cge/text.cpp | 10 +++---- engines/cge/text.h | 4 +-- engines/cge/vga13h.cpp | 2 +- 13 files changed, 64 insertions(+), 58 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 0d0df4ea9cf..8b3bea3eb5f 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -31,6 +31,7 @@ #include "engines/util.h" #include "cge/cge.h" #include "cge/cge_main.h" +#include "cge/text.h" namespace CGE { @@ -39,6 +40,10 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel"); _console = new CGEConsole(this); + Text = new TEXT(ProgName()); + Vga = new VGA(M13H); + + OffUseCount = atoi(Text->getText(OFF_USE_COUNT)); debug("CGEEngine::CGEEngine"); } diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 8cfa3a1cf6d..6472cdef0b6 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -117,14 +117,14 @@ static SPRITE *Sprite = NULL; static SPRITE *MiniCave = NULL; static SPRITE *Shadow = NULL; -static VGA Vga = M13H; +VGA *Vga; static EMS *Mini = MiniEmm.Alloc((uint16)MINI_EMM_SIZE); static BMP_PTR *MiniShpList = NULL; static BMP_PTR MiniShp[] = { NULL, NULL }; static KEYBOARD Keyboard; static bool Finis = false; static int Startup = 1; -static int OffUseCount = atoi(Text[OFF_USE_COUNT]); +int OffUseCount; uint16 *intStackPtr = false; @@ -248,7 +248,7 @@ static void LoadGame(XFILE &file, bool tiny = false) { file.Read((uint8 *) &i, sizeof(i)); if (i != SVGCHKSUM) - error(Text[BADSVG_TEXT]); + error(Text->getText(BADSVG_TEXT)); if (STARTUP::Core < CORE_HIG) Music = false; @@ -608,9 +608,9 @@ static void Quit(void) { SNPOST_(SNKILL, -1, 0, VMENU::Addr); ResetQSwitch(); } else { - QuitMenu[0].Text = Text[QUIT_TEXT]; - QuitMenu[1].Text = Text[NOQUIT_TEXT]; - (new VMENU(QuitMenu, -1, -1))->SetName(Text[QUIT_TITLE]); + QuitMenu[0].Text = Text->getText(QUIT_TEXT); + QuitMenu[1].Text = Text->getText(NOQUIT_TEXT); + (new VMENU(QuitMenu, -1, -1))->SetName(Text->getText(QUIT_TITLE)); SNPOST_(SNSEQ, 123, 1, NULL); KeyClick(); } @@ -687,7 +687,7 @@ static void CaveUp(void) { ShowBak(BakRef); LoadMapping(); - Text.Preload(BakRef, BakRef + 1000); + Text->Preload(BakRef, BakRef + 1000); SPRITE *spr = VGA::SpareQ.First(); while (spr) { SPRITE *n = spr->Next; @@ -716,7 +716,7 @@ static void CaveUp(void) { } if (! Dark) - Vga.Sunset(); + Vga->Sunset(); VGA::CopyPage(0, 1); SelectPocket(-1); @@ -730,10 +730,10 @@ static void CaveUp(void) { Shadow->Z = Hero->Z; } FeedSnail(VGA::ShowQ.Locate(BakRef + 999), TAKE); - Vga.Show(); - Vga.CopyPage(1, 0); - Vga.Show(); - Vga.Sunrise(SysPal); + Vga->Show(); + Vga->CopyPage(1, 0); + Vga->Show(); + Vga->Sunrise(SysPal); Dark = false; if (! Startup) Mouse.On(); @@ -756,7 +756,7 @@ static void CaveDown(void) { } spr = n; } - Text.Clear(1000); + Text->Clear(1000); } @@ -772,7 +772,7 @@ static void QGame(void) { SaveSound(); CFILE file = CFILE(UsrPath(UsrFnam), WRI, RCrypt); SaveGame(file); - Vga.Sunset(); + Vga->Sunset(); Finis = true; } @@ -1060,9 +1060,9 @@ static void TakeName(void) { if (GET_TEXT::Ptr) SNPOST_(SNKILL, -1, 0, GET_TEXT::Ptr); else { - GET_TEXT *tn = new GET_TEXT(Text[GETNAME_PROMPT], UsrFnam, 8, KeyClick); + GET_TEXT *tn = new GET_TEXT(Text->getText(GETNAME_PROMPT), UsrFnam, 8, KeyClick); if (tn) { - tn->SetName(Text[GETNAME_TITLE]); + tn->SetName(Text->getText(GETNAME_TITLE)); tn->Center(); tn->Goto(tn->X, tn->Y - 10); tn->Z = 126; @@ -1183,7 +1183,7 @@ static void SayDebug(void) { if (t1 - t >= 18) { static uint32 old = 0L; - uint32 now = Vga.FrmCnt; + uint32 now = Vga->FrmCnt; dwtom(now - old, FRPS, 10, 4); old = now; t = t1; @@ -1534,18 +1534,18 @@ static void MainLoop(void) { #ifdef DEMO static uint32 tc = 0; if (/* FIXME: TimerCount - tc >= ((182L*6L) * 5L) && */ Talk == NULL && Snail.Idle()) { - if (Text[DemoText]) { + if (Text->getText(DemoText)) { SNPOST(SNSOUND, -1, 4, NULL); // drumla SNPOST(SNINF, -1, DemoText, NULL); SNPOST(SNLABEL, -1, -1, NULL); - if (Text[++ DemoText] == NULL) + if (Text->getText(++ DemoText) == NULL) DemoText = DEMO_TEXT + 1; } //FIXME: tc = TimerCount; } #endif - Vga.Show(); + Vga->Show(); Snail_.RunCom(); Snail.RunCom(); } @@ -1573,8 +1573,8 @@ void LoadUser(void) { static void RunGame(void) { - Text.Clear(); - Text.Preload(100, 1000); + Text->Clear(); + Text->Preload(100, 1000); LoadHeroXY(); CavLight.Flags.Tran = true; @@ -1722,11 +1722,11 @@ bool ShowTitle(const char *name) { Talk->Show(2); } - Vga.Sunset(); + Vga->Sunset(); VGA::CopyPage(1, 2); VGA::CopyPage(0, 1); SelectPocket(-1); - Vga.Sunrise(SysPal); + Vga->Sunrise(SysPal); if (STARTUP::Mode < 2 && ! STARTUP::SoundOk) { VGA::CopyPage(1, 2); @@ -1788,7 +1788,7 @@ bool ShowTitle(const char *name) { CFILE file = CFILE(n, REA, RCrypt); LoadGame(file, true); // only system vars VGA::SetColors(SysPal, 64); - Vga.Update(); + Vga->Update(); if (FINIS) { ++ STARTUP::Mode; FINIS = false; @@ -1828,7 +1828,7 @@ void cge_main(void) { memset(Barriers, 0xFF, sizeof(Barriers)); if (! Mouse.Exist) - error("%s", Text[NO_MOUSE_TEXT]); + error("%s", Text->getText(NO_MOUSE_TEXT)); if (! SVG0FILE::Exist(SVG0NAME)) STARTUP::Mode = 2; @@ -1851,8 +1851,8 @@ void cge_main(void) { if (FINIS) Movie("X03"); } else - Vga.Sunset(); - error("%s", Text[EXIT_OK_TEXT + FINIS]); + Vga->Sunset(); + error("%s", Text->getText(EXIT_OK_TEXT + FINIS)); } } // End of namespace CGE diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 3c9fede6fb9..fe50e7bab30 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -169,6 +169,9 @@ void ExpandSprite(SPRITE *spr); void ContractSprite(SPRITE *spr); void cge_main(void); +extern VGA *Vga; +extern int OffUseCount; + } // End of namespace CGE #endif diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 19000935209..9ffda8d6356 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -159,11 +159,11 @@ void SelectSound(void) { Sound.Close(); if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); - Inf(Text[STYPE_TEXT]); + Inf(Text->getText(STYPE_TEXT)); Talk->Goto(Talk->X, FONT_HIG / 2); for (i = 0; i < ArrayCount(DevName); i ++) - DevMenu[i].Text = Text[DevName[i]]; - (new VMENU(DevMenu, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text[MENU_TEXT]); + DevMenu[i].Text = Text->getText(DevName[i]); + (new VMENU(DevMenu, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); } @@ -196,9 +196,9 @@ static CHOICE *Cho; static int Hlp; static void SNSelect(void) { - Inf(Text[Hlp]); + Inf(Text->getText(Hlp)); Talk->Goto(Talk->X, FONT_HIG / 2); - (new VMENU(Cho, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text[MENU_TEXT]); + (new VMENU(Cho, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); } diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 4399a30916e..e11f4ff3089 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -38,7 +38,7 @@ GET_TEXT *GET_TEXT::Ptr = NULL; GET_TEXT::GET_TEXT(const char *info, char *text, int size, void (*click)(void)) : Text(text), Size(min(size, GTMAX)), Len(min(Size, strlen(text))), Cntr(GTBLINK), Click(click), OldKeybClient(KEYBOARD::SetClient(this)) { - int i = 2 * TEXT_HM + Font.Width(info); + int i = 2 * TEXT_HM + Font->Width(info); Ptr = this; Mode = RECT; TS[0] = Box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); @@ -106,7 +106,7 @@ void GET_TEXT::Touch(uint16 mask, int x, int y) { if (p) x = ogon[p - bezo]; } - if (Len < Size && 2 * TEXT_HM + Font.Width(Buff) + Font.Wid[x] <= W) { + if (Len < Size && 2 * TEXT_HM + Font->Width(Buff) + Font->Wid[x] <= W) { Buff[Len + 2] = Buff[Len + 1]; Buff[Len + 1] = Buff[Len]; Buff[Len ++] = x; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 83d9cd1be56..5b65eee9cab 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -44,7 +44,7 @@ MIXER::MIXER(int x, int y) : SPRITE(NULL), Fall(MIX_FALL) { mb[0] = new BITMAP("VOLUME"); mb[1] = NULL; SetShapeList(mb); - SetName(Text[MIX_NAME]); + SetName(Text->getText(MIX_NAME)); Flags.Syst = true; Flags.Kill = true; Flags.BDel = true; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index ec1fae515c6..29ab11a36ed 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -959,13 +959,13 @@ void SNAIL::RunCom(void) { if (sprel && TalkEnable) { if (sprel == Hero && sprel->SeqTest(-1)) sprel->Step(HTALK); - Say(Text[snc->Val], sprel); + Say(Text->getText(snc->Val), sprel); SYSTEM::FunDel = HEROFUN0; } break; case SNINF : if (TalkEnable) { - Inf(Text[snc->Val]); + Inf(Text->getText(snc->Val)); SYSTEM::FunDel = HEROFUN0; } break; diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index e534e042570..631a64d732c 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -54,7 +54,7 @@ uint16 STARTUP::Summa; void quit_now(int ref) { - error("%d\n", Text[ref]); + error("%s", Text->getText(ref)); } diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index f4c0c1ac27b..1739511a498 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -97,14 +97,12 @@ void FONT::Save(void) { */ -FONT TALK::Font(ProgName()); - - TALK::TALK(const char *tx, TBOX_STYLE mode) : SPRITE(NULL), Mode(mode) { TS[0] = TS[1] = NULL; Flags.Syst = true; Update(tx); + Font = new FONT(ProgName()); } @@ -144,7 +142,7 @@ void TALK::Update(const char *tx) { mw = k; k = 2 * hmarg; } else - k += Font.Wid[*p]; + k += Font->Wid[*p]; } if (k > mw) mw = k; @@ -157,8 +155,8 @@ void TALK::Update(const char *tx) { if (*tx == '|' || *tx == '\n') m = TS[0]->M + (ln += FONT_HIG + TEXT_LS) * mw + hmarg; else { - int cw = Font.Wid[*tx], i; - uint8 *f = Font.Map + Font.Pos[*tx]; + int cw = Font->Wid[*tx], i; + uint8 *f = Font->Map + Font->Pos[*tx]; for (i = 0; i < cw; i++) { uint8 *p = m; uint16 n; @@ -255,8 +253,8 @@ void TALK::PutLine(int line, const char *text) { q = v + size; while (* text) { - uint16 cw = Font.Wid[*text], i; - uint8 *fp = Font.Map + Font.Pos[*text]; + uint16 cw = Font->Wid[*text], i; + uint8 *fp = Font->Map + Font->Pos[*text]; for (i = 0; i < cw; i ++) { register uint16 b = fp[i]; @@ -303,8 +301,8 @@ void INFO_LINE::Update(const char *tx) { uint8 *p = v + 2, * q = p + size; while (*tx) { - uint16 cw = Font.Wid[*tx]; - uint8 *fp = Font.Map + Font.Pos[*tx]; + uint16 cw = Font->Wid[*tx]; + uint8 *fp = Font->Map + Font->Pos[*tx]; for (uint16 i = 0; i < cw; i++) { register uint16 b = fp[i]; diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 568fd829641..67b4fc91d62 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -74,7 +74,7 @@ protected: BITMAP *TS[2]; BITMAP *Box(uint16 w, uint16 h); public: - static FONT Font; + FONT *Font; TALK(const char *tx, TBOX_STYLE mode = PURE); TALK(void); //~TALK (void); diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 3695c955f5e..bbb69839ddb 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -38,7 +38,7 @@ namespace CGE { -TEXT Text = ProgName(); +TEXT *Text; TALK *Talk = NULL; TEXT::TEXT(const char *fname, int size) { @@ -163,7 +163,7 @@ char *TEXT::Load(int idx, int ref) { } -char *TEXT::operator [](int ref) { +char *TEXT::getText(int ref) { int i; if ((i = Find(ref)) < Size) return Cache[i].Txt; @@ -202,7 +202,7 @@ void Say(const char *txt, SPRITE *spr) { Talk->Flags.Kill = true; Talk->Flags.BDel = true; - Talk->SetName(Text[SAY_NAME]); + Talk->SetName(Text->getText(SAY_NAME)); Talk->Goto(x - (Talk->W - sw) / 2 - 3 + 6 * east, y - spike->H - Talk->H + 1); Talk->Z = 125; Talk->Ref = SAY_REF; @@ -211,7 +211,7 @@ void Say(const char *txt, SPRITE *spr) { spike->Z = 126; spike->Flags.Slav = true; spike->Flags.Kill = true; - spike->SetName(Text[SAY_NAME]); + spike->SetName(Text->getText(SAY_NAME)); spike->Step(east); spike->Ref = SAY_REF; @@ -226,7 +226,7 @@ void Inf(const char *txt) { if (Talk) { Talk->Flags.Kill = true; Talk->Flags.BDel = true; - Talk->SetName(Text[INF_NAME]); + Talk->SetName(Text->getText(INF_NAME)); Talk->Center(); Talk->Goto(Talk->X, Talk->Y - 20); Talk->Z = 126; diff --git a/engines/cge/text.h b/engines/cge/text.h index 7cf3922c5ac..c7782103040 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -65,12 +65,12 @@ public: ~TEXT(void); void Clear(int from = 1, int upto = 0x7FFF); void Preload(int from = 1, int upto = 0x7FFF); - char *operator[](int ref); + char *getText(int ref); }; extern TALK *Talk; -extern TEXT Text; +extern TEXT *Text; void Say(const char *txt, SPRITE *spr); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index a7dd76273d1..52015c27f1e 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -916,7 +916,7 @@ VGA::VGA(int mode) bool std = true; int i; for (i = 10; i < 20; i ++) { - char *txt = Text[i]; + char *txt = Text->getText(i); if (txt) { // puts(txt); warning(txt); From 40f95669aeb60a50c2736d71008f0e3461654f4f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 20 Jun 2011 00:13:41 +0200 Subject: [PATCH 024/276] CGE: As there's only one instance of VGA, suppress all the static keywords from it --- engines/cge/cge_main.cpp | 122 ++++++++++++++++++++------------------- engines/cge/mixer.cpp | 5 +- engines/cge/snail.cpp | 42 +++++++------- engines/cge/text.cpp | 7 ++- engines/cge/vga13h.cpp | 43 +++++++------- engines/cge/vga13h.h | 47 ++++++++------- engines/cge/vmenu.cpp | 5 +- 7 files changed, 138 insertions(+), 133 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 6472cdef0b6..c6c6a3961bc 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -224,7 +224,7 @@ struct SAVTAB { { &Game, sizeof(Game), 1 }, // spare 2 { &Game, sizeof(Game), 1 }, // spare 3 { &Game, sizeof(Game), 1 }, // spare 4 - { &VGA::Mono, sizeof(VGA::Mono), 0 }, +// { &VGA::Mono, sizeof(VGA::Mono), 0 }, { &Music, sizeof(Music), 1 }, { volume, sizeof(volume), 1 }, { Flag, sizeof(Flag), 1 }, @@ -273,12 +273,12 @@ static void LoadGame(XFILE &file, bool tiny = false) { if (spr == NULL) error("No core"); *spr = S; - VGA::SpareQ.Append(spr); + Vga->SpareQ->Append(spr); } for (i = 0; i < POCKET_NX; i ++) { register int r = pocref[i]; - Pocket[i] = (r < 0) ? NULL : VGA::SpareQ.Locate(r); + Pocket[i] = (r < 0) ? NULL : Vga->SpareQ->Locate(r); } } } @@ -311,7 +311,7 @@ static void SaveGame(XFILE &file) { file.Write((uint8 *) & (i = SVGCHKSUM), sizeof(i)); - for (spr = VGA::SpareQ.First(); spr; spr = spr->Next) + for (spr = Vga->SpareQ->First(); spr; spr = spr->Next) if (spr->Ref >= 1000) if (!file.Error) file.Write((uint8 *)spr, sizeof(*spr)); @@ -386,7 +386,7 @@ void WALK::Tick(void) { if (Dir != NO_DIR) { SPRITE *spr; SYSTEM::FunTouch(); - for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { + for (spr = Vga->ShowQ->First(); spr; spr = spr->Next) { if (Distance(spr) < 2) { if (! spr->Flags.Near) { FeedSnail(spr, NEAR); @@ -562,7 +562,7 @@ static void SetMapBrick(int x, int z) { wtom(z, n + 3, 10, 2); CLUSTER::Map[z][x] = 1; s->SetName(n); - VGA::ShowQ.Insert(s, VGA::ShowQ.First()); + Vga->ShowQ->Insert(s, Vga->ShowQ->First()); } } @@ -667,13 +667,13 @@ void SYSTEM::FunTouch(void) { static void ShowBak(int ref) { - SPRITE *spr = VGA::SpareQ.Locate(ref); + SPRITE *spr = Vga->SpareQ->Locate(ref); if (spr) { BITMAP::Pal = SysPal; spr->Expand(); BITMAP::Pal = NULL; spr->Show(2); - VGA::CopyPage(1, 2); + Vga->CopyPage(1, 2); SYSTEM::SetPal(); spr->Contract(); } @@ -688,7 +688,7 @@ static void CaveUp(void) { ShowBak(BakRef); LoadMapping(); Text->Preload(BakRef, BakRef + 1000); - SPRITE *spr = VGA::SpareQ.First(); + SPRITE *spr = Vga->SpareQ->First(); while (spr) { SPRITE *n = spr->Next; if (spr->Cave == Now || spr->Cave == 0) @@ -718,18 +718,18 @@ static void CaveUp(void) { if (! Dark) Vga->Sunset(); - VGA::CopyPage(0, 1); + Vga->CopyPage(0, 1); SelectPocket(-1); if (Hero) - VGA::ShowQ.Insert(VGA::ShowQ.Remove(Hero)); + Vga->ShowQ->Insert(Vga->ShowQ->Remove(Hero)); if (Shadow) { - VGA::ShowQ.Remove(Shadow); + Vga->ShowQ->Remove(Shadow); Shadow->MakeXlat(Glass(SysPal, 204, 204, 204)); - VGA::ShowQ.Insert(Shadow, Hero); + Vga->ShowQ->Insert(Shadow, Hero); Shadow->Z = Hero->Z; } - FeedSnail(VGA::ShowQ.Locate(BakRef + 999), TAKE); + FeedSnail(Vga->ShowQ->Locate(BakRef + 999), TAKE); Vga->Show(); Vga->CopyPage(1, 0); Vga->Show(); @@ -747,12 +747,12 @@ static void CaveDown(void) { if (! HorzLine.Flags.Hide) SwitchMapping(); - for (spr = VGA::ShowQ.First(); spr;) { + for (spr = Vga->ShowQ->First(); spr;) { SPRITE *n = spr->Next; if (spr->Ref >= 1000 /*&& spr->Cave*/) { if (spr->Ref % 1000 == 999) FeedSnail(spr, TAKE); - VGA::SpareQ.Append(VGA::ShowQ.Remove(spr)); + Vga->SpareQ->Append(Vga->ShowQ->Remove(spr)); } spr = n; } @@ -793,14 +793,15 @@ void SwitchCave(int cav) { Hero->Step(0); #ifndef DEMO ///// protection: auto-destruction on! ---------------------- - VGA::SpareQ.Show = STARTUP::Summa * (cav <= CAVE_MAX); + Vga->SpareQ->Show = STARTUP::Summa * (cav <= CAVE_MAX); /////-------------------------------------------------------- #endif } CavLight.Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); KillText(); - if (! Startup) KeyClick(); + if (! Startup) + KeyClick(); SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint //TODO Change the SNPOST message send to a special way to send function pointer //SNPOST(SNEXEC, 0, 0, (void *)&XCave); // switch cave @@ -834,7 +835,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { break; case 'F': if (KEYBOARD::Key[ALT]) { - SPRITE *m = VGA::ShowQ.Locate(17001); + SPRITE *m = Vga->ShowQ->Locate(17001); if (m) { m->Step(1); m->Time = 216; // 3s @@ -1017,9 +1018,9 @@ static void SpkClose(void) { static void SwitchColorMode(void) { - SNPOST_(SNSEQ, 121, VGA::Mono = ! VGA::Mono, NULL); + SNPOST_(SNSEQ, 121, Vga->Mono = !Vga->Mono, NULL); KeyClick(); - VGA::SetColors(SysPal, 64); + Vga->SetColors(SysPal, 64); } @@ -1066,7 +1067,7 @@ static void TakeName(void) { tn->Center(); tn->Goto(tn->X, tn->Y - 10); tn->Z = 126; - VGA::ShowQ.Insert(tn); + Vga->ShowQ->Insert(tn); } } } @@ -1085,7 +1086,7 @@ static void SwitchMapping(void) { } } else { SPRITE *s; - for (s = VGA::ShowQ.First(); s; s = s->Next) + for (s = Vga->ShowQ->First(); s; s = s->Next) if (s->W == MAP_XGRID && s->H == MAP_ZGRID) SNPOST_(SNKILL, -1, 0, s); } @@ -1104,7 +1105,7 @@ static void KillSprite(void) { static void PushSprite(void) { SPRITE *spr = Sprite->Prev; if (spr) { - VGA::ShowQ.Insert(VGA::ShowQ.Remove(Sprite), spr); + Vga->ShowQ->Insert(Vga->ShowQ->Remove(Sprite), spr); while (Sprite->Z > Sprite->Next->Z) --Sprite->Z; } else @@ -1121,7 +1122,7 @@ static void PullSprite(void) { ok = (!spr->Flags.Slav); } if (ok) { - VGA::ShowQ.Insert(VGA::ShowQ.Remove(Sprite), spr); + Vga->ShowQ->Insert(Vga->ShowQ->Remove(Sprite), spr); if (Sprite->Prev) while (Sprite->Z < Sprite->Prev->Z) ++Sprite->Z; @@ -1197,7 +1198,7 @@ static void SayDebug(void) { // sprite queue size uint16 n = 0; SPRITE *spr; - for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { + for (spr = Vga->ShowQ->First(); spr; spr = spr->Next) { ++ n; if (spr == Sprite) { *XSPR = ' '; @@ -1463,7 +1464,7 @@ static void LoadSprite(const char *fname, int ref, int cav, int col = 0, int row warning("LoadSprite: use of fnsplit"); Sprite->ShpCnt = shpcnt; - VGA::SpareQ.Append(Sprite); + Vga->SpareQ->Append(Sprite); } } @@ -1578,7 +1579,7 @@ static void RunGame(void) { LoadHeroXY(); CavLight.Flags.Tran = true; - VGA::ShowQ.Append(&CavLight); + Vga->ShowQ->Append(&CavLight); CavLight.Flags.Hide = true; static SEQ PocSeq[] = { { 0, 0, 0, 0, 20 }, @@ -1593,18 +1594,18 @@ static void RunGame(void) { PocLight.Flags.Tran = true; PocLight.Time = 1; PocLight.Z = 120; - VGA::ShowQ.Append(&PocLight); + Vga->ShowQ->Append(&PocLight); SelectPocket(-1); - VGA::ShowQ.Append(&Mouse); + Vga->ShowQ->Append(&Mouse); // ___________ LoadUser(); // ~~~~~~~~~~~ - if ((Sprite = VGA::SpareQ.Locate(121)) != NULL) - SNPOST_(SNSEQ, -1, VGA::Mono, Sprite); - if ((Sprite = VGA::SpareQ.Locate(122)) != NULL) + if ((Sprite = Vga->SpareQ->Locate(121)) != NULL) + SNPOST_(SNSEQ, -1, Vga->Mono, Sprite); + if ((Sprite = Vga->SpareQ->Locate(122)) != NULL) Sprite->Step(Music); SNPOST_(SNSEQ, -1, Music, Sprite); if (! Music) @@ -1634,7 +1635,7 @@ static void RunGame(void) { Shadow->Ref = 2; Shadow->Flags.Tran = true; Hero->Flags.Shad = true; - VGA::ShowQ.Insert(VGA::SpareQ.Remove(Shadow), Hero); + Vga->ShowQ->Insert(Vga->SpareQ->Remove(Shadow), Hero); } } } @@ -1642,16 +1643,16 @@ static void RunGame(void) { InfoLine.Goto(INFO_X, INFO_Y); InfoLine.Flags.Tran = true; InfoLine.Update(NULL); - VGA::ShowQ.Insert(&InfoLine); + Vga->ShowQ->Insert(&InfoLine); DebugLine.Z = 126; - VGA::ShowQ.Insert(&DebugLine); + Vga->ShowQ->Insert(&DebugLine); HorzLine.Y = MAP_TOP - (MAP_TOP > 0); HorzLine.Z = 126; - VGA::ShowQ.Insert(&HorzLine); + Vga->ShowQ->Insert(&HorzLine); - Mouse.Busy = VGA::SpareQ.Locate(BUSY_REF); + Mouse.Busy = Vga->SpareQ->Locate(BUSY_REF); if (Mouse.Busy) ExpandSprite(Mouse.Busy); @@ -1676,8 +1677,8 @@ static void RunGame(void) { SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); Mouse.Off(); - VGA::ShowQ.Clear(); - VGA::SpareQ.Clear(); + Vga->ShowQ->Clear(); + Vga->SpareQ->Clear(); Hero = NULL; Shadow = NULL; } @@ -1687,9 +1688,9 @@ void Movie(const char *ext) { const char *fn = ProgName(ext); if (INI_FILE::Exist(fn)) { LoadScript(fn); - ExpandSprite(VGA::SpareQ.Locate(999)); - FeedSnail(VGA::ShowQ.Locate(999), TAKE); - VGA::ShowQ.Append(&Mouse); + ExpandSprite(Vga->SpareQ->Locate(999)); + FeedSnail(Vga->ShowQ->Locate(999), TAKE); + Vga->ShowQ->Append(&Mouse); HEART::Enable = true; KEYBOARD::SetClient(Sys); while (! Snail.Idle()) { @@ -1699,8 +1700,8 @@ void Movie(const char *ext) { HEART::Enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); - VGA::ShowQ.Clear(); - VGA::SpareQ.Clear(); + Vga->ShowQ->Clear(); + Vga->SpareQ->Clear(); } } @@ -1723,23 +1724,23 @@ bool ShowTitle(const char *name) { } Vga->Sunset(); - VGA::CopyPage(1, 2); - VGA::CopyPage(0, 1); + Vga->CopyPage(1, 2); + Vga->CopyPage(0, 1); SelectPocket(-1); Vga->Sunrise(SysPal); if (STARTUP::Mode < 2 && ! STARTUP::SoundOk) { - VGA::CopyPage(1, 2); - VGA::CopyPage(0, 1); - VGA::ShowQ.Append(&Mouse); + Vga->CopyPage(1, 2); + Vga->CopyPage(0, 1); + Vga->ShowQ->Append(&Mouse); HEART::Enable = true; Mouse.On(); for (SelectSound(); ! Snail.Idle() || VMENU::Addr;) MainLoop(); Mouse.Off(); HEART::Enable = false; - VGA::ShowQ.Clear(); - VGA::CopyPage(0, 2); + Vga->ShowQ->Clear(); + Vga->CopyPage(0, 2); STARTUP::SoundOk = 2; if (Music) LoadMIDI(0); @@ -1766,9 +1767,9 @@ bool ShowTitle(const char *name) { #endif //----------------------------------------- Movie("X00"); // paylist - VGA::CopyPage(1, 2); - VGA::CopyPage(0, 1); - VGA::ShowQ.Append(&Mouse); + Vga->CopyPage(1, 2); + Vga->CopyPage(0, 1); + Vga->ShowQ->Append(&Mouse); //Mouse.On(); HEART::Enable = true; for (TakeName(); GET_TEXT::Ptr;) @@ -1779,15 +1780,15 @@ bool ShowTitle(const char *name) { if (usr_ok) strcat(UsrFnam, SVG_EXT); //Mouse.Off(); - VGA::ShowQ.Clear(); - VGA::CopyPage(0, 2); + Vga->ShowQ->Clear(); + Vga->CopyPage(0, 2); #endif if (usr_ok && STARTUP::Mode == 0) { const char *n = UsrPath(UsrFnam); if (CFILE::Exist(n)) { CFILE file = CFILE(n, REA, RCrypt); LoadGame(file, true); // only system vars - VGA::SetColors(SysPal, 64); + Vga->SetColors(SysPal, 64); Vga->Update(); if (FINIS) { ++ STARTUP::Mode; @@ -1801,7 +1802,7 @@ bool ShowTitle(const char *name) { if (STARTUP::Mode < 2) Movie("X01"); // wink - VGA::CopyPage(0, 2); + Vga->CopyPage(0, 2); #ifdef DEMO return true; @@ -1844,7 +1845,8 @@ void cge_main(void) { Movie(LGO_EXT); if (ShowTitle("WELCOME")) { #ifndef DEMO - if (STARTUP::Mode == 1) Movie("X02"); // intro + if (STARTUP::Mode == 1) + Movie("X02"); // intro #endif RunGame(); Startup = 2; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 5b65eee9cab..c1b69d40c2b 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -30,6 +30,7 @@ #include "cge/snail.h" #include "cge/mouse.h" #include "cge/snddrv.h" +#include "cge/cge_main.h" #include namespace CGE { @@ -75,9 +76,9 @@ MIXER::MIXER(int x, int y) : SPRITE(NULL), Fall(MIX_FALL) { } Led[ArrayCount(Led) - 1]->Flags.BDel = true; - VGA::ShowQ.Insert(this); + Vga->ShowQ->Insert(this); for (i = 0; i < ArrayCount(Led); i ++) - VGA::ShowQ.Insert(Led[i]); + Vga->ShowQ->Insert(Led[i]); //--- reset balance i = (SNDDrvInfo.VOL4.ML + SNDDrvInfo.VOL4.MR) / 2; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 29ab11a36ed..f40d2bc2faa 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -80,7 +80,7 @@ static void SNGame(SPRITE *spr, int num) { int buref = 0; int Stage = 0; - for (dup[0] = VGA::ShowQ.First(); dup[0]; dup[0] = dup[0]->Next) { + for (dup[0] = Vga->ShowQ->First(); dup[0]; dup[0] = dup[0]->Next) { buref = dup[0]->Ref; if (buref / 1000 == 16 && buref % 100 == 6) { Stage = (buref / 100) % 10; @@ -88,8 +88,8 @@ static void SNGame(SPRITE *spr, int num) { } } if (dup[1] == NULL) { - dup[1] = VGA::ShowQ.Locate(16003); // pan - dup[2] = VGA::ShowQ.Locate(16004); // pani + dup[1] = Vga->ShowQ->Locate(16003); // pan + dup[2] = Vga->ShowQ->Locate(16004); // pani } if (Game) { // continue game @@ -172,10 +172,10 @@ static void SNGame(SPRITE *spr, int num) { static int count = 0; if (k == NULL) { - k = VGA::ShowQ.Locate(20700); - k1 = VGA::ShowQ.Locate(20701); - k2 = VGA::ShowQ.Locate(20702); - k3 = VGA::ShowQ.Locate(20703); + k = Vga->ShowQ->Locate(20700); + k1 = Vga->ShowQ->Locate(20701); + k2 = Vga->ShowQ->Locate(20702); + k3 = Vga->ShowQ->Locate(20703); } if (! Game) { // init @@ -282,13 +282,13 @@ static void SNGame(SPRITE *spr, int num) { void ExpandSprite(SPRITE *spr) { if (spr) - VGA::ShowQ.Insert(VGA::SpareQ.Remove(spr)); + Vga->ShowQ->Insert(Vga->SpareQ->Remove(spr)); } void ContractSprite(SPRITE *spr) { if (spr) - VGA::SpareQ.Append(VGA::ShowQ.Remove(spr)); + Vga->SpareQ->Append(Vga->ShowQ->Remove(spr)); } int FindPocket(SPRITE *spr) { @@ -515,10 +515,10 @@ static void SNZTrim(SPRITE *spr) { SPRITE *s; HEART::Enable = false; s = (spr->Flags.Shad) ? spr->Prev : NULL; - VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr)); + Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr)); if (s) { s->Z = spr->Z; - VGA::ShowQ.Insert(VGA::ShowQ.Remove(s), spr); + Vga->ShowQ->Insert(Vga->ShowQ->Remove(s), spr); } HEART::Enable = en; } @@ -636,7 +636,7 @@ void SNCover(SPRITE *spr, int xref) { xspr->Goto(spr->X, spr->Y); ExpandSprite(xspr); if ((xspr->Flags.Shad = spr->Flags.Shad) == 1) { - VGA::ShowQ.Insert(VGA::ShowQ.Remove(spr->Prev), xspr); + Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr->Prev), xspr); spr->Flags.Shad = false; } FeedSnail(xspr, NEAR); @@ -650,7 +650,7 @@ void SNUncover(SPRITE *spr, SPRITE *xspr) { spr->Cave = xspr->Cave; spr->Goto(xspr->X, xspr->Y); if ((spr->Flags.Shad = xspr->Flags.Shad) == 1) { - VGA::ShowQ.Insert(VGA::ShowQ.Remove(xspr->Prev), spr); + Vga->ShowQ->Insert(Vga->ShowQ->Remove(xspr->Prev), spr); xspr->Flags.Shad = false; } spr->Z = xspr->Z; @@ -725,7 +725,7 @@ void SNSlave(SPRITE *spr, int ref) { SNSend(slv, spr->Cave); slv->Flags.Slav = true; slv->Z = spr->Z; - VGA::ShowQ.Insert(VGA::ShowQ.Remove(slv), spr->Next); + Vga->ShowQ->Insert(Vga->ShowQ->Remove(slv), spr->Next); } } } @@ -752,13 +752,13 @@ void SNKill(SPRITE *spr) { } SPRITE *nx = spr->Next; Hide1(spr); - VGA::ShowQ.Remove(spr); + Vga->ShowQ->Remove(spr); MOUSE::ClrEvt(spr); if (spr->Flags.Kill) delete spr; else { spr->Cave = -1; - VGA::SpareQ.Append(spr); + Vga->SpareQ->Append(spr); } if (nx) if (nx->Flags.Slav) @@ -826,7 +826,7 @@ static void SNLevel(SPRITE *spr, int lev) { while (Lev < lev) { SPRITE *spr; ++Lev; - spr = VGA::SpareQ.Locate(100 + Lev); + spr = Vga->SpareQ->Locate(100 + Lev); if (spr) { spr->BackShow(true); spr->Cave = 0; @@ -863,19 +863,19 @@ void SNFlash(bool on) { c = pal[i].B << 1; pal[i].B = (c < 64) ? c : 63; } - VGA::SetColors(pal, 64); + Vga->SetColors(pal, 64); } } else - VGA::SetColors(SysPal, 64); + Vga->SetColors(SysPal, 64); Dark = false; } static void SNLight(bool in) { if (in) - VGA::Sunrise(SysPal); + Vga->Sunrise(SysPal); else - VGA::Sunset(); + Vga->Sunset(); Dark = ! in; } diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index bbb69839ddb..4944d8529ad 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -32,6 +32,7 @@ #include "cge/bitmaps.h" #include "cge/game.h" #include "cge/snail.h" +#include "cge/cge_main.h" #include #include #include @@ -215,8 +216,8 @@ void Say(const char *txt, SPRITE *spr) { spike->Step(east); spike->Ref = SAY_REF; - VGA::ShowQ.Insert(Talk, VGA::ShowQ.Last()); - VGA::ShowQ.Insert(spike, VGA::ShowQ.Last()); + Vga->ShowQ->Insert(Talk, Vga->ShowQ->Last()); + Vga->ShowQ->Insert(spike, Vga->ShowQ->Last()); } } @@ -231,7 +232,7 @@ void Inf(const char *txt) { Talk->Goto(Talk->X, Talk->Y - 20); Talk->Z = 126; Talk->Ref = INF_REF; - VGA::ShowQ.Insert(Talk, VGA::ShowQ.Last()); + Vga->ShowQ->Insert(Talk, Vga->ShowQ->Last()); } } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 52015c27f1e..54b34105d85 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -30,6 +30,7 @@ #include "cge/bitmap.h" #include "cge/vol.h" #include "cge/text.h" +#include "cge/cge_main.h" #include #include #include @@ -213,8 +214,8 @@ RGB MkRGB(uint8 r, uint8 g, uint8 b) { SPRITE *Locate(int ref) { - SPRITE *spr = VGA::ShowQ.Locate(ref); - return (spr) ? spr : VGA::SpareQ.Locate(ref); + SPRITE *spr = Vga->ShowQ->Locate(ref); + return (spr) ? spr : Vga->SpareQ->Locate(ref); } @@ -774,7 +775,7 @@ BMP_PTR SPRITE::Ghost(void) { SPRITE *SpriteAt(int x, int y) { - SPRITE *spr = NULL, * tail = VGA::ShowQ.Last(); + SPRITE *spr = NULL, * tail = Vga->ShowQ->Last(); if (tail) { for (spr = tail->Prev; spr; spr = spr->Prev) if (! spr->Flags.Hide && ! spr->Flags.Tran) @@ -888,17 +889,6 @@ SPRITE *QUEUE::Locate(int ref) { } -uint16 VGA::StatAdr = VGAST1_; -uint16 VGA::OldMode = 0; -uint16 *VGA::OldScreen = NULL; -const char *VGA::Msg = NULL; -const char *VGA::Nam = NULL; -DAC *VGA::OldColors = NULL; -DAC *VGA::NewColors = NULL; -bool VGA::SetPal = false; -int VGA::Mono = 0; -QUEUE VGA::ShowQ = true, VGA::SpareQ = false; - // TODO: Was direct mapping to VGA buffers.. need to create scummvm surfaces for that uint8 *VGA::Page[4] = { 0, 0, 0, 0 }; @@ -912,7 +902,13 @@ uint8 * VGA::Page[4] = { (uint8 *) MK_FP(SCR_SEG, 0x0000), //extern const char Copr[]; VGA::VGA(int mode) - : FrmCnt(0) { + : FrmCnt(0), OldMode(0), OldScreen(NULL), StatAdr(VGAST1_), + Msg(NULL), Nam(NULL), SetPal(false), Mono(0) { + OldColors = NULL; + NewColors = NULL; + ShowQ = new QUEUE(true); + SpareQ = new QUEUE(false); + bool std = true; int i; for (i = 10; i < 20; i ++) { @@ -939,7 +935,7 @@ VGA::VGA(int mode) OldMode = SetMode(mode); SetColors(); Setup(VideoMode); - Clear(); + Clear(0); } } @@ -948,7 +944,7 @@ VGA::~VGA(void) { Mono = 0; if (IsVga()) { Common::String buffer = ""; - Clear(); + Clear(0); SetMode(OldMode); SetColors(); RestoreScreen(OldScreen); @@ -1154,7 +1150,7 @@ void VGA::SetColors(void) { void VGA::Sunrise(DAC *tab) { for (int i = 0; i <= 64; i += FADE_STEP) { SetColors(tab, i); - WaitVR(); + WaitVR(true); UpdateColors(); } } @@ -1165,19 +1161,19 @@ void VGA::Sunset(void) { GetColors(tab); for (int i = 64; i >= 0; i -= FADE_STEP) { SetColors(tab, i); - WaitVR(); + WaitVR(true); UpdateColors(); } } void VGA::Show(void) { - SPRITE *spr = ShowQ.First(); + SPRITE *spr = ShowQ->First(); - for (spr = ShowQ.First(); spr; spr = spr->Next) + for (spr = ShowQ->First(); spr; spr = spr->Next) spr->Show(); Update(); - for (spr = ShowQ.First(); spr; spr = spr->Next) + for (spr = ShowQ->First(); spr; spr = spr->Next) spr->Hide(); ++ FrmCnt; @@ -1228,7 +1224,8 @@ void VGA::Update(void) { asm mov ah,byte ptr p+1 asm out dx,ax */ - if (! SpeedTest) WaitVR(); + if (! SpeedTest) + WaitVR(true); if (SetPal) { UpdateColors(); diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 19453a4523d..b467b0405f3 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -228,7 +228,7 @@ class QUEUE { SPRITE *Head, * Tail; public: bool Show; - QUEUE(bool show = false); + QUEUE(bool show); ~QUEUE(void); void Append(SPRITE *spr); void Insert(SPRITE *spr, SPRITE *nxt); @@ -247,32 +247,35 @@ public: class VGA { - static uint16 OldMode; - static uint16 *OldScreen; - static uint16 StatAdr; - static bool SetPal; - static DAC *OldColors, * NewColors; - static int SetMode(int mode); - static void UpdateColors(void); - static void SetColors(void); - static const char *Msg; - static const char *Nam; - static void SetStatAdr(void); - static void WaitVR(bool on = true); + uint16 OldMode; + uint16 *OldScreen; + uint16 StatAdr; + bool SetPal; + DAC *OldColors, *NewColors; + const char *Msg; + const char *Nam; + + int SetMode(int mode); + void UpdateColors(void); + void SetColors(void); + void SetStatAdr(void); + void WaitVR(bool on); public: uint32 FrmCnt; - static QUEUE ShowQ, SpareQ; - static int Mono; + QUEUE *ShowQ, *SpareQ; + int Mono; static uint8 *Page[4]; - VGA(int mode = M13H); + + VGA(int mode); ~VGA(void); + void Setup(VgaRegBlk *vrb); - static void GetColors(DAC *tab); - static void SetColors(DAC *tab, int lum); - static void Clear(uint8 color = 0); - static void CopyPage(uint16 d, uint16 s = 3); - static void Sunrise(DAC *tab); - static void Sunset(void); + void GetColors(DAC *tab); + void SetColors(DAC *tab, int lum); + void Clear(uint8 color); + void CopyPage(uint16 d, uint16 s); + void Sunrise(DAC *tab); + void Sunset(void); void Show(void); void Update(void); }; diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 4e1a3334bf8..cb2c2013f41 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -27,6 +27,7 @@ #include "cge/vmenu.h" #include "cge/mouse.h" +#include "cge/cge_main.h" #include namespace CGE { @@ -112,10 +113,10 @@ VMENU::VMENU(CHOICE *list, int x, int y) Center(); else Goto(x - W / 2, y - (TEXT_VM + FONT_HIG / 2)); - VGA::ShowQ.Insert(this, VGA::ShowQ.Last()); + Vga->ShowQ->Insert(this, Vga->ShowQ->Last()); Bar = new MENU_BAR(W - 2 * TEXT_HM); Bar->Goto(X + TEXT_HM - MB_HM, Y + TEXT_VM - MB_VM); - VGA::ShowQ.Insert(Bar, VGA::ShowQ.Last()); + Vga->ShowQ->Insert(Bar, Vga->ShowQ->Last()); } From 77d4dcade26a69a6e2ebcc69a4224059c450f3e4 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 20 Jun 2011 00:55:47 +0200 Subject: [PATCH 025/276] CGE: Remove static parts of HEART --- engines/cge/cge.cpp | 2 ++ engines/cge/cge_main.cpp | 23 ++++++++++++----------- engines/cge/cge_main.h | 1 + engines/cge/snail.cpp | 10 +++++----- engines/cge/vga13h.cpp | 28 +++++++++++++--------------- engines/cge/vga13h.h | 11 ++++++----- 6 files changed, 39 insertions(+), 36 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 8b3bea3eb5f..f28be8b224d 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -42,6 +42,8 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) _console = new CGEConsole(this); Text = new TEXT(ProgName()); Vga = new VGA(M13H); + Heart = new HEART; + OffUseCount = atoi(Text->getText(OFF_USE_COUNT)); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index c6c6a3961bc..3c1cb28b140 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -61,6 +61,9 @@ namespace CGE { extern uint16 _stklen = (STACK_SIZ * 2); +VGA *Vga; +HEART *Heart; + // 0.75 - 17II95 - full sound support // 0.76 - 18II95 - small MiniEMS in DEMO, // unhide CavLight in SNLEVEL @@ -117,7 +120,6 @@ static SPRITE *Sprite = NULL; static SPRITE *MiniCave = NULL; static SPRITE *Shadow = NULL; -VGA *Vga; static EMS *Mini = MiniEmm.Alloc((uint16)MINI_EMM_SIZE); static BMP_PTR *MiniShpList = NULL; static BMP_PTR MiniShp[] = { NULL, NULL }; @@ -582,7 +584,6 @@ static void SaveMapping(void); WALK *Hero = NULL; static INFO_LINE InfoLine = INFO_W; -static HEART Heart; static SPRITE CavLight = PR; @@ -738,7 +739,7 @@ static void CaveUp(void) { if (! Startup) Mouse.On(); - HEART::Enable = true; + Heart->Enable = true; } @@ -779,7 +780,7 @@ static void QGame(void) { void SwitchCave(int cav) { if (cav != Now) { - HEART::Enable = false; + Heart->Enable = false; if (cav < 0) { SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint //TODO Change the SNPOST message send to a special way to send function pointer @@ -1673,7 +1674,7 @@ static void RunGame(void) { } KEYBOARD::SetClient(NULL); - HEART::Enable = false; + Heart->Enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); Mouse.Off(); @@ -1691,13 +1692,13 @@ void Movie(const char *ext) { ExpandSprite(Vga->SpareQ->Locate(999)); FeedSnail(Vga->ShowQ->Locate(999), TAKE); Vga->ShowQ->Append(&Mouse); - HEART::Enable = true; + Heart->Enable = true; KEYBOARD::SetClient(Sys); while (! Snail.Idle()) { MainLoop(); } KEYBOARD::SetClient(NULL); - HEART::Enable = false; + Heart->Enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); Vga->ShowQ->Clear(); @@ -1733,12 +1734,12 @@ bool ShowTitle(const char *name) { Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); Vga->ShowQ->Append(&Mouse); - HEART::Enable = true; + Heart->Enable = true; Mouse.On(); for (SelectSound(); ! Snail.Idle() || VMENU::Addr;) MainLoop(); Mouse.Off(); - HEART::Enable = false; + Heart->Enable = false; Vga->ShowQ->Clear(); Vga->CopyPage(0, 2); STARTUP::SoundOk = 2; @@ -1771,10 +1772,10 @@ bool ShowTitle(const char *name) { Vga->CopyPage(0, 1); Vga->ShowQ->Append(&Mouse); //Mouse.On(); - HEART::Enable = true; + Heart->Enable = true; for (TakeName(); GET_TEXT::Ptr;) MainLoop(); - HEART::Enable = false; + Heart->Enable = false; if (KEYBOARD::Last() == Enter && *UsrFnam) usr_ok = true; if (usr_ok) diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index fe50e7bab30..0afdc0f820d 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -170,6 +170,7 @@ void ContractSprite(SPRITE *spr); void cge_main(void); extern VGA *Vga; +extern HEART *Heart; extern int OffUseCount; } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index f40d2bc2faa..afe73b4d245 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -511,16 +511,16 @@ static void SNRTNext(SPRITE *sprel, int p) { static void SNZTrim(SPRITE *spr) { if (spr) if (spr->Active()) { - bool en = HEART::Enable; + bool en = Heart->Enable; SPRITE *s; - HEART::Enable = false; + Heart->Enable = false; s = (spr->Flags.Shad) ? spr->Prev : NULL; Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr)); if (s) { s->Z = spr->Z; Vga->ShowQ->Insert(Vga->ShowQ->Remove(s), spr); } - HEART::Enable = en; + Heart->Enable = en; } } @@ -936,7 +936,7 @@ void SNAIL::RunCom(void) { case SNLABEL : break; case SNPAUSE : - HEART::SetXTimer(&Pause, snc->Val); + Heart->SetXTimer(&Pause, snc->Val); if (Talk) TextDelay = true; break; @@ -944,7 +944,7 @@ void SNAIL::RunCom(void) { if (sprel) { if (sprel->SeqTest(snc->Val) && (snc->Val >= 0 || sprel != Hero || Hero->TracePtr < 0)) { - HEART::SetXTimer(&Pause, sprel->Time); + Heart->SetXTimer(&Pause, sprel->Time); } else goto xit; } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 54b34105d85..a8a0c5faf0a 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -219,12 +219,10 @@ SPRITE *Locate(int ref) { } -bool HEART::Enable = false; -uint16 *HEART::XTimer = NULL; - - HEART::HEART(void) : ENGINE(TMR_DIV) { + Enable = false; + XTimer = NULL; } @@ -235,11 +233,11 @@ extern "C" void TimerProc (void) static uint8 run = 0; // decrement external timer uint16 - if (HEART::XTimer) - if (*HEART::XTimer) -- *HEART::XTimer; - else HEART::XTimer = NULL; + if (Heart->XTimer) + if (*Heart->XTimer) -- *Heart->XTimer; + else Heart->XTimer = NULL; - if (! run && HEART::Enable) // check overrun flag + if (! run && Heart->Enable) // check overrun flag { static uint16 oldSP, oldSS; @@ -299,11 +297,11 @@ void ENGINE::NewTimer(...) { my_int: //------72Hz-------// // decrement external timer uint16 - if (HEART::XTimer) - if (*HEART::XTimer) -- *HEART::XTimer; - else HEART::XTimer = NULL; + if (Heart->XTimer) + if (*Heart->XTimer) -- *Heart->XTimer; + else Heart->XTimer = NULL; - if (! run && HEART::Enable) // check overrun flag + if (! run && Heart->Enable) // check overrun flag { static uint16 oldSP, oldSS; @@ -473,8 +471,8 @@ void SPRITE::SetName(char *n) { SPRITE *SPRITE::Expand(void) { if (! Ext) { - bool enbl = HEART::Enable; - HEART::Enable = false; + bool enbl = Heart->Enable; + Heart->Enable = false; if ((Ext = new SPREXT) == NULL) error("No core"); if (*File) { @@ -596,7 +594,7 @@ SPRITE *SPRITE::Expand(void) { else TakePtr = NO_PTR; } - HEART::Enable = enbl; + Heart->Enable = enbl; } return this; } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index b467b0405f3..63886d9a99e 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -131,11 +131,12 @@ extern SEQ Seq2[]; class HEART : public ENGINE { friend class ENGINE; public: - static bool Enable; - static uint16 *XTimer; - static void SetXTimer(uint16 *ptr); - static void SetXTimer(uint16 *ptr, uint16 time); - HEART(void); + HEART(); + + bool Enable; + uint16 *XTimer; + void SetXTimer(uint16 *ptr); + void SetXTimer(uint16 *ptr, uint16 time); }; From 6dc29e4a0489a62498653a880f38369ce05d41f8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 20 Jun 2011 23:40:22 +0200 Subject: [PATCH 026/276] CGE: Remove some statics --- engines/cge/cge.cpp | 10 +++++- engines/cge/cge_main.cpp | 76 ++++++++++++++++++++-------------------- engines/cge/cge_main.h | 25 ++++++------- engines/cge/game.h | 4 --- engines/cge/mixer.cpp | 5 +-- engines/cge/mouse.cpp | 1 + engines/cge/snail.cpp | 20 +++++------ engines/cge/vga13h.cpp | 1 - 8 files changed, 73 insertions(+), 69 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index f28be8b224d..04a950faf09 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -30,8 +30,11 @@ #include "common/fs.h" #include "engines/util.h" #include "cge/cge.h" +#include "cge/vga13h.h" #include "cge/cge_main.h" #include "cge/text.h" +#include "cge/bitmaps.h" + namespace CGE { @@ -43,7 +46,12 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) Text = new TEXT(ProgName()); Vga = new VGA(M13H); Heart = new HEART; - + Hero = new WALK(NULL); + Sys = new SYSTEM(); + PocLight = new SPRITE(LI); + Mouse = new MOUSE; + for (int i = 0; i < POCKET_NX; i++) + Pocket[i] = new SPRITE(NULL); OffUseCount = atoi(Text->getText(OFF_USE_COUNT)); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 3c1cb28b140..5817c1436b8 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -61,8 +61,13 @@ namespace CGE { extern uint16 _stklen = (STACK_SIZ * 2); -VGA *Vga; +VGA *Vga; HEART *Heart; +WALK *Hero; +SYSTEM *Sys; +SPRITE *PocLight; +MOUSE *Mouse; +SPRITE *Pocket[POCKET_NX]; // 0.75 - 17II95 - full sound support // 0.76 - 18II95 - small MiniEMS in DEMO, @@ -109,13 +114,8 @@ bool JBW = false; DAC *SysPal = farnew(DAC, PAL_CNT); //------------------------------------------------------------------------- -SPRITE PocLight = LI; -SPRITE *Pocket[POCKET_NX] = { NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, - }; int PocPtr = 0; -MOUSE Mouse; static SPRITE *Sprite = NULL; static SPRITE *MiniCave = NULL; static SPRITE *Shadow = NULL; @@ -387,9 +387,9 @@ void WALK::Tick(void) { if (Dir != NO_DIR) { SPRITE *spr; - SYSTEM::FunTouch(); + Sys->FunTouch(); for (spr = Vga->ShowQ->First(); spr; spr = spr->Next) { - if (Distance(spr) < 2) { + if (Distance(spr) < 2) { if (! spr->Flags.Near) { FeedSnail(spr, NEAR); spr->Flags.Near = true; @@ -582,7 +582,6 @@ static void NextStep(void); static void SaveMapping(void); -WALK *Hero = NULL; static INFO_LINE InfoLine = INFO_W; static SPRITE CavLight = PR; @@ -645,10 +644,6 @@ static void PostMiniStep(int stp) { warning("STUB: PostMiniStep()"); } - -int SYSTEM::FunDel = HEROFUN0; - - void SYSTEM::SetPal(void) { int i; DAC *p = SysPal + 256 - ArrayCount(StdPal); @@ -675,7 +670,7 @@ static void ShowBak(int ref) { BITMAP::Pal = NULL; spr->Show(2); Vga->CopyPage(1, 2); - SYSTEM::SetPal(); + Sys->SetPal(); spr->Contract(); } } @@ -737,7 +732,7 @@ static void CaveUp(void) { Vga->Sunrise(SysPal); Dark = false; if (! Startup) - Mouse.On(); + Mouse->On(); Heart->Enable = true; } @@ -788,7 +783,7 @@ void SwitchCave(int cav) { warning("SwitchCave() - SNPOST"); } else { Now = cav; - Mouse.Off(); + Mouse->Off(); if (Hero) { Hero->Park(); Hero->Step(0); @@ -811,6 +806,11 @@ void SwitchCave(int cav) { } } +SYSTEM::SYSTEM() : SPRITE(NULL) { + FunDel = HEROFUN0; + SetPal(); + Tick(); +} void SYSTEM::Touch(uint16 mask, int x, int y) { static int pp = 0; @@ -880,7 +880,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { Hero->Step(TSEQ + 3); break; case F9: - SYSTEM::FunDel = 1; + Sys->FunDel = 1; break; case 'X': if (KEYBOARD::Key[ALT]) @@ -1191,8 +1191,8 @@ static void SayDebug(void) { t = t1; } - dwtom(Mouse.X, ABSX, 10, 3); - dwtom(Mouse.Y, ABSY, 10, 3); + dwtom(Mouse->X, ABSX, 10, 3); + dwtom(Mouse->Y, ABSY, 10, 3); // dwtom(coreleft(), NFRE, 10, 5); // dwtom(farcoreleft(), FFRE, 10, 6); @@ -1249,7 +1249,7 @@ static void OptionTouch(int opt, uint16 mask) { #pragma argsused void SPRITE::Touch(uint16 mask, int x, int y) { - SYSTEM::FunTouch(); + Sys->FunTouch(); if ((mask & ATTN) == 0) { InfoLine.Update(Name()); if (mask & (R_DN | L_DN)) @@ -1265,7 +1265,7 @@ void SPRITE::Touch(uint16 mask, int x, int y) { mask |= R_UP; } if ((mask & R_UP) && Snail.Idle()) { - SPRITE *ps = (PocLight.SeqPtr) ? Pocket[PocPtr] : NULL; + SPRITE *ps = (PocLight->SeqPtr) ? Pocket[PocPtr] : NULL; if (ps) { if (Flags.Kept || Hero->Distance(this) < MAX_DISTANCE) { if (Works(ps)) { @@ -1591,14 +1591,14 @@ static void RunGame(void) { { 1, 6, 0, 0, 4 }, { 0, 1, 0, 0, 16 }, }; - PocLight.SetSeq(PocSeq); - PocLight.Flags.Tran = true; - PocLight.Time = 1; - PocLight.Z = 120; - Vga->ShowQ->Append(&PocLight); + PocLight->SetSeq(PocSeq); + PocLight->Flags.Tran = true; + PocLight->Time = 1; + PocLight->Z = 120; + Vga->ShowQ->Append(PocLight); SelectPocket(-1); - Vga->ShowQ->Append(&Mouse); + Vga->ShowQ->Append(Mouse); // ___________ LoadUser(); @@ -1653,9 +1653,9 @@ static void RunGame(void) { HorzLine.Z = 126; Vga->ShowQ->Insert(&HorzLine); - Mouse.Busy = Vga->SpareQ->Locate(BUSY_REF); - if (Mouse.Busy) - ExpandSprite(Mouse.Busy); + Mouse->Busy = Vga->SpareQ->Locate(BUSY_REF); + if (Mouse->Busy) + ExpandSprite(Mouse->Busy); Startup = 0; @@ -1677,7 +1677,7 @@ static void RunGame(void) { Heart->Enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); - Mouse.Off(); + Mouse->Off(); Vga->ShowQ->Clear(); Vga->SpareQ->Clear(); Hero = NULL; @@ -1691,7 +1691,7 @@ void Movie(const char *ext) { LoadScript(fn); ExpandSprite(Vga->SpareQ->Locate(999)); FeedSnail(Vga->ShowQ->Locate(999), TAKE); - Vga->ShowQ->Append(&Mouse); + Vga->ShowQ->Append(Mouse); Heart->Enable = true; KEYBOARD::SetClient(Sys); while (! Snail.Idle()) { @@ -1733,12 +1733,12 @@ bool ShowTitle(const char *name) { if (STARTUP::Mode < 2 && ! STARTUP::SoundOk) { Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); - Vga->ShowQ->Append(&Mouse); + Vga->ShowQ->Append(Mouse); Heart->Enable = true; - Mouse.On(); + Mouse->On(); for (SelectSound(); ! Snail.Idle() || VMENU::Addr;) MainLoop(); - Mouse.Off(); + Mouse->Off(); Heart->Enable = false; Vga->ShowQ->Clear(); Vga->CopyPage(0, 2); @@ -1770,7 +1770,7 @@ bool ShowTitle(const char *name) { Movie("X00"); // paylist Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); - Vga->ShowQ->Append(&Mouse); + Vga->ShowQ->Append(Mouse); //Mouse.On(); Heart->Enable = true; for (TakeName(); GET_TEXT::Ptr;) @@ -1829,9 +1829,9 @@ void cge_main(void) { //Debug( memset((void *) (-K(4)), 0, K(1)); ) memset(Barriers, 0xFF, sizeof(Barriers)); - if (! Mouse.Exist) + if (!Mouse->Exist) error("%s", Text->getText(NO_MOUSE_TEXT)); - if (! SVG0FILE::Exist(SVG0NAME)) + if (!SVG0FILE::Exist(SVG0NAME)) STARTUP::Mode = 2; DebugLine.Flags.Hide = true; diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 0afdc0f820d..3eb38cafce1 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -30,6 +30,7 @@ #include "cge/wav.h" #include "cge/vga13h.h" +#include "cge/mouse.h" namespace CGE { @@ -119,15 +120,14 @@ namespace CGE { class SYSTEM : public SPRITE { int lum; public: - static int FunDel; - static void SetPal(void); - static void FunTouch(void); - SYSTEM(void) : SPRITE(NULL) { - SetPal(); - Tick(); - } + int FunDel; + + SYSTEM(); + + void SetPal(); + void FunTouch(); void Touch(uint16 mask, int x, int y); - void Tick(void); + void Tick(); }; @@ -161,17 +161,18 @@ public: CLUSTER XZ(int x, int y); CLUSTER XZ(COUPLE xy); - -extern WALK *Hero; - - void ExpandSprite(SPRITE *spr); void ContractSprite(SPRITE *spr); void cge_main(void); +extern WALK *Hero; extern VGA *Vga; extern HEART *Heart; +extern SYSTEM *Sys; extern int OffUseCount; +extern SPRITE *PocLight; +extern MOUSE *Mouse; +extern SPRITE *Pocket[]; } // End of namespace CGE diff --git a/engines/cge/game.h b/engines/cge/game.h index 1bc24e1fd9d..1d65d0c7678 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -40,14 +40,10 @@ namespace CGE { #define TBound(s) (s->Y <= 0) #define BBound(s) (s->Y+s->H >= SCR_HIG - PAN_HIG) - -extern SPRITE *Sys; - int Sinus(long x); uint8 *Glass(DAC *pal, uint8 r, uint8 g, uint8 b); uint8 *Mark(DAC *pal); - class FLY : public SPRITE { static int L, T, R, B; public: diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index c1b69d40c2b..6a3a45553a3 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -35,7 +35,7 @@ namespace CGE { -extern MOUSE Mouse; +extern MOUSE *Mouse; bool MIXER::Appear = false; @@ -114,7 +114,8 @@ void MIXER::Touch(uint16 mask, int x, int y) { void MIXER::Tick(void) { - int x = Mouse.X, y = Mouse.Y; + int x = Mouse->X; + int y = Mouse->Y; if (SpriteAt(x, y) == this) { Fall = MIX_FALL; if (Flags.Hold) diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index 78e686ff953..8ad12742d32 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -27,6 +27,7 @@ #include "cge/mouse.h" #include "cge/text.h" +#include "cge/cge_main.h" namespace CGE { diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index afe73b4d245..4675c6b8483 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -58,7 +58,7 @@ int Lev = -1; SNAIL Snail = false; SNAIL Snail_ = true; -extern SPRITE PocLight; +extern SPRITE *PocLight; //------------------------------------------------------------------------- // SPRITE * Pocket[POCKET_NX]={ NULL, NULL, NULL, NULL, @@ -68,8 +68,6 @@ extern SPRITE PocLight; extern SPRITE *Pocket[]; extern int PocPtr; extern DAC *SysPal; -extern MOUSE Mouse; - static void SNGame(SPRITE *spr, int num) { switch (num) { @@ -300,18 +298,18 @@ int FindPocket(SPRITE *spr) { void SelectPocket(int n) { - if (n < 0 || (PocLight.SeqPtr && PocPtr == n)) { - PocLight.Step(0); + if (n < 0 || (PocLight->SeqPtr && PocPtr == n)) { + PocLight->Step(0); n = FindPocket(NULL); if (n >= 0) PocPtr = n; } else { if (Pocket[n] != NULL) { PocPtr = n; - PocLight.Step(1); + PocLight->Step(1); } } - PocLight.Goto(POCKET_X + PocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY); + PocLight->Goto(POCKET_X + PocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY); } @@ -903,9 +901,9 @@ static void SNReach(SPRITE *spr, int mode) { static void SNMouse(bool on) { if (on) - Mouse.On(); + Mouse->On(); else - Mouse.Off(); + Mouse->Off(); } @@ -960,13 +958,13 @@ void SNAIL::RunCom(void) { if (sprel == Hero && sprel->SeqTest(-1)) sprel->Step(HTALK); Say(Text->getText(snc->Val), sprel); - SYSTEM::FunDel = HEROFUN0; + Sys->FunDel = HEROFUN0; } break; case SNINF : if (TalkEnable) { Inf(Text->getText(snc->Val)); - SYSTEM::FunDel = HEROFUN0; + Sys->FunDel = HEROFUN0; } break; case SNTIME : diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index a8a0c5faf0a..349f412ca07 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -69,7 +69,6 @@ static VgaRegBlk VideoMode[] = { bool SpeedTest = false; SEQ Seq1[] = { { 0, 0, 0, 0, 0 } }; SEQ Seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; -SPRITE *Sys = NULL; extern "C" void SNDMIDIPlay(void); From b5ad69d13cf531c2d4c841c043a89f732fc4d4e0 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 21 Jun 2011 19:38:16 +0200 Subject: [PATCH 027/276] CGE: ScummVM no longer crashes instantly --- engines/cge/bitmaps.cpp | 33 ----------------- engines/cge/cge.cpp | 24 +++++++++++++ engines/cge/cge_main.cpp | 77 ++++++++++++++++++++-------------------- engines/cge/cge_main.h | 14 ++++++++ 4 files changed, 77 insertions(+), 71 deletions(-) diff --git a/engines/cge/bitmaps.cpp b/engines/cge/bitmaps.cpp index cabe04b784f..5e8757ae736 100644 --- a/engines/cge/bitmaps.cpp +++ b/engines/cge/bitmaps.cpp @@ -224,39 +224,6 @@ static uint8 MEDesign[][9] = { { R R R R R R R R R }, // 0 namespace CGE { -BMP_PTR MB[] = { - new BITMAP("BRICK"), - NULL -}; -BMP_PTR HL[] = { - new BITMAP("HLINE"), - NULL -}; - -BMP_PTR MC[] = { - new BITMAP("MOUSE"), - new BITMAP("DUMMY"), - NULL -}; - -BMP_PTR PR[] = { - new BITMAP("PRESS"), - NULL -}; - -BMP_PTR SP[] = { - new BITMAP("SPK_L"), - new BITMAP("SPK_R"), - NULL -}; - -BMP_PTR LI[] = { - new BITMAP("LITE0"), - new BITMAP("LITE1"), - new BITMAP("LITE2"), - new BITMAP("LITE3"), - NULL -}; } // End of namespace CGE diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 04a950faf09..a34288b7e95 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -52,6 +52,30 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) Mouse = new MOUSE; for (int i = 0; i < POCKET_NX; i++) Pocket[i] = new SPRITE(NULL); + Sprite = new SPRITE(NULL); + MiniCave = new SPRITE(NULL); + Shadow = new SPRITE(NULL); + HorzLine = new SPRITE(HL); + InfoLine = new INFO_LINE(INFO_W); + CavLight = new SPRITE(PR); + DebugLine = new INFO_LINE(SCR_WID); + MB[0] = new BITMAP("BRICK"); + MB[1] = NULL; + HL[0] = new BITMAP("HLINE"); + HL[1] = NULL; + MC[0] = new BITMAP("MOUSE"); + MC[1] = new BITMAP("DUMMY"); + MC[2] = NULL; + PR[0] = new BITMAP("PRESS"); + PR[1] = NULL; + SP[0] = new BITMAP("SPK_L"); + SP[1] = new BITMAP("SPK_R"); + SP[2] = NULL; + LI[0] = new BITMAP("LITE0"); + LI[1] = new BITMAP("LITE1"), + LI[2] = new BITMAP("LITE2"), + LI[3] = new BITMAP("LITE3"), + LI[4] = NULL; OffUseCount = atoi(Text->getText(OFF_USE_COUNT)); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 5817c1436b8..7c055548a3b 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -68,6 +68,20 @@ SYSTEM *Sys; SPRITE *PocLight; MOUSE *Mouse; SPRITE *Pocket[POCKET_NX]; +SPRITE *Sprite; +SPRITE *MiniCave; +SPRITE *Shadow; +SPRITE *HorzLine; +INFO_LINE *InfoLine; +SPRITE *CavLight; +INFO_LINE *DebugLine; + +BMP_PTR MB[2]; +BMP_PTR HL[2]; +BMP_PTR MC[3]; +BMP_PTR PR[2]; +BMP_PTR SP[3]; +BMP_PTR LI[5]; // 0.75 - 17II95 - full sound support // 0.76 - 18II95 - small MiniEMS in DEMO, @@ -116,10 +130,6 @@ DAC *SysPal = farnew(DAC, PAL_CNT); //------------------------------------------------------------------------- int PocPtr = 0; -static SPRITE *Sprite = NULL; -static SPRITE *MiniCave = NULL; -static SPRITE *Shadow = NULL; - static EMS *Mini = MiniEmm.Alloc((uint16)MINI_EMM_SIZE); static BMP_PTR *MiniShpList = NULL; static BMP_PTR MiniShp[] = { NULL, NULL }; @@ -138,8 +148,6 @@ extern int FindPocket(SPRITE *); extern DAC StdPal[58]; -static SPRITE HorzLine = HL; - void FeedSnail(SPRITE *spr, SNLIST snq); // defined in SNAIL uint8 CLUSTER::Map[MAP_ZCNT][MAP_XCNT]; @@ -581,11 +589,6 @@ static void BackPaint(void); static void NextStep(void); static void SaveMapping(void); - -static INFO_LINE InfoLine = INFO_W; -static SPRITE CavLight = PR; - - static void KeyClick(void) { SNPOST_(SNSOUND, -1, 5, NULL); } @@ -740,7 +743,7 @@ static void CaveUp(void) { static void CaveDown(void) { SPRITE *spr; - if (! HorzLine.Flags.Hide) + if (! HorzLine->Flags.Hide) SwitchMapping(); for (spr = Vga->ShowQ->First(); spr;) { @@ -793,7 +796,7 @@ void SwitchCave(int cav) { /////-------------------------------------------------------- #endif } - CavLight.Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, + CavLight->Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); KillText(); if (! Startup) @@ -926,7 +929,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { if (Startup) return; int cav = 0; - InfoLine.Update(NULL); + InfoLine->Update(NULL); if (y >= WORLD_HIG) { if (x < BUTTON_X) { // select cave? if (y >= CAVE_Y && y < CAVE_Y + CAVE_NY * CAVE_DY && @@ -952,7 +955,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { if (cav && Snail.Idle() && Hero->TracePtr < 0) SwitchCave(cav); - if (!HorzLine.Flags.Hide) { + if (!HorzLine->Flags.Hide) { if (y >= MAP_TOP && y < MAP_TOP + MAP_HIG) { int8 x1, z1; XZ(x, y).Split(x1, z1); @@ -1076,7 +1079,7 @@ static void TakeName(void) { static void SwitchMapping(void) { - if (HorzLine.Flags.Hide) { + if (HorzLine->Flags.Hide) { int i; for (i = 0; i < MAP_ZCNT; i ++) { int j; @@ -1091,7 +1094,7 @@ static void SwitchMapping(void) { if (s->W == MAP_XGRID && s->H == MAP_ZGRID) SNPOST_(SNKILL, -1, 0, s); } - HorzLine.Flags.Hide = ! HorzLine.Flags.Hide; + HorzLine->Flags.Hide = ! HorzLine->Flags.Hide; } @@ -1176,10 +1179,8 @@ static char DebugText[] = " N=00000 F=000000 X=000 Y=000 FPS=0000\0S=00:00 0 #define SP_F (DebugText + 67) #define SP__ (DebugText + 70) -INFO_LINE DebugLine(SCR_WID); - static void SayDebug(void) { - if (!DebugLine.Flags.Hide) { + if (!DebugLine->Flags.Hide) { static long t = -1L; long t1 = Timer(); @@ -1214,13 +1215,13 @@ static void SayDebug(void) { } dwtom(n, SP_S, 10, 2); // *SP__ = (heapcheck() < 0) ? '!' : ' '; - DebugLine.Update(DebugText); + DebugLine->Update(DebugText); } } static void SwitchDebug(void) { - DebugLine.Flags.Hide = ! DebugLine.Flags.Hide; + DebugLine->Flags.Hide = ! DebugLine->Flags.Hide; } @@ -1251,7 +1252,7 @@ static void OptionTouch(int opt, uint16 mask) { void SPRITE::Touch(uint16 mask, int x, int y) { Sys->FunTouch(); if ((mask & ATTN) == 0) { - InfoLine.Update(Name()); + InfoLine->Update(Name()); if (mask & (R_DN | L_DN)) Sprite = this; if (Ref / 10 == 12) { @@ -1579,9 +1580,9 @@ static void RunGame(void) { Text->Preload(100, 1000); LoadHeroXY(); - CavLight.Flags.Tran = true; - Vga->ShowQ->Append(&CavLight); - CavLight.Flags.Hide = true; + CavLight->Flags.Tran = true; + Vga->ShowQ->Append(CavLight); + CavLight->Flags.Hide = true; static SEQ PocSeq[] = { { 0, 0, 0, 0, 20 }, { 1, 2, 0, 0, 4 }, @@ -1641,17 +1642,17 @@ static void RunGame(void) { } } - InfoLine.Goto(INFO_X, INFO_Y); - InfoLine.Flags.Tran = true; - InfoLine.Update(NULL); - Vga->ShowQ->Insert(&InfoLine); + InfoLine->Goto(INFO_X, INFO_Y); + InfoLine->Flags.Tran = true; + InfoLine->Update(NULL); + Vga->ShowQ->Insert(InfoLine); - DebugLine.Z = 126; - Vga->ShowQ->Insert(&DebugLine); + DebugLine->Z = 126; + Vga->ShowQ->Insert(DebugLine); - HorzLine.Y = MAP_TOP - (MAP_TOP > 0); - HorzLine.Z = 126; - Vga->ShowQ->Insert(&HorzLine); + HorzLine->Y = MAP_TOP - (MAP_TOP > 0); + HorzLine->Z = 126; + Vga->ShowQ->Insert(HorzLine); Mouse->Busy = Vga->SpareQ->Locate(BUSY_REF); if (Mouse->Busy) @@ -1660,7 +1661,7 @@ static void RunGame(void) { Startup = 0; SNPOST(SNLEVEL, -1, OldLev, &CavLight); - CavLight.Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, + CavLight->Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); CaveUp(); @@ -1834,8 +1835,8 @@ void cge_main(void) { if (!SVG0FILE::Exist(SVG0NAME)) STARTUP::Mode = 2; - DebugLine.Flags.Hide = true; - HorzLine.Flags.Hide = true; + DebugLine->Flags.Hide = true; + HorzLine->Flags.Hide = true; //srand((uint16) Timer()); Sys = new SYSTEM; diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 3eb38cafce1..d2443a7e87d 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -173,6 +173,20 @@ extern int OffUseCount; extern SPRITE *PocLight; extern MOUSE *Mouse; extern SPRITE *Pocket[]; +extern SPRITE *Sprite; +extern SPRITE *MiniCave; +extern SPRITE *Shadow; +extern SPRITE *HorzLine; +extern INFO_LINE *InfoLine; +extern SPRITE *CavLight; +extern INFO_LINE *DebugLine; +extern BMP_PTR MB[2]; +extern BMP_PTR MB[2]; +extern BMP_PTR HL[2]; +extern BMP_PTR MC[3]; +extern BMP_PTR PR[2]; +extern BMP_PTR SP[3]; +extern BMP_PTR LI[5]; } // End of namespace CGE From a307d405b6ddf4cb94d57e8365327667a6291bac Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 22 Jun 2011 08:11:18 +0200 Subject: [PATCH 028/276] CGE: suppress a couple of static, add ProgName and MergeExt --- engines/cge/cge.cpp | 43 ++++++++++++++++++++++++++++++++++++---- engines/cge/cge_main.cpp | 29 +++++++++++++++------------ engines/cge/cge_main.h | 2 ++ engines/cge/general.cpp | 18 +++++++++++++---- engines/cge/gettext.cpp | 1 + engines/cge/snail.cpp | 4 +--- engines/cge/snail.h | 28 +++++++++++++------------- engines/cge/text.cpp | 2 +- engines/cge/text.h | 2 +- 9 files changed, 89 insertions(+), 40 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index a34288b7e95..ef00d0e5170 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -42,8 +42,9 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) : Engine(syst), _gameDescription(gameDescription) { DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel"); + _console = new CGEConsole(this); - Text = new TEXT(ProgName()); + Text = new TEXT(ProgName(), 128); Vga = new VGA(M13H); Heart = new HEART; Hero = new WALK(NULL); @@ -72,10 +73,12 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) SP[1] = new BITMAP("SPK_R"); SP[2] = NULL; LI[0] = new BITMAP("LITE0"); - LI[1] = new BITMAP("LITE1"), - LI[2] = new BITMAP("LITE2"), - LI[3] = new BITMAP("LITE3"), + LI[1] = new BITMAP("LITE1"); + LI[2] = new BITMAP("LITE2"); + LI[3] = new BITMAP("LITE3"); LI[4] = NULL; + Snail = new SNAIL(false); + Snail_ = new SNAIL(true); OffUseCount = atoi(Text->getText(OFF_USE_COUNT)); @@ -87,6 +90,38 @@ CGEEngine::~CGEEngine() { // Remove all of our debug levels here DebugMan.clearAllDebugChannels(); + + _console = new CGEConsole(this); + + delete Text; + delete Vga; + delete Heart; + delete Hero; + delete Sys; + delete PocLight; + delete Mouse; + for (int i = 0; i < POCKET_NX; i++) + delete Pocket[i]; + delete Sprite; + delete MiniCave; + delete Shadow; + delete HorzLine; + delete InfoLine; + delete CavLight; + delete DebugLine; + delete MB[0]; + delete HL[0]; + delete MC[0]; + delete MC[1]; + delete PR[0]; + delete SP[0]; + delete SP[1]; + delete LI[0]; + delete LI[1]; + delete LI[2]; + delete LI[3]; + delete Snail; + delete Snail_; } Common::Error CGEEngine::run() { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 7c055548a3b..ec8f743fe48 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -83,6 +83,9 @@ BMP_PTR PR[2]; BMP_PTR SP[3]; BMP_PTR LI[5]; +SNAIL *Snail; +SNAIL *Snail_; + // 0.75 - 17II95 - full sound support // 0.76 - 18II95 - small MiniEMS in DEMO, // unhide CavLight in SNLEVEL @@ -606,7 +609,7 @@ static void Quit(void) { { NULL, dummy } }; - if (Snail.Idle() && ! Hero->Flags.Hide) { + if (Snail->Idle() && ! Hero->Flags.Hide) { if (VMENU::Addr) { SNPOST_(SNKILL, -1, 0, VMENU::Addr); ResetQSwitch(); @@ -907,7 +910,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { Sprite->Step(x - '0'); break; case F10 : - if (Snail.Idle() && ! Hero->Flags.Hide) + if (Snail->Idle() && ! Hero->Flags.Hide) StartCountDown(); break; case 'J': @@ -952,7 +955,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { PostMiniStep(cav - 1); if (mask & L_UP) { - if (cav && Snail.Idle() && Hero->TracePtr < 0) + if (cav && Snail->Idle() && Hero->TracePtr < 0) SwitchCave(cav); if (!HorzLine->Flags.Hide) { @@ -964,7 +967,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { } } else { - if (! Talk && Snail.Idle() && Hero + if (! Talk && Snail->Idle() && Hero && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && ! Game) { Hero->FindWay(XZ(x, y)); } @@ -977,7 +980,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { void SYSTEM::Tick(void) { if (! Startup) if (-- FunDel == 0) { KillText(); - if (Snail.Idle()) { + if (Snail->Idle()) { if (PAIN) HeroCover(9); else if (STARTUP::Core >= CORE_MID) { @@ -1265,7 +1268,7 @@ void SPRITE::Touch(uint16 mask, int x, int y) { mask &= ~L_UP; mask |= R_UP; } - if ((mask & R_UP) && Snail.Idle()) { + if ((mask & R_UP) && Snail->Idle()) { SPRITE *ps = (PocLight->SeqPtr) ? Pocket[PocPtr] : NULL; if (ps) { if (Flags.Kept || Hero->Distance(this) < MAX_DISTANCE) { @@ -1305,7 +1308,7 @@ void SPRITE::Touch(uint16 mask, int x, int y) { } } } - if ((mask & L_UP) && Snail.Idle()) { + if ((mask & L_UP) && Snail->Idle()) { if (Flags.Kept) { int n; for (n = 0; n < POCKET_NX; n ++) { @@ -1549,8 +1552,8 @@ static void MainLoop(void) { #endif Vga->Show(); - Snail_.RunCom(); - Snail.RunCom(); + Snail_->RunCom(); + Snail->RunCom(); } @@ -1695,9 +1698,9 @@ void Movie(const char *ext) { Vga->ShowQ->Append(Mouse); Heart->Enable = true; KEYBOARD::SetClient(Sys); - while (! Snail.Idle()) { + while (!Snail->Idle()) MainLoop(); - } + KEYBOARD::SetClient(NULL); Heart->Enable = false; SNPOST(SNCLEAR, -1, 0, NULL); @@ -1731,13 +1734,13 @@ bool ShowTitle(const char *name) { SelectPocket(-1); Vga->Sunrise(SysPal); - if (STARTUP::Mode < 2 && ! STARTUP::SoundOk) { + if (STARTUP::Mode < 2 && !STARTUP::SoundOk) { Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); Vga->ShowQ->Append(Mouse); Heart->Enable = true; Mouse->On(); - for (SelectSound(); ! Snail.Idle() || VMENU::Addr;) + for (SelectSound(); !Snail->Idle() || VMENU::Addr;) MainLoop(); Mouse->Off(); Heart->Enable = false; diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index d2443a7e87d..f3a95e786cc 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -187,6 +187,8 @@ extern BMP_PTR MC[3]; extern BMP_PTR PR[2]; extern BMP_PTR SP[3]; extern BMP_PTR LI[5]; +extern SNAIL *Snail; +extern SNAIL *Snail_; } // End of namespace CGE diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 7e1653f61af..efca664b712 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -99,16 +99,26 @@ EC void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const vo warning("STUB: _fqsort"); } -const char *ProgName(const char *ext) { - warning("STUB: ProgName"); - return NULL; +const char *ProgName(const char *ext) { + warning("ProgName"); + + static Common::String buf = "CGE"; + if (ext) + buf += ext; + return buf.c_str(); } char *MergeExt(char *buf, const char *nam, const char *ext) { // char dr[MAXDRIVE], di[MAXDIR], na[MAXFILE], ex[MAXEXT]; // fnmerge(buf, dr, di, na, (fnsplit(nam, dr, di, na, ex) & EXTENSION) ? ex : ext); // return buf; - warning("STUB: MergeExt"); + warning("MergeExt"); + + strcpy(buf, nam); + char *dot = strrchr(buf, '.'); + if (!dot) + strcat(buf, ext); + return buf; } diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index e11f4ff3089..c1d54099f89 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -28,6 +28,7 @@ #include "cge/gettext.h" #include "cge/keybd.h" #include "cge/mouse.h" +#include "cge/cge_main.h" #include namespace CGE { diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 4675c6b8483..2b36ca43252 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -55,8 +55,6 @@ bool Dark = false; bool Game = false; int Now = 1; int Lev = -1; -SNAIL Snail = false; -SNAIL Snail_ = true; extern SPRITE *PocLight; @@ -359,7 +357,7 @@ void FeedSnail(SPRITE *spr, SNLIST snq) { } while (true) { if (c->Com == SNTALK) { - if ((Snail.TalkEnable = (c->Val != 0)) == false) + if ((Snail->TalkEnable = (c->Val != 0)) == false) KillText(); } if (c->Com == SNNEXT) { diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 4255ea4e616..54c7809fda7 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -42,9 +42,9 @@ namespace CGE { #define POCKET_SX 8 #define POCKET_SY 3 -#define SNINSERT(c,r,v,p) Snail.InsCom(c,r,v,p) -#define SNPOST(c,r,v,p) Snail.AddCom(c,r,v,p) -#define SNPOST_(c,r,v,p) Snail_.AddCom(c,r,v,p) +#define SNINSERT(c,r,v,p) Snail->InsCom(c,r,v,p) +#define SNPOST(c,r,v,p) Snail->AddCom(c,r,v,p) +#define SNPOST_(c,r,v,p) Snail_->AddCom(c,r,v,p) typedef struct { @@ -102,17 +102,17 @@ void SelectPocket(int n); void PocFul(void); -extern SCB Scb; -extern bool Flag[4]; -extern bool Game; -extern bool Dark; -extern SNAIL Snail; -extern SNAIL Snail_; -extern int Now; -extern int Lev; -extern int MaxCave; -extern int PocPtr; -extern BAR Barriers[]; +extern SCB Scb; +extern bool Flag[4]; +extern bool Game; +extern bool Dark; +//extern SNAIL *Snail; +//extern SNAIL *Snail_; +extern int Now; +extern int Lev; +extern int MaxCave; +extern int PocPtr; +extern BAR Barriers[]; extern struct HXY { int X; int Y; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 4944d8529ad..ee949833524 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -46,7 +46,7 @@ TEXT::TEXT(const char *fname, int size) { Cache = new HAN[size]; MergeExt(FileName, fname, SAY_EXT); if (!INI_FILE::Exist(FileName)) - error("No talk\n"); + error("No talk (%s)\n", FileName); for (Size = 0; Size < size; Size ++) { Cache[Size].Ref = 0; diff --git a/engines/cge/text.h b/engines/cge/text.h index c7782103040..64e3b1d6693 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -61,7 +61,7 @@ class TEXT { char *Load(int idx, int ref); int Find(int ref); public: - TEXT(const char *fname, int size = 128); + TEXT(const char *fname, int size); ~TEXT(void); void Clear(int from = 1, int upto = 0x7FFF); void Preload(int from = 1, int upto = 0x7FFF); From fe9dc10964ab4dc4528cc473ef841709732fceff Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 26 Jun 2011 17:53:55 +1000 Subject: [PATCH 029/276] CGE: Implemented basic file access functionality --- engines/cge/cge.cpp | 22 +++++++++-- engines/cge/cge.h | 2 + engines/cge/general.cpp | 82 +++++++++++++---------------------------- engines/cge/general.h | 3 +- engines/cge/vol.cpp | 60 ++++++++++++++++++++---------- engines/cge/vol.h | 23 ++++++++---- 6 files changed, 103 insertions(+), 89 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index ef00d0e5170..d056a6737de 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -34,6 +34,7 @@ #include "cge/cge_main.h" #include "cge/text.h" #include "cge/bitmaps.h" +#include "cge/vol.h" namespace CGE { @@ -41,9 +42,20 @@ namespace CGE { CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) : Engine(syst), _gameDescription(gameDescription) { + // Debug/console setup DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel"); + debug("CGEEngine::CGEEngine"); +} + +void CGEEngine::setup() { + // Create debugger console _console = new CGEConsole(this); + + // Initialise classes that have static members + VFILE::init(); + + // Initialise engine objects Text = new TEXT(ProgName(), 128); Vga = new VGA(M13H); Heart = new HEART; @@ -81,18 +93,20 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) Snail_ = new SNAIL(true); OffUseCount = atoi(Text->getText(OFF_USE_COUNT)); - - debug("CGEEngine::CGEEngine"); } CGEEngine::~CGEEngine() { debug("CGEEngine::~CGEEngine"); + // Call classes with static members to clear them up + VFILE::deinit(); + // Remove all of our debug levels here DebugMan.clearAllDebugChannels(); _console = new CGEConsole(this); + // Delete engine objects delete Text; delete Vga; delete Heart; @@ -128,8 +142,8 @@ Common::Error CGEEngine::run() { // Initialize graphics using following: initGraphics(320, 200, false); - // Create debugger console. It requires GFX to be initialized - _console = new CGEConsole(this); + // Setup necessary game objects + setup(); // Additional setup. debug("CGEEngine::init"); diff --git a/engines/cge/cge.h b/engines/cge/cge.h index c6d9a099bf6..f8857f045ff 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -55,6 +55,8 @@ public: private: CGEConsole *_console; + + void setup(); }; // Example console class diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index efca664b712..9caa8642275 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -158,9 +158,11 @@ uint16 RCrypt(void *buf, uint16 siz, uint16 seed) { } uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { -// for (uint16 i = 0; i < siz; i ++) -// *(BUF ++) ^= seed; - warning("STUB: XCrypt"); + byte *b = static_cast(buf); + + for (uint16 i = 0; i < siz; i ++) + *b++ ^= seed; + return seed; } @@ -208,45 +210,32 @@ char *dwtom(uint32 val, char *str, int radix, int len) { } IOHAND::IOHAND(IOMODE mode, CRYPT *crpt) - : XFILE(mode), Handle(-1), Crypt(crpt), Seed(SEED) { + : XFILE(mode), Crypt(crpt), Seed(SEED) { } IOHAND::IOHAND(const char *name, IOMODE mode, CRYPT *crpt) - : XFILE(mode), Crypt(crpt), Seed(SEED) { - /* switch (mode) - { - case REA : Error = _dos_open(name, O_RDONLY | O_DENYNONE, &Handle); break; - case WRI : Error = _dos_creat(name, FA_ARCH, &Handle); break; - case UPD : Error = _dos_open(name, O_RDWR | O_DENYALL, &Handle); break; - } - if (Error) Handle = -1; - */ - warning("STUB: IOHAND::IOHAND"); + : XFILE(mode), Crypt(crpt), Seed(SEED) { + // TODO: Check if WRI and/or UPD modes are needed, and map to a save file + assert(mode == REA); + + _file.open(name); } IOHAND::~IOHAND(void) { - /* - if (Handle != -1) - { - Error = _dos_close(Handle); - Handle = -1; - } - */ - warning("STUB: IOHAND::~IOHAND"); + _file.close(); } uint16 IOHAND::Read(void *buf, uint16 len) { - /* - if (Mode == WRI || Handle < 0) return 0; - if (len) Error = _dos_read(Handle, buf, len, &len); - if (Crypt) Seed = Crypt(buf, len, Seed); - return len; - */ - warning("STUB: IOHAND::Read"); - return 0; + if (Mode == WRI || !_file.isOpen()) + return 0; + + uint16 bytesRead = _file.read(buf, len); + if (Crypt) Seed = Crypt(buf, len, Seed); + return bytesRead; } uint16 IOHAND::Write(void *buf, uint16 len) { + error("IOHAND::Write not supported"); /* if (len) { if (Mode == REA || Handle < 0) @@ -259,45 +248,24 @@ uint16 IOHAND::Write(void *buf, uint16 len) { } return len; */ - warning("STUB: IOHAND::Write"); - return 0; } long IOHAND::Mark(void) { -/* - return (Handle < 0) ? 0 : tell(Handle); -*/ - warning("STUB: IOHAND::Mark"); - return 0; + return _file.pos(); } long IOHAND::Seek(long pos) { -/* - if (Handle < 0) - return 0; - lseek(Handle, pos, SEEK_SET); - return tell(Handle); -*/ - warning("STUB: IOHAND::Seek"); - return 0; + _file.seek(pos, SEEK_SET); + return _file.pos(); } long IOHAND::Size(void) { -/* - if (Handle < 0) - return 0; - return filelength(Handle); -*/ - warning("STUB: IOHAND::Size"); - return 0; + return _file.size(); } bool IOHAND::Exist(const char *name) { -/* - return access(name, 0) == 0; -*/ - warning("STUB: IOHAND::Exist"); - return 0; + Common::File f; + return f.exists(name); } //#define EMS_ADR(a) (FP_SEG(a) > 0xA000) diff --git a/engines/cge/general.h b/engines/cge/general.h index 16b0c1e2bf2..6fb8e24f9ce 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -29,6 +29,7 @@ #define __GENERAL__ #include "common/system.h" +#include "common/file.h" #include "common/random.h" #include "common/textconsole.h" #include "common/str.h" @@ -183,7 +184,7 @@ inline uint16 XRead(XFILE *xf, T *t) { class IOHAND : public XFILE { protected: - int Handle; + Common::File _file; uint16 Seed; CRYPT *Crypt; public: diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 9b6489afab3..c76914c0039 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -34,23 +34,45 @@ namespace CGE { -#ifdef VOL_UPD -BTFILE VFILE::Cat(CAT_NAME, UPD, CRP); -VOLBASE DAT::File(DAT_NAME, UPD, CRP); -#else -BTFILE VFILE::Cat(CAT_NAME, REA, CRP); -VOLBASE DAT::File(DAT_NAME, REA, CRP); -#endif -DAT VFILE::Dat; -VFILE *VFILE::Recent = NULL; +DAT *VFILE::_Dat = NULL; +BTFILE *VFILE::_Cat = NULL; +VFILE *VFILE::_Recent = NULL; +/*-----------------------------------------------------------------------*/ + +DAT::DAT(): +#ifdef VOL_UPD + _File(DAT_NAME, UPD, CRP) +#else + _File(DAT_NAME, REA, CRP) +#endif +{ +} + +/*-----------------------------------------------------------------------*/ + +void VFILE::init() { + _Dat = new DAT(); +#ifdef VOL_UPD + _Cat = new BTFILE(CAT_NAME, UPD, CRP); +#else + _Cat = new BTFILE(CAT_NAME, REA, CRP); +#endif + + _Recent = NULL; +} + +void VFILE::deinit() { + delete _Dat; + delete _Cat; +} VFILE::VFILE(const char *name, IOMODE mode) : IOBUF(mode) { if (mode == REA) { - if (Dat.File.Error || Cat.Error) + if (_Dat->_File.Error || _Cat->Error) error("Bad volume data"); - BT_KEYPACK *kp = Cat.Find(name); + BT_KEYPACK *kp = _Cat->Find(name); if (scumm_stricmp(kp->Key, name) != 0) Error = 1; EndMark = (BufMark = BegMark = kp->Mark) + kp->Size; @@ -63,26 +85,26 @@ VFILE::VFILE(const char *name, IOMODE mode) VFILE::~VFILE(void) { - if (Recent == this) - Recent = NULL; + if (_Recent == this) + _Recent = NULL; } bool VFILE::Exist(const char *name) { - return scumm_stricmp(Cat.Find(name)->Key, name) == 0; + return scumm_stricmp(_Cat->Find(name)->Key, name) == 0; } void VFILE::ReadBuff(void) { - if (Recent != this) { - Dat.File.Seek(BufMark + Lim); - Recent = this; + if (_Recent != this) { + _Dat->_File.Seek(BufMark + Lim); + _Recent = this; } - BufMark = Dat.File.Mark(); + BufMark = _Dat->_File.Mark(); long n = EndMark - BufMark; if (n > IOBUF_SIZE) n = IOBUF_SIZE; - Lim = Dat.File.Read(Buff, (uint16) n); + Lim = _Dat->_File.Read(Buff, (uint16) n); Ptr = 0; } diff --git a/engines/cge/vol.h b/engines/cge/vol.h index ea82e8bf6a5..a910aa72094 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -51,18 +51,22 @@ namespace CGE { class DAT { friend class VFILE; - static VOLBASE File; + VOLBASE _File; public: - static bool Append(uint8 *buf, uint16 len); - static bool Write(CFILE &f); - static bool Read(long org, uint16 len, uint8 *buf); + DAT(); + + bool Append(uint8 *buf, uint16 len); + bool Write(CFILE &f); + bool Read(long org, uint16 len, uint8 *buf); }; class VFILE : public IOBUF { - static DAT Dat; - static BTFILE Cat; - static VFILE *Recent; +private: + static DAT *_Dat; + static BTFILE *_Cat; + static VFILE *_Recent; + long BegMark, EndMark; void ReadBuff(void); void WriteBuff(void) { } @@ -70,6 +74,9 @@ class VFILE : public IOBUF { public: VFILE(const char *name, IOMODE mode = REA); ~VFILE(void); + static void init(); + static void deinit(); + static bool Exist(const char *name); static const char *Next(void); long Mark(void) { @@ -79,7 +86,7 @@ public: return EndMark - BegMark; } long Seek(long pos) { - Recent = NULL; + _Recent = NULL; Lim = 0; return (BufMark = BegMark + pos); } From d5fdd094294becb49ef2adf0af00c4814c6efefe Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 26 Jun 2011 18:51:12 +1000 Subject: [PATCH 030/276] CGE: Bugfix for scanning archive index in BTFILE class --- engines/cge/btfile.cpp | 3 ++- engines/cge/btfile.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 0552e78c1cc..a6ba3d85b09 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -101,9 +101,10 @@ BT_KEYPACK *BTFILE::Find(const char *key) { // search if (pg->Hea.Down != BT_NONE) { int i; - for (i = 0; i < pg->Hea.Count; i ++) + for (i = 0; i < pg->Hea.Count; i ++) { if (memicmp(key, pg->Inn[i].Key, BT_KEYLEN) < 0) break; + } nxt = (i) ? pg->Inn[i - 1].Down : pg->Hea.Down; Buff[lev].Indx = i - 1; ++ lev; diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 6e6398f4de3..449f2001405 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -39,6 +39,7 @@ namespace CGE { #define BT_NONE 0xFFFF #define BT_ROOT 0 +#include "common/pack-start.h" // START STRUCT PACKING struct BT_KEYPACK { char Key[BT_KEYLEN]; @@ -66,6 +67,8 @@ struct BT_PAGE { }; }; +#include "common/pack-end.h" // END STRUCT PACKING + class BTFILE : public IOHAND { struct { From a06a75b9a41fb3ef9da2c7420ee9dee257c89cca Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 26 Jun 2011 12:07:42 +0200 Subject: [PATCH 031/276] CGE: Implement ForceExt and RCrypt. Little style cleanup. --- engines/cge/bitmap.cpp | 10 ++++---- engines/cge/btfile.cpp | 14 +++++----- engines/cge/cfile.cpp | 6 ++--- engines/cge/cge_main.cpp | 22 ++++++++-------- engines/cge/config.cpp | 2 +- engines/cge/detection.cpp | 2 +- engines/cge/ems.cpp | 4 +-- engines/cge/game.cpp | 4 +-- engines/cge/general.cpp | 39 ++++++++++++++++------------ engines/cge/gettext.cpp | 4 +-- engines/cge/jbw.h | 14 +++++----- engines/cge/mixer.cpp | 8 +++--- engines/cge/snail.cpp | 8 +++--- engines/cge/sound.cpp | 8 +++--- engines/cge/talk.cpp | 22 ++++++++-------- engines/cge/text.cpp | 6 ++--- engines/cge/vga13h.cpp | 54 +++++++++++++++++++++------------------ engines/cge/vga13h.h | 2 +- engines/cge/vmenu.cpp | 8 +++--- 19 files changed, 123 insertions(+), 114 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index b528b5578d5..90c6a02059f 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -194,18 +194,18 @@ BMP_PTR BITMAP::Code(void) { int bpl; if (V) { // 2nd pass - fill the hide table - for (i = 0; i < H; i ++) { + for (i = 0; i < H; i++) { B[i].skip = 0xFFFF; B[i].hide = 0x0000; } } - for (bpl = 0; bpl < 4; bpl ++) { // once per each bitplane + for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane uint8 *bm = M; bool skip = (bm[bpl] == TRANS); uint16 j; cnt = 0; - for (i = 0; i < H; i ++) { // once per each line + for (i = 0; i < H; i++) { // once per each line uint8 pix; for (j = bpl; j < W; j += 4) { pix = bm[j]; @@ -274,7 +274,7 @@ BMP_PTR BITMAP::Code(void) { B = (HideDesc *)(V + sizV); } cnt = 0; - for (i = 0; i < H; i ++) { + for (i = 0; i < H; i++) { if (B[i].skip == 0xFFFF) { // whole line is skipped B[i].skip = (cnt + SCR_WID) >> 2; cnt = 0; @@ -326,7 +326,7 @@ bool BITMAP::SolidAt(int x, int y) { while (true) { uint16 w, t; - w = * (uint16 *) m; + w = *(uint16 *) m; m += 2; t = w & 0xC000; w &= 0x3FFF; diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index a6ba3d85b09..12c35194660 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -42,7 +42,7 @@ namespace CGE { BTFILE::BTFILE(const char *name, IOMODE mode, CRYPT *crpt) : IOHAND(name, mode, crpt) { - for (int i = 0; i < BT_LEVELS; i ++) { + for (int i = 0; i < BT_LEVELS; i++) { Buff[i].Page = new BT_PAGE; Buff[i].PgNo = BT_NONE; Buff[i].Indx = -1; @@ -54,7 +54,7 @@ BTFILE::BTFILE(const char *name, IOMODE mode, CRYPT *crpt) BTFILE::~BTFILE(void) { - for (int i = 0; i < BT_LEVELS; i ++) { + for (int i = 0; i < BT_LEVELS; i++) { PutPage(i); delete Buff[i].Page; } @@ -101,7 +101,7 @@ BT_KEYPACK *BTFILE::Find(const char *key) { // search if (pg->Hea.Down != BT_NONE) { int i; - for (i = 0; i < pg->Hea.Count; i ++) { + for (i = 0; i < pg->Hea.Count; i++) { if (memicmp(key, pg->Inn[i].Key, BT_KEYLEN) < 0) break; } @@ -110,7 +110,7 @@ BT_KEYPACK *BTFILE::Find(const char *key) { ++ lev; } else { int i; - for (i = 0; i < pg->Hea.Count - 1; i ++) + for (i = 0; i < pg->Hea.Count - 1; i++) if (scumm_stricmp((const char *)key, (const char *)pg->Lea[i].Key) <= 0) break; Buff[lev].Indx = i; @@ -136,15 +136,15 @@ void BTFILE::Make(BT_KEYPACK *keypack, uint16 count) { *Leaf = GetPage(1, n); Root->Hea.Down = n; PutPage(0, true); - while (count --) { + while (count--) { if (Leaf->Hea.Count >= ArrayCount(Leaf->Lea)) { PutPage(1, true); // save filled page Leaf = GetPage(1, ++n); // take empty page memcpy(Root->Inn[Root->Hea.Count].Key, keypack->Key, BT_KEYLEN); - Root->Inn[Root->Hea.Count ++].Down = n; + Root->Inn[Root->Hea.Count++].Down = n; Buff[0].Updt = true; } - Leaf->Lea[Leaf->Hea.Count ++] = * (keypack ++); + Leaf->Lea[Leaf->Hea.Count++] = *(keypack++); Buff[1].Updt = true; } } diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index da56587ebed..85e51a94c1f 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -126,7 +126,7 @@ uint16 IOBUF::Read(uint8 *buf) { Ptr += n; if (eol) { ++ Ptr; - * (buf ++) = '\n'; + *(buf++) = '\n'; ++ total; if (Ptr >= Lim) ReadBuff(); @@ -186,14 +186,14 @@ int IOBUF::Read(void) { if (Lim == 0) return -1; } - return Buff[Ptr ++]; + return Buff[Ptr++]; } void IOBUF::Write(uint8 b) { if (Lim >= IOBUF_SIZE) WriteBuff(); - Buff[Lim ++] = b; + Buff[Lim++] = b; } diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index ec8f743fe48..4121efdb785 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -253,7 +253,7 @@ static void LoadGame(XFILE &file, bool tiny = false) { SPRITE *spr; int i; - for (st = SavTab; st->Ptr; st ++) { + for (st = SavTab; st->Ptr; st++) { if (file.Error) error("Bad SVG"); file.Read((uint8 *)((tiny || st->Flg) ? st->Ptr : &i), st->Len); @@ -289,7 +289,7 @@ static void LoadGame(XFILE &file, bool tiny = false) { Vga->SpareQ->Append(spr); } - for (i = 0; i < POCKET_NX; i ++) { + for (i = 0; i < POCKET_NX; i++) { register int r = pocref[i]; Pocket[i] = (r < 0) ? NULL : Vga->SpareQ->Locate(r); } @@ -308,7 +308,7 @@ static void SaveGame(XFILE &file) { SPRITE *spr; int i; - for (i = 0; i < POCKET_NX; i ++) { + for (i = 0; i < POCKET_NX; i++) { register SPRITE *s = Pocket[i]; pocref[i] = (s) ? s->Ref : -1; } @@ -316,7 +316,7 @@ static void SaveGame(XFILE &file) { volume[0] = SNDDrvInfo.VOL2.D; volume[1] = SNDDrvInfo.VOL2.M; - for (st = SavTab; st->Ptr; st ++) { + for (st = SavTab; st->Ptr; st++) { if (file.Error) error("Bad SVG"); file.Write((uint8 *) st->Ptr, st->Len); @@ -450,7 +450,7 @@ int WALK::Distance(SPRITE *spr) { dz = - dz; dx = dx * dx + dz * dz; - for (dz = 1; dz * dz < dx; dz ++) + for (dz = 1; dz * dz < dx; dz++) ; return dz - 1; @@ -485,7 +485,7 @@ void WALK::FindWay(CLUSTER c) { extern uint16 Target; if (c != Here) { - for (FindLevel = 1; FindLevel <= MAX_FIND_LEVEL; FindLevel ++) { + for (FindLevel = 1; FindLevel <= MAX_FIND_LEVEL; FindLevel++) { signed char x, z; Here.Split(x, z); Target = (z << 8) | x; @@ -653,7 +653,7 @@ static void PostMiniStep(int stp) { void SYSTEM::SetPal(void) { int i; DAC *p = SysPal + 256 - ArrayCount(StdPal); - for (i = 0; i < ArrayCount(StdPal); i ++) { + for (i = 0; i < ArrayCount(StdPal); i++) { p[i].R = StdPal[i].R >> 2; p[i].G = StdPal[i].G >> 2; p[i].B = StdPal[i].B >> 2; @@ -1084,9 +1084,9 @@ static void TakeName(void) { static void SwitchMapping(void) { if (HorzLine->Flags.Hide) { int i; - for (i = 0; i < MAP_ZCNT; i ++) { + for (i = 0; i < MAP_ZCNT; i++) { int j; - for (j = 0; j < MAP_XCNT; j ++) { + for (j = 0; j < MAP_XCNT; j++) { if (CLUSTER::Map[i][j]) SetMapBrick(j, i); } @@ -1311,7 +1311,7 @@ void SPRITE::Touch(uint16 mask, int x, int y) { if ((mask & L_UP) && Snail->Idle()) { if (Flags.Kept) { int n; - for (n = 0; n < POCKET_NX; n ++) { + for (n = 0; n < POCKET_NX; n++) { if (Pocket[n] == this) { SelectPocket(n); break; @@ -1436,7 +1436,7 @@ static void LoadSprite(const char *fname, int ref, int cav, int col = 0, int row l->By = 13; l->Cx = 300; l->Cy = 500; - * (long *) &l->Dx = 0; // movex * cnt + *(long *) &l->Dx = 0; // movex * cnt l->Goto(col, row); } Sprite = l; diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 9ffda8d6356..fe2d1bc16e7 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -161,7 +161,7 @@ void SelectSound(void) { SNPOST_(SNKILL, -1, 0, VMENU::Addr); Inf(Text->getText(STYPE_TEXT)); Talk->Goto(Talk->X, FONT_HIG / 2); - for (i = 0; i < ArrayCount(DevName); i ++) + for (i = 0; i < ArrayCount(DevName); i++) DevMenu[i].Text = Text->getText(DevName[i]); (new VMENU(DevMenu, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); } diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index f522f872c92..bebb342c033 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -160,7 +160,7 @@ SaveStateList CGEMetaEngine::listSaves(const char *target) const { SaveStateList saveList; int slotNum = 0; - for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { + for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); filename++) { // Obtain the last 3 digits of the filename, since they correspond to the save slot slotNum = atoi(filename->c_str() + filename->size() - 3); diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp index c21bc356dcb..f1f7ece7087 100644 --- a/engines/cge/ems.cpp +++ b/engines/cge/ems.cpp @@ -142,8 +142,8 @@ EMS *EMM::Alloc(uint16 siz) { if (cnt > 4) { top = (top + PAGE_MASK) & 0xFFFFC000L; - ++ pgn; - -- cnt; + pgn++; + cnt--; } if (size <= Lim - top) diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 58334f2e532..afa6fbeed08 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -35,7 +35,7 @@ uint8 *Glass(DAC *pal, uint8 r, uint8 g, uint8 b) { uint8 *x = new uint8[256]; if (x) { uint16 i; - for (i = 0; i < 256; i ++) { + for (i = 0; i < 256; i++) { x[i] = Closest(pal, MkDAC(((uint16)(pal[i].R) * r) / 255, ((uint16)(pal[i].G) * g) / 255, ((uint16)(pal[i].B) * b) / 255)); @@ -50,7 +50,7 @@ uint8 *Mark(DAC *pal) { uint8 *x = new uint8[256]; if (x) { uint16 i; - for (i = 0; i < 256; i ++) { + for (i = 0; i < 256; i++) { x[i] = Closest(pal, MkDAC(f(pal[i].R), f(pal[i].G), f(pal[i].B))); diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 9caa8642275..fd5cee3ec9f 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -127,7 +127,13 @@ char *ForceExt(char *buf, const char *nam, const char *ext) { // fnsplit(nam, dr, di, na, ex); // fnmerge(buf, dr, di, na, ext); // return buf; - warning("STUB: ForceExt"); + warning("ForceExt"); + strcpy(buf, nam); + char *dot = strrchr(buf, '.'); + if (dot) + *dot = '\0'; + strcat(buf, ext); + return buf; } @@ -143,24 +149,23 @@ unsigned FastRand(unsigned s) { } uint16 RCrypt(void *buf, uint16 siz, uint16 seed) { - /* - if (buf && siz) { - uint8 * q = BUF + (siz-1); - seed = FastRand(seed); - * (BUF ++) ^= seed; - while (buf < q) * (BUF ++) ^= FastRand(); - if (buf == q) * BUF ^= (seed = FastRand()); - } - return seed; - */ - warning("STUB: RCrypt"); - return 0; + if (buf && siz) { + byte *b = static_cast(buf); + byte *q = b + (siz - 1); + seed = FastRand(seed); + *b++ ^= seed; + while (buf < q) + *b++ ^= FastRand(); + if (buf == q) + *b ^= (seed = FastRand()); + } + return seed; } uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { byte *b = static_cast(buf); - for (uint16 i = 0; i < siz; i ++) + for (uint16 i = 0; i < siz; i++) *b++ ^= seed; return seed; @@ -170,7 +175,7 @@ uint16 atow(const char *a) { uint16 w = 0; if (a) while (IsDigit(*a)) - w = (10 * w) + (*(a ++) & 0xF); + w = (10 * w) + (*(a++) & 0xF); return w; } @@ -178,7 +183,7 @@ uint16 xtow(const char *x) { uint16 w = 0; if (x) { while (IsHxDig(*x)) { - register uint16 d = * (x ++); + register uint16 d = *(x++); if (d > '9') d -= 'A' - ('9' + 1); w = (w << 4) | (d & 0xF); @@ -327,7 +332,7 @@ DATACK *LoadWave(XFILE *file, EMM *emm) { int TakeEnum(const char **tab, const char *txt) { const char **e; if (txt) { - for (e = tab; *e; e ++) { + for (e = tab; *e; e++) { if (scumm_stricmp(txt, *e) == 0) { return e - tab; } diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index c1d54099f89..b6b47a05f9c 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -82,7 +82,7 @@ void GET_TEXT::Touch(uint16 mask, int x, int y) { case Enter : Buff[Len] = '\0'; strcpy(Text, Buff); - for (p = Text; *p; p ++) { + for (p = Text; *p; p++) { char *q = strchr(ogon, *p); if (q) *p = bezo[q - ogon]; @@ -110,7 +110,7 @@ void GET_TEXT::Touch(uint16 mask, int x, int y) { if (Len < Size && 2 * TEXT_HM + Font->Width(Buff) + Font->Wid[x] <= W) { Buff[Len + 2] = Buff[Len + 1]; Buff[Len + 1] = Buff[Len]; - Buff[Len ++] = x; + Buff[Len++] = x; } } break; diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 82647ed49af..4c96507ab78 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -57,7 +57,7 @@ namespace CGE { #define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) #define farnew(t,n) ((t *) malloc(sizeof(t) * (n))) -#define ArrayCount(a) (sizeof(a)/sizeof((a)[0])) +#define ArrayCount(a) (sizeof(a) / sizeof((a)[0])) #define MAX_TIMER 0x1800B0L typedef void (MouseFunType)(void); @@ -66,8 +66,8 @@ typedef void (MouseFunType)(void); #define Hi(d) (((int *) &d)[1]) #define LoWord(d) ((uint16) Lo(d)) #define HiWord(d) ((uint16) Hi(d)) -#define K(n) (1024*(n)) -#define MASK(n) ((1<SetSeq(ls); spr->Goto(x + 2 + 12 * i, y + 8); @@ -77,7 +77,7 @@ MIXER::MIXER(int x, int y) : SPRITE(NULL), Fall(MIX_FALL) { Led[ArrayCount(Led) - 1]->Flags.BDel = true; Vga->ShowQ->Insert(this); - for (i = 0; i < ArrayCount(Led); i ++) + for (i = 0; i < ArrayCount(Led); i++) Vga->ShowQ->Insert(Led[i]); //--- reset balance @@ -124,7 +124,7 @@ void MIXER::Tick(void) { if (Fall) --Fall; else { - for (int i = 0; i < ArrayCount(Led); i ++) + for (int i = 0; i < ArrayCount(Led); i++) SNPOST_(SNKILL, -1, 0, Led[i]); SNPOST_(SNKILL, -1, 0, this); } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 2b36ca43252..cc79dfcc620 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -288,7 +288,7 @@ void ContractSprite(SPRITE *spr) { } int FindPocket(SPRITE *spr) { - for (int i = 0; i < POCKET_NX; i ++) + for (int i = 0; i < POCKET_NX; i++) if (Pocket[i] == spr) return i; return -1; @@ -346,7 +346,7 @@ void FeedSnail(SPRITE *spr, SNLIST snq) { if (FindPocket(NULL) < 0) { // no empty pockets? SNAIL::COM *p; - for (p = c; p->Com != SNNEXT; p ++) { // find KEEP command + for (p = c; p->Com != SNNEXT; p++) { // find KEEP command if (p->Com == SNKEEP) { PocFul(); return; @@ -439,7 +439,7 @@ SNAIL::~SNAIL(void) { void SNAIL::AddCom(SNCOM com, int ref, int val, void *ptr) { _disable(); - COM *snc = &SNList[Head ++]; + COM *snc = &SNList[Head++]; snc->Com = com; snc->Ref = ref; snc->Val = val; @@ -850,7 +850,7 @@ void SNFlash(bool on) { DAC *pal = farnew(DAC, PAL_CNT); if (pal) { memcpy(pal, SysPal, PAL_SIZ); - for (int i = 0; i < PAL_CNT; i ++) { + for (int i = 0; i < PAL_CNT; i++) { register int c; c = pal[i].R << 1; pal[i].R = (c < 64) ? c : 63; diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 04e5d9464a3..4a7b63fb089 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -82,7 +82,7 @@ void SOUND::Stop(void) { FX::FX(int size) : Emm(0L), Current(NULL) { Cache = new HAN[size]; - for (Size = 0; Size < size; Size ++) { + for (Size = 0; Size < size; Size++) { Cache[Size].Ref = 0; Cache[Size].Wav = NULL; } @@ -97,7 +97,7 @@ FX::~FX(void) { void FX::Clear(void) { HAN *p, * q; - for (p = Cache, q = p + Size; p < q; p ++) { + for (p = Cache, q = p + Size; p < q; p++) { if (p->Ref) { p->Ref = 0; delete p->Wav; @@ -112,7 +112,7 @@ void FX::Clear(void) { int FX::Find(int ref) { HAN *p, * q; int i = 0; - for (p = Cache, q = p + Size; p < q; p ++) { + for (p = Cache, q = p + Size; p < q; p++) { if (p->Ref == ref) break; else @@ -126,7 +126,7 @@ void FX::Preload(int ref0) { HAN *CacheLim = Cache + Size; int ref; - for (ref = ref0; ref < ref0 + 10; ref ++) { + for (ref = ref0; ref < ref0 + 10; ref++) { static char fname[] = "FX00000.WAV"; wtom(ref, fname + 2, 10, 5); INI_FILE file = INI_FILE(fname); diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 1739511a498..9f162d0e6c0 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -66,7 +66,7 @@ void FONT::Load(void) { f.Read(Wid, WID_SIZ); if (! f.Error) { uint16 i, p = 0; - for (i = 0; i < POS_SIZ; i ++) { + for (i = 0; i < POS_SIZ; i++) { Pos[i] = p; p += Wid[i]; } @@ -80,7 +80,7 @@ uint16 FONT::Width(const char *text) { uint16 w = 0; if (text) while (* text) - w += Wid[*(text ++)]; + w += Wid[*(text++)]; return w; } @@ -91,7 +91,7 @@ void FONT::Save(void) { if (! f.Error) { f.Write(Wid, WID_SIZ); if (! f.Error) - f.Write(Map, Pos[POS_SIZ-1] + Wid[WID_SIZ-1]); + f.Write(Map, Pos[POS_SIZ - 1] + Wid[WID_SIZ - 1]); } } */ @@ -115,7 +115,7 @@ TALK::TALK(void) /* TALK::~TALK (void) { - for (uint16 i = 0; i < ShpCnt; i ++) { + for (uint16 i = 0; i < ShpCnt; i++) { if (FP_SEG(ShpList[i]) != _DS) { // small model: always false delete ShpList[i]; ShpList[i] = NULL; @@ -135,7 +135,7 @@ void TALK::Update(const char *tx) { if (!TS[0]) { uint16 k = 2 * hmarg; mh = 2 * vmarg + FONT_HIG; - for (p = tx; *p; p ++) { + for (p = tx; *p; p++) { if (*p == '|' || *p == '\n') { mh += FONT_HIG + TEXT_LS; if (k > mw) @@ -203,9 +203,9 @@ BITMAP *TALK::Box(uint16 w, uint16 h) { *p = LGRAY; } p = b; - for (int i = 0; i < r; i ++) { + for (int i = 0; i < r; i++) { int j; - for (j = 0; j < r - i; j ++) { + for (j = 0; j < r - i; j++) { p[j] = TRANS; p[w - j - 1] = TRANS; q[j] = TRANS; @@ -256,10 +256,10 @@ void TALK::PutLine(int line, const char *text) { uint16 cw = Font->Wid[*text], i; uint8 *fp = Font->Map + Font->Pos[*text]; - for (i = 0; i < cw; i ++) { + for (i = 0; i < cw; i++) { register uint16 b = fp[i]; uint16 n; - for (n = 0; n < FONT_HIG; n ++) { + for (n = 0; n < FONT_HIG; n++) { if (b & 1) *p = TEXT_FG; b >>= 1; @@ -293,7 +293,7 @@ void INFO_LINE::Update(const char *tx) { // claer whole rectangle memset(v + 2, TEXT_BG, dsiz); // data bytes memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines - * (uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 + *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes // paint text line @@ -306,7 +306,7 @@ void INFO_LINE::Update(const char *tx) { for (uint16 i = 0; i < cw; i++) { register uint16 b = fp[i]; - for (uint16 n = 0; n < FONT_HIG; n ++) { + for (uint16 n = 0; n < FONT_HIG; n++) { if (b & 1) *p = TEXT_FG; b >>= 1; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index ee949833524..a8bf0d0cf87 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -48,7 +48,7 @@ TEXT::TEXT(const char *fname, int size) { if (!INI_FILE::Exist(FileName)) error("No talk (%s)\n", FileName); - for (Size = 0; Size < size; Size ++) { + for (Size = 0; Size < size; Size++) { Cache[Size].Ref = 0; Cache[Size].Txt = NULL; } @@ -63,7 +63,7 @@ TEXT::~TEXT(void) { void TEXT::Clear(int from, int upto) { HAN *p, * q; - for (p = Cache, q = p + Size; p < q; p ++) { + for (p = Cache, q = p + Size; p < q; p++) { if (p->Ref && p->Ref >= from && p->Ref < upto) { p->Ref = 0; delete p->Txt; @@ -76,7 +76,7 @@ void TEXT::Clear(int from, int upto) { int TEXT::Find(int ref) { HAN *p, * q; int i = 0; - for (p = Cache, q = p + Size; p < q; p ++) { + for (p = Cache, q = p + Size; p < q; p++) { if (p->Ref == ref) break; else diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 349f412ca07..d7c6946e879 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -233,14 +233,16 @@ extern "C" void TimerProc (void) // decrement external timer uint16 if (Heart->XTimer) - if (*Heart->XTimer) -- *Heart->XTimer; - else Heart->XTimer = NULL; + if (*Heart->XTimer) + *Heart->XTimer--; + else + Heart->XTimer = NULL; if (! run && Heart->Enable) // check overrun flag { static uint16 oldSP, oldSS; - ++ run; // disable 2nd call until current lasts + run++; // disable 2nd call until current lasts asm mov ax,ds asm mov oldSS,ss asm mov oldSP,sp @@ -256,7 +258,7 @@ extern "C" void TimerProc (void) } asm mov ss,oldSS asm mov sp,oldSP - -- run; + run--; } } */ @@ -297,14 +299,16 @@ void ENGINE::NewTimer(...) { // decrement external timer uint16 if (Heart->XTimer) - if (*Heart->XTimer) -- *Heart->XTimer; - else Heart->XTimer = NULL; + if (*Heart->XTimer) + *Heart->XTimer--; + else + Heart->XTimer = NULL; if (! run && Heart->Enable) // check overrun flag { static uint16 oldSP, oldSS; - ++ run; // disable 2nd call until current lasts + run++; // disable 2nd call until current lasts asm mov ax,ds asm mov oldSS,ss asm mov oldSP,sp @@ -320,7 +324,7 @@ void ENGINE::NewTimer(...) { } asm mov ss,oldSS asm mov sp,oldSP - -- run; + run--; } */ @@ -402,7 +406,7 @@ BMP_PTR *SPRITE::SetShapeList(BMP_PTR *shp) { void SPRITE::MoveShapes(uint8 *buf) { BMP_PTR *p; - for (p = Ext->ShpList; *p; p ++) { + for (p = Ext->ShpList; *p; p++) { buf += (*p)->MoveVmap(buf); } } @@ -507,14 +511,14 @@ SPRITE *SPRITE::Expand(void) { break; } case 1 : { // Phase - shplist[shpcnt ++] = new BITMAP(strtok(NULL, " \t,;/")); + shplist[shpcnt++] = new BITMAP(strtok(NULL, " \t,;/")); break; } case 2 : { // Seq seq = (SEQ *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); if (seq == NULL) error("No core [%s]", fname); - SEQ *s = &seq[seqcnt ++]; + SEQ *s = &seq[seqcnt++]; s->Now = atoi(strtok(NULL, " \t,;/")); if (s->Now > maxnow) maxnow = s->Now; @@ -540,7 +544,7 @@ SPRITE *SPRITE::Expand(void) { if (nea == NULL) error("No core [%s]", fname); else { - SNAIL::COM *c = &nea[neacnt ++]; + SNAIL::COM *c = &nea[neacnt++]; if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), fname); c->Ref = atoi(strtok(NULL, " \t,;/")); @@ -556,7 +560,7 @@ SPRITE *SPRITE::Expand(void) { if (tak == NULL) error("No core [%s]", fname); else { - SNAIL::COM *c = &tak[takcnt ++]; + SNAIL::COM *c = &tak[takcnt++]; if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), fname); c->Ref = atoi(strtok(NULL, " \t,;/")); @@ -569,7 +573,7 @@ SPRITE *SPRITE::Expand(void) { } } } else { // no sprite description: try to read immediately from .BMP - shplist[shpcnt ++] = new BITMAP(File); + shplist[shpcnt++] = new BITMAP(File); } shplist[shpcnt] = NULL; if (seq) { @@ -606,7 +610,7 @@ SPRITE *SPRITE::Contract(void) { delete[] e->Name; if (Flags.BDel && e->ShpList) { int i; - for (i = 0; e->ShpList[i]; i ++) + for (i = 0; e->ShpList[i]; i++) delete e->ShpList[i]; if (MemType(e->ShpList) == NEAR_MEM) delete[] e->ShpList; @@ -662,7 +666,7 @@ void SPRITE::MakeXlat(uint8 *x) { if (Flags.Xlat) KillXlat(); - for (b = Ext->ShpList; *b; b ++) + for (b = Ext->ShpList; *b; b++) (*b)->M = x; Flags.Xlat = true; } @@ -682,7 +686,7 @@ void SPRITE::KillXlat(void) { free(m); break; } - for (b = Ext->ShpList; *b; b ++) + for (b = Ext->ShpList; *b; b++) (*b)->M = NULL; Flags.Xlat = false; } @@ -908,7 +912,7 @@ VGA::VGA(int mode) bool std = true; int i; - for (i = 10; i < 20; i ++) { + for (i = 10; i < 20; i++) { char *txt = Text->getText(i); if (txt) { // puts(txt); @@ -1293,9 +1297,9 @@ void BITMAP::XShow(int x, int y) { /* uint8 rmsk = x % 4, mask = 1 << rmsk, - * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; - uint8 * m = (char *) M; - uint8 * v = V; + *scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; + uint8 *m = (char *) M; + uint8 *v = V; asm push bx asm push si @@ -1374,8 +1378,8 @@ void BITMAP::XShow(int x, int y) { void BITMAP::Show(int x, int y) { /* uint8 mask = 1 << (x & 3), - * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); - uint8 * v = V; + *scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); + uint8 *v = V; asm push ds // preserve DS @@ -1443,9 +1447,9 @@ void BITMAP::Show(int x, int y) { void BITMAP::Hide(int x, int y) { /* - uint8 * scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; + uint8 *scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; uint16 d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); - HideDesc * b = B; + HideDesc *b = B; uint16 extra = ((x & 3) != 0); uint16 h = H; diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 63886d9a99e..d5bbf3972e9 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -294,7 +294,7 @@ uint8 Closest(CBLK *pal, CBLK x) { if (!L) ++L; uint16 R = f(x.R, L), G = f(x.G, L), B = f(x.B, L); - for (i = 0; i < 256; i ++) { + for (i = 0; i < 256; i++) { uint16 l = pal[i].R + pal[i].G + pal[i].B; if (! l) ++l; diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index cb2c2013f41..e2b2a29515a 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -54,7 +54,7 @@ MENU_BAR::MENU_BAR(uint16 w) { memset(p + i - w, MB_RB, w); p1 = p; p2 = p + i - 1; - for (i = 0; i < h; i ++) { + for (i = 0; i < h; i++) { *p1 = MB_LT; *p2 = MB_RB; p1 += w; @@ -76,14 +76,14 @@ char *VMGather(CHOICE *list) { CHOICE *cp; int len = 0, h = 0; - for (cp = list; cp->Text; cp ++) { + for (cp = list; cp->Text; cp++) { len += strlen(cp->Text); ++h; } vmgt = new char[len + h]; if (vmgt) { *vmgt = '\0'; - for (cp = list; cp->Text; cp ++) { + for (cp = list; cp->Text; cp++) { if (*vmgt) strcat(vmgt, "|"); strcat(vmgt, cp->Text); @@ -105,7 +105,7 @@ VMENU::VMENU(CHOICE *list, int x, int y) Addr = this; delete[] vmgt; Items = 0; - for (cp = list; cp->Text; cp ++) + for (cp = list; cp->Text; cp++) ++Items; Flags.BDel = true; Flags.Kill = true; From e0673c113563ab9fc28d08c07a3bcb5c3b98fa1c Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 26 Jun 2011 12:52:07 +0200 Subject: [PATCH 032/276] CGE: get rid of memicmp --- engines/cge/btfile.cpp | 13 ++++++------- engines/cge/startup.cpp | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 12c35194660..db0ebc2d5f3 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -72,7 +72,7 @@ void BTFILE::PutPage(int lev, bool hard) { BT_PAGE *BTFILE::GetPage(int lev, uint16 pgn) { if (Buff[lev].PgNo != pgn) { - uint32 pos = pgn * sizeof(BT_PAGE); + int32 pos = pgn * sizeof(BT_PAGE); PutPage(lev); Buff[lev].PgNo = pgn; if (Size() > pos) { @@ -90,9 +90,6 @@ BT_PAGE *BTFILE::GetPage(int lev, uint16 pgn) { return Buff[lev].Page; } -// Does this work, or does it have to compare the entire buffer? -#define memicmp(s1, s2, n) scumm_strnicmp((const char *)s1, (const char *)s2, n) - BT_KEYPACK *BTFILE::Find(const char *key) { int lev = 0; uint16 nxt = BT_ROOT; @@ -102,7 +99,8 @@ BT_KEYPACK *BTFILE::Find(const char *key) { if (pg->Hea.Down != BT_NONE) { int i; for (i = 0; i < pg->Hea.Count; i++) { - if (memicmp(key, pg->Inn[i].Key, BT_KEYLEN) < 0) + // Does this work, or does it have to compare the entire buffer? + if (scumm_strnicmp((const char *) key, (const char*)pg->Inn[i].Key, BT_KEYLEN) < 0) break; } nxt = (i) ? pg->Inn[i - 1].Down : pg->Hea.Down; @@ -110,9 +108,10 @@ BT_KEYPACK *BTFILE::Find(const char *key) { ++ lev; } else { int i; - for (i = 0; i < pg->Hea.Count - 1; i++) + for (i = 0; i < pg->Hea.Count - 1; i++) { if (scumm_stricmp((const char *)key, (const char *)pg->Lea[i].Key) <= 0) break; + } Buff[lev].Indx = i; return &pg->Lea[i]; } @@ -122,7 +121,7 @@ BT_KEYPACK *BTFILE::Find(const char *key) { int keycomp(const void *k1, const void *k2) { - return memicmp(k1, k2, BT_KEYLEN); + return scumm_strnicmp((const char *) k1, (const char*) k2, BT_KEYLEN); } diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 631a64d732c..4895ce98611 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -150,7 +150,7 @@ const char *UsrPath(const char *nam) { if (j) if (buf[--j] == '\n') buf[j] = '\0'; - if (memicmp(buf, key, i) == 0) + if (scumm_strnicmp((const char *) buf, (const char*) key, i) == 0) ok = true; } if (ok) { From 083d6ff6122cb2faf0a4330eb480bb9f77afa255 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 27 Jun 2011 01:03:47 +0200 Subject: [PATCH 033/276] CGE: remove some if(n)def DEMO by using a new flag. Added CGEEngine in several classes in order to do so. --- engines/cge/cge.cpp | 33 +++--- engines/cge/cge.h | 39 ++++++- engines/cge/cge_main.cpp | 213 +++++++++++++++++++------------------- engines/cge/cge_main.h | 39 +++---- engines/cge/config.cpp | 126 +++++++++++----------- engines/cge/detection.cpp | 4 +- engines/cge/game.cpp | 4 +- engines/cge/game.h | 4 +- engines/cge/gettext.cpp | 6 +- engines/cge/gettext.h | 11 +- engines/cge/jbw.h | 9 +- engines/cge/mixer.cpp | 4 +- engines/cge/mixer.h | 8 +- engines/cge/mouse.cpp | 2 +- engines/cge/mouse.h | 12 ++- engines/cge/snail.cpp | 9 +- engines/cge/snail.h | 7 +- engines/cge/talk.cpp | 10 +- engines/cge/talk.h | 10 +- engines/cge/text.cpp | 14 +-- engines/cge/text.h | 5 +- engines/cge/vga13h.cpp | 5 +- engines/cge/vga13h.h | 5 +- engines/cge/vmenu.cpp | 14 +-- engines/cge/vmenu.h | 12 ++- 25 files changed, 329 insertions(+), 276 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index d056a6737de..d09085857fd 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -45,7 +45,8 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) // Debug/console setup DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel"); - debug("CGEEngine::CGEEngine"); + _isDemo = _gameDescription->flags & ADGF_DEMO; + } void CGEEngine::setup() { @@ -56,22 +57,22 @@ void CGEEngine::setup() { VFILE::init(); // Initialise engine objects - Text = new TEXT(ProgName(), 128); + Text = new TEXT(this, ProgName(), 128); Vga = new VGA(M13H); Heart = new HEART; - Hero = new WALK(NULL); - Sys = new SYSTEM(); - PocLight = new SPRITE(LI); - Mouse = new MOUSE; + Hero = new WALK(this, NULL); + Sys = new SYSTEM(this); + PocLight = new SPRITE(this, LI); + Mouse = new MOUSE(this); for (int i = 0; i < POCKET_NX; i++) - Pocket[i] = new SPRITE(NULL); - Sprite = new SPRITE(NULL); - MiniCave = new SPRITE(NULL); - Shadow = new SPRITE(NULL); - HorzLine = new SPRITE(HL); - InfoLine = new INFO_LINE(INFO_W); - CavLight = new SPRITE(PR); - DebugLine = new INFO_LINE(SCR_WID); + Pocket[i] = new SPRITE(this, NULL); + Sprite = new SPRITE(this, NULL); + MiniCave = new SPRITE(this, NULL); + Shadow = new SPRITE(this, NULL); + HorzLine = new SPRITE(this, HL); + InfoLine = new INFO_LINE(this, INFO_W); + CavLight = new SPRITE(this, PR); + DebugLine = new INFO_LINE(this, SCR_WID); MB[0] = new BITMAP("BRICK"); MB[1] = NULL; HL[0] = new BITMAP("HLINE"); @@ -89,8 +90,8 @@ void CGEEngine::setup() { LI[2] = new BITMAP("LITE2"); LI[3] = new BITMAP("LITE3"); LI[4] = NULL; - Snail = new SNAIL(false); - Snail_ = new SNAIL(true); + Snail = new SNAIL(this, false); + Snail_ = new SNAIL(this, true); OffUseCount = atoi(Text->getText(OFF_USE_COUNT)); } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index f8857f045ff..c3f241b2fe2 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -23,6 +23,7 @@ #ifndef CGE_H #define CGE_H +#include "cge/general.h" #include "common/random.h" #include "engines/engine.h" #include "gui/debugger.h" @@ -47,15 +48,51 @@ public: ~CGEEngine(); const ADGameDescription *_gameDescription; + bool _isDemo; virtual Common::Error run(); GUI::Debugger *getDebugger() { return _console; } + void cge_main(); + void SwitchCave(int cav); + void StartCountDown(); + void Quit(); + void ResetQSwitch(); + void OptionTouch(int opt, uint16 mask); + void LoadGame(XFILE &file, bool tiny); + void SetMapBrick(int x, int z); + void SwitchMapping(); + void LoadSprite(const char *fname, int ref, int cav, int col, int row, int pos); + void LoadScript(const char *fname); + void LoadUser(); + void RunGame(); + bool ShowTitle(const char *name); + void Movie(const char *ext); + void TakeName(); + void Inf(const char *txt); + void SelectSound(); + void SNSelect(); + void dummy() {} + void NONE(); + void SB(); + void CaveDown(); + void XCave(); + void QGame(); + void SBM(); + void GUS(); + void GUSM(); + void MIDI(); + void AUTO(); + void SetPortD(); + void SetPortM(); + void SetIRQ(); + void SetDMA(); + void MainLoop(); + private: CGEConsole *_console; - void setup(); }; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 4121efdb785..dda6041f0a8 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -44,6 +44,7 @@ #include "cge/gettext.h" #include "cge/mixer.h" #include "cge/cge_main.h" +#include "cge/cge.h" #include #include #include @@ -54,7 +55,7 @@ namespace CGE { #define STACK_SIZ (K(2)) -#define SVGCHKSUM (1956+Now+OldLev+Game+Music+DemoText) +#define SVGCHKSUM (1956 + Now + OldLev + Game + Music + DemoText) #define SVG0NAME ("{{INIT}}" SVG_EXT) #define SVG0FILE CFILE @@ -142,7 +143,6 @@ static int Startup = 1; int OffUseCount; uint16 *intStackPtr = false; - HXY HeroXY[CAVE_MAX] = {{0, 0}}; BAR Barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; @@ -248,7 +248,7 @@ struct SAVTAB { }; -static void LoadGame(XFILE &file, bool tiny = false) { +void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { SAVTAB *st; SPRITE *spr; int i; @@ -274,15 +274,15 @@ static void LoadGame(XFILE &file, bool tiny = false) { if (! tiny) { // load sprites & pocket while (! file.Error) { - SPRITE S(NULL); + SPRITE S(this, NULL); uint16 n = file.Read((uint8 *) &S, sizeof(S)); if (n != sizeof(S)) break; S.Prev = S.Next = NULL; - spr = (scumm_stricmp(S.File + 2, "MUCHA") == 0) ? new FLY(NULL) - : new SPRITE(NULL); + spr = (scumm_stricmp(S.File + 2, "MUCHA") == 0) ? new FLY(this, NULL) + : new SPRITE(this, NULL); if (spr == NULL) error("No core"); *spr = S; @@ -385,8 +385,8 @@ CLUSTER Trace[MAX_FIND_LEVEL]; int FindLevel; -WALK::WALK(BMP_PTR *shpl) - : SPRITE(shpl), Dir(NO_DIR), TracePtr(-1) { +WALK::WALK(CGEEngine *vm, BMP_PTR *shpl) + : SPRITE(vm, shpl), Dir(NO_DIR), TracePtr(-1), _vm(vm) { } @@ -545,13 +545,15 @@ void WALK::Reach(SPRITE *spr, int mode) { class SQUARE : public SPRITE { public: - SQUARE(void); + SQUARE(CGEEngine *vm); void Touch(uint16 mask, int x, int y); +private: + CGEEngine *_vm; }; -SQUARE::SQUARE(void) - : SPRITE(MB) { +SQUARE::SQUARE(CGEEngine *vm) + : SPRITE(vm, MB), _vm(vm) { Flags.Kill = true; Flags.BDel = false; } @@ -566,8 +568,8 @@ void SQUARE::Touch(uint16 mask, int x, int y) { } -static void SetMapBrick(int x, int z) { - SQUARE *s = new SQUARE; +void CGEEngine::SetMapBrick(int x, int z) { + SQUARE *s = new SQUARE(this); if (s) { static char n[] = "00:00"; s->Goto(x * MAP_XGRID, MAP_TOP + z * MAP_ZGRID); @@ -579,10 +581,9 @@ static void SetMapBrick(int x, int z) { } } -void dummy(void) {} -static void SwitchMapping(void); +//static void SwitchMapping(void); static void SwitchColorMode(void); -static void StartCountDown(void); +//static void StartCountDown(void); static void SwitchDebug(void); static void SwitchMusic(void); static void KillSprite(void); @@ -597,16 +598,17 @@ static void KeyClick(void) { } -static void ResetQSwitch(void) { +void CGEEngine::ResetQSwitch() { SNPOST_(SNSEQ, 123, 0, NULL); KeyClick(); } -static void Quit(void) { - static CHOICE QuitMenu[] = { { NULL, StartCountDown }, - { NULL, ResetQSwitch }, - { NULL, dummy } +void CGEEngine::Quit() { + static CHOICE QuitMenu[] = { + { NULL, &CGEEngine::StartCountDown }, + { NULL, &CGEEngine::ResetQSwitch }, + { NULL, &CGEEngine::dummy } }; if (Snail->Idle() && ! Hero->Flags.Hide) { @@ -616,7 +618,7 @@ static void Quit(void) { } else { QuitMenu[0].Text = Text->getText(QUIT_TEXT); QuitMenu[1].Text = Text->getText(NOQUIT_TEXT); - (new VMENU(QuitMenu, -1, -1))->SetName(Text->getText(QUIT_TITLE)); + (new VMENU(this, QuitMenu, -1, -1))->SetName(Text->getText(QUIT_TITLE)); SNPOST_(SNSEQ, 123, 1, NULL); KeyClick(); } @@ -744,7 +746,7 @@ static void CaveUp(void) { } -static void CaveDown(void) { +void CGEEngine::CaveDown() { SPRITE *spr; if (! HorzLine->Flags.Hide) SwitchMapping(); @@ -762,13 +764,13 @@ static void CaveDown(void) { } -static void XCave(void) { +void CGEEngine::XCave() { CaveDown(); CaveUp(); } -static void QGame(void) { +void CGEEngine::QGame() { CaveDown(); OldLev = Lev; SaveSound(); @@ -779,7 +781,7 @@ static void QGame(void) { } -void SwitchCave(int cav) { +void CGEEngine::SwitchCave(int cav) { if (cav != Now) { Heart->Enable = false; if (cav < 0) { @@ -793,11 +795,10 @@ void SwitchCave(int cav) { if (Hero) { Hero->Park(); Hero->Step(0); -#ifndef DEMO + if (!_isDemo) ///// protection: auto-destruction on! ---------------------- - Vga->SpareQ->Show = STARTUP::Summa * (cav <= CAVE_MAX); + Vga->SpareQ->Show = STARTUP::Summa * (cav <= CAVE_MAX); /////-------------------------------------------------------- -#endif } CavLight->Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); @@ -812,7 +813,7 @@ void SwitchCave(int cav) { } } -SYSTEM::SYSTEM() : SPRITE(NULL) { +SYSTEM::SYSTEM(CGEEngine *vm) : SPRITE(vm, NULL), _vm(vm) { FunDel = HEROFUN0; SetPal(); Tick(); @@ -820,7 +821,6 @@ SYSTEM::SYSTEM() : SPRITE(NULL) { void SYSTEM::Touch(uint16 mask, int x, int y) { static int pp = 0; - void SwitchCave(int cav); FunTouch(); @@ -862,7 +862,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { if (KEYBOARD::Key[ALT]) SaveMapping(); else - SwitchMapping(); + _vm->SwitchMapping(); break; case F1: SwitchDebug(); @@ -911,7 +911,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { break; case F10 : if (Snail->Idle() && ! Hero->Flags.Hide) - StartCountDown(); + _vm->StartCountDown(); break; case 'J': if (pp == 0) @@ -956,14 +956,14 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { if (mask & L_UP) { if (cav && Snail->Idle() && Hero->TracePtr < 0) - SwitchCave(cav); + _vm->SwitchCave(cav); if (!HorzLine->Flags.Hide) { if (y >= MAP_TOP && y < MAP_TOP + MAP_HIG) { int8 x1, z1; XZ(x, y).Split(x1, z1); CLUSTER::Map[z1][x1] = 1; - SetMapBrick(x1, z1); + _vm->SetMapBrick(x1, z1); } } else { @@ -1057,18 +1057,17 @@ static void SwitchMusic(void) { } -static void StartCountDown(void) { +void CGEEngine::StartCountDown() { //SNPOST(SNSEQ, 123, 0, NULL); SwitchCave(-1); } -#ifndef DEMO -static void TakeName(void) { +void CGEEngine::TakeName() { if (GET_TEXT::Ptr) SNPOST_(SNKILL, -1, 0, GET_TEXT::Ptr); else { - GET_TEXT *tn = new GET_TEXT(Text->getText(GETNAME_PROMPT), UsrFnam, 8, KeyClick); + GET_TEXT *tn = new GET_TEXT(this, Text->getText(GETNAME_PROMPT), UsrFnam, 8, KeyClick); if (tn) { tn->SetName(Text->getText(GETNAME_TITLE)); tn->Center(); @@ -1078,10 +1077,9 @@ static void TakeName(void) { } } } -#endif -static void SwitchMapping(void) { +void CGEEngine::SwitchMapping() { if (HorzLine->Flags.Hide) { int i; for (i = 0; i < MAP_ZCNT; i++) { @@ -1228,7 +1226,7 @@ static void SwitchDebug(void) { } -static void OptionTouch(int opt, uint16 mask) { +void CGEEngine::OptionTouch(int opt, uint16 mask) { switch (opt) { case 1 : if (mask & L_UP) @@ -1240,7 +1238,7 @@ static void OptionTouch(int opt, uint16 mask) { else if (mask & R_UP) if (! MIXER::Appear) { MIXER::Appear = true; - new MIXER(BUTTON_X, BUTTON_Y); + new MIXER(this, BUTTON_X, BUTTON_Y); } break; case 3 : @@ -1259,7 +1257,7 @@ void SPRITE::Touch(uint16 mask, int x, int y) { if (mask & (R_DN | L_DN)) Sprite = this; if (Ref / 10 == 12) { - OptionTouch(Ref % 10, mask); + _vm->OptionTouch(Ref % 10, mask); return; } if (Flags.Syst) @@ -1324,7 +1322,7 @@ void SPRITE::Touch(uint16 mask, int x, int y) { } -static void LoadSprite(const char *fname, int ref, int cav, int col = 0, int row = 0, int pos = 0) { +void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int row = 0, int pos = 0) { static const char *Comd[] = { "Name", "Type", "Phase", "East", "Left", "Right", "Top", "Bottom", "Seq", "Near", "Take", @@ -1391,7 +1389,7 @@ static void LoadSprite(const char *fname, int ref, int cav, int col = 0, int row // make sprite of choosen type switch (type) { case 1 : { // AUTO - Sprite = new SPRITE(NULL); + Sprite = new SPRITE(this, NULL); if (Sprite) { Sprite->Goto(col, row); //Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$ @@ -1399,7 +1397,7 @@ static void LoadSprite(const char *fname, int ref, int cav, int col = 0, int row break; } case 2 : { // WALK - WALK *w = new WALK(NULL); + WALK *w = new WALK(this, NULL); if (w && ref == 1) { w->Goto(col, row); if (Hero) @@ -1444,13 +1442,13 @@ static void LoadSprite(const char *fname, int ref, int cav, int col = 0, int row break; } case 5 : { // FLY - FLY *f = new FLY(NULL); + FLY *f = new FLY(this, NULL); Sprite = f; //////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$ break; } default: { // DEAD - Sprite = new SPRITE(NULL); + Sprite = new SPRITE(this, NULL); if (Sprite) Sprite->Goto(col, row); break; @@ -1474,7 +1472,7 @@ static void LoadSprite(const char *fname, int ref, int cav, int col = 0, int row } -static void LoadScript(const char *fname) { +void CGEEngine::LoadScript(const char *fname) { char line[LINE_MAX]; char *SpN; int SpI, SpA, SpX, SpY, SpZ; @@ -1534,30 +1532,29 @@ static void LoadScript(const char *fname) { } -static void MainLoop(void) { +void CGEEngine::MainLoop() { SayDebug(); -#ifdef DEMO - static uint32 tc = 0; - if (/* FIXME: TimerCount - tc >= ((182L*6L) * 5L) && */ Talk == NULL && Snail.Idle()) { - if (Text->getText(DemoText)) { - SNPOST(SNSOUND, -1, 4, NULL); // drumla - SNPOST(SNINF, -1, DemoText, NULL); - SNPOST(SNLABEL, -1, -1, NULL); - if (Text->getText(++ DemoText) == NULL) - DemoText = DEMO_TEXT + 1; + if (_isDemo) { + static uint32 tc = 0; + if (/* FIXME: TimerCount - tc >= ((182L * 6L) * 5L) && */ Talk == NULL && Snail->Idle()) { + if (Text->getText(DemoText)) { + SNPOST(SNSOUND, -1, 4, NULL); // drumla + SNPOST(SNINF, -1, DemoText, NULL); + SNPOST(SNLABEL, -1, -1, NULL); + if (Text->getText(++ DemoText) == NULL) + DemoText = DEMO_TEXT + 1; + } + //FIXME: tc = TimerCount; } - //FIXME: tc = TimerCount; } -#endif - Vga->Show(); Snail_->RunCom(); Snail->RunCom(); } -void LoadUser(void) { +void CGEEngine::LoadUser() { // set scene if (STARTUP::Mode == 0) { // user .SVG file found CFILE cfile = CFILE(UsrPath(UsrFnam), REA, RCrypt); @@ -1578,7 +1575,7 @@ void LoadUser(void) { } -static void RunGame(void) { +void CGEEngine::RunGame() { Text->Clear(); Text->Preload(100, 1000); LoadHeroXY(); @@ -1689,7 +1686,7 @@ static void RunGame(void) { } -void Movie(const char *ext) { +void CGEEngine::Movie(const char *ext) { const char *fn = ProgName(ext); if (INI_FILE::Exist(fn)) { LoadScript(fn); @@ -1711,13 +1708,13 @@ void Movie(const char *ext) { } -bool ShowTitle(const char *name) { +bool CGEEngine::ShowTitle(const char *name) { BITMAP::Pal = SysPal; BMP_PTR LB[] = { new BITMAP(name), NULL }; BITMAP::Pal = NULL; bool usr_ok = false; - SPRITE D(LB); + SPRITE D(this, LB); D.Flags.Kill = true; D.Flags.BDel = true; D.Center(); @@ -1752,42 +1749,43 @@ bool ShowTitle(const char *name) { } if (STARTUP::Mode < 2) { -#ifdef DEMO - strcpy(UsrFnam, ProgName(SVG_EXT)); - usr_ok = true; -#else - //----------------------------------------- + if (_isDemo) { + strcpy(UsrFnam, ProgName(SVG_EXT)); + usr_ok = true; + } else { + //----------------------------------------- #ifndef EVA #ifdef CD - STARTUP::Summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; + STARTUP::Summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; #else -// Boot * b = ReadBoot(getdisk()); - warning("ShowTitle: FIXME ReadBoot"); - Boot *b = ReadBoot(0); - uint32 sn = (b->XSign == 0x29) ? b->Serial : b->lTotSecs; - free(b); - sn -= ((IDENT *)Copr)->disk; - STARTUP::Summa |= Lo(sn) | Hi(sn); +// Boot * b = ReadBoot(getdisk()); + warning("ShowTitle: FIXME ReadBoot"); + Boot *b = ReadBoot(0); + uint32 sn = (b->XSign == 0x29) ? b->Serial : b->lTotSecs; + free(b); + sn -= ((IDENT *)Copr)->disk; + STARTUP::Summa |= Lo(sn) | Hi(sn); #endif + //----------------------------------------- + Movie("X00"); // paylist + Vga->CopyPage(1, 2); + Vga->CopyPage(0, 1); + Vga->ShowQ->Append(Mouse); + //Mouse.On(); + Heart->Enable = true; + for (TakeName(); GET_TEXT::Ptr;) + MainLoop(); + Heart->Enable = false; + if (KEYBOARD::Last() == Enter && *UsrFnam) + usr_ok = true; + if (usr_ok) + strcat(UsrFnam, SVG_EXT); + //Mouse.Off(); + Vga->ShowQ->Clear(); + Vga->CopyPage(0, 2); #endif - //----------------------------------------- - Movie("X00"); // paylist - Vga->CopyPage(1, 2); - Vga->CopyPage(0, 1); - Vga->ShowQ->Append(Mouse); - //Mouse.On(); - Heart->Enable = true; - for (TakeName(); GET_TEXT::Ptr;) - MainLoop(); - Heart->Enable = false; - if (KEYBOARD::Last() == Enter && *UsrFnam) - usr_ok = true; - if (usr_ok) - strcat(UsrFnam, SVG_EXT); - //Mouse.Off(); - Vga->ShowQ->Clear(); - Vga->CopyPage(0, 2); -#endif + } + if (usr_ok && STARTUP::Mode == 0) { const char *n = UsrPath(UsrFnam); if (CFILE::Exist(n)) { @@ -1809,11 +1807,10 @@ bool ShowTitle(const char *name) { Vga->CopyPage(0, 2); -#ifdef DEMO - return true; -#else - return (STARTUP::Mode == 2 || usr_ok); -#endif + if (_isDemo) + return true; + else + return (STARTUP::Mode == 2 || usr_ok); } @@ -1825,7 +1822,7 @@ void StkDump (void) { */ -void cge_main(void) { +void CGEEngine::cge_main(void) { uint16 intStack[STACK_SIZ / 2]; intStackPtr = intStack; @@ -1842,17 +1839,15 @@ void cge_main(void) { HorzLine->Flags.Hide = true; //srand((uint16) Timer()); - Sys = new SYSTEM; + Sys = new SYSTEM(this); if (Music && STARTUP::SoundOk) LoadMIDI(0); if (STARTUP::Mode < 2) Movie(LGO_EXT); if (ShowTitle("WELCOME")) { -#ifndef DEMO - if (STARTUP::Mode == 1) + if ((!_isDemo) && (STARTUP::Mode == 1)) Movie("X02"); // intro -#endif RunGame(); Startup = 2; if (FINIS) diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index f3a95e786cc..146c3cb6c9b 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -35,11 +35,11 @@ namespace CGE { #define TSEQ 96 -#define HTALK (TSEQ+4) -#define TOO_FAR (TSEQ+5) -#define NO_WAY (TSEQ+5) -#define POC_FUL (TSEQ+5) -#define OFF_USE (TSEQ+6) +#define HTALK (TSEQ + 4) +#define TOO_FAR (TSEQ + 5) +#define NO_WAY (TSEQ + 5) +#define POC_FUL (TSEQ + 5) +#define OFF_USE (TSEQ + 6) #define EXIT_OK_TEXT 40 #define NOMUSIC_TEXT 98 #define BADSVG_TEXT 99 @@ -57,25 +57,21 @@ namespace CGE { #define DEMO_TEXT 300 #define NOSOUND_TEXT 310 #define PAN_HIG 40 -#define WORLD_HIG (SCR_HIG-PAN_HIG) +#define WORLD_HIG (SCR_HIG - PAN_HIG) #define INFO_X 177 #define INFO_Y 164 #define INFO_W 140 - -#if defined(DEMO) #define CAVE_X 4 #define CAVE_Y 166 #define CAVE_SX 0 #define CAVE_SY 0 + +#ifdef DEMO #define CAVE_DX 23 #define CAVE_DY 29 #define CAVE_NX 3 #define CAVE_NY 1 #else -#define CAVE_X 4 -#define CAVE_Y 166 -#define CAVE_SX 0 -#define CAVE_SY 0 #define CAVE_DX 9 #define CAVE_DY 10 #define CAVE_NX 8 @@ -101,7 +97,7 @@ namespace CGE { #define SHP_MAX 1024 #define STD_DELAY 3 #define LEV_MAX 5 -#define CAVE_MAX (CAVE_NX*CAVE_NY) +#define CAVE_MAX (CAVE_NX * CAVE_NY) #define MAX_FIND_LEVEL 3 #define MAX_DISTANCE 3 #define INI_EXT ".INI" @@ -111,8 +107,8 @@ namespace CGE { #define WALKSIDE 10 #define BUSY_REF 500 #define SYSTIMERATE 6 // 12 Hz -#define HEROFUN0 (40*12) -#define HEROFUN1 ( 2*12) +#define HEROFUN0 (40 * 12) +#define HEROFUN1 ( 2 * 12) #define PAIN (Flag[0]) #define FINIS (Flag[3]) @@ -122,12 +118,14 @@ class SYSTEM : public SPRITE { public: int FunDel; - SYSTEM(); + SYSTEM(CGEEngine *vm); void SetPal(); void FunTouch(); void Touch(uint16 mask, int x, int y); void Tick(); +private: + CGEEngine *_vm; }; @@ -144,9 +142,10 @@ public: class WALK : public SPRITE { public: CLUSTER Here; - enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; int TracePtr; - WALK(BMP_PTR *shpl); + + enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; + WALK(CGEEngine *vm, BMP_PTR *shpl); void Tick(void); void FindWay(CLUSTER c); void FindWay(SPRITE *spr); @@ -155,6 +154,9 @@ public: void Park(void); bool Lower(SPRITE *spr); void Reach(SPRITE *spr, int mode = -1); +private: + CGEEngine *_vm; + }; @@ -163,7 +165,6 @@ CLUSTER XZ(COUPLE xy); void ExpandSprite(SPRITE *spr); void ContractSprite(SPRITE *spr); -void cge_main(void); extern WALK *Hero; extern VGA *Vga; diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index fe2d1bc16e7..4aa4f40c8a5 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -78,83 +78,83 @@ static int DevName[] = { }; static CHOICE DevMenu[] = { - { NULL, NONE }, - { NULL, SB }, - { NULL, SBM }, - { NULL, GUS }, - { NULL, GUSM }, - { NULL, MIDI }, - { NULL, AUTO }, - { NULL, NULL } + { NULL, &CGEEngine::NONE }, + { NULL, &CGEEngine::SB }, + { NULL, &CGEEngine::SBM }, + { NULL, &CGEEngine::GUS }, + { NULL, &CGEEngine::GUSM }, + { NULL, &CGEEngine::MIDI }, + { NULL, &CGEEngine::AUTO }, + { NULL, NULL } }; static CHOICE DigiPorts[] = { - { " 210h", SetPortD }, - { " 220h", SetPortD }, - { " 230h", SetPortD }, - { " 240h", SetPortD }, - { " 250h", SetPortD }, - { " 260h", SetPortD }, - { "AUTO ", SetPortD }, + { " 210h", &CGEEngine::SetPortD }, + { " 220h", &CGEEngine::SetPortD }, + { " 230h", &CGEEngine::SetPortD }, + { " 240h", &CGEEngine::SetPortD }, + { " 250h", &CGEEngine::SetPortD }, + { " 260h", &CGEEngine::SetPortD }, + { "AUTO ", &CGEEngine::SetPortD }, { NULL, NULL } }; static CHOICE MIDIPorts[] = { - { " 220h", SetPortM }, - { " 230h", SetPortM }, - { " 240h", SetPortM }, - { " 250h", SetPortM }, - { " 300h", SetPortM }, - { " 320h", SetPortM }, - { " 330h", SetPortM }, - { " 340h", SetPortM }, - { " 350h", SetPortM }, - { " 360h", SetPortM }, - { "AUTO ", SetPortM }, + { " 220h", &CGEEngine::SetPortM }, + { " 230h", &CGEEngine::SetPortM }, + { " 240h", &CGEEngine::SetPortM }, + { " 250h", &CGEEngine::SetPortM }, + { " 300h", &CGEEngine::SetPortM }, + { " 320h", &CGEEngine::SetPortM }, + { " 330h", &CGEEngine::SetPortM }, + { " 340h", &CGEEngine::SetPortM }, + { " 350h", &CGEEngine::SetPortM }, + { " 360h", &CGEEngine::SetPortM }, + { "AUTO ", &CGEEngine::SetPortM }, { NULL, NULL } }; static CHOICE BlsterIRQ[] = { - { "IRQ 2", SetIRQ }, - { "IRQ 5", SetIRQ }, - { "IRQ 7", SetIRQ }, - { "IRQ 10", SetIRQ }, - { "AUTO ", SetIRQ }, + { "IRQ 2", &CGEEngine::SetIRQ }, + { "IRQ 5", &CGEEngine::SetIRQ }, + { "IRQ 7", &CGEEngine::SetIRQ }, + { "IRQ 10", &CGEEngine::SetIRQ }, + { "AUTO ", &CGEEngine::SetIRQ }, { NULL, NULL } }; static CHOICE GravisIRQ[] = { - { "IRQ 2", SetIRQ }, - { "IRQ 5", SetIRQ }, - { "IRQ 7", SetIRQ }, - { "IRQ 11", SetIRQ }, - { "IRQ 12", SetIRQ }, - { "IRQ 15", SetIRQ }, - { "AUTO ", SetIRQ }, + { "IRQ 2", &CGEEngine::SetIRQ }, + { "IRQ 5", &CGEEngine::SetIRQ }, + { "IRQ 7", &CGEEngine::SetIRQ }, + { "IRQ 11", &CGEEngine::SetIRQ }, + { "IRQ 12", &CGEEngine::SetIRQ }, + { "IRQ 15", &CGEEngine::SetIRQ }, + { "AUTO ", &CGEEngine::SetIRQ }, { NULL, NULL } }; static CHOICE GravisDMA[] = { - { "DMA 1", SetDMA }, - { "DMA 3", SetDMA }, - { "DMA 5", SetDMA }, - { "DMA 6", SetDMA }, - { "DMA 7", SetDMA }, - { "AUTO ", SetDMA }, + { "DMA 1", &CGEEngine::SetDMA }, + { "DMA 3", &CGEEngine::SetDMA }, + { "DMA 5", &CGEEngine::SetDMA }, + { "DMA 6", &CGEEngine::SetDMA }, + { "DMA 7", &CGEEngine::SetDMA }, + { "AUTO ", &CGEEngine::SetDMA }, { NULL, NULL } }; static CHOICE BlsterDMA[] = { - { "DMA 0", SetDMA }, - { "DMA 1", SetDMA }, - { "DMA 3", SetDMA }, - { "AUTO ", SetDMA }, + { "DMA 0", &CGEEngine::SetDMA }, + { "DMA 1", &CGEEngine::SetDMA }, + { "DMA 3", &CGEEngine::SetDMA }, + { "AUTO ", &CGEEngine::SetDMA }, { NULL, NULL } }; -void SelectSound(void) { +void CGEEngine::SelectSound() { int i; Sound.Close(); if (VMENU::Addr) @@ -163,7 +163,7 @@ void SelectSound(void) { Talk->Goto(Talk->X, FONT_HIG / 2); for (i = 0; i < ArrayCount(DevName); i++) DevMenu[i].Text = Text->getText(DevName[i]); - (new VMENU(DevMenu, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); + (new VMENU(this, DevMenu, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); } @@ -195,10 +195,10 @@ static uint16 xdeco(const char *str) { static CHOICE *Cho; static int Hlp; -static void SNSelect(void) { +void CGEEngine::SNSelect() { Inf(Text->getText(Hlp)); Talk->Goto(Talk->X, FONT_HIG / 2); - (new VMENU(Cho, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); + (new VMENU(this, Cho, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); } @@ -211,14 +211,14 @@ static void Select(CHOICE *cho, int hlp) { } -static void NONE(void) { +void CGEEngine::NONE() { SNDDrvInfo.DDEV = DEV_QUIET; SNDDrvInfo.MDEV = DEV_QUIET; Sound.Open(); } -static void SB(void) { +void CGEEngine::SB() { SNDDrvInfo.DDEV = DEV_SB; SNDDrvInfo.MDEV = DEV_SB; Reset(); @@ -226,7 +226,7 @@ static void SB(void) { } -static void SBM(void) { +void CGEEngine::SBM() { SNDDrvInfo.DDEV = DEV_SB; SNDDrvInfo.MDEV = DEV_GM; Reset(); @@ -234,7 +234,7 @@ static void SBM(void) { } -static void GUS(void) { +void CGEEngine::GUS() { SNDDrvInfo.DDEV = DEV_GUS; SNDDrvInfo.MDEV = DEV_GUS; Reset(); @@ -242,7 +242,7 @@ static void GUS(void) { } -static void GUSM(void) { +void CGEEngine::GUSM() { SNDDrvInfo.DDEV = DEV_GUS; SNDDrvInfo.MDEV = DEV_GM; Reset(); @@ -250,7 +250,7 @@ static void GUSM(void) { } -static void MIDI(void) { +void CGEEngine::MIDI() { SNDDrvInfo.DDEV = DEV_QUIET; SNDDrvInfo.MDEV = DEV_GM; SNDDrvInfo.MBASE = DETECT; @@ -258,7 +258,7 @@ static void MIDI(void) { } -static void AUTO(void) { +void CGEEngine::AUTO() { SNDDrvInfo.DDEV = DEV_AUTO; SNDDrvInfo.MDEV = DEV_AUTO; Reset(); @@ -266,25 +266,25 @@ static void AUTO(void) { } -static void SetPortD(void) { +void CGEEngine::SetPortD() { SNDDrvInfo.DBASE = xdeco(DigiPorts[VMENU::Recent].Text); Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ, SIRQ_TEXT); } -static void SetPortM(void) { +void CGEEngine::SetPortM() { SNDDrvInfo.MBASE = xdeco(MIDIPorts[VMENU::Recent].Text); Sound.Open(); } -static void SetIRQ(void) { +void CGEEngine::SetIRQ() { SNDDrvInfo.DIRQ = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ)[VMENU::Recent].Text); Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA, SDMA_TEXT); } -static void SetDMA(void) { +void CGEEngine::SetDMA() { SNDDrvInfo.DDMA = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA)[VMENU::Recent].Text); if (SNDDrvInfo.MDEV != SNDDrvInfo.DDEV) Select(MIDIPorts, MPORT_TEXT); diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index bebb342c033..f03a42fb35f 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -64,7 +64,7 @@ static const ADGameDescription gameDescriptions[] = { {"vol.dat", 0, "75d385a6074c58b69f7730481f256051", 1796710}, AD_LISTEND }, - Common::PL_POL, Common::kPlatformPC, ADGF_NO_FLAGS, GUIO_NONE + Common::PL_POL, Common::kPlatformPC, ADGF_DEMO, GUIO_NONE }, { "soltys", "Soltys Demo", @@ -73,7 +73,7 @@ static const ADGameDescription gameDescriptions[] = { {"vol.dat", 0, "c5d9b15863cab61dc125551576dece04", 1075272}, AD_LISTEND }, - Common::PL_POL, Common::kPlatformPC, ADGF_NO_FLAGS, GUIO_NONE + Common::PL_POL, Common::kPlatformPC, ADGF_DEMO, GUIO_NONE }, AD_TABLE_END_MARKER }; diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index afa6fbeed08..21e8ceddeb8 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -67,8 +67,8 @@ int FLY::L = 20, FLY::B = 100; -FLY::FLY(BITMAP **shpl) - : SPRITE(shpl), Tx(0), Ty(0) { +FLY::FLY(CGEEngine *vm, BITMAP **shpl) + : SPRITE(vm, shpl), Tx(0), Ty(0), _vm(vm) { Step(new_random(2)); Goto(L + new_random(R - L - W), T + new_random(B - T - H)); } diff --git a/engines/cge/game.h b/engines/cge/game.h index 1d65d0c7678..7892b1c93ff 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -48,8 +48,10 @@ class FLY : public SPRITE { static int L, T, R, B; public: int Tx, Ty; - FLY(BITMAP **shpl); + FLY(CGEEngine *vm, BITMAP **shpl); void Tick(void); +private: + CGEEngine *_vm; }; } // End of namespace CGE diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index b6b47a05f9c..69e19b175c2 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -36,9 +36,9 @@ namespace CGE { GET_TEXT *GET_TEXT::Ptr = NULL; -GET_TEXT::GET_TEXT(const char *info, char *text, int size, void (*click)(void)) - : Text(text), Size(min(size, GTMAX)), Len(min(Size, strlen(text))), - Cntr(GTBLINK), Click(click), OldKeybClient(KEYBOARD::SetClient(this)) { +GET_TEXT::GET_TEXT(CGEEngine *vm, const char *info, char *text, int size, void (*click)(void)) + : TALK(vm), Text(text), Size(min(size, GTMAX)), Len(min(Size, strlen(text))), + Cntr(GTBLINK), Click(click), OldKeybClient(KEYBOARD::SetClient(this)), _vm(vm) { int i = 2 * TEXT_HM + Font->Width(info); Ptr = this; Mode = RECT; diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h index 3fc7e4ff34c..c868232677e 100644 --- a/engines/cge/gettext.h +++ b/engines/cge/gettext.h @@ -42,13 +42,16 @@ class GET_TEXT : public TALK { uint16 Size, Len; uint16 Cntr; SPRITE *OldKeybClient; - void (*Click)(void); + void (*Click)(); public: static GET_TEXT *Ptr; - GET_TEXT(const char *info, char *text, int size, void (*click)(void) = NULL); - ~GET_TEXT(void); + GET_TEXT(CGEEngine *vm, const char *info, char *text, int size, void (*click)(void) = NULL); + ~GET_TEXT(); void Touch(uint16 mask, int x, int y); - void Tick(void); + void Tick(); + +private: + CGEEngine *_vm; }; } // End of namespace CGE diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 4c96507ab78..12c6609f4eb 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -34,7 +34,6 @@ namespace CGE { // Defines found in cge.mak #define VOL -//#define DEMO #define INI_FILE VFILE // Or is it CFILE? #define PIC_FILE VFILE #define BMP_MODE 0 @@ -56,7 +55,7 @@ namespace CGE { #define IsAlNum(c) (IsAlpha(c) || IsDigit(c)) #define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) -#define farnew(t,n) ((t *) malloc(sizeof(t) * (n))) +#define farnew(t, n) ((t *) malloc(sizeof(t) * (n))) #define ArrayCount(a) (sizeof(a) / sizeof((a)[0])) #define MAX_TIMER 0x1800B0L @@ -141,12 +140,6 @@ struct KeyStatStruct { #define PostFlag (*((volatile uint16 *) ((void _seg *) 0x40 + (void *) 0x72))) #define POST ((void (*)(void)) ((void _seg *) 0xF000 + (void *) 0xFFF0)) -#ifdef DEMO -#define Demo(x) x -#else -#define Demo(x) -#endif - #ifdef __cplusplus #define EC extern "C" diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index e0a4409a868..864fb6cdba8 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -40,7 +40,7 @@ extern MOUSE *Mouse; bool MIXER::Appear = false; -MIXER::MIXER(int x, int y) : SPRITE(NULL), Fall(MIX_FALL) { +MIXER::MIXER(CGEEngine *vm, int x, int y) : SPRITE(vm, NULL), Fall(MIX_FALL), _vm(vm) { Appear = true; mb[0] = new BITMAP("VOLUME"); mb[1] = NULL; @@ -65,7 +65,7 @@ MIXER::MIXER(int x, int y) : SPRITE(NULL), Fall(MIX_FALL) { lb[i] = NULL; for (i = 0; i < ArrayCount(Led); i++) { - register SPRITE *spr = new SPRITE(lb); + register SPRITE *spr = new SPRITE(_vm, lb); spr->SetSeq(ls); spr->Goto(x + 2 + 12 * i, y + 8); spr->Flags.Tran = true; diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index 81bc7c7cdf9..d589aceaea2 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -48,10 +48,12 @@ class MIXER : public SPRITE { void Update(void); public: static bool Appear; - MIXER(int x, int y); - ~MIXER(void); + MIXER(CGEEngine *vm, int x, int y); + ~MIXER(); void Touch(uint16 mask, int x, int y); - void Tick(void); + void Tick(); +private: + CGEEngine *_vm; }; } // End of namespace CGE diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index 8ad12742d32..10953291f21 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -39,7 +39,7 @@ MOUSE_FUN *MOUSE::OldMouseFun = NULL; uint16 MOUSE::OldMouseMask = 0; -MOUSE::MOUSE(BITMAP **shpl) : SPRITE(shpl), Busy(NULL), Hold(NULL), hx(0) { +MOUSE::MOUSE(CGEEngine *vm, BITMAP **shpl) : SPRITE(vm, shpl), Busy(NULL), Hold(NULL), hx(0), _vm(vm) { static SEQ ms[] = { { 0, 0, 0, 0, 1 }, { 1, 1, 0, 0, 1 } diff --git a/engines/cge/mouse.h b/engines/cge/mouse.h index 78f43665cd6..61503fadd19 100644 --- a/engines/cge/mouse.h +++ b/engines/cge/mouse.h @@ -69,12 +69,14 @@ public: int Buttons; SPRITE *Busy; //SPRITE * Touched; - MOUSE(BITMAP **shpl = MC); - ~MOUSE(void); - void On(void); - void Off(void); + MOUSE(CGEEngine *vm, BITMAP **shpl = MC); + ~MOUSE(); + void On(); + void Off(); static void ClrEvt(SPRITE *spr = NULL); - void Tick(void); + void Tick(); +private: + CGEEngine *_vm; }; } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index cc79dfcc620..7325d767b40 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -424,10 +424,10 @@ const char *SNAIL::ComTxt[] = { }; -SNAIL::SNAIL(bool turbo) +SNAIL::SNAIL(CGEEngine *vm, bool turbo) : Turbo(turbo), Busy(false), TextDelay(false), Pause(0), TalkEnable(true), - Head(0), Tail(0), SNList(farnew(COM, 256)) { + Head(0), Tail(0), SNList(farnew(COM, 256)), _vm(vm) { } @@ -907,7 +907,6 @@ static void SNMouse(bool on) { void SNAIL::RunCom(void) { static int count = 1; -// extern void SwitchCave(int); if (! Busy) { Busy = true; uint8 tmphea = Head; @@ -955,13 +954,13 @@ void SNAIL::RunCom(void) { if (sprel && TalkEnable) { if (sprel == Hero && sprel->SeqTest(-1)) sprel->Step(HTALK); - Say(Text->getText(snc->Val), sprel); + Text->Say(Text->getText(snc->Val), sprel); Sys->FunDel = HEROFUN0; } break; case SNINF : if (TalkEnable) { - Inf(Text->getText(snc->Val)); + _vm->Inf(Text->getText(snc->Val)); Sys->FunDel = HEROFUN0; } break; diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 54c7809fda7..9449a8081e1 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -29,6 +29,7 @@ #define __SNAIL__ #include "cge/jbw.h" +#include "cge/cge.h" namespace CGE { @@ -89,12 +90,14 @@ public: uint16 Pause; static const char *ComTxt[]; bool TalkEnable; - SNAIL(bool turbo = false); - ~SNAIL(void); + SNAIL(CGEEngine *vm, bool turbo = false); + ~SNAIL(); void RunCom(void); void AddCom(SNCOM com, int ref = 0, int val = 0, void *ptr = NULL); void InsCom(SNCOM com, int ref = 0, int val = 0, void *ptr = NULL); bool Idle(void); +private: + CGEEngine *_vm; }; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 9f162d0e6c0..b67d9082acc 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -97,8 +97,8 @@ void FONT::Save(void) { */ -TALK::TALK(const char *tx, TBOX_STYLE mode) - : SPRITE(NULL), Mode(mode) { +TALK::TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode) + : SPRITE(vm, NULL), Mode(mode), _vm(vm) { TS[0] = TS[1] = NULL; Flags.Syst = true; Update(tx); @@ -106,8 +106,8 @@ TALK::TALK(const char *tx, TBOX_STYLE mode) } -TALK::TALK(void) - : SPRITE(NULL), Mode(PURE) { +TALK::TALK(CGEEngine *vm) + : SPRITE(vm, NULL), Mode(PURE), _vm(vm) { TS[0] = TS[1] = NULL; Flags.Syst = true; } @@ -275,7 +275,7 @@ void TALK::PutLine(int line, const char *text) { } -INFO_LINE::INFO_LINE(uint16 w) : OldTxt(NULL) { +INFO_LINE::INFO_LINE(CGEEngine *vm, uint16 w) : TALK(vm), OldTxt(NULL), _vm(vm) { TS[0] = new BITMAP(w, FONT_HIG, TEXT_BG); SetShapeList(TS); } diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 67b4fc91d62..ba4952c3e6c 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -75,20 +75,24 @@ protected: BITMAP *Box(uint16 w, uint16 h); public: FONT *Font; - TALK(const char *tx, TBOX_STYLE mode = PURE); - TALK(void); + TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode = PURE); + TALK(CGEEngine *vm); //~TALK (void); virtual void Update(const char *tx); virtual void Update(void) {} void PutLine(int line, const char *text); +private: + CGEEngine *_vm; }; class INFO_LINE : public TALK { const char *OldTxt; public: - INFO_LINE(uint16 wid); + INFO_LINE(CGEEngine *vm, uint16 wid); void Update(const char *tx); +private: + CGEEngine *_vm; }; } // End of namespace CGE diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index a8bf0d0cf87..6d7341af0a3 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -42,7 +42,7 @@ namespace CGE { TEXT *Text; TALK *Talk = NULL; -TEXT::TEXT(const char *fname, int size) { +TEXT::TEXT(CGEEngine *vm, const char *fname, int size) : _vm(vm) { Cache = new HAN[size]; MergeExt(FileName, fname, SAY_EXT); if (!INI_FILE::Exist(FileName)) @@ -55,7 +55,7 @@ TEXT::TEXT(const char *fname, int size) { } -TEXT::~TEXT(void) { +TEXT::~TEXT() { Clear(); delete[] Cache; } @@ -180,14 +180,14 @@ char *TEXT::getText(int ref) { } -void Say(const char *txt, SPRITE *spr) { +void TEXT::Say(const char *txt, SPRITE *spr) { KillText(); - Talk = new TALK(txt, ROUND); + Talk = new TALK(_vm, txt, ROUND); if (Talk) { bool east = spr->Flags.East; int x = (east) ? (spr->X + spr->W - 2) : (spr->X + 2); int y = spr->Y + 2; - SPRITE *spike = new SPRITE(SP); + SPRITE *spike = new SPRITE(_vm, SP); uint16 sw = spike->W; if (east) { @@ -221,9 +221,9 @@ void Say(const char *txt, SPRITE *spr) { } } -void Inf(const char *txt) { +void CGEEngine::Inf(const char *txt) { KillText(); - Talk = new TALK(txt, RECT); + Talk = new TALK(this, txt, RECT); if (Talk) { Talk->Flags.Kill = true; Talk->Flags.BDel = true; diff --git a/engines/cge/text.h b/engines/cge/text.h index 64e3b1d6693..161b2e813ae 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -61,11 +61,14 @@ class TEXT { char *Load(int idx, int ref); int Find(int ref); public: - TEXT(const char *fname, int size); + TEXT(CGEEngine *vm, const char *fname, int size); ~TEXT(void); void Clear(int from = 1, int upto = 0x7FFF); void Preload(int from = 1, int upto = 0x7FFF); char *getText(int ref); + void Say(const char *txt, SPRITE *spr); +private: + CGEEngine *_vm; }; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d7c6946e879..1038cd26314 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -35,6 +35,7 @@ #include #include #include +#include "cge/cge.h" namespace CGE { @@ -345,10 +346,10 @@ void HEART::SetXTimer(uint16 *ptr, uint16 time) { } -SPRITE::SPRITE(BMP_PTR *shp) +SPRITE::SPRITE(CGEEngine *vm, BMP_PTR *shp) : X(0), Y(0), Z(0), NearPtr(0), TakePtr(0), Next(NULL), Prev(NULL), SeqPtr(NO_SEQ), Time(0), //Delay(0), - Ext(NULL), Ref(-1), Cave(0) { + Ext(NULL), Ref(-1), Cave(0), _vm(vm) { memset(File, 0, sizeof(File)); *((uint16 *)&Flags) = 0; SetShapeList(shp); diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index d5bbf3972e9..7d239540592 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -32,6 +32,7 @@ #include #include "cge/bitmap.h" #include "cge/snail.h" +#include "cge/cge.h" namespace CGE { @@ -197,7 +198,7 @@ public: inline bool Active(void) { return Ext != NULL; } - SPRITE(BMP_PTR *shp); + SPRITE(CGEEngine *vm, BMP_PTR *shp); virtual ~SPRITE(void); BMP_PTR Shp(void); BMP_PTR *SetShapeList(BMP_PTR *shp); @@ -222,6 +223,8 @@ public: SNAIL::COM *SnList(SNLIST type); virtual void Touch(uint16 mask, int x, int y); virtual void Tick(void); +private: + CGEEngine *_vm; }; diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index e2b2a29515a..7db5a79f856 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -45,7 +45,7 @@ namespace CGE { -MENU_BAR::MENU_BAR(uint16 w) { +MENU_BAR::MENU_BAR(CGEEngine *vm, uint16 w) : TALK(vm), _vm(vm) { int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h; uint8 *p = farnew(uint8, i), * p1, * p2; @@ -98,8 +98,8 @@ VMENU *VMENU::Addr = NULL; int VMENU::Recent = -1; -VMENU::VMENU(CHOICE *list, int x, int y) - : TALK(VMGather(list), RECT), Menu(list), Bar(NULL) { +VMENU::VMENU(CGEEngine *vm, CHOICE *list, int x, int y) + : TALK(vm, VMGather(list), RECT), Menu(list), Bar(NULL), _vm(vm) { CHOICE *cp; Addr = this; @@ -114,7 +114,7 @@ VMENU::VMENU(CHOICE *list, int x, int y) else Goto(x - W / 2, y - (TEXT_VM + FONT_HIG / 2)); Vga->ShowQ->Insert(this, Vga->ShowQ->Last()); - Bar = new MENU_BAR(W - 2 * TEXT_HM); + Bar = new MENU_BAR(_vm, W - 2 * TEXT_HM); Bar->Goto(X + TEXT_HM - MB_HM, Y + TEXT_VM - MB_VM); Vga->ShowQ->Insert(Bar, Vga->ShowQ->Last()); } @@ -126,7 +126,7 @@ VMENU::~VMENU(void) { void VMENU::Touch(uint16 mask, int x, int y) { -#define h (FONT_HIG + TEXT_LS) + uint16 h = FONT_HIG + TEXT_LS; bool ok = false; if (Items) { @@ -147,10 +147,10 @@ void VMENU::Touch(uint16 mask, int x, int y) { if (ok && (mask & L_UP)) { Items = 0; SNPOST_(SNKILL, -1, 0, this); - Menu[Recent = n].Proc(); + //Menu[Recent = n].Proc(); + warning("Missing call to proc()"); } } -#undef h } } // End of namespace CGE diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index ecec9d51b58..61645d2c55b 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -38,13 +38,15 @@ namespace CGE { typedef struct { char *Text; - void (* Proc)(void); + void (CGEEngine::*Proc)(); } CHOICE; class MENU_BAR : public TALK { public: - MENU_BAR(uint16 w); + MENU_BAR(CGEEngine *vm, uint16 w); +private: + CGEEngine *_vm; }; @@ -55,9 +57,11 @@ public: static VMENU *Addr; static int Recent; MENU_BAR *Bar; - VMENU(CHOICE *list, int x, int y); - ~VMENU(void); + VMENU(CGEEngine *vm, CHOICE *list, int x, int y); + ~VMENU(); void Touch(uint16 mask, int x, int y); +private: + CGEEngine *_vm; }; } // End of namespace CGE From e13317baeab99f4868d49a89e110deda1d5ca5f4 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 27 Jun 2011 18:57:58 +1000 Subject: [PATCH 034/276] CGE: Beginnings of work on graphics support --- engines/cge/bitmap.cpp | 20 ++- engines/cge/bitmap.h | 5 + engines/cge/cge.cpp | 4 + engines/cge/cge_main.cpp | 17 +- engines/cge/general.cpp | 7 +- engines/cge/snail.cpp | 9 +- engines/cge/vga13h.cpp | 377 ++++++++++++--------------------------- engines/cge/vga13h.h | 11 +- 8 files changed, 170 insertions(+), 280 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index b528b5578d5..4112ccb3803 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -30,6 +30,7 @@ #include "cge/jbw.h" #include "cge/vol.h" #include "cge/cfile.h" +#include "cge/vga13h.h" #include "common/system.h" namespace CGE { @@ -37,6 +38,13 @@ namespace CGE { DAC *BITMAP::Pal = NULL; #define MAXPATH 128 +void BITMAP::init() { + Pal = NULL; +} + +void BITMAP::deinit() { +} + #pragma argsused BITMAP::BITMAP(const char *fname, bool rem) : M(NULL), V(NULL) { char pat[MAXPATH]; @@ -369,7 +377,7 @@ bool BITMAP::VBMSave(XFILE *f) { if (f->Error == 0) if (p) - f->Write((uint8 *)Pal, 256 * sizeof(DAC)); + f->Write((uint8 *)Pal, 256 * 3); if (f->Error == 0) f->Write(V, n); @@ -394,10 +402,12 @@ bool BITMAP::VBMLoad(XFILE *f) { if (f->Error == 0) { if (p) { - if (Pal) - f->Read((uint8 *)Pal, 256 * sizeof(DAC)); - else - f->Seek(f->Mark() + 256 * sizeof(DAC)); + if (Pal) { + byte palData[PAL_SIZ]; + f->Read(palData, PAL_SIZ); + VGA::pal2DAC(palData, Pal); + } else + f->Seek(f->Mark() + PAL_SIZ); } } if ((V = farnew(uint8, n)) == NULL) diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index eca3be70e8c..13e28f43698 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -39,6 +39,7 @@ namespace CGE { #define TRANS 0xFE +#include "common/pack-start.h" typedef struct { uint16 b : 2; @@ -56,6 +57,7 @@ typedef struct { uint16 hide; } HideDesc; +#include "common/pack-end.h" class BITMAP { bool BMPLoad(XFILE *f); @@ -70,6 +72,9 @@ public: BITMAP(uint16 w, uint16 h, uint8 fill); BITMAP(const BITMAP &bmp); ~BITMAP(void); + static void init(); + static void deinit(); + BITMAP *FlipH(void); BITMAP *Code(); BITMAP &operator = (const BITMAP &bmp); diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index d056a6737de..287586e0925 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -53,7 +53,9 @@ void CGEEngine::setup() { _console = new CGEConsole(this); // Initialise classes that have static members + BITMAP::init(); VFILE::init(); + VGA::init(); // Initialise engine objects Text = new TEXT(ProgName(), 128); @@ -99,7 +101,9 @@ CGEEngine::~CGEEngine() { debug("CGEEngine::~CGEEngine"); // Call classes with static members to clear them up + BITMAP::deinit(); VFILE::deinit(); + VGA::deinit(); // Remove all of our debug levels here DebugMan.clearAllDebugChannels(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index ec8f743fe48..d49f71cd99b 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -128,7 +128,6 @@ static int DemoText = DEMO_TEXT; //-------------------------------------------------------------------------- bool JBW = false; -DAC *SysPal = farnew(DAC, PAL_CNT); //------------------------------------------------------------------------- int PocPtr = 0; @@ -652,7 +651,7 @@ static void PostMiniStep(int stp) { void SYSTEM::SetPal(void) { int i; - DAC *p = SysPal + 256 - ArrayCount(StdPal); + DAC *p = VGA::SysPal + 256 - ArrayCount(StdPal); for (i = 0; i < ArrayCount(StdPal); i ++) { p[i].R = StdPal[i].R >> 2; p[i].G = StdPal[i].G >> 2; @@ -671,7 +670,7 @@ void SYSTEM::FunTouch(void) { static void ShowBak(int ref) { SPRITE *spr = Vga->SpareQ->Locate(ref); if (spr) { - BITMAP::Pal = SysPal; + BITMAP::Pal = VGA::SysPal; spr->Expand(); BITMAP::Pal = NULL; spr->Show(2); @@ -727,7 +726,7 @@ static void CaveUp(void) { if (Shadow) { Vga->ShowQ->Remove(Shadow); - Shadow->MakeXlat(Glass(SysPal, 204, 204, 204)); + Shadow->MakeXlat(Glass(VGA::SysPal, 204, 204, 204)); Vga->ShowQ->Insert(Shadow, Hero); Shadow->Z = Hero->Z; } @@ -735,7 +734,7 @@ static void CaveUp(void) { Vga->Show(); Vga->CopyPage(1, 0); Vga->Show(); - Vga->Sunrise(SysPal); + Vga->Sunrise(VGA::SysPal); Dark = false; if (! Startup) Mouse->On(); @@ -1027,7 +1026,7 @@ static void SpkClose(void) { static void SwitchColorMode(void) { SNPOST_(SNSEQ, 121, Vga->Mono = !Vga->Mono, NULL); KeyClick(); - Vga->SetColors(SysPal, 64); + Vga->SetColors(VGA::SysPal, 64); } @@ -1712,7 +1711,7 @@ void Movie(const char *ext) { bool ShowTitle(const char *name) { - BITMAP::Pal = SysPal; + BITMAP::Pal = VGA::SysPal; BMP_PTR LB[] = { new BITMAP(name), NULL }; BITMAP::Pal = NULL; bool usr_ok = false; @@ -1732,7 +1731,7 @@ bool ShowTitle(const char *name) { Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); SelectPocket(-1); - Vga->Sunrise(SysPal); + Vga->Sunrise(VGA::SysPal); if (STARTUP::Mode < 2 && !STARTUP::SoundOk) { Vga->CopyPage(1, 2); @@ -1793,7 +1792,7 @@ bool ShowTitle(const char *name) { if (CFILE::Exist(n)) { CFILE file = CFILE(n, REA, RCrypt); LoadGame(file, true); // only system vars - Vga->SetColors(SysPal, 64); + Vga->SetColors(VGA::SysPal, 64); Vga->Update(); if (FINIS) { ++ STARTUP::Mode; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 9caa8642275..a851957b21b 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -127,7 +127,12 @@ char *ForceExt(char *buf, const char *nam, const char *ext) { // fnsplit(nam, dr, di, na, ex); // fnmerge(buf, dr, di, na, ext); // return buf; - warning("STUB: ForceExt"); + strcpy(buf, nam); + char *dot = strrchr(buf, '.'); + if (dot) + *dot = '\0'; + strcat(buf, ext); + return buf; } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 2b36ca43252..a07cf9d09bc 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -65,7 +65,6 @@ extern SPRITE *PocLight; //------------------------------------------------------------------------- extern SPRITE *Pocket[]; extern int PocPtr; -extern DAC *SysPal; static void SNGame(SPRITE *spr, int num) { switch (num) { @@ -576,7 +575,7 @@ void SNSend(SPRITE *spr, int val) { spr->Flags.Slav = false; } else { if (spr->Ref % 1000 == 0) - BITMAP::Pal = SysPal; + BITMAP::Pal = VGA::SysPal; if (spr->Flags.Back) spr->BackShow(true); else @@ -849,7 +848,7 @@ void SNFlash(bool on) { if (on) { DAC *pal = farnew(DAC, PAL_CNT); if (pal) { - memcpy(pal, SysPal, PAL_SIZ); + memcpy(pal, VGA::SysPal, PAL_SIZ); for (int i = 0; i < PAL_CNT; i ++) { register int c; c = pal[i].R << 1; @@ -862,14 +861,14 @@ void SNFlash(bool on) { Vga->SetColors(pal, 64); } } else - Vga->SetColors(SysPal, 64); + Vga->SetColors(VGA::SysPal, 64); Dark = false; } static void SNLight(bool in) { if (in) - Vga->Sunrise(SysPal); + Vga->Sunrise(VGA::SysPal); else Vga->Sunset(); Dark = ! in; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 349f412ca07..f5fde14122e 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -25,6 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ +#include "common/rect.h" +#include "graphics/palette.h" #include "cge/general.h" #include "cge/vga13h.h" #include "cge/bitmap.h" @@ -737,7 +739,7 @@ void SPRITE::Show(void) { void SPRITE::Show(uint16 pg) { - uint8 *a = VGA::Page[1]; + Graphics::Surface *a = VGA::Page[1]; VGA::Page[1] = VGA::Page[pg & 3]; Shp()->Show(X, Y); VGA::Page[1] = a; @@ -886,17 +888,25 @@ SPRITE *QUEUE::Locate(int ref) { } -// TODO: Was direct mapping to VGA buffers.. need to create scummvm surfaces for that -uint8 *VGA::Page[4] = { 0, 0, 0, 0 }; - -/* -uint8 * VGA::Page[4] = { (uint8 *) MK_FP(SCR_SEG, 0x0000), - (uint8 *) MK_FP(SCR_SEG, 0x4000), - (uint8 *) MK_FP(SCR_SEG, 0x8000), - (uint8 *) MK_FP(SCR_SEG, 0xC000) }; -*/ - //extern const char Copr[]; +Graphics::Surface *VGA::Page[4]; +DAC *VGA::SysPal; + +void VGA::init() { + for (int idx = 0; idx < 4; ++idx) { + Page[idx] = new Graphics::Surface(); + Page[idx]->create(320, 200, Graphics::PixelFormat::createFormatCLUT8()); + } + + SysPal = new DAC[PAL_CNT]; +} + +void VGA::deinit() { + for (int idx = 0; idx < 4; ++idx) { + delete Page[idx]; + } + delete[] SysPal; +} VGA::VGA(int mode) : FrmCnt(0), OldMode(0), OldScreen(NULL), StatAdr(VGAST1_), @@ -977,21 +987,9 @@ void VGA::SetStatAdr(void) { #pragma argsused void VGA::WaitVR(bool on) { - /* - _DX = StatAdr; - _AH = (on) ? 0x00 : 0x08; - - asm mov cx,2 - // wait for vertical retrace on (off) - wait: - asm in al,dx - asm xor al,ah - asm test al,0x08 - asm jnz wait - asm xor ah,0x08 - asm loop wait - */ - warning("STUB: VGA::WaitVR"); + // Since some of the game parts rely on using vertical sync as a delay mechanism, + // we're introducing a short delay to simulate it + g_system->delayMillis(10); } @@ -1039,102 +1037,54 @@ void VGA::Setup(VgaRegBlk *vrb) { int VGA::SetMode(int mode) { - /* - Clear(); - // get current mode - asm mov ah,0x0F - Video(); // BIOS video service - asm xor ah,ah - asm push ax - - // wait for v-retrace - WaitVR(); - - // set mode - asm xor ah,ah - asm mov al,byte ptr mode - Video(); // BIOS video service - SetStatAdr(); - // return previous mode - asm pop ax - return _AX; - */ - warning("STUB: VGA::SetMode"); + // ScummVM provides it's own vieo services return 0; } void VGA::GetColors(DAC *tab) { - /* - asm cld - asm les di,tab // color table - asm mov dx,0x3C7 // PEL address read mode register - asm xor al,al // start from address 0 - asm out dx,al // put address - asm mov cx,256*3 // # of colors - asm mov dl,0xC9 // PEL data register - - // asm rep insb // very fast! - - gc: // much slower: - asm in al,dx // take 1 color - asm jmp sto // little delay - sto: - asm stosb // store 1 color - asm loop gc // next one? - */ - warning("STUB: VGA::GetColors"); + byte palData[PAL_SIZ]; + g_system->getPaletteManager()->grabPalette(palData, 0, PAL_CNT); + pal2DAC(palData, tab); } +void VGA::pal2DAC(const byte *palData, DAC *tab) { + const byte *colP = palData; + for (int idx = 0; idx < PAL_CNT; ++idx, colP += 3) { + tab[idx].R = *colP; + tab[idx].G = *(colP + 1); + tab[idx].B = *(colP + 2); + } +} + +void VGA::DAC2pal(const DAC *tab, byte *palData) { + for (int idx = 0; idx < PAL_CNT; ++idx, palData += 3) { + *palData = tab[idx].R; + *(palData + 1) = tab[idx].G; + *(palData + 2) = tab[idx].B; + } +} void VGA::SetColors(DAC *tab, int lum) { - /* - DAC * des = NewColors; - asm push ds + DAC *palP = tab; + for (int idx = 0; idx < PAL_CNT; ++idx, ++palP) { + palP->R = (palP->R * lum) >> 6; + palP->G = (palP->G * lum) >> 6; + palP->B = (palP->B * lum) >> 6; + } - asm les di,des - asm lds si,tab - asm mov cx,256*3 - asm xor bx,bx - asm mov dx,lum + if (Mono) { + palP = tab; + for (int idx = 0; idx < PAL_CNT; ++idx, ++palP) { + // Form a greyscalce colour from 30% R, 59% G, 11% B + uint8 intensity = (palP->R * 77) + (palP->G * 151) + (palP->B * 28); + palP->R = intensity; + palP->G = intensity; + palP->B = intensity; + } + } - copcol: - asm mov al,[si+bx] - asm mul dl - asm shr ax,6 - asm mov es:[di+bx],al - asm inc bx - asm cmp bx,cx - asm jb copcol - - asm pop ds - - if (Mono) - { - asm add cx,di - mono: - asm xor dx,dx - asm mov al,77 // 30% R - asm mul byte ptr es:[di].0 - asm add dx,ax - asm mov al,151 // 59% G - asm mul byte ptr es:[di].1 - asm add dx,ax - asm mov al,28 // 11% B - asm mul byte ptr es:[di].2 - asm add dx,ax - - asm mov es:[di].0,dh - asm mov es:[di].1,dh - asm mov es:[di].2,dh - - asm add di,3 - asm cmp di,cx - asm jb mono - } - */ SetPal = true; - warning("STUB: VGA::SetColors"); } @@ -1178,113 +1128,33 @@ void VGA::Show(void) { void VGA::UpdateColors(void) { - /* - DAC * tab = NewColors; - - asm push ds - asm cld - asm lds si,tab // color table - asm mov dx,0x3C8 // PEL address write mode register - asm xor al,al // start from address 0 - asm out dx,al // put address - asm mov cx,256*3 // # of colors - asm mov dl,0xC9 // PEL data register - - // asm rep outsb // very fast! - - // the slower version of above: - sc: - asm lodsb // take 1/3 color - asm out dx,al // put 1/3 color - asm jmp loop // little delay - loop: - asm loop sc // next one? - - - asm pop ds - */ - warning("STUB: VGA::UpdateColors"); + byte palData[PAL_SIZ]; + DAC2pal(NewColors, palData); + g_system->getPaletteManager()->setPalette(palData, 0, 256); } void VGA::Update(void) { - /* - uint8 * p = Page[1]; - Page[1] = Page[0]; - Page[0] = p; - - asm mov dx,VGACRT_ - asm mov al,0x0D - asm mov ah,byte ptr p - asm out dx,ax - asm dec al - asm mov ah,byte ptr p+1 - asm out dx,ax - */ - if (! SpeedTest) - WaitVR(true); + SWAP(VGA::Page[0], VGA::Page[1]); if (SetPal) { UpdateColors(); SetPal = false; } - warning("STUB: VGA::Update"); + + g_system->copyRectToScreen((const byte *)VGA::Page[0]->getBasePtr(0, 0), SCR_WID, 0, 0, SCR_WID, SCR_HIG); + g_system->updateScreen(); } void VGA::Clear(uint8 color) { - /* - uint8 * a = (uint8 *) MK_FP(SCR_SEG, 0); - - asm mov dx,VGASEQ_ - asm mov ax,0x0F02 // map mask register - enable all planes - asm out dx,ax - asm les di,a - asm cld - - asm mov cx,0xFFFF - asm mov al,color - asm rep stosb - asm stosb - */ - warning("STUB: VGA::Clear"); + for (int paneNum = 0; paneNum < 4; ++paneNum) + Page[paneNum]->fillRect(Common::Rect(0, 0, SCR_WID, SCR_HIG), color); } void VGA::CopyPage(uint16 d, uint16 s) { - /* - uint8 * S = Page[s & 3], * D = Page[d & 3]; - - asm mov dx,VGAGRA_ - asm mov al,0x05 // R/W mode - asm out dx,al - asm inc dx - asm in al,dx - asm and al,0xF4 - asm push ax - asm push dx - asm or al,0x01 - asm out dx,al - - asm mov dx,VGASEQ_ - asm mov ax,0x0F02 // map mask register - enable all planes - asm out dx,ax - - asm push ds - - asm les di,D - asm lds si,S - asm cld - asm mov cx,0x4000 - asm rep movsb - - asm pop ds - - asm pop dx - asm pop ax - asm out dx,al // end of copy mode - */ - warning("STUB: VGA::CopyPage"); + Page[d]->copyFrom(*Page[s]); } //-------------------------------------------------------------------------- @@ -1372,72 +1242,63 @@ void BITMAP::XShow(int x, int y) { void BITMAP::Show(int x, int y) { - /* - uint8 mask = 1 << (x & 3), - * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); - uint8 * v = V; + const byte *srcP = (const byte *)V; + byte *destP = (byte *)VGA::Page[1]->getBasePtr(x, y); - asm push ds // preserve DS + int yc = 0, xc = 0; + + for (;;) { + uint16 v = READ_LE_UINT16(srcP); + srcP += 2; + int cmd = v >> 14; + int count = v & 0x3FFF; - asm cld // normal direction - asm les di,scr // screen address - asm lds si,v // picture address - asm mov dx,VGASEQ_ // VGA reg - asm mov al,0x02 - asm mov ah,mask + if (cmd == 0) + // End of image + break; - plane: - asm out dx,ax - asm push ax - asm push di + // Handle a set of pixels + while (count-- > 0) { + // Transfer operation + switch (cmd) { + case 1: + // SKIP + break; + case 2: + // REPEAT + *destP = *srcP; + break; + case 3: + // COPY + *destP = *srcP++; + break; + } - block: - asm mov cx,[si] // with ADD faster then LODSW - asm add si,2 - asm test ch,0xC0 - asm jns skip // 1 (SKP) or 0 (EOI) - asm jpo repeat // 2 (REP) + // Move to next dest position + ++destP; + ++xc; + if (xc == W) { + xc = 0; + ++yc; + if (yc == H) + return; - copy: // 3 (CPY) - asm and ch,0x3F - asm shr cx,1 - asm rep movsw - asm jnc block - asm movsb - asm jmp block + destP = (byte *)VGA::Page[1]->getBasePtr(x, y + yc); + } + } - repeat: - asm and ch,0x3F - asm mov al,[si] - asm inc si - asm mov ah,al - asm shr cx,1 - asm rep stosw - asm jnc block - asm mov es:[di],al - asm inc di - asm jmp block + if (cmd == 2) + ++srcP; + } - skip: - asm jz endpl - asm and ch,0x3F - asm add di,cx - asm jmp block + // Temporary + g_system->copyRectToScreen((const byte *)VGA::Page[1]->getBasePtr(0, 0), SCR_WID, 0, 0, SCR_WID, SCR_HIG); + byte palData[PAL_SIZ]; + VGA::DAC2pal(VGA::SysPal, palData); + g_system->getPaletteManager()->setPalette(palData, 0, PAL_CNT); - endpl: - asm pop di - asm pop ax - asm shl ah,1 - asm test ah,0x10 - asm jz x_chk - asm mov ah,0x01 - asm inc di - x_chk: - asm cmp ah,mask - asm jne plane - asm pop ds - */ - warning("STUB: BITMAP::Show"); + g_system->updateScreen(); + g_system->delayMillis(5000); } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 63886d9a99e..edbeebf7274 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -28,6 +28,7 @@ #ifndef __VGA13H__ #define __VGA13H__ +#include "graphics/surface.h" #include "cge/general.h" #include #include "cge/bitmap.h" @@ -111,7 +112,7 @@ extern SEQ Seq2[]; #define PAL_CNT 256 -#define PAL_SIZ (PAL_CNT * sizeof(DAC)) +#define PAL_SIZ (PAL_CNT * 3) #define VGAATR_ 0x3C0 #define VGAMIw_ 0x3C0 #define VGASEQ_ 0x3C4 @@ -265,10 +266,13 @@ public: uint32 FrmCnt; QUEUE *ShowQ, *SpareQ; int Mono; - static uint8 *Page[4]; + static Graphics::Surface *Page[4]; + static DAC *VGA::SysPal; VGA(int mode); ~VGA(void); + static void init(); + static void deinit(); void Setup(VgaRegBlk *vrb); void GetColors(DAC *tab); @@ -279,6 +283,9 @@ public: void Sunset(void); void Show(void); void Update(void); + + static void pal2DAC(const byte *palData, DAC *tab); + static void DAC2pal(const DAC *tab, byte *palData); }; From 571c3fc666ce95ce880e7a428585ea99c7c66fd2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 27 Jun 2011 21:29:18 +1000 Subject: [PATCH 035/276] CGE: Getting closer to properly showing bitmap images --- engines/cge/vga13h.cpp | 90 +++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 1804d25aa96..32e0fd60907 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1064,9 +1064,9 @@ void VGA::pal2DAC(const byte *palData, DAC *tab) { void VGA::DAC2pal(const DAC *tab, byte *palData) { for (int idx = 0; idx < PAL_CNT; ++idx, palData += 3) { - *palData = tab[idx].R; - *(palData + 1) = tab[idx].G; - *(palData + 2) = tab[idx].B; + *palData = tab[idx].R << 2; + *(palData + 1) = tab[idx].G << 2; + *(palData + 2) = tab[idx].B << 2; } } @@ -1247,53 +1247,63 @@ void BITMAP::XShow(int x, int y) { void BITMAP::Show(int x, int y) { + // Create a temporary surface to hold the unpacked bitmap data + Graphics::Surface rawSurface; + rawSurface.create(W, H, Graphics::PixelFormat::createFormatCLUT8()); + const byte *srcP = (const byte *)V; - byte *destP = (byte *)VGA::Page[1]->getBasePtr(x, y); + byte *destP = (byte *)rawSurface.pixels; + byte *destEndP = destP + (W * H); + Common::set_to(destP, destEndP, 0); - int yc = 0, xc = 0; - - for (;;) { - uint16 v = READ_LE_UINT16(srcP); - srcP += 2; - int cmd = v >> 14; - int count = v & 0x3FFF; + // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a + // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data + // must be decompressed and inserted into the surface + for (int planeCtr = 0; planeCtr < 4; ++planeCtr) { + destP = (byte *)rawSurface.getBasePtr(planeCtr, 0); + + while (destP < destEndP) { + uint16 v = READ_LE_UINT16(srcP); + srcP += 2; + int cmd = v >> 14; + int count = v & 0x3FFF; - if (cmd == 0) - // End of image - break; - - // Handle a set of pixels - while (count-- > 0) { - // Transfer operation - switch (cmd) { - case 1: - // SKIP - break; - case 2: - // REPEAT - *destP = *srcP; - break; - case 3: - // COPY - *destP = *srcP++; + if (cmd == 0) { + // End of image break; } - // Move to next dest position - ++destP; - ++xc; - if (xc == W) { - xc = 0; - ++yc; - if (yc == H) - return; + // Handle a set of pixels + while (count-- > 0) { + // Transfer operation + switch (cmd) { + case 1: + // SKIP + break; + case 2: + // REPEAT + *destP = *srcP; + break; + case 3: + // COPY + *destP = *srcP++; + break; + } - destP = (byte *)VGA::Page[1]->getBasePtr(x, y + yc); + // Move to next dest position + destP += 4; } + + if (cmd == 2) + ++srcP; } + } - if (cmd == 2) - ++srcP; + // Copy the decompressed buffer to the specified x/y position on Page #1 + for (int yc = 0; yc < rawSurface.h; ++yc) { + srcP = (const byte *)rawSurface.getBasePtr(0, yc); + destP = (byte *)VGA::Page[1]->getBasePtr(x, y + yc); + Common::copy(srcP, srcP + rawSurface.w, destP); } // Temporary From 315bbd348d490d3edf6f5dcfb58ffcc9ecde83b3 Mon Sep 17 00:00:00 2001 From: eriktorbjorn Date: Mon, 27 Jun 2011 19:25:24 +0200 Subject: [PATCH 036/276] CGE: Fix some GCC compile errors and warnings. --- engines/cge/cge_main.cpp | 2 +- engines/cge/general.cpp | 19 +++++++++++-------- engines/cge/general.h | 3 ++- engines/cge/mixer.cpp | 4 ++-- engines/cge/snail.cpp | 2 +- engines/cge/vga13h.h | 2 +- engines/cge/vmenu.h | 2 +- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index cd8a8ff9df7..90b14d2c709 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -652,7 +652,7 @@ static void PostMiniStep(int stp) { } void SYSTEM::SetPal(void) { - int i; + uint i; DAC *p = VGA::SysPal + 256 - ArrayCount(StdPal); for (i = 0; i < ArrayCount(StdPal); i++) { p[i].R = StdPal[i].R >> 2; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index b07ddbc362d..1bf4bcd9828 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -215,6 +215,7 @@ char *dwtom(uint32 val, char *str, int radix, int len) { IOHAND::IOHAND(IOMODE mode, CRYPT *crpt) : XFILE(mode), Crypt(crpt), Seed(SEED) { + _file = new Common::File(); } IOHAND::IOHAND(const char *name, IOMODE mode, CRYPT *crpt) @@ -222,18 +223,20 @@ IOHAND::IOHAND(const char *name, IOMODE mode, CRYPT *crpt) // TODO: Check if WRI and/or UPD modes are needed, and map to a save file assert(mode == REA); - _file.open(name); + _file = new Common::File(); + _file->open(name); } IOHAND::~IOHAND(void) { - _file.close(); + _file->close(); + delete _file; } uint16 IOHAND::Read(void *buf, uint16 len) { - if (Mode == WRI || !_file.isOpen()) + if (Mode == WRI || !_file->isOpen()) return 0; - uint16 bytesRead = _file.read(buf, len); + uint16 bytesRead = _file->read(buf, len); if (Crypt) Seed = Crypt(buf, len, Seed); return bytesRead; } @@ -255,16 +258,16 @@ uint16 IOHAND::Write(void *buf, uint16 len) { } long IOHAND::Mark(void) { - return _file.pos(); + return _file->pos(); } long IOHAND::Seek(long pos) { - _file.seek(pos, SEEK_SET); - return _file.pos(); + _file->seek(pos, SEEK_SET); + return _file->pos(); } long IOHAND::Size(void) { - return _file.size(); + return _file->size(); } bool IOHAND::Exist(const char *name) { diff --git a/engines/cge/general.h b/engines/cge/general.h index 6fb8e24f9ce..4946e40c7b7 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -173,6 +173,7 @@ public: virtual long Mark(void) = 0; virtual long Size(void) = 0; virtual long Seek(long pos) = 0; + virtual ~XFILE() { } }; @@ -184,7 +185,7 @@ inline uint16 XRead(XFILE *xf, T *t) { class IOHAND : public XFILE { protected: - Common::File _file; + Common::File *_file; uint16 Seed; CRYPT *Crypt; public: diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 864fb6cdba8..ecdd2b75335 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -54,7 +54,7 @@ MIXER::MIXER(CGEEngine *vm, int x, int y) : SPRITE(vm, NULL), Fall(MIX_FALL), _v // slaves - int i; + uint i; for (i = 0; i < MIX_MAX; i++) { static char fn[] = "V00"; wtom(i, fn + 1, 10, 2); @@ -124,7 +124,7 @@ void MIXER::Tick(void) { if (Fall) --Fall; else { - for (int i = 0; i < ArrayCount(Led); i++) + for (uint i = 0; i < ArrayCount(Led); i++) SNPOST_(SNKILL, -1, 0, Led[i]); SNPOST_(SNKILL, -1, 0, this); } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 24ed08c1407..0137ab4cfa0 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -92,7 +92,7 @@ static void SNGame(SPRITE *spr, int num) { ++ Stage; if (hand && Stage > DRESSED) ++hand; - if (i >= 0 || dup[i] == spr && new_random(3) == 0) { + if (i >= 0 || (dup[i] == spr && new_random(3) == 0)) { SNPOST(SNSEQ, -1, 3, dup[0]); // yes SNPOST(SNSEQ, -1, 3, dup[1]); // yes SNPOST(SNSEQ, -1, 3, dup[2]); // yes diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index cf4252e5c28..c984e121e84 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -270,7 +270,7 @@ public: QUEUE *ShowQ, *SpareQ; int Mono; static Graphics::Surface *Page[4]; - static DAC *VGA::SysPal; + static DAC *SysPal; VGA(int mode); ~VGA(void); diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index 61645d2c55b..3c38576a406 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -37,7 +37,7 @@ namespace CGE { typedef struct { - char *Text; + const char *Text; void (CGEEngine::*Proc)(); } CHOICE; From 2fe6061d919a84e1f2849415902b3e91403bf69d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 28 Jun 2011 21:58:03 +1000 Subject: [PATCH 037/276] CGE: Bitmap now shows correctly --- engines/cge/vga13h.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 32e0fd60907..21aec31e5df 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1261,8 +1261,8 @@ void BITMAP::Show(int x, int y) { // must be decompressed and inserted into the surface for (int planeCtr = 0; planeCtr < 4; ++planeCtr) { destP = (byte *)rawSurface.getBasePtr(planeCtr, 0); - - while (destP < destEndP) { + + for (;;) { uint16 v = READ_LE_UINT16(srcP); srcP += 2; int cmd = v >> 14; @@ -1273,6 +1273,8 @@ void BITMAP::Show(int x, int y) { break; } + assert(destP < destEndP); + // Handle a set of pixels while (count-- > 0) { // Transfer operation From a89ce394bcaa9f967f2db7e9281bf25f381ceb69 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 28 Jun 2011 22:18:21 +1000 Subject: [PATCH 038/276] CGE: Fix initialisation of the TALK class --- engines/cge/cge.cpp | 7 +++++-- engines/cge/gettext.cpp | 4 ++-- engines/cge/talk.cpp | 25 +++++++++++++++++-------- engines/cge/talk.h | 6 +++++- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 2fd196f509c..f2bebef258b 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -32,6 +32,7 @@ #include "cge/cge.h" #include "cge/vga13h.h" #include "cge/cge_main.h" +#include "cge/talk.h" #include "cge/text.h" #include "cge/bitmaps.h" #include "cge/vol.h" @@ -54,9 +55,10 @@ void CGEEngine::setup() { _console = new CGEConsole(this); // Initialise classes that have static members - BITMAP::init(); - VFILE::init(); VGA::init(); + VFILE::init(); + BITMAP::init(); + TALK::init(); // Initialise engine objects Text = new TEXT(this, ProgName(), 128); @@ -102,6 +104,7 @@ CGEEngine::~CGEEngine() { debug("CGEEngine::~CGEEngine"); // Call classes with static members to clear them up + TALK::deinit(); BITMAP::deinit(); VFILE::deinit(); VGA::deinit(); diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 69e19b175c2..d444b75ab4c 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -39,7 +39,7 @@ GET_TEXT *GET_TEXT::Ptr = NULL; GET_TEXT::GET_TEXT(CGEEngine *vm, const char *info, char *text, int size, void (*click)(void)) : TALK(vm), Text(text), Size(min(size, GTMAX)), Len(min(Size, strlen(text))), Cntr(GTBLINK), Click(click), OldKeybClient(KEYBOARD::SetClient(this)), _vm(vm) { - int i = 2 * TEXT_HM + Font->Width(info); + int i = 2 * TEXT_HM + _Font->Width(info); Ptr = this; Mode = RECT; TS[0] = Box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); @@ -107,7 +107,7 @@ void GET_TEXT::Touch(uint16 mask, int x, int y) { if (p) x = ogon[p - bezo]; } - if (Len < Size && 2 * TEXT_HM + Font->Width(Buff) + Font->Wid[x] <= W) { + if (Len < Size && 2 * TEXT_HM + _Font->Width(Buff) + _Font->Wid[x] <= W) { Buff[Len + 2] = Buff[Len + 1]; Buff[Len + 1] = Buff[Len]; Buff[Len++] = x; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index b67d9082acc..ae94233464c 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -102,7 +102,6 @@ TALK::TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode) TS[0] = TS[1] = NULL; Flags.Syst = true; Update(tx); - Font = new FONT(ProgName()); } @@ -124,6 +123,16 @@ TALK::~TALK (void) { } */ +FONT *TALK::_Font; + +void TALK::init() { + _Font = new FONT(ProgName()); +} + +void TALK::deinit() { + delete _Font; +} + void TALK::Update(const char *tx) { uint16 vmarg = (Mode) ? TEXT_VM : 0; @@ -142,7 +151,7 @@ void TALK::Update(const char *tx) { mw = k; k = 2 * hmarg; } else - k += Font->Wid[*p]; + k += _Font->Wid[*p]; } if (k > mw) mw = k; @@ -155,8 +164,8 @@ void TALK::Update(const char *tx) { if (*tx == '|' || *tx == '\n') m = TS[0]->M + (ln += FONT_HIG + TEXT_LS) * mw + hmarg; else { - int cw = Font->Wid[*tx], i; - uint8 *f = Font->Map + Font->Pos[*tx]; + int cw = _Font->Wid[*tx], i; + uint8 *f = _Font->Map + _Font->Pos[*tx]; for (i = 0; i < cw; i++) { uint8 *p = m; uint16 n; @@ -253,8 +262,8 @@ void TALK::PutLine(int line, const char *text) { q = v + size; while (* text) { - uint16 cw = Font->Wid[*text], i; - uint8 *fp = Font->Map + Font->Pos[*text]; + uint16 cw = _Font->Wid[*text], i; + uint8 *fp = _Font->Map + _Font->Pos[*text]; for (i = 0; i < cw; i++) { register uint16 b = fp[i]; @@ -301,8 +310,8 @@ void INFO_LINE::Update(const char *tx) { uint8 *p = v + 2, * q = p + size; while (*tx) { - uint16 cw = Font->Wid[*tx]; - uint8 *fp = Font->Map + Font->Pos[*tx]; + uint16 cw = _Font->Wid[*tx]; + uint8 *fp = _Font->Map + _Font->Pos[*tx]; for (uint16 i = 0; i < cw; i++) { register uint16 b = fp[i]; diff --git a/engines/cge/talk.h b/engines/cge/talk.h index ba4952c3e6c..184b84e553c 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -74,10 +74,14 @@ protected: BITMAP *TS[2]; BITMAP *Box(uint16 w, uint16 h); public: - FONT *Font; TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode = PURE); TALK(CGEEngine *vm); //~TALK (void); + + static FONT *_Font; + static void init(); + static void deinit(); + virtual void Update(const char *tx); virtual void Update(void) {} void PutLine(int line, const char *text); From 04a123a4efc0ae4a76fa4ca20d8ffd692d7359ab Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 28 Jun 2011 22:36:43 +1000 Subject: [PATCH 039/276] CGE: Fix for displaying non full-screen bitmaps --- engines/cge/vga13h.cpp | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 21aec31e5df..b59f8e8de5f 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1247,20 +1247,14 @@ void BITMAP::XShow(int x, int y) { void BITMAP::Show(int x, int y) { - // Create a temporary surface to hold the unpacked bitmap data - Graphics::Surface rawSurface; - rawSurface.create(W, H, Graphics::PixelFormat::createFormatCLUT8()); - const byte *srcP = (const byte *)V; - byte *destP = (byte *)rawSurface.pixels; - byte *destEndP = destP + (W * H); - Common::set_to(destP, destEndP, 0); + byte *destEndP = (byte *)VGA::Page[1]->pixels + (SCR_WID * SCR_HIG); // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data // must be decompressed and inserted into the surface for (int planeCtr = 0; planeCtr < 4; ++planeCtr) { - destP = (byte *)rawSurface.getBasePtr(planeCtr, 0); + byte *destP = (byte *)VGA::Page[1]->getBasePtr(x + planeCtr, y); for (;;) { uint16 v = READ_LE_UINT16(srcP); @@ -1301,13 +1295,6 @@ void BITMAP::Show(int x, int y) { } } - // Copy the decompressed buffer to the specified x/y position on Page #1 - for (int yc = 0; yc < rawSurface.h; ++yc) { - srcP = (const byte *)rawSurface.getBasePtr(0, yc); - destP = (byte *)VGA::Page[1]->getBasePtr(x, y + yc); - Common::copy(srcP, srcP + rawSurface.w, destP); - } - // Temporary g_system->copyRectToScreen((const byte *)VGA::Page[1]->getBasePtr(0, 0), SCR_WID, 0, 0, SCR_WID, SCR_HIG); byte palData[PAL_SIZ]; From e25f9c71f525a0feba28648a93846d7c9435f6e2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 28 Jun 2011 22:58:51 +1000 Subject: [PATCH 040/276] CGE: Fix SVG0FILE define to point to INI_FILE class --- engines/cge/cge_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 90b14d2c709..c415258ad80 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -58,7 +58,7 @@ namespace CGE { #define SVGCHKSUM (1956 + Now + OldLev + Game + Music + DemoText) #define SVG0NAME ("{{INIT}}" SVG_EXT) -#define SVG0FILE CFILE +#define SVG0FILE INI_FILE extern uint16 _stklen = (STACK_SIZ * 2); From 290305ad4320a489d6dc98279433e0d3b3a7de40 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 29 Jun 2011 00:35:21 +0200 Subject: [PATCH 041/276] CGE: Cleanup : Start renaming. Add BMPLoad() function --- engines/cge/bitmap.cpp | 56 ++++++ engines/cge/bitmap.h | 8 +- engines/cge/cge.cpp | 32 ++-- engines/cge/cge_main.cpp | 366 ++++++++++++++++++------------------- engines/cge/cge_main.h | 32 ++-- engines/cge/game.cpp | 2 +- engines/cge/game.h | 2 +- engines/cge/general.cpp | 7 +- engines/cge/gettext.cpp | 2 +- engines/cge/gettext.h | 2 +- engines/cge/keybd.cpp | 6 +- engines/cge/keybd.h | 4 +- engines/cge/mixer.cpp | 6 +- engines/cge/mixer.h | 6 +- engines/cge/mouse.cpp | 7 +- engines/cge/mouse.h | 12 +- engines/cge/snail.cpp | 176 +++++++++--------- engines/cge/talk.cpp | 4 +- engines/cge/talk.h | 2 +- engines/cge/text.cpp | 14 +- engines/cge/text.h | 6 +- engines/cge/vga13h.cpp | 376 ++++++++++++++++++++------------------- engines/cge/vga13h.h | 132 +++++++------- engines/cge/vmenu.cpp | 2 +- 24 files changed, 671 insertions(+), 591 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 943f1cf1547..10fc9a4df6b 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -139,6 +139,7 @@ BITMAP::~BITMAP(void) { break; case FAR_MEM : free(V); + default: break; } } @@ -419,4 +420,59 @@ bool BITMAP::VBMLoad(XFILE *f) { B = (HideDesc *)(V + n - H * sizeof(HideDesc)); return (f->Error == 0); } + +bool BITMAP::BMPLoad (XFILE * f) { + struct { + char BM[2]; + union { int16 len; int32 len_; }; + union { int16 _06; int32 _06_; }; + union { int16 hdr; int32 hdr_; }; + union { int16 _0E; int32 _0E_; }; + union { int16 wid; int32 wid_; }; + union { int16 hig; int32 hig_; }; + union { int16 _1A; int32 _1A_; }; + union { int16 _1E; int32 _1E_; }; + union { int16 _22; int32 _22_; }; + union { int16 _26; int32 _26_; }; + union { int16 _2A; int32 _2A_; }; + union { int16 _2E; int32 _2E_; }; + union { int16 _32; int32 _32_; }; + } hea; + BGR4 bpal[256]; + + f->Read((byte *)&hea, sizeof(hea)); + if (f->Error == 0) { + if (hea.hdr == 0x436L) { + int16 i = (hea.hdr - sizeof(hea)) / sizeof(BGR4); + f->Read((byte *)&bpal, sizeof(bpal)); + if (f->Error == 0) { + if (Pal) { + for (i = 0; i < 256; i ++) { + Pal[i].R = bpal[i].R; + Pal[i].G = bpal[i].G; + Pal[i].B = bpal[i].B; + } + Pal = NULL; + } + H = hea.hig; + W = hea.wid; + if ((M = farnew(byte, H * W)) != NULL) { + int16 r = (4 - (hea.wid & 3)) % 4; + byte buf[3]; int i; + for (i = H-1; i >= 0; i --) { + f->Read(M + (W * i), W); + if (r && f->Error == 0) + f->Read(buf, r); + if (f->Error) + break; + } + if (i < 0) + return true; + } + } + } + } + return false; +} + } // End of namespace CGE diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 13e28f43698..e114760e2ae 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -41,7 +41,7 @@ namespace CGE { #include "common/pack-start.h" -typedef struct { +struct BGR4 { uint16 b : 2; uint16 B : 6; uint16 g : 2; @@ -49,13 +49,13 @@ typedef struct { uint16 r : 2; uint16 R : 6; uint16 Z : 8; -} BGR4; +}; -typedef struct { +struct HideDesc { uint16 skip; uint16 hide; -} HideDesc; +}; #include "common/pack-end.h" diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index f2bebef258b..07638ebdd84 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -63,19 +63,19 @@ void CGEEngine::setup() { // Initialise engine objects Text = new TEXT(this, ProgName(), 128); Vga = new VGA(M13H); - Heart = new HEART; + _heart = new Heart; Hero = new WALK(this, NULL); Sys = new SYSTEM(this); - PocLight = new SPRITE(this, LI); + _pocLight = new Sprite(this, LI); Mouse = new MOUSE(this); for (int i = 0; i < POCKET_NX; i++) - Pocket[i] = new SPRITE(this, NULL); - Sprite = new SPRITE(this, NULL); - MiniCave = new SPRITE(this, NULL); - Shadow = new SPRITE(this, NULL); - HorzLine = new SPRITE(this, HL); + _pocket[i] = new Sprite(this, NULL); + _sprite = new Sprite(this, NULL); + _miniCave = new Sprite(this, NULL); + _shadow = new Sprite(this, NULL); + _horzLine = new Sprite(this, HL); InfoLine = new INFO_LINE(this, INFO_W); - CavLight = new SPRITE(this, PR); + _cavLight = new Sprite(this, PR); DebugLine = new INFO_LINE(this, SCR_WID); MB[0] = new BITMAP("BRICK"); MB[1] = NULL; @@ -117,19 +117,19 @@ CGEEngine::~CGEEngine() { // Delete engine objects delete Text; delete Vga; - delete Heart; + delete _heart; delete Hero; delete Sys; - delete PocLight; + delete _pocLight; delete Mouse; for (int i = 0; i < POCKET_NX; i++) - delete Pocket[i]; - delete Sprite; - delete MiniCave; - delete Shadow; - delete HorzLine; + delete _pocket[i]; + delete _sprite; + delete _miniCave; + delete _shadow; + delete _horzLine; delete InfoLine; - delete CavLight; + delete _cavLight; delete DebugLine; delete MB[0]; delete HL[0]; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index c415258ad80..ece6ec5adb4 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -25,56 +25,55 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/general.h" -#include "cge/boot.h" -#include "cge/ident.h" -#include "cge/sound.h" -#include "cge/startup.h" -#include "cge/config.h" -#include "cge/vga13h.h" -#include "cge/snail.h" -#include "cge/text.h" -#include "cge/game.h" -#include "cge/mouse.h" -#include "cge/keybd.h" -#include "cge/cfile.h" -#include "cge/vol.h" -#include "cge/talk.h" -#include "cge/vmenu.h" -#include "cge/gettext.h" -#include "cge/mixer.h" -#include "cge/cge_main.h" -#include "cge/cge.h" -#include -#include -#include -#include - +#include "cge/general.h" +#include "cge/boot.h" +#include "cge/ident.h" +#include "cge/sound.h" +#include "cge/startup.h" +#include "cge/config.h" +#include "cge/vga13h.h" +#include "cge/snail.h" +#include "cge/text.h" +#include "cge/game.h" +#include "cge/mouse.h" +#include "cge/keybd.h" +#include "cge/cfile.h" +#include "cge/vol.h" +#include "cge/talk.h" +#include "cge/vmenu.h" +#include "cge/gettext.h" +#include "cge/mixer.h" +#include "cge/cge_main.h" +#include "cge/cge.h" +#include +#include +#include +#include #include "common/str.h" namespace CGE { -#define STACK_SIZ (K(2)) -#define SVGCHKSUM (1956 + Now + OldLev + Game + Music + DemoText) +#define STACK_SIZ (K(2)) +#define SVGCHKSUM (1956 + Now + OldLev + Game + Music + DemoText) -#define SVG0NAME ("{{INIT}}" SVG_EXT) -#define SVG0FILE INI_FILE +#define SVG0NAME ("{{INIT}}" SVG_EXT) +#define SVG0FILE INI_FILE extern uint16 _stklen = (STACK_SIZ * 2); VGA *Vga; -HEART *Heart; +Heart *_heart; WALK *Hero; SYSTEM *Sys; -SPRITE *PocLight; +Sprite *_pocLight; MOUSE *Mouse; -SPRITE *Pocket[POCKET_NX]; -SPRITE *Sprite; -SPRITE *MiniCave; -SPRITE *Shadow; -SPRITE *HorzLine; +Sprite *_pocket[POCKET_NX]; +Sprite *_sprite; +Sprite *_miniCave; +Sprite *_shadow; +Sprite *_horzLine; INFO_LINE *InfoLine; -SPRITE *CavLight; +Sprite *_cavLight; INFO_LINE *DebugLine; BMP_PTR MB[2]; @@ -146,11 +145,11 @@ HXY HeroXY[CAVE_MAX] = {{0, 0}}; BAR Barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; -extern int FindPocket(SPRITE *); +extern int FindPocket(Sprite *); extern DAC StdPal[58]; -void FeedSnail(SPRITE *spr, SNLIST snq); // defined in SNAIL +void FeedSnail(Sprite *spr, SNLIST snq); // defined in SNAIL uint8 CLUSTER::Map[MAP_ZCNT][MAP_XCNT]; @@ -223,11 +222,13 @@ CLUSTER XZ(COUPLE xy) { int pocref[POCKET_NX]; uint8 volume[2]; -struct SAVTAB { +struct SavTab { void *Ptr; int Len; uint8 Flg; -} SavTab[] = { +}; + +SavTab _savTab[] = { { &Now, sizeof(Now), 1 }, { &OldLev, sizeof(OldLev), 1 }, { &DemoText, sizeof(DemoText), 1 }, @@ -248,11 +249,11 @@ struct SAVTAB { void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { - SAVTAB *st; - SPRITE *spr; + SavTab *st; + Sprite *spr; int i; - for (st = SavTab; st->Ptr; st++) { + for (st = _savTab; st->Ptr; st++) { if (file.Error) error("Bad SVG"); file.Read((uint8 *)((tiny || st->Flg) ? st->Ptr : &i), st->Len); @@ -273,7 +274,7 @@ void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { if (! tiny) { // load sprites & pocket while (! file.Error) { - SPRITE S(this, NULL); + Sprite S(this, NULL); uint16 n = file.Read((uint8 *) &S, sizeof(S)); if (n != sizeof(S)) @@ -281,7 +282,7 @@ void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { S.Prev = S.Next = NULL; spr = (scumm_stricmp(S.File + 2, "MUCHA") == 0) ? new FLY(this, NULL) - : new SPRITE(this, NULL); + : new Sprite(this, NULL); if (spr == NULL) error("No core"); *spr = S; @@ -290,7 +291,7 @@ void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { for (i = 0; i < POCKET_NX; i++) { register int r = pocref[i]; - Pocket[i] = (r < 0) ? NULL : Vga->SpareQ->Locate(r); + _pocket[i] = (r < 0) ? NULL : Vga->SpareQ->Locate(r); } } } @@ -303,19 +304,19 @@ static void SaveSound(void) { static void SaveGame(XFILE &file) { - SAVTAB *st; - SPRITE *spr; + SavTab *st; + Sprite *spr; int i; for (i = 0; i < POCKET_NX; i++) { - register SPRITE *s = Pocket[i]; - pocref[i] = (s) ? s->Ref : -1; + register Sprite *s = _pocket[i]; + pocref[i] = (s) ? s->_ref : -1; } volume[0] = SNDDrvInfo.VOL2.D; volume[1] = SNDDrvInfo.VOL2.M; - for (st = SavTab; st->Ptr; st++) { + for (st = _savTab; st->Ptr; st++) { if (file.Error) error("Bad SVG"); file.Write((uint8 *) st->Ptr, st->Len); @@ -324,7 +325,7 @@ static void SaveGame(XFILE &file) { file.Write((uint8 *) & (i = SVGCHKSUM), sizeof(i)); for (spr = Vga->SpareQ->First(); spr; spr = spr->Next) - if (spr->Ref >= 1000) + if (spr->_ref >= 1000) if (!file.Error) file.Write((uint8 *)spr, sizeof(*spr)); } @@ -385,7 +386,7 @@ int FindLevel; WALK::WALK(CGEEngine *vm, BMP_PTR *shpl) - : SPRITE(vm, shpl), Dir(NO_DIR), TracePtr(-1), _vm(vm) { + : Sprite(vm, shpl), Dir(NO_DIR), TracePtr(-1), _vm(vm) { } @@ -396,7 +397,7 @@ void WALK::Tick(void) { Here = XZ(X + W / 2, Y + H); if (Dir != NO_DIR) { - SPRITE *spr; + Sprite *spr; Sys->FunTouch(); for (spr = Vga->ShowQ->First(); spr; spr = spr->Next) { if (Distance(spr) < 2) { @@ -434,7 +435,7 @@ void WALK::Tick(void) { } -int WALK::Distance(SPRITE *spr) { +int WALK::Distance(Sprite *spr) { int dx, dz; dx = spr->X - (X + W - WALKSIDE); if (dx < 0) @@ -502,7 +503,7 @@ void WALK::FindWay(CLUSTER c) { } -void WALK::FindWay(SPRITE *spr) { +void WALK::FindWay(Sprite *spr) { if (spr && spr != this) { int x = spr->X, z = spr->Z; if (spr->Flags.East) @@ -516,12 +517,12 @@ void WALK::FindWay(SPRITE *spr) { } -bool WALK::Lower(SPRITE *spr) { +bool WALK::Lower(Sprite *spr) { return (spr->Y > Y + (H * 3) / 5); } -void WALK::Reach(SPRITE *spr, int mode) { +void WALK::Reach(Sprite *spr, int mode) { if (spr) { Hero->FindWay(spr); if (mode < 0) { @@ -542,7 +543,7 @@ void WALK::Reach(SPRITE *spr, int mode) { } -class SQUARE : public SPRITE { +class SQUARE : public Sprite { public: SQUARE(CGEEngine *vm); void Touch(uint16 mask, int x, int y); @@ -552,14 +553,14 @@ private: SQUARE::SQUARE(CGEEngine *vm) - : SPRITE(vm, MB), _vm(vm) { + : Sprite(vm, MB), _vm(vm) { Flags.Kill = true; Flags.BDel = false; } void SQUARE::Touch(uint16 mask, int x, int y) { - SPRITE::Touch(mask, x, y); + Sprite::Touch(mask, x, y); if (mask & L_UP) { XZ(X + x, Y + y).Cell() = 0; SNPOST_(SNKILL, -1, 0, this); @@ -632,14 +633,14 @@ static void AltCtrlDel(void) { static void MiniStep(int stp) { if (stp < 0) - MiniCave->Flags.Hide = true; + _miniCave->Flags.Hide = true; else { &*Mini; *MiniShp[0] = *MiniShpList[stp]; if (Fx.Current) &*(Fx.Current->EAddr()); - MiniCave->Flags.Hide = false; + _miniCave->Flags.Hide = false; } } @@ -670,7 +671,7 @@ void SYSTEM::FunTouch(void) { static void ShowBak(int ref) { - SPRITE *spr = Vga->SpareQ->Locate(ref); + Sprite *spr = Vga->SpareQ->Locate(ref); if (spr) { BITMAP::Pal = VGA::SysPal; spr->Expand(); @@ -691,11 +692,11 @@ static void CaveUp(void) { ShowBak(BakRef); LoadMapping(); Text->Preload(BakRef, BakRef + 1000); - SPRITE *spr = Vga->SpareQ->First(); + Sprite *spr = Vga->SpareQ->First(); while (spr) { - SPRITE *n = spr->Next; - if (spr->Cave == Now || spr->Cave == 0) - if (spr->Ref != BakRef) { + Sprite *n = spr->Next; + if (spr->_cave == Now || spr->_cave == 0) + if (spr->_ref != BakRef) { if (spr->Flags.Back) spr->BackShow(); else @@ -726,11 +727,11 @@ static void CaveUp(void) { if (Hero) Vga->ShowQ->Insert(Vga->ShowQ->Remove(Hero)); - if (Shadow) { - Vga->ShowQ->Remove(Shadow); - Shadow->MakeXlat(Glass(VGA::SysPal, 204, 204, 204)); - Vga->ShowQ->Insert(Shadow, Hero); - Shadow->Z = Hero->Z; + if (_shadow) { + Vga->ShowQ->Remove(_shadow); + _shadow->MakeXlat(Glass(VGA::SysPal, 204, 204, 204)); + Vga->ShowQ->Insert(_shadow, Hero); + _shadow->Z = Hero->Z; } FeedSnail(Vga->ShowQ->Locate(BakRef + 999), TAKE); Vga->Show(); @@ -741,19 +742,19 @@ static void CaveUp(void) { if (! Startup) Mouse->On(); - Heart->Enable = true; + _heart->_enable = true; } void CGEEngine::CaveDown() { - SPRITE *spr; - if (! HorzLine->Flags.Hide) + Sprite *spr; + if (!_horzLine->Flags.Hide) SwitchMapping(); for (spr = Vga->ShowQ->First(); spr;) { - SPRITE *n = spr->Next; - if (spr->Ref >= 1000 /*&& spr->Cave*/) { - if (spr->Ref % 1000 == 999) + Sprite *n = spr->Next; + if (spr->_ref >= 1000 /*&& spr->_cave*/) { + if (spr->_ref % 1000 == 999) FeedSnail(spr, TAKE); Vga->SpareQ->Append(Vga->ShowQ->Remove(spr)); } @@ -782,7 +783,7 @@ void CGEEngine::QGame() { void CGEEngine::SwitchCave(int cav) { if (cav != Now) { - Heart->Enable = false; + _heart->_enable = false; if (cav < 0) { SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint //TODO Change the SNPOST message send to a special way to send function pointer @@ -799,7 +800,7 @@ void CGEEngine::SwitchCave(int cav) { Vga->SpareQ->Show = STARTUP::Summa * (cav <= CAVE_MAX); /////-------------------------------------------------------- } - CavLight->Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, + _cavLight->Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); KillText(); if (! Startup) @@ -812,7 +813,7 @@ void CGEEngine::SwitchCave(int cav) { } } -SYSTEM::SYSTEM(CGEEngine *vm) : SPRITE(vm, NULL), _vm(vm) { +SYSTEM::SYSTEM(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { FunDel = HEROFUN0; SetPal(); Tick(); @@ -841,7 +842,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { break; case 'F': if (KEYBOARD::Key[ALT]) { - SPRITE *m = Vga->ShowQ->Locate(17001); + Sprite *m = Vga->ShowQ->Locate(17001); if (m) { m->Step(1); m->Time = 216; // 3s @@ -905,8 +906,8 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { case '7': case '8': case '9': - if (Sprite) - Sprite->Step(x - '0'); + if (_sprite) + _sprite->Step(x - '0'); break; case F10 : if (Snail->Idle() && ! Hero->Flags.Hide) @@ -957,7 +958,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { if (cav && Snail->Idle() && Hero->TracePtr < 0) _vm->SwitchCave(cav); - if (!HorzLine->Flags.Hide) { + if (!_horzLine->Flags.Hide) { if (y >= MAP_TOP && y < MAP_TOP + MAP_HIG) { int8 x1, z1; XZ(x, y).Split(x1, z1); @@ -1079,7 +1080,7 @@ void CGEEngine::TakeName() { void CGEEngine::SwitchMapping() { - if (HorzLine->Flags.Hide) { + if (_horzLine->Flags.Hide) { int i; for (i = 0; i < MAP_ZCNT; i++) { int j; @@ -1089,29 +1090,29 @@ void CGEEngine::SwitchMapping() { } } } else { - SPRITE *s; + Sprite *s; for (s = Vga->ShowQ->First(); s; s = s->Next) if (s->W == MAP_XGRID && s->H == MAP_ZGRID) SNPOST_(SNKILL, -1, 0, s); } - HorzLine->Flags.Hide = ! HorzLine->Flags.Hide; + _horzLine->Flags.Hide = !_horzLine->Flags.Hide; } static void KillSprite(void) { - Sprite->Flags.Kill = true; - Sprite->Flags.BDel = true; - SNPOST_(SNKILL, -1, 0, Sprite); - Sprite = NULL; + _sprite->Flags.Kill = true; + _sprite->Flags.BDel = true; + SNPOST_(SNKILL, -1, 0, _sprite); + _sprite = NULL; } static void PushSprite(void) { - SPRITE *spr = Sprite->Prev; + Sprite *spr = _sprite->Prev; if (spr) { - Vga->ShowQ->Insert(Vga->ShowQ->Remove(Sprite), spr); - while (Sprite->Z > Sprite->Next->Z) - --Sprite->Z; + Vga->ShowQ->Insert(Vga->ShowQ->Remove(_sprite), spr); + while (_sprite->Z > _sprite->Next->Z) + --_sprite->Z; } else SNPOST_(SNSOUND, -1, 2, NULL); } @@ -1119,24 +1120,24 @@ static void PushSprite(void) { static void PullSprite(void) { bool ok = false; - SPRITE *spr = Sprite->Next; + Sprite *spr = _sprite->Next; if (spr) { spr = spr->Next; if (spr) ok = (!spr->Flags.Slav); } if (ok) { - Vga->ShowQ->Insert(Vga->ShowQ->Remove(Sprite), spr); - if (Sprite->Prev) - while (Sprite->Z < Sprite->Prev->Z) - ++Sprite->Z; + Vga->ShowQ->Insert(Vga->ShowQ->Remove(_sprite), spr); + if (_sprite->Prev) + while (_sprite->Z < _sprite->Prev->Z) + ++_sprite->Z; } else SNPOST_(SNSOUND, -1, 2, NULL); } static void NextStep(void) { - SNPOST_(SNSTEP, 0, 0, Sprite); + SNPOST_(SNSTEP, 0, 0, _sprite); } @@ -1199,18 +1200,18 @@ static void SayDebug(void) { // sprite queue size uint16 n = 0; - SPRITE *spr; + Sprite *spr; for (spr = Vga->ShowQ->First(); spr; spr = spr->Next) { ++ n; - if (spr == Sprite) { + if (spr == _sprite) { *XSPR = ' '; dwtom(n, SP_N, 10, 2); - dwtom(Sprite->X, SP_X, 10, 3); - dwtom(Sprite->Y, SP_Y, 10, 3); - dwtom(Sprite->Z, SP_Z, 10, 3); - dwtom(Sprite->W, SP_W, 10, 3); - dwtom(Sprite->H, SP_H, 10, 3); - dwtom(*(uint16 *)(&Sprite->Flags), SP_F, 16, 2); + dwtom(_sprite->X, SP_X, 10, 3); + dwtom(_sprite->Y, SP_Y, 10, 3); + dwtom(_sprite->Z, SP_Z, 10, 3); + dwtom(_sprite->W, SP_W, 10, 3); + dwtom(_sprite->H, SP_H, 10, 3); + dwtom(*(uint16 *)(&_sprite->Flags), SP_F, 16, 2); } } dwtom(n, SP_S, 10, 2); @@ -1249,14 +1250,14 @@ void CGEEngine::OptionTouch(int opt, uint16 mask) { #pragma argsused -void SPRITE::Touch(uint16 mask, int x, int y) { +void Sprite::Touch(uint16 mask, int x, int y) { Sys->FunTouch(); if ((mask & ATTN) == 0) { InfoLine->Update(Name()); if (mask & (R_DN | L_DN)) - Sprite = this; - if (Ref / 10 == 12) { - _vm->OptionTouch(Ref % 10, mask); + _sprite = this; + if (_ref / 10 == 12) { + _vm->OptionTouch(_ref % 10, mask); return; } if (Flags.Syst) @@ -1266,7 +1267,7 @@ void SPRITE::Touch(uint16 mask, int x, int y) { mask |= R_UP; } if ((mask & R_UP) && Snail->Idle()) { - SPRITE *ps = (PocLight->SeqPtr) ? Pocket[PocPtr] : NULL; + Sprite *ps = (_pocLight->SeqPtr) ? _pocket[PocPtr] : NULL; if (ps) { if (Flags.Kept || Hero->Distance(this) < MAX_DISTANCE) { if (Works(ps)) { @@ -1309,7 +1310,7 @@ void SPRITE::Touch(uint16 mask, int x, int y) { if (Flags.Kept) { int n; for (n = 0; n < POCKET_NX; n++) { - if (Pocket[n] == this) { + if (_pocket[n] == this) { SelectPocket(n); break; } @@ -1388,9 +1389,9 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int // make sprite of choosen type switch (type) { case 1 : { // AUTO - Sprite = new SPRITE(this, NULL); - if (Sprite) { - Sprite->Goto(col, row); + _sprite = new Sprite(this, NULL); + if (_sprite) { + _sprite->Goto(col, row); //Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$ } break; @@ -1403,7 +1404,7 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int error("2nd HERO [%s]", fname); Hero = w; } - Sprite = w; + _sprite = w; break; } /* @@ -1418,7 +1419,7 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int n->Cx = 3; n->Goto(col, row); } - Sprite = n; + _sprite = n; break; */ case 4 : { // LISSAJOUS @@ -1436,37 +1437,37 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int *(long *) &l->Dx = 0; // movex * cnt l->Goto(col, row); } - Sprite = l; + _sprite = l; */ break; } case 5 : { // FLY FLY *f = new FLY(this, NULL); - Sprite = f; + _sprite = f; //////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$ break; } default: { // DEAD - Sprite = new SPRITE(this, NULL); - if (Sprite) - Sprite->Goto(col, row); + _sprite = new Sprite(this, NULL); + if (_sprite) + _sprite->Goto(col, row); break; } } - if (Sprite) { - Sprite->Ref = ref; - Sprite->Cave = cav; - Sprite->Z = pos; - Sprite->Flags.East = east; - Sprite->Flags.Port = port; - Sprite->Flags.Tran = tran; - Sprite->Flags.Kill = true; - Sprite->Flags.BDel = true; - //fnsplit(fname, NULL, NULL, Sprite->File, NULL); + if (_sprite) { + _sprite->_ref = ref; + _sprite->_cave = cav; + _sprite->Z = pos; + _sprite->Flags.East = east; + _sprite->Flags.Port = port; + _sprite->Flags.Tran = tran; + _sprite->Flags.Kill = true; + _sprite->Flags.BDel = true; + //fnsplit(fname, NULL, NULL, _sprite->File, NULL); warning("LoadSprite: use of fnsplit"); - Sprite->ShpCnt = shpcnt; - Vga->SpareQ->Append(Sprite); + _sprite->ShpCnt = shpcnt; + Vga->SpareQ->Append(_sprite); } } @@ -1521,10 +1522,10 @@ void CGEEngine::LoadScript(const char *fname) { ok = true; // no break: OK - Sprite = NULL; + _sprite = NULL; LoadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); - if (Sprite && BkG) - Sprite->Flags.Back = true; + if (_sprite && BkG) + _sprite->Flags.Back = true; } if (! ok) error("%s [%s]", NumStr("Bad INI line ######", lcnt), fname); @@ -1579,11 +1580,11 @@ void CGEEngine::RunGame() { Text->Preload(100, 1000); LoadHeroXY(); - CavLight->Flags.Tran = true; - Vga->ShowQ->Append(CavLight); - CavLight->Flags.Hide = true; + _cavLight->Flags.Tran = true; + Vga->ShowQ->Append(_cavLight); + _cavLight->Flags.Hide = true; - static SEQ PocSeq[] = { { 0, 0, 0, 0, 20 }, + static Seq pocSeq[] = { { 0, 0, 0, 0, 20 }, { 1, 2, 0, 0, 4 }, { 2, 3, 0, 0, 4 }, { 3, 4, 0, 0, 16 }, @@ -1591,11 +1592,11 @@ void CGEEngine::RunGame() { { 1, 6, 0, 0, 4 }, { 0, 1, 0, 0, 16 }, }; - PocLight->SetSeq(PocSeq); - PocLight->Flags.Tran = true; - PocLight->Time = 1; - PocLight->Z = 120; - Vga->ShowQ->Append(PocLight); + _pocLight->SetSeq(pocSeq); + _pocLight->Flags.Tran = true; + _pocLight->Time = 1; + _pocLight->Z = 120; + Vga->ShowQ->Append(_pocLight); SelectPocket(-1); Vga->ShowQ->Append(Mouse); @@ -1604,11 +1605,11 @@ void CGEEngine::RunGame() { LoadUser(); // ~~~~~~~~~~~ - if ((Sprite = Vga->SpareQ->Locate(121)) != NULL) - SNPOST_(SNSEQ, -1, Vga->Mono, Sprite); - if ((Sprite = Vga->SpareQ->Locate(122)) != NULL) - Sprite->Step(Music); - SNPOST_(SNSEQ, -1, Music, Sprite); + if ((_sprite = Vga->SpareQ->Locate(121)) != NULL) + SNPOST_(SNSEQ, -1, Vga->Mono, _sprite); + if ((_sprite = Vga->SpareQ->Locate(122)) != NULL) + _sprite->Step(Music); + SNPOST_(SNSEQ, -1, Music, _sprite); if (! Music) KillMIDI(); @@ -1616,12 +1617,12 @@ void CGEEngine::RunGame() { uint8 *ptr = (uint8 *) &*Mini; if (ptr != NULL) { LoadSprite("MINI", -1, 0, MINI_X, MINI_Y); - ExpandSprite(MiniCave = Sprite); // NULL is ok - if (MiniCave) { - MiniCave->Flags.Hide = true; - MiniCave->MoveShapes(ptr); - MiniShp[0] = new BITMAP(*MiniCave->Shp()); - MiniShpList = MiniCave->SetShapeList(MiniShp); + ExpandSprite(_miniCave = _sprite); // NULL is ok + if (_miniCave) { + _miniCave->Flags.Hide = true; + _miniCave->MoveShapes(ptr); + MiniShp[0] = new BITMAP(*_miniCave->Shp()); + MiniShpList = _miniCave->SetShapeList(MiniShp); PostMiniStep(-1); } } @@ -1632,11 +1633,11 @@ void CGEEngine::RunGame() { Hero->Goto(HeroXY[Now - 1].X, HeroXY[Now - 1].Y); if (INI_FILE::Exist("00SHADOW.SPR")) { LoadSprite("00SHADOW", -1, 0, Hero->X + 14, Hero->Y + 51); - if ((Shadow = Sprite) != NULL) { - Shadow->Ref = 2; - Shadow->Flags.Tran = true; + if ((_shadow = _sprite) != NULL) { + _shadow->_ref = 2; + _shadow->Flags.Tran = true; Hero->Flags.Shad = true; - Vga->ShowQ->Insert(Vga->SpareQ->Remove(Shadow), Hero); + Vga->ShowQ->Insert(Vga->SpareQ->Remove(_shadow), Hero); } } } @@ -1649,9 +1650,9 @@ void CGEEngine::RunGame() { DebugLine->Z = 126; Vga->ShowQ->Insert(DebugLine); - HorzLine->Y = MAP_TOP - (MAP_TOP > 0); - HorzLine->Z = 126; - Vga->ShowQ->Insert(HorzLine); + _horzLine->Y = MAP_TOP - (MAP_TOP > 0); + _horzLine->Z = 126; + Vga->ShowQ->Insert(_horzLine); Mouse->Busy = Vga->SpareQ->Locate(BUSY_REF); if (Mouse->Busy) @@ -1659,8 +1660,8 @@ void CGEEngine::RunGame() { Startup = 0; - SNPOST(SNLEVEL, -1, OldLev, &CavLight); - CavLight->Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, + SNPOST(SNLEVEL, -1, OldLev, &_cavLight); + _cavLight->Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); CaveUp(); @@ -1674,14 +1675,14 @@ void CGEEngine::RunGame() { } KEYBOARD::SetClient(NULL); - Heart->Enable = false; + _heart->_enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); Mouse->Off(); Vga->ShowQ->Clear(); Vga->SpareQ->Clear(); Hero = NULL; - Shadow = NULL; + _shadow = NULL; } @@ -1692,13 +1693,13 @@ void CGEEngine::Movie(const char *ext) { ExpandSprite(Vga->SpareQ->Locate(999)); FeedSnail(Vga->ShowQ->Locate(999), TAKE); Vga->ShowQ->Append(Mouse); - Heart->Enable = true; + _heart->_enable = true; KEYBOARD::SetClient(Sys); while (!Snail->Idle()) MainLoop(); KEYBOARD::SetClient(NULL); - Heart->Enable = false; + _heart->_enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); Vga->ShowQ->Clear(); @@ -1713,7 +1714,7 @@ bool CGEEngine::ShowTitle(const char *name) { BITMAP::Pal = NULL; bool usr_ok = false; - SPRITE D(this, LB); + Sprite D(this, LB); D.Flags.Kill = true; D.Flags.BDel = true; D.Center(); @@ -1734,12 +1735,12 @@ bool CGEEngine::ShowTitle(const char *name) { Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); Vga->ShowQ->Append(Mouse); - Heart->Enable = true; + _heart->_enable = true; Mouse->On(); for (SelectSound(); !Snail->Idle() || VMENU::Addr;) MainLoop(); Mouse->Off(); - Heart->Enable = false; + _heart->_enable = false; Vga->ShowQ->Clear(); Vga->CopyPage(0, 2); STARTUP::SoundOk = 2; @@ -1771,10 +1772,10 @@ bool CGEEngine::ShowTitle(const char *name) { Vga->CopyPage(0, 1); Vga->ShowQ->Append(Mouse); //Mouse.On(); - Heart->Enable = true; + _heart->_enable = true; for (TakeName(); GET_TEXT::Ptr;) MainLoop(); - Heart->Enable = false; + _heart->_enable = false; if (KEYBOARD::Last() == Enter && *UsrFnam) usr_ok = true; if (usr_ok) @@ -1831,11 +1832,12 @@ void CGEEngine::cge_main(void) { if (!Mouse->Exist) error("%s", Text->getText(NO_MOUSE_TEXT)); + if (!SVG0FILE::Exist(SVG0NAME)) STARTUP::Mode = 2; DebugLine->Flags.Hide = true; - HorzLine->Flags.Hide = true; + _horzLine->Flags.Hide = true; //srand((uint16) Timer()); Sys = new SYSTEM(this); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 146c3cb6c9b..8b2f87aad9c 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -113,7 +113,7 @@ namespace CGE { #define FINIS (Flag[3]) -class SYSTEM : public SPRITE { +class SYSTEM : public Sprite { int lum; public: int FunDel; @@ -139,7 +139,7 @@ public: }; -class WALK : public SPRITE { +class WALK : public Sprite { public: CLUSTER Here; int TracePtr; @@ -148,12 +148,12 @@ public: WALK(CGEEngine *vm, BMP_PTR *shpl); void Tick(void); void FindWay(CLUSTER c); - void FindWay(SPRITE *spr); - int Distance(SPRITE *spr); + void FindWay(Sprite *spr); + int Distance(Sprite *spr); void Turn(DIR d); void Park(void); - bool Lower(SPRITE *spr); - void Reach(SPRITE *spr, int mode = -1); + bool Lower(Sprite *spr); + void Reach(Sprite *spr, int mode = -1); private: CGEEngine *_vm; @@ -163,23 +163,23 @@ private: CLUSTER XZ(int x, int y); CLUSTER XZ(COUPLE xy); -void ExpandSprite(SPRITE *spr); -void ContractSprite(SPRITE *spr); +void ExpandSprite(Sprite *spr); +void ContractSprite(Sprite *spr); extern WALK *Hero; extern VGA *Vga; -extern HEART *Heart; +extern Heart *_heart; extern SYSTEM *Sys; extern int OffUseCount; -extern SPRITE *PocLight; +extern Sprite *_pocLight; extern MOUSE *Mouse; -extern SPRITE *Pocket[]; -extern SPRITE *Sprite; -extern SPRITE *MiniCave; -extern SPRITE *Shadow; -extern SPRITE *HorzLine; +extern Sprite *_pocket[]; +extern Sprite *_sprite; +extern Sprite *_miniCave; +extern Sprite *_shadow; +extern Sprite *_horzLine; extern INFO_LINE *InfoLine; -extern SPRITE *CavLight; +extern Sprite *_cavLight; extern INFO_LINE *DebugLine; extern BMP_PTR MB[2]; extern BMP_PTR MB[2]; diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 21e8ceddeb8..a5b82f1e8dd 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -68,7 +68,7 @@ int FLY::L = 20, FLY::FLY(CGEEngine *vm, BITMAP **shpl) - : SPRITE(vm, shpl), Tx(0), Ty(0), _vm(vm) { + : Sprite(vm, shpl), Tx(0), Ty(0), _vm(vm) { Step(new_random(2)); Goto(L + new_random(R - L - W), T + new_random(B - T - H)); } diff --git a/engines/cge/game.h b/engines/cge/game.h index 7892b1c93ff..fb4dad6fae2 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -44,7 +44,7 @@ int Sinus(long x); uint8 *Glass(DAC *pal, uint8 r, uint8 g, uint8 b); uint8 *Mark(DAC *pal); -class FLY : public SPRITE { +class FLY : public Sprite { static int L, T, R, B; public: int Tx, Ty; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 1bf4bcd9828..428498923e9 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -136,8 +136,6 @@ char *ForceExt(char *buf, const char *nam, const char *ext) { return buf; } - -#define BUF ((uint8 *) buf) static unsigned Seed = 1; unsigned FastRand(void) { @@ -237,7 +235,10 @@ uint16 IOHAND::Read(void *buf, uint16 len) { return 0; uint16 bytesRead = _file->read(buf, len); - if (Crypt) Seed = Crypt(buf, len, Seed); + if (!bytesRead) + error("Read %s - %d bytes", _file->getName(), len); + if (Crypt) + Seed = Crypt(buf, len, Seed); return bytesRead; } diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index d444b75ab4c..f891b9c0928 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -116,7 +116,7 @@ void GET_TEXT::Touch(uint16 mask, int x, int y) { break; } } else - SPRITE::Touch(mask, x, y); + Sprite::Touch(mask, x, y); } } // End of namespace CGE diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h index c868232677e..33210758af1 100644 --- a/engines/cge/gettext.h +++ b/engines/cge/gettext.h @@ -41,7 +41,7 @@ class GET_TEXT : public TALK { char Buff[GTMAX + 2], * Text; uint16 Size, Len; uint16 Cntr; - SPRITE *OldKeybClient; + Sprite *OldKeybClient; void (*Click)(); public: static GET_TEXT *Ptr; diff --git a/engines/cge/keybd.cpp b/engines/cge/keybd.cpp index c912555949b..4aee394e07b 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/keybd.cpp @@ -30,8 +30,8 @@ namespace CGE { -SPRITE *KEYBOARD::Client = NULL; -uint8 KEYBOARD::Key[0x60] = { 0 }; +Sprite *KEYBOARD::Client = NULL; +uint8 KEYBOARD::Key[0x60] = { 0 }; uint16 KEYBOARD::Current = 0; uint16 KEYBOARD::Code[0x60] = { 0, Esc, '1', '2', '3', @@ -78,7 +78,7 @@ KEYBOARD::~KEYBOARD(void) { } -SPRITE *KEYBOARD::SetClient(SPRITE *spr) { +Sprite *KEYBOARD::SetClient(Sprite *spr) { Swap(Client, spr); return spr; } diff --git a/engines/cge/keybd.h b/engines/cge/keybd.h index f2fa595be2a..2cdbd558d8a 100644 --- a/engines/cge/keybd.h +++ b/engines/cge/keybd.h @@ -46,14 +46,14 @@ public: static void NewKeyboard(...); static uint16 Code[0x60]; static uint16 Current; - static SPRITE *Client; + static Sprite *Client; static uint8 Key[0x60]; static uint16 Last(void) { uint16 cur = Current; Current = 0; return cur; } - static SPRITE *SetClient(SPRITE *spr); + static Sprite *SetClient(Sprite *spr); KEYBOARD(void); ~KEYBOARD(void); }; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index ecdd2b75335..c1f688babd0 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -40,7 +40,7 @@ extern MOUSE *Mouse; bool MIXER::Appear = false; -MIXER::MIXER(CGEEngine *vm, int x, int y) : SPRITE(vm, NULL), Fall(MIX_FALL), _vm(vm) { +MIXER::MIXER(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), Fall(MIX_FALL), _vm(vm) { Appear = true; mb[0] = new BITMAP("VOLUME"); mb[1] = NULL; @@ -65,7 +65,7 @@ MIXER::MIXER(CGEEngine *vm, int x, int y) : SPRITE(vm, NULL), Fall(MIX_FALL), _v lb[i] = NULL; for (i = 0; i < ArrayCount(Led); i++) { - register SPRITE *spr = new SPRITE(_vm, lb); + register Sprite *spr = new Sprite(_vm, lb); spr->SetSeq(ls); spr->Goto(x + 2 + 12 * i, y + 8); spr->Flags.Tran = true; @@ -98,7 +98,7 @@ MIXER::~MIXER(void) { #pragma argsused void MIXER::Touch(uint16 mask, int x, int y) { - SPRITE::Touch(mask, x, y); + Sprite::Touch(mask, x, y); if (mask & L_UP) { uint8 *vol = (&SNDDrvInfo.VOL2.D) + (x < W / 2); if (y < MIX_BHIG) { diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index d589aceaea2..d42d25ca24c 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -39,11 +39,11 @@ namespace CGE { #define MIX_BHIG 6 // mixer button high #define MIX_NAME 105 // sprite name -class MIXER : public SPRITE { +class MIXER : public Sprite { BMP_PTR mb[2]; BMP_PTR lb[MIX_MAX + 1]; - SEQ ls[MIX_MAX]; - SPRITE *Led[2]; + Seq ls[MIX_MAX]; + Sprite *Led[2]; int Fall; void Update(void); public: diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index 10953291f21..cb94e926c5a 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -39,8 +39,8 @@ MOUSE_FUN *MOUSE::OldMouseFun = NULL; uint16 MOUSE::OldMouseMask = 0; -MOUSE::MOUSE(CGEEngine *vm, BITMAP **shpl) : SPRITE(vm, shpl), Busy(NULL), Hold(NULL), hx(0), _vm(vm) { - static SEQ ms[] = { +MOUSE::MOUSE(CGEEngine *vm, BITMAP **shpl) : Sprite(vm, shpl), Busy(NULL), Hold(NULL), hx(0), _vm(vm) { + static Seq ms[] = { { 0, 0, 0, 0, 1 }, { 1, 1, 0, 0, 1 } }; @@ -58,6 +58,7 @@ MOUSE::MOUSE(CGEEngine *vm, BITMAP **shpl) : SPRITE(vm, shpl), Busy(NULL), Hold( Z = 127; Step(1); */ + Exist = true; warning("STUB: MOUSE::MOUSE"); } @@ -131,7 +132,7 @@ void MOUSE::Off(void) { } -void MOUSE::ClrEvt(SPRITE *spr) { +void MOUSE::ClrEvt(Sprite *spr) { if (spr) { uint16 e; for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) diff --git a/engines/cge/mouse.h b/engines/cge/mouse.h index 61503fadd19..28152b7f29c 100644 --- a/engines/cge/mouse.h +++ b/engines/cge/mouse.h @@ -48,7 +48,7 @@ extern TALK *Talk; struct EVENT { uint16 Msk; uint16 X, Y; - SPRITE *Ptr; + Sprite *Ptr; }; extern EVENT Evt[EVT_MAX]; @@ -56,24 +56,24 @@ extern uint16 EvtHead, EvtTail; typedef void (MOUSE_FUN)(void); -class MOUSE : public SPRITE { +class MOUSE : public Sprite { static MOUSE_FUN *OldMouseFun; static MOUSE_FUN NewMouseFun; static uint16 OldMouseMask; - SPRITE *Hold; + Sprite *Hold; int hx, hy; //void SetFun (void); //void ResetFun (void); public: bool Exist; int Buttons; - SPRITE *Busy; - //SPRITE * Touched; + Sprite *Busy; + //Sprite *Touched; MOUSE(CGEEngine *vm, BITMAP **shpl = MC); ~MOUSE(); void On(); void Off(); - static void ClrEvt(SPRITE *spr = NULL); + static void ClrEvt(Sprite *spr = NULL); void Tick(); private: CGEEngine *_vm; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 0137ab4cfa0..1cb53d20240 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -56,27 +56,27 @@ bool Game = false; int Now = 1; int Lev = -1; -extern SPRITE *PocLight; +extern Sprite *_pocLight; //------------------------------------------------------------------------- // SPRITE * Pocket[POCKET_NX]={ NULL, NULL, NULL, NULL, // NULL, NULL, NULL, NULL, }; // int PocPtr = 0; //------------------------------------------------------------------------- -extern SPRITE *Pocket[]; +extern Sprite *_pocket[]; extern int PocPtr; -static void SNGame(SPRITE *spr, int num) { +static void SNGame(Sprite *spr, int num) { switch (num) { case 1 : { #define STAGES 8 #define DRESSED 3 - static SPRITE *dup[3] = { NULL, NULL, NULL }; + static Sprite *dup[3] = { NULL, NULL, NULL }; int buref = 0; int Stage = 0; for (dup[0] = Vga->ShowQ->First(); dup[0]; dup[0] = dup[0]->Next) { - buref = dup[0]->Ref; + buref = dup[0]->_ref; if (buref / 1000 == 16 && buref % 100 == 6) { Stage = (buref / 100) % 10; break; @@ -163,7 +163,7 @@ static void SNGame(SPRITE *spr, int num) { break; //-------------------------------------------------------------------- case 2 : { - static SPRITE *k = NULL, * k1, * k2, * k3; + static Sprite *k = NULL, * k1, * k2, * k3; static int count = 0; if (k == NULL) { @@ -181,7 +181,7 @@ static void SNGame(SPRITE *spr, int num) { k2->Step(new_random(6)); k3->Step(new_random(6)); ///-------------------- - if (spr->Ref == 1 && KEYBOARD::Key[ALT]) { + if (spr->_ref == 1 && KEYBOARD::Key[ALT]) { k1->Step(5); k2->Step(5); k3->Step(5); @@ -190,7 +190,7 @@ static void SNGame(SPRITE *spr, int num) { SNPOST(SNSETZ, 20700, 0, NULL); bool hit = (k1->SeqPtr + k2->SeqPtr + k3->SeqPtr == 15); if (hit) { - if (spr->Ref == 1) { + if (spr->_ref == 1) { SNPOST(SNSAY, 1, 20003, NULL); // hura! SNPOST(SNSEQ, 20011, 2, NULL); // kamera won SNPOST(SNSEND, 20701, -1, NULL); // k1 won @@ -223,7 +223,7 @@ static void SNGame(SPRITE *spr, int num) { } ++ count; } - switch (spr->Ref) { + switch (spr->_ref) { case 1 : SNPOST(SNSAY, 20001, 20011, NULL); // zapro SNPOST(SNSEQ, 20001, 1, NULL); // rzu @@ -275,38 +275,38 @@ static void SNGame(SPRITE *spr, int num) { } -void ExpandSprite(SPRITE *spr) { +void ExpandSprite(Sprite *spr) { if (spr) Vga->ShowQ->Insert(Vga->SpareQ->Remove(spr)); } -void ContractSprite(SPRITE *spr) { +void ContractSprite(Sprite *spr) { if (spr) Vga->SpareQ->Append(Vga->ShowQ->Remove(spr)); } -int FindPocket(SPRITE *spr) { +int FindPocket(Sprite *spr) { for (int i = 0; i < POCKET_NX; i++) - if (Pocket[i] == spr) + if (_pocket[i] == spr) return i; return -1; } void SelectPocket(int n) { - if (n < 0 || (PocLight->SeqPtr && PocPtr == n)) { - PocLight->Step(0); + if (n < 0 || (_pocLight->SeqPtr && PocPtr == n)) { + _pocLight->Step(0); n = FindPocket(NULL); if (n >= 0) PocPtr = n; } else { - if (Pocket[n] != NULL) { + if (_pocket[n] != NULL) { PocPtr = n; - PocLight->Step(1); + _pocLight->Step(1); } } - PocLight->Goto(POCKET_X + PocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY); + _pocLight->Goto(POCKET_X + PocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY); } @@ -320,7 +320,7 @@ void PocFul(void) { } -void Hide1(SPRITE *spr) { +void Hide1(Sprite *spr) { SNPOST_(SNGHOST, -1, 0, spr->Ghost()); } @@ -334,7 +334,7 @@ void SNGhost(BITMAP *bmp) { } -void FeedSnail(SPRITE *spr, SNLIST snq) { +void FeedSnail(Sprite *spr, SNLIST snq) { if (spr) if (spr->Active()) { uint8 ptr = (snq == TAKE) ? spr->TakePtr : spr->NearPtr; @@ -360,7 +360,7 @@ void FeedSnail(SPRITE *spr, SNLIST snq) { KillText(); } if (c->Com == SNNEXT) { - SPRITE *s = (c->Ref < 0) ? spr : Locate(c->Ref); + Sprite *s = (c->Ref < 0) ? spr : Locate(c->Ref); if (s) { uint8 *idx = (snq == TAKE) ? &s->TakePtr : &s->NearPtr; if (*idx != NO_PTR) { @@ -387,7 +387,7 @@ void FeedSnail(SPRITE *spr, SNLIST snq) { break; } if (c->Com == SNIF) { - SPRITE *s = (c->Ref < 0) ? spr : Locate(c->Ref); + Sprite *s = (c->Ref < 0) ? spr : Locate(c->Ref); if (s) { // sprite extsts if (! s->SeqTest(-1)) c = comtab + c->Val; // not parked @@ -475,52 +475,52 @@ void SNAIL::InsCom(SNCOM com, int ref, int val, void *ptr) { } -static void SNNNext(SPRITE *sprel, int p) { +static void SNNNext(Sprite *sprel, int p) { if (sprel) if (sprel->NearPtr != NO_PTR) sprel->NearPtr = p; } -static void SNTNext(SPRITE *sprel, int p) { +static void SNTNext(Sprite *sprel, int p) { if (sprel) if (sprel->TakePtr != NO_PTR) sprel->TakePtr = p; } -static void SNRNNext(SPRITE *sprel, int p) { +static void SNRNNext(Sprite *sprel, int p) { if (sprel) if (sprel->NearPtr != NO_PTR) sprel->NearPtr += p; } -static void SNRTNext(SPRITE *sprel, int p) { +static void SNRTNext(Sprite *sprel, int p) { if (sprel) if (sprel->TakePtr != NO_PTR) sprel->TakePtr += p; } -static void SNZTrim(SPRITE *spr) { +static void SNZTrim(Sprite *spr) { if (spr) if (spr->Active()) { - bool en = Heart->Enable; - SPRITE *s; - Heart->Enable = false; + bool en = _heart->_enable; + Sprite *s; + _heart->_enable = false; s = (spr->Flags.Shad) ? spr->Prev : NULL; Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr)); if (s) { s->Z = spr->Z; Vga->ShowQ->Insert(Vga->ShowQ->Remove(s), spr); } - Heart->Enable = en; + _heart->_enable = en; } } -static void SNHide(SPRITE *spr, int val) { +static void SNHide(Sprite *spr, int val) { if (spr) { spr->Flags.Hide = (val >= 0) ? (val != 0) : (! spr->Flags.Hide); if (spr->Flags.Shad) @@ -529,19 +529,19 @@ static void SNHide(SPRITE *spr, int val) { } -static void SNRmNear(SPRITE *spr) { +static void SNRmNear(Sprite *spr) { if (spr) spr->NearPtr = NO_PTR; } -static void SNRmTake(SPRITE *spr) { +static void SNRmTake(Sprite *spr) { if (spr) spr->TakePtr = NO_PTR; } -void SNSeq(SPRITE *spr, int val) { +void SNSeq(Sprite *spr, int val) { if (spr) { if (spr == Hero && val == 0) Hero->Park(); @@ -551,30 +551,30 @@ void SNSeq(SPRITE *spr, int val) { } -void SNRSeq(SPRITE *spr, int val) { +void SNRSeq(Sprite *spr, int val) { if (spr) SNSeq(spr, spr->SeqPtr + val); } -void SNSend(SPRITE *spr, int val) { +void SNSend(Sprite *spr, int val) { if (spr) { - int was = spr->Cave; + int was = spr->_cave; bool was1 = (was == 0 || was == Now); bool val1 = (val == 0 || val == Now); - spr->Cave = val; + spr->_cave = val; if (val1 != was1) { if (was1) { if (spr->Flags.Kept) { int n = FindPocket(spr); if (n >= 0) - Pocket[n] = NULL; + _pocket[n] = NULL; } Hide1(spr); ContractSprite(spr); spr->Flags.Slav = false; } else { - if (spr->Ref % 1000 == 0) + if (spr->_ref % 1000 == 0) BITMAP::Pal = VGA::SysPal; if (spr->Flags.Back) spr->BackShow(true); @@ -587,22 +587,22 @@ void SNSend(SPRITE *spr, int val) { } -void SNSwap(SPRITE *spr, int xref) { - SPRITE *xspr = Locate(xref); +void SNSwap(Sprite *spr, int xref) { + Sprite *xspr = Locate(xref); if (spr && xspr) { - int was = spr->Cave; - int xwas = xspr->Cave; + int was = spr->_cave; + int xwas = xspr->_cave; bool was1 = (was == 0 || was == Now); bool xwas1 = (xwas == 0 || xwas == Now); - Swap(spr->Cave, xspr->Cave); + Swap(spr->_cave, xspr->_cave); Swap(spr->X, xspr->X); Swap(spr->Y, xspr->Y); Swap(spr->Z, xspr->Z); if (spr->Flags.Kept) { int n = FindPocket(spr); if (n >= 0) - Pocket[n] = xspr; + _pocket[n] = xspr; xspr->Flags.Kept = true; xspr->Flags.Port = false; } @@ -622,12 +622,12 @@ void SNSwap(SPRITE *spr, int xref) { } -void SNCover(SPRITE *spr, int xref) { - SPRITE *xspr = Locate(xref); +void SNCover(Sprite *spr, int xref) { + Sprite *xspr = Locate(xref); if (spr && xspr) { spr->Flags.Hide = true; xspr->Z = spr->Z; - xspr->Cave = spr->Cave; + xspr->_cave = spr->_cave; xspr->Goto(spr->X, spr->Y); ExpandSprite(xspr); if ((xspr->Flags.Shad = spr->Flags.Shad) == 1) { @@ -639,10 +639,10 @@ void SNCover(SPRITE *spr, int xref) { } -void SNUncover(SPRITE *spr, SPRITE *xspr) { +void SNUncover(Sprite *spr, Sprite *xspr) { if (spr && xspr) { spr->Flags.Hide = false; - spr->Cave = xspr->Cave; + spr->_cave = xspr->_cave; spr->Goto(xspr->X, xspr->Y); if ((spr->Flags.Shad = xspr->Flags.Shad) == 1) { Vga->ShowQ->Insert(Vga->ShowQ->Remove(xspr->Prev), spr); @@ -666,25 +666,25 @@ void SNSetY0(int cav, int y0) { } -void SNSetXY(SPRITE *spr, uint16 xy) { +void SNSetXY(Sprite *spr, uint16 xy) { if (spr) spr->Goto(xy % SCR_WID, xy / SCR_WID); } -void SNRelX(SPRITE *spr, int x) { +void SNRelX(Sprite *spr, int x) { if (spr && Hero) spr->Goto(Hero->X + x, spr->Y); } -void SNRelY(SPRITE *spr, int y) { +void SNRelY(Sprite *spr, int y) { if (spr && Hero) spr->Goto(spr->X, Hero->Y + y); } -void SNRelZ(SPRITE *spr, int z) { +void SNRelZ(Sprite *spr, int z) { if (spr && Hero) { spr->Z = Hero->Z + z; SNZTrim(spr); @@ -692,19 +692,19 @@ void SNRelZ(SPRITE *spr, int z) { } -void SNSetX(SPRITE *spr, int x) { +void SNSetX(Sprite *spr, int x) { if (spr) spr->Goto(x, spr->Y); } -void SNSetY(SPRITE *spr, int y) { +void SNSetY(Sprite *spr, int y) { if (spr) spr->Goto(spr->X, y); } -void SNSetZ(SPRITE *spr, int z) { +void SNSetZ(Sprite *spr, int z) { if (spr) { spr->Z = z; //SNPOST_(SNZTRIM, -1, 0, spr); @@ -713,11 +713,11 @@ void SNSetZ(SPRITE *spr, int z) { } -void SNSlave(SPRITE *spr, int ref) { - SPRITE *slv = Locate(ref); +void SNSlave(Sprite *spr, int ref) { + Sprite *slv = Locate(ref); if (spr && slv) { if (spr->Active()) { - SNSend(slv, spr->Cave); + SNSend(slv, spr->_cave); slv->Flags.Slav = true; slv->Z = spr->Z; Vga->ShowQ->Insert(Vga->ShowQ->Remove(slv), spr->Next); @@ -726,33 +726,33 @@ void SNSlave(SPRITE *spr, int ref) { } -void SNTrans(SPRITE *spr, int trans) { +void SNTrans(Sprite *spr, int trans) { if (spr) spr->Flags.Tran = (trans < 0) ? !spr->Flags.Tran : (trans != 0); } -void SNPort(SPRITE *spr, int port) { +void SNPort(Sprite *spr, int port) { if (spr) spr->Flags.Port = (port < 0) ? !spr->Flags.Port : (port != 0); } -void SNKill(SPRITE *spr) { +void SNKill(Sprite *spr) { if (spr) { if (spr->Flags.Kept) { int n = FindPocket(spr); if (n >= 0) - Pocket[n] = NULL; + _pocket[n] = NULL; } - SPRITE *nx = spr->Next; + Sprite *nx = spr->Next; Hide1(spr); Vga->ShowQ->Remove(spr); MOUSE::ClrEvt(spr); if (spr->Flags.Kill) delete spr; else { - spr->Cave = -1; + spr->_cave = -1; Vga->SpareQ->Append(spr); } if (nx) @@ -762,7 +762,7 @@ void SNKill(SPRITE *spr) { } -static void SNSound(SPRITE *spr, int wav, int cnt) { +static void SNSound(Sprite *spr, int wav, int cnt) { if (SNDDrvInfo.DDEV) { if (wav == -1) Sound.Stop(); @@ -772,12 +772,12 @@ static void SNSound(SPRITE *spr, int wav, int cnt) { } -void SNKeep(SPRITE *spr, int stp) { +void SNKeep(Sprite *spr, int stp) { SelectPocket(-1); - if (spr && ! spr->Flags.Kept && Pocket[PocPtr] == NULL) { + if (spr && ! spr->Flags.Kept && _pocket[PocPtr] == NULL) { SNSound(spr, 3, 1); - Pocket[PocPtr] = spr; - spr->Cave = 0; + _pocket[PocPtr] = spr; + spr->_cave = 0; spr->Flags.Kept = true; spr->Goto(POCKET_X + POCKET_DX * PocPtr + POCKET_DX / 2 - spr->W / 2, POCKET_Y + POCKET_DY / 2 - spr->H / 2); @@ -788,12 +788,12 @@ void SNKeep(SPRITE *spr, int stp) { } -void SNGive(SPRITE *spr, int stp) { +void SNGive(Sprite *spr, int stp) { if (spr) { int p = FindPocket(spr); if (p >= 0) { - Pocket[p] = NULL; - spr->Cave = Now; + _pocket[p] = NULL; + spr->_cave = Now; spr->Flags.Kept = false; if (stp >= 0) spr->Step(stp); @@ -803,7 +803,7 @@ void SNGive(SPRITE *spr, int stp) { } -static void SNBackPt(SPRITE *spr, int stp) { +static void SNBackPt(Sprite *spr, int stp) { if (spr) { if (stp >= 0) spr->Step(stp); @@ -812,19 +812,19 @@ static void SNBackPt(SPRITE *spr, int stp) { } -static void SNLevel(SPRITE *spr, int lev) { +static void SNLevel(Sprite *spr, int lev) { #ifdef DEMO static int maxcav[] = { CAVE_MAX }; #else static int maxcav[] = { 1, 8, 16, 23, 24 }; #endif while (Lev < lev) { - SPRITE *spr; + Sprite *spr; ++Lev; spr = Vga->SpareQ->Locate(100 + Lev); if (spr) { spr->BackShow(true); - spr->Cave = 0; + spr->_cave = 0; } } MaxCave = maxcav[Lev]; @@ -838,9 +838,9 @@ static void SNFlag(int fn, bool v) { } -static void SNSetRef(SPRITE *spr, int nr) { +static void SNSetRef(Sprite *spr, int nr) { if (spr) - spr->Ref = nr; + spr->_ref = nr; } @@ -880,7 +880,7 @@ static void SNBarrier(int cav, int bar, bool horz) { } -static void SNWalk(SPRITE *spr, int x, int y) { +static void SNWalk(Sprite *spr, int x, int y) { if (Hero) { if (spr && y < 0) Hero->FindWay(spr); @@ -890,7 +890,7 @@ static void SNWalk(SPRITE *spr, int x, int y) { } -static void SNReach(SPRITE *spr, int mode) { +static void SNReach(Sprite *spr, int mode) { if (Hero) Hero->Reach(spr, mode); } @@ -925,12 +925,12 @@ void SNAIL::RunCom(void) { break; } - SPRITE *sprel = ((snc->Ref >= 0) ? Locate(snc->Ref) : ((SPRITE *) snc->Ptr)); + Sprite *sprel = ((snc->Ref >= 0) ? Locate(snc->Ref) : ((Sprite *) snc->Ptr)); switch (snc->Com) { case SNLABEL : break; case SNPAUSE : - Heart->SetXTimer(&Pause, snc->Val); + _heart->setXTimer(&Pause, snc->Val); if (Talk) TextDelay = true; break; @@ -938,7 +938,7 @@ void SNAIL::RunCom(void) { if (sprel) { if (sprel->SeqTest(snc->Val) && (snc->Val >= 0 || sprel != Hero || Hero->TracePtr < 0)) { - Heart->SetXTimer(&Pause, sprel->Time); + _heart->setXTimer(&Pause, sprel->Time); } else goto xit; } @@ -993,7 +993,7 @@ void SNAIL::RunCom(void) { SNCover(sprel, snc->Val); break; case SNUNCOVER : - SNUncover(sprel, (snc->Val >= 0) ? Locate(snc->Val) : ((SPRITE *) snc->Ptr)); + SNUncover(sprel, (snc->Val >= 0) ? Locate(snc->Val) : ((Sprite *) snc->Ptr)); break; case SNKEEP : SNKeep(sprel, snc->Val); diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index ae94233464c..544359897f3 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -98,7 +98,7 @@ void FONT::Save(void) { TALK::TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode) - : SPRITE(vm, NULL), Mode(mode), _vm(vm) { + : Sprite(vm, NULL), Mode(mode), _vm(vm) { TS[0] = TS[1] = NULL; Flags.Syst = true; Update(tx); @@ -106,7 +106,7 @@ TALK::TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode) TALK::TALK(CGEEngine *vm) - : SPRITE(vm, NULL), Mode(PURE), _vm(vm) { + : Sprite(vm, NULL), Mode(PURE), _vm(vm) { TS[0] = TS[1] = NULL; Flags.Syst = true; } diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 184b84e553c..2a38af91d10 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -68,7 +68,7 @@ public: enum TBOX_STYLE { PURE, RECT, ROUND }; -class TALK : public SPRITE { +class TALK : public Sprite { protected: TBOX_STYLE Mode; BITMAP *TS[2]; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 6d7341af0a3..74ff6fac2dd 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -180,14 +180,14 @@ char *TEXT::getText(int ref) { } -void TEXT::Say(const char *txt, SPRITE *spr) { +void TEXT::Say(const char *txt, Sprite *spr) { KillText(); Talk = new TALK(_vm, txt, ROUND); if (Talk) { bool east = spr->Flags.East; int x = (east) ? (spr->X + spr->W - 2) : (spr->X + 2); int y = spr->Y + 2; - SPRITE *spike = new SPRITE(_vm, SP); + Sprite *spike = new Sprite(_vm, SP); uint16 sw = spike->W; if (east) { @@ -198,7 +198,7 @@ void TEXT::Say(const char *txt, SPRITE *spr) { east = true; } x = (east) ? (spr->X + spr->W - 2) : (spr->X + 2 - sw); - if (spr->Ref == 1) + if (spr->_ref == 1) x += ((east) ? -10 : 10); // Hero Talk->Flags.Kill = true; @@ -206,7 +206,7 @@ void TEXT::Say(const char *txt, SPRITE *spr) { Talk->SetName(Text->getText(SAY_NAME)); Talk->Goto(x - (Talk->W - sw) / 2 - 3 + 6 * east, y - spike->H - Talk->H + 1); Talk->Z = 125; - Talk->Ref = SAY_REF; + Talk->_ref = SAY_REF; spike->Goto(x, Talk->Y + Talk->H - 1); spike->Z = 126; @@ -214,7 +214,7 @@ void TEXT::Say(const char *txt, SPRITE *spr) { spike->Flags.Kill = true; spike->SetName(Text->getText(SAY_NAME)); spike->Step(east); - spike->Ref = SAY_REF; + spike->_ref = SAY_REF; Vga->ShowQ->Insert(Talk, Vga->ShowQ->Last()); Vga->ShowQ->Insert(spike, Vga->ShowQ->Last()); @@ -231,13 +231,13 @@ void CGEEngine::Inf(const char *txt) { Talk->Center(); Talk->Goto(Talk->X, Talk->Y - 20); Talk->Z = 126; - Talk->Ref = INF_REF; + Talk->_ref = INF_REF; Vga->ShowQ->Insert(Talk, Vga->ShowQ->Last()); } } -void SayTime(SPRITE *spr) { +void SayTime(Sprite *spr) { /* static char t[] = "00:00"; struct time ti; diff --git a/engines/cge/text.h b/engines/cge/text.h index 161b2e813ae..874a640ad03 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -66,7 +66,7 @@ public: void Clear(int from = 1, int upto = 0x7FFF); void Preload(int from = 1, int upto = 0x7FFF); char *getText(int ref); - void Say(const char *txt, SPRITE *spr); + void Say(const char *txt, Sprite *spr); private: CGEEngine *_vm; }; @@ -76,8 +76,8 @@ extern TALK *Talk; extern TEXT *Text; -void Say(const char *txt, SPRITE *spr); -void SayTime(SPRITE *spr); +void Say(const char *txt, Sprite *spr); +void SayTime(Sprite *spr); void Inf(const char *txt); void KillText(void); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index b59f8e8de5f..1d55af7e31e 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -51,7 +51,6 @@ static char Report[] = "NearHeap=..... FarHeap=......\n"; #define FREP 24 static VgaRegBlk VideoMode[] = { - { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 { 0x05, VGAGRA, 0x03, 0x00 }, // R/W mode = 0 @@ -69,9 +68,9 @@ static VgaRegBlk VideoMode[] = { }; -bool SpeedTest = false; -SEQ Seq1[] = { { 0, 0, 0, 0, 0 } }; -SEQ Seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; +bool SpeedTest = false; +Seq _seq1[] = { { 0, 0, 0, 0, 0 } }; +Seq _seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; extern "C" void SNDMIDIPlay(void); @@ -83,8 +82,7 @@ char *NumStr(char *str, int num) { } -static void Video(void) -{ +static void Video() { /* static uint16 SP_S; @@ -206,7 +204,7 @@ DAC MkDAC(uint8 r, uint8 g, uint8 b) { } -RGB MkRGB(uint8 r, uint8 g, uint8 b) { +Rgb MkRGB(uint8 r, uint8 g, uint8 b) { static TRGB x; x.dac.R = r; x.dac.G = g; @@ -215,54 +213,60 @@ RGB MkRGB(uint8 r, uint8 g, uint8 b) { } -SPRITE *Locate(int ref) { - SPRITE *spr = Vga->ShowQ->Locate(ref); +Sprite *Locate(int ref) { + Sprite *spr = Vga->ShowQ->Locate(ref); return (spr) ? spr : Vga->SpareQ->Locate(ref); } -HEART::HEART(void) +Heart::Heart(void) : ENGINE(TMR_DIV) { - Enable = false; - XTimer = NULL; + _enable = false; + _xTimer = NULL; } /* -extern "C" void TimerProc (void) -{ - static SPRITE * spr; - static uint8 run = 0; +extern "C" void TimerProc() { + static SPRITE * spr; + static uint8 run = 0; - // decrement external timer uint16 - if (Heart->XTimer) - if (*Heart->XTimer) - *Heart->XTimer--; - else - Heart->XTimer = NULL; + // decrement external timer uint16 + if (_heart->_xTimer) { + if (*_heart->_xTimer) + *_heart->_xTimer--; + else + _heart->_xTimer = NULL; + } - if (! run && Heart->Enable) // check overrun flag - { - static uint16 oldSP, oldSS; + if (!run && _heart->_enable) { // check overrun flag + static uint16 oldSP, oldSS; + run++; // disable 2nd call until current lasts + asm mov ax,ds + asm mov oldSS,ss + asm mov oldSP,sp + asm mov ss,ax + asm mov sp,0xFF80 - run++; // disable 2nd call until current lasts - asm mov ax,ds - asm mov oldSS,ss - asm mov oldSP,sp - asm mov ss,ax - asm mov sp,0xFF80 - - // system pseudo-sprite - if (Sys) if (Sys->Time) if (-- Sys->Time == 0) Sys->Tick(); - - for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) - { - if (spr->Time) if (!spr->Flags.Hide) if (-- spr->Time == 0) spr->Tick(); - } - asm mov ss,oldSS - asm mov sp,oldSP - run--; - } + // system pseudo-sprite + if (Sys) { + if (Sys->Time) { + if (--Sys->Time == 0) + Sys->Tick(); + } + } + for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { + if (spr->Time) { + if (!spr->Flags.Hide) { + if (-- spr->Time == 0) + spr->Tick(); + } + } + } + asm mov ss,oldSS + asm mov sp,oldSP + run--; + } } */ @@ -301,17 +305,17 @@ void ENGINE::NewTimer(...) { my_int: //------72Hz-------// // decrement external timer uint16 - if (Heart->XTimer) - if (*Heart->XTimer) - *Heart->XTimer--; + if (_heart->XTimer) { + if (*_heart->XTimer) + *_heart->XTimer--; else - Heart->XTimer = NULL; + _heart->XTimer = NULL; + } - if (! run && Heart->Enable) // check overrun flag - { + if (! run && _heart->Enable) { // check overrun flag static uint16 oldSP, oldSS; - run++; // disable 2nd call until current lasts + run++; // disable 2nd call until current lasts asm mov ax,ds asm mov oldSS,ss asm mov oldSP,sp @@ -319,12 +323,21 @@ void ENGINE::NewTimer(...) { asm mov sp,0xFF80 // system pseudo-sprite - if (Sys) if (Sys->Time) if (-- Sys->Time == 0) Sys->Tick(); + if (Sys) { + if (Sys->Time) { + if (--Sys->Time == 0) + Sys->Tick(); + } + } - for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) - { - if (spr->Time) if (!spr->Flags.Hide) if (-- spr->Time == 0) spr->Tick(); - } + for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { + if (spr->Time) { + if (!spr->Flags.Hide) { + if (--spr->Time == 0) + spr->Tick(); + } + } + } asm mov ss,oldSS asm mov sp,oldSP run--; @@ -335,39 +348,39 @@ void ENGINE::NewTimer(...) { } -void HEART::SetXTimer(uint16 *ptr) { - if (XTimer && ptr != XTimer) - *XTimer = 0; - XTimer = ptr; +void Heart::setXTimer(uint16 *ptr) { + if (_xTimer && ptr != _xTimer) + *_xTimer = 0; + _xTimer = ptr; } -void HEART::SetXTimer(uint16 *ptr, uint16 time) { - SetXTimer(ptr); +void Heart::setXTimer(uint16 *ptr, uint16 time) { + setXTimer(ptr); *ptr = time; } -SPRITE::SPRITE(CGEEngine *vm, BMP_PTR *shp) +Sprite::Sprite(CGEEngine *vm, BMP_PTR *shp) : X(0), Y(0), Z(0), NearPtr(0), TakePtr(0), Next(NULL), Prev(NULL), SeqPtr(NO_SEQ), Time(0), //Delay(0), - Ext(NULL), Ref(-1), Cave(0), _vm(vm) { + _ext(NULL), _ref(-1), _cave(0), _vm(vm) { memset(File, 0, sizeof(File)); *((uint16 *)&Flags) = 0; SetShapeList(shp); } -SPRITE::~SPRITE(void) { +Sprite::~Sprite() { Contract(); } -BMP_PTR SPRITE::Shp(void) { - register SPREXT *e = Ext; +BMP_PTR Sprite::Shp() { + register SprExt *e = _ext; if (e) - if (e->Seq) { - int i = e->Seq[SeqPtr].Now; + if (e->_seq) { + int i = e->_seq[SeqPtr].Now; if (i >= ShpCnt) { //char s[256]; //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", @@ -375,14 +388,14 @@ BMP_PTR SPRITE::Shp(void) { //VGA::Exit(s, File); error("Invalid PHASE in SPRITE::Shp() %s", File); } - return e->ShpList[i]; + return e->_shpList[i]; } return NULL; } -BMP_PTR *SPRITE::SetShapeList(BMP_PTR *shp) { - BMP_PTR *r = (Ext) ? Ext->ShpList : NULL; +BMP_PTR *Sprite::SetShapeList(BMP_PTR *shp) { + BMP_PTR *r = (_ext) ? _ext->_shpList : NULL; ShpCnt = 0; W = 0; @@ -399,29 +412,29 @@ BMP_PTR *SPRITE::SetShapeList(BMP_PTR *shp) { ++ShpCnt; } Expand(); - Ext->ShpList = shp; - if (! Ext->Seq) - SetSeq((ShpCnt < 2) ? Seq1 : Seq2); + _ext->_shpList = shp; + if (!_ext->_seq) + SetSeq((ShpCnt < 2) ? _seq1 : _seq2); } return r; } -void SPRITE::MoveShapes(uint8 *buf) { +void Sprite::MoveShapes(uint8 *buf) { BMP_PTR *p; - for (p = Ext->ShpList; *p; p++) { + for (p = _ext->_shpList; *p; p++) { buf += (*p)->MoveVmap(buf); } } -bool SPRITE::Works(SPRITE *spr) { +bool Sprite::Works(Sprite *spr) { if (spr) - if (spr->Ext) { - SNAIL::COM *c = spr->Ext->Take; + if (spr->_ext) { + SNAIL::COM *c = spr->_ext->_take; if (c != NULL) { c += spr->TakePtr; - if (c->Ref == Ref) + if (c->Ref == _ref) if (c->Com != SNLABEL || (c->Val == 0 || c->Val == Now)) return true; } @@ -430,10 +443,10 @@ bool SPRITE::Works(SPRITE *spr) { } -SEQ *SPRITE::SetSeq(SEQ *seq) { +Seq *Sprite::SetSeq(Seq *seq) { Expand(); - register SEQ *s = Ext->Seq; - Ext->Seq = seq; + register Seq *s = _ext->_seq; + _ext->_seq = seq; if (SeqPtr == NO_SEQ) Step(0); else if (Time == 0) @@ -442,32 +455,32 @@ SEQ *SPRITE::SetSeq(SEQ *seq) { } -bool SPRITE::SeqTest(int n) { +bool Sprite::SeqTest(int n) { if (n >= 0) return (SeqPtr == n); - if (Ext) - return (Ext->Seq[SeqPtr].Next == SeqPtr); + if (_ext) + return (_ext->_seq[SeqPtr].Next == SeqPtr); return true; } -SNAIL::COM *SPRITE::SnList(SNLIST type) { - register SPREXT *e = Ext; +SNAIL::COM *Sprite::SnList(SNLIST type) { + register SprExt *e = _ext; if (e) - return (type == NEAR) ? e->Near : e->Take; + return (type == NEAR) ? e->_near : e->_take; return NULL; } -void SPRITE::SetName(char *n) { - if (Ext) { - if (Ext->Name) { - delete[] Ext->Name; - Ext->Name = NULL; +void Sprite::SetName(char *n) { + if (_ext) { + if (_ext->_name) { + delete[] _ext->_name; + _ext->_name = NULL; } if (n) { - if ((Ext->Name = new char[strlen(n) + 1]) != NULL) - strcpy(Ext->Name, n); + if ((_ext->_name = new char[strlen(n) + 1]) != NULL) + strcpy(_ext->_name, n); else error("No core [%s]", n); } @@ -475,17 +488,17 @@ void SPRITE::SetName(char *n) { } -SPRITE *SPRITE::Expand(void) { - if (! Ext) { - bool enbl = Heart->Enable; - Heart->Enable = false; - if ((Ext = new SPREXT) == NULL) +Sprite *Sprite::Expand(void) { + if (!_ext) { + bool enbl = _heart->_enable; + _heart->_enable = false; + if ((_ext = new SprExt) == NULL) error("No core"); if (*File) { static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; char line[LINE_MAX], fname[MAXPATH]; BMP_PTR *shplist = new BMP_PTR [ShpCnt + 1]; - SEQ *seq = NULL; + Seq *seq = NULL; int shpcnt = 0, seqcnt = 0, neacnt = 0, @@ -518,10 +531,10 @@ SPRITE *SPRITE::Expand(void) { break; } case 2 : { // Seq - seq = (SEQ *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); + seq = (Seq *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); if (seq == NULL) error("No core [%s]", fname); - SEQ *s = &seq[seqcnt++]; + Seq *s = &seq[seqcnt++]; s->Now = atoi(strtok(NULL, " \t,;/")); if (s->Now > maxnow) maxnow = s->Now; @@ -586,52 +599,52 @@ SPRITE *SPRITE::Expand(void) { error("Bad JUMP in SEQ [%s]", fname); SetSeq(seq); } else - SetSeq((ShpCnt == 1) ? Seq1 : Seq2); + SetSeq((ShpCnt == 1) ? _seq1 : _seq2); //disable(); // disable interupt SetShapeList(shplist); //enable(); // enable interupt if (nea) - nea[neacnt - 1].Ptr = Ext->Near = nea; + nea[neacnt - 1].Ptr = _ext->_near = nea; else NearPtr = NO_PTR; if (tak) - tak[takcnt - 1].Ptr = Ext->Take = tak; + tak[takcnt - 1].Ptr = _ext->_take = tak; else TakePtr = NO_PTR; } - Heart->Enable = enbl; + _heart->_enable = enbl; } return this; } -SPRITE *SPRITE::Contract(void) { - register SPREXT *e = Ext; +Sprite *Sprite::Contract(void) { + register SprExt *e = _ext; if (e) { - if (e->Name) - delete[] e->Name; - if (Flags.BDel && e->ShpList) { + if (e->_name) + delete[] e->_name; + if (Flags.BDel && e->_shpList) { int i; - for (i = 0; e->ShpList[i]; i++) - delete e->ShpList[i]; - if (MemType(e->ShpList) == NEAR_MEM) - delete[] e->ShpList; + for (i = 0; e->_shpList[i]; i++) + delete e->_shpList[i]; + if (MemType(e->_shpList) == NEAR_MEM) + delete[] e->_shpList; } - if (MemType(e->Seq) == NEAR_MEM) - free(e->Seq); - if (e->Near) - free(e->Near); - if (e->Take) - free(e->Take); + if (MemType(e->_seq) == NEAR_MEM) + free(e->_seq); + if (e->_near) + free(e->_near); + if (e->_take) + free(e->_take); delete e; - Ext = NULL; + _ext = NULL; } return this; } -SPRITE *SPRITE::BackShow(bool fast) { +Sprite *Sprite::BackShow(bool fast) { Expand(); Show(2); Show(1); @@ -642,14 +655,14 @@ SPRITE *SPRITE::BackShow(bool fast) { } -void SPRITE::Step(int nr) { +void Sprite::Step(int nr) { if (nr >= 0) SeqPtr = nr; - if (Ext) { - SEQ *seq; + if (_ext) { + Seq *seq; if (nr < 0) - SeqPtr = Ext->Seq[SeqPtr].Next; - seq = Ext->Seq + SeqPtr; + SeqPtr = _ext->_seq[SeqPtr].Next; + seq = _ext->_seq + SeqPtr; if (seq->Dly >= 0) { Goto(X + (seq->Dx), Y + (seq->Dy)); Time = seq->Dly; @@ -658,28 +671,28 @@ void SPRITE::Step(int nr) { } -void SPRITE::Tick(void) { +void Sprite::Tick(void) { Step(); } -void SPRITE::MakeXlat(uint8 *x) { - if (Ext) { +void Sprite::MakeXlat(uint8 *x) { + if (_ext) { BMP_PTR *b; if (Flags.Xlat) KillXlat(); - for (b = Ext->ShpList; *b; b++) + for (b = _ext->_shpList; *b; b++) (*b)->M = x; Flags.Xlat = true; } } -void SPRITE::KillXlat(void) { - if (Flags.Xlat && Ext) { +void Sprite::KillXlat(void) { + if (Flags.Xlat && _ext) { BMP_PTR *b; - uint8 *m = (*Ext->ShpList)->M; + uint8 *m = (*_ext->_shpList)->M; switch (MemType(m)) { case NEAR_MEM : @@ -689,14 +702,14 @@ void SPRITE::KillXlat(void) { free(m); break; } - for (b = Ext->ShpList; *b; b++) + for (b = _ext->_shpList; *b; b++) (*b)->M = NULL; Flags.Xlat = false; } } -void SPRITE::Goto(int x, int y) { +void Sprite::Goto(int x, int y) { int xo = X, yo = Y; if (W < SCR_WID) { if (x < 0) @@ -720,30 +733,32 @@ void SPRITE::Goto(int x, int y) { } -void SPRITE::Center(void) { +void Sprite::Center(void) { Goto((SCR_WID - W) / 2, (SCR_HIG - H) / 2); } -void SPRITE::Show(void) { - register SPREXT *e; +void Sprite::Show(void) { + register SprExt *e; // asm cli // critic section... - e = Ext; - e->x0 = e->x1; - e->y0 = e->y1; - e->b0 = e->b1; - e->x1 = X; - e->y1 = Y; - e->b1 = Shp(); + e = _ext; + e->_x0 = e->_x1; + e->_y0 = e->_y1; + e->_b0 = e->_b1; + e->_x1 = X; + e->_y1 = Y; + e->_b1 = Shp(); // asm sti // ...done! if (! Flags.Hide) { - if (Flags.Xlat) e->b1->XShow(e->x1, e->y1); - else e->b1->Show(e->x1, e->y1); + if (Flags.Xlat) + e->_b1->XShow(e->_x1, e->_y1); + else + e->_b1->Show(e->_x1, e->_y1); } } -void SPRITE::Show(uint16 pg) { +void Sprite::Show(uint16 pg) { Graphics::Surface *a = VGA::Page[1]; VGA::Page[1] = VGA::Page[pg & 3]; Shp()->Show(X, Y); @@ -751,24 +766,24 @@ void SPRITE::Show(uint16 pg) { } -void SPRITE::Hide(void) { - register SPREXT *e = Ext; - if (e->b0) - e->b0->Hide(e->x0, e->y0); +void Sprite::Hide(void) { + register SprExt *e = _ext; + if (e->_b0) + e->_b0->Hide(e->_x0, e->_y0); } -BMP_PTR SPRITE::Ghost(void) { - register SPREXT *e = Ext; - if (e->b1) { +BMP_PTR Sprite::Ghost(void) { + register SprExt *e = _ext; + if (e->_b1) { BMP_PTR bmp = new BITMAP(0, 0, (uint8 *)NULL); if (bmp == NULL) error("No core"); - bmp->W = e->b1->W; - bmp->H = e->b1->H; + bmp->W = e->_b1->W; + bmp->H = e->_b1->H; if ((bmp->B = farnew(HideDesc, bmp->H)) == NULL) error("No Core"); - bmp->V = (uint8 *) memcpy(bmp->B, e->b1->B, sizeof(HideDesc) * bmp->H); + bmp->V = (uint8 *) memcpy(bmp->B, e->_b1->B, sizeof(HideDesc) * bmp->H); // TODO offset correctly in the surface using y1 pitch and x1 and not via offset segment //bmp->M = (uint8 *) MK_FP(e->y1, e->x1); warning("FIXME: SPRITE::Ghost"); @@ -778,8 +793,8 @@ BMP_PTR SPRITE::Ghost(void) { } -SPRITE *SpriteAt(int x, int y) { - SPRITE *spr = NULL, * tail = Vga->ShowQ->Last(); +Sprite *SpriteAt(int x, int y) { + Sprite *spr = NULL, * tail = Vga->ShowQ->Last(); if (tail) { for (spr = tail->Prev; spr; spr = spr->Prev) if (! spr->Flags.Hide && ! spr->Flags.Tran) @@ -801,24 +816,24 @@ QUEUE::~QUEUE(void) { void QUEUE::Clear(void) { while (Head) { - SPRITE *s = Remove(Head); + Sprite *s = Remove(Head); if (s->Flags.Kill) delete s; } } -void QUEUE::ForAll(void (*fun)(SPRITE *)) { - SPRITE *s = Head; +void QUEUE::ForAll(void (*fun)(Sprite *)) { + Sprite *s = Head; while (s) { - SPRITE *n = s->Next; + Sprite *n = s->Next; fun(s); s = n; } } -void QUEUE::Append(SPRITE *spr) { +void QUEUE::Append(Sprite *spr) { if (Tail) { spr->Prev = Tail; Tail->Next = spr; @@ -832,7 +847,7 @@ void QUEUE::Append(SPRITE *spr) { } -void QUEUE::Insert(SPRITE *spr, SPRITE *nxt) { +void QUEUE::Insert(Sprite *spr, Sprite *nxt) { if (nxt == Head) { spr->Next = Head; Head = spr; @@ -853,8 +868,8 @@ void QUEUE::Insert(SPRITE *spr, SPRITE *nxt) { } -void QUEUE::Insert(SPRITE *spr) { - SPRITE *s; +void QUEUE::Insert(Sprite *spr) { + Sprite *s; for (s = Head; s; s = s->Next) if (s->Z > spr->Z) break; @@ -869,7 +884,7 @@ void QUEUE::Insert(SPRITE *spr) { } -SPRITE *QUEUE::Remove(SPRITE *spr) { +Sprite *QUEUE::Remove(Sprite *spr) { if (spr == Head) Head = spr->Next; if (spr == Tail) @@ -884,11 +899,12 @@ SPRITE *QUEUE::Remove(SPRITE *spr) { } -SPRITE *QUEUE::Locate(int ref) { - SPRITE *spr; - for (spr = Head; spr; spr = spr->Next) - if (spr->Ref == ref) +Sprite *QUEUE::Locate(int ref) { + Sprite *spr; + for (spr = Head; spr; spr = spr->Next) { + if (spr->_ref == ref) return spr; + } return NULL; } @@ -907,9 +923,9 @@ void VGA::init() { } void VGA::deinit() { - for (int idx = 0; idx < 4; ++idx) { + for (int idx = 0; idx < 4; ++idx) delete Page[idx]; - } + delete[] SysPal; } @@ -1120,7 +1136,7 @@ void VGA::Sunset(void) { void VGA::Show(void) { - SPRITE *spr = ShowQ->First(); + Sprite *spr = ShowQ->First(); for (spr = ShowQ->First(); spr; spr = spr->Next) spr->Show(); diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index c984e121e84..af1c981aa86 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -81,37 +81,40 @@ namespace CGE { -typedef struct { +struct Rgb { uint16 r : 2; uint16 R : 6; uint16 g : 2; uint16 G : 6; uint16 b : 2; uint16 B : 6; -} RGB; +}; typedef union { DAC dac; - RGB rgb; + Rgb rgb; } TRGB; -typedef struct { - uint8 idx, adr; - uint8 clr, set; -} VgaRegBlk; +struct VgaRegBlk { + uint8 idx; + uint8 adr; + uint8 clr; + uint8 set; +}; -typedef struct { - uint8 Now, Next; - signed char Dx, Dy; +struct Seq { + uint8 Now; + uint8 Next; + int8 Dx; + int8 Dy; int Dly; -} SEQ; +}; -extern SEQ Seq1[]; -extern SEQ Seq2[]; +extern Seq _seq1[]; +extern Seq _seq2[]; //extern SEQ * Compass[]; //extern SEQ TurnToS[]; - #define PAL_CNT 256 #define PAL_SIZ (PAL_CNT * 3) #define VGAATR_ 0x3C0 @@ -130,43 +133,44 @@ extern SEQ Seq2[]; #define VGAST1 (VGAST1_ & 0xFF) -class HEART : public ENGINE { +class Heart : public ENGINE { friend class ENGINE; public: - HEART(); + Heart(); - bool Enable; - uint16 *XTimer; - void SetXTimer(uint16 *ptr); - void SetXTimer(uint16 *ptr, uint16 time); + bool _enable; + uint16 *_xTimer; + + void setXTimer(uint16 *ptr); + void setXTimer(uint16 *ptr, uint16 time); }; -class SPREXT { +class SprExt { public: - int x0, y0; - int x1, y1; - BMP_PTR b0, b1; - BMP_PTR *ShpList; - SEQ *Seq; - char *Name; - SNAIL::COM *Near, * Take; - SPREXT(void) : - x0(0), y0(0), - x1(0), y1(0), - b0(NULL), b1(NULL), - ShpList(NULL), Seq(NULL), - Name(NULL), Near(NULL), Take(NULL) + int _x0, _y0; + int _x1, _y1; + BMP_PTR _b0, _b1; + BMP_PTR *_shpList; + Seq *_seq; + char *_name; + SNAIL::COM *_near, *_take; + SprExt() : + _x0(0), _y0(0), + _x1(0), _y1(0), + _b0(NULL), _b1(NULL), + _shpList(NULL), _seq(NULL), + _name(NULL), _near(NULL), _take(NULL) {} }; -class SPRITE { +class Sprite { protected: - SPREXT *Ext; + SprExt *_ext; public: - int Ref; - signed char Cave; + int _ref; + signed char _cave; struct FLAGS { uint16 Hide : 1; // general visibility switch uint16 Near : 1; // Near action lock @@ -193,23 +197,23 @@ public: int SeqPtr; int ShpCnt; char File[MAXFILE]; - SPRITE *Prev, * Next; - bool Works(SPRITE *spr); + Sprite *Prev, * Next; + bool Works(Sprite *spr); bool SeqTest(int n); inline bool Active(void) { - return Ext != NULL; + return _ext != NULL; } - SPRITE(CGEEngine *vm, BMP_PTR *shp); - virtual ~SPRITE(void); + Sprite(CGEEngine *vm, BMP_PTR *shp); + virtual ~Sprite(void); BMP_PTR Shp(void); BMP_PTR *SetShapeList(BMP_PTR *shp); void MoveShapes(uint8 *buf); - SPRITE *Expand(void); - SPRITE *Contract(void); - SPRITE *BackShow(bool fast = false); + Sprite *Expand(void); + Sprite *Contract(void); + Sprite *BackShow(bool fast = false); void SetName(char *n); inline char *Name(void) { - return (Ext) ? Ext->Name : NULL; + return (_ext) ? _ext->_name : NULL; } void Goto(int x, int y); void Center(void); @@ -220,7 +224,7 @@ public: void MakeXlat(uint8 *x); void KillXlat(void); void Step(int nr = -1); - SEQ *SetSeq(SEQ *seq); + Seq *SetSeq(Seq *seq); SNAIL::COM *SnList(SNLIST type); virtual void Touch(uint16 mask, int x, int y); virtual void Tick(void); @@ -230,23 +234,23 @@ private: class QUEUE { - SPRITE *Head, * Tail; + Sprite *Head, * Tail; public: bool Show; QUEUE(bool show); ~QUEUE(void); - void Append(SPRITE *spr); - void Insert(SPRITE *spr, SPRITE *nxt); - void Insert(SPRITE *spr); - SPRITE *Remove(SPRITE *spr); - void ForAll(void (*fun)(SPRITE *)); - SPRITE *First(void) { + void Append(Sprite *spr); + void Insert(Sprite *spr, Sprite *nxt); + void Insert(Sprite *spr); + Sprite *Remove(Sprite *spr); + void ForAll(void (*fun)(Sprite *)); + Sprite *First(void) { return Head; } - SPRITE *Last(void) { + Sprite *Last(void) { return Tail; } - SPRITE *Locate(int ref); + Sprite *Locate(int ref); void Clear(void); }; @@ -292,8 +296,8 @@ public: }; -DAC MkDAC(uint8 r, uint8 g, uint8 b); -RGB MkRGB(uint8 r, uint8 g, uint8 b); +DAC MkDAC(uint8 r, uint8 g, uint8 b); +Rgb MkRGB(uint8 r, uint8 g, uint8 b); template @@ -331,12 +335,12 @@ uint8 Closest(CBLK *pal, CBLK x) { -char *NumStr(char *str, int num); +char *NumStr(char *str, int num); //static void Video (void); -uint16 *SaveScreen(void); -void RestoreScreen(uint16 * &sav); -SPRITE *SpriteAt(int x, int y); -SPRITE *Locate(int ref); +uint16 *SaveScreen(void); +void RestoreScreen(uint16 * &sav); +Sprite *SpriteAt(int x, int y); +Sprite *Locate(int ref); extern bool SpeedTest; diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 7db5a79f856..ed335191aa1 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -130,7 +130,7 @@ void VMENU::Touch(uint16 mask, int x, int y) { bool ok = false; if (Items) { - SPRITE::Touch(mask, x, y); + Sprite::Touch(mask, x, y); y -= TEXT_VM - 1; int n = 0; From e1b6bc042752f2a07a6cb0911d11bf52ed26d9a8 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 29 Jun 2011 21:17:07 +1000 Subject: [PATCH 042/276] CGE: Removed Mouse from VGA::ShowQ to prevent crashes in the movie player --- engines/cge/cge_main.cpp | 20 ++++++++++++++++---- engines/cge/vga13h.cpp | 4 +++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index ece6ec5adb4..20663768854 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -25,6 +25,7 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ +#include "common/scummsys.h" #include "cge/general.h" #include "cge/boot.h" #include "cge/ident.h" @@ -1463,8 +1464,12 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int _sprite->Flags.Tran = tran; _sprite->Flags.Kill = true; _sprite->Flags.BDel = true; - //fnsplit(fname, NULL, NULL, _sprite->File, NULL); - warning("LoadSprite: use of fnsplit"); + + // Extract the filename, without the extension + strcpy(_sprite->File, fname); + char *p = strchr(_sprite->File, '.'); + if (p) + *p = '\0'; _sprite->ShpCnt = shpcnt; Vga->SpareQ->Append(_sprite); @@ -1551,6 +1556,9 @@ void CGEEngine::MainLoop() { Vga->Show(); Snail_->RunCom(); Snail->RunCom(); + + // Delay to slow things down + g_system->delayMillis(10); } @@ -1599,7 +1607,8 @@ void CGEEngine::RunGame() { Vga->ShowQ->Append(_pocLight); SelectPocket(-1); - Vga->ShowQ->Append(Mouse); + // FIXME: Allow ScummVM to handle mouse display +// Vga->ShowQ->Append(Mouse); // ___________ LoadUser(); @@ -1692,7 +1701,10 @@ void CGEEngine::Movie(const char *ext) { LoadScript(fn); ExpandSprite(Vga->SpareQ->Locate(999)); FeedSnail(Vga->ShowQ->Locate(999), TAKE); - Vga->ShowQ->Append(Mouse); + + // FIXME: Allow ScummVM to handle mouse display + //Vga->ShowQ->Append(Mouse); + _heart->_enable = true; KEYBOARD::SetClient(Sys); while (!Snail->Idle()) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 1d55af7e31e..e642db8e7f8 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1310,7 +1310,8 @@ void BITMAP::Show(int x, int y) { ++srcP; } } - +/* + DEBUG code to display image immediately // Temporary g_system->copyRectToScreen((const byte *)VGA::Page[1]->getBasePtr(0, 0), SCR_WID, 0, 0, SCR_WID, SCR_HIG); byte palData[PAL_SIZ]; @@ -1319,6 +1320,7 @@ void BITMAP::Show(int x, int y) { g_system->updateScreen(); g_system->delayMillis(5000); +*/ } From 91dc5f424aa474001ac85d600cd22aff54e317c4 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 29 Jun 2011 09:57:16 +0200 Subject: [PATCH 043/276] CGE: Misc cleanup (provided by Digitall) --- engines/cge/bitmap.cpp | 5 +++++ engines/cge/cge_main.cpp | 14 ++++++-------- engines/cge/config.cpp | 13 ------------- engines/cge/detection.cpp | 33 +++++++-------------------------- engines/cge/ems.cpp | 3 +-- engines/cge/general.cpp | 4 ++-- engines/cge/keybd.cpp | 2 +- engines/cge/snail.cpp | 4 +++- engines/cge/talk.cpp | 6 +++--- engines/cge/vga13h.cpp | 28 ++++++++++++---------------- engines/cge/vga13h.h | 2 +- 11 files changed, 41 insertions(+), 73 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 10fc9a4df6b..9f19e91b1f5 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -140,6 +140,8 @@ BITMAP::~BITMAP(void) { case FAR_MEM : free(V); default: + warning("Unhandled MemType in Bitmap destructor"); + break; break; } } @@ -193,6 +195,9 @@ BMP_PTR BITMAP::Code(void) { case FAR_MEM : free(V); break; + default: + warning("Unhandled MemType in Bitmap::Code()"); + break; } V = NULL; } diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 20663768854..e5294c0c148 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -262,7 +262,7 @@ void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { file.Read((uint8 *) &i, sizeof(i)); if (i != SVGCHKSUM) - error(Text->getText(BADSVG_TEXT)); + error("%s", Text->getText(BADSVG_TEXT)); if (STARTUP::Core < CORE_HIG) Music = false; @@ -357,6 +357,7 @@ static void TooFar(void) { } +// Used in stubbed function, do not remove! static void NoWay(void) { Trouble(NO_WAY, NO_WAY_TEXT); } @@ -582,15 +583,12 @@ void CGEEngine::SetMapBrick(int x, int z) { } } -//static void SwitchMapping(void); static void SwitchColorMode(void); -//static void StartCountDown(void); static void SwitchDebug(void); static void SwitchMusic(void); static void KillSprite(void); static void PushSprite(void); static void PullSprite(void); -static void BackPaint(void); static void NextStep(void); static void SaveMapping(void); @@ -631,7 +629,7 @@ static void AltCtrlDel(void) { SNPOST_(SNSAY, -1, A_C_D_TEXT, Hero); } - +// Used in stubbed function, do not remove! static void MiniStep(int stp) { if (stp < 0) _miniCave->Flags.Hide = true; @@ -1357,7 +1355,7 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int continue; if ((i = TakeEnum(Comd, strtok(line, " =\t"))) < 0) - error("%s [%s]", NumStr("Bad line ######", lcnt), fname); + error("%s [%s]", NumStr("Bad line ######", lcnt), (const char *)fname); switch (i) { @@ -1365,7 +1363,7 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int break; case 1 : // Type if ((type = TakeEnum(Type, strtok(NULL, " \t,;/"))) < 0) - error("%s [%s]", NumStr("Bad line ######", lcnt), fname); + error("%s [%s]", NumStr("Bad line ######", lcnt), (const char *)fname); break; case 2 : // Phase ++ shpcnt; @@ -1541,7 +1539,7 @@ void CGEEngine::MainLoop() { SayDebug(); if (_isDemo) { - static uint32 tc = 0; +// static uint32 tc = 0; if (/* FIXME: TimerCount - tc >= ((182L * 6L) * 5L) && */ Talk == NULL && Snail->Idle()) { if (Text->getText(DemoText)) { SNPOST(SNSOUND, -1, 4, NULL); // drumla diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 4aa4f40c8a5..a9d55957af4 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -59,19 +59,6 @@ namespace CGE { #define DETECT 0xFFFF -static void NONE(void); -static void SB(void); -static void SBM(void); -static void GUS(void); -static void GUSM(void); -static void MIDI(void); -static void AUTO(void); -static void SetPortD(void); -static void SetPortM(void); -static void SetIRQ(void); -static void SetDMA(void); - - static int DevName[] = { NONE_TEXT, SB_TEXT, SBM_TEXT, GUS_TEXT, GUSM_TEXT, MIDI_TEXT, AUTO_TEXT diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index f03a42fb35f..31bf629fcfa 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -85,34 +85,15 @@ static const ADFileBasedFallback fileBasedFallback[] = { } // End of namespace CGE -static const ADParams detectionParams = { - // Pointer to ADGameDescription or its superset structure - (const byte *)CGE::gameDescriptions, - // Size of that superset structure - sizeof(ADGameDescription), - // Number of bytes to compute MD5 sum for - 5000, - // List of all engine targets - CGEGames, - // Structure for autoupgrading obsolete targets - 0, - // Name of single gameid (optional) - "Soltys", - // List of files for file-based fallback detection (optional) - CGE::fileBasedFallback, - // Flags - 0, - // Additional GUI options (for every game} - Common::GUIO_NONE, - // Maximum directory depth - 0, - // List of directory globs - NULL -}; - class CGEMetaEngine : public AdvancedMetaEngine { public: - CGEMetaEngine() : AdvancedMetaEngine(detectionParams) {} + CGEMetaEngine() : AdvancedMetaEngine(CGE::gameDescriptions, sizeof(ADGameDescription), CGEGames) { + _singleid = "Soltys"; + } + + virtual const ADGameDescription *fallbackDetect(const FileMap &allFiles, const Common::FSList &fslist) const { + return detectGameFilebased(allFiles, CGE::fileBasedFallback); + } virtual const char *getName() const { return "CGE"; diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp index f1f7ece7087..56d853f4e80 100644 --- a/engines/cge/ems.cpp +++ b/engines/cge/ems.cpp @@ -83,7 +83,7 @@ EMM::EMM(long size): Han(-1), Top(0), Lim(0), List(NULL) { EMM::~EMM(void) { - /* + /* FIXME Release(); if (Han >= 0) { @@ -94,7 +94,6 @@ EMM::~EMM(void) { asm int EMS_INT } */ - warning("STUB: EMM::~EMM"); } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 428498923e9..7bf753ff9f6 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -304,7 +304,7 @@ EC void SNDInit() { } EC void SNDDone() { - warning("STUB: SNDDone"); + // FIXME: STUB: SNDDone } EC void SNDSetVolume() { @@ -324,7 +324,7 @@ EC void SNDMIDIStart(uint8 *MIDFile) { } EC void SNDMIDIStop() { - warning("STUB: SNDMIDIStop"); + // FIXME: STUB: SNDMIDIStop } DATACK *LoadWave(XFILE *file, EMM *emm) { diff --git a/engines/cge/keybd.cpp b/engines/cge/keybd.cpp index 4aee394e07b..8530815b16e 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/keybd.cpp @@ -74,7 +74,7 @@ KEYBOARD::~KEYBOARD(void) { /* TODO replace totally by scummvm handling setvect(KEYBD_INT, OldKeyboard); */ - warning("STUB: KEYBOARD::~KEYBOARD"); + // FIXME: STUB: KEYBOARD::~KEYBOARD } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 1cb53d20240..50eed3f5620 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -819,7 +819,6 @@ static void SNLevel(Sprite *spr, int lev) { static int maxcav[] = { 1, 8, 16, 23, 24 }; #endif while (Lev < lev) { - Sprite *spr; ++Lev; spr = Vga->SpareQ->Locate(100 + Lev); if (spr) { @@ -1114,6 +1113,9 @@ void SNAIL::RunCom(void) { case SNGHOST : SNGhost((BITMAP *) snc->Ptr); break; + default : + warning("Unhandled snc->Com in SNMouse(bool)"); + break; } ++Tail; if (!Turbo) diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 544359897f3..43917732be6 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -167,14 +167,14 @@ void TALK::Update(const char *tx) { int cw = _Font->Wid[*tx], i; uint8 *f = _Font->Map + _Font->Pos[*tx]; for (i = 0; i < cw; i++) { - uint8 *p = m; + uint8 *pp = m; uint16 n; register uint16 b = *(f++); for (n = 0; n < FONT_HIG; n++) { if (b & 1) - *p = TEXT_FG; + *pp = TEXT_FG; b >>= 1; - p += mw; + pp += mw; } ++m; } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index e642db8e7f8..56960389c8e 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -41,12 +41,8 @@ namespace CGE { -#define FADE_STEP 2 -#define TMR_DIV ((0x8000/TMR_RATE)*2) - -//-------------------------------------------------------------------------- - -static char Report[] = "NearHeap=..... FarHeap=......\n"; +#define FADE_STEP 2 +#define TMR_DIV ((0x8000/TMR_RATE)*2) #define NREP 9 #define FREP 24 @@ -64,10 +60,9 @@ static VgaRegBlk VideoMode[] = { // { 0x12, VGACRT, 0xFF, 0x6E }, // vert display end // { 0x15, VGACRT, 0xFF, 0x7F }, // start vb // { 0x10, VGACRT, 0xFF, 0x94 }, // start vr - { 0x00 } + { 0x00, 0x00, 0x00, 0x00 } }; - bool SpeedTest = false; Seq _seq1[] = { { 0, 0, 0, 0, 0 } }; Seq _seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; @@ -82,8 +77,8 @@ char *NumStr(char *str, int num) { } -static void Video() { /* +static void Video() { static uint16 SP_S; asm push bx @@ -100,9 +95,8 @@ static void Video() { asm pop si asm pop bp asm pop bx -*/ - warning("STUB: Video"); } +*/ uint16 *SaveScreen(void) { @@ -562,7 +556,7 @@ Sprite *Sprite::Expand(void) { else { SNAIL::COM *c = &nea[neacnt++]; if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) - error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), fname); + error("%s [%s]", (const char*)NumStr("Bad NEAR in ######", lcnt), (const char*)fname); c->Ref = atoi(strtok(NULL, " \t,;/")); c->Val = atoi(strtok(NULL, " \t,;/")); c->Ptr = NULL; @@ -578,7 +572,7 @@ Sprite *Sprite::Expand(void) { else { SNAIL::COM *c = &tak[takcnt++]; if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) - error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), fname); + error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), (const char *)fname); c->Ref = atoi(strtok(NULL, " \t,;/")); c->Val = atoi(strtok(NULL, " \t,;/")); c->Ptr = NULL; @@ -701,6 +695,9 @@ void Sprite::KillXlat(void) { case FAR_MEM : free(m); break; + default: + warning("Unhandled MemType in Sprite::KillXlat()"); + break; } for (b = _ext->_shpList; *b; b++) (*b)->M = NULL; @@ -942,8 +939,7 @@ VGA::VGA(int mode) for (i = 10; i < 20; i++) { char *txt = Text->getText(i); if (txt) { -// puts(txt); - warning(txt); + warning("%s", txt); std = false; } } @@ -986,7 +982,7 @@ VGA::~VGA(void) { if (Nam) buffer = buffer + " [" + Nam + "]"; - warning(buffer.c_str()); + warning("%s", buffer.c_str()); } } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index af1c981aa86..77594217abc 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -344,6 +344,6 @@ Sprite *Locate(int ref); extern bool SpeedTest; -} // End if namespace CGE +} // End of namespace CGE #endif From f2f3124246a77036f843dee2d83ad28084234ebc Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 29 Jun 2011 16:13:17 +0200 Subject: [PATCH 044/276] CGE: Some more renaming (wip) --- engines/cge/bitmap.cpp | 220 ++++++++++++++++++------------------- engines/cge/bitmap.h | 29 ++--- engines/cge/bitmaps.h | 12 +- engines/cge/cge.cpp | 26 ++--- engines/cge/cge_main.cpp | 231 ++++++++++++++++++++------------------- engines/cge/config.cpp | 8 +- engines/cge/game.cpp | 12 +- engines/cge/game.h | 2 +- engines/cge/gettext.cpp | 8 +- engines/cge/mixer.cpp | 38 +++---- engines/cge/mouse.cpp | 48 ++++---- engines/cge/mouse.h | 13 ++- engines/cge/snail.cpp | 135 +++++++++++------------ engines/cge/snail.h | 4 +- engines/cge/talk.cpp | 30 ++--- engines/cge/talk.h | 4 +- engines/cge/text.cpp | 34 +++--- engines/cge/vga13h.cpp | 190 ++++++++++++++++---------------- engines/cge/vga13h.h | 57 +++++----- engines/cge/vmenu.cpp | 30 ++--- 20 files changed, 569 insertions(+), 562 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 9f19e91b1f5..ab5c1ff3c78 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -35,18 +35,18 @@ namespace CGE { -DAC *BITMAP::Pal = NULL; +DAC *Bitmap::Pal = NULL; #define MAXPATH 128 -void BITMAP::init() { +void Bitmap::init() { Pal = NULL; } -void BITMAP::deinit() { +void Bitmap::deinit() { } #pragma argsused -BITMAP::BITMAP(const char *fname, bool rem) : M(NULL), V(NULL) { +Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { char pat[MAXPATH]; ForceExt(pat, fname, ".VBM"); @@ -65,8 +65,8 @@ BITMAP::BITMAP(const char *fname, bool rem) : M(NULL), V(NULL) { if (BMPLoad(&file)) { Code(); if (rem) { - free(M); - M = NULL; + free(_m); + _m = NULL; } } else error("Bad BMP [%s]", fname); @@ -78,7 +78,7 @@ BITMAP::BITMAP(const char *fname, bool rem) : M(NULL), V(NULL) { } -BITMAP::BITMAP(uint16 w, uint16 h, uint8 *map) : W(w), H(h), M(map), V(NULL) { +Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL) { if (map) Code(); } @@ -87,14 +87,14 @@ BITMAP::BITMAP(uint16 w, uint16 h, uint8 *map) : W(w), H(h), M(map), V(NULL) { // following routine creates filled rectangle // immediately as VGA video chunks, in near memory as fast as possible, // especially for text line real time display -BITMAP::BITMAP(uint16 w, uint16 h, uint8 fill) - : W((w + 3) & ~3), // only full uint32 allowed! - H(h), - M(NULL) { - uint16 dsiz = W >> 2; // data size (1 plane line size) +Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) + : _w((w + 3) & ~3), // only full uint32 allowed! + _h(h), + _m(NULL) { + uint16 dsiz = _w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap - uint16 psiz = H * lsiz; // - last gape, but + plane trailer - uint8 *v = new uint8[4 * psiz + H * sizeof(*B)];// the same for 4 planes + uint16 psiz = _h * lsiz; // - last gape, but + plane trailer + uint8 *v = new uint8[4 * psiz + _h * sizeof(*_b)];// the same for 4 planes // + room for wash table if (v == NULL) error("No core"); @@ -106,39 +106,39 @@ BITMAP::BITMAP(uint16 w, uint16 h, uint8 fill) *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes HideDesc *b = (HideDesc *)(v + 4 * psiz); - b->skip = (SCR_WID - W) >> 2; - b->hide = W >> 2; - memcpy(b + 1, b, (H - 1) * sizeof(*b)); // tricky fill entire table + b->skip = (SCR_WID - _w) >> 2; + b->hide = _w >> 2; + memcpy(b + 1, b, (_h - 1) * sizeof(*b)); // tricky fill entire table b->skip = 0; // fix the first entry - V = v; - B = b; + _v = v; + _b = b; } -BITMAP::BITMAP(const BITMAP &bmp) : W(bmp.W), H(bmp.H), M(NULL), V(NULL) { - uint8 *v0 = bmp.V; +Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL) { + uint8 *v0 = bmp._v; if (v0) { - uint16 vsiz = (uint8 *)(bmp.B) - (uint8 *)(v0); - uint16 siz = vsiz + H * sizeof(HideDesc); + uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); + uint16 siz = vsiz + _h * sizeof(HideDesc); uint8 *v1 = farnew(uint8, siz); if (v1 == NULL) error("No core"); memcpy(v1, v0, siz); - B = (HideDesc *)((V = v1) + vsiz); + _b = (HideDesc *)((_v = v1) + vsiz); } } -BITMAP::~BITMAP(void) { - if (MemType(M) == FAR_MEM) - free(M); +Bitmap::~Bitmap(void) { + if (MemType(_m) == FAR_MEM) + free(_m); - switch (MemType(V)) { + switch (MemType(_v)) { case NEAR_MEM : - delete[](uint8 *) V; + delete[](uint8 *) _v; break; case FAR_MEM : - free(V); + free(_v); default: warning("Unhandled MemType in Bitmap destructor"); break; @@ -147,92 +147,92 @@ BITMAP::~BITMAP(void) { } -BITMAP &BITMAP::operator = (const BITMAP &bmp) { - uint8 *v0 = bmp.V; - W = bmp.W; - H = bmp.H; - M = NULL; - if (MemType(V) == FAR_MEM) - free(V); +Bitmap &Bitmap::operator = (const Bitmap &bmp) { + uint8 *v0 = bmp._v; + _w = bmp._w; + _h = bmp._h; + _m = NULL; + if (MemType(_v) == FAR_MEM) + free(_v); if (v0 == NULL) - V = NULL; + _v = NULL; else { - uint16 vsiz = (uint8 *)bmp.B - (uint8 *)v0; - uint16 siz = vsiz + H * sizeof(HideDesc); + uint16 vsiz = (uint8 *)bmp._b - (uint8 *)v0; + uint16 siz = vsiz + _h * sizeof(HideDesc); uint8 *v1 = farnew(uint8, siz); if (v1 == NULL) error("No core"); memcpy(v1, v0, siz); - B = (HideDesc *)((V = v1) + vsiz); + _b = (HideDesc *)((_v = v1) + vsiz); } return *this; } -uint16 BITMAP::MoveVmap(uint8 *buf) { - if (V) { - uint16 vsiz = (uint8 *)B - (uint8 *)V; - uint16 siz = vsiz + H * sizeof(HideDesc); - memcpy(buf, V, siz); - if (MemType(V) == FAR_MEM) - free(V); - B = (HideDesc *)((V = buf) + vsiz); +uint16 Bitmap::MoveVmap(uint8 *buf) { + if (_v) { + uint16 vsiz = (uint8 *)_b - (uint8 *)_v; + uint16 siz = vsiz + _h * sizeof(HideDesc); + memcpy(buf, _v, siz); + if (MemType(_v) == FAR_MEM) + free(_v); + _b = (HideDesc *)((_v = buf) + vsiz); return siz; } return 0; } -BMP_PTR BITMAP::Code(void) { - if (M) { +BMP_PTR Bitmap::Code(void) { + if (_m) { uint16 i, cnt; - if (V) { // old X-map exists, so remove it - switch (MemType(V)) { + if (_v) { // old X-map exists, so remove it + switch (MemType(_v)) { case NEAR_MEM : - delete[](uint8 *) V; + delete[](uint8 *) _v; break; case FAR_MEM : - free(V); + free(_v); break; default: warning("Unhandled MemType in Bitmap::Code()"); break; } - V = NULL; + _v = NULL; } while (true) { // at most 2 times: for (V == NULL) & for allocated block; - uint8 *im = V + 2; - uint16 *cp = (uint16 *) V; + uint8 *im = _v + 2; + uint16 *cp = (uint16 *) _v; int bpl; - if (V) { // 2nd pass - fill the hide table - for (i = 0; i < H; i++) { - B[i].skip = 0xFFFF; - B[i].hide = 0x0000; + if (_v) { // 2nd pass - fill the hide table + for (i = 0; i < _h; i++) { + _b[i].skip = 0xFFFF; + _b[i].hide = 0x0000; } } for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane - uint8 *bm = M; + uint8 *bm = _m; bool skip = (bm[bpl] == TRANS); uint16 j; cnt = 0; - for (i = 0; i < H; i++) { // once per each line + for (i = 0; i < _h; i++) { // once per each line uint8 pix; - for (j = bpl; j < W; j += 4) { + for (j = bpl; j < _w; j += 4) { pix = bm[j]; - if (V && pix != TRANS) { - if (j < B[i].skip) - B[i].skip = j; + if (_v && pix != TRANS) { + if (j < _b[i].skip) + _b[i].skip = j; - if (j >= B[i].hide) - B[i].hide = j + 1; + if (j >= _b[i].hide) + _b[i].hide = j + 1; } if ((pix == TRANS) != skip || cnt >= 0x3FF0) { // end of block cnt |= (skip) ? SKP : CPY; - if (V) + if (_v) *cp = cnt; // store block description uint16 cp = (uint16 *) im; @@ -241,20 +241,20 @@ BMP_PTR BITMAP::Code(void) { cnt = 0; } if (! skip) { - if (V) + if (_v) *im = pix; ++ im; } ++ cnt; } - bm += W; - if (W < SCR_WID) { + bm += _w; + if (_w < SCR_WID) { if (skip) { cnt += (SCR_WID - j + 3) / 4; } else { cnt |= CPY; - if (V) + if (_v) *cp = cnt; cp = (uint16 *) im; @@ -266,37 +266,37 @@ BMP_PTR BITMAP::Code(void) { } if (cnt && ! skip) { cnt |= CPY; - if (V) + if (_v) *cp = cnt; cp = (uint16 *) im; im += 2; } - if (V) + if (_v) *cp = EOI; cp = (uint16 *) im; im += 2; } - if (V) + if (_v) break; - uint16 sizV = (uint16)(im - 2 - V); - V = farnew(uint8, sizV + H * sizeof(*B)); - if (! V) + uint16 sizV = (uint16)(im - 2 - _v); + _v = farnew(uint8, sizV + _h * sizeof(*_b)); + if (!_v) error("No core"); - B = (HideDesc *)(V + sizV); + _b = (HideDesc *)(_v + sizV); } cnt = 0; - for (i = 0; i < H; i++) { - if (B[i].skip == 0xFFFF) { // whole line is skipped - B[i].skip = (cnt + SCR_WID) >> 2; + for (i = 0; i < _h; i++) { + if (_b[i].skip == 0xFFFF) { // whole line is skipped + _b[i].skip = (cnt + SCR_WID) >> 2; cnt = 0; } else { - uint16 s = B[i].skip & ~3; - uint16 h = (B[i].hide + 3) & ~3; - B[i].skip = (cnt + s) >> 2; - B[i].hide = (h - s) >> 2; + uint16 s = _b[i].skip & ~3; + uint16 h = (_b[i].hide + 3) & ~3; + _b[i].skip = (cnt + s) >> 2; + _b[i].hide = (h - s) >> 2; cnt = SCR_WID - h; } } @@ -305,14 +305,14 @@ BMP_PTR BITMAP::Code(void) { } -bool BITMAP::SolidAt(int x, int y) { +bool Bitmap::SolidAt(int x, int y) { uint8 *m; uint16 r, n, n0; - if ((x >= W) || (y >= H)) + if ((x >= _w) || (y >= _h)) return false; - m = V; + m = _v; r = x % 4; n0 = (SCR_WID * y + x) / 4, n = 0; @@ -326,7 +326,7 @@ bool BITMAP::SolidAt(int x, int y) { switch (t) { case EOI : - -- r; + r--; case SKP : w = 0; break; @@ -366,9 +366,9 @@ bool BITMAP::SolidAt(int x, int y) { } -bool BITMAP::VBMSave(XFILE *f) { +bool Bitmap::VBMSave(XFILE *f) { uint16 p = (Pal != NULL), - n = ((uint16)(((uint8 *)B) - V)) + H * sizeof(HideDesc); + n = ((uint16)(((uint8 *)_b) - _v)) + _h * sizeof(HideDesc); if (f->Error == 0) f->Write((uint8 *)&p, sizeof(p)); @@ -376,23 +376,23 @@ bool BITMAP::VBMSave(XFILE *f) { f->Write((uint8 *)&n, sizeof(n)); if (f->Error == 0) - f->Write((uint8 *)&W, sizeof(W)); + f->Write((uint8 *)&_w, sizeof(_w)); if (f->Error == 0) - f->Write((uint8 *)&H, sizeof(H)); + f->Write((uint8 *)&_h, sizeof(_h)); if (f->Error == 0) if (p) f->Write((uint8 *)Pal, 256 * 3); if (f->Error == 0) - f->Write(V, n); + f->Write(_v, n); return (f->Error == 0); } -bool BITMAP::VBMLoad(XFILE *f) { +bool Bitmap::VBMLoad(XFILE *f) { uint16 p = 0, n = 0; if (f->Error == 0) f->Read((uint8 *)&p, sizeof(p)); @@ -401,10 +401,10 @@ bool BITMAP::VBMLoad(XFILE *f) { f->Read((uint8 *)&n, sizeof(n)); if (f->Error == 0) - f->Read((uint8 *)&W, sizeof(W)); + f->Read((uint8 *)&_w, sizeof(_w)); if (f->Error == 0) - f->Read((uint8 *)&H, sizeof(H)); + f->Read((uint8 *)&_h, sizeof(_h)); if (f->Error == 0) { if (p) { @@ -416,17 +416,17 @@ bool BITMAP::VBMLoad(XFILE *f) { f->Seek(f->Mark() + PAL_SIZ); } } - if ((V = farnew(uint8, n)) == NULL) + if ((_v = farnew(uint8, n)) == NULL) return false; if (f->Error == 0) - f->Read(V, n); + f->Read(_v, n); - B = (HideDesc *)(V + n - H * sizeof(HideDesc)); + _b = (HideDesc *)(_v + n - _h * sizeof(HideDesc)); return (f->Error == 0); } -bool BITMAP::BMPLoad (XFILE * f) { +bool Bitmap::BMPLoad (XFILE * f) { struct { char BM[2]; union { int16 len; int32 len_; }; @@ -459,13 +459,13 @@ bool BITMAP::BMPLoad (XFILE * f) { } Pal = NULL; } - H = hea.hig; - W = hea.wid; - if ((M = farnew(byte, H * W)) != NULL) { + _h = hea.hig; + _w = hea.wid; + if ((_m = farnew(byte, _h * _w)) != NULL) { int16 r = (4 - (hea.wid & 3)) % 4; byte buf[3]; int i; - for (i = H-1; i >= 0; i --) { - f->Read(M + (W * i), W); + for (i = _h - 1; i >= 0; i--) { + f->Read(_m + (_w * i), _w); if (r && f->Error == 0) f->Read(buf, r); if (f->Error) diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index e114760e2ae..cfa7830f390 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -59,25 +59,28 @@ struct HideDesc { #include "common/pack-end.h" -class BITMAP { +class Bitmap { bool BMPLoad(XFILE *f); bool VBMLoad(XFILE *f); public: static DAC *Pal; - uint16 W, H; - uint8 *M, * V; - HideDesc *B; - BITMAP(const char *fname, bool rem = true); - BITMAP(uint16 w, uint16 h, uint8 *map); - BITMAP(uint16 w, uint16 h, uint8 fill); - BITMAP(const BITMAP &bmp); - ~BITMAP(void); + uint16 _w; + uint16 _h; + uint8 *_m; + uint8 *_v; + HideDesc *_b; + + Bitmap(const char *fname, bool rem = true); + Bitmap(uint16 w, uint16 h, uint8 *map); + Bitmap(uint16 w, uint16 h, uint8 fill); + Bitmap(const Bitmap &bmp); + ~Bitmap(void); static void init(); static void deinit(); - BITMAP *FlipH(void); - BITMAP *Code(); - BITMAP &operator = (const BITMAP &bmp); + Bitmap *FlipH(void); + Bitmap *Code(); + Bitmap &operator = (const Bitmap &bmp); void Hide(int x, int y); void Show(int x, int y); void XShow(int x, int y); @@ -87,7 +90,7 @@ public: }; -typedef BITMAP *BMP_PTR; +typedef Bitmap *BMP_PTR; } // End of namespace CGE diff --git a/engines/cge/bitmaps.h b/engines/cge/bitmaps.h index 5ac878de3cf..40b1158b21e 100644 --- a/engines/cge/bitmaps.h +++ b/engines/cge/bitmaps.h @@ -32,12 +32,12 @@ namespace CGE { -extern BITMAP *MB[]; -extern BITMAP *HL[]; -extern BITMAP *MC[]; -extern BITMAP *PR[]; -extern BITMAP *SP[]; -extern BITMAP *LI[]; +extern Bitmap *MB[]; +extern Bitmap *HL[]; +extern Bitmap *MC[]; +extern Bitmap *PR[]; +extern Bitmap *SP[]; +extern Bitmap *LI[]; } // End of namespace CGE diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 07638ebdd84..885aa4d4924 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -57,7 +57,7 @@ void CGEEngine::setup() { // Initialise classes that have static members VGA::init(); VFILE::init(); - BITMAP::init(); + Bitmap::init(); TALK::init(); // Initialise engine objects @@ -77,22 +77,22 @@ void CGEEngine::setup() { InfoLine = new INFO_LINE(this, INFO_W); _cavLight = new Sprite(this, PR); DebugLine = new INFO_LINE(this, SCR_WID); - MB[0] = new BITMAP("BRICK"); + MB[0] = new Bitmap("BRICK"); MB[1] = NULL; - HL[0] = new BITMAP("HLINE"); + HL[0] = new Bitmap("HLINE"); HL[1] = NULL; - MC[0] = new BITMAP("MOUSE"); - MC[1] = new BITMAP("DUMMY"); + MC[0] = new Bitmap("MOUSE"); + MC[1] = new Bitmap("DUMMY"); MC[2] = NULL; - PR[0] = new BITMAP("PRESS"); + PR[0] = new Bitmap("PRESS"); PR[1] = NULL; - SP[0] = new BITMAP("SPK_L"); - SP[1] = new BITMAP("SPK_R"); + SP[0] = new Bitmap("SPK_L"); + SP[1] = new Bitmap("SPK_R"); SP[2] = NULL; - LI[0] = new BITMAP("LITE0"); - LI[1] = new BITMAP("LITE1"); - LI[2] = new BITMAP("LITE2"); - LI[3] = new BITMAP("LITE3"); + LI[0] = new Bitmap("LITE0"); + LI[1] = new Bitmap("LITE1"); + LI[2] = new Bitmap("LITE2"); + LI[3] = new Bitmap("LITE3"); LI[4] = NULL; Snail = new SNAIL(this, false); Snail_ = new SNAIL(this, true); @@ -105,7 +105,7 @@ CGEEngine::~CGEEngine() { // Call classes with static members to clear them up TALK::deinit(); - BITMAP::deinit(); + Bitmap::deinit(); VFILE::deinit(); VGA::deinit(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index e5294c0c148..1e1b952f777 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -281,7 +281,7 @@ void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { if (n != sizeof(S)) break; - S.Prev = S.Next = NULL; + S._prev = S._next = NULL; spr = (scumm_stricmp(S.File + 2, "MUCHA") == 0) ? new FLY(this, NULL) : new Sprite(this, NULL); if (spr == NULL) @@ -325,7 +325,7 @@ static void SaveGame(XFILE &file) { file.Write((uint8 *) & (i = SVGCHKSUM), sizeof(i)); - for (spr = Vga->SpareQ->First(); spr; spr = spr->Next) + for (spr = Vga->SpareQ->First(); spr; spr = spr->_next) if (spr->_ref >= 1000) if (!file.Error) file.Write((uint8 *)spr, sizeof(*spr)); @@ -393,29 +393,31 @@ WALK::WALK(CGEEngine *vm, BMP_PTR *shpl) void WALK::Tick(void) { - if (Flags.Hide) + if (_flags._hide) return; - Here = XZ(X + W / 2, Y + H); + Here = XZ(_x + _w / 2, _y + _h); if (Dir != NO_DIR) { Sprite *spr; Sys->FunTouch(); - for (spr = Vga->ShowQ->First(); spr; spr = spr->Next) { - if (Distance(spr) < 2) { - if (! spr->Flags.Near) { + for (spr = Vga->ShowQ->First(); spr; spr = spr->_next) { + if (Distance(spr) < 2) { + if (!spr->_flags._near) { FeedSnail(spr, NEAR); - spr->Flags.Near = true; + spr->_flags._near = true; } - } else spr->Flags.Near = false; + } else { + spr->_flags._near = false; + } } } - if (Flags.Hold || TracePtr < 0) + if (_flags._hold || TracePtr < 0) Park(); else { if (Here == Trace[TracePtr]) { - if (-- TracePtr < 0) + if (--TracePtr < 0) Park(); } else { signed char dx, dz; @@ -425,13 +427,13 @@ void WALK::Tick(void) { } } Step(); - if ((Dir == WW && X <= 0) || - (Dir == EE && X + W >= SCR_WID) || - (Dir == SS && Y + W >= WORLD_HIG - 2)) + if ((Dir == WW && _x <= 0) || + (Dir == EE && _x + _w >= SCR_WID) || + (Dir == SS && _y + _w >= WORLD_HIG - 2)) Park(); else { signed char x; // dummy var - Here.Split(x, Z); // take current Z position + Here.Split(x, _z); // take current Z position SNPOST_(SNZTRIM, -1, 0, this); // update Hero's pos in show queue } } @@ -439,15 +441,15 @@ void WALK::Tick(void) { int WALK::Distance(Sprite *spr) { int dx, dz; - dx = spr->X - (X + W - WALKSIDE); + dx = spr->_x - (_x + _w - WALKSIDE); if (dx < 0) - dx = (X + WALKSIDE) - (spr->X + spr->W); + dx = (_x + WALKSIDE) - (spr->_x + spr->_w); if (dx < 0) dx = 0; dx /= MAP_XGRID; - dz = spr->Z - Z; + dz = spr->_z - _z; if (dz < 0) dz = - dz; @@ -469,8 +471,8 @@ void WALK::Turn(DIR d) { void WALK::Park(void) { - if (Time == 0) - ++Time; + if (_time == 0) + ++_time; if (Dir != NO_DIR) { Step(9 + 4 * Dir + Dir); @@ -507,11 +509,12 @@ void WALK::FindWay(CLUSTER c) { void WALK::FindWay(Sprite *spr) { if (spr && spr != this) { - int x = spr->X, z = spr->Z; - if (spr->Flags.East) - x += spr->W + W / 2 - WALKSIDE; + int x = spr->_x; + int z = spr->_z; + if (spr->_flags._east) + x += spr->_w + _w / 2 - WALKSIDE; else - x -= W / 2 - WALKSIDE; + x -= _w / 2 - WALKSIDE; FindWay(CLUSTER((x / MAP_XGRID), ((z < MAP_ZCNT - MAX_DISTANCE) ? (z + 1) : (z - 1)))); @@ -520,7 +523,7 @@ void WALK::FindWay(Sprite *spr) { bool WALK::Lower(Sprite *spr) { - return (spr->Y > Y + (H * 3) / 5); + return (spr->_y > _y + (_h * 3) / 5); } @@ -528,7 +531,7 @@ void WALK::Reach(Sprite *spr, int mode) { if (spr) { Hero->FindWay(spr); if (mode < 0) { - mode = spr->Flags.East; + mode = spr->_flags._east; if (Lower(spr)) mode += 2; } @@ -556,15 +559,15 @@ private: SQUARE::SQUARE(CGEEngine *vm) : Sprite(vm, MB), _vm(vm) { - Flags.Kill = true; - Flags.BDel = false; + _flags._kill = true; + _flags._bDel = false; } void SQUARE::Touch(uint16 mask, int x, int y) { Sprite::Touch(mask, x, y); if (mask & L_UP) { - XZ(X + x, Y + y).Cell() = 0; + XZ(_x + x, _y + y).Cell() = 0; SNPOST_(SNKILL, -1, 0, this); } } @@ -610,7 +613,7 @@ void CGEEngine::Quit() { { NULL, &CGEEngine::dummy } }; - if (Snail->Idle() && ! Hero->Flags.Hide) { + if (Snail->Idle() && ! Hero->_flags._hide) { if (VMENU::Addr) { SNPOST_(SNKILL, -1, 0, VMENU::Addr); ResetQSwitch(); @@ -632,14 +635,14 @@ static void AltCtrlDel(void) { // Used in stubbed function, do not remove! static void MiniStep(int stp) { if (stp < 0) - _miniCave->Flags.Hide = true; + _miniCave->_flags._hide = true; else { &*Mini; *MiniShp[0] = *MiniShpList[stp]; if (Fx.Current) &*(Fx.Current->EAddr()); - _miniCave->Flags.Hide = false; + _miniCave->_flags._hide = false; } } @@ -672,9 +675,9 @@ void SYSTEM::FunTouch(void) { static void ShowBak(int ref) { Sprite *spr = Vga->SpareQ->Locate(ref); if (spr) { - BITMAP::Pal = VGA::SysPal; + Bitmap::Pal = VGA::SysPal; spr->Expand(); - BITMAP::Pal = NULL; + Bitmap::Pal = NULL; spr->Show(2); Vga->CopyPage(1, 2); Sys->SetPal(); @@ -693,10 +696,10 @@ static void CaveUp(void) { Text->Preload(BakRef, BakRef + 1000); Sprite *spr = Vga->SpareQ->First(); while (spr) { - Sprite *n = spr->Next; + Sprite *n = spr->_next; if (spr->_cave == Now || spr->_cave == 0) if (spr->_ref != BakRef) { - if (spr->Flags.Back) + if (spr->_flags._back) spr->BackShow(); else ExpandSprite(spr); @@ -711,11 +714,11 @@ static void CaveUp(void) { } if (Hero) { - Hero->Goto(HeroXY[Now - 1].X, HeroXY[Now - 1].Y); + Hero->Goto(HeroXY[Now - 1]._x, HeroXY[Now - 1]._y); // following 2 lines trims Hero's Z position! Hero->Tick(); - Hero->Time = 1; - Hero->Flags.Hide = false; + Hero->_time = 1; + Hero->_flags._hide = false; } if (! Dark) @@ -730,7 +733,7 @@ static void CaveUp(void) { Vga->ShowQ->Remove(_shadow); _shadow->MakeXlat(Glass(VGA::SysPal, 204, 204, 204)); Vga->ShowQ->Insert(_shadow, Hero); - _shadow->Z = Hero->Z; + _shadow->_z = Hero->_z; } FeedSnail(Vga->ShowQ->Locate(BakRef + 999), TAKE); Vga->Show(); @@ -747,11 +750,11 @@ static void CaveUp(void) { void CGEEngine::CaveDown() { Sprite *spr; - if (!_horzLine->Flags.Hide) + if (!_horzLine->_flags._hide) SwitchMapping(); for (spr = Vga->ShowQ->First(); spr;) { - Sprite *n = spr->Next; + Sprite *n = spr->_next; if (spr->_ref >= 1000 /*&& spr->_cave*/) { if (spr->_ref % 1000 == 999) FeedSnail(spr, TAKE); @@ -844,7 +847,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { Sprite *m = Vga->ShowQ->Locate(17001); if (m) { m->Step(1); - m->Time = 216; // 3s + m->_time = 216; // 3s } } break; @@ -909,7 +912,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { _sprite->Step(x - '0'); break; case F10 : - if (Snail->Idle() && ! Hero->Flags.Hide) + if (Snail->Idle() && ! Hero->_flags._hide) _vm->StartCountDown(); break; case 'J': @@ -957,7 +960,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { if (cav && Snail->Idle() && Hero->TracePtr < 0) _vm->SwitchCave(cav); - if (!_horzLine->Flags.Hide) { + if (!_horzLine->_flags._hide) { if (y >= MAP_TOP && y < MAP_TOP + MAP_HIG) { int8 x1, z1; XZ(x, y).Split(x1, z1); @@ -985,7 +988,7 @@ void SYSTEM::Tick(void) { else if (STARTUP::Core >= CORE_MID) { int n = new_random(100); if (n > 96) - HeroCover(6 + (Hero->X + Hero->W / 2 < SCR_WID / 2)); + HeroCover(6 + (Hero->_x + Hero->_w / 2 < SCR_WID / 2)); else { if (n > 90) HeroCover(5); @@ -1000,7 +1003,7 @@ void SYSTEM::Tick(void) { } FunTouch(); } - Time = SYSTIMERATE; + _time = SYSTIMERATE; } @@ -1070,8 +1073,8 @@ void CGEEngine::TakeName() { if (tn) { tn->SetName(Text->getText(GETNAME_TITLE)); tn->Center(); - tn->Goto(tn->X, tn->Y - 10); - tn->Z = 126; + tn->Goto(tn->_x, tn->_y - 10); + tn->_z = 126; Vga->ShowQ->Insert(tn); } } @@ -1079,7 +1082,7 @@ void CGEEngine::TakeName() { void CGEEngine::SwitchMapping() { - if (_horzLine->Flags.Hide) { + if (_horzLine->_flags._hide) { int i; for (i = 0; i < MAP_ZCNT; i++) { int j; @@ -1090,28 +1093,28 @@ void CGEEngine::SwitchMapping() { } } else { Sprite *s; - for (s = Vga->ShowQ->First(); s; s = s->Next) - if (s->W == MAP_XGRID && s->H == MAP_ZGRID) + for (s = Vga->ShowQ->First(); s; s = s->_next) + if (s->_w == MAP_XGRID && s->_h == MAP_ZGRID) SNPOST_(SNKILL, -1, 0, s); } - _horzLine->Flags.Hide = !_horzLine->Flags.Hide; + _horzLine->_flags._hide = !_horzLine->_flags._hide; } static void KillSprite(void) { - _sprite->Flags.Kill = true; - _sprite->Flags.BDel = true; + _sprite->_flags._kill = true; + _sprite->_flags._bDel = true; SNPOST_(SNKILL, -1, 0, _sprite); _sprite = NULL; } static void PushSprite(void) { - Sprite *spr = _sprite->Prev; + Sprite *spr = _sprite->_prev; if (spr) { Vga->ShowQ->Insert(Vga->ShowQ->Remove(_sprite), spr); - while (_sprite->Z > _sprite->Next->Z) - --_sprite->Z; + while (_sprite->_z > _sprite->_next->_z) + _sprite->_z--; } else SNPOST_(SNSOUND, -1, 2, NULL); } @@ -1119,17 +1122,17 @@ static void PushSprite(void) { static void PullSprite(void) { bool ok = false; - Sprite *spr = _sprite->Next; + Sprite *spr = _sprite->_next; if (spr) { - spr = spr->Next; + spr = spr->_next; if (spr) - ok = (!spr->Flags.Slav); + ok = (!spr->_flags._slav); } if (ok) { Vga->ShowQ->Insert(Vga->ShowQ->Remove(_sprite), spr); - if (_sprite->Prev) - while (_sprite->Z < _sprite->Prev->Z) - ++_sprite->Z; + if (_sprite->_prev) + while (_sprite->_z < _sprite->_prev->_z) + _sprite->_z++; } else SNPOST_(SNSOUND, -1, 2, NULL); } @@ -1151,8 +1154,8 @@ static void SaveMapping(void) { { IOHAND cf(ProgName(".HXY"), WRI); if (!cf.Error) { - HeroXY[Now - 1].X = Hero->X; - HeroXY[Now - 1].Y = Hero->Y; + HeroXY[Now - 1]._x = Hero->_x; + HeroXY[Now - 1]._y = Hero->_y; cf.Write((uint8 *) HeroXY, sizeof(HeroXY)); } } @@ -1180,7 +1183,7 @@ static char DebugText[] = " N=00000 F=000000 X=000 Y=000 FPS=0000\0S=00:00 0 #define SP__ (DebugText + 70) static void SayDebug(void) { - if (!DebugLine->Flags.Hide) { + if (!DebugLine->_flags._hide) { static long t = -1L; long t1 = Timer(); @@ -1192,25 +1195,25 @@ static void SayDebug(void) { t = t1; } - dwtom(Mouse->X, ABSX, 10, 3); - dwtom(Mouse->Y, ABSY, 10, 3); + dwtom(Mouse->_x, ABSX, 10, 3); + dwtom(Mouse->_y, ABSY, 10, 3); // dwtom(coreleft(), NFRE, 10, 5); // dwtom(farcoreleft(), FFRE, 10, 6); // sprite queue size uint16 n = 0; Sprite *spr; - for (spr = Vga->ShowQ->First(); spr; spr = spr->Next) { + for (spr = Vga->ShowQ->First(); spr; spr = spr->_next) { ++ n; if (spr == _sprite) { *XSPR = ' '; dwtom(n, SP_N, 10, 2); - dwtom(_sprite->X, SP_X, 10, 3); - dwtom(_sprite->Y, SP_Y, 10, 3); - dwtom(_sprite->Z, SP_Z, 10, 3); - dwtom(_sprite->W, SP_W, 10, 3); - dwtom(_sprite->H, SP_H, 10, 3); - dwtom(*(uint16 *)(&_sprite->Flags), SP_F, 16, 2); + dwtom(_sprite->_x, SP_X, 10, 3); + dwtom(_sprite->_y, SP_Y, 10, 3); + dwtom(_sprite->_z, SP_Z, 10, 3); + dwtom(_sprite->_w, SP_W, 10, 3); + dwtom(_sprite->_h, SP_H, 10, 3); + dwtom(*(uint16 *)(&_sprite->_flags), SP_F, 16, 2); } } dwtom(n, SP_S, 10, 2); @@ -1221,7 +1224,7 @@ static void SayDebug(void) { static void SwitchDebug(void) { - DebugLine->Flags.Hide = ! DebugLine->Flags.Hide; + DebugLine->_flags._hide = ! DebugLine->_flags._hide; } @@ -1259,16 +1262,16 @@ void Sprite::Touch(uint16 mask, int x, int y) { _vm->OptionTouch(_ref % 10, mask); return; } - if (Flags.Syst) + if (_flags._syst) return; // cannot access system sprites if (Game) if (mask & L_UP) { mask &= ~L_UP; mask |= R_UP; } if ((mask & R_UP) && Snail->Idle()) { - Sprite *ps = (_pocLight->SeqPtr) ? _pocket[PocPtr] : NULL; + Sprite *ps = (_pocLight->_seqPtr) ? _pocket[PocPtr] : NULL; if (ps) { - if (Flags.Kept || Hero->Distance(this) < MAX_DISTANCE) { + if (_flags._kept || Hero->Distance(this) < MAX_DISTANCE) { if (Works(ps)) { FeedSnail(ps, TAKE); } else @@ -1277,18 +1280,18 @@ void Sprite::Touch(uint16 mask, int x, int y) { } else TooFar(); } else { - if (Flags.Kept) + if (_flags._kept) mask |= L_UP; else { if (Hero->Distance(this) < MAX_DISTANCE) { /// - if (Flags.Port) { + if (_flags._port) { if (FindPocket(NULL) < 0) PocFul(); else { SNPOST(SNREACH, -1, -1, this); SNPOST(SNKEEP, -1, -1, this); - Flags.Port = false; + _flags._port = false; } } else { if (TakePtr != NO_PTR) { @@ -1306,7 +1309,7 @@ void Sprite::Touch(uint16 mask, int x, int y) { } } if ((mask & L_UP) && Snail->Idle()) { - if (Flags.Kept) { + if (_flags._kept) { int n; for (n = 0; n < POCKET_NX; n++) { if (_pocket[n] == this) { @@ -1456,12 +1459,12 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int if (_sprite) { _sprite->_ref = ref; _sprite->_cave = cav; - _sprite->Z = pos; - _sprite->Flags.East = east; - _sprite->Flags.Port = port; - _sprite->Flags.Tran = tran; - _sprite->Flags.Kill = true; - _sprite->Flags.BDel = true; + _sprite->_z = pos; + _sprite->_flags._east = east; + _sprite->_flags._port = port; + _sprite->_flags._tran = tran; + _sprite->_flags._kill = true; + _sprite->_flags._bDel = true; // Extract the filename, without the extension strcpy(_sprite->File, fname); @@ -1469,7 +1472,7 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int if (p) *p = '\0'; - _sprite->ShpCnt = shpcnt; + _sprite->_shpCnt = shpcnt; Vga->SpareQ->Append(_sprite); } } @@ -1528,7 +1531,7 @@ void CGEEngine::LoadScript(const char *fname) { _sprite = NULL; LoadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); if (_sprite && BkG) - _sprite->Flags.Back = true; + _sprite->_flags._back = true; } if (! ok) error("%s [%s]", NumStr("Bad INI line ######", lcnt), fname); @@ -1586,9 +1589,9 @@ void CGEEngine::RunGame() { Text->Preload(100, 1000); LoadHeroXY(); - _cavLight->Flags.Tran = true; + _cavLight->_flags._tran = true; Vga->ShowQ->Append(_cavLight); - _cavLight->Flags.Hide = true; + _cavLight->_flags._hide = true; static Seq pocSeq[] = { { 0, 0, 0, 0, 20 }, { 1, 2, 0, 0, 4 }, @@ -1599,9 +1602,9 @@ void CGEEngine::RunGame() { { 0, 1, 0, 0, 16 }, }; _pocLight->SetSeq(pocSeq); - _pocLight->Flags.Tran = true; - _pocLight->Time = 1; - _pocLight->Z = 120; + _pocLight->_flags._tran = true; + _pocLight->_time = 1; + _pocLight->_z = 120; Vga->ShowQ->Append(_pocLight); SelectPocket(-1); @@ -1626,9 +1629,9 @@ void CGEEngine::RunGame() { LoadSprite("MINI", -1, 0, MINI_X, MINI_Y); ExpandSprite(_miniCave = _sprite); // NULL is ok if (_miniCave) { - _miniCave->Flags.Hide = true; + _miniCave->_flags._hide = true; _miniCave->MoveShapes(ptr); - MiniShp[0] = new BITMAP(*_miniCave->Shp()); + MiniShp[0] = new Bitmap(*_miniCave->Shp()); MiniShpList = _miniCave->SetShapeList(MiniShp); PostMiniStep(-1); } @@ -1637,28 +1640,28 @@ void CGEEngine::RunGame() { if (Hero) { ExpandSprite(Hero); - Hero->Goto(HeroXY[Now - 1].X, HeroXY[Now - 1].Y); + Hero->Goto(HeroXY[Now - 1]._x, HeroXY[Now - 1]._y); if (INI_FILE::Exist("00SHADOW.SPR")) { - LoadSprite("00SHADOW", -1, 0, Hero->X + 14, Hero->Y + 51); + LoadSprite("00SHADOW", -1, 0, Hero->_x + 14, Hero->_y + 51); if ((_shadow = _sprite) != NULL) { _shadow->_ref = 2; - _shadow->Flags.Tran = true; - Hero->Flags.Shad = true; + _shadow->_flags._tran = true; + Hero->_flags._shad = true; Vga->ShowQ->Insert(Vga->SpareQ->Remove(_shadow), Hero); } } } InfoLine->Goto(INFO_X, INFO_Y); - InfoLine->Flags.Tran = true; + InfoLine->_flags._tran = true; InfoLine->Update(NULL); Vga->ShowQ->Insert(InfoLine); - DebugLine->Z = 126; + DebugLine->_z = 126; Vga->ShowQ->Insert(DebugLine); - _horzLine->Y = MAP_TOP - (MAP_TOP > 0); - _horzLine->Z = 126; + _horzLine->_y = MAP_TOP - (MAP_TOP > 0); + _horzLine->_z = 126; Vga->ShowQ->Insert(_horzLine); Mouse->Busy = Vga->SpareQ->Locate(BUSY_REF); @@ -1719,14 +1722,14 @@ void CGEEngine::Movie(const char *ext) { bool CGEEngine::ShowTitle(const char *name) { - BITMAP::Pal = VGA::SysPal; - BMP_PTR LB[] = { new BITMAP(name), NULL }; - BITMAP::Pal = NULL; + Bitmap::Pal = VGA::SysPal; + BMP_PTR LB[] = { new Bitmap(name), NULL }; + Bitmap::Pal = NULL; bool usr_ok = false; Sprite D(this, LB); - D.Flags.Kill = true; - D.Flags.BDel = true; + D._flags._kill = true; + D._flags._bDel = true; D.Center(); D.Show(2); @@ -1846,8 +1849,8 @@ void CGEEngine::cge_main(void) { if (!SVG0FILE::Exist(SVG0NAME)) STARTUP::Mode = 2; - DebugLine->Flags.Hide = true; - _horzLine->Flags.Hide = true; + DebugLine->_flags._hide = true; + _horzLine->_flags._hide = true; //srand((uint16) Timer()); Sys = new SYSTEM(this); diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index a9d55957af4..26731432851 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -147,10 +147,10 @@ void CGEEngine::SelectSound() { if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); Inf(Text->getText(STYPE_TEXT)); - Talk->Goto(Talk->X, FONT_HIG / 2); + Talk->Goto(Talk->_x, FONT_HIG / 2); for (i = 0; i < ArrayCount(DevName); i++) DevMenu[i].Text = Text->getText(DevName[i]); - (new VMENU(this, DevMenu, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); + (new VMENU(this, DevMenu, SCR_WID / 2, Talk->_y + Talk->_h + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); } @@ -184,8 +184,8 @@ static int Hlp; void CGEEngine::SNSelect() { Inf(Text->getText(Hlp)); - Talk->Goto(Talk->X, FONT_HIG / 2); - (new VMENU(this, Cho, SCR_WID / 2, Talk->Y + Talk->H + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); + Talk->Goto(Talk->_x, FONT_HIG / 2); + (new VMENU(this, Cho, SCR_WID / 2, Talk->_y + Talk->_h + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); } diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index a5b82f1e8dd..87daced31e1 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -67,25 +67,25 @@ int FLY::L = 20, FLY::B = 100; -FLY::FLY(CGEEngine *vm, BITMAP **shpl) +FLY::FLY(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Tx(0), Ty(0), _vm(vm) { Step(new_random(2)); - Goto(L + new_random(R - L - W), T + new_random(B - T - H)); + Goto(L + new_random(R - L - _w), T + new_random(B - T - _h)); } void FLY::Tick(void) { Step(); - if (! Flags.Kept) { + if (!_flags._kept) { if (new_random(10) < 1) { Tx = new_random(3) - 1; Ty = new_random(3) - 1; } - if (X + Tx < L || X + Tx + W > R) + if (_x + Tx < L || _x + Tx + _w > R) Tx = -Tx; - if (Y + Ty < T || Y + Ty + H > B) + if (_y + Ty < T || _y + Ty + _h > B) Ty = -Ty; - Goto(X + Tx, Y + Ty); + Goto(_x + Tx, _y + Ty); } } diff --git a/engines/cge/game.h b/engines/cge/game.h index fb4dad6fae2..a64018aa58c 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -48,7 +48,7 @@ class FLY : public Sprite { static int L, T, R, B; public: int Tx, Ty; - FLY(CGEEngine *vm, BITMAP **shpl); + FLY(CGEEngine *vm, Bitmap **shpl); void Tick(void); private: CGEEngine *_vm; diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index f891b9c0928..e3c60b6e217 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -44,8 +44,8 @@ GET_TEXT::GET_TEXT(CGEEngine *vm, const char *info, char *text, int size, void ( Mode = RECT; TS[0] = Box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); SetShapeList(TS); - Flags.BDel = true; - Flags.Kill = true; + _flags._bDel = true; + _flags._kill = true; memcpy(Buff, text, Len); Buff[Len] = ' '; Buff[Len + 1] = '\0'; @@ -66,7 +66,7 @@ void GET_TEXT::Tick(void) { Cntr = 0; } PutLine(1, Buff); - Time = GTTIME; + _time = GTTIME; } @@ -107,7 +107,7 @@ void GET_TEXT::Touch(uint16 mask, int x, int y) { if (p) x = ogon[p - bezo]; } - if (Len < Size && 2 * TEXT_HM + _Font->Width(Buff) + _Font->Wid[x] <= W) { + if (Len < Size && 2 * TEXT_HM + _Font->Width(Buff) + _Font->Wid[x] <= _w) { Buff[Len + 2] = Buff[Len + 1]; Buff[Len + 1] = Buff[Len]; Buff[Len++] = x; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index c1f688babd0..7b9ce59f5ed 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -42,15 +42,15 @@ bool MIXER::Appear = false; MIXER::MIXER(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), Fall(MIX_FALL), _vm(vm) { Appear = true; - mb[0] = new BITMAP("VOLUME"); + mb[0] = new Bitmap("VOLUME"); mb[1] = NULL; SetShapeList(mb); SetName(Text->getText(MIX_NAME)); - Flags.Syst = true; - Flags.Kill = true; - Flags.BDel = true; + _flags._syst = true; + _flags._kill = true; + _flags._bDel = true; Goto(x, y); - Z = MIX_Z; + _z = MIX_Z; // slaves @@ -58,7 +58,7 @@ MIXER::MIXER(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), Fall(MIX_FALL), _v for (i = 0; i < MIX_MAX; i++) { static char fn[] = "V00"; wtom(i, fn + 1, 10, 2); - lb[i] = new BITMAP(fn); + lb[i] = new Bitmap(fn); ls[i].Now = ls[i].Next = i; ls[i].Dx = ls[i].Dy = ls[i].Dly = 0; } @@ -68,13 +68,13 @@ MIXER::MIXER(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), Fall(MIX_FALL), _v register Sprite *spr = new Sprite(_vm, lb); spr->SetSeq(ls); spr->Goto(x + 2 + 12 * i, y + 8); - spr->Flags.Tran = true; - spr->Flags.Kill = true; - spr->Flags.BDel = false; - spr->Z = MIX_Z; + spr->_flags._tran = true; + spr->_flags._kill = true; + spr->_flags._bDel = false; + spr->_z = MIX_Z; Led[i] = spr; } - Led[ArrayCount(Led) - 1]->Flags.BDel = true; + Led[ArrayCount(Led) - 1]->_flags._bDel = true; Vga->ShowQ->Insert(this); for (i = 0; i < ArrayCount(Led); i++) @@ -88,7 +88,7 @@ MIXER::MIXER(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), Fall(MIX_FALL), _v SNDDrvInfo.VOL4.DL = i; SNDDrvInfo.VOL4.DR = i; Update(); - Time = MIX_DELAY; + _time = MIX_DELAY; } MIXER::~MIXER(void) { @@ -100,11 +100,11 @@ MIXER::~MIXER(void) { void MIXER::Touch(uint16 mask, int x, int y) { Sprite::Touch(mask, x, y); if (mask & L_UP) { - uint8 *vol = (&SNDDrvInfo.VOL2.D) + (x < W / 2); + uint8 *vol = (&SNDDrvInfo.VOL2.D) + (x < _w / 2); if (y < MIX_BHIG) { if (*vol < 0xFF) *vol += 0x11; - } else if (y >= H - MIX_BHIG) { + } else if (y >= _h - MIX_BHIG) { if (*vol > 0x00) *vol -= 0x11; } @@ -114,12 +114,12 @@ void MIXER::Touch(uint16 mask, int x, int y) { void MIXER::Tick(void) { - int x = Mouse->X; - int y = Mouse->Y; + int x = Mouse->_x; + int y = Mouse->_y; if (SpriteAt(x, y) == this) { Fall = MIX_FALL; - if (Flags.Hold) - Touch(L_UP, x - X, y - Y); + if (_flags._hold) + Touch(L_UP, x - _x, y - _y); } else { if (Fall) --Fall; @@ -129,7 +129,7 @@ void MIXER::Tick(void) { SNPOST_(SNKILL, -1, 0, this); } } - Time = MIX_DELAY; + _time = MIX_DELAY; } diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index cb94e926c5a..5bdf7449fcc 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -31,7 +31,7 @@ namespace CGE { -EVENT Evt[EVT_MAX]; +Event Evt[EVT_MAX]; uint16 EvtHead = 0, EvtTail = 0; @@ -39,7 +39,7 @@ MOUSE_FUN *MOUSE::OldMouseFun = NULL; uint16 MOUSE::OldMouseMask = 0; -MOUSE::MOUSE(CGEEngine *vm, BITMAP **shpl) : Sprite(vm, shpl), Busy(NULL), Hold(NULL), hx(0), _vm(vm) { +MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold(NULL), hx(0), _vm(vm) { static Seq ms[] = { { 0, 0, 0, 0, 1 }, { 1, 1, 0, 0, 1 } @@ -136,8 +136,8 @@ void MOUSE::ClrEvt(Sprite *spr) { if (spr) { uint16 e; for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) - if (Evt[e].Ptr == spr) - Evt[e].Msk = 0; + if (Evt[e]._ptr == spr) + Evt[e]._msk = 0; } else EvtTail = EvtHead; } @@ -146,49 +146,49 @@ void MOUSE::ClrEvt(Sprite *spr) { void MOUSE::Tick(void) { Step(); while (EvtTail != EvtHead) { - EVENT e = Evt[EvtTail]; - if (e.Msk) { - if (Hold && e.Ptr != Hold) - Hold->Touch(e.Msk | ATTN, e.X - Hold->X, e.Y - Hold->Y); + Event e = Evt[EvtTail]; + if (e._msk) { + if (Hold && e._ptr != Hold) + Hold->Touch(e._msk | ATTN, e._x - Hold->_x, e._y - Hold->_y); // update mouse cursor position - if (e.Msk & ROLL) - Goto(e.X, e.Y); + if (e._msk & ROLL) + Goto(e._x, e._y); // activate current touched SPRITE - if (e.Ptr) { - if (e.Msk & KEYB) - e.Ptr->Touch(e.Msk, e.X, e.Y); + if (e._ptr) { + if (e._msk & KEYB) + e._ptr->Touch(e._msk, e._x, e._y); else - e.Ptr->Touch(e.Msk, e.X - e.Ptr->X, e.Y - e.Ptr->Y); + e._ptr->Touch(e._msk, e._x - e._ptr->_x, e._y - e._ptr->_y); } else if (Sys) - Sys->Touch(e.Msk, e.X, e.Y); + Sys->Touch(e._msk, e._x, e._y); - if (e.Msk & L_DN) { - Hold = e.Ptr; + if (e._msk & L_DN) { + Hold = e._ptr; if (Hold) { - Hold->Flags.Hold = true; - hx = e.X - Hold->X; - hy = e.Y - Hold->Y; + Hold->_flags._hold = true; + hx = e._x - Hold->_x; + hy = e._y - Hold->_y; } } - if (e.Msk & L_UP) { + if (e._msk & L_UP) { if (Hold) { - Hold->Flags.Hold = false; + Hold->_flags._hold = false; Hold = NULL; } } ///Touched = e.Ptr; // discard Text if button released - if (e.Msk & (L_UP | R_UP)) + if (e._msk & (L_UP | R_UP)) KillText(); } EvtTail = (EvtTail + 1) % EVT_MAX; } if (Hold) - Hold->Goto(X - hx, Y - hy); + Hold->Goto(_x - hx, _y - hy); } } // End of namespace CGE diff --git a/engines/cge/mouse.h b/engines/cge/mouse.h index 28152b7f29c..4d95f104236 100644 --- a/engines/cge/mouse.h +++ b/engines/cge/mouse.h @@ -45,13 +45,14 @@ namespace CGE { extern TALK *Talk; -struct EVENT { - uint16 Msk; - uint16 X, Y; - Sprite *Ptr; +struct Event { + uint16 _msk; + uint16 _x; + uint16 _y; + Sprite *_ptr; }; -extern EVENT Evt[EVT_MAX]; +extern Event Evt[EVT_MAX]; extern uint16 EvtHead, EvtTail; typedef void (MOUSE_FUN)(void); @@ -69,7 +70,7 @@ public: int Buttons; Sprite *Busy; //Sprite *Touched; - MOUSE(CGEEngine *vm, BITMAP **shpl = MC); + MOUSE(CGEEngine *vm, Bitmap **shpl = MC); ~MOUSE(); void On(); void Off(); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 50eed3f5620..565c7d33f05 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -75,7 +75,7 @@ static void SNGame(Sprite *spr, int num) { int buref = 0; int Stage = 0; - for (dup[0] = Vga->ShowQ->First(); dup[0]; dup[0] = dup[0]->Next) { + for (dup[0] = Vga->ShowQ->First(); dup[0]; dup[0] = dup[0]->_next) { buref = dup[0]->_ref; if (buref / 1000 == 16 && buref % 100 == 6) { Stage = (buref / 100) % 10; @@ -88,8 +88,8 @@ static void SNGame(Sprite *spr, int num) { } if (Game) { // continue game - int i = new_random(3), hand = (dup[0]->ShpCnt == 6); - ++ Stage; + int i = new_random(3), hand = (dup[0]->_shpCnt == 6); + Stage++; if (hand && Stage > DRESSED) ++hand; if (i >= 0 || (dup[i] == spr && new_random(3) == 0)) { @@ -188,7 +188,7 @@ static void SNGame(Sprite *spr, int num) { } ///-------------------- SNPOST(SNSETZ, 20700, 0, NULL); - bool hit = (k1->SeqPtr + k2->SeqPtr + k3->SeqPtr == 15); + bool hit = (k1->_seqPtr + k2->_seqPtr + k3->_seqPtr == 15); if (hit) { if (spr->_ref == 1) { SNPOST(SNSAY, 1, 20003, NULL); // hura! @@ -295,7 +295,7 @@ int FindPocket(Sprite *spr) { void SelectPocket(int n) { - if (n < 0 || (_pocLight->SeqPtr && PocPtr == n)) { + if (n < 0 || (_pocLight->_seqPtr && PocPtr == n)) { _pocLight->Step(0); n = FindPocket(NULL); if (n >= 0) @@ -325,10 +325,10 @@ void Hide1(Sprite *spr) { } -void SNGhost(BITMAP *bmp) { +void SNGhost(Bitmap *bmp) { // TODO : Get x and y from M but not using segment / offset - //bmp->Hide(FP_OFF(bmp->M), FP_SEG(bmp->M)); - bmp->M = NULL; + //bmp->Hide(FP_OFF(bmp->_m), FP_SEG(bmp->_m)); + bmp->_m = NULL; delete bmp; warning("STUB: SNGhost"); } @@ -509,10 +509,10 @@ static void SNZTrim(Sprite *spr) { bool en = _heart->_enable; Sprite *s; _heart->_enable = false; - s = (spr->Flags.Shad) ? spr->Prev : NULL; + s = (spr->_flags._shad) ? spr->_prev : NULL; Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr)); if (s) { - s->Z = spr->Z; + s->_z = spr->_z; Vga->ShowQ->Insert(Vga->ShowQ->Remove(s), spr); } _heart->_enable = en; @@ -522,9 +522,9 @@ static void SNZTrim(Sprite *spr) { static void SNHide(Sprite *spr, int val) { if (spr) { - spr->Flags.Hide = (val >= 0) ? (val != 0) : (! spr->Flags.Hide); - if (spr->Flags.Shad) - spr->Prev->Flags.Hide = spr->Flags.Hide; + spr->_flags._hide = (val >= 0) ? (val != 0) : (!spr->_flags._hide); + if (spr->_flags._shad) + spr->_prev->_flags._hide = spr->_flags._hide; } } @@ -553,7 +553,7 @@ void SNSeq(Sprite *spr, int val) { void SNRSeq(Sprite *spr, int val) { if (spr) - SNSeq(spr, spr->SeqPtr + val); + SNSeq(spr, spr->_seqPtr + val); } @@ -565,22 +565,22 @@ void SNSend(Sprite *spr, int val) { spr->_cave = val; if (val1 != was1) { if (was1) { - if (spr->Flags.Kept) { + if (spr->_flags._kept) { int n = FindPocket(spr); if (n >= 0) _pocket[n] = NULL; } Hide1(spr); ContractSprite(spr); - spr->Flags.Slav = false; + spr->_flags._slav = false; } else { if (spr->_ref % 1000 == 0) - BITMAP::Pal = VGA::SysPal; - if (spr->Flags.Back) + Bitmap::Pal = VGA::SysPal; + if (spr->_flags._back) spr->BackShow(true); else ExpandSprite(spr); - BITMAP::Pal = NULL; + Bitmap::Pal = NULL; } } } @@ -596,15 +596,15 @@ void SNSwap(Sprite *spr, int xref) { bool xwas1 = (xwas == 0 || xwas == Now); Swap(spr->_cave, xspr->_cave); - Swap(spr->X, xspr->X); - Swap(spr->Y, xspr->Y); - Swap(spr->Z, xspr->Z); - if (spr->Flags.Kept) { + Swap(spr->_x, xspr->_x); + Swap(spr->_y, xspr->_y); + Swap(spr->_z, xspr->_z); + if (spr->_flags._kept) { int n = FindPocket(spr); if (n >= 0) _pocket[n] = xspr; - xspr->Flags.Kept = true; - xspr->Flags.Port = false; + xspr->_flags._kept = true; + xspr->_flags._port = false; } if (xwas1 != was1) { if (was1) { @@ -625,14 +625,14 @@ void SNSwap(Sprite *spr, int xref) { void SNCover(Sprite *spr, int xref) { Sprite *xspr = Locate(xref); if (spr && xspr) { - spr->Flags.Hide = true; - xspr->Z = spr->Z; + spr->_flags._hide = true; + xspr->_z = spr->_z; xspr->_cave = spr->_cave; - xspr->Goto(spr->X, spr->Y); + xspr->Goto(spr->_x, spr->_y); ExpandSprite(xspr); - if ((xspr->Flags.Shad = spr->Flags.Shad) == 1) { - Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr->Prev), xspr); - spr->Flags.Shad = false; + if ((xspr->_flags._shad = spr->_flags._shad) == 1) { + Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr->_prev), xspr); + spr->_flags._shad = false; } FeedSnail(xspr, NEAR); } @@ -641,28 +641,28 @@ void SNCover(Sprite *spr, int xref) { void SNUncover(Sprite *spr, Sprite *xspr) { if (spr && xspr) { - spr->Flags.Hide = false; + spr->_flags._hide = false; spr->_cave = xspr->_cave; - spr->Goto(xspr->X, xspr->Y); - if ((spr->Flags.Shad = xspr->Flags.Shad) == 1) { - Vga->ShowQ->Insert(Vga->ShowQ->Remove(xspr->Prev), spr); - xspr->Flags.Shad = false; + spr->Goto(xspr->_x, xspr->_y); + if ((spr->_flags._shad = xspr->_flags._shad) == 1) { + Vga->ShowQ->Insert(Vga->ShowQ->Remove(xspr->_prev), spr); + xspr->_flags._shad = false; } - spr->Z = xspr->Z; + spr->_z = xspr->_z; SNSend(xspr, -1); - if (spr->Time == 0) - ++spr->Time; + if (spr->_time == 0) + ++spr->_time; } } void SNSetX0(int cav, int x0) { - HeroXY[cav - 1].X = x0; + HeroXY[cav - 1]._x = x0; } void SNSetY0(int cav, int y0) { - HeroXY[cav - 1].Y = y0; + HeroXY[cav - 1]._y = y0; } @@ -674,19 +674,19 @@ void SNSetXY(Sprite *spr, uint16 xy) { void SNRelX(Sprite *spr, int x) { if (spr && Hero) - spr->Goto(Hero->X + x, spr->Y); + spr->Goto(Hero->_x + x, spr->_y); } void SNRelY(Sprite *spr, int y) { if (spr && Hero) - spr->Goto(spr->X, Hero->Y + y); + spr->Goto(spr->_x, Hero->_y + y); } void SNRelZ(Sprite *spr, int z) { if (spr && Hero) { - spr->Z = Hero->Z + z; + spr->_z = Hero->_z + z; SNZTrim(spr); } } @@ -694,19 +694,19 @@ void SNRelZ(Sprite *spr, int z) { void SNSetX(Sprite *spr, int x) { if (spr) - spr->Goto(x, spr->Y); + spr->Goto(x, spr->_y); } void SNSetY(Sprite *spr, int y) { if (spr) - spr->Goto(spr->X, y); + spr->Goto(spr->_x, y); } void SNSetZ(Sprite *spr, int z) { if (spr) { - spr->Z = z; + spr->_z = z; //SNPOST_(SNZTRIM, -1, 0, spr); SNZTrim(spr); } @@ -718,9 +718,9 @@ void SNSlave(Sprite *spr, int ref) { if (spr && slv) { if (spr->Active()) { SNSend(slv, spr->_cave); - slv->Flags.Slav = true; - slv->Z = spr->Z; - Vga->ShowQ->Insert(Vga->ShowQ->Remove(slv), spr->Next); + slv->_flags._slav = true; + slv->_z = spr->_z; + Vga->ShowQ->Insert(Vga->ShowQ->Remove(slv), spr->_next); } } } @@ -728,36 +728,37 @@ void SNSlave(Sprite *spr, int ref) { void SNTrans(Sprite *spr, int trans) { if (spr) - spr->Flags.Tran = (trans < 0) ? !spr->Flags.Tran : (trans != 0); + spr->_flags._tran = (trans < 0) ? !spr->_flags._tran : (trans != 0); } void SNPort(Sprite *spr, int port) { if (spr) - spr->Flags.Port = (port < 0) ? !spr->Flags.Port : (port != 0); + spr->_flags._port = (port < 0) ? !spr->_flags._port : (port != 0); } void SNKill(Sprite *spr) { if (spr) { - if (spr->Flags.Kept) { + if (spr->_flags._kept) { int n = FindPocket(spr); if (n >= 0) _pocket[n] = NULL; } - Sprite *nx = spr->Next; + Sprite *nx = spr->_next; Hide1(spr); Vga->ShowQ->Remove(spr); MOUSE::ClrEvt(spr); - if (spr->Flags.Kill) + if (spr->_flags._kill) delete spr; else { spr->_cave = -1; Vga->SpareQ->Append(spr); } - if (nx) - if (nx->Flags.Slav) + if (nx) { + if (nx->_flags._slav) SNKill(nx); + } } } @@ -767,20 +768,20 @@ static void SNSound(Sprite *spr, int wav, int cnt) { if (wav == -1) Sound.Stop(); else - Sound.Play(Fx[wav], (spr) ? ((spr->X + spr->W / 2) / (SCR_WID / 16)) : 8, cnt); + Sound.Play(Fx[wav], (spr) ? ((spr->_x + spr->_w / 2) / (SCR_WID / 16)) : 8, cnt); } } void SNKeep(Sprite *spr, int stp) { SelectPocket(-1); - if (spr && ! spr->Flags.Kept && _pocket[PocPtr] == NULL) { + if (spr && ! spr->_flags._kept && _pocket[PocPtr] == NULL) { SNSound(spr, 3, 1); _pocket[PocPtr] = spr; spr->_cave = 0; - spr->Flags.Kept = true; - spr->Goto(POCKET_X + POCKET_DX * PocPtr + POCKET_DX / 2 - spr->W / 2, - POCKET_Y + POCKET_DY / 2 - spr->H / 2); + spr->_flags._kept = true; + spr->Goto(POCKET_X + POCKET_DX * PocPtr + POCKET_DX / 2 - spr->_w / 2, + POCKET_Y + POCKET_DY / 2 - spr->_h / 2); if (stp >= 0) spr->Step(stp); } @@ -794,7 +795,7 @@ void SNGive(Sprite *spr, int stp) { if (p >= 0) { _pocket[p] = NULL; spr->_cave = Now; - spr->Flags.Kept = false; + spr->_flags._kept = false; if (stp >= 0) spr->Step(stp); } @@ -828,7 +829,7 @@ static void SNLevel(Sprite *spr, int lev) { } MaxCave = maxcav[Lev]; if (spr) - spr->Flags.Hide = false; + spr->_flags._hide = false; } @@ -937,7 +938,7 @@ void SNAIL::RunCom(void) { if (sprel) { if (sprel->SeqTest(snc->Val) && (snc->Val >= 0 || sprel != Hero || Hero->TracePtr < 0)) { - _heart->setXTimer(&Pause, sprel->Time); + _heart->setXTimer(&Pause, sprel->_time); } else goto xit; } @@ -1111,13 +1112,13 @@ void SNAIL::RunCom(void) { SNZTrim(sprel); break; case SNGHOST : - SNGhost((BITMAP *) snc->Ptr); + SNGhost((Bitmap *) snc->Ptr); break; default : warning("Unhandled snc->Com in SNMouse(bool)"); break; } - ++Tail; + Tail++; if (!Turbo) break; } diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 9449a8081e1..e1df628d3bf 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -117,8 +117,8 @@ extern int MaxCave; extern int PocPtr; extern BAR Barriers[]; extern struct HXY { - int X; - int Y; + int _x; + int _y; } HeroXY[]; } // End of namespace CGE diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 43917732be6..5aa5e44b8d4 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -100,7 +100,7 @@ void FONT::Save(void) { TALK::TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode) : Sprite(vm, NULL), Mode(mode), _vm(vm) { TS[0] = TS[1] = NULL; - Flags.Syst = true; + _flags._syst = true; Update(tx); } @@ -108,7 +108,7 @@ TALK::TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode) TALK::TALK(CGEEngine *vm) : Sprite(vm, NULL), Mode(PURE), _vm(vm) { TS[0] = TS[1] = NULL; - Flags.Syst = true; + _flags._syst = true; } @@ -158,11 +158,11 @@ void TALK::Update(const char *tx) { TS[0] = Box(mw, mh); } - m = TS[0]->M + ln * mw + hmarg; + m = TS[0]->_m + ln * mw + hmarg; while (* tx) { if (*tx == '|' || *tx == '\n') - m = TS[0]->M + (ln += FONT_HIG + TEXT_LS) * mw + hmarg; + m = TS[0]->_m + (ln += FONT_HIG + TEXT_LS) * mw + hmarg; else { int cw = _Font->Wid[*tx], i; uint8 *f = _Font->Map + _Font->Pos[*tx]; @@ -176,10 +176,10 @@ void TALK::Update(const char *tx) { b >>= 1; pp += mw; } - ++m; + m++; } } - ++tx; + tx++; } TS[0]->Code(); SetShapeList(TS); @@ -188,7 +188,7 @@ void TALK::Update(const char *tx) { -BITMAP *TALK::Box(uint16 w, uint16 h) { +Bitmap *TALK::Box(uint16 w, uint16 h) { uint8 *b, * p, * q; uint16 n, r = (Mode == ROUND) ? TEXT_RD : 0; @@ -228,14 +228,14 @@ BITMAP *TALK::Box(uint16 w, uint16 h) { q -= w; } } - return new BITMAP(w, h, b); + return new Bitmap(w, h, b); } void TALK::PutLine(int line, const char *text) { // Note: (TS[0].W % 4) have to be 0 - uint16 w = TS[0]->W, h = TS[0]->H; - uint8 *v = TS[0]->V, * p; + uint16 w = TS[0]->_w, h = TS[0]->_h; + uint8 *v = TS[0]->_v, * p; uint16 dsiz = w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap uint16 psiz = h * lsiz; // - last gap, but + plane trailer @@ -278,22 +278,22 @@ void TALK::PutLine(int line, const char *text) { if (p >= q) p = p - size + 1; } - ++text; + text++; } } } INFO_LINE::INFO_LINE(CGEEngine *vm, uint16 w) : TALK(vm), OldTxt(NULL), _vm(vm) { - TS[0] = new BITMAP(w, FONT_HIG, TEXT_BG); + TS[0] = new Bitmap(w, FONT_HIG, TEXT_BG); SetShapeList(TS); } void INFO_LINE::Update(const char *tx) { if (tx != OldTxt) { - uint16 w = TS[0]->W, h = TS[0]->H; - uint8 *v = (uint8 *) TS[0]->V; + uint16 w = TS[0]->_w, h = TS[0]->_h; + uint8 *v = (uint8 *) TS[0]->_v; uint16 dsiz = w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap uint16 psiz = h * lsiz; // - last gape, but + plane trailer @@ -324,7 +324,7 @@ void INFO_LINE::Update(const char *tx) { if (p >= q) p = p - size + 1; } - ++tx; + tx++; } } OldTxt = tx; diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 2a38af91d10..60f7f213d47 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -71,8 +71,8 @@ enum TBOX_STYLE { PURE, RECT, ROUND }; class TALK : public Sprite { protected: TBOX_STYLE Mode; - BITMAP *TS[2]; - BITMAP *Box(uint16 w, uint16 h); + Bitmap *TS[2]; + Bitmap *Box(uint16 w, uint16 h); public: TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode = PURE); TALK(CGEEngine *vm); diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 74ff6fac2dd..7b191b492b3 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -184,11 +184,11 @@ void TEXT::Say(const char *txt, Sprite *spr) { KillText(); Talk = new TALK(_vm, txt, ROUND); if (Talk) { - bool east = spr->Flags.East; - int x = (east) ? (spr->X + spr->W - 2) : (spr->X + 2); - int y = spr->Y + 2; + bool east = spr->_flags._east; + int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2); + int y = spr->_y + 2; Sprite *spike = new Sprite(_vm, SP); - uint16 sw = spike->W; + uint16 sw = spike->_w; if (east) { if (x + sw + TEXT_RD + 5 >= SCR_WID) @@ -197,21 +197,21 @@ void TEXT::Say(const char *txt, Sprite *spr) { if (x <= 5 + TEXT_RD + sw) east = true; } - x = (east) ? (spr->X + spr->W - 2) : (spr->X + 2 - sw); + x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2 - sw); if (spr->_ref == 1) x += ((east) ? -10 : 10); // Hero - Talk->Flags.Kill = true; - Talk->Flags.BDel = true; + Talk->_flags._kill = true; + Talk->_flags._bDel = true; Talk->SetName(Text->getText(SAY_NAME)); - Talk->Goto(x - (Talk->W - sw) / 2 - 3 + 6 * east, y - spike->H - Talk->H + 1); - Talk->Z = 125; + Talk->Goto(x - (Talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - Talk->_h + 1); + Talk->_z = 125; Talk->_ref = SAY_REF; - spike->Goto(x, Talk->Y + Talk->H - 1); - spike->Z = 126; - spike->Flags.Slav = true; - spike->Flags.Kill = true; + spike->Goto(x, Talk->_y + Talk->_h - 1); + spike->_z = 126; + spike->_flags._slav = true; + spike->_flags._kill = true; spike->SetName(Text->getText(SAY_NAME)); spike->Step(east); spike->_ref = SAY_REF; @@ -225,12 +225,12 @@ void CGEEngine::Inf(const char *txt) { KillText(); Talk = new TALK(this, txt, RECT); if (Talk) { - Talk->Flags.Kill = true; - Talk->Flags.BDel = true; + Talk->_flags._kill = true; + Talk->_flags._bDel = true; Talk->SetName(Text->getText(INF_NAME)); Talk->Center(); - Talk->Goto(Talk->X, Talk->Y - 20); - Talk->Z = 126; + Talk->Goto(Talk->_x, Talk->_y - 20); + Talk->_z = 126; Talk->_ref = INF_REF; Vga->ShowQ->Insert(Talk, Vga->ShowQ->Last()); } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 56960389c8e..673d6036d82 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -356,11 +356,11 @@ void Heart::setXTimer(uint16 *ptr, uint16 time) { Sprite::Sprite(CGEEngine *vm, BMP_PTR *shp) - : X(0), Y(0), Z(0), NearPtr(0), TakePtr(0), - Next(NULL), Prev(NULL), SeqPtr(NO_SEQ), Time(0), //Delay(0), + : _x(0), _y(0), _z(0), NearPtr(0), TakePtr(0), + _next(NULL), _prev(NULL), _seqPtr(NO_SEQ), _time(0), //Delay(0), _ext(NULL), _ref(-1), _cave(0), _vm(vm) { memset(File, 0, sizeof(File)); - *((uint16 *)&Flags) = 0; + *((uint16 *)&_flags) = 0; SetShapeList(shp); } @@ -374,8 +374,8 @@ BMP_PTR Sprite::Shp() { register SprExt *e = _ext; if (e) if (e->_seq) { - int i = e->_seq[SeqPtr].Now; - if (i >= ShpCnt) { + int i = e->_seq[_seqPtr].Now; + if (i >= _shpCnt) { //char s[256]; //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", // Seq, ShpCnt, SeqPtr, Seq[SeqPtr].Now, Seq[SeqPtr].Next); @@ -391,24 +391,24 @@ BMP_PTR Sprite::Shp() { BMP_PTR *Sprite::SetShapeList(BMP_PTR *shp) { BMP_PTR *r = (_ext) ? _ext->_shpList : NULL; - ShpCnt = 0; - W = 0; - H = 0; + _shpCnt = 0; + _w = 0; + _h = 0; if (shp) { BMP_PTR *p; for (p = shp; *p; p++) { BMP_PTR b = (*p); // ->Code(); - if (b->W > W) - W = b->W; - if (b->H > H) - H = b->H; - ++ShpCnt; + if (b->_w > _w) + _w = b->_w; + if (b->_h > _h) + _h = b->_h; + _shpCnt++; } Expand(); _ext->_shpList = shp; if (!_ext->_seq) - SetSeq((ShpCnt < 2) ? _seq1 : _seq2); + SetSeq((_shpCnt < 2) ? _seq1 : _seq2); } return r; } @@ -441,19 +441,19 @@ Seq *Sprite::SetSeq(Seq *seq) { Expand(); register Seq *s = _ext->_seq; _ext->_seq = seq; - if (SeqPtr == NO_SEQ) + if (_seqPtr == NO_SEQ) Step(0); - else if (Time == 0) - Step(SeqPtr); + else if (_time == 0) + Step(_seqPtr); return s; } bool Sprite::SeqTest(int n) { if (n >= 0) - return (SeqPtr == n); + return (_seqPtr == n); if (_ext) - return (_ext->_seq[SeqPtr].Next == SeqPtr); + return (_ext->_seq[_seqPtr].Next == _seqPtr); return true; } @@ -491,7 +491,7 @@ Sprite *Sprite::Expand(void) { if (*File) { static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; char line[LINE_MAX], fname[MAXPATH]; - BMP_PTR *shplist = new BMP_PTR [ShpCnt + 1]; + BMP_PTR *shplist = new BMP_PTR [_shpCnt + 1]; Seq *seq = NULL; int shpcnt = 0, seqcnt = 0, @@ -521,7 +521,7 @@ Sprite *Sprite::Expand(void) { break; } case 1 : { // Phase - shplist[shpcnt++] = new BITMAP(strtok(NULL, " \t,;/")); + shplist[shpcnt++] = new Bitmap(strtok(NULL, " \t,;/")); break; } case 2 : { // Seq @@ -583,7 +583,7 @@ Sprite *Sprite::Expand(void) { } } } else { // no sprite description: try to read immediately from .BMP - shplist[shpcnt++] = new BITMAP(File); + shplist[shpcnt++] = new Bitmap(File); } shplist[shpcnt] = NULL; if (seq) { @@ -593,7 +593,7 @@ Sprite *Sprite::Expand(void) { error("Bad JUMP in SEQ [%s]", fname); SetSeq(seq); } else - SetSeq((ShpCnt == 1) ? _seq1 : _seq2); + SetSeq((_shpCnt == 1) ? _seq1 : _seq2); //disable(); // disable interupt SetShapeList(shplist); @@ -618,7 +618,7 @@ Sprite *Sprite::Contract(void) { if (e) { if (e->_name) delete[] e->_name; - if (Flags.BDel && e->_shpList) { + if (_flags._bDel && e->_shpList) { int i; for (i = 0; e->_shpList[i]; i++) delete e->_shpList[i]; @@ -651,15 +651,15 @@ Sprite *Sprite::BackShow(bool fast) { void Sprite::Step(int nr) { if (nr >= 0) - SeqPtr = nr; + _seqPtr = nr; if (_ext) { Seq *seq; if (nr < 0) - SeqPtr = _ext->_seq[SeqPtr].Next; - seq = _ext->_seq + SeqPtr; + _seqPtr = _ext->_seq[_seqPtr].Next; + seq = _ext->_seq + _seqPtr; if (seq->Dly >= 0) { - Goto(X + (seq->Dx), Y + (seq->Dy)); - Time = seq->Dly; + Goto(_x + (seq->Dx), _y + (seq->Dy)); + _time = seq->Dly; } } } @@ -674,19 +674,19 @@ void Sprite::MakeXlat(uint8 *x) { if (_ext) { BMP_PTR *b; - if (Flags.Xlat) + if (_flags._xlat) KillXlat(); for (b = _ext->_shpList; *b; b++) - (*b)->M = x; - Flags.Xlat = true; + (*b)->_m = x; + _flags._xlat = true; } } void Sprite::KillXlat(void) { - if (Flags.Xlat && _ext) { + if (_flags._xlat && _ext) { BMP_PTR *b; - uint8 *m = (*_ext->_shpList)->M; + uint8 *m = (*_ext->_shpList)->_m; switch (MemType(m)) { case NEAR_MEM : @@ -700,38 +700,38 @@ void Sprite::KillXlat(void) { break; } for (b = _ext->_shpList; *b; b++) - (*b)->M = NULL; - Flags.Xlat = false; + (*b)->_m = NULL; + _flags._xlat = false; } } void Sprite::Goto(int x, int y) { - int xo = X, yo = Y; - if (W < SCR_WID) { + int xo = _x, yo = _y; + if (_x < SCR_WID) { if (x < 0) x = 0; - if (x + W > SCR_WID) - x = (SCR_WID - W); - X = x; + if (x + _w > SCR_WID) + x = (SCR_WID - _w); + _x = x; } - if (H < SCR_HIG) { + if (_h < SCR_HIG) { if (y < 0) y = 0; - if (y + H > SCR_HIG) - y = (SCR_HIG - H); - Y = y; + if (y + _h > SCR_HIG) + y = (SCR_HIG - _h); + _y = y; } - if (Next) - if (Next->Flags.Slav) - Next->Goto(Next->X - xo + X, Next->Y - yo + Y); - if (Flags.Shad) - Prev->Goto(Prev->X - xo + X, Prev->Y - yo + Y); + if (_next) + if (_next->_flags._slav) + _next->Goto(_next->_x - xo + _x, _next->_y - yo + _y); + if (_flags._shad) + _prev->Goto(_prev->_x - xo + _x, _prev->_y - yo + _y); } void Sprite::Center(void) { - Goto((SCR_WID - W) / 2, (SCR_HIG - H) / 2); + Goto((SCR_WID - _w) / 2, (SCR_HIG - _h) / 2); } @@ -742,12 +742,12 @@ void Sprite::Show(void) { e->_x0 = e->_x1; e->_y0 = e->_y1; e->_b0 = e->_b1; - e->_x1 = X; - e->_y1 = Y; + e->_x1 = _x; + e->_y1 = _y; e->_b1 = Shp(); // asm sti // ...done! - if (! Flags.Hide) { - if (Flags.Xlat) + if (!_flags._hide) { + if (_flags._xlat) e->_b1->XShow(e->_x1, e->_y1); else e->_b1->Show(e->_x1, e->_y1); @@ -758,7 +758,7 @@ void Sprite::Show(void) { void Sprite::Show(uint16 pg) { Graphics::Surface *a = VGA::Page[1]; VGA::Page[1] = VGA::Page[pg & 3]; - Shp()->Show(X, Y); + Shp()->Show(_x, _y); VGA::Page[1] = a; } @@ -773,16 +773,16 @@ void Sprite::Hide(void) { BMP_PTR Sprite::Ghost(void) { register SprExt *e = _ext; if (e->_b1) { - BMP_PTR bmp = new BITMAP(0, 0, (uint8 *)NULL); + BMP_PTR bmp = new Bitmap(0, 0, (uint8 *)NULL); if (bmp == NULL) error("No core"); - bmp->W = e->_b1->W; - bmp->H = e->_b1->H; - if ((bmp->B = farnew(HideDesc, bmp->H)) == NULL) + bmp->_w = e->_b1->_w; + bmp->_h = e->_b1->_h; + if ((bmp->_b = farnew(HideDesc, bmp->_h)) == NULL) error("No Core"); - bmp->V = (uint8 *) memcpy(bmp->B, e->_b1->B, sizeof(HideDesc) * bmp->H); + bmp->_v = (uint8 *) memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc) * bmp->_h); // TODO offset correctly in the surface using y1 pitch and x1 and not via offset segment - //bmp->M = (uint8 *) MK_FP(e->y1, e->x1); + //bmp->_m = (uint8 *) MK_FP(e->y1, e->x1); warning("FIXME: SPRITE::Ghost"); return bmp; } @@ -793,10 +793,12 @@ BMP_PTR Sprite::Ghost(void) { Sprite *SpriteAt(int x, int y) { Sprite *spr = NULL, * tail = Vga->ShowQ->Last(); if (tail) { - for (spr = tail->Prev; spr; spr = spr->Prev) - if (! spr->Flags.Hide && ! spr->Flags.Tran) - if (spr->Shp()->SolidAt(x - spr->X, y - spr->Y)) + for (spr = tail->_prev; spr; spr = spr->_prev) { + if (! spr->_flags._hide && ! spr->_flags._tran) { + if (spr->Shp()->SolidAt(x - spr->_x, y - spr->_y)) break; + } + } } return spr; } @@ -814,7 +816,7 @@ QUEUE::~QUEUE(void) { void QUEUE::Clear(void) { while (Head) { Sprite *s = Remove(Head); - if (s->Flags.Kill) + if (s->_flags._kill) delete s; } } @@ -823,7 +825,7 @@ void QUEUE::Clear(void) { void QUEUE::ForAll(void (*fun)(Sprite *)) { Sprite *s = Head; while (s) { - Sprite *n = s->Next; + Sprite *n = s->_next; fun(s); s = n; } @@ -832,8 +834,8 @@ void QUEUE::ForAll(void (*fun)(Sprite *)) { void QUEUE::Append(Sprite *spr) { if (Tail) { - spr->Prev = Tail; - Tail->Next = spr; + spr->_prev = Tail; + Tail->_next = spr; } else Head = spr; Tail = spr; @@ -846,18 +848,18 @@ void QUEUE::Append(Sprite *spr) { void QUEUE::Insert(Sprite *spr, Sprite *nxt) { if (nxt == Head) { - spr->Next = Head; + spr->_next = Head; Head = spr; if (! Tail) Tail = spr; } else { - spr->Next = nxt; - spr->Prev = nxt->Prev; - if (spr->Prev) - spr->Prev->Next = spr; + spr->_next = nxt; + spr->_prev = nxt->_prev; + if (spr->_prev) + spr->_prev->_next = spr; } - if (spr->Next) - spr->Next->Prev = spr; + if (spr->_next) + spr->_next->_prev = spr; if (Show) spr->Expand(); else @@ -867,8 +869,8 @@ void QUEUE::Insert(Sprite *spr, Sprite *nxt) { void QUEUE::Insert(Sprite *spr) { Sprite *s; - for (s = Head; s; s = s->Next) - if (s->Z > spr->Z) + for (s = Head; s; s = s->_next) + if (s->_z > spr->_z) break; if (s) Insert(spr, s); @@ -883,22 +885,22 @@ void QUEUE::Insert(Sprite *spr) { Sprite *QUEUE::Remove(Sprite *spr) { if (spr == Head) - Head = spr->Next; + Head = spr->_next; if (spr == Tail) - Tail = spr->Prev; - if (spr->Next) - spr->Next->Prev = spr->Prev; - if (spr->Prev) - spr->Prev->Next = spr->Next; - spr->Prev = NULL; - spr->Next = NULL; + Tail = spr->_prev; + if (spr->_next) + spr->_next->_prev = spr->_prev; + if (spr->_prev) + spr->_prev->_next = spr->_next; + spr->_prev = NULL; + spr->_next = NULL; return spr; } Sprite *QUEUE::Locate(int ref) { Sprite *spr; - for (spr = Head; spr; spr = spr->Next) { + for (spr = Head; spr; spr = spr->_next) { if (spr->_ref == ref) return spr; } @@ -1134,10 +1136,10 @@ void VGA::Sunset(void) { void VGA::Show(void) { Sprite *spr = ShowQ->First(); - for (spr = ShowQ->First(); spr; spr = spr->Next) + for (spr = ShowQ->First(); spr; spr = spr->_next) spr->Show(); Update(); - for (spr = ShowQ->First(); spr; spr = spr->Next) + for (spr = ShowQ->First(); spr; spr = spr->_next) spr->Hide(); ++ FrmCnt; @@ -1176,7 +1178,7 @@ void VGA::CopyPage(uint16 d, uint16 s) { //-------------------------------------------------------------------------- -void BITMAP::XShow(int x, int y) { +void Bitmap::XShow(int x, int y) { /* uint8 rmsk = x % 4, mask = 1 << rmsk, @@ -1258,8 +1260,8 @@ void BITMAP::XShow(int x, int y) { } -void BITMAP::Show(int x, int y) { - const byte *srcP = (const byte *)V; +void Bitmap::Show(int x, int y) { + const byte *srcP = (const byte *)_v; byte *destEndP = (byte *)VGA::Page[1]->pixels + (SCR_WID * SCR_HIG); // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a @@ -1320,7 +1322,7 @@ void BITMAP::Show(int x, int y) { } -void BITMAP::Hide(int x, int y) { +void Bitmap::Hide(int x, int y) { /* uint8 *scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; uint16 d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); @@ -1383,7 +1385,7 @@ void BITMAP::Hide(int x, int y) { asm pop si // asm pop bx */ - warning("STUB: BITMAP::Hide"); + warning("STUB: Bitmap::Hide"); } } // End of namespace CGE diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 77594217abc..0c75dd6ba95 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -172,32 +172,35 @@ public: int _ref; signed char _cave; struct FLAGS { - uint16 Hide : 1; // general visibility switch - uint16 Near : 1; // Near action lock - uint16 Drag : 1; // sprite is moveable - uint16 Hold : 1; // sprite is held with mouse - uint16 ____ : 1; // intrrupt driven animation - uint16 Slav : 1; // slave object - uint16 Syst : 1; // system object - uint16 Kill : 1; // dispose memory after remove - uint16 Xlat : 1; // 2nd way display: xlat table - uint16 Port : 1; // portable - uint16 Kept : 1; // kept in pocket - uint16 East : 1; // talk to east (in opposite to west) - uint16 Shad : 1; // shadow - uint16 Back : 1; // 'send to background' request - uint16 BDel : 1; // delete bitmaps in ~SPRITE - uint16 Tran : 1; // transparent (untouchable) - } Flags; - int X, Y; - signed char Z; - uint16 W, H; - uint16 Time; + uint16 _hide : 1; // general visibility switch + uint16 _near : 1; // Near action lock + uint16 _drag : 1; // sprite is moveable + uint16 _hold : 1; // sprite is held with mouse + uint16 _____ : 1; // intrrupt driven animation + uint16 _slav : 1; // slave object + uint16 _syst : 1; // system object + uint16 _kill : 1; // dispose memory after remove + uint16 _xlat : 1; // 2nd way display: xlat table + uint16 _port : 1; // portable + uint16 _kept : 1; // kept in pocket + uint16 _east : 1; // talk to east (in opposite to west) + uint16 _shad : 1; // shadow + uint16 _back : 1; // 'send to background' request + uint16 _bDel : 1; // delete bitmaps in ~SPRITE + uint16 _tran : 1; // transparent (untouchable) + } _flags; + int _x; + int _y; + signed char _z; + uint16 _w; + uint16 _h; + uint16 _time; uint8 NearPtr, TakePtr; - int SeqPtr; - int ShpCnt; + int _seqPtr; + int _shpCnt; char File[MAXFILE]; - Sprite *Prev, * Next; + Sprite *_prev; + Sprite *_next; bool Works(Sprite *spr); bool SeqTest(int n); inline bool Active(void) { @@ -329,12 +332,6 @@ uint8 Closest(CBLK *pal, CBLK x) { #undef f } - - - - - - char *NumStr(char *str, int num); //static void Video (void); uint16 *SaveScreen(void); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index ed335191aa1..ed07a1269fa 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -60,12 +60,12 @@ MENU_BAR::MENU_BAR(CGEEngine *vm, uint16 w) : TALK(vm), _vm(vm) { p1 += w; p2 -= w; } - TS[0] = new BITMAP(w, h, p); + TS[0] = new Bitmap(w, h, p); SetShapeList(TS); - Flags.Slav = true; - Flags.Tran = true; - Flags.Kill = true; - Flags.BDel = true; + _flags._slav = true; + _flags._tran = true; + _flags._kill = true; + _flags._bDel = true; } @@ -78,7 +78,7 @@ char *VMGather(CHOICE *list) { for (cp = list; cp->Text; cp++) { len += strlen(cp->Text); - ++h; + h++; } vmgt = new char[len + h]; if (vmgt) { @@ -87,7 +87,7 @@ char *VMGather(CHOICE *list) { if (*vmgt) strcat(vmgt, "|"); strcat(vmgt, cp->Text); - ++ h; + h++; } } return vmgt; @@ -106,16 +106,16 @@ VMENU::VMENU(CGEEngine *vm, CHOICE *list, int x, int y) delete[] vmgt; Items = 0; for (cp = list; cp->Text; cp++) - ++Items; - Flags.BDel = true; - Flags.Kill = true; + Items++; + _flags._bDel = true; + _flags._kill = true; if (x < 0 || y < 0) Center(); else - Goto(x - W / 2, y - (TEXT_VM + FONT_HIG / 2)); + Goto(x - _w / 2, y - (TEXT_VM + FONT_HIG / 2)); Vga->ShowQ->Insert(this, Vga->ShowQ->Last()); - Bar = new MENU_BAR(_vm, W - 2 * TEXT_HM); - Bar->Goto(X + TEXT_HM - MB_HM, Y + TEXT_VM - MB_VM); + Bar = new MENU_BAR(_vm, _w - 2 * TEXT_HM); + Bar->Goto(_x + TEXT_HM - MB_HM, _y + TEXT_VM - MB_VM); Vga->ShowQ->Insert(Bar, Vga->ShowQ->Last()); } @@ -137,12 +137,12 @@ void VMENU::Touch(uint16 mask, int x, int y) { if (y >= 0) { n = y / h; if (n < Items) - ok = (x >= TEXT_HM && x < W - TEXT_HM/* && y % h < FONT_HIG*/); + ok = (x >= TEXT_HM && x < _w - TEXT_HM/* && y % h < FONT_HIG*/); else n = Items - 1; } - Bar->Goto(X + TEXT_HM - MB_HM, Y + TEXT_VM + n * h - MB_VM); + Bar->Goto(_x + TEXT_HM - MB_HM, _y + TEXT_VM + n * h - MB_VM); if (ok && (mask & L_UP)) { Items = 0; From f59c910b8f41cfa9eeda88ce5f4d5c2a18b97662 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 30 Jun 2011 08:30:23 +0200 Subject: [PATCH 045/276] CGE: Some more renaming (wip) --- engines/cge/bitmap.cpp | 78 +++++++++--------- engines/cge/bitmap.h | 28 +++---- engines/cge/boot.h | 64 +++++++-------- engines/cge/btfile.cpp | 110 ++++++++++++------------- engines/cge/btfile.h | 61 +++++++------- engines/cge/cfile.cpp | 168 +++++++++++++++++++-------------------- engines/cge/cfile.h | 53 ++++++------ engines/cge/cge.cpp | 22 ++--- engines/cge/cge_main.cpp | 67 ++++++++-------- engines/cge/general.cpp | 26 +++--- engines/cge/general.h | 36 ++++----- engines/cge/mixer.cpp | 4 +- engines/cge/snail.cpp | 4 +- engines/cge/sound.cpp | 10 +-- engines/cge/talk.cpp | 10 +-- engines/cge/text.cpp | 6 +- engines/cge/vga13h.cpp | 30 +++---- engines/cge/vol.cpp | 52 ++++++------ engines/cge/vol.h | 46 ++++++----- engines/cge/wav.h | 2 +- 20 files changed, 440 insertions(+), 437 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index ab5c1ff3c78..30684999756 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -35,11 +35,11 @@ namespace CGE { -DAC *Bitmap::Pal = NULL; +DAC *Bitmap::_pal = NULL; #define MAXPATH 128 void Bitmap::init() { - Pal = NULL; + _pal = NULL; } void Bitmap::deinit() { @@ -51,9 +51,9 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { ForceExt(pat, fname, ".VBM"); #if (BMP_MODE < 2) - if (rem && PIC_FILE::Exist(pat)) { + if (rem && PIC_FILE::exist(pat)) { PIC_FILE file(pat); - if ((file.Error == 0) && (!VBMLoad(&file))) + if ((file.Error == 0) && (!loadVBM(&file))) error("Bad VBM [%s]", fname); } else #endif @@ -62,7 +62,7 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { ForceExt(pat, fname, ".BMP"); PIC_FILE file(pat); if (file.Error == 0) { - if (BMPLoad(&file)) { + if (loadBMP(&file)) { Code(); if (rem) { free(_m); @@ -80,7 +80,7 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL) { if (map) - Code(); + code(); } @@ -169,7 +169,7 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { } -uint16 Bitmap::MoveVmap(uint8 *buf) { +uint16 Bitmap::moveVmap(uint8 *buf) { if (_v) { uint16 vsiz = (uint8 *)_b - (uint8 *)_v; uint16 siz = vsiz + _h * sizeof(HideDesc); @@ -183,7 +183,7 @@ uint16 Bitmap::MoveVmap(uint8 *buf) { } -BMP_PTR Bitmap::Code(void) { +BMP_PTR Bitmap::code(void) { if (_m) { uint16 i, cnt; @@ -305,7 +305,7 @@ BMP_PTR Bitmap::Code(void) { } -bool Bitmap::SolidAt(int x, int y) { +bool Bitmap::solidAt(int x, int y) { uint8 *m; uint16 r, n, n0; @@ -366,67 +366,67 @@ bool Bitmap::SolidAt(int x, int y) { } -bool Bitmap::VBMSave(XFILE *f) { - uint16 p = (Pal != NULL), +bool Bitmap::saveVBM(XFILE *f) { + uint16 p = (_pal != NULL), n = ((uint16)(((uint8 *)_b) - _v)) + _h * sizeof(HideDesc); if (f->Error == 0) - f->Write((uint8 *)&p, sizeof(p)); + f->write((uint8 *)&p, sizeof(p)); if (f->Error == 0) - f->Write((uint8 *)&n, sizeof(n)); + f->write((uint8 *)&n, sizeof(n)); if (f->Error == 0) - f->Write((uint8 *)&_w, sizeof(_w)); + f->write((uint8 *)&_w, sizeof(_w)); if (f->Error == 0) - f->Write((uint8 *)&_h, sizeof(_h)); + f->write((uint8 *)&_h, sizeof(_h)); if (f->Error == 0) if (p) - f->Write((uint8 *)Pal, 256 * 3); + f->write((uint8 *)_pal, 256 * 3); if (f->Error == 0) - f->Write(_v, n); + f->write(_v, n); return (f->Error == 0); } -bool Bitmap::VBMLoad(XFILE *f) { +bool Bitmap::loadVBM(XFILE *f) { uint16 p = 0, n = 0; if (f->Error == 0) - f->Read((uint8 *)&p, sizeof(p)); + f->read((uint8 *)&p, sizeof(p)); if (f->Error == 0) - f->Read((uint8 *)&n, sizeof(n)); + f->read((uint8 *)&n, sizeof(n)); if (f->Error == 0) - f->Read((uint8 *)&_w, sizeof(_w)); + f->read((uint8 *)&_w, sizeof(_w)); if (f->Error == 0) - f->Read((uint8 *)&_h, sizeof(_h)); + f->read((uint8 *)&_h, sizeof(_h)); if (f->Error == 0) { if (p) { - if (Pal) { + if (_pal) { byte palData[PAL_SIZ]; - f->Read(palData, PAL_SIZ); - VGA::pal2DAC(palData, Pal); + f->read(palData, PAL_SIZ); + VGA::pal2DAC(palData, _pal); } else - f->Seek(f->Mark() + PAL_SIZ); + f->seek(f->mark() + PAL_SIZ); } } if ((_v = farnew(uint8, n)) == NULL) return false; if (f->Error == 0) - f->Read(_v, n); + f->read(_v, n); _b = (HideDesc *)(_v + n - _h * sizeof(HideDesc)); return (f->Error == 0); } -bool Bitmap::BMPLoad (XFILE * f) { +bool Bitmap::loadBMP(XFILE * f) { struct { char BM[2]; union { int16 len; int32 len_; }; @@ -445,19 +445,19 @@ bool Bitmap::BMPLoad (XFILE * f) { } hea; BGR4 bpal[256]; - f->Read((byte *)&hea, sizeof(hea)); + f->read((byte *)&hea, sizeof(hea)); if (f->Error == 0) { if (hea.hdr == 0x436L) { int16 i = (hea.hdr - sizeof(hea)) / sizeof(BGR4); - f->Read((byte *)&bpal, sizeof(bpal)); + f->read((byte *)&bpal, sizeof(bpal)); if (f->Error == 0) { - if (Pal) { - for (i = 0; i < 256; i ++) { - Pal[i].R = bpal[i].R; - Pal[i].G = bpal[i].G; - Pal[i].B = bpal[i].B; - } - Pal = NULL; + if (_pal) { + for (i = 0; i < 256; i ++) { + _pal[i].R = bpal[i].R; + _pal[i].G = bpal[i].G; + _pal[i].B = bpal[i].B; + } + _pal = NULL; } _h = hea.hig; _w = hea.wid; @@ -465,9 +465,9 @@ bool Bitmap::BMPLoad (XFILE * f) { int16 r = (4 - (hea.wid & 3)) % 4; byte buf[3]; int i; for (i = _h - 1; i >= 0; i--) { - f->Read(_m + (_w * i), _w); + f->read(_m + (_w * i), _w); if (r && f->Error == 0) - f->Read(buf, r); + f->read(buf, r); if (f->Error) break; } diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index cfa7830f390..b13912a3c6e 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -60,33 +60,33 @@ struct HideDesc { #include "common/pack-end.h" class Bitmap { - bool BMPLoad(XFILE *f); - bool VBMLoad(XFILE *f); + bool loadBMP(XFILE *f); + bool loadVBM(XFILE *f); public: - static DAC *Pal; + static DAC *_pal; uint16 _w; uint16 _h; uint8 *_m; uint8 *_v; HideDesc *_b; - Bitmap(const char *fname, bool rem = true); + Bitmap(const char *fname, bool rem); Bitmap(uint16 w, uint16 h, uint8 *map); Bitmap(uint16 w, uint16 h, uint8 fill); Bitmap(const Bitmap &bmp); - ~Bitmap(void); + ~Bitmap(); + static void init(); static void deinit(); - - Bitmap *FlipH(void); - Bitmap *Code(); + Bitmap *flipH(); + Bitmap *code(); Bitmap &operator = (const Bitmap &bmp); - void Hide(int x, int y); - void Show(int x, int y); - void XShow(int x, int y); - bool SolidAt(int x, int y); - bool VBMSave(XFILE *f); - uint16 MoveVmap(uint8 *buf); + void hide(int x, int y); + void show(int x, int y); + void xShow(int x, int y); + bool solidAt(int x, int y); + bool saveVBM(XFILE *f); + uint16 moveVmap(uint8 *buf); }; diff --git a/engines/cge/boot.h b/engines/cge/boot.h index ab4dcde0e23..2dce0d6d160 100644 --- a/engines/cge/boot.h +++ b/engines/cge/boot.h @@ -37,42 +37,38 @@ namespace CGE { #define BOOTCODE_SIZ BOOTSECT_SIZ-BOOTHEAD_SIZ #define FreeBoot(b) free(b) -#ifndef EC -#define EC -#endif - -typedef struct { - uint8 Jmp[3]; // NEAR jump machine code - char OEM_ID[8]; // OEM name and version - uint16 SectSize; // bytes per sector - uint8 ClustSize; // sectors per cluster - uint16 ResSecs; // sectors before 1st FAT - uint8 FatCnt; // number of FATs - uint16 RootSize; // root directory entries - uint16 TotSecs; // total sectors on disk - uint8 Media; // media descriptor byte - uint16 FatSize; // sectors per FAT - uint16 TrkSecs; // sectors per track - uint16 HeadCnt; // number of sufraces - uint16 HidnSecs; // special hidden sectors - uint16 _; // (unknown: reserved?) - uint32 lTotSecs; // total number of sectors - uint16 DriveNum; // physical drive number - uint8 XSign; // extended boot signature - uint32 Serial; // volume serial number - char Label[11]; // volume label - char FileSysID[8]; // file system ID - char Code[BOOTCODE_SIZ - 8]; // 8 = length of following - uint32 Secret; // long secret number - uint8 BootCheck; // boot sector checksum - uint8 BootFlags; // secret flags - uint16 BootSig; // boot signature 0xAA55 -} Boot; +struct Boot { + uint8 _jmp[3]; // NEAR jump machine code + char _idOEM[8]; // OEM name and version + uint16 _sectSize; // bytes per sector + uint8 _clustSize; // sectors per cluster + uint16 _resSecs; // sectors before 1st FAT + uint8 _fatCnt; // number of FATs + uint16 _rootSize; // root directory entries + uint16 _totSecs; // total sectors on disk + uint8 _media; // media descriptor byte + uint16 _fatSize; // sectors per FAT + uint16 _trkSecs; // sectors per track + uint16 _headCnt; // number of sufraces + uint16 _hidnSecs; // special hidden sectors + uint16 __; // (unknown: reserved?) + uint32 _lTotSecs; // total number of sectors + uint16 _driveNum; // physical drive number + uint8 _xSign; // extended boot signature + uint32 _serial; // volume serial number + char _label[11]; // volume label + char _fileSysID[8]; // file system ID + char _code[BOOTCODE_SIZ - 8]; // 8 = length of following + uint32 _secret; // long secret number + uint8 _bootCheck; // boot sector checksum + uint8 _bootFlags; // secret flags + uint16 _bootSig; // boot signature 0xAA55 +}; -EC Boot *ReadBoot(int drive); -EC uint8 CheckBoot(Boot *boot); -EC bool WriteBoot(int drive, Boot *boot); +Boot *readBoot(int drive); +uint8 checkBoot(Boot *boot); +bool writeBoot(int drive, Boot *boot); } // End of namespace CGE diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index db0ebc2d5f3..8255775fd14 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -40,80 +40,80 @@ namespace CGE { #define BT_KEYLEN 13 #endif -BTFILE::BTFILE(const char *name, IOMODE mode, CRYPT *crpt) - : IOHAND(name, mode, crpt) { +BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt) + : IoHand(name, mode, crpt) { for (int i = 0; i < BT_LEVELS; i++) { - Buff[i].Page = new BT_PAGE; - Buff[i].PgNo = BT_NONE; - Buff[i].Indx = -1; - Buff[i].Updt = false; - if (Buff[i].Page == NULL) + _buff[i]._page = new BtPage; + _buff[i]._pgNo = BT_NONE; + _buff[i]._indx = -1; + _buff[i]._updt = false; + if (_buff[i]._page == NULL) error("No core"); } } -BTFILE::~BTFILE(void) { +BtFile::~BtFile(void) { for (int i = 0; i < BT_LEVELS; i++) { - PutPage(i); - delete Buff[i].Page; + putPage(i); + delete _buff[i]._page; } } -void BTFILE::PutPage(int lev, bool hard) { - if (hard || Buff[lev].Updt) { - Seek(Buff[lev].PgNo * sizeof(BT_PAGE)); - Write((uint8 *) Buff[lev].Page, sizeof(BT_PAGE)); - Buff[lev].Updt = false; +void BtFile::putPage(int lev, bool hard) { + if (hard || _buff[lev]._updt) { + seek(_buff[lev]._pgNo * sizeof(BtPage)); + write((uint8 *) _buff[lev]._page, sizeof(BtPage)); + _buff[lev]._updt = false; } } -BT_PAGE *BTFILE::GetPage(int lev, uint16 pgn) { - if (Buff[lev].PgNo != pgn) { - int32 pos = pgn * sizeof(BT_PAGE); - PutPage(lev); - Buff[lev].PgNo = pgn; - if (Size() > pos) { - Seek((uint32) pgn * sizeof(BT_PAGE)); - Read((uint8 *) Buff[lev].Page, sizeof(BT_PAGE)); - Buff[lev].Updt = false; +BtPage *BtFile::getPage(int lev, uint16 pgn) { + if (_buff[lev]._pgNo != pgn) { + int32 pos = pgn * sizeof(BtPage); + putPage(lev); + _buff[lev]._pgNo = pgn; + if (size() > pos) { + seek((uint32) pgn * sizeof(BtPage)); + read((uint8 *) _buff[lev]._page, sizeof(BtPage)); + _buff[lev]._updt = false; } else { - Buff[lev].Page->Hea.Count = 0; - Buff[lev].Page->Hea.Down = BT_NONE; - memset(Buff[lev].Page->Data, '\0', sizeof(Buff[lev].Page->Data)); - Buff[lev].Updt = true; + _buff[lev]._page->_hea._count = 0; + _buff[lev]._page->_hea._down = BT_NONE; + memset(_buff[lev]._page->_data, '\0', sizeof(_buff[lev]._page->_data)); + _buff[lev]._updt = true; } - Buff[lev].Indx = -1; + _buff[lev]._indx = -1; } - return Buff[lev].Page; + return _buff[lev]._page; } -BT_KEYPACK *BTFILE::Find(const char *key) { +BtKeypack *BtFile::find(const char *key) { int lev = 0; uint16 nxt = BT_ROOT; while (! Error) { - BT_PAGE *pg = GetPage(lev, nxt); + BtPage *pg = getPage(lev, nxt); // search - if (pg->Hea.Down != BT_NONE) { + if (pg->_hea._down != BT_NONE) { int i; - for (i = 0; i < pg->Hea.Count; i++) { + for (i = 0; i < pg->_hea._count; i++) { // Does this work, or does it have to compare the entire buffer? - if (scumm_strnicmp((const char *) key, (const char*)pg->Inn[i].Key, BT_KEYLEN) < 0) + if (scumm_strnicmp((const char *)key, (const char*)pg->_inn[i]._key, BT_KEYLEN) < 0) break; } - nxt = (i) ? pg->Inn[i - 1].Down : pg->Hea.Down; - Buff[lev].Indx = i - 1; - ++ lev; + nxt = (i) ? pg->_inn[i - 1]._down : pg->_hea._down; + _buff[lev]._indx = i - 1; + lev++; } else { int i; - for (i = 0; i < pg->Hea.Count - 1; i++) { - if (scumm_stricmp((const char *)key, (const char *)pg->Lea[i].Key) <= 0) + for (i = 0; i < pg->_hea._count - 1; i++) { + if (scumm_stricmp((const char *)key, (const char *)pg->_lea[i]._key) <= 0) break; } - Buff[lev].Indx = i; - return &pg->Lea[i]; + _buff[lev]._indx = i; + return &pg->_lea[i]; } } return NULL; @@ -125,26 +125,26 @@ int keycomp(const void *k1, const void *k2) { } -void BTFILE::Make(BT_KEYPACK *keypack, uint16 count) { +void BtFile::make(BtKeypack *keypack, uint16 count) { #if BT_LEVELS != 2 #error This tiny BTREE implementation works with exactly 2 levels! #endif _fqsort(keypack, count, sizeof(*keypack), keycomp); uint16 n = 0; - BT_PAGE *Root = GetPage(0, n++), - *Leaf = GetPage(1, n); - Root->Hea.Down = n; - PutPage(0, true); + BtPage *Root = getPage(0, n++); + BtPage *Leaf = getPage(1, n); + Root->_hea._down = n; + putPage(0, true); while (count--) { - if (Leaf->Hea.Count >= ArrayCount(Leaf->Lea)) { - PutPage(1, true); // save filled page - Leaf = GetPage(1, ++n); // take empty page - memcpy(Root->Inn[Root->Hea.Count].Key, keypack->Key, BT_KEYLEN); - Root->Inn[Root->Hea.Count++].Down = n; - Buff[0].Updt = true; + if (Leaf->_hea._count >= ArrayCount(Leaf->_lea)) { + putPage(1, true); // save filled page + Leaf = getPage(1, ++n); // take empty page + memcpy(Root->_inn[Root->_hea._count]._key, keypack->_key, BT_KEYLEN); + Root->_inn[Root->_hea._count++]._down = n; + _buff[0]._updt = true; } - Leaf->Lea[Leaf->Hea.Count++] = *(keypack++); - Buff[1].Updt = true; + Leaf->_lea[Leaf->_hea._count++] = *(keypack++); + _buff[1]._updt = true; } } diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 449f2001405..3fd31757984 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -41,50 +41,53 @@ namespace CGE { #include "common/pack-start.h" // START STRUCT PACKING -struct BT_KEYPACK { - char Key[BT_KEYLEN]; - uint32 Mark; - uint16 Size; +struct BtKeypack { + char _key[BT_KEYLEN]; + uint32 _mark; + uint16 _size; }; -typedef struct { - uint8 Key[BT_KEYLEN]; - uint16 Down; -} INNER; +struct Inner { + uint8 _key[BT_KEYLEN]; + uint16 _down; +}; -struct BT_PAGE { - struct HEA { - uint16 Count; - uint16 Down; - } Hea; +struct Hea { + uint16 _count; + uint16 _down; +}; + +struct BtPage { + Hea _hea; union { // dummy filler to make proper size of union - uint8 Data[BT_SIZE - sizeof(HEA)]; + uint8 _data[BT_SIZE - sizeof(Hea)]; // inner version of data: key + word-sized page link - INNER Inn[(BT_SIZE - sizeof(HEA)) / sizeof(INNER)]; + Inner _inn[(BT_SIZE - sizeof(Hea)) / sizeof(Inner)]; // leaf version of data: key + all user data - BT_KEYPACK Lea[(BT_SIZE - sizeof(HEA)) / sizeof(BT_KEYPACK)]; + BtKeypack _lea[(BT_SIZE - sizeof(Hea)) / sizeof(BtKeypack)]; }; }; #include "common/pack-end.h" // END STRUCT PACKING -class BTFILE : public IOHAND { +class BtFile : public IoHand { struct { - BT_PAGE *Page; - uint16 PgNo; - int Indx; - bool Updt; - } Buff[BT_LEVELS]; - void PutPage(int lev, bool hard = false); - BT_PAGE *GetPage(int lev, uint16 pgn); + BtPage *_page; + uint16 _pgNo; + int _indx; + bool _updt; + } _buff[BT_LEVELS]; + + void putPage(int lev, bool hard = false); + BtPage *getPage(int lev, uint16 pgn); public: - BTFILE(const char *name, IOMODE mode = REA, CRYPT *crpt = NULL); - virtual ~BTFILE(void); - BT_KEYPACK *Find(const char *key); - BT_KEYPACK *Next(void); - void Make(BT_KEYPACK *keypack, uint16 count); + BtFile(const char *name, IOMODE mode = REA, CRYPT *crpt = NULL); + virtual ~BtFile(); + BtKeypack *find(const char *key); + BtKeypack *next(); + void make(BtKeypack *keypack, uint16 count); }; } // End of namespace CGE diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 85e51a94c1f..9a2b697bd70 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -32,65 +32,65 @@ namespace CGE { -IOBUF::IOBUF(IOMODE mode, CRYPT *crpt) - : IOHAND(mode, crpt), - BufMark(0), - Ptr(0), - Lim(0) { - Buff = farnew(uint8, IOBUF_SIZE); - if (Buff == NULL) +IoBuf::IoBuf(IOMODE mode, CRYPT *crpt) + : IoHand(mode, crpt), + _bufMark(0), + _ptr(0), + _lim(0) { + _buff = farnew(uint8, IOBUF_SIZE); + if (_buff == NULL) error("No core for I/O"); } -IOBUF::IOBUF(const char *name, IOMODE mode, CRYPT *crpt) - : IOHAND(name, mode, crpt), - BufMark(0), - Ptr(0), - Lim(0) { - Buff = farnew(uint8, IOBUF_SIZE); - if (Buff == NULL) +IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt) + : IoHand(name, mode, crpt), + _bufMark(0), + _ptr(0), + _lim(0) { + _buff = farnew(uint8, IOBUF_SIZE); + if (_buff == NULL) error("No core for I/O [%s]", name); } -IOBUF::~IOBUF(void) { +IoBuf::~IoBuf(void) { if (Mode > REA) - WriteBuff(); - if (Buff) - free(Buff); + writeBuff(); + if (_buff) + free(_buff); } -void IOBUF::ReadBuff(void) { - BufMark = IOHAND::Mark(); - Lim = IOHAND::Read(Buff, IOBUF_SIZE); - Ptr = 0; +void IoBuf::readBuff(void) { + _bufMark = IoHand::mark(); + _lim = IoHand::read(_buff, IOBUF_SIZE); + _ptr = 0; } -void IOBUF::WriteBuff(void) { - if (Lim) { - IOHAND::Write(Buff, Lim); - BufMark = IOHAND::Mark(); - Lim = 0; +void IoBuf::writeBuff(void) { + if (_lim) { + IoHand::write(_buff, _lim); + _bufMark = IoHand::mark(); + _lim = 0; } } -uint16 IOBUF::Read(void *buf, uint16 len) { +uint16 IoBuf::read(void *buf, uint16 len) { uint16 total = 0; while (len) { - if (Ptr >= Lim) - ReadBuff(); - uint16 n = Lim - Ptr; + if (_ptr >= _lim) + readBuff(); + uint16 n = _lim - _ptr; if (n) { if (len < n) n = len; - memcpy(buf, Buff + Ptr, n); + memcpy(buf, _buff + _ptr, n); buf = (uint8 *)buf + n; len -= n; total += n; - Ptr += n; + _ptr += n; } else break; } @@ -98,14 +98,14 @@ uint16 IOBUF::Read(void *buf, uint16 len) { } -uint16 IOBUF::Read(uint8 *buf) { +uint16 IoBuf::read(uint8 *buf) { uint16 total = 0; while (total < LINE_MAX - 2) { - if (Ptr >= Lim) - ReadBuff(); - uint8 *p = Buff + Ptr; - uint16 n = Lim - Ptr; + if (_ptr >= _lim) + readBuff(); + uint8 *p = _buff + _ptr; + uint16 n = _lim - _ptr; if (n) { if (total + n >= LINE_MAX - 2) n = LINE_MAX - 2 - total; @@ -115,7 +115,7 @@ uint16 IOBUF::Read(uint8 *buf) { uint8 *eof = (uint8 *) memchr(p, '\32', n); if (eof) { // end-of-file n = (uint16)(eof - p); - Ptr = (uint16)(eof - Buff); + _ptr = (uint16)(eof - _buff); } if (n) memcpy(buf, p, n); @@ -123,16 +123,16 @@ uint16 IOBUF::Read(uint8 *buf) { total += n; if (eof) break; - Ptr += n; + _ptr += n; if (eol) { - ++ Ptr; + _ptr++; *(buf++) = '\n'; - ++ total; - if (Ptr >= Lim) - ReadBuff(); - if (Ptr < Lim) - if (Buff[Ptr] == '\n') - ++Ptr; + total++; + if (_ptr >= _lim) + readBuff(); + if (_ptr < _lim) + if (_buff[_ptr] == '\n') + ++_ptr; break; } } else @@ -143,36 +143,36 @@ uint16 IOBUF::Read(uint8 *buf) { } -uint16 IOBUF::Write(void *buf, uint16 len) { +uint16 IoBuf::write(void *buf, uint16 len) { uint16 tot = 0; while (len) { - uint16 n = IOBUF_SIZE - Lim; + uint16 n = IOBUF_SIZE - _lim; if (n > len) n = len; if (n) { - memcpy(Buff + Lim, buf, n); - Lim += n; + memcpy(_buff + _lim, buf, n); + _lim += n; len -= n; buf = (uint8 *)buf + n; tot += n; } else - WriteBuff(); + writeBuff(); } return tot; } -uint16 IOBUF::Write(uint8 *buf) { +uint16 IoBuf::write(uint8 *buf) { uint16 len = 0; if (buf) { len = strlen((const char *) buf); if (len) if (buf[len - 1] == '\n') --len; - len = Write(buf, len); + len = write(buf, len); if (len) { static char EOL[] = "\r\n"; - uint16 n = Write(EOL, sizeof(EOL) - 1); + uint16 n = write(EOL, sizeof(EOL) - 1); len += n; } } @@ -180,40 +180,40 @@ uint16 IOBUF::Write(uint8 *buf) { } -int IOBUF::Read(void) { - if (Ptr >= Lim) { - ReadBuff(); - if (Lim == 0) +int IoBuf::read() { + if (_ptr >= _lim) { + readBuff(); + if (_lim == 0) return -1; } - return Buff[Ptr++]; + return _buff[_ptr++]; } -void IOBUF::Write(uint8 b) { - if (Lim >= IOBUF_SIZE) - WriteBuff(); - Buff[Lim++] = b; +void IoBuf::write(uint8 b) { + if (_lim >= IOBUF_SIZE) + writeBuff(); + _buff[_lim++] = b; } -uint16 CFILE::MaxLineLen = LINE_MAX; +uint16 CFile::_maxLineLen = LINE_MAX; -CFILE::CFILE(const char *name, IOMODE mode, CRYPT *crpt) - : IOBUF(name, mode, crpt) { +CFile::CFile(const char *name, IOMODE mode, CRYPT *crpt) + : IoBuf(name, mode, crpt) { } -CFILE::~CFILE(void) { +CFile::~CFile(void) { } -void CFILE::Flush(void) { +void CFile::flush(void) { if (Mode > REA) - WriteBuff(); + writeBuff(); else - Lim = 0; + _lim = 0; /* _BX = Handle; @@ -224,33 +224,33 @@ void CFILE::Flush(void) { } -long CFILE::Mark(void) { - return BufMark + ((Mode > REA) ? Lim : Ptr); +long CFile::mark(void) { + return _bufMark + ((Mode > REA) ? _lim : _ptr); } -long CFILE::Seek(long pos) { - if (pos >= BufMark && pos < BufMark + Lim) { - ((Mode == REA) ? Ptr : Lim) = (uint16)(pos - BufMark); +long CFile::seek(long pos) { + if (pos >= _bufMark && pos < _bufMark + _lim) { + ((Mode == REA) ? _ptr : _lim) = (uint16)(pos - _bufMark); return pos; } else { if (Mode > REA) - WriteBuff(); + writeBuff(); else - Lim = 0; + _lim = 0; - Ptr = 0; - return BufMark = IOHAND::Seek(pos); + _ptr = 0; + return _bufMark = IoHand::seek(pos); } } -void CFILE::Append(CFILE &f) { - Seek(Size()); +void CFile::append(CFile &f) { + seek(size()); if (f.Error == 0) { while (true) { - if ((Lim = f.IOHAND::Read(Buff, IOBUF_SIZE)) == IOBUF_SIZE) - WriteBuff(); + if ((_lim = f.IoHand::read(_buff, IOBUF_SIZE)) == IOBUF_SIZE) + writeBuff(); else break; if ((Error = f.Error) != 0) diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index f045c48c0f1..376e50ae449 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -38,40 +38,41 @@ namespace CGE { #define IOBUF_SIZE K(2) #endif -#define CFREAD(x) Read((uint8 *)(x),sizeof(*(x))) +#define CFREAD(x) read((uint8 *)(x),sizeof(*(x))) -class IOBUF : public IOHAND { +class IoBuf : public IoHand { protected: - uint8 *Buff; - uint16 Ptr, Lim; - long BufMark; - uint16 Seed; - CRYPT *Crypt; - virtual void ReadBuff(void); - virtual void WriteBuff(void); + uint8 *_buff; + uint16 _ptr; + uint16 _lim; + long _bufMark; + uint16 _seed; + CRYPT *_crypt; + virtual void readBuff(); + virtual void writeBuff(); public: - IOBUF(IOMODE mode, CRYPT *crpt = NULL); - IOBUF(const char *name, IOMODE mode, CRYPT *crpt = NULL); - virtual ~IOBUF(void); - uint16 Read(void *buf, uint16 len); - uint16 Read(uint8 *buf); - int Read(void); - uint16 Write(void *buf, uint16 len); - uint16 Write(uint8 *buf); - void Write(uint8 b); + IoBuf(IOMODE mode, CRYPT *crpt = NULL); + IoBuf(const char *name, IOMODE mode, CRYPT *crpt = NULL); + virtual ~IoBuf(); + uint16 read(void *buf, uint16 len); + uint16 read(uint8 *buf); + int read(); + uint16 write(void *buf, uint16 len); + uint16 write(uint8 *buf); + void write(uint8 b); }; -class CFILE : public IOBUF { +class CFile : public IoBuf { public: - static uint16 MaxLineLen; - CFILE(const char *name, IOMODE mode = REA, CRYPT *crpt = NULL); - virtual ~CFILE(void); - void Flush(void); - long Mark(void); - long Seek(long pos); - void Append(CFILE &f); + static uint16 _maxLineLen; + CFile(const char *name, IOMODE mode = REA, CRYPT *crpt = NULL); + virtual ~CFile(); + void flush(); + long mark(); + long seek(long pos); + void append(CFile &f); }; } // End of namespace CGE diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 885aa4d4924..c921d7c6ba8 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -77,22 +77,22 @@ void CGEEngine::setup() { InfoLine = new INFO_LINE(this, INFO_W); _cavLight = new Sprite(this, PR); DebugLine = new INFO_LINE(this, SCR_WID); - MB[0] = new Bitmap("BRICK"); + MB[0] = new Bitmap("BRICK", true); MB[1] = NULL; - HL[0] = new Bitmap("HLINE"); + HL[0] = new Bitmap("HLINE", true); HL[1] = NULL; - MC[0] = new Bitmap("MOUSE"); - MC[1] = new Bitmap("DUMMY"); + MC[0] = new Bitmap("MOUSE", true); + MC[1] = new Bitmap("DUMMY", true); MC[2] = NULL; - PR[0] = new Bitmap("PRESS"); + PR[0] = new Bitmap("PRESS", true); PR[1] = NULL; - SP[0] = new Bitmap("SPK_L"); - SP[1] = new Bitmap("SPK_R"); + SP[0] = new Bitmap("SPK_L", true); + SP[1] = new Bitmap("SPK_R", true); SP[2] = NULL; - LI[0] = new Bitmap("LITE0"); - LI[1] = new Bitmap("LITE1"); - LI[2] = new Bitmap("LITE2"); - LI[3] = new Bitmap("LITE3"); + LI[0] = new Bitmap("LITE0", true); + LI[1] = new Bitmap("LITE1", true); + LI[2] = new Bitmap("LITE2", true); + LI[3] = new Bitmap("LITE3", true); LI[4] = NULL; Snail = new SNAIL(this, false); Snail_ = new SNAIL(this, true); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 1e1b952f777..035c4dc3174 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -257,10 +257,10 @@ void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { for (st = _savTab; st->Ptr; st++) { if (file.Error) error("Bad SVG"); - file.Read((uint8 *)((tiny || st->Flg) ? st->Ptr : &i), st->Len); + file.read((uint8 *)((tiny || st->Flg) ? st->Ptr : &i), st->Len); } - file.Read((uint8 *) &i, sizeof(i)); + file.read((uint8 *) &i, sizeof(i)); if (i != SVGCHKSUM) error("%s", Text->getText(BADSVG_TEXT)); @@ -276,7 +276,7 @@ void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { if (! tiny) { // load sprites & pocket while (! file.Error) { Sprite S(this, NULL); - uint16 n = file.Read((uint8 *) &S, sizeof(S)); + uint16 n = file.read((uint8 *) &S, sizeof(S)); if (n != sizeof(S)) break; @@ -299,8 +299,9 @@ void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { static void SaveSound(void) { - CFILE cfg(UsrPath(ProgName(CFG_EXT)), WRI); - if (! cfg.Error) cfg.Write(&SNDDrvInfo, sizeof(SNDDrvInfo) - sizeof(SNDDrvInfo.VOL2)); + CFile cfg(UsrPath(ProgName(CFG_EXT)), WRI); + if (! cfg.Error) + cfg.write(&SNDDrvInfo, sizeof(SNDDrvInfo) - sizeof(SNDDrvInfo.VOL2)); } @@ -320,15 +321,15 @@ static void SaveGame(XFILE &file) { for (st = _savTab; st->Ptr; st++) { if (file.Error) error("Bad SVG"); - file.Write((uint8 *) st->Ptr, st->Len); + file.write((uint8 *) st->Ptr, st->Len); } - file.Write((uint8 *) & (i = SVGCHKSUM), sizeof(i)); + file.write((uint8 *) & (i = SVGCHKSUM), sizeof(i)); for (spr = Vga->SpareQ->First(); spr; spr = spr->_next) if (spr->_ref >= 1000) if (!file.Error) - file.Write((uint8 *)spr, sizeof(*spr)); + file.write((uint8 *)spr, sizeof(*spr)); } @@ -376,8 +377,8 @@ static void LoadMapping(void) { INI_FILE cf(ProgName(".TAB")); if (! cf.Error) { memset(CLUSTER::Map, 0, sizeof(CLUSTER::Map)); - cf.Seek((Now - 1) * sizeof(CLUSTER::Map)); - cf.Read((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); + cf.seek((Now - 1) * sizeof(CLUSTER::Map)); + cf.read((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); } } } @@ -675,9 +676,9 @@ void SYSTEM::FunTouch(void) { static void ShowBak(int ref) { Sprite *spr = Vga->SpareQ->Locate(ref); if (spr) { - Bitmap::Pal = VGA::SysPal; + Bitmap::_pal = VGA::SysPal; spr->Expand(); - Bitmap::Pal = NULL; + Bitmap::_pal = NULL; spr->Show(2); Vga->CopyPage(1, 2); Sys->SetPal(); @@ -776,7 +777,7 @@ void CGEEngine::QGame() { CaveDown(); OldLev = Lev; SaveSound(); - CFILE file = CFILE(UsrPath(UsrFnam), WRI, RCrypt); + CFile file = CFile(UsrPath(UsrFnam), WRI, RCrypt); SaveGame(file); Vga->Sunset(); Finis = true; @@ -1145,18 +1146,18 @@ static void NextStep(void) { static void SaveMapping(void) { { - IOHAND cf(ProgName(".TAB"), UPD); + IoHand cf(ProgName(".TAB"), UPD); if (!cf.Error) { - cf.Seek((Now - 1) * sizeof(CLUSTER::Map)); - cf.Write((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); + cf.seek((Now - 1) * sizeof(CLUSTER::Map)); + cf.write((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); } } { - IOHAND cf(ProgName(".HXY"), WRI); + IoHand cf(ProgName(".HXY"), WRI); if (!cf.Error) { HeroXY[Now - 1]._x = Hero->_x; HeroXY[Now - 1]._y = Hero->_y; - cf.Write((uint8 *) HeroXY, sizeof(HeroXY)); + cf.write((uint8 *) HeroXY, sizeof(HeroXY)); } } } @@ -1345,12 +1346,12 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int uint16 len; MergeExt(line, fname, SPR_EXT); - if (INI_FILE::Exist(line)) { // sprite description file exist + if (INI_FILE::exist(line)) { // sprite description file exist INI_FILE sprf(line); if (sprf.Error) error("Bad SPR [%s]", line); - while ((len = sprf.Read((uint8 *)line)) != 0) { + while ((len = sprf.read((uint8 *)line)) != 0) { ++ lcnt; if (len && line[len - 1] == '\n') line[-- len] = '\0'; @@ -1490,7 +1491,7 @@ void CGEEngine::LoadScript(const char *fname) { if (scrf.Error) return; - while (scrf.Read((uint8 *)line) != 0) { + while (scrf.read((uint8 *)line) != 0) { char *p; ++lcnt; @@ -1566,7 +1567,7 @@ void CGEEngine::MainLoop() { void CGEEngine::LoadUser() { // set scene if (STARTUP::Mode == 0) { // user .SVG file found - CFILE cfile = CFILE(UsrPath(UsrFnam), REA, RCrypt); + CFile cfile = CFile(UsrPath(UsrFnam), REA, RCrypt); LoadGame(cfile); } else { if (STARTUP::Mode == 1) { @@ -1575,7 +1576,7 @@ void CGEEngine::LoadUser() { } else { LoadScript(ProgName(INI_EXT)); Music = true; - CFILE file = CFILE(SVG0NAME, WRI); + CFile file = CFile(SVG0NAME, WRI); SaveGame(file); error("Ok [%s]", SVG0NAME); } @@ -1623,7 +1624,7 @@ void CGEEngine::RunGame() { if (! Music) KillMIDI(); - if (Mini && INI_FILE::Exist("MINI.SPR")) { + if (Mini && INI_FILE::exist("MINI.SPR")) { uint8 *ptr = (uint8 *) &*Mini; if (ptr != NULL) { LoadSprite("MINI", -1, 0, MINI_X, MINI_Y); @@ -1641,7 +1642,7 @@ void CGEEngine::RunGame() { if (Hero) { ExpandSprite(Hero); Hero->Goto(HeroXY[Now - 1]._x, HeroXY[Now - 1]._y); - if (INI_FILE::Exist("00SHADOW.SPR")) { + if (INI_FILE::exist("00SHADOW.SPR")) { LoadSprite("00SHADOW", -1, 0, Hero->_x + 14, Hero->_y + 51); if ((_shadow = _sprite) != NULL) { _shadow->_ref = 2; @@ -1698,7 +1699,7 @@ void CGEEngine::RunGame() { void CGEEngine::Movie(const char *ext) { const char *fn = ProgName(ext); - if (INI_FILE::Exist(fn)) { + if (INI_FILE::exist(fn)) { LoadScript(fn); ExpandSprite(Vga->SpareQ->Locate(999)); FeedSnail(Vga->ShowQ->Locate(999), TAKE); @@ -1722,9 +1723,9 @@ void CGEEngine::Movie(const char *ext) { bool CGEEngine::ShowTitle(const char *name) { - Bitmap::Pal = VGA::SysPal; - BMP_PTR LB[] = { new Bitmap(name), NULL }; - Bitmap::Pal = NULL; + Bitmap::_pal = VGA::SysPal; + BMP_PTR LB[] = { new Bitmap(name, true), NULL }; + Bitmap::_pal = NULL; bool usr_ok = false; Sprite D(this, LB); @@ -1774,7 +1775,7 @@ bool CGEEngine::ShowTitle(const char *name) { // Boot * b = ReadBoot(getdisk()); warning("ShowTitle: FIXME ReadBoot"); Boot *b = ReadBoot(0); - uint32 sn = (b->XSign == 0x29) ? b->Serial : b->lTotSecs; + uint32 sn = (b->_xSign == 0x29) ? b->_serial : b->_lTotSecs; free(b); sn -= ((IDENT *)Copr)->disk; STARTUP::Summa |= Lo(sn) | Hi(sn); @@ -1801,8 +1802,8 @@ bool CGEEngine::ShowTitle(const char *name) { if (usr_ok && STARTUP::Mode == 0) { const char *n = UsrPath(UsrFnam); - if (CFILE::Exist(n)) { - CFILE file = CFILE(n, REA, RCrypt); + if (CFile::exist(n)) { + CFile file = CFile(n, REA, RCrypt); LoadGame(file, true); // only system vars Vga->SetColors(VGA::SysPal, 64); Vga->Update(); @@ -1846,7 +1847,7 @@ void CGEEngine::cge_main(void) { if (!Mouse->Exist) error("%s", Text->getText(NO_MOUSE_TEXT)); - if (!SVG0FILE::Exist(SVG0NAME)) + if (!SVG0FILE::exist(SVG0NAME)) STARTUP::Mode = 2; DebugLine->_flags._hide = true; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 7bf753ff9f6..510456087f4 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -211,13 +211,13 @@ char *dwtom(uint32 val, char *str, int radix, int len) { return str; } -IOHAND::IOHAND(IOMODE mode, CRYPT *crpt) - : XFILE(mode), Crypt(crpt), Seed(SEED) { +IoHand::IoHand(IOMODE mode, CRYPT *crpt) + : XFILE(mode), _crypt(crpt), _seed(SEED) { _file = new Common::File(); } -IOHAND::IOHAND(const char *name, IOMODE mode, CRYPT *crpt) - : XFILE(mode), Crypt(crpt), Seed(SEED) { +IoHand::IoHand(const char *name, IOMODE mode, CRYPT *crpt) + : XFILE(mode), _crypt(crpt), _seed(SEED) { // TODO: Check if WRI and/or UPD modes are needed, and map to a save file assert(mode == REA); @@ -225,24 +225,24 @@ IOHAND::IOHAND(const char *name, IOMODE mode, CRYPT *crpt) _file->open(name); } -IOHAND::~IOHAND(void) { +IoHand::~IoHand(void) { _file->close(); delete _file; } -uint16 IOHAND::Read(void *buf, uint16 len) { +uint16 IoHand::read(void *buf, uint16 len) { if (Mode == WRI || !_file->isOpen()) return 0; uint16 bytesRead = _file->read(buf, len); if (!bytesRead) error("Read %s - %d bytes", _file->getName(), len); - if (Crypt) - Seed = Crypt(buf, len, Seed); + if (_crypt) + _seed = _crypt(buf, len, Seed); return bytesRead; } -uint16 IOHAND::Write(void *buf, uint16 len) { +uint16 IoHand::write(void *buf, uint16 len) { error("IOHAND::Write not supported"); /* if (len) { @@ -258,20 +258,20 @@ uint16 IOHAND::Write(void *buf, uint16 len) { */ } -long IOHAND::Mark(void) { +long IoHand::mark(void) { return _file->pos(); } -long IOHAND::Seek(long pos) { +long IoHand::seek(long pos) { _file->seek(pos, SEEK_SET); return _file->pos(); } -long IOHAND::Size(void) { +long IoHand::size(void) { return _file->size(); } -bool IOHAND::Exist(const char *name) { +bool IoHand::exist(const char *name) { Common::File f; return f.exists(name); } diff --git a/engines/cge/general.h b/engines/cge/general.h index 4946e40c7b7..1ecec9fbe99 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -168,36 +168,36 @@ public: uint16 Error; XFILE(void) : Mode(REA), Error(0) { } XFILE(IOMODE mode) : Mode(mode), Error(0) { } - virtual uint16 Read(void *buf, uint16 len) = 0; - virtual uint16 Write(void *buf, uint16 len) = 0; - virtual long Mark(void) = 0; - virtual long Size(void) = 0; - virtual long Seek(long pos) = 0; + virtual uint16 read(void *buf, uint16 len) = 0; + virtual uint16 write(void *buf, uint16 len) = 0; + virtual long mark(void) = 0; + virtual long size(void) = 0; + virtual long seek(long pos) = 0; virtual ~XFILE() { } }; template inline uint16 XRead(XFILE *xf, T *t) { - return xf->Read((uint8 *) t, sizeof(*t)); + return xf->read((uint8 *) t, sizeof(*t)); } -class IOHAND : public XFILE { +class IoHand : public XFILE { protected: Common::File *_file; - uint16 Seed; - CRYPT *Crypt; + uint16 _seed; + CRYPT *_crypt; public: - IOHAND(const char *name, IOMODE mode = REA, CRYPT crypt = NULL); - IOHAND(IOMODE mode = REA, CRYPT *crpt = NULL); - virtual ~IOHAND(void); - static bool Exist(const char *name); - uint16 Read(void *buf, uint16 len); - uint16 Write(void *buf, uint16 len); - long Mark(void); - long Size(void); - long Seek(long pos); + IoHand(const char *name, IOMODE mode = REA, CRYPT crypt = NULL); + IoHand(IOMODE mode = REA, CRYPT *crpt = NULL); + virtual ~IoHand(); + static bool exist(const char *name); + uint16 read(void *buf, uint16 len); + uint16 write(void *buf, uint16 len); + long mark(); + long size(); + long seek(long pos); //timeb Time (void); // void SetTime (timeb t); }; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 7b9ce59f5ed..a5ef5b8b624 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -42,7 +42,7 @@ bool MIXER::Appear = false; MIXER::MIXER(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), Fall(MIX_FALL), _vm(vm) { Appear = true; - mb[0] = new Bitmap("VOLUME"); + mb[0] = new Bitmap("VOLUME", true); mb[1] = NULL; SetShapeList(mb); SetName(Text->getText(MIX_NAME)); @@ -58,7 +58,7 @@ MIXER::MIXER(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), Fall(MIX_FALL), _v for (i = 0; i < MIX_MAX; i++) { static char fn[] = "V00"; wtom(i, fn + 1, 10, 2); - lb[i] = new Bitmap(fn); + lb[i] = new Bitmap(fn, true); ls[i].Now = ls[i].Next = i; ls[i].Dx = ls[i].Dy = ls[i].Dly = 0; } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 565c7d33f05..e9d9b4643ff 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -575,12 +575,12 @@ void SNSend(Sprite *spr, int val) { spr->_flags._slav = false; } else { if (spr->_ref % 1000 == 0) - Bitmap::Pal = VGA::SysPal; + Bitmap::_pal = VGA::SysPal; if (spr->_flags._back) spr->BackShow(true); else ExpandSprite(spr); - Bitmap::Pal = NULL; + Bitmap::_pal = NULL; } } } diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 4a7b63fb089..eecd3bacb26 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -187,14 +187,14 @@ void KillMIDI(void) { void LoadMIDI(int ref) { static char fn[] = "00.MID"; wtom(ref, fn, 10, 2); - if (INI_FILE::Exist(fn)) { + if (INI_FILE::exist(fn)) { KillMIDI(); INI_FILE mid = fn; if (mid.Error == 0) { - uint16 siz = (uint16) mid.Size(); + uint16 siz = (uint16) mid.size(); midi = new uint8[siz]; if (midi) { - mid.Read(midi, siz); + mid.read(midi, siz); if (mid.Error) KillMIDI(); else @@ -212,10 +212,10 @@ EC void *Patch(int pat) { wtom(pat, fn + 5, 10, 3); INI_FILE snd = fn; if (! snd.Error) { - uint16 siz = (uint16) snd.Size(); + uint16 siz = (uint16) snd.size(); p = (uint8 *) malloc(siz); if (p) { - snd.Read(p, siz); + snd.read(p, siz); if (snd.Error) { free(p); p = NULL; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 5aa5e44b8d4..c8aa8292e81 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -53,24 +53,24 @@ FONT::FONT(const char *name) { } -FONT::~FONT(void) { +FONT::~FONT() { free(Map); free(Pos); free(Wid); } -void FONT::Load(void) { +void FONT::Load() { INI_FILE f(Path); if (! f.Error) { - f.Read(Wid, WID_SIZ); + f.read(Wid, WID_SIZ); if (! f.Error) { uint16 i, p = 0; for (i = 0; i < POS_SIZ; i++) { Pos[i] = p; p += Wid[i]; } - f.Read(Map, p); + f.read(Map, p); } } } @@ -181,7 +181,7 @@ void TALK::Update(const char *tx) { } tx++; } - TS[0]->Code(); + TS[0]->code(); SetShapeList(TS); } diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 7b191b492b3..7df51f11265 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -45,7 +45,7 @@ TALK *Talk = NULL; TEXT::TEXT(CGEEngine *vm, const char *fname, int size) : _vm(vm) { Cache = new HAN[size]; MergeExt(FileName, fname, SAY_EXT); - if (!INI_FILE::Exist(FileName)) + if (!INI_FILE::exist(FileName)) error("No talk (%s)\n", FileName); for (Size = 0; Size < size; Size++) { @@ -93,7 +93,7 @@ void TEXT::Preload(int from, int upto) { char line[LINE_MAX + 1]; int n; - while ((n = tf.Read((uint8 *)line)) != 0) { + while ((n = tf.read((uint8 *)line)) != 0) { char *s; int ref; @@ -135,7 +135,7 @@ char *TEXT::Load(int idx, int ref) { char line[LINE_MAX + 1]; int n; - while ((n = tf.Read((uint8 *)line)) != 0) { + while ((n = tf.read((uint8 *)line)) != 0) { char *s; if (line[n - 1] == '\n') diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 673d6036d82..f26d202dcaa 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -417,7 +417,7 @@ BMP_PTR *Sprite::SetShapeList(BMP_PTR *shp) { void Sprite::MoveShapes(uint8 *buf) { BMP_PTR *p; for (p = _ext->_shpList; *p; p++) { - buf += (*p)->MoveVmap(buf); + buf += (*p)->moveVmap(buf); } } @@ -503,12 +503,12 @@ Sprite *Sprite::Expand(void) { SNAIL::COM *nea = NULL; SNAIL::COM *tak = NULL; MergeExt(fname, File, SPR_EXT); - if (INI_FILE::Exist(fname)) { // sprite description file exist + if (INI_FILE::exist(fname)) { // sprite description file exist INI_FILE sprf(fname); if (! (sprf.Error==0)) error("Bad SPR [%s]", fname); int len = 0, lcnt = 0; - while ((len = sprf.Read((uint8 *)line)) != 0) { + while ((len = sprf.read((uint8 *)line)) != 0) { ++lcnt; if (len && line[len - 1] == '\n') line[-- len] = '\0'; @@ -521,7 +521,7 @@ Sprite *Sprite::Expand(void) { break; } case 1 : { // Phase - shplist[shpcnt++] = new Bitmap(strtok(NULL, " \t,;/")); + shplist[shpcnt++] = new Bitmap(strtok(NULL, " \t,;/"), true); break; } case 2 : { // Seq @@ -583,7 +583,7 @@ Sprite *Sprite::Expand(void) { } } } else { // no sprite description: try to read immediately from .BMP - shplist[shpcnt++] = new Bitmap(File); + shplist[shpcnt++] = new Bitmap(File, true); } shplist[shpcnt] = NULL; if (seq) { @@ -748,9 +748,9 @@ void Sprite::Show(void) { // asm sti // ...done! if (!_flags._hide) { if (_flags._xlat) - e->_b1->XShow(e->_x1, e->_y1); + e->_b1->xShow(e->_x1, e->_y1); else - e->_b1->Show(e->_x1, e->_y1); + e->_b1->show(e->_x1, e->_y1); } } @@ -758,7 +758,7 @@ void Sprite::Show(void) { void Sprite::Show(uint16 pg) { Graphics::Surface *a = VGA::Page[1]; VGA::Page[1] = VGA::Page[pg & 3]; - Shp()->Show(_x, _y); + Shp()->show(_x, _y); VGA::Page[1] = a; } @@ -766,7 +766,7 @@ void Sprite::Show(uint16 pg) { void Sprite::Hide(void) { register SprExt *e = _ext; if (e->_b0) - e->_b0->Hide(e->_x0, e->_y0); + e->_b0->hide(e->_x0, e->_y0); } @@ -795,7 +795,7 @@ Sprite *SpriteAt(int x, int y) { if (tail) { for (spr = tail->_prev; spr; spr = spr->_prev) { if (! spr->_flags._hide && ! spr->_flags._tran) { - if (spr->Shp()->SolidAt(x - spr->_x, y - spr->_y)) + if (spr->Shp()->solidAt(x - spr->_x, y - spr->_y)) break; } } @@ -1178,7 +1178,7 @@ void VGA::CopyPage(uint16 d, uint16 s) { //-------------------------------------------------------------------------- -void Bitmap::XShow(int x, int y) { +void Bitmap::xShow(int x, int y) { /* uint8 rmsk = x % 4, mask = 1 << rmsk, @@ -1256,11 +1256,11 @@ void Bitmap::XShow(int x, int y) { asm pop si asm pop bx */ - warning("STUB: BITMAP::XShow"); + warning("STUB: BITMAP::xShow"); } -void Bitmap::Show(int x, int y) { +void Bitmap::show(int x, int y) { const byte *srcP = (const byte *)_v; byte *destEndP = (byte *)VGA::Page[1]->pixels + (SCR_WID * SCR_HIG); @@ -1322,7 +1322,7 @@ void Bitmap::Show(int x, int y) { } -void Bitmap::Hide(int x, int y) { +void Bitmap::hide(int x, int y) { /* uint8 *scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; uint16 d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); @@ -1385,7 +1385,7 @@ void Bitmap::Hide(int x, int y) { asm pop si // asm pop bx */ - warning("STUB: Bitmap::Hide"); + warning("STUB: Bitmap::hide"); } } // End of namespace CGE diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index c76914c0039..8170bd5980a 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -34,9 +34,9 @@ namespace CGE { -DAT *VFILE::_Dat = NULL; -BTFILE *VFILE::_Cat = NULL; -VFILE *VFILE::_Recent = NULL; +DAT *VFILE::_dat = NULL; +BtFile *VFILE::_cat = NULL; +VFILE *VFILE::_recent = NULL; /*-----------------------------------------------------------------------*/ @@ -52,30 +52,30 @@ DAT::DAT(): /*-----------------------------------------------------------------------*/ void VFILE::init() { - _Dat = new DAT(); + _dat = new DAT(); #ifdef VOL_UPD - _Cat = new BTFILE(CAT_NAME, UPD, CRP); + _cat = new BtFile(CAT_NAME, UPD, CRP); #else - _Cat = new BTFILE(CAT_NAME, REA, CRP); + _cat = new BtFile(CAT_NAME, REA, CRP); #endif - _Recent = NULL; + _recent = NULL; } void VFILE::deinit() { - delete _Dat; - delete _Cat; + delete _dat; + delete _cat; } VFILE::VFILE(const char *name, IOMODE mode) - : IOBUF(mode) { + : IoBuf(mode) { if (mode == REA) { - if (_Dat->_File.Error || _Cat->Error) + if (_dat->_File.Error || _cat->Error) error("Bad volume data"); - BT_KEYPACK *kp = _Cat->Find(name); - if (scumm_stricmp(kp->Key, name) != 0) + BtKeypack *kp = _cat->find(name); + if (scumm_stricmp(kp->_key, name) != 0) Error = 1; - EndMark = (BufMark = BegMark = kp->Mark) + kp->Size; + _endMark = (_bufMark = _begMark = kp->_mark) + kp->_size; } #ifdef VOL_UPD else @@ -85,27 +85,27 @@ VFILE::VFILE(const char *name, IOMODE mode) VFILE::~VFILE(void) { - if (_Recent == this) - _Recent = NULL; + if (_recent == this) + _recent = NULL; } -bool VFILE::Exist(const char *name) { - return scumm_stricmp(_Cat->Find(name)->Key, name) == 0; +bool VFILE::exist(const char *name) { + return scumm_stricmp(_cat->find(name)->_key, name) == 0; } -void VFILE::ReadBuff(void) { - if (_Recent != this) { - _Dat->_File.Seek(BufMark + Lim); - _Recent = this; +void VFILE::readBuff(void) { + if (_recent != this) { + _dat->_File.seek(_bufMark + _lim); + _recent = this; } - BufMark = _Dat->_File.Mark(); - long n = EndMark - BufMark; + _bufMark = _dat->_File.mark(); + long n = _endMark - _bufMark; if (n > IOBUF_SIZE) n = IOBUF_SIZE; - Lim = _Dat->_File.Read(Buff, (uint16) n); - Ptr = 0; + _lim = _dat->_File.read(_buff, (uint16) n); + _ptr = 0; } } // End of namespace CGE diff --git a/engines/cge/vol.h b/engines/cge/vol.h index a910aa72094..c2e676130e6 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -45,7 +45,7 @@ namespace CGE { #ifdef VOL_UPD #define VOLBASE IOHAND #else -#define VOLBASE CFILE +#define VOLBASE CFile #endif @@ -55,40 +55,42 @@ class DAT { public: DAT(); - bool Append(uint8 *buf, uint16 len); - bool Write(CFILE &f); - bool Read(long org, uint16 len, uint8 *buf); + bool append(uint8 *buf, uint16 len); + bool write(CFile &f); + bool read(long org, uint16 len, uint8 *buf); }; -class VFILE : public IOBUF { +class VFILE : public IoBuf { private: - static DAT *_Dat; - static BTFILE *_Cat; - static VFILE *_Recent; + static DAT *_dat; + static BtFile *_cat; + static VFILE *_recent; - long BegMark, EndMark; - void ReadBuff(void); - void WriteBuff(void) { } - void Make(const char *fspec); + long _begMark; + long _endMark; + + void readBuff(void); + void writeBuff(void) { } + void make(const char *fspec); public: VFILE(const char *name, IOMODE mode = REA); ~VFILE(void); static void init(); static void deinit(); - static bool Exist(const char *name); - static const char *Next(void); - long Mark(void) { - return (BufMark + Ptr) - BegMark; + static bool exist(const char *name); + static const char *next(void); + long mark(void) { + return (_bufMark + _ptr) - _begMark; } - long Size(void) { - return EndMark - BegMark; + long size(void) { + return _endMark - _begMark; } - long Seek(long pos) { - _Recent = NULL; - Lim = 0; - return (BufMark = BegMark + pos); + long seek(long pos) { + _recent = NULL; + _lim = 0; + return (_bufMark = _begMark + pos); } }; diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 304c2827d8f..3423c430338 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -58,7 +58,7 @@ public: Id = d; } CKID(XFILE *xf) { - (ckFile = xf)->Read(Tx, sizeof(Tx)); + (ckFile = xf)->read(Tx, sizeof(Tx)); } bool operator !=(CKID &X) { return Id != X.Id; From 0000a3139a7c1d3ddf993741d4e0aa0c7ac3d760 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 1 Jul 2011 08:37:40 +0200 Subject: [PATCH 046/276] CGE: Some more renaming (wip) --- engines/cge/bitmap.cpp | 54 ++++---- engines/cge/bitmap.h | 8 +- engines/cge/btfile.cpp | 6 +- engines/cge/btfile.h | 4 +- engines/cge/cfile.cpp | 14 +- engines/cge/cge.h | 50 +++---- engines/cge/cge_main.cpp | 274 +++++++++++++++++++-------------------- engines/cge/cge_main.h | 34 ++--- engines/cge/config.cpp | 94 +++++++------- engines/cge/config.h | 2 +- engines/cge/ems.cpp | 28 ++-- engines/cge/game.cpp | 44 +++---- engines/cge/game.h | 29 +++-- engines/cge/general.cpp | 28 ++-- engines/cge/general.h | 109 ++++++++-------- engines/cge/snail.cpp | 28 ++-- engines/cge/sound.cpp | 10 +- engines/cge/talk.cpp | 4 +- engines/cge/text.cpp | 6 +- engines/cge/vga13h.cpp | 72 +++++----- engines/cge/vga13h.h | 31 ++--- engines/cge/vol.cpp | 4 +- engines/cge/wav.h | 8 +- 23 files changed, 473 insertions(+), 468 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 30684999756..64a89e93810 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -35,7 +35,7 @@ namespace CGE { -DAC *Bitmap::_pal = NULL; +Dac *Bitmap::_pal = NULL; #define MAXPATH 128 void Bitmap::init() { @@ -53,7 +53,7 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { #if (BMP_MODE < 2) if (rem && PIC_FILE::exist(pat)) { PIC_FILE file(pat); - if ((file.Error == 0) && (!loadVBM(&file))) + if ((file._error == 0) && (!loadVBM(&file))) error("Bad VBM [%s]", fname); } else #endif @@ -61,7 +61,7 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { #if (BMP_MODE) ForceExt(pat, fname, ".BMP"); PIC_FILE file(pat); - if (file.Error == 0) { + if (file._error == 0) { if (loadBMP(&file)) { Code(); if (rem) { @@ -366,47 +366,47 @@ bool Bitmap::solidAt(int x, int y) { } -bool Bitmap::saveVBM(XFILE *f) { +bool Bitmap::saveVBM(XFile *f) { uint16 p = (_pal != NULL), n = ((uint16)(((uint8 *)_b) - _v)) + _h * sizeof(HideDesc); - if (f->Error == 0) + if (f->_error == 0) f->write((uint8 *)&p, sizeof(p)); - if (f->Error == 0) + if (f->_error == 0) f->write((uint8 *)&n, sizeof(n)); - if (f->Error == 0) + if (f->_error == 0) f->write((uint8 *)&_w, sizeof(_w)); - if (f->Error == 0) + if (f->_error == 0) f->write((uint8 *)&_h, sizeof(_h)); - if (f->Error == 0) + if (f->_error == 0) if (p) f->write((uint8 *)_pal, 256 * 3); - if (f->Error == 0) + if (f->_error == 0) f->write(_v, n); - return (f->Error == 0); + return (f->_error == 0); } -bool Bitmap::loadVBM(XFILE *f) { +bool Bitmap::loadVBM(XFile *f) { uint16 p = 0, n = 0; - if (f->Error == 0) + if (f->_error == 0) f->read((uint8 *)&p, sizeof(p)); - if (f->Error == 0) + if (f->_error == 0) f->read((uint8 *)&n, sizeof(n)); - if (f->Error == 0) + if (f->_error == 0) f->read((uint8 *)&_w, sizeof(_w)); - if (f->Error == 0) + if (f->_error == 0) f->read((uint8 *)&_h, sizeof(_h)); - if (f->Error == 0) { + if (f->_error == 0) { if (p) { if (_pal) { byte palData[PAL_SIZ]; @@ -419,14 +419,14 @@ bool Bitmap::loadVBM(XFILE *f) { if ((_v = farnew(uint8, n)) == NULL) return false; - if (f->Error == 0) + if (f->_error == 0) f->read(_v, n); _b = (HideDesc *)(_v + n - _h * sizeof(HideDesc)); - return (f->Error == 0); + return (f->_error == 0); } -bool Bitmap::loadBMP(XFILE * f) { +bool Bitmap::loadBMP(XFile *f) { struct { char BM[2]; union { int16 len; int32 len_; }; @@ -446,16 +446,16 @@ bool Bitmap::loadBMP(XFILE * f) { BGR4 bpal[256]; f->read((byte *)&hea, sizeof(hea)); - if (f->Error == 0) { + if (f->_error == 0) { if (hea.hdr == 0x436L) { int16 i = (hea.hdr - sizeof(hea)) / sizeof(BGR4); f->read((byte *)&bpal, sizeof(bpal)); - if (f->Error == 0) { + if (f->_error == 0) { if (_pal) { for (i = 0; i < 256; i ++) { - _pal[i].R = bpal[i].R; - _pal[i].G = bpal[i].G; - _pal[i].B = bpal[i].B; + _pal[i]._r = bpal[i].R; + _pal[i]._g = bpal[i].G; + _pal[i]._b = bpal[i].B; } _pal = NULL; } @@ -466,9 +466,9 @@ bool Bitmap::loadBMP(XFILE * f) { byte buf[3]; int i; for (i = _h - 1; i >= 0; i--) { f->read(_m + (_w * i), _w); - if (r && f->Error == 0) + if (r && f->_error == 0) f->read(buf, r); - if (f->Error) + if (f->_error) break; } if (i < 0) diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index b13912a3c6e..99464bffeb2 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -60,10 +60,10 @@ struct HideDesc { #include "common/pack-end.h" class Bitmap { - bool loadBMP(XFILE *f); - bool loadVBM(XFILE *f); + bool loadBMP(XFile *f); + bool loadVBM(XFile *f); public: - static DAC *_pal; + static Dac *_pal; uint16 _w; uint16 _h; uint8 *_m; @@ -85,7 +85,7 @@ public: void show(int x, int y); void xShow(int x, int y); bool solidAt(int x, int y); - bool saveVBM(XFILE *f); + bool saveVBM(XFile *f); uint16 moveVmap(uint8 *buf); }; diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 8255775fd14..18bd2d72e7c 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -55,7 +55,7 @@ BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt) BtFile::~BtFile(void) { for (int i = 0; i < BT_LEVELS; i++) { - putPage(i); + putPage(i, false); delete _buff[i]._page; } } @@ -73,7 +73,7 @@ void BtFile::putPage(int lev, bool hard) { BtPage *BtFile::getPage(int lev, uint16 pgn) { if (_buff[lev]._pgNo != pgn) { int32 pos = pgn * sizeof(BtPage); - putPage(lev); + putPage(lev, false); _buff[lev]._pgNo = pgn; if (size() > pos) { seek((uint32) pgn * sizeof(BtPage)); @@ -93,7 +93,7 @@ BtPage *BtFile::getPage(int lev, uint16 pgn) { BtKeypack *BtFile::find(const char *key) { int lev = 0; uint16 nxt = BT_ROOT; - while (! Error) { + while (!_error) { BtPage *pg = getPage(lev, nxt); // search if (pg->_hea._down != BT_NONE) { diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 3fd31757984..ac05c3a7e78 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -80,10 +80,10 @@ class BtFile : public IoHand { bool _updt; } _buff[BT_LEVELS]; - void putPage(int lev, bool hard = false); + void putPage(int lev, bool hard); BtPage *getPage(int lev, uint16 pgn); public: - BtFile(const char *name, IOMODE mode = REA, CRYPT *crpt = NULL); + BtFile(const char *name, IOMODE mode, CRYPT *crpt); virtual ~BtFile(); BtKeypack *find(const char *key); BtKeypack *next(); diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 9a2b697bd70..ee2aecbc42b 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -54,7 +54,7 @@ IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt) } IoBuf::~IoBuf(void) { - if (Mode > REA) + if (_mode > REA) writeBuff(); if (_buff) free(_buff); @@ -210,7 +210,7 @@ CFile::~CFile(void) { void CFile::flush(void) { - if (Mode > REA) + if (_mode > REA) writeBuff(); else _lim = 0; @@ -225,16 +225,16 @@ void CFile::flush(void) { long CFile::mark(void) { - return _bufMark + ((Mode > REA) ? _lim : _ptr); + return _bufMark + ((_mode > REA) ? _lim : _ptr); } long CFile::seek(long pos) { if (pos >= _bufMark && pos < _bufMark + _lim) { - ((Mode == REA) ? _ptr : _lim) = (uint16)(pos - _bufMark); + ((_mode == REA) ? _ptr : _lim) = (uint16)(pos - _bufMark); return pos; } else { - if (Mode > REA) + if (_mode > REA) writeBuff(); else _lim = 0; @@ -247,13 +247,13 @@ long CFile::seek(long pos) { void CFile::append(CFile &f) { seek(size()); - if (f.Error == 0) { + if (f._error == 0) { while (true) { if ((_lim = f.IoHand::read(_buff, IOBUF_SIZE)) == IOBUF_SIZE) writeBuff(); else break; - if ((Error = f.Error) != 0) + if ((_error = f._error) != 0) break; } } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index c3f241b2fe2..06c7fb23267 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -56,40 +56,40 @@ public: } void cge_main(); - void SwitchCave(int cav); - void StartCountDown(); - void Quit(); - void ResetQSwitch(); - void OptionTouch(int opt, uint16 mask); - void LoadGame(XFILE &file, bool tiny); - void SetMapBrick(int x, int z); - void SwitchMapping(); - void LoadSprite(const char *fname, int ref, int cav, int col, int row, int pos); - void LoadScript(const char *fname); - void LoadUser(); - void RunGame(); - bool ShowTitle(const char *name); - void Movie(const char *ext); - void TakeName(); - void Inf(const char *txt); - void SelectSound(); + void switchCave(int cav); + void startCountDown(); + void quit(); + void resetQSwitch(); + void optionTouch(int opt, uint16 mask); + void loadGame(XFile &file, bool tiny); + void setMapBrick(int x, int z); + void switchMapping(); + void loadSprite(const char *fname, int ref, int cav, int col, int row, int pos); + void loadScript(const char *fname); + void loadUser(); + void runGame(); + bool showTitle(const char *name); + void movie(const char *ext); + void takeName(); + void inf(const char *txt); + void selectSound(); void SNSelect(); void dummy() {} void NONE(); void SB(); - void CaveDown(); - void XCave(); - void QGame(); + void caveDown(); + void xCave(); + void qGame(); void SBM(); void GUS(); void GUSM(); void MIDI(); void AUTO(); - void SetPortD(); - void SetPortM(); - void SetIRQ(); - void SetDMA(); - void MainLoop(); + void setPortD(); + void setPortM(); + void setIRQ(); + void setDMA(); + void mainLoop(); private: CGEConsole *_console; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 035c4dc3174..2d4f004632a 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -133,7 +133,7 @@ bool JBW = false; //------------------------------------------------------------------------- int PocPtr = 0; -static EMS *Mini = MiniEmm.Alloc((uint16)MINI_EMM_SIZE); +static EMS *Mini = MiniEmm.alloc((uint16)MINI_EMM_SIZE); static BMP_PTR *MiniShpList = NULL; static BMP_PTR MiniShp[] = { NULL, NULL }; static KEYBOARD Keyboard; @@ -148,18 +148,18 @@ BAR Barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; extern int FindPocket(Sprite *); -extern DAC StdPal[58]; +extern Dac _stdPal[58]; void FeedSnail(Sprite *spr, SNLIST snq); // defined in SNAIL -uint8 CLUSTER::Map[MAP_ZCNT][MAP_XCNT]; +uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; -uint8 &CLUSTER::Cell(void) { - return Map[B][A]; +uint8 &Cluster::cell(void) { + return _map[_b][_a]; } -bool CLUSTER::Protected(void) { +bool Cluster::Protected(void) { /* if (A == Barriers[Now].Vert || B == Barriers[Now].Horz) return true; @@ -202,20 +202,20 @@ bool CLUSTER::Protected(void) { } -CLUSTER XZ(int x, int y) { +Cluster XZ(int x, int y) { if (y < MAP_TOP) y = MAP_TOP; if (y > MAP_TOP + MAP_HIG - MAP_ZGRID) y = MAP_TOP + MAP_HIG - MAP_ZGRID; - return CLUSTER(x / MAP_XGRID, (y - MAP_TOP) / MAP_ZGRID); + return Cluster(x / MAP_XGRID, (y - MAP_TOP) / MAP_ZGRID); } -CLUSTER XZ(COUPLE xy) { +Cluster XZ(Couple xy) { signed char x, y; - xy.Split(x, y); + xy.split(x, y); return XZ(x, y); } @@ -249,13 +249,13 @@ SavTab _savTab[] = { }; -void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { +void CGEEngine::loadGame(XFile &file, bool tiny = false) { SavTab *st; Sprite *spr; int i; for (st = _savTab; st->Ptr; st++) { - if (file.Error) + if (file._error) error("Bad SVG"); file.read((uint8 *)((tiny || st->Flg) ? st->Ptr : &i), st->Len); } @@ -274,7 +274,7 @@ void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { } if (! tiny) { // load sprites & pocket - while (! file.Error) { + while (!file._error) { Sprite S(this, NULL); uint16 n = file.read((uint8 *) &S, sizeof(S)); @@ -282,7 +282,7 @@ void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { break; S._prev = S._next = NULL; - spr = (scumm_stricmp(S.File + 2, "MUCHA") == 0) ? new FLY(this, NULL) + spr = (scumm_stricmp(S.File + 2, "MUCHA") == 0) ? new Fly(this, NULL) : new Sprite(this, NULL); if (spr == NULL) error("No core"); @@ -300,12 +300,12 @@ void CGEEngine::LoadGame(XFILE &file, bool tiny = false) { static void SaveSound(void) { CFile cfg(UsrPath(ProgName(CFG_EXT)), WRI); - if (! cfg.Error) + if (!cfg._error) cfg.write(&SNDDrvInfo, sizeof(SNDDrvInfo) - sizeof(SNDDrvInfo.VOL2)); } -static void SaveGame(XFILE &file) { +static void SaveGame(XFile &file) { SavTab *st; Sprite *spr; int i; @@ -319,7 +319,7 @@ static void SaveGame(XFILE &file) { volume[1] = SNDDrvInfo.VOL2.M; for (st = _savTab; st->Ptr; st++) { - if (file.Error) + if (file._error) error("Bad SVG"); file.write((uint8 *) st->Ptr, st->Len); } @@ -328,7 +328,7 @@ static void SaveGame(XFILE &file) { for (spr = Vga->SpareQ->First(); spr; spr = spr->_next) if (spr->_ref >= 1000) - if (!file.Error) + if (!file._error) file.write((uint8 *)spr, sizeof(*spr)); } @@ -339,7 +339,7 @@ static void HeroCover(int cvr) { static void Trouble(int seq, int txt) { - Hero->Park(); + Hero->park(); SNPOST(SNWAIT, -1, -1, Hero); SNPOST(SNSEQ, -1, seq, Hero); SNPOST(SNSOUND, -1, 2, Hero); @@ -359,7 +359,7 @@ static void TooFar(void) { // Used in stubbed function, do not remove! -static void NoWay(void) { +static void noWay() { Trouble(NO_WAY, NO_WAY_TEXT); } @@ -367,7 +367,7 @@ static void NoWay(void) { static void LoadHeroXY(void) { INI_FILE cf(ProgName(".HXY")); memset(HeroXY, 0, sizeof(HeroXY)); - if (! cf.Error) + if (!cf._error) cf.CFREAD(&HeroXY); } @@ -375,35 +375,35 @@ static void LoadHeroXY(void) { static void LoadMapping(void) { if (Now <= CAVE_MAX) { INI_FILE cf(ProgName(".TAB")); - if (! cf.Error) { - memset(CLUSTER::Map, 0, sizeof(CLUSTER::Map)); - cf.seek((Now - 1) * sizeof(CLUSTER::Map)); - cf.read((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); + if (!cf._error) { + memset(Cluster::_map, 0, sizeof(Cluster::_map)); + cf.seek((Now - 1) * sizeof(Cluster::_map)); + cf.read((uint8 *) Cluster::_map, sizeof(Cluster::_map)); } } } -CLUSTER Trace[MAX_FIND_LEVEL]; +Cluster Trace[MAX_FIND_LEVEL]; int FindLevel; WALK::WALK(CGEEngine *vm, BMP_PTR *shpl) - : Sprite(vm, shpl), Dir(NO_DIR), TracePtr(-1), _vm(vm) { + : Sprite(vm, shpl), Dir(NO_DIR), _tracePtr(-1), _vm(vm) { } -void WALK::Tick(void) { +void WALK::tick() { if (_flags._hide) return; - Here = XZ(_x + _w / 2, _y + _h); + _here = XZ(_x + _w / 2, _y + _h); if (Dir != NO_DIR) { Sprite *spr; Sys->FunTouch(); for (spr = Vga->ShowQ->First(); spr; spr = spr->_next) { - if (Distance(spr) < 2) { + if (distance(spr) < 2) { if (!spr->_flags._near) { FeedSnail(spr, NEAR); spr->_flags._near = true; @@ -414,33 +414,33 @@ void WALK::Tick(void) { } } - if (_flags._hold || TracePtr < 0) - Park(); + if (_flags._hold || _tracePtr < 0) + park(); else { - if (Here == Trace[TracePtr]) { - if (--TracePtr < 0) - Park(); + if (_here == Trace[_tracePtr]) { + if (--_tracePtr < 0) + park(); } else { signed char dx, dz; - (Trace[TracePtr] - Here).Split(dx, dz); + (Trace[_tracePtr] - _here).split(dx, dz); DIR d = (dx) ? ((dx > 0) ? EE : WW) : ((dz > 0) ? SS : NN); - Turn(d); + turn(d); } } Step(); if ((Dir == WW && _x <= 0) || (Dir == EE && _x + _w >= SCR_WID) || (Dir == SS && _y + _w >= WORLD_HIG - 2)) - Park(); + park(); else { signed char x; // dummy var - Here.Split(x, _z); // take current Z position + _here.split(x, _z); // take current Z position SNPOST_(SNZTRIM, -1, 0, this); // update Hero's pos in show queue } } -int WALK::Distance(Sprite *spr) { +int WALK::distance(Sprite *spr) { int dx, dz; dx = spr->_x - (_x + _w - WALKSIDE); if (dx < 0) @@ -462,7 +462,7 @@ int WALK::Distance(Sprite *spr) { } -void WALK::Turn(DIR d) { +void WALK::turn(DIR d) { DIR dir = (Dir == NO_DIR) ? SS : Dir; if (d != Dir) { Step((d == dir) ? (1 + dir + dir) : (9 + 4 * dir + d)); @@ -471,20 +471,20 @@ void WALK::Turn(DIR d) { } -void WALK::Park(void) { +void WALK::park(void) { if (_time == 0) ++_time; if (Dir != NO_DIR) { Step(9 + 4 * Dir + Dir); Dir = NO_DIR; - TracePtr = -1; + _tracePtr = -1; } } -void WALK::FindWay(CLUSTER c) { - warning("STUB: Find1Way"); +void WALK::findWay(Cluster c) { + warning("STUB: WALK::findWay"); /* bool Find1Way(void); extern uint16 Target; @@ -508,7 +508,7 @@ void WALK::FindWay(CLUSTER c) { } -void WALK::FindWay(Sprite *spr) { +void WALK::findWay(Sprite *spr) { if (spr && spr != this) { int x = spr->_x; int z = spr->_z; @@ -516,24 +516,24 @@ void WALK::FindWay(Sprite *spr) { x += spr->_w + _w / 2 - WALKSIDE; else x -= _w / 2 - WALKSIDE; - FindWay(CLUSTER((x / MAP_XGRID), + findWay(Cluster((x / MAP_XGRID), ((z < MAP_ZCNT - MAX_DISTANCE) ? (z + 1) : (z - 1)))); } } -bool WALK::Lower(Sprite *spr) { +bool WALK::lower(Sprite *spr) { return (spr->_y > _y + (_h * 3) / 5); } -void WALK::Reach(Sprite *spr, int mode) { +void WALK::reach(Sprite *spr, int mode) { if (spr) { - Hero->FindWay(spr); + Hero->findWay(spr); if (mode < 0) { mode = spr->_flags._east; - if (Lower(spr)) + if (lower(spr)) mode += 2; } } @@ -568,20 +568,20 @@ SQUARE::SQUARE(CGEEngine *vm) void SQUARE::Touch(uint16 mask, int x, int y) { Sprite::Touch(mask, x, y); if (mask & L_UP) { - XZ(_x + x, _y + y).Cell() = 0; + XZ(_x + x, _y + y).cell() = 0; SNPOST_(SNKILL, -1, 0, this); } } -void CGEEngine::SetMapBrick(int x, int z) { +void CGEEngine::setMapBrick(int x, int z) { SQUARE *s = new SQUARE(this); if (s) { static char n[] = "00:00"; s->Goto(x * MAP_XGRID, MAP_TOP + z * MAP_ZGRID); wtom(x, n + 0, 10, 2); wtom(z, n + 3, 10, 2); - CLUSTER::Map[z][x] = 1; + Cluster::_map[z][x] = 1; s->SetName(n); Vga->ShowQ->Insert(s, Vga->ShowQ->First()); } @@ -601,23 +601,23 @@ static void KeyClick(void) { } -void CGEEngine::ResetQSwitch() { +void CGEEngine::resetQSwitch() { SNPOST_(SNSEQ, 123, 0, NULL); KeyClick(); } -void CGEEngine::Quit() { +void CGEEngine::quit() { static CHOICE QuitMenu[] = { - { NULL, &CGEEngine::StartCountDown }, - { NULL, &CGEEngine::ResetQSwitch }, + { NULL, &CGEEngine::startCountDown }, + { NULL, &CGEEngine::resetQSwitch }, { NULL, &CGEEngine::dummy } }; if (Snail->Idle() && ! Hero->_flags._hide) { if (VMENU::Addr) { SNPOST_(SNKILL, -1, 0, VMENU::Addr); - ResetQSwitch(); + resetQSwitch(); } else { QuitMenu[0].Text = Text->getText(QUIT_TEXT); QuitMenu[1].Text = Text->getText(NOQUIT_TEXT); @@ -634,7 +634,7 @@ static void AltCtrlDel(void) { } // Used in stubbed function, do not remove! -static void MiniStep(int stp) { +static void miniStep(int stp) { if (stp < 0) _miniCave->_flags._hide = true; else { @@ -657,11 +657,11 @@ static void PostMiniStep(int stp) { void SYSTEM::SetPal(void) { uint i; - DAC *p = VGA::SysPal + 256 - ArrayCount(StdPal); - for (i = 0; i < ArrayCount(StdPal); i++) { - p[i].R = StdPal[i].R >> 2; - p[i].G = StdPal[i].G >> 2; - p[i].B = StdPal[i].B >> 2; + Dac *p = VGA::SysPal + 256 - ArrayCount(_stdPal); + for (i = 0; i < ArrayCount(_stdPal); i++) { + p[i]._r = _stdPal[i]._r >> 2; + p[i]._g = _stdPal[i]._g >> 2; + p[i]._b = _stdPal[i]._b >> 2; } } @@ -687,7 +687,7 @@ static void ShowBak(int ref) { } -static void CaveUp(void) { +static void caveUp() { int BakRef = 1000 * Now; if (Music) LoadMIDI(Now); @@ -732,7 +732,7 @@ static void CaveUp(void) { if (_shadow) { Vga->ShowQ->Remove(_shadow); - _shadow->MakeXlat(Glass(VGA::SysPal, 204, 204, 204)); + _shadow->MakeXlat(glass(VGA::SysPal, 204, 204, 204)); Vga->ShowQ->Insert(_shadow, Hero); _shadow->_z = Hero->_z; } @@ -749,10 +749,10 @@ static void CaveUp(void) { } -void CGEEngine::CaveDown() { +void CGEEngine::caveDown() { Sprite *spr; if (!_horzLine->_flags._hide) - SwitchMapping(); + switchMapping(); for (spr = Vga->ShowQ->First(); spr;) { Sprite *n = spr->_next; @@ -767,14 +767,14 @@ void CGEEngine::CaveDown() { } -void CGEEngine::XCave() { - CaveDown(); - CaveUp(); +void CGEEngine::xCave() { + caveDown(); + caveUp(); } -void CGEEngine::QGame() { - CaveDown(); +void CGEEngine::qGame() { + caveDown(); OldLev = Lev; SaveSound(); CFile file = CFile(UsrPath(UsrFnam), WRI, RCrypt); @@ -784,7 +784,7 @@ void CGEEngine::QGame() { } -void CGEEngine::SwitchCave(int cav) { +void CGEEngine::switchCave(int cav) { if (cav != Now) { _heart->_enable = false; if (cav < 0) { @@ -796,7 +796,7 @@ void CGEEngine::SwitchCave(int cav) { Now = cav; Mouse->Off(); if (Hero) { - Hero->Park(); + Hero->park(); Hero->Step(0); if (!_isDemo) ///// protection: auto-destruction on! ---------------------- @@ -865,7 +865,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { if (KEYBOARD::Key[ALT]) SaveMapping(); else - _vm->SwitchMapping(); + _vm->switchMapping(); break; case F1: SwitchDebug(); @@ -914,7 +914,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { break; case F10 : if (Snail->Idle() && ! Hero->_flags._hide) - _vm->StartCountDown(); + _vm->startCountDown(); break; case 'J': if (pp == 0) @@ -958,21 +958,21 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { PostMiniStep(cav - 1); if (mask & L_UP) { - if (cav && Snail->Idle() && Hero->TracePtr < 0) - _vm->SwitchCave(cav); + if (cav && Snail->Idle() && Hero->_tracePtr < 0) + _vm->switchCave(cav); if (!_horzLine->_flags._hide) { if (y >= MAP_TOP && y < MAP_TOP + MAP_HIG) { int8 x1, z1; - XZ(x, y).Split(x1, z1); - CLUSTER::Map[z1][x1] = 1; - _vm->SetMapBrick(x1, z1); + XZ(x, y).split(x1, z1); + Cluster::_map[z1][x1] = 1; + _vm->setMapBrick(x1, z1); } } else { if (! Talk && Snail->Idle() && Hero && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && ! Game) { - Hero->FindWay(XZ(x, y)); + Hero->findWay(XZ(x, y)); } } } @@ -1042,7 +1042,7 @@ static void SwitchMusic(void) { else { SNPOST_(SNSEQ, 122, (Music = false), NULL); //TODO Change the SNPOST message send to a special way to send function pointer - // SNPOST(SNEXEC, -1, 0, (void *)&SelectSound); + // SNPOST(SNEXEC, -1, 0, (void *)&selectSound); warning("SwitchMusic() - SNPOST"); } } else { @@ -1060,13 +1060,13 @@ static void SwitchMusic(void) { } -void CGEEngine::StartCountDown() { +void CGEEngine::startCountDown() { //SNPOST(SNSEQ, 123, 0, NULL); - SwitchCave(-1); + switchCave(-1); } -void CGEEngine::TakeName() { +void CGEEngine::takeName() { if (GET_TEXT::Ptr) SNPOST_(SNKILL, -1, 0, GET_TEXT::Ptr); else { @@ -1082,14 +1082,14 @@ void CGEEngine::TakeName() { } -void CGEEngine::SwitchMapping() { +void CGEEngine::switchMapping() { if (_horzLine->_flags._hide) { int i; for (i = 0; i < MAP_ZCNT; i++) { int j; for (j = 0; j < MAP_XCNT; j++) { - if (CLUSTER::Map[i][j]) - SetMapBrick(j, i); + if (Cluster::_map[i][j]) + setMapBrick(j, i); } } } else { @@ -1144,17 +1144,17 @@ static void NextStep(void) { } -static void SaveMapping(void) { +static void SaveMapping() { { IoHand cf(ProgName(".TAB"), UPD); - if (!cf.Error) { - cf.seek((Now - 1) * sizeof(CLUSTER::Map)); - cf.write((uint8 *) CLUSTER::Map, sizeof(CLUSTER::Map)); + if (!cf._error) { + cf.seek((Now - 1) * sizeof(Cluster::_map)); + cf.write((uint8 *) Cluster::_map, sizeof(Cluster::_map)); } } { IoHand cf(ProgName(".HXY"), WRI); - if (!cf.Error) { + if (!cf._error) { HeroXY[Now - 1]._x = Hero->_x; HeroXY[Now - 1]._y = Hero->_y; cf.write((uint8 *) HeroXY, sizeof(HeroXY)); @@ -1229,7 +1229,7 @@ static void SwitchDebug(void) { } -void CGEEngine::OptionTouch(int opt, uint16 mask) { +void CGEEngine::optionTouch(int opt, uint16 mask) { switch (opt) { case 1 : if (mask & L_UP) @@ -1246,7 +1246,7 @@ void CGEEngine::OptionTouch(int opt, uint16 mask) { break; case 3 : if (mask & L_UP) - Quit(); + quit(); break; } } @@ -1260,7 +1260,7 @@ void Sprite::Touch(uint16 mask, int x, int y) { if (mask & (R_DN | L_DN)) _sprite = this; if (_ref / 10 == 12) { - _vm->OptionTouch(_ref % 10, mask); + _vm->optionTouch(_ref % 10, mask); return; } if (_flags._syst) @@ -1272,7 +1272,7 @@ void Sprite::Touch(uint16 mask, int x, int y) { if ((mask & R_UP) && Snail->Idle()) { Sprite *ps = (_pocLight->_seqPtr) ? _pocket[PocPtr] : NULL; if (ps) { - if (_flags._kept || Hero->Distance(this) < MAX_DISTANCE) { + if (_flags._kept || Hero->distance(this) < MAX_DISTANCE) { if (Works(ps)) { FeedSnail(ps, TAKE); } else @@ -1284,7 +1284,7 @@ void Sprite::Touch(uint16 mask, int x, int y) { if (_flags._kept) mask |= L_UP; else { - if (Hero->Distance(this) < MAX_DISTANCE) { + if (Hero->distance(this) < MAX_DISTANCE) { /// if (_flags._port) { if (FindPocket(NULL) < 0) @@ -1325,7 +1325,7 @@ void Sprite::Touch(uint16 mask, int x, int y) { } -void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int row = 0, int pos = 0) { +void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int row = 0, int pos = 0) { static const char *Comd[] = { "Name", "Type", "Phase", "East", "Left", "Right", "Top", "Bottom", "Seq", "Near", "Take", @@ -1348,7 +1348,7 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int MergeExt(line, fname, SPR_EXT); if (INI_FILE::exist(line)) { // sprite description file exist INI_FILE sprf(line); - if (sprf.Error) + if (sprf._error) error("Bad SPR [%s]", line); while ((len = sprf.read((uint8 *)line)) != 0) { @@ -1445,7 +1445,7 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int break; } case 5 : { // FLY - FLY *f = new FLY(this, NULL); + Fly *f = new Fly(this, NULL); _sprite = f; //////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$ break; @@ -1479,7 +1479,7 @@ void CGEEngine::LoadSprite(const char *fname, int ref, int cav, int col = 0, int } -void CGEEngine::LoadScript(const char *fname) { +void CGEEngine::loadScript(const char *fname) { char line[LINE_MAX]; char *SpN; int SpI, SpA, SpX, SpY, SpZ; @@ -1488,13 +1488,13 @@ void CGEEngine::LoadScript(const char *fname) { int lcnt = 0; bool ok = true; - if (scrf.Error) + if (scrf._error) return; while (scrf.read((uint8 *)line) != 0) { char *p; - ++lcnt; + lcnt++; if (*line == 0 || *line == '\n' || *line == '.') continue; @@ -1530,7 +1530,7 @@ void CGEEngine::LoadScript(const char *fname) { ok = true; // no break: OK _sprite = NULL; - LoadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); + loadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); if (_sprite && BkG) _sprite->_flags._back = true; } @@ -1539,7 +1539,7 @@ void CGEEngine::LoadScript(const char *fname) { } -void CGEEngine::MainLoop() { +void CGEEngine::mainLoop() { SayDebug(); if (_isDemo) { @@ -1564,28 +1564,28 @@ void CGEEngine::MainLoop() { } -void CGEEngine::LoadUser() { +void CGEEngine::loadUser() { // set scene if (STARTUP::Mode == 0) { // user .SVG file found CFile cfile = CFile(UsrPath(UsrFnam), REA, RCrypt); - LoadGame(cfile); + loadGame(cfile); } else { if (STARTUP::Mode == 1) { SVG0FILE file = SVG0FILE(SVG0NAME); - LoadGame(file); + loadGame(file); } else { - LoadScript(ProgName(INI_EXT)); + loadScript(ProgName(INI_EXT)); Music = true; CFile file = CFile(SVG0NAME, WRI); SaveGame(file); error("Ok [%s]", SVG0NAME); } } - LoadScript(ProgName(IN0_EXT)); + loadScript(ProgName(IN0_EXT)); } -void CGEEngine::RunGame() { +void CGEEngine::runGame() { Text->Clear(); Text->Preload(100, 1000); LoadHeroXY(); @@ -1613,7 +1613,7 @@ void CGEEngine::RunGame() { // Vga->ShowQ->Append(Mouse); // ___________ - LoadUser(); + loadUser(); // ~~~~~~~~~~~ if ((_sprite = Vga->SpareQ->Locate(121)) != NULL) @@ -1627,7 +1627,7 @@ void CGEEngine::RunGame() { if (Mini && INI_FILE::exist("MINI.SPR")) { uint8 *ptr = (uint8 *) &*Mini; if (ptr != NULL) { - LoadSprite("MINI", -1, 0, MINI_X, MINI_Y); + loadSprite("MINI", -1, 0, MINI_X, MINI_Y); ExpandSprite(_miniCave = _sprite); // NULL is ok if (_miniCave) { _miniCave->_flags._hide = true; @@ -1643,7 +1643,7 @@ void CGEEngine::RunGame() { ExpandSprite(Hero); Hero->Goto(HeroXY[Now - 1]._x, HeroXY[Now - 1]._y); if (INI_FILE::exist("00SHADOW.SPR")) { - LoadSprite("00SHADOW", -1, 0, Hero->_x + 14, Hero->_y + 51); + loadSprite("00SHADOW", -1, 0, Hero->_x + 14, Hero->_y + 51); if ((_shadow = _sprite) != NULL) { _shadow->_ref = 2; _shadow->_flags._tran = true; @@ -1674,7 +1674,7 @@ void CGEEngine::RunGame() { SNPOST(SNLEVEL, -1, OldLev, &_cavLight); _cavLight->Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); - CaveUp(); + caveUp(); KEYBOARD::SetClient(Sys); // main loop @@ -1682,7 +1682,7 @@ void CGEEngine::RunGame() { //TODO Change the SNPOST message send to a special way to send function pointer // if (FINIS) SNPOST(SNEXEC, -1, 0, (void *)&QGame); warning("RunGame: problematic use of SNPOST"); - MainLoop(); + mainLoop(); } KEYBOARD::SetClient(NULL); @@ -1697,10 +1697,10 @@ void CGEEngine::RunGame() { } -void CGEEngine::Movie(const char *ext) { +void CGEEngine::movie(const char *ext) { const char *fn = ProgName(ext); if (INI_FILE::exist(fn)) { - LoadScript(fn); + loadScript(fn); ExpandSprite(Vga->SpareQ->Locate(999)); FeedSnail(Vga->ShowQ->Locate(999), TAKE); @@ -1710,7 +1710,7 @@ void CGEEngine::Movie(const char *ext) { _heart->_enable = true; KEYBOARD::SetClient(Sys); while (!Snail->Idle()) - MainLoop(); + mainLoop(); KEYBOARD::SetClient(NULL); _heart->_enable = false; @@ -1722,7 +1722,7 @@ void CGEEngine::Movie(const char *ext) { } -bool CGEEngine::ShowTitle(const char *name) { +bool CGEEngine::showTitle(const char *name) { Bitmap::_pal = VGA::SysPal; BMP_PTR LB[] = { new Bitmap(name, true), NULL }; Bitmap::_pal = NULL; @@ -1735,7 +1735,7 @@ bool CGEEngine::ShowTitle(const char *name) { D.Show(2); if (STARTUP::Mode == 2) { - Inf(SVG0NAME); + inf(SVG0NAME); Talk->Show(2); } @@ -1751,8 +1751,8 @@ bool CGEEngine::ShowTitle(const char *name) { Vga->ShowQ->Append(Mouse); _heart->_enable = true; Mouse->On(); - for (SelectSound(); !Snail->Idle() || VMENU::Addr;) - MainLoop(); + for (selectSound(); !Snail->Idle() || VMENU::Addr;) + mainLoop(); Mouse->Off(); _heart->_enable = false; Vga->ShowQ->Clear(); @@ -1781,14 +1781,14 @@ bool CGEEngine::ShowTitle(const char *name) { STARTUP::Summa |= Lo(sn) | Hi(sn); #endif //----------------------------------------- - Movie("X00"); // paylist + movie("X00"); // paylist Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); Vga->ShowQ->Append(Mouse); //Mouse.On(); _heart->_enable = true; - for (TakeName(); GET_TEXT::Ptr;) - MainLoop(); + for (takeName(); GET_TEXT::Ptr;) + mainLoop(); _heart->_enable = false; if (KEYBOARD::Last() == Enter && *UsrFnam) usr_ok = true; @@ -1804,7 +1804,7 @@ bool CGEEngine::ShowTitle(const char *name) { const char *n = UsrPath(UsrFnam); if (CFile::exist(n)) { CFile file = CFile(n, REA, RCrypt); - LoadGame(file, true); // only system vars + loadGame(file, true); // only system vars Vga->SetColors(VGA::SysPal, 64); Vga->Update(); if (FINIS) { @@ -1817,7 +1817,7 @@ bool CGEEngine::ShowTitle(const char *name) { } if (STARTUP::Mode < 2) - Movie("X01"); // wink + movie("X01"); // wink Vga->CopyPage(0, 2); @@ -1859,14 +1859,14 @@ void CGEEngine::cge_main(void) { if (Music && STARTUP::SoundOk) LoadMIDI(0); if (STARTUP::Mode < 2) - Movie(LGO_EXT); - if (ShowTitle("WELCOME")) { + movie(LGO_EXT); + if (showTitle("WELCOME")) { if ((!_isDemo) && (STARTUP::Mode == 1)) - Movie("X02"); // intro - RunGame(); + movie("X02"); // intro + runGame(); Startup = 2; if (FINIS) - Movie("X03"); + movie("X03"); } else Vga->Sunset(); error("%s", Text->getText(EXIT_OK_TEXT + FINIS)); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 8b2f87aad9c..9b905ea360c 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -129,39 +129,39 @@ private: }; -class CLUSTER : public COUPLE { +class Cluster : public Couple { public: - static uint8 Map[MAP_ZCNT][MAP_XCNT]; - uint8 &Cell(void); - CLUSTER(void) : COUPLE() { } - CLUSTER(int a, int b) : COUPLE(a, b) { } + static uint8 _map[MAP_ZCNT][MAP_XCNT]; + uint8 &cell(void); + Cluster(void) : Couple() { } + Cluster(int a, int b) : Couple(a, b) { } bool Protected(void); }; class WALK : public Sprite { public: - CLUSTER Here; - int TracePtr; + Cluster _here; + int _tracePtr; enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; WALK(CGEEngine *vm, BMP_PTR *shpl); - void Tick(void); - void FindWay(CLUSTER c); - void FindWay(Sprite *spr); - int Distance(Sprite *spr); - void Turn(DIR d); - void Park(void); - bool Lower(Sprite *spr); - void Reach(Sprite *spr, int mode = -1); + void tick(); + void findWay(Cluster c); + void findWay(Sprite *spr); + int distance(Sprite *spr); + void turn(DIR d); + void park(); + bool lower(Sprite *spr); + void reach(Sprite *spr, int mode = -1); private: CGEEngine *_vm; }; -CLUSTER XZ(int x, int y); -CLUSTER XZ(COUPLE xy); +Cluster XZ(int x, int y); +Cluster XZ(Couple xy); void ExpandSprite(Sprite *spr); void ContractSprite(Sprite *spr); diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 26731432851..702c10ed154 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -77,76 +77,76 @@ static CHOICE DevMenu[] = { static CHOICE DigiPorts[] = { - { " 210h", &CGEEngine::SetPortD }, - { " 220h", &CGEEngine::SetPortD }, - { " 230h", &CGEEngine::SetPortD }, - { " 240h", &CGEEngine::SetPortD }, - { " 250h", &CGEEngine::SetPortD }, - { " 260h", &CGEEngine::SetPortD }, - { "AUTO ", &CGEEngine::SetPortD }, + { " 210h", &CGEEngine::setPortD }, + { " 220h", &CGEEngine::setPortD }, + { " 230h", &CGEEngine::setPortD }, + { " 240h", &CGEEngine::setPortD }, + { " 250h", &CGEEngine::setPortD }, + { " 260h", &CGEEngine::setPortD }, + { "AUTO ", &CGEEngine::setPortD }, { NULL, NULL } }; static CHOICE MIDIPorts[] = { - { " 220h", &CGEEngine::SetPortM }, - { " 230h", &CGEEngine::SetPortM }, - { " 240h", &CGEEngine::SetPortM }, - { " 250h", &CGEEngine::SetPortM }, - { " 300h", &CGEEngine::SetPortM }, - { " 320h", &CGEEngine::SetPortM }, - { " 330h", &CGEEngine::SetPortM }, - { " 340h", &CGEEngine::SetPortM }, - { " 350h", &CGEEngine::SetPortM }, - { " 360h", &CGEEngine::SetPortM }, - { "AUTO ", &CGEEngine::SetPortM }, + { " 220h", &CGEEngine::setPortM }, + { " 230h", &CGEEngine::setPortM }, + { " 240h", &CGEEngine::setPortM }, + { " 250h", &CGEEngine::setPortM }, + { " 300h", &CGEEngine::setPortM }, + { " 320h", &CGEEngine::setPortM }, + { " 330h", &CGEEngine::setPortM }, + { " 340h", &CGEEngine::setPortM }, + { " 350h", &CGEEngine::setPortM }, + { " 360h", &CGEEngine::setPortM }, + { "AUTO ", &CGEEngine::setPortM }, { NULL, NULL } }; static CHOICE BlsterIRQ[] = { - { "IRQ 2", &CGEEngine::SetIRQ }, - { "IRQ 5", &CGEEngine::SetIRQ }, - { "IRQ 7", &CGEEngine::SetIRQ }, - { "IRQ 10", &CGEEngine::SetIRQ }, - { "AUTO ", &CGEEngine::SetIRQ }, + { "IRQ 2", &CGEEngine::setIRQ }, + { "IRQ 5", &CGEEngine::setIRQ }, + { "IRQ 7", &CGEEngine::setIRQ }, + { "IRQ 10", &CGEEngine::setIRQ }, + { "AUTO ", &CGEEngine::setIRQ }, { NULL, NULL } }; static CHOICE GravisIRQ[] = { - { "IRQ 2", &CGEEngine::SetIRQ }, - { "IRQ 5", &CGEEngine::SetIRQ }, - { "IRQ 7", &CGEEngine::SetIRQ }, - { "IRQ 11", &CGEEngine::SetIRQ }, - { "IRQ 12", &CGEEngine::SetIRQ }, - { "IRQ 15", &CGEEngine::SetIRQ }, - { "AUTO ", &CGEEngine::SetIRQ }, + { "IRQ 2", &CGEEngine::setIRQ }, + { "IRQ 5", &CGEEngine::setIRQ }, + { "IRQ 7", &CGEEngine::setIRQ }, + { "IRQ 11", &CGEEngine::setIRQ }, + { "IRQ 12", &CGEEngine::setIRQ }, + { "IRQ 15", &CGEEngine::setIRQ }, + { "AUTO ", &CGEEngine::setIRQ }, { NULL, NULL } }; static CHOICE GravisDMA[] = { - { "DMA 1", &CGEEngine::SetDMA }, - { "DMA 3", &CGEEngine::SetDMA }, - { "DMA 5", &CGEEngine::SetDMA }, - { "DMA 6", &CGEEngine::SetDMA }, - { "DMA 7", &CGEEngine::SetDMA }, - { "AUTO ", &CGEEngine::SetDMA }, + { "DMA 1", &CGEEngine::setDMA }, + { "DMA 3", &CGEEngine::setDMA }, + { "DMA 5", &CGEEngine::setDMA }, + { "DMA 6", &CGEEngine::setDMA }, + { "DMA 7", &CGEEngine::setDMA }, + { "AUTO ", &CGEEngine::setDMA }, { NULL, NULL } }; static CHOICE BlsterDMA[] = { - { "DMA 0", &CGEEngine::SetDMA }, - { "DMA 1", &CGEEngine::SetDMA }, - { "DMA 3", &CGEEngine::SetDMA }, - { "AUTO ", &CGEEngine::SetDMA }, + { "DMA 0", &CGEEngine::setDMA }, + { "DMA 1", &CGEEngine::setDMA }, + { "DMA 3", &CGEEngine::setDMA }, + { "AUTO ", &CGEEngine::setDMA }, { NULL, NULL } }; -void CGEEngine::SelectSound() { +void CGEEngine::selectSound() { int i; Sound.Close(); if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); - Inf(Text->getText(STYPE_TEXT)); + inf(Text->getText(STYPE_TEXT)); Talk->Goto(Talk->_x, FONT_HIG / 2); for (i = 0; i < ArrayCount(DevName); i++) DevMenu[i].Text = Text->getText(DevName[i]); @@ -183,7 +183,7 @@ static CHOICE *Cho; static int Hlp; void CGEEngine::SNSelect() { - Inf(Text->getText(Hlp)); + inf(Text->getText(Hlp)); Talk->Goto(Talk->_x, FONT_HIG / 2); (new VMENU(this, Cho, SCR_WID / 2, Talk->_y + Talk->_h + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); } @@ -253,25 +253,25 @@ void CGEEngine::AUTO() { } -void CGEEngine::SetPortD() { +void CGEEngine::setPortD() { SNDDrvInfo.DBASE = xdeco(DigiPorts[VMENU::Recent].Text); Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ, SIRQ_TEXT); } -void CGEEngine::SetPortM() { +void CGEEngine::setPortM() { SNDDrvInfo.MBASE = xdeco(MIDIPorts[VMENU::Recent].Text); Sound.Open(); } -void CGEEngine::SetIRQ() { +void CGEEngine::setIRQ() { SNDDrvInfo.DIRQ = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ)[VMENU::Recent].Text); Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA, SDMA_TEXT); } -void CGEEngine::SetDMA() { +void CGEEngine::setDMA() { SNDDrvInfo.DDMA = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA)[VMENU::Recent].Text); if (SNDDrvInfo.MDEV != SNDDrvInfo.DDEV) Select(MIDIPorts, MPORT_TEXT); diff --git a/engines/cge/config.h b/engines/cge/config.h index e3fe094681a..0f279ab0477 100644 --- a/engines/cge/config.h +++ b/engines/cge/config.h @@ -30,7 +30,7 @@ namespace CGE { -void SelectSound(void); +void selectSound(); } // End of namespace CGE diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp index 56d853f4e80..158857c0021 100644 --- a/engines/cge/ems.cpp +++ b/engines/cge/ems.cpp @@ -41,10 +41,10 @@ enum EMM_FUN { }; -void *EMM::Frame = NULL; +void *EMM::_frame = NULL; -EMM::EMM(long size): Han(-1), Top(0), Lim(0), List(NULL) { +EMM::EMM(long size): _han(-1), _top(0), _lim(0), _list(NULL) { /* if (Test()) { @@ -97,7 +97,7 @@ EMM::~EMM(void) { } -bool EMM::Test(void) { +bool EMM::test() { /* static char e[] = "EMMXXXX0"; @@ -130,7 +130,7 @@ bool EMM::Test(void) { } -EMS *EMM::Alloc(uint16 siz) { +EMS *EMM::alloc(uint16 siz) { /* long size = SIZ(siz), top = Top; @@ -167,22 +167,22 @@ EMS *EMM::Alloc(uint16 siz) { } fail: return NULL; */ - warning("STUB: EMM::Alloc"); + warning("STUB: EMM::alloc"); return NULL; } -void EMM::Release(void) { - while (List) { - EMS *e = List; - List = e->Nxt; +void EMM::release() { + while (_list) { + EMS *e = _list; + _list = e->_next; delete e; } - Top = 0; + _top = 0; } -EMS::EMS(void) : Ptr(0), Siz(0), Nxt(NULL) { +EMS::EMS(void) : _ptr(0), _size(0), _next(NULL) { } @@ -193,7 +193,7 @@ void *EMS::operator & () const { cnt = (uint16) ((Ptr + SIZ(Siz) + PAGE_MASK) >> 14) - pgn, cmd = MAP_PAGE << 8; - _DX = Emm->Han; // take EMM handle + _DX = Emm->_han; // take EMM handle asm dec cnt // prapare for deferred checking asm or dx,dx // see if valid asm jns more // negative handle = unavailable @@ -218,8 +218,8 @@ void *EMS::operator & () const { } -uint16 EMS::Size(void) { - return Siz; +uint16 EMS::size() { + return _size; } } // End of namespace CGE diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 87daced31e1..2a6bc85015b 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -31,20 +31,20 @@ namespace CGE { -uint8 *Glass(DAC *pal, uint8 r, uint8 g, uint8 b) { +uint8 *glass(Dac *pal, uint8 r, uint8 g, uint8 b) { uint8 *x = new uint8[256]; if (x) { uint16 i; for (i = 0; i < 256; i++) { - x[i] = Closest(pal, MkDAC(((uint16)(pal[i].R) * r) / 255, - ((uint16)(pal[i].G) * g) / 255, - ((uint16)(pal[i].B) * b) / 255)); + x[i] = Closest(pal, MkDAC(((uint16)(pal[i]._r) * r) / 255, + ((uint16)(pal[i]._g) * g) / 255, + ((uint16)(pal[i]._b) * b) / 255)); } } return x; } - +/* Useless? uint8 *Mark(DAC *pal) { #define f(c) (c ^ 63) uint8 *x = new uint8[256]; @@ -59,33 +59,33 @@ uint8 *Mark(DAC *pal) { return x; #undef f } +*/ + +int Fly::_l = 20, + Fly::_t = 40, + Fly::_r = 110, + Fly::_b = 100; -int FLY::L = 20, - FLY::T = 40, - FLY::R = 110, - FLY::B = 100; - - -FLY::FLY(CGEEngine *vm, Bitmap **shpl) - : Sprite(vm, shpl), Tx(0), Ty(0), _vm(vm) { +Fly::Fly(CGEEngine *vm, Bitmap **shpl) + : Sprite(vm, shpl), _tx(0), _ty(0), _vm(vm) { Step(new_random(2)); - Goto(L + new_random(R - L - _w), T + new_random(B - T - _h)); + Goto(_l + new_random(_r - _l - _w), _t + new_random(_b - _t - _h)); } -void FLY::Tick(void) { +void Fly::tick() { Step(); if (!_flags._kept) { if (new_random(10) < 1) { - Tx = new_random(3) - 1; - Ty = new_random(3) - 1; + _tx = new_random(3) - 1; + _ty = new_random(3) - 1; } - if (_x + Tx < L || _x + Tx + _w > R) - Tx = -Tx; - if (_y + Ty < T || _y + Ty + _h > B) - Ty = -Ty; - Goto(_x + Tx, _y + Ty); + if (_x + _tx < _l || _x + _tx + _w > _r) + _tx = -_tx; + if (_y + _ty < _t || _y + _ty + _h > _b) + _ty = -_ty; + Goto(_x + _tx, _y + _ty); } } diff --git a/engines/cge/game.h b/engines/cge/game.h index a64018aa58c..3f86c970818 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -34,22 +34,25 @@ namespace CGE { -#define PAN_HIG 40 -#define LBound(s) (s->X <= 0) -#define RBound(s) (s->X+s->W >= SCR_WID) -#define TBound(s) (s->Y <= 0) -#define BBound(s) (s->Y+s->H >= SCR_HIG - PAN_HIG) +//#define PAN_HIG 40 +//#define LBound(s) (s->X <= 0) +//#define RBound(s) (s->X+s->W >= SCR_WID) +//#define TBound(s) (s->Y <= 0) +//#define BBound(s) (s->Y+s->H >= SCR_HIG - PAN_HIG) -int Sinus(long x); -uint8 *Glass(DAC *pal, uint8 r, uint8 g, uint8 b); -uint8 *Mark(DAC *pal); +//int sinus(long x); +uint8 *glass(Dac *pal, uint8 r, uint8 g, uint8 b); +//uint8 *mark(DAC *pal); -class FLY : public Sprite { - static int L, T, R, B; +class Fly : public Sprite { + static int _l; + static int _t; + static int _r; + static int _b; public: - int Tx, Ty; - FLY(CGEEngine *vm, Bitmap **shpl); - void Tick(void); + int _tx, _ty; + Fly(CGEEngine *vm, Bitmap **shpl); + void tick(); private: CGEEngine *_vm; }; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 510456087f4..0b761f22998 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -32,7 +32,7 @@ namespace CGE { -DAC StdPal[] = {// R G B +Dac _stdPal[] = {// R G B { 0, 60, 0}, // 198 { 0, 104, 0}, // 199 { 20, 172, 0}, // 200 @@ -212,12 +212,12 @@ char *dwtom(uint32 val, char *str, int radix, int len) { } IoHand::IoHand(IOMODE mode, CRYPT *crpt) - : XFILE(mode), _crypt(crpt), _seed(SEED) { + : XFile(mode), _crypt(crpt), _seed(SEED) { _file = new Common::File(); } IoHand::IoHand(const char *name, IOMODE mode, CRYPT *crpt) - : XFILE(mode), _crypt(crpt), _seed(SEED) { + : XFile(mode), _crypt(crpt), _seed(SEED) { // TODO: Check if WRI and/or UPD modes are needed, and map to a save file assert(mode == REA); @@ -231,7 +231,7 @@ IoHand::~IoHand(void) { } uint16 IoHand::read(void *buf, uint16 len) { - if (Mode == WRI || !_file->isOpen()) + if (_mode == WRI || !_file->isOpen()) return 0; uint16 bytesRead = _file->read(buf, len); @@ -327,7 +327,7 @@ EC void SNDMIDIStop() { // FIXME: STUB: SNDMIDIStop } -DATACK *LoadWave(XFILE *file, EMM *emm) { +DATACK *LoadWave(XFile *file, EMM *emm) { warning("STUB: LoadWave"); return NULL; } @@ -377,10 +377,9 @@ int new_random(int range) { } #define TIMER_INT 0x08 -//void interrupt (* ENGINE::OldTimer) (...) = NULL; +//void interrupt (* Engine_::oldTimer) (...) = NULL; -ENGINE::ENGINE (uint16 tdiv) -{ +Engine_::Engine_(uint16 tdiv) { /* // steal timer interrupt OldTimer = getvect(TIMER_INT); @@ -394,11 +393,10 @@ ENGINE::ENGINE (uint16 tdiv) asm mov al,ah asm out 0x40,al */ - warning("STUB: ENGINE::ENGINE"); + warning("STUB: Engine_::Engine_"); } -ENGINE::~ENGINE (void) -{ +Engine_::~Engine_() { /* // reset timer asm mov al,0x36 @@ -409,12 +407,12 @@ ENGINE::~ENGINE (void) // bring back timer interrupt setvect(TIMER_INT, OldTimer); */ - warning("STUB: ENGINE::~ENGINE"); + warning("STUB: Engine_::~Engine_"); } -DATACK::~DATACK (void) -{ - if (!e && Buf) free(Buf); +DATACK::~DATACK () { + if (!e && Buf) + free(Buf); } } // End of namespace CGE diff --git a/engines/cge/general.h b/engines/cge/general.h index 1ecec9fbe99..3c94e22ae46 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -54,59 +54,59 @@ enum MEM_TYPE { BAD_MEM, EMS_MEM, NEAR_MEM, FAR_MEM }; enum ALLOC_MODE { FIRST_FIT, BEST_FIT, LAST_FIT }; enum IOMODE { REA, WRI, UPD }; -typedef struct { - uint8 R, G, B; -} DAC; +struct Dac { + uint8 _r, _g, _b; +}; typedef uint16 CRYPT(void *buf, uint16 siz, uint16 seed); -class COUPLE { +class Couple { protected: - signed char A; - signed char B; + signed char _a; + signed char _b; public: - COUPLE(void) { } - COUPLE(const signed char a, const signed char b) : A(a), B(b) { } - COUPLE operator + (COUPLE c) { - return COUPLE(A + c.A, B + c.B); + Couple() { } + Couple(const signed char a, const signed char b) : _a(a), _b(b) { } + Couple operator + (Couple c) { + return Couple(_a + c._a, _b + c._b); } - void operator += (COUPLE c) { - A += c.A; - B += c.B; + void operator += (Couple c) { + _a += c._a; + _b += c._b; } - COUPLE operator - (COUPLE c) { - return COUPLE(A - c.A, B - c.B); + Couple operator - (Couple c) { + return Couple(_a - c._a, _b - c._b); } - void operator -= (COUPLE c) { - A -= c.A; - B -= c.B; + void operator -= (Couple c) { + _a -= c._a; + _b -= c._b; } - bool operator == (COUPLE c) { - return ((A - c.A) | (B - c.B)) == 0; + bool operator == (Couple c) { + return ((_a - c._a) | (_b - c._b)) == 0; } - bool operator != (COUPLE c) { + bool operator != (Couple c) { return !(operator == (c)); } - void Split(signed char &a, signed char &b) { - a = A; - b = B; + void split(signed char &a, signed char &b) { + a = _a; + b = _b; } }; -class ENGINE { +class Engine_ { protected: - static void (* OldTimer)(...); - static void NewTimer(...); + static void (* oldTimer)(...); + static void newTimer(...); public: - ENGINE(uint16 tdiv); - ~ENGINE(void); + Engine_(uint16 tdiv); + ~Engine_(void); }; @@ -115,29 +115,31 @@ class EMS; class EMM { friend class EMS; - bool Test(void); - long Top, Lim; - EMS *List; - int Han; - static void *Frame; + bool test(); + + long _top; + long _lim; + EMS *_list; + int _han; + static void *_frame; public: EMM(long size = 0); - ~EMM(void); - EMS *Alloc(uint16 siz); - void Release(void); + ~EMM(); + EMS *alloc(uint16 siz); + void release(); }; class EMS { friend class EMM; - EMM *Emm; - long Ptr; - uint16 Siz; - EMS *Nxt; + EMM *_emm; + long _ptr; + uint16 _size; + EMS *_next; public: - EMS(void); + EMS(); void *operator & () const; - uint16 Size(void); + uint16 size(void); }; @@ -162,28 +164,29 @@ T min(T A, T B) { #endif -class XFILE { +class XFile { public: - IOMODE Mode; - uint16 Error; - XFILE(void) : Mode(REA), Error(0) { } - XFILE(IOMODE mode) : Mode(mode), Error(0) { } + IOMODE _mode; + uint16 _error; + + XFile() : _mode(REA), _error(0) { } + XFile(IOMODE mode) : _mode(mode), _error(0) { } + virtual ~XFile() { } virtual uint16 read(void *buf, uint16 len) = 0; virtual uint16 write(void *buf, uint16 len) = 0; - virtual long mark(void) = 0; - virtual long size(void) = 0; + virtual long mark() = 0; + virtual long size() = 0; virtual long seek(long pos) = 0; - virtual ~XFILE() { } }; template -inline uint16 XRead(XFILE *xf, T *t) { +inline uint16 XRead(XFile *xf, T *t) { return xf->read((uint8 *) t, sizeof(*t)); } -class IoHand : public XFILE { +class IoHand : public XFile { protected: Common::File *_file; uint16 _seed; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index e9d9b4643ff..a10ab21658d 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -311,7 +311,7 @@ void SelectPocket(int n) { void PocFul(void) { - Hero->Park(); + Hero->park(); SNPOST(SNWAIT, -1, -1, Hero); SNPOST(SNSEQ, -1, POC_FUL, Hero); SNPOST(SNSOUND, -1, 2, Hero); @@ -544,7 +544,7 @@ static void SNRmTake(Sprite *spr) { void SNSeq(Sprite *spr, int val) { if (spr) { if (spr == Hero && val == 0) - Hero->Park(); + Hero->park(); else spr->Step(val); } @@ -846,17 +846,17 @@ static void SNSetRef(Sprite *spr, int nr) { void SNFlash(bool on) { if (on) { - DAC *pal = farnew(DAC, PAL_CNT); + Dac *pal = farnew(Dac, PAL_CNT); if (pal) { memcpy(pal, VGA::SysPal, PAL_SIZ); for (int i = 0; i < PAL_CNT; i++) { register int c; - c = pal[i].R << 1; - pal[i].R = (c < 64) ? c : 63; - c = pal[i].G << 1; - pal[i].G = (c < 64) ? c : 63; - c = pal[i].B << 1; - pal[i].B = (c < 64) ? c : 63; + c = pal[i]._r << 1; + pal[i]._r = (c < 64) ? c : 63; + c = pal[i]._g << 1; + pal[i]._g = (c < 64) ? c : 63; + c = pal[i]._b << 1; + pal[i]._b = (c < 64) ? c : 63; } Vga->SetColors(pal, 64); } @@ -883,16 +883,16 @@ static void SNBarrier(int cav, int bar, bool horz) { static void SNWalk(Sprite *spr, int x, int y) { if (Hero) { if (spr && y < 0) - Hero->FindWay(spr); + Hero->findWay(spr); else - Hero->FindWay(XZ(x, y)); + Hero->findWay(XZ(x, y)); } } static void SNReach(Sprite *spr, int mode) { if (Hero) - Hero->Reach(spr, mode); + Hero->reach(spr, mode); } @@ -937,7 +937,7 @@ void SNAIL::RunCom(void) { case SNWAIT : if (sprel) { if (sprel->SeqTest(snc->Val) && - (snc->Val >= 0 || sprel != Hero || Hero->TracePtr < 0)) { + (snc->Val >= 0 || sprel != Hero || Hero->_tracePtr < 0)) { _heart->setXTimer(&Pause, sprel->_time); } else goto xit; @@ -959,7 +959,7 @@ void SNAIL::RunCom(void) { break; case SNINF : if (TalkEnable) { - _vm->Inf(Text->getText(snc->Val)); + _vm->inf(Text->getText(snc->Val)); Sys->FunDel = HEROFUN0; } break; diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index eecd3bacb26..a59179710bd 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -104,7 +104,7 @@ void FX::Clear(void) { p->Wav = NULL; } } - Emm.Release(); + Emm.release(); Current = NULL; } @@ -190,12 +190,12 @@ void LoadMIDI(int ref) { if (INI_FILE::exist(fn)) { KillMIDI(); INI_FILE mid = fn; - if (mid.Error == 0) { + if (mid._error == 0) { uint16 siz = (uint16) mid.size(); midi = new uint8[siz]; if (midi) { mid.read(midi, siz); - if (mid.Error) + if (mid._error) KillMIDI(); else SNDMIDIStart(midi); @@ -211,12 +211,12 @@ EC void *Patch(int pat) { wtom(pat, fn + 5, 10, 3); INI_FILE snd = fn; - if (! snd.Error) { + if (!snd._error) { uint16 siz = (uint16) snd.size(); p = (uint8 *) malloc(siz); if (p) { snd.read(p, siz); - if (snd.Error) { + if (snd._error) { free(p); p = NULL; } diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index c8aa8292e81..fab1abc0d85 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -62,9 +62,9 @@ FONT::~FONT() { void FONT::Load() { INI_FILE f(Path); - if (! f.Error) { + if (!f._error) { f.read(Wid, WID_SIZ); - if (! f.Error) { + if (!f._error) { uint16 i, p = 0; for (i = 0; i < POS_SIZ; i++) { Pos[i] = p; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 7df51f11265..515c1091f80 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -88,7 +88,7 @@ int TEXT::Find(int ref) { void TEXT::Preload(int from, int upto) { INI_FILE tf = FileName; - if (! tf.Error) { + if (!tf._error) { HAN *CacheLim = Cache + Size; char line[LINE_MAX + 1]; int n; @@ -130,7 +130,7 @@ void TEXT::Preload(int from, int upto) { char *TEXT::Load(int idx, int ref) { INI_FILE tf = FileName; - if (! tf.Error) { + if (!tf._error) { HAN *p = &Cache[idx]; char line[LINE_MAX + 1]; int n; @@ -221,7 +221,7 @@ void TEXT::Say(const char *txt, Sprite *spr) { } } -void CGEEngine::Inf(const char *txt) { +void CGEEngine::inf(const char *txt) { KillText(); Talk = new TALK(this, txt, RECT); if (Talk) { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index f26d202dcaa..d12bb9596cf 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -189,20 +189,20 @@ void RestoreScreen(uint16 * &sav) { } -DAC MkDAC(uint8 r, uint8 g, uint8 b) { - static DAC x; - x.R = r; - x.G = g; - x.B = b; +Dac MkDAC(uint8 r, uint8 g, uint8 b) { + static Dac x; + x._r = r; + x._g = g; + x._b = b; return x; } Rgb MkRGB(uint8 r, uint8 g, uint8 b) { static TRGB x; - x.dac.R = r; - x.dac.G = g; - x.dac.B = b; + x.dac._r = r; + x.dac._g = g; + x.dac._b = b; return x.rgb; } @@ -214,7 +214,7 @@ Sprite *Locate(int ref) { Heart::Heart(void) - : ENGINE(TMR_DIV) { + : Engine_(TMR_DIV) { _enable = false; _xTimer = NULL; } @@ -265,7 +265,7 @@ extern "C" void TimerProc() { */ -void ENGINE::NewTimer(...) { +void Engine_::newTimer(...) { /* static SPRITE *spr; static uint8 run = 0, cntr1 = TMR_RATE1, cntr2 = TMR_RATE2; @@ -338,7 +338,7 @@ void ENGINE::NewTimer(...) { } */ - warning("STUB: ENGINE::NewTimer"); + warning("STUB: Engine_::NewTimer"); } @@ -505,7 +505,7 @@ Sprite *Sprite::Expand(void) { MergeExt(fname, File, SPR_EXT); if (INI_FILE::exist(fname)) { // sprite description file exist INI_FILE sprf(fname); - if (! (sprf.Error==0)) + if (!(sprf._error==0)) error("Bad SPR [%s]", fname); int len = 0, lcnt = 0; while ((len = sprf.read((uint8 *)line)) != 0) { @@ -910,7 +910,7 @@ Sprite *QUEUE::Locate(int ref) { //extern const char Copr[]; Graphics::Surface *VGA::Page[4]; -DAC *VGA::SysPal; +Dac *VGA::SysPal; void VGA::init() { for (int idx = 0; idx < 4; ++idx) { @@ -918,7 +918,7 @@ void VGA::init() { Page[idx]->create(320, 200, Graphics::PixelFormat::createFormatCLUT8()); } - SysPal = new DAC[PAL_CNT]; + SysPal = new Dac[PAL_CNT]; } void VGA::deinit() { @@ -953,8 +953,8 @@ VGA::VGA(int mode) if (StatAdr != VGAST1_) ++Mono; if (IsVga()) { - OldColors = farnew(DAC, 256); - NewColors = farnew(DAC, 256); + OldColors = farnew(Dac, 256); + NewColors = farnew(Dac, 256); OldScreen = SaveScreen(); GetColors(OldColors); Sunset(); @@ -1061,45 +1061,45 @@ int VGA::SetMode(int mode) { } -void VGA::GetColors(DAC *tab) { +void VGA::GetColors(Dac *tab) { byte palData[PAL_SIZ]; g_system->getPaletteManager()->grabPalette(palData, 0, PAL_CNT); pal2DAC(palData, tab); } -void VGA::pal2DAC(const byte *palData, DAC *tab) { +void VGA::pal2DAC(const byte *palData, Dac *tab) { const byte *colP = palData; for (int idx = 0; idx < PAL_CNT; ++idx, colP += 3) { - tab[idx].R = *colP; - tab[idx].G = *(colP + 1); - tab[idx].B = *(colP + 2); + tab[idx]._r = *colP; + tab[idx]._g = *(colP + 1); + tab[idx]._b = *(colP + 2); } } -void VGA::DAC2pal(const DAC *tab, byte *palData) { +void VGA::DAC2pal(const Dac *tab, byte *palData) { for (int idx = 0; idx < PAL_CNT; ++idx, palData += 3) { - *palData = tab[idx].R << 2; - *(palData + 1) = tab[idx].G << 2; - *(palData + 2) = tab[idx].B << 2; + *palData = tab[idx]._r << 2; + *(palData + 1) = tab[idx]._g << 2; + *(palData + 2) = tab[idx]._b << 2; } } -void VGA::SetColors(DAC *tab, int lum) { - DAC *palP = tab; +void VGA::SetColors(Dac *tab, int lum) { + Dac *palP = tab; for (int idx = 0; idx < PAL_CNT; ++idx, ++palP) { - palP->R = (palP->R * lum) >> 6; - palP->G = (palP->G * lum) >> 6; - palP->B = (palP->B * lum) >> 6; + palP->_r = (palP->_r * lum) >> 6; + palP->_g = (palP->_g * lum) >> 6; + palP->_b = (palP->_b * lum) >> 6; } if (Mono) { palP = tab; for (int idx = 0; idx < PAL_CNT; ++idx, ++palP) { // Form a greyscalce colour from 30% R, 59% G, 11% B - uint8 intensity = (palP->R * 77) + (palP->G * 151) + (palP->B * 28); - palP->R = intensity; - palP->G = intensity; - palP->B = intensity; + uint8 intensity = (palP->_r * 77) + (palP->_g * 151) + (palP->_b * 28); + palP->_r = intensity; + palP->_g = intensity; + palP->_b = intensity; } } @@ -1113,7 +1113,7 @@ void VGA::SetColors(void) { } -void VGA::Sunrise(DAC *tab) { +void VGA::Sunrise(Dac *tab) { for (int i = 0; i <= 64; i += FADE_STEP) { SetColors(tab, i); WaitVR(true); @@ -1123,7 +1123,7 @@ void VGA::Sunrise(DAC *tab) { void VGA::Sunset(void) { - DAC tab[256]; + Dac tab[256]; GetColors(tab); for (int i = 64; i >= 0; i -= FADE_STEP) { SetColors(tab, i); diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 0c75dd6ba95..a3d5ad949b0 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -91,7 +91,7 @@ struct Rgb { }; typedef union { - DAC dac; + Dac dac; Rgb rgb; } TRGB; @@ -133,8 +133,8 @@ extern Seq _seq2[]; #define VGAST1 (VGAST1_ & 0xFF) -class Heart : public ENGINE { - friend class ENGINE; +class Heart : public Engine_ { + friend class Engine_; public: Heart(); @@ -263,7 +263,8 @@ class VGA { uint16 *OldScreen; uint16 StatAdr; bool SetPal; - DAC *OldColors, *NewColors; + Dac *OldColors; + Dac *NewColors; const char *Msg; const char *Nam; @@ -277,7 +278,7 @@ public: QUEUE *ShowQ, *SpareQ; int Mono; static Graphics::Surface *Page[4]; - static DAC *SysPal; + static Dac *SysPal; VGA(int mode); ~VGA(void); @@ -285,21 +286,21 @@ public: static void deinit(); void Setup(VgaRegBlk *vrb); - void GetColors(DAC *tab); - void SetColors(DAC *tab, int lum); + void GetColors(Dac *tab); + void SetColors(Dac *tab, int lum); void Clear(uint8 color); void CopyPage(uint16 d, uint16 s); - void Sunrise(DAC *tab); + void Sunrise(Dac *tab); void Sunset(void); void Show(void); void Update(void); - static void pal2DAC(const byte *palData, DAC *tab); - static void DAC2pal(const DAC *tab, byte *palData); + static void pal2DAC(const byte *palData, Dac *tab); + static void DAC2pal(const Dac *tab, byte *palData); }; -DAC MkDAC(uint8 r, uint8 g, uint8 b); +Dac MkDAC(uint8 r, uint8 g, uint8 b); Rgb MkRGB(uint8 r, uint8 g, uint8 b); @@ -307,15 +308,15 @@ template uint8 Closest(CBLK *pal, CBLK x) { #define f(col, lum) ((((uint16)(col)) << 8) / lum) uint16 i, dif = 0xFFFF, found = 0; - uint16 L = x.R + x.G + x.B; + uint16 L = x._r + x._g + x._b; if (!L) ++L; - uint16 R = f(x.R, L), G = f(x.G, L), B = f(x.B, L); + uint16 R = f(x._r, L), G = f(x._g, L), B = f(x._b, L); for (i = 0; i < 256; i++) { - uint16 l = pal[i].R + pal[i].G + pal[i].B; + uint16 l = pal[i]._r + pal[i]._g + pal[i]._b; if (! l) ++l; - int r = f(pal[i].R, l), g = f(pal[i].G, l), b = f(pal[i].B, l); + int r = f(pal[i]._r, l), g = f(pal[i]._g, l), b = f(pal[i]._b, l); uint16 D = ((r > R) ? (r - R) : (R - r)) + ((g > G) ? (g - G) : (G - g)) + ((b > B) ? (b - B) : (B - b)) + diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 8170bd5980a..5f8573706ba 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -70,11 +70,11 @@ void VFILE::deinit() { VFILE::VFILE(const char *name, IOMODE mode) : IoBuf(mode) { if (mode == REA) { - if (_dat->_File.Error || _cat->Error) + if (_dat->_File._error || _cat->_error) error("Bad volume data"); BtKeypack *kp = _cat->find(name); if (scumm_stricmp(kp->_key, name) != 0) - Error = 1; + _error = 1; _endMark = (_bufMark = _begMark = kp->_mark) + kp->_size; } #ifdef VOL_UPD diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 3423c430338..980c7672c39 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -49,7 +49,7 @@ class CKID { // Chunk type identifier uint32 Id; }; protected: - static XFILE *ckFile; + static XFile *ckFile; public: CKID(FOURCC t) { memcpy(Tx, t, sizeof(Tx)); @@ -57,7 +57,7 @@ public: CKID(uint32 d) { Id = d; } - CKID(XFILE *xf) { + CKID(XFile *xf) { (ckFile = xf)->read(Tx, sizeof(Tx)); } bool operator !=(CKID &X) { @@ -74,7 +74,7 @@ class CKHEA : public CKID { protected: CKSIZE ckSize; // Chunk size field (size of ckData) public: - CKHEA(XFILE *xf) : CKID(xf) { + CKHEA(XFile *xf) : CKID(xf) { XRead(xf, &ckSize); } CKHEA(char id[]) : CKID(id), ckSize(0) { } @@ -145,7 +145,7 @@ extern CKID FMT; extern CKID DATA; -DATACK *LoadWave(XFILE *file, EMM *emm = NULL); +DATACK *LoadWave(XFile *file, EMM *emm = NULL); } // End of namespace CGE From ac86efcd61aafe1ede9933f1d08b86b307de467a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 1 Jul 2011 18:04:21 +1000 Subject: [PATCH 047/276] CGE: Palette fixes so that first screen shows correctly --- engines/cge/bitmap.cpp | 9 ++++++++- engines/cge/general.cpp | 2 +- engines/cge/mouse.cpp | 6 +++--- engines/cge/vga13h.cpp | 26 +++++++++++++------------- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 64a89e93810..959301bf501 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -409,9 +409,16 @@ bool Bitmap::loadVBM(XFile *f) { if (f->_error == 0) { if (p) { if (_pal) { + // Read in the palette byte palData[PAL_SIZ]; f->read(palData, PAL_SIZ); - VGA::pal2DAC(palData, _pal); + + const byte *srcP = palData; + for (int idx = 0; idx < PAL_CNT; ++idx, srcP += 3) { + _pal[idx]._r = *srcP; + _pal[idx]._g = *(srcP + 1); + _pal[idx]._b = *(srcP + 2); + } } else f->seek(f->mark() + PAL_SIZ); } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 0b761f22998..803100d0d4b 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -136,7 +136,7 @@ char *ForceExt(char *buf, const char *nam, const char *ext) { return buf; } -static unsigned Seed = 1; +static unsigned Seed = 0xA5; unsigned FastRand(void) { return Seed = 257 * Seed + 817; diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index 5bdf7449fcc..b16f4f52b28 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -53,11 +53,11 @@ MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold( __int__(0x33); Exist = (_AX != 0); Buttons = _BX; - +*/ Goto(SCR_WID/2, SCR_HIG/2); - Z = 127; + _z = 127; Step(1); - */ + Exist = true; warning("STUB: MOUSE::MOUSE"); } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d12bb9596cf..e1bea9a15c6 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1070,9 +1070,9 @@ void VGA::GetColors(Dac *tab) { void VGA::pal2DAC(const byte *palData, Dac *tab) { const byte *colP = palData; for (int idx = 0; idx < PAL_CNT; ++idx, colP += 3) { - tab[idx]._r = *colP; - tab[idx]._g = *(colP + 1); - tab[idx]._b = *(colP + 2); + tab[idx]._r = *colP >> 2; + tab[idx]._g = *(colP + 1) >> 2; + tab[idx]._b = *(colP + 2) >> 2; } } @@ -1085,21 +1085,21 @@ void VGA::DAC2pal(const Dac *tab, byte *palData) { } void VGA::SetColors(Dac *tab, int lum) { - Dac *palP = tab; - for (int idx = 0; idx < PAL_CNT; ++idx, ++palP) { - palP->_r = (palP->_r * lum) >> 6; - palP->_g = (palP->_g * lum) >> 6; - palP->_b = (palP->_b * lum) >> 6; + Dac *palP = tab, *destP = NewColors; + for (int idx = 0; idx < PAL_CNT; ++idx, ++palP, ++destP) { + destP->_r = (palP->_r * lum) >> 6; + destP->_g = (palP->_g * lum) >> 6; + destP->_b = (palP->_b * lum) >> 6; } if (Mono) { - palP = tab; + destP = NewColors; for (int idx = 0; idx < PAL_CNT; ++idx, ++palP) { // Form a greyscalce colour from 30% R, 59% G, 11% B - uint8 intensity = (palP->_r * 77) + (palP->_g * 151) + (palP->_b * 28); - palP->_r = intensity; - palP->_g = intensity; - palP->_b = intensity; + uint8 intensity = (destP->_r * 77) + (destP->_g * 151) + (destP->_b * 28); + destP->_r = intensity; + destP->_g = intensity; + destP->_b = intensity; } } From c982298cbdf8220aa9a8151233e972f2c886c5fc Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 1 Jul 2011 18:17:58 +1000 Subject: [PATCH 048/276] CGE: Fix initialisation of the MOUSE class --- engines/cge/cge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index c921d7c6ba8..e844322e0e0 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -67,7 +67,6 @@ void CGEEngine::setup() { Hero = new WALK(this, NULL); Sys = new SYSTEM(this); _pocLight = new Sprite(this, LI); - Mouse = new MOUSE(this); for (int i = 0; i < POCKET_NX; i++) _pocket[i] = new Sprite(this, NULL); _sprite = new Sprite(this, NULL); @@ -97,6 +96,7 @@ void CGEEngine::setup() { Snail = new SNAIL(this, false); Snail_ = new SNAIL(this, true); + Mouse = new MOUSE(this); OffUseCount = atoi(Text->getText(OFF_USE_COUNT)); } From 601bfbd6095a88b2f6b77d2dec16731fe4fbf687 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 1 Jul 2011 18:18:44 +1000 Subject: [PATCH 049/276] CGE: Reimplemented game timer from using thread to using getMillis() --- engines/cge/snail.cpp | 12 ++++++------ engines/cge/snail.h | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index a10ab21658d..6600b752458 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -425,7 +425,7 @@ const char *SNAIL::ComTxt[] = { SNAIL::SNAIL(CGEEngine *vm, bool turbo) : Turbo(turbo), Busy(false), TextDelay(false), - Pause(0), TalkEnable(true), + _timerExpiry(0), TalkEnable(true), Head(0), Tail(0), SNList(farnew(COM, 256)), _vm(vm) { } @@ -446,7 +446,7 @@ void SNAIL::AddCom(SNCOM com, int ref, int val, void *ptr) { if (com == SNCLEAR) { Tail = Head; KillText(); - Pause = 0; + _timerExpiry = 0; } _enable(); } @@ -469,7 +469,7 @@ void SNAIL::InsCom(SNCOM com, int ref, int val, void *ptr) { if (com == SNCLEAR) { Tail = Head; KillText(); - Pause = 0; + _timerExpiry = 0; } _enable(); } @@ -913,7 +913,7 @@ void SNAIL::RunCom(void) { COM *snc = &SNList[Tail]; if (! Turbo) { // only for the slower one - if (Pause) + if (_timerExpiry && (_timerExpiry > g_system->getMillis())) break; else { if (TextDelay) { @@ -930,7 +930,7 @@ void SNAIL::RunCom(void) { case SNLABEL : break; case SNPAUSE : - _heart->setXTimer(&Pause, snc->Val); + _timerExpiry = g_system->getMillis() + snc->Val * SNAIL_FRAME_DELAY; if (Talk) TextDelay = true; break; @@ -938,7 +938,7 @@ void SNAIL::RunCom(void) { if (sprel) { if (sprel->SeqTest(snc->Val) && (snc->Val >= 0 || sprel != Hero || Hero->_tracePtr < 0)) { - _heart->setXTimer(&Pause, sprel->_time); + _timerExpiry = g_system->getMillis() + sprel->_time * SNAIL_FRAME_DELAY; } else goto xit; } diff --git a/engines/cge/snail.h b/engines/cge/snail.h index e1df628d3bf..3221f5c02e6 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -47,6 +47,8 @@ namespace CGE { #define SNPOST(c,r,v,p) Snail->AddCom(c,r,v,p) #define SNPOST_(c,r,v,p) Snail_->AddCom(c,r,v,p) +#define SNAIL_FRAME_RATE 62 +#define SNAIL_FRAME_DELAY (1000 / SNAIL_FRAME_RATE) typedef struct { uint8 Horz, Vert; @@ -87,7 +89,7 @@ public: } *SNList; uint8 Head, Tail; bool Turbo, Busy, TextDelay; - uint16 Pause; + uint32 _timerExpiry; static const char *ComTxt[]; bool TalkEnable; SNAIL(CGEEngine *vm, bool turbo = false); From 8e531d0da391b895a573c36c4b1bd8074571df83 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 2 Jul 2011 01:02:14 +0200 Subject: [PATCH 050/276] CGE: Some more renaming (WIP) --- engines/cge/bitmap.cpp | 23 +++--- engines/cge/bitmap.h | 16 ++-- engines/cge/cge.cpp | 2 +- engines/cge/cge_main.cpp | 165 +++++++++++++++++++-------------------- engines/cge/config.cpp | 8 +- engines/cge/game.cpp | 8 +- engines/cge/general.cpp | 61 ++++++++------- engines/cge/general.h | 36 ++++----- engines/cge/gettext.cpp | 72 ++++++++--------- engines/cge/gettext.h | 25 +++--- engines/cge/ident.h | 10 +-- engines/cge/jbw.h | 36 ++------- engines/cge/keybd.cpp | 24 +++--- engines/cge/keybd.h | 22 +++--- engines/cge/mixer.cpp | 74 +++++++++--------- engines/cge/mixer.h | 24 +++--- engines/cge/mouse.cpp | 20 ++--- engines/cge/snail.cpp | 100 ++++++++++++------------ engines/cge/snddrv.h | 16 ++-- engines/cge/sound.cpp | 2 +- engines/cge/startup.cpp | 49 ++++++------ engines/cge/talk.cpp | 8 +- engines/cge/text.cpp | 18 ++--- engines/cge/vga13h.cpp | 146 +++++++++++++++++----------------- engines/cge/vga13h.h | 59 +++++++------- engines/cge/vmenu.cpp | 12 +-- 26 files changed, 512 insertions(+), 524 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 959301bf501..dc06d9944e6 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -48,7 +48,7 @@ void Bitmap::deinit() { #pragma argsused Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { char pat[MAXPATH]; - ForceExt(pat, fname, ".VBM"); + forceExt(pat, fname, ".VBM"); #if (BMP_MODE < 2) if (rem && PIC_FILE::exist(pat)) { @@ -130,10 +130,10 @@ Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL) { Bitmap::~Bitmap(void) { - if (MemType(_m) == FAR_MEM) + if (memType(_m) == FAR_MEM) free(_m); - switch (MemType(_v)) { + switch (memType(_v)) { case NEAR_MEM : delete[](uint8 *) _v; break; @@ -152,7 +152,7 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { _w = bmp._w; _h = bmp._h; _m = NULL; - if (MemType(_v) == FAR_MEM) + if (memType(_v) == FAR_MEM) free(_v); if (v0 == NULL) _v = NULL; @@ -174,7 +174,7 @@ uint16 Bitmap::moveVmap(uint8 *buf) { uint16 vsiz = (uint8 *)_b - (uint8 *)_v; uint16 siz = vsiz + _h * sizeof(HideDesc); memcpy(buf, _v, siz); - if (MemType(_v) == FAR_MEM) + if (memType(_v) == FAR_MEM) free(_v); _b = (HideDesc *)((_v = buf) + vsiz); return siz; @@ -188,7 +188,7 @@ BMP_PTR Bitmap::code(void) { uint16 i, cnt; if (_v) { // old X-map exists, so remove it - switch (MemType(_v)) { + switch (memType(_v)) { case NEAR_MEM : delete[](uint8 *) _v; break; @@ -450,19 +450,20 @@ bool Bitmap::loadBMP(XFile *f) { union { int16 _2E; int32 _2E_; }; union { int16 _32; int32 _32_; }; } hea; - BGR4 bpal[256]; + + Bgr4 bpal[256]; f->read((byte *)&hea, sizeof(hea)); if (f->_error == 0) { if (hea.hdr == 0x436L) { - int16 i = (hea.hdr - sizeof(hea)) / sizeof(BGR4); + int16 i = (hea.hdr - sizeof(hea)) / sizeof(Bgr4); f->read((byte *)&bpal, sizeof(bpal)); if (f->_error == 0) { if (_pal) { for (i = 0; i < 256; i ++) { - _pal[i]._r = bpal[i].R; - _pal[i]._g = bpal[i].G; - _pal[i]._b = bpal[i].B; + _pal[i]._r = bpal[i]._R; + _pal[i]._g = bpal[i]._G; + _pal[i]._b = bpal[i]._B; } _pal = NULL; } diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 99464bffeb2..846f0149be6 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -41,14 +41,14 @@ namespace CGE { #include "common/pack-start.h" -struct BGR4 { - uint16 b : 2; - uint16 B : 6; - uint16 g : 2; - uint16 G : 6; - uint16 r : 2; - uint16 R : 6; - uint16 Z : 8; +struct Bgr4 { + uint16 _b : 2; + uint16 _B : 6; + uint16 _g : 2; + uint16 _G : 6; + uint16 _r : 2; + uint16 _R : 6; + uint16 _Z : 8; }; diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index e844322e0e0..43d74ab3a50 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -61,7 +61,7 @@ void CGEEngine::setup() { TALK::init(); // Initialise engine objects - Text = new TEXT(this, ProgName(), 128); + Text = new TEXT(this, progName(), 128); Vga = new VGA(M13H); _heart = new Heart; Hero = new WALK(this, NULL); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 2d4f004632a..0d8bef4b856 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -136,7 +136,6 @@ int PocPtr = 0; static EMS *Mini = MiniEmm.alloc((uint16)MINI_EMM_SIZE); static BMP_PTR *MiniShpList = NULL; static BMP_PTR MiniShp[] = { NULL, NULL }; -static KEYBOARD Keyboard; static bool Finis = false; static int Startup = 1; int OffUseCount; @@ -282,7 +281,7 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { break; S._prev = S._next = NULL; - spr = (scumm_stricmp(S.File + 2, "MUCHA") == 0) ? new Fly(this, NULL) + spr = (scumm_stricmp(S._file + 2, "MUCHA") == 0) ? new Fly(this, NULL) : new Sprite(this, NULL); if (spr == NULL) error("No core"); @@ -299,7 +298,7 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { static void SaveSound(void) { - CFile cfg(UsrPath(ProgName(CFG_EXT)), WRI); + CFile cfg(UsrPath(progName(CFG_EXT)), WRI); if (!cfg._error) cfg.write(&SNDDrvInfo, sizeof(SNDDrvInfo) - sizeof(SNDDrvInfo.VOL2)); } @@ -365,7 +364,7 @@ static void noWay() { static void LoadHeroXY(void) { - INI_FILE cf(ProgName(".HXY")); + INI_FILE cf(progName(".HXY")); memset(HeroXY, 0, sizeof(HeroXY)); if (!cf._error) cf.CFREAD(&HeroXY); @@ -374,7 +373,7 @@ static void LoadHeroXY(void) { static void LoadMapping(void) { if (Now <= CAVE_MAX) { - INI_FILE cf(ProgName(".TAB")); + INI_FILE cf(progName(".TAB")); if (!cf._error) { memset(Cluster::_map, 0, sizeof(Cluster::_map)); cf.seek((Now - 1) * sizeof(Cluster::_map)); @@ -427,7 +426,7 @@ void WALK::tick() { turn(d); } } - Step(); + step(); if ((Dir == WW && _x <= 0) || (Dir == EE && _x + _w >= SCR_WID) || (Dir == SS && _y + _w >= WORLD_HIG - 2)) @@ -465,7 +464,7 @@ int WALK::distance(Sprite *spr) { void WALK::turn(DIR d) { DIR dir = (Dir == NO_DIR) ? SS : Dir; if (d != Dir) { - Step((d == dir) ? (1 + dir + dir) : (9 + 4 * dir + d)); + step((d == dir) ? (1 + dir + dir) : (9 + 4 * dir + d)); Dir = d; } } @@ -476,7 +475,7 @@ void WALK::park(void) { ++_time; if (Dir != NO_DIR) { - Step(9 + 4 * Dir + Dir); + step(9 + 4 * Dir + Dir); Dir = NO_DIR; _tracePtr = -1; } @@ -566,7 +565,7 @@ SQUARE::SQUARE(CGEEngine *vm) void SQUARE::Touch(uint16 mask, int x, int y) { - Sprite::Touch(mask, x, y); + Sprite::touch(mask, x, y); if (mask & L_UP) { XZ(_x + x, _y + y).cell() = 0; SNPOST_(SNKILL, -1, 0, this); @@ -578,11 +577,11 @@ void CGEEngine::setMapBrick(int x, int z) { SQUARE *s = new SQUARE(this); if (s) { static char n[] = "00:00"; - s->Goto(x * MAP_XGRID, MAP_TOP + z * MAP_ZGRID); + s->gotoxy(x * MAP_XGRID, MAP_TOP + z * MAP_ZGRID); wtom(x, n + 0, 10, 2); wtom(z, n + 3, 10, 2); Cluster::_map[z][x] = 1; - s->SetName(n); + s->setName(n); Vga->ShowQ->Insert(s, Vga->ShowQ->First()); } } @@ -621,7 +620,7 @@ void CGEEngine::quit() { } else { QuitMenu[0].Text = Text->getText(QUIT_TEXT); QuitMenu[1].Text = Text->getText(NOQUIT_TEXT); - (new VMENU(this, QuitMenu, -1, -1))->SetName(Text->getText(QUIT_TITLE)); + (new VMENU(this, QuitMenu, -1, -1))->setName(Text->getText(QUIT_TITLE)); SNPOST_(SNSEQ, 123, 1, NULL); KeyClick(); } @@ -677,12 +676,12 @@ static void ShowBak(int ref) { Sprite *spr = Vga->SpareQ->Locate(ref); if (spr) { Bitmap::_pal = VGA::SysPal; - spr->Expand(); + spr->expand(); Bitmap::_pal = NULL; - spr->Show(2); + spr->show(2); Vga->CopyPage(1, 2); Sys->SetPal(); - spr->Contract(); + spr->contract(); } } @@ -701,7 +700,7 @@ static void caveUp() { if (spr->_cave == Now || spr->_cave == 0) if (spr->_ref != BakRef) { if (spr->_flags._back) - spr->BackShow(); + spr->backShow(); else ExpandSprite(spr); } @@ -715,9 +714,9 @@ static void caveUp() { } if (Hero) { - Hero->Goto(HeroXY[Now - 1]._x, HeroXY[Now - 1]._y); + Hero->gotoxy(HeroXY[Now - 1]._x, HeroXY[Now - 1]._y); // following 2 lines trims Hero's Z position! - Hero->Tick(); + Hero->tick(); Hero->_time = 1; Hero->_flags._hide = false; } @@ -732,7 +731,7 @@ static void caveUp() { if (_shadow) { Vga->ShowQ->Remove(_shadow); - _shadow->MakeXlat(glass(VGA::SysPal, 204, 204, 204)); + _shadow->makeXlat(glass(VGA::SysPal, 204, 204, 204)); Vga->ShowQ->Insert(_shadow, Hero); _shadow->_z = Hero->_z; } @@ -797,13 +796,13 @@ void CGEEngine::switchCave(int cav) { Mouse->Off(); if (Hero) { Hero->park(); - Hero->Step(0); + Hero->step(0); if (!_isDemo) ///// protection: auto-destruction on! ---------------------- Vga->SpareQ->Show = STARTUP::Summa * (cav <= CAVE_MAX); /////-------------------------------------------------------- } - _cavLight->Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, + _cavLight->gotoxy(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); KillText(); if (! Startup) @@ -838,16 +837,16 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { pp0 = pp; switch (x) { case Del: - if (KEYBOARD::Key[ALT] && KEYBOARD::Key[CTRL]) + if (Keyboard::_key[ALT] && Keyboard::_key[CTRL]) AltCtrlDel(); else KillSprite(); break; case 'F': - if (KEYBOARD::Key[ALT]) { + if (Keyboard::_key[ALT]) { Sprite *m = Vga->ShowQ->Locate(17001); if (m) { - m->Step(1); + m->step(1); m->_time = 216; // 3s } } @@ -862,7 +861,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { NextStep(); break; case '`': - if (KEYBOARD::Key[ALT]) + if (Keyboard::_key[ALT]) SaveMapping(); else _vm->switchMapping(); @@ -871,28 +870,28 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { SwitchDebug(); break; case F3: - Hero->Step(TSEQ + 4); + Hero->step(TSEQ + 4); break; case F4: - Hero->Step(TSEQ + 5); + Hero->step(TSEQ + 5); break; case F5: - Hero->Step(TSEQ + 0); + Hero->step(TSEQ + 0); break; case F6: - Hero->Step(TSEQ + 1); + Hero->step(TSEQ + 1); break; case F7: - Hero->Step(TSEQ + 2); + Hero->step(TSEQ + 2); break; case F8: - Hero->Step(TSEQ + 3); + Hero->step(TSEQ + 3); break; case F9: Sys->FunDel = 1; break; case 'X': - if (KEYBOARD::Key[ALT]) + if (Keyboard::_key[ALT]) Finis = true; break; case '0': @@ -900,7 +899,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { case '2': case '3': case '4': - if (KEYBOARD::Key[ALT]) { + if (Keyboard::_key[ALT]) { SNPOST(SNLEVEL, -1, x - '0', NULL); break; } @@ -910,7 +909,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { case '8': case '9': if (_sprite) - _sprite->Step(x - '0'); + _sprite->step(x - '0'); break; case F10 : if (Snail->Idle() && ! Hero->_flags._hide) @@ -1036,7 +1035,7 @@ static void SwitchColorMode(void) { static void SwitchMusic(void) { - if (KEYBOARD::Key[ALT]) { + if (Keyboard::_key[ALT]) { if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); else { @@ -1067,14 +1066,14 @@ void CGEEngine::startCountDown() { void CGEEngine::takeName() { - if (GET_TEXT::Ptr) - SNPOST_(SNKILL, -1, 0, GET_TEXT::Ptr); + if (GetText::_ptr) + SNPOST_(SNKILL, -1, 0, GetText::_ptr); else { - GET_TEXT *tn = new GET_TEXT(this, Text->getText(GETNAME_PROMPT), UsrFnam, 8, KeyClick); + GetText *tn = new GetText(this, Text->getText(GETNAME_PROMPT), UsrFnam, 8, KeyClick); if (tn) { - tn->SetName(Text->getText(GETNAME_TITLE)); - tn->Center(); - tn->Goto(tn->_x, tn->_y - 10); + tn->setName(Text->getText(GETNAME_TITLE)); + tn->center(); + tn->gotoxy(tn->_x, tn->_y - 10); tn->_z = 126; Vga->ShowQ->Insert(tn); } @@ -1146,14 +1145,14 @@ static void NextStep(void) { static void SaveMapping() { { - IoHand cf(ProgName(".TAB"), UPD); + IoHand cf(progName(".TAB"), UPD); if (!cf._error) { cf.seek((Now - 1) * sizeof(Cluster::_map)); cf.write((uint8 *) Cluster::_map, sizeof(Cluster::_map)); } } { - IoHand cf(ProgName(".HXY"), WRI); + IoHand cf(progName(".HXY"), WRI); if (!cf._error) { HeroXY[Now - 1]._x = Hero->_x; HeroXY[Now - 1]._y = Hero->_y; @@ -1186,7 +1185,7 @@ static char DebugText[] = " N=00000 F=000000 X=000 Y=000 FPS=0000\0S=00:00 0 static void SayDebug(void) { if (!DebugLine->_flags._hide) { static long t = -1L; - long t1 = Timer(); + long t1 = timer(); if (t1 - t >= 18) { static uint32 old = 0L; @@ -1239,9 +1238,9 @@ void CGEEngine::optionTouch(int opt, uint16 mask) { if (mask & L_UP) SwitchMusic(); else if (mask & R_UP) - if (! MIXER::Appear) { - MIXER::Appear = true; - new MIXER(this, BUTTON_X, BUTTON_Y); + if (!Mixer::_appear) { + Mixer::_appear = true; + new Mixer(this, BUTTON_X, BUTTON_Y); } break; case 3 : @@ -1253,10 +1252,10 @@ void CGEEngine::optionTouch(int opt, uint16 mask) { #pragma argsused -void Sprite::Touch(uint16 mask, int x, int y) { +void Sprite::touch(uint16 mask, int x, int y) { Sys->FunTouch(); if ((mask & ATTN) == 0) { - InfoLine->Update(Name()); + InfoLine->Update(name()); if (mask & (R_DN | L_DN)) _sprite = this; if (_ref / 10 == 12) { @@ -1273,7 +1272,7 @@ void Sprite::Touch(uint16 mask, int x, int y) { Sprite *ps = (_pocLight->_seqPtr) ? _pocket[PocPtr] : NULL; if (ps) { if (_flags._kept || Hero->distance(this) < MAX_DISTANCE) { - if (Works(ps)) { + if (works(ps)) { FeedSnail(ps, TAKE); } else OffUse(); @@ -1295,8 +1294,8 @@ void Sprite::Touch(uint16 mask, int x, int y) { _flags._port = false; } } else { - if (TakePtr != NO_PTR) { - if (SnList(TAKE)[TakePtr].Com == SNNEXT) + if (_takePtr != NO_PTR) { + if (snList(TAKE)[_takePtr].Com == SNNEXT) OffUse(); else FeedSnail(this, TAKE); @@ -1345,7 +1344,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int int i, lcnt = 0; uint16 len; - MergeExt(line, fname, SPR_EXT); + mergeExt(line, fname, SPR_EXT); if (INI_FILE::exist(line)) { // sprite description file exist INI_FILE sprf(line); if (sprf._error) @@ -1358,7 +1357,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int if (len == 0 || *line == '.') continue; - if ((i = TakeEnum(Comd, strtok(line, " =\t"))) < 0) + if ((i = takeEnum(Comd, strtok(line, " =\t"))) < 0) error("%s [%s]", NumStr("Bad line ######", lcnt), (const char *)fname); @@ -1366,7 +1365,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int case 0 : // Name - will be taken in Expand routine break; case 1 : // Type - if ((type = TakeEnum(Type, strtok(NULL, " \t,;/"))) < 0) + if ((type = takeEnum(Type, strtok(NULL, " \t,;/"))) < 0) error("%s [%s]", NumStr("Bad line ######", lcnt), (const char *)fname); break; case 2 : // Phase @@ -1394,7 +1393,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int case 1 : { // AUTO _sprite = new Sprite(this, NULL); if (_sprite) { - _sprite->Goto(col, row); + _sprite->gotoxy(col, row); //Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$ } break; @@ -1402,7 +1401,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int case 2 : { // WALK WALK *w = new WALK(this, NULL); if (w && ref == 1) { - w->Goto(col, row); + w->gotoxy(col, row); if (Hero) error("2nd HERO [%s]", fname); Hero = w; @@ -1453,7 +1452,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int default: { // DEAD _sprite = new Sprite(this, NULL); if (_sprite) - _sprite->Goto(col, row); + _sprite->gotoxy(col, row); break; } } @@ -1468,8 +1467,8 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int _sprite->_flags._bDel = true; // Extract the filename, without the extension - strcpy(_sprite->File, fname); - char *p = strchr(_sprite->File, '.'); + strcpy(_sprite->_file, fname); + char *p = strchr(_sprite->_file, '.'); if (p) *p = '\0'; @@ -1574,14 +1573,14 @@ void CGEEngine::loadUser() { SVG0FILE file = SVG0FILE(SVG0NAME); loadGame(file); } else { - loadScript(ProgName(INI_EXT)); + loadScript(progName(INI_EXT)); Music = true; CFile file = CFile(SVG0NAME, WRI); SaveGame(file); error("Ok [%s]", SVG0NAME); } } - loadScript(ProgName(IN0_EXT)); + loadScript(progName(IN0_EXT)); } @@ -1602,7 +1601,7 @@ void CGEEngine::runGame() { { 1, 6, 0, 0, 4 }, { 0, 1, 0, 0, 16 }, }; - _pocLight->SetSeq(pocSeq); + _pocLight->setSeq(pocSeq); _pocLight->_flags._tran = true; _pocLight->_time = 1; _pocLight->_z = 120; @@ -1619,7 +1618,7 @@ void CGEEngine::runGame() { if ((_sprite = Vga->SpareQ->Locate(121)) != NULL) SNPOST_(SNSEQ, -1, Vga->Mono, _sprite); if ((_sprite = Vga->SpareQ->Locate(122)) != NULL) - _sprite->Step(Music); + _sprite->step(Music); SNPOST_(SNSEQ, -1, Music, _sprite); if (! Music) KillMIDI(); @@ -1631,9 +1630,9 @@ void CGEEngine::runGame() { ExpandSprite(_miniCave = _sprite); // NULL is ok if (_miniCave) { _miniCave->_flags._hide = true; - _miniCave->MoveShapes(ptr); - MiniShp[0] = new Bitmap(*_miniCave->Shp()); - MiniShpList = _miniCave->SetShapeList(MiniShp); + _miniCave->moveShapes(ptr); + MiniShp[0] = new Bitmap(*_miniCave->shp()); + MiniShpList = _miniCave->setShapeList(MiniShp); PostMiniStep(-1); } } @@ -1641,7 +1640,7 @@ void CGEEngine::runGame() { if (Hero) { ExpandSprite(Hero); - Hero->Goto(HeroXY[Now - 1]._x, HeroXY[Now - 1]._y); + Hero->gotoxy(HeroXY[Now - 1]._x, HeroXY[Now - 1]._y); if (INI_FILE::exist("00SHADOW.SPR")) { loadSprite("00SHADOW", -1, 0, Hero->_x + 14, Hero->_y + 51); if ((_shadow = _sprite) != NULL) { @@ -1653,7 +1652,7 @@ void CGEEngine::runGame() { } } - InfoLine->Goto(INFO_X, INFO_Y); + InfoLine->gotoxy(INFO_X, INFO_Y); InfoLine->_flags._tran = true; InfoLine->Update(NULL); Vga->ShowQ->Insert(InfoLine); @@ -1672,11 +1671,11 @@ void CGEEngine::runGame() { Startup = 0; SNPOST(SNLEVEL, -1, OldLev, &_cavLight); - _cavLight->Goto(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, + _cavLight->gotoxy(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); caveUp(); - KEYBOARD::SetClient(Sys); + Keyboard::setClient(Sys); // main loop while (! Finis) { //TODO Change the SNPOST message send to a special way to send function pointer @@ -1685,7 +1684,7 @@ void CGEEngine::runGame() { mainLoop(); } - KEYBOARD::SetClient(NULL); + Keyboard::setClient(NULL); _heart->_enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); @@ -1698,7 +1697,7 @@ void CGEEngine::runGame() { void CGEEngine::movie(const char *ext) { - const char *fn = ProgName(ext); + const char *fn = progName(ext); if (INI_FILE::exist(fn)) { loadScript(fn); ExpandSprite(Vga->SpareQ->Locate(999)); @@ -1708,11 +1707,11 @@ void CGEEngine::movie(const char *ext) { //Vga->ShowQ->Append(Mouse); _heart->_enable = true; - KEYBOARD::SetClient(Sys); + Keyboard::setClient(Sys); while (!Snail->Idle()) mainLoop(); - KEYBOARD::SetClient(NULL); + Keyboard::setClient(NULL); _heart->_enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); @@ -1731,12 +1730,12 @@ bool CGEEngine::showTitle(const char *name) { Sprite D(this, LB); D._flags._kill = true; D._flags._bDel = true; - D.Center(); - D.Show(2); + D.center(); + D.show(2); if (STARTUP::Mode == 2) { inf(SVG0NAME); - Talk->Show(2); + Talk->show(2); } Vga->Sunset(); @@ -1764,7 +1763,7 @@ bool CGEEngine::showTitle(const char *name) { if (STARTUP::Mode < 2) { if (_isDemo) { - strcpy(UsrFnam, ProgName(SVG_EXT)); + strcpy(UsrFnam, progName(SVG_EXT)); usr_ok = true; } else { //----------------------------------------- @@ -1774,10 +1773,10 @@ bool CGEEngine::showTitle(const char *name) { #else // Boot * b = ReadBoot(getdisk()); warning("ShowTitle: FIXME ReadBoot"); - Boot *b = ReadBoot(0); + Boot *b = readBoot(0); uint32 sn = (b->_xSign == 0x29) ? b->_serial : b->_lTotSecs; free(b); - sn -= ((IDENT *)Copr)->disk; + sn -= ((Ident *)Copr)->_disk; STARTUP::Summa |= Lo(sn) | Hi(sn); #endif //----------------------------------------- @@ -1787,10 +1786,10 @@ bool CGEEngine::showTitle(const char *name) { Vga->ShowQ->Append(Mouse); //Mouse.On(); _heart->_enable = true; - for (takeName(); GET_TEXT::Ptr;) + for (takeName(); GetText::_ptr;) mainLoop(); _heart->_enable = false; - if (KEYBOARD::Last() == Enter && *UsrFnam) + if (Keyboard::last() == Enter && *UsrFnam) usr_ok = true; if (usr_ok) strcat(UsrFnam, SVG_EXT); diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 702c10ed154..8110e1702fa 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -147,10 +147,10 @@ void CGEEngine::selectSound() { if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); inf(Text->getText(STYPE_TEXT)); - Talk->Goto(Talk->_x, FONT_HIG / 2); + Talk->gotoxy(Talk->_x, FONT_HIG / 2); for (i = 0; i < ArrayCount(DevName); i++) DevMenu[i].Text = Text->getText(DevName[i]); - (new VMENU(this, DevMenu, SCR_WID / 2, Talk->_y + Talk->_h + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); + (new VMENU(this, DevMenu, SCR_WID / 2, Talk->_y + Talk->_h + TEXT_VM + FONT_HIG))->setName(Text->getText(MENU_TEXT)); } @@ -184,8 +184,8 @@ static int Hlp; void CGEEngine::SNSelect() { inf(Text->getText(Hlp)); - Talk->Goto(Talk->_x, FONT_HIG / 2); - (new VMENU(this, Cho, SCR_WID / 2, Talk->_y + Talk->_h + TEXT_VM + FONT_HIG))->SetName(Text->getText(MENU_TEXT)); + Talk->gotoxy(Talk->_x, FONT_HIG / 2); + (new VMENU(this, Cho, SCR_WID / 2, Talk->_y + Talk->_h + TEXT_VM + FONT_HIG))->setName(Text->getText(MENU_TEXT)); } diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 2a6bc85015b..be93709f178 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -69,13 +69,13 @@ int Fly::_l = 20, Fly::Fly(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), _tx(0), _ty(0), _vm(vm) { - Step(new_random(2)); - Goto(_l + new_random(_r - _l - _w), _t + new_random(_b - _t - _h)); + step(new_random(2)); + gotoxy(_l + new_random(_r - _l - _w), _t + new_random(_b - _t - _h)); } void Fly::tick() { - Step(); + step(); if (!_flags._kept) { if (new_random(10) < 1) { _tx = new_random(3) - 1; @@ -85,7 +85,7 @@ void Fly::tick() { _tx = -_tx; if (_y + _ty < _t || _y + _ty + _h > _b) _ty = -_ty; - Goto(_x + _tx, _y + _ty); + gotoxy(_x + _tx, _y + _ty); } } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 803100d0d4b..b2852788428 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -95,12 +95,12 @@ Dac _stdPal[] = {// R G B DRVINFO SNDDrvInfo; -EC void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)) { +void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)) { warning("STUB: _fqsort"); } -const char *ProgName(const char *ext) { - warning("ProgName"); +const char *progName(const char *ext) { + warning("progName"); static Common::String buf = "CGE"; if (ext) @@ -108,11 +108,11 @@ const char *ProgName(const char *ext) { return buf.c_str(); } -char *MergeExt(char *buf, const char *nam, const char *ext) { +char *mergeExt(char *buf, const char *nam, const char *ext) { // char dr[MAXDRIVE], di[MAXDIR], na[MAXFILE], ex[MAXEXT]; // fnmerge(buf, dr, di, na, (fnsplit(nam, dr, di, na, ex) & EXTENSION) ? ex : ext); // return buf; - warning("MergeExt"); + warning("mergeExt"); strcpy(buf, nam); char *dot = strrchr(buf, '.'); @@ -122,7 +122,7 @@ char *MergeExt(char *buf, const char *nam, const char *ext) { return buf; } -char *ForceExt(char *buf, const char *nam, const char *ext) { +char *forceExt(char *buf, const char *nam, const char *ext) { // char dr[MAXDRIVE], di[MAXDIR], na[MAXFILE], ex[MAXEXT]; // fnsplit(nam, dr, di, na, ex); // fnmerge(buf, dr, di, na, ext); @@ -279,7 +279,7 @@ bool IoHand::exist(const char *name) { //#define EMS_ADR(a) (FP_SEG(a) > 0xA000) //#define HNODE_OK(p) (heapchecknode(p)==4) -MEM_TYPE MemType(void *mem) { +MEM_TYPE memType(void *mem) { /* if (FP_SEG(mem) == _DS) { if (heapchecknode((void *)mem)==4) return NEAR_MEM; @@ -291,39 +291,39 @@ MEM_TYPE MemType(void *mem) { } return BAD_MEM; */ - warning("STUB: MemType"); + warning("STUB: memType"); return FAR_MEM; } -bool IsVga() { +bool isVga() { return true; } -EC void SNDInit() { +void SNDInit() { warning("STUB: SNDInit"); } -EC void SNDDone() { +void SNDDone() { // FIXME: STUB: SNDDone } -EC void SNDSetVolume() { +void SNDSetVolume() { warning("STUB: SNDSetVolume"); } -EC void SNDDigiStart(SMPINFO *PSmpInfo) { +void SNDDigiStart(SMPINFO *PSmpInfo) { warning("STUB: SNDDigitStart"); } -EC void SNDDigiStop(SMPINFO *PSmpInfo) { +void SNDDigiStop(SMPINFO *PSmpInfo) { warning("STUB: SNDDigiStop"); } -EC void SNDMIDIStart(uint8 *MIDFile) { +void SNDMIDIStart(uint8 *MIDFile) { warning("STUB: SNDMIDIStart"); } -EC void SNDMIDIStop() { +void SNDMIDIStop() { // FIXME: STUB: SNDMIDIStop } @@ -332,7 +332,7 @@ DATACK *LoadWave(XFile *file, EMM *emm) { return NULL; } -int TakeEnum(const char **tab, const char *txt) { +int takeEnum(const char **tab, const char *txt) { const char **e; if (txt) { for (e = tab; *e; e++) { @@ -344,22 +344,25 @@ int TakeEnum(const char **tab, const char *txt) { return -1; } -Boot *ReadBoot(int drive) { +Boot *readBoot(int drive) { /* - struct fatinfo fi; Boot *b; - getfat(drive+1, &fi); - if (fi.fi_sclus & 0x80) return NULL; - if ((b = malloc(fi.fi_bysec)) == NULL) return NULL; - // read boot sector - if (absread(drive, 1, 0L, b) == 0) return b; - free(b); - return NULL; + struct fatinfo fi; Boot *b; + getfat(drive+1, &fi); + if (fi.fi_sclus & 0x80) + return NULL; + if ((b = malloc(fi.fi_bysec)) == NULL) + return NULL; + // read boot sector + if (absread(drive, 1, 0L, b) == 0) + return b; + free(b); + return NULL; */ - warning("STUB: ReadBoot"); + warning("STUB: readBoot"); return NULL; } -long Timer(void) { +long timer(void) { /* asm mov ax,0x40 asm mov es,ax @@ -367,7 +370,7 @@ long Timer(void) { asm mov dx,es:[0x6E] return ((long) _DX << 16) | _CX; */ - warning("STUB: Timer"); + warning("STUB: timer"); return 0; } diff --git a/engines/cge/general.h b/engines/cge/general.h index 3c94e22ae46..cff00fb7f35 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -208,35 +208,35 @@ public: CRYPT XCrypt; CRYPT RCrypt; -MEM_TYPE MemType(void *mem); +MEM_TYPE memType(void *mem); uint16 atow(const char *a); uint16 xtow(const char *x); char *wtom(uint16 val, char *str, int radix, int len); char *dwtom(uint32 val, char *str, int radix, int len); -int TakeEnum(const char **tab, const char *txt); -uint16 ChkSum(void *m, uint16 n); -long Timer(void); -char *MergeExt(char *buf, const char *nam, const char *ext); -char *ForceExt(char *buf, const char *nam, const char *ext); -int DriveCD(unsigned drv); -bool IsVga(void); +int takeEnum(const char **tab, const char *txt); +uint16 chkSum(void *m, uint16 n); +long timer(); +char *mergeExt(char *buf, const char *nam, const char *ext); +char *forceExt(char *buf, const char *nam, const char *ext); +int driveCD(unsigned drv); +bool isVga(); // MISSING FUNCTIONS -EC void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)); -const char *ProgName(const char *ext = NULL); -char *MergeExt(char *buf, const char *nam, const char *ext); -char *ForceExt(char *buf, const char *nam, const char *ext); -unsigned FastRand(void); -unsigned FastRand(unsigned s); -uint16 RCrypt(void *buf, uint16 siz, uint16 seed); +void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)); +const char *progName(const char *ext = NULL); +char *mergeExt(char *buf, const char *nam, const char *ext); +char *forceExt(char *buf, const char *nam, const char *ext); +unsigned fastRand(void); +unsigned fastRand(unsigned s); +uint16 rCrypt(void *buf, uint16 siz, uint16 seed); uint16 atow(const char *a); uint16 xtow(const char *x); char *wtom(uint16 val, char *str, int radix, int len); char *dwtom(uint32 val, char * str, int radix, int len); -int TakeEnum(const char **tab, const char *txt); -Boot *ReadBoot(int drive); -long Timer(void); +int takeEnum(const char **tab, const char *txt); +Boot *readBoot(int drive); +long timer(void); int new_random(int range); } // End of namespace CGE diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index e3c60b6e217..1b609e2d8bf 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -33,56 +33,56 @@ namespace CGE { -GET_TEXT *GET_TEXT::Ptr = NULL; +GetText *GetText::_ptr = NULL; -GET_TEXT::GET_TEXT(CGEEngine *vm, const char *info, char *text, int size, void (*click)(void)) - : TALK(vm), Text(text), Size(min(size, GTMAX)), Len(min(Size, strlen(text))), - Cntr(GTBLINK), Click(click), OldKeybClient(KEYBOARD::SetClient(this)), _vm(vm) { +GetText::GetText(CGEEngine *vm, const char *info, char *text, int size, void (*click)()) + : TALK(vm), _text(text), _size(min(size, GTMAX)), _len(min(_size, strlen(text))), + _cntr(GTBLINK), _click(click), _oldKeybClient(Keyboard::setClient(this)), _vm(vm) { int i = 2 * TEXT_HM + _Font->Width(info); - Ptr = this; + _ptr = this; Mode = RECT; TS[0] = Box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); - SetShapeList(TS); + setShapeList(TS); _flags._bDel = true; _flags._kill = true; - memcpy(Buff, text, Len); - Buff[Len] = ' '; - Buff[Len + 1] = '\0'; + memcpy(_buff, text, _len); + _buff[_len] = ' '; + _buff[_len + 1] = '\0'; PutLine(0, info); - Tick(); + tick(); } -GET_TEXT::~GET_TEXT(void) { - KEYBOARD::SetClient(OldKeybClient); - Ptr = NULL; +GetText::~GetText() { + Keyboard::setClient(_oldKeybClient); + _ptr = NULL; } -void GET_TEXT::Tick(void) { - if (++ Cntr >= GTBLINK) { - Buff[Len] ^= (' ' ^ '_'); - Cntr = 0; +void GetText::tick() { + if (++_cntr >= GTBLINK) { + _buff[_len] ^= (' ' ^ '_'); + _cntr = 0; } - PutLine(1, Buff); + PutLine(1, _buff); _time = GTTIME; } -void GET_TEXT::Touch(uint16 mask, int x, int y) { +void GetText::touch(uint16 mask, int x, int y) { static char ogon[] = "•œ¥£˜ ¡"; static char bezo[] = "ACELNOSXZ"; char *p; if (mask & KEYB) { - if (Click) - Click(); + if (_click) + _click(); switch (x) { case Enter : - Buff[Len] = '\0'; - strcpy(Text, Buff); - for (p = Text; *p; p++) { + _buff[_len] = '\0'; + strcpy(_text, _buff); + for (p = _text; *p; p++) { char *q = strchr(ogon, *p); if (q) *p = bezo[q - ogon]; @@ -91,32 +91,32 @@ void GET_TEXT::Touch(uint16 mask, int x, int y) { SNPOST_(SNKILL, -1, 0, this); break; case BSp : - if (Len) { - --Len; - Buff[Len] = Buff[Len + 1]; - Buff[Len + 1] = Buff[Len + 2]; + if (_len) { + _len--; + _buff[_len] = _buff[_len + 1]; + _buff[_len + 1] = _buff[_len + 2]; } break; default : if (x < 'A' || x > 'Z') { - if (OldKeybClient) - OldKeybClient->Touch(mask, x, y); + if (_oldKeybClient) + _oldKeybClient->touch(mask, x, y); } else { - if (KEYBOARD::Key[ALT]) { + if (Keyboard::_key[ALT]) { p = strchr(bezo, x); if (p) x = ogon[p - bezo]; } - if (Len < Size && 2 * TEXT_HM + _Font->Width(Buff) + _Font->Wid[x] <= _w) { - Buff[Len + 2] = Buff[Len + 1]; - Buff[Len + 1] = Buff[Len]; - Buff[Len++] = x; + if (_len < _size && 2 * TEXT_HM + _Font->Width(_buff) + _Font->Wid[x] <= _w) { + _buff[_len + 2] = _buff[_len + 1]; + _buff[_len + 1] = _buff[_len]; + _buff[_len++] = x; } } break; } } else - Sprite::Touch(mask, x, y); + Sprite::touch(mask, x, y); } } // End of namespace CGE diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h index 33210758af1..059d84be410 100644 --- a/engines/cge/gettext.h +++ b/engines/cge/gettext.h @@ -37,18 +37,21 @@ namespace CGE { #define GTBLINK 6 #define GTTIME 6 -class GET_TEXT : public TALK { - char Buff[GTMAX + 2], * Text; - uint16 Size, Len; - uint16 Cntr; - Sprite *OldKeybClient; - void (*Click)(); +class GetText : public TALK { + char _buff[GTMAX + 2]; + char *_text; + uint16 _size; + uint16 _len; + uint16 _cntr; + Sprite *_oldKeybClient; + void (*_click)(); + public: - static GET_TEXT *Ptr; - GET_TEXT(CGEEngine *vm, const char *info, char *text, int size, void (*click)(void) = NULL); - ~GET_TEXT(); - void Touch(uint16 mask, int x, int y); - void Tick(); + static GetText *_ptr; + GetText(CGEEngine *vm, const char *info, char *text, int size, void (*click)(void) = NULL); + ~GetText(); + void touch(uint16 mask, int x, int y); + void tick(); private: CGEEngine *_vm; diff --git a/engines/cge/ident.h b/engines/cge/ident.h index da36bfa682c..afdb86d785a 100644 --- a/engines/cge/ident.h +++ b/engines/cge/ident.h @@ -30,11 +30,11 @@ namespace CGE { -struct IDENT { - char copr[83]; - char fill[8]; - unsigned long disk; - unsigned char cork; +struct Ident { + char _copr[83]; + char _fill[8]; + unsigned long _disk; + unsigned char _cork; }; } // End of namespace CGE diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 12c6609f4eb..359df8a2161 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -59,7 +59,7 @@ namespace CGE { #define ArrayCount(a) (sizeof(a) / sizeof((a)[0])) #define MAX_TIMER 0x1800B0L -typedef void (MouseFunType)(void); +typedef void (MouseFunType)(); #define Lo(d) (((int *) &d)[0]) #define Hi(d) (((int *) &d)[1]) @@ -68,7 +68,7 @@ typedef void (MouseFunType)(void); #define K(n) (1024 * (n)) #define MASK(n) ((1 << n) - 1) -typedef enum { +enum Keys { NoKey = 0, CtrlA, CtrlB, CtrlC, CtrlD, CtrlE, CtrlF, CtrlG, CtrlH, CtrlI, CtrlJ, CtrlK, CtrlL, CtrlM, CtrlN, CtrlO, CtrlP, CtrlQ, CtrlR, CtrlS, CtrlT, CtrlU, CtrlV, CtrlW, CtrlX, @@ -112,40 +112,16 @@ typedef enum { MouseRight, TwiceLeft = 512 + 256 + 1, TwiceRight -} Keys; - -struct KeyStatStruct { - int RShift : 1; - int LShift : 1; - int Ctrl : 1; - int Alt : 1; - - int ScrollLock : 1; - int NumLock : 1; - int CapsLock : 1; - int Ins : 1; - - int LeftCtrl : 1; - int LeftAlt : 1; - int Unused : 6; }; #define HGC_Cursor 0x0B0C #define CGA_Cursor 0x0607 #define OFF_Cursor 0x2000 -#define TimerCount (*((volatile long *) ((void _seg *) 0x40 + (void *) 0x6C))) -#define KeyStat (*((volatile struct KeyStatStruct *) ((void _seg *) 0x40 + (void *) 0x17))) -#define BreakFlag (*((volatile uint8 *) ((void _seg *) 0x40 + (void *) 0x71))) -#define PostFlag (*((volatile uint16 *) ((void _seg *) 0x40 + (void *) 0x72))) -#define POST ((void (*)(void)) ((void _seg *) 0xF000 + (void *) 0xFFF0)) - - -#ifdef __cplusplus -#define EC extern "C" -#else -#define EC -#endif +//#define TimerCount (*((volatile long *) ((void _seg *) 0x40 + (void *) 0x6C))) +//#define BreakFlag (*((volatile uint8 *) ((void _seg *) 0x40 + (void *) 0x71))) +//#define PostFlag (*((volatile uint16 *) ((void _seg *) 0x40 + (void *) 0x72))) +//#define POST ((void (*)(void)) ((void _seg *) 0xF000 + (void *) 0xFFF0)) extern uint16 _stklen; diff --git a/engines/cge/keybd.cpp b/engines/cge/keybd.cpp index 8530815b16e..45237d15d1a 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/keybd.cpp @@ -30,10 +30,10 @@ namespace CGE { -Sprite *KEYBOARD::Client = NULL; -uint8 KEYBOARD::Key[0x60] = { 0 }; -uint16 KEYBOARD::Current = 0; -uint16 KEYBOARD::Code[0x60] = { +Sprite *Keyboard::_client = NULL; +uint8 Keyboard::_key[0x60] = { 0 }; +uint16 Keyboard::_current = 0; +uint16 Keyboard::_code[0x60] = { 0, Esc, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '+', BSp, @@ -56,20 +56,20 @@ uint16 KEYBOARD::Code[0x60] = { 0 * 0x5F }; -void (* KEYBOARD::OldKeyboard)(...); +void (* Keyboard::OldKeyboard)(...); -KEYBOARD::KEYBOARD(void) { +Keyboard::Keyboard() { // steal keyboard interrupt /* TODO replace totally by scummvm handling OldKeyboard = getvect(KEYBD_INT); setvect(KEYBD_INT, NewKeyboard); */ - warning("STUB: KEYBOARD::KEYBOARD"); + warning("STUB: Keyboard::Keyboard"); } -KEYBOARD::~KEYBOARD(void) { +Keyboard::~Keyboard() { // bring back keyboard interrupt /* TODO replace totally by scummvm handling setvect(KEYBD_INT, OldKeyboard); @@ -78,13 +78,13 @@ KEYBOARD::~KEYBOARD(void) { } -Sprite *KEYBOARD::SetClient(Sprite *spr) { - Swap(Client, spr); +Sprite *Keyboard::setClient(Sprite *spr) { + Swap(_client, spr); return spr; } -void KEYBOARD::NewKeyboard(...) { +void Keyboard::NewKeyboard(...) { // table address /* _SI = (uint16) Key; @@ -145,7 +145,7 @@ void KEYBOARD::NewKeyboard(...) { asm mov al,20h // send End-Of-Interrupt asm out 20h,al // to the 8259 IC */ - warning("STUB: KEYBOARD::NewKeyboard"); + warning("STUB: Keyboard::NewKeyboard"); } } // End of namespace CGE diff --git a/engines/cge/keybd.h b/engines/cge/keybd.h index 2cdbd558d8a..bb87ffb0edf 100644 --- a/engines/cge/keybd.h +++ b/engines/cge/keybd.h @@ -40,22 +40,22 @@ namespace CGE { #define ALT 56 -class KEYBOARD { +class Keyboard { public: static void (* OldKeyboard)(...); static void NewKeyboard(...); - static uint16 Code[0x60]; - static uint16 Current; - static Sprite *Client; - static uint8 Key[0x60]; - static uint16 Last(void) { - uint16 cur = Current; - Current = 0; + static uint16 _code[0x60]; + static uint16 _current; + static Sprite *_client; + static uint8 _key[0x60]; + static uint16 last() { + uint16 cur = _current; + _current = 0; return cur; } - static Sprite *SetClient(Sprite *spr); - KEYBOARD(void); - ~KEYBOARD(void); + static Sprite *setClient(Sprite *spr); + Keyboard(); + ~Keyboard(); }; } // End of namespace CGE diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index a5ef5b8b624..b6442f3cd3b 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -37,19 +37,19 @@ namespace CGE { extern MOUSE *Mouse; -bool MIXER::Appear = false; +bool Mixer::_appear = false; -MIXER::MIXER(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), Fall(MIX_FALL), _vm(vm) { - Appear = true; - mb[0] = new Bitmap("VOLUME", true); - mb[1] = NULL; - SetShapeList(mb); - SetName(Text->getText(MIX_NAME)); +Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(MIX_FALL), _vm(vm) { + _appear = true; + _mb[0] = new Bitmap("VOLUME", true); + _mb[1] = NULL; + setShapeList(_mb); + setName(Text->getText(MIX_NAME)); _flags._syst = true; _flags._kill = true; _flags._bDel = true; - Goto(x, y); + gotoxy(x, y); _z = MIX_Z; // slaves @@ -58,27 +58,27 @@ MIXER::MIXER(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), Fall(MIX_FALL), _v for (i = 0; i < MIX_MAX; i++) { static char fn[] = "V00"; wtom(i, fn + 1, 10, 2); - lb[i] = new Bitmap(fn, true); - ls[i].Now = ls[i].Next = i; - ls[i].Dx = ls[i].Dy = ls[i].Dly = 0; + _lb[i] = new Bitmap(fn, true); + _ls[i].Now = _ls[i].Next = i; + _ls[i].Dx = _ls[i].Dy = _ls[i].Dly = 0; } - lb[i] = NULL; + _lb[i] = NULL; - for (i = 0; i < ArrayCount(Led); i++) { - register Sprite *spr = new Sprite(_vm, lb); - spr->SetSeq(ls); - spr->Goto(x + 2 + 12 * i, y + 8); + for (i = 0; i < ArrayCount(_led); i++) { + register Sprite *spr = new Sprite(_vm, _lb); + spr->setSeq(_ls); + spr->gotoxy(x + 2 + 12 * i, y + 8); spr->_flags._tran = true; spr->_flags._kill = true; spr->_flags._bDel = false; spr->_z = MIX_Z; - Led[i] = spr; + _led[i] = spr; } - Led[ArrayCount(Led) - 1]->_flags._bDel = true; + _led[ArrayCount(_led) - 1]->_flags._bDel = true; Vga->ShowQ->Insert(this); - for (i = 0; i < ArrayCount(Led); i++) - Vga->ShowQ->Insert(Led[i]); + for (i = 0; i < ArrayCount(_led); i++) + Vga->ShowQ->Insert(_led[i]); //--- reset balance i = (SNDDrvInfo.VOL4.ML + SNDDrvInfo.VOL4.MR) / 2; @@ -87,18 +87,18 @@ MIXER::MIXER(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), Fall(MIX_FALL), _v i = (SNDDrvInfo.VOL4.DL + SNDDrvInfo.VOL4.DR) / 2; SNDDrvInfo.VOL4.DL = i; SNDDrvInfo.VOL4.DR = i; - Update(); + update(); _time = MIX_DELAY; } -MIXER::~MIXER(void) { - Appear = false; +Mixer::~Mixer() { + _appear = false; } #pragma argsused -void MIXER::Touch(uint16 mask, int x, int y) { - Sprite::Touch(mask, x, y); +void Mixer::touch(uint16 mask, int x, int y) { + Sprite::touch(mask, x, y); if (mask & L_UP) { uint8 *vol = (&SNDDrvInfo.VOL2.D) + (x < _w / 2); if (y < MIX_BHIG) { @@ -108,24 +108,24 @@ void MIXER::Touch(uint16 mask, int x, int y) { if (*vol > 0x00) *vol -= 0x11; } - Update(); + update(); } } -void MIXER::Tick(void) { +void Mixer::tick() { int x = Mouse->_x; int y = Mouse->_y; if (SpriteAt(x, y) == this) { - Fall = MIX_FALL; + _fall = MIX_FALL; if (_flags._hold) - Touch(L_UP, x - _x, y - _y); + touch(L_UP, x - _x, y - _y); } else { - if (Fall) - --Fall; + if (_fall) + _fall--; else { - for (uint i = 0; i < ArrayCount(Led); i++) - SNPOST_(SNKILL, -1, 0, Led[i]); + for (uint i = 0; i < ArrayCount(_led); i++) + SNPOST_(SNKILL, -1, 0, _led[i]); SNPOST_(SNKILL, -1, 0, this); } } @@ -133,13 +133,13 @@ void MIXER::Tick(void) { } -void MIXER::Update(void) { - Led[0]->Step(SNDDrvInfo.VOL4.ML); - Led[1]->Step(SNDDrvInfo.VOL4.DL); +void Mixer::update(void) { + _led[0]->step(SNDDrvInfo.VOL4.ML); + _led[1]->step(SNDDrvInfo.VOL4.DL); //TODO Change the SNPOST message send to a special way to send function pointer //SNPOST_(SNEXEC, -1, 0, (void*)&SNDSetVolume); - warning("STUB: MIXER::Update"); + warning("STUB: Mixer::Update"); } } // End of namespace CGE diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index d42d25ca24c..a86e65d3d18 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -39,19 +39,19 @@ namespace CGE { #define MIX_BHIG 6 // mixer button high #define MIX_NAME 105 // sprite name -class MIXER : public Sprite { - BMP_PTR mb[2]; - BMP_PTR lb[MIX_MAX + 1]; - Seq ls[MIX_MAX]; - Sprite *Led[2]; - int Fall; - void Update(void); +class Mixer : public Sprite { + BMP_PTR _mb[2]; + BMP_PTR _lb[MIX_MAX + 1]; + Seq _ls[MIX_MAX]; + Sprite *_led[2]; + int _fall; + void update(); public: - static bool Appear; - MIXER(CGEEngine *vm, int x, int y); - ~MIXER(); - void Touch(uint16 mask, int x, int y); - void Tick(); + static bool _appear; + Mixer(CGEEngine *vm, int x, int y); + ~Mixer(); + void touch(uint16 mask, int x, int y); + void tick(); private: CGEEngine *_vm; }; diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp index b16f4f52b28..a1b6b253ced 100644 --- a/engines/cge/mouse.cpp +++ b/engines/cge/mouse.cpp @@ -45,7 +45,7 @@ MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold( { 1, 1, 0, 0, 1 } }; - SetSeq(ms); + setSeq(ms); /* TODO Mouse handling // Mouse reset @@ -54,9 +54,9 @@ MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold( Exist = (_AX != 0); Buttons = _BX; */ - Goto(SCR_WID/2, SCR_HIG/2); + gotoxy(SCR_WID/2, SCR_HIG/2); _z = 127; - Step(1); + step(1); Exist = true; warning("STUB: MOUSE::MOUSE"); @@ -144,25 +144,25 @@ void MOUSE::ClrEvt(Sprite *spr) { void MOUSE::Tick(void) { - Step(); + step(); while (EvtTail != EvtHead) { Event e = Evt[EvtTail]; if (e._msk) { if (Hold && e._ptr != Hold) - Hold->Touch(e._msk | ATTN, e._x - Hold->_x, e._y - Hold->_y); + Hold->touch(e._msk | ATTN, e._x - Hold->_x, e._y - Hold->_y); // update mouse cursor position if (e._msk & ROLL) - Goto(e._x, e._y); + gotoxy(e._x, e._y); // activate current touched SPRITE if (e._ptr) { if (e._msk & KEYB) - e._ptr->Touch(e._msk, e._x, e._y); + e._ptr->touch(e._msk, e._x, e._y); else - e._ptr->Touch(e._msk, e._x - e._ptr->_x, e._y - e._ptr->_y); + e._ptr->touch(e._msk, e._x - e._ptr->_x, e._y - e._ptr->_y); } else if (Sys) - Sys->Touch(e._msk, e._x, e._y); + Sys->touch(e._msk, e._x, e._y); if (e._msk & L_DN) { Hold = e._ptr; @@ -188,7 +188,7 @@ void MOUSE::Tick(void) { EvtTail = (EvtTail + 1) % EVT_MAX; } if (Hold) - Hold->Goto(_x - hx, _y - hy); + Hold->gotoxy(_x - hx, _y - hy); } } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 6600b752458..baaac250dd5 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -177,14 +177,14 @@ static void SNGame(Sprite *spr, int num) { SNPOST(SNGAME, 20002, 2, NULL); Game = true; } else { // cont - k1->Step(new_random(6)); - k2->Step(new_random(6)); - k3->Step(new_random(6)); + k1->step(new_random(6)); + k2->step(new_random(6)); + k3->step(new_random(6)); ///-------------------- - if (spr->_ref == 1 && KEYBOARD::Key[ALT]) { - k1->Step(5); - k2->Step(5); - k3->Step(5); + if (spr->_ref == 1 && Keyboard::_key[ALT]) { + k1->step(5); + k2->step(5); + k3->step(5); } ///-------------------- SNPOST(SNSETZ, 20700, 0, NULL); @@ -207,7 +207,7 @@ static void SNGame(Sprite *spr, int num) { Game = false; return; } else - k3->Step(new_random(5)); + k3->step(new_random(5)); } if (count < 100) { switch (count) { @@ -296,17 +296,17 @@ int FindPocket(Sprite *spr) { void SelectPocket(int n) { if (n < 0 || (_pocLight->_seqPtr && PocPtr == n)) { - _pocLight->Step(0); + _pocLight->step(0); n = FindPocket(NULL); if (n >= 0) PocPtr = n; } else { if (_pocket[n] != NULL) { PocPtr = n; - _pocLight->Step(1); + _pocLight->step(1); } } - _pocLight->Goto(POCKET_X + PocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY); + _pocLight->gotoxy(POCKET_X + PocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY); } @@ -321,7 +321,7 @@ void PocFul(void) { void Hide1(Sprite *spr) { - SNPOST_(SNGHOST, -1, 0, spr->Ghost()); + SNPOST_(SNGHOST, -1, 0, spr->ghost()); } @@ -336,11 +336,11 @@ void SNGhost(Bitmap *bmp) { void FeedSnail(Sprite *spr, SNLIST snq) { if (spr) - if (spr->Active()) { - uint8 ptr = (snq == TAKE) ? spr->TakePtr : spr->NearPtr; + if (spr->active()) { + uint8 ptr = (snq == TAKE) ? spr->_takePtr : spr->_nearPtr; if (ptr != NO_PTR) { - SNAIL::COM *comtab = spr->SnList(snq); + SNAIL::COM *comtab = spr->snList(snq); SNAIL::COM *c = comtab + ptr; if (FindPocket(NULL) < 0) { // no empty pockets? @@ -362,7 +362,7 @@ void FeedSnail(Sprite *spr, SNLIST snq) { if (c->Com == SNNEXT) { Sprite *s = (c->Ref < 0) ? spr : Locate(c->Ref); if (s) { - uint8 *idx = (snq == TAKE) ? &s->TakePtr : &s->NearPtr; + uint8 *idx = (snq == TAKE) ? &s->_takePtr : &s->_nearPtr; if (*idx != NO_PTR) { int v; switch (c->Val) { @@ -389,7 +389,7 @@ void FeedSnail(Sprite *spr, SNLIST snq) { if (c->Com == SNIF) { Sprite *s = (c->Ref < 0) ? spr : Locate(c->Ref); if (s) { // sprite extsts - if (! s->SeqTest(-1)) + if (! s->seqTest(-1)) c = comtab + c->Val; // not parked else ++c; @@ -477,35 +477,35 @@ void SNAIL::InsCom(SNCOM com, int ref, int val, void *ptr) { static void SNNNext(Sprite *sprel, int p) { if (sprel) - if (sprel->NearPtr != NO_PTR) - sprel->NearPtr = p; + if (sprel->_nearPtr != NO_PTR) + sprel->_nearPtr = p; } static void SNTNext(Sprite *sprel, int p) { if (sprel) - if (sprel->TakePtr != NO_PTR) - sprel->TakePtr = p; + if (sprel->_takePtr != NO_PTR) + sprel->_takePtr = p; } static void SNRNNext(Sprite *sprel, int p) { if (sprel) - if (sprel->NearPtr != NO_PTR) - sprel->NearPtr += p; + if (sprel->_nearPtr != NO_PTR) + sprel->_nearPtr += p; } static void SNRTNext(Sprite *sprel, int p) { if (sprel) - if (sprel->TakePtr != NO_PTR) - sprel->TakePtr += p; + if (sprel->_takePtr != NO_PTR) + sprel->_takePtr += p; } static void SNZTrim(Sprite *spr) { if (spr) - if (spr->Active()) { + if (spr->active()) { bool en = _heart->_enable; Sprite *s; _heart->_enable = false; @@ -531,13 +531,13 @@ static void SNHide(Sprite *spr, int val) { static void SNRmNear(Sprite *spr) { if (spr) - spr->NearPtr = NO_PTR; + spr->_nearPtr = NO_PTR; } static void SNRmTake(Sprite *spr) { if (spr) - spr->TakePtr = NO_PTR; + spr->_takePtr = NO_PTR; } @@ -546,7 +546,7 @@ void SNSeq(Sprite *spr, int val) { if (spr == Hero && val == 0) Hero->park(); else - spr->Step(val); + spr->step(val); } } @@ -577,7 +577,7 @@ void SNSend(Sprite *spr, int val) { if (spr->_ref % 1000 == 0) Bitmap::_pal = VGA::SysPal; if (spr->_flags._back) - spr->BackShow(true); + spr->backShow(true); else ExpandSprite(spr); Bitmap::_pal = NULL; @@ -628,7 +628,7 @@ void SNCover(Sprite *spr, int xref) { spr->_flags._hide = true; xspr->_z = spr->_z; xspr->_cave = spr->_cave; - xspr->Goto(spr->_x, spr->_y); + xspr->gotoxy(spr->_x, spr->_y); ExpandSprite(xspr); if ((xspr->_flags._shad = spr->_flags._shad) == 1) { Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr->_prev), xspr); @@ -643,7 +643,7 @@ void SNUncover(Sprite *spr, Sprite *xspr) { if (spr && xspr) { spr->_flags._hide = false; spr->_cave = xspr->_cave; - spr->Goto(xspr->_x, xspr->_y); + spr->gotoxy(xspr->_x, xspr->_y); if ((spr->_flags._shad = xspr->_flags._shad) == 1) { Vga->ShowQ->Insert(Vga->ShowQ->Remove(xspr->_prev), spr); xspr->_flags._shad = false; @@ -668,19 +668,19 @@ void SNSetY0(int cav, int y0) { void SNSetXY(Sprite *spr, uint16 xy) { if (spr) - spr->Goto(xy % SCR_WID, xy / SCR_WID); + spr->gotoxy(xy % SCR_WID, xy / SCR_WID); } void SNRelX(Sprite *spr, int x) { if (spr && Hero) - spr->Goto(Hero->_x + x, spr->_y); + spr->gotoxy(Hero->_x + x, spr->_y); } void SNRelY(Sprite *spr, int y) { if (spr && Hero) - spr->Goto(spr->_x, Hero->_y + y); + spr->gotoxy(spr->_x, Hero->_y + y); } @@ -694,13 +694,13 @@ void SNRelZ(Sprite *spr, int z) { void SNSetX(Sprite *spr, int x) { if (spr) - spr->Goto(x, spr->_y); + spr->gotoxy(x, spr->_y); } void SNSetY(Sprite *spr, int y) { if (spr) - spr->Goto(spr->_x, y); + spr->gotoxy(spr->_x, y); } @@ -716,7 +716,7 @@ void SNSetZ(Sprite *spr, int z) { void SNSlave(Sprite *spr, int ref) { Sprite *slv = Locate(ref); if (spr && slv) { - if (spr->Active()) { + if (spr->active()) { SNSend(slv, spr->_cave); slv->_flags._slav = true; slv->_z = spr->_z; @@ -780,10 +780,10 @@ void SNKeep(Sprite *spr, int stp) { _pocket[PocPtr] = spr; spr->_cave = 0; spr->_flags._kept = true; - spr->Goto(POCKET_X + POCKET_DX * PocPtr + POCKET_DX / 2 - spr->_w / 2, + spr->gotoxy(POCKET_X + POCKET_DX * PocPtr + POCKET_DX / 2 - spr->_w / 2, POCKET_Y + POCKET_DY / 2 - spr->_h / 2); if (stp >= 0) - spr->Step(stp); + spr->step(stp); } SelectPocket(-1); } @@ -797,7 +797,7 @@ void SNGive(Sprite *spr, int stp) { spr->_cave = Now; spr->_flags._kept = false; if (stp >= 0) - spr->Step(stp); + spr->step(stp); } } SelectPocket(-1); @@ -807,8 +807,8 @@ void SNGive(Sprite *spr, int stp) { static void SNBackPt(Sprite *spr, int stp) { if (spr) { if (stp >= 0) - spr->Step(stp); - spr->BackShow(true); + spr->step(stp); + spr->backShow(true); } } @@ -823,7 +823,7 @@ static void SNLevel(Sprite *spr, int lev) { ++Lev; spr = Vga->SpareQ->Locate(100 + Lev); if (spr) { - spr->BackShow(true); + spr->backShow(true); spr->_cave = 0; } } @@ -936,7 +936,7 @@ void SNAIL::RunCom(void) { break; case SNWAIT : if (sprel) { - if (sprel->SeqTest(snc->Val) && + if (sprel->seqTest(snc->Val) && (snc->Val >= 0 || sprel != Hero || Hero->_tracePtr < 0)) { _timerExpiry = g_system->getMillis() + sprel->_time * SNAIL_FRAME_DELAY; } else @@ -951,8 +951,8 @@ void SNAIL::RunCom(void) { break; case SNSAY : if (sprel && TalkEnable) { - if (sprel == Hero && sprel->SeqTest(-1)) - sprel->Step(HTALK); + if (sprel == Hero && sprel->seqTest(-1)) + sprel->step(HTALK); Text->Say(Text->getText(snc->Val), sprel); Sys->FunDel = HEROFUN0; } @@ -965,8 +965,8 @@ void SNAIL::RunCom(void) { break; case SNTIME : if (sprel && TalkEnable) { - if (sprel == Hero && sprel->SeqTest(-1)) - sprel->Step(HTALK); + if (sprel == Hero && sprel->seqTest(-1)) + sprel->step(HTALK); SayTime(sprel); } break; @@ -1106,7 +1106,7 @@ void SNAIL::RunCom(void) { // ((void(*)(int)) (snc->Ptr))(snc->Val); break; warning("STUB: SNEXEC code"); case SNSTEP : - sprel->Step(); + sprel->step(); break; case SNZTRIM : SNZTrim(sprel); diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 3d1658e1e05..2de90140340 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -101,29 +101,29 @@ extern uint16 MIDIEndFlag; // * Driver Code * // ****************************************************** // Init Digi Device -EC void SNDInit(void); +void SNDInit(); // Close Digi Device -EC void SNDDone(void); +void SNDDone(); // Set Volume -EC void SNDSetVolume(void); +void SNDSetVolume(); // Start Digi -EC void SNDDigiStart(SMPINFO *PSmpInfo); +void SNDDigiStart(SMPINFO *PSmpInfo); // Stop Digi -EC void SNDDigiStop(SMPINFO *PSmpInfo); +void SNDDigiStop(SMPINFO *PSmpInfo); // Start MIDI File -EC void SNDMIDIStart(uint8 *MIDFile); +void SNDMIDIStart(uint8 *MIDFile); // Stop MIDI File -EC void SNDMIDIStop(void); +void SNDMIDIStop(); // Play MIDI File (to be called while interrupting) // WARNING: Uses ALL registers! -EC void SNDMIDIPlay(void); +void SNDMIDIPlay(); } // End of namespace CGE diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index a59179710bd..75adf3868a2 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -205,7 +205,7 @@ void LoadMIDI(int ref) { } -EC void *Patch(int pat) { +void *Patch(int pat) { void *p = NULL; static char fn[] = "PATCH000.SND"; diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 4895ce98611..028e4c61b1d 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -39,7 +39,7 @@ namespace CGE { extern char Copr[]; -#define id (*(IDENT*)Copr) +#define id (*(Ident*)Copr) EMM MiniEmm = MINI_EMM_SIZE; @@ -65,7 +65,7 @@ bool STARTUP::get_parms(void) { { static char *PrmTab[] = { "NEW", "MK0SVG", "QUIET", "SB", "GUS", "MIDI", "P", "D", "I", "M" }; - int n = TakeEnum(PrmTab, strtok(_argv[--i], " =:(")); + int n = takeEnum(PrmTab, strtok(_argv[--i], " =:(")); uint16 p = xtow(strtok(NULL, " h,)")); switch (n) { @@ -99,7 +99,7 @@ bool STARTUP::get_parms(void) { Summa = 0; #else // disk signature checksum - Summa = ChkSum(Copr, sizeof(IDENT)); + Summa = ChkSum(Copr, sizeof(Ident)); #endif #endif if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; @@ -112,26 +112,31 @@ bool STARTUP::get_parms(void) { STARTUP::STARTUP(void) { /* - uint32 m = farcoreleft() >> 10; - if (m < 0x7FFF) Core = (int) m; else Core = 0x7FFF; + uint32 m = farcoreleft() >> 10; + if (m < 0x7FFF) + Core = (int) m; + else + Core = 0x7FFF; - if (! IsVga()) quit_now(NOT_VGA_TEXT); - if (Cpu() < _80286) quit_now(BAD_CHIP_TEXT); - if (100 * _osmajor + _osminor < 330) quit_now(BAD_DOS_TEXT); - - if (! get_parms()) quit_now(BAD_ARG_TEXT); - //--- load sound configuration - const char * fn = UsrPath(ProgName(CFG_EXT)); - if (! STARTUP::SoundOk && CFILE::Exist(fn)) - { - CFILE cfg(fn, REA); - if (! cfg.Error) - { - cfg.Read(&SNDDrvInfo, sizeof(SNDDrvInfo)-sizeof(SNDDrvInfo.VOL2)); - if (! cfg.Error) STARTUP::SoundOk = 1; - } - } - */ + if (! IsVga()) + quit_now(NOT_VGA_TEXT); + if (Cpu() < _80286) + quit_now(BAD_CHIP_TEXT); + if (100 * _osmajor + _osminor < 330) + quit_now(BAD_DOS_TEXT); + if (! get_parms()) + quit_now(BAD_ARG_TEXT); + //--- load sound configuration + const char * fn = UsrPath(ProgName(CFG_EXT)); + if (! STARTUP::SoundOk && CFILE::Exist(fn)) { + CFILE cfg(fn, REA); + if (! cfg.Error) { + cfg.Read(&SNDDrvInfo, sizeof(SNDDrvInfo)-sizeof(SNDDrvInfo.VOL2)); + if (! cfg.Error) + STARTUP::SoundOk = 1; + } + } + */ warning("STUB: STARTUP::STARTUP"); } diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index fab1abc0d85..38625e2971d 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -48,7 +48,7 @@ FONT::FONT(const char *name) { Wid = farnew(uint8, WID_SIZ); if ((Map == NULL) || (Pos == NULL) || (Wid == NULL)) error("No core"); - MergeExt(Path, name, FONT_EXT); + mergeExt(Path, name, FONT_EXT); Load(); } @@ -126,7 +126,7 @@ TALK::~TALK (void) { FONT *TALK::_Font; void TALK::init() { - _Font = new FONT(ProgName()); + _Font = new FONT(progName()); } void TALK::deinit() { @@ -182,7 +182,7 @@ void TALK::Update(const char *tx) { tx++; } TS[0]->code(); - SetShapeList(TS); + setShapeList(TS); } @@ -286,7 +286,7 @@ void TALK::PutLine(int line, const char *text) { INFO_LINE::INFO_LINE(CGEEngine *vm, uint16 w) : TALK(vm), OldTxt(NULL), _vm(vm) { TS[0] = new Bitmap(w, FONT_HIG, TEXT_BG); - SetShapeList(TS); + setShapeList(TS); } diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 515c1091f80..f98b7f5d1ce 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -44,7 +44,7 @@ TALK *Talk = NULL; TEXT::TEXT(CGEEngine *vm, const char *fname, int size) : _vm(vm) { Cache = new HAN[size]; - MergeExt(FileName, fname, SAY_EXT); + mergeExt(FileName, fname, SAY_EXT); if (!INI_FILE::exist(FileName)) error("No talk (%s)\n", FileName); @@ -203,17 +203,17 @@ void TEXT::Say(const char *txt, Sprite *spr) { Talk->_flags._kill = true; Talk->_flags._bDel = true; - Talk->SetName(Text->getText(SAY_NAME)); - Talk->Goto(x - (Talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - Talk->_h + 1); + Talk->setName(Text->getText(SAY_NAME)); + Talk->gotoxy(x - (Talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - Talk->_h + 1); Talk->_z = 125; Talk->_ref = SAY_REF; - spike->Goto(x, Talk->_y + Talk->_h - 1); + spike->gotoxy(x, Talk->_y + Talk->_h - 1); spike->_z = 126; spike->_flags._slav = true; spike->_flags._kill = true; - spike->SetName(Text->getText(SAY_NAME)); - spike->Step(east); + spike->setName(Text->getText(SAY_NAME)); + spike->step(east); spike->_ref = SAY_REF; Vga->ShowQ->Insert(Talk, Vga->ShowQ->Last()); @@ -227,9 +227,9 @@ void CGEEngine::inf(const char *txt) { if (Talk) { Talk->_flags._kill = true; Talk->_flags._bDel = true; - Talk->SetName(Text->getText(INF_NAME)); - Talk->Center(); - Talk->Goto(Talk->_x, Talk->_y - 20); + Talk->setName(Text->getText(INF_NAME)); + Talk->center(); + Talk->gotoxy(Talk->_x, Talk->_y - 20); Talk->_z = 126; Talk->_ref = INF_REF; Vga->ShowQ->Insert(Talk, Vga->ShowQ->Last()); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index e1bea9a15c6..0e865ffd90b 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -356,21 +356,21 @@ void Heart::setXTimer(uint16 *ptr, uint16 time) { Sprite::Sprite(CGEEngine *vm, BMP_PTR *shp) - : _x(0), _y(0), _z(0), NearPtr(0), TakePtr(0), + : _x(0), _y(0), _z(0), _nearPtr(0), _takePtr(0), _next(NULL), _prev(NULL), _seqPtr(NO_SEQ), _time(0), //Delay(0), _ext(NULL), _ref(-1), _cave(0), _vm(vm) { - memset(File, 0, sizeof(File)); + memset(_file, 0, sizeof(_file)); *((uint16 *)&_flags) = 0; - SetShapeList(shp); + setShapeList(shp); } Sprite::~Sprite() { - Contract(); + contract(); } -BMP_PTR Sprite::Shp() { +BMP_PTR Sprite::shp() { register SprExt *e = _ext; if (e) if (e->_seq) { @@ -380,7 +380,7 @@ BMP_PTR Sprite::Shp() { //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", // Seq, ShpCnt, SeqPtr, Seq[SeqPtr].Now, Seq[SeqPtr].Next); //VGA::Exit(s, File); - error("Invalid PHASE in SPRITE::Shp() %s", File); + error("Invalid PHASE in SPRITE::Shp() %s", _file); } return e->_shpList[i]; } @@ -388,7 +388,7 @@ BMP_PTR Sprite::Shp() { } -BMP_PTR *Sprite::SetShapeList(BMP_PTR *shp) { +BMP_PTR *Sprite::setShapeList(BMP_PTR *shp) { BMP_PTR *r = (_ext) ? _ext->_shpList : NULL; _shpCnt = 0; @@ -405,16 +405,16 @@ BMP_PTR *Sprite::SetShapeList(BMP_PTR *shp) { _h = b->_h; _shpCnt++; } - Expand(); + expand(); _ext->_shpList = shp; if (!_ext->_seq) - SetSeq((_shpCnt < 2) ? _seq1 : _seq2); + setSeq((_shpCnt < 2) ? _seq1 : _seq2); } return r; } -void Sprite::MoveShapes(uint8 *buf) { +void Sprite::moveShapes(uint8 *buf) { BMP_PTR *p; for (p = _ext->_shpList; *p; p++) { buf += (*p)->moveVmap(buf); @@ -422,12 +422,12 @@ void Sprite::MoveShapes(uint8 *buf) { } -bool Sprite::Works(Sprite *spr) { +bool Sprite::works(Sprite *spr) { if (spr) if (spr->_ext) { SNAIL::COM *c = spr->_ext->_take; if (c != NULL) { - c += spr->TakePtr; + c += spr->_takePtr; if (c->Ref == _ref) if (c->Com != SNLABEL || (c->Val == 0 || c->Val == Now)) return true; @@ -437,19 +437,19 @@ bool Sprite::Works(Sprite *spr) { } -Seq *Sprite::SetSeq(Seq *seq) { - Expand(); +Seq *Sprite::setSeq(Seq *seq) { + expand(); register Seq *s = _ext->_seq; _ext->_seq = seq; if (_seqPtr == NO_SEQ) - Step(0); + step(0); else if (_time == 0) - Step(_seqPtr); + step(_seqPtr); return s; } -bool Sprite::SeqTest(int n) { +bool Sprite::seqTest(int n) { if (n >= 0) return (_seqPtr == n); if (_ext) @@ -458,7 +458,7 @@ bool Sprite::SeqTest(int n) { } -SNAIL::COM *Sprite::SnList(SNLIST type) { +SNAIL::COM *Sprite::snList(SNLIST type) { register SprExt *e = _ext; if (e) return (type == NEAR) ? e->_near : e->_take; @@ -466,7 +466,7 @@ SNAIL::COM *Sprite::SnList(SNLIST type) { } -void Sprite::SetName(char *n) { +void Sprite::setName(char *n) { if (_ext) { if (_ext->_name) { delete[] _ext->_name; @@ -482,13 +482,13 @@ void Sprite::SetName(char *n) { } -Sprite *Sprite::Expand(void) { +Sprite *Sprite::expand() { if (!_ext) { bool enbl = _heart->_enable; _heart->_enable = false; if ((_ext = new SprExt) == NULL) error("No core"); - if (*File) { + if (*_file) { static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; char line[LINE_MAX], fname[MAXPATH]; BMP_PTR *shplist = new BMP_PTR [_shpCnt + 1]; @@ -502,7 +502,7 @@ Sprite *Sprite::Expand(void) { SNAIL::COM *nea = NULL; SNAIL::COM *tak = NULL; - MergeExt(fname, File, SPR_EXT); + mergeExt(fname, _file, SPR_EXT); if (INI_FILE::exist(fname)) { // sprite description file exist INI_FILE sprf(fname); if (!(sprf._error==0)) @@ -515,9 +515,9 @@ Sprite *Sprite::Expand(void) { if (len == 0 || *line == '.') continue; - switch (TakeEnum(Comd, strtok(line, " =\t"))) { + switch (takeEnum(Comd, strtok(line, " =\t"))) { case 0 : { // Name - SetName(strtok(NULL, "")); + setName(strtok(NULL, "")); break; } case 1 : { // Phase @@ -549,13 +549,13 @@ Sprite *Sprite::Expand(void) { break; } case 3 : { // Near - if (NearPtr != NO_PTR) { + if (_nearPtr != NO_PTR) { nea = (SNAIL::COM *) realloc(nea, (neacnt + 1) * sizeof(*nea)); if (nea == NULL) error("No core [%s]", fname); else { SNAIL::COM *c = &nea[neacnt++]; - if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) + if ((c->Com = (SNCOM) takeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) error("%s [%s]", (const char*)NumStr("Bad NEAR in ######", lcnt), (const char*)fname); c->Ref = atoi(strtok(NULL, " \t,;/")); c->Val = atoi(strtok(NULL, " \t,;/")); @@ -565,13 +565,13 @@ Sprite *Sprite::Expand(void) { } break; case 4 : { // Take - if (TakePtr != NO_PTR) { + if (_takePtr != NO_PTR) { tak = (SNAIL::COM *) realloc(tak, (takcnt + 1) * sizeof(*tak)); if (tak == NULL) error("No core [%s]", fname); else { SNAIL::COM *c = &tak[takcnt++]; - if ((c->Com = (SNCOM) TakeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) + if ((c->Com = (SNCOM) takeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), (const char *)fname); c->Ref = atoi(strtok(NULL, " \t,;/")); c->Val = atoi(strtok(NULL, " \t,;/")); @@ -583,7 +583,7 @@ Sprite *Sprite::Expand(void) { } } } else { // no sprite description: try to read immediately from .BMP - shplist[shpcnt++] = new Bitmap(File, true); + shplist[shpcnt++] = new Bitmap(_file, true); } shplist[shpcnt] = NULL; if (seq) { @@ -591,21 +591,21 @@ Sprite *Sprite::Expand(void) { error("Bad PHASE in SEQ [%s]", fname); if (maxnxt >= seqcnt) error("Bad JUMP in SEQ [%s]", fname); - SetSeq(seq); + setSeq(seq); } else - SetSeq((_shpCnt == 1) ? _seq1 : _seq2); + setSeq((_shpCnt == 1) ? _seq1 : _seq2); //disable(); // disable interupt - SetShapeList(shplist); + setShapeList(shplist); //enable(); // enable interupt if (nea) nea[neacnt - 1].Ptr = _ext->_near = nea; else - NearPtr = NO_PTR; + _nearPtr = NO_PTR; if (tak) tak[takcnt - 1].Ptr = _ext->_take = tak; else - TakePtr = NO_PTR; + _takePtr = NO_PTR; } _heart->_enable = enbl; } @@ -613,7 +613,7 @@ Sprite *Sprite::Expand(void) { } -Sprite *Sprite::Contract(void) { +Sprite *Sprite::contract() { register SprExt *e = _ext; if (e) { if (e->_name) @@ -622,10 +622,10 @@ Sprite *Sprite::Contract(void) { int i; for (i = 0; e->_shpList[i]; i++) delete e->_shpList[i]; - if (MemType(e->_shpList) == NEAR_MEM) + if (memType(e->_shpList) == NEAR_MEM) delete[] e->_shpList; } - if (MemType(e->_seq) == NEAR_MEM) + if (memType(e->_seq) == NEAR_MEM) free(e->_seq); if (e->_near) free(e->_near); @@ -638,18 +638,18 @@ Sprite *Sprite::Contract(void) { } -Sprite *Sprite::BackShow(bool fast) { - Expand(); - Show(2); - Show(1); +Sprite *Sprite::backShow(bool fast) { + expand(); + show(2); + show(1); if (fast) - Show(0); - Contract(); + show(0); + contract(); return this; } -void Sprite::Step(int nr) { +void Sprite::step(int nr) { if (nr >= 0) _seqPtr = nr; if (_ext) { @@ -658,24 +658,24 @@ void Sprite::Step(int nr) { _seqPtr = _ext->_seq[_seqPtr].Next; seq = _ext->_seq + _seqPtr; if (seq->Dly >= 0) { - Goto(_x + (seq->Dx), _y + (seq->Dy)); + gotoxy(_x + (seq->Dx), _y + (seq->Dy)); _time = seq->Dly; } } } -void Sprite::Tick(void) { - Step(); +void Sprite::tick() { + step(); } -void Sprite::MakeXlat(uint8 *x) { +void Sprite::makeXlat(uint8 *x) { if (_ext) { BMP_PTR *b; if (_flags._xlat) - KillXlat(); + killXlat(); for (b = _ext->_shpList; *b; b++) (*b)->_m = x; _flags._xlat = true; @@ -683,12 +683,12 @@ void Sprite::MakeXlat(uint8 *x) { } -void Sprite::KillXlat(void) { +void Sprite::killXlat() { if (_flags._xlat && _ext) { BMP_PTR *b; uint8 *m = (*_ext->_shpList)->_m; - switch (MemType(m)) { + switch (memType(m)) { case NEAR_MEM : delete[](uint8 *) m; break; @@ -706,7 +706,7 @@ void Sprite::KillXlat(void) { } -void Sprite::Goto(int x, int y) { +void Sprite::gotoxy(int x, int y) { int xo = _x, yo = _y; if (_x < SCR_WID) { if (x < 0) @@ -724,18 +724,18 @@ void Sprite::Goto(int x, int y) { } if (_next) if (_next->_flags._slav) - _next->Goto(_next->_x - xo + _x, _next->_y - yo + _y); + _next->gotoxy(_next->_x - xo + _x, _next->_y - yo + _y); if (_flags._shad) - _prev->Goto(_prev->_x - xo + _x, _prev->_y - yo + _y); + _prev->gotoxy(_prev->_x - xo + _x, _prev->_y - yo + _y); } -void Sprite::Center(void) { - Goto((SCR_WID - _w) / 2, (SCR_HIG - _h) / 2); +void Sprite::center() { + gotoxy((SCR_WID - _w) / 2, (SCR_HIG - _h) / 2); } -void Sprite::Show(void) { +void Sprite::show() { register SprExt *e; // asm cli // critic section... e = _ext; @@ -744,7 +744,7 @@ void Sprite::Show(void) { e->_b0 = e->_b1; e->_x1 = _x; e->_y1 = _y; - e->_b1 = Shp(); + e->_b1 = shp(); // asm sti // ...done! if (!_flags._hide) { if (_flags._xlat) @@ -755,22 +755,22 @@ void Sprite::Show(void) { } -void Sprite::Show(uint16 pg) { +void Sprite::show(uint16 pg) { Graphics::Surface *a = VGA::Page[1]; VGA::Page[1] = VGA::Page[pg & 3]; - Shp()->show(_x, _y); + shp()->show(_x, _y); VGA::Page[1] = a; } -void Sprite::Hide(void) { +void Sprite::hide() { register SprExt *e = _ext; if (e->_b0) e->_b0->hide(e->_x0, e->_y0); } -BMP_PTR Sprite::Ghost(void) { +BMP_PTR Sprite::ghost() { register SprExt *e = _ext; if (e->_b1) { BMP_PTR bmp = new Bitmap(0, 0, (uint8 *)NULL); @@ -795,7 +795,7 @@ Sprite *SpriteAt(int x, int y) { if (tail) { for (spr = tail->_prev; spr; spr = spr->_prev) { if (! spr->_flags._hide && ! spr->_flags._tran) { - if (spr->Shp()->solidAt(x - spr->_x, y - spr->_y)) + if (spr->shp()->solidAt(x - spr->_x, y - spr->_y)) break; } } @@ -840,9 +840,9 @@ void QUEUE::Append(Sprite *spr) { Head = spr; Tail = spr; if (Show) - spr->Expand(); + spr->expand(); else - spr->Contract(); + spr->contract(); } @@ -861,9 +861,9 @@ void QUEUE::Insert(Sprite *spr, Sprite *nxt) { if (spr->_next) spr->_next->_prev = spr; if (Show) - spr->Expand(); + spr->expand(); else - spr->Contract(); + spr->contract(); } @@ -877,9 +877,9 @@ void QUEUE::Insert(Sprite *spr) { else Append(spr); if (Show) - spr->Expand(); + spr->expand(); else - spr->Contract(); + spr->contract(); } @@ -952,7 +952,7 @@ VGA::VGA(int mode) SetStatAdr(); if (StatAdr != VGAST1_) ++Mono; - if (IsVga()) { + if (isVga()) { OldColors = farnew(Dac, 256); NewColors = farnew(Dac, 256); OldScreen = SaveScreen(); @@ -968,7 +968,7 @@ VGA::VGA(int mode) VGA::~VGA(void) { Mono = 0; - if (IsVga()) { + if (isVga()) { Common::String buffer = ""; Clear(0); SetMode(OldMode); @@ -1137,10 +1137,10 @@ void VGA::Show(void) { Sprite *spr = ShowQ->First(); for (spr = ShowQ->First(); spr; spr = spr->_next) - spr->Show(); + spr->show(); Update(); for (spr = ShowQ->First(); spr; spr = spr->_next) - spr->Hide(); + spr->hide(); ++ FrmCnt; } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index a3d5ad949b0..a22dd9d57af 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -195,42 +195,43 @@ public: uint16 _w; uint16 _h; uint16 _time; - uint8 NearPtr, TakePtr; + uint8 _nearPtr; + uint8 _takePtr; int _seqPtr; int _shpCnt; - char File[MAXFILE]; + char _file[MAXFILE]; Sprite *_prev; Sprite *_next; - bool Works(Sprite *spr); - bool SeqTest(int n); - inline bool Active(void) { + bool works(Sprite *spr); + bool seqTest(int n); + inline bool active() { return _ext != NULL; } Sprite(CGEEngine *vm, BMP_PTR *shp); virtual ~Sprite(void); - BMP_PTR Shp(void); - BMP_PTR *SetShapeList(BMP_PTR *shp); - void MoveShapes(uint8 *buf); - Sprite *Expand(void); - Sprite *Contract(void); - Sprite *BackShow(bool fast = false); - void SetName(char *n); - inline char *Name(void) { + BMP_PTR shp(); + BMP_PTR *setShapeList(BMP_PTR *shp); + void moveShapes(uint8 *buf); + Sprite *expand(); + Sprite *contract(); + Sprite *backShow(bool fast = false); + void setName(char *n); + inline char *name() { return (_ext) ? _ext->_name : NULL; } - void Goto(int x, int y); - void Center(void); - void Show(void); - void Hide(void); - BMP_PTR Ghost(void); - void Show(uint16 pg); - void MakeXlat(uint8 *x); - void KillXlat(void); - void Step(int nr = -1); - Seq *SetSeq(Seq *seq); - SNAIL::COM *SnList(SNLIST type); - virtual void Touch(uint16 mask, int x, int y); - virtual void Tick(void); + void gotoxy(int x, int y); + void center(); + void show(); + void hide(); + BMP_PTR ghost(); + void show(uint16 pg); + void makeXlat(uint8 *x); + void killXlat(); + void step(int nr = -1); + Seq *setSeq(Seq *seq); + SNAIL::COM *snList(SNLIST type); + virtual void touch(uint16 mask, int x, int y); + virtual void tick(); private: CGEEngine *_vm; }; @@ -291,9 +292,9 @@ public: void Clear(uint8 color); void CopyPage(uint16 d, uint16 s); void Sunrise(Dac *tab); - void Sunset(void); - void Show(void); - void Update(void); + void Sunset(); + void Show(); + void Update(); static void pal2DAC(const byte *palData, Dac *tab); static void DAC2pal(const Dac *tab, byte *palData); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index ed07a1269fa..7e1d327b69f 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -61,7 +61,7 @@ MENU_BAR::MENU_BAR(CGEEngine *vm, uint16 w) : TALK(vm), _vm(vm) { p2 -= w; } TS[0] = new Bitmap(w, h, p); - SetShapeList(TS); + setShapeList(TS); _flags._slav = true; _flags._tran = true; _flags._kill = true; @@ -110,12 +110,12 @@ VMENU::VMENU(CGEEngine *vm, CHOICE *list, int x, int y) _flags._bDel = true; _flags._kill = true; if (x < 0 || y < 0) - Center(); + center(); else - Goto(x - _w / 2, y - (TEXT_VM + FONT_HIG / 2)); + gotoxy(x - _w / 2, y - (TEXT_VM + FONT_HIG / 2)); Vga->ShowQ->Insert(this, Vga->ShowQ->Last()); Bar = new MENU_BAR(_vm, _w - 2 * TEXT_HM); - Bar->Goto(_x + TEXT_HM - MB_HM, _y + TEXT_VM - MB_VM); + Bar->gotoxy(_x + TEXT_HM - MB_HM, _y + TEXT_VM - MB_VM); Vga->ShowQ->Insert(Bar, Vga->ShowQ->Last()); } @@ -130,7 +130,7 @@ void VMENU::Touch(uint16 mask, int x, int y) { bool ok = false; if (Items) { - Sprite::Touch(mask, x, y); + Sprite::touch(mask, x, y); y -= TEXT_VM - 1; int n = 0; @@ -142,7 +142,7 @@ void VMENU::Touch(uint16 mask, int x, int y) { n = Items - 1; } - Bar->Goto(_x + TEXT_HM - MB_HM, _y + TEXT_VM + n * h - MB_VM); + Bar->gotoxy(_x + TEXT_HM - MB_HM, _y + TEXT_VM + n * h - MB_VM); if (ok && (mask & L_UP)) { Items = 0; From 3469d1fb04d84840bb720c472b79f738b72a08e8 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 1 Jul 2011 20:09:36 +1000 Subject: [PATCH 051/276] CGE: Bugfix to correctly reset wait timeouts when done --- engines/cge/snail.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index baaac250dd5..54b786722fd 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -913,9 +913,15 @@ void SNAIL::RunCom(void) { COM *snc = &SNList[Tail]; if (! Turbo) { // only for the slower one - if (_timerExpiry && (_timerExpiry > g_system->getMillis())) - break; - else { + if (_timerExpiry) { + // Delay in progress + if (_timerExpiry > g_system->getMillis()) + // Delay not yet ended + break; + + // Delay is finished + _timerExpiry = 0; + } else { if (TextDelay) { KillText(); TextDelay = false; From 1ab67c2124d178cf38aae82af49f6babcd4dd2cd Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Jul 2011 16:04:47 +1000 Subject: [PATCH 052/276] CGE: Fix problem with calculating box sizes for text strings --- engines/cge/talk.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 38625e2971d..ce6490cccfa 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -80,7 +80,7 @@ uint16 FONT::Width(const char *text) { uint16 w = 0; if (text) while (* text) - w += Wid[*(text++)]; + w += Wid[(unsigned char)*(text++)]; return w; } @@ -151,7 +151,7 @@ void TALK::Update(const char *tx) { mw = k; k = 2 * hmarg; } else - k += _Font->Wid[*p]; + k += _Font->Wid[(unsigned char)*p]; } if (k > mw) mw = k; @@ -164,8 +164,8 @@ void TALK::Update(const char *tx) { if (*tx == '|' || *tx == '\n') m = TS[0]->_m + (ln += FONT_HIG + TEXT_LS) * mw + hmarg; else { - int cw = _Font->Wid[*tx], i; - uint8 *f = _Font->Map + _Font->Pos[*tx]; + int cw = _Font->Wid[(unsigned char)*tx], i; + uint8 *f = _Font->Map + _Font->Pos[(unsigned char)*tx]; for (i = 0; i < cw; i++) { uint8 *pp = m; uint16 n; @@ -262,8 +262,8 @@ void TALK::PutLine(int line, const char *text) { q = v + size; while (* text) { - uint16 cw = _Font->Wid[*text], i; - uint8 *fp = _Font->Map + _Font->Pos[*text]; + uint16 cw = _Font->Wid[(unsigned char)*text], i; + uint8 *fp = _Font->Map + _Font->Pos[(unsigned char)*text]; for (i = 0; i < cw; i++) { register uint16 b = fp[i]; @@ -310,8 +310,8 @@ void INFO_LINE::Update(const char *tx) { uint8 *p = v + 2, * q = p + size; while (*tx) { - uint16 cw = _Font->Wid[*tx]; - uint8 *fp = _Font->Map + _Font->Pos[*tx]; + uint16 cw = _Font->Wid[(unsigned char)*tx]; + uint8 *fp = _Font->Map + _Font->Pos[(unsigned char)*tx]; for (uint16 i = 0; i < cw; i++) { register uint16 b = fp[i]; From ec28ef04c467d45703296a610f7ef0e30154164d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Jul 2011 16:19:36 +1000 Subject: [PATCH 053/276] CGE: Merged mouse.* and keybd.* files to centralise event handling --- engines/cge/cge_main.cpp | 5 +- engines/cge/cge_main.h | 2 +- engines/cge/{keybd.cpp => events.cpp} | 171 ++++++++++++++++++++++- engines/cge/{mouse.h => events.h} | 35 ++++- engines/cge/gettext.cpp | 3 +- engines/cge/keybd.h | 63 --------- engines/cge/mixer.cpp | 2 +- engines/cge/module.mk | 3 +- engines/cge/mouse.cpp | 194 -------------------------- engines/cge/snail.cpp | 3 +- engines/cge/vmenu.cpp | 2 +- 11 files changed, 211 insertions(+), 272 deletions(-) rename engines/cge/{keybd.cpp => events.cpp} (57%) rename engines/cge/{mouse.h => events.h} (74%) delete mode 100644 engines/cge/keybd.h delete mode 100644 engines/cge/mouse.cpp diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 0d8bef4b856..40bace9c513 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -36,8 +36,7 @@ #include "cge/snail.h" #include "cge/text.h" #include "cge/game.h" -#include "cge/mouse.h" -#include "cge/keybd.h" +#include "cge/events.h" #include "cge/cfile.h" #include "cge/vol.h" #include "cge/talk.h" @@ -1857,8 +1856,10 @@ void CGEEngine::cge_main(void) { if (Music && STARTUP::SoundOk) LoadMIDI(0); +/** *****DEBUG***** if (STARTUP::Mode < 2) movie(LGO_EXT); +*/ if (showTitle("WELCOME")) { if ((!_isDemo) && (STARTUP::Mode == 1)) movie("X02"); // intro diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 9b905ea360c..1b77c05bf07 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -30,7 +30,7 @@ #include "cge/wav.h" #include "cge/vga13h.h" -#include "cge/mouse.h" +#include "cge/events.h" namespace CGE { diff --git a/engines/cge/keybd.cpp b/engines/cge/events.cpp similarity index 57% rename from engines/cge/keybd.cpp rename to engines/cge/events.cpp index 45237d15d1a..e5ad00da5e4 100644 --- a/engines/cge/keybd.cpp +++ b/engines/cge/events.cpp @@ -25,11 +25,15 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/keybd.h" -#include "cge/mouse.h" +#include "cge/events.h" +#include "cge/events.h" +#include "cge/text.h" +#include "cge/cge_main.h" namespace CGE { +/*----------------- KEYBOARD interface -----------------*/ + Sprite *Keyboard::_client = NULL; uint8 Keyboard::_key[0x60] = { 0 }; uint16 Keyboard::_current = 0; @@ -148,4 +152,167 @@ void Keyboard::NewKeyboard(...) { warning("STUB: Keyboard::NewKeyboard"); } +/*----------------- MOUSE interface -----------------*/ + +Event Evt[EVT_MAX]; + +uint16 EvtHead = 0, EvtTail = 0; + +MOUSE_FUN *MOUSE::OldMouseFun = NULL; +uint16 MOUSE::OldMouseMask = 0; + + +MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold(NULL), hx(0), _vm(vm) { + static Seq ms[] = { + { 0, 0, 0, 0, 1 }, + { 1, 1, 0, 0, 1 } + }; + + setSeq(ms); + + /* TODO Mouse handling + // Mouse reset + _AX = 0x0000; // soft & hard reset (0x0021 soft reset does not work) + __int__(0x33); + Exist = (_AX != 0); + Buttons = _BX; +*/ + gotoxy(SCR_WID/2, SCR_HIG/2); + _z = 127; + step(1); + + Exist = true; + warning("STUB: MOUSE::MOUSE"); +} + + +MOUSE::~MOUSE(void) { + Off(); +} + + +//void MOUSE::SetFun (void) +//{ +//} + + +void MOUSE::On(void) { + /* + if (SeqPtr && Exist) + { + _CX = X + X; // horizontal position + _DX = Y; // vertical position + _AX = 0x0004; // Set Mouse Position + __int__(0x33); + // set new mouse fun + _ES = FP_SEG(NewMouseFun); + _DX = FP_OFF(NewMouseFun); + _CX = 0x001F; // 11111b = all events + _AX = 0x0014; // Swap User-Interrupt Vector + __int__(0x33); + // save old mouse fun + OldMouseMask = _CX; + OldMouseFun = (MOUSE_FUN *) MK_FP(_ES, _DX); + + // set X bounds + _DX = (SCR_WID - W) * 2; // right limit + _CX = 0; // left limit + _AX = 0x0007; // note: each pixel = 2 + __int__(0x33); + + // set Y bounds + _DX = SCR_HIG - H; // bottom limit + _CX = 0; // top limit + _AX = 0x0008; + __int__(0x33); + + Step(0); + if (Busy) Busy->Step(0); + } + */ + warning("STUB: MOUSE::On"); +} + + +void MOUSE::Off(void) { +/* + if (SeqPtr == 0) + { + if (Exist) + { + // bring back old mouse fun + _ES = FP_SEG(OldMouseFun); + _DX = FP_OFF(OldMouseFun); + _CX = OldMouseMask; + _AX = 0x0014; // Swap User-Interrupt Vector + __int__(0x33); + } + Step(1); + if (Busy) Busy->Step(1); + } + */ + warning("STUB: MOUSE::Off"); +} + + +void MOUSE::ClrEvt(Sprite *spr) { + if (spr) { + uint16 e; + for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) + if (Evt[e]._ptr == spr) + Evt[e]._msk = 0; + } else + EvtTail = EvtHead; +} + + +void MOUSE::Tick(void) { + step(); + while (EvtTail != EvtHead) { + Event e = Evt[EvtTail]; + if (e._msk) { + if (Hold && e._ptr != Hold) + Hold->touch(e._msk | ATTN, e._x - Hold->_x, e._y - Hold->_y); + + // update mouse cursor position + if (e._msk & ROLL) + gotoxy(e._x, e._y); + + // activate current touched SPRITE + if (e._ptr) { + if (e._msk & KEYB) + e._ptr->touch(e._msk, e._x, e._y); + else + e._ptr->touch(e._msk, e._x - e._ptr->_x, e._y - e._ptr->_y); + } else if (Sys) + Sys->touch(e._msk, e._x, e._y); + + if (e._msk & L_DN) { + Hold = e._ptr; + if (Hold) { + Hold->_flags._hold = true; + hx = e._x - Hold->_x; + hy = e._y - Hold->_y; + } + } + + if (e._msk & L_UP) { + if (Hold) { + Hold->_flags._hold = false; + Hold = NULL; + } + } + ///Touched = e.Ptr; + + // discard Text if button released + if (e._msk & (L_UP | R_UP)) + KillText(); + } + EvtTail = (EvtTail + 1) % EVT_MAX; + } + if (Hold) + Hold->gotoxy(_x - hx, _y - hy); +} + + } // End of namespace CGE diff --git a/engines/cge/mouse.h b/engines/cge/events.h similarity index 74% rename from engines/cge/mouse.h rename to engines/cge/events.h index 4d95f104236..be4b15e133e 100644 --- a/engines/cge/mouse.h +++ b/engines/cge/events.h @@ -25,14 +25,45 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __MOUSE__ -#define __MOUSE__ +#ifndef __CGE_EVENTS__ +#define __CGE_EVENTS__ #include "cge/game.h" #include "cge/talk.h" +#include "cge/jbw.h" +#include "cge/vga13h.h" namespace CGE { +/*----------------- KEYBOARD interface -----------------*/ + +#define KEYBD_INT 9 +#define LSHIFT 42 +#define RSHIFT 54 +#define CTRL 29 +#define ALT 56 + + +class Keyboard { +public: + static void (* OldKeyboard)(...); + static void NewKeyboard(...); + static uint16 _code[0x60]; + static uint16 _current; + static Sprite *_client; + static uint8 _key[0x60]; + static uint16 last() { + uint16 cur = _current; + _current = 0; + return cur; + } + static Sprite *setClient(Sprite *spr); + Keyboard(); + ~Keyboard(); +}; + +/*----------------- MOUSE interface -----------------*/ + #define EVT_MAX 256 #define ROLL 0x01 #define L_DN 0x02 diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 1b609e2d8bf..889aee4feda 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -26,8 +26,7 @@ */ #include "cge/gettext.h" -#include "cge/keybd.h" -#include "cge/mouse.h" +#include "cge/events.h" #include "cge/cge_main.h" #include diff --git a/engines/cge/keybd.h b/engines/cge/keybd.h deleted file mode 100644 index bb87ffb0edf..00000000000 --- a/engines/cge/keybd.h +++ /dev/null @@ -1,63 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __KEYBD__ -#define __KEYBD__ - -#include "cge/jbw.h" -#include "cge/vga13h.h" - -namespace CGE { - -#define KEYBD_INT 9 -#define LSHIFT 42 -#define RSHIFT 54 -#define CTRL 29 -#define ALT 56 - - -class Keyboard { -public: - static void (* OldKeyboard)(...); - static void NewKeyboard(...); - static uint16 _code[0x60]; - static uint16 _current; - static Sprite *_client; - static uint8 _key[0x60]; - static uint16 last() { - uint16 cur = _current; - _current = 0; - return cur; - } - static Sprite *setClient(Sprite *spr); - Keyboard(); - ~Keyboard(); -}; - -} // End of namespace CGE - -#endif diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index b6442f3cd3b..f8c0b9ceabc 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -28,7 +28,7 @@ #include "cge/mixer.h" #include "cge/text.h" #include "cge/snail.h" -#include "cge/mouse.h" +#include "cge/events.h" #include "cge/snddrv.h" #include "cge/cge_main.h" #include diff --git a/engines/cge/module.mk b/engines/cge/module.mk index 70967667a5b..d9dea6534d7 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -11,12 +11,11 @@ MODULE_OBJS := \ console.o \ detection.o \ ems.o \ + events.o \ game.o \ general.o \ gettext.o \ - keybd.o \ mixer.o \ - mouse.o \ snail.o \ sound.o \ startup.o \ diff --git a/engines/cge/mouse.cpp b/engines/cge/mouse.cpp deleted file mode 100644 index a1b6b253ced..00000000000 --- a/engines/cge/mouse.cpp +++ /dev/null @@ -1,194 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/mouse.h" -#include "cge/text.h" -#include "cge/cge_main.h" - -namespace CGE { - -Event Evt[EVT_MAX]; - -uint16 EvtHead = 0, EvtTail = 0; - -MOUSE_FUN *MOUSE::OldMouseFun = NULL; -uint16 MOUSE::OldMouseMask = 0; - - -MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold(NULL), hx(0), _vm(vm) { - static Seq ms[] = { - { 0, 0, 0, 0, 1 }, - { 1, 1, 0, 0, 1 } - }; - - setSeq(ms); - - /* TODO Mouse handling - // Mouse reset - _AX = 0x0000; // soft & hard reset (0x0021 soft reset does not work) - __int__(0x33); - Exist = (_AX != 0); - Buttons = _BX; -*/ - gotoxy(SCR_WID/2, SCR_HIG/2); - _z = 127; - step(1); - - Exist = true; - warning("STUB: MOUSE::MOUSE"); -} - - -MOUSE::~MOUSE(void) { - Off(); -} - - -//void MOUSE::SetFun (void) -//{ -//} - - -void MOUSE::On(void) { - /* - if (SeqPtr && Exist) - { - _CX = X + X; // horizontal position - _DX = Y; // vertical position - _AX = 0x0004; // Set Mouse Position - __int__(0x33); - // set new mouse fun - _ES = FP_SEG(NewMouseFun); - _DX = FP_OFF(NewMouseFun); - _CX = 0x001F; // 11111b = all events - _AX = 0x0014; // Swap User-Interrupt Vector - __int__(0x33); - // save old mouse fun - OldMouseMask = _CX; - OldMouseFun = (MOUSE_FUN *) MK_FP(_ES, _DX); - - // set X bounds - _DX = (SCR_WID - W) * 2; // right limit - _CX = 0; // left limit - _AX = 0x0007; // note: each pixel = 2 - __int__(0x33); - - // set Y bounds - _DX = SCR_HIG - H; // bottom limit - _CX = 0; // top limit - _AX = 0x0008; - __int__(0x33); - - Step(0); - if (Busy) Busy->Step(0); - } - */ - warning("STUB: MOUSE::On"); -} - - -void MOUSE::Off(void) { -/* - if (SeqPtr == 0) - { - if (Exist) - { - // bring back old mouse fun - _ES = FP_SEG(OldMouseFun); - _DX = FP_OFF(OldMouseFun); - _CX = OldMouseMask; - _AX = 0x0014; // Swap User-Interrupt Vector - __int__(0x33); - } - Step(1); - if (Busy) Busy->Step(1); - } - */ - warning("STUB: MOUSE::Off"); -} - - -void MOUSE::ClrEvt(Sprite *spr) { - if (spr) { - uint16 e; - for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) - if (Evt[e]._ptr == spr) - Evt[e]._msk = 0; - } else - EvtTail = EvtHead; -} - - -void MOUSE::Tick(void) { - step(); - while (EvtTail != EvtHead) { - Event e = Evt[EvtTail]; - if (e._msk) { - if (Hold && e._ptr != Hold) - Hold->touch(e._msk | ATTN, e._x - Hold->_x, e._y - Hold->_y); - - // update mouse cursor position - if (e._msk & ROLL) - gotoxy(e._x, e._y); - - // activate current touched SPRITE - if (e._ptr) { - if (e._msk & KEYB) - e._ptr->touch(e._msk, e._x, e._y); - else - e._ptr->touch(e._msk, e._x - e._ptr->_x, e._y - e._ptr->_y); - } else if (Sys) - Sys->touch(e._msk, e._x, e._y); - - if (e._msk & L_DN) { - Hold = e._ptr; - if (Hold) { - Hold->_flags._hold = true; - hx = e._x - Hold->_x; - hy = e._y - Hold->_y; - } - } - - if (e._msk & L_UP) { - if (Hold) { - Hold->_flags._hold = false; - Hold = NULL; - } - } - ///Touched = e.Ptr; - - // discard Text if button released - if (e._msk & (L_UP | R_UP)) - KillText(); - } - EvtTail = (EvtTail + 1) % EVT_MAX; - } - if (Hold) - Hold->gotoxy(_x - hx, _y - hy); -} - -} // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 54b786722fd..217acb24488 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -31,11 +31,10 @@ #include "cge/vga13h.h" #include "cge/bitmaps.h" #include "cge/text.h" -#include "cge/mouse.h" #include "cge/cge_main.h" #include #include -#include "cge/keybd.h" +#include "cge/events.h" namespace CGE { diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 7e1d327b69f..149af901e81 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -26,7 +26,7 @@ */ #include "cge/vmenu.h" -#include "cge/mouse.h" +#include "cge/events.h" #include "cge/cge_main.h" #include From 6833daab84a39a3d5dd0afcb176245f8678b28de Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Jul 2011 16:23:32 +1000 Subject: [PATCH 054/276] CGE: Added engine prefix to header file #defines --- engines/cge/bitmap.h | 4 ++-- engines/cge/bitmaps.h | 4 ++-- engines/cge/boot.h | 4 ++-- engines/cge/btfile.h | 4 ++-- engines/cge/cfile.h | 4 ++-- engines/cge/cge_main.h | 4 ++-- engines/cge/config.h | 4 ++-- engines/cge/events.h | 4 ++-- engines/cge/game.cpp | 2 +- engines/cge/game.h | 4 ++-- engines/cge/general.h | 4 ++-- engines/cge/gettext.h | 4 ++-- engines/cge/ident.h | 4 ++-- engines/cge/jbw.h | 4 ++-- engines/cge/mixer.h | 4 ++-- engines/cge/snail.h | 4 ++-- engines/cge/snddrv.h | 4 ++-- engines/cge/sound.h | 4 ++-- engines/cge/startup.h | 4 ++-- engines/cge/talk.cpp | 2 +- engines/cge/talk.h | 4 ++-- engines/cge/text.h | 4 ++-- engines/cge/vga13h.h | 4 ++-- engines/cge/vmenu.h | 4 ++-- engines/cge/vol.h | 4 ++-- engines/cge/wav.h | 4 ++-- 26 files changed, 50 insertions(+), 50 deletions(-) diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 846f0149be6..4c2b67b8dfd 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __BITMAP__ -#define __BITMAP__ +#ifndef __CGE_BITMAP__ +#define __CGE_BITMAP__ #include "cge/general.h" diff --git a/engines/cge/bitmaps.h b/engines/cge/bitmaps.h index 40b1158b21e..85699321348 100644 --- a/engines/cge/bitmaps.h +++ b/engines/cge/bitmaps.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __BITMAPS__ -#define __BITMAPS__ +#ifndef __CGE_BITMAPS__ +#define __CGE_BITMAPS__ #include "cge/vga13h.h" diff --git a/engines/cge/boot.h b/engines/cge/boot.h index 2dce0d6d160..5c03a626d82 100644 --- a/engines/cge/boot.h +++ b/engines/cge/boot.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __BOOT__ -#define __BOOT__ +#ifndef __CGE_BOOT__ +#define __CGE_BOOT__ #include "cge/jbw.h" diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index ac05c3a7e78..1ac093d897b 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __BTFILE__ -#define __BTFILE__ +#ifndef __CGE_BTFILE__ +#define __CGE_BTFILE__ #include "cge/general.h" diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index 376e50ae449..bf90633dd08 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CFILE__ -#define __CFILE__ +#ifndef __CGE_CFILE__ +#define __CGE_CFILE__ #include "cge/general.h" diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 1b77c05bf07..37d1a91e001 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE__ -#define __CGE__ +#ifndef __CGE_CGE__ +#define __CGE_CGE__ #include "cge/wav.h" #include "cge/vga13h.h" diff --git a/engines/cge/config.h b/engines/cge/config.h index 0f279ab0477..4a1e5927e51 100644 --- a/engines/cge/config.h +++ b/engines/cge/config.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CONFIG__ -#define __CONFIG__ +#ifndef __CGE_CONFIG__ +#define __CGE_CONFIG__ namespace CGE { diff --git a/engines/cge/events.h b/engines/cge/events.h index be4b15e133e..518c8c8bd16 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_EVENTS__ -#define __CGE_EVENTS__ +#ifndef __CGE_CGE_EVENTS__ +#define __CGE_CGE_EVENTS__ #include "cge/game.h" #include "cge/talk.h" diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index be93709f178..72233f746a4 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -26,7 +26,7 @@ */ #include "cge/game.h" -#include "cge/mouse.h" +#include "cge/events.h" #include namespace CGE { diff --git a/engines/cge/game.h b/engines/cge/game.h index 3f86c970818..b26fc0d1652 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __GAME__ -#define __GAME__ +#ifndef __CGE_GAME__ +#define __CGE_GAME__ #include "cge/vga13h.h" #include "cge/bitmaps.h" diff --git a/engines/cge/general.h b/engines/cge/general.h index cff00fb7f35..fae47eed42d 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __GENERAL__ -#define __GENERAL__ +#ifndef __CGE_GENERAL__ +#define __CGE_GENERAL__ #include "common/system.h" #include "common/file.h" diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h index 059d84be410..f743d0c66cc 100644 --- a/engines/cge/gettext.h +++ b/engines/cge/gettext.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __GETTEXT__ -#define __GETTEXT__ +#ifndef __CGE_GETTEXT__ +#define __CGE_GETTEXT__ #include "cge/general.h" #include "cge/talk.h" diff --git a/engines/cge/ident.h b/engines/cge/ident.h index afdb86d785a..953f8a579d3 100644 --- a/engines/cge/ident.h +++ b/engines/cge/ident.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __IDENT__ -#define __IDENT__ +#ifndef __CGE_IDENT__ +#define __CGE_IDENT__ namespace CGE { diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 359df8a2161..93cdb75a4be 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __JBW__ -#define __JBW__ +#ifndef __CGE_JBW__ +#define __CGE_JBW__ #include "common/scummsys.h" diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index a86e65d3d18..8ded075514a 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __MIXER__ -#define __MIXER__ +#ifndef __CGE_MIXER__ +#define __CGE_MIXER__ #include "cge/vga13h.h" diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 3221f5c02e6..54a24ac1a9f 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __SNAIL__ -#define __SNAIL__ +#ifndef __CGE_SNAIL__ +#define __CGE_SNAIL__ #include "cge/jbw.h" #include "cge/cge.h" diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 2de90140340..4cdac383bef 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -34,8 +34,8 @@ // * Ver 1.40: 11-Mar-95 * // ****************************************************** -#ifndef __SNDDRV__ -#define __SNDDRV__ +#ifndef __CGE_SNDDRV__ +#define __CGE_SNDDRV__ namespace CGE { diff --git a/engines/cge/sound.h b/engines/cge/sound.h index b617891268d..743fba0bb69 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __SOUND__ -#define __SOUND__ +#ifndef __CGE_SOUND__ +#define __CGE_SOUND__ #include "cge/wav.h" #include "cge/snddrv.h" diff --git a/engines/cge/startup.h b/engines/cge/startup.h index 5bfa9876d67..a1e44cc4af7 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __STARTUP__ -#define __STARTUP__ +#ifndef __CGE_STARTUP__ +#define __CGE_STARTUP__ #include "cge/general.h" diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index ce6490cccfa..0abff7752c3 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -29,7 +29,7 @@ #include "cge/talk.h" #include "cge/vol.h" #include "cge/game.h" -#include "cge/mouse.h" +#include "cge/events.h" namespace CGE { diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 60f7f213d47..e5e32998cb3 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __TALK__ -#define __TALK__ +#ifndef __CGE_TALK__ +#define __CGE_TALK__ #include "cge/vga13h.h" #include "cge/general.h" diff --git a/engines/cge/text.h b/engines/cge/text.h index 874a640ad03..5232084738f 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __TEXT__ -#define __TEXT__ +#ifndef __CGE_TEXT__ +#define __CGE_TEXT__ #include "cge/talk.h" #include "cge/jbw.h" diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index a22dd9d57af..152f608c56d 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __VGA13H__ -#define __VGA13H__ +#ifndef __CGE_VGA13H__ +#define __CGE_VGA13H__ #include "graphics/surface.h" #include "cge/general.h" diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index 3c38576a406..2bb3cef88d8 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __VMENU__ -#define __VMENU__ +#ifndef __CGE_VMENU__ +#define __CGE_VMENU__ #include "cge/talk.h" diff --git a/engines/cge/vol.h b/engines/cge/vol.h index c2e676130e6..1e0b363ca5d 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __VOL__ -#define __VOL__ +#ifndef __CGE_VOL__ +#define __CGE_VOL__ #include "cge/btfile.h" #include "cge/cfile.h" diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 980c7672c39..57187f7b87d 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __WAV__ -#define __WAV__ +#ifndef __CGE_WAV__ +#define __CGE_WAV__ #include "cge/general.h" #include From d55401c2e10276827372f8df29418937cc2daf22 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Jul 2011 16:46:31 +1000 Subject: [PATCH 055/276] CGE: Changed MOUSE class from using static fields to an instantiated class --- engines/cge/cge.cpp | 6 +++-- engines/cge/cge_main.cpp | 51 ++++++++++++++++++++-------------------- engines/cge/cge_main.h | 3 ++- engines/cge/events.cpp | 11 ++++----- engines/cge/events.h | 20 +++++++++------- engines/cge/gettext.cpp | 6 ++--- engines/cge/mixer.cpp | 4 ++-- engines/cge/snail.cpp | 6 ++--- 8 files changed, 57 insertions(+), 50 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 43d74ab3a50..3feb8f64d20 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -96,7 +96,8 @@ void CGEEngine::setup() { Snail = new SNAIL(this, false); Snail_ = new SNAIL(this, true); - Mouse = new MOUSE(this); + _mouse = new MOUSE(this); + _keyboard = new Keyboard(); OffUseCount = atoi(Text->getText(OFF_USE_COUNT)); } @@ -121,7 +122,8 @@ CGEEngine::~CGEEngine() { delete Hero; delete Sys; delete _pocLight; - delete Mouse; + delete _keyboard; + delete _mouse; for (int i = 0; i < POCKET_NX; i++) delete _pocket[i]; delete _sprite; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 40bace9c513..6e5c65b76f2 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -66,7 +66,8 @@ Heart *_heart; WALK *Hero; SYSTEM *Sys; Sprite *_pocLight; -MOUSE *Mouse; +Keyboard *_keyboard; +MOUSE *_mouse; Sprite *_pocket[POCKET_NX]; Sprite *_sprite; Sprite *_miniCave; @@ -741,7 +742,7 @@ static void caveUp() { Vga->Sunrise(VGA::SysPal); Dark = false; if (! Startup) - Mouse->On(); + _mouse->On(); _heart->_enable = true; } @@ -792,7 +793,7 @@ void CGEEngine::switchCave(int cav) { warning("SwitchCave() - SNPOST"); } else { Now = cav; - Mouse->Off(); + _mouse->Off(); if (Hero) { Hero->park(); Hero->step(0); @@ -836,13 +837,13 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { pp0 = pp; switch (x) { case Del: - if (Keyboard::_key[ALT] && Keyboard::_key[CTRL]) + if (_keyboard->_key[ALT] && _keyboard->_key[CTRL]) AltCtrlDel(); else KillSprite(); break; case 'F': - if (Keyboard::_key[ALT]) { + if (_keyboard->_key[ALT]) { Sprite *m = Vga->ShowQ->Locate(17001); if (m) { m->step(1); @@ -860,7 +861,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { NextStep(); break; case '`': - if (Keyboard::_key[ALT]) + if (_keyboard->_key[ALT]) SaveMapping(); else _vm->switchMapping(); @@ -890,7 +891,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { Sys->FunDel = 1; break; case 'X': - if (Keyboard::_key[ALT]) + if (_keyboard->_key[ALT]) Finis = true; break; case '0': @@ -898,7 +899,7 @@ void SYSTEM::Touch(uint16 mask, int x, int y) { case '2': case '3': case '4': - if (Keyboard::_key[ALT]) { + if (_keyboard->_key[ALT]) { SNPOST(SNLEVEL, -1, x - '0', NULL); break; } @@ -1034,7 +1035,7 @@ static void SwitchColorMode(void) { static void SwitchMusic(void) { - if (Keyboard::_key[ALT]) { + if (_keyboard->_key[ALT]) { if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); else { @@ -1194,8 +1195,8 @@ static void SayDebug(void) { t = t1; } - dwtom(Mouse->_x, ABSX, 10, 3); - dwtom(Mouse->_y, ABSY, 10, 3); + dwtom(_mouse->_x, ABSX, 10, 3); + dwtom(_mouse->_y, ABSY, 10, 3); // dwtom(coreleft(), NFRE, 10, 5); // dwtom(farcoreleft(), FFRE, 10, 6); @@ -1663,9 +1664,9 @@ void CGEEngine::runGame() { _horzLine->_z = 126; Vga->ShowQ->Insert(_horzLine); - Mouse->Busy = Vga->SpareQ->Locate(BUSY_REF); - if (Mouse->Busy) - ExpandSprite(Mouse->Busy); + _mouse->Busy = Vga->SpareQ->Locate(BUSY_REF); + if (_mouse->Busy) + ExpandSprite(_mouse->Busy); Startup = 0; @@ -1674,7 +1675,7 @@ void CGEEngine::runGame() { CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); caveUp(); - Keyboard::setClient(Sys); + _keyboard->setClient(Sys); // main loop while (! Finis) { //TODO Change the SNPOST message send to a special way to send function pointer @@ -1683,11 +1684,11 @@ void CGEEngine::runGame() { mainLoop(); } - Keyboard::setClient(NULL); + _keyboard->setClient(NULL); _heart->_enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); - Mouse->Off(); + _mouse->Off(); Vga->ShowQ->Clear(); Vga->SpareQ->Clear(); Hero = NULL; @@ -1706,11 +1707,11 @@ void CGEEngine::movie(const char *ext) { //Vga->ShowQ->Append(Mouse); _heart->_enable = true; - Keyboard::setClient(Sys); + _keyboard->setClient(Sys); while (!Snail->Idle()) mainLoop(); - Keyboard::setClient(NULL); + _keyboard->setClient(NULL); _heart->_enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); @@ -1746,12 +1747,12 @@ bool CGEEngine::showTitle(const char *name) { if (STARTUP::Mode < 2 && !STARTUP::SoundOk) { Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); - Vga->ShowQ->Append(Mouse); + Vga->ShowQ->Append(_mouse); _heart->_enable = true; - Mouse->On(); + _mouse->On(); for (selectSound(); !Snail->Idle() || VMENU::Addr;) mainLoop(); - Mouse->Off(); + _mouse->Off(); _heart->_enable = false; Vga->ShowQ->Clear(); Vga->CopyPage(0, 2); @@ -1782,13 +1783,13 @@ bool CGEEngine::showTitle(const char *name) { movie("X00"); // paylist Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); - Vga->ShowQ->Append(Mouse); + Vga->ShowQ->Append(_mouse); //Mouse.On(); _heart->_enable = true; for (takeName(); GetText::_ptr;) mainLoop(); _heart->_enable = false; - if (Keyboard::last() == Enter && *UsrFnam) + if (_keyboard->last() == Enter && *UsrFnam) usr_ok = true; if (usr_ok) strcat(UsrFnam, SVG_EXT); @@ -1842,7 +1843,7 @@ void CGEEngine::cge_main(void) { //Debug( memset((void *) (-K(4)), 0, K(1)); ) memset(Barriers, 0xFF, sizeof(Barriers)); - if (!Mouse->Exist) + if (!_mouse->Exist) error("%s", Text->getText(NO_MOUSE_TEXT)); if (!SVG0FILE::exist(SVG0NAME)) diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 37d1a91e001..3eea114420a 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -172,7 +172,8 @@ extern Heart *_heart; extern SYSTEM *Sys; extern int OffUseCount; extern Sprite *_pocLight; -extern MOUSE *Mouse; +extern Keyboard *_keyboard; +extern MOUSE *_mouse; extern Sprite *_pocket[]; extern Sprite *_sprite; extern Sprite *_miniCave; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index e5ad00da5e4..49b08e407b3 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -34,10 +34,7 @@ namespace CGE { /*----------------- KEYBOARD interface -----------------*/ -Sprite *Keyboard::_client = NULL; -uint8 Keyboard::_key[0x60] = { 0 }; -uint16 Keyboard::_current = 0; -uint16 Keyboard::_code[0x60] = { +const uint16 Keyboard::_code[0x60] = { 0, Esc, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '+', BSp, @@ -60,10 +57,12 @@ uint16 Keyboard::_code[0x60] = { 0 * 0x5F }; -void (* Keyboard::OldKeyboard)(...); - Keyboard::Keyboard() { + _client = NULL; + Common::set_to(&_key[0], &_key[0x60], 0); + _current = 0; + // steal keyboard interrupt /* TODO replace totally by scummvm handling OldKeyboard = getvect(KEYBD_INT); diff --git a/engines/cge/events.h b/engines/cge/events.h index 518c8c8bd16..462571f5ad8 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -46,18 +46,19 @@ namespace CGE { class Keyboard { public: - static void (* OldKeyboard)(...); - static void NewKeyboard(...); - static uint16 _code[0x60]; - static uint16 _current; - static Sprite *_client; - static uint8 _key[0x60]; - static uint16 last() { + static const uint16 _code[0x60]; + + void NewKeyboard(...); + uint16 _current; + Sprite *_client; + uint8 _key[0x60]; + uint16 last() { uint16 cur = _current; _current = 0; return cur; } - static Sprite *setClient(Sprite *spr); + Sprite *setClient(Sprite *spr); + Keyboard(); ~Keyboard(); }; @@ -111,6 +112,9 @@ private: CGEEngine *_vm; }; +/*----------------- Access variables -----------------*/ +// TODO: Move this into either the CGEEngine class or a suitable 'globals' + } // End of namespace CGE #endif diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 889aee4feda..9a6c1539d17 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -37,7 +37,7 @@ GetText *GetText::_ptr = NULL; GetText::GetText(CGEEngine *vm, const char *info, char *text, int size, void (*click)()) : TALK(vm), _text(text), _size(min(size, GTMAX)), _len(min(_size, strlen(text))), - _cntr(GTBLINK), _click(click), _oldKeybClient(Keyboard::setClient(this)), _vm(vm) { + _cntr(GTBLINK), _click(click), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { int i = 2 * TEXT_HM + _Font->Width(info); _ptr = this; Mode = RECT; @@ -54,7 +54,7 @@ GetText::GetText(CGEEngine *vm, const char *info, char *text, int size, void (*c GetText::~GetText() { - Keyboard::setClient(_oldKeybClient); + _keyboard->setClient(_oldKeybClient); _ptr = NULL; } @@ -101,7 +101,7 @@ void GetText::touch(uint16 mask, int x, int y) { if (_oldKeybClient) _oldKeybClient->touch(mask, x, y); } else { - if (Keyboard::_key[ALT]) { + if (_keyboard->_key[ALT]) { p = strchr(bezo, x); if (p) x = ogon[p - bezo]; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index f8c0b9ceabc..18bbfb65b51 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -114,8 +114,8 @@ void Mixer::touch(uint16 mask, int x, int y) { void Mixer::tick() { - int x = Mouse->_x; - int y = Mouse->_y; + int x = _mouse->_x; + int y = _mouse->_y; if (SpriteAt(x, y) == this) { _fall = MIX_FALL; if (_flags._hold) diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 217acb24488..9db8f4af6f9 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -180,7 +180,7 @@ static void SNGame(Sprite *spr, int num) { k2->step(new_random(6)); k3->step(new_random(6)); ///-------------------- - if (spr->_ref == 1 && Keyboard::_key[ALT]) { + if (spr->_ref == 1 && _keyboard->_key[ALT]) { k1->step(5); k2->step(5); k3->step(5); @@ -897,9 +897,9 @@ static void SNReach(Sprite *spr, int mode) { static void SNMouse(bool on) { if (on) - Mouse->On(); + _mouse->On(); else - Mouse->Off(); + _mouse->Off(); } From bb3d61b137aea4cab3e82d4f9f93b1dbea27c54e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Jul 2011 18:38:25 +1000 Subject: [PATCH 056/276] CGE: Created an EventManager class and hooked it up to the Keyboard class --- engines/cge/cge.cpp | 4 ++ engines/cge/cge.h | 2 + engines/cge/cge_main.cpp | 42 ++++++++--- engines/cge/cge_main.h | 1 + engines/cge/events.cpp | 152 ++++++++++++++++++++------------------- engines/cge/events.h | 26 +++++-- 6 files changed, 138 insertions(+), 89 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 3feb8f64d20..f7e66183ce1 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -51,6 +51,9 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) } void CGEEngine::setup() { + // Initialise fields + _lastFrame = 0; + // Create debugger console _console = new CGEConsole(this); @@ -98,6 +101,7 @@ void CGEEngine::setup() { _mouse = new MOUSE(this); _keyboard = new Keyboard(); + _eventManager = new EventManager(); OffUseCount = atoi(Text->getText(OFF_USE_COUNT)); } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 06c7fb23267..e4bb260bcce 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -43,6 +43,8 @@ enum { }; class CGEEngine : public Engine { +private: + uint32 _lastFrame; public: CGEEngine(OSystem *syst, const ADGameDescription *gameDescription); ~CGEEngine(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 6e5c65b76f2..0fa2b0cb0cb 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -66,6 +66,7 @@ Heart *_heart; WALK *Hero; SYSTEM *Sys; Sprite *_pocLight; +EventManager *_eventManager; Keyboard *_keyboard; MOUSE *_mouse; Sprite *_pocket[POCKET_NX]; @@ -1537,6 +1538,7 @@ void CGEEngine::loadScript(const char *fname) { error("%s [%s]", NumStr("Bad INI line ######", lcnt), fname); } +#define GAME_FRAME_DELAY (1000 / 50) void CGEEngine::mainLoop() { SayDebug(); @@ -1558,8 +1560,17 @@ void CGEEngine::mainLoop() { Snail_->RunCom(); Snail->RunCom(); - // Delay to slow things down - g_system->delayMillis(10); + // Game frame delay + uint32 millis = g_system->getMillis(); + while (!_eventManager->_quitFlag && (millis < (_lastFrame + GAME_FRAME_DELAY))) { + // Handle any pending events + _eventManager->poll(); + + // Slight delay + g_system->delayMillis(10); + millis = g_system->getMillis(); + } + _lastFrame = millis; } @@ -1585,6 +1596,9 @@ void CGEEngine::loadUser() { void CGEEngine::runGame() { + if (_eventManager->_quitFlag) + return; + Text->Clear(); Text->Preload(100, 1000); LoadHeroXY(); @@ -1677,7 +1691,7 @@ void CGEEngine::runGame() { _keyboard->setClient(Sys); // main loop - while (! Finis) { + while (! Finis && !_eventManager->_quitFlag) { //TODO Change the SNPOST message send to a special way to send function pointer // if (FINIS) SNPOST(SNEXEC, -1, 0, (void *)&QGame); warning("RunGame: problematic use of SNPOST"); @@ -1697,6 +1711,9 @@ void CGEEngine::runGame() { void CGEEngine::movie(const char *ext) { + if (_eventManager->_quitFlag) + return; + const char *fn = progName(ext); if (INI_FILE::exist(fn)) { loadScript(fn); @@ -1708,7 +1725,7 @@ void CGEEngine::movie(const char *ext) { _heart->_enable = true; _keyboard->setClient(Sys); - while (!Snail->Idle()) + while (!Snail->Idle() && !_eventManager->_quitFlag) mainLoop(); _keyboard->setClient(NULL); @@ -1722,6 +1739,9 @@ void CGEEngine::movie(const char *ext) { bool CGEEngine::showTitle(const char *name) { + if (_eventManager->_quitFlag) + return false; + Bitmap::_pal = VGA::SysPal; BMP_PTR LB[] = { new Bitmap(name, true), NULL }; Bitmap::_pal = NULL; @@ -1750,8 +1770,12 @@ bool CGEEngine::showTitle(const char *name) { Vga->ShowQ->Append(_mouse); _heart->_enable = true; _mouse->On(); - for (selectSound(); !Snail->Idle() || VMENU::Addr;) + for (selectSound(); !Snail->Idle() || VMENU::Addr;) { mainLoop(); + if (_eventManager->_quitFlag) + return false; + } + _mouse->Off(); _heart->_enable = false; Vga->ShowQ->Clear(); @@ -1786,8 +1810,11 @@ bool CGEEngine::showTitle(const char *name) { Vga->ShowQ->Append(_mouse); //Mouse.On(); _heart->_enable = true; - for (takeName(); GetText::_ptr;) + for (takeName(); GetText::_ptr;) { mainLoop(); + if (_eventManager->_quitFlag) + return false; + } _heart->_enable = false; if (_keyboard->last() == Enter && *UsrFnam) usr_ok = true; @@ -1857,10 +1884,9 @@ void CGEEngine::cge_main(void) { if (Music && STARTUP::SoundOk) LoadMIDI(0); -/** *****DEBUG***** if (STARTUP::Mode < 2) movie(LGO_EXT); -*/ + if (showTitle("WELCOME")) { if ((!_isDemo) && (STARTUP::Mode == 1)) movie("X02"); // intro diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 3eea114420a..effded84ccd 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -174,6 +174,7 @@ extern int OffUseCount; extern Sprite *_pocLight; extern Keyboard *_keyboard; extern MOUSE *_mouse; +extern EventManager *_eventManager; extern Sprite *_pocket[]; extern Sprite *_sprite; extern Sprite *_miniCave; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 49b08e407b3..92c356fa5fe 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -25,6 +25,7 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ +#include "common/events.h" #include "cge/events.h" #include "cge/events.h" #include "cge/text.h" @@ -57,103 +58,85 @@ const uint16 Keyboard::_code[0x60] = { 0 * 0x5F }; +const uint16 Keyboard::_scummVmCodes[0x60] = { + 0, Common::KEYCODE_ESCAPE, Common::KEYCODE_1, Common::KEYCODE_2, Common::KEYCODE_3, + Common::KEYCODE_4, Common::KEYCODE_5, Common::KEYCODE_6, Common::KEYCODE_7, Common::KEYCODE_8, + Common::KEYCODE_9, Common::KEYCODE_0, Common::KEYCODE_MINUS, Common::KEYCODE_PLUS, Common::KEYCODE_BACKSPACE, + Common::KEYCODE_TAB, Common::KEYCODE_q, Common::KEYCODE_w, Common::KEYCODE_e, Common::KEYCODE_r, + Common::KEYCODE_t, Common::KEYCODE_y, Common::KEYCODE_u, Common::KEYCODE_i, Common::KEYCODE_o, + Common::KEYCODE_p, Common::KEYCODE_LEFTBRACKET, Common::KEYCODE_RIGHTBRACKET, Common::KEYCODE_RETURN, 0/*Ctrl*/, + Common::KEYCODE_a, Common::KEYCODE_s, Common::KEYCODE_d, Common::KEYCODE_f, Common::KEYCODE_g, + Common::KEYCODE_h, Common::KEYCODE_j, Common::KEYCODE_k, Common::KEYCODE_l, Common::KEYCODE_SEMICOLON, + Common::KEYCODE_BACKSLASH, Common::KEYCODE_TILDE, Common::KEYCODE_LSHIFT, Common::KEYCODE_BACKSLASH, Common::KEYCODE_z, + Common::KEYCODE_x, Common::KEYCODE_c, Common::KEYCODE_v, Common::KEYCODE_b, Common::KEYCODE_n, + Common::KEYCODE_m, Common::KEYCODE_COMMA, Common::KEYCODE_PERIOD, Common::KEYCODE_SLASH, Common::KEYCODE_RSHIFT, + Common::KEYCODE_KP_MULTIPLY, 0 /*Alt*/, Common::KEYCODE_SPACE, Common::KEYCODE_CAPSLOCK, Common::KEYCODE_F1, + Common::KEYCODE_F2, Common::KEYCODE_F3, Common::KEYCODE_F4, Common::KEYCODE_F5, Common::KEYCODE_F6, + Common::KEYCODE_F7, Common::KEYCODE_F8, Common::KEYCODE_F9, Common::KEYCODE_F10, Common::KEYCODE_NUMLOCK, + Common::KEYCODE_SCROLLOCK, Common::KEYCODE_KP7, Common::KEYCODE_KP8, Common::KEYCODE_KP9, Common::KEYCODE_KP_MINUS, + Common::KEYCODE_KP4, Common::KEYCODE_KP5, Common::KEYCODE_KP6, Common::KEYCODE_KP_PLUS, Common::KEYCODE_KP1, + Common::KEYCODE_KP2, Common::KEYCODE_KP3, Common::KEYCODE_KP0, Common::KEYCODE_KP_PERIOD, 0, + 0, 0, Common::KEYCODE_F11, Common::KEYCODE_F12, 0, + 0, 0, 0, 0, 0, + 0 +}; Keyboard::Keyboard() { _client = NULL; - Common::set_to(&_key[0], &_key[0x60], 0); + Common::set_to(&_key[0], &_key[0x60], false); _current = 0; - - // steal keyboard interrupt - /* TODO replace totally by scummvm handling - OldKeyboard = getvect(KEYBD_INT); - setvect(KEYBD_INT, NewKeyboard); - */ - warning("STUB: Keyboard::Keyboard"); } - Keyboard::~Keyboard() { - // bring back keyboard interrupt - /* TODO replace totally by scummvm handling - setvect(KEYBD_INT, OldKeyboard); - */ - // FIXME: STUB: KEYBOARD::~KEYBOARD } - Sprite *Keyboard::setClient(Sprite *spr) { Swap(_client, spr); return spr; } +bool Keyboard::getKey(uint16 keycode, int &cgeCode) { + if ((keycode == Common::KEYCODE_LCTRL) || (keycode == Common::KEYCODE_RCTRL)) { + cgeCode = 29; + return true; + } -void Keyboard::NewKeyboard(...) { - // table address - /* - _SI = (uint16) Key; + // Scan through the ScummVM mapping list + for (int idx = 0; idx < 0x60; ++idx) { + if (_scummVmCodes[idx] == keycode) { + cgeCode = idx; + return true; + } + } - // take keyboard code - asm in al,60h - asm mov bl,al - asm and bx,007Fh - asm cmp bl,60h - asm jae xit - asm cmp al,bl - asm je ok // key pressed + return false; +} - // key released... - asm cmp [si+bx],bh // BH == 0 - asm jne ok - // ...but not pressed: call the original service - OldKeyboard(); - return; +void Keyboard::NewKeyboard(Common::Event &event) { + int keycode; + if (!getKey(event.kbd.keycode, keycode)) + return; - ok: - asm shl ax,1 - asm and ah,1 - asm xor ah,1 - asm mov [si+bx],ah - asm jz xit // released: exit + if (event.type == Common::EVENT_KEYUP) { + // Key release + _key[event.kbd.keycode] = false; + } else if (event.type == Common::EVENT_KEYDOWN) { + // Key press + _key[event.kbd.keycode] = true; + _current = Keyboard::_code[event.kbd.keycode]; - // pressed: lock ASCII code - _SI = (uint16) Code; - asm add bx,bx // uint16 size - asm mov ax,[si+bx] - asm or ax,ax - asm jz xit // zero means NO KEY - Current = _AX; - - _SI = (uint16) Client; - asm or si,si - asm jz xit // if (Client) ... - //--- fill current event entry with mask, key code and sprite - asm mov bx,EvtHead // take queue head pointer - asm inc byte ptr EvtHead // update queue head pointer - asm shl bx,3 // * 8 - _AX = Current; - asm mov Evt[bx].(struct EVENT)X,ax // key code - asm mov ax,KEYB // event mask - asm mov Evt[bx].(struct EVENT)Msk,ax // event mask - //asm mov Evt[bx].(struct EVENT)Y,dx // row - asm mov Evt[bx].(struct EVENT)Ptr,si // SPRITE pointer - - xit: - - asm in al,61h // kbd control lines - asm push ax // save it - asm or al,80h // set the "enable kbd" bit - asm out 61h,al // and write it out - asm pop ax // original control port value - asm out 61h,al // write it back - asm mov al,20h // send End-Of-Interrupt - asm out 20h,al // to the 8259 IC - */ - warning("STUB: Keyboard::NewKeyboard"); + if (_client) { + CGEEvent &evt = Evt[EvtHead++]; + evt._x = _current; // Keycode + evt._msk = KEYB; // Event mask + evt._ptr = _client; // Sprite pointer + } + } } /*----------------- MOUSE interface -----------------*/ -Event Evt[EVT_MAX]; +CGEEvent Evt[EVT_MAX]; uint16 EvtHead = 0, EvtTail = 0; @@ -268,7 +251,7 @@ void MOUSE::ClrEvt(Sprite *spr) { void MOUSE::Tick(void) { step(); while (EvtTail != EvtHead) { - Event e = Evt[EvtTail]; + CGEEvent e = Evt[EvtTail]; if (e._msk) { if (Hold && e._ptr != Hold) Hold->touch(e._msk | ATTN, e._x - Hold->_x, e._y - Hold->_y); @@ -313,5 +296,24 @@ void MOUSE::Tick(void) { Hold->gotoxy(_x - hx, _y - hy); } +/*----------------- EventManager interface -----------------*/ + +EventManager::EventManager() { + _quitFlag = false; +} + +void EventManager::poll() { + while (g_system->getEventManager()->pollEvent(_event)) { + switch (_event.type) { + case Common::EVENT_QUIT: + _quitFlag = true; + return; + case Common::EVENT_KEYDOWN: + case Common::EVENT_KEYUP: + _keyboard->NewKeyboard(_event); + break; + } + } +} } // End of namespace CGE diff --git a/engines/cge/events.h b/engines/cge/events.h index 462571f5ad8..be003ea0d86 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -28,6 +28,7 @@ #ifndef __CGE_CGE_EVENTS__ #define __CGE_CGE_EVENTS__ +#include "common/events.h" #include "cge/game.h" #include "cge/talk.h" #include "cge/jbw.h" @@ -45,13 +46,17 @@ namespace CGE { class Keyboard { +private: + bool getKey(uint16 keycode, int &cgeCode); public: static const uint16 _code[0x60]; + static const uint16 _scummVmCodes[0x60]; - void NewKeyboard(...); uint16 _current; Sprite *_client; - uint8 _key[0x60]; + bool _key[0x60]; + + void NewKeyboard(Common::Event &event); uint16 last() { uint16 cur = _current; _current = 0; @@ -77,14 +82,14 @@ public: extern TALK *Talk; -struct Event { +struct CGEEvent { uint16 _msk; uint16 _x; uint16 _y; Sprite *_ptr; }; -extern Event Evt[EVT_MAX]; +extern CGEEvent Evt[EVT_MAX]; extern uint16 EvtHead, EvtTail; typedef void (MOUSE_FUN)(void); @@ -112,8 +117,17 @@ private: CGEEngine *_vm; }; -/*----------------- Access variables -----------------*/ -// TODO: Move this into either the CGEEngine class or a suitable 'globals' +/*----------------- EventManager interface -----------------*/ + +class EventManager { +private: + Common::Event _event; +public: + bool _quitFlag; + + EventManager(); + void poll(); +}; } // End of namespace CGE From 72ae475c97e6f0ba1cae2f7aa0bc2860e45de495 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Jul 2011 20:04:30 +1000 Subject: [PATCH 057/276] CGE: Fix naming of touch() virtual methods, and fixed keyboard handling --- engines/cge/cge_main.cpp | 6 +-- engines/cge/cge_main.h | 2 +- engines/cge/events.cpp | 106 +++++++++++++++++++++------------------ engines/cge/events.h | 5 +- engines/cge/vmenu.cpp | 2 +- engines/cge/vmenu.h | 2 +- 6 files changed, 66 insertions(+), 57 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 0fa2b0cb0cb..0ee8f3ef0b8 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -552,7 +552,7 @@ void WALK::reach(Sprite *spr, int mode) { class SQUARE : public Sprite { public: SQUARE(CGEEngine *vm); - void Touch(uint16 mask, int x, int y); + virtual void touch(uint16 mask, int x, int y); private: CGEEngine *_vm; }; @@ -565,7 +565,7 @@ SQUARE::SQUARE(CGEEngine *vm) } -void SQUARE::Touch(uint16 mask, int x, int y) { +void SQUARE::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); if (mask & L_UP) { XZ(_x + x, _y + y).cell() = 0; @@ -822,7 +822,7 @@ SYSTEM::SYSTEM(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { Tick(); } -void SYSTEM::Touch(uint16 mask, int x, int y) { +void SYSTEM::touch(uint16 mask, int x, int y) { static int pp = 0; FunTouch(); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index effded84ccd..6920f7b2d32 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -122,7 +122,7 @@ public: void SetPal(); void FunTouch(); - void Touch(uint16 mask, int x, int y); + virtual void touch(uint16 mask, int x, int y); void Tick(); private: CGEEngine *_vm; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 92c356fa5fe..932c922c495 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -247,55 +247,6 @@ void MOUSE::ClrEvt(Sprite *spr) { EvtTail = EvtHead; } - -void MOUSE::Tick(void) { - step(); - while (EvtTail != EvtHead) { - CGEEvent e = Evt[EvtTail]; - if (e._msk) { - if (Hold && e._ptr != Hold) - Hold->touch(e._msk | ATTN, e._x - Hold->_x, e._y - Hold->_y); - - // update mouse cursor position - if (e._msk & ROLL) - gotoxy(e._x, e._y); - - // activate current touched SPRITE - if (e._ptr) { - if (e._msk & KEYB) - e._ptr->touch(e._msk, e._x, e._y); - else - e._ptr->touch(e._msk, e._x - e._ptr->_x, e._y - e._ptr->_y); - } else if (Sys) - Sys->touch(e._msk, e._x, e._y); - - if (e._msk & L_DN) { - Hold = e._ptr; - if (Hold) { - Hold->_flags._hold = true; - hx = e._x - Hold->_x; - hy = e._y - Hold->_y; - } - } - - if (e._msk & L_UP) { - if (Hold) { - Hold->_flags._hold = false; - Hold = NULL; - } - } - ///Touched = e.Ptr; - - // discard Text if button released - if (e._msk & (L_UP | R_UP)) - KillText(); - } - EvtTail = (EvtTail + 1) % EVT_MAX; - } - if (Hold) - Hold->gotoxy(_x - hx, _y - hy); -} - /*----------------- EventManager interface -----------------*/ EventManager::EventManager() { @@ -311,9 +262,66 @@ void EventManager::poll() { case Common::EVENT_KEYDOWN: case Common::EVENT_KEYUP: _keyboard->NewKeyboard(_event); + handleEvents(); + break; + case Common::EVENT_MOUSEMOVE: + case Common::EVENT_LBUTTONDOWN: + case Common::EVENT_LBUTTONUP: + case Common::EVENT_RBUTTONDOWN: + case Common::EVENT_RBUTTONUP: + // TODO: Handle mouse events + //_mouse->NewMouse(event); + handleEvents(); break; } } } +void EventManager::handleEvents(void) { + while (EvtTail != EvtHead) { + CGEEvent e = Evt[EvtTail]; + if (e._msk) { + if (_mouse->Hold && e._ptr != _mouse->Hold) + _mouse->Hold->touch(e._msk | ATTN, e._x - _mouse->Hold->_x, e._y - _mouse->Hold->_y); + + // update mouse cursor position + if (e._msk & ROLL) + _mouse->gotoxy(e._x, e._y); + + // activate current touched SPRITE + if (e._ptr) { + if (e._msk & KEYB) + e._ptr->touch(e._msk, e._x, e._y); + else + e._ptr->touch(e._msk, e._x - e._ptr->_x, e._y - e._ptr->_y); + } else if (Sys) + Sys->touch(e._msk, e._x, e._y); + + if (e._msk & L_DN) { + _mouse->Hold = e._ptr; + if (_mouse->Hold) { + _mouse->Hold->_flags._hold = true; + _mouse->hx = e._x - _mouse->Hold->_x; + _mouse->hy = e._y - _mouse->Hold->_y; + } + } + + if (e._msk & L_UP) { + if (_mouse->Hold) { + _mouse->Hold->_flags._hold = false; + _mouse->Hold = NULL; + } + } + ///Touched = e.Ptr; + + // discard Text if button released + if (e._msk & (L_UP | R_UP)) + KillText(); + } + EvtTail = (EvtTail + 1) % EVT_MAX; + } + if (_mouse->Hold) + _mouse->Hold->gotoxy(_mouse->_x - _mouse->hx, _mouse->_y - _mouse->hy); +} + } // End of namespace CGE diff --git a/engines/cge/events.h b/engines/cge/events.h index be003ea0d86..4ed74469f23 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -98,11 +98,11 @@ class MOUSE : public Sprite { static MOUSE_FUN *OldMouseFun; static MOUSE_FUN NewMouseFun; static uint16 OldMouseMask; - Sprite *Hold; - int hx, hy; //void SetFun (void); //void ResetFun (void); public: + Sprite *Hold; + int hx, hy; bool Exist; int Buttons; Sprite *Busy; @@ -122,6 +122,7 @@ private: class EventManager { private: Common::Event _event; + void handleEvents(); public: bool _quitFlag; diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 149af901e81..d999dfa7607 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -125,7 +125,7 @@ VMENU::~VMENU(void) { } -void VMENU::Touch(uint16 mask, int x, int y) { +void VMENU::touch(uint16 mask, int x, int y) { uint16 h = FONT_HIG + TEXT_LS; bool ok = false; diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index 2bb3cef88d8..c2fc096e830 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -59,7 +59,7 @@ public: MENU_BAR *Bar; VMENU(CGEEngine *vm, CHOICE *list, int x, int y); ~VMENU(); - void Touch(uint16 mask, int x, int y); + virtual void touch(uint16 mask, int x, int y); private: CGEEngine *_vm; }; From adb27016294b995eb273663a2c33904050723f96 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Jul 2011 20:38:27 +1000 Subject: [PATCH 058/276] CGE: Graceful exit rather than an error --- engines/cge/cge.cpp | 22 +++++++++++----------- engines/cge/cge_main.cpp | 1 - engines/cge/vga13h.cpp | 4 ++++ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index f7e66183ce1..da6365ca838 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -119,17 +119,7 @@ CGEEngine::~CGEEngine() { _console = new CGEConsole(this); - // Delete engine objects - delete Text; - delete Vga; - delete _heart; - delete Hero; - delete Sys; - delete _pocLight; - delete _keyboard; - delete _mouse; - for (int i = 0; i < POCKET_NX; i++) - delete _pocket[i]; + // Delete engine objects delete _sprite; delete _miniCave; delete _shadow; @@ -148,8 +138,18 @@ CGEEngine::~CGEEngine() { delete LI[1]; delete LI[2]; delete LI[3]; + delete Text; + delete _heart; + delete _pocLight; + delete _keyboard; + delete _mouse; + for (int i = 0; i < POCKET_NX; i++) + delete _pocket[i]; delete Snail; delete Snail_; + delete Hero; + delete Vga; + delete Sys; } Common::Error CGEEngine::run() { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 0ee8f3ef0b8..6562dac0411 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1896,7 +1896,6 @@ void CGEEngine::cge_main(void) { movie("X03"); } else Vga->Sunset(); - error("%s", Text->getText(EXIT_OK_TEXT + FINIS)); } } // End of namespace CGE diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 0e865ffd90b..83c89892cae 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -366,6 +366,8 @@ Sprite::Sprite(CGEEngine *vm, BMP_PTR *shp) Sprite::~Sprite() { + if (_sprite == this) + _sprite = NULL; contract(); } @@ -970,11 +972,13 @@ VGA::~VGA(void) { Mono = 0; if (isVga()) { Common::String buffer = ""; +/* Clear(0); SetMode(OldMode); SetColors(); RestoreScreen(OldScreen); Sunrise(OldColors); +*/ if (OldColors) free(OldColors); if (NewColors) From 1e3c0725e4ed431f6e1336edb7e3976532f71160 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Jul 2011 21:34:40 +1000 Subject: [PATCH 059/276] CGE: Hooked up mouse event handler --- engines/cge/events.cpp | 70 +++++++++++++++++++++++++++--------------- engines/cge/events.h | 9 ++---- engines/cge/snail.cpp | 2 +- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 932c922c495..2c675a69f81 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -140,31 +140,23 @@ CGEEvent Evt[EVT_MAX]; uint16 EvtHead = 0, EvtTail = 0; -MOUSE_FUN *MOUSE::OldMouseFun = NULL; -uint16 MOUSE::OldMouseMask = 0; - - MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold(NULL), hx(0), _vm(vm) { static Seq ms[] = { { 0, 0, 0, 0, 1 }, { 1, 1, 0, 0, 1 } }; + Hold = NULL; + hx = 0; hy = 0; + Exist = true; + Buttons = 0; + Busy = NULL; + setSeq(ms); - /* TODO Mouse handling - // Mouse reset - _AX = 0x0000; // soft & hard reset (0x0021 soft reset does not work) - __int__(0x33); - Exist = (_AX != 0); - Buttons = _BX; -*/ gotoxy(SCR_WID/2, SCR_HIG/2); _z = 127; step(1); - - Exist = true; - warning("STUB: MOUSE::MOUSE"); } @@ -236,15 +228,33 @@ void MOUSE::Off(void) { warning("STUB: MOUSE::Off"); } +void MOUSE::NewMouse(Common::Event &event) { + CGEEvent &evt = Evt[EvtHead++]; + evt._x = event.mouse.x; + evt._y = event.mouse.y; + evt._ptr = SpriteAt(evt._x, evt._y); -void MOUSE::ClrEvt(Sprite *spr) { - if (spr) { - uint16 e; - for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) - if (Evt[e]._ptr == spr) - Evt[e]._msk = 0; - } else - EvtTail = EvtHead; + switch (event.type) { + case Common::EVENT_MOUSEMOVE: + evt._msk = ROLL; + break; + case Common::EVENT_LBUTTONDOWN: + evt._msk = L_DN; + Buttons |= 1; + break; + case Common::EVENT_LBUTTONUP: + evt._msk = L_UP; + Buttons &= ~1; + break; + case Common::EVENT_RBUTTONDOWN: + evt._msk = R_DN; + Buttons |= 2; + break; + case Common::EVENT_RBUTTONUP: + evt._msk = R_UP; + Buttons &= ~2; + break; + } } /*----------------- EventManager interface -----------------*/ @@ -257,10 +267,12 @@ void EventManager::poll() { while (g_system->getEventManager()->pollEvent(_event)) { switch (_event.type) { case Common::EVENT_QUIT: + // Signal to quit _quitFlag = true; return; case Common::EVENT_KEYDOWN: case Common::EVENT_KEYUP: + // Handle keyboard events _keyboard->NewKeyboard(_event); handleEvents(); break; @@ -269,8 +281,8 @@ void EventManager::poll() { case Common::EVENT_LBUTTONUP: case Common::EVENT_RBUTTONDOWN: case Common::EVENT_RBUTTONUP: - // TODO: Handle mouse events - //_mouse->NewMouse(event); + // Handle mouse events + _mouse->NewMouse(_event); handleEvents(); break; } @@ -324,4 +336,14 @@ void EventManager::handleEvents(void) { _mouse->Hold->gotoxy(_mouse->_x - _mouse->hx, _mouse->_y - _mouse->hy); } +void EventManager::ClrEvt(Sprite *spr) { + if (spr) { + uint16 e; + for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) + if (Evt[e]._ptr == spr) + Evt[e]._msk = 0; + } else + EvtTail = EvtHead; +} + } // End of namespace CGE diff --git a/engines/cge/events.h b/engines/cge/events.h index 4ed74469f23..f1e02b0d093 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -91,15 +91,9 @@ struct CGEEvent { extern CGEEvent Evt[EVT_MAX]; extern uint16 EvtHead, EvtTail; -typedef void (MOUSE_FUN)(void); class MOUSE : public Sprite { - static MOUSE_FUN *OldMouseFun; - static MOUSE_FUN NewMouseFun; - static uint16 OldMouseMask; - //void SetFun (void); - //void ResetFun (void); public: Sprite *Hold; int hx, hy; @@ -111,8 +105,8 @@ public: ~MOUSE(); void On(); void Off(); - static void ClrEvt(Sprite *spr = NULL); void Tick(); + void NewMouse(Common::Event &event); private: CGEEngine *_vm; }; @@ -128,6 +122,7 @@ public: EventManager(); void poll(); + static void ClrEvt(Sprite *spr = NULL); }; } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 9db8f4af6f9..4bf6f724893 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -747,7 +747,7 @@ void SNKill(Sprite *spr) { Sprite *nx = spr->_next; Hide1(spr); Vga->ShowQ->Remove(spr); - MOUSE::ClrEvt(spr); + EventManager::ClrEvt(spr); if (spr->_flags._kill) delete spr; else { From e782b53eab7d9c77f17e1393712bf8425f9349a0 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Jul 2011 21:45:29 +1000 Subject: [PATCH 060/276] CGE: Added code for Mouse::On and Mouse::Off --- engines/cge/events.cpp | 66 ++++++++++-------------------------------- engines/cge/events.h | 1 + 2 files changed, 17 insertions(+), 50 deletions(-) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 2c675a69f81..99ada03bd5f 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -151,6 +151,7 @@ MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold( Exist = true; Buttons = 0; Busy = NULL; + _active = false; setSeq(ms); @@ -171,64 +172,29 @@ MOUSE::~MOUSE(void) { void MOUSE::On(void) { - /* - if (SeqPtr && Exist) - { - _CX = X + X; // horizontal position - _DX = Y; // vertical position - _AX = 0x0004; // Set Mouse Position - __int__(0x33); - // set new mouse fun - _ES = FP_SEG(NewMouseFun); - _DX = FP_OFF(NewMouseFun); - _CX = 0x001F; // 11111b = all events - _AX = 0x0014; // Swap User-Interrupt Vector - __int__(0x33); - // save old mouse fun - OldMouseMask = _CX; - OldMouseFun = (MOUSE_FUN *) MK_FP(_ES, _DX); - - // set X bounds - _DX = (SCR_WID - W) * 2; // right limit - _CX = 0; // left limit - _AX = 0x0007; // note: each pixel = 2 - __int__(0x33); - - // set Y bounds - _DX = SCR_HIG - H; // bottom limit - _CX = 0; // top limit - _AX = 0x0008; - __int__(0x33); - - Step(0); - if (Busy) Busy->Step(0); - } - */ - warning("STUB: MOUSE::On"); + if (_seqPtr && Exist) { + _active = true; + step(0); + if (Busy) Busy->step(0); + } } void MOUSE::Off(void) { -/* - if (SeqPtr == 0) - { - if (Exist) - { - // bring back old mouse fun - _ES = FP_SEG(OldMouseFun); - _DX = FP_OFF(OldMouseFun); - _CX = OldMouseMask; - _AX = 0x0014; // Swap User-Interrupt Vector - __int__(0x33); + if (_seqPtr == 0) { + if (Exist) { + _active = false; + } + + step(1); + if (Busy) Busy->step(1); } - Step(1); - if (Busy) Busy->Step(1); - } - */ - warning("STUB: MOUSE::Off"); } void MOUSE::NewMouse(Common::Event &event) { + if (!_active) + return; + CGEEvent &evt = Evt[EvtHead++]; evt._x = event.mouse.x; evt._y = event.mouse.y; diff --git a/engines/cge/events.h b/engines/cge/events.h index f1e02b0d093..59a62803bac 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -96,6 +96,7 @@ extern uint16 EvtHead, EvtTail; class MOUSE : public Sprite { public: Sprite *Hold; + bool _active; int hx, hy; bool Exist; int Buttons; From d510d2505b7c9e4968020de6926dea19cfb7fa34 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Jul 2011 22:15:23 +1000 Subject: [PATCH 061/276] CGE: Fix for crash in BITMAP::solidAt when negative co-ordinates passed --- engines/cge/bitmap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index dc06d9944e6..3bcf751b401 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -313,7 +313,7 @@ bool Bitmap::solidAt(int x, int y) { return false; m = _v; - r = x % 4; + r = static_cast(x) % 4; n0 = (SCR_WID * y + x) / 4, n = 0; while (r) { From f150126a0b209418d3a91ec5b5f1c1c0fdced9c7 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 2 Jul 2011 22:26:40 +1000 Subject: [PATCH 062/276] CGE: Bugfix for wrapping event queue when it reaches the 256th event --- engines/cge/events.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 99ada03bd5f..2b9cc7fc6c4 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -33,6 +33,10 @@ namespace CGE { +CGEEvent Evt[EVT_MAX]; + +uint16 EvtHead = 0, EvtTail = 0; + /*----------------- KEYBOARD interface -----------------*/ const uint16 Keyboard::_code[0x60] = { @@ -126,7 +130,8 @@ void Keyboard::NewKeyboard(Common::Event &event) { _current = Keyboard::_code[event.kbd.keycode]; if (_client) { - CGEEvent &evt = Evt[EvtHead++]; + CGEEvent &evt = Evt[EvtHead]; + EvtHead = (EvtHead + 1) % EVT_MAX; evt._x = _current; // Keycode evt._msk = KEYB; // Event mask evt._ptr = _client; // Sprite pointer @@ -136,10 +141,6 @@ void Keyboard::NewKeyboard(Common::Event &event) { /*----------------- MOUSE interface -----------------*/ -CGEEvent Evt[EVT_MAX]; - -uint16 EvtHead = 0, EvtTail = 0; - MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold(NULL), hx(0), _vm(vm) { static Seq ms[] = { { 0, 0, 0, 0, 1 }, @@ -195,7 +196,8 @@ void MOUSE::NewMouse(Common::Event &event) { if (!_active) return; - CGEEvent &evt = Evt[EvtHead++]; + CGEEvent &evt = Evt[EvtHead]; + EvtHead = (EvtHead + 1) % EVT_MAX; evt._x = event.mouse.x; evt._y = event.mouse.y; evt._ptr = SpriteAt(evt._x, evt._y); From bdc213846e1c35c7b6b7f5a397f97d8fe334c1b1 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 2 Jul 2011 18:20:41 +0200 Subject: [PATCH 063/276] CGE: Some more renaming (WIP) --- engines/cge/cge.cpp | 8 +- engines/cge/cge_main.cpp | 224 ++++++++++++++------------- engines/cge/cge_main.h | 8 +- engines/cge/config.cpp | 10 +- engines/cge/general.cpp | 6 +- engines/cge/snail.cpp | 322 +++++++++++++++++++-------------------- engines/cge/snail.h | 82 +++++----- engines/cge/snddrv.h | 10 +- engines/cge/sound.cpp | 8 +- engines/cge/sound.h | 10 +- engines/cge/vga13h.cpp | 46 +++--- engines/cge/vga13h.h | 4 +- 12 files changed, 364 insertions(+), 374 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index da6365ca838..4af10b2b8df 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -96,8 +96,8 @@ void CGEEngine::setup() { LI[2] = new Bitmap("LITE2", true); LI[3] = new Bitmap("LITE3", true); LI[4] = NULL; - Snail = new SNAIL(this, false); - Snail_ = new SNAIL(this, true); + _snail = new Snail(this, false); + _snail_ = new Snail(this, true); _mouse = new MOUSE(this); _keyboard = new Keyboard(); @@ -145,8 +145,8 @@ CGEEngine::~CGEEngine() { delete _mouse; for (int i = 0; i < POCKET_NX; i++) delete _pocket[i]; - delete Snail; - delete Snail_; + delete _snail; + delete _snail_; delete Hero; delete Vga; delete Sys; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 6562dac0411..22316d79b19 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -54,7 +54,7 @@ namespace CGE { #define STACK_SIZ (K(2)) -#define SVGCHKSUM (1956 + Now + OldLev + Game + Music + DemoText) +#define SVGCHKSUM (1956 + _now + _oldLev + _game + _music + _demoText) #define SVG0NAME ("{{INIT}}" SVG_EXT) #define SVG0FILE INI_FILE @@ -85,8 +85,8 @@ BMP_PTR PR[2]; BMP_PTR SP[3]; BMP_PTR LI[5]; -SNAIL *Snail; -SNAIL *Snail_; +Snail *_snail; +Snail *_snail_; // 0.75 - 17II95 - full sound support // 0.76 - 18II95 - small MiniEMS in DEMO, @@ -124,8 +124,8 @@ SNAIL *Snail_; char Copr[] = "To be fixed - Copr[]"; static char UsrFnam[15] = "\0ɱ%^þúȼ´ ÇÉ"; -static int OldLev = 0; -static int DemoText = DEMO_TEXT; +static int _oldLev = 0; +static int _demoText = DEMO_TEXT; //-------------------------------------------------------------------------- @@ -142,16 +142,14 @@ static int Startup = 1; int OffUseCount; uint16 *intStackPtr = false; -HXY HeroXY[CAVE_MAX] = {{0, 0}}; -BAR Barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; +Hxy _heroXY[CAVE_MAX] = {{0, 0}}; +Bar _barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; +extern int findPocket(Sprite *); +extern Dac _stdPal[58]; -extern int FindPocket(Sprite *); - -extern Dac _stdPal[58]; - -void FeedSnail(Sprite *spr, SNLIST snq); // defined in SNAIL -uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; +void feedSnail(Sprite *spr, SNLIST snq); // defined in SNAIL +uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; uint8 &Cluster::cell(void) { @@ -161,7 +159,7 @@ uint8 &Cluster::cell(void) { bool Cluster::Protected(void) { /* - if (A == Barriers[Now].Vert || B == Barriers[Now].Horz) + if (A == Barriers[Now]._vert || B == Barriers[Now]._horz) return true; _DX = (MAP_ZCNT << 8) + MAP_XCNT; @@ -220,8 +218,8 @@ Cluster XZ(Couple xy) { } -int pocref[POCKET_NX]; -uint8 volume[2]; +int _pocref[POCKET_NX]; +uint8 _volume[2]; struct SavTab { void *Ptr; @@ -230,21 +228,21 @@ struct SavTab { }; SavTab _savTab[] = { - { &Now, sizeof(Now), 1 }, - { &OldLev, sizeof(OldLev), 1 }, - { &DemoText, sizeof(DemoText), 1 }, - { &Game, sizeof(Game), 1 }, - { &Game, sizeof(Game), 1 }, // spare 1 - { &Game, sizeof(Game), 1 }, // spare 2 - { &Game, sizeof(Game), 1 }, // spare 3 - { &Game, sizeof(Game), 1 }, // spare 4 + { &_now, sizeof(_now), 1 }, + { &_oldLev, sizeof(_oldLev), 1 }, + { &_demoText, sizeof(_demoText), 1 }, + { &_game, sizeof(_game), 1 }, + { &_game, sizeof(_game), 1 }, // spare 1 + { &_game, sizeof(_game), 1 }, // spare 2 + { &_game, sizeof(_game), 1 }, // spare 3 + { &_game, sizeof(_game), 1 }, // spare 4 // { &VGA::Mono, sizeof(VGA::Mono), 0 }, - { &Music, sizeof(Music), 1 }, - { volume, sizeof(volume), 1 }, - { Flag, sizeof(Flag), 1 }, - { HeroXY, sizeof(HeroXY), 1 }, - { Barriers, sizeof(Barriers), 1 }, - { pocref, sizeof(pocref), 1 }, + { &_music, sizeof(_music), 1 }, + { _volume, sizeof(_volume), 1 }, + { _flag, sizeof(_flag), 1 }, + { _heroXY, sizeof(_heroXY), 1 }, + { _barriers, sizeof(_barriers), 1 }, + { _pocref, sizeof(_pocref), 1 }, { NULL, 0, 0 } }; @@ -265,11 +263,11 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { error("%s", Text->getText(BADSVG_TEXT)); if (STARTUP::Core < CORE_HIG) - Music = false; + _music = false; if (STARTUP::SoundOk == 1 && STARTUP::Mode == 0) { - SNDDrvInfo.VOL2.D = volume[0]; - SNDDrvInfo.VOL2.M = volume[1]; + SNDDrvInfo.VOL2.D = _volume[0]; + SNDDrvInfo.VOL2.M = _volume[1]; SNDSetVolume(); } @@ -291,7 +289,7 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { } for (i = 0; i < POCKET_NX; i++) { - register int r = pocref[i]; + register int r = _pocref[i]; _pocket[i] = (r < 0) ? NULL : Vga->SpareQ->Locate(r); } } @@ -312,11 +310,11 @@ static void SaveGame(XFile &file) { for (i = 0; i < POCKET_NX; i++) { register Sprite *s = _pocket[i]; - pocref[i] = (s) ? s->_ref : -1; + _pocref[i] = (s) ? s->_ref : -1; } - volume[0] = SNDDrvInfo.VOL2.D; - volume[1] = SNDDrvInfo.VOL2.M; + _volume[0] = SNDDrvInfo.VOL2.D; + _volume[1] = SNDDrvInfo.VOL2.M; for (st = _savTab; st->Ptr; st++) { if (file._error) @@ -366,18 +364,18 @@ static void noWay() { static void LoadHeroXY(void) { INI_FILE cf(progName(".HXY")); - memset(HeroXY, 0, sizeof(HeroXY)); + memset(_heroXY, 0, sizeof(_heroXY)); if (!cf._error) - cf.CFREAD(&HeroXY); + cf.CFREAD(&_heroXY); } static void LoadMapping(void) { - if (Now <= CAVE_MAX) { + if (_now <= CAVE_MAX) { INI_FILE cf(progName(".TAB")); if (!cf._error) { memset(Cluster::_map, 0, sizeof(Cluster::_map)); - cf.seek((Now - 1) * sizeof(Cluster::_map)); + cf.seek((_now - 1) * sizeof(Cluster::_map)); cf.read((uint8 *) Cluster::_map, sizeof(Cluster::_map)); } } @@ -405,7 +403,7 @@ void WALK::tick() { for (spr = Vga->ShowQ->First(); spr; spr = spr->_next) { if (distance(spr) < 2) { if (!spr->_flags._near) { - FeedSnail(spr, NEAR); + feedSnail(spr, NEAR); spr->_flags._near = true; } } else { @@ -614,7 +612,7 @@ void CGEEngine::quit() { { NULL, &CGEEngine::dummy } }; - if (Snail->Idle() && ! Hero->_flags._hide) { + if (_snail->idle() && ! Hero->_flags._hide) { if (VMENU::Addr) { SNPOST_(SNKILL, -1, 0, VMENU::Addr); resetQSwitch(); @@ -640,8 +638,8 @@ static void miniStep(int stp) { else { &*Mini; *MiniShp[0] = *MiniShpList[stp]; - if (Fx.Current) - &*(Fx.Current->EAddr()); + if (_fx.Current) + &*(_fx.Current->EAddr()); _miniCave->_flags._hide = false; } @@ -688,9 +686,9 @@ static void ShowBak(int ref) { static void caveUp() { - int BakRef = 1000 * Now; - if (Music) - LoadMIDI(Now); + int BakRef = 1000 * _now; + if (_music) + LoadMIDI(_now); ShowBak(BakRef); LoadMapping(); @@ -698,7 +696,7 @@ static void caveUp() { Sprite *spr = Vga->SpareQ->First(); while (spr) { Sprite *n = spr->_next; - if (spr->_cave == Now || spr->_cave == 0) + if (spr->_cave == _now || spr->_cave == 0) if (spr->_ref != BakRef) { if (spr->_flags._back) spr->backShow(); @@ -708,25 +706,25 @@ static void caveUp() { spr = n; } if (SNDDrvInfo.DDEV) { - Sound.Stop(); - Fx.Clear(); - Fx.Preload(0); - Fx.Preload(BakRef); + _sound.Stop(); + _fx.Clear(); + _fx.Preload(0); + _fx.Preload(BakRef); } if (Hero) { - Hero->gotoxy(HeroXY[Now - 1]._x, HeroXY[Now - 1]._y); + Hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); // following 2 lines trims Hero's Z position! Hero->tick(); Hero->_time = 1; Hero->_flags._hide = false; } - if (! Dark) + if (!_dark) Vga->Sunset(); Vga->CopyPage(0, 1); - SelectPocket(-1); + selectPocket(-1); if (Hero) Vga->ShowQ->Insert(Vga->ShowQ->Remove(Hero)); @@ -736,12 +734,12 @@ static void caveUp() { Vga->ShowQ->Insert(_shadow, Hero); _shadow->_z = Hero->_z; } - FeedSnail(Vga->ShowQ->Locate(BakRef + 999), TAKE); + feedSnail(Vga->ShowQ->Locate(BakRef + 999), TAKE); Vga->Show(); Vga->CopyPage(1, 0); Vga->Show(); Vga->Sunrise(VGA::SysPal); - Dark = false; + _dark = false; if (! Startup) _mouse->On(); @@ -758,7 +756,7 @@ void CGEEngine::caveDown() { Sprite *n = spr->_next; if (spr->_ref >= 1000 /*&& spr->_cave*/) { if (spr->_ref % 1000 == 999) - FeedSnail(spr, TAKE); + feedSnail(spr, TAKE); Vga->SpareQ->Append(Vga->ShowQ->Remove(spr)); } spr = n; @@ -775,7 +773,7 @@ void CGEEngine::xCave() { void CGEEngine::qGame() { caveDown(); - OldLev = Lev; + _oldLev = _lev; SaveSound(); CFile file = CFile(UsrPath(UsrFnam), WRI, RCrypt); SaveGame(file); @@ -785,7 +783,7 @@ void CGEEngine::qGame() { void CGEEngine::switchCave(int cav) { - if (cav != Now) { + if (cav != _now) { _heart->_enable = false; if (cav < 0) { SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint @@ -793,7 +791,7 @@ void CGEEngine::switchCave(int cav) { //SNPOST(SNEXEC, -1, 0, (void *)&QGame); // switch cave warning("SwitchCave() - SNPOST"); } else { - Now = cav; + _now = cav; _mouse->Off(); if (Hero) { Hero->park(); @@ -803,8 +801,8 @@ void CGEEngine::switchCave(int cav) { Vga->SpareQ->Show = STARTUP::Summa * (cav <= CAVE_MAX); /////-------------------------------------------------------- } - _cavLight->gotoxy(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, - CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); + _cavLight->gotoxy(CAVE_X + ((_now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, + CAVE_Y + ((_now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); KillText(); if (! Startup) KeyClick(); @@ -913,7 +911,7 @@ void SYSTEM::touch(uint16 mask, int x, int y) { _sprite->step(x - '0'); break; case F10 : - if (Snail->Idle() && ! Hero->_flags._hide) + if (_snail->idle() && ! Hero->_flags._hide) _vm->startCountDown(); break; case 'J': @@ -939,9 +937,9 @@ void SYSTEM::touch(uint16 mask, int x, int y) { if (y >= WORLD_HIG) { if (x < BUTTON_X) { // select cave? if (y >= CAVE_Y && y < CAVE_Y + CAVE_NY * CAVE_DY && - x >= CAVE_X && x < CAVE_X + CAVE_NX * CAVE_DX && ! Game) { + x >= CAVE_X && x < CAVE_X + CAVE_NX * CAVE_DX && !_game) { cav = ((y - CAVE_Y) / CAVE_DY) * CAVE_NX + (x - CAVE_X) / CAVE_DX + 1; - if (cav > MaxCave) + if (cav > _maxCave) cav = 0; } else { cav = 0; @@ -950,7 +948,7 @@ void SYSTEM::touch(uint16 mask, int x, int y) { if (y >= POCKET_Y && y < POCKET_Y + POCKET_NY * POCKET_DY && x >= POCKET_X && x < POCKET_X + POCKET_NX * POCKET_DX) { int n = ((y - POCKET_Y) / POCKET_DY) * POCKET_NX + (x - POCKET_X) / POCKET_DX; - SelectPocket(n); + selectPocket(n); } } } @@ -958,7 +956,7 @@ void SYSTEM::touch(uint16 mask, int x, int y) { PostMiniStep(cav - 1); if (mask & L_UP) { - if (cav && Snail->Idle() && Hero->_tracePtr < 0) + if (cav && _snail->idle() && Hero->_tracePtr < 0) _vm->switchCave(cav); if (!_horzLine->_flags._hide) { @@ -970,8 +968,8 @@ void SYSTEM::touch(uint16 mask, int x, int y) { } } else { - if (! Talk && Snail->Idle() && Hero - && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && ! Game) { + if (! Talk && _snail->idle() && Hero + && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && !_game) { Hero->findWay(XZ(x, y)); } } @@ -983,7 +981,7 @@ void SYSTEM::touch(uint16 mask, int x, int y) { void SYSTEM::Tick(void) { if (! Startup) if (-- FunDel == 0) { KillText(); - if (Snail->Idle()) { + if (_snail->idle()) { if (PAIN) HeroCover(9); else if (STARTUP::Core >= CORE_MID) { @@ -1040,7 +1038,7 @@ static void SwitchMusic(void) { if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); else { - SNPOST_(SNSEQ, 122, (Music = false), NULL); + SNPOST_(SNSEQ, 122, (_music = false), NULL); //TODO Change the SNPOST message send to a special way to send function pointer // SNPOST(SNEXEC, -1, 0, (void *)&selectSound); warning("SwitchMusic() - SNPOST"); @@ -1049,12 +1047,12 @@ static void SwitchMusic(void) { if (STARTUP::Core < CORE_HIG) SNPOST(SNINF, -1, NOMUSIC_TEXT, NULL); else { - SNPOST_(SNSEQ, 122, (Music = ! Music), NULL); + SNPOST_(SNSEQ, 122, (_music = !_music), NULL); KeyClick(); } } - if (Music) - LoadMIDI(Now); + if (_music) + LoadMIDI(_now); else KillMIDI(); } @@ -1148,16 +1146,16 @@ static void SaveMapping() { { IoHand cf(progName(".TAB"), UPD); if (!cf._error) { - cf.seek((Now - 1) * sizeof(Cluster::_map)); + cf.seek((_now - 1) * sizeof(Cluster::_map)); cf.write((uint8 *) Cluster::_map, sizeof(Cluster::_map)); } } { IoHand cf(progName(".HXY"), WRI); if (!cf._error) { - HeroXY[Now - 1]._x = Hero->_x; - HeroXY[Now - 1]._y = Hero->_y; - cf.write((uint8 *) HeroXY, sizeof(HeroXY)); + _heroXY[_now - 1]._x = Hero->_x; + _heroXY[_now - 1]._y = Hero->_y; + cf.write((uint8 *) _heroXY, sizeof(_heroXY)); } } } @@ -1265,19 +1263,19 @@ void Sprite::touch(uint16 mask, int x, int y) { } if (_flags._syst) return; // cannot access system sprites - if (Game) if (mask & L_UP) { + if (_game) if (mask & L_UP) { mask &= ~L_UP; mask |= R_UP; } - if ((mask & R_UP) && Snail->Idle()) { + if ((mask & R_UP) && _snail->idle()) { Sprite *ps = (_pocLight->_seqPtr) ? _pocket[PocPtr] : NULL; if (ps) { if (_flags._kept || Hero->distance(this) < MAX_DISTANCE) { if (works(ps)) { - FeedSnail(ps, TAKE); + feedSnail(ps, TAKE); } else OffUse(); - SelectPocket(-1); + selectPocket(-1); } else TooFar(); } else { @@ -1287,8 +1285,8 @@ void Sprite::touch(uint16 mask, int x, int y) { if (Hero->distance(this) < MAX_DISTANCE) { /// if (_flags._port) { - if (FindPocket(NULL) < 0) - PocFul(); + if (findPocket(NULL) < 0) + pocFul(); else { SNPOST(SNREACH, -1, -1, this); SNPOST(SNKEEP, -1, -1, this); @@ -1296,10 +1294,10 @@ void Sprite::touch(uint16 mask, int x, int y) { } } else { if (_takePtr != NO_PTR) { - if (snList(TAKE)[_takePtr].Com == SNNEXT) + if (snList(TAKE)[_takePtr]._com == SNNEXT) OffUse(); else - FeedSnail(this, TAKE); + feedSnail(this, TAKE); } else OffUse(); } @@ -1309,12 +1307,12 @@ void Sprite::touch(uint16 mask, int x, int y) { } } } - if ((mask & L_UP) && Snail->Idle()) { + if ((mask & L_UP) && _snail->idle()) { if (_flags._kept) { int n; for (n = 0; n < POCKET_NX; n++) { if (_pocket[n] == this) { - SelectPocket(n); + selectPocket(n); break; } } @@ -1545,20 +1543,20 @@ void CGEEngine::mainLoop() { if (_isDemo) { // static uint32 tc = 0; - if (/* FIXME: TimerCount - tc >= ((182L * 6L) * 5L) && */ Talk == NULL && Snail->Idle()) { - if (Text->getText(DemoText)) { + if (/* FIXME: TimerCount - tc >= ((182L * 6L) * 5L) && */ Talk == NULL && _snail->idle()) { + if (Text->getText(_demoText)) { SNPOST(SNSOUND, -1, 4, NULL); // drumla - SNPOST(SNINF, -1, DemoText, NULL); + SNPOST(SNINF, -1, _demoText, NULL); SNPOST(SNLABEL, -1, -1, NULL); - if (Text->getText(++ DemoText) == NULL) - DemoText = DEMO_TEXT + 1; + if (Text->getText(++_demoText) == NULL) + _demoText = DEMO_TEXT + 1; } //FIXME: tc = TimerCount; } } Vga->Show(); - Snail_->RunCom(); - Snail->RunCom(); + _snail_->runCom(); + _snail->runCom(); // Game frame delay uint32 millis = g_system->getMillis(); @@ -1585,7 +1583,7 @@ void CGEEngine::loadUser() { loadGame(file); } else { loadScript(progName(INI_EXT)); - Music = true; + _music = true; CFile file = CFile(SVG0NAME, WRI); SaveGame(file); error("Ok [%s]", SVG0NAME); @@ -1620,7 +1618,7 @@ void CGEEngine::runGame() { _pocLight->_time = 1; _pocLight->_z = 120; Vga->ShowQ->Append(_pocLight); - SelectPocket(-1); + selectPocket(-1); // FIXME: Allow ScummVM to handle mouse display // Vga->ShowQ->Append(Mouse); @@ -1632,9 +1630,9 @@ void CGEEngine::runGame() { if ((_sprite = Vga->SpareQ->Locate(121)) != NULL) SNPOST_(SNSEQ, -1, Vga->Mono, _sprite); if ((_sprite = Vga->SpareQ->Locate(122)) != NULL) - _sprite->step(Music); - SNPOST_(SNSEQ, -1, Music, _sprite); - if (! Music) + _sprite->step(_music); + SNPOST_(SNSEQ, -1, _music, _sprite); + if (!_music) KillMIDI(); if (Mini && INI_FILE::exist("MINI.SPR")) { @@ -1654,7 +1652,7 @@ void CGEEngine::runGame() { if (Hero) { ExpandSprite(Hero); - Hero->gotoxy(HeroXY[Now - 1]._x, HeroXY[Now - 1]._y); + Hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); if (INI_FILE::exist("00SHADOW.SPR")) { loadSprite("00SHADOW", -1, 0, Hero->_x + 14, Hero->_y + 51); if ((_shadow = _sprite) != NULL) { @@ -1684,9 +1682,9 @@ void CGEEngine::runGame() { Startup = 0; - SNPOST(SNLEVEL, -1, OldLev, &_cavLight); - _cavLight->gotoxy(CAVE_X + ((Now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, - CAVE_Y + ((Now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); + SNPOST(SNLEVEL, -1, _oldLev, &_cavLight); + _cavLight->gotoxy(CAVE_X + ((_now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, + CAVE_Y + ((_now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); caveUp(); _keyboard->setClient(Sys); @@ -1718,14 +1716,14 @@ void CGEEngine::movie(const char *ext) { if (INI_FILE::exist(fn)) { loadScript(fn); ExpandSprite(Vga->SpareQ->Locate(999)); - FeedSnail(Vga->ShowQ->Locate(999), TAKE); + feedSnail(Vga->ShowQ->Locate(999), TAKE); // FIXME: Allow ScummVM to handle mouse display //Vga->ShowQ->Append(Mouse); _heart->_enable = true; _keyboard->setClient(Sys); - while (!Snail->Idle() && !_eventManager->_quitFlag) + while (!_snail->idle() && !_eventManager->_quitFlag) mainLoop(); _keyboard->setClient(NULL); @@ -1761,7 +1759,7 @@ bool CGEEngine::showTitle(const char *name) { Vga->Sunset(); Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); - SelectPocket(-1); + selectPocket(-1); Vga->Sunrise(VGA::SysPal); if (STARTUP::Mode < 2 && !STARTUP::SoundOk) { @@ -1770,7 +1768,7 @@ bool CGEEngine::showTitle(const char *name) { Vga->ShowQ->Append(_mouse); _heart->_enable = true; _mouse->On(); - for (selectSound(); !Snail->Idle() || VMENU::Addr;) { + for (selectSound(); !_snail->idle() || VMENU::Addr;) { mainLoop(); if (_eventManager->_quitFlag) return false; @@ -1781,7 +1779,7 @@ bool CGEEngine::showTitle(const char *name) { Vga->ShowQ->Clear(); Vga->CopyPage(0, 2); STARTUP::SoundOk = 2; - if (Music) + if (_music) LoadMIDI(0); } @@ -1868,7 +1866,7 @@ void CGEEngine::cge_main(void) { //Debug( memset((void *) (-K(2)), 0, K(1)); ) //Debug( memset((void *) (-K(4)), 0, K(1)); ) - memset(Barriers, 0xFF, sizeof(Barriers)); + memset(_barriers, 0xFF, sizeof(_barriers)); if (!_mouse->Exist) error("%s", Text->getText(NO_MOUSE_TEXT)); @@ -1882,7 +1880,7 @@ void CGEEngine::cge_main(void) { //srand((uint16) Timer()); Sys = new SYSTEM(this); - if (Music && STARTUP::SoundOk) + if (_music && STARTUP::SoundOk) LoadMIDI(0); if (STARTUP::Mode < 2) movie(LGO_EXT); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 6920f7b2d32..5e3eb6bf1c5 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -109,8 +109,8 @@ namespace CGE { #define SYSTIMERATE 6 // 12 Hz #define HEROFUN0 (40 * 12) #define HEROFUN1 ( 2 * 12) -#define PAIN (Flag[0]) -#define FINIS (Flag[3]) +#define PAIN (_flag[0]) +#define FINIS (_flag[3]) class SYSTEM : public Sprite { @@ -190,8 +190,8 @@ extern BMP_PTR MC[3]; extern BMP_PTR PR[2]; extern BMP_PTR SP[3]; extern BMP_PTR LI[5]; -extern SNAIL *Snail; -extern SNAIL *Snail_; +extern Snail *_snail; +extern Snail *_snail_; } // End of namespace CGE diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 8110e1702fa..4f5284b69b4 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -143,7 +143,7 @@ static CHOICE BlsterDMA[] = { void CGEEngine::selectSound() { int i; - Sound.Close(); + _sound.Close(); if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); inf(Text->getText(STYPE_TEXT)); @@ -201,7 +201,7 @@ static void Select(CHOICE *cho, int hlp) { void CGEEngine::NONE() { SNDDrvInfo.DDEV = DEV_QUIET; SNDDrvInfo.MDEV = DEV_QUIET; - Sound.Open(); + _sound.Open(); } @@ -249,7 +249,7 @@ void CGEEngine::AUTO() { SNDDrvInfo.DDEV = DEV_AUTO; SNDDrvInfo.MDEV = DEV_AUTO; Reset(); - Sound.Open(); + _sound.Open(); } @@ -261,7 +261,7 @@ void CGEEngine::setPortD() { void CGEEngine::setPortM() { SNDDrvInfo.MBASE = xdeco(MIDIPorts[VMENU::Recent].Text); - Sound.Open(); + _sound.Open(); } @@ -276,7 +276,7 @@ void CGEEngine::setDMA() { if (SNDDrvInfo.MDEV != SNDDrvInfo.DDEV) Select(MIDIPorts, MPORT_TEXT); else - Sound.Open(); + _sound.Open(); } } // End of namespace CGE diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index b2852788428..faff3ada575 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -93,7 +93,7 @@ Dac _stdPal[] = {// R G B { 255, 255, 255}, // 255 }; -DRVINFO SNDDrvInfo; +DrvInfo SNDDrvInfo; void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)) { warning("STUB: _fqsort"); @@ -311,11 +311,11 @@ void SNDSetVolume() { warning("STUB: SNDSetVolume"); } -void SNDDigiStart(SMPINFO *PSmpInfo) { +void SNDDigiStart(SmpInfo *PSmpInfo) { warning("STUB: SNDDigitStart"); } -void SNDDigiStop(SMPINFO *PSmpInfo) { +void SNDDigiStop(SmpInfo *PSmpInfo) { warning("STUB: SNDDigiStop"); } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 4bf6f724893..fbde5bd846e 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -46,14 +46,13 @@ static void _disable() { warning("STUB: _disable"); } -int MaxCave = 0; +int _maxCave = 0; -SCB Scb = { NULL, 0, NULL }; -bool Flag[4]; -bool Dark = false; -bool Game = false; -int Now = 1; -int Lev = -1; +bool _flag[4]; +bool _dark = false; +bool _game = false; +int _now = 1; +int _lev = -1; extern Sprite *_pocLight; @@ -86,7 +85,7 @@ static void SNGame(Sprite *spr, int num) { dup[2] = Vga->ShowQ->Locate(16004); // pani } - if (Game) { // continue game + if (_game) { // continue game int i = new_random(3), hand = (dup[0]->_shpCnt == 6); Stage++; if (hand && Stage > DRESSED) @@ -131,7 +130,7 @@ static void SNGame(Sprite *spr, int num) { SNPOST(SNSEQ, -1, 0, dup[2]); // odstaw J† SNPOST(SNSETXY, -1, 182 + SCR_WID * 62, dup[2]); SNPOST(SNSETZ, -1, 9, dup[2]); - Game = 0; + _game = 0; return; } else { SNPOST(SNSEQ, -1, 2, dup[0]); // no @@ -152,9 +151,9 @@ static void SNGame(Sprite *spr, int num) { SNPOST(SNSEQ, 16040, 0, NULL); // schowaj plask SNPOST(SNWAIT, 16101, -1, NULL); // stoi SNPOST(SNUNCOVER, 1, 16101, NULL); // SDS - if (! Game) { + if (!_game) { SNPOST(SNSAY, buref, 16008, NULL); // zgadnij! - Game = true; + _game = true; } #undef STEPS #undef DRESSED @@ -172,9 +171,9 @@ static void SNGame(Sprite *spr, int num) { k3 = Vga->ShowQ->Locate(20703); } - if (! Game) { // init + if (!_game) { // init SNPOST(SNGAME, 20002, 2, NULL); - Game = true; + _game = true; } else { // cont k1->step(new_random(6)); k2->step(new_random(6)); @@ -203,7 +202,7 @@ static void SNGame(Sprite *spr, int num) { SNPOST(SNSEND, 20010, 20, NULL); // papier SNPOST(SNSOUND, 20010, 20003, NULL); // papier! SNPOST(SNSAY, 20001, 20005, NULL); - Game = false; + _game = false; return; } else k3->step(new_random(5)); @@ -285,7 +284,7 @@ void ContractSprite(Sprite *spr) { Vga->SpareQ->Append(Vga->ShowQ->Remove(spr)); } -int FindPocket(Sprite *spr) { +int findPocket(Sprite *spr) { for (int i = 0; i < POCKET_NX; i++) if (_pocket[i] == spr) return i; @@ -293,10 +292,10 @@ int FindPocket(Sprite *spr) { } -void SelectPocket(int n) { +void selectPocket(int n) { if (n < 0 || (_pocLight->_seqPtr && PocPtr == n)) { _pocLight->step(0); - n = FindPocket(NULL); + n = findPocket(NULL); if (n >= 0) PocPtr = n; } else { @@ -309,7 +308,7 @@ void SelectPocket(int n) { } -void PocFul(void) { +void pocFul() { Hero->park(); SNPOST(SNWAIT, -1, -1, Hero); SNPOST(SNSEQ, -1, POC_FUL, Hero); @@ -333,38 +332,38 @@ void SNGhost(Bitmap *bmp) { } -void FeedSnail(Sprite *spr, SNLIST snq) { +void feedSnail(Sprite *spr, SNLIST snq) { if (spr) if (spr->active()) { uint8 ptr = (snq == TAKE) ? spr->_takePtr : spr->_nearPtr; if (ptr != NO_PTR) { - SNAIL::COM *comtab = spr->snList(snq); - SNAIL::COM *c = comtab + ptr; + Snail::Com *comtab = spr->snList(snq); + Snail::Com *c = comtab + ptr; - if (FindPocket(NULL) < 0) { // no empty pockets? - SNAIL::COM *p; - for (p = c; p->Com != SNNEXT; p++) { // find KEEP command - if (p->Com == SNKEEP) { - PocFul(); + if (findPocket(NULL) < 0) { // no empty pockets? + Snail::Com *p; + for (p = c; p->_com != SNNEXT; p++) { // find KEEP command + if (p->_com == SNKEEP) { + pocFul(); return; } - if (p->Ptr) + if (p->_ptr) break; } } while (true) { - if (c->Com == SNTALK) { - if ((Snail->TalkEnable = (c->Val != 0)) == false) + if (c->_com == SNTALK) { + if ((_snail->_talkEnable = (c->_val != 0)) == false) KillText(); } - if (c->Com == SNNEXT) { - Sprite *s = (c->Ref < 0) ? spr : Locate(c->Ref); + if (c->_com == SNNEXT) { + Sprite *s = (c->_ref < 0) ? spr : Locate(c->_ref); if (s) { uint8 *idx = (snq == TAKE) ? &s->_takePtr : &s->_nearPtr; if (*idx != NO_PTR) { int v; - switch (c->Val) { + switch (c->_val) { case -1 : v = c - comtab + 1; break; @@ -375,7 +374,7 @@ void FeedSnail(Sprite *spr, SNLIST snq) { v = -1; break; default : - v = c->Val; + v = c->_val; break; } if (v >= 0) @@ -385,18 +384,18 @@ void FeedSnail(Sprite *spr, SNLIST snq) { if (s == spr) break; } - if (c->Com == SNIF) { - Sprite *s = (c->Ref < 0) ? spr : Locate(c->Ref); + if (c->_com == SNIF) { + Sprite *s = (c->_ref < 0) ? spr : Locate(c->_ref); if (s) { // sprite extsts if (! s->seqTest(-1)) - c = comtab + c->Val; // not parked + c = comtab + c->_val; // not parked else ++c; } else ++c; } else { - SNPOST(c->Com, c->Ref, c->Val, spr); - if (c->Ptr) + SNPOST(c->_com, c->_ref, c->_val, spr); + if (c->_ptr) break; else ++c; @@ -407,7 +406,7 @@ void FeedSnail(Sprite *spr, SNLIST snq) { } -const char *SNAIL::ComTxt[] = { +const char *Snail::_comTxt[] = { "LABEL", "PAUSE", "WAIT", "LEVEL", "HIDE", "SAY", "INF", "TIME", "CAVE", "KILL", "RSEQ", "SEQ", "SEND", "SWAP", "KEEP", @@ -422,28 +421,28 @@ const char *SNAIL::ComTxt[] = { }; -SNAIL::SNAIL(CGEEngine *vm, bool turbo) - : Turbo(turbo), Busy(false), TextDelay(false), - _timerExpiry(0), TalkEnable(true), - Head(0), Tail(0), SNList(farnew(COM, 256)), _vm(vm) { +Snail::Snail(CGEEngine *vm, bool turbo) + : _turbo(turbo), _busy(false), _textDelay(false), + _timerExpiry(0), _talkEnable(true), + _head(0), _tail(0), _snList(farnew(Com, 256)), _vm(vm) { } -SNAIL::~SNAIL(void) { - if (SNList) - free(SNList); +Snail::~Snail() { + if (_snList) + free(_snList); } -void SNAIL::AddCom(SNCOM com, int ref, int val, void *ptr) { +void Snail::addCom(SNCOM com, int ref, int val, void *ptr) { _disable(); - COM *snc = &SNList[Head++]; - snc->Com = com; - snc->Ref = ref; - snc->Val = val; - snc->Ptr = ptr; + Com *snc = &_snList[_head++]; + snc->_com = com; + snc->_ref = ref; + snc->_val = val; + snc->_ptr = ptr; if (com == SNCLEAR) { - Tail = Head; + _tail = _head; KillText(); _timerExpiry = 0; } @@ -451,22 +450,22 @@ void SNAIL::AddCom(SNCOM com, int ref, int val, void *ptr) { } -void SNAIL::InsCom(SNCOM com, int ref, int val, void *ptr) { - COM *snc; +void Snail::insCom(SNCOM com, int ref, int val, void *ptr) { + Com *snc; _disable(); - if (Busy) { - SNList[(Tail - 1) & 0xFF] = SNList[Tail]; - snc = &SNList[Tail]; + if (_busy) { + _snList[(_tail - 1) & 0xFF] = _snList[_tail]; + snc = &_snList[_tail]; } else - snc = &SNList[(Tail - 1) & 0xFF]; - --Tail; - snc->Com = com; - snc->Ref = ref; - snc->Val = val; - snc->Ptr = ptr; + snc = &_snList[(_tail - 1) & 0xFF]; + _tail--; + snc->_com = com; + snc->_ref = ref; + snc->_val = val; + snc->_ptr = ptr; if (com == SNCLEAR) { - Tail = Head; + _tail = _head; KillText(); _timerExpiry = 0; } @@ -559,13 +558,13 @@ void SNRSeq(Sprite *spr, int val) { void SNSend(Sprite *spr, int val) { if (spr) { int was = spr->_cave; - bool was1 = (was == 0 || was == Now); - bool val1 = (val == 0 || val == Now); + bool was1 = (was == 0 || was == _now); + bool val1 = (val == 0 || val == _now); spr->_cave = val; if (val1 != was1) { if (was1) { if (spr->_flags._kept) { - int n = FindPocket(spr); + int n = findPocket(spr); if (n >= 0) _pocket[n] = NULL; } @@ -591,15 +590,15 @@ void SNSwap(Sprite *spr, int xref) { if (spr && xspr) { int was = spr->_cave; int xwas = xspr->_cave; - bool was1 = (was == 0 || was == Now); - bool xwas1 = (xwas == 0 || xwas == Now); + bool was1 = (was == 0 || was == _now); + bool xwas1 = (xwas == 0 || xwas == _now); Swap(spr->_cave, xspr->_cave); Swap(spr->_x, xspr->_x); Swap(spr->_y, xspr->_y); Swap(spr->_z, xspr->_z); if (spr->_flags._kept) { - int n = FindPocket(spr); + int n = findPocket(spr); if (n >= 0) _pocket[n] = xspr; xspr->_flags._kept = true; @@ -633,7 +632,7 @@ void SNCover(Sprite *spr, int xref) { Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr->_prev), xspr); spr->_flags._shad = false; } - FeedSnail(xspr, NEAR); + feedSnail(xspr, NEAR); } } @@ -656,12 +655,12 @@ void SNUncover(Sprite *spr, Sprite *xspr) { void SNSetX0(int cav, int x0) { - HeroXY[cav - 1]._x = x0; + _heroXY[cav - 1]._x = x0; } void SNSetY0(int cav, int y0) { - HeroXY[cav - 1]._y = y0; + _heroXY[cav - 1]._y = y0; } @@ -740,7 +739,7 @@ void SNPort(Sprite *spr, int port) { void SNKill(Sprite *spr) { if (spr) { if (spr->_flags._kept) { - int n = FindPocket(spr); + int n = findPocket(spr); if (n >= 0) _pocket[n] = NULL; } @@ -765,15 +764,15 @@ void SNKill(Sprite *spr) { static void SNSound(Sprite *spr, int wav, int cnt) { if (SNDDrvInfo.DDEV) { if (wav == -1) - Sound.Stop(); + _sound.Stop(); else - Sound.Play(Fx[wav], (spr) ? ((spr->_x + spr->_w / 2) / (SCR_WID / 16)) : 8, cnt); + _sound.Play(_fx[wav], (spr) ? ((spr->_x + spr->_w / 2) / (SCR_WID / 16)) : 8, cnt); } } void SNKeep(Sprite *spr, int stp) { - SelectPocket(-1); + selectPocket(-1); if (spr && ! spr->_flags._kept && _pocket[PocPtr] == NULL) { SNSound(spr, 3, 1); _pocket[PocPtr] = spr; @@ -784,22 +783,22 @@ void SNKeep(Sprite *spr, int stp) { if (stp >= 0) spr->step(stp); } - SelectPocket(-1); + selectPocket(-1); } void SNGive(Sprite *spr, int stp) { if (spr) { - int p = FindPocket(spr); + int p = findPocket(spr); if (p >= 0) { _pocket[p] = NULL; - spr->_cave = Now; + spr->_cave = _now; spr->_flags._kept = false; if (stp >= 0) spr->step(stp); } } - SelectPocket(-1); + selectPocket(-1); } @@ -818,22 +817,22 @@ static void SNLevel(Sprite *spr, int lev) { #else static int maxcav[] = { 1, 8, 16, 23, 24 }; #endif - while (Lev < lev) { - ++Lev; - spr = Vga->SpareQ->Locate(100 + Lev); + while (_lev < lev) { + _lev++; + spr = Vga->SpareQ->Locate(100 + _lev); if (spr) { spr->backShow(true); spr->_cave = 0; } } - MaxCave = maxcav[Lev]; + _maxCave = maxcav[_lev]; if (spr) spr->_flags._hide = false; } static void SNFlag(int fn, bool v) { - Flag[fn] = v; + _flag[fn] = v; } @@ -861,7 +860,7 @@ void SNFlash(bool on) { } } else Vga->SetColors(VGA::SysPal, 64); - Dark = false; + _dark = false; } @@ -870,12 +869,12 @@ static void SNLight(bool in) { Vga->Sunrise(VGA::SysPal); else Vga->Sunset(); - Dark = ! in; + _dark = ! in; } static void SNBarrier(int cav, int bar, bool horz) { - ((uint8 *)(Barriers + ((cav > 0) ? cav : Now)))[horz] = bar; + ((uint8 *)(_barriers + ((cav > 0) ? cav : _now)))[horz] = bar; } @@ -903,15 +902,15 @@ static void SNMouse(bool on) { } -void SNAIL::RunCom(void) { +void Snail::runCom() { static int count = 1; - if (! Busy) { - Busy = true; - uint8 tmphea = Head; - while (Tail != tmphea) { - COM *snc = &SNList[Tail]; + if (!_busy) { + _busy = true; + uint8 tmphea = _head; + while (_tail != tmphea) { + Com *snc = &_snList[_tail]; - if (! Turbo) { // only for the slower one + if (!_turbo) { // only for the slower one if (_timerExpiry) { // Delay in progress if (_timerExpiry > g_system->getMillis()) @@ -921,150 +920,148 @@ void SNAIL::RunCom(void) { // Delay is finished _timerExpiry = 0; } else { - if (TextDelay) { + if (_textDelay) { KillText(); - TextDelay = false; + _textDelay = false; } } - if (Talk && snc->Com != SNPAUSE) + if (Talk && snc->_com != SNPAUSE) break; } - Sprite *sprel = ((snc->Ref >= 0) ? Locate(snc->Ref) : ((Sprite *) snc->Ptr)); - switch (snc->Com) { + Sprite *sprel = ((snc->_ref >= 0) ? Locate(snc->_ref) : ((Sprite *) snc->_ptr)); + switch (snc->_com) { case SNLABEL : break; case SNPAUSE : - _timerExpiry = g_system->getMillis() + snc->Val * SNAIL_FRAME_DELAY; + _timerExpiry = g_system->getMillis() + snc->_val * SNAIL_FRAME_DELAY; if (Talk) - TextDelay = true; + _textDelay = true; break; case SNWAIT : if (sprel) { - if (sprel->seqTest(snc->Val) && - (snc->Val >= 0 || sprel != Hero || Hero->_tracePtr < 0)) { + if (sprel->seqTest(snc->_val) && + (snc->_val >= 0 || sprel != Hero || Hero->_tracePtr < 0)) { _timerExpiry = g_system->getMillis() + sprel->_time * SNAIL_FRAME_DELAY; } else goto xit; } break; case SNLEVEL : - SNLevel(sprel, snc->Val); + SNLevel(sprel, snc->_val); break; case SNHIDE : - SNHide(sprel, snc->Val); + SNHide(sprel, snc->_val); break; case SNSAY : - if (sprel && TalkEnable) { + if (sprel && _talkEnable) { if (sprel == Hero && sprel->seqTest(-1)) sprel->step(HTALK); - Text->Say(Text->getText(snc->Val), sprel); + Text->Say(Text->getText(snc->_val), sprel); Sys->FunDel = HEROFUN0; } break; case SNINF : - if (TalkEnable) { - _vm->inf(Text->getText(snc->Val)); + if (_talkEnable) { + _vm->inf(Text->getText(snc->_val)); Sys->FunDel = HEROFUN0; } break; case SNTIME : - if (sprel && TalkEnable) { + if (sprel && _talkEnable) { if (sprel == Hero && sprel->seqTest(-1)) sprel->step(HTALK); SayTime(sprel); } break; case SNCAVE : - // SwitchCave(snc->Val); - warning("Problematic call of SwitchCave in SNAIL::RunCom"); + // SwitchCave(snc->_val); + warning("Problematic call of SwitchCave in SNAIL::runCom"); break; case SNKILL : SNKill(sprel); break; case SNSEQ : - SNSeq(sprel, snc->Val); + SNSeq(sprel, snc->_val); break; case SNRSEQ : - SNRSeq(sprel, snc->Val); + SNRSeq(sprel, snc->_val); break; case SNSEND : - SNSend(sprel, snc->Val); + SNSend(sprel, snc->_val); break; case SNSWAP : - SNSwap(sprel, snc->Val); + SNSwap(sprel, snc->_val); break; case SNCOVER : - SNCover(sprel, snc->Val); + SNCover(sprel, snc->_val); break; case SNUNCOVER : - SNUncover(sprel, (snc->Val >= 0) ? Locate(snc->Val) : ((Sprite *) snc->Ptr)); + SNUncover(sprel, (snc->_val >= 0) ? Locate(snc->_val) : ((Sprite *) snc->_ptr)); break; case SNKEEP : - SNKeep(sprel, snc->Val); + SNKeep(sprel, snc->_val); break; case SNGIVE : - SNGive(sprel, snc->Val); + SNGive(sprel, snc->_val); break; case SNGAME : - SNGame(sprel, snc->Val); + SNGame(sprel, snc->_val); break; case SNSETX0 : - SNSetX0(snc->Ref, snc->Val); + SNSetX0(snc->_ref, snc->_val); break; case SNSETY0 : - SNSetY0(snc->Ref, snc->Val); + SNSetY0(snc->_ref, snc->_val); break; case SNSETXY : - SNSetXY(sprel, snc->Val); + SNSetXY(sprel, snc->_val); break; case SNRELX : - SNRelX(sprel, snc->Val); + SNRelX(sprel, snc->_val); break; case SNRELY : - SNRelY(sprel, snc->Val); + SNRelY(sprel, snc->_val); break; case SNRELZ : - SNRelZ(sprel, snc->Val); + SNRelZ(sprel, snc->_val); break; case SNSETX : - SNSetX(sprel, snc->Val); + SNSetX(sprel, snc->_val); break; case SNSETY : - SNSetY(sprel, snc->Val); + SNSetY(sprel, snc->_val); break; case SNSETZ : - SNSetZ(sprel, snc->Val); + SNSetZ(sprel, snc->_val); break; case SNSLAVE : - SNSlave(sprel, snc->Val); + SNSlave(sprel, snc->_val); break; case SNTRANS : - SNTrans(sprel, snc->Val); + SNTrans(sprel, snc->_val); break; case SNPORT : - SNPort(sprel, snc->Val); + SNPort(sprel, snc->_val); break; case SNNEXT : - break; case SNIF : - break; case SNTALK : break; case SNMOUSE : - SNMouse(snc->Val != 0); + SNMouse(snc->_val != 0); break; case SNNNEXT : - SNNNext(sprel, snc->Val); + SNNNext(sprel, snc->_val); break; case SNTNEXT : - SNTNext(sprel, snc->Val); + SNTNext(sprel, snc->_val); break; case SNRNNEXT : - SNRNNext(sprel, snc->Val); + SNRNNext(sprel, snc->_val); break; case SNRTNEXT : - SNRTNext(sprel, snc->Val); + SNRTNext(sprel, snc->_val); break; case SNRMNEAR : SNRmNear(sprel); @@ -1073,43 +1070,44 @@ void SNAIL::RunCom(void) { SNRmTake(sprel); break; case SNFLAG : - SNFlag(snc->Ref & 3, snc->Val != 0); + SNFlag(snc->_ref & 3, snc->_val != 0); break; case SNSETREF : - SNSetRef(sprel, snc->Val); + SNSetRef(sprel, snc->_val); break; case SNBACKPT : - SNBackPt(sprel, snc->Val); + SNBackPt(sprel, snc->_val); break; case SNFLASH : - SNFlash(snc->Val != 0); + SNFlash(snc->_val != 0); break; case SNLIGHT : - SNLight(snc->Val != 0); + SNLight(snc->_val != 0); break; case SNSETHB : - SNBarrier(snc->Ref, snc->Val, true); + SNBarrier(snc->_ref, snc->_val, true); break; case SNSETVB : - SNBarrier(snc->Ref, snc->Val, false); + SNBarrier(snc->_ref, snc->_val, false); break; case SNWALK : - SNWalk(sprel, snc->Ref, snc->Val); + SNWalk(sprel, snc->_ref, snc->_val); break; case SNREACH : - SNReach(sprel, snc->Val); + SNReach(sprel, snc->_val); break; case SNSOUND : - SNSound(sprel, snc->Val, count); + SNSound(sprel, snc->_val, count); count = 1; break; case SNCOUNT : - count = snc->Val; + count = snc->_val; break; case SNEXEC : // TODO: Handle correctly the execution of function pointer coming from Message send SNPOST - // ((void(*)(int)) (snc->Ptr))(snc->Val); break; + // ((void(*)(int)) (snc->_ptr))(snc->_val); warning("STUB: SNEXEC code"); + break; case SNSTEP : sprel->step(); break; @@ -1117,24 +1115,24 @@ void SNAIL::RunCom(void) { SNZTrim(sprel); break; case SNGHOST : - SNGhost((Bitmap *) snc->Ptr); + SNGhost((Bitmap *) snc->_ptr); break; default : - warning("Unhandled snc->Com in SNMouse(bool)"); + warning("Unhandled snc->_com in SNMouse(bool)"); break; } - Tail++; - if (!Turbo) + _tail++; + if (!_turbo) break; } xit: - Busy = false; + _busy = false; } } -bool SNAIL::Idle(void) { - return (Head == Tail); +bool Snail::idle() { + return (_head == _tail); } } // End of namespace CGE diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 54a24ac1a9f..2e061495265 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -43,22 +43,16 @@ namespace CGE { #define POCKET_SX 8 #define POCKET_SY 3 -#define SNINSERT(c,r,v,p) Snail->InsCom(c,r,v,p) -#define SNPOST(c,r,v,p) Snail->AddCom(c,r,v,p) -#define SNPOST_(c,r,v,p) Snail_->AddCom(c,r,v,p) +#define SNINSERT(c, r, v, p) _snail->insCom(c, r, v, p) +#define SNPOST(c, r, v, p) _snail->addCom(c, r, v, p) +#define SNPOST_(c, r, v, p) _snail_->addCom(c, r, v, p) #define SNAIL_FRAME_RATE 62 #define SNAIL_FRAME_DELAY (1000 / SNAIL_FRAME_RATE) -typedef struct { - uint8 Horz, Vert; -} BAR; - - -struct SCB { - uint8 *Ptr; - uint16 Siz; - SCB *Nxt; +struct Bar { + uint8 _horz; + uint8 _vert; }; @@ -79,49 +73,49 @@ enum SNCOM { enum SNLIST { NEAR, TAKE }; -class SNAIL { +class Snail { public: - struct COM { - SNCOM Com; - int Ref; - int Val; - void *Ptr; - } *SNList; - uint8 Head, Tail; - bool Turbo, Busy, TextDelay; + struct Com { + SNCOM _com; + int _ref; + int _val; + void *_ptr; + } *_snList; + uint8 _head; + uint8 _tail; + bool _turbo; + bool _busy; + bool _textDelay; uint32 _timerExpiry; - static const char *ComTxt[]; - bool TalkEnable; - SNAIL(CGEEngine *vm, bool turbo = false); - ~SNAIL(); - void RunCom(void); - void AddCom(SNCOM com, int ref = 0, int val = 0, void *ptr = NULL); - void InsCom(SNCOM com, int ref = 0, int val = 0, void *ptr = NULL); - bool Idle(void); + static const char *_comTxt[]; + bool _talkEnable; + Snail(CGEEngine *vm, bool turbo); + ~Snail(); + void runCom(); + void addCom(SNCOM com, int ref, int val, void *ptr); + void insCom(SNCOM com, int ref, int val, void *ptr); + bool idle(); private: CGEEngine *_vm; }; -void SelectPocket(int n); -void PocFul(void); +void selectPocket(int n); +void pocFul(); -extern SCB Scb; -extern bool Flag[4]; -extern bool Game; -extern bool Dark; -//extern SNAIL *Snail; -//extern SNAIL *Snail_; -extern int Now; -extern int Lev; -extern int MaxCave; -extern int PocPtr; -extern BAR Barriers[]; -extern struct HXY { +extern bool _flag[4]; +extern bool _game; +extern bool _dark; +extern int _now; +extern int _lev; +extern int _maxCave; +extern int _pocPtr; +extern Bar _barriers[]; +extern struct Hxy { int _x; int _y; -} HeroXY[]; +} _heroXY[]; } // End of namespace CGE diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 4cdac383bef..78d1434b40f 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -56,7 +56,7 @@ enum DEV_TYPE { DEV_AUTO = -1, // auto-detect mode #define SERR_BADDDEV 128 // bad device // driver info -struct DRVINFO { +struct DrvInfo { DEV_TYPE DDEV; // digi device DEV_TYPE MDEV; // midi device uint16 DBASE; // digi base port @@ -78,7 +78,7 @@ struct DRVINFO { }; // sample info -struct SMPINFO { +struct SmpInfo { uint8 *saddr; // address uint16 slen; // length uint16 span; // left/right pan (0-15) @@ -89,7 +89,7 @@ struct SMPINFO { // * Data * // ****************************************************** // driver info -extern DRVINFO SNDDrvInfo; +extern DrvInfo SNDDrvInfo; // midi player flag (1 means we are playing) extern uint16 MIDIPlayFlag; @@ -110,10 +110,10 @@ void SNDDone(); void SNDSetVolume(); // Start Digi -void SNDDigiStart(SMPINFO *PSmpInfo); +void SNDDigiStart(SmpInfo *PSmpInfo); // Stop Digi -void SNDDigiStop(SMPINFO *PSmpInfo); +void SNDDigiStop(SmpInfo *PSmpInfo); // Start MIDI File void SNDMIDIStart(uint8 *MIDFile); diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 75adf3868a2..60af9f70166 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -35,9 +35,9 @@ namespace CGE { -bool Music = true; -FX Fx = 16; // must precede SOUND!! -SOUND Sound; +bool _music = true; +FX _fx = 16; // must precede SOUND!! +SOUND _sound; SOUND::SOUND(void) { @@ -59,7 +59,7 @@ void SOUND::Close(void) { void SOUND::Open(void) { SNDInit(); - Play(Fx[30000], 8); + Play(_fx[30000], 8); } diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 743fba0bb69..55dd1615ccb 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -39,7 +39,7 @@ namespace CGE { class SOUND { public: - SMPINFO smpinf; + SmpInfo smpinf; SOUND(void); ~SOUND(void); void Open(void); @@ -68,13 +68,13 @@ public: }; -extern bool Music; -extern SOUND Sound; -extern FX Fx; +extern bool _music; +extern SOUND _sound; +extern FX _fx; void LoadMIDI(int ref); -void KillMIDI(void); +void KillMIDI(); } // End of namespace CGE diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 83c89892cae..484d7118eff 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -251,7 +251,7 @@ extern "C" void TimerProc() { } for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { if (spr->Time) { - if (!spr->Flags.Hide) { + if (!spr->_flags.Hide) { if (-- spr->Time == 0) spr->Tick(); } @@ -326,7 +326,7 @@ void Engine_::newTimer(...) { for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { if (spr->Time) { - if (!spr->Flags.Hide) { + if (!spr->_flags.Hide) { if (--spr->Time == 0) spr->Tick(); } @@ -427,11 +427,11 @@ void Sprite::moveShapes(uint8 *buf) { bool Sprite::works(Sprite *spr) { if (spr) if (spr->_ext) { - SNAIL::COM *c = spr->_ext->_take; + Snail::Com *c = spr->_ext->_take; if (c != NULL) { c += spr->_takePtr; - if (c->Ref == _ref) - if (c->Com != SNLABEL || (c->Val == 0 || c->Val == Now)) + if (c->_ref == _ref) + if (c->_com != SNLABEL || (c->_val == 0 || c->_val == _now)) return true; } } @@ -460,7 +460,7 @@ bool Sprite::seqTest(int n) { } -SNAIL::COM *Sprite::snList(SNLIST type) { +Snail::Com *Sprite::snList(SNLIST type) { register SprExt *e = _ext; if (e) return (type == NEAR) ? e->_near : e->_take; @@ -493,7 +493,7 @@ Sprite *Sprite::expand() { if (*_file) { static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; char line[LINE_MAX], fname[MAXPATH]; - BMP_PTR *shplist = new BMP_PTR [_shpCnt + 1]; + BMP_PTR *shplist = new BMP_PTR[_shpCnt + 1]; Seq *seq = NULL; int shpcnt = 0, seqcnt = 0, @@ -502,8 +502,8 @@ Sprite *Sprite::expand() { maxnow = 0, maxnxt = 0; - SNAIL::COM *nea = NULL; - SNAIL::COM *tak = NULL; + Snail::Com *nea = NULL; + Snail::Com *tak = NULL; mergeExt(fname, _file, SPR_EXT); if (INI_FILE::exist(fname)) { // sprite description file exist INI_FILE sprf(fname); @@ -552,32 +552,32 @@ Sprite *Sprite::expand() { } case 3 : { // Near if (_nearPtr != NO_PTR) { - nea = (SNAIL::COM *) realloc(nea, (neacnt + 1) * sizeof(*nea)); + nea = (Snail::Com *) realloc(nea, (neacnt + 1) * sizeof(*nea)); if (nea == NULL) error("No core [%s]", fname); else { - SNAIL::COM *c = &nea[neacnt++]; - if ((c->Com = (SNCOM) takeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) + Snail::Com *c = &nea[neacnt++]; + if ((c->_com = (SNCOM)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) error("%s [%s]", (const char*)NumStr("Bad NEAR in ######", lcnt), (const char*)fname); - c->Ref = atoi(strtok(NULL, " \t,;/")); - c->Val = atoi(strtok(NULL, " \t,;/")); - c->Ptr = NULL; + c->_ref = atoi(strtok(NULL, " \t,;/")); + c->_val = atoi(strtok(NULL, " \t,;/")); + c->_ptr = NULL; } } } break; case 4 : { // Take if (_takePtr != NO_PTR) { - tak = (SNAIL::COM *) realloc(tak, (takcnt + 1) * sizeof(*tak)); + tak = (Snail::Com *) realloc(tak, (takcnt + 1) * sizeof(*tak)); if (tak == NULL) error("No core [%s]", fname); else { - SNAIL::COM *c = &tak[takcnt++]; - if ((c->Com = (SNCOM) takeEnum(SNAIL::ComTxt, strtok(NULL, " \t,;/"))) < 0) + Snail::Com *c = &tak[takcnt++]; + if ((c->_com = (SNCOM)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), (const char *)fname); - c->Ref = atoi(strtok(NULL, " \t,;/")); - c->Val = atoi(strtok(NULL, " \t,;/")); - c->Ptr = NULL; + c->_ref = atoi(strtok(NULL, " \t,;/")); + c->_val = atoi(strtok(NULL, " \t,;/")); + c->_ptr = NULL; } } break; @@ -601,11 +601,11 @@ Sprite *Sprite::expand() { setShapeList(shplist); //enable(); // enable interupt if (nea) - nea[neacnt - 1].Ptr = _ext->_near = nea; + nea[neacnt - 1]._ptr = _ext->_near = nea; else _nearPtr = NO_PTR; if (tak) - tak[takcnt - 1].Ptr = _ext->_take = tak; + tak[takcnt - 1]._ptr = _ext->_take = tak; else _takePtr = NO_PTR; } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 152f608c56d..8bc24bc9fb5 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -154,7 +154,7 @@ public: BMP_PTR *_shpList; Seq *_seq; char *_name; - SNAIL::COM *_near, *_take; + Snail::Com *_near, *_take; SprExt() : _x0(0), _y0(0), _x1(0), _y1(0), @@ -229,7 +229,7 @@ public: void killXlat(); void step(int nr = -1); Seq *setSeq(Seq *seq); - SNAIL::COM *snList(SNLIST type); + Snail::Com *snList(SNLIST type); virtual void touch(uint16 mask, int x, int y); virtual void tick(); private: From ada4556b9ae3b7d94ccac8ecec2ed31ba959ad55 Mon Sep 17 00:00:00 2001 From: eriktorbjorn Date: Sat, 2 Jul 2011 20:25:39 +0200 Subject: [PATCH 064/276] CGE: Simplify error() calls This also silences a few GCC warnings. --- engines/cge/cge_main.cpp | 6 +++--- engines/cge/vga13h.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 22316d79b19..31a71cc16c3 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1357,7 +1357,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int continue; if ((i = takeEnum(Comd, strtok(line, " =\t"))) < 0) - error("%s [%s]", NumStr("Bad line ######", lcnt), (const char *)fname); + error("Bad line %d [%s]", lcnt, fname); switch (i) { @@ -1365,7 +1365,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int break; case 1 : // Type if ((type = takeEnum(Type, strtok(NULL, " \t,;/"))) < 0) - error("%s [%s]", NumStr("Bad line ######", lcnt), (const char *)fname); + error("Bad line %d [%s]", lcnt, fname); break; case 2 : // Phase ++ shpcnt; @@ -1533,7 +1533,7 @@ void CGEEngine::loadScript(const char *fname) { _sprite->_flags._back = true; } if (! ok) - error("%s [%s]", NumStr("Bad INI line ######", lcnt), fname); + error("Bad INI line %d [%s]", lcnt, fname); } #define GAME_FRAME_DELAY (1000 / 50) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 484d7118eff..41d4b794699 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -558,7 +558,7 @@ Sprite *Sprite::expand() { else { Snail::Com *c = &nea[neacnt++]; if ((c->_com = (SNCOM)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) - error("%s [%s]", (const char*)NumStr("Bad NEAR in ######", lcnt), (const char*)fname); + error("Bad NEAR in %d [%s]", lcnt, fname); c->_ref = atoi(strtok(NULL, " \t,;/")); c->_val = atoi(strtok(NULL, " \t,;/")); c->_ptr = NULL; @@ -574,7 +574,7 @@ Sprite *Sprite::expand() { else { Snail::Com *c = &tak[takcnt++]; if ((c->_com = (SNCOM)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) - error("%s [%s]", NumStr("Bad NEAR in ######", lcnt), (const char *)fname); + error("Bad NEAR in %d [%s]", lcnt, fname); c->_ref = atoi(strtok(NULL, " \t,;/")); c->_val = atoi(strtok(NULL, " \t,;/")); c->_ptr = NULL; From 5f64f3ff4743b91559756a319c4a41ab36851ac1 Mon Sep 17 00:00:00 2001 From: eriktorbjorn Date: Sat, 2 Jul 2011 20:28:11 +0200 Subject: [PATCH 065/276] CGE: Removed unused NumStr() function. It was used, until my previous commit. :-) --- engines/cge/vga13h.cpp | 8 -------- engines/cge/vga13h.h | 1 - 2 files changed, 9 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 41d4b794699..a6275a39298 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -69,14 +69,6 @@ Seq _seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; extern "C" void SNDMIDIPlay(void); -char *NumStr(char *str, int num) { - char *p = strchr(str, '#'); - if (p) - wtom(num, p, 10, 5); - return str; -} - - /* static void Video() { static uint16 SP_S; diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 8bc24bc9fb5..b14edb9ba95 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -334,7 +334,6 @@ uint8 Closest(CBLK *pal, CBLK x) { #undef f } -char *NumStr(char *str, int num); //static void Video (void); uint16 *SaveScreen(void); void RestoreScreen(uint16 * &sav); From ac0caf757950b960cba058800fa42eebc7becbd8 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Jul 2011 11:43:59 +1000 Subject: [PATCH 066/276] CGE: Implemented BITMAP::Hide method --- engines/cge/vga13h.cpp | 67 ++++-------------------------------------- 1 file changed, 5 insertions(+), 62 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index a6275a39298..43de8dc9b7a 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1319,69 +1319,12 @@ void Bitmap::show(int x, int y) { void Bitmap::hide(int x, int y) { - /* - uint8 *scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; - uint16 d = FP_OFF(VGA::Page[2]) - FP_OFF(VGA::Page[1]); - HideDesc *b = B; - uint16 extra = ((x & 3) != 0); - uint16 h = H; + for (int yp = y; yp < y + _h; ++yp) { + const byte *srcP = (const byte *)VGA::Page[2]->getBasePtr(x, yp); + byte *destP = (byte *)VGA::Page[1]->getBasePtr(x, yp); - // asm push bx - asm push si - asm push ds - - asm cld - asm les di,scr - asm mov si,di - asm add si,d // take bytes from background page - asm lds bx,b - - asm mov dx,VGAGRA_ - asm mov al,0x05 // R/W mode - asm out dx,al - asm inc dx - asm in al,dx - asm and al,0xF4 - asm push ax - asm push dx - asm or al,0x01 - asm out dx,al - - asm mov dx,VGASEQ_ - asm mov ax,0x0F02 // enable all planes - asm out dx,ax - - asm mov dx,ds // save DS - - row: - // skip block - asm mov cx,[bx] - asm add si,cx - asm add di,cx - asm mov cx,[bx+2] - asm add bx,4 - asm add cx,extra - - asm push es - asm pop ds // set DS to video seg - asm rep movsb // move bytes fast - asm sub si,extra - asm sub di,extra - asm mov ds,dx // restore DS - - asm dec h - asm jnz row - - asm pop dx - asm pop ax - asm out dx,al // end of copy mode - - - asm pop ds - asm pop si - // asm pop bx - */ - warning("STUB: Bitmap::hide"); + Common::copy(srcP, srcP + _w, destP); + } } } // End of namespace CGE From bf6a5256fe325816626156703b389273e10f1ae5 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Jul 2011 12:05:58 +1000 Subject: [PATCH 067/276] CGE: Removed code for boot sector based copy protection check --- engines/cge/boot.h | 75 ---------------------------------------- engines/cge/cge_main.cpp | 38 ++------------------ engines/cge/general.cpp | 19 ---------- engines/cge/general.h | 2 -- engines/cge/ident.h | 42 ---------------------- engines/cge/startup.cpp | 3 +- 6 files changed, 5 insertions(+), 174 deletions(-) delete mode 100644 engines/cge/boot.h delete mode 100644 engines/cge/ident.h diff --git a/engines/cge/boot.h b/engines/cge/boot.h deleted file mode 100644 index 5c03a626d82..00000000000 --- a/engines/cge/boot.h +++ /dev/null @@ -1,75 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __CGE_BOOT__ -#define __CGE_BOOT__ - -#include "cge/jbw.h" - -namespace CGE { - -#define BOOTSECT_SIZ 512 -#define BOOTHEAD_SIZ 62 -#define BOOTCODE_SIZ BOOTSECT_SIZ-BOOTHEAD_SIZ -#define FreeBoot(b) free(b) - -struct Boot { - uint8 _jmp[3]; // NEAR jump machine code - char _idOEM[8]; // OEM name and version - uint16 _sectSize; // bytes per sector - uint8 _clustSize; // sectors per cluster - uint16 _resSecs; // sectors before 1st FAT - uint8 _fatCnt; // number of FATs - uint16 _rootSize; // root directory entries - uint16 _totSecs; // total sectors on disk - uint8 _media; // media descriptor byte - uint16 _fatSize; // sectors per FAT - uint16 _trkSecs; // sectors per track - uint16 _headCnt; // number of sufraces - uint16 _hidnSecs; // special hidden sectors - uint16 __; // (unknown: reserved?) - uint32 _lTotSecs; // total number of sectors - uint16 _driveNum; // physical drive number - uint8 _xSign; // extended boot signature - uint32 _serial; // volume serial number - char _label[11]; // volume label - char _fileSysID[8]; // file system ID - char _code[BOOTCODE_SIZ - 8]; // 8 = length of following - uint32 _secret; // long secret number - uint8 _bootCheck; // boot sector checksum - uint8 _bootFlags; // secret flags - uint16 _bootSig; // boot signature 0xAA55 -}; - - -Boot *readBoot(int drive); -uint8 checkBoot(Boot *boot); -bool writeBoot(int drive, Boot *boot); - -} // End of namespace CGE - -#endif diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 31a71cc16c3..9f9bebad0cd 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -27,8 +27,6 @@ #include "common/scummsys.h" #include "cge/general.h" -#include "cge/boot.h" -#include "cge/ident.h" #include "cge/sound.h" #include "cge/startup.h" #include "cge/config.h" @@ -96,33 +94,6 @@ Snail *_snail_; // 1.01 - 17VII95 - default savegame with sound ON // coditionals EVA for 2-month evaluation version -/* - char Copr[] = "Common Game Engine " - #ifdef EVA - "ú" - #else - #ifdef CD - "ù" - #else - " " - #endif - #endif - " version 1.05 [" - #if sizeof(INI_FILE) == sizeof(VFILE) - "I" - #else - "i" - #endif - #if sizeof(PIC_FILE) == sizeof(VFILE) - "B" - #else - "b" - #endif - "]\n" - "Copyright (c) 1994 by Janusz B. Wi$niewski"; -*/ -char Copr[] = "To be fixed - Copr[]"; - static char UsrFnam[15] = "\0ɱ%^þúȼ´ ÇÉ"; static int _oldLev = 0; static int _demoText = DEMO_TEXT; @@ -1793,12 +1764,9 @@ bool CGEEngine::showTitle(const char *name) { #ifdef CD STARTUP::Summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; #else -// Boot * b = ReadBoot(getdisk()); - warning("ShowTitle: FIXME ReadBoot"); - Boot *b = readBoot(0); - uint32 sn = (b->_xSign == 0x29) ? b->_serial : b->_lTotSecs; - free(b); - sn -= ((Ident *)Copr)->_disk; + // At this point the game originally read the boot sector to get + // the serial number for it's copy protection check + uint32 sn = 0; STARTUP::Summa |= Lo(sn) | Hi(sn); #endif //----------------------------------------- diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index faff3ada575..fe94bd4598b 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -25,7 +25,6 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "cge/boot.h" #include "cge/general.h" #include "cge/snddrv.h" #include "cge/wav.h" @@ -344,24 +343,6 @@ int takeEnum(const char **tab, const char *txt) { return -1; } -Boot *readBoot(int drive) { - /* - struct fatinfo fi; Boot *b; - getfat(drive+1, &fi); - if (fi.fi_sclus & 0x80) - return NULL; - if ((b = malloc(fi.fi_bysec)) == NULL) - return NULL; - // read boot sector - if (absread(drive, 1, 0L, b) == 0) - return b; - free(b); - return NULL; - */ - warning("STUB: readBoot"); - return NULL; -} - long timer(void) { /* asm mov ax,0x40 diff --git a/engines/cge/general.h b/engines/cge/general.h index fae47eed42d..63b94d3872c 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -34,7 +34,6 @@ #include "common/textconsole.h" #include "common/str.h" #include "cge/jbw.h" -#include "cge/boot.h" namespace CGE { @@ -235,7 +234,6 @@ uint16 xtow(const char *x); char *wtom(uint16 val, char *str, int radix, int len); char *dwtom(uint32 val, char * str, int radix, int len); int takeEnum(const char **tab, const char *txt); -Boot *readBoot(int drive); long timer(void); int new_random(int range); } // End of namespace CGE diff --git a/engines/cge/ident.h b/engines/cge/ident.h deleted file mode 100644 index 953f8a579d3..00000000000 --- a/engines/cge/ident.h +++ /dev/null @@ -1,42 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __CGE_IDENT__ -#define __CGE_IDENT__ - -namespace CGE { - -struct Ident { - char _copr[83]; - char _fill[8]; - unsigned long _disk; - unsigned char _cork; -}; - -} // End of namespace CGE - -#endif diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 028e4c61b1d..b024701c934 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -28,7 +28,6 @@ #include "cge/startup.h" #include "cge/text.h" #include "cge/sound.h" -#include "cge/ident.h" #include "cge/cfile.h" #include "cge/snddrv.h" #include @@ -59,6 +58,8 @@ void quit_now(int ref) { bool STARTUP::get_parms(void) { + Summa = 0; + /* int i = _argc; while (i > 1) From 334de9626ae6e6e5cd66582993fe799b329a0a50 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Jul 2011 12:30:27 +1000 Subject: [PATCH 068/276] CGE: Removed C standard library includes --- engines/cge/bitmap.cpp | 2 +- engines/cge/btfile.cpp | 1 - engines/cge/cfile.cpp | 2 -- engines/cge/cge_main.cpp | 6 ------ engines/cge/game.cpp | 1 - engines/cge/gettext.cpp | 1 - engines/cge/mixer.cpp | 1 - engines/cge/snail.cpp | 2 -- engines/cge/startup.cpp | 3 --- engines/cge/text.cpp | 3 --- engines/cge/vga13h.cpp | 4 ---- engines/cge/vga13h.h | 1 - engines/cge/vmenu.cpp | 1 - engines/cge/vol.cpp | 3 --- engines/cge/wav.h | 1 - 15 files changed, 1 insertion(+), 31 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 3bcf751b401..e4e0a37eb3e 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -471,7 +471,7 @@ bool Bitmap::loadBMP(XFile *f) { _w = hea.wid; if ((_m = farnew(byte, _h * _w)) != NULL) { int16 r = (4 - (hea.wid & 3)) % 4; - byte buf[3]; int i; + byte buf[3]; for (i = _h - 1; i >= 0; i--) { f->read(_m + (_w * i), _w); if (r && f->_error == 0) diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 18bd2d72e7c..3d0ce8a061e 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -28,7 +28,6 @@ #include "cge/btfile.h" #include "common/system.h" #include "common/str.h" -#include namespace CGE { diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index ee2aecbc42b..51e580a53be 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -26,8 +26,6 @@ */ #include "cge/cfile.h" -#include -#include #include "common/system.h" namespace CGE { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 9f9bebad0cd..b8b0a2e3cc4 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -43,10 +43,6 @@ #include "cge/mixer.h" #include "cge/cge_main.h" #include "cge/cge.h" -#include -#include -#include -#include #include "common/str.h" namespace CGE { @@ -1766,8 +1762,6 @@ bool CGEEngine::showTitle(const char *name) { #else // At this point the game originally read the boot sector to get // the serial number for it's copy protection check - uint32 sn = 0; - STARTUP::Summa |= Lo(sn) | Hi(sn); #endif //----------------------------------------- movie("X00"); // paylist diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 72233f746a4..3acafd80e75 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -27,7 +27,6 @@ #include "cge/game.h" #include "cge/events.h" -#include namespace CGE { diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 9a6c1539d17..c48b281771f 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -28,7 +28,6 @@ #include "cge/gettext.h" #include "cge/events.h" #include "cge/cge_main.h" -#include namespace CGE { diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 18bbfb65b51..e3fd2c07edd 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -31,7 +31,6 @@ #include "cge/events.h" #include "cge/snddrv.h" #include "cge/cge_main.h" -#include namespace CGE { diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index fbde5bd846e..308ffb231cc 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -32,8 +32,6 @@ #include "cge/bitmaps.h" #include "cge/text.h" #include "cge/cge_main.h" -#include -#include #include "cge/events.h" namespace CGE { diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index b024701c934..39a2b66e4bd 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -30,9 +30,6 @@ #include "cge/sound.h" #include "cge/cfile.h" #include "cge/snddrv.h" -#include -#include -#include namespace CGE { diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index f98b7f5d1ce..85ef17f4cf4 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -33,9 +33,6 @@ #include "cge/game.h" #include "cge/snail.h" #include "cge/cge_main.h" -#include -#include -#include namespace CGE { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 43de8dc9b7a..dc11ffbf6ac 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -33,10 +33,6 @@ #include "cge/vol.h" #include "cge/text.h" #include "cge/cge_main.h" -#include -#include -#include -#include #include "cge/cge.h" namespace CGE { diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index b14edb9ba95..a063e405083 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -30,7 +30,6 @@ #include "graphics/surface.h" #include "cge/general.h" -#include #include "cge/bitmap.h" #include "cge/snail.h" #include "cge/cge.h" diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index d999dfa7607..8ad3848cdbc 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -28,7 +28,6 @@ #include "cge/vmenu.h" #include "cge/events.h" #include "cge/cge_main.h" -#include namespace CGE { diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 5f8573706ba..332ae869c89 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -28,9 +28,6 @@ #include "cge/vol.h" #include "common/system.h" #include "common/str.h" -#include -#include -#include namespace CGE { diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 57187f7b87d..062f83dfcaa 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -29,7 +29,6 @@ #define __CGE_WAV__ #include "cge/general.h" -#include namespace CGE { From 156c2d020fca74bb901e547a04ae2a9e2f8ec8cc Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Jul 2011 14:55:49 +1000 Subject: [PATCH 069/276] CGE: Fix GCC compiler warnings --- engines/cge/cge_main.cpp | 2 +- engines/cge/config.cpp | 2 +- engines/cge/events.cpp | 4 ++++ engines/cge/vga13h.cpp | 12 ++++++------ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index b8b0a2e3cc4..5f27f99c3cf 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -53,7 +53,7 @@ namespace CGE { #define SVG0NAME ("{{INIT}}" SVG_EXT) #define SVG0FILE INI_FILE -extern uint16 _stklen = (STACK_SIZ * 2); +uint16 _stklen = (STACK_SIZ * 2); VGA *Vga; Heart *_heart; diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 4f5284b69b4..9a8219dd6bc 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -148,7 +148,7 @@ void CGEEngine::selectSound() { SNPOST_(SNKILL, -1, 0, VMENU::Addr); inf(Text->getText(STYPE_TEXT)); Talk->gotoxy(Talk->_x, FONT_HIG / 2); - for (i = 0; i < ArrayCount(DevName); i++) + for (i = 0; i < (int)ArrayCount(DevName); i++) DevMenu[i].Text = Text->getText(DevName[i]); (new VMENU(this, DevMenu, SCR_WID / 2, Talk->_y + Talk->_h + TEXT_VM + FONT_HIG))->setName(Text->getText(MENU_TEXT)); } diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 2b9cc7fc6c4..e18890625f3 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -222,6 +222,8 @@ void MOUSE::NewMouse(Common::Event &event) { evt._msk = R_UP; Buttons &= ~2; break; + default: + break; } } @@ -253,6 +255,8 @@ void EventManager::poll() { _mouse->NewMouse(_event); handleEvents(); break; + default: + break; } } } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index dc11ffbf6ac..b4e9bff2863 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -343,13 +343,13 @@ void Heart::setXTimer(uint16 *ptr, uint16 time) { } -Sprite::Sprite(CGEEngine *vm, BMP_PTR *shp) +Sprite::Sprite(CGEEngine *vm, BMP_PTR *shpP) : _x(0), _y(0), _z(0), _nearPtr(0), _takePtr(0), _next(NULL), _prev(NULL), _seqPtr(NO_SEQ), _time(0), //Delay(0), _ext(NULL), _ref(-1), _cave(0), _vm(vm) { memset(_file, 0, sizeof(_file)); *((uint16 *)&_flags) = 0; - setShapeList(shp); + setShapeList(shpP); } @@ -378,16 +378,16 @@ BMP_PTR Sprite::shp() { } -BMP_PTR *Sprite::setShapeList(BMP_PTR *shp) { +BMP_PTR *Sprite::setShapeList(BMP_PTR *shpP) { BMP_PTR *r = (_ext) ? _ext->_shpList : NULL; _shpCnt = 0; _w = 0; _h = 0; - if (shp) { + if (shpP) { BMP_PTR *p; - for (p = shp; *p; p++) { + for (p = shpP; *p; p++) { BMP_PTR b = (*p); // ->Code(); if (b->_w > _w) _w = b->_w; @@ -396,7 +396,7 @@ BMP_PTR *Sprite::setShapeList(BMP_PTR *shp) { _shpCnt++; } expand(); - _ext->_shpList = shp; + _ext->_shpList = shpP; if (!_ext->_seq) setSeq((_shpCnt < 2) ? _seq1 : _seq2); } From 900e8cbf5b95ceea36c44296bc0de12e32687745 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Jul 2011 15:32:27 +1000 Subject: [PATCH 070/276] CGE: Fixed GCC compiler warnings --- engines/cge/bitmap.cpp | 13 +++++++++++-- engines/cge/text.cpp | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index e4e0a37eb3e..c94b8503cfc 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -102,9 +102,18 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) *(uint16 *) v = CPY | dsiz; // data chunk hader memset(v + 2, fill, dsiz); // data bytes *(uint16 *)(v + lsiz - 2) = SKP | ((SCR_WID / 4) - dsiz); // gap - memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines + + // Replicate lines + byte *destP; + for (destP = v + lsiz; destP < (v + psiz); destP += lsiz) + Common::copy(v, v + lsiz, destP); + *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 - memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes + + // Repliccate planes + for (destP = v + psiz; destP < (v + 4 * psiz); destP += psiz) + Common::copy(v, v + psiz, destP); + HideDesc *b = (HideDesc *)(v + 4 * psiz); b->skip = (SCR_WID - _w) >> 2; b->hide = _w >> 2; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 85ef17f4cf4..e17688c6eee 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -63,7 +63,7 @@ void TEXT::Clear(int from, int upto) { for (p = Cache, q = p + Size; p < q; p++) { if (p->Ref && p->Ref >= from && p->Ref < upto) { p->Ref = 0; - delete p->Txt; + delete[] p->Txt; p->Txt = NULL; } } From d53142d95e793861d2891f8a7d16ac11b9b94126 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Jul 2011 15:41:07 +1000 Subject: [PATCH 071/276] CGE: Fixed code using memory overruns to do duplication --- engines/cge/bitmap.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index c94b8503cfc..833d0f1f1bd 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -117,6 +117,11 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) HideDesc *b = (HideDesc *)(v + 4 * psiz); b->skip = (SCR_WID - _w) >> 2; b->hide = _w >> 2; + + // Replicate across the entire table + for (HideDesc *hdP = b + 1; hdP < (b + _h); ++hdP) + *hdP = *b; + memcpy(b + 1, b, (_h - 1) * sizeof(*b)); // tricky fill entire table b->skip = 0; // fix the first entry _v = v; From dff8bd5474905c924f4039ab079c20b3f145b364 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Jul 2011 17:14:47 +1000 Subject: [PATCH 072/276] CGE: Fix some memory leaks --- engines/cge/bitmap.cpp | 1 - engines/cge/cge.cpp | 2 +- engines/cge/vga13h.cpp | 11 ++++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 833d0f1f1bd..d0c7ba6ab5a 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -122,7 +122,6 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) for (HideDesc *hdP = b + 1; hdP < (b + _h); ++hdP) *hdP = *b; - memcpy(b + 1, b, (_h - 1) * sizeof(*b)); // tricky fill entire table b->skip = 0; // fix the first entry _v = v; _b = b; diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 4af10b2b8df..89d5c0a86e6 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -117,7 +117,7 @@ CGEEngine::~CGEEngine() { // Remove all of our debug levels here DebugMan.clearAllDebugChannels(); - _console = new CGEConsole(this); + delete _console; // Delete engine objects delete _sprite; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index b4e9bff2863..35d9688bd36 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -912,8 +912,10 @@ void VGA::init() { } void VGA::deinit() { - for (int idx = 0; idx < 4; ++idx) + for (int idx = 0; idx < 4; ++idx) { + Page[idx]->free(); delete Page[idx]; + } delete[] SysPal; } @@ -931,7 +933,7 @@ VGA::VGA(int mode) for (i = 10; i < 20; i++) { char *txt = Text->getText(i); if (txt) { - warning("%s", txt); + debugN("%s", txt); std = false; } } @@ -976,8 +978,11 @@ VGA::~VGA(void) { if (Nam) buffer = buffer + " [" + Nam + "]"; - warning("%s", buffer.c_str()); + debugN("%s", buffer.c_str()); } + + delete ShowQ; + delete SpareQ; } From 4116189395a87959f1981ca7ebae0604aa4ca9a4 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 3 Jul 2011 11:28:22 +0200 Subject: [PATCH 073/276] CGE: Some more renaming (WIP) --- engines/cge/cge.cpp | 18 +-- engines/cge/cge_main.cpp | 309 ++++++++++++++++++++------------------- engines/cge/cge_main.h | 6 +- engines/cge/config.cpp | 60 ++++---- engines/cge/events.cpp | 2 +- engines/cge/events.h | 2 +- engines/cge/general.cpp | 18 +-- engines/cge/gettext.cpp | 16 +- engines/cge/gettext.h | 2 +- engines/cge/mixer.cpp | 30 ++-- engines/cge/snail.cpp | 72 ++++----- engines/cge/snddrv.h | 58 ++++---- engines/cge/sound.cpp | 22 +-- engines/cge/startup.cpp | 41 +++--- engines/cge/startup.h | 18 +-- engines/cge/talk.cpp | 144 +++++++++--------- engines/cge/talk.h | 56 +++---- engines/cge/text.cpp | 162 ++++++++++---------- engines/cge/text.h | 42 +++--- engines/cge/vga13h.cpp | 136 ++++++++--------- engines/cge/vga13h.h | 73 ++++----- engines/cge/vmenu.cpp | 12 +- engines/cge/vmenu.h | 4 +- 23 files changed, 653 insertions(+), 650 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 89d5c0a86e6..6eae8f3c0e8 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -61,10 +61,10 @@ void CGEEngine::setup() { VGA::init(); VFILE::init(); Bitmap::init(); - TALK::init(); + Talk::init(); // Initialise engine objects - Text = new TEXT(this, progName(), 128); + _text = new Text(this, progName(), 128); Vga = new VGA(M13H); _heart = new Heart; Hero = new WALK(this, NULL); @@ -76,9 +76,9 @@ void CGEEngine::setup() { _miniCave = new Sprite(this, NULL); _shadow = new Sprite(this, NULL); _horzLine = new Sprite(this, HL); - InfoLine = new INFO_LINE(this, INFO_W); + _infoLine = new InfoLine(this, INFO_W); _cavLight = new Sprite(this, PR); - DebugLine = new INFO_LINE(this, SCR_WID); + _debugLine = new InfoLine(this, SCR_WID); MB[0] = new Bitmap("BRICK", true); MB[1] = NULL; HL[0] = new Bitmap("HLINE", true); @@ -102,14 +102,14 @@ void CGEEngine::setup() { _mouse = new MOUSE(this); _keyboard = new Keyboard(); _eventManager = new EventManager(); - OffUseCount = atoi(Text->getText(OFF_USE_COUNT)); + _offUseCount = atoi(_text->getText(OFF_USE_COUNT)); } CGEEngine::~CGEEngine() { debug("CGEEngine::~CGEEngine"); // Call classes with static members to clear them up - TALK::deinit(); + Talk::deinit(); Bitmap::deinit(); VFILE::deinit(); VGA::deinit(); @@ -124,9 +124,9 @@ CGEEngine::~CGEEngine() { delete _miniCave; delete _shadow; delete _horzLine; - delete InfoLine; + delete _infoLine; delete _cavLight; - delete DebugLine; + delete _debugLine; delete MB[0]; delete HL[0]; delete MC[0]; @@ -138,7 +138,7 @@ CGEEngine::~CGEEngine() { delete LI[1]; delete LI[2]; delete LI[3]; - delete Text; + delete _text; delete _heart; delete _pocLight; delete _keyboard; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 5f27f99c3cf..33abf7917d1 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -68,9 +68,9 @@ Sprite *_sprite; Sprite *_miniCave; Sprite *_shadow; Sprite *_horzLine; -INFO_LINE *InfoLine; +InfoLine *_infoLine; Sprite *_cavLight; -INFO_LINE *DebugLine; +InfoLine *_debugLine; BMP_PTR MB[2]; BMP_PTR HL[2]; @@ -90,24 +90,24 @@ Snail *_snail_; // 1.01 - 17VII95 - default savegame with sound ON // coditionals EVA for 2-month evaluation version -static char UsrFnam[15] = "\0ɱ%^þúȼ´ ÇÉ"; +static char _usrFnam[15] = "\0ɱ%^þúȼ´ ÇÉ"; static int _oldLev = 0; static int _demoText = DEMO_TEXT; //-------------------------------------------------------------------------- -bool JBW = false; +bool _jbw = false; //------------------------------------------------------------------------- -int PocPtr = 0; +int _pocPtr = 0; -static EMS *Mini = MiniEmm.alloc((uint16)MINI_EMM_SIZE); -static BMP_PTR *MiniShpList = NULL; -static BMP_PTR MiniShp[] = { NULL, NULL }; -static bool Finis = false; -static int Startup = 1; -int OffUseCount; -uint16 *intStackPtr = false; +static EMS *_mini = _miniEmm.alloc((uint16)MINI_EMM_SIZE); +static BMP_PTR *_miniShpList = NULL; +static BMP_PTR _miniShp[] = { NULL, NULL }; +static bool _finis = false; +static int _startup = 1; +int _offUseCount; +uint16 *_intStackPtr = false; Hxy _heroXY[CAVE_MAX] = {{0, 0}}; Bar _barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; @@ -119,7 +119,7 @@ void feedSnail(Sprite *spr, SNLIST snq); // defined in SNAIL uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; -uint8 &Cluster::cell(void) { +uint8 &Cluster::cell() { return _map[_b][_a]; } @@ -227,15 +227,15 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { file.read((uint8 *) &i, sizeof(i)); if (i != SVGCHKSUM) - error("%s", Text->getText(BADSVG_TEXT)); + error("%s", _text->getText(BADSVG_TEXT)); - if (STARTUP::Core < CORE_HIG) + if (Startup::_core < CORE_HIG) _music = false; - if (STARTUP::SoundOk == 1 && STARTUP::Mode == 0) { - SNDDrvInfo.VOL2.D = _volume[0]; - SNDDrvInfo.VOL2.M = _volume[1]; - SNDSetVolume(); + if (Startup::_soundOk == 1 && Startup::_mode == 0) { + _sndDrvInfo.Vol2._d = _volume[0]; + _sndDrvInfo.Vol2._m = _volume[1]; + sndSetVolume(); } if (! tiny) { // load sprites & pocket @@ -252,21 +252,21 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { if (spr == NULL) error("No core"); *spr = S; - Vga->SpareQ->Append(spr); + Vga->_spareQ->append(spr); } for (i = 0; i < POCKET_NX; i++) { register int r = _pocref[i]; - _pocket[i] = (r < 0) ? NULL : Vga->SpareQ->Locate(r); + _pocket[i] = (r < 0) ? NULL : Vga->_spareQ->locate(r); } } } static void SaveSound(void) { - CFile cfg(UsrPath(progName(CFG_EXT)), WRI); + CFile cfg(usrPath(progName(CFG_EXT)), WRI); if (!cfg._error) - cfg.write(&SNDDrvInfo, sizeof(SNDDrvInfo) - sizeof(SNDDrvInfo.VOL2)); + cfg.write(&_sndDrvInfo, sizeof(_sndDrvInfo) - sizeof(_sndDrvInfo.Vol2)); } @@ -280,8 +280,8 @@ static void SaveGame(XFile &file) { _pocref[i] = (s) ? s->_ref : -1; } - _volume[0] = SNDDrvInfo.VOL2.D; - _volume[1] = SNDDrvInfo.VOL2.M; + _volume[0] = _sndDrvInfo.Vol2._d; + _volume[1] = _sndDrvInfo.Vol2._m; for (st = _savTab; st->Ptr; st++) { if (file._error) @@ -291,7 +291,7 @@ static void SaveGame(XFile &file) { file.write((uint8 *) & (i = SVGCHKSUM), sizeof(i)); - for (spr = Vga->SpareQ->First(); spr; spr = spr->_next) + for (spr = Vga->_spareQ->first(); spr; spr = spr->_next) if (spr->_ref >= 1000) if (!file._error) file.write((uint8 *)spr, sizeof(*spr)); @@ -303,7 +303,7 @@ static void HeroCover(int cvr) { } -static void Trouble(int seq, int txt) { +static void trouble(int seq, int txt) { Hero->park(); SNPOST(SNWAIT, -1, -1, Hero); SNPOST(SNSEQ, -1, seq, Hero); @@ -313,23 +313,23 @@ static void Trouble(int seq, int txt) { } -static void OffUse(void) { - Trouble(OFF_USE, OFF_USE_TEXT + new_random(OffUseCount)); +static void offUse() { + trouble(OFF_USE, OFF_USE_TEXT + new_random(_offUseCount)); } -static void TooFar(void) { - Trouble(TOO_FAR, TOO_FAR_TEXT); +static void tooFar() { + trouble(TOO_FAR, TOO_FAR_TEXT); } // Used in stubbed function, do not remove! static void noWay() { - Trouble(NO_WAY, NO_WAY_TEXT); + trouble(NO_WAY, NO_WAY_TEXT); } -static void LoadHeroXY(void) { +static void loadHeroXY() { INI_FILE cf(progName(".HXY")); memset(_heroXY, 0, sizeof(_heroXY)); if (!cf._error) @@ -337,7 +337,7 @@ static void LoadHeroXY(void) { } -static void LoadMapping(void) { +static void loadMapping() { if (_now <= CAVE_MAX) { INI_FILE cf(progName(".TAB")); if (!cf._error) { @@ -367,7 +367,7 @@ void WALK::tick() { if (Dir != NO_DIR) { Sprite *spr; Sys->FunTouch(); - for (spr = Vga->ShowQ->First(); spr; spr = spr->_next) { + for (spr = Vga->_showQ->first(); spr; spr = spr->_next) { if (distance(spr) < 2) { if (!spr->_flags._near) { feedSnail(spr, NEAR); @@ -548,7 +548,7 @@ void CGEEngine::setMapBrick(int x, int z) { wtom(z, n + 3, 10, 2); Cluster::_map[z][x] = 1; s->setName(n); - Vga->ShowQ->Insert(s, Vga->ShowQ->First()); + Vga->_showQ->insert(s, Vga->_showQ->first()); } } @@ -584,9 +584,9 @@ void CGEEngine::quit() { SNPOST_(SNKILL, -1, 0, VMENU::Addr); resetQSwitch(); } else { - QuitMenu[0].Text = Text->getText(QUIT_TEXT); - QuitMenu[1].Text = Text->getText(NOQUIT_TEXT); - (new VMENU(this, QuitMenu, -1, -1))->setName(Text->getText(QUIT_TITLE)); + QuitMenu[0].Text = _text->getText(QUIT_TEXT); + QuitMenu[1].Text = _text->getText(NOQUIT_TEXT); + (new VMENU(this, QuitMenu, -1, -1))->setName(_text->getText(QUIT_TITLE)); SNPOST_(SNSEQ, 123, 1, NULL); KeyClick(); } @@ -594,7 +594,7 @@ void CGEEngine::quit() { } -static void AltCtrlDel(void) { +static void AltCtrlDel() { SNPOST_(SNSAY, -1, A_C_D_TEXT, Hero); } @@ -603,8 +603,8 @@ static void miniStep(int stp) { if (stp < 0) _miniCave->_flags._hide = true; else { - &*Mini; - *MiniShp[0] = *MiniShpList[stp]; + &*_mini; + *_miniShp[0] = *_miniShpList[stp]; if (_fx.Current) &*(_fx.Current->EAddr()); @@ -633,13 +633,13 @@ void SYSTEM::SetPal(void) { void SYSTEM::FunTouch(void) { uint16 n = (PAIN) ? HEROFUN1 : HEROFUN0; - if (Talk == NULL || n > FunDel) + if (_talk == NULL || n > FunDel) FunDel = n; } static void ShowBak(int ref) { - Sprite *spr = Vga->SpareQ->Locate(ref); + Sprite *spr = Vga->_spareQ->locate(ref); if (spr) { Bitmap::_pal = VGA::SysPal; spr->expand(); @@ -658,9 +658,9 @@ static void caveUp() { LoadMIDI(_now); ShowBak(BakRef); - LoadMapping(); - Text->Preload(BakRef, BakRef + 1000); - Sprite *spr = Vga->SpareQ->First(); + loadMapping(); + _text->preload(BakRef, BakRef + 1000); + Sprite *spr = Vga->_spareQ->first(); while (spr) { Sprite *n = spr->_next; if (spr->_cave == _now || spr->_cave == 0) @@ -672,7 +672,7 @@ static void caveUp() { } spr = n; } - if (SNDDrvInfo.DDEV) { + if (_sndDrvInfo._dDev) { _sound.Stop(); _fx.Clear(); _fx.Preload(0); @@ -693,21 +693,21 @@ static void caveUp() { Vga->CopyPage(0, 1); selectPocket(-1); if (Hero) - Vga->ShowQ->Insert(Vga->ShowQ->Remove(Hero)); + Vga->_showQ->insert(Vga->_showQ->remove(Hero)); if (_shadow) { - Vga->ShowQ->Remove(_shadow); + Vga->_showQ->remove(_shadow); _shadow->makeXlat(glass(VGA::SysPal, 204, 204, 204)); - Vga->ShowQ->Insert(_shadow, Hero); + Vga->_showQ->insert(_shadow, Hero); _shadow->_z = Hero->_z; } - feedSnail(Vga->ShowQ->Locate(BakRef + 999), TAKE); + feedSnail(Vga->_showQ->locate(BakRef + 999), TAKE); Vga->Show(); Vga->CopyPage(1, 0); Vga->Show(); Vga->Sunrise(VGA::SysPal); _dark = false; - if (! Startup) + if (!_startup) _mouse->On(); _heart->_enable = true; @@ -719,16 +719,16 @@ void CGEEngine::caveDown() { if (!_horzLine->_flags._hide) switchMapping(); - for (spr = Vga->ShowQ->First(); spr;) { + for (spr = Vga->_showQ->first(); spr;) { Sprite *n = spr->_next; if (spr->_ref >= 1000 /*&& spr->_cave*/) { if (spr->_ref % 1000 == 999) feedSnail(spr, TAKE); - Vga->SpareQ->Append(Vga->ShowQ->Remove(spr)); + Vga->_spareQ->append(Vga->_showQ->remove(spr)); } spr = n; } - Text->Clear(1000); + _text->clear(1000); } @@ -742,10 +742,10 @@ void CGEEngine::qGame() { caveDown(); _oldLev = _lev; SaveSound(); - CFile file = CFile(UsrPath(UsrFnam), WRI, RCrypt); + CFile file = CFile(usrPath(_usrFnam), WRI, RCrypt); SaveGame(file); Vga->Sunset(); - Finis = true; + _finis = true; } @@ -765,13 +765,13 @@ void CGEEngine::switchCave(int cav) { Hero->step(0); if (!_isDemo) ///// protection: auto-destruction on! ---------------------- - Vga->SpareQ->Show = STARTUP::Summa * (cav <= CAVE_MAX); + Vga->_spareQ->_show = Startup::_summa * (cav <= CAVE_MAX); /////-------------------------------------------------------- } _cavLight->gotoxy(CAVE_X + ((_now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((_now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); - KillText(); - if (! Startup) + killText(); + if (!_startup) KeyClick(); SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint //TODO Change the SNPOST message send to a special way to send function pointer @@ -795,8 +795,8 @@ void SYSTEM::touch(uint16 mask, int x, int y) { if (mask & KEYB) { int pp0; KeyClick(); - KillText(); - if (Startup == 1) { + killText(); + if (_startup == 1) { SNPOST(SNCLEAR, -1, 0, NULL); return; } @@ -810,7 +810,7 @@ void SYSTEM::touch(uint16 mask, int x, int y) { break; case 'F': if (_keyboard->_key[ALT]) { - Sprite *m = Vga->ShowQ->Locate(17001); + Sprite *m = Vga->_showQ->locate(17001); if (m) { m->step(1); m->_time = 216; // 3s @@ -858,7 +858,7 @@ void SYSTEM::touch(uint16 mask, int x, int y) { break; case 'X': if (_keyboard->_key[ALT]) - Finis = true; + _finis = true; break; case '0': case '1': @@ -891,16 +891,16 @@ void SYSTEM::touch(uint16 mask, int x, int y) { break; case 'W': if (pp == 2) - JBW = !JBW; + _jbw = !_jbw; break; } if (pp == pp0) pp = 0; } else { - if (Startup) + if (_startup) return; int cav = 0; - InfoLine->Update(NULL); + _infoLine->update(NULL); if (y >= WORLD_HIG) { if (x < BUTTON_X) { // select cave? if (y >= CAVE_Y && y < CAVE_Y + CAVE_NY * CAVE_DY && @@ -935,7 +935,7 @@ void SYSTEM::touch(uint16 mask, int x, int y) { } } else { - if (! Talk && _snail->idle() && Hero + if (!_talk && _snail->idle() && Hero && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && !_game) { Hero->findWay(XZ(x, y)); } @@ -946,12 +946,13 @@ void SYSTEM::touch(uint16 mask, int x, int y) { void SYSTEM::Tick(void) { - if (! Startup) if (-- FunDel == 0) { - KillText(); + if (!_startup) + if (--FunDel == 0) { + killText(); if (_snail->idle()) { if (PAIN) HeroCover(9); - else if (STARTUP::Core >= CORE_MID) { + else if (Startup::_core >= CORE_MID) { int n = new_random(100); if (n > 96) HeroCover(6 + (Hero->_x + Hero->_w / 2 < SCR_WID / 2)); @@ -1011,7 +1012,7 @@ static void SwitchMusic(void) { warning("SwitchMusic() - SNPOST"); } } else { - if (STARTUP::Core < CORE_HIG) + if (Startup::_core < CORE_HIG) SNPOST(SNINF, -1, NOMUSIC_TEXT, NULL); else { SNPOST_(SNSEQ, 122, (_music = !_music), NULL); @@ -1035,13 +1036,13 @@ void CGEEngine::takeName() { if (GetText::_ptr) SNPOST_(SNKILL, -1, 0, GetText::_ptr); else { - GetText *tn = new GetText(this, Text->getText(GETNAME_PROMPT), UsrFnam, 8, KeyClick); + GetText *tn = new GetText(this, _text->getText(GETNAME_PROMPT), _usrFnam, 8, KeyClick); if (tn) { - tn->setName(Text->getText(GETNAME_TITLE)); + tn->setName(_text->getText(GETNAME_TITLE)); tn->center(); tn->gotoxy(tn->_x, tn->_y - 10); tn->_z = 126; - Vga->ShowQ->Insert(tn); + Vga->_showQ->insert(tn); } } } @@ -1059,7 +1060,7 @@ void CGEEngine::switchMapping() { } } else { Sprite *s; - for (s = Vga->ShowQ->First(); s; s = s->_next) + for (s = Vga->_showQ->first(); s; s = s->_next) if (s->_w == MAP_XGRID && s->_h == MAP_ZGRID) SNPOST_(SNKILL, -1, 0, s); } @@ -1078,7 +1079,7 @@ static void KillSprite(void) { static void PushSprite(void) { Sprite *spr = _sprite->_prev; if (spr) { - Vga->ShowQ->Insert(Vga->ShowQ->Remove(_sprite), spr); + Vga->_showQ->insert(Vga->_showQ->remove(_sprite), spr); while (_sprite->_z > _sprite->_next->_z) _sprite->_z--; } else @@ -1095,7 +1096,7 @@ static void PullSprite(void) { ok = (!spr->_flags._slav); } if (ok) { - Vga->ShowQ->Insert(Vga->ShowQ->Remove(_sprite), spr); + Vga->_showQ->insert(Vga->_showQ->remove(_sprite), spr); if (_sprite->_prev) while (_sprite->_z < _sprite->_prev->_z) _sprite->_z++; @@ -1148,8 +1149,8 @@ static char DebugText[] = " N=00000 F=000000 X=000 Y=000 FPS=0000\0S=00:00 0 #define SP_F (DebugText + 67) #define SP__ (DebugText + 70) -static void SayDebug(void) { - if (!DebugLine->_flags._hide) { +static void sayDebug() { + if (!_debugLine->_flags._hide) { static long t = -1L; long t1 = timer(); @@ -1169,7 +1170,7 @@ static void SayDebug(void) { // sprite queue size uint16 n = 0; Sprite *spr; - for (spr = Vga->ShowQ->First(); spr; spr = spr->_next) { + for (spr = Vga->_showQ->first(); spr; spr = spr->_next) { ++ n; if (spr == _sprite) { *XSPR = ' '; @@ -1184,13 +1185,13 @@ static void SayDebug(void) { } dwtom(n, SP_S, 10, 2); // *SP__ = (heapcheck() < 0) ? '!' : ' '; - DebugLine->Update(DebugText); + _debugLine->update(DebugText); } } static void SwitchDebug(void) { - DebugLine->_flags._hide = ! DebugLine->_flags._hide; + _debugLine->_flags._hide = !_debugLine->_flags._hide; } @@ -1221,7 +1222,7 @@ void CGEEngine::optionTouch(int opt, uint16 mask) { void Sprite::touch(uint16 mask, int x, int y) { Sys->FunTouch(); if ((mask & ATTN) == 0) { - InfoLine->Update(name()); + _infoLine->update(name()); if (mask & (R_DN | L_DN)) _sprite = this; if (_ref / 10 == 12) { @@ -1235,16 +1236,16 @@ void Sprite::touch(uint16 mask, int x, int y) { mask |= R_UP; } if ((mask & R_UP) && _snail->idle()) { - Sprite *ps = (_pocLight->_seqPtr) ? _pocket[PocPtr] : NULL; + Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_pocPtr] : NULL; if (ps) { if (_flags._kept || Hero->distance(this) < MAX_DISTANCE) { if (works(ps)) { feedSnail(ps, TAKE); } else - OffUse(); + offUse(); selectPocket(-1); } else - TooFar(); + tooFar(); } else { if (_flags._kept) mask |= L_UP; @@ -1262,15 +1263,15 @@ void Sprite::touch(uint16 mask, int x, int y) { } else { if (_takePtr != NO_PTR) { if (snList(TAKE)[_takePtr]._com == SNNEXT) - OffUse(); + offUse(); else feedSnail(this, TAKE); } else - OffUse(); + offUse(); } }/// else - TooFar(); + tooFar(); } } } @@ -1439,7 +1440,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int *p = '\0'; _sprite->_shpCnt = shpcnt; - Vga->SpareQ->Append(_sprite); + Vga->_spareQ->append(_sprite); } } @@ -1506,16 +1507,16 @@ void CGEEngine::loadScript(const char *fname) { #define GAME_FRAME_DELAY (1000 / 50) void CGEEngine::mainLoop() { - SayDebug(); + sayDebug(); if (_isDemo) { // static uint32 tc = 0; - if (/* FIXME: TimerCount - tc >= ((182L * 6L) * 5L) && */ Talk == NULL && _snail->idle()) { - if (Text->getText(_demoText)) { + if (/* FIXME: TimerCount - tc >= ((182L * 6L) * 5L) && */ _talk == NULL && _snail->idle()) { + if (_text->getText(_demoText)) { SNPOST(SNSOUND, -1, 4, NULL); // drumla SNPOST(SNINF, -1, _demoText, NULL); SNPOST(SNLABEL, -1, -1, NULL); - if (Text->getText(++_demoText) == NULL) + if (_text->getText(++_demoText) == NULL) _demoText = DEMO_TEXT + 1; } //FIXME: tc = TimerCount; @@ -1541,11 +1542,11 @@ void CGEEngine::mainLoop() { void CGEEngine::loadUser() { // set scene - if (STARTUP::Mode == 0) { // user .SVG file found - CFile cfile = CFile(UsrPath(UsrFnam), REA, RCrypt); + if (Startup::_mode == 0) { // user .SVG file found + CFile cfile = CFile(usrPath(_usrFnam), REA, RCrypt); loadGame(cfile); } else { - if (STARTUP::Mode == 1) { + if (Startup::_mode == 1) { SVG0FILE file = SVG0FILE(SVG0NAME); loadGame(file); } else { @@ -1564,12 +1565,12 @@ void CGEEngine::runGame() { if (_eventManager->_quitFlag) return; - Text->Clear(); - Text->Preload(100, 1000); - LoadHeroXY(); + _text->clear(); + _text->preload(100, 1000); + loadHeroXY(); _cavLight->_flags._tran = true; - Vga->ShowQ->Append(_cavLight); + Vga->_showQ->append(_cavLight); _cavLight->_flags._hide = true; static Seq pocSeq[] = { { 0, 0, 0, 0, 20 }, @@ -1584,7 +1585,7 @@ void CGEEngine::runGame() { _pocLight->_flags._tran = true; _pocLight->_time = 1; _pocLight->_z = 120; - Vga->ShowQ->Append(_pocLight); + Vga->_showQ->append(_pocLight); selectPocket(-1); // FIXME: Allow ScummVM to handle mouse display @@ -1594,24 +1595,24 @@ void CGEEngine::runGame() { loadUser(); // ~~~~~~~~~~~ - if ((_sprite = Vga->SpareQ->Locate(121)) != NULL) + if ((_sprite = Vga->_spareQ->locate(121)) != NULL) SNPOST_(SNSEQ, -1, Vga->Mono, _sprite); - if ((_sprite = Vga->SpareQ->Locate(122)) != NULL) + if ((_sprite = Vga->_spareQ->locate(122)) != NULL) _sprite->step(_music); SNPOST_(SNSEQ, -1, _music, _sprite); if (!_music) KillMIDI(); - if (Mini && INI_FILE::exist("MINI.SPR")) { - uint8 *ptr = (uint8 *) &*Mini; + if (_mini && INI_FILE::exist("MINI.SPR")) { + uint8 *ptr = (uint8 *) &*_mini; if (ptr != NULL) { loadSprite("MINI", -1, 0, MINI_X, MINI_Y); ExpandSprite(_miniCave = _sprite); // NULL is ok if (_miniCave) { _miniCave->_flags._hide = true; _miniCave->moveShapes(ptr); - MiniShp[0] = new Bitmap(*_miniCave->shp()); - MiniShpList = _miniCave->setShapeList(MiniShp); + _miniShp[0] = new Bitmap(*_miniCave->shp()); + _miniShpList = _miniCave->setShapeList(_miniShp); PostMiniStep(-1); } } @@ -1626,28 +1627,28 @@ void CGEEngine::runGame() { _shadow->_ref = 2; _shadow->_flags._tran = true; Hero->_flags._shad = true; - Vga->ShowQ->Insert(Vga->SpareQ->Remove(_shadow), Hero); + Vga->_showQ->insert(Vga->_spareQ->remove(_shadow), Hero); } } } - InfoLine->gotoxy(INFO_X, INFO_Y); - InfoLine->_flags._tran = true; - InfoLine->Update(NULL); - Vga->ShowQ->Insert(InfoLine); + _infoLine->gotoxy(INFO_X, INFO_Y); + _infoLine->_flags._tran = true; + _infoLine->update(NULL); + Vga->_showQ->insert(_infoLine); - DebugLine->_z = 126; - Vga->ShowQ->Insert(DebugLine); + _debugLine->_z = 126; + Vga->_showQ->insert(_debugLine); _horzLine->_y = MAP_TOP - (MAP_TOP > 0); _horzLine->_z = 126; - Vga->ShowQ->Insert(_horzLine); + Vga->_showQ->insert(_horzLine); - _mouse->Busy = Vga->SpareQ->Locate(BUSY_REF); + _mouse->Busy = Vga->_spareQ->locate(BUSY_REF); if (_mouse->Busy) ExpandSprite(_mouse->Busy); - Startup = 0; + _startup = 0; SNPOST(SNLEVEL, -1, _oldLev, &_cavLight); _cavLight->gotoxy(CAVE_X + ((_now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, @@ -1656,7 +1657,7 @@ void CGEEngine::runGame() { _keyboard->setClient(Sys); // main loop - while (! Finis && !_eventManager->_quitFlag) { + while (!_finis && !_eventManager->_quitFlag) { //TODO Change the SNPOST message send to a special way to send function pointer // if (FINIS) SNPOST(SNEXEC, -1, 0, (void *)&QGame); warning("RunGame: problematic use of SNPOST"); @@ -1668,8 +1669,8 @@ void CGEEngine::runGame() { SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); _mouse->Off(); - Vga->ShowQ->Clear(); - Vga->SpareQ->Clear(); + Vga->_showQ->clear(); + Vga->_spareQ->clear(); Hero = NULL; _shadow = NULL; } @@ -1682,8 +1683,8 @@ void CGEEngine::movie(const char *ext) { const char *fn = progName(ext); if (INI_FILE::exist(fn)) { loadScript(fn); - ExpandSprite(Vga->SpareQ->Locate(999)); - feedSnail(Vga->ShowQ->Locate(999), TAKE); + ExpandSprite(Vga->_spareQ->locate(999)); + feedSnail(Vga->_showQ->locate(999), TAKE); // FIXME: Allow ScummVM to handle mouse display //Vga->ShowQ->Append(Mouse); @@ -1697,8 +1698,8 @@ void CGEEngine::movie(const char *ext) { _heart->_enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); - Vga->ShowQ->Clear(); - Vga->SpareQ->Clear(); + Vga->_showQ->clear(); + Vga->_spareQ->clear(); } } @@ -1718,9 +1719,9 @@ bool CGEEngine::showTitle(const char *name) { D.center(); D.show(2); - if (STARTUP::Mode == 2) { + if (Startup::_mode == 2) { inf(SVG0NAME); - Talk->show(2); + _talk->show(2); } Vga->Sunset(); @@ -1729,10 +1730,10 @@ bool CGEEngine::showTitle(const char *name) { selectPocket(-1); Vga->Sunrise(VGA::SysPal); - if (STARTUP::Mode < 2 && !STARTUP::SoundOk) { + if (Startup::_mode < 2 && !Startup::_soundOk) { Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); - Vga->ShowQ->Append(_mouse); + Vga->_showQ->append(_mouse); _heart->_enable = true; _mouse->On(); for (selectSound(); !_snail->idle() || VMENU::Addr;) { @@ -1743,22 +1744,22 @@ bool CGEEngine::showTitle(const char *name) { _mouse->Off(); _heart->_enable = false; - Vga->ShowQ->Clear(); + Vga->_showQ->clear(); Vga->CopyPage(0, 2); - STARTUP::SoundOk = 2; + Startup::_soundOk = 2; if (_music) LoadMIDI(0); } - if (STARTUP::Mode < 2) { + if (Startup::_mode < 2) { if (_isDemo) { - strcpy(UsrFnam, progName(SVG_EXT)); + strcpy(_usrFnam, progName(SVG_EXT)); usr_ok = true; } else { //----------------------------------------- #ifndef EVA #ifdef CD - STARTUP::Summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; + Startup::_summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; #else // At this point the game originally read the boot sector to get // the serial number for it's copy protection check @@ -1767,7 +1768,7 @@ bool CGEEngine::showTitle(const char *name) { movie("X00"); // paylist Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); - Vga->ShowQ->Append(_mouse); + Vga->_showQ->append(_mouse); //Mouse.On(); _heart->_enable = true; for (takeName(); GetText::_ptr;) { @@ -1776,33 +1777,33 @@ bool CGEEngine::showTitle(const char *name) { return false; } _heart->_enable = false; - if (_keyboard->last() == Enter && *UsrFnam) + if (_keyboard->last() == Enter && *_usrFnam) usr_ok = true; if (usr_ok) - strcat(UsrFnam, SVG_EXT); + strcat(_usrFnam, SVG_EXT); //Mouse.Off(); - Vga->ShowQ->Clear(); + Vga->_showQ->clear(); Vga->CopyPage(0, 2); #endif } - if (usr_ok && STARTUP::Mode == 0) { - const char *n = UsrPath(UsrFnam); + if (usr_ok && Startup::_mode == 0) { + const char *n = usrPath(_usrFnam); if (CFile::exist(n)) { CFile file = CFile(n, REA, RCrypt); loadGame(file, true); // only system vars Vga->SetColors(VGA::SysPal, 64); Vga->Update(); if (FINIS) { - ++ STARTUP::Mode; + Startup::_mode++; FINIS = false; } } else - ++STARTUP::Mode; + Startup::_mode++; } } - if (STARTUP::Mode < 2) + if (Startup::_mode < 2) movie("X01"); // wink Vga->CopyPage(0, 2); @@ -1810,7 +1811,7 @@ bool CGEEngine::showTitle(const char *name) { if (_isDemo) return true; else - return (STARTUP::Mode == 2 || usr_ok); + return (Startup::_mode == 2 || usr_ok); } @@ -1824,34 +1825,34 @@ void StkDump (void) { void CGEEngine::cge_main(void) { uint16 intStack[STACK_SIZ / 2]; - intStackPtr = intStack; + _intStackPtr = intStack; //Debug( memset((void *) (-K(2)), 0, K(1)); ) //Debug( memset((void *) (-K(4)), 0, K(1)); ) memset(_barriers, 0xFF, sizeof(_barriers)); if (!_mouse->Exist) - error("%s", Text->getText(NO_MOUSE_TEXT)); + error("%s", _text->getText(NO_MOUSE_TEXT)); if (!SVG0FILE::exist(SVG0NAME)) - STARTUP::Mode = 2; + Startup::_mode = 2; - DebugLine->_flags._hide = true; + _debugLine->_flags._hide = true; _horzLine->_flags._hide = true; //srand((uint16) Timer()); Sys = new SYSTEM(this); - if (_music && STARTUP::SoundOk) + if (_music && Startup::_soundOk) LoadMIDI(0); - if (STARTUP::Mode < 2) + if (Startup::_mode < 2) movie(LGO_EXT); if (showTitle("WELCOME")) { - if ((!_isDemo) && (STARTUP::Mode == 1)) + if ((!_isDemo) && (Startup::_mode == 1)) movie("X02"); // intro runGame(); - Startup = 2; + _startup = 2; if (FINIS) movie("X03"); } else diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 5e3eb6bf1c5..0684a886e5a 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -170,7 +170,7 @@ extern WALK *Hero; extern VGA *Vga; extern Heart *_heart; extern SYSTEM *Sys; -extern int OffUseCount; +extern int _offUseCount; extern Sprite *_pocLight; extern Keyboard *_keyboard; extern MOUSE *_mouse; @@ -180,9 +180,9 @@ extern Sprite *_sprite; extern Sprite *_miniCave; extern Sprite *_shadow; extern Sprite *_horzLine; -extern INFO_LINE *InfoLine; +extern InfoLine *_infoLine; extern Sprite *_cavLight; -extern INFO_LINE *DebugLine; +extern InfoLine *_debugLine; extern BMP_PTR MB[2]; extern BMP_PTR MB[2]; extern BMP_PTR HL[2]; diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 9a8219dd6bc..f32c3b71952 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -146,16 +146,16 @@ void CGEEngine::selectSound() { _sound.Close(); if (VMENU::Addr) SNPOST_(SNKILL, -1, 0, VMENU::Addr); - inf(Text->getText(STYPE_TEXT)); - Talk->gotoxy(Talk->_x, FONT_HIG / 2); + inf(_text->getText(STYPE_TEXT)); + _talk->gotoxy(_talk->_x, FONT_HIG / 2); for (i = 0; i < (int)ArrayCount(DevName); i++) - DevMenu[i].Text = Text->getText(DevName[i]); - (new VMENU(this, DevMenu, SCR_WID / 2, Talk->_y + Talk->_h + TEXT_VM + FONT_HIG))->setName(Text->getText(MENU_TEXT)); + DevMenu[i].Text = _text->getText(DevName[i]); + (new VMENU(this, DevMenu, SCR_WID / 2, _talk->_y + _talk->_h + TEXT_VM + FONT_HIG))->setName(_text->getText(MENU_TEXT)); } static void Reset(void) { - SNDDrvInfo.DBASE = SNDDrvInfo.DIRQ = SNDDrvInfo.DDMA = SNDDrvInfo.MBASE = DETECT; + _sndDrvInfo._dBase = _sndDrvInfo._dIrq = _sndDrvInfo._dDma = _sndDrvInfo._mBase = DETECT; } @@ -183,9 +183,9 @@ static CHOICE *Cho; static int Hlp; void CGEEngine::SNSelect() { - inf(Text->getText(Hlp)); - Talk->gotoxy(Talk->_x, FONT_HIG / 2); - (new VMENU(this, Cho, SCR_WID / 2, Talk->_y + Talk->_h + TEXT_VM + FONT_HIG))->setName(Text->getText(MENU_TEXT)); + inf(_text->getText(Hlp)); + _talk->gotoxy(_talk->_x, FONT_HIG / 2); + (new VMENU(this, Cho, SCR_WID / 2, _talk->_y + _talk->_h + TEXT_VM + FONT_HIG))->setName(_text->getText(MENU_TEXT)); } @@ -199,81 +199,81 @@ static void Select(CHOICE *cho, int hlp) { void CGEEngine::NONE() { - SNDDrvInfo.DDEV = DEV_QUIET; - SNDDrvInfo.MDEV = DEV_QUIET; + _sndDrvInfo._dDev = DEV_QUIET; + _sndDrvInfo._mDev = DEV_QUIET; _sound.Open(); } void CGEEngine::SB() { - SNDDrvInfo.DDEV = DEV_SB; - SNDDrvInfo.MDEV = DEV_SB; + _sndDrvInfo._dDev = DEV_SB; + _sndDrvInfo._mDev = DEV_SB; Reset(); Select(DigiPorts, SPORT_TEXT); } void CGEEngine::SBM() { - SNDDrvInfo.DDEV = DEV_SB; - SNDDrvInfo.MDEV = DEV_GM; + _sndDrvInfo._dDev = DEV_SB; + _sndDrvInfo._mDev = DEV_GM; Reset(); Select(DigiPorts, SPORT_TEXT); } void CGEEngine::GUS() { - SNDDrvInfo.DDEV = DEV_GUS; - SNDDrvInfo.MDEV = DEV_GUS; + _sndDrvInfo._dDev = DEV_GUS; + _sndDrvInfo._mDev = DEV_GUS; Reset(); Select(DigiPorts, SPORT_TEXT); } void CGEEngine::GUSM() { - SNDDrvInfo.DDEV = DEV_GUS; - SNDDrvInfo.MDEV = DEV_GM; + _sndDrvInfo._dDev = DEV_GUS; + _sndDrvInfo._mDev = DEV_GM; Reset(); Select(DigiPorts, SPORT_TEXT); } void CGEEngine::MIDI() { - SNDDrvInfo.DDEV = DEV_QUIET; - SNDDrvInfo.MDEV = DEV_GM; - SNDDrvInfo.MBASE = DETECT; + _sndDrvInfo._dDev = DEV_QUIET; + _sndDrvInfo._mDev = DEV_GM; + _sndDrvInfo._mBase = DETECT; Select(MIDIPorts, MPORT_TEXT); } void CGEEngine::AUTO() { - SNDDrvInfo.DDEV = DEV_AUTO; - SNDDrvInfo.MDEV = DEV_AUTO; + _sndDrvInfo._dDev = DEV_AUTO; + _sndDrvInfo._mDev = DEV_AUTO; Reset(); _sound.Open(); } void CGEEngine::setPortD() { - SNDDrvInfo.DBASE = xdeco(DigiPorts[VMENU::Recent].Text); - Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ, SIRQ_TEXT); + _sndDrvInfo._dBase = xdeco(DigiPorts[VMENU::Recent].Text); + Select((_sndDrvInfo._dDev == DEV_SB) ? BlsterIRQ : GravisIRQ, SIRQ_TEXT); } void CGEEngine::setPortM() { - SNDDrvInfo.MBASE = xdeco(MIDIPorts[VMENU::Recent].Text); + _sndDrvInfo._mBase = xdeco(MIDIPorts[VMENU::Recent].Text); _sound.Open(); } void CGEEngine::setIRQ() { - SNDDrvInfo.DIRQ = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterIRQ : GravisIRQ)[VMENU::Recent].Text); - Select((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA, SDMA_TEXT); + _sndDrvInfo._dIrq = ddeco(((_sndDrvInfo._dDev == DEV_SB) ? BlsterIRQ : GravisIRQ)[VMENU::Recent].Text); + Select((_sndDrvInfo._dDev == DEV_SB) ? BlsterDMA : GravisDMA, SDMA_TEXT); } void CGEEngine::setDMA() { - SNDDrvInfo.DDMA = ddeco(((SNDDrvInfo.DDEV == DEV_SB) ? BlsterDMA : GravisDMA)[VMENU::Recent].Text); - if (SNDDrvInfo.MDEV != SNDDrvInfo.DDEV) + _sndDrvInfo._dDma = ddeco(((_sndDrvInfo._dDev == DEV_SB) ? BlsterDMA : GravisDMA)[VMENU::Recent].Text); + if (_sndDrvInfo._mDev != _sndDrvInfo._dDev) Select(MIDIPorts, MPORT_TEXT); else _sound.Open(); diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index e18890625f3..97385c3ae17 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -300,7 +300,7 @@ void EventManager::handleEvents(void) { // discard Text if button released if (e._msk & (L_UP | R_UP)) - KillText(); + killText(); } EvtTail = (EvtTail + 1) % EVT_MAX; } diff --git a/engines/cge/events.h b/engines/cge/events.h index 59a62803bac..cfb1023d6b5 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -80,7 +80,7 @@ public: #define KEYB 0x80 -extern TALK *Talk; +extern Talk *_talk; struct CGEEvent { uint16 _msk; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index fe94bd4598b..6b0327ff233 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -92,7 +92,7 @@ Dac _stdPal[] = {// R G B { 255, 255, 255}, // 255 }; -DrvInfo SNDDrvInfo; +DrvInfo _sndDrvInfo; void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)) { warning("STUB: _fqsort"); @@ -298,32 +298,32 @@ bool isVga() { return true; } -void SNDInit() { +void sndInit() { warning("STUB: SNDInit"); } -void SNDDone() { +void sndDone() { // FIXME: STUB: SNDDone } -void SNDSetVolume() { +void sndSetVolume() { warning("STUB: SNDSetVolume"); } -void SNDDigiStart(SmpInfo *PSmpInfo) { +void sndDigiStart(SmpInfo *PSmpInfo) { warning("STUB: SNDDigitStart"); } -void SNDDigiStop(SmpInfo *PSmpInfo) { +void sndDigiStop(SmpInfo *PSmpInfo) { warning("STUB: SNDDigiStop"); } -void SNDMIDIStart(uint8 *MIDFile) { +void sndMidiStart(uint8 *MIDFile) { warning("STUB: SNDMIDIStart"); } -void SNDMIDIStop() { - // FIXME: STUB: SNDMIDIStop +void sndMidiStop() { + // FIXME: STUB: sndMIDIStop } DATACK *LoadWave(XFile *file, EMM *emm) { diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index c48b281771f..508175ccd5d 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -35,19 +35,19 @@ GetText *GetText::_ptr = NULL; GetText::GetText(CGEEngine *vm, const char *info, char *text, int size, void (*click)()) - : TALK(vm), _text(text), _size(min(size, GTMAX)), _len(min(_size, strlen(text))), + : Talk(vm), _text(text), _size(min(size, GTMAX)), _len(min(_size, strlen(text))), _cntr(GTBLINK), _click(click), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { - int i = 2 * TEXT_HM + _Font->Width(info); + int i = 2 * TEXT_HM + _font->width(info); _ptr = this; - Mode = RECT; - TS[0] = Box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); - setShapeList(TS); + _mode = RECT; + _ts[0] = box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); + setShapeList(_ts); _flags._bDel = true; _flags._kill = true; memcpy(_buff, text, _len); _buff[_len] = ' '; _buff[_len + 1] = '\0'; - PutLine(0, info); + putLine(0, info); tick(); } @@ -63,7 +63,7 @@ void GetText::tick() { _buff[_len] ^= (' ' ^ '_'); _cntr = 0; } - PutLine(1, _buff); + putLine(1, _buff); _time = GTTIME; } @@ -105,7 +105,7 @@ void GetText::touch(uint16 mask, int x, int y) { if (p) x = ogon[p - bezo]; } - if (_len < _size && 2 * TEXT_HM + _Font->Width(_buff) + _Font->Wid[x] <= _w) { + if (_len < _size && 2 * TEXT_HM + _font->width(_buff) + _font->_wid[x] <= _w) { _buff[_len + 2] = _buff[_len + 1]; _buff[_len + 1] = _buff[_len]; _buff[_len++] = x; diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h index f743d0c66cc..d29d11abb77 100644 --- a/engines/cge/gettext.h +++ b/engines/cge/gettext.h @@ -37,7 +37,7 @@ namespace CGE { #define GTBLINK 6 #define GTTIME 6 -class GetText : public TALK { +class GetText : public Talk { char _buff[GTMAX + 2]; char *_text; uint16 _size; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index e3fd2c07edd..a49f7c5c7fa 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -44,7 +44,7 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(MIX_FALL), _ _mb[0] = new Bitmap("VOLUME", true); _mb[1] = NULL; setShapeList(_mb); - setName(Text->getText(MIX_NAME)); + setName(_text->getText(MIX_NAME)); _flags._syst = true; _flags._kill = true; _flags._bDel = true; @@ -58,8 +58,8 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(MIX_FALL), _ static char fn[] = "V00"; wtom(i, fn + 1, 10, 2); _lb[i] = new Bitmap(fn, true); - _ls[i].Now = _ls[i].Next = i; - _ls[i].Dx = _ls[i].Dy = _ls[i].Dly = 0; + _ls[i]._now = _ls[i]._next = i; + _ls[i]._dx = _ls[i]._dy = _ls[i]._dly = 0; } _lb[i] = NULL; @@ -75,17 +75,17 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(MIX_FALL), _ } _led[ArrayCount(_led) - 1]->_flags._bDel = true; - Vga->ShowQ->Insert(this); + Vga->_showQ->insert(this); for (i = 0; i < ArrayCount(_led); i++) - Vga->ShowQ->Insert(_led[i]); + Vga->_showQ->insert(_led[i]); //--- reset balance - i = (SNDDrvInfo.VOL4.ML + SNDDrvInfo.VOL4.MR) / 2; - SNDDrvInfo.VOL4.ML = i; - SNDDrvInfo.VOL4.MR = i; - i = (SNDDrvInfo.VOL4.DL + SNDDrvInfo.VOL4.DR) / 2; - SNDDrvInfo.VOL4.DL = i; - SNDDrvInfo.VOL4.DR = i; + i = (_sndDrvInfo.Vol4._ml + _sndDrvInfo.Vol4._mr) / 2; + _sndDrvInfo.Vol4._ml = i; + _sndDrvInfo.Vol4._mr = i; + i = (_sndDrvInfo.Vol4._dl + _sndDrvInfo.Vol4._dr) / 2; + _sndDrvInfo.Vol4._dl = i; + _sndDrvInfo.Vol4._dr = i; update(); _time = MIX_DELAY; } @@ -99,7 +99,7 @@ Mixer::~Mixer() { void Mixer::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); if (mask & L_UP) { - uint8 *vol = (&SNDDrvInfo.VOL2.D) + (x < _w / 2); + uint8 *vol = (&_sndDrvInfo.Vol2._d) + (x < _w / 2); if (y < MIX_BHIG) { if (*vol < 0xFF) *vol += 0x11; @@ -133,11 +133,11 @@ void Mixer::tick() { void Mixer::update(void) { - _led[0]->step(SNDDrvInfo.VOL4.ML); - _led[1]->step(SNDDrvInfo.VOL4.DL); + _led[0]->step(_sndDrvInfo.Vol4._ml); + _led[1]->step(_sndDrvInfo.Vol4._dl); //TODO Change the SNPOST message send to a special way to send function pointer - //SNPOST_(SNEXEC, -1, 0, (void*)&SNDSetVolume); + //SNPOST_(SNEXEC, -1, 0, (void*)&sndSetVolume); warning("STUB: Mixer::Update"); } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 308ffb231cc..01be69386fd 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -57,10 +57,10 @@ extern Sprite *_pocLight; //------------------------------------------------------------------------- // SPRITE * Pocket[POCKET_NX]={ NULL, NULL, NULL, NULL, // NULL, NULL, NULL, NULL, }; -// int PocPtr = 0; +// int _pocPtr = 0; //------------------------------------------------------------------------- extern Sprite *_pocket[]; -extern int PocPtr; +extern int _pocPtr; static void SNGame(Sprite *spr, int num) { switch (num) { @@ -71,7 +71,7 @@ static void SNGame(Sprite *spr, int num) { int buref = 0; int Stage = 0; - for (dup[0] = Vga->ShowQ->First(); dup[0]; dup[0] = dup[0]->_next) { + for (dup[0] = Vga->_showQ->first(); dup[0]; dup[0] = dup[0]->_next) { buref = dup[0]->_ref; if (buref / 1000 == 16 && buref % 100 == 6) { Stage = (buref / 100) % 10; @@ -79,8 +79,8 @@ static void SNGame(Sprite *spr, int num) { } } if (dup[1] == NULL) { - dup[1] = Vga->ShowQ->Locate(16003); // pan - dup[2] = Vga->ShowQ->Locate(16004); // pani + dup[1] = Vga->_showQ->locate(16003); // pan + dup[2] = Vga->_showQ->locate(16004); // pani } if (_game) { // continue game @@ -163,10 +163,10 @@ static void SNGame(Sprite *spr, int num) { static int count = 0; if (k == NULL) { - k = Vga->ShowQ->Locate(20700); - k1 = Vga->ShowQ->Locate(20701); - k2 = Vga->ShowQ->Locate(20702); - k3 = Vga->ShowQ->Locate(20703); + k = Vga->_showQ->locate(20700); + k1 = Vga->_showQ->locate(20701); + k2 = Vga->_showQ->locate(20702); + k3 = Vga->_showQ->locate(20703); } if (!_game) { // init @@ -273,13 +273,13 @@ static void SNGame(Sprite *spr, int num) { void ExpandSprite(Sprite *spr) { if (spr) - Vga->ShowQ->Insert(Vga->SpareQ->Remove(spr)); + Vga->_showQ->insert(Vga->_spareQ->remove(spr)); } void ContractSprite(Sprite *spr) { if (spr) - Vga->SpareQ->Append(Vga->ShowQ->Remove(spr)); + Vga->_spareQ->append(Vga->_showQ->remove(spr)); } int findPocket(Sprite *spr) { @@ -291,18 +291,18 @@ int findPocket(Sprite *spr) { void selectPocket(int n) { - if (n < 0 || (_pocLight->_seqPtr && PocPtr == n)) { + if (n < 0 || (_pocLight->_seqPtr && _pocPtr == n)) { _pocLight->step(0); n = findPocket(NULL); if (n >= 0) - PocPtr = n; + _pocPtr = n; } else { if (_pocket[n] != NULL) { - PocPtr = n; + _pocPtr = n; _pocLight->step(1); } } - _pocLight->gotoxy(POCKET_X + PocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY); + _pocLight->gotoxy(POCKET_X + _pocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY); } @@ -353,7 +353,7 @@ void feedSnail(Sprite *spr, SNLIST snq) { while (true) { if (c->_com == SNTALK) { if ((_snail->_talkEnable = (c->_val != 0)) == false) - KillText(); + killText(); } if (c->_com == SNNEXT) { Sprite *s = (c->_ref < 0) ? spr : Locate(c->_ref); @@ -441,7 +441,7 @@ void Snail::addCom(SNCOM com, int ref, int val, void *ptr) { snc->_ptr = ptr; if (com == SNCLEAR) { _tail = _head; - KillText(); + killText(); _timerExpiry = 0; } _enable(); @@ -464,7 +464,7 @@ void Snail::insCom(SNCOM com, int ref, int val, void *ptr) { snc->_ptr = ptr; if (com == SNCLEAR) { _tail = _head; - KillText(); + killText(); _timerExpiry = 0; } _enable(); @@ -506,10 +506,10 @@ static void SNZTrim(Sprite *spr) { Sprite *s; _heart->_enable = false; s = (spr->_flags._shad) ? spr->_prev : NULL; - Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr)); + Vga->_showQ->insert(Vga->_showQ->remove(spr)); if (s) { s->_z = spr->_z; - Vga->ShowQ->Insert(Vga->ShowQ->Remove(s), spr); + Vga->_showQ->insert(Vga->_showQ->remove(s), spr); } _heart->_enable = en; } @@ -627,7 +627,7 @@ void SNCover(Sprite *spr, int xref) { xspr->gotoxy(spr->_x, spr->_y); ExpandSprite(xspr); if ((xspr->_flags._shad = spr->_flags._shad) == 1) { - Vga->ShowQ->Insert(Vga->ShowQ->Remove(spr->_prev), xspr); + Vga->_showQ->insert(Vga->_showQ->remove(spr->_prev), xspr); spr->_flags._shad = false; } feedSnail(xspr, NEAR); @@ -641,7 +641,7 @@ void SNUncover(Sprite *spr, Sprite *xspr) { spr->_cave = xspr->_cave; spr->gotoxy(xspr->_x, xspr->_y); if ((spr->_flags._shad = xspr->_flags._shad) == 1) { - Vga->ShowQ->Insert(Vga->ShowQ->Remove(xspr->_prev), spr); + Vga->_showQ->insert(Vga->_showQ->remove(xspr->_prev), spr); xspr->_flags._shad = false; } spr->_z = xspr->_z; @@ -716,7 +716,7 @@ void SNSlave(Sprite *spr, int ref) { SNSend(slv, spr->_cave); slv->_flags._slav = true; slv->_z = spr->_z; - Vga->ShowQ->Insert(Vga->ShowQ->Remove(slv), spr->_next); + Vga->_showQ->insert(Vga->_showQ->remove(slv), spr->_next); } } } @@ -743,13 +743,13 @@ void SNKill(Sprite *spr) { } Sprite *nx = spr->_next; Hide1(spr); - Vga->ShowQ->Remove(spr); + Vga->_showQ->remove(spr); EventManager::ClrEvt(spr); if (spr->_flags._kill) delete spr; else { spr->_cave = -1; - Vga->SpareQ->Append(spr); + Vga->_spareQ->append(spr); } if (nx) { if (nx->_flags._slav) @@ -760,7 +760,7 @@ void SNKill(Sprite *spr) { static void SNSound(Sprite *spr, int wav, int cnt) { - if (SNDDrvInfo.DDEV) { + if (_sndDrvInfo._dDev) { if (wav == -1) _sound.Stop(); else @@ -771,12 +771,12 @@ static void SNSound(Sprite *spr, int wav, int cnt) { void SNKeep(Sprite *spr, int stp) { selectPocket(-1); - if (spr && ! spr->_flags._kept && _pocket[PocPtr] == NULL) { + if (spr && ! spr->_flags._kept && _pocket[_pocPtr] == NULL) { SNSound(spr, 3, 1); - _pocket[PocPtr] = spr; + _pocket[_pocPtr] = spr; spr->_cave = 0; spr->_flags._kept = true; - spr->gotoxy(POCKET_X + POCKET_DX * PocPtr + POCKET_DX / 2 - spr->_w / 2, + spr->gotoxy(POCKET_X + POCKET_DX * _pocPtr + POCKET_DX / 2 - spr->_w / 2, POCKET_Y + POCKET_DY / 2 - spr->_h / 2); if (stp >= 0) spr->step(stp); @@ -817,7 +817,7 @@ static void SNLevel(Sprite *spr, int lev) { #endif while (_lev < lev) { _lev++; - spr = Vga->SpareQ->Locate(100 + _lev); + spr = Vga->_spareQ->locate(100 + _lev); if (spr) { spr->backShow(true); spr->_cave = 0; @@ -919,11 +919,11 @@ void Snail::runCom() { _timerExpiry = 0; } else { if (_textDelay) { - KillText(); + killText(); _textDelay = false; } } - if (Talk && snc->_com != SNPAUSE) + if (_talk && snc->_com != SNPAUSE) break; } @@ -933,7 +933,7 @@ void Snail::runCom() { break; case SNPAUSE : _timerExpiry = g_system->getMillis() + snc->_val * SNAIL_FRAME_DELAY; - if (Talk) + if (_talk) _textDelay = true; break; case SNWAIT : @@ -955,13 +955,13 @@ void Snail::runCom() { if (sprel && _talkEnable) { if (sprel == Hero && sprel->seqTest(-1)) sprel->step(HTALK); - Text->Say(Text->getText(snc->_val), sprel); + _text->say(_text->getText(snc->_val), sprel); Sys->FunDel = HEROFUN0; } break; case SNINF : if (_talkEnable) { - _vm->inf(Text->getText(snc->_val)); + _vm->inf(_text->getText(snc->_val)); Sys->FunDel = HEROFUN0; } break; @@ -969,7 +969,7 @@ void Snail::runCom() { if (sprel && _talkEnable) { if (sprel == Hero && sprel->seqTest(-1)) sprel->step(HTALK); - SayTime(sprel); + sayTime(sprel); } break; case SNCAVE : diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 78d1434b40f..0ea776b7848 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -57,73 +57,73 @@ enum DEV_TYPE { DEV_AUTO = -1, // auto-detect mode // driver info struct DrvInfo { - DEV_TYPE DDEV; // digi device - DEV_TYPE MDEV; // midi device - uint16 DBASE; // digi base port - uint16 DDMA; // digi dma no - uint16 DIRQ; // digi irq no - uint16 MBASE; // midi base port + DEV_TYPE _dDev; // digi device + DEV_TYPE _mDev; // midi device + uint16 _dBase; // digi base port + uint16 _dDma; // digi dma no + uint16 _dIrq; // digi irq no + uint16 _mBase; // midi base port union { struct { - uint16 DR : 4; - uint16 DL : 4; - uint16 MR : 4; - uint16 ML : 4; - } VOL4; + uint16 _dr : 4; + uint16 _dl : 4; + uint16 _mr : 4; + uint16 _ml : 4; + } Vol4; struct { - uint8 D; // digi volume - uint8 M; // midi volume - } VOL2; + uint8 _d; // digi volume + uint8 _m; // midi volume + } Vol2; }; }; // sample info struct SmpInfo { - uint8 *saddr; // address - uint16 slen; // length - uint16 span; // left/right pan (0-15) - int sflag; // flag + uint8 *_saddr; // address + uint16 _slen; // length + uint16 _span; // left/right pan (0-15) + int _sflag; // flag }; // ****************************************************** // * Data * // ****************************************************** // driver info -extern DrvInfo SNDDrvInfo; +extern DrvInfo _sndDrvInfo; // midi player flag (1 means we are playing) -extern uint16 MIDIPlayFlag; +extern uint16 _midiPlayFlag; // midi song end flag (1 means we have crossed end mark) -extern uint16 MIDIEndFlag; +extern uint16 _midiEndFlag; // ****************************************************** // * Driver Code * // ****************************************************** // Init Digi Device -void SNDInit(); +void sndInit(); // Close Digi Device -void SNDDone(); +void sndDone(); // Set Volume -void SNDSetVolume(); +void sndSetVolume(); // Start Digi -void SNDDigiStart(SmpInfo *PSmpInfo); +void sndDigiStart(SmpInfo *PSmpInfo); // Stop Digi -void SNDDigiStop(SmpInfo *PSmpInfo); +void sndDigiStop(SmpInfo *PSmpInfo); // Start MIDI File -void SNDMIDIStart(uint8 *MIDFile); +void sndMidiStart(uint8 *MIDFile); // Stop MIDI File -void SNDMIDIStop(); +void sndMidiStop(); // Play MIDI File (to be called while interrupting) // WARNING: Uses ALL registers! -void SNDMIDIPlay(); +void sndMidiPlay(); } // End of namespace CGE diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 60af9f70166..aca4b4d5345 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -41,7 +41,7 @@ SOUND _sound; SOUND::SOUND(void) { - if (STARTUP::SoundOk) + if (Startup::_soundOk) Open(); } @@ -53,12 +53,12 @@ SOUND::~SOUND(void) { void SOUND::Close(void) { KillMIDI(); - SNDDone(); + sndDone(); } void SOUND::Open(void) { - SNDInit(); + sndInit(); Play(_fx[30000], 8); } @@ -66,17 +66,17 @@ void SOUND::Open(void) { void SOUND::Play(DATACK *wav, int pan, int cnt) { if (wav) { Stop(); - smpinf.saddr = (uint8 *) &*(wav->EAddr()); - smpinf.slen = (uint16)wav->Size(); - smpinf.span = pan; - smpinf.sflag = cnt; - SNDDigiStart(&smpinf); + smpinf._saddr = (uint8 *) &*(wav->EAddr()); + smpinf._slen = (uint16)wav->Size(); + smpinf._span = pan; + smpinf._sflag = cnt; + sndDigiStart(&smpinf); } } void SOUND::Stop(void) { - SNDDigiStop(&smpinf); + sndDigiStop(&smpinf); } @@ -176,7 +176,7 @@ static uint8 *midi = NULL; void KillMIDI(void) { - SNDMIDIStop(); + sndMidiStop(); if (midi) { delete[] midi; midi = NULL; @@ -198,7 +198,7 @@ void LoadMIDI(int ref) { if (mid._error) KillMIDI(); else - SNDMIDIStart(midi); + sndMidiStart(midi); } } } diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 39a2b66e4bd..0dfbc67916b 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -33,29 +33,28 @@ namespace CGE { -extern char Copr[]; +extern char _copr[]; -#define id (*(Ident*)Copr) +#define id (*(Ident*)_copr) -EMM MiniEmm = MINI_EMM_SIZE; +EMM _miniEmm = MINI_EMM_SIZE; -static STARTUP StartUp; +// static Startup _startUp; + +int Startup::_mode = 0; +int Startup::_core; +int Startup::_soundOk = 0; +uint16 Startup::_summa; -int STARTUP::Mode = 0; -int STARTUP::Core; -int STARTUP::SoundOk = 0; -uint16 STARTUP::Summa; - - -void quit_now(int ref) { - error("%s", Text->getText(ref)); +void quitNow(int ref) { + error("%s", _text->getText(ref)); } -bool STARTUP::get_parms(void) { - Summa = 0; +bool Startup::getParms() { + _summa = 0; /* int i = _argc; @@ -103,12 +102,12 @@ bool STARTUP::get_parms(void) { if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; return true; */ - warning("STUB: STARTUP::get_parms"); + warning("STUB: Startup::get_parms"); return true; } -STARTUP::STARTUP(void) { +Startup::Startup() { /* uint32 m = farcoreleft() >> 10; if (m < 0x7FFF) @@ -125,21 +124,21 @@ STARTUP::STARTUP(void) { if (! get_parms()) quit_now(BAD_ARG_TEXT); //--- load sound configuration - const char * fn = UsrPath(ProgName(CFG_EXT)); - if (! STARTUP::SoundOk && CFILE::Exist(fn)) { + const char * fn = usrPath(ProgName(CFG_EXT)); + if (!Startup::_soundOk && CFILE::Exist(fn)) { CFILE cfg(fn, REA); if (! cfg.Error) { cfg.Read(&SNDDrvInfo, sizeof(SNDDrvInfo)-sizeof(SNDDrvInfo.VOL2)); if (! cfg.Error) - STARTUP::SoundOk = 1; + Startup::_soundOk = 1; } } */ - warning("STUB: STARTUP::STARTUP"); + warning("STUB: Startup::Startup"); } -const char *UsrPath(const char *nam) { +const char *usrPath(const char *nam) { static char buf[MAXPATH] = ".\\", *p = buf + 2; #if defined(CD) if (DriveCD(0)) { diff --git a/engines/cge/startup.h b/engines/cge/startup.h index a1e44cc4af7..96c73880702 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -59,20 +59,20 @@ namespace CGE { #define CORE_LOW (CORE_MID - 20) -class STARTUP { - static bool get_parms(void); +class Startup { + static bool getParms(); public: - static int Mode; - static int Core; - static int SoundOk; - static uint16 Summa; - STARTUP(void); + static int _mode; + static int _core; + static int _soundOk; + static uint16 _summa; + Startup(); }; -extern EMM MiniEmm; +extern EMM _miniEmm; -const char *UsrPath(const char *nam); +const char *usrPath(const char *nam); } // End of namespace CGE diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 0abff7752c3..7c0f9563a64 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -42,106 +42,106 @@ namespace CGE { //uint8 FONT::Map[MAP_SIZ]; -FONT::FONT(const char *name) { - Map = farnew(uint8, MAP_SIZ); - Pos = farnew(uint16, POS_SIZ); - Wid = farnew(uint8, WID_SIZ); - if ((Map == NULL) || (Pos == NULL) || (Wid == NULL)) +Font::Font(const char *name) { + _map = farnew(uint8, MAP_SIZ); + _pos = farnew(uint16, POS_SIZ); + _wid = farnew(uint8, WID_SIZ); + if ((_map == NULL) || (_pos == NULL) || (_wid == NULL)) error("No core"); - mergeExt(Path, name, FONT_EXT); - Load(); + mergeExt(_path, name, FONT_EXT); + load(); } -FONT::~FONT() { - free(Map); - free(Pos); - free(Wid); +Font::~Font() { + free(_map); + free(_pos); + free(_wid); } -void FONT::Load() { - INI_FILE f(Path); +void Font::load() { + INI_FILE f(_path); if (!f._error) { - f.read(Wid, WID_SIZ); + f.read(_wid, WID_SIZ); if (!f._error) { uint16 i, p = 0; for (i = 0; i < POS_SIZ; i++) { - Pos[i] = p; - p += Wid[i]; + _pos[i] = p; + p += _wid[i]; } - f.read(Map, p); + f.read(_map, p); } } } -uint16 FONT::Width(const char *text) { +uint16 Font::width(const char *text) { uint16 w = 0; if (text) while (* text) - w += Wid[(unsigned char)*(text++)]; + w += _wid[(unsigned char)*(text++)]; return w; } /* -void FONT::Save(void) { - CFILE f((const char *) Path, WRI); - if (! f.Error) { - f.Write(Wid, WID_SIZ); - if (! f.Error) - f.Write(Map, Pos[POS_SIZ - 1] + Wid[WID_SIZ - 1]); +void Font::save() { + CFILE f((const char *) _path, WRI); + if (!f._error) { + f.Write(_wid, WID_SIZ); + if (!f._error) + f.Write(_map, _pos[POS_SIZ - 1] + _wid[WID_SIZ - 1]); } } */ -TALK::TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode) - : Sprite(vm, NULL), Mode(mode), _vm(vm) { - TS[0] = TS[1] = NULL; +Talk::Talk(CGEEngine *vm, const char *tx, TBOX_STYLE mode) + : Sprite(vm, NULL), _mode(mode), _vm(vm) { + _ts[0] = _ts[1] = NULL; _flags._syst = true; - Update(tx); + update(tx); } -TALK::TALK(CGEEngine *vm) - : Sprite(vm, NULL), Mode(PURE), _vm(vm) { - TS[0] = TS[1] = NULL; +Talk::Talk(CGEEngine *vm) + : Sprite(vm, NULL), _mode(PURE), _vm(vm) { + _ts[0] = _ts[1] = NULL; _flags._syst = true; } /* -TALK::~TALK (void) { +Talk::~Talk() { for (uint16 i = 0; i < ShpCnt; i++) { - if (FP_SEG(ShpList[i]) != _DS) { // small model: always false - delete ShpList[i]; + if (FP_SEG(_shpList[i]) != _DS) { // small model: always false + delete _shpList[i]; ShpList[i] = NULL; } } } */ -FONT *TALK::_Font; +Font *Talk::_font; -void TALK::init() { - _Font = new FONT(progName()); +void Talk::init() { + _font = new Font(progName()); } -void TALK::deinit() { - delete _Font; +void Talk::deinit() { + delete _font; } -void TALK::Update(const char *tx) { - uint16 vmarg = (Mode) ? TEXT_VM : 0; - uint16 hmarg = (Mode) ? TEXT_HM : 0; +void Talk::update(const char *tx) { + uint16 vmarg = (_mode) ? TEXT_VM : 0; + uint16 hmarg = (_mode) ? TEXT_HM : 0; uint16 mw = 0, mh, ln = vmarg; const char *p; uint8 *m; - if (!TS[0]) { + if (!_ts[0]) { uint16 k = 2 * hmarg; mh = 2 * vmarg + FONT_HIG; for (p = tx; *p; p++) { @@ -151,21 +151,21 @@ void TALK::Update(const char *tx) { mw = k; k = 2 * hmarg; } else - k += _Font->Wid[(unsigned char)*p]; + k += _font->_wid[(unsigned char)*p]; } if (k > mw) mw = k; - TS[0] = Box(mw, mh); + _ts[0] = box(mw, mh); } - m = TS[0]->_m + ln * mw + hmarg; + m = _ts[0]->_m + ln * mw + hmarg; while (* tx) { if (*tx == '|' || *tx == '\n') - m = TS[0]->_m + (ln += FONT_HIG + TEXT_LS) * mw + hmarg; + m = _ts[0]->_m + (ln += FONT_HIG + TEXT_LS) * mw + hmarg; else { - int cw = _Font->Wid[(unsigned char)*tx], i; - uint8 *f = _Font->Map + _Font->Pos[(unsigned char)*tx]; + int cw = _font->_wid[(unsigned char)*tx], i; + uint8 *f = _font->_map + _font->_pos[(unsigned char)*tx]; for (i = 0; i < cw; i++) { uint8 *pp = m; uint16 n; @@ -181,16 +181,16 @@ void TALK::Update(const char *tx) { } tx++; } - TS[0]->code(); - setShapeList(TS); + _ts[0]->code(); + setShapeList(_ts); } -Bitmap *TALK::Box(uint16 w, uint16 h) { +Bitmap *Talk::box(uint16 w, uint16 h) { uint8 *b, * p, * q; - uint16 n, r = (Mode == ROUND) ? TEXT_RD : 0; + uint16 n, r = (_mode == ROUND) ? TEXT_RD : 0; if (w < 8) w = 8; @@ -201,7 +201,7 @@ Bitmap *TALK::Box(uint16 w, uint16 h) { error("No core"); memset(b, TEXT_BG, n); - if (Mode) { + if (_mode) { p = b; q = b + n - w; memset(p, LGRAY, w); @@ -232,10 +232,11 @@ Bitmap *TALK::Box(uint16 w, uint16 h) { } -void TALK::PutLine(int line, const char *text) { +void Talk::putLine(int line, const char *text) { // Note: (TS[0].W % 4) have to be 0 - uint16 w = TS[0]->_w, h = TS[0]->_h; - uint8 *v = TS[0]->_v, * p; + uint16 w = _ts[0]->_w; + uint16 h = _ts[0]->_h; + uint8 *v = _ts[0]->_v, * p; uint16 dsiz = w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap uint16 psiz = h * lsiz; // - last gap, but + plane trailer @@ -262,8 +263,8 @@ void TALK::PutLine(int line, const char *text) { q = v + size; while (* text) { - uint16 cw = _Font->Wid[(unsigned char)*text], i; - uint8 *fp = _Font->Map + _Font->Pos[(unsigned char)*text]; + uint16 cw = _font->_wid[(unsigned char)*text], i; + uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; for (i = 0; i < cw; i++) { register uint16 b = fp[i]; @@ -284,22 +285,23 @@ void TALK::PutLine(int line, const char *text) { } -INFO_LINE::INFO_LINE(CGEEngine *vm, uint16 w) : TALK(vm), OldTxt(NULL), _vm(vm) { - TS[0] = new Bitmap(w, FONT_HIG, TEXT_BG); - setShapeList(TS); +InfoLine::InfoLine(CGEEngine *vm, uint16 w) : Talk(vm), _oldTxt(NULL), _vm(vm) { + _ts[0] = new Bitmap(w, FONT_HIG, TEXT_BG); + setShapeList(_ts); } -void INFO_LINE::Update(const char *tx) { - if (tx != OldTxt) { - uint16 w = TS[0]->_w, h = TS[0]->_h; - uint8 *v = (uint8 *) TS[0]->_v; +void InfoLine::update(const char *tx) { + if (tx != _oldTxt) { + uint16 w = _ts[0]->_w; + uint16 h = _ts[0]->_h; + uint8 *v = (uint8 *) _ts[0]->_v; uint16 dsiz = w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap uint16 psiz = h * lsiz; // - last gape, but + plane trailer uint16 size = 4 * psiz; // whole map size - // claer whole rectangle + // clear whole rectangle memset(v + 2, TEXT_BG, dsiz); // data bytes memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 @@ -310,8 +312,8 @@ void INFO_LINE::Update(const char *tx) { uint8 *p = v + 2, * q = p + size; while (*tx) { - uint16 cw = _Font->Wid[(unsigned char)*tx]; - uint8 *fp = _Font->Map + _Font->Pos[(unsigned char)*tx]; + uint16 cw = _font->_wid[(unsigned char)*tx]; + uint8 *fp = _font->_map + _font->_pos[(unsigned char)*tx]; for (uint16 i = 0; i < cw; i++) { register uint16 b = fp[i]; @@ -327,7 +329,7 @@ void INFO_LINE::Update(const char *tx) { tx++; } } - OldTxt = tx; + _oldTxt = tx; } } diff --git a/engines/cge/talk.h b/engines/cge/talk.h index e5e32998cb3..2f704713593 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -48,53 +48,53 @@ namespace CGE { #define MAXPATH 128 -class FONT { - char Path[MAXPATH]; - void Load(void); +class Font { + char _path[MAXPATH]; + void load(); public: -// static uint8 Wid[256]; -// static uint16 Pos[256]; -// static uint8 Map[256*8]; - uint8 *Wid; - uint16 *Pos; - uint8 *Map; - FONT(const char *name); - ~FONT(void); - uint16 Width(const char *text); - void Save(void); +// static uint8 _wid[256]; +// static uint16 _pos[256]; +// static uint8 _map[256*8]; + uint8 *_wid; + uint16 *_pos; + uint8 *_map; + Font(const char *name); + ~Font(); + uint16 width(const char *text); + void save(); }; enum TBOX_STYLE { PURE, RECT, ROUND }; -class TALK : public Sprite { +class Talk : public Sprite { protected: - TBOX_STYLE Mode; - Bitmap *TS[2]; - Bitmap *Box(uint16 w, uint16 h); + TBOX_STYLE _mode; + Bitmap *_ts[2]; + Bitmap *box(uint16 w, uint16 h); public: - TALK(CGEEngine *vm, const char *tx, TBOX_STYLE mode = PURE); - TALK(CGEEngine *vm); - //~TALK (void); + Talk(CGEEngine *vm, const char *tx, TBOX_STYLE mode); + Talk(CGEEngine *vm); + //~TALK(); - static FONT *_Font; + static Font *_font; static void init(); static void deinit(); - virtual void Update(const char *tx); - virtual void Update(void) {} - void PutLine(int line, const char *text); + virtual void update(const char *tx); + virtual void update() {} + void putLine(int line, const char *text); private: CGEEngine *_vm; }; -class INFO_LINE : public TALK { - const char *OldTxt; +class InfoLine : public Talk { + const char *_oldTxt; public: - INFO_LINE(CGEEngine *vm, uint16 wid); - void Update(const char *tx); + InfoLine(CGEEngine *vm, uint16 wid); + void update(const char *tx); private: CGEEngine *_vm; }; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index e17688c6eee..f1124932780 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -36,57 +36,57 @@ namespace CGE { -TEXT *Text; -TALK *Talk = NULL; +Text *_text; +Talk *_talk = NULL; -TEXT::TEXT(CGEEngine *vm, const char *fname, int size) : _vm(vm) { - Cache = new HAN[size]; - mergeExt(FileName, fname, SAY_EXT); - if (!INI_FILE::exist(FileName)) - error("No talk (%s)\n", FileName); +Text::Text(CGEEngine *vm, const char *fname, int size) : _vm(vm) { + _cache = new Han[size]; + mergeExt(_fileName, fname, SAY_EXT); + if (!INI_FILE::exist(_fileName)) + error("No talk (%s)\n", _fileName); - for (Size = 0; Size < size; Size++) { - Cache[Size].Ref = 0; - Cache[Size].Txt = NULL; + for (_size = 0; _size < size; _size++) { + _cache[_size]._ref = 0; + _cache[_size]._txt = NULL; } } -TEXT::~TEXT() { - Clear(); - delete[] Cache; +Text::~Text() { + clear(); + delete[] _cache; } -void TEXT::Clear(int from, int upto) { - HAN *p, * q; - for (p = Cache, q = p + Size; p < q; p++) { - if (p->Ref && p->Ref >= from && p->Ref < upto) { - p->Ref = 0; - delete[] p->Txt; - p->Txt = NULL; +void Text::clear(int from, int upto) { + Han *p, * q; + for (p = _cache, q = p + _size; p < q; p++) { + if (p->_ref && p->_ref >= from && p->_ref < upto) { + p->_ref = 0; + delete[] p->_txt; + p->_txt = NULL; } } } -int TEXT::Find(int ref) { - HAN *p, * q; +int Text::find(int ref) { + Han *p, * q; int i = 0; - for (p = Cache, q = p + Size; p < q; p++) { - if (p->Ref == ref) + for (p = _cache, q = p + _size; p < q; p++) { + if (p->_ref == ref) break; else - ++i; + i++; } return i; } -void TEXT::Preload(int from, int upto) { - INI_FILE tf = FileName; +void Text::preload(int from, int upto) { + INI_FILE tf = _fileName; if (!tf._error) { - HAN *CacheLim = Cache + Size; + Han *CacheLim = _cache + _size; char line[LINE_MAX + 1]; int n; @@ -102,33 +102,33 @@ void TEXT::Preload(int from, int upto) { continue; ref = atoi(s); if (ref && ref >= from && ref < upto) { - HAN *p; + Han *p; - p = &Cache[Find(ref)]; + p = &_cache[find(ref)]; if (p < CacheLim) { - delete[] p->Txt; - p->Txt = NULL; + delete[] p->_txt; + p->_txt = NULL; } else - p = &Cache[Find(0)]; + p = &_cache[find(0)]; if (p >= CacheLim) break; s += strlen(s); if (s < line + n) ++s; - if ((p->Txt = new char[strlen(s) + 1]) == NULL) + if ((p->_txt = new char[strlen(s) + 1]) == NULL) break; - p->Ref = ref; - strcpy(p->Txt, s); + p->_ref = ref; + strcpy(p->_txt, s); } } } } -char *TEXT::Load(int idx, int ref) { - INI_FILE tf = FileName; +char *Text::load(int idx, int ref) { + INI_FILE tf = _fileName; if (!tf._error) { - HAN *p = &Cache[idx]; + Han *p = &_cache[idx]; char line[LINE_MAX + 1]; int n; @@ -151,36 +151,36 @@ char *TEXT::Load(int idx, int ref) { s += strlen(s); if (s < line + n) ++s; - p->Ref = ref; - if ((p->Txt = new char[strlen(s) + 1]) == NULL) + p->_ref = ref; + if ((p->_txt = new char[strlen(s) + 1]) == NULL) return NULL; - return strcpy(p->Txt, s); + return strcpy(p->_txt, s); } } return NULL; } -char *TEXT::getText(int ref) { +char *Text::getText(int ref) { int i; - if ((i = Find(ref)) < Size) - return Cache[i].Txt; + if ((i = find(ref)) < _size) + return _cache[i]._txt; - if ((i = Find(0)) >= Size) { - Clear(SYSTXT_MAX); // clear non-system - if ((i = Find(0)) >= Size) { - Clear(); // clear all + if ((i = find(0)) >= _size) { + clear(SYSTXT_MAX); // clear non-system + if ((i = find(0)) >= _size) { + clear(); // clear all i = 0; } } - return Load(i, ref); + return load(i, ref); } -void TEXT::Say(const char *txt, Sprite *spr) { - KillText(); - Talk = new TALK(_vm, txt, ROUND); - if (Talk) { +void Text::say(const char *txt, Sprite *spr) { + killText(); + _talk = new Talk(_vm, txt, ROUND); + if (_talk) { bool east = spr->_flags._east; int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2); int y = spr->_y + 2; @@ -198,43 +198,43 @@ void TEXT::Say(const char *txt, Sprite *spr) { if (spr->_ref == 1) x += ((east) ? -10 : 10); // Hero - Talk->_flags._kill = true; - Talk->_flags._bDel = true; - Talk->setName(Text->getText(SAY_NAME)); - Talk->gotoxy(x - (Talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - Talk->_h + 1); - Talk->_z = 125; - Talk->_ref = SAY_REF; + _talk->_flags._kill = true; + _talk->_flags._bDel = true; + _talk->setName(_text->getText(SAY_NAME)); + _talk->gotoxy(x - (_talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - _talk->_h + 1); + _talk->_z = 125; + _talk->_ref = SAY_REF; - spike->gotoxy(x, Talk->_y + Talk->_h - 1); + spike->gotoxy(x, _talk->_y + _talk->_h - 1); spike->_z = 126; spike->_flags._slav = true; spike->_flags._kill = true; - spike->setName(Text->getText(SAY_NAME)); + spike->setName(_text->getText(SAY_NAME)); spike->step(east); spike->_ref = SAY_REF; - Vga->ShowQ->Insert(Talk, Vga->ShowQ->Last()); - Vga->ShowQ->Insert(spike, Vga->ShowQ->Last()); + Vga->_showQ->insert(_talk, Vga->_showQ->last()); + Vga->_showQ->insert(spike, Vga->_showQ->last()); } } void CGEEngine::inf(const char *txt) { - KillText(); - Talk = new TALK(this, txt, RECT); - if (Talk) { - Talk->_flags._kill = true; - Talk->_flags._bDel = true; - Talk->setName(Text->getText(INF_NAME)); - Talk->center(); - Talk->gotoxy(Talk->_x, Talk->_y - 20); - Talk->_z = 126; - Talk->_ref = INF_REF; - Vga->ShowQ->Insert(Talk, Vga->ShowQ->Last()); + killText(); + _talk = new Talk(this, txt, RECT); + if (_talk) { + _talk->_flags._kill = true; + _talk->_flags._bDel = true; + _talk->setName(_text->getText(INF_NAME)); + _talk->center(); + _talk->gotoxy(_talk->_x, _talk->_y - 20); + _talk->_z = 126; + _talk->_ref = INF_REF; + Vga->_showQ->insert(_talk, Vga->_showQ->last()); } } -void SayTime(Sprite *spr) { +void sayTime(Sprite *spr) { /* static char t[] = "00:00"; struct time ti; @@ -243,13 +243,13 @@ void SayTime(Sprite *spr) { wtom(ti.ti_min, t+3, 10, 2); Say((*t == '0') ? (t+1) : t, spr); */ - warning("STUB: SayTime"); + warning("STUB: sayTime"); } -void KillText(void) { - if (Talk) { - SNPOST_(SNKILL, -1, 0, Talk); - Talk = NULL; +void killText() { + if (_talk) { + SNPOST_(SNKILL, -1, 0, _talk); + _talk = NULL; } } diff --git a/engines/cge/text.h b/engines/cge/text.h index 5232084738f..cf917ece618 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -51,35 +51,33 @@ namespace CGE { #define SAY_REF 302 -class TEXT { - struct HAN { - int Ref; - char *Txt; - } *Cache; - int Size; - char FileName[MAXPATH]; - char *Load(int idx, int ref); - int Find(int ref); +class Text { + struct Han { + int _ref; + char *_txt; + } *_cache; + int _size; + char _fileName[MAXPATH]; + char *load(int idx, int ref); + int find(int ref); public: - TEXT(CGEEngine *vm, const char *fname, int size); - ~TEXT(void); - void Clear(int from = 1, int upto = 0x7FFF); - void Preload(int from = 1, int upto = 0x7FFF); + Text(CGEEngine *vm, const char *fname, int size); + ~Text(); + void clear(int from = 1, int upto = 0x7FFF); + void preload(int from = 1, int upto = 0x7FFF); char *getText(int ref); - void Say(const char *txt, Sprite *spr); + void say(const char *txt, Sprite *spr); private: CGEEngine *_vm; }; +extern Talk *_talk; +extern Text *_text; -extern TALK *Talk; -extern TEXT *Text; - - -void Say(const char *txt, Sprite *spr); -void SayTime(Sprite *spr); -void Inf(const char *txt); -void KillText(void); +void say(const char *txt, Sprite *spr); +void sayTime(Sprite *spr); +void inf(const char *txt); +void killText(); } // End of namespace CGE diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 35d9688bd36..36661e756ec 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -187,17 +187,17 @@ Dac MkDAC(uint8 r, uint8 g, uint8 b) { Rgb MkRGB(uint8 r, uint8 g, uint8 b) { - static TRGB x; - x.dac._r = r; - x.dac._g = g; - x.dac._b = b; - return x.rgb; + static Trgb x; + x._dac._r = r; + x._dac._g = g; + x._dac._b = b; + return x._rgb; } Sprite *Locate(int ref) { - Sprite *spr = Vga->ShowQ->Locate(ref); - return (spr) ? spr : Vga->SpareQ->Locate(ref); + Sprite *spr = Vga->_showQ->locate(ref); + return (spr) ? spr : Vga->_spareQ->locate(ref); } @@ -364,7 +364,7 @@ BMP_PTR Sprite::shp() { register SprExt *e = _ext; if (e) if (e->_seq) { - int i = e->_seq[_seqPtr].Now; + int i = e->_seq[_seqPtr]._now; if (i >= _shpCnt) { //char s[256]; //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", @@ -443,7 +443,7 @@ bool Sprite::seqTest(int n) { if (n >= 0) return (_seqPtr == n); if (_ext) - return (_ext->_seq[_seqPtr].Next == _seqPtr); + return (_ext->_seq[_seqPtr]._next == _seqPtr); return true; } @@ -519,23 +519,23 @@ Sprite *Sprite::expand() { if (seq == NULL) error("No core [%s]", fname); Seq *s = &seq[seqcnt++]; - s->Now = atoi(strtok(NULL, " \t,;/")); - if (s->Now > maxnow) - maxnow = s->Now; - s->Next = atoi(strtok(NULL, " \t,;/")); - switch (s->Next) { + s->_now = atoi(strtok(NULL, " \t,;/")); + if (s->_now > maxnow) + maxnow = s->_now; + s->_next = atoi(strtok(NULL, " \t,;/")); + switch (s->_next) { case 0xFF : - s->Next = seqcnt; + s->_next = seqcnt; break; case 0xFE : - s->Next = seqcnt - 1; + s->_next = seqcnt - 1; break; } - if (s->Next > maxnxt) - maxnxt = s->Next; - s->Dx = atoi(strtok(NULL, " \t,;/")); - s->Dy = atoi(strtok(NULL, " \t,;/")); - s->Dly = atoi(strtok(NULL, " \t,;/")); + if (s->_next > maxnxt) + maxnxt = s->_next; + s->_dx = atoi(strtok(NULL, " \t,;/")); + s->_dy = atoi(strtok(NULL, " \t,;/")); + s->_dly = atoi(strtok(NULL, " \t,;/")); break; } case 3 : { // Near @@ -645,11 +645,11 @@ void Sprite::step(int nr) { if (_ext) { Seq *seq; if (nr < 0) - _seqPtr = _ext->_seq[_seqPtr].Next; + _seqPtr = _ext->_seq[_seqPtr]._next; seq = _ext->_seq + _seqPtr; - if (seq->Dly >= 0) { - gotoxy(_x + (seq->Dx), _y + (seq->Dy)); - _time = seq->Dly; + if (seq->_dly >= 0) { + gotoxy(_x + (seq->_dx), _y + (seq->_dy)); + _time = seq->_dly; } } } @@ -781,7 +781,7 @@ BMP_PTR Sprite::ghost() { Sprite *SpriteAt(int x, int y) { - Sprite *spr = NULL, * tail = Vga->ShowQ->Last(); + Sprite *spr = NULL, * tail = Vga->_showQ->last(); if (tail) { for (spr = tail->_prev; spr; spr = spr->_prev) { if (! spr->_flags._hide && ! spr->_flags._tran) { @@ -794,26 +794,26 @@ Sprite *SpriteAt(int x, int y) { } -QUEUE::QUEUE(bool show) : Head(NULL), Tail(NULL), Show(show) { +Queue::Queue(bool show) : _head(NULL), _tail(NULL), _show(show) { } -QUEUE::~QUEUE(void) { - Clear(); +Queue::~Queue() { + clear(); } -void QUEUE::Clear(void) { - while (Head) { - Sprite *s = Remove(Head); +void Queue::clear() { + while (_head) { + Sprite *s = remove(_head); if (s->_flags._kill) delete s; } } -void QUEUE::ForAll(void (*fun)(Sprite *)) { - Sprite *s = Head; +void Queue::forAll(void (*fun)(Sprite *)) { + Sprite *s = _head; while (s) { Sprite *n = s->_next; fun(s); @@ -822,26 +822,26 @@ void QUEUE::ForAll(void (*fun)(Sprite *)) { } -void QUEUE::Append(Sprite *spr) { - if (Tail) { - spr->_prev = Tail; - Tail->_next = spr; +void Queue::append(Sprite *spr) { + if (_tail) { + spr->_prev = _tail; + _tail->_next = spr; } else - Head = spr; - Tail = spr; - if (Show) + _head = spr; + _tail = spr; + if (_show) spr->expand(); else spr->contract(); } -void QUEUE::Insert(Sprite *spr, Sprite *nxt) { - if (nxt == Head) { - spr->_next = Head; - Head = spr; - if (! Tail) - Tail = spr; +void Queue::insert(Sprite *spr, Sprite *nxt) { + if (nxt == _head) { + spr->_next = _head; + _head = spr; + if (!_tail) + _tail = spr; } else { spr->_next = nxt; spr->_prev = nxt->_prev; @@ -850,34 +850,34 @@ void QUEUE::Insert(Sprite *spr, Sprite *nxt) { } if (spr->_next) spr->_next->_prev = spr; - if (Show) + if (_show) spr->expand(); else spr->contract(); } -void QUEUE::Insert(Sprite *spr) { +void Queue::insert(Sprite *spr) { Sprite *s; - for (s = Head; s; s = s->_next) + for (s = _head; s; s = s->_next) if (s->_z > spr->_z) break; if (s) - Insert(spr, s); + insert(spr, s); else - Append(spr); - if (Show) + append(spr); + if (_show) spr->expand(); else spr->contract(); } -Sprite *QUEUE::Remove(Sprite *spr) { - if (spr == Head) - Head = spr->_next; - if (spr == Tail) - Tail = spr->_prev; +Sprite *Queue::remove(Sprite *spr) { + if (spr == _head) + _head = spr->_next; + if (spr == _tail) + _tail = spr->_prev; if (spr->_next) spr->_next->_prev = spr->_prev; if (spr->_prev) @@ -888,9 +888,9 @@ Sprite *QUEUE::Remove(Sprite *spr) { } -Sprite *QUEUE::Locate(int ref) { +Sprite *Queue::locate(int ref) { Sprite *spr; - for (spr = Head; spr; spr = spr->_next) { + for (spr = _head; spr; spr = spr->_next) { if (spr->_ref == ref) return spr; } @@ -925,13 +925,13 @@ VGA::VGA(int mode) Msg(NULL), Nam(NULL), SetPal(false), Mono(0) { OldColors = NULL; NewColors = NULL; - ShowQ = new QUEUE(true); - SpareQ = new QUEUE(false); + _showQ = new Queue(true); + _spareQ = new Queue(false); bool std = true; int i; for (i = 10; i < 20; i++) { - char *txt = Text->getText(i); + char *txt = _text->getText(i); if (txt) { debugN("%s", txt); std = false; @@ -981,8 +981,8 @@ VGA::~VGA(void) { debugN("%s", buffer.c_str()); } - delete ShowQ; - delete SpareQ; + delete _showQ; + delete _spareQ; } @@ -1131,12 +1131,12 @@ void VGA::Sunset(void) { void VGA::Show(void) { - Sprite *spr = ShowQ->First(); + Sprite *spr = _showQ->first(); - for (spr = ShowQ->First(); spr; spr = spr->_next) + for (spr = _showQ->first(); spr; spr = spr->_next) spr->show(); Update(); - for (spr = ShowQ->First(); spr; spr = spr->_next) + for (spr = _showQ->first(); spr; spr = spr->_next) spr->hide(); ++ FrmCnt; diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index a063e405083..9e49b3d9188 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -81,32 +81,32 @@ namespace CGE { struct Rgb { - uint16 r : 2; - uint16 R : 6; - uint16 g : 2; - uint16 G : 6; - uint16 b : 2; - uint16 B : 6; + uint16 _r : 2; + uint16 _R : 6; + uint16 _g : 2; + uint16 _G : 6; + uint16 _b : 2; + uint16 _B : 6; }; typedef union { - Dac dac; - Rgb rgb; -} TRGB; + Dac _dac; + Rgb _rgb; +} Trgb; struct VgaRegBlk { - uint8 idx; - uint8 adr; - uint8 clr; - uint8 set; + uint8 _idx; + uint8 _adr; + uint8 _clr; + uint8 _set; }; struct Seq { - uint8 Now; - uint8 Next; - int8 Dx; - int8 Dy; - int Dly; + uint8 _now; + uint8 _next; + int8 _dx; + int8 _dy; + int _dly; }; extern Seq _seq1[]; @@ -236,25 +236,27 @@ private: }; -class QUEUE { - Sprite *Head, * Tail; +class Queue { + Sprite *_head, *_tail; public: - bool Show; - QUEUE(bool show); - ~QUEUE(void); - void Append(Sprite *spr); - void Insert(Sprite *spr, Sprite *nxt); - void Insert(Sprite *spr); - Sprite *Remove(Sprite *spr); - void ForAll(void (*fun)(Sprite *)); - Sprite *First(void) { - return Head; + Queue(bool show); + ~Queue(); + + bool _show; + + void append(Sprite *spr); + void insert(Sprite *spr, Sprite *nxt); + void insert(Sprite *spr); + Sprite *remove(Sprite *spr); + void forAll(void (*fun)(Sprite *)); + Sprite *first() { + return _head; } - Sprite *Last(void) { - return Tail; + Sprite *last() { + return _tail; } - Sprite *Locate(int ref); - void Clear(void); + Sprite *locate(int ref); + void clear(); }; @@ -275,7 +277,8 @@ class VGA { void WaitVR(bool on); public: uint32 FrmCnt; - QUEUE *ShowQ, *SpareQ; + Queue *_showQ; + Queue *_spareQ; int Mono; static Graphics::Surface *Page[4]; static Dac *SysPal; diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 8ad3848cdbc..7ea32ff0236 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -44,7 +44,7 @@ namespace CGE { -MENU_BAR::MENU_BAR(CGEEngine *vm, uint16 w) : TALK(vm), _vm(vm) { +MENU_BAR::MENU_BAR(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h; uint8 *p = farnew(uint8, i), * p1, * p2; @@ -59,8 +59,8 @@ MENU_BAR::MENU_BAR(CGEEngine *vm, uint16 w) : TALK(vm), _vm(vm) { p1 += w; p2 -= w; } - TS[0] = new Bitmap(w, h, p); - setShapeList(TS); + _ts[0] = new Bitmap(w, h, p); + setShapeList(_ts); _flags._slav = true; _flags._tran = true; _flags._kill = true; @@ -98,7 +98,7 @@ int VMENU::Recent = -1; VMENU::VMENU(CGEEngine *vm, CHOICE *list, int x, int y) - : TALK(vm, VMGather(list), RECT), Menu(list), Bar(NULL), _vm(vm) { + : Talk(vm, VMGather(list), RECT), Menu(list), Bar(NULL), _vm(vm) { CHOICE *cp; Addr = this; @@ -112,10 +112,10 @@ VMENU::VMENU(CGEEngine *vm, CHOICE *list, int x, int y) center(); else gotoxy(x - _w / 2, y - (TEXT_VM + FONT_HIG / 2)); - Vga->ShowQ->Insert(this, Vga->ShowQ->Last()); + Vga->_showQ->insert(this, Vga->_showQ->last()); Bar = new MENU_BAR(_vm, _w - 2 * TEXT_HM); Bar->gotoxy(_x + TEXT_HM - MB_HM, _y + TEXT_VM - MB_VM); - Vga->ShowQ->Insert(Bar, Vga->ShowQ->Last()); + Vga->_showQ->insert(Bar, Vga->_showQ->last()); } diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index c2fc096e830..88a27660400 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -42,7 +42,7 @@ typedef struct { } CHOICE; -class MENU_BAR : public TALK { +class MENU_BAR : public Talk { public: MENU_BAR(CGEEngine *vm, uint16 w); private: @@ -50,7 +50,7 @@ private: }; -class VMENU : public TALK { +class VMENU : public Talk { uint16 Items; CHOICE *Menu; public: From ecad39e246475603b7ee55f7df73a77c32b60ba6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Jul 2011 20:20:01 +1000 Subject: [PATCH 074/276] CGE: Implemented code for game tick --- engines/cge/cge.h | 1 + engines/cge/cge_main.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index e4bb260bcce..ba6326726a2 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -45,6 +45,7 @@ enum { class CGEEngine : public Engine { private: uint32 _lastFrame; + void tick(); public: CGEEngine(OSystem *syst, const ADGameDescription *gameDescription); ~CGEEngine(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 33abf7917d1..4bb954eaeda 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1537,8 +1537,21 @@ void CGEEngine::mainLoop() { millis = g_system->getMillis(); } _lastFrame = millis; + + // Dispatch the tick to any active objects + tick(); } +void CGEEngine::tick() { + for (Sprite *spr = Vga->ShowQ->First(); spr; spr = spr->_next) { + if (spr->_time) { + if (!spr->_flags._hide) { + if (--spr->_time == 0) + spr->tick(); + } + } + } +} void CGEEngine::loadUser() { // set scene From d1ef4021bc320cf1a328e58fabfbf4da60c1468e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Jul 2011 20:20:16 +1000 Subject: [PATCH 075/276] CGE: Bugfix for keyboard entry --- engines/cge/events.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 97385c3ae17..5f98cf34fb0 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -126,8 +126,8 @@ void Keyboard::NewKeyboard(Common::Event &event) { _key[event.kbd.keycode] = false; } else if (event.type == Common::EVENT_KEYDOWN) { // Key press - _key[event.kbd.keycode] = true; - _current = Keyboard::_code[event.kbd.keycode]; + _key[keycode] = true; + _current = Keyboard::_code[keycode]; if (_client) { CGEEvent &evt = Evt[EvtHead]; From 665b12ff8dfac9fc1d8fb97f80327e3bdcd20fb6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Jul 2011 20:23:19 +1000 Subject: [PATCH 076/276] CGE: Compilation fix after merge --- engines/cge/cge_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 4bb954eaeda..a2209e72e93 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1543,7 +1543,7 @@ void CGEEngine::mainLoop() { } void CGEEngine::tick() { - for (Sprite *spr = Vga->ShowQ->First(); spr; spr = spr->_next) { + for (Sprite *spr = Vga->_showQ->first(); spr; spr = spr->_next) { if (spr->_time) { if (!spr->_flags._hide) { if (--spr->_time == 0) From c313d2cce8d647265f192400c667d72824874dbc Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 3 Jul 2011 16:22:26 +0200 Subject: [PATCH 077/276] CGE: Even more renaming (WIP) --- engines/cge/cge.cpp | 20 +-- engines/cge/cge_main.cpp | 278 +++++++++++++++++++-------------------- engines/cge/cge_main.h | 6 +- engines/cge/config.cpp | 74 +++++------ engines/cge/events.cpp | 6 +- engines/cge/game.cpp | 8 +- engines/cge/jbw.h | 4 +- engines/cge/mixer.cpp | 6 +- engines/cge/snail.cpp | 112 ++++++++-------- engines/cge/text.cpp | 6 +- engines/cge/vga13h.cpp | 198 ++++++++++++++-------------- engines/cge/vga13h.h | 83 ++++++------ engines/cge/vmenu.cpp | 58 ++++---- engines/cge/vmenu.h | 26 ++-- engines/cge/vol.cpp | 34 ++--- engines/cge/vol.h | 24 ++-- 16 files changed, 472 insertions(+), 471 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 6eae8f3c0e8..04874415179 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -58,17 +58,17 @@ void CGEEngine::setup() { _console = new CGEConsole(this); // Initialise classes that have static members - VGA::init(); - VFILE::init(); + Vga::init(); + VFile::init(); Bitmap::init(); Talk::init(); // Initialise engine objects _text = new Text(this, progName(), 128); - Vga = new VGA(M13H); + _vga = new Vga(M13H); _heart = new Heart; - Hero = new WALK(this, NULL); - Sys = new SYSTEM(this); + _hero = new WALK(this, NULL); + _sys = new SYSTEM(this); _pocLight = new Sprite(this, LI); for (int i = 0; i < POCKET_NX; i++) _pocket[i] = new Sprite(this, NULL); @@ -111,8 +111,8 @@ CGEEngine::~CGEEngine() { // Call classes with static members to clear them up Talk::deinit(); Bitmap::deinit(); - VFILE::deinit(); - VGA::deinit(); + VFile::deinit(); + Vga::deinit(); // Remove all of our debug levels here DebugMan.clearAllDebugChannels(); @@ -147,9 +147,9 @@ CGEEngine::~CGEEngine() { delete _pocket[i]; delete _snail; delete _snail_; - delete Hero; - delete Vga; - delete Sys; + delete _hero; + delete _vga; + delete _sys; } Common::Error CGEEngine::run() { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index a2209e72e93..2caa9e0a98a 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -55,10 +55,10 @@ namespace CGE { uint16 _stklen = (STACK_SIZ * 2); -VGA *Vga; +Vga *_vga; Heart *_heart; -WALK *Hero; -SYSTEM *Sys; +WALK *_hero; +SYSTEM *_sys; Sprite *_pocLight; EventManager *_eventManager; Keyboard *_keyboard; @@ -252,12 +252,12 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { if (spr == NULL) error("No core"); *spr = S; - Vga->_spareQ->append(spr); + _vga->_spareQ->append(spr); } for (i = 0; i < POCKET_NX; i++) { register int r = _pocref[i]; - _pocket[i] = (r < 0) ? NULL : Vga->_spareQ->locate(r); + _pocket[i] = (r < 0) ? NULL : _vga->_spareQ->locate(r); } } } @@ -291,7 +291,7 @@ static void SaveGame(XFile &file) { file.write((uint8 *) & (i = SVGCHKSUM), sizeof(i)); - for (spr = Vga->_spareQ->first(); spr; spr = spr->_next) + for (spr = _vga->_spareQ->first(); spr; spr = spr->_next) if (spr->_ref >= 1000) if (!file._error) file.write((uint8 *)spr, sizeof(*spr)); @@ -304,12 +304,12 @@ static void HeroCover(int cvr) { static void trouble(int seq, int txt) { - Hero->park(); - SNPOST(SNWAIT, -1, -1, Hero); - SNPOST(SNSEQ, -1, seq, Hero); - SNPOST(SNSOUND, -1, 2, Hero); - SNPOST(SNWAIT, -1, -1, Hero); - SNPOST(SNSAY, 1, txt, Hero); + _hero->park(); + SNPOST(SNWAIT, -1, -1, _hero); + SNPOST(SNSEQ, -1, seq, _hero); + SNPOST(SNSOUND, -1, 2, _hero); + SNPOST(SNWAIT, -1, -1, _hero); + SNPOST(SNSAY, 1, txt, _hero); } @@ -366,8 +366,8 @@ void WALK::tick() { if (Dir != NO_DIR) { Sprite *spr; - Sys->FunTouch(); - for (spr = Vga->_showQ->first(); spr; spr = spr->_next) { + _sys->FunTouch(); + for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (distance(spr) < 2) { if (!spr->_flags._near) { feedSnail(spr, NEAR); @@ -495,7 +495,7 @@ bool WALK::lower(Sprite *spr) { void WALK::reach(Sprite *spr, int mode) { if (spr) { - Hero->findWay(spr); + _hero->findWay(spr); if (mode < 0) { mode = spr->_flags._east; if (lower(spr)) @@ -506,7 +506,7 @@ void WALK::reach(Sprite *spr, int mode) { SNINSERT(SNPAUSE, -1, 64, NULL); SNINSERT(SNSEQ, -1, TSEQ + mode, this); if (spr) { - SNINSERT(SNWAIT, -1, -1, Hero); /////--------$$$$$$$ + SNINSERT(SNWAIT, -1, -1, _hero); /////--------$$$$$$$ //SNINSERT(SNWALK, -1, -1, spr); } // sequence is not finished, @@ -548,12 +548,12 @@ void CGEEngine::setMapBrick(int x, int z) { wtom(z, n + 3, 10, 2); Cluster::_map[z][x] = 1; s->setName(n); - Vga->_showQ->insert(s, Vga->_showQ->first()); + _vga->_showQ->insert(s, _vga->_showQ->first()); } } static void SwitchColorMode(void); -static void SwitchDebug(void); +static void switchDebug(); static void SwitchMusic(void); static void KillSprite(void); static void PushSprite(void); @@ -573,20 +573,20 @@ void CGEEngine::resetQSwitch() { void CGEEngine::quit() { - static CHOICE QuitMenu[] = { + static Choice QuitMenu[] = { { NULL, &CGEEngine::startCountDown }, { NULL, &CGEEngine::resetQSwitch }, { NULL, &CGEEngine::dummy } }; - if (_snail->idle() && ! Hero->_flags._hide) { - if (VMENU::Addr) { - SNPOST_(SNKILL, -1, 0, VMENU::Addr); + if (_snail->idle() && !_hero->_flags._hide) { + if (Vmenu::_addr) { + SNPOST_(SNKILL, -1, 0, Vmenu::_addr); resetQSwitch(); } else { - QuitMenu[0].Text = _text->getText(QUIT_TEXT); - QuitMenu[1].Text = _text->getText(NOQUIT_TEXT); - (new VMENU(this, QuitMenu, -1, -1))->setName(_text->getText(QUIT_TITLE)); + QuitMenu[0]._text = _text->getText(QUIT_TEXT); + QuitMenu[1]._text = _text->getText(NOQUIT_TEXT); + (new Vmenu(this, QuitMenu, -1, -1))->setName(_text->getText(QUIT_TITLE)); SNPOST_(SNSEQ, 123, 1, NULL); KeyClick(); } @@ -595,7 +595,7 @@ void CGEEngine::quit() { static void AltCtrlDel() { - SNPOST_(SNSAY, -1, A_C_D_TEXT, Hero); + SNPOST_(SNSAY, -1, A_C_D_TEXT, _hero); } // Used in stubbed function, do not remove! @@ -622,7 +622,7 @@ static void PostMiniStep(int stp) { void SYSTEM::SetPal(void) { uint i; - Dac *p = VGA::SysPal + 256 - ArrayCount(_stdPal); + Dac *p = Vga::_sysPal + 256 - ArrayCount(_stdPal); for (i = 0; i < ArrayCount(_stdPal); i++) { p[i]._r = _stdPal[i]._r >> 2; p[i]._g = _stdPal[i]._g >> 2; @@ -639,14 +639,14 @@ void SYSTEM::FunTouch(void) { static void ShowBak(int ref) { - Sprite *spr = Vga->_spareQ->locate(ref); + Sprite *spr = _vga->_spareQ->locate(ref); if (spr) { - Bitmap::_pal = VGA::SysPal; + Bitmap::_pal = Vga::_sysPal; spr->expand(); Bitmap::_pal = NULL; spr->show(2); - Vga->CopyPage(1, 2); - Sys->SetPal(); + _vga->copyPage(1, 2); + _sys->SetPal(); spr->contract(); } } @@ -660,7 +660,7 @@ static void caveUp() { ShowBak(BakRef); loadMapping(); _text->preload(BakRef, BakRef + 1000); - Sprite *spr = Vga->_spareQ->first(); + Sprite *spr = _vga->_spareQ->first(); while (spr) { Sprite *n = spr->_next; if (spr->_cave == _now || spr->_cave == 0) @@ -679,33 +679,33 @@ static void caveUp() { _fx.Preload(BakRef); } - if (Hero) { - Hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); + if (_hero) { + _hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); // following 2 lines trims Hero's Z position! - Hero->tick(); - Hero->_time = 1; - Hero->_flags._hide = false; + _hero->tick(); + _hero->_time = 1; + _hero->_flags._hide = false; } if (!_dark) - Vga->Sunset(); + _vga->sunset(); - Vga->CopyPage(0, 1); + _vga->copyPage(0, 1); selectPocket(-1); - if (Hero) - Vga->_showQ->insert(Vga->_showQ->remove(Hero)); + if (_hero) + _vga->_showQ->insert(_vga->_showQ->remove(_hero)); if (_shadow) { - Vga->_showQ->remove(_shadow); - _shadow->makeXlat(glass(VGA::SysPal, 204, 204, 204)); - Vga->_showQ->insert(_shadow, Hero); - _shadow->_z = Hero->_z; + _vga->_showQ->remove(_shadow); + _shadow->makeXlat(glass(Vga::_sysPal, 204, 204, 204)); + _vga->_showQ->insert(_shadow, _hero); + _shadow->_z = _hero->_z; } - feedSnail(Vga->_showQ->locate(BakRef + 999), TAKE); - Vga->Show(); - Vga->CopyPage(1, 0); - Vga->Show(); - Vga->Sunrise(VGA::SysPal); + feedSnail(_vga->_showQ->locate(BakRef + 999), TAKE); + _vga->show(); + _vga->copyPage(1, 0); + _vga->show(); + _vga->sunrise(Vga::_sysPal); _dark = false; if (!_startup) _mouse->On(); @@ -719,12 +719,12 @@ void CGEEngine::caveDown() { if (!_horzLine->_flags._hide) switchMapping(); - for (spr = Vga->_showQ->first(); spr;) { + for (spr = _vga->_showQ->first(); spr;) { Sprite *n = spr->_next; if (spr->_ref >= 1000 /*&& spr->_cave*/) { if (spr->_ref % 1000 == 999) feedSnail(spr, TAKE); - Vga->_spareQ->append(Vga->_showQ->remove(spr)); + _vga->_spareQ->append(_vga->_showQ->remove(spr)); } spr = n; } @@ -744,7 +744,7 @@ void CGEEngine::qGame() { SaveSound(); CFile file = CFile(usrPath(_usrFnam), WRI, RCrypt); SaveGame(file); - Vga->Sunset(); + _vga->sunset(); _finis = true; } @@ -760,12 +760,12 @@ void CGEEngine::switchCave(int cav) { } else { _now = cav; _mouse->Off(); - if (Hero) { - Hero->park(); - Hero->step(0); + if (_hero) { + _hero->park(); + _hero->step(0); if (!_isDemo) ///// protection: auto-destruction on! ---------------------- - Vga->_spareQ->_show = Startup::_summa * (cav <= CAVE_MAX); + _vga->_spareQ->_show = Startup::_summa * (cav <= CAVE_MAX); /////-------------------------------------------------------- } _cavLight->gotoxy(CAVE_X + ((_now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, @@ -810,7 +810,7 @@ void SYSTEM::touch(uint16 mask, int x, int y) { break; case 'F': if (_keyboard->_key[ALT]) { - Sprite *m = Vga->_showQ->locate(17001); + Sprite *m = _vga->_showQ->locate(17001); if (m) { m->step(1); m->_time = 216; // 3s @@ -833,28 +833,28 @@ void SYSTEM::touch(uint16 mask, int x, int y) { _vm->switchMapping(); break; case F1: - SwitchDebug(); + switchDebug(); break; case F3: - Hero->step(TSEQ + 4); + _hero->step(TSEQ + 4); break; case F4: - Hero->step(TSEQ + 5); + _hero->step(TSEQ + 5); break; case F5: - Hero->step(TSEQ + 0); + _hero->step(TSEQ + 0); break; case F6: - Hero->step(TSEQ + 1); + _hero->step(TSEQ + 1); break; case F7: - Hero->step(TSEQ + 2); + _hero->step(TSEQ + 2); break; case F8: - Hero->step(TSEQ + 3); + _hero->step(TSEQ + 3); break; case F9: - Sys->FunDel = 1; + _sys->FunDel = 1; break; case 'X': if (_keyboard->_key[ALT]) @@ -878,16 +878,16 @@ void SYSTEM::touch(uint16 mask, int x, int y) { _sprite->step(x - '0'); break; case F10 : - if (_snail->idle() && ! Hero->_flags._hide) + if (_snail->idle() && !_hero->_flags._hide) _vm->startCountDown(); break; case 'J': if (pp == 0) - ++pp; + pp++; break; case 'B': if (pp == 1) - ++pp; + pp++; break; case 'W': if (pp == 2) @@ -923,7 +923,7 @@ void SYSTEM::touch(uint16 mask, int x, int y) { PostMiniStep(cav - 1); if (mask & L_UP) { - if (cav && _snail->idle() && Hero->_tracePtr < 0) + if (cav && _snail->idle() && _hero->_tracePtr < 0) _vm->switchCave(cav); if (!_horzLine->_flags._hide) { @@ -935,9 +935,9 @@ void SYSTEM::touch(uint16 mask, int x, int y) { } } else { - if (!_talk && _snail->idle() && Hero + if (!_talk && _snail->idle() && _hero && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && !_game) { - Hero->findWay(XZ(x, y)); + _hero->findWay(XZ(x, y)); } } } @@ -955,7 +955,7 @@ void SYSTEM::Tick(void) { else if (Startup::_core >= CORE_MID) { int n = new_random(100); if (n > 96) - HeroCover(6 + (Hero->_x + Hero->_w / 2 < SCR_WID / 2)); + HeroCover(6 + (_hero->_x + _hero->_w / 2 < SCR_WID / 2)); else { if (n > 90) HeroCover(5); @@ -994,17 +994,17 @@ static void SpkClose(void) { static void SwitchColorMode(void) { - SNPOST_(SNSEQ, 121, Vga->Mono = !Vga->Mono, NULL); + SNPOST_(SNSEQ, 121, _vga->_mono = !_vga->_mono, NULL); KeyClick(); - Vga->SetColors(VGA::SysPal, 64); + _vga->setColors(Vga::_sysPal, 64); } static void SwitchMusic(void) { if (_keyboard->_key[ALT]) { - if (VMENU::Addr) - SNPOST_(SNKILL, -1, 0, VMENU::Addr); + if (Vmenu::_addr) + SNPOST_(SNKILL, -1, 0, Vmenu::_addr); else { SNPOST_(SNSEQ, 122, (_music = false), NULL); //TODO Change the SNPOST message send to a special way to send function pointer @@ -1042,7 +1042,7 @@ void CGEEngine::takeName() { tn->center(); tn->gotoxy(tn->_x, tn->_y - 10); tn->_z = 126; - Vga->_showQ->insert(tn); + _vga->_showQ->insert(tn); } } } @@ -1060,7 +1060,7 @@ void CGEEngine::switchMapping() { } } else { Sprite *s; - for (s = Vga->_showQ->first(); s; s = s->_next) + for (s = _vga->_showQ->first(); s; s = s->_next) if (s->_w == MAP_XGRID && s->_h == MAP_ZGRID) SNPOST_(SNKILL, -1, 0, s); } @@ -1079,7 +1079,7 @@ static void KillSprite(void) { static void PushSprite(void) { Sprite *spr = _sprite->_prev; if (spr) { - Vga->_showQ->insert(Vga->_showQ->remove(_sprite), spr); + _vga->_showQ->insert(_vga->_showQ->remove(_sprite), spr); while (_sprite->_z > _sprite->_next->_z) _sprite->_z--; } else @@ -1096,7 +1096,7 @@ static void PullSprite(void) { ok = (!spr->_flags._slav); } if (ok) { - Vga->_showQ->insert(Vga->_showQ->remove(_sprite), spr); + _vga->_showQ->insert(_vga->_showQ->remove(_sprite), spr); if (_sprite->_prev) while (_sprite->_z < _sprite->_prev->_z) _sprite->_z++; @@ -1121,8 +1121,8 @@ static void SaveMapping() { { IoHand cf(progName(".HXY"), WRI); if (!cf._error) { - _heroXY[_now - 1]._x = Hero->_x; - _heroXY[_now - 1]._y = Hero->_y; + _heroXY[_now - 1]._x = _hero->_x; + _heroXY[_now - 1]._y = _hero->_y; cf.write((uint8 *) _heroXY, sizeof(_heroXY)); } } @@ -1156,7 +1156,7 @@ static void sayDebug() { if (t1 - t >= 18) { static uint32 old = 0L; - uint32 now = Vga->FrmCnt; + uint32 now = _vga->_frmCnt; dwtom(now - old, FRPS, 10, 4); old = now; t = t1; @@ -1170,7 +1170,7 @@ static void sayDebug() { // sprite queue size uint16 n = 0; Sprite *spr; - for (spr = Vga->_showQ->first(); spr; spr = spr->_next) { + for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { ++ n; if (spr == _sprite) { *XSPR = ' '; @@ -1190,7 +1190,7 @@ static void sayDebug() { } -static void SwitchDebug(void) { +static void switchDebug() { _debugLine->_flags._hide = !_debugLine->_flags._hide; } @@ -1220,7 +1220,7 @@ void CGEEngine::optionTouch(int opt, uint16 mask) { #pragma argsused void Sprite::touch(uint16 mask, int x, int y) { - Sys->FunTouch(); + _sys->FunTouch(); if ((mask & ATTN) == 0) { _infoLine->update(name()); if (mask & (R_DN | L_DN)) @@ -1238,7 +1238,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if ((mask & R_UP) && _snail->idle()) { Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_pocPtr] : NULL; if (ps) { - if (_flags._kept || Hero->distance(this) < MAX_DISTANCE) { + if (_flags._kept || _hero->distance(this) < MAX_DISTANCE) { if (works(ps)) { feedSnail(ps, TAKE); } else @@ -1250,7 +1250,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if (_flags._kept) mask |= L_UP; else { - if (Hero->distance(this) < MAX_DISTANCE) { + if (_hero->distance(this) < MAX_DISTANCE) { /// if (_flags._port) { if (findPocket(NULL) < 0) @@ -1369,9 +1369,9 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int WALK *w = new WALK(this, NULL); if (w && ref == 1) { w->gotoxy(col, row); - if (Hero) + if (_hero) error("2nd HERO [%s]", fname); - Hero = w; + _hero = w; } _sprite = w; break; @@ -1440,7 +1440,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int *p = '\0'; _sprite->_shpCnt = shpcnt; - Vga->_spareQ->append(_sprite); + _vga->_spareQ->append(_sprite); } } @@ -1522,7 +1522,7 @@ void CGEEngine::mainLoop() { //FIXME: tc = TimerCount; } } - Vga->Show(); + _vga->show(); _snail_->runCom(); _snail->runCom(); @@ -1543,7 +1543,7 @@ void CGEEngine::mainLoop() { } void CGEEngine::tick() { - for (Sprite *spr = Vga->_showQ->first(); spr; spr = spr->_next) { + for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (spr->_time) { if (!spr->_flags._hide) { if (--spr->_time == 0) @@ -1583,7 +1583,7 @@ void CGEEngine::runGame() { loadHeroXY(); _cavLight->_flags._tran = true; - Vga->_showQ->append(_cavLight); + _vga->_showQ->append(_cavLight); _cavLight->_flags._hide = true; static Seq pocSeq[] = { { 0, 0, 0, 0, 20 }, @@ -1598,7 +1598,7 @@ void CGEEngine::runGame() { _pocLight->_flags._tran = true; _pocLight->_time = 1; _pocLight->_z = 120; - Vga->_showQ->append(_pocLight); + _vga->_showQ->append(_pocLight); selectPocket(-1); // FIXME: Allow ScummVM to handle mouse display @@ -1608,9 +1608,9 @@ void CGEEngine::runGame() { loadUser(); // ~~~~~~~~~~~ - if ((_sprite = Vga->_spareQ->locate(121)) != NULL) - SNPOST_(SNSEQ, -1, Vga->Mono, _sprite); - if ((_sprite = Vga->_spareQ->locate(122)) != NULL) + if ((_sprite = _vga->_spareQ->locate(121)) != NULL) + SNPOST_(SNSEQ, -1, _vga->_mono, _sprite); + if ((_sprite = _vga->_spareQ->locate(122)) != NULL) _sprite->step(_music); SNPOST_(SNSEQ, -1, _music, _sprite); if (!_music) @@ -1631,16 +1631,16 @@ void CGEEngine::runGame() { } } - if (Hero) { - ExpandSprite(Hero); - Hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); + if (_hero) { + ExpandSprite(_hero); + _hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); if (INI_FILE::exist("00SHADOW.SPR")) { - loadSprite("00SHADOW", -1, 0, Hero->_x + 14, Hero->_y + 51); + loadSprite("00SHADOW", -1, 0, _hero->_x + 14, _hero->_y + 51); if ((_shadow = _sprite) != NULL) { _shadow->_ref = 2; _shadow->_flags._tran = true; - Hero->_flags._shad = true; - Vga->_showQ->insert(Vga->_spareQ->remove(_shadow), Hero); + _hero->_flags._shad = true; + _vga->_showQ->insert(_vga->_spareQ->remove(_shadow), _hero); } } } @@ -1648,16 +1648,16 @@ void CGEEngine::runGame() { _infoLine->gotoxy(INFO_X, INFO_Y); _infoLine->_flags._tran = true; _infoLine->update(NULL); - Vga->_showQ->insert(_infoLine); + _vga->_showQ->insert(_infoLine); _debugLine->_z = 126; - Vga->_showQ->insert(_debugLine); + _vga->_showQ->insert(_debugLine); _horzLine->_y = MAP_TOP - (MAP_TOP > 0); _horzLine->_z = 126; - Vga->_showQ->insert(_horzLine); + _vga->_showQ->insert(_horzLine); - _mouse->Busy = Vga->_spareQ->locate(BUSY_REF); + _mouse->Busy = _vga->_spareQ->locate(BUSY_REF); if (_mouse->Busy) ExpandSprite(_mouse->Busy); @@ -1668,7 +1668,7 @@ void CGEEngine::runGame() { CAVE_Y + ((_now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); caveUp(); - _keyboard->setClient(Sys); + _keyboard->setClient(_sys); // main loop while (!_finis && !_eventManager->_quitFlag) { //TODO Change the SNPOST message send to a special way to send function pointer @@ -1682,9 +1682,9 @@ void CGEEngine::runGame() { SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); _mouse->Off(); - Vga->_showQ->clear(); - Vga->_spareQ->clear(); - Hero = NULL; + _vga->_showQ->clear(); + _vga->_spareQ->clear(); + _hero = NULL; _shadow = NULL; } @@ -1696,14 +1696,14 @@ void CGEEngine::movie(const char *ext) { const char *fn = progName(ext); if (INI_FILE::exist(fn)) { loadScript(fn); - ExpandSprite(Vga->_spareQ->locate(999)); - feedSnail(Vga->_showQ->locate(999), TAKE); + ExpandSprite(_vga->_spareQ->locate(999)); + feedSnail(_vga->_showQ->locate(999), TAKE); // FIXME: Allow ScummVM to handle mouse display //Vga->ShowQ->Append(Mouse); _heart->_enable = true; - _keyboard->setClient(Sys); + _keyboard->setClient(_sys); while (!_snail->idle() && !_eventManager->_quitFlag) mainLoop(); @@ -1711,8 +1711,8 @@ void CGEEngine::movie(const char *ext) { _heart->_enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); - Vga->_showQ->clear(); - Vga->_spareQ->clear(); + _vga->_showQ->clear(); + _vga->_spareQ->clear(); } } @@ -1721,7 +1721,7 @@ bool CGEEngine::showTitle(const char *name) { if (_eventManager->_quitFlag) return false; - Bitmap::_pal = VGA::SysPal; + Bitmap::_pal = Vga::_sysPal; BMP_PTR LB[] = { new Bitmap(name, true), NULL }; Bitmap::_pal = NULL; bool usr_ok = false; @@ -1737,19 +1737,19 @@ bool CGEEngine::showTitle(const char *name) { _talk->show(2); } - Vga->Sunset(); - Vga->CopyPage(1, 2); - Vga->CopyPage(0, 1); + _vga->sunset(); + _vga->copyPage(1, 2); + _vga->copyPage(0, 1); selectPocket(-1); - Vga->Sunrise(VGA::SysPal); + _vga->sunrise(Vga::_sysPal); if (Startup::_mode < 2 && !Startup::_soundOk) { - Vga->CopyPage(1, 2); - Vga->CopyPage(0, 1); - Vga->_showQ->append(_mouse); + _vga->copyPage(1, 2); + _vga->copyPage(0, 1); + _vga->_showQ->append(_mouse); _heart->_enable = true; _mouse->On(); - for (selectSound(); !_snail->idle() || VMENU::Addr;) { + for (selectSound(); !_snail->idle() || Vmenu::_addr;) { mainLoop(); if (_eventManager->_quitFlag) return false; @@ -1757,8 +1757,8 @@ bool CGEEngine::showTitle(const char *name) { _mouse->Off(); _heart->_enable = false; - Vga->_showQ->clear(); - Vga->CopyPage(0, 2); + _vga->_showQ->clear(); + _vga->copyPage(0, 2); Startup::_soundOk = 2; if (_music) LoadMIDI(0); @@ -1779,9 +1779,9 @@ bool CGEEngine::showTitle(const char *name) { #endif //----------------------------------------- movie("X00"); // paylist - Vga->CopyPage(1, 2); - Vga->CopyPage(0, 1); - Vga->_showQ->append(_mouse); + _vga->copyPage(1, 2); + _vga->copyPage(0, 1); + _vga->_showQ->append(_mouse); //Mouse.On(); _heart->_enable = true; for (takeName(); GetText::_ptr;) { @@ -1795,8 +1795,8 @@ bool CGEEngine::showTitle(const char *name) { if (usr_ok) strcat(_usrFnam, SVG_EXT); //Mouse.Off(); - Vga->_showQ->clear(); - Vga->CopyPage(0, 2); + _vga->_showQ->clear(); + _vga->copyPage(0, 2); #endif } @@ -1805,8 +1805,8 @@ bool CGEEngine::showTitle(const char *name) { if (CFile::exist(n)) { CFile file = CFile(n, REA, RCrypt); loadGame(file, true); // only system vars - Vga->SetColors(VGA::SysPal, 64); - Vga->Update(); + _vga->setColors(Vga::_sysPal, 64); + _vga->update(); if (FINIS) { Startup::_mode++; FINIS = false; @@ -1819,7 +1819,7 @@ bool CGEEngine::showTitle(const char *name) { if (Startup::_mode < 2) movie("X01"); // wink - Vga->CopyPage(0, 2); + _vga->copyPage(0, 2); if (_isDemo) return true; @@ -1854,7 +1854,7 @@ void CGEEngine::cge_main(void) { _horzLine->_flags._hide = true; //srand((uint16) Timer()); - Sys = new SYSTEM(this); + _sys = new SYSTEM(this); if (_music && Startup::_soundOk) LoadMIDI(0); @@ -1869,7 +1869,7 @@ void CGEEngine::cge_main(void) { if (FINIS) movie("X03"); } else - Vga->Sunset(); + _vga->sunset(); } } // End of namespace CGE diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 0684a886e5a..c5be2adc26e 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -166,10 +166,10 @@ Cluster XZ(Couple xy); void ExpandSprite(Sprite *spr); void ContractSprite(Sprite *spr); -extern WALK *Hero; -extern VGA *Vga; +extern WALK *_hero; +extern Vga *_vga; extern Heart *_heart; -extern SYSTEM *Sys; +extern SYSTEM *_sys; extern int _offUseCount; extern Sprite *_pocLight; extern Keyboard *_keyboard; diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index f32c3b71952..88122073719 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -64,7 +64,7 @@ static int DevName[] = { MIDI_TEXT, AUTO_TEXT }; -static CHOICE DevMenu[] = { +static Choice DevMenu[] = { { NULL, &CGEEngine::NONE }, { NULL, &CGEEngine::SB }, { NULL, &CGEEngine::SBM }, @@ -76,7 +76,7 @@ static CHOICE DevMenu[] = { }; -static CHOICE DigiPorts[] = { +static Choice DigiPorts[] = { { " 210h", &CGEEngine::setPortD }, { " 220h", &CGEEngine::setPortD }, { " 230h", &CGEEngine::setPortD }, @@ -87,7 +87,7 @@ static CHOICE DigiPorts[] = { { NULL, NULL } }; -static CHOICE MIDIPorts[] = { +static Choice MIDIPorts[] = { { " 220h", &CGEEngine::setPortM }, { " 230h", &CGEEngine::setPortM }, { " 240h", &CGEEngine::setPortM }, @@ -102,7 +102,7 @@ static CHOICE MIDIPorts[] = { { NULL, NULL } }; -static CHOICE BlsterIRQ[] = { +static Choice BlsterIRQ[] = { { "IRQ 2", &CGEEngine::setIRQ }, { "IRQ 5", &CGEEngine::setIRQ }, { "IRQ 7", &CGEEngine::setIRQ }, @@ -111,7 +111,7 @@ static CHOICE BlsterIRQ[] = { { NULL, NULL } }; -static CHOICE GravisIRQ[] = { +static Choice GravisIRQ[] = { { "IRQ 2", &CGEEngine::setIRQ }, { "IRQ 5", &CGEEngine::setIRQ }, { "IRQ 7", &CGEEngine::setIRQ }, @@ -122,7 +122,7 @@ static CHOICE GravisIRQ[] = { { NULL, NULL } }; -static CHOICE GravisDMA[] = { +static Choice GravisDMA[] = { { "DMA 1", &CGEEngine::setDMA }, { "DMA 3", &CGEEngine::setDMA }, { "DMA 5", &CGEEngine::setDMA }, @@ -132,7 +132,7 @@ static CHOICE GravisDMA[] = { { NULL, NULL } }; -static CHOICE BlsterDMA[] = { +static Choice BlsterDMA[] = { { "DMA 0", &CGEEngine::setDMA }, { "DMA 1", &CGEEngine::setDMA }, { "DMA 3", &CGEEngine::setDMA }, @@ -144,17 +144,17 @@ static CHOICE BlsterDMA[] = { void CGEEngine::selectSound() { int i; _sound.Close(); - if (VMENU::Addr) - SNPOST_(SNKILL, -1, 0, VMENU::Addr); + if (Vmenu::_addr) + SNPOST_(SNKILL, -1, 0, Vmenu::_addr); inf(_text->getText(STYPE_TEXT)); _talk->gotoxy(_talk->_x, FONT_HIG / 2); for (i = 0; i < (int)ArrayCount(DevName); i++) - DevMenu[i].Text = _text->getText(DevName[i]); - (new VMENU(this, DevMenu, SCR_WID / 2, _talk->_y + _talk->_h + TEXT_VM + FONT_HIG))->setName(_text->getText(MENU_TEXT)); + DevMenu[i]._text = _text->getText(DevName[i]); + (new Vmenu(this, DevMenu, SCR_WID / 2, _talk->_y + _talk->_h + TEXT_VM + FONT_HIG))->setName(_text->getText(MENU_TEXT)); } -static void Reset(void) { +static void reset(void) { _sndDrvInfo._dBase = _sndDrvInfo._dIrq = _sndDrvInfo._dDma = _sndDrvInfo._mBase = DETECT; } @@ -179,22 +179,22 @@ static uint16 xdeco(const char *str) { } -static CHOICE *Cho; -static int Hlp; +static Choice *_cho; +static int _hlp; void CGEEngine::SNSelect() { - inf(_text->getText(Hlp)); + inf(_text->getText(_hlp)); _talk->gotoxy(_talk->_x, FONT_HIG / 2); - (new VMENU(this, Cho, SCR_WID / 2, _talk->_y + _talk->_h + TEXT_VM + FONT_HIG))->setName(_text->getText(MENU_TEXT)); + (new Vmenu(this, _cho, SCR_WID / 2, _talk->_y + _talk->_h + TEXT_VM + FONT_HIG))->setName(_text->getText(MENU_TEXT)); } -static void Select(CHOICE *cho, int hlp) { - Cho = cho; - Hlp = hlp; +static void select(Choice *cho, int hlp) { + _cho = cho; + _hlp = hlp; //TODO Change the SNPOST message send to a special way to send function pointer //SNPOST(SNEXEC, -1, 0, (void *)&SNSelect); - warning("STUB: Select"); + warning("STUB: select"); } @@ -208,32 +208,32 @@ void CGEEngine::NONE() { void CGEEngine::SB() { _sndDrvInfo._dDev = DEV_SB; _sndDrvInfo._mDev = DEV_SB; - Reset(); - Select(DigiPorts, SPORT_TEXT); + reset(); + select(DigiPorts, SPORT_TEXT); } void CGEEngine::SBM() { _sndDrvInfo._dDev = DEV_SB; _sndDrvInfo._mDev = DEV_GM; - Reset(); - Select(DigiPorts, SPORT_TEXT); + reset(); + select(DigiPorts, SPORT_TEXT); } void CGEEngine::GUS() { _sndDrvInfo._dDev = DEV_GUS; _sndDrvInfo._mDev = DEV_GUS; - Reset(); - Select(DigiPorts, SPORT_TEXT); + reset(); + select(DigiPorts, SPORT_TEXT); } void CGEEngine::GUSM() { _sndDrvInfo._dDev = DEV_GUS; _sndDrvInfo._mDev = DEV_GM; - Reset(); - Select(DigiPorts, SPORT_TEXT); + reset(); + select(DigiPorts, SPORT_TEXT); } @@ -241,40 +241,40 @@ void CGEEngine::MIDI() { _sndDrvInfo._dDev = DEV_QUIET; _sndDrvInfo._mDev = DEV_GM; _sndDrvInfo._mBase = DETECT; - Select(MIDIPorts, MPORT_TEXT); + select(MIDIPorts, MPORT_TEXT); } void CGEEngine::AUTO() { _sndDrvInfo._dDev = DEV_AUTO; _sndDrvInfo._mDev = DEV_AUTO; - Reset(); + reset(); _sound.Open(); } void CGEEngine::setPortD() { - _sndDrvInfo._dBase = xdeco(DigiPorts[VMENU::Recent].Text); - Select((_sndDrvInfo._dDev == DEV_SB) ? BlsterIRQ : GravisIRQ, SIRQ_TEXT); + _sndDrvInfo._dBase = xdeco(DigiPorts[Vmenu::_recent]._text); + select((_sndDrvInfo._dDev == DEV_SB) ? BlsterIRQ : GravisIRQ, SIRQ_TEXT); } void CGEEngine::setPortM() { - _sndDrvInfo._mBase = xdeco(MIDIPorts[VMENU::Recent].Text); + _sndDrvInfo._mBase = xdeco(MIDIPorts[Vmenu::_recent]._text); _sound.Open(); } void CGEEngine::setIRQ() { - _sndDrvInfo._dIrq = ddeco(((_sndDrvInfo._dDev == DEV_SB) ? BlsterIRQ : GravisIRQ)[VMENU::Recent].Text); - Select((_sndDrvInfo._dDev == DEV_SB) ? BlsterDMA : GravisDMA, SDMA_TEXT); + _sndDrvInfo._dIrq = ddeco(((_sndDrvInfo._dDev == DEV_SB) ? BlsterIRQ : GravisIRQ)[Vmenu::_recent]._text); + select((_sndDrvInfo._dDev == DEV_SB) ? BlsterDMA : GravisDMA, SDMA_TEXT); } void CGEEngine::setDMA() { - _sndDrvInfo._dDma = ddeco(((_sndDrvInfo._dDev == DEV_SB) ? BlsterDMA : GravisDMA)[VMENU::Recent].Text); + _sndDrvInfo._dDma = ddeco(((_sndDrvInfo._dDev == DEV_SB) ? BlsterDMA : GravisDMA)[Vmenu::_recent]._text); if (_sndDrvInfo._mDev != _sndDrvInfo._dDev) - Select(MIDIPorts, MPORT_TEXT); + select(MIDIPorts, MPORT_TEXT); else _sound.Open(); } diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 5f98cf34fb0..5bafd46884f 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -200,7 +200,7 @@ void MOUSE::NewMouse(Common::Event &event) { EvtHead = (EvtHead + 1) % EVT_MAX; evt._x = event.mouse.x; evt._y = event.mouse.y; - evt._ptr = SpriteAt(evt._x, evt._y); + evt._ptr = spriteAt(evt._x, evt._y); switch (event.type) { case Common::EVENT_MOUSEMOVE: @@ -278,8 +278,8 @@ void EventManager::handleEvents(void) { e._ptr->touch(e._msk, e._x, e._y); else e._ptr->touch(e._msk, e._x - e._ptr->_x, e._y - e._ptr->_y); - } else if (Sys) - Sys->touch(e._msk, e._x, e._y); + } else if (_sys) + _sys->touch(e._msk, e._x, e._y); if (e._msk & L_DN) { _mouse->Hold = e._ptr; diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 3acafd80e75..f2ebc0b4f80 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -35,7 +35,7 @@ uint8 *glass(Dac *pal, uint8 r, uint8 g, uint8 b) { if (x) { uint16 i; for (i = 0; i < 256; i++) { - x[i] = Closest(pal, MkDAC(((uint16)(pal[i]._r) * r) / 255, + x[i] = closest(pal, mkDac(((uint16)(pal[i]._r) * r) / 255, ((uint16)(pal[i]._g) * g) / 255, ((uint16)(pal[i]._b) * b) / 255)); } @@ -50,9 +50,9 @@ uint8 *Mark(DAC *pal) { if (x) { uint16 i; for (i = 0; i < 256; i++) { - x[i] = Closest(pal, MkDAC(f(pal[i].R), - f(pal[i].G), - f(pal[i].B))); + x[i] = closest(pal, mkDax(f(pal[i]._R), + f(pal[i]._G), + f(pal[i]._B))); } } return x; diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 93cdb75a4be..74084fb905c 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -34,8 +34,8 @@ namespace CGE { // Defines found in cge.mak #define VOL -#define INI_FILE VFILE // Or is it CFILE? -#define PIC_FILE VFILE +#define INI_FILE VFile // Or is it CFile? +#define PIC_FILE VFile #define BMP_MODE 0 // diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index a49f7c5c7fa..b7c4b8ca831 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -75,9 +75,9 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(MIX_FALL), _ } _led[ArrayCount(_led) - 1]->_flags._bDel = true; - Vga->_showQ->insert(this); + _vga->_showQ->insert(this); for (i = 0; i < ArrayCount(_led); i++) - Vga->_showQ->insert(_led[i]); + _vga->_showQ->insert(_led[i]); //--- reset balance i = (_sndDrvInfo.Vol4._ml + _sndDrvInfo.Vol4._mr) / 2; @@ -115,7 +115,7 @@ void Mixer::touch(uint16 mask, int x, int y) { void Mixer::tick() { int x = _mouse->_x; int y = _mouse->_y; - if (SpriteAt(x, y) == this) { + if (spriteAt(x, y) == this) { _fall = MIX_FALL; if (_flags._hold) touch(L_UP, x - _x, y - _y); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 01be69386fd..edafd591111 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -71,7 +71,7 @@ static void SNGame(Sprite *spr, int num) { int buref = 0; int Stage = 0; - for (dup[0] = Vga->_showQ->first(); dup[0]; dup[0] = dup[0]->_next) { + for (dup[0] = _vga->_showQ->first(); dup[0]; dup[0] = dup[0]->_next) { buref = dup[0]->_ref; if (buref / 1000 == 16 && buref % 100 == 6) { Stage = (buref / 100) % 10; @@ -79,8 +79,8 @@ static void SNGame(Sprite *spr, int num) { } } if (dup[1] == NULL) { - dup[1] = Vga->_showQ->locate(16003); // pan - dup[2] = Vga->_showQ->locate(16004); // pani + dup[1] = _vga->_showQ->locate(16003); // pan + dup[2] = _vga->_showQ->locate(16004); // pani } if (_game) { // continue game @@ -163,10 +163,10 @@ static void SNGame(Sprite *spr, int num) { static int count = 0; if (k == NULL) { - k = Vga->_showQ->locate(20700); - k1 = Vga->_showQ->locate(20701); - k2 = Vga->_showQ->locate(20702); - k3 = Vga->_showQ->locate(20703); + k = _vga->_showQ->locate(20700); + k1 = _vga->_showQ->locate(20701); + k2 = _vga->_showQ->locate(20702); + k3 = _vga->_showQ->locate(20703); } if (!_game) { // init @@ -217,7 +217,7 @@ static void SNGame(Sprite *spr, int num) { SNPOST(SNSAY, 20003, 20022, NULL); break; } - ++ count; + count++; } switch (spr->_ref) { case 1 : @@ -273,13 +273,13 @@ static void SNGame(Sprite *spr, int num) { void ExpandSprite(Sprite *spr) { if (spr) - Vga->_showQ->insert(Vga->_spareQ->remove(spr)); + _vga->_showQ->insert(_vga->_spareQ->remove(spr)); } void ContractSprite(Sprite *spr) { if (spr) - Vga->_spareQ->append(Vga->_showQ->remove(spr)); + _vga->_spareQ->append(_vga->_showQ->remove(spr)); } int findPocket(Sprite *spr) { @@ -307,12 +307,12 @@ void selectPocket(int n) { void pocFul() { - Hero->park(); - SNPOST(SNWAIT, -1, -1, Hero); - SNPOST(SNSEQ, -1, POC_FUL, Hero); - SNPOST(SNSOUND, -1, 2, Hero); - SNPOST(SNWAIT, -1, -1, Hero); - SNPOST(SNSAY, 1, POC_FUL_TEXT, Hero); + _hero->park(); + SNPOST(SNWAIT, -1, -1, _hero); + SNPOST(SNSEQ, -1, POC_FUL, _hero); + SNPOST(SNSOUND, -1, 2, _hero); + SNPOST(SNWAIT, -1, -1, _hero); + SNPOST(SNSAY, 1, POC_FUL_TEXT, _hero); } @@ -356,7 +356,7 @@ void feedSnail(Sprite *spr, SNLIST snq) { killText(); } if (c->_com == SNNEXT) { - Sprite *s = (c->_ref < 0) ? spr : Locate(c->_ref); + Sprite *s = (c->_ref < 0) ? spr : locate(c->_ref); if (s) { uint8 *idx = (snq == TAKE) ? &s->_takePtr : &s->_nearPtr; if (*idx != NO_PTR) { @@ -383,7 +383,7 @@ void feedSnail(Sprite *spr, SNLIST snq) { break; } if (c->_com == SNIF) { - Sprite *s = (c->_ref < 0) ? spr : Locate(c->_ref); + Sprite *s = (c->_ref < 0) ? spr : locate(c->_ref); if (s) { // sprite extsts if (! s->seqTest(-1)) c = comtab + c->_val; // not parked @@ -506,10 +506,10 @@ static void SNZTrim(Sprite *spr) { Sprite *s; _heart->_enable = false; s = (spr->_flags._shad) ? spr->_prev : NULL; - Vga->_showQ->insert(Vga->_showQ->remove(spr)); + _vga->_showQ->insert(_vga->_showQ->remove(spr)); if (s) { s->_z = spr->_z; - Vga->_showQ->insert(Vga->_showQ->remove(s), spr); + _vga->_showQ->insert(_vga->_showQ->remove(s), spr); } _heart->_enable = en; } @@ -539,8 +539,8 @@ static void SNRmTake(Sprite *spr) { void SNSeq(Sprite *spr, int val) { if (spr) { - if (spr == Hero && val == 0) - Hero->park(); + if (spr == _hero && val == 0) + _hero->park(); else spr->step(val); } @@ -571,7 +571,7 @@ void SNSend(Sprite *spr, int val) { spr->_flags._slav = false; } else { if (spr->_ref % 1000 == 0) - Bitmap::_pal = VGA::SysPal; + Bitmap::_pal = Vga::_sysPal; if (spr->_flags._back) spr->backShow(true); else @@ -584,7 +584,7 @@ void SNSend(Sprite *spr, int val) { void SNSwap(Sprite *spr, int xref) { - Sprite *xspr = Locate(xref); + Sprite *xspr = locate(xref); if (spr && xspr) { int was = spr->_cave; int xwas = xspr->_cave; @@ -619,7 +619,7 @@ void SNSwap(Sprite *spr, int xref) { void SNCover(Sprite *spr, int xref) { - Sprite *xspr = Locate(xref); + Sprite *xspr = locate(xref); if (spr && xspr) { spr->_flags._hide = true; xspr->_z = spr->_z; @@ -627,7 +627,7 @@ void SNCover(Sprite *spr, int xref) { xspr->gotoxy(spr->_x, spr->_y); ExpandSprite(xspr); if ((xspr->_flags._shad = spr->_flags._shad) == 1) { - Vga->_showQ->insert(Vga->_showQ->remove(spr->_prev), xspr); + _vga->_showQ->insert(_vga->_showQ->remove(spr->_prev), xspr); spr->_flags._shad = false; } feedSnail(xspr, NEAR); @@ -641,13 +641,13 @@ void SNUncover(Sprite *spr, Sprite *xspr) { spr->_cave = xspr->_cave; spr->gotoxy(xspr->_x, xspr->_y); if ((spr->_flags._shad = xspr->_flags._shad) == 1) { - Vga->_showQ->insert(Vga->_showQ->remove(xspr->_prev), spr); + _vga->_showQ->insert(_vga->_showQ->remove(xspr->_prev), spr); xspr->_flags._shad = false; } spr->_z = xspr->_z; SNSend(xspr, -1); if (spr->_time == 0) - ++spr->_time; + spr->_time++; } } @@ -669,20 +669,20 @@ void SNSetXY(Sprite *spr, uint16 xy) { void SNRelX(Sprite *spr, int x) { - if (spr && Hero) - spr->gotoxy(Hero->_x + x, spr->_y); + if (spr && _hero) + spr->gotoxy(_hero->_x + x, spr->_y); } void SNRelY(Sprite *spr, int y) { - if (spr && Hero) - spr->gotoxy(spr->_x, Hero->_y + y); + if (spr && _hero) + spr->gotoxy(spr->_x, _hero->_y + y); } void SNRelZ(Sprite *spr, int z) { - if (spr && Hero) { - spr->_z = Hero->_z + z; + if (spr && _hero) { + spr->_z = _hero->_z + z; SNZTrim(spr); } } @@ -710,13 +710,13 @@ void SNSetZ(Sprite *spr, int z) { void SNSlave(Sprite *spr, int ref) { - Sprite *slv = Locate(ref); + Sprite *slv = locate(ref); if (spr && slv) { if (spr->active()) { SNSend(slv, spr->_cave); slv->_flags._slav = true; slv->_z = spr->_z; - Vga->_showQ->insert(Vga->_showQ->remove(slv), spr->_next); + _vga->_showQ->insert(_vga->_showQ->remove(slv), spr->_next); } } } @@ -743,13 +743,13 @@ void SNKill(Sprite *spr) { } Sprite *nx = spr->_next; Hide1(spr); - Vga->_showQ->remove(spr); + _vga->_showQ->remove(spr); EventManager::ClrEvt(spr); if (spr->_flags._kill) delete spr; else { spr->_cave = -1; - Vga->_spareQ->append(spr); + _vga->_spareQ->append(spr); } if (nx) { if (nx->_flags._slav) @@ -817,7 +817,7 @@ static void SNLevel(Sprite *spr, int lev) { #endif while (_lev < lev) { _lev++; - spr = Vga->_spareQ->locate(100 + _lev); + spr = _vga->_spareQ->locate(100 + _lev); if (spr) { spr->backShow(true); spr->_cave = 0; @@ -844,7 +844,7 @@ void SNFlash(bool on) { if (on) { Dac *pal = farnew(Dac, PAL_CNT); if (pal) { - memcpy(pal, VGA::SysPal, PAL_SIZ); + memcpy(pal, Vga::_sysPal, PAL_SIZ); for (int i = 0; i < PAL_CNT; i++) { register int c; c = pal[i]._r << 1; @@ -854,19 +854,19 @@ void SNFlash(bool on) { c = pal[i]._b << 1; pal[i]._b = (c < 64) ? c : 63; } - Vga->SetColors(pal, 64); + _vga->setColors(pal, 64); } } else - Vga->SetColors(VGA::SysPal, 64); + _vga->setColors(Vga::_sysPal, 64); _dark = false; } static void SNLight(bool in) { if (in) - Vga->Sunrise(VGA::SysPal); + _vga->sunrise(Vga::_sysPal); else - Vga->Sunset(); + _vga->sunset(); _dark = ! in; } @@ -877,18 +877,18 @@ static void SNBarrier(int cav, int bar, bool horz) { static void SNWalk(Sprite *spr, int x, int y) { - if (Hero) { + if (_hero) { if (spr && y < 0) - Hero->findWay(spr); + _hero->findWay(spr); else - Hero->findWay(XZ(x, y)); + _hero->findWay(XZ(x, y)); } } static void SNReach(Sprite *spr, int mode) { - if (Hero) - Hero->reach(spr, mode); + if (_hero) + _hero->reach(spr, mode); } @@ -927,7 +927,7 @@ void Snail::runCom() { break; } - Sprite *sprel = ((snc->_ref >= 0) ? Locate(snc->_ref) : ((Sprite *) snc->_ptr)); + Sprite *sprel = ((snc->_ref >= 0) ? locate(snc->_ref) : ((Sprite *) snc->_ptr)); switch (snc->_com) { case SNLABEL : break; @@ -939,7 +939,7 @@ void Snail::runCom() { case SNWAIT : if (sprel) { if (sprel->seqTest(snc->_val) && - (snc->_val >= 0 || sprel != Hero || Hero->_tracePtr < 0)) { + (snc->_val >= 0 || sprel != _hero || _hero->_tracePtr < 0)) { _timerExpiry = g_system->getMillis() + sprel->_time * SNAIL_FRAME_DELAY; } else goto xit; @@ -953,21 +953,21 @@ void Snail::runCom() { break; case SNSAY : if (sprel && _talkEnable) { - if (sprel == Hero && sprel->seqTest(-1)) + if (sprel == _hero && sprel->seqTest(-1)) sprel->step(HTALK); _text->say(_text->getText(snc->_val), sprel); - Sys->FunDel = HEROFUN0; + _sys->FunDel = HEROFUN0; } break; case SNINF : if (_talkEnable) { _vm->inf(_text->getText(snc->_val)); - Sys->FunDel = HEROFUN0; + _sys->FunDel = HEROFUN0; } break; case SNTIME : if (sprel && _talkEnable) { - if (sprel == Hero && sprel->seqTest(-1)) + if (sprel == _hero && sprel->seqTest(-1)) sprel->step(HTALK); sayTime(sprel); } @@ -995,7 +995,7 @@ void Snail::runCom() { SNCover(sprel, snc->_val); break; case SNUNCOVER : - SNUncover(sprel, (snc->_val >= 0) ? Locate(snc->_val) : ((Sprite *) snc->_ptr)); + SNUncover(sprel, (snc->_val >= 0) ? locate(snc->_val) : ((Sprite *) snc->_ptr)); break; case SNKEEP : SNKeep(sprel, snc->_val); diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index f1124932780..5f370150ca9 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -213,8 +213,8 @@ void Text::say(const char *txt, Sprite *spr) { spike->step(east); spike->_ref = SAY_REF; - Vga->_showQ->insert(_talk, Vga->_showQ->last()); - Vga->_showQ->insert(spike, Vga->_showQ->last()); + _vga->_showQ->insert(_talk, _vga->_showQ->last()); + _vga->_showQ->insert(spike, _vga->_showQ->last()); } } @@ -229,7 +229,7 @@ void CGEEngine::inf(const char *txt) { _talk->gotoxy(_talk->_x, _talk->_y - 20); _talk->_z = 126; _talk->_ref = INF_REF; - Vga->_showQ->insert(_talk, Vga->_showQ->last()); + _vga->_showQ->insert(_talk, _vga->_showQ->last()); } } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 36661e756ec..aa7cd8ad06c 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -177,7 +177,7 @@ void RestoreScreen(uint16 * &sav) { } -Dac MkDAC(uint8 r, uint8 g, uint8 b) { +Dac mkDac(uint8 r, uint8 g, uint8 b) { static Dac x; x._r = r; x._g = g; @@ -186,7 +186,7 @@ Dac MkDAC(uint8 r, uint8 g, uint8 b) { } -Rgb MkRGB(uint8 r, uint8 g, uint8 b) { +Rgb mkRgb(uint8 r, uint8 g, uint8 b) { static Trgb x; x._dac._r = r; x._dac._g = g; @@ -195,9 +195,9 @@ Rgb MkRGB(uint8 r, uint8 g, uint8 b) { } -Sprite *Locate(int ref) { - Sprite *spr = Vga->_showQ->locate(ref); - return (spr) ? spr : Vga->_spareQ->locate(ref); +Sprite *locate(int ref) { + Sprite *spr = _vga->_showQ->locate(ref); + return (spr) ? spr : _vga->_spareQ->locate(ref); } @@ -746,10 +746,10 @@ void Sprite::show() { void Sprite::show(uint16 pg) { - Graphics::Surface *a = VGA::Page[1]; - VGA::Page[1] = VGA::Page[pg & 3]; + Graphics::Surface *a = Vga::_page[1]; + Vga::_page[1] = Vga::_page[pg & 3]; shp()->show(_x, _y); - VGA::Page[1] = a; + Vga::_page[1] = a; } @@ -780,8 +780,8 @@ BMP_PTR Sprite::ghost() { } -Sprite *SpriteAt(int x, int y) { - Sprite *spr = NULL, * tail = Vga->_showQ->last(); +Sprite *spriteAt(int x, int y) { + Sprite *spr = NULL, * tail = _vga->_showQ->last(); if (tail) { for (spr = tail->_prev; spr; spr = spr->_prev) { if (! spr->_flags._hide && ! spr->_flags._tran) { @@ -899,32 +899,32 @@ Sprite *Queue::locate(int ref) { //extern const char Copr[]; -Graphics::Surface *VGA::Page[4]; -Dac *VGA::SysPal; +Graphics::Surface *Vga::_page[4]; +Dac *Vga::_sysPal; -void VGA::init() { +void Vga::init() { for (int idx = 0; idx < 4; ++idx) { - Page[idx] = new Graphics::Surface(); - Page[idx]->create(320, 200, Graphics::PixelFormat::createFormatCLUT8()); + _page[idx] = new Graphics::Surface(); + _page[idx]->create(320, 200, Graphics::PixelFormat::createFormatCLUT8()); } - SysPal = new Dac[PAL_CNT]; + _sysPal = new Dac[PAL_CNT]; } -void VGA::deinit() { +void Vga::deinit() { for (int idx = 0; idx < 4; ++idx) { - Page[idx]->free(); - delete Page[idx]; + _page[idx]->free(); + delete _page[idx]; } - delete[] SysPal; + delete[] _sysPal; } -VGA::VGA(int mode) - : FrmCnt(0), OldMode(0), OldScreen(NULL), StatAdr(VGAST1_), - Msg(NULL), Nam(NULL), SetPal(false), Mono(0) { - OldColors = NULL; - NewColors = NULL; +Vga::Vga(int mode) + : _frmCnt(0), _oldMode(0), _oldScreen(NULL), _statAdr(VGAST1_), + _msg(NULL), _nam(NULL), _setPal(false), _mono(0) { + _oldColors = NULL; + _newColors = NULL; _showQ = new Queue(true); _spareQ = new Queue(false); @@ -941,42 +941,42 @@ VGA::VGA(int mode) // warning(Copr); warning("TODO: Fix Copr"); - SetStatAdr(); - if (StatAdr != VGAST1_) - ++Mono; + setStatAdr(); + if (_statAdr != VGAST1_) + _mono++; if (isVga()) { - OldColors = farnew(Dac, 256); - NewColors = farnew(Dac, 256); - OldScreen = SaveScreen(); - GetColors(OldColors); - Sunset(); - OldMode = SetMode(mode); - SetColors(); - Setup(VideoMode); - Clear(0); + _oldColors = farnew(Dac, 256); + _newColors = farnew(Dac, 256); + _oldScreen = SaveScreen(); + getColors(_oldColors); + sunset(); + _oldMode = setMode(mode); + setColors(); + setup(VideoMode); + clear(0); } } -VGA::~VGA(void) { - Mono = 0; +Vga::~Vga() { + _mono = 0; if (isVga()) { Common::String buffer = ""; /* - Clear(0); - SetMode(OldMode); - SetColors(); - RestoreScreen(OldScreen); - Sunrise(OldColors); + clear(0); + setMode(_oldMode); + setColors(); + restoreScreen(_oldScreen); + sunrise(_oldColors); */ - if (OldColors) - free(OldColors); - if (NewColors) - free(NewColors); - if (Msg) - buffer = Common::String(Msg); - if (Nam) - buffer = buffer + " [" + Nam + "]"; + if (_oldColors) + free(_oldColors); + if (_newColors) + free(_newColors); + if (_msg) + buffer = Common::String(_msg); + if (_nam) + buffer = buffer + " [" + _nam + "]"; debugN("%s", buffer.c_str()); } @@ -986,7 +986,7 @@ VGA::~VGA(void) { } -void VGA::SetStatAdr(void) { +void Vga::setStatAdr() { /* asm mov dx,VGAMIr_ asm in al,dx @@ -997,21 +997,21 @@ void VGA::SetStatAdr(void) { set_mode_adr: StatAdr = _AX; */ - warning("STUB: VGA::SetStatADR"); + warning("STUB: VGA::setStatADR"); } #pragma argsused -void VGA::WaitVR(bool on) { +void Vga::waitVR(bool on) { // Since some of the game parts rely on using vertical sync as a delay mechanism, // we're introducing a short delay to simulate it g_system->delayMillis(10); } -void VGA::Setup(VgaRegBlk *vrb) { +void Vga::setup(VgaRegBlk *vrb) { /* - WaitVR(); // *--LOOK!--* resets VGAATR logic + waitVR(); // *--LOOK!--* resets VGAATR logic asm cld asm mov si, vrb // take address of parameter table asm mov dh,0x03 // higher byte of I/O address is always 3 @@ -1048,23 +1048,23 @@ void VGA::Setup(VgaRegBlk *vrb) { xit: */ - warning("STUB: VGA::Setup"); + warning("STUB: VGA::setup"); } -int VGA::SetMode(int mode) { +int Vga::setMode(int mode) { // ScummVM provides it's own vieo services return 0; } -void VGA::GetColors(Dac *tab) { +void Vga::getColors(Dac *tab) { byte palData[PAL_SIZ]; g_system->getPaletteManager()->grabPalette(palData, 0, PAL_CNT); - pal2DAC(palData, tab); + palToDac(palData, tab); } -void VGA::pal2DAC(const byte *palData, Dac *tab) { +void Vga::palToDac(const byte *palData, Dac *tab) { const byte *colP = palData; for (int idx = 0; idx < PAL_CNT; ++idx, colP += 3) { tab[idx]._r = *colP >> 2; @@ -1073,7 +1073,7 @@ void VGA::pal2DAC(const byte *palData, Dac *tab) { } } -void VGA::DAC2pal(const Dac *tab, byte *palData) { +void Vga::dacToPal(const Dac *tab, byte *palData) { for (int idx = 0; idx < PAL_CNT; ++idx, palData += 3) { *palData = tab[idx]._r << 2; *(palData + 1) = tab[idx]._g << 2; @@ -1081,16 +1081,16 @@ void VGA::DAC2pal(const Dac *tab, byte *palData) { } } -void VGA::SetColors(Dac *tab, int lum) { - Dac *palP = tab, *destP = NewColors; +void Vga::setColors(Dac *tab, int lum) { + Dac *palP = tab, *destP = _newColors; for (int idx = 0; idx < PAL_CNT; ++idx, ++palP, ++destP) { destP->_r = (palP->_r * lum) >> 6; destP->_g = (palP->_g * lum) >> 6; destP->_b = (palP->_b * lum) >> 6; } - if (Mono) { - destP = NewColors; + if (_mono) { + destP = _newColors; for (int idx = 0; idx < PAL_CNT; ++idx, ++palP) { // Form a greyscalce colour from 30% R, 59% G, 11% B uint8 intensity = (destP->_r * 77) + (destP->_g * 151) + (destP->_b * 28); @@ -1100,77 +1100,77 @@ void VGA::SetColors(Dac *tab, int lum) { } } - SetPal = true; + _setPal = true; } -void VGA::SetColors(void) { - memset(NewColors, 0, PAL_SIZ); - UpdateColors(); +void Vga::setColors(void) { + memset(_newColors, 0, PAL_SIZ); + updateColors(); } -void VGA::Sunrise(Dac *tab) { +void Vga::sunrise(Dac *tab) { for (int i = 0; i <= 64; i += FADE_STEP) { - SetColors(tab, i); - WaitVR(true); - UpdateColors(); + setColors(tab, i); + waitVR(true); + updateColors(); } } -void VGA::Sunset(void) { +void Vga::sunset() { Dac tab[256]; - GetColors(tab); + getColors(tab); for (int i = 64; i >= 0; i -= FADE_STEP) { - SetColors(tab, i); - WaitVR(true); - UpdateColors(); + setColors(tab, i); + waitVR(true); + updateColors(); } } -void VGA::Show(void) { +void Vga::show() { Sprite *spr = _showQ->first(); for (spr = _showQ->first(); spr; spr = spr->_next) spr->show(); - Update(); + update(); for (spr = _showQ->first(); spr; spr = spr->_next) spr->hide(); - ++ FrmCnt; + _frmCnt++; } -void VGA::UpdateColors(void) { +void Vga::updateColors() { byte palData[PAL_SIZ]; - DAC2pal(NewColors, palData); + dacToPal(_newColors, palData); g_system->getPaletteManager()->setPalette(palData, 0, 256); } -void VGA::Update(void) { - SWAP(VGA::Page[0], VGA::Page[1]); +void Vga::update() { + SWAP(Vga::_page[0], Vga::_page[1]); - if (SetPal) { - UpdateColors(); - SetPal = false; + if (_setPal) { + updateColors(); + _setPal = false; } - g_system->copyRectToScreen((const byte *)VGA::Page[0]->getBasePtr(0, 0), SCR_WID, 0, 0, SCR_WID, SCR_HIG); + g_system->copyRectToScreen((const byte *)Vga::_page[0]->getBasePtr(0, 0), SCR_WID, 0, 0, SCR_WID, SCR_HIG); g_system->updateScreen(); } -void VGA::Clear(uint8 color) { +void Vga::clear(uint8 color) { for (int paneNum = 0; paneNum < 4; ++paneNum) - Page[paneNum]->fillRect(Common::Rect(0, 0, SCR_WID, SCR_HIG), color); + _page[paneNum]->fillRect(Common::Rect(0, 0, SCR_WID, SCR_HIG), color); } -void VGA::CopyPage(uint16 d, uint16 s) { - Page[d]->copyFrom(*Page[s]); +void Vga::copyPage(uint16 d, uint16 s) { + _page[d]->copyFrom(*_page[s]); } //-------------------------------------------------------------------------- @@ -1259,13 +1259,13 @@ void Bitmap::xShow(int x, int y) { void Bitmap::show(int x, int y) { const byte *srcP = (const byte *)_v; - byte *destEndP = (byte *)VGA::Page[1]->pixels + (SCR_WID * SCR_HIG); + byte *destEndP = (byte *)Vga::_page[1]->pixels + (SCR_WID * SCR_HIG); // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data // must be decompressed and inserted into the surface for (int planeCtr = 0; planeCtr < 4; ++planeCtr) { - byte *destP = (byte *)VGA::Page[1]->getBasePtr(x + planeCtr, y); + byte *destP = (byte *)Vga::_page[1]->getBasePtr(x + planeCtr, y); for (;;) { uint16 v = READ_LE_UINT16(srcP); @@ -1321,8 +1321,8 @@ void Bitmap::show(int x, int y) { void Bitmap::hide(int x, int y) { for (int yp = y; yp < y + _h; ++yp) { - const byte *srcP = (const byte *)VGA::Page[2]->getBasePtr(x, yp); - byte *destP = (byte *)VGA::Page[1]->getBasePtr(x, yp); + const byte *srcP = (const byte *)Vga::_page[2]->getBasePtr(x, yp); + byte *destP = (byte *)Vga::_page[1]->getBasePtr(x, yp); Common::copy(srcP, srcP + _w, destP); } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 9e49b3d9188..5ef7f99c694 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -170,7 +170,7 @@ protected: public: int _ref; signed char _cave; - struct FLAGS { + struct Flags { uint16 _hide : 1; // general visibility switch uint16 _near : 1; // Near action lock uint16 _drag : 1; // sprite is moveable @@ -237,7 +237,8 @@ private: class Queue { - Sprite *_head, *_tail; + Sprite *_head; + Sprite *_tail; public: Queue(bool show); ~Queue(); @@ -260,55 +261,55 @@ public: }; -class VGA { - uint16 OldMode; - uint16 *OldScreen; - uint16 StatAdr; - bool SetPal; - Dac *OldColors; - Dac *NewColors; - const char *Msg; - const char *Nam; +class Vga { + uint16 _oldMode; + uint16 *_oldScreen; + uint16 _statAdr; + bool _setPal; + Dac *_oldColors; + Dac *_newColors; + const char *_msg; + const char *_nam; - int SetMode(int mode); - void UpdateColors(void); - void SetColors(void); - void SetStatAdr(void); - void WaitVR(bool on); + int setMode(int mode); + void updateColors(); + void setColors(); + void setStatAdr(); + void waitVR(bool on); public: - uint32 FrmCnt; + uint32 _frmCnt; Queue *_showQ; Queue *_spareQ; - int Mono; - static Graphics::Surface *Page[4]; - static Dac *SysPal; + int _mono; + static Graphics::Surface *_page[4]; + static Dac *_sysPal; - VGA(int mode); - ~VGA(void); + Vga(int mode); + ~Vga(void); static void init(); static void deinit(); - void Setup(VgaRegBlk *vrb); - void GetColors(Dac *tab); - void SetColors(Dac *tab, int lum); - void Clear(uint8 color); - void CopyPage(uint16 d, uint16 s); - void Sunrise(Dac *tab); - void Sunset(); - void Show(); - void Update(); + void setup(VgaRegBlk *vrb); + void getColors(Dac *tab); + void setColors(Dac *tab, int lum); + void clear(uint8 color); + void copyPage(uint16 d, uint16 s); + void sunrise(Dac *tab); + void sunset(); + void show(); + void update(); - static void pal2DAC(const byte *palData, Dac *tab); - static void DAC2pal(const Dac *tab, byte *palData); + static void palToDac(const byte *palData, Dac *tab); + static void dacToPal(const Dac *tab, byte *palData); }; -Dac MkDAC(uint8 r, uint8 g, uint8 b); -Rgb MkRGB(uint8 r, uint8 g, uint8 b); +Dac mkDac(uint8 r, uint8 g, uint8 b); +Rgb mkRgb(uint8 r, uint8 g, uint8 b); template -uint8 Closest(CBLK *pal, CBLK x) { +uint8 closest(CBLK *pal, CBLK x) { #define f(col, lum) ((((uint16)(col)) << 8) / lum) uint16 i, dif = 0xFFFF, found = 0; uint16 L = x._r + x._g + x._b; @@ -337,12 +338,12 @@ uint8 Closest(CBLK *pal, CBLK x) { } //static void Video (void); -uint16 *SaveScreen(void); -void RestoreScreen(uint16 * &sav); -Sprite *SpriteAt(int x, int y); -Sprite *Locate(int ref); +uint16 *saveScreen(); +void restoreScreen(uint16 * &sav); +Sprite *spriteAt(int x, int y); +Sprite *locate(int ref); -extern bool SpeedTest; +extern bool _speedTest; } // End of namespace CGE diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 7ea32ff0236..49dbbbdab66 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -44,7 +44,7 @@ namespace CGE { -MENU_BAR::MENU_BAR(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { +MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h; uint8 *p = farnew(uint8, i), * p1, * p2; @@ -71,21 +71,21 @@ MENU_BAR::MENU_BAR(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { static char *vmgt; -char *VMGather(CHOICE *list) { - CHOICE *cp; +char *VMGather(Choice *list) { + Choice *cp; int len = 0, h = 0; - for (cp = list; cp->Text; cp++) { - len += strlen(cp->Text); + for (cp = list; cp->_text; cp++) { + len += strlen(cp->_text); h++; } vmgt = new char[len + h]; if (vmgt) { *vmgt = '\0'; - for (cp = list; cp->Text; cp++) { + for (cp = list; cp->_text; cp++) { if (*vmgt) strcat(vmgt, "|"); - strcat(vmgt, cp->Text); + strcat(vmgt, cp->_text); h++; } } @@ -93,60 +93,60 @@ char *VMGather(CHOICE *list) { } -VMENU *VMENU::Addr = NULL; -int VMENU::Recent = -1; +Vmenu *Vmenu::_addr = NULL; +int Vmenu::_recent = -1; -VMENU::VMENU(CGEEngine *vm, CHOICE *list, int x, int y) - : Talk(vm, VMGather(list), RECT), Menu(list), Bar(NULL), _vm(vm) { - CHOICE *cp; +Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y) + : Talk(vm, VMGather(list), RECT), _menu(list), _bar(NULL), _vm(vm) { + Choice *cp; - Addr = this; + _addr = this; delete[] vmgt; - Items = 0; - for (cp = list; cp->Text; cp++) - Items++; + _items = 0; + for (cp = list; cp->_text; cp++) + _items++; _flags._bDel = true; _flags._kill = true; if (x < 0 || y < 0) center(); else gotoxy(x - _w / 2, y - (TEXT_VM + FONT_HIG / 2)); - Vga->_showQ->insert(this, Vga->_showQ->last()); - Bar = new MENU_BAR(_vm, _w - 2 * TEXT_HM); - Bar->gotoxy(_x + TEXT_HM - MB_HM, _y + TEXT_VM - MB_VM); - Vga->_showQ->insert(Bar, Vga->_showQ->last()); + _vga->_showQ->insert(this, _vga->_showQ->last()); + _bar = new MenuBar(_vm, _w - 2 * TEXT_HM); + _bar->gotoxy(_x + TEXT_HM - MB_HM, _y + TEXT_VM - MB_VM); + _vga->_showQ->insert(_bar, _vga->_showQ->last()); } -VMENU::~VMENU(void) { - Addr = NULL; +Vmenu::~Vmenu(void) { + _addr = NULL; } -void VMENU::touch(uint16 mask, int x, int y) { +void Vmenu::touch(uint16 mask, int x, int y) { uint16 h = FONT_HIG + TEXT_LS; bool ok = false; - if (Items) { + if (_items) { Sprite::touch(mask, x, y); y -= TEXT_VM - 1; int n = 0; if (y >= 0) { n = y / h; - if (n < Items) + if (n < _items) ok = (x >= TEXT_HM && x < _w - TEXT_HM/* && y % h < FONT_HIG*/); else - n = Items - 1; + n = _items - 1; } - Bar->gotoxy(_x + TEXT_HM - MB_HM, _y + TEXT_VM + n * h - MB_VM); + _bar->gotoxy(_x + TEXT_HM - MB_HM, _y + TEXT_VM + n * h - MB_VM); if (ok && (mask & L_UP)) { - Items = 0; + _items = 0; SNPOST_(SNKILL, -1, 0, this); - //Menu[Recent = n].Proc(); + //_menu[_recent = n].Proc(); warning("Missing call to proc()"); } } diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index 88a27660400..6b4eb85a53f 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -36,29 +36,29 @@ namespace CGE { #define MB_HM 3 -typedef struct { - const char *Text; +struct Choice { + const char *_text; void (CGEEngine::*Proc)(); -} CHOICE; +}; -class MENU_BAR : public Talk { +class MenuBar : public Talk { public: - MENU_BAR(CGEEngine *vm, uint16 w); + MenuBar(CGEEngine *vm, uint16 w); private: CGEEngine *_vm; }; -class VMENU : public Talk { - uint16 Items; - CHOICE *Menu; +class Vmenu : public Talk { + uint16 _items; + Choice *_menu; public: - static VMENU *Addr; - static int Recent; - MENU_BAR *Bar; - VMENU(CGEEngine *vm, CHOICE *list, int x, int y); - ~VMENU(); + static Vmenu *_addr; + static int _recent; + MenuBar *_bar; + Vmenu(CGEEngine *vm, Choice *list, int x, int y); + ~Vmenu(); virtual void touch(uint16 mask, int x, int y); private: CGEEngine *_vm; diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 332ae869c89..2988f9ab11c 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -31,25 +31,25 @@ namespace CGE { -DAT *VFILE::_dat = NULL; -BtFile *VFILE::_cat = NULL; -VFILE *VFILE::_recent = NULL; +Dat *VFile::_dat = NULL; +BtFile *VFile::_cat = NULL; +VFile *VFile::_recent = NULL; /*-----------------------------------------------------------------------*/ -DAT::DAT(): +Dat::Dat(): #ifdef VOL_UPD - _File(DAT_NAME, UPD, CRP) + _file(DAT_NAME, UPD, CRP) #else - _File(DAT_NAME, REA, CRP) + _file(DAT_NAME, REA, CRP) #endif { } /*-----------------------------------------------------------------------*/ -void VFILE::init() { - _dat = new DAT(); +void VFile::init() { + _dat = new Dat(); #ifdef VOL_UPD _cat = new BtFile(CAT_NAME, UPD, CRP); #else @@ -59,15 +59,15 @@ void VFILE::init() { _recent = NULL; } -void VFILE::deinit() { +void VFile::deinit() { delete _dat; delete _cat; } -VFILE::VFILE(const char *name, IOMODE mode) +VFile::VFile(const char *name, IOMODE mode) : IoBuf(mode) { if (mode == REA) { - if (_dat->_File._error || _cat->_error) + if (_dat->_file._error || _cat->_error) error("Bad volume data"); BtKeypack *kp = _cat->find(name); if (scumm_stricmp(kp->_key, name) != 0) @@ -81,27 +81,27 @@ VFILE::VFILE(const char *name, IOMODE mode) } -VFILE::~VFILE(void) { +VFile::~VFile() { if (_recent == this) _recent = NULL; } -bool VFILE::exist(const char *name) { +bool VFile::exist(const char *name) { return scumm_stricmp(_cat->find(name)->_key, name) == 0; } -void VFILE::readBuff(void) { +void VFile::readBuff() { if (_recent != this) { - _dat->_File.seek(_bufMark + _lim); + _dat->_file.seek(_bufMark + _lim); _recent = this; } - _bufMark = _dat->_File.mark(); + _bufMark = _dat->_file.mark(); long n = _endMark - _bufMark; if (n > IOBUF_SIZE) n = IOBUF_SIZE; - _lim = _dat->_File.read(_buff, (uint16) n); + _lim = _dat->_file.read(_buff, (uint16) n); _ptr = 0; } diff --git a/engines/cge/vol.h b/engines/cge/vol.h index 1e0b363ca5d..d8ba0979cbf 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -49,11 +49,11 @@ namespace CGE { #endif -class DAT { - friend class VFILE; - VOLBASE _File; +class Dat { + friend class VFile; + VOLBASE _file; public: - DAT(); + Dat(); bool append(uint8 *buf, uint16 len); bool write(CFile &f); @@ -61,11 +61,11 @@ public: }; -class VFILE : public IoBuf { +class VFile : public IoBuf { private: - static DAT *_dat; + static Dat *_dat; static BtFile *_cat; - static VFILE *_recent; + static VFile *_recent; long _begMark; long _endMark; @@ -74,17 +74,17 @@ private: void writeBuff(void) { } void make(const char *fspec); public: - VFILE(const char *name, IOMODE mode = REA); - ~VFILE(void); + VFile(const char *name, IOMODE mode = REA); + ~VFile(); static void init(); static void deinit(); static bool exist(const char *name); - static const char *next(void); - long mark(void) { + static const char *next(); + long mark() { return (_bufMark + _ptr) - _begMark; } - long size(void) { + long size() { return _endMark - _begMark; } long seek(long pos) { From fae1d7efd885eae98ee9b0c8ae9bc99612942430 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 4 Jul 2011 08:15:56 +0200 Subject: [PATCH 078/276] CGE: This ends the first renaming pass. Also move some functions to CGEEngine --- engines/cge/cge.cpp | 66 ++++++++++++++++- engines/cge/cge.h | 28 +++++++- engines/cge/cge_main.cpp | 148 +++++++++++++++------------------------ engines/cge/cge_main.h | 17 +++-- engines/cge/config.cpp | 10 +-- engines/cge/ems.cpp | 24 +++---- engines/cge/events.cpp | 2 +- engines/cge/general.cpp | 8 +-- engines/cge/general.h | 26 +++---- engines/cge/snail.cpp | 27 ++++--- engines/cge/snail.h | 3 - engines/cge/sound.cpp | 129 +++++++++++++++++----------------- engines/cge/sound.h | 56 +++++++-------- engines/cge/startup.cpp | 2 +- engines/cge/startup.h | 2 +- engines/cge/vol.cpp | 14 ++++ engines/cge/vol.h | 20 ++---- engines/cge/wav.h | 125 ++++++++++++++++----------------- 18 files changed, 375 insertions(+), 332 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 04874415179..87c3964563a 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -46,7 +46,12 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) // Debug/console setup DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel"); - _isDemo = _gameDescription->flags & ADGF_DEMO; + _isDemo = _gameDescription->flags & ADGF_DEMO; + _startupMode = 1; + _demoText = DEMO_TEXT; + _oldLev = 0; + _jbw = false; + _pocPtr = 0; } @@ -68,7 +73,7 @@ void CGEEngine::setup() { _vga = new Vga(M13H); _heart = new Heart; _hero = new WALK(this, NULL); - _sys = new SYSTEM(this); + _sys = new System(this); _pocLight = new Sprite(this, LI); for (int i = 0; i < POCKET_NX; i++) _pocket[i] = new Sprite(this, NULL); @@ -103,6 +108,63 @@ void CGEEngine::setup() { _keyboard = new Keyboard(); _eventManager = new EventManager(); _offUseCount = atoi(_text->getText(OFF_USE_COUNT)); + _music = true; + + for (int i = 0; i < POCKET_NX; i++) + _pocref[i] = -1; + _volume[0] = 0; + _volume[1] = 0; + + _savTab[0].Ptr = &_now; + _savTab[0].Len = sizeof(_now); + _savTab[0].Flg = 1; + _savTab[1].Ptr = &_oldLev; + _savTab[1].Len = sizeof(_oldLev); + _savTab[1].Flg = 1; + _savTab[2].Ptr = &_demoText; + _savTab[2].Len = sizeof(_demoText); + _savTab[2].Flg = 1; + _savTab[3].Ptr = &_game; + _savTab[3].Len = sizeof(_game); + _savTab[3].Flg = 1; + _savTab[4].Ptr = &_game; + _savTab[4].Len = sizeof(_game); + _savTab[4].Flg = 1; + _savTab[5].Ptr = &_game; + _savTab[5].Len = sizeof(_game); + _savTab[5].Flg = 1; + _savTab[6].Ptr = &_game; + _savTab[6].Len = sizeof(_game); + _savTab[6].Flg = 1; + _savTab[7].Ptr = &_game; + _savTab[7].Len = sizeof(_game); + _savTab[7].Flg = 1; + _savTab[8].Ptr = &_vga->_mono; + _savTab[8].Len = sizeof(_vga->_mono); + _savTab[8].Flg = 0; + _savTab[9].Ptr = &_music; + _savTab[9].Len = sizeof(_music); + _savTab[9].Flg = 1; + _savTab[10].Ptr = _volume; + _savTab[10].Len = sizeof(_volume); + _savTab[10].Flg = 1; + _savTab[11].Ptr = _flag; + _savTab[11].Len = sizeof(_flag); + _savTab[11].Flg = 1; + _savTab[12].Ptr = _heroXY; +// _savTab[12].Len = sizeof(_heroXY); FIXME: illegal sizeof + _savTab[12].Len = 0; + _savTab[12].Flg = 1; + _savTab[13].Ptr = _barriers; +// _savTab[13].Len = sizeof(_barriers); FIXME: illegal sizeof + _savTab[13].Len = 0; + _savTab[13].Flg = 1; + _savTab[14].Ptr = _pocref; + _savTab[14].Len = sizeof(_pocref); + _savTab[14].Flg = 1; + _savTab[15].Ptr = NULL; + _savTab[15].Len = 0; + _savTab[15].Flg = 0; } CGEEngine::~CGEEngine() { diff --git a/engines/cge/cge.h b/engines/cge/cge.h index ba6326726a2..04f395559f1 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -36,12 +36,21 @@ namespace CGE { class Console; +class Sprite; // our engine debug channels enum { kCGEDebug = 1 << 0 }; +#define POCKET_NX 8 + +struct SavTab { + void *Ptr; + int Len; + uint8 Flg; +}; + class CGEEngine : public Engine { private: uint32 _lastFrame; @@ -50,8 +59,17 @@ public: CGEEngine(OSystem *syst, const ADGameDescription *gameDescription); ~CGEEngine(); - const ADGameDescription *_gameDescription; - bool _isDemo; + const ADGameDescription *_gameDescription; + bool _isDemo; + int _startupMode; + int _demoText; + int _oldLev; + bool _jbw; + int _pocPtr; + SavTab _savTab[16]; + bool _music; + int _pocref[POCKET_NX]; + uint8 _volume[2]; virtual Common::Error run(); GUI::Debugger *getDebugger() { @@ -81,6 +99,7 @@ public: void NONE(); void SB(); void caveDown(); + void caveUp(); void xCave(); void qGame(); void SBM(); @@ -93,6 +112,11 @@ public: void setIRQ(); void setDMA(); void mainLoop(); + void SaveGame(XFile &file); + void switchMusic(); + void selectPocket(int n); + void SNKeep(Sprite *spr, int stp); + void SNGive(Sprite *spr, int stp); private: CGEConsole *_console; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 2caa9e0a98a..6b02f82910c 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -58,7 +58,7 @@ uint16 _stklen = (STACK_SIZ * 2); Vga *_vga; Heart *_heart; WALK *_hero; -SYSTEM *_sys; +System *_sys; Sprite *_pocLight; EventManager *_eventManager; Keyboard *_keyboard; @@ -91,21 +91,14 @@ Snail *_snail_; // coditionals EVA for 2-month evaluation version static char _usrFnam[15] = "\0ɱ%^þúȼ´ ÇÉ"; -static int _oldLev = 0; -static int _demoText = DEMO_TEXT; //-------------------------------------------------------------------------- -bool _jbw = false; - -//------------------------------------------------------------------------- -int _pocPtr = 0; - -static EMS *_mini = _miniEmm.alloc((uint16)MINI_EMM_SIZE); +static Ems *_mini = _miniEmm.alloc((uint16)MINI_EMM_SIZE); static BMP_PTR *_miniShpList = NULL; static BMP_PTR _miniShp[] = { NULL, NULL }; static bool _finis = false; -static int _startup = 1; +//static int _startup = 1; int _offUseCount; uint16 *_intStackPtr = false; @@ -115,11 +108,11 @@ Bar _barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; extern int findPocket(Sprite *); extern Dac _stdPal[58]; -void feedSnail(Sprite *spr, SNLIST snq); // defined in SNAIL -uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; +void feedSnail(Sprite *spr, SNLIST snq); // defined in SNAIL +uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; -uint8 &Cluster::cell() { +uint8 &Cluster::cell() { return _map[_b][_a]; } @@ -184,36 +177,6 @@ Cluster XZ(Couple xy) { return XZ(x, y); } - -int _pocref[POCKET_NX]; -uint8 _volume[2]; - -struct SavTab { - void *Ptr; - int Len; - uint8 Flg; -}; - -SavTab _savTab[] = { - { &_now, sizeof(_now), 1 }, - { &_oldLev, sizeof(_oldLev), 1 }, - { &_demoText, sizeof(_demoText), 1 }, - { &_game, sizeof(_game), 1 }, - { &_game, sizeof(_game), 1 }, // spare 1 - { &_game, sizeof(_game), 1 }, // spare 2 - { &_game, sizeof(_game), 1 }, // spare 3 - { &_game, sizeof(_game), 1 }, // spare 4 -// { &VGA::Mono, sizeof(VGA::Mono), 0 }, - { &_music, sizeof(_music), 1 }, - { _volume, sizeof(_volume), 1 }, - { _flag, sizeof(_flag), 1 }, - { _heroXY, sizeof(_heroXY), 1 }, - { _barriers, sizeof(_barriers), 1 }, - { _pocref, sizeof(_pocref), 1 }, - { NULL, 0, 0 } -}; - - void CGEEngine::loadGame(XFile &file, bool tiny = false) { SavTab *st; Sprite *spr; @@ -270,7 +233,7 @@ static void SaveSound(void) { } -static void SaveGame(XFile &file) { +void CGEEngine::SaveGame(XFile &file) { SavTab *st; Sprite *spr; int i; @@ -366,7 +329,7 @@ void WALK::tick() { if (Dir != NO_DIR) { Sprite *spr; - _sys->FunTouch(); + _sys->funTouch(); for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (distance(spr) < 2) { if (!spr->_flags._near) { @@ -554,7 +517,6 @@ void CGEEngine::setMapBrick(int x, int z) { static void SwitchColorMode(void); static void switchDebug(); -static void SwitchMusic(void); static void KillSprite(void); static void PushSprite(void); static void PullSprite(void); @@ -605,22 +567,22 @@ static void miniStep(int stp) { else { &*_mini; *_miniShp[0] = *_miniShpList[stp]; - if (_fx.Current) - &*(_fx.Current->EAddr()); + if (_fx._current) + &*(_fx._current->eAddr()); _miniCave->_flags._hide = false; } } -static void PostMiniStep(int stp) { +static void postMiniStep(int stp) { //static int recent = -2; //TODO Change the SNPOST message send to a special way to send function pointer //if (MiniCave && stp != recent) SNPOST_(SNEXEC, -1, recent = stp, (void *)&MiniStep); warning("STUB: PostMiniStep()"); } -void SYSTEM::SetPal(void) { +void System::setPal() { uint i; Dac *p = Vga::_sysPal + 256 - ArrayCount(_stdPal); for (i = 0; i < ArrayCount(_stdPal); i++) { @@ -631,10 +593,10 @@ void SYSTEM::SetPal(void) { } -void SYSTEM::FunTouch(void) { +void System::funTouch() { uint16 n = (PAIN) ? HEROFUN1 : HEROFUN0; - if (_talk == NULL || n > FunDel) - FunDel = n; + if (_talk == NULL || n > _funDel) + _funDel = n; } @@ -646,16 +608,16 @@ static void ShowBak(int ref) { Bitmap::_pal = NULL; spr->show(2); _vga->copyPage(1, 2); - _sys->SetPal(); + _sys->setPal(); spr->contract(); } } -static void caveUp() { +void CGEEngine::caveUp() { int BakRef = 1000 * _now; if (_music) - LoadMIDI(_now); + loadMidi(_now); ShowBak(BakRef); loadMapping(); @@ -673,10 +635,10 @@ static void caveUp() { spr = n; } if (_sndDrvInfo._dDev) { - _sound.Stop(); - _fx.Clear(); - _fx.Preload(0); - _fx.Preload(BakRef); + _sound.stop(); + _fx.clear(); + _fx.preload(0); + _fx.preload(BakRef); } if (_hero) { @@ -707,7 +669,7 @@ static void caveUp() { _vga->show(); _vga->sunrise(Vga::_sysPal); _dark = false; - if (!_startup) + if (!_startupMode) _mouse->On(); _heart->_enable = true; @@ -771,7 +733,7 @@ void CGEEngine::switchCave(int cav) { _cavLight->gotoxy(CAVE_X + ((_now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((_now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); killText(); - if (!_startup) + if (!_startupMode) KeyClick(); SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint //TODO Change the SNPOST message send to a special way to send function pointer @@ -781,22 +743,22 @@ void CGEEngine::switchCave(int cav) { } } -SYSTEM::SYSTEM(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { - FunDel = HEROFUN0; - SetPal(); - Tick(); +System::System(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { + _funDel = HEROFUN0; + setPal(); + tick(); } -void SYSTEM::touch(uint16 mask, int x, int y) { +void System::touch(uint16 mask, int x, int y) { static int pp = 0; - FunTouch(); + funTouch(); if (mask & KEYB) { int pp0; KeyClick(); killText(); - if (_startup == 1) { + if (_vm->_startupMode == 1) { SNPOST(SNCLEAR, -1, 0, NULL); return; } @@ -854,7 +816,7 @@ void SYSTEM::touch(uint16 mask, int x, int y) { _hero->step(TSEQ + 3); break; case F9: - _sys->FunDel = 1; + _sys->_funDel = 1; break; case 'X': if (_keyboard->_key[ALT]) @@ -891,13 +853,13 @@ void SYSTEM::touch(uint16 mask, int x, int y) { break; case 'W': if (pp == 2) - _jbw = !_jbw; + _vm->_jbw = !_vm->_jbw; break; } if (pp == pp0) pp = 0; } else { - if (_startup) + if (_vm->_startupMode) return; int cav = 0; _infoLine->update(NULL); @@ -915,12 +877,12 @@ void SYSTEM::touch(uint16 mask, int x, int y) { if (y >= POCKET_Y && y < POCKET_Y + POCKET_NY * POCKET_DY && x >= POCKET_X && x < POCKET_X + POCKET_NX * POCKET_DX) { int n = ((y - POCKET_Y) / POCKET_DY) * POCKET_NX + (x - POCKET_X) / POCKET_DX; - selectPocket(n); + _vm->selectPocket(n); } } } - PostMiniStep(cav - 1); + postMiniStep(cav - 1); if (mask & L_UP) { if (cav && _snail->idle() && _hero->_tracePtr < 0) @@ -945,9 +907,9 @@ void SYSTEM::touch(uint16 mask, int x, int y) { } -void SYSTEM::Tick(void) { - if (!_startup) - if (--FunDel == 0) { +void System::tick() { + if (!_vm->_startupMode) + if (--_funDel == 0) { killText(); if (_snail->idle()) { if (PAIN) @@ -968,7 +930,7 @@ void SYSTEM::Tick(void) { } } } - FunTouch(); + funTouch(); } _time = SYSTIMERATE; } @@ -1001,7 +963,7 @@ static void SwitchColorMode(void) { -static void SwitchMusic(void) { +void CGEEngine::switchMusic() { if (_keyboard->_key[ALT]) { if (Vmenu::_addr) SNPOST_(SNKILL, -1, 0, Vmenu::_addr); @@ -1020,9 +982,9 @@ static void SwitchMusic(void) { } } if (_music) - LoadMIDI(_now); + loadMidi(_now); else - KillMIDI(); + killMidi(); } @@ -1203,7 +1165,7 @@ void CGEEngine::optionTouch(int opt, uint16 mask) { break; case 2 : if (mask & L_UP) - SwitchMusic(); + switchMusic(); else if (mask & R_UP) if (!Mixer::_appear) { Mixer::_appear = true; @@ -1220,7 +1182,7 @@ void CGEEngine::optionTouch(int opt, uint16 mask) { #pragma argsused void Sprite::touch(uint16 mask, int x, int y) { - _sys->FunTouch(); + _sys->funTouch(); if ((mask & ATTN) == 0) { _infoLine->update(name()); if (mask & (R_DN | L_DN)) @@ -1236,14 +1198,14 @@ void Sprite::touch(uint16 mask, int x, int y) { mask |= R_UP; } if ((mask & R_UP) && _snail->idle()) { - Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_pocPtr] : NULL; + Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_vm->_pocPtr] : NULL; if (ps) { if (_flags._kept || _hero->distance(this) < MAX_DISTANCE) { if (works(ps)) { feedSnail(ps, TAKE); } else offUse(); - selectPocket(-1); + _vm->selectPocket(-1); } else tooFar(); } else { @@ -1280,7 +1242,7 @@ void Sprite::touch(uint16 mask, int x, int y) { int n; for (n = 0; n < POCKET_NX; n++) { if (_pocket[n] == this) { - selectPocket(n); + _vm->selectPocket(n); break; } } @@ -1614,7 +1576,7 @@ void CGEEngine::runGame() { _sprite->step(_music); SNPOST_(SNSEQ, -1, _music, _sprite); if (!_music) - KillMIDI(); + killMidi(); if (_mini && INI_FILE::exist("MINI.SPR")) { uint8 *ptr = (uint8 *) &*_mini; @@ -1626,7 +1588,7 @@ void CGEEngine::runGame() { _miniCave->moveShapes(ptr); _miniShp[0] = new Bitmap(*_miniCave->shp()); _miniShpList = _miniCave->setShapeList(_miniShp); - PostMiniStep(-1); + postMiniStep(-1); } } } @@ -1661,7 +1623,7 @@ void CGEEngine::runGame() { if (_mouse->Busy) ExpandSprite(_mouse->Busy); - _startup = 0; + _startupMode = 0; SNPOST(SNLEVEL, -1, _oldLev, &_cavLight); _cavLight->gotoxy(CAVE_X + ((_now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, @@ -1761,7 +1723,7 @@ bool CGEEngine::showTitle(const char *name) { _vga->copyPage(0, 2); Startup::_soundOk = 2; if (_music) - LoadMIDI(0); + loadMidi(0); } if (Startup::_mode < 2) { @@ -1854,10 +1816,10 @@ void CGEEngine::cge_main(void) { _horzLine->_flags._hide = true; //srand((uint16) Timer()); - _sys = new SYSTEM(this); + _sys = new System(this); if (_music && Startup::_soundOk) - LoadMIDI(0); + loadMidi(0); if (Startup::_mode < 2) movie(LGO_EXT); @@ -1865,7 +1827,7 @@ void CGEEngine::cge_main(void) { if ((!_isDemo) && (Startup::_mode == 1)) movie("X02"); // intro runGame(); - _startup = 2; + _startupMode = 2; if (FINIS) movie("X03"); } else diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index c5be2adc26e..e9c96931c39 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -113,17 +113,17 @@ namespace CGE { #define FINIS (_flag[3]) -class SYSTEM : public Sprite { - int lum; +class System : public Sprite { + int _lum; public: - int FunDel; + int _funDel; - SYSTEM(CGEEngine *vm); + System(CGEEngine *vm); - void SetPal(); - void FunTouch(); + void setPal(); + void funTouch(); virtual void touch(uint16 mask, int x, int y); - void Tick(); + void tick(); private: CGEEngine *_vm; }; @@ -159,7 +159,6 @@ private: }; - Cluster XZ(int x, int y); Cluster XZ(Couple xy); @@ -169,7 +168,7 @@ void ContractSprite(Sprite *spr); extern WALK *_hero; extern Vga *_vga; extern Heart *_heart; -extern SYSTEM *_sys; +extern System *_sys; extern int _offUseCount; extern Sprite *_pocLight; extern Keyboard *_keyboard; diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 88122073719..11f2088034f 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -143,7 +143,7 @@ static Choice BlsterDMA[] = { void CGEEngine::selectSound() { int i; - _sound.Close(); + _sound.close(); if (Vmenu::_addr) SNPOST_(SNKILL, -1, 0, Vmenu::_addr); inf(_text->getText(STYPE_TEXT)); @@ -201,7 +201,7 @@ static void select(Choice *cho, int hlp) { void CGEEngine::NONE() { _sndDrvInfo._dDev = DEV_QUIET; _sndDrvInfo._mDev = DEV_QUIET; - _sound.Open(); + _sound.open(); } @@ -249,7 +249,7 @@ void CGEEngine::AUTO() { _sndDrvInfo._dDev = DEV_AUTO; _sndDrvInfo._mDev = DEV_AUTO; reset(); - _sound.Open(); + _sound.open(); } @@ -261,7 +261,7 @@ void CGEEngine::setPortD() { void CGEEngine::setPortM() { _sndDrvInfo._mBase = xdeco(MIDIPorts[Vmenu::_recent]._text); - _sound.Open(); + _sound.open(); } @@ -276,7 +276,7 @@ void CGEEngine::setDMA() { if (_sndDrvInfo._mDev != _sndDrvInfo._dDev) select(MIDIPorts, MPORT_TEXT); else - _sound.Open(); + _sound.open(); } } // End of namespace CGE diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp index 158857c0021..ddb4861f036 100644 --- a/engines/cge/ems.cpp +++ b/engines/cge/ems.cpp @@ -41,10 +41,10 @@ enum EMM_FUN { }; -void *EMM::_frame = NULL; +void *Emm::_frame = NULL; -EMM::EMM(long size): _han(-1), _top(0), _lim(0), _list(NULL) { +Emm::Emm(long size): _han(-1), _top(0), _lim(0), _list(NULL) { /* if (Test()) { @@ -82,7 +82,7 @@ EMM::EMM(long size): _han(-1), _top(0), _lim(0), _list(NULL) { } -EMM::~EMM(void) { +Emm::~Emm(void) { /* FIXME Release(); if (Han >= 0) @@ -97,7 +97,7 @@ EMM::~EMM(void) { } -bool EMM::test() { +bool Emm::test() { /* static char e[] = "EMMXXXX0"; @@ -130,7 +130,7 @@ bool EMM::test() { } -EMS *EMM::alloc(uint16 siz) { +Ems *Emm::alloc(uint16 siz) { /* long size = SIZ(siz), top = Top; @@ -167,14 +167,14 @@ EMS *EMM::alloc(uint16 siz) { } fail: return NULL; */ - warning("STUB: EMM::alloc"); + warning("STUB: Emm::alloc"); return NULL; } -void EMM::release() { +void Emm::release() { while (_list) { - EMS *e = _list; + Ems *e = _list; _list = e->_next; delete e; } @@ -182,11 +182,11 @@ void EMM::release() { } -EMS::EMS(void) : _ptr(0), _size(0), _next(NULL) { +Ems::Ems() : _ptr(0), _size(0), _next(NULL) { } -void *EMS::operator & () const { +void *Ems::operator & () const { /* uint16 pgn = (uint16) (Ptr >> 14), off = (uint16) Ptr & PAGE_MASK, @@ -213,12 +213,12 @@ void *EMS::operator & () const { return (void *) (EMM::Frame + (void *) off); */ - warning("STUB: EMS::operator &"); + warning("STUB: Ems::operator &"); return NULL; } -uint16 EMS::size() { +uint16 Ems::size() { return _size; } diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 5bafd46884f..accd6fb4ab2 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -95,7 +95,7 @@ Keyboard::~Keyboard() { } Sprite *Keyboard::setClient(Sprite *spr) { - Swap(_client, spr); + swap(_client, spr); return spr; } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 6b0327ff233..3c0dc8a802e 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -326,7 +326,7 @@ void sndMidiStop() { // FIXME: STUB: sndMIDIStop } -DATACK *LoadWave(XFile *file, EMM *emm) { +DataCk *loadWave(XFile *file, Emm *emm) { warning("STUB: LoadWave"); return NULL; } @@ -394,9 +394,9 @@ Engine_::~Engine_() { warning("STUB: Engine_::~Engine_"); } -DATACK::~DATACK () { - if (!e && Buf) - free(Buf); +DataCk::~DataCk() { + if (!_e && _buf) + free(_buf); } } // End of namespace CGE diff --git a/engines/cge/general.h b/engines/cge/general.h index 63b94d3872c..95660ad4dfa 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -109,41 +109,41 @@ public: }; -class EMS; +class Ems; -class EMM { - friend class EMS; +class Emm { + friend class Ems; bool test(); long _top; long _lim; - EMS *_list; + Ems *_list; int _han; static void *_frame; public: - EMM(long size = 0); - ~EMM(); - EMS *alloc(uint16 siz); + Emm(long size = 0); + ~Emm(); + Ems *alloc(uint16 siz); void release(); }; -class EMS { - friend class EMM; - EMM *_emm; +class Ems { + friend class Emm; + Emm *_emm; long _ptr; uint16 _size; - EMS *_next; + Ems *_next; public: - EMS(); + Ems(); void *operator & () const; uint16 size(void); }; template -void Swap(T &A, T &B) { +void swap(T &A, T &B) { T a = A; A = B; B = a; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index edafd591111..4c1b8d4c2f4 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -60,7 +60,6 @@ extern Sprite *_pocLight; // int _pocPtr = 0; //------------------------------------------------------------------------- extern Sprite *_pocket[]; -extern int _pocPtr; static void SNGame(Sprite *spr, int num) { switch (num) { @@ -290,7 +289,7 @@ int findPocket(Sprite *spr) { } -void selectPocket(int n) { +void CGEEngine::selectPocket(int n) { if (n < 0 || (_pocLight->_seqPtr && _pocPtr == n)) { _pocLight->step(0); n = findPocket(NULL); @@ -591,10 +590,10 @@ void SNSwap(Sprite *spr, int xref) { bool was1 = (was == 0 || was == _now); bool xwas1 = (xwas == 0 || xwas == _now); - Swap(spr->_cave, xspr->_cave); - Swap(spr->_x, xspr->_x); - Swap(spr->_y, xspr->_y); - Swap(spr->_z, xspr->_z); + swap(spr->_cave, xspr->_cave); + swap(spr->_x, xspr->_x); + swap(spr->_y, xspr->_y); + swap(spr->_z, xspr->_z); if (spr->_flags._kept) { int n = findPocket(spr); if (n >= 0) @@ -762,14 +761,14 @@ void SNKill(Sprite *spr) { static void SNSound(Sprite *spr, int wav, int cnt) { if (_sndDrvInfo._dDev) { if (wav == -1) - _sound.Stop(); + _sound.stop(); else - _sound.Play(_fx[wav], (spr) ? ((spr->_x + spr->_w / 2) / (SCR_WID / 16)) : 8, cnt); + _sound.play(_fx[wav], (spr) ? ((spr->_x + spr->_w / 2) / (SCR_WID / 16)) : 8, cnt); } } -void SNKeep(Sprite *spr, int stp) { +void CGEEngine::SNKeep(Sprite *spr, int stp) { selectPocket(-1); if (spr && ! spr->_flags._kept && _pocket[_pocPtr] == NULL) { SNSound(spr, 3, 1); @@ -785,7 +784,7 @@ void SNKeep(Sprite *spr, int stp) { } -void SNGive(Sprite *spr, int stp) { +void CGEEngine::SNGive(Sprite *spr, int stp) { if (spr) { int p = findPocket(spr); if (p >= 0) { @@ -956,13 +955,13 @@ void Snail::runCom() { if (sprel == _hero && sprel->seqTest(-1)) sprel->step(HTALK); _text->say(_text->getText(snc->_val), sprel); - _sys->FunDel = HEROFUN0; + _sys->_funDel = HEROFUN0; } break; case SNINF : if (_talkEnable) { _vm->inf(_text->getText(snc->_val)); - _sys->FunDel = HEROFUN0; + _sys->_funDel = HEROFUN0; } break; case SNTIME : @@ -998,10 +997,10 @@ void Snail::runCom() { SNUncover(sprel, (snc->_val >= 0) ? locate(snc->_val) : ((Sprite *) snc->_ptr)); break; case SNKEEP : - SNKeep(sprel, snc->_val); + _vm->SNKeep(sprel, snc->_val); break; case SNGIVE : - SNGive(sprel, snc->_val); + _vm->SNGive(sprel, snc->_val); break; case SNGAME : SNGame(sprel, snc->_val); diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 2e061495265..bd874a35b47 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -37,7 +37,6 @@ namespace CGE { #define POCKET_Y 176 #define POCKET_DX 18 #define POCKET_DY 22 -#define POCKET_NX 8 #define POCKET_NY 1 #define POCKET_SX 8 @@ -100,7 +99,6 @@ private: }; -void selectPocket(int n); void pocFul(); @@ -110,7 +108,6 @@ extern bool _dark; extern int _now; extern int _lev; extern int _maxCave; -extern int _pocPtr; extern Bar _barriers[]; extern struct Hxy { int _x; diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index aca4b4d5345..a163949ddde 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -35,85 +35,84 @@ namespace CGE { -bool _music = true; -FX _fx = 16; // must precede SOUND!! -SOUND _sound; +Fx _fx = 16; // must precede SOUND!! +Sound _sound; -SOUND::SOUND(void) { +Sound::Sound() { if (Startup::_soundOk) - Open(); + open(); } -SOUND::~SOUND(void) { - Close(); +Sound::~Sound() { + close(); } -void SOUND::Close(void) { - KillMIDI(); +void Sound::close() { + killMidi(); sndDone(); } -void SOUND::Open(void) { +void Sound::open() { sndInit(); - Play(_fx[30000], 8); + play(_fx[30000], 8); } -void SOUND::Play(DATACK *wav, int pan, int cnt) { +void Sound::play(DataCk *wav, int pan, int cnt) { if (wav) { - Stop(); - smpinf._saddr = (uint8 *) &*(wav->EAddr()); - smpinf._slen = (uint16)wav->Size(); - smpinf._span = pan; - smpinf._sflag = cnt; - sndDigiStart(&smpinf); + stop(); + _smpinf._saddr = (uint8 *) &*(wav->eAddr()); + _smpinf._slen = (uint16)wav->size(); + _smpinf._span = pan; + _smpinf._sflag = cnt; + sndDigiStart(&_smpinf); } } -void SOUND::Stop(void) { - sndDigiStop(&smpinf); +void Sound::stop() { + sndDigiStop(&_smpinf); } -FX::FX(int size) : Emm(0L), Current(NULL) { - Cache = new HAN[size]; - for (Size = 0; Size < size; Size++) { - Cache[Size].Ref = 0; - Cache[Size].Wav = NULL; +Fx::Fx(int size) : _emm(0L), _current(NULL) { + _cache = new Han[size]; + for (_size = 0; _size < size; _size++) { + _cache[_size]._ref = 0; + _cache[_size]._wav = NULL; } } -FX::~FX(void) { - Clear(); - delete[] Cache; +Fx::~Fx() { + clear(); + delete[] _cache; } -void FX::Clear(void) { - HAN *p, * q; - for (p = Cache, q = p + Size; p < q; p++) { - if (p->Ref) { - p->Ref = 0; - delete p->Wav; - p->Wav = NULL; +void Fx::clear() { + Han *p, * q; + for (p = _cache, q = p + _size; p < q; p++) { + if (p->_ref) { + p->_ref = 0; + delete p->_wav; + p->_wav = NULL; } } - Emm.release(); - Current = NULL; + _emm.release(); + _current = NULL; } -int FX::Find(int ref) { - HAN *p, * q; +int Fx::find(int ref) { + Han *p, * q; int i = 0; - for (p = Cache, q = p + Size; p < q; p++) { - if (p->Ref == ref) + for (p = _cache, q = p + _size; p < q; p++) { + if (p->_ref == ref) break; else ++i; @@ -122,60 +121,60 @@ int FX::Find(int ref) { } -void FX::Preload(int ref0) { - HAN *CacheLim = Cache + Size; +void Fx::preload(int ref0) { + Han *cacheLim = _cache + _size; int ref; for (ref = ref0; ref < ref0 + 10; ref++) { static char fname[] = "FX00000.WAV"; wtom(ref, fname + 2, 10, 5); INI_FILE file = INI_FILE(fname); - DATACK *wav = LoadWave(&file, &Emm); + DataCk *wav = loadWave(&file, &_emm); if (wav) { - HAN *p = &Cache[Find(0)]; - if (p >= CacheLim) + Han *p = &_cache[find(0)]; + if (p >= cacheLim) break; - p->Wav = wav; - p->Ref = ref; + p->_wav = wav; + p->_ref = ref; } } } -DATACK *FX::Load(int idx, int ref) { +DataCk *Fx::load(int idx, int ref) { static char fname[] = "FX00000.WAV"; wtom(ref, fname + 2, 10, 5); INI_FILE file = INI_FILE(fname); - DATACK *wav = LoadWave(&file, &Emm); + DataCk *wav = loadWave(&file, &_emm); if (wav) { - HAN *p = &Cache[idx]; - p->Wav = wav; - p->Ref = ref; + Han *p = &_cache[idx]; + p->_wav = wav; + p->_ref = ref; } return wav; } -DATACK *FX::operator [](int ref) { +DataCk *Fx::operator [](int ref) { int i; - if ((i = Find(ref)) < Size) - Current = Cache[i].Wav; + if ((i = find(ref)) < _size) + _current = _cache[i]._wav; else { - if ((i = Find(0)) >= Size) { - Clear(); + if ((i = find(0)) >= _size) { + clear(); i = 0; } - Current = Load(i, ref); + _current = load(i, ref); } - return Current; + return _current; } -static uint8 *midi = NULL; +static uint8 *midi = NULL; -void KillMIDI(void) { +void killMidi() { sndMidiStop(); if (midi) { delete[] midi; @@ -184,11 +183,11 @@ void KillMIDI(void) { } -void LoadMIDI(int ref) { +void loadMidi(int ref) { static char fn[] = "00.MID"; wtom(ref, fn, 10, 2); if (INI_FILE::exist(fn)) { - KillMIDI(); + killMidi(); INI_FILE mid = fn; if (mid._error == 0) { uint16 siz = (uint16) mid.size(); @@ -196,7 +195,7 @@ void LoadMIDI(int ref) { if (midi) { mid.read(midi, siz); if (mid._error) - KillMIDI(); + killMidi(); else sndMidiStart(midi); } diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 55dd1615ccb..fda8d4f1282 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -37,44 +37,42 @@ namespace CGE { #define BAD_MIDI_TEXT 98 -class SOUND { +class Sound { public: - SmpInfo smpinf; - SOUND(void); - ~SOUND(void); - void Open(void); - void Close(void); - void Play(DATACK *wav, int pan, int cnt = 1); - void Stop(void); + SmpInfo _smpinf; + Sound(); + ~Sound(); + void open(); + void close(); + void play(DataCk *wav, int pan, int cnt = 1); + void stop(); }; -class FX { - EMM Emm; - struct HAN { - int Ref; - DATACK *Wav; - } *Cache; - int Size; - DATACK *Load(int idx, int ref); - int Find(int ref); +class Fx { + Emm _emm; + struct Han { + int _ref; + DataCk *_wav; + } *_cache; + int _size; + DataCk *load(int idx, int ref); + int find(int ref); public: - DATACK *Current; - FX(int size = 16); - ~FX(void); - void Clear(void); - void Preload(int ref0); - DATACK *operator[](int ref); + DataCk *_current; + Fx(int size = 16); + ~Fx(); + void clear(); + void preload(int ref0); + DataCk *operator[](int ref); }; - -extern bool _music; -extern SOUND _sound; -extern FX _fx; +extern Sound _sound; +extern Fx _fx; -void LoadMIDI(int ref); -void KillMIDI(); +void loadMidi(int ref); +void killMidi(); } // End of namespace CGE diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 0dfbc67916b..6a06cbc537a 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -38,7 +38,7 @@ extern char _copr[]; #define id (*(Ident*)_copr) -EMM _miniEmm = MINI_EMM_SIZE; +Emm _miniEmm = MINI_EMM_SIZE; // static Startup _startUp; diff --git a/engines/cge/startup.h b/engines/cge/startup.h index 96c73880702..cc16f2a1236 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -70,7 +70,7 @@ public: }; -extern EMM _miniEmm; +extern Emm _miniEmm; const char *usrPath(const char *nam); diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 2988f9ab11c..04a91896822 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -105,4 +105,18 @@ void VFile::readBuff() { _ptr = 0; } +long VFile::mark() { + return (_bufMark + _ptr) - _begMark; +} + +long VFile::size() { + return _endMark - _begMark; +} + +long VFile::seek(long pos) { + _recent = NULL; + _lim = 0; + return (_bufMark = _begMark + pos); +} + } // End of namespace CGE diff --git a/engines/cge/vol.h b/engines/cge/vol.h index d8ba0979cbf..8ed33d0ab4b 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -70,28 +70,20 @@ private: long _begMark; long _endMark; - void readBuff(void); - void writeBuff(void) { } + void readBuff(); + void writeBuff() { } void make(const char *fspec); public: VFile(const char *name, IOMODE mode = REA); ~VFile(); + static void init(); static void deinit(); - static bool exist(const char *name); static const char *next(); - long mark() { - return (_bufMark + _ptr) - _begMark; - } - long size() { - return _endMark - _begMark; - } - long seek(long pos) { - _recent = NULL; - _lim = 0; - return (_bufMark = _begMark + pos); - } + long mark(); + long size(); + long seek(long pos); }; diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 062f83dfcaa..c3e67f5f956 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -37,114 +37,111 @@ namespace CGE { #define IBM_FORMAT_ALAW 0x0102 #define IBM_FORMAT_ADPCM 0x0103 +typedef char FourCC[4]; // Four-character code -typedef char FOURCC[4]; // Four-character code -typedef uint32 CKSIZE; // 32-bit unsigned size - - -class CKID { // Chunk type identifier +class ChunkId { // Chunk type identifier union { - FOURCC Tx; - uint32 Id; + FourCC _tx; + uint32 _id; }; protected: static XFile *ckFile; public: - CKID(FOURCC t) { - memcpy(Tx, t, sizeof(Tx)); + ChunkId(FourCC t) { + memcpy(_tx, t, sizeof(_tx)); } - CKID(uint32 d) { - Id = d; + ChunkId(uint32 d) { + _id = d; } - CKID(XFile *xf) { - (ckFile = xf)->read(Tx, sizeof(Tx)); + ChunkId(XFile *xf) { + (ckFile = xf)->read(_tx, sizeof(_tx)); } - bool operator !=(CKID &X) { - return Id != X.Id; + bool operator !=(ChunkId &X) { + return _id != X._id; } - bool operator ==(CKID &X) { - return Id == X.Id; + bool operator ==(ChunkId &X) { + return _id == X._id; } - const char *Name(void); + const char *name(); }; -class CKHEA : public CKID { +class CkHea : public ChunkId { protected: - CKSIZE ckSize; // Chunk size field (size of ckData) + uint32 _ckSize; // Chunk size field (size of ckData) public: - CKHEA(XFile *xf) : CKID(xf) { - XRead(xf, &ckSize); + CkHea(XFile *xf) : ChunkId(xf) { + XRead(xf, &_ckSize); } - CKHEA(char id[]) : CKID(id), ckSize(0) { } - void Skip(void); - CKSIZE Size(void) { - return ckSize; + CkHea(char id[]) : ChunkId(id), _ckSize(0) { } + void skip(); + uint32 size() { + return _ckSize; } }; -class FMTCK : public CKHEA { - struct WAV { - uint16 wFormatTag; // Format category - uint16 wChannels; // Number of channels - uint32 dwSamplesPerSec; // Sampling rate - uint32 dwAvgBytesPerSec; // For buffer estimation - uint16 wBlockAlign; // Data block size - } Wav; +class FmtCk : public CkHea { + struct Wav { + uint16 _wFormatTag; // Format category + uint16 _wChannels; // Number of channels + uint32 _dwSamplesPerSec; // Sampling rate + uint32 _dwAvgBytesPerSec; // For buffer estimation + uint16 _wBlockAlign; // Data block size + } _wav; union { struct { - uint16 wBitsPerSample; // Sample size - } Pcm; + uint16 _wBitsPerSample; // Sample size + } _pcm; }; public: - FMTCK(CKHEA &hea); - inline uint16 Channels(void) { - return Wav.wChannels; + FmtCk(CkHea &hea); + inline uint16 channels() { + return _wav._wChannels; } - inline uint32 SmplRate(void) { - return Wav.dwSamplesPerSec; + inline uint32 smplRate() { + return _wav._dwSamplesPerSec; } - inline uint32 ByteRate(void) { - return Wav.dwAvgBytesPerSec; + inline uint32 byteRate() { + return _wav._dwAvgBytesPerSec; } - inline uint16 BlckSize(void) { - return Wav.wBlockAlign; + inline uint16 blckSize() { + return _wav._wBlockAlign; } - inline uint16 SmplSize(void) { - return Pcm.wBitsPerSample; + inline uint16 smplSize() { + return _pcm._wBitsPerSample; } }; -class DATACK : public CKHEA { - bool e; +class DataCk : public CkHea { + bool _e; union { - uint8 *Buf; - EMS *EBuf; + uint8 *_buf; + Ems *_eBuf; }; public: - DATACK(CKHEA &hea); - DATACK(CKHEA &hea, EMM *emm); - DATACK(int first, int last); - ~DATACK(void); - inline uint8 *Addr(void) { - return Buf; + DataCk(CkHea &hea); + DataCk(CkHea &hea, Emm *emm); + DataCk(int first, int last); + ~DataCk(); + inline uint8 *addr() { + return _buf; } - inline EMS *EAddr(void) { - return EBuf; + inline Ems *eAddr() { + return _eBuf; } }; -extern CKID RIFF; -extern CKID WAVE; -extern CKID FMT; -extern CKID DATA; +extern ChunkId _riff; +extern ChunkId _wave; +extern ChunkId _fmt; +extern ChunkId _data; -DATACK *LoadWave(XFile *file, EMM *emm = NULL); +DataCk *loadWave(XFile *file, Emm *emm = NULL); } // End of namespace CGE From dbf9e4679c694277be20dd1d1bc5db8d60f7fabd Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 3 Jul 2011 22:30:24 +1000 Subject: [PATCH 079/276] CGE: Started work on endifying savegame loading --- engines/cge/general.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/engines/cge/general.h b/engines/cge/general.h index 95660ad4dfa..438e9c014db 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -176,6 +176,12 @@ public: virtual long mark() = 0; virtual long size() = 0; virtual long seek(long pos) = 0; + + uint16 readWord() { + uint16 v; + read(&v, sizeof(uint16)); + return FROM_LE_32(v); + } }; From fe0ff3b2e98b8a0ec68f497925aefbdea77aeed0 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 5 Jul 2011 20:26:34 +1000 Subject: [PATCH 080/276] CGE: Converted loadGame to use the ScummVM serialiser --- engines/cge/cge_main.cpp | 48 ++++++++++++++++++++++++++++++---------- engines/cge/general.cpp | 4 ++++ engines/cge/general.h | 6 ----- engines/cge/vga13h.cpp | 24 ++++++++++++++++++++ engines/cge/vga13h.h | 3 +++ 5 files changed, 67 insertions(+), 18 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 6b02f82910c..08e373d322a 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -26,6 +26,8 @@ */ #include "common/scummsys.h" +#include "common/memstream.h" +#include "common/serializer.h" #include "cge/general.h" #include "cge/sound.h" #include "cge/startup.h" @@ -182,14 +184,39 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { Sprite *spr; int i; - for (st = _savTab; st->Ptr; st++) { - if (file._error) - error("Bad SVG"); - file.read((uint8 *)((tiny || st->Flg) ? st->Ptr : &i), st->Len); - } + // Read the data into a data buffer + int size = file.size() - file.mark(); + byte *dataBuffer = new byte[size]; + file.read(dataBuffer, size); + Common::MemoryReadStream readStream(dataBuffer, size, DisposeAfterUse::YES); + Common::Serializer s(&readStream, NULL); - file.read((uint8 *) &i, sizeof(i)); - if (i != SVGCHKSUM) + // Synchronise header data + s.syncAsUint16LE(_now); + s.syncAsUint16LE(_oldLev); + s.syncAsUint16LE(_demoText); + for (i = 0; i < 5; ++i) + s.syncAsUint16LE(_game); + s.syncAsSint16LE(i); // unused VGA::Mono variable + s.syncAsUint16LE(_music); + s.syncBytes(_volume, 2); + for (i = 0; i < 4; ++i) + s.syncAsUint16LE(_flag[i]); + + for (i = 0; i < CAVE_MAX; ++i) { + s.syncAsSint16LE(_heroXY[i]._x); + s.syncAsUint16LE(_heroXY[i]._y); + } + for (i = 0; i < 1 + CAVE_MAX; ++i) { + s.syncAsByte(_barriers[i]._horz); + s.syncAsByte(_barriers[i]._vert); + } + for (i = 0; i < POCKET_NX; ++i) + s.syncAsUint16LE(_pocref[i]); + + uint16 checksum; + s.syncAsUint16LE(checksum); + if (checksum != SVGCHKSUM) error("%s", _text->getText(BADSVG_TEXT)); if (Startup::_core < CORE_HIG) @@ -202,12 +229,9 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { } if (! tiny) { // load sprites & pocket - while (!file._error) { + while (!readStream.eos()) { Sprite S(this, NULL); - uint16 n = file.read((uint8 *) &S, sizeof(S)); - - if (n != sizeof(S)) - break; + S.sync(s); S._prev = S._next = NULL; spr = (scumm_stricmp(S._file + 2, "MUCHA") == 0) ? new Fly(this, NULL) diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 3c0dc8a802e..50dfeaeb5a9 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -238,6 +238,10 @@ uint16 IoHand::read(void *buf, uint16 len) { error("Read %s - %d bytes", _file->getName(), len); if (_crypt) _seed = _crypt(buf, len, Seed); + + if (_file->eos()) + _error = 1; + return bytesRead; } diff --git a/engines/cge/general.h b/engines/cge/general.h index 438e9c014db..95660ad4dfa 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -176,12 +176,6 @@ public: virtual long mark() = 0; virtual long size() = 0; virtual long seek(long pos) = 0; - - uint16 readWord() { - uint16 v; - read(&v, sizeof(uint16)); - return FROM_LE_32(v); - } }; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index aa7cd8ad06c..1aec1689bc7 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -779,6 +779,30 @@ BMP_PTR Sprite::ghost() { return NULL; } +void Sprite::sync(Common::Serializer &s) { + uint16 unused; + + s.syncAsUint16LE(unused); + s.syncAsUint16LE(unused); // _ext + s.syncAsUint16LE(_ref); + s.syncAsByte(_cave); + s.syncBytes((byte *)&_flags, 2); + s.syncAsUint16LE(_x); + s.syncAsUint16LE(_y); + s.syncAsByte(_z); + s.syncAsUint16LE(_w); + s.syncAsUint16LE(_h); + s.syncAsUint16LE(_time); + s.syncAsByte(_nearPtr); + s.syncAsByte(_takePtr); + s.syncAsUint16LE(_seqPtr); + s.syncAsUint16LE(_shpCnt); + s.syncBytes((byte *)&_file[0], 9); + _file[8] = '\0'; + + s.syncAsUint16LE(unused); // _prev + s.syncAsUint16LE(unused); // _next +} Sprite *spriteAt(int x, int y) { Sprite *spr = NULL, * tail = _vga->_showQ->last(); diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 5ef7f99c694..d5a87e973df 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -28,6 +28,7 @@ #ifndef __CGE_VGA13H__ #define __CGE_VGA13H__ +#include "common/serializer.h" #include "graphics/surface.h" #include "cge/general.h" #include "cge/bitmap.h" @@ -201,6 +202,7 @@ public: char _file[MAXFILE]; Sprite *_prev; Sprite *_next; + bool works(Sprite *spr); bool seqTest(int n); inline bool active() { @@ -231,6 +233,7 @@ public: Snail::Com *snList(SNLIST type); virtual void touch(uint16 mask, int x, int y); virtual void tick(); + void sync(Common::Serializer &s); private: CGEEngine *_vm; }; From a1f177317c780f1223f153ccc3934eae2a76111b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 5 Jul 2011 20:40:24 +1000 Subject: [PATCH 081/276] CGE: Bugfix for ProgName method --- engines/cge/general.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 50dfeaeb5a9..c4552e6f231 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -99,12 +99,12 @@ void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, c } const char *progName(const char *ext) { - warning("progName"); - - static Common::String buf = "CGE"; + static char buf[MAXFILE]; + strcpy(buf, "CGE"); if (ext) - buf += ext; - return buf.c_str(); + strcat(buf, ext); + + return buf; } char *mergeExt(char *buf, const char *nam, const char *ext) { @@ -238,10 +238,6 @@ uint16 IoHand::read(void *buf, uint16 len) { error("Read %s - %d bytes", _file->getName(), len); if (_crypt) _seed = _crypt(buf, len, Seed); - - if (_file->eos()) - _error = 1; - return bytesRead; } From 41c7482a525951407dfa09b9793eeef140f21979 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 5 Jul 2011 20:51:29 +1000 Subject: [PATCH 082/276] CGE: Implement random number source --- engines/cge/cge.cpp | 2 +- engines/cge/cge.h | 1 + engines/cge/general.cpp | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 87c3964563a..7eeb20bebba 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -41,7 +41,7 @@ namespace CGE { CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) - : Engine(syst), _gameDescription(gameDescription) { + : Engine(syst), _gameDescription(gameDescription), _randomSource("cge") { // Debug/console setup DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel"); diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 04f395559f1..a3adf43dde5 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -70,6 +70,7 @@ public: bool _music; int _pocref[POCKET_NX]; uint8 _volume[2]; + Common::RandomSource _randomSource; virtual Common::Error run(); GUI::Debugger *getDebugger() { diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index c4552e6f231..30b5f3186bb 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -25,6 +25,7 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ +#include "cge/cge.h" #include "cge/general.h" #include "cge/snddrv.h" #include "cge/wav.h" @@ -356,8 +357,7 @@ long timer(void) { } int new_random(int range) { - warning("STUB: new_random(a)"); - return 0; + return ((CGEEngine *)g_engine)->_randomSource.getRandomNumber(range - 1); } #define TIMER_INT 0x08 From 44490c378dd78f8a51203ca8c3d45126bbd9fd08 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 5 Jul 2011 21:07:14 +1000 Subject: [PATCH 083/276] CGE: _hero isn't meant to be instantiated during the engine setup --- engines/cge/cge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 7eeb20bebba..df40db55e68 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -58,6 +58,7 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) void CGEEngine::setup() { // Initialise fields _lastFrame = 0; + _hero = NULL; // Create debugger console _console = new CGEConsole(this); @@ -72,7 +73,6 @@ void CGEEngine::setup() { _text = new Text(this, progName(), 128); _vga = new Vga(M13H); _heart = new Heart; - _hero = new WALK(this, NULL); _sys = new System(this); _pocLight = new Sprite(this, LI); for (int i = 0; i < POCKET_NX; i++) From 24fa551a71453dd712b5cb0223b2ff85026a2894 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 5 Jul 2011 21:11:59 +1000 Subject: [PATCH 084/276] CGE: Fix synchronising Sprite::_seqPtr to be a signed int16 --- engines/cge/vga13h.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 1aec1689bc7..c349950beee 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -795,7 +795,7 @@ void Sprite::sync(Common::Serializer &s) { s.syncAsUint16LE(_time); s.syncAsByte(_nearPtr); s.syncAsByte(_takePtr); - s.syncAsUint16LE(_seqPtr); + s.syncAsSint16LE(_seqPtr); s.syncAsUint16LE(_shpCnt); s.syncBytes((byte *)&_file[0], 9); _file[8] = '\0'; From c676f88da02f56a8b7caecb83bcf9e1a9f7e663c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 5 Jul 2011 21:39:14 +1000 Subject: [PATCH 085/276] CGE: Rearrange engine setup so sprite arrays are setup before they're needed --- engines/cge/cge.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index df40db55e68..eee359b74c6 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -69,21 +69,7 @@ void CGEEngine::setup() { Bitmap::init(); Talk::init(); - // Initialise engine objects - _text = new Text(this, progName(), 128); - _vga = new Vga(M13H); - _heart = new Heart; - _sys = new System(this); - _pocLight = new Sprite(this, LI); - for (int i = 0; i < POCKET_NX; i++) - _pocket[i] = new Sprite(this, NULL); - _sprite = new Sprite(this, NULL); - _miniCave = new Sprite(this, NULL); - _shadow = new Sprite(this, NULL); - _horzLine = new Sprite(this, HL); - _infoLine = new InfoLine(this, INFO_W); - _cavLight = new Sprite(this, PR); - _debugLine = new InfoLine(this, SCR_WID); + // Initialise sprite arrays used by game objects MB[0] = new Bitmap("BRICK", true); MB[1] = NULL; HL[0] = new Bitmap("HLINE", true); @@ -101,6 +87,22 @@ void CGEEngine::setup() { LI[2] = new Bitmap("LITE2", true); LI[3] = new Bitmap("LITE3", true); LI[4] = NULL; + + // Initialise engine objects + _text = new Text(this, progName(), 128); + _vga = new Vga(M13H); + _heart = new Heart; + _sys = new System(this); + _pocLight = new Sprite(this, LI); + for (int i = 0; i < POCKET_NX; i++) + _pocket[i] = new Sprite(this, NULL); + _sprite = new Sprite(this, NULL); + _miniCave = new Sprite(this, NULL); + _shadow = new Sprite(this, NULL); + _horzLine = new Sprite(this, HL); + _infoLine = new InfoLine(this, INFO_W); + _cavLight = new Sprite(this, PR); + _debugLine = new InfoLine(this, SCR_WID); _snail = new Snail(this, false); _snail_ = new Snail(this, true); From 2997db0040d4c4e7ead02f37d8e7bd2c0ce6b206 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 5 Jul 2011 22:06:26 +1000 Subject: [PATCH 086/276] CGE: Minor bugfixes for game loading --- engines/cge/cge_main.cpp | 2 +- engines/cge/vga13h.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 08e373d322a..14109ddd6fa 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -229,7 +229,7 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { } if (! tiny) { // load sprites & pocket - while (!readStream.eos()) { + while (readStream.pos() < readStream.size()) { Sprite S(this, NULL); S.sync(s); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index c349950beee..6c20a78caee 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -349,6 +349,14 @@ Sprite::Sprite(CGEEngine *vm, BMP_PTR *shpP) _ext(NULL), _ref(-1), _cave(0), _vm(vm) { memset(_file, 0, sizeof(_file)); *((uint16 *)&_flags) = 0; + _ref = 0; + _x = _y = 0; + _w = _h = 0; + _time = 0; + _seqPtr = 0; + _shpCnt = 0; + _prev = _next = NULL; + setShapeList(shpP); } From c86c62b288dd3c8a1a630864142f99b177e4db3a Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 5 Jul 2011 23:13:12 +0200 Subject: [PATCH 087/276] CGE: Cleanup and renaming. Also move some static and global functions to CGEEngine. --- engines/cge/bitmap.cpp | 4 +- engines/cge/btfile.cpp | 2 +- engines/cge/cfile.cpp | 12 +- engines/cge/cge.cpp | 21 ++++ engines/cge/cge.h | 69 +++++++++- engines/cge/cge_main.cpp | 82 ++++++------ engines/cge/cge_main.h | 13 +- engines/cge/config.cpp | 4 +- engines/cge/console.h | 2 +- engines/cge/ems.cpp | 2 +- engines/cge/events.cpp | 10 +- engines/cge/general.cpp | 18 +-- engines/cge/general.h | 10 +- engines/cge/mixer.cpp | 2 +- engines/cge/snail.cpp | 264 ++++++++++++++++----------------------- engines/cge/snail.h | 9 -- engines/cge/vga13h.cpp | 10 +- engines/cge/vga13h.h | 5 +- engines/cge/vmenu.cpp | 2 +- 19 files changed, 281 insertions(+), 260 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index d0c7ba6ab5a..4630f874563 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -142,7 +142,7 @@ Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL) { } -Bitmap::~Bitmap(void) { +Bitmap::~Bitmap() { if (memType(_m) == FAR_MEM) free(_m); @@ -196,7 +196,7 @@ uint16 Bitmap::moveVmap(uint8 *buf) { } -BMP_PTR Bitmap::code(void) { +BMP_PTR Bitmap::code() { if (_m) { uint16 i, cnt; diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 3d0ce8a061e..eda18ebaaf8 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -52,7 +52,7 @@ BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt) } -BtFile::~BtFile(void) { +BtFile::~BtFile() { for (int i = 0; i < BT_LEVELS; i++) { putPage(i, false); delete _buff[i]._page; diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 51e580a53be..b235d552b27 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -51,7 +51,7 @@ IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt) error("No core for I/O [%s]", name); } -IoBuf::~IoBuf(void) { +IoBuf::~IoBuf() { if (_mode > REA) writeBuff(); if (_buff) @@ -59,14 +59,14 @@ IoBuf::~IoBuf(void) { } -void IoBuf::readBuff(void) { +void IoBuf::readBuff() { _bufMark = IoHand::mark(); _lim = IoHand::read(_buff, IOBUF_SIZE); _ptr = 0; } -void IoBuf::writeBuff(void) { +void IoBuf::writeBuff() { if (_lim) { IoHand::write(_buff, _lim); _bufMark = IoHand::mark(); @@ -203,11 +203,11 @@ CFile::CFile(const char *name, IOMODE mode, CRYPT *crpt) } -CFile::~CFile(void) { +CFile::~CFile() { } -void CFile::flush(void) { +void CFile::flush() { if (_mode > REA) writeBuff(); else @@ -222,7 +222,7 @@ void CFile::flush(void) { } -long CFile::mark(void) { +long CFile::mark() { return _bufMark + ((_mode > REA) ? _lim : _ptr); } diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index eee359b74c6..067b9eb6e98 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -167,6 +167,27 @@ void CGEEngine::setup() { _savTab[15].Ptr = NULL; _savTab[15].Len = 0; _savTab[15].Flg = 0; + + if (_isDemo) { + _maxCaveArr[0] = CAVE_MAX; + _maxCaveArr[1] = -1; + _maxCaveArr[2] = -1; + _maxCaveArr[3] = -1; + _maxCaveArr[4] = -1; + } else { + _maxCaveArr[0] = 1; + _maxCaveArr[1] = 8; + _maxCaveArr[2] = 16; + _maxCaveArr[3] = 23; + _maxCaveArr[4] = 24; + }; + _maxCave = 0; + _dark = false; + _game = false; + _now = 1; + _lev = -1; + + } CGEEngine::~CGEEngine() { diff --git a/engines/cge/cge.h b/engines/cge/cge.h index a3adf43dde5..e4b8ef86c17 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -30,6 +30,7 @@ #include "graphics/surface.h" #include "engines/advancedDetector.h" #include "cge/console.h" +#include "cge/bitmap.h" #define CGE_SAVEGAME_VERSION 1 @@ -43,6 +44,8 @@ enum { kCGEDebug = 1 << 0 }; +enum SNLIST { NEAR, TAKE }; + #define POCKET_NX 8 struct SavTab { @@ -70,6 +73,15 @@ public: bool _music; int _pocref[POCKET_NX]; uint8 _volume[2]; + int _maxCaveArr[5]; + + int _maxCave; + bool _flag[4]; + bool _dark; + bool _game; + int _now; + int _lev; + Common::RandomSource _randomSource; virtual Common::Error run(); @@ -95,7 +107,6 @@ public: void takeName(); void inf(const char *txt); void selectSound(); - void SNSelect(); void dummy() {} void NONE(); void SB(); @@ -116,8 +127,58 @@ public: void SaveGame(XFile &file); void switchMusic(); void selectPocket(int n); - void SNKeep(Sprite *spr, int stp); - void SNGive(Sprite *spr, int stp); + void expandSprite(Sprite *spr); + void contractSprite(Sprite *spr); + int findPocket(Sprite *spr); + void feedSnail(Sprite *spr, SNLIST snq); + void pocFul(); + void hide1(Sprite *spr); + void loadMapping(); + void saveMapping(); + + void snBackPt(Sprite *spr, int stp); + void snBarrier(int cav, int bar, bool horz); + void snCover(Sprite *spr, int xref); + void snFlag(int fn, bool v); + void snFlash(bool on); + void snGame(Sprite *spr, int num); + void snGhost(Bitmap *bmp); + void snGive(Sprite *spr, int stp); + void snHide(Sprite *spr, int val); + void snKeep(Sprite *spr, int stp); + void snKill(Sprite *spr); + void snLevel(Sprite *spr, int lev); + void snLight(bool in); + void snMouse(bool on); + void snNNext(Sprite *sprel, int p); + void snPort(Sprite *spr, int port); + void snReach(Sprite *spr, int mode); + void snRelZ(Sprite *spr, int z); + void snRNNext(Sprite *sprel, int p); + void snRTNext(Sprite *sprel, int p); + void snSelect(); + void snSend(Sprite *spr, int val); + void snRelX(Sprite *spr, int x); + void snRelY(Sprite *spr, int y); + void snRmNear(Sprite *spr); + void snRmTake(Sprite *spr); + void snRSeq(Sprite *spr, int val); + void snSeq(Sprite *spr, int val); + void snSetRef(Sprite *spr, int nr); + void snSetX(Sprite *spr, int x); + void snSetX0(int cav, int x0); + void snSetXY(Sprite *spr, uint16 xy); + void snSetY(Sprite *spr, int y); + void snSetY0(int cav, int y0); + void snSetZ(Sprite *spr, int z); + void snSlave(Sprite *spr, int ref); + void snSound(Sprite *spr, int wav, int cnt); + void snSwap(Sprite *spr, int xref); + void snTNext(Sprite *sprel, int p); + void snTrans(Sprite *spr, int trans); + void snUncover(Sprite *spr, Sprite *xspr); + void snWalk(Sprite *spr, int x, int y); + void snZTrim(Sprite *spr); private: CGEConsole *_console; @@ -128,7 +189,7 @@ private: class Console : public GUI::Debugger { public: Console(CGEEngine *vm) {} - virtual ~Console(void) {} + virtual ~Console() {} }; } // End of namespace CGE diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 14109ddd6fa..456a11092e9 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -100,17 +100,14 @@ static Ems *_mini = _miniEmm.alloc((uint16)MINI_EMM_SIZE); static BMP_PTR *_miniShpList = NULL; static BMP_PTR _miniShp[] = { NULL, NULL }; static bool _finis = false; -//static int _startup = 1; int _offUseCount; uint16 *_intStackPtr = false; Hxy _heroXY[CAVE_MAX] = {{0, 0}}; Bar _barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; -extern int findPocket(Sprite *); extern Dac _stdPal[58]; -void feedSnail(Sprite *spr, SNLIST snq); // defined in SNAIL uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; @@ -119,7 +116,7 @@ uint8 &Cluster::cell() { } -bool Cluster::Protected(void) { +bool Cluster::Protected() { /* if (A == Barriers[Now]._vert || B == Barriers[Now]._horz) return true; @@ -250,7 +247,7 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { } -static void SaveSound(void) { +static void SaveSound() { CFile cfg(usrPath(progName(CFG_EXT)), WRI); if (!cfg._error) cfg.write(&_sndDrvInfo, sizeof(_sndDrvInfo) - sizeof(_sndDrvInfo.Vol2)); @@ -324,7 +321,7 @@ static void loadHeroXY() { } -static void loadMapping() { +void CGEEngine::loadMapping() { if (_now <= CAVE_MAX) { INI_FILE cf(progName(".TAB")); if (!cf._error) { @@ -357,7 +354,7 @@ void WALK::tick() { for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (distance(spr) < 2) { if (!spr->_flags._near) { - feedSnail(spr, NEAR); + _vm->feedSnail(spr, NEAR); spr->_flags._near = true; } } else { @@ -423,7 +420,7 @@ void WALK::turn(DIR d) { } -void WALK::park(void) { +void WALK::park() { if (_time == 0) ++_time; @@ -438,7 +435,7 @@ void WALK::park(void) { void WALK::findWay(Cluster c) { warning("STUB: WALK::findWay"); /* - bool Find1Way(void); + bool Find1Way(); extern uint16 Target; if (c != Here) { @@ -539,15 +536,14 @@ void CGEEngine::setMapBrick(int x, int z) { } } -static void SwitchColorMode(void); +static void SwitchColorMode(); static void switchDebug(); -static void KillSprite(void); -static void PushSprite(void); -static void PullSprite(void); -static void NextStep(void); -static void SaveMapping(void); +static void KillSprite(); +static void PushSprite(); +static void PullSprite(); +static void NextStep(); -static void KeyClick(void) { +static void KeyClick() { SNPOST_(SNSOUND, -1, 5, NULL); } @@ -654,7 +650,7 @@ void CGEEngine::caveUp() { if (spr->_flags._back) spr->backShow(); else - ExpandSprite(spr); + expandSprite(spr); } spr = n; } @@ -814,7 +810,7 @@ void System::touch(uint16 mask, int x, int y) { break; case '`': if (_keyboard->_key[ALT]) - SaveMapping(); + _vm->saveMapping(); else _vm->switchMapping(); break; @@ -890,9 +886,9 @@ void System::touch(uint16 mask, int x, int y) { if (y >= WORLD_HIG) { if (x < BUTTON_X) { // select cave? if (y >= CAVE_Y && y < CAVE_Y + CAVE_NY * CAVE_DY && - x >= CAVE_X && x < CAVE_X + CAVE_NX * CAVE_DX && !_game) { + x >= CAVE_X && x < CAVE_X + CAVE_NX * CAVE_DX && !_vm->_game) { cav = ((y - CAVE_Y) / CAVE_DY) * CAVE_NX + (x - CAVE_X) / CAVE_DX + 1; - if (cav > _maxCave) + if (cav > _vm->_maxCave) cav = 0; } else { cav = 0; @@ -922,7 +918,7 @@ void System::touch(uint16 mask, int x, int y) { } else { if (!_talk && _snail->idle() && _hero - && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && !_game) { + && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && !_vm->_game) { _hero->findWay(XZ(x, y)); } } @@ -961,7 +957,7 @@ void System::tick() { /* -static void SpkOpen(void) { +static void SpkOpen() { asm in al,0x61 asm or al,0x03 asm out 0x61,al @@ -970,7 +966,7 @@ static void SpkOpen(void) { } -static void SpkClose(void) { +static void SpkClose() { asm in al,0x61 asm and al,0xFC asm out 0x61,al @@ -979,7 +975,7 @@ static void SpkClose(void) { */ -static void SwitchColorMode(void) { +static void SwitchColorMode() { SNPOST_(SNSEQ, 121, _vga->_mono = !_vga->_mono, NULL); KeyClick(); _vga->setColors(Vga::_sysPal, 64); @@ -1054,7 +1050,7 @@ void CGEEngine::switchMapping() { } -static void KillSprite(void) { +static void KillSprite() { _sprite->_flags._kill = true; _sprite->_flags._bDel = true; SNPOST_(SNKILL, -1, 0, _sprite); @@ -1062,7 +1058,7 @@ static void KillSprite(void) { } -static void PushSprite(void) { +static void PushSprite() { Sprite *spr = _sprite->_prev; if (spr) { _vga->_showQ->insert(_vga->_showQ->remove(_sprite), spr); @@ -1073,7 +1069,7 @@ static void PushSprite(void) { } -static void PullSprite(void) { +static void PullSprite() { bool ok = false; Sprite *spr = _sprite->_next; if (spr) { @@ -1091,12 +1087,12 @@ static void PullSprite(void) { } -static void NextStep(void) { +static void NextStep() { SNPOST_(SNSTEP, 0, 0, _sprite); } -static void SaveMapping() { +void CGEEngine::saveMapping() { { IoHand cf(progName(".TAB"), UPD); if (!cf._error) { @@ -1217,7 +1213,7 @@ void Sprite::touch(uint16 mask, int x, int y) { } if (_flags._syst) return; // cannot access system sprites - if (_game) if (mask & L_UP) { + if (_vm->_game) if (mask & L_UP) { mask &= ~L_UP; mask |= R_UP; } @@ -1226,7 +1222,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if (ps) { if (_flags._kept || _hero->distance(this) < MAX_DISTANCE) { if (works(ps)) { - feedSnail(ps, TAKE); + _vm->feedSnail(ps, TAKE); } else offUse(); _vm->selectPocket(-1); @@ -1239,8 +1235,8 @@ void Sprite::touch(uint16 mask, int x, int y) { if (_hero->distance(this) < MAX_DISTANCE) { /// if (_flags._port) { - if (findPocket(NULL) < 0) - pocFul(); + if (_vm->findPocket(NULL) < 0) + _vm->pocFul(); else { SNPOST(SNREACH, -1, -1, this); SNPOST(SNKEEP, -1, -1, this); @@ -1251,7 +1247,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if (snList(TAKE)[_takePtr]._com == SNNEXT) offUse(); else - feedSnail(this, TAKE); + _vm->feedSnail(this, TAKE); } else offUse(); } @@ -1606,7 +1602,7 @@ void CGEEngine::runGame() { uint8 *ptr = (uint8 *) &*_mini; if (ptr != NULL) { loadSprite("MINI", -1, 0, MINI_X, MINI_Y); - ExpandSprite(_miniCave = _sprite); // NULL is ok + expandSprite(_miniCave = _sprite); // NULL is ok if (_miniCave) { _miniCave->_flags._hide = true; _miniCave->moveShapes(ptr); @@ -1618,7 +1614,7 @@ void CGEEngine::runGame() { } if (_hero) { - ExpandSprite(_hero); + expandSprite(_hero); _hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); if (INI_FILE::exist("00SHADOW.SPR")) { loadSprite("00SHADOW", -1, 0, _hero->_x + 14, _hero->_y + 51); @@ -1645,7 +1641,7 @@ void CGEEngine::runGame() { _mouse->Busy = _vga->_spareQ->locate(BUSY_REF); if (_mouse->Busy) - ExpandSprite(_mouse->Busy); + expandSprite(_mouse->Busy); _startupMode = 0; @@ -1682,7 +1678,7 @@ void CGEEngine::movie(const char *ext) { const char *fn = progName(ext); if (INI_FILE::exist(fn)) { loadScript(fn); - ExpandSprite(_vga->_spareQ->locate(999)); + expandSprite(_vga->_spareQ->locate(999)); feedSnail(_vga->_showQ->locate(999), TAKE); // FIXME: Allow ScummVM to handle mouse display @@ -1793,9 +1789,9 @@ bool CGEEngine::showTitle(const char *name) { loadGame(file, true); // only system vars _vga->setColors(Vga::_sysPal, 64); _vga->update(); - if (FINIS) { + if (_flag[3]) { //flag FINIS Startup::_mode++; - FINIS = false; + _flag[3] = false; } } else Startup::_mode++; @@ -1815,14 +1811,14 @@ bool CGEEngine::showTitle(const char *name) { /* -void StkDump (void) { +void StkDump () { CFILE f("!STACK.DMP", BFW); f.Write((uint8 *) (intStackPtr-STACK_SIZ/2), STACK_SIZ*2); } */ -void CGEEngine::cge_main(void) { +void CGEEngine::cge_main() { uint16 intStack[STACK_SIZ / 2]; _intStackPtr = intStack; @@ -1852,7 +1848,7 @@ void CGEEngine::cge_main(void) { movie("X02"); // intro runGame(); _startupMode = 2; - if (FINIS) + if (_flag[3]) // Flag FINIS movie("X03"); } else _vga->sunset(); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index e9c96931c39..3ef3679e8e1 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -109,8 +109,8 @@ namespace CGE { #define SYSTIMERATE 6 // 12 Hz #define HEROFUN0 (40 * 12) #define HEROFUN1 ( 2 * 12) -#define PAIN (_flag[0]) -#define FINIS (_flag[3]) +#define PAIN (_vm->_flag[0]) +//#define FINIS (_vm->_flag[3]) class System : public Sprite { @@ -132,10 +132,10 @@ private: class Cluster : public Couple { public: static uint8 _map[MAP_ZCNT][MAP_XCNT]; - uint8 &cell(void); - Cluster(void) : Couple() { } + uint8 &cell(); + Cluster() : Couple() { } Cluster(int a, int b) : Couple(a, b) { } - bool Protected(void); + bool Protected(); }; @@ -162,9 +162,6 @@ private: Cluster XZ(int x, int y); Cluster XZ(Couple xy); -void ExpandSprite(Sprite *spr); -void ContractSprite(Sprite *spr); - extern WALK *_hero; extern Vga *_vga; extern Heart *_heart; diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 11f2088034f..808d74ff9b4 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -154,7 +154,7 @@ void CGEEngine::selectSound() { } -static void reset(void) { +static void reset() { _sndDrvInfo._dBase = _sndDrvInfo._dIrq = _sndDrvInfo._dDma = _sndDrvInfo._mBase = DETECT; } @@ -182,7 +182,7 @@ static uint16 xdeco(const char *str) { static Choice *_cho; static int _hlp; -void CGEEngine::SNSelect() { +void CGEEngine::snSelect() { inf(_text->getText(_hlp)); _talk->gotoxy(_talk->_x, FONT_HIG / 2); (new Vmenu(this, _cho, SCR_WID / 2, _talk->_y + _talk->_h + TEXT_VM + FONT_HIG))->setName(_text->getText(MENU_TEXT)); diff --git a/engines/cge/console.h b/engines/cge/console.h index 7f265202ea7..25a1a4fae32 100644 --- a/engines/cge/console.h +++ b/engines/cge/console.h @@ -32,7 +32,7 @@ class CGEEngine; class CGEConsole : public GUI::Debugger { public: CGEConsole(CGEEngine *vm); - virtual ~CGEConsole(void); + virtual ~CGEConsole(); private: CGEEngine *_vm; diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp index ddb4861f036..93342f77da1 100644 --- a/engines/cge/ems.cpp +++ b/engines/cge/ems.cpp @@ -82,7 +82,7 @@ Emm::Emm(long size): _han(-1), _top(0), _lim(0), _list(NULL) { } -Emm::~Emm(void) { +Emm::~Emm() { /* FIXME Release(); if (Han >= 0) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index accd6fb4ab2..e904b710baf 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -162,17 +162,17 @@ MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold( } -MOUSE::~MOUSE(void) { +MOUSE::~MOUSE() { Off(); } -//void MOUSE::SetFun (void) +//void MOUSE::SetFun() //{ //} -void MOUSE::On(void) { +void MOUSE::On() { if (_seqPtr && Exist) { _active = true; step(0); @@ -181,7 +181,7 @@ void MOUSE::On(void) { } -void MOUSE::Off(void) { +void MOUSE::Off() { if (_seqPtr == 0) { if (Exist) { _active = false; @@ -261,7 +261,7 @@ void EventManager::poll() { } } -void EventManager::handleEvents(void) { +void EventManager::handleEvents() { while (EvtTail != EvtHead) { CGEEvent e = Evt[EvtTail]; if (e._msk) { diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 30b5f3186bb..8464d020e57 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -138,10 +138,10 @@ char *forceExt(char *buf, const char *nam, const char *ext) { static unsigned Seed = 0xA5; -unsigned FastRand(void) { +unsigned fastRand() { return Seed = 257 * Seed + 817; } -unsigned FastRand(unsigned s) { +unsigned fastRand(unsigned s) { return Seed = 257 * s + 817; } @@ -149,12 +149,12 @@ uint16 RCrypt(void *buf, uint16 siz, uint16 seed) { if (buf && siz) { byte *b = static_cast(buf); byte *q = b + (siz - 1); - seed = FastRand(seed); + seed = fastRand(seed); *b++ ^= seed; while (buf < q) - *b++ ^= FastRand(); + *b++ ^= fastRand(); if (buf == q) - *b ^= (seed = FastRand()); + *b ^= (seed = fastRand()); } return seed; } @@ -225,7 +225,7 @@ IoHand::IoHand(const char *name, IOMODE mode, CRYPT *crpt) _file->open(name); } -IoHand::~IoHand(void) { +IoHand::~IoHand() { _file->close(); delete _file; } @@ -258,7 +258,7 @@ uint16 IoHand::write(void *buf, uint16 len) { */ } -long IoHand::mark(void) { +long IoHand::mark() { return _file->pos(); } @@ -267,7 +267,7 @@ long IoHand::seek(long pos) { return _file->pos(); } -long IoHand::size(void) { +long IoHand::size() { return _file->size(); } @@ -344,7 +344,7 @@ int takeEnum(const char **tab, const char *txt) { return -1; } -long timer(void) { +long timer() { /* asm mov ax,0x40 asm mov es,ax diff --git a/engines/cge/general.h b/engines/cge/general.h index 95660ad4dfa..7cf3ec3e419 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -105,7 +105,7 @@ protected: static void newTimer(...); public: Engine_(uint16 tdiv); - ~Engine_(void); + ~Engine_(); }; @@ -138,7 +138,7 @@ class Ems { public: Ems(); void *operator & () const; - uint16 size(void); + uint16 size(); }; @@ -200,7 +200,7 @@ public: long mark(); long size(); long seek(long pos); - //timeb Time (void); + //timeb Time (); // void SetTime (timeb t); }; @@ -226,7 +226,7 @@ void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, c const char *progName(const char *ext = NULL); char *mergeExt(char *buf, const char *nam, const char *ext); char *forceExt(char *buf, const char *nam, const char *ext); -unsigned fastRand(void); +unsigned fastRand(); unsigned fastRand(unsigned s); uint16 rCrypt(void *buf, uint16 siz, uint16 seed); uint16 atow(const char *a); @@ -234,7 +234,7 @@ uint16 xtow(const char *x); char *wtom(uint16 val, char *str, int radix, int len); char *dwtom(uint32 val, char * str, int radix, int len); int takeEnum(const char **tab, const char *txt); -long timer(void); +long timer(); int new_random(int range); } // End of namespace CGE diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index b7c4b8ca831..d4a5212552f 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -132,7 +132,7 @@ void Mixer::tick() { } -void Mixer::update(void) { +void Mixer::update() { _led[0]->step(_sndDrvInfo.Vol4._ml); _led[1]->step(_sndDrvInfo.Vol4._dl); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 4c1b8d4c2f4..683568e1a81 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -44,14 +44,6 @@ static void _disable() { warning("STUB: _disable"); } -int _maxCave = 0; - -bool _flag[4]; -bool _dark = false; -bool _game = false; -int _now = 1; -int _lev = -1; - extern Sprite *_pocLight; //------------------------------------------------------------------------- @@ -61,7 +53,7 @@ extern Sprite *_pocLight; //------------------------------------------------------------------------- extern Sprite *_pocket[]; -static void SNGame(Sprite *spr, int num) { +void CGEEngine::snGame(Sprite *spr, int num) { switch (num) { case 1 : { #define STAGES 8 @@ -270,18 +262,18 @@ static void SNGame(Sprite *spr, int num) { } -void ExpandSprite(Sprite *spr) { +void CGEEngine::expandSprite(Sprite *spr) { if (spr) _vga->_showQ->insert(_vga->_spareQ->remove(spr)); } -void ContractSprite(Sprite *spr) { +void CGEEngine::contractSprite(Sprite *spr) { if (spr) _vga->_spareQ->append(_vga->_showQ->remove(spr)); } -int findPocket(Sprite *spr) { +int CGEEngine::findPocket(Sprite *spr) { for (int i = 0; i < POCKET_NX; i++) if (_pocket[i] == spr) return i; @@ -304,8 +296,7 @@ void CGEEngine::selectPocket(int n) { _pocLight->gotoxy(POCKET_X + _pocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY); } - -void pocFul() { +void CGEEngine::pocFul() { _hero->park(); SNPOST(SNWAIT, -1, -1, _hero); SNPOST(SNSEQ, -1, POC_FUL, _hero); @@ -314,13 +305,11 @@ void pocFul() { SNPOST(SNSAY, 1, POC_FUL_TEXT, _hero); } - -void Hide1(Sprite *spr) { +void CGEEngine::hide1(Sprite *spr) { SNPOST_(SNGHOST, -1, 0, spr->ghost()); } - -void SNGhost(Bitmap *bmp) { +void CGEEngine::snGhost(Bitmap *bmp) { // TODO : Get x and y from M but not using segment / offset //bmp->Hide(FP_OFF(bmp->_m), FP_SEG(bmp->_m)); bmp->_m = NULL; @@ -328,8 +317,7 @@ void SNGhost(Bitmap *bmp) { warning("STUB: SNGhost"); } - -void feedSnail(Sprite *spr, SNLIST snq) { +void CGEEngine::feedSnail(Sprite *spr, SNLIST snq) { if (spr) if (spr->active()) { uint8 ptr = (snq == TAKE) ? spr->_takePtr : spr->_nearPtr; @@ -402,7 +390,6 @@ void feedSnail(Sprite *spr, SNLIST snq) { } } - const char *Snail::_comTxt[] = { "LABEL", "PAUSE", "WAIT", "LEVEL", "HIDE", "SAY", "INF", "TIME", "CAVE", "KILL", @@ -424,13 +411,11 @@ Snail::Snail(CGEEngine *vm, bool turbo) _head(0), _tail(0), _snList(farnew(Com, 256)), _vm(vm) { } - Snail::~Snail() { if (_snList) free(_snList); } - void Snail::addCom(SNCOM com, int ref, int val, void *ptr) { _disable(); Com *snc = &_snList[_head++]; @@ -446,7 +431,6 @@ void Snail::addCom(SNCOM com, int ref, int val, void *ptr) { _enable(); } - void Snail::insCom(SNCOM com, int ref, int val, void *ptr) { Com *snc; @@ -469,36 +453,32 @@ void Snail::insCom(SNCOM com, int ref, int val, void *ptr) { _enable(); } - -static void SNNNext(Sprite *sprel, int p) { +void CGEEngine::snNNext(Sprite *sprel, int p) { if (sprel) if (sprel->_nearPtr != NO_PTR) sprel->_nearPtr = p; } - -static void SNTNext(Sprite *sprel, int p) { +void CGEEngine::snTNext(Sprite *sprel, int p) { if (sprel) if (sprel->_takePtr != NO_PTR) sprel->_takePtr = p; } - -static void SNRNNext(Sprite *sprel, int p) { +void CGEEngine::snRNNext(Sprite *sprel, int p) { if (sprel) if (sprel->_nearPtr != NO_PTR) sprel->_nearPtr += p; } -static void SNRTNext(Sprite *sprel, int p) { +void CGEEngine::snRTNext(Sprite *sprel, int p) { if (sprel) if (sprel->_takePtr != NO_PTR) sprel->_takePtr += p; } - -static void SNZTrim(Sprite *spr) { +void CGEEngine::snZTrim(Sprite *spr) { if (spr) if (spr->active()) { bool en = _heart->_enable; @@ -514,8 +494,7 @@ static void SNZTrim(Sprite *spr) { } } - -static void SNHide(Sprite *spr, int val) { +void CGEEngine::snHide(Sprite *spr, int val) { if (spr) { spr->_flags._hide = (val >= 0) ? (val != 0) : (!spr->_flags._hide); if (spr->_flags._shad) @@ -523,20 +502,17 @@ static void SNHide(Sprite *spr, int val) { } } - -static void SNRmNear(Sprite *spr) { +void CGEEngine::snRmNear(Sprite *spr) { if (spr) spr->_nearPtr = NO_PTR; } - -static void SNRmTake(Sprite *spr) { +void CGEEngine::snRmTake(Sprite *spr) { if (spr) spr->_takePtr = NO_PTR; } - -void SNSeq(Sprite *spr, int val) { +void CGEEngine::snSeq(Sprite *spr, int val) { if (spr) { if (spr == _hero && val == 0) _hero->park(); @@ -545,14 +521,12 @@ void SNSeq(Sprite *spr, int val) { } } - -void SNRSeq(Sprite *spr, int val) { +void CGEEngine::snRSeq(Sprite *spr, int val) { if (spr) - SNSeq(spr, spr->_seqPtr + val); + snSeq(spr, spr->_seqPtr + val); } - -void SNSend(Sprite *spr, int val) { +void CGEEngine::snSend(Sprite *spr, int val) { if (spr) { int was = spr->_cave; bool was1 = (was == 0 || was == _now); @@ -565,8 +539,8 @@ void SNSend(Sprite *spr, int val) { if (n >= 0) _pocket[n] = NULL; } - Hide1(spr); - ContractSprite(spr); + hide1(spr); + contractSprite(spr); spr->_flags._slav = false; } else { if (spr->_ref % 1000 == 0) @@ -574,7 +548,7 @@ void SNSend(Sprite *spr, int val) { if (spr->_flags._back) spr->backShow(true); else - ExpandSprite(spr); + expandSprite(spr); Bitmap::_pal = NULL; } } @@ -582,7 +556,7 @@ void SNSend(Sprite *spr, int val) { } -void SNSwap(Sprite *spr, int xref) { +void CGEEngine::snSwap(Sprite *spr, int xref) { Sprite *xspr = locate(xref); if (spr && xspr) { int was = spr->_cave; @@ -603,28 +577,28 @@ void SNSwap(Sprite *spr, int xref) { } if (xwas1 != was1) { if (was1) { - Hide1(spr); - ContractSprite(spr); + hide1(spr); + contractSprite(spr); } else - ExpandSprite(spr); + expandSprite(spr); if (xwas1) { - Hide1(xspr); - ContractSprite(xspr); + hide1(xspr); + contractSprite(xspr); } else - ExpandSprite(xspr); + expandSprite(xspr); } } } -void SNCover(Sprite *spr, int xref) { +void CGEEngine::snCover(Sprite *spr, int xref) { Sprite *xspr = locate(xref); if (spr && xspr) { spr->_flags._hide = true; xspr->_z = spr->_z; xspr->_cave = spr->_cave; xspr->gotoxy(spr->_x, spr->_y); - ExpandSprite(xspr); + expandSprite(xspr); if ((xspr->_flags._shad = spr->_flags._shad) == 1) { _vga->_showQ->insert(_vga->_showQ->remove(spr->_prev), xspr); spr->_flags._shad = false; @@ -634,7 +608,7 @@ void SNCover(Sprite *spr, int xref) { } -void SNUncover(Sprite *spr, Sprite *xspr) { +void CGEEngine::snUncover(Sprite *spr, Sprite *xspr) { if (spr && xspr) { spr->_flags._hide = false; spr->_cave = xspr->_cave; @@ -644,75 +618,71 @@ void SNUncover(Sprite *spr, Sprite *xspr) { xspr->_flags._shad = false; } spr->_z = xspr->_z; - SNSend(xspr, -1); + snSend(xspr, -1); if (spr->_time == 0) spr->_time++; } } -void SNSetX0(int cav, int x0) { +void CGEEngine::snSetX0(int cav, int x0) { _heroXY[cav - 1]._x = x0; } - -void SNSetY0(int cav, int y0) { +void CGEEngine::snSetY0(int cav, int y0) { _heroXY[cav - 1]._y = y0; } - -void SNSetXY(Sprite *spr, uint16 xy) { +void CGEEngine::snSetXY(Sprite *spr, uint16 xy) { if (spr) spr->gotoxy(xy % SCR_WID, xy / SCR_WID); } - -void SNRelX(Sprite *spr, int x) { +void CGEEngine::snRelX(Sprite *spr, int x) { if (spr && _hero) spr->gotoxy(_hero->_x + x, spr->_y); } - -void SNRelY(Sprite *spr, int y) { +void CGEEngine::snRelY(Sprite *spr, int y) { if (spr && _hero) spr->gotoxy(spr->_x, _hero->_y + y); } -void SNRelZ(Sprite *spr, int z) { +void CGEEngine::snRelZ(Sprite *spr, int z) { if (spr && _hero) { spr->_z = _hero->_z + z; - SNZTrim(spr); + snZTrim(spr); } } -void SNSetX(Sprite *spr, int x) { +void CGEEngine::snSetX(Sprite *spr, int x) { if (spr) spr->gotoxy(x, spr->_y); } -void SNSetY(Sprite *spr, int y) { +void CGEEngine::snSetY(Sprite *spr, int y) { if (spr) spr->gotoxy(spr->_x, y); } -void SNSetZ(Sprite *spr, int z) { +void CGEEngine::snSetZ(Sprite *spr, int z) { if (spr) { spr->_z = z; //SNPOST_(SNZTRIM, -1, 0, spr); - SNZTrim(spr); + snZTrim(spr); } } -void SNSlave(Sprite *spr, int ref) { +void CGEEngine::snSlave(Sprite *spr, int ref) { Sprite *slv = locate(ref); if (spr && slv) { if (spr->active()) { - SNSend(slv, spr->_cave); + snSend(slv, spr->_cave); slv->_flags._slav = true; slv->_z = spr->_z; _vga->_showQ->insert(_vga->_showQ->remove(slv), spr->_next); @@ -721,19 +691,17 @@ void SNSlave(Sprite *spr, int ref) { } -void SNTrans(Sprite *spr, int trans) { +void CGEEngine::snTrans(Sprite *spr, int trans) { if (spr) spr->_flags._tran = (trans < 0) ? !spr->_flags._tran : (trans != 0); } - -void SNPort(Sprite *spr, int port) { +void CGEEngine::snPort(Sprite *spr, int port) { if (spr) spr->_flags._port = (port < 0) ? !spr->_flags._port : (port != 0); } - -void SNKill(Sprite *spr) { +void CGEEngine::snKill(Sprite *spr) { if (spr) { if (spr->_flags._kept) { int n = findPocket(spr); @@ -741,7 +709,7 @@ void SNKill(Sprite *spr) { _pocket[n] = NULL; } Sprite *nx = spr->_next; - Hide1(spr); + hide1(spr); _vga->_showQ->remove(spr); EventManager::ClrEvt(spr); if (spr->_flags._kill) @@ -752,13 +720,13 @@ void SNKill(Sprite *spr) { } if (nx) { if (nx->_flags._slav) - SNKill(nx); + snKill(nx); } } } -static void SNSound(Sprite *spr, int wav, int cnt) { +void CGEEngine::snSound(Sprite *spr, int wav, int cnt) { if (_sndDrvInfo._dDev) { if (wav == -1) _sound.stop(); @@ -768,10 +736,10 @@ static void SNSound(Sprite *spr, int wav, int cnt) { } -void CGEEngine::SNKeep(Sprite *spr, int stp) { +void CGEEngine::snKeep(Sprite *spr, int stp) { selectPocket(-1); if (spr && ! spr->_flags._kept && _pocket[_pocPtr] == NULL) { - SNSound(spr, 3, 1); + snSound(spr, 3, 1); _pocket[_pocPtr] = spr; spr->_cave = 0; spr->_flags._kept = true; @@ -784,7 +752,7 @@ void CGEEngine::SNKeep(Sprite *spr, int stp) { } -void CGEEngine::SNGive(Sprite *spr, int stp) { +void CGEEngine::snGive(Sprite *spr, int stp) { if (spr) { int p = findPocket(spr); if (p >= 0) { @@ -799,7 +767,7 @@ void CGEEngine::SNGive(Sprite *spr, int stp) { } -static void SNBackPt(Sprite *spr, int stp) { +void CGEEngine::snBackPt(Sprite *spr, int stp) { if (spr) { if (stp >= 0) spr->step(stp); @@ -807,13 +775,7 @@ static void SNBackPt(Sprite *spr, int stp) { } } - -static void SNLevel(Sprite *spr, int lev) { -#ifdef DEMO - static int maxcav[] = { CAVE_MAX }; -#else - static int maxcav[] = { 1, 8, 16, 23, 24 }; -#endif +void CGEEngine::snLevel(Sprite *spr, int lev) { while (_lev < lev) { _lev++; spr = _vga->_spareQ->locate(100 + _lev); @@ -822,24 +784,22 @@ static void SNLevel(Sprite *spr, int lev) { spr->_cave = 0; } } - _maxCave = maxcav[_lev]; + _maxCave = _maxCaveArr[_lev]; if (spr) spr->_flags._hide = false; } -static void SNFlag(int fn, bool v) { +void CGEEngine::snFlag(int fn, bool v) { _flag[fn] = v; } - -static void SNSetRef(Sprite *spr, int nr) { +void CGEEngine::snSetRef(Sprite *spr, int nr) { if (spr) spr->_ref = nr; } - -void SNFlash(bool on) { +void CGEEngine::snFlash(bool on) { if (on) { Dac *pal = farnew(Dac, PAL_CNT); if (pal) { @@ -861,7 +821,7 @@ void SNFlash(bool on) { } -static void SNLight(bool in) { +void CGEEngine::snLight(bool in) { if (in) _vga->sunrise(Vga::_sysPal); else @@ -869,13 +829,11 @@ static void SNLight(bool in) { _dark = ! in; } - -static void SNBarrier(int cav, int bar, bool horz) { +void CGEEngine::snBarrier(int cav, int bar, bool horz) { ((uint8 *)(_barriers + ((cav > 0) ? cav : _now)))[horz] = bar; } - -static void SNWalk(Sprite *spr, int x, int y) { +void CGEEngine::snWalk(Sprite *spr, int x, int y) { if (_hero) { if (spr && y < 0) _hero->findWay(spr); @@ -884,14 +842,12 @@ static void SNWalk(Sprite *spr, int x, int y) { } } - -static void SNReach(Sprite *spr, int mode) { +void CGEEngine::snReach(Sprite *spr, int mode) { if (_hero) _hero->reach(spr, mode); } - -static void SNMouse(bool on) { +void CGEEngine::snMouse(bool on) { if (on) _mouse->On(); else @@ -945,10 +901,10 @@ void Snail::runCom() { } break; case SNLEVEL : - SNLevel(sprel, snc->_val); + _vm->snLevel(sprel, snc->_val); break; case SNHIDE : - SNHide(sprel, snc->_val); + _vm->snHide(sprel, snc->_val); break; case SNSAY : if (sprel && _talkEnable) { @@ -976,125 +932,125 @@ void Snail::runCom() { warning("Problematic call of SwitchCave in SNAIL::runCom"); break; case SNKILL : - SNKill(sprel); + _vm->snKill(sprel); break; case SNSEQ : - SNSeq(sprel, snc->_val); + _vm->snSeq(sprel, snc->_val); break; case SNRSEQ : - SNRSeq(sprel, snc->_val); + _vm->snRSeq(sprel, snc->_val); break; case SNSEND : - SNSend(sprel, snc->_val); + _vm->snSend(sprel, snc->_val); break; case SNSWAP : - SNSwap(sprel, snc->_val); + _vm->snSwap(sprel, snc->_val); break; case SNCOVER : - SNCover(sprel, snc->_val); + _vm->snCover(sprel, snc->_val); break; case SNUNCOVER : - SNUncover(sprel, (snc->_val >= 0) ? locate(snc->_val) : ((Sprite *) snc->_ptr)); + _vm->snUncover(sprel, (snc->_val >= 0) ? locate(snc->_val) : ((Sprite *) snc->_ptr)); break; case SNKEEP : - _vm->SNKeep(sprel, snc->_val); + _vm->snKeep(sprel, snc->_val); break; case SNGIVE : - _vm->SNGive(sprel, snc->_val); + _vm->snGive(sprel, snc->_val); break; case SNGAME : - SNGame(sprel, snc->_val); + _vm->snGame(sprel, snc->_val); break; case SNSETX0 : - SNSetX0(snc->_ref, snc->_val); + _vm->snSetX0(snc->_ref, snc->_val); break; case SNSETY0 : - SNSetY0(snc->_ref, snc->_val); + _vm->snSetY0(snc->_ref, snc->_val); break; case SNSETXY : - SNSetXY(sprel, snc->_val); + _vm->snSetXY(sprel, snc->_val); break; case SNRELX : - SNRelX(sprel, snc->_val); + _vm->snRelX(sprel, snc->_val); break; case SNRELY : - SNRelY(sprel, snc->_val); + _vm->snRelY(sprel, snc->_val); break; case SNRELZ : - SNRelZ(sprel, snc->_val); + _vm->snRelZ(sprel, snc->_val); break; case SNSETX : - SNSetX(sprel, snc->_val); + _vm->snSetX(sprel, snc->_val); break; case SNSETY : - SNSetY(sprel, snc->_val); + _vm->snSetY(sprel, snc->_val); break; case SNSETZ : - SNSetZ(sprel, snc->_val); + _vm->snSetZ(sprel, snc->_val); break; case SNSLAVE : - SNSlave(sprel, snc->_val); + _vm->snSlave(sprel, snc->_val); break; case SNTRANS : - SNTrans(sprel, snc->_val); + _vm->snTrans(sprel, snc->_val); break; case SNPORT : - SNPort(sprel, snc->_val); + _vm->snPort(sprel, snc->_val); break; case SNNEXT : case SNIF : case SNTALK : break; case SNMOUSE : - SNMouse(snc->_val != 0); + _vm->snMouse(snc->_val != 0); break; case SNNNEXT : - SNNNext(sprel, snc->_val); + _vm->snNNext(sprel, snc->_val); break; case SNTNEXT : - SNTNext(sprel, snc->_val); + _vm->snTNext(sprel, snc->_val); break; case SNRNNEXT : - SNRNNext(sprel, snc->_val); + _vm->snRNNext(sprel, snc->_val); break; case SNRTNEXT : - SNRTNext(sprel, snc->_val); + _vm->snRTNext(sprel, snc->_val); break; case SNRMNEAR : - SNRmNear(sprel); + _vm->snRmNear(sprel); break; case SNRMTAKE : - SNRmTake(sprel); + _vm->snRmTake(sprel); break; case SNFLAG : - SNFlag(snc->_ref & 3, snc->_val != 0); + _vm->snFlag(snc->_ref & 3, snc->_val != 0); break; case SNSETREF : - SNSetRef(sprel, snc->_val); + _vm->snSetRef(sprel, snc->_val); break; case SNBACKPT : - SNBackPt(sprel, snc->_val); + _vm->snBackPt(sprel, snc->_val); break; case SNFLASH : - SNFlash(snc->_val != 0); + _vm->snFlash(snc->_val != 0); break; case SNLIGHT : - SNLight(snc->_val != 0); + _vm->snLight(snc->_val != 0); break; case SNSETHB : - SNBarrier(snc->_ref, snc->_val, true); + _vm->snBarrier(snc->_ref, snc->_val, true); break; case SNSETVB : - SNBarrier(snc->_ref, snc->_val, false); + _vm->snBarrier(snc->_ref, snc->_val, false); break; case SNWALK : - SNWalk(sprel, snc->_ref, snc->_val); + _vm->snWalk(sprel, snc->_ref, snc->_val); break; case SNREACH : - SNReach(sprel, snc->_val); + _vm->snReach(sprel, snc->_val); break; case SNSOUND : - SNSound(sprel, snc->_val, count); + _vm->snSound(sprel, snc->_val, count); count = 1; break; case SNCOUNT : @@ -1109,10 +1065,10 @@ void Snail::runCom() { sprel->step(); break; case SNZTRIM : - SNZTrim(sprel); + _vm->snZTrim(sprel); break; case SNGHOST : - SNGhost((Bitmap *) snc->_ptr); + _vm->snGhost((Bitmap *) snc->_ptr); break; default : warning("Unhandled snc->_com in SNMouse(bool)"); diff --git a/engines/cge/snail.h b/engines/cge/snail.h index bd874a35b47..888fae6ce9e 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -70,8 +70,6 @@ enum SNCOM { SNZTRIM, SNGHOST }; -enum SNLIST { NEAR, TAKE }; - class Snail { public: struct Com { @@ -99,15 +97,8 @@ private: }; -void pocFul(); - - -extern bool _flag[4]; -extern bool _game; extern bool _dark; -extern int _now; extern int _lev; -extern int _maxCave; extern Bar _barriers[]; extern struct Hxy { int _x; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 6c20a78caee..36ac0601117 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -63,7 +63,7 @@ bool SpeedTest = false; Seq _seq1[] = { { 0, 0, 0, 0, 0 } }; Seq _seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; -extern "C" void SNDMIDIPlay(void); +extern "C" void SNDMIDIPlay(); /* static void Video() { @@ -87,7 +87,7 @@ static void Video() { */ -uint16 *SaveScreen(void) { +uint16 *SaveScreen() { /* uint16 cxy, cur, siz, * scr = NULL, * sav; @@ -201,7 +201,7 @@ Sprite *locate(int ref) { } -Heart::Heart(void) +Heart::Heart() : Engine_(TMR_DIV) { _enable = false; _xTimer = NULL; @@ -427,7 +427,7 @@ bool Sprite::works(Sprite *spr) { if (c != NULL) { c += spr->_takePtr; if (c->_ref == _ref) - if (c->_com != SNLABEL || (c->_val == 0 || c->_val == _now)) + if (c->_com != SNLABEL || (c->_val == 0 || c->_val == _vm->_now)) return true; } } @@ -1136,7 +1136,7 @@ void Vga::setColors(Dac *tab, int lum) { } -void Vga::setColors(void) { +void Vga::setColors() { memset(_newColors, 0, PAL_SIZ); updateColors(); } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index d5a87e973df..b0cba4dcc09 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -209,7 +209,7 @@ public: return _ext != NULL; } Sprite(CGEEngine *vm, BMP_PTR *shp); - virtual ~Sprite(void); + virtual ~Sprite(); BMP_PTR shp(); BMP_PTR *setShapeList(BMP_PTR *shp); void moveShapes(uint8 *buf); @@ -288,7 +288,7 @@ public: static Dac *_sysPal; Vga(int mode); - ~Vga(void); + ~Vga(); static void init(); static void deinit(); @@ -340,7 +340,6 @@ uint8 closest(CBLK *pal, CBLK x) { #undef f } -//static void Video (void); uint16 *saveScreen(); void restoreScreen(uint16 * &sav); Sprite *spriteAt(int x, int y); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 49dbbbdab66..8fef6307b14 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -119,7 +119,7 @@ Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y) } -Vmenu::~Vmenu(void) { +Vmenu::~Vmenu() { _addr = NULL; } From affaa1f4d6cf5f27f654029133b1aec7b9eca4b5 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 7 Jul 2011 08:11:29 +0200 Subject: [PATCH 088/276] CGE: Some cleanup: Move some static functions to CGEEngine, remove parameters to GetText, rename members of SavTab --- engines/cge/cge.cpp | 102 ++++++++++++++++++------------------ engines/cge/cge.h | 23 +++++++-- engines/cge/cge_main.cpp | 109 +++++++++++++++++---------------------- engines/cge/general.cpp | 9 ---- engines/cge/gettext.cpp | 7 ++- engines/cge/gettext.h | 3 +- engines/cge/startup.cpp | 107 +++++++++++++++++++++++--------------- 7 files changed, 187 insertions(+), 173 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 067b9eb6e98..b953f2f5b02 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -117,56 +117,56 @@ void CGEEngine::setup() { _volume[0] = 0; _volume[1] = 0; - _savTab[0].Ptr = &_now; - _savTab[0].Len = sizeof(_now); - _savTab[0].Flg = 1; - _savTab[1].Ptr = &_oldLev; - _savTab[1].Len = sizeof(_oldLev); - _savTab[1].Flg = 1; - _savTab[2].Ptr = &_demoText; - _savTab[2].Len = sizeof(_demoText); - _savTab[2].Flg = 1; - _savTab[3].Ptr = &_game; - _savTab[3].Len = sizeof(_game); - _savTab[3].Flg = 1; - _savTab[4].Ptr = &_game; - _savTab[4].Len = sizeof(_game); - _savTab[4].Flg = 1; - _savTab[5].Ptr = &_game; - _savTab[5].Len = sizeof(_game); - _savTab[5].Flg = 1; - _savTab[6].Ptr = &_game; - _savTab[6].Len = sizeof(_game); - _savTab[6].Flg = 1; - _savTab[7].Ptr = &_game; - _savTab[7].Len = sizeof(_game); - _savTab[7].Flg = 1; - _savTab[8].Ptr = &_vga->_mono; - _savTab[8].Len = sizeof(_vga->_mono); - _savTab[8].Flg = 0; - _savTab[9].Ptr = &_music; - _savTab[9].Len = sizeof(_music); - _savTab[9].Flg = 1; - _savTab[10].Ptr = _volume; - _savTab[10].Len = sizeof(_volume); - _savTab[10].Flg = 1; - _savTab[11].Ptr = _flag; - _savTab[11].Len = sizeof(_flag); - _savTab[11].Flg = 1; - _savTab[12].Ptr = _heroXY; -// _savTab[12].Len = sizeof(_heroXY); FIXME: illegal sizeof - _savTab[12].Len = 0; - _savTab[12].Flg = 1; - _savTab[13].Ptr = _barriers; -// _savTab[13].Len = sizeof(_barriers); FIXME: illegal sizeof - _savTab[13].Len = 0; - _savTab[13].Flg = 1; - _savTab[14].Ptr = _pocref; - _savTab[14].Len = sizeof(_pocref); - _savTab[14].Flg = 1; - _savTab[15].Ptr = NULL; - _savTab[15].Len = 0; - _savTab[15].Flg = 0; + _savTab[0]._ptr = &_now; + _savTab[0]._len = sizeof(_now); + _savTab[0]._flag = true; + _savTab[1]._ptr = &_oldLev; + _savTab[1]._len = sizeof(_oldLev); + _savTab[1]._flag = true; + _savTab[2]._ptr = &_demoText; + _savTab[2]._len = sizeof(_demoText); + _savTab[2]._flag = true; + _savTab[3]._ptr = &_game; + _savTab[3]._len = sizeof(_game); + _savTab[3]._flag = true; + _savTab[4]._ptr = &_game; + _savTab[4]._len = sizeof(_game); + _savTab[4]._flag = true; + _savTab[5]._ptr = &_game; + _savTab[5]._len = sizeof(_game); + _savTab[5]._flag = true; + _savTab[6]._ptr = &_game; + _savTab[6]._len = sizeof(_game); + _savTab[6]._flag = true; + _savTab[7]._ptr = &_game; + _savTab[7]._len = sizeof(_game); + _savTab[7]._flag = true; + _savTab[8]._ptr = &_vga->_mono; + _savTab[8]._len = sizeof(_vga->_mono); + _savTab[8]._flag = false; + _savTab[9]._ptr = &_music; + _savTab[9]._len = sizeof(_music); + _savTab[9]._flag = true; + _savTab[10]._ptr = _volume; + _savTab[10]._len = sizeof(_volume); + _savTab[10]._flag = true; + _savTab[11]._ptr = _flag; + _savTab[11]._len = sizeof(_flag); + _savTab[11]._flag = true; + _savTab[12]._ptr = _heroXY; +// _savTab[12]._len = sizeof(_heroXY); FIXME: illegal sizeof + _savTab[12]._len = 0; + _savTab[12]._flag = true; + _savTab[13]._ptr = _barriers; +// _savTab[13]._len = sizeof(_barriers); FIXME: illegal sizeof + _savTab[13]._len = 0; + _savTab[13]._flag = true; + _savTab[14]._ptr = _pocref; + _savTab[14]._len = sizeof(_pocref); + _savTab[14]._flag = true; + _savTab[15]._ptr = NULL; + _savTab[15]._len = 0; + _savTab[15]._flag = false; if (_isDemo) { _maxCaveArr[0] = CAVE_MAX; @@ -187,6 +187,8 @@ void CGEEngine::setup() { _now = 1; _lev = -1; + for (int i = 0; i < 4; i++) + _flag[i] = false; } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index e4b8ef86c17..4f6b452850d 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -49,9 +49,9 @@ enum SNLIST { NEAR, TAKE }; #define POCKET_NX 8 struct SavTab { - void *Ptr; - int Len; - uint8 Flg; + void *_ptr; + int32 _len; + bool _flag; }; class CGEEngine : public Engine { @@ -124,7 +124,7 @@ public: void setIRQ(); void setDMA(); void mainLoop(); - void SaveGame(XFile &file); + void saveGame(XFile &file); void switchMusic(); void selectPocket(int n); void expandSprite(Sprite *spr); @@ -135,6 +135,21 @@ public: void hide1(Sprite *spr); void loadMapping(); void saveMapping(); + void saveSound(); + void heroCover(int cvr); + void trouble(int seq, int txt); + void offUse(); + void tooFar(); + void noWay(); + void loadHeroXY(); + void keyClick(); + void switchColorMode(); + void killSprite(); + void pushSprite(); + void pullSprite(); + void sayDebug(); + void nextStep(); + void switchDebug(); void snBackPt(Sprite *spr, int stp); void snBarrier(int cav, int bar, bool horz); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 456a11092e9..e7ca76a98fc 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -247,14 +247,14 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { } -static void SaveSound() { +void CGEEngine::saveSound() { CFile cfg(usrPath(progName(CFG_EXT)), WRI); if (!cfg._error) cfg.write(&_sndDrvInfo, sizeof(_sndDrvInfo) - sizeof(_sndDrvInfo.Vol2)); } -void CGEEngine::SaveGame(XFile &file) { +void CGEEngine::saveGame(XFile &file) { SavTab *st; Sprite *spr; int i; @@ -267,10 +267,10 @@ void CGEEngine::SaveGame(XFile &file) { _volume[0] = _sndDrvInfo.Vol2._d; _volume[1] = _sndDrvInfo.Vol2._m; - for (st = _savTab; st->Ptr; st++) { + for (st = _savTab; st->_ptr; st++) { if (file._error) error("Bad SVG"); - file.write((uint8 *) st->Ptr, st->Len); + file.write((uint8 *) st->_ptr, st->_len); } file.write((uint8 *) & (i = SVGCHKSUM), sizeof(i)); @@ -281,13 +281,11 @@ void CGEEngine::SaveGame(XFile &file) { file.write((uint8 *)spr, sizeof(*spr)); } - -static void HeroCover(int cvr) { +void CGEEngine::heroCover(int cvr) { SNPOST(SNCOVER, 1, cvr, NULL); } - -static void trouble(int seq, int txt) { +void CGEEngine::trouble(int seq, int txt) { _hero->park(); SNPOST(SNWAIT, -1, -1, _hero); SNPOST(SNSEQ, -1, seq, _hero); @@ -296,31 +294,27 @@ static void trouble(int seq, int txt) { SNPOST(SNSAY, 1, txt, _hero); } - -static void offUse() { +void CGEEngine::offUse() { trouble(OFF_USE, OFF_USE_TEXT + new_random(_offUseCount)); } - -static void tooFar() { +void CGEEngine::tooFar() { trouble(TOO_FAR, TOO_FAR_TEXT); } - // Used in stubbed function, do not remove! -static void noWay() { +void CGEEngine::noWay() { trouble(NO_WAY, NO_WAY_TEXT); } -static void loadHeroXY() { +void CGEEngine::loadHeroXY() { INI_FILE cf(progName(".HXY")); memset(_heroXY, 0, sizeof(_heroXY)); if (!cf._error) cf.CFREAD(&_heroXY); } - void CGEEngine::loadMapping() { if (_now <= CAVE_MAX) { INI_FILE cf(progName(".TAB")); @@ -536,21 +530,19 @@ void CGEEngine::setMapBrick(int x, int z) { } } -static void SwitchColorMode(); -static void switchDebug(); -static void KillSprite(); -static void PushSprite(); -static void PullSprite(); -static void NextStep(); +//static void switchColorMode(); +//static void switchDebug(); +//static void pullSprite(); +//static void NextStep(); -static void KeyClick() { +void CGEEngine::keyClick() { SNPOST_(SNSOUND, -1, 5, NULL); } void CGEEngine::resetQSwitch() { SNPOST_(SNSEQ, 123, 0, NULL); - KeyClick(); + keyClick(); } @@ -570,7 +562,7 @@ void CGEEngine::quit() { QuitMenu[1]._text = _text->getText(NOQUIT_TEXT); (new Vmenu(this, QuitMenu, -1, -1))->setName(_text->getText(QUIT_TITLE)); SNPOST_(SNSEQ, 123, 1, NULL); - KeyClick(); + keyClick(); } } } @@ -723,9 +715,9 @@ void CGEEngine::xCave() { void CGEEngine::qGame() { caveDown(); _oldLev = _lev; - SaveSound(); + saveSound(); CFile file = CFile(usrPath(_usrFnam), WRI, RCrypt); - SaveGame(file); + saveGame(file); _vga->sunset(); _finis = true; } @@ -754,7 +746,7 @@ void CGEEngine::switchCave(int cav) { CAVE_Y + ((_now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); killText(); if (!_startupMode) - KeyClick(); + keyClick(); SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint //TODO Change the SNPOST message send to a special way to send function pointer //SNPOST(SNEXEC, 0, 0, (void *)&XCave); // switch cave @@ -776,7 +768,7 @@ void System::touch(uint16 mask, int x, int y) { if (mask & KEYB) { int pp0; - KeyClick(); + _vm->keyClick(); killText(); if (_vm->_startupMode == 1) { SNPOST(SNCLEAR, -1, 0, NULL); @@ -788,7 +780,7 @@ void System::touch(uint16 mask, int x, int y) { if (_keyboard->_key[ALT] && _keyboard->_key[CTRL]) AltCtrlDel(); else - KillSprite(); + _vm->killSprite(); break; case 'F': if (_keyboard->_key[ALT]) { @@ -800,13 +792,13 @@ void System::touch(uint16 mask, int x, int y) { } break; case PgUp: - PushSprite(); + _vm->pushSprite(); break; case PgDn: - PullSprite(); + _vm->pullSprite(); break; case '+': - NextStep(); + _vm->nextStep(); break; case '`': if (_keyboard->_key[ALT]) @@ -815,7 +807,7 @@ void System::touch(uint16 mask, int x, int y) { _vm->switchMapping(); break; case F1: - switchDebug(); + _vm->switchDebug(); break; case F3: _hero->step(TSEQ + 4); @@ -933,19 +925,19 @@ void System::tick() { killText(); if (_snail->idle()) { if (PAIN) - HeroCover(9); + _vm->heroCover(9); else if (Startup::_core >= CORE_MID) { int n = new_random(100); if (n > 96) - HeroCover(6 + (_hero->_x + _hero->_w / 2 < SCR_WID / 2)); + _vm->heroCover(6 + (_hero->_x + _hero->_w / 2 < SCR_WID / 2)); else { if (n > 90) - HeroCover(5); + _vm->heroCover(5); else { if (n > 60) - HeroCover(4); + _vm->heroCover(4); else - HeroCover(3); + _vm->heroCover(3); } } } @@ -975,9 +967,9 @@ static void SpkClose() { */ -static void SwitchColorMode() { +void CGEEngine::switchColorMode() { SNPOST_(SNSEQ, 121, _vga->_mono = !_vga->_mono, NULL); - KeyClick(); + keyClick(); _vga->setColors(Vga::_sysPal, 64); } @@ -998,7 +990,7 @@ void CGEEngine::switchMusic() { SNPOST(SNINF, -1, NOMUSIC_TEXT, NULL); else { SNPOST_(SNSEQ, 122, (_music = !_music), NULL); - KeyClick(); + keyClick(); } } if (_music) @@ -1018,7 +1010,7 @@ void CGEEngine::takeName() { if (GetText::_ptr) SNPOST_(SNKILL, -1, 0, GetText::_ptr); else { - GetText *tn = new GetText(this, _text->getText(GETNAME_PROMPT), _usrFnam, 8, KeyClick); + GetText *tn = new GetText(this, _text->getText(GETNAME_PROMPT), _usrFnam, 8); if (tn) { tn->setName(_text->getText(GETNAME_TITLE)); tn->center(); @@ -1049,16 +1041,14 @@ void CGEEngine::switchMapping() { _horzLine->_flags._hide = !_horzLine->_flags._hide; } - -static void KillSprite() { +void CGEEngine::killSprite() { _sprite->_flags._kill = true; _sprite->_flags._bDel = true; SNPOST_(SNKILL, -1, 0, _sprite); _sprite = NULL; } - -static void PushSprite() { +void CGEEngine::pushSprite() { Sprite *spr = _sprite->_prev; if (spr) { _vga->_showQ->insert(_vga->_showQ->remove(_sprite), spr); @@ -1068,8 +1058,7 @@ static void PushSprite() { SNPOST_(SNSOUND, -1, 2, NULL); } - -static void PullSprite() { +void CGEEngine::pullSprite() { bool ok = false; Sprite *spr = _sprite->_next; if (spr) { @@ -1086,12 +1075,10 @@ static void PullSprite() { SNPOST_(SNSOUND, -1, 2, NULL); } - -static void NextStep() { +void CGEEngine::nextStep() { SNPOST_(SNSTEP, 0, 0, _sprite); } - void CGEEngine::saveMapping() { { IoHand cf(progName(".TAB"), UPD); @@ -1131,7 +1118,7 @@ static char DebugText[] = " N=00000 F=000000 X=000 Y=000 FPS=0000\0S=00:00 0 #define SP_F (DebugText + 67) #define SP__ (DebugText + 70) -static void sayDebug() { +void CGEEngine::sayDebug() { if (!_debugLine->_flags._hide) { static long t = -1L; long t1 = timer(); @@ -1172,7 +1159,7 @@ static void sayDebug() { } -static void switchDebug() { +void CGEEngine::switchDebug() { _debugLine->_flags._hide = !_debugLine->_flags._hide; } @@ -1181,7 +1168,7 @@ void CGEEngine::optionTouch(int opt, uint16 mask) { switch (opt) { case 1 : if (mask & L_UP) - SwitchColorMode(); + switchColorMode(); break; case 2 : if (mask & L_UP) @@ -1224,10 +1211,10 @@ void Sprite::touch(uint16 mask, int x, int y) { if (works(ps)) { _vm->feedSnail(ps, TAKE); } else - offUse(); + _vm->offUse(); _vm->selectPocket(-1); } else - tooFar(); + _vm->tooFar(); } else { if (_flags._kept) mask |= L_UP; @@ -1245,15 +1232,15 @@ void Sprite::touch(uint16 mask, int x, int y) { } else { if (_takePtr != NO_PTR) { if (snList(TAKE)[_takePtr]._com == SNNEXT) - offUse(); + _vm->offUse(); else _vm->feedSnail(this, TAKE); } else - offUse(); + _vm->offUse(); } }/// else - tooFar(); + _vm->tooFar(); } } } @@ -1548,7 +1535,7 @@ void CGEEngine::loadUser() { loadScript(progName(INI_EXT)); _music = true; CFile file = CFile(SVG0NAME, WRI); - SaveGame(file); + saveGame(file); error("Ok [%s]", SVG0NAME); } } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 8464d020e57..6ed6884aba8 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -109,11 +109,6 @@ const char *progName(const char *ext) { } char *mergeExt(char *buf, const char *nam, const char *ext) { -// char dr[MAXDRIVE], di[MAXDIR], na[MAXFILE], ex[MAXEXT]; -// fnmerge(buf, dr, di, na, (fnsplit(nam, dr, di, na, ex) & EXTENSION) ? ex : ext); -// return buf; - warning("mergeExt"); - strcpy(buf, nam); char *dot = strrchr(buf, '.'); if (!dot) @@ -123,10 +118,6 @@ char *mergeExt(char *buf, const char *nam, const char *ext) { } char *forceExt(char *buf, const char *nam, const char *ext) { -// char dr[MAXDRIVE], di[MAXDIR], na[MAXFILE], ex[MAXEXT]; -// fnsplit(nam, dr, di, na, ex); -// fnmerge(buf, dr, di, na, ext); -// return buf; strcpy(buf, nam); char *dot = strrchr(buf, '.'); if (dot) diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 508175ccd5d..2ee6dc42eb2 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -34,9 +34,9 @@ namespace CGE { GetText *GetText::_ptr = NULL; -GetText::GetText(CGEEngine *vm, const char *info, char *text, int size, void (*click)()) +GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) : Talk(vm), _text(text), _size(min(size, GTMAX)), _len(min(_size, strlen(text))), - _cntr(GTBLINK), _click(click), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { + _cntr(GTBLINK), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { int i = 2 * TEXT_HM + _font->width(info); _ptr = this; _mode = RECT; @@ -74,8 +74,7 @@ void GetText::touch(uint16 mask, int x, int y) { char *p; if (mask & KEYB) { - if (_click) - _click(); + _vm->keyClick(); switch (x) { case Enter : _buff[_len] = '\0'; diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h index d29d11abb77..188e90c7764 100644 --- a/engines/cge/gettext.h +++ b/engines/cge/gettext.h @@ -44,11 +44,10 @@ class GetText : public Talk { uint16 _len; uint16 _cntr; Sprite *_oldKeybClient; - void (*_click)(); public: static GetText *_ptr; - GetText(CGEEngine *vm, const char *info, char *text, int size, void (*click)(void) = NULL); + GetText(CGEEngine *vm, const char *info, char *text, int size); ~GetText(); void touch(uint16 mask, int x, int y); void tick(); diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 6a06cbc537a..9210b40c775 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -57,49 +57,70 @@ bool Startup::getParms() { _summa = 0; /* - int i = _argc; - while (i > 1) - { - static char *PrmTab[] = { "NEW", "MK0SVG", "QUIET", "SB", "GUS", "MIDI", - "P", "D", "I", "M" }; - int n = takeEnum(PrmTab, strtok(_argv[--i], " =:(")); - uint16 p = xtow(strtok(NULL, " h,)")); - switch (n) - { - case 0 : if (Mode != 2) Mode = 1; break; - case 1 : Mode = 2; break; - case 2 : SNDDrvInfo.DDEV = DEV_QUIET; break; - case 3 : SNDDrvInfo.DDEV = DEV_SB; break; - case 4 : SNDDrvInfo.DDEV = DEV_GUS; break; - case 5 : SNDDrvInfo.MDEV = DEV_GM; break; - case 6 : SNDDrvInfo.DBASE = p; break; - case 7 : SNDDrvInfo.DDMA = p; break; - case 8 : SNDDrvInfo.DIRQ = p; break; - case 9 : SNDDrvInfo.MBASE = p; - SNDDrvInfo.MDEV = DEV_GM; break; - default: return false; - } - if (n >= 2) SoundOk = 2; - } - #ifdef DEMO - // protection disabled - Summa = 0; - #else - #ifdef EVA - { - union { dosdate_t d; uint32 n; } today; - _dos_getdate(&today.d); - id.disk += (id.disk < today.n); - } - #endif - #ifdef CD - Summa = 0; - #else - // disk signature checksum - Summa = ChkSum(Copr, sizeof(Ident)); - #endif - #endif - if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; + int i = _argc; + while (i > 1) { + static char *PrmTab[] = { "NEW", "MK0SVG", "QUIET", "SB", "GUS", "MIDI", "P", "D", "I", "M" }; + int n = takeEnum(PrmTab, strtok(_argv[--i], " =:(")); + uint16 p = xtow(strtok(NULL, " h,)")); + switch (n) { + case 0 : + if (Mode != 2) + Mode = 1; + break; + case 1 : + Mode = 2; + break; + case 2 : + SNDDrvInfo.DDEV = DEV_QUIET; + break; + case 3 : + SNDDrvInfo.DDEV = DEV_SB; + break; + case 4 : + SNDDrvInfo.DDEV = DEV_GUS; + break; + case 5 : + SNDDrvInfo.MDEV = DEV_GM; + break; + case 6 : + SNDDrvInfo.DBASE = p; + break; + case 7 : + SNDDrvInfo.DDMA = p; + break; + case 8 : + SNDDrvInfo.DIRQ = p; + break; + case 9 : + SNDDrvInfo.MBASE = p; + SNDDrvInfo.MDEV = DEV_GM; + break; + default: + return false; + } + + if (n >= 2) + SoundOk = 2; + } + if (_vm->_isDemo) + // protection disabled + Summa = 0; + else { +#ifdef EVA + union { dosdate_t d; uint32 n; } today; + _dos_getdate(&today.d); + id.disk += (id.disk < today.n); +#endif +#ifdef CD + Summa = 0; +#else + // disk signature checksum + Summa = ChkSum(Copr, sizeof(Ident)); +#endif + } + + if (SNDDrvInfo.MDEV != DEV_GM) + SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; return true; */ warning("STUB: Startup::get_parms"); From fe2e1bb2fd11d4f9e656f1e9392dc8e97c069d73 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 7 Jul 2011 20:43:09 +0200 Subject: [PATCH 089/276] CGE: Remove "bitmaps" files --- engines/cge/bitmaps.cpp | 229 ---------------------------------------- engines/cge/bitmaps.h | 44 -------- engines/cge/cge.cpp | 1 - engines/cge/events.h | 1 + engines/cge/game.h | 1 - engines/cge/module.mk | 1 - engines/cge/snail.cpp | 1 - engines/cge/text.cpp | 1 - 8 files changed, 1 insertion(+), 278 deletions(-) delete mode 100644 engines/cge/bitmaps.cpp delete mode 100644 engines/cge/bitmaps.h diff --git a/engines/cge/bitmaps.cpp b/engines/cge/bitmaps.cpp deleted file mode 100644 index 5e8757ae736..00000000000 --- a/engines/cge/bitmaps.cpp +++ /dev/null @@ -1,229 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/bitmaps.h" -/* - -#define W 255, -#define x 252, -#define _ TRANS, -#define o 0, -#define L LGRAY, -#define G GRAY, -#define D DGRAY, - -static uint8 MCDesign0[]= { W W W W W W _ - W W W W W o _ - W W W W o _ _ - W W W W W _ _ - W W o W W W _ - W o _ o W W W - o _ _ _ o W W - _ _ _ _ _ o o }; - - -static uint8 MCDesign1[]= { _ }; - - - -static uint8 SLDesign[] = { G G G G G G G G G _ _ _ _ _ _ - L G G G G G G G G D _ _ _ _ _ - _ L G G G G G G G D _ _ _ _ _ - _ _ L G G G G G G G D _ _ _ _ - _ _ _ L G G G G G G D _ _ _ _ - _ _ _ _ L G G G G G D _ _ _ _ - _ _ _ _ _ L G G G G G D _ _ _ - _ _ _ _ _ _ L G G G G D _ _ _ - _ _ _ _ _ _ _ L G G G D _ _ _ - _ _ _ _ _ _ _ _ L G G G D _ _ - _ _ _ _ _ _ _ _ _ L G G D _ _ - _ _ _ _ _ _ _ _ _ _ L G D _ _ - _ _ _ _ _ _ _ _ _ _ _ L G D _ - _ _ _ _ _ _ _ _ _ _ _ _ L D _ - _ _ _ _ _ _ _ _ _ _ _ _ _ L D - _ _ _ _ _ _ _ _ _ _ _ _ _ _ D - }; - -static uint8 SRDesign[] = { _ _ _ _ _ _ G G G G G G G G G - _ _ _ _ _ L G G G G G G G G D - _ _ _ _ _ L G G G G G G G D _ - _ _ _ _ L G G G G G G G D _ _ - _ _ _ _ L G G G G G G D _ _ _ - _ _ _ _ L G G G G G D _ _ _ _ - _ _ _ L G G G G G D _ _ _ _ _ - _ _ _ L G G G G D _ _ _ _ _ _ - _ _ _ L G G G D _ _ _ _ _ _ _ - _ _ L G G G D _ _ _ _ _ _ _ _ - _ _ L G G D _ _ _ _ _ _ _ _ _ - _ _ L G D _ _ _ _ _ _ _ _ _ _ - _ L G D _ _ _ _ _ _ _ _ _ _ _ - _ L D _ _ _ _ _ _ _ _ _ _ _ _ - L D _ _ _ _ _ _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ _ _ _ _ _ _ _ _ - }; - -static uint8 MapBrick[] = { L L L L L L L G - L G G G G G G D - L G G G G G G D - G D D D D D D D - }; - -#undef W -#undef _ -#undef x -#undef o -#undef L -#undef G -#undef D - - -#if 0 - -#define _ TRANS, -#define A 213, -#define B 207, -#define C 225, -#define D 219, -#define E 231, - -static uint8 PRDesign[] = { A E E E C C D A B - C _ _ _ _ _ _ D A - C _ _ _ _ _ _ D A - C _ _ _ _ _ _ D A - C _ _ _ _ _ _ D A - C _ _ _ _ _ _ D A - C _ _ _ _ _ _ D A - B A A A A A A A B - B B B B B B B B B - }; - -#else - -#define _ TRANS, -#define A 213, -#define B 207, -#define C 225, // DGRAY -#define D 219, -#define E 231, -#define F 237, - -static uint8 PRDesign[] = { D D D D D D D D _ - D D D D D D D D _ - D _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ _ _ - D _ _ _ _ _ _ C _ - D C C C C C C C _ - _ _ _ _ _ _ _ _ _ - }; -#endif - - -#undef _ -#undef A -#undef B -#undef C -#undef D -#undef E - - - -#define _ 0x00, -#define x 0xFF, -#define A _ x _ x _ x _ x -#define B A A A A A A A A - -static uint8 HLDesign[] = { B B B B B }; - -#undef _ -#undef x -#undef A -#undef B - - -// 228 yellow -// 211 red -// 226 light green -// 221 blue - -#define A 208, -#define B 214, -#define C 220, -#define D 226, -#define E 255, - -static uint8 LIDesign[][9] = { { A A A - A B A - A A A }, - - { A B A - B C B - A B A }, - - { B C B - C D C - B C B }, - - { C D C - D E D - C D C }, - }; - -#undef A -#undef B -#undef C -#undef D -#undef E - - -#define R 211, -#define G 0, -//226, - -static uint8 MEDesign[][9] = { { R R R R R R R R R }, // 0 - { R R R R R R R R G }, // 1 - { R R R R R R R G G }, // 2 - { R R R R R R G G G }, // 3 - { R R R R R G G G G }, // 4 - { R R R R G G G G G }, // 5 - { R R R G G G G G G }, // 6 - { R R G G G G G G G }, // 7 - { R G G G G G G G G }, // 8 - { G G G G G G G G G }, // 9 - }; - -#undef R -#undef G -*/ - -namespace CGE { - - - -} // End of namespace CGE diff --git a/engines/cge/bitmaps.h b/engines/cge/bitmaps.h deleted file mode 100644 index 85699321348..00000000000 --- a/engines/cge/bitmaps.h +++ /dev/null @@ -1,44 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __CGE_BITMAPS__ -#define __CGE_BITMAPS__ - -#include "cge/vga13h.h" - -namespace CGE { - -extern Bitmap *MB[]; -extern Bitmap *HL[]; -extern Bitmap *MC[]; -extern Bitmap *PR[]; -extern Bitmap *SP[]; -extern Bitmap *LI[]; - -} // End of namespace CGE - -#endif diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index b953f2f5b02..4c21b21f872 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -34,7 +34,6 @@ #include "cge/cge_main.h" #include "cge/talk.h" #include "cge/text.h" -#include "cge/bitmaps.h" #include "cge/vol.h" diff --git a/engines/cge/events.h b/engines/cge/events.h index cfb1023d6b5..6df2c94d4a0 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -91,6 +91,7 @@ struct CGEEvent { extern CGEEvent Evt[EVT_MAX]; extern uint16 EvtHead, EvtTail; +extern Bitmap *MC[]; class MOUSE : public Sprite { diff --git a/engines/cge/game.h b/engines/cge/game.h index b26fc0d1652..c442d815774 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -29,7 +29,6 @@ #define __CGE_GAME__ #include "cge/vga13h.h" -#include "cge/bitmaps.h" namespace CGE { diff --git a/engines/cge/module.mk b/engines/cge/module.mk index d9dea6534d7..95ffd6d9061 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -2,7 +2,6 @@ MODULE := engines/cge MODULE_OBJS := \ bitmap.o \ - bitmaps.o \ btfile.o \ cfile.o \ cge.o \ diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 683568e1a81..a0b5c4bdd61 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -29,7 +29,6 @@ #include "cge/sound.h" #include "cge/snail.h" #include "cge/vga13h.h" -#include "cge/bitmaps.h" #include "cge/text.h" #include "cge/cge_main.h" #include "cge/events.h" diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 5f370150ca9..c1d32d15cdb 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -29,7 +29,6 @@ #include "cge/text.h" #include "cge/talk.h" #include "cge/vol.h" -#include "cge/bitmaps.h" #include "cge/game.h" #include "cge/snail.h" #include "cge/cge_main.h" From dd778667096d2bfab50ac8171d1ee3a45d46fb55 Mon Sep 17 00:00:00 2001 From: eriktorbjorn Date: Thu, 7 Jul 2011 20:51:31 +0200 Subject: [PATCH 090/276] CGE: Remove unused variable --- engines/cge/cge_main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index e7ca76a98fc..d08fa674004 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -177,7 +177,6 @@ Cluster XZ(Couple xy) { } void CGEEngine::loadGame(XFile &file, bool tiny = false) { - SavTab *st; Sprite *spr; int i; From 080d7cf7f082b5faa245da965211a099ed37fd2b Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 8 Jul 2011 08:21:35 +0200 Subject: [PATCH 091/276] CGE: Rename Mouse class --- engines/cge/cge.cpp | 2 +- engines/cge/cge_main.cpp | 20 ++++++------ engines/cge/cge_main.h | 2 +- engines/cge/events.cpp | 69 +++++++++++++++++++++------------------- engines/cge/events.h | 25 ++++++++------- engines/cge/mixer.cpp | 2 +- engines/cge/snail.cpp | 4 +-- engines/cge/vga13h.cpp | 8 ++--- 8 files changed, 68 insertions(+), 64 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 4c21b21f872..2c173b89901 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -105,7 +105,7 @@ void CGEEngine::setup() { _snail = new Snail(this, false); _snail_ = new Snail(this, true); - _mouse = new MOUSE(this); + _mouse = new Mouse(this); _keyboard = new Keyboard(); _eventManager = new EventManager(); _offUseCount = atoi(_text->getText(OFF_USE_COUNT)); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index d08fa674004..0135b0441a9 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -64,7 +64,7 @@ System *_sys; Sprite *_pocLight; EventManager *_eventManager; Keyboard *_keyboard; -MOUSE *_mouse; +Mouse *_mouse; Sprite *_pocket[POCKET_NX]; Sprite *_sprite; Sprite *_miniCave; @@ -681,7 +681,7 @@ void CGEEngine::caveUp() { _vga->sunrise(Vga::_sysPal); _dark = false; if (!_startupMode) - _mouse->On(); + _mouse->on(); _heart->_enable = true; } @@ -732,7 +732,7 @@ void CGEEngine::switchCave(int cav) { warning("SwitchCave() - SNPOST"); } else { _now = cav; - _mouse->Off(); + _mouse->off(); if (_hero) { _hero->park(); _hero->step(0); @@ -1625,9 +1625,9 @@ void CGEEngine::runGame() { _horzLine->_z = 126; _vga->_showQ->insert(_horzLine); - _mouse->Busy = _vga->_spareQ->locate(BUSY_REF); - if (_mouse->Busy) - expandSprite(_mouse->Busy); + _mouse->_busy = _vga->_spareQ->locate(BUSY_REF); + if (_mouse->_busy) + expandSprite(_mouse->_busy); _startupMode = 0; @@ -1649,7 +1649,7 @@ void CGEEngine::runGame() { _heart->_enable = false; SNPOST(SNCLEAR, -1, 0, NULL); SNPOST_(SNCLEAR, -1, 0, NULL); - _mouse->Off(); + _mouse->off(); _vga->_showQ->clear(); _vga->_spareQ->clear(); _hero = NULL; @@ -1716,14 +1716,14 @@ bool CGEEngine::showTitle(const char *name) { _vga->copyPage(0, 1); _vga->_showQ->append(_mouse); _heart->_enable = true; - _mouse->On(); + _mouse->on(); for (selectSound(); !_snail->idle() || Vmenu::_addr;) { mainLoop(); if (_eventManager->_quitFlag) return false; } - _mouse->Off(); + _mouse->off(); _heart->_enable = false; _vga->_showQ->clear(); _vga->copyPage(0, 2); @@ -1812,7 +1812,7 @@ void CGEEngine::cge_main() { //Debug( memset((void *) (-K(4)), 0, K(1)); ) memset(_barriers, 0xFF, sizeof(_barriers)); - if (!_mouse->Exist) + if (!_mouse->_exist) error("%s", _text->getText(NO_MOUSE_TEXT)); if (!SVG0FILE::exist(SVG0NAME)) diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 3ef3679e8e1..17925f76f95 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -169,7 +169,7 @@ extern System *_sys; extern int _offUseCount; extern Sprite *_pocLight; extern Keyboard *_keyboard; -extern MOUSE *_mouse; +extern Mouse *_mouse; extern EventManager *_eventManager; extern Sprite *_pocket[]; extern Sprite *_sprite; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index e904b710baf..82d0203e5ec 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -141,17 +141,18 @@ void Keyboard::NewKeyboard(Common::Event &event) { /*----------------- MOUSE interface -----------------*/ -MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold(NULL), hx(0), _vm(vm) { +Mouse::Mouse(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { static Seq ms[] = { { 0, 0, 0, 0, 1 }, { 1, 1, 0, 0, 1 } }; - Hold = NULL; - hx = 0; hy = 0; - Exist = true; - Buttons = 0; - Busy = NULL; + _hold = NULL; + _hx = 0; + _hy = 0; + _exist = true; + _buttons = 0; + _busy = NULL; _active = false; setSeq(ms); @@ -162,37 +163,39 @@ MOUSE::MOUSE(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), Busy(NULL), Hold( } -MOUSE::~MOUSE() { - Off(); +Mouse::~Mouse() { + off(); } -//void MOUSE::SetFun() +//void Mouse::setFun() //{ //} -void MOUSE::On() { - if (_seqPtr && Exist) { +void Mouse::on() { + if (_seqPtr && _exist) { _active = true; step(0); - if (Busy) Busy->step(0); + if (_busy) + _busy->step(0); } } -void MOUSE::Off() { +void Mouse::off() { if (_seqPtr == 0) { - if (Exist) { + if (_exist) { _active = false; } step(1); - if (Busy) Busy->step(1); + if (_busy) + _busy->step(1); } } -void MOUSE::NewMouse(Common::Event &event) { +void Mouse::newMouse(Common::Event &event) { if (!_active) return; @@ -208,19 +211,19 @@ void MOUSE::NewMouse(Common::Event &event) { break; case Common::EVENT_LBUTTONDOWN: evt._msk = L_DN; - Buttons |= 1; + _buttons |= 1; break; case Common::EVENT_LBUTTONUP: evt._msk = L_UP; - Buttons &= ~1; + _buttons &= ~1; break; case Common::EVENT_RBUTTONDOWN: evt._msk = R_DN; - Buttons |= 2; + _buttons |= 2; break; case Common::EVENT_RBUTTONUP: evt._msk = R_UP; - Buttons &= ~2; + _buttons &= ~2; break; default: break; @@ -252,7 +255,7 @@ void EventManager::poll() { case Common::EVENT_RBUTTONDOWN: case Common::EVENT_RBUTTONUP: // Handle mouse events - _mouse->NewMouse(_event); + _mouse->newMouse(_event); handleEvents(); break; default: @@ -265,8 +268,8 @@ void EventManager::handleEvents() { while (EvtTail != EvtHead) { CGEEvent e = Evt[EvtTail]; if (e._msk) { - if (_mouse->Hold && e._ptr != _mouse->Hold) - _mouse->Hold->touch(e._msk | ATTN, e._x - _mouse->Hold->_x, e._y - _mouse->Hold->_y); + if (_mouse->_hold && e._ptr != _mouse->_hold) + _mouse->_hold->touch(e._msk | ATTN, e._x - _mouse->_hold->_x, e._y - _mouse->_hold->_y); // update mouse cursor position if (e._msk & ROLL) @@ -282,18 +285,18 @@ void EventManager::handleEvents() { _sys->touch(e._msk, e._x, e._y); if (e._msk & L_DN) { - _mouse->Hold = e._ptr; - if (_mouse->Hold) { - _mouse->Hold->_flags._hold = true; - _mouse->hx = e._x - _mouse->Hold->_x; - _mouse->hy = e._y - _mouse->Hold->_y; + _mouse->_hold = e._ptr; + if (_mouse->_hold) { + _mouse->_hold->_flags._hold = true; + _mouse->_hx = e._x - _mouse->_hold->_x; + _mouse->_hy = e._y - _mouse->_hold->_y; } } if (e._msk & L_UP) { - if (_mouse->Hold) { - _mouse->Hold->_flags._hold = false; - _mouse->Hold = NULL; + if (_mouse->_hold) { + _mouse->_hold->_flags._hold = false; + _mouse->_hold = NULL; } } ///Touched = e.Ptr; @@ -304,8 +307,8 @@ void EventManager::handleEvents() { } EvtTail = (EvtTail + 1) % EVT_MAX; } - if (_mouse->Hold) - _mouse->Hold->gotoxy(_mouse->_x - _mouse->hx, _mouse->_y - _mouse->hy); + if (_mouse->_hold) + _mouse->_hold->gotoxy(_mouse->_x - _mouse->_hx, _mouse->_y - _mouse->_hy); } void EventManager::ClrEvt(Sprite *spr) { diff --git a/engines/cge/events.h b/engines/cge/events.h index 6df2c94d4a0..374c28aebcc 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -94,21 +94,22 @@ extern uint16 EvtHead, EvtTail; extern Bitmap *MC[]; -class MOUSE : public Sprite { +class Mouse : public Sprite { public: - Sprite *Hold; + Sprite *_hold; bool _active; - int hx, hy; - bool Exist; - int Buttons; - Sprite *Busy; + int _hx; + int _hy; + bool _exist; + int _buttons; + Sprite *_busy; //Sprite *Touched; - MOUSE(CGEEngine *vm, Bitmap **shpl = MC); - ~MOUSE(); - void On(); - void Off(); - void Tick(); - void NewMouse(Common::Event &event); + Mouse(CGEEngine *vm, Bitmap **shpl = MC); + ~Mouse(); + void on(); + void off(); + void tick(); + void newMouse(Common::Event &event); private: CGEEngine *_vm; }; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index d4a5212552f..aea033ebc91 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -34,7 +34,7 @@ namespace CGE { -extern MOUSE *Mouse; +extern Mouse *Mouse; bool Mixer::_appear = false; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index a0b5c4bdd61..15ba714369d 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -848,9 +848,9 @@ void CGEEngine::snReach(Sprite *spr, int mode) { void CGEEngine::snMouse(bool on) { if (on) - _mouse->On(); + _mouse->on(); else - _mouse->Off(); + _mouse->off(); } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 36ac0601117..e1309c96f03 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -234,14 +234,14 @@ extern "C" void TimerProc() { if (Sys) { if (Sys->Time) { if (--Sys->Time == 0) - Sys->Tick(); + Sys->tick(); } } for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { if (spr->Time) { if (!spr->_flags.Hide) { if (-- spr->Time == 0) - spr->Tick(); + spr->tick(); } } } @@ -308,7 +308,7 @@ void Engine_::newTimer(...) { if (Sys) { if (Sys->Time) { if (--Sys->Time == 0) - Sys->Tick(); + Sys->tick(); } } @@ -316,7 +316,7 @@ void Engine_::newTimer(...) { if (spr->Time) { if (!spr->_flags.Hide) { if (--spr->Time == 0) - spr->Tick(); + spr->tick(); } } } From 0b27de942b9dcb9cd3ea75955c02bb1bf813ddd8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 9 Jul 2011 00:25:09 +0200 Subject: [PATCH 092/276] CGE: replace some 'tricky replicate lines' memcpy by two, in order to avoid overlapping --- engines/cge/events.h | 1 - engines/cge/talk.cpp | 29 +++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/engines/cge/events.h b/engines/cge/events.h index 374c28aebcc..90b8ed1db0c 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -108,7 +108,6 @@ public: ~Mouse(); void on(); void off(); - void tick(); void newMouse(Common::Event &event); private: CGEEngine *_vm; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 7c0f9563a64..61de47e48a8 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -248,13 +248,22 @@ void Talk::putLine(int line, const char *text) { // clear whole rectangle p = v; // assume blanked line above text - memcpy(p, p - lsiz, rsiz); + + byte *tmpBuf = new byte[rsiz]; + + memcpy(tmpBuf, p - lsiz, rsiz); + memcpy(p, tmpBuf, rsiz); p += psiz; // tricky replicate lines for plane 0 - memcpy(p, p - lsiz, rsiz); + memcpy(tmpBuf, p - lsiz, rsiz); + memcpy(p, tmpBuf, rsiz); p += psiz; // same for plane 1 - memcpy(p, p - lsiz, rsiz); + memcpy(tmpBuf, p - lsiz, rsiz); + memcpy(p, tmpBuf, rsiz); p += psiz; // same for plane 2 - memcpy(p, p - lsiz, rsiz); // same for plane 3 + memcpy(tmpBuf, p - lsiz, rsiz); + memcpy(p, tmpBuf, rsiz); + + delete[] tmpBuf; // paint text line if (text) { @@ -302,10 +311,18 @@ void InfoLine::update(const char *tx) { uint16 size = 4 * psiz; // whole map size // clear whole rectangle + byte *tmpBuf = new byte[size]; memset(v + 2, TEXT_BG, dsiz); // data bytes - memcpy(v + lsiz, v, psiz - lsiz); // tricky replicate lines + + memcpy(tmpBuf, v, psiz - lsiz); + memcpy(v + lsiz, tmpBuf, psiz - lsiz); + *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 - memcpy(v + psiz, v, 3 * psiz); // tricky replicate planes + + memcpy(tmpBuf, v, 3 * psiz); + memcpy(v + psiz, tmpBuf, 3 * psiz); + + delete[] tmpBuf; // paint text line if (tx) { From 6ed9dd0d04b8513ad44e3541afc6db758100310c Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 9 Jul 2011 00:41:47 +0200 Subject: [PATCH 093/276] CGE: Cleanup: rename a couple of forgotten class members --- engines/cge/events.cpp | 6 +++--- engines/cge/events.h | 6 ++---- engines/cge/snail.cpp | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 82d0203e5ec..116eb34b521 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -116,7 +116,7 @@ bool Keyboard::getKey(uint16 keycode, int &cgeCode) { return false; } -void Keyboard::NewKeyboard(Common::Event &event) { +void Keyboard::newKeyboard(Common::Event &event) { int keycode; if (!getKey(event.kbd.keycode, keycode)) return; @@ -246,7 +246,7 @@ void EventManager::poll() { case Common::EVENT_KEYDOWN: case Common::EVENT_KEYUP: // Handle keyboard events - _keyboard->NewKeyboard(_event); + _keyboard->newKeyboard(_event); handleEvents(); break; case Common::EVENT_MOUSEMOVE: @@ -311,7 +311,7 @@ void EventManager::handleEvents() { _mouse->_hold->gotoxy(_mouse->_x - _mouse->_hx, _mouse->_y - _mouse->_hy); } -void EventManager::ClrEvt(Sprite *spr) { +void EventManager::clrEvt(Sprite *spr) { if (spr) { uint16 e; for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) diff --git a/engines/cge/events.h b/engines/cge/events.h index 90b8ed1db0c..75c504f0309 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -56,7 +56,7 @@ public: Sprite *_client; bool _key[0x60]; - void NewKeyboard(Common::Event &event); + void newKeyboard(Common::Event &event); uint16 last() { uint16 cur = _current; _current = 0; @@ -89,8 +89,6 @@ struct CGEEvent { Sprite *_ptr; }; -extern CGEEvent Evt[EVT_MAX]; -extern uint16 EvtHead, EvtTail; extern Bitmap *MC[]; @@ -124,7 +122,7 @@ public: EventManager(); void poll(); - static void ClrEvt(Sprite *spr = NULL); + static void clrEvt(Sprite *spr = NULL); }; } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 15ba714369d..242fb067e7a 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -710,7 +710,7 @@ void CGEEngine::snKill(Sprite *spr) { Sprite *nx = spr->_next; hide1(spr); _vga->_showQ->remove(spr); - EventManager::ClrEvt(spr); + EventManager::clrEvt(spr); if (spr->_flags._kill) delete spr; else { From cf1a45f8a8ecfe758dfb6a420b004821528a19cc Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 9 Jul 2011 09:39:02 +0200 Subject: [PATCH 094/276] CGE: replace the 2 memcpy previously used by a memmove (thanks eriktorbjorn for pointing that out) --- engines/cge/talk.cpp | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 61de47e48a8..f41e31dce69 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -248,22 +248,13 @@ void Talk::putLine(int line, const char *text) { // clear whole rectangle p = v; // assume blanked line above text - - byte *tmpBuf = new byte[rsiz]; - - memcpy(tmpBuf, p - lsiz, rsiz); - memcpy(p, tmpBuf, rsiz); + memmove(p, p - lsiz, rsiz); p += psiz; // tricky replicate lines for plane 0 - memcpy(tmpBuf, p - lsiz, rsiz); - memcpy(p, tmpBuf, rsiz); + memmove(p, p - lsiz, rsiz); p += psiz; // same for plane 1 - memcpy(tmpBuf, p - lsiz, rsiz); - memcpy(p, tmpBuf, rsiz); + memmove(p, p - lsiz, rsiz); p += psiz; // same for plane 2 - memcpy(tmpBuf, p - lsiz, rsiz); - memcpy(p, tmpBuf, rsiz); - - delete[] tmpBuf; + memmove(p, p - lsiz, rsiz); // paint text line if (text) { @@ -311,18 +302,10 @@ void InfoLine::update(const char *tx) { uint16 size = 4 * psiz; // whole map size // clear whole rectangle - byte *tmpBuf = new byte[size]; memset(v + 2, TEXT_BG, dsiz); // data bytes - - memcpy(tmpBuf, v, psiz - lsiz); - memcpy(v + lsiz, tmpBuf, psiz - lsiz); - + memmove(v + lsiz, v, psiz - lsiz); *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 - - memcpy(tmpBuf, v, 3 * psiz); - memcpy(v + psiz, tmpBuf, 3 * psiz); - - delete[] tmpBuf; + memmove(v + psiz, v, 3 * psiz); // paint text line if (tx) { From 989e071bb9d101696f5498d1eeea5e32c7291e5d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 09:44:46 +1000 Subject: [PATCH 095/276] CGE: Implemented code for saving games, removing the need for the SavTab array --- engines/cge/cge.cpp | 51 ------------------------ engines/cge/cge.h | 5 ++- engines/cge/cge_main.cpp | 83 ++++++++++++++++++++++++++-------------- 3 files changed, 57 insertions(+), 82 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 2c173b89901..25fc4f7c000 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -116,57 +116,6 @@ void CGEEngine::setup() { _volume[0] = 0; _volume[1] = 0; - _savTab[0]._ptr = &_now; - _savTab[0]._len = sizeof(_now); - _savTab[0]._flag = true; - _savTab[1]._ptr = &_oldLev; - _savTab[1]._len = sizeof(_oldLev); - _savTab[1]._flag = true; - _savTab[2]._ptr = &_demoText; - _savTab[2]._len = sizeof(_demoText); - _savTab[2]._flag = true; - _savTab[3]._ptr = &_game; - _savTab[3]._len = sizeof(_game); - _savTab[3]._flag = true; - _savTab[4]._ptr = &_game; - _savTab[4]._len = sizeof(_game); - _savTab[4]._flag = true; - _savTab[5]._ptr = &_game; - _savTab[5]._len = sizeof(_game); - _savTab[5]._flag = true; - _savTab[6]._ptr = &_game; - _savTab[6]._len = sizeof(_game); - _savTab[6]._flag = true; - _savTab[7]._ptr = &_game; - _savTab[7]._len = sizeof(_game); - _savTab[7]._flag = true; - _savTab[8]._ptr = &_vga->_mono; - _savTab[8]._len = sizeof(_vga->_mono); - _savTab[8]._flag = false; - _savTab[9]._ptr = &_music; - _savTab[9]._len = sizeof(_music); - _savTab[9]._flag = true; - _savTab[10]._ptr = _volume; - _savTab[10]._len = sizeof(_volume); - _savTab[10]._flag = true; - _savTab[11]._ptr = _flag; - _savTab[11]._len = sizeof(_flag); - _savTab[11]._flag = true; - _savTab[12]._ptr = _heroXY; -// _savTab[12]._len = sizeof(_heroXY); FIXME: illegal sizeof - _savTab[12]._len = 0; - _savTab[12]._flag = true; - _savTab[13]._ptr = _barriers; -// _savTab[13]._len = sizeof(_barriers); FIXME: illegal sizeof - _savTab[13]._len = 0; - _savTab[13]._flag = true; - _savTab[14]._ptr = _pocref; - _savTab[14]._len = sizeof(_pocref); - _savTab[14]._flag = true; - _savTab[15]._ptr = NULL; - _savTab[15]._len = 0; - _savTab[15]._flag = false; - if (_isDemo) { _maxCaveArr[0] = CAVE_MAX; _maxCaveArr[1] = -1; diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 4f6b452850d..49f2c46e407 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -25,6 +25,7 @@ #include "cge/general.h" #include "common/random.h" +#include "common/serializer.h" #include "engines/engine.h" #include "gui/debugger.h" #include "graphics/surface.h" @@ -58,6 +59,7 @@ class CGEEngine : public Engine { private: uint32 _lastFrame; void tick(); + void syncHeader(Common::Serializer &s); public: CGEEngine(OSystem *syst, const ADGameDescription *gameDescription); ~CGEEngine(); @@ -69,7 +71,6 @@ public: int _oldLev; bool _jbw; int _pocPtr; - SavTab _savTab[16]; bool _music; int _pocref[POCKET_NX]; uint8 _volume[2]; @@ -124,7 +125,7 @@ public: void setIRQ(); void setDMA(); void mainLoop(); - void saveGame(XFile &file); + void saveGame(Common::WriteStream *file); void switchMusic(); void selectPocket(int n); void expandSprite(Sprite *spr); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 0135b0441a9..256cee67959 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -27,6 +27,7 @@ #include "common/scummsys.h" #include "common/memstream.h" +#include "common/savefile.h" #include "common/serializer.h" #include "cge/general.h" #include "cge/sound.h" @@ -176,18 +177,9 @@ Cluster XZ(Couple xy) { return XZ(x, y); } -void CGEEngine::loadGame(XFile &file, bool tiny = false) { - Sprite *spr; +void CGEEngine::syncHeader(Common::Serializer &s) { int i; - // Read the data into a data buffer - int size = file.size() - file.mark(); - byte *dataBuffer = new byte[size]; - file.read(dataBuffer, size); - Common::MemoryReadStream readStream(dataBuffer, size, DisposeAfterUse::YES); - Common::Serializer s(&readStream, NULL); - - // Synchronise header data s.syncAsUint16LE(_now); s.syncAsUint16LE(_oldLev); s.syncAsUint16LE(_demoText); @@ -210,10 +202,32 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { for (i = 0; i < POCKET_NX; ++i) s.syncAsUint16LE(_pocref[i]); - uint16 checksum; - s.syncAsUint16LE(checksum); - if (checksum != SVGCHKSUM) - error("%s", _text->getText(BADSVG_TEXT)); + if (s.isSaving()) { + // Write checksum + int checksum = SVGCHKSUM; + s.syncAsUint16LE(checksum); + } else { + // Read checksum and validate it + uint16 checksum; + s.syncAsUint16LE(checksum); + if (checksum != SVGCHKSUM) + error("%s", _text->getText(BADSVG_TEXT)); + } +} + +void CGEEngine::loadGame(XFile &file, bool tiny = false) { + Sprite *spr; + int i; + + // Read the data into a data buffer + int size = file.size() - file.mark(); + byte *dataBuffer = new byte[size]; + file.read(dataBuffer, size); + Common::MemoryReadStream readStream(dataBuffer, size, DisposeAfterUse::YES); + Common::Serializer s(&readStream, NULL); + + // Synchronise header data + syncHeader(s); if (Startup::_core < CORE_HIG) _music = false; @@ -253,7 +267,7 @@ void CGEEngine::saveSound() { } -void CGEEngine::saveGame(XFile &file) { +void CGEEngine::saveGame(Common::WriteStream *file) { SavTab *st; Sprite *spr; int i; @@ -266,18 +280,19 @@ void CGEEngine::saveGame(XFile &file) { _volume[0] = _sndDrvInfo.Vol2._d; _volume[1] = _sndDrvInfo.Vol2._m; - for (st = _savTab; st->_ptr; st++) { - if (file._error) - error("Bad SVG"); - file.write((uint8 *) st->_ptr, st->_len); + Common::Serializer s(NULL, file); + + // Synchronise header data + syncHeader(s); + + // Loop through saving the sprite data + for (spr = _vga->_spareQ->first(); spr; spr = spr->_next) { + if ((spr->_ref >= 1000) && !s.err()) + spr->sync(s); } - file.write((uint8 *) & (i = SVGCHKSUM), sizeof(i)); - - for (spr = _vga->_spareQ->first(); spr; spr = spr->_next) - if (spr->_ref >= 1000) - if (!file._error) - file.write((uint8 *)spr, sizeof(*spr)); + // Finish writing out game data + file->finalize(); } void CGEEngine::heroCover(int cvr) { @@ -715,8 +730,12 @@ void CGEEngine::qGame() { caveDown(); _oldLev = _lev; saveSound(); - CFile file = CFile(usrPath(_usrFnam), WRI, RCrypt); - saveGame(file); + + // Write out the user's progress + Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(Common::String(_usrFnam)); + saveGame(saveFile); + delete saveFile; + _vga->sunset(); _finis = true; } @@ -1531,10 +1550,16 @@ void CGEEngine::loadUser() { SVG0FILE file = SVG0FILE(SVG0NAME); loadGame(file); } else { + // TODO: I think this was only used by the original developers to create the initial + // game state savegame. Verify this is the case, and if so remove this block loadScript(progName(INI_EXT)); _music = true; - CFile file = CFile(SVG0NAME, WRI); - saveGame(file); + + Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving( + Common::String(SVG0NAME)); + saveGame(saveFile); + delete saveFile; + error("Ok [%s]", SVG0NAME); } } From 1e83e27925e121ee50b3ee66f5fb007e2d6b338f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 09:51:18 +1000 Subject: [PATCH 096/276] CGE: Moved MB sprite array into Square class --- engines/cge/cge.cpp | 3 --- engines/cge/cge_main.cpp | 8 ++++++-- engines/cge/cge_main.h | 2 -- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 25fc4f7c000..4fca901873b 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -69,8 +69,6 @@ void CGEEngine::setup() { Talk::init(); // Initialise sprite arrays used by game objects - MB[0] = new Bitmap("BRICK", true); - MB[1] = NULL; HL[0] = new Bitmap("HLINE", true); HL[1] = NULL; MC[0] = new Bitmap("MOUSE", true); @@ -162,7 +160,6 @@ CGEEngine::~CGEEngine() { delete _infoLine; delete _cavLight; delete _debugLine; - delete MB[0]; delete HL[0]; delete MC[0]; delete MC[1]; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 256cee67959..5f56899bc85 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -75,7 +75,6 @@ InfoLine *_infoLine; Sprite *_cavLight; InfoLine *_debugLine; -BMP_PTR MB[2]; BMP_PTR HL[2]; BMP_PTR MC[3]; BMP_PTR PR[2]; @@ -516,9 +515,14 @@ private: SQUARE::SQUARE(CGEEngine *vm) - : Sprite(vm, MB), _vm(vm) { + : Sprite(vm, NULL), _vm(vm) { _flags._kill = true; _flags._bDel = false; + + BMP_PTR *MB = new BMP_PTR[2]; + MB[0] = new Bitmap("BRICK", true); + MB[1] = NULL; + setShapeList(MB); } diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 17925f76f95..ff2e5a0492c 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -179,8 +179,6 @@ extern Sprite *_horzLine; extern InfoLine *_infoLine; extern Sprite *_cavLight; extern InfoLine *_debugLine; -extern BMP_PTR MB[2]; -extern BMP_PTR MB[2]; extern BMP_PTR HL[2]; extern BMP_PTR MC[3]; extern BMP_PTR PR[2]; From 817a52ed56abc172b158d794501f2bff0ab70e94 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 09:57:19 +1000 Subject: [PATCH 097/276] CGE: Created a HorizLine stub class to hold the HL sprite array --- engines/cge/cge.cpp | 5 +---- engines/cge/cge_main.cpp | 3 +-- engines/cge/cge_main.h | 3 +-- engines/cge/vga13h.cpp | 11 +++++++++++ engines/cge/vga13h.h | 4 ++++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 4fca901873b..1fba9dfdc23 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -69,8 +69,6 @@ void CGEEngine::setup() { Talk::init(); // Initialise sprite arrays used by game objects - HL[0] = new Bitmap("HLINE", true); - HL[1] = NULL; MC[0] = new Bitmap("MOUSE", true); MC[1] = new Bitmap("DUMMY", true); MC[2] = NULL; @@ -96,7 +94,7 @@ void CGEEngine::setup() { _sprite = new Sprite(this, NULL); _miniCave = new Sprite(this, NULL); _shadow = new Sprite(this, NULL); - _horzLine = new Sprite(this, HL); + _horzLine = new HorizLine(this); _infoLine = new InfoLine(this, INFO_W); _cavLight = new Sprite(this, PR); _debugLine = new InfoLine(this, SCR_WID); @@ -160,7 +158,6 @@ CGEEngine::~CGEEngine() { delete _infoLine; delete _cavLight; delete _debugLine; - delete HL[0]; delete MC[0]; delete MC[1]; delete PR[0]; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 5f56899bc85..f74eda259ed 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -70,12 +70,11 @@ Sprite *_pocket[POCKET_NX]; Sprite *_sprite; Sprite *_miniCave; Sprite *_shadow; -Sprite *_horzLine; +HorizLine *_horzLine; InfoLine *_infoLine; Sprite *_cavLight; InfoLine *_debugLine; -BMP_PTR HL[2]; BMP_PTR MC[3]; BMP_PTR PR[2]; BMP_PTR SP[3]; diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index ff2e5a0492c..6455b0d3caf 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -175,11 +175,10 @@ extern Sprite *_pocket[]; extern Sprite *_sprite; extern Sprite *_miniCave; extern Sprite *_shadow; -extern Sprite *_horzLine; +extern HorizLine *_horzLine; extern InfoLine *_infoLine; extern Sprite *_cavLight; extern InfoLine *_debugLine; -extern BMP_PTR HL[2]; extern BMP_PTR MC[3]; extern BMP_PTR PR[2]; extern BMP_PTR SP[3]; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index e1309c96f03..fb1c89ef5ec 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1360,4 +1360,15 @@ void Bitmap::hide(int x, int y) { } } +/*--------------------------------------------------------------------------*/ + +HorizLine::HorizLine(CGEEngine *vm): Sprite(vm, NULL) { + // Set the sprite list + BMP_PTR *HL = new BMP_PTR[2]; + HL[0] = new Bitmap("HLINE", true); + HL[1] = NULL; + + setShapeList(HL); +} + } // End of namespace CGE diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index b0cba4dcc09..d9aba0468e6 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -306,6 +306,10 @@ public: static void dacToPal(const Dac *tab, byte *palData); }; +class HorizLine: public Sprite { +public: + HorizLine(CGEEngine *vm); +}; Dac mkDac(uint8 r, uint8 g, uint8 b); Rgb mkRgb(uint8 r, uint8 g, uint8 b); From 9d40a1ba9d79fd8623dc0525cf25cfc4756a36d2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 10:00:57 +1000 Subject: [PATCH 098/276] CGE: Mouse MC sprite array into the Mouse class --- engines/cge/cge.cpp | 5 ----- engines/cge/cge_main.cpp | 1 - engines/cge/events.cpp | 8 +++++++- engines/cge/events.h | 4 +--- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 1fba9dfdc23..5ce83f109d3 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -69,9 +69,6 @@ void CGEEngine::setup() { Talk::init(); // Initialise sprite arrays used by game objects - MC[0] = new Bitmap("MOUSE", true); - MC[1] = new Bitmap("DUMMY", true); - MC[2] = NULL; PR[0] = new Bitmap("PRESS", true); PR[1] = NULL; SP[0] = new Bitmap("SPK_L", true); @@ -158,8 +155,6 @@ CGEEngine::~CGEEngine() { delete _infoLine; delete _cavLight; delete _debugLine; - delete MC[0]; - delete MC[1]; delete PR[0]; delete SP[0]; delete SP[1]; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index f74eda259ed..7edfd9b1d1c 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -75,7 +75,6 @@ InfoLine *_infoLine; Sprite *_cavLight; InfoLine *_debugLine; -BMP_PTR MC[3]; BMP_PTR PR[2]; BMP_PTR SP[3]; BMP_PTR LI[5]; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 116eb34b521..6168dd15a8f 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -141,7 +141,7 @@ void Keyboard::newKeyboard(Common::Event &event) { /*----------------- MOUSE interface -----------------*/ -Mouse::Mouse(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { +Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { static Seq ms[] = { { 0, 0, 0, 0, 1 }, { 1, 1, 0, 0, 1 } @@ -157,6 +157,12 @@ Mouse::Mouse(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), _busy(NULL), _hol setSeq(ms); + BMP_PTR *MC = new BMP_PTR[3]; + MC[0] = new Bitmap("MOUSE", true); + MC[1] = new Bitmap("DUMMY", true); + MC[2] = NULL; + setShapeList(MC); + gotoxy(SCR_WID/2, SCR_HIG/2); _z = 127; step(1); diff --git a/engines/cge/events.h b/engines/cge/events.h index 75c504f0309..671878f69a2 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -89,8 +89,6 @@ struct CGEEvent { Sprite *_ptr; }; -extern Bitmap *MC[]; - class Mouse : public Sprite { public: @@ -102,7 +100,7 @@ public: int _buttons; Sprite *_busy; //Sprite *Touched; - Mouse(CGEEngine *vm, Bitmap **shpl = MC); + Mouse(CGEEngine *vm); ~Mouse(); void on(); void off(); From 622dc2d503c247e750d82fb9dea885bcf14881ed Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 10:04:41 +1000 Subject: [PATCH 099/276] CGE: Created a CavLight class to encapsulate the PR sprite array --- engines/cge/cge.cpp | 5 +---- engines/cge/cge_main.cpp | 1 - engines/cge/cge_main.h | 1 - engines/cge/vga13h.cpp | 9 +++++++++ engines/cge/vga13h.h | 5 +++++ 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 5ce83f109d3..6dbe12d9c6b 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -69,8 +69,6 @@ void CGEEngine::setup() { Talk::init(); // Initialise sprite arrays used by game objects - PR[0] = new Bitmap("PRESS", true); - PR[1] = NULL; SP[0] = new Bitmap("SPK_L", true); SP[1] = new Bitmap("SPK_R", true); SP[2] = NULL; @@ -93,7 +91,7 @@ void CGEEngine::setup() { _shadow = new Sprite(this, NULL); _horzLine = new HorizLine(this); _infoLine = new InfoLine(this, INFO_W); - _cavLight = new Sprite(this, PR); + _cavLight = new CavLight(this); _debugLine = new InfoLine(this, SCR_WID); _snail = new Snail(this, false); _snail_ = new Snail(this, true); @@ -155,7 +153,6 @@ CGEEngine::~CGEEngine() { delete _infoLine; delete _cavLight; delete _debugLine; - delete PR[0]; delete SP[0]; delete SP[1]; delete LI[0]; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 7edfd9b1d1c..4632caabfa2 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -75,7 +75,6 @@ InfoLine *_infoLine; Sprite *_cavLight; InfoLine *_debugLine; -BMP_PTR PR[2]; BMP_PTR SP[3]; BMP_PTR LI[5]; diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 6455b0d3caf..d7594c94d92 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -180,7 +180,6 @@ extern InfoLine *_infoLine; extern Sprite *_cavLight; extern InfoLine *_debugLine; extern BMP_PTR MC[3]; -extern BMP_PTR PR[2]; extern BMP_PTR SP[3]; extern BMP_PTR LI[5]; extern Snail *_snail; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index fb1c89ef5ec..1f12dd8aa92 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1371,4 +1371,13 @@ HorizLine::HorizLine(CGEEngine *vm): Sprite(vm, NULL) { setShapeList(HL); } +CavLight::CavLight(CGEEngine *vm): Sprite(vm, NULL) { + // Set the sprite list + BMP_PTR *PR = new BMP_PTR[2]; + PR[0] = new Bitmap("PRESS", true); + PR[1] = NULL; + + setShapeList(PR); +} + } // End of namespace CGE diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index d9aba0468e6..6ee4c6f320e 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -311,6 +311,11 @@ public: HorizLine(CGEEngine *vm); }; +class CavLight: public Sprite { +public: + CavLight(CGEEngine *vm); +}; + Dac mkDac(uint8 r, uint8 g, uint8 b); Rgb mkRgb(uint8 r, uint8 g, uint8 b); From 47b17cd1cec22dfaafe80ce23805587d3a6e4821 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 10:07:35 +1000 Subject: [PATCH 100/276] CGE: Create Spike class to encapsulate the SP spite array --- engines/cge/cge.cpp | 5 ----- engines/cge/cge_main.cpp | 1 - engines/cge/cge_main.h | 1 - engines/cge/text.cpp | 2 +- engines/cge/vga13h.cpp | 10 ++++++++++ engines/cge/vga13h.h | 6 ++++++ 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 6dbe12d9c6b..1df0165e5d8 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -69,9 +69,6 @@ void CGEEngine::setup() { Talk::init(); // Initialise sprite arrays used by game objects - SP[0] = new Bitmap("SPK_L", true); - SP[1] = new Bitmap("SPK_R", true); - SP[2] = NULL; LI[0] = new Bitmap("LITE0", true); LI[1] = new Bitmap("LITE1", true); LI[2] = new Bitmap("LITE2", true); @@ -153,8 +150,6 @@ CGEEngine::~CGEEngine() { delete _infoLine; delete _cavLight; delete _debugLine; - delete SP[0]; - delete SP[1]; delete LI[0]; delete LI[1]; delete LI[2]; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 4632caabfa2..452791b99e0 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -75,7 +75,6 @@ InfoLine *_infoLine; Sprite *_cavLight; InfoLine *_debugLine; -BMP_PTR SP[3]; BMP_PTR LI[5]; Snail *_snail; diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index d7594c94d92..9706e4c0ec7 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -180,7 +180,6 @@ extern InfoLine *_infoLine; extern Sprite *_cavLight; extern InfoLine *_debugLine; extern BMP_PTR MC[3]; -extern BMP_PTR SP[3]; extern BMP_PTR LI[5]; extern Snail *_snail; extern Snail *_snail_; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index c1d32d15cdb..63d618b5d50 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -183,7 +183,7 @@ void Text::say(const char *txt, Sprite *spr) { bool east = spr->_flags._east; int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2); int y = spr->_y + 2; - Sprite *spike = new Sprite(_vm, SP); + Sprite *spike = new Spike(_vm); uint16 sw = spike->_w; if (east) { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 1f12dd8aa92..ce4465a4165 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1380,4 +1380,14 @@ CavLight::CavLight(CGEEngine *vm): Sprite(vm, NULL) { setShapeList(PR); } +Spike::Spike(CGEEngine *vm): Sprite(vm, NULL) { + // Set the sprite list + BMP_PTR *SP = new BMP_PTR[2]; + SP[0] = new Bitmap("SPK_L", true); + SP[1] = new Bitmap("SPK_R", true); + SP[2] = NULL; + + setShapeList(SP); +} + } // End of namespace CGE diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 6ee4c6f320e..ec8b81fe0be 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -316,6 +316,12 @@ public: CavLight(CGEEngine *vm); }; +class Spike: public Sprite { +public: + Spike(CGEEngine *vm); +}; + + Dac mkDac(uint8 r, uint8 g, uint8 b); Rgb mkRgb(uint8 r, uint8 g, uint8 b); From 0bbefbef901e5bf5686f6fe0b49ebbdc9f89a3df Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 10:10:51 +1000 Subject: [PATCH 101/276] CGE: Created PocLight class to encapsulate the LI sprite array --- engines/cge/cge.cpp | 13 +------------ engines/cge/cge_main.cpp | 2 -- engines/cge/cge_main.h | 1 - engines/cge/vga13h.cpp | 12 ++++++++++++ engines/cge/vga13h.h | 5 +++++ 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 1df0165e5d8..2957ba87f1b 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -68,19 +68,12 @@ void CGEEngine::setup() { Bitmap::init(); Talk::init(); - // Initialise sprite arrays used by game objects - LI[0] = new Bitmap("LITE0", true); - LI[1] = new Bitmap("LITE1", true); - LI[2] = new Bitmap("LITE2", true); - LI[3] = new Bitmap("LITE3", true); - LI[4] = NULL; - // Initialise engine objects _text = new Text(this, progName(), 128); _vga = new Vga(M13H); _heart = new Heart; _sys = new System(this); - _pocLight = new Sprite(this, LI); + _pocLight = new PocLight(this); for (int i = 0; i < POCKET_NX; i++) _pocket[i] = new Sprite(this, NULL); _sprite = new Sprite(this, NULL); @@ -150,10 +143,6 @@ CGEEngine::~CGEEngine() { delete _infoLine; delete _cavLight; delete _debugLine; - delete LI[0]; - delete LI[1]; - delete LI[2]; - delete LI[3]; delete _text; delete _heart; delete _pocLight; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 452791b99e0..33a85ae8acf 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -75,8 +75,6 @@ InfoLine *_infoLine; Sprite *_cavLight; InfoLine *_debugLine; -BMP_PTR LI[5]; - Snail *_snail; Snail *_snail_; diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 9706e4c0ec7..8495ef8786a 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -180,7 +180,6 @@ extern InfoLine *_infoLine; extern Sprite *_cavLight; extern InfoLine *_debugLine; extern BMP_PTR MC[3]; -extern BMP_PTR LI[5]; extern Snail *_snail; extern Snail *_snail_; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index ce4465a4165..ed87da1c827 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1390,4 +1390,16 @@ Spike::Spike(CGEEngine *vm): Sprite(vm, NULL) { setShapeList(SP); } +PocLight::PocLight(CGEEngine *vm): Sprite(vm, NULL) { + // Set the sprite list + BMP_PTR *LI = new BMP_PTR[5]; + LI[0] = new Bitmap("LITE0", true); + LI[1] = new Bitmap("LITE1", true); + LI[2] = new Bitmap("LITE2", true); + LI[3] = new Bitmap("LITE3", true); + LI[4] = NULL; + + setShapeList(LI); +} + } // End of namespace CGE diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index ec8b81fe0be..003be7c8008 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -321,6 +321,11 @@ public: Spike(CGEEngine *vm); }; +class PocLight: public Sprite { +public: + PocLight(CGEEngine *vm); +}; + Dac mkDac(uint8 r, uint8 g, uint8 b); Rgb mkRgb(uint8 r, uint8 g, uint8 b); From 319ff2ca4911a68b7d21246699c31ca26b8e59a2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 10:11:50 +1000 Subject: [PATCH 102/276] CGE: Changed Sprite::contract to always destroy the sprite array --- engines/cge/vga13h.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index ed87da1c827..2530bf970a8 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -620,8 +620,7 @@ Sprite *Sprite::contract() { int i; for (i = 0; e->_shpList[i]; i++) delete e->_shpList[i]; - if (memType(e->_shpList) == NEAR_MEM) - delete[] e->_shpList; + delete[] e->_shpList; } if (memType(e->_seq) == NEAR_MEM) free(e->_seq); From 6039e8a24546d0cd58f20454ee41862908f09caf Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 10:12:46 +1000 Subject: [PATCH 103/276] CGE: Removed the definition of the now unused SavTab structure --- engines/cge/cge.h | 6 ------ engines/cge/cge_main.cpp | 1 - 2 files changed, 7 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 49f2c46e407..29a7a11b9d3 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -49,12 +49,6 @@ enum SNLIST { NEAR, TAKE }; #define POCKET_NX 8 -struct SavTab { - void *_ptr; - int32 _len; - bool _flag; -}; - class CGEEngine : public Engine { private: uint32 _lastFrame; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 33a85ae8acf..5b6a49ee4a3 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -261,7 +261,6 @@ void CGEEngine::saveSound() { void CGEEngine::saveGame(Common::WriteStream *file) { - SavTab *st; Sprite *spr; int i; From 8628b154a7cb06ec6a3a185392dc3ae8ef87ab1b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 11:40:06 +1000 Subject: [PATCH 104/276] CGE: Fixed compiler warning --- engines/cge/cge_main.h | 1 - 1 file changed, 1 deletion(-) diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 8495ef8786a..a60ba0515ea 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -179,7 +179,6 @@ extern HorizLine *_horzLine; extern InfoLine *_infoLine; extern Sprite *_cavLight; extern InfoLine *_debugLine; -extern BMP_PTR MC[3]; extern Snail *_snail; extern Snail *_snail_; From ef83c248d386ec75b4e3ddf3d1178e82a38b6b76 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 11:45:17 +1000 Subject: [PATCH 105/276] CGE: Added extra event processing call to fix non-responsiveness when running under Valgrind --- engines/cge/cge_main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 5b6a49ee4a3..c800d242aeb 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1524,6 +1524,9 @@ void CGEEngine::mainLoop() { // Dispatch the tick to any active objects tick(); + + // Handle any pending events + _eventManager->poll(); } void CGEEngine::tick() { From 1870f09d3131ea6b9e2646343e5191cda614b49b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 14:51:22 +1000 Subject: [PATCH 106/276] CGE: Fix several allocation mismatches and Valgrind issues --- engines/cge/cge_main.cpp | 4 +++- engines/cge/events.cpp | 2 +- engines/cge/talk.cpp | 15 ++++++++++++--- engines/cge/talk.h | 2 +- engines/cge/vga13h.cpp | 2 +- engines/cge/vmenu.cpp | 4 ++++ 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index c800d242aeb..a4d110eac6e 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1715,7 +1715,9 @@ bool CGEEngine::showTitle(const char *name) { return false; Bitmap::_pal = Vga::_sysPal; - BMP_PTR LB[] = { new Bitmap(name, true), NULL }; + BMP_PTR *LB = new BMP_PTR[2]; + LB[0] = new Bitmap(name, true); + LB[1] = NULL; Bitmap::_pal = NULL; bool usr_ok = false; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 6168dd15a8f..71110c4067e 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -154,7 +154,7 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) _buttons = 0; _busy = NULL; _active = false; - + _flags._kill = true; setSeq(ms); BMP_PTR *MC = new BMP_PTR[3]; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index f41e31dce69..b6f276c4526 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -99,7 +99,8 @@ void Font::save() { Talk::Talk(CGEEngine *vm, const char *tx, TBOX_STYLE mode) : Sprite(vm, NULL), _mode(mode), _vm(vm) { - _ts[0] = _ts[1] = NULL; + + _ts = NULL; _flags._syst = true; update(tx); } @@ -107,7 +108,7 @@ Talk::Talk(CGEEngine *vm, const char *tx, TBOX_STYLE mode) Talk::Talk(CGEEngine *vm) : Sprite(vm, NULL), _mode(PURE), _vm(vm) { - _ts[0] = _ts[1] = NULL; + _ts = NULL; _flags._syst = true; } @@ -141,7 +142,7 @@ void Talk::update(const char *tx) { const char *p; uint8 *m; - if (!_ts[0]) { + if (!_ts) { uint16 k = 2 * hmarg; mh = 2 * vmarg + FONT_HIG; for (p = tx; *p; p++) { @@ -155,7 +156,10 @@ void Talk::update(const char *tx) { } if (k > mw) mw = k; + + _ts = new BMP_PTR[2]; _ts[0] = box(mw, mh); + _ts[1] = NULL; } m = _ts[0]->_m + ln * mw + hmarg; @@ -286,6 +290,11 @@ void Talk::putLine(int line, const char *text) { InfoLine::InfoLine(CGEEngine *vm, uint16 w) : Talk(vm), _oldTxt(NULL), _vm(vm) { + if (!_ts) { + _ts = new BMP_PTR[2]; + _ts[1] = NULL; + } + _ts[0] = new Bitmap(w, FONT_HIG, TEXT_BG); setShapeList(_ts); } diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 2f704713593..4d30047ea14 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -71,7 +71,7 @@ enum TBOX_STYLE { PURE, RECT, ROUND }; class Talk : public Sprite { protected: TBOX_STYLE _mode; - Bitmap *_ts[2]; + BMP_PTR *_ts; Bitmap *box(uint16 w, uint16 h); public: Talk(CGEEngine *vm, const char *tx, TBOX_STYLE mode); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 2530bf970a8..6e0493695a6 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -619,7 +619,7 @@ Sprite *Sprite::contract() { if (_flags._bDel && e->_shpList) { int i; for (i = 0; e->_shpList[i]; i++) - delete e->_shpList[i]; + delete e->_shpList[i]; delete[] e->_shpList; } if (memType(e->_seq) == NEAR_MEM) diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 8fef6307b14..f8029166572 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -59,8 +59,12 @@ MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { p1 += w; p2 -= w; } + + _ts = new BMP_PTR[2]; _ts[0] = new Bitmap(w, h, p); + _ts[1] = NULL; setShapeList(_ts); + _flags._slav = true; _flags._tran = true; _flags._kill = true; From 88c7b25e5b0cdf8bb0709f0f7e728f637e72b33c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 17:56:29 +1000 Subject: [PATCH 107/276] CGE: Fixed more free/delete[] mismatches identified by Valgrind --- engines/cge/bitmap.cpp | 8 ++++---- engines/cge/cge.cpp | 4 ++-- engines/cge/events.cpp | 2 +- engines/cge/vga13h.cpp | 16 ++++++++++++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 4630f874563..a8264e6c3fa 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -151,7 +151,7 @@ Bitmap::~Bitmap() { delete[](uint8 *) _v; break; case FAR_MEM : - free(_v); + delete[] _v; default: warning("Unhandled MemType in Bitmap destructor"); break; @@ -206,7 +206,7 @@ BMP_PTR Bitmap::code() { delete[](uint8 *) _v; break; case FAR_MEM : - free(_v); + delete[] _v; break; default: warning("Unhandled MemType in Bitmap::Code()"); @@ -294,7 +294,7 @@ BMP_PTR Bitmap::code() { break; uint16 sizV = (uint16)(im - 2 - _v); - _v = farnew(uint8, sizV + _h * sizeof(*_b)); + _v = new uint8[sizV + _h * sizeof(*_b)]; if (!_v) error("No core"); @@ -436,7 +436,7 @@ bool Bitmap::loadVBM(XFile *f) { f->seek(f->mark() + PAL_SIZ); } } - if ((_v = farnew(uint8, n)) == NULL) + if ((_v = new uint8[n]) == NULL) return false; if (f->_error == 0) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 2957ba87f1b..731f92854ef 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -136,6 +136,8 @@ CGEEngine::~CGEEngine() { delete _console; // Delete engine objects + delete _vga; + delete _sys; delete _sprite; delete _miniCave; delete _shadow; @@ -153,8 +155,6 @@ CGEEngine::~CGEEngine() { delete _snail; delete _snail_; delete _hero; - delete _vga; - delete _sys; } Common::Error CGEEngine::run() { diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 71110c4067e..e12031bb38d 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -154,7 +154,7 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) _buttons = 0; _busy = NULL; _active = false; - _flags._kill = true; + _flags._kill = false; setSeq(ms); BMP_PTR *MC = new BMP_PTR[3]; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 6e0493695a6..73a753b6008 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -356,12 +356,14 @@ Sprite::Sprite(CGEEngine *vm, BMP_PTR *shpP) _seqPtr = 0; _shpCnt = 0; _prev = _next = NULL; - +static int ctr = 1; +debug("create %d %x", ctr++, this); setShapeList(shpP); } Sprite::~Sprite() { +debug("destroy %x", this); if (_sprite == this) _sprite = NULL; contract(); @@ -775,7 +777,7 @@ BMP_PTR Sprite::ghost() { error("No core"); bmp->_w = e->_b1->_w; bmp->_h = e->_b1->_h; - if ((bmp->_b = farnew(HideDesc, bmp->_h)) == NULL) + if ((bmp->_b = new HideDesc[bmp->_h]) == NULL) error("No Core"); bmp->_v = (uint8 *) memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc) * bmp->_h); // TODO offset correctly in the surface using y1 pitch and x1 and not via offset segment @@ -903,8 +905,18 @@ void Queue::insert(Sprite *spr) { spr->contract(); } +template +inline bool contains(const Common::List &l, const T &v) { + return (Common::find(l.begin(), l.end(), v) != l.end()); +} +Common::List l; Sprite *Queue::remove(Sprite *spr) { + if (contains(l, spr)) { + debug("N"); + } + l.push_back(spr); + if (spr == _head) _head = spr->_next; if (spr == _tail) From 32c8962d62162e79f5c27fbf2b5bbc843be4ad92 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 17:58:39 +1000 Subject: [PATCH 108/276] CGE: Removed some accidentally added debugging statements --- engines/cge/vga13h.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 73a753b6008..526faed5662 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -356,14 +356,12 @@ Sprite::Sprite(CGEEngine *vm, BMP_PTR *shpP) _seqPtr = 0; _shpCnt = 0; _prev = _next = NULL; -static int ctr = 1; -debug("create %d %x", ctr++, this); + setShapeList(shpP); } Sprite::~Sprite() { -debug("destroy %x", this); if (_sprite == this) _sprite = NULL; contract(); From 66c7777dfedd4ec7a251b4a47e9b581a3e7570d4 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 18:17:40 +1000 Subject: [PATCH 109/276] CGE: Fix Valgrind identified errors --- engines/cge/vga13h.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 526faed5662..9498b04e8c5 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -362,8 +362,6 @@ Sprite::Sprite(CGEEngine *vm, BMP_PTR *shpP) Sprite::~Sprite() { - if (_sprite == this) - _sprite = NULL; contract(); } @@ -405,6 +403,7 @@ BMP_PTR *Sprite::setShapeList(BMP_PTR *shpP) { } expand(); _ext->_shpList = shpP; + _flags._bDel = true; if (!_ext->_seq) setSeq((_shpCnt < 2) ? _seq1 : _seq2); } @@ -907,14 +906,8 @@ template inline bool contains(const Common::List &l, const T &v) { return (Common::find(l.begin(), l.end(), v) != l.end()); } -Common::List l; Sprite *Queue::remove(Sprite *spr) { - if (contains(l, spr)) { - debug("N"); - } - l.push_back(spr); - if (spr == _head) _head = spr->_next; if (spr == _tail) From a693ff2ecfa960b25ac33a936ef8b7b6055e68ae Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 19:23:14 +1000 Subject: [PATCH 110/276] CGE: A few more fixes for memory leaks identified by Valgrind --- engines/cge/cge.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 731f92854ef..55b79d5b35d 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -78,7 +78,9 @@ void CGEEngine::setup() { _pocket[i] = new Sprite(this, NULL); _sprite = new Sprite(this, NULL); _miniCave = new Sprite(this, NULL); + _miniCave->_flags._kill = false; _shadow = new Sprite(this, NULL); + _shadow->_flags._kill = false; _horzLine = new HorizLine(this); _infoLine = new InfoLine(this, INFO_W); _cavLight = new CavLight(this); @@ -138,7 +140,7 @@ CGEEngine::~CGEEngine() { // Delete engine objects delete _vga; delete _sys; - delete _sprite; + //delete _sprite; Sprite is destroyed by the queue it's added to delete _miniCave; delete _shadow; delete _horzLine; From 9efefdbced8af533e09f7cba703ccbe31dfa6f80 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 20:02:17 +1000 Subject: [PATCH 111/276] CGE: Fixed the display of text in the name entry dialog Whilst the 'melting' effect of entered text was very amusing, it did need to be fixed. --- engines/cge/talk.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index b6f276c4526..146c7206678 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -249,16 +249,14 @@ void Talk::putLine(int line, const char *text) { // set desired line pointer v += (TEXT_VM + (FONT_HIG + TEXT_LS) * line) * lsiz; + p = v; // assume blanked line above text // clear whole rectangle - p = v; // assume blanked line above text - memmove(p, p - lsiz, rsiz); - p += psiz; // tricky replicate lines for plane 0 - memmove(p, p - lsiz, rsiz); - p += psiz; // same for plane 1 - memmove(p, p - lsiz, rsiz); - p += psiz; // same for plane 2 - memmove(p, p - lsiz, rsiz); + assert((rsiz % lsiz) == 0); + for (int planeCtr = 0; planeCtr < 4; ++planeCtr, p += psiz) { + for (byte *pDest = p; pDest < (p + (rsiz - lsiz)); pDest += lsiz) + Common::copy(p - lsiz, p, pDest); + } // paint text line if (text) { From f33ac85e795a0f5abba29bcca365315f3b343310 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 20:07:45 +1000 Subject: [PATCH 112/276] CGE: Bugfixes for some crashes --- engines/cge/gettext.cpp | 4 ++++ engines/cge/vga13h.cpp | 2 ++ 2 files changed, 6 insertions(+) diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 2ee6dc42eb2..f5c62809dbd 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -40,8 +40,12 @@ GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) int i = 2 * TEXT_HM + _font->width(info); _ptr = this; _mode = RECT; + + _ts = new BMP_PTR[2]; _ts[0] = box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); + _ts[1] = NULL; setShapeList(_ts); + _flags._bDel = true; _flags._kill = true; memcpy(_buff, text, _len); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 9498b04e8c5..d92b9e97f07 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1402,6 +1402,8 @@ PocLight::PocLight(CGEEngine *vm): Sprite(vm, NULL) { LI[4] = NULL; setShapeList(LI); + + _flags._kill = false; } } // End of namespace CGE From 9b5b88274e4d0f76b280133624343f8ce7222937 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 20:13:11 +1000 Subject: [PATCH 113/276] CGE: Bugfix for correctly flagging key release --- engines/cge/events.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index e12031bb38d..433f7c6db93 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -123,7 +123,7 @@ void Keyboard::newKeyboard(Common::Event &event) { if (event.type == Common::EVENT_KEYUP) { // Key release - _key[event.kbd.keycode] = false; + _key[keycode] = false; } else if (event.type == Common::EVENT_KEYDOWN) { // Key press _key[keycode] = true; From c3a4ba8b053b93a3f759af2a77922a886bba986e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 20:28:22 +1000 Subject: [PATCH 114/276] CGE: More fixes for free/delete[] mismatches --- engines/cge/cge_main.cpp | 2 +- engines/cge/game.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index a4d110eac6e..68a69ff64e0 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -214,7 +214,7 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { // Read the data into a data buffer int size = file.size() - file.mark(); - byte *dataBuffer = new byte[size]; + byte *dataBuffer = (byte *)malloc(size); file.read(dataBuffer, size); Common::MemoryReadStream readStream(dataBuffer, size, DisposeAfterUse::YES); Common::Serializer s(&readStream, NULL); diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index f2ebc0b4f80..18c4efbe009 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -31,7 +31,7 @@ namespace CGE { uint8 *glass(Dac *pal, uint8 r, uint8 g, uint8 b) { - uint8 *x = new uint8[256]; + uint8 *x = (uint8 *)malloc(256); if (x) { uint16 i; for (i = 0; i < 256; i++) { From 10ca53a00c3ae13c520dbf871bb7f6ec65318706 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 10 Jul 2011 21:07:57 +1000 Subject: [PATCH 115/276] CGE: Fix cursor to show on-screen once the game starts --- engines/cge/cge_main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 68a69ff64e0..4c20f31cacc 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1594,8 +1594,7 @@ void CGEEngine::runGame() { _vga->_showQ->append(_pocLight); selectPocket(-1); - // FIXME: Allow ScummVM to handle mouse display -// Vga->ShowQ->Append(Mouse); + _vga->_showQ->append(_mouse); // ___________ loadUser(); From 18077762d738178795c99d38010052b95cb1cef5 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 11 Jul 2011 20:37:37 +1000 Subject: [PATCH 116/276] CGE: Standardised Sprite::seq on always allocating/freeing data --- engines/cge/cge_main.cpp | 5 ++++- engines/cge/events.cpp | 14 ++++++++------ engines/cge/talk.cpp | 7 ++++++- engines/cge/vga13h.cpp | 29 ++++++++++++++++++++++------- engines/cge/vga13h.h | 2 ++ 5 files changed, 42 insertions(+), 15 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 4c20f31cacc..76d1b7dbcda 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1587,7 +1587,10 @@ void CGEEngine::runGame() { { 1, 6, 0, 0, 4 }, { 0, 1, 0, 0, 16 }, }; - _pocLight->setSeq(pocSeq); + Seq *seq = (Seq *)malloc(7 * sizeof(Seq)); + Common::copy(&pocSeq[0], &pocSeq[7], seq); + _pocLight->setSeq(seq); + _pocLight->_flags._tran = true; _pocLight->_time = 1; _pocLight->_z = 120; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 433f7c6db93..0bf5191530e 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -142,11 +142,6 @@ void Keyboard::newKeyboard(Common::Event &event) { /*----------------- MOUSE interface -----------------*/ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { - static Seq ms[] = { - { 0, 0, 0, 0, 1 }, - { 1, 1, 0, 0, 1 } - }; - _hold = NULL; _hx = 0; _hy = 0; @@ -155,7 +150,14 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) _busy = NULL; _active = false; _flags._kill = false; - setSeq(ms); + + static Seq ms[] = { + { 0, 0, 0, 0, 1 }, + { 1, 1, 0, 0, 1 } + }; + Seq *seq = (Seq *)malloc(2 * sizeof(Seq)); + Common::copy(&ms[0], &ms[2], seq); + setSeq(seq); BMP_PTR *MC = new BMP_PTR[3]; MC[0] = new Bitmap("MOUSE", true); diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 146c7206678..152f4a71239 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -310,7 +310,12 @@ void InfoLine::update(const char *tx) { // clear whole rectangle memset(v + 2, TEXT_BG, dsiz); // data bytes - memmove(v + lsiz, v, psiz - lsiz); + + for (byte *pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz) + *pDest = 0; +// Common::set_to(pDest, pDest + lsiz, 0); + //Common::copy(v, v + lsiz, pDest); + *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 memmove(v + psiz, v, 3 * psiz); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d92b9e97f07..ff21f5cce80 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -60,8 +60,6 @@ static VgaRegBlk VideoMode[] = { }; bool SpeedTest = false; -Seq _seq1[] = { { 0, 0, 0, 0, 0 } }; -Seq _seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; extern "C" void SNDMIDIPlay(); @@ -383,6 +381,23 @@ BMP_PTR Sprite::shp() { return NULL; } +Seq *Sprite::getConstantSeq(bool seqFlag) { + Seq seq1[] = { { 0, 0, 0, 0, 0 } }; + Seq seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; + + // Make a copy of the given seq list and return it + Seq *seq; + if (seqFlag) { + seq = (Seq *)malloc(sizeof(Seq)); + seq[0] = seq1[0]; + } else { + seq = (Seq *)malloc(2 * sizeof(Seq)); + seq[0] = seq2[0]; + seq[1] = seq2[1]; + } + + return seq; +} BMP_PTR *Sprite::setShapeList(BMP_PTR *shpP) { BMP_PTR *r = (_ext) ? _ext->_shpList : NULL; @@ -405,7 +420,7 @@ BMP_PTR *Sprite::setShapeList(BMP_PTR *shpP) { _ext->_shpList = shpP; _flags._bDel = true; if (!_ext->_seq) - setSeq((_shpCnt < 2) ? _seq1 : _seq2); + setSeq(getConstantSeq(_shpCnt < 2)); } return r; } @@ -590,7 +605,7 @@ Sprite *Sprite::expand() { error("Bad JUMP in SEQ [%s]", fname); setSeq(seq); } else - setSeq((_shpCnt == 1) ? _seq1 : _seq2); + setSeq(getConstantSeq(_shpCnt == 1)); //disable(); // disable interupt setShapeList(shplist); @@ -621,8 +636,8 @@ Sprite *Sprite::contract() { delete e->_shpList[i]; delete[] e->_shpList; } - if (memType(e->_seq) == NEAR_MEM) - free(e->_seq); + free(e->_seq); + if (e->_near) free(e->_near); if (e->_take) @@ -1384,7 +1399,7 @@ CavLight::CavLight(CGEEngine *vm): Sprite(vm, NULL) { Spike::Spike(CGEEngine *vm): Sprite(vm, NULL) { // Set the sprite list - BMP_PTR *SP = new BMP_PTR[2]; + BMP_PTR *SP = new BMP_PTR[3]; SP[0] = new Bitmap("SPK_L", true); SP[1] = new Bitmap("SPK_R", true); SP[2] = NULL; diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 003be7c8008..177165689ef 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -166,6 +166,8 @@ public: class Sprite { +private: + Seq *getConstantSeq(bool seqFlag); protected: SprExt *_ext; public: From 9ba5e2b304e6ba7ca9d0b782ad8e5dfd98317b02 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 11 Jul 2011 20:56:32 +1000 Subject: [PATCH 117/276] CGE: Reverted last commit due to extra memory leaks --- engines/cge/cge_main.cpp | 5 +---- engines/cge/events.cpp | 14 ++++++-------- engines/cge/talk.cpp | 7 +------ engines/cge/vga13h.cpp | 29 +++++++---------------------- engines/cge/vga13h.h | 2 -- 5 files changed, 15 insertions(+), 42 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 76d1b7dbcda..4c20f31cacc 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1587,10 +1587,7 @@ void CGEEngine::runGame() { { 1, 6, 0, 0, 4 }, { 0, 1, 0, 0, 16 }, }; - Seq *seq = (Seq *)malloc(7 * sizeof(Seq)); - Common::copy(&pocSeq[0], &pocSeq[7], seq); - _pocLight->setSeq(seq); - + _pocLight->setSeq(pocSeq); _pocLight->_flags._tran = true; _pocLight->_time = 1; _pocLight->_z = 120; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 0bf5191530e..433f7c6db93 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -142,6 +142,11 @@ void Keyboard::newKeyboard(Common::Event &event) { /*----------------- MOUSE interface -----------------*/ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { + static Seq ms[] = { + { 0, 0, 0, 0, 1 }, + { 1, 1, 0, 0, 1 } + }; + _hold = NULL; _hx = 0; _hy = 0; @@ -150,14 +155,7 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) _busy = NULL; _active = false; _flags._kill = false; - - static Seq ms[] = { - { 0, 0, 0, 0, 1 }, - { 1, 1, 0, 0, 1 } - }; - Seq *seq = (Seq *)malloc(2 * sizeof(Seq)); - Common::copy(&ms[0], &ms[2], seq); - setSeq(seq); + setSeq(ms); BMP_PTR *MC = new BMP_PTR[3]; MC[0] = new Bitmap("MOUSE", true); diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 152f4a71239..146c7206678 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -310,12 +310,7 @@ void InfoLine::update(const char *tx) { // clear whole rectangle memset(v + 2, TEXT_BG, dsiz); // data bytes - - for (byte *pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz) - *pDest = 0; -// Common::set_to(pDest, pDest + lsiz, 0); - //Common::copy(v, v + lsiz, pDest); - + memmove(v + lsiz, v, psiz - lsiz); *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 memmove(v + psiz, v, 3 * psiz); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index ff21f5cce80..d92b9e97f07 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -60,6 +60,8 @@ static VgaRegBlk VideoMode[] = { }; bool SpeedTest = false; +Seq _seq1[] = { { 0, 0, 0, 0, 0 } }; +Seq _seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; extern "C" void SNDMIDIPlay(); @@ -381,23 +383,6 @@ BMP_PTR Sprite::shp() { return NULL; } -Seq *Sprite::getConstantSeq(bool seqFlag) { - Seq seq1[] = { { 0, 0, 0, 0, 0 } }; - Seq seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; - - // Make a copy of the given seq list and return it - Seq *seq; - if (seqFlag) { - seq = (Seq *)malloc(sizeof(Seq)); - seq[0] = seq1[0]; - } else { - seq = (Seq *)malloc(2 * sizeof(Seq)); - seq[0] = seq2[0]; - seq[1] = seq2[1]; - } - - return seq; -} BMP_PTR *Sprite::setShapeList(BMP_PTR *shpP) { BMP_PTR *r = (_ext) ? _ext->_shpList : NULL; @@ -420,7 +405,7 @@ BMP_PTR *Sprite::setShapeList(BMP_PTR *shpP) { _ext->_shpList = shpP; _flags._bDel = true; if (!_ext->_seq) - setSeq(getConstantSeq(_shpCnt < 2)); + setSeq((_shpCnt < 2) ? _seq1 : _seq2); } return r; } @@ -605,7 +590,7 @@ Sprite *Sprite::expand() { error("Bad JUMP in SEQ [%s]", fname); setSeq(seq); } else - setSeq(getConstantSeq(_shpCnt == 1)); + setSeq((_shpCnt == 1) ? _seq1 : _seq2); //disable(); // disable interupt setShapeList(shplist); @@ -636,8 +621,8 @@ Sprite *Sprite::contract() { delete e->_shpList[i]; delete[] e->_shpList; } - free(e->_seq); - + if (memType(e->_seq) == NEAR_MEM) + free(e->_seq); if (e->_near) free(e->_near); if (e->_take) @@ -1399,7 +1384,7 @@ CavLight::CavLight(CGEEngine *vm): Sprite(vm, NULL) { Spike::Spike(CGEEngine *vm): Sprite(vm, NULL) { // Set the sprite list - BMP_PTR *SP = new BMP_PTR[3]; + BMP_PTR *SP = new BMP_PTR[2]; SP[0] = new Bitmap("SPK_L", true); SP[1] = new Bitmap("SPK_R", true); SP[2] = NULL; diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 177165689ef..003be7c8008 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -166,8 +166,6 @@ public: class Sprite { -private: - Seq *getConstantSeq(bool seqFlag); protected: SprExt *_ext; public: From dab96401ad352512a8ffa8c1d7baeb431ade7b8c Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 12 Jul 2011 07:24:20 +0200 Subject: [PATCH 118/276] CGE: Implement snGhost by splitting _m field in two. Some cleanup. --- engines/cge/bitmap.cpp | 317 +++++++++++++++++++---------------------- engines/cge/bitmap.h | 9 +- engines/cge/general.h | 15 +- engines/cge/snail.cpp | 5 +- engines/cge/vga13h.cpp | 25 +--- engines/cge/vga13h.h | 8 -- 6 files changed, 167 insertions(+), 212 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index a8264e6c3fa..48bfe1fafbb 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -46,7 +46,7 @@ void Bitmap::deinit() { } #pragma argsused -Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { +Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { char pat[MAXPATH]; forceExt(pat, fname, ".VBM"); @@ -78,7 +78,7 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL) { } -Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL) { +Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL), _map(0) { if (map) code(); } @@ -90,7 +90,8 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL) Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) : _w((w + 3) & ~3), // only full uint32 allowed! _h(h), - _m(NULL) { + _m(NULL), + _map(0) { uint16 dsiz = _w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap uint16 psiz = _h * lsiz; // - last gape, but + plane trailer @@ -128,7 +129,7 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) } -Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL) { +Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), _map(0) { uint8 *v0 = bmp._v; if (v0) { uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); @@ -143,20 +144,9 @@ Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL) { Bitmap::~Bitmap() { - if (memType(_m) == FAR_MEM) + if (_m) free(_m); - - switch (memType(_v)) { - case NEAR_MEM : - delete[](uint8 *) _v; - break; - case FAR_MEM : - delete[] _v; - default: - warning("Unhandled MemType in Bitmap destructor"); - break; - break; - } + delete[] _v; } @@ -165,6 +155,7 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { _w = bmp._w; _h = bmp._h; _m = NULL; + _map = 0; if (memType(_v) == FAR_MEM) free(_v); if (v0 == NULL) @@ -197,128 +188,120 @@ uint16 Bitmap::moveVmap(uint8 *buf) { BMP_PTR Bitmap::code() { - if (_m) { - uint16 i, cnt; + if (!_m) + return false; - if (_v) { // old X-map exists, so remove it - switch (memType(_v)) { - case NEAR_MEM : - delete[](uint8 *) _v; - break; - case FAR_MEM : - delete[] _v; - break; - default: - warning("Unhandled MemType in Bitmap::Code()"); - break; + uint16 i, cnt; + + if (_v) { // old X-map exists, so remove it + delete[] _v; + _v = NULL; + } + + while (true) { // at most 2 times: for (V == NULL) & for allocated block; + uint8 *im = _v + 2; + uint16 *cp = (uint16 *) _v; + int bpl; + + if (_v) { // 2nd pass - fill the hide table + for (i = 0; i < _h; i++) { + _b[i].skip = 0xFFFF; + _b[i].hide = 0x0000; } - _v = NULL; } + for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane + uint8 *bm = _m; + bool skip = (bm[bpl] == TRANS); + uint16 j; - while (true) { // at most 2 times: for (V == NULL) & for allocated block; - uint8 *im = _v + 2; - uint16 *cp = (uint16 *) _v; - int bpl; + cnt = 0; + for (i = 0; i < _h; i++) { // once per each line + uint8 pix; + for (j = bpl; j < _w; j += 4) { + pix = bm[j]; + if (_v && pix != TRANS) { + if (j < _b[i].skip) + _b[i].skip = j; - if (_v) { // 2nd pass - fill the hide table - for (i = 0; i < _h; i++) { - _b[i].skip = 0xFFFF; - _b[i].hide = 0x0000; + if (j >= _b[i].hide) + _b[i].hide = j + 1; + } + if ((pix == TRANS) != skip || cnt >= 0x3FF0) { // end of block + cnt |= (skip) ? SKP : CPY; + if (_v) + *cp = cnt; // store block description uint16 + + cp = (uint16 *) im; + im += 2; + skip = (pix == TRANS); + cnt = 0; + } + if (! skip) { + if (_v) + *im = pix; + ++ im; + } + ++ cnt; + } + + bm += _w; + if (_w < SCR_WID) { + if (skip) { + cnt += (SCR_WID - j + 3) / 4; + } else { + cnt |= CPY; + if (_v) + *cp = cnt; + + cp = (uint16 *) im; + im += 2; + skip = true; + cnt = (SCR_WID - j + 3) / 4; + } } } - for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane - uint8 *bm = _m; - bool skip = (bm[bpl] == TRANS); - uint16 j; - - cnt = 0; - for (i = 0; i < _h; i++) { // once per each line - uint8 pix; - for (j = bpl; j < _w; j += 4) { - pix = bm[j]; - if (_v && pix != TRANS) { - if (j < _b[i].skip) - _b[i].skip = j; - - if (j >= _b[i].hide) - _b[i].hide = j + 1; - } - if ((pix == TRANS) != skip || cnt >= 0x3FF0) { // end of block - cnt |= (skip) ? SKP : CPY; - if (_v) - *cp = cnt; // store block description uint16 - - cp = (uint16 *) im; - im += 2; - skip = (pix == TRANS); - cnt = 0; - } - if (! skip) { - if (_v) - *im = pix; - ++ im; - } - ++ cnt; - } - - bm += _w; - if (_w < SCR_WID) { - if (skip) { - cnt += (SCR_WID - j + 3) / 4; - } else { - cnt |= CPY; - if (_v) - *cp = cnt; - - cp = (uint16 *) im; - im += 2; - skip = true; - cnt = (SCR_WID - j + 3) / 4; - } - } - } - if (cnt && ! skip) { - cnt |= CPY; - if (_v) - *cp = cnt; - - cp = (uint16 *) im; - im += 2; - } + if (cnt && ! skip) { + cnt |= CPY; if (_v) - *cp = EOI; + *cp = cnt; + cp = (uint16 *) im; im += 2; } if (_v) - break; - - uint16 sizV = (uint16)(im - 2 - _v); - _v = new uint8[sizV + _h * sizeof(*_b)]; - if (!_v) - error("No core"); - - _b = (HideDesc *)(_v + sizV); + *cp = EOI; + cp = (uint16 *) im; + im += 2; } - cnt = 0; - for (i = 0; i < _h; i++) { - if (_b[i].skip == 0xFFFF) { // whole line is skipped - _b[i].skip = (cnt + SCR_WID) >> 2; - cnt = 0; - } else { - uint16 s = _b[i].skip & ~3; - uint16 h = (_b[i].hide + 3) & ~3; - _b[i].skip = (cnt + s) >> 2; - _b[i].hide = (h - s) >> 2; - cnt = SCR_WID - h; - } + if (_v) + break; + + uint16 sizV = (uint16)(im - 2 - _v); + _v = new uint8[sizV + _h * sizeof(*_b)]; + if (!_v) + error("No core"); + + _b = (HideDesc *)(_v + sizV); + } + cnt = 0; + for (i = 0; i < _h; i++) { + if (_b[i].skip == 0xFFFF) { // whole line is skipped + _b[i].skip = (cnt + SCR_WID) >> 2; + cnt = 0; + } else { + uint16 s = _b[i].skip & ~3; + uint16 h = (_b[i].hide + 3) & ~3; + _b[i].skip = (cnt + s) >> 2; + _b[i].hide = (h - s) >> 2; + cnt = SCR_WID - h; } } + return this; } -bool Bitmap::solidAt(int x, int y) { +bool Bitmap::solidAt(int16 x, int16 y) { uint8 *m; uint16 r, n, n0; @@ -447,58 +430,58 @@ bool Bitmap::loadVBM(XFile *f) { } bool Bitmap::loadBMP(XFile *f) { - struct { - char BM[2]; - union { int16 len; int32 len_; }; - union { int16 _06; int32 _06_; }; - union { int16 hdr; int32 hdr_; }; - union { int16 _0E; int32 _0E_; }; - union { int16 wid; int32 wid_; }; - union { int16 hig; int32 hig_; }; - union { int16 _1A; int32 _1A_; }; - union { int16 _1E; int32 _1E_; }; - union { int16 _22; int32 _22_; }; - union { int16 _26; int32 _26_; }; - union { int16 _2A; int32 _2A_; }; - union { int16 _2E; int32 _2E_; }; - union { int16 _32; int32 _32_; }; - } hea; + struct { + char BM[2]; + union { int16 len; int32 len_; }; + union { int16 _06; int32 _06_; }; + union { int16 hdr; int32 hdr_; }; + union { int16 _0E; int32 _0E_; }; + union { int16 wid; int32 wid_; }; + union { int16 hig; int32 hig_; }; + union { int16 _1A; int32 _1A_; }; + union { int16 _1E; int32 _1E_; }; + union { int16 _22; int32 _22_; }; + union { int16 _26; int32 _26_; }; + union { int16 _2A; int32 _2A_; }; + union { int16 _2E; int32 _2E_; }; + union { int16 _32; int32 _32_; }; + } hea; - Bgr4 bpal[256]; + Bgr4 bpal[256]; - f->read((byte *)&hea, sizeof(hea)); - if (f->_error == 0) { - if (hea.hdr == 0x436L) { - int16 i = (hea.hdr - sizeof(hea)) / sizeof(Bgr4); - f->read((byte *)&bpal, sizeof(bpal)); - if (f->_error == 0) { - if (_pal) { - for (i = 0; i < 256; i ++) { - _pal[i]._r = bpal[i]._R; - _pal[i]._g = bpal[i]._G; - _pal[i]._b = bpal[i]._B; + f->read((byte *)&hea, sizeof(hea)); + if (f->_error == 0) { + if (hea.hdr == 0x436L) { + int16 i = (hea.hdr - sizeof(hea)) / sizeof(Bgr4); + f->read((byte *)&bpal, sizeof(bpal)); + if (f->_error == 0) { + if (_pal) { + for (i = 0; i < 256; i ++) { + _pal[i]._r = bpal[i]._R; + _pal[i]._g = bpal[i]._G; + _pal[i]._b = bpal[i]._B; + } + _pal = NULL; + } + _h = hea.hig; + _w = hea.wid; + if ((_m = farnew(byte, _h * _w)) != NULL) { + int16 r = (4 - (hea.wid & 3)) % 4; + byte buf[3]; + for (i = _h - 1; i >= 0; i--) { + f->read(_m + (_w * i), _w); + if (r && f->_error == 0) + f->read(buf, r); + if (f->_error) + break; + } + if (i < 0) + return true; + } } - _pal = NULL; } - _h = hea.hig; - _w = hea.wid; - if ((_m = farnew(byte, _h * _w)) != NULL) { - int16 r = (4 - (hea.wid & 3)) % 4; - byte buf[3]; - for (i = _h - 1; i >= 0; i--) { - f->read(_m + (_w * i), _w); - if (r && f->_error == 0) - f->read(buf, r); - if (f->_error) - break; - } - if (i < 0) - return true; - } - } } - } - return false; + return false; } } // End of namespace CGE diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 4c2b67b8dfd..3fdb673396b 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -68,6 +68,7 @@ public: uint16 _h; uint8 *_m; uint8 *_v; + int32 _map; HideDesc *_b; Bitmap(const char *fname, bool rem); @@ -81,10 +82,10 @@ public: Bitmap *flipH(); Bitmap *code(); Bitmap &operator = (const Bitmap &bmp); - void hide(int x, int y); - void show(int x, int y); - void xShow(int x, int y); - bool solidAt(int x, int y); + void hide(int16 x, int16 y); + void show(int16 x, int16 y); + void xShow(int16 x, int16 y); + bool solidAt(int16 x, int16 y); bool saveVBM(XFile *f); uint16 moveVmap(uint8 *buf); }; diff --git a/engines/cge/general.h b/engines/cge/general.h index 7cf3ec3e419..2eebc01c62f 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -39,22 +39,13 @@ namespace CGE { #define SEED 0xA5 -#define SCR_WID_ 320 -#define SCR_HIG_ 200 -#define SCR_WID ((uint16)SCR_WID_) -#define SCR_HIG ((uint16)SCR_HIG_) -#define SCR_SEG 0xA000 -#define SCR_ADR ((uint8 *) MK_FP(SCR_SEG, 0)) - - - -//enum CPU { _8086, _80186, _80286, _80386, _80486 }; enum MEM_TYPE { BAD_MEM, EMS_MEM, NEAR_MEM, FAR_MEM }; -enum ALLOC_MODE { FIRST_FIT, BEST_FIT, LAST_FIT }; enum IOMODE { REA, WRI, UPD }; struct Dac { - uint8 _r, _g, _b; + uint8 _r; + uint8 _g; + uint8 _b; }; typedef uint16 CRYPT(void *buf, uint16 siz, uint16 seed); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 242fb067e7a..bc9d2124688 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -309,11 +309,10 @@ void CGEEngine::hide1(Sprite *spr) { } void CGEEngine::snGhost(Bitmap *bmp) { - // TODO : Get x and y from M but not using segment / offset - //bmp->Hide(FP_OFF(bmp->_m), FP_SEG(bmp->_m)); + bmp->hide(bmp->_map & 0xFFFF, bmp->_map >> 16); bmp->_m = NULL; + bmp->_map = 0; delete bmp; - warning("STUB: SNGhost"); } void CGEEngine::feedSnail(Sprite *spr, SNLIST snq) { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d92b9e97f07..e85e13d20c9 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -683,18 +683,9 @@ void Sprite::killXlat() { if (_flags._xlat && _ext) { BMP_PTR *b; uint8 *m = (*_ext->_shpList)->_m; - - switch (memType(m)) { - case NEAR_MEM : - delete[](uint8 *) m; - break; - case FAR_MEM : + if (m) free(m); - break; - default: - warning("Unhandled MemType in Sprite::KillXlat()"); - break; - } + for (b = _ext->_shpList; *b; b++) (*b)->_m = NULL; _flags._xlat = false; @@ -777,9 +768,7 @@ BMP_PTR Sprite::ghost() { if ((bmp->_b = new HideDesc[bmp->_h]) == NULL) error("No Core"); bmp->_v = (uint8 *) memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc) * bmp->_h); - // TODO offset correctly in the surface using y1 pitch and x1 and not via offset segment - //bmp->_m = (uint8 *) MK_FP(e->y1, e->x1); - warning("FIXME: SPRITE::Ghost"); + bmp->_map = (e->_y1 << 16) + e->_x1; return bmp; } return NULL; @@ -1209,7 +1198,7 @@ void Vga::copyPage(uint16 d, uint16 s) { //-------------------------------------------------------------------------- -void Bitmap::xShow(int x, int y) { +void Bitmap::xShow(int16 x, int16 y) { /* uint8 rmsk = x % 4, mask = 1 << rmsk, @@ -1291,7 +1280,7 @@ void Bitmap::xShow(int x, int y) { } -void Bitmap::show(int x, int y) { +void Bitmap::show(int16 x, int16 y) { const byte *srcP = (const byte *)_v; byte *destEndP = (byte *)Vga::_page[1]->pixels + (SCR_WID * SCR_HIG); @@ -1353,8 +1342,8 @@ void Bitmap::show(int x, int y) { } -void Bitmap::hide(int x, int y) { - for (int yp = y; yp < y + _h; ++yp) { +void Bitmap::hide(int16 x, int16 y) { + for (int yp = y; yp < y + _h; yp++) { const byte *srcP = (const byte *)Vga::_page[2]->getBasePtr(x, yp); byte *destP = (byte *)Vga::_page[1]->getBasePtr(x, yp); diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 003be7c8008..e29fa2eea4d 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -57,19 +57,11 @@ namespace CGE { #endif -#if 0 -#define LIGHT 0xFF -#define DARK 0x00 -#define DGRAY 0xF6 -#define GRAY 0xFC -#define LGRAY 0xFF -#else #define LIGHT 0xFF #define DARK 207 #define DGRAY 225 /*219*/ #define GRAY 231 #define LGRAY 237 -#endif #define NO_SEQ (-1) #define NO_PTR ((uint8)-1) From a524adcaee89678ba99b294fcbc5efdf9e137c04 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 12 Jul 2011 08:02:18 +0200 Subject: [PATCH 119/276] CGE: Suppress isVga() and memType() --- engines/cge/bitmap.cpp | 9 ++---- engines/cge/cfile.cpp | 3 +- engines/cge/general.cpp | 23 -------------- engines/cge/general.h | 9 ------ engines/cge/snail.cpp | 5 ++- engines/cge/vga13h.cpp | 67 ++++++++++++++++++----------------------- 6 files changed, 35 insertions(+), 81 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 48bfe1fafbb..84749243667 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -144,8 +144,7 @@ Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), Bitmap::~Bitmap() { - if (_m) - free(_m); + free(_m); delete[] _v; } @@ -156,8 +155,7 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { _h = bmp._h; _m = NULL; _map = 0; - if (memType(_v) == FAR_MEM) - free(_v); + free(_v); if (v0 == NULL) _v = NULL; else { @@ -178,8 +176,7 @@ uint16 Bitmap::moveVmap(uint8 *buf) { uint16 vsiz = (uint8 *)_b - (uint8 *)_v; uint16 siz = vsiz + _h * sizeof(HideDesc); memcpy(buf, _v, siz); - if (memType(_v) == FAR_MEM) - free(_v); + free(_v); _b = (HideDesc *)((_v = buf) + vsiz); return siz; } diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index b235d552b27..f0a0ef3b8fc 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -54,8 +54,7 @@ IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt) IoBuf::~IoBuf() { if (_mode > REA) writeBuff(); - if (_buff) - free(_buff); + free(_buff); } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 6ed6884aba8..f17ebf799ce 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -267,29 +267,6 @@ bool IoHand::exist(const char *name) { return f.exists(name); } -//#define EMS_ADR(a) (FP_SEG(a) > 0xA000) -//#define HNODE_OK(p) (heapchecknode(p)==4) - -MEM_TYPE memType(void *mem) { - /* if (FP_SEG(mem) == _DS) { - if (heapchecknode((void *)mem)==4) - return NEAR_MEM; - } else { - if (FP_SEG(mem) > 0xA000) - return EMS_MEM; - else if (farheapchecknode(mem)==4) - return FAR_MEM; - } - return BAD_MEM; - */ - warning("STUB: memType"); - return FAR_MEM; -} - -bool isVga() { - return true; -} - void sndInit() { warning("STUB: SNDInit"); } diff --git a/engines/cge/general.h b/engines/cge/general.h index 2eebc01c62f..a3cc12080db 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -39,7 +39,6 @@ namespace CGE { #define SEED 0xA5 -enum MEM_TYPE { BAD_MEM, EMS_MEM, NEAR_MEM, FAR_MEM }; enum IOMODE { REA, WRI, UPD }; struct Dac { @@ -140,8 +139,6 @@ void swap(T &A, T &B) { B = a; } - -#ifdef __cplusplus template T max(T A, T B) { return (A > B) ? A : B; @@ -151,8 +148,6 @@ template T min(T A, T B) { return (A < B) ? A : B; } -#endif - class XFile { public: @@ -195,10 +190,8 @@ public: // void SetTime (timeb t); }; - CRYPT XCrypt; CRYPT RCrypt; -MEM_TYPE memType(void *mem); uint16 atow(const char *a); uint16 xtow(const char *x); char *wtom(uint16 val, char *str, int radix, int len); @@ -209,8 +202,6 @@ long timer(); char *mergeExt(char *buf, const char *nam, const char *ext); char *forceExt(char *buf, const char *nam, const char *ext); int driveCD(unsigned drv); -bool isVga(); - // MISSING FUNCTIONS void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index bc9d2124688..a568110de72 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -381,7 +381,7 @@ void CGEEngine::feedSnail(Sprite *spr, SNLIST snq) { if (c->_ptr) break; else - ++c; + c++; } } } @@ -410,8 +410,7 @@ Snail::Snail(CGEEngine *vm, bool turbo) } Snail::~Snail() { - if (_snList) - free(_snList); + free(_snList); } void Snail::addCom(SNCOM com, int ref, int val, void *ptr) { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index e85e13d20c9..4d8b5bf6284 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -621,12 +621,9 @@ Sprite *Sprite::contract() { delete e->_shpList[i]; delete[] e->_shpList; } - if (memType(e->_seq) == NEAR_MEM) - free(e->_seq); - if (e->_near) - free(e->_near); - if (e->_take) - free(e->_take); +// free(e->_seq); + free(e->_near); + free(e->_take); delete e; _ext = NULL; } @@ -683,8 +680,7 @@ void Sprite::killXlat() { if (_flags._xlat && _ext) { BMP_PTR *b; uint8 *m = (*_ext->_shpList)->_m; - if (m) - free(m); + free(m); for (b = _ext->_shpList; *b; b++) (*b)->_m = NULL; @@ -967,42 +963,37 @@ Vga::Vga(int mode) setStatAdr(); if (_statAdr != VGAST1_) _mono++; - if (isVga()) { - _oldColors = farnew(Dac, 256); - _newColors = farnew(Dac, 256); - _oldScreen = SaveScreen(); - getColors(_oldColors); - sunset(); - _oldMode = setMode(mode); - setColors(); - setup(VideoMode); - clear(0); - } + _oldColors = farnew(Dac, 256); + _newColors = farnew(Dac, 256); + _oldScreen = SaveScreen(); + getColors(_oldColors); + sunset(); + _oldMode = setMode(mode); + setColors(); + setup(VideoMode); + clear(0); } Vga::~Vga() { _mono = 0; - if (isVga()) { - Common::String buffer = ""; -/* - clear(0); - setMode(_oldMode); - setColors(); - restoreScreen(_oldScreen); - sunrise(_oldColors); -*/ - if (_oldColors) - free(_oldColors); - if (_newColors) - free(_newColors); - if (_msg) - buffer = Common::String(_msg); - if (_nam) - buffer = buffer + " [" + _nam + "]"; - debugN("%s", buffer.c_str()); - } + Common::String buffer = ""; +/* + clear(0); + setMode(_oldMode); + setColors(); + restoreScreen(_oldScreen); + sunrise(_oldColors); +*/ + free(_oldColors); + free(_newColors); + if (_msg) + buffer = Common::String(_msg); + if (_nam) + buffer = buffer + " [" + _nam + "]"; + + debugN("%s", buffer.c_str()); delete _showQ; delete _spareQ; From daae033e0156f19b3bdbb46aa7b0785c40f1e094 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 12 Jul 2011 21:16:23 +1000 Subject: [PATCH 120/276] CGE: Converted SprExt::_Seq to use dynamically allocated data --- engines/cge/cge_main.cpp | 7 +++++-- engines/cge/events.cpp | 14 ++++++++------ engines/cge/mixer.cpp | 12 +++++++++--- engines/cge/mixer.h | 1 - engines/cge/vga13h.cpp | 28 +++++++++++++++++++++++----- 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 4c20f31cacc..d35a985d89d 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1579,7 +1579,7 @@ void CGEEngine::runGame() { _vga->_showQ->append(_cavLight); _cavLight->_flags._hide = true; - static Seq pocSeq[] = { { 0, 0, 0, 0, 20 }, + const Seq pocSeq[] = { { 0, 0, 0, 0, 20 }, { 1, 2, 0, 0, 4 }, { 2, 3, 0, 0, 4 }, { 3, 4, 0, 0, 16 }, @@ -1587,7 +1587,10 @@ void CGEEngine::runGame() { { 1, 6, 0, 0, 4 }, { 0, 1, 0, 0, 16 }, }; - _pocLight->setSeq(pocSeq); + Seq *seq = (Seq *)malloc(7 * sizeof(Seq)); + Common::copy(pocSeq, pocSeq + 7, seq); + _pocLight->setSeq(seq); + _pocLight->_flags._tran = true; _pocLight->_time = 1; _pocLight->_z = 120; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 433f7c6db93..9c1741189f5 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -142,11 +142,6 @@ void Keyboard::newKeyboard(Common::Event &event) { /*----------------- MOUSE interface -----------------*/ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { - static Seq ms[] = { - { 0, 0, 0, 0, 1 }, - { 1, 1, 0, 0, 1 } - }; - _hold = NULL; _hx = 0; _hy = 0; @@ -155,7 +150,14 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) _busy = NULL; _active = false; _flags._kill = false; - setSeq(ms); + + const Seq ms[] = { + { 0, 0, 0, 0, 1 }, + { 1, 1, 0, 0, 1 } + }; + Seq *seq = (Seq *)malloc(2 * sizeof(Seq)); + Common::copy(ms, ms + 2, seq); + setSeq(seq); BMP_PTR *MC = new BMP_PTR[3]; MC[0] = new Bitmap("MOUSE", true); diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index aea033ebc91..0e3a613e603 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -54,18 +54,24 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(MIX_FALL), _ // slaves uint i; + Seq ls[MIX_MAX]; + for (i = 0; i < MIX_MAX; i++) { static char fn[] = "V00"; wtom(i, fn + 1, 10, 2); _lb[i] = new Bitmap(fn, true); - _ls[i]._now = _ls[i]._next = i; - _ls[i]._dx = _ls[i]._dy = _ls[i]._dly = 0; + ls[i]._now = ls[i]._next = i; + ls[i]._dx = ls[i]._dy = ls[i]._dly = 0; } _lb[i] = NULL; for (i = 0; i < ArrayCount(_led); i++) { register Sprite *spr = new Sprite(_vm, _lb); - spr->setSeq(_ls); + + Seq *seq = (Seq *)malloc(MIX_MAX * sizeof(Seq)); + Common::copy(ls, ls + MIX_MAX, seq); + spr->setSeq(seq); + spr->gotoxy(x + 2 + 12 * i, y + 8); spr->_flags._tran = true; spr->_flags._kill = true; diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index 8ded075514a..ef53eec0705 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -42,7 +42,6 @@ namespace CGE { class Mixer : public Sprite { BMP_PTR _mb[2]; BMP_PTR _lb[MIX_MAX + 1]; - Seq _ls[MIX_MAX]; Sprite *_led[2]; int _fall; void update(); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 4d8b5bf6284..2cdca0004f5 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -60,8 +60,24 @@ static VgaRegBlk VideoMode[] = { }; bool SpeedTest = false; -Seq _seq1[] = { { 0, 0, 0, 0, 0 } }; -Seq _seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; + +Seq *getConstantSeq(bool seqFlag) { + const Seq seq1[] = { { 0, 0, 0, 0, 0 } }; + const Seq seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; + + Seq *seq; + if (seqFlag) { + seq = (Seq *)malloc(1 * sizeof(Seq)); + *seq = seq1[0]; + } else { + seq = (Seq *)malloc(2 * sizeof(Seq)); + seq[0] = seq2[0]; + seq[1] = seq2[1]; + } + + return seq; +} + extern "C" void SNDMIDIPlay(); @@ -405,7 +421,7 @@ BMP_PTR *Sprite::setShapeList(BMP_PTR *shpP) { _ext->_shpList = shpP; _flags._bDel = true; if (!_ext->_seq) - setSeq((_shpCnt < 2) ? _seq1 : _seq2); + setSeq(getConstantSeq(_shpCnt < 2)); } return r; } @@ -590,7 +606,7 @@ Sprite *Sprite::expand() { error("Bad JUMP in SEQ [%s]", fname); setSeq(seq); } else - setSeq((_shpCnt == 1) ? _seq1 : _seq2); + setSeq(getConstantSeq(_shpCnt == 1)); //disable(); // disable interupt setShapeList(shplist); @@ -621,9 +637,11 @@ Sprite *Sprite::contract() { delete e->_shpList[i]; delete[] e->_shpList; } -// free(e->_seq); + + free(e->_seq); free(e->_near); free(e->_take); + delete e; _ext = NULL; } From b6be90326d31030ac364edeb8538aecaef51e378 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 12 Jul 2011 21:41:11 +1000 Subject: [PATCH 121/276] CGE: Fixed a memory leak with Sprite::setSeq --- engines/cge/vga13h.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 2cdca0004f5..96642b45409 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -451,6 +451,11 @@ bool Sprite::works(Sprite *spr) { Seq *Sprite::setSeq(Seq *seq) { + if (_ext) { + free(_ext->_seq); + _ext->_seq = NULL; + } + expand(); register Seq *s = _ext->_seq; _ext->_seq = seq; From 891032053a19f0962771f4374cd79ee66f2f9b0f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 12 Jul 2011 21:43:53 +1000 Subject: [PATCH 122/276] CGE: Removed redundant disable/enable calls --- engines/cge/snail.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index a568110de72..2fe2d22d5be 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -35,14 +35,6 @@ namespace CGE { -static void _enable() { - warning("STUB: _enable"); -} - -static void _disable() { - warning("STUB: _disable"); -} - extern Sprite *_pocLight; //------------------------------------------------------------------------- @@ -414,7 +406,6 @@ Snail::~Snail() { } void Snail::addCom(SNCOM com, int ref, int val, void *ptr) { - _disable(); Com *snc = &_snList[_head++]; snc->_com = com; snc->_ref = ref; @@ -425,13 +416,11 @@ void Snail::addCom(SNCOM com, int ref, int val, void *ptr) { killText(); _timerExpiry = 0; } - _enable(); } void Snail::insCom(SNCOM com, int ref, int val, void *ptr) { Com *snc; - _disable(); if (_busy) { _snList[(_tail - 1) & 0xFF] = _snList[_tail]; snc = &_snList[_tail]; @@ -447,7 +436,6 @@ void Snail::insCom(SNCOM com, int ref, int val, void *ptr) { killText(); _timerExpiry = 0; } - _enable(); } void CGEEngine::snNNext(Sprite *sprel, int p) { From e2b19ad9b0bc3e2a437eaab3aaa62302e0e892d3 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 12 Jul 2011 21:53:07 +1000 Subject: [PATCH 123/276] CGE: Fixed several memory leaks of main objects --- engines/cge/cge.cpp | 4 +++- engines/cge/cge_main.cpp | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 55b79d5b35d..884af2cd467 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -74,8 +74,10 @@ void CGEEngine::setup() { _heart = new Heart; _sys = new System(this); _pocLight = new PocLight(this); - for (int i = 0; i < POCKET_NX; i++) + for (int i = 0; i < POCKET_NX; i++) { _pocket[i] = new Sprite(this, NULL); + _pocket[i]->_flags._kill = false; + } _sprite = new Sprite(this, NULL); _miniCave = new Sprite(this, NULL); _miniCave->_flags._kill = false; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index d35a985d89d..6f741f1598d 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1631,6 +1631,7 @@ void CGEEngine::runGame() { _hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); if (INI_FILE::exist("00SHADOW.SPR")) { loadSprite("00SHADOW", -1, 0, _hero->_x + 14, _hero->_y + 51); + delete _shadow; if ((_shadow = _sprite) != NULL) { _shadow->_ref = 2; _shadow->_flags._tran = true; @@ -1850,9 +1851,6 @@ void CGEEngine::cge_main() { _debugLine->_flags._hide = true; _horzLine->_flags._hide = true; - //srand((uint16) Timer()); - _sys = new System(this); - if (_music && Startup::_soundOk) loadMidi(0); if (Startup::_mode < 2) From 11c9e64885faed3c3d7ba5888e3f129548f789e8 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 12 Jul 2011 22:02:00 +1000 Subject: [PATCH 124/276] CGE: More bugfixes for memory leaks --- engines/cge/cge_main.cpp | 1 + engines/cge/vga13h.cpp | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 6f741f1598d..ed5ee8eeb17 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -247,6 +247,7 @@ void CGEEngine::loadGame(XFile &file, bool tiny = false) { for (i = 0; i < POCKET_NX; i++) { register int r = _pocref[i]; + delete _pocket[i]; _pocket[i] = (r < 0) ? NULL : _vga->_spareQ->locate(r); } } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 96642b45409..5bdb50fa9e4 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -612,10 +612,9 @@ Sprite *Sprite::expand() { setSeq(seq); } else setSeq(getConstantSeq(_shpCnt == 1)); - //disable(); // disable interupt setShapeList(shplist); - //enable(); // enable interupt + if (nea) nea[neacnt - 1]._ptr = _ext->_near = nea; else From 700dbe021ed98939d52649c4961744f2172a1986 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 12 Jul 2011 22:43:24 +1000 Subject: [PATCH 125/276] CGE: Fix ProgName method to handle extensions without a leading period --- engines/cge/general.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index f17ebf799ce..4ca1ef57cab 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -102,8 +102,12 @@ void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, c const char *progName(const char *ext) { static char buf[MAXFILE]; strcpy(buf, "CGE"); - if (ext) + if (ext) { + strcat(buf, "."); + if (*ext == '.') + ++ext; strcat(buf, ext); + } return buf; } From 4d96ec70340b5f3dbf875ed3a3f6832faffd796c Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 12 Jul 2011 22:44:04 +1000 Subject: [PATCH 126/276] CGE: Fixed a previously commented adding of mouse object to show queue --- engines/cge/cge_main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index ed5ee8eeb17..05e936e4e5e 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1696,8 +1696,7 @@ void CGEEngine::movie(const char *ext) { expandSprite(_vga->_spareQ->locate(999)); feedSnail(_vga->_showQ->locate(999), TAKE); - // FIXME: Allow ScummVM to handle mouse display - //Vga->ShowQ->Append(Mouse); + _vga->_showQ->append(_mouse); _heart->_enable = true; _keyboard->setClient(_sys); From 5148f80fa5077e2bdffba44dabac793c9cbe4666 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 13 Jul 2011 00:28:17 +0200 Subject: [PATCH 127/276] CGE: add a new SNPOST to fix the function pointer issue --- engines/cge/cge.h | 2 ++ engines/cge/cge_main.cpp | 30 +++++++++++------------------ engines/cge/config.cpp | 4 +--- engines/cge/general.h | 2 +- engines/cge/mixer.cpp | 4 +--- engines/cge/snail.cpp | 41 +++++++++++++++++++++++++++++++++++----- engines/cge/snail.h | 4 ++++ engines/cge/startup.h | 1 - 8 files changed, 56 insertions(+), 32 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 29a7a11b9d3..644e06e7e7d 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -46,6 +46,7 @@ enum { }; enum SNLIST { NEAR, TAKE }; +enum CALLBACK { NULLCB = 0, QGAME, MINISTEP, XCAVE, SELECTSOUND, SNSELECT, SNDSETVOLUME }; #define POCKET_NX 8 @@ -145,6 +146,7 @@ public: void sayDebug(); void nextStep(); void switchDebug(); + void miniStep(int stp); void snBackPt(Sprite *spr, int stp); void snBarrier(int cav, int bar, bool horz); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 05e936e4e5e..f2aca3ed8bb 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -584,8 +584,7 @@ static void AltCtrlDel() { SNPOST_(SNSAY, -1, A_C_D_TEXT, _hero); } -// Used in stubbed function, do not remove! -static void miniStep(int stp) { +void CGEEngine::miniStep(int stp) { if (stp < 0) _miniCave->_flags._hide = true; else { @@ -600,10 +599,9 @@ static void miniStep(int stp) { static void postMiniStep(int stp) { - //static int recent = -2; - //TODO Change the SNPOST message send to a special way to send function pointer - //if (MiniCave && stp != recent) SNPOST_(SNEXEC, -1, recent = stp, (void *)&MiniStep); - warning("STUB: PostMiniStep()"); + static int recent = -2; + if (_miniCave && stp != recent) + SNPOST2_(SNEXEC, -1, recent = stp, MINISTEP); } void System::setPal() { @@ -744,9 +742,7 @@ void CGEEngine::switchCave(int cav) { _heart->_enable = false; if (cav < 0) { SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - //TODO Change the SNPOST message send to a special way to send function pointer - //SNPOST(SNEXEC, -1, 0, (void *)&QGame); // switch cave - warning("SwitchCave() - SNPOST"); + SNPOST2(SNEXEC, -1, 0, QGAME); // switch cave } else { _now = cav; _mouse->off(); @@ -764,9 +760,7 @@ void CGEEngine::switchCave(int cav) { if (!_startupMode) keyClick(); SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - //TODO Change the SNPOST message send to a special way to send function pointer - //SNPOST(SNEXEC, 0, 0, (void *)&XCave); // switch cave - warning("SwitchCave() - SNPOST"); + SNPOST2(SNEXEC, 0, 0, XCAVE); // switch cave } } } @@ -997,9 +991,7 @@ void CGEEngine::switchMusic() { SNPOST_(SNKILL, -1, 0, Vmenu::_addr); else { SNPOST_(SNSEQ, 122, (_music = false), NULL); - //TODO Change the SNPOST message send to a special way to send function pointer - // SNPOST(SNEXEC, -1, 0, (void *)&selectSound); - warning("SwitchMusic() - SNPOST"); + SNPOST2(SNEXEC, -1, 0, SELECTSOUND); } } else { if (Startup::_core < CORE_HIG) @@ -1580,7 +1572,8 @@ void CGEEngine::runGame() { _vga->_showQ->append(_cavLight); _cavLight->_flags._hide = true; - const Seq pocSeq[] = { { 0, 0, 0, 0, 20 }, + const Seq pocSeq[] = { + { 0, 0, 0, 0, 20 }, { 1, 2, 0, 0, 4 }, { 2, 3, 0, 0, 4 }, { 3, 4, 0, 0, 16 }, @@ -1668,9 +1661,8 @@ void CGEEngine::runGame() { _keyboard->setClient(_sys); // main loop while (!_finis && !_eventManager->_quitFlag) { - //TODO Change the SNPOST message send to a special way to send function pointer - // if (FINIS) SNPOST(SNEXEC, -1, 0, (void *)&QGame); - warning("RunGame: problematic use of SNPOST"); + if (_finis) + SNPOST2(SNEXEC, -1, 0, QGAME); mainLoop(); } diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 808d74ff9b4..01529619827 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -192,9 +192,7 @@ void CGEEngine::snSelect() { static void select(Choice *cho, int hlp) { _cho = cho; _hlp = hlp; - //TODO Change the SNPOST message send to a special way to send function pointer - //SNPOST(SNEXEC, -1, 0, (void *)&SNSelect); - warning("STUB: select"); + SNPOST2(SNEXEC, -1, 0, SNSELECT); } diff --git a/engines/cge/general.h b/engines/cge/general.h index a3cc12080db..b4f73726eeb 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -112,7 +112,7 @@ class Emm { int _han; static void *_frame; public: - Emm(long size = 0); + Emm(long size); ~Emm(); Ems *alloc(uint16 siz); void release(); diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 0e3a613e603..8b11dbcc4c2 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -142,9 +142,7 @@ void Mixer::update() { _led[0]->step(_sndDrvInfo.Vol4._ml); _led[1]->step(_sndDrvInfo.Vol4._dl); - //TODO Change the SNPOST message send to a special way to send function pointer - //SNPOST_(SNEXEC, -1, 0, (void*)&sndSetVolume); - warning("STUB: Mixer::Update"); + SNPOST2_(SNEXEC, -1, 0, SNDSETVOLUME); } } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 2fe2d22d5be..23a182cbd50 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -411,6 +411,21 @@ void Snail::addCom(SNCOM com, int ref, int val, void *ptr) { snc->_ref = ref; snc->_val = val; snc->_ptr = ptr; + snc->_cbType = NULLCB; + if (com == SNCLEAR) { + _tail = _head; + killText(); + _timerExpiry = 0; + } +} + +void Snail::addCom2(SNCOM com, int ref, int val, CALLBACK cbType) { + Com *snc = &_snList[_head++]; + snc->_com = com; + snc->_ref = ref; + snc->_val = val; + snc->_ptr = NULL; + snc->_cbType = cbType; if (com == SNCLEAR) { _tail = _head; killText(); @@ -913,8 +928,7 @@ void Snail::runCom() { } break; case SNCAVE : - // SwitchCave(snc->_val); - warning("Problematic call of SwitchCave in SNAIL::runCom"); + _vm->switchCave(snc->_val); break; case SNKILL : _vm->snKill(sprel); @@ -1042,9 +1056,26 @@ void Snail::runCom() { count = snc->_val; break; case SNEXEC : - // TODO: Handle correctly the execution of function pointer coming from Message send SNPOST - // ((void(*)(int)) (snc->_ptr))(snc->_val); - warning("STUB: SNEXEC code"); + switch (snc->_cbType) { + case QGAME: + _vm->qGame(); + break; + case MINISTEP: + _vm->miniStep(snc->_val); + break; + case XCAVE: + _vm->xCave(); + break; + case SELECTSOUND: + _vm->selectSound(); + break; + case SNSELECT: + _vm->snSelect(); + break; + case SNDSETVOLUME: + sndSetVolume(); + break; + } break; case SNSTEP : sprel->step(); diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 888fae6ce9e..48e59002484 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -44,7 +44,9 @@ namespace CGE { #define SNINSERT(c, r, v, p) _snail->insCom(c, r, v, p) #define SNPOST(c, r, v, p) _snail->addCom(c, r, v, p) +#define SNPOST2(c, r, v, p) _snail->addCom2(c, r, v, p) #define SNPOST_(c, r, v, p) _snail_->addCom(c, r, v, p) +#define SNPOST2_(c, r, v, p) _snail_->addCom2(c, r, v, p) #define SNAIL_FRAME_RATE 62 #define SNAIL_FRAME_DELAY (1000 / SNAIL_FRAME_RATE) @@ -77,6 +79,7 @@ public: int _ref; int _val; void *_ptr; + CALLBACK _cbType; } *_snList; uint8 _head; uint8 _tail; @@ -90,6 +93,7 @@ public: ~Snail(); void runCom(); void addCom(SNCOM com, int ref, int val, void *ptr); + void addCom2(SNCOM com, int ref, int val, CALLBACK cbType); void insCom(SNCOM com, int ref, int val, void *ptr); bool idle(); private: diff --git a/engines/cge/startup.h b/engines/cge/startup.h index cc16f2a1236..54799451041 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -56,7 +56,6 @@ namespace CGE { #endif #define CORE_MID (CORE_HIG - 20) -#define CORE_LOW (CORE_MID - 20) class Startup { From 4d0f83babb923527c67157204ba0b8b678b6732a Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 13 Jul 2011 08:44:58 +0200 Subject: [PATCH 128/276] CGE: Rename some constants --- engines/cge/cge.h | 12 +++++++++--- engines/cge/cge_main.cpp | 24 ++++++++++++------------ engines/cge/config.cpp | 2 +- engines/cge/mixer.cpp | 2 +- engines/cge/snail.cpp | 26 ++++++++++++++------------ engines/cge/snail.h | 4 ++-- engines/cge/vga13h.cpp | 4 ++-- engines/cge/vga13h.h | 2 +- 8 files changed, 42 insertions(+), 34 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 644e06e7e7d..7dd218e258a 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -45,8 +45,14 @@ enum { kCGEDebug = 1 << 0 }; -enum SNLIST { NEAR, TAKE }; -enum CALLBACK { NULLCB = 0, QGAME, MINISTEP, XCAVE, SELECTSOUND, SNSELECT, SNDSETVOLUME }; +enum SnList { + kNear, kTake +}; + +enum CallbackType { + kNullCB = 0, kQGame, kMiniStep, kXCave, kSelectSound, + kSnSelect, kSndSetVolume +}; #define POCKET_NX 8 @@ -126,7 +132,7 @@ public: void expandSprite(Sprite *spr); void contractSprite(Sprite *spr); int findPocket(Sprite *spr); - void feedSnail(Sprite *spr, SNLIST snq); + void feedSnail(Sprite *spr, SnList snq); void pocFul(); void hide1(Sprite *spr); void loadMapping(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index f2aca3ed8bb..16e21e1f73a 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -355,7 +355,7 @@ void WALK::tick() { for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (distance(spr) < 2) { if (!spr->_flags._near) { - _vm->feedSnail(spr, NEAR); + _vm->feedSnail(spr, kNear); spr->_flags._near = true; } } else { @@ -601,7 +601,7 @@ void CGEEngine::miniStep(int stp) { static void postMiniStep(int stp) { static int recent = -2; if (_miniCave && stp != recent) - SNPOST2_(SNEXEC, -1, recent = stp, MINISTEP); + SNPOST2_(SNEXEC, -1, recent = stp, kMiniStep); } void System::setPal() { @@ -685,7 +685,7 @@ void CGEEngine::caveUp() { _vga->_showQ->insert(_shadow, _hero); _shadow->_z = _hero->_z; } - feedSnail(_vga->_showQ->locate(BakRef + 999), TAKE); + feedSnail(_vga->_showQ->locate(BakRef + 999), kTake); _vga->show(); _vga->copyPage(1, 0); _vga->show(); @@ -707,7 +707,7 @@ void CGEEngine::caveDown() { Sprite *n = spr->_next; if (spr->_ref >= 1000 /*&& spr->_cave*/) { if (spr->_ref % 1000 == 999) - feedSnail(spr, TAKE); + feedSnail(spr, kTake); _vga->_spareQ->append(_vga->_showQ->remove(spr)); } spr = n; @@ -742,7 +742,7 @@ void CGEEngine::switchCave(int cav) { _heart->_enable = false; if (cav < 0) { SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - SNPOST2(SNEXEC, -1, 0, QGAME); // switch cave + SNPOST2(SNEXEC, -1, 0, kQGame); // switch cave } else { _now = cav; _mouse->off(); @@ -760,7 +760,7 @@ void CGEEngine::switchCave(int cav) { if (!_startupMode) keyClick(); SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - SNPOST2(SNEXEC, 0, 0, XCAVE); // switch cave + SNPOST2(SNEXEC, 0, 0, kXCave); // switch cave } } } @@ -991,7 +991,7 @@ void CGEEngine::switchMusic() { SNPOST_(SNKILL, -1, 0, Vmenu::_addr); else { SNPOST_(SNSEQ, 122, (_music = false), NULL); - SNPOST2(SNEXEC, -1, 0, SELECTSOUND); + SNPOST2(SNEXEC, -1, 0, kSelectSound); } } else { if (Startup::_core < CORE_HIG) @@ -1217,7 +1217,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if (ps) { if (_flags._kept || _hero->distance(this) < MAX_DISTANCE) { if (works(ps)) { - _vm->feedSnail(ps, TAKE); + _vm->feedSnail(ps, kTake); } else _vm->offUse(); _vm->selectPocket(-1); @@ -1239,10 +1239,10 @@ void Sprite::touch(uint16 mask, int x, int y) { } } else { if (_takePtr != NO_PTR) { - if (snList(TAKE)[_takePtr]._com == SNNEXT) + if (snList(kTake)[_takePtr]._com == SNNEXT) _vm->offUse(); else - _vm->feedSnail(this, TAKE); + _vm->feedSnail(this, kTake); } else _vm->offUse(); } @@ -1662,7 +1662,7 @@ void CGEEngine::runGame() { // main loop while (!_finis && !_eventManager->_quitFlag) { if (_finis) - SNPOST2(SNEXEC, -1, 0, QGAME); + SNPOST2(SNEXEC, -1, 0, kQGame); mainLoop(); } @@ -1686,7 +1686,7 @@ void CGEEngine::movie(const char *ext) { if (INI_FILE::exist(fn)) { loadScript(fn); expandSprite(_vga->_spareQ->locate(999)); - feedSnail(_vga->_showQ->locate(999), TAKE); + feedSnail(_vga->_showQ->locate(999), kTake); _vga->_showQ->append(_mouse); diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 01529619827..2941d36d2c8 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -192,7 +192,7 @@ void CGEEngine::snSelect() { static void select(Choice *cho, int hlp) { _cho = cho; _hlp = hlp; - SNPOST2(SNEXEC, -1, 0, SNSELECT); + SNPOST2(SNEXEC, -1, 0, kSnSelect); } diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 8b11dbcc4c2..eddc4a65704 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -142,7 +142,7 @@ void Mixer::update() { _led[0]->step(_sndDrvInfo.Vol4._ml); _led[1]->step(_sndDrvInfo.Vol4._dl); - SNPOST2_(SNEXEC, -1, 0, SNDSETVOLUME); + SNPOST2_(SNEXEC, -1, 0, kSndSetVolume); } } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 23a182cbd50..10d85bfc0f6 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -307,10 +307,10 @@ void CGEEngine::snGhost(Bitmap *bmp) { delete bmp; } -void CGEEngine::feedSnail(Sprite *spr, SNLIST snq) { +void CGEEngine::feedSnail(Sprite *spr, SnList snq) { if (spr) if (spr->active()) { - uint8 ptr = (snq == TAKE) ? spr->_takePtr : spr->_nearPtr; + uint8 ptr = (snq == kTake) ? spr->_takePtr : spr->_nearPtr; if (ptr != NO_PTR) { Snail::Com *comtab = spr->snList(snq); @@ -335,7 +335,7 @@ void CGEEngine::feedSnail(Sprite *spr, SNLIST snq) { if (c->_com == SNNEXT) { Sprite *s = (c->_ref < 0) ? spr : locate(c->_ref); if (s) { - uint8 *idx = (snq == TAKE) ? &s->_takePtr : &s->_nearPtr; + uint8 *idx = (snq == kTake) ? &s->_takePtr : &s->_nearPtr; if (*idx != NO_PTR) { int v; switch (c->_val) { @@ -411,7 +411,7 @@ void Snail::addCom(SNCOM com, int ref, int val, void *ptr) { snc->_ref = ref; snc->_val = val; snc->_ptr = ptr; - snc->_cbType = NULLCB; + snc->_cbType = kNullCB; if (com == SNCLEAR) { _tail = _head; killText(); @@ -419,7 +419,7 @@ void Snail::addCom(SNCOM com, int ref, int val, void *ptr) { } } -void Snail::addCom2(SNCOM com, int ref, int val, CALLBACK cbType) { +void Snail::addCom2(SNCOM com, int ref, int val, CallbackType cbType) { Com *snc = &_snList[_head++]; snc->_com = com; snc->_ref = ref; @@ -603,7 +603,7 @@ void CGEEngine::snCover(Sprite *spr, int xref) { _vga->_showQ->insert(_vga->_showQ->remove(spr->_prev), xspr); spr->_flags._shad = false; } - feedSnail(xspr, NEAR); + feedSnail(xspr, kNear); } } @@ -1057,24 +1057,26 @@ void Snail::runCom() { break; case SNEXEC : switch (snc->_cbType) { - case QGAME: + case kQGame: _vm->qGame(); break; - case MINISTEP: + case kMiniStep: _vm->miniStep(snc->_val); break; - case XCAVE: + case kXCave: _vm->xCave(); break; - case SELECTSOUND: + case kSelectSound: _vm->selectSound(); break; - case SNSELECT: + case kSnSelect: _vm->snSelect(); break; - case SNDSETVOLUME: + case kSndSetVolume: sndSetVolume(); break; + default: + error("Unknown Callback Type in SNEXEC"); } break; case SNSTEP : diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 48e59002484..08f20b9d07f 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -79,7 +79,7 @@ public: int _ref; int _val; void *_ptr; - CALLBACK _cbType; + CallbackType _cbType; } *_snList; uint8 _head; uint8 _tail; @@ -93,7 +93,7 @@ public: ~Snail(); void runCom(); void addCom(SNCOM com, int ref, int val, void *ptr); - void addCom2(SNCOM com, int ref, int val, CALLBACK cbType); + void addCom2(SNCOM com, int ref, int val, CallbackType cbType); void insCom(SNCOM com, int ref, int val, void *ptr); bool idle(); private: diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 5bdb50fa9e4..d0e267ef385 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -476,10 +476,10 @@ bool Sprite::seqTest(int n) { } -Snail::Com *Sprite::snList(SNLIST type) { +Snail::Com *Sprite::snList(SnList type) { register SprExt *e = _ext; if (e) - return (type == NEAR) ? e->_near : e->_take; + return (type == kNear) ? e->_near : e->_take; return NULL; } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index e29fa2eea4d..6b56217a1e8 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -222,7 +222,7 @@ public: void killXlat(); void step(int nr = -1); Seq *setSeq(Seq *seq); - Snail::Com *snList(SNLIST type); + Snail::Com *snList(SnList type); virtual void touch(uint16 mask, int x, int y); virtual void tick(); void sync(Common::Serializer &s); From 6c9719009223947572c8e81fdefe9e4cd17f717f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 13 Jul 2011 19:18:23 +1000 Subject: [PATCH 129/276] CGE: Fixed initialising of _shadow that was crashing the intro sequence --- engines/cge/cge.cpp | 3 +-- engines/cge/cge_main.cpp | 1 + engines/cge/vga13h.cpp | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 884af2cd467..527b16d2883 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -58,6 +58,7 @@ void CGEEngine::setup() { // Initialise fields _lastFrame = 0; _hero = NULL; + _shadow = NULL; // Create debugger console _console = new CGEConsole(this); @@ -81,8 +82,6 @@ void CGEEngine::setup() { _sprite = new Sprite(this, NULL); _miniCave = new Sprite(this, NULL); _miniCave->_flags._kill = false; - _shadow = new Sprite(this, NULL); - _shadow->_flags._kill = false; _horzLine = new HorizLine(this); _infoLine = new InfoLine(this, INFO_W); _cavLight = new CavLight(this); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 16e21e1f73a..6e2721f8fc1 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1629,6 +1629,7 @@ void CGEEngine::runGame() { if ((_shadow = _sprite) != NULL) { _shadow->_ref = 2; _shadow->_flags._tran = true; + _shadow->_flags._kill = false; _hero->_flags._shad = true; _vga->_showQ->insert(_vga->_spareQ->remove(_shadow), _hero); } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d0e267ef385..c36d7472959 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -880,6 +880,7 @@ void Queue::insert(Sprite *spr, Sprite *nxt) { if (!_tail) _tail = spr; } else { + assert(nxt); spr->_next = nxt; spr->_prev = nxt->_prev; if (spr->_prev) From 9dc2cb87d98c801a773659af37dd1b84d73f4888 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 13 Jul 2011 19:21:34 +1000 Subject: [PATCH 130/276] CGE: Fix array size in Spike class constructor --- engines/cge/vga13h.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index c36d7472959..eab50660ddd 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1387,7 +1387,7 @@ CavLight::CavLight(CGEEngine *vm): Sprite(vm, NULL) { Spike::Spike(CGEEngine *vm): Sprite(vm, NULL) { // Set the sprite list - BMP_PTR *SP = new BMP_PTR[2]; + BMP_PTR *SP = new BMP_PTR[3]; SP[0] = new Bitmap("SPK_L", true); SP[1] = new Bitmap("SPK_R", true); SP[2] = NULL; From c3c8032c42958f73ef4370fb0476fd0f5a7e30dd Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 13 Jul 2011 20:42:30 +1000 Subject: [PATCH 131/276] CGE: Implemented Bitmap::xShow method --- engines/cge/vga13h.cpp | 111 +++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 71 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index eab50660ddd..ec616a2551c 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1213,84 +1213,53 @@ void Vga::copyPage(uint16 d, uint16 s) { //-------------------------------------------------------------------------- void Bitmap::xShow(int16 x, int16 y) { - /* - uint8 rmsk = x % 4, - mask = 1 << rmsk, - *scr = VGA::Page[1] + y * (SCR_WID / 4) + x / 4; - uint8 *m = (char *) M; - uint8 *v = V; + const byte *srcP = (const byte *)_v; + byte *destEndP = (byte *)Vga::_page[1]->pixels + (SCR_WID * SCR_HIG); + byte *lookupTable = _m; - asm push bx - asm push si - asm push ds + // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a + // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data + // must be decompressed and inserted into the surface + for (int planeCtr = 0; planeCtr < 4; ++planeCtr) { + byte *destP = (byte *)Vga::_page[1]->getBasePtr(x + planeCtr, y); - asm cld - asm les di,scr - asm lds si,v - asm mov bx,m + for (;;) { + uint16 v = READ_LE_UINT16(srcP); + srcP += 2; + int cmd = v >> 14; + int count = v & 0x3FFF; - asm mov al,0x02 // map mask register - asm mov ah,mask + if (cmd == 0) { + // End of image + break; + } - plane: - // enable output plane - asm mov dx,VGASEQ_ - asm out dx,ax - asm push ax + assert(destP < destEndP); - // select input plane - asm mov dx,VGAGRA_ - asm mov al,0x04 // read map select register - asm mov ah,rmsk - asm out dx,ax + if (cmd == 2) + ++srcP; + else if (cmd == 3) + srcP += count; - asm push di + // Handle a set of pixels + while (count-- > 0) { + // Transfer operation + switch (cmd) { + case 1: + // SKIP + break; + case 2: + case 3: + // TINT + *destP = lookupTable[*destP]; + break; + } - block: - asm lodsw - asm mov cx,ax - asm and ch,0x3F - asm test ah,0xC0 - asm jz endpl - asm jns skip - asm jnp incsi // replicate? - asm add si,cx // skip over data block - asm dec si // fix it before following inc - - incsi: - asm inc si - tint: - asm mov al,es:[di] - //----------------------------------------------- - // asm xlat ss:0 // unsupported with BASM! - __emit__(0x36, 0xD7); // this stands for above! - //----------------------------------------------- - asm stosb - asm loop tint - asm jmp block - - skip: - asm add di,cx - asm jmp block - - endpl: - asm pop di - asm pop ax - asm inc rmsk - asm shl ah,1 - asm test ah,0x10 - asm jz x_chk - asm mov ah,0x01 - asm mov rmsk,0 - asm inc di - x_chk: - asm cmp ah,mask - asm jne plane - asm pop ds - asm pop si - asm pop bx - */ - warning("STUB: BITMAP::xShow"); + // Move to next dest position + destP += 4; + } + } + } } From 324ccb1760b4915d91b58e643bd0d079eaa095f6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 13 Jul 2011 21:04:44 +1000 Subject: [PATCH 132/276] CGE: Split pathfinding related code into walk.cpp --- engines/cge/cge.cpp | 2 +- engines/cge/cge_main.cpp | 238 +-------------------------------- engines/cge/cge_main.h | 40 ------ engines/cge/module.mk | 3 +- engines/cge/snail.cpp | 1 + engines/cge/walk.cpp | 281 +++++++++++++++++++++++++++++++++++++++ engines/cge/walk.h | 82 ++++++++++++ 7 files changed, 369 insertions(+), 278 deletions(-) create mode 100644 engines/cge/walk.cpp create mode 100644 engines/cge/walk.h diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 527b16d2883..0861e3e7f29 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -35,7 +35,7 @@ #include "cge/talk.h" #include "cge/text.h" #include "cge/vol.h" - +#include "cge/walk.h" namespace CGE { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 6e2721f8fc1..0e2bcc451c1 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -29,6 +29,7 @@ #include "common/memstream.h" #include "common/savefile.h" #include "common/serializer.h" +#include "common/str.h" #include "cge/general.h" #include "cge/sound.h" #include "cge/startup.h" @@ -46,7 +47,7 @@ #include "cge/mixer.h" #include "cge/cge_main.h" #include "cge/cge.h" -#include "common/str.h" +#include "cge/walk.h" namespace CGE { @@ -60,7 +61,6 @@ uint16 _stklen = (STACK_SIZ * 2); Vga *_vga; Heart *_heart; -WALK *_hero; System *_sys; Sprite *_pocLight; EventManager *_eventManager; @@ -102,74 +102,6 @@ Bar _barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; extern Dac _stdPal[58]; -uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; - - -uint8 &Cluster::cell() { - return _map[_b][_a]; -} - - -bool Cluster::Protected() { -/* - if (A == Barriers[Now]._vert || B == Barriers[Now]._horz) - return true; - - _DX = (MAP_ZCNT << 8) + MAP_XCNT; - _BX = (uint16) this; - - asm mov ax,1 - asm mov cl,[bx].(COUPLE)A - asm mov ch,[bx].(COUPLE)B - asm test cx,0x8080 // (A < 0) || (B < 0) - asm jnz xit - - asm cmp cl,dl - asm jge xit - asm cmp ch,dh - asm jge xit - - // if (A < 0 || A >= MAP_XCNT || B < 0 || B >= MAP_ZCNT) return true; - - asm mov al,dl - asm mul ch - asm xor ch,ch - asm add ax,cx - asm mov bx,ax - _BX += (uint16) Map; - //asm add bx,offset CLUSTER::Map - asm mov al,[bx] - asm and ax,0xFF - asm jz xit - asm mov ax,1 - - // return Map[B][A] != 0; - - xit: return _AX; - */ - - warning("STUB: CLUSTER::Protected()"); - return true; -} - - -Cluster XZ(int x, int y) { - if (y < MAP_TOP) - y = MAP_TOP; - - if (y > MAP_TOP + MAP_HIG - MAP_ZGRID) - y = MAP_TOP + MAP_HIG - MAP_ZGRID; - - return Cluster(x / MAP_XGRID, (y - MAP_TOP) / MAP_ZGRID); -} - - -Cluster XZ(Couple xy) { - signed char x, y; - xy.split(x, y); - return XZ(x, y); -} - void CGEEngine::syncHeader(Common::Serializer &s) { int i; @@ -333,172 +265,6 @@ void CGEEngine::loadMapping() { } } - -Cluster Trace[MAX_FIND_LEVEL]; -int FindLevel; - - -WALK::WALK(CGEEngine *vm, BMP_PTR *shpl) - : Sprite(vm, shpl), Dir(NO_DIR), _tracePtr(-1), _vm(vm) { -} - - -void WALK::tick() { - if (_flags._hide) - return; - - _here = XZ(_x + _w / 2, _y + _h); - - if (Dir != NO_DIR) { - Sprite *spr; - _sys->funTouch(); - for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { - if (distance(spr) < 2) { - if (!spr->_flags._near) { - _vm->feedSnail(spr, kNear); - spr->_flags._near = true; - } - } else { - spr->_flags._near = false; - } - } - } - - if (_flags._hold || _tracePtr < 0) - park(); - else { - if (_here == Trace[_tracePtr]) { - if (--_tracePtr < 0) - park(); - } else { - signed char dx, dz; - (Trace[_tracePtr] - _here).split(dx, dz); - DIR d = (dx) ? ((dx > 0) ? EE : WW) : ((dz > 0) ? SS : NN); - turn(d); - } - } - step(); - if ((Dir == WW && _x <= 0) || - (Dir == EE && _x + _w >= SCR_WID) || - (Dir == SS && _y + _w >= WORLD_HIG - 2)) - park(); - else { - signed char x; // dummy var - _here.split(x, _z); // take current Z position - SNPOST_(SNZTRIM, -1, 0, this); // update Hero's pos in show queue - } -} - - -int WALK::distance(Sprite *spr) { - int dx, dz; - dx = spr->_x - (_x + _w - WALKSIDE); - if (dx < 0) - dx = (_x + WALKSIDE) - (spr->_x + spr->_w); - - if (dx < 0) - dx = 0; - - dx /= MAP_XGRID; - dz = spr->_z - _z; - if (dz < 0) - dz = - dz; - - dx = dx * dx + dz * dz; - for (dz = 1; dz * dz < dx; dz++) - ; - - return dz - 1; -} - - -void WALK::turn(DIR d) { - DIR dir = (Dir == NO_DIR) ? SS : Dir; - if (d != Dir) { - step((d == dir) ? (1 + dir + dir) : (9 + 4 * dir + d)); - Dir = d; - } -} - - -void WALK::park() { - if (_time == 0) - ++_time; - - if (Dir != NO_DIR) { - step(9 + 4 * Dir + Dir); - Dir = NO_DIR; - _tracePtr = -1; - } -} - - -void WALK::findWay(Cluster c) { - warning("STUB: WALK::findWay"); - /* - bool Find1Way(); - extern uint16 Target; - - if (c != Here) { - for (FindLevel = 1; FindLevel <= MAX_FIND_LEVEL; FindLevel++) { - signed char x, z; - Here.Split(x, z); - Target = (z << 8) | x; - c.Split(x, z); - _CX = (z << 8) | x; - if (Find1Way()) - break; - } - TracePtr = (FindLevel > MAX_FIND_LEVEL) ? -1 : (FindLevel - 1); - if (TracePtr < 0) - NoWay(); - Time = 1; - } -*/ -} - - -void WALK::findWay(Sprite *spr) { - if (spr && spr != this) { - int x = spr->_x; - int z = spr->_z; - if (spr->_flags._east) - x += spr->_w + _w / 2 - WALKSIDE; - else - x -= _w / 2 - WALKSIDE; - findWay(Cluster((x / MAP_XGRID), - ((z < MAP_ZCNT - MAX_DISTANCE) ? (z + 1) - : (z - 1)))); - } -} - - -bool WALK::lower(Sprite *spr) { - return (spr->_y > _y + (_h * 3) / 5); -} - - -void WALK::reach(Sprite *spr, int mode) { - if (spr) { - _hero->findWay(spr); - if (mode < 0) { - mode = spr->_flags._east; - if (lower(spr)) - mode += 2; - } - } - // note: insert SNAIL commands in reverse order - SNINSERT(SNPAUSE, -1, 64, NULL); - SNINSERT(SNSEQ, -1, TSEQ + mode, this); - if (spr) { - SNINSERT(SNWAIT, -1, -1, _hero); /////--------$$$$$$$ - //SNINSERT(SNWALK, -1, -1, spr); - } - // sequence is not finished, - // now it is just at sprite appear (disappear) point -} - - class SQUARE : public Sprite { public: SQUARE(CGEEngine *vm); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index a60ba0515ea..bd57bd64bde 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -86,12 +86,6 @@ namespace CGE { #define BUTTON_NY 3 #define MINI_X 86 #define MINI_Y 162 -#define MAP_XCNT 40 -#define MAP_ZCNT 20 -#define MAP_TOP 80 -#define MAP_HIG 80 -#define MAP_XGRID (SCR_WID / MAP_XCNT) -#define MAP_ZGRID (MAP_HIG / MAP_ZCNT) #define LINE_MAX 512 #define USER_MAX 100 #define SHP_MAX 1024 @@ -129,40 +123,6 @@ private: }; -class Cluster : public Couple { -public: - static uint8 _map[MAP_ZCNT][MAP_XCNT]; - uint8 &cell(); - Cluster() : Couple() { } - Cluster(int a, int b) : Couple(a, b) { } - bool Protected(); -}; - - -class WALK : public Sprite { -public: - Cluster _here; - int _tracePtr; - - enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; - WALK(CGEEngine *vm, BMP_PTR *shpl); - void tick(); - void findWay(Cluster c); - void findWay(Sprite *spr); - int distance(Sprite *spr); - void turn(DIR d); - void park(); - bool lower(Sprite *spr); - void reach(Sprite *spr, int mode = -1); -private: - CGEEngine *_vm; - -}; - -Cluster XZ(int x, int y); -Cluster XZ(Couple xy); - -extern WALK *_hero; extern Vga *_vga; extern Heart *_heart; extern System *_sys; diff --git a/engines/cge/module.mk b/engines/cge/module.mk index 95ffd6d9061..584ab5a1b68 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -22,7 +22,8 @@ MODULE_OBJS := \ text.o \ vga13h.o \ vmenu.o \ - vol.o + vol.o \ + walk.o MODULE_DIRS += \ engines/cge diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 10d85bfc0f6..977103d7a1c 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -32,6 +32,7 @@ #include "cge/text.h" #include "cge/cge_main.h" #include "cge/events.h" +#include "cge/walk.h" namespace CGE { diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp new file mode 100644 index 00000000000..fc2ed277dbc --- /dev/null +++ b/engines/cge/walk.cpp @@ -0,0 +1,281 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "common/scummsys.h" +#include "cge/walk.h" +#include "cge/sound.h" +#include "cge/startup.h" +#include "cge/config.h" +#include "cge/vga13h.h" +#include "cge/snail.h" +#include "cge/text.h" +#include "cge/game.h" +#include "cge/events.h" +#include "cge/cfile.h" +#include "cge/vol.h" +#include "cge/talk.h" +#include "cge/vmenu.h" +#include "cge/gettext.h" +#include "cge/mixer.h" +#include "cge/cge_main.h" +#include "cge/cge.h" +#include "common/str.h" + +namespace CGE { + +WALK *_hero; +Cluster Trace[MAX_FIND_LEVEL]; +int FindLevel; + +uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; + + +uint8 &Cluster::cell() { + return _map[_b][_a]; +} + + +bool Cluster::Protected() { +/* + if (A == Barriers[Now]._vert || B == Barriers[Now]._horz) + return true; + + _DX = (MAP_ZCNT << 8) + MAP_XCNT; + _BX = (uint16) this; + + asm mov ax,1 + asm mov cl,[bx].(COUPLE)A + asm mov ch,[bx].(COUPLE)B + asm test cx,0x8080 // (A < 0) || (B < 0) + asm jnz xit + + asm cmp cl,dl + asm jge xit + asm cmp ch,dh + asm jge xit + + // if (A < 0 || A >= MAP_XCNT || B < 0 || B >= MAP_ZCNT) return true; + + asm mov al,dl + asm mul ch + asm xor ch,ch + asm add ax,cx + asm mov bx,ax + _BX += (uint16) Map; + //asm add bx,offset CLUSTER::Map + asm mov al,[bx] + asm and ax,0xFF + asm jz xit + asm mov ax,1 + + // return Map[B][A] != 0; + + xit: return _AX; + */ + + warning("STUB: CLUSTER::Protected()"); + return true; +} + + +Cluster XZ(int x, int y) { + if (y < MAP_TOP) + y = MAP_TOP; + + if (y > MAP_TOP + MAP_HIG - MAP_ZGRID) + y = MAP_TOP + MAP_HIG - MAP_ZGRID; + + return Cluster(x / MAP_XGRID, (y - MAP_TOP) / MAP_ZGRID); +} + + +Cluster XZ(Couple xy) { + signed char x, y; + xy.split(x, y); + return XZ(x, y); +} + +WALK::WALK(CGEEngine *vm, BMP_PTR *shpl) + : Sprite(vm, shpl), Dir(NO_DIR), _tracePtr(-1), _vm(vm) { +} + + +void WALK::tick() { + if (_flags._hide) + return; + + _here = XZ(_x + _w / 2, _y + _h); + + if (Dir != NO_DIR) { + Sprite *spr; + _sys->funTouch(); + for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { + if (distance(spr) < 2) { + if (!spr->_flags._near) { + _vm->feedSnail(spr, kNear); + spr->_flags._near = true; + } + } else { + spr->_flags._near = false; + } + } + } + + if (_flags._hold || _tracePtr < 0) + park(); + else { + if (_here == Trace[_tracePtr]) { + if (--_tracePtr < 0) + park(); + } else { + signed char dx, dz; + (Trace[_tracePtr] - _here).split(dx, dz); + DIR d = (dx) ? ((dx > 0) ? EE : WW) : ((dz > 0) ? SS : NN); + turn(d); + } + } + step(); + if ((Dir == WW && _x <= 0) || + (Dir == EE && _x + _w >= SCR_WID) || + (Dir == SS && _y + _w >= WORLD_HIG - 2)) + park(); + else { + signed char x; // dummy var + _here.split(x, _z); // take current Z position + SNPOST_(SNZTRIM, -1, 0, this); // update Hero's pos in show queue + } +} + + +int WALK::distance(Sprite *spr) { + int dx, dz; + dx = spr->_x - (_x + _w - WALKSIDE); + if (dx < 0) + dx = (_x + WALKSIDE) - (spr->_x + spr->_w); + + if (dx < 0) + dx = 0; + + dx /= MAP_XGRID; + dz = spr->_z - _z; + if (dz < 0) + dz = - dz; + + dx = dx * dx + dz * dz; + for (dz = 1; dz * dz < dx; dz++) + ; + + return dz - 1; +} + + +void WALK::turn(DIR d) { + DIR dir = (Dir == NO_DIR) ? SS : Dir; + if (d != Dir) { + step((d == dir) ? (1 + dir + dir) : (9 + 4 * dir + d)); + Dir = d; + } +} + + +void WALK::park() { + if (_time == 0) + ++_time; + + if (Dir != NO_DIR) { + step(9 + 4 * Dir + Dir); + Dir = NO_DIR; + _tracePtr = -1; + } +} + + +void WALK::findWay(Cluster c) { + /* + bool Find1Way(); + extern uint16 Target; + + if (c != _here) { + for (FindLevel = 1; FindLevel <= MAX_FIND_LEVEL; FindLevel++) { + signed char x, z; + _here.split(x, z); + Target = (z << 8) | x; + c.split(x, z); + _CX = (z << 8) | x; + if (Find1Way()) + break; + } + _tracePtr = (FindLevel > MAX_FIND_LEVEL) ? -1 : (FindLevel - 1); + if (_tracePtr < 0) + NoWay(); + Time = 1; + } + */ +} + + +void WALK::findWay(Sprite *spr) { + if (spr && spr != this) { + int x = spr->_x; + int z = spr->_z; + if (spr->_flags._east) + x += spr->_w + _w / 2 - WALKSIDE; + else + x -= _w / 2 - WALKSIDE; + findWay(Cluster((x / MAP_XGRID), + ((z < MAP_ZCNT - MAX_DISTANCE) ? (z + 1) + : (z - 1)))); + } +} + + +bool WALK::lower(Sprite *spr) { + return (spr->_y > _y + (_h * 3) / 5); +} + + +void WALK::reach(Sprite *spr, int mode) { + if (spr) { + _hero->findWay(spr); + if (mode < 0) { + mode = spr->_flags._east; + if (lower(spr)) + mode += 2; + } + } + // note: insert SNAIL commands in reverse order + SNINSERT(SNPAUSE, -1, 64, NULL); + SNINSERT(SNSEQ, -1, TSEQ + mode, this); + if (spr) { + SNINSERT(SNWAIT, -1, -1, _hero); /////--------$$$$$$$ + //SNINSERT(SNWALK, -1, -1, spr); + } + // sequence is not finished, + // now it is just at sprite appear (disappear) point +} + +} // End of namespace CGE diff --git a/engines/cge/walk.h b/engines/cge/walk.h new file mode 100644 index 00000000000..4573816bb45 --- /dev/null +++ b/engines/cge/walk.h @@ -0,0 +1,82 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#ifndef __CGE_WALK__ +#define __CGE_WALK__ + +#include "cge/wav.h" +#include "cge/vga13h.h" +#include "cge/events.h" + +namespace CGE { + +#define MAP_XCNT 40 +#define MAP_ZCNT 20 +#define MAP_TOP 80 +#define MAP_HIG 80 +#define MAP_XGRID (SCR_WID / MAP_XCNT) +#define MAP_ZGRID (MAP_HIG / MAP_ZCNT) + + +class Cluster : public Couple { +public: + static uint8 _map[MAP_ZCNT][MAP_XCNT]; + uint8 &cell(); + Cluster() : Couple() { } + Cluster(int a, int b) : Couple(a, b) { } + bool Protected(); +}; + + +class WALK : public Sprite { +public: + Cluster _here; + int _tracePtr; + + enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; + WALK(CGEEngine *vm, BMP_PTR *shpl); + void tick(); + void findWay(Cluster c); + void findWay(Sprite *spr); + int distance(Sprite *spr); + void turn(DIR d); + void park(); + bool lower(Sprite *spr); + void reach(Sprite *spr, int mode = -1); +private: + CGEEngine *_vm; + +}; + +Cluster XZ(int x, int y); +Cluster XZ(Couple xy); + +extern WALK *_hero; + +} // End of namespace CGE + +#endif From f0d10b62b37b7d3e35ebcd989745a2d0a9570a21 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 14 Jul 2011 22:36:18 +1000 Subject: [PATCH 133/276] CGE: In progress work on pathfinder --- engines/cge/cge.h | 1 - engines/cge/cge_main.cpp | 6 --- engines/cge/cge_main.h | 1 - engines/cge/general.h | 40 ------------------ engines/cge/walk.cpp | 89 ++++++++++++++++++++++++++++++++-------- engines/cge/walk.h | 51 ++++++++++++++++++++++- 6 files changed, 122 insertions(+), 66 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 7dd218e258a..dc757ec5a00 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -142,7 +142,6 @@ public: void trouble(int seq, int txt); void offUse(); void tooFar(); - void noWay(); void loadHeroXY(); void keyClick(); void switchColorMode(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 0e2bcc451c1..f532bd05e84 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -241,12 +241,6 @@ void CGEEngine::tooFar() { trouble(TOO_FAR, TOO_FAR_TEXT); } -// Used in stubbed function, do not remove! -void CGEEngine::noWay() { - trouble(NO_WAY, NO_WAY_TEXT); -} - - void CGEEngine::loadHeroXY() { INI_FILE cf(progName(".HXY")); memset(_heroXY, 0, sizeof(_heroXY)); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index bd57bd64bde..40e6d886685 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -92,7 +92,6 @@ namespace CGE { #define STD_DELAY 3 #define LEV_MAX 5 #define CAVE_MAX (CAVE_NX * CAVE_NY) -#define MAX_FIND_LEVEL 3 #define MAX_DISTANCE 3 #define INI_EXT ".INI" #define IN0_EXT ".IN0" diff --git a/engines/cge/general.h b/engines/cge/general.h index b4f73726eeb..0639fe2a017 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -49,46 +49,6 @@ struct Dac { typedef uint16 CRYPT(void *buf, uint16 siz, uint16 seed); -class Couple { -protected: - signed char _a; - signed char _b; -public: - Couple() { } - Couple(const signed char a, const signed char b) : _a(a), _b(b) { } - Couple operator + (Couple c) { - return Couple(_a + c._a, _b + c._b); - } - - void operator += (Couple c) { - _a += c._a; - _b += c._b; - } - - Couple operator - (Couple c) { - return Couple(_a - c._a, _b - c._b); - } - - void operator -= (Couple c) { - _a -= c._a; - _b -= c._b; - } - - bool operator == (Couple c) { - return ((_a - c._a) | (_b - c._b)) == 0; - } - - bool operator != (Couple c) { - return !(operator == (c)); - } - - void split(signed char &a, signed char &b) { - a = _a; - b = _b; - } -}; - - class Engine_ { protected: static void (* oldTimer)(...); diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index fc2ed277dbc..e33638b958a 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -48,8 +48,10 @@ namespace CGE { WALK *_hero; -Cluster Trace[MAX_FIND_LEVEL]; -int FindLevel; + +struct TabDir { + int xd, yd; +}; uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; @@ -58,6 +60,9 @@ uint8 &Cluster::cell() { return _map[_b][_a]; } +bool Cluster::isValid() const { + return (_a >= 0) && (_a < MAP_XCNT) && (_b >= 0) && (_b < MAP_ZCNT); +} bool Cluster::Protected() { /* @@ -148,12 +153,12 @@ void WALK::tick() { if (_flags._hold || _tracePtr < 0) park(); else { - if (_here == Trace[_tracePtr]) { + if (_here == _trace[_tracePtr]) { if (--_tracePtr < 0) park(); } else { signed char dx, dz; - (Trace[_tracePtr] - _here).split(dx, dz); + (_trace[_tracePtr] - _here).split(dx, dz); DIR d = (dx) ? ((dx > 0) ? EE : WW) : ((dz > 0) ? SS : NN); turn(d); } @@ -215,26 +220,23 @@ void WALK::park() { void WALK::findWay(Cluster c) { - /* - bool Find1Way(); - extern uint16 Target; - if (c != _here) { - for (FindLevel = 1; FindLevel <= MAX_FIND_LEVEL; FindLevel++) { + _level = 0; + + for (_findLevel = 1; _findLevel <= MAX_FIND_LEVEL; _findLevel++) { signed char x, z; _here.split(x, z); - Target = (z << 8) | x; + _target = (z << 8) | x; c.split(x, z); - _CX = (z << 8) | x; - if (Find1Way()) + + if (find1Way(XZ(x, z))) break; } - _tracePtr = (FindLevel > MAX_FIND_LEVEL) ? -1 : (FindLevel - 1); + _tracePtr = (_findLevel > MAX_FIND_LEVEL) ? -1 : (_findLevel - 1); if (_tracePtr < 0) - NoWay(); - Time = 1; + noWay(); + _time = 1; } - */ } @@ -278,4 +280,59 @@ void WALK::reach(Sprite *spr, int mode) { // now it is just at sprite appear (disappear) point } +void WALK::noWay() { + _vm->trouble(NO_WAY, NO_WAY_TEXT); +} + +bool WALK::find1Way(Cluster c) { + Cluster start = c; + const Cluster tab[4] = { Cluster(-1, 0), Cluster(1, 0), Cluster(0, -1), Cluster(0, 1)}; + const int tabLen = 4; + + if (c == _here) + // Found destination + return true; + + if (_level >= _findLevel) + // Nesting limit + return false; + + // Look for barriers + if (c.Protected()) + return false; + + if (c.cell()) + // Location is occupied + return false; + + + // Loop through each direction + for (int i = 0; i < tabLen; ++i) { + // Reset to starting position + c = start; + + do { + c += tab[i]; + if (!c.isValid()) + // Break to check next direction + break; + + // Recursively check for further paths + ++_level; + ++c.cell(); + bool foundPath = find1Way(c); + --c.cell(); + --_level; + + if (foundPath) { + // Set route point + _trace[_level] = start; + return true; + } + } while (c.Protected() && !c.cell()); + } + + return false; +} + } // End of namespace CGE diff --git a/engines/cge/walk.h b/engines/cge/walk.h index 4573816bb45..30eb727e2cd 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -40,7 +40,46 @@ namespace CGE { #define MAP_HIG 80 #define MAP_XGRID (SCR_WID / MAP_XCNT) #define MAP_ZGRID (MAP_HIG / MAP_ZCNT) +#define MAX_FIND_LEVEL 3 +class Couple { +protected: + signed char _a; + signed char _b; +public: + Couple() { } + Couple(const signed char a, const signed char b) : _a(a), _b(b) { } + Couple operator + (Couple c) { + return Couple(_a + c._a, _b + c._b); + } + + void operator += (Couple c) { + _a += c._a; + _b += c._b; + } + + Couple operator - (Couple c) { + return Couple(_a - c._a, _b - c._b); + } + + void operator -= (Couple c) { + _a -= c._a; + _b -= c._b; + } + + bool operator == (const Couple &c) { + return ((_a - c._a) | (_b - c._b)) == 0; + } + + bool operator != (Couple c) { + return !(operator == (c)); + } + + void split(signed char &a, signed char &b) { + a = _a; + b = _b; + } +}; class Cluster : public Couple { public: @@ -49,13 +88,21 @@ public: Cluster() : Couple() { } Cluster(int a, int b) : Couple(a, b) { } bool Protected(); + bool isValid() const; + }; class WALK : public Sprite { +private: + CGEEngine *_vm; public: Cluster _here; int _tracePtr; + int _level; + int _findLevel; + int _target; + Cluster _trace[MAX_FIND_LEVEL]; enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; WALK(CGEEngine *vm, BMP_PTR *shpl); @@ -67,9 +114,9 @@ public: void park(); bool lower(Sprite *spr); void reach(Sprite *spr, int mode = -1); -private: - CGEEngine *_vm; + void noWay(); + bool find1Way(Cluster c); }; Cluster XZ(int x, int y); From c3bed46ba06046c8ba76c12c42d016f63beb6331 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 15 Jul 2011 19:38:58 +1000 Subject: [PATCH 134/276] CGE: Fix for all the game objects being draggable --- engines/cge/events.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 9c1741189f5..73018aa2ea6 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -296,8 +296,11 @@ void EventManager::handleEvents() { _mouse->_hold = e._ptr; if (_mouse->_hold) { _mouse->_hold->_flags._hold = true; - _mouse->_hx = e._x - _mouse->_hold->_x; - _mouse->_hy = e._y - _mouse->_hold->_y; + + if (_mouse->_hold->_flags._drag) { + _mouse->_hx = e._x - _mouse->_hold->_x; + _mouse->_hy = e._y - _mouse->_hold->_y; + } } } @@ -315,8 +318,10 @@ void EventManager::handleEvents() { } EvtTail = (EvtTail + 1) % EVT_MAX; } - if (_mouse->_hold) - _mouse->_hold->gotoxy(_mouse->_x - _mouse->_hx, _mouse->_y - _mouse->_hy); + if (_mouse->_hold) { + if (_mouse->_hold->_flags._drag) + _mouse->_hold->gotoxy(_mouse->_x - _mouse->_hx, _mouse->_y - _mouse->_hy); + } } void EventManager::clrEvt(Sprite *spr) { From 11fa6b941c520129c017c946474114afa71fe41f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 15 Jul 2011 20:43:29 +1000 Subject: [PATCH 135/276] CGE: Fix some errors in the pathfinder setup --- engines/cge/cge.cpp | 2 ++ engines/cge/walk.cpp | 69 ++++++++++---------------------------------- engines/cge/walk.h | 8 +++-- 3 files changed, 24 insertions(+), 55 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 0861e3e7f29..e192774f45c 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -68,6 +68,7 @@ void CGEEngine::setup() { VFile::init(); Bitmap::init(); Talk::init(); + Cluster::init(this); // Initialise engine objects _text = new Text(this, progName(), 128); @@ -132,6 +133,7 @@ CGEEngine::~CGEEngine() { Bitmap::deinit(); VFile::deinit(); Vga::deinit(); + Cluster::init(this); // Remove all of our debug levels here DebugMan.clearAllDebugChannels(); diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index e33638b958a..0e31e2e5416 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -27,6 +27,7 @@ #include "common/scummsys.h" #include "cge/walk.h" +#include "cge/cge.h" #include "cge/sound.h" #include "cge/startup.h" #include "cge/config.h" @@ -47,14 +48,16 @@ namespace CGE { +extern Bar _barriers[]; + WALK *_hero; -struct TabDir { - int xd, yd; -}; - uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; +CGEEngine *Cluster::_vm; +void Cluster::init(CGEEngine *vm) { + _vm = vm; +} uint8 &Cluster::cell() { return _map[_b][_a]; @@ -64,49 +67,11 @@ bool Cluster::isValid() const { return (_a >= 0) && (_a < MAP_XCNT) && (_b >= 0) && (_b < MAP_ZCNT); } -bool Cluster::Protected() { -/* - if (A == Barriers[Now]._vert || B == Barriers[Now]._horz) - return true; - - _DX = (MAP_ZCNT << 8) + MAP_XCNT; - _BX = (uint16) this; - - asm mov ax,1 - asm mov cl,[bx].(COUPLE)A - asm mov ch,[bx].(COUPLE)B - asm test cx,0x8080 // (A < 0) || (B < 0) - asm jnz xit - - asm cmp cl,dl - asm jge xit - asm cmp ch,dh - asm jge xit - - // if (A < 0 || A >= MAP_XCNT || B < 0 || B >= MAP_ZCNT) return true; - - asm mov al,dl - asm mul ch - asm xor ch,ch - asm add ax,cx - asm mov bx,ax - _BX += (uint16) Map; - //asm add bx,offset CLUSTER::Map - asm mov al,[bx] - asm and ax,0xFF - asm jz xit - asm mov ax,1 - - // return Map[B][A] != 0; - - xit: return _AX; - */ - - warning("STUB: CLUSTER::Protected()"); - return true; +bool Cluster::chkBar() const { + assert(_vm->_now <= CAVE_MAX); + return (_a == _barriers[_vm->_now]._horz) && (_b == _barriers[_vm->_now]._vert); } - Cluster XZ(int x, int y) { if (y < MAP_TOP) y = MAP_TOP; @@ -125,7 +90,7 @@ Cluster XZ(Couple xy) { } WALK::WALK(CGEEngine *vm, BMP_PTR *shpl) - : Sprite(vm, shpl), Dir(NO_DIR), _tracePtr(-1), _vm(vm) { + : Sprite(vm, shpl), Dir(NO_DIR), _tracePtr(-1), _level(0), _vm(vm) { } @@ -221,15 +186,13 @@ void WALK::park() { void WALK::findWay(Cluster c) { if (c != _here) { - _level = 0; - for (_findLevel = 1; _findLevel <= MAX_FIND_LEVEL; _findLevel++) { signed char x, z; _here.split(x, z); - _target = (z << 8) | x; + _target = Couple(x, z); c.split(x, z); - if (find1Way(XZ(x, z))) + if (find1Way(Cluster(x, z))) break; } _tracePtr = (_findLevel > MAX_FIND_LEVEL) ? -1 : (_findLevel - 1); @@ -289,7 +252,7 @@ bool WALK::find1Way(Cluster c) { const Cluster tab[4] = { Cluster(-1, 0), Cluster(1, 0), Cluster(0, -1), Cluster(0, 1)}; const int tabLen = 4; - if (c == _here) + if (c == _target) // Found destination return true; @@ -298,7 +261,7 @@ bool WALK::find1Way(Cluster c) { return false; // Look for barriers - if (c.Protected()) + if (c.chkBar()) return false; if (c.cell()) @@ -329,7 +292,7 @@ bool WALK::find1Way(Cluster c) { _trace[_level] = start; return true; } - } while (c.Protected() && !c.cell()); + } while (c.chkBar() && !c.cell()); } return false; diff --git a/engines/cge/walk.h b/engines/cge/walk.h index 30eb727e2cd..eb29d9b4625 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -84,10 +84,14 @@ public: class Cluster : public Couple { public: static uint8 _map[MAP_ZCNT][MAP_XCNT]; + static CGEEngine *_vm; + + static void init(CGEEngine *vm); +public: uint8 &cell(); Cluster() : Couple() { } Cluster(int a, int b) : Couple(a, b) { } - bool Protected(); + bool chkBar() const; bool isValid() const; }; @@ -101,7 +105,7 @@ public: int _tracePtr; int _level; int _findLevel; - int _target; + Couple _target; Cluster _trace[MAX_FIND_LEVEL]; enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; From b74e1b6af026bf0420e548e7d63e11968041e9a2 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 15 Jul 2011 21:25:03 +1000 Subject: [PATCH 136/276] CGE: Pathfinder now works --- engines/cge/walk.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 0e31e2e5416..b35864f16ed 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -282,9 +282,9 @@ bool WALK::find1Way(Cluster c) { // Recursively check for further paths ++_level; - ++c.cell(); + ++start.cell(); bool foundPath = find1Way(c); - --c.cell(); + --start.cell(); --_level; if (foundPath) { @@ -292,7 +292,7 @@ bool WALK::find1Way(Cluster c) { _trace[_level] = start; return true; } - } while (c.chkBar() && !c.cell()); + } while (!c.chkBar() && !c.cell()); } return false; From 8c7130fdfaf6e7b6f93f158fc2399f81f2c12b71 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 15 Jul 2011 22:12:56 +1000 Subject: [PATCH 137/276] CGE: Fix display of in-game hotspot description --- engines/cge/talk.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 146c7206678..11dedf349b1 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -309,11 +309,22 @@ void InfoLine::update(const char *tx) { uint16 size = 4 * psiz; // whole map size // clear whole rectangle + byte *pDest; + memset(v + 2, TEXT_BG, dsiz); // data bytes + for (pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz) { + Common::copy(v, v + lsiz, pDest); + } + *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 + for (pDest = v + psiz; pDest < (v + 4 * psiz); pDest += psiz) { + Common::copy(v, v + psiz, pDest); + } + +/* memset(v + 2, TEXT_BG, dsiz); // data bytes memmove(v + lsiz, v, psiz - lsiz); *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 memmove(v + psiz, v, 3 * psiz); - +*/ // paint text line if (tx) { uint8 *p = v + 2, * q = p + size; From 4dd65c5e57df55edfabe4e71e487f164a9c5b150 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 15 Jul 2011 22:14:33 +1000 Subject: [PATCH 138/276] CGE: Removed some commented out code from previous bugfix --- engines/cge/talk.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 11dedf349b1..e2a5af5fde2 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -319,12 +319,6 @@ void InfoLine::update(const char *tx) { Common::copy(v, v + psiz, pDest); } -/* - memset(v + 2, TEXT_BG, dsiz); // data bytes - memmove(v + lsiz, v, psiz - lsiz); - *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 - memmove(v + psiz, v, 3 * psiz); -*/ // paint text line if (tx) { uint8 *p = v + 2, * q = p + size; From 453fbb7454b5e6d517febd29aea4e589c44247bf Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 15 Jul 2011 22:56:49 +1000 Subject: [PATCH 139/276] CGE: Bugfixes for loading the room preview shapes list --- engines/cge/cge.cpp | 3 +++ engines/cge/cge.h | 1 + engines/cge/cge_main.cpp | 2 -- engines/cge/snail.h | 2 +- engines/cge/startup.cpp | 3 --- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index e192774f45c..5c1bf2caf09 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -36,6 +36,7 @@ #include "cge/text.h" #include "cge/vol.h" #include "cge/walk.h" +#include "cge/startup.h" namespace CGE { @@ -95,6 +96,7 @@ void CGEEngine::setup() { _eventManager = new EventManager(); _offUseCount = atoi(_text->getText(OFF_USE_COUNT)); _music = true; + _mini = new byte[MINI_EMM_SIZE]; for (int i = 0; i < POCKET_NX; i++) _pocref[i] = -1; @@ -160,6 +162,7 @@ CGEEngine::~CGEEngine() { delete _snail; delete _snail_; delete _hero; + delete[] _mini; } Common::Error CGEEngine::run() { diff --git a/engines/cge/cge.h b/engines/cge/cge.h index dc757ec5a00..bb142515998 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -85,6 +85,7 @@ public: int _lev; Common::RandomSource _randomSource; + byte * _mini; virtual Common::Error run(); GUI::Debugger *getDebugger() { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index f532bd05e84..3c926a3f891 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -90,7 +90,6 @@ static char _usrFnam[15] = "\0ɱ%^ //-------------------------------------------------------------------------- -static Ems *_mini = _miniEmm.alloc((uint16)MINI_EMM_SIZE); static BMP_PTR *_miniShpList = NULL; static BMP_PTR _miniShp[] = { NULL, NULL }; static bool _finis = false; @@ -348,7 +347,6 @@ void CGEEngine::miniStep(int stp) { if (stp < 0) _miniCave->_flags._hide = true; else { - &*_mini; *_miniShp[0] = *_miniShpList[stp]; if (_fx._current) &*(_fx._current->eAddr()); diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 08f20b9d07f..e8578e2b3d5 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -48,7 +48,7 @@ namespace CGE { #define SNPOST_(c, r, v, p) _snail_->addCom(c, r, v, p) #define SNPOST2_(c, r, v, p) _snail_->addCom2(c, r, v, p) -#define SNAIL_FRAME_RATE 62 +#define SNAIL_FRAME_RATE 80 #define SNAIL_FRAME_DELAY (1000 / SNAIL_FRAME_RATE) struct Bar { diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 9210b40c775..37c6b4f62ec 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -37,9 +37,6 @@ extern char _copr[]; #define id (*(Ident*)_copr) - -Emm _miniEmm = MINI_EMM_SIZE; - // static Startup _startUp; int Startup::_mode = 0; From c3f3120194151cdeb31d9b3622c76cd4e5b7ed6a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 16 Jul 2011 15:17:18 +1000 Subject: [PATCH 140/276] CGE: Cleaned up room preview handling code and fixed memory leak --- engines/cge/cge.cpp | 5 +++-- engines/cge/cge.h | 4 +++- engines/cge/cge_main.cpp | 6 ++++-- engines/cge/vga13h.cpp | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 5c1bf2caf09..6924f0b14e6 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -60,6 +60,9 @@ void CGEEngine::setup() { _lastFrame = 0; _hero = NULL; _shadow = NULL; + _miniCave = NULL; + _miniShp = NULL; + _miniShpList = NULL; // Create debugger console _console = new CGEConsole(this); @@ -82,8 +85,6 @@ void CGEEngine::setup() { _pocket[i]->_flags._kill = false; } _sprite = new Sprite(this, NULL); - _miniCave = new Sprite(this, NULL); - _miniCave->_flags._kill = false; _horzLine = new HorizLine(this); _infoLine = new InfoLine(this, INFO_W); _cavLight = new CavLight(this); diff --git a/engines/cge/cge.h b/engines/cge/cge.h index bb142515998..9894cc07bc7 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -85,7 +85,9 @@ public: int _lev; Common::RandomSource _randomSource; - byte * _mini; + byte * _mini; + BMP_PTR * _miniShp; + BMP_PTR * _miniShpList; virtual Common::Error run(); GUI::Debugger *getDebugger() { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 3c926a3f891..e518c668f4c 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -90,8 +90,6 @@ static char _usrFnam[15] = "\0ɱ%^ //-------------------------------------------------------------------------- -static BMP_PTR *_miniShpList = NULL; -static BMP_PTR _miniShp[] = { NULL, NULL }; static bool _finis = false; int _offUseCount; uint16 *_intStackPtr = false; @@ -1364,11 +1362,15 @@ void CGEEngine::runGame() { killMidi(); if (_mini && INI_FILE::exist("MINI.SPR")) { + _miniShp = new BMP_PTR[2]; + _miniShp[0] = _miniShp[1] = NULL; + uint8 *ptr = (uint8 *) &*_mini; if (ptr != NULL) { loadSprite("MINI", -1, 0, MINI_X, MINI_Y); expandSprite(_miniCave = _sprite); // NULL is ok if (_miniCave) { + _miniCave->_flags._kill = false; _miniCave->_flags._hide = true; _miniCave->moveShapes(ptr); _miniShp[0] = new Bitmap(*_miniCave->shp()); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index ec616a2551c..716a6b584dc 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1378,4 +1378,4 @@ PocLight::PocLight(CGEEngine *vm): Sprite(vm, NULL) { _flags._kill = false; } -} // End of namespace CGE +} // End of namespace CGE \ No newline at end of file From b957eda759c060048ca2c1d371105c64776d1207 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 16 Jul 2011 15:30:06 +1000 Subject: [PATCH 141/276] CGE: Map keypad Enter to be handled like the main Enter key --- engines/cge/events.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 73018aa2ea6..eba043cdc8e 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -104,6 +104,10 @@ bool Keyboard::getKey(uint16 keycode, int &cgeCode) { cgeCode = 29; return true; } + if (keycode == Common::KEYCODE_KP_ENTER) { + cgeCode = 28; + return true; + } // Scan through the ScummVM mapping list for (int idx = 0; idx < 0x60; ++idx) { From 50d313a547ae1bec050be8d6b64ccc01161da22f Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 16 Jul 2011 15:44:17 +1000 Subject: [PATCH 142/276] CGE: Implement monochrome view mode button --- engines/cge/cge_main.cpp | 1 - engines/cge/vga13h.cpp | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index e518c668f4c..b43360c0b53 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -299,7 +299,6 @@ void CGEEngine::setMapBrick(int x, int z) { } } -//static void switchColorMode(); //static void switchDebug(); //static void pullSprite(); //static void NextStep(); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 716a6b584dc..a7b9d8c0804 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1128,9 +1128,9 @@ void Vga::setColors(Dac *tab, int lum) { if (_mono) { destP = _newColors; - for (int idx = 0; idx < PAL_CNT; ++idx, ++palP) { + for (int idx = 0; idx < PAL_CNT; ++idx, ++destP) { // Form a greyscalce colour from 30% R, 59% G, 11% B - uint8 intensity = (destP->_r * 77) + (destP->_g * 151) + (destP->_b * 28); + uint8 intensity = (((int)destP->_r * 77) + ((int)destP->_g * 151) + ((int)destP->_b * 28)) >> 8; destP->_r = intensity; destP->_g = intensity; destP->_b = intensity; From 10627dccfa51eefccc6aa2a468f3a2fa246e88b6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 16 Jul 2011 16:23:34 +1000 Subject: [PATCH 143/276] CGE: Fix the selection of menu items to call appropriate dispatch method --- engines/cge/vmenu.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index f8029166572..0c0e1fb8554 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -127,6 +127,7 @@ Vmenu::~Vmenu() { _addr = NULL; } +#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) void Vmenu::touch(uint16 mask, int x, int y) { uint16 h = FONT_HIG + TEXT_LS; @@ -150,8 +151,9 @@ void Vmenu::touch(uint16 mask, int x, int y) { if (ok && (mask & L_UP)) { _items = 0; SNPOST_(SNKILL, -1, 0, this); - //_menu[_recent = n].Proc(); - warning("Missing call to proc()"); + _recent = n; + assert(_menu[n].Proc); + CALL_MEMBER_FN(*_vm, _menu[n].Proc)(); } } } From ce070cdd3c664bc5fca80770a40e669fd07a83a0 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 16 Jul 2011 18:33:20 +1000 Subject: [PATCH 144/276] CGE: Implemented basic savegame support I've slightly modified the behaviour of the original - rather than prompting each time the user starts for a name, it now only prompts the first time, and uses the entered name as a save description for a slot 0 savegame --- engines/cge/cge.h | 23 ++- engines/cge/cge_main.cpp | 314 +++++++++++++++++++++++++++++---------- 2 files changed, 253 insertions(+), 84 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 9894cc07bc7..2d67b2218a2 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -25,7 +25,9 @@ #include "cge/general.h" #include "common/random.h" +#include "common/savefile.h" #include "common/serializer.h" +#include "common/str.h" #include "engines/engine.h" #include "gui/debugger.h" #include "graphics/surface.h" @@ -56,11 +58,27 @@ enum CallbackType { #define POCKET_NX 8 +#define CGE_SAVEGAME_VERSION 1 + +struct SavegameHeader { + uint8 version; + Common::String saveName; + Graphics::Surface *thumbnail; + int saveYear, saveMonth, saveDay; + int saveHour, saveMinutes; + int totalFrames; +}; + class CGEEngine : public Engine { private: uint32 _lastFrame; void tick(); void syncHeader(Common::Serializer &s); + bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header); + void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header); + void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream, bool tiny = false); + bool savegameExists(int slotNumber); + Common::String generateSaveName(int slot); public: CGEEngine(OSystem *syst, const ADGameDescription *gameDescription); ~CGEEngine(); @@ -83,6 +101,7 @@ public: bool _game; int _now; int _lev; + char _usrFnam[15]; Common::RandomSource _randomSource; byte * _mini; @@ -100,7 +119,7 @@ public: void quit(); void resetQSwitch(); void optionTouch(int opt, uint16 mask); - void loadGame(XFile &file, bool tiny); + bool loadGame(int slotNumber, SavegameHeader *header = NULL, bool tiny = false); void setMapBrick(int x, int z); void switchMapping(); void loadSprite(const char *fname, int ref, int cav, int col, int row, int pos); @@ -129,7 +148,7 @@ public: void setIRQ(); void setDMA(); void mainLoop(); - void saveGame(Common::WriteStream *file); + void saveGame(int slotNumber, const Common::String &desc); void switchMusic(); void selectPocket(int n); void expandSprite(Sprite *spr); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index b43360c0b53..3ea82e30997 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -30,6 +30,9 @@ #include "common/savefile.h" #include "common/serializer.h" #include "common/str.h" +#include "graphics/palette.h" +#include "graphics/scaler.h" +#include "graphics/thumbnail.h" #include "cge/general.h" #include "cge/sound.h" #include "cge/startup.h" @@ -86,7 +89,8 @@ Snail *_snail_; // 1.01 - 17VII95 - default savegame with sound ON // coditionals EVA for 2-month evaluation version -static char _usrFnam[15] = "\0ɱ%^þúȼ´ ÇÉ"; +const char *SAVEGAME_STR = "SCUMMVM_CGE"; +#define SAVEGAME_STR_SIZE 11 //-------------------------------------------------------------------------- @@ -137,84 +141,237 @@ void CGEEngine::syncHeader(Common::Serializer &s) { } } -void CGEEngine::loadGame(XFile &file, bool tiny = false) { - Sprite *spr; - int i; +bool CGEEngine::loadGame(int slotNumber, SavegameHeader *header, bool tiny) { + Common::MemoryReadStream *readStream; + SavegameHeader saveHeader; - // Read the data into a data buffer - int size = file.size() - file.mark(); - byte *dataBuffer = (byte *)malloc(size); - file.read(dataBuffer, size); - Common::MemoryReadStream readStream(dataBuffer, size, DisposeAfterUse::YES); - Common::Serializer s(&readStream, NULL); + if (slotNumber == -1) { + // Loading the data for the initial game state + SVG0FILE file = SVG0FILE(SVG0NAME); + int size = file.size(); + byte *dataBuffer = (byte *)malloc(size); + file.read(dataBuffer, size); + readStream = new Common::MemoryReadStream(dataBuffer, size, DisposeAfterUse::YES); - // Synchronise header data - syncHeader(s); + } else { + // Open up the savgame file + Common::String slotName = generateSaveName(slotNumber); + Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(slotName); - if (Startup::_core < CORE_HIG) - _music = false; - - if (Startup::_soundOk == 1 && Startup::_mode == 0) { - _sndDrvInfo.Vol2._d = _volume[0]; - _sndDrvInfo.Vol2._m = _volume[1]; - sndSetVolume(); + // Read the data into a data buffer + int size = saveFile->size(); + byte *dataBuffer = (byte *)malloc(size); + saveFile->read(dataBuffer, size); + readStream = new Common::MemoryReadStream(dataBuffer, size, DisposeAfterUse::YES); } - if (! tiny) { // load sprites & pocket - while (readStream.pos() < readStream.size()) { - Sprite S(this, NULL); - S.sync(s); + // Check to see if it's a ScummVM savegame or not + char buffer[SAVEGAME_STR_SIZE + 1]; + readStream->read(buffer, SAVEGAME_STR_SIZE + 1); - S._prev = S._next = NULL; - spr = (scumm_stricmp(S._file + 2, "MUCHA") == 0) ? new Fly(this, NULL) - : new Sprite(this, NULL); - if (spr == NULL) - error("No core"); - *spr = S; - _vga->_spareQ->append(spr); + if (strncmp(buffer, SAVEGAME_STR, SAVEGAME_STR_SIZE + 1) != 0) { + // It's not, so rewind back to the start + readStream->seek(0); + + if (header) + // Header wanted where none exists, so return false + return false; + } else { + // Found header + if (!readSavegameHeader(readStream, saveHeader)) { + delete readStream; + return false; } - for (i = 0; i < POCKET_NX; i++) { - register int r = _pocref[i]; - delete _pocket[i]; - _pocket[i] = (r < 0) ? NULL : _vga->_spareQ->locate(r); + if (header) { + *header = saveHeader; + delete readStream; + return true; } + + // Delete the thumbnail + delete saveHeader.thumbnail; + + // If we're loading the auto-save slot, load the name + if (slotNumber == 0) + strncpy(_usrFnam, saveHeader.saveName.c_str(), 8); } + + // Get in the savegame + syncGame(readStream, NULL, tiny); + + delete readStream; + return true; } +/** + * Returns true if a given savegame exists + */ +bool CGEEngine::savegameExists(int slotNumber) { + Common::String slotName = generateSaveName(slotNumber); + + Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(slotName); + bool result = saveFile != NULL; + delete saveFile; + return result; +} + +/** + * Support method that generates a savegame name + * @param slot Slot number + */ +Common::String CGEEngine::generateSaveName(int slot) { + return Common::String::format("%s.%03d", _targetName.c_str(), slot); +} void CGEEngine::saveSound() { + warning("STUB: CGEEngine::saveSound"); + /* Convert to saving any such needed data in ScummVM configuration file + CFile cfg(usrPath(progName(CFG_EXT)), WRI); if (!cfg._error) cfg.write(&_sndDrvInfo, sizeof(_sndDrvInfo) - sizeof(_sndDrvInfo.Vol2)); + */ } +void CGEEngine::saveGame(int slotNumber, const Common::String &desc) { + // Set up the serializer + Common::String slotName = generateSaveName(slotNumber); + Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(slotName); -void CGEEngine::saveGame(Common::WriteStream *file) { + // Write out the ScummVM savegame header + SavegameHeader header; + header.saveName = desc; + header.version = CGE_SAVEGAME_VERSION; + writeSavegameHeader(saveFile, header); + + // Write out the data of the savegame + syncGame(NULL, saveFile); + + // Finish writing out game data + saveFile->finalize(); + delete saveFile; +} + +void CGEEngine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header) { + // Write out a savegame header + out->write(SAVEGAME_STR, SAVEGAME_STR_SIZE + 1); + + out->writeByte(CGE_SAVEGAME_VERSION); + + // Write savegame name + out->write(header.saveName.c_str(), header.saveName.size() + 1); + + // Get the active palette + uint8 thumbPalette[256 * 3]; + g_system->getPaletteManager()->grabPalette(thumbPalette, 0, 256); + + // Create a thumbnail and save it + Graphics::Surface *thumb = new Graphics::Surface(); + Graphics::Surface *s = _vga->_page[1]; + ::createThumbnail(thumb, (const byte *)s->pixels, SCR_WID, SCR_HIG, thumbPalette); + Graphics::saveThumbnail(*out, *thumb); + delete thumb; + + // Write out the save date/time + TimeDate td; + g_system->getTimeAndDate(td); + out->writeSint16LE(td.tm_year + 1900); + out->writeSint16LE(td.tm_mon + 1); + out->writeSint16LE(td.tm_mday); + out->writeSint16LE(td.tm_hour); + out->writeSint16LE(td.tm_min); +} + +void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream, bool tiny) { Sprite *spr; int i; - for (i = 0; i < POCKET_NX; i++) { - register Sprite *s = _pocket[i]; - _pocref[i] = (s) ? s->_ref : -1; + Common::Serializer s(readStream, writeStream); + + if (s.isSaving()) { + for (i = 0; i < POCKET_NX; i++) { + register Sprite *s = _pocket[i]; + _pocref[i] = (s) ? s->_ref : -1; + } + + _volume[0] = _sndDrvInfo.Vol2._d; + _volume[1] = _sndDrvInfo.Vol2._m; } - _volume[0] = _sndDrvInfo.Vol2._d; - _volume[1] = _sndDrvInfo.Vol2._m; - - Common::Serializer s(NULL, file); - // Synchronise header data syncHeader(s); - // Loop through saving the sprite data - for (spr = _vga->_spareQ->first(); spr; spr = spr->_next) { - if ((spr->_ref >= 1000) && !s.err()) - spr->sync(s); + if (s.isSaving()) { + // Loop through saving the sprite data + for (spr = _vga->_spareQ->first(); spr; spr = spr->_next) { + if ((spr->_ref >= 1000) && !s.err()) + spr->sync(s); + } + } else { + // Loading game + if (Startup::_core < CORE_HIG) + _music = false; + + if (Startup::_soundOk == 1 && Startup::_mode == 0) { + _sndDrvInfo.Vol2._d = _volume[0]; + _sndDrvInfo.Vol2._m = _volume[1]; + sndSetVolume(); + } + + if (! tiny) { // load sprites & pocket + while (readStream->pos() < readStream->size()) { + Sprite S(this, NULL); + S.sync(s); + + S._prev = S._next = NULL; + spr = (scumm_stricmp(S._file + 2, "MUCHA") == 0) ? new Fly(this, NULL) + : new Sprite(this, NULL); + if (spr == NULL) + error("No core"); + *spr = S; + _vga->_spareQ->append(spr); + } + + for (i = 0; i < POCKET_NX; i++) { + register int r = _pocref[i]; + delete _pocket[i]; + _pocket[i] = (r < 0) ? NULL : _vga->_spareQ->locate(r); + } + } + } +} + +bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header) { + header.thumbnail = NULL; + + // Get the savegame version + header.version = in->readByte(); + if (header.version > CGE_SAVEGAME_VERSION) + return false; + + // Read in the string + header.saveName.clear(); + char ch; + while ((ch = (char)in->readByte()) != '\0') header.saveName += ch; + + // Get the thumbnail + header.thumbnail = new Graphics::Surface(); + if (!Graphics::loadThumbnail(*in, *header.thumbnail)) { + delete header.thumbnail; + header.thumbnail = NULL; + return false; } - // Finish writing out game data - file->finalize(); + // Read in save date/time + header.saveYear = in->readSint16LE(); + header.saveMonth = in->readSint16LE(); + header.saveDay = in->readSint16LE(); + header.saveHour = in->readSint16LE(); + header.saveMinutes = in->readSint16LE(); + + return true; + } void CGEEngine::heroCover(int cvr) { @@ -483,9 +640,7 @@ void CGEEngine::qGame() { saveSound(); // Write out the user's progress - Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving(Common::String(_usrFnam)); - saveGame(saveFile); - delete saveFile; + saveGame(0, _usrFnam); _vga->sunset(); _finis = true; @@ -773,6 +928,7 @@ void CGEEngine::takeName() { if (GetText::_ptr) SNPOST_(SNKILL, -1, 0, GetText::_ptr); else { + memset(_usrFnam, 0, 15); GetText *tn = new GetText(this, _text->getText(GETNAME_PROMPT), _usrFnam, 8); if (tn) { tn->setName(_text->getText(GETNAME_TITLE)); @@ -1290,25 +1446,15 @@ void CGEEngine::tick() { void CGEEngine::loadUser() { // set scene - if (Startup::_mode == 0) { // user .SVG file found - CFile cfile = CFile(usrPath(_usrFnam), REA, RCrypt); - loadGame(cfile); + if (Startup::_mode == 0) { + // user .SVG file found - load it from slot 0 + loadGame(0, NULL); } else { if (Startup::_mode == 1) { - SVG0FILE file = SVG0FILE(SVG0NAME); - loadGame(file); + // Load initial game state savegame + loadGame(-1, NULL); } else { - // TODO: I think this was only used by the original developers to create the initial - // game state savegame. Verify this is the case, and if so remove this block - loadScript(progName(INI_EXT)); - _music = true; - - Common::OutSaveFile *saveFile = g_system->getSavefileManager()->openForSaving( - Common::String(SVG0NAME)); - saveGame(saveFile); - delete saveFile; - - error("Ok [%s]", SVG0NAME); + error("Creating setup savegames not supported"); } } loadScript(progName(IN0_EXT)); @@ -1533,17 +1679,22 @@ bool CGEEngine::showTitle(const char *name) { _vga->copyPage(0, 1); _vga->_showQ->append(_mouse); //Mouse.On(); - _heart->_enable = true; - for (takeName(); GetText::_ptr;) { - mainLoop(); - if (_eventManager->_quitFlag) - return false; - } - _heart->_enable = false; - if (_keyboard->last() == Enter && *_usrFnam) + + // For ScummVM, skip prompting for name if a savegame in slot 0 already exists + if (savegameExists(0)) { + strcpy(_usrFnam, "User"); usr_ok = true; - if (usr_ok) - strcat(_usrFnam, SVG_EXT); + } else { + _heart->_enable = true; + for (takeName(); GetText::_ptr;) { + mainLoop(); + if (_eventManager->_quitFlag) + return false; + } + _heart->_enable = false; + if (_keyboard->last() == Enter && *_usrFnam) + usr_ok = true; + } //Mouse.Off(); _vga->_showQ->clear(); _vga->copyPage(0, 2); @@ -1551,10 +1702,9 @@ bool CGEEngine::showTitle(const char *name) { } if (usr_ok && Startup::_mode == 0) { - const char *n = usrPath(_usrFnam); - if (CFile::exist(n)) { - CFile file = CFile(n, REA, RCrypt); - loadGame(file, true); // only system vars + if (savegameExists(0)) { + // Load the savegame + loadGame(0, NULL, true); // only system vars _vga->setColors(Vga::_sysPal, 64); _vga->update(); if (_flag[3]) { //flag FINIS From 00061bc5dd6492fcb3be9781b134f1928f69205b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 16 Jul 2011 21:12:19 +1000 Subject: [PATCH 145/276] CGE: Added support for GMM save/load and launcher loading --- engines/cge/cge.cpp | 20 +++++++-- engines/cge/cge.h | 13 +++++- engines/cge/cge_main.cpp | 51 +++++++++++++++++----- engines/cge/detection.cpp | 90 ++++++++++++++++----------------------- 4 files changed, 105 insertions(+), 69 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 6924f0b14e6..bb5b7863308 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -126,6 +126,7 @@ void CGEEngine::setup() { for (int i = 0; i < 4; i++) _flag[i] = false; + _startGameSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1; } CGEEngine::~CGEEngine() { @@ -173,12 +174,25 @@ Common::Error CGEEngine::run() { // Setup necessary game objects setup(); - // Additional setup. - debug("CGEEngine::init"); - + // Run the game cge_main(); return Common::kNoError; } +bool CGEEngine::hasFeature(EngineFeature f) const { + return + (f == kSupportsRTL) || + (f == kSupportsLoadingDuringRuntime) || + (f == kSupportsSavingDuringRuntime); +} + +bool CGEEngine::canLoadGameStateCurrently() { + return (_startupMode == 0) && _mouse->_active; +} + +bool CGEEngine::canSaveGameStateCurrently() { + return (_startupMode == 0) && _mouse->_active; +} + } // End of namespace CGE diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 2d67b2218a2..851a1166abd 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -69,19 +69,26 @@ struct SavegameHeader { int totalFrames; }; +extern const char *SAVEGAME_STR; +#define SAVEGAME_STR_SIZE 11 + class CGEEngine : public Engine { private: uint32 _lastFrame; void tick(); void syncHeader(Common::Serializer &s); - bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header); - void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header); + static void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header); void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream, bool tiny = false); bool savegameExists(int slotNumber); Common::String generateSaveName(int slot); public: CGEEngine(OSystem *syst, const ADGameDescription *gameDescription); ~CGEEngine(); + virtual bool hasFeature(EngineFeature f) const; + virtual bool canLoadGameStateCurrently(); + virtual bool canSaveGameStateCurrently(); + virtual Common::Error loadGameState(int slot); + virtual Common::Error saveGameState(int slot, const Common::String &desc); const ADGameDescription *_gameDescription; bool _isDemo; @@ -107,6 +114,7 @@ public: byte * _mini; BMP_PTR * _miniShp; BMP_PTR * _miniShpList; + int _startGameSlot; virtual Common::Error run(); GUI::Debugger *getDebugger() { @@ -149,6 +157,7 @@ public: void setDMA(); void mainLoop(); void saveGame(int slotNumber, const Common::String &desc); + static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header); void switchMusic(); void selectPocket(int n); void expandSprite(Sprite *spr); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 3ea82e30997..f3b2784ca67 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -224,6 +224,24 @@ Common::String CGEEngine::generateSaveName(int slot) { return Common::String::format("%s.%03d", _targetName.c_str(), slot); } +Common::Error CGEEngine::loadGameState(int slot) { + // Clear current game activity + caveDown(); + + // Load the game + loadGame(slot, NULL, true); + caveUp(); + loadGame(slot, NULL); + + return Common::kNoError; +} + +Common::Error CGEEngine::saveGameState(int slot, const Common::String &desc) { + saveGame(slot, desc); + return Common::kNoError; +} + + void CGEEngine::saveSound() { warning("STUB: CGEEngine::saveSound"); /* Convert to saving any such needed data in ScummVM configuration file @@ -268,7 +286,7 @@ void CGEEngine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &he // Create a thumbnail and save it Graphics::Surface *thumb = new Graphics::Surface(); - Graphics::Surface *s = _vga->_page[1]; + Graphics::Surface *s = _vga->_page[0]; ::createThumbnail(thumb, (const byte *)s->pixels, SCR_WID, SCR_HIG, thumbPalette); Graphics::saveThumbnail(*out, *thumb); delete thumb; @@ -1451,8 +1469,8 @@ void CGEEngine::loadUser() { loadGame(0, NULL); } else { if (Startup::_mode == 1) { - // Load initial game state savegame - loadGame(-1, NULL); + // Load either initial game state savegame or launcher specified savegame + loadGame(_startGameSlot, NULL); } else { error("Creating setup savegames not supported"); } @@ -1681,7 +1699,7 @@ bool CGEEngine::showTitle(const char *name) { //Mouse.On(); // For ScummVM, skip prompting for name if a savegame in slot 0 already exists - if (savegameExists(0)) { + if ((_startGameSlot == -1) && savegameExists(0)) { strcpy(_usrFnam, "User"); usr_ok = true; } else { @@ -1755,18 +1773,29 @@ void CGEEngine::cge_main() { if (_music && Startup::_soundOk) loadMidi(0); - if (Startup::_mode < 2) - movie(LGO_EXT); - if (showTitle("WELCOME")) { - if ((!_isDemo) && (Startup::_mode == 1)) - movie("X02"); // intro + if (_startGameSlot != -1) { + // Starting up a savegame from the launcher + Startup::_mode++; runGame(); + _startupMode = 2; if (_flag[3]) // Flag FINIS movie("X03"); - } else - _vga->sunset(); + } else { + if (Startup::_mode < 2) + movie(LGO_EXT); + + if (showTitle("WELCOME")) { + if ((!_isDemo) && (Startup::_mode == 1)) + movie("X02"); // intro + runGame(); + _startupMode = 2; + if (_flag[3]) // Flag FINIS + movie("X03"); + } else + _vga->sunset(); + } } } // End of namespace CGE diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index 31bf629fcfa..24fd3d2043b 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -103,6 +103,8 @@ public: return "Soltys (c) 1994-1996 L.K. Avalon"; } + + virtual bool hasFeature(MetaEngineFeature f) const; virtual bool createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const; virtual int getMaximumSaveSlot() const; @@ -146,25 +148,26 @@ SaveStateList CGEMetaEngine::listSaves(const char *target) const { slotNum = atoi(filename->c_str() + filename->size() - 3); if (slotNum >= 0 && slotNum <= 99) { + Common::InSaveFile *file = saveFileMan->openForLoading(*filename); if (file) { - int32 version = file->readSint32BE(); - if (version != CGE_SAVEGAME_VERSION) { - delete file; - continue; + CGE::SavegameHeader header; + + // Check to see if it's a ScummVM savegame or not + char buffer[SAVEGAME_STR_SIZE + 1]; + file->read(buffer, SAVEGAME_STR_SIZE + 1); + + if (!strncmp(buffer, CGE::SAVEGAME_STR, SAVEGAME_STR_SIZE + 1)) { + // Valid savegame + if (CGE::CGEEngine::readSavegameHeader(file, header)) { + saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); + delete header.thumbnail; + } + } else { + // Must be an original format savegame + saveList.push_back(SaveStateDescriptor(slotNum, "Unknown")); } - // read name - uint16 nameSize = file->readUint16BE(); - if (nameSize >= 255) { - delete file; - continue; - } - char name[256]; - file->read(name, nameSize); - name[nameSize] = 0; - - saveList.push_back(SaveStateDescriptor(slotNum, name)); delete file; } } @@ -175,53 +178,34 @@ SaveStateList CGEMetaEngine::listSaves(const char *target) const { SaveStateDescriptor CGEMetaEngine::querySaveMetaInfos(const char *target, int slot) const { Common::String fileName = Common::String::format("%s.%03d", target, slot); - Common::InSaveFile *file = g_system->getSavefileManager()->openForLoading(fileName); + Common::InSaveFile *f = g_system->getSavefileManager()->openForLoading(fileName); + assert(f); - if (file) { + CGE::SavegameHeader header; - int32 version = file->readSint32BE(); - if (version != CGE_SAVEGAME_VERSION) { - delete file; - return SaveStateDescriptor(); - } + // Check to see if it's a ScummVM savegame or not + char buffer[SAVEGAME_STR_SIZE + 1]; + f->read(buffer, SAVEGAME_STR_SIZE + 1); - uint32 saveNameLength = file->readUint16BE(); - char saveName[256]; - file->read(saveName, saveNameLength); - saveName[saveNameLength] = 0; - - SaveStateDescriptor desc(slot, saveName); - - Graphics::Surface *thumbnail = new Graphics::Surface(); - assert(thumbnail); - if (!Graphics::loadThumbnail(*file, *thumbnail)) { - delete thumbnail; - thumbnail = 0; - } - desc.setThumbnail(thumbnail); + bool hasHeader = !strncmp(buffer, CGE::SAVEGAME_STR, SAVEGAME_STR_SIZE + 1) && + CGE::CGEEngine::readSavegameHeader(f, header); + delete f; + if (!hasHeader) { + // Original savegame perhaps? + SaveStateDescriptor desc(slot, "Unknown"); + return desc; + } else { + // Create the return descriptor + SaveStateDescriptor desc(slot, header.saveName); desc.setDeletableFlag(true); desc.setWriteProtectedFlag(false); + desc.setThumbnail(header.thumbnail); + desc.setSaveDate(header.saveYear, header.saveMonth, header.saveDay); + desc.setSaveTime(header.saveHour, header.saveMinutes); - uint32 saveDate = file->readUint32BE(); - uint16 saveTime = file->readUint16BE(); - - int day = (saveDate >> 24) & 0xFF; - int month = (saveDate >> 16) & 0xFF; - int year = saveDate & 0xFFFF; - - desc.setSaveDate(year, month, day); - - int hour = (saveTime >> 8) & 0xFF; - int minutes = saveTime & 0xFF; - - desc.setSaveTime(hour, minutes); - - delete file; return desc; } - - return SaveStateDescriptor(); } bool CGEMetaEngine::createInstance(OSystem *syst, Engine **engine, const ADGameDescription *desc) const { From e1df646ace3f0b487ef810a5489c3f0c2090da71 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 16 Jul 2011 22:28:49 +1000 Subject: [PATCH 146/276] CGE: Set up a separate variable for the game tick speed, independent from frame rate --- engines/cge/cge.cpp | 1 + engines/cge/cge.h | 3 ++- engines/cge/cge_main.cpp | 25 ++++++++++++++++++++----- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index bb5b7863308..97712591fa5 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -58,6 +58,7 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) void CGEEngine::setup() { // Initialise fields _lastFrame = 0; + _lastTick = 0; _hero = NULL; _shadow = NULL; _miniCave = NULL; diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 851a1166abd..5187e57c0fd 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -74,7 +74,7 @@ extern const char *SAVEGAME_STR; class CGEEngine : public Engine { private: - uint32 _lastFrame; + uint32 _lastFrame, _lastTick; void tick(); void syncHeader(Common::Serializer &s); static void writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header); @@ -156,6 +156,7 @@ public: void setIRQ(); void setDMA(); void mainLoop(); + void handleFrame(); void saveGame(int slotNumber, const Common::String &desc); static bool readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header); void switchMusic(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index f3b2784ca67..ad31a5c1e6e 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1411,6 +1411,7 @@ void CGEEngine::loadScript(const char *fname) { } #define GAME_FRAME_DELAY (1000 / 50) +#define GAME_TICK_DELAY (1000 / 62) void CGEEngine::mainLoop() { sayDebug(); @@ -1432,23 +1433,37 @@ void CGEEngine::mainLoop() { _snail_->runCom(); _snail->runCom(); + // Handle a delay between game frames + handleFrame(); + + // Handle any pending events + _eventManager->poll(); +} + +void CGEEngine::handleFrame() { // Game frame delay uint32 millis = g_system->getMillis(); while (!_eventManager->_quitFlag && (millis < (_lastFrame + GAME_FRAME_DELAY))) { // Handle any pending events _eventManager->poll(); + if (millis >= (_lastTick + GAME_TICK_DELAY)) { + // Dispatch the tick to any active objects + tick(); + _lastTick = millis; + } + // Slight delay g_system->delayMillis(10); millis = g_system->getMillis(); } _lastFrame = millis; - // Dispatch the tick to any active objects - tick(); - - // Handle any pending events - _eventManager->poll(); + if (millis >= (_lastTick + GAME_TICK_DELAY)) { + // Dispatch the tick to any active objects + tick(); + _lastTick = millis; + } } void CGEEngine::tick() { From 8aa4f739af014303cc6a0fb90f13c22a1f77d33f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 18 Jul 2011 18:05:57 +0200 Subject: [PATCH 147/276] CGE: Add debug channels (WIP) --- engines/cge/bitmap.cpp | 54 ++++++++++++++++++++++++++----------- engines/cge/bitmap.h | 4 +-- engines/cge/btfile.cpp | 22 +++++++++------ engines/cge/cfile.cpp | 58 +++++++++++++++++++++++++++++++--------- engines/cge/cfile.h | 4 +-- engines/cge/cge.cpp | 10 +++++-- engines/cge/cge.h | 6 ++++- engines/cge/cge_main.cpp | 38 +++++++++++++++++++++----- engines/cge/general.cpp | 3 ++- engines/cge/vga13h.cpp | 8 +++++- engines/cge/vol.cpp | 20 +++++++++++++- engines/cge/vol.h | 4 +-- 12 files changed, 177 insertions(+), 54 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 84749243667..f280f61e3ef 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -32,6 +32,8 @@ #include "cge/cfile.h" #include "cge/vga13h.h" #include "common/system.h" +#include "common/debug.h" +#include "common/debug-channels.h" namespace CGE { @@ -47,6 +49,8 @@ void Bitmap::deinit() { #pragma argsused Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { + debugC(1, kDebugBitmap, "Bitmap::Bitmap(%s, %s)", fname, rem ? "true" : "false"); + char pat[MAXPATH]; forceExt(pat, fname, ".VBM"); @@ -79,6 +83,7 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL), _map(0) { + debugC(1, kDebugBitmap, "Bitmap::Bitmap(%d, %d, map)", w, h); if (map) code(); } @@ -92,6 +97,8 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) _h(h), _m(NULL), _map(0) { + debugC(1, kDebugBitmap, "Bitmap::Bitmap(%d, %d, %d)", w, h, fill); + uint16 dsiz = _w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap uint16 psiz = _h * lsiz; // - last gape, but + plane trailer @@ -116,20 +123,21 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) Common::copy(v, v + psiz, destP); HideDesc *b = (HideDesc *)(v + 4 * psiz); - b->skip = (SCR_WID - _w) >> 2; - b->hide = _w >> 2; + b->_skip = (SCR_WID - _w) >> 2; + b->_hide = _w >> 2; // Replicate across the entire table for (HideDesc *hdP = b + 1; hdP < (b + _h); ++hdP) *hdP = *b; - b->skip = 0; // fix the first entry + b->_skip = 0; // fix the first entry _v = v; _b = b; } Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), _map(0) { + debugC(1, kDebugBitmap, "Bitmap::Bitmap(bmp)"); uint8 *v0 = bmp._v; if (v0) { uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); @@ -144,12 +152,16 @@ Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), Bitmap::~Bitmap() { + debugC(6, kDebugBitmap, "Bitmap::~Bitmap()"); + free(_m); delete[] _v; } Bitmap &Bitmap::operator = (const Bitmap &bmp) { + debugC(1, kDebugBitmap, "&Bitmap::operator ="); + uint8 *v0 = bmp._v; _w = bmp._w; _h = bmp._h; @@ -172,6 +184,8 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { uint16 Bitmap::moveVmap(uint8 *buf) { + debugC(1, kDebugBitmap, "Bitmap::moveVmap(buf)"); + if (_v) { uint16 vsiz = (uint8 *)_b - (uint8 *)_v; uint16 siz = vsiz + _h * sizeof(HideDesc); @@ -185,6 +199,8 @@ uint16 Bitmap::moveVmap(uint8 *buf) { BMP_PTR Bitmap::code() { + debugC(1, kDebugBitmap, "Bitmap::code()"); + if (!_m) return false; @@ -202,8 +218,8 @@ BMP_PTR Bitmap::code() { if (_v) { // 2nd pass - fill the hide table for (i = 0; i < _h; i++) { - _b[i].skip = 0xFFFF; - _b[i].hide = 0x0000; + _b[i]._skip = 0xFFFF; + _b[i]._hide = 0x0000; } } for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane @@ -217,11 +233,11 @@ BMP_PTR Bitmap::code() { for (j = bpl; j < _w; j += 4) { pix = bm[j]; if (_v && pix != TRANS) { - if (j < _b[i].skip) - _b[i].skip = j; + if (j < _b[i]._skip) + _b[i]._skip = j; - if (j >= _b[i].hide) - _b[i].hide = j + 1; + if (j >= _b[i]._hide) + _b[i]._hide = j + 1; } if ((pix == TRANS) != skip || cnt >= 0x3FF0) { // end of block cnt |= (skip) ? SKP : CPY; @@ -282,14 +298,14 @@ BMP_PTR Bitmap::code() { } cnt = 0; for (i = 0; i < _h; i++) { - if (_b[i].skip == 0xFFFF) { // whole line is skipped - _b[i].skip = (cnt + SCR_WID) >> 2; + if (_b[i]._skip == 0xFFFF) { // whole line is skipped + _b[i]._skip = (cnt + SCR_WID) >> 2; cnt = 0; } else { - uint16 s = _b[i].skip & ~3; - uint16 h = (_b[i].hide + 3) & ~3; - _b[i].skip = (cnt + s) >> 2; - _b[i].hide = (h - s) >> 2; + uint16 s = _b[i]._skip & ~3; + uint16 h = (_b[i]._hide + 3) & ~3; + _b[i]._skip = (cnt + s) >> 2; + _b[i]._hide = (h - s) >> 2; cnt = SCR_WID - h; } } @@ -299,6 +315,8 @@ BMP_PTR Bitmap::code() { bool Bitmap::solidAt(int16 x, int16 y) { + debugC(6, kDebugBitmap, "Bitmap::solidAt(%d, %d)", x, y); + uint8 *m; uint16 r, n, n0; @@ -360,6 +378,8 @@ bool Bitmap::solidAt(int16 x, int16 y) { bool Bitmap::saveVBM(XFile *f) { + debugC(1, kDebugBitmap, "Bitmap::saveVBM(f)"); + uint16 p = (_pal != NULL), n = ((uint16)(((uint8 *)_b) - _v)) + _h * sizeof(HideDesc); if (f->_error == 0) @@ -386,6 +406,8 @@ bool Bitmap::saveVBM(XFile *f) { bool Bitmap::loadVBM(XFile *f) { + debugC(5, kDebugBitmap, "Bitmap::loadVBM(f)"); + uint16 p = 0, n = 0; if (f->_error == 0) f->read((uint8 *)&p, sizeof(p)); @@ -427,6 +449,8 @@ bool Bitmap::loadVBM(XFile *f) { } bool Bitmap::loadBMP(XFile *f) { + debugC(1, kDebugBitmap, "Bitmap::loadBMP(f)"); + struct { char BM[2]; union { int16 len; int32 len_; }; diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 3fdb673396b..2728e273030 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -53,8 +53,8 @@ struct Bgr4 { struct HideDesc { - uint16 skip; - uint16 hide; + uint16 _skip; + uint16 _hide; }; #include "common/pack-end.h" diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index eda18ebaaf8..68d3fe40e3a 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -28,19 +28,16 @@ #include "cge/btfile.h" #include "common/system.h" #include "common/str.h" +#include "cge/cge.h" +#include "common/debug.h" +#include "common/debug-channels.h" namespace CGE { -#ifndef BT_SIZE -#define BT_SIZE K(1) -#endif - -#ifndef BT_KEYLEN -#define BT_KEYLEN 13 -#endif - BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt) : IoHand(name, mode, crpt) { + debugC(1, kDebugFile, "BtFile::BtFile(%s, %d, crpt)", name, mode); + for (int i = 0; i < BT_LEVELS; i++) { _buff[i]._page = new BtPage; _buff[i]._pgNo = BT_NONE; @@ -53,6 +50,7 @@ BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt) BtFile::~BtFile() { + debugC(1, kDebugFile, "BtFile::~BtFile()"); for (int i = 0; i < BT_LEVELS; i++) { putPage(i, false); delete _buff[i]._page; @@ -61,6 +59,8 @@ BtFile::~BtFile() { void BtFile::putPage(int lev, bool hard) { + debugC(1, kDebugFile, "BtFile::putPage(%d, %s)", lev, hard ? "true" : "false"); + if (hard || _buff[lev]._updt) { seek(_buff[lev]._pgNo * sizeof(BtPage)); write((uint8 *) _buff[lev]._page, sizeof(BtPage)); @@ -70,6 +70,8 @@ void BtFile::putPage(int lev, bool hard) { BtPage *BtFile::getPage(int lev, uint16 pgn) { + debugC(1, kDebugFile, "BtFile::getPage(%d, %d)", lev, pgn); + if (_buff[lev]._pgNo != pgn) { int32 pos = pgn * sizeof(BtPage); putPage(lev, false); @@ -90,6 +92,8 @@ BtPage *BtFile::getPage(int lev, uint16 pgn) { } BtKeypack *BtFile::find(const char *key) { + debugC(1, kDebugFile, "BtFile::find(%s)", key); + int lev = 0; uint16 nxt = BT_ROOT; while (!_error) { @@ -125,6 +129,8 @@ int keycomp(const void *k1, const void *k2) { void BtFile::make(BtKeypack *keypack, uint16 count) { + debugC(1, kDebugFile, "BtFile::make(keypack, %d)", count); + #if BT_LEVELS != 2 #error This tiny BTREE implementation works with exactly 2 levels! #endif diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index f0a0ef3b8fc..af29ec5df77 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -27,6 +27,9 @@ #include "cge/cfile.h" #include "common/system.h" +#include "cge/cge.h" +#include "common/debug.h" +#include "common/debug-channels.h" namespace CGE { @@ -35,6 +38,8 @@ IoBuf::IoBuf(IOMODE mode, CRYPT *crpt) _bufMark(0), _ptr(0), _lim(0) { + debugC(1, kDebugFile, "IoBuf::IoBuf(%d, crpt)", mode); + _buff = farnew(uint8, IOBUF_SIZE); if (_buff == NULL) error("No core for I/O"); @@ -46,26 +51,34 @@ IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt) _bufMark(0), _ptr(0), _lim(0) { + debugC(1, kDebugFile, "IoBuf::IoBuf(%s, %d, crpt)", name, mode); + _buff = farnew(uint8, IOBUF_SIZE); if (_buff == NULL) error("No core for I/O [%s]", name); } IoBuf::~IoBuf() { + debugC(6, kDebugFile, "IoBuf::~IoBuf()"); + if (_mode > REA) - writeBuff(); + writeBuf(); free(_buff); } -void IoBuf::readBuff() { +void IoBuf::readBuf() { + debugC(4, kDebugFile, "IoBuf::readBuf()"); + _bufMark = IoHand::mark(); _lim = IoHand::read(_buff, IOBUF_SIZE); _ptr = 0; } -void IoBuf::writeBuff() { +void IoBuf::writeBuf() { + debugC(4, kDebugFile, "IoBuf::writeBuf()"); + if (_lim) { IoHand::write(_buff, _lim); _bufMark = IoHand::mark(); @@ -75,10 +88,12 @@ void IoBuf::writeBuff() { uint16 IoBuf::read(void *buf, uint16 len) { + debugC(4, kDebugFile, "IoBuf::read(buf, %d)", len); + uint16 total = 0; while (len) { if (_ptr >= _lim) - readBuff(); + readBuf(); uint16 n = _lim - _ptr; if (n) { if (len < n) @@ -96,11 +111,13 @@ uint16 IoBuf::read(void *buf, uint16 len) { uint16 IoBuf::read(uint8 *buf) { + debugC(3, kDebugFile, "IoBuf::read(buf)"); + uint16 total = 0; while (total < LINE_MAX - 2) { if (_ptr >= _lim) - readBuff(); + readBuf(); uint8 *p = _buff + _ptr; uint16 n = _lim - _ptr; if (n) { @@ -126,7 +143,7 @@ uint16 IoBuf::read(uint8 *buf) { *(buf++) = '\n'; total++; if (_ptr >= _lim) - readBuff(); + readBuf(); if (_ptr < _lim) if (_buff[_ptr] == '\n') ++_ptr; @@ -141,6 +158,8 @@ uint16 IoBuf::read(uint8 *buf) { uint16 IoBuf::write(void *buf, uint16 len) { + debugC(1, kDebugFile, "IoBuf::write(buf, %d)", len); + uint16 tot = 0; while (len) { uint16 n = IOBUF_SIZE - _lim; @@ -153,13 +172,15 @@ uint16 IoBuf::write(void *buf, uint16 len) { buf = (uint8 *)buf + n; tot += n; } else - writeBuff(); + writeBuf(); } return tot; } uint16 IoBuf::write(uint8 *buf) { + debugC(1, kDebugFile, "IoBuf::write(buf)"); + uint16 len = 0; if (buf) { len = strlen((const char *) buf); @@ -178,8 +199,10 @@ uint16 IoBuf::write(uint8 *buf) { int IoBuf::read() { + debugC(1, kDebugFile, "IoBuf::read()"); + if (_ptr >= _lim) { - readBuff(); + readBuf(); if (_lim == 0) return -1; } @@ -188,8 +211,10 @@ int IoBuf::read() { void IoBuf::write(uint8 b) { + debugC(1, kDebugFile, "IoBuf::write(%d)", b); + if (_lim >= IOBUF_SIZE) - writeBuff(); + writeBuf(); _buff[_lim++] = b; } @@ -199,6 +224,7 @@ uint16 CFile::_maxLineLen = LINE_MAX; CFile::CFile(const char *name, IOMODE mode, CRYPT *crpt) : IoBuf(name, mode, crpt) { + debugC(1, kDebugFile, "CFile::CFile(%s, %d, crpt)", name, mode); } @@ -207,8 +233,10 @@ CFile::~CFile() { void CFile::flush() { + debugC(1, kDebugFile, "CFile::flush()"); + if (_mode > REA) - writeBuff(); + writeBuf(); else _lim = 0; @@ -222,17 +250,21 @@ void CFile::flush() { long CFile::mark() { + debugC(5, kDebugFile, "CFile::mark()"); + return _bufMark + ((_mode > REA) ? _lim : _ptr); } long CFile::seek(long pos) { + debugC(1, kDebugFile, "CFile::seek(%ld)", pos); + if (pos >= _bufMark && pos < _bufMark + _lim) { ((_mode == REA) ? _ptr : _lim) = (uint16)(pos - _bufMark); return pos; } else { if (_mode > REA) - writeBuff(); + writeBuf(); else _lim = 0; @@ -243,11 +275,13 @@ long CFile::seek(long pos) { void CFile::append(CFile &f) { + debugC(1, kDebugFile, "CFile::append(f)"); + seek(size()); if (f._error == 0) { while (true) { if ((_lim = f.IoHand::read(_buff, IOBUF_SIZE)) == IOBUF_SIZE) - writeBuff(); + writeBuf(); else break; if ((_error = f._error) != 0) diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index bf90633dd08..490e120afa4 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -49,8 +49,8 @@ protected: long _bufMark; uint16 _seed; CRYPT *_crypt; - virtual void readBuff(); - virtual void writeBuff(); + virtual void readBuf(); + virtual void writeBuf(); public: IoBuf(IOMODE mode, CRYPT *crpt = NULL); IoBuf(const char *name, IOMODE mode, CRYPT *crpt = NULL); diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 97712591fa5..7e8c8377a88 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -45,6 +45,9 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) // Debug/console setup DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel"); + DebugMan.addDebugChannel(kDebugBitmap, "bitmap", "CGE Bitmap debug channel"); + DebugMan.addDebugChannel(kDebugFile, "file", "CGE IO debug channel"); + DebugMan.addDebugChannel(kDebugEngine, "engine", "CGE Engine debug channel"); _isDemo = _gameDescription->flags & ADGF_DEMO; _startupMode = 1; @@ -56,6 +59,8 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) } void CGEEngine::setup() { + debugC(1, kDebugEngine, "CGEEngine::setup()"); + // Initialise fields _lastFrame = 0; _lastTick = 0; @@ -131,7 +136,7 @@ void CGEEngine::setup() { } CGEEngine::~CGEEngine() { - debug("CGEEngine::~CGEEngine"); + debugC(1, kDebugEngine, "CGEEngine::~CGEEngine()"); // Call classes with static members to clear them up Talk::deinit(); @@ -169,12 +174,13 @@ CGEEngine::~CGEEngine() { } Common::Error CGEEngine::run() { + debugC(1, kDebugEngine, "CGEEngine::run()"); + // Initialize graphics using following: initGraphics(320, 200, false); // Setup necessary game objects setup(); - // Run the game cge_main(); diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 5187e57c0fd..e8451454a4b 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -44,7 +44,10 @@ class Sprite; // our engine debug channels enum { - kCGEDebug = 1 << 0 + kCGEDebug = 1 << 0, + kDebugBitmap = 1 << 1, + kDebugFile = 1 << 2, + kDebugEngine = 1 << 3 }; enum SnList { @@ -184,6 +187,7 @@ public: void nextStep(); void switchDebug(); void miniStep(int stp); + void AltCtrlDel(); void snBackPt(Sprite *spr, int stp); void snBarrier(int cav, int bar, bool horz); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index ad31a5c1e6e..34768e42a42 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -104,6 +104,8 @@ Bar _barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; extern Dac _stdPal[58]; void CGEEngine::syncHeader(Common::Serializer &s) { + debugC(1, kDebugEngine, "CGEEngine::syncHeader(s)"); + int i; s.syncAsUint16LE(_now); @@ -142,6 +144,8 @@ void CGEEngine::syncHeader(Common::Serializer &s) { } bool CGEEngine::loadGame(int slotNumber, SavegameHeader *header, bool tiny) { + debugC(1, kDebugEngine, "CGEEngine::loadgame(file, %s)", tiny ? "true" : "false"); + Common::MemoryReadStream *readStream; SavegameHeader saveHeader; @@ -358,6 +362,8 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt } } } + debugC(1, kDebugEngine, "CGEEngine::saveSound()"); + } bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header) { @@ -393,10 +399,14 @@ bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &heade } void CGEEngine::heroCover(int cvr) { + debugC(1, kDebugEngine, "CGEEngine::heroCover(%d)", cvr); + SNPOST(SNCOVER, 1, cvr, NULL); } void CGEEngine::trouble(int seq, int txt) { + debugC(1, kDebugEngine, "CGEEngine::trouble(%d, %d)", seq, txt); + _hero->park(); SNPOST(SNWAIT, -1, -1, _hero); SNPOST(SNSEQ, -1, seq, _hero); @@ -406,14 +416,20 @@ void CGEEngine::trouble(int seq, int txt) { } void CGEEngine::offUse() { + debugC(1, kDebugEngine, "CGEEngine::offUse()"); + trouble(OFF_USE, OFF_USE_TEXT + new_random(_offUseCount)); } void CGEEngine::tooFar() { + debugC(1, kDebugEngine, "CGEEngine::tooFar()"); + trouble(TOO_FAR, TOO_FAR_TEXT); } void CGEEngine::loadHeroXY() { + debugC(1, kDebugEngine, "CGEEngine::loadHeroXY()"); + INI_FILE cf(progName(".HXY")); memset(_heroXY, 0, sizeof(_heroXY)); if (!cf._error) @@ -421,6 +437,8 @@ void CGEEngine::loadHeroXY() { } void CGEEngine::loadMapping() { + debugC(1, kDebugEngine, "CGEEngine::loadMapping()"); + if (_now <= CAVE_MAX) { INI_FILE cf(progName(".TAB")); if (!cf._error) { @@ -462,6 +480,8 @@ void SQUARE::touch(uint16 mask, int x, int y) { void CGEEngine::setMapBrick(int x, int z) { + debugC(1, kDebugEngine, "CGEEngine::setMapBrick(%d, %d)", x, z); + SQUARE *s = new SQUARE(this); if (s) { static char n[] = "00:00"; @@ -474,22 +494,24 @@ void CGEEngine::setMapBrick(int x, int z) { } } -//static void switchDebug(); -//static void pullSprite(); -//static void NextStep(); - void CGEEngine::keyClick() { + debugC(1, kDebugEngine, "CGEEngine::keyClick()"); + SNPOST_(SNSOUND, -1, 5, NULL); } void CGEEngine::resetQSwitch() { + debugC(1, kDebugEngine, "CGEEngine::resetQSwitch()"); + SNPOST_(SNSEQ, 123, 0, NULL); keyClick(); } void CGEEngine::quit() { + debugC(1, kDebugEngine, "CGEEngine::quit()"); + static Choice QuitMenu[] = { { NULL, &CGEEngine::startCountDown }, { NULL, &CGEEngine::resetQSwitch }, @@ -511,8 +533,10 @@ void CGEEngine::quit() { } -static void AltCtrlDel() { - SNPOST_(SNSAY, -1, A_C_D_TEXT, _hero); +void CGEEngine::AltCtrlDel() { + debugC(1, kDebugEngine, "CGEEngine::setup()"); + + SNPOST_(SNSAY, -1, A_C_D_TEXT, _hero); } void CGEEngine::miniStep(int stp) { @@ -716,7 +740,7 @@ void System::touch(uint16 mask, int x, int y) { switch (x) { case Del: if (_keyboard->_key[ALT] && _keyboard->_key[CTRL]) - AltCtrlDel(); + _vm->AltCtrlDel(); else _vm->killSprite(); break; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 4ca1ef57cab..25b7cc25a50 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -238,7 +238,8 @@ uint16 IoHand::read(void *buf, uint16 len) { } uint16 IoHand::write(void *buf, uint16 len) { - error("IOHAND::Write not supported"); + warning("IOHAND::Write not supported"); + return 0; /* if (len) { if (Mode == REA || Handle < 0) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index a7b9d8c0804..ca6a9e3bdd6 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1213,6 +1213,8 @@ void Vga::copyPage(uint16 d, uint16 s) { //-------------------------------------------------------------------------- void Bitmap::xShow(int16 x, int16 y) { + debugC(4, kDebugBitmap, "Bitmap::xShow(%d, %d)", x, y); + const byte *srcP = (const byte *)_v; byte *destEndP = (byte *)Vga::_page[1]->pixels + (SCR_WID * SCR_HIG); byte *lookupTable = _m; @@ -1264,6 +1266,8 @@ void Bitmap::xShow(int16 x, int16 y) { void Bitmap::show(int16 x, int16 y) { + debugC(5, kDebugBitmap, "Bitmap::show(%d, %d)", x, y); + const byte *srcP = (const byte *)_v; byte *destEndP = (byte *)Vga::_page[1]->pixels + (SCR_WID * SCR_HIG); @@ -1326,6 +1330,8 @@ void Bitmap::show(int16 x, int16 y) { void Bitmap::hide(int16 x, int16 y) { + debugC(5, kDebugBitmap, "Bitmap::hide(%d, %d)", x, y); + for (int yp = y; yp < y + _h; yp++) { const byte *srcP = (const byte *)Vga::_page[2]->getBasePtr(x, yp); byte *destP = (byte *)Vga::_page[1]->getBasePtr(x, yp); @@ -1378,4 +1384,4 @@ PocLight::PocLight(CGEEngine *vm): Sprite(vm, NULL) { _flags._kill = false; } -} // End of namespace CGE \ No newline at end of file +} // End of namespace CGE diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 04a91896822..cff735abf58 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -28,6 +28,9 @@ #include "cge/vol.h" #include "common/system.h" #include "common/str.h" +#include "cge/cge.h" +#include "common/debug.h" +#include "common/debug-channels.h" namespace CGE { @@ -44,11 +47,14 @@ Dat::Dat(): _file(DAT_NAME, REA, CRP) #endif { + debugC(1, kDebugFile, "Dat::Dat()"); } /*-----------------------------------------------------------------------*/ void VFile::init() { + debugC(1, kDebugFile, "VFile::init()"); + _dat = new Dat(); #ifdef VOL_UPD _cat = new BtFile(CAT_NAME, UPD, CRP); @@ -66,6 +72,8 @@ void VFile::deinit() { VFile::VFile(const char *name, IOMODE mode) : IoBuf(mode) { + debugC(3, kDebugFile, "VFile::VFile(%s, %d)", name, mode); + if (mode == REA) { if (_dat->_file._error || _cat->_error) error("Bad volume data"); @@ -88,11 +96,15 @@ VFile::~VFile() { bool VFile::exist(const char *name) { + debugC(1, kDebugFile, "VFile::exist(%s)", name); + return scumm_stricmp(_cat->find(name)->_key, name) == 0; } -void VFile::readBuff() { +void VFile::readBuf() { + debugC(3, kDebugFile, "VFile::readBuf()"); + if (_recent != this) { _dat->_file.seek(_bufMark + _lim); _recent = this; @@ -106,14 +118,20 @@ void VFile::readBuff() { } long VFile::mark() { + debugC(5, kDebugFile, "VFile::mark()"); + return (_bufMark + _ptr) - _begMark; } long VFile::size() { + debugC(1, kDebugFile, "VFile::size()"); + return _endMark - _begMark; } long VFile::seek(long pos) { + debugC(1, kDebugFile, "VFile::seel(%ld)", pos); + _recent = NULL; _lim = 0; return (_bufMark = _begMark + pos); diff --git a/engines/cge/vol.h b/engines/cge/vol.h index 8ed33d0ab4b..bbf3237721f 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -70,8 +70,8 @@ private: long _begMark; long _endMark; - void readBuff(); - void writeBuff() { } + void readBuf(); + void writeBuf() { } void make(const char *fspec); public: VFile(const char *name, IOMODE mode = REA); From f884e578669ff85365b1e838ee8671ddac8ab112 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 18 Jul 2011 21:47:57 +0200 Subject: [PATCH 148/276] CGE: Remove a bunch of useless sound related menus --- engines/cge/cge_main.cpp | 2 +- engines/cge/config.cpp | 233 --------------------------------------- engines/cge/config.h | 3 - engines/cge/snail.cpp | 2 +- 4 files changed, 2 insertions(+), 238 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 34768e42a42..cb060891cfd 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1702,7 +1702,7 @@ bool CGEEngine::showTitle(const char *name) { _vga->_showQ->append(_mouse); _heart->_enable = true; _mouse->on(); - for (selectSound(); !_snail->idle() || Vmenu::_addr;) { + for (; !_snail->idle() || Vmenu::_addr;) { mainLoop(); if (_eventManager->_quitFlag) return false; diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 2941d36d2c8..f8d5431ef08 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -33,152 +33,8 @@ namespace CGE { -/* - 51=wska§ typ posiadanej karty d¦wi‘kowej - 52=wybierz numer portu dla karty d¦wi‘kowej - 53=wybierz numer przerwania dla karty d¦wi‘kowej - 54=wybierz numer kana’u DMA dla karty d¦wi‘kowej - 55=wybierz numer portu dla General MIDI - 55=konfiguracja karty d¦wi‘kowej -*/ -#define STYPE_TEXT 51 -#define SPORT_TEXT 52 -#define SIRQ_TEXT 53 -#define SDMA_TEXT 54 -#define MPORT_TEXT 55 #define MENU_TEXT 56 -#define NONE_TEXT 60 -#define SB_TEXT 61 -#define SBM_TEXT 62 -#define GUS_TEXT 63 -#define GUSM_TEXT 64 -#define MIDI_TEXT 65 -#define AUTO_TEXT 66 - -#define DETECT 0xFFFF - - -static int DevName[] = { - NONE_TEXT, SB_TEXT, SBM_TEXT, GUS_TEXT, GUSM_TEXT, - MIDI_TEXT, AUTO_TEXT -}; - -static Choice DevMenu[] = { - { NULL, &CGEEngine::NONE }, - { NULL, &CGEEngine::SB }, - { NULL, &CGEEngine::SBM }, - { NULL, &CGEEngine::GUS }, - { NULL, &CGEEngine::GUSM }, - { NULL, &CGEEngine::MIDI }, - { NULL, &CGEEngine::AUTO }, - { NULL, NULL } -}; - - -static Choice DigiPorts[] = { - { " 210h", &CGEEngine::setPortD }, - { " 220h", &CGEEngine::setPortD }, - { " 230h", &CGEEngine::setPortD }, - { " 240h", &CGEEngine::setPortD }, - { " 250h", &CGEEngine::setPortD }, - { " 260h", &CGEEngine::setPortD }, - { "AUTO ", &CGEEngine::setPortD }, - { NULL, NULL } -}; - -static Choice MIDIPorts[] = { - { " 220h", &CGEEngine::setPortM }, - { " 230h", &CGEEngine::setPortM }, - { " 240h", &CGEEngine::setPortM }, - { " 250h", &CGEEngine::setPortM }, - { " 300h", &CGEEngine::setPortM }, - { " 320h", &CGEEngine::setPortM }, - { " 330h", &CGEEngine::setPortM }, - { " 340h", &CGEEngine::setPortM }, - { " 350h", &CGEEngine::setPortM }, - { " 360h", &CGEEngine::setPortM }, - { "AUTO ", &CGEEngine::setPortM }, - { NULL, NULL } -}; - -static Choice BlsterIRQ[] = { - { "IRQ 2", &CGEEngine::setIRQ }, - { "IRQ 5", &CGEEngine::setIRQ }, - { "IRQ 7", &CGEEngine::setIRQ }, - { "IRQ 10", &CGEEngine::setIRQ }, - { "AUTO ", &CGEEngine::setIRQ }, - { NULL, NULL } -}; - -static Choice GravisIRQ[] = { - { "IRQ 2", &CGEEngine::setIRQ }, - { "IRQ 5", &CGEEngine::setIRQ }, - { "IRQ 7", &CGEEngine::setIRQ }, - { "IRQ 11", &CGEEngine::setIRQ }, - { "IRQ 12", &CGEEngine::setIRQ }, - { "IRQ 15", &CGEEngine::setIRQ }, - { "AUTO ", &CGEEngine::setIRQ }, - { NULL, NULL } -}; - -static Choice GravisDMA[] = { - { "DMA 1", &CGEEngine::setDMA }, - { "DMA 3", &CGEEngine::setDMA }, - { "DMA 5", &CGEEngine::setDMA }, - { "DMA 6", &CGEEngine::setDMA }, - { "DMA 7", &CGEEngine::setDMA }, - { "AUTO ", &CGEEngine::setDMA }, - { NULL, NULL } -}; - -static Choice BlsterDMA[] = { - { "DMA 0", &CGEEngine::setDMA }, - { "DMA 1", &CGEEngine::setDMA }, - { "DMA 3", &CGEEngine::setDMA }, - { "AUTO ", &CGEEngine::setDMA }, - { NULL, NULL } -}; - - -void CGEEngine::selectSound() { - int i; - _sound.close(); - if (Vmenu::_addr) - SNPOST_(SNKILL, -1, 0, Vmenu::_addr); - inf(_text->getText(STYPE_TEXT)); - _talk->gotoxy(_talk->_x, FONT_HIG / 2); - for (i = 0; i < (int)ArrayCount(DevName); i++) - DevMenu[i]._text = _text->getText(DevName[i]); - (new Vmenu(this, DevMenu, SCR_WID / 2, _talk->_y + _talk->_h + TEXT_VM + FONT_HIG))->setName(_text->getText(MENU_TEXT)); -} - - -static void reset() { - _sndDrvInfo._dBase = _sndDrvInfo._dIrq = _sndDrvInfo._dDma = _sndDrvInfo._mBase = DETECT; -} - - -static uint16 deco(const char *str, uint16(*dco)(const char *)) { - while (*str && ! IsDigit(*str)) - ++str; - if (*str) - return dco(str); - else - return DETECT; -} - - -static uint16 ddeco(const char *str) { - return deco(str, atow); -} - - -static uint16 xdeco(const char *str) { - return deco(str, xtow); -} - - static Choice *_cho; static int _hlp; @@ -188,93 +44,4 @@ void CGEEngine::snSelect() { (new Vmenu(this, _cho, SCR_WID / 2, _talk->_y + _talk->_h + TEXT_VM + FONT_HIG))->setName(_text->getText(MENU_TEXT)); } - -static void select(Choice *cho, int hlp) { - _cho = cho; - _hlp = hlp; - SNPOST2(SNEXEC, -1, 0, kSnSelect); -} - - -void CGEEngine::NONE() { - _sndDrvInfo._dDev = DEV_QUIET; - _sndDrvInfo._mDev = DEV_QUIET; - _sound.open(); -} - - -void CGEEngine::SB() { - _sndDrvInfo._dDev = DEV_SB; - _sndDrvInfo._mDev = DEV_SB; - reset(); - select(DigiPorts, SPORT_TEXT); -} - - -void CGEEngine::SBM() { - _sndDrvInfo._dDev = DEV_SB; - _sndDrvInfo._mDev = DEV_GM; - reset(); - select(DigiPorts, SPORT_TEXT); -} - - -void CGEEngine::GUS() { - _sndDrvInfo._dDev = DEV_GUS; - _sndDrvInfo._mDev = DEV_GUS; - reset(); - select(DigiPorts, SPORT_TEXT); -} - - -void CGEEngine::GUSM() { - _sndDrvInfo._dDev = DEV_GUS; - _sndDrvInfo._mDev = DEV_GM; - reset(); - select(DigiPorts, SPORT_TEXT); -} - - -void CGEEngine::MIDI() { - _sndDrvInfo._dDev = DEV_QUIET; - _sndDrvInfo._mDev = DEV_GM; - _sndDrvInfo._mBase = DETECT; - select(MIDIPorts, MPORT_TEXT); -} - - -void CGEEngine::AUTO() { - _sndDrvInfo._dDev = DEV_AUTO; - _sndDrvInfo._mDev = DEV_AUTO; - reset(); - _sound.open(); -} - - -void CGEEngine::setPortD() { - _sndDrvInfo._dBase = xdeco(DigiPorts[Vmenu::_recent]._text); - select((_sndDrvInfo._dDev == DEV_SB) ? BlsterIRQ : GravisIRQ, SIRQ_TEXT); -} - - -void CGEEngine::setPortM() { - _sndDrvInfo._mBase = xdeco(MIDIPorts[Vmenu::_recent]._text); - _sound.open(); -} - - -void CGEEngine::setIRQ() { - _sndDrvInfo._dIrq = ddeco(((_sndDrvInfo._dDev == DEV_SB) ? BlsterIRQ : GravisIRQ)[Vmenu::_recent]._text); - select((_sndDrvInfo._dDev == DEV_SB) ? BlsterDMA : GravisDMA, SDMA_TEXT); -} - - -void CGEEngine::setDMA() { - _sndDrvInfo._dDma = ddeco(((_sndDrvInfo._dDev == DEV_SB) ? BlsterDMA : GravisDMA)[Vmenu::_recent]._text); - if (_sndDrvInfo._mDev != _sndDrvInfo._dDev) - select(MIDIPorts, MPORT_TEXT); - else - _sound.open(); -} - } // End of namespace CGE diff --git a/engines/cge/config.h b/engines/cge/config.h index 4a1e5927e51..d7191a281db 100644 --- a/engines/cge/config.h +++ b/engines/cge/config.h @@ -29,9 +29,6 @@ #define __CGE_CONFIG__ namespace CGE { - -void selectSound(); - } // End of namespace CGE #endif diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 977103d7a1c..9d5b188fe52 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -1068,7 +1068,7 @@ void Snail::runCom() { _vm->xCave(); break; case kSelectSound: - _vm->selectSound(); + warning("TODO: Select sound card"); break; case kSnSelect: _vm->snSelect(); From b3f0e72e25a3b738ab4af0f198ff78938dd4e5b3 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 18 Jul 2011 23:09:57 +0200 Subject: [PATCH 149/276] CGE: Remove useless fields in DebugText, add some more debugC --- engines/cge/cge.h | 5 +- engines/cge/cge_main.cpp | 179 +++++++++++++++++---------------------- 2 files changed, 82 insertions(+), 102 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index e8451454a4b..b67b6b28a7d 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -188,6 +188,8 @@ public: void switchDebug(); void miniStep(int stp); void AltCtrlDel(); + void postMiniStep(int stp); + void ShowBak(int ref); void snBackPt(Sprite *spr, int stp); void snBarrier(int cav, int bar, bool horz); @@ -232,7 +234,8 @@ public: void snUncover(Sprite *spr, Sprite *xspr); void snWalk(Sprite *spr, int x, int y); void snZTrim(Sprite *spr); - +protected: + int _recentStep; private: CGEConsole *_console; void setup(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index cb060891cfd..10ec47e815d 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -534,12 +534,14 @@ void CGEEngine::quit() { void CGEEngine::AltCtrlDel() { - debugC(1, kDebugEngine, "CGEEngine::setup()"); + debugC(1, kDebugEngine, "CGEEngine::AltCtrlDel()"); SNPOST_(SNSAY, -1, A_C_D_TEXT, _hero); } void CGEEngine::miniStep(int stp) { + debugC(1, kDebugEngine, "CGEEngine::miniStep(%d)", stp); + if (stp < 0) _miniCave->_flags._hide = true; else { @@ -551,32 +553,16 @@ void CGEEngine::miniStep(int stp) { } } +void CGEEngine::postMiniStep(int step) { + debugC(6, kDebugEngine, "CGEEngine::postMiniStep(%d)", step); -static void postMiniStep(int stp) { - static int recent = -2; - if (_miniCave && stp != recent) - SNPOST2_(SNEXEC, -1, recent = stp, kMiniStep); + if (_miniCave && step != _recentStep) + SNPOST2_(SNEXEC, -1, _recentStep = step, kMiniStep); } -void System::setPal() { - uint i; - Dac *p = Vga::_sysPal + 256 - ArrayCount(_stdPal); - for (i = 0; i < ArrayCount(_stdPal); i++) { - p[i]._r = _stdPal[i]._r >> 2; - p[i]._g = _stdPal[i]._g >> 2; - p[i]._b = _stdPal[i]._b >> 2; - } -} +void CGEEngine::ShowBak(int ref) { + debugC(1, kDebugEngine, "CGEEngine::ShowBack(%d)", ref); - -void System::funTouch() { - uint16 n = (PAIN) ? HEROFUN1 : HEROFUN0; - if (_talk == NULL || n > _funDel) - _funDel = n; -} - - -static void ShowBak(int ref) { Sprite *spr = _vga->_spareQ->locate(ref); if (spr) { Bitmap::_pal = Vga::_sysPal; @@ -589,8 +575,9 @@ static void ShowBak(int ref) { } } - void CGEEngine::caveUp() { + debugC(1, kDebugEngine, "CGEEngine::caveUp()"); + int BakRef = 1000 * _now; if (_music) loadMidi(_now); @@ -653,6 +640,8 @@ void CGEEngine::caveUp() { void CGEEngine::caveDown() { + debugC(1, kDebugEngine, "CGEEngine::caveDown()"); + Sprite *spr; if (!_horzLine->_flags._hide) switchMapping(); @@ -669,14 +658,16 @@ void CGEEngine::caveDown() { _text->clear(1000); } - void CGEEngine::xCave() { + debugC(6, kDebugEngine, "CGEEngine::xCave()"); + caveDown(); caveUp(); } - void CGEEngine::qGame() { + debugC(1, kDebugEngine, "CGEEngine::qGame()"); + caveDown(); _oldLev = _lev; saveSound(); @@ -690,6 +681,8 @@ void CGEEngine::qGame() { void CGEEngine::switchCave(int cav) { + debugC(1, kDebugEngine, "CGEEngine::switchCave(%d)", cav); + if (cav != _now) { _heart->_enable = false; if (cav < 0) { @@ -723,6 +716,22 @@ System::System(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { tick(); } +void System::setPal() { + uint i; + Dac *p = Vga::_sysPal + 256 - ArrayCount(_stdPal); + for (i = 0; i < ArrayCount(_stdPal); i++) { + p[i]._r = _stdPal[i]._r >> 2; + p[i]._g = _stdPal[i]._g >> 2; + p[i]._b = _stdPal[i]._b >> 2; + } +} + +void System::funTouch() { + uint16 n = (PAIN) ? HEROFUN1 : HEROFUN0; + if (_talk == NULL || n > _funDel) + _funDel = n; +} + void System::touch(uint16 mask, int x, int y) { static int pp = 0; @@ -856,7 +865,7 @@ void System::touch(uint16 mask, int x, int y) { } } - postMiniStep(cav - 1); + _vm->postMiniStep(cav - 1); if (mask & L_UP) { if (cav && _snail->idle() && _hero->_tracePtr < 0) @@ -869,8 +878,7 @@ void System::touch(uint16 mask, int x, int y) { Cluster::_map[z1][x1] = 1; _vm->setMapBrick(x1, z1); } - } else - { + } else { if (!_talk && _snail->idle() && _hero && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && !_vm->_game) { _hero->findWay(XZ(x, y)); @@ -909,35 +917,17 @@ void System::tick() { _time = SYSTIMERATE; } - -/* -static void SpkOpen() { - asm in al,0x61 - asm or al,0x03 - asm out 0x61,al - asm mov al,0x90 - asm out 0x43,al -} - - -static void SpkClose() { - asm in al,0x61 - asm and al,0xFC - asm out 0x61,al -} - -*/ - - void CGEEngine::switchColorMode() { + debugC(1, kDebugEngine, "CGEEngine::switchColorMode()"); + SNPOST_(SNSEQ, 121, _vga->_mono = !_vga->_mono, NULL); keyClick(); _vga->setColors(Vga::_sysPal, 64); } - - void CGEEngine::switchMusic() { + debugC(1, kDebugEngine, "CGEEngine::switchMusic()"); + if (_keyboard->_key[ALT]) { if (Vmenu::_addr) SNPOST_(SNKILL, -1, 0, Vmenu::_addr); @@ -959,14 +949,16 @@ void CGEEngine::switchMusic() { killMidi(); } - void CGEEngine::startCountDown() { + debugC(1, kDebugEngine, "CGEEngine::startCountDown()"); + //SNPOST(SNSEQ, 123, 0, NULL); switchCave(-1); } - void CGEEngine::takeName() { + debugC(1, kDebugEngine, "CGEEngine::takeName()"); + if (GetText::_ptr) SNPOST_(SNKILL, -1, 0, GetText::_ptr); else { @@ -982,8 +974,9 @@ void CGEEngine::takeName() { } } - void CGEEngine::switchMapping() { + debugC(1, kDebugEngine, "CGEEngine::switchMapping()"); + if (_horzLine->_flags._hide) { int i; for (i = 0; i < MAP_ZCNT; i++) { @@ -1003,6 +996,8 @@ void CGEEngine::switchMapping() { } void CGEEngine::killSprite() { + debugC(1, kDebugEngine, "CGEEngine::killSprite()"); + _sprite->_flags._kill = true; _sprite->_flags._bDel = true; SNPOST_(SNKILL, -1, 0, _sprite); @@ -1010,6 +1005,8 @@ void CGEEngine::killSprite() { } void CGEEngine::pushSprite() { + debugC(1, kDebugEngine, "CGEEngine::pushSprite()"); + Sprite *spr = _sprite->_prev; if (spr) { _vga->_showQ->insert(_vga->_showQ->remove(_sprite), spr); @@ -1020,6 +1017,8 @@ void CGEEngine::pushSprite() { } void CGEEngine::pullSprite() { + debugC(1, kDebugEngine, "CGEEngine::pullSprite()"); + bool ok = false; Sprite *spr = _sprite->_next; if (spr) { @@ -1037,65 +1036,45 @@ void CGEEngine::pullSprite() { } void CGEEngine::nextStep() { + debugC(1, kDebugEngine, "CGEEngine::nextStep()"); + SNPOST_(SNSTEP, 0, 0, _sprite); } void CGEEngine::saveMapping() { - { - IoHand cf(progName(".TAB"), UPD); - if (!cf._error) { - cf.seek((_now - 1) * sizeof(Cluster::_map)); - cf.write((uint8 *) Cluster::_map, sizeof(Cluster::_map)); - } + IoHand cfTab(progName(".TAB"), UPD); + if (!cfTab._error) { + cfTab.seek((_now - 1) * sizeof(Cluster::_map)); + cfTab.write((uint8 *) Cluster::_map, sizeof(Cluster::_map)); } - { - IoHand cf(progName(".HXY"), WRI); - if (!cf._error) { - _heroXY[_now - 1]._x = _hero->_x; - _heroXY[_now - 1]._y = _hero->_y; - cf.write((uint8 *) _heroXY, sizeof(_heroXY)); - } + + IoHand cfHxy(progName(".HXY"), WRI); + if (!cfHxy._error) { + _heroXY[_now - 1]._x = _hero->_x; + _heroXY[_now - 1]._y = _hero->_y; + cfHxy.write((uint8 *) _heroXY, sizeof(_heroXY)); } } -// 1111111111222222222233333333 334444444444555555555566666666667777777777 -// 01234567890123456789012345678901234567 890123456789012345678901234567890123456789 -static char DebugText[] = " N=00000 F=000000 X=000 Y=000 FPS=0000\0S=00:00 000:000:000 000:000 00 "; +// 1111111111222222222233333333334444444444555555555566666666667777777777 +// 01234567890123456789012345678901234567890123456789012345678901234567890123456789 +static char DebugText[] = " X=000 Y=000 S=00:00 000:000:000 000:000 00"; -#define NFRE (DebugText + 3) -#define FFRE (DebugText + 11) -#define ABSX (DebugText + 20) -#define ABSY (DebugText + 26) -#define FRPS (DebugText + 34) -#define XSPR (DebugText + 38) -#define SP_N (DebugText + 41) -#define SP_S (DebugText + 44) - -#define SP_X (DebugText + 47) -#define SP_Y (DebugText + 51) -#define SP_Z (DebugText + 55) -#define SP_W (DebugText + 59) -#define SP_H (DebugText + 63) -#define SP_F (DebugText + 67) -#define SP__ (DebugText + 70) +#define ABSX (DebugText + 3) +#define ABSY (DebugText + 9) +#define SP_N (DebugText + 15) +#define SP_S (DebugText + 18) +#define SP_X (DebugText + 21) +#define SP_Y (DebugText + 25) +#define SP_Z (DebugText + 29) +#define SP_W (DebugText + 33) +#define SP_H (DebugText + 37) +#define SP_F (DebugText + 41) void CGEEngine::sayDebug() { if (!_debugLine->_flags._hide) { - static long t = -1L; - long t1 = timer(); - - if (t1 - t >= 18) { - static uint32 old = 0L; - uint32 now = _vga->_frmCnt; - dwtom(now - old, FRPS, 10, 4); - old = now; - t = t1; - } - dwtom(_mouse->_x, ABSX, 10, 3); dwtom(_mouse->_y, ABSY, 10, 3); -// dwtom(coreleft(), NFRE, 10, 5); -// dwtom(farcoreleft(), FFRE, 10, 6); // sprite queue size uint16 n = 0; @@ -1103,7 +1082,6 @@ void CGEEngine::sayDebug() { for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { ++ n; if (spr == _sprite) { - *XSPR = ' '; dwtom(n, SP_N, 10, 2); dwtom(_sprite->_x, SP_X, 10, 3); dwtom(_sprite->_y, SP_Y, 10, 3); @@ -1114,7 +1092,6 @@ void CGEEngine::sayDebug() { } } dwtom(n, SP_S, 10, 2); -// *SP__ = (heapcheck() < 0) ? '!' : ' '; _debugLine->update(DebugText); } } From 17003d0e906f776996b483a18e463b1994c8fb61 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 18 Jul 2011 23:14:22 +0200 Subject: [PATCH 150/276] CGE: Fix name of showBak() --- engines/cge/cge.cpp | 11 ++++++----- engines/cge/cge.h | 4 ++-- engines/cge/cge_main.cpp | 8 +++++--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 7e8c8377a88..239fc89dfcc 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -123,11 +123,12 @@ void CGEEngine::setup() { _maxCaveArr[3] = 23; _maxCaveArr[4] = 24; }; - _maxCave = 0; - _dark = false; - _game = false; - _now = 1; - _lev = -1; + _maxCave = 0; + _dark = false; + _game = false; + _now = 1; + _lev = -1; + _recentStep = -2; for (int i = 0; i < 4; i++) _flag[i] = false; diff --git a/engines/cge/cge.h b/engines/cge/cge.h index b67b6b28a7d..d83025dd25f 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -111,7 +111,7 @@ public: bool _game; int _now; int _lev; - char _usrFnam[15]; + char _usrFnam[15]; Common::RandomSource _randomSource; byte * _mini; @@ -189,7 +189,7 @@ public: void miniStep(int stp); void AltCtrlDel(); void postMiniStep(int stp); - void ShowBak(int ref); + void showBak(int ref); void snBackPt(Sprite *spr, int stp); void snBarrier(int cav, int bar, bool horz); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 10ec47e815d..527d075ade0 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -560,8 +560,8 @@ void CGEEngine::postMiniStep(int step) { SNPOST2_(SNEXEC, -1, _recentStep = step, kMiniStep); } -void CGEEngine::ShowBak(int ref) { - debugC(1, kDebugEngine, "CGEEngine::ShowBack(%d)", ref); +void CGEEngine::showBak(int ref) { + debugC(1, kDebugEngine, "CGEEngine::showBack(%d)", ref); Sprite *spr = _vga->_spareQ->locate(ref); if (spr) { @@ -582,7 +582,7 @@ void CGEEngine::caveUp() { if (_music) loadMidi(_now); - ShowBak(BakRef); + showBak(BakRef); loadMapping(); _text->preload(BakRef, BakRef + 1000); Sprite *spr = _vga->_spareQ->first(); @@ -1042,6 +1042,8 @@ void CGEEngine::nextStep() { } void CGEEngine::saveMapping() { + debugC(1, kDebugEngine, "CGEEngine::saveMapping()"); + IoHand cfTab(progName(".TAB"), UPD); if (!cfTab._error) { cfTab.seek((_now - 1) * sizeof(Cluster::_map)); From 5190bbb7bef0e5ad51880f24e9fab465d7343428 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 19 Jul 2011 07:13:41 +0200 Subject: [PATCH 151/276] CGE: Finish adding debugc to CGEEngine class members --- engines/cge/cge.h | 10 +- engines/cge/config.cpp | 2 + engines/cge/snail.cpp | 228 +++++++++++++++++++++++++++++------------ engines/cge/text.cpp | 2 + 4 files changed, 171 insertions(+), 71 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index d83025dd25f..431dcc79ad2 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -194,7 +194,7 @@ public: void snBackPt(Sprite *spr, int stp); void snBarrier(int cav, int bar, bool horz); void snCover(Sprite *spr, int xref); - void snFlag(int fn, bool v); + void snFlag(int indx, bool v); void snFlash(bool on); void snGame(Sprite *spr, int num); void snGhost(Bitmap *bmp); @@ -205,12 +205,12 @@ public: void snLevel(Sprite *spr, int lev); void snLight(bool in); void snMouse(bool on); - void snNNext(Sprite *sprel, int p); + void snNNext(Sprite *spr, int p); void snPort(Sprite *spr, int port); void snReach(Sprite *spr, int mode); void snRelZ(Sprite *spr, int z); - void snRNNext(Sprite *sprel, int p); - void snRTNext(Sprite *sprel, int p); + void snRNNext(Sprite *spr, int p); + void snRTNext(Sprite *spr, int p); void snSelect(); void snSend(Sprite *spr, int val); void snRelX(Sprite *spr, int x); @@ -229,7 +229,7 @@ public: void snSlave(Sprite *spr, int ref); void snSound(Sprite *spr, int wav, int cnt); void snSwap(Sprite *spr, int xref); - void snTNext(Sprite *sprel, int p); + void snTNext(Sprite *spr, int p); void snTrans(Sprite *spr, int trans); void snUncover(Sprite *spr, Sprite *xspr); void snWalk(Sprite *spr, int x, int y); diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index f8d5431ef08..1391c909eb2 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -39,6 +39,8 @@ static Choice *_cho; static int _hlp; void CGEEngine::snSelect() { + debugC(1, kDebugEngine, "CGEEngine::snSelect()"); + inf(_text->getText(_hlp)); _talk->gotoxy(_talk->_x, FONT_HIG / 2); (new Vmenu(this, _cho, SCR_WID / 2, _talk->_y + _talk->_h + TEXT_VM + FONT_HIG))->setName(_text->getText(MENU_TEXT)); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 9d5b188fe52..1393daa3925 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -46,6 +46,8 @@ extern Sprite *_pocLight; extern Sprite *_pocket[]; void CGEEngine::snGame(Sprite *spr, int num) { + debugC(1, kDebugEngine, "CGEEngine::snGame(spr, %d)", num); + switch (num) { case 1 : { #define STAGES 8 @@ -255,17 +257,23 @@ void CGEEngine::snGame(Sprite *spr, int num) { void CGEEngine::expandSprite(Sprite *spr) { + debugC(5, kDebugEngine, "CGEEngine::expandSprite(spr)"); + if (spr) _vga->_showQ->insert(_vga->_spareQ->remove(spr)); } void CGEEngine::contractSprite(Sprite *spr) { + debugC(1, kDebugEngine, "CGEEngine::contractSprite(spr)"); + if (spr) _vga->_spareQ->append(_vga->_showQ->remove(spr)); } int CGEEngine::findPocket(Sprite *spr) { + debugC(1, kDebugEngine, "CGEEngine::findPocket(spr)"); + for (int i = 0; i < POCKET_NX; i++) if (_pocket[i] == spr) return i; @@ -274,6 +282,8 @@ int CGEEngine::findPocket(Sprite *spr) { void CGEEngine::selectPocket(int n) { + debugC(1, kDebugEngine, "CGEEngine::selectPocket(%d)", n); + if (n < 0 || (_pocLight->_seqPtr && _pocPtr == n)) { _pocLight->step(0); n = findPocket(NULL); @@ -289,6 +299,8 @@ void CGEEngine::selectPocket(int n) { } void CGEEngine::pocFul() { + debugC(1, kDebugEngine, "CGEEngine::pocFul()"); + _hero->park(); SNPOST(SNWAIT, -1, -1, _hero); SNPOST(SNSEQ, -1, POC_FUL, _hero); @@ -298,10 +310,14 @@ void CGEEngine::pocFul() { } void CGEEngine::hide1(Sprite *spr) { + debugC(1, kDebugEngine, "CGEEngine::hide1(spr)"); + SNPOST_(SNGHOST, -1, 0, spr->ghost()); } void CGEEngine::snGhost(Bitmap *bmp) { + debugC(1, kDebugEngine, "CGEEngine::snGhost(bmp)"); + bmp->hide(bmp->_map & 0xFFFF, bmp->_map >> 16); bmp->_m = NULL; bmp->_map = 0; @@ -309,6 +325,8 @@ void CGEEngine::snGhost(Bitmap *bmp) { } void CGEEngine::feedSnail(Sprite *spr, SnList snq) { + debugC(1, kDebugEngine, "CGEEngine::feedSnail(spr, snq)"); + if (spr) if (spr->active()) { uint8 ptr = (snq == kTake) ? spr->_takePtr : spr->_nearPtr; @@ -454,32 +472,42 @@ void Snail::insCom(SNCOM com, int ref, int val, void *ptr) { } } -void CGEEngine::snNNext(Sprite *sprel, int p) { - if (sprel) - if (sprel->_nearPtr != NO_PTR) - sprel->_nearPtr = p; +void CGEEngine::snNNext(Sprite *spr, int p) { + debugC(1, kDebugEngine, "CGEEngine::snNNext(spr, %d)", p); + + if (spr) + if (spr->_nearPtr != NO_PTR) + spr->_nearPtr = p; } -void CGEEngine::snTNext(Sprite *sprel, int p) { - if (sprel) - if (sprel->_takePtr != NO_PTR) - sprel->_takePtr = p; +void CGEEngine::snTNext(Sprite *spr, int p) { + debugC(1, kDebugEngine, "CGEEngine::snTNext(spr, %d)", p); + + if (spr) + if (spr->_takePtr != NO_PTR) + spr->_takePtr = p; } -void CGEEngine::snRNNext(Sprite *sprel, int p) { - if (sprel) - if (sprel->_nearPtr != NO_PTR) - sprel->_nearPtr += p; +void CGEEngine::snRNNext(Sprite *spr, int p) { + debugC(1, kDebugEngine, "CGEEngine::snRNNext(spr, %d)", p); + + if (spr) + if (spr->_nearPtr != NO_PTR) + spr->_nearPtr += p; } -void CGEEngine::snRTNext(Sprite *sprel, int p) { - if (sprel) - if (sprel->_takePtr != NO_PTR) - sprel->_takePtr += p; +void CGEEngine::snRTNext(Sprite *spr, int p) { + debugC(1, kDebugEngine, "CGEEngine::snRTNext(spr, %d)", p); + + if (spr) + if (spr->_takePtr != NO_PTR) + spr->_takePtr += p; } void CGEEngine::snZTrim(Sprite *spr) { + debugC(4, kDebugEngine, "CGEEngine::snZTrim(spr)"); + if (spr) if (spr->active()) { bool en = _heart->_enable; @@ -496,6 +524,8 @@ void CGEEngine::snZTrim(Sprite *spr) { } void CGEEngine::snHide(Sprite *spr, int val) { + debugC(1, kDebugEngine, "CGEEngine::snHide(spr, %d)", val); + if (spr) { spr->_flags._hide = (val >= 0) ? (val != 0) : (!spr->_flags._hide); if (spr->_flags._shad) @@ -504,16 +534,22 @@ void CGEEngine::snHide(Sprite *spr, int val) { } void CGEEngine::snRmNear(Sprite *spr) { + debugC(1, kDebugEngine, "CGEEngine::snRmNear(spr)"); + if (spr) spr->_nearPtr = NO_PTR; } void CGEEngine::snRmTake(Sprite *spr) { + debugC(1, kDebugEngine, "CGEEngine::snRmTake(spr)"); + if (spr) spr->_takePtr = NO_PTR; } void CGEEngine::snSeq(Sprite *spr, int val) { + debugC(1, kDebugEngine, "CGEEngine::snSeq(spr, %d)", val); + if (spr) { if (spr == _hero && val == 0) _hero->park(); @@ -523,11 +559,15 @@ void CGEEngine::snSeq(Sprite *spr, int val) { } void CGEEngine::snRSeq(Sprite *spr, int val) { + debugC(1, kDebugEngine, "CGEEngine::snRSeq(spr, %d)", val); + if (spr) snSeq(spr, spr->_seqPtr + val); } void CGEEngine::snSend(Sprite *spr, int val) { + debugC(1, kDebugEngine, "CGEEngine::snSend(spr, %d)", val); + if (spr) { int was = spr->_cave; bool was1 = (was == 0 || was == _now); @@ -558,6 +598,8 @@ void CGEEngine::snSend(Sprite *spr, int val) { void CGEEngine::snSwap(Sprite *spr, int xref) { + debugC(1, kDebugEngine, "CGEEngine::snSwap(spr, %d)", xref); + Sprite *xspr = locate(xref); if (spr && xspr) { int was = spr->_cave; @@ -593,6 +635,8 @@ void CGEEngine::snSwap(Sprite *spr, int xref) { void CGEEngine::snCover(Sprite *spr, int xref) { + debugC(1, kDebugEngine, "CGEEngine::snCover(spr, %d)", xref); + Sprite *xspr = locate(xref); if (spr && xspr) { spr->_flags._hide = true; @@ -610,6 +654,8 @@ void CGEEngine::snCover(Sprite *spr, int xref) { void CGEEngine::snUncover(Sprite *spr, Sprite *xspr) { + debugC(1, kDebugEngine, "CGEEngine::snUncover(spr, xspr)"); + if (spr && xspr) { spr->_flags._hide = false; spr->_cave = xspr->_cave; @@ -627,30 +673,42 @@ void CGEEngine::snUncover(Sprite *spr, Sprite *xspr) { void CGEEngine::snSetX0(int cav, int x0) { + debugC(1, kDebugEngine, "CGEEngine::snSetX0(%d, %d)", cav, x0); + _heroXY[cav - 1]._x = x0; } void CGEEngine::snSetY0(int cav, int y0) { + debugC(1, kDebugEngine, "CGEEngine::snSetY0(%d, %d)", cav, y0); + _heroXY[cav - 1]._y = y0; } void CGEEngine::snSetXY(Sprite *spr, uint16 xy) { + debugC(1, kDebugEngine, "CGEEngine::snSetXY(spr, %d)", xy); + if (spr) spr->gotoxy(xy % SCR_WID, xy / SCR_WID); } void CGEEngine::snRelX(Sprite *spr, int x) { + debugC(1, kDebugEngine, "CGEEngine::snRelX(spr, %d)", x); + if (spr && _hero) spr->gotoxy(_hero->_x + x, spr->_y); } void CGEEngine::snRelY(Sprite *spr, int y) { + debugC(1, kDebugEngine, "CGEEngine::snRelY(spr, %d)", y); + if (spr && _hero) spr->gotoxy(spr->_x, _hero->_y + y); } void CGEEngine::snRelZ(Sprite *spr, int z) { + debugC(1, kDebugEngine, "CGEEngine::snRelZ(spr, %d)", z); + if (spr && _hero) { spr->_z = _hero->_z + z; snZTrim(spr); @@ -659,18 +717,24 @@ void CGEEngine::snRelZ(Sprite *spr, int z) { void CGEEngine::snSetX(Sprite *spr, int x) { + debugC(1, kDebugEngine, "CGEEngine::snSetX(spr, %d)", x); + if (spr) spr->gotoxy(x, spr->_y); } void CGEEngine::snSetY(Sprite *spr, int y) { + debugC(1, kDebugEngine, "CGEEngine::snSetY(spr, %d)", y); + if (spr) spr->gotoxy(spr->_x, y); } void CGEEngine::snSetZ(Sprite *spr, int z) { + debugC(1, kDebugEngine, "CGEEngine::snSetZ(spr, %d)", z); + if (spr) { spr->_z = z; //SNPOST_(SNZTRIM, -1, 0, spr); @@ -680,6 +744,8 @@ void CGEEngine::snSetZ(Sprite *spr, int z) { void CGEEngine::snSlave(Sprite *spr, int ref) { + debugC(1, kDebugEngine, "CGEEngine::snSlave(spr, %d)", ref); + Sprite *slv = locate(ref); if (spr && slv) { if (spr->active()) { @@ -693,16 +759,22 @@ void CGEEngine::snSlave(Sprite *spr, int ref) { void CGEEngine::snTrans(Sprite *spr, int trans) { + debugC(1, kDebugEngine, "CGEEngine::snTrans(spr, %d)", trans); + if (spr) spr->_flags._tran = (trans < 0) ? !spr->_flags._tran : (trans != 0); } void CGEEngine::snPort(Sprite *spr, int port) { + debugC(1, kDebugEngine, "CGEEngine::snPort(spr, %d)", port); + if (spr) spr->_flags._port = (port < 0) ? !spr->_flags._port : (port != 0); } void CGEEngine::snKill(Sprite *spr) { + debugC(1, kDebugEngine, "CGEEngine::snKill(spr)"); + if (spr) { if (spr->_flags._kept) { int n = findPocket(spr); @@ -728,6 +800,8 @@ void CGEEngine::snKill(Sprite *spr) { void CGEEngine::snSound(Sprite *spr, int wav, int cnt) { + debugC(1, kDebugEngine, "CGEEngine::snSound(spr, %d, %d)", wav, cnt); + if (_sndDrvInfo._dDev) { if (wav == -1) _sound.stop(); @@ -738,6 +812,8 @@ void CGEEngine::snSound(Sprite *spr, int wav, int cnt) { void CGEEngine::snKeep(Sprite *spr, int stp) { + debugC(1, kDebugEngine, "CGEEngine::snKeep(spr, %d)", stp); + selectPocket(-1); if (spr && ! spr->_flags._kept && _pocket[_pocPtr] == NULL) { snSound(spr, 3, 1); @@ -754,6 +830,8 @@ void CGEEngine::snKeep(Sprite *spr, int stp) { void CGEEngine::snGive(Sprite *spr, int stp) { + debugC(1, kDebugEngine, "CGEEngine::snGive(spr, %d)", stp); + if (spr) { int p = findPocket(spr); if (p >= 0) { @@ -769,6 +847,8 @@ void CGEEngine::snGive(Sprite *spr, int stp) { void CGEEngine::snBackPt(Sprite *spr, int stp) { + debugC(1, kDebugEngine, "CGEEngine::snBackPt(spr, %d)", stp); + if (spr) { if (stp >= 0) spr->step(stp); @@ -777,6 +857,8 @@ void CGEEngine::snBackPt(Sprite *spr, int stp) { } void CGEEngine::snLevel(Sprite *spr, int lev) { + debugC(1, kDebugEngine, "CGEEngine::snLevel(spr, %d)", lev); + while (_lev < lev) { _lev++; spr = _vga->_spareQ->locate(100 + _lev); @@ -791,16 +873,20 @@ void CGEEngine::snLevel(Sprite *spr, int lev) { } -void CGEEngine::snFlag(int fn, bool v) { - _flag[fn] = v; +void CGEEngine::snFlag(int indx, bool v) { + _flag[indx] = v; } void CGEEngine::snSetRef(Sprite *spr, int nr) { + debugC(1, kDebugEngine, "CGEEngine::snSetRef(spr, %d)", nr); + if (spr) spr->_ref = nr; } void CGEEngine::snFlash(bool on) { + debugC(1, kDebugEngine, "CGEEngine::snFlash(%s)", on ? "true" : "false"); + if (on) { Dac *pal = farnew(Dac, PAL_CNT); if (pal) { @@ -823,6 +909,8 @@ void CGEEngine::snFlash(bool on) { void CGEEngine::snLight(bool in) { + debugC(1, kDebugEngine, "CGEEngine::snLight(%s)", in ? "true" : "false"); + if (in) _vga->sunrise(Vga::_sysPal); else @@ -831,10 +919,14 @@ void CGEEngine::snLight(bool in) { } void CGEEngine::snBarrier(int cav, int bar, bool horz) { + debugC(1, kDebugEngine, "CGEEngine::snBarrier(%d, %d, %s)", cav, bar, horz ? "true" : "false"); + ((uint8 *)(_barriers + ((cav > 0) ? cav : _now)))[horz] = bar; } void CGEEngine::snWalk(Sprite *spr, int x, int y) { + debugC(1, kDebugEngine, "CGEEngine::snWalk(spr, %d, %d)", x, y); + if (_hero) { if (spr && y < 0) _hero->findWay(spr); @@ -844,11 +936,15 @@ void CGEEngine::snWalk(Sprite *spr, int x, int y) { } void CGEEngine::snReach(Sprite *spr, int mode) { + debugC(1, kDebugEngine, "CGEEngine::snReach(spr, %d)", mode); + if (_hero) _hero->reach(spr, mode); } void CGEEngine::snMouse(bool on) { + debugC(1, kDebugEngine, "CGEEngine::snMouse(%s)", on ? "true" : "false"); + if (on) _mouse->on(); else @@ -883,7 +979,7 @@ void Snail::runCom() { break; } - Sprite *sprel = ((snc->_ref >= 0) ? locate(snc->_ref) : ((Sprite *) snc->_ptr)); + Sprite *spr = ((snc->_ref >= 0) ? locate(snc->_ref) : ((Sprite *) snc->_ptr)); switch (snc->_com) { case SNLABEL : break; @@ -893,25 +989,25 @@ void Snail::runCom() { _textDelay = true; break; case SNWAIT : - if (sprel) { - if (sprel->seqTest(snc->_val) && - (snc->_val >= 0 || sprel != _hero || _hero->_tracePtr < 0)) { - _timerExpiry = g_system->getMillis() + sprel->_time * SNAIL_FRAME_DELAY; + if (spr) { + if (spr->seqTest(snc->_val) && + (snc->_val >= 0 || spr != _hero || _hero->_tracePtr < 0)) { + _timerExpiry = g_system->getMillis() + spr->_time * SNAIL_FRAME_DELAY; } else goto xit; } break; case SNLEVEL : - _vm->snLevel(sprel, snc->_val); + _vm->snLevel(spr, snc->_val); break; case SNHIDE : - _vm->snHide(sprel, snc->_val); + _vm->snHide(spr, snc->_val); break; case SNSAY : - if (sprel && _talkEnable) { - if (sprel == _hero && sprel->seqTest(-1)) - sprel->step(HTALK); - _text->say(_text->getText(snc->_val), sprel); + if (spr && _talkEnable) { + if (spr == _hero && spr->seqTest(-1)) + spr->step(HTALK); + _text->say(_text->getText(snc->_val), spr); _sys->_funDel = HEROFUN0; } break; @@ -922,44 +1018,44 @@ void Snail::runCom() { } break; case SNTIME : - if (sprel && _talkEnable) { - if (sprel == _hero && sprel->seqTest(-1)) - sprel->step(HTALK); - sayTime(sprel); + if (spr && _talkEnable) { + if (spr == _hero && spr->seqTest(-1)) + spr->step(HTALK); + sayTime(spr); } break; case SNCAVE : _vm->switchCave(snc->_val); break; case SNKILL : - _vm->snKill(sprel); + _vm->snKill(spr); break; case SNSEQ : - _vm->snSeq(sprel, snc->_val); + _vm->snSeq(spr, snc->_val); break; case SNRSEQ : - _vm->snRSeq(sprel, snc->_val); + _vm->snRSeq(spr, snc->_val); break; case SNSEND : - _vm->snSend(sprel, snc->_val); + _vm->snSend(spr, snc->_val); break; case SNSWAP : - _vm->snSwap(sprel, snc->_val); + _vm->snSwap(spr, snc->_val); break; case SNCOVER : - _vm->snCover(sprel, snc->_val); + _vm->snCover(spr, snc->_val); break; case SNUNCOVER : - _vm->snUncover(sprel, (snc->_val >= 0) ? locate(snc->_val) : ((Sprite *) snc->_ptr)); + _vm->snUncover(spr, (snc->_val >= 0) ? locate(snc->_val) : ((Sprite *) snc->_ptr)); break; case SNKEEP : - _vm->snKeep(sprel, snc->_val); + _vm->snKeep(spr, snc->_val); break; case SNGIVE : - _vm->snGive(sprel, snc->_val); + _vm->snGive(spr, snc->_val); break; case SNGAME : - _vm->snGame(sprel, snc->_val); + _vm->snGame(spr, snc->_val); break; case SNSETX0 : _vm->snSetX0(snc->_ref, snc->_val); @@ -968,34 +1064,34 @@ void Snail::runCom() { _vm->snSetY0(snc->_ref, snc->_val); break; case SNSETXY : - _vm->snSetXY(sprel, snc->_val); + _vm->snSetXY(spr, snc->_val); break; case SNRELX : - _vm->snRelX(sprel, snc->_val); + _vm->snRelX(spr, snc->_val); break; case SNRELY : - _vm->snRelY(sprel, snc->_val); + _vm->snRelY(spr, snc->_val); break; case SNRELZ : - _vm->snRelZ(sprel, snc->_val); + _vm->snRelZ(spr, snc->_val); break; case SNSETX : - _vm->snSetX(sprel, snc->_val); + _vm->snSetX(spr, snc->_val); break; case SNSETY : - _vm->snSetY(sprel, snc->_val); + _vm->snSetY(spr, snc->_val); break; case SNSETZ : - _vm->snSetZ(sprel, snc->_val); + _vm->snSetZ(spr, snc->_val); break; case SNSLAVE : - _vm->snSlave(sprel, snc->_val); + _vm->snSlave(spr, snc->_val); break; case SNTRANS : - _vm->snTrans(sprel, snc->_val); + _vm->snTrans(spr, snc->_val); break; case SNPORT : - _vm->snPort(sprel, snc->_val); + _vm->snPort(spr, snc->_val); break; case SNNEXT : case SNIF : @@ -1005,31 +1101,31 @@ void Snail::runCom() { _vm->snMouse(snc->_val != 0); break; case SNNNEXT : - _vm->snNNext(sprel, snc->_val); + _vm->snNNext(spr, snc->_val); break; case SNTNEXT : - _vm->snTNext(sprel, snc->_val); + _vm->snTNext(spr, snc->_val); break; case SNRNNEXT : - _vm->snRNNext(sprel, snc->_val); + _vm->snRNNext(spr, snc->_val); break; case SNRTNEXT : - _vm->snRTNext(sprel, snc->_val); + _vm->snRTNext(spr, snc->_val); break; case SNRMNEAR : - _vm->snRmNear(sprel); + _vm->snRmNear(spr); break; case SNRMTAKE : - _vm->snRmTake(sprel); + _vm->snRmTake(spr); break; case SNFLAG : _vm->snFlag(snc->_ref & 3, snc->_val != 0); break; case SNSETREF : - _vm->snSetRef(sprel, snc->_val); + _vm->snSetRef(spr, snc->_val); break; case SNBACKPT : - _vm->snBackPt(sprel, snc->_val); + _vm->snBackPt(spr, snc->_val); break; case SNFLASH : _vm->snFlash(snc->_val != 0); @@ -1044,13 +1140,13 @@ void Snail::runCom() { _vm->snBarrier(snc->_ref, snc->_val, false); break; case SNWALK : - _vm->snWalk(sprel, snc->_ref, snc->_val); + _vm->snWalk(spr, snc->_ref, snc->_val); break; case SNREACH : - _vm->snReach(sprel, snc->_val); + _vm->snReach(spr, snc->_val); break; case SNSOUND : - _vm->snSound(sprel, snc->_val, count); + _vm->snSound(spr, snc->_val, count); count = 1; break; case SNCOUNT : @@ -1081,10 +1177,10 @@ void Snail::runCom() { } break; case SNSTEP : - sprel->step(); + spr->step(); break; case SNZTRIM : - _vm->snZTrim(sprel); + _vm->snZTrim(spr); break; case SNGHOST : _vm->snGhost((Bitmap *) snc->_ptr); diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 63d618b5d50..1cc25da5e13 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -218,6 +218,8 @@ void Text::say(const char *txt, Sprite *spr) { } void CGEEngine::inf(const char *txt) { + debugC(1, kDebugEngine, "CGEEngine::inf(%s)", txt); + killText(); _talk = new Talk(this, txt, RECT); if (_talk) { From a073e78ba1fb4be357660a03aa0c387d80df3aab Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 19 Jul 2011 07:50:07 +0200 Subject: [PATCH 152/276] CGE: Rename constants (WIP) --- engines/cge/config.cpp | 4 +-- engines/cge/gettext.cpp | 6 ++--- engines/cge/talk.cpp | 58 +++++++++++++++++------------------------ engines/cge/talk.h | 19 ++++++++------ engines/cge/text.cpp | 4 +-- engines/cge/vmenu.cpp | 41 ++++++++++------------------- engines/cge/vmenu.h | 6 +++-- 7 files changed, 60 insertions(+), 78 deletions(-) diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 1391c909eb2..b49d2b77ea0 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -42,8 +42,8 @@ void CGEEngine::snSelect() { debugC(1, kDebugEngine, "CGEEngine::snSelect()"); inf(_text->getText(_hlp)); - _talk->gotoxy(_talk->_x, FONT_HIG / 2); - (new Vmenu(this, _cho, SCR_WID / 2, _talk->_y + _talk->_h + TEXT_VM + FONT_HIG))->setName(_text->getText(MENU_TEXT)); + _talk->gotoxy(_talk->_x, kFontHigh / 2); + (new Vmenu(this, _cho, SCR_WID / 2, _talk->_y + _talk->_h + kTextVMargin + kFontHigh))->setName(_text->getText(MENU_TEXT)); } } // End of namespace CGE diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index f5c62809dbd..2f16cad86ae 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -37,12 +37,12 @@ GetText *GetText::_ptr = NULL; GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) : Talk(vm), _text(text), _size(min(size, GTMAX)), _len(min(_size, strlen(text))), _cntr(GTBLINK), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { - int i = 2 * TEXT_HM + _font->width(info); + int i = 2 * kTextHMargin + _font->width(info); _ptr = this; _mode = RECT; _ts = new BMP_PTR[2]; - _ts[0] = box((i + 3) & ~3, 2 * TEXT_VM + 2 * FONT_HIG + TEXT_LS); + _ts[0] = box((i + 3) & ~3, 2 * kTextVMargin + 2 * kFontHigh + kTextLineSpace); _ts[1] = NULL; setShapeList(_ts); @@ -108,7 +108,7 @@ void GetText::touch(uint16 mask, int x, int y) { if (p) x = ogon[p - bezo]; } - if (_len < _size && 2 * TEXT_HM + _font->width(_buff) + _font->_wid[x] <= _w) { + if (_len < _size && 2 * kTextHMargin + _font->width(_buff) + _font->_wid[x] <= _w) { _buff[_len + 2] = _buff[_len + 1]; _buff[_len + 1] = _buff[_len]; _buff[_len++] = x; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index e2a5af5fde2..aa342f8216e 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -32,23 +32,13 @@ #include "cge/events.h" namespace CGE { - -#define WID_SIZ 256 -#define POS_SIZ 256 -#define MAP_SIZ (256*8) - -//uint8 FONT::Wid[WID_SIZ]; -//uint16 FONT::Pos[POS_SIZ]; -//uint8 FONT::Map[MAP_SIZ]; - - Font::Font(const char *name) { - _map = farnew(uint8, MAP_SIZ); - _pos = farnew(uint16, POS_SIZ); - _wid = farnew(uint8, WID_SIZ); + _map = farnew(uint8, kMapSize); + _pos = farnew(uint16, kPosSize); + _wid = farnew(uint8, kWidSize); if ((_map == NULL) || (_pos == NULL) || (_wid == NULL)) error("No core"); - mergeExt(_path, name, FONT_EXT); + mergeExt(_path, name, kFontExt); load(); } @@ -63,10 +53,10 @@ Font::~Font() { void Font::load() { INI_FILE f(_path); if (!f._error) { - f.read(_wid, WID_SIZ); + f.read(_wid, kWidSize); if (!f._error) { uint16 i, p = 0; - for (i = 0; i < POS_SIZ; i++) { + for (i = 0; i < kPosSize; i++) { _pos[i] = p; p += _wid[i]; } @@ -136,18 +126,18 @@ void Talk::deinit() { void Talk::update(const char *tx) { - uint16 vmarg = (_mode) ? TEXT_VM : 0; - uint16 hmarg = (_mode) ? TEXT_HM : 0; + uint16 vmarg = (_mode) ? kTextVMargin : 0; + uint16 hmarg = (_mode) ? kTextHMargin : 0; uint16 mw = 0, mh, ln = vmarg; const char *p; uint8 *m; if (!_ts) { uint16 k = 2 * hmarg; - mh = 2 * vmarg + FONT_HIG; + mh = 2 * vmarg + kFontHigh; for (p = tx; *p; p++) { if (*p == '|' || *p == '\n') { - mh += FONT_HIG + TEXT_LS; + mh += kFontHigh + kTextLineSpace; if (k > mw) mw = k; k = 2 * hmarg; @@ -166,7 +156,7 @@ void Talk::update(const char *tx) { while (* tx) { if (*tx == '|' || *tx == '\n') - m = _ts[0]->_m + (ln += FONT_HIG + TEXT_LS) * mw + hmarg; + m = _ts[0]->_m + (ln += kFontHigh + kTextLineSpace) * mw + hmarg; else { int cw = _font->_wid[(unsigned char)*tx], i; uint8 *f = _font->_map + _font->_pos[(unsigned char)*tx]; @@ -174,9 +164,9 @@ void Talk::update(const char *tx) { uint8 *pp = m; uint16 n; register uint16 b = *(f++); - for (n = 0; n < FONT_HIG; n++) { + for (n = 0; n < kFontHigh; n++) { if (b & 1) - *pp = TEXT_FG; + *pp = kTextColFG; b >>= 1; pp += mw; } @@ -194,7 +184,7 @@ void Talk::update(const char *tx) { Bitmap *Talk::box(uint16 w, uint16 h) { uint8 *b, * p, * q; - uint16 n, r = (_mode == ROUND) ? TEXT_RD : 0; + uint16 n, r = (_mode == ROUND) ? kTextRoundCorner : 0; if (w < 8) w = 8; @@ -203,7 +193,7 @@ Bitmap *Talk::box(uint16 w, uint16 h) { b = farnew(uint8, n = w * h); if (! b) error("No core"); - memset(b, TEXT_BG, n); + memset(b, kTextColBG, n); if (_mode) { p = b; @@ -245,10 +235,10 @@ void Talk::putLine(int line, const char *text) { uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap uint16 psiz = h * lsiz; // - last gap, but + plane trailer uint16 size = 4 * psiz; // whole map size - uint16 rsiz = FONT_HIG * lsiz; // length of whole text row map + uint16 rsiz = kFontHigh * lsiz; // length of whole text row map // set desired line pointer - v += (TEXT_VM + (FONT_HIG + TEXT_LS) * line) * lsiz; + v += (kTextVMargin + (kFontHigh + kTextLineSpace) * line) * lsiz; p = v; // assume blanked line above text // clear whole rectangle @@ -261,7 +251,7 @@ void Talk::putLine(int line, const char *text) { // paint text line if (text) { uint8 *q; - p = v + 2 + TEXT_HM / 4 + (TEXT_HM % 4) * psiz; + p = v + 2 + kTextHMargin / 4 + (kTextHMargin % 4) * psiz; q = v + size; while (* text) { @@ -271,9 +261,9 @@ void Talk::putLine(int line, const char *text) { for (i = 0; i < cw; i++) { register uint16 b = fp[i]; uint16 n; - for (n = 0; n < FONT_HIG; n++) { + for (n = 0; n < kFontHigh; n++) { if (b & 1) - *p = TEXT_FG; + *p = kTextColFG; b >>= 1; p += lsiz; } @@ -293,7 +283,7 @@ InfoLine::InfoLine(CGEEngine *vm, uint16 w) : Talk(vm), _oldTxt(NULL), _vm(vm) { _ts[1] = NULL; } - _ts[0] = new Bitmap(w, FONT_HIG, TEXT_BG); + _ts[0] = new Bitmap(w, kFontHigh, kTextColBG); setShapeList(_ts); } @@ -310,7 +300,7 @@ void InfoLine::update(const char *tx) { // clear whole rectangle byte *pDest; - memset(v + 2, TEXT_BG, dsiz); // data bytes + memset(v + 2, kTextColBG, dsiz); // data bytes for (pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz) { Common::copy(v, v + lsiz, pDest); } @@ -329,9 +319,9 @@ void InfoLine::update(const char *tx) { for (uint16 i = 0; i < cw; i++) { register uint16 b = fp[i]; - for (uint16 n = 0; n < FONT_HIG; n++) { + for (uint16 n = 0; n < kFontHigh; n++) { if (b & 1) - *p = TEXT_FG; + *p = kTextColFG; b >>= 1; p += lsiz; } diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 4d30047ea14..e8136271f6a 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -34,15 +34,18 @@ namespace CGE { -#define TEXT_FG DARK // foreground color -#define TEXT_BG GRAY // background color -#define TEXT_HM (6&~1) // EVEN horizontal margins! -#define TEXT_VM 5 // vertical margins -#define TEXT_LS 2 // line spacing -#define TEXT_RD 3 // rounded corners +#define kTextColFG DARK // foreground color +#define kTextColBG GRAY // background color +#define kTextHMargin (6&~1) // EVEN horizontal margins! +#define kTextVMargin 5 // vertical margins +#define kTextLineSpace 2 // line spacing +#define kTextRoundCorner 3 // rounded corners +#define kWidSize 256 +#define kPosSize 256 +#define kMapSize (256*8) -#define FONT_HIG 8 -#define FONT_EXT ".CFT" +#define kFontHigh 8 +#define kFontExt ".CFT" diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 1cc25da5e13..fd37dada8b8 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -187,10 +187,10 @@ void Text::say(const char *txt, Sprite *spr) { uint16 sw = spike->_w; if (east) { - if (x + sw + TEXT_RD + 5 >= SCR_WID) + if (x + sw + kTextRoundCorner + 5 >= SCR_WID) east = false; } else { - if (x <= 5 + TEXT_RD + sw) + if (x <= 5 + kTextRoundCorner + sw) east = true; } x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2 - sw); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 0c0e1fb8554..bc5e5cfb6c3 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -31,31 +31,18 @@ namespace CGE { - -#define RELIEF 1 -#if RELIEF -#define MB_LT LGRAY -#define MB_RB DGRAY -#else -#define MB_LT DGRAY -#define MB_RB LGRAY -#endif - - - - MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { - int h = FONT_HIG + 2 * MB_VM, i = (w += 2 * MB_HM) * h; + int h = kFontHigh + 2 * kMenuBarVM, i = (w += 2 * kMenuBarHM) * h; uint8 *p = farnew(uint8, i), * p1, * p2; memset(p + w, TRANS, i - 2 * w); - memset(p, MB_LT, w); - memset(p + i - w, MB_RB, w); + memset(p, kMenuBarLT, w); + memset(p + i - w, kMenuBarRB, w); p1 = p; p2 = p + i - 1; for (i = 0; i < h; i++) { - *p1 = MB_LT; - *p2 = MB_RB; + *p1 = kMenuBarLT; + *p2 = kMenuBarRB; p1 += w; p2 -= w; } @@ -115,10 +102,10 @@ Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y) if (x < 0 || y < 0) center(); else - gotoxy(x - _w / 2, y - (TEXT_VM + FONT_HIG / 2)); + gotoxy(x - _w / 2, y - (kTextVMargin + kFontHigh / 2)); _vga->_showQ->insert(this, _vga->_showQ->last()); - _bar = new MenuBar(_vm, _w - 2 * TEXT_HM); - _bar->gotoxy(_x + TEXT_HM - MB_HM, _y + TEXT_VM - MB_VM); + _bar = new MenuBar(_vm, _w - 2 * kTextHMargin); + _bar->gotoxy(_x + kTextHMargin - kMenuBarHM, _y + kTextVMargin - kMenuBarVM); _vga->_showQ->insert(_bar, _vga->_showQ->last()); } @@ -130,23 +117,23 @@ Vmenu::~Vmenu() { #define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) void Vmenu::touch(uint16 mask, int x, int y) { - uint16 h = FONT_HIG + TEXT_LS; - bool ok = false; - if (_items) { Sprite::touch(mask, x, y); - y -= TEXT_VM - 1; + y -= kTextVMargin - 1; int n = 0; + bool ok = false; + uint16 h = kFontHigh + kTextLineSpace; + if (y >= 0) { n = y / h; if (n < _items) - ok = (x >= TEXT_HM && x < _w - TEXT_HM/* && y % h < FONT_HIG*/); + ok = (x >= kTextHMargin && x < _w - kTextHMargin/* && y % h < FONT_HIG*/); else n = _items - 1; } - _bar->gotoxy(_x + TEXT_HM - MB_HM, _y + TEXT_VM + n * h - MB_VM); + _bar->gotoxy(_x + kTextHMargin - kMenuBarHM, _y + kTextVMargin + n * h - kMenuBarVM); if (ok && (mask & L_UP)) { _items = 0; diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index 6b4eb85a53f..93979b58957 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -32,8 +32,10 @@ namespace CGE { -#define MB_VM 1 -#define MB_HM 3 +#define kMenuBarVM 1 +#define kMenuBarHM 3 +#define kMenuBarLT LGRAY +#define kMenuBarRB DGRAY struct Choice { From 9a148a27cc44ba089e57ea07996a868c89c2287f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 19 Jul 2011 08:09:16 +0200 Subject: [PATCH 153/276] CGE: Remove macro farnew --- engines/cge/bitmap.cpp | 6 +++--- engines/cge/cfile.cpp | 4 ++-- engines/cge/cge.h | 1 + engines/cge/jbw.h | 1 - engines/cge/snail.cpp | 4 ++-- engines/cge/talk.cpp | 9 +++++---- engines/cge/vga13h.cpp | 4 ++-- engines/cge/vmenu.cpp | 11 ++++++----- 8 files changed, 21 insertions(+), 19 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index f280f61e3ef..29fc4fd8d61 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -142,7 +142,7 @@ Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), if (v0) { uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); uint16 siz = vsiz + _h * sizeof(HideDesc); - uint8 *v1 = farnew(uint8, siz); + uint8 *v1 = (uint8 *) malloc(sizeof(uint8) * siz); if (v1 == NULL) error("No core"); memcpy(v1, v0, siz); @@ -173,7 +173,7 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { else { uint16 vsiz = (uint8 *)bmp._b - (uint8 *)v0; uint16 siz = vsiz + _h * sizeof(HideDesc); - uint8 *v1 = farnew(uint8, siz); + uint8 *v1 = (uint8 *) malloc(sizeof(uint8) * siz); if (v1 == NULL) error("No core"); memcpy(v1, v0, siz); @@ -486,7 +486,7 @@ bool Bitmap::loadBMP(XFile *f) { } _h = hea.hig; _w = hea.wid; - if ((_m = farnew(byte, _h * _w)) != NULL) { + if ((_m = (byte *) malloc(sizeof(byte) * (_h * _w))) != NULL) { int16 r = (4 - (hea.wid & 3)) % 4; byte buf[3]; for (i = _h - 1; i >= 0; i--) { diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index af29ec5df77..5cbf078610b 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -40,7 +40,7 @@ IoBuf::IoBuf(IOMODE mode, CRYPT *crpt) _lim(0) { debugC(1, kDebugFile, "IoBuf::IoBuf(%d, crpt)", mode); - _buff = farnew(uint8, IOBUF_SIZE); + _buff = (uint8 *) malloc(sizeof(uint8) * IOBUF_SIZE); if (_buff == NULL) error("No core for I/O"); } @@ -53,7 +53,7 @@ IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt) _lim(0) { debugC(1, kDebugFile, "IoBuf::IoBuf(%s, %d, crpt)", name, mode); - _buff = farnew(uint8, IOBUF_SIZE); + _buff = (uint8 *) malloc(sizeof(uint8) * IOBUF_SIZE); if (_buff == NULL) error("No core for I/O [%s]", name); } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 431dcc79ad2..011e08bb319 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -236,6 +236,7 @@ public: void snZTrim(Sprite *spr); protected: int _recentStep; + private: CGEConsole *_console; void setup(); diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 74084fb905c..89bcb2b03e0 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -55,7 +55,6 @@ namespace CGE { #define IsAlNum(c) (IsAlpha(c) || IsDigit(c)) #define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) -#define farnew(t, n) ((t *) malloc(sizeof(t) * (n))) #define ArrayCount(a) (sizeof(a) / sizeof((a)[0])) #define MAX_TIMER 0x1800B0L diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 1393daa3925..b0f56be4764 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -417,7 +417,7 @@ const char *Snail::_comTxt[] = { Snail::Snail(CGEEngine *vm, bool turbo) : _turbo(turbo), _busy(false), _textDelay(false), _timerExpiry(0), _talkEnable(true), - _head(0), _tail(0), _snList(farnew(Com, 256)), _vm(vm) { + _head(0), _tail(0), _snList((Com *) malloc(sizeof(Com) * 256)), _vm(vm) { } Snail::~Snail() { @@ -888,7 +888,7 @@ void CGEEngine::snFlash(bool on) { debugC(1, kDebugEngine, "CGEEngine::snFlash(%s)", on ? "true" : "false"); if (on) { - Dac *pal = farnew(Dac, PAL_CNT); + Dac *pal = (Dac *) malloc(sizeof(Dac) * PAL_CNT); if (pal) { memcpy(pal, Vga::_sysPal, PAL_SIZ); for (int i = 0; i < PAL_CNT; i++) { diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index aa342f8216e..c00e7f3a88d 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -33,9 +33,9 @@ namespace CGE { Font::Font(const char *name) { - _map = farnew(uint8, kMapSize); - _pos = farnew(uint16, kPosSize); - _wid = farnew(uint8, kWidSize); + _map = (uint8 *) malloc(sizeof(uint8) * kMapSize); + _pos = (uint16 *) malloc(sizeof(uint16) * kPosSize); + _wid = (uint8 *) malloc(sizeof(uint8) * kWidSize); if ((_map == NULL) || (_pos == NULL) || (_wid == NULL)) error("No core"); mergeExt(_path, name, kFontExt); @@ -190,7 +190,8 @@ Bitmap *Talk::box(uint16 w, uint16 h) { w = 8; if (h < 8) h = 8; - b = farnew(uint8, n = w * h); + n = w * h; + b = (uint8 *) malloc(sizeof(uint8) * n); if (! b) error("No core"); memset(b, kTextColBG, n); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index ca6a9e3bdd6..6fc17dc37b9 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -986,8 +986,8 @@ Vga::Vga(int mode) setStatAdr(); if (_statAdr != VGAST1_) _mono++; - _oldColors = farnew(Dac, 256); - _newColors = farnew(Dac, 256); + _oldColors = (Dac *) malloc(sizeof(Dac) * PAL_CNT); + _newColors = (Dac *) malloc(sizeof(Dac) * PAL_CNT); _oldScreen = SaveScreen(); getColors(_oldColors); sunset(); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index bc5e5cfb6c3..c65ec6957ec 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -32,15 +32,16 @@ namespace CGE { MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { - int h = kFontHigh + 2 * kMenuBarVM, i = (w += 2 * kMenuBarHM) * h; - uint8 *p = farnew(uint8, i), * p1, * p2; + int h = kFontHigh + 2 * kMenuBarVM; + int i = (w += 2 * kMenuBarHM) * h; + uint8 *p = (uint8 *) malloc(sizeof(uint8) * i); memset(p + w, TRANS, i - 2 * w); memset(p, kMenuBarLT, w); memset(p + i - w, kMenuBarRB, w); - p1 = p; - p2 = p + i - 1; - for (i = 0; i < h; i++) { + uint8 *p1 = p; + uint8 *p2 = p + i - 1; + for (int cpt = 0; cpt < h; cpt++) { *p1 = kMenuBarLT; *p2 = kMenuBarRB; p1 += w; From 2e6e7d81da3a2c81c80478edf1b7d2eee5b92340 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 19 Jul 2011 08:24:06 +0200 Subject: [PATCH 154/276] CGE: cleanup in jbw.h --- engines/cge/btfile.h | 2 +- engines/cge/cfile.h | 5 +---- engines/cge/cge_main.cpp | 2 +- engines/cge/general.cpp | 4 ++-- engines/cge/jbw.h | 44 ++++++---------------------------------- engines/cge/vga13h.h | 2 +- 6 files changed, 12 insertions(+), 47 deletions(-) diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 1ac093d897b..1f3d7217ce0 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -32,7 +32,7 @@ namespace CGE { -#define BT_SIZE K(1) +#define BT_SIZE 1024 #define BT_KEYLEN 13 #define BT_LEVELS 2 diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index 490e120afa4..b5bf9da603c 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -33,10 +33,7 @@ namespace CGE { #define LINE_MAX 512 - -#ifndef IOBUF_SIZE -#define IOBUF_SIZE K(2) -#endif +#define IOBUF_SIZE 2048 #define CFREAD(x) read((uint8 *)(x),sizeof(*(x))) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 527d075ade0..3958225583f 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -54,7 +54,7 @@ namespace CGE { -#define STACK_SIZ (K(2)) +#define STACK_SIZ 2048 #define SVGCHKSUM (1956 + _now + _oldLev + _game + _music + _demoText) #define SVG0NAME ("{{INIT}}" SVG_EXT) diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 25b7cc25a50..8639c66653d 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -100,12 +100,12 @@ void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, c } const char *progName(const char *ext) { - static char buf[MAXFILE]; + static char buf[kMaxFile]; strcpy(buf, "CGE"); if (ext) { strcat(buf, "."); if (*ext == '.') - ++ext; + ext++; strcat(buf, ext); } diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 89bcb2b03e0..d555c82c5a5 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -39,33 +39,11 @@ namespace CGE { #define BMP_MODE 0 // -#define BEL 7 -#define BS 8 -#define HT 9 -#define LF 10 -#define FF 12 -#define CR 13 -#define MAXFILE 128 +#define kMaxFile 128 -#define IsWhite(c) ((c) == ' ' || (c) == '\t' || (c) == '\n') -#define IsUpper(c) ((c) >= 'A' && (c) <= 'Z') -#define IsLower(c) ((c) >= 'a' && (c) <= 'z') -#define IsDigit(c) ((c) >= '0' && (c) <= '9') -#define IsAlpha(c) (IsLower(c) || IsUpper(c) || (c) == '_') -#define IsAlNum(c) (IsAlpha(c) || IsDigit(c)) -#define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) - -#define ArrayCount(a) (sizeof(a) / sizeof((a)[0])) -#define MAX_TIMER 0x1800B0L - -typedef void (MouseFunType)(); - -#define Lo(d) (((int *) &d)[0]) -#define Hi(d) (((int *) &d)[1]) -#define LoWord(d) ((uint16) Lo(d)) -#define HiWord(d) ((uint16) Hi(d)) -#define K(n) (1024 * (n)) -#define MASK(n) ((1 << n) - 1) +#define IsDigit(c) ((c) >= '0' && (c) <= '9') +#define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) +#define ArrayCount(a) (sizeof(a) / sizeof((a)[0])) enum Keys { NoKey = 0, CtrlA, CtrlB, CtrlC, CtrlD, CtrlE, CtrlF, CtrlG, CtrlH, @@ -113,18 +91,8 @@ enum Keys { TwiceRight }; -#define HGC_Cursor 0x0B0C -#define CGA_Cursor 0x0607 -#define OFF_Cursor 0x2000 - -//#define TimerCount (*((volatile long *) ((void _seg *) 0x40 + (void *) 0x6C))) -//#define BreakFlag (*((volatile uint8 *) ((void _seg *) 0x40 + (void *) 0x71))) -//#define PostFlag (*((volatile uint16 *) ((void _seg *) 0x40 + (void *) 0x72))) -//#define POST ((void (*)(void)) ((void _seg *) 0xF000 + (void *) 0xFFF0)) - - -extern uint16 _stklen; -extern uint16 _heaplen; +//extern uint16 _stklen; +//extern uint16 _heaplen; } // End of namespace CGE diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 6b56217a1e8..26969e70315 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -191,7 +191,7 @@ public: uint8 _takePtr; int _seqPtr; int _shpCnt; - char _file[MAXFILE]; + char _file[kMaxFile]; Sprite *_prev; Sprite *_next; From dc28d9debbd3abb1da176bc6ab0ba596bcbda520 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 19 Jul 2011 08:42:58 +0200 Subject: [PATCH 155/276] CGE: rename constants in bitmap --- engines/cge/bitmap.cpp | 41 ++++++++++++++++++++--------------------- engines/cge/bitmap.h | 10 +++++----- engines/cge/jbw.h | 3 --- engines/cge/talk.cpp | 10 +++++----- engines/cge/vga13h.h | 1 + engines/cge/vmenu.cpp | 2 +- 6 files changed, 32 insertions(+), 35 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 29fc4fd8d61..9d898506da8 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -38,7 +38,6 @@ namespace CGE { Dac *Bitmap::_pal = NULL; -#define MAXPATH 128 void Bitmap::init() { _pal = NULL; @@ -51,7 +50,7 @@ void Bitmap::deinit() { Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { debugC(1, kDebugBitmap, "Bitmap::Bitmap(%s, %s)", fname, rem ? "true" : "false"); - char pat[MAXPATH]; + char pat[kMaxPath]; forceExt(pat, fname, ".VBM"); #if (BMP_MODE < 2) @@ -107,16 +106,16 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) if (v == NULL) error("No core"); - *(uint16 *) v = CPY | dsiz; // data chunk hader + *(uint16 *) v = kBmpCPY | dsiz; // data chunk hader memset(v + 2, fill, dsiz); // data bytes - *(uint16 *)(v + lsiz - 2) = SKP | ((SCR_WID / 4) - dsiz); // gap + *(uint16 *)(v + lsiz - 2) = kBmpSKP | ((SCR_WID / 4) - dsiz); // gap // Replicate lines byte *destP; for (destP = v + lsiz; destP < (v + psiz); destP += lsiz) Common::copy(v, v + lsiz, destP); - *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 + *(uint16 *)(v + psiz - 2) = kBmpEOI; // plane trailer uint16 // Repliccate planes for (destP = v + psiz; destP < (v + 4 * psiz); destP += psiz) @@ -224,7 +223,7 @@ BMP_PTR Bitmap::code() { } for (bpl = 0; bpl < 4; bpl++) { // once per each bitplane uint8 *bm = _m; - bool skip = (bm[bpl] == TRANS); + bool skip = (bm[bpl] == kPixelTransp); uint16 j; cnt = 0; @@ -232,21 +231,21 @@ BMP_PTR Bitmap::code() { uint8 pix; for (j = bpl; j < _w; j += 4) { pix = bm[j]; - if (_v && pix != TRANS) { + if (_v && pix != kPixelTransp) { if (j < _b[i]._skip) _b[i]._skip = j; if (j >= _b[i]._hide) _b[i]._hide = j + 1; } - if ((pix == TRANS) != skip || cnt >= 0x3FF0) { // end of block - cnt |= (skip) ? SKP : CPY; + if ((pix == kPixelTransp) != skip || cnt >= 0x3FF0) { // end of block + cnt |= (skip) ? kBmpSKP : kBmpCPY; if (_v) *cp = cnt; // store block description uint16 cp = (uint16 *) im; im += 2; - skip = (pix == TRANS); + skip = (pix == kPixelTransp); cnt = 0; } if (! skip) { @@ -262,7 +261,7 @@ BMP_PTR Bitmap::code() { if (skip) { cnt += (SCR_WID - j + 3) / 4; } else { - cnt |= CPY; + cnt |= kBmpCPY; if (_v) *cp = cnt; @@ -274,7 +273,7 @@ BMP_PTR Bitmap::code() { } } if (cnt && ! skip) { - cnt |= CPY; + cnt |= kBmpCPY; if (_v) *cp = cnt; @@ -282,7 +281,7 @@ BMP_PTR Bitmap::code() { im += 2; } if (_v) - *cp = EOI; + *cp = kBmpEOI; cp = (uint16 *) im; im += 2; } @@ -336,12 +335,12 @@ bool Bitmap::solidAt(int16 x, int16 y) { w &= 0x3FFF; switch (t) { - case EOI : + case kBmpEOI: r--; - case SKP : + case kBmpSKP: w = 0; break; - case REP : + case kBmpREP: w = 1; break; } @@ -361,18 +360,18 @@ bool Bitmap::solidAt(int16 x, int16 y) { n += w; switch (t) { - case EOI : + case kBmpEOI: return false; - case SKP : + case kBmpSKP: w = 0; break; - case REP : - case CPY : + case kBmpREP: + case kBmpCPY: if (n - w <= n0 && n > n0) return true; break; } - m += ((t == REP) ? 1 : w); + m += ((t == kBmpREP) ? 1 : w); } } diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 2728e273030..6b931573f8d 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -32,12 +32,12 @@ namespace CGE { -#define EOI 0x0000 -#define SKP 0x4000 -#define REP 0x8000 -#define CPY 0xC000 +#define kBmpEOI 0x0000 +#define kBmpSKP 0x4000 +#define kBmpREP 0x8000 +#define kBmpCPY 0xC000 -#define TRANS 0xFE +#define kMaxPath 128 #include "common/pack-start.h" diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index d555c82c5a5..4540c1d8e5b 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -91,9 +91,6 @@ enum Keys { TwiceRight }; -//extern uint16 _stklen; -//extern uint16 _heaplen; - } // End of namespace CGE #endif diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index c00e7f3a88d..a164a69f998 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -210,10 +210,10 @@ Bitmap *Talk::box(uint16 w, uint16 h) { for (int i = 0; i < r; i++) { int j; for (j = 0; j < r - i; j++) { - p[j] = TRANS; - p[w - j - 1] = TRANS; - q[j] = TRANS; - q[w - j - 1] = TRANS; + p[j] = kPixelTransp; + p[w - j - 1] = kPixelTransp; + q[j] = kPixelTransp; + q[w - j - 1] = kPixelTransp; } p[j] = LGRAY; p[w - j - 1] = DGRAY; @@ -305,7 +305,7 @@ void InfoLine::update(const char *tx) { for (pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz) { Common::copy(v, v + lsiz, pDest); } - *(uint16 *)(v + psiz - 2) = EOI; // plane trailer uint16 + *(uint16 *)(v + psiz - 2) = kBmpEOI; // plane trailer uint16 for (pDest = v + psiz; pDest < (v + 4 * psiz); pDest += psiz) { Common::copy(v, v + psiz, pDest); } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 26969e70315..13bfce4189b 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -62,6 +62,7 @@ namespace CGE { #define DGRAY 225 /*219*/ #define GRAY 231 #define LGRAY 237 +#define kPixelTransp 0xFE #define NO_SEQ (-1) #define NO_PTR ((uint8)-1) diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index c65ec6957ec..af3d5ff4f5a 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -36,7 +36,7 @@ MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { int i = (w += 2 * kMenuBarHM) * h; uint8 *p = (uint8 *) malloc(sizeof(uint8) * i); - memset(p + w, TRANS, i - 2 * w); + memset(p + w, kPixelTransp, i - 2 * w); memset(p, kMenuBarLT, w); memset(p + i - w, kMenuBarRB, w); uint8 *p1 = p; From 32890064585c75bb796417fa87170ebf611897fe Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 19 Jul 2011 13:24:09 +0200 Subject: [PATCH 156/276] CGE: Rename constants in btfile and cfile --- engines/cge/btfile.cpp | 20 ++++++++++---------- engines/cge/btfile.h | 22 +++++++++++----------- engines/cge/cfile.cpp | 20 ++++++++++---------- engines/cge/cfile.h | 7 ++----- engines/cge/cge_main.cpp | 2 +- engines/cge/vol.cpp | 4 ++-- 6 files changed, 36 insertions(+), 39 deletions(-) diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 68d3fe40e3a..8e4e8a756f6 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -38,9 +38,9 @@ BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt) : IoHand(name, mode, crpt) { debugC(1, kDebugFile, "BtFile::BtFile(%s, %d, crpt)", name, mode); - for (int i = 0; i < BT_LEVELS; i++) { + for (int i = 0; i < kBtLevel; i++) { _buff[i]._page = new BtPage; - _buff[i]._pgNo = BT_NONE; + _buff[i]._pgNo = kBtValNone; _buff[i]._indx = -1; _buff[i]._updt = false; if (_buff[i]._page == NULL) @@ -51,7 +51,7 @@ BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt) BtFile::~BtFile() { debugC(1, kDebugFile, "BtFile::~BtFile()"); - for (int i = 0; i < BT_LEVELS; i++) { + for (int i = 0; i < kBtLevel; i++) { putPage(i, false); delete _buff[i]._page; } @@ -82,7 +82,7 @@ BtPage *BtFile::getPage(int lev, uint16 pgn) { _buff[lev]._updt = false; } else { _buff[lev]._page->_hea._count = 0; - _buff[lev]._page->_hea._down = BT_NONE; + _buff[lev]._page->_hea._down = kBtValNone; memset(_buff[lev]._page->_data, '\0', sizeof(_buff[lev]._page->_data)); _buff[lev]._updt = true; } @@ -95,15 +95,15 @@ BtKeypack *BtFile::find(const char *key) { debugC(1, kDebugFile, "BtFile::find(%s)", key); int lev = 0; - uint16 nxt = BT_ROOT; + uint16 nxt = kBtValRoot; while (!_error) { BtPage *pg = getPage(lev, nxt); // search - if (pg->_hea._down != BT_NONE) { + if (pg->_hea._down != kBtValNone) { int i; for (i = 0; i < pg->_hea._count; i++) { // Does this work, or does it have to compare the entire buffer? - if (scumm_strnicmp((const char *)key, (const char*)pg->_inn[i]._key, BT_KEYLEN) < 0) + if (scumm_strnicmp((const char *)key, (const char*)pg->_inn[i]._key, kBtKeySize) < 0) break; } nxt = (i) ? pg->_inn[i - 1]._down : pg->_hea._down; @@ -124,14 +124,14 @@ BtKeypack *BtFile::find(const char *key) { int keycomp(const void *k1, const void *k2) { - return scumm_strnicmp((const char *) k1, (const char*) k2, BT_KEYLEN); + return scumm_strnicmp((const char *) k1, (const char*) k2, kBtKeySize); } void BtFile::make(BtKeypack *keypack, uint16 count) { debugC(1, kDebugFile, "BtFile::make(keypack, %d)", count); -#if BT_LEVELS != 2 +#if kBtLevel != 2 #error This tiny BTREE implementation works with exactly 2 levels! #endif _fqsort(keypack, count, sizeof(*keypack), keycomp); @@ -144,7 +144,7 @@ void BtFile::make(BtKeypack *keypack, uint16 count) { if (Leaf->_hea._count >= ArrayCount(Leaf->_lea)) { putPage(1, true); // save filled page Leaf = getPage(1, ++n); // take empty page - memcpy(Root->_inn[Root->_hea._count]._key, keypack->_key, BT_KEYLEN); + memcpy(Root->_inn[Root->_hea._count]._key, keypack->_key, kBtKeySize); Root->_inn[Root->_hea._count++]._down = n; _buff[0]._updt = true; } diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 1f3d7217ce0..4784ffd6ed2 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -32,23 +32,23 @@ namespace CGE { -#define BT_SIZE 1024 -#define BT_KEYLEN 13 -#define BT_LEVELS 2 +#define kBtSize 1024 +#define kBtKeySize 13 +#define kBtLevel 2 -#define BT_NONE 0xFFFF -#define BT_ROOT 0 +#define kBtValNone 0xFFFF +#define kBtValRoot 0 #include "common/pack-start.h" // START STRUCT PACKING struct BtKeypack { - char _key[BT_KEYLEN]; + char _key[kBtKeySize]; uint32 _mark; uint16 _size; }; struct Inner { - uint8 _key[BT_KEYLEN]; + uint8 _key[kBtKeySize]; uint16 _down; }; @@ -61,11 +61,11 @@ struct BtPage { Hea _hea; union { // dummy filler to make proper size of union - uint8 _data[BT_SIZE - sizeof(Hea)]; + uint8 _data[kBtSize - sizeof(Hea)]; // inner version of data: key + word-sized page link - Inner _inn[(BT_SIZE - sizeof(Hea)) / sizeof(Inner)]; + Inner _inn[(kBtSize - sizeof(Hea)) / sizeof(Inner)]; // leaf version of data: key + all user data - BtKeypack _lea[(BT_SIZE - sizeof(Hea)) / sizeof(BtKeypack)]; + BtKeypack _lea[(kBtSize - sizeof(Hea)) / sizeof(BtKeypack)]; }; }; @@ -78,7 +78,7 @@ class BtFile : public IoHand { uint16 _pgNo; int _indx; bool _updt; - } _buff[BT_LEVELS]; + } _buff[kBtLevel]; void putPage(int lev, bool hard); BtPage *getPage(int lev, uint16 pgn); diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 5cbf078610b..1486b789024 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -40,7 +40,7 @@ IoBuf::IoBuf(IOMODE mode, CRYPT *crpt) _lim(0) { debugC(1, kDebugFile, "IoBuf::IoBuf(%d, crpt)", mode); - _buff = (uint8 *) malloc(sizeof(uint8) * IOBUF_SIZE); + _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); if (_buff == NULL) error("No core for I/O"); } @@ -53,7 +53,7 @@ IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt) _lim(0) { debugC(1, kDebugFile, "IoBuf::IoBuf(%s, %d, crpt)", name, mode); - _buff = (uint8 *) malloc(sizeof(uint8) * IOBUF_SIZE); + _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); if (_buff == NULL) error("No core for I/O [%s]", name); } @@ -71,7 +71,7 @@ void IoBuf::readBuf() { debugC(4, kDebugFile, "IoBuf::readBuf()"); _bufMark = IoHand::mark(); - _lim = IoHand::read(_buff, IOBUF_SIZE); + _lim = IoHand::read(_buff, kBufferSize); _ptr = 0; } @@ -115,14 +115,14 @@ uint16 IoBuf::read(uint8 *buf) { uint16 total = 0; - while (total < LINE_MAX - 2) { + while (total < kLineMaxSize - 2) { if (_ptr >= _lim) readBuf(); uint8 *p = _buff + _ptr; uint16 n = _lim - _ptr; if (n) { - if (total + n >= LINE_MAX - 2) - n = LINE_MAX - 2 - total; + if (total + n >= kLineMaxSize - 2) + n = kLineMaxSize - 2 - total; uint8 *eol = (uint8 *) memchr(p, '\r', n); if (eol) n = (uint16)(eol - p); @@ -162,7 +162,7 @@ uint16 IoBuf::write(void *buf, uint16 len) { uint16 tot = 0; while (len) { - uint16 n = IOBUF_SIZE - _lim; + uint16 n = kBufferSize - _lim; if (n > len) n = len; if (n) { @@ -213,13 +213,13 @@ int IoBuf::read() { void IoBuf::write(uint8 b) { debugC(1, kDebugFile, "IoBuf::write(%d)", b); - if (_lim >= IOBUF_SIZE) + if (_lim >= kBufferSize) writeBuf(); _buff[_lim++] = b; } -uint16 CFile::_maxLineLen = LINE_MAX; +uint16 CFile::_maxLineLen = kLineMaxSize; CFile::CFile(const char *name, IOMODE mode, CRYPT *crpt) @@ -280,7 +280,7 @@ void CFile::append(CFile &f) { seek(size()); if (f._error == 0) { while (true) { - if ((_lim = f.IoHand::read(_buff, IOBUF_SIZE)) == IOBUF_SIZE) + if ((_lim = f.IoHand::read(_buff, kBufferSize)) == kBufferSize) writeBuf(); else break; diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index b5bf9da603c..227b0f6a63c 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -32,11 +32,8 @@ namespace CGE { -#define LINE_MAX 512 -#define IOBUF_SIZE 2048 - -#define CFREAD(x) read((uint8 *)(x),sizeof(*(x))) - +#define kLineMaxSize 512 +#define kBufferSize 2048 class IoBuf : public IoHand { protected: diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 3958225583f..a32356e08aa 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -433,7 +433,7 @@ void CGEEngine::loadHeroXY() { INI_FILE cf(progName(".HXY")); memset(_heroXY, 0, sizeof(_heroXY)); if (!cf._error) - cf.CFREAD(&_heroXY); + cf.read((uint8 *)(&_heroXY),sizeof(*(&_heroXY))); } void CGEEngine::loadMapping() { diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index cff735abf58..94ec2fc7ada 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -111,8 +111,8 @@ void VFile::readBuf() { } _bufMark = _dat->_file.mark(); long n = _endMark - _bufMark; - if (n > IOBUF_SIZE) - n = IOBUF_SIZE; + if (n > kBufferSize) + n = kBufferSize; _lim = _dat->_file.read(_buff, (uint16) n); _ptr = 0; } From 420516b45e1822c249775c68f9c61b62aba5de0b Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 20 Jul 2011 14:22:56 +0200 Subject: [PATCH 157/276] CGE: Rename Debug channel constants --- engines/cge/bitmap.cpp | 24 +++++----- engines/cge/btfile.cpp | 12 ++--- engines/cge/cfile.cpp | 32 +++++++------- engines/cge/cge.cpp | 13 +++--- engines/cge/cge.h | 7 ++- engines/cge/cge_main.cpp | 64 +++++++++++++-------------- engines/cge/config.cpp | 2 +- engines/cge/snail.cpp | 96 ++++++++++++++++++++-------------------- engines/cge/text.cpp | 2 +- engines/cge/vga13h.cpp | 6 +-- engines/cge/vol.cpp | 16 +++---- 11 files changed, 136 insertions(+), 138 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 9d898506da8..8f335fed600 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -48,7 +48,7 @@ void Bitmap::deinit() { #pragma argsused Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { - debugC(1, kDebugBitmap, "Bitmap::Bitmap(%s, %s)", fname, rem ? "true" : "false"); + debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(%s, %s)", fname, rem ? "true" : "false"); char pat[kMaxPath]; forceExt(pat, fname, ".VBM"); @@ -82,7 +82,7 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL), _map(0) { - debugC(1, kDebugBitmap, "Bitmap::Bitmap(%d, %d, map)", w, h); + debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(%d, %d, map)", w, h); if (map) code(); } @@ -96,7 +96,7 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) _h(h), _m(NULL), _map(0) { - debugC(1, kDebugBitmap, "Bitmap::Bitmap(%d, %d, %d)", w, h, fill); + debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(%d, %d, %d)", w, h, fill); uint16 dsiz = _w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap @@ -136,7 +136,7 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), _map(0) { - debugC(1, kDebugBitmap, "Bitmap::Bitmap(bmp)"); + debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(bmp)"); uint8 *v0 = bmp._v; if (v0) { uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); @@ -151,7 +151,7 @@ Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), Bitmap::~Bitmap() { - debugC(6, kDebugBitmap, "Bitmap::~Bitmap()"); + debugC(6, kCGEDebugBitmap, "Bitmap::~Bitmap()"); free(_m); delete[] _v; @@ -159,7 +159,7 @@ Bitmap::~Bitmap() { Bitmap &Bitmap::operator = (const Bitmap &bmp) { - debugC(1, kDebugBitmap, "&Bitmap::operator ="); + debugC(1, kCGEDebugBitmap, "&Bitmap::operator ="); uint8 *v0 = bmp._v; _w = bmp._w; @@ -183,7 +183,7 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { uint16 Bitmap::moveVmap(uint8 *buf) { - debugC(1, kDebugBitmap, "Bitmap::moveVmap(buf)"); + debugC(1, kCGEDebugBitmap, "Bitmap::moveVmap(buf)"); if (_v) { uint16 vsiz = (uint8 *)_b - (uint8 *)_v; @@ -198,7 +198,7 @@ uint16 Bitmap::moveVmap(uint8 *buf) { BMP_PTR Bitmap::code() { - debugC(1, kDebugBitmap, "Bitmap::code()"); + debugC(1, kCGEDebugBitmap, "Bitmap::code()"); if (!_m) return false; @@ -314,7 +314,7 @@ BMP_PTR Bitmap::code() { bool Bitmap::solidAt(int16 x, int16 y) { - debugC(6, kDebugBitmap, "Bitmap::solidAt(%d, %d)", x, y); + debugC(6, kCGEDebugBitmap, "Bitmap::solidAt(%d, %d)", x, y); uint8 *m; uint16 r, n, n0; @@ -377,7 +377,7 @@ bool Bitmap::solidAt(int16 x, int16 y) { bool Bitmap::saveVBM(XFile *f) { - debugC(1, kDebugBitmap, "Bitmap::saveVBM(f)"); + debugC(1, kCGEDebugBitmap, "Bitmap::saveVBM(f)"); uint16 p = (_pal != NULL), n = ((uint16)(((uint8 *)_b) - _v)) + _h * sizeof(HideDesc); @@ -405,7 +405,7 @@ bool Bitmap::saveVBM(XFile *f) { bool Bitmap::loadVBM(XFile *f) { - debugC(5, kDebugBitmap, "Bitmap::loadVBM(f)"); + debugC(5, kCGEDebugBitmap, "Bitmap::loadVBM(f)"); uint16 p = 0, n = 0; if (f->_error == 0) @@ -448,7 +448,7 @@ bool Bitmap::loadVBM(XFile *f) { } bool Bitmap::loadBMP(XFile *f) { - debugC(1, kDebugBitmap, "Bitmap::loadBMP(f)"); + debugC(1, kCGEDebugBitmap, "Bitmap::loadBMP(f)"); struct { char BM[2]; diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 8e4e8a756f6..e3d9f729d91 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -36,7 +36,7 @@ namespace CGE { BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt) : IoHand(name, mode, crpt) { - debugC(1, kDebugFile, "BtFile::BtFile(%s, %d, crpt)", name, mode); + debugC(1, kCGEDebugFile, "BtFile::BtFile(%s, %d, crpt)", name, mode); for (int i = 0; i < kBtLevel; i++) { _buff[i]._page = new BtPage; @@ -50,7 +50,7 @@ BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt) BtFile::~BtFile() { - debugC(1, kDebugFile, "BtFile::~BtFile()"); + debugC(1, kCGEDebugFile, "BtFile::~BtFile()"); for (int i = 0; i < kBtLevel; i++) { putPage(i, false); delete _buff[i]._page; @@ -59,7 +59,7 @@ BtFile::~BtFile() { void BtFile::putPage(int lev, bool hard) { - debugC(1, kDebugFile, "BtFile::putPage(%d, %s)", lev, hard ? "true" : "false"); + debugC(1, kCGEDebugFile, "BtFile::putPage(%d, %s)", lev, hard ? "true" : "false"); if (hard || _buff[lev]._updt) { seek(_buff[lev]._pgNo * sizeof(BtPage)); @@ -70,7 +70,7 @@ void BtFile::putPage(int lev, bool hard) { BtPage *BtFile::getPage(int lev, uint16 pgn) { - debugC(1, kDebugFile, "BtFile::getPage(%d, %d)", lev, pgn); + debugC(1, kCGEDebugFile, "BtFile::getPage(%d, %d)", lev, pgn); if (_buff[lev]._pgNo != pgn) { int32 pos = pgn * sizeof(BtPage); @@ -92,7 +92,7 @@ BtPage *BtFile::getPage(int lev, uint16 pgn) { } BtKeypack *BtFile::find(const char *key) { - debugC(1, kDebugFile, "BtFile::find(%s)", key); + debugC(1, kCGEDebugFile, "BtFile::find(%s)", key); int lev = 0; uint16 nxt = kBtValRoot; @@ -129,7 +129,7 @@ int keycomp(const void *k1, const void *k2) { void BtFile::make(BtKeypack *keypack, uint16 count) { - debugC(1, kDebugFile, "BtFile::make(keypack, %d)", count); + debugC(1, kCGEDebugFile, "BtFile::make(keypack, %d)", count); #if kBtLevel != 2 #error This tiny BTREE implementation works with exactly 2 levels! diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 1486b789024..f0eeb30bff3 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -38,7 +38,7 @@ IoBuf::IoBuf(IOMODE mode, CRYPT *crpt) _bufMark(0), _ptr(0), _lim(0) { - debugC(1, kDebugFile, "IoBuf::IoBuf(%d, crpt)", mode); + debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%d, crpt)", mode); _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); if (_buff == NULL) @@ -51,7 +51,7 @@ IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt) _bufMark(0), _ptr(0), _lim(0) { - debugC(1, kDebugFile, "IoBuf::IoBuf(%s, %d, crpt)", name, mode); + debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%s, %d, crpt)", name, mode); _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); if (_buff == NULL) @@ -59,7 +59,7 @@ IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt) } IoBuf::~IoBuf() { - debugC(6, kDebugFile, "IoBuf::~IoBuf()"); + debugC(6, kCGEDebugFile, "IoBuf::~IoBuf()"); if (_mode > REA) writeBuf(); @@ -68,7 +68,7 @@ IoBuf::~IoBuf() { void IoBuf::readBuf() { - debugC(4, kDebugFile, "IoBuf::readBuf()"); + debugC(4, kCGEDebugFile, "IoBuf::readBuf()"); _bufMark = IoHand::mark(); _lim = IoHand::read(_buff, kBufferSize); @@ -77,7 +77,7 @@ void IoBuf::readBuf() { void IoBuf::writeBuf() { - debugC(4, kDebugFile, "IoBuf::writeBuf()"); + debugC(4, kCGEDebugFile, "IoBuf::writeBuf()"); if (_lim) { IoHand::write(_buff, _lim); @@ -88,7 +88,7 @@ void IoBuf::writeBuf() { uint16 IoBuf::read(void *buf, uint16 len) { - debugC(4, kDebugFile, "IoBuf::read(buf, %d)", len); + debugC(4, kCGEDebugFile, "IoBuf::read(buf, %d)", len); uint16 total = 0; while (len) { @@ -111,7 +111,7 @@ uint16 IoBuf::read(void *buf, uint16 len) { uint16 IoBuf::read(uint8 *buf) { - debugC(3, kDebugFile, "IoBuf::read(buf)"); + debugC(3, kCGEDebugFile, "IoBuf::read(buf)"); uint16 total = 0; @@ -158,7 +158,7 @@ uint16 IoBuf::read(uint8 *buf) { uint16 IoBuf::write(void *buf, uint16 len) { - debugC(1, kDebugFile, "IoBuf::write(buf, %d)", len); + debugC(1, kCGEDebugFile, "IoBuf::write(buf, %d)", len); uint16 tot = 0; while (len) { @@ -179,7 +179,7 @@ uint16 IoBuf::write(void *buf, uint16 len) { uint16 IoBuf::write(uint8 *buf) { - debugC(1, kDebugFile, "IoBuf::write(buf)"); + debugC(1, kCGEDebugFile, "IoBuf::write(buf)"); uint16 len = 0; if (buf) { @@ -199,7 +199,7 @@ uint16 IoBuf::write(uint8 *buf) { int IoBuf::read() { - debugC(1, kDebugFile, "IoBuf::read()"); + debugC(1, kCGEDebugFile, "IoBuf::read()"); if (_ptr >= _lim) { readBuf(); @@ -211,7 +211,7 @@ int IoBuf::read() { void IoBuf::write(uint8 b) { - debugC(1, kDebugFile, "IoBuf::write(%d)", b); + debugC(1, kCGEDebugFile, "IoBuf::write(%d)", b); if (_lim >= kBufferSize) writeBuf(); @@ -224,7 +224,7 @@ uint16 CFile::_maxLineLen = kLineMaxSize; CFile::CFile(const char *name, IOMODE mode, CRYPT *crpt) : IoBuf(name, mode, crpt) { - debugC(1, kDebugFile, "CFile::CFile(%s, %d, crpt)", name, mode); + debugC(1, kCGEDebugFile, "CFile::CFile(%s, %d, crpt)", name, mode); } @@ -233,7 +233,7 @@ CFile::~CFile() { void CFile::flush() { - debugC(1, kDebugFile, "CFile::flush()"); + debugC(1, kCGEDebugFile, "CFile::flush()"); if (_mode > REA) writeBuf(); @@ -250,14 +250,14 @@ void CFile::flush() { long CFile::mark() { - debugC(5, kDebugFile, "CFile::mark()"); + debugC(5, kCGEDebugFile, "CFile::mark()"); return _bufMark + ((_mode > REA) ? _lim : _ptr); } long CFile::seek(long pos) { - debugC(1, kDebugFile, "CFile::seek(%ld)", pos); + debugC(1, kCGEDebugFile, "CFile::seek(%ld)", pos); if (pos >= _bufMark && pos < _bufMark + _lim) { ((_mode == REA) ? _ptr : _lim) = (uint16)(pos - _bufMark); @@ -275,7 +275,7 @@ long CFile::seek(long pos) { void CFile::append(CFile &f) { - debugC(1, kDebugFile, "CFile::append(f)"); + debugC(1, kCGEDebugFile, "CFile::append(f)"); seek(size()); if (f._error == 0) { diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 239fc89dfcc..a3478b14f81 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -44,10 +44,9 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) : Engine(syst), _gameDescription(gameDescription), _randomSource("cge") { // Debug/console setup - DebugMan.addDebugChannel(kCGEDebug, "general", "CGE general debug channel"); - DebugMan.addDebugChannel(kDebugBitmap, "bitmap", "CGE Bitmap debug channel"); - DebugMan.addDebugChannel(kDebugFile, "file", "CGE IO debug channel"); - DebugMan.addDebugChannel(kDebugEngine, "engine", "CGE Engine debug channel"); + DebugMan.addDebugChannel(kCGEDebugBitmap, "bitmap", "CGE Bitmap debug channel"); + DebugMan.addDebugChannel(kCGEDebugFile, "file", "CGE IO debug channel"); + DebugMan.addDebugChannel(kCGEDebugEngine, "engine", "CGE Engine debug channel"); _isDemo = _gameDescription->flags & ADGF_DEMO; _startupMode = 1; @@ -59,7 +58,7 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) } void CGEEngine::setup() { - debugC(1, kDebugEngine, "CGEEngine::setup()"); + debugC(1, kCGEDebugEngine, "CGEEngine::setup()"); // Initialise fields _lastFrame = 0; @@ -137,7 +136,7 @@ void CGEEngine::setup() { } CGEEngine::~CGEEngine() { - debugC(1, kDebugEngine, "CGEEngine::~CGEEngine()"); + debugC(1, kCGEDebugEngine, "CGEEngine::~CGEEngine()"); // Call classes with static members to clear them up Talk::deinit(); @@ -175,7 +174,7 @@ CGEEngine::~CGEEngine() { } Common::Error CGEEngine::run() { - debugC(1, kDebugEngine, "CGEEngine::run()"); + debugC(1, kCGEDebugEngine, "CGEEngine::run()"); // Initialize graphics using following: initGraphics(320, 200, false); diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 011e08bb319..5bc97d6eff7 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -44,10 +44,9 @@ class Sprite; // our engine debug channels enum { - kCGEDebug = 1 << 0, - kDebugBitmap = 1 << 1, - kDebugFile = 1 << 2, - kDebugEngine = 1 << 3 + kCGEDebugBitmap = 1 << 0, + kCGEDebugFile = 1 << 1, + kCGEDebugEngine = 1 << 2 }; enum SnList { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index a32356e08aa..4b1b0b695ee 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -104,7 +104,7 @@ Bar _barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; extern Dac _stdPal[58]; void CGEEngine::syncHeader(Common::Serializer &s) { - debugC(1, kDebugEngine, "CGEEngine::syncHeader(s)"); + debugC(1, kCGEDebugEngine, "CGEEngine::syncHeader(s)"); int i; @@ -144,7 +144,7 @@ void CGEEngine::syncHeader(Common::Serializer &s) { } bool CGEEngine::loadGame(int slotNumber, SavegameHeader *header, bool tiny) { - debugC(1, kDebugEngine, "CGEEngine::loadgame(file, %s)", tiny ? "true" : "false"); + debugC(1, kCGEDebugEngine, "CGEEngine::loadgame(file, %s)", tiny ? "true" : "false"); Common::MemoryReadStream *readStream; SavegameHeader saveHeader; @@ -362,7 +362,7 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt } } } - debugC(1, kDebugEngine, "CGEEngine::saveSound()"); + debugC(1, kCGEDebugEngine, "CGEEngine::saveSound()"); } @@ -399,13 +399,13 @@ bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &heade } void CGEEngine::heroCover(int cvr) { - debugC(1, kDebugEngine, "CGEEngine::heroCover(%d)", cvr); + debugC(1, kCGEDebugEngine, "CGEEngine::heroCover(%d)", cvr); SNPOST(SNCOVER, 1, cvr, NULL); } void CGEEngine::trouble(int seq, int txt) { - debugC(1, kDebugEngine, "CGEEngine::trouble(%d, %d)", seq, txt); + debugC(1, kCGEDebugEngine, "CGEEngine::trouble(%d, %d)", seq, txt); _hero->park(); SNPOST(SNWAIT, -1, -1, _hero); @@ -416,19 +416,19 @@ void CGEEngine::trouble(int seq, int txt) { } void CGEEngine::offUse() { - debugC(1, kDebugEngine, "CGEEngine::offUse()"); + debugC(1, kCGEDebugEngine, "CGEEngine::offUse()"); trouble(OFF_USE, OFF_USE_TEXT + new_random(_offUseCount)); } void CGEEngine::tooFar() { - debugC(1, kDebugEngine, "CGEEngine::tooFar()"); + debugC(1, kCGEDebugEngine, "CGEEngine::tooFar()"); trouble(TOO_FAR, TOO_FAR_TEXT); } void CGEEngine::loadHeroXY() { - debugC(1, kDebugEngine, "CGEEngine::loadHeroXY()"); + debugC(1, kCGEDebugEngine, "CGEEngine::loadHeroXY()"); INI_FILE cf(progName(".HXY")); memset(_heroXY, 0, sizeof(_heroXY)); @@ -437,7 +437,7 @@ void CGEEngine::loadHeroXY() { } void CGEEngine::loadMapping() { - debugC(1, kDebugEngine, "CGEEngine::loadMapping()"); + debugC(1, kCGEDebugEngine, "CGEEngine::loadMapping()"); if (_now <= CAVE_MAX) { INI_FILE cf(progName(".TAB")); @@ -480,7 +480,7 @@ void SQUARE::touch(uint16 mask, int x, int y) { void CGEEngine::setMapBrick(int x, int z) { - debugC(1, kDebugEngine, "CGEEngine::setMapBrick(%d, %d)", x, z); + debugC(1, kCGEDebugEngine, "CGEEngine::setMapBrick(%d, %d)", x, z); SQUARE *s = new SQUARE(this); if (s) { @@ -495,14 +495,14 @@ void CGEEngine::setMapBrick(int x, int z) { } void CGEEngine::keyClick() { - debugC(1, kDebugEngine, "CGEEngine::keyClick()"); + debugC(1, kCGEDebugEngine, "CGEEngine::keyClick()"); SNPOST_(SNSOUND, -1, 5, NULL); } void CGEEngine::resetQSwitch() { - debugC(1, kDebugEngine, "CGEEngine::resetQSwitch()"); + debugC(1, kCGEDebugEngine, "CGEEngine::resetQSwitch()"); SNPOST_(SNSEQ, 123, 0, NULL); keyClick(); @@ -510,7 +510,7 @@ void CGEEngine::resetQSwitch() { void CGEEngine::quit() { - debugC(1, kDebugEngine, "CGEEngine::quit()"); + debugC(1, kCGEDebugEngine, "CGEEngine::quit()"); static Choice QuitMenu[] = { { NULL, &CGEEngine::startCountDown }, @@ -534,13 +534,13 @@ void CGEEngine::quit() { void CGEEngine::AltCtrlDel() { - debugC(1, kDebugEngine, "CGEEngine::AltCtrlDel()"); + debugC(1, kCGEDebugEngine, "CGEEngine::AltCtrlDel()"); SNPOST_(SNSAY, -1, A_C_D_TEXT, _hero); } void CGEEngine::miniStep(int stp) { - debugC(1, kDebugEngine, "CGEEngine::miniStep(%d)", stp); + debugC(1, kCGEDebugEngine, "CGEEngine::miniStep(%d)", stp); if (stp < 0) _miniCave->_flags._hide = true; @@ -554,14 +554,14 @@ void CGEEngine::miniStep(int stp) { } void CGEEngine::postMiniStep(int step) { - debugC(6, kDebugEngine, "CGEEngine::postMiniStep(%d)", step); + debugC(6, kCGEDebugEngine, "CGEEngine::postMiniStep(%d)", step); if (_miniCave && step != _recentStep) SNPOST2_(SNEXEC, -1, _recentStep = step, kMiniStep); } void CGEEngine::showBak(int ref) { - debugC(1, kDebugEngine, "CGEEngine::showBack(%d)", ref); + debugC(1, kCGEDebugEngine, "CGEEngine::showBack(%d)", ref); Sprite *spr = _vga->_spareQ->locate(ref); if (spr) { @@ -576,7 +576,7 @@ void CGEEngine::showBak(int ref) { } void CGEEngine::caveUp() { - debugC(1, kDebugEngine, "CGEEngine::caveUp()"); + debugC(1, kCGEDebugEngine, "CGEEngine::caveUp()"); int BakRef = 1000 * _now; if (_music) @@ -640,7 +640,7 @@ void CGEEngine::caveUp() { void CGEEngine::caveDown() { - debugC(1, kDebugEngine, "CGEEngine::caveDown()"); + debugC(1, kCGEDebugEngine, "CGEEngine::caveDown()"); Sprite *spr; if (!_horzLine->_flags._hide) @@ -659,14 +659,14 @@ void CGEEngine::caveDown() { } void CGEEngine::xCave() { - debugC(6, kDebugEngine, "CGEEngine::xCave()"); + debugC(6, kCGEDebugEngine, "CGEEngine::xCave()"); caveDown(); caveUp(); } void CGEEngine::qGame() { - debugC(1, kDebugEngine, "CGEEngine::qGame()"); + debugC(1, kCGEDebugEngine, "CGEEngine::qGame()"); caveDown(); _oldLev = _lev; @@ -681,7 +681,7 @@ void CGEEngine::qGame() { void CGEEngine::switchCave(int cav) { - debugC(1, kDebugEngine, "CGEEngine::switchCave(%d)", cav); + debugC(1, kCGEDebugEngine, "CGEEngine::switchCave(%d)", cav); if (cav != _now) { _heart->_enable = false; @@ -918,7 +918,7 @@ void System::tick() { } void CGEEngine::switchColorMode() { - debugC(1, kDebugEngine, "CGEEngine::switchColorMode()"); + debugC(1, kCGEDebugEngine, "CGEEngine::switchColorMode()"); SNPOST_(SNSEQ, 121, _vga->_mono = !_vga->_mono, NULL); keyClick(); @@ -926,7 +926,7 @@ void CGEEngine::switchColorMode() { } void CGEEngine::switchMusic() { - debugC(1, kDebugEngine, "CGEEngine::switchMusic()"); + debugC(1, kCGEDebugEngine, "CGEEngine::switchMusic()"); if (_keyboard->_key[ALT]) { if (Vmenu::_addr) @@ -950,14 +950,14 @@ void CGEEngine::switchMusic() { } void CGEEngine::startCountDown() { - debugC(1, kDebugEngine, "CGEEngine::startCountDown()"); + debugC(1, kCGEDebugEngine, "CGEEngine::startCountDown()"); //SNPOST(SNSEQ, 123, 0, NULL); switchCave(-1); } void CGEEngine::takeName() { - debugC(1, kDebugEngine, "CGEEngine::takeName()"); + debugC(1, kCGEDebugEngine, "CGEEngine::takeName()"); if (GetText::_ptr) SNPOST_(SNKILL, -1, 0, GetText::_ptr); @@ -975,7 +975,7 @@ void CGEEngine::takeName() { } void CGEEngine::switchMapping() { - debugC(1, kDebugEngine, "CGEEngine::switchMapping()"); + debugC(1, kCGEDebugEngine, "CGEEngine::switchMapping()"); if (_horzLine->_flags._hide) { int i; @@ -996,7 +996,7 @@ void CGEEngine::switchMapping() { } void CGEEngine::killSprite() { - debugC(1, kDebugEngine, "CGEEngine::killSprite()"); + debugC(1, kCGEDebugEngine, "CGEEngine::killSprite()"); _sprite->_flags._kill = true; _sprite->_flags._bDel = true; @@ -1005,7 +1005,7 @@ void CGEEngine::killSprite() { } void CGEEngine::pushSprite() { - debugC(1, kDebugEngine, "CGEEngine::pushSprite()"); + debugC(1, kCGEDebugEngine, "CGEEngine::pushSprite()"); Sprite *spr = _sprite->_prev; if (spr) { @@ -1017,7 +1017,7 @@ void CGEEngine::pushSprite() { } void CGEEngine::pullSprite() { - debugC(1, kDebugEngine, "CGEEngine::pullSprite()"); + debugC(1, kCGEDebugEngine, "CGEEngine::pullSprite()"); bool ok = false; Sprite *spr = _sprite->_next; @@ -1036,13 +1036,13 @@ void CGEEngine::pullSprite() { } void CGEEngine::nextStep() { - debugC(1, kDebugEngine, "CGEEngine::nextStep()"); + debugC(1, kCGEDebugEngine, "CGEEngine::nextStep()"); SNPOST_(SNSTEP, 0, 0, _sprite); } void CGEEngine::saveMapping() { - debugC(1, kDebugEngine, "CGEEngine::saveMapping()"); + debugC(1, kCGEDebugEngine, "CGEEngine::saveMapping()"); IoHand cfTab(progName(".TAB"), UPD); if (!cfTab._error) { diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index b49d2b77ea0..2649afc2411 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -39,7 +39,7 @@ static Choice *_cho; static int _hlp; void CGEEngine::snSelect() { - debugC(1, kDebugEngine, "CGEEngine::snSelect()"); + debugC(1, kCGEDebugEngine, "CGEEngine::snSelect()"); inf(_text->getText(_hlp)); _talk->gotoxy(_talk->_x, kFontHigh / 2); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index b0f56be4764..c4b4b383d06 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -46,7 +46,7 @@ extern Sprite *_pocLight; extern Sprite *_pocket[]; void CGEEngine::snGame(Sprite *spr, int num) { - debugC(1, kDebugEngine, "CGEEngine::snGame(spr, %d)", num); + debugC(1, kCGEDebugEngine, "CGEEngine::snGame(spr, %d)", num); switch (num) { case 1 : { @@ -257,7 +257,7 @@ void CGEEngine::snGame(Sprite *spr, int num) { void CGEEngine::expandSprite(Sprite *spr) { - debugC(5, kDebugEngine, "CGEEngine::expandSprite(spr)"); + debugC(5, kCGEDebugEngine, "CGEEngine::expandSprite(spr)"); if (spr) _vga->_showQ->insert(_vga->_spareQ->remove(spr)); @@ -265,14 +265,14 @@ void CGEEngine::expandSprite(Sprite *spr) { void CGEEngine::contractSprite(Sprite *spr) { - debugC(1, kDebugEngine, "CGEEngine::contractSprite(spr)"); + debugC(1, kCGEDebugEngine, "CGEEngine::contractSprite(spr)"); if (spr) _vga->_spareQ->append(_vga->_showQ->remove(spr)); } int CGEEngine::findPocket(Sprite *spr) { - debugC(1, kDebugEngine, "CGEEngine::findPocket(spr)"); + debugC(1, kCGEDebugEngine, "CGEEngine::findPocket(spr)"); for (int i = 0; i < POCKET_NX; i++) if (_pocket[i] == spr) @@ -282,7 +282,7 @@ int CGEEngine::findPocket(Sprite *spr) { void CGEEngine::selectPocket(int n) { - debugC(1, kDebugEngine, "CGEEngine::selectPocket(%d)", n); + debugC(1, kCGEDebugEngine, "CGEEngine::selectPocket(%d)", n); if (n < 0 || (_pocLight->_seqPtr && _pocPtr == n)) { _pocLight->step(0); @@ -299,7 +299,7 @@ void CGEEngine::selectPocket(int n) { } void CGEEngine::pocFul() { - debugC(1, kDebugEngine, "CGEEngine::pocFul()"); + debugC(1, kCGEDebugEngine, "CGEEngine::pocFul()"); _hero->park(); SNPOST(SNWAIT, -1, -1, _hero); @@ -310,13 +310,13 @@ void CGEEngine::pocFul() { } void CGEEngine::hide1(Sprite *spr) { - debugC(1, kDebugEngine, "CGEEngine::hide1(spr)"); + debugC(1, kCGEDebugEngine, "CGEEngine::hide1(spr)"); SNPOST_(SNGHOST, -1, 0, spr->ghost()); } void CGEEngine::snGhost(Bitmap *bmp) { - debugC(1, kDebugEngine, "CGEEngine::snGhost(bmp)"); + debugC(1, kCGEDebugEngine, "CGEEngine::snGhost(bmp)"); bmp->hide(bmp->_map & 0xFFFF, bmp->_map >> 16); bmp->_m = NULL; @@ -325,7 +325,7 @@ void CGEEngine::snGhost(Bitmap *bmp) { } void CGEEngine::feedSnail(Sprite *spr, SnList snq) { - debugC(1, kDebugEngine, "CGEEngine::feedSnail(spr, snq)"); + debugC(1, kCGEDebugEngine, "CGEEngine::feedSnail(spr, snq)"); if (spr) if (spr->active()) { @@ -473,7 +473,7 @@ void Snail::insCom(SNCOM com, int ref, int val, void *ptr) { } void CGEEngine::snNNext(Sprite *spr, int p) { - debugC(1, kDebugEngine, "CGEEngine::snNNext(spr, %d)", p); + debugC(1, kCGEDebugEngine, "CGEEngine::snNNext(spr, %d)", p); if (spr) if (spr->_nearPtr != NO_PTR) @@ -481,7 +481,7 @@ void CGEEngine::snNNext(Sprite *spr, int p) { } void CGEEngine::snTNext(Sprite *spr, int p) { - debugC(1, kDebugEngine, "CGEEngine::snTNext(spr, %d)", p); + debugC(1, kCGEDebugEngine, "CGEEngine::snTNext(spr, %d)", p); if (spr) if (spr->_takePtr != NO_PTR) @@ -489,7 +489,7 @@ void CGEEngine::snTNext(Sprite *spr, int p) { } void CGEEngine::snRNNext(Sprite *spr, int p) { - debugC(1, kDebugEngine, "CGEEngine::snRNNext(spr, %d)", p); + debugC(1, kCGEDebugEngine, "CGEEngine::snRNNext(spr, %d)", p); if (spr) if (spr->_nearPtr != NO_PTR) @@ -498,7 +498,7 @@ void CGEEngine::snRNNext(Sprite *spr, int p) { void CGEEngine::snRTNext(Sprite *spr, int p) { - debugC(1, kDebugEngine, "CGEEngine::snRTNext(spr, %d)", p); + debugC(1, kCGEDebugEngine, "CGEEngine::snRTNext(spr, %d)", p); if (spr) if (spr->_takePtr != NO_PTR) @@ -506,7 +506,7 @@ void CGEEngine::snRTNext(Sprite *spr, int p) { } void CGEEngine::snZTrim(Sprite *spr) { - debugC(4, kDebugEngine, "CGEEngine::snZTrim(spr)"); + debugC(4, kCGEDebugEngine, "CGEEngine::snZTrim(spr)"); if (spr) if (spr->active()) { @@ -524,7 +524,7 @@ void CGEEngine::snZTrim(Sprite *spr) { } void CGEEngine::snHide(Sprite *spr, int val) { - debugC(1, kDebugEngine, "CGEEngine::snHide(spr, %d)", val); + debugC(1, kCGEDebugEngine, "CGEEngine::snHide(spr, %d)", val); if (spr) { spr->_flags._hide = (val >= 0) ? (val != 0) : (!spr->_flags._hide); @@ -534,21 +534,21 @@ void CGEEngine::snHide(Sprite *spr, int val) { } void CGEEngine::snRmNear(Sprite *spr) { - debugC(1, kDebugEngine, "CGEEngine::snRmNear(spr)"); + debugC(1, kCGEDebugEngine, "CGEEngine::snRmNear(spr)"); if (spr) spr->_nearPtr = NO_PTR; } void CGEEngine::snRmTake(Sprite *spr) { - debugC(1, kDebugEngine, "CGEEngine::snRmTake(spr)"); + debugC(1, kCGEDebugEngine, "CGEEngine::snRmTake(spr)"); if (spr) spr->_takePtr = NO_PTR; } void CGEEngine::snSeq(Sprite *spr, int val) { - debugC(1, kDebugEngine, "CGEEngine::snSeq(spr, %d)", val); + debugC(1, kCGEDebugEngine, "CGEEngine::snSeq(spr, %d)", val); if (spr) { if (spr == _hero && val == 0) @@ -559,14 +559,14 @@ void CGEEngine::snSeq(Sprite *spr, int val) { } void CGEEngine::snRSeq(Sprite *spr, int val) { - debugC(1, kDebugEngine, "CGEEngine::snRSeq(spr, %d)", val); + debugC(1, kCGEDebugEngine, "CGEEngine::snRSeq(spr, %d)", val); if (spr) snSeq(spr, spr->_seqPtr + val); } void CGEEngine::snSend(Sprite *spr, int val) { - debugC(1, kDebugEngine, "CGEEngine::snSend(spr, %d)", val); + debugC(1, kCGEDebugEngine, "CGEEngine::snSend(spr, %d)", val); if (spr) { int was = spr->_cave; @@ -598,7 +598,7 @@ void CGEEngine::snSend(Sprite *spr, int val) { void CGEEngine::snSwap(Sprite *spr, int xref) { - debugC(1, kDebugEngine, "CGEEngine::snSwap(spr, %d)", xref); + debugC(1, kCGEDebugEngine, "CGEEngine::snSwap(spr, %d)", xref); Sprite *xspr = locate(xref); if (spr && xspr) { @@ -635,7 +635,7 @@ void CGEEngine::snSwap(Sprite *spr, int xref) { void CGEEngine::snCover(Sprite *spr, int xref) { - debugC(1, kDebugEngine, "CGEEngine::snCover(spr, %d)", xref); + debugC(1, kCGEDebugEngine, "CGEEngine::snCover(spr, %d)", xref); Sprite *xspr = locate(xref); if (spr && xspr) { @@ -654,7 +654,7 @@ void CGEEngine::snCover(Sprite *spr, int xref) { void CGEEngine::snUncover(Sprite *spr, Sprite *xspr) { - debugC(1, kDebugEngine, "CGEEngine::snUncover(spr, xspr)"); + debugC(1, kCGEDebugEngine, "CGEEngine::snUncover(spr, xspr)"); if (spr && xspr) { spr->_flags._hide = false; @@ -673,33 +673,33 @@ void CGEEngine::snUncover(Sprite *spr, Sprite *xspr) { void CGEEngine::snSetX0(int cav, int x0) { - debugC(1, kDebugEngine, "CGEEngine::snSetX0(%d, %d)", cav, x0); + debugC(1, kCGEDebugEngine, "CGEEngine::snSetX0(%d, %d)", cav, x0); _heroXY[cav - 1]._x = x0; } void CGEEngine::snSetY0(int cav, int y0) { - debugC(1, kDebugEngine, "CGEEngine::snSetY0(%d, %d)", cav, y0); + debugC(1, kCGEDebugEngine, "CGEEngine::snSetY0(%d, %d)", cav, y0); _heroXY[cav - 1]._y = y0; } void CGEEngine::snSetXY(Sprite *spr, uint16 xy) { - debugC(1, kDebugEngine, "CGEEngine::snSetXY(spr, %d)", xy); + debugC(1, kCGEDebugEngine, "CGEEngine::snSetXY(spr, %d)", xy); if (spr) spr->gotoxy(xy % SCR_WID, xy / SCR_WID); } void CGEEngine::snRelX(Sprite *spr, int x) { - debugC(1, kDebugEngine, "CGEEngine::snRelX(spr, %d)", x); + debugC(1, kCGEDebugEngine, "CGEEngine::snRelX(spr, %d)", x); if (spr && _hero) spr->gotoxy(_hero->_x + x, spr->_y); } void CGEEngine::snRelY(Sprite *spr, int y) { - debugC(1, kDebugEngine, "CGEEngine::snRelY(spr, %d)", y); + debugC(1, kCGEDebugEngine, "CGEEngine::snRelY(spr, %d)", y); if (spr && _hero) spr->gotoxy(spr->_x, _hero->_y + y); @@ -707,7 +707,7 @@ void CGEEngine::snRelY(Sprite *spr, int y) { void CGEEngine::snRelZ(Sprite *spr, int z) { - debugC(1, kDebugEngine, "CGEEngine::snRelZ(spr, %d)", z); + debugC(1, kCGEDebugEngine, "CGEEngine::snRelZ(spr, %d)", z); if (spr && _hero) { spr->_z = _hero->_z + z; @@ -717,7 +717,7 @@ void CGEEngine::snRelZ(Sprite *spr, int z) { void CGEEngine::snSetX(Sprite *spr, int x) { - debugC(1, kDebugEngine, "CGEEngine::snSetX(spr, %d)", x); + debugC(1, kCGEDebugEngine, "CGEEngine::snSetX(spr, %d)", x); if (spr) spr->gotoxy(x, spr->_y); @@ -725,7 +725,7 @@ void CGEEngine::snSetX(Sprite *spr, int x) { void CGEEngine::snSetY(Sprite *spr, int y) { - debugC(1, kDebugEngine, "CGEEngine::snSetY(spr, %d)", y); + debugC(1, kCGEDebugEngine, "CGEEngine::snSetY(spr, %d)", y); if (spr) spr->gotoxy(spr->_x, y); @@ -733,7 +733,7 @@ void CGEEngine::snSetY(Sprite *spr, int y) { void CGEEngine::snSetZ(Sprite *spr, int z) { - debugC(1, kDebugEngine, "CGEEngine::snSetZ(spr, %d)", z); + debugC(1, kCGEDebugEngine, "CGEEngine::snSetZ(spr, %d)", z); if (spr) { spr->_z = z; @@ -744,7 +744,7 @@ void CGEEngine::snSetZ(Sprite *spr, int z) { void CGEEngine::snSlave(Sprite *spr, int ref) { - debugC(1, kDebugEngine, "CGEEngine::snSlave(spr, %d)", ref); + debugC(1, kCGEDebugEngine, "CGEEngine::snSlave(spr, %d)", ref); Sprite *slv = locate(ref); if (spr && slv) { @@ -759,21 +759,21 @@ void CGEEngine::snSlave(Sprite *spr, int ref) { void CGEEngine::snTrans(Sprite *spr, int trans) { - debugC(1, kDebugEngine, "CGEEngine::snTrans(spr, %d)", trans); + debugC(1, kCGEDebugEngine, "CGEEngine::snTrans(spr, %d)", trans); if (spr) spr->_flags._tran = (trans < 0) ? !spr->_flags._tran : (trans != 0); } void CGEEngine::snPort(Sprite *spr, int port) { - debugC(1, kDebugEngine, "CGEEngine::snPort(spr, %d)", port); + debugC(1, kCGEDebugEngine, "CGEEngine::snPort(spr, %d)", port); if (spr) spr->_flags._port = (port < 0) ? !spr->_flags._port : (port != 0); } void CGEEngine::snKill(Sprite *spr) { - debugC(1, kDebugEngine, "CGEEngine::snKill(spr)"); + debugC(1, kCGEDebugEngine, "CGEEngine::snKill(spr)"); if (spr) { if (spr->_flags._kept) { @@ -800,7 +800,7 @@ void CGEEngine::snKill(Sprite *spr) { void CGEEngine::snSound(Sprite *spr, int wav, int cnt) { - debugC(1, kDebugEngine, "CGEEngine::snSound(spr, %d, %d)", wav, cnt); + debugC(1, kCGEDebugEngine, "CGEEngine::snSound(spr, %d, %d)", wav, cnt); if (_sndDrvInfo._dDev) { if (wav == -1) @@ -812,7 +812,7 @@ void CGEEngine::snSound(Sprite *spr, int wav, int cnt) { void CGEEngine::snKeep(Sprite *spr, int stp) { - debugC(1, kDebugEngine, "CGEEngine::snKeep(spr, %d)", stp); + debugC(1, kCGEDebugEngine, "CGEEngine::snKeep(spr, %d)", stp); selectPocket(-1); if (spr && ! spr->_flags._kept && _pocket[_pocPtr] == NULL) { @@ -830,7 +830,7 @@ void CGEEngine::snKeep(Sprite *spr, int stp) { void CGEEngine::snGive(Sprite *spr, int stp) { - debugC(1, kDebugEngine, "CGEEngine::snGive(spr, %d)", stp); + debugC(1, kCGEDebugEngine, "CGEEngine::snGive(spr, %d)", stp); if (spr) { int p = findPocket(spr); @@ -847,7 +847,7 @@ void CGEEngine::snGive(Sprite *spr, int stp) { void CGEEngine::snBackPt(Sprite *spr, int stp) { - debugC(1, kDebugEngine, "CGEEngine::snBackPt(spr, %d)", stp); + debugC(1, kCGEDebugEngine, "CGEEngine::snBackPt(spr, %d)", stp); if (spr) { if (stp >= 0) @@ -857,7 +857,7 @@ void CGEEngine::snBackPt(Sprite *spr, int stp) { } void CGEEngine::snLevel(Sprite *spr, int lev) { - debugC(1, kDebugEngine, "CGEEngine::snLevel(spr, %d)", lev); + debugC(1, kCGEDebugEngine, "CGEEngine::snLevel(spr, %d)", lev); while (_lev < lev) { _lev++; @@ -878,14 +878,14 @@ void CGEEngine::snFlag(int indx, bool v) { } void CGEEngine::snSetRef(Sprite *spr, int nr) { - debugC(1, kDebugEngine, "CGEEngine::snSetRef(spr, %d)", nr); + debugC(1, kCGEDebugEngine, "CGEEngine::snSetRef(spr, %d)", nr); if (spr) spr->_ref = nr; } void CGEEngine::snFlash(bool on) { - debugC(1, kDebugEngine, "CGEEngine::snFlash(%s)", on ? "true" : "false"); + debugC(1, kCGEDebugEngine, "CGEEngine::snFlash(%s)", on ? "true" : "false"); if (on) { Dac *pal = (Dac *) malloc(sizeof(Dac) * PAL_CNT); @@ -909,7 +909,7 @@ void CGEEngine::snFlash(bool on) { void CGEEngine::snLight(bool in) { - debugC(1, kDebugEngine, "CGEEngine::snLight(%s)", in ? "true" : "false"); + debugC(1, kCGEDebugEngine, "CGEEngine::snLight(%s)", in ? "true" : "false"); if (in) _vga->sunrise(Vga::_sysPal); @@ -919,13 +919,13 @@ void CGEEngine::snLight(bool in) { } void CGEEngine::snBarrier(int cav, int bar, bool horz) { - debugC(1, kDebugEngine, "CGEEngine::snBarrier(%d, %d, %s)", cav, bar, horz ? "true" : "false"); + debugC(1, kCGEDebugEngine, "CGEEngine::snBarrier(%d, %d, %s)", cav, bar, horz ? "true" : "false"); ((uint8 *)(_barriers + ((cav > 0) ? cav : _now)))[horz] = bar; } void CGEEngine::snWalk(Sprite *spr, int x, int y) { - debugC(1, kDebugEngine, "CGEEngine::snWalk(spr, %d, %d)", x, y); + debugC(1, kCGEDebugEngine, "CGEEngine::snWalk(spr, %d, %d)", x, y); if (_hero) { if (spr && y < 0) @@ -936,14 +936,14 @@ void CGEEngine::snWalk(Sprite *spr, int x, int y) { } void CGEEngine::snReach(Sprite *spr, int mode) { - debugC(1, kDebugEngine, "CGEEngine::snReach(spr, %d)", mode); + debugC(1, kCGEDebugEngine, "CGEEngine::snReach(spr, %d)", mode); if (_hero) _hero->reach(spr, mode); } void CGEEngine::snMouse(bool on) { - debugC(1, kDebugEngine, "CGEEngine::snMouse(%s)", on ? "true" : "false"); + debugC(1, kCGEDebugEngine, "CGEEngine::snMouse(%s)", on ? "true" : "false"); if (on) _mouse->on(); diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index fd37dada8b8..1ed640be8a2 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -218,7 +218,7 @@ void Text::say(const char *txt, Sprite *spr) { } void CGEEngine::inf(const char *txt) { - debugC(1, kDebugEngine, "CGEEngine::inf(%s)", txt); + debugC(1, kCGEDebugEngine, "CGEEngine::inf(%s)", txt); killText(); _talk = new Talk(this, txt, RECT); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 6fc17dc37b9..60936812921 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -1213,7 +1213,7 @@ void Vga::copyPage(uint16 d, uint16 s) { //-------------------------------------------------------------------------- void Bitmap::xShow(int16 x, int16 y) { - debugC(4, kDebugBitmap, "Bitmap::xShow(%d, %d)", x, y); + debugC(4, kCGEDebugBitmap, "Bitmap::xShow(%d, %d)", x, y); const byte *srcP = (const byte *)_v; byte *destEndP = (byte *)Vga::_page[1]->pixels + (SCR_WID * SCR_HIG); @@ -1266,7 +1266,7 @@ void Bitmap::xShow(int16 x, int16 y) { void Bitmap::show(int16 x, int16 y) { - debugC(5, kDebugBitmap, "Bitmap::show(%d, %d)", x, y); + debugC(5, kCGEDebugBitmap, "Bitmap::show(%d, %d)", x, y); const byte *srcP = (const byte *)_v; byte *destEndP = (byte *)Vga::_page[1]->pixels + (SCR_WID * SCR_HIG); @@ -1330,7 +1330,7 @@ void Bitmap::show(int16 x, int16 y) { void Bitmap::hide(int16 x, int16 y) { - debugC(5, kDebugBitmap, "Bitmap::hide(%d, %d)", x, y); + debugC(5, kCGEDebugBitmap, "Bitmap::hide(%d, %d)", x, y); for (int yp = y; yp < y + _h; yp++) { const byte *srcP = (const byte *)Vga::_page[2]->getBasePtr(x, yp); diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 94ec2fc7ada..63f3fadd1c6 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -47,13 +47,13 @@ Dat::Dat(): _file(DAT_NAME, REA, CRP) #endif { - debugC(1, kDebugFile, "Dat::Dat()"); + debugC(1, kCGEDebugFile, "Dat::Dat()"); } /*-----------------------------------------------------------------------*/ void VFile::init() { - debugC(1, kDebugFile, "VFile::init()"); + debugC(1, kCGEDebugFile, "VFile::init()"); _dat = new Dat(); #ifdef VOL_UPD @@ -72,7 +72,7 @@ void VFile::deinit() { VFile::VFile(const char *name, IOMODE mode) : IoBuf(mode) { - debugC(3, kDebugFile, "VFile::VFile(%s, %d)", name, mode); + debugC(3, kCGEDebugFile, "VFile::VFile(%s, %d)", name, mode); if (mode == REA) { if (_dat->_file._error || _cat->_error) @@ -96,14 +96,14 @@ VFile::~VFile() { bool VFile::exist(const char *name) { - debugC(1, kDebugFile, "VFile::exist(%s)", name); + debugC(1, kCGEDebugFile, "VFile::exist(%s)", name); return scumm_stricmp(_cat->find(name)->_key, name) == 0; } void VFile::readBuf() { - debugC(3, kDebugFile, "VFile::readBuf()"); + debugC(3, kCGEDebugFile, "VFile::readBuf()"); if (_recent != this) { _dat->_file.seek(_bufMark + _lim); @@ -118,19 +118,19 @@ void VFile::readBuf() { } long VFile::mark() { - debugC(5, kDebugFile, "VFile::mark()"); + debugC(5, kCGEDebugFile, "VFile::mark()"); return (_bufMark + _ptr) - _begMark; } long VFile::size() { - debugC(1, kDebugFile, "VFile::size()"); + debugC(1, kCGEDebugFile, "VFile::size()"); return _endMark - _begMark; } long VFile::seek(long pos) { - debugC(1, kDebugFile, "VFile::seel(%ld)", pos); + debugC(1, kCGEDebugFile, "VFile::seel(%ld)", pos); _recent = NULL; _lim = 0; From 9576e415e2779011ecfca77a2f9642c011a928a2 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 20 Jul 2011 14:27:36 +0200 Subject: [PATCH 158/276] CGE: Clean up Square class --- engines/cge/cge_main.cpp | 16 +++------------- engines/cge/cge_main.h | 8 +++++++- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 4b1b0b695ee..3ebec730308 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -449,17 +449,7 @@ void CGEEngine::loadMapping() { } } -class SQUARE : public Sprite { -public: - SQUARE(CGEEngine *vm); - virtual void touch(uint16 mask, int x, int y); -private: - CGEEngine *_vm; -}; - - -SQUARE::SQUARE(CGEEngine *vm) - : Sprite(vm, NULL), _vm(vm) { +Square::Square(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { _flags._kill = true; _flags._bDel = false; @@ -470,7 +460,7 @@ SQUARE::SQUARE(CGEEngine *vm) } -void SQUARE::touch(uint16 mask, int x, int y) { +void Square::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); if (mask & L_UP) { XZ(_x + x, _y + y).cell() = 0; @@ -482,7 +472,7 @@ void SQUARE::touch(uint16 mask, int x, int y) { void CGEEngine::setMapBrick(int x, int z) { debugC(1, kCGEDebugEngine, "CGEEngine::setMapBrick(%d, %d)", x, z); - SQUARE *s = new SQUARE(this); + Square *s = new Square(this); if (s) { static char n[] = "00:00"; s->gotoxy(x * MAP_XGRID, MAP_TOP + z * MAP_ZGRID); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 40e6d886685..103c718759b 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -103,7 +103,6 @@ namespace CGE { #define HEROFUN0 (40 * 12) #define HEROFUN1 ( 2 * 12) #define PAIN (_vm->_flag[0]) -//#define FINIS (_vm->_flag[3]) class System : public Sprite { @@ -121,6 +120,13 @@ private: CGEEngine *_vm; }; +class Square : public Sprite { +public: + Square(CGEEngine *vm); + virtual void touch(uint16 mask, int x, int y); +private: + CGEEngine *_vm; +}; extern Vga *_vga; extern Heart *_heart; From 5d41ab8b5fd778f206633157ffa87efc31f643cf Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 21 Jul 2011 01:56:40 +0200 Subject: [PATCH 159/276] CGE: Rename some more constants, remove some useless ones --- engines/cge/bitmap.cpp | 17 ++++---- engines/cge/cge.cpp | 10 ++--- engines/cge/cge.h | 18 +++++--- engines/cge/cge_main.cpp | 54 +++++++++++------------ engines/cge/cge_main.h | 94 ++++++++++++++++++---------------------- engines/cge/config.cpp | 2 +- engines/cge/events.cpp | 2 +- engines/cge/snail.cpp | 20 ++++----- engines/cge/snail.h | 9 ---- engines/cge/startup.cpp | 2 +- engines/cge/talk.h | 4 +- engines/cge/text.cpp | 6 +-- engines/cge/text.h | 2 +- engines/cge/vga13h.cpp | 24 +++++----- engines/cge/vga13h.h | 9 ---- engines/cge/walk.cpp | 14 +++--- engines/cge/walk.h | 2 +- 17 files changed, 133 insertions(+), 156 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 8f335fed600..023e95a8f1d 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -31,6 +31,7 @@ #include "cge/vol.h" #include "cge/cfile.h" #include "cge/vga13h.h" +#include "cge/cge_main.h" #include "common/system.h" #include "common/debug.h" #include "common/debug-channels.h" @@ -108,7 +109,7 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) *(uint16 *) v = kBmpCPY | dsiz; // data chunk hader memset(v + 2, fill, dsiz); // data bytes - *(uint16 *)(v + lsiz - 2) = kBmpSKP | ((SCR_WID / 4) - dsiz); // gap + *(uint16 *)(v + lsiz - 2) = kBmpSKP | ((kScrWidth / 4) - dsiz); // gap // Replicate lines byte *destP; @@ -122,7 +123,7 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) Common::copy(v, v + psiz, destP); HideDesc *b = (HideDesc *)(v + 4 * psiz); - b->_skip = (SCR_WID - _w) >> 2; + b->_skip = (kScrWidth - _w) >> 2; b->_hide = _w >> 2; // Replicate across the entire table @@ -257,9 +258,9 @@ BMP_PTR Bitmap::code() { } bm += _w; - if (_w < SCR_WID) { + if (_w < kScrWidth) { if (skip) { - cnt += (SCR_WID - j + 3) / 4; + cnt += (kScrWidth - j + 3) / 4; } else { cnt |= kBmpCPY; if (_v) @@ -268,7 +269,7 @@ BMP_PTR Bitmap::code() { cp = (uint16 *) im; im += 2; skip = true; - cnt = (SCR_WID - j + 3) / 4; + cnt = (kScrWidth - j + 3) / 4; } } } @@ -298,14 +299,14 @@ BMP_PTR Bitmap::code() { cnt = 0; for (i = 0; i < _h; i++) { if (_b[i]._skip == 0xFFFF) { // whole line is skipped - _b[i]._skip = (cnt + SCR_WID) >> 2; + _b[i]._skip = (cnt + kScrWidth) >> 2; cnt = 0; } else { uint16 s = _b[i]._skip & ~3; uint16 h = (_b[i]._hide + 3) & ~3; _b[i]._skip = (cnt + s) >> 2; _b[i]._hide = (h - s) >> 2; - cnt = SCR_WID - h; + cnt = kScrWidth - h; } } @@ -324,7 +325,7 @@ bool Bitmap::solidAt(int16 x, int16 y) { m = _v; r = static_cast(x) % 4; - n0 = (SCR_WID * y + x) / 4, n = 0; + n0 = (kScrWidth * y + x) / 4, n = 0; while (r) { uint16 w, t; diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index a3478b14f81..58c32dd5759 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -85,15 +85,15 @@ void CGEEngine::setup() { _heart = new Heart; _sys = new System(this); _pocLight = new PocLight(this); - for (int i = 0; i < POCKET_NX; i++) { + for (int i = 0; i < kPocketNX; i++) { _pocket[i] = new Sprite(this, NULL); _pocket[i]->_flags._kill = false; } _sprite = new Sprite(this, NULL); _horzLine = new HorizLine(this); - _infoLine = new InfoLine(this, INFO_W); + _infoLine = new InfoLine(this, kInfoW); _cavLight = new CavLight(this); - _debugLine = new InfoLine(this, SCR_WID); + _debugLine = new InfoLine(this, kScrWidth); _snail = new Snail(this, false); _snail_ = new Snail(this, true); @@ -104,7 +104,7 @@ void CGEEngine::setup() { _music = true; _mini = new byte[MINI_EMM_SIZE]; - for (int i = 0; i < POCKET_NX; i++) + for (int i = 0; i < kPocketNX; i++) _pocref[i] = -1; _volume[0] = 0; _volume[1] = 0; @@ -165,7 +165,7 @@ CGEEngine::~CGEEngine() { delete _pocLight; delete _keyboard; delete _mouse; - for (int i = 0; i < POCKET_NX; i++) + for (int i = 0; i < kPocketNX; i++) delete _pocket[i]; delete _snail; delete _snail_; diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 5bc97d6eff7..255dadfac6b 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -35,13 +35,21 @@ #include "cge/console.h" #include "cge/bitmap.h" -#define CGE_SAVEGAME_VERSION 1 - namespace CGE { class Console; class Sprite; +#define CGE_SAVEGAME_VERSION 1 +#define kPocketX 174 +#define kPocketY 176 +#define kPocketDX 18 +#define kPocketDY 22 +#define kPocketNX 8 +#define kPocketNY 1 +#define kPocketSX 8 +#define kPocketSY 3 + // our engine debug channels enum { kCGEDebugBitmap = 1 << 0, @@ -58,10 +66,6 @@ enum CallbackType { kSnSelect, kSndSetVolume }; -#define POCKET_NX 8 - -#define CGE_SAVEGAME_VERSION 1 - struct SavegameHeader { uint8 version; Common::String saveName; @@ -100,7 +104,7 @@ public: bool _jbw; int _pocPtr; bool _music; - int _pocref[POCKET_NX]; + int _pocref[kPocketNX]; uint8 _volume[2]; int _maxCaveArr[5]; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 3ebec730308..22e38618cb7 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -57,7 +57,7 @@ namespace CGE { #define STACK_SIZ 2048 #define SVGCHKSUM (1956 + _now + _oldLev + _game + _music + _demoText) -#define SVG0NAME ("{{INIT}}" SVG_EXT) +#define SVG0NAME ("{{INIT}}" kSvgExt) #define SVG0FILE INI_FILE uint16 _stklen = (STACK_SIZ * 2); @@ -69,7 +69,7 @@ Sprite *_pocLight; EventManager *_eventManager; Keyboard *_keyboard; Mouse *_mouse; -Sprite *_pocket[POCKET_NX]; +Sprite *_pocket[kPocketNX]; Sprite *_sprite; Sprite *_miniCave; Sprite *_shadow; @@ -127,7 +127,7 @@ void CGEEngine::syncHeader(Common::Serializer &s) { s.syncAsByte(_barriers[i]._horz); s.syncAsByte(_barriers[i]._vert); } - for (i = 0; i < POCKET_NX; ++i) + for (i = 0; i < kPocketNX; ++i) s.syncAsUint16LE(_pocref[i]); if (s.isSaving()) { @@ -291,7 +291,7 @@ void CGEEngine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &he // Create a thumbnail and save it Graphics::Surface *thumb = new Graphics::Surface(); Graphics::Surface *s = _vga->_page[0]; - ::createThumbnail(thumb, (const byte *)s->pixels, SCR_WID, SCR_HIG, thumbPalette); + ::createThumbnail(thumb, (const byte *)s->pixels, kScrWidth, kScrHeight, thumbPalette); Graphics::saveThumbnail(*out, *thumb); delete thumb; @@ -312,7 +312,7 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt Common::Serializer s(readStream, writeStream); if (s.isSaving()) { - for (i = 0; i < POCKET_NX; i++) { + for (i = 0; i < kPocketNX; i++) { register Sprite *s = _pocket[i]; _pocref[i] = (s) ? s->_ref : -1; } @@ -355,7 +355,7 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt _vga->_spareQ->append(spr); } - for (i = 0; i < POCKET_NX; i++) { + for (i = 0; i < kPocketNX; i++) { register int r = _pocref[i]; delete _pocket[i]; _pocket[i] = (r < 0) ? NULL : _vga->_spareQ->locate(r); @@ -701,7 +701,7 @@ void CGEEngine::switchCave(int cav) { } System::System(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { - _funDel = HEROFUN0; + _funDel = kHeroFun0; setPal(); tick(); } @@ -717,7 +717,7 @@ void System::setPal() { } void System::funTouch() { - uint16 n = (PAIN) ? HEROFUN1 : HEROFUN0; + uint16 n = (PAIN) ? kHeroFun1 : kHeroFun0; if (_talk == NULL || n > _funDel) _funDel = n; } @@ -836,8 +836,8 @@ void System::touch(uint16 mask, int x, int y) { return; int cav = 0; _infoLine->update(NULL); - if (y >= WORLD_HIG) { - if (x < BUTTON_X) { // select cave? + if (y >= kWorldHeight ) { + if (x < kButtonX) { // select cave? if (y >= CAVE_Y && y < CAVE_Y + CAVE_NY * CAVE_DY && x >= CAVE_X && x < CAVE_X + CAVE_NX * CAVE_DX && !_vm->_game) { cav = ((y - CAVE_Y) / CAVE_DY) * CAVE_NX + (x - CAVE_X) / CAVE_DX + 1; @@ -847,9 +847,9 @@ void System::touch(uint16 mask, int x, int y) { cav = 0; } } else if (mask & L_UP) { - if (y >= POCKET_Y && y < POCKET_Y + POCKET_NY * POCKET_DY && - x >= POCKET_X && x < POCKET_X + POCKET_NX * POCKET_DX) { - int n = ((y - POCKET_Y) / POCKET_DY) * POCKET_NX + (x - POCKET_X) / POCKET_DX; + if (y >= kPocketY && y < kPocketY + kPocketNY * kPocketDY && + x >= kPocketX && x < kPocketX + kPocketNX * kPocketDX) { + int n = ((y - kPocketY) / kPocketDY) * kPocketNX + (x - kPocketX) / kPocketDX; _vm->selectPocket(n); } } @@ -889,7 +889,7 @@ void System::tick() { else if (Startup::_core >= CORE_MID) { int n = new_random(100); if (n > 96) - _vm->heroCover(6 + (_hero->_x + _hero->_w / 2 < SCR_WID / 2)); + _vm->heroCover(6 + (_hero->_x + _hero->_w / 2 < kScrWidth / 2)); else { if (n > 90) _vm->heroCover(5); @@ -904,7 +904,7 @@ void System::tick() { } funTouch(); } - _time = SYSTIMERATE; + _time = kSystemRate; } void CGEEngine::switchColorMode() { @@ -1106,7 +1106,7 @@ void CGEEngine::optionTouch(int opt, uint16 mask) { else if (mask & R_UP) if (!Mixer::_appear) { Mixer::_appear = true; - new Mixer(this, BUTTON_X, BUTTON_Y); + new Mixer(this, kButtonX, kButtonY); } break; case 3 : @@ -1137,7 +1137,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if ((mask & R_UP) && _snail->idle()) { Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_vm->_pocPtr] : NULL; if (ps) { - if (_flags._kept || _hero->distance(this) < MAX_DISTANCE) { + if (_flags._kept || _hero->distance(this) < kDistMax) { if (works(ps)) { _vm->feedSnail(ps, kTake); } else @@ -1149,7 +1149,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if (_flags._kept) mask |= L_UP; else { - if (_hero->distance(this) < MAX_DISTANCE) { + if (_hero->distance(this) < kDistMax) { /// if (_flags._port) { if (_vm->findPocket(NULL) < 0) @@ -1177,7 +1177,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if ((mask & L_UP) && _snail->idle()) { if (_flags._kept) { int n; - for (n = 0; n < POCKET_NX; n++) { + for (n = 0; n < kPocketNX; n++) { if (_pocket[n] == this) { _vm->selectPocket(n); break; @@ -1200,7 +1200,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int static const char *Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS", "FLY", NULL }; - char line[LINE_MAX]; + char line[kLineMax]; int shpcnt = 0; int type = 0; // DEAD @@ -1345,7 +1345,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int void CGEEngine::loadScript(const char *fname) { - char line[LINE_MAX]; + char line[kLineMax]; char *SpN; int SpI, SpA, SpX, SpY, SpZ; bool BkG = false; @@ -1483,7 +1483,7 @@ void CGEEngine::loadUser() { error("Creating setup savegames not supported"); } } - loadScript(progName(IN0_EXT)); + loadScript(progName(kIn0Ext)); } @@ -1538,7 +1538,7 @@ void CGEEngine::runGame() { uint8 *ptr = (uint8 *) &*_mini; if (ptr != NULL) { - loadSprite("MINI", -1, 0, MINI_X, MINI_Y); + loadSprite("MINI", -1, 0, kMiniX, kMiniY); expandSprite(_miniCave = _sprite); // NULL is ok if (_miniCave) { _miniCave->_flags._kill = false; @@ -1567,7 +1567,7 @@ void CGEEngine::runGame() { } } - _infoLine->gotoxy(INFO_X, INFO_Y); + _infoLine->gotoxy(kInfoX, kInfoY); _infoLine->_flags._tran = true; _infoLine->update(NULL); _vga->_showQ->insert(_infoLine); @@ -1579,7 +1579,7 @@ void CGEEngine::runGame() { _horzLine->_z = 126; _vga->_showQ->insert(_horzLine); - _mouse->_busy = _vga->_spareQ->locate(BUSY_REF); + _mouse->_busy = _vga->_spareQ->locate(kBusyRef); if (_mouse->_busy) expandSprite(_mouse->_busy); @@ -1688,7 +1688,7 @@ bool CGEEngine::showTitle(const char *name) { if (Startup::_mode < 2) { if (_isDemo) { - strcpy(_usrFnam, progName(SVG_EXT)); + strcpy(_usrFnam, progName(kSvgExt)); usr_ok = true; } else { //----------------------------------------- @@ -1792,7 +1792,7 @@ void CGEEngine::cge_main() { movie("X03"); } else { if (Startup::_mode < 2) - movie(LGO_EXT); + movie(kLgoExt); if (showTitle("WELCOME")) { if ((!_isDemo) && (Startup::_mode == 1)) diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 103c718759b..68c6f1f1dc9 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -33,34 +33,6 @@ #include "cge/events.h" namespace CGE { - -#define TSEQ 96 -#define HTALK (TSEQ + 4) -#define TOO_FAR (TSEQ + 5) -#define NO_WAY (TSEQ + 5) -#define POC_FUL (TSEQ + 5) -#define OFF_USE (TSEQ + 6) -#define EXIT_OK_TEXT 40 -#define NOMUSIC_TEXT 98 -#define BADSVG_TEXT 99 -#define OFF_USE_COUNT 600 -#define OFF_USE_TEXT 601 -#define NO_WAY_TEXT 671 -#define TOO_FAR_TEXT 681 -#define POC_FUL_TEXT 691 -#define A_C_D_TEXT 777 -#define GETNAME_PROMPT 50 -#define GETNAME_TITLE 51 -#define QUIT_TITLE 200 -#define QUIT_TEXT 201 -#define NOQUIT_TEXT 202 -#define DEMO_TEXT 300 -#define NOSOUND_TEXT 310 -#define PAN_HIG 40 -#define WORLD_HIG (SCR_HIG - PAN_HIG) -#define INFO_X 177 -#define INFO_Y 164 -#define INFO_W 140 #define CAVE_X 4 #define CAVE_Y 166 #define CAVE_SX 0 @@ -77,33 +49,51 @@ namespace CGE { #define CAVE_NX 8 #define CAVE_NY 3 #endif - -#define BUTTON_X 151 -#define BUTTON_Y 164 -#define BUTTON_DX 19 -#define BUTTON_DY 11 -#define BUTTON_NX 1 -#define BUTTON_NY 3 -#define MINI_X 86 -#define MINI_Y 162 -#define LINE_MAX 512 -#define USER_MAX 100 -#define SHP_MAX 1024 -#define STD_DELAY 3 -#define LEV_MAX 5 #define CAVE_MAX (CAVE_NX * CAVE_NY) -#define MAX_DISTANCE 3 -#define INI_EXT ".INI" -#define IN0_EXT ".IN0" -#define LGO_EXT ".LGO" -#define SVG_EXT ".SVG" -#define WALKSIDE 10 -#define BUSY_REF 500 -#define SYSTIMERATE 6 // 12 Hz -#define HEROFUN0 (40 * 12) -#define HEROFUN1 ( 2 * 12) #define PAIN (_vm->_flag[0]) +#define kInfoX 177 +#define kInfoY 164 +#define kInfoW 140 +#define kButtonX 151 +#define kButtonY 164 +#define kMiniX 86 +#define kMiniY 162 +#define kLineMax 512 +#define kDistMax 3 +#define kIn0Ext ".IN0" +#define kLgoExt ".LGO" +#define kSvgExt ".SVG" +#define kWalkSide 10 +#define kBusyRef 500 +#define kSystemRate 6 // 12 Hz +#define kHeroFun0 (40 * 12) +#define kHeroFun1 ( 2 * 12) +#define GETNAME_PROMPT 50 +#define GETNAME_TITLE 51 +#define TSEQ 96 +#define NOMUSIC_TEXT 98 +#define BADSVG_TEXT 99 +#define HTALK (TSEQ + 4) +#define TOO_FAR (TSEQ + 5) +#define NO_WAY (TSEQ + 5) +#define POC_FUL (TSEQ + 5) +#define OFF_USE (TSEQ + 6) +#define QUIT_TITLE 200 +#define QUIT_TEXT 201 +#define NOQUIT_TEXT 202 +#define DEMO_TEXT 300 +#define NOSOUND_TEXT 310 +#define OFF_USE_COUNT 600 +#define OFF_USE_TEXT 601 +#define NO_WAY_TEXT 671 +#define TOO_FAR_TEXT 681 +#define POC_FUL_TEXT 691 +#define A_C_D_TEXT 777 +#define kPanHeight 40 +#define kScrWidth 320 +#define kScrHeight 200 +#define kWorldHeight (kScrHeight - kPanHeight) class System : public Sprite { int _lum; diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 2649afc2411..964b029b592 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -43,7 +43,7 @@ void CGEEngine::snSelect() { inf(_text->getText(_hlp)); _talk->gotoxy(_talk->_x, kFontHigh / 2); - (new Vmenu(this, _cho, SCR_WID / 2, _talk->_y + _talk->_h + kTextVMargin + kFontHigh))->setName(_text->getText(MENU_TEXT)); + (new Vmenu(this, _cho, kScrWidth / 2, _talk->_y + _talk->_h + kTextVMargin + kFontHigh))->setName(_text->getText(MENU_TEXT)); } } // End of namespace CGE diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index eba043cdc8e..aa71782f779 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -169,7 +169,7 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) MC[2] = NULL; setShapeList(MC); - gotoxy(SCR_WID/2, SCR_HIG/2); + gotoxy(kScrWidth/2, kScrHeight/2); _z = 127; step(1); } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index c4b4b383d06..e9ae494811a 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -107,11 +107,11 @@ void CGEEngine::snGame(Sprite *spr, int num) { SNPOST(SNPAUSE, -1, 72, NULL); // chwilk‘... SNPOST(SNSEQ, -1, 0, dup[1]); // odstaw Go - SNPOST(SNSETXY, -1, 203 + SCR_WID * 49, dup[1]); + SNPOST(SNSETXY, -1, 203 + kScrWidth * 49, dup[1]); SNPOST(SNSETZ, -1, 7, dup[1]); SNPOST(SNSEQ, -1, 0, dup[2]); // odstaw J† - SNPOST(SNSETXY, -1, 182 + SCR_WID * 62, dup[2]); + SNPOST(SNSETXY, -1, 182 + kScrWidth * 62, dup[2]); SNPOST(SNSETZ, -1, 9, dup[2]); _game = 0; return; @@ -274,7 +274,7 @@ void CGEEngine::contractSprite(Sprite *spr) { int CGEEngine::findPocket(Sprite *spr) { debugC(1, kCGEDebugEngine, "CGEEngine::findPocket(spr)"); - for (int i = 0; i < POCKET_NX; i++) + for (int i = 0; i < kPocketNX; i++) if (_pocket[i] == spr) return i; return -1; @@ -295,7 +295,7 @@ void CGEEngine::selectPocket(int n) { _pocLight->step(1); } } - _pocLight->gotoxy(POCKET_X + _pocPtr * POCKET_DX + POCKET_SX, POCKET_Y + POCKET_SY); + _pocLight->gotoxy(kPocketX + _pocPtr * kPocketDX + kPocketSX, kPocketY + kPocketSY); } void CGEEngine::pocFul() { @@ -688,7 +688,7 @@ void CGEEngine::snSetXY(Sprite *spr, uint16 xy) { debugC(1, kCGEDebugEngine, "CGEEngine::snSetXY(spr, %d)", xy); if (spr) - spr->gotoxy(xy % SCR_WID, xy / SCR_WID); + spr->gotoxy(xy % kScrWidth, xy / kScrWidth); } void CGEEngine::snRelX(Sprite *spr, int x) { @@ -806,7 +806,7 @@ void CGEEngine::snSound(Sprite *spr, int wav, int cnt) { if (wav == -1) _sound.stop(); else - _sound.play(_fx[wav], (spr) ? ((spr->_x + spr->_w / 2) / (SCR_WID / 16)) : 8, cnt); + _sound.play(_fx[wav], (spr) ? ((spr->_x + spr->_w / 2) / (kScrWidth / 16)) : 8, cnt); } } @@ -820,8 +820,8 @@ void CGEEngine::snKeep(Sprite *spr, int stp) { _pocket[_pocPtr] = spr; spr->_cave = 0; spr->_flags._kept = true; - spr->gotoxy(POCKET_X + POCKET_DX * _pocPtr + POCKET_DX / 2 - spr->_w / 2, - POCKET_Y + POCKET_DY / 2 - spr->_h / 2); + spr->gotoxy(kPocketX + kPocketDX * _pocPtr + kPocketDX / 2 - spr->_w / 2, + kPocketY + kPocketDY / 2 - spr->_h / 2); if (stp >= 0) spr->step(stp); } @@ -1008,13 +1008,13 @@ void Snail::runCom() { if (spr == _hero && spr->seqTest(-1)) spr->step(HTALK); _text->say(_text->getText(snc->_val), spr); - _sys->_funDel = HEROFUN0; + _sys->_funDel = kHeroFun0; } break; case SNINF : if (_talkEnable) { _vm->inf(_text->getText(snc->_val)); - _sys->_funDel = HEROFUN0; + _sys->_funDel = kHeroFun0; } break; case SNTIME : diff --git a/engines/cge/snail.h b/engines/cge/snail.h index e8578e2b3d5..b8b4dc68ffe 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -33,15 +33,6 @@ namespace CGE { -#define POCKET_X 174 -#define POCKET_Y 176 -#define POCKET_DX 18 -#define POCKET_DY 22 -#define POCKET_NY 1 - -#define POCKET_SX 8 -#define POCKET_SY 3 - #define SNINSERT(c, r, v, p) _snail->insCom(c, r, v, p) #define SNPOST(c, r, v, p) _snail->addCom(c, r, v, p) #define SNPOST2(c, r, v, p) _snail->addCom2(c, r, v, p) diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 37c6b4f62ec..aca58a91ba3 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -157,7 +157,7 @@ Startup::Startup() { const char *usrPath(const char *nam) { - static char buf[MAXPATH] = ".\\", *p = buf + 2; + static char buf[kPathMax] = ".\\", *p = buf + 2; #if defined(CD) if (DriveCD(0)) { bool ok = false; diff --git a/engines/cge/talk.h b/engines/cge/talk.h index e8136271f6a..5eab6672e36 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -49,10 +49,10 @@ namespace CGE { -#define MAXPATH 128 +#define kPathMax 128 class Font { - char _path[MAXPATH]; + char _path[kPathMax]; void load(); public: // static uint8 _wid[256]; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 1ed640be8a2..dd75ea3681b 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -86,7 +86,7 @@ void Text::preload(int from, int upto) { INI_FILE tf = _fileName; if (!tf._error) { Han *CacheLim = _cache + _size; - char line[LINE_MAX + 1]; + char line[kLineMax + 1]; int n; while ((n = tf.read((uint8 *)line)) != 0) { @@ -128,7 +128,7 @@ char *Text::load(int idx, int ref) { INI_FILE tf = _fileName; if (!tf._error) { Han *p = &_cache[idx]; - char line[LINE_MAX + 1]; + char line[kLineMax + 1]; int n; while ((n = tf.read((uint8 *)line)) != 0) { @@ -187,7 +187,7 @@ void Text::say(const char *txt, Sprite *spr) { uint16 sw = spike->_w; if (east) { - if (x + sw + kTextRoundCorner + 5 >= SCR_WID) + if (x + sw + kTextRoundCorner + 5 >= kScrWidth) east = false; } else { if (x <= 5 + kTextRoundCorner + sw) diff --git a/engines/cge/text.h b/engines/cge/text.h index cf917ece618..196bfc4edb8 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -57,7 +57,7 @@ class Text { char *_txt; } *_cache; int _size; - char _fileName[MAXPATH]; + char _fileName[kPathMax]; char *load(int idx, int ref); int find(int ref); public: diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 60936812921..24c83f12ee1 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -508,7 +508,7 @@ Sprite *Sprite::expand() { error("No core"); if (*_file) { static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; - char line[LINE_MAX], fname[MAXPATH]; + char line[kLineMax], fname[kPathMax]; BMP_PTR *shplist = new BMP_PTR[_shpCnt + 1]; Seq *seq = NULL; int shpcnt = 0, @@ -713,18 +713,18 @@ void Sprite::killXlat() { void Sprite::gotoxy(int x, int y) { int xo = _x, yo = _y; - if (_x < SCR_WID) { + if (_x < kScrWidth) { if (x < 0) x = 0; - if (x + _w > SCR_WID) - x = (SCR_WID - _w); + if (x + _w > kScrWidth) + x = (kScrWidth - _w); _x = x; } - if (_h < SCR_HIG) { + if (_h < kScrHeight) { if (y < 0) y = 0; - if (y + _h > SCR_HIG) - y = (SCR_HIG - _h); + if (y + _h > kScrHeight) + y = (kScrHeight - _h); _y = y; } if (_next) @@ -736,7 +736,7 @@ void Sprite::gotoxy(int x, int y) { void Sprite::center() { - gotoxy((SCR_WID - _w) / 2, (SCR_HIG - _h) / 2); + gotoxy((kScrWidth - _w) / 2, (kScrHeight - _h) / 2); } @@ -1195,14 +1195,14 @@ void Vga::update() { _setPal = false; } - g_system->copyRectToScreen((const byte *)Vga::_page[0]->getBasePtr(0, 0), SCR_WID, 0, 0, SCR_WID, SCR_HIG); + g_system->copyRectToScreen((const byte *)Vga::_page[0]->getBasePtr(0, 0), kScrWidth, 0, 0, kScrWidth, kScrHeight); g_system->updateScreen(); } void Vga::clear(uint8 color) { for (int paneNum = 0; paneNum < 4; ++paneNum) - _page[paneNum]->fillRect(Common::Rect(0, 0, SCR_WID, SCR_HIG), color); + _page[paneNum]->fillRect(Common::Rect(0, 0, kScrWidth, kScrHeight), color); } @@ -1216,7 +1216,7 @@ void Bitmap::xShow(int16 x, int16 y) { debugC(4, kCGEDebugBitmap, "Bitmap::xShow(%d, %d)", x, y); const byte *srcP = (const byte *)_v; - byte *destEndP = (byte *)Vga::_page[1]->pixels + (SCR_WID * SCR_HIG); + byte *destEndP = (byte *)Vga::_page[1]->pixels + (kScrWidth * kScrHeight); byte *lookupTable = _m; // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a @@ -1269,7 +1269,7 @@ void Bitmap::show(int16 x, int16 y) { debugC(5, kCGEDebugBitmap, "Bitmap::show(%d, %d)", x, y); const byte *srcP = (const byte *)_v; - byte *destEndP = (byte *)Vga::_page[1]->pixels + (SCR_WID * SCR_HIG); + byte *destEndP = (byte *)Vga::_page[1]->pixels + (kScrWidth * kScrHeight); // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 13bfce4189b..4884ae104e7 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -48,15 +48,6 @@ namespace CGE { #define TEXT_MODE 0x03 #define M13H 0x13 -#ifndef SCR_WID -#define SCR_WID 320 -#endif - -#ifndef SCR_HIG -#define SCR_HIG 200 -#endif - - #define LIGHT 0xFF #define DARK 207 #define DGRAY 225 /*219*/ diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index b35864f16ed..f07ed4ece26 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -130,8 +130,8 @@ void WALK::tick() { } step(); if ((Dir == WW && _x <= 0) || - (Dir == EE && _x + _w >= SCR_WID) || - (Dir == SS && _y + _w >= WORLD_HIG - 2)) + (Dir == EE && _x + _w >= kScrWidth) || + (Dir == SS && _y + _w >= kWorldHeight - 2)) park(); else { signed char x; // dummy var @@ -143,9 +143,9 @@ void WALK::tick() { int WALK::distance(Sprite *spr) { int dx, dz; - dx = spr->_x - (_x + _w - WALKSIDE); + dx = spr->_x - (_x + _w - kWalkSide); if (dx < 0) - dx = (_x + WALKSIDE) - (spr->_x + spr->_w); + dx = (_x + kWalkSide) - (spr->_x + spr->_w); if (dx < 0) dx = 0; @@ -208,11 +208,11 @@ void WALK::findWay(Sprite *spr) { int x = spr->_x; int z = spr->_z; if (spr->_flags._east) - x += spr->_w + _w / 2 - WALKSIDE; + x += spr->_w + _w / 2 - kWalkSide; else - x -= _w / 2 - WALKSIDE; + x -= _w / 2 - kWalkSide; findWay(Cluster((x / MAP_XGRID), - ((z < MAP_ZCNT - MAX_DISTANCE) ? (z + 1) + ((z < MAP_ZCNT - kDistMax) ? (z + 1) : (z - 1)))); } } diff --git a/engines/cge/walk.h b/engines/cge/walk.h index eb29d9b4625..52f372c363a 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -38,7 +38,7 @@ namespace CGE { #define MAP_ZCNT 20 #define MAP_TOP 80 #define MAP_HIG 80 -#define MAP_XGRID (SCR_WID / MAP_XCNT) +#define MAP_XGRID (kScrWidth / MAP_XCNT) #define MAP_ZGRID (MAP_HIG / MAP_ZCNT) #define MAX_FIND_LEVEL 3 From 3ef0558aa933ce20242b3f842c235f792a6d2d32 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 22 Jul 2011 11:54:46 +0200 Subject: [PATCH 160/276] CGE: Rename some more constants, some cleanup --- engines/cge/cge.cpp | 4 ++-- engines/cge/cge_main.cpp | 34 ++++++++++++++++----------------- engines/cge/cge_main.h | 41 ++++++++++++++++++++-------------------- engines/cge/config.cpp | 4 +--- engines/cge/config.h | 1 + engines/cge/ems.cpp | 4 ---- engines/cge/game.cpp | 19 ------------------- engines/cge/game.h | 8 -------- engines/cge/snail.cpp | 8 ++++---- engines/cge/walk.cpp | 4 ++-- 10 files changed, 47 insertions(+), 80 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 58c32dd5759..6068dee46e7 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -50,7 +50,7 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) _isDemo = _gameDescription->flags & ADGF_DEMO; _startupMode = 1; - _demoText = DEMO_TEXT; + _demoText = kDemo; _oldLev = 0; _jbw = false; _pocPtr = 0; @@ -100,7 +100,7 @@ void CGEEngine::setup() { _mouse = new Mouse(this); _keyboard = new Keyboard(); _eventManager = new EventManager(); - _offUseCount = atoi(_text->getText(OFF_USE_COUNT)); + _offUseCount = atoi(_text->getText(kOffUseCount)); _music = true; _mini = new byte[MINI_EMM_SIZE]; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 22e38618cb7..ee561726a16 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -139,7 +139,7 @@ void CGEEngine::syncHeader(Common::Serializer &s) { uint16 checksum; s.syncAsUint16LE(checksum); if (checksum != SVGCHKSUM) - error("%s", _text->getText(BADSVG_TEXT)); + error("%s", _text->getText(kBadSVG)); } } @@ -418,13 +418,13 @@ void CGEEngine::trouble(int seq, int txt) { void CGEEngine::offUse() { debugC(1, kCGEDebugEngine, "CGEEngine::offUse()"); - trouble(OFF_USE, OFF_USE_TEXT + new_random(_offUseCount)); + trouble(kSeqOffUse, kOffUse + new_random(_offUseCount)); } void CGEEngine::tooFar() { debugC(1, kCGEDebugEngine, "CGEEngine::tooFar()"); - trouble(TOO_FAR, TOO_FAR_TEXT); + trouble(kSeqTooFar, kTooFar); } void CGEEngine::loadHeroXY() { @@ -513,9 +513,9 @@ void CGEEngine::quit() { SNPOST_(SNKILL, -1, 0, Vmenu::_addr); resetQSwitch(); } else { - QuitMenu[0]._text = _text->getText(QUIT_TEXT); - QuitMenu[1]._text = _text->getText(NOQUIT_TEXT); - (new Vmenu(this, QuitMenu, -1, -1))->setName(_text->getText(QUIT_TITLE)); + QuitMenu[0]._text = _text->getText(kQuit); + QuitMenu[1]._text = _text->getText(kNoQuit); + (new Vmenu(this, QuitMenu, -1, -1))->setName(_text->getText(kQuitTitle)); SNPOST_(SNSEQ, 123, 1, NULL); keyClick(); } @@ -526,7 +526,7 @@ void CGEEngine::quit() { void CGEEngine::AltCtrlDel() { debugC(1, kCGEDebugEngine, "CGEEngine::AltCtrlDel()"); - SNPOST_(SNSAY, -1, A_C_D_TEXT, _hero); + SNPOST_(SNSAY, -1, kAltCtrlDel, _hero); } void CGEEngine::miniStep(int stp) { @@ -771,22 +771,22 @@ void System::touch(uint16 mask, int x, int y) { _vm->switchDebug(); break; case F3: - _hero->step(TSEQ + 4); + _hero->step(kTSeq + 4); break; case F4: - _hero->step(TSEQ + 5); + _hero->step(kTSeq + 5); break; case F5: - _hero->step(TSEQ + 0); + _hero->step(kTSeq + 0); break; case F6: - _hero->step(TSEQ + 1); + _hero->step(kTSeq + 1); break; case F7: - _hero->step(TSEQ + 2); + _hero->step(kTSeq + 2); break; case F8: - _hero->step(TSEQ + 3); + _hero->step(kTSeq + 3); break; case F9: _sys->_funDel = 1; @@ -927,7 +927,7 @@ void CGEEngine::switchMusic() { } } else { if (Startup::_core < CORE_HIG) - SNPOST(SNINF, -1, NOMUSIC_TEXT, NULL); + SNPOST(SNINF, -1, kNoMusic, NULL); else { SNPOST_(SNSEQ, 122, (_music = !_music), NULL); keyClick(); @@ -953,9 +953,9 @@ void CGEEngine::takeName() { SNPOST_(SNKILL, -1, 0, GetText::_ptr); else { memset(_usrFnam, 0, 15); - GetText *tn = new GetText(this, _text->getText(GETNAME_PROMPT), _usrFnam, 8); + GetText *tn = new GetText(this, _text->getText(kGetNamePrompt), _usrFnam, 8); if (tn) { - tn->setName(_text->getText(GETNAME_TITLE)); + tn->setName(_text->getText(kGetNameTitle)); tn->center(); tn->gotoxy(tn->_x, tn->_y - 10); tn->_z = 126; @@ -1417,7 +1417,7 @@ void CGEEngine::mainLoop() { SNPOST(SNINF, -1, _demoText, NULL); SNPOST(SNLABEL, -1, -1, NULL); if (_text->getText(++_demoText) == NULL) - _demoText = DEMO_TEXT + 1; + _demoText = kDemo + 1; } //FIXME: tc = TimerCount; } diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 68c6f1f1dc9..2a467761b31 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -69,27 +69,26 @@ namespace CGE { #define kSystemRate 6 // 12 Hz #define kHeroFun0 (40 * 12) #define kHeroFun1 ( 2 * 12) -#define GETNAME_PROMPT 50 -#define GETNAME_TITLE 51 -#define TSEQ 96 -#define NOMUSIC_TEXT 98 -#define BADSVG_TEXT 99 -#define HTALK (TSEQ + 4) -#define TOO_FAR (TSEQ + 5) -#define NO_WAY (TSEQ + 5) -#define POC_FUL (TSEQ + 5) -#define OFF_USE (TSEQ + 6) -#define QUIT_TITLE 200 -#define QUIT_TEXT 201 -#define NOQUIT_TEXT 202 -#define DEMO_TEXT 300 -#define NOSOUND_TEXT 310 -#define OFF_USE_COUNT 600 -#define OFF_USE_TEXT 601 -#define NO_WAY_TEXT 671 -#define TOO_FAR_TEXT 681 -#define POC_FUL_TEXT 691 -#define A_C_D_TEXT 777 +#define kGetNamePrompt 50 +#define kGetNameTitle 51 +#define kTSeq 96 +#define kNoMusic 98 +#define kBadSVG 99 +#define kSeqHTalk (kTSeq + 4) +#define kSeqTooFar (kTSeq + 5) +#define kSeqNoWay (kTSeq + 5) +#define kSeqPocketFull (kTSeq + 5) +#define kSeqOffUse (kTSeq + 6) +#define kQuitTitle 200 +#define kQuit 201 +#define kNoQuit 202 +#define kDemo 300 +#define kOffUseCount 600 +#define kOffUse 601 +#define kNoWay 671 +#define kTooFar 681 +#define kPocketFull 691 +#define kAltCtrlDel 777 #define kPanHeight 40 #define kScrWidth 320 #define kScrHeight 200 diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp index 964b029b592..b1cc5769d8d 100644 --- a/engines/cge/config.cpp +++ b/engines/cge/config.cpp @@ -33,8 +33,6 @@ namespace CGE { -#define MENU_TEXT 56 - static Choice *_cho; static int _hlp; @@ -43,7 +41,7 @@ void CGEEngine::snSelect() { inf(_text->getText(_hlp)); _talk->gotoxy(_talk->_x, kFontHigh / 2); - (new Vmenu(this, _cho, kScrWidth / 2, _talk->_y + _talk->_h + kTextVMargin + kFontHigh))->setName(_text->getText(MENU_TEXT)); + (new Vmenu(this, _cho, kScrWidth / 2, _talk->_y + _talk->_h + kTextVMargin + kFontHigh))->setName(_text->getText(kMenu)); } } // End of namespace CGE diff --git a/engines/cge/config.h b/engines/cge/config.h index d7191a281db..5ea677b97d6 100644 --- a/engines/cge/config.h +++ b/engines/cge/config.h @@ -29,6 +29,7 @@ #define __CGE_CONFIG__ namespace CGE { + #define kMenu 56 } // End of namespace CGE #endif diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp index 93342f77da1..0364758a123 100644 --- a/engines/cge/ems.cpp +++ b/engines/cge/ems.cpp @@ -29,10 +29,6 @@ namespace CGE { -#define EMS_INT 0x67 -#define PAGE_MASK 0x3FFF -#define SIZ(n) ((n) ? ((long)n) : (0x10000L)) - enum EMM_FUN { GET_STATUS = 0x40, GET_FRAME, GET_SIZE, OPEN_HANDLE, MAP_PAGE, diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 18c4efbe009..41075806919 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -43,36 +43,17 @@ uint8 *glass(Dac *pal, uint8 r, uint8 g, uint8 b) { return x; } -/* Useless? -uint8 *Mark(DAC *pal) { -#define f(c) (c ^ 63) - uint8 *x = new uint8[256]; - if (x) { - uint16 i; - for (i = 0; i < 256; i++) { - x[i] = closest(pal, mkDax(f(pal[i]._R), - f(pal[i]._G), - f(pal[i]._B))); - } - } - return x; -#undef f -} -*/ - int Fly::_l = 20, Fly::_t = 40, Fly::_r = 110, Fly::_b = 100; - Fly::Fly(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), _tx(0), _ty(0), _vm(vm) { step(new_random(2)); gotoxy(_l + new_random(_r - _l - _w), _t + new_random(_b - _t - _h)); } - void Fly::tick() { step(); if (!_flags._kept) { diff --git a/engines/cge/game.h b/engines/cge/game.h index c442d815774..078f3880ead 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -33,15 +33,7 @@ namespace CGE { -//#define PAN_HIG 40 -//#define LBound(s) (s->X <= 0) -//#define RBound(s) (s->X+s->W >= SCR_WID) -//#define TBound(s) (s->Y <= 0) -//#define BBound(s) (s->Y+s->H >= SCR_HIG - PAN_HIG) - -//int sinus(long x); uint8 *glass(Dac *pal, uint8 r, uint8 g, uint8 b); -//uint8 *mark(DAC *pal); class Fly : public Sprite { static int _l; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index e9ae494811a..e694cab0b90 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -303,10 +303,10 @@ void CGEEngine::pocFul() { _hero->park(); SNPOST(SNWAIT, -1, -1, _hero); - SNPOST(SNSEQ, -1, POC_FUL, _hero); + SNPOST(SNSEQ, -1, kSeqPocketFull, _hero); SNPOST(SNSOUND, -1, 2, _hero); SNPOST(SNWAIT, -1, -1, _hero); - SNPOST(SNSAY, 1, POC_FUL_TEXT, _hero); + SNPOST(SNSAY, 1, kPocketFull, _hero); } void CGEEngine::hide1(Sprite *spr) { @@ -1006,7 +1006,7 @@ void Snail::runCom() { case SNSAY : if (spr && _talkEnable) { if (spr == _hero && spr->seqTest(-1)) - spr->step(HTALK); + spr->step(kSeqHTalk); _text->say(_text->getText(snc->_val), spr); _sys->_funDel = kHeroFun0; } @@ -1020,7 +1020,7 @@ void Snail::runCom() { case SNTIME : if (spr && _talkEnable) { if (spr == _hero && spr->seqTest(-1)) - spr->step(HTALK); + spr->step(kSeqHTalk); sayTime(spr); } break; diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index f07ed4ece26..2568a51df0c 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -234,7 +234,7 @@ void WALK::reach(Sprite *spr, int mode) { } // note: insert SNAIL commands in reverse order SNINSERT(SNPAUSE, -1, 64, NULL); - SNINSERT(SNSEQ, -1, TSEQ + mode, this); + SNINSERT(SNSEQ, -1, kTSeq + mode, this); if (spr) { SNINSERT(SNWAIT, -1, -1, _hero); /////--------$$$$$$$ //SNINSERT(SNWALK, -1, -1, spr); @@ -244,7 +244,7 @@ void WALK::reach(Sprite *spr, int mode) { } void WALK::noWay() { - _vm->trouble(NO_WAY, NO_WAY_TEXT); + _vm->trouble(kSeqNoWay, kNoWay); } bool WALK::find1Way(Cluster c) { From c728a53148d436cfebb33d58a75f3146980a39e0 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 23 Jul 2011 14:31:39 +0200 Subject: [PATCH 161/276] CGE: Rename IOMode and SnCom enums --- engines/cge/btfile.cpp | 2 +- engines/cge/btfile.h | 2 +- engines/cge/cfile.cpp | 16 +- engines/cge/cfile.h | 6 +- engines/cge/cge_main.cpp | 96 +++++----- engines/cge/general.cpp | 15 +- engines/cge/general.h | 18 +- engines/cge/gettext.cpp | 10 +- engines/cge/gettext.h | 8 +- engines/cge/mixer.cpp | 32 ++-- engines/cge/mixer.h | 14 +- engines/cge/snail.cpp | 373 +++++++++++++++++++-------------------- engines/cge/snail.h | 48 +++-- engines/cge/text.cpp | 3 +- engines/cge/vga13h.cpp | 6 +- engines/cge/vmenu.cpp | 2 +- engines/cge/vol.cpp | 8 +- engines/cge/vol.h | 2 +- engines/cge/walk.cpp | 8 +- 19 files changed, 325 insertions(+), 344 deletions(-) diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index e3d9f729d91..d5cdef1ba0f 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -34,7 +34,7 @@ namespace CGE { -BtFile::BtFile(const char *name, IOMODE mode, CRYPT *crpt) +BtFile::BtFile(const char *name, IOMode mode, CRYPT *crpt) : IoHand(name, mode, crpt) { debugC(1, kCGEDebugFile, "BtFile::BtFile(%s, %d, crpt)", name, mode); diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 4784ffd6ed2..b589e86aee0 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -83,7 +83,7 @@ class BtFile : public IoHand { void putPage(int lev, bool hard); BtPage *getPage(int lev, uint16 pgn); public: - BtFile(const char *name, IOMODE mode, CRYPT *crpt); + BtFile(const char *name, IOMode mode, CRYPT *crpt); virtual ~BtFile(); BtKeypack *find(const char *key); BtKeypack *next(); diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index f0eeb30bff3..1c5cf1d3588 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -33,7 +33,7 @@ namespace CGE { -IoBuf::IoBuf(IOMODE mode, CRYPT *crpt) +IoBuf::IoBuf(IOMode mode, CRYPT *crpt) : IoHand(mode, crpt), _bufMark(0), _ptr(0), @@ -46,7 +46,7 @@ IoBuf::IoBuf(IOMODE mode, CRYPT *crpt) } -IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt) +IoBuf::IoBuf(const char *name, IOMode mode, CRYPT *crpt) : IoHand(name, mode, crpt), _bufMark(0), _ptr(0), @@ -61,7 +61,7 @@ IoBuf::IoBuf(const char *name, IOMODE mode, CRYPT *crpt) IoBuf::~IoBuf() { debugC(6, kCGEDebugFile, "IoBuf::~IoBuf()"); - if (_mode > REA) + if (_mode != kModeRead) writeBuf(); free(_buff); } @@ -222,7 +222,7 @@ void IoBuf::write(uint8 b) { uint16 CFile::_maxLineLen = kLineMaxSize; -CFile::CFile(const char *name, IOMODE mode, CRYPT *crpt) +CFile::CFile(const char *name, IOMode mode, CRYPT *crpt) : IoBuf(name, mode, crpt) { debugC(1, kCGEDebugFile, "CFile::CFile(%s, %d, crpt)", name, mode); } @@ -235,7 +235,7 @@ CFile::~CFile() { void CFile::flush() { debugC(1, kCGEDebugFile, "CFile::flush()"); - if (_mode > REA) + if (_mode != kModeRead) writeBuf(); else _lim = 0; @@ -252,7 +252,7 @@ void CFile::flush() { long CFile::mark() { debugC(5, kCGEDebugFile, "CFile::mark()"); - return _bufMark + ((_mode > REA) ? _lim : _ptr); + return _bufMark + ((_mode != kModeRead) ? _lim : _ptr); } @@ -260,10 +260,10 @@ long CFile::seek(long pos) { debugC(1, kCGEDebugFile, "CFile::seek(%ld)", pos); if (pos >= _bufMark && pos < _bufMark + _lim) { - ((_mode == REA) ? _ptr : _lim) = (uint16)(pos - _bufMark); + ((_mode == kModeRead) ? _ptr : _lim) = (uint16)(pos - _bufMark); return pos; } else { - if (_mode > REA) + if (_mode != kModeRead) writeBuf(); else _lim = 0; diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index 227b0f6a63c..306ec5926be 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -46,8 +46,8 @@ protected: virtual void readBuf(); virtual void writeBuf(); public: - IoBuf(IOMODE mode, CRYPT *crpt = NULL); - IoBuf(const char *name, IOMODE mode, CRYPT *crpt = NULL); + IoBuf(IOMode mode, CRYPT *crpt = NULL); + IoBuf(const char *name, IOMode mode, CRYPT *crpt = NULL); virtual ~IoBuf(); uint16 read(void *buf, uint16 len); uint16 read(uint8 *buf); @@ -61,7 +61,7 @@ public: class CFile : public IoBuf { public: static uint16 _maxLineLen; - CFile(const char *name, IOMODE mode = REA, CRYPT *crpt = NULL); + CFile(const char *name, IOMode mode = kModeRead, CRYPT *crpt = NULL); virtual ~CFile(); void flush(); long mark(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index ee561726a16..b6f342edfff 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -401,18 +401,18 @@ bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &heade void CGEEngine::heroCover(int cvr) { debugC(1, kCGEDebugEngine, "CGEEngine::heroCover(%d)", cvr); - SNPOST(SNCOVER, 1, cvr, NULL); + _snail->addCom(kSnCover, 1, cvr, NULL); } void CGEEngine::trouble(int seq, int txt) { debugC(1, kCGEDebugEngine, "CGEEngine::trouble(%d, %d)", seq, txt); _hero->park(); - SNPOST(SNWAIT, -1, -1, _hero); - SNPOST(SNSEQ, -1, seq, _hero); - SNPOST(SNSOUND, -1, 2, _hero); - SNPOST(SNWAIT, -1, -1, _hero); - SNPOST(SNSAY, 1, txt, _hero); + _snail->addCom(kSnWait, -1, -1, _hero); + _snail->addCom(kSnSeq, -1, seq, _hero); + _snail->addCom(kSnSound, -1, 2, _hero); + _snail->addCom(kSnWait, -1, -1, _hero); + _snail->addCom(kSnSay, 1, txt, _hero); } void CGEEngine::offUse() { @@ -464,7 +464,7 @@ void Square::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); if (mask & L_UP) { XZ(_x + x, _y + y).cell() = 0; - SNPOST_(SNKILL, -1, 0, this); + _snail_->addCom(kSnKill, -1, 0, this); } } @@ -487,14 +487,14 @@ void CGEEngine::setMapBrick(int x, int z) { void CGEEngine::keyClick() { debugC(1, kCGEDebugEngine, "CGEEngine::keyClick()"); - SNPOST_(SNSOUND, -1, 5, NULL); + _snail_->addCom(kSnSound, -1, 5, NULL); } void CGEEngine::resetQSwitch() { debugC(1, kCGEDebugEngine, "CGEEngine::resetQSwitch()"); - SNPOST_(SNSEQ, 123, 0, NULL); + _snail_->addCom(kSnSeq, 123, 0, NULL); keyClick(); } @@ -510,13 +510,13 @@ void CGEEngine::quit() { if (_snail->idle() && !_hero->_flags._hide) { if (Vmenu::_addr) { - SNPOST_(SNKILL, -1, 0, Vmenu::_addr); + _snail_->addCom(kSnKill, -1, 0, Vmenu::_addr); resetQSwitch(); } else { QuitMenu[0]._text = _text->getText(kQuit); QuitMenu[1]._text = _text->getText(kNoQuit); (new Vmenu(this, QuitMenu, -1, -1))->setName(_text->getText(kQuitTitle)); - SNPOST_(SNSEQ, 123, 1, NULL); + _snail_->addCom(kSnSeq, 123, 1, NULL); keyClick(); } } @@ -526,7 +526,7 @@ void CGEEngine::quit() { void CGEEngine::AltCtrlDel() { debugC(1, kCGEDebugEngine, "CGEEngine::AltCtrlDel()"); - SNPOST_(SNSAY, -1, kAltCtrlDel, _hero); + _snail_->addCom(kSnSay, -1, kAltCtrlDel, _hero); } void CGEEngine::miniStep(int stp) { @@ -547,7 +547,7 @@ void CGEEngine::postMiniStep(int step) { debugC(6, kCGEDebugEngine, "CGEEngine::postMiniStep(%d)", step); if (_miniCave && step != _recentStep) - SNPOST2_(SNEXEC, -1, _recentStep = step, kMiniStep); + _snail_->addCom2(kSnExec, -1, _recentStep = step, kMiniStep); } void CGEEngine::showBak(int ref) { @@ -676,8 +676,8 @@ void CGEEngine::switchCave(int cav) { if (cav != _now) { _heart->_enable = false; if (cav < 0) { - SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - SNPOST2(SNEXEC, -1, 0, kQGame); // switch cave + _snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint + _snail->addCom2(kSnExec, -1, 0, kQGame); // switch cave } else { _now = cav; _mouse->off(); @@ -694,8 +694,8 @@ void CGEEngine::switchCave(int cav) { killText(); if (!_startupMode) keyClick(); - SNPOST(SNLABEL, -1, 0, NULL); // wait for repaint - SNPOST2(SNEXEC, 0, 0, kXCave); // switch cave + _snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint + _snail->addCom2(kSnExec, 0, 0, kXCave); // switch cave } } } @@ -732,7 +732,7 @@ void System::touch(uint16 mask, int x, int y) { _vm->keyClick(); killText(); if (_vm->_startupMode == 1) { - SNPOST(SNCLEAR, -1, 0, NULL); + _snail->addCom(kSnClear, -1, 0, NULL); return; } pp0 = pp; @@ -801,7 +801,7 @@ void System::touch(uint16 mask, int x, int y) { case '3': case '4': if (_keyboard->_key[ALT]) { - SNPOST(SNLEVEL, -1, x - '0', NULL); + _snail->addCom(kSnLevel, -1, x - '0', NULL); break; } case '5': @@ -910,7 +910,7 @@ void System::tick() { void CGEEngine::switchColorMode() { debugC(1, kCGEDebugEngine, "CGEEngine::switchColorMode()"); - SNPOST_(SNSEQ, 121, _vga->_mono = !_vga->_mono, NULL); + _snail_->addCom(kSnSeq, 121, _vga->_mono = !_vga->_mono, NULL); keyClick(); _vga->setColors(Vga::_sysPal, 64); } @@ -920,16 +920,16 @@ void CGEEngine::switchMusic() { if (_keyboard->_key[ALT]) { if (Vmenu::_addr) - SNPOST_(SNKILL, -1, 0, Vmenu::_addr); + _snail_->addCom(kSnKill, -1, 0, Vmenu::_addr); else { - SNPOST_(SNSEQ, 122, (_music = false), NULL); - SNPOST2(SNEXEC, -1, 0, kSelectSound); + _snail_->addCom(kSnSeq, 122, (_music = false), NULL); + _snail->addCom2(kSnExec, -1, 0, kSelectSound); } } else { if (Startup::_core < CORE_HIG) - SNPOST(SNINF, -1, kNoMusic, NULL); + _snail->addCom(kSnInf, -1, kNoMusic, NULL); else { - SNPOST_(SNSEQ, 122, (_music = !_music), NULL); + _snail_->addCom(kSnSeq, 122, (_music = !_music), NULL); keyClick(); } } @@ -950,7 +950,7 @@ void CGEEngine::takeName() { debugC(1, kCGEDebugEngine, "CGEEngine::takeName()"); if (GetText::_ptr) - SNPOST_(SNKILL, -1, 0, GetText::_ptr); + _snail_->addCom(kSnKill, -1, 0, GetText::_ptr); else { memset(_usrFnam, 0, 15); GetText *tn = new GetText(this, _text->getText(kGetNamePrompt), _usrFnam, 8); @@ -980,7 +980,7 @@ void CGEEngine::switchMapping() { Sprite *s; for (s = _vga->_showQ->first(); s; s = s->_next) if (s->_w == MAP_XGRID && s->_h == MAP_ZGRID) - SNPOST_(SNKILL, -1, 0, s); + _snail_->addCom(kSnKill, -1, 0, s); } _horzLine->_flags._hide = !_horzLine->_flags._hide; } @@ -990,7 +990,7 @@ void CGEEngine::killSprite() { _sprite->_flags._kill = true; _sprite->_flags._bDel = true; - SNPOST_(SNKILL, -1, 0, _sprite); + _snail_->addCom(kSnKill, -1, 0, _sprite); _sprite = NULL; } @@ -1003,7 +1003,7 @@ void CGEEngine::pushSprite() { while (_sprite->_z > _sprite->_next->_z) _sprite->_z--; } else - SNPOST_(SNSOUND, -1, 2, NULL); + _snail_->addCom(kSnSound, -1, 2, NULL); } void CGEEngine::pullSprite() { @@ -1022,25 +1022,25 @@ void CGEEngine::pullSprite() { while (_sprite->_z < _sprite->_prev->_z) _sprite->_z++; } else - SNPOST_(SNSOUND, -1, 2, NULL); + _snail_->addCom(kSnSound, -1, 2, NULL); } void CGEEngine::nextStep() { debugC(1, kCGEDebugEngine, "CGEEngine::nextStep()"); - SNPOST_(SNSTEP, 0, 0, _sprite); + _snail_->addCom(kSnStep, 0, 0, _sprite); } void CGEEngine::saveMapping() { debugC(1, kCGEDebugEngine, "CGEEngine::saveMapping()"); - IoHand cfTab(progName(".TAB"), UPD); + IoHand cfTab(progName(".TAB"), kModeUpdate); if (!cfTab._error) { cfTab.seek((_now - 1) * sizeof(Cluster::_map)); cfTab.write((uint8 *) Cluster::_map, sizeof(Cluster::_map)); } - IoHand cfHxy(progName(".HXY"), WRI); + IoHand cfHxy(progName(".HXY"), kModeWrite); if (!cfHxy._error) { _heroXY[_now - 1]._x = _hero->_x; _heroXY[_now - 1]._y = _hero->_y; @@ -1155,13 +1155,13 @@ void Sprite::touch(uint16 mask, int x, int y) { if (_vm->findPocket(NULL) < 0) _vm->pocFul(); else { - SNPOST(SNREACH, -1, -1, this); - SNPOST(SNKEEP, -1, -1, this); + _snail->addCom(kSnReach, -1, -1, this); + _snail->addCom(kSnKeep, -1, -1, this); _flags._port = false; } } else { if (_takePtr != NO_PTR) { - if (snList(kTake)[_takePtr]._com == SNNEXT) + if (snList(kTake)[_takePtr]._com == kSnNext) _vm->offUse(); else _vm->feedSnail(this, kTake); @@ -1184,7 +1184,7 @@ void Sprite::touch(uint16 mask, int x, int y) { } } } else - SNPOST(SNWALK, -1, -1, this); // Hero->FindWay(this); + _snail->addCom(kSnWalk, -1, -1, this); // Hero->FindWay(this); } } } @@ -1413,9 +1413,9 @@ void CGEEngine::mainLoop() { // static uint32 tc = 0; if (/* FIXME: TimerCount - tc >= ((182L * 6L) * 5L) && */ _talk == NULL && _snail->idle()) { if (_text->getText(_demoText)) { - SNPOST(SNSOUND, -1, 4, NULL); // drumla - SNPOST(SNINF, -1, _demoText, NULL); - SNPOST(SNLABEL, -1, -1, NULL); + _snail->addCom(kSnSound, -1, 4, NULL); // drumla + _snail->addCom(kSnInf, -1, _demoText, NULL); + _snail->addCom(kSnLabel, -1, -1, NULL); if (_text->getText(++_demoText) == NULL) _demoText = kDemo + 1; } @@ -1525,10 +1525,10 @@ void CGEEngine::runGame() { // ~~~~~~~~~~~ if ((_sprite = _vga->_spareQ->locate(121)) != NULL) - SNPOST_(SNSEQ, -1, _vga->_mono, _sprite); + _snail_->addCom(kSnSeq, -1, _vga->_mono, _sprite); if ((_sprite = _vga->_spareQ->locate(122)) != NULL) _sprite->step(_music); - SNPOST_(SNSEQ, -1, _music, _sprite); + _snail_->addCom(kSnSeq, -1, _music, _sprite); if (!_music) killMidi(); @@ -1585,7 +1585,7 @@ void CGEEngine::runGame() { _startupMode = 0; - SNPOST(SNLEVEL, -1, _oldLev, &_cavLight); + _snail->addCom(kSnLevel, -1, _oldLev, &_cavLight); _cavLight->gotoxy(CAVE_X + ((_now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((_now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); caveUp(); @@ -1594,14 +1594,14 @@ void CGEEngine::runGame() { // main loop while (!_finis && !_eventManager->_quitFlag) { if (_finis) - SNPOST2(SNEXEC, -1, 0, kQGame); + _snail->addCom2(kSnExec, -1, 0, kQGame); mainLoop(); } _keyboard->setClient(NULL); _heart->_enable = false; - SNPOST(SNCLEAR, -1, 0, NULL); - SNPOST_(SNCLEAR, -1, 0, NULL); + _snail->addCom(kSnClear, -1, 0, NULL); + _snail_->addCom(kSnClear, -1, 0, NULL); _mouse->off(); _vga->_showQ->clear(); _vga->_spareQ->clear(); @@ -1629,8 +1629,8 @@ void CGEEngine::movie(const char *ext) { _keyboard->setClient(NULL); _heart->_enable = false; - SNPOST(SNCLEAR, -1, 0, NULL); - SNPOST_(SNCLEAR, -1, 0, NULL); + _snail->addCom(kSnClear, -1, 0, NULL); + _snail_->addCom(kSnClear, -1, 0, NULL); _vga->_showQ->clear(); _vga->_spareQ->clear(); } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 8639c66653d..909c517c32c 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -206,15 +206,15 @@ char *dwtom(uint32 val, char *str, int radix, int len) { return str; } -IoHand::IoHand(IOMODE mode, CRYPT *crpt) - : XFile(mode), _crypt(crpt), _seed(SEED) { +IoHand::IoHand(IOMode mode, CRYPT *crpt) + : XFile(mode), _crypt(crpt), _seed(kCryptSeed) { _file = new Common::File(); } -IoHand::IoHand(const char *name, IOMODE mode, CRYPT *crpt) - : XFile(mode), _crypt(crpt), _seed(SEED) { +IoHand::IoHand(const char *name, IOMode mode, CRYPT *crpt) + : XFile(mode), _crypt(crpt), _seed(kCryptSeed) { // TODO: Check if WRI and/or UPD modes are needed, and map to a save file - assert(mode == REA); + assert(mode == kModeRead); _file = new Common::File(); _file->open(name); @@ -226,7 +226,7 @@ IoHand::~IoHand() { } uint16 IoHand::read(void *buf, uint16 len) { - if (_mode == WRI || !_file->isOpen()) + if (_mode == kModeWrite || !_file->isOpen()) return 0; uint16 bytesRead = _file->read(buf, len); @@ -242,7 +242,7 @@ uint16 IoHand::write(void *buf, uint16 len) { return 0; /* if (len) { - if (Mode == REA || Handle < 0) + if (Mode == kModeRead || Handle < 0) return 0; if (Crypt) Seed = Crypt(buf, len, Seed); @@ -333,7 +333,6 @@ int new_random(int range) { return ((CGEEngine *)g_engine)->_randomSource.getRandomNumber(range - 1); } -#define TIMER_INT 0x08 //void interrupt (* Engine_::oldTimer) (...) = NULL; Engine_::Engine_(uint16 tdiv) { diff --git a/engines/cge/general.h b/engines/cge/general.h index 0639fe2a017..63d43c4403b 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -37,9 +37,9 @@ namespace CGE { -#define SEED 0xA5 +#define kCryptSeed 0xA5 -enum IOMODE { REA, WRI, UPD }; +enum IOMode { kModeRead, kModeWrite, kModeUpdate }; struct Dac { uint8 _r; @@ -47,7 +47,7 @@ struct Dac { uint8 _b; }; -typedef uint16 CRYPT(void *buf, uint16 siz, uint16 seed); +typedef uint16 CRYPT(void *buf, uint16 siz, uint16 seed); class Engine_ { protected: @@ -111,11 +111,11 @@ T min(T A, T B) { class XFile { public: - IOMODE _mode; + IOMode _mode; uint16 _error; - XFile() : _mode(REA), _error(0) { } - XFile(IOMODE mode) : _mode(mode), _error(0) { } + XFile() : _mode(kModeRead), _error(0) { } + XFile(IOMode mode) : _mode(mode), _error(0) { } virtual ~XFile() { } virtual uint16 read(void *buf, uint16 len) = 0; virtual uint16 write(void *buf, uint16 len) = 0; @@ -137,8 +137,8 @@ protected: uint16 _seed; CRYPT *_crypt; public: - IoHand(const char *name, IOMODE mode = REA, CRYPT crypt = NULL); - IoHand(IOMODE mode = REA, CRYPT *crpt = NULL); + IoHand(const char *name, IOMode mode = kModeRead, CRYPT crypt = NULL); + IoHand(IOMode mode = kModeRead, CRYPT *crpt = NULL); virtual ~IoHand(); static bool exist(const char *name); uint16 read(void *buf, uint16 len); @@ -146,8 +146,6 @@ public: long mark(); long size(); long seek(long pos); - //timeb Time (); -// void SetTime (timeb t); }; CRYPT XCrypt; diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 2f16cad86ae..7a8cff3cb2c 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -35,8 +35,8 @@ GetText *GetText::_ptr = NULL; GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) - : Talk(vm), _text(text), _size(min(size, GTMAX)), _len(min(_size, strlen(text))), - _cntr(GTBLINK), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { + : Talk(vm), _text(text), _size(min(size, kGetTextMax)), _len(min(_size, strlen(text))), + _cntr(kGetTextBlink), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { int i = 2 * kTextHMargin + _font->width(info); _ptr = this; _mode = RECT; @@ -63,12 +63,12 @@ GetText::~GetText() { void GetText::tick() { - if (++_cntr >= GTBLINK) { + if (++_cntr >= kGetTextBlink) { _buff[_len] ^= (' ' ^ '_'); _cntr = 0; } putLine(1, _buff); - _time = GTTIME; + _time = kGetTextTime; } @@ -89,7 +89,7 @@ void GetText::touch(uint16 mask, int x, int y) { *p = bezo[q - ogon]; } case Esc : - SNPOST_(SNKILL, -1, 0, this); + _snail_->addCom(kSnKill, -1, 0, this); break; case BSp : if (_len) { diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h index 188e90c7764..6afa9ccfecd 100644 --- a/engines/cge/gettext.h +++ b/engines/cge/gettext.h @@ -33,12 +33,12 @@ namespace CGE { -#define GTMAX 24 -#define GTBLINK 6 -#define GTTIME 6 +#define kGetTextMax 24 +#define kGetTextBlink 6 +#define kGetTextTime 6 class GetText : public Talk { - char _buff[GTMAX + 2]; + char _buff[kGetTextMax + 2]; char *_text; uint16 _size; uint16 _len; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index eddc4a65704..aeaaa86593b 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -39,24 +39,24 @@ extern Mouse *Mouse; bool Mixer::_appear = false; -Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(MIX_FALL), _vm(vm) { +Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _vm(vm) { _appear = true; _mb[0] = new Bitmap("VOLUME", true); _mb[1] = NULL; setShapeList(_mb); - setName(_text->getText(MIX_NAME)); + setName(_text->getText(kMixName)); _flags._syst = true; _flags._kill = true; _flags._bDel = true; gotoxy(x, y); - _z = MIX_Z; + _z = kMixZ; // slaves uint i; - Seq ls[MIX_MAX]; + Seq ls[kMixMax]; - for (i = 0; i < MIX_MAX; i++) { + for (i = 0; i < kMixMax; i++) { static char fn[] = "V00"; wtom(i, fn + 1, 10, 2); _lb[i] = new Bitmap(fn, true); @@ -68,15 +68,15 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(MIX_FALL), _ for (i = 0; i < ArrayCount(_led); i++) { register Sprite *spr = new Sprite(_vm, _lb); - Seq *seq = (Seq *)malloc(MIX_MAX * sizeof(Seq)); - Common::copy(ls, ls + MIX_MAX, seq); + Seq *seq = (Seq *)malloc(kMixMax * sizeof(Seq)); + Common::copy(ls, ls + kMixMax, seq); spr->setSeq(seq); spr->gotoxy(x + 2 + 12 * i, y + 8); spr->_flags._tran = true; spr->_flags._kill = true; spr->_flags._bDel = false; - spr->_z = MIX_Z; + spr->_z = kMixZ; _led[i] = spr; } _led[ArrayCount(_led) - 1]->_flags._bDel = true; @@ -93,7 +93,7 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(MIX_FALL), _ _sndDrvInfo.Vol4._dl = i; _sndDrvInfo.Vol4._dr = i; update(); - _time = MIX_DELAY; + _time = kMixDelay; } Mixer::~Mixer() { @@ -106,10 +106,10 @@ void Mixer::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); if (mask & L_UP) { uint8 *vol = (&_sndDrvInfo.Vol2._d) + (x < _w / 2); - if (y < MIX_BHIG) { + if (y < kMixButtonHigh) { if (*vol < 0xFF) *vol += 0x11; - } else if (y >= _h - MIX_BHIG) { + } else if (y >= _h - kMixButtonHigh) { if (*vol > 0x00) *vol -= 0x11; } @@ -122,7 +122,7 @@ void Mixer::tick() { int x = _mouse->_x; int y = _mouse->_y; if (spriteAt(x, y) == this) { - _fall = MIX_FALL; + _fall = kMixFall; if (_flags._hold) touch(L_UP, x - _x, y - _y); } else { @@ -130,11 +130,11 @@ void Mixer::tick() { _fall--; else { for (uint i = 0; i < ArrayCount(_led); i++) - SNPOST_(SNKILL, -1, 0, _led[i]); - SNPOST_(SNKILL, -1, 0, this); + _snail_->addCom(kSnKill, -1, 0, _led[i]); + _snail_->addCom(kSnKill, -1, 0, this); } } - _time = MIX_DELAY; + _time = kMixDelay; } @@ -142,7 +142,7 @@ void Mixer::update() { _led[0]->step(_sndDrvInfo.Vol4._ml); _led[1]->step(_sndDrvInfo.Vol4._dl); - SNPOST2_(SNEXEC, -1, 0, kSndSetVolume); + _snail_->addCom2(kSnExec, -1, 0, kSndSetVolume); } } // End of namespace CGE diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index ef53eec0705..d97a4f3dd3a 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -32,16 +32,16 @@ namespace CGE { -#define MIX_MAX 16 // count of Leds -#define MIX_Z 64 // mixer Z position -#define MIX_DELAY 12 // 6/s -#define MIX_FALL 6 // in MIX_DELAY units -#define MIX_BHIG 6 // mixer button high -#define MIX_NAME 105 // sprite name +#define kMixMax 16 // count of Leds +#define kMixZ 64 // mixer Z position +#define kMixDelay 12 // 6/s +#define kMixFall 6 // in MIX_DELAY units +#define kMixButtonHigh 6 // mixer button high +#define kMixName 105 // sprite name class Mixer : public Sprite { BMP_PTR _mb[2]; - BMP_PTR _lb[MIX_MAX + 1]; + BMP_PTR _lb[kMixMax + 1]; Sprite *_led[2]; int _fall; void update(); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index e694cab0b90..d2ed77d7555 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -50,8 +50,6 @@ void CGEEngine::snGame(Sprite *spr, int num) { switch (num) { case 1 : { -#define STAGES 8 -#define DRESSED 3 static Sprite *dup[3] = { NULL, NULL, NULL }; int buref = 0; int Stage = 0; @@ -71,71 +69,69 @@ void CGEEngine::snGame(Sprite *spr, int num) { if (_game) { // continue game int i = new_random(3), hand = (dup[0]->_shpCnt == 6); Stage++; - if (hand && Stage > DRESSED) + if (hand && Stage > kDressed) ++hand; if (i >= 0 || (dup[i] == spr && new_random(3) == 0)) { - SNPOST(SNSEQ, -1, 3, dup[0]); // yes - SNPOST(SNSEQ, -1, 3, dup[1]); // yes - SNPOST(SNSEQ, -1, 3, dup[2]); // yes - SNPOST(SNTNEXT, -1, 0, dup[0]); // reset Take - SNPOST(SNTNEXT, -1, 0, dup[1]); // reset Take - SNPOST(SNTNEXT, -1, 0, dup[2]); // reset Take - SNPOST(SNNNEXT, -1, 0, dup[0]); // reset Near - SNPOST(SNPAUSE, -1, 72, NULL); // little rest - SNPOST(SNSAY, 1, 16009, NULL); // hura - SNPOST(SNSAY, buref, 16010, NULL); // siadaj - SNPOST(SNSAY, 1, 16011, NULL); // postoj‘ + _snail->addCom(kSnSeq, -1, 3, dup[0]); // yes + _snail->addCom(kSnSeq, -1, 3, dup[1]); // yes + _snail->addCom(kSnSeq, -1, 3, dup[2]); // yes + _snail->addCom(kSnTNext, -1, 0, dup[0]); // reset Take + _snail->addCom(kSnTNext, -1, 0, dup[1]); // reset Take + _snail->addCom(kSnTNext, -1, 0, dup[2]); // reset Take + _snail->addCom(kSnNNext, -1, 0, dup[0]); // reset Near + _snail->addCom(kSnPause, -1, 72, NULL); // little rest + _snail->addCom(kSnSay, 1, 16009, NULL); // hura + _snail->addCom(kSnSay, buref, 16010, NULL); // siadaj + _snail->addCom(kSnSay, 1, 16011, NULL); // postoj‘ if (hand) { - SNPOST(SNSEND, 16060 + hand, 16, NULL); // dawaj r‘k‘ - SNPOST(SNSEQ, buref, 4, NULL); // zdejmowanie - SNPOST(SNSEQ, 16060 + hand, 1, NULL); // ruch - SNPOST(SNSOUND, 16060 + hand, 16002, NULL); // szelest - SNPOST(SNWAIT, 16060 + hand, 3, NULL); // podniesie - SNPOST(SNSWAP, buref, buref + 100, NULL); // rozdziana - SNPOST(SNSEQ, 16016, Stage, NULL); // rožnie kupa - SNPOST(SNSEND, 16060 + hand, -1, NULL); // chowaj r‘k‘ - SNPOST(SNWAIT, 16060 + hand, -1, NULL); // r‘ka zamar’a + _snail->addCom(kSnSend, 16060 + hand, 16, NULL); // dawaj r‘k‘ + _snail->addCom(kSnSeq, buref, 4, NULL); // zdejmowanie + _snail->addCom(kSnSeq, 16060 + hand, 1, NULL); // ruch + _snail->addCom(kSnSound, 16060 + hand, 16002, NULL); // szelest + _snail->addCom(kSnWait, 16060 + hand, 3, NULL); // podniesie + _snail->addCom(kSnSwap, buref, buref + 100, NULL); // rozdziana + _snail->addCom(kSnSeq, 16016, Stage, NULL); // rožnie kupa + _snail->addCom(kSnSend, 16060 + hand, -1, NULL); // chowaj r‘k‘ + _snail->addCom(kSnWait, 16060 + hand, -1, NULL); // r‘ka zamar’a } else { - SNPOST(SNSEQ, buref, 4, NULL); // zdejmowanie - SNPOST(SNSOUND, 16060 + hand, 16002, NULL); // szelest - SNPOST(SNWAIT, buref, -1, NULL); // zdejmie - SNPOST(SNSWAP, buref, buref + 100, NULL); // rozdziana - SNPOST(SNSEQ, 16016, Stage, NULL); // rožnie kupa + _snail->addCom(kSnSeq, buref, 4, NULL); // zdejmowanie + _snail->addCom(kSnSound, 16060 + hand, 16002, NULL); // szelest + _snail->addCom(kSnWait, buref, -1, NULL); // zdejmie + _snail->addCom(kSnSwap, buref, buref + 100, NULL); // rozdziana + _snail->addCom(kSnSeq, 16016, Stage, NULL); // rožnie kupa } //SNPOST(SNSEQ, buref+100, 0, NULL); // reset - SNPOST(SNPAUSE, -1, 72, NULL); // chwilk‘... - - SNPOST(SNSEQ, -1, 0, dup[1]); // odstaw Go - SNPOST(SNSETXY, -1, 203 + kScrWidth * 49, dup[1]); - SNPOST(SNSETZ, -1, 7, dup[1]); - - SNPOST(SNSEQ, -1, 0, dup[2]); // odstaw J† - SNPOST(SNSETXY, -1, 182 + kScrWidth * 62, dup[2]); - SNPOST(SNSETZ, -1, 9, dup[2]); + _snail->addCom(kSnPause, -1, 72, NULL); // chwilk‘... + _snail->addCom(kSnSeq, -1, 0, dup[1]); // odstaw Go + _snail->addCom(kSnSetXY, -1, 203 + kScrWidth * 49, dup[1]); + _snail->addCom(kSnSetZ, -1, 7, dup[1]); + _snail->addCom(kSnSeq, -1, 0, dup[2]); // odstaw J† + _snail->addCom(kSnSetXY, -1, 182 + kScrWidth * 62, dup[2]); + _snail->addCom(kSnSetZ, -1, 9, dup[2]); _game = 0; return; } else { - SNPOST(SNSEQ, -1, 2, dup[0]); // no - SNPOST(SNSEQ, -1, 2, dup[1]); // no - SNPOST(SNSEQ, -1, 2, dup[2]); // no - SNPOST(SNPAUSE, -1, 72, NULL); // 1 sec + _snail->addCom(kSnSeq, -1, 2, dup[0]); // no + _snail->addCom(kSnSeq, -1, 2, dup[1]); // no + _snail->addCom(kSnSeq, -1, 2, dup[2]); // no + _snail->addCom(kSnPause, -1, 72, NULL); // 1 sec } } - SNPOST(SNWALK, 198, 134, NULL); // na miejsce - SNPOST(SNWAIT, 1, -1, NULL); // stoi - SNPOST(SNCOVER, 1, 16101, NULL); // ch’op do bicia - SNPOST(SNSEQ, 16101, 1, NULL); // wystaw - SNPOST(SNWAIT, 16101, 5, NULL); // czekaj - SNPOST(SNPAUSE, 16101, 24, NULL); // czekaj chwil‘ - SNPOST(SNSEQ, 16040, 1, NULL); // plask - SNPOST(SNSOUND, 16101, 16001, NULL); // plask! - SNPOST(SNPAUSE, 16101, 24, NULL); // czekaj chwil‘ - SNPOST(SNSEQ, 16040, 0, NULL); // schowaj plask - SNPOST(SNWAIT, 16101, -1, NULL); // stoi - SNPOST(SNUNCOVER, 1, 16101, NULL); // SDS + _snail->addCom(kSnWalk, 198, 134, NULL); // na miejsce + _snail->addCom(kSnWait, 1, -1, NULL); // stoi + _snail->addCom(kSnCover, 1, 16101, NULL); // ch’op do bicia + _snail->addCom(kSnSeq, 16101, 1, NULL); // wystaw + _snail->addCom(kSnWait, 16101, 5, NULL); // czekaj + _snail->addCom(kSnPause, 16101, 24, NULL); // czekaj chwil‘ + _snail->addCom(kSnSeq, 16040, 1, NULL); // plask + _snail->addCom(kSnSound, 16101, 16001, NULL); // plask! + _snail->addCom(kSnPause, 16101, 24, NULL); // czekaj chwil‘ + _snail->addCom(kSnSeq, 16040, 0, NULL); // schowaj plask + _snail->addCom(kSnWait, 16101, -1, NULL); // stoi + _snail->addCom(kSnUncover, 1, 16101, NULL); // SDS if (!_game) { - SNPOST(SNSAY, buref, 16008, NULL); // zgadnij! + _snail->addCom(kSnSay, buref, 16008, NULL); // zgadnij! _game = true; } #undef STEPS @@ -155,7 +151,7 @@ void CGEEngine::snGame(Sprite *spr, int num) { } if (!_game) { // init - SNPOST(SNGAME, 20002, 2, NULL); + _snail->addCom(kSnGame, 20002, 2, NULL); _game = true; } else { // cont k1->step(new_random(6)); @@ -168,23 +164,23 @@ void CGEEngine::snGame(Sprite *spr, int num) { k3->step(5); } ///-------------------- - SNPOST(SNSETZ, 20700, 0, NULL); + _snail->addCom(kSnSetZ, 20700, 0, NULL); bool hit = (k1->_seqPtr + k2->_seqPtr + k3->_seqPtr == 15); if (hit) { if (spr->_ref == 1) { - SNPOST(SNSAY, 1, 20003, NULL); // hura! - SNPOST(SNSEQ, 20011, 2, NULL); // kamera won - SNPOST(SNSEND, 20701, -1, NULL); // k1 won - SNPOST(SNSEND, 20702, -1, NULL); // k2 won - SNPOST(SNSEND, 20703, -1, NULL); // k3 won - SNPOST(SNSEND, 20700, -1, NULL); // tv won - SNPOST(SNKEEP, 20007, 0, NULL); // do kieszeni - SNPOST(SNSEND, 20006, 20, NULL); // bilon - SNPOST(SNSOUND, 20006, 20002, NULL); // bilon! - SNPOST(SNSAY, 20002, 20004, NULL); - SNPOST(SNSEND, 20010, 20, NULL); // papier - SNPOST(SNSOUND, 20010, 20003, NULL); // papier! - SNPOST(SNSAY, 20001, 20005, NULL); + _snail->addCom(kSnSay, 1, 20003, NULL); // hura! + _snail->addCom(kSnSeq, 20011, 2, NULL); // kamera won + _snail->addCom(kSnSend, 20701, -1, NULL); // k1 won + _snail->addCom(kSnSend, 20702, -1, NULL); // k2 won + _snail->addCom(kSnSend, 20703, -1, NULL); // k3 won + _snail->addCom(kSnSend, 20700, -1, NULL); // tv won + _snail->addCom(kSnKeep, 20007, 0, NULL); // do kieszeni + _snail->addCom(kSnSend, 20006, 20, NULL); // bilon + _snail->addCom(kSnSound, 20006, 20002, NULL); // bilon! + _snail->addCom(kSnSay, 20002, 20004, NULL); + _snail->addCom(kSnSend, 20010, 20, NULL); // papier + _snail->addCom(kSnSound, 20010, 20003, NULL); // papier! + _snail->addCom(kSnSay, 20001, 20005, NULL); _game = false; return; } else @@ -193,60 +189,60 @@ void CGEEngine::snGame(Sprite *spr, int num) { if (count < 100) { switch (count) { case 15 : - SNPOST(SNSAY, 20003, 20021, NULL); + _snail->addCom(kSnSay, 20003, 20021, NULL); break; case 30 : case 45 : case 60 : case 75 : - SNPOST(SNSAY, 20003, 20022, NULL); + _snail->addCom(kSnSay, 20003, 20022, NULL); break; } count++; } switch (spr->_ref) { case 1 : - SNPOST(SNSAY, 20001, 20011, NULL); // zapro - SNPOST(SNSEQ, 20001, 1, NULL); // rzu - SNPOST(SNWAIT, 20001, 1, NULL); // czekaj - SNPOST(SNSETZ, 20700, 2, NULL); // skryj k - SNPOST(SNHIDE, 20007, 1, NULL); // skryj k - SNPOST(SNWAIT, 20001, 16, NULL); // czekaj - SNPOST(SNSEQ, 20007, 1, NULL); // lec† - SNPOST(SNHIDE, 20007, 0, NULL); // poka§ - SNPOST(SNSOUND, 20007, 20001, NULL); // grzech - SNPOST(SNWAIT, 20007, -1, NULL); // koniec - SNPOST(SNGAME, 20001, 2, NULL); // again! + _snail->addCom(kSnSay, 20001, 20011, NULL); // zapro + _snail->addCom(kSnSeq, 20001, 1, NULL); // rzu + _snail->addCom(kSnWait, 20001, 1, NULL); // czekaj + _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k + _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k + _snail->addCom(kSnWait, 20001, 16, NULL); // czekaj + _snail->addCom(kSnSeq, 20007, 1, NULL); // lec† + _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ + _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech + _snail->addCom(kSnWait, 20007, -1, NULL); // koniec + _snail->addCom(kSnGame, 20001, 2, NULL); // again! break; case 20001: - SNPOST(SNSAY, 20002, 20012, NULL); // zapro - SNPOST(SNSEQ, 20002, 1, NULL); // rzu - SNPOST(SNWAIT, 20002, 3, NULL); // czekaj - SNPOST(SNSETZ, 20700, 2, NULL); // skryj k - SNPOST(SNHIDE, 20007, 1, NULL); // skryj k - SNPOST(SNWAIT, 20002, 10, NULL); // czekaj - SNPOST(SNSEQ, 20007, 2, NULL); // lec† - SNPOST(SNHIDE, 20007, 0, NULL); // poka§ - SNPOST(SNSOUND, 20007, 20001, NULL); // grzech - SNPOST(SNWAIT, 20007, -1, NULL); // koniec - SNPOST(SNGAME, 20002, 2, NULL); // again! + _snail->addCom(kSnSay, 20002, 20012, NULL); // zapro + _snail->addCom(kSnSeq, 20002, 1, NULL); // rzu + _snail->addCom(kSnWait, 20002, 3, NULL); // czekaj + _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k + _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k + _snail->addCom(kSnWait, 20002, 10, NULL); // czekaj + _snail->addCom(kSnSeq, 20007, 2, NULL); // lec† + _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ + _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech + _snail->addCom(kSnWait, 20007, -1, NULL); // koniec + _snail->addCom(kSnGame, 20002, 2, NULL); // again! break; case 20002: - SNPOST(SNSAY, 20002, 20010, NULL); // zapro - SNPOST(SNWALK, 20005, -1, NULL); // do stol - SNPOST(SNWAIT, 1, -1, NULL); // stoi - SNPOST(SNCOVER, 1, 20101, NULL); // grasol - SNPOST(SNSEQ, 20101, 1, NULL); // rzu - SNPOST(SNWAIT, 20101, 5, NULL); // czekaj - SNPOST(SNSETZ, 20700, 2, NULL); // skryj k - SNPOST(SNHIDE, 20007, 1, NULL); // skryj k - SNPOST(SNWAIT, 20101, 15, NULL); // czekaj - SNPOST(SNSEQ, 20007, 1, NULL); // lec† - SNPOST(SNHIDE, 20007, 0, NULL); // poka§ - SNPOST(SNSOUND, 20007, 20001, NULL); // grzech - SNPOST(SNWAIT, 20101, -1, NULL); // koniec - SNPOST(SNUNCOVER, 1, 20101, NULL); // SDS - SNPOST(SNGAME, 1, 2, NULL); // again! + _snail->addCom(kSnSay, 20002, 20010, NULL); // zapro + _snail->addCom(kSnWalk, 20005, -1, NULL); // do stol + _snail->addCom(kSnWait, 1, -1, NULL); // stoi + _snail->addCom(kSnCover, 1, 20101, NULL); // grasol + _snail->addCom(kSnSeq, 20101, 1, NULL); // rzu + _snail->addCom(kSnWait, 20101, 5, NULL); // czekaj + _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k + _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k + _snail->addCom(kSnWait, 20101, 15, NULL); // czekaj + _snail->addCom(kSnSeq, 20007, 1, NULL); // lec† + _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ + _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech + _snail->addCom(kSnWait, 20101, -1, NULL); // koniec + _snail->addCom(kSnUncover, 1, 20101, NULL); // SDS + _snail->addCom(kSnGame, 1, 2, NULL); // again! break; } } @@ -302,17 +298,17 @@ void CGEEngine::pocFul() { debugC(1, kCGEDebugEngine, "CGEEngine::pocFul()"); _hero->park(); - SNPOST(SNWAIT, -1, -1, _hero); - SNPOST(SNSEQ, -1, kSeqPocketFull, _hero); - SNPOST(SNSOUND, -1, 2, _hero); - SNPOST(SNWAIT, -1, -1, _hero); - SNPOST(SNSAY, 1, kPocketFull, _hero); + _snail->addCom(kSnWait, -1, -1, _hero); + _snail->addCom(kSnSeq, -1, kSeqPocketFull, _hero); + _snail->addCom(kSnSound, -1, 2, _hero); + _snail->addCom(kSnWait, -1, -1, _hero); + _snail->addCom(kSnSay, 1, kPocketFull, _hero); } void CGEEngine::hide1(Sprite *spr) { debugC(1, kCGEDebugEngine, "CGEEngine::hide1(spr)"); - SNPOST_(SNGHOST, -1, 0, spr->ghost()); + _snail_->addCom(kSnGhost, -1, 0, spr->ghost()); } void CGEEngine::snGhost(Bitmap *bmp) { @@ -337,8 +333,8 @@ void CGEEngine::feedSnail(Sprite *spr, SnList snq) { if (findPocket(NULL) < 0) { // no empty pockets? Snail::Com *p; - for (p = c; p->_com != SNNEXT; p++) { // find KEEP command - if (p->_com == SNKEEP) { + for (p = c; p->_com != kSnNext; p++) { // find KEEP command + if (p->_com == kSnKeep) { pocFul(); return; } @@ -347,11 +343,11 @@ void CGEEngine::feedSnail(Sprite *spr, SnList snq) { } } while (true) { - if (c->_com == SNTALK) { + if (c->_com == kSnTalk) { if ((_snail->_talkEnable = (c->_val != 0)) == false) killText(); } - if (c->_com == SNNEXT) { + if (c->_com == kSnNext) { Sprite *s = (c->_ref < 0) ? spr : locate(c->_ref); if (s) { uint8 *idx = (snq == kTake) ? &s->_takePtr : &s->_nearPtr; @@ -378,7 +374,7 @@ void CGEEngine::feedSnail(Sprite *spr, SnList snq) { if (s == spr) break; } - if (c->_com == SNIF) { + if (c->_com == kSnIf) { Sprite *s = (c->_ref < 0) ? spr : locate(c->_ref); if (s) { // sprite extsts if (! s->seqTest(-1)) @@ -388,7 +384,7 @@ void CGEEngine::feedSnail(Sprite *spr, SnList snq) { } else ++c; } else { - SNPOST(c->_com, c->_ref, c->_val, spr); + _snail->addCom(c->_com, c->_ref, c->_val, spr); if (c->_ptr) break; else @@ -424,35 +420,35 @@ Snail::~Snail() { free(_snList); } -void Snail::addCom(SNCOM com, int ref, int val, void *ptr) { +void Snail::addCom(SnCom com, int ref, int val, void *ptr) { Com *snc = &_snList[_head++]; snc->_com = com; snc->_ref = ref; snc->_val = val; snc->_ptr = ptr; snc->_cbType = kNullCB; - if (com == SNCLEAR) { + if (com == kSnClear) { _tail = _head; killText(); _timerExpiry = 0; } } -void Snail::addCom2(SNCOM com, int ref, int val, CallbackType cbType) { +void Snail::addCom2(SnCom com, int ref, int val, CallbackType cbType) { Com *snc = &_snList[_head++]; snc->_com = com; snc->_ref = ref; snc->_val = val; snc->_ptr = NULL; snc->_cbType = cbType; - if (com == SNCLEAR) { + if (com == kSnClear) { _tail = _head; killText(); _timerExpiry = 0; } } -void Snail::insCom(SNCOM com, int ref, int val, void *ptr) { +void Snail::insCom(SnCom com, int ref, int val, void *ptr) { Com *snc; if (_busy) { @@ -465,7 +461,7 @@ void Snail::insCom(SNCOM com, int ref, int val, void *ptr) { snc->_ref = ref; snc->_val = val; snc->_ptr = ptr; - if (com == SNCLEAR) { + if (com == kSnClear) { _tail = _head; killText(); _timerExpiry = 0; @@ -596,7 +592,6 @@ void CGEEngine::snSend(Sprite *spr, int val) { } } - void CGEEngine::snSwap(Sprite *spr, int xref) { debugC(1, kCGEDebugEngine, "CGEEngine::snSwap(spr, %d)", xref); @@ -828,7 +823,6 @@ void CGEEngine::snKeep(Sprite *spr, int stp) { selectPocket(-1); } - void CGEEngine::snGive(Sprite *spr, int stp) { debugC(1, kCGEDebugEngine, "CGEEngine::snGive(spr, %d)", stp); @@ -845,7 +839,6 @@ void CGEEngine::snGive(Sprite *spr, int stp) { selectPocket(-1); } - void CGEEngine::snBackPt(Sprite *spr, int stp) { debugC(1, kCGEDebugEngine, "CGEEngine::snBackPt(spr, %d)", stp); @@ -956,8 +949,8 @@ void Snail::runCom() { static int count = 1; if (!_busy) { _busy = true; - uint8 tmphea = _head; - while (_tail != tmphea) { + uint8 tmpHead = _head; + while (_tail != tmpHead) { Com *snc = &_snList[_tail]; if (!_turbo) { // only for the slower one @@ -975,35 +968,35 @@ void Snail::runCom() { _textDelay = false; } } - if (_talk && snc->_com != SNPAUSE) + if (_talk && snc->_com != kSnPause) break; } Sprite *spr = ((snc->_ref >= 0) ? locate(snc->_ref) : ((Sprite *) snc->_ptr)); switch (snc->_com) { - case SNLABEL : + case kSnLabel: break; - case SNPAUSE : - _timerExpiry = g_system->getMillis() + snc->_val * SNAIL_FRAME_DELAY; + case kSnPause : + _timerExpiry = g_system->getMillis() + snc->_val * kSnailFrameDelay; if (_talk) _textDelay = true; break; - case SNWAIT : + case kSnWait: if (spr) { if (spr->seqTest(snc->_val) && (snc->_val >= 0 || spr != _hero || _hero->_tracePtr < 0)) { - _timerExpiry = g_system->getMillis() + spr->_time * SNAIL_FRAME_DELAY; + _timerExpiry = g_system->getMillis() + spr->_time * kSnailFrameDelay; } else goto xit; } break; - case SNLEVEL : + case kSnLevel: _vm->snLevel(spr, snc->_val); break; - case SNHIDE : + case kSnHide: _vm->snHide(spr, snc->_val); break; - case SNSAY : + case kSnSay: if (spr && _talkEnable) { if (spr == _hero && spr->seqTest(-1)) spr->step(kSeqHTalk); @@ -1011,148 +1004,148 @@ void Snail::runCom() { _sys->_funDel = kHeroFun0; } break; - case SNINF : + case kSnInf: if (_talkEnable) { _vm->inf(_text->getText(snc->_val)); _sys->_funDel = kHeroFun0; } break; - case SNTIME : + case kSnTime: if (spr && _talkEnable) { if (spr == _hero && spr->seqTest(-1)) spr->step(kSeqHTalk); sayTime(spr); } break; - case SNCAVE : + case kSnCave: _vm->switchCave(snc->_val); break; - case SNKILL : + case kSnKill: _vm->snKill(spr); break; - case SNSEQ : + case kSnSeq: _vm->snSeq(spr, snc->_val); break; - case SNRSEQ : + case kSnRSeq: _vm->snRSeq(spr, snc->_val); break; - case SNSEND : + case kSnSend: _vm->snSend(spr, snc->_val); break; - case SNSWAP : + case kSnSwap: _vm->snSwap(spr, snc->_val); break; - case SNCOVER : + case kSnCover: _vm->snCover(spr, snc->_val); break; - case SNUNCOVER : + case kSnUncover: _vm->snUncover(spr, (snc->_val >= 0) ? locate(snc->_val) : ((Sprite *) snc->_ptr)); break; - case SNKEEP : + case kSnKeep: _vm->snKeep(spr, snc->_val); break; - case SNGIVE : + case kSnGive: _vm->snGive(spr, snc->_val); break; - case SNGAME : + case kSnGame: _vm->snGame(spr, snc->_val); break; - case SNSETX0 : + case kSnSetX0: _vm->snSetX0(snc->_ref, snc->_val); break; - case SNSETY0 : + case kSnSetY0: _vm->snSetY0(snc->_ref, snc->_val); break; - case SNSETXY : + case kSnSetXY: _vm->snSetXY(spr, snc->_val); break; - case SNRELX : + case kSnRelX: _vm->snRelX(spr, snc->_val); break; - case SNRELY : + case kSnRelY: _vm->snRelY(spr, snc->_val); break; - case SNRELZ : + case kSnRelZ: _vm->snRelZ(spr, snc->_val); break; - case SNSETX : + case kSnSetX: _vm->snSetX(spr, snc->_val); break; - case SNSETY : + case kSnSetY: _vm->snSetY(spr, snc->_val); break; - case SNSETZ : + case kSnSetZ: _vm->snSetZ(spr, snc->_val); break; - case SNSLAVE : + case kSnSlave: _vm->snSlave(spr, snc->_val); break; - case SNTRANS : + case kSnTrans: _vm->snTrans(spr, snc->_val); break; - case SNPORT : + case kSnPort: _vm->snPort(spr, snc->_val); break; - case SNNEXT : - case SNIF : - case SNTALK : + case kSnNext: + case kSnIf: + case kSnTalk: break; - case SNMOUSE : + case kSnMouse: _vm->snMouse(snc->_val != 0); break; - case SNNNEXT : + case kSnNNext: _vm->snNNext(spr, snc->_val); break; - case SNTNEXT : + case kSnTNext: _vm->snTNext(spr, snc->_val); break; - case SNRNNEXT : + case kSnRNNext: _vm->snRNNext(spr, snc->_val); break; - case SNRTNEXT : + case kSnRTNext: _vm->snRTNext(spr, snc->_val); break; - case SNRMNEAR : + case kSnRMNear: _vm->snRmNear(spr); break; - case SNRMTAKE : + case kSnRmTake: _vm->snRmTake(spr); break; - case SNFLAG : + case kSnFlag: _vm->snFlag(snc->_ref & 3, snc->_val != 0); break; - case SNSETREF : + case kSnSetRef: _vm->snSetRef(spr, snc->_val); break; - case SNBACKPT : + case kSnBackPt: _vm->snBackPt(spr, snc->_val); break; - case SNFLASH : + case kSnFlash: _vm->snFlash(snc->_val != 0); break; - case SNLIGHT : + case kSnLight: _vm->snLight(snc->_val != 0); break; - case SNSETHB : + case kSnSetHBarrier: _vm->snBarrier(snc->_ref, snc->_val, true); break; - case SNSETVB : + case kSnSetVBarrier: _vm->snBarrier(snc->_ref, snc->_val, false); break; - case SNWALK : + case kSnWalk: _vm->snWalk(spr, snc->_ref, snc->_val); break; - case SNREACH : + case kSnReach: _vm->snReach(spr, snc->_val); break; - case SNSOUND : + case kSnSound: _vm->snSound(spr, snc->_val, count); count = 1; break; - case SNCOUNT : + case kSnCount: count = snc->_val; break; - case SNEXEC : + case kSnExec: switch (snc->_cbType) { case kQGame: _vm->qGame(); @@ -1176,13 +1169,13 @@ void Snail::runCom() { error("Unknown Callback Type in SNEXEC"); } break; - case SNSTEP : + case kSnStep: spr->step(); break; - case SNZTRIM : + case kSnZTrim: _vm->snZTrim(spr); break; - case SNGHOST : + case kSnGhost: _vm->snGhost((Bitmap *) snc->_ptr); break; default : diff --git a/engines/cge/snail.h b/engines/cge/snail.h index b8b4dc68ffe..ad63f55f36b 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -33,40 +33,34 @@ namespace CGE { -#define SNINSERT(c, r, v, p) _snail->insCom(c, r, v, p) -#define SNPOST(c, r, v, p) _snail->addCom(c, r, v, p) -#define SNPOST2(c, r, v, p) _snail->addCom2(c, r, v, p) -#define SNPOST_(c, r, v, p) _snail_->addCom(c, r, v, p) -#define SNPOST2_(c, r, v, p) _snail_->addCom2(c, r, v, p) - -#define SNAIL_FRAME_RATE 80 -#define SNAIL_FRAME_DELAY (1000 / SNAIL_FRAME_RATE) +#define kSnailFrameRate 80 +#define kSnailFrameDelay (1000 / kSnailFrameRate) +#define kDressed 3 struct Bar { uint8 _horz; uint8 _vert; }; - -enum SNCOM { - SNLABEL, SNPAUSE, SNWAIT, SNLEVEL, SNHIDE, - SNSAY, SNINF, SNTIME, SNCAVE, SNKILL, - SNRSEQ, SNSEQ, SNSEND, SNSWAP, SNKEEP, - SNGIVE, SNIF, SNGAME, SNSETX0, SNSETY0, - SNSLAVE, SNSETXY, SNRELX, SNRELY, SNRELZ, - SNSETX, SNSETY, SNSETZ, SNTRANS, SNPORT, - SNNEXT, SNNNEXT, SNTNEXT, SNRNNEXT, SNRTNEXT, - SNRMNEAR, SNRMTAKE, SNFLAG, SNSETREF, SNBACKPT, - SNFLASH, SNLIGHT, SNSETHB, SNSETVB, SNWALK, - SNREACH, SNCOVER, SNUNCOVER, SNCLEAR, SNTALK, - SNMOUSE, SNSOUND, SNCOUNT, SNEXEC, SNSTEP, - SNZTRIM, SNGHOST +enum SnCom { + kSnLabel, kSnPause, kSnWait, kSnLevel, kSnHide, + kSnSay, kSnInf, kSnTime, kSnCave, kSnKill, + kSnRSeq, kSnSeq, kSnSend, kSnSwap, kSnKeep, + kSnGive, kSnIf, kSnGame, kSnSetX0, kSnSetY0, + kSnSlave, kSnSetXY, kSnRelX, kSnRelY, kSnRelZ, + kSnSetX, kSnSetY, kSnSetZ, kSnTrans, kSnPort, + kSnNext, kSnNNext, kSnTNext, kSnRNNext, kSnRTNext, + kSnRMNear, kSnRmTake, kSnFlag, kSnSetRef, kSnBackPt, + kSnFlash, kSnLight, kSnSetHBarrier, kSnSetVBarrier, kSnWalk, + kSnReach, kSnCover, kSnUncover, kSnClear, kSnTalk, + kSnMouse, kSnSound, kSnCount, kSnExec, kSnStep, + kSnZTrim, kSnGhost }; class Snail { public: struct Com { - SNCOM _com; + SnCom _com; int _ref; int _val; void *_ptr; @@ -83,17 +77,15 @@ public: Snail(CGEEngine *vm, bool turbo); ~Snail(); void runCom(); - void addCom(SNCOM com, int ref, int val, void *ptr); - void addCom2(SNCOM com, int ref, int val, CallbackType cbType); - void insCom(SNCOM com, int ref, int val, void *ptr); + void addCom(SnCom com, int ref, int val, void *ptr); + void addCom2(SnCom com, int ref, int val, CallbackType cbType); + void insCom(SnCom com, int ref, int val, void *ptr); bool idle(); private: CGEEngine *_vm; }; -extern bool _dark; -extern int _lev; extern Bar _barriers[]; extern struct Hxy { int _x; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index dd75ea3681b..edf7931278a 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -234,7 +234,6 @@ void CGEEngine::inf(const char *txt) { } } - void sayTime(Sprite *spr) { /* static char t[] = "00:00"; @@ -249,7 +248,7 @@ void sayTime(Sprite *spr) { void killText() { if (_talk) { - SNPOST_(SNKILL, -1, 0, _talk); + _snail_->addCom(kSnKill, -1, 0, _talk); _talk = NULL; } } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 24c83f12ee1..94a4963a5e6 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -442,7 +442,7 @@ bool Sprite::works(Sprite *spr) { if (c != NULL) { c += spr->_takePtr; if (c->_ref == _ref) - if (c->_com != SNLABEL || (c->_val == 0 || c->_val == _vm->_now)) + if (c->_com != kSnLabel || (c->_val == 0 || c->_val == _vm->_now)) return true; } } @@ -573,7 +573,7 @@ Sprite *Sprite::expand() { error("No core [%s]", fname); else { Snail::Com *c = &nea[neacnt++]; - if ((c->_com = (SNCOM)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) + if ((c->_com = (SnCom)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) error("Bad NEAR in %d [%s]", lcnt, fname); c->_ref = atoi(strtok(NULL, " \t,;/")); c->_val = atoi(strtok(NULL, " \t,;/")); @@ -589,7 +589,7 @@ Sprite *Sprite::expand() { error("No core [%s]", fname); else { Snail::Com *c = &tak[takcnt++]; - if ((c->_com = (SNCOM)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) + if ((c->_com = (SnCom)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) error("Bad NEAR in %d [%s]", lcnt, fname); c->_ref = atoi(strtok(NULL, " \t,;/")); c->_val = atoi(strtok(NULL, " \t,;/")); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index af3d5ff4f5a..2c22625ae3a 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -138,7 +138,7 @@ void Vmenu::touch(uint16 mask, int x, int y) { if (ok && (mask & L_UP)) { _items = 0; - SNPOST_(SNKILL, -1, 0, this); + _snail_->addCom(kSnKill, -1, 0, this); _recent = n; assert(_menu[n].Proc); CALL_MEMBER_FN(*_vm, _menu[n].Proc)(); diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 63f3fadd1c6..9074a8f0616 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -44,7 +44,7 @@ Dat::Dat(): #ifdef VOL_UPD _file(DAT_NAME, UPD, CRP) #else - _file(DAT_NAME, REA, CRP) + _file(DAT_NAME, kModeRead, CRP) #endif { debugC(1, kCGEDebugFile, "Dat::Dat()"); @@ -59,7 +59,7 @@ void VFile::init() { #ifdef VOL_UPD _cat = new BtFile(CAT_NAME, UPD, CRP); #else - _cat = new BtFile(CAT_NAME, REA, CRP); + _cat = new BtFile(CAT_NAME, kModeRead, CRP); #endif _recent = NULL; @@ -70,11 +70,11 @@ void VFile::deinit() { delete _cat; } -VFile::VFile(const char *name, IOMODE mode) +VFile::VFile(const char *name, IOMode mode) : IoBuf(mode) { debugC(3, kCGEDebugFile, "VFile::VFile(%s, %d)", name, mode); - if (mode == REA) { + if (mode == kModeRead) { if (_dat->_file._error || _cat->_error) error("Bad volume data"); BtKeypack *kp = _cat->find(name); diff --git a/engines/cge/vol.h b/engines/cge/vol.h index bbf3237721f..e975cc34e60 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -74,7 +74,7 @@ private: void writeBuf() { } void make(const char *fspec); public: - VFile(const char *name, IOMODE mode = REA); + VFile(const char *name, IOMode mode = kModeRead); ~VFile(); static void init(); diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 2568a51df0c..f9c542ec925 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -136,7 +136,7 @@ void WALK::tick() { else { signed char x; // dummy var _here.split(x, _z); // take current Z position - SNPOST_(SNZTRIM, -1, 0, this); // update Hero's pos in show queue + _snail_->addCom(kSnZTrim, -1, 0, this); // update Hero's pos in show queue } } @@ -233,10 +233,10 @@ void WALK::reach(Sprite *spr, int mode) { } } // note: insert SNAIL commands in reverse order - SNINSERT(SNPAUSE, -1, 64, NULL); - SNINSERT(SNSEQ, -1, kTSeq + mode, this); + _snail->insCom(kSnPause, -1, 64, NULL); + _snail->insCom(kSnSeq, -1, kTSeq + mode, this); if (spr) { - SNINSERT(SNWAIT, -1, -1, _hero); /////--------$$$$$$$ + _snail->insCom(kSnWait, -1, -1, _hero); /////--------$$$$$$$ //SNINSERT(SNWALK, -1, -1, spr); } // sequence is not finished, From 82adc025ea451f1fce2c0e0eed03d6e48a51e152 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 24 Jul 2011 23:42:03 +0200 Subject: [PATCH 162/276] CGE: Remove DrvInfo, rename some enums --- engines/cge/cge_main.cpp | 25 +++++++++++++----------- engines/cge/cge_main.h | 3 +++ engines/cge/general.cpp | 2 -- engines/cge/gettext.cpp | 2 +- engines/cge/mixer.cpp | 13 ++++++++++--- engines/cge/snail.cpp | 10 ++++------ engines/cge/snddrv.h | 36 ---------------------------------- engines/cge/sound.h | 4 ---- engines/cge/talk.cpp | 13 +++++-------- engines/cge/talk.h | 17 ++++------------ engines/cge/text.cpp | 4 ++-- engines/cge/vga13h.cpp | 5 ----- engines/cge/vga13h.h | 10 +++++----- engines/cge/vmenu.cpp | 2 +- engines/cge/vol.h | 2 -- engines/cge/walk.cpp | 42 ++++++++++++---------------------------- engines/cge/walk.h | 6 +++--- 17 files changed, 64 insertions(+), 132 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index b6f342edfff..98de57597d9 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -317,8 +317,11 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt _pocref[i] = (s) ? s->_ref : -1; } - _volume[0] = _sndDrvInfo.Vol2._d; - _volume[1] = _sndDrvInfo.Vol2._m; + warning("STUB: CGEEngine::syncGame Digital and Midi volume"); +// _volume[0] = _sndDrvInfo.Vol2._d; +// _volume[1] = _sndDrvInfo.Vol2._m; + _volume[0] = 0; + _volume[1] = 0; } // Synchronise header data @@ -336,8 +339,9 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt _music = false; if (Startup::_soundOk == 1 && Startup::_mode == 0) { - _sndDrvInfo.Vol2._d = _volume[0]; - _sndDrvInfo.Vol2._m = _volume[1]; +// _sndDrvInfo.Vol2._d = _volume[0]; +// _sndDrvInfo.Vol2._m = _volume[1]; + warning("STUB: CGEEngine::syncGame Digital and Midi volume"); sndSetVolume(); } @@ -587,12 +591,11 @@ void CGEEngine::caveUp() { } spr = n; } - if (_sndDrvInfo._dDev) { - _sound.stop(); - _fx.clear(); - _fx.preload(0); - _fx.preload(BakRef); - } + + _sound.stop(); + _fx.clear(); + _fx.preload(0); + _fx.preload(BakRef); if (_hero) { _hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); @@ -1265,7 +1268,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int break; } case 2 : { // WALK - WALK *w = new WALK(this, NULL); + Walk *w = new Walk(this, NULL); if (w && ref == 1) { w->gotoxy(col, row); if (_hero) diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 2a467761b31..8586d84d50d 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -72,6 +72,9 @@ namespace CGE { #define kGetNamePrompt 50 #define kGetNameTitle 51 #define kTSeq 96 +//Useless? +//#define kBadSnd 97 +//#define kBadMidi 98 #define kNoMusic 98 #define kBadSVG 99 #define kSeqHTalk (kTSeq + 4) diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 909c517c32c..46df263b93d 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -93,8 +93,6 @@ Dac _stdPal[] = {// R G B { 255, 255, 255}, // 255 }; -DrvInfo _sndDrvInfo; - void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)) { warning("STUB: _fqsort"); } diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 7a8cff3cb2c..fa30b3a9d1c 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -39,7 +39,7 @@ GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) _cntr(kGetTextBlink), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { int i = 2 * kTextHMargin + _font->width(info); _ptr = this; - _mode = RECT; + _mode = kTBRect; _ts = new BMP_PTR[2]; _ts[0] = box((i + 3) & ~3, 2 * kTextVMargin + 2 * kFontHigh + kTextLineSpace); diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index aeaaa86593b..36f7a8e2f7d 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -86,12 +86,14 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _ _vga->_showQ->insert(_led[i]); //--- reset balance - i = (_sndDrvInfo.Vol4._ml + _sndDrvInfo.Vol4._mr) / 2; + warning("STUB: MIXER::MIXER() reset balance of digital and midi volumes"); +/* i = (_sndDrvInfo.Vol4._ml + _sndDrvInfo.Vol4._mr) / 2; _sndDrvInfo.Vol4._ml = i; _sndDrvInfo.Vol4._mr = i; i = (_sndDrvInfo.Vol4._dl + _sndDrvInfo.Vol4._dr) / 2; _sndDrvInfo.Vol4._dl = i; _sndDrvInfo.Vol4._dr = i; +*/ update(); _time = kMixDelay; } @@ -104,8 +106,10 @@ Mixer::~Mixer() { #pragma argsused void Mixer::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); + if (mask & L_UP) { - uint8 *vol = (&_sndDrvInfo.Vol2._d) + (x < _w / 2); + warning("STUB: Mixer::touch(): Digital Volume"); +/* uint8 *vol = (&_sndDrvInfo.Vol2._d) + (x < _w / 2); if (y < kMixButtonHigh) { if (*vol < 0xFF) *vol += 0x11; @@ -114,6 +118,7 @@ void Mixer::touch(uint16 mask, int x, int y) { *vol -= 0x11; } update(); +*/ } } @@ -139,9 +144,11 @@ void Mixer::tick() { void Mixer::update() { + warning("STUB: Mixer::Update"); +/* _led[0]->step(_sndDrvInfo.Vol4._ml); _led[1]->step(_sndDrvInfo.Vol4._dl); - +*/ _snail_->addCom2(kSnExec, -1, 0, kSndSetVolume); } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index d2ed77d7555..697e70bf8ec 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -797,12 +797,10 @@ void CGEEngine::snKill(Sprite *spr) { void CGEEngine::snSound(Sprite *spr, int wav, int cnt) { debugC(1, kCGEDebugEngine, "CGEEngine::snSound(spr, %d, %d)", wav, cnt); - if (_sndDrvInfo._dDev) { - if (wav == -1) - _sound.stop(); - else - _sound.play(_fx[wav], (spr) ? ((spr->_x + spr->_w / 2) / (kScrWidth / 16)) : 8, cnt); - } + if (wav == -1) + _sound.stop(); + else + _sound.play(_fx[wav], (spr) ? ((spr->_x + spr->_w / 2) / (kScrWidth / 16)) : 8, cnt); } diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 0ea776b7848..07c4ccd0dd8 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -42,40 +42,6 @@ namespace CGE { // ****************************************************** // * Constants * // ****************************************************** -// available devices - -enum DEV_TYPE { DEV_AUTO = -1, // auto-detect mode - DEV_QUIET, // disable sound - DEV_SB, // sb/pro/16/awe32 - DEV_GUS, // gus/max - DEV_GM // general midi - }; - -#define SERR_OK 0 // no error -#define SERR_INITFAIL 1 // couldn't initialize -#define SERR_BADDDEV 128 // bad device - -// driver info -struct DrvInfo { - DEV_TYPE _dDev; // digi device - DEV_TYPE _mDev; // midi device - uint16 _dBase; // digi base port - uint16 _dDma; // digi dma no - uint16 _dIrq; // digi irq no - uint16 _mBase; // midi base port - union { - struct { - uint16 _dr : 4; - uint16 _dl : 4; - uint16 _mr : 4; - uint16 _ml : 4; - } Vol4; - struct { - uint8 _d; // digi volume - uint8 _m; // midi volume - } Vol2; - }; -}; // sample info struct SmpInfo { @@ -88,8 +54,6 @@ struct SmpInfo { // ****************************************************** // * Data * // ****************************************************** -// driver info -extern DrvInfo _sndDrvInfo; // midi player flag (1 means we are playing) extern uint16 _midiPlayFlag; diff --git a/engines/cge/sound.h b/engines/cge/sound.h index fda8d4f1282..5e1af713074 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -33,10 +33,6 @@ namespace CGE { -#define BAD_SND_TEXT 97 -#define BAD_MIDI_TEXT 98 - - class Sound { public: SmpInfo _smpinf; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index a164a69f998..4e367e33181 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -87,7 +87,7 @@ void Font::save() { */ -Talk::Talk(CGEEngine *vm, const char *tx, TBOX_STYLE mode) +Talk::Talk(CGEEngine *vm, const char *tx, TextBoxStyle mode) : Sprite(vm, NULL), _mode(mode), _vm(vm) { _ts = NULL; @@ -97,7 +97,7 @@ Talk::Talk(CGEEngine *vm, const char *tx, TBOX_STYLE mode) Talk::Talk(CGEEngine *vm) - : Sprite(vm, NULL), _mode(PURE), _vm(vm) { + : Sprite(vm, NULL), _mode(kTBPure), _vm(vm) { _ts = NULL; _flags._syst = true; } @@ -179,20 +179,17 @@ void Talk::update(const char *tx) { setShapeList(_ts); } - - - Bitmap *Talk::box(uint16 w, uint16 h) { uint8 *b, * p, * q; - uint16 n, r = (_mode == ROUND) ? kTextRoundCorner : 0; + uint16 r = (_mode == kTBRound) ? kTextRoundCorner : 0; if (w < 8) w = 8; if (h < 8) h = 8; - n = w * h; + uint16 n = w * h; b = (uint8 *) malloc(sizeof(uint8) * n); - if (! b) + if (!b) error("No core"); memset(b, kTextColBG, n); diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 5eab6672e36..d9c29261f6c 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -46,18 +46,14 @@ namespace CGE { #define kFontHigh 8 #define kFontExt ".CFT" - - - #define kPathMax 128 +enum TextBoxStyle { kTBPure, kTBRect, kTBRound }; + class Font { char _path[kPathMax]; void load(); public: -// static uint8 _wid[256]; -// static uint16 _pos[256]; -// static uint8 _map[256*8]; uint8 *_wid; uint16 *_pos; uint8 *_map; @@ -67,17 +63,13 @@ public: void save(); }; - -enum TBOX_STYLE { PURE, RECT, ROUND }; - - class Talk : public Sprite { protected: - TBOX_STYLE _mode; + TextBoxStyle _mode; BMP_PTR *_ts; Bitmap *box(uint16 w, uint16 h); public: - Talk(CGEEngine *vm, const char *tx, TBOX_STYLE mode); + Talk(CGEEngine *vm, const char *tx, TextBoxStyle mode); Talk(CGEEngine *vm); //~TALK(); @@ -92,7 +84,6 @@ private: CGEEngine *_vm; }; - class InfoLine : public Talk { const char *_oldTxt; public: diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index edf7931278a..f688546810d 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -178,7 +178,7 @@ char *Text::getText(int ref) { void Text::say(const char *txt, Sprite *spr) { killText(); - _talk = new Talk(_vm, txt, ROUND); + _talk = new Talk(_vm, txt, kTBRound); if (_talk) { bool east = spr->_flags._east; int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2); @@ -221,7 +221,7 @@ void CGEEngine::inf(const char *txt) { debugC(1, kCGEDebugEngine, "CGEEngine::inf(%s)", txt); killText(); - _talk = new Talk(this, txt, RECT); + _talk = new Talk(this, txt, kTBRect); if (_talk) { _talk->_flags._kill = true; _talk->_flags._bDel = true; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 94a4963a5e6..f5a3fdd22f6 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -37,11 +37,6 @@ namespace CGE { -#define FADE_STEP 2 -#define TMR_DIV ((0x8000/TMR_RATE)*2) -#define NREP 9 -#define FREP 24 - static VgaRegBlk VideoMode[] = { { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 4884ae104e7..f192d962ffc 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -37,6 +37,11 @@ namespace CGE { +#define FADE_STEP 2 +#define TMR_DIV ((0x8000/TMR_RATE)*2) +#define NREP 9 +#define FREP 24 + #define TMR_RATE1 16 #define TMR_RATE2 4 #define TMR_RATE (TMR_RATE1 * TMR_RATE2) @@ -60,11 +65,6 @@ namespace CGE { #define SPR_EXT ".SPR" -#define IsFile(s) (access(s, 0) == 0) -#define IsWrit(s) (access(s, 2) == 0) - - - struct Rgb { uint16 _r : 2; uint16 _R : 6; diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 2c22625ae3a..f846b3d061e 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -90,7 +90,7 @@ int Vmenu::_recent = -1; Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y) - : Talk(vm, VMGather(list), RECT), _menu(list), _bar(NULL), _vm(vm) { + : Talk(vm, VMGather(list), kTBRect), _menu(list), _bar(NULL), _vm(vm) { Choice *cp; _addr = this; diff --git a/engines/cge/vol.h b/engines/cge/vol.h index e975cc34e60..f64e7eec54e 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -36,9 +36,7 @@ namespace CGE { #define CAT_NAME "VOL.CAT" #define DAT_NAME "VOL.DAT" -#ifndef CRP #define CRP XCrypt -#endif #define XMASK 0xA5 diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index f9c542ec925..9bcc2be23d1 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -25,32 +25,14 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#include "common/scummsys.h" #include "cge/walk.h" -#include "cge/cge.h" -#include "cge/sound.h" -#include "cge/startup.h" -#include "cge/config.h" -#include "cge/vga13h.h" -#include "cge/snail.h" -#include "cge/text.h" -#include "cge/game.h" -#include "cge/events.h" -#include "cge/cfile.h" -#include "cge/vol.h" -#include "cge/talk.h" -#include "cge/vmenu.h" -#include "cge/gettext.h" -#include "cge/mixer.h" #include "cge/cge_main.h" -#include "cge/cge.h" -#include "common/str.h" namespace CGE { extern Bar _barriers[]; -WALK *_hero; +Walk *_hero; uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; CGEEngine *Cluster::_vm; @@ -89,12 +71,12 @@ Cluster XZ(Couple xy) { return XZ(x, y); } -WALK::WALK(CGEEngine *vm, BMP_PTR *shpl) +Walk::Walk(CGEEngine *vm, BMP_PTR *shpl) : Sprite(vm, shpl), Dir(NO_DIR), _tracePtr(-1), _level(0), _vm(vm) { } -void WALK::tick() { +void Walk::tick() { if (_flags._hide) return; @@ -141,7 +123,7 @@ void WALK::tick() { } -int WALK::distance(Sprite *spr) { +int Walk::distance(Sprite *spr) { int dx, dz; dx = spr->_x - (_x + _w - kWalkSide); if (dx < 0) @@ -163,7 +145,7 @@ int WALK::distance(Sprite *spr) { } -void WALK::turn(DIR d) { +void Walk::turn(DIR d) { DIR dir = (Dir == NO_DIR) ? SS : Dir; if (d != Dir) { step((d == dir) ? (1 + dir + dir) : (9 + 4 * dir + d)); @@ -172,7 +154,7 @@ void WALK::turn(DIR d) { } -void WALK::park() { +void Walk::park() { if (_time == 0) ++_time; @@ -184,7 +166,7 @@ void WALK::park() { } -void WALK::findWay(Cluster c) { +void Walk::findWay(Cluster c) { if (c != _here) { for (_findLevel = 1; _findLevel <= MAX_FIND_LEVEL; _findLevel++) { signed char x, z; @@ -203,7 +185,7 @@ void WALK::findWay(Cluster c) { } -void WALK::findWay(Sprite *spr) { +void Walk::findWay(Sprite *spr) { if (spr && spr != this) { int x = spr->_x; int z = spr->_z; @@ -218,12 +200,12 @@ void WALK::findWay(Sprite *spr) { } -bool WALK::lower(Sprite *spr) { +bool Walk::lower(Sprite *spr) { return (spr->_y > _y + (_h * 3) / 5); } -void WALK::reach(Sprite *spr, int mode) { +void Walk::reach(Sprite *spr, int mode) { if (spr) { _hero->findWay(spr); if (mode < 0) { @@ -243,11 +225,11 @@ void WALK::reach(Sprite *spr, int mode) { // now it is just at sprite appear (disappear) point } -void WALK::noWay() { +void Walk::noWay() { _vm->trouble(kSeqNoWay, kNoWay); } -bool WALK::find1Way(Cluster c) { +bool Walk::find1Way(Cluster c) { Cluster start = c; const Cluster tab[4] = { Cluster(-1, 0), Cluster(1, 0), Cluster(0, -1), Cluster(0, 1)}; const int tabLen = 4; diff --git a/engines/cge/walk.h b/engines/cge/walk.h index 52f372c363a..15ea9ee0cec 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -97,7 +97,7 @@ public: }; -class WALK : public Sprite { +class Walk : public Sprite { private: CGEEngine *_vm; public: @@ -109,7 +109,7 @@ public: Cluster _trace[MAX_FIND_LEVEL]; enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; - WALK(CGEEngine *vm, BMP_PTR *shpl); + Walk(CGEEngine *vm, BMP_PTR *shpl); void tick(); void findWay(Cluster c); void findWay(Sprite *spr); @@ -126,7 +126,7 @@ public: Cluster XZ(int x, int y); Cluster XZ(Couple xy); -extern WALK *_hero; +extern Walk *_hero; } // End of namespace CGE From cf619196484d7edc11dc6908ab81ebafcb65405f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 25 Jul 2011 16:04:45 +0200 Subject: [PATCH 163/276] CGE: Replace 'no core' checks by asserts --- engines/cge/bitmap.cpp | 16 ++++------- engines/cge/btfile.cpp | 3 +- engines/cge/cfile.cpp | 6 ++-- engines/cge/cge_main.cpp | 11 ++++---- engines/cge/talk.cpp | 6 ++-- engines/cge/vga13h.cpp | 59 +++++++++++++++++----------------------- 6 files changed, 41 insertions(+), 60 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 023e95a8f1d..c02c66df8b3 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -104,8 +104,7 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) uint16 psiz = _h * lsiz; // - last gape, but + plane trailer uint8 *v = new uint8[4 * psiz + _h * sizeof(*_b)];// the same for 4 planes // + room for wash table - if (v == NULL) - error("No core"); + assert(v != NULL); *(uint16 *) v = kBmpCPY | dsiz; // data chunk hader memset(v + 2, fill, dsiz); // data bytes @@ -143,8 +142,7 @@ Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); uint16 siz = vsiz + _h * sizeof(HideDesc); uint8 *v1 = (uint8 *) malloc(sizeof(uint8) * siz); - if (v1 == NULL) - error("No core"); + assert(v1 != NULL); memcpy(v1, v0, siz); _b = (HideDesc *)((_v = v1) + vsiz); } @@ -174,8 +172,7 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { uint16 vsiz = (uint8 *)bmp._b - (uint8 *)v0; uint16 siz = vsiz + _h * sizeof(HideDesc); uint8 *v1 = (uint8 *) malloc(sizeof(uint8) * siz); - if (v1 == NULL) - error("No core"); + assert(v1 != NULL); memcpy(v1, v0, siz); _b = (HideDesc *)((_v = v1) + vsiz); } @@ -252,9 +249,9 @@ BMP_PTR Bitmap::code() { if (! skip) { if (_v) *im = pix; - ++ im; + im++; } - ++ cnt; + cnt++; } bm += _w; @@ -291,8 +288,7 @@ BMP_PTR Bitmap::code() { uint16 sizV = (uint16)(im - 2 - _v); _v = new uint8[sizV + _h * sizeof(*_b)]; - if (!_v) - error("No core"); + assert(_v != NULL); _b = (HideDesc *)(_v + sizV); } diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index d5cdef1ba0f..55511e63822 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -43,8 +43,7 @@ BtFile::BtFile(const char *name, IOMode mode, CRYPT *crpt) _buff[i]._pgNo = kBtValNone; _buff[i]._indx = -1; _buff[i]._updt = false; - if (_buff[i]._page == NULL) - error("No core"); + assert(_buff[i]._page != NULL); } } diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 1c5cf1d3588..ac9f782d840 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -41,8 +41,7 @@ IoBuf::IoBuf(IOMode mode, CRYPT *crpt) debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%d, crpt)", mode); _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); - if (_buff == NULL) - error("No core for I/O"); + assert(_buff != NULL); } @@ -54,8 +53,7 @@ IoBuf::IoBuf(const char *name, IOMode mode, CRYPT *crpt) debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%s, %d, crpt)", name, mode); _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); - if (_buff == NULL) - error("No core for I/O [%s]", name); + assert(_buff != NULL); } IoBuf::~IoBuf() { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 98de57597d9..352d2954dca 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -353,8 +353,7 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt S._prev = S._next = NULL; spr = (scumm_stricmp(S._file + 2, "MUCHA") == 0) ? new Fly(this, NULL) : new Sprite(this, NULL); - if (spr == NULL) - error("No core"); + assert(spr != NULL); *spr = S; _vga->_spareQ->append(spr); } @@ -1075,7 +1074,7 @@ void CGEEngine::sayDebug() { uint16 n = 0; Sprite *spr; for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { - ++ n; + n++; if (spr == _sprite) { dwtom(n, SP_N, 10, 2); dwtom(_sprite->_x, SP_X, 10, 3); @@ -1220,9 +1219,9 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int error("Bad SPR [%s]", line); while ((len = sprf.read((uint8 *)line)) != 0) { - ++ lcnt; + lcnt++; if (len && line[len - 1] == '\n') - line[-- len] = '\0'; + line[--len] = '\0'; if (len == 0 || *line == '.') continue; @@ -1238,7 +1237,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int error("Bad line %d [%s]", lcnt, fname); break; case 2 : // Phase - ++ shpcnt; + shpcnt++; break; case 3 : // East east = (atoi(strtok(NULL, " \t,;/")) != 0); diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 4e367e33181..4a2df79f24e 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -36,8 +36,7 @@ Font::Font(const char *name) { _map = (uint8 *) malloc(sizeof(uint8) * kMapSize); _pos = (uint16 *) malloc(sizeof(uint16) * kPosSize); _wid = (uint8 *) malloc(sizeof(uint8) * kWidSize); - if ((_map == NULL) || (_pos == NULL) || (_wid == NULL)) - error("No core"); + assert((_map != NULL) && (_pos != NULL) && (_wid != NULL)); mergeExt(_path, name, kFontExt); load(); } @@ -189,8 +188,7 @@ Bitmap *Talk::box(uint16 w, uint16 h) { h = 8; uint16 n = w * h; b = (uint8 *) malloc(sizeof(uint8) * n); - if (!b) - error("No core"); + assert(b != NULL); memset(b, kTextColBG, n); if (_mode) { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index f5a3fdd22f6..d08f9bc8e83 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -486,10 +486,9 @@ void Sprite::setName(char *n) { _ext->_name = NULL; } if (n) { - if ((_ext->_name = new char[strlen(n) + 1]) != NULL) - strcpy(_ext->_name, n); - else - error("No core [%s]", n); + _ext->_name = new char[strlen(n) + 1]; + assert(_ext->_name != NULL); + strcpy(_ext->_name, n); } } } @@ -499,8 +498,8 @@ Sprite *Sprite::expand() { if (!_ext) { bool enbl = _heart->_enable; _heart->_enable = false; - if ((_ext = new SprExt) == NULL) - error("No core"); + _ext = new SprExt; + assert(_ext != NULL); if (*_file) { static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; char line[kLineMax], fname[kPathMax]; @@ -522,9 +521,9 @@ Sprite *Sprite::expand() { error("Bad SPR [%s]", fname); int len = 0, lcnt = 0; while ((len = sprf.read((uint8 *)line)) != 0) { - ++lcnt; + lcnt++; if (len && line[len - 1] == '\n') - line[-- len] = '\0'; + line[--len] = '\0'; if (len == 0 || *line == '.') continue; @@ -539,8 +538,7 @@ Sprite *Sprite::expand() { } case 2 : { // Seq seq = (Seq *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); - if (seq == NULL) - error("No core [%s]", fname); + assert(seq != NULL); Seq *s = &seq[seqcnt++]; s->_now = atoi(strtok(NULL, " \t,;/")); if (s->_now > maxnow) @@ -564,32 +562,26 @@ Sprite *Sprite::expand() { case 3 : { // Near if (_nearPtr != NO_PTR) { nea = (Snail::Com *) realloc(nea, (neacnt + 1) * sizeof(*nea)); - if (nea == NULL) - error("No core [%s]", fname); - else { - Snail::Com *c = &nea[neacnt++]; - if ((c->_com = (SnCom)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) - error("Bad NEAR in %d [%s]", lcnt, fname); - c->_ref = atoi(strtok(NULL, " \t,;/")); - c->_val = atoi(strtok(NULL, " \t,;/")); - c->_ptr = NULL; - } + assert(nea != NULL); + Snail::Com *c = &nea[neacnt++]; + if ((c->_com = (SnCom)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) + error("Bad NEAR in %d [%s]", lcnt, fname); + c->_ref = atoi(strtok(NULL, " \t,;/")); + c->_val = atoi(strtok(NULL, " \t,;/")); + c->_ptr = NULL; } } break; case 4 : { // Take if (_takePtr != NO_PTR) { tak = (Snail::Com *) realloc(tak, (takcnt + 1) * sizeof(*tak)); - if (tak == NULL) - error("No core [%s]", fname); - else { - Snail::Com *c = &tak[takcnt++]; - if ((c->_com = (SnCom)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) - error("Bad NEAR in %d [%s]", lcnt, fname); - c->_ref = atoi(strtok(NULL, " \t,;/")); - c->_val = atoi(strtok(NULL, " \t,;/")); - c->_ptr = NULL; - } + assert(tak != NULL); + Snail::Com *c = &tak[takcnt++]; + if ((c->_com = (SnCom)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) + error("Bad NEAR in %d [%s]", lcnt, fname); + c->_ref = atoi(strtok(NULL, " \t,;/")); + c->_val = atoi(strtok(NULL, " \t,;/")); + c->_ptr = NULL; } break; } @@ -774,12 +766,11 @@ BMP_PTR Sprite::ghost() { register SprExt *e = _ext; if (e->_b1) { BMP_PTR bmp = new Bitmap(0, 0, (uint8 *)NULL); - if (bmp == NULL) - error("No core"); + assert(bmp != NULL); bmp->_w = e->_b1->_w; bmp->_h = e->_b1->_h; - if ((bmp->_b = new HideDesc[bmp->_h]) == NULL) - error("No Core"); + bmp->_b = new HideDesc[bmp->_h]; + assert(bmp->_b != NULL); bmp->_v = (uint8 *) memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc) * bmp->_h); bmp->_map = (e->_y1 << 16) + e->_x1; return bmp; From 2e5a041046f69378da87fb8cab805fdee31a01e2 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 25 Jul 2011 17:50:58 +0200 Subject: [PATCH 164/276] CGE: Remove EMM and EMS classes --- engines/cge/cge_main.cpp | 2 +- engines/cge/ems.cpp | 190 --------------------------------------- engines/cge/general.cpp | 2 +- engines/cge/general.h | 34 ------- engines/cge/module.mk | 1 - engines/cge/sound.cpp | 9 +- engines/cge/sound.h | 1 - engines/cge/startup.h | 2 - engines/cge/wav.h | 11 +-- 9 files changed, 8 insertions(+), 244 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 352d2954dca..60500b2b0e3 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -540,7 +540,7 @@ void CGEEngine::miniStep(int stp) { else { *_miniShp[0] = *_miniShpList[stp]; if (_fx._current) - &*(_fx._current->eAddr()); + &*(_fx._current->addr()); _miniCave->_flags._hide = false; } diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp index 0364758a123..f545822a6b7 100644 --- a/engines/cge/ems.cpp +++ b/engines/cge/ems.cpp @@ -28,194 +28,4 @@ #include "cge/general.h" namespace CGE { - - -enum EMM_FUN { - GET_STATUS = 0x40, GET_FRAME, GET_SIZE, OPEN_HANDLE, MAP_PAGE, - CLOSE_HANDLE, GET_VER, SAVE_CONTEXT, REST_CONTEXT, GET_PAGES = 0x4B, - GET_HANDLES, GET_INFO, CONTROL -}; - - -void *Emm::_frame = NULL; - - -Emm::Emm(long size): _han(-1), _top(0), _lim(0), _list(NULL) { - /* - if (Test()) - { - asm mov ah,GET_FRAME // get EMS frame segment - asm int EMS_INT // do it! - asm or ah,ah // see status - asm jnz xit // abort on error - Frame = (void _seg *) _BX; // save frame segment - - if (size == 0) - { - asm mov ah,GET_SIZE // get EMS memory size - asm int EMS_INT // do it! - asm or ah,ah // see status - asm jnz xit // abort on error - asm or bx,bx // test page count - asm jz xit // abort if no free pages - // number of available pages in BX is ready to use by OPEN - } - else _BX = (uint16) ((size + PAGE_MASK) >> 14); - asm mov ah,OPEN_HANDLE // open EMM handle - asm int EMS_INT // do it! - asm or ah,ah // see status - asm jnz xit // abort on error - Han = _DX; - Lim = _BX; - Lim <<= 14; - _DX = Han; - asm mov ah,SAVE_CONTEXT // save mapping context - asm int EMS_INT // do it! - } - xit: - */ - warning("STUB: EMM:EMM"); -} - - -Emm::~Emm() { - /* FIXME - Release(); - if (Han >= 0) - { - _DX = Han; - asm mov ah,REST_CONTEXT - asm int EMS_INT - asm mov ah,CLOSE_HANDLE - asm int EMS_INT - } - */ -} - - -bool Emm::test() { - /* - static char e[] = "EMMXXXX0"; - - asm mov ax,0x3D40 - asm mov dx,offset e - asm int 0x21 - asm jc fail - - asm push ax - asm mov bx,ax - asm mov ax,0x4407 - asm int 0x21 - - asm pop bx - asm push ax - asm mov ax,0x3E00 - asm int 0x21 - asm pop ax - - asm cmp al,0x00 - asm je fail - - success: - return TRUE; - fail: - return FALSE; - */ - warning("EMM::Test"); - return false; -} - - -Ems *Emm::alloc(uint16 siz) { - /* - long size = SIZ(siz), - top = Top; - - uint16 pgn = (uint16) (top >> 14), - cnt = (uint16) ((top + size + PAGE_MASK) >> 14) - pgn; - - if (cnt > 4) - { - top = (top + PAGE_MASK) & 0xFFFFC000L; - pgn++; - cnt--; - } - - if (size <= Lim - top) - { - EMS * e = new EMS, * f; - - if (e) - { - Top = (e->Ptr = top) + (e->Siz = siz); - e->Emm = this; - - if (List) - { - for (f = List; f->Nxt; f = f->Nxt); - return (f->Nxt = e); // existing list: link to the end - } - else - { - return (List = e); // empty list: link to the head - } - } - } - fail: return NULL; - */ - warning("STUB: Emm::alloc"); - return NULL; -} - - -void Emm::release() { - while (_list) { - Ems *e = _list; - _list = e->_next; - delete e; - } - _top = 0; -} - - -Ems::Ems() : _ptr(0), _size(0), _next(NULL) { -} - - -void *Ems::operator & () const { - /* - uint16 pgn = (uint16) (Ptr >> 14), - off = (uint16) Ptr & PAGE_MASK, - cnt = (uint16) ((Ptr + SIZ(Siz) + PAGE_MASK) >> 14) - pgn, - cmd = MAP_PAGE << 8; - - _DX = Emm->_han; // take EMM handle - asm dec cnt // prapare for deferred checking - asm or dx,dx // see if valid - asm jns more // negative handle = unavailable - - fail: return NULL; - - more: - asm mov ax,cmd // command + page frame index - asm mov bx,pgn // logical page number - asm int EMS_INT // do it! - asm or ah,ah // check error code - asm jnz fail // exit on error - asm inc cmd // advance page frame index - asm inc pgn // advance logical page number - asm cmp al,byte ptr cnt // all pages? - asm jb more - - return (void *) (EMM::Frame + (void *) off); - */ - warning("STUB: Ems::operator &"); - return NULL; -} - - -uint16 Ems::size() { - return _size; -} - } // End of namespace CGE diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 46df263b93d..101c6cdd17d 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -298,7 +298,7 @@ void sndMidiStop() { // FIXME: STUB: sndMIDIStop } -DataCk *loadWave(XFile *file, Emm *emm) { +DataCk *loadWave(XFile *file) { warning("STUB: LoadWave"); return NULL; } diff --git a/engines/cge/general.h b/engines/cge/general.h index 63d43c4403b..e340c962bd7 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -58,40 +58,6 @@ public: ~Engine_(); }; - -class Ems; - - -class Emm { - friend class Ems; - bool test(); - - long _top; - long _lim; - Ems *_list; - int _han; - static void *_frame; -public: - Emm(long size); - ~Emm(); - Ems *alloc(uint16 siz); - void release(); -}; - - -class Ems { - friend class Emm; - Emm *_emm; - long _ptr; - uint16 _size; - Ems *_next; -public: - Ems(); - void *operator & () const; - uint16 size(); -}; - - template void swap(T &A, T &B) { T a = A; diff --git a/engines/cge/module.mk b/engines/cge/module.mk index 584ab5a1b68..c1112c7ec2e 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -9,7 +9,6 @@ MODULE_OBJS := \ config.o \ console.o \ detection.o \ - ems.o \ events.o \ game.o \ general.o \ diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index a163949ddde..9bf0d59be0a 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -65,7 +65,7 @@ void Sound::open() { void Sound::play(DataCk *wav, int pan, int cnt) { if (wav) { stop(); - _smpinf._saddr = (uint8 *) &*(wav->eAddr()); + _smpinf._saddr = (uint8 *) &*(wav->addr()); _smpinf._slen = (uint16)wav->size(); _smpinf._span = pan; _smpinf._sflag = cnt; @@ -79,7 +79,7 @@ void Sound::stop() { } -Fx::Fx(int size) : _emm(0L), _current(NULL) { +Fx::Fx(int size) : _current(NULL) { _cache = new Han[size]; for (_size = 0; _size < size; _size++) { _cache[_size]._ref = 0; @@ -103,7 +103,6 @@ void Fx::clear() { p->_wav = NULL; } } - _emm.release(); _current = NULL; } @@ -129,7 +128,7 @@ void Fx::preload(int ref0) { static char fname[] = "FX00000.WAV"; wtom(ref, fname + 2, 10, 5); INI_FILE file = INI_FILE(fname); - DataCk *wav = loadWave(&file, &_emm); + DataCk *wav = loadWave(&file); if (wav) { Han *p = &_cache[find(0)]; if (p >= cacheLim) @@ -146,7 +145,7 @@ DataCk *Fx::load(int idx, int ref) { wtom(ref, fname + 2, 10, 5); INI_FILE file = INI_FILE(fname); - DataCk *wav = loadWave(&file, &_emm); + DataCk *wav = loadWave(&file); if (wav) { Han *p = &_cache[idx]; p->_wav = wav; diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 5e1af713074..3ca4deaecc5 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -46,7 +46,6 @@ public: class Fx { - Emm _emm; struct Han { int _ref; DataCk *_wav; diff --git a/engines/cge/startup.h b/engines/cge/startup.h index 54799451041..4b1f8662f39 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -69,8 +69,6 @@ public: }; -extern Emm _miniEmm; - const char *usrPath(const char *nam); } // End of namespace CGE diff --git a/engines/cge/wav.h b/engines/cge/wav.h index c3e67f5f956..739e1029592 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -117,21 +117,14 @@ public: class DataCk : public CkHea { bool _e; - union { - uint8 *_buf; - Ems *_eBuf; - }; + uint8 *_buf; public: DataCk(CkHea &hea); - DataCk(CkHea &hea, Emm *emm); DataCk(int first, int last); ~DataCk(); inline uint8 *addr() { return _buf; } - inline Ems *eAddr() { - return _eBuf; - } }; @@ -141,7 +134,7 @@ extern ChunkId _fmt; extern ChunkId _data; -DataCk *loadWave(XFile *file, Emm *emm = NULL); +DataCk *loadWave(XFile *file); } // End of namespace CGE From dad302b640524224cb9381b3cfdcac7f430f0b21 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 25 Jul 2011 19:09:12 +0200 Subject: [PATCH 165/276] CGE: Remove _core from Startup class --- engines/cge/cge.cpp | 4 +++- engines/cge/cge_main.cpp | 13 +++---------- engines/cge/startup.cpp | 1 - engines/cge/startup.h | 12 ------------ 4 files changed, 6 insertions(+), 24 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 6068dee46e7..6542518a7e7 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -102,20 +102,22 @@ void CGEEngine::setup() { _eventManager = new EventManager(); _offUseCount = atoi(_text->getText(kOffUseCount)); _music = true; - _mini = new byte[MINI_EMM_SIZE]; for (int i = 0; i < kPocketNX; i++) _pocref[i] = -1; _volume[0] = 0; _volume[1] = 0; + if (_isDemo) { + _mini = new byte[16384]; _maxCaveArr[0] = CAVE_MAX; _maxCaveArr[1] = -1; _maxCaveArr[2] = -1; _maxCaveArr[3] = -1; _maxCaveArr[4] = -1; } else { + _mini = new byte[65536]; _maxCaveArr[0] = 1; _maxCaveArr[1] = 8; _maxCaveArr[2] = 16; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 60500b2b0e3..3bffa1f732c 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -335,9 +335,6 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt } } else { // Loading game - if (Startup::_core < CORE_HIG) - _music = false; - if (Startup::_soundOk == 1 && Startup::_mode == 0) { // _sndDrvInfo.Vol2._d = _volume[0]; // _sndDrvInfo.Vol2._m = _volume[1]; @@ -888,7 +885,7 @@ void System::tick() { if (_snail->idle()) { if (PAIN) _vm->heroCover(9); - else if (Startup::_core >= CORE_MID) { + else { // CHECKME: Before, was: if (Startup::_core >= CORE_MID) { int n = new_random(100); if (n > 96) _vm->heroCover(6 + (_hero->_x + _hero->_w / 2 < kScrWidth / 2)); @@ -928,12 +925,8 @@ void CGEEngine::switchMusic() { _snail->addCom2(kSnExec, -1, 0, kSelectSound); } } else { - if (Startup::_core < CORE_HIG) - _snail->addCom(kSnInf, -1, kNoMusic, NULL); - else { - _snail_->addCom(kSnSeq, 122, (_music = !_music), NULL); - keyClick(); - } + _snail_->addCom(kSnSeq, 122, (_music = !_music), NULL); + keyClick(); } if (_music) loadMidi(_now); diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index aca58a91ba3..19ec2879c6e 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -40,7 +40,6 @@ extern char _copr[]; // static Startup _startUp; int Startup::_mode = 0; -int Startup::_core; int Startup::_soundOk = 0; uint16 Startup::_summa; diff --git a/engines/cge/startup.h b/engines/cge/startup.h index 4b1f8662f39..d9416ff6a4b 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -47,22 +47,10 @@ namespace CGE { #define CFG_EXT ".CFG" -#if defined(DEMO) -#define MINI_EMM_SIZE 0x00004000L -#define CORE_HIG 400 -#else -#define MINI_EMM_SIZE 0x00010000L -#define CORE_HIG 450 -#endif - -#define CORE_MID (CORE_HIG - 20) - - class Startup { static bool getParms(); public: static int _mode; - static int _core; static int _soundOk; static uint16 _summa; Startup(); From df7d771feb8ad9f532d6c8ba768d77cf491116b2 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 28 Jul 2011 11:08:56 +0200 Subject: [PATCH 166/276] CGE: Remove summa variable, formerly used for the protection check --- engines/cge/cge_main.cpp | 14 +++----------- engines/cge/startup.cpp | 19 ------------------- engines/cge/startup.h | 1 - 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 3bffa1f732c..d6dd82dbe03 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -684,9 +684,7 @@ void CGEEngine::switchCave(int cav) { _hero->park(); _hero->step(0); if (!_isDemo) - ///// protection: auto-destruction on! ---------------------- - _vga->_spareQ->_show = Startup::_summa * (cav <= CAVE_MAX); - /////-------------------------------------------------------- + _vga->_spareQ->_show = 0; } _cavLight->gotoxy(CAVE_X + ((_now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, CAVE_Y + ((_now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); @@ -1686,15 +1684,9 @@ bool CGEEngine::showTitle(const char *name) { strcpy(_usrFnam, progName(kSvgExt)); usr_ok = true; } else { - //----------------------------------------- #ifndef EVA -#ifdef CD - Startup::_summa |= (0xC0 + (DriveCD(0) << 6)) & 0xFF; -#else - // At this point the game originally read the boot sector to get - // the serial number for it's copy protection check -#endif - //----------------------------------------- + // At this point the game originally set the protection variables + // used by the copy protection check movie("X00"); // paylist _vga->copyPage(1, 2); _vga->copyPage(0, 1); diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 19ec2879c6e..9a9d9ccfee8 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -41,7 +41,6 @@ extern char _copr[]; int Startup::_mode = 0; int Startup::_soundOk = 0; -uint16 Startup::_summa; void quitNow(int ref) { @@ -50,8 +49,6 @@ void quitNow(int ref) { bool Startup::getParms() { - _summa = 0; - /* int i = _argc; while (i > 1) { @@ -98,22 +95,6 @@ bool Startup::getParms() { if (n >= 2) SoundOk = 2; } - if (_vm->_isDemo) - // protection disabled - Summa = 0; - else { -#ifdef EVA - union { dosdate_t d; uint32 n; } today; - _dos_getdate(&today.d); - id.disk += (id.disk < today.n); -#endif -#ifdef CD - Summa = 0; -#else - // disk signature checksum - Summa = ChkSum(Copr, sizeof(Ident)); -#endif - } if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; diff --git a/engines/cge/startup.h b/engines/cge/startup.h index d9416ff6a4b..a9de89a5e23 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -52,7 +52,6 @@ class Startup { public: static int _mode; static int _soundOk; - static uint16 _summa; Startup(); }; From 7d5eb1ee639bf04e8f3b2ca280e631c3f67b1e9b Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 28 Jul 2011 15:35:12 +0200 Subject: [PATCH 167/276] CGE: Janitorial: remove trailing spaces --- engines/cge/cge.cpp | 4 ++-- engines/cge/cge_main.cpp | 19 ++++--------------- engines/cge/events.cpp | 4 ++-- engines/cge/mixer.cpp | 2 +- engines/cge/startup.cpp | 6 +++--- engines/cge/startup.h | 2 +- engines/cge/vga13h.cpp | 16 ++++++++-------- engines/cge/vmenu.cpp | 2 +- 8 files changed, 22 insertions(+), 33 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 6542518a7e7..3c3f14884d7 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -152,10 +152,10 @@ CGEEngine::~CGEEngine() { delete _console; - // Delete engine objects + // Delete engine objects delete _vga; delete _sys; - //delete _sprite; Sprite is destroyed by the queue it's added to + //delete _sprite; Sprite is destroyed by the queue it's added to delete _miniCave; delete _shadow; delete _horzLine; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index d6dd82dbe03..8681a6314a4 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -200,7 +200,7 @@ bool CGEEngine::loadGame(int slotNumber, SavegameHeader *header, bool tiny) { if (slotNumber == 0) strncpy(_usrFnam, saveHeader.saveName.c_str(), 8); } - + // Get in the savegame syncGame(readStream, NULL, tiny); @@ -502,7 +502,7 @@ void CGEEngine::resetQSwitch() { void CGEEngine::quit() { debugC(1, kCGEDebugEngine, "CGEEngine::quit()"); - static Choice QuitMenu[] = { + static Choice QuitMenu[] = { { NULL, &CGEEngine::startCountDown }, { NULL, &CGEEngine::resetQSwitch }, { NULL, &CGEEngine::dummy } @@ -737,7 +737,7 @@ void System::touch(uint16 mask, int x, int y) { case Del: if (_keyboard->_key[ALT] && _keyboard->_key[CTRL]) _vm->AltCtrlDel(); - else + else _vm->killSprite(); break; case 'F': @@ -1465,7 +1465,7 @@ void CGEEngine::tick() { void CGEEngine::loadUser() { // set scene - if (Startup::_mode == 0) { + if (Startup::_mode == 0) { // user .SVG file found - load it from slot 0 loadGame(0, NULL); } else { @@ -1740,21 +1740,10 @@ bool CGEEngine::showTitle(const char *name) { return (Startup::_mode == 2 || usr_ok); } - -/* -void StkDump () { - CFILE f("!STACK.DMP", BFW); - f.Write((uint8 *) (intStackPtr-STACK_SIZ/2), STACK_SIZ*2); -} -*/ - - void CGEEngine::cge_main() { uint16 intStack[STACK_SIZ / 2]; _intStackPtr = intStack; - //Debug( memset((void *) (-K(2)), 0, K(1)); ) - //Debug( memset((void *) (-K(4)), 0, K(1)); ) memset(_barriers, 0xFF, sizeof(_barriers)); if (!_mouse->_exist) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index aa71782f779..dc6e65722d0 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -147,14 +147,14 @@ void Keyboard::newKeyboard(Common::Event &event) { Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { _hold = NULL; - _hx = 0; + _hx = 0; _hy = 0; _exist = true; _buttons = 0; _busy = NULL; _active = false; _flags._kill = false; - + const Seq ms[] = { { 0, 0, 0, 0, 1 }, { 1, 1, 0, 0, 1 } diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 36f7a8e2f7d..decc516ae39 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -54,7 +54,7 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _ // slaves uint i; - Seq ls[kMixMax]; + Seq ls[kMixMax]; for (i = 0; i < kMixMax; i++) { static char fn[] = "V00"; diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp index 9a9d9ccfee8..5e1c8b8d649 100644 --- a/engines/cge/startup.cpp +++ b/engines/cge/startup.cpp @@ -56,7 +56,7 @@ bool Startup::getParms() { int n = takeEnum(PrmTab, strtok(_argv[--i], " =:(")); uint16 p = xtow(strtok(NULL, " h,)")); switch (n) { - case 0 : + case 0 : if (Mode != 2) Mode = 1; break; @@ -95,7 +95,7 @@ bool Startup::getParms() { if (n >= 2) SoundOk = 2; } - + if (SNDDrvInfo.MDEV != DEV_GM) SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; return true; @@ -109,7 +109,7 @@ Startup::Startup() { /* uint32 m = farcoreleft() >> 10; if (m < 0x7FFF) - Core = (int) m; + Core = (int) m; else Core = 0x7FFF; diff --git a/engines/cge/startup.h b/engines/cge/startup.h index a9de89a5e23..8a8305040c0 100644 --- a/engines/cge/startup.h +++ b/engines/cge/startup.h @@ -49,10 +49,10 @@ namespace CGE { class Startup { static bool getParms(); + Startup(); public: static int _mode; static int _soundOk; - Startup(); }; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d08f9bc8e83..7e1d8f9962a 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -228,7 +228,7 @@ extern "C" void TimerProc() { if (_heart->_xTimer) { if (*_heart->_xTimer) *_heart->_xTimer--; - else + else _heart->_xTimer = NULL; } @@ -324,9 +324,9 @@ void Engine_::newTimer(...) { } for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { - if (spr->Time) { + if (spr->Time) { if (!spr->_flags.Hide) { - if (--spr->Time == 0) + if (--spr->Time == 0) spr->tick(); } } @@ -949,7 +949,7 @@ void Vga::deinit() { } Vga::Vga(int mode) - : _frmCnt(0), _oldMode(0), _oldScreen(NULL), _statAdr(VGAST1_), + : _frmCnt(0), _oldMode(0), _oldScreen(NULL), _statAdr(VGAST1_), _msg(NULL), _nam(NULL), _setPal(false), _mono(0) { _oldColors = NULL; _newColors = NULL; @@ -1026,7 +1026,7 @@ void Vga::setStatAdr() { #pragma argsused void Vga::waitVR(bool on) { - // Since some of the game parts rely on using vertical sync as a delay mechanism, + // Since some of the game parts rely on using vertical sync as a delay mechanism, // we're introducing a short delay to simulate it g_system->delayMillis(10); } @@ -1244,7 +1244,7 @@ void Bitmap::xShow(int16 x, int16 y) { } // Move to next dest position - destP += 4; + destP += 4; } } } @@ -1294,7 +1294,7 @@ void Bitmap::show(int16 x, int16 y) { } // Move to next dest position - destP += 4; + destP += 4; } if (cmd == 2) @@ -1302,7 +1302,7 @@ void Bitmap::show(int16 x, int16 y) { } } /* - DEBUG code to display image immediately + DEBUG code to display image immediately // Temporary g_system->copyRectToScreen((const byte *)VGA::Page[1]->getBasePtr(0, 0), SCR_WID, 0, 0, SCR_WID, SCR_HIG); byte palData[PAL_SIZ]; diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index f846b3d061e..934bd6299d4 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -115,7 +115,7 @@ Vmenu::~Vmenu() { _addr = NULL; } -#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) +#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) void Vmenu::touch(uint16 mask, int x, int y) { if (_items) { From 316b73ee00091da6f0399bd7b446e859cd9d8c0d Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 29 Jul 2011 10:02:32 +0200 Subject: [PATCH 168/276] CGE: Remove Startup class, set _fx and _sound as dynamic --- engines/cge/cge.cpp | 10 ++- engines/cge/cge.h | 2 + engines/cge/cge_main.cpp | 54 ++++++------ engines/cge/cge_main.h | 3 + engines/cge/module.mk | 1 - engines/cge/snail.cpp | 4 +- engines/cge/sound.cpp | 13 +-- engines/cge/sound.h | 11 ++- engines/cge/startup.cpp | 176 --------------------------------------- engines/cge/startup.h | 63 -------------- 10 files changed, 52 insertions(+), 285 deletions(-) delete mode 100644 engines/cge/startup.cpp delete mode 100644 engines/cge/startup.h diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 3c3f14884d7..435a552bb49 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -36,7 +36,6 @@ #include "cge/text.h" #include "cge/vol.h" #include "cge/walk.h" -#include "cge/startup.h" namespace CGE { @@ -100,6 +99,9 @@ void CGEEngine::setup() { _mouse = new Mouse(this); _keyboard = new Keyboard(); _eventManager = new EventManager(); + _fx = new Fx(16); // must precede SOUND!! + _sound = new Sound(this); + _offUseCount = atoi(_text->getText(kOffUseCount)); _music = true; @@ -134,6 +136,9 @@ void CGEEngine::setup() { for (int i = 0; i < 4; i++) _flag[i] = false; + _mode = 0; + _soundOk = 0; + _startGameSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1; } @@ -167,6 +172,9 @@ CGEEngine::~CGEEngine() { delete _pocLight; delete _keyboard; delete _mouse; + delete _eventManager; + delete _fx; + delete _sound; for (int i = 0; i < kPocketNX; i++) delete _pocket[i]; delete _snail; diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 255dadfac6b..6d2842c6132 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -115,6 +115,8 @@ public: int _now; int _lev; char _usrFnam[15]; + int _mode; + int _soundOk; Common::RandomSource _randomSource; byte * _mini; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 8681a6314a4..855834b489b 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -35,7 +35,6 @@ #include "graphics/thumbnail.h" #include "cge/general.h" #include "cge/sound.h" -#include "cge/startup.h" #include "cge/config.h" #include "cge/vga13h.h" #include "cge/snail.h" @@ -51,6 +50,7 @@ #include "cge/cge_main.h" #include "cge/cge.h" #include "cge/walk.h" +#include "cge/sound.h" namespace CGE { @@ -81,6 +81,8 @@ InfoLine *_debugLine; Snail *_snail; Snail *_snail_; +Fx *_fx; +Sound *_sound; // 0.75 - 17II95 - full sound support // 0.76 - 18II95 - small MiniEMS in DEMO, // unhide CavLight in SNLEVEL @@ -335,7 +337,7 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt } } else { // Loading game - if (Startup::_soundOk == 1 && Startup::_mode == 0) { + if (_soundOk == 1 && _mode == 0) { // _sndDrvInfo.Vol2._d = _volume[0]; // _sndDrvInfo.Vol2._m = _volume[1]; warning("STUB: CGEEngine::syncGame Digital and Midi volume"); @@ -536,8 +538,8 @@ void CGEEngine::miniStep(int stp) { _miniCave->_flags._hide = true; else { *_miniShp[0] = *_miniShpList[stp]; - if (_fx._current) - &*(_fx._current->addr()); + if (_fx->_current) + &*(_fx->_current->addr()); _miniCave->_flags._hide = false; } @@ -588,10 +590,10 @@ void CGEEngine::caveUp() { spr = n; } - _sound.stop(); - _fx.clear(); - _fx.preload(0); - _fx.preload(BakRef); + _sound->stop(); + _fx->clear(); + _fx->preload(0); + _fx->preload(BakRef); if (_hero) { _hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); @@ -1465,16 +1467,14 @@ void CGEEngine::tick() { void CGEEngine::loadUser() { // set scene - if (Startup::_mode == 0) { + if (_mode == 0) { // user .SVG file found - load it from slot 0 loadGame(0, NULL); - } else { - if (Startup::_mode == 1) { + } else if (_mode == 1) { // Load either initial game state savegame or launcher specified savegame loadGame(_startGameSlot, NULL); - } else { + } else { error("Creating setup savegames not supported"); - } } loadScript(progName(kIn0Ext)); } @@ -1647,7 +1647,7 @@ bool CGEEngine::showTitle(const char *name) { D.center(); D.show(2); - if (Startup::_mode == 2) { + if (_mode == 2) { inf(SVG0NAME); _talk->show(2); } @@ -1658,7 +1658,7 @@ bool CGEEngine::showTitle(const char *name) { selectPocket(-1); _vga->sunrise(Vga::_sysPal); - if (Startup::_mode < 2 && !Startup::_soundOk) { + if (_mode < 2 && !_soundOk) { _vga->copyPage(1, 2); _vga->copyPage(0, 1); _vga->_showQ->append(_mouse); @@ -1674,12 +1674,12 @@ bool CGEEngine::showTitle(const char *name) { _heart->_enable = false; _vga->_showQ->clear(); _vga->copyPage(0, 2); - Startup::_soundOk = 2; + _soundOk = 2; if (_music) loadMidi(0); } - if (Startup::_mode < 2) { + if (_mode < 2) { if (_isDemo) { strcpy(_usrFnam, progName(kSvgExt)); usr_ok = true; @@ -1714,22 +1714,22 @@ bool CGEEngine::showTitle(const char *name) { #endif } - if (usr_ok && Startup::_mode == 0) { + if (usr_ok && _mode == 0) { if (savegameExists(0)) { // Load the savegame loadGame(0, NULL, true); // only system vars _vga->setColors(Vga::_sysPal, 64); _vga->update(); if (_flag[3]) { //flag FINIS - Startup::_mode++; + _mode++; _flag[3] = false; } } else - Startup::_mode++; + _mode++; } } - if (Startup::_mode < 2) + if (_mode < 2) movie("X01"); // wink _vga->copyPage(0, 2); @@ -1737,7 +1737,7 @@ bool CGEEngine::showTitle(const char *name) { if (_isDemo) return true; else - return (Startup::_mode == 2 || usr_ok); + return (_mode == 2 || usr_ok); } void CGEEngine::cge_main() { @@ -1750,28 +1750,28 @@ void CGEEngine::cge_main() { error("%s", _text->getText(NO_MOUSE_TEXT)); if (!SVG0FILE::exist(SVG0NAME)) - Startup::_mode = 2; + _mode = 2; _debugLine->_flags._hide = true; _horzLine->_flags._hide = true; - if (_music && Startup::_soundOk) + if (_music && _soundOk) loadMidi(0); if (_startGameSlot != -1) { // Starting up a savegame from the launcher - Startup::_mode++; + _mode++; runGame(); _startupMode = 2; if (_flag[3]) // Flag FINIS movie("X03"); } else { - if (Startup::_mode < 2) + if (_mode < 2) movie(kLgoExt); if (showTitle("WELCOME")) { - if ((!_isDemo) && (Startup::_mode == 1)) + if ((!_isDemo) && (_mode == 1)) movie("X02"); // intro runGame(); _startupMode = 2; diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 8586d84d50d..681e756c063 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -31,6 +31,7 @@ #include "cge/wav.h" #include "cge/vga13h.h" #include "cge/events.h" +#include "cge/sound.h" namespace CGE { #define CAVE_X 4 @@ -138,6 +139,8 @@ extern Sprite *_cavLight; extern InfoLine *_debugLine; extern Snail *_snail; extern Snail *_snail_; +extern Fx *_fx; +extern Sound *_sound; } // End of namespace CGE diff --git a/engines/cge/module.mk b/engines/cge/module.mk index c1112c7ec2e..8829883e263 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -16,7 +16,6 @@ MODULE_OBJS := \ mixer.o \ snail.o \ sound.o \ - startup.o \ talk.o \ text.o \ vga13h.o \ diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 697e70bf8ec..d1978ef8450 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -798,9 +798,9 @@ void CGEEngine::snSound(Sprite *spr, int wav, int cnt) { debugC(1, kCGEDebugEngine, "CGEEngine::snSound(spr, %d, %d)", wav, cnt); if (wav == -1) - _sound.stop(); + _sound->stop(); else - _sound.play(_fx[wav], (spr) ? ((spr->_x + spr->_w / 2) / (kScrWidth / 16)) : 8, cnt); + _sound->play((*_fx)[wav], (spr) ? ((spr->_x + spr->_w / 2) / (kScrWidth / 16)) : 8, cnt); } diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 9bf0d59be0a..56db1a64824 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -26,22 +26,17 @@ */ #include "cge/general.h" -#include "cge/startup.h" #include "cge/sound.h" #include "cge/text.h" #include "cge/cfile.h" #include "cge/vol.h" +#include "cge/cge_main.h" namespace CGE { -Fx _fx = 16; // must precede SOUND!! -Sound _sound; - - -Sound::Sound() { - if (Startup::_soundOk) - open(); +Sound::Sound(CGEEngine *vm) : _vm(vm) { + open(); } @@ -58,7 +53,7 @@ void Sound::close() { void Sound::open() { sndInit(); - play(_fx[30000], 8); + play((*_fx)[30000], 8); } diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 3ca4deaecc5..292cb30e766 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -30,18 +30,21 @@ #include "cge/wav.h" #include "cge/snddrv.h" +#include "cge/cge.h" namespace CGE { class Sound { public: SmpInfo _smpinf; - Sound(); + Sound(CGEEngine *vm); ~Sound(); void open(); void close(); void play(DataCk *wav, int pan, int cnt = 1); void stop(); +private: + CGEEngine *_vm; }; @@ -55,17 +58,13 @@ class Fx { int find(int ref); public: DataCk *_current; - Fx(int size = 16); + Fx(int size); ~Fx(); void clear(); void preload(int ref0); DataCk *operator[](int ref); }; -extern Sound _sound; -extern Fx _fx; - - void loadMidi(int ref); void killMidi(); diff --git a/engines/cge/startup.cpp b/engines/cge/startup.cpp deleted file mode 100644 index 5e1c8b8d649..00000000000 --- a/engines/cge/startup.cpp +++ /dev/null @@ -1,176 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/startup.h" -#include "cge/text.h" -#include "cge/sound.h" -#include "cge/cfile.h" -#include "cge/snddrv.h" - -namespace CGE { - -extern char _copr[]; - -#define id (*(Ident*)_copr) - -// static Startup _startUp; - -int Startup::_mode = 0; -int Startup::_soundOk = 0; - - -void quitNow(int ref) { - error("%s", _text->getText(ref)); -} - - -bool Startup::getParms() { - /* - int i = _argc; - while (i > 1) { - static char *PrmTab[] = { "NEW", "MK0SVG", "QUIET", "SB", "GUS", "MIDI", "P", "D", "I", "M" }; - int n = takeEnum(PrmTab, strtok(_argv[--i], " =:(")); - uint16 p = xtow(strtok(NULL, " h,)")); - switch (n) { - case 0 : - if (Mode != 2) - Mode = 1; - break; - case 1 : - Mode = 2; - break; - case 2 : - SNDDrvInfo.DDEV = DEV_QUIET; - break; - case 3 : - SNDDrvInfo.DDEV = DEV_SB; - break; - case 4 : - SNDDrvInfo.DDEV = DEV_GUS; - break; - case 5 : - SNDDrvInfo.MDEV = DEV_GM; - break; - case 6 : - SNDDrvInfo.DBASE = p; - break; - case 7 : - SNDDrvInfo.DDMA = p; - break; - case 8 : - SNDDrvInfo.DIRQ = p; - break; - case 9 : - SNDDrvInfo.MBASE = p; - SNDDrvInfo.MDEV = DEV_GM; - break; - default: - return false; - } - - if (n >= 2) - SoundOk = 2; - } - - if (SNDDrvInfo.MDEV != DEV_GM) - SNDDrvInfo.MDEV = SNDDrvInfo.DDEV; - return true; - */ - warning("STUB: Startup::get_parms"); - return true; -} - - -Startup::Startup() { - /* - uint32 m = farcoreleft() >> 10; - if (m < 0x7FFF) - Core = (int) m; - else - Core = 0x7FFF; - - if (! IsVga()) - quit_now(NOT_VGA_TEXT); - if (Cpu() < _80286) - quit_now(BAD_CHIP_TEXT); - if (100 * _osmajor + _osminor < 330) - quit_now(BAD_DOS_TEXT); - if (! get_parms()) - quit_now(BAD_ARG_TEXT); - //--- load sound configuration - const char * fn = usrPath(ProgName(CFG_EXT)); - if (!Startup::_soundOk && CFILE::Exist(fn)) { - CFILE cfg(fn, REA); - if (! cfg.Error) { - cfg.Read(&SNDDrvInfo, sizeof(SNDDrvInfo)-sizeof(SNDDrvInfo.VOL2)); - if (! cfg.Error) - Startup::_soundOk = 1; - } - } - */ - warning("STUB: Startup::Startup"); -} - - -const char *usrPath(const char *nam) { - static char buf[kPathMax] = ".\\", *p = buf + 2; -#if defined(CD) - if (DriveCD(0)) { - bool ok = false; - CFILE ini = Text[CDINI_FNAME]; - if (!ini.Error) { - char *key = Text[GAME_ID]; - int i = strlen(key); - while (ini.Read(buf) && !ok) { - int j = strlen(buf); - if (j) - if (buf[--j] == '\n') - buf[j] = '\0'; - if (scumm_strnicmp((const char *) buf, (const char*) key, i) == 0) - ok = true; - } - if (ok) { - strcpy(buf, buf + i); - p = buf + strlen(buf); - if (*(p - 1) != '\\') - *(p++) = '\\'; - strcpy(p, "NUL"); - if (_dos_open(buf, 0, &i) == 0) - _dos_close(i); - else - ok = false; - } - } - if (!ok) - quit_now(BADCD_TEXT); - } -#endif - strcpy(p, nam); - return buf; -} - -} // End of namespace CGE diff --git a/engines/cge/startup.h b/engines/cge/startup.h deleted file mode 100644 index 8a8305040c0..00000000000 --- a/engines/cge/startup.h +++ /dev/null @@ -1,63 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __CGE_STARTUP__ -#define __CGE_STARTUP__ - - -#include "cge/general.h" - -namespace CGE { - -#define GAME_ID 45 -#define CDINI_FNAME 46 - -#define NOT_VGA_TEXT 90 -#define BAD_CHIP_TEXT 91 -#define BAD_DOS_TEXT 92 -#define NO_CORE_TEXT 93 -#define BAD_MIPS_TEXT 94 -#define NO_MOUSE_TEXT 95 -#define BAD_ARG_TEXT 96 -#define BADCD_TEXT 97 - -#define CFG_EXT ".CFG" - -class Startup { - static bool getParms(); - Startup(); -public: - static int _mode; - static int _soundOk; -}; - - -const char *usrPath(const char *nam); - -} // End of namespace CGE - -#endif From 5c7eb9a7686e6c701af083072fa944d3fc2e88fd Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 30 Jul 2011 12:52:04 +0200 Subject: [PATCH 169/276] CGE: un-static-fy several variables, clean Heart class --- engines/cge/cge.cpp | 2 + engines/cge/cge.h | 7 +- engines/cge/general.cpp | 33 ---------- engines/cge/general.h | 9 --- engines/cge/snail.cpp | 127 +++++++++++++++++------------------- engines/cge/vga13h.cpp | 140 +--------------------------------------- engines/cge/vga13h.h | 8 +-- 7 files changed, 71 insertions(+), 255 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 435a552bb49..168f45e45b2 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -138,6 +138,8 @@ void CGEEngine::setup() { _mode = 0; _soundOk = 0; + _sprTv = NULL; + _gameCase2Cpt = 0; _startGameSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1; } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 6d2842c6132..835c47cb6e3 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -107,7 +107,6 @@ public: int _pocref[kPocketNX]; uint8 _volume[2]; int _maxCaveArr[5]; - int _maxCave; bool _flag[4]; bool _dark; @@ -117,6 +116,12 @@ public: char _usrFnam[15]; int _mode; int _soundOk; + int _gameCase2Cpt; + + Sprite *_sprTv; + Sprite *_sprK1; + Sprite *_sprK2; + Sprite *_sprK3; Common::RandomSource _randomSource; byte * _mini; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 101c6cdd17d..1947fc60619 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -331,39 +331,6 @@ int new_random(int range) { return ((CGEEngine *)g_engine)->_randomSource.getRandomNumber(range - 1); } -//void interrupt (* Engine_::oldTimer) (...) = NULL; - -Engine_::Engine_(uint16 tdiv) { -/* - // steal timer interrupt - OldTimer = getvect(TIMER_INT); - setvect(TIMER_INT, NewTimer); - - // set turbo-timer mode - asm mov al,0x36 - asm out 0x43,al - asm mov ax,TMR_DIV - asm out 0x40,al - asm mov al,ah - asm out 0x40,al -*/ - warning("STUB: Engine_::Engine_"); -} - -Engine_::~Engine_() { -/* - // reset timer - asm mov al,0x36 - asm out 0x43,al - asm xor al,al - asm out 0x40,al - asm out 0x40,al - // bring back timer interrupt - setvect(TIMER_INT, OldTimer); -*/ - warning("STUB: Engine_::~Engine_"); -} - DataCk::~DataCk() { if (!_e && _buf) free(_buf); diff --git a/engines/cge/general.h b/engines/cge/general.h index e340c962bd7..d55193d85c4 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -49,15 +49,6 @@ struct Dac { typedef uint16 CRYPT(void *buf, uint16 siz, uint16 seed); -class Engine_ { -protected: - static void (* oldTimer)(...); - static void newTimer(...); -public: - Engine_(uint16 tdiv); - ~Engine_(); -}; - template void swap(T &A, T &B) { T a = A; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index d1978ef8450..aa37922b70b 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -134,60 +134,55 @@ void CGEEngine::snGame(Sprite *spr, int num) { _snail->addCom(kSnSay, buref, 16008, NULL); // zgadnij! _game = true; } -#undef STEPS -#undef DRESSED } break; //-------------------------------------------------------------------- case 2 : { - static Sprite *k = NULL, * k1, * k2, * k3; - static int count = 0; - - if (k == NULL) { - k = _vga->_showQ->locate(20700); - k1 = _vga->_showQ->locate(20701); - k2 = _vga->_showQ->locate(20702); - k3 = _vga->_showQ->locate(20703); + if (_sprTv == NULL) { + _sprTv = _vga->_showQ->locate(20700); + _sprK1 = _vga->_showQ->locate(20701); + _sprK2 = _vga->_showQ->locate(20702); + _sprK3 = _vga->_showQ->locate(20703); } if (!_game) { // init _snail->addCom(kSnGame, 20002, 2, NULL); _game = true; } else { // cont - k1->step(new_random(6)); - k2->step(new_random(6)); - k3->step(new_random(6)); + _sprK1->step(new_random(6)); + _sprK2->step(new_random(6)); + _sprK3->step(new_random(6)); ///-------------------- if (spr->_ref == 1 && _keyboard->_key[ALT]) { - k1->step(5); - k2->step(5); - k3->step(5); + _sprK1->step(5); + _sprK2->step(5); + _sprK3->step(5); } ///-------------------- _snail->addCom(kSnSetZ, 20700, 0, NULL); - bool hit = (k1->_seqPtr + k2->_seqPtr + k3->_seqPtr == 15); + bool hit = (_sprK1->_seqPtr + _sprK2->_seqPtr + _sprK3->_seqPtr == 15); if (hit) { if (spr->_ref == 1) { - _snail->addCom(kSnSay, 1, 20003, NULL); // hura! - _snail->addCom(kSnSeq, 20011, 2, NULL); // kamera won - _snail->addCom(kSnSend, 20701, -1, NULL); // k1 won - _snail->addCom(kSnSend, 20702, -1, NULL); // k2 won - _snail->addCom(kSnSend, 20703, -1, NULL); // k3 won - _snail->addCom(kSnSend, 20700, -1, NULL); // tv won - _snail->addCom(kSnKeep, 20007, 0, NULL); // do kieszeni - _snail->addCom(kSnSend, 20006, 20, NULL); // bilon + _snail->addCom(kSnSay, 1, 20003, NULL); // hura! + _snail->addCom(kSnSeq, 20011, 2, NULL); // kamera won + _snail->addCom(kSnSend, 20701, -1, NULL); // k1 won + _snail->addCom(kSnSend, 20702, -1, NULL); // k2 won + _snail->addCom(kSnSend, 20703, -1, NULL); // k3 won + _snail->addCom(kSnSend, 20700, -1, NULL); // tv won + _snail->addCom(kSnKeep, 20007, 0, NULL); // do kieszeni + _snail->addCom(kSnSend, 20006, 20, NULL); // bilon _snail->addCom(kSnSound, 20006, 20002, NULL); // bilon! - _snail->addCom(kSnSay, 20002, 20004, NULL); - _snail->addCom(kSnSend, 20010, 20, NULL); // papier + _snail->addCom(kSnSay, 20002, 20004, NULL); + _snail->addCom(kSnSend, 20010, 20, NULL); // papier _snail->addCom(kSnSound, 20010, 20003, NULL); // papier! - _snail->addCom(kSnSay, 20001, 20005, NULL); + _snail->addCom(kSnSay, 20001, 20005, NULL); _game = false; return; } else - k3->step(new_random(5)); + _sprK3->step(new_random(5)); } - if (count < 100) { - switch (count) { + if (_gameCase2Cpt < 100) { + switch (_gameCase2Cpt) { case 15 : _snail->addCom(kSnSay, 20003, 20021, NULL); break; @@ -198,51 +193,51 @@ void CGEEngine::snGame(Sprite *spr, int num) { _snail->addCom(kSnSay, 20003, 20022, NULL); break; } - count++; + _gameCase2Cpt++; } switch (spr->_ref) { case 1 : - _snail->addCom(kSnSay, 20001, 20011, NULL); // zapro - _snail->addCom(kSnSeq, 20001, 1, NULL); // rzu - _snail->addCom(kSnWait, 20001, 1, NULL); // czekaj - _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k - _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k - _snail->addCom(kSnWait, 20001, 16, NULL); // czekaj - _snail->addCom(kSnSeq, 20007, 1, NULL); // lec† - _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ + _snail->addCom(kSnSay, 20001, 20011, NULL); // zapro + _snail->addCom(kSnSeq, 20001, 1, NULL); // rzu + _snail->addCom(kSnWait, 20001, 1, NULL); // czekaj + _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k + _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k + _snail->addCom(kSnWait, 20001, 16, NULL); // czekaj + _snail->addCom(kSnSeq, 20007, 1, NULL); // lec† + _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech - _snail->addCom(kSnWait, 20007, -1, NULL); // koniec - _snail->addCom(kSnGame, 20001, 2, NULL); // again! + _snail->addCom(kSnWait, 20007, -1, NULL); // koniec + _snail->addCom(kSnGame, 20001, 2, NULL); // again! break; case 20001: - _snail->addCom(kSnSay, 20002, 20012, NULL); // zapro - _snail->addCom(kSnSeq, 20002, 1, NULL); // rzu - _snail->addCom(kSnWait, 20002, 3, NULL); // czekaj - _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k - _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k - _snail->addCom(kSnWait, 20002, 10, NULL); // czekaj - _snail->addCom(kSnSeq, 20007, 2, NULL); // lec† - _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ + _snail->addCom(kSnSay, 20002, 20012, NULL); // zapro + _snail->addCom(kSnSeq, 20002, 1, NULL); // rzu + _snail->addCom(kSnWait, 20002, 3, NULL); // czekaj + _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k + _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k + _snail->addCom(kSnWait, 20002, 10, NULL); // czekaj + _snail->addCom(kSnSeq, 20007, 2, NULL); // lec† + _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech - _snail->addCom(kSnWait, 20007, -1, NULL); // koniec - _snail->addCom(kSnGame, 20002, 2, NULL); // again! + _snail->addCom(kSnWait, 20007, -1, NULL); // koniec + _snail->addCom(kSnGame, 20002, 2, NULL); // again! break; case 20002: - _snail->addCom(kSnSay, 20002, 20010, NULL); // zapro - _snail->addCom(kSnWalk, 20005, -1, NULL); // do stol - _snail->addCom(kSnWait, 1, -1, NULL); // stoi - _snail->addCom(kSnCover, 1, 20101, NULL); // grasol - _snail->addCom(kSnSeq, 20101, 1, NULL); // rzu - _snail->addCom(kSnWait, 20101, 5, NULL); // czekaj - _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k - _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k - _snail->addCom(kSnWait, 20101, 15, NULL); // czekaj - _snail->addCom(kSnSeq, 20007, 1, NULL); // lec† - _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ + _snail->addCom(kSnSay, 20002, 20010, NULL); // zapro + _snail->addCom(kSnWalk, 20005, -1, NULL); // do stol + _snail->addCom(kSnWait, 1, -1, NULL); // stoi + _snail->addCom(kSnCover, 1, 20101, NULL); // grasol + _snail->addCom(kSnSeq, 20101, 1, NULL); // rzu + _snail->addCom(kSnWait, 20101, 5, NULL); // czekaj + _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k + _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k + _snail->addCom(kSnWait, 20101, 15, NULL); // czekaj + _snail->addCom(kSnSeq, 20007, 1, NULL); // lec† + _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech - _snail->addCom(kSnWait, 20101, -1, NULL); // koniec - _snail->addCom(kSnUncover, 1, 20101, NULL); // SDS - _snail->addCom(kSnGame, 1, 2, NULL); // again! + _snail->addCom(kSnWait, 20101, -1, NULL); // koniec + _snail->addCom(kSnUncover, 1, 20101, NULL); // SDS + _snail->addCom(kSnGame, 1, 2, NULL); // again! break; } } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 7e1d8f9962a..6e14666bd99 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -212,148 +212,10 @@ Sprite *locate(int ref) { } -Heart::Heart() - : Engine_(TMR_DIV) { +Heart::Heart() { _enable = false; - _xTimer = NULL; } - -/* -extern "C" void TimerProc() { - static SPRITE * spr; - static uint8 run = 0; - - // decrement external timer uint16 - if (_heart->_xTimer) { - if (*_heart->_xTimer) - *_heart->_xTimer--; - else - _heart->_xTimer = NULL; - } - - if (!run && _heart->_enable) { // check overrun flag - static uint16 oldSP, oldSS; - run++; // disable 2nd call until current lasts - asm mov ax,ds - asm mov oldSS,ss - asm mov oldSP,sp - asm mov ss,ax - asm mov sp,0xFF80 - - // system pseudo-sprite - if (Sys) { - if (Sys->Time) { - if (--Sys->Time == 0) - Sys->tick(); - } - } - for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { - if (spr->Time) { - if (!spr->_flags.Hide) { - if (-- spr->Time == 0) - spr->tick(); - } - } - } - asm mov ss,oldSS - asm mov sp,oldSP - run--; - } -} -*/ - - -void Engine_::newTimer(...) { - /* - static SPRITE *spr; - static uint8 run = 0, cntr1 = TMR_RATE1, cntr2 = TMR_RATE2; - ___1152_Hz___: - - SNDMIDIPlay(); - asm dec cntr1 - asm jz ___72_Hz___ - asm mov al,0x20 // send... - asm out 0x020,al // ...e-o-i - return; - - ___72_Hz___: - - asm mov cntr1,TMR_RATE1 - asm dec cntr2 - asm jnz my_eoi - - ___18_Hz___: - - OldTimer(); - asm mov cntr2,TMR_RATE2 - asm jmp short my_int - - // send E-O-I - my_eoi: - asm mov al,0x20 - asm out 0x020,al - asm sti // enable interrupts - - my_int: //------72Hz-------// - - // decrement external timer uint16 - if (_heart->XTimer) { - if (*_heart->XTimer) - *_heart->XTimer--; - else - _heart->XTimer = NULL; - } - - if (! run && _heart->Enable) { // check overrun flag - static uint16 oldSP, oldSS; - - run++; // disable 2nd call until current lasts - asm mov ax,ds - asm mov oldSS,ss - asm mov oldSP,sp - asm mov ss,ax - asm mov sp,0xFF80 - - // system pseudo-sprite - if (Sys) { - if (Sys->Time) { - if (--Sys->Time == 0) - Sys->tick(); - } - } - - for (spr = VGA::ShowQ.First(); spr; spr = spr->Next) { - if (spr->Time) { - if (!spr->_flags.Hide) { - if (--spr->Time == 0) - spr->tick(); - } - } - } - asm mov ss,oldSS - asm mov sp,oldSP - run--; - } - - */ - warning("STUB: Engine_::NewTimer"); -} - - -void Heart::setXTimer(uint16 *ptr) { - if (_xTimer && ptr != _xTimer) - *_xTimer = 0; - _xTimer = ptr; -} - - -void Heart::setXTimer(uint16 *ptr, uint16 time) { - setXTimer(ptr); - *ptr = time; -} - - Sprite::Sprite(CGEEngine *vm, BMP_PTR *shpP) : _x(0), _y(0), _z(0), _nearPtr(0), _takePtr(0), _next(NULL), _prev(NULL), _seqPtr(NO_SEQ), _time(0), //Delay(0), diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index f192d962ffc..535c7005d2e 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -117,16 +117,10 @@ extern Seq _seq2[]; #define VGAST1 (VGAST1_ & 0xFF) -class Heart : public Engine_ { - friend class Engine_; +class Heart { public: Heart(); - bool _enable; - uint16 *_xTimer; - - void setXTimer(uint16 *ptr); - void setXTimer(uint16 *ptr, uint16 time); }; From 8b53899ca7d5ab1599f6bf3e1d4e49746876674b Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 30 Jul 2011 15:28:57 +0200 Subject: [PATCH 170/276] CGE: Remove Heart --- engines/cge/cge.cpp | 2 -- engines/cge/cge_main.cpp | 13 ------------- engines/cge/cge_main.h | 1 - engines/cge/snail.cpp | 3 --- engines/cge/vga13h.cpp | 8 -------- engines/cge/vga13h.h | 7 ------- 6 files changed, 34 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 168f45e45b2..116bafcb64e 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -81,7 +81,6 @@ void CGEEngine::setup() { // Initialise engine objects _text = new Text(this, progName(), 128); _vga = new Vga(M13H); - _heart = new Heart; _sys = new System(this); _pocLight = new PocLight(this); for (int i = 0; i < kPocketNX; i++) { @@ -170,7 +169,6 @@ CGEEngine::~CGEEngine() { delete _cavLight; delete _debugLine; delete _text; - delete _heart; delete _pocLight; delete _keyboard; delete _mouse; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 855834b489b..dc573b8b2f7 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -63,7 +63,6 @@ namespace CGE { uint16 _stklen = (STACK_SIZ * 2); Vga *_vga; -Heart *_heart; System *_sys; Sprite *_pocLight; EventManager *_eventManager; @@ -625,8 +624,6 @@ void CGEEngine::caveUp() { _dark = false; if (!_startupMode) _mouse->on(); - - _heart->_enable = true; } @@ -675,7 +672,6 @@ void CGEEngine::switchCave(int cav) { debugC(1, kCGEDebugEngine, "CGEEngine::switchCave(%d)", cav); if (cav != _now) { - _heart->_enable = false; if (cav < 0) { _snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint _snail->addCom2(kSnExec, -1, 0, kQGame); // switch cave @@ -1592,7 +1588,6 @@ void CGEEngine::runGame() { } _keyboard->setClient(NULL); - _heart->_enable = false; _snail->addCom(kSnClear, -1, 0, NULL); _snail_->addCom(kSnClear, -1, 0, NULL); _mouse->off(); @@ -1612,16 +1607,12 @@ void CGEEngine::movie(const char *ext) { loadScript(fn); expandSprite(_vga->_spareQ->locate(999)); feedSnail(_vga->_showQ->locate(999), kTake); - _vga->_showQ->append(_mouse); - - _heart->_enable = true; _keyboard->setClient(_sys); while (!_snail->idle() && !_eventManager->_quitFlag) mainLoop(); _keyboard->setClient(NULL); - _heart->_enable = false; _snail->addCom(kSnClear, -1, 0, NULL); _snail_->addCom(kSnClear, -1, 0, NULL); _vga->_showQ->clear(); @@ -1662,7 +1653,6 @@ bool CGEEngine::showTitle(const char *name) { _vga->copyPage(1, 2); _vga->copyPage(0, 1); _vga->_showQ->append(_mouse); - _heart->_enable = true; _mouse->on(); for (; !_snail->idle() || Vmenu::_addr;) { mainLoop(); @@ -1671,7 +1661,6 @@ bool CGEEngine::showTitle(const char *name) { } _mouse->off(); - _heart->_enable = false; _vga->_showQ->clear(); _vga->copyPage(0, 2); _soundOk = 2; @@ -1698,13 +1687,11 @@ bool CGEEngine::showTitle(const char *name) { strcpy(_usrFnam, "User"); usr_ok = true; } else { - _heart->_enable = true; for (takeName(); GetText::_ptr;) { mainLoop(); if (_eventManager->_quitFlag) return false; } - _heart->_enable = false; if (_keyboard->last() == Enter && *_usrFnam) usr_ok = true; } diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 681e756c063..d811236485c 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -122,7 +122,6 @@ private: }; extern Vga *_vga; -extern Heart *_heart; extern System *_sys; extern int _offUseCount; extern Sprite *_pocLight; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index aa37922b70b..2cd38d671fc 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -501,16 +501,13 @@ void CGEEngine::snZTrim(Sprite *spr) { if (spr) if (spr->active()) { - bool en = _heart->_enable; Sprite *s; - _heart->_enable = false; s = (spr->_flags._shad) ? spr->_prev : NULL; _vga->_showQ->insert(_vga->_showQ->remove(spr)); if (s) { s->_z = spr->_z; _vga->_showQ->insert(_vga->_showQ->remove(s), spr); } - _heart->_enable = en; } } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 6e14666bd99..9b30e02e4da 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -211,11 +211,6 @@ Sprite *locate(int ref) { return (spr) ? spr : _vga->_spareQ->locate(ref); } - -Heart::Heart() { - _enable = false; -} - Sprite::Sprite(CGEEngine *vm, BMP_PTR *shpP) : _x(0), _y(0), _z(0), _nearPtr(0), _takePtr(0), _next(NULL), _prev(NULL), _seqPtr(NO_SEQ), _time(0), //Delay(0), @@ -358,8 +353,6 @@ void Sprite::setName(char *n) { Sprite *Sprite::expand() { if (!_ext) { - bool enbl = _heart->_enable; - _heart->_enable = false; _ext = new SprExt; assert(_ext != NULL); if (*_file) { @@ -473,7 +466,6 @@ Sprite *Sprite::expand() { else _takePtr = NO_PTR; } - _heart->_enable = enbl; } return this; } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 535c7005d2e..15da63efbcd 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -117,13 +117,6 @@ extern Seq _seq2[]; #define VGAST1 (VGAST1_ & 0xFF) -class Heart { -public: - Heart(); - bool _enable; -}; - - class SprExt { public: int _x0, _y0; From b53ffa8f2c31d27ac5a7b3fd48143102be6ff4ff Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 30 Jul 2011 15:43:49 +0200 Subject: [PATCH 171/276] CGE: Move some conditional defines to variables --- engines/cge/cge.cpp | 62 ++++++++++++++++++++++++++++++---------- engines/cge/cge.h | 19 ++++++++++++ engines/cge/cge_main.cpp | 18 +++++++----- engines/cge/cge_main.h | 12 -------- engines/cge/snail.h | 11 ------- engines/cge/walk.cpp | 6 ++-- 6 files changed, 79 insertions(+), 49 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 116bafcb64e..8d2073b66f7 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -56,6 +56,49 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) } +void CGEEngine::initCaveValues() { + if (_isDemo) { + _mini = new byte[16384]; + CAVE_DX = 23; + CAVE_DY = 29; + CAVE_NX = 3; + CAVE_NY = 1; + } else { + _mini = new byte[65536]; + CAVE_DX = 9; + CAVE_DY = 10; + CAVE_NX = 8; + CAVE_NY = 3; + } + CAVE_MAX = CAVE_NX * CAVE_NY; + + if (_isDemo) { + _maxCaveArr[0] = CAVE_MAX; + _maxCaveArr[1] = -1; + _maxCaveArr[2] = -1; + _maxCaveArr[3] = -1; + _maxCaveArr[4] = -1; + } else { + _maxCaveArr[0] = 1; + _maxCaveArr[1] = 8; + _maxCaveArr[2] = 16; + _maxCaveArr[3] = 23; + _maxCaveArr[4] = 24; + }; + + _heroXY = (Hxy *) malloc (sizeof(Hxy) * CAVE_MAX); + for (int i = 0; i < CAVE_MAX; i++) { + _heroXY[i]._x = 0; + _heroXY[i]._y = 0; + } + + _barriers = (Bar *) malloc (sizeof(Bar) * (1 + CAVE_MAX)); + for (int i = 0; i < CAVE_MAX + 1; i++) { + _barriers[i]._horz = 0xFF; + _barriers[i]._vert = 0xFF; + } +} + void CGEEngine::setup() { debugC(1, kCGEDebugEngine, "CGEEngine::setup()"); @@ -109,22 +152,8 @@ void CGEEngine::setup() { _volume[0] = 0; _volume[1] = 0; + initCaveValues(); - if (_isDemo) { - _mini = new byte[16384]; - _maxCaveArr[0] = CAVE_MAX; - _maxCaveArr[1] = -1; - _maxCaveArr[2] = -1; - _maxCaveArr[3] = -1; - _maxCaveArr[4] = -1; - } else { - _mini = new byte[65536]; - _maxCaveArr[0] = 1; - _maxCaveArr[1] = 8; - _maxCaveArr[2] = 16; - _maxCaveArr[3] = 23; - _maxCaveArr[4] = 24; - }; _maxCave = 0; _dark = false; _game = false; @@ -181,6 +210,9 @@ CGEEngine::~CGEEngine() { delete _snail_; delete _hero; delete[] _mini; + + free(_heroXY); + free(_barriers); } Common::Error CGEEngine::run() { diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 835c47cb6e3..9d2503a5cf7 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -78,6 +78,16 @@ struct SavegameHeader { extern const char *SAVEGAME_STR; #define SAVEGAME_STR_SIZE 11 +struct Bar { + uint8 _horz; + uint8 _vert; +}; + +struct Hxy { + int _x; + int _y; +}; + class CGEEngine : public Engine { private: uint32 _lastFrame, _lastTick; @@ -123,6 +133,14 @@ public: Sprite *_sprK2; Sprite *_sprK3; + uint8 CAVE_DX; + uint8 CAVE_DY; + uint8 CAVE_NX; + uint8 CAVE_NY; + uint16 CAVE_MAX; + Hxy *_heroXY; + Bar *_barriers; + Common::RandomSource _randomSource; byte * _mini; BMP_PTR * _miniShp; @@ -200,6 +218,7 @@ public: void AltCtrlDel(); void postMiniStep(int stp); void showBak(int ref); + void initCaveValues(); void snBackPt(Sprite *spr, int stp); void snBarrier(int cav, int bar, bool horz); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index dc573b8b2f7..123501047ae 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -99,9 +99,6 @@ static bool _finis = false; int _offUseCount; uint16 *_intStackPtr = false; -Hxy _heroXY[CAVE_MAX] = {{0, 0}}; -Bar _barriers[1 + CAVE_MAX] = { { 0xFF, 0xFF } }; - extern Dac _stdPal[58]; void CGEEngine::syncHeader(Common::Serializer &s) { @@ -120,6 +117,13 @@ void CGEEngine::syncHeader(Common::Serializer &s) { for (i = 0; i < 4; ++i) s.syncAsUint16LE(_flag[i]); + initCaveValues(); + if (s.isLoading()) { + //TODO: Fix the memory leak when the game is already running + _heroXY = (Hxy *) malloc (sizeof(Hxy) * CAVE_MAX); + _barriers = (Bar *) malloc (sizeof(Bar) * (1 + CAVE_MAX)); + } + for (i = 0; i < CAVE_MAX; ++i) { s.syncAsSint16LE(_heroXY[i]._x); s.syncAsUint16LE(_heroXY[i]._y); @@ -145,7 +149,7 @@ void CGEEngine::syncHeader(Common::Serializer &s) { } bool CGEEngine::loadGame(int slotNumber, SavegameHeader *header, bool tiny) { - debugC(1, kCGEDebugEngine, "CGEEngine::loadgame(file, %s)", tiny ? "true" : "false"); + debugC(1, kCGEDebugEngine, "CGEEngine::loadgame(%d, header, %s)", slotNumber, tiny ? "true" : "false"); Common::MemoryReadStream *readStream; SavegameHeader saveHeader; @@ -833,9 +837,9 @@ void System::touch(uint16 mask, int x, int y) { _infoLine->update(NULL); if (y >= kWorldHeight ) { if (x < kButtonX) { // select cave? - if (y >= CAVE_Y && y < CAVE_Y + CAVE_NY * CAVE_DY && - x >= CAVE_X && x < CAVE_X + CAVE_NX * CAVE_DX && !_vm->_game) { - cav = ((y - CAVE_Y) / CAVE_DY) * CAVE_NX + (x - CAVE_X) / CAVE_DX + 1; + if (y >= CAVE_Y && y < CAVE_Y + _vm->CAVE_NY * _vm->CAVE_DY && + x >= CAVE_X && x < CAVE_X + _vm->CAVE_NX * _vm->CAVE_DX && !_vm->_game) { + cav = ((y - CAVE_Y) / _vm->CAVE_DY) * _vm->CAVE_NX + (x - CAVE_X) / _vm->CAVE_DX + 1; if (cav > _vm->_maxCave) cav = 0; } else { diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index d811236485c..e3d8d408467 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -39,18 +39,6 @@ namespace CGE { #define CAVE_SX 0 #define CAVE_SY 0 -#ifdef DEMO -#define CAVE_DX 23 -#define CAVE_DY 29 -#define CAVE_NX 3 -#define CAVE_NY 1 -#else -#define CAVE_DX 9 -#define CAVE_DY 10 -#define CAVE_NX 8 -#define CAVE_NY 3 -#endif -#define CAVE_MAX (CAVE_NX * CAVE_NY) #define PAIN (_vm->_flag[0]) #define kInfoX 177 diff --git a/engines/cge/snail.h b/engines/cge/snail.h index ad63f55f36b..2b488cd5b2d 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -37,11 +37,6 @@ namespace CGE { #define kSnailFrameDelay (1000 / kSnailFrameRate) #define kDressed 3 -struct Bar { - uint8 _horz; - uint8 _vert; -}; - enum SnCom { kSnLabel, kSnPause, kSnWait, kSnLevel, kSnHide, kSnSay, kSnInf, kSnTime, kSnCave, kSnKill, @@ -86,12 +81,6 @@ private: }; -extern Bar _barriers[]; -extern struct Hxy { - int _x; - int _y; -} _heroXY[]; - } // End of namespace CGE #endif diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 9bcc2be23d1..e2c62513dd7 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -30,8 +30,6 @@ namespace CGE { -extern Bar _barriers[]; - Walk *_hero; uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; @@ -50,8 +48,8 @@ bool Cluster::isValid() const { } bool Cluster::chkBar() const { - assert(_vm->_now <= CAVE_MAX); - return (_a == _barriers[_vm->_now]._horz) && (_b == _barriers[_vm->_now]._vert); + assert(_vm->_now <= _vm->CAVE_MAX); + return (_a == _vm->_barriers[_vm->_now]._horz) && (_b == _vm->_barriers[_vm->_now]._vert); } Cluster XZ(int x, int y) { From 55df4d063596c774969a8d3537c999a95b7dfcc0 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 31 Jul 2011 00:52:35 +0200 Subject: [PATCH 172/276] CGE: Rename some class members, various clean up --- engines/cge/bitmap.cpp | 14 +++--- engines/cge/bitmap.h | 2 +- engines/cge/btfile.cpp | 2 +- engines/cge/btfile.h | 2 +- engines/cge/cfile.cpp | 18 ++++---- engines/cge/cfile.h | 8 ++-- engines/cge/cge.cpp | 28 ++++++------ engines/cge/cge.h | 22 ++++----- engines/cge/cge_main.cpp | 68 ++++++++++++++-------------- engines/cge/events.cpp | 6 +-- engines/cge/general.cpp | 24 +++++----- engines/cge/general.h | 23 +++++----- engines/cge/gettext.cpp | 2 +- engines/cge/mixer.h | 4 +- engines/cge/snail.cpp | 8 ++-- engines/cge/snail.h | 2 +- engines/cge/talk.cpp | 72 ++++++++++-------------------- engines/cge/talk.h | 10 ++--- engines/cge/text.cpp | 34 +++++++------- engines/cge/text.h | 14 +++--- engines/cge/vga13h.cpp | 96 ++++++++++++++++++++-------------------- engines/cge/vga13h.h | 38 ++++++++-------- engines/cge/vmenu.cpp | 2 +- engines/cge/walk.cpp | 58 ++++++++++++------------ engines/cge/walk.h | 26 ++++++----- engines/cge/wav.h | 10 ++--- 26 files changed, 282 insertions(+), 311 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index c02c66df8b3..ddde3bbd213 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -126,7 +126,7 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) b->_hide = _w >> 2; // Replicate across the entire table - for (HideDesc *hdP = b + 1; hdP < (b + _h); ++hdP) + for (HideDesc *hdP = b + 1; hdP < (b + _h); hdP++) *hdP = *b; b->_skip = 0; // fix the first entry @@ -195,7 +195,7 @@ uint16 Bitmap::moveVmap(uint8 *buf) { } -BMP_PTR Bitmap::code() { +BitmapPtr Bitmap::code() { debugC(1, kCGEDebugBitmap, "Bitmap::code()"); if (!_m) @@ -421,17 +421,17 @@ bool Bitmap::loadVBM(XFile *f) { if (p) { if (_pal) { // Read in the palette - byte palData[PAL_SIZ]; - f->read(palData, PAL_SIZ); + byte palData[kPalSize]; + f->read(palData, kPalSize); const byte *srcP = palData; - for (int idx = 0; idx < PAL_CNT; ++idx, srcP += 3) { + for (int idx = 0; idx < kPalCount; idx++, srcP += 3) { _pal[idx]._r = *srcP; _pal[idx]._g = *(srcP + 1); _pal[idx]._b = *(srcP + 2); } } else - f->seek(f->mark() + PAL_SIZ); + f->seek(f->mark() + kPalSize); } } if ((_v = new uint8[n]) == NULL) @@ -473,7 +473,7 @@ bool Bitmap::loadBMP(XFile *f) { f->read((byte *)&bpal, sizeof(bpal)); if (f->_error == 0) { if (_pal) { - for (i = 0; i < 256; i ++) { + for (i = 0; i < 256; i++) { _pal[i]._r = bpal[i]._R; _pal[i]._g = bpal[i]._G; _pal[i]._b = bpal[i]._B; diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 6b931573f8d..30e11d08ec9 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -91,7 +91,7 @@ public: }; -typedef Bitmap *BMP_PTR; +typedef Bitmap *BitmapPtr; } // End of namespace CGE diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 55511e63822..1f987340b77 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -34,7 +34,7 @@ namespace CGE { -BtFile::BtFile(const char *name, IOMode mode, CRYPT *crpt) +BtFile::BtFile(const char *name, IOMode mode, Crypt *crpt) : IoHand(name, mode, crpt) { debugC(1, kCGEDebugFile, "BtFile::BtFile(%s, %d, crpt)", name, mode); diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index b589e86aee0..6b7155d43dc 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -83,7 +83,7 @@ class BtFile : public IoHand { void putPage(int lev, bool hard); BtPage *getPage(int lev, uint16 pgn); public: - BtFile(const char *name, IOMode mode, CRYPT *crpt); + BtFile(const char *name, IOMode mode, Crypt *crpt); virtual ~BtFile(); BtKeypack *find(const char *key); BtKeypack *next(); diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index ac9f782d840..c6144f624ba 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -33,24 +33,24 @@ namespace CGE { -IoBuf::IoBuf(IOMode mode, CRYPT *crpt) - : IoHand(mode, crpt), +IoBuf::IoBuf(IOMode mode, Crypt *crypt) + : IoHand(mode, crypt), _bufMark(0), _ptr(0), _lim(0) { - debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%d, crpt)", mode); + debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%d, crypt)", mode); _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); assert(_buff != NULL); } -IoBuf::IoBuf(const char *name, IOMode mode, CRYPT *crpt) - : IoHand(name, mode, crpt), +IoBuf::IoBuf(const char *name, IOMode mode, Crypt *crypt) + : IoHand(name, mode, crypt), _bufMark(0), _ptr(0), _lim(0) { - debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%s, %d, crpt)", name, mode); + debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%s, %d, crypt)", name, mode); _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); assert(_buff != NULL); @@ -220,9 +220,9 @@ void IoBuf::write(uint8 b) { uint16 CFile::_maxLineLen = kLineMaxSize; -CFile::CFile(const char *name, IOMode mode, CRYPT *crpt) - : IoBuf(name, mode, crpt) { - debugC(1, kCGEDebugFile, "CFile::CFile(%s, %d, crpt)", name, mode); +CFile::CFile(const char *name, IOMode mode, Crypt *crypt) + : IoBuf(name, mode, crypt) { + debugC(1, kCGEDebugFile, "CFile::CFile(%s, %d, crypt)", name, mode); } diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index 306ec5926be..6ed3b5e7502 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -42,12 +42,12 @@ protected: uint16 _lim; long _bufMark; uint16 _seed; - CRYPT *_crypt; + Crypt *_crypt; virtual void readBuf(); virtual void writeBuf(); public: - IoBuf(IOMode mode, CRYPT *crpt = NULL); - IoBuf(const char *name, IOMode mode, CRYPT *crpt = NULL); + IoBuf(IOMode mode, Crypt *crpt = NULL); + IoBuf(const char *name, IOMode mode, Crypt *crpt = NULL); virtual ~IoBuf(); uint16 read(void *buf, uint16 len); uint16 read(uint8 *buf); @@ -61,7 +61,7 @@ public: class CFile : public IoBuf { public: static uint16 _maxLineLen; - CFile(const char *name, IOMode mode = kModeRead, CRYPT *crpt = NULL); + CFile(const char *name, IOMode mode = kModeRead, Crypt *crpt = NULL); virtual ~CFile(); void flush(); long mark(); diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 8d2073b66f7..2baf1cde1e4 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -59,21 +59,21 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) void CGEEngine::initCaveValues() { if (_isDemo) { _mini = new byte[16384]; - CAVE_DX = 23; - CAVE_DY = 29; - CAVE_NX = 3; - CAVE_NY = 1; + _caveDx = 23; + _caveDy = 29; + _caveNx = 3; + _caveNy = 1; } else { _mini = new byte[65536]; - CAVE_DX = 9; - CAVE_DY = 10; - CAVE_NX = 8; - CAVE_NY = 3; + _caveDx = 9; + _caveDy = 10; + _caveNx = 8; + _caveNy = 3; } - CAVE_MAX = CAVE_NX * CAVE_NY; + _caveMax = _caveNx * _caveNy; if (_isDemo) { - _maxCaveArr[0] = CAVE_MAX; + _maxCaveArr[0] = _caveMax; _maxCaveArr[1] = -1; _maxCaveArr[2] = -1; _maxCaveArr[3] = -1; @@ -86,14 +86,14 @@ void CGEEngine::initCaveValues() { _maxCaveArr[4] = 24; }; - _heroXY = (Hxy *) malloc (sizeof(Hxy) * CAVE_MAX); - for (int i = 0; i < CAVE_MAX; i++) { + _heroXY = (Hxy *) malloc (sizeof(Hxy) * _caveMax); + for (int i = 0; i < _caveMax; i++) { _heroXY[i]._x = 0; _heroXY[i]._y = 0; } - _barriers = (Bar *) malloc (sizeof(Bar) * (1 + CAVE_MAX)); - for (int i = 0; i < CAVE_MAX + 1; i++) { + _barriers = (Bar *) malloc (sizeof(Bar) * (1 + _caveMax)); + for (int i = 0; i < _caveMax + 1; i++) { _barriers[i]._horz = 0xFF; _barriers[i]._vert = 0xFF; } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 9d2503a5cf7..7adc44fac6f 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -133,19 +133,19 @@ public: Sprite *_sprK2; Sprite *_sprK3; - uint8 CAVE_DX; - uint8 CAVE_DY; - uint8 CAVE_NX; - uint8 CAVE_NY; - uint16 CAVE_MAX; + uint8 _caveDx; + uint8 _caveDy; + uint8 _caveNx; + uint8 _caveNy; + uint16 _caveMax; Hxy *_heroXY; Bar *_barriers; Common::RandomSource _randomSource; - byte * _mini; - BMP_PTR * _miniShp; - BMP_PTR * _miniShpList; - int _startGameSlot; + byte *_mini; + BitmapPtr *_miniShp; + BitmapPtr *_miniShpList; + int _startGameSlot; virtual Common::Error run(); GUI::Debugger *getDebugger() { @@ -168,7 +168,7 @@ public: bool showTitle(const char *name); void movie(const char *ext); void takeName(); - void inf(const char *txt); + void inf(const char *text); void selectSound(); void dummy() {} void NONE(); @@ -202,7 +202,7 @@ public: void saveMapping(); void saveSound(); void heroCover(int cvr); - void trouble(int seq, int txt); + void trouble(int seq, int text); void offUse(); void tooFar(); void loadHeroXY(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 123501047ae..37449fd5dd8 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -109,30 +109,30 @@ void CGEEngine::syncHeader(Common::Serializer &s) { s.syncAsUint16LE(_now); s.syncAsUint16LE(_oldLev); s.syncAsUint16LE(_demoText); - for (i = 0; i < 5; ++i) + for (i = 0; i < 5; i++) s.syncAsUint16LE(_game); s.syncAsSint16LE(i); // unused VGA::Mono variable s.syncAsUint16LE(_music); s.syncBytes(_volume, 2); - for (i = 0; i < 4; ++i) + for (i = 0; i < 4; i++) s.syncAsUint16LE(_flag[i]); initCaveValues(); if (s.isLoading()) { //TODO: Fix the memory leak when the game is already running - _heroXY = (Hxy *) malloc (sizeof(Hxy) * CAVE_MAX); - _barriers = (Bar *) malloc (sizeof(Bar) * (1 + CAVE_MAX)); + _heroXY = (Hxy *) malloc (sizeof(Hxy) * _caveMax); + _barriers = (Bar *) malloc (sizeof(Bar) * (1 + _caveMax)); } - for (i = 0; i < CAVE_MAX; ++i) { + for (i = 0; i < _caveMax; i++) { s.syncAsSint16LE(_heroXY[i]._x); s.syncAsUint16LE(_heroXY[i]._y); } - for (i = 0; i < 1 + CAVE_MAX; ++i) { + for (i = 0; i < 1 + _caveMax; i++) { s.syncAsByte(_barriers[i]._horz); s.syncAsByte(_barriers[i]._vert); } - for (i = 0; i < kPocketNX; ++i) + for (i = 0; i < kPocketNX; i++) s.syncAsUint16LE(_pocref[i]); if (s.isSaving()) { @@ -409,15 +409,15 @@ void CGEEngine::heroCover(int cvr) { _snail->addCom(kSnCover, 1, cvr, NULL); } -void CGEEngine::trouble(int seq, int txt) { - debugC(1, kCGEDebugEngine, "CGEEngine::trouble(%d, %d)", seq, txt); +void CGEEngine::trouble(int seq, int text) { + debugC(1, kCGEDebugEngine, "CGEEngine::trouble(%d, %d)", seq, text); _hero->park(); _snail->addCom(kSnWait, -1, -1, _hero); _snail->addCom(kSnSeq, -1, seq, _hero); _snail->addCom(kSnSound, -1, 2, _hero); _snail->addCom(kSnWait, -1, -1, _hero); - _snail->addCom(kSnSay, 1, txt, _hero); + _snail->addCom(kSnSay, 1, text, _hero); } void CGEEngine::offUse() { @@ -444,7 +444,7 @@ void CGEEngine::loadHeroXY() { void CGEEngine::loadMapping() { debugC(1, kCGEDebugEngine, "CGEEngine::loadMapping()"); - if (_now <= CAVE_MAX) { + if (_now <= _caveMax) { INI_FILE cf(progName(".TAB")); if (!cf._error) { memset(Cluster::_map, 0, sizeof(Cluster::_map)); @@ -458,7 +458,7 @@ Square::Square(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { _flags._kill = true; _flags._bDel = false; - BMP_PTR *MB = new BMP_PTR[2]; + BitmapPtr *MB = new BitmapPtr[2]; MB[0] = new Bitmap("BRICK", true); MB[1] = NULL; setShapeList(MB); @@ -480,7 +480,7 @@ void CGEEngine::setMapBrick(int x, int z) { Square *s = new Square(this); if (s) { static char n[] = "00:00"; - s->gotoxy(x * MAP_XGRID, MAP_TOP + z * MAP_ZGRID); + s->gotoxy(x * kMapGridX, kMapTop + z * kMapGridZ); wtom(x, n + 0, 10, 2); wtom(z, n + 3, 10, 2); Cluster::_map[z][x] = 1; @@ -688,8 +688,8 @@ void CGEEngine::switchCave(int cav) { if (!_isDemo) _vga->_spareQ->_show = 0; } - _cavLight->gotoxy(CAVE_X + ((_now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, - CAVE_Y + ((_now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); + _cavLight->gotoxy(CAVE_X + ((_now - 1) % _caveNx) * _caveDx + CAVE_SX, + CAVE_Y + ((_now - 1) / _caveNx) * _caveDy + CAVE_SY); killText(); if (!_startupMode) keyClick(); @@ -837,9 +837,9 @@ void System::touch(uint16 mask, int x, int y) { _infoLine->update(NULL); if (y >= kWorldHeight ) { if (x < kButtonX) { // select cave? - if (y >= CAVE_Y && y < CAVE_Y + _vm->CAVE_NY * _vm->CAVE_DY && - x >= CAVE_X && x < CAVE_X + _vm->CAVE_NX * _vm->CAVE_DX && !_vm->_game) { - cav = ((y - CAVE_Y) / _vm->CAVE_DY) * _vm->CAVE_NX + (x - CAVE_X) / _vm->CAVE_DX + 1; + if (y >= CAVE_Y && y < CAVE_Y + _vm->_caveNy * _vm->_caveDy && + x >= CAVE_X && x < CAVE_X + _vm->_caveNx * _vm->_caveDx && !_vm->_game) { + cav = ((y - CAVE_Y) / _vm->_caveDy) * _vm->_caveNx + (x - CAVE_X) / _vm->_caveDx + 1; if (cav > _vm->_maxCave) cav = 0; } else { @@ -861,7 +861,7 @@ void System::touch(uint16 mask, int x, int y) { _vm->switchCave(cav); if (!_horzLine->_flags._hide) { - if (y >= MAP_TOP && y < MAP_TOP + MAP_HIG) { + if (y >= kMapTop && y < kMapTop + kMapHig) { int8 x1, z1; XZ(x, y).split(x1, z1); Cluster::_map[z1][x1] = 1; @@ -869,7 +869,7 @@ void System::touch(uint16 mask, int x, int y) { } } else { if (!_talk && _snail->idle() && _hero - && y >= MAP_TOP && y < MAP_TOP + MAP_HIG && !_vm->_game) { + && y >= kMapTop && y < kMapTop + kMapHig && !_vm->_game) { _hero->findWay(XZ(x, y)); } } @@ -964,9 +964,9 @@ void CGEEngine::switchMapping() { if (_horzLine->_flags._hide) { int i; - for (i = 0; i < MAP_ZCNT; i++) { + for (i = 0; i < kMapZCnt; i++) { int j; - for (j = 0; j < MAP_XCNT; j++) { + for (j = 0; j < kMapXCnt; j++) { if (Cluster::_map[i][j]) setMapBrick(j, i); } @@ -974,7 +974,7 @@ void CGEEngine::switchMapping() { } else { Sprite *s; for (s = _vga->_showQ->first(); s; s = s->_next) - if (s->_w == MAP_XGRID && s->_h == MAP_ZGRID) + if (s->_w == kMapGridX && s->_h == kMapGridZ) _snail_->addCom(kSnKill, -1, 0, s); } _horzLine->_flags._hide = !_horzLine->_flags._hide; @@ -1526,7 +1526,7 @@ void CGEEngine::runGame() { killMidi(); if (_mini && INI_FILE::exist("MINI.SPR")) { - _miniShp = new BMP_PTR[2]; + _miniShp = new BitmapPtr[2]; _miniShp[0] = _miniShp[1] = NULL; uint8 *ptr = (uint8 *) &*_mini; @@ -1568,7 +1568,7 @@ void CGEEngine::runGame() { _debugLine->_z = 126; _vga->_showQ->insert(_debugLine); - _horzLine->_y = MAP_TOP - (MAP_TOP > 0); + _horzLine->_y = kMapTop - (kMapTop > 0); _horzLine->_z = 126; _vga->_showQ->insert(_horzLine); @@ -1579,8 +1579,8 @@ void CGEEngine::runGame() { _startupMode = 0; _snail->addCom(kSnLevel, -1, _oldLev, &_cavLight); - _cavLight->gotoxy(CAVE_X + ((_now - 1) % CAVE_NX) * CAVE_DX + CAVE_SX, - CAVE_Y + ((_now - 1) / CAVE_NX) * CAVE_DY + CAVE_SY); + _cavLight->gotoxy(CAVE_X + ((_now - 1) % _caveNx) * _caveDx + CAVE_SX, + CAVE_Y + ((_now - 1) / _caveNx) * _caveDy + CAVE_SY); caveUp(); _keyboard->setClient(_sys); @@ -1630,11 +1630,11 @@ bool CGEEngine::showTitle(const char *name) { return false; Bitmap::_pal = Vga::_sysPal; - BMP_PTR *LB = new BMP_PTR[2]; + BitmapPtr *LB = new BitmapPtr[2]; LB[0] = new Bitmap(name, true); LB[1] = NULL; Bitmap::_pal = NULL; - bool usr_ok = false; + bool userOk = false; Sprite D(this, LB); D._flags._kill = true; @@ -1675,7 +1675,7 @@ bool CGEEngine::showTitle(const char *name) { if (_mode < 2) { if (_isDemo) { strcpy(_usrFnam, progName(kSvgExt)); - usr_ok = true; + userOk = true; } else { #ifndef EVA // At this point the game originally set the protection variables @@ -1689,7 +1689,7 @@ bool CGEEngine::showTitle(const char *name) { // For ScummVM, skip prompting for name if a savegame in slot 0 already exists if ((_startGameSlot == -1) && savegameExists(0)) { strcpy(_usrFnam, "User"); - usr_ok = true; + userOk = true; } else { for (takeName(); GetText::_ptr;) { mainLoop(); @@ -1697,7 +1697,7 @@ bool CGEEngine::showTitle(const char *name) { return false; } if (_keyboard->last() == Enter && *_usrFnam) - usr_ok = true; + userOk = true; } //Mouse.Off(); _vga->_showQ->clear(); @@ -1705,7 +1705,7 @@ bool CGEEngine::showTitle(const char *name) { #endif } - if (usr_ok && _mode == 0) { + if (userOk && _mode == 0) { if (savegameExists(0)) { // Load the savegame loadGame(0, NULL, true); // only system vars @@ -1728,7 +1728,7 @@ bool CGEEngine::showTitle(const char *name) { if (_isDemo) return true; else - return (_mode == 2 || usr_ok); + return (_mode == 2 || userOk); } void CGEEngine::cge_main() { diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index dc6e65722d0..1c2738f62e9 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -110,7 +110,7 @@ bool Keyboard::getKey(uint16 keycode, int &cgeCode) { } // Scan through the ScummVM mapping list - for (int idx = 0; idx < 0x60; ++idx) { + for (int idx = 0; idx < 0x60; idx++) { if (_scummVmCodes[idx] == keycode) { cgeCode = idx; return true; @@ -163,13 +163,13 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) Common::copy(ms, ms + 2, seq); setSeq(seq); - BMP_PTR *MC = new BMP_PTR[3]; + BitmapPtr *MC = new BitmapPtr[3]; MC[0] = new Bitmap("MOUSE", true); MC[1] = new Bitmap("DUMMY", true); MC[2] = NULL; setShapeList(MC); - gotoxy(kScrWidth/2, kScrHeight/2); + gotoxy(kScrWidth / 2, kScrHeight / 2); _z = 127; step(1); } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 1947fc60619..8e141a8be41 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -110,8 +110,8 @@ const char *progName(const char *ext) { return buf; } -char *mergeExt(char *buf, const char *nam, const char *ext) { - strcpy(buf, nam); +char *mergeExt(char *buf, const char *name, const char *ext) { + strcpy(buf, name); char *dot = strrchr(buf, '.'); if (!dot) strcat(buf, ext); @@ -119,8 +119,8 @@ char *mergeExt(char *buf, const char *nam, const char *ext) { return buf; } -char *forceExt(char *buf, const char *nam, const char *ext) { - strcpy(buf, nam); +char *forceExt(char *buf, const char *name, const char *ext) { + strcpy(buf, name); char *dot = strrchr(buf, '.'); if (dot) *dot = '\0'; @@ -204,13 +204,13 @@ char *dwtom(uint32 val, char *str, int radix, int len) { return str; } -IoHand::IoHand(IOMode mode, CRYPT *crpt) - : XFile(mode), _crypt(crpt), _seed(kCryptSeed) { +IoHand::IoHand(IOMode mode, Crypt *crypt) + : XFile(mode), _crypt(crypt), _seed(kCryptSeed) { _file = new Common::File(); } -IoHand::IoHand(const char *name, IOMode mode, CRYPT *crpt) - : XFile(mode), _crypt(crpt), _seed(kCryptSeed) { +IoHand::IoHand(const char *name, IOMode mode, Crypt *crypt) + : XFile(mode), _crypt(crypt), _seed(kCryptSeed) { // TODO: Check if WRI and/or UPD modes are needed, and map to a save file assert(mode == kModeRead); @@ -303,11 +303,11 @@ DataCk *loadWave(XFile *file) { return NULL; } -int takeEnum(const char **tab, const char *txt) { +int takeEnum(const char **tab, const char *text) { const char **e; - if (txt) { + if (text) { for (e = tab; *e; e++) { - if (scumm_stricmp(txt, *e) == 0) { + if (scumm_stricmp(text, *e) == 0) { return e - tab; } } @@ -332,7 +332,7 @@ int new_random(int range) { } DataCk::~DataCk() { - if (!_e && _buf) + if (_buf) free(_buf); } } // End of namespace CGE diff --git a/engines/cge/general.h b/engines/cge/general.h index d55193d85c4..57991f21259 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -47,7 +47,7 @@ struct Dac { uint8 _b; }; -typedef uint16 CRYPT(void *buf, uint16 siz, uint16 seed); +typedef uint16 Crypt(void *buf, uint16 siz, uint16 seed); template void swap(T &A, T &B) { @@ -92,10 +92,10 @@ class IoHand : public XFile { protected: Common::File *_file; uint16 _seed; - CRYPT *_crypt; + Crypt *_crypt; public: - IoHand(const char *name, IOMode mode = kModeRead, CRYPT crypt = NULL); - IoHand(IOMode mode = kModeRead, CRYPT *crpt = NULL); + IoHand(const char *name, IOMode mode = kModeRead, Crypt crypt = NULL); + IoHand(IOMode mode = kModeRead, Crypt *crypt = NULL); virtual ~IoHand(); static bool exist(const char *name); uint16 read(void *buf, uint16 len); @@ -105,24 +105,21 @@ public: long seek(long pos); }; -CRYPT XCrypt; -CRYPT RCrypt; +Crypt XCrypt; +Crypt RCrypt; uint16 atow(const char *a); uint16 xtow(const char *x); char *wtom(uint16 val, char *str, int radix, int len); char *dwtom(uint32 val, char *str, int radix, int len); -int takeEnum(const char **tab, const char *txt); +int takeEnum(const char **tab, const char *text); uint16 chkSum(void *m, uint16 n); long timer(); -char *mergeExt(char *buf, const char *nam, const char *ext); -char *forceExt(char *buf, const char *nam, const char *ext); -int driveCD(unsigned drv); +char *mergeExt(char *buf, const char *name, const char *ext); +char *forceExt(char *buf, const char *name, const char *ext); // MISSING FUNCTIONS void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)); const char *progName(const char *ext = NULL); -char *mergeExt(char *buf, const char *nam, const char *ext); -char *forceExt(char *buf, const char *nam, const char *ext); unsigned fastRand(); unsigned fastRand(unsigned s); uint16 rCrypt(void *buf, uint16 siz, uint16 seed); @@ -130,7 +127,7 @@ uint16 atow(const char *a); uint16 xtow(const char *x); char *wtom(uint16 val, char *str, int radix, int len); char *dwtom(uint32 val, char * str, int radix, int len); -int takeEnum(const char **tab, const char *txt); +int takeEnum(const char **tab, const char *text); long timer(); int new_random(int range); } // End of namespace CGE diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index fa30b3a9d1c..f64f4b2619e 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -41,7 +41,7 @@ GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) _ptr = this; _mode = kTBRect; - _ts = new BMP_PTR[2]; + _ts = new BitmapPtr[2]; _ts[0] = box((i + 3) & ~3, 2 * kTextVMargin + 2 * kFontHigh + kTextLineSpace); _ts[1] = NULL; setShapeList(_ts); diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h index d97a4f3dd3a..10c05e7cfb4 100644 --- a/engines/cge/mixer.h +++ b/engines/cge/mixer.h @@ -40,8 +40,8 @@ namespace CGE { #define kMixName 105 // sprite name class Mixer : public Sprite { - BMP_PTR _mb[2]; - BMP_PTR _lb[kMixMax + 1]; + BitmapPtr _mb[2]; + BitmapPtr _lb[kMixMax + 1]; Sprite *_led[2]; int _fall; void update(); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 2cd38d671fc..03cb43f4f1a 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -390,7 +390,7 @@ void CGEEngine::feedSnail(Sprite *spr, SnList snq) { } } -const char *Snail::_comTxt[] = { +const char *Snail::_comText[] = { "LABEL", "PAUSE", "WAIT", "LEVEL", "HIDE", "SAY", "INF", "TIME", "CAVE", "KILL", "RSEQ", "SEQ", "SEND", "SWAP", "KEEP", @@ -871,10 +871,10 @@ void CGEEngine::snFlash(bool on) { debugC(1, kCGEDebugEngine, "CGEEngine::snFlash(%s)", on ? "true" : "false"); if (on) { - Dac *pal = (Dac *) malloc(sizeof(Dac) * PAL_CNT); + Dac *pal = (Dac *) malloc(sizeof(Dac) * kPalCount); if (pal) { - memcpy(pal, Vga::_sysPal, PAL_SIZ); - for (int i = 0; i < PAL_CNT; i++) { + memcpy(pal, Vga::_sysPal, kPalSize); + for (int i = 0; i < kPalCount; i++) { register int c; c = pal[i]._r << 1; pal[i]._r = (c < 64) ? c : 63; diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 2b488cd5b2d..2d12963f2c5 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -67,7 +67,7 @@ public: bool _busy; bool _textDelay; uint32 _timerExpiry; - static const char *_comTxt[]; + static const char *_comText[]; bool _talkEnable; Snail(CGEEngine *vm, bool turbo); ~Snail(); diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 4a2df79f24e..db44536267f 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -73,25 +73,12 @@ uint16 Font::width(const char *text) { return w; } - -/* -void Font::save() { - CFILE f((const char *) _path, WRI); - if (!f._error) { - f.Write(_wid, WID_SIZ); - if (!f._error) - f.Write(_map, _pos[POS_SIZ - 1] + _wid[WID_SIZ - 1]); - } -} -*/ - - -Talk::Talk(CGEEngine *vm, const char *tx, TextBoxStyle mode) +Talk::Talk(CGEEngine *vm, const char *text, TextBoxStyle mode) : Sprite(vm, NULL), _mode(mode), _vm(vm) { _ts = NULL; _flags._syst = true; - update(tx); + update(text); } @@ -101,18 +88,6 @@ Talk::Talk(CGEEngine *vm) _flags._syst = true; } - -/* -Talk::~Talk() { - for (uint16 i = 0; i < ShpCnt; i++) { - if (FP_SEG(_shpList[i]) != _DS) { // small model: always false - delete _shpList[i]; - ShpList[i] = NULL; - } - } -} -*/ - Font *Talk::_font; void Talk::init() { @@ -124,17 +99,18 @@ void Talk::deinit() { } -void Talk::update(const char *tx) { +void Talk::update(const char *text) { uint16 vmarg = (_mode) ? kTextVMargin : 0; uint16 hmarg = (_mode) ? kTextHMargin : 0; - uint16 mw = 0, mh, ln = vmarg; + uint16 mw = 0; + uint16 ln = vmarg; const char *p; uint8 *m; if (!_ts) { uint16 k = 2 * hmarg; - mh = 2 * vmarg + kFontHigh; - for (p = tx; *p; p++) { + uint16 mh = 2 * vmarg + kFontHigh; + for (p = text; *p; p++) { if (*p == '|' || *p == '\n') { mh += kFontHigh + kTextLineSpace; if (k > mw) @@ -146,19 +122,19 @@ void Talk::update(const char *tx) { if (k > mw) mw = k; - _ts = new BMP_PTR[2]; + _ts = new BitmapPtr[2]; _ts[0] = box(mw, mh); _ts[1] = NULL; } m = _ts[0]->_m + ln * mw + hmarg; - while (* tx) { - if (*tx == '|' || *tx == '\n') + while (*text) { + if (*text == '|' || *text == '\n') m = _ts[0]->_m + (ln += kFontHigh + kTextLineSpace) * mw + hmarg; else { - int cw = _font->_wid[(unsigned char)*tx], i; - uint8 *f = _font->_map + _font->_pos[(unsigned char)*tx]; + int cw = _font->_wid[(unsigned char)*text], i; + uint8 *f = _font->_map + _font->_pos[(unsigned char)*text]; for (i = 0; i < cw; i++) { uint8 *pp = m; uint16 n; @@ -172,7 +148,7 @@ void Talk::update(const char *tx) { m++; } } - tx++; + text++; } _ts[0]->code(); setShapeList(_ts); @@ -239,7 +215,7 @@ void Talk::putLine(int line, const char *text) { // clear whole rectangle assert((rsiz % lsiz) == 0); - for (int planeCtr = 0; planeCtr < 4; ++planeCtr, p += psiz) { + for (int planeCtr = 0; planeCtr < 4; planeCtr++, p += psiz) { for (byte *pDest = p; pDest < (p + (rsiz - lsiz)); pDest += lsiz) Common::copy(p - lsiz, p, pDest); } @@ -273,9 +249,9 @@ void Talk::putLine(int line, const char *text) { } -InfoLine::InfoLine(CGEEngine *vm, uint16 w) : Talk(vm), _oldTxt(NULL), _vm(vm) { +InfoLine::InfoLine(CGEEngine *vm, uint16 w) : Talk(vm), _oldText(NULL), _vm(vm) { if (!_ts) { - _ts = new BMP_PTR[2]; + _ts = new BitmapPtr[2]; _ts[1] = NULL; } @@ -284,8 +260,8 @@ InfoLine::InfoLine(CGEEngine *vm, uint16 w) : Talk(vm), _oldTxt(NULL), _vm(vm) { } -void InfoLine::update(const char *tx) { - if (tx != _oldTxt) { +void InfoLine::update(const char *text) { + if (text != _oldText) { uint16 w = _ts[0]->_w; uint16 h = _ts[0]->_h; uint8 *v = (uint8 *) _ts[0]->_v; @@ -306,12 +282,12 @@ void InfoLine::update(const char *tx) { } // paint text line - if (tx) { + if (text) { uint8 *p = v + 2, * q = p + size; - while (*tx) { - uint16 cw = _font->_wid[(unsigned char)*tx]; - uint8 *fp = _font->_map + _font->_pos[(unsigned char)*tx]; + while (*text) { + uint16 cw = _font->_wid[(unsigned char)*text]; + uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; for (uint16 i = 0; i < cw; i++) { register uint16 b = fp[i]; @@ -324,10 +300,10 @@ void InfoLine::update(const char *tx) { if (p >= q) p = p - size + 1; } - tx++; + text++; } } - _oldTxt = tx; + _oldText = text; } } diff --git a/engines/cge/talk.h b/engines/cge/talk.h index d9c29261f6c..71db57c887c 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -66,10 +66,10 @@ public: class Talk : public Sprite { protected: TextBoxStyle _mode; - BMP_PTR *_ts; + BitmapPtr *_ts; Bitmap *box(uint16 w, uint16 h); public: - Talk(CGEEngine *vm, const char *tx, TextBoxStyle mode); + Talk(CGEEngine *vm, const char *text, TextBoxStyle mode); Talk(CGEEngine *vm); //~TALK(); @@ -77,7 +77,7 @@ public: static void init(); static void deinit(); - virtual void update(const char *tx); + virtual void update(const char *text); virtual void update() {} void putLine(int line, const char *text); private: @@ -85,10 +85,10 @@ private: }; class InfoLine : public Talk { - const char *_oldTxt; + const char *_oldText; public: InfoLine(CGEEngine *vm, uint16 wid); - void update(const char *tx); + void update(const char *text); private: CGEEngine *_vm; }; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index f688546810d..485ba00ad10 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -40,13 +40,13 @@ Talk *_talk = NULL; Text::Text(CGEEngine *vm, const char *fname, int size) : _vm(vm) { _cache = new Han[size]; - mergeExt(_fileName, fname, SAY_EXT); + mergeExt(_fileName, fname, kSayExt); if (!INI_FILE::exist(_fileName)) error("No talk (%s)\n", _fileName); for (_size = 0; _size < size; _size++) { _cache[_size]._ref = 0; - _cache[_size]._txt = NULL; + _cache[_size]._text = NULL; } } @@ -62,8 +62,8 @@ void Text::clear(int from, int upto) { for (p = _cache, q = p + _size; p < q; p++) { if (p->_ref && p->_ref >= from && p->_ref < upto) { p->_ref = 0; - delete[] p->_txt; - p->_txt = NULL; + delete[] p->_text; + p->_text = NULL; } } } @@ -105,8 +105,8 @@ void Text::preload(int from, int upto) { p = &_cache[find(ref)]; if (p < CacheLim) { - delete[] p->_txt; - p->_txt = NULL; + delete[] p->_text; + p->_text = NULL; } else p = &_cache[find(0)]; if (p >= CacheLim) @@ -114,10 +114,10 @@ void Text::preload(int from, int upto) { s += strlen(s); if (s < line + n) ++s; - if ((p->_txt = new char[strlen(s) + 1]) == NULL) + if ((p->_text = new char[strlen(s) + 1]) == NULL) break; p->_ref = ref; - strcpy(p->_txt, s); + strcpy(p->_text, s); } } } @@ -151,9 +151,9 @@ char *Text::load(int idx, int ref) { if (s < line + n) ++s; p->_ref = ref; - if ((p->_txt = new char[strlen(s) + 1]) == NULL) + if ((p->_text = new char[strlen(s) + 1]) == NULL) return NULL; - return strcpy(p->_txt, s); + return strcpy(p->_text, s); } } return NULL; @@ -163,10 +163,10 @@ char *Text::load(int idx, int ref) { char *Text::getText(int ref) { int i; if ((i = find(ref)) < _size) - return _cache[i]._txt; + return _cache[i]._text; if ((i = find(0)) >= _size) { - clear(SYSTXT_MAX); // clear non-system + clear(kSysTextMax); // clear non-system if ((i = find(0)) >= _size) { clear(); // clear all i = 0; @@ -176,9 +176,9 @@ char *Text::getText(int ref) { } -void Text::say(const char *txt, Sprite *spr) { +void Text::say(const char *text, Sprite *spr) { killText(); - _talk = new Talk(_vm, txt, kTBRound); + _talk = new Talk(_vm, text, kTBRound); if (_talk) { bool east = spr->_flags._east; int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2); @@ -217,11 +217,11 @@ void Text::say(const char *txt, Sprite *spr) { } } -void CGEEngine::inf(const char *txt) { - debugC(1, kCGEDebugEngine, "CGEEngine::inf(%s)", txt); +void CGEEngine::inf(const char *text) { + debugC(1, kCGEDebugEngine, "CGEEngine::inf(%s)", text); killText(); - _talk = new Talk(this, txt, kTBRect); + _talk = new Talk(this, text, kTBRect); if (_talk) { _talk->_flags._kill = true; _talk->_flags._bDel = true; diff --git a/engines/cge/text.h b/engines/cge/text.h index 196bfc4edb8..6ed5b32b229 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -33,11 +33,9 @@ namespace CGE { -#ifndef SYSTXT_MAX -#define SYSTXT_MAX 1000 -#endif +#define kSysTextMax 1000 -#define SAY_EXT ".SAY" +#define kSayExt ".SAY" #define NOT_VGA_TEXT 90 #define BAD_CHIP_TEXT 91 @@ -54,7 +52,7 @@ namespace CGE { class Text { struct Han { int _ref; - char *_txt; + char *_text; } *_cache; int _size; char _fileName[kPathMax]; @@ -66,7 +64,7 @@ public: void clear(int from = 1, int upto = 0x7FFF); void preload(int from = 1, int upto = 0x7FFF); char *getText(int ref); - void say(const char *txt, Sprite *spr); + void say(const char *text, Sprite *spr); private: CGEEngine *_vm; }; @@ -74,9 +72,9 @@ private: extern Talk *_talk; extern Text *_text; -void say(const char *txt, Sprite *spr); +void say(const char *text, Sprite *spr); void sayTime(Sprite *spr); -void inf(const char *txt); +void inf(const char *text); void killText(); } // End of namespace CGE diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 9b30e02e4da..cc715da03c0 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -211,7 +211,7 @@ Sprite *locate(int ref) { return (spr) ? spr : _vga->_spareQ->locate(ref); } -Sprite::Sprite(CGEEngine *vm, BMP_PTR *shpP) +Sprite::Sprite(CGEEngine *vm, BitmapPtr *shpP) : _x(0), _y(0), _z(0), _nearPtr(0), _takePtr(0), _next(NULL), _prev(NULL), _seqPtr(NO_SEQ), _time(0), //Delay(0), _ext(NULL), _ref(-1), _cave(0), _vm(vm) { @@ -234,7 +234,7 @@ Sprite::~Sprite() { } -BMP_PTR Sprite::shp() { +BitmapPtr Sprite::shp() { register SprExt *e = _ext; if (e) if (e->_seq) { @@ -252,17 +252,17 @@ BMP_PTR Sprite::shp() { } -BMP_PTR *Sprite::setShapeList(BMP_PTR *shpP) { - BMP_PTR *r = (_ext) ? _ext->_shpList : NULL; +BitmapPtr *Sprite::setShapeList(BitmapPtr *shpP) { + BitmapPtr *r = (_ext) ? _ext->_shpList : NULL; _shpCnt = 0; _w = 0; _h = 0; if (shpP) { - BMP_PTR *p; + BitmapPtr *p; for (p = shpP; *p; p++) { - BMP_PTR b = (*p); // ->Code(); + BitmapPtr b = (*p); // ->Code(); if (b->_w > _w) _w = b->_w; if (b->_h > _h) @@ -280,7 +280,7 @@ BMP_PTR *Sprite::setShapeList(BMP_PTR *shpP) { void Sprite::moveShapes(uint8 *buf) { - BMP_PTR *p; + BitmapPtr *p; for (p = _ext->_shpList; *p; p++) { buf += (*p)->moveVmap(buf); } @@ -336,16 +336,16 @@ Snail::Com *Sprite::snList(SnList type) { } -void Sprite::setName(char *n) { +void Sprite::setName(char *name) { if (_ext) { if (_ext->_name) { delete[] _ext->_name; _ext->_name = NULL; } - if (n) { - _ext->_name = new char[strlen(n) + 1]; + if (name) { + _ext->_name = new char[strlen(name) + 1]; assert(_ext->_name != NULL); - strcpy(_ext->_name, n); + strcpy(_ext->_name, name); } } } @@ -358,7 +358,7 @@ Sprite *Sprite::expand() { if (*_file) { static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; char line[kLineMax], fname[kPathMax]; - BMP_PTR *shplist = new BMP_PTR[_shpCnt + 1]; + BitmapPtr *shplist = new BitmapPtr[_shpCnt + 1]; Seq *seq = NULL; int shpcnt = 0, seqcnt = 0, @@ -419,7 +419,7 @@ Sprite *Sprite::expand() { nea = (Snail::Com *) realloc(nea, (neacnt + 1) * sizeof(*nea)); assert(nea != NULL); Snail::Com *c = &nea[neacnt++]; - if ((c->_com = (SnCom)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) + if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0) error("Bad NEAR in %d [%s]", lcnt, fname); c->_ref = atoi(strtok(NULL, " \t,;/")); c->_val = atoi(strtok(NULL, " \t,;/")); @@ -432,7 +432,7 @@ Sprite *Sprite::expand() { tak = (Snail::Com *) realloc(tak, (takcnt + 1) * sizeof(*tak)); assert(tak != NULL); Snail::Com *c = &tak[takcnt++]; - if ((c->_com = (SnCom)takeEnum(Snail::_comTxt, strtok(NULL, " \t,;/"))) < 0) + if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0) error("Bad NEAR in %d [%s]", lcnt, fname); c->_ref = atoi(strtok(NULL, " \t,;/")); c->_val = atoi(strtok(NULL, " \t,;/")); @@ -528,7 +528,7 @@ void Sprite::tick() { void Sprite::makeXlat(uint8 *x) { if (_ext) { - BMP_PTR *b; + BitmapPtr *b; if (_flags._xlat) killXlat(); @@ -541,7 +541,7 @@ void Sprite::makeXlat(uint8 *x) { void Sprite::killXlat() { if (_flags._xlat && _ext) { - BMP_PTR *b; + BitmapPtr *b; uint8 *m = (*_ext->_shpList)->_m; free(m); @@ -616,10 +616,10 @@ void Sprite::hide() { } -BMP_PTR Sprite::ghost() { +BitmapPtr Sprite::ghost() { register SprExt *e = _ext; if (e->_b1) { - BMP_PTR bmp = new Bitmap(0, 0, (uint8 *)NULL); + BitmapPtr bmp = new Bitmap(0, 0, (uint8 *)NULL); assert(bmp != NULL); bmp->_w = e->_b1->_w; bmp->_h = e->_b1->_h; @@ -785,37 +785,35 @@ Graphics::Surface *Vga::_page[4]; Dac *Vga::_sysPal; void Vga::init() { - for (int idx = 0; idx < 4; ++idx) { + for (int idx = 0; idx < 4; idx++) { _page[idx] = new Graphics::Surface(); _page[idx]->create(320, 200, Graphics::PixelFormat::createFormatCLUT8()); } - _sysPal = new Dac[PAL_CNT]; + _sysPal = new Dac[kPalCount]; } void Vga::deinit() { - for (int idx = 0; idx < 4; ++idx) { + for (int idx = 0; idx < 4; idx++) { _page[idx]->free(); delete _page[idx]; } - delete[] _sysPal; } Vga::Vga(int mode) : _frmCnt(0), _oldMode(0), _oldScreen(NULL), _statAdr(VGAST1_), - _msg(NULL), _nam(NULL), _setPal(false), _mono(0) { + _msg(NULL), _name(NULL), _setPal(false), _mono(0) { _oldColors = NULL; _newColors = NULL; _showQ = new Queue(true); _spareQ = new Queue(false); bool std = true; - int i; - for (i = 10; i < 20; i++) { - char *txt = _text->getText(i); - if (txt) { - debugN("%s", txt); + for (int i = 10; i < 20; i++) { + char *text = _text->getText(i); + if (text) { + debugN("%s", text); std = false; } } @@ -826,8 +824,8 @@ Vga::Vga(int mode) setStatAdr(); if (_statAdr != VGAST1_) _mono++; - _oldColors = (Dac *) malloc(sizeof(Dac) * PAL_CNT); - _newColors = (Dac *) malloc(sizeof(Dac) * PAL_CNT); + _oldColors = (Dac *) malloc(sizeof(Dac) * kPalCount); + _newColors = (Dac *) malloc(sizeof(Dac) * kPalCount); _oldScreen = SaveScreen(); getColors(_oldColors); sunset(); @@ -853,8 +851,8 @@ Vga::~Vga() { free(_newColors); if (_msg) buffer = Common::String(_msg); - if (_nam) - buffer = buffer + " [" + _nam + "]"; + if (_name) + buffer = buffer + " [" + _name + "]"; debugN("%s", buffer.c_str()); @@ -936,14 +934,14 @@ int Vga::setMode(int mode) { void Vga::getColors(Dac *tab) { - byte palData[PAL_SIZ]; - g_system->getPaletteManager()->grabPalette(palData, 0, PAL_CNT); + byte palData[kPalSize]; + g_system->getPaletteManager()->grabPalette(palData, 0, kPalCount); palToDac(palData, tab); } void Vga::palToDac(const byte *palData, Dac *tab) { const byte *colP = palData; - for (int idx = 0; idx < PAL_CNT; ++idx, colP += 3) { + for (int idx = 0; idx < kPalCount; idx++, colP += 3) { tab[idx]._r = *colP >> 2; tab[idx]._g = *(colP + 1) >> 2; tab[idx]._b = *(colP + 2) >> 2; @@ -951,7 +949,7 @@ void Vga::palToDac(const byte *palData, Dac *tab) { } void Vga::dacToPal(const Dac *tab, byte *palData) { - for (int idx = 0; idx < PAL_CNT; ++idx, palData += 3) { + for (int idx = 0; idx < kPalCount; idx++, palData += 3) { *palData = tab[idx]._r << 2; *(palData + 1) = tab[idx]._g << 2; *(palData + 2) = tab[idx]._b << 2; @@ -960,7 +958,7 @@ void Vga::dacToPal(const Dac *tab, byte *palData) { void Vga::setColors(Dac *tab, int lum) { Dac *palP = tab, *destP = _newColors; - for (int idx = 0; idx < PAL_CNT; ++idx, ++palP, ++destP) { + for (int idx = 0; idx < kPalCount; idx++, palP++, destP++) { destP->_r = (palP->_r * lum) >> 6; destP->_g = (palP->_g * lum) >> 6; destP->_b = (palP->_b * lum) >> 6; @@ -968,7 +966,7 @@ void Vga::setColors(Dac *tab, int lum) { if (_mono) { destP = _newColors; - for (int idx = 0; idx < PAL_CNT; ++idx, ++destP) { + for (int idx = 0; idx < kPalCount; idx++, destP++) { // Form a greyscalce colour from 30% R, 59% G, 11% B uint8 intensity = (((int)destP->_r * 77) + ((int)destP->_g * 151) + ((int)destP->_b * 28)) >> 8; destP->_r = intensity; @@ -982,7 +980,7 @@ void Vga::setColors(Dac *tab, int lum) { void Vga::setColors() { - memset(_newColors, 0, PAL_SIZ); + memset(_newColors, 0, kPalSize); updateColors(); } @@ -1021,7 +1019,7 @@ void Vga::show() { void Vga::updateColors() { - byte palData[PAL_SIZ]; + byte palData[kPalSize]; dacToPal(_newColors, palData); g_system->getPaletteManager()->setPalette(palData, 0, 256); } @@ -1041,7 +1039,7 @@ void Vga::update() { void Vga::clear(uint8 color) { - for (int paneNum = 0; paneNum < 4; ++paneNum) + for (int paneNum = 0; paneNum < 4; paneNum++) _page[paneNum]->fillRect(Common::Rect(0, 0, kScrWidth, kScrHeight), color); } @@ -1062,7 +1060,7 @@ void Bitmap::xShow(int16 x, int16 y) { // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data // must be decompressed and inserted into the surface - for (int planeCtr = 0; planeCtr < 4; ++planeCtr) { + for (int planeCtr = 0; planeCtr < 4; planeCtr++) { byte *destP = (byte *)Vga::_page[1]->getBasePtr(x + planeCtr, y); for (;;) { @@ -1079,7 +1077,7 @@ void Bitmap::xShow(int16 x, int16 y) { assert(destP < destEndP); if (cmd == 2) - ++srcP; + srcP++; else if (cmd == 3) srcP += count; @@ -1114,7 +1112,7 @@ void Bitmap::show(int16 x, int16 y) { // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data // must be decompressed and inserted into the surface - for (int planeCtr = 0; planeCtr < 4; ++planeCtr) { + for (int planeCtr = 0; planeCtr < 4; planeCtr++) { byte *destP = (byte *)Vga::_page[1]->getBasePtr(x + planeCtr, y); for (;;) { @@ -1152,7 +1150,7 @@ void Bitmap::show(int16 x, int16 y) { } if (cmd == 2) - ++srcP; + srcP++; } } /* @@ -1184,7 +1182,7 @@ void Bitmap::hide(int16 x, int16 y) { HorizLine::HorizLine(CGEEngine *vm): Sprite(vm, NULL) { // Set the sprite list - BMP_PTR *HL = new BMP_PTR[2]; + BitmapPtr *HL = new BitmapPtr[2]; HL[0] = new Bitmap("HLINE", true); HL[1] = NULL; @@ -1193,7 +1191,7 @@ HorizLine::HorizLine(CGEEngine *vm): Sprite(vm, NULL) { CavLight::CavLight(CGEEngine *vm): Sprite(vm, NULL) { // Set the sprite list - BMP_PTR *PR = new BMP_PTR[2]; + BitmapPtr *PR = new BitmapPtr[2]; PR[0] = new Bitmap("PRESS", true); PR[1] = NULL; @@ -1202,7 +1200,7 @@ CavLight::CavLight(CGEEngine *vm): Sprite(vm, NULL) { Spike::Spike(CGEEngine *vm): Sprite(vm, NULL) { // Set the sprite list - BMP_PTR *SP = new BMP_PTR[3]; + BitmapPtr *SP = new BitmapPtr[3]; SP[0] = new Bitmap("SPK_L", true); SP[1] = new Bitmap("SPK_R", true); SP[2] = NULL; @@ -1212,7 +1210,7 @@ Spike::Spike(CGEEngine *vm): Sprite(vm, NULL) { PocLight::PocLight(CGEEngine *vm): Sprite(vm, NULL) { // Set the sprite list - BMP_PTR *LI = new BMP_PTR[5]; + BitmapPtr *LI = new BitmapPtr[5]; LI[0] = new Bitmap("LITE0", true); LI[1] = new Bitmap("LITE1", true); LI[2] = new Bitmap("LITE2", true); diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 15da63efbcd..f72d4c693da 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -99,33 +99,32 @@ extern Seq _seq2[]; //extern SEQ * Compass[]; //extern SEQ TurnToS[]; -#define PAL_CNT 256 -#define PAL_SIZ (PAL_CNT * 3) +#define kPalCount 256 +#define kPalSize (kPalCount * 3) + #define VGAATR_ 0x3C0 -#define VGAMIw_ 0x3C0 #define VGASEQ_ 0x3C4 -#define VGAMIr_ 0x3CC #define VGAGRA_ 0x3CE #define VGACRT_ 0x3D4 #define VGAST1_ 0x3DA #define VGAATR (VGAATR_ & 0xFF) -#define VGAMIw (VGAMIw_ & 0xFF) #define VGASEQ (VGASEQ_ & 0xFF) -#define VGAMIr (VGAMIr_ & 0xFF) #define VGAGRA (VGAGRA_ & 0xFF) #define VGACRT (VGACRT_ & 0xFF) -#define VGAST1 (VGAST1_ & 0xFF) - class SprExt { public: - int _x0, _y0; - int _x1, _y1; - BMP_PTR _b0, _b1; - BMP_PTR *_shpList; + int _x0; + int _y0; + int _x1; + int _y1; + BitmapPtr _b0; + BitmapPtr _b1; + BitmapPtr *_shpList; Seq *_seq; char *_name; - Snail::Com *_near, *_take; + Snail::Com *_near; + Snail::Com *_take; SprExt() : _x0(0), _y0(0), _x1(0), _y1(0), @@ -179,15 +178,16 @@ public: inline bool active() { return _ext != NULL; } - Sprite(CGEEngine *vm, BMP_PTR *shp); + + Sprite(CGEEngine *vm, BitmapPtr *shp); virtual ~Sprite(); - BMP_PTR shp(); - BMP_PTR *setShapeList(BMP_PTR *shp); + BitmapPtr shp(); + BitmapPtr *setShapeList(BitmapPtr *shp); void moveShapes(uint8 *buf); Sprite *expand(); Sprite *contract(); Sprite *backShow(bool fast = false); - void setName(char *n); + void setName(char *name); inline char *name() { return (_ext) ? _ext->_name : NULL; } @@ -195,7 +195,7 @@ public: void center(); void show(); void hide(); - BMP_PTR ghost(); + BitmapPtr ghost(); void show(uint16 pg); void makeXlat(uint8 *x); void killXlat(); @@ -243,7 +243,7 @@ class Vga { Dac *_oldColors; Dac *_newColors; const char *_msg; - const char *_nam; + const char *_name; int setMode(int mode); void updateColors(); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 934bd6299d4..e8aa899583f 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -48,7 +48,7 @@ MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { p2 -= w; } - _ts = new BMP_PTR[2]; + _ts = new BitmapPtr[2]; _ts[0] = new Bitmap(w, h, p); _ts[1] = NULL; setShapeList(_ts); diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index e2c62513dd7..a9eeb6db8ef 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -32,7 +32,7 @@ namespace CGE { Walk *_hero; -uint8 Cluster::_map[MAP_ZCNT][MAP_XCNT]; +uint8 Cluster::_map[kMapZCnt][kMapXCnt]; CGEEngine *Cluster::_vm; void Cluster::init(CGEEngine *vm) { @@ -44,22 +44,22 @@ uint8 &Cluster::cell() { } bool Cluster::isValid() const { - return (_a >= 0) && (_a < MAP_XCNT) && (_b >= 0) && (_b < MAP_ZCNT); + return (_a >= 0) && (_a < kMapXCnt) && (_b >= 0) && (_b < kMapZCnt); } bool Cluster::chkBar() const { - assert(_vm->_now <= _vm->CAVE_MAX); + assert(_vm->_now <= _vm->_caveMax); return (_a == _vm->_barriers[_vm->_now]._horz) && (_b == _vm->_barriers[_vm->_now]._vert); } Cluster XZ(int x, int y) { - if (y < MAP_TOP) - y = MAP_TOP; + if (y < kMapTop) + y = kMapTop; - if (y > MAP_TOP + MAP_HIG - MAP_ZGRID) - y = MAP_TOP + MAP_HIG - MAP_ZGRID; + if (y > kMapTop + kMapHig - kMapGridZ) + y = kMapTop + kMapHig - kMapGridZ; - return Cluster(x / MAP_XGRID, (y - MAP_TOP) / MAP_ZGRID); + return Cluster(x / kMapGridX, (y - kMapTop) / kMapGridZ); } @@ -69,8 +69,8 @@ Cluster XZ(Couple xy) { return XZ(x, y); } -Walk::Walk(CGEEngine *vm, BMP_PTR *shpl) - : Sprite(vm, shpl), Dir(NO_DIR), _tracePtr(-1), _level(0), _vm(vm) { +Walk::Walk(CGEEngine *vm, BitmapPtr *shpl) + : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _vm(vm) { } @@ -80,7 +80,7 @@ void Walk::tick() { _here = XZ(_x + _w / 2, _y + _h); - if (Dir != NO_DIR) { + if (_dir != kDirNone) { Sprite *spr; _sys->funTouch(); for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { @@ -104,14 +104,14 @@ void Walk::tick() { } else { signed char dx, dz; (_trace[_tracePtr] - _here).split(dx, dz); - DIR d = (dx) ? ((dx > 0) ? EE : WW) : ((dz > 0) ? SS : NN); + Dir d = (dx) ? ((dx > 0) ? kDirEast : kDirWest) : ((dz > 0) ? kDirSouth : kDirNorth); turn(d); } } step(); - if ((Dir == WW && _x <= 0) || - (Dir == EE && _x + _w >= kScrWidth) || - (Dir == SS && _y + _w >= kWorldHeight - 2)) + if ((_dir == kDirWest && _x <= 0) || + (_dir == kDirEast && _x + _w >= kScrWidth) || + (_dir == kDirSouth && _y + _w >= kWorldHeight - 2)) park(); else { signed char x; // dummy var @@ -130,7 +130,7 @@ int Walk::distance(Sprite *spr) { if (dx < 0) dx = 0; - dx /= MAP_XGRID; + dx /= kMapGridX; dz = spr->_z - _z; if (dz < 0) dz = - dz; @@ -143,22 +143,22 @@ int Walk::distance(Sprite *spr) { } -void Walk::turn(DIR d) { - DIR dir = (Dir == NO_DIR) ? SS : Dir; - if (d != Dir) { +void Walk::turn(Dir d) { + Dir dir = (_dir == kDirNone) ? kDirSouth : _dir; + if (d != _dir) { step((d == dir) ? (1 + dir + dir) : (9 + 4 * dir + d)); - Dir = d; + _dir = d; } } void Walk::park() { if (_time == 0) - ++_time; + _time++; - if (Dir != NO_DIR) { - step(9 + 4 * Dir + Dir); - Dir = NO_DIR; + if (_dir != kDirNone) { + step(9 + 4 * _dir + _dir); + _dir = kDirNone; _tracePtr = -1; } } @@ -166,7 +166,7 @@ void Walk::park() { void Walk::findWay(Cluster c) { if (c != _here) { - for (_findLevel = 1; _findLevel <= MAX_FIND_LEVEL; _findLevel++) { + for (_findLevel = 1; _findLevel <= kMaxFindLevel; _findLevel++) { signed char x, z; _here.split(x, z); _target = Couple(x, z); @@ -175,7 +175,7 @@ void Walk::findWay(Cluster c) { if (find1Way(Cluster(x, z))) break; } - _tracePtr = (_findLevel > MAX_FIND_LEVEL) ? -1 : (_findLevel - 1); + _tracePtr = (_findLevel > kMaxFindLevel) ? -1 : (_findLevel - 1); if (_tracePtr < 0) noWay(); _time = 1; @@ -191,8 +191,8 @@ void Walk::findWay(Sprite *spr) { x += spr->_w + _w / 2 - kWalkSide; else x -= _w / 2 - kWalkSide; - findWay(Cluster((x / MAP_XGRID), - ((z < MAP_ZCNT - kDistMax) ? (z + 1) + findWay(Cluster((x / kMapGridX), + ((z < kMapZCnt - kDistMax) ? (z + 1) : (z - 1)))); } } @@ -250,7 +250,7 @@ bool Walk::find1Way(Cluster c) { // Loop through each direction - for (int i = 0; i < tabLen; ++i) { + for (int i = 0; i < tabLen; i++) { // Reset to starting position c = start; diff --git a/engines/cge/walk.h b/engines/cge/walk.h index 15ea9ee0cec..115cb4924a7 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -34,13 +34,15 @@ namespace CGE { -#define MAP_XCNT 40 -#define MAP_ZCNT 20 -#define MAP_TOP 80 -#define MAP_HIG 80 -#define MAP_XGRID (kScrWidth / MAP_XCNT) -#define MAP_ZGRID (MAP_HIG / MAP_ZCNT) -#define MAX_FIND_LEVEL 3 +#define kMapXCnt 40 +#define kMapZCnt 20 +#define kMapTop 80 +#define kMapHig 80 +#define kMapGridX (kScrWidth / kMapXCnt) +#define kMapGridZ (kMapHig / kMapZCnt) +#define kMaxFindLevel 3 + +enum Dir { kDirNone = -1, kDirNorth, kDirEast, kDirSouth, kDirWest }; class Couple { protected: @@ -83,7 +85,7 @@ public: class Cluster : public Couple { public: - static uint8 _map[MAP_ZCNT][MAP_XCNT]; + static uint8 _map[kMapZCnt][kMapXCnt]; static CGEEngine *_vm; static void init(CGEEngine *vm); @@ -106,15 +108,15 @@ public: int _level; int _findLevel; Couple _target; - Cluster _trace[MAX_FIND_LEVEL]; + Cluster _trace[kMaxFindLevel]; - enum DIR { NO_DIR = -1, NN, EE, SS, WW } Dir; - Walk(CGEEngine *vm, BMP_PTR *shpl); + Dir _dir; + Walk(CGEEngine *vm, BitmapPtr *shpl); void tick(); void findWay(Cluster c); void findWay(Sprite *spr); int distance(Sprite *spr); - void turn(DIR d); + void turn(Dir d); void park(); bool lower(Sprite *spr); void reach(Sprite *spr, int mode = -1); diff --git a/engines/cge/wav.h b/engines/cge/wav.h index 739e1029592..bd9fc96b0a7 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -41,20 +41,20 @@ typedef char FourCC[4]; // Four-character code class ChunkId { // Chunk type identifier union { - FourCC _tx; + FourCC _text; uint32 _id; }; protected: static XFile *ckFile; public: - ChunkId(FourCC t) { - memcpy(_tx, t, sizeof(_tx)); + ChunkId(FourCC text) { + memcpy(_text, text, sizeof(_text)); } ChunkId(uint32 d) { _id = d; } ChunkId(XFile *xf) { - (ckFile = xf)->read(_tx, sizeof(_tx)); + (ckFile = xf)->read(_text, sizeof(_text)); } bool operator !=(ChunkId &X) { return _id != X._id; @@ -116,7 +116,7 @@ public: class DataCk : public CkHea { - bool _e; + bool _ef; uint8 *_buf; public: DataCk(CkHea &hea); From f898da53a48ff9d3dbb5f23ca3aa58ff37181edd Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 31 Jul 2011 09:38:08 +0200 Subject: [PATCH 173/276] CGE: Improve keyboard behavior for non-US layouts --- engines/cge/events.cpp | 11 ++++++++--- engines/cge/events.h | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 1c2738f62e9..e2aaaa587d9 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -99,11 +99,16 @@ Sprite *Keyboard::setClient(Sprite *spr) { return spr; } -bool Keyboard::getKey(uint16 keycode, int &cgeCode) { +bool Keyboard::getKey(Common::Event &event, int &cgeCode) { + Common::KeyCode keycode = event.kbd.keycode; if ((keycode == Common::KEYCODE_LCTRL) || (keycode == Common::KEYCODE_RCTRL)) { cgeCode = 29; return true; } + if ((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT)) { + cgeCode = 56; + return true; + } if (keycode == Common::KEYCODE_KP_ENTER) { cgeCode = 28; return true; @@ -111,7 +116,7 @@ bool Keyboard::getKey(uint16 keycode, int &cgeCode) { // Scan through the ScummVM mapping list for (int idx = 0; idx < 0x60; idx++) { - if (_scummVmCodes[idx] == keycode) { + if (_scummVmCodes[idx] == event.kbd.ascii) { cgeCode = idx; return true; } @@ -122,7 +127,7 @@ bool Keyboard::getKey(uint16 keycode, int &cgeCode) { void Keyboard::newKeyboard(Common::Event &event) { int keycode; - if (!getKey(event.kbd.keycode, keycode)) + if (!getKey(event, keycode)) return; if (event.type == Common::EVENT_KEYUP) { diff --git a/engines/cge/events.h b/engines/cge/events.h index 671878f69a2..2d85574bd79 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -47,7 +47,7 @@ namespace CGE { class Keyboard { private: - bool getKey(uint16 keycode, int &cgeCode); + bool getKey(Common::Event &event, int &cgeCode); public: static const uint16 _code[0x60]; static const uint16 _scummVmCodes[0x60]; From c053762c6398c7d818d5c7f319877c4b1e712070 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 31 Jul 2011 19:56:14 +0200 Subject: [PATCH 174/276] CGE: Replace magic values by defines, rename some defines --- engines/cge/cge_main.cpp | 12 ++++++------ engines/cge/events.cpp | 4 ++-- engines/cge/events.h | 9 ++------- engines/cge/gettext.cpp | 2 +- engines/cge/snail.cpp | 2 +- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 37449fd5dd8..302a25a3d5e 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -737,13 +737,13 @@ void System::touch(uint16 mask, int x, int y) { pp0 = pp; switch (x) { case Del: - if (_keyboard->_key[ALT] && _keyboard->_key[CTRL]) + if (_keyboard->_key[kKeyAlt] && _keyboard->_key[kKeyCtrl]) _vm->AltCtrlDel(); else _vm->killSprite(); break; case 'F': - if (_keyboard->_key[ALT]) { + if (_keyboard->_key[kKeyAlt]) { Sprite *m = _vga->_showQ->locate(17001); if (m) { m->step(1); @@ -761,7 +761,7 @@ void System::touch(uint16 mask, int x, int y) { _vm->nextStep(); break; case '`': - if (_keyboard->_key[ALT]) + if (_keyboard->_key[kKeyAlt]) _vm->saveMapping(); else _vm->switchMapping(); @@ -791,7 +791,7 @@ void System::touch(uint16 mask, int x, int y) { _sys->_funDel = 1; break; case 'X': - if (_keyboard->_key[ALT]) + if (_keyboard->_key[kKeyAlt]) _finis = true; break; case '0': @@ -799,7 +799,7 @@ void System::touch(uint16 mask, int x, int y) { case '2': case '3': case '4': - if (_keyboard->_key[ALT]) { + if (_keyboard->_key[kKeyAlt]) { _snail->addCom(kSnLevel, -1, x - '0', NULL); break; } @@ -917,7 +917,7 @@ void CGEEngine::switchColorMode() { void CGEEngine::switchMusic() { debugC(1, kCGEDebugEngine, "CGEEngine::switchMusic()"); - if (_keyboard->_key[ALT]) { + if (_keyboard->_key[kKeyAlt]) { if (Vmenu::_addr) _snail_->addCom(kSnKill, -1, 0, Vmenu::_addr); else { diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index e2aaaa587d9..119390944e1 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -102,11 +102,11 @@ Sprite *Keyboard::setClient(Sprite *spr) { bool Keyboard::getKey(Common::Event &event, int &cgeCode) { Common::KeyCode keycode = event.kbd.keycode; if ((keycode == Common::KEYCODE_LCTRL) || (keycode == Common::KEYCODE_RCTRL)) { - cgeCode = 29; + cgeCode = kKeyCtrl; return true; } if ((keycode == Common::KEYCODE_LALT) || (keycode == Common::KEYCODE_RALT)) { - cgeCode = 56; + cgeCode = kKeyAlt; return true; } if (keycode == Common::KEYCODE_KP_ENTER) { diff --git a/engines/cge/events.h b/engines/cge/events.h index 2d85574bd79..3b4ff2092f6 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -38,12 +38,8 @@ namespace CGE { /*----------------- KEYBOARD interface -----------------*/ -#define KEYBD_INT 9 -#define LSHIFT 42 -#define RSHIFT 54 -#define CTRL 29 -#define ALT 56 - +#define kKeyCtrl 29 +#define kKeyAlt 56 class Keyboard { private: @@ -79,7 +75,6 @@ public: #define ATTN 0x20 // 0x40 #define KEYB 0x80 - extern Talk *_talk; struct CGEEvent { diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index f64f4b2619e..a2408bc7922 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -103,7 +103,7 @@ void GetText::touch(uint16 mask, int x, int y) { if (_oldKeybClient) _oldKeybClient->touch(mask, x, y); } else { - if (_keyboard->_key[ALT]) { + if (_keyboard->_key[kKeyAlt]) { p = strchr(bezo, x); if (p) x = ogon[p - bezo]; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 03cb43f4f1a..e188f766503 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -153,7 +153,7 @@ void CGEEngine::snGame(Sprite *spr, int num) { _sprK2->step(new_random(6)); _sprK3->step(new_random(6)); ///-------------------- - if (spr->_ref == 1 && _keyboard->_key[ALT]) { + if (spr->_ref == 1 && _keyboard->_key[kKeyAlt]) { _sprK1->step(5); _sprK2->step(5); _sprK3->step(5); From 88f6cc9b234432b068a6bd7e18ed92696dc95176 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 1 Aug 2011 09:53:15 +0200 Subject: [PATCH 175/276] CGE: Clean eventManager --- engines/cge/cge_main.cpp | 2 +- engines/cge/events.cpp | 90 ++++++++++++++++++++-------------------- engines/cge/events.h | 20 +++++---- engines/cge/snail.cpp | 2 +- 4 files changed, 59 insertions(+), 55 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 302a25a3d5e..1198946a41d 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1696,7 +1696,7 @@ bool CGEEngine::showTitle(const char *name) { if (_eventManager->_quitFlag) return false; } - if (_keyboard->last() == Enter && *_usrFnam) + if (_keyboard->lastKey() == Enter && *_usrFnam) userOk = true; } //Mouse.Off(); diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 119390944e1..113b64cee88 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -33,10 +33,6 @@ namespace CGE { -CGEEvent Evt[EVT_MAX]; - -uint16 EvtHead = 0, EvtTail = 0; - /*----------------- KEYBOARD interface -----------------*/ const uint16 Keyboard::_code[0x60] = { @@ -85,8 +81,7 @@ const uint16 Keyboard::_scummVmCodes[0x60] = { 0 }; -Keyboard::Keyboard() { - _client = NULL; +Keyboard::Keyboard() : _client(NULL) { Common::set_to(&_key[0], &_key[0x60], false); _current = 0; } @@ -139,15 +134,20 @@ void Keyboard::newKeyboard(Common::Event &event) { _current = Keyboard::_code[keycode]; if (_client) { - CGEEvent &evt = Evt[EvtHead]; - EvtHead = (EvtHead + 1) % EVT_MAX; + CGEEvent &evt = _eventManager->getNextEvent(); evt._x = _current; // Keycode - evt._msk = KEYB; // Event mask - evt._ptr = _client; // Sprite pointer + evt._mask = KEYB; // Event mask + evt._spritePtr = _client; // Sprite pointer } } } +uint16 Keyboard::lastKey() { + uint16 cur = _current; + _current = 0; + return cur; +} + /*----------------- MOUSE interface -----------------*/ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0), _vm(vm) { @@ -185,11 +185,6 @@ Mouse::~Mouse() { } -//void Mouse::setFun() -//{ -//} - - void Mouse::on() { if (_seqPtr && _exist) { _active = true; @@ -216,30 +211,29 @@ void Mouse::newMouse(Common::Event &event) { if (!_active) return; - CGEEvent &evt = Evt[EvtHead]; - EvtHead = (EvtHead + 1) % EVT_MAX; + CGEEvent &evt = _eventManager->getNextEvent(); evt._x = event.mouse.x; evt._y = event.mouse.y; - evt._ptr = spriteAt(evt._x, evt._y); + evt._spritePtr = spriteAt(evt._x, evt._y); switch (event.type) { case Common::EVENT_MOUSEMOVE: - evt._msk = ROLL; + evt._mask = ROLL; break; case Common::EVENT_LBUTTONDOWN: - evt._msk = L_DN; + evt._mask = L_DN; _buttons |= 1; break; case Common::EVENT_LBUTTONUP: - evt._msk = L_UP; + evt._mask = L_UP; _buttons &= ~1; break; case Common::EVENT_RBUTTONDOWN: - evt._msk = R_DN; + evt._mask = R_DN; _buttons |= 2; break; case Common::EVENT_RBUTTONUP: - evt._msk = R_UP; + evt._mask = R_UP; _buttons &= ~2; break; default: @@ -251,6 +245,8 @@ void Mouse::newMouse(Common::Event &event) { EventManager::EventManager() { _quitFlag = false; + _eventQueueHead = 0; + _eventQueueTail = 0; } void EventManager::poll() { @@ -282,27 +278,27 @@ void EventManager::poll() { } void EventManager::handleEvents() { - while (EvtTail != EvtHead) { - CGEEvent e = Evt[EvtTail]; - if (e._msk) { - if (_mouse->_hold && e._ptr != _mouse->_hold) - _mouse->_hold->touch(e._msk | ATTN, e._x - _mouse->_hold->_x, e._y - _mouse->_hold->_y); + while (_eventQueueTail != _eventQueueHead) { + CGEEvent e = _eventQueue[_eventQueueTail]; + if (e._mask) { + if (_mouse->_hold && e._spritePtr != _mouse->_hold) + _mouse->_hold->touch(e._mask | ATTN, e._x - _mouse->_hold->_x, e._y - _mouse->_hold->_y); // update mouse cursor position - if (e._msk & ROLL) + if (e._mask & ROLL) _mouse->gotoxy(e._x, e._y); // activate current touched SPRITE - if (e._ptr) { - if (e._msk & KEYB) - e._ptr->touch(e._msk, e._x, e._y); + if (e._spritePtr) { + if (e._mask & KEYB) + e._spritePtr->touch(e._mask, e._x, e._y); else - e._ptr->touch(e._msk, e._x - e._ptr->_x, e._y - e._ptr->_y); + e._spritePtr->touch(e._mask, e._x - e._spritePtr->_x, e._y - e._spritePtr->_y); } else if (_sys) - _sys->touch(e._msk, e._x, e._y); + _sys->touch(e._mask, e._x, e._y); - if (e._msk & L_DN) { - _mouse->_hold = e._ptr; + if (e._mask & L_DN) { + _mouse->_hold = e._spritePtr; if (_mouse->_hold) { _mouse->_hold->_flags._hold = true; @@ -313,7 +309,7 @@ void EventManager::handleEvents() { } } - if (e._msk & L_UP) { + if (e._mask & L_UP) { if (_mouse->_hold) { _mouse->_hold->_flags._hold = false; _mouse->_hold = NULL; @@ -322,10 +318,10 @@ void EventManager::handleEvents() { ///Touched = e.Ptr; // discard Text if button released - if (e._msk & (L_UP | R_UP)) + if (e._mask & (L_UP | R_UP)) killText(); } - EvtTail = (EvtTail + 1) % EVT_MAX; + _eventQueueTail = (_eventQueueTail + 1) % EVT_MAX; } if (_mouse->_hold) { if (_mouse->_hold->_flags._drag) @@ -333,14 +329,20 @@ void EventManager::handleEvents() { } } -void EventManager::clrEvt(Sprite *spr) { +void EventManager::clearEvent(Sprite *spr) { if (spr) { uint16 e; - for (e = EvtTail; e != EvtHead; e = (e + 1) % EVT_MAX) - if (Evt[e]._ptr == spr) - Evt[e]._msk = 0; + for (e = _eventQueueTail; e != _eventQueueHead; e = (e + 1) % EVT_MAX) + if (_eventQueue[e]._spritePtr == spr) + _eventQueue[e]._mask = 0; } else - EvtTail = EvtHead; + _eventQueueTail = _eventQueueHead; } +CGEEvent &EventManager::getNextEvent() { + CGEEvent &evt = _eventQueue[_eventQueueHead]; + _eventQueueHead = (_eventQueueHead + 1) % EVT_MAX; + + return evt; +} } // End of namespace CGE diff --git a/engines/cge/events.h b/engines/cge/events.h index 3b4ff2092f6..b213caed3c0 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -44,20 +44,16 @@ namespace CGE { class Keyboard { private: bool getKey(Common::Event &event, int &cgeCode); + uint16 _current; public: static const uint16 _code[0x60]; static const uint16 _scummVmCodes[0x60]; - uint16 _current; Sprite *_client; bool _key[0x60]; void newKeyboard(Common::Event &event); - uint16 last() { - uint16 cur = _current; - _current = 0; - return cur; - } + uint16 lastKey(); Sprite *setClient(Sprite *spr); Keyboard(); @@ -78,10 +74,10 @@ public: extern Talk *_talk; struct CGEEvent { - uint16 _msk; + uint16 _mask; uint16 _x; uint16 _y; - Sprite *_ptr; + Sprite *_spritePtr; }; @@ -109,13 +105,19 @@ private: class EventManager { private: Common::Event _event; + CGEEvent _eventQueue[EVT_MAX]; + uint16 _eventQueueHead; + uint16 _eventQueueTail; + void handleEvents(); public: bool _quitFlag; EventManager(); void poll(); - static void clrEvt(Sprite *spr = NULL); + void clearEvent(Sprite *spr); + + CGEEvent &getNextEvent(); }; } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index e188f766503..aece48a9336 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -771,7 +771,7 @@ void CGEEngine::snKill(Sprite *spr) { Sprite *nx = spr->_next; hide1(spr); _vga->_showQ->remove(spr); - EventManager::clrEvt(spr); + _eventManager->clearEvent(spr); if (spr->_flags._kill) delete spr; else { From 6f92cdd0d0e124653c4164c7ab0f91e5b910f6bc Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 2 Aug 2011 21:47:56 +0200 Subject: [PATCH 176/276] CGE: Rename some more defines --- engines/cge/bitmap.cpp | 4 +- engines/cge/cge.h | 6 +- engines/cge/cge_main.cpp | 154 ++++++++++++++++++-------------------- engines/cge/cge_main.h | 19 +++-- engines/cge/detection.cpp | 12 +-- engines/cge/events.cpp | 30 ++++---- engines/cge/events.h | 22 +++--- engines/cge/game.cpp | 10 +-- engines/cge/general.cpp | 2 +- engines/cge/general.h | 2 +- engines/cge/gettext.cpp | 2 +- engines/cge/jbw.h | 1 - engines/cge/mixer.cpp | 4 +- engines/cge/snail.cpp | 21 ++---- engines/cge/text.cpp | 12 +-- engines/cge/text.h | 15 ++-- engines/cge/vmenu.cpp | 2 +- 17 files changed, 151 insertions(+), 167 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index ddde3bbd213..63f7c0dadf2 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -63,11 +63,11 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { #endif { #if (BMP_MODE) - ForceExt(pat, fname, ".BMP"); + forceExt(pat, fname, ".BMP"); PIC_FILE file(pat); if (file._error == 0) { if (loadBMP(&file)) { - Code(); + code(); if (rem) { free(_m); _m = NULL; diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 7adc44fac6f..54ea9e37f62 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -40,7 +40,8 @@ namespace CGE { class Console; class Sprite; -#define CGE_SAVEGAME_VERSION 1 +#define kSavegameVersion 1 +#define kSavegameStrSize 11 #define kPocketX 174 #define kPocketY 176 #define kPocketDX 18 @@ -75,8 +76,7 @@ struct SavegameHeader { int totalFrames; }; -extern const char *SAVEGAME_STR; -#define SAVEGAME_STR_SIZE 11 +extern const char *savegameStr; struct Bar { uint8 _horz; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 1198946a41d..cbba280ff8f 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -54,13 +54,7 @@ namespace CGE { -#define STACK_SIZ 2048 -#define SVGCHKSUM (1956 + _now + _oldLev + _game + _music + _demoText) - -#define SVG0NAME ("{{INIT}}" kSvgExt) -#define SVG0FILE INI_FILE - -uint16 _stklen = (STACK_SIZ * 2); +uint16 _stklen = (kStackSize * 2); Vga *_vga; System *_sys; @@ -90,8 +84,7 @@ Sound *_sound; // 1.01 - 17VII95 - default savegame with sound ON // coditionals EVA for 2-month evaluation version -const char *SAVEGAME_STR = "SCUMMVM_CGE"; -#define SAVEGAME_STR_SIZE 11 +const char *savegameStr = "SCUMMVM_CGE"; //-------------------------------------------------------------------------- @@ -137,13 +130,13 @@ void CGEEngine::syncHeader(Common::Serializer &s) { if (s.isSaving()) { // Write checksum - int checksum = SVGCHKSUM; + int checksum = kSavegameCheckSum; s.syncAsUint16LE(checksum); } else { // Read checksum and validate it uint16 checksum; s.syncAsUint16LE(checksum); - if (checksum != SVGCHKSUM) + if (checksum != kSavegameCheckSum) error("%s", _text->getText(kBadSVG)); } } @@ -156,7 +149,7 @@ bool CGEEngine::loadGame(int slotNumber, SavegameHeader *header, bool tiny) { if (slotNumber == -1) { // Loading the data for the initial game state - SVG0FILE file = SVG0FILE(SVG0NAME); + kSavegame0File file = kSavegame0File(kSavegame0Name); int size = file.size(); byte *dataBuffer = (byte *)malloc(size); file.read(dataBuffer, size); @@ -175,10 +168,10 @@ bool CGEEngine::loadGame(int slotNumber, SavegameHeader *header, bool tiny) { } // Check to see if it's a ScummVM savegame or not - char buffer[SAVEGAME_STR_SIZE + 1]; - readStream->read(buffer, SAVEGAME_STR_SIZE + 1); + char buffer[kSavegameStrSize + 1]; + readStream->read(buffer, kSavegameStrSize + 1); - if (strncmp(buffer, SAVEGAME_STR, SAVEGAME_STR_SIZE + 1) != 0) { + if (strncmp(buffer, savegameStr, kSavegameStrSize + 1) != 0) { // It's not, so rewind back to the start readStream->seek(0); @@ -269,7 +262,7 @@ void CGEEngine::saveGame(int slotNumber, const Common::String &desc) { // Write out the ScummVM savegame header SavegameHeader header; header.saveName = desc; - header.version = CGE_SAVEGAME_VERSION; + header.version = kSavegameVersion; writeSavegameHeader(saveFile, header); // Write out the data of the savegame @@ -282,9 +275,9 @@ void CGEEngine::saveGame(int slotNumber, const Common::String &desc) { void CGEEngine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &header) { // Write out a savegame header - out->write(SAVEGAME_STR, SAVEGAME_STR_SIZE + 1); + out->write(savegameStr, kSavegameStrSize + 1); - out->writeByte(CGE_SAVEGAME_VERSION); + out->writeByte(kSavegameVersion); // Write savegame name out->write(header.saveName.c_str(), header.saveName.size() + 1); @@ -376,7 +369,7 @@ bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &heade // Get the savegame version header.version = in->readByte(); - if (header.version > CGE_SAVEGAME_VERSION) + if (header.version > kSavegameVersion) return false; // Read in the string @@ -423,7 +416,7 @@ void CGEEngine::trouble(int seq, int text) { void CGEEngine::offUse() { debugC(1, kCGEDebugEngine, "CGEEngine::offUse()"); - trouble(kSeqOffUse, kOffUse + new_random(_offUseCount)); + trouble(kSeqOffUse, kOffUse + newRandom(_offUseCount)); } void CGEEngine::tooFar() { @@ -467,7 +460,7 @@ Square::Square(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { void Square::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); - if (mask & L_UP) { + if (mask & kMouseLeftUp) { XZ(_x + x, _y + y).cell() = 0; _snail_->addCom(kSnKill, -1, 0, this); } @@ -688,8 +681,8 @@ void CGEEngine::switchCave(int cav) { if (!_isDemo) _vga->_spareQ->_show = 0; } - _cavLight->gotoxy(CAVE_X + ((_now - 1) % _caveNx) * _caveDx + CAVE_SX, - CAVE_Y + ((_now - 1) / _caveNx) * _caveDy + CAVE_SY); + _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, + kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); killText(); if (!_startupMode) keyClick(); @@ -716,7 +709,7 @@ void System::setPal() { } void System::funTouch() { - uint16 n = (PAIN) ? kHeroFun1 : kHeroFun0; + uint16 n = (_vm->_flag[0]) ? kHeroFun1 : kHeroFun0; // PAIN flag if (_talk == NULL || n > _funDel) _funDel = n; } @@ -726,7 +719,7 @@ void System::touch(uint16 mask, int x, int y) { funTouch(); - if (mask & KEYB) { + if (mask & kEventKeyb) { int pp0; _vm->keyClick(); killText(); @@ -837,15 +830,15 @@ void System::touch(uint16 mask, int x, int y) { _infoLine->update(NULL); if (y >= kWorldHeight ) { if (x < kButtonX) { // select cave? - if (y >= CAVE_Y && y < CAVE_Y + _vm->_caveNy * _vm->_caveDy && - x >= CAVE_X && x < CAVE_X + _vm->_caveNx * _vm->_caveDx && !_vm->_game) { - cav = ((y - CAVE_Y) / _vm->_caveDy) * _vm->_caveNx + (x - CAVE_X) / _vm->_caveDx + 1; + if (y >= kCaveY && y < kCaveY + _vm->_caveNy * _vm->_caveDy && + x >= kCaveX && x < kCaveX + _vm->_caveNx * _vm->_caveDx && !_vm->_game) { + cav = ((y - kCaveY) / _vm->_caveDy) * _vm->_caveNx + (x - kCaveX) / _vm->_caveDx + 1; if (cav > _vm->_maxCave) cav = 0; } else { cav = 0; } - } else if (mask & L_UP) { + } else if (mask & kMouseLeftUp) { if (y >= kPocketY && y < kPocketY + kPocketNY * kPocketDY && x >= kPocketX && x < kPocketX + kPocketNX * kPocketDX) { int n = ((y - kPocketY) / kPocketDY) * kPocketNX + (x - kPocketX) / kPocketDX; @@ -856,7 +849,7 @@ void System::touch(uint16 mask, int x, int y) { _vm->postMiniStep(cav - 1); - if (mask & L_UP) { + if (mask & kMouseLeftUp) { if (cav && _snail->idle() && _hero->_tracePtr < 0) _vm->switchCave(cav); @@ -883,10 +876,10 @@ void System::tick() { if (--_funDel == 0) { killText(); if (_snail->idle()) { - if (PAIN) + if (_vm->_flag[0]) // Pain flag _vm->heroCover(9); else { // CHECKME: Before, was: if (Startup::_core >= CORE_MID) { - int n = new_random(100); + int n = newRandom(100); if (n > 96) _vm->heroCover(6 + (_hero->_x + _hero->_w / 2 < kScrWidth / 2)); else { @@ -1043,42 +1036,42 @@ void CGEEngine::saveMapping() { } } -// 1111111111222222222233333333334444444444555555555566666666667777777777 -// 01234567890123456789012345678901234567890123456789012345678901234567890123456789 -static char DebugText[] = " X=000 Y=000 S=00:00 000:000:000 000:000 00"; - -#define ABSX (DebugText + 3) -#define ABSY (DebugText + 9) -#define SP_N (DebugText + 15) -#define SP_S (DebugText + 18) -#define SP_X (DebugText + 21) -#define SP_Y (DebugText + 25) -#define SP_Z (DebugText + 29) -#define SP_W (DebugText + 33) -#define SP_H (DebugText + 37) -#define SP_F (DebugText + 41) void CGEEngine::sayDebug() { +// 1111111111222222222233333333334444444444555555555566666666667777777777 +// 01234567890123456789012345678901234567890123456789012345678901234567890123456789 + static char DebugText[] = " X=000 Y=000 S=00:00 000:000:000 000:000 00"; + + char *absX = DebugText + 3; + char *absY = DebugText + 9; + char *spN = DebugText + 15; + char *spS = DebugText + 18; + char *spX = DebugText + 21; + char *spY = DebugText + 25; + char *spZ = DebugText + 29; + char *spW = DebugText + 33; + char *spH = DebugText + 37; + char *spF = DebugText + 41; + if (!_debugLine->_flags._hide) { - dwtom(_mouse->_x, ABSX, 10, 3); - dwtom(_mouse->_y, ABSY, 10, 3); + dwtom(_mouse->_x, absX, 10, 3); + dwtom(_mouse->_y, absY, 10, 3); // sprite queue size uint16 n = 0; - Sprite *spr; - for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { + for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { n++; if (spr == _sprite) { - dwtom(n, SP_N, 10, 2); - dwtom(_sprite->_x, SP_X, 10, 3); - dwtom(_sprite->_y, SP_Y, 10, 3); - dwtom(_sprite->_z, SP_Z, 10, 3); - dwtom(_sprite->_w, SP_W, 10, 3); - dwtom(_sprite->_h, SP_H, 10, 3); - dwtom(*(uint16 *)(&_sprite->_flags), SP_F, 16, 2); + dwtom(n, spN, 10, 2); + dwtom(_sprite->_x, spX, 10, 3); + dwtom(_sprite->_y, spY, 10, 3); + dwtom(_sprite->_z, spZ, 10, 3); + dwtom(_sprite->_w, spW, 10, 3); + dwtom(_sprite->_h, spH, 10, 3); + dwtom(*(uint16 *)(&_sprite->_flags), spF, 16, 2); } } - dwtom(n, SP_S, 10, 2); + dwtom(n, spS, 10, 2); _debugLine->update(DebugText); } } @@ -1092,20 +1085,20 @@ void CGEEngine::switchDebug() { void CGEEngine::optionTouch(int opt, uint16 mask) { switch (opt) { case 1 : - if (mask & L_UP) + if (mask & kMouseLeftUp) switchColorMode(); break; case 2 : - if (mask & L_UP) + if (mask & kMouseLeftUp) switchMusic(); - else if (mask & R_UP) + else if (mask & kMouseRightUp) if (!Mixer::_appear) { Mixer::_appear = true; new Mixer(this, kButtonX, kButtonY); } break; case 3 : - if (mask & L_UP) + if (mask & kMouseLeftUp) quit(); break; } @@ -1115,9 +1108,9 @@ void CGEEngine::optionTouch(int opt, uint16 mask) { #pragma argsused void Sprite::touch(uint16 mask, int x, int y) { _sys->funTouch(); - if ((mask & ATTN) == 0) { + if ((mask & kEventAttn) == 0) { _infoLine->update(name()); - if (mask & (R_DN | L_DN)) + if (mask & (kMouseRightDown | kMouseLeftDown)) _sprite = this; if (_ref / 10 == 12) { _vm->optionTouch(_ref % 10, mask); @@ -1125,11 +1118,11 @@ void Sprite::touch(uint16 mask, int x, int y) { } if (_flags._syst) return; // cannot access system sprites - if (_vm->_game) if (mask & L_UP) { - mask &= ~L_UP; - mask |= R_UP; + if (_vm->_game) if (mask & kMouseLeftUp) { + mask &= ~kMouseLeftUp; + mask |= kMouseRightUp; } - if ((mask & R_UP) && _snail->idle()) { + if ((mask & kMouseRightUp) && _snail->idle()) { Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_vm->_pocPtr] : NULL; if (ps) { if (_flags._kept || _hero->distance(this) < kDistMax) { @@ -1142,7 +1135,7 @@ void Sprite::touch(uint16 mask, int x, int y) { _vm->tooFar(); } else { if (_flags._kept) - mask |= L_UP; + mask |= kMouseLeftUp; else { if (_hero->distance(this) < kDistMax) { /// @@ -1169,7 +1162,7 @@ void Sprite::touch(uint16 mask, int x, int y) { } } } - if ((mask & L_UP) && _snail->idle()) { + if ((mask & kMouseLeftUp) && _snail->idle()) { if (_flags._kept) { int n; for (n = 0; n < kPocketNX; n++) { @@ -1398,9 +1391,6 @@ void CGEEngine::loadScript(const char *fname) { error("Bad INI line %d [%s]", lcnt, fname); } -#define GAME_FRAME_DELAY (1000 / 50) -#define GAME_TICK_DELAY (1000 / 62) - void CGEEngine::mainLoop() { sayDebug(); @@ -1431,11 +1421,11 @@ void CGEEngine::mainLoop() { void CGEEngine::handleFrame() { // Game frame delay uint32 millis = g_system->getMillis(); - while (!_eventManager->_quitFlag && (millis < (_lastFrame + GAME_FRAME_DELAY))) { + while (!_eventManager->_quitFlag && (millis < (_lastFrame + kGameFrameDelay))) { // Handle any pending events _eventManager->poll(); - if (millis >= (_lastTick + GAME_TICK_DELAY)) { + if (millis >= (_lastTick + kGameTickDelay)) { // Dispatch the tick to any active objects tick(); _lastTick = millis; @@ -1447,7 +1437,7 @@ void CGEEngine::handleFrame() { } _lastFrame = millis; - if (millis >= (_lastTick + GAME_TICK_DELAY)) { + if (millis >= (_lastTick + kGameTickDelay)) { // Dispatch the tick to any active objects tick(); _lastTick = millis; @@ -1579,8 +1569,8 @@ void CGEEngine::runGame() { _startupMode = 0; _snail->addCom(kSnLevel, -1, _oldLev, &_cavLight); - _cavLight->gotoxy(CAVE_X + ((_now - 1) % _caveNx) * _caveDx + CAVE_SX, - CAVE_Y + ((_now - 1) / _caveNx) * _caveDy + CAVE_SY); + _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, + kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); caveUp(); _keyboard->setClient(_sys); @@ -1643,7 +1633,7 @@ bool CGEEngine::showTitle(const char *name) { D.show(2); if (_mode == 2) { - inf(SVG0NAME); + inf(kSavegame0Name); _talk->show(2); } @@ -1732,15 +1722,15 @@ bool CGEEngine::showTitle(const char *name) { } void CGEEngine::cge_main() { - uint16 intStack[STACK_SIZ / 2]; + uint16 intStack[kStackSize / 2]; _intStackPtr = intStack; memset(_barriers, 0xFF, sizeof(_barriers)); if (!_mouse->_exist) - error("%s", _text->getText(NO_MOUSE_TEXT)); + error("%s", _text->getText(kTextNoMouse)); - if (!SVG0FILE::exist(SVG0NAME)) + if (!kSavegame0File::exist(kSavegame0Name)) _mode = 2; _debugLine->_flags._hide = true; diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index e3d8d408467..293943d358f 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -34,13 +34,11 @@ #include "cge/sound.h" namespace CGE { -#define CAVE_X 4 -#define CAVE_Y 166 -#define CAVE_SX 0 -#define CAVE_SY 0 - -#define PAIN (_vm->_flag[0]) +#define kCaveX 4 +#define kCaveY 166 +#define kCaveSX 0 +#define kCaveSY 0 #define kInfoX 177 #define kInfoY 164 #define kInfoW 140 @@ -85,6 +83,15 @@ namespace CGE { #define kScrWidth 320 #define kScrHeight 200 #define kWorldHeight (kScrHeight - kPanHeight) +#define kStackSize 2048 +#define kSavegameCheckSum (1956 + _now + _oldLev + _game + _music + _demoText) +#define kSavegame0Name ("{{INIT}}" kSvgExt) +#define kSavegame0File INI_FILE +#define kSavegameStrSize 11 +#define kGameFrameDelay (1000 / 50) +#define kGameTickDelay (1000 / 62) + + class System : public Sprite { int _lum; diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index 24fd3d2043b..3455052730d 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -154,10 +154,10 @@ SaveStateList CGEMetaEngine::listSaves(const char *target) const { CGE::SavegameHeader header; // Check to see if it's a ScummVM savegame or not - char buffer[SAVEGAME_STR_SIZE + 1]; - file->read(buffer, SAVEGAME_STR_SIZE + 1); + char buffer[kSavegameStrSize + 1]; + file->read(buffer, kSavegameStrSize + 1); - if (!strncmp(buffer, CGE::SAVEGAME_STR, SAVEGAME_STR_SIZE + 1)) { + if (!strncmp(buffer, CGE::savegameStr, kSavegameStrSize + 1)) { // Valid savegame if (CGE::CGEEngine::readSavegameHeader(file, header)) { saveList.push_back(SaveStateDescriptor(slotNum, header.saveName)); @@ -184,10 +184,10 @@ SaveStateDescriptor CGEMetaEngine::querySaveMetaInfos(const char *target, int sl CGE::SavegameHeader header; // Check to see if it's a ScummVM savegame or not - char buffer[SAVEGAME_STR_SIZE + 1]; - f->read(buffer, SAVEGAME_STR_SIZE + 1); + char buffer[kSavegameStrSize + 1]; + f->read(buffer, kSavegameStrSize + 1); - bool hasHeader = !strncmp(buffer, CGE::SAVEGAME_STR, SAVEGAME_STR_SIZE + 1) && + bool hasHeader = !strncmp(buffer, CGE::savegameStr, kSavegameStrSize + 1) && CGE::CGEEngine::readSavegameHeader(f, header); delete f; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 113b64cee88..50544255a8c 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -136,7 +136,7 @@ void Keyboard::newKeyboard(Common::Event &event) { if (_client) { CGEEvent &evt = _eventManager->getNextEvent(); evt._x = _current; // Keycode - evt._mask = KEYB; // Event mask + evt._mask = kEventKeyb; // Event mask evt._spritePtr = _client; // Sprite pointer } } @@ -218,22 +218,22 @@ void Mouse::newMouse(Common::Event &event) { switch (event.type) { case Common::EVENT_MOUSEMOVE: - evt._mask = ROLL; + evt._mask = kMouseRoll; break; case Common::EVENT_LBUTTONDOWN: - evt._mask = L_DN; + evt._mask = kMouseLeftDown; _buttons |= 1; break; case Common::EVENT_LBUTTONUP: - evt._mask = L_UP; + evt._mask = kMouseLeftUp; _buttons &= ~1; break; case Common::EVENT_RBUTTONDOWN: - evt._mask = R_DN; + evt._mask = kMouseRightDown; _buttons |= 2; break; case Common::EVENT_RBUTTONUP: - evt._mask = R_UP; + evt._mask = kMouseRightUp; _buttons &= ~2; break; default: @@ -282,22 +282,22 @@ void EventManager::handleEvents() { CGEEvent e = _eventQueue[_eventQueueTail]; if (e._mask) { if (_mouse->_hold && e._spritePtr != _mouse->_hold) - _mouse->_hold->touch(e._mask | ATTN, e._x - _mouse->_hold->_x, e._y - _mouse->_hold->_y); + _mouse->_hold->touch(e._mask | kEventAttn, e._x - _mouse->_hold->_x, e._y - _mouse->_hold->_y); // update mouse cursor position - if (e._mask & ROLL) + if (e._mask & kMouseRoll) _mouse->gotoxy(e._x, e._y); // activate current touched SPRITE if (e._spritePtr) { - if (e._mask & KEYB) + if (e._mask & kEventKeyb) e._spritePtr->touch(e._mask, e._x, e._y); else e._spritePtr->touch(e._mask, e._x - e._spritePtr->_x, e._y - e._spritePtr->_y); } else if (_sys) _sys->touch(e._mask, e._x, e._y); - if (e._mask & L_DN) { + if (e._mask & kMouseLeftDown) { _mouse->_hold = e._spritePtr; if (_mouse->_hold) { _mouse->_hold->_flags._hold = true; @@ -309,7 +309,7 @@ void EventManager::handleEvents() { } } - if (e._mask & L_UP) { + if (e._mask & kMouseLeftUp) { if (_mouse->_hold) { _mouse->_hold->_flags._hold = false; _mouse->_hold = NULL; @@ -318,10 +318,10 @@ void EventManager::handleEvents() { ///Touched = e.Ptr; // discard Text if button released - if (e._mask & (L_UP | R_UP)) + if (e._mask & (kMouseLeftUp | kMouseRightUp)) killText(); } - _eventQueueTail = (_eventQueueTail + 1) % EVT_MAX; + _eventQueueTail = (_eventQueueTail + 1) % kEventMax; } if (_mouse->_hold) { if (_mouse->_hold->_flags._drag) @@ -332,7 +332,7 @@ void EventManager::handleEvents() { void EventManager::clearEvent(Sprite *spr) { if (spr) { uint16 e; - for (e = _eventQueueTail; e != _eventQueueHead; e = (e + 1) % EVT_MAX) + for (e = _eventQueueTail; e != _eventQueueHead; e = (e + 1) % kEventMax) if (_eventQueue[e]._spritePtr == spr) _eventQueue[e]._mask = 0; } else @@ -341,7 +341,7 @@ void EventManager::clearEvent(Sprite *spr) { CGEEvent &EventManager::getNextEvent() { CGEEvent &evt = _eventQueue[_eventQueueHead]; - _eventQueueHead = (_eventQueueHead + 1) % EVT_MAX; + _eventQueueHead = (_eventQueueHead + 1) % kEventMax; return evt; } diff --git a/engines/cge/events.h b/engines/cge/events.h index b213caed3c0..124597c3291 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -40,6 +40,17 @@ namespace CGE { #define kKeyCtrl 29 #define kKeyAlt 56 +#define kEventMax 256 + +enum EventMask { + kMouseRoll = 1 << 0, + kMouseLeftDown = 1 << 1, + kMouseLeftUp = 1 << 2, + kMouseRightDown = 1 << 3, + kMouseRightUp = 1 << 4, + kEventAttn = 1 << 5, + kEventKeyb = 1 << 7 +}; class Keyboard { private: @@ -62,15 +73,6 @@ public: /*----------------- MOUSE interface -----------------*/ -#define EVT_MAX 256 -#define ROLL 0x01 -#define L_DN 0x02 -#define L_UP 0x04 -#define R_DN 0x08 -#define R_UP 0x10 -#define ATTN 0x20 // 0x40 -#define KEYB 0x80 - extern Talk *_talk; struct CGEEvent { @@ -105,7 +107,7 @@ private: class EventManager { private: Common::Event _event; - CGEEvent _eventQueue[EVT_MAX]; + CGEEvent _eventQueue[kEventMax]; uint16 _eventQueueHead; uint16 _eventQueueTail; diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 41075806919..e64e4af38a2 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -50,16 +50,16 @@ int Fly::_l = 20, Fly::Fly(CGEEngine *vm, Bitmap **shpl) : Sprite(vm, shpl), _tx(0), _ty(0), _vm(vm) { - step(new_random(2)); - gotoxy(_l + new_random(_r - _l - _w), _t + new_random(_b - _t - _h)); + step(newRandom(2)); + gotoxy(_l + newRandom(_r - _l - _w), _t + newRandom(_b - _t - _h)); } void Fly::tick() { step(); if (!_flags._kept) { - if (new_random(10) < 1) { - _tx = new_random(3) - 1; - _ty = new_random(3) - 1; + if (newRandom(10) < 1) { + _tx = newRandom(3) - 1; + _ty = newRandom(3) - 1; } if (_x + _tx < _l || _x + _tx + _w > _r) _tx = -_tx; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 8e141a8be41..b9c10a7029d 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -327,7 +327,7 @@ long timer() { return 0; } -int new_random(int range) { +int newRandom(int range) { return ((CGEEngine *)g_engine)->_randomSource.getRandomNumber(range - 1); } diff --git a/engines/cge/general.h b/engines/cge/general.h index 57991f21259..fe346061081 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -129,7 +129,7 @@ char *wtom(uint16 val, char *str, int radix, int len); char *dwtom(uint32 val, char * str, int radix, int len); int takeEnum(const char **tab, const char *text); long timer(); -int new_random(int range); +int newRandom(int range); } // End of namespace CGE #endif diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index a2408bc7922..d96e494402a 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -77,7 +77,7 @@ void GetText::touch(uint16 mask, int x, int y) { static char bezo[] = "ACELNOSXZ"; char *p; - if (mask & KEYB) { + if (mask & kEventKeyb) { _vm->keyClick(); switch (x) { case Enter : diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 4540c1d8e5b..128a92f5941 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -33,7 +33,6 @@ namespace CGE { // Defines found in cge.mak -#define VOL #define INI_FILE VFile // Or is it CFile? #define PIC_FILE VFile #define BMP_MODE 0 diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index decc516ae39..ba24f832c3e 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -107,7 +107,7 @@ Mixer::~Mixer() { void Mixer::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); - if (mask & L_UP) { + if (mask & kMouseLeftUp) { warning("STUB: Mixer::touch(): Digital Volume"); /* uint8 *vol = (&_sndDrvInfo.Vol2._d) + (x < _w / 2); if (y < kMixButtonHigh) { @@ -129,7 +129,7 @@ void Mixer::tick() { if (spriteAt(x, y) == this) { _fall = kMixFall; if (_flags._hold) - touch(L_UP, x - _x, y - _y); + touch(kMouseLeftUp, x - _x, y - _y); } else { if (_fall) _fall--; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index aece48a9336..2d4c28c0abf 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -36,15 +36,6 @@ namespace CGE { -extern Sprite *_pocLight; - -//------------------------------------------------------------------------- -// SPRITE * Pocket[POCKET_NX]={ NULL, NULL, NULL, NULL, -// NULL, NULL, NULL, NULL, }; -// int _pocPtr = 0; -//------------------------------------------------------------------------- -extern Sprite *_pocket[]; - void CGEEngine::snGame(Sprite *spr, int num) { debugC(1, kCGEDebugEngine, "CGEEngine::snGame(spr, %d)", num); @@ -67,11 +58,11 @@ void CGEEngine::snGame(Sprite *spr, int num) { } if (_game) { // continue game - int i = new_random(3), hand = (dup[0]->_shpCnt == 6); + int i = newRandom(3), hand = (dup[0]->_shpCnt == 6); Stage++; if (hand && Stage > kDressed) ++hand; - if (i >= 0 || (dup[i] == spr && new_random(3) == 0)) { + if (i >= 0 || (dup[i] == spr && newRandom(3) == 0)) { _snail->addCom(kSnSeq, -1, 3, dup[0]); // yes _snail->addCom(kSnSeq, -1, 3, dup[1]); // yes _snail->addCom(kSnSeq, -1, 3, dup[2]); // yes @@ -149,9 +140,9 @@ void CGEEngine::snGame(Sprite *spr, int num) { _snail->addCom(kSnGame, 20002, 2, NULL); _game = true; } else { // cont - _sprK1->step(new_random(6)); - _sprK2->step(new_random(6)); - _sprK3->step(new_random(6)); + _sprK1->step(newRandom(6)); + _sprK2->step(newRandom(6)); + _sprK3->step(newRandom(6)); ///-------------------- if (spr->_ref == 1 && _keyboard->_key[kKeyAlt]) { _sprK1->step(5); @@ -179,7 +170,7 @@ void CGEEngine::snGame(Sprite *spr, int num) { _game = false; return; } else - _sprK3->step(new_random(5)); + _sprK3->step(newRandom(5)); } if (_gameCase2Cpt < 100) { switch (_gameCase2Cpt) { diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 485ba00ad10..699bd5bcc16 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -199,18 +199,18 @@ void Text::say(const char *text, Sprite *spr) { _talk->_flags._kill = true; _talk->_flags._bDel = true; - _talk->setName(_text->getText(SAY_NAME)); + _talk->setName(_text->getText(kSayName)); _talk->gotoxy(x - (_talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - _talk->_h + 1); _talk->_z = 125; - _talk->_ref = SAY_REF; + _talk->_ref = kSayRef; spike->gotoxy(x, _talk->_y + _talk->_h - 1); spike->_z = 126; spike->_flags._slav = true; spike->_flags._kill = true; - spike->setName(_text->getText(SAY_NAME)); + spike->setName(_text->getText(kSayName)); spike->step(east); - spike->_ref = SAY_REF; + spike->_ref = kSayRef; _vga->_showQ->insert(_talk, _vga->_showQ->last()); _vga->_showQ->insert(spike, _vga->_showQ->last()); @@ -225,11 +225,11 @@ void CGEEngine::inf(const char *text) { if (_talk) { _talk->_flags._kill = true; _talk->_flags._bDel = true; - _talk->setName(_text->getText(INF_NAME)); + _talk->setName(_text->getText(kInfName)); _talk->center(); _talk->gotoxy(_talk->_x, _talk->_y - 20); _talk->_z = 126; - _talk->_ref = INF_REF; + _talk->_ref = kInfRef; _vga->_showQ->insert(_talk, _vga->_showQ->last()); } } diff --git a/engines/cge/text.h b/engines/cge/text.h index 6ed5b32b229..bb905ac655b 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -37,16 +37,11 @@ namespace CGE { #define kSayExt ".SAY" -#define NOT_VGA_TEXT 90 -#define BAD_CHIP_TEXT 91 -#define BAD_DOS_TEXT 92 -#define NO_CORE_TEXT 93 -#define BAD_MIPS_TEXT 94 -#define NO_MOUSE_TEXT 95 -#define INF_NAME 101 -#define SAY_NAME 102 -#define INF_REF 301 -#define SAY_REF 302 +#define kTextNoMouse 95 +#define kInfName 101 +#define kSayName 102 +#define kInfRef 301 +#define kSayRef 302 class Text { diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index e8aa899583f..48b27d97275 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -136,7 +136,7 @@ void Vmenu::touch(uint16 mask, int x, int y) { _bar->gotoxy(_x + kTextHMargin - kMenuBarHM, _y + kTextVMargin + n * h - kMenuBarVM); - if (ok && (mask & L_UP)) { + if (ok && (mask & kMouseLeftUp)) { _items = 0; _snail_->addCom(kSnKill, -1, 0, this); _recent = n; From 7ea1f74759c2b1a5e9d497a6bc3175a414ac94a1 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 3 Aug 2011 16:31:32 +0200 Subject: [PATCH 177/276] CGE: Fix display of info text at the beginning of the game --- engines/cge/vga13h.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index cc715da03c0..8889c59b8dd 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -813,7 +813,7 @@ Vga::Vga(int mode) for (int i = 10; i < 20; i++) { char *text = _text->getText(i); if (text) { - debugN("%s", text); + debugN("%s\n", text); std = false; } } From d229c92879048bc1e48892231783a4788f452490 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 5 Aug 2011 21:09:03 +1000 Subject: [PATCH 178/276] CGE: Built an English version game archive This combines the base game resources with the files of cge_work\dusa and work\ins\usa. This makes both action descriptions and hotspots appear in English, although the introduction credits still appear in Polish. I don't know if this was the case for the original 'official' English release; but I consider it a minor issue. --- engines/cge/detection.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index 24fd3d2043b..fbe3bc60767 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -75,6 +75,17 @@ static const ADGameDescription gameDescriptions[] = { }, Common::PL_POL, Common::kPlatformPC, ADGF_DEMO, GUIO_NONE }, + // English ScummVM version + { + "soltys", "", + { + {"vol.cat", 0, "bfea076fee47b8d64fdf213e56c60911", 50176}, + {"vol.dat", 0, "f9ae2e7f8f7cac91378cdafca43faf1e", 8427396}, + AD_LISTEND + }, + Common::EN_ANY, Common::kPlatformPC, ADGF_NO_FLAGS, GUIO_NONE + }, + AD_TABLE_END_MARKER }; From b7a548f3c75e80573b31dd7fdec39bd6569af662 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 5 Aug 2011 21:23:41 +1000 Subject: [PATCH 179/276] CGE: Fixed compiler warning of shadowed variable --- engines/cge/cge_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 123501047ae..05beaae58d0 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -318,8 +318,8 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt if (s.isSaving()) { for (i = 0; i < kPocketNX; i++) { - register Sprite *s = _pocket[i]; - _pocref[i] = (s) ? s->_ref : -1; + register Sprite *spr = _pocket[i]; + _pocref[i] = (spr) ? spr->_ref : -1; } warning("STUB: CGEEngine::syncGame Digital and Midi volume"); From 3ce71737b590ed1306f836c6fb751c2d2654a431 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 5 Aug 2011 21:54:21 +1000 Subject: [PATCH 180/276] CGE: Fix mismatched memory free. --- engines/cge/bitmap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index c02c66df8b3..6689998debd 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -187,7 +187,7 @@ uint16 Bitmap::moveVmap(uint8 *buf) { uint16 vsiz = (uint8 *)_b - (uint8 *)_v; uint16 siz = vsiz + _h * sizeof(HideDesc); memcpy(buf, _v, siz); - free(_v); + delete[] _v; _b = (HideDesc *)((_v = buf) + vsiz); return siz; } From c1294b772f3f459976dacb1c06f45425cc94853b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 5 Aug 2011 22:51:32 +1000 Subject: [PATCH 181/276] CGE: Added an assert to test out of bounds sprite shape access The English version seems to expect a different number of shapes for some sprites, so it will need further work to determine how best to handle the differences. --- engines/cge/vga13h.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 9b30e02e4da..62b902b19ca 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -382,6 +382,7 @@ Sprite *Sprite::expand() { if (len == 0 || *line == '.') continue; + assert(shpcnt <= _shpCnt); switch (takeEnum(Comd, strtok(line, " =\t"))) { case 0 : { // Name setName(strtok(NULL, "")); From 388dadd56f0b0f35e0b617d1a8ce9ab47a0c14fc Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 13:12:22 +1000 Subject: [PATCH 182/276] CGE: Changed sprite shape list loading to exceed size specified by _shpCnt This fixes the problem that was happening with the new English archive, which had a bigger shape list for one of the items in the first scene. --- engines/cge/vga13h.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index de28794f3f1..f34211c360a 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -25,6 +25,7 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ +#include "common/array.h" #include "common/rect.h" #include "graphics/palette.h" #include "cge/general.h" @@ -358,7 +359,9 @@ Sprite *Sprite::expand() { if (*_file) { static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; char line[kLineMax], fname[kPathMax]; - BitmapPtr *shplist = new BitmapPtr[_shpCnt + 1]; + + Common::Array shplist; + for (int i = 0; i < _shpCnt + 1; ++i) shplist.push_back(NULL); Seq *seq = NULL; int shpcnt = 0, seqcnt = 0, @@ -382,13 +385,18 @@ Sprite *Sprite::expand() { if (len == 0 || *line == '.') continue; - assert(shpcnt <= _shpCnt); switch (takeEnum(Comd, strtok(line, " =\t"))) { case 0 : { // Name setName(strtok(NULL, "")); break; } case 1 : { // Phase + // In case the shape index gets too high, increase the array size + while ((shpcnt + 1) >= (int)shplist.size()) { + shplist.push_back(NULL); + ++_shpCnt; + } + shplist[shpcnt++] = new Bitmap(strtok(NULL, " \t,;/"), true); break; } @@ -456,7 +464,12 @@ Sprite *Sprite::expand() { } else setSeq(getConstantSeq(_shpCnt == 1)); - setShapeList(shplist); + // Set the shape list + BitmapPtr *shapeList = new BitmapPtr[shplist.size()]; + for (uint i = 0; i < shplist.size(); ++i) + shapeList[i] = shplist[i]; + + setShapeList(shapeList); if (nea) nea[neacnt - 1]._ptr = _ext->_near = nea; From 0cb8b15cdf3eafbfea33ab68c6f3d43e42f11e80 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 13:30:36 +1000 Subject: [PATCH 183/276] CGE: Fixed warning of shadowed variable --- engines/cge/vga13h.cpp | 8 ++++---- engines/cge/vga13h.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index f34211c360a..d2ba9b1b999 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -337,16 +337,16 @@ Snail::Com *Sprite::snList(SnList type) { } -void Sprite::setName(char *name) { +void Sprite::setName(char *newName) { if (_ext) { if (_ext->_name) { delete[] _ext->_name; _ext->_name = NULL; } - if (name) { - _ext->_name = new char[strlen(name) + 1]; + if (newName) { + _ext->_name = new char[strlen(newName) + 1]; assert(_ext->_name != NULL); - strcpy(_ext->_name, name); + strcpy(_ext->_name, newName); } } } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index f72d4c693da..db75b48692d 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -187,7 +187,7 @@ public: Sprite *expand(); Sprite *contract(); Sprite *backShow(bool fast = false); - void setName(char *name); + void setName(char *newName); inline char *name() { return (_ext) ? _ext->_name : NULL; } From 33c42264868573ed7a47f66075f75d60d2233b39 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 13:34:33 +1000 Subject: [PATCH 184/276] CGE: Fix another shadowed variable warning --- engines/cge/cge_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index d9d32b7f397..71089c5ea9d 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -311,8 +311,8 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt if (s.isSaving()) { for (i = 0; i < kPocketNX; i++) { - register Sprite *spr = _pocket[i]; - _pocref[i] = (spr) ? spr->_ref : -1; + register Sprite *pocSpr = _pocket[i]; + _pocref[i] = (pocSpr) ? pocSpr->_ref : -1; } warning("STUB: CGEEngine::syncGame Digital and Midi volume"); From 63d49d3e1a460e848915ee54ca85812e1129aaf8 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 13:46:44 +1000 Subject: [PATCH 185/276] CGE: Fix uninitialised value Valgrind warnings when saving sprite data --- engines/cge/vga13h.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d2ba9b1b999..4ad4e83ad6f 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -647,7 +647,7 @@ BitmapPtr Sprite::ghost() { } void Sprite::sync(Common::Serializer &s) { - uint16 unused; + uint16 unused = 0; s.syncAsUint16LE(unused); s.syncAsUint16LE(unused); // _ext From f5d38d82d0c805f6c6d2d58999791cc69f29a024 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 14:01:00 +1000 Subject: [PATCH 186/276] CGE: Fix mismatched delete in Bitmap::_v --- engines/cge/bitmap.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index b53cac4e90f..60b6cc90fac 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -141,7 +141,7 @@ Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), if (v0) { uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); uint16 siz = vsiz + _h * sizeof(HideDesc); - uint8 *v1 = (uint8 *) malloc(sizeof(uint8) * siz); + uint8 *v1 = new uint8[siz]; assert(v1 != NULL); memcpy(v1, v0, siz); _b = (HideDesc *)((_v = v1) + vsiz); From c961597988ab0e9d9ed7dff5b317d620bcc84153 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 15:29:49 +1000 Subject: [PATCH 187/276] CGE: Fixed non-portability in loading _heroXY array --- engines/cge/cge_main.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 71089c5ea9d..41bb68417ce 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -26,6 +26,7 @@ */ #include "common/scummsys.h" +#include "common/endian.h" #include "common/memstream.h" #include "common/savefile.h" #include "common/serializer.h" @@ -110,11 +111,12 @@ void CGEEngine::syncHeader(Common::Serializer &s) { for (i = 0; i < 4; i++) s.syncAsUint16LE(_flag[i]); - initCaveValues(); if (s.isLoading()) { - //TODO: Fix the memory leak when the game is already running - _heroXY = (Hxy *) malloc (sizeof(Hxy) * _caveMax); - _barriers = (Bar *) malloc (sizeof(Bar) * (1 + _caveMax)); + // Reinitialise cave values + free(_heroXY); + free(_barriers); + + initCaveValues(); } for (i = 0; i < _caveMax; i++) { @@ -429,9 +431,18 @@ void CGEEngine::loadHeroXY() { debugC(1, kCGEDebugEngine, "CGEEngine::loadHeroXY()"); INI_FILE cf(progName(".HXY")); + uint16 x, y; + memset(_heroXY, 0, sizeof(_heroXY)); - if (!cf._error) - cf.read((uint8 *)(&_heroXY),sizeof(*(&_heroXY))); + if (!cf._error) { + for (int i = 0; i < _caveMax; ++i) { + cf.read((byte *)&x, 2); + cf.read((byte *)&y, 2); + + _heroXY[i]._x = (int16)FROM_LE_16(x); + _heroXY[i]._y = (int16)FROM_LE_16(y); + } + } } void CGEEngine::loadMapping() { From fc05b8cf1b489933d28e35d949f2de62cc0d8c6a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 16:08:47 +1000 Subject: [PATCH 188/276] CGE: Fix memory leak with savegame thumbnails --- engines/cge/cge_main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 41bb68417ce..3d1c4518625 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -293,6 +293,7 @@ void CGEEngine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &he Graphics::Surface *s = _vga->_page[0]; ::createThumbnail(thumb, (const byte *)s->pixels, kScrWidth, kScrHeight, thumbPalette); Graphics::saveThumbnail(*out, *thumb); + thumb->free(); delete thumb; // Write out the save date/time From 9f8eb5a74086881f2818256b01fb6fb946c6420a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 16:55:39 +1000 Subject: [PATCH 189/276] CGE: Re-added an explicit check in Sprite destructor against _sprite variable The trouble is that the _sprite variable can currently be pointing to any registered sprite, and should only be freed in the destructor if it hasn't already been freed. Currently, this is best done by keeping track of whether the pointed to sprite has been already freed or not. --- engines/cge/vga13h.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 4ad4e83ad6f..b1858c0cbe0 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -231,6 +231,9 @@ Sprite::Sprite(CGEEngine *vm, BitmapPtr *shpP) Sprite::~Sprite() { + if (_sprite == this) + _sprite = NULL; + contract(); } From 1f6c27480d67593cdd786ef25762eee249f74d36 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 17:22:04 +1000 Subject: [PATCH 190/276] CGE: Fix memory leak with _sprite global sprite --- engines/cge/cge.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 2baf1cde1e4..c06e65491db 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -131,6 +131,7 @@ void CGEEngine::setup() { _pocket[i]->_flags._kill = false; } _sprite = new Sprite(this, NULL); + _sprite->_flags._kill = false; _horzLine = new HorizLine(this); _infoLine = new InfoLine(this, kInfoW); _cavLight = new CavLight(this); @@ -190,7 +191,7 @@ CGEEngine::~CGEEngine() { // Delete engine objects delete _vga; delete _sys; - //delete _sprite; Sprite is destroyed by the queue it's added to + delete _sprite; delete _miniCave; delete _shadow; delete _horzLine; From 5aba6b5a0c5876792290fac806695fee9fecd743 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 18:23:53 +1000 Subject: [PATCH 191/276] CGE: Removed redundant _sprite creation in engine setup --- engines/cge/cge.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index c06e65491db..603352d8a0a 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -110,6 +110,7 @@ void CGEEngine::setup() { _miniCave = NULL; _miniShp = NULL; _miniShpList = NULL; + _sprite = NULL; // Create debugger console _console = new CGEConsole(this); @@ -130,8 +131,6 @@ void CGEEngine::setup() { _pocket[i] = new Sprite(this, NULL); _pocket[i]->_flags._kill = false; } - _sprite = new Sprite(this, NULL); - _sprite->_flags._kill = false; _horzLine = new HorizLine(this); _infoLine = new InfoLine(this, kInfoW); _cavLight = new CavLight(this); From db61f65b41530b01d2aa2ae6f31496bee669585d Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 19:23:01 +1000 Subject: [PATCH 192/276] CGE: Fix uninitialised warning on event polling --- engines/cge/events.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 50544255a8c..916de839ebb 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -247,6 +247,7 @@ EventManager::EventManager() { _quitFlag = false; _eventQueueHead = 0; _eventQueueTail = 0; + memset(&_event, 0, sizeof(Common::Event)); } void EventManager::poll() { From 46e1f03585ffd841eba3a2f5570bd0559cb833bd Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 20:03:42 +1000 Subject: [PATCH 193/276] CGE: Fixed up freeing of caveValues data --- engines/cge/cge.cpp | 10 +++++++--- engines/cge/cge.h | 1 + engines/cge/cge_main.cpp | 4 +--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 603352d8a0a..2a4ea6bea26 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -99,6 +99,12 @@ void CGEEngine::initCaveValues() { } } +void CGEEngine::freeCaveValues() { + delete[] _mini; + free(_heroXY); + free(_barriers); +} + void CGEEngine::setup() { debugC(1, kCGEDebugEngine, "CGEEngine::setup()"); @@ -209,10 +215,8 @@ CGEEngine::~CGEEngine() { delete _snail; delete _snail_; delete _hero; - delete[] _mini; - free(_heroXY); - free(_barriers); + freeCaveValues(); } Common::Error CGEEngine::run() { diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 54ea9e37f62..54bbadfef7e 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -219,6 +219,7 @@ public: void postMiniStep(int stp); void showBak(int ref); void initCaveValues(); + void freeCaveValues(); void snBackPt(Sprite *spr, int stp); void snBarrier(int cav, int bar, bool horz); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 3d1c4518625..b17f40b863f 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -113,9 +113,7 @@ void CGEEngine::syncHeader(Common::Serializer &s) { if (s.isLoading()) { // Reinitialise cave values - free(_heroXY); - free(_barriers); - + freeCaveValues(); initCaveValues(); } From 1208e7e5af5d5cf74c615f6b5e7f40800100d146 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 21:03:24 +1000 Subject: [PATCH 194/276] CGE: Removed the _mini data block originally used to hold inventory shapes in high memory --- engines/cge/cge.cpp | 5 ++--- engines/cge/cge.h | 1 - engines/cge/cge_main.cpp | 22 +++++++++------------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 2a4ea6bea26..b38b6d392f4 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -58,13 +58,11 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) void CGEEngine::initCaveValues() { if (_isDemo) { - _mini = new byte[16384]; _caveDx = 23; _caveDy = 29; _caveNx = 3; _caveNy = 1; } else { - _mini = new byte[65536]; _caveDx = 9; _caveDy = 10; _caveNx = 8; @@ -100,7 +98,6 @@ void CGEEngine::initCaveValues() { } void CGEEngine::freeCaveValues() { - delete[] _mini; free(_heroXY); free(_barriers); } @@ -216,6 +213,8 @@ CGEEngine::~CGEEngine() { delete _snail_; delete _hero; + delete[] _miniShpList; + freeCaveValues(); } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 54bbadfef7e..23509bbf49c 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -142,7 +142,6 @@ public: Bar *_barriers; Common::RandomSource _randomSource; - byte *_mini; BitmapPtr *_miniShp; BitmapPtr *_miniShpList; int _startGameSlot; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index b17f40b863f..6b6f4ff971d 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1525,22 +1525,18 @@ void CGEEngine::runGame() { if (!_music) killMidi(); - if (_mini && INI_FILE::exist("MINI.SPR")) { + if (INI_FILE::exist("MINI.SPR")) { _miniShp = new BitmapPtr[2]; _miniShp[0] = _miniShp[1] = NULL; - uint8 *ptr = (uint8 *) &*_mini; - if (ptr != NULL) { - loadSprite("MINI", -1, 0, kMiniX, kMiniY); - expandSprite(_miniCave = _sprite); // NULL is ok - if (_miniCave) { - _miniCave->_flags._kill = false; - _miniCave->_flags._hide = true; - _miniCave->moveShapes(ptr); - _miniShp[0] = new Bitmap(*_miniCave->shp()); - _miniShpList = _miniCave->setShapeList(_miniShp); - postMiniStep(-1); - } + loadSprite("MINI", -1, 0, kMiniX, kMiniY); + expandSprite(_miniCave = _sprite); // NULL is ok + if (_miniCave) { + _miniCave->_flags._kill = false; + _miniCave->_flags._hide = true; + _miniShp[0] = new Bitmap(*_miniCave->shp()); + _miniShpList = _miniCave->setShapeList(_miniShp); + postMiniStep(-1); } } From 04e09e530a3bff231022ebf1c50ae5b70fc1c4a7 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 6 Aug 2011 22:14:23 +1000 Subject: [PATCH 195/276] CGE: Fix memory leaks in pocket list --- engines/cge/cge.cpp | 10 ++++------ engines/cge/cge_main.cpp | 1 - 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index b38b6d392f4..0d63b32d090 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -130,10 +130,8 @@ void CGEEngine::setup() { _vga = new Vga(M13H); _sys = new System(this); _pocLight = new PocLight(this); - for (int i = 0; i < kPocketNX; i++) { - _pocket[i] = new Sprite(this, NULL); - _pocket[i]->_flags._kill = false; - } + for (int i = 0; i < kPocketNX; i++) + _pocket[i] = NULL; _horzLine = new HorizLine(this); _infoLine = new InfoLine(this, kInfoW); _cavLight = new CavLight(this); @@ -207,12 +205,12 @@ CGEEngine::~CGEEngine() { delete _eventManager; delete _fx; delete _sound; - for (int i = 0; i < kPocketNX; i++) - delete _pocket[i]; delete _snail; delete _snail_; delete _hero; + for (int i = 0; _miniShpList[i]; ++i) + delete _miniShpList[i]; delete[] _miniShpList; freeCaveValues(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 6b6f4ff971d..fd45dd797f8 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -356,7 +356,6 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt for (i = 0; i < kPocketNX; i++) { register int r = _pocref[i]; - delete _pocket[i]; _pocket[i] = (r < 0) ? NULL : _vga->_spareQ->locate(r); } } From cbb828b337979e4dae4d5f1560ca4debe94079c4 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 7 Aug 2011 11:34:03 +0200 Subject: [PATCH 196/276] CGE: Fix a couple of warnings reported by cppcheck --- engines/cge/cfile.h | 8 +++----- engines/cge/cge_main.cpp | 2 +- engines/cge/detection.cpp | 2 +- engines/cge/vol.cpp | 2 +- engines/cge/walk.cpp | 2 +- engines/cge/walk.h | 3 +-- 6 files changed, 8 insertions(+), 11 deletions(-) diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index 6ed3b5e7502..f5d784073bd 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -41,13 +41,11 @@ protected: uint16 _ptr; uint16 _lim; long _bufMark; - uint16 _seed; - Crypt *_crypt; virtual void readBuf(); virtual void writeBuf(); public: - IoBuf(IOMode mode, Crypt *crpt = NULL); - IoBuf(const char *name, IOMode mode, Crypt *crpt = NULL); + IoBuf(IOMode mode, Crypt *crpt); + IoBuf(const char *name, IOMode mode, Crypt *crpt); virtual ~IoBuf(); uint16 read(void *buf, uint16 len); uint16 read(uint8 *buf); @@ -61,7 +59,7 @@ public: class CFile : public IoBuf { public: static uint16 _maxLineLen; - CFile(const char *name, IOMode mode = kModeRead, Crypt *crpt = NULL); + CFile(const char *name, IOMode mode, Crypt *crpt); virtual ~CFile(); void flush(); long mark(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index fd45dd797f8..d709b65c1db 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -91,7 +91,7 @@ const char *savegameStr = "SCUMMVM_CGE"; static bool _finis = false; int _offUseCount; -uint16 *_intStackPtr = false; +uint16 *_intStackPtr = NULL; extern Dac _stdPal[58]; diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index 7eb147d6977..e944f2e9b75 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -154,7 +154,7 @@ SaveStateList CGEMetaEngine::listSaves(const char *target) const { SaveStateList saveList; int slotNum = 0; - for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); filename++) { + for (Common::StringArray::const_iterator filename = filenames.begin(); filename != filenames.end(); ++filename) { // Obtain the last 3 digits of the filename, since they correspond to the save slot slotNum = atoi(filename->c_str() + filename->size() - 3); diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 9074a8f0616..b3cc49495ac 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -71,7 +71,7 @@ void VFile::deinit() { } VFile::VFile(const char *name, IOMode mode) - : IoBuf(mode) { + : IoBuf(mode, NULL) { debugC(3, kCGEDebugFile, "VFile::VFile(%s, %d)", name, mode); if (mode == kModeRead) { diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index a9eeb6db8ef..a418bfb178e 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -70,7 +70,7 @@ Cluster XZ(Couple xy) { } Walk::Walk(CGEEngine *vm, BitmapPtr *shpl) - : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _vm(vm) { + : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _target(-1, -1), _vm(vm) { } diff --git a/engines/cge/walk.h b/engines/cge/walk.h index 115cb4924a7..8327c901b6f 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -49,7 +49,6 @@ protected: signed char _a; signed char _b; public: - Couple() { } Couple(const signed char a, const signed char b) : _a(a), _b(b) { } Couple operator + (Couple c) { return Couple(_a + c._a, _b + c._b); @@ -91,8 +90,8 @@ public: static void init(CGEEngine *vm); public: uint8 &cell(); - Cluster() : Couple() { } Cluster(int a, int b) : Couple(a, b) { } + Cluster() : Couple (-1, -1) { } bool chkBar() const; bool isValid() const; From de40ab5e0a24de6139be41f58399b83545a0928d Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 7 Aug 2011 11:36:49 +0200 Subject: [PATCH 197/276] CGE: Remove JBW flag (useless) --- engines/cge/cge.cpp | 1 - engines/cge/cge.h | 1 - engines/cge/cge_main.cpp | 18 ------------------ 3 files changed, 20 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 0d63b32d090..6fc23969c25 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -51,7 +51,6 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) _startupMode = 1; _demoText = kDemo; _oldLev = 0; - _jbw = false; _pocPtr = 0; } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 23509bbf49c..d681eb43e39 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -111,7 +111,6 @@ public: int _startupMode; int _demoText; int _oldLev; - bool _jbw; int _pocPtr; bool _music; int _pocref[kPocketNX]; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index d709b65c1db..6fed0b73ce6 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -724,19 +724,15 @@ void System::funTouch() { } void System::touch(uint16 mask, int x, int y) { - static int pp = 0; - funTouch(); if (mask & kEventKeyb) { - int pp0; _vm->keyClick(); killText(); if (_vm->_startupMode == 1) { _snail->addCom(kSnClear, -1, 0, NULL); return; } - pp0 = pp; switch (x) { case Del: if (_keyboard->_key[kKeyAlt] && _keyboard->_key[kKeyCtrl]) @@ -817,21 +813,7 @@ void System::touch(uint16 mask, int x, int y) { if (_snail->idle() && !_hero->_flags._hide) _vm->startCountDown(); break; - case 'J': - if (pp == 0) - pp++; - break; - case 'B': - if (pp == 1) - pp++; - break; - case 'W': - if (pp == 2) - _vm->_jbw = !_vm->_jbw; - break; } - if (pp == pp0) - pp = 0; } else { if (_vm->_startupMode) return; From 7ae8f8ce69ba27b4ee2c1b42dcb624d59edcdfe0 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 10 Aug 2011 18:38:06 +1000 Subject: [PATCH 198/276] CGE: Decrease delay amounts to give better precision for frame execution --- engines/cge/cge_main.cpp | 2 +- engines/cge/vga13h.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 6fed0b73ce6..71acd2a522f 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1423,7 +1423,7 @@ void CGEEngine::handleFrame() { } // Slight delay - g_system->delayMillis(10); + g_system->delayMillis(5); millis = g_system->getMillis(); } _lastFrame = millis; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index b1858c0cbe0..7c11653c4e5 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -897,7 +897,7 @@ void Vga::setStatAdr() { void Vga::waitVR(bool on) { // Since some of the game parts rely on using vertical sync as a delay mechanism, // we're introducing a short delay to simulate it - g_system->delayMillis(10); + g_system->delayMillis(5); } From 621fa62e8b21535fc2b6e82d0686f1ae06b7ec7a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 10 Aug 2011 19:02:13 +1000 Subject: [PATCH 199/276] CGE: Save the game if the game is quit via closing the window --- engines/cge/cge_main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 71acd2a522f..4d3b3b251e2 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1568,6 +1568,10 @@ void CGEEngine::runGame() { mainLoop(); } + // If finishing game due to closing ScummVM window, explicitly save the game + if (!_finis) + qGame(); + _keyboard->setClient(NULL); _snail->addCom(kSnClear, -1, 0, NULL); _snail_->addCom(kSnClear, -1, 0, NULL); From 8cad6821bd1c045b65878e02cfd666a39d1e8ed1 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 10 Aug 2011 19:33:08 +1000 Subject: [PATCH 200/276] CGE: Fixes for saving games --- engines/cge/cge_main.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 4d3b3b251e2..5e7e3d9ac40 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -239,7 +239,16 @@ Common::Error CGEEngine::loadGameState(int slot) { } Common::Error CGEEngine::saveGameState(int slot, const Common::String &desc) { + caveDown(); + _oldLev = _lev; + saveSound(); + + // Write out the user's progress saveGame(slot, desc); + + // Reload the scene + caveUp(); + return Common::kNoError; } From 0c33687de29c23e7750855ca7885dfad933f869b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 10 Aug 2011 20:41:39 +1000 Subject: [PATCH 201/276] CGE: Further fixes to savegames. --- engines/cge/cge.h | 1 + engines/cge/cge_main.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index d681eb43e39..55c97d0644d 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -156,6 +156,7 @@ public: void quit(); void resetQSwitch(); void optionTouch(int opt, uint16 mask); + void resetGame(); bool loadGame(int slotNumber, SavegameHeader *header = NULL, bool tiny = false); void setMapBrick(int x, int z); void switchMapping(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 5e7e3d9ac40..0ce514c6bb8 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -192,6 +192,7 @@ bool CGEEngine::loadGame(int slotNumber, SavegameHeader *header, bool tiny) { } // Delete the thumbnail + saveHeader.thumbnail->free(); delete saveHeader.thumbnail; // If we're loading the auto-save slot, load the name @@ -229,15 +230,19 @@ Common::String CGEEngine::generateSaveName(int slot) { Common::Error CGEEngine::loadGameState(int slot) { // Clear current game activity caveDown(); + resetGame(); // Load the game - loadGame(slot, NULL, true); - caveUp(); loadGame(slot, NULL); + caveUp(); return Common::kNoError; } +void CGEEngine::resetGame() { + _vga->_spareQ->clear(); +} + Common::Error CGEEngine::saveGameState(int slot, const Common::String &desc) { caveDown(); _oldLev = _lev; @@ -1578,7 +1583,7 @@ void CGEEngine::runGame() { } // If finishing game due to closing ScummVM window, explicitly save the game - if (!_finis) + if (!_finis && canSaveGameStateCurrently()) qGame(); _keyboard->setClient(NULL); From f1f1d8bde084b44756480c7b724f356562ca02b1 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 12 Aug 2011 19:48:51 +1000 Subject: [PATCH 202/276] CGE: Implemented sound effects --- engines/cge/general.cpp | 20 ++++++++++---------- engines/cge/snddrv.h | 6 ------ engines/cge/sound.cpp | 18 +++++++++++++++++- engines/cge/sound.h | 9 +++++++++ engines/cge/wav.h | 13 ++++++++----- 5 files changed, 44 insertions(+), 22 deletions(-) diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index b9c10a7029d..67068a9673b 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -282,14 +282,6 @@ void sndSetVolume() { warning("STUB: SNDSetVolume"); } -void sndDigiStart(SmpInfo *PSmpInfo) { - warning("STUB: SNDDigitStart"); -} - -void sndDigiStop(SmpInfo *PSmpInfo) { - warning("STUB: SNDDigiStop"); -} - void sndMidiStart(uint8 *MIDFile) { warning("STUB: SNDMIDIStart"); } @@ -299,8 +291,10 @@ void sndMidiStop() { } DataCk *loadWave(XFile *file) { - warning("STUB: LoadWave"); - return NULL; + byte *data = (byte *)malloc(file->size()); + file->read(data, file->size()); + + return new DataCk(data, file->size()); } int takeEnum(const char **tab, const char *text) { @@ -331,9 +325,15 @@ int newRandom(int range) { return ((CGEEngine *)g_engine)->_randomSource.getRandomNumber(range - 1); } +DataCk::DataCk(byte *buf, int size) { + _buf = buf; + _ckSize = size; +} + DataCk::~DataCk() { if (_buf) free(_buf); } + } // End of namespace CGE diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 07c4ccd0dd8..44ccf47f949 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -73,12 +73,6 @@ void sndDone(); // Set Volume void sndSetVolume(); -// Start Digi -void sndDigiStart(SmpInfo *PSmpInfo); - -// Stop Digi -void sndDigiStop(SmpInfo *PSmpInfo); - // Start MIDI File void sndMidiStart(uint8 *MIDFile); diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 56db1a64824..2cb24df5ba8 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -31,11 +31,13 @@ #include "cge/cfile.h" #include "cge/vol.h" #include "cge/cge_main.h" - +#include "common/memstream.h" +#include "audio/decoders/raw.h" namespace CGE { Sound::Sound(CGEEngine *vm) : _vm(vm) { + _audioStream = NULL; open(); } @@ -68,11 +70,25 @@ void Sound::play(DataCk *wav, int pan, int cnt) { } } +void Sound::sndDigiStart(SmpInfo *PSmpInfo) { + // Create an audio stream wrapper for sound + Common::MemoryReadStream *stream = new Common::MemoryReadStream(PSmpInfo->_saddr, + PSmpInfo->_slen, DisposeAfterUse::NO); + _audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES); + + // Start the new sound + _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, _audioStream); +} void Sound::stop() { sndDigiStop(&_smpinf); } +void Sound::sndDigiStop(SmpInfo *PSmpInfo) { + if (_vm->_mixer->isSoundHandleActive(_soundHandle)) + _vm->_mixer->stopHandle(_soundHandle); + _audioStream = NULL; +} Fx::Fx(int size) : _current(NULL) { _cache = new Han[size]; diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 292cb30e766..67b16fc888b 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -31,6 +31,10 @@ #include "cge/wav.h" #include "cge/snddrv.h" #include "cge/cge.h" +#include "audio/audiostream.h" +#include "audio/decoders/wave.h" +#include "audio/fmopl.h" +#include "audio/mixer.h" namespace CGE { @@ -45,6 +49,11 @@ public: void stop(); private: CGEEngine *_vm; + Audio::SoundHandle _soundHandle; + Audio::RewindableAudioStream *_audioStream; + + void sndDigiStart(SmpInfo *PSmpInfo); + void sndDigiStop(SmpInfo *PSmpInfo); }; diff --git a/engines/cge/wav.h b/engines/cge/wav.h index bd9fc96b0a7..824f40f96fc 100644 --- a/engines/cge/wav.h +++ b/engines/cge/wav.h @@ -115,16 +115,19 @@ public: }; -class DataCk : public CkHea { +class DataCk { bool _ef; - uint8 *_buf; + byte *_buf; + int _ckSize; public: - DataCk(CkHea &hea); - DataCk(int first, int last); + DataCk(byte *buf, int size); ~DataCk(); - inline uint8 *addr() { + inline const byte *addr() { return _buf; } + inline int size() { + return _ckSize; + } }; From b76c0af2f4fe9cafeafdde70867e159e076b2752 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 12 Aug 2011 21:33:45 +1000 Subject: [PATCH 203/276] CGE: Work on implementing MIDI music playback. Music playback is now sort of working, but it seems like only a beat track of the MIDI is getting played --- engines/cge/cge.cpp | 11 +++-- engines/cge/cge.h | 2 + engines/cge/cge_main.cpp | 12 ++--- engines/cge/general.cpp | 16 ------- engines/cge/snddrv.h | 16 ------- engines/cge/sound.cpp | 99 +++++++++++++++++++++++++--------------- engines/cge/sound.h | 28 ++++++++++-- 7 files changed, 102 insertions(+), 82 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 6fc23969c25..cfd941017e4 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -165,7 +165,7 @@ void CGEEngine::setup() { _flag[i] = false; _mode = 0; - _soundOk = 0; + _soundOk = 1; _sprTv = NULL; _gameCase2Cpt = 0; @@ -186,6 +186,7 @@ CGEEngine::~CGEEngine() { DebugMan.clearAllDebugChannels(); delete _console; + _midiPlayer.killMidi(); // Delete engine objects delete _vga; @@ -208,9 +209,11 @@ CGEEngine::~CGEEngine() { delete _snail_; delete _hero; - for (int i = 0; _miniShpList[i]; ++i) - delete _miniShpList[i]; - delete[] _miniShpList; + if (_miniShpList) { + for (int i = 0; _miniShpList[i]; ++i) + delete _miniShpList[i]; + delete[] _miniShpList; + } freeCaveValues(); } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 55c97d0644d..bd347c6e269 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -34,6 +34,7 @@ #include "engines/advancedDetector.h" #include "cge/console.h" #include "cge/bitmap.h" +#include "cge/sound.h" namespace CGE { @@ -141,6 +142,7 @@ public: Bar *_barriers; Common::RandomSource _randomSource; + MusicPlayer _midiPlayer; BitmapPtr *_miniShp; BitmapPtr *_miniShpList; int _startGameSlot; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 0ce514c6bb8..1dd6e496501 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -591,7 +591,7 @@ void CGEEngine::caveUp() { int BakRef = 1000 * _now; if (_music) - loadMidi(_now); + _midiPlayer.loadMidi(_now); showBak(BakRef); loadMapping(); @@ -927,9 +927,9 @@ void CGEEngine::switchMusic() { keyClick(); } if (_music) - loadMidi(_now); + _midiPlayer.loadMidi(_now); else - killMidi(); + _midiPlayer.killMidi(); } void CGEEngine::startCountDown() { @@ -1518,7 +1518,7 @@ void CGEEngine::runGame() { _sprite->step(_music); _snail_->addCom(kSnSeq, -1, _music, _sprite); if (!_music) - killMidi(); + _midiPlayer.killMidi(); if (INI_FILE::exist("MINI.SPR")) { _miniShp = new BitmapPtr[2]; @@ -1664,7 +1664,7 @@ bool CGEEngine::showTitle(const char *name) { _vga->copyPage(0, 2); _soundOk = 2; if (_music) - loadMidi(0); + _midiPlayer.loadMidi(0); } if (_mode < 2) { @@ -1742,7 +1742,7 @@ void CGEEngine::cge_main() { _horzLine->_flags._hide = true; if (_music && _soundOk) - loadMidi(0); + _midiPlayer.loadMidi(0); if (_startGameSlot != -1) { // Starting up a savegame from the launcher diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 67068a9673b..4d79dbeddc6 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -270,26 +270,10 @@ bool IoHand::exist(const char *name) { return f.exists(name); } -void sndInit() { - warning("STUB: SNDInit"); -} - -void sndDone() { - // FIXME: STUB: SNDDone -} - void sndSetVolume() { warning("STUB: SNDSetVolume"); } -void sndMidiStart(uint8 *MIDFile) { - warning("STUB: SNDMIDIStart"); -} - -void sndMidiStop() { - // FIXME: STUB: sndMIDIStop -} - DataCk *loadWave(XFile *file) { byte *data = (byte *)malloc(file->size()); file->read(data, file->size()); diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 44ccf47f949..0678971d0c8 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -64,25 +64,9 @@ extern uint16 _midiEndFlag; // ****************************************************** // * Driver Code * // ****************************************************** -// Init Digi Device -void sndInit(); - -// Close Digi Device -void sndDone(); - // Set Volume void sndSetVolume(); -// Start MIDI File -void sndMidiStart(uint8 *MIDFile); - -// Stop MIDI File -void sndMidiStop(); - -// Play MIDI File (to be called while interrupting) -// WARNING: Uses ALL registers! -void sndMidiPlay(); - } // End of namespace CGE #endif diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 2cb24df5ba8..aa42df57bf1 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -48,13 +48,11 @@ Sound::~Sound() { void Sound::close() { - killMidi(); - sndDone(); + _vm->_midiPlayer.killMidi(); } void Sound::open() { - sndInit(); play((*_fx)[30000], 8); } @@ -180,40 +178,6 @@ DataCk *Fx::operator [](int ref) { return _current; } - -static uint8 *midi = NULL; - - -void killMidi() { - sndMidiStop(); - if (midi) { - delete[] midi; - midi = NULL; - } -} - - -void loadMidi(int ref) { - static char fn[] = "00.MID"; - wtom(ref, fn, 10, 2); - if (INI_FILE::exist(fn)) { - killMidi(); - INI_FILE mid = fn; - if (mid._error == 0) { - uint16 siz = (uint16) mid.size(); - midi = new uint8[siz]; - if (midi) { - mid.read(midi, siz); - if (mid._error) - killMidi(); - else - sndMidiStart(midi); - } - } - } -} - - void *Patch(int pat) { void *p = NULL; static char fn[] = "PATCH000.SND"; @@ -234,4 +198,65 @@ void *Patch(int pat) { return p; } +MusicPlayer::MusicPlayer() { + MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB); + _driver = MidiDriver::createMidi(dev); + _driver->open(); + _midiParser = NULL; + _data = NULL; +} + +MusicPlayer::~MusicPlayer() { + killMidi(); + _driver->close(); + delete _driver; +} + +void MusicPlayer::killMidi() { + if (_midiParser) { + // Stop MIDI playback + _midiParser->unloadMusic(); + _driver->setTimerCallback(NULL, NULL); + _driver->close(); + delete _midiParser; + delete _data; + + // Reset playback objects + _data = NULL; + _midiParser = NULL; + } +} + +void MusicPlayer::loadMidi(int ref) { + // Work out the filename and check the given MIDI file exists + Common::String filename = Common::String::format("%.2d.MID", ref); + if (!INI_FILE::exist(filename.c_str())) + return; + + // Stop any currently playing MIDI file + killMidi(); + + // Read in the data for the file + INI_FILE mid(filename.c_str()); + _dataSize = mid.size(); + _data = (byte *)malloc(_dataSize); + mid.read(_data, _dataSize); + + // Start playing the music + sndMidiStart(); +} + +void MusicPlayer::sndMidiStart() { + _midiParser = MidiParser::createParser_SMF(); + + if (_midiParser->loadMusic(_data, _dataSize)) { + _midiParser->setTrack(0); + _midiParser->setMidiDriver(_driver); + _midiParser->setTimerRate(_driver->getBaseTempo()); + + _midiParser->property(MidiParser::mpCenterPitchWheelOnUnload, 1); + _driver->setTimerCallback(_midiParser, MidiParser::timerCallback); + } +} + } // End of namespace CGE diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 67b16fc888b..9f7d20957e0 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -30,14 +30,19 @@ #include "cge/wav.h" #include "cge/snddrv.h" -#include "cge/cge.h" #include "audio/audiostream.h" #include "audio/decoders/wave.h" #include "audio/fmopl.h" +#include "audio/mididrv.h" +#include "audio/midiparser.h" +#include "audio/midiplayer.h" #include "audio/mixer.h" +#include "common/memstream.h" namespace CGE { +class CGEEngine; + class Sound { public: SmpInfo _smpinf; @@ -74,8 +79,25 @@ public: DataCk *operator[](int ref); }; -void loadMidi(int ref); -void killMidi(); +class MusicPlayer { +private: + MidiDriver *_driver; + MidiParser *_midiParser; + byte *_data; + int _dataSize; + + // Start MIDI File + void sndMidiStart(); + + // Stop MIDI File + void sndMidiStop(); +public: + MusicPlayer(); + ~MusicPlayer(); + + void loadMidi(int ref); + void killMidi(); +}; } // End of namespace CGE From 91fdecbf68cf9eb1bd1f4105cefd1fa20351d31e Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 12 Aug 2011 23:10:30 +1000 Subject: [PATCH 204/276] CGE: Properly implemented MIDI music playback --- engines/cge/sound.cpp | 78 ++++++++++++++++++++++++++++++------------- engines/cge/sound.h | 8 +++-- 2 files changed, 60 insertions(+), 26 deletions(-) diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index aa42df57bf1..8e60d851a46 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -31,6 +31,7 @@ #include "cge/cfile.h" #include "cge/vol.h" #include "cge/cge_main.h" +#include "common/config-manager.h" #include "common/memstream.h" #include "audio/decoders/raw.h" @@ -199,31 +200,36 @@ void *Patch(int pat) { } MusicPlayer::MusicPlayer() { - MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB); - _driver = MidiDriver::createMidi(dev); - _driver->open(); - _midiParser = NULL; _data = NULL; + _isGM = false; + + MidiPlayer::createDriver(); + + int ret = _driver->open(); + if (ret == 0) { + if (_nativeMT32) + _driver->sendMT32Reset(); + else + _driver->sendGMReset(); + + // TODO: Load cmf.ins with the instrument table. It seems that an + // interface for such an operation is supported for AdLib. Maybe for + // this card, setting instruments is necessary. + + _driver->setTimerCallback(this, &timerCallback); + } } MusicPlayer::~MusicPlayer() { killMidi(); - _driver->close(); - delete _driver; } void MusicPlayer::killMidi() { - if (_midiParser) { - // Stop MIDI playback - _midiParser->unloadMusic(); - _driver->setTimerCallback(NULL, NULL); - _driver->close(); - delete _midiParser; - delete _data; + Audio::MidiPlayer::stop(); - // Reset playback objects + if (_data != NULL) { + delete _data; _data = NULL; - _midiParser = NULL; } } @@ -247,16 +253,42 @@ void MusicPlayer::loadMidi(int ref) { } void MusicPlayer::sndMidiStart() { - _midiParser = MidiParser::createParser_SMF(); + _isGM = true; - if (_midiParser->loadMusic(_data, _dataSize)) { - _midiParser->setTrack(0); - _midiParser->setMidiDriver(_driver); - _midiParser->setTimerRate(_driver->getBaseTempo()); + MidiParser *parser = MidiParser::createParser_SMF(); + if (parser->loadMusic(_data, _dataSize)) { + parser->setTrack(0); + parser->setMidiDriver(this); + parser->setTimerRate(_driver->getBaseTempo()); + parser->property(MidiParser::mpCenterPitchWheelOnUnload, 1); - _midiParser->property(MidiParser::mpCenterPitchWheelOnUnload, 1); - _driver->setTimerCallback(_midiParser, MidiParser::timerCallback); - } + _parser = parser; + + syncVolume(); + + _isPlaying = true; + } +} + +void MusicPlayer::send(uint32 b) { + if ((b & 0xF0) == 0xC0 && !_isGM && !_nativeMT32) { + b = (b & 0xFFFF00FF) | MidiDriver::_mt32ToGm[(b >> 8) & 0xFF] << 8; + } + + Audio::MidiPlayer::send(b); +} + +void MusicPlayer::sendToChannel(byte channel, uint32 b) { + if (!_channelsTable[channel]) { + _channelsTable[channel] = (channel == 9) ? _driver->getPercussionChannel() : _driver->allocateChannel(); + // If a new channel is allocated during the playback, make sure + // its volume is correctly initialized. + if (_channelsTable[channel]) + _channelsTable[channel]->volume(_channelsVolume[channel] * _masterVolume / 255); + } + + if (_channelsTable[channel]) + _channelsTable[channel]->send(b); } } // End of namespace CGE diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 9f7d20957e0..33c4e95d35e 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -79,12 +79,11 @@ public: DataCk *operator[](int ref); }; -class MusicPlayer { +class MusicPlayer: public Audio::MidiPlayer { private: - MidiDriver *_driver; - MidiParser *_midiParser; byte *_data; int _dataSize; + bool _isGM; // Start MIDI File void sndMidiStart(); @@ -97,6 +96,9 @@ public: void loadMidi(int ref); void killMidi(); + + virtual void send(uint32 b); + virtual void sendToChannel(byte channel, uint32 b); }; } // End of namespace CGE From 6af5fffd3607d5ffcbb26a7a18316949b7e1ddb8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 12 Aug 2011 19:11:17 +0200 Subject: [PATCH 205/276] CGE: Cleanup: remove useless classes --- engines/cge/cge_main.h | 1 - engines/cge/general.cpp | 1 - engines/cge/sound.h | 18 ++++- engines/cge/walk.h | 1 - engines/cge/wav.h | 144 ---------------------------------------- 5 files changed, 17 insertions(+), 148 deletions(-) delete mode 100644 engines/cge/wav.h diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 293943d358f..1c85816c3e1 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -28,7 +28,6 @@ #ifndef __CGE_CGE__ #define __CGE_CGE__ -#include "cge/wav.h" #include "cge/vga13h.h" #include "cge/events.h" #include "cge/sound.h" diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 4d79dbeddc6..ddfb982d584 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -28,7 +28,6 @@ #include "cge/cge.h" #include "cge/general.h" #include "cge/snddrv.h" -#include "cge/wav.h" namespace CGE { diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 33c4e95d35e..01b11487d08 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -28,7 +28,7 @@ #ifndef __CGE_SOUND__ #define __CGE_SOUND__ -#include "cge/wav.h" +#include "cge/general.h" #include "cge/snddrv.h" #include "audio/audiostream.h" #include "audio/decoders/wave.h" @@ -43,6 +43,22 @@ namespace CGE { class CGEEngine; +class DataCk { + byte *_buf; + int _ckSize; +public: + DataCk(byte *buf, int size); + ~DataCk(); + inline const byte *addr() { + return _buf; + } + inline int size() { + return _ckSize; + } +}; + +DataCk *loadWave(XFile *file); + class Sound { public: SmpInfo _smpinf; diff --git a/engines/cge/walk.h b/engines/cge/walk.h index 8327c901b6f..c1d387f0b57 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -28,7 +28,6 @@ #ifndef __CGE_WALK__ #define __CGE_WALK__ -#include "cge/wav.h" #include "cge/vga13h.h" #include "cge/events.h" diff --git a/engines/cge/wav.h b/engines/cge/wav.h deleted file mode 100644 index 824f40f96fc..00000000000 --- a/engines/cge/wav.h +++ /dev/null @@ -1,144 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __CGE_WAV__ -#define __CGE_WAV__ - -#include "cge/general.h" - -namespace CGE { - -#define WAVE_FORMAT_PCM 0x0001 -#define IBM_FORMAT_MULAW 0x0101 -#define IBM_FORMAT_ALAW 0x0102 -#define IBM_FORMAT_ADPCM 0x0103 - -typedef char FourCC[4]; // Four-character code - -class ChunkId { // Chunk type identifier - union { - FourCC _text; - uint32 _id; - }; -protected: - static XFile *ckFile; -public: - ChunkId(FourCC text) { - memcpy(_text, text, sizeof(_text)); - } - ChunkId(uint32 d) { - _id = d; - } - ChunkId(XFile *xf) { - (ckFile = xf)->read(_text, sizeof(_text)); - } - bool operator !=(ChunkId &X) { - return _id != X._id; - } - bool operator ==(ChunkId &X) { - return _id == X._id; - } - const char *name(); -}; - - -class CkHea : public ChunkId { -protected: - uint32 _ckSize; // Chunk size field (size of ckData) -public: - CkHea(XFile *xf) : ChunkId(xf) { - XRead(xf, &_ckSize); - } - CkHea(char id[]) : ChunkId(id), _ckSize(0) { } - void skip(); - uint32 size() { - return _ckSize; - } -}; - - -class FmtCk : public CkHea { - struct Wav { - uint16 _wFormatTag; // Format category - uint16 _wChannels; // Number of channels - uint32 _dwSamplesPerSec; // Sampling rate - uint32 _dwAvgBytesPerSec; // For buffer estimation - uint16 _wBlockAlign; // Data block size - } _wav; - - union { - struct { - uint16 _wBitsPerSample; // Sample size - } _pcm; - }; -public: - FmtCk(CkHea &hea); - inline uint16 channels() { - return _wav._wChannels; - } - inline uint32 smplRate() { - return _wav._dwSamplesPerSec; - } - inline uint32 byteRate() { - return _wav._dwAvgBytesPerSec; - } - inline uint16 blckSize() { - return _wav._wBlockAlign; - } - inline uint16 smplSize() { - return _pcm._wBitsPerSample; - } -}; - - -class DataCk { - bool _ef; - byte *_buf; - int _ckSize; -public: - DataCk(byte *buf, int size); - ~DataCk(); - inline const byte *addr() { - return _buf; - } - inline int size() { - return _ckSize; - } -}; - - -extern ChunkId _riff; -extern ChunkId _wave; -extern ChunkId _fmt; -extern ChunkId _data; - - -DataCk *loadWave(XFile *file); - -} // End of namespace CGE - -#endif From 161a39e9fe0bfdbb1d96a6bb4c88b83d3f073ad0 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 13 Aug 2011 11:04:10 +1000 Subject: [PATCH 206/276] CGE: Got rid of stub warnings for things that don't need to be implemented in ScummVM --- engines/cge/vga13h.cpp | 137 ++--------------------------------------- 1 file changed, 5 insertions(+), 132 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 7c11653c4e5..51be2ed1e8f 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -100,92 +100,13 @@ static void Video() { uint16 *SaveScreen() { - /* - uint16 cxy, cur, siz, * scr = NULL, * sav; - - // horizontal size of text mode screen - asm mov ah,0x0F // get current video mode - Video(); // BIOS video service - asm xchg ah,al // answer in ah - asm push ax // preserve width - - // vertical size of text mode screen - asm mov dl,24 // last row on std screen - asm xor bx,bx // valid request in BH - asm mov ax,0x1130 // get EGA's last row # - Video(); // BIOS video service - asm inc dl // # of rows = last+1 - - // compute screen size in words - asm pop ax // restore width - asm mul dl // width * height - - siz = _AX; - - asm mov ax,0x40 // system data segment - asm mov es,ax - asm mov ax,0B000H // Mono - asm cmp byte ptr es:[0x49],0x07 - asm je sto - asm mov ax,0B800H // Color - sto: // store screen address - asm mov word ptr scr+2,ax - - _AH = 0x0F; Video(); // active page - - // take cursor shape - _AH = 0x03; Video(); // get cursor size - cur = _CX; - - // take cursor position - _DH = 0; - _AH = 0x03; Video(); // get cursor - cxy = _DX; - - sav = farnew(uint16, siz+3); // +3 extra uint16s for size and cursor - if (sav) - { - sav[0] = siz; - sav[1] = cur; - sav[2] = cxy; - memcpy(sav+3, scr, siz * 2); - } - return sav; - */ - warning("STUB: SaveScreen"); + // In ScummVM, we don't need to worry about saving the original screen mode return 0; } void RestoreScreen(uint16 * &sav) { - /* - uint16 * scr = NULL; - - asm mov ax,0x40 // system data segment - asm mov es,ax - asm mov ax,0B000H // Mono - asm cmp byte ptr es:[0x49],0x07 - asm je sto - asm mov ax,0B800H // Color - sto: // store screen address - asm mov word ptr scr+2,ax - - memcpy(scr, sav+3, sav[0] * 2); - - _AH = 0x0F; Video(); // active page - - // set cursor shape - _CX = sav[1]; - _AH = 0x01; Video(); // set cursor size - - // set cursor position - _DX = sav[2]; - _AH = 0x02; Video(); // set cursor - - free(sav); - sav = NULL; - */ - warning("STUB: RestoreScreen"); + // In ScummVM, we don't need to restore the original text screen when the game exits } @@ -830,7 +751,7 @@ Vga::Vga(int mode) for (int i = 10; i < 20; i++) { char *text = _text->getText(i); if (text) { - debugN("%s\n", text); + debugN(1, "%s\n", text); std = false; } } @@ -879,17 +800,7 @@ Vga::~Vga() { void Vga::setStatAdr() { - /* - asm mov dx,VGAMIr_ - asm in al,dx - asm test al,1 // CGA addressing mode flag - asm mov ax,VGAST1_ // CGA addressing - asm jnz set_mode_adr - asm xor al,0x60 // MDA addressing - set_mode_adr: - StatAdr = _AX; - */ - warning("STUB: VGA::setStatADR"); + // No implementation needed for ScummVM } @@ -902,45 +813,7 @@ void Vga::waitVR(bool on) { void Vga::setup(VgaRegBlk *vrb) { - /* - waitVR(); // *--LOOK!--* resets VGAATR logic - asm cld - asm mov si, vrb // take address of parameter table - asm mov dh,0x03 // higher byte of I/O address is always 3 - - s: - asm lodsw // take lower byte of I/O address and index - asm or ah,ah // 0 = end of table - asm jz xit // no more: exit - asm or al,al // indexed register? - asm js single // 7th bit set means single register - asm mov dl,ah // complete I/O address - asm out dx,al // put index into control register - asm inc dx // data register is next to control - asm in al,dx // take old data - - write: - asm mov cl,al // preserve old data - asm lodsw // take 2 masks from table - asm xor al,0xFF // invert mask bits - asm and al,cl // clear bits with "clr" mask - asm or al,ah // set bits with "set" mask - asm cmp dl,0xC1 // special case? - asm jne std2 // no: standard job, otherwise... - asm dec dx // data out reg shares address with index - std2: - asm out dx,al // write new value to register - asm jmp s - - single: // read address in al, write address in ah - asm mov dl,al // complete I/O read address - asm in al,dx // take old data - asm mov dl,ah // complete I/O write address - asm jmp write // continue standard routine - - xit: - */ - warning("STUB: VGA::setup"); + // No direct VGA setup required, since ScummVM provides it's own graphics interface } From ef7a17a64a9d3781108ccdf2c7338b02bf3b3aa6 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 13 Aug 2011 16:44:48 +1000 Subject: [PATCH 207/276] CGE: Fix for HLINE not being available for demo The HorizLine class is really only used for on-screen debugging information anyway, so it's not a problem. --- engines/cge/cge.cpp | 6 +++++- engines/cge/cge.h | 1 + engines/cge/cge_main.cpp | 18 +++++++++++------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index cfd941017e4..936aeea75a4 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -131,7 +131,7 @@ void CGEEngine::setup() { _pocLight = new PocLight(this); for (int i = 0; i < kPocketNX; i++) _pocket[i] = NULL; - _horzLine = new HorizLine(this); + _horzLine = isDemo() ? NULL : new HorizLine(this); _infoLine = new InfoLine(this, kInfoW); _cavLight = new CavLight(this); _debugLine = new InfoLine(this, kScrWidth); @@ -247,4 +247,8 @@ bool CGEEngine::canSaveGameStateCurrently() { return (_startupMode == 0) && _mouse->_active; } +bool CGEEngine::isDemo() const { + return _gameDescription->flags & ADGF_DEMO; +} + } // End of namespace CGE diff --git a/engines/cge/cge.h b/engines/cge/cge.h index bd347c6e269..8aff3334a06 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -104,6 +104,7 @@ public: virtual bool hasFeature(EngineFeature f) const; virtual bool canLoadGameStateCurrently(); virtual bool canSaveGameStateCurrently(); + bool isDemo() const; virtual Common::Error loadGameState(int slot); virtual Common::Error saveGameState(int slot, const Common::String &desc); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 1dd6e496501..24cdaf5e921 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -651,7 +651,7 @@ void CGEEngine::caveDown() { debugC(1, kCGEDebugEngine, "CGEEngine::caveDown()"); Sprite *spr; - if (!_horzLine->_flags._hide) + if (_horzLine && !_horzLine->_flags._hide) switchMapping(); for (spr = _vga->_showQ->first(); spr;) { @@ -858,7 +858,7 @@ void System::touch(uint16 mask, int x, int y) { if (cav && _snail->idle() && _hero->_tracePtr < 0) _vm->switchCave(cav); - if (!_horzLine->_flags._hide) { + if (_horzLine && !_horzLine->_flags._hide) { if (y >= kMapTop && y < kMapTop + kMapHig) { int8 x1, z1; XZ(x, y).split(x1, z1); @@ -958,9 +958,10 @@ void CGEEngine::takeName() { } void CGEEngine::switchMapping() { + assert(_horzLine); debugC(1, kCGEDebugEngine, "CGEEngine::switchMapping()"); - if (_horzLine->_flags._hide) { + if (_horzLine && _horzLine->_flags._hide) { int i; for (i = 0; i < kMapZCnt; i++) { int j; @@ -1559,9 +1560,11 @@ void CGEEngine::runGame() { _debugLine->_z = 126; _vga->_showQ->insert(_debugLine); - _horzLine->_y = kMapTop - (kMapTop > 0); - _horzLine->_z = 126; - _vga->_showQ->insert(_horzLine); + if (_horzLine) { + _horzLine->_y = kMapTop - (kMapTop > 0); + _horzLine->_z = 126; + _vga->_showQ->insert(_horzLine); + } _mouse->_busy = _vga->_spareQ->locate(kBusyRef); if (_mouse->_busy) @@ -1739,7 +1742,8 @@ void CGEEngine::cge_main() { _mode = 2; _debugLine->_flags._hide = true; - _horzLine->_flags._hide = true; + if (_horzLine) + _horzLine->_flags._hide = true; if (_music && _soundOk) _midiPlayer.loadMidi(0); From 58229750ccf6ede03332aec6b8c888fdca2917a0 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 13 Aug 2011 09:16:15 +0200 Subject: [PATCH 208/276] CGE: silent valgrind warnings --- engines/cge/bitmap.cpp | 2 +- engines/cge/sound.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 60b6cc90fac..df68491bd5e 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -165,7 +165,7 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { _h = bmp._h; _m = NULL; _map = 0; - free(_v); + delete[] _v; if (v0 == NULL) _v = NULL; else { diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 8e60d851a46..a3895958f01 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -228,7 +228,7 @@ void MusicPlayer::killMidi() { Audio::MidiPlayer::stop(); if (_data != NULL) { - delete _data; + free(_data); _data = NULL; } } From b02e34cade624362bee157dab364094c1710e548 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 13 Aug 2011 09:33:39 +0200 Subject: [PATCH 209/276] CGE: Implement sayTime() --- engines/cge/snail.cpp | 2 +- engines/cge/text.cpp | 16 ++++++---------- engines/cge/text.h | 4 +--- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 2d4c28c0abf..6a5556ca58c 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -995,7 +995,7 @@ void Snail::runCom() { if (spr && _talkEnable) { if (spr == _hero && spr->seqTest(-1)) spr->step(kSeqHTalk); - sayTime(spr); + _text->sayTime(spr); } break; case kSnCave: diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 699bd5bcc16..0e77bb89553 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -234,16 +234,12 @@ void CGEEngine::inf(const char *text) { } } -void sayTime(Sprite *spr) { - /* - static char t[] = "00:00"; - struct time ti; - gettime(&ti); - wtom(ti.ti_hour, t+0, 10, 2); - wtom(ti.ti_min, t+3, 10, 2); - Say((*t == '0') ? (t+1) : t, spr); - */ - warning("STUB: sayTime"); +void Text::sayTime(Sprite *spr) { + TimeDate curTime; + char t[6]; + _vm->_system->getTimeAndDate(curTime); + sprintf(t, "%d:%02d", curTime.tm_hour, curTime.tm_min); + say(t, spr); } void killText() { diff --git a/engines/cge/text.h b/engines/cge/text.h index bb905ac655b..d6845f4361f 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -60,6 +60,7 @@ public: void preload(int from = 1, int upto = 0x7FFF); char *getText(int ref); void say(const char *text, Sprite *spr); + void sayTime(Sprite *spr); private: CGEEngine *_vm; }; @@ -67,9 +68,6 @@ private: extern Talk *_talk; extern Text *_text; -void say(const char *text, Sprite *spr); -void sayTime(Sprite *spr); -void inf(const char *text); void killText(); } // End of namespace CGE From 177da650dde785abbee7ed446e71115839082517 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 13 Aug 2011 18:06:09 +1000 Subject: [PATCH 210/276] CGE: Fix loading of vol.cat file to be endian safe --- engines/cge/btfile.cpp | 41 +++++++++++++++++++++++++++++++++++------ engines/cge/btfile.h | 16 ++++++++-------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 1f987340b77..7ecfa94e9ba 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -31,6 +31,7 @@ #include "cge/cge.h" #include "common/debug.h" #include "common/debug-channels.h" +#include "common/memstream.h" namespace CGE { @@ -61,8 +62,8 @@ void BtFile::putPage(int lev, bool hard) { debugC(1, kCGEDebugFile, "BtFile::putPage(%d, %s)", lev, hard ? "true" : "false"); if (hard || _buff[lev]._updt) { - seek(_buff[lev]._pgNo * sizeof(BtPage)); - write((uint8 *) _buff[lev]._page, sizeof(BtPage)); + seek(_buff[lev]._pgNo * kBtSize); + write((uint8 *) _buff[lev]._page, kBtSize); _buff[lev]._updt = false; } } @@ -72,17 +73,25 @@ BtPage *BtFile::getPage(int lev, uint16 pgn) { debugC(1, kCGEDebugFile, "BtFile::getPage(%d, %d)", lev, pgn); if (_buff[lev]._pgNo != pgn) { - int32 pos = pgn * sizeof(BtPage); + int32 pos = pgn * kBtSize; putPage(lev, false); _buff[lev]._pgNo = pgn; if (size() > pos) { - seek((uint32) pgn * sizeof(BtPage)); - read((uint8 *) _buff[lev]._page, sizeof(BtPage)); + seek((uint32) pgn * kBtSize); + + // Read in the page + byte buffer[kBtSize]; + int bytesRead = read(buffer, kBtSize); + + // Unpack it into the page structure + Common::MemoryReadStream stream(buffer, bytesRead, DisposeAfterUse::NO); + _buff[lev]._page->read(stream); + _buff[lev]._updt = false; } else { + memset(&_buff[lev]._page, 0, kBtSize); _buff[lev]._page->_hea._count = 0; _buff[lev]._page->_hea._down = kBtValNone; - memset(_buff[lev]._page->_data, '\0', sizeof(_buff[lev]._page->_data)); _buff[lev]._updt = true; } _buff[lev]._indx = -1; @@ -152,4 +161,24 @@ void BtFile::make(BtKeypack *keypack, uint16 count) { } } +void BtPage::read(Common::ReadStream &s) { + _hea._count = s.readUint16LE(); + _hea._down = s.readUint16LE(); + + if (_hea._down == kBtValNone) { + // Leaf list + for (int i = 0; i < kBtLeafCount; ++i) { + s.read(_lea[i]._key, kBtKeySize); + _lea[i]._mark = s.readUint32LE(); + _lea[i]._size = s.readUint16LE(); + } + } else { + // Root index + for (int i = 0; i < kBtInnerCount; ++i) { + s.read(_inn[i]._key, kBtKeySize); + _inn[i]._down = s.readUint16LE(); + } + } +} + } // End of namespace CGE diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 6b7155d43dc..26b008bea6f 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -29,18 +29,19 @@ #define __CGE_BTFILE__ #include "cge/general.h" +#include "common/stream.h" namespace CGE { #define kBtSize 1024 #define kBtKeySize 13 #define kBtLevel 2 +#define kBtInnerCount ((kBtSize - 4 /*sizeof(Hea) */) / (kBtKeySize + 2 /*sizeof(Inner) */)) +#define kBtLeafCount ((kBtSize - 4 /*sizeof(Hea) */) / (kBtKeySize + 4 + 2 /*sizeof(BtKeypack) */)) #define kBtValNone 0xFFFF #define kBtValRoot 0 -#include "common/pack-start.h" // START STRUCT PACKING - struct BtKeypack { char _key[kBtKeySize]; uint32 _mark; @@ -61,17 +62,16 @@ struct BtPage { Hea _hea; union { // dummy filler to make proper size of union - uint8 _data[kBtSize - sizeof(Hea)]; + uint8 _data[kBtSize - 4 /*sizeof(Hea) */]; // inner version of data: key + word-sized page link - Inner _inn[(kBtSize - sizeof(Hea)) / sizeof(Inner)]; + Inner _inn[kBtInnerCount]; // leaf version of data: key + all user data - BtKeypack _lea[(kBtSize - sizeof(Hea)) / sizeof(BtKeypack)]; + BtKeypack _lea[kBtLeafCount]; }; + + void read(Common::ReadStream &s); }; -#include "common/pack-end.h" // END STRUCT PACKING - - class BtFile : public IoHand { struct { BtPage *_page; From 1d3f1830c890f2f4f2fbb8fcf4db90dfe1bacdde Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 13 Aug 2011 10:09:45 +0200 Subject: [PATCH 211/276] CGE: Remove useless functions related to data file creation (unused) --- engines/cge/btfile.cpp | 26 -------------------------- engines/cge/btfile.h | 1 - engines/cge/general.cpp | 16 ---------------- engines/cge/general.h | 8 -------- engines/cge/vol.cpp | 17 +---------------- engines/cge/vol.h | 11 +---------- 6 files changed, 2 insertions(+), 77 deletions(-) diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 7ecfa94e9ba..053f264b351 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -135,32 +135,6 @@ int keycomp(const void *k1, const void *k2) { return scumm_strnicmp((const char *) k1, (const char*) k2, kBtKeySize); } - -void BtFile::make(BtKeypack *keypack, uint16 count) { - debugC(1, kCGEDebugFile, "BtFile::make(keypack, %d)", count); - -#if kBtLevel != 2 -#error This tiny BTREE implementation works with exactly 2 levels! -#endif - _fqsort(keypack, count, sizeof(*keypack), keycomp); - uint16 n = 0; - BtPage *Root = getPage(0, n++); - BtPage *Leaf = getPage(1, n); - Root->_hea._down = n; - putPage(0, true); - while (count--) { - if (Leaf->_hea._count >= ArrayCount(Leaf->_lea)) { - putPage(1, true); // save filled page - Leaf = getPage(1, ++n); // take empty page - memcpy(Root->_inn[Root->_hea._count]._key, keypack->_key, kBtKeySize); - Root->_inn[Root->_hea._count++]._down = n; - _buff[0]._updt = true; - } - Leaf->_lea[Leaf->_hea._count++] = *(keypack++); - _buff[1]._updt = true; - } -} - void BtPage::read(Common::ReadStream &s) { _hea._count = s.readUint16LE(); _hea._down = s.readUint16LE(); diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 26b008bea6f..7cfdc263e74 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -87,7 +87,6 @@ public: virtual ~BtFile(); BtKeypack *find(const char *key); BtKeypack *next(); - void make(BtKeypack *keypack, uint16 count); }; } // End of namespace CGE diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index ddfb982d584..6d7b1daf887 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -92,10 +92,6 @@ Dac _stdPal[] = {// R G B { 255, 255, 255}, // 255 }; -void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)) { - warning("STUB: _fqsort"); -} - const char *progName(const char *ext) { static char buf[kMaxFile]; strcpy(buf, "CGE"); @@ -292,18 +288,6 @@ int takeEnum(const char **tab, const char *text) { return -1; } -long timer() { -/* - asm mov ax,0x40 - asm mov es,ax - asm mov cx,es:[0x6C] - asm mov dx,es:[0x6E] - return ((long) _DX << 16) | _CX; -*/ - warning("STUB: timer"); - return 0; -} - int newRandom(int range) { return ((CGEEngine *)g_engine)->_randomSource.getRandomNumber(range - 1); } diff --git a/engines/cge/general.h b/engines/cge/general.h index fe346061081..90cba269cd5 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -113,22 +113,14 @@ char *wtom(uint16 val, char *str, int radix, int len); char *dwtom(uint32 val, char *str, int radix, int len); int takeEnum(const char **tab, const char *text); uint16 chkSum(void *m, uint16 n); -long timer(); char *mergeExt(char *buf, const char *name, const char *ext); char *forceExt(char *buf, const char *name, const char *ext); // MISSING FUNCTIONS -void _fqsort(void *base, uint16 nelem, uint16 width, int (*fcmp)(const void *, const void *)); const char *progName(const char *ext = NULL); unsigned fastRand(); unsigned fastRand(unsigned s); uint16 rCrypt(void *buf, uint16 siz, uint16 seed); -uint16 atow(const char *a); -uint16 xtow(const char *x); -char *wtom(uint16 val, char *str, int radix, int len); -char *dwtom(uint32 val, char * str, int radix, int len); -int takeEnum(const char **tab, const char *text); -long timer(); int newRandom(int range); } // End of namespace CGE diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index b3cc49495ac..44cad5e8326 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -40,13 +40,7 @@ VFile *VFile::_recent = NULL; /*-----------------------------------------------------------------------*/ -Dat::Dat(): -#ifdef VOL_UPD - _file(DAT_NAME, UPD, CRP) -#else - _file(DAT_NAME, kModeRead, CRP) -#endif -{ +Dat::Dat(): _file(DAT_NAME, kModeRead, CRP) { debugC(1, kCGEDebugFile, "Dat::Dat()"); } @@ -56,12 +50,7 @@ void VFile::init() { debugC(1, kCGEDebugFile, "VFile::init()"); _dat = new Dat(); -#ifdef VOL_UPD - _cat = new BtFile(CAT_NAME, UPD, CRP); -#else _cat = new BtFile(CAT_NAME, kModeRead, CRP); -#endif - _recent = NULL; } @@ -82,10 +71,6 @@ VFile::VFile(const char *name, IOMode mode) _error = 1; _endMark = (_bufMark = _begMark = kp->_mark) + kp->_size; } -#ifdef VOL_UPD - else - Make(name); -#endif } diff --git a/engines/cge/vol.h b/engines/cge/vol.h index f64e7eec54e..f9d9382eacf 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -36,16 +36,9 @@ namespace CGE { #define CAT_NAME "VOL.CAT" #define DAT_NAME "VOL.DAT" -#define CRP XCrypt - +#define CRP XCrypt #define XMASK 0xA5 - -#ifdef VOL_UPD -#define VOLBASE IOHAND -#else #define VOLBASE CFile -#endif - class Dat { friend class VFile; @@ -58,7 +51,6 @@ public: bool read(long org, uint16 len, uint8 *buf); }; - class VFile : public IoBuf { private: static Dat *_dat; @@ -70,7 +62,6 @@ private: void readBuf(); void writeBuf() { } - void make(const char *fspec); public: VFile(const char *name, IOMode mode = kModeRead); ~VFile(); From 9a94a239b8b9099ebfb8b4061ca68a0a7b1174b7 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Wed, 17 Aug 2011 10:12:37 +0200 Subject: [PATCH 212/276] CGE: Fix gcc shadowed member warning. --- engines/cge/general.cpp | 4 ++-- engines/cge/sound.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 6d7b1daf887..112de730ec5 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -292,9 +292,9 @@ int newRandom(int range) { return ((CGEEngine *)g_engine)->_randomSource.getRandomNumber(range - 1); } -DataCk::DataCk(byte *buf, int size) { +DataCk::DataCk(byte *buf, int bufSize) { _buf = buf; - _ckSize = size; + _ckSize = bufSize; } DataCk::~DataCk() { diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 01b11487d08..e6bc2dedde2 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -47,7 +47,7 @@ class DataCk { byte *_buf; int _ckSize; public: - DataCk(byte *buf, int size); + DataCk(byte *buf, int bufSize); ~DataCk(); inline const byte *addr() { return _buf; From a9f002897ea344d8851d66a9a3fa27dd3d457fa7 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Wed, 17 Aug 2011 10:50:26 +0200 Subject: [PATCH 213/276] CGE: Preserve const in cast. --- engines/cge/snddrv.h | 2 +- engines/cge/sound.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 0678971d0c8..7af214365f9 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -45,7 +45,7 @@ namespace CGE { // sample info struct SmpInfo { - uint8 *_saddr; // address + const uint8 *_saddr; // address uint16 _slen; // length uint16 _span; // left/right pan (0-15) int _sflag; // flag diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index a3895958f01..8a199c7ee2f 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -61,7 +61,7 @@ void Sound::open() { void Sound::play(DataCk *wav, int pan, int cnt) { if (wav) { stop(); - _smpinf._saddr = (uint8 *) &*(wav->addr()); + _smpinf._saddr = &*(wav->addr()); _smpinf._slen = (uint16)wav->size(); _smpinf._span = pan; _smpinf._sflag = cnt; From 23689cac23fcbe205f28434ddbb4a686feda4dea Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Wed, 17 Aug 2011 10:55:49 +0200 Subject: [PATCH 214/276] CGE: Remove unused Rgb/Trgb/mkRgb. --- engines/cge/vga13h.cpp | 10 ---------- engines/cge/vga13h.h | 15 --------------- 2 files changed, 25 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 51be2ed1e8f..9b063f0c02d 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -118,16 +118,6 @@ Dac mkDac(uint8 r, uint8 g, uint8 b) { return x; } - -Rgb mkRgb(uint8 r, uint8 g, uint8 b) { - static Trgb x; - x._dac._r = r; - x._dac._g = g; - x._dac._b = b; - return x._rgb; -} - - Sprite *locate(int ref) { Sprite *spr = _vga->_showQ->locate(ref); return (spr) ? spr : _vga->_spareQ->locate(ref); diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index db75b48692d..d43e5900842 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -65,20 +65,6 @@ namespace CGE { #define SPR_EXT ".SPR" -struct Rgb { - uint16 _r : 2; - uint16 _R : 6; - uint16 _g : 2; - uint16 _G : 6; - uint16 _b : 2; - uint16 _B : 6; -}; - -typedef union { - Dac _dac; - Rgb _rgb; -} Trgb; - struct VgaRegBlk { uint8 _idx; uint8 _adr; @@ -299,7 +285,6 @@ public: Dac mkDac(uint8 r, uint8 g, uint8 b); -Rgb mkRgb(uint8 r, uint8 g, uint8 b); template From 85a0fa03ad72be9942decc84b87a6c91c71e5652 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Thu, 18 Aug 2011 00:33:54 +0200 Subject: [PATCH 215/276] CGE: Remove unused _intStackPtr. --- engines/cge/cge_main.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 24cdaf5e921..a154a3d141d 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -91,7 +91,6 @@ const char *savegameStr = "SCUMMVM_CGE"; static bool _finis = false; int _offUseCount; -uint16 *_intStackPtr = NULL; extern Dac _stdPal[58]; @@ -1730,9 +1729,6 @@ bool CGEEngine::showTitle(const char *name) { } void CGEEngine::cge_main() { - uint16 intStack[kStackSize / 2]; - _intStackPtr = intStack; - memset(_barriers, 0xFF, sizeof(_barriers)); if (!_mouse->_exist) From 40ea6d788bfabb9d692377fa0baf87b3e5824e0c Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 19 Aug 2011 07:25:58 +0200 Subject: [PATCH 216/276] CGE: Suppress some dead code --- engines/cge/sound.cpp | 20 -------------------- engines/cge/vga13h.cpp | 24 +----------------------- 2 files changed, 1 insertion(+), 43 deletions(-) diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 8a199c7ee2f..b22548c16d3 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -179,26 +179,6 @@ DataCk *Fx::operator [](int ref) { return _current; } -void *Patch(int pat) { - void *p = NULL; - static char fn[] = "PATCH000.SND"; - - wtom(pat, fn + 5, 10, 3); - INI_FILE snd = fn; - if (!snd._error) { - uint16 siz = (uint16) snd.size(); - p = (uint8 *) malloc(siz); - if (p) { - snd.read(p, siz); - if (snd._error) { - free(p); - p = NULL; - } - } - } - return p; -} - MusicPlayer::MusicPlayer() { _data = NULL; _isGM = false; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 9b063f0c02d..ad2415caafd 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -77,28 +77,6 @@ Seq *getConstantSeq(bool seqFlag) { extern "C" void SNDMIDIPlay(); -/* -static void Video() { - static uint16 SP_S; - - asm push bx - asm push bp - asm push si - asm push di - asm push es - asm xor bx,bx // video page #0 - SP_S = _SP; - asm int VIDEO - _SP = SP_S; - asm pop es - asm pop di - asm pop si - asm pop bp - asm pop bx -} -*/ - - uint16 *SaveScreen() { // In ScummVM, we don't need to worry about saving the original screen mode return 0; @@ -125,7 +103,7 @@ Sprite *locate(int ref) { Sprite::Sprite(CGEEngine *vm, BitmapPtr *shpP) : _x(0), _y(0), _z(0), _nearPtr(0), _takePtr(0), - _next(NULL), _prev(NULL), _seqPtr(NO_SEQ), _time(0), //Delay(0), + _next(NULL), _prev(NULL), _seqPtr(NO_SEQ), _time(0), _ext(NULL), _ref(-1), _cave(0), _vm(vm) { memset(_file, 0, sizeof(_file)); *((uint16 *)&_flags) = 0; From 0d730b85e3e05829ba5ce3fbcdbf2886a9a28a94 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 19 Aug 2011 19:49:05 +1000 Subject: [PATCH 217/276] CGE: Changed the Sprite bit-flags into a union, to fix savegame endian issues --- engines/cge/cge_main.cpp | 86 ++++++++++++++++++++-------------------- engines/cge/events.cpp | 10 ++--- engines/cge/game.cpp | 2 +- engines/cge/gettext.cpp | 4 +- engines/cge/mixer.cpp | 16 ++++---- engines/cge/snail.cpp | 52 ++++++++++++------------ engines/cge/talk.cpp | 4 +- engines/cge/text.cpp | 14 +++---- engines/cge/vga13h.cpp | 28 ++++++------- engines/cge/vga13h.h | 22 +++++----- engines/cge/vmenu.cpp | 12 +++--- engines/cge/walk.cpp | 14 +++---- 12 files changed, 134 insertions(+), 130 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index a154a3d141d..213ad7abec1 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -470,8 +470,8 @@ void CGEEngine::loadMapping() { } Square::Square(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { - _flags._kill = true; - _flags._bDel = false; + _flags.flags._kill = true; + _flags.flags._bDel = false; BitmapPtr *MB = new BitmapPtr[2]; MB[0] = new Bitmap("BRICK", true); @@ -528,7 +528,7 @@ void CGEEngine::quit() { { NULL, &CGEEngine::dummy } }; - if (_snail->idle() && !_hero->_flags._hide) { + if (_snail->idle() && !_hero->_flags.flags._hide) { if (Vmenu::_addr) { _snail_->addCom(kSnKill, -1, 0, Vmenu::_addr); resetQSwitch(); @@ -553,13 +553,13 @@ void CGEEngine::miniStep(int stp) { debugC(1, kCGEDebugEngine, "CGEEngine::miniStep(%d)", stp); if (stp < 0) - _miniCave->_flags._hide = true; + _miniCave->_flags.flags._hide = true; else { *_miniShp[0] = *_miniShpList[stp]; if (_fx->_current) &*(_fx->_current->addr()); - _miniCave->_flags._hide = false; + _miniCave->_flags.flags._hide = false; } } @@ -600,7 +600,7 @@ void CGEEngine::caveUp() { Sprite *n = spr->_next; if (spr->_cave == _now || spr->_cave == 0) if (spr->_ref != BakRef) { - if (spr->_flags._back) + if (spr->_flags.flags._back) spr->backShow(); else expandSprite(spr); @@ -618,7 +618,7 @@ void CGEEngine::caveUp() { // following 2 lines trims Hero's Z position! _hero->tick(); _hero->_time = 1; - _hero->_flags._hide = false; + _hero->_flags.flags._hide = false; } if (!_dark) @@ -650,7 +650,7 @@ void CGEEngine::caveDown() { debugC(1, kCGEDebugEngine, "CGEEngine::caveDown()"); Sprite *spr; - if (_horzLine && !_horzLine->_flags._hide) + if (_horzLine && !_horzLine->_flags.flags._hide) switchMapping(); for (spr = _vga->_showQ->first(); spr;) { @@ -823,7 +823,7 @@ void System::touch(uint16 mask, int x, int y) { _sprite->step(x - '0'); break; case F10 : - if (_snail->idle() && !_hero->_flags._hide) + if (_snail->idle() && !_hero->_flags.flags._hide) _vm->startCountDown(); break; } @@ -857,7 +857,7 @@ void System::touch(uint16 mask, int x, int y) { if (cav && _snail->idle() && _hero->_tracePtr < 0) _vm->switchCave(cav); - if (_horzLine && !_horzLine->_flags._hide) { + if (_horzLine && !_horzLine->_flags.flags._hide) { if (y >= kMapTop && y < kMapTop + kMapHig) { int8 x1, z1; XZ(x, y).split(x1, z1); @@ -960,7 +960,7 @@ void CGEEngine::switchMapping() { assert(_horzLine); debugC(1, kCGEDebugEngine, "CGEEngine::switchMapping()"); - if (_horzLine && _horzLine->_flags._hide) { + if (_horzLine && _horzLine->_flags.flags._hide) { int i; for (i = 0; i < kMapZCnt; i++) { int j; @@ -975,14 +975,14 @@ void CGEEngine::switchMapping() { if (s->_w == kMapGridX && s->_h == kMapGridZ) _snail_->addCom(kSnKill, -1, 0, s); } - _horzLine->_flags._hide = !_horzLine->_flags._hide; + _horzLine->_flags.flags._hide = !_horzLine->_flags.flags._hide; } void CGEEngine::killSprite() { debugC(1, kCGEDebugEngine, "CGEEngine::killSprite()"); - _sprite->_flags._kill = true; - _sprite->_flags._bDel = true; + _sprite->_flags.flags._kill = true; + _sprite->_flags.flags._bDel = true; _snail_->addCom(kSnKill, -1, 0, _sprite); _sprite = NULL; } @@ -1007,7 +1007,7 @@ void CGEEngine::pullSprite() { if (spr) { spr = spr->_next; if (spr) - ok = (!spr->_flags._slav); + ok = (!spr->_flags.flags._slav); } if (ok) { _vga->_showQ->insert(_vga->_showQ->remove(_sprite), spr); @@ -1058,7 +1058,7 @@ void CGEEngine::sayDebug() { char *spH = DebugText + 37; char *spF = DebugText + 41; - if (!_debugLine->_flags._hide) { + if (!_debugLine->_flags.flags._hide) { dwtom(_mouse->_x, absX, 10, 3); dwtom(_mouse->_y, absY, 10, 3); @@ -1083,7 +1083,7 @@ void CGEEngine::sayDebug() { void CGEEngine::switchDebug() { - _debugLine->_flags._hide = !_debugLine->_flags._hide; + _debugLine->_flags.flags._hide = !_debugLine->_flags.flags._hide; } @@ -1121,7 +1121,7 @@ void Sprite::touch(uint16 mask, int x, int y) { _vm->optionTouch(_ref % 10, mask); return; } - if (_flags._syst) + if (_flags.flags._syst) return; // cannot access system sprites if (_vm->_game) if (mask & kMouseLeftUp) { mask &= ~kMouseLeftUp; @@ -1130,7 +1130,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if ((mask & kMouseRightUp) && _snail->idle()) { Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_vm->_pocPtr] : NULL; if (ps) { - if (_flags._kept || _hero->distance(this) < kDistMax) { + if (_flags.flags._kept || _hero->distance(this) < kDistMax) { if (works(ps)) { _vm->feedSnail(ps, kTake); } else @@ -1139,18 +1139,18 @@ void Sprite::touch(uint16 mask, int x, int y) { } else _vm->tooFar(); } else { - if (_flags._kept) + if (_flags.flags._kept) mask |= kMouseLeftUp; else { if (_hero->distance(this) < kDistMax) { /// - if (_flags._port) { + if (_flags.flags._port) { if (_vm->findPocket(NULL) < 0) _vm->pocFul(); else { _snail->addCom(kSnReach, -1, -1, this); _snail->addCom(kSnKeep, -1, -1, this); - _flags._port = false; + _flags.flags._port = false; } } else { if (_takePtr != NO_PTR) { @@ -1168,7 +1168,7 @@ void Sprite::touch(uint16 mask, int x, int y) { } } if ((mask & kMouseLeftUp) && _snail->idle()) { - if (_flags._kept) { + if (_flags.flags._kept) { int n; for (n = 0; n < kPocketNX; n++) { if (_pocket[n] == this) { @@ -1319,11 +1319,11 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int _sprite->_ref = ref; _sprite->_cave = cav; _sprite->_z = pos; - _sprite->_flags._east = east; - _sprite->_flags._port = port; - _sprite->_flags._tran = tran; - _sprite->_flags._kill = true; - _sprite->_flags._bDel = true; + _sprite->_flags.flags._east = east; + _sprite->_flags.flags._port = port; + _sprite->_flags.flags._tran = tran; + _sprite->_flags.flags._kill = true; + _sprite->_flags.flags._bDel = true; // Extract the filename, without the extension strcpy(_sprite->_file, fname); @@ -1390,7 +1390,7 @@ void CGEEngine::loadScript(const char *fname) { _sprite = NULL; loadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); if (_sprite && BkG) - _sprite->_flags._back = true; + _sprite->_flags.flags._back = true; } if (! ok) error("Bad INI line %d [%s]", lcnt, fname); @@ -1452,7 +1452,7 @@ void CGEEngine::handleFrame() { void CGEEngine::tick() { for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (spr->_time) { - if (!spr->_flags._hide) { + if (!spr->_flags.flags._hide) { if (--spr->_time == 0) spr->tick(); } @@ -1483,9 +1483,9 @@ void CGEEngine::runGame() { _text->preload(100, 1000); loadHeroXY(); - _cavLight->_flags._tran = true; + _cavLight->_flags.flags._tran = true; _vga->_showQ->append(_cavLight); - _cavLight->_flags._hide = true; + _cavLight->_flags.flags._hide = true; const Seq pocSeq[] = { { 0, 0, 0, 0, 20 }, @@ -1500,7 +1500,7 @@ void CGEEngine::runGame() { Common::copy(pocSeq, pocSeq + 7, seq); _pocLight->setSeq(seq); - _pocLight->_flags._tran = true; + _pocLight->_flags.flags._tran = true; _pocLight->_time = 1; _pocLight->_z = 120; _vga->_showQ->append(_pocLight); @@ -1527,8 +1527,8 @@ void CGEEngine::runGame() { loadSprite("MINI", -1, 0, kMiniX, kMiniY); expandSprite(_miniCave = _sprite); // NULL is ok if (_miniCave) { - _miniCave->_flags._kill = false; - _miniCave->_flags._hide = true; + _miniCave->_flags.flags._kill = false; + _miniCave->_flags.flags._hide = true; _miniShp[0] = new Bitmap(*_miniCave->shp()); _miniShpList = _miniCave->setShapeList(_miniShp); postMiniStep(-1); @@ -1543,16 +1543,16 @@ void CGEEngine::runGame() { delete _shadow; if ((_shadow = _sprite) != NULL) { _shadow->_ref = 2; - _shadow->_flags._tran = true; - _shadow->_flags._kill = false; - _hero->_flags._shad = true; + _shadow->_flags.flags._tran = true; + _shadow->_flags.flags._kill = false; + _hero->_flags.flags._shad = true; _vga->_showQ->insert(_vga->_spareQ->remove(_shadow), _hero); } } } _infoLine->gotoxy(kInfoX, kInfoY); - _infoLine->_flags._tran = true; + _infoLine->_flags.flags._tran = true; _infoLine->update(NULL); _vga->_showQ->insert(_infoLine); @@ -1634,8 +1634,8 @@ bool CGEEngine::showTitle(const char *name) { bool userOk = false; Sprite D(this, LB); - D._flags._kill = true; - D._flags._bDel = true; + D._flags.flags._kill = true; + D._flags.flags._bDel = true; D.center(); D.show(2); @@ -1737,9 +1737,9 @@ void CGEEngine::cge_main() { if (!kSavegame0File::exist(kSavegame0Name)) _mode = 2; - _debugLine->_flags._hide = true; + _debugLine->_flags.flags._hide = true; if (_horzLine) - _horzLine->_flags._hide = true; + _horzLine->_flags.flags._hide = true; if (_music && _soundOk) _midiPlayer.loadMidi(0); diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 916de839ebb..7235bf19c1e 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -158,7 +158,7 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) _buttons = 0; _busy = NULL; _active = false; - _flags._kill = false; + _flags.flags._kill = false; const Seq ms[] = { { 0, 0, 0, 0, 1 }, @@ -301,9 +301,9 @@ void EventManager::handleEvents() { if (e._mask & kMouseLeftDown) { _mouse->_hold = e._spritePtr; if (_mouse->_hold) { - _mouse->_hold->_flags._hold = true; + _mouse->_hold->_flags.flags._hold = true; - if (_mouse->_hold->_flags._drag) { + if (_mouse->_hold->_flags.flags._drag) { _mouse->_hx = e._x - _mouse->_hold->_x; _mouse->_hy = e._y - _mouse->_hold->_y; } @@ -312,7 +312,7 @@ void EventManager::handleEvents() { if (e._mask & kMouseLeftUp) { if (_mouse->_hold) { - _mouse->_hold->_flags._hold = false; + _mouse->_hold->_flags.flags._hold = false; _mouse->_hold = NULL; } } @@ -325,7 +325,7 @@ void EventManager::handleEvents() { _eventQueueTail = (_eventQueueTail + 1) % kEventMax; } if (_mouse->_hold) { - if (_mouse->_hold->_flags._drag) + if (_mouse->_hold->_flags.flags._drag) _mouse->_hold->gotoxy(_mouse->_x - _mouse->_hx, _mouse->_y - _mouse->_hy); } } diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index e64e4af38a2..0b9c6e2a400 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -56,7 +56,7 @@ Fly::Fly(CGEEngine *vm, Bitmap **shpl) void Fly::tick() { step(); - if (!_flags._kept) { + if (!_flags.flags._kept) { if (newRandom(10) < 1) { _tx = newRandom(3) - 1; _ty = newRandom(3) - 1; diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index d96e494402a..34e8643668e 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -46,8 +46,8 @@ GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) _ts[1] = NULL; setShapeList(_ts); - _flags._bDel = true; - _flags._kill = true; + _flags.flags._bDel = true; + _flags.flags._kill = true; memcpy(_buff, text, _len); _buff[_len] = ' '; _buff[_len + 1] = '\0'; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index ba24f832c3e..513c6f683f5 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -45,9 +45,9 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _ _mb[1] = NULL; setShapeList(_mb); setName(_text->getText(kMixName)); - _flags._syst = true; - _flags._kill = true; - _flags._bDel = true; + _flags.flags._syst = true; + _flags.flags._kill = true; + _flags.flags._bDel = true; gotoxy(x, y); _z = kMixZ; @@ -73,13 +73,13 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _ spr->setSeq(seq); spr->gotoxy(x + 2 + 12 * i, y + 8); - spr->_flags._tran = true; - spr->_flags._kill = true; - spr->_flags._bDel = false; + spr->_flags.flags._tran = true; + spr->_flags.flags._kill = true; + spr->_flags.flags._bDel = false; spr->_z = kMixZ; _led[i] = spr; } - _led[ArrayCount(_led) - 1]->_flags._bDel = true; + _led[ArrayCount(_led) - 1]->_flags.flags._bDel = true; _vga->_showQ->insert(this); for (i = 0; i < ArrayCount(_led); i++) @@ -128,7 +128,7 @@ void Mixer::tick() { int y = _mouse->_y; if (spriteAt(x, y) == this) { _fall = kMixFall; - if (_flags._hold) + if (_flags.flags._hold) touch(kMouseLeftUp, x - _x, y - _y); } else { if (_fall) diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 6a5556ca58c..750d44f45c3 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -493,7 +493,7 @@ void CGEEngine::snZTrim(Sprite *spr) { if (spr) if (spr->active()) { Sprite *s; - s = (spr->_flags._shad) ? spr->_prev : NULL; + s = (spr->_flags.flags._shad) ? spr->_prev : NULL; _vga->_showQ->insert(_vga->_showQ->remove(spr)); if (s) { s->_z = spr->_z; @@ -506,9 +506,9 @@ void CGEEngine::snHide(Sprite *spr, int val) { debugC(1, kCGEDebugEngine, "CGEEngine::snHide(spr, %d)", val); if (spr) { - spr->_flags._hide = (val >= 0) ? (val != 0) : (!spr->_flags._hide); - if (spr->_flags._shad) - spr->_prev->_flags._hide = spr->_flags._hide; + spr->_flags.flags._hide = (val >= 0) ? (val != 0) : (!spr->_flags.flags._hide); + if (spr->_flags.flags._shad) + spr->_prev->_flags.flags._hide = spr->_flags.flags._hide; } } @@ -554,18 +554,18 @@ void CGEEngine::snSend(Sprite *spr, int val) { spr->_cave = val; if (val1 != was1) { if (was1) { - if (spr->_flags._kept) { + if (spr->_flags.flags._kept) { int n = findPocket(spr); if (n >= 0) _pocket[n] = NULL; } hide1(spr); contractSprite(spr); - spr->_flags._slav = false; + spr->_flags.flags._slav = false; } else { if (spr->_ref % 1000 == 0) Bitmap::_pal = Vga::_sysPal; - if (spr->_flags._back) + if (spr->_flags.flags._back) spr->backShow(true); else expandSprite(spr); @@ -589,12 +589,12 @@ void CGEEngine::snSwap(Sprite *spr, int xref) { swap(spr->_x, xspr->_x); swap(spr->_y, xspr->_y); swap(spr->_z, xspr->_z); - if (spr->_flags._kept) { + if (spr->_flags.flags._kept) { int n = findPocket(spr); if (n >= 0) _pocket[n] = xspr; - xspr->_flags._kept = true; - xspr->_flags._port = false; + xspr->_flags.flags._kept = true; + xspr->_flags.flags._port = false; } if (xwas1 != was1) { if (was1) { @@ -617,14 +617,14 @@ void CGEEngine::snCover(Sprite *spr, int xref) { Sprite *xspr = locate(xref); if (spr && xspr) { - spr->_flags._hide = true; + spr->_flags.flags._hide = true; xspr->_z = spr->_z; xspr->_cave = spr->_cave; xspr->gotoxy(spr->_x, spr->_y); expandSprite(xspr); - if ((xspr->_flags._shad = spr->_flags._shad) == 1) { + if ((xspr->_flags.flags._shad = spr->_flags.flags._shad) == 1) { _vga->_showQ->insert(_vga->_showQ->remove(spr->_prev), xspr); - spr->_flags._shad = false; + spr->_flags.flags._shad = false; } feedSnail(xspr, kNear); } @@ -635,12 +635,12 @@ void CGEEngine::snUncover(Sprite *spr, Sprite *xspr) { debugC(1, kCGEDebugEngine, "CGEEngine::snUncover(spr, xspr)"); if (spr && xspr) { - spr->_flags._hide = false; + spr->_flags.flags._hide = false; spr->_cave = xspr->_cave; spr->gotoxy(xspr->_x, xspr->_y); - if ((spr->_flags._shad = xspr->_flags._shad) == 1) { + if ((spr->_flags.flags._shad = xspr->_flags.flags._shad) == 1) { _vga->_showQ->insert(_vga->_showQ->remove(xspr->_prev), spr); - xspr->_flags._shad = false; + xspr->_flags.flags._shad = false; } spr->_z = xspr->_z; snSend(xspr, -1); @@ -728,7 +728,7 @@ void CGEEngine::snSlave(Sprite *spr, int ref) { if (spr && slv) { if (spr->active()) { snSend(slv, spr->_cave); - slv->_flags._slav = true; + slv->_flags.flags._slav = true; slv->_z = spr->_z; _vga->_showQ->insert(_vga->_showQ->remove(slv), spr->_next); } @@ -740,21 +740,21 @@ void CGEEngine::snTrans(Sprite *spr, int trans) { debugC(1, kCGEDebugEngine, "CGEEngine::snTrans(spr, %d)", trans); if (spr) - spr->_flags._tran = (trans < 0) ? !spr->_flags._tran : (trans != 0); + spr->_flags.flags._tran = (trans < 0) ? !spr->_flags.flags._tran : (trans != 0); } void CGEEngine::snPort(Sprite *spr, int port) { debugC(1, kCGEDebugEngine, "CGEEngine::snPort(spr, %d)", port); if (spr) - spr->_flags._port = (port < 0) ? !spr->_flags._port : (port != 0); + spr->_flags.flags._port = (port < 0) ? !spr->_flags.flags._port : (port != 0); } void CGEEngine::snKill(Sprite *spr) { debugC(1, kCGEDebugEngine, "CGEEngine::snKill(spr)"); if (spr) { - if (spr->_flags._kept) { + if (spr->_flags.flags._kept) { int n = findPocket(spr); if (n >= 0) _pocket[n] = NULL; @@ -763,14 +763,14 @@ void CGEEngine::snKill(Sprite *spr) { hide1(spr); _vga->_showQ->remove(spr); _eventManager->clearEvent(spr); - if (spr->_flags._kill) + if (spr->_flags.flags._kill) delete spr; else { spr->_cave = -1; _vga->_spareQ->append(spr); } if (nx) { - if (nx->_flags._slav) + if (nx->_flags.flags._slav) snKill(nx); } } @@ -791,11 +791,11 @@ void CGEEngine::snKeep(Sprite *spr, int stp) { debugC(1, kCGEDebugEngine, "CGEEngine::snKeep(spr, %d)", stp); selectPocket(-1); - if (spr && ! spr->_flags._kept && _pocket[_pocPtr] == NULL) { + if (spr && ! spr->_flags.flags._kept && _pocket[_pocPtr] == NULL) { snSound(spr, 3, 1); _pocket[_pocPtr] = spr; spr->_cave = 0; - spr->_flags._kept = true; + spr->_flags.flags._kept = true; spr->gotoxy(kPocketX + kPocketDX * _pocPtr + kPocketDX / 2 - spr->_w / 2, kPocketY + kPocketDY / 2 - spr->_h / 2); if (stp >= 0) @@ -812,7 +812,7 @@ void CGEEngine::snGive(Sprite *spr, int stp) { if (p >= 0) { _pocket[p] = NULL; spr->_cave = _now; - spr->_flags._kept = false; + spr->_flags.flags._kept = false; if (stp >= 0) spr->step(stp); } @@ -843,7 +843,7 @@ void CGEEngine::snLevel(Sprite *spr, int lev) { } _maxCave = _maxCaveArr[_lev]; if (spr) - spr->_flags._hide = false; + spr->_flags.flags._hide = false; } diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index db44536267f..0f38bb0892c 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -77,7 +77,7 @@ Talk::Talk(CGEEngine *vm, const char *text, TextBoxStyle mode) : Sprite(vm, NULL), _mode(mode), _vm(vm) { _ts = NULL; - _flags._syst = true; + _flags.flags._syst = true; update(text); } @@ -85,7 +85,7 @@ Talk::Talk(CGEEngine *vm, const char *text, TextBoxStyle mode) Talk::Talk(CGEEngine *vm) : Sprite(vm, NULL), _mode(kTBPure), _vm(vm) { _ts = NULL; - _flags._syst = true; + _flags.flags._syst = true; } Font *Talk::_font; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 0e77bb89553..c3bdbea7067 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -180,7 +180,7 @@ void Text::say(const char *text, Sprite *spr) { killText(); _talk = new Talk(_vm, text, kTBRound); if (_talk) { - bool east = spr->_flags._east; + bool east = spr->_flags.flags._east; int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2); int y = spr->_y + 2; Sprite *spike = new Spike(_vm); @@ -197,8 +197,8 @@ void Text::say(const char *text, Sprite *spr) { if (spr->_ref == 1) x += ((east) ? -10 : 10); // Hero - _talk->_flags._kill = true; - _talk->_flags._bDel = true; + _talk->_flags.flags._kill = true; + _talk->_flags.flags._bDel = true; _talk->setName(_text->getText(kSayName)); _talk->gotoxy(x - (_talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - _talk->_h + 1); _talk->_z = 125; @@ -206,8 +206,8 @@ void Text::say(const char *text, Sprite *spr) { spike->gotoxy(x, _talk->_y + _talk->_h - 1); spike->_z = 126; - spike->_flags._slav = true; - spike->_flags._kill = true; + spike->_flags.flags._slav = true; + spike->_flags.flags._kill = true; spike->setName(_text->getText(kSayName)); spike->step(east); spike->_ref = kSayRef; @@ -223,8 +223,8 @@ void CGEEngine::inf(const char *text) { killText(); _talk = new Talk(this, text, kTBRect); if (_talk) { - _talk->_flags._kill = true; - _talk->_flags._bDel = true; + _talk->_flags.flags._kill = true; + _talk->_flags.flags._bDel = true; _talk->setName(_text->getText(kInfName)); _talk->center(); _talk->gotoxy(_talk->_x, _talk->_y - 20); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index ad2415caafd..6c412927129 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -164,7 +164,7 @@ BitmapPtr *Sprite::setShapeList(BitmapPtr *shpP) { } expand(); _ext->_shpList = shpP; - _flags._bDel = true; + _flags.flags._bDel = true; if (!_ext->_seq) setSeq(getConstantSeq(_shpCnt < 2)); } @@ -382,7 +382,7 @@ Sprite *Sprite::contract() { if (e) { if (e->_name) delete[] e->_name; - if (_flags._bDel && e->_shpList) { + if (_flags.flags._bDel && e->_shpList) { int i; for (i = 0; e->_shpList[i]; i++) delete e->_shpList[i]; @@ -436,24 +436,24 @@ void Sprite::makeXlat(uint8 *x) { if (_ext) { BitmapPtr *b; - if (_flags._xlat) + if (_flags.flags._xlat) killXlat(); for (b = _ext->_shpList; *b; b++) (*b)->_m = x; - _flags._xlat = true; + _flags.flags._xlat = true; } } void Sprite::killXlat() { - if (_flags._xlat && _ext) { + if (_flags.flags._xlat && _ext) { BitmapPtr *b; uint8 *m = (*_ext->_shpList)->_m; free(m); for (b = _ext->_shpList; *b; b++) (*b)->_m = NULL; - _flags._xlat = false; + _flags.flags._xlat = false; } } @@ -475,9 +475,9 @@ void Sprite::gotoxy(int x, int y) { _y = y; } if (_next) - if (_next->_flags._slav) + if (_next->_flags.flags._slav) _next->gotoxy(_next->_x - xo + _x, _next->_y - yo + _y); - if (_flags._shad) + if (_flags.flags._shad) _prev->gotoxy(_prev->_x - xo + _x, _prev->_y - yo + _y); } @@ -498,8 +498,8 @@ void Sprite::show() { e->_y1 = _y; e->_b1 = shp(); // asm sti // ...done! - if (!_flags._hide) { - if (_flags._xlat) + if (!_flags.flags._hide) { + if (_flags.flags._xlat) e->_b1->xShow(e->_x1, e->_y1); else e->_b1->show(e->_x1, e->_y1); @@ -545,7 +545,7 @@ void Sprite::sync(Common::Serializer &s) { s.syncAsUint16LE(unused); // _ext s.syncAsUint16LE(_ref); s.syncAsByte(_cave); - s.syncBytes((byte *)&_flags, 2); + s.syncAsUint16LE(_flags.flagsWord); s.syncAsUint16LE(_x); s.syncAsUint16LE(_y); s.syncAsByte(_z); @@ -567,7 +567,7 @@ Sprite *spriteAt(int x, int y) { Sprite *spr = NULL, * tail = _vga->_showQ->last(); if (tail) { for (spr = tail->_prev; spr; spr = spr->_prev) { - if (! spr->_flags._hide && ! spr->_flags._tran) { + if (! spr->_flags.flags._hide && ! spr->_flags.flags._tran) { if (spr->shp()->solidAt(x - spr->_x, y - spr->_y)) break; } @@ -589,7 +589,7 @@ Queue::~Queue() { void Queue::clear() { while (_head) { Sprite *s = remove(_head); - if (s->_flags._kill) + if (s->_flags.flags._kill) delete s; } } @@ -1077,7 +1077,7 @@ PocLight::PocLight(CGEEngine *vm): Sprite(vm, NULL) { setShapeList(LI); - _flags._kill = false; + _flags.flags._kill = false; } } // End of namespace CGE diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index d43e5900842..9ac1bb3c634 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -120,14 +120,8 @@ public: {} }; - -class Sprite { -protected: - SprExt *_ext; -public: - int _ref; - signed char _cave; - struct Flags { +union Flags { + struct FlagsBits { uint16 _hide : 1; // general visibility switch uint16 _near : 1; // Near action lock uint16 _drag : 1; // sprite is moveable @@ -144,7 +138,17 @@ public: uint16 _back : 1; // 'send to background' request uint16 _bDel : 1; // delete bitmaps in ~SPRITE uint16 _tran : 1; // transparent (untouchable) - } _flags; + } flags; + uint16 flagsWord; +}; + +class Sprite { +protected: + SprExt *_ext; +public: + int _ref; + signed char _cave; + Flags _flags; int _x; int _y; signed char _z; diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 48b27d97275..fc7ef2fe004 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -53,10 +53,10 @@ MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { _ts[1] = NULL; setShapeList(_ts); - _flags._slav = true; - _flags._tran = true; - _flags._kill = true; - _flags._bDel = true; + _flags.flags._slav = true; + _flags.flags._tran = true; + _flags.flags._kill = true; + _flags.flags._bDel = true; } @@ -98,8 +98,8 @@ Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y) _items = 0; for (cp = list; cp->_text; cp++) _items++; - _flags._bDel = true; - _flags._kill = true; + _flags.flags._bDel = true; + _flags.flags._kill = true; if (x < 0 || y < 0) center(); else diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index a418bfb178e..36fecdd22b0 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -75,7 +75,7 @@ Walk::Walk(CGEEngine *vm, BitmapPtr *shpl) void Walk::tick() { - if (_flags._hide) + if (_flags.flags._hide) return; _here = XZ(_x + _w / 2, _y + _h); @@ -85,17 +85,17 @@ void Walk::tick() { _sys->funTouch(); for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (distance(spr) < 2) { - if (!spr->_flags._near) { + if (!spr->_flags.flags._near) { _vm->feedSnail(spr, kNear); - spr->_flags._near = true; + spr->_flags.flags._near = true; } } else { - spr->_flags._near = false; + spr->_flags.flags._near = false; } } } - if (_flags._hold || _tracePtr < 0) + if (_flags.flags._hold || _tracePtr < 0) park(); else { if (_here == _trace[_tracePtr]) { @@ -187,7 +187,7 @@ void Walk::findWay(Sprite *spr) { if (spr && spr != this) { int x = spr->_x; int z = spr->_z; - if (spr->_flags._east) + if (spr->_flags.flags._east) x += spr->_w + _w / 2 - kWalkSide; else x -= _w / 2 - kWalkSide; @@ -207,7 +207,7 @@ void Walk::reach(Sprite *spr, int mode) { if (spr) { _hero->findWay(spr); if (mode < 0) { - mode = spr->_flags._east; + mode = spr->_flags.flags._east; if (lower(spr)) mode += 2; } From 372d488b3bc01f6dce06dde83d4818a010695c70 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 19 Aug 2011 20:36:43 +1000 Subject: [PATCH 218/276] CGE: Revert previous commit of flags synchronisation --- engines/cge/cge_main.cpp | 96 +++++++++++++++++++++------------------- engines/cge/events.cpp | 10 ++--- engines/cge/game.cpp | 2 +- engines/cge/gettext.cpp | 4 +- engines/cge/mixer.cpp | 16 +++---- engines/cge/snail.cpp | 52 +++++++++++----------- engines/cge/talk.cpp | 4 +- engines/cge/text.cpp | 14 +++--- engines/cge/vga13h.cpp | 28 ++++++------ engines/cge/vga13h.h | 21 ++++----- engines/cge/vmenu.cpp | 12 ++--- engines/cge/walk.cpp | 14 +++--- engines/cge/walk.h | 2 +- 13 files changed, 137 insertions(+), 138 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 213ad7abec1..5b98b0a4e8c 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -462,16 +462,20 @@ void CGEEngine::loadMapping() { if (_now <= _caveMax) { INI_FILE cf(progName(".TAB")); if (!cf._error) { - memset(Cluster::_map, 0, sizeof(Cluster::_map)); - cf.seek((_now - 1) * sizeof(Cluster::_map)); - cf.read((uint8 *) Cluster::_map, sizeof(Cluster::_map)); + // Move to the data for the given room + cf.seek((_now - 1) * kMapArrSize); + + // Read in the data + for (int z = 0; z < kMapZCnt; ++z) { + cf.read(&Cluster::_map[z][0], kMapXCnt); + } } } } Square::Square(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { - _flags.flags._kill = true; - _flags.flags._bDel = false; + _flags._kill = true; + _flags._bDel = false; BitmapPtr *MB = new BitmapPtr[2]; MB[0] = new Bitmap("BRICK", true); @@ -528,7 +532,7 @@ void CGEEngine::quit() { { NULL, &CGEEngine::dummy } }; - if (_snail->idle() && !_hero->_flags.flags._hide) { + if (_snail->idle() && !_hero->_flags._hide) { if (Vmenu::_addr) { _snail_->addCom(kSnKill, -1, 0, Vmenu::_addr); resetQSwitch(); @@ -553,13 +557,13 @@ void CGEEngine::miniStep(int stp) { debugC(1, kCGEDebugEngine, "CGEEngine::miniStep(%d)", stp); if (stp < 0) - _miniCave->_flags.flags._hide = true; + _miniCave->_flags._hide = true; else { *_miniShp[0] = *_miniShpList[stp]; if (_fx->_current) &*(_fx->_current->addr()); - _miniCave->_flags.flags._hide = false; + _miniCave->_flags._hide = false; } } @@ -600,7 +604,7 @@ void CGEEngine::caveUp() { Sprite *n = spr->_next; if (spr->_cave == _now || spr->_cave == 0) if (spr->_ref != BakRef) { - if (spr->_flags.flags._back) + if (spr->_flags._back) spr->backShow(); else expandSprite(spr); @@ -618,7 +622,7 @@ void CGEEngine::caveUp() { // following 2 lines trims Hero's Z position! _hero->tick(); _hero->_time = 1; - _hero->_flags.flags._hide = false; + _hero->_flags._hide = false; } if (!_dark) @@ -650,7 +654,7 @@ void CGEEngine::caveDown() { debugC(1, kCGEDebugEngine, "CGEEngine::caveDown()"); Sprite *spr; - if (_horzLine && !_horzLine->_flags.flags._hide) + if (_horzLine && !_horzLine->_flags._hide) switchMapping(); for (spr = _vga->_showQ->first(); spr;) { @@ -823,7 +827,7 @@ void System::touch(uint16 mask, int x, int y) { _sprite->step(x - '0'); break; case F10 : - if (_snail->idle() && !_hero->_flags.flags._hide) + if (_snail->idle() && !_hero->_flags._hide) _vm->startCountDown(); break; } @@ -857,7 +861,7 @@ void System::touch(uint16 mask, int x, int y) { if (cav && _snail->idle() && _hero->_tracePtr < 0) _vm->switchCave(cav); - if (_horzLine && !_horzLine->_flags.flags._hide) { + if (_horzLine && !_horzLine->_flags._hide) { if (y >= kMapTop && y < kMapTop + kMapHig) { int8 x1, z1; XZ(x, y).split(x1, z1); @@ -960,7 +964,7 @@ void CGEEngine::switchMapping() { assert(_horzLine); debugC(1, kCGEDebugEngine, "CGEEngine::switchMapping()"); - if (_horzLine && _horzLine->_flags.flags._hide) { + if (_horzLine && _horzLine->_flags._hide) { int i; for (i = 0; i < kMapZCnt; i++) { int j; @@ -975,14 +979,14 @@ void CGEEngine::switchMapping() { if (s->_w == kMapGridX && s->_h == kMapGridZ) _snail_->addCom(kSnKill, -1, 0, s); } - _horzLine->_flags.flags._hide = !_horzLine->_flags.flags._hide; + _horzLine->_flags._hide = !_horzLine->_flags._hide; } void CGEEngine::killSprite() { debugC(1, kCGEDebugEngine, "CGEEngine::killSprite()"); - _sprite->_flags.flags._kill = true; - _sprite->_flags.flags._bDel = true; + _sprite->_flags._kill = true; + _sprite->_flags._bDel = true; _snail_->addCom(kSnKill, -1, 0, _sprite); _sprite = NULL; } @@ -1007,7 +1011,7 @@ void CGEEngine::pullSprite() { if (spr) { spr = spr->_next; if (spr) - ok = (!spr->_flags.flags._slav); + ok = (!spr->_flags._slav); } if (ok) { _vga->_showQ->insert(_vga->_showQ->remove(_sprite), spr); @@ -1058,7 +1062,7 @@ void CGEEngine::sayDebug() { char *spH = DebugText + 37; char *spF = DebugText + 41; - if (!_debugLine->_flags.flags._hide) { + if (!_debugLine->_flags._hide) { dwtom(_mouse->_x, absX, 10, 3); dwtom(_mouse->_y, absY, 10, 3); @@ -1083,7 +1087,7 @@ void CGEEngine::sayDebug() { void CGEEngine::switchDebug() { - _debugLine->_flags.flags._hide = !_debugLine->_flags.flags._hide; + _debugLine->_flags._hide = !_debugLine->_flags._hide; } @@ -1121,7 +1125,7 @@ void Sprite::touch(uint16 mask, int x, int y) { _vm->optionTouch(_ref % 10, mask); return; } - if (_flags.flags._syst) + if (_flags._syst) return; // cannot access system sprites if (_vm->_game) if (mask & kMouseLeftUp) { mask &= ~kMouseLeftUp; @@ -1130,7 +1134,7 @@ void Sprite::touch(uint16 mask, int x, int y) { if ((mask & kMouseRightUp) && _snail->idle()) { Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_vm->_pocPtr] : NULL; if (ps) { - if (_flags.flags._kept || _hero->distance(this) < kDistMax) { + if (_flags._kept || _hero->distance(this) < kDistMax) { if (works(ps)) { _vm->feedSnail(ps, kTake); } else @@ -1139,18 +1143,18 @@ void Sprite::touch(uint16 mask, int x, int y) { } else _vm->tooFar(); } else { - if (_flags.flags._kept) + if (_flags._kept) mask |= kMouseLeftUp; else { if (_hero->distance(this) < kDistMax) { /// - if (_flags.flags._port) { + if (_flags._port) { if (_vm->findPocket(NULL) < 0) _vm->pocFul(); else { _snail->addCom(kSnReach, -1, -1, this); _snail->addCom(kSnKeep, -1, -1, this); - _flags.flags._port = false; + _flags._port = false; } } else { if (_takePtr != NO_PTR) { @@ -1168,7 +1172,7 @@ void Sprite::touch(uint16 mask, int x, int y) { } } if ((mask & kMouseLeftUp) && _snail->idle()) { - if (_flags.flags._kept) { + if (_flags._kept) { int n; for (n = 0; n < kPocketNX; n++) { if (_pocket[n] == this) { @@ -1319,11 +1323,11 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int _sprite->_ref = ref; _sprite->_cave = cav; _sprite->_z = pos; - _sprite->_flags.flags._east = east; - _sprite->_flags.flags._port = port; - _sprite->_flags.flags._tran = tran; - _sprite->_flags.flags._kill = true; - _sprite->_flags.flags._bDel = true; + _sprite->_flags._east = east; + _sprite->_flags._port = port; + _sprite->_flags._tran = tran; + _sprite->_flags._kill = true; + _sprite->_flags._bDel = true; // Extract the filename, without the extension strcpy(_sprite->_file, fname); @@ -1390,7 +1394,7 @@ void CGEEngine::loadScript(const char *fname) { _sprite = NULL; loadSprite(SpN, SpI, SpA, SpX, SpY, SpZ); if (_sprite && BkG) - _sprite->_flags.flags._back = true; + _sprite->_flags._back = true; } if (! ok) error("Bad INI line %d [%s]", lcnt, fname); @@ -1452,7 +1456,7 @@ void CGEEngine::handleFrame() { void CGEEngine::tick() { for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (spr->_time) { - if (!spr->_flags.flags._hide) { + if (!spr->_flags._hide) { if (--spr->_time == 0) spr->tick(); } @@ -1483,9 +1487,9 @@ void CGEEngine::runGame() { _text->preload(100, 1000); loadHeroXY(); - _cavLight->_flags.flags._tran = true; + _cavLight->_flags._tran = true; _vga->_showQ->append(_cavLight); - _cavLight->_flags.flags._hide = true; + _cavLight->_flags._hide = true; const Seq pocSeq[] = { { 0, 0, 0, 0, 20 }, @@ -1500,7 +1504,7 @@ void CGEEngine::runGame() { Common::copy(pocSeq, pocSeq + 7, seq); _pocLight->setSeq(seq); - _pocLight->_flags.flags._tran = true; + _pocLight->_flags._tran = true; _pocLight->_time = 1; _pocLight->_z = 120; _vga->_showQ->append(_pocLight); @@ -1527,8 +1531,8 @@ void CGEEngine::runGame() { loadSprite("MINI", -1, 0, kMiniX, kMiniY); expandSprite(_miniCave = _sprite); // NULL is ok if (_miniCave) { - _miniCave->_flags.flags._kill = false; - _miniCave->_flags.flags._hide = true; + _miniCave->_flags._kill = false; + _miniCave->_flags._hide = true; _miniShp[0] = new Bitmap(*_miniCave->shp()); _miniShpList = _miniCave->setShapeList(_miniShp); postMiniStep(-1); @@ -1543,16 +1547,16 @@ void CGEEngine::runGame() { delete _shadow; if ((_shadow = _sprite) != NULL) { _shadow->_ref = 2; - _shadow->_flags.flags._tran = true; - _shadow->_flags.flags._kill = false; - _hero->_flags.flags._shad = true; + _shadow->_flags._tran = true; + _shadow->_flags._kill = false; + _hero->_flags._shad = true; _vga->_showQ->insert(_vga->_spareQ->remove(_shadow), _hero); } } } _infoLine->gotoxy(kInfoX, kInfoY); - _infoLine->_flags.flags._tran = true; + _infoLine->_flags._tran = true; _infoLine->update(NULL); _vga->_showQ->insert(_infoLine); @@ -1634,8 +1638,8 @@ bool CGEEngine::showTitle(const char *name) { bool userOk = false; Sprite D(this, LB); - D._flags.flags._kill = true; - D._flags.flags._bDel = true; + D._flags._kill = true; + D._flags._bDel = true; D.center(); D.show(2); @@ -1737,9 +1741,9 @@ void CGEEngine::cge_main() { if (!kSavegame0File::exist(kSavegame0Name)) _mode = 2; - _debugLine->_flags.flags._hide = true; + _debugLine->_flags._hide = true; if (_horzLine) - _horzLine->_flags.flags._hide = true; + _horzLine->_flags._hide = true; if (_music && _soundOk) _midiPlayer.loadMidi(0); diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 7235bf19c1e..916de839ebb 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -158,7 +158,7 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) _buttons = 0; _busy = NULL; _active = false; - _flags.flags._kill = false; + _flags._kill = false; const Seq ms[] = { { 0, 0, 0, 0, 1 }, @@ -301,9 +301,9 @@ void EventManager::handleEvents() { if (e._mask & kMouseLeftDown) { _mouse->_hold = e._spritePtr; if (_mouse->_hold) { - _mouse->_hold->_flags.flags._hold = true; + _mouse->_hold->_flags._hold = true; - if (_mouse->_hold->_flags.flags._drag) { + if (_mouse->_hold->_flags._drag) { _mouse->_hx = e._x - _mouse->_hold->_x; _mouse->_hy = e._y - _mouse->_hold->_y; } @@ -312,7 +312,7 @@ void EventManager::handleEvents() { if (e._mask & kMouseLeftUp) { if (_mouse->_hold) { - _mouse->_hold->_flags.flags._hold = false; + _mouse->_hold->_flags._hold = false; _mouse->_hold = NULL; } } @@ -325,7 +325,7 @@ void EventManager::handleEvents() { _eventQueueTail = (_eventQueueTail + 1) % kEventMax; } if (_mouse->_hold) { - if (_mouse->_hold->_flags.flags._drag) + if (_mouse->_hold->_flags._drag) _mouse->_hold->gotoxy(_mouse->_x - _mouse->_hx, _mouse->_y - _mouse->_hy); } } diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index 0b9c6e2a400..e64e4af38a2 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -56,7 +56,7 @@ Fly::Fly(CGEEngine *vm, Bitmap **shpl) void Fly::tick() { step(); - if (!_flags.flags._kept) { + if (!_flags._kept) { if (newRandom(10) < 1) { _tx = newRandom(3) - 1; _ty = newRandom(3) - 1; diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index 34e8643668e..d96e494402a 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -46,8 +46,8 @@ GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) _ts[1] = NULL; setShapeList(_ts); - _flags.flags._bDel = true; - _flags.flags._kill = true; + _flags._bDel = true; + _flags._kill = true; memcpy(_buff, text, _len); _buff[_len] = ' '; _buff[_len + 1] = '\0'; diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index 513c6f683f5..ba24f832c3e 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -45,9 +45,9 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _ _mb[1] = NULL; setShapeList(_mb); setName(_text->getText(kMixName)); - _flags.flags._syst = true; - _flags.flags._kill = true; - _flags.flags._bDel = true; + _flags._syst = true; + _flags._kill = true; + _flags._bDel = true; gotoxy(x, y); _z = kMixZ; @@ -73,13 +73,13 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _ spr->setSeq(seq); spr->gotoxy(x + 2 + 12 * i, y + 8); - spr->_flags.flags._tran = true; - spr->_flags.flags._kill = true; - spr->_flags.flags._bDel = false; + spr->_flags._tran = true; + spr->_flags._kill = true; + spr->_flags._bDel = false; spr->_z = kMixZ; _led[i] = spr; } - _led[ArrayCount(_led) - 1]->_flags.flags._bDel = true; + _led[ArrayCount(_led) - 1]->_flags._bDel = true; _vga->_showQ->insert(this); for (i = 0; i < ArrayCount(_led); i++) @@ -128,7 +128,7 @@ void Mixer::tick() { int y = _mouse->_y; if (spriteAt(x, y) == this) { _fall = kMixFall; - if (_flags.flags._hold) + if (_flags._hold) touch(kMouseLeftUp, x - _x, y - _y); } else { if (_fall) diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 750d44f45c3..6a5556ca58c 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -493,7 +493,7 @@ void CGEEngine::snZTrim(Sprite *spr) { if (spr) if (spr->active()) { Sprite *s; - s = (spr->_flags.flags._shad) ? spr->_prev : NULL; + s = (spr->_flags._shad) ? spr->_prev : NULL; _vga->_showQ->insert(_vga->_showQ->remove(spr)); if (s) { s->_z = spr->_z; @@ -506,9 +506,9 @@ void CGEEngine::snHide(Sprite *spr, int val) { debugC(1, kCGEDebugEngine, "CGEEngine::snHide(spr, %d)", val); if (spr) { - spr->_flags.flags._hide = (val >= 0) ? (val != 0) : (!spr->_flags.flags._hide); - if (spr->_flags.flags._shad) - spr->_prev->_flags.flags._hide = spr->_flags.flags._hide; + spr->_flags._hide = (val >= 0) ? (val != 0) : (!spr->_flags._hide); + if (spr->_flags._shad) + spr->_prev->_flags._hide = spr->_flags._hide; } } @@ -554,18 +554,18 @@ void CGEEngine::snSend(Sprite *spr, int val) { spr->_cave = val; if (val1 != was1) { if (was1) { - if (spr->_flags.flags._kept) { + if (spr->_flags._kept) { int n = findPocket(spr); if (n >= 0) _pocket[n] = NULL; } hide1(spr); contractSprite(spr); - spr->_flags.flags._slav = false; + spr->_flags._slav = false; } else { if (spr->_ref % 1000 == 0) Bitmap::_pal = Vga::_sysPal; - if (spr->_flags.flags._back) + if (spr->_flags._back) spr->backShow(true); else expandSprite(spr); @@ -589,12 +589,12 @@ void CGEEngine::snSwap(Sprite *spr, int xref) { swap(spr->_x, xspr->_x); swap(spr->_y, xspr->_y); swap(spr->_z, xspr->_z); - if (spr->_flags.flags._kept) { + if (spr->_flags._kept) { int n = findPocket(spr); if (n >= 0) _pocket[n] = xspr; - xspr->_flags.flags._kept = true; - xspr->_flags.flags._port = false; + xspr->_flags._kept = true; + xspr->_flags._port = false; } if (xwas1 != was1) { if (was1) { @@ -617,14 +617,14 @@ void CGEEngine::snCover(Sprite *spr, int xref) { Sprite *xspr = locate(xref); if (spr && xspr) { - spr->_flags.flags._hide = true; + spr->_flags._hide = true; xspr->_z = spr->_z; xspr->_cave = spr->_cave; xspr->gotoxy(spr->_x, spr->_y); expandSprite(xspr); - if ((xspr->_flags.flags._shad = spr->_flags.flags._shad) == 1) { + if ((xspr->_flags._shad = spr->_flags._shad) == 1) { _vga->_showQ->insert(_vga->_showQ->remove(spr->_prev), xspr); - spr->_flags.flags._shad = false; + spr->_flags._shad = false; } feedSnail(xspr, kNear); } @@ -635,12 +635,12 @@ void CGEEngine::snUncover(Sprite *spr, Sprite *xspr) { debugC(1, kCGEDebugEngine, "CGEEngine::snUncover(spr, xspr)"); if (spr && xspr) { - spr->_flags.flags._hide = false; + spr->_flags._hide = false; spr->_cave = xspr->_cave; spr->gotoxy(xspr->_x, xspr->_y); - if ((spr->_flags.flags._shad = xspr->_flags.flags._shad) == 1) { + if ((spr->_flags._shad = xspr->_flags._shad) == 1) { _vga->_showQ->insert(_vga->_showQ->remove(xspr->_prev), spr); - xspr->_flags.flags._shad = false; + xspr->_flags._shad = false; } spr->_z = xspr->_z; snSend(xspr, -1); @@ -728,7 +728,7 @@ void CGEEngine::snSlave(Sprite *spr, int ref) { if (spr && slv) { if (spr->active()) { snSend(slv, spr->_cave); - slv->_flags.flags._slav = true; + slv->_flags._slav = true; slv->_z = spr->_z; _vga->_showQ->insert(_vga->_showQ->remove(slv), spr->_next); } @@ -740,21 +740,21 @@ void CGEEngine::snTrans(Sprite *spr, int trans) { debugC(1, kCGEDebugEngine, "CGEEngine::snTrans(spr, %d)", trans); if (spr) - spr->_flags.flags._tran = (trans < 0) ? !spr->_flags.flags._tran : (trans != 0); + spr->_flags._tran = (trans < 0) ? !spr->_flags._tran : (trans != 0); } void CGEEngine::snPort(Sprite *spr, int port) { debugC(1, kCGEDebugEngine, "CGEEngine::snPort(spr, %d)", port); if (spr) - spr->_flags.flags._port = (port < 0) ? !spr->_flags.flags._port : (port != 0); + spr->_flags._port = (port < 0) ? !spr->_flags._port : (port != 0); } void CGEEngine::snKill(Sprite *spr) { debugC(1, kCGEDebugEngine, "CGEEngine::snKill(spr)"); if (spr) { - if (spr->_flags.flags._kept) { + if (spr->_flags._kept) { int n = findPocket(spr); if (n >= 0) _pocket[n] = NULL; @@ -763,14 +763,14 @@ void CGEEngine::snKill(Sprite *spr) { hide1(spr); _vga->_showQ->remove(spr); _eventManager->clearEvent(spr); - if (spr->_flags.flags._kill) + if (spr->_flags._kill) delete spr; else { spr->_cave = -1; _vga->_spareQ->append(spr); } if (nx) { - if (nx->_flags.flags._slav) + if (nx->_flags._slav) snKill(nx); } } @@ -791,11 +791,11 @@ void CGEEngine::snKeep(Sprite *spr, int stp) { debugC(1, kCGEDebugEngine, "CGEEngine::snKeep(spr, %d)", stp); selectPocket(-1); - if (spr && ! spr->_flags.flags._kept && _pocket[_pocPtr] == NULL) { + if (spr && ! spr->_flags._kept && _pocket[_pocPtr] == NULL) { snSound(spr, 3, 1); _pocket[_pocPtr] = spr; spr->_cave = 0; - spr->_flags.flags._kept = true; + spr->_flags._kept = true; spr->gotoxy(kPocketX + kPocketDX * _pocPtr + kPocketDX / 2 - spr->_w / 2, kPocketY + kPocketDY / 2 - spr->_h / 2); if (stp >= 0) @@ -812,7 +812,7 @@ void CGEEngine::snGive(Sprite *spr, int stp) { if (p >= 0) { _pocket[p] = NULL; spr->_cave = _now; - spr->_flags.flags._kept = false; + spr->_flags._kept = false; if (stp >= 0) spr->step(stp); } @@ -843,7 +843,7 @@ void CGEEngine::snLevel(Sprite *spr, int lev) { } _maxCave = _maxCaveArr[_lev]; if (spr) - spr->_flags.flags._hide = false; + spr->_flags._hide = false; } diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 0f38bb0892c..db44536267f 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -77,7 +77,7 @@ Talk::Talk(CGEEngine *vm, const char *text, TextBoxStyle mode) : Sprite(vm, NULL), _mode(mode), _vm(vm) { _ts = NULL; - _flags.flags._syst = true; + _flags._syst = true; update(text); } @@ -85,7 +85,7 @@ Talk::Talk(CGEEngine *vm, const char *text, TextBoxStyle mode) Talk::Talk(CGEEngine *vm) : Sprite(vm, NULL), _mode(kTBPure), _vm(vm) { _ts = NULL; - _flags.flags._syst = true; + _flags._syst = true; } Font *Talk::_font; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index c3bdbea7067..0e77bb89553 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -180,7 +180,7 @@ void Text::say(const char *text, Sprite *spr) { killText(); _talk = new Talk(_vm, text, kTBRound); if (_talk) { - bool east = spr->_flags.flags._east; + bool east = spr->_flags._east; int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2); int y = spr->_y + 2; Sprite *spike = new Spike(_vm); @@ -197,8 +197,8 @@ void Text::say(const char *text, Sprite *spr) { if (spr->_ref == 1) x += ((east) ? -10 : 10); // Hero - _talk->_flags.flags._kill = true; - _talk->_flags.flags._bDel = true; + _talk->_flags._kill = true; + _talk->_flags._bDel = true; _talk->setName(_text->getText(kSayName)); _talk->gotoxy(x - (_talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - _talk->_h + 1); _talk->_z = 125; @@ -206,8 +206,8 @@ void Text::say(const char *text, Sprite *spr) { spike->gotoxy(x, _talk->_y + _talk->_h - 1); spike->_z = 126; - spike->_flags.flags._slav = true; - spike->_flags.flags._kill = true; + spike->_flags._slav = true; + spike->_flags._kill = true; spike->setName(_text->getText(kSayName)); spike->step(east); spike->_ref = kSayRef; @@ -223,8 +223,8 @@ void CGEEngine::inf(const char *text) { killText(); _talk = new Talk(this, text, kTBRect); if (_talk) { - _talk->_flags.flags._kill = true; - _talk->_flags.flags._bDel = true; + _talk->_flags._kill = true; + _talk->_flags._bDel = true; _talk->setName(_text->getText(kInfName)); _talk->center(); _talk->gotoxy(_talk->_x, _talk->_y - 20); diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 6c412927129..ad2415caafd 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -164,7 +164,7 @@ BitmapPtr *Sprite::setShapeList(BitmapPtr *shpP) { } expand(); _ext->_shpList = shpP; - _flags.flags._bDel = true; + _flags._bDel = true; if (!_ext->_seq) setSeq(getConstantSeq(_shpCnt < 2)); } @@ -382,7 +382,7 @@ Sprite *Sprite::contract() { if (e) { if (e->_name) delete[] e->_name; - if (_flags.flags._bDel && e->_shpList) { + if (_flags._bDel && e->_shpList) { int i; for (i = 0; e->_shpList[i]; i++) delete e->_shpList[i]; @@ -436,24 +436,24 @@ void Sprite::makeXlat(uint8 *x) { if (_ext) { BitmapPtr *b; - if (_flags.flags._xlat) + if (_flags._xlat) killXlat(); for (b = _ext->_shpList; *b; b++) (*b)->_m = x; - _flags.flags._xlat = true; + _flags._xlat = true; } } void Sprite::killXlat() { - if (_flags.flags._xlat && _ext) { + if (_flags._xlat && _ext) { BitmapPtr *b; uint8 *m = (*_ext->_shpList)->_m; free(m); for (b = _ext->_shpList; *b; b++) (*b)->_m = NULL; - _flags.flags._xlat = false; + _flags._xlat = false; } } @@ -475,9 +475,9 @@ void Sprite::gotoxy(int x, int y) { _y = y; } if (_next) - if (_next->_flags.flags._slav) + if (_next->_flags._slav) _next->gotoxy(_next->_x - xo + _x, _next->_y - yo + _y); - if (_flags.flags._shad) + if (_flags._shad) _prev->gotoxy(_prev->_x - xo + _x, _prev->_y - yo + _y); } @@ -498,8 +498,8 @@ void Sprite::show() { e->_y1 = _y; e->_b1 = shp(); // asm sti // ...done! - if (!_flags.flags._hide) { - if (_flags.flags._xlat) + if (!_flags._hide) { + if (_flags._xlat) e->_b1->xShow(e->_x1, e->_y1); else e->_b1->show(e->_x1, e->_y1); @@ -545,7 +545,7 @@ void Sprite::sync(Common::Serializer &s) { s.syncAsUint16LE(unused); // _ext s.syncAsUint16LE(_ref); s.syncAsByte(_cave); - s.syncAsUint16LE(_flags.flagsWord); + s.syncBytes((byte *)&_flags, 2); s.syncAsUint16LE(_x); s.syncAsUint16LE(_y); s.syncAsByte(_z); @@ -567,7 +567,7 @@ Sprite *spriteAt(int x, int y) { Sprite *spr = NULL, * tail = _vga->_showQ->last(); if (tail) { for (spr = tail->_prev; spr; spr = spr->_prev) { - if (! spr->_flags.flags._hide && ! spr->_flags.flags._tran) { + if (! spr->_flags._hide && ! spr->_flags._tran) { if (spr->shp()->solidAt(x - spr->_x, y - spr->_y)) break; } @@ -589,7 +589,7 @@ Queue::~Queue() { void Queue::clear() { while (_head) { Sprite *s = remove(_head); - if (s->_flags.flags._kill) + if (s->_flags._kill) delete s; } } @@ -1077,7 +1077,7 @@ PocLight::PocLight(CGEEngine *vm): Sprite(vm, NULL) { setShapeList(LI); - _flags.flags._kill = false; + _flags._kill = false; } } // End of namespace CGE diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 9ac1bb3c634..1d41a068ff8 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -120,8 +120,13 @@ public: {} }; -union Flags { - struct FlagsBits { +class Sprite { +protected: + SprExt *_ext; +public: + int _ref; + signed char _cave; + struct Flags { uint16 _hide : 1; // general visibility switch uint16 _near : 1; // Near action lock uint16 _drag : 1; // sprite is moveable @@ -138,17 +143,7 @@ union Flags { uint16 _back : 1; // 'send to background' request uint16 _bDel : 1; // delete bitmaps in ~SPRITE uint16 _tran : 1; // transparent (untouchable) - } flags; - uint16 flagsWord; -}; - -class Sprite { -protected: - SprExt *_ext; -public: - int _ref; - signed char _cave; - Flags _flags; + } _flags; int _x; int _y; signed char _z; diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index fc7ef2fe004..48b27d97275 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -53,10 +53,10 @@ MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { _ts[1] = NULL; setShapeList(_ts); - _flags.flags._slav = true; - _flags.flags._tran = true; - _flags.flags._kill = true; - _flags.flags._bDel = true; + _flags._slav = true; + _flags._tran = true; + _flags._kill = true; + _flags._bDel = true; } @@ -98,8 +98,8 @@ Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y) _items = 0; for (cp = list; cp->_text; cp++) _items++; - _flags.flags._bDel = true; - _flags.flags._kill = true; + _flags._bDel = true; + _flags._kill = true; if (x < 0 || y < 0) center(); else diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 36fecdd22b0..a418bfb178e 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -75,7 +75,7 @@ Walk::Walk(CGEEngine *vm, BitmapPtr *shpl) void Walk::tick() { - if (_flags.flags._hide) + if (_flags._hide) return; _here = XZ(_x + _w / 2, _y + _h); @@ -85,17 +85,17 @@ void Walk::tick() { _sys->funTouch(); for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (distance(spr) < 2) { - if (!spr->_flags.flags._near) { + if (!spr->_flags._near) { _vm->feedSnail(spr, kNear); - spr->_flags.flags._near = true; + spr->_flags._near = true; } } else { - spr->_flags.flags._near = false; + spr->_flags._near = false; } } } - if (_flags.flags._hold || _tracePtr < 0) + if (_flags._hold || _tracePtr < 0) park(); else { if (_here == _trace[_tracePtr]) { @@ -187,7 +187,7 @@ void Walk::findWay(Sprite *spr) { if (spr && spr != this) { int x = spr->_x; int z = spr->_z; - if (spr->_flags.flags._east) + if (spr->_flags._east) x += spr->_w + _w / 2 - kWalkSide; else x -= _w / 2 - kWalkSide; @@ -207,7 +207,7 @@ void Walk::reach(Sprite *spr, int mode) { if (spr) { _hero->findWay(spr); if (mode < 0) { - mode = spr->_flags.flags._east; + mode = spr->_flags._east; if (lower(spr)) mode += 2; } diff --git a/engines/cge/walk.h b/engines/cge/walk.h index c1d387f0b57..271663e51dc 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -35,6 +35,7 @@ namespace CGE { #define kMapXCnt 40 #define kMapZCnt 20 +#define kMapArrSize (kMapZCnt * kMapXCnt) #define kMapTop 80 #define kMapHig 80 #define kMapGridX (kScrWidth / kMapXCnt) @@ -93,7 +94,6 @@ public: Cluster() : Couple (-1, -1) { } bool chkBar() const; bool isValid() const; - }; From 2b0cec1cd7b87fe971f2adc44da20e03e71991dc Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 19 Aug 2011 21:15:59 +1000 Subject: [PATCH 219/276] CGE: Fix problem with being able to walk into protected areas --- engines/cge/walk.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index a418bfb178e..7bce9e29e66 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -49,7 +49,8 @@ bool Cluster::isValid() const { bool Cluster::chkBar() const { assert(_vm->_now <= _vm->_caveMax); - return (_a == _vm->_barriers[_vm->_now]._horz) && (_b == _vm->_barriers[_vm->_now]._vert); + return (_a < 0) || (_b < 0) || (_a >= _vm->_barriers[_vm->_now]._horz) || + (_b >= _vm->_barriers[_vm->_now]._vert); } Cluster XZ(int x, int y) { From 2178d64cbe795ab839ecac3bdbb4d7dd0bf647bd Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Fri, 19 Aug 2011 14:54:34 +0200 Subject: [PATCH 220/276] CGE: Endian-swap the contents of block descriptions. --- engines/cge/bitmap.cpp | 18 +++++++++--------- engines/cge/talk.cpp | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index df68491bd5e..ddab57eec8d 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -106,16 +106,16 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) // + room for wash table assert(v != NULL); - *(uint16 *) v = kBmpCPY | dsiz; // data chunk hader + *(uint16 *) v = TO_LE_16(kBmpCPY | dsiz); // data chunk hader memset(v + 2, fill, dsiz); // data bytes - *(uint16 *)(v + lsiz - 2) = kBmpSKP | ((kScrWidth / 4) - dsiz); // gap + *(uint16 *)(v + lsiz - 2) = TO_LE_16(kBmpSKP | ((kScrWidth / 4) - dsiz)); // gap // Replicate lines byte *destP; for (destP = v + lsiz; destP < (v + psiz); destP += lsiz) Common::copy(v, v + lsiz, destP); - *(uint16 *)(v + psiz - 2) = kBmpEOI; // plane trailer uint16 + *(uint16 *)(v + psiz - 2) = TO_LE_16(kBmpEOI); // plane trailer uint16 // Repliccate planes for (destP = v + psiz; destP < (v + 4 * psiz); destP += psiz) @@ -239,7 +239,7 @@ BitmapPtr Bitmap::code() { if ((pix == kPixelTransp) != skip || cnt >= 0x3FF0) { // end of block cnt |= (skip) ? kBmpSKP : kBmpCPY; if (_v) - *cp = cnt; // store block description uint16 + *cp = TO_LE_16(cnt); // store block description uint16 cp = (uint16 *) im; im += 2; @@ -261,7 +261,7 @@ BitmapPtr Bitmap::code() { } else { cnt |= kBmpCPY; if (_v) - *cp = cnt; + *cp = TO_LE_16(cnt); cp = (uint16 *) im; im += 2; @@ -273,13 +273,13 @@ BitmapPtr Bitmap::code() { if (cnt && ! skip) { cnt |= kBmpCPY; if (_v) - *cp = cnt; + *cp = TO_LE_16(cnt); cp = (uint16 *) im; im += 2; } if (_v) - *cp = kBmpEOI; + *cp = TO_LE_16(kBmpEOI); cp = (uint16 *) im; im += 2; } @@ -326,7 +326,7 @@ bool Bitmap::solidAt(int16 x, int16 y) { while (r) { uint16 w, t; - w = *(uint16 *) m; + w = READ_LE_UINT16(m); m += 2; t = w & 0xC000; w &= 0x3FFF; @@ -347,7 +347,7 @@ bool Bitmap::solidAt(int16 x, int16 y) { while (true) { uint16 w, t; - w = *(uint16 *) m; + w = READ_LE_UINT16(m); m += 2; t = w & 0xC000; w &= 0x3FFF; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index db44536267f..88949dbfc0d 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -276,7 +276,7 @@ void InfoLine::update(const char *text) { for (pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz) { Common::copy(v, v + lsiz, pDest); } - *(uint16 *)(v + psiz - 2) = kBmpEOI; // plane trailer uint16 + *(uint16 *)(v + psiz - 2) = TO_LE_16(kBmpEOI); // plane trailer uint16 for (pDest = v + psiz; pDest < (v + 4 * psiz); pDest += psiz) { Common::copy(v, v + psiz, pDest); } From 43a41f5380228c62959374750667dadd175ea5ad Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Fri, 19 Aug 2011 14:55:44 +0200 Subject: [PATCH 221/276] CGE: Endian-swap VBM headers on load if needed. --- engines/cge/bitmap.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index ddab57eec8d..e4978287885 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -407,15 +407,19 @@ bool Bitmap::loadVBM(XFile *f) { uint16 p = 0, n = 0; if (f->_error == 0) f->read((uint8 *)&p, sizeof(p)); + p = FROM_LE_16(p); if (f->_error == 0) f->read((uint8 *)&n, sizeof(n)); + n = FROM_LE_16(n); if (f->_error == 0) f->read((uint8 *)&_w, sizeof(_w)); + _w = FROM_LE_16(_w); if (f->_error == 0) f->read((uint8 *)&_h, sizeof(_h)); + _h = FROM_LE_16(_h); if (f->_error == 0) { if (p) { From 4e4062806b1b1d80e98f7935e911249a458eadc8 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Fri, 19 Aug 2011 15:55:27 +0200 Subject: [PATCH 222/276] CGE: Portability fix for syncing sprite flags. --- engines/cge/vga13h.cpp | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index ad2415caafd..7e4daeb8985 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -545,7 +545,48 @@ void Sprite::sync(Common::Serializer &s) { s.syncAsUint16LE(unused); // _ext s.syncAsUint16LE(_ref); s.syncAsByte(_cave); - s.syncBytes((byte *)&_flags, 2); + + // bitfield in-memory storage is unpredictable, so to avoid + // any issues, pack/unpack everything manually + uint16 flags = 0; + if (s.isLoading()) { + s.syncAsUint16LE(flags); + _flags._hide = flags & 0x0001 ? true : false; + _flags._near = flags & 0x0002 ? true : false; + _flags._drag = flags & 0x0004 ? true : false; + _flags._hold = flags & 0x0008 ? true : false; + _flags._____ = flags & 0x0010 ? true : false; + _flags._slav = flags & 0x0020 ? true : false; + _flags._syst = flags & 0x0040 ? true : false; + _flags._kill = flags & 0x0080 ? true : false; + _flags._xlat = flags & 0x0100 ? true : false; + _flags._port = flags & 0x0200 ? true : false; + _flags._kept = flags & 0x0400 ? true : false; + _flags._east = flags & 0x0800 ? true : false; + _flags._shad = flags & 0x1000 ? true : false; + _flags._back = flags & 0x2000 ? true : false; + _flags._bDel = flags & 0x4000 ? true : false; + _flags._tran = flags & 0x8000 ? true : false; + } else { + flags = (flags << 1) | _flags._tran; + flags = (flags << 1) | _flags._bDel; + flags = (flags << 1) | _flags._back; + flags = (flags << 1) | _flags._shad; + flags = (flags << 1) | _flags._east; + flags = (flags << 1) | _flags._kept; + flags = (flags << 1) | _flags._port; + flags = (flags << 1) | _flags._xlat; + flags = (flags << 1) | _flags._kill; + flags = (flags << 1) | _flags._syst; + flags = (flags << 1) | _flags._slav; + flags = (flags << 1) | _flags._____; + flags = (flags << 1) | _flags._hold; + flags = (flags << 1) | _flags._drag; + flags = (flags << 1) | _flags._near; + flags = (flags << 1) | _flags._hide; + s.syncAsUint16LE(flags); + } + s.syncAsUint16LE(_x); s.syncAsUint16LE(_y); s.syncAsByte(_z); From 65cd0689c7f23dde33b7c8c5328b5dd3b21c7171 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Fri, 19 Aug 2011 15:56:03 +0200 Subject: [PATCH 223/276] CGE: Remove (empty) ems.cpp. --- engines/cge/ems.cpp | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 engines/cge/ems.cpp diff --git a/engines/cge/ems.cpp b/engines/cge/ems.cpp deleted file mode 100644 index f545822a6b7..00000000000 --- a/engines/cge/ems.cpp +++ /dev/null @@ -1,31 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/general.h" - -namespace CGE { -} // End of namespace CGE From f0889d3f5492a71293d789b5ffb9752c90c9b6f8 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Fri, 19 Aug 2011 16:01:51 +0200 Subject: [PATCH 224/276] CGE: Remove unused snSelect function, and broken config.cpp. --- engines/cge/cge.h | 1 - engines/cge/cge_main.cpp | 1 - engines/cge/config.cpp | 47 ---------------------------------------- engines/cge/config.h | 35 ------------------------------ engines/cge/module.mk | 1 - engines/cge/snail.cpp | 2 +- 6 files changed, 1 insertion(+), 86 deletions(-) delete mode 100644 engines/cge/config.cpp delete mode 100644 engines/cge/config.h diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 8aff3334a06..1c5e680901b 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -243,7 +243,6 @@ public: void snRelZ(Sprite *spr, int z); void snRNNext(Sprite *spr, int p); void snRTNext(Sprite *spr, int p); - void snSelect(); void snSend(Sprite *spr, int val); void snRelX(Sprite *spr, int x); void snRelY(Sprite *spr, int y); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 5b98b0a4e8c..39e65370e81 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -36,7 +36,6 @@ #include "graphics/thumbnail.h" #include "cge/general.h" #include "cge/sound.h" -#include "cge/config.h" #include "cge/vga13h.h" #include "cge/snail.h" #include "cge/text.h" diff --git a/engines/cge/config.cpp b/engines/cge/config.cpp deleted file mode 100644 index b1cc5769d8d..00000000000 --- a/engines/cge/config.cpp +++ /dev/null @@ -1,47 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/config.h" -#include "cge/sound.h" -#include "cge/vmenu.h" -#include "cge/text.h" -#include "cge/cge_main.h" - -namespace CGE { - -static Choice *_cho; -static int _hlp; - -void CGEEngine::snSelect() { - debugC(1, kCGEDebugEngine, "CGEEngine::snSelect()"); - - inf(_text->getText(_hlp)); - _talk->gotoxy(_talk->_x, kFontHigh / 2); - (new Vmenu(this, _cho, kScrWidth / 2, _talk->_y + _talk->_h + kTextVMargin + kFontHigh))->setName(_text->getText(kMenu)); -} - -} // End of namespace CGE diff --git a/engines/cge/config.h b/engines/cge/config.h deleted file mode 100644 index 5ea677b97d6..00000000000 --- a/engines/cge/config.h +++ /dev/null @@ -1,35 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __CGE_CONFIG__ -#define __CGE_CONFIG__ - -namespace CGE { - #define kMenu 56 -} // End of namespace CGE - -#endif diff --git a/engines/cge/module.mk b/engines/cge/module.mk index 8829883e263..3ea061419b6 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -6,7 +6,6 @@ MODULE_OBJS := \ cfile.o \ cge.o \ cge_main.o \ - config.o \ console.o \ detection.o \ events.o \ diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 6a5556ca58c..ea8e480b350 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -1141,7 +1141,7 @@ void Snail::runCom() { warning("TODO: Select sound card"); break; case kSnSelect: - _vm->snSelect(); + warning("TODO: Sound card selection"); break; case kSndSetVolume: sndSetVolume(); From 4e156b24635c3cb44d46dde7a01f97fb2fe4a552 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Fri, 19 Aug 2011 16:04:10 +0200 Subject: [PATCH 225/276] CGE: Mass re-style/cleanup. --- engines/cge/bitmap.cpp | 68 ++++----- engines/cge/cfile.cpp | 18 +-- engines/cge/cge_main.cpp | 319 +++++++++++++++++++-------------------- engines/cge/events.cpp | 6 +- engines/cge/events.h | 1 - engines/cge/game.cpp | 22 +-- engines/cge/game.h | 9 +- engines/cge/general.cpp | 32 ++-- engines/cge/gettext.cpp | 14 +- engines/cge/mixer.cpp | 17 +-- engines/cge/talk.cpp | 204 ++++++++++++------------- engines/cge/text.cpp | 184 +++++++++++----------- engines/cge/vmenu.cpp | 68 ++++----- engines/cge/vol.cpp | 3 - engines/cge/walk.cpp | 64 ++++---- engines/cge/walk.h | 1 - 16 files changed, 493 insertions(+), 537 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index e4978287885..08296009027 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -81,14 +81,12 @@ Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { } } - Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL), _map(0) { debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(%d, %d, map)", w, h); if (map) code(); } - // following routine creates filled rectangle // immediately as VGA video chunks, in near memory as fast as possible, // especially for text line real time display @@ -134,20 +132,19 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) _b = b; } - Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), _map(0) { debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(bmp)"); uint8 *v0 = bmp._v; - if (v0) { - uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); - uint16 siz = vsiz + _h * sizeof(HideDesc); - uint8 *v1 = new uint8[siz]; - assert(v1 != NULL); - memcpy(v1, v0, siz); - _b = (HideDesc *)((_v = v1) + vsiz); - } -} + if (!v0) + return; + uint16 vsiz = (uint8 *)(bmp._b) - (uint8 *)(v0); + uint16 siz = vsiz + _h * sizeof(HideDesc); + uint8 *v1 = new uint8[siz]; + assert(v1 != NULL); + memcpy(v1, v0, siz); + _b = (HideDesc *)((_v = v1) + vsiz); +} Bitmap::~Bitmap() { debugC(6, kCGEDebugBitmap, "Bitmap::~Bitmap()"); @@ -156,7 +153,6 @@ Bitmap::~Bitmap() { delete[] _v; } - Bitmap &Bitmap::operator = (const Bitmap &bmp) { debugC(1, kCGEDebugBitmap, "&Bitmap::operator ="); @@ -166,9 +162,10 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { _m = NULL; _map = 0; delete[] _v; - if (v0 == NULL) + + if (v0 == NULL) { _v = NULL; - else { + } else { uint16 vsiz = (uint8 *)bmp._b - (uint8 *)v0; uint16 siz = vsiz + _h * sizeof(HideDesc); uint8 *v1 = (uint8 *) malloc(sizeof(uint8) * siz); @@ -179,21 +176,19 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { return *this; } - uint16 Bitmap::moveVmap(uint8 *buf) { debugC(1, kCGEDebugBitmap, "Bitmap::moveVmap(buf)"); - if (_v) { - uint16 vsiz = (uint8 *)_b - (uint8 *)_v; - uint16 siz = vsiz + _h * sizeof(HideDesc); - memcpy(buf, _v, siz); - delete[] _v; - _b = (HideDesc *)((_v = buf) + vsiz); - return siz; - } - return 0; -} + if (!_v) + return 0; + uint16 vsiz = (uint8 *)_b - (uint8 *)_v; + uint16 siz = vsiz + _h * sizeof(HideDesc); + memcpy(buf, _v, siz); + delete[] _v; + _b = (HideDesc *)((_v = buf) + vsiz); + return siz; +} BitmapPtr Bitmap::code() { debugC(1, kCGEDebugBitmap, "Bitmap::code()"); @@ -201,7 +196,7 @@ BitmapPtr Bitmap::code() { if (!_m) return false; - uint16 i, cnt; + uint16 cnt; if (_v) { // old X-map exists, so remove it delete[] _v; @@ -214,7 +209,7 @@ BitmapPtr Bitmap::code() { int bpl; if (_v) { // 2nd pass - fill the hide table - for (i = 0; i < _h; i++) { + for (uint16 i = 0; i < _h; i++) { _b[i]._skip = 0xFFFF; _b[i]._hide = 0x0000; } @@ -225,7 +220,7 @@ BitmapPtr Bitmap::code() { uint16 j; cnt = 0; - for (i = 0; i < _h; i++) { // once per each line + for (uint16 i = 0; i < _h; i++) { // once per each line uint8 pix; for (j = bpl; j < _w; j += 4) { pix = bm[j]; @@ -293,7 +288,7 @@ BitmapPtr Bitmap::code() { _b = (HideDesc *)(_v + sizV); } cnt = 0; - for (i = 0; i < _h; i++) { + for (uint16 i = 0; i < _h; i++) { if (_b[i]._skip == 0xFFFF) { // whole line is skipped _b[i]._skip = (cnt + kScrWidth) >> 2; cnt = 0; @@ -309,19 +304,16 @@ BitmapPtr Bitmap::code() { return this; } - bool Bitmap::solidAt(int16 x, int16 y) { debugC(6, kCGEDebugBitmap, "Bitmap::solidAt(%d, %d)", x, y); - uint8 *m; - uint16 r, n, n0; - if ((x >= _w) || (y >= _h)) return false; - m = _v; - r = static_cast(x) % 4; - n0 = (kScrWidth * y + x) / 4, n = 0; + uint8 *m = _v; + uint16 r = static_cast(x) % 4; + uint16 n0 = (kScrWidth * y + x) / 4; + uint16 n = 0; while (r) { uint16 w, t; @@ -372,7 +364,6 @@ bool Bitmap::solidAt(int16 x, int16 y) { } } - bool Bitmap::saveVBM(XFile *f) { debugC(1, kCGEDebugBitmap, "Bitmap::saveVBM(f)"); @@ -400,7 +391,6 @@ bool Bitmap::saveVBM(XFile *f) { return (f->_error == 0); } - bool Bitmap::loadVBM(XFile *f) { debugC(5, kCGEDebugBitmap, "Bitmap::loadVBM(f)"); diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index c6144f624ba..c5c2c2c19c3 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -44,7 +44,6 @@ IoBuf::IoBuf(IOMode mode, Crypt *crypt) assert(_buff != NULL); } - IoBuf::IoBuf(const char *name, IOMode mode, Crypt *crypt) : IoHand(name, mode, crypt), _bufMark(0), @@ -64,7 +63,6 @@ IoBuf::~IoBuf() { free(_buff); } - void IoBuf::readBuf() { debugC(4, kCGEDebugFile, "IoBuf::readBuf()"); @@ -73,7 +71,6 @@ void IoBuf::readBuf() { _ptr = 0; } - void IoBuf::writeBuf() { debugC(4, kCGEDebugFile, "IoBuf::writeBuf()"); @@ -84,7 +81,6 @@ void IoBuf::writeBuf() { } } - uint16 IoBuf::read(void *buf, uint16 len) { debugC(4, kCGEDebugFile, "IoBuf::read(buf, %d)", len); @@ -107,7 +103,6 @@ uint16 IoBuf::read(void *buf, uint16 len) { return total; } - uint16 IoBuf::read(uint8 *buf) { debugC(3, kCGEDebugFile, "IoBuf::read(buf)"); @@ -154,7 +149,6 @@ uint16 IoBuf::read(uint8 *buf) { return total; } - uint16 IoBuf::write(void *buf, uint16 len) { debugC(1, kCGEDebugFile, "IoBuf::write(buf, %d)", len); @@ -175,7 +169,6 @@ uint16 IoBuf::write(void *buf, uint16 len) { return tot; } - uint16 IoBuf::write(uint8 *buf) { debugC(1, kCGEDebugFile, "IoBuf::write(buf)"); @@ -195,7 +188,6 @@ uint16 IoBuf::write(uint8 *buf) { return len; } - int IoBuf::read() { debugC(1, kCGEDebugFile, "IoBuf::read()"); @@ -207,7 +199,6 @@ int IoBuf::read() { return _buff[_ptr++]; } - void IoBuf::write(uint8 b) { debugC(1, kCGEDebugFile, "IoBuf::write(%d)", b); @@ -216,20 +207,16 @@ void IoBuf::write(uint8 b) { _buff[_lim++] = b; } - -uint16 CFile::_maxLineLen = kLineMaxSize; - +uint16 CFile::_maxLineLen = kLineMaxSize; CFile::CFile(const char *name, IOMode mode, Crypt *crypt) : IoBuf(name, mode, crypt) { debugC(1, kCGEDebugFile, "CFile::CFile(%s, %d, crypt)", name, mode); } - CFile::~CFile() { } - void CFile::flush() { debugC(1, kCGEDebugFile, "CFile::flush()"); @@ -246,14 +233,12 @@ void CFile::flush() { warning("FIXME: CFILE::Flush"); } - long CFile::mark() { debugC(5, kCGEDebugFile, "CFile::mark()"); return _bufMark + ((_mode != kModeRead) ? _lim : _ptr); } - long CFile::seek(long pos) { debugC(1, kCGEDebugFile, "CFile::seek(%ld)", pos); @@ -271,7 +256,6 @@ long CFile::seek(long pos) { } } - void CFile::append(CFile &f) { debugC(1, kCGEDebugFile, "CFile::append(f)"); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 39e65370e81..91de45e4479 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -88,8 +88,8 @@ const char *savegameStr = "SCUMMVM_CGE"; //-------------------------------------------------------------------------- -static bool _finis = false; -int _offUseCount; +static bool _finis = false; +int _offUseCount; extern Dac _stdPal[58]; @@ -255,7 +255,6 @@ Common::Error CGEEngine::saveGameState(int slot, const Common::String &desc) { return Common::kNoError; } - void CGEEngine::saveSound() { warning("STUB: CGEEngine::saveSound"); /* Convert to saving any such needed data in ScummVM configuration file @@ -317,13 +316,10 @@ void CGEEngine::writeSavegameHeader(Common::OutSaveFile *out, SavegameHeader &he } void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream, bool tiny) { - Sprite *spr; - int i; - Common::Serializer s(readStream, writeStream); if (s.isSaving()) { - for (i = 0; i < kPocketNX; i++) { + for (int i = 0; i < kPocketNX; i++) { register Sprite *pocSpr = _pocket[i]; _pocref[i] = (pocSpr) ? pocSpr->_ref : -1; } @@ -340,7 +336,7 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt if (s.isSaving()) { // Loop through saving the sprite data - for (spr = _vga->_spareQ->first(); spr; spr = spr->_next) { + for (Sprite *spr = _vga->_spareQ->first(); spr; spr = spr->_next) { if ((spr->_ref >= 1000) && !s.err()) spr->sync(s); } @@ -359,14 +355,14 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt S.sync(s); S._prev = S._next = NULL; - spr = (scumm_stricmp(S._file + 2, "MUCHA") == 0) ? new Fly(this, NULL) + Sprite *spr = (scumm_stricmp(S._file + 2, "MUCHA") == 0) ? new Fly(this, NULL) : new Sprite(this, NULL); assert(spr != NULL); *spr = S; _vga->_spareQ->append(spr); } - for (i = 0; i < kPocketNX; i++) { + for (int i = 0; i < kPocketNX; i++) { register int r = _pocref[i]; _pocket[i] = (r < 0) ? NULL : _vga->_spareQ->locate(r); } @@ -482,7 +478,6 @@ Square::Square(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { setShapeList(MB); } - void Square::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); if (mask & kMouseLeftUp) { @@ -491,7 +486,6 @@ void Square::touch(uint16 mask, int x, int y) { } } - void CGEEngine::setMapBrick(int x, int z) { debugC(1, kCGEDebugEngine, "CGEEngine::setMapBrick(%d, %d)", x, z); @@ -513,7 +507,6 @@ void CGEEngine::keyClick() { _snail_->addCom(kSnSound, -1, 5, NULL); } - void CGEEngine::resetQSwitch() { debugC(1, kCGEDebugEngine, "CGEEngine::resetQSwitch()"); @@ -521,7 +514,6 @@ void CGEEngine::resetQSwitch() { keyClick(); } - void CGEEngine::quit() { debugC(1, kCGEDebugEngine, "CGEEngine::quit()"); @@ -545,7 +537,6 @@ void CGEEngine::quit() { } } - void CGEEngine::AltCtrlDel() { debugC(1, kCGEDebugEngine, "CGEEngine::AltCtrlDel()"); @@ -577,21 +568,22 @@ void CGEEngine::showBak(int ref) { debugC(1, kCGEDebugEngine, "CGEEngine::showBack(%d)", ref); Sprite *spr = _vga->_spareQ->locate(ref); - if (spr) { - Bitmap::_pal = Vga::_sysPal; - spr->expand(); - Bitmap::_pal = NULL; - spr->show(2); - _vga->copyPage(1, 2); - _sys->setPal(); - spr->contract(); - } + if (!spr) + return; + + Bitmap::_pal = Vga::_sysPal; + spr->expand(); + Bitmap::_pal = NULL; + spr->show(2); + _vga->copyPage(1, 2); + _sys->setPal(); + spr->contract(); } void CGEEngine::caveUp() { debugC(1, kCGEDebugEngine, "CGEEngine::caveUp()"); - int BakRef = 1000 * _now; + const int BakRef = 1000 * _now; if (_music) _midiPlayer.loadMidi(_now); @@ -652,11 +644,10 @@ void CGEEngine::caveUp() { void CGEEngine::caveDown() { debugC(1, kCGEDebugEngine, "CGEEngine::caveDown()"); - Sprite *spr; if (_horzLine && !_horzLine->_flags._hide) switchMapping(); - for (spr = _vga->_showQ->first(); spr;) { + for (Sprite *spr = _vga->_showQ->first(); spr;) { Sprite *n = spr->_next; if (spr->_ref >= 1000 /*&& spr->_cave*/) { if (spr->_ref % 1000 == 999) @@ -689,31 +680,31 @@ void CGEEngine::qGame() { _finis = true; } - void CGEEngine::switchCave(int cav) { debugC(1, kCGEDebugEngine, "CGEEngine::switchCave(%d)", cav); - if (cav != _now) { - if (cav < 0) { - _snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint - _snail->addCom2(kSnExec, -1, 0, kQGame); // switch cave - } else { - _now = cav; - _mouse->off(); - if (_hero) { - _hero->park(); - _hero->step(0); - if (!_isDemo) - _vga->_spareQ->_show = 0; - } - _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, - kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); - killText(); - if (!_startupMode) - keyClick(); - _snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint - _snail->addCom2(kSnExec, 0, 0, kXCave); // switch cave + if (cav == _now) + return; + + if (cav < 0) { + _snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint + _snail->addCom2(kSnExec, -1, 0, kQGame); // switch cave + } else { + _now = cav; + _mouse->off(); + if (_hero) { + _hero->park(); + _hero->step(0); + if (!_isDemo) + _vga->_spareQ->_show = 0; } + _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, + kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); + killText(); + if (!_startupMode) + keyClick(); + _snail->addCom(kSnLabel, -1, 0, NULL); // wait for repaint + _snail->addCom2(kSnExec, 0, 0, kXCave); // switch cave } } @@ -724,9 +715,8 @@ System::System(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { } void System::setPal() { - uint i; Dac *p = Vga::_sysPal + 256 - ArrayCount(_stdPal); - for (i = 0; i < ArrayCount(_stdPal); i++) { + for (uint i = 0; i < ArrayCount(_stdPal); i++) { p[i]._r = _stdPal[i]._r >> 2; p[i]._g = _stdPal[i]._g >> 2; p[i]._b = _stdPal[i]._b >> 2; @@ -918,9 +908,9 @@ void CGEEngine::switchMusic() { debugC(1, kCGEDebugEngine, "CGEEngine::switchMusic()"); if (_keyboard->_key[kKeyAlt]) { - if (Vmenu::_addr) + if (Vmenu::_addr) { _snail_->addCom(kSnKill, -1, 0, Vmenu::_addr); - else { + } else { _snail_->addCom(kSnSeq, 122, (_music = false), NULL); _snail->addCom2(kSnExec, -1, 0, kSelectSound); } @@ -944,9 +934,9 @@ void CGEEngine::startCountDown() { void CGEEngine::takeName() { debugC(1, kCGEDebugEngine, "CGEEngine::takeName()"); - if (GetText::_ptr) + if (GetText::_ptr) { _snail_->addCom(kSnKill, -1, 0, GetText::_ptr); - else { + } else { memset(_usrFnam, 0, 15); GetText *tn = new GetText(this, _text->getText(kGetNamePrompt), _usrFnam, 8); if (tn) { @@ -964,17 +954,14 @@ void CGEEngine::switchMapping() { debugC(1, kCGEDebugEngine, "CGEEngine::switchMapping()"); if (_horzLine && _horzLine->_flags._hide) { - int i; - for (i = 0; i < kMapZCnt; i++) { - int j; - for (j = 0; j < kMapXCnt; j++) { + for (int i = 0; i < kMapZCnt; i++) { + for (int j = 0; j < kMapXCnt; j++) { if (Cluster::_map[i][j]) setMapBrick(j, i); } } } else { - Sprite *s; - for (s = _vga->_showQ->first(); s; s = s->_next) + for (Sprite *s = _vga->_showQ->first(); s; s = s->_next) if (s->_w == kMapGridX && s->_h == kMapGridZ) _snail_->addCom(kSnKill, -1, 0, s); } @@ -1084,104 +1071,109 @@ void CGEEngine::sayDebug() { } } - void CGEEngine::switchDebug() { _debugLine->_flags._hide = !_debugLine->_flags._hide; } - void CGEEngine::optionTouch(int opt, uint16 mask) { switch (opt) { - case 1 : + case 1: if (mask & kMouseLeftUp) switchColorMode(); break; - case 2 : - if (mask & kMouseLeftUp) + case 2: + if (mask & kMouseLeftUp) { switchMusic(); - else if (mask & kMouseRightUp) + } else if (mask & kMouseRightUp) if (!Mixer::_appear) { Mixer::_appear = true; new Mixer(this, kButtonX, kButtonY); } break; - case 3 : + case 3: if (mask & kMouseLeftUp) quit(); break; } } - #pragma argsused void Sprite::touch(uint16 mask, int x, int y) { _sys->funTouch(); - if ((mask & kEventAttn) == 0) { - _infoLine->update(name()); - if (mask & (kMouseRightDown | kMouseLeftDown)) - _sprite = this; - if (_ref / 10 == 12) { - _vm->optionTouch(_ref % 10, mask); - return; + + if ((mask & kEventAttn) != 0) + return; + + _infoLine->update(name()); + + if (mask & (kMouseRightDown | kMouseLeftDown)) + _sprite = this; + + if (_ref / 10 == 12) { + _vm->optionTouch(_ref % 10, mask); + return; + } + + if (_flags._syst) + return; // cannot access system sprites + + if (_vm->_game) + if (mask & kMouseLeftUp) { + mask &= ~kMouseLeftUp; + mask |= kMouseRightUp; } - if (_flags._syst) - return; // cannot access system sprites - if (_vm->_game) if (mask & kMouseLeftUp) { - mask &= ~kMouseLeftUp; - mask |= kMouseRightUp; - } - if ((mask & kMouseRightUp) && _snail->idle()) { - Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_vm->_pocPtr] : NULL; - if (ps) { - if (_flags._kept || _hero->distance(this) < kDistMax) { - if (works(ps)) { - _vm->feedSnail(ps, kTake); - } else - _vm->offUse(); - _vm->selectPocket(-1); + + if ((mask & kMouseRightUp) && _snail->idle()) { + Sprite *ps = (_pocLight->_seqPtr) ? _pocket[_vm->_pocPtr] : NULL; + if (ps) { + if (_flags._kept || _hero->distance(this) < kDistMax) { + if (works(ps)) { + _vm->feedSnail(ps, kTake); } else - _vm->tooFar(); + _vm->offUse(); + _vm->selectPocket(-1); + } else + _vm->tooFar(); + } else { + if (_flags._kept) { + mask |= kMouseLeftUp; } else { - if (_flags._kept) - mask |= kMouseLeftUp; - else { - if (_hero->distance(this) < kDistMax) { - /// - if (_flags._port) { - if (_vm->findPocket(NULL) < 0) - _vm->pocFul(); - else { - _snail->addCom(kSnReach, -1, -1, this); - _snail->addCom(kSnKeep, -1, -1, this); - _flags._port = false; - } - } else { - if (_takePtr != NO_PTR) { - if (snList(kTake)[_takePtr]._com == kSnNext) - _vm->offUse(); - else - _vm->feedSnail(this, kTake); - } else - _vm->offUse(); + if (_hero->distance(this) < kDistMax) { + /// + if (_flags._port) { + if (_vm->findPocket(NULL) < 0) + _vm->pocFul(); + else { + _snail->addCom(kSnReach, -1, -1, this); + _snail->addCom(kSnKeep, -1, -1, this); + _flags._port = false; } - }/// - else - _vm->tooFar(); - } + } else { + if (_takePtr != NO_PTR) { + if (snList(kTake)[_takePtr]._com == kSnNext) + _vm->offUse(); + else + _vm->feedSnail(this, kTake); + } else + _vm->offUse(); + } + }/// + else + _vm->tooFar(); } } - if ((mask & kMouseLeftUp) && _snail->idle()) { - if (_flags._kept) { - int n; - for (n = 0; n < kPocketNX; n++) { - if (_pocket[n] == this) { - _vm->selectPocket(n); - break; - } + } + + if ((mask & kMouseLeftUp) && _snail->idle()) { + if (_flags._kept) { + for (int n = 0; n < kPocketNX; n++) { + if (_pocket[n] == this) { + _vm->selectPocket(n); + break; } - } else - _snail->addCom(kSnWalk, -1, -1, this); // Hero->FindWay(this); - } + } + } else + _snail->addCom(kSnWalk, -1, -1, this); // Hero->FindWay(this); } } @@ -1196,7 +1188,6 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int static const char *Type[] = { "DEAD", "AUTO", "WALK", "NEWTON", "LISSAJOUS", "FLY", NULL }; - char line[kLineMax]; int shpcnt = 0; int type = 0; // DEAD @@ -1204,14 +1195,16 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int bool port = false; bool tran = false; int i, lcnt = 0; - uint16 len; + char line[kLineMax]; mergeExt(line, fname, SPR_EXT); + if (INI_FILE::exist(line)) { // sprite description file exist INI_FILE sprf(line); if (sprf._error) error("Bad SPR [%s]", line); + uint16 len; while ((len = sprf.read((uint8 *)line)) != 0) { lcnt++; if (len && line[len - 1] == '\n') @@ -1252,15 +1245,16 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int // make sprite of choosen type switch (type) { - case 1 : { // AUTO + case 1: + // AUTO _sprite = new Sprite(this, NULL); if (_sprite) { _sprite->gotoxy(col, row); //Sprite->Time = 1;//-----------$$$$$$$$$$$$$$$$ } break; - } - case 2 : { // WALK + case 2: + { // WALK Walk *w = new Walk(this, NULL); if (w && ref == 1) { w->gotoxy(col, row); @@ -1270,7 +1264,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int } _sprite = w; break; - } + } /* case 3 : // NEWTON NEWTON * n = new NEWTON(NULL); @@ -1286,7 +1280,8 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int _sprite = n; break; */ - case 4 : { // LISSAJOUS + case 4: + // LISSAJOUS error("Bad type [%s]", fname); /* LISSAJOUS * l = new LISSAJOUS(NULL); @@ -1304,20 +1299,21 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int _sprite = l; */ break; - } - case 5 : { // FLY + case 5: + { // FLY Fly *f = new Fly(this, NULL); _sprite = f; //////Sprite->Time = 1;//-----------$$$$$$$$$$$$$$ break; - } - default: { // DEAD + } + default: + // DEAD _sprite = new Sprite(this, NULL); if (_sprite) _sprite->gotoxy(col, row); break; } - } + if (_sprite) { _sprite->_ref = ref; _sprite->_cave = cav; @@ -1339,19 +1335,16 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int } } - void CGEEngine::loadScript(const char *fname) { - char line[kLineMax]; - char *SpN; - int SpI, SpA, SpX, SpY, SpZ; - bool BkG = false; INI_FILE scrf(fname); - int lcnt = 0; - bool ok = true; if (scrf._error) return; + bool ok = true; + int lcnt = 0; + + char line[kLineMax]; while (scrf.read((uint8 *)line) != 0) { char *p; @@ -1360,33 +1353,41 @@ void CGEEngine::loadScript(const char *fname) { continue; ok = false; // not OK if break + // sprite ident number if ((p = strtok(line, " \t\n")) == NULL) break; - SpI = atoi(p); + int SpI = atoi(p); + // sprite file name + char *SpN; if ((SpN = strtok(NULL, " ,;/\t\n")) == NULL) break; + // sprite cave if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpA = atoi(p); + int SpA = atoi(p); + // sprite column if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpX = atoi(p); + int SpX = atoi(p); + // sprite row if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpY = atoi(p); + int SpY = atoi(p); + // sprite Z pos if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - SpZ = atoi(p); + int SpZ = atoi(p); + // sprite life if ((p = strtok(NULL, " ,;/\t\n")) == NULL) break; - BkG = atoi(p) == 0; + bool BkG = atoi(p) == 0; ok = true; // no break: OK @@ -1395,7 +1396,8 @@ void CGEEngine::loadScript(const char *fname) { if (_sprite && BkG) _sprite->_flags._back = true; } - if (! ok) + + if (!ok) error("Bad INI line %d [%s]", lcnt, fname); } @@ -1469,15 +1471,14 @@ void CGEEngine::loadUser() { // user .SVG file found - load it from slot 0 loadGame(0, NULL); } else if (_mode == 1) { - // Load either initial game state savegame or launcher specified savegame - loadGame(_startGameSlot, NULL); + // Load either initial game state savegame or launcher specified savegame + loadGame(_startGameSlot, NULL); } else { - error("Creating setup savegames not supported"); + error("Creating setup savegames not supported"); } loadScript(progName(kIn0Ext)); } - void CGEEngine::runGame() { if (_eventManager->_quitFlag) return; @@ -1601,7 +1602,6 @@ void CGEEngine::runGame() { _shadow = NULL; } - void CGEEngine::movie(const char *ext) { if (_eventManager->_quitFlag) return; @@ -1624,7 +1624,6 @@ void CGEEngine::movie(const char *ext) { } } - bool CGEEngine::showTitle(const char *name) { if (_eventManager->_quitFlag) return false; @@ -1634,7 +1633,6 @@ bool CGEEngine::showTitle(const char *name) { LB[0] = new Bitmap(name, true); LB[1] = NULL; Bitmap::_pal = NULL; - bool userOk = false; Sprite D(this, LB); D._flags._kill = true; @@ -1672,6 +1670,7 @@ bool CGEEngine::showTitle(const char *name) { _midiPlayer.loadMidi(0); } + bool userOk = false; if (_mode < 2) { if (_isDemo) { strcpy(_usrFnam, progName(kSvgExt)); diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 916de839ebb..342a0a8cb17 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -184,7 +184,6 @@ Mouse::~Mouse() { off(); } - void Mouse::on() { if (_seqPtr && _exist) { _active = true; @@ -194,7 +193,6 @@ void Mouse::on() { } } - void Mouse::off() { if (_seqPtr == 0) { if (_exist) { @@ -332,8 +330,7 @@ void EventManager::handleEvents() { void EventManager::clearEvent(Sprite *spr) { if (spr) { - uint16 e; - for (e = _eventQueueTail; e != _eventQueueHead; e = (e + 1) % kEventMax) + for (uint16 e = _eventQueueTail; e != _eventQueueHead; e = (e + 1) % kEventMax) if (_eventQueue[e]._spritePtr == spr) _eventQueue[e]._mask = 0; } else @@ -346,4 +343,5 @@ CGEEvent &EventManager::getNextEvent() { return evt; } + } // End of namespace CGE diff --git a/engines/cge/events.h b/engines/cge/events.h index 124597c3291..9df09fdba50 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -82,7 +82,6 @@ struct CGEEvent { Sprite *_spritePtr; }; - class Mouse : public Sprite { public: Sprite *_hold; diff --git a/engines/cge/game.cpp b/engines/cge/game.cpp index e64e4af38a2..0c4f5971bcc 100644 --- a/engines/cge/game.cpp +++ b/engines/cge/game.cpp @@ -43,7 +43,7 @@ uint8 *glass(Dac *pal, uint8 r, uint8 g, uint8 b) { return x; } -int Fly::_l = 20, +const int Fly::_l = 20, Fly::_t = 40, Fly::_r = 110, Fly::_b = 100; @@ -56,17 +56,17 @@ Fly::Fly(CGEEngine *vm, Bitmap **shpl) void Fly::tick() { step(); - if (!_flags._kept) { - if (newRandom(10) < 1) { - _tx = newRandom(3) - 1; - _ty = newRandom(3) - 1; - } - if (_x + _tx < _l || _x + _tx + _w > _r) - _tx = -_tx; - if (_y + _ty < _t || _y + _ty + _h > _b) - _ty = -_ty; - gotoxy(_x + _tx, _y + _ty); + if (_flags._kept) + return; + if (newRandom(10) < 1) { + _tx = newRandom(3) - 1; + _ty = newRandom(3) - 1; } + if (_x + _tx < _l || _x + _tx + _w > _r) + _tx = -_tx; + if (_y + _ty < _t || _y + _ty + _h > _b) + _ty = -_ty; + gotoxy(_x + _tx, _y + _ty); } } // End of namespace CGE diff --git a/engines/cge/game.h b/engines/cge/game.h index 078f3880ead..bb4f3655a21 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -32,14 +32,13 @@ namespace CGE { - uint8 *glass(Dac *pal, uint8 r, uint8 g, uint8 b); class Fly : public Sprite { - static int _l; - static int _t; - static int _r; - static int _b; + static const int _l; + static const int _t; + static const int _r; + static const int _b; public: int _tx, _ty; Fly(CGEEngine *vm, Bitmap **shpl); diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 112de730ec5..25ed7d6ff28 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -124,7 +124,7 @@ char *forceExt(char *buf, const char *name, const char *ext) { return buf; } -static unsigned Seed = 0xA5; +static unsigned Seed = 0xA5; unsigned fastRand() { return Seed = 257 * Seed + 817; @@ -157,22 +157,25 @@ uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { } uint16 atow(const char *a) { + if (!a) + return 0; + uint16 w = 0; - if (a) - while (IsDigit(*a)) - w = (10 * w) + (*(a++) & 0xF); + while (IsDigit(*a)) + w = (10 * w) + (*(a++) & 0xF); return w; } uint16 xtow(const char *x) { + if (!x) + return 0; + uint16 w = 0; - if (x) { - while (IsHxDig(*x)) { - register uint16 d = *(x++); - if (d > '9') - d -= 'A' - ('9' + 1); - w = (w << 4) | (d & 0xF); - } + while (IsHxDig(*x)) { + register uint16 d = *(x++); + if (d > '9') + d -= 'A' - ('9' + 1); + w = (w << 4) | (d & 0xF); } return w; } @@ -261,8 +264,7 @@ long IoHand::size() { } bool IoHand::exist(const char *name) { - Common::File f; - return f.exists(name); + return Common::File::exists(name); } void sndSetVolume() { @@ -298,8 +300,8 @@ DataCk::DataCk(byte *buf, int bufSize) { } DataCk::~DataCk() { - if (_buf) - free(_buf); + if (_buf) + free(_buf); } } // End of namespace CGE diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp index d96e494402a..46dacbe1ded 100644 --- a/engines/cge/gettext.cpp +++ b/engines/cge/gettext.cpp @@ -33,15 +33,14 @@ namespace CGE { GetText *GetText::_ptr = NULL; - GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) : Talk(vm), _text(text), _size(min(size, kGetTextMax)), _len(min(_size, strlen(text))), _cntr(kGetTextBlink), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { - int i = 2 * kTextHMargin + _font->width(info); _ptr = this; _mode = kTBRect; _ts = new BitmapPtr[2]; + const int i = 2 * kTextHMargin + _font->width(info); _ts[0] = box((i + 3) & ~3, 2 * kTextVMargin + 2 * kFontHigh + kTextLineSpace); _ts[1] = NULL; setShapeList(_ts); @@ -55,13 +54,11 @@ GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) tick(); } - GetText::~GetText() { _keyboard->setClient(_oldKeybClient); _ptr = NULL; } - void GetText::tick() { if (++_cntr >= kGetTextBlink) { _buff[_len] ^= (' ' ^ '_'); @@ -71,7 +68,6 @@ void GetText::tick() { _time = kGetTextTime; } - void GetText::touch(uint16 mask, int x, int y) { static char ogon[] = "•œ¥£˜ ¡"; static char bezo[] = "ACELNOSXZ"; @@ -80,7 +76,7 @@ void GetText::touch(uint16 mask, int x, int y) { if (mask & kEventKeyb) { _vm->keyClick(); switch (x) { - case Enter : + case Enter: _buff[_len] = '\0'; strcpy(_text, _buff); for (p = _text; *p; p++) { @@ -88,17 +84,17 @@ void GetText::touch(uint16 mask, int x, int y) { if (q) *p = bezo[q - ogon]; } - case Esc : + case Esc: _snail_->addCom(kSnKill, -1, 0, this); break; - case BSp : + case BSp: if (_len) { _len--; _buff[_len] = _buff[_len + 1]; _buff[_len + 1] = _buff[_len + 2]; } break; - default : + default: if (x < 'A' || x > 'Z') { if (_oldKeybClient) _oldKeybClient->touch(mask, x, y); diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index ba24f832c3e..8390647cec5 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -38,7 +38,6 @@ extern Mouse *Mouse; bool Mixer::_appear = false; - Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _vm(vm) { _appear = true; _mb[0] = new Bitmap("VOLUME", true); @@ -53,19 +52,18 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _ // slaves - uint i; Seq ls[kMixMax]; - for (i = 0; i < kMixMax; i++) { + for (uint i = 0; i < kMixMax; i++) { static char fn[] = "V00"; wtom(i, fn + 1, 10, 2); _lb[i] = new Bitmap(fn, true); ls[i]._now = ls[i]._next = i; ls[i]._dx = ls[i]._dy = ls[i]._dly = 0; } - _lb[i] = NULL; + _lb[kMixMax] = NULL; - for (i = 0; i < ArrayCount(_led); i++) { + for (uint i = 0; i < ArrayCount(_led); i++) { register Sprite *spr = new Sprite(_vm, _lb); Seq *seq = (Seq *)malloc(kMixMax * sizeof(Seq)); @@ -82,7 +80,7 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _ _led[ArrayCount(_led) - 1]->_flags._bDel = true; _vga->_showQ->insert(this); - for (i = 0; i < ArrayCount(_led); i++) + for (uint i = 0; i < ArrayCount(_led); i++) _vga->_showQ->insert(_led[i]); //--- reset balance @@ -102,7 +100,6 @@ Mixer::~Mixer() { _appear = false; } - #pragma argsused void Mixer::touch(uint16 mask, int x, int y) { Sprite::touch(mask, x, y); @@ -122,7 +119,6 @@ void Mixer::touch(uint16 mask, int x, int y) { } } - void Mixer::tick() { int x = _mouse->_x; int y = _mouse->_y; @@ -131,9 +127,9 @@ void Mixer::tick() { if (_flags._hold) touch(kMouseLeftUp, x - _x, y - _y); } else { - if (_fall) + if (_fall) { _fall--; - else { + } else { for (uint i = 0; i < ArrayCount(_led); i++) _snail_->addCom(kSnKill, -1, 0, _led[i]); _snail_->addCom(kSnKill, -1, 0, this); @@ -142,7 +138,6 @@ void Mixer::tick() { _time = kMixDelay; } - void Mixer::update() { warning("STUB: Mixer::Update"); /* diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 88949dbfc0d..4bcd5cb7156 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -32,50 +32,51 @@ #include "cge/events.h" namespace CGE { + Font::Font(const char *name) { - _map = (uint8 *) malloc(sizeof(uint8) * kMapSize); - _pos = (uint16 *) malloc(sizeof(uint16) * kPosSize); - _wid = (uint8 *) malloc(sizeof(uint8) * kWidSize); + _map = (uint8 *)malloc(kMapSize); + _pos = (uint16 *)malloc(kPosSize * sizeof(uint16)); + _wid = (uint8 *)malloc(kWidSize); + assert((_map != NULL) && (_pos != NULL) && (_wid != NULL)); mergeExt(_path, name, kFontExt); load(); } - Font::~Font() { free(_map); free(_pos); free(_wid); } - void Font::load() { INI_FILE f(_path); - if (!f._error) { - f.read(_wid, kWidSize); - if (!f._error) { - uint16 i, p = 0; - for (i = 0; i < kPosSize; i++) { - _pos[i] = p; - p += _wid[i]; - } - f.read(_map, p); - } - } -} + if (f._error) + return; + f.read(_wid, kWidSize); + if (f._error) + return; + + uint16 p = 0; + for (uint16 i = 0; i < kPosSize; i++) { + _pos[i] = p; + p += _wid[i]; + } + f.read(_map, p); +} uint16 Font::width(const char *text) { uint16 w = 0; - if (text) - while (* text) - w += _wid[(unsigned char)*(text++)]; + if (!text) + return 0; + while (*text) + w += _wid[(unsigned char)*(text++)]; return w; } Talk::Talk(CGEEngine *vm, const char *text, TextBoxStyle mode) : Sprite(vm, NULL), _mode(mode), _vm(vm) { - _ts = NULL; _flags._syst = true; update(text); @@ -98,19 +99,17 @@ void Talk::deinit() { delete _font; } - void Talk::update(const char *text) { - uint16 vmarg = (_mode) ? kTextVMargin : 0; - uint16 hmarg = (_mode) ? kTextHMargin : 0; + const uint16 vmarg = (_mode) ? kTextVMargin : 0; + const uint16 hmarg = (_mode) ? kTextHMargin : 0; uint16 mw = 0; uint16 ln = vmarg; - const char *p; uint8 *m; if (!_ts) { uint16 k = 2 * hmarg; uint16 mh = 2 * vmarg + kFontHigh; - for (p = text; *p; p++) { + for (const char *p = text; *p; p++) { if (*p == '|' || *p == '\n') { mh += kFontHigh + kTextLineSpace; if (k > mw) @@ -130,15 +129,15 @@ void Talk::update(const char *text) { m = _ts[0]->_m + ln * mw + hmarg; while (*text) { - if (*text == '|' || *text == '\n') + if (*text == '|' || *text == '\n') { m = _ts[0]->_m + (ln += kFontHigh + kTextLineSpace) * mw + hmarg; - else { - int cw = _font->_wid[(unsigned char)*text], i; + } else { + int cw = _font->_wid[(unsigned char)*text]; uint8 *f = _font->_map + _font->_pos[(unsigned char)*text]; - for (i = 0; i < cw; i++) { + for (int i = 0; i < cw; i++) { uint8 *pp = m; uint16 n; - register uint16 b = *(f++); + uint16 b = *(f++); for (n = 0; n < kFontHigh; n++) { if (b & 1) *pp = kTextColFG; @@ -155,21 +154,18 @@ void Talk::update(const char *text) { } Bitmap *Talk::box(uint16 w, uint16 h) { - uint8 *b, * p, * q; - uint16 r = (_mode == kTBRound) ? kTextRoundCorner : 0; - if (w < 8) w = 8; if (h < 8) h = 8; uint16 n = w * h; - b = (uint8 *) malloc(sizeof(uint8) * n); + uint8 *b = (uint8 *)malloc(n); assert(b != NULL); memset(b, kTextColBG, n); if (_mode) { - p = b; - q = b + n - w; + uint8 *p = b; + uint8 *q = b + n - w; memset(p, LGRAY, w); memset(q, DGRAY, w); while (p < q) { @@ -178,6 +174,7 @@ Bitmap *Talk::box(uint16 w, uint16 h) { *p = LGRAY; } p = b; + const uint16 r = (_mode == kTBRound) ? kTextRoundCorner : 0; for (int i = 0; i < r; i++) { int j; for (j = 0; j < r - i; j++) { @@ -197,13 +194,12 @@ Bitmap *Talk::box(uint16 w, uint16 h) { return new Bitmap(w, h, b); } - void Talk::putLine(int line, const char *text) { -// Note: (TS[0].W % 4) have to be 0 + // Note: (_ts[0]._w % 4) must be 0 uint16 w = _ts[0]->_w; uint16 h = _ts[0]->_h; - uint8 *v = _ts[0]->_v, * p; - uint16 dsiz = w >> 2; // data size (1 plane line size) + uint8 *v = _ts[0]->_v; + uint16 dsiz = w >> 2; // data size (1 plane line size) uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap uint16 psiz = h * lsiz; // - last gap, but + plane trailer uint16 size = 4 * psiz; // whole map size @@ -211,7 +207,7 @@ void Talk::putLine(int line, const char *text) { // set desired line pointer v += (kTextVMargin + (kFontHigh + kTextLineSpace) * line) * lsiz; - p = v; // assume blanked line above text + uint8 *p = v; // assume blanked line above text // clear whole rectangle assert((rsiz % lsiz) == 0); @@ -221,34 +217,32 @@ void Talk::putLine(int line, const char *text) { } // paint text line - if (text) { - uint8 *q; - p = v + 2 + kTextHMargin / 4 + (kTextHMargin % 4) * psiz; - q = v + size; + if (!text) + return; + p = v + 2 + (kTextHMargin / 4) + (kTextHMargin % 4) * psiz; + uint8 *q = v + size; - while (* text) { - uint16 cw = _font->_wid[(unsigned char)*text], i; - uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; + while (*text) { + uint16 cw = _font->_wid[(unsigned char)*text], i; + uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; - for (i = 0; i < cw; i++) { - register uint16 b = fp[i]; - uint16 n; - for (n = 0; n < kFontHigh; n++) { - if (b & 1) - *p = kTextColFG; - b >>= 1; - p += lsiz; - } - p = p - rsiz + psiz; - if (p >= q) - p = p - size + 1; + for (i = 0; i < cw; i++) { + uint16 b = fp[i]; + uint16 n; + for (n = 0; n < kFontHigh; n++) { + if (b & 1) + *p = kTextColFG; + b >>= 1; + p += lsiz; } - text++; + p = p - rsiz + psiz; + if (p >= q) + p = p - size + 1; } + text++; } } - InfoLine::InfoLine(CGEEngine *vm, uint16 w) : Talk(vm), _oldText(NULL), _vm(vm) { if (!_ts) { _ts = new BitmapPtr[2]; @@ -259,52 +253,52 @@ InfoLine::InfoLine(CGEEngine *vm, uint16 w) : Talk(vm), _oldText(NULL), _vm(vm) setShapeList(_ts); } - void InfoLine::update(const char *text) { - if (text != _oldText) { - uint16 w = _ts[0]->_w; - uint16 h = _ts[0]->_h; - uint8 *v = (uint8 *) _ts[0]->_v; - uint16 dsiz = w >> 2; // data size (1 plane line size) - uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap - uint16 psiz = h * lsiz; // - last gape, but + plane trailer - uint16 size = 4 * psiz; // whole map size + if (text == _oldText) + return; - // clear whole rectangle - byte *pDest; - memset(v + 2, kTextColBG, dsiz); // data bytes - for (pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz) { - Common::copy(v, v + lsiz, pDest); - } - *(uint16 *)(v + psiz - 2) = TO_LE_16(kBmpEOI); // plane trailer uint16 - for (pDest = v + psiz; pDest < (v + 4 * psiz); pDest += psiz) { - Common::copy(v, v + psiz, pDest); - } + uint16 w = _ts[0]->_w; + uint16 h = _ts[0]->_h; + uint8 *v = (uint8 *)_ts[0]->_v; + uint16 dsiz = w >> 2; // data size (1 plane line size) + uint16 lsiz = 2 + dsiz + 2; // uint16 for line header, uint16 for gap + uint16 psiz = h * lsiz; // - last gape, but + plane trailer + uint16 size = 4 * psiz; // whole map size - // paint text line - if (text) { - uint8 *p = v + 2, * q = p + size; - - while (*text) { - uint16 cw = _font->_wid[(unsigned char)*text]; - uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; - - for (uint16 i = 0; i < cw; i++) { - register uint16 b = fp[i]; - for (uint16 n = 0; n < kFontHigh; n++) { - if (b & 1) - *p = kTextColFG; - b >>= 1; - p += lsiz; - } - if (p >= q) - p = p - size + 1; - } - text++; - } - } - _oldText = text; + // clear whole rectangle + memset(v + 2, kTextColBG, dsiz); // data bytes + for (byte *pDest = v + lsiz; pDest < (v + psiz); pDest += lsiz) { + Common::copy(v, v + lsiz, pDest); } + *(uint16 *)(v + psiz - 2) = TO_LE_16(kBmpEOI); // plane trailer uint16 + for (byte *pDest = v + psiz; pDest < (v + 4 * psiz); pDest += psiz) { + Common::copy(v, v + psiz, pDest); + } + + // paint text line + if (text) { + uint8 *p = v + 2, * q = p + size; + + while (*text) { + uint16 cw = _font->_wid[(unsigned char)*text]; + uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; + + for (uint16 i = 0; i < cw; i++) { + uint16 b = fp[i]; + for (uint16 n = 0; n < kFontHigh; n++) { + if (b & 1) + *p = kTextColFG; + b >>= 1; + p += lsiz; + } + if (p >= q) + p = p - size + 1; + } + text++; + } + } + + _oldText = text; } } // End of namespace CGE diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 0e77bb89553..7e58762afa9 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -50,16 +50,13 @@ Text::Text(CGEEngine *vm, const char *fname, int size) : _vm(vm) { } } - Text::~Text() { clear(); delete[] _cache; } - void Text::clear(int from, int upto) { - Han *p, * q; - for (p = _cache, q = p + _size; p < q; p++) { + for (Han *p = _cache, *q = p + _size; p < q; p++) { if (p->_ref && p->_ref >= from && p->_ref < upto) { p->_ref = 0; delete[] p->_text; @@ -68,11 +65,9 @@ void Text::clear(int from, int upto) { } } - int Text::find(int ref) { - Han *p, * q; int i = 0; - for (p = _cache, q = p + _size; p < q; p++) { + for (Han *p = _cache, *q = p + _size; p < q; p++) { if (p->_ref == ref) break; else @@ -91,31 +86,34 @@ void Text::preload(int from, int upto) { while ((n = tf.read((uint8 *)line)) != 0) { char *s; - int ref; if (line[n - 1] == '\n') - line[-- n] = '\0'; + line[--n] = '\0'; + if ((s = strtok(line, " =,;/\t\n")) == NULL) continue; - if (! IsDigit(*s)) + if (!IsDigit(*s)) continue; - ref = atoi(s); - if (ref && ref >= from && ref < upto) { - Han *p; - p = &_cache[find(ref)]; + int ref = atoi(s); + if (ref && ref >= from && ref < upto) { + Han *p = &_cache[find(ref)]; + if (p < CacheLim) { delete[] p->_text; p->_text = NULL; } else p = &_cache[find(0)]; + if (p >= CacheLim) break; + s += strlen(s); if (s < line + n) ++s; if ((p->_text = new char[strlen(s) + 1]) == NULL) break; + p->_ref = ref; strcpy(p->_text, s); } @@ -126,35 +124,39 @@ void Text::preload(int from, int upto) { char *Text::load(int idx, int ref) { INI_FILE tf = _fileName; - if (!tf._error) { + if (tf._error) + return NULL; + + char line[kLineMax + 1]; + int n; + + while ((n = tf.read((uint8 *)line)) != 0) { + char *s; + + if (line[n - 1] == '\n') + line[-- n] = '\0'; + if ((s = strtok(line, " =,;/\t\n")) == NULL) + continue; + if (!IsDigit(*s)) + continue; + + int r = atoi(s); + if (r < ref) + continue; + if (r > ref) + break; + + // (r == ref) + s += strlen(s); + if (s < line + n) + ++s; + Han *p = &_cache[idx]; - char line[kLineMax + 1]; - int n; + p->_ref = ref; - while ((n = tf.read((uint8 *)line)) != 0) { - char *s; - - if (line[n - 1] == '\n') - line[-- n] = '\0'; - if ((s = strtok(line, " =,;/\t\n")) == NULL) - continue; - if (! IsDigit(*s)) - continue; - - int r = atoi(s); - if (r < ref) - continue; - if (r > ref) - break; - // (r == ref) - s += strlen(s); - if (s < line + n) - ++s; - p->_ref = ref; - if ((p->_text = new char[strlen(s) + 1]) == NULL) - return NULL; - return strcpy(p->_text, s); - } + if ((p->_text = new char[strlen(s) + 1]) == NULL) + return NULL; + return strcpy(p->_text, s); } return NULL; } @@ -179,42 +181,43 @@ char *Text::getText(int ref) { void Text::say(const char *text, Sprite *spr) { killText(); _talk = new Talk(_vm, text, kTBRound); - if (_talk) { - bool east = spr->_flags._east; - int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2); - int y = spr->_y + 2; - Sprite *spike = new Spike(_vm); - uint16 sw = spike->_w; + if (!_talk) + return; - if (east) { - if (x + sw + kTextRoundCorner + 5 >= kScrWidth) - east = false; - } else { - if (x <= 5 + kTextRoundCorner + sw) - east = true; - } - x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2 - sw); - if (spr->_ref == 1) - x += ((east) ? -10 : 10); // Hero + bool east = spr->_flags._east; + int x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2); + int y = spr->_y + 2; + Sprite *spike = new Spike(_vm); + uint16 sw = spike->_w; - _talk->_flags._kill = true; - _talk->_flags._bDel = true; - _talk->setName(_text->getText(kSayName)); - _talk->gotoxy(x - (_talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - _talk->_h + 1); - _talk->_z = 125; - _talk->_ref = kSayRef; - - spike->gotoxy(x, _talk->_y + _talk->_h - 1); - spike->_z = 126; - spike->_flags._slav = true; - spike->_flags._kill = true; - spike->setName(_text->getText(kSayName)); - spike->step(east); - spike->_ref = kSayRef; - - _vga->_showQ->insert(_talk, _vga->_showQ->last()); - _vga->_showQ->insert(spike, _vga->_showQ->last()); + if (east) { + if (x + sw + kTextRoundCorner + 5 >= kScrWidth) + east = false; + } else { + if (x <= 5 + kTextRoundCorner + sw) + east = true; } + x = (east) ? (spr->_x + spr->_w - 2) : (spr->_x + 2 - sw); + if (spr->_ref == 1) + x += ((east) ? -10 : 10); // Hero + + _talk->_flags._kill = true; + _talk->_flags._bDel = true; + _talk->setName(_text->getText(kSayName)); + _talk->gotoxy(x - (_talk->_w - sw) / 2 - 3 + 6 * east, y - spike->_h - _talk->_h + 1); + _talk->_z = 125; + _talk->_ref = kSayRef; + + spike->gotoxy(x, _talk->_y + _talk->_h - 1); + spike->_z = 126; + spike->_flags._slav = true; + spike->_flags._kill = true; + spike->setName(_text->getText(kSayName)); + spike->step(east); + spike->_ref = kSayRef; + + _vga->_showQ->insert(_talk, _vga->_showQ->last()); + _vga->_showQ->insert(spike, _vga->_showQ->last()); } void CGEEngine::inf(const char *text) { @@ -222,31 +225,34 @@ void CGEEngine::inf(const char *text) { killText(); _talk = new Talk(this, text, kTBRect); - if (_talk) { - _talk->_flags._kill = true; - _talk->_flags._bDel = true; - _talk->setName(_text->getText(kInfName)); - _talk->center(); - _talk->gotoxy(_talk->_x, _talk->_y - 20); - _talk->_z = 126; - _talk->_ref = kInfRef; - _vga->_showQ->insert(_talk, _vga->_showQ->last()); - } + if (!_talk) + return; + + _talk->_flags._kill = true; + _talk->_flags._bDel = true; + _talk->setName(_text->getText(kInfName)); + _talk->center(); + _talk->gotoxy(_talk->_x, _talk->_y - 20); + _talk->_z = 126; + _talk->_ref = kInfRef; + _vga->_showQ->insert(_talk, _vga->_showQ->last()); } void Text::sayTime(Sprite *spr) { TimeDate curTime; - char t[6]; _vm->_system->getTimeAndDate(curTime); + + char t[6]; sprintf(t, "%d:%02d", curTime.tm_hour, curTime.tm_min); say(t, spr); } void killText() { - if (_talk) { - _snail_->addCom(kSnKill, -1, 0, _talk); - _talk = NULL; - } + if (!_talk) + return; + + _snail_->addCom(kSnKill, -1, 0, _talk); + _talk = NULL; } } // End of namespace CGE diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 48b27d97275..c8a21160bfe 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -59,9 +59,7 @@ MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { _flags._bDel = true; } - -static char *vmgt; - +static char *g_vmgt; char *VMGather(Choice *list) { Choice *cp; @@ -71,30 +69,28 @@ char *VMGather(Choice *list) { len += strlen(cp->_text); h++; } - vmgt = new char[len + h]; - if (vmgt) { - *vmgt = '\0'; + g_vmgt = new char[len + h]; + if (g_vmgt) { + *g_vmgt = '\0'; for (cp = list; cp->_text; cp++) { - if (*vmgt) - strcat(vmgt, "|"); - strcat(vmgt, cp->_text); + if (*g_vmgt) + strcat(g_vmgt, "|"); + strcat(g_vmgt, cp->_text); h++; } } - return vmgt; + return g_vmgt; } - Vmenu *Vmenu::_addr = NULL; -int Vmenu::_recent = -1; - +int Vmenu::_recent = -1; Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y) : Talk(vm, VMGather(list), kTBRect), _menu(list), _bar(NULL), _vm(vm) { Choice *cp; _addr = this; - delete[] vmgt; + delete[] g_vmgt; _items = 0; for (cp = list; cp->_text; cp++) _items++; @@ -110,7 +106,6 @@ Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y) _vga->_showQ->insert(_bar, _vga->_showQ->last()); } - Vmenu::~Vmenu() { _addr = NULL; } @@ -118,31 +113,32 @@ Vmenu::~Vmenu() { #define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember)) void Vmenu::touch(uint16 mask, int x, int y) { - if (_items) { - Sprite::touch(mask, x, y); + if (!_items) + return; - y -= kTextVMargin - 1; - int n = 0; - bool ok = false; - uint16 h = kFontHigh + kTextLineSpace; + Sprite::touch(mask, x, y); - if (y >= 0) { - n = y / h; - if (n < _items) - ok = (x >= kTextHMargin && x < _w - kTextHMargin/* && y % h < FONT_HIG*/); - else - n = _items - 1; - } + y -= kTextVMargin - 1; + int n = 0; + bool ok = false; + uint16 h = kFontHigh + kTextLineSpace; - _bar->gotoxy(_x + kTextHMargin - kMenuBarHM, _y + kTextVMargin + n * h - kMenuBarVM); + if (y >= 0) { + n = y / h; + if (n < _items) + ok = (x >= kTextHMargin && x < _w - kTextHMargin/* && y % h < FONT_HIG*/); + else + n = _items - 1; + } - if (ok && (mask & kMouseLeftUp)) { - _items = 0; - _snail_->addCom(kSnKill, -1, 0, this); - _recent = n; - assert(_menu[n].Proc); - CALL_MEMBER_FN(*_vm, _menu[n].Proc)(); - } + _bar->gotoxy(_x + kTextHMargin - kMenuBarHM, _y + kTextVMargin + n * h - kMenuBarVM); + + if (ok && (mask & kMouseLeftUp)) { + _items = 0; + _snail_->addCom(kSnKill, -1, 0, this); + _recent = n; + assert(_menu[n].Proc); + CALL_MEMBER_FN(*_vm, _menu[n].Proc)(); } } diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 44cad5e8326..51dbe4f8560 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -73,20 +73,17 @@ VFile::VFile(const char *name, IOMode mode) } } - VFile::~VFile() { if (_recent == this) _recent = NULL; } - bool VFile::exist(const char *name) { debugC(1, kCGEDebugFile, "VFile::exist(%s)", name); return scumm_stricmp(_cat->find(name)->_key, name) == 0; } - void VFile::readBuf() { debugC(3, kCGEDebugFile, "VFile::readBuf()"); diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 7bce9e29e66..89d7f6308b1 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -96,9 +96,9 @@ void Walk::tick() { } } - if (_flags._hold || _tracePtr < 0) + if (_flags._hold || _tracePtr < 0) { park(); - else { + } else { if (_here == _trace[_tracePtr]) { if (--_tracePtr < 0) park(); @@ -112,9 +112,9 @@ void Walk::tick() { step(); if ((_dir == kDirWest && _x <= 0) || (_dir == kDirEast && _x + _w >= kScrWidth) || - (_dir == kDirSouth && _y + _w >= kWorldHeight - 2)) + (_dir == kDirSouth && _y + _w >= kWorldHeight - 2)) { park(); - else { + } else { signed char x; // dummy var _here.split(x, _z); // take current Z position _snail_->addCom(kSnZTrim, -1, 0, this); // update Hero's pos in show queue @@ -123,8 +123,7 @@ void Walk::tick() { int Walk::distance(Sprite *spr) { - int dx, dz; - dx = spr->_x - (_x + _w - kWalkSide); + int dx = spr->_x - (_x + _w - kWalkSide); if (dx < 0) dx = (_x + kWalkSide) - (spr->_x + spr->_w); @@ -132,7 +131,7 @@ int Walk::distance(Sprite *spr) { dx = 0; dx /= kMapGridX; - dz = spr->_z - _z; + int dz = spr->_z - _z; if (dz < 0) dz = - dz; @@ -166,36 +165,39 @@ void Walk::park() { void Walk::findWay(Cluster c) { - if (c != _here) { - for (_findLevel = 1; _findLevel <= kMaxFindLevel; _findLevel++) { - signed char x, z; - _here.split(x, z); - _target = Couple(x, z); - c.split(x, z); + if (c == _here) + return; - if (find1Way(Cluster(x, z))) - break; - } - _tracePtr = (_findLevel > kMaxFindLevel) ? -1 : (_findLevel - 1); - if (_tracePtr < 0) - noWay(); - _time = 1; + for (_findLevel = 1; _findLevel <= kMaxFindLevel; _findLevel++) { + signed char x, z; + _here.split(x, z); + _target = Couple(x, z); + c.split(x, z); + + if (find1Way(Cluster(x, z))) + break; } + _tracePtr = (_findLevel > kMaxFindLevel) ? -1 : (_findLevel - 1); + if (_tracePtr < 0) + noWay(); + _time = 1; } void Walk::findWay(Sprite *spr) { - if (spr && spr != this) { - int x = spr->_x; - int z = spr->_z; - if (spr->_flags._east) - x += spr->_w + _w / 2 - kWalkSide; - else - x -= _w / 2 - kWalkSide; - findWay(Cluster((x / kMapGridX), - ((z < kMapZCnt - kDistMax) ? (z + 1) - : (z - 1)))); - } + if (!spr || spr == this) + return; + + int x = spr->_x; + int z = spr->_z; + if (spr->_flags._east) + x += spr->_w + _w / 2 - kWalkSide; + else + x -= _w / 2 - kWalkSide; + + findWay(Cluster((x / kMapGridX), + ((z < kMapZCnt - kDistMax) ? (z + 1) + : (z - 1)))); } diff --git a/engines/cge/walk.h b/engines/cge/walk.h index 271663e51dc..e9249769273 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -96,7 +96,6 @@ public: bool isValid() const; }; - class Walk : public Sprite { private: CGEEngine *_vm; From df122cec1779659365f4f3bddb67b6b635620822 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 19 Aug 2011 18:32:46 +0200 Subject: [PATCH 226/276] CGE: fix some warnings reported by cppcheck --- engines/cge/cge_main.h | 1 - engines/cge/events.cpp | 1 + engines/cge/walk.cpp | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 1c85816c3e1..1c5f818217a 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -93,7 +93,6 @@ namespace CGE { class System : public Sprite { - int _lum; public: int _funDel; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 916de839ebb..ea2515ef2e0 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -247,6 +247,7 @@ EventManager::EventManager() { _quitFlag = false; _eventQueueHead = 0; _eventQueueTail = 0; + memset(&_eventQueue, 0, kEventMax * sizeof(CGEEvent)); memset(&_event, 0, sizeof(Common::Event)); } diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 7bce9e29e66..a0245992037 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -71,7 +71,7 @@ Cluster XZ(Couple xy) { } Walk::Walk(CGEEngine *vm, BitmapPtr *shpl) - : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _target(-1, -1), _vm(vm) { + : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _target(-1, -1), _findLevel(-1), _vm(vm) { } From 8ff904c6b576eda37930b020e39855c1fd261b2f Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 19 Aug 2011 19:48:49 +0200 Subject: [PATCH 227/276] CGE: clean up bitmap class. Suppress useless methods, functions, defines... --- engines/cge/bitmap.cpp | 116 ++------------------------------------- engines/cge/bitmap.h | 5 +- engines/cge/cge_main.cpp | 4 +- engines/cge/events.cpp | 4 +- engines/cge/jbw.h | 1 - engines/cge/mixer.cpp | 4 +- engines/cge/vga13h.cpp | 20 +++---- 7 files changed, 22 insertions(+), 132 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index e4978287885..b7e9eec2fcb 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -48,36 +48,18 @@ void Bitmap::deinit() { } #pragma argsused -Bitmap::Bitmap(const char *fname, bool rem) : _m(NULL), _v(NULL), _map(0) { - debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(%s, %s)", fname, rem ? "true" : "false"); +Bitmap::Bitmap(const char *fname) : _m(NULL), _v(NULL), _map(0) { + debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(%s)", fname); char pat[kMaxPath]; forceExt(pat, fname, ".VBM"); -#if (BMP_MODE < 2) - if (rem && PIC_FILE::exist(pat)) { + if (PIC_FILE::exist(pat)) { PIC_FILE file(pat); if ((file._error == 0) && (!loadVBM(&file))) error("Bad VBM [%s]", fname); - } else -#endif - { -#if (BMP_MODE) - forceExt(pat, fname, ".BMP"); - PIC_FILE file(pat); - if (file._error == 0) { - if (loadBMP(&file)) { - code(); - if (rem) { - free(_m); - _m = NULL; - } - } else - error("Bad BMP [%s]", fname); - } -#else + } else { error("Bad VBM [%s]", fname); -#endif } } @@ -88,7 +70,6 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 *map) : _w(w), _h(h), _m(map), _v(NULL) code(); } - // following routine creates filled rectangle // immediately as VGA video chunks, in near memory as fast as possible, // especially for text line real time display @@ -117,7 +98,7 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) *(uint16 *)(v + psiz - 2) = TO_LE_16(kBmpEOI); // plane trailer uint16 - // Repliccate planes + // Replicate planes for (destP = v + psiz; destP < (v + 4 * psiz); destP += psiz) Common::copy(v, v + psiz, destP); @@ -134,7 +115,6 @@ Bitmap::Bitmap(uint16 w, uint16 h, uint8 fill) _b = b; } - Bitmap::Bitmap(const Bitmap &bmp) : _w(bmp._w), _h(bmp._h), _m(NULL), _v(NULL), _map(0) { debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(bmp)"); uint8 *v0 = bmp._v; @@ -372,35 +352,6 @@ bool Bitmap::solidAt(int16 x, int16 y) { } } - -bool Bitmap::saveVBM(XFile *f) { - debugC(1, kCGEDebugBitmap, "Bitmap::saveVBM(f)"); - - uint16 p = (_pal != NULL), - n = ((uint16)(((uint8 *)_b) - _v)) + _h * sizeof(HideDesc); - if (f->_error == 0) - f->write((uint8 *)&p, sizeof(p)); - - if (f->_error == 0) - f->write((uint8 *)&n, sizeof(n)); - - if (f->_error == 0) - f->write((uint8 *)&_w, sizeof(_w)); - - if (f->_error == 0) - f->write((uint8 *)&_h, sizeof(_h)); - - if (f->_error == 0) - if (p) - f->write((uint8 *)_pal, 256 * 3); - - if (f->_error == 0) - f->write(_v, n); - - return (f->_error == 0); -} - - bool Bitmap::loadVBM(XFile *f) { debugC(5, kCGEDebugBitmap, "Bitmap::loadVBM(f)"); @@ -448,61 +399,4 @@ bool Bitmap::loadVBM(XFile *f) { return (f->_error == 0); } -bool Bitmap::loadBMP(XFile *f) { - debugC(1, kCGEDebugBitmap, "Bitmap::loadBMP(f)"); - - struct { - char BM[2]; - union { int16 len; int32 len_; }; - union { int16 _06; int32 _06_; }; - union { int16 hdr; int32 hdr_; }; - union { int16 _0E; int32 _0E_; }; - union { int16 wid; int32 wid_; }; - union { int16 hig; int32 hig_; }; - union { int16 _1A; int32 _1A_; }; - union { int16 _1E; int32 _1E_; }; - union { int16 _22; int32 _22_; }; - union { int16 _26; int32 _26_; }; - union { int16 _2A; int32 _2A_; }; - union { int16 _2E; int32 _2E_; }; - union { int16 _32; int32 _32_; }; - } hea; - - Bgr4 bpal[256]; - - f->read((byte *)&hea, sizeof(hea)); - if (f->_error == 0) { - if (hea.hdr == 0x436L) { - int16 i = (hea.hdr - sizeof(hea)) / sizeof(Bgr4); - f->read((byte *)&bpal, sizeof(bpal)); - if (f->_error == 0) { - if (_pal) { - for (i = 0; i < 256; i++) { - _pal[i]._r = bpal[i]._R; - _pal[i]._g = bpal[i]._G; - _pal[i]._b = bpal[i]._B; - } - _pal = NULL; - } - _h = hea.hig; - _w = hea.wid; - if ((_m = (byte *) malloc(sizeof(byte) * (_h * _w))) != NULL) { - int16 r = (4 - (hea.wid & 3)) % 4; - byte buf[3]; - for (i = _h - 1; i >= 0; i--) { - f->read(_m + (_w * i), _w); - if (r && f->_error == 0) - f->read(buf, r); - if (f->_error) - break; - } - if (i < 0) - return true; - } - } - } - } - return false; -} - } // End of namespace CGE diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 30e11d08ec9..7604cb8081f 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -60,7 +60,6 @@ struct HideDesc { #include "common/pack-end.h" class Bitmap { - bool loadBMP(XFile *f); bool loadVBM(XFile *f); public: static Dac *_pal; @@ -71,7 +70,7 @@ public: int32 _map; HideDesc *_b; - Bitmap(const char *fname, bool rem); + Bitmap(const char *fname); Bitmap(uint16 w, uint16 h, uint8 *map); Bitmap(uint16 w, uint16 h, uint8 fill); Bitmap(const Bitmap &bmp); @@ -79,14 +78,12 @@ public: static void init(); static void deinit(); - Bitmap *flipH(); Bitmap *code(); Bitmap &operator = (const Bitmap &bmp); void hide(int16 x, int16 y); void show(int16 x, int16 y); void xShow(int16 x, int16 y); bool solidAt(int16 x, int16 y); - bool saveVBM(XFile *f); uint16 moveVmap(uint8 *buf); }; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 5b98b0a4e8c..e64fc382eef 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -478,7 +478,7 @@ Square::Square(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { _flags._bDel = false; BitmapPtr *MB = new BitmapPtr[2]; - MB[0] = new Bitmap("BRICK", true); + MB[0] = new Bitmap("BRICK"); MB[1] = NULL; setShapeList(MB); } @@ -1632,7 +1632,7 @@ bool CGEEngine::showTitle(const char *name) { Bitmap::_pal = Vga::_sysPal; BitmapPtr *LB = new BitmapPtr[2]; - LB[0] = new Bitmap(name, true); + LB[0] = new Bitmap(name); LB[1] = NULL; Bitmap::_pal = NULL; bool userOk = false; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index ea2515ef2e0..f414bd048a6 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -169,8 +169,8 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) setSeq(seq); BitmapPtr *MC = new BitmapPtr[3]; - MC[0] = new Bitmap("MOUSE", true); - MC[1] = new Bitmap("DUMMY", true); + MC[0] = new Bitmap("MOUSE"); + MC[1] = new Bitmap("DUMMY"); MC[2] = NULL; setShapeList(MC); diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 128a92f5941..0ba8a1956b2 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -35,7 +35,6 @@ namespace CGE { // Defines found in cge.mak #define INI_FILE VFile // Or is it CFile? #define PIC_FILE VFile -#define BMP_MODE 0 // #define kMaxFile 128 diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp index ba24f832c3e..7a07f99c6e3 100644 --- a/engines/cge/mixer.cpp +++ b/engines/cge/mixer.cpp @@ -41,7 +41,7 @@ bool Mixer::_appear = false; Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _vm(vm) { _appear = true; - _mb[0] = new Bitmap("VOLUME", true); + _mb[0] = new Bitmap("VOLUME"); _mb[1] = NULL; setShapeList(_mb); setName(_text->getText(kMixName)); @@ -59,7 +59,7 @@ Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _ for (i = 0; i < kMixMax; i++) { static char fn[] = "V00"; wtom(i, fn + 1, 10, 2); - _lb[i] = new Bitmap(fn, true); + _lb[i] = new Bitmap(fn); ls[i]._now = ls[i]._next = i; ls[i]._dx = ls[i]._dy = ls[i]._dly = 0; } diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index ad2415caafd..d963622b131 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -289,7 +289,7 @@ Sprite *Sprite::expand() { ++_shpCnt; } - shplist[shpcnt++] = new Bitmap(strtok(NULL, " \t,;/"), true); + shplist[shpcnt++] = new Bitmap(strtok(NULL, " \t,;/")); break; } case 2 : { // Seq @@ -344,7 +344,7 @@ Sprite *Sprite::expand() { } } } else { // no sprite description: try to read immediately from .BMP - shplist[shpcnt++] = new Bitmap(_file, true); + shplist[shpcnt++] = new Bitmap(_file); } shplist[shpcnt] = NULL; if (seq) { @@ -1041,7 +1041,7 @@ void Bitmap::hide(int16 x, int16 y) { HorizLine::HorizLine(CGEEngine *vm): Sprite(vm, NULL) { // Set the sprite list BitmapPtr *HL = new BitmapPtr[2]; - HL[0] = new Bitmap("HLINE", true); + HL[0] = new Bitmap("HLINE"); HL[1] = NULL; setShapeList(HL); @@ -1050,7 +1050,7 @@ HorizLine::HorizLine(CGEEngine *vm): Sprite(vm, NULL) { CavLight::CavLight(CGEEngine *vm): Sprite(vm, NULL) { // Set the sprite list BitmapPtr *PR = new BitmapPtr[2]; - PR[0] = new Bitmap("PRESS", true); + PR[0] = new Bitmap("PRESS"); PR[1] = NULL; setShapeList(PR); @@ -1059,8 +1059,8 @@ CavLight::CavLight(CGEEngine *vm): Sprite(vm, NULL) { Spike::Spike(CGEEngine *vm): Sprite(vm, NULL) { // Set the sprite list BitmapPtr *SP = new BitmapPtr[3]; - SP[0] = new Bitmap("SPK_L", true); - SP[1] = new Bitmap("SPK_R", true); + SP[0] = new Bitmap("SPK_L"); + SP[1] = new Bitmap("SPK_R"); SP[2] = NULL; setShapeList(SP); @@ -1069,10 +1069,10 @@ Spike::Spike(CGEEngine *vm): Sprite(vm, NULL) { PocLight::PocLight(CGEEngine *vm): Sprite(vm, NULL) { // Set the sprite list BitmapPtr *LI = new BitmapPtr[5]; - LI[0] = new Bitmap("LITE0", true); - LI[1] = new Bitmap("LITE1", true); - LI[2] = new Bitmap("LITE2", true); - LI[3] = new Bitmap("LITE3", true); + LI[0] = new Bitmap("LITE0"); + LI[1] = new Bitmap("LITE1"); + LI[2] = new Bitmap("LITE2"); + LI[3] = new Bitmap("LITE3"); LI[4] = NULL; setShapeList(LI); From 01b4ac72190bdfb3cd637890c5c0a88bc16163ac Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Fri, 19 Aug 2011 23:54:24 +0200 Subject: [PATCH 228/276] CGE: More cleanup. --- engines/cge/vga13h.cpp | 477 +++++++++++++++++++---------------------- engines/cge/vga13h.h | 6 +- 2 files changed, 218 insertions(+), 265 deletions(-) diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 80060bfd741..feaa005643c 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -38,7 +38,7 @@ namespace CGE { -static VgaRegBlk VideoMode[] = { +static VgaRegBlk VideoMode[] = { { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 { 0x05, VGAGRA, 0x03, 0x00 }, // R/W mode = 0 @@ -55,7 +55,7 @@ static VgaRegBlk VideoMode[] = { { 0x00, 0x00, 0x00, 0x00 } }; -bool SpeedTest = false; +bool SpeedTest = false; Seq *getConstantSeq(bool seqFlag) { const Seq seq1[] = { { 0, 0, 0, 0, 0 } }; @@ -74,20 +74,17 @@ Seq *getConstantSeq(bool seqFlag) { return seq; } - -extern "C" void SNDMIDIPlay(); +extern "C" void SNDMIDIPlay(); uint16 *SaveScreen() { // In ScummVM, we don't need to worry about saving the original screen mode return 0; } - void RestoreScreen(uint16 * &sav) { // In ScummVM, we don't need to restore the original text screen when the game exits } - Dac mkDac(uint8 r, uint8 g, uint8 b) { static Dac x; x._r = r; @@ -118,7 +115,6 @@ Sprite::Sprite(CGEEngine *vm, BitmapPtr *shpP) setShapeList(shpP); } - Sprite::~Sprite() { if (_sprite == this) _sprite = NULL; @@ -126,24 +122,21 @@ Sprite::~Sprite() { contract(); } - BitmapPtr Sprite::shp() { - register SprExt *e = _ext; - if (e) - if (e->_seq) { - int i = e->_seq[_seqPtr]._now; - if (i >= _shpCnt) { - //char s[256]; - //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", - // Seq, ShpCnt, SeqPtr, Seq[SeqPtr].Now, Seq[SeqPtr].Next); - //VGA::Exit(s, File); - error("Invalid PHASE in SPRITE::Shp() %s", _file); - } - return e->_shpList[i]; - } - return NULL; -} + SprExt *e = _ext; + if (!e || !e->_seq) + return NULL; + int i = e->_seq[_seqPtr]._now; + if (i >= _shpCnt) { + //char s[256]; + //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", + // Seq, ShpCnt, SeqPtr, Seq[SeqPtr].Now, Seq[SeqPtr].Next); + //VGA::Exit(s, File); + error("Invalid PHASE in SPRITE::Shp() %s", _file); + } + return e->_shpList[i]; +} BitmapPtr *Sprite::setShapeList(BitmapPtr *shpP) { BitmapPtr *r = (_ext) ? _ext->_shpList : NULL; @@ -171,7 +164,6 @@ BitmapPtr *Sprite::setShapeList(BitmapPtr *shpP) { return r; } - void Sprite::moveShapes(uint8 *buf) { BitmapPtr *p; for (p = _ext->_shpList; *p; p++) { @@ -179,22 +171,21 @@ void Sprite::moveShapes(uint8 *buf) { } } - bool Sprite::works(Sprite *spr) { - if (spr) - if (spr->_ext) { - Snail::Com *c = spr->_ext->_take; - if (c != NULL) { - c += spr->_takePtr; - if (c->_ref == _ref) - if (c->_com != kSnLabel || (c->_val == 0 || c->_val == _vm->_now)) - return true; - } - } + if (!spr || !spr->_ext) + return false; + + Snail::Com *c = spr->_ext->_take; + if (c != NULL) { + c += spr->_takePtr; + if (c->_ref == _ref) + if (c->_com != kSnLabel || (c->_val == 0 || c->_val == _vm->_now)) + return true; + } + return false; } - Seq *Sprite::setSeq(Seq *seq) { if (_ext) { free(_ext->_seq); @@ -202,7 +193,8 @@ Seq *Sprite::setSeq(Seq *seq) { } expand(); - register Seq *s = _ext->_seq; + + Seq *s = _ext->_seq; _ext->_seq = seq; if (_seqPtr == NO_SEQ) step(0); @@ -211,7 +203,6 @@ Seq *Sprite::setSeq(Seq *seq) { return s; } - bool Sprite::seqTest(int n) { if (n >= 0) return (_seqPtr == n); @@ -220,186 +211,189 @@ bool Sprite::seqTest(int n) { return true; } - Snail::Com *Sprite::snList(SnList type) { - register SprExt *e = _ext; + SprExt *e = _ext; if (e) return (type == kNear) ? e->_near : e->_take; return NULL; } - void Sprite::setName(char *newName) { - if (_ext) { - if (_ext->_name) { - delete[] _ext->_name; - _ext->_name = NULL; - } - if (newName) { - _ext->_name = new char[strlen(newName) + 1]; - assert(_ext->_name != NULL); - strcpy(_ext->_name, newName); - } + if (!_ext) + return; + + if (_ext->_name) { + delete[] _ext->_name; + _ext->_name = NULL; + } + if (newName) { + _ext->_name = new char[strlen(newName) + 1]; + assert(_ext->_name != NULL); + strcpy(_ext->_name, newName); } } - Sprite *Sprite::expand() { - if (!_ext) { - _ext = new SprExt; - assert(_ext != NULL); - if (*_file) { - static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; - char line[kLineMax], fname[kPathMax]; + if (_ext) + return this; - Common::Array shplist; - for (int i = 0; i < _shpCnt + 1; ++i) shplist.push_back(NULL); - Seq *seq = NULL; - int shpcnt = 0, - seqcnt = 0, - neacnt = 0, - takcnt = 0, - maxnow = 0, - maxnxt = 0; + _ext = new SprExt; + assert(_ext != NULL); + if (!*_file) + return this; - Snail::Com *nea = NULL; - Snail::Com *tak = NULL; - mergeExt(fname, _file, SPR_EXT); - if (INI_FILE::exist(fname)) { // sprite description file exist - INI_FILE sprf(fname); - if (!(sprf._error==0)) - error("Bad SPR [%s]", fname); - int len = 0, lcnt = 0; - while ((len = sprf.read((uint8 *)line)) != 0) { - lcnt++; - if (len && line[len - 1] == '\n') - line[--len] = '\0'; - if (len == 0 || *line == '.') - continue; + static const char *Comd[] = { "Name", "Phase", "Seq", "Near", "Take", NULL }; + char line[kLineMax], fname[kPathMax]; - switch (takeEnum(Comd, strtok(line, " =\t"))) { - case 0 : { // Name - setName(strtok(NULL, "")); - break; - } - case 1 : { // Phase - // In case the shape index gets too high, increase the array size - while ((shpcnt + 1) >= (int)shplist.size()) { - shplist.push_back(NULL); - ++_shpCnt; - } + Common::Array shplist; + for (int i = 0; i < _shpCnt + 1; ++i) shplist.push_back(NULL); + Seq *seq = NULL; + int shpcnt = 0, + seqcnt = 0, + neacnt = 0, + takcnt = 0, + maxnow = 0, + maxnxt = 0; - shplist[shpcnt++] = new Bitmap(strtok(NULL, " \t,;/")); - break; - } - case 2 : { // Seq - seq = (Seq *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); - assert(seq != NULL); - Seq *s = &seq[seqcnt++]; - s->_now = atoi(strtok(NULL, " \t,;/")); - if (s->_now > maxnow) - maxnow = s->_now; - s->_next = atoi(strtok(NULL, " \t,;/")); - switch (s->_next) { - case 0xFF : - s->_next = seqcnt; - break; - case 0xFE : - s->_next = seqcnt - 1; - break; - } - if (s->_next > maxnxt) - maxnxt = s->_next; - s->_dx = atoi(strtok(NULL, " \t,;/")); - s->_dy = atoi(strtok(NULL, " \t,;/")); - s->_dly = atoi(strtok(NULL, " \t,;/")); - break; - } - case 3 : { // Near - if (_nearPtr != NO_PTR) { - nea = (Snail::Com *) realloc(nea, (neacnt + 1) * sizeof(*nea)); - assert(nea != NULL); - Snail::Com *c = &nea[neacnt++]; - if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0) - error("Bad NEAR in %d [%s]", lcnt, fname); - c->_ref = atoi(strtok(NULL, " \t,;/")); - c->_val = atoi(strtok(NULL, " \t,;/")); - c->_ptr = NULL; - } - } - break; - case 4 : { // Take - if (_takePtr != NO_PTR) { - tak = (Snail::Com *) realloc(tak, (takcnt + 1) * sizeof(*tak)); - assert(tak != NULL); - Snail::Com *c = &tak[takcnt++]; - if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0) - error("Bad NEAR in %d [%s]", lcnt, fname); - c->_ref = atoi(strtok(NULL, " \t,;/")); - c->_val = atoi(strtok(NULL, " \t,;/")); - c->_ptr = NULL; - } - break; - } - } + Snail::Com *nea = NULL; + Snail::Com *tak = NULL; + mergeExt(fname, _file, SPR_EXT); + if (INI_FILE::exist(fname)) { // sprite description file exist + INI_FILE sprf(fname); + if (!(sprf._error==0)) + error("Bad SPR [%s]", fname); + int len = 0, lcnt = 0; + while ((len = sprf.read((uint8 *)line)) != 0) { + lcnt++; + if (len && line[len - 1] == '\n') + line[--len] = '\0'; + if (len == 0 || *line == '.') + continue; + + Snail::Com *c; + switch (takeEnum(Comd, strtok(line, " =\t"))) { + case 0: + // Name + setName(strtok(NULL, "")); + break; + case 1: + // Phase + // In case the shape index gets too high, increase the array size + while ((shpcnt + 1) >= (int)shplist.size()) { + shplist.push_back(NULL); + ++_shpCnt; } - } else { // no sprite description: try to read immediately from .BMP - shplist[shpcnt++] = new Bitmap(_file); + shplist[shpcnt++] = new Bitmap(strtok(NULL, " \t,;/")); + break; + case 2: + // Seq + seq = (Seq *) realloc(seq, (seqcnt + 1) * sizeof(*seq)); + assert(seq != NULL); + Seq *s; + s = &seq[seqcnt++]; + s->_now = atoi(strtok(NULL, " \t,;/")); + if (s->_now > maxnow) + maxnow = s->_now; + s->_next = atoi(strtok(NULL, " \t,;/")); + switch (s->_next) { + case 0xFF: + s->_next = seqcnt; + break; + case 0xFE: + s->_next = seqcnt - 1; + break; + } + if (s->_next > maxnxt) + maxnxt = s->_next; + s->_dx = atoi(strtok(NULL, " \t,;/")); + s->_dy = atoi(strtok(NULL, " \t,;/")); + s->_dly = atoi(strtok(NULL, " \t,;/")); + break; + case 3: + // Near + if (_nearPtr == NO_PTR) + break; + nea = (Snail::Com *) realloc(nea, (neacnt + 1) * sizeof(*nea)); + assert(nea != NULL); + c = &nea[neacnt++]; + if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0) + error("Bad NEAR in %d [%s]", lcnt, fname); + c->_ref = atoi(strtok(NULL, " \t,;/")); + c->_val = atoi(strtok(NULL, " \t,;/")); + c->_ptr = NULL; + break; + case 4: + // Take + if (_takePtr == NO_PTR) + break; + tak = (Snail::Com *) realloc(tak, (takcnt + 1) * sizeof(*tak)); + assert(tak != NULL); + c = &tak[takcnt++]; + if ((c->_com = (SnCom)takeEnum(Snail::_comText, strtok(NULL, " \t,;/"))) < 0) + error("Bad NEAR in %d [%s]", lcnt, fname); + c->_ref = atoi(strtok(NULL, " \t,;/")); + c->_val = atoi(strtok(NULL, " \t,;/")); + c->_ptr = NULL; + break; } - shplist[shpcnt] = NULL; - if (seq) { - if (maxnow >= shpcnt) - error("Bad PHASE in SEQ [%s]", fname); - if (maxnxt >= seqcnt) - error("Bad JUMP in SEQ [%s]", fname); - setSeq(seq); - } else - setSeq(getConstantSeq(_shpCnt == 1)); - - // Set the shape list - BitmapPtr *shapeList = new BitmapPtr[shplist.size()]; - for (uint i = 0; i < shplist.size(); ++i) - shapeList[i] = shplist[i]; - - setShapeList(shapeList); - - if (nea) - nea[neacnt - 1]._ptr = _ext->_near = nea; - else - _nearPtr = NO_PTR; - if (tak) - tak[takcnt - 1]._ptr = _ext->_take = tak; - else - _takePtr = NO_PTR; } + } else { + // no sprite description: try to read immediately from .BMP + shplist[shpcnt++] = new Bitmap(_file); } + + shplist[shpcnt] = NULL; + if (seq) { + if (maxnow >= shpcnt) + error("Bad PHASE in SEQ [%s]", fname); + if (maxnxt >= seqcnt) + error("Bad JUMP in SEQ [%s]", fname); + setSeq(seq); + } else + setSeq(getConstantSeq(_shpCnt == 1)); + + // Set the shape list + BitmapPtr *shapeList = new BitmapPtr[shplist.size()]; + for (uint i = 0; i < shplist.size(); ++i) + shapeList[i] = shplist[i]; + + setShapeList(shapeList); + + if (nea) + nea[neacnt - 1]._ptr = _ext->_near = nea; + else + _nearPtr = NO_PTR; + if (tak) + tak[takcnt - 1]._ptr = _ext->_take = tak; + else + _takePtr = NO_PTR; + return this; } - Sprite *Sprite::contract() { - register SprExt *e = _ext; - if (e) { - if (e->_name) - delete[] e->_name; - if (_flags._bDel && e->_shpList) { - int i; - for (i = 0; e->_shpList[i]; i++) - delete e->_shpList[i]; - delete[] e->_shpList; - } + SprExt *e = _ext; + if (!e) + return this; - free(e->_seq); - free(e->_near); - free(e->_take); - - delete e; - _ext = NULL; + if (e->_name) + delete[] e->_name; + if (_flags._bDel && e->_shpList) { + for (int i = 0; e->_shpList[i]; i++) + delete e->_shpList[i]; + delete[] e->_shpList; } + + free(e->_seq); + free(e->_near); + free(e->_take); + + delete e; + _ext = NULL; + return this; } - Sprite *Sprite::backShow(bool fast) { expand(); show(2); @@ -410,7 +404,6 @@ Sprite *Sprite::backShow(bool fast) { return this; } - void Sprite::step(int nr) { if (nr >= 0) _seqPtr = nr; @@ -426,38 +419,33 @@ void Sprite::step(int nr) { } } - void Sprite::tick() { step(); } - void Sprite::makeXlat(uint8 *x) { - if (_ext) { - BitmapPtr *b; + if (!_ext) + return; - if (_flags._xlat) - killXlat(); - for (b = _ext->_shpList; *b; b++) - (*b)->_m = x; - _flags._xlat = true; - } + if (_flags._xlat) + killXlat(); + for (BitmapPtr *b = _ext->_shpList; *b; b++) + (*b)->_m = x; + _flags._xlat = true; } - void Sprite::killXlat() { - if (_flags._xlat && _ext) { - BitmapPtr *b; - uint8 *m = (*_ext->_shpList)->_m; - free(m); + if (!_flags._xlat || !_ext) + return; - for (b = _ext->_shpList; *b; b++) - (*b)->_m = NULL; - _flags._xlat = false; - } + uint8 *m = (*_ext->_shpList)->_m; + free(m); + + for (BitmapPtr *b = _ext->_shpList; *b; b++) + (*b)->_m = NULL; + _flags._xlat = false; } - void Sprite::gotoxy(int x, int y) { int xo = _x, yo = _y; if (_x < kScrWidth) { @@ -481,14 +469,12 @@ void Sprite::gotoxy(int x, int y) { _prev->gotoxy(_prev->_x - xo + _x, _prev->_y - yo + _y); } - void Sprite::center() { gotoxy((kScrWidth - _w) / 2, (kScrHeight - _h) / 2); } - void Sprite::show() { - register SprExt *e; + SprExt *e; // asm cli // critic section... e = _ext; e->_x0 = e->_x1; @@ -506,7 +492,6 @@ void Sprite::show() { } } - void Sprite::show(uint16 pg) { Graphics::Surface *a = Vga::_page[1]; Vga::_page[1] = Vga::_page[pg & 3]; @@ -514,28 +499,26 @@ void Sprite::show(uint16 pg) { Vga::_page[1] = a; } - void Sprite::hide() { - register SprExt *e = _ext; + SprExt *e = _ext; if (e->_b0) e->_b0->hide(e->_x0, e->_y0); } - BitmapPtr Sprite::ghost() { - register SprExt *e = _ext; - if (e->_b1) { - BitmapPtr bmp = new Bitmap(0, 0, (uint8 *)NULL); - assert(bmp != NULL); - bmp->_w = e->_b1->_w; - bmp->_h = e->_b1->_h; - bmp->_b = new HideDesc[bmp->_h]; - assert(bmp->_b != NULL); - bmp->_v = (uint8 *) memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc) * bmp->_h); - bmp->_map = (e->_y1 << 16) + e->_x1; - return bmp; - } - return NULL; + SprExt *e = _ext; + if (!e->_b1) + return NULL; + + BitmapPtr bmp = new Bitmap(0, 0, (uint8 *)NULL); + assert(bmp != NULL); + bmp->_w = e->_b1->_w; + bmp->_h = e->_b1->_h; + bmp->_b = new HideDesc[bmp->_h]; + assert(bmp->_b != NULL); + bmp->_v = (uint8 *) memcpy(bmp->_b, e->_b1->_b, sizeof(HideDesc) * bmp->_h); + bmp->_map = (e->_y1 << 16) + e->_x1; + return bmp; } void Sprite::sync(Common::Serializer &s) { @@ -617,16 +600,13 @@ Sprite *spriteAt(int x, int y) { return spr; } - Queue::Queue(bool show) : _head(NULL), _tail(NULL), _show(show) { } - Queue::~Queue() { clear(); } - void Queue::clear() { while (_head) { Sprite *s = remove(_head); @@ -635,7 +615,6 @@ void Queue::clear() { } } - void Queue::forAll(void (*fun)(Sprite *)) { Sprite *s = _head; while (s) { @@ -645,7 +624,6 @@ void Queue::forAll(void (*fun)(Sprite *)) { } } - void Queue::append(Sprite *spr) { if (_tail) { spr->_prev = _tail; @@ -659,7 +637,6 @@ void Queue::append(Sprite *spr) { spr->contract(); } - void Queue::insert(Sprite *spr, Sprite *nxt) { if (nxt == _head) { spr->_next = _head; @@ -681,7 +658,6 @@ void Queue::insert(Sprite *spr, Sprite *nxt) { spr->contract(); } - void Queue::insert(Sprite *spr) { Sprite *s; for (s = _head; s; s = s->_next) @@ -716,17 +692,14 @@ Sprite *Queue::remove(Sprite *spr) { return spr; } - Sprite *Queue::locate(int ref) { - Sprite *spr; - for (spr = _head; spr; spr = spr->_next) { + for (Sprite *spr = _head; spr; spr = spr->_next) { if (spr->_ref == ref) return spr; } return NULL; } - //extern const char Copr[]; Graphics::Surface *Vga::_page[4]; Dac *Vga::_sysPal; @@ -782,7 +755,6 @@ Vga::Vga(int mode) clear(0); } - Vga::~Vga() { _mono = 0; @@ -807,12 +779,10 @@ Vga::~Vga() { delete _spareQ; } - void Vga::setStatAdr() { // No implementation needed for ScummVM } - #pragma argsused void Vga::waitVR(bool on) { // Since some of the game parts rely on using vertical sync as a delay mechanism, @@ -820,18 +790,15 @@ void Vga::waitVR(bool on) { g_system->delayMillis(5); } - void Vga::setup(VgaRegBlk *vrb) { // No direct VGA setup required, since ScummVM provides it's own graphics interface } - int Vga::setMode(int mode) { // ScummVM provides it's own vieo services return 0; } - void Vga::getColors(Dac *tab) { byte palData[kPalSize]; g_system->getPaletteManager()->grabPalette(palData, 0, kPalCount); @@ -877,13 +844,11 @@ void Vga::setColors(Dac *tab, int lum) { _setPal = true; } - void Vga::setColors() { memset(_newColors, 0, kPalSize); updateColors(); } - void Vga::sunrise(Dac *tab) { for (int i = 0; i <= 64; i += FADE_STEP) { setColors(tab, i); @@ -892,7 +857,6 @@ void Vga::sunrise(Dac *tab) { } } - void Vga::sunset() { Dac tab[256]; getColors(tab); @@ -903,27 +867,22 @@ void Vga::sunset() { } } - void Vga::show() { - Sprite *spr = _showQ->first(); - - for (spr = _showQ->first(); spr; spr = spr->_next) + for (Sprite *spr = _showQ->first(); spr; spr = spr->_next) spr->show(); update(); - for (spr = _showQ->first(); spr; spr = spr->_next) + for (Sprite *spr = _showQ->first(); spr; spr = spr->_next) spr->hide(); _frmCnt++; } - void Vga::updateColors() { byte palData[kPalSize]; dacToPal(_newColors, palData); g_system->getPaletteManager()->setPalette(palData, 0, 256); } - void Vga::update() { SWAP(Vga::_page[0], Vga::_page[1]); @@ -936,13 +895,11 @@ void Vga::update() { g_system->updateScreen(); } - void Vga::clear(uint8 color) { for (int paneNum = 0; paneNum < 4; paneNum++) _page[paneNum]->fillRect(Common::Rect(0, 0, kScrWidth, kScrHeight), color); } - void Vga::copyPage(uint16 d, uint16 s) { _page[d]->copyFrom(*_page[s]); } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 1d41a068ff8..8576752d07b 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -194,7 +194,6 @@ private: CGEEngine *_vm; }; - class Queue { Sprite *_head; Sprite *_tail; @@ -219,7 +218,6 @@ public: void clear(); }; - class Vga { uint16 _oldMode; uint16 *_oldScreen; @@ -282,10 +280,8 @@ public: PocLight(CGEEngine *vm); }; - Dac mkDac(uint8 r, uint8 g, uint8 b); - template uint8 closest(CBLK *pal, CBLK x) { #define f(col, lum) ((((uint16)(col)) << 8) / lum) @@ -316,7 +312,7 @@ uint8 closest(CBLK *pal, CBLK x) { } uint16 *saveScreen(); -void restoreScreen(uint16 * &sav); +void restoreScreen(uint16 * &sav); Sprite *spriteAt(int x, int y); Sprite *locate(int ref); From 749cd3b1159d132a2dc58afdf1817b1cee41f634 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 20 Aug 2011 00:03:44 +0200 Subject: [PATCH 229/276] CGE: Another fix for the pathfinding --- engines/cge/walk.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 914f6db6693..ccbb0e5532f 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -47,12 +47,6 @@ bool Cluster::isValid() const { return (_a >= 0) && (_a < kMapXCnt) && (_b >= 0) && (_b < kMapZCnt); } -bool Cluster::chkBar() const { - assert(_vm->_now <= _vm->_caveMax); - return (_a < 0) || (_b < 0) || (_a >= _vm->_barriers[_vm->_now]._horz) || - (_b >= _vm->_barriers[_vm->_now]._vert); -} - Cluster XZ(int x, int y) { if (y < kMapTop) y = kMapTop; @@ -230,6 +224,11 @@ void Walk::noWay() { _vm->trouble(kSeqNoWay, kNoWay); } +bool Cluster::chkBar() const { + assert(_vm->_now <= _vm->_caveMax); + return (_a == _vm->_barriers[_vm->_now]._horz) || (_b == _vm->_barriers[_vm->_now]._vert); +} + bool Walk::find1Way(Cluster c) { Cluster start = c; const Cluster tab[4] = { Cluster(-1, 0), Cluster(1, 0), Cluster(0, -1), Cluster(0, 1)}; @@ -251,7 +250,6 @@ bool Walk::find1Way(Cluster c) { // Location is occupied return false; - // Loop through each direction for (int i = 0; i < tabLen; i++) { // Reset to starting position From c1807138fbb9dca4ff2d59f8c5ed39385716c6a0 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Sat, 20 Aug 2011 00:11:30 +0200 Subject: [PATCH 230/276] CGE: Cleanup of snail.cpp. --- engines/cge/snail.cpp | 1039 ++++++++++++++++++++--------------------- engines/cge/snail.h | 1 - 2 files changed, 515 insertions(+), 525 deletions(-) diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index ea8e480b350..ef766b9a4e3 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -40,7 +40,7 @@ void CGEEngine::snGame(Sprite *spr, int num) { debugC(1, kCGEDebugEngine, "CGEEngine::snGame(spr, %d)", num); switch (num) { - case 1 : { + case 1: { static Sprite *dup[3] = { NULL, NULL, NULL }; int buref = 0; int Stage = 0; @@ -125,10 +125,9 @@ void CGEEngine::snGame(Sprite *spr, int num) { _snail->addCom(kSnSay, buref, 16008, NULL); // zgadnij! _game = true; } - } - break; - //-------------------------------------------------------------------- - case 2 : { + } + break; + case 2: if (_sprTv == NULL) { _sprTv = _vga->_showQ->locate(20700); _sprK1 = _vga->_showQ->locate(20701); @@ -139,105 +138,108 @@ void CGEEngine::snGame(Sprite *spr, int num) { if (!_game) { // init _snail->addCom(kSnGame, 20002, 2, NULL); _game = true; - } else { // cont - _sprK1->step(newRandom(6)); - _sprK2->step(newRandom(6)); - _sprK3->step(newRandom(6)); - ///-------------------- - if (spr->_ref == 1 && _keyboard->_key[kKeyAlt]) { - _sprK1->step(5); - _sprK2->step(5); - _sprK3->step(5); - } - ///-------------------- - _snail->addCom(kSnSetZ, 20700, 0, NULL); - bool hit = (_sprK1->_seqPtr + _sprK2->_seqPtr + _sprK3->_seqPtr == 15); - if (hit) { - if (spr->_ref == 1) { - _snail->addCom(kSnSay, 1, 20003, NULL); // hura! - _snail->addCom(kSnSeq, 20011, 2, NULL); // kamera won - _snail->addCom(kSnSend, 20701, -1, NULL); // k1 won - _snail->addCom(kSnSend, 20702, -1, NULL); // k2 won - _snail->addCom(kSnSend, 20703, -1, NULL); // k3 won - _snail->addCom(kSnSend, 20700, -1, NULL); // tv won - _snail->addCom(kSnKeep, 20007, 0, NULL); // do kieszeni - _snail->addCom(kSnSend, 20006, 20, NULL); // bilon - _snail->addCom(kSnSound, 20006, 20002, NULL); // bilon! - _snail->addCom(kSnSay, 20002, 20004, NULL); - _snail->addCom(kSnSend, 20010, 20, NULL); // papier - _snail->addCom(kSnSound, 20010, 20003, NULL); // papier! - _snail->addCom(kSnSay, 20001, 20005, NULL); - _game = false; - return; - } else - _sprK3->step(newRandom(5)); - } - if (_gameCase2Cpt < 100) { - switch (_gameCase2Cpt) { - case 15 : - _snail->addCom(kSnSay, 20003, 20021, NULL); - break; - case 30 : - case 45 : - case 60 : - case 75 : - _snail->addCom(kSnSay, 20003, 20022, NULL); - break; - } - _gameCase2Cpt++; - } - switch (spr->_ref) { - case 1 : - _snail->addCom(kSnSay, 20001, 20011, NULL); // zapro - _snail->addCom(kSnSeq, 20001, 1, NULL); // rzu - _snail->addCom(kSnWait, 20001, 1, NULL); // czekaj - _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k - _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k - _snail->addCom(kSnWait, 20001, 16, NULL); // czekaj - _snail->addCom(kSnSeq, 20007, 1, NULL); // lec† - _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ - _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech - _snail->addCom(kSnWait, 20007, -1, NULL); // koniec - _snail->addCom(kSnGame, 20001, 2, NULL); // again! + break; + } + + // cont + _sprK1->step(newRandom(6)); + _sprK2->step(newRandom(6)); + _sprK3->step(newRandom(6)); + + if (spr->_ref == 1 && _keyboard->_key[kKeyAlt]) { + _sprK1->step(5); + _sprK2->step(5); + _sprK3->step(5); + } + + _snail->addCom(kSnSetZ, 20700, 0, NULL); + bool hit = (_sprK1->_seqPtr + _sprK2->_seqPtr + _sprK3->_seqPtr == 15); + if (hit) { + if (spr->_ref == 1) { + _snail->addCom(kSnSay, 1, 20003, NULL); // hura! + _snail->addCom(kSnSeq, 20011, 2, NULL); // kamera won + _snail->addCom(kSnSend, 20701, -1, NULL); // k1 won + _snail->addCom(kSnSend, 20702, -1, NULL); // k2 won + _snail->addCom(kSnSend, 20703, -1, NULL); // k3 won + _snail->addCom(kSnSend, 20700, -1, NULL); // tv won + _snail->addCom(kSnKeep, 20007, 0, NULL); // do kieszeni + _snail->addCom(kSnSend, 20006, 20, NULL); // bilon + _snail->addCom(kSnSound, 20006, 20002, NULL); // bilon! + _snail->addCom(kSnSay, 20002, 20004, NULL); + _snail->addCom(kSnSend, 20010, 20, NULL); // papier + _snail->addCom(kSnSound, 20010, 20003, NULL); // papier! + _snail->addCom(kSnSay, 20001, 20005, NULL); + _game = false; + return; + } else + _sprK3->step(newRandom(5)); + } + + if (_gameCase2Cpt < 100) { + switch (_gameCase2Cpt) { + case 15: + _snail->addCom(kSnSay, 20003, 20021, NULL); break; - case 20001: - _snail->addCom(kSnSay, 20002, 20012, NULL); // zapro - _snail->addCom(kSnSeq, 20002, 1, NULL); // rzu - _snail->addCom(kSnWait, 20002, 3, NULL); // czekaj - _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k - _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k - _snail->addCom(kSnWait, 20002, 10, NULL); // czekaj - _snail->addCom(kSnSeq, 20007, 2, NULL); // lec† - _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ - _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech - _snail->addCom(kSnWait, 20007, -1, NULL); // koniec - _snail->addCom(kSnGame, 20002, 2, NULL); // again! - break; - case 20002: - _snail->addCom(kSnSay, 20002, 20010, NULL); // zapro - _snail->addCom(kSnWalk, 20005, -1, NULL); // do stol - _snail->addCom(kSnWait, 1, -1, NULL); // stoi - _snail->addCom(kSnCover, 1, 20101, NULL); // grasol - _snail->addCom(kSnSeq, 20101, 1, NULL); // rzu - _snail->addCom(kSnWait, 20101, 5, NULL); // czekaj - _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k - _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k - _snail->addCom(kSnWait, 20101, 15, NULL); // czekaj - _snail->addCom(kSnSeq, 20007, 1, NULL); // lec† - _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ - _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech - _snail->addCom(kSnWait, 20101, -1, NULL); // koniec - _snail->addCom(kSnUncover, 1, 20101, NULL); // SDS - _snail->addCom(kSnGame, 1, 2, NULL); // again! + case 30: + case 45: + case 60: + case 75: + _snail->addCom(kSnSay, 20003, 20022, NULL); break; } + _gameCase2Cpt++; + } + + switch (spr->_ref) { + case 1: + _snail->addCom(kSnSay, 20001, 20011, NULL); // zapro + _snail->addCom(kSnSeq, 20001, 1, NULL); // rzu + _snail->addCom(kSnWait, 20001, 1, NULL); // czekaj + _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k + _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k + _snail->addCom(kSnWait, 20001, 16, NULL); // czekaj + _snail->addCom(kSnSeq, 20007, 1, NULL); // lec† + _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ + _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech + _snail->addCom(kSnWait, 20007, -1, NULL); // koniec + _snail->addCom(kSnGame, 20001, 2, NULL); // again! + break; + + case 20001: + _snail->addCom(kSnSay, 20002, 20012, NULL); // zapro + _snail->addCom(kSnSeq, 20002, 1, NULL); // rzu + _snail->addCom(kSnWait, 20002, 3, NULL); // czekaj + _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k + _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k + _snail->addCom(kSnWait, 20002, 10, NULL); // czekaj + _snail->addCom(kSnSeq, 20007, 2, NULL); // lec† + _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ + _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech + _snail->addCom(kSnWait, 20007, -1, NULL); // koniec + _snail->addCom(kSnGame, 20002, 2, NULL); // again! + break; + + case 20002: + _snail->addCom(kSnSay, 20002, 20010, NULL); // zapro + _snail->addCom(kSnWalk, 20005, -1, NULL); // do stol + _snail->addCom(kSnWait, 1, -1, NULL); // stoi + _snail->addCom(kSnCover, 1, 20101, NULL); // grasol + _snail->addCom(kSnSeq, 20101, 1, NULL); // rzu + _snail->addCom(kSnWait, 20101, 5, NULL); // czekaj + _snail->addCom(kSnSetZ, 20700, 2, NULL); // skryj k + _snail->addCom(kSnHide, 20007, 1, NULL); // skryj k + _snail->addCom(kSnWait, 20101, 15, NULL); // czekaj + _snail->addCom(kSnSeq, 20007, 1, NULL); // lec† + _snail->addCom(kSnHide, 20007, 0, NULL); // poka§ + _snail->addCom(kSnSound, 20007, 20001, NULL); // grzech + _snail->addCom(kSnWait, 20101, -1, NULL); // koniec + _snail->addCom(kSnUncover, 1, 20101, NULL); // SDS + _snail->addCom(kSnGame, 1, 2, NULL); // again! + break; } } - break; - } } - void CGEEngine::expandSprite(Sprite *spr) { debugC(5, kCGEDebugEngine, "CGEEngine::expandSprite(spr)"); @@ -245,7 +247,6 @@ void CGEEngine::expandSprite(Sprite *spr) { _vga->_showQ->insert(_vga->_spareQ->remove(spr)); } - void CGEEngine::contractSprite(Sprite *spr) { debugC(1, kCGEDebugEngine, "CGEEngine::contractSprite(spr)"); @@ -257,12 +258,11 @@ int CGEEngine::findPocket(Sprite *spr) { debugC(1, kCGEDebugEngine, "CGEEngine::findPocket(spr)"); for (int i = 0; i < kPocketNX; i++) - if (_pocket[i] == spr) - return i; + if (_pocket[i] == spr) + return i; return -1; } - void CGEEngine::selectPocket(int n) { debugC(1, kCGEDebugEngine, "CGEEngine::selectPocket(%d)", n); @@ -309,76 +309,77 @@ void CGEEngine::snGhost(Bitmap *bmp) { void CGEEngine::feedSnail(Sprite *spr, SnList snq) { debugC(1, kCGEDebugEngine, "CGEEngine::feedSnail(spr, snq)"); - if (spr) - if (spr->active()) { - uint8 ptr = (snq == kTake) ? spr->_takePtr : spr->_nearPtr; + if (!spr || !spr->active()) + return; - if (ptr != NO_PTR) { - Snail::Com *comtab = spr->snList(snq); - Snail::Com *c = comtab + ptr; + uint8 ptr = (snq == kTake) ? spr->_takePtr : spr->_nearPtr; - if (findPocket(NULL) < 0) { // no empty pockets? - Snail::Com *p; - for (p = c; p->_com != kSnNext; p++) { // find KEEP command - if (p->_com == kSnKeep) { - pocFul(); - return; - } - if (p->_ptr) - break; - } - } - while (true) { - if (c->_com == kSnTalk) { - if ((_snail->_talkEnable = (c->_val != 0)) == false) - killText(); - } - if (c->_com == kSnNext) { - Sprite *s = (c->_ref < 0) ? spr : locate(c->_ref); - if (s) { - uint8 *idx = (snq == kTake) ? &s->_takePtr : &s->_nearPtr; - if (*idx != NO_PTR) { - int v; - switch (c->_val) { - case -1 : - v = c - comtab + 1; - break; - case -2 : - v = c - comtab; - break; - case -3 : - v = -1; - break; - default : - v = c->_val; - break; - } - if (v >= 0) - *idx = v; - } - } - if (s == spr) - break; - } - if (c->_com == kSnIf) { - Sprite *s = (c->_ref < 0) ? spr : locate(c->_ref); - if (s) { // sprite extsts - if (! s->seqTest(-1)) - c = comtab + c->_val; // not parked - else - ++c; - } else - ++c; - } else { - _snail->addCom(c->_com, c->_ref, c->_val, spr); - if (c->_ptr) - break; - else - c++; + if (ptr == NO_PTR) + return; + + Snail::Com *comtab = spr->snList(snq); + Snail::Com *c = comtab + ptr; + + if (findPocket(NULL) < 0) { // no empty pockets? + Snail::Com *p; + for (p = c; p->_com != kSnNext; p++) { // find KEEP command + if (p->_com == kSnKeep) { + pocFul(); + return; + } + if (p->_ptr) + break; + } + } + while (true) { + if (c->_com == kSnTalk) { + if ((_snail->_talkEnable = (c->_val != 0)) == false) + killText(); + } + if (c->_com == kSnNext) { + Sprite *s = (c->_ref < 0) ? spr : locate(c->_ref); + if (s) { + uint8 *idx = (snq == kTake) ? &s->_takePtr : &s->_nearPtr; + if (*idx != NO_PTR) { + int v; + switch (c->_val) { + case -1 : + v = c - comtab + 1; + break; + case -2 : + v = c - comtab; + break; + case -3 : + v = -1; + break; + default : + v = c->_val; + break; } + if (v >= 0) + *idx = v; } } + if (s == spr) + break; } + if (c->_com == kSnIf) { + Sprite *s = (c->_ref < 0) ? spr : locate(c->_ref); + if (s) { // sprite extsts + if (! s->seqTest(-1)) + c = comtab + c->_val; // not parked + else + ++c; + } else + ++c; + } else { + _snail->addCom(c->_com, c->_ref, c->_val, spr); + if (c->_ptr) + break; + else + c++; + } + } } const char *Snail::_comText[] = { @@ -395,7 +396,6 @@ const char *Snail::_comText[] = { "MOUSE", "SOUND", "COUNT", NULL }; - Snail::Snail(CGEEngine *vm, bool turbo) : _turbo(turbo), _busy(false), _textDelay(false), _timerExpiry(0), _talkEnable(true), @@ -490,16 +490,15 @@ void CGEEngine::snRTNext(Sprite *spr, int p) { void CGEEngine::snZTrim(Sprite *spr) { debugC(4, kCGEDebugEngine, "CGEEngine::snZTrim(spr)"); - if (spr) - if (spr->active()) { - Sprite *s; - s = (spr->_flags._shad) ? spr->_prev : NULL; - _vga->_showQ->insert(_vga->_showQ->remove(spr)); - if (s) { - s->_z = spr->_z; - _vga->_showQ->insert(_vga->_showQ->remove(s), spr); - } - } + if (!spr || !spr->active()) + return; + + Sprite *s = (spr->_flags._shad) ? spr->_prev : NULL; + _vga->_showQ->insert(_vga->_showQ->remove(spr)); + if (s) { + s->_z = spr->_z; + _vga->_showQ->insert(_vga->_showQ->remove(s), spr); + } } void CGEEngine::snHide(Sprite *spr, int val) { @@ -547,30 +546,31 @@ void CGEEngine::snRSeq(Sprite *spr, int val) { void CGEEngine::snSend(Sprite *spr, int val) { debugC(1, kCGEDebugEngine, "CGEEngine::snSend(spr, %d)", val); - if (spr) { - int was = spr->_cave; - bool was1 = (was == 0 || was == _now); - bool val1 = (val == 0 || val == _now); - spr->_cave = val; - if (val1 != was1) { - if (was1) { - if (spr->_flags._kept) { - int n = findPocket(spr); - if (n >= 0) - _pocket[n] = NULL; - } - hide1(spr); - contractSprite(spr); - spr->_flags._slav = false; - } else { - if (spr->_ref % 1000 == 0) - Bitmap::_pal = Vga::_sysPal; - if (spr->_flags._back) - spr->backShow(true); - else - expandSprite(spr); - Bitmap::_pal = NULL; + if (!spr) + return; + + int was = spr->_cave; + bool was1 = (was == 0 || was == _now); + bool val1 = (val == 0 || val == _now); + spr->_cave = val; + if (val1 != was1) { + if (was1) { + if (spr->_flags._kept) { + int n = findPocket(spr); + if (n >= 0) + _pocket[n] = NULL; } + hide1(spr); + contractSprite(spr); + spr->_flags._slav = false; + } else { + if (spr->_ref % 1000 == 0) + Bitmap::_pal = Vga::_sysPal; + if (spr->_flags._back) + spr->backShow(true); + else + expandSprite(spr); + Bitmap::_pal = NULL; } } } @@ -579,76 +579,76 @@ void CGEEngine::snSwap(Sprite *spr, int xref) { debugC(1, kCGEDebugEngine, "CGEEngine::snSwap(spr, %d)", xref); Sprite *xspr = locate(xref); - if (spr && xspr) { - int was = spr->_cave; - int xwas = xspr->_cave; - bool was1 = (was == 0 || was == _now); - bool xwas1 = (xwas == 0 || xwas == _now); + if (!spr || !xspr) + return; - swap(spr->_cave, xspr->_cave); - swap(spr->_x, xspr->_x); - swap(spr->_y, xspr->_y); - swap(spr->_z, xspr->_z); - if (spr->_flags._kept) { - int n = findPocket(spr); - if (n >= 0) - _pocket[n] = xspr; - xspr->_flags._kept = true; - xspr->_flags._port = false; - } - if (xwas1 != was1) { - if (was1) { - hide1(spr); - contractSprite(spr); - } else - expandSprite(spr); - if (xwas1) { - hide1(xspr); - contractSprite(xspr); - } else - expandSprite(xspr); - } + int was = spr->_cave; + int xwas = xspr->_cave; + bool was1 = (was == 0 || was == _now); + bool xwas1 = (xwas == 0 || xwas == _now); + + swap(spr->_cave, xspr->_cave); + swap(spr->_x, xspr->_x); + swap(spr->_y, xspr->_y); + swap(spr->_z, xspr->_z); + if (spr->_flags._kept) { + int n = findPocket(spr); + if (n >= 0) + _pocket[n] = xspr; + xspr->_flags._kept = true; + xspr->_flags._port = false; + } + if (xwas1 != was1) { + if (was1) { + hide1(spr); + contractSprite(spr); + } else + expandSprite(spr); + if (xwas1) { + hide1(xspr); + contractSprite(xspr); + } else + expandSprite(xspr); } } - void CGEEngine::snCover(Sprite *spr, int xref) { debugC(1, kCGEDebugEngine, "CGEEngine::snCover(spr, %d)", xref); Sprite *xspr = locate(xref); - if (spr && xspr) { - spr->_flags._hide = true; - xspr->_z = spr->_z; - xspr->_cave = spr->_cave; - xspr->gotoxy(spr->_x, spr->_y); - expandSprite(xspr); - if ((xspr->_flags._shad = spr->_flags._shad) == 1) { - _vga->_showQ->insert(_vga->_showQ->remove(spr->_prev), xspr); - spr->_flags._shad = false; - } - feedSnail(xspr, kNear); - } -} + if (!spr || !xspr) + return; + spr->_flags._hide = true; + xspr->_z = spr->_z; + xspr->_cave = spr->_cave; + xspr->gotoxy(spr->_x, spr->_y); + expandSprite(xspr); + if ((xspr->_flags._shad = spr->_flags._shad) == 1) { + _vga->_showQ->insert(_vga->_showQ->remove(spr->_prev), xspr); + spr->_flags._shad = false; + } + feedSnail(xspr, kNear); +} void CGEEngine::snUncover(Sprite *spr, Sprite *xspr) { debugC(1, kCGEDebugEngine, "CGEEngine::snUncover(spr, xspr)"); - if (spr && xspr) { - spr->_flags._hide = false; - spr->_cave = xspr->_cave; - spr->gotoxy(xspr->_x, xspr->_y); - if ((spr->_flags._shad = xspr->_flags._shad) == 1) { - _vga->_showQ->insert(_vga->_showQ->remove(xspr->_prev), spr); - xspr->_flags._shad = false; - } - spr->_z = xspr->_z; - snSend(xspr, -1); - if (spr->_time == 0) - spr->_time++; - } -} + if (!spr || !xspr) + return; + spr->_flags._hide = false; + spr->_cave = xspr->_cave; + spr->gotoxy(xspr->_x, xspr->_y); + if ((spr->_flags._shad = xspr->_flags._shad) == 1) { + _vga->_showQ->insert(_vga->_showQ->remove(xspr->_prev), spr); + xspr->_flags._shad = false; + } + spr->_z = xspr->_z; + snSend(xspr, -1); + if (spr->_time == 0) + spr->_time++; +} void CGEEngine::snSetX0(int cav, int x0) { debugC(1, kCGEDebugEngine, "CGEEngine::snSetX0(%d, %d)", cav, x0); @@ -683,7 +683,6 @@ void CGEEngine::snRelY(Sprite *spr, int y) { spr->gotoxy(spr->_x, _hero->_y + y); } - void CGEEngine::snRelZ(Sprite *spr, int z) { debugC(1, kCGEDebugEngine, "CGEEngine::snRelZ(spr, %d)", z); @@ -693,7 +692,6 @@ void CGEEngine::snRelZ(Sprite *spr, int z) { } } - void CGEEngine::snSetX(Sprite *spr, int x) { debugC(1, kCGEDebugEngine, "CGEEngine::snSetX(spr, %d)", x); @@ -701,7 +699,6 @@ void CGEEngine::snSetX(Sprite *spr, int x) { spr->gotoxy(x, spr->_y); } - void CGEEngine::snSetY(Sprite *spr, int y) { debugC(1, kCGEDebugEngine, "CGEEngine::snSetY(spr, %d)", y); @@ -709,7 +706,6 @@ void CGEEngine::snSetY(Sprite *spr, int y) { spr->gotoxy(spr->_x, y); } - void CGEEngine::snSetZ(Sprite *spr, int z) { debugC(1, kCGEDebugEngine, "CGEEngine::snSetZ(spr, %d)", z); @@ -720,7 +716,6 @@ void CGEEngine::snSetZ(Sprite *spr, int z) { } } - void CGEEngine::snSlave(Sprite *spr, int ref) { debugC(1, kCGEDebugEngine, "CGEEngine::snSlave(spr, %d)", ref); @@ -735,7 +730,6 @@ void CGEEngine::snSlave(Sprite *spr, int ref) { } } - void CGEEngine::snTrans(Sprite *spr, int trans) { debugC(1, kCGEDebugEngine, "CGEEngine::snTrans(spr, %d)", trans); @@ -753,30 +747,30 @@ void CGEEngine::snPort(Sprite *spr, int port) { void CGEEngine::snKill(Sprite *spr) { debugC(1, kCGEDebugEngine, "CGEEngine::snKill(spr)"); - if (spr) { - if (spr->_flags._kept) { - int n = findPocket(spr); - if (n >= 0) - _pocket[n] = NULL; - } - Sprite *nx = spr->_next; - hide1(spr); - _vga->_showQ->remove(spr); - _eventManager->clearEvent(spr); - if (spr->_flags._kill) - delete spr; - else { - spr->_cave = -1; - _vga->_spareQ->append(spr); - } - if (nx) { - if (nx->_flags._slav) - snKill(nx); - } + if (!spr) + return; + + if (spr->_flags._kept) { + int n = findPocket(spr); + if (n >= 0) + _pocket[n] = NULL; + } + Sprite *nx = spr->_next; + hide1(spr); + _vga->_showQ->remove(spr); + _eventManager->clearEvent(spr); + if (spr->_flags._kill) { + delete spr; + } else { + spr->_cave = -1; + _vga->_spareQ->append(spr); + } + if (nx) { + if (nx->_flags._slav) + snKill(nx); } } - void CGEEngine::snSound(Sprite *spr, int wav, int cnt) { debugC(1, kCGEDebugEngine, "CGEEngine::snSound(spr, %d, %d)", wav, cnt); @@ -786,7 +780,6 @@ void CGEEngine::snSound(Sprite *spr, int wav, int cnt) { _sound->play((*_fx)[wav], (spr) ? ((spr->_x + spr->_w / 2) / (kScrWidth / 16)) : 8, cnt); } - void CGEEngine::snKeep(Sprite *spr, int stp) { debugC(1, kCGEDebugEngine, "CGEEngine::snKeep(spr, %d)", stp); @@ -846,7 +839,6 @@ void CGEEngine::snLevel(Sprite *spr, int lev) { spr->_flags._hide = false; } - void CGEEngine::snFlag(int indx, bool v) { _flag[indx] = v; } @@ -881,7 +873,6 @@ void CGEEngine::snFlash(bool on) { _dark = false; } - void CGEEngine::snLight(bool in) { debugC(1, kCGEDebugEngine, "CGEEngine::snLight(%s)", in ? "true" : "false"); @@ -889,7 +880,7 @@ void CGEEngine::snLight(bool in) { _vga->sunrise(Vga::_sysPal); else _vga->sunset(); - _dark = ! in; + _dark = !in; } void CGEEngine::snBarrier(int cav, int bar, bool horz) { @@ -925,253 +916,253 @@ void CGEEngine::snMouse(bool on) { _mouse->off(); } - void Snail::runCom() { static int count = 1; - if (!_busy) { - _busy = true; - uint8 tmpHead = _head; - while (_tail != tmpHead) { - Com *snc = &_snList[_tail]; - if (!_turbo) { // only for the slower one - if (_timerExpiry) { - // Delay in progress - if (_timerExpiry > g_system->getMillis()) - // Delay not yet ended - break; + if (_busy) + return; - // Delay is finished - _timerExpiry = 0; - } else { - if (_textDelay) { - killText(); - _textDelay = false; - } - } - if (_talk && snc->_com != kSnPause) + _busy = true; + uint8 tmpHead = _head; + while (_tail != tmpHead) { + Com *snc = &_snList[_tail]; + + if (!_turbo) { // only for the slower one + if (_timerExpiry) { + // Delay in progress + if (_timerExpiry > g_system->getMillis()) + // Delay not yet ended break; + + // Delay is finished + _timerExpiry = 0; + } else { + if (_textDelay) { + killText(); + _textDelay = false; + } } - - Sprite *spr = ((snc->_ref >= 0) ? locate(snc->_ref) : ((Sprite *) snc->_ptr)); - switch (snc->_com) { - case kSnLabel: - break; - case kSnPause : - _timerExpiry = g_system->getMillis() + snc->_val * kSnailFrameDelay; - if (_talk) - _textDelay = true; - break; - case kSnWait: - if (spr) { - if (spr->seqTest(snc->_val) && - (snc->_val >= 0 || spr != _hero || _hero->_tracePtr < 0)) { - _timerExpiry = g_system->getMillis() + spr->_time * kSnailFrameDelay; - } else - goto xit; - } - break; - case kSnLevel: - _vm->snLevel(spr, snc->_val); - break; - case kSnHide: - _vm->snHide(spr, snc->_val); - break; - case kSnSay: - if (spr && _talkEnable) { - if (spr == _hero && spr->seqTest(-1)) - spr->step(kSeqHTalk); - _text->say(_text->getText(snc->_val), spr); - _sys->_funDel = kHeroFun0; - } - break; - case kSnInf: - if (_talkEnable) { - _vm->inf(_text->getText(snc->_val)); - _sys->_funDel = kHeroFun0; - } - break; - case kSnTime: - if (spr && _talkEnable) { - if (spr == _hero && spr->seqTest(-1)) - spr->step(kSeqHTalk); - _text->sayTime(spr); - } - break; - case kSnCave: - _vm->switchCave(snc->_val); - break; - case kSnKill: - _vm->snKill(spr); - break; - case kSnSeq: - _vm->snSeq(spr, snc->_val); - break; - case kSnRSeq: - _vm->snRSeq(spr, snc->_val); - break; - case kSnSend: - _vm->snSend(spr, snc->_val); - break; - case kSnSwap: - _vm->snSwap(spr, snc->_val); - break; - case kSnCover: - _vm->snCover(spr, snc->_val); - break; - case kSnUncover: - _vm->snUncover(spr, (snc->_val >= 0) ? locate(snc->_val) : ((Sprite *) snc->_ptr)); - break; - case kSnKeep: - _vm->snKeep(spr, snc->_val); - break; - case kSnGive: - _vm->snGive(spr, snc->_val); - break; - case kSnGame: - _vm->snGame(spr, snc->_val); - break; - case kSnSetX0: - _vm->snSetX0(snc->_ref, snc->_val); - break; - case kSnSetY0: - _vm->snSetY0(snc->_ref, snc->_val); - break; - case kSnSetXY: - _vm->snSetXY(spr, snc->_val); - break; - case kSnRelX: - _vm->snRelX(spr, snc->_val); - break; - case kSnRelY: - _vm->snRelY(spr, snc->_val); - break; - case kSnRelZ: - _vm->snRelZ(spr, snc->_val); - break; - case kSnSetX: - _vm->snSetX(spr, snc->_val); - break; - case kSnSetY: - _vm->snSetY(spr, snc->_val); - break; - case kSnSetZ: - _vm->snSetZ(spr, snc->_val); - break; - case kSnSlave: - _vm->snSlave(spr, snc->_val); - break; - case kSnTrans: - _vm->snTrans(spr, snc->_val); - break; - case kSnPort: - _vm->snPort(spr, snc->_val); - break; - case kSnNext: - case kSnIf: - case kSnTalk: - break; - case kSnMouse: - _vm->snMouse(snc->_val != 0); - break; - case kSnNNext: - _vm->snNNext(spr, snc->_val); - break; - case kSnTNext: - _vm->snTNext(spr, snc->_val); - break; - case kSnRNNext: - _vm->snRNNext(spr, snc->_val); - break; - case kSnRTNext: - _vm->snRTNext(spr, snc->_val); - break; - case kSnRMNear: - _vm->snRmNear(spr); - break; - case kSnRmTake: - _vm->snRmTake(spr); - break; - case kSnFlag: - _vm->snFlag(snc->_ref & 3, snc->_val != 0); - break; - case kSnSetRef: - _vm->snSetRef(spr, snc->_val); - break; - case kSnBackPt: - _vm->snBackPt(spr, snc->_val); - break; - case kSnFlash: - _vm->snFlash(snc->_val != 0); - break; - case kSnLight: - _vm->snLight(snc->_val != 0); - break; - case kSnSetHBarrier: - _vm->snBarrier(snc->_ref, snc->_val, true); - break; - case kSnSetVBarrier: - _vm->snBarrier(snc->_ref, snc->_val, false); - break; - case kSnWalk: - _vm->snWalk(spr, snc->_ref, snc->_val); - break; - case kSnReach: - _vm->snReach(spr, snc->_val); - break; - case kSnSound: - _vm->snSound(spr, snc->_val, count); - count = 1; - break; - case kSnCount: - count = snc->_val; - break; - case kSnExec: - switch (snc->_cbType) { - case kQGame: - _vm->qGame(); - break; - case kMiniStep: - _vm->miniStep(snc->_val); - break; - case kXCave: - _vm->xCave(); - break; - case kSelectSound: - warning("TODO: Select sound card"); - break; - case kSnSelect: - warning("TODO: Sound card selection"); - break; - case kSndSetVolume: - sndSetVolume(); - break; - default: - error("Unknown Callback Type in SNEXEC"); - } - break; - case kSnStep: - spr->step(); - break; - case kSnZTrim: - _vm->snZTrim(spr); - break; - case kSnGhost: - _vm->snGhost((Bitmap *) snc->_ptr); - break; - default : - warning("Unhandled snc->_com in SNMouse(bool)"); - break; - } - _tail++; - if (!_turbo) + if (_talk && snc->_com != kSnPause) break; } -xit: - _busy = false; - } -} + Sprite *spr = ((snc->_ref >= 0) ? locate(snc->_ref) : ((Sprite *) snc->_ptr)); + switch (snc->_com) { + case kSnLabel: + break; + case kSnPause : + _timerExpiry = g_system->getMillis() + snc->_val * kSnailFrameDelay; + if (_talk) + _textDelay = true; + break; + case kSnWait: + if (spr) { + if (spr->seqTest(snc->_val) && + (snc->_val >= 0 || spr != _hero || _hero->_tracePtr < 0)) { + _timerExpiry = g_system->getMillis() + spr->_time * kSnailFrameDelay; + } else + goto xit; + } + break; + case kSnLevel: + _vm->snLevel(spr, snc->_val); + break; + case kSnHide: + _vm->snHide(spr, snc->_val); + break; + case kSnSay: + if (spr && _talkEnable) { + if (spr == _hero && spr->seqTest(-1)) + spr->step(kSeqHTalk); + _text->say(_text->getText(snc->_val), spr); + _sys->_funDel = kHeroFun0; + } + break; + case kSnInf: + if (_talkEnable) { + _vm->inf(_text->getText(snc->_val)); + _sys->_funDel = kHeroFun0; + } + break; + case kSnTime: + if (spr && _talkEnable) { + if (spr == _hero && spr->seqTest(-1)) + spr->step(kSeqHTalk); + _text->sayTime(spr); + } + break; + case kSnCave: + _vm->switchCave(snc->_val); + break; + case kSnKill: + _vm->snKill(spr); + break; + case kSnSeq: + _vm->snSeq(spr, snc->_val); + break; + case kSnRSeq: + _vm->snRSeq(spr, snc->_val); + break; + case kSnSend: + _vm->snSend(spr, snc->_val); + break; + case kSnSwap: + _vm->snSwap(spr, snc->_val); + break; + case kSnCover: + _vm->snCover(spr, snc->_val); + break; + case kSnUncover: + _vm->snUncover(spr, (snc->_val >= 0) ? locate(snc->_val) : ((Sprite *) snc->_ptr)); + break; + case kSnKeep: + _vm->snKeep(spr, snc->_val); + break; + case kSnGive: + _vm->snGive(spr, snc->_val); + break; + case kSnGame: + _vm->snGame(spr, snc->_val); + break; + case kSnSetX0: + _vm->snSetX0(snc->_ref, snc->_val); + break; + case kSnSetY0: + _vm->snSetY0(snc->_ref, snc->_val); + break; + case kSnSetXY: + _vm->snSetXY(spr, snc->_val); + break; + case kSnRelX: + _vm->snRelX(spr, snc->_val); + break; + case kSnRelY: + _vm->snRelY(spr, snc->_val); + break; + case kSnRelZ: + _vm->snRelZ(spr, snc->_val); + break; + case kSnSetX: + _vm->snSetX(spr, snc->_val); + break; + case kSnSetY: + _vm->snSetY(spr, snc->_val); + break; + case kSnSetZ: + _vm->snSetZ(spr, snc->_val); + break; + case kSnSlave: + _vm->snSlave(spr, snc->_val); + break; + case kSnTrans: + _vm->snTrans(spr, snc->_val); + break; + case kSnPort: + _vm->snPort(spr, snc->_val); + break; + case kSnNext: + case kSnIf: + case kSnTalk: + break; + case kSnMouse: + _vm->snMouse(snc->_val != 0); + break; + case kSnNNext: + _vm->snNNext(spr, snc->_val); + break; + case kSnTNext: + _vm->snTNext(spr, snc->_val); + break; + case kSnRNNext: + _vm->snRNNext(spr, snc->_val); + break; + case kSnRTNext: + _vm->snRTNext(spr, snc->_val); + break; + case kSnRMNear: + _vm->snRmNear(spr); + break; + case kSnRmTake: + _vm->snRmTake(spr); + break; + case kSnFlag: + _vm->snFlag(snc->_ref & 3, snc->_val != 0); + break; + case kSnSetRef: + _vm->snSetRef(spr, snc->_val); + break; + case kSnBackPt: + _vm->snBackPt(spr, snc->_val); + break; + case kSnFlash: + _vm->snFlash(snc->_val != 0); + break; + case kSnLight: + _vm->snLight(snc->_val != 0); + break; + case kSnSetHBarrier: + _vm->snBarrier(snc->_ref, snc->_val, true); + break; + case kSnSetVBarrier: + _vm->snBarrier(snc->_ref, snc->_val, false); + break; + case kSnWalk: + _vm->snWalk(spr, snc->_ref, snc->_val); + break; + case kSnReach: + _vm->snReach(spr, snc->_val); + break; + case kSnSound: + _vm->snSound(spr, snc->_val, count); + count = 1; + break; + case kSnCount: + count = snc->_val; + break; + case kSnExec: + switch (snc->_cbType) { + case kQGame: + _vm->qGame(); + break; + case kMiniStep: + _vm->miniStep(snc->_val); + break; + case kXCave: + _vm->xCave(); + break; + case kSelectSound: + warning("TODO: Select sound card"); + break; + case kSnSelect: + warning("TODO: Sound card selection"); + break; + case kSndSetVolume: + sndSetVolume(); + break; + default: + error("Unknown Callback Type in SNEXEC"); + } + break; + case kSnStep: + spr->step(); + break; + case kSnZTrim: + _vm->snZTrim(spr); + break; + case kSnGhost: + _vm->snGhost((Bitmap *) snc->_ptr); + break; + default: + warning("Unhandled snc->_com in SNMouse(bool)"); + break; + } + _tail++; + if (!_turbo) + break; + } +xit: + _busy = false; +} bool Snail::idle() { return (_head == _tail); diff --git a/engines/cge/snail.h b/engines/cge/snail.h index 2d12963f2c5..e478ad95ff1 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -80,7 +80,6 @@ private: CGEEngine *_vm; }; - } // End of namespace CGE #endif From e4a37322a6678aa3874d96ce131bebbccbdd7a44 Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Sat, 20 Aug 2011 00:23:45 +0200 Subject: [PATCH 231/276] CGE: More misc cleanup. --- engines/cge/btfile.cpp | 4 --- engines/cge/events.cpp | 1 - engines/cge/sound.cpp | 19 ++----------- engines/cge/text.cpp | 62 ++++++++++++++++++++---------------------- engines/cge/walk.cpp | 19 ++++--------- 5 files changed, 39 insertions(+), 66 deletions(-) diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 053f264b351..a4d16010e5f 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -48,7 +48,6 @@ BtFile::BtFile(const char *name, IOMode mode, Crypt *crpt) } } - BtFile::~BtFile() { debugC(1, kCGEDebugFile, "BtFile::~BtFile()"); for (int i = 0; i < kBtLevel; i++) { @@ -57,7 +56,6 @@ BtFile::~BtFile() { } } - void BtFile::putPage(int lev, bool hard) { debugC(1, kCGEDebugFile, "BtFile::putPage(%d, %s)", lev, hard ? "true" : "false"); @@ -68,7 +66,6 @@ void BtFile::putPage(int lev, bool hard) { } } - BtPage *BtFile::getPage(int lev, uint16 pgn) { debugC(1, kCGEDebugFile, "BtFile::getPage(%d, %d)", lev, pgn); @@ -130,7 +127,6 @@ BtKeypack *BtFile::find(const char *key) { return NULL; } - int keycomp(const void *k1, const void *k2) { return scumm_strnicmp((const char *) k1, (const char*) k2, kBtKeySize); } diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 6e23b4e6139..5af5a9ee3fd 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -179,7 +179,6 @@ Mouse::Mouse(CGEEngine *vm) : Sprite(vm, NULL), _busy(NULL), _hold(NULL), _hx(0) step(1); } - Mouse::~Mouse() { off(); } diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index b22548c16d3..432bca75b53 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -42,22 +42,18 @@ Sound::Sound(CGEEngine *vm) : _vm(vm) { open(); } - Sound::~Sound() { close(); } - void Sound::close() { _vm->_midiPlayer.killMidi(); } - void Sound::open() { play((*_fx)[30000], 8); } - void Sound::play(DataCk *wav, int pan, int cnt) { if (wav) { stop(); @@ -97,16 +93,13 @@ Fx::Fx(int size) : _current(NULL) { } } - Fx::~Fx() { clear(); delete[] _cache; } - void Fx::clear() { - Han *p, * q; - for (p = _cache, q = p + _size; p < q; p++) { + for (Han *p = _cache, *q = p + _size; p < q; p++) { if (p->_ref) { p->_ref = 0; delete p->_wav; @@ -116,11 +109,9 @@ void Fx::clear() { _current = NULL; } - int Fx::find(int ref) { - Han *p, * q; int i = 0; - for (p = _cache, q = p + _size; p < q; p++) { + for (Han *p = _cache, *q = p + _size; p < q; p++) { if (p->_ref == ref) break; else @@ -129,12 +120,10 @@ int Fx::find(int ref) { return i; } - void Fx::preload(int ref0) { Han *cacheLim = _cache + _size; - int ref; - for (ref = ref0; ref < ref0 + 10; ref++) { + for (int ref = ref0; ref < ref0 + 10; ref++) { static char fname[] = "FX00000.WAV"; wtom(ref, fname + 2, 10, 5); INI_FILE file = INI_FILE(fname); @@ -149,7 +138,6 @@ void Fx::preload(int ref0) { } } - DataCk *Fx::load(int idx, int ref) { static char fname[] = "FX00000.WAV"; wtom(ref, fname + 2, 10, 5); @@ -164,7 +152,6 @@ DataCk *Fx::load(int idx, int ref) { return wav; } - DataCk *Fx::operator [](int ref) { int i; if ((i = find(ref)) < _size) diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 7e58762afa9..0e6fc409201 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -79,44 +79,44 @@ int Text::find(int ref) { void Text::preload(int from, int upto) { INI_FILE tf = _fileName; - if (!tf._error) { - Han *CacheLim = _cache + _size; - char line[kLineMax + 1]; - int n; + if (tf._error) + return; - while ((n = tf.read((uint8 *)line)) != 0) { - char *s; + Han *CacheLim = _cache + _size; + char line[kLineMax + 1]; + int n; - if (line[n - 1] == '\n') - line[--n] = '\0'; + while ((n = tf.read((uint8 *)line)) != 0) { + if (line[n - 1] == '\n') + line[--n] = '\0'; - if ((s = strtok(line, " =,;/\t\n")) == NULL) - continue; - if (!IsDigit(*s)) - continue; + char *s; + if ((s = strtok(line, " =,;/\t\n")) == NULL) + continue; + if (!IsDigit(*s)) + continue; - int ref = atoi(s); - if (ref && ref >= from && ref < upto) { - Han *p = &_cache[find(ref)]; + int ref = atoi(s); + if (ref && ref >= from && ref < upto) { + Han *p = &_cache[find(ref)]; - if (p < CacheLim) { - delete[] p->_text; - p->_text = NULL; - } else - p = &_cache[find(0)]; + if (p < CacheLim) { + delete[] p->_text; + p->_text = NULL; + } else + p = &_cache[find(0)]; - if (p >= CacheLim) - break; + if (p >= CacheLim) + break; - s += strlen(s); - if (s < line + n) - ++s; - if ((p->_text = new char[strlen(s) + 1]) == NULL) - break; + s += strlen(s); + if (s < line + n) + ++s; + if ((p->_text = new char[strlen(s) + 1]) == NULL) + break; - p->_ref = ref; - strcpy(p->_text, s); - } + p->_ref = ref; + strcpy(p->_text, s); } } } @@ -161,7 +161,6 @@ char *Text::load(int idx, int ref) { return NULL; } - char *Text::getText(int ref) { int i; if ((i = find(ref)) < _size) @@ -177,7 +176,6 @@ char *Text::getText(int ref) { return load(i, ref); } - void Text::say(const char *text, Sprite *spr) { killText(); _talk = new Talk(_vm, text, kTBRound); diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index ccbb0e5532f..95cc92afd4e 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -57,7 +57,6 @@ Cluster XZ(int x, int y) { return Cluster(x / kMapGridX, (y - kMapTop) / kMapGridZ); } - Cluster XZ(Couple xy) { signed char x, y; xy.split(x, y); @@ -68,7 +67,6 @@ Walk::Walk(CGEEngine *vm, BitmapPtr *shpl) : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _target(-1, -1), _findLevel(-1), _vm(vm) { } - void Walk::tick() { if (_flags._hide) return; @@ -76,9 +74,8 @@ void Walk::tick() { _here = XZ(_x + _w / 2, _y + _h); if (_dir != kDirNone) { - Sprite *spr; _sys->funTouch(); - for (spr = _vga->_showQ->first(); spr; spr = spr->_next) { + for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { if (distance(spr) < 2) { if (!spr->_flags._near) { _vm->feedSnail(spr, kNear); @@ -103,8 +100,10 @@ void Walk::tick() { turn(d); } } + step(); - if ((_dir == kDirWest && _x <= 0) || + + if ((_dir == kDirWest && _x <= 0) || (_dir == kDirEast && _x + _w >= kScrWidth) || (_dir == kDirSouth && _y + _w >= kWorldHeight - 2)) { park(); @@ -115,7 +114,6 @@ void Walk::tick() { } } - int Walk::distance(Sprite *spr) { int dx = spr->_x - (_x + _w - kWalkSide); if (dx < 0) @@ -136,7 +134,6 @@ int Walk::distance(Sprite *spr) { return dz - 1; } - void Walk::turn(Dir d) { Dir dir = (_dir == kDirNone) ? kDirSouth : _dir; if (d != _dir) { @@ -145,7 +142,6 @@ void Walk::turn(Dir d) { } } - void Walk::park() { if (_time == 0) _time++; @@ -157,7 +153,6 @@ void Walk::park() { } } - void Walk::findWay(Cluster c) { if (c == _here) return; @@ -171,13 +166,13 @@ void Walk::findWay(Cluster c) { if (find1Way(Cluster(x, z))) break; } + _tracePtr = (_findLevel > kMaxFindLevel) ? -1 : (_findLevel - 1); if (_tracePtr < 0) noWay(); _time = 1; } - void Walk::findWay(Sprite *spr) { if (!spr || spr == this) return; @@ -194,12 +189,10 @@ void Walk::findWay(Sprite *spr) { : (z - 1)))); } - bool Walk::lower(Sprite *spr) { return (spr->_y > _y + (_h * 3) / 5); } - void Walk::reach(Sprite *spr, int mode) { if (spr) { _hero->findWay(spr); @@ -230,7 +223,6 @@ bool Cluster::chkBar() const { } bool Walk::find1Way(Cluster c) { - Cluster start = c; const Cluster tab[4] = { Cluster(-1, 0), Cluster(1, 0), Cluster(0, -1), Cluster(0, 1)}; const int tabLen = 4; @@ -251,6 +243,7 @@ bool Walk::find1Way(Cluster c) { return false; // Loop through each direction + Cluster start = c; for (int i = 0; i < tabLen; i++) { // Reset to starting position c = start; From e916f9ce8c284a429798ea2dc74fd0b6fc1b09ab Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Sat, 20 Aug 2011 00:40:44 +0200 Subject: [PATCH 232/276] CGE: Another few formatting tweaks. --- engines/cge/bitmap.cpp | 2 +- engines/cge/cge_main.cpp | 11 +++-------- engines/cge/snddrv.h | 2 +- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 1de10e2bfdd..f9eae101cee 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -223,7 +223,7 @@ BitmapPtr Bitmap::code() { skip = (pix == kPixelTransp); cnt = 0; } - if (! skip) { + if (!skip) { if (_v) *im = pix; im++; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 99cb5d487fc..fb92f93e01f 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -369,7 +369,6 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt } } debugC(1, kCGEDebugEngine, "CGEEngine::saveSound()"); - } bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header) { @@ -401,7 +400,6 @@ bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &heade header.saveMinutes = in->readSint16LE(); return true; - } void CGEEngine::heroCover(int cvr) { @@ -546,9 +544,9 @@ void CGEEngine::AltCtrlDel() { void CGEEngine::miniStep(int stp) { debugC(1, kCGEDebugEngine, "CGEEngine::miniStep(%d)", stp); - if (stp < 0) + if (stp < 0) { _miniCave->_flags._hide = true; - else { + } else { *_miniShp[0] = *_miniShpList[stp]; if (_fx->_current) &*(_fx->_current->addr()); @@ -640,7 +638,6 @@ void CGEEngine::caveUp() { _mouse->on(); } - void CGEEngine::caveDown() { debugC(1, kCGEDebugEngine, "CGEEngine::caveDown()"); @@ -656,6 +653,7 @@ void CGEEngine::caveDown() { } spr = n; } + _text->clear(1000); } @@ -867,7 +865,6 @@ void System::touch(uint16 mask, int x, int y) { } } - void System::tick() { if (!_vm->_startupMode) if (--_funDel == 0) { @@ -1031,7 +1028,6 @@ void CGEEngine::saveMapping() { } } - void CGEEngine::sayDebug() { // 1111111111222222222233333333334444444444555555555566666666667777777777 // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 @@ -1177,7 +1173,6 @@ void Sprite::touch(uint16 mask, int x, int y) { } } - void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int row = 0, int pos = 0) { static const char *Comd[] = { "Name", "Type", "Phase", "East", "Left", "Right", "Top", "Bottom", diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 7af214365f9..9e937d1cbf2 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -45,7 +45,7 @@ namespace CGE { // sample info struct SmpInfo { - const uint8 *_saddr; // address + const uint8 *_saddr; // address uint16 _slen; // length uint16 _span; // left/right pan (0-15) int _sflag; // flag From 81ae309d5f8617615305ef1c6ce280e7cc380d2a Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 20 Aug 2011 01:32:20 +0200 Subject: [PATCH 233/276] CGE: Suppress some debug code present in the original --- engines/cge/cge.h | 6 -- engines/cge/cge_main.cpp | 178 ++------------------------------------- engines/cge/cge_main.h | 1 - engines/cge/walk.cpp | 2 +- 4 files changed, 7 insertions(+), 180 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 1c5e680901b..fbb096df074 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -201,7 +201,6 @@ public: void pocFul(); void hide1(Sprite *spr); void loadMapping(); - void saveMapping(); void saveSound(); void heroCover(int cvr); void trouble(int seq, int text); @@ -211,13 +210,8 @@ public: void keyClick(); void switchColorMode(); void killSprite(); - void pushSprite(); - void pullSprite(); - void sayDebug(); - void nextStep(); void switchDebug(); void miniStep(int stp); - void AltCtrlDel(); void postMiniStep(int stp); void showBak(int ref); void initCaveValues(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index fb92f93e01f..56033c9c9f6 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -535,12 +535,6 @@ void CGEEngine::quit() { } } -void CGEEngine::AltCtrlDel() { - debugC(1, kCGEDebugEngine, "CGEEngine::AltCtrlDel()"); - - _snail_->addCom(kSnSay, -1, kAltCtrlDel, _hero); -} - void CGEEngine::miniStep(int stp) { debugC(1, kCGEDebugEngine, "CGEEngine::miniStep(%d)", stp); @@ -738,12 +732,6 @@ void System::touch(uint16 mask, int x, int y) { return; } switch (x) { - case Del: - if (_keyboard->_key[kKeyAlt] && _keyboard->_key[kKeyCtrl]) - _vm->AltCtrlDel(); - else - _vm->killSprite(); - break; case 'F': if (_keyboard->_key[kKeyAlt]) { Sprite *m = _vga->_showQ->locate(17001); @@ -753,45 +741,6 @@ void System::touch(uint16 mask, int x, int y) { } } break; - case PgUp: - _vm->pushSprite(); - break; - case PgDn: - _vm->pullSprite(); - break; - case '+': - _vm->nextStep(); - break; - case '`': - if (_keyboard->_key[kKeyAlt]) - _vm->saveMapping(); - else - _vm->switchMapping(); - break; - case F1: - _vm->switchDebug(); - break; - case F3: - _hero->step(kTSeq + 4); - break; - case F4: - _hero->step(kTSeq + 5); - break; - case F5: - _hero->step(kTSeq + 0); - break; - case F6: - _hero->step(kTSeq + 1); - break; - case F7: - _hero->step(kTSeq + 2); - break; - case F8: - _hero->step(kTSeq + 3); - break; - case F9: - _sys->_funDel = 1; - break; case 'X': if (_keyboard->_key[kKeyAlt]) _finis = true; @@ -805,18 +754,6 @@ void System::touch(uint16 mask, int x, int y) { _snail->addCom(kSnLevel, -1, x - '0', NULL); break; } - case '5': - case '6': - case '7': - case '8': - case '9': - if (_sprite) - _sprite->step(x - '0'); - break; - case F10 : - if (_snail->idle() && !_hero->_flags._hide) - _vm->startCountDown(); - break; } } else { if (_vm->_startupMode) @@ -876,16 +813,12 @@ void System::tick() { int n = newRandom(100); if (n > 96) _vm->heroCover(6 + (_hero->_x + _hero->_w / 2 < kScrWidth / 2)); - else { - if (n > 90) - _vm->heroCover(5); - else { - if (n > 60) - _vm->heroCover(4); - else - _vm->heroCover(3); - } - } + else if (n > 90) + _vm->heroCover(5); + else if (n > 60) + _vm->heroCover(4); + else + _vm->heroCover(3); } } funTouch(); @@ -974,103 +907,6 @@ void CGEEngine::killSprite() { _sprite = NULL; } -void CGEEngine::pushSprite() { - debugC(1, kCGEDebugEngine, "CGEEngine::pushSprite()"); - - Sprite *spr = _sprite->_prev; - if (spr) { - _vga->_showQ->insert(_vga->_showQ->remove(_sprite), spr); - while (_sprite->_z > _sprite->_next->_z) - _sprite->_z--; - } else - _snail_->addCom(kSnSound, -1, 2, NULL); -} - -void CGEEngine::pullSprite() { - debugC(1, kCGEDebugEngine, "CGEEngine::pullSprite()"); - - bool ok = false; - Sprite *spr = _sprite->_next; - if (spr) { - spr = spr->_next; - if (spr) - ok = (!spr->_flags._slav); - } - if (ok) { - _vga->_showQ->insert(_vga->_showQ->remove(_sprite), spr); - if (_sprite->_prev) - while (_sprite->_z < _sprite->_prev->_z) - _sprite->_z++; - } else - _snail_->addCom(kSnSound, -1, 2, NULL); -} - -void CGEEngine::nextStep() { - debugC(1, kCGEDebugEngine, "CGEEngine::nextStep()"); - - _snail_->addCom(kSnStep, 0, 0, _sprite); -} - -void CGEEngine::saveMapping() { - debugC(1, kCGEDebugEngine, "CGEEngine::saveMapping()"); - - IoHand cfTab(progName(".TAB"), kModeUpdate); - if (!cfTab._error) { - cfTab.seek((_now - 1) * sizeof(Cluster::_map)); - cfTab.write((uint8 *) Cluster::_map, sizeof(Cluster::_map)); - } - - IoHand cfHxy(progName(".HXY"), kModeWrite); - if (!cfHxy._error) { - _heroXY[_now - 1]._x = _hero->_x; - _heroXY[_now - 1]._y = _hero->_y; - cfHxy.write((uint8 *) _heroXY, sizeof(_heroXY)); - } -} - -void CGEEngine::sayDebug() { -// 1111111111222222222233333333334444444444555555555566666666667777777777 -// 01234567890123456789012345678901234567890123456789012345678901234567890123456789 - static char DebugText[] = " X=000 Y=000 S=00:00 000:000:000 000:000 00"; - - char *absX = DebugText + 3; - char *absY = DebugText + 9; - char *spN = DebugText + 15; - char *spS = DebugText + 18; - char *spX = DebugText + 21; - char *spY = DebugText + 25; - char *spZ = DebugText + 29; - char *spW = DebugText + 33; - char *spH = DebugText + 37; - char *spF = DebugText + 41; - - if (!_debugLine->_flags._hide) { - dwtom(_mouse->_x, absX, 10, 3); - dwtom(_mouse->_y, absY, 10, 3); - - // sprite queue size - uint16 n = 0; - for (Sprite *spr = _vga->_showQ->first(); spr; spr = spr->_next) { - n++; - if (spr == _sprite) { - dwtom(n, spN, 10, 2); - dwtom(_sprite->_x, spX, 10, 3); - dwtom(_sprite->_y, spY, 10, 3); - dwtom(_sprite->_z, spZ, 10, 3); - dwtom(_sprite->_w, spW, 10, 3); - dwtom(_sprite->_h, spH, 10, 3); - dwtom(*(uint16 *)(&_sprite->_flags), spF, 16, 2); - } - } - dwtom(n, spS, 10, 2); - _debugLine->update(DebugText); - } -} - -void CGEEngine::switchDebug() { - _debugLine->_flags._hide = !_debugLine->_flags._hide; -} - void CGEEngine::optionTouch(int opt, uint16 mask) { switch (opt) { case 1: @@ -1397,8 +1233,6 @@ void CGEEngine::loadScript(const char *fname) { } void CGEEngine::mainLoop() { - sayDebug(); - if (_isDemo) { // static uint32 tc = 0; if (/* FIXME: TimerCount - tc >= ((182L * 6L) * 5L) && */ _talk == NULL && _snail->idle()) { diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 1c5f818217a..ad1e4e258f5 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -77,7 +77,6 @@ namespace CGE { #define kNoWay 671 #define kTooFar 681 #define kPocketFull 691 -#define kAltCtrlDel 777 #define kPanHeight 40 #define kScrWidth 320 #define kScrHeight 200 diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 95cc92afd4e..252e068d809 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -206,7 +206,7 @@ void Walk::reach(Sprite *spr, int mode) { _snail->insCom(kSnPause, -1, 64, NULL); _snail->insCom(kSnSeq, -1, kTSeq + mode, this); if (spr) { - _snail->insCom(kSnWait, -1, -1, _hero); /////--------$$$$$$$ + _snail->insCom(kSnWait, -1, -1, _hero); /////--------$$$$$$$ //SNINSERT(SNWALK, -1, -1, spr); } // sequence is not finished, From 62035d06bb0f7be05074921c901aa2cd61a53a39 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 21 Aug 2011 01:28:07 +0200 Subject: [PATCH 234/276] CGE: Remove a useless pragma, and any code related to writing data --- engines/cge/bitmap.cpp | 1 - engines/cge/btfile.cpp | 42 +++++------------ engines/cge/btfile.h | 2 - engines/cge/cfile.cpp | 100 +--------------------------------------- engines/cge/cfile.h | 6 --- engines/cge/general.cpp | 17 ------- engines/cge/general.h | 2 - engines/cge/vol.h | 4 -- 8 files changed, 14 insertions(+), 160 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index f9eae101cee..50bec4ed57b 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -47,7 +47,6 @@ void Bitmap::init() { void Bitmap::deinit() { } -#pragma argsused Bitmap::Bitmap(const char *fname) : _m(NULL), _v(NULL), _map(0) { debugC(1, kCGEDebugBitmap, "Bitmap::Bitmap(%s)", fname); diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index a4d16010e5f..449bd6aaad1 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -43,27 +43,14 @@ BtFile::BtFile(const char *name, IOMode mode, Crypt *crpt) _buff[i]._page = new BtPage; _buff[i]._pgNo = kBtValNone; _buff[i]._indx = -1; - _buff[i]._updt = false; assert(_buff[i]._page != NULL); } } BtFile::~BtFile() { debugC(1, kCGEDebugFile, "BtFile::~BtFile()"); - for (int i = 0; i < kBtLevel; i++) { - putPage(i, false); + for (int i = 0; i < kBtLevel; i++) delete _buff[i]._page; - } -} - -void BtFile::putPage(int lev, bool hard) { - debugC(1, kCGEDebugFile, "BtFile::putPage(%d, %s)", lev, hard ? "true" : "false"); - - if (hard || _buff[lev]._updt) { - seek(_buff[lev]._pgNo * kBtSize); - write((uint8 *) _buff[lev]._page, kBtSize); - _buff[lev]._updt = false; - } } BtPage *BtFile::getPage(int lev, uint16 pgn) { @@ -71,26 +58,21 @@ BtPage *BtFile::getPage(int lev, uint16 pgn) { if (_buff[lev]._pgNo != pgn) { int32 pos = pgn * kBtSize; - putPage(lev, false); _buff[lev]._pgNo = pgn; - if (size() > pos) { - seek((uint32) pgn * kBtSize); + assert(size() > pos); + // In the original, there was a check verifying if the + // purpose was to write a new file. This should only be + // to create a new file, thus it was removed. + seek((uint32) pgn * kBtSize); - // Read in the page - byte buffer[kBtSize]; - int bytesRead = read(buffer, kBtSize); + // Read in the page + byte buffer[kBtSize]; + int bytesRead = read(buffer, kBtSize); - // Unpack it into the page structure - Common::MemoryReadStream stream(buffer, bytesRead, DisposeAfterUse::NO); - _buff[lev]._page->read(stream); + // Unpack it into the page structure + Common::MemoryReadStream stream(buffer, bytesRead, DisposeAfterUse::NO); + _buff[lev]._page->read(stream); - _buff[lev]._updt = false; - } else { - memset(&_buff[lev]._page, 0, kBtSize); - _buff[lev]._page->_hea._count = 0; - _buff[lev]._page->_hea._down = kBtValNone; - _buff[lev]._updt = true; - } _buff[lev]._indx = -1; } return _buff[lev]._page; diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 7cfdc263e74..1095324116f 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -77,10 +77,8 @@ class BtFile : public IoHand { BtPage *_page; uint16 _pgNo; int _indx; - bool _updt; } _buff[kBtLevel]; - void putPage(int lev, bool hard); BtPage *getPage(int lev, uint16 pgn); public: BtFile(const char *name, IOMode mode, Crypt *crpt); diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index c5c2c2c19c3..f20ab163537 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -57,9 +57,6 @@ IoBuf::IoBuf(const char *name, IOMode mode, Crypt *crypt) IoBuf::~IoBuf() { debugC(6, kCGEDebugFile, "IoBuf::~IoBuf()"); - - if (_mode != kModeRead) - writeBuf(); free(_buff); } @@ -71,16 +68,6 @@ void IoBuf::readBuf() { _ptr = 0; } -void IoBuf::writeBuf() { - debugC(4, kCGEDebugFile, "IoBuf::writeBuf()"); - - if (_lim) { - IoHand::write(_buff, _lim); - _bufMark = IoHand::mark(); - _lim = 0; - } -} - uint16 IoBuf::read(void *buf, uint16 len) { debugC(4, kCGEDebugFile, "IoBuf::read(buf, %d)", len); @@ -149,45 +136,6 @@ uint16 IoBuf::read(uint8 *buf) { return total; } -uint16 IoBuf::write(void *buf, uint16 len) { - debugC(1, kCGEDebugFile, "IoBuf::write(buf, %d)", len); - - uint16 tot = 0; - while (len) { - uint16 n = kBufferSize - _lim; - if (n > len) - n = len; - if (n) { - memcpy(_buff + _lim, buf, n); - _lim += n; - len -= n; - buf = (uint8 *)buf + n; - tot += n; - } else - writeBuf(); - } - return tot; -} - -uint16 IoBuf::write(uint8 *buf) { - debugC(1, kCGEDebugFile, "IoBuf::write(buf)"); - - uint16 len = 0; - if (buf) { - len = strlen((const char *) buf); - if (len) - if (buf[len - 1] == '\n') - --len; - len = write(buf, len); - if (len) { - static char EOL[] = "\r\n"; - uint16 n = write(EOL, sizeof(EOL) - 1); - len += n; - } - } - return len; -} - int IoBuf::read() { debugC(1, kCGEDebugFile, "IoBuf::read()"); @@ -199,14 +147,6 @@ int IoBuf::read() { return _buff[_ptr++]; } -void IoBuf::write(uint8 b) { - debugC(1, kCGEDebugFile, "IoBuf::write(%d)", b); - - if (_lim >= kBufferSize) - writeBuf(); - _buff[_lim++] = b; -} - uint16 CFile::_maxLineLen = kLineMaxSize; CFile::CFile(const char *name, IOMode mode, Crypt *crypt) @@ -217,22 +157,6 @@ CFile::CFile(const char *name, IOMode mode, Crypt *crypt) CFile::~CFile() { } -void CFile::flush() { - debugC(1, kCGEDebugFile, "CFile::flush()"); - - if (_mode != kModeRead) - writeBuf(); - else - _lim = 0; - - /* - _BX = Handle; - _AH = 0x68; // Flush buffer - asm int 0x21 - */ - warning("FIXME: CFILE::Flush"); -} - long CFile::mark() { debugC(5, kCGEDebugFile, "CFile::mark()"); @@ -243,33 +167,13 @@ long CFile::seek(long pos) { debugC(1, kCGEDebugFile, "CFile::seek(%ld)", pos); if (pos >= _bufMark && pos < _bufMark + _lim) { - ((_mode == kModeRead) ? _ptr : _lim) = (uint16)(pos - _bufMark); + _ptr = (uint16)(pos - _bufMark); return pos; } else { - if (_mode != kModeRead) - writeBuf(); - else - _lim = 0; - + _lim = 0; _ptr = 0; return _bufMark = IoHand::seek(pos); } } -void CFile::append(CFile &f) { - debugC(1, kCGEDebugFile, "CFile::append(f)"); - - seek(size()); - if (f._error == 0) { - while (true) { - if ((_lim = f.IoHand::read(_buff, kBufferSize)) == kBufferSize) - writeBuf(); - else - break; - if ((_error = f._error) != 0) - break; - } - } -} - } // End of namespace CGE diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index f5d784073bd..39260d26737 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -42,7 +42,6 @@ protected: uint16 _lim; long _bufMark; virtual void readBuf(); - virtual void writeBuf(); public: IoBuf(IOMode mode, Crypt *crpt); IoBuf(const char *name, IOMode mode, Crypt *crpt); @@ -50,9 +49,6 @@ public: uint16 read(void *buf, uint16 len); uint16 read(uint8 *buf); int read(); - uint16 write(void *buf, uint16 len); - uint16 write(uint8 *buf); - void write(uint8 b); }; @@ -61,10 +57,8 @@ public: static uint16 _maxLineLen; CFile(const char *name, IOMode mode, Crypt *crpt); virtual ~CFile(); - void flush(); long mark(); long seek(long pos); - void append(CFile &f); }; } // End of namespace CGE diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 25ed7d6ff28..798749c2bf0 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -233,23 +233,6 @@ uint16 IoHand::read(void *buf, uint16 len) { return bytesRead; } -uint16 IoHand::write(void *buf, uint16 len) { - warning("IOHAND::Write not supported"); - return 0; -/* - if (len) { - if (Mode == kModeRead || Handle < 0) - return 0; - if (Crypt) - Seed = Crypt(buf, len, Seed); - Error = _dos_write(Handle, buf, len, &len); - if (Crypt) - Seed = Crypt(buf, len, Seed); //------$$$$$$$ - } - return len; -*/ -} - long IoHand::mark() { return _file->pos(); } diff --git a/engines/cge/general.h b/engines/cge/general.h index 90cba269cd5..75a3f3da933 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -75,7 +75,6 @@ public: XFile(IOMode mode) : _mode(mode), _error(0) { } virtual ~XFile() { } virtual uint16 read(void *buf, uint16 len) = 0; - virtual uint16 write(void *buf, uint16 len) = 0; virtual long mark() = 0; virtual long size() = 0; virtual long seek(long pos) = 0; @@ -99,7 +98,6 @@ public: virtual ~IoHand(); static bool exist(const char *name); uint16 read(void *buf, uint16 len); - uint16 write(void *buf, uint16 len); long mark(); long size(); long seek(long pos); diff --git a/engines/cge/vol.h b/engines/cge/vol.h index f9d9382eacf..d85faa4f4a8 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -45,9 +45,6 @@ class Dat { VOLBASE _file; public: Dat(); - - bool append(uint8 *buf, uint16 len); - bool write(CFile &f); bool read(long org, uint16 len, uint8 *buf); }; @@ -61,7 +58,6 @@ private: long _endMark; void readBuf(); - void writeBuf() { } public: VFile(const char *name, IOMode mode = kModeRead); ~VFile(); From 8de4d8c402bf8a2ae97fa4ffcd96b1c071dc8bbb Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 21 Aug 2011 01:41:03 +0200 Subject: [PATCH 235/276] CGE: Get rid of IOMode since it's always 'read' --- engines/cge/btfile.cpp | 6 +++--- engines/cge/btfile.h | 2 +- engines/cge/cfile.cpp | 20 ++++++++++---------- engines/cge/cfile.h | 6 +++--- engines/cge/general.cpp | 13 +++++-------- engines/cge/general.h | 10 +++------- engines/cge/vol.cpp | 24 +++++++++++------------- engines/cge/vol.h | 2 +- 8 files changed, 37 insertions(+), 46 deletions(-) diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index 449bd6aaad1..fd49cd2b120 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -35,9 +35,9 @@ namespace CGE { -BtFile::BtFile(const char *name, IOMode mode, Crypt *crpt) - : IoHand(name, mode, crpt) { - debugC(1, kCGEDebugFile, "BtFile::BtFile(%s, %d, crpt)", name, mode); +BtFile::BtFile(const char *name, Crypt *crpt) + : IoHand(name, crpt) { + debugC(1, kCGEDebugFile, "BtFile::BtFile(%s, crpt)", name); for (int i = 0; i < kBtLevel; i++) { _buff[i]._page = new BtPage; diff --git a/engines/cge/btfile.h b/engines/cge/btfile.h index 1095324116f..19b10c3eed0 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/btfile.h @@ -81,7 +81,7 @@ class BtFile : public IoHand { BtPage *getPage(int lev, uint16 pgn); public: - BtFile(const char *name, IOMode mode, Crypt *crpt); + BtFile(const char *name, Crypt *crpt); virtual ~BtFile(); BtKeypack *find(const char *key); BtKeypack *next(); diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index f20ab163537..652fecae9ac 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -33,23 +33,23 @@ namespace CGE { -IoBuf::IoBuf(IOMode mode, Crypt *crypt) - : IoHand(mode, crypt), +IoBuf::IoBuf(Crypt *crypt) + : IoHand(crypt), _bufMark(0), _ptr(0), _lim(0) { - debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%d, crypt)", mode); + debugC(1, kCGEDebugFile, "IoBuf::IoBuf(crypt)"); _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); assert(_buff != NULL); } -IoBuf::IoBuf(const char *name, IOMode mode, Crypt *crypt) - : IoHand(name, mode, crypt), +IoBuf::IoBuf(const char *name, Crypt *crypt) + : IoHand(name, crypt), _bufMark(0), _ptr(0), _lim(0) { - debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%s, %d, crypt)", name, mode); + debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%s, %d, crypt)", name); _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); assert(_buff != NULL); @@ -149,9 +149,9 @@ int IoBuf::read() { uint16 CFile::_maxLineLen = kLineMaxSize; -CFile::CFile(const char *name, IOMode mode, Crypt *crypt) - : IoBuf(name, mode, crypt) { - debugC(1, kCGEDebugFile, "CFile::CFile(%s, %d, crypt)", name, mode); +CFile::CFile(const char *name, Crypt *crypt) + : IoBuf(name, crypt) { + debugC(1, kCGEDebugFile, "CFile::CFile(%s, crypt)", name); } CFile::~CFile() { @@ -160,7 +160,7 @@ CFile::~CFile() { long CFile::mark() { debugC(5, kCGEDebugFile, "CFile::mark()"); - return _bufMark + ((_mode != kModeRead) ? _lim : _ptr); + return _bufMark + _ptr; } long CFile::seek(long pos) { diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h index 39260d26737..f7b45d8ade5 100644 --- a/engines/cge/cfile.h +++ b/engines/cge/cfile.h @@ -43,8 +43,8 @@ protected: long _bufMark; virtual void readBuf(); public: - IoBuf(IOMode mode, Crypt *crpt); - IoBuf(const char *name, IOMode mode, Crypt *crpt); + IoBuf(Crypt *crpt); + IoBuf(const char *name, Crypt *crpt); virtual ~IoBuf(); uint16 read(void *buf, uint16 len); uint16 read(uint8 *buf); @@ -55,7 +55,7 @@ public: class CFile : public IoBuf { public: static uint16 _maxLineLen; - CFile(const char *name, IOMode mode, Crypt *crpt); + CFile(const char *name, Crypt *crpt); virtual ~CFile(); long mark(); long seek(long pos); diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 798749c2bf0..a3258e9415a 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -202,16 +202,13 @@ char *dwtom(uint32 val, char *str, int radix, int len) { return str; } -IoHand::IoHand(IOMode mode, Crypt *crypt) - : XFile(mode), _crypt(crypt), _seed(kCryptSeed) { +IoHand::IoHand(Crypt *crypt) + : XFile(), _crypt(crypt), _seed(kCryptSeed) { _file = new Common::File(); } -IoHand::IoHand(const char *name, IOMode mode, Crypt *crypt) - : XFile(mode), _crypt(crypt), _seed(kCryptSeed) { - // TODO: Check if WRI and/or UPD modes are needed, and map to a save file - assert(mode == kModeRead); - +IoHand::IoHand(const char *name, Crypt *crypt) + : XFile(), _crypt(crypt), _seed(kCryptSeed) { _file = new Common::File(); _file->open(name); } @@ -222,7 +219,7 @@ IoHand::~IoHand() { } uint16 IoHand::read(void *buf, uint16 len) { - if (_mode == kModeWrite || !_file->isOpen()) + if (!_file->isOpen()) return 0; uint16 bytesRead = _file->read(buf, len); diff --git a/engines/cge/general.h b/engines/cge/general.h index 75a3f3da933..37f492a5381 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -39,8 +39,6 @@ namespace CGE { #define kCryptSeed 0xA5 -enum IOMode { kModeRead, kModeWrite, kModeUpdate }; - struct Dac { uint8 _r; uint8 _g; @@ -68,11 +66,9 @@ T min(T A, T B) { class XFile { public: - IOMode _mode; uint16 _error; - XFile() : _mode(kModeRead), _error(0) { } - XFile(IOMode mode) : _mode(mode), _error(0) { } + XFile() : _error(0) { } virtual ~XFile() { } virtual uint16 read(void *buf, uint16 len) = 0; virtual long mark() = 0; @@ -93,8 +89,8 @@ protected: uint16 _seed; Crypt *_crypt; public: - IoHand(const char *name, IOMode mode = kModeRead, Crypt crypt = NULL); - IoHand(IOMode mode = kModeRead, Crypt *crypt = NULL); + IoHand(const char *name, Crypt crypt = NULL); + IoHand(Crypt *crypt = NULL); virtual ~IoHand(); static bool exist(const char *name); uint16 read(void *buf, uint16 len); diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp index 51dbe4f8560..ff0a979b1de 100644 --- a/engines/cge/vol.cpp +++ b/engines/cge/vol.cpp @@ -40,7 +40,7 @@ VFile *VFile::_recent = NULL; /*-----------------------------------------------------------------------*/ -Dat::Dat(): _file(DAT_NAME, kModeRead, CRP) { +Dat::Dat(): _file(DAT_NAME, CRP) { debugC(1, kCGEDebugFile, "Dat::Dat()"); } @@ -50,7 +50,7 @@ void VFile::init() { debugC(1, kCGEDebugFile, "VFile::init()"); _dat = new Dat(); - _cat = new BtFile(CAT_NAME, kModeRead, CRP); + _cat = new BtFile(CAT_NAME, CRP); _recent = NULL; } @@ -59,18 +59,16 @@ void VFile::deinit() { delete _cat; } -VFile::VFile(const char *name, IOMode mode) - : IoBuf(mode, NULL) { - debugC(3, kCGEDebugFile, "VFile::VFile(%s, %d)", name, mode); +VFile::VFile(const char *name) + : IoBuf(NULL) { + debugC(3, kCGEDebugFile, "VFile::VFile(%s)", name); - if (mode == kModeRead) { - if (_dat->_file._error || _cat->_error) - error("Bad volume data"); - BtKeypack *kp = _cat->find(name); - if (scumm_stricmp(kp->_key, name) != 0) - _error = 1; - _endMark = (_bufMark = _begMark = kp->_mark) + kp->_size; - } + if (_dat->_file._error || _cat->_error) + error("Bad volume data"); + BtKeypack *kp = _cat->find(name); + if (scumm_stricmp(kp->_key, name) != 0) + _error = 1; + _endMark = (_bufMark = _begMark = kp->_mark) + kp->_size; } VFile::~VFile() { diff --git a/engines/cge/vol.h b/engines/cge/vol.h index d85faa4f4a8..d7184ba0645 100644 --- a/engines/cge/vol.h +++ b/engines/cge/vol.h @@ -59,7 +59,7 @@ private: void readBuf(); public: - VFile(const char *name, IOMode mode = kModeRead); + VFile(const char *name); ~VFile(); static void init(); From e69c7a3ac4e3a764b0ace52ea580a877eb7f72da Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 21 Aug 2011 09:51:49 +0200 Subject: [PATCH 236/276] CGE: Remove mixer --- engines/cge/cge_main.cpp | 16 +---- engines/cge/mixer.cpp | 150 --------------------------------------- engines/cge/mixer.h | 60 ---------------- engines/cge/module.mk | 1 - 4 files changed, 3 insertions(+), 224 deletions(-) delete mode 100644 engines/cge/mixer.cpp delete mode 100644 engines/cge/mixer.h diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 56033c9c9f6..759f942c291 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -46,7 +46,6 @@ #include "cge/talk.h" #include "cge/vmenu.h" #include "cge/gettext.h" -#include "cge/mixer.h" #include "cge/cge_main.h" #include "cge/cge.h" #include "cge/walk.h" @@ -257,12 +256,6 @@ Common::Error CGEEngine::saveGameState(int slot, const Common::String &desc) { void CGEEngine::saveSound() { warning("STUB: CGEEngine::saveSound"); - /* Convert to saving any such needed data in ScummVM configuration file - - CFile cfg(usrPath(progName(CFG_EXT)), WRI); - if (!cfg._error) - cfg.write(&_sndDrvInfo, sizeof(_sndDrvInfo) - sizeof(_sndDrvInfo.Vol2)); - */ } void CGEEngine::saveGame(int slotNumber, const Common::String &desc) { @@ -914,13 +907,10 @@ void CGEEngine::optionTouch(int opt, uint16 mask) { switchColorMode(); break; case 2: - if (mask & kMouseLeftUp) { + if (mask & kMouseLeftUp) switchMusic(); - } else if (mask & kMouseRightUp) - if (!Mixer::_appear) { - Mixer::_appear = true; - new Mixer(this, kButtonX, kButtonY); - } + else if (mask & kMouseRightUp) + warning("TODO: Use ScummVM sound dialog"); break; case 3: if (mask & kMouseLeftUp) diff --git a/engines/cge/mixer.cpp b/engines/cge/mixer.cpp deleted file mode 100644 index c483653ec2f..00000000000 --- a/engines/cge/mixer.cpp +++ /dev/null @@ -1,150 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/mixer.h" -#include "cge/text.h" -#include "cge/snail.h" -#include "cge/events.h" -#include "cge/snddrv.h" -#include "cge/cge_main.h" - -namespace CGE { - -extern Mouse *Mouse; - -bool Mixer::_appear = false; - -Mixer::Mixer(CGEEngine *vm, int x, int y) : Sprite(vm, NULL), _fall(kMixFall), _vm(vm) { - _appear = true; - _mb[0] = new Bitmap("VOLUME"); - _mb[1] = NULL; - setShapeList(_mb); - setName(_text->getText(kMixName)); - _flags._syst = true; - _flags._kill = true; - _flags._bDel = true; - gotoxy(x, y); - _z = kMixZ; - - // slaves - - Seq ls[kMixMax]; - - for (uint i = 0; i < kMixMax; i++) { - static char fn[] = "V00"; - wtom(i, fn + 1, 10, 2); - _lb[i] = new Bitmap(fn); - ls[i]._now = ls[i]._next = i; - ls[i]._dx = ls[i]._dy = ls[i]._dly = 0; - } - _lb[kMixMax] = NULL; - - for (uint i = 0; i < ArrayCount(_led); i++) { - register Sprite *spr = new Sprite(_vm, _lb); - - Seq *seq = (Seq *)malloc(kMixMax * sizeof(Seq)); - Common::copy(ls, ls + kMixMax, seq); - spr->setSeq(seq); - - spr->gotoxy(x + 2 + 12 * i, y + 8); - spr->_flags._tran = true; - spr->_flags._kill = true; - spr->_flags._bDel = false; - spr->_z = kMixZ; - _led[i] = spr; - } - _led[ArrayCount(_led) - 1]->_flags._bDel = true; - - _vga->_showQ->insert(this); - for (uint i = 0; i < ArrayCount(_led); i++) - _vga->_showQ->insert(_led[i]); - - //--- reset balance - warning("STUB: MIXER::MIXER() reset balance of digital and midi volumes"); -/* i = (_sndDrvInfo.Vol4._ml + _sndDrvInfo.Vol4._mr) / 2; - _sndDrvInfo.Vol4._ml = i; - _sndDrvInfo.Vol4._mr = i; - i = (_sndDrvInfo.Vol4._dl + _sndDrvInfo.Vol4._dr) / 2; - _sndDrvInfo.Vol4._dl = i; - _sndDrvInfo.Vol4._dr = i; -*/ - update(); - _time = kMixDelay; -} - -Mixer::~Mixer() { - _appear = false; -} - -#pragma argsused -void Mixer::touch(uint16 mask, int x, int y) { - Sprite::touch(mask, x, y); - - if (mask & kMouseLeftUp) { - warning("STUB: Mixer::touch(): Digital Volume"); -/* uint8 *vol = (&_sndDrvInfo.Vol2._d) + (x < _w / 2); - if (y < kMixButtonHigh) { - if (*vol < 0xFF) - *vol += 0x11; - } else if (y >= _h - kMixButtonHigh) { - if (*vol > 0x00) - *vol -= 0x11; - } - update(); -*/ - } -} - -void Mixer::tick() { - int x = _mouse->_x; - int y = _mouse->_y; - if (spriteAt(x, y) == this) { - _fall = kMixFall; - if (_flags._hold) - touch(kMouseLeftUp, x - _x, y - _y); - } else { - if (_fall) { - _fall--; - } else { - for (uint i = 0; i < ArrayCount(_led); i++) - _snail_->addCom(kSnKill, -1, 0, _led[i]); - _snail_->addCom(kSnKill, -1, 0, this); - } - } - _time = kMixDelay; -} - -void Mixer::update() { - warning("STUB: Mixer::Update"); -/* - _led[0]->step(_sndDrvInfo.Vol4._ml); - _led[1]->step(_sndDrvInfo.Vol4._dl); -*/ - _snail_->addCom2(kSnExec, -1, 0, kSndSetVolume); -} - -} // End of namespace CGE diff --git a/engines/cge/mixer.h b/engines/cge/mixer.h deleted file mode 100644 index 10c05e7cfb4..00000000000 --- a/engines/cge/mixer.h +++ /dev/null @@ -1,60 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __CGE_MIXER__ -#define __CGE_MIXER__ - -#include "cge/vga13h.h" - -namespace CGE { - -#define kMixMax 16 // count of Leds -#define kMixZ 64 // mixer Z position -#define kMixDelay 12 // 6/s -#define kMixFall 6 // in MIX_DELAY units -#define kMixButtonHigh 6 // mixer button high -#define kMixName 105 // sprite name - -class Mixer : public Sprite { - BitmapPtr _mb[2]; - BitmapPtr _lb[kMixMax + 1]; - Sprite *_led[2]; - int _fall; - void update(); -public: - static bool _appear; - Mixer(CGEEngine *vm, int x, int y); - ~Mixer(); - void touch(uint16 mask, int x, int y); - void tick(); -private: - CGEEngine *_vm; -}; - -} // End of namespace CGE - -#endif diff --git a/engines/cge/module.mk b/engines/cge/module.mk index 3ea061419b6..e71de2d9e47 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -12,7 +12,6 @@ MODULE_OBJS := \ game.o \ general.o \ gettext.o \ - mixer.o \ snail.o \ sound.o \ talk.o \ From bb591b5415bcf63f554c14d5be9d74bba9e5b6cc Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 21 Aug 2011 11:15:28 +0200 Subject: [PATCH 237/276] CGE: Some clean up in Vga class --- engines/cge/cge.cpp | 2 +- engines/cge/cge_main.cpp | 19 +++++----- engines/cge/snail.cpp | 16 ++++---- engines/cge/talk.cpp | 16 ++++---- engines/cge/talk.h | 4 +- engines/cge/vga13h.cpp | 81 +++++++++------------------------------- engines/cge/vga13h.h | 79 ++++++++------------------------------- engines/cge/vmenu.h | 4 +- 8 files changed, 64 insertions(+), 157 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 936aeea75a4..584512b69ac 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -126,7 +126,7 @@ void CGEEngine::setup() { // Initialise engine objects _text = new Text(this, progName(), 128); - _vga = new Vga(M13H); + _vga = new Vga(); _sys = new System(this); _pocLight = new PocLight(this); for (int i = 0; i < kPocketNX; i++) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 759f942c291..e9ea9bd428e 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -961,27 +961,27 @@ void Sprite::touch(uint16 mask, int x, int y) { mask |= kMouseLeftUp; } else { if (_hero->distance(this) < kDistMax) { - /// if (_flags._port) { - if (_vm->findPocket(NULL) < 0) + if (_vm->findPocket(NULL) < 0) { _vm->pocFul(); - else { + } else { _snail->addCom(kSnReach, -1, -1, this); _snail->addCom(kSnKeep, -1, -1, this); _flags._port = false; } } else { - if (_takePtr != NO_PTR) { + if (_takePtr != kNoPtr) { if (snList(kTake)[_takePtr]._com == kSnNext) _vm->offUse(); else _vm->feedSnail(this, kTake); - } else + } else { _vm->offUse(); + } } - }/// - else + } else { _vm->tooFar(); + } } } } @@ -994,8 +994,9 @@ void Sprite::touch(uint16 mask, int x, int y) { break; } } - } else + } else { _snail->addCom(kSnWalk, -1, -1, this); // Hero->FindWay(this); + } } } @@ -1018,7 +1019,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int int i, lcnt = 0; char line[kLineMax]; - mergeExt(line, fname, SPR_EXT); + mergeExt(line, fname, kSprExt); if (INI_FILE::exist(line)) { // sprite description file exist INI_FILE sprf(line); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index ef766b9a4e3..756c2675aa5 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -314,7 +314,7 @@ void CGEEngine::feedSnail(Sprite *spr, SnList snq) { uint8 ptr = (snq == kTake) ? spr->_takePtr : spr->_nearPtr; - if (ptr == NO_PTR) + if (ptr == kNoPtr) return; Snail::Com *comtab = spr->snList(snq); @@ -340,7 +340,7 @@ void CGEEngine::feedSnail(Sprite *spr, SnList snq) { Sprite *s = (c->_ref < 0) ? spr : locate(c->_ref); if (s) { uint8 *idx = (snq == kTake) ? &s->_takePtr : &s->_nearPtr; - if (*idx != NO_PTR) { + if (*idx != kNoPtr) { int v; switch (c->_val) { case -1 : @@ -458,7 +458,7 @@ void CGEEngine::snNNext(Sprite *spr, int p) { debugC(1, kCGEDebugEngine, "CGEEngine::snNNext(spr, %d)", p); if (spr) - if (spr->_nearPtr != NO_PTR) + if (spr->_nearPtr != kNoPtr) spr->_nearPtr = p; } @@ -466,7 +466,7 @@ void CGEEngine::snTNext(Sprite *spr, int p) { debugC(1, kCGEDebugEngine, "CGEEngine::snTNext(spr, %d)", p); if (spr) - if (spr->_takePtr != NO_PTR) + if (spr->_takePtr != kNoPtr) spr->_takePtr = p; } @@ -474,7 +474,7 @@ void CGEEngine::snRNNext(Sprite *spr, int p) { debugC(1, kCGEDebugEngine, "CGEEngine::snRNNext(spr, %d)", p); if (spr) - if (spr->_nearPtr != NO_PTR) + if (spr->_nearPtr != kNoPtr) spr->_nearPtr += p; } @@ -483,7 +483,7 @@ void CGEEngine::snRTNext(Sprite *spr, int p) { debugC(1, kCGEDebugEngine, "CGEEngine::snRTNext(spr, %d)", p); if (spr) - if (spr->_takePtr != NO_PTR) + if (spr->_takePtr != kNoPtr) spr->_takePtr += p; } @@ -515,14 +515,14 @@ void CGEEngine::snRmNear(Sprite *spr) { debugC(1, kCGEDebugEngine, "CGEEngine::snRmNear(spr)"); if (spr) - spr->_nearPtr = NO_PTR; + spr->_nearPtr = kNoPtr; } void CGEEngine::snRmTake(Sprite *spr) { debugC(1, kCGEDebugEngine, "CGEEngine::snRmTake(spr)"); if (spr) - spr->_takePtr = NO_PTR; + spr->_takePtr = kNoPtr; } void CGEEngine::snSeq(Sprite *spr, int val) { diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 4bcd5cb7156..812fa1d9dcf 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -166,12 +166,12 @@ Bitmap *Talk::box(uint16 w, uint16 h) { if (_mode) { uint8 *p = b; uint8 *q = b + n - w; - memset(p, LGRAY, w); - memset(q, DGRAY, w); + memset(p, kVgaColLightGray, w); + memset(q, kVgaColDarkGray, w); while (p < q) { p += w; - *(p - 1) = DGRAY; - *p = LGRAY; + *(p - 1) = kVgaColDarkGray; + *p = kVgaColLightGray; } p = b; const uint16 r = (_mode == kTBRound) ? kTextRoundCorner : 0; @@ -183,10 +183,10 @@ Bitmap *Talk::box(uint16 w, uint16 h) { q[j] = kPixelTransp; q[w - j - 1] = kPixelTransp; } - p[j] = LGRAY; - p[w - j - 1] = DGRAY; - q[j] = LGRAY; - q[w - j - 1] = DGRAY; + p[j] = kVgaColLightGray; + p[w - j - 1] = kVgaColDarkGray; + q[j] = kVgaColLightGray; + q[w - j - 1] = kVgaColDarkGray; p += w; q -= w; } diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 71db57c887c..9a999e5e8e5 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -34,8 +34,8 @@ namespace CGE { -#define kTextColFG DARK // foreground color -#define kTextColBG GRAY // background color +#define kTextColFG kVgaColDark // foreground color +#define kTextColBG kVgaColGray // background color #define kTextHMargin (6&~1) // EVEN horizontal margins! #define kTextVMargin 5 // vertical margins #define kTextLineSpace 2 // line spacing diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index feaa005643c..8213a1bcf37 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -38,25 +38,6 @@ namespace CGE { -static VgaRegBlk VideoMode[] = { - { 0x04, VGASEQ, 0x08, 0x04 }, // memory mode - { 0x03, VGAGRA, 0xFF, 0x00 }, // data rotate = 0 - { 0x05, VGAGRA, 0x03, 0x00 }, // R/W mode = 0 - { 0x06, VGAGRA, 0x02, 0x00 }, // misc - { 0x14, VGACRT, 0x40, 0x00 }, // underline - { 0x13, VGACRT, 0xFF, 0x28 }, // screen width - { 0x17, VGACRT, 0xFF, 0xC3 }, // mode control - { 0x11, VGACRT, 0x80, 0x00 }, // vert retrace end - { 0x09, VGACRT, 0xEF, 0x01 }, // max scan line - { 0x30, VGAATR, 0x00, 0x20 }, // 256 color mode -// { 0x12, VGACRT, 0xFF, 0x6E }, // vert display end -// { 0x15, VGACRT, 0xFF, 0x7F }, // start vb -// { 0x10, VGACRT, 0xFF, 0x94 }, // start vr - { 0x00, 0x00, 0x00, 0x00 } -}; - -bool SpeedTest = false; - Seq *getConstantSeq(bool seqFlag) { const Seq seq1[] = { { 0, 0, 0, 0, 0 } }; const Seq seq2[] = { { 0, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 } }; @@ -76,15 +57,6 @@ Seq *getConstantSeq(bool seqFlag) { extern "C" void SNDMIDIPlay(); -uint16 *SaveScreen() { - // In ScummVM, we don't need to worry about saving the original screen mode - return 0; -} - -void RestoreScreen(uint16 * &sav) { - // In ScummVM, we don't need to restore the original text screen when the game exits -} - Dac mkDac(uint8 r, uint8 g, uint8 b) { static Dac x; x._r = r; @@ -100,7 +72,7 @@ Sprite *locate(int ref) { Sprite::Sprite(CGEEngine *vm, BitmapPtr *shpP) : _x(0), _y(0), _z(0), _nearPtr(0), _takePtr(0), - _next(NULL), _prev(NULL), _seqPtr(NO_SEQ), _time(0), + _next(NULL), _prev(NULL), _seqPtr(kNoSeq), _time(0), _ext(NULL), _ref(-1), _cave(0), _vm(vm) { memset(_file, 0, sizeof(_file)); *((uint16 *)&_flags) = 0; @@ -196,7 +168,7 @@ Seq *Sprite::setSeq(Seq *seq) { Seq *s = _ext->_seq; _ext->_seq = seq; - if (_seqPtr == NO_SEQ) + if (_seqPtr == kNoSeq) step(0); else if (_time == 0) step(_seqPtr); @@ -246,7 +218,9 @@ Sprite *Sprite::expand() { char line[kLineMax], fname[kPathMax]; Common::Array shplist; - for (int i = 0; i < _shpCnt + 1; ++i) shplist.push_back(NULL); + for (int i = 0; i < _shpCnt + 1; ++i) + shplist.push_back(NULL); + Seq *seq = NULL; int shpcnt = 0, seqcnt = 0, @@ -257,7 +231,7 @@ Sprite *Sprite::expand() { Snail::Com *nea = NULL; Snail::Com *tak = NULL; - mergeExt(fname, _file, SPR_EXT); + mergeExt(fname, _file, kSprExt); if (INI_FILE::exist(fname)) { // sprite description file exist INI_FILE sprf(fname); if (!(sprf._error==0)) @@ -311,7 +285,7 @@ Sprite *Sprite::expand() { break; case 3: // Near - if (_nearPtr == NO_PTR) + if (_nearPtr == kNoPtr) break; nea = (Snail::Com *) realloc(nea, (neacnt + 1) * sizeof(*nea)); assert(nea != NULL); @@ -324,7 +298,7 @@ Sprite *Sprite::expand() { break; case 4: // Take - if (_takePtr == NO_PTR) + if (_takePtr == kNoPtr) break; tak = (Snail::Com *) realloc(tak, (takcnt + 1) * sizeof(*tak)); assert(tak != NULL); @@ -362,11 +336,11 @@ Sprite *Sprite::expand() { if (nea) nea[neacnt - 1]._ptr = _ext->_near = nea; else - _nearPtr = NO_PTR; + _nearPtr = kNoPtr; if (tak) tak[takcnt - 1]._ptr = _ext->_take = tak; else - _takePtr = NO_PTR; + _takePtr = kNoPtr; return this; } @@ -721,9 +695,8 @@ void Vga::deinit() { delete[] _sysPal; } -Vga::Vga(int mode) - : _frmCnt(0), _oldMode(0), _oldScreen(NULL), _statAdr(VGAST1_), - _msg(NULL), _name(NULL), _setPal(false), _mono(0) { +Vga::Vga() + : _frmCnt(0), _msg(NULL), _name(NULL), _setPal(false), _mono(0) { _oldColors = NULL; _newColors = NULL; _showQ = new Queue(true); @@ -741,17 +714,11 @@ Vga::Vga(int mode) // warning(Copr); warning("TODO: Fix Copr"); - setStatAdr(); - if (_statAdr != VGAST1_) - _mono++; _oldColors = (Dac *) malloc(sizeof(Dac) * kPalCount); _newColors = (Dac *) malloc(sizeof(Dac) * kPalCount); - _oldScreen = SaveScreen(); getColors(_oldColors); sunset(); - _oldMode = setMode(mode); setColors(); - setup(VideoMode); clear(0); } @@ -779,26 +746,12 @@ Vga::~Vga() { delete _spareQ; } -void Vga::setStatAdr() { - // No implementation needed for ScummVM -} - -#pragma argsused -void Vga::waitVR(bool on) { +void Vga::waitVR() { // Since some of the game parts rely on using vertical sync as a delay mechanism, // we're introducing a short delay to simulate it g_system->delayMillis(5); } -void Vga::setup(VgaRegBlk *vrb) { - // No direct VGA setup required, since ScummVM provides it's own graphics interface -} - -int Vga::setMode(int mode) { - // ScummVM provides it's own vieo services - return 0; -} - void Vga::getColors(Dac *tab) { byte palData[kPalSize]; g_system->getPaletteManager()->grabPalette(palData, 0, kPalCount); @@ -850,9 +803,9 @@ void Vga::setColors() { } void Vga::sunrise(Dac *tab) { - for (int i = 0; i <= 64; i += FADE_STEP) { + for (int i = 0; i <= 64; i += kFadeStep) { setColors(tab, i); - waitVR(true); + waitVR(); updateColors(); } } @@ -860,9 +813,9 @@ void Vga::sunrise(Dac *tab) { void Vga::sunset() { Dac tab[256]; getColors(tab); - for (int i = 64; i >= 0; i -= FADE_STEP) { + for (int i = 64; i >= 0; i -= kFadeStep) { setColors(tab, i); - waitVR(true); + waitVR(); updateColors(); } } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 8576752d07b..96492010214 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -37,40 +37,18 @@ namespace CGE { -#define FADE_STEP 2 -#define TMR_DIV ((0x8000/TMR_RATE)*2) -#define NREP 9 -#define FREP 24 +#define kFadeStep 2 +#define kVgaColDark 207 +#define kVgaColDarkGray 225 /*219*/ +#define kVgaColGray 231 +#define kVgaColLightGray 237 +#define kPixelTransp 0xFE +#define kNoSeq (-1) +#define kNoPtr ((uint8)-1) +#define kSprExt ".SPR" +#define kPalCount 256 +#define kPalSize (kPalCount * 3) -#define TMR_RATE1 16 -#define TMR_RATE2 4 -#define TMR_RATE (TMR_RATE1 * TMR_RATE2) - -#define MAX_NAME 20 -#define VIDEO 0x10 - -#define NO_CLEAR 0x80 -#define TEXT_MODE 0x03 -#define M13H 0x13 - -#define LIGHT 0xFF -#define DARK 207 -#define DGRAY 225 /*219*/ -#define GRAY 231 -#define LGRAY 237 -#define kPixelTransp 0xFE - -#define NO_SEQ (-1) -#define NO_PTR ((uint8)-1) - -#define SPR_EXT ".SPR" - -struct VgaRegBlk { - uint8 _idx; - uint8 _adr; - uint8 _clr; - uint8 _set; -}; struct Seq { uint8 _now; @@ -82,21 +60,6 @@ struct Seq { extern Seq _seq1[]; extern Seq _seq2[]; -//extern SEQ * Compass[]; -//extern SEQ TurnToS[]; - -#define kPalCount 256 -#define kPalSize (kPalCount * 3) - -#define VGAATR_ 0x3C0 -#define VGASEQ_ 0x3C4 -#define VGAGRA_ 0x3CE -#define VGACRT_ 0x3D4 -#define VGAST1_ 0x3DA -#define VGAATR (VGAATR_ & 0xFF) -#define VGASEQ (VGASEQ_ & 0xFF) -#define VGAGRA (VGAGRA_ & 0xFF) -#define VGACRT (VGACRT_ & 0xFF) class SprExt { public: @@ -219,20 +182,15 @@ public: }; class Vga { - uint16 _oldMode; - uint16 *_oldScreen; - uint16 _statAdr; bool _setPal; Dac *_oldColors; Dac *_newColors; const char *_msg; const char *_name; - int setMode(int mode); void updateColors(); void setColors(); - void setStatAdr(); - void waitVR(bool on); + void waitVR(); public: uint32 _frmCnt; Queue *_showQ; @@ -241,12 +199,11 @@ public: static Graphics::Surface *_page[4]; static Dac *_sysPal; - Vga(int mode); + Vga(); ~Vga(); static void init(); static void deinit(); - void setup(VgaRegBlk *vrb); void getColors(Dac *tab); void setColors(Dac *tab, int lum); void clear(uint8 color); @@ -288,12 +245,12 @@ uint8 closest(CBLK *pal, CBLK x) { uint16 i, dif = 0xFFFF, found = 0; uint16 L = x._r + x._g + x._b; if (!L) - ++L; + L++; uint16 R = f(x._r, L), G = f(x._g, L), B = f(x._b, L); for (i = 0; i < 256; i++) { uint16 l = pal[i]._r + pal[i]._g + pal[i]._b; - if (! l) - ++l; + if (!l) + l++; int r = f(pal[i]._r, l), g = f(pal[i]._g, l), b = f(pal[i]._b, l); uint16 D = ((r > R) ? (r - R) : (R - r)) + ((g > G) ? (g - G) : (G - g)) + @@ -311,13 +268,9 @@ uint8 closest(CBLK *pal, CBLK x) { #undef f } -uint16 *saveScreen(); -void restoreScreen(uint16 * &sav); Sprite *spriteAt(int x, int y); Sprite *locate(int ref); -extern bool _speedTest; - } // End of namespace CGE #endif diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index 93979b58957..0ddcfdb91d9 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -34,8 +34,8 @@ namespace CGE { #define kMenuBarVM 1 #define kMenuBarHM 3 -#define kMenuBarLT LGRAY -#define kMenuBarRB DGRAY +#define kMenuBarLT kVgaColLightGray +#define kMenuBarRB kVgaColDarkGray struct Choice { From c6e89df3d940747a85d447f172e2323c800f5eaf Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 22 Aug 2011 19:59:09 +0200 Subject: [PATCH 238/276] CGE: Fix error reported by fuzzie --- engines/cge/cfile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp index 652fecae9ac..23881cf89a5 100644 --- a/engines/cge/cfile.cpp +++ b/engines/cge/cfile.cpp @@ -49,7 +49,7 @@ IoBuf::IoBuf(const char *name, Crypt *crypt) _bufMark(0), _ptr(0), _lim(0) { - debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%s, %d, crypt)", name); + debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%s, crypt)", name); _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); assert(_buff != NULL); From 8b388b6829885bbeb223991626f6b457115dabeb Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Mon, 22 Aug 2011 20:17:49 +0200 Subject: [PATCH 239/276] CGE: Fix compilation after thumbnail changes. --- engines/cge/cge_main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index e9ea9bd428e..0309f9f7244 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -378,8 +378,8 @@ bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &heade while ((ch = (char)in->readByte()) != '\0') header.saveName += ch; // Get the thumbnail - header.thumbnail = new Graphics::Surface(); - if (!Graphics::loadThumbnail(*in, *header.thumbnail)) { + header.thumbnail = Graphics::loadThumbnail(*in); + if (!header.thumbnail) { delete header.thumbnail; header.thumbnail = NULL; return false; From bb2f63d285c705f592adb06720776cf51d108af8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 26 Aug 2011 23:32:05 +0200 Subject: [PATCH 240/276] CGE: Remove useless function --- engines/cge/btfile.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp index fd49cd2b120..ca02e1e43dc 100644 --- a/engines/cge/btfile.cpp +++ b/engines/cge/btfile.cpp @@ -109,10 +109,6 @@ BtKeypack *BtFile::find(const char *key) { return NULL; } -int keycomp(const void *k1, const void *k2) { - return scumm_strnicmp((const char *) k1, (const char*) k2, kBtKeySize); -} - void BtPage::read(Common::ReadStream &s) { _hea._count = s.readUint16LE(); _hea._down = s.readUint16LE(); From 71440760307dfb99e6194929fb0c8d3bf1a0df10 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 27 Aug 2011 09:05:32 +0200 Subject: [PATCH 241/276] CGE: Move IO classes to a separated source file --- engines/cge/bitmap.cpp | 7 +- engines/cge/bitmap.h | 3 +- engines/cge/btfile.cpp | 132 --------- engines/cge/cfile.cpp | 179 ------------ engines/cge/cfile.h | 66 ----- engines/cge/cge.cpp | 1 - engines/cge/cge_main.cpp | 18 +- engines/cge/cge_main.h | 2 +- engines/cge/fileio.cpp | 427 +++++++++++++++++++++++++++++ engines/cge/{btfile.h => fileio.h} | 102 ++++++- engines/cge/general.cpp | 77 ------ engines/cge/general.h | 40 --- engines/cge/jbw.h | 5 - engines/cge/module.mk | 4 +- engines/cge/sound.cpp | 10 +- engines/cge/sound.h | 2 +- engines/cge/talk.cpp | 4 +- engines/cge/text.cpp | 7 +- engines/cge/vga13h.cpp | 5 +- engines/cge/vol.cpp | 120 -------- engines/cge/vol.h | 77 ------ 21 files changed, 548 insertions(+), 740 deletions(-) delete mode 100644 engines/cge/btfile.cpp delete mode 100644 engines/cge/cfile.cpp delete mode 100644 engines/cge/cfile.h create mode 100644 engines/cge/fileio.cpp rename engines/cge/{btfile.h => fileio.h} (53%) delete mode 100644 engines/cge/vol.cpp delete mode 100644 engines/cge/vol.h diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 50bec4ed57b..02265f09bcd 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -26,10 +26,7 @@ */ #include "cge/bitmap.h" -#include "cge/cfile.h" #include "cge/jbw.h" -#include "cge/vol.h" -#include "cge/cfile.h" #include "cge/vga13h.h" #include "cge/cge_main.h" #include "common/system.h" @@ -53,8 +50,8 @@ Bitmap::Bitmap(const char *fname) : _m(NULL), _v(NULL), _map(0) { char pat[kMaxPath]; forceExt(pat, fname, ".VBM"); - if (PIC_FILE::exist(pat)) { - PIC_FILE file(pat); + if (VFile::exist(pat)) { + VFile file(pat); if ((file._error == 0) && (!loadVBM(&file))) error("Bad VBM [%s]", fname); } else { diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 7604cb8081f..8896d13bb43 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -28,7 +28,8 @@ #ifndef __CGE_BITMAP__ #define __CGE_BITMAP__ -#include "cge/general.h" +#include "cge/fileio.h" +//#include "cge/general.h" namespace CGE { diff --git a/engines/cge/btfile.cpp b/engines/cge/btfile.cpp deleted file mode 100644 index ca02e1e43dc..00000000000 --- a/engines/cge/btfile.cpp +++ /dev/null @@ -1,132 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/btfile.h" -#include "common/system.h" -#include "common/str.h" -#include "cge/cge.h" -#include "common/debug.h" -#include "common/debug-channels.h" -#include "common/memstream.h" - -namespace CGE { - -BtFile::BtFile(const char *name, Crypt *crpt) - : IoHand(name, crpt) { - debugC(1, kCGEDebugFile, "BtFile::BtFile(%s, crpt)", name); - - for (int i = 0; i < kBtLevel; i++) { - _buff[i]._page = new BtPage; - _buff[i]._pgNo = kBtValNone; - _buff[i]._indx = -1; - assert(_buff[i]._page != NULL); - } -} - -BtFile::~BtFile() { - debugC(1, kCGEDebugFile, "BtFile::~BtFile()"); - for (int i = 0; i < kBtLevel; i++) - delete _buff[i]._page; -} - -BtPage *BtFile::getPage(int lev, uint16 pgn) { - debugC(1, kCGEDebugFile, "BtFile::getPage(%d, %d)", lev, pgn); - - if (_buff[lev]._pgNo != pgn) { - int32 pos = pgn * kBtSize; - _buff[lev]._pgNo = pgn; - assert(size() > pos); - // In the original, there was a check verifying if the - // purpose was to write a new file. This should only be - // to create a new file, thus it was removed. - seek((uint32) pgn * kBtSize); - - // Read in the page - byte buffer[kBtSize]; - int bytesRead = read(buffer, kBtSize); - - // Unpack it into the page structure - Common::MemoryReadStream stream(buffer, bytesRead, DisposeAfterUse::NO); - _buff[lev]._page->read(stream); - - _buff[lev]._indx = -1; - } - return _buff[lev]._page; -} - -BtKeypack *BtFile::find(const char *key) { - debugC(1, kCGEDebugFile, "BtFile::find(%s)", key); - - int lev = 0; - uint16 nxt = kBtValRoot; - while (!_error) { - BtPage *pg = getPage(lev, nxt); - // search - if (pg->_hea._down != kBtValNone) { - int i; - for (i = 0; i < pg->_hea._count; i++) { - // Does this work, or does it have to compare the entire buffer? - if (scumm_strnicmp((const char *)key, (const char*)pg->_inn[i]._key, kBtKeySize) < 0) - break; - } - nxt = (i) ? pg->_inn[i - 1]._down : pg->_hea._down; - _buff[lev]._indx = i - 1; - lev++; - } else { - int i; - for (i = 0; i < pg->_hea._count - 1; i++) { - if (scumm_stricmp((const char *)key, (const char *)pg->_lea[i]._key) <= 0) - break; - } - _buff[lev]._indx = i; - return &pg->_lea[i]; - } - } - return NULL; -} - -void BtPage::read(Common::ReadStream &s) { - _hea._count = s.readUint16LE(); - _hea._down = s.readUint16LE(); - - if (_hea._down == kBtValNone) { - // Leaf list - for (int i = 0; i < kBtLeafCount; ++i) { - s.read(_lea[i]._key, kBtKeySize); - _lea[i]._mark = s.readUint32LE(); - _lea[i]._size = s.readUint16LE(); - } - } else { - // Root index - for (int i = 0; i < kBtInnerCount; ++i) { - s.read(_inn[i]._key, kBtKeySize); - _inn[i]._down = s.readUint16LE(); - } - } -} - -} // End of namespace CGE diff --git a/engines/cge/cfile.cpp b/engines/cge/cfile.cpp deleted file mode 100644 index 23881cf89a5..00000000000 --- a/engines/cge/cfile.cpp +++ /dev/null @@ -1,179 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/cfile.h" -#include "common/system.h" -#include "cge/cge.h" -#include "common/debug.h" -#include "common/debug-channels.h" - -namespace CGE { - -IoBuf::IoBuf(Crypt *crypt) - : IoHand(crypt), - _bufMark(0), - _ptr(0), - _lim(0) { - debugC(1, kCGEDebugFile, "IoBuf::IoBuf(crypt)"); - - _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); - assert(_buff != NULL); -} - -IoBuf::IoBuf(const char *name, Crypt *crypt) - : IoHand(name, crypt), - _bufMark(0), - _ptr(0), - _lim(0) { - debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%s, crypt)", name); - - _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); - assert(_buff != NULL); -} - -IoBuf::~IoBuf() { - debugC(6, kCGEDebugFile, "IoBuf::~IoBuf()"); - free(_buff); -} - -void IoBuf::readBuf() { - debugC(4, kCGEDebugFile, "IoBuf::readBuf()"); - - _bufMark = IoHand::mark(); - _lim = IoHand::read(_buff, kBufferSize); - _ptr = 0; -} - -uint16 IoBuf::read(void *buf, uint16 len) { - debugC(4, kCGEDebugFile, "IoBuf::read(buf, %d)", len); - - uint16 total = 0; - while (len) { - if (_ptr >= _lim) - readBuf(); - uint16 n = _lim - _ptr; - if (n) { - if (len < n) - n = len; - memcpy(buf, _buff + _ptr, n); - buf = (uint8 *)buf + n; - len -= n; - total += n; - _ptr += n; - } else - break; - } - return total; -} - -uint16 IoBuf::read(uint8 *buf) { - debugC(3, kCGEDebugFile, "IoBuf::read(buf)"); - - uint16 total = 0; - - while (total < kLineMaxSize - 2) { - if (_ptr >= _lim) - readBuf(); - uint8 *p = _buff + _ptr; - uint16 n = _lim - _ptr; - if (n) { - if (total + n >= kLineMaxSize - 2) - n = kLineMaxSize - 2 - total; - uint8 *eol = (uint8 *) memchr(p, '\r', n); - if (eol) - n = (uint16)(eol - p); - uint8 *eof = (uint8 *) memchr(p, '\32', n); - if (eof) { // end-of-file - n = (uint16)(eof - p); - _ptr = (uint16)(eof - _buff); - } - if (n) - memcpy(buf, p, n); - buf += n; - total += n; - if (eof) - break; - _ptr += n; - if (eol) { - _ptr++; - *(buf++) = '\n'; - total++; - if (_ptr >= _lim) - readBuf(); - if (_ptr < _lim) - if (_buff[_ptr] == '\n') - ++_ptr; - break; - } - } else - break; - } - *buf = '\0'; - return total; -} - -int IoBuf::read() { - debugC(1, kCGEDebugFile, "IoBuf::read()"); - - if (_ptr >= _lim) { - readBuf(); - if (_lim == 0) - return -1; - } - return _buff[_ptr++]; -} - -uint16 CFile::_maxLineLen = kLineMaxSize; - -CFile::CFile(const char *name, Crypt *crypt) - : IoBuf(name, crypt) { - debugC(1, kCGEDebugFile, "CFile::CFile(%s, crypt)", name); -} - -CFile::~CFile() { -} - -long CFile::mark() { - debugC(5, kCGEDebugFile, "CFile::mark()"); - - return _bufMark + _ptr; -} - -long CFile::seek(long pos) { - debugC(1, kCGEDebugFile, "CFile::seek(%ld)", pos); - - if (pos >= _bufMark && pos < _bufMark + _lim) { - _ptr = (uint16)(pos - _bufMark); - return pos; - } else { - _lim = 0; - _ptr = 0; - return _bufMark = IoHand::seek(pos); - } -} - -} // End of namespace CGE diff --git a/engines/cge/cfile.h b/engines/cge/cfile.h deleted file mode 100644 index f7b45d8ade5..00000000000 --- a/engines/cge/cfile.h +++ /dev/null @@ -1,66 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __CGE_CFILE__ -#define __CGE_CFILE__ - -#include "cge/general.h" - -namespace CGE { - -#define kLineMaxSize 512 -#define kBufferSize 2048 - -class IoBuf : public IoHand { -protected: - uint8 *_buff; - uint16 _ptr; - uint16 _lim; - long _bufMark; - virtual void readBuf(); -public: - IoBuf(Crypt *crpt); - IoBuf(const char *name, Crypt *crpt); - virtual ~IoBuf(); - uint16 read(void *buf, uint16 len); - uint16 read(uint8 *buf); - int read(); -}; - - -class CFile : public IoBuf { -public: - static uint16 _maxLineLen; - CFile(const char *name, Crypt *crpt); - virtual ~CFile(); - long mark(); - long seek(long pos); -}; - -} // End of namespace CGE - -#endif diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 584512b69ac..0dbc1c8696f 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -34,7 +34,6 @@ #include "cge/cge_main.h" #include "cge/talk.h" #include "cge/text.h" -#include "cge/vol.h" #include "cge/walk.h" namespace CGE { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 0309f9f7244..cf3e5223b44 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -41,8 +41,6 @@ #include "cge/text.h" #include "cge/game.h" #include "cge/events.h" -#include "cge/cfile.h" -#include "cge/vol.h" #include "cge/talk.h" #include "cge/vmenu.h" #include "cge/gettext.h" @@ -427,7 +425,7 @@ void CGEEngine::tooFar() { void CGEEngine::loadHeroXY() { debugC(1, kCGEDebugEngine, "CGEEngine::loadHeroXY()"); - INI_FILE cf(progName(".HXY")); + VFile cf(progName(".HXY")); uint16 x, y; memset(_heroXY, 0, sizeof(_heroXY)); @@ -446,7 +444,7 @@ void CGEEngine::loadMapping() { debugC(1, kCGEDebugEngine, "CGEEngine::loadMapping()"); if (_now <= _caveMax) { - INI_FILE cf(progName(".TAB")); + VFile cf(progName(".TAB")); if (!cf._error) { // Move to the data for the given room cf.seek((_now - 1) * kMapArrSize); @@ -1021,8 +1019,8 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int char line[kLineMax]; mergeExt(line, fname, kSprExt); - if (INI_FILE::exist(line)) { // sprite description file exist - INI_FILE sprf(line); + if (VFile::exist(line)) { // sprite description file exist + VFile sprf(line); if (sprf._error) error("Bad SPR [%s]", line); @@ -1158,7 +1156,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int } void CGEEngine::loadScript(const char *fname) { - INI_FILE scrf(fname); + VFile scrf(fname); if (scrf._error) return; @@ -1344,7 +1342,7 @@ void CGEEngine::runGame() { if (!_music) _midiPlayer.killMidi(); - if (INI_FILE::exist("MINI.SPR")) { + if (VFile::exist("MINI.SPR")) { _miniShp = new BitmapPtr[2]; _miniShp[0] = _miniShp[1] = NULL; @@ -1362,7 +1360,7 @@ void CGEEngine::runGame() { if (_hero) { expandSprite(_hero); _hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); - if (INI_FILE::exist("00SHADOW.SPR")) { + if (VFile::exist("00SHADOW.SPR")) { loadSprite("00SHADOW", -1, 0, _hero->_x + 14, _hero->_y + 51); delete _shadow; if ((_shadow = _sprite) != NULL) { @@ -1427,7 +1425,7 @@ void CGEEngine::movie(const char *ext) { return; const char *fn = progName(ext); - if (INI_FILE::exist(fn)) { + if (VFile::exist(fn)) { loadScript(fn); expandSprite(_vga->_spareQ->locate(999)); feedSnail(_vga->_showQ->locate(999), kTake); diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index ad1e4e258f5..cce31222358 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -84,7 +84,7 @@ namespace CGE { #define kStackSize 2048 #define kSavegameCheckSum (1956 + _now + _oldLev + _game + _music + _demoText) #define kSavegame0Name ("{{INIT}}" kSvgExt) -#define kSavegame0File INI_FILE +#define kSavegame0File VFile #define kSavegameStrSize 11 #define kGameFrameDelay (1000 / 50) #define kGameTickDelay (1000 / 62) diff --git a/engines/cge/fileio.cpp b/engines/cge/fileio.cpp new file mode 100644 index 00000000000..b2761f33be4 --- /dev/null +++ b/engines/cge/fileio.cpp @@ -0,0 +1,427 @@ +/* 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. + * + */ + +/* + * This code is based on original Soltys source code + * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon + */ + +#include "common/system.h" +#include "common/str.h" +#include "common/debug.h" +#include "common/debug-channels.h" +#include "common/memstream.h" +#include "cge/cge.h" +#include "cge/fileio.h" + +namespace CGE { + +Dat *VFile::_dat = NULL; +BtFile *VFile::_cat = NULL; +VFile *VFile::_recent = NULL; + +uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { + byte *b = static_cast(buf); + + for (uint16 i = 0; i < siz; i++) + *b++ ^= seed; + + return seed; +} + +/*----------------------------------------------------------------------- + * IOHand + *-----------------------------------------------------------------------*/ +IoHand::IoHand(Crypt *crypt) : XFile(), _crypt(crypt), _seed(kCryptSeed) { + _file = new Common::File(); +} + +IoHand::IoHand(const char *name, Crypt *crypt) + : XFile(), _crypt(crypt), _seed(kCryptSeed) { + _file = new Common::File(); + _file->open(name); +} + +IoHand::~IoHand() { + _file->close(); + delete _file; +} + +uint16 IoHand::read(void *buf, uint16 len) { + if (!_file->isOpen()) + return 0; + + uint16 bytesRead = _file->read(buf, len); + if (!bytesRead) + error("Read %s - %d bytes", _file->getName(), len); + if (_crypt) + _seed = _crypt(buf, len, kCryptSeed); + return bytesRead; +} + +long IoHand::mark() { + return _file->pos(); +} + +long IoHand::seek(long pos) { + _file->seek(pos, SEEK_SET); + return _file->pos(); +} + +long IoHand::size() { + return _file->size(); +} + +bool IoHand::exist(const char *name) { + return Common::File::exists(name); +} + +/*----------------------------------------------------------------------- + * IoBuf + *-----------------------------------------------------------------------*/ +IoBuf::IoBuf(Crypt *crypt) + : IoHand(crypt), + _bufMark(0), + _ptr(0), + _lim(0) { + debugC(1, kCGEDebugFile, "IoBuf::IoBuf(crypt)"); + + _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); + assert(_buff != NULL); +} + +IoBuf::IoBuf(const char *name, Crypt *crypt) + : IoHand(name, crypt), + _bufMark(0), + _ptr(0), + _lim(0) { + debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%s, crypt)", name); + + _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); + assert(_buff != NULL); +} + +IoBuf::~IoBuf() { + debugC(6, kCGEDebugFile, "IoBuf::~IoBuf()"); + free(_buff); +} + +void IoBuf::readBuf() { + debugC(4, kCGEDebugFile, "IoBuf::readBuf()"); + + _bufMark = IoHand::mark(); + _lim = IoHand::read(_buff, kBufferSize); + _ptr = 0; +} + +uint16 IoBuf::read(void *buf, uint16 len) { + debugC(4, kCGEDebugFile, "IoBuf::read(buf, %d)", len); + + uint16 total = 0; + while (len) { + if (_ptr >= _lim) + readBuf(); + uint16 n = _lim - _ptr; + if (n) { + if (len < n) + n = len; + memcpy(buf, _buff + _ptr, n); + buf = (uint8 *)buf + n; + len -= n; + total += n; + _ptr += n; + } else + break; + } + return total; +} + +uint16 IoBuf::read(uint8 *buf) { + debugC(3, kCGEDebugFile, "IoBuf::read(buf)"); + + uint16 total = 0; + + while (total < kLineMaxSize - 2) { + if (_ptr >= _lim) + readBuf(); + uint8 *p = _buff + _ptr; + uint16 n = _lim - _ptr; + if (n) { + if (total + n >= kLineMaxSize - 2) + n = kLineMaxSize - 2 - total; + uint8 *eol = (uint8 *) memchr(p, '\r', n); + if (eol) + n = (uint16)(eol - p); + uint8 *eof = (uint8 *) memchr(p, '\32', n); + if (eof) { // end-of-file + n = (uint16)(eof - p); + _ptr = (uint16)(eof - _buff); + } + if (n) + memcpy(buf, p, n); + buf += n; + total += n; + if (eof) + break; + _ptr += n; + if (eol) { + _ptr++; + *(buf++) = '\n'; + total++; + if (_ptr >= _lim) + readBuf(); + if (_ptr < _lim) + if (_buff[_ptr] == '\n') + ++_ptr; + break; + } + } else + break; + } + *buf = '\0'; + return total; +} + +int IoBuf::read() { + debugC(1, kCGEDebugFile, "IoBuf::read()"); + + if (_ptr >= _lim) { + readBuf(); + if (_lim == 0) + return -1; + } + return _buff[_ptr++]; +} + +/*----------------------------------------------------------------------- + * CFile + *-----------------------------------------------------------------------*/ +uint16 CFile::_maxLineLen = kLineMaxSize; + +CFile::CFile(const char *name, Crypt *crypt) + : IoBuf(name, crypt) { + debugC(1, kCGEDebugFile, "CFile::CFile(%s, crypt)", name); +} + +CFile::~CFile() { +} + +long CFile::mark() { + debugC(5, kCGEDebugFile, "CFile::mark()"); + + return _bufMark + _ptr; +} + +long CFile::seek(long pos) { + debugC(1, kCGEDebugFile, "CFile::seek(%ld)", pos); + + if (pos >= _bufMark && pos < _bufMark + _lim) { + _ptr = (uint16)(pos - _bufMark); + return pos; + } else { + _lim = 0; + _ptr = 0; + return _bufMark = IoHand::seek(pos); + } +} + +/*----------------------------------------------------------------------- + * BtPage + *-----------------------------------------------------------------------*/ +void BtPage::read(Common::ReadStream &s) { + _hea._count = s.readUint16LE(); + _hea._down = s.readUint16LE(); + + if (_hea._down == kBtValNone) { + // Leaf list + for (int i = 0; i < kBtLeafCount; ++i) { + s.read(_lea[i]._key, kBtKeySize); + _lea[i]._mark = s.readUint32LE(); + _lea[i]._size = s.readUint16LE(); + } + } else { + // Root index + for (int i = 0; i < kBtInnerCount; ++i) { + s.read(_inn[i]._key, kBtKeySize); + _inn[i]._down = s.readUint16LE(); + } + } +} + +/*----------------------------------------------------------------------- + * BtFile + *-----------------------------------------------------------------------*/ +BtFile::BtFile(const char *name, Crypt *crpt) + : IoHand(name, crpt) { + debugC(1, kCGEDebugFile, "BtFile::BtFile(%s, crpt)", name); + + for (int i = 0; i < kBtLevel; i++) { + _buff[i]._page = new BtPage; + _buff[i]._pgNo = kBtValNone; + _buff[i]._indx = -1; + assert(_buff[i]._page != NULL); + } +} + +BtFile::~BtFile() { + debugC(1, kCGEDebugFile, "BtFile::~BtFile()"); + for (int i = 0; i < kBtLevel; i++) + delete _buff[i]._page; +} + +BtPage *BtFile::getPage(int lev, uint16 pgn) { + debugC(1, kCGEDebugFile, "BtFile::getPage(%d, %d)", lev, pgn); + + if (_buff[lev]._pgNo != pgn) { + int32 pos = pgn * kBtSize; + _buff[lev]._pgNo = pgn; + assert(size() > pos); + // In the original, there was a check verifying if the + // purpose was to write a new file. This should only be + // to create a new file, thus it was removed. + seek((uint32) pgn * kBtSize); + + // Read in the page + byte buffer[kBtSize]; + int bytesRead = read(buffer, kBtSize); + + // Unpack it into the page structure + Common::MemoryReadStream stream(buffer, bytesRead, DisposeAfterUse::NO); + _buff[lev]._page->read(stream); + + _buff[lev]._indx = -1; + } + return _buff[lev]._page; +} + +BtKeypack *BtFile::find(const char *key) { + debugC(1, kCGEDebugFile, "BtFile::find(%s)", key); + + int lev = 0; + uint16 nxt = kBtValRoot; + while (!_error) { + BtPage *pg = getPage(lev, nxt); + // search + if (pg->_hea._down != kBtValNone) { + int i; + for (i = 0; i < pg->_hea._count; i++) { + // Does this work, or does it have to compare the entire buffer? + if (scumm_strnicmp((const char *)key, (const char*)pg->_inn[i]._key, kBtKeySize) < 0) + break; + } + nxt = (i) ? pg->_inn[i - 1]._down : pg->_hea._down; + _buff[lev]._indx = i - 1; + lev++; + } else { + int i; + for (i = 0; i < pg->_hea._count - 1; i++) { + if (scumm_stricmp((const char *)key, (const char *)pg->_lea[i]._key) <= 0) + break; + } + _buff[lev]._indx = i; + return &pg->_lea[i]; + } + } + return NULL; +} + +/*----------------------------------------------------------------------- + * Dat + *-----------------------------------------------------------------------*/ +Dat::Dat(): _file(kDatName, XCrypt) { + debugC(1, kCGEDebugFile, "Dat::Dat()"); +} + +/*----------------------------------------------------------------------- + * VFile + *-----------------------------------------------------------------------*/ +void VFile::init() { + debugC(1, kCGEDebugFile, "VFile::init()"); + + _dat = new Dat(); + _cat = new BtFile(kCatName, XCrypt); + _recent = NULL; +} + +void VFile::deinit() { + delete _dat; + delete _cat; +} + +VFile::VFile(const char *name) : IoBuf(NULL) { + debugC(3, kCGEDebugFile, "VFile::VFile(%s)", name); + + if (_dat->_file._error || _cat->_error) + error("Bad volume data"); + BtKeypack *kp = _cat->find(name); + if (scumm_stricmp(kp->_key, name) != 0) + _error = 1; + _endMark = (_bufMark = _begMark = kp->_mark) + kp->_size; +} + +VFile::~VFile() { + if (_recent == this) + _recent = NULL; +} + +bool VFile::exist(const char *name) { + debugC(1, kCGEDebugFile, "VFile::exist(%s)", name); + + return scumm_stricmp(_cat->find(name)->_key, name) == 0; +} + +void VFile::readBuf() { + debugC(3, kCGEDebugFile, "VFile::readBuf()"); + + if (_recent != this) { + _dat->_file.seek(_bufMark + _lim); + _recent = this; + } + _bufMark = _dat->_file.mark(); + long n = _endMark - _bufMark; + if (n > kBufferSize) + n = kBufferSize; + _lim = _dat->_file.read(_buff, (uint16) n); + _ptr = 0; +} + +long VFile::mark() { + debugC(5, kCGEDebugFile, "VFile::mark()"); + + return (_bufMark + _ptr) - _begMark; +} + +long VFile::size() { + debugC(1, kCGEDebugFile, "VFile::size()"); + + return _endMark - _begMark; +} + +long VFile::seek(long pos) { + debugC(1, kCGEDebugFile, "VFile::seek(%ld)", pos); + + _recent = NULL; + _lim = 0; + return (_bufMark = _begMark + pos); +} + +} // End of namespace CGE diff --git a/engines/cge/btfile.h b/engines/cge/fileio.h similarity index 53% rename from engines/cge/btfile.h rename to engines/cge/fileio.h index 19b10c3eed0..a8577207bd3 100644 --- a/engines/cge/btfile.h +++ b/engines/cge/fileio.h @@ -33,14 +33,17 @@ namespace CGE { -#define kBtSize 1024 -#define kBtKeySize 13 -#define kBtLevel 2 +#define kBtSize 1024 +#define kBtKeySize 13 +#define kBtLevel 2 #define kBtInnerCount ((kBtSize - 4 /*sizeof(Hea) */) / (kBtKeySize + 2 /*sizeof(Inner) */)) -#define kBtLeafCount ((kBtSize - 4 /*sizeof(Hea) */) / (kBtKeySize + 4 + 2 /*sizeof(BtKeypack) */)) - -#define kBtValNone 0xFFFF -#define kBtValRoot 0 +#define kBtLeafCount ((kBtSize - 4 /*sizeof(Hea) */) / (kBtKeySize + 4 + 2 /*sizeof(BtKeypack) */)) +#define kBtValNone 0xFFFF +#define kBtValRoot 0 +#define kLineMaxSize 512 +#define kBufferSize 2048 +#define kCatName "VOL.CAT" +#define kDatName "VOL.DAT" struct BtKeypack { char _key[kBtKeySize]; @@ -58,6 +61,60 @@ struct Hea { uint16 _down; }; +class XFile { +public: + uint16 _error; + + XFile() : _error(0) { } + virtual ~XFile() { } + virtual uint16 read(void *buf, uint16 len) = 0; + virtual long mark() = 0; + virtual long size() = 0; + virtual long seek(long pos) = 0; +}; + +class IoHand : public XFile { +protected: + Common::File *_file; + uint16 _seed; + Crypt *_crypt; +public: + IoHand(const char *name, Crypt crypt); + IoHand(Crypt *crypt); + virtual ~IoHand(); + static bool exist(const char *name); + uint16 read(void *buf, uint16 len); + long mark(); + long size(); + long seek(long pos); +}; + +class IoBuf : public IoHand { +protected: + uint8 *_buff; + uint16 _ptr; + uint16 _lim; + long _bufMark; + virtual void readBuf(); +public: + IoBuf(Crypt *crpt); + IoBuf(const char *name, Crypt *crpt); + virtual ~IoBuf(); + uint16 read(void *buf, uint16 len); + uint16 read(uint8 *buf); + int read(); +}; + + +class CFile : public IoBuf { +public: + static uint16 _maxLineLen; + CFile(const char *name, Crypt *crpt); + virtual ~CFile(); + long mark(); + long seek(long pos); +}; + struct BtPage { Hea _hea; union { @@ -87,6 +144,37 @@ public: BtKeypack *next(); }; +class Dat { + friend class VFile; + CFile _file; +public: + Dat(); + bool read(long org, uint16 len, uint8 *buf); +}; + +class VFile : public IoBuf { +private: + static Dat *_dat; + static BtFile *_cat; + static VFile *_recent; + + long _begMark; + long _endMark; + + void readBuf(); +public: + VFile(const char *name); + ~VFile(); + + static void init(); + static void deinit(); + static bool exist(const char *name); + static const char *next(); + long mark(); + long size(); + long seek(long pos); +}; + } // End of namespace CGE #endif diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index a3258e9415a..68db71e9188 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -124,38 +124,6 @@ char *forceExt(char *buf, const char *name, const char *ext) { return buf; } -static unsigned Seed = 0xA5; - -unsigned fastRand() { - return Seed = 257 * Seed + 817; -} -unsigned fastRand(unsigned s) { - return Seed = 257 * s + 817; -} - -uint16 RCrypt(void *buf, uint16 siz, uint16 seed) { - if (buf && siz) { - byte *b = static_cast(buf); - byte *q = b + (siz - 1); - seed = fastRand(seed); - *b++ ^= seed; - while (buf < q) - *b++ ^= fastRand(); - if (buf == q) - *b ^= (seed = fastRand()); - } - return seed; -} - -uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { - byte *b = static_cast(buf); - - for (uint16 i = 0; i < siz; i++) - *b++ ^= seed; - - return seed; -} - uint16 atow(const char *a) { if (!a) return 0; @@ -202,51 +170,6 @@ char *dwtom(uint32 val, char *str, int radix, int len) { return str; } -IoHand::IoHand(Crypt *crypt) - : XFile(), _crypt(crypt), _seed(kCryptSeed) { - _file = new Common::File(); -} - -IoHand::IoHand(const char *name, Crypt *crypt) - : XFile(), _crypt(crypt), _seed(kCryptSeed) { - _file = new Common::File(); - _file->open(name); -} - -IoHand::~IoHand() { - _file->close(); - delete _file; -} - -uint16 IoHand::read(void *buf, uint16 len) { - if (!_file->isOpen()) - return 0; - - uint16 bytesRead = _file->read(buf, len); - if (!bytesRead) - error("Read %s - %d bytes", _file->getName(), len); - if (_crypt) - _seed = _crypt(buf, len, Seed); - return bytesRead; -} - -long IoHand::mark() { - return _file->pos(); -} - -long IoHand::seek(long pos) { - _file->seek(pos, SEEK_SET); - return _file->pos(); -} - -long IoHand::size() { - return _file->size(); -} - -bool IoHand::exist(const char *name) { - return Common::File::exists(name); -} - void sndSetVolume() { warning("STUB: SNDSetVolume"); } diff --git a/engines/cge/general.h b/engines/cge/general.h index 37f492a5381..fbb5fc4c453 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -64,43 +64,6 @@ T min(T A, T B) { return (A < B) ? A : B; } -class XFile { -public: - uint16 _error; - - XFile() : _error(0) { } - virtual ~XFile() { } - virtual uint16 read(void *buf, uint16 len) = 0; - virtual long mark() = 0; - virtual long size() = 0; - virtual long seek(long pos) = 0; -}; - - -template -inline uint16 XRead(XFile *xf, T *t) { - return xf->read((uint8 *) t, sizeof(*t)); -} - - -class IoHand : public XFile { -protected: - Common::File *_file; - uint16 _seed; - Crypt *_crypt; -public: - IoHand(const char *name, Crypt crypt = NULL); - IoHand(Crypt *crypt = NULL); - virtual ~IoHand(); - static bool exist(const char *name); - uint16 read(void *buf, uint16 len); - long mark(); - long size(); - long seek(long pos); -}; - -Crypt XCrypt; -Crypt RCrypt; uint16 atow(const char *a); uint16 xtow(const char *x); char *wtom(uint16 val, char *str, int radix, int len); @@ -112,9 +75,6 @@ char *forceExt(char *buf, const char *name, const char *ext); // MISSING FUNCTIONS const char *progName(const char *ext = NULL); -unsigned fastRand(); -unsigned fastRand(unsigned s); -uint16 rCrypt(void *buf, uint16 siz, uint16 seed); int newRandom(int range); } // End of namespace CGE diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h index 0ba8a1956b2..490c79803a2 100644 --- a/engines/cge/jbw.h +++ b/engines/cge/jbw.h @@ -32,11 +32,6 @@ namespace CGE { -// Defines found in cge.mak -#define INI_FILE VFile // Or is it CFile? -#define PIC_FILE VFile -// - #define kMaxFile 128 #define IsDigit(c) ((c) >= '0' && (c) <= '9') diff --git a/engines/cge/module.mk b/engines/cge/module.mk index e71de2d9e47..6d34cdfd14f 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -2,13 +2,12 @@ MODULE := engines/cge MODULE_OBJS := \ bitmap.o \ - btfile.o \ - cfile.o \ cge.o \ cge_main.o \ console.o \ detection.o \ events.o \ + fileio.o \ game.o \ general.o \ gettext.o \ @@ -18,7 +17,6 @@ MODULE_OBJS := \ text.o \ vga13h.o \ vmenu.o \ - vol.o \ walk.o MODULE_DIRS += \ diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 432bca75b53..daef3fa429d 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -28,8 +28,6 @@ #include "cge/general.h" #include "cge/sound.h" #include "cge/text.h" -#include "cge/cfile.h" -#include "cge/vol.h" #include "cge/cge_main.h" #include "common/config-manager.h" #include "common/memstream.h" @@ -126,7 +124,7 @@ void Fx::preload(int ref0) { for (int ref = ref0; ref < ref0 + 10; ref++) { static char fname[] = "FX00000.WAV"; wtom(ref, fname + 2, 10, 5); - INI_FILE file = INI_FILE(fname); + VFile file = VFile(fname); DataCk *wav = loadWave(&file); if (wav) { Han *p = &_cache[find(0)]; @@ -142,7 +140,7 @@ DataCk *Fx::load(int idx, int ref) { static char fname[] = "FX00000.WAV"; wtom(ref, fname + 2, 10, 5); - INI_FILE file = INI_FILE(fname); + VFile file = VFile(fname); DataCk *wav = loadWave(&file); if (wav) { Han *p = &_cache[idx]; @@ -203,14 +201,14 @@ void MusicPlayer::killMidi() { void MusicPlayer::loadMidi(int ref) { // Work out the filename and check the given MIDI file exists Common::String filename = Common::String::format("%.2d.MID", ref); - if (!INI_FILE::exist(filename.c_str())) + if (!VFile::exist(filename.c_str())) return; // Stop any currently playing MIDI file killMidi(); // Read in the data for the file - INI_FILE mid(filename.c_str()); + VFile mid(filename.c_str()); _dataSize = mid.size(); _data = (byte *)malloc(_dataSize); mid.read(_data, _dataSize); diff --git a/engines/cge/sound.h b/engines/cge/sound.h index e6bc2dedde2..53f57a19b09 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -28,7 +28,7 @@ #ifndef __CGE_SOUND__ #define __CGE_SOUND__ -#include "cge/general.h" +#include "cge/fileio.h" #include "cge/snddrv.h" #include "audio/audiostream.h" #include "audio/decoders/wave.h" diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 812fa1d9dcf..5e8aa1b869d 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -27,7 +27,6 @@ #include "cge/general.h" #include "cge/talk.h" -#include "cge/vol.h" #include "cge/game.h" #include "cge/events.h" @@ -50,7 +49,7 @@ Font::~Font() { } void Font::load() { - INI_FILE f(_path); + VFile f(_path); if (f._error) return; @@ -61,6 +60,7 @@ void Font::load() { uint16 p = 0; for (uint16 i = 0; i < kPosSize; i++) { _pos[i] = p; + warning("Fonts 0x%X 0x%X", i, p); p += _wid[i]; } f.read(_map, p); diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 0e6fc409201..973aadd23af 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -28,7 +28,6 @@ #include "cge/general.h" #include "cge/text.h" #include "cge/talk.h" -#include "cge/vol.h" #include "cge/game.h" #include "cge/snail.h" #include "cge/cge_main.h" @@ -41,7 +40,7 @@ Talk *_talk = NULL; Text::Text(CGEEngine *vm, const char *fname, int size) : _vm(vm) { _cache = new Han[size]; mergeExt(_fileName, fname, kSayExt); - if (!INI_FILE::exist(_fileName)) + if (!VFile::exist(_fileName)) error("No talk (%s)\n", _fileName); for (_size = 0; _size < size; _size++) { @@ -78,7 +77,7 @@ int Text::find(int ref) { void Text::preload(int from, int upto) { - INI_FILE tf = _fileName; + VFile tf = _fileName; if (tf._error) return; @@ -123,7 +122,7 @@ void Text::preload(int from, int upto) { char *Text::load(int idx, int ref) { - INI_FILE tf = _fileName; + VFile tf = _fileName; if (tf._error) return NULL; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 8213a1bcf37..317cb415f87 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -31,7 +31,6 @@ #include "cge/general.h" #include "cge/vga13h.h" #include "cge/bitmap.h" -#include "cge/vol.h" #include "cge/text.h" #include "cge/cge_main.h" #include "cge/cge.h" @@ -232,8 +231,8 @@ Sprite *Sprite::expand() { Snail::Com *nea = NULL; Snail::Com *tak = NULL; mergeExt(fname, _file, kSprExt); - if (INI_FILE::exist(fname)) { // sprite description file exist - INI_FILE sprf(fname); + if (VFile::exist(fname)) { // sprite description file exist + VFile sprf(fname); if (!(sprf._error==0)) error("Bad SPR [%s]", fname); int len = 0, lcnt = 0; diff --git a/engines/cge/vol.cpp b/engines/cge/vol.cpp deleted file mode 100644 index ff0a979b1de..00000000000 --- a/engines/cge/vol.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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/vol.h" -#include "common/system.h" -#include "common/str.h" -#include "cge/cge.h" -#include "common/debug.h" -#include "common/debug-channels.h" - -namespace CGE { - -Dat *VFile::_dat = NULL; -BtFile *VFile::_cat = NULL; -VFile *VFile::_recent = NULL; - -/*-----------------------------------------------------------------------*/ - -Dat::Dat(): _file(DAT_NAME, CRP) { - debugC(1, kCGEDebugFile, "Dat::Dat()"); -} - -/*-----------------------------------------------------------------------*/ - -void VFile::init() { - debugC(1, kCGEDebugFile, "VFile::init()"); - - _dat = new Dat(); - _cat = new BtFile(CAT_NAME, CRP); - _recent = NULL; -} - -void VFile::deinit() { - delete _dat; - delete _cat; -} - -VFile::VFile(const char *name) - : IoBuf(NULL) { - debugC(3, kCGEDebugFile, "VFile::VFile(%s)", name); - - if (_dat->_file._error || _cat->_error) - error("Bad volume data"); - BtKeypack *kp = _cat->find(name); - if (scumm_stricmp(kp->_key, name) != 0) - _error = 1; - _endMark = (_bufMark = _begMark = kp->_mark) + kp->_size; -} - -VFile::~VFile() { - if (_recent == this) - _recent = NULL; -} - -bool VFile::exist(const char *name) { - debugC(1, kCGEDebugFile, "VFile::exist(%s)", name); - - return scumm_stricmp(_cat->find(name)->_key, name) == 0; -} - -void VFile::readBuf() { - debugC(3, kCGEDebugFile, "VFile::readBuf()"); - - if (_recent != this) { - _dat->_file.seek(_bufMark + _lim); - _recent = this; - } - _bufMark = _dat->_file.mark(); - long n = _endMark - _bufMark; - if (n > kBufferSize) - n = kBufferSize; - _lim = _dat->_file.read(_buff, (uint16) n); - _ptr = 0; -} - -long VFile::mark() { - debugC(5, kCGEDebugFile, "VFile::mark()"); - - return (_bufMark + _ptr) - _begMark; -} - -long VFile::size() { - debugC(1, kCGEDebugFile, "VFile::size()"); - - return _endMark - _begMark; -} - -long VFile::seek(long pos) { - debugC(1, kCGEDebugFile, "VFile::seel(%ld)", pos); - - _recent = NULL; - _lim = 0; - return (_bufMark = _begMark + pos); -} - -} // End of namespace CGE diff --git a/engines/cge/vol.h b/engines/cge/vol.h deleted file mode 100644 index d7184ba0645..00000000000 --- a/engines/cge/vol.h +++ /dev/null @@ -1,77 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __CGE_VOL__ -#define __CGE_VOL__ - -#include "cge/btfile.h" -#include "cge/cfile.h" - -namespace CGE { - -#define CAT_NAME "VOL.CAT" -#define DAT_NAME "VOL.DAT" - -#define CRP XCrypt -#define XMASK 0xA5 -#define VOLBASE CFile - -class Dat { - friend class VFile; - VOLBASE _file; -public: - Dat(); - bool read(long org, uint16 len, uint8 *buf); -}; - -class VFile : public IoBuf { -private: - static Dat *_dat; - static BtFile *_cat; - static VFile *_recent; - - long _begMark; - long _endMark; - - void readBuf(); -public: - VFile(const char *name); - ~VFile(); - - static void init(); - static void deinit(); - static bool exist(const char *name); - static const char *next(); - long mark(); - long size(); - long seek(long pos); -}; - - -} // End of namespace CGE - -#endif From a8ad211c3663130c151b7a5cad8f9fc550226449 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 27 Aug 2011 09:39:35 +0200 Subject: [PATCH 242/276] CGE: Merge talk.cpp and gettext.cpp --- engines/cge/cge_main.cpp | 1 - engines/cge/fileio.h | 4 +- engines/cge/gettext.cpp | 119 --------------------------------------- engines/cge/gettext.h | 61 -------------------- engines/cge/module.mk | 1 - engines/cge/talk.cpp | 85 ++++++++++++++++++++++++++++ engines/cge/talk.h | 29 ++++++++-- 7 files changed, 112 insertions(+), 188 deletions(-) delete mode 100644 engines/cge/gettext.cpp delete mode 100644 engines/cge/gettext.h diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index cf3e5223b44..2d83dce0407 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -43,7 +43,6 @@ #include "cge/events.h" #include "cge/talk.h" #include "cge/vmenu.h" -#include "cge/gettext.h" #include "cge/cge_main.h" #include "cge/cge.h" #include "cge/walk.h" diff --git a/engines/cge/fileio.h b/engines/cge/fileio.h index a8577207bd3..7cb5ce07e0b 100644 --- a/engines/cge/fileio.h +++ b/engines/cge/fileio.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_BTFILE__ -#define __CGE_BTFILE__ +#ifndef __CGE_FILEIO__ +#define __CGE_FILEIO__ #include "cge/general.h" #include "common/stream.h" diff --git a/engines/cge/gettext.cpp b/engines/cge/gettext.cpp deleted file mode 100644 index 46dacbe1ded..00000000000 --- a/engines/cge/gettext.cpp +++ /dev/null @@ -1,119 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#include "cge/gettext.h" -#include "cge/events.h" -#include "cge/cge_main.h" - -namespace CGE { - -GetText *GetText::_ptr = NULL; - -GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) - : Talk(vm), _text(text), _size(min(size, kGetTextMax)), _len(min(_size, strlen(text))), - _cntr(kGetTextBlink), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { - _ptr = this; - _mode = kTBRect; - - _ts = new BitmapPtr[2]; - const int i = 2 * kTextHMargin + _font->width(info); - _ts[0] = box((i + 3) & ~3, 2 * kTextVMargin + 2 * kFontHigh + kTextLineSpace); - _ts[1] = NULL; - setShapeList(_ts); - - _flags._bDel = true; - _flags._kill = true; - memcpy(_buff, text, _len); - _buff[_len] = ' '; - _buff[_len + 1] = '\0'; - putLine(0, info); - tick(); -} - -GetText::~GetText() { - _keyboard->setClient(_oldKeybClient); - _ptr = NULL; -} - -void GetText::tick() { - if (++_cntr >= kGetTextBlink) { - _buff[_len] ^= (' ' ^ '_'); - _cntr = 0; - } - putLine(1, _buff); - _time = kGetTextTime; -} - -void GetText::touch(uint16 mask, int x, int y) { - static char ogon[] = "•œ¥£˜ ¡"; - static char bezo[] = "ACELNOSXZ"; - char *p; - - if (mask & kEventKeyb) { - _vm->keyClick(); - switch (x) { - case Enter: - _buff[_len] = '\0'; - strcpy(_text, _buff); - for (p = _text; *p; p++) { - char *q = strchr(ogon, *p); - if (q) - *p = bezo[q - ogon]; - } - case Esc: - _snail_->addCom(kSnKill, -1, 0, this); - break; - case BSp: - if (_len) { - _len--; - _buff[_len] = _buff[_len + 1]; - _buff[_len + 1] = _buff[_len + 2]; - } - break; - default: - if (x < 'A' || x > 'Z') { - if (_oldKeybClient) - _oldKeybClient->touch(mask, x, y); - } else { - if (_keyboard->_key[kKeyAlt]) { - p = strchr(bezo, x); - if (p) - x = ogon[p - bezo]; - } - if (_len < _size && 2 * kTextHMargin + _font->width(_buff) + _font->_wid[x] <= _w) { - _buff[_len + 2] = _buff[_len + 1]; - _buff[_len + 1] = _buff[_len]; - _buff[_len++] = x; - } - } - break; - } - } else - Sprite::touch(mask, x, y); -} - -} // End of namespace CGE diff --git a/engines/cge/gettext.h b/engines/cge/gettext.h deleted file mode 100644 index 6afa9ccfecd..00000000000 --- a/engines/cge/gettext.h +++ /dev/null @@ -1,61 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __CGE_GETTEXT__ -#define __CGE_GETTEXT__ - -#include "cge/general.h" -#include "cge/talk.h" - -namespace CGE { - -#define kGetTextMax 24 -#define kGetTextBlink 6 -#define kGetTextTime 6 - -class GetText : public Talk { - char _buff[kGetTextMax + 2]; - char *_text; - uint16 _size; - uint16 _len; - uint16 _cntr; - Sprite *_oldKeybClient; - -public: - static GetText *_ptr; - GetText(CGEEngine *vm, const char *info, char *text, int size); - ~GetText(); - void touch(uint16 mask, int x, int y); - void tick(); - -private: - CGEEngine *_vm; -}; - -} // End of namespace CGE - -#endif diff --git a/engines/cge/module.mk b/engines/cge/module.mk index 6d34cdfd14f..62b319e1900 100644 --- a/engines/cge/module.mk +++ b/engines/cge/module.mk @@ -10,7 +10,6 @@ MODULE_OBJS := \ fileio.o \ game.o \ general.o \ - gettext.o \ snail.o \ sound.o \ talk.o \ diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 5e8aa1b869d..58c68339bb2 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -29,6 +29,7 @@ #include "cge/talk.h" #include "cge/game.h" #include "cge/events.h" +#include "cge/cge_main.h" namespace CGE { @@ -301,4 +302,88 @@ void InfoLine::update(const char *text) { _oldText = text; } +GetText *GetText::_ptr = NULL; + +GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) + : Talk(vm), _text(text), _size(min(size, kGetTextMax)), _len(min(_size, strlen(text))), + _cntr(kGetTextBlink), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { + _ptr = this; + _mode = kTBRect; + + _ts = new BitmapPtr[2]; + const int i = 2 * kTextHMargin + _font->width(info); + _ts[0] = box((i + 3) & ~3, 2 * kTextVMargin + 2 * kFontHigh + kTextLineSpace); + _ts[1] = NULL; + setShapeList(_ts); + + _flags._bDel = true; + _flags._kill = true; + memcpy(_buff, text, _len); + _buff[_len] = ' '; + _buff[_len + 1] = '\0'; + putLine(0, info); + tick(); +} + +GetText::~GetText() { + _keyboard->setClient(_oldKeybClient); + _ptr = NULL; +} + +void GetText::tick() { + if (++_cntr >= kGetTextBlink) { + _buff[_len] ^= (' ' ^ '_'); + _cntr = 0; + } + putLine(1, _buff); + _time = kGetTextTime; +} + +void GetText::touch(uint16 mask, int x, int y) { + static char ogon[] = "•œ¥£˜ ¡"; + static char bezo[] = "ACELNOSXZ"; + char *p; + + if (mask & kEventKeyb) { + _vm->keyClick(); + switch (x) { + case Enter: + _buff[_len] = '\0'; + strcpy(_text, _buff); + for (p = _text; *p; p++) { + char *q = strchr(ogon, *p); + if (q) + *p = bezo[q - ogon]; + } + case Esc: + _snail_->addCom(kSnKill, -1, 0, this); + break; + case BSp: + if (_len) { + _len--; + _buff[_len] = _buff[_len + 1]; + _buff[_len + 1] = _buff[_len + 2]; + } + break; + default: + if (x < 'A' || x > 'Z') { + if (_oldKeybClient) + _oldKeybClient->touch(mask, x, y); + } else { + if (_keyboard->_key[kKeyAlt]) { + p = strchr(bezo, x); + if (p) + x = ogon[p - bezo]; + } + if (_len < _size && 2 * kTextHMargin + _font->width(_buff) + _font->_wid[x] <= _w) { + _buff[_len + 2] = _buff[_len + 1]; + _buff[_len + 1] = _buff[_len]; + _buff[_len++] = x; + } + } + break; + } + } else + Sprite::touch(mask, x, y); +} } // End of namespace CGE diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 9a999e5e8e5..5bb4aa20525 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -28,9 +28,9 @@ #ifndef __CGE_TALK__ #define __CGE_TALK__ -#include "cge/vga13h.h" #include "cge/general.h" #include "cge/jbw.h" +#include "cge/vga13h.h" namespace CGE { @@ -43,10 +43,12 @@ namespace CGE { #define kWidSize 256 #define kPosSize 256 #define kMapSize (256*8) - -#define kFontHigh 8 -#define kFontExt ".CFT" +#define kFontHigh 8 +#define kFontExt ".CFT" #define kPathMax 128 +#define kGetTextMax 24 +#define kGetTextBlink 6 +#define kGetTextTime 6 enum TextBoxStyle { kTBPure, kTBRect, kTBRound }; @@ -93,6 +95,25 @@ private: CGEEngine *_vm; }; +class GetText : public Talk { + char _buff[kGetTextMax + 2]; + char *_text; + uint16 _size; + uint16 _len; + uint16 _cntr; + Sprite *_oldKeybClient; + +public: + static GetText *_ptr; + GetText(CGEEngine *vm, const char *info, char *text, int size); + ~GetText(); + void touch(uint16 mask, int x, int y); + void tick(); + +private: + CGEEngine *_vm; +}; + } // End of namespace CGE #endif From 4d059c0e62f6d1c2a78963a55e86d74a89373a56 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 27 Aug 2011 14:05:04 +0200 Subject: [PATCH 243/276] CGE: Remove user first name input, used originally for savegame names --- engines/cge/cge.h | 2 -- engines/cge/cge_main.cpp | 60 ++++++---------------------------------- 2 files changed, 9 insertions(+), 53 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index fbb096df074..f4260dc31a3 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -124,7 +124,6 @@ public: bool _game; int _now; int _lev; - char _usrFnam[15]; int _mode; int _soundOk; int _gameCase2Cpt; @@ -169,7 +168,6 @@ public: void runGame(); bool showTitle(const char *name); void movie(const char *ext); - void takeName(); void inf(const char *text); void selectSound(); void dummy() {} diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 2d83dce0407..5df7ab193e8 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -188,10 +188,6 @@ bool CGEEngine::loadGame(int slotNumber, SavegameHeader *header, bool tiny) { // Delete the thumbnail saveHeader.thumbnail->free(); delete saveHeader.thumbnail; - - // If we're loading the auto-save slot, load the name - if (slotNumber == 0) - strncpy(_usrFnam, saveHeader.saveName.c_str(), 8); } // Get in the savegame @@ -656,7 +652,7 @@ void CGEEngine::qGame() { saveSound(); // Write out the user's progress - saveGame(0, _usrFnam); + saveGame(0, ""); _vga->sunset(); _finis = true; @@ -851,24 +847,6 @@ void CGEEngine::startCountDown() { switchCave(-1); } -void CGEEngine::takeName() { - debugC(1, kCGEDebugEngine, "CGEEngine::takeName()"); - - if (GetText::_ptr) { - _snail_->addCom(kSnKill, -1, 0, GetText::_ptr); - } else { - memset(_usrFnam, 0, 15); - GetText *tn = new GetText(this, _text->getText(kGetNamePrompt), _usrFnam, 8); - if (tn) { - tn->setName(_text->getText(kGetNameTitle)); - tn->center(); - tn->gotoxy(tn->_x, tn->_y - 10); - tn->_z = 126; - _vga->_showQ->insert(tn); - } - } -} - void CGEEngine::switchMapping() { assert(_horzLine); debugC(1, kCGEDebugEngine, "CGEEngine::switchMapping()"); @@ -1487,41 +1465,23 @@ bool CGEEngine::showTitle(const char *name) { _midiPlayer.loadMidi(0); } - bool userOk = false; if (_mode < 2) { - if (_isDemo) { - strcpy(_usrFnam, progName(kSvgExt)); - userOk = true; - } else { -#ifndef EVA + if (!_isDemo) { // At this point the game originally set the protection variables // used by the copy protection check movie("X00"); // paylist _vga->copyPage(1, 2); _vga->copyPage(0, 1); _vga->_showQ->append(_mouse); - //Mouse.On(); - - // For ScummVM, skip prompting for name if a savegame in slot 0 already exists - if ((_startGameSlot == -1) && savegameExists(0)) { - strcpy(_usrFnam, "User"); - userOk = true; - } else { - for (takeName(); GetText::_ptr;) { - mainLoop(); - if (_eventManager->_quitFlag) - return false; - } - if (_keyboard->lastKey() == Enter && *_usrFnam) - userOk = true; - } - //Mouse.Off(); + // In the original game, the user had to enter his name + // As it was only used to name savegames, it has been removed _vga->_showQ->clear(); _vga->copyPage(0, 2); -#endif } - if (userOk && _mode == 0) { + if (_mode == 0) { +// The auto-load of savegame #0 is currently disabled +#if 0 if (savegameExists(0)) { // Load the savegame loadGame(0, NULL, true); // only system vars @@ -1532,6 +1492,7 @@ bool CGEEngine::showTitle(const char *name) { _flag[3] = false; } } else +#endif _mode++; } } @@ -1541,10 +1502,7 @@ bool CGEEngine::showTitle(const char *name) { _vga->copyPage(0, 2); - if (_isDemo) - return true; - else - return (_mode == 2 || userOk); + return true; } void CGEEngine::cge_main() { From fedd3108719405eb5de52206a8337de4c9cd875d Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 27 Aug 2011 14:08:39 +0200 Subject: [PATCH 244/276] CGE: Remove GetText class, which was used to enter the username --- engines/cge/talk.cpp | 84 -------------------------------------------- engines/cge/talk.h | 22 ------------ 2 files changed, 106 deletions(-) diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 58c68339bb2..9a4cd7caf52 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -302,88 +302,4 @@ void InfoLine::update(const char *text) { _oldText = text; } -GetText *GetText::_ptr = NULL; - -GetText::GetText(CGEEngine *vm, const char *info, char *text, int size) - : Talk(vm), _text(text), _size(min(size, kGetTextMax)), _len(min(_size, strlen(text))), - _cntr(kGetTextBlink), _oldKeybClient(_keyboard->setClient(this)), _vm(vm) { - _ptr = this; - _mode = kTBRect; - - _ts = new BitmapPtr[2]; - const int i = 2 * kTextHMargin + _font->width(info); - _ts[0] = box((i + 3) & ~3, 2 * kTextVMargin + 2 * kFontHigh + kTextLineSpace); - _ts[1] = NULL; - setShapeList(_ts); - - _flags._bDel = true; - _flags._kill = true; - memcpy(_buff, text, _len); - _buff[_len] = ' '; - _buff[_len + 1] = '\0'; - putLine(0, info); - tick(); -} - -GetText::~GetText() { - _keyboard->setClient(_oldKeybClient); - _ptr = NULL; -} - -void GetText::tick() { - if (++_cntr >= kGetTextBlink) { - _buff[_len] ^= (' ' ^ '_'); - _cntr = 0; - } - putLine(1, _buff); - _time = kGetTextTime; -} - -void GetText::touch(uint16 mask, int x, int y) { - static char ogon[] = "•œ¥£˜ ¡"; - static char bezo[] = "ACELNOSXZ"; - char *p; - - if (mask & kEventKeyb) { - _vm->keyClick(); - switch (x) { - case Enter: - _buff[_len] = '\0'; - strcpy(_text, _buff); - for (p = _text; *p; p++) { - char *q = strchr(ogon, *p); - if (q) - *p = bezo[q - ogon]; - } - case Esc: - _snail_->addCom(kSnKill, -1, 0, this); - break; - case BSp: - if (_len) { - _len--; - _buff[_len] = _buff[_len + 1]; - _buff[_len + 1] = _buff[_len + 2]; - } - break; - default: - if (x < 'A' || x > 'Z') { - if (_oldKeybClient) - _oldKeybClient->touch(mask, x, y); - } else { - if (_keyboard->_key[kKeyAlt]) { - p = strchr(bezo, x); - if (p) - x = ogon[p - bezo]; - } - if (_len < _size && 2 * kTextHMargin + _font->width(_buff) + _font->_wid[x] <= _w) { - _buff[_len + 2] = _buff[_len + 1]; - _buff[_len + 1] = _buff[_len]; - _buff[_len++] = x; - } - } - break; - } - } else - Sprite::touch(mask, x, y); -} } // End of namespace CGE diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 5bb4aa20525..2c546f34279 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -46,9 +46,6 @@ namespace CGE { #define kFontHigh 8 #define kFontExt ".CFT" #define kPathMax 128 -#define kGetTextMax 24 -#define kGetTextBlink 6 -#define kGetTextTime 6 enum TextBoxStyle { kTBPure, kTBRect, kTBRound }; @@ -95,25 +92,6 @@ private: CGEEngine *_vm; }; -class GetText : public Talk { - char _buff[kGetTextMax + 2]; - char *_text; - uint16 _size; - uint16 _len; - uint16 _cntr; - Sprite *_oldKeybClient; - -public: - static GetText *_ptr; - GetText(CGEEngine *vm, const char *info, char *text, int size); - ~GetText(); - void touch(uint16 mask, int x, int y); - void tick(); - -private: - CGEEngine *_vm; -}; - } // End of namespace CGE #endif From bc0e65baacedc5daebc55f0c16a83b5c1810ab88 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 27 Aug 2011 18:01:06 +0200 Subject: [PATCH 245/276] CGE: remove jbw.h, some clean up --- engines/cge/bitmap.cpp | 1 - engines/cge/cge_main.cpp | 10 ++--- engines/cge/events.h | 30 +++++++++++++- engines/cge/general.cpp | 2 +- engines/cge/general.h | 5 ++- engines/cge/jbw.h | 89 ---------------------------------------- engines/cge/snail.h | 1 - engines/cge/talk.h | 1 - engines/cge/text.h | 5 +-- 9 files changed, 38 insertions(+), 106 deletions(-) delete mode 100644 engines/cge/jbw.h diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 02265f09bcd..87bf49047fe 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -26,7 +26,6 @@ */ #include "cge/bitmap.h" -#include "cge/jbw.h" #include "cge/vga13h.h" #include "cge/cge_main.h" #include "common/system.h" diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 5df7ab193e8..8ac07b9f111 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -310,9 +310,7 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt _pocref[i] = (pocSpr) ? pocSpr->_ref : -1; } - warning("STUB: CGEEngine::syncGame Digital and Midi volume"); -// _volume[0] = _sndDrvInfo.Vol2._d; -// _volume[1] = _sndDrvInfo.Vol2._m; + // Skip Digital and Midi volumes, useless under ScummVM _volume[0] = 0; _volume[1] = 0; } @@ -329,9 +327,7 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt } else { // Loading game if (_soundOk == 1 && _mode == 0) { -// _sndDrvInfo.Vol2._d = _volume[0]; -// _sndDrvInfo.Vol2._m = _volume[1]; - warning("STUB: CGEEngine::syncGame Digital and Midi volume"); + // Skip Digital and Midi volumes, useless under ScummVM sndSetVolume(); } @@ -652,7 +648,7 @@ void CGEEngine::qGame() { saveSound(); // Write out the user's progress - saveGame(0, ""); + saveGame(0, Common::String("Automatic Savegame")); _vga->sunset(); _finis = true; diff --git a/engines/cge/events.h b/engines/cge/events.h index 9df09fdba50..9b7de9efd45 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -31,7 +31,6 @@ #include "common/events.h" #include "cge/game.h" #include "cge/talk.h" -#include "cge/jbw.h" #include "cge/vga13h.h" namespace CGE { @@ -52,6 +51,35 @@ enum EventMask { kEventKeyb = 1 << 7 }; +enum Keys { + NoKey = 0, CtrlA, CtrlB, CtrlC, CtrlD, CtrlE, CtrlF, CtrlG, CtrlH, + CtrlI, CtrlJ, CtrlK, CtrlL, CtrlM, CtrlN, CtrlO, CtrlP, + CtrlQ, CtrlR, CtrlS, CtrlT, CtrlU, CtrlV, CtrlW, CtrlX, + CtrlY, CtrlZ, + BSp = 8, Tab, + Enter = 13, + Eof = 26, Esc, + AltQ = 256 + 16, AltW, AltE, AltR, AltT, AltY, AltU, AltI, AltO, AltP, + AltA = 256 + 30, AltS, AltD, AltF, AltG, AltH, AltJ, AltK, AltL, + AltZ = 256 + 44, AltX, AltC, AltV, AltB, AltN, AltM, + F11 = 256 + 87, F12, + F1 = 256 + 59, F2, F3, F4, F5, F6, F7, F8, F9, F10, + ShiftTab = 256 + 15, + ShiftF1 = 256 + 84, ShiftF2, ShiftF3, ShiftF4, ShiftF5, + ShiftF6, ShiftF7, ShiftF8, ShiftF9, ShiftF10, + CtrlF1 = 256 + 94, CtrlF2, CtrlF3, CtrlF4, CtrlF5, + CtrlF6, CtrlF7, CtrlF8, CtrlF9, CtrlF10, + AltF1 = 256 + 104, AltF2, AltF3, AltF4, AltF5, + AltF6, AltF7, AltF8, AltF9, AltF10, + Home = 256 + 71, Up, PgUp, + Left = 256 + 75, Ctr, Right, + End = 256 + 79, Down, PgDn, Ins, Del, + CtrlLeft = 256 + 115, CtrlRight, CtrlEnd, CtrlPgDn, CtrlHome, + CtrlPgUp = 256 + 132, + MouseLeft = 512 + 1, MouseRight, + TwiceLeft = 512 + 256 + 1, TwiceRight +}; + class Keyboard { private: bool getKey(Common::Event &event, int &cgeCode); diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 68db71e9188..c20da2466c5 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -171,7 +171,7 @@ char *dwtom(uint32 val, char *str, int radix, int len) { } void sndSetVolume() { - warning("STUB: SNDSetVolume"); + // USeless for ScummVM } DataCk *loadWave(XFile *file) { diff --git a/engines/cge/general.h b/engines/cge/general.h index fbb5fc4c453..6a0bc136755 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -33,11 +33,14 @@ #include "common/random.h" #include "common/textconsole.h" #include "common/str.h" -#include "cge/jbw.h" namespace CGE { #define kCryptSeed 0xA5 +#define kMaxFile 128 +#define IsDigit(c) ((c) >= '0' && (c) <= '9') +#define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) +#define ArrayCount(a) (sizeof(a) / sizeof((a)[0])) struct Dac { uint8 _r; diff --git a/engines/cge/jbw.h b/engines/cge/jbw.h deleted file mode 100644 index 490c79803a2..00000000000 --- a/engines/cge/jbw.h +++ /dev/null @@ -1,89 +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. - * - */ - -/* - * This code is based on original Soltys source code - * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon - */ - -#ifndef __CGE_JBW__ -#define __CGE_JBW__ - -#include "common/scummsys.h" - -namespace CGE { - -#define kMaxFile 128 - -#define IsDigit(c) ((c) >= '0' && (c) <= '9') -#define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) -#define ArrayCount(a) (sizeof(a) / sizeof((a)[0])) - -enum Keys { - NoKey = 0, CtrlA, CtrlB, CtrlC, CtrlD, CtrlE, CtrlF, CtrlG, CtrlH, - CtrlI, CtrlJ, CtrlK, CtrlL, CtrlM, CtrlN, CtrlO, CtrlP, - CtrlQ, CtrlR, CtrlS, CtrlT, CtrlU, CtrlV, CtrlW, CtrlX, - CtrlY, CtrlZ, - BSp = 8, - Tab = 9, - Enter = 13, - Eof = 26, - Esc = 27, - AltQ = 256 + 16, AltW, AltE, AltR, AltT, AltY, AltU, AltI, AltO, AltP, - AltA = 256 + 30, AltS, AltD, AltF, AltG, AltH, AltJ, AltK, AltL, - AltZ = 256 + 44, AltX, AltC, AltV, AltB, AltN, AltM, - F11 = 256 + 87, F12, - F1 = 256 + 59, F2, F3, F4, F5, F6, F7, F8, F9, F10, - ShiftTab = 256 + 15, - ShiftF1 = 256 + 84, ShiftF2, ShiftF3, ShiftF4, ShiftF5, - ShiftF6, ShiftF7, ShiftF8, ShiftF9, ShiftF10, - CtrlF1 = 256 + 94, CtrlF2, CtrlF3, CtrlF4, CtrlF5, - CtrlF6, CtrlF7, CtrlF8, CtrlF9, CtrlF10, - AltF1 = 256 + 104, AltF2, AltF3, AltF4, AltF5, - AltF6, AltF7, AltF8, AltF9, AltF10, - Home = 256 + 71, - Up, - PgUp, - Left = 256 + 75, - Ctr, - Right, - End = 256 + 79, - Down, - PgDn, - Ins, - Del, - CtrlLeft = 256 + 115, - CtrlRight, - CtrlEnd, - CtrlPgDn, - CtrlHome, - CtrlPgUp = 256 + 132, - - MouseLeft = 512 + 1, - MouseRight, - TwiceLeft = 512 + 256 + 1, - TwiceRight -}; - -} // End of namespace CGE - -#endif diff --git a/engines/cge/snail.h b/engines/cge/snail.h index e478ad95ff1..c2290da9110 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -28,7 +28,6 @@ #ifndef __CGE_SNAIL__ #define __CGE_SNAIL__ -#include "cge/jbw.h" #include "cge/cge.h" namespace CGE { diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 2c546f34279..3591fc6fccc 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -29,7 +29,6 @@ #define __CGE_TALK__ #include "cge/general.h" -#include "cge/jbw.h" #include "cge/vga13h.h" namespace CGE { diff --git a/engines/cge/text.h b/engines/cge/text.h index d6845f4361f..d4607f8f3c9 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -29,14 +29,11 @@ #define __CGE_TEXT__ #include "cge/talk.h" -#include "cge/jbw.h" namespace CGE { -#define kSysTextMax 1000 - #define kSayExt ".SAY" - +#define kSysTextMax 1000 #define kTextNoMouse 95 #define kInfName 101 #define kSayName 102 From ad244d464cbae3fdef27caf948f33b8f7884bad9 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 27 Aug 2011 18:14:50 +0200 Subject: [PATCH 246/276] CGE: Set slot #0 as write protected as it's an automatic savegame --- engines/cge/detection.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index e944f2e9b75..383eb3933a2 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -215,6 +215,11 @@ SaveStateDescriptor CGEMetaEngine::querySaveMetaInfos(const char *target, int sl desc.setSaveDate(header.saveYear, header.saveMonth, header.saveDay); desc.setSaveTime(header.saveHour, header.saveMinutes); + // Slot 0 is used for the 'automatic save on exit' save in Soltys, thus + // we prevent it from being deleted or overwritten by accident. + desc.setDeletableFlag(slot != 0); + desc.setWriteProtectedFlag(slot == 0); + return desc; } } From 4cb6c739a4cf75a0e072197845a54620db0b10b8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 27 Aug 2011 19:09:13 +0200 Subject: [PATCH 247/276] CGE: Change a couple of static members to non static in Vga class --- engines/cge/cge.cpp | 2 -- engines/cge/cge_main.cpp | 16 +++++------ engines/cge/snail.cpp | 8 +++--- engines/cge/vga13h.cpp | 59 ++++++++++++++-------------------------- engines/cge/vga13h.h | 6 ++-- 5 files changed, 35 insertions(+), 56 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 0dbc1c8696f..f471b63866f 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -117,7 +117,6 @@ void CGEEngine::setup() { _console = new CGEConsole(this); // Initialise classes that have static members - Vga::init(); VFile::init(); Bitmap::init(); Talk::init(); @@ -178,7 +177,6 @@ CGEEngine::~CGEEngine() { Talk::deinit(); Bitmap::deinit(); VFile::deinit(); - Vga::deinit(); Cluster::init(this); // Remove all of our debug levels here diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 8ac07b9f111..a784b10c1d5 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -545,7 +545,7 @@ void CGEEngine::showBak(int ref) { if (!spr) return; - Bitmap::_pal = Vga::_sysPal; + Bitmap::_pal = _vga->_sysPal; spr->expand(); Bitmap::_pal = NULL; spr->show(2); @@ -600,7 +600,7 @@ void CGEEngine::caveUp() { if (_shadow) { _vga->_showQ->remove(_shadow); - _shadow->makeXlat(glass(Vga::_sysPal, 204, 204, 204)); + _shadow->makeXlat(glass(_vga->_sysPal, 204, 204, 204)); _vga->_showQ->insert(_shadow, _hero); _shadow->_z = _hero->_z; } @@ -608,7 +608,7 @@ void CGEEngine::caveUp() { _vga->show(); _vga->copyPage(1, 0); _vga->show(); - _vga->sunrise(Vga::_sysPal); + _vga->sunrise(_vga->_sysPal); _dark = false; if (!_startupMode) _mouse->on(); @@ -689,7 +689,7 @@ System::System(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { } void System::setPal() { - Dac *p = Vga::_sysPal + 256 - ArrayCount(_stdPal); + Dac *p = _vga->_sysPal + 256 - ArrayCount(_stdPal); for (uint i = 0; i < ArrayCount(_stdPal); i++) { p[i]._r = _stdPal[i]._r >> 2; p[i]._g = _stdPal[i]._g >> 2; @@ -813,7 +813,7 @@ void CGEEngine::switchColorMode() { _snail_->addCom(kSnSeq, 121, _vga->_mono = !_vga->_mono, NULL); keyClick(); - _vga->setColors(Vga::_sysPal, 64); + _vga->setColors(_vga->_sysPal, 64); } void CGEEngine::switchMusic() { @@ -1419,7 +1419,7 @@ bool CGEEngine::showTitle(const char *name) { if (_eventManager->_quitFlag) return false; - Bitmap::_pal = Vga::_sysPal; + Bitmap::_pal = _vga->_sysPal; BitmapPtr *LB = new BitmapPtr[2]; LB[0] = new Bitmap(name); LB[1] = NULL; @@ -1440,7 +1440,7 @@ bool CGEEngine::showTitle(const char *name) { _vga->copyPage(1, 2); _vga->copyPage(0, 1); selectPocket(-1); - _vga->sunrise(Vga::_sysPal); + _vga->sunrise(_vga->_sysPal); if (_mode < 2 && !_soundOk) { _vga->copyPage(1, 2); @@ -1481,7 +1481,7 @@ bool CGEEngine::showTitle(const char *name) { if (savegameExists(0)) { // Load the savegame loadGame(0, NULL, true); // only system vars - _vga->setColors(Vga::_sysPal, 64); + _vga->setColors(_vga->_sysPal, 64); _vga->update(); if (_flag[3]) { //flag FINIS _mode++; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 756c2675aa5..7893b9d539d 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -565,7 +565,7 @@ void CGEEngine::snSend(Sprite *spr, int val) { spr->_flags._slav = false; } else { if (spr->_ref % 1000 == 0) - Bitmap::_pal = Vga::_sysPal; + Bitmap::_pal = _vga->_sysPal; if (spr->_flags._back) spr->backShow(true); else @@ -856,7 +856,7 @@ void CGEEngine::snFlash(bool on) { if (on) { Dac *pal = (Dac *) malloc(sizeof(Dac) * kPalCount); if (pal) { - memcpy(pal, Vga::_sysPal, kPalSize); + memcpy(pal, _vga->_sysPal, kPalSize); for (int i = 0; i < kPalCount; i++) { register int c; c = pal[i]._r << 1; @@ -869,7 +869,7 @@ void CGEEngine::snFlash(bool on) { _vga->setColors(pal, 64); } } else - _vga->setColors(Vga::_sysPal, 64); + _vga->setColors(_vga->_sysPal, 64); _dark = false; } @@ -877,7 +877,7 @@ void CGEEngine::snLight(bool in) { debugC(1, kCGEDebugEngine, "CGEEngine::snLight(%s)", in ? "true" : "false"); if (in) - _vga->sunrise(Vga::_sysPal); + _vga->sunrise(_vga->_sysPal); else _vga->sunset(); _dark = !in; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 317cb415f87..d510b98f452 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -448,7 +448,6 @@ void Sprite::center() { void Sprite::show() { SprExt *e; -// asm cli // critic section... e = _ext; e->_x0 = e->_x1; e->_y0 = e->_y1; @@ -456,7 +455,6 @@ void Sprite::show() { e->_x1 = _x; e->_y1 = _y; e->_b1 = shp(); -// asm sti // ...done! if (!_flags._hide) { if (_flags._xlat) e->_b1->xShow(e->_x1, e->_y1); @@ -466,10 +464,10 @@ void Sprite::show() { } void Sprite::show(uint16 pg) { - Graphics::Surface *a = Vga::_page[1]; - Vga::_page[1] = Vga::_page[pg & 3]; + Graphics::Surface *a = _vga->_page[1]; + _vga->_page[1] = _vga->_page[pg & 3]; shp()->show(_x, _y); - Vga::_page[1] = a; + _vga->_page[1] = a; } void Sprite::hide() { @@ -673,45 +671,24 @@ Sprite *Queue::locate(int ref) { return NULL; } -//extern const char Copr[]; -Graphics::Surface *Vga::_page[4]; -Dac *Vga::_sysPal; +Vga::Vga() : _frmCnt(0), _msg(NULL), _name(NULL), _setPal(false), _mono(0) { + _oldColors = NULL; + _newColors = NULL; + _showQ = new Queue(true); + _spareQ = new Queue(false); + _sysPal = new Dac[kPalCount]; -void Vga::init() { for (int idx = 0; idx < 4; idx++) { _page[idx] = new Graphics::Surface(); _page[idx]->create(320, 200, Graphics::PixelFormat::createFormatCLUT8()); } - _sysPal = new Dac[kPalCount]; -} - -void Vga::deinit() { - for (int idx = 0; idx < 4; idx++) { - _page[idx]->free(); - delete _page[idx]; - } - delete[] _sysPal; -} - -Vga::Vga() - : _frmCnt(0), _msg(NULL), _name(NULL), _setPal(false), _mono(0) { - _oldColors = NULL; - _newColors = NULL; - _showQ = new Queue(true); - _spareQ = new Queue(false); - - bool std = true; for (int i = 10; i < 20; i++) { char *text = _text->getText(i); if (text) { debugN(1, "%s\n", text); - std = false; } } - if (std) -// warning(Copr); - warning("TODO: Fix Copr"); _oldColors = (Dac *) malloc(sizeof(Dac) * kPalCount); _newColors = (Dac *) malloc(sizeof(Dac) * kPalCount); @@ -743,6 +720,12 @@ Vga::~Vga() { delete _showQ; delete _spareQ; + delete[] _sysPal; + + for (int idx = 0; idx < 4; idx++) { + _page[idx]->free(); + delete _page[idx]; + } } void Vga::waitVR() { @@ -862,14 +845,14 @@ void Bitmap::xShow(int16 x, int16 y) { debugC(4, kCGEDebugBitmap, "Bitmap::xShow(%d, %d)", x, y); const byte *srcP = (const byte *)_v; - byte *destEndP = (byte *)Vga::_page[1]->pixels + (kScrWidth * kScrHeight); + byte *destEndP = (byte *)_vga->_page[1]->pixels + (kScrWidth * kScrHeight); byte *lookupTable = _m; // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data // must be decompressed and inserted into the surface for (int planeCtr = 0; planeCtr < 4; planeCtr++) { - byte *destP = (byte *)Vga::_page[1]->getBasePtr(x + planeCtr, y); + byte *destP = (byte *)_vga->_page[1]->getBasePtr(x + planeCtr, y); for (;;) { uint16 v = READ_LE_UINT16(srcP); @@ -915,13 +898,13 @@ void Bitmap::show(int16 x, int16 y) { debugC(5, kCGEDebugBitmap, "Bitmap::show(%d, %d)", x, y); const byte *srcP = (const byte *)_v; - byte *destEndP = (byte *)Vga::_page[1]->pixels + (kScrWidth * kScrHeight); + byte *destEndP = (byte *)_vga->_page[1]->pixels + (kScrWidth * kScrHeight); // Loop through processing data for each plane. The game originally ran in plane mapped mode, where a // given plane holds each fourth pixel sequentially. So to handle an entire picture, each plane's data // must be decompressed and inserted into the surface for (int planeCtr = 0; planeCtr < 4; planeCtr++) { - byte *destP = (byte *)Vga::_page[1]->getBasePtr(x + planeCtr, y); + byte *destP = (byte *)_vga->_page[1]->getBasePtr(x + planeCtr, y); for (;;) { uint16 v = READ_LE_UINT16(srcP); @@ -979,8 +962,8 @@ void Bitmap::hide(int16 x, int16 y) { debugC(5, kCGEDebugBitmap, "Bitmap::hide(%d, %d)", x, y); for (int yp = y; yp < y + _h; yp++) { - const byte *srcP = (const byte *)Vga::_page[2]->getBasePtr(x, yp); - byte *destP = (byte *)Vga::_page[1]->getBasePtr(x, yp); + const byte *srcP = (const byte *)_vga->_page[2]->getBasePtr(x, yp); + byte *destP = (byte *)_vga->_page[1]->getBasePtr(x, yp); Common::copy(srcP, srcP + _w, destP); } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 96492010214..e917e86a323 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -196,13 +196,11 @@ public: Queue *_showQ; Queue *_spareQ; int _mono; - static Graphics::Surface *_page[4]; - static Dac *_sysPal; + Graphics::Surface *_page[4]; + Dac *_sysPal; Vga(); ~Vga(); - static void init(); - static void deinit(); void getColors(Dac *tab); void setColors(Dac *tab, int lum); From dc9cca5f46c513da929561b7bee2f78909881626 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sat, 27 Aug 2011 23:54:18 +0200 Subject: [PATCH 248/276] CGE: Fix level when restoring a game --- engines/cge/cge_main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index a784b10c1d5..f09b374b8a5 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -224,6 +224,8 @@ Common::Error CGEEngine::loadGameState(int slot) { // Load the game loadGame(slot, NULL); + _lev = _oldLev; + _snail->addCom(kSnLevel, -1, _oldLev, &_cavLight); caveUp(); return Common::kNoError; @@ -331,7 +333,7 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt sndSetVolume(); } - if (! tiny) { // load sprites & pocket + if (!tiny) { // load sprites & pocket while (readStream->pos() < readStream->size()) { Sprite S(this, NULL); S.sync(s); @@ -350,7 +352,6 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt } } } - debugC(1, kCGEDebugEngine, "CGEEngine::saveSound()"); } bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &header) { @@ -364,7 +365,8 @@ bool CGEEngine::readSavegameHeader(Common::InSaveFile *in, SavegameHeader &heade // Read in the string header.saveName.clear(); char ch; - while ((ch = (char)in->readByte()) != '\0') header.saveName += ch; + while ((ch = (char)in->readByte()) != '\0') + header.saveName += ch; // Get the thumbnail header.thumbnail = Graphics::loadThumbnail(*in); From 12b6851276d8249ad499c54f25d0dd8e84998384 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 28 Aug 2011 00:35:00 +0200 Subject: [PATCH 249/276] CGE: Fix glitch in previous commit --- engines/cge/cge_main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index f09b374b8a5..6aa3052399f 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -224,7 +224,6 @@ Common::Error CGEEngine::loadGameState(int slot) { // Load the game loadGame(slot, NULL); - _lev = _oldLev; _snail->addCom(kSnLevel, -1, _oldLev, &_cavLight); caveUp(); From a14a9bb9a22d356a04bbacc3880d36a7ec1a9c57 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 28 Aug 2011 00:48:53 +0200 Subject: [PATCH 250/276] CGE: Fix ending animation - Game is now completable --- engines/cge/cge_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 6aa3052399f..8763cb99670 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -1375,7 +1375,7 @@ void CGEEngine::runGame() { _keyboard->setClient(_sys); // main loop while (!_finis && !_eventManager->_quitFlag) { - if (_finis) + if (_flag[3]) _snail->addCom2(kSnExec, -1, 0, kQGame); mainLoop(); } From a8d6b92b5a02d582e34d1249d973a9273909db4c Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 29 Aug 2011 00:29:22 +0200 Subject: [PATCH 251/276] CGE: Little cleanup of the English data file and update the detection --- engines/cge/detection.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index 383eb3933a2..5e741662225 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -79,8 +79,8 @@ static const ADGameDescription gameDescriptions[] = { { "soltys", "", { - {"vol.cat", 0, "bfea076fee47b8d64fdf213e56c60911", 50176}, - {"vol.dat", 0, "f9ae2e7f8f7cac91378cdafca43faf1e", 8427396}, + {"vol.cat", 0, "bd08969b5f1acea0f92d195f750c17d5", 50176}, + {"vol.dat", 0, "f9ae2e7f8f7cac91378cdafca43faf1e", 8428832}, AD_LISTEND }, Common::EN_ANY, Common::kPlatformPC, ADGF_NO_FLAGS, GUIO_NONE From 5e0c546aa99b789d528da307dac99dc704a0a995 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 29 Aug 2011 22:51:45 +0200 Subject: [PATCH 252/276] CGE: Remove code related to demos, and tag demos as unsupported --- engines/cge/cge.cpp | 60 ++++++++++++++++----------------------- engines/cge/cge.h | 5 ++-- engines/cge/cge_main.cpp | 42 +++++++++------------------ engines/cge/detection.cpp | 37 ++++++++++++------------ 4 files changed, 59 insertions(+), 85 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index f471b63866f..514580bbe35 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -46,7 +46,6 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) DebugMan.addDebugChannel(kCGEDebugFile, "file", "CGE IO debug channel"); DebugMan.addDebugChannel(kCGEDebugEngine, "engine", "CGE Engine debug channel"); - _isDemo = _gameDescription->flags & ADGF_DEMO; _startupMode = 1; _demoText = kDemo; _oldLev = 0; @@ -55,32 +54,17 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) } void CGEEngine::initCaveValues() { - if (_isDemo) { - _caveDx = 23; - _caveDy = 29; - _caveNx = 3; - _caveNy = 1; - } else { - _caveDx = 9; - _caveDy = 10; - _caveNx = 8; - _caveNy = 3; - } + _caveDx = 9; + _caveDy = 10; + _caveNx = 8; + _caveNy = 3; _caveMax = _caveNx * _caveNy; - if (_isDemo) { - _maxCaveArr[0] = _caveMax; - _maxCaveArr[1] = -1; - _maxCaveArr[2] = -1; - _maxCaveArr[3] = -1; - _maxCaveArr[4] = -1; - } else { - _maxCaveArr[0] = 1; - _maxCaveArr[1] = 8; - _maxCaveArr[2] = 16; - _maxCaveArr[3] = 23; - _maxCaveArr[4] = 24; - }; + _maxCaveArr[0] = 1; + _maxCaveArr[1] = 8; + _maxCaveArr[2] = 16; + _maxCaveArr[3] = 23; + _maxCaveArr[4] = 24; _heroXY = (Hxy *) malloc (sizeof(Hxy) * _caveMax); for (int i = 0; i < _caveMax; i++) { @@ -100,7 +84,7 @@ void CGEEngine::freeCaveValues() { free(_barriers); } -void CGEEngine::setup() { +void CGEEngine::init() { debugC(1, kCGEDebugEngine, "CGEEngine::setup()"); // Initialise fields @@ -129,7 +113,7 @@ void CGEEngine::setup() { _pocLight = new PocLight(this); for (int i = 0; i < kPocketNX; i++) _pocket[i] = NULL; - _horzLine = isDemo() ? NULL : new HorizLine(this); + _horzLine = new HorizLine(this); _infoLine = new InfoLine(this, kInfoW); _cavLight = new CavLight(this); _debugLine = new InfoLine(this, kScrWidth); @@ -170,9 +154,7 @@ void CGEEngine::setup() { _startGameSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1; } -CGEEngine::~CGEEngine() { - debugC(1, kCGEDebugEngine, "CGEEngine::~CGEEngine()"); - +void CGEEngine::deinit() { // Call classes with static members to clear them up Talk::deinit(); Bitmap::deinit(); @@ -215,17 +197,29 @@ CGEEngine::~CGEEngine() { freeCaveValues(); } +CGEEngine::~CGEEngine() { + debugC(1, kCGEDebugEngine, "CGEEngine::~CGEEngine()"); +} + Common::Error CGEEngine::run() { debugC(1, kCGEDebugEngine, "CGEEngine::run()"); + if (_gameDescription->flags & ADGF_DEMO) { + warning("Demos of Soltys are not supported.\nPlease get a free version on ScummVM download page"); + return Common::kUnsupportedGameidError; + } + // Initialize graphics using following: initGraphics(320, 200, false); // Setup necessary game objects - setup(); + init(); // Run the game cge_main(); + // Remove game objects + deinit(); + return Common::kNoError; } @@ -244,8 +238,4 @@ bool CGEEngine::canSaveGameStateCurrently() { return (_startupMode == 0) && _mouse->_active; } -bool CGEEngine::isDemo() const { - return _gameDescription->flags & ADGF_DEMO; -} - } // End of namespace CGE diff --git a/engines/cge/cge.h b/engines/cge/cge.h index f4260dc31a3..98f9ba8bc2a 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -104,12 +104,10 @@ public: virtual bool hasFeature(EngineFeature f) const; virtual bool canLoadGameStateCurrently(); virtual bool canSaveGameStateCurrently(); - bool isDemo() const; virtual Common::Error loadGameState(int slot); virtual Common::Error saveGameState(int slot, const Common::String &desc); const ADGameDescription *_gameDescription; - bool _isDemo; int _startupMode; int _demoText; int _oldLev; @@ -262,7 +260,8 @@ protected: private: CGEConsole *_console; - void setup(); + void init(); + void deinit(); }; // Example console class diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 8763cb99670..4b834c98006 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -225,6 +225,8 @@ Common::Error CGEEngine::loadGameState(int slot) { // Load the game loadGame(slot, NULL); _snail->addCom(kSnLevel, -1, _oldLev, &_cavLight); + _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, + kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); caveUp(); return Common::kNoError; @@ -670,8 +672,7 @@ void CGEEngine::switchCave(int cav) { if (_hero) { _hero->park(); _hero->step(0); - if (!_isDemo) - _vga->_spareQ->_show = 0; + _vga->_spareQ->_show = 0; } _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); @@ -1196,19 +1197,6 @@ void CGEEngine::loadScript(const char *fname) { } void CGEEngine::mainLoop() { - if (_isDemo) { -// static uint32 tc = 0; - if (/* FIXME: TimerCount - tc >= ((182L * 6L) * 5L) && */ _talk == NULL && _snail->idle()) { - if (_text->getText(_demoText)) { - _snail->addCom(kSnSound, -1, 4, NULL); // drumla - _snail->addCom(kSnInf, -1, _demoText, NULL); - _snail->addCom(kSnLabel, -1, -1, NULL); - if (_text->getText(++_demoText) == NULL) - _demoText = kDemo + 1; - } - //FIXME: tc = TimerCount; - } - } _vga->show(); _snail_->runCom(); _snail->runCom(); @@ -1463,18 +1451,16 @@ bool CGEEngine::showTitle(const char *name) { } if (_mode < 2) { - if (!_isDemo) { - // At this point the game originally set the protection variables - // used by the copy protection check - movie("X00"); // paylist - _vga->copyPage(1, 2); - _vga->copyPage(0, 1); - _vga->_showQ->append(_mouse); - // In the original game, the user had to enter his name - // As it was only used to name savegames, it has been removed - _vga->_showQ->clear(); - _vga->copyPage(0, 2); - } + // At this point the game originally set the protection variables + // used by the copy protection check + movie("X00"); // paylist + _vga->copyPage(1, 2); + _vga->copyPage(0, 1); + _vga->_showQ->append(_mouse); + // In the original game, the user had to enter his name + // As it was only used to name savegames, it has been removed + _vga->_showQ->clear(); + _vga->copyPage(0, 2); if (_mode == 0) { // The auto-load of savegame #0 is currently disabled @@ -1531,7 +1517,7 @@ void CGEEngine::cge_main() { movie(kLgoExt); if (showTitle("WELCOME")) { - if ((!_isDemo) && (_mode == 1)) + if (_mode == 1) movie("X02"); // intro runGame(); _startupMode = 2; diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index 5e741662225..c64295db0ee 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -57,24 +57,6 @@ static const ADGameDescription gameDescriptions[] = { }, Common::PL_POL, Common::kPlatformPC, ADGF_NO_FLAGS, GUIO_NONE }, - { - "soltys", "Soltys Demo", - { - {"vol.cat", 0, "1e077c8ff58109a187f07ac54b0c873a", 18788}, - {"vol.dat", 0, "75d385a6074c58b69f7730481f256051", 1796710}, - AD_LISTEND - }, - Common::PL_POL, Common::kPlatformPC, ADGF_DEMO, GUIO_NONE - }, - { - "soltys", "Soltys Demo", - { - {"vol.cat", 0, "f17987487fab1ebddd781d8d02fedecc", 7168}, - {"vol.dat", 0, "c5d9b15863cab61dc125551576dece04", 1075272}, - AD_LISTEND - }, - Common::PL_POL, Common::kPlatformPC, ADGF_DEMO, GUIO_NONE - }, // English ScummVM version { "soltys", "", @@ -85,7 +67,24 @@ static const ADGameDescription gameDescriptions[] = { }, Common::EN_ANY, Common::kPlatformPC, ADGF_NO_FLAGS, GUIO_NONE }, - + { + "soltys", "Soltys Demo (not supported)", + { + {"vol.cat", 0, "1e077c8ff58109a187f07ac54b0c873a", 18788}, + {"vol.dat", 0, "75d385a6074c58b69f7730481f256051", 1796710}, + AD_LISTEND + }, + Common::PL_POL, Common::kPlatformPC, ADGF_DEMO , GUIO_NONE + }, + { + "soltys", "Soltys Demo (not supported)", + { + {"vol.cat", 0, "f17987487fab1ebddd781d8d02fedecc", 7168}, + {"vol.dat", 0, "c5d9b15863cab61dc125551576dece04", 1075272}, + AD_LISTEND + }, + Common::PL_POL, Common::kPlatformPC, ADGF_DEMO , GUIO_NONE + }, AD_TABLE_END_MARKER }; From 951dfa2be973e5234df3fbca4d14e10f0dcd3c9c Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 29 Aug 2011 23:10:33 +0200 Subject: [PATCH 253/276] CGE: Fix the language of one of the demos --- engines/cge/detection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engines/cge/detection.cpp b/engines/cge/detection.cpp index c64295db0ee..abb0cf5efbe 100644 --- a/engines/cge/detection.cpp +++ b/engines/cge/detection.cpp @@ -74,7 +74,7 @@ static const ADGameDescription gameDescriptions[] = { {"vol.dat", 0, "75d385a6074c58b69f7730481f256051", 1796710}, AD_LISTEND }, - Common::PL_POL, Common::kPlatformPC, ADGF_DEMO , GUIO_NONE + Common::EN_ANY, Common::kPlatformPC, ADGF_DEMO , GUIO_NONE }, { "soltys", "Soltys Demo (not supported)", From 31d41731369697ca38900b3a6a89d9a6e1ac8a8c Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 1 Sep 2011 00:22:20 +0200 Subject: [PATCH 254/276] CGE: Fix thumbnails display when a game is loaded. --- engines/cge/cge.h | 2 +- engines/cge/cge_main.cpp | 4 ++-- engines/cge/snail.cpp | 23 ++++++++++++++++------- engines/cge/vga13h.cpp | 7 +------ 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 98f9ba8bc2a..2ad66fc74ae 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -41,7 +41,7 @@ namespace CGE { class Console; class Sprite; -#define kSavegameVersion 1 +#define kSavegameVersion 2 #define kSavegameStrSize 11 #define kPocketX 174 #define kPocketY 176 diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 4b834c98006..aa332ed8ea0 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -266,7 +266,7 @@ void CGEEngine::saveGame(int slotNumber, const Common::String &desc) { writeSavegameHeader(saveFile, header); // Write out the data of the savegame - syncGame(NULL, saveFile); + syncGame(NULL, saveFile, false); // Finish writing out game data saveFile->finalize(); @@ -324,7 +324,7 @@ void CGEEngine::syncGame(Common::SeekableReadStream *readStream, Common::WriteSt if (s.isSaving()) { // Loop through saving the sprite data for (Sprite *spr = _vga->_spareQ->first(); spr; spr = spr->_next) { - if ((spr->_ref >= 1000) && !s.err()) + if (!s.err()) spr->sync(s); } } else { diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 7893b9d539d..0e9d834d176 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -826,17 +826,26 @@ void CGEEngine::snBackPt(Sprite *spr, int stp) { void CGEEngine::snLevel(Sprite *spr, int lev) { debugC(1, kCGEDebugEngine, "CGEEngine::snLevel(spr, %d)", lev); - while (_lev < lev) { - _lev++; - spr = _vga->_spareQ->locate(100 + _lev); + assert((lev >= 0) && (lev < 5)); + + for (int i = 0; i < 5; i++) { + spr = _vga->_spareQ->locate(100 + i); if (spr) { - spr->backShow(true); - spr->_cave = 0; + if (i <= lev) { + spr->backShow(true); + spr->_cave = 0; + spr->_flags._hide = false; + } else { + spr->_flags._hide = true; + spr->_cave = -1; + } + } else { + warning("SPR not found! ref: %d", 100 + i); } } + + _lev = lev; _maxCave = _maxCaveArr[_lev]; - if (spr) - spr->_flags._hide = false; } void CGEEngine::snFlag(int indx, bool v) { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d510b98f452..3db504425fa 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -99,13 +99,8 @@ BitmapPtr Sprite::shp() { return NULL; int i = e->_seq[_seqPtr]._now; - if (i >= _shpCnt) { - //char s[256]; - //sprintf(s, "Seq=%p ShpCnt=%d SeqPtr=%d Now=%d Next=%d", - // Seq, ShpCnt, SeqPtr, Seq[SeqPtr].Now, Seq[SeqPtr].Next); - //VGA::Exit(s, File); + if (i >= _shpCnt) error("Invalid PHASE in SPRITE::Shp() %s", _file); - } return e->_shpList[i]; } From 690d94eb0376252818b5c27e86e0c70a6d01435d Mon Sep 17 00:00:00 2001 From: Strangerke Date: Thu, 1 Sep 2011 00:32:20 +0200 Subject: [PATCH 255/276] CGE: Take fingolfin's remark into account: suppress the two leading underscore in define names --- engines/cge/bitmap.h | 4 ++-- engines/cge/cge_main.h | 4 ++-- engines/cge/events.h | 4 ++-- engines/cge/fileio.h | 4 ++-- engines/cge/game.h | 4 ++-- engines/cge/general.h | 4 ++-- engines/cge/snail.h | 4 ++-- engines/cge/snddrv.h | 13 ++----------- engines/cge/sound.h | 4 ++-- engines/cge/talk.h | 4 ++-- engines/cge/text.h | 4 ++-- engines/cge/vga13h.h | 4 ++-- engines/cge/vmenu.h | 4 ++-- engines/cge/walk.h | 4 ++-- 14 files changed, 28 insertions(+), 37 deletions(-) diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index 8896d13bb43..cd4f8267d11 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_BITMAP__ -#define __CGE_BITMAP__ +#ifndef CGE_BITMAP_H +#define CGE_BITMAP_H #include "cge/fileio.h" //#include "cge/general.h" diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index cce31222358..5e2e3bbe462 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_CGE__ -#define __CGE_CGE__ +#ifndef CGE_CGEMAIN_H +#define CGE_CGEMAIN_H #include "cge/vga13h.h" #include "cge/events.h" diff --git a/engines/cge/events.h b/engines/cge/events.h index 9b7de9efd45..62841dabe41 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_CGE_EVENTS__ -#define __CGE_CGE_EVENTS__ +#ifndef CGE_EVENTS_H +#define CGE_EVENTS_H #include "common/events.h" #include "cge/game.h" diff --git a/engines/cge/fileio.h b/engines/cge/fileio.h index 7cb5ce07e0b..4ac8e132924 100644 --- a/engines/cge/fileio.h +++ b/engines/cge/fileio.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_FILEIO__ -#define __CGE_FILEIO__ +#ifndef CGE_FILEIO_H +#define CGE_FILEIO_H #include "cge/general.h" #include "common/stream.h" diff --git a/engines/cge/game.h b/engines/cge/game.h index bb4f3655a21..63d686239e5 100644 --- a/engines/cge/game.h +++ b/engines/cge/game.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_GAME__ -#define __CGE_GAME__ +#ifndef CGE_GAME_H +#define CGE_GAME_H #include "cge/vga13h.h" diff --git a/engines/cge/general.h b/engines/cge/general.h index 6a0bc136755..ad5abba6b10 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_GENERAL__ -#define __CGE_GENERAL__ +#ifndef CGE_GENERAL_H +#define CGE_GENERAL_H #include "common/system.h" #include "common/file.h" diff --git a/engines/cge/snail.h b/engines/cge/snail.h index c2290da9110..c6157a00969 100644 --- a/engines/cge/snail.h +++ b/engines/cge/snail.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_SNAIL__ -#define __CGE_SNAIL__ +#ifndef CGE_SNAIL_H +#define CGE_SNAIL_H #include "cge/cge.h" diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 9e937d1cbf2..987582190c9 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -25,17 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -// ****************************************************** -// * Sound Driver by Hedges (c) 1995 LK AVALON * -// * Ver 1.00: 01-Mar-95 * -// * Ver 1.10: 03-Mar-95 * -// * Ver 1.20: 07-Mar-95 * -// * Ver 1.30: 09-Mar-95 * -// * Ver 1.40: 11-Mar-95 * -// ****************************************************** - -#ifndef __CGE_SNDDRV__ -#define __CGE_SNDDRV__ +#ifndef CGE_SNDDRV_H +#define CGE_SNDDRV_H namespace CGE { diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 53f57a19b09..1474b78c28e 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_SOUND__ -#define __CGE_SOUND__ +#ifndef CGE_SOUND_H +#define CGE_SOUND_H #include "cge/fileio.h" #include "cge/snddrv.h" diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 3591fc6fccc..6b06e8009c2 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_TALK__ -#define __CGE_TALK__ +#ifndef CGE_TALK_H +#define CGE_TALK_H #include "cge/general.h" #include "cge/vga13h.h" diff --git a/engines/cge/text.h b/engines/cge/text.h index d4607f8f3c9..7ea0a947dbe 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_TEXT__ -#define __CGE_TEXT__ +#ifndef CGE_TEXT_H +#define CGE_TEXT_H #include "cge/talk.h" diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index e917e86a323..33120654923 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_VGA13H__ -#define __CGE_VGA13H__ +#ifndef CGE_VGA13H_H +#define CGE_VGA13H_H #include "common/serializer.h" #include "graphics/surface.h" diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index 0ddcfdb91d9..30fcb53f4be 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_VMENU__ -#define __CGE_VMENU__ +#ifndef CGE_VMENU_H +#define CGE_VMENU_H #include "cge/talk.h" diff --git a/engines/cge/walk.h b/engines/cge/walk.h index e9249769273..a0dce1f7153 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -25,8 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ -#ifndef __CGE_WALK__ -#define __CGE_WALK__ +#ifndef CGE_WALK_H +#define CGE_WALK_H #include "cge/vga13h.h" #include "cge/events.h" From 56e57cf3807642ceff2460c255322325c779fb2e Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 4 Sep 2011 11:23:01 +0200 Subject: [PATCH 256/276] CGE: Remove two useless callback types --- engines/cge/cge.h | 3 +-- engines/cge/cge_main.cpp | 26 +++++--------------------- engines/cge/snail.cpp | 6 ------ 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 2ad66fc74ae..edb396f4cfd 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -64,8 +64,7 @@ enum SnList { }; enum CallbackType { - kNullCB = 0, kQGame, kMiniStep, kXCave, kSelectSound, - kSnSelect, kSndSetVolume + kNullCB = 0, kQGame, kMiniStep, kXCave, kSndSetVolume }; struct SavegameHeader { diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index aa332ed8ea0..5ccf681f965 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -716,18 +716,9 @@ void System::touch(uint16 mask, int x, int y) { return; } switch (x) { - case 'F': - if (_keyboard->_key[kKeyAlt]) { - Sprite *m = _vga->_showQ->locate(17001); - if (m) { - m->step(1); - m->_time = 216; // 3s - } - } - break; case 'X': if (_keyboard->_key[kKeyAlt]) - _finis = true; + _vm->quit(); break; case '0': case '1': @@ -738,6 +729,7 @@ void System::touch(uint16 mask, int x, int y) { _snail->addCom(kSnLevel, -1, x - '0', NULL); break; } + break; } } else { if (_vm->_startupMode) @@ -821,17 +813,9 @@ void CGEEngine::switchColorMode() { void CGEEngine::switchMusic() { debugC(1, kCGEDebugEngine, "CGEEngine::switchMusic()"); - if (_keyboard->_key[kKeyAlt]) { - if (Vmenu::_addr) { - _snail_->addCom(kSnKill, -1, 0, Vmenu::_addr); - } else { - _snail_->addCom(kSnSeq, 122, (_music = false), NULL); - _snail->addCom2(kSnExec, -1, 0, kSelectSound); - } - } else { - _snail_->addCom(kSnSeq, 122, (_music = !_music), NULL); - keyClick(); - } + _snail_->addCom(kSnSeq, 122, (_music = !_music), NULL); + keyClick(); + if (_music) _midiPlayer.loadMidi(_now); else diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 0e9d834d176..bffbe7c628e 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -1139,12 +1139,6 @@ void Snail::runCom() { case kXCave: _vm->xCave(); break; - case kSelectSound: - warning("TODO: Select sound card"); - break; - case kSnSelect: - warning("TODO: Sound card selection"); - break; case kSndSetVolume: sndSetVolume(); break; From 76f410958a6682406264032c401b80f322749950 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 4 Sep 2011 14:28:12 +0200 Subject: [PATCH 257/276] CGE: Use F5/F7 to display the save/load dialog box --- engines/cge/cge.cpp | 2 +- engines/cge/events.cpp | 33 ++++++++++++++++++++++++++++++++- engines/cge/events.h | 3 ++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 514580bbe35..b56635125db 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -121,7 +121,7 @@ void CGEEngine::init() { _snail_ = new Snail(this, true); _mouse = new Mouse(this); - _keyboard = new Keyboard(); + _keyboard = new Keyboard(this); _eventManager = new EventManager(); _fx = new Fx(16); // must precede SOUND!! _sound = new Sound(this); diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 5af5a9ee3fd..9cbf889dfe5 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -25,6 +25,10 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ +#include "gui/saveload.h" +#include "gui/about.h" +#include "gui/message.h" +#include "common/config-manager.h" #include "common/events.h" #include "cge/events.h" #include "cge/events.h" @@ -81,7 +85,7 @@ const uint16 Keyboard::_scummVmCodes[0x60] = { 0 }; -Keyboard::Keyboard() : _client(NULL) { +Keyboard::Keyboard(CGEEngine *vm) : _client(NULL), _vm(vm) { Common::set_to(&_key[0], &_key[0x60], false); _current = 0; } @@ -108,6 +112,33 @@ bool Keyboard::getKey(Common::Event &event, int &cgeCode) { cgeCode = 28; return true; } + if (keycode == Common::KEYCODE_F5) { + warning("keycode %d", event.kbd.ascii); + if (_vm->canSaveGameStateCurrently()) { + const EnginePlugin *plugin = NULL; + EngineMan.findGame(_vm->_gameDescription->gameid, &plugin); + + GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Save game:", "Save"); + dialog->setSaveMode(true); + int16 savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + Common::String savegameDescription = dialog->getResultString(); + delete dialog; + _vm->saveGameState(savegameId, savegameDescription); + } + return false; + } else if (keycode == Common::KEYCODE_F7) { + if (_vm->canLoadGameStateCurrently()) { + const EnginePlugin *plugin = NULL; + EngineMan.findGame(_vm->_gameDescription->gameid, &plugin); + + GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser("Restore game:", "Restore"); + dialog->setSaveMode(false); + int16 savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName()); + delete dialog; + _vm->loadGameState(savegameId); + } + return false; + } // Scan through the ScummVM mapping list for (int idx = 0; idx < 0x60; idx++) { diff --git a/engines/cge/events.h b/engines/cge/events.h index 62841dabe41..f170455fa71 100644 --- a/engines/cge/events.h +++ b/engines/cge/events.h @@ -84,6 +84,7 @@ class Keyboard { private: bool getKey(Common::Event &event, int &cgeCode); uint16 _current; + CGEEngine *_vm; public: static const uint16 _code[0x60]; static const uint16 _scummVmCodes[0x60]; @@ -95,7 +96,7 @@ public: uint16 lastKey(); Sprite *setClient(Sprite *spr); - Keyboard(); + Keyboard(CGEEngine *vm); ~Keyboard(); }; From 27328f254639a0db8a4d8c26afcfc8b605adf353 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 5 Sep 2011 21:21:42 +0200 Subject: [PATCH 258/276] CGE: Little cleanup of vmenu --- engines/cge/vmenu.cpp | 45 ++++++++++++++++++++----------------------- engines/cge/vmenu.h | 7 +++++-- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index c8a21160bfe..1497d5823ce 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -59,29 +59,6 @@ MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { _flags._bDel = true; } -static char *g_vmgt; - -char *VMGather(Choice *list) { - Choice *cp; - int len = 0, h = 0; - - for (cp = list; cp->_text; cp++) { - len += strlen(cp->_text); - h++; - } - g_vmgt = new char[len + h]; - if (g_vmgt) { - *g_vmgt = '\0'; - for (cp = list; cp->_text; cp++) { - if (*g_vmgt) - strcat(g_vmgt, "|"); - strcat(g_vmgt, cp->_text); - h++; - } - } - return g_vmgt; -} - Vmenu *Vmenu::_addr = NULL; int Vmenu::_recent = -1; @@ -90,7 +67,7 @@ Vmenu::Vmenu(CGEEngine *vm, Choice *list, int x, int y) Choice *cp; _addr = this; - delete[] g_vmgt; + delete[] _vmgt; _items = 0; for (cp = list; cp->_text; cp++) _items++; @@ -142,4 +119,24 @@ void Vmenu::touch(uint16 mask, int x, int y) { } } +char *Vmenu::VMGather(Choice *list) { + Choice *cp; + int len = 0, h = 0; + + for (cp = list; cp->_text; cp++) { + len += strlen(cp->_text); + h++; + } + _vmgt = new char[len + h]; + if (_vmgt) { + *_vmgt = '\0'; + for (cp = list; cp->_text; cp++) { + if (*_vmgt) + strcat(_vmgt, "|"); + strcat(_vmgt, cp->_text); + h++; + } + } + return _vmgt; +} } // End of namespace CGE diff --git a/engines/cge/vmenu.h b/engines/cge/vmenu.h index 30fcb53f4be..b8740a9e93c 100644 --- a/engines/cge/vmenu.h +++ b/engines/cge/vmenu.h @@ -53,8 +53,6 @@ private: class Vmenu : public Talk { - uint16 _items; - Choice *_menu; public: static Vmenu *_addr; static int _recent; @@ -63,7 +61,12 @@ public: ~Vmenu(); virtual void touch(uint16 mask, int x, int y); private: + char *_vmgt; CGEEngine *_vm; + uint16 _items; + Choice *_menu; + + char *VMGather(Choice *list); }; } // End of namespace CGE From b75a308bccae32a4fbd28be7ce61410cff050271 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 5 Sep 2011 23:50:30 +0200 Subject: [PATCH 259/276] CGE: Replace Couple by Common::Point (thanks Fingolfin for pointing that out) --- engines/cge/cge_main.cpp | 5 ++-- engines/cge/walk.cpp | 38 +++++++++++++----------------- engines/cge/walk.h | 51 ++++++---------------------------------- 3 files changed, 26 insertions(+), 68 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 5ccf681f965..9b1afed2453 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -763,8 +763,9 @@ void System::touch(uint16 mask, int x, int y) { if (_horzLine && !_horzLine->_flags._hide) { if (y >= kMapTop && y < kMapTop + kMapHig) { - int8 x1, z1; - XZ(x, y).split(x1, z1); + Cluster tmpCluster = XZ(x, y); + int16 x1 = tmpCluster._pt.x; + int16 z1 = tmpCluster._pt.y; Cluster::_map[z1][x1] = 1; _vm->setMapBrick(x1, z1); } diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index 252e068d809..bcd15768f1a 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -40,14 +40,14 @@ void Cluster::init(CGEEngine *vm) { } uint8 &Cluster::cell() { - return _map[_b][_a]; + return _map[_pt.y][_pt.x]; } bool Cluster::isValid() const { - return (_a >= 0) && (_a < kMapXCnt) && (_b >= 0) && (_b < kMapZCnt); + return (_pt.x >= 0) && (_pt.x < kMapXCnt) && (_pt.y >= 0) && (_pt.y < kMapZCnt); } -Cluster XZ(int x, int y) { +Cluster XZ(int16 x, int16 y) { if (y < kMapTop) y = kMapTop; @@ -57,12 +57,6 @@ Cluster XZ(int x, int y) { return Cluster(x / kMapGridX, (y - kMapTop) / kMapGridZ); } -Cluster XZ(Couple xy) { - signed char x, y; - xy.split(x, y); - return XZ(x, y); -} - Walk::Walk(CGEEngine *vm, BitmapPtr *shpl) : Sprite(vm, shpl), _dir(kDirNone), _tracePtr(-1), _level(0), _target(-1, -1), _findLevel(-1), _vm(vm) { } @@ -90,12 +84,13 @@ void Walk::tick() { if (_flags._hold || _tracePtr < 0) { park(); } else { - if (_here == _trace[_tracePtr]) { + if (_here._pt == _trace[_tracePtr]._pt) { if (--_tracePtr < 0) park(); } else { - signed char dx, dz; - (_trace[_tracePtr] - _here).split(dx, dz); + Common::Point tmpPoint = _trace[_tracePtr]._pt - _here._pt; + int16 dx = tmpPoint.x; + int16 dz = tmpPoint.y; Dir d = (dx) ? ((dx > 0) ? kDirEast : kDirWest) : ((dz > 0) ? kDirSouth : kDirNorth); turn(d); } @@ -108,8 +103,8 @@ void Walk::tick() { (_dir == kDirSouth && _y + _w >= kWorldHeight - 2)) { park(); } else { - signed char x; // dummy var - _here.split(x, _z); // take current Z position + // take current Z position + _z = _here._pt.y; _snail_->addCom(kSnZTrim, -1, 0, this); // update Hero's pos in show queue } } @@ -154,14 +149,13 @@ void Walk::park() { } void Walk::findWay(Cluster c) { - if (c == _here) + if (c._pt == _here._pt) return; for (_findLevel = 1; _findLevel <= kMaxFindLevel; _findLevel++) { - signed char x, z; - _here.split(x, z); - _target = Couple(x, z); - c.split(x, z); + _target = _here._pt; + int16 x = c._pt.x; + int16 z = c._pt.y; if (find1Way(Cluster(x, z))) break; @@ -219,14 +213,14 @@ void Walk::noWay() { bool Cluster::chkBar() const { assert(_vm->_now <= _vm->_caveMax); - return (_a == _vm->_barriers[_vm->_now]._horz) || (_b == _vm->_barriers[_vm->_now]._vert); + return (_pt.x == _vm->_barriers[_vm->_now]._horz) || (_pt.y == _vm->_barriers[_vm->_now]._vert); } bool Walk::find1Way(Cluster c) { const Cluster tab[4] = { Cluster(-1, 0), Cluster(1, 0), Cluster(0, -1), Cluster(0, 1)}; const int tabLen = 4; - if (c == _target) + if (c._pt == _target) // Found destination return true; @@ -249,7 +243,7 @@ bool Walk::find1Way(Cluster c) { c = start; do { - c += tab[i]; + c._pt += tab[i]._pt; if (!c.isValid()) // Break to check next direction break; diff --git a/engines/cge/walk.h b/engines/cge/walk.h index a0dce1f7153..9b94120bb4e 100644 --- a/engines/cge/walk.h +++ b/engines/cge/walk.h @@ -28,6 +28,7 @@ #ifndef CGE_WALK_H #define CGE_WALK_H +#include "common/rect.h" #include "cge/vga13h.h" #include "cge/events.h" @@ -44,54 +45,17 @@ namespace CGE { enum Dir { kDirNone = -1, kDirNorth, kDirEast, kDirSouth, kDirWest }; -class Couple { -protected: - signed char _a; - signed char _b; -public: - Couple(const signed char a, const signed char b) : _a(a), _b(b) { } - Couple operator + (Couple c) { - return Couple(_a + c._a, _b + c._b); - } - - void operator += (Couple c) { - _a += c._a; - _b += c._b; - } - - Couple operator - (Couple c) { - return Couple(_a - c._a, _b - c._b); - } - - void operator -= (Couple c) { - _a -= c._a; - _b -= c._b; - } - - bool operator == (const Couple &c) { - return ((_a - c._a) | (_b - c._b)) == 0; - } - - bool operator != (Couple c) { - return !(operator == (c)); - } - - void split(signed char &a, signed char &b) { - a = _a; - b = _b; - } -}; - -class Cluster : public Couple { +class Cluster { public: static uint8 _map[kMapZCnt][kMapXCnt]; static CGEEngine *_vm; + Common::Point _pt; static void init(CGEEngine *vm); public: uint8 &cell(); - Cluster(int a, int b) : Couple(a, b) { } - Cluster() : Couple (-1, -1) { } + Cluster(int16 a, int16 b) { _pt = Common::Point(a, b); } + Cluster() { _pt = Common::Point(-1, -1); } bool chkBar() const; bool isValid() const; }; @@ -104,7 +68,7 @@ public: int _tracePtr; int _level; int _findLevel; - Couple _target; + Common::Point _target; Cluster _trace[kMaxFindLevel]; Dir _dir; @@ -122,8 +86,7 @@ public: bool find1Way(Cluster c); }; -Cluster XZ(int x, int y); -Cluster XZ(Couple xy); +Cluster XZ(int16 x, int16 y); extern Walk *_hero; From d7695542cdd486dbb29e3cc7d0bc8c317760d185 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 6 Sep 2011 00:16:07 +0200 Subject: [PATCH 260/276] CGE: Remove various defines and functions from "general" Those were already present in ScummVM (thanks Fingolfin for point out) --- engines/cge/cge_main.cpp | 4 ++-- engines/cge/events.cpp | 2 +- engines/cge/general.cpp | 35 ----------------------------------- engines/cge/general.h | 23 ----------------------- engines/cge/snail.cpp | 8 ++++---- engines/cge/text.cpp | 4 ++-- 6 files changed, 9 insertions(+), 67 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 9b1afed2453..5970a3e339e 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -691,8 +691,8 @@ System::System(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { } void System::setPal() { - Dac *p = _vga->_sysPal + 256 - ArrayCount(_stdPal); - for (uint i = 0; i < ArrayCount(_stdPal); i++) { + Dac *p = _vga->_sysPal + 256 - ARRAYSIZE(_stdPal); + for (uint i = 0; i < ARRAYSIZE(_stdPal); i++) { p[i]._r = _stdPal[i]._r >> 2; p[i]._g = _stdPal[i]._g >> 2; p[i]._b = _stdPal[i]._b >> 2; diff --git a/engines/cge/events.cpp b/engines/cge/events.cpp index 9cbf889dfe5..072771ebacb 100644 --- a/engines/cge/events.cpp +++ b/engines/cge/events.cpp @@ -94,7 +94,7 @@ Keyboard::~Keyboard() { } Sprite *Keyboard::setClient(Sprite *spr) { - swap(_client, spr); + SWAP(_client, spr); return spr; } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index c20da2466c5..8fbf5455355 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -124,30 +124,6 @@ char *forceExt(char *buf, const char *name, const char *ext) { return buf; } -uint16 atow(const char *a) { - if (!a) - return 0; - - uint16 w = 0; - while (IsDigit(*a)) - w = (10 * w) + (*(a++) & 0xF); - return w; -} - -uint16 xtow(const char *x) { - if (!x) - return 0; - - uint16 w = 0; - while (IsHxDig(*x)) { - register uint16 d = *(x++); - if (d > '9') - d -= 'A' - ('9' + 1); - w = (w << 4) | (d & 0xF); - } - return w; -} - char *wtom(uint16 val, char *str, int radix, int len) { while (--len >= 0) { uint16 w = val % radix; @@ -159,17 +135,6 @@ char *wtom(uint16 val, char *str, int radix, int len) { return str; } -char *dwtom(uint32 val, char *str, int radix, int len) { - while (--len >= 0) { - uint16 w = (uint16) (val % radix); - if (w > 9) - w += ('A' - ('9' + 1)); - str[len] = '0' + w; - val /= radix; - } - return str; -} - void sndSetVolume() { // USeless for ScummVM } diff --git a/engines/cge/general.h b/engines/cge/general.h index ad5abba6b10..33abd1e852b 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -38,9 +38,6 @@ namespace CGE { #define kCryptSeed 0xA5 #define kMaxFile 128 -#define IsDigit(c) ((c) >= '0' && (c) <= '9') -#define IsHxDig(c) (IsDigit(c) || ((c) >= 'A' && (c) <= 'F') || ((c) >= 'a' && (c) <= 'f')) -#define ArrayCount(a) (sizeof(a) / sizeof((a)[0])) struct Dac { uint8 _r; @@ -50,27 +47,7 @@ struct Dac { typedef uint16 Crypt(void *buf, uint16 siz, uint16 seed); -template -void swap(T &A, T &B) { - T a = A; - A = B; - B = a; -} - -template -T max(T A, T B) { - return (A > B) ? A : B; -} - -template -T min(T A, T B) { - return (A < B) ? A : B; -} - -uint16 atow(const char *a); -uint16 xtow(const char *x); char *wtom(uint16 val, char *str, int radix, int len); -char *dwtom(uint32 val, char *str, int radix, int len); int takeEnum(const char **tab, const char *text); uint16 chkSum(void *m, uint16 n); char *mergeExt(char *buf, const char *name, const char *ext); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index bffbe7c628e..2d15b61d973 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -587,10 +587,10 @@ void CGEEngine::snSwap(Sprite *spr, int xref) { bool was1 = (was == 0 || was == _now); bool xwas1 = (xwas == 0 || xwas == _now); - swap(spr->_cave, xspr->_cave); - swap(spr->_x, xspr->_x); - swap(spr->_y, xspr->_y); - swap(spr->_z, xspr->_z); + SWAP(spr->_cave, xspr->_cave); + SWAP(spr->_x, xspr->_x); + SWAP(spr->_y, xspr->_y); + SWAP(spr->_z, xspr->_z); if (spr->_flags._kept) { int n = findPocket(spr); if (n >= 0) diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 973aadd23af..6076fdd8ff7 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -92,7 +92,7 @@ void Text::preload(int from, int upto) { char *s; if ((s = strtok(line, " =,;/\t\n")) == NULL) continue; - if (!IsDigit(*s)) + if (!isdigit(*s)) continue; int ref = atoi(s); @@ -136,7 +136,7 @@ char *Text::load(int idx, int ref) { line[-- n] = '\0'; if ((s = strtok(line, " =,;/\t\n")) == NULL) continue; - if (!IsDigit(*s)) + if (!isdigit(*s)) continue; int r = atoi(s); From 5bad1a7c7fc14caaa8af7d51addc70c94804e435 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 6 Sep 2011 00:43:40 +0200 Subject: [PATCH 261/276] CGE: Take into account some of LordHoto's comments --- engines/cge/bitmap.cpp | 2 +- engines/cge/cge.cpp | 6 ++-- engines/cge/cge.h | 2 ++ engines/cge/cge_main.cpp | 74 +++++++++++++++++++++++++++++++++++----- engines/cge/cge_main.h | 1 - engines/cge/fileio.cpp | 4 +-- engines/cge/general.cpp | 64 +--------------------------------- engines/cge/snail.cpp | 4 +-- engines/cge/sound.cpp | 6 ++-- engines/cge/vga13h.cpp | 4 +-- engines/cge/vmenu.cpp | 2 +- 11 files changed, 82 insertions(+), 87 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 87bf49047fe..42c1cc908d5 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -145,7 +145,7 @@ Bitmap &Bitmap::operator = (const Bitmap &bmp) { } else { uint16 vsiz = (uint8 *)bmp._b - (uint8 *)v0; uint16 siz = vsiz + _h * sizeof(HideDesc); - uint8 *v1 = (uint8 *) malloc(sizeof(uint8) * siz); + uint8 *v1 = (uint8 *)malloc(sizeof(uint8) * siz); assert(v1 != NULL); memcpy(v1, v0, siz); _b = (HideDesc *)((_v = v1) + vsiz); diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index b56635125db..dafb8a3782c 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -66,13 +66,13 @@ void CGEEngine::initCaveValues() { _maxCaveArr[3] = 23; _maxCaveArr[4] = 24; - _heroXY = (Hxy *) malloc (sizeof(Hxy) * _caveMax); + _heroXY = (Hxy *)malloc(sizeof(Hxy) * _caveMax); for (int i = 0; i < _caveMax; i++) { _heroXY[i]._x = 0; _heroXY[i]._y = 0; } - _barriers = (Bar *) malloc (sizeof(Bar) * (1 + _caveMax)); + _barriers = (Bar *)malloc(sizeof(Bar) * (1 + _caveMax)); for (int i = 0; i < _caveMax + 1; i++) { _barriers[i]._horz = 0xFF; _barriers[i]._vert = 0xFF; @@ -139,6 +139,7 @@ void CGEEngine::init() { _maxCave = 0; _dark = false; _game = false; + _finis = false; _now = 1; _lev = -1; _recentStep = -2; @@ -150,6 +151,7 @@ void CGEEngine::init() { _soundOk = 1; _sprTv = NULL; _gameCase2Cpt = 0; + _offUseCount = 0; _startGameSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1; } diff --git a/engines/cge/cge.h b/engines/cge/cge.h index edb396f4cfd..1d38b6a59b5 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -119,11 +119,13 @@ public: bool _flag[4]; bool _dark; bool _game; + bool _finis; int _now; int _lev; int _mode; int _soundOk; int _gameCase2Cpt; + int _offUseCount; Sprite *_sprTv; Sprite *_sprK1; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index 5970a3e339e..a6fd08d396d 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -84,10 +84,66 @@ const char *savegameStr = "SCUMMVM_CGE"; //-------------------------------------------------------------------------- -static bool _finis = false; -int _offUseCount; - -extern Dac _stdPal[58]; +const Dac g_stdPal[] = {// R G B + { 0, 60, 0}, // 198 + { 0, 104, 0}, // 199 + { 20, 172, 0}, // 200 + { 82, 82, 0}, // 201 + { 0, 132, 82}, // 202 + { 132, 173, 82}, // 203 + { 82, 0, 0}, // 204 + { 206, 0, 24}, // 205 + { 255, 33, 33}, // 206 + { 123, 41, 0}, // 207 + { 0, 41, 0}, // 208 + { 0, 0, 82}, // 209 + { 132, 0, 0}, // 210 + { 255, 0, 0}, // 211 + { 255, 66, 66}, // 212 + { 148, 66, 16}, // 213 + { 0, 82, 0}, // 214 + { 0, 0, 132}, // 215 + { 173, 0, 0}, // 216 + { 255, 49, 0}, // 217 + { 255, 99, 99}, // 218 + { 181, 107, 49}, // 219 + { 0, 132, 0}, // 220 + { 0, 0, 255}, // 221 + { 173, 41, 0}, // 222 + { 255, 82, 0}, // 223 + { 255, 132, 132}, // 224 + { 214, 148, 74}, // 225 + { 41, 214, 0}, // 226 + { 0, 82, 173}, // 227 + { 255, 214, 0}, // 228 + { 247, 132, 49}, // 229 + { 255, 165, 165}, // 230 + { 239, 198, 123}, // 231 + { 173, 214, 0}, // 232 + { 0, 132, 214}, // 233 + { 57, 57, 57}, // 234 + { 247, 189, 74}, // 235 + { 255, 198, 198}, // 236 + { 255, 239, 173}, // 237 + { 214, 255, 173}, // 238 + { 82, 173, 255}, // 239 + { 107, 107, 107}, // 240 + { 247, 222, 99}, // 241 + { 255, 0, 255}, // 242 + { 255, 132, 255}, // 243 + { 132, 132, 173}, // 244 + { 148, 247, 255}, // 245 + { 148, 148, 148}, // 246 + { 82, 0, 82}, // 247 + { 112, 68, 112}, // 248 + { 176, 88, 144}, // 249 + { 214, 132, 173}, // 250 + { 206, 247, 255}, // 251 + { 198, 198, 198}, // 252 + { 0, 214, 255}, // 253 + { 96, 224, 96 }, // 254 + { 255, 255, 255}, // 255 +}; void CGEEngine::syncHeader(Common::Serializer &s) { debugC(1, kCGEDebugEngine, "CGEEngine::syncHeader(s)"); @@ -691,11 +747,11 @@ System::System(CGEEngine *vm) : Sprite(vm, NULL), _vm(vm) { } void System::setPal() { - Dac *p = _vga->_sysPal + 256 - ARRAYSIZE(_stdPal); - for (uint i = 0; i < ARRAYSIZE(_stdPal); i++) { - p[i]._r = _stdPal[i]._r >> 2; - p[i]._g = _stdPal[i]._g >> 2; - p[i]._b = _stdPal[i]._b >> 2; + Dac *p = _vga->_sysPal + 256 - ARRAYSIZE(g_stdPal); + for (uint i = 0; i < ARRAYSIZE(g_stdPal); i++) { + p[i]._r = g_stdPal[i]._r >> 2; + p[i]._g = g_stdPal[i]._g >> 2; + p[i]._b = g_stdPal[i]._b >> 2; } } diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index 5e2e3bbe462..d91fabc875d 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -115,7 +115,6 @@ private: extern Vga *_vga; extern System *_sys; -extern int _offUseCount; extern Sprite *_pocLight; extern Keyboard *_keyboard; extern Mouse *_mouse; diff --git a/engines/cge/fileio.cpp b/engines/cge/fileio.cpp index b2761f33be4..e196a66d26c 100644 --- a/engines/cge/fileio.cpp +++ b/engines/cge/fileio.cpp @@ -105,7 +105,7 @@ IoBuf::IoBuf(Crypt *crypt) _lim(0) { debugC(1, kCGEDebugFile, "IoBuf::IoBuf(crypt)"); - _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); + _buff = (uint8 *)malloc(sizeof(uint8) * kBufferSize); assert(_buff != NULL); } @@ -116,7 +116,7 @@ IoBuf::IoBuf(const char *name, Crypt *crypt) _lim(0) { debugC(1, kCGEDebugFile, "IoBuf::IoBuf(%s, crypt)", name); - _buff = (uint8 *) malloc(sizeof(uint8) * kBufferSize); + _buff = (uint8 *)malloc(sizeof(uint8) * kBufferSize); assert(_buff != NULL); } diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 8fbf5455355..7cd44a81d0b 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -31,67 +31,6 @@ namespace CGE { -Dac _stdPal[] = {// R G B - { 0, 60, 0}, // 198 - { 0, 104, 0}, // 199 - { 20, 172, 0}, // 200 - { 82, 82, 0}, // 201 - { 0, 132, 82}, // 202 - { 132, 173, 82}, // 203 - { 82, 0, 0}, // 204 - { 206, 0, 24}, // 205 - { 255, 33, 33}, // 206 - { 123, 41, 0}, // 207 - { 0, 41, 0}, // 208 - { 0, 0, 82}, // 209 - { 132, 0, 0}, // 210 - { 255, 0, 0}, // 211 - { 255, 66, 66}, // 212 - { 148, 66, 16}, // 213 - { 0, 82, 0}, // 214 - { 0, 0, 132}, // 215 - { 173, 0, 0}, // 216 - { 255, 49, 0}, // 217 - { 255, 99, 99}, // 218 - { 181, 107, 49}, // 219 - { 0, 132, 0}, // 220 - { 0, 0, 255}, // 221 - { 173, 41, 0}, // 222 - { 255, 82, 0}, // 223 - { 255, 132, 132}, // 224 - { 214, 148, 74}, // 225 - { 41, 214, 0}, // 226 - { 0, 82, 173}, // 227 - { 255, 214, 0}, // 228 - { 247, 132, 49}, // 229 - { 255, 165, 165}, // 230 - { 239, 198, 123}, // 231 - { 173, 214, 0}, // 232 - { 0, 132, 214}, // 233 - { 57, 57, 57}, // 234 - { 247, 189, 74}, // 235 - { 255, 198, 198}, // 236 - { 255, 239, 173}, // 237 - { 214, 255, 173}, // 238 - { 82, 173, 255}, // 239 - { 107, 107, 107}, // 240 - { 247, 222, 99}, // 241 - { 255, 0, 255}, // 242 - { 255, 132, 255}, // 243 - { 132, 132, 173}, // 244 - { 148, 247, 255}, // 245 - { 148, 148, 148}, // 246 - { 82, 0, 82}, // 247 - { 112, 68, 112}, // 248 - { 176, 88, 144}, // 249 - { 214, 132, 173}, // 250 - { 206, 247, 255}, // 251 - { 198, 198, 198}, // 252 - { 0, 214, 255}, // 253 - { 96, 224, 96 }, // 254 - { 255, 255, 255}, // 255 -}; - const char *progName(const char *ext) { static char buf[kMaxFile]; strcpy(buf, "CGE"); @@ -168,8 +107,7 @@ DataCk::DataCk(byte *buf, int bufSize) { } DataCk::~DataCk() { - if (_buf) - free(_buf); + free(_buf); } } // End of namespace CGE diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 2d15b61d973..b1fc7629b02 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -399,7 +399,7 @@ const char *Snail::_comText[] = { Snail::Snail(CGEEngine *vm, bool turbo) : _turbo(turbo), _busy(false), _textDelay(false), _timerExpiry(0), _talkEnable(true), - _head(0), _tail(0), _snList((Com *) malloc(sizeof(Com) * 256)), _vm(vm) { + _head(0), _tail(0), _snList((Com *)malloc(sizeof(Com) * 256)), _vm(vm) { } Snail::~Snail() { @@ -863,7 +863,7 @@ void CGEEngine::snFlash(bool on) { debugC(1, kCGEDebugEngine, "CGEEngine::snFlash(%s)", on ? "true" : "false"); if (on) { - Dac *pal = (Dac *) malloc(sizeof(Dac) * kPalCount); + Dac *pal = (Dac *)malloc(sizeof(Dac) * kPalCount); if (pal) { memcpy(pal, _vga->_sysPal, kPalSize); for (int i = 0; i < kPalCount; i++) { diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index daef3fa429d..7a080f34056 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -192,10 +192,8 @@ MusicPlayer::~MusicPlayer() { void MusicPlayer::killMidi() { Audio::MidiPlayer::stop(); - if (_data != NULL) { - free(_data); - _data = NULL; - } + free(_data); + _data = NULL; } void MusicPlayer::loadMidi(int ref) { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 3db504425fa..d4643a32e18 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -685,8 +685,8 @@ Vga::Vga() : _frmCnt(0), _msg(NULL), _name(NULL), _setPal(false), _mono(0) { } } - _oldColors = (Dac *) malloc(sizeof(Dac) * kPalCount); - _newColors = (Dac *) malloc(sizeof(Dac) * kPalCount); + _oldColors = (Dac *)malloc(sizeof(Dac) * kPalCount); + _newColors = (Dac *)malloc(sizeof(Dac) * kPalCount); getColors(_oldColors); sunset(); setColors(); diff --git a/engines/cge/vmenu.cpp b/engines/cge/vmenu.cpp index 1497d5823ce..c213b997a3e 100644 --- a/engines/cge/vmenu.cpp +++ b/engines/cge/vmenu.cpp @@ -34,7 +34,7 @@ namespace CGE { MenuBar::MenuBar(CGEEngine *vm, uint16 w) : Talk(vm), _vm(vm) { int h = kFontHigh + 2 * kMenuBarVM; int i = (w += 2 * kMenuBarHM) * h; - uint8 *p = (uint8 *) malloc(sizeof(uint8) * i); + uint8 *p = (uint8 *)malloc(sizeof(uint8) * i); memset(p + w, kPixelTransp, i - 2 * w); memset(p, kMenuBarLT, w); From e46c613e9a06828ede0001b8e4e7db1bef65d433 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 6 Sep 2011 19:56:47 +0200 Subject: [PATCH 262/276] CGE: Remove 'count' static variable from snail Thanks LordHoto for pointing it out --- engines/cge/cge.h | 2 +- engines/cge/snail.cpp | 20 +++++++++++--------- engines/cge/sound.cpp | 14 ++++++++++++-- engines/cge/sound.h | 5 ++++- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 1d38b6a59b5..40ea682ebce 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -249,7 +249,7 @@ public: void snSetY0(int cav, int y0); void snSetZ(Sprite *spr, int z); void snSlave(Sprite *spr, int ref); - void snSound(Sprite *spr, int wav, int cnt); + void snSound(Sprite *spr, int wav); void snSwap(Sprite *spr, int xref); void snTNext(Sprite *spr, int p); void snTrans(Sprite *spr, int trans); diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index b1fc7629b02..ccdcac35780 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -771,13 +771,15 @@ void CGEEngine::snKill(Sprite *spr) { } } -void CGEEngine::snSound(Sprite *spr, int wav, int cnt) { - debugC(1, kCGEDebugEngine, "CGEEngine::snSound(spr, %d, %d)", wav, cnt); +void CGEEngine::snSound(Sprite *spr, int wav) { + debugC(1, kCGEDebugEngine, "CGEEngine::snSound(spr, %d)", wav); if (wav == -1) _sound->stop(); else - _sound->play((*_fx)[wav], (spr) ? ((spr->_x + spr->_w / 2) / (kScrWidth / 16)) : 8, cnt); + _sound->play((*_fx)[wav], (spr) ? ((spr->_x + spr->_w / 2) / (kScrWidth / 16)) : 8); + + _sound->setRepeat(1); } void CGEEngine::snKeep(Sprite *spr, int stp) { @@ -785,7 +787,10 @@ void CGEEngine::snKeep(Sprite *spr, int stp) { selectPocket(-1); if (spr && ! spr->_flags._kept && _pocket[_pocPtr] == NULL) { - snSound(spr, 3, 1); + int16 oldRepeat = _sound->getRepeat(); + _sound->setRepeat(1); + snSound(spr, 3); + _sound->setRepeat(oldRepeat); _pocket[_pocPtr] = spr; spr->_cave = 0; spr->_flags._kept = true; @@ -926,8 +931,6 @@ void CGEEngine::snMouse(bool on) { } void Snail::runCom() { - static int count = 1; - if (_busy) return; @@ -1122,11 +1125,10 @@ void Snail::runCom() { _vm->snReach(spr, snc->_val); break; case kSnSound: - _vm->snSound(spr, snc->_val, count); - count = 1; + _vm->snSound(spr, snc->_val); break; case kSnCount: - count = snc->_val; + _sound->setRepeat(snc->_val); break; case kSnExec: switch (snc->_cbType) { diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 7a080f34056..340a6c644c4 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -37,6 +37,7 @@ namespace CGE { Sound::Sound(CGEEngine *vm) : _vm(vm) { _audioStream = NULL; + _soundRepeatCount = 1; open(); } @@ -49,16 +50,25 @@ void Sound::close() { } void Sound::open() { + setRepeat(1); play((*_fx)[30000], 8); } -void Sound::play(DataCk *wav, int pan, int cnt) { +void Sound::setRepeat(int16 count) { + _soundRepeatCount = count; +} + +int16 Sound::getRepeat() { + return _soundRepeatCount; +} + +void Sound::play(DataCk *wav, int pan) { if (wav) { stop(); _smpinf._saddr = &*(wav->addr()); _smpinf._slen = (uint16)wav->size(); _smpinf._span = pan; - _smpinf._sflag = cnt; + _smpinf._sflag = getRepeat(); sndDigiStart(&_smpinf); } } diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 1474b78c28e..7cb4f33969e 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -66,9 +66,12 @@ public: ~Sound(); void open(); void close(); - void play(DataCk *wav, int pan, int cnt = 1); + void play(DataCk *wav, int pan); + int16 getRepeat(); + void setRepeat(int16 count); void stop(); private: + int _soundRepeatCount; CGEEngine *_vm; Audio::SoundHandle _soundHandle; Audio::RewindableAudioStream *_audioStream; From 85d10fe6c7fb249bdb0e349fba5f4d46dce464e4 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 6 Sep 2011 21:58:41 +0200 Subject: [PATCH 263/276] CGE: Handle properly looping samples --- engines/cge/snddrv.h | 2 +- engines/cge/sound.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/engines/cge/snddrv.h b/engines/cge/snddrv.h index 987582190c9..93793de2feb 100644 --- a/engines/cge/snddrv.h +++ b/engines/cge/snddrv.h @@ -39,7 +39,7 @@ struct SmpInfo { const uint8 *_saddr; // address uint16 _slen; // length uint16 _span; // left/right pan (0-15) - int _sflag; // flag + int _counter; // number of time the sample should be played }; // ****************************************************** diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 340a6c644c4..fb0549ac225 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -32,6 +32,7 @@ #include "common/config-manager.h" #include "common/memstream.h" #include "audio/decoders/raw.h" +#include "audio/audiostream.h" namespace CGE { @@ -68,7 +69,7 @@ void Sound::play(DataCk *wav, int pan) { _smpinf._saddr = &*(wav->addr()); _smpinf._slen = (uint16)wav->size(); _smpinf._span = pan; - _smpinf._sflag = getRepeat(); + _smpinf._counter = getRepeat(); sndDigiStart(&_smpinf); } } @@ -80,7 +81,8 @@ void Sound::sndDigiStart(SmpInfo *PSmpInfo) { _audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES); // Start the new sound - _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, _audioStream); + _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, + Audio::makeLoopingAudioStream(_audioStream, (uint)PSmpInfo->_counter)); } void Sound::stop() { From 39d09d5865d9a01bfdbde02b047806f801a5d5c8 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 6 Sep 2011 22:59:10 +0200 Subject: [PATCH 264/276] CGE: Cleanup: remove residuals of the demo code Thanks to fingolfin and LordHoto for pointing it out --- engines/cge/cge.cpp | 27 ++++----------------------- engines/cge/cge.h | 19 ++++++++++--------- engines/cge/cge_main.cpp | 29 ++++++++++++++--------------- engines/cge/walk.cpp | 4 ++-- 4 files changed, 30 insertions(+), 49 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index dafb8a3782c..66262e5e4aa 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -38,6 +38,8 @@ namespace CGE { +const int CGEEngine::_maxCaveArr[5] = {1, 8, 16, 23, 24}; + CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) : Engine(syst), _gameDescription(gameDescription), _randomSource("cge") { @@ -54,36 +56,17 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) } void CGEEngine::initCaveValues() { - _caveDx = 9; - _caveDy = 10; - _caveNx = 8; - _caveNy = 3; - _caveMax = _caveNx * _caveNy; - - _maxCaveArr[0] = 1; - _maxCaveArr[1] = 8; - _maxCaveArr[2] = 16; - _maxCaveArr[3] = 23; - _maxCaveArr[4] = 24; - - _heroXY = (Hxy *)malloc(sizeof(Hxy) * _caveMax); - for (int i = 0; i < _caveMax; i++) { + for (int i = 0; i < kCaveMax; i++) { _heroXY[i]._x = 0; _heroXY[i]._y = 0; } - _barriers = (Bar *)malloc(sizeof(Bar) * (1 + _caveMax)); - for (int i = 0; i < _caveMax + 1; i++) { + for (int i = 0; i < kCaveMax + 1; i++) { _barriers[i]._horz = 0xFF; _barriers[i]._vert = 0xFF; } } -void CGEEngine::freeCaveValues() { - free(_heroXY); - free(_barriers); -} - void CGEEngine::init() { debugC(1, kCGEDebugEngine, "CGEEngine::setup()"); @@ -195,8 +178,6 @@ void CGEEngine::deinit() { delete _miniShpList[i]; delete[] _miniShpList; } - - freeCaveValues(); } CGEEngine::~CGEEngine() { diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 40ea682ebce..95985103f4d 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -51,6 +51,12 @@ class Sprite; #define kPocketNY 1 #define kPocketSX 8 #define kPocketSY 3 +#define kCaveDx 9 +#define kCaveDy 10 +#define kCaveNx 8 +#define kCaveNy 3 +#define kCaveMax kCaveNx * kCaveNy + // our engine debug channels enum { @@ -106,6 +112,8 @@ public: virtual Common::Error loadGameState(int slot); virtual Common::Error saveGameState(int slot, const Common::String &desc); + static const int _maxCaveArr[5]; + const ADGameDescription *_gameDescription; int _startupMode; int _demoText; @@ -114,7 +122,6 @@ public: bool _music; int _pocref[kPocketNX]; uint8 _volume[2]; - int _maxCaveArr[5]; int _maxCave; bool _flag[4]; bool _dark; @@ -132,13 +139,8 @@ public: Sprite *_sprK2; Sprite *_sprK3; - uint8 _caveDx; - uint8 _caveDy; - uint8 _caveNx; - uint8 _caveNy; - uint16 _caveMax; - Hxy *_heroXY; - Bar *_barriers; + Hxy _heroXY[kCaveMax]; + Bar _barriers[kCaveMax]; Common::RandomSource _randomSource; MusicPlayer _midiPlayer; @@ -212,7 +214,6 @@ public: void postMiniStep(int stp); void showBak(int ref); void initCaveValues(); - void freeCaveValues(); void snBackPt(Sprite *spr, int stp); void snBarrier(int cav, int bar, bool horz); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index a6fd08d396d..b168c039e6f 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -162,16 +162,15 @@ void CGEEngine::syncHeader(Common::Serializer &s) { s.syncAsUint16LE(_flag[i]); if (s.isLoading()) { - // Reinitialise cave values - freeCaveValues(); + // Reset cave values initCaveValues(); } - for (i = 0; i < _caveMax; i++) { + for (i = 0; i < kCaveMax; i++) { s.syncAsSint16LE(_heroXY[i]._x); s.syncAsUint16LE(_heroXY[i]._y); } - for (i = 0; i < 1 + _caveMax; i++) { + for (i = 0; i < 1 + kCaveMax; i++) { s.syncAsByte(_barriers[i]._horz); s.syncAsByte(_barriers[i]._vert); } @@ -281,8 +280,8 @@ Common::Error CGEEngine::loadGameState(int slot) { // Load the game loadGame(slot, NULL); _snail->addCom(kSnLevel, -1, _oldLev, &_cavLight); - _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, - kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); + _cavLight->gotoxy(kCaveX + ((_now - 1) % kCaveNx) * kCaveDx + kCaveSX, + kCaveY + ((_now - 1) / kCaveNx) * kCaveDy + kCaveSY); caveUp(); return Common::kNoError; @@ -480,7 +479,7 @@ void CGEEngine::loadHeroXY() { memset(_heroXY, 0, sizeof(_heroXY)); if (!cf._error) { - for (int i = 0; i < _caveMax; ++i) { + for (int i = 0; i < kCaveMax; ++i) { cf.read((byte *)&x, 2); cf.read((byte *)&y, 2); @@ -493,7 +492,7 @@ void CGEEngine::loadHeroXY() { void CGEEngine::loadMapping() { debugC(1, kCGEDebugEngine, "CGEEngine::loadMapping()"); - if (_now <= _caveMax) { + if (_now <= kCaveMax) { VFile cf(progName(".TAB")); if (!cf._error) { // Move to the data for the given room @@ -730,8 +729,8 @@ void CGEEngine::switchCave(int cav) { _hero->step(0); _vga->_spareQ->_show = 0; } - _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, - kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); + _cavLight->gotoxy(kCaveX + ((_now - 1) % kCaveNx) * kCaveDx + kCaveSX, + kCaveY + ((_now - 1) / kCaveNx) * kCaveDy + kCaveSY); killText(); if (!_startupMode) keyClick(); @@ -794,9 +793,9 @@ void System::touch(uint16 mask, int x, int y) { _infoLine->update(NULL); if (y >= kWorldHeight ) { if (x < kButtonX) { // select cave? - if (y >= kCaveY && y < kCaveY + _vm->_caveNy * _vm->_caveDy && - x >= kCaveX && x < kCaveX + _vm->_caveNx * _vm->_caveDx && !_vm->_game) { - cav = ((y - kCaveY) / _vm->_caveDy) * _vm->_caveNx + (x - kCaveX) / _vm->_caveDx + 1; + if (y >= kCaveY && y < kCaveY + kCaveNy * kCaveDy && + x >= kCaveX && x < kCaveX + kCaveNx * kCaveDx && !_vm->_game) { + cav = ((y - kCaveY) / kCaveDy) * kCaveNx + (x - kCaveX) / kCaveDx + 1; if (cav > _vm->_maxCave) cav = 0; } else { @@ -1397,8 +1396,8 @@ void CGEEngine::runGame() { _startupMode = 0; _snail->addCom(kSnLevel, -1, _oldLev, &_cavLight); - _cavLight->gotoxy(kCaveX + ((_now - 1) % _caveNx) * _caveDx + kCaveSX, - kCaveY + ((_now - 1) / _caveNx) * _caveDy + kCaveSY); + _cavLight->gotoxy(kCaveX + ((_now - 1) % kCaveNx) * kCaveDx + kCaveSX, + kCaveY + ((_now - 1) / kCaveNx) * kCaveDy + kCaveSY); caveUp(); _keyboard->setClient(_sys); diff --git a/engines/cge/walk.cpp b/engines/cge/walk.cpp index bcd15768f1a..e2b9a8961ff 100644 --- a/engines/cge/walk.cpp +++ b/engines/cge/walk.cpp @@ -200,7 +200,7 @@ void Walk::reach(Sprite *spr, int mode) { _snail->insCom(kSnPause, -1, 64, NULL); _snail->insCom(kSnSeq, -1, kTSeq + mode, this); if (spr) { - _snail->insCom(kSnWait, -1, -1, _hero); /////--------$$$$$$$ + _snail->insCom(kSnWait, -1, -1, _hero); //SNINSERT(SNWALK, -1, -1, spr); } // sequence is not finished, @@ -212,7 +212,7 @@ void Walk::noWay() { } bool Cluster::chkBar() const { - assert(_vm->_now <= _vm->_caveMax); + assert(_vm->_now <= kCaveMax); return (_pt.x == _vm->_barriers[_vm->_now]._horz) || (_pt.y == _vm->_barriers[_vm->_now]._vert); } From 52f669c93c9497a03e3e32467a4614263e1c6382 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Tue, 6 Sep 2011 23:14:49 +0200 Subject: [PATCH 265/276] CGE: Replace Hxy by Common::Point --- engines/cge/cge.cpp | 4 ++-- engines/cge/cge.h | 8 ++------ engines/cge/cge_main.cpp | 12 ++++++------ engines/cge/snail.cpp | 4 ++-- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 66262e5e4aa..7a181a58be4 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -57,8 +57,8 @@ CGEEngine::CGEEngine(OSystem *syst, const ADGameDescription *gameDescription) void CGEEngine::initCaveValues() { for (int i = 0; i < kCaveMax; i++) { - _heroXY[i]._x = 0; - _heroXY[i]._y = 0; + _heroXY[i].x = 0; + _heroXY[i].y = 0; } for (int i = 0; i < kCaveMax + 1; i++) { diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 95985103f4d..66811a9a10d 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -28,6 +28,7 @@ #include "common/savefile.h" #include "common/serializer.h" #include "common/str.h" +#include "common/rect.h" #include "engines/engine.h" #include "gui/debugger.h" #include "graphics/surface.h" @@ -89,11 +90,6 @@ struct Bar { uint8 _vert; }; -struct Hxy { - int _x; - int _y; -}; - class CGEEngine : public Engine { private: uint32 _lastFrame, _lastTick; @@ -139,7 +135,7 @@ public: Sprite *_sprK2; Sprite *_sprK3; - Hxy _heroXY[kCaveMax]; + Common::Point _heroXY[kCaveMax]; Bar _barriers[kCaveMax]; Common::RandomSource _randomSource; diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index b168c039e6f..a915a086898 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -167,8 +167,8 @@ void CGEEngine::syncHeader(Common::Serializer &s) { } for (i = 0; i < kCaveMax; i++) { - s.syncAsSint16LE(_heroXY[i]._x); - s.syncAsUint16LE(_heroXY[i]._y); + s.syncAsSint16LE(_heroXY[i].x); + s.syncAsUint16LE(_heroXY[i].y); } for (i = 0; i < 1 + kCaveMax; i++) { s.syncAsByte(_barriers[i]._horz); @@ -483,8 +483,8 @@ void CGEEngine::loadHeroXY() { cf.read((byte *)&x, 2); cf.read((byte *)&y, 2); - _heroXY[i]._x = (int16)FROM_LE_16(x); - _heroXY[i]._y = (int16)FROM_LE_16(y); + _heroXY[i].x = (int16)FROM_LE_16(x); + _heroXY[i].y = (int16)FROM_LE_16(y); } } } @@ -641,7 +641,7 @@ void CGEEngine::caveUp() { _fx->preload(BakRef); if (_hero) { - _hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); + _hero->gotoxy(_heroXY[_now - 1].x, _heroXY[_now - 1].y); // following 2 lines trims Hero's Z position! _hero->tick(); _hero->_time = 1; @@ -1361,7 +1361,7 @@ void CGEEngine::runGame() { if (_hero) { expandSprite(_hero); - _hero->gotoxy(_heroXY[_now - 1]._x, _heroXY[_now - 1]._y); + _hero->gotoxy(_heroXY[_now - 1].x, _heroXY[_now - 1].y); if (VFile::exist("00SHADOW.SPR")) { loadSprite("00SHADOW", -1, 0, _hero->_x + 14, _hero->_y + 51); delete _shadow; diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index ccdcac35780..0e0606706b1 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -653,13 +653,13 @@ void CGEEngine::snUncover(Sprite *spr, Sprite *xspr) { void CGEEngine::snSetX0(int cav, int x0) { debugC(1, kCGEDebugEngine, "CGEEngine::snSetX0(%d, %d)", cav, x0); - _heroXY[cav - 1]._x = x0; + _heroXY[cav - 1].x = x0; } void CGEEngine::snSetY0(int cav, int y0) { debugC(1, kCGEDebugEngine, "CGEEngine::snSetY0(%d, %d)", cav, y0); - _heroXY[cav - 1]._y = y0; + _heroXY[cav - 1].y = y0; } void CGEEngine::snSetXY(Sprite *spr, uint16 xy) { From 3e574cfbf89ef7dc6126e64a1776595fea9fac7b Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 7 Sep 2011 01:02:05 +0200 Subject: [PATCH 266/276] CGE: Remove wtom() --- engines/cge/cge_main.cpp | 5 ++--- engines/cge/general.cpp | 11 ----------- engines/cge/general.h | 1 - engines/cge/sound.cpp | 16 ++++++++++------ 4 files changed, 12 insertions(+), 21 deletions(-) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index a915a086898..c4719fe287d 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -529,10 +529,9 @@ void CGEEngine::setMapBrick(int x, int z) { Square *s = new Square(this); if (s) { - static char n[] = "00:00"; + char n[6]; s->gotoxy(x * kMapGridX, kMapTop + z * kMapGridZ); - wtom(x, n + 0, 10, 2); - wtom(z, n + 3, 10, 2); + sprintf(n, "%02d:%02d", x, z); Cluster::_map[z][x] = 1; s->setName(n); _vga->_showQ->insert(s, _vga->_showQ->first()); diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 7cd44a81d0b..13a92d38c23 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -63,17 +63,6 @@ char *forceExt(char *buf, const char *name, const char *ext) { return buf; } -char *wtom(uint16 val, char *str, int radix, int len) { - while (--len >= 0) { - uint16 w = val % radix; - if (w > 9) - w += ('A' - ('9' + 1)); - str[len] = '0' + w; - val /= radix; - } - return str; -} - void sndSetVolume() { // USeless for ScummVM } diff --git a/engines/cge/general.h b/engines/cge/general.h index 33abd1e852b..b9e8e27be44 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -47,7 +47,6 @@ struct Dac { typedef uint16 Crypt(void *buf, uint16 siz, uint16 seed); -char *wtom(uint16 val, char *str, int radix, int len); int takeEnum(const char **tab, const char *text); uint16 chkSum(void *m, uint16 n); char *mergeExt(char *buf, const char *name, const char *ext); diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index fb0549ac225..547469aef8d 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -132,11 +132,11 @@ int Fx::find(int ref) { void Fx::preload(int ref0) { Han *cacheLim = _cache + _size; + char filename[12]; for (int ref = ref0; ref < ref0 + 10; ref++) { - static char fname[] = "FX00000.WAV"; - wtom(ref, fname + 2, 10, 5); - VFile file = VFile(fname); + sprintf(filename, "FX%05d.WAV", ref); + VFile file = VFile(filename); DataCk *wav = loadWave(&file); if (wav) { Han *p = &_cache[find(0)]; @@ -144,20 +144,24 @@ void Fx::preload(int ref0) { break; p->_wav = wav; p->_ref = ref; + } else { + warning("Unable to load %s", filename); } } } DataCk *Fx::load(int idx, int ref) { - static char fname[] = "FX00000.WAV"; - wtom(ref, fname + 2, 10, 5); + char filename[12]; + sprintf(filename, "FX%05d.WAV", ref); - VFile file = VFile(fname); + VFile file = VFile(filename); DataCk *wav = loadWave(&file); if (wav) { Han *p = &_cache[idx]; p->_wav = wav; p->_ref = ref; + } else { + warning("Unable to load %s", filename); } return wav; } From 45de8747d5dd97dcad09667393fc0e534d199f3a Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 7 Sep 2011 22:37:03 +0200 Subject: [PATCH 267/276] CGE: Clean up and split snBarrier(), remove progName() --- engines/cge/cge.cpp | 2 +- engines/cge/cge.h | 3 ++- engines/cge/cge_main.cpp | 22 +++++++++++++--------- engines/cge/cge_main.h | 5 ++++- engines/cge/general.cpp | 13 ------------- engines/cge/general.h | 13 +++++-------- engines/cge/snail.cpp | 16 +++++++++++----- engines/cge/talk.cpp | 2 +- 8 files changed, 37 insertions(+), 39 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 7a181a58be4..944413471bb 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -90,7 +90,7 @@ void CGEEngine::init() { Cluster::init(this); // Initialise engine objects - _text = new Text(this, progName(), 128); + _text = new Text(this, "CGE", 128); _vga = new Vga(); _sys = new System(this); _pocLight = new PocLight(this); diff --git a/engines/cge/cge.h b/engines/cge/cge.h index 66811a9a10d..5a4c0bf86d3 100644 --- a/engines/cge/cge.h +++ b/engines/cge/cge.h @@ -212,7 +212,8 @@ public: void initCaveValues(); void snBackPt(Sprite *spr, int stp); - void snBarrier(int cav, int bar, bool horz); + void snHBarrier(const int cave, const int barX); + void snVBarrier(const int cave, const int barY); void snCover(Sprite *spr, int xref); void snFlag(int indx, bool v); void snFlash(bool on); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index c4719fe287d..e3f0e610bd5 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -474,7 +474,7 @@ void CGEEngine::tooFar() { void CGEEngine::loadHeroXY() { debugC(1, kCGEDebugEngine, "CGEEngine::loadHeroXY()"); - VFile cf(progName(".HXY")); + VFile cf("CGE.HXY"); uint16 x, y; memset(_heroXY, 0, sizeof(_heroXY)); @@ -493,7 +493,7 @@ void CGEEngine::loadMapping() { debugC(1, kCGEDebugEngine, "CGEEngine::loadMapping()"); if (_now <= kCaveMax) { - VFile cf(progName(".TAB")); + VFile cf("CGE.TAB"); if (!cf._error) { // Move to the data for the given room cf.seek((_now - 1) * kMapArrSize); @@ -1295,7 +1295,7 @@ void CGEEngine::loadUser() { } else { error("Creating setup savegames not supported"); } - loadScript(progName(kIn0Ext)); + loadScript("CGE.IN0"); } void CGEEngine::runGame() { @@ -1422,10 +1422,14 @@ void CGEEngine::runGame() { } void CGEEngine::movie(const char *ext) { + assert(ext); + if (_eventManager->_quitFlag) return; - const char *fn = progName(ext); + char fn[12]; + sprintf(fn, "CGE.%s", (*ext == '.') ? ext +1 : ext); + if (VFile::exist(fn)) { loadScript(fn); expandSprite(_vga->_spareQ->locate(999)); @@ -1492,7 +1496,7 @@ bool CGEEngine::showTitle(const char *name) { if (_mode < 2) { // At this point the game originally set the protection variables // used by the copy protection check - movie("X00"); // paylist + movie(kPaylistExt); // paylist _vga->copyPage(1, 2); _vga->copyPage(0, 1); _vga->_showQ->append(_mouse); @@ -1520,7 +1524,7 @@ bool CGEEngine::showTitle(const char *name) { } if (_mode < 2) - movie("X01"); // wink + movie(kWinkExt); _vga->copyPage(0, 2); @@ -1550,18 +1554,18 @@ void CGEEngine::cge_main() { _startupMode = 2; if (_flag[3]) // Flag FINIS - movie("X03"); + movie(kEndgExt); } else { if (_mode < 2) movie(kLgoExt); if (showTitle("WELCOME")) { if (_mode == 1) - movie("X02"); // intro + movie(kIntroExt); runGame(); _startupMode = 2; if (_flag[3]) // Flag FINIS - movie("X03"); + movie(kEndgExt); } else _vga->sunset(); } diff --git a/engines/cge/cge_main.h b/engines/cge/cge_main.h index d91fabc875d..d6f1a996d1a 100644 --- a/engines/cge/cge_main.h +++ b/engines/cge/cge_main.h @@ -47,9 +47,12 @@ namespace CGE { #define kMiniY 162 #define kLineMax 512 #define kDistMax 3 -#define kIn0Ext ".IN0" #define kLgoExt ".LGO" #define kSvgExt ".SVG" +#define kPaylistExt ".X00" +#define kWinkExt ".X01" +#define kIntroExt ".X02" +#define kEndgExt ".X03" #define kWalkSide 10 #define kBusyRef 500 #define kSystemRate 6 // 12 Hz diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 13a92d38c23..5c113bd1e17 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -31,19 +31,6 @@ namespace CGE { -const char *progName(const char *ext) { - static char buf[kMaxFile]; - strcpy(buf, "CGE"); - if (ext) { - strcat(buf, "."); - if (*ext == '.') - ext++; - strcat(buf, ext); - } - - return buf; -} - char *mergeExt(char *buf, const char *name, const char *ext) { strcpy(buf, name); char *dot = strrchr(buf, '.'); diff --git a/engines/cge/general.h b/engines/cge/general.h index b9e8e27be44..8c0432b763d 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -47,14 +47,11 @@ struct Dac { typedef uint16 Crypt(void *buf, uint16 siz, uint16 seed); -int takeEnum(const char **tab, const char *text); -uint16 chkSum(void *m, uint16 n); -char *mergeExt(char *buf, const char *name, const char *ext); -char *forceExt(char *buf, const char *name, const char *ext); - -// MISSING FUNCTIONS -const char *progName(const char *ext = NULL); -int newRandom(int range); +int takeEnum(const char **tab, const char *text); +uint16 chkSum(void *m, uint16 n); +char *mergeExt(char *buf, const char *name, const char *ext); +char *forceExt(char *buf, const char *name, const char *ext); +int newRandom(int range); } // End of namespace CGE #endif diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 0e0606706b1..3605ad94bda 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -897,10 +897,16 @@ void CGEEngine::snLight(bool in) { _dark = !in; } -void CGEEngine::snBarrier(int cav, int bar, bool horz) { - debugC(1, kCGEDebugEngine, "CGEEngine::snBarrier(%d, %d, %s)", cav, bar, horz ? "true" : "false"); +void CGEEngine::snHBarrier(const int cave, const int barX) { + debugC(1, kCGEDebugEngine, "CGEEngine::snHBarrier(%d, %d)", cave, barX); - ((uint8 *)(_barriers + ((cav > 0) ? cav : _now)))[horz] = bar; + _barriers[(cave > 0) ? cave : _now]._horz = barX; +} + +void CGEEngine::snVBarrier(const int cave, const int barY) { + debugC(1, kCGEDebugEngine, "CGEEngine::snVBarrier(%d, %d)", cave, barY); + + _barriers[(cave > 0) ? cave : _now]._vert = barY; } void CGEEngine::snWalk(Sprite *spr, int x, int y) { @@ -1113,10 +1119,10 @@ void Snail::runCom() { _vm->snLight(snc->_val != 0); break; case kSnSetHBarrier: - _vm->snBarrier(snc->_ref, snc->_val, true); + _vm->snHBarrier(snc->_ref, snc->_val); break; case kSnSetVBarrier: - _vm->snBarrier(snc->_ref, snc->_val, false); + _vm->snVBarrier(snc->_ref, snc->_val); break; case kSnWalk: _vm->snWalk(spr, snc->_ref, snc->_val); diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 9a4cd7caf52..2d9c17c73d0 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -93,7 +93,7 @@ Talk::Talk(CGEEngine *vm) Font *Talk::_font; void Talk::init() { - _font = new Font(progName()); + _font = new Font("CGE"); } void Talk::deinit() { From 4b9d2c2516b5eb84945ee11bdc0b6a8fd1b82fd5 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 7 Sep 2011 23:00:32 +0200 Subject: [PATCH 268/276] CGE: Rename Han structures to Handler Thanks to Fingolfin for pointing this out (as previous commit) --- engines/cge/sound.cpp | 12 ++++++------ engines/cge/sound.h | 2 +- engines/cge/text.cpp | 12 ++++++------ engines/cge/text.h | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 547469aef8d..6deb7f50200 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -96,7 +96,7 @@ void Sound::sndDigiStop(SmpInfo *PSmpInfo) { } Fx::Fx(int size) : _current(NULL) { - _cache = new Han[size]; + _cache = new Handler[size]; for (_size = 0; _size < size; _size++) { _cache[_size]._ref = 0; _cache[_size]._wav = NULL; @@ -109,7 +109,7 @@ Fx::~Fx() { } void Fx::clear() { - for (Han *p = _cache, *q = p + _size; p < q; p++) { + for (Handler *p = _cache, *q = p + _size; p < q; p++) { if (p->_ref) { p->_ref = 0; delete p->_wav; @@ -121,7 +121,7 @@ void Fx::clear() { int Fx::find(int ref) { int i = 0; - for (Han *p = _cache, *q = p + _size; p < q; p++) { + for (Handler *p = _cache, *q = p + _size; p < q; p++) { if (p->_ref == ref) break; else @@ -131,7 +131,7 @@ int Fx::find(int ref) { } void Fx::preload(int ref0) { - Han *cacheLim = _cache + _size; + Handler *cacheLim = _cache + _size; char filename[12]; for (int ref = ref0; ref < ref0 + 10; ref++) { @@ -139,7 +139,7 @@ void Fx::preload(int ref0) { VFile file = VFile(filename); DataCk *wav = loadWave(&file); if (wav) { - Han *p = &_cache[find(0)]; + Handler *p = &_cache[find(0)]; if (p >= cacheLim) break; p->_wav = wav; @@ -157,7 +157,7 @@ DataCk *Fx::load(int idx, int ref) { VFile file = VFile(filename); DataCk *wav = loadWave(&file); if (wav) { - Han *p = &_cache[idx]; + Handler *p = &_cache[idx]; p->_wav = wav; p->_ref = ref; } else { diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 7cb4f33969e..71ef7c2db62 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -82,7 +82,7 @@ private: class Fx { - struct Han { + struct Handler { int _ref; DataCk *_wav; } *_cache; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 6076fdd8ff7..3d67dd94459 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -38,7 +38,7 @@ Text *_text; Talk *_talk = NULL; Text::Text(CGEEngine *vm, const char *fname, int size) : _vm(vm) { - _cache = new Han[size]; + _cache = new Handler[size]; mergeExt(_fileName, fname, kSayExt); if (!VFile::exist(_fileName)) error("No talk (%s)\n", _fileName); @@ -55,7 +55,7 @@ Text::~Text() { } void Text::clear(int from, int upto) { - for (Han *p = _cache, *q = p + _size; p < q; p++) { + for (Handler *p = _cache, *q = p + _size; p < q; p++) { if (p->_ref && p->_ref >= from && p->_ref < upto) { p->_ref = 0; delete[] p->_text; @@ -66,7 +66,7 @@ void Text::clear(int from, int upto) { int Text::find(int ref) { int i = 0; - for (Han *p = _cache, *q = p + _size; p < q; p++) { + for (Handler *p = _cache, *q = p + _size; p < q; p++) { if (p->_ref == ref) break; else @@ -81,7 +81,7 @@ void Text::preload(int from, int upto) { if (tf._error) return; - Han *CacheLim = _cache + _size; + Handler *CacheLim = _cache + _size; char line[kLineMax + 1]; int n; @@ -97,7 +97,7 @@ void Text::preload(int from, int upto) { int ref = atoi(s); if (ref && ref >= from && ref < upto) { - Han *p = &_cache[find(ref)]; + Handler *p = &_cache[find(ref)]; if (p < CacheLim) { delete[] p->_text; @@ -150,7 +150,7 @@ char *Text::load(int idx, int ref) { if (s < line + n) ++s; - Han *p = &_cache[idx]; + Handler *p = &_cache[idx]; p->_ref = ref; if ((p->_text = new char[strlen(s) + 1]) == NULL) diff --git a/engines/cge/text.h b/engines/cge/text.h index 7ea0a947dbe..30bb77faaed 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -42,7 +42,7 @@ namespace CGE { class Text { - struct Han { + struct Handler { int _ref; char *_text; } *_cache; From b23bee8571567260c3003f82e3da4a681f3f0cc2 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 9 Sep 2011 16:51:47 +0200 Subject: [PATCH 269/276] CGE: Remove XFile, rename some members --- engines/cge/bitmap.cpp | 2 +- engines/cge/bitmap.h | 2 +- engines/cge/fileio.cpp | 34 +++++++++++++++++----------------- engines/cge/fileio.h | 26 ++++++++------------------ engines/cge/general.cpp | 2 +- engines/cge/sound.cpp | 4 ++-- engines/cge/sound.h | 2 +- 7 files changed, 31 insertions(+), 41 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index 42c1cc908d5..fee9eeeea1e 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -341,7 +341,7 @@ bool Bitmap::solidAt(int16 x, int16 y) { } } -bool Bitmap::loadVBM(XFile *f) { +bool Bitmap::loadVBM(VFile *f) { debugC(5, kCGEDebugBitmap, "Bitmap::loadVBM(f)"); uint16 p = 0, n = 0; diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index cd4f8267d11..78907dc4d74 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -61,7 +61,7 @@ struct HideDesc { #include "common/pack-end.h" class Bitmap { - bool loadVBM(XFile *f); + bool loadVBM(VFile *f); public: static Dac *_pal; uint16 _w; diff --git a/engines/cge/fileio.cpp b/engines/cge/fileio.cpp index e196a66d26c..7fc981070d3 100644 --- a/engines/cge/fileio.cpp +++ b/engines/cge/fileio.cpp @@ -51,12 +51,12 @@ uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { /*----------------------------------------------------------------------- * IOHand *-----------------------------------------------------------------------*/ -IoHand::IoHand(Crypt *crypt) : XFile(), _crypt(crypt), _seed(kCryptSeed) { +IoHand::IoHand(Crypt *crypt) : _error(0), _crypt(crypt), _seed(kCryptSeed) { _file = new Common::File(); } IoHand::IoHand(const char *name, Crypt *crypt) - : XFile(), _crypt(crypt), _seed(kCryptSeed) { + : _error(0), _crypt(crypt), _seed(kCryptSeed) { _file = new Common::File(); _file->open(name); } @@ -248,21 +248,21 @@ long CFile::seek(long pos) { * BtPage *-----------------------------------------------------------------------*/ void BtPage::read(Common::ReadStream &s) { - _hea._count = s.readUint16LE(); - _hea._down = s.readUint16LE(); + _header._count = s.readUint16LE(); + _header._down = s.readUint16LE(); - if (_hea._down == kBtValNone) { + if (_header._down == kBtValNone) { // Leaf list for (int i = 0; i < kBtLeafCount; ++i) { - s.read(_lea[i]._key, kBtKeySize); - _lea[i]._mark = s.readUint32LE(); - _lea[i]._size = s.readUint16LE(); + s.read(_leaf[i]._key, kBtKeySize); + _leaf[i]._mark = s.readUint32LE(); + _leaf[i]._size = s.readUint16LE(); } } else { // Root index for (int i = 0; i < kBtInnerCount; ++i) { - s.read(_inn[i]._key, kBtKeySize); - _inn[i]._down = s.readUint16LE(); + s.read(_inner[i]._key, kBtKeySize); + _inner[i]._down = s.readUint16LE(); } } } @@ -321,24 +321,24 @@ BtKeypack *BtFile::find(const char *key) { while (!_error) { BtPage *pg = getPage(lev, nxt); // search - if (pg->_hea._down != kBtValNone) { + if (pg->_header._down != kBtValNone) { int i; - for (i = 0; i < pg->_hea._count; i++) { + for (i = 0; i < pg->_header._count; i++) { // Does this work, or does it have to compare the entire buffer? - if (scumm_strnicmp((const char *)key, (const char*)pg->_inn[i]._key, kBtKeySize) < 0) + if (scumm_strnicmp((const char *)key, (const char*)pg->_inner[i]._key, kBtKeySize) < 0) break; } - nxt = (i) ? pg->_inn[i - 1]._down : pg->_hea._down; + nxt = (i) ? pg->_inner[i - 1]._down : pg->_header._down; _buff[lev]._indx = i - 1; lev++; } else { int i; - for (i = 0; i < pg->_hea._count - 1; i++) { - if (scumm_stricmp((const char *)key, (const char *)pg->_lea[i]._key) <= 0) + for (i = 0; i < pg->_header._count - 1; i++) { + if (scumm_stricmp((const char *)key, (const char *)pg->_leaf[i]._key) <= 0) break; } _buff[lev]._indx = i; - return &pg->_lea[i]; + return &pg->_leaf[i]; } } return NULL; diff --git a/engines/cge/fileio.h b/engines/cge/fileio.h index 4ac8e132924..eee0332010e 100644 --- a/engines/cge/fileio.h +++ b/engines/cge/fileio.h @@ -52,33 +52,23 @@ struct BtKeypack { }; struct Inner { - uint8 _key[kBtKeySize]; + uint8 _key[kBtKeySize]; uint16 _down; }; -struct Hea { +struct Header { uint16 _count; uint16 _down; }; -class XFile { -public: - uint16 _error; - - XFile() : _error(0) { } - virtual ~XFile() { } - virtual uint16 read(void *buf, uint16 len) = 0; - virtual long mark() = 0; - virtual long size() = 0; - virtual long seek(long pos) = 0; -}; - -class IoHand : public XFile { +class IoHand { protected: Common::File *_file; uint16 _seed; Crypt *_crypt; public: + uint16 _error; + IoHand(const char *name, Crypt crypt); IoHand(Crypt *crypt); virtual ~IoHand(); @@ -116,14 +106,14 @@ public: }; struct BtPage { - Hea _hea; + Header _header; union { // dummy filler to make proper size of union uint8 _data[kBtSize - 4 /*sizeof(Hea) */]; // inner version of data: key + word-sized page link - Inner _inn[kBtInnerCount]; + Inner _inner[kBtInnerCount]; // leaf version of data: key + all user data - BtKeypack _lea[kBtLeafCount]; + BtKeypack _leaf[kBtLeafCount]; }; void read(Common::ReadStream &s); diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 5c113bd1e17..ec98db705ef 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -54,7 +54,7 @@ void sndSetVolume() { // USeless for ScummVM } -DataCk *loadWave(XFile *file) { +DataCk *loadWave(VFile *file) { byte *data = (byte *)malloc(file->size()); file->read(data, file->size()); diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index 6deb7f50200..d8a9b7831ed 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -76,12 +76,12 @@ void Sound::play(DataCk *wav, int pan) { void Sound::sndDigiStart(SmpInfo *PSmpInfo) { // Create an audio stream wrapper for sound - Common::MemoryReadStream *stream = new Common::MemoryReadStream(PSmpInfo->_saddr, + Common::MemoryReadStream *stream = new Common::MemoryReadStream(PSmpInfo->_saddr, PSmpInfo->_slen, DisposeAfterUse::NO); _audioStream = Audio::makeWAVStream(stream, DisposeAfterUse::YES); // Start the new sound - _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, + _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundHandle, Audio::makeLoopingAudioStream(_audioStream, (uint)PSmpInfo->_counter)); } diff --git a/engines/cge/sound.h b/engines/cge/sound.h index 71ef7c2db62..0a7d018c815 100644 --- a/engines/cge/sound.h +++ b/engines/cge/sound.h @@ -57,7 +57,7 @@ public: } }; -DataCk *loadWave(XFile *file); +DataCk *loadWave(VFile *file); class Sound { public: From 8dc4cb40d91477103086da729350ba847e13cb04 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 9 Sep 2011 17:14:02 +0200 Subject: [PATCH 270/276] CGE: Remove a useless function declaration in class BtFile --- engines/cge/fileio.h | 1 - 1 file changed, 1 deletion(-) diff --git a/engines/cge/fileio.h b/engines/cge/fileio.h index eee0332010e..dc9c74ecf97 100644 --- a/engines/cge/fileio.h +++ b/engines/cge/fileio.h @@ -131,7 +131,6 @@ public: BtFile(const char *name, Crypt *crpt); virtual ~BtFile(); BtKeypack *find(const char *key); - BtKeypack *next(); }; class Dat { From 4848683e56b1466a7dabbbecb7bb1bf7e4c857a7 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 9 Sep 2011 18:24:11 +0200 Subject: [PATCH 271/276] CGE: Remove some static variables from fileIO --- engines/cge/bitmap.cpp | 2 +- engines/cge/cge.cpp | 6 +++-- engines/cge/cge_main.cpp | 13 ++++++---- engines/cge/fileio.cpp | 56 +++++++--------------------------------- engines/cge/fileio.h | 20 +++++--------- engines/cge/general.cpp | 9 +++++++ engines/cge/general.h | 2 ++ engines/cge/sound.cpp | 2 +- engines/cge/text.cpp | 2 +- engines/cge/vga13h.cpp | 2 +- 10 files changed, 42 insertions(+), 72 deletions(-) diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index fee9eeeea1e..cd440e08b4a 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -49,7 +49,7 @@ Bitmap::Bitmap(const char *fname) : _m(NULL), _v(NULL), _map(0) { char pat[kMaxPath]; forceExt(pat, fname, ".VBM"); - if (VFile::exist(pat)) { + if (_cat->exist(pat)) { VFile file(pat); if ((file._error == 0) && (!loadVBM(&file))) error("Bad VBM [%s]", fname); diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 944413471bb..d5d21726b1e 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -79,12 +79,13 @@ void CGEEngine::init() { _miniShp = NULL; _miniShpList = NULL; _sprite = NULL; + _dat = new Dat(); + _cat = new BtFile(kCatName, XCrypt); // Create debugger console _console = new CGEConsole(this); // Initialise classes that have static members - VFile::init(); Bitmap::init(); Talk::init(); Cluster::init(this); @@ -143,7 +144,6 @@ void CGEEngine::deinit() { // Call classes with static members to clear them up Talk::deinit(); Bitmap::deinit(); - VFile::deinit(); Cluster::init(this); // Remove all of our debug levels here @@ -172,6 +172,8 @@ void CGEEngine::deinit() { delete _snail; delete _snail_; delete _hero; + delete _dat; + delete _cat; if (_miniShpList) { for (int i = 0; _miniShpList[i]; ++i) diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index e3f0e610bd5..f837788edf9 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -72,6 +72,9 @@ Snail *_snail_; Fx *_fx; Sound *_sound; +Dat *_dat; +BtFile *_cat; + // 0.75 - 17II95 - full sound support // 0.76 - 18II95 - small MiniEMS in DEMO, // unhide CavLight in SNLEVEL @@ -1033,7 +1036,7 @@ void CGEEngine::loadSprite(const char *fname, int ref, int cav, int col = 0, int char line[kLineMax]; mergeExt(line, fname, kSprExt); - if (VFile::exist(line)) { // sprite description file exist + if (_cat->exist(line)) { // sprite description file exist VFile sprf(line); if (sprf._error) error("Bad SPR [%s]", line); @@ -1343,7 +1346,7 @@ void CGEEngine::runGame() { if (!_music) _midiPlayer.killMidi(); - if (VFile::exist("MINI.SPR")) { + if (_cat->exist("MINI.SPR")) { _miniShp = new BitmapPtr[2]; _miniShp[0] = _miniShp[1] = NULL; @@ -1361,7 +1364,7 @@ void CGEEngine::runGame() { if (_hero) { expandSprite(_hero); _hero->gotoxy(_heroXY[_now - 1].x, _heroXY[_now - 1].y); - if (VFile::exist("00SHADOW.SPR")) { + if (_cat->exist("00SHADOW.SPR")) { loadSprite("00SHADOW", -1, 0, _hero->_x + 14, _hero->_y + 51); delete _shadow; if ((_shadow = _sprite) != NULL) { @@ -1430,7 +1433,7 @@ void CGEEngine::movie(const char *ext) { char fn[12]; sprintf(fn, "CGE.%s", (*ext == '.') ? ext +1 : ext); - if (VFile::exist(fn)) { + if (_cat->exist(fn)) { loadScript(fn); expandSprite(_vga->_spareQ->locate(999)); feedSnail(_vga->_showQ->locate(999), kTake); @@ -1537,7 +1540,7 @@ void CGEEngine::cge_main() { if (!_mouse->_exist) error("%s", _text->getText(kTextNoMouse)); - if (!kSavegame0File::exist(kSavegame0Name)) + if (!_cat->exist(kSavegame0Name)) _mode = 2; _debugLine->_flags._hide = true; diff --git a/engines/cge/fileio.cpp b/engines/cge/fileio.cpp index 7fc981070d3..30d291d16bf 100644 --- a/engines/cge/fileio.cpp +++ b/engines/cge/fileio.cpp @@ -35,19 +35,6 @@ namespace CGE { -Dat *VFile::_dat = NULL; -BtFile *VFile::_cat = NULL; -VFile *VFile::_recent = NULL; - -uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { - byte *b = static_cast(buf); - - for (uint16 i = 0; i < siz; i++) - *b++ ^= seed; - - return seed; -} - /*----------------------------------------------------------------------- * IOHand *-----------------------------------------------------------------------*/ @@ -91,10 +78,6 @@ long IoHand::size() { return _file->size(); } -bool IoHand::exist(const char *name) { - return Common::File::exists(name); -} - /*----------------------------------------------------------------------- * IoBuf *-----------------------------------------------------------------------*/ @@ -215,10 +198,7 @@ int IoBuf::read() { /*----------------------------------------------------------------------- * CFile *-----------------------------------------------------------------------*/ -uint16 CFile::_maxLineLen = kLineMaxSize; - -CFile::CFile(const char *name, Crypt *crypt) - : IoBuf(name, crypt) { +CFile::CFile(const char *name, Crypt *crypt) : IoBuf(name, crypt) { debugC(1, kCGEDebugFile, "CFile::CFile(%s, crypt)", name); } @@ -344,6 +324,13 @@ BtKeypack *BtFile::find(const char *key) { return NULL; } +bool BtFile::exist(const char *name) { + debugC(1, kCGEDebugFile, "BtFile::exist(%s)", name); + + return scumm_stricmp(find(name)->_key, name) == 0; +} + + /*----------------------------------------------------------------------- * Dat *-----------------------------------------------------------------------*/ @@ -354,19 +341,6 @@ Dat::Dat(): _file(kDatName, XCrypt) { /*----------------------------------------------------------------------- * VFile *-----------------------------------------------------------------------*/ -void VFile::init() { - debugC(1, kCGEDebugFile, "VFile::init()"); - - _dat = new Dat(); - _cat = new BtFile(kCatName, XCrypt); - _recent = NULL; -} - -void VFile::deinit() { - delete _dat; - delete _cat; -} - VFile::VFile(const char *name) : IoBuf(NULL) { debugC(3, kCGEDebugFile, "VFile::VFile(%s)", name); @@ -379,23 +353,12 @@ VFile::VFile(const char *name) : IoBuf(NULL) { } VFile::~VFile() { - if (_recent == this) - _recent = NULL; -} - -bool VFile::exist(const char *name) { - debugC(1, kCGEDebugFile, "VFile::exist(%s)", name); - - return scumm_stricmp(_cat->find(name)->_key, name) == 0; } void VFile::readBuf() { debugC(3, kCGEDebugFile, "VFile::readBuf()"); - if (_recent != this) { - _dat->_file.seek(_bufMark + _lim); - _recent = this; - } + _dat->_file.seek(_bufMark + _lim); _bufMark = _dat->_file.mark(); long n = _endMark - _bufMark; if (n > kBufferSize) @@ -419,7 +382,6 @@ long VFile::size() { long VFile::seek(long pos) { debugC(1, kCGEDebugFile, "VFile::seek(%ld)", pos); - _recent = NULL; _lim = 0; return (_bufMark = _begMark + pos); } diff --git a/engines/cge/fileio.h b/engines/cge/fileio.h index dc9c74ecf97..6465c8e8f86 100644 --- a/engines/cge/fileio.h +++ b/engines/cge/fileio.h @@ -72,7 +72,6 @@ public: IoHand(const char *name, Crypt crypt); IoHand(Crypt *crypt); virtual ~IoHand(); - static bool exist(const char *name); uint16 read(void *buf, uint16 len); long mark(); long size(); @@ -98,7 +97,6 @@ public: class CFile : public IoBuf { public: - static uint16 _maxLineLen; CFile(const char *name, Crypt *crpt); virtual ~CFile(); long mark(); @@ -109,7 +107,7 @@ struct BtPage { Header _header; union { // dummy filler to make proper size of union - uint8 _data[kBtSize - 4 /*sizeof(Hea) */]; + uint8 _data[kBtSize - 4]; /* 4 is the size of struct Header */ // inner version of data: key + word-sized page link Inner _inner[kBtInnerCount]; // leaf version of data: key + all user data @@ -131,22 +129,17 @@ public: BtFile(const char *name, Crypt *crpt); virtual ~BtFile(); BtKeypack *find(const char *key); + bool exist(const char *name); }; class Dat { - friend class VFile; - CFile _file; public: Dat(); - bool read(long org, uint16 len, uint8 *buf); + CFile _file; }; class VFile : public IoBuf { private: - static Dat *_dat; - static BtFile *_cat; - static VFile *_recent; - long _begMark; long _endMark; @@ -155,15 +148,14 @@ public: VFile(const char *name); ~VFile(); - static void init(); - static void deinit(); - static bool exist(const char *name); - static const char *next(); long mark(); long size(); long seek(long pos); }; +extern Dat *_dat; +extern BtFile *_cat; + } // End of namespace CGE #endif diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index ec98db705ef..c93cc1292b0 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -31,6 +31,15 @@ namespace CGE { +uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { + byte *b = static_cast(buf); + + for (uint16 i = 0; i < siz; i++) + *b++ ^= seed; + + return seed; +} + char *mergeExt(char *buf, const char *name, const char *ext) { strcpy(buf, name); char *dot = strrchr(buf, '.'); diff --git a/engines/cge/general.h b/engines/cge/general.h index 8c0432b763d..8f997c9ae2f 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -47,11 +47,13 @@ struct Dac { typedef uint16 Crypt(void *buf, uint16 siz, uint16 seed); +uint16 XCrypt(void *buf, uint16 siz, uint16 seed); int takeEnum(const char **tab, const char *text); uint16 chkSum(void *m, uint16 n); char *mergeExt(char *buf, const char *name, const char *ext); char *forceExt(char *buf, const char *name, const char *ext); int newRandom(int range); + } // End of namespace CGE #endif diff --git a/engines/cge/sound.cpp b/engines/cge/sound.cpp index d8a9b7831ed..a7b2d34b0b3 100644 --- a/engines/cge/sound.cpp +++ b/engines/cge/sound.cpp @@ -215,7 +215,7 @@ void MusicPlayer::killMidi() { void MusicPlayer::loadMidi(int ref) { // Work out the filename and check the given MIDI file exists Common::String filename = Common::String::format("%.2d.MID", ref); - if (!VFile::exist(filename.c_str())) + if (!_cat->exist(filename.c_str())) return; // Stop any currently playing MIDI file diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 3d67dd94459..25af8eccfce 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -40,7 +40,7 @@ Talk *_talk = NULL; Text::Text(CGEEngine *vm, const char *fname, int size) : _vm(vm) { _cache = new Handler[size]; mergeExt(_fileName, fname, kSayExt); - if (!VFile::exist(_fileName)) + if (!_cat->exist(_fileName)) error("No talk (%s)\n", _fileName); for (_size = 0; _size < size; _size++) { diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index d4643a32e18..727cc72e39c 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -226,7 +226,7 @@ Sprite *Sprite::expand() { Snail::Com *nea = NULL; Snail::Com *tak = NULL; mergeExt(fname, _file, kSprExt); - if (VFile::exist(fname)) { // sprite description file exist + if (_cat->exist(fname)) { // sprite description file exist VFile sprf(fname); if (!(sprf._error==0)) error("Bad SPR [%s]", fname); From 0784b7e0b4f0f19b4c5a34f7081fdbf8ce9f75d9 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Fri, 9 Sep 2011 20:03:23 +0200 Subject: [PATCH 272/276] CGE: Remove Dat class --- engines/cge/cge.cpp | 2 +- engines/cge/cge_main.cpp | 2 +- engines/cge/fileio.cpp | 16 ++++------------ engines/cge/fileio.h | 10 ++-------- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index d5d21726b1e..1b9fcf64ed3 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -79,7 +79,7 @@ void CGEEngine::init() { _miniShp = NULL; _miniShpList = NULL; _sprite = NULL; - _dat = new Dat(); + _dat = new CFile(kDatName, XCrypt); _cat = new BtFile(kCatName, XCrypt); // Create debugger console diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index f837788edf9..b9033a81eee 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -72,7 +72,7 @@ Snail *_snail_; Fx *_fx; Sound *_sound; -Dat *_dat; +CFile *_dat; BtFile *_cat; // 0.75 - 17II95 - full sound support diff --git a/engines/cge/fileio.cpp b/engines/cge/fileio.cpp index 30d291d16bf..7624eac9364 100644 --- a/engines/cge/fileio.cpp +++ b/engines/cge/fileio.cpp @@ -330,21 +330,13 @@ bool BtFile::exist(const char *name) { return scumm_stricmp(find(name)->_key, name) == 0; } - -/*----------------------------------------------------------------------- - * Dat - *-----------------------------------------------------------------------*/ -Dat::Dat(): _file(kDatName, XCrypt) { - debugC(1, kCGEDebugFile, "Dat::Dat()"); -} - /*----------------------------------------------------------------------- * VFile *-----------------------------------------------------------------------*/ VFile::VFile(const char *name) : IoBuf(NULL) { debugC(3, kCGEDebugFile, "VFile::VFile(%s)", name); - if (_dat->_file._error || _cat->_error) + if (_dat->_error || _cat->_error) error("Bad volume data"); BtKeypack *kp = _cat->find(name); if (scumm_stricmp(kp->_key, name) != 0) @@ -358,12 +350,12 @@ VFile::~VFile() { void VFile::readBuf() { debugC(3, kCGEDebugFile, "VFile::readBuf()"); - _dat->_file.seek(_bufMark + _lim); - _bufMark = _dat->_file.mark(); + _dat->seek(_bufMark + _lim); + _bufMark = _dat->mark(); long n = _endMark - _bufMark; if (n > kBufferSize) n = kBufferSize; - _lim = _dat->_file.read(_buff, (uint16) n); + _lim = _dat->read(_buff, (uint16) n); _ptr = 0; } diff --git a/engines/cge/fileio.h b/engines/cge/fileio.h index 6465c8e8f86..65f0b953e7a 100644 --- a/engines/cge/fileio.h +++ b/engines/cge/fileio.h @@ -63,10 +63,10 @@ struct Header { class IoHand { protected: - Common::File *_file; uint16 _seed; Crypt *_crypt; public: + Common::File *_file; uint16 _error; IoHand(const char *name, Crypt crypt); @@ -132,12 +132,6 @@ public: bool exist(const char *name); }; -class Dat { -public: - Dat(); - CFile _file; -}; - class VFile : public IoBuf { private: long _begMark; @@ -153,7 +147,7 @@ public: long seek(long pos); }; -extern Dat *_dat; +extern CFile *_dat; extern BtFile *_cat; } // End of namespace CGE From 3715d6d444792fc93fe98df4f0274f0be846eed1 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 11 Sep 2011 14:15:32 +0200 Subject: [PATCH 273/276] CGE: Add EncryptedStream class, remove seed parameter from XCrypt() --- engines/cge/fileio.cpp | 25 ++++++++++++++++++++++++- engines/cge/fileio.h | 8 ++++++++ engines/cge/general.cpp | 6 +++--- engines/cge/general.h | 4 ++-- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/engines/cge/fileio.cpp b/engines/cge/fileio.cpp index 7624eac9364..87a1ffebacd 100644 --- a/engines/cge/fileio.cpp +++ b/engines/cge/fileio.cpp @@ -61,7 +61,7 @@ uint16 IoHand::read(void *buf, uint16 len) { if (!bytesRead) error("Read %s - %d bytes", _file->getName(), len); if (_crypt) - _seed = _crypt(buf, len, kCryptSeed); + _seed = _crypt(buf, len); return bytesRead; } @@ -378,4 +378,27 @@ long VFile::seek(long pos) { return (_bufMark = _begMark + pos); } +/*----------------------------------------------------------------------- + * EncryptedStream + *-----------------------------------------------------------------------*/ +EncryptedStream::EncryptedStream(const char *name) { + debugC(3, kCGEDebugFile, "EncryptedStream::EncryptedStream(%s)", name); + + _error = false; + if (_dat->_error || _cat->_error) + error("Bad volume data"); + BtKeypack *kp = _cat->find(name); + if (scumm_stricmp(kp->_key, name) != 0) + _error = true; + + _dat->_file->seek(kp->_mark); + byte *dataBuffer = (byte *)malloc(kp->_size); + _dat->_file->read(dataBuffer, kp->_size); + XCrypt(dataBuffer, kp->_size); + _readStream = new Common::MemoryReadStream(dataBuffer, kp->_size, DisposeAfterUse::YES); +} + +EncryptedStream::~EncryptedStream() { +} + } // End of namespace CGE diff --git a/engines/cge/fileio.h b/engines/cge/fileio.h index 65f0b953e7a..68b9a26d76d 100644 --- a/engines/cge/fileio.h +++ b/engines/cge/fileio.h @@ -147,6 +147,14 @@ public: long seek(long pos); }; +class EncryptedStream { +public: + bool _error; + EncryptedStream(const char *name); + ~EncryptedStream(); + Common::SeekableReadStream *_readStream; +}; + extern CFile *_dat; extern BtFile *_cat; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index c93cc1292b0..7db61818abb 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -31,13 +31,13 @@ namespace CGE { -uint16 XCrypt(void *buf, uint16 siz, uint16 seed) { +uint16 XCrypt(void *buf, uint16 siz) { byte *b = static_cast(buf); for (uint16 i = 0; i < siz; i++) - *b++ ^= seed; + *b++ ^= kCryptSeed; - return seed; + return kCryptSeed; } char *mergeExt(char *buf, const char *name, const char *ext) { diff --git a/engines/cge/general.h b/engines/cge/general.h index 8f997c9ae2f..1793594d077 100644 --- a/engines/cge/general.h +++ b/engines/cge/general.h @@ -45,9 +45,9 @@ struct Dac { uint8 _b; }; -typedef uint16 Crypt(void *buf, uint16 siz, uint16 seed); +typedef uint16 Crypt(void *buf, uint16 siz); -uint16 XCrypt(void *buf, uint16 siz, uint16 seed); +uint16 XCrypt(void *buf, uint16 siz); int takeEnum(const char **tab, const char *text); uint16 chkSum(void *m, uint16 n); char *mergeExt(char *buf, const char *name, const char *ext); From 08d87130aa31606bfb62ef8a574e161a30866225 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 11 Sep 2011 14:19:46 +0200 Subject: [PATCH 274/276] CGE: Use EncryptedStream in Text: rewrite caching, remove some methods. --- engines/cge/cge.cpp | 2 +- engines/cge/cge_main.cpp | 5 -- engines/cge/text.cpp | 148 ++++++++++++++------------------------- engines/cge/text.h | 9 ++- 4 files changed, 59 insertions(+), 105 deletions(-) diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index 1b9fcf64ed3..ade3071497a 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -91,7 +91,7 @@ void CGEEngine::init() { Cluster::init(this); // Initialise engine objects - _text = new Text(this, "CGE", 128); + _text = new Text(this, "CGE"); _vga = new Vga(); _sys = new System(this); _pocLight = new PocLight(this); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index b9033a81eee..d3c88845c2f 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -623,7 +623,6 @@ void CGEEngine::caveUp() { showBak(BakRef); loadMapping(); - _text->preload(BakRef, BakRef + 1000); Sprite *spr = _vga->_spareQ->first(); while (spr) { Sprite *n = spr->_next; @@ -689,8 +688,6 @@ void CGEEngine::caveDown() { } spr = n; } - - _text->clear(1000); } void CGEEngine::xCave() { @@ -1305,8 +1302,6 @@ void CGEEngine::runGame() { if (_eventManager->_quitFlag) return; - _text->clear(); - _text->preload(100, 1000); loadHeroXY(); _cavLight->_flags._tran = true; diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 25af8eccfce..7e574a00bcd 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -31,22 +31,26 @@ #include "cge/game.h" #include "cge/snail.h" #include "cge/cge_main.h" +#include "common/str.h" namespace CGE { Text *_text; Talk *_talk = NULL; -Text::Text(CGEEngine *vm, const char *fname, int size) : _vm(vm) { - _cache = new Handler[size]; +Text::Text(CGEEngine *vm, const char *fname) : _vm(vm) { mergeExt(_fileName, fname, kSayExt); if (!_cat->exist(_fileName)) error("No talk (%s)\n", _fileName); + int16 txtCount = count() + 1; + warning("Number of texts: %d", txtCount); - for (_size = 0; _size < size; _size++) { + _cache = new Handler[txtCount]; + for (_size = 0; _size < txtCount; _size++) { _cache[_size]._ref = 0; _cache[_size]._text = NULL; } + load(); } Text::~Text() { @@ -54,9 +58,33 @@ Text::~Text() { delete[] _cache; } -void Text::clear(int from, int upto) { +int16 Text::count() { + EncryptedStream tf = _fileName; + if (tf._error) + return NULL; + + Common::String line; + char tmpStr[kLineMax + 1]; + int n, count = 0; + + for (line = tf._readStream->readLine(); !tf._readStream->eos(); line = tf._readStream->readLine()) { + n = line.size(); + char *s; + + strcpy(tmpStr, line.c_str()); + if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL) + continue; + if (!isdigit(*s)) + continue; + + count++; + } + return count; +} + +void Text::clear() { for (Handler *p = _cache, *q = p + _size; p < q; p++) { - if (p->_ref && p->_ref >= from && p->_ref < upto) { + if (p->_ref) { p->_ref = 0; delete[] p->_text; p->_text = NULL; @@ -64,115 +92,47 @@ void Text::clear(int from, int upto) { } } -int Text::find(int ref) { - int i = 0; - for (Handler *p = _cache, *q = p + _size; p < q; p++) { - if (p->_ref == ref) - break; - else - i++; - } - return i; -} +void Text::load() { + EncryptedStream tf = _fileName; + assert(!tf._error); + Common::String line; + char tmpStr[kLineMax + 1]; + int idx; -void Text::preload(int from, int upto) { - VFile tf = _fileName; - if (tf._error) - return; - - Handler *CacheLim = _cache + _size; - char line[kLineMax + 1]; - int n; - - while ((n = tf.read((uint8 *)line)) != 0) { - if (line[n - 1] == '\n') - line[--n] = '\0'; - - char *s; - if ((s = strtok(line, " =,;/\t\n")) == NULL) - continue; - if (!isdigit(*s)) - continue; - - int ref = atoi(s); - if (ref && ref >= from && ref < upto) { - Handler *p = &_cache[find(ref)]; - - if (p < CacheLim) { - delete[] p->_text; - p->_text = NULL; - } else - p = &_cache[find(0)]; - - if (p >= CacheLim) - break; - - s += strlen(s); - if (s < line + n) - ++s; - if ((p->_text = new char[strlen(s) + 1]) == NULL) - break; - - p->_ref = ref; - strcpy(p->_text, s); - } - } -} - - -char *Text::load(int idx, int ref) { - VFile tf = _fileName; - if (tf._error) - return NULL; - - char line[kLineMax + 1]; - int n; - - while ((n = tf.read((uint8 *)line)) != 0) { + for (idx = 0, line = tf._readStream->readLine(); !tf._readStream->eos(); line = tf._readStream->readLine()) { + int n = line.size(); char *s; - if (line[n - 1] == '\n') - line[-- n] = '\0'; - if ((s = strtok(line, " =,;/\t\n")) == NULL) + strcpy(tmpStr, line.c_str()); + if ((s = strtok(tmpStr, " =,;/\t\n")) == NULL) continue; if (!isdigit(*s)) continue; int r = atoi(s); - if (r < ref) - continue; - if (r > ref) - break; - // (r == ref) s += strlen(s); - if (s < line + n) + if (s < tmpStr + n) ++s; - Handler *p = &_cache[idx]; - p->_ref = ref; - - if ((p->_text = new char[strlen(s) + 1]) == NULL) - return NULL; - return strcpy(p->_text, s); + _cache[idx]._ref = r; + _cache[idx]._text = new char[strlen(s) + 1]; + strcpy(_cache[idx]._text, s); + idx++; } - return NULL; } char *Text::getText(int ref) { int i; - if ((i = find(ref)) < _size) + for (i = 0; (i < _size) && (_cache[i]._ref != ref); i++) + ; + + if (i < _size) return _cache[i]._text; - if ((i = find(0)) >= _size) { - clear(kSysTextMax); // clear non-system - if ((i = find(0)) >= _size) { - clear(); // clear all - i = 0; - } - } - return load(i, ref); + warning("getText: Unable to find ref %d", ref); + return NULL; } void Text::say(const char *text, Sprite *spr) { diff --git a/engines/cge/text.h b/engines/cge/text.h index 30bb77faaed..668f307f724 100644 --- a/engines/cge/text.h +++ b/engines/cge/text.h @@ -48,13 +48,12 @@ class Text { } *_cache; int _size; char _fileName[kPathMax]; - char *load(int idx, int ref); - int find(int ref); + void load(); + int16 count(); public: - Text(CGEEngine *vm, const char *fname, int size); + Text(CGEEngine *vm, const char *fname); ~Text(); - void clear(int from = 1, int upto = 0x7FFF); - void preload(int from = 1, int upto = 0x7FFF); + void clear(); char *getText(int ref); void say(const char *text, Sprite *spr); void sayTime(Sprite *spr); From cdba3ac108940e141901f021da890e2ddbda70f0 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 11 Sep 2011 14:21:03 +0200 Subject: [PATCH 275/276] CGE: Remove noisy debug message --- engines/cge/talk.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 2d9c17c73d0..609a4727c91 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -61,7 +61,6 @@ void Font::load() { uint16 p = 0; for (uint16 i = 0; i < kPosSize; i++) { _pos[i] = p; - warning("Fonts 0x%X 0x%X", i, p); p += _wid[i]; } f.read(_map, p); From 3b9b89a78bf65db18bdc6d0c3a1268c892d3db2c Mon Sep 17 00:00:00 2001 From: Strangerke Date: Sun, 11 Sep 2011 15:07:56 +0200 Subject: [PATCH 276/276] CGE: Talk now uses EncryptedStream. Clean up of EncryptedStream --- engines/cge/fileio.cpp | 16 ++++++++++++++++ engines/cge/fileio.h | 9 +++++++-- engines/cge/talk.cpp | 28 +++++++++++++--------------- engines/cge/talk.h | 2 +- engines/cge/text.cpp | 8 ++++---- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/engines/cge/fileio.cpp b/engines/cge/fileio.cpp index 87a1ffebacd..34c7c6510f1 100644 --- a/engines/cge/fileio.cpp +++ b/engines/cge/fileio.cpp @@ -398,6 +398,22 @@ EncryptedStream::EncryptedStream(const char *name) { _readStream = new Common::MemoryReadStream(dataBuffer, kp->_size, DisposeAfterUse::YES); } +uint32 EncryptedStream::read(void *dataPtr, uint32 dataSize) { + return _readStream->read(dataPtr, dataSize); +} + +bool EncryptedStream::err() { + return (_error & _readStream->err()); +} + +bool EncryptedStream::eos() { + return _readStream->eos(); +} + +Common::String EncryptedStream::readLine() { + return _readStream->readLine(); +} + EncryptedStream::~EncryptedStream() { } diff --git a/engines/cge/fileio.h b/engines/cge/fileio.h index 68b9a26d76d..1f0756a2761 100644 --- a/engines/cge/fileio.h +++ b/engines/cge/fileio.h @@ -148,11 +148,16 @@ public: }; class EncryptedStream { -public: +private: + Common::SeekableReadStream *_readStream; bool _error; +public: EncryptedStream(const char *name); ~EncryptedStream(); - Common::SeekableReadStream *_readStream; + bool err(); + bool eos(); + uint32 read(void *dataPtr, uint32 dataSize); + Common::String readLine(); }; extern CFile *_dat; diff --git a/engines/cge/talk.cpp b/engines/cge/talk.cpp index 609a4727c91..8fd425d3289 100644 --- a/engines/cge/talk.cpp +++ b/engines/cge/talk.cpp @@ -36,9 +36,9 @@ namespace CGE { Font::Font(const char *name) { _map = (uint8 *)malloc(kMapSize); _pos = (uint16 *)malloc(kPosSize * sizeof(uint16)); - _wid = (uint8 *)malloc(kWidSize); + _widthArr = (uint8 *)malloc(kWidSize); - assert((_map != NULL) && (_pos != NULL) && (_wid != NULL)); + assert((_map != NULL) && (_pos != NULL) && (_widthArr != NULL)); mergeExt(_path, name, kFontExt); load(); } @@ -46,22 +46,20 @@ Font::Font(const char *name) { Font::~Font() { free(_map); free(_pos); - free(_wid); + free(_widthArr); } void Font::load() { - VFile f(_path); - if (f._error) - return; + EncryptedStream f = _path; + assert(!f.err()); - f.read(_wid, kWidSize); - if (f._error) - return; + f.read(_widthArr, kWidSize); + assert(!f.err()); uint16 p = 0; for (uint16 i = 0; i < kPosSize; i++) { _pos[i] = p; - p += _wid[i]; + p += _widthArr[i]; } f.read(_map, p); } @@ -71,7 +69,7 @@ uint16 Font::width(const char *text) { if (!text) return 0; while (*text) - w += _wid[(unsigned char)*(text++)]; + w += _widthArr[(unsigned char)*(text++)]; return w; } @@ -116,7 +114,7 @@ void Talk::update(const char *text) { mw = k; k = 2 * hmarg; } else - k += _font->_wid[(unsigned char)*p]; + k += _font->_widthArr[(unsigned char)*p]; } if (k > mw) mw = k; @@ -132,7 +130,7 @@ void Talk::update(const char *text) { if (*text == '|' || *text == '\n') { m = _ts[0]->_m + (ln += kFontHigh + kTextLineSpace) * mw + hmarg; } else { - int cw = _font->_wid[(unsigned char)*text]; + int cw = _font->_widthArr[(unsigned char)*text]; uint8 *f = _font->_map + _font->_pos[(unsigned char)*text]; for (int i = 0; i < cw; i++) { uint8 *pp = m; @@ -223,7 +221,7 @@ void Talk::putLine(int line, const char *text) { uint8 *q = v + size; while (*text) { - uint16 cw = _font->_wid[(unsigned char)*text], i; + uint16 cw = _font->_widthArr[(unsigned char)*text], i; uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; for (i = 0; i < cw; i++) { @@ -280,7 +278,7 @@ void InfoLine::update(const char *text) { uint8 *p = v + 2, * q = p + size; while (*text) { - uint16 cw = _font->_wid[(unsigned char)*text]; + uint16 cw = _font->_widthArr[(unsigned char)*text]; uint8 *fp = _font->_map + _font->_pos[(unsigned char)*text]; for (uint16 i = 0; i < cw; i++) { diff --git a/engines/cge/talk.h b/engines/cge/talk.h index 6b06e8009c2..23ef9c9c077 100644 --- a/engines/cge/talk.h +++ b/engines/cge/talk.h @@ -52,7 +52,7 @@ class Font { char _path[kPathMax]; void load(); public: - uint8 *_wid; + uint8 *_widthArr; uint16 *_pos; uint8 *_map; Font(const char *name); diff --git a/engines/cge/text.cpp b/engines/cge/text.cpp index 7e574a00bcd..71bb411f11f 100644 --- a/engines/cge/text.cpp +++ b/engines/cge/text.cpp @@ -60,14 +60,14 @@ Text::~Text() { int16 Text::count() { EncryptedStream tf = _fileName; - if (tf._error) + if (tf.err()) return NULL; Common::String line; char tmpStr[kLineMax + 1]; int n, count = 0; - for (line = tf._readStream->readLine(); !tf._readStream->eos(); line = tf._readStream->readLine()) { + for (line = tf.readLine(); !tf.eos(); line = tf.readLine()) { n = line.size(); char *s; @@ -94,13 +94,13 @@ void Text::clear() { void Text::load() { EncryptedStream tf = _fileName; - assert(!tf._error); + assert(!tf.err()); Common::String line; char tmpStr[kLineMax + 1]; int idx; - for (idx = 0, line = tf._readStream->readLine(); !tf._readStream->eos(); line = tf._readStream->readLine()) { + for (idx = 0, line = tf.readLine(); !tf.eos(); line = tf.readLine()) { int n = line.size(); char *s;