diff --git a/engines/hopkins/anim.cpp b/engines/hopkins/anim.cpp index afaf37253c3..7622302fc38 100644 --- a/engines/hopkins/anim.cpp +++ b/engines/hopkins/anim.cpp @@ -273,9 +273,9 @@ void AnimationManager::PLAY_ANM2(const Common::String &filename, uint32 a2, uint memcpy(_vm->_graphicsManager.OLD_PAL, _vm->_graphicsManager.Palette, 0x301u); _vm->_fileManager.CONSTRUIT_LINUX("TEMP.SCR"); if (_vm->_graphicsManager.nbrligne == SCREEN_WIDTH) - _vm->_fileManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x4B000u); + _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x4B000u); if (_vm->_graphicsManager.nbrligne == 1280) - _vm->_fileManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x96000u); + _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x96000u); if (!_vm->_graphicsManager.nbrligne) _vm->_graphicsManager.ofscroll = 0; v12 = _vm->_graphicsManager.VESA_SCREEN; @@ -972,9 +972,9 @@ void AnimationManager::PLAY_SEQ(int a1, const Common::String &a2, uint32 a3, uin _vm->_eventsManager.VBL(); _vm->_fileManager.CONSTRUIT_LINUX("TEMP.SCR"); if (_vm->_graphicsManager.nbrligne == SCREEN_WIDTH) - _vm->_fileManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x4B000u); + _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x4B000u); if (_vm->_graphicsManager.nbrligne == (SCREEN_WIDTH * 2)) - _vm->_fileManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x96000u); + _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x96000u); if (!_vm->_graphicsManager.nbrligne) _vm->_graphicsManager.ofscroll = 0; } diff --git a/engines/hopkins/files.cpp b/engines/hopkins/files.cpp index 151a9a84f81..79b672ca33a 100644 --- a/engines/hopkins/files.cpp +++ b/engines/hopkins/files.cpp @@ -38,32 +38,6 @@ void FileManager::setParent(HopkinsEngine *vm) { _vm = vm; } -void FileManager::initSaves() { - Common::String dataFilename = "HISCORE.DAT"; - byte data[100]; - Common::fill(&data[0], &data[100], 0); - - SAUVE_FICHIER(dataFilename, data, 100); -} - -// Save File -bool FileManager::SAUVE_FICHIER(const Common::String &file, const void *buf, size_t n) { - return bsave(file, buf, n); -} - -bool FileManager::bsave(const Common::String &file, const void *buf, size_t n) { - Common::OutSaveFile *f = g_system->getSavefileManager()->openForSaving(file); - - if (f) { - size_t bytesWritten = f->write(buf, n); - f->finalize(); - delete f; - - return bytesWritten == n; - } else - return false; -} - // Load INI File void FileManager::Chage_Inifile(Common::StringMap &iniParams) { // TODO: Review whether we can do something cleaner with ScummVM initialisation than @@ -342,6 +316,7 @@ uint32 FileManager::FLONG(const Common::String &filename) { // Build Linux Common::String FileManager::CONSTRUIT_LINUX(const Common::String &file) { + _vm->_globals.NFICHIER = file; return file; } diff --git a/engines/hopkins/files.h b/engines/hopkins/files.h index 9aece5fba32..d9df4341ca6 100644 --- a/engines/hopkins/files.h +++ b/engines/hopkins/files.h @@ -39,9 +39,6 @@ public: FileManager(); void setParent(HopkinsEngine *vm); - void initSaves(); - bool SAUVE_FICHIER(const Common::String &file, const void *buf, size_t n); - bool bsave(const Common::String &file, const void *buf, size_t n); void Chage_Inifile(Common::StringMap &iniParams); byte *CHARGE_FICHIER(const Common::String &file); void CHARGE_FICHIER2(const Common::String &file, byte *a2); diff --git a/engines/hopkins/hopkins.cpp b/engines/hopkins/hopkins.cpp index 08f4b9f874d..97271313f6f 100644 --- a/engines/hopkins/hopkins.cpp +++ b/engines/hopkins/hopkins.cpp @@ -28,6 +28,7 @@ #include "hopkins/graphics.h" #include "hopkins/hopkins.h" #include "hopkins/files.h" +#include "hopkins/saveload.h" #include "hopkins/sound.h" #include "hopkins/talk.h" @@ -49,6 +50,7 @@ HopkinsEngine::HopkinsEngine(OSystem *syst, const HopkinsGameDescription *gameDe _linesManager.setParent(this); _menuManager.setParent(this); _objectsManager.setParent(this); + _saveLoadManager.setParent(this); _scriptManager.setParent(this); _soundManager.setParent(this); _talkManager.setParent(this); @@ -58,7 +60,7 @@ HopkinsEngine::~HopkinsEngine() { } Common::Error HopkinsEngine::run() { - _fileManager.initSaves(); + _saveLoadManager.initSaves(); Common::StringMap iniParams; _fileManager.Chage_Inifile(iniParams); diff --git a/engines/hopkins/hopkins.h b/engines/hopkins/hopkins.h index 0b6818d8cdb..6a0eb2e5cd3 100644 --- a/engines/hopkins/hopkins.h +++ b/engines/hopkins/hopkins.h @@ -42,6 +42,7 @@ #include "hopkins/lines.h" #include "hopkins/menu.h" #include "hopkins/objects.h" +#include "hopkins/saveload.h" #include "hopkins/script.h" #include "hopkins/sound.h" #include "hopkins/talk.h" @@ -107,6 +108,7 @@ public: LinesManager _linesManager; MenuManager _menuManager; ObjectsManager _objectsManager; + SaveLoadManager _saveLoadManager; ScriptManager _scriptManager; SoundManager _soundManager; TalkManager _talkManager; diff --git a/engines/hopkins/menu.cpp b/engines/hopkins/menu.cpp index 58616e59d8a..1de66a103c8 100644 --- a/engines/hopkins/menu.cpp +++ b/engines/hopkins/menu.cpp @@ -353,14 +353,14 @@ void MenuManager::SAUVE_PARTIE() { } while (v4 <= 34); _vm->_fileManager.CONSTRUIT_LINUX(v7); - _vm->_fileManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, &_vm->_globals.SAUVEGARDE->data[0], 0x7D0u); + _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, &_vm->_globals.SAUVEGARDE->data[0], 0x7D0u); v12 = 46; v13 = 69; v14 = 67; v15 = 82; v16 = 0; _vm->_fileManager.CONSTRUIT_LINUX(v7); - _vm->_fileManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, v1, 0x2B80u); + _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, v1, 0x2B80u); } _vm->_globals.dos_free2(v1); } diff --git a/engines/hopkins/module.mk b/engines/hopkins/module.mk index dbed88c6685..109104f2292 100644 --- a/engines/hopkins/module.mk +++ b/engines/hopkins/module.mk @@ -14,6 +14,7 @@ MODULE_OBJS := \ lines.o \ menu.o \ objects.o \ + saveload.o \ script.o \ sound.o \ talk.o diff --git a/engines/hopkins/objects.cpp b/engines/hopkins/objects.cpp index c94544f5aee..e60d72ba68f 100644 --- a/engines/hopkins/objects.cpp +++ b/engines/hopkins/objects.cpp @@ -4301,7 +4301,7 @@ void ObjectsManager::SPECIAL_JEU() { v1 = _vm->_globals.dos_malloc2(0x3E8u); memcpy(v1, _vm->_graphicsManager.Palette, 0x301u); _vm->_fileManager.CONSTRUIT_LINUX("TEMP1.SCR"); - _vm->_fileManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x4B000u); + _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x4B000u); if (!_vm->_graphicsManager.nbrligne) _vm->_graphicsManager.ofscroll = 0; _vm->_graphicsManager.NB_SCREEN(); diff --git a/engines/hopkins/saveload.cpp b/engines/hopkins/saveload.cpp new file mode 100644 index 00000000000..ed4e3f15969 --- /dev/null +++ b/engines/hopkins/saveload.cpp @@ -0,0 +1,61 @@ +/* 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/system.h" +#include "common/savefile.h" +#include "hopkins/saveload.h" +#include "hopkins/files.h" +#include "hopkins/globals.h" + +namespace Hopkins { + +void SaveLoadManager::setParent(HopkinsEngine *vm) { + _vm = vm; +} + +bool SaveLoadManager::bsave(const Common::String &file, const void *buf, size_t n) { + Common::OutSaveFile *f = g_system->getSavefileManager()->openForSaving(file); + + if (f) { + size_t bytesWritten = f->write(buf, n); + f->finalize(); + delete f; + + return bytesWritten == n; + } else + return false; +} + +// Save File +bool SaveLoadManager::SAUVE_FICHIER(const Common::String &file, const void *buf, size_t n) { + return bsave(file, buf, n); +} + +void SaveLoadManager::initSaves() { + Common::String dataFilename = "HISCORE.DAT"; + byte data[100]; + Common::fill(&data[0], &data[100], 0); + + SAUVE_FICHIER(dataFilename, data, 100); +} + +} // End of namespace Hopkins diff --git a/engines/hopkins/saveload.h b/engines/hopkins/saveload.h new file mode 100644 index 00000000000..d35d5297490 --- /dev/null +++ b/engines/hopkins/saveload.h @@ -0,0 +1,46 @@ +/* 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 HOPKINS_SAVELOAD_H +#define HOPKINS_SAVELOAD_H + +#include "common/scummsys.h" +#include "common/str.h" + +namespace Hopkins { + +class HopkinsEngine; + +class SaveLoadManager { +private: + HopkinsEngine *_vm; +public: + void setParent(HopkinsEngine *vm); + + void initSaves(); + bool bsave(const Common::String &file, const void *buf, size_t n); + bool SAUVE_FICHIER(const Common::String &file, const void *buf, size_t n); +}; + +} // End of namespace Hopkins + +#endif /* HOPKINS_SAVELOAD_H */ diff --git a/engines/hopkins/talk.cpp b/engines/hopkins/talk.cpp index b010afd6eb5..1630ce60137 100644 --- a/engines/hopkins/talk.cpp +++ b/engines/hopkins/talk.cpp @@ -91,11 +91,13 @@ void TalkManager::PARLER_PERSO(const Common::String &filename) { } PERSOSPR = _vm->_objectsManager.CHARGE_SPRITE(_vm->_globals.NFICHIER); _vm->_globals.CAT_FLAG = 0; + _vm->_fileManager.CONSTRUIT_LINUX("TEMP.SCR"); - if (_vm->_graphicsManager.nbrligne == 640) - _vm->_fileManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x4B000u); - if (_vm->_graphicsManager.nbrligne == 1280) - _vm->_fileManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x96000u); + if (_vm->_graphicsManager.nbrligne == SCREEN_WIDTH) + _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x4B000u); + if (_vm->_graphicsManager.nbrligne == (SCREEN_WIDTH * 2)) + _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x96000u); + if (!_vm->_graphicsManager.nbrligne) _vm->_graphicsManager.ofscroll = 0; _vm->_graphicsManager.NB_SCREEN(); @@ -1214,9 +1216,9 @@ void TalkManager::OBJET_VIVANT(const Common::String &a2) { _vm->_globals.CAT_FLAG = 0; _vm->_fileManager.CONSTRUIT_LINUX("TEMP.SCR"); if (_vm->_graphicsManager.nbrligne == SCREEN_WIDTH) - _vm->_fileManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x4B000u); + _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x4B000u); if (_vm->_graphicsManager.nbrligne == (SCREEN_WIDTH * 2)) - _vm->_fileManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x96000u); + _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, _vm->_graphicsManager.VESA_SCREEN, 0x96000u); if (!_vm->_graphicsManager.nbrligne) _vm->_graphicsManager.ofscroll = 0; _vm->_graphicsManager.NB_SCREEN();