Skip to content

Commit

Permalink
HOPKINS: Implement proper graphics initialisation code
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Sep 8, 2012
1 parent ca84b27 commit ecee539
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 77 deletions.
8 changes: 6 additions & 2 deletions engines/hopkins/events.cpp
Expand Up @@ -30,8 +30,6 @@ void Mouse::INSTALL_SOURIS() {
}

void Mouse::souris_on() {
bool result; // eax@5

souris_flag = true;

if (mouse_linux) {
Expand Down Expand Up @@ -59,4 +57,10 @@ void Mouse::souris_max() {
// No implementation in original
}

void Mouse::hideCursor() {
}

void Mouse::showCursor() {
}

} // End of namespace Hopkins
3 changes: 3 additions & 0 deletions engines/hopkins/events.h
Expand Up @@ -46,6 +46,9 @@ class Mouse {
void souris_on();
void souris_xy(int xp, int yp);
void souris_max();

void hideCursor();
void showCursor();
};

} // End of namespace Hopkins
Expand Down
2 changes: 1 addition & 1 deletion engines/hopkins/files.cpp
Expand Up @@ -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());

Expand Down
71 changes: 9 additions & 62 deletions engines/hopkins/globals.cpp
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 3 additions & 5 deletions engines/hopkins/globals.h
Expand Up @@ -180,6 +180,7 @@ class Globals {
byte *essai1;
byte *essai2;
byte *Bufferobjet;
int INVENTAIRE[36];
byte *inventaire2;
byte *GESTE;
int OBJET_EN_COURS;
Expand All @@ -200,6 +201,7 @@ class Globals {
bool redraw;
int OBJL, OBJH;
int Nouv_objet;
int HELICO;

Globals();
~Globals();
Expand All @@ -210,13 +212,9 @@ class Globals {
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
Expand Down
136 changes: 135 additions & 1 deletion engines/hopkins/graphics.cpp
Expand Up @@ -21,16 +21,77 @@
*/

#include "common/system.h"
#include "engines/util.h"
#include "hopkins/files.h"
#include "hopkins/globals.h"
#include "hopkins/graphics.h"
#include "hopkins/hopkins.h"

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);
Expand Down Expand Up @@ -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
29 changes: 29 additions & 0 deletions engines/hopkins/graphics.h
Expand Up @@ -29,15 +29,44 @@

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);
static byte *DEL_FICHIER_OBJ();

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
Expand Down

0 comments on commit ecee539

Please sign in to comment.