From ecee539bfde463648d69e0330500ab5ad3cde080 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 8 Sep 2012 23:43:35 +1000 Subject: HOPKINS: Implement proper graphics initialisation code --- engines/hopkins/events.cpp | 8 ++- engines/hopkins/events.h | 3 + engines/hopkins/files.cpp | 2 +- engines/hopkins/globals.cpp | 71 +++------------------- engines/hopkins/globals.h | 8 +-- engines/hopkins/graphics.cpp | 136 ++++++++++++++++++++++++++++++++++++++++++- engines/hopkins/graphics.h | 29 +++++++++ engines/hopkins/hopkins.cpp | 14 +++-- engines/hopkins/hopkins.h | 2 + 9 files changed, 196 insertions(+), 77 deletions(-) (limited to 'engines/hopkins') diff --git a/engines/hopkins/events.cpp b/engines/hopkins/events.cpp index c714338574..f498a4e383 100644 --- a/engines/hopkins/events.cpp +++ b/engines/hopkins/events.cpp @@ -30,8 +30,6 @@ void Mouse::INSTALL_SOURIS() { } void Mouse::souris_on() { - bool result; // eax@5 - souris_flag = true; if (mouse_linux) { @@ -59,4 +57,10 @@ void Mouse::souris_max() { // No implementation in original } +void Mouse::hideCursor() { +} + +void Mouse::showCursor() { +} + } // End of namespace Hopkins diff --git a/engines/hopkins/events.h b/engines/hopkins/events.h index c6fb6a3eab..3293d10b7a 100644 --- a/engines/hopkins/events.h +++ b/engines/hopkins/events.h @@ -46,6 +46,9 @@ public: void souris_on(); void souris_xy(int xp, int yp); void souris_max(); + + void hideCursor(); + void showCursor(); }; } // End of namespace Hopkins diff --git a/engines/hopkins/files.cpp b/engines/hopkins/files.cpp index 40cd238d1e..cf6c06f22c 100644 --- a/engines/hopkins/files.cpp +++ b/engines/hopkins/files.cpp @@ -107,7 +107,7 @@ byte *FileManager::CHARGE_FICHIER(const Common::String &file) { // Allocate space for the file contents size_t filesize = f.size(); - byte *data = (byte *)malloc(filesize); + byte *data = GLOBALS.dos_malloc2(filesize); if (!data) error("Error allocating space for file being loaded - %s", file.c_str()); diff --git a/engines/hopkins/globals.cpp b/engines/hopkins/globals.cpp index f6db20fe8f..1f00651f9c 100644 --- a/engines/hopkins/globals.cpp +++ b/engines/hopkins/globals.cpp @@ -203,9 +203,9 @@ void Globals::clearAll() { texte_long = 0; texte_tmp = PTRNUL; - BUFFERTAPE = (byte *)malloc(85000); + BUFFERTAPE = dos_malloc2(85000); - SAUVEGARDE = (byte *)malloc(2050); + SAUVEGARDE = dos_malloc2(2050); memset(SAUVEGARDE, 0, 1999); essai0 = BUFFERTAPE; @@ -215,14 +215,14 @@ void Globals::clearAll() { largeur_boite = 240; TEXTE_FORMATE = 300; - Bufferobjet = (byte *)malloc(2500); - INVENTAIRE_OBJET = (byte *)malloc(2500); + Bufferobjet = dos_malloc2(2500); + INVENTAIRE_OBJET = dos_malloc2(2500); ADR_FICHIER_OBJ = PTRNUL; FORETSPR = PTRNUL; FORET = 0; - cache_souris = (byte *)malloc(2500); + cache_souris = dos_malloc2(2500); GESTE = PTRNUL; GESTE_FLAG = false; } @@ -651,63 +651,10 @@ void Globals::CHARGE_OBJET() { free(data); } -byte *Globals::CHANGE_OBJET(int objIndex) { - byte *result = CAPTURE_OBJET(objIndex, 1); - Bufferobjet = result; - Nouv_objet = 1; - OBJET_EN_COURS = objIndex; - return result; -} - -byte *Globals::CAPTURE_OBJET(int objIndex, int mode) { - byte *result = NULL; - byte *dataP; - - dataP = 0; - int v2 = ObjetW[objIndex].field0; - int v3 = ObjetW[objIndex].field1; - - if (mode == 1) - ++v3; - if (v2 != NUM_FICHIER_OBJ) { - if (ADR_FICHIER_OBJ != PTRNUL) - ObjectManager::DEL_FICHIER_OBJ(); - if (v2 == 1) { - FileManager::CONSTRUIT_SYSTEM("OBJET1.SPR"); - ADR_FICHIER_OBJ = ObjectManager::CHARGE_SPRITE(NFICHIER); - } - NUM_FICHIER_OBJ = v2; - } - - int width = ObjectManager::Get_Largeur(ADR_FICHIER_OBJ, v3); - int height = ObjectManager::Get_Hauteur(ADR_FICHIER_OBJ, v3); - OBJL = width; - OBJH = height; - - switch (mode) { - case 0: - dataP = (byte *)malloc(height * width); - if (dataP == PTRNUL) - error("CAPTURE_OBJET"); - - ObjectManager::capture_mem_sprite(ADR_FICHIER_OBJ, dataP, v3); - break; - - case 1: - ObjectManager::sprite_alone(ADR_FICHIER_OBJ, Bufferobjet, v3); - result = Bufferobjet; - break; - - case 3: - ObjectManager::capture_mem_sprite(ADR_FICHIER_OBJ, INVENTAIRE_OBJET, v3); - result = INVENTAIRE_OBJET; - break; - - default: - result = dataP; - break; - } - +byte *Globals::dos_malloc2(int count) { + byte *result = (byte *)malloc(count); + if (!result) + result = PTRNUL; return result; } diff --git a/engines/hopkins/globals.h b/engines/hopkins/globals.h index 47100bb7ba..3289a49575 100644 --- a/engines/hopkins/globals.h +++ b/engines/hopkins/globals.h @@ -180,6 +180,7 @@ public: byte *essai1; byte *essai2; byte *Bufferobjet; + int INVENTAIRE[36]; byte *inventaire2; byte *GESTE; int OBJET_EN_COURS; @@ -200,6 +201,7 @@ public: bool redraw; int OBJL, OBJH; int Nouv_objet; + int HELICO; Globals(); ~Globals(); @@ -210,13 +212,9 @@ public: void INIT_ANIM(); void INIT_VBOB(); void CHARGE_OBJET(); - byte *CHANGE_OBJET(int objIndex); - byte *CAPTURE_OBJET(int objIndex, int mode); + byte *dos_malloc2(int count); }; -// TODO: The original pointed PTRNUL to a specially allocated memory block. If this proves -// to be necsesary, all malloc calls will need to be replaced with a stub that sets the -// result to PTRNUL if the memory block can't be allocated #define PTRNUL (byte *)NULL } // End of namespace Hopkins diff --git a/engines/hopkins/graphics.cpp b/engines/hopkins/graphics.cpp index 01a673f020..7b04e1f1ba 100644 --- a/engines/hopkins/graphics.cpp +++ b/engines/hopkins/graphics.cpp @@ -21,6 +21,7 @@ */ #include "common/system.h" +#include "engines/util.h" #include "hopkins/files.h" #include "hopkins/globals.h" #include "hopkins/graphics.h" @@ -28,9 +29,69 @@ namespace Hopkins { +byte *ObjectManager::CHANGE_OBJET(int objIndex) { + byte *result = ObjectManager::CAPTURE_OBJET(objIndex, 1); + GLOBALS.Bufferobjet = result; + GLOBALS.Nouv_objet = 1; + GLOBALS.OBJET_EN_COURS = objIndex; + return result; +} + +byte *ObjectManager::CAPTURE_OBJET(int objIndex, int mode) { + byte *result = NULL; + byte *dataP; + + dataP = 0; + int v2 = GLOBALS.ObjetW[objIndex].field0; + int v3 = GLOBALS.ObjetW[objIndex].field1; + + if (mode == 1) + ++v3; + if (v2 != GLOBALS.NUM_FICHIER_OBJ) { + if (GLOBALS.ADR_FICHIER_OBJ != PTRNUL) + ObjectManager::DEL_FICHIER_OBJ(); + if (v2 == 1) { + FileManager::CONSTRUIT_SYSTEM("OBJET1.SPR"); + GLOBALS.ADR_FICHIER_OBJ = ObjectManager::CHARGE_SPRITE(GLOBALS.NFICHIER); + } + GLOBALS.NUM_FICHIER_OBJ = v2; + } + + int width = ObjectManager::Get_Largeur(GLOBALS.ADR_FICHIER_OBJ, v3); + int height = ObjectManager::Get_Hauteur(GLOBALS.ADR_FICHIER_OBJ, v3); + GLOBALS.OBJL = width; + GLOBALS.OBJH = height; + + switch (mode) { + case 0: + dataP = GLOBALS.dos_malloc2(height * width); + if (dataP == PTRNUL) + error("CAPTURE_OBJET"); + + ObjectManager::capture_mem_sprite(GLOBALS.ADR_FICHIER_OBJ, dataP, v3); + break; + + case 1: + ObjectManager::sprite_alone(GLOBALS.ADR_FICHIER_OBJ, GLOBALS.Bufferobjet, v3); + result = GLOBALS.Bufferobjet; + break; + + case 3: + ObjectManager::capture_mem_sprite(GLOBALS.ADR_FICHIER_OBJ, GLOBALS.INVENTAIRE_OBJET, v3); + result = GLOBALS.INVENTAIRE_OBJET; + break; + + default: + result = dataP; + break; + } + + return result; +} + int ObjectManager::Get_Largeur(const byte *objectData, int objIndex) { const byte *objP = objectData + 3; - for (int i = objIndex; i; --i ) + for (int i = objIndex; i; --i) objP += READ_LE_UINT32(objP) + 16; return READ_LE_UINT16(objP + 4); @@ -85,4 +146,77 @@ int ObjectManager::capture_mem_sprite(const byte *objectData, byte *sprite, int return result; } +int ObjectManager::AJOUTE_OBJET(int objIndex) { + bool flag = false; + int arrIndex = 0; + do { + ++arrIndex; + if (!GLOBALS.INVENTAIRE[arrIndex]) + flag = true; + if (arrIndex == 32) + flag = true; + } while (!flag); + + GLOBALS.INVENTAIRE[arrIndex] = objIndex; + return arrIndex; +} + +GraphicsManager::GraphicsManager() { + SDL_MODEYES = false; +} + +void GraphicsManager::SET_MODE(int width, int height) { + if (!SDL_MODEYES) { + SDL_ECHELLE = 0; + + if (GLOBALS.XSETMODE == 1) + SDL_ECHELLE = 0; + if (GLOBALS.XSETMODE == 2) + SDL_ECHELLE = 25; + if (GLOBALS.XSETMODE == 3) + SDL_ECHELLE = 50; + if (GLOBALS.XSETMODE == 4) + SDL_ECHELLE = 75; + if (GLOBALS.XSETMODE == 5) + SDL_ECHELLE = GLOBALS.XZOOM; + + int bpp = 8; + if (GLOBALS.XFORCE8 == 1) + bpp = 8; + if (GLOBALS.XFORCE16 == 1) + bpp = 16; + + if (SDL_ECHELLE) { + error("TODO: Implement zooming support"); + //width = Reel_Zoom(a1, SDL_ECHELLE); + //height = Reel_Zoom(a2, SDL_ECHELLE); + } + + if (bpp == 8) + initGraphics(width, height, true); + else { + Graphics::PixelFormat pixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0); + initGraphics(width, height, true, &pixelFormat); + } + + XSCREEN = width; + YSCREEN = height; + + Linear = true; + Winbpp = bpp; + WinScan = width; + + PAL_PIXELS = SD_PIXELS; + nbrligne = width; + + for (int idx = 0; idx < 256; ++idx) { + cmap[idx].r = cmap[idx].g = cmap[idx].b = 0; + } + + SDL_MODEYES = true; + } else { + error("Called SET_MODE multiple times"); + } +} + } // End of namespace Hopkins diff --git a/engines/hopkins/graphics.h b/engines/hopkins/graphics.h index 523ab28575..de80160dda 100644 --- a/engines/hopkins/graphics.h +++ b/engines/hopkins/graphics.h @@ -29,8 +29,17 @@ namespace Hopkins { +struct RGB8 { + byte r; + byte g; + byte b; +}; + class ObjectManager { public: + static byte *CHANGE_OBJET(int objIndex); + static byte *CAPTURE_OBJET(int objIndex, int mode); + static int Get_Largeur(const byte *objectData, int objIndex); static int Get_Hauteur(const byte *objectData, int objIndex); static int sprite_alone(const byte *objectData, byte *sprite, int objIndex); @@ -38,6 +47,26 @@ public: static byte *CHARGE_SPRITE(const Common::String &file); static int capture_mem_sprite(const byte *objectData, byte *sprite, int objIndex); + static int AJOUTE_OBJET(int objIndex); +}; + +class GraphicsManager { +public: + bool SDL_MODEYES; + int SDL_ECHELLE; + int XSCREEN; + int YSCREEN; + int WinScan; + int Winbpp; + byte SD_PIXELS[514]; + byte *PAL_PIXELS; + int nbrligne; + RGB8 cmap[256]; + bool Linear; +public: + GraphicsManager(); + + void SET_MODE(int width, int height); }; } // End of namespace Hopkins diff --git a/engines/hopkins/hopkins.cpp b/engines/hopkins/hopkins.cpp index ecadd25953..342d7d2361 100644 --- a/engines/hopkins/hopkins.cpp +++ b/engines/hopkins/hopkins.cpp @@ -25,7 +25,7 @@ #include "common/debug-channels.h" #include "common/events.h" #include "common/file.h" -#include "engines/util.h" +#include "hopkins/graphics.h" #include "hopkins/hopkins.h" #include "hopkins/files.h" #include "hopkins/sound.h" @@ -60,12 +60,13 @@ Common::Error HopkinsEngine::run() { SoundManager::WSOUND_INIT(); GLOBALS.CHARGE_OBJET(); + ObjectManager::CHANGE_OBJET(14); + ObjectManager::AJOUTE_OBJET(14); + + GLOBALS.HELICO = 0; + _mouse.hideCursor(); /* - CHANGE_OBJET(14); - AJOUTE_OBJET(14); - HELICO = 0; - SDL_ShowCursor(0); DD_Lock(); Cls_Video(); DD_Unlock(); @@ -499,7 +500,8 @@ void HopkinsEngine::processIniParams(Common::StringMap &iniParams) { } void HopkinsEngine::INIT_SYSTEM() { - initGraphics(640, 480, true); + // Set graphics mode + _graphicsManager.SET_MODE(640, 480); // TODO: init surfaces //VESA_SCREEN = dos_malloc2(0x96000u); diff --git a/engines/hopkins/hopkins.h b/engines/hopkins/hopkins.h index 641be0113a..5f6b19d47a 100644 --- a/engines/hopkins/hopkins.h +++ b/engines/hopkins/hopkins.h @@ -33,6 +33,7 @@ #include "graphics/surface.h" #include "hopkins/events.h" #include "hopkins/globals.h" +#include "hopkins/graphics.h" /** * This is the namespace of the Hopkins engine. @@ -65,6 +66,7 @@ private: Graphics::Surface VESA_SCREEN; Graphics::Surface VESA_BUFFER; Mouse _mouse; + GraphicsManager _graphicsManager; /** * Processes the loaded list of ini file parameters -- cgit v1.2.3