From eece86d78e6821638772da0a5198e690c0f08745 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Wed, 12 Dec 2012 08:05:04 +0100 Subject: HOPKINS: Homogenization of memory management --- engines/hopkins/anim.cpp | 79 +++++++++++++++++++++----------------------- engines/hopkins/computer.cpp | 30 ++++++++--------- engines/hopkins/dialogs.cpp | 27 ++++++++------- engines/hopkins/events.cpp | 4 +-- engines/hopkins/files.cpp | 8 ++--- engines/hopkins/font.cpp | 33 ++++++++---------- engines/hopkins/globals.cpp | 64 +++++++++++++++-------------------- engines/hopkins/globals.h | 5 ++- engines/hopkins/graphics.cpp | 20 +++++------ engines/hopkins/hopkins.cpp | 22 ++++++------ engines/hopkins/lines.cpp | 19 ++++------- engines/hopkins/menu.cpp | 2 +- engines/hopkins/objects.cpp | 69 ++++++++++++++------------------------ engines/hopkins/talk.cpp | 27 +++++++-------- 14 files changed, 176 insertions(+), 233 deletions(-) diff --git a/engines/hopkins/anim.cpp b/engines/hopkins/anim.cpp index 1558069e6b..80e1bdb19b 100644 --- a/engines/hopkins/anim.cpp +++ b/engines/hopkins/anim.cpp @@ -61,7 +61,7 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui hasScreenCopy = false; screenP = _vm->_graphicsManager.VESA_SCREEN; - ptr = _vm->_globals.dos_malloc2(0x14u); + ptr = _vm->_globals.allocMemory(0x14u); _vm->_fileManager.constructFilename(_vm->_globals.HOPANM, filename); if (!f.open(_vm->_globals.NFICHIER)) @@ -81,7 +81,7 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui } if (_vm->_graphicsManager.WinScan / _vm->_graphicsManager.Winbpp > SCREEN_WIDTH) { hasScreenCopy = true; - screenCopy = _vm->_globals.dos_malloc2(0x4B000u); + screenCopy = _vm->_globals.allocMemory(0x4B000u); memcpy(screenCopy, screenP, 0x4B000u); } if (NO_SEQ) { @@ -184,7 +184,7 @@ void AnimationManager::playAnim(const Common::String &filename, uint32 rate1, ui _vm->_soundManager.VERIF_SOUND(); EXIT: if (_vm->_graphicsManager.FADE_LINUX == 2 && !hasScreenCopy) { - screenCopy = _vm->_globals.dos_malloc2(0x4B000u); + screenCopy = _vm->_globals.allocMemory(0x4B000u); f.seek(0); f.skip(6); @@ -212,17 +212,17 @@ EXIT: } } while (breakFlag); _vm->_graphicsManager.FADE_OUTW_LINUX(screenCopy); - screenCopy = _vm->_globals.dos_free2(screenCopy); + screenCopy = _vm->_globals.freeMemory(screenCopy); } if (hasScreenCopy) { if (_vm->_graphicsManager.FADE_LINUX == 2) _vm->_graphicsManager.FADE_OUTW_LINUX(screenCopy); - _vm->_globals.dos_free2(screenCopy); + screenCopy = _vm->_globals.freeMemory(screenCopy); } _vm->_graphicsManager.FADE_LINUX = 0; f.close(); - _vm->_globals.dos_free2(ptr); + ptr = _vm->_globals.freeMemory(ptr); _vm->_graphicsManager.NOLOCK = false; } @@ -258,7 +258,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 a2, uint _vm->_graphicsManager.ofscroll = 0; v12 = _vm->_graphicsManager.VESA_SCREEN; - v13 = _vm->_globals.dos_malloc2(0x14u); + v13 = _vm->_globals.allocMemory(0x14u); _vm->_fileManager.constructFilename(_vm->_globals.HOPANM, filename); if (!f.open(_vm->_globals.NFICHIER)) @@ -287,7 +287,7 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 a2, uint _vm->_graphicsManager.max_x = SCREEN_WIDTH; if (_vm->_graphicsManager.WinScan / _vm->_graphicsManager.Winbpp > SCREEN_WIDTH) { v8 = 1; - ptr = _vm->_globals.dos_malloc2(0x4B000u); + ptr = _vm->_globals.allocMemory(0x4B000u); memcpy(ptr, v12, 0x4B000u); } if (_vm->_animationManager.NO_SEQ) { @@ -329,8 +329,8 @@ void AnimationManager::playAnim2(const Common::String &filename, uint32 a2, uint if (_vm->_graphicsManager.NOLOCK == true) goto LABEL_114; if (v8 == 1) - ptr = _vm->_globals.dos_free2(ptr); - _vm->_globals.dos_free2(v13); + ptr = _vm->_globals.freeMemory(ptr); + _vm->_globals.freeMemory(v13); f.close(); _vm->_saveLoadManager.bload("TEMP.SCR", _vm->_graphicsManager.VESA_SCREEN); @@ -432,8 +432,8 @@ LABEL_88: if (_vm->_graphicsManager.NOLOCK == true) goto LABEL_114; if (v8 == 1) - ptr = _vm->_globals.dos_free2(ptr); - _vm->_globals.dos_free2(v13); + ptr = _vm->_globals.freeMemory(ptr); + _vm->_globals.freeMemory(v13); f.close(); _vm->_saveLoadManager.bload("TEMP.SCR", _vm->_graphicsManager.VESA_SCREEN); @@ -495,8 +495,8 @@ LABEL_88: if (_vm->_graphicsManager.NOLOCK == true) break; if (v8 == 1) - ptr = _vm->_globals.dos_free2(ptr); - _vm->_globals.dos_free2(v13); + ptr = _vm->_globals.freeMemory(ptr); + _vm->_globals.freeMemory(v13); f.close(); _vm->_saveLoadManager.bload("TEMP.SCR", _vm->_graphicsManager.VESA_SCREEN); @@ -555,7 +555,7 @@ LABEL_114: if (_vm->_graphicsManager.FADE_LINUX == 2 && !v8) { byte *ptra; - ptra = _vm->_globals.dos_malloc2(0x4B000u); + ptra = _vm->_globals.allocMemory(0x4B000u); f.seek(0); f.read(&buf, 6); @@ -589,15 +589,15 @@ LABEL_114: } } while (v6 != -1); _vm->_graphicsManager.FADE_OUTW_LINUX(ptra); - ptr = _vm->_globals.dos_free2(ptra); + ptra = _vm->_globals.freeMemory(ptra); } if (v8 == 1) { if (_vm->_graphicsManager.FADE_LINUX == 2) _vm->_graphicsManager.FADE_OUTW_LINUX(ptr); - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); } _vm->_graphicsManager.FADE_LINUX = 0; - _vm->_globals.dos_free2(v13); + _vm->_globals.freeMemory(v13); _vm->_saveLoadManager.bload("TEMP.SCR", _vm->_graphicsManager.VESA_SCREEN); g_system->getSavefileManager()->removeSavefile("TEMP.SCR"); @@ -702,7 +702,7 @@ void AnimationManager::loadAnim(const Common::String &animName) { } } - byte *data = _vm->_globals.dos_malloc2(nbytes + 1); + byte *data = _vm->_globals.allocMemory(nbytes + 1); f.read(data, nbytes); f.close(); @@ -710,7 +710,7 @@ void AnimationManager::loadAnim(const Common::String &animName) { searchAnim(data, idx, nbytes); } - _vm->_globals.dos_free2(data); + _vm->_globals.freeMemory(data); } /** @@ -718,14 +718,12 @@ void AnimationManager::loadAnim(const Common::String &animName) { */ void AnimationManager::clearAnim() { for (int idx = 0; idx < 35; ++idx) { - if (_vm->_globals.Bqe_Anim[idx].data != g_PTRNUL) - _vm->_globals.Bqe_Anim[idx].data = _vm->_globals.dos_free2(_vm->_globals.Bqe_Anim[idx].data); + _vm->_globals.Bqe_Anim[idx].data = _vm->_globals.freeMemory(_vm->_globals.Bqe_Anim[idx].data); _vm->_globals.Bqe_Anim[idx].field4 = 0; } for (int idx = 0; idx < 8; ++idx) { - if (_vm->_globals.Bank[idx].data != g_PTRNUL) - _vm->_globals.Bank[idx].data = _vm->_globals.dos_free2(_vm->_globals.Bank[idx].data); + _vm->_globals.Bank[idx].data = _vm->_globals.freeMemory(_vm->_globals.Bank[idx].data); _vm->_globals.Bank[idx].field4 = 0; _vm->_globals.Bank[idx].filename1 = ""; _vm->_globals.Bank[idx].fileHeader = 0; @@ -809,17 +807,17 @@ int AnimationManager::loadSpriteBank(int idx, const Common::String &filename) { } } - _vm->_globals.dos_free2(v19); + _vm->_globals.freeMemory(v19); } result = 0; } else { - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); _vm->_globals.Bank[idx].field4 = 0; result = -2; } } else { - _vm->_globals.dos_free2(v3); + _vm->_globals.freeMemory(v3); _vm->_globals.Bank[idx].field4 = 0; result = -1; } @@ -877,7 +875,7 @@ void AnimationManager::searchAnim(const byte *data, int animIndex, int count) { ++v7; ++v5; } while (v8 != 1); - _vm->_globals.Bqe_Anim[v19].data = _vm->_globals.dos_malloc2(v7 + 50); + _vm->_globals.Bqe_Anim[v19].data = _vm->_globals.allocMemory(v7 + 50); _vm->_globals.Bqe_Anim[animIndex].field4 = 1; memcpy(_vm->_globals.Bqe_Anim[v19].data, v21 + data + 5, 0x14u); @@ -953,7 +951,7 @@ void AnimationManager::playSequence(const Common::String &file, uint32 rate1, ui _vm->_graphicsManager.ofscroll = 0; } v9 = _vm->_graphicsManager.VESA_SCREEN; - v10 = _vm->_globals.dos_malloc2(0x16u); + v10 = _vm->_globals.allocMemory(0x16u); _vm->_fileManager.constructFilename(_vm->_globals.HOPSEQ, file); if (!f.open(_vm->_globals.NFICHIER)) error("Error opening file - %s", _vm->_globals.NFICHIER.c_str()); @@ -967,7 +965,7 @@ void AnimationManager::playSequence(const Common::String &file, uint32 rate1, ui if (_vm->_graphicsManager.WinScan / _vm->_graphicsManager.Winbpp > SCREEN_WIDTH) { v7 = 1; - ptr = _vm->_globals.dos_malloc2(0x4B000u); + ptr = _vm->_globals.allocMemory(0x4B000u); memcpy(ptr, v9, 0x4B000u); } if (_vm->_animationManager.NO_SEQ) { @@ -1100,8 +1098,8 @@ LABEL_59: _vm->_eventsManager._mouseFl = true; } if (v7 == 1) - _vm->_globals.dos_free2(ptr); - _vm->_globals.dos_free2(v10); + _vm->_globals.freeMemory(ptr); + _vm->_globals.freeMemory(v10); } /** @@ -1124,7 +1122,7 @@ void AnimationManager::playSequence2(const Common::String &file, uint32 rate1, u _vm->_eventsManager._mouseFl = false; v10 = _vm->_graphicsManager.VESA_SCREEN; - v11 = _vm->_globals.dos_malloc2(0x16u); + v11 = _vm->_globals.allocMemory(0x16u); _vm->_fileManager.constructFilename(_vm->_globals.HOPSEQ, file); if (!f.open(_vm->_globals.NFICHIER)) @@ -1144,7 +1142,7 @@ void AnimationManager::playSequence2(const Common::String &file, uint32 rate1, u if (_vm->_graphicsManager.WinScan / _vm->_graphicsManager.Winbpp > SCREEN_WIDTH) { v7 = 1; - ptr = _vm->_globals.dos_malloc2(0x4B000u); + ptr = _vm->_globals.allocMemory(0x4B000u); memcpy((void *)ptr, v10, 0x4B000u); } if (_vm->_animationManager.NO_SEQ) { @@ -1190,8 +1188,8 @@ LABEL_48: if (_vm->_graphicsManager.NOLOCK == true) goto LABEL_54; if (v7 == 1) - ptr = _vm->_globals.dos_free2(ptr); - _vm->_globals.dos_free2(v11); + ptr = _vm->_globals.freeMemory(ptr); + _vm->_globals.freeMemory(v11); f.close(); } LABEL_23: @@ -1259,8 +1257,7 @@ LABEL_53: } LABEL_54: if (_vm->_graphicsManager.FADE_LINUX == 2 && !v7) { - byte *ptra; - ptra = _vm->_globals.dos_malloc2(0x4B000u); + byte *ptra = _vm->_globals.allocMemory(0x4B000u); f.seek(0); f.skip(6); @@ -1293,17 +1290,17 @@ LABEL_54: } } while (!v5); _vm->_graphicsManager.FADE_OUTW_LINUX(ptra); - ptr = _vm->_globals.dos_free2(ptra); + ptra = _vm->_globals.freeMemory(ptra); } if (v7 == 1) { if (_vm->_graphicsManager.FADE_LINUX == 2) _vm->_graphicsManager.FADE_OUTW_LINUX(ptr); - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); } _vm->_graphicsManager.FADE_LINUX = 0; f.close(); - _vm->_globals.dos_free2(v11); + _vm->_globals.freeMemory(v11); _vm->_eventsManager._mouseFl = true; } diff --git a/engines/hopkins/computer.cpp b/engines/hopkins/computer.cpp index 6dc7f1e6ac..e2c1ada8ef 100644 --- a/engines/hopkins/computer.cpp +++ b/engines/hopkins/computer.cpp @@ -78,7 +78,7 @@ void ComputerManager::setTextMode() { _vm->_graphicsManager.nbrligne = SCREEN_WIDTH; _vm->_fileManager.constructFilename(_vm->_globals.HOPSYSTEM, "STFONT.SPR"); - _vm->_globals.police = _vm->_globals.dos_free2(_vm->_globals.police); + _vm->_globals.police = _vm->_globals.freeMemory(_vm->_globals.police); _vm->_globals.police = _vm->_fileManager.loadFile(_vm->_globals.NFICHIER); _vm->_globals.police_l = 8; _vm->_globals.police_h = 8; @@ -348,7 +348,7 @@ void ComputerManager::loadMenu() { LABEL_13: tmpPtr = tmpPtr + 1; } while (!loopCond); - _vm->_globals.dos_free2(ptr); + ptr = _vm->_globals.freeMemory(ptr); } void ComputerManager::TXT4(int xp, int yp, int textIdx) { @@ -497,7 +497,7 @@ void ComputerManager::outText2(const Common::String &msg) { * Restores the scene for the FBI headquarters room */ void ComputerManager::restoreFBIRoom() { - _vm->_globals.police = _vm->_globals.dos_free2(_vm->_globals.police); + _vm->_globals.police = _vm->_globals.freeMemory(_vm->_globals.police); _vm->_fileManager.constructFilename(_vm->_globals.HOPSYSTEM, "FONTE3.SPR"); _vm->_globals.police = _vm->_fileManager.loadFile(_vm->_globals.NFICHIER); @@ -582,7 +582,7 @@ void ComputerManager::readText(int idx) { } while (v4 != 37); _vm->_eventsManager.waitKeyPress(); - _vm->_globals.dos_free2(ptr); + ptr = _vm->_globals.freeMemory(ptr); } /** @@ -618,9 +618,8 @@ void ComputerManager::displayGamesSubMenu() { _vm->_graphicsManager.RESET_SEGMENT_VESA(); playBreakout(); _vm->_graphicsManager.RESET_SEGMENT_VESA(); - _breakoutSpr = _vm->_globals.LIBERE_FICHIER(_breakoutSpr); - _vm->_globals.dos_free2((byte *)_breakoutLevel); - _breakoutLevel = (int16 *)g_PTRNUL; + _breakoutSpr = _vm->_globals.freeMemory(_breakoutSpr); + _breakoutLevel = (int16 *)_vm->_globals.freeMemory((byte *)_breakoutLevel); _vm->_objectsManager.Sprite[0].spriteData = v1; _vm->_soundManager.DEL_SAMPLE(1); @@ -644,7 +643,7 @@ void ComputerManager::loadHiscore() { byte *ptr; _vm->_fileManager.constructLinuxFilename("HISCORE.DAT"); - ptr = _vm->_globals.dos_malloc2(100); + ptr = _vm->_globals.allocMemory(100); _vm->_saveLoadManager.bload(_vm->_globals.NFICHIER, ptr); for (int scoreIndex = 0; scoreIndex < 6; ++scoreIndex) { @@ -663,7 +662,7 @@ void ComputerManager::loadHiscore() { } } - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); _breakoutHiscore = atol(_score[5]._score.c_str()); } @@ -692,10 +691,7 @@ void ComputerManager::newLevel() { _breakoutLives = 11; _vm->_graphicsManager.LOAD_IMAGEVGA("CASSEF.PCX"); displayLives(); - if (_breakoutLevel != (int16 *)g_PTRNUL) { - _vm->_globals.dos_free2((byte *)_breakoutLevel); - _breakoutLevel = (int16 *)g_PTRNUL; - } + _breakoutLevel = (int16 *)_vm->_globals.freeMemory((byte *)_breakoutLevel); ++_breakoutLevelNbr; while (!_vm->shouldQuit()) { @@ -929,7 +925,7 @@ int ComputerManager::displayHiscores() { _vm->_eventsManager.mouseOff(); _vm->_graphicsManager.FADE_OUT_CASSE(); - _vm->_globals.LIBERE_FICHIER(ptr); + _vm->_globals.freeMemory(ptr); return buttonIndex; } @@ -978,7 +974,7 @@ void ComputerManager::getScoreName() { break; } _vm->_graphicsManager.FADE_OUT_CASSE(); - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); saveScore(); } @@ -1081,7 +1077,7 @@ void ComputerManager::saveScore() { } while (!v3); } - ptr = _vm->_globals.dos_malloc2(0x64u); + ptr = _vm->_globals.allocMemory(0x64u); memset(ptr, 0, 0x63u); for (int v5 = 0; v5 <= 5; v5++) { v6 = 16 * v5; @@ -1107,7 +1103,7 @@ void ComputerManager::saveScore() { _vm->_fileManager.constructLinuxFilename("HISCORE.DAT"); _vm->_saveLoadManager.SAUVE_FICHIER(_vm->_globals.NFICHIER, ptr, 0x64u); - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); } /** diff --git a/engines/hopkins/dialogs.cpp b/engines/hopkins/dialogs.cpp index 0c72005894..4072126508 100644 --- a/engines/hopkins/dialogs.cpp +++ b/engines/hopkins/dialogs.cpp @@ -46,7 +46,7 @@ DialogsManager::DialogsManager() { } DialogsManager::~DialogsManager() { - _vm->_globals.dos_free2(_inventWin1); + _vm->_globals.freeMemory(_inventWin1); } void DialogsManager::setParent(HopkinsEngine *vm) { @@ -297,7 +297,7 @@ void DialogsManager::showOptionsDialog() { _vm->_graphicsManager.Ajoute_Segment_Vesa(_vm->_graphicsManager.ofscroll + 164, 107, _vm->_graphicsManager.ofscroll + 498, 320); - _vm->_globals.OPTION_SPR = _vm->_globals.dos_free2(_vm->_globals.OPTION_SPR); + _vm->_globals.OPTION_SPR = _vm->_globals.freeMemory(_vm->_globals.OPTION_SPR); _vm->_globals._optionDialogFl = false; } @@ -337,7 +337,7 @@ LABEL_7: error("Error opening file - %s", _vm->_globals.NFICHIER.c_str()); size_t filesize = f.size(); - _vm->_dialogsManager._inventWin1 = _vm->_globals.dos_malloc2(filesize); + _vm->_dialogsManager._inventWin1 = _vm->_globals.allocMemory(filesize); _vm->_fileManager.readStream(f, _vm->_dialogsManager._inventWin1, filesize); f.close(); @@ -362,7 +362,7 @@ LABEL_7: byte *v7 = _vm->_objectsManager.CAPTURE_OBJET(v6, 0); _vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, v7, v19 + v16 + 6, v15 + 120, _vm->_globals.OBJL, _vm->_globals.OBJH); - _vm->_globals.dos_free2(v7); + _vm->_globals.freeMemory(v7); } v16 += 54; }; @@ -423,9 +423,8 @@ LABEL_7: v20 = true; _vm->_globals.SORTIE = 0; if (!v20) { - _inventBuf2 = _vm->_globals.dos_free2(_inventBuf2); - if (g_PTRNUL != _vm->_dialogsManager._inventWin1) - _vm->_dialogsManager._inventWin1 = _vm->_globals.dos_free2(_vm->_dialogsManager._inventWin1); + _inventBuf2 = _vm->_globals.freeMemory(_inventBuf2); + _vm->_dialogsManager._inventWin1 = _vm->_globals.freeMemory(_vm->_dialogsManager._inventWin1); goto LABEL_7; } } else if (!v20) { @@ -449,9 +448,9 @@ LABEL_7: _vm->_graphicsManager.Ajoute_Segment_Vesa(v19, 114, v19 + v18, v18 + 114); _vm->_objectsManager.BOBTOUS = true; } - if (_vm->_dialogsManager._inventWin1 != g_PTRNUL) - _vm->_dialogsManager._inventWin1 = _vm->_globals.dos_free2(_vm->_dialogsManager._inventWin1); - _inventBuf2 = _vm->_globals.dos_free2(_inventBuf2); + + _vm->_dialogsManager._inventWin1 = _vm->_globals.freeMemory(_vm->_dialogsManager._inventWin1); + _inventBuf2 = _vm->_globals.freeMemory(_inventBuf2); if (_vm->_eventsManager._mouseCursorId == 1) showOptionsDialog(); @@ -577,8 +576,8 @@ void DialogsManager::showLoadGame() { _vm->_graphicsManager.SCOPY(_vm->_graphicsManager.VESA_SCREEN, _vm->_eventsManager._startPos.x + 183, 60, 274, 353, _vm->_graphicsManager.VESA_BUFFER, _vm->_eventsManager._startPos.x + 183, 60); _vm->_graphicsManager.Ajoute_Segment_Vesa(_vm->_eventsManager._startPos.x + 183, 60, 457, 413); _vm->_objectsManager.BOBTOUS = true; - _vm->_objectsManager.SL_SPR = _vm->_globals.dos_free2(_vm->_objectsManager.SL_SPR); - _vm->_objectsManager.SL_SPR2 = _vm->_globals.dos_free2(_vm->_objectsManager.SL_SPR2); + _vm->_objectsManager.SL_SPR = _vm->_globals.freeMemory(_vm->_objectsManager.SL_SPR); + _vm->_objectsManager.SL_SPR2 = _vm->_globals.freeMemory(_vm->_objectsManager.SL_SPR2); _vm->_objectsManager.SL_X = 0; _vm->_objectsManager.SL_Y = 0; @@ -610,8 +609,8 @@ void DialogsManager::showSaveGame() { _vm->_graphicsManager.SCOPY(_vm->_graphicsManager.VESA_SCREEN, _vm->_eventsManager._startPos.x + 183, 60, 274, 353, _vm->_graphicsManager.VESA_BUFFER, _vm->_eventsManager._startPos.x + 183, 60); _vm->_graphicsManager.Ajoute_Segment_Vesa(_vm->_eventsManager._startPos.x + 183, 60, _vm->_eventsManager._startPos.x + 457, 413); _vm->_objectsManager.BOBTOUS = true; - _vm->_objectsManager.SL_SPR = _vm->_globals.dos_free2(_vm->_objectsManager.SL_SPR); - _vm->_objectsManager.SL_SPR2 = _vm->_globals.dos_free2(_vm->_objectsManager.SL_SPR2); + _vm->_objectsManager.SL_SPR = _vm->_globals.freeMemory(_vm->_objectsManager.SL_SPR); + _vm->_objectsManager.SL_SPR2 = _vm->_globals.freeMemory(_vm->_objectsManager.SL_SPR2); _vm->_objectsManager.SL_X = 0; _vm->_objectsManager.SL_Y = 0; diff --git a/engines/hopkins/events.cpp b/engines/hopkins/events.cpp index 5f9ee21464..8f077d5463 100644 --- a/engines/hopkins/events.cpp +++ b/engines/hopkins/events.cpp @@ -56,8 +56,8 @@ EventsManager::EventsManager() { } EventsManager::~EventsManager() { - _vm->_globals.dos_free2(_objectBuf); - _vm->_globals.dos_free2(_mouseCursor); + _vm->_globals.freeMemory(_objectBuf); + _vm->_globals.freeMemory(_mouseCursor); } void EventsManager::setParent(HopkinsEngine *vm) { diff --git a/engines/hopkins/files.cpp b/engines/hopkins/files.cpp index f251d51388..998ab57fc5 100644 --- a/engines/hopkins/files.cpp +++ b/engines/hopkins/files.cpp @@ -64,7 +64,7 @@ byte *FileManager::loadFile(const Common::String &file) { // Allocate space for the file contents size_t filesize = f.size(); - byte *data = _vm->_globals.dos_malloc2(filesize); + byte *data = _vm->_globals.allocMemory(filesize); if (!data) error("Error allocating space for file being loaded - %s", file.c_str()); @@ -273,14 +273,14 @@ byte *FileManager::searchCat(const Common::String &file, int a2) { } if (name == "FINIS") { - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); return g_PTRNUL; } offsetVal += 23; } - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); // TODO: Double check whether this really should be an unsigned int comparison if ((uint16)(a2 - 6) > 1 && (uint16)(a2 - 8) > 1) { @@ -289,7 +289,7 @@ byte *FileManager::searchCat(const Common::String &file, int a2) { f.seek(_vm->_globals.CAT_POSI); - byte *catData = _vm->_globals.dos_malloc2(_vm->_globals.CAT_TAILLE); + byte *catData = _vm->_globals.allocMemory(_vm->_globals.CAT_TAILLE); if (catData == g_PTRNUL) error("CHARGE_FICHIER"); diff --git a/engines/hopkins/font.cpp b/engines/hopkins/font.cpp index 7b5cfded30..400ab48cfe 100644 --- a/engines/hopkins/font.cpp +++ b/engines/hopkins/font.cpp @@ -74,10 +74,7 @@ void FontManager::showText(int idx) { txt._textOnFl = true; txt._textLoadedFl = false; - if (txt._textBlock != g_PTRNUL) { - _vm->_globals.dos_free2(txt._textBlock); - txt._textBlock = g_PTRNUL; - } + txt._textBlock = _vm->_globals.freeMemory(txt._textBlock); } /** @@ -90,11 +87,7 @@ void FontManager::hideText(int idx) { TxtItem &txt = _text[idx - 5]; txt._textOnFl = false; txt._textLoadedFl = false; - - if (txt._textBlock != g_PTRNUL) { - _vm->_globals.dos_free2(txt._textBlock); - txt._textBlock = g_PTRNUL; - } + txt._textBlock = _vm->_globals.freeMemory(txt._textBlock); } /** @@ -202,7 +195,7 @@ void FontManager::box(int idx, int messageId, const Common::String &filename, in v69 = 2048; f.seek(_index[messageId]); - _tempText = _vm->_globals.dos_malloc2(0x80Au); + _tempText = _vm->_globals.allocMemory(0x80Au); if (_tempText == g_PTRNUL) error("Error allocating text"); @@ -213,7 +206,7 @@ void FontManager::box(int idx, int messageId, const Common::String &filename, in } else { v69 = 100; _vm->_globals.texte_long = 100; - v9 = _vm->_globals.dos_malloc2(0x6Eu); + v9 = _vm->_globals.allocMemory(0x6Eu); Common::fill(&v9[0], &v9[0x6e], 0); _tempText = v9; @@ -397,14 +390,14 @@ LABEL_57: int textType = _text[idx]._textType; if (textType == 1 || textType == 3 || textType == 5 || textType == 6) { int v49 = v51 * v53; - byte *ptrd = _vm->_globals.dos_malloc2(v49); + byte *ptrd = _vm->_globals.allocMemory(v49); if (ptrd == g_PTRNUL) { error("Cutting a block for text box (%d)", v49); } _vm->_graphicsManager.Capture_Mem(_vm->_graphicsManager.VESA_BUFFER, ptrd, v56, v55, v53, v51); _vm->_graphicsManager.Trans_bloc2(ptrd, _vm->_graphicsManager.TABLE_COUL, v49); _vm->_graphicsManager.Restore_Mem(_vm->_graphicsManager.VESA_BUFFER, ptrd, v56, v55, v53, v51); - _vm->_globals.dos_free2(ptrd); + _vm->_globals.freeMemory(ptrd); _vm->_graphicsManager.Plot_Hline(_vm->_graphicsManager.VESA_BUFFER, v56, v55, v53, (byte)-2); _vm->_graphicsManager.Plot_Hline(_vm->_graphicsManager.VESA_BUFFER, v56, v51 + v55, v53, (byte)-2); @@ -429,10 +422,9 @@ LABEL_57: _text[idx]._height = blockHeight; textType = _text[idx]._textType; if (textType == 6 || textType == 1 || textType == 3 || textType == 5) { - if (_text[idx]._textBlock != g_PTRNUL) - _text[idx]._textBlock = _vm->_globals.dos_free2(_text[idx]._textBlock); + _text[idx]._textBlock = _vm->_globals.freeMemory(_text[idx]._textBlock); int blockSize = blockHeight * blockWidth; - ptre = _vm->_globals.dos_malloc2(blockSize + 20); + ptre = _vm->_globals.allocMemory(blockSize + 20); if (ptre == g_PTRNUL) error("Cutting a block for text box (%d)", blockSize); @@ -441,11 +433,12 @@ LABEL_57: _text[idx]._height = blockHeight; _vm->_graphicsManager.Capture_Mem(_vm->_graphicsManager.VESA_BUFFER, _text[idx]._textBlock, v56, v55, _text[idx]._width, blockHeight); } - _tempText = _vm->_globals.dos_free2(_tempText); + _tempText = _vm->_globals.freeMemory(_tempText); } } + /** - * Directly display text + * Directly display text (using a VESA segment) */ void FontManager::displayTextVesa(int xp, int yp, const Common::String &message, int col) { const char *srcP; @@ -469,7 +462,9 @@ void FontManager::displayTextVesa(int xp, int yp, const Common::String &message, _vm->_graphicsManager.Ajoute_Segment_Vesa(xp, yp, currentX, yp + 12); } - +/** + * Directly display text + */ void FontManager::displayText(int xp, int yp, const Common::String &message, int col) { for (uint idx = 0; idx < message.size(); ++idx) { char currentChar = message[idx]; diff --git a/engines/hopkins/globals.cpp b/engines/hopkins/globals.cpp index e5a4e85ed4..ed4e998df3 100644 --- a/engines/hopkins/globals.cpp +++ b/engines/hopkins/globals.cpp @@ -261,23 +261,23 @@ Globals::Globals() { Globals::~Globals() { free(ICONE); - dos_free2(TETE); - dos_free2(police); - dos_free2(BUF_ZONE); - dos_free2(CACHE_BANQUE[6]); - dos_free2(texte_tmp); - dos_free2(SPRITE_ECRAN); - dos_free2((byte *)SAUVEGARDE); - dos_free2(BUFFERTAPE); - dos_free2(inventaire2); - dos_free2(GESTE); - dos_free2(INVENTAIRE_OBJET); - dos_free2(FORETSPR); - dos_free2(COUCOU); - dos_free2(cache_souris); - dos_free2(Bufferdecor); - dos_free2(ADR_FICHIER_OBJ); - dos_free2(PERSO); + freeMemory(TETE); + freeMemory(police); + freeMemory(BUF_ZONE); + freeMemory(CACHE_BANQUE[6]); + freeMemory(texte_tmp); + freeMemory(SPRITE_ECRAN); + freeMemory((byte *)SAUVEGARDE); + freeMemory(BUFFERTAPE); + freeMemory(inventaire2); + freeMemory(GESTE); + freeMemory(INVENTAIRE_OBJET); + freeMemory(FORETSPR); + freeMemory(COUCOU); + freeMemory(cache_souris); + freeMemory(Bufferdecor); + freeMemory(ADR_FICHIER_OBJ); + freeMemory(PERSO); CLEAR_VBOB(); @@ -406,7 +406,7 @@ void Globals::clearAll() { texte_long = 0; texte_tmp = g_PTRNUL; - BUFFERTAPE = dos_malloc2(85000); + BUFFERTAPE = allocMemory(85000); SAUVEGARDE = (Sauvegarde *)malloc(sizeof(Sauvegarde)); memset(SAUVEGARDE, 0, sizeof(Sauvegarde)); @@ -418,14 +418,14 @@ void Globals::clearAll() { largeur_boite = 240; TEXTE_FORMATE = 300; - _vm->_eventsManager._objectBuf = dos_malloc2(2500); - INVENTAIRE_OBJET = dos_malloc2(2500); + _vm->_eventsManager._objectBuf = allocMemory(2500); + INVENTAIRE_OBJET = allocMemory(2500); ADR_FICHIER_OBJ = g_PTRNUL; FORETSPR = g_PTRNUL; FORET = false; - cache_souris = dos_malloc2(2500); + cache_souris = allocMemory(2500); GESTE = g_PTRNUL; GESTE_FLAG = false; } @@ -481,9 +481,7 @@ void Globals::CLEAR_VBOB() { VBob[idx].yp = 0; VBob[idx].frameIndex = 0; VBob[idx].fieldC = 0; - if (VBob[idx].surface != g_PTRNUL) - dos_free2(VBob[idx].surface); - VBob[idx].surface = g_PTRNUL; + VBob[idx].surface = freeMemory(VBob[idx].surface); VBob[idx].spriteData = g_PTRNUL; VBob[idx].oldSpriteData = g_PTRNUL; } @@ -509,34 +507,24 @@ void Globals::CHARGE_OBJET() { free(data); } -byte *Globals::dos_malloc2(int count) { +byte *Globals::allocMemory(int count) { byte *result = (byte *)malloc(count); if (!result) result = g_PTRNUL; return result; } -byte *Globals::dos_free2(byte *p) { +byte *Globals::freeMemory(byte *p) { if (p != g_PTRNUL) free(p); return g_PTRNUL; } -// Free File -byte *Globals::LIBERE_FICHIER(byte *p) { - dos_free2(p); - return g_PTRNUL; -} - // Reset Cache void Globals::RESET_CACHE() { - byte *dataP; for (int idx = 1; idx <= 5; ++idx) { - dataP = CACHE_BANQUE[idx]; - if (dataP != g_PTRNUL && dataP) - CACHE_BANQUE[idx] = dos_free2(CACHE_BANQUE[idx]); - CACHE_BANQUE[idx] = g_PTRNUL; + CACHE_BANQUE[idx] = freeMemory(CACHE_BANQUE[idx]); } for (int idx = 0; idx <= 20; ++idx) { @@ -619,7 +607,7 @@ void Globals::CHARGE_CACHE(const Common::String &file) { CACHE_ON(); v2 = ptr; } - dos_free2(v2); + freeMemory(v2); } void Globals::B_CACHE_OFF(int idx) { diff --git a/engines/hopkins/globals.h b/engines/hopkins/globals.h index 1cbd6d8e7b..eebfea5782 100644 --- a/engines/hopkins/globals.h +++ b/engines/hopkins/globals.h @@ -499,9 +499,8 @@ public: void INIT_VBOB(); void CLEAR_VBOB(); void CHARGE_OBJET(); - byte *dos_malloc2(int count); - byte *dos_free2(byte *p); - byte *LIBERE_FICHIER(byte *p); + byte *allocMemory(int count); + byte *freeMemory(byte *p); void RESET_CACHE(); void CACHE_ON(); diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp index 0fd0de58dd..32b7b62688 100644 --- a/engines/hopkins/graphics.cpp +++ b/engines/hopkins/graphics.cpp @@ -80,8 +80,8 @@ GraphicsManager::GraphicsManager() { } GraphicsManager::~GraphicsManager() { - _vm->_globals.dos_free2(VESA_SCREEN); - _vm->_globals.dos_free2(VESA_BUFFER); + _vm->_globals.freeMemory(VESA_SCREEN); + _vm->_globals.freeMemory(VESA_BUFFER); } void GraphicsManager::setParent(HopkinsEngine *vm) { @@ -135,8 +135,8 @@ void GraphicsManager::SET_MODE(int width, int height) { } // Init surfaces - VESA_SCREEN = _vm->_globals.dos_malloc2(SCREEN_WIDTH * 2 * SCREEN_HEIGHT); - VESA_BUFFER = _vm->_globals.dos_malloc2(SCREEN_WIDTH * 2 * SCREEN_HEIGHT); + VESA_SCREEN = _vm->_globals.allocMemory(SCREEN_WIDTH * 2 * SCREEN_HEIGHT); + VESA_BUFFER = _vm->_globals.allocMemory(SCREEN_WIDTH * 2 * SCREEN_HEIGHT); VideoPtr = NULL; XSCREEN = width; @@ -410,7 +410,7 @@ void GraphicsManager::A_PCX320(byte *surface, const Common::String &file, byte * f.read(surface, 0x80u); v4 = filesize - 896; - ptr = _vm->_globals.dos_malloc2(0xFE00u); + ptr = _vm->_globals.allocMemory(0xFE00u); if (v4 >= 0xFA00) { v15 = v4 / 0xFA00 + 1; v17 = 64000 * (v4 / 0xFA00) - v4; @@ -465,7 +465,7 @@ void GraphicsManager::A_PCX320(byte *surface, const Common::String &file, byte * f.read(palette, 0x300u); f.close(); - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); } // Clear Palette @@ -2302,8 +2302,7 @@ void GraphicsManager::OPTI_INI(const Common::String &file, int mode) { } if (!mode) { filename = file + ".spr"; - if (g_PTRNUL != _vm->_globals.SPRITE_ECRAN) - _vm->_globals.SPRITE_ECRAN = _vm->_globals.LIBERE_FICHIER(_vm->_globals.SPRITE_ECRAN); + _vm->_globals.SPRITE_ECRAN = _vm->_globals.freeMemory(_vm->_globals.SPRITE_ECRAN); if (!_vm->_globals.NOSPRECRAN) { _vm->_globals.SPRITE_ECRAN = _vm->_fileManager.searchCat(filename, 8); if (_vm->_globals.SPRITE_ECRAN) { @@ -2340,10 +2339,9 @@ void GraphicsManager::OPTI_INI(const Common::String &file, int mode) { doneFlag = true; } while (!doneFlag); } - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); if (mode != 1) { - if (g_PTRNUL != _vm->_globals.COUCOU) - _vm->_globals.COUCOU = _vm->_globals.dos_free2(_vm->_globals.COUCOU); + _vm->_globals.COUCOU = _vm->_globals.freeMemory(_vm->_globals.COUCOU); filename = file + ".rep"; byte *dataP = _vm->_fileManager.searchCat(filename, 2); diff --git a/engines/hopkins/hopkins.cpp b/engines/hopkins/hopkins.cpp index 54f2c55ae2..28723edd33 100644 --- a/engines/hopkins/hopkins.cpp +++ b/engines/hopkins/hopkins.cpp @@ -193,7 +193,7 @@ bool HopkinsEngine::runWin95Demo() { if (!_globals.SORTIE) { _globals.SORTIE = _menuManager.MENU(); if (_globals.SORTIE == -1) { - _globals.PERSO = _globals.dos_free2(_globals.PERSO); + _globals.PERSO = _globals.freeMemory(_globals.PERSO); REST_SYSTEM(); return false; } @@ -499,7 +499,7 @@ bool HopkinsEngine::runLinuxDemo() { if (_globals.SORTIE == -1) { if (!g_system->getEventManager()->shouldQuit()) PUBQUIT(); - _globals.PERSO = _globals.dos_free2(_globals.PERSO); + _globals.PERSO = _globals.freeMemory(_globals.PERSO); REST_SYSTEM(); } } @@ -864,7 +864,7 @@ bool HopkinsEngine::runWin95full() { if (!_globals.SORTIE) { _globals.SORTIE = _menuManager.MENU();; if (_globals.SORTIE == -1) { - _globals.PERSO = _globals.dos_free2(_globals.PERSO); + _globals.PERSO = _globals.freeMemory(_globals.PERSO); REST_SYSTEM(); return false; } @@ -1243,8 +1243,7 @@ bool HopkinsEngine::runWin95full() { _objectsManager.PERSONAGE2(im, im, "BANDIT", im, 13); _globals.NOSPRECRAN = false; if (_globals.SORTIE < 35 || _globals.SORTIE > 49) { - _globals.dos_free2(_globals.FORETSPR); - _globals.FORETSPR = g_PTRNUL; + _globals.FORETSPR = _globals.freeMemory(_globals.FORETSPR); _globals.FORET = false; _soundManager.DEL_SAMPLE(1); } @@ -1678,7 +1677,7 @@ bool HopkinsEngine::runWin95full() { case 197: case 198: case 199: - _globals.PERSO = _globals.dos_free2(_globals.PERSO); + _globals.PERSO = _globals.freeMemory(_globals.PERSO); _globals.iRegul = 1; _soundManager.WSOUND_OFF(); warning("TODO: heapshrink();"); @@ -1742,7 +1741,7 @@ bool HopkinsEngine::runLinuxFull() { if (!_globals.SORTIE) { _globals.SORTIE = _menuManager.MENU(); if (_globals.SORTIE == -1) { - _globals.PERSO = _globals.dos_free2(_globals.PERSO); + _globals.PERSO = _globals.freeMemory(_globals.PERSO); REST_SYSTEM(); return true; } @@ -2122,8 +2121,7 @@ bool HopkinsEngine::runLinuxFull() { _objectsManager.PERSONAGE2(im, im, "BANDIT", im, 13); _globals.NOSPRECRAN = false; if (_globals.SORTIE < 35 || _globals.SORTIE > 49) { - _globals.dos_free2(_globals.FORETSPR); - _globals.FORETSPR = g_PTRNUL; + _globals.FORETSPR = _globals.freeMemory(_globals.FORETSPR); _globals.FORET = false; _soundManager.DEL_SAMPLE(1); } @@ -2572,7 +2570,7 @@ bool HopkinsEngine::runLinuxFull() { case 197: case 198: case 199: - _globals.PERSO = _globals.dos_free2(_globals.PERSO); + _globals.PERSO = _globals.freeMemory(_globals.PERSO); _globals.iRegul = 1; _soundManager.WSOUND(23); _globals.SORTIE = PWBASE(); @@ -3207,7 +3205,7 @@ void HopkinsEngine::BASED() { } void HopkinsEngine::JOUE_FIN() { - _globals.PERSO = _globals.dos_free2(_globals.PERSO); + _globals.PERSO = _globals.freeMemory(_globals.PERSO); _dialogsManager._removeInventFl = true; _globals._disableInventFl = true; _graphicsManager.ofscroll = 0; @@ -3590,7 +3588,7 @@ void HopkinsEngine::Charge_Credits() { while (v5 < _globals.Credit_lignes); } */ - _globals.dos_free2(bufPtr); + _globals.freeMemory(bufPtr); } void HopkinsEngine::CREDIT_AFFICHE(int startPosY, byte *buffer, char colour) { diff --git a/engines/hopkins/lines.cpp b/engines/hopkins/lines.cpp index 4a3eabe878..85a6e07aad 100644 --- a/engines/hopkins/lines.cpp +++ b/engines/hopkins/lines.cpp @@ -132,10 +132,8 @@ int LinesManager::OPTI_ZONE(int a1, int a2, int a3) { void LinesManager::RETIRE_LIGNE_ZONE(int idx) { if (idx > 400) error("Attempting to add a line obstacle > MAX_LIGNE."); - if (_vm->_linesManager.LigneZone[idx].zoneData != (int16 *)g_PTRNUL) - _vm->_globals.dos_free2((byte *)_vm->_linesManager.LigneZone[idx].zoneData); - _vm->_linesManager.LigneZone[idx].zoneData = (int16 *)g_PTRNUL; + _vm->_linesManager.LigneZone[idx].zoneData = (int16 *)_vm->_globals.freeMemory((byte *)_vm->_linesManager.LigneZone[idx].zoneData); } // Add Line Zone @@ -146,8 +144,8 @@ void LinesManager::AJOUTE_LIGNE_ZONE(int idx, int a2, int a3, int a4, int a5, in if (idx > 400) error("Attempting to add a line obstacle > MAX_LIGNE."); - if (LigneZone[idx].zoneData != (int16 *)g_PTRNUL) - LigneZone[idx].zoneData = (int16 *)_vm->_globals.dos_free2((byte *)LigneZone[idx].zoneData); + LigneZone[idx].zoneData = (int16 *)_vm->_globals.freeMemory((byte *)LigneZone[idx].zoneData); + int v8 = a2 - a4; if (a2 - a4 < 0) v8 = -v8; @@ -162,7 +160,7 @@ void LinesManager::AJOUTE_LIGNE_ZONE(int idx, int a2, int a3, int a4, int a5, in else v20 += v19; - zoneData = (int16 *)_vm->_globals.dos_malloc2(2 * sizeof(int16) * v20 + (4 * sizeof(int16))); + zoneData = (int16 *)_vm->_globals.allocMemory(2 * sizeof(int16) * v20 + (4 * sizeof(int16))); int v11 = idx; LigneZone[v11].zoneData = zoneData; if (zoneData == (int16 *)g_PTRNUL) @@ -214,9 +212,7 @@ void LinesManager::RESET_OBSTACLE() { void LinesManager::RETIRE_LIGNE(int idx) { if (idx > 400) error("Attempting to add a line obstacle > MAX_LIGNE."); - if (Ligne[idx].lineData != (int16 *)g_PTRNUL) - _vm->_globals.dos_free2((byte *)Ligne[idx].lineData); - Ligne[idx].lineData = (int16 *)g_PTRNUL; + Ligne[idx].lineData = (int16 *)_vm->_globals.freeMemory((byte *)Ligne[idx].lineData); } // Add Line @@ -249,8 +245,7 @@ void LinesManager::AJOUTE_LIGNE(int idx, int a2, int a3, int a4, int a5, int a6, if (TOTAL_LIGNES < idx) TOTAL_LIGNES = idx; - if (Ligne[idx].lineData != (int16 *)g_PTRNUL) - _vm->_globals.dos_free2((byte *)Ligne[idx].lineData); + Ligne[idx].lineData = (int16 *)_vm->_globals.freeMemory((byte *)Ligne[idx].lineData); v7 = a3 - a5; if (a3 - a5 < 0) v7 = -v7; @@ -263,7 +258,7 @@ void LinesManager::AJOUTE_LIGNE(int idx, int a2, int a3, int a4, int a5, int a6, if (v8 > (int)(v9 + 1)) v34 = v8; - v10 = _vm->_globals.dos_malloc2(4 * v34 + 8); + v10 = _vm->_globals.allocMemory(4 * v34 + 8); if (v10 == g_PTRNUL) error("AJOUTE LIGNE OBSTACLE"); diff --git a/engines/hopkins/menu.cpp b/engines/hopkins/menu.cpp index 9e5abf0c3e..7dbd386d90 100644 --- a/engines/hopkins/menu.cpp +++ b/engines/hopkins/menu.cpp @@ -229,7 +229,7 @@ int MenuManager::MENU() { break; } - _vm->_globals.LIBERE_FICHIER(spriteData); + _vm->_globals.freeMemory(spriteData); _vm->_globals._disableInventFl = false; _vm->_globals.FLAG_VISIBLE = false; _vm->_graphicsManager.FADE_OUTW(); diff --git a/engines/hopkins/objects.cpp b/engines/hopkins/objects.cpp index a050663090..eb195c213b 100644 --- a/engines/hopkins/objects.cpp +++ b/engines/hopkins/objects.cpp @@ -133,7 +133,7 @@ byte *ObjectsManager::CAPTURE_OBJET(int objIndex, int mode) { switch (mode) { case 0: - dataP = _vm->_globals.dos_malloc2(height * width); + dataP = _vm->_globals.allocMemory(height * width); if (dataP == g_PTRNUL) error("CAPTURE_OBJET"); @@ -261,12 +261,9 @@ int ObjectsManager::sprite_alone(const byte *objectData, byte *sprite, int objIn byte *ObjectsManager::DEL_FICHIER_OBJ() { _vm->_globals.NUM_FICHIER_OBJ = 0; - if (_vm->_globals.ADR_FICHIER_OBJ != g_PTRNUL) - _vm->_globals.ADR_FICHIER_OBJ = _vm->_globals.LIBERE_FICHIER(_vm->_globals.ADR_FICHIER_OBJ); + _vm->_globals.ADR_FICHIER_OBJ = _vm->_globals.freeMemory(_vm->_globals.ADR_FICHIER_OBJ); - byte *result = g_PTRNUL; - _vm->_globals.ADR_FICHIER_OBJ = g_PTRNUL; - return result; + return g_PTRNUL; } // Load Sprite @@ -1369,11 +1366,9 @@ void ObjectsManager::AFF_VBOB() { _vm->_globals.VBob[idx].xp, _vm->_globals.VBob[idx].yp, _vm->_globals.VBob[idx].xp + width, height + _vm->_globals.VBob[idx].yp); - if (_vm->_globals.VBob[idx].surface != g_PTRNUL) - _vm->_globals.dos_free2(_vm->_globals.VBob[idx].surface); + _vm->_globals.VBob[idx].surface = _vm->_globals.freeMemory(_vm->_globals.VBob[idx].surface); _vm->_globals.VBob[idx].field4 = 0; - _vm->_globals.VBob[idx].surface = g_PTRNUL; _vm->_globals.VBob[idx].spriteData = g_PTRNUL; _vm->_globals.VBob[idx].xp = 0; _vm->_globals.VBob[idx].yp = 0; @@ -1404,10 +1399,8 @@ void ObjectsManager::AFF_VBOB() { _vm->_globals.VBob[idx].field4 = 1; _vm->_globals.VBob[idx].oldSpriteData = _vm->_globals.VBob[idx].spriteData; - if (_vm->_globals.VBob[idx].surface != g_PTRNUL) - _vm->_globals.dos_free2(_vm->_globals.VBob[idx].surface); + _vm->_globals.VBob[idx].surface = _vm->_globals.freeMemory(_vm->_globals.VBob[idx].surface); - _vm->_globals.VBob[idx].surface = g_PTRNUL; _vm->_globals.VBob[idx].oldX = _vm->_globals.VBob[idx].xp; _vm->_globals.VBob[idx].oldY = _vm->_globals.VBob[idx].yp; _vm->_globals.VBob[idx].oldFrameIndex = _vm->_globals.VBob[idx].frameIndex; @@ -1417,10 +1410,9 @@ void ObjectsManager::AFF_VBOB() { width = getWidth(_vm->_globals.VBob[idx].spriteData, _vm->_globals.VBob[idx].frameIndex); height = getHeight(_vm->_globals.VBob[idx].spriteData, _vm->_globals.VBob[idx].frameIndex); - if (_vm->_globals.VBob[idx].surface != g_PTRNUL) - _vm->_globals.dos_free2(_vm->_globals.VBob[idx].surface); + _vm->_globals.VBob[idx].surface = _vm->_globals.freeMemory(_vm->_globals.VBob[idx].surface); - byte *surface = _vm->_globals.dos_malloc2(height * width); + byte *surface = _vm->_globals.allocMemory(height * width); _vm->_globals.VBob[idx].surface = surface; _vm->_graphicsManager.Capture_Mem(_vm->_graphicsManager.VESA_SCREEN, surface, @@ -1551,9 +1543,7 @@ void ObjectsManager::SPRITE2(const byte *spriteData, int idx, byte *a3, int a4, void ObjectsManager::SPRITE_OFF(int idx) { Sprite[idx].field0 = 3; - if (Sprite[idx].field1C != g_PTRNUL) - _vm->_globals.dos_free2(Sprite[idx].field1C); - Sprite[idx].field1C = g_PTRNUL; + Sprite[idx].field1C = _vm->_globals.freeMemory(Sprite[idx].field1C); } void ObjectsManager::SPRITE_GEL(int idx) { @@ -2355,7 +2345,7 @@ void ObjectsManager::CHARGE_OBSTACLE(const Common::String &file) { ++v5; } while (v1 != -1); _vm->_linesManager.INIPARCOURS(); - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); } // Load Zone @@ -2466,7 +2456,7 @@ void ObjectsManager::CHARGE_ZONE(const Common::String &file) { _vm->_globals.ZONEP[v15++].field12 = READ_LE_UINT16(v13 + 2 * v14++); while (v15 <= 100); - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); CARRE_ZONE(); } @@ -2656,7 +2646,7 @@ void ObjectsManager::PLAN_BETA() { _vm->_globals.PLANI = 1; SPRITE_OFF(0); _vm->_globals.AFFLI = false; - sprite_ptr = _vm->_globals.LIBERE_FICHIER(sprite_ptr); + sprite_ptr = _vm->_globals.freeMemory(sprite_ptr); CLEAR_ECRAN(); _vm->_globals.NOSPRECRAN = false; _vm->_globals.PLAN_FLAG = false; @@ -2998,10 +2988,8 @@ void ObjectsManager::CLEAR_ECRAN() { _vm->_linesManager.TOTAL_LIGNES = 0; DERLIGNE = 0; _vm->_globals.chemin = (int16 *)g_PTRNUL; - if (_vm->_globals.COUCOU != g_PTRNUL) - _vm->_globals.COUCOU = _vm->_globals.LIBERE_FICHIER(_vm->_globals.COUCOU); - if (g_PTRNUL != _vm->_globals.SPRITE_ECRAN) - _vm->_globals.SPRITE_ECRAN = _vm->_globals.LIBERE_FICHIER(_vm->_globals.SPRITE_ECRAN); + _vm->_globals.COUCOU = _vm->_globals.freeMemory(_vm->_globals.COUCOU); + _vm->_globals.SPRITE_ECRAN = _vm->_globals.freeMemory(_vm->_globals.SPRITE_ECRAN); _vm->_eventsManager._startPos.x = 0; _vm->_eventsManager._mouseSpriteId = 0; Vold_taille = 200; @@ -4143,7 +4131,7 @@ void ObjectsManager::OPTI_OBJET() { v7 = 1; } while (v7 != 1); } - _vm->_globals.dos_free2(data); + _vm->_globals.freeMemory(data); } void ObjectsManager::SPECIAL_JEU() { @@ -4189,7 +4177,7 @@ void ObjectsManager::SPECIAL_JEU() { _vm->_talkManager.PARLER_PERSO("flicspe1.pe2"); _vm->_globals.NOPARLE = false; if (!_vm->_globals.CENSURE) { - v1 = _vm->_globals.dos_malloc2(0x3E8u); + v1 = _vm->_globals.allocMemory(0x3E8u); memcpy(v1, _vm->_graphicsManager.Palette, 0x301u); _vm->_saveLoadManager.SAUVE_FICHIER("TEMP1.SCR", _vm->_graphicsManager.VESA_SCREEN, 0x4B000u); @@ -4214,7 +4202,7 @@ void ObjectsManager::SPECIAL_JEU() { PERSO_ON = false; memcpy(_vm->_graphicsManager.Palette, v1, 0x301u); _vm->_graphicsManager.SHOW_PALETTE(); - _vm->_globals.dos_free2(v1); + _vm->_globals.freeMemory(v1); _vm->_graphicsManager.DD_Lock(); if (_vm->_graphicsManager.Winbpp == 2) { if (_vm->_graphicsManager.SDL_ECHELLE) @@ -4315,8 +4303,7 @@ void ObjectsManager::VBOB(byte *src, int idx, int xp, int yp, int frameIndex) { _vm->_globals.VBob[idx].oldFrameIndex = frameIndex; _vm->_globals.VBob[idx].spriteData = src; _vm->_globals.VBob[idx].oldSpriteData = src; - if (_vm->_globals.VBob[idx].surface != g_PTRNUL) - _vm->_globals.VBob[idx].surface = _vm->_globals.dos_free2(_vm->_globals.VBob[idx].surface); + _vm->_globals.VBob[idx].surface = _vm->_globals.freeMemory(_vm->_globals.VBob[idx].surface); } int f4 = _vm->_globals.VBob[idx].field4; @@ -4345,8 +4332,7 @@ void ObjectsManager::VBOB_OFF(int idx) { void ObjectsManager::ACTION_DOS(int idx) { if (_vm->_globals.GESTE_FLAG != 1) { - if (g_PTRNUL != _vm->_globals.GESTE) - _vm->_globals.GESTE = _vm->_globals.dos_free2(_vm->_globals.GESTE); + _vm->_globals.GESTE = _vm->_globals.freeMemory(_vm->_globals.GESTE); _vm->_globals.GESTE_FLAG = 1; _vm->_fileManager.constructFilename(_vm->_globals.HOPSYSTEM, "DOS.SPR"); @@ -4382,8 +4368,7 @@ void ObjectsManager::ACTION_DOS(int idx) { void ObjectsManager::ACTION_DROITE(int idx) { if (_vm->_globals.GESTE_FLAG != 3) { - if (_vm->_globals.GESTE != g_PTRNUL) - _vm->_globals.GESTE = _vm->_globals.dos_free2(_vm->_globals.GESTE); + _vm->_globals.GESTE = _vm->_globals.freeMemory(_vm->_globals.GESTE); _vm->_globals.GESTE_FLAG = 3; _vm->_fileManager.constructFilename(_vm->_globals.HOPSYSTEM, "PROFIL.SPR"); _vm->_globals.GESTE = _vm->_fileManager.loadFile(_vm->_globals.NFICHIER); @@ -4412,8 +4397,7 @@ void ObjectsManager::ACTION_DROITE(int idx) { void ObjectsManager::Q_DROITE(int idx) { if (_vm->_globals.GESTE_FLAG != 4) { - if (_vm->_globals.GESTE != g_PTRNUL) - _vm->_globals.GESTE = _vm->_globals.dos_free2(_vm->_globals.GESTE); + _vm->_globals.GESTE = _vm->_globals.freeMemory(_vm->_globals.GESTE); _vm->_globals.GESTE_FLAG = 4; _vm->_fileManager.constructFilename(_vm->_globals.HOPSYSTEM, "3Q.SPR"); _vm->_globals.GESTE = _vm->_fileManager.loadFile(_vm->_globals.NFICHIER); @@ -4442,8 +4426,7 @@ void ObjectsManager::Q_DROITE(int idx) { void ObjectsManager::ACTION_FACE(int idx) { if (_vm->_globals.GESTE_FLAG != 2) { - if (_vm->_globals.GESTE != g_PTRNUL) - _vm->_globals.GESTE = _vm->_globals.dos_free2(_vm->_globals.GESTE); + _vm->_globals.GESTE = _vm->_globals.freeMemory(_vm->_globals.GESTE); _vm->_globals.GESTE_FLAG = 2; _vm->_fileManager.constructFilename(_vm->_globals.HOPSYSTEM, "FACE.SPR"); _vm->_globals.GESTE = _vm->_fileManager.loadFile(_vm->_globals.NFICHIER); @@ -4460,8 +4443,7 @@ void ObjectsManager::ACTION_FACE(int idx) { void ObjectsManager::Q_GAUCHE(int idx) { if (_vm->_globals.GESTE_FLAG != 4) { - if (_vm->_globals.GESTE != g_PTRNUL) - _vm->_globals.GESTE = _vm->_globals.dos_free2(_vm->_globals.GESTE); + _vm->_globals.GESTE = _vm->_globals.freeMemory(_vm->_globals.GESTE); _vm->_globals.GESTE_FLAG = 4; _vm->_fileManager.constructFilename(_vm->_globals.HOPSYSTEM, "3Q.SPR"); _vm->_globals.GESTE = _vm->_fileManager.loadFile(_vm->_globals.NFICHIER); @@ -4490,8 +4472,7 @@ void ObjectsManager::Q_GAUCHE(int idx) { void ObjectsManager::ACTION_GAUCHE(int idx) { if (_vm->_globals.GESTE_FLAG != 3) { - if (_vm->_globals.GESTE != g_PTRNUL) - _vm->_globals.GESTE = _vm->_globals.dos_free2(_vm->_globals.GESTE); + _vm->_globals.GESTE = _vm->_globals.freeMemory(_vm->_globals.GESTE); _vm->_globals.GESTE_FLAG = 3; _vm->_fileManager.constructFilename(_vm->_globals.HOPSYSTEM, "PROFIL.SPR"); _vm->_globals.GESTE = _vm->_fileManager.loadFile(_vm->_globals.NFICHIER); @@ -4654,7 +4635,7 @@ void ObjectsManager::INILINK(const Common::String &file) { error("Error opening file - %s", _vm->_globals.NFICHIER.c_str()); nbytes = f.size(); - ptr = _vm->_globals.dos_malloc2(nbytes); + ptr = _vm->_globals.allocMemory(nbytes); if (g_PTRNUL == ptr) error("INILINK"); _vm->_fileManager.readStream(f, ptr, nbytes); @@ -4833,7 +4814,7 @@ void ObjectsManager::INILINK(const Common::String &file) { } while (nbytes > v42); } } - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); } void ObjectsManager::SPECIAL_INI(const Common::String &a1) { diff --git a/engines/hopkins/talk.cpp b/engines/hopkins/talk.cpp index 31ebb3cc3a..ed41e34c0f 100644 --- a/engines/hopkins/talk.cpp +++ b/engines/hopkins/talk.cpp @@ -143,8 +143,8 @@ void TalkManager::PARLER_PERSO(const Common::String &filename) { clearCharacterAnim(); _vm->_globals.NOPARLE = false; _vm->_globals.NECESSAIRE = true; - BUFFERPERSO = _vm->_globals.LIBERE_FICHIER(BUFFERPERSO); - PERSOSPR = _vm->_globals.LIBERE_FICHIER(PERSOSPR); + BUFFERPERSO = _vm->_globals.freeMemory(BUFFERPERSO); + PERSOSPR = _vm->_globals.freeMemory(PERSOSPR); _vm->_graphicsManager.NB_SCREEN(); _vm->_globals.NECESSAIRE = false; @@ -258,7 +258,7 @@ void TalkManager::PARLER_PERSO2(const Common::String &filename) { while (v5 != -1); } - BUFFERPERSO = _vm->_globals.LIBERE_FICHIER(BUFFERPERSO); + BUFFERPERSO = _vm->_globals.freeMemory(BUFFERPERSO); _vm->_eventsManager._mouseCursorId = v8; _vm->_eventsManager.changeMouseCursor(v8); @@ -670,7 +670,7 @@ int TalkManager::VERIF_BOITE(int idx, const Common::String &file, int a3) { error("Error opening file - %s", dest.c_str()); f.seek(indexData[idx]); - ptr = _vm->_globals.dos_malloc2(2058); + ptr = _vm->_globals.allocMemory(2058); if (ptr == g_PTRNUL) error("temporary TEXT"); f.read(ptr, 2048); @@ -864,10 +864,7 @@ void TalkManager::ANIM_PERSO_INIT() { void TalkManager::clearCharacterAnim() { for (int idx = 21; idx <= 34; ++idx) { - if (_vm->_globals.Bqe_Anim[idx].data != g_PTRNUL) - _vm->_globals.Bqe_Anim[idx].data = _vm->_globals.dos_free2(_vm->_globals.Bqe_Anim[idx].data); - - _vm->_globals.Bqe_Anim[idx].data = g_PTRNUL; + _vm->_globals.Bqe_Anim[idx].data = _vm->_globals.freeMemory(_vm->_globals.Bqe_Anim[idx].data); _vm->_globals.Bqe_Anim[idx].field4 = 0; } } @@ -919,7 +916,7 @@ bool TalkManager::searchCharacterAnim(int a1, const byte *bufPerso, int a3, int ++v6; ++v5; } while (v7 != 1); - _vm->_globals.Bqe_Anim[v20].data = _vm->_globals.dos_malloc2(v6 + 50); + _vm->_globals.Bqe_Anim[v20].data = _vm->_globals.allocMemory(v6 + 50); _vm->_globals.Bqe_Anim[a1].field4 = 1; memcpy(_vm->_globals.Bqe_Anim[v20].data, (const byte *)(v22 + bufPerso + 5), 20); v8 = _vm->_globals.Bqe_Anim[v20].data; @@ -1007,7 +1004,7 @@ LABEL_2: v5 = v5 + 1; if (v15 == 1) { v6 = v5 + 5; - ptr = _vm->_globals.dos_malloc2(620); + ptr = _vm->_globals.allocMemory(620); if (g_PTRNUL == ptr) error("TRADUC"); memset(ptr, 0, 620); @@ -1061,13 +1058,13 @@ LABEL_2: if (!v10 || v10 == 5) v17 = 1; if (v10 == 6) { - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); v2 = _vm->_objectsManager.NVZONE; v3 = _vm->_objectsManager.NVVERBE; goto LABEL_2; } } while (v17 != 1); - _vm->_globals.dos_free2(ptr); + _vm->_globals.freeMemory(ptr); _vm->_globals.SAUVEGARDE->data[svField2] = 0; return; } @@ -1295,8 +1292,8 @@ void TalkManager::OBJET_VIVANT(const Common::String &a2) { clearCharacterAnim(); _vm->_globals.NOPARLE = false; _vm->_globals.NECESSAIRE = true; - BUFFERPERSO = _vm->_globals.LIBERE_FICHIER(BUFFERPERSO); - PERSOSPR = _vm->_globals.LIBERE_FICHIER(PERSOSPR); + BUFFERPERSO = _vm->_globals.freeMemory(BUFFERPERSO); + PERSOSPR = _vm->_globals.freeMemory(PERSOSPR); _vm->_graphicsManager.NB_SCREEN(); _vm->_globals.NECESSAIRE = false; _vm->_linesManager.CLEAR_ZONE(); @@ -1306,7 +1303,7 @@ void TalkManager::OBJET_VIVANT(const Common::String &a2) { do _vm->_globals.BOBZONE[v13++] = 0; while (v13 <= 44); - _vm->_globals.LIBERE_FICHIER(_vm->_globals.COUCOU); + _vm->_globals.freeMemory(_vm->_globals.COUCOU); _vm->_globals.COUCOU = v11; _vm->_objectsManager.DESACTIVE = true; _vm->_objectsManager.INILINK(v20); -- cgit v1.2.3