Add cruise source code for scummvm

svn-id: r26605
This commit is contained in:
Vincent Hamm 2007-04-27 12:58:35 +00:00
parent edd9b31a48
commit c01aa37caa
55 changed files with 17390 additions and 0 deletions

1080
engines/cruise/actor.cpp Normal file

File diff suppressed because it is too large Load diff

74
engines/cruise/actor.h Normal file
View file

@ -0,0 +1,74 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _ACTOR_H_
#define _ACTOR_H_
namespace Cruise {
enum animPhase
{
ANIM_PHASE_WAIT = 0,
ANIM_PHASE_STATIC = 1,
ANIM_PHASE_MOVE = 2,
ANIM_PHASE_STATIC_END = 3,
ANIM_PHASE_END = 4,
};
typedef enum animPhase animPhase;
struct actorStruct {
struct actorStruct* next;
struct actorStruct* prev;
int16 var4;
int16 type;
int16 overlayNumber;
int16 x_dest;
int16 y_dest;
int16 x;
int16 y;
int16 startDirection;
int16 nextDirection;
int16 endDirection;
int16 stepX;
int16 stepY;
int16 pathId;
animPhase phase;
int16 counter;
int16 poly;
int16 flag;
int16 start;
int16 freeze;
};
typedef struct actorStruct actorStruct;
int16 mainProc13(int overlayIdx, int param1, actorStruct* pStartEntry, int param2);
actorStruct* findActor(int overlayIdx, int param1, actorStruct* pStartEntry, int param2);
void processActors(void);
void getPixel(int x, int y);
} // End of namespace Cruise
#endif

View file

@ -0,0 +1,220 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
uint8 colorMode = 0;
uint8* backgroundPtrtable[8] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; // wasn't initialized in original, but it's probably better
backgroundTableStruct backgroundTable[8];
char hwPage[64000];
char* hwMemAddr[] =
{
hwPage,
};
short int cvtPalette[0x20];
int loadMEN(uint8** ptr)
{
char* localPtr = (char*)*ptr;
if(!strcmp(localPtr,"MEN"))
{
localPtr+=4;
video4 = *(localPtr++);
video3 = *(localPtr++);
video2 = *(localPtr++);
colorOfSelectedSaveDrive = *(localPtr++);
*ptr = (uint8*)localPtr;
return 1;
}
else
{
return 0;
}
}
int CVTLoaded;
int loadCVT(uint8** ptr)
{
char* localPtr = (char*)*ptr;
if(!strcmp(localPtr,"CVT"))
{
int i;
localPtr+=4;
for(i=0;i<0x20;i++)
{
cvtPalette[i] = *(localPtr++);
}
*ptr = (uint8*)localPtr;
CVTLoaded = 1;
return 1;
}
else
{
CVTLoaded = 0;
return 0;
}
}
extern int lastFileSize;
int loadBackground(char* name, int idx)
{
uint8* ptr;
uint8* ptr2;
uint8* ptrToFree;
printf("Loading BG: %s\n",name);
if(!backgroundPtrtable[idx])
{
//if(!gfxModuleData.useEGA && !gfxModuleData.useVGA)
{
backgroundPtrtable[idx] = (uint8*)mallocAndZero(320*200/*64000*/);
}
/* else
{
backgroundPtrtable[idx] = hwMemAddr[idx];
} */
}
if(!backgroundPtrtable[idx])
{
backgroundTable[idx].name[0] = 0;
return(-2);
}
ptrToFree = gfxModuleData.pPage10;
if(loadFileSub1(&ptrToFree,(uint8*)name,NULL)<0)
{
if(ptrToFree != gfxModuleData.pPage10)
free(ptrToFree);
return(-18);
}
if(lastFileSize == 32078 || lastFileSize == 32080 || lastFileSize == 32034)
{
colorMode = 0;
}
else
{
colorMode = 1;
}
ptr = ptrToFree;
ptr2 = ptrToFree;
if(!strcmpuint8(name,"LOGO.PI1"))
{
bgVar3=bgVar2;
bgVar1=1;
bgVar2=1;
}
else
{
if(bgVar1)
{
bgVar2=bgVar3;
bgVar1=0;
}
}
if(!strcmpuint8(ptr,"PAL"))
{
printf("Pal loading unsupported !\n");
exit(1);
}
else
{
if(!colorMode || ptr2[1] == 5)
{
ptr2+=2;
memcpy(palette,ptr2,0x20);
ptr2+=0x20;
flipGen(palette,0x20);
ptr2 += 0x7D00;
loadMEN(&ptr2);
loadCVT(&ptr2);
gfxModuleData_gfxClearFrameBuffer(backgroundPtrtable[idx]);
gfxModuleData_field_60((char*)ptrToFree+34, 20, 200, (char*)backgroundPtrtable[idx], 0, 0);
gfxModuleData_setPal((uint8*)(palette + (idx << 6)));
}
else
if(ptr2[1] == 8)
{
int i;
ptr2+=2;
for(i=0;i<256*3;i++)
{
palette[i] = ptr2[i];
}
//memcpy(palette,ptr2,256*3);
ptr2+=256*3;
memcpy(backgroundPtrtable[idx], ptr2, 320*200);
gfxModuleData_setPal256(palette);
}
}
//if(ptrToFree != gfxModuleData.pPage10)
// free(ptrToFree);
if(gfxModuleData.useEGA || gfxModuleData.useTandy)
{
ASSERT(0);
}
if(gfxModuleData.useEGA || gfxModuleData.useTandy)
{
ASSERT(0);
}
strcpy(backgroundTable[idx].name, name);
return(0);
}
} // End of namespace Cruise

View file

@ -0,0 +1,46 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _BACKGROUND_H_
#define _BACKGROUND_H_
namespace Cruise {
struct backgroundTableStruct
{
char name[9];
char extention[6];
};
typedef struct backgroundTableStruct backgroundTableStruct;
extern short int cvtPalette[0x20];
extern int CVTLoaded;
extern uint8* backgroundPtrtable[8];
extern backgroundTableStruct backgroundTable[8];
int loadBackground(char* name, int idx);
} // End of namespace Cruise
#endif

View file

@ -0,0 +1,222 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
backgroundIncrustStruct backgroundIncrustHead;
void resetBackgroundIncrustList(backgroundIncrustStruct* pHead)
{
pHead->next = NULL;
pHead->prev = NULL;
}
// blit background to another one
void addBackgroundIncrustSub1(int fileIdx, int X, int Y, char* ptr2, int16 scale, char* destBuffer, char* dataPtr)
{
if(*dataPtr == 0)
{
ASSERT(0);
}
buildPolyModel(X, Y, scale, ptr2, destBuffer, dataPtr);
}
backgroundIncrustStruct* addBackgroundIncrust(int16 overlayIdx,int16 objectIdx,backgroundIncrustStruct* pHead,int16 scriptNumber,int16 scriptOverlay, int16 backgroundIdx, int16 param4)
{
uint8* backgroundPtr;
uint8* ptr;
objectParamsQuery params;
backgroundIncrustStruct* newElement;
backgroundIncrustStruct* currentHead;
backgroundIncrustStruct* currentHead2;
getMultipleObjectParam(overlayIdx,objectIdx,&params);
ptr = filesDatabase[params.fileIdx].subData.ptr;
if(!ptr)
{
return NULL;
}
if(filesDatabase[params.fileIdx].subData.resourceType != 4 && filesDatabase[params.fileIdx].subData.resourceType != 8)
{
return NULL;
}
backgroundPtr = backgroundPtrtable[backgroundIdx];
if(!backgroundPtr)
{
ASSERT(0);
return NULL;
}
currentHead = pHead;
currentHead2 = currentHead->next;
while(currentHead2)
{
currentHead = currentHead2;
currentHead2 = currentHead->next;
}
newElement = (backgroundIncrustStruct*)mallocAndZero(sizeof(backgroundIncrustStruct));
if(!newElement)
return NULL;
newElement->next = currentHead->next;
currentHead->next = newElement;
if(!currentHead2)
{
currentHead2 = pHead;
}
newElement->prev = currentHead2->prev;
currentHead2->prev = newElement;
newElement->objectIdx = objectIdx;
newElement->field_6 = param4;
newElement->backgroundIdx = backgroundIdx;
newElement->overlayIdx = overlayIdx;
newElement->scriptNumber = scriptNumber;
newElement->scriptOverlayIdx = scriptOverlay;
newElement->X = params.X;
newElement->Y = params.Y;
newElement->scale = params.scale;
newElement->field_E = params.fileIdx;
newElement->var34 = filesDatabase[params.fileIdx].subData.index;
newElement->ptr = NULL;
strcpy(newElement->name, filesDatabase[params.fileIdx].subData.name);
if(filesDatabase[params.fileIdx].subData.resourceType == 4) // sprite
{
int width = filesDatabase[params.fileIdx].width;
int height = filesDatabase[params.fileIdx].height;
currentTransparent = filesDatabase[params.fileIdx].subData.transparency;
mainDrawSub4(width, height, NULL, (char*)filesDatabase[params.fileIdx].subData.ptr, newElement->Y, newElement->X, (char*)backgroundPtr, (char*)filesDatabase[params.fileIdx].subData.ptr);
// ASSERT(0);
}
else // poly
{
/* if(param4 == 1)
{
int var_A;
int var_8;
int var_6;
char* var_10;
mainDrawSub1Sub1(lvar[3], newElement->X, newElement->Y, &var_A, &var_8, &var_6, &var_10, lvar[4], filesDatabase[lvar[3]].subData.ptr);
ASSERT(0);
}*/
addBackgroundIncrustSub1(params.fileIdx, newElement->X, newElement->Y, NULL, params.scale, (char*)backgroundPtr, (char*)filesDatabase[params.fileIdx].subData.ptr );
}
return newElement;
}
void loadBackgroundIncrustFromSave(FILE* fileHandle)
{
int16 numEntry;
backgroundIncrustStruct* ptr1;
backgroundIncrustStruct* ptr2;
int32 i;
fread(&numEntry,2,1,fileHandle);
ptr1 = &backgroundIncrustHead;
ptr2 = &backgroundIncrustHead;
for(i=0;i<numEntry;i++)
{
backgroundIncrustStruct* current = (backgroundIncrustStruct*)mallocAndZero(sizeof(backgroundIncrustStruct));
fseek(fileHandle, 4, SEEK_CUR);
fread(&current->objectIdx,2,1,fileHandle);
fread(&current->field_6,2,1,fileHandle);
fread(&current->overlayIdx,2,1,fileHandle);
fread(&current->X,2,1,fileHandle);
fread(&current->Y,2,1,fileHandle);
fread(&current->field_E,2,1,fileHandle);
fread(&current->scale,2,1,fileHandle);
fread(&current->backgroundIdx,2,1,fileHandle);
fread(&current->scriptNumber,2,1,fileHandle);
fread(&current->scriptOverlayIdx,2,1,fileHandle);
fread(&current->ptr,4,1,fileHandle);
fread(&current->field_1C,4,1,fileHandle);
fread(&current->size,2,1,fileHandle);
fread(&current->field_22,2,1,fileHandle);
fread(&current->field_24,2,1,fileHandle);
fread(current->name,14,1,fileHandle);
fread(&current->var34,2,1,fileHandle);
if(current->size)
{
current->ptr = (uint8*)mallocAndZero(current->size);
fread(current->ptr,current->size,1,fileHandle);
}
current->next = NULL;
ptr2 = current;
current->prev = backgroundIncrustHead.prev;
backgroundIncrustHead.prev = current;
ptr2 = current->next;
}
}
void regenerateBackgroundIncrust(backgroundIncrustStruct* pHead)
{
printf("Need to regenerate backgroundIncrust\n");
}
void freeBackgroundIncrustList(backgroundIncrustStruct* pHead)
{
backgroundIncrustStruct* pCurrent = pHead->next;
while(pCurrent)
{
backgroundIncrustStruct* pNext = pCurrent->next;
if(pCurrent->ptr)
{
free(pCurrent->ptr);
}
free(pCurrent);
pCurrent = pNext;
}
resetBackgroundIncrustList(pHead);
}
} // End of namespace Cruise

View file

@ -0,0 +1,66 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _BACKGROUNDINCRUST_H_
#define _BACKGROUNDINCRUST_H_
namespace Cruise {
struct backgroundIncrustStruct {
struct backgroundIncrustStruct* next;
struct backgroundIncrustStruct* prev;
uint16 objectIdx;
uint16 field_6;
uint16 overlayIdx;
uint16 X;
uint16 Y;
uint16 field_E;
uint16 scale;
uint16 backgroundIdx;
uint16 scriptNumber;
uint16 scriptOverlayIdx;
uint8* ptr;
int32 field_1C;
int16 size;
uint16 field_22;
uint16 field_24;
char name[14];
uint16 var34;
};
typedef struct backgroundIncrustStruct backgroundIncrustStruct;
extern backgroundIncrustStruct backgroundIncrustHead;
void resetBackgroundIncrustList(backgroundIncrustStruct* pHead);
backgroundIncrustStruct* addBackgroundIncrust(int16 overlayIdx,int16 param2,backgroundIncrustStruct* pHead,int16 scriptNumber,int16 scriptOverlay, int16 backgroundIdx, int16 param4);
void loadBackgroundIncrustFromSave(FILE* fileHandle);
void regenerateBackgroundIncrust(backgroundIncrustStruct* pHead);
void freeBackgroundIncrustList(backgroundIncrustStruct* pHead);
} // End of namespace Cruise
#endif

111
engines/cruise/cruise.cpp Normal file
View file

@ -0,0 +1,111 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "common/stdafx.h"
#include "common/file.h"
#include "common/fs.h"
#include "common/savefile.h"
#include "common/config-manager.h"
#include "common/system.h"
#include "graphics/cursorman.h"
#include "sound/mididrv.h"
#include "sound/mixer.h"
#include "cruise/cruise.h"
namespace Cruise {
//SoundDriver *g_soundDriver;
//SfxPlayer *g_sfxPlayer;
Common::SaveFileManager *g_saveFileMan;
CruiseEngine *g_cruise;
CruiseEngine::CruiseEngine(OSystem *syst) : Engine(syst) {
Common::addSpecialDebugLevel(kCruiseDebugScript, "Script", "Script debug level");
// Setup mixer
if (!_mixer->isReady()) {
warning("Sound initialization failed.");
}
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
g_cruise = this;
}
CruiseEngine::~CruiseEngine() {
}
int CruiseEngine::init() {
// Detect game
if (!initGame()) {
GUIErrorMessage("No valid games were found in the specified directory.");
return -1;
}
// Initialize backend
_system->beginGFXTransaction();
initCommonGFX(false);
_system->initSize(320, 200);
_system->endGFXTransaction();
initialize();
return 0;
}
int CruiseEngine::go() {
CursorMan.showMouse(true);
Cruise::mainLoop();
return 0;
}
void CruiseEngine::initialize() {
fadeVar = 0;
ptr_something = (ctpVar19Struct*)mallocAndZero(sizeof(ctpVar19Struct)*0x200);
/*volVar1 = 0;
fileData1 = 0;*/
/*PAL_fileHandle = -1;*/
// video init stuff
loadSystemFont();
// another bit of video init
readVolCnf();
}
} // End of namespace Cruise

107
engines/cruise/cruise.h Normal file
View file

@ -0,0 +1,107 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CruisE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef CRUISE_H
#define CRUISE_H
#include "common/stdafx.h"
#include "common/scummsys.h"
#include "common/util.h"
#include "engines/engine.h"
#include "cruise/cruise_main.h"
namespace Cruise {
enum CruiseGameType {
GType_CRUISE = 1
};
struct CRUISEGameDescription;
class CruiseEngine : public Engine {
protected:
int init();
int go();
void shutdown();
bool initGame();
public:
CruiseEngine(OSystem *syst);
virtual ~CruiseEngine();
int getGameType() const;
uint32 getFeatures() const;
Common::Language getLanguage() const;
Common::Platform getPlatform() const;
bool loadSaveDirectory(void);
void makeSystemMenu(void);
const CRUISEGameDescription *_gameDescription;
private:
void initialize(void);
bool makeLoad(char *saveName);
void mainLoop(int bootScriptIdx);
bool _preLoad;
};
extern CruiseEngine *g_cruise;
#define BOOT_PRC_NAME "AUTO00.PRC"
enum {
VAR_MOUSE_X_MODE = 253,
VAR_MOUSE_X_POS = 249,
VAR_MOUSE_Y_MODE = 251,
VAR_MOUSE_Y_POS = 250
};
enum {
MOUSE_CURSOR_NORMAL = 0,
MOUSE_CURSOR_DISK,
MOUSE_CURSOR_CROSS
};
enum {
kCruiseDebugScript = 1 << 0
};
enum {
kCmpEQ = (1 << 0),
kCmpGT = (1 << 1),
kCmpLT = (1 << 2)
};
extern Common::SaveFileManager *g_saveFileMan; // TEMP
} // End of namespace Cruise
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,101 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _CRUISE_H_
#define _CRUISE_H_
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include "common/stdafx.h"
#include "common/scummsys.h"
#include "cruise/overlay.h"
#include "cruise/object.h"
#include "cruise/ctp.h"
#include "cruise/actor.h"
#include "cruise/vars.h"
#include "cruise/font.h"
#include "cruise/volume.h"
#include "cruise/fontCharacterTable.h"
#include "cruise/stack.h"
#include "cruise/script.h"
#include "cruise/various.h"
#include "cruise/stringSupport.h"
#include "cruise/function.h"
#include "cruise/loadSave.h"
#include "cruise/linker.h"
#include "cruise/mouse.h"
#include "cruise/gfxModule.h"
#include "cruise/dataLoader.h"
#include "cruise/perso.h"
#include "cruise/menu.h"
#include "cruise/background.h"
#include "cruise/backgroundIncrust.h"
#include "cruise/mainDraw.h"
namespace Cruise {
/*#define DUMP_SCRIPT
#define DUMP_OBJECT*/
#define ASSERT_PTR assert
#define ASSERT assert
int32 decomp(uint8 * in, uint8 * out, int32 size);
ovlData3Struct* getOvlData3Entry(int32 scriptNumber, int32 param);
ovlData3Struct* scriptFunc1Sub2(int32 scriptNumber, int32 param);
int16 loadShort(void* ptr);
void resetFileEntry(int32 entryNumber);
void saveShort(void* ptr, int16 var);
void* mallocAndZero(int32 size);
uint8* mainProc14(uint16 overlay, uint16 idx);
void printInfoBlackBox(char* string);
void waitForPlayerInput(void);
int loadCtp(uint8* ctpName);
void loadPakedFileToMem(int fileIdx, uint8* buffer);
int loadScriptSub1(int scriptIdx, int param);
void resetFileEntryRange(int param1, int param2);
int getProcParam(int overlayIdx, int param2, uint8* name);
void changeScriptParamInList(int param1, int param2, scriptInstanceStruct* pScriptInstance,int newValue, int param3);
uint8* getDataFromData3(ovlData3Struct* ptr, int param);
int32 prepareWordRender(int32 param, int32 var1,int16* out2, uint8* ptr3,uint8* string);
void removeExtention(const char* name, char* buffer);
void resetRaster(uint8* rasterPtr, int32 rasterSize);
void changeCursor(uint16 cursorType);
void resetPtr(objectStruct* ptr);
void resetPtr2(scriptInstanceStruct* ptr);
void getFileExtention(const char* name,char* buffer);
void *allocAndZero(int size);
void freeStuff2(void);
char* getObjectName(int index, uint8* string);
void mainLoop(void);
} // End of namespace Cruise
#endif

423
engines/cruise/ctp.cpp Normal file
View file

@ -0,0 +1,423 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
ctpVar19Struct* ptr_something;
ctpVar19Struct* polyStruct;
ctpVar19Struct* ctpVar11;
ctpVar19Struct* ctpVar13;
ctpVar19Struct* ctpVar15;
uint8* ctpVar17;
ctpVar19Struct* ctpVar19;
int currentWalkBoxCenterX;
int currentWalkBoxCenterY;
int currentWalkBoxCenterXBis;
int currentWalkBoxCenterYBis;
int ctpVarUnk;
uint8 walkboxTable[0x12];
int ctpProc2(int varX, int varY, int paramX, int paramY)
{
int diffX = abs(paramX - varX);
int diffY = abs(paramY - varY);
if(diffX > diffY)
{
diffY = diffX;
}
ctpVar14 = diffY; // highest difference
return(diffY);
}
// this function process path finding coordinates
void loadCtpSub2(short int coordCount, short int* ptr) // coordCount = ctp_routeCoordCount, ptr = ctpVar8
{
int i;
int offset = 0;
short int* cur_ctp_routeCoords = (short int*)ctp_routeCoords; // coordinates table
int8* cur_ctp_routes = (int8*)ctp_routes;
for(i = 0; i < coordCount; i++) // for i < ctp_routeCoordCount
{
int varX = cur_ctp_routeCoords[0]; // x
int varY = cur_ctp_routeCoords[1]; // y
int di = 0;
int var4Offset = 2;
while(*(int16*) cur_ctp_routes > di) // while (coordCount > counter++)
{
int idx = *(int16*)(cur_ctp_routes + var4Offset);
ptr[offset + idx] = ctpProc2(varX , varY, ctp_routeCoords[idx][0], ctp_routeCoords[idx * 2][1]);
var4Offset += 2;
di++;
}
offset += 10;
cur_ctp_routes += 20;
cur_ctp_routeCoords += 2;
}
}
void getWalkBoxCenter(int boxIdx, uint16* walkboxTable)
{
int minX = 1000;
int minY = 1000;
int maxX = -1;
int maxY = -1;
ASSERT(boxIdx <= 15); // max number of walkboxes is 16
ASSERT(walkboxTable[boxIdx * 40]); // we should never have an empty walk box
if(walkboxTable[boxIdx * 40] > 0)
{
int numPoints = walkboxTable[boxIdx * 40];
uint16* pCurrentPtr = walkboxTable + (boxIdx * 40) + 1;
int i;
for(i = 0; i < numPoints; i++)
{
int X = *(pCurrentPtr++);
int Y = *(pCurrentPtr++);;
if(X < minX)
minX = X;
if(X > maxX)
maxX = X;
if(Y < minY)
minY = Y;
if(Y > maxY)
maxY = Y;
}
}
currentWalkBoxCenterX = ((maxX - minX) / 2) + minX;
currentWalkBoxCenterY = ((maxY - minY) / 2) + minY;
}
// ax dx bx
void renderCTPWalkBox(int X1, int Y1, int X2, int scale, int Y2, uint16* walkboxData)
{
int numPoints;
int wbSelf1;
int wbSelf2;
int i;
int16* destination;
wbSelf1 = upscaleValue(X1, scale) - X2;
wbSelf2 = upscaleValue(Y1, scale) - Y2;
numPoints = *(walkboxData++);
destination = polyBuffer2;
for(i = 0; i < numPoints; i++)
{
int pointX = *(walkboxData++);
int pointY = *(walkboxData++);
int scaledX = upscaleValue(pointX, scale) - wbSelf1;
int scaledY = upscaleValue(pointY, scale) - wbSelf2;
*(destination++) = scaledX >> 16;
*(destination++) = scaledY >> 16;
}
m_color = 0;
ctpVarUnk = 0;
for(i = 0; i < numPoints; i++)
{
walkboxTable[i] = i;
}
drawPolyMode2((char*)walkboxTable, numPoints);
}
// this process the walkboxes
void loadCtpSub1(int boxIdx, int scale, uint16* walkboxTable, ctpVar19Struct* param4)
{
int minX = 1000;
int minY = 1000;
int maxX = -1;
int maxY = -1;
ctpVar19Struct* var_1C;
ctpVar19Struct* var_12;
int16* var_18;
int16* si;
// int16* di;
// uint8* cx;
// int bx;
// int ax;
// int var_2;
int var_E;
int var_C = 1000;
int var_A = 0;
ctpVar19SubStruct* subStruct;
ASSERT(boxIdx <= 15);
if(walkboxTable[boxIdx * 40] > 0) // is walkbox used ?
{
getWalkBoxCenter(boxIdx, walkboxTable);
currentWalkBoxCenterYBis = currentWalkBoxCenterY;
currentWalkBoxCenterXBis = currentWalkBoxCenterX;
// + 512
renderCTPWalkBox(currentWalkBoxCenterX, currentWalkBoxCenterY, currentWalkBoxCenterX, scale + 0x200, currentWalkBoxCenterY, walkboxTable + boxIdx * 40);
var_1C = param4;
var_12 = var_1C + 1; // next
var_18 = polyBuffer3;
var_E = 0;
si = &polyBuffer3[1];
/* if(*si>=0)
{
di = si;
cx = var_12;
do
{
di++;
bx = di[-1];
ax = di[0];
di++;
var_2 = ax;
if(var_C < bx)
{
var_C = bx;
}
if(var_2 < var_A)
{
var_A = var_2;
}
*cx = bx;
cx++;
*cx = var_2;
cx++;
var_E ++;
}while(di);
var_12 = cx;
}*/
/*************/
{
int i;
int numPoints;
uint16* pCurrentPtr = walkboxTable + boxIdx * 40;
numPoints = *(pCurrentPtr++);
for(i = 0; i < numPoints; i++)
{
int X = *(pCurrentPtr++);
int Y = *(pCurrentPtr++);
if(X < minX)
minX = X;
if(X > maxX)
maxX = X;
if(Y < minY)
minY = Y;
if(Y > maxY)
maxY = Y;
}
}
/************/
var_1C->field_0 = var_12;
ctpVar13 = var_12;
var_12->field_0 = (ctpVar19Struct*)(-1);
subStruct = &var_1C->subStruct;
subStruct->boxIdx = boxIdx;
subStruct->type = walkboxType[boxIdx];
subStruct->minX = minX;
subStruct->maxX = maxX;
subStruct->minY = minY;
subStruct->maxY = maxY;
}
}
int loadCtp(uint8* ctpName)
{
int walkboxCounter; // si
uint8* ptr;
uint8* dataPointer; // ptr2
char fileType[5]; // string2
short int segementSizeTable[7]; // tempTable
char string[32];
if(ctpVar1 == 0)
{
int i;
for(i = 0; i < 10; i++)
{
persoTable[i] = NULL;
}
}
if(!loadFileSub1(&ptr,ctpName,0))
{
free(ptr);
return(-18);
}
dataPointer = ptr;
fileType[4] = 0;
memcpy(fileType, dataPointer, 4); // get the file type, first 4 bytes of the CTP file
dataPointer += 4;
if(strcmp(fileType, "CTP "))
{
free(ptr);
return(0);
}
memcpy(&ctp_routeCoordCount , dataPointer, 2); // get the number of path-finding coordinates
dataPointer += 2;
flipShort(&ctp_routeCoordCount);
memcpy(segementSizeTable, dataPointer, 0xE);
dataPointer += 0xE; // + 14
flipGen(segementSizeTable, 0xE);
memcpy(ctp_routeCoords, dataPointer, segementSizeTable[0]); // get the path-finding coordinates
dataPointer += segementSizeTable[0];
flipGen(ctp_routeCoords, segementSizeTable[0]);
memcpy(ctp_routes, dataPointer, segementSizeTable[1]); // get the path-finding line informations (indexing the routeCoords array)
dataPointer += segementSizeTable[1];
flipGen(ctp_routes, segementSizeTable[1]);
memcpy(ctp_walkboxTable, dataPointer, segementSizeTable[2]);// get the walkbox coordinates and lines
dataPointer += segementSizeTable[2];
flipGen(ctp_walkboxTable, segementSizeTable[2]);
if(ctpVar1)
{
dataPointer += segementSizeTable[3];
dataPointer += segementSizeTable[4];
}
else
{
memcpy(walkboxType, dataPointer, segementSizeTable[3]); // get the walkbox type
dataPointer += segementSizeTable[3];
flipGen(walkboxType, segementSizeTable[3]); // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone
memcpy(walkboxChange, dataPointer, segementSizeTable[4]); // change indicator, walkbox type can change, i.e. blocked by object (values are either 0x00 or 0x01)
dataPointer += segementSizeTable[4];
flipGen(walkboxChange, segementSizeTable[4]);
}
memcpy(ctpVar6, dataPointer, segementSizeTable[5]); // unknown? always 2*16 bytes (used by S24.CTP, S33.CTP, S33_2.CTP, S34.CTP, S35.CTP, S36.CTP; values can be 0x00, 0x01, 0x03, 0x05)
dataPointer += segementSizeTable[5];
flipGen(ctpVar6,segementSizeTable[5]);
memcpy(ctp_scale, dataPointer, segementSizeTable[6]); // scale values for the walkbox coordinates (don't know why there is a need for scaling walkboxes)
dataPointer += segementSizeTable[6];
flipGen(ctp_scale, segementSizeTable[6]); // ok
free(ptr);
strcpyuint8(string, currentCtpName);
numberOfWalkboxes = segementSizeTable[6] / 2; // get the number of walkboxes
loadCtpSub2(ctp_routeCoordCount, ctpVar8); // process path-finding stuff
polyStruct = ctpVar11 = ctpVar13 = ptr_something;
ptr = (uint8*) polyStruct;
walkboxCounter = numberOfWalkboxes;
while((--walkboxCounter) >= 0)
{
loadCtpSub1(walkboxCounter, 0, ctp_walkboxTable, ctpVar13);
}
ctpVar15 = ctpVar13 + 1; // was after the -1 thing
walkboxCounter = numberOfWalkboxes;
while(--walkboxCounter)
{
loadCtpSub1(walkboxCounter, ctp_scale[walkboxCounter] * 20, ctp_walkboxTable, ctpVar13);
}
//ctpVar17 = ctpVar13 - ptr + 4;
{
int numOfUsedEntries = ctpVar13 - (ctpVar19Struct*) ptr;
numOfUsedEntries++;// there is a -1 entry at the end... Original was only mallocing numOfUsedEntries*sizeof(ctpVar19Struct)+4, but this is a bit ugly...
ctpVar13 = ctpVar11 = polyStruct = (ctpVar19Struct*)malloc(numOfUsedEntries * sizeof(ctpVar19Struct));
}
walkboxCounter = numberOfWalkboxes;
while((--walkboxCounter) >= 0)
{
loadCtpSub1(walkboxCounter, 0, ctp_walkboxTable, ctpVar13);
}
ctpVar15 = ctpVar13 + 1;
walkboxCounter = numberOfWalkboxes;
while(--walkboxCounter)
{
loadCtpSub1(walkboxCounter, ctp_scale[walkboxCounter] * 20, ctp_walkboxTable, ctpVar13);
}
ctpVar19 = ctpVar11;
return(1);
}
} // End of namespace Cruise

64
engines/cruise/ctp.h Normal file
View file

@ -0,0 +1,64 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _CTP_H_
#define _CTP_H_
namespace Cruise {
struct ctpVar19SubStruct
{
uint16 boxIdx; //0
uint16 type; //2
uint16 minX; //4
uint16 maxX; //6
uint16 minY; //8
uint16 maxY; //A
};
typedef struct ctpVar19SubStruct ctpVar19SubStruct;
struct ctpVar19Struct
{
struct ctpVar19Struct* field_0; //0
ctpVar19SubStruct subStruct;
};
typedef struct ctpVar19Struct ctpVar19Struct;
extern ctpVar19Struct* ptr_something;
extern ctpVar19Struct* polyStruct;
extern ctpVar19Struct* ctpVar11;
extern ctpVar19Struct* ctpVar13;
extern ctpVar19Struct* ctpVar15;
extern uint8* ctpVar17;
extern ctpVar19Struct* ctpVar19;
int loadCtp(uint8* ctpName);
int ctpProc2(int varX, int varY, int paramX, int paramY);
} // End of namespace Cruise
#endif

View file

@ -0,0 +1,532 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
void loadSetEntry(uint8* name, uint8* ptr, int currentEntryIdx, int currentDestEntry);
void loadFNTSub(uint8* ptr, int destIdx);
enum fileTypeEnum
{
type_UNK,
type_SPL,
type_SET,
type_FNT,
};
typedef enum fileTypeEnum fileTypeEnum;
int loadSingleFile;
// TODO: Unify decodeGfxFormat1, decodeGfxFormat4 and decodeGfxFormat5
void decodeGfxFormat1(dataFileEntry* pCurrentFileEntry)
{
uint8* buffer;
uint8* dataPtr = pCurrentFileEntry->subData.ptr;
int spriteSize = pCurrentFileEntry->height * pCurrentFileEntry->widthInColumn * 8;
int x = 0;
buffer = (uint8*)malloc(spriteSize);
while (x < spriteSize)
{
uint8 c;
uint16 p0;
p0 = (dataPtr[0] << 8) | dataPtr[1];
/* decode planes */
for (c = 0; c < 16; c++)
{
buffer[x+c] = ((p0 >> 15) & 1);
p0 <<= 1;
}
x+=16;
dataPtr+=2;
}
pCurrentFileEntry->subData.ptr = buffer;
}
void decodeGfxFormat4(dataFileEntry* pCurrentFileEntry)
{
uint8* buffer;
uint8* dataPtr = pCurrentFileEntry->subData.ptr;
int spriteSize = pCurrentFileEntry->height * pCurrentFileEntry->widthInColumn * 2;
int x = 0;
buffer = (uint8*)malloc(spriteSize);
while (x < spriteSize)
{
uint8 c;
uint16 p0;
uint16 p1;
uint16 p2;
uint16 p3;
p0 = (dataPtr[0] << 8) | dataPtr[1];
p1 = (dataPtr[2] << 8) | dataPtr[3];
p2 = (dataPtr[4] << 8) | dataPtr[5];
p3 = (dataPtr[6] << 8) | dataPtr[7];
/* decode planes */
for (c = 0; c < 16; c++)
{
buffer[x+c] = ((p0 >> 15) & 1) | ((p1 >> 14) & 2) | ((p2 >> 13) & 4) | ((p3 >> 12) & 8);
p0 <<= 1;
p1 <<= 1;
p2 <<= 1;
p3 <<= 1;
}
x+=16;
dataPtr+=8;
}
pCurrentFileEntry->subData.ptr = buffer;
}
void decodeGfxFormat5(dataFileEntry* pCurrentFileEntry)
{
uint8* buffer;
uint8* dataPtr = pCurrentFileEntry->subData.ptr;
int spriteSize = pCurrentFileEntry->height * pCurrentFileEntry->widthInColumn;
int x = 0;
int range = pCurrentFileEntry->height * pCurrentFileEntry->width;
buffer = (uint8*)malloc(spriteSize);
while (x < spriteSize)
{
uint8 c;
uint16 p0;
uint16 p1;
uint16 p2;
uint16 p3;
uint16 p4;
p0 = (dataPtr[0 + range * 0] << 8) | dataPtr[1 + range * 0];
p1 = (dataPtr[0 + range * 1] << 8) | dataPtr[1 + range * 1];
p2 = (dataPtr[0 + range * 2] << 8) | dataPtr[1 + range * 2];
p3 = (dataPtr[0 + range * 3] << 8) | dataPtr[1 + range * 3];
p4 = (dataPtr[0 + range * 4] << 8) | dataPtr[1 + range * 4];
/* decode planes */
for (c = 0; c < 16; c++)
{
buffer[x+c] = ((p0 >> 15) & 1) | ((p1 >> 14) & 2) | ((p2 >> 13) & 4) | ((p3 >> 12) & 8) | ((p4 >> 11) & 16);
p0 <<= 1;
p1 <<= 1;
p2 <<= 1;
p3 <<= 1;
p4 <<= 1;
}
x+=16;
dataPtr+=2;
}
pCurrentFileEntry->subData.ptr = buffer;
}
int updateResFileEntry(int height, int width, int entryNumber, int resType)
{
int div = 0;
int size;
resetFileEntry(entryNumber);
filesDatabase[entryNumber].subData.field_1C = 0;
size = height * width; // for sprites: width * height
if(resType == 4)
{
div = size / 4;
}
else if (resType == 5)
{
width = (width * 8) / 5;
}
filesDatabase[entryNumber].subData.ptr = (uint8*)mallocAndZero(size + div);
if(!filesDatabase[entryNumber].subData.ptr)
return(-2);
filesDatabase[entryNumber].widthInColumn = width;
filesDatabase[entryNumber].subData.ptr2 = filesDatabase[entryNumber].subData.ptr+size;
filesDatabase[entryNumber].width = width / 8;
filesDatabase[entryNumber].resType = resType;
filesDatabase[entryNumber].height = height;
filesDatabase[entryNumber].subData.index = -1;
return entryNumber;
}
int createResFileEntry(int width, int height, int resType)
{
int i;
int entryNumber;
int div = 0;
int size;
printf("Executing untested createResFileEntry!\n");
exit(1);
for(i = 0; i < 257; i++)
{
if(!filesDatabase[i].subData.ptr)
break;
}
if(i >= 257)
{
return(-19);
}
entryNumber = i;
filesDatabase[entryNumber].subData.field_1C = 0;
size = width * height; // for sprites: width * height
if(resType == 4)
{
div = size / 4;
}
else if (resType == 5)
{
width = (width * 8) / 5;
}
filesDatabase[entryNumber].subData.ptr = (uint8*)mallocAndZero(size + div);
if(filesDatabase[entryNumber].subData.ptr)
{
return(-2);
}
filesDatabase[entryNumber].widthInColumn = width;
filesDatabase[entryNumber].subData.ptr2 = filesDatabase[entryNumber].subData.ptr + size;
filesDatabase[entryNumber].width = width / 8;
filesDatabase[entryNumber].resType = resType;
filesDatabase[entryNumber].height = height;
filesDatabase[entryNumber].subData.index = -1;
return entryNumber;
}
fileTypeEnum getFileType(uint8* name)
{
char extentionBuffer[16];
fileTypeEnum newFileType = type_UNK;
getFileExtention((char*)name,extentionBuffer);
if(!strcmp(extentionBuffer,".SPL"))
{
newFileType = type_SPL;
}
else
if(!strcmp(extentionBuffer,".SET"))
{
newFileType = type_SET;
}
else
if(!strcmp(extentionBuffer,".FNT"))
{
newFileType = type_FNT;
}
ASSERT(newFileType != type_UNK);
return newFileType;
}
int getNumMaxEntiresInSet(uint8* ptr)
{
uint16 numEntries = *(uint16*)(ptr + 4);
flipShort(&numEntries);
return numEntries;
}
int loadFileMode2(uint8* name, int startIdx, int currentEntryIdx, int numIdx)
{
uint8* ptr = NULL;
fileTypeEnum fileType;
fileType = getFileType(name);
loadFileSub1(&ptr, name, NULL);
switch(fileType)
{
case type_SET:
{
int i;
int numMaxEntriesInSet = getNumMaxEntiresInSet(ptr);
for(i = 0; i < numIdx; i++)
{
if ((currentEntryIdx + i) > numMaxEntriesInSet)
{
return 0; // exit if limit is reached
}
loadSetEntry(name, ptr, currentEntryIdx + i, startIdx + i);
}
break;
}
case type_FNT:
{
loadFNTSub(ptr, startIdx);
break;
}
}
return 0;
}
int loadFullBundle(uint8* name, int startIdx)
{
uint8* ptr = NULL;
fileTypeEnum fileType;
fileType = getFileType(name);
loadFileSub1(&ptr,name,NULL);
switch(fileType)
{
case type_SET:
{
int i;
int numMaxEntriesInSet;
numMaxEntriesInSet = getNumMaxEntiresInSet(ptr); // get maximum number of sprites/animations in SET file
for(i = 0; i < numMaxEntriesInSet; i++)
{
loadSetEntry(name, ptr, i, startIdx+i);
}
break;
}
case type_FNT:
{
loadFNTSub(ptr, startIdx);
break;
}
}
return 0;
}
void loadFNTSub(uint8* ptr, int destIdx)
{
uint8* ptr2 = ptr;
uint8* destPtr;
int fileIndex;
uint32 fontSize;
ptr2 += 4;
memcpy(&loadFileVar1, ptr2, 4);
flipLong(&loadFileVar1);
if(destIdx == -1)
{
fileIndex = createResFileEntry(loadFileVar1, 1 ,1);
}
else
{
fileIndex = updateResFileEntry(loadFileVar1, 1, destIdx, 1);
}
destPtr = filesDatabase[fileIndex].subData.ptr;
memcpy(destPtr, ptr2, loadFileVar1);
memcpy(&fontSize,ptr2,4);
flipLong(&fontSize);
if(destPtr!=NULL)
{
int32 i;
uint8* currentPtr;
destPtr = filesDatabase[fileIndex].subData.ptr;
flipLong((int32*) destPtr);
flipLong((int32*) (destPtr + 4));
flipGen(destPtr + 8, 6);
currentPtr = destPtr + 14;
for(i = 0; i < *(int16*) (destPtr + 8); i++)
{
flipLong((int32*) currentPtr);
currentPtr += 4;
flipGen(currentPtr, 8);
currentPtr += 8;
}
}
}
void loadSetEntry(uint8* name, uint8* ptr, int currentEntryIdx, int currentDestEntry)
{
uint8* ptr2;
uint8* ptr3;
int offset;
int sec = 0;
uint16 numIdx;
if (!strcmpuint8(ptr,"SEC"))
{
sec = 1;
}
ptr2 = ptr + 4;
memcpy(&numIdx,ptr2,2);
flipShort(&numIdx);
ptr3 = ptr + 6;
offset = currentEntryIdx*16;
{
uint8* ptr4;
int resourceSize;
int fileIndex;
setHeaderEntry localBuffer;
uint8* ptr5;
ptr4 = ptr + offset + 6;
memcpy(&localBuffer, ptr4, sizeof(setHeaderEntry));
flipLong((int32*) &localBuffer.field_0);
flipGen(&localBuffer.width, 12);
if ((sec == 1) || (localBuffer.type == 5))
{
localBuffer.width = localBuffer.width - (localBuffer.type * 2); // Type 1: Width - (1*2) , Type 5: Width - (5*2)
}
resourceSize = localBuffer.width * localBuffer.height;
if(currentDestEntry == -1)
{
fileIndex = createResFileEntry(localBuffer.width,localBuffer.height,localBuffer.type);
}
else
{
fileIndex = updateResFileEntry(localBuffer.height, localBuffer.width, currentDestEntry, localBuffer.type);
}
if(fileIndex < 0)
{
return; // TODO: buffer is not freed
}
ptr5 = ptr3 + localBuffer.field_0 + numIdx * 16;
memcpy(filesDatabase[fileIndex].subData.ptr,ptr5, resourceSize);
ptr5 += resourceSize;
switch(localBuffer.type)
{
case 0:
{
filesDatabase[fileIndex].subData.resourceType = 8;
break;
}
case 1:
{
filesDatabase[fileIndex].subData.resourceType = 2;
decodeGfxFormat1(&filesDatabase[fileIndex]);
break;
}
case 4:
{
filesDatabase[fileIndex].width *= 2;
filesDatabase[fileIndex].subData.resourceType = 4;
decodeGfxFormat4(&filesDatabase[fileIndex]);
break;
}
case 5:
{
if (sec == 0)
{
// TODO sec type 5 needs special conversion. cut out 2 bytes at every width/5 position.
return;
}
filesDatabase[fileIndex].subData.resourceType = 4;
decodeGfxFormat5(&filesDatabase[fileIndex]);
break;
}
case 8:
{
filesDatabase[fileIndex].subData.resourceType = 4; // dummy !
break;
}
default:
{
printf("Unsuported gfx loading type: %d\n", localBuffer.type);
break;
}
}
filesDatabase[fileIndex].subData.index = currentDestEntry;
filesDatabase[fileIndex].subData.transparency = localBuffer.transparency; /*% 0x10*/;
strcpyuint8(filesDatabase[fileIndex].subData.name,name);
}
// TODO: free
return;
}
} // End of namespace Cruise

View file

@ -0,0 +1,38 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _DATALOADER_H_
#define _DATALOADER_H_
namespace Cruise {
int loadData(uint8* name, int startIdx);
int loadFileMode2(uint8* name, int param, int startIdx, int numIdx);
int loadFileSub1(uint8** ptr, uint8* name, uint8* ptr2);
int loadFullBundle(uint8* name, int startIdx);
} // End of namespace Cruise
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,176 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
uint32 crc; // variable at 5C5A
uint32 bitbucket; // dx:bx
uint16 swap16(uint16 r)
{
return (r >> 8) | (r << 8);
}
#define loadd(p, d) {\
d = *(--p);\
d |= (*(--p)) << 8;\
d |= (*(--p)) << 16;\
d |= (*(--p)) << 24;\
}
#define store(p, b) *(--p) = b
#define getbit(p, b) {\
b = (uint8)(bitbucket & 1);\
bitbucket >>= 1;\
if (!bitbucket) {\
loadd(p, bitbucket);\
crc ^= bitbucket;\
b = (uint8)(bitbucket & 1);\
bitbucket >>= 1;\
bitbucket |= 0x80000000;\
}\
}
#define loadbits(p, b) {\
b = 0;\
do {\
getbit(p, bit);\
b <<= 1;\
b |= bit;\
nbits--;\
} while (nbits);\
}
int32 decomp(uint8 * in, uint8 * out, int32 size) {
uint8 bit; // Carry flag
uint8 nbits; // cl
uint8 byte; // ch
uint16 counter; // bp
uint16 var; // variable at 5C58
uint16 ptr;
uint16 flags;
enum {
DO_COPY,
DO_UNPACK
} action;
loadd(in, crc);
loadd(in, bitbucket);
crc ^= bitbucket;
do { // 5A4C
getbit(in, bit);
if (!bit) { // 5A94
getbit(in, bit);
if (!bit) { // 5AC8
nbits = 3;
byte = 0;
action = DO_COPY;
} else { // 5ACA
var = 1;
nbits = 8;
action = DO_UNPACK;
}
} else { // 5B4F
nbits = 2;
loadbits(in, flags);
if (flags < 2) {
nbits = flags + 9; // 5BC3
var = flags + 2;
action = DO_UNPACK;
} else if (flags == 3) {
nbits = 8; // 5B4A
byte = 8;
action = DO_COPY;
} else {
nbits = 8;
loadbits(in, var);
nbits = 12;
action = DO_UNPACK;
}
}
switch (action) {
case DO_COPY:
// 5AD1
loadbits(in, counter); // 5AFD
counter += byte;
counter++;
size -= counter;
do {
nbits = 8;
loadbits(in, byte); // 5B3F
store(out, byte);
counter--;
} while (counter); // 5B45
break;
case DO_UNPACK:
// 5BD3
loadbits(in, ptr); // 5BFF
counter = var + 1;
size -= counter;
do {
byte = *(out + ptr - 1);
store(out, byte);
counter--;
} while(counter);
}
} while (size > 0);
// 5C32
// ???
if (crc) {
return -1;
} else {
return 0;
}
}
/*
int main(void) {
FILE * in, * out;
uint8 * bufin, * bufout;
uint32 isize, osize;
in = fopen("FIN.FR", "rb");
out = fopen("FIN.FR.out", "wb");
fseek(in, -4, SEEK_END);
bufin = (uint8 *) mallocAndZero((isize = ftell(in)));
fread(&osize, 4, 1, in);
osize = (osize >> 24) | ((osize >> 8) & 0xff00) | ((osize << 8) & 0xff0000) | (osize << 24);
bufout = (uint8 *) mallocAndZero(osize);
fseek(in, 0, SEEK_SET);
fread(bufin, 1, isize, in);
decomp(bufin + isize, bufout + osize, osize);
fwrite(bufout, 1, osize, out);
fclose(out);
fclose(in);
}*/
} // End of namespace Cruise

View file

@ -0,0 +1,112 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "common/stdafx.h"
#include "base/plugins.h"
#include "common/advancedDetector.h"
#include "cruise/cruise.h"
namespace Cruise {
struct CRUISEGameDescription {
Common::ADGameDescription desc;
int gameType;
uint32 features;
};
int CruiseEngine::getGameType() const { return _gameDescription->gameType; }
uint32 CruiseEngine::getFeatures() const { return _gameDescription->features; }
Common::Language CruiseEngine::getLanguage() const { return _gameDescription->desc.language; }
Common::Platform CruiseEngine::getPlatform() const { return _gameDescription->desc.platform; }
}
static const PlainGameDescriptor cruiseGames[] = {
{"cruise", "Cinematique evo.2 engine game"},
{"cruise", "Cruise for a corps"},
{0, 0}
};
static const Common::ADObsoleteGameID obsoleteGameIDsTable[] = {
{"cruise", "cruise", Common::kPlatformUnknown},
{0, 0, Common::kPlatformUnknown}
};
namespace Cruise {
static const CRUISEGameDescription gameDescriptions[] = {
{
{
"cruise",
"",
AD_ENTRY1("D1", "41a7a4d426dbd048eb369cfee4bb2717"),
Common::FR_FRA,
Common::kPlatformPC,
Common::ADGF_NO_FLAGS
},
GType_CRUISE,
0,
},
{ AD_TABLE_END_MARKER, 0, 0 }
};
}
static const Common::ADParams detectionParams = {
// Pointer to ADGameDescription or its superset structure
(const byte *)Cruise::gameDescriptions,
// Size of that superset structure
sizeof(Cruise::CRUISEGameDescription),
// Number of bytes to compute MD5 sum for
5000,
// List of all engine targets
cruiseGames,
// Structure for autoupgrading obsolete targets
obsoleteGameIDsTable,
// Name of single gameid (optional)
"cruise",
// List of files for file-based fallback detection (optional)
0,
// Fallback callback
0,
// Flags
Common::kADFlagAugmentPreferredTarget
};
ADVANCED_DETECTOR_DEFINE_PLUGIN(CRUISE, Cruise::CruiseEngine, detectionParams);
REGISTER_PLUGIN(CRUISE, "Cinematique evo 2 engine", "Cruise for a Corpse (C) Delphine Software");
namespace Cruise {
bool CruiseEngine::initGame() {
_gameDescription = (const CRUISEGameDescription *)Common::AdvancedDetector::detectBestMatchingGame(detectionParams);
return (_gameDescription != 0);
}
} // End of namespace Cruise

745
engines/cruise/font.cpp Normal file
View file

@ -0,0 +1,745 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "common/file.h"
#include "cruise/cruise_main.h"
namespace Cruise {
// (old: fontProc1(int16 param, uint8* ptr1, uint8* ptr2))
int32 getLineHeight(int16 charCount, uint8* fontPtr, uint8* fontPrt_Desc)
{
uint8* dest;
int32 highestChar = 0;
int32 i;
if(!charCount)
{
return(0);
}
dest = fontPrt_Desc + 6; // fontPtr + 20 // char height
for(i = 0; i < charCount; i++)
{
if((*(int16*) dest) > highestChar)
{
highestChar = *(int16*) dest;
}
dest += 12;
}
return highestChar;
}
// this function determins how many lines the text will have (old: fontProc2(int32 param1, int32 param2, uint8* ptr, uint8* string))
int32 getTextLineCount(int32 rightBorder_X, int32 wordSpacingWidth, uint8* ptr, uint8* textString)
{
uint8* localString = textString;
uint8* currentStringPtr;
uint8 character;
int32 var_6 = 0;
int32 lineLength = 0;
uint8* tempPtr;
if(!*localString)
{
return(0);
}
currentStringPtr = localString;
character = *localString;
do
{
int32 charData = fontCharacterTable[character];
if(character == '|')
{
lineLength = rightBorder_X;
localString = tempPtr;
}
else
{
if(charData >= 0)
{ // + 0xA jump to last 2 bytes of the 12 bytes slice = letter width
lineLength += wordSpacingWidth + *(int16*) (ptr + 0xA + charData * 12);
}
else
{
if(character == ' ')
{
lineLength += wordSpacingWidth + 5;
localString = currentStringPtr;
}
}
}
tempPtr = currentStringPtr;
if(rightBorder_X <= lineLength)
{
var_6 += rightBorder_X;
currentStringPtr = localString;
tempPtr = localString;
lineLength = 0;
}
character = *(tempPtr++);
currentStringPtr = tempPtr;
} while(character);
if(lineLength == 0)
{
return (var_6 / rightBorder_X);
}
else
{
return ((var_6 + rightBorder_X) / rightBorder_X);
}
}
void loadFNT(void* fileNameChar)
{
uint8 header[6];
int32 fontSize;
int32 data2;
uint8 data3[6];
uint8* fileName = (uint8*) fileNameChar;
_systemFNT = NULL;
Common::File fontFileHandle;
if(!fontFileHandle.exists((char*)fileName))
{
return;
}
fontFileHandle.open((char*)fileName);
fontFileHandle.read(header, 4);
if(strcmpuint8(header, "FNT") == 0)
{
fontFileHandle.read(&fontSize, 4);
flipLong(&fontSize);
fontFileHandle.read(&data2, 4);
flipLong(&data2);
fontFileHandle.read(data3, 6); // may need an endian flip ?
flipGen(&data3, 6);
_systemFNT = (uint8*) mallocAndZero(fontSize);
if(_systemFNT != NULL)
{
int32 i;
uint8* currentPtr;
fontFileHandle.seek(0);
fontFileHandle.read(header, 4); // not really require, we could fseek to 4
fontFileHandle.read(_systemFNT, fontSize);
flipLong((int32*) _systemFNT);
flipLong((int32*) (_systemFNT + 4));
flipGen(_systemFNT + 8, 6);
currentPtr = _systemFNT + 14;
for(i = 0; i < *(int16*) (_systemFNT + 8); i++)
{
flipLong((int32*) currentPtr);
currentPtr += 4;
flipGen(currentPtr, 8);
currentPtr += 8;
}
}
}
fontFileHandle.close();
}
void loadSystemFont(void)
{
int32 i;
video2 = 15;
video4 = 9;
video3 = 13;
colorOfSelectedSaveDrive = 10;
for(i = 0; i < 64; i++)
{
mediumVar[i].ptr = 0;
mediumVar[i].field_1C = 0;
}
initVar1 = 0;
main5 = 0;
var22 = 0;
initVar2 = 0;
initVar3 = 0;
currentActiveBackgroundPlane = 0;
//changeCursor();
initVar4[0] = 0;
loadFNT("system.fnt");
}
void flipShort(int16* var)
{
uint8* varPtr = (uint8*) var;
uint8 temp = varPtr[0];
varPtr[0] = varPtr[1];
varPtr[1] = temp;
}
void flipShort(uint16* var)
{
uint8* varPtr = (uint8*) var;
uint8 temp = varPtr[0];
varPtr[0] = varPtr[1];
varPtr[1] = temp;
}
void flipLong(int32* var)
{
char swap1;
char swap2;
char* varPtr = (char*) var;
swap1 = varPtr[0];
varPtr[0] = varPtr[3];
varPtr[3] = swap1;
swap2 = varPtr[1];
varPtr[1] = varPtr[2];
varPtr[2] = swap2;
}
void flipLong(uint32* var)
{
char swap1;
char swap2;
char* varPtr = (char*) var;
swap1 = varPtr[0];
varPtr[0] = varPtr[3];
varPtr[3] = swap1;
swap2 = varPtr[1];
varPtr[1] = varPtr[2];
varPtr[2] = swap2;
}
void flipGen(void* var, int32 length)
{
int i;
short int* varPtr = (int16*) var;
for(i = 0; i < (length / 2); i++)
{
flipShort(&varPtr[i]);
}
}
void renderWord(uint8* fontPtr_Data, uint8* outBufferPtr, int32 drawPosPixel_X, int32 heightOff, int32 height, int32 param4, int32 stringRenderBufferSize, int32 width, int32 charWidth)
{
int i;
int j;
uint8* fontPtr_Data2 = fontPtr_Data + height * 2;
outBufferPtr += heightOff * width * 2; // param2 = height , param6 = width
outBufferPtr += drawPosPixel_X; // param1 = drawPosPixel_X
for(i = 0; i < height; i++) // y++
{
uint16 currentColor1 = (*(fontPtr_Data) << 8) | *(fontPtr_Data + 1);
uint16 currentColor2 = (*(fontPtr_Data2) << 8) | *(fontPtr_Data2 + 1);
fontPtr_Data += 2;
fontPtr_Data2 += 2;
for (j = 0; j < charWidth; j++)
{
*outBufferPtr = ((currentColor1 >> 15) & 1) | ((currentColor2 >> 14) & 2);
outBufferPtr++;
currentColor1 <<= 1;
currentColor2 <<= 1;
}
outBufferPtr += (width * 2) - charWidth;
}
}
// returns character count and pixel size (via pointer) per line of the string (old: prepareWordRender(int32 param, int32 var1, int16* out2, uint8* ptr3, uint8* string))
int32 prepareWordRender(int32 inRightBorder_X, int32 wordSpacingWidth, int16* strPixelLength, uint8* ptr3, uint8* textString)
{
uint8* localString = textString;
int32 counter = 0;
int32 finish = 0;
int32 temp_pc = 0; // var_A // temporary pixel count save
int32 temp_cc = 0; // var_C // temporary char count save
int32 pixelCount = 0; // si
do
{
uint8 character = *(localString++);
int16 charData = fontCharacterTable[character];
if(character == ' ')
{
temp_cc = counter;
temp_pc = pixelCount;
if(pixelCount + wordSpacingWidth + 5 >= inRightBorder_X)
{
finish = 1;
}
else
{
pixelCount += wordSpacingWidth + 5 ;
}
}
else
{
if(character == '|' || !character)
{
finish = 1;
}
else
{
if(charData)
{
if(pixelCount + wordSpacingWidth + *(int16*) ((ptr3 + charData * 12) + 0xA) >= inRightBorder_X)
{
finish = 1;
if(temp_pc)
{
pixelCount = temp_pc;
counter = temp_cc;
}
}
else
{
pixelCount += wordSpacingWidth + *(int16*) ((ptr3 + charData * 12) + 0xA);
}
}
}
}
counter++;
} while(!finish);
*strPixelLength = (int16) pixelCount;
return counter;
}
void drawString(int32 x, int32 y, uint8* string, uint8* buffer, uint8 color, int32 inRightBorder_X)
{
uint8* fontPtr;
uint8* fontPtr_Data; // ptr2
uint8* fontPtr_Desc; // ptr3
int32 wordSpacingWidth; // var1
int32 wordSpacingHeight; // var2
int32 rightBorder_X; // param2
int32 lineHeight; // fontProc1result
int32 numLines;
int32 stringHeight;
int32 stringFinished;
int32 stringWidth; // var_1C
int32 stringRenderBufferSize;
int32 useDynamicBuffer;
uint8* currentStrRenderBuffer;
// int32 var_8; // don't need that on
int32 heightOffset; // var_12
int32 renderBufferSize; // var_1E
int needFlip;
if(!buffer || !string)
{
return;
}
if(fontFileIndex != -1)
{
fontPtr = filesDatabase[fontFileIndex].subData.ptr;
if(!fontPtr)
{
fontPtr = _systemFNT;
}
}
else
{
fontPtr = _systemFNT;
}
if(!fontPtr)
{
return;
}
fontPtr_Data = fontPtr + *(int16*) (fontPtr + 4);
fontPtr_Desc = fontPtr + 14;
lineHeight = getLineHeight(*(int16*) (fontPtr + 8), fontPtr, fontPtr_Desc); // ok
wordSpacingWidth = *(int16*) (fontPtr + 10);
wordSpacingHeight = *(int16*) (fontPtr + 12);
if(inRightBorder_X > 310)
{
rightBorder_X = 310;
}
else
{
rightBorder_X = inRightBorder_X;
}
if(x + rightBorder_X > 319)
{
x = 319 - rightBorder_X;
}
if(y < 0)
{
y = 0;
}
if(x < 0)
{
x = 0;
}
numLines = getTextLineCount(rightBorder_X, wordSpacingWidth, fontPtr_Desc, string); // ok
if(!numLines)
{
return;
}
stringHeight = ((wordSpacingHeight + lineHeight + 2) * numLines) + 1;
if (y + stringHeight > 199)
{
y = 200 - stringHeight;
}
stringFinished = 0;
stringWidth = (rightBorder_X / 16) + 2;
stringRenderBufferSize = stringWidth * stringHeight * 4;
inRightBorder_X = rightBorder_X;
if(stringRenderBufferSize > 0x2000)
{
currentStrRenderBuffer = (uint8*) mallocAndZero(stringRenderBufferSize);
if(!currentStrRenderBuffer)
{
return;
}
useDynamicBuffer = 1;
}
else
{
currentStrRenderBuffer = (uint8*) ptr_something;
useDynamicBuffer = 0;
}
resetRaster(currentStrRenderBuffer, stringRenderBufferSize);
// var_8 = 0;
heightOffset = 0;
renderBufferSize = stringRenderBufferSize;
do
{
int spacesCount = 0; // si
char character = *(string);
short int strPixelLength; // var_16;
uint8* ptrStringEnd; // var_4 //ok
int drawPosPixel_X; // di
while(character == ' ')
{
spacesCount++;
character = *(string + spacesCount);
}
string += spacesCount;
ptrStringEnd = string + prepareWordRender(inRightBorder_X, wordSpacingWidth, &strPixelLength, fontPtr_Desc, string); //ok
if(inRightBorder_X > strPixelLength)
{
drawPosPixel_X = (inRightBorder_X - strPixelLength) / 2;
}
else
{
drawPosPixel_X = 0;
}
// drawPosPixel_X = var_8;
do
{
uint8 character = *(string++);
short int data = fontCharacterTable[character];
if(character)
{
if(character == ' ' || character == 0x7D)
{
drawPosPixel_X += var1 + 5;
}
else
{
if(data)
{
short int* si = (int16*) (fontPtr_Desc + data * 12);
//int var_2 = si[5];
renderWord(fontPtr_Data + si[0], currentStrRenderBuffer, drawPosPixel_X, si[4] - si[3] + lineHeight + heightOffset, si[3], si[2], renderBufferSize / 2, stringWidth * 2, si[5]);
drawPosPixel_X += wordSpacingWidth + si[5];
}
}
}
else
{
stringFinished = 1;
}
if(ptrStringEnd <= string)
{
break;
}
} while(!stringFinished);
// var_8 = 0;
heightOffset = wordSpacingHeight + lineHeight;
} while(!stringFinished);
needFlip = 0;
if(buffer == gfxModuleData.pPage00)
{
if(gfxModuleData.field_1 != 0)
{
needFlip = 1;
gfxModuleData_field_90();
}
gfxModuleData_gfxWaitVSync();
}
gfxModuleData_field_64((char*)currentStrRenderBuffer, stringWidth, stringHeight, (char*)buffer, x, y, 0);
gfxModuleData_field_64((char*)currentStrRenderBuffer, stringWidth, stringHeight, (char*)buffer, x, y, color);
if(needFlip)
{
gfxModuleData_flip();
}
if(useDynamicBuffer)
{
free(currentStrRenderBuffer);
}
}
// calculates all necessary datas and renders text
gfxEntryStruct* renderText(int inRightBorder_X, uint8* string)
{
uint8* fontPtr;
uint8* fontPtr_Data; // pt2
uint8* fontPtr_Desc; // ptr3
int32 wordSpacingWidth; // var1 //0 or -1
int32 wordSpacingHeight; // var2 //0 or -1
int32 rightBorder_X;
int32 lineHeight; // fontProc1result
int32 numLines;
int32 stringHeight;
int32 stringFinished;
int32 stringWidth; // var_1C
int32 stringRenderBufferSize;
// int32 useDynamicBuffer;
uint8* currentStrRenderBuffer;
// int32 var_8; // don't need that one
int32 heightOffset; // var_12 // how much pixel-lines have already been drawn
// int32 var_1E;
gfxEntryStruct* generatedGfxEntry;
// check if string is empty
if(!string)
{
return NULL;
}
// check if font has been loaded, else get system font
if(fontFileIndex != -1)
{
fontPtr = filesDatabase[fontFileIndex].subData.ptr;
if(!fontPtr)
{
fontPtr = _systemFNT;
}
}
else
{
fontPtr = _systemFNT;
}
if(!fontPtr)
{
return NULL;
}
fontPtr_Data = fontPtr + *(int16*) (fontPtr + 4); // offset to char data
fontPtr_Desc = fontPtr + 14; // offset to char description
lineHeight = getLineHeight(*(int16*) (fontPtr + 8), fontPtr, fontPtr_Desc); // ok
wordSpacingWidth = *(int16*) (fontPtr + 10);
wordSpacingHeight = *(int16*) (fontPtr + 12);
// if right border is higher then screenwidth (+ spacing), adjust border
if(inRightBorder_X > 310)
{
rightBorder_X = 310;
}
else
{
rightBorder_X = inRightBorder_X;
}
numLines = getTextLineCount(rightBorder_X, wordSpacingWidth, fontPtr_Desc, string); // ok
if(!numLines)
{
return NULL;
}
stringHeight = ((wordSpacingHeight + lineHeight + 2) * numLines) + 1;
stringFinished = 0;
stringWidth = rightBorder_X + 2; // max render width to the right
stringRenderBufferSize = stringWidth * stringHeight * 4;
inRightBorder_X = rightBorder_X;
currentStrRenderBuffer = (uint8*) mallocAndZero(stringRenderBufferSize);
resetRaster(currentStrRenderBuffer, stringRenderBufferSize);
generatedGfxEntry = (gfxEntryStruct*) malloc(sizeof(gfxEntryStruct));
generatedGfxEntry->imagePtr = currentStrRenderBuffer;
generatedGfxEntry->imageSize = stringRenderBufferSize / 2;
generatedGfxEntry->fontIndex = fontFileIndex;
generatedGfxEntry->height = stringHeight;
generatedGfxEntry->width = stringWidth; // maximum render width to the right
// var_8 = 0;
heightOffset = 0;
do
{
int spacesCount = 0; // si
char character = *string;
short int strPixelLength; // var_16
uint8* ptrStringEnd; // var_4 //ok
int drawPosPixel_X; // di
// find first letter in string, skip all spaces
while(character == ' ')
{
spacesCount++;
character = *(string + spacesCount);
}
string += spacesCount;
// returns character count and pixel length (via pointer) per line of the text string
ptrStringEnd = string + prepareWordRender(inRightBorder_X, wordSpacingWidth, &strPixelLength, fontPtr_Desc, string); //ok
// determine how much space is left to the right and left (center text)
if(inRightBorder_X > strPixelLength)
{
//var_8 = (inRightBorder_X - strPixelLength) / 2;
drawPosPixel_X = (inRightBorder_X - strPixelLength) / 2;
}
else
{
drawPosPixel_X = 0;
}
//drawPosPixel_X = var_8;
// draw textline, character wise
do
{
uint8 character = *(string++);
short int charData = fontCharacterTable[character]; // get character position
if(character)
{
if(character == ' ' || character == 0x7C)
{
drawPosPixel_X += wordSpacingWidth + 5; // if char = "space" adjust word starting postion (don't render space though);
}
else
{
if(charData >= 0)
{
short int* si = (int16*) (fontPtr_Desc + charData * 12); // offset font data
// int var_2 = si[5]; // don't need this
// should ist be stringRenderBufferSize/2 for the second last param?
renderWord(fontPtr_Data + si[0], currentStrRenderBuffer, drawPosPixel_X, si[4] - si[3] + lineHeight + heightOffset, si[3], si[2], stringRenderBufferSize, stringWidth / 2, si[5]);
drawPosPixel_X += wordSpacingWidth + si[5];
}
}
}
else
{
stringFinished = 1; // character = 0x00
}
// check if string already reached the end
if(ptrStringEnd <= string)
{
break;
}
} while(!stringFinished);
// var_8 = 0;
heightOffset += wordSpacingHeight + lineHeight;
}while(!stringFinished);
return generatedGfxEntry;
}
} // End of namespace Cruise

49
engines/cruise/font.h Normal file
View file

@ -0,0 +1,49 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _FONT_H_
#define _FONT_H_
namespace Cruise {
void loadFNT(void* fileName);
void loadSystemFont(void);
//////////////////////////////////////////////////
void flipShort(int16* var);
void flipShort(uint16* var);
void flipLong(int32* var); // TODO: move away
void flipLong(uint32* var); // TODO: move away
void flipGen(void* var, int32 length);
int32 getLineHeight(int16 charCount, uint8* fontPtr, uint8* fontPrt_Desc); // fontProc1
int32 getTextLineCount(int32 rightBorder_X, int32 wordSpacingWidth, uint8* ptr, uint8* textString); // fontProc2
void renderWord(uint8* fontPtr_Data, uint8* outBufferPtr, int32 drawPosPixel_X, int32 heightOff, int32 height, int32 param4, int32 stringRenderBufferSize, int32 width , int32 charWidth);
gfxEntryStruct* renderText(int inRightBorder_X, uint8* string);
void drawString(int32 x, int32 y, uint8* string, uint8* buffer, uint8 color, int32 inRightBorder_X);
} // End of namespace Cruise
#endif

View file

@ -0,0 +1,195 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
int16 fontCharacterTable[256]={
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
86, 87, 88, 89, 90, 91, 92,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
106, 105,
-1,
-1,
-1,
-1,
107, 108,
-1,-1,
109, 110,
-1,
-1,
-1,
-1,
-1,-1,
111, -1,
112,
-1,-1,
113,
114,
-1,
-1,
116, 93,
-1,
118,
-1,
94,
-1,
117,
115,
96,
95,
97,
98,
-1,
-1,
99,
100,
-1,
-1,
-1,
-1,
101,
-1,
102,
-1,
-1,
103,
-1,
104,
-1,
-1,
-1,
-1,
};
} // End of namespace Cruise

View file

@ -0,0 +1,35 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _FONTCHARACTERTABLE_H_
#define _FONTCHARACTERTABLE_H_
namespace Cruise {
extern short int fontCharacterTable[256];
} // End of namespace Cruise
#endif

1718
engines/cruise/function.cpp Normal file

File diff suppressed because it is too large Load diff

39
engines/cruise/function.h Normal file
View file

@ -0,0 +1,39 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _FUNCTION_H_
#define _FUNCTION_H_
namespace Cruise {
extern int flag_obstacle;
void setupOpcodeTable(void);
int32 opcodeType8(void);
int16 subOp22(int param);
int16 subOp23(int param1, int param2);
} // End of namespace Cruise
#endif

View file

@ -0,0 +1,657 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "common/stdafx.h"
#include "common/system.h"
#include "cruise/cruise_main.h"
namespace Cruise {
uint8 page00[320 * 200];
uint8 page10[320 * 200];
char screen[320 * 200];
palEntry lpalette[256];
short globalAtariScreen[320 * 200 / 4];
gfxModuleDataStruct gfxModuleData =
{
0, // field_1
0, // use Tandy
0, // use EGA
1, // use VGA
page00, // pPage00
page10, // pPage10
};
void gfxModuleData_gfxClearFrameBuffer(uint8* ptr)
{
memset(ptr, 0, 64000);
}
void gfxModuleData_gfxCopyScreen(char* sourcePtr, char* destPtr)
{
memcpy(destPtr, sourcePtr, 64000);
}
void outputBit(char* buffer, int bitPlaneNumber, uint8 data)
{
*(buffer +(8000 * bitPlaneNumber)) = data;
}
void gfxModuleData_field_60(char* sourcePtr, int width, int height, char* destPtr, int x, int y)
{/*
int loc_1064;
int loc_10AA;
int loc_10AD;
int loc_10C5;
int loc_10DF;
int loc_10EC;
int loc_1147;
int loc_114B;
int loc_117C = 0xF8;
int loc_11DC;
int loc_1277;
int loc_12D9;
int loc_12DD;
int loc_11E7;
int loc_127A;
int loc_1203;
int loc_122B;
int loc_117F;
int loc_11EF;
int loc_1217;
int loc_12E1;
int tempSwap;
int cx;
int bp;
int bpSave;
char* diPtr;
char* siPtr;
int direction = 1;
int dx = height;
int ax = width;
int es = ax << 1;
int bx = 0;
int di = 199;
int si;
ax = y;
si = 0;
if(y>199) // out of screen vertically
return;
if(y<0) // cropped on the top
{
cx = bx;
bx -= ax;
dx -= bx;
if(dx <= 0)
{
return;
}
ax = es; // es = size of a line ?
ax*=(bx&0xFF); // bx number of lines to skip vertically
si+=ax;
ax = cx;
}
bx = ax;
ax += dx;
ax--;
if(ax > di)
{
ax -= di;
dx -= ax;
if(dx <= 0)
{
return;
}
}
ax = dx;
loc_10DF = ax;
ax = bx;
loc_10AD = ax;
bx = 0;
di = 319;
ax = x;
dx = ax;
cx = ax&0xFF;
cx &= 7;
{
int cl = cx;
int ch = cl;
cl-=8;
cl=-cl;
cl&=7;
ax = (ch<<8) | (cl);
}
loc_1064 = ax;
ax = es;
ax <<= 3;
tempSwap = dx;
dx = ax;
ax = tempSwap;
if(ax > di)
{
return;
}
cx = ax;
cx += dx;
cx --;
dx >>= 3;
dx = dx&0xFF;
if(cx<bx)
{
return;
}
if(cx>di)
{
cx -= di;
cx >>= 3;
dx = (dx&0xFF00) | (((dx&0xFF) - (cx&0xFF))&0xFF);
dx = ((cx&0xFF)<<8) | (dx&0xFF);
di = 0xF8F9;
}
else
{
di = 0xF8F8;
}
if(ax<bx)
{
ax -= bx;
ax = -ax;
ax >>= 3;
si += ax;
dx = (dx&0xFF00) | (((dx&0xFF)-(ax&0xFF))&0xFF);
dx = (((dx&0xFF00) + ((ax&0xFF)<<8))&0xFF00) | (dx&0xFF);
ax = bx;
cx = di;
cx = (248<<8)|(cx&0xFF);
di = cx;
}
loc_10AA = ax;
ax = (ax&0xFF00) | (((dx&0xFF00)>>8)&0xFF);
ax = ax&0xFF;
loc_10C5 = ax;
ax = (ax&0xFF00) | (dx&0xFF);
dx = loc_1064;
if(dx)
{
if(di&1)
{
loc_10C5++;
}
bx = ax;
ax--;
loc_11DC = ax;
if(di&0x100)
{
bx--;
}
ax = bx;
ax -= 40;
ax = -ax;
loc_12D9 = ax;
ax = di;
loc_1277 = ax&0xFF;
ax = (ax&0xFF00) | (((ax&0xFF00)>>8)&0xFF);
loc_117C = ax&0xFF;
}
else
{
loc_10EC = ax;
ax -= 40;
ax = -ax;
loc_1147 = ax;
}
bx = loc_10AA;
ax = loc_10AD;
bx = ((((((bx&0xFF00)>>8)&0xFF) + (ax&0xFF))<<8)&0xFF00) | (bx&0xFF);
bx>>=3;
ax<<=3;
bx+=ax;
diPtr = destPtr;
diPtr += bx;
ax = loc_10C5;
ax<<=2;
loc_114B = ax;
loc_12DD = ax;
ax = si;
ax <<=2;
siPtr = sourcePtr;
siPtr+=ax;
bp = loc_10DF;
bx = dx;
dx = 974;
if(!bx) // no crop ?
{
do // for each line
{
bpSave = bp;
cx = loc_10EC;
do // for the line
{
outputBit(diPtr,0,*(siPtr));
outputBit(diPtr,1,*(siPtr+1));
outputBit(diPtr,2,*(siPtr+2));
outputBit(diPtr,3,*(siPtr+3));
siPtr+=4;
diPtr++;
}while(--cx);
diPtr += loc_1147; // interline
siPtr += loc_114B;
bp = bpSave;
}while(--bp);
}
else // croped
{
ASSERT(0);
loc_1156:
ax = (ax&0xFF00) | bx&0xFF;
loc_11E7 = ax&0xFF;
loc_127A = ax&0xFF;
loc_1203 = ax&0xFF;
loc_122B = ax&0xFF;
ax = (ax&0xFF00) | (((bx&0xFF00)>>8)&0xFF);
loc_117F = ax&0xFF;
loc_11EF = ax&0xFF;
loc_1217 = ax&0xFF;
do // main copy loop
{
ax = bp;
loc_12E1 = ax;
if(loc_117C == 0xF8)
{
direction = 1;
}
else
{
direction = -1;
}
if(direction == -1)
{
goto label_11DC;
}
cx = loc_117F;
ax = (ax&0xFF00) | (((*siPtr)&0xFF)>>cx)&0xFF;
dx = (((ax&0xFF)<<8)&0xFF00) | (dx&0xFF);
ax = (((ax&0xFF)<<8)&0xFF00) | (ax&0xFF);
ax = (ax&0xFF00) | (((*(siPtr+1))&0xFF)>>cx)&0xFF;
dx = (dx&0xFF00) | (ax&0xFF);
ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF);
ax = (ax&0xFF00) | (((*(siPtr+2))&0xFF)>>cx)&0xFF;
bx = (((ax&0xFF)<<8)&0xFF00) | (bx&0xFF);
ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF);
ax = (ax&0xFF00) | (((*(siPtr+3))&0xFF)>>cx)&0xFF;
bx = (bx&0xFF00) | (ax&0xFF);
ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF);
if(ax)
{
bp = dx;
ax = (ax&0xFF00) | (*diPtr)&0xFF;
ax = (ax&0xFF00) | 8;
outputBit(diPtr,0,(bp>>8)&0xFF);
outputBit(diPtr,1,(bp&0xFF));
outputBit(diPtr,2,(bx>>8)&0xFF);
outputBit(diPtr,3,(bx&0xFF));
}
diPtr++;
label_11DC:
bp = loc_11DC;
if(bp >0)
{
do
{
cx = loc_11E7;
ax = (ax&0xFF00) | (((*siPtr)&0xFF)>>cx)&0xFF;
dx = (((ax&0xFF)<<8)&0xFF00) | (dx&0xFF);
cx = loc_11EF;
ax = (ax&0xFF00) | (((*(siPtr+4))&0xFF)>>cx)&0xFF;
dx = (((dx&0xFF00) | (((ax&0xFF)<<8)&0xFF00))&0xFF00) | (dx&0xFF);
ax = (ax&0xFF00) | (((ax&0xFF) | (((dx&0xFF00)>>8)&0xFF))&0xFF);
ax = ((ax&0xFF)<<8) | (ax&0xFF);
ax = (ax&0xFF00) | (((*(siPtr+5))&0xFF)>>cx)&0xFF;
dx = (dx&0xFF00) | (ax&0xFF);
cx = loc_1203;
ax = (ax&0xFF00) | (((*(siPtr+1))&0xFF)>>cx)&0xFF;
dx = (dx&0xFF00) | ((dx&0xFF) | (ax&0xFF));
ax = (ax&0xFF00) | ((ax&0xFF) | dx&0xFF);
ax = (ax&0xFF00) | ((ax&0xFF)<<8) | (ax&0xFF);
ax = (ax&0xFF00) | (((*(siPtr+2))&0xFF)>>cx)&0xFF;
bx = (((ax&0xFF)<<8)&0xFF00) | (bx&0xFF);
cx = loc_1217;
ax = (ax&0xFF00) | (((*(siPtr+7))&0xFF)>>cx)&0xFF;
bx = (((bx&0xFF00) | (((ax&0xFF)<<8)&0xFF00))&0xFF00) | (bx&0xFF);
ax = (ax&0xFF00) | ((ax&0xFF) | ((bx&0xFF00)>>8));
ax = (ax&0xFF00) | ((ax&0xFF)<<8) | (ax&0xFF);
ax = (ax&0xFF00) | (((*(siPtr+7))&0xFF)>>cx)&0xFF;
bx = (bx&0xFF00) | (ax&0xFF);
cx = loc_122B;
ax = (ax&0xFF00) | (((*(siPtr+3))&0xFF)>>cx)&0xFF;
bx = (bx&0xFF00) | ((bx&0xFF) | (ax&0xFF));
ax = (ax&0xFF00) | ((ax&0xFF) | bx&0xFF);
ax = (ax&0xFF00) | ((ax&0xFF)<<8) | (ax&0xFF);
if(ax)
{
cx = dx;
ax = (ax&0xFF00) | (*diPtr)&0xFF;
ax = (ax&0xFF00) | 8;
outputBit(diPtr,0,(cx>>8)&0xFF);
outputBit(diPtr,1,(cx&0xFF));
outputBit(diPtr,2,(cx>>8)&0xFF);
outputBit(diPtr,3,(cx&0xFF));
}
siPtr += 4;
diPtr++;
}while(--bp);
}
if(loc_122B == 0xF8)
{
direction = 1;
}
else
{
direction = -1;
}
if(direction == -1)
{
goto label_12D9;
}
cx = loc_127A;
ax = (ax&0xFF00) | (((*siPtr)&0xFF)>>cx)&0xFF;
dx = (((ax&0xFF)<<8)&0xFF00) | (dx&0xFF);
ax = (((ax&0xFF)<<8)&0xFF00) | (ax&0xFF);
ax = (ax&0xFF00) | (((*(siPtr+1))&0xFF)>>cx)&0xFF;
dx = (dx&0xFF00) | (ax&0xFF);
ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF);
ax = (ax&0xFF00) | (((*(siPtr+2))&0xFF)>>cx)&0xFF;
bx = (((ax&0xFF)<<8)&0xFF00) | (bx&0xFF);
ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF);
ax = (ax&0xFF00) | (((*(siPtr+3))&0xFF)>>cx)&0xFF;
bx = (bx&0xFF00) | (ax&0xFF);
ax = ((((((ax&0xFF00)>>8)&0xFF) | (ax&0xFF))<<8)&0xFF00) | (ax&0xFF);
if(ax)
{
bp = dx;
ax = (ax&0xFF00) | (*diPtr)&0xFF;
ax = (ax&0xFF00) | 8;
outputBit(diPtr,0,(bp>>8)&0xFF);
outputBit(diPtr,1,(bp&0xFF));
outputBit(diPtr,2,(bx>>8)&0xFF);
outputBit(diPtr,3,(bx&0xFF));
}
siPtr+=4;
label_12D9:
diPtr+=loc_12D9;
siPtr+=loc_12DD;
bp = loc_12E1;
}while(--bp);
}*/
{
int cols = 320;
int rows = 200;
int row;
int col;
int i;
uint8* pP;
short atariScreen[320*200/4];
for(i=0;i<rows*cols/4;i++)
{
atariScreen[i] = *(int16*)sourcePtr;
flipShort(&atariScreen[i]);
sourcePtr+=2;
}
memcpy(globalAtariScreen,atariScreen,sizeof(atariScreen));
pP = (uint8*)destPtr;
for ( row = 0; row < rows; ++row )
{
for ( col = 0; col < cols; ++col, ++pP )
{
long int c, ind, b, plane;
ind = 80 * row + ( ( col >> 4 ) << 2 );
b = 0x8000 >> ( col & 0xf );
c = 0;
for ( plane = 0; plane < 4; ++plane )
{
if ( b & atariScreen[ind+plane] )
{
c |= (1 << plane);
}
}
*pP = (uint8)c;
}
}
}
/*
{
int i;
int j;
for(i=x;i<height+x;i++)
{
for(j=y;j<width*16+y;j++)
{
if(i>=0&&i<200&&j>=0&&j<320)
destPtr[i*320+j] = *(sourcePtr++);
}
}
}*/
}
void gfxModuleData_setPal256(int16* ptr)
{
int R;
int G;
int B;
int i;
for(i = 0; i < 256;i++)
{
R=*(ptr++);
G=*(ptr++);
B=*(ptr++);
lpalette[i].R = R;
lpalette[i].G = G;
lpalette[i].B = B;
lpalette[i].A = 255;
}
}
void gfxModuleData_setPal(uint8* ptr)
{
int i;
int R;
int G;
int B;
for(i = 0; i < 16; i++)
{
#define convertRatio 36.571428571428571428571428571429
short int atariColor = *(int16*)ptr;
//flipShort(&atariColor);
ptr += 2;
R = (int)(convertRatio*((atariColor & 0x700) >> 8));
G = (int)(convertRatio*((atariColor & 0x070) >> 4));
B = (int)(convertRatio*((atariColor & 0x007)));
if(R > 0xFF)
R = 0xFF;
if(G> 0xFF)
G = 0xFF;
if(B >0xFF)
B = 0xFF;
lpalette[i].R = R;
lpalette[i].G = G;
lpalette[i].B = B;
lpalette[i].A = 255;
}
}
void gfxModuleData_field_90(void)
{
}
void gfxModuleData_gfxWaitVSync(void)
{
}
void gfxModuleData_flip(void)
{
}
void gfxModuleData_field_64(char* sourceBuffer, int width, int height, char* dest, int x, int y, int color)
{
int i;
int j;
x = 0;
y = 0;
for(i = 0; i < height; i++)
{
for(j = 0; j < width; j++)
{
dest[(y + i) * 320 / 4 + x + j] = sourceBuffer[i * width + j];
}
}
}
void gfxModuleData_flipScreen(void)
{
memcpy(globalScreen, gfxModuleData.pPage00,320*200);
flip();
}
void flip()
{
int i;
byte paletteRGBA[256 * 4];
uint8* outPtr = scaledScreen;
uint8* inPtr = globalScreen;
for(i=0;i<256;i++)
{
paletteRGBA[i * 4 + 0] = lpalette[i].R;
paletteRGBA[i * 4 + 1] = lpalette[i].G;
paletteRGBA[i * 4 + 2] = lpalette[i].B;
paletteRGBA[i * 4 + 3] = 0xFF;
}
g_system->setPalette(paletteRGBA, 0, 16);
g_system->copyRectToScreen(globalScreen, 320, 0, 0, 320, 200);
g_system->updateScreen();
}
} // End of namespace Cruise

View file

@ -0,0 +1,72 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _GFXMODULE_H_
#define _GFXMODULE_H_
namespace Cruise {
struct gfxModuleDataStruct
{
int field_1;
int useTandy;
int useEGA;
int useVGA;
uint8* pPage00;
uint8* pPage10;
};
struct palEntry
{
uint8 R;
uint8 G;
uint8 B;
uint8 A;
};
typedef struct gfxModuleDataStruct gfxModuleDataStruct;
typedef struct palEntry palEntry;
extern gfxModuleDataStruct gfxModuleData;
extern palEntry lpalette[256];
extern short globalAtariScreen[320*200/4];
void gfxModuleData_gfxClearFrameBuffer(uint8* ptr);
void gfxModuleData_setPal(uint8* ptr);
void gfxModuleData_field_90(void);
void gfxModuleData_gfxWaitVSync(void);
void gfxModuleData_flip(void);
void gfxModuleData_field_64(char* sourceBuffer, int width, int height, char* dest, int x, int y, int color);
void gfxModuleData_gfxCopyScreen(char* sourcePtr,char* destPtr);
void gfxModuleData_field_60(char* sourcePtr, int width, int height, char* destPtr, int x, int y);
void gfxModuleData_flipScreen(void);
void gfxModuleData_setPal256(int16* ptr);
void flip(void);
} // End of namespace Cruise
#endif

330
engines/cruise/linker.cpp Normal file
View file

@ -0,0 +1,330 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
exportEntryStruct* parseExport(int* out1, int* pExportedFuncionIdx, char* buffer)
{
char localBuffer[256];
uint8 functionName[256];
uint8 overlayName[256];
char* dotPtr;
char* ptr2;
int idx;
int numExport;
exportEntryStruct* currentExportEntry;
uint8* entity1Name;
int i;
*out1 = 0;
*pExportedFuncionIdx = 0;
strcpyuint8(localBuffer, buffer);
dotPtr = strchr(localBuffer,'.');
if(dotPtr)
{
strcpyuint8(functionName,dotPtr+1);
*dotPtr = 0;
strcpyuint8(overlayName,localBuffer);
}
else
{
overlayName[0] = 0;
strcpyuint8(functionName,buffer);
}
ptr2 = strchr((char*)functionName,':');
if(ptr2)
{
*ptr2 = 0;
*out1 = 1;
}
strToUpper(overlayName);
strToUpper(functionName);
if(strlen((char*)overlayName) == 0)
return NULL;
idx = findOverlayByName2(overlayName);
if(idx == -4)
return(NULL);
if(overlayTable[idx].alreadyLoaded == 0)
return(NULL);
if(!overlayTable[idx].ovlData)
return(NULL);
numExport = overlayTable[idx].ovlData->numExport;
currentExportEntry = overlayTable[idx].ovlData->exportDataPtr;
entity1Name = overlayTable[idx].ovlData->exportNamesPtr;
if(!entity1Name)
return(0);
for(i=0;i<numExport;i++)
{
uint8 exportedName[256];
uint8* name = entity1Name + currentExportEntry->offsetToName;
strcpyuint8(exportedName,name);
strToUpper(exportedName);
if(!strcmpuint8(functionName,exportedName))
{
*pExportedFuncionIdx = idx;
return(currentExportEntry);
}
currentExportEntry++;
}
return(NULL);
}
int updateScriptImport(int ovlIdx)
{
char buffer[256];
ovlDataStruct* ovlData;
int numData3;
int size5;
int numImport;
int param;
int var_32;
ovlData3Struct* pScript;
// char* importDataPtr;
// char* namePtr;
// char* linkDataPtr;
if(!overlayTable[ovlIdx].ovlData)
return(-4);
ovlData = overlayTable[ovlIdx].ovlData;
numData3 = ovlData->numScripts1;
size5 = ovlData->numScripts2;
numImport = ovlData->numImport;
param = 0;
// do it for the 2 first string types
do
{
int i = 0;
if(param == 0)
{
var_32 = numData3;
}
else
{
var_32 = size5;
}
if(var_32)
{
do
{
importScriptStruct* ptrImportData;
uint8* ptrImportName;
uint8* ptrData;
int var_22 = 0;
if(param == 0)
{
pScript = getOvlData3Entry(ovlIdx, i);
}
else
{
pScript = scriptFunc1Sub2(ovlIdx, i);
}
ptrImportData = (importScriptStruct*) (pScript->dataPtr + pScript->offsetToImportData); // import data
ptrImportName = pScript->dataPtr + pScript->offsetToImportName; // import name
ptrData = pScript->dataPtr;
var_22 = 0;
if(pScript->numImport > 0)
{
int counter = pScript->numImport;
do
{
int param2 = ptrImportData->type;
if(param2 != 70)
{
exportEntryStruct* ptrDest2;
int out1;
int out2;
strcpyuint8(buffer,ptrImportName + ptrImportData->offsetToName);
ptrDest2 = parseExport(&out1,&out2,buffer);
if(ptrDest2 && out2)
{
int temp = ptrImportData->offset;
if(out1) //is sub function... (ie 'invent.livre:s')
{
uint8* ptr = ptrData + temp;
*(ptr+1) = out2;
*(int16*)(ptr+2) = ptrDest2->idx;
flipShort((int16*)(ptr+2));
}
else
{
if(param2 == 20 || param2 == 30 || param2 == 40 || param2 == 50 ) // this patch a double push
{
uint8* ptr = ptrData + temp;
*(ptr+1) = 0;
*(ptr+2) = out2; // update the overlay number
*(int16*)(ptr+4) = ptrDest2->idx;
flipShort((int16*)(ptr+4));
}
else
{
int var_4 = ptrDest2->var4;
if(var_4&1)
{
param2 = 8;
}
else
{
param2 = 16;
}
if(var_4>=0 && var_4<=3)
{
param2 |= 5;
}
else
{
param2 |= 6;
}
*(ptrData + temp) = param2;
*(ptrData + temp + 1 ) = out2;
*(int16*)(ptrData + temp + 2) = ptrDest2->idx;
flipShort((int16*)(ptrData + temp + 2));
}
}
}
}
ptrImportData++;
}while(--counter);
}
}while(++i<var_32);
}
}while(++param<2);
if(ovlData->importDataPtr && ovlData->importNamePtr && numImport)
{
int numImport2 = numImport;
int i;
for(i=0;i<numImport2;i++)
{
char buffer[256];
int out1;
int foundExportIdx;
exportEntryStruct* pFoundExport;
int linkType;
int linkEntryIdx;
strcpyuint8(buffer,ovlData->importNamePtr + ovlData->importDataPtr[i].nameOffset);
pFoundExport = parseExport(&out1,&foundExportIdx,buffer);
linkType = ovlData->importDataPtr[i].linkType;
linkEntryIdx = ovlData->importDataPtr[i].linkIdx;
if(pFoundExport && foundExportIdx)
{
switch(linkType)
{
case 0: // var
{
ovlData->linkDataPtr[linkEntryIdx].varIdx = foundExportIdx;
ovlData->linkDataPtr[linkEntryIdx].varNameOffset = pFoundExport->offsetToName;
break;
}
case 1: // string
{
ovlData->linkDataPtr[linkEntryIdx].stringIdx = foundExportIdx;
ovlData->linkDataPtr[linkEntryIdx].stringNameOffset = pFoundExport->offsetToName;
break;
}
case 2: // proc
{
ovlData->linkDataPtr[linkEntryIdx].procIdx = foundExportIdx;
ovlData->linkDataPtr[linkEntryIdx].procNameOffset = pFoundExport->offsetToName;
break;
}
}
}
}
}
return(0);
}
// check that the newly loaded isn't used by the already loaded overlays
void updateAllScriptsImports(void)
{
int i;
for(i=0;i<90;i++)
{
if(overlayTable[i].ovlData && overlayTable[i].alreadyLoaded)
{
updateScriptImport(i);
}
}
}
} // End of namespace Cruise

34
engines/cruise/linker.h Normal file
View file

@ -0,0 +1,34 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _LINKER_H_
#define _LINKER_H_
namespace Cruise {
void updateAllScriptsImports(void);
} // End of namespace Cruise
#endif

471
engines/cruise/loadSave.cpp Normal file
View file

@ -0,0 +1,471 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
void loadSavegameDataSub1(FILE* fileHandle)
{
int i;
for(i=1;i<numOfLoadedOverlay;i++)
{
filesData[i].field_4 = NULL;
filesData[i].field_0 = NULL;
filesData2[i].field_0 = 0;
if(overlayTable[i].alreadyLoaded)
{
fread(&filesData2[i].field_0,2,1,fileHandle);
if(filesData2[i].field_0)
{
filesData[i].field_0 = (uint8*)mallocAndZero(filesData2[i].field_0);
if(filesData[i].field_0)
{
fread(filesData[i].field_0,filesData2[i].field_0,1,fileHandle);
}
}
fread(&filesData2[i].field_2,2,1,fileHandle);
if(filesData2[i].field_2)
{
filesData[i].field_4 = (uint8*)mallocAndZero(filesData2[i].field_2*12);
if(filesData[i].field_4)
{
fread(filesData[i].field_4,filesData2[i].field_2*12,1,fileHandle);
}
}
}
}
}
void loadScriptsFromSave(FILE* fileHandle,scriptInstanceStruct* entry)
{
short int numScripts;
int i;
fread(&numScripts,2,1,fileHandle);
for(i=0;i<numScripts;i++)
{
scriptInstanceStruct* ptr = (scriptInstanceStruct*)mallocAndZero(sizeof(scriptInstanceStruct));
fread(ptr,0x1C,1,fileHandle); // use 0x1C as our scriptInstanceStruct is bigger than in original because of cross platform problems
fread(&ptr->varA,2,1,fileHandle);
if(ptr->varA)
{
ptr->var6 = (uint8*)mallocAndZero(ptr->varA);
fread(ptr->var6,ptr->varA,1,fileHandle);
}
/////////
ptr->bitMask = *((int16*)ptr+1);
/////////
ptr->nextScriptPtr = 0;
entry->nextScriptPtr = ptr;
entry = ptr;
}
}
void loadSavegameDataSub2(FILE * f)
{
unsigned short int n_chunks;
int i;
objectStruct *p;
objectStruct *t;
objectHead.next = NULL; // Not in ASM code, but I guess the variable is defaulted
// to this value in the .exe
fread(&n_chunks, 2, 1, f);
// BIG ENDIAN MACHINES, PLEASE SWAP IT
p = &objectHead;
for (i = 0; i < n_chunks; i++)
{
t = (objectStruct *) mallocAndZero(sizeof(objectStruct));
fseek(f, 4, SEEK_CUR);
fread(&t->idx, 1, 0x30, f);
t->next = NULL;
p->next = t;
t->prev = objectHead.prev;
objectHead.prev = t;
p = t;
}
}
void loadSavegameActor(FILE* fileHandle)
{
short int numEntry;
actorStruct* ptr;
int i;
fread(&numEntry,2,1,fileHandle);
ptr = &actorHead;
for(i=0;i<numEntry;i++)
{
actorStruct* current = (actorStruct*)mallocAndZero(sizeof(actorStruct));
fseek(fileHandle, 4, SEEK_CUR);
fread(&current->var4,0x26,1,fileHandle);
current->next = NULL;
ptr->next = current;
current->prev = actorHead.prev;
actorHead.prev = current;
ptr = current->next;
}
}
void loadSavegameDataSub5(FILE* fileHandle)
{
if(var1)
{
fread(&saveVar1,1,1,fileHandle);
if(saveVar1)
{
fread(saveVar2,saveVar1,1,fileHandle);
}
}
else
{
fread(&saveVar1,1,1,fileHandle);
}
}
void loadSavegameDataSub6(FILE* fileHandle)
{
int32 var;
fread(&var,4,1,fileHandle);
flipLong(&var);
if(var)
{
int i;
fread(&numberOfWalkboxes, 2, 1, fileHandle);
if(numberOfWalkboxes)
{
fread(walkboxType, numberOfWalkboxes * 2, 1, fileHandle);
fread(walkboxType, numberOfWalkboxes * 2, 1, fileHandle);
}
for(i=0;i<10;i++)
{
fread(&persoTable[i],4,1,fileHandle);
if(persoTable[i])
{
assert(sizeof(persoStruct) == 0x6AA);
persoTable[i] = (persoStruct*)mallocAndZero(sizeof(persoStruct));
fread(persoTable[i],0x6AA,1,fileHandle);
}
}
}
}
int loadSavegameData(int saveGameIdx)
{
char buffer[256];
FILE* fileHandle;
char saveIdentBuffer[6];
int j;
int initVar1Save;
objectStruct* currentObjectHead;
sprintf(buffer,"CR.%d",saveGameIdx);
fileHandle = fopen(buffer,"rb");
if(!fileHandle)
{
printInfoBlackBox("Sauvegarde non trouvée...");
waitForPlayerInput();
return(-1);
}
printInfoBlackBox("Chargement en cours...");
fread(saveIdentBuffer,6,1,fileHandle);
if(strcmp(saveIdentBuffer,"SAVPC"))
{
fclose(fileHandle);
return(-1);
}
//initVars();
fread(&var1,2,1,fileHandle);
fread(&var2,2,1,fileHandle);
fread(&var3,2,1,fileHandle);
fread(&var4,2,1,fileHandle);
fread(&userEnabled,2,1,fileHandle);
fread(&var6,2,1,fileHandle);
fread(&var7,2,1,fileHandle);
fread(&var8,2,1,fileHandle);
fread(&userDelay,2,1,fileHandle);
fread(&sysKey,2,1,fileHandle);
fread(&var11,2,1,fileHandle);
fread(&var12,2,1,fileHandle);
fread(&var13,2,1,fileHandle);
fread(&var14,2,1,fileHandle);
fread(&affichePasMenuJoueur,2,1,fileHandle);
fread(&var20,2,1,fileHandle);
fread(&var22,2,1,fileHandle);
fread(&var23,2,1,fileHandle);
fread(&var24,2,1,fileHandle);
fread(&automaticMode,2,1,fileHandle);
// video param (not loaded in EGA mode)
fread(&video4,2,1,fileHandle);
fread(&video2,2,1,fileHandle);
fread(&video3,2,1,fileHandle);
fread(&colorOfSelectedSaveDrive,2,1,fileHandle);
//
fread(&var30,2,1,fileHandle);
fread(&var31,2,1,fileHandle);
fread(&var34,2,1,fileHandle);
fread(&var35,2,1,fileHandle);
fread(&animationStart,2,1,fileHandle);
fread(&currentActiveBackgroundPlane,2,1,fileHandle);
fread(&initVar3,2,1,fileHandle);
fread(&initVar2,2,1,fileHandle);
fread(&var22,2,1,fileHandle);
fread(&main5,2,1,fileHandle);
fread(&numOfLoadedOverlay,2,1,fileHandle);
fread(&setup1,2,1,fileHandle);
fread(&fontFileIndex,2,1,fileHandle);
fread(&currentActiveMenu,2,1,fileHandle);
fread(&main7,2,1,fileHandle); // ok
fread(&main17,2,1,fileHandle);
fread(&main14,2,1,fileHandle);
fread(&main8,2,1,fileHandle);
fread(&var39,2,1,fileHandle);
fread(&var42,2,1,fileHandle);
fread(&var45,2,1,fileHandle);
fread(&var46,2,1,fileHandle);
fread(&var47,2,1,fileHandle);
fread(&var48,2,1,fileHandle);
fread(&flagCt,2,1,fileHandle);
fread(&var41,2,1,fileHandle);
fread(&entrerMenuJoueur,2,1,fileHandle);
fread(var50,64,1,fileHandle);
fread(var50,64,1,fileHandle); // Hu ? why 2 times ?
fread(&systemStrings,sizeof(systemStrings),1,fileHandle); // ok
fread(currentCtpName,40,1,fileHandle);
fread(backgroundTable,120,1,fileHandle);
fread(palette,256,2,fileHandle); // ok
fread(initVar5,24,1,fileHandle);
fread(globalVars,setup1*2,1,fileHandle);
fread(filesDatabase,9766,1,fileHandle);
fread(overlayTable,40*numOfLoadedOverlay,1,fileHandle); // ok
fread(mediumVar,0x880,1,fileHandle);
loadSavegameDataSub1(fileHandle);
loadScriptsFromSave(fileHandle,&scriptHandle2);
loadScriptsFromSave(fileHandle,&scriptHandle1);
loadSavegameDataSub2(fileHandle);
loadBackgroundIncrustFromSave(fileHandle);
loadSavegameActor(fileHandle);
loadSavegameDataSub5(fileHandle);
loadSavegameDataSub6(fileHandle);
fclose(fileHandle); // finished with loading !!!!! Yatta !
for(j=0;j<64;j++)
{
mediumVar[j].ptr=NULL;
}
for(j=1;j<numOfLoadedOverlay;j++)
{
if(overlayTable[j].alreadyLoaded)
{
overlayTable[j].alreadyLoaded = 0;
loadOverlay((uint8*)overlayTable[j].overlayName);
if(overlayTable[j].alreadyLoaded)
{
ovlDataStruct* ovlData = overlayTable[j].ovlData;
if(filesData[j].field_0)
{
if(ovlData->data4Ptr)
{
free(ovlData->data4Ptr);
}
ovlData->data4Ptr = (uint8*)filesData[j].field_0;
ovlData->sizeOfData4 = filesData2[j].field_0;
}
if(filesData[j].field_4)
{
if(ovlData->objData2WorkTable)
{
free(ovlData->objData2WorkTable);
}
ovlData->objData2WorkTable = (objectParams*)filesData[j].field_4; // TODO: fix !
ovlData->size9 = filesData2[j].field_2;
}
}
}
}
updateAllScriptsImports();
saveVar6[0] = 0;
initVar1Save = initVar1;
for(j=0;j<257;j++)
{
if(filesDatabase[j].subData.ptr)
{
int i;
int k;
for(i=j+1;i<257;i++)
{
if(filesDatabase[i].subData.ptr)
{
if(strcmpuint8(filesDatabase[j].subData.name,filesDatabase[i].subData.name))
{
break;
}
}
else
{
break;
}
}
for(k=j;k<i;k++)
{
if(filesDatabase[k].subData.ptr2)
initVar1 = 0;
filesDatabase[k].subData.ptr = NULL;
filesDatabase[k].subData.ptr2 = NULL;
}
if(i<2)
{
printf("Unsupported mono file load!\n");
exit(1);
//loadFileMode1(filesDatabase[j].subData.name,filesDatabase[j].subData.var4);
}
else
{
loadFileMode2((uint8*)filesDatabase[j].subData.name,filesDatabase[j].subData.index, j, i-j);
j = i-1;
}
initVar1 = initVar1Save;
}
}
saveVar6[0] = 0;
currentObjectHead = objectHead.next;
while(currentObjectHead)
{
if(currentObjectHead->type == 5)
{
uint8* ptr = mainProc14(currentObjectHead->overlay,currentObjectHead->idx);
ASSERT(0);
if(ptr)
{
ASSERT(0);
//*(int16*)(currentobjectHead->datas+0x2E) = getSprite(ptr,*(int16*)(currentobjectHead->datas+0xE));
}
else
{
//*(int16*)(currentobjectHead->datas+0x2E) = 0;
}
}
currentObjectHead = currentObjectHead->next;
}
//TODO: here, restart music
if(strlen((char*)currentCtpName))
{
ctpVar1 = 1;
loadCtp(currentCtpName);
ctpVar1 = 0;
}
//prepareFadeOut();
//gfxModuleData.gfxFunction8();
for(j=0;j<8;j++)
{
if(strlen((char*)backgroundTable[j].name))
{
loadBackground(backgroundTable[j].name,j);
}
}
regenerateBackgroundIncrust(&backgroundIncrustHead);
// to finish
changeCursor(0);
mainDraw(1);
flipScreen();
return(0);
}
} // End of namespace Cruise

34
engines/cruise/loadSave.h Normal file
View file

@ -0,0 +1,34 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _LOADSAVE_H_
#define _LOADSAVE_H_
namespace Cruise {
int loadSavegameData(int saveGameIdx);
} // End of namespace Cruise
#endif

1142
engines/cruise/mainDraw.cpp Normal file

File diff suppressed because it is too large Load diff

48
engines/cruise/mainDraw.h Normal file
View file

@ -0,0 +1,48 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _MAINDRAW_H_
#define _MAINDRAW_H_
namespace Cruise {
extern int currentTransparent;
extern int16 polyBuffer3[404];
extern int16 polyBuffer2[512];
extern int m_color;
int upscaleValue(int value, int scale);
void pixel(int x, int y, char color);
void mainDraw(int16 param);
void flipScreen(void);
void buildPolyModel(int X, int Y, int scale, char* ptr2, char* destBuffer, char* dataPtr);
void getPolyData(int fileIndex, int X, int Y, int *newScale, int *newY, int *newX, char **newDataPtr, int scale, char* dataPtr);
void mainDrawSub4(int objX1, int var_6, objectStruct* currentObjPtr, char* data1, int objY2, int objX2, char* output, char* data2);
char* drawPolyMode2(char* si, int cx);
} // End of namespace Cruise
#endif

321
engines/cruise/menu.cpp Normal file
View file

@ -0,0 +1,321 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
menuStruct* menuTable[8];
menuStruct* createMenu(int X, int Y, char* menuName)
{
menuStruct* entry;
entry = (menuStruct*)malloc(sizeof(menuStruct));
ASSERT(entry);
entry->x = X - 80;
entry->y = Y;
entry->stringPtr = menuName;
entry->numElements = 0;
entry->ptrNextElement = NULL;
entry->gfx = renderText(160, (uint8*)menuName);
return entry;
}
// TODO: rewrite to remove the goto
void addSelectableMenuEntry(int var0, int var1, menuStruct* pMenu, int var2, int color, char* menuText)
{
menuElementStruct* di;
menuElementStruct* var_6;
menuElementStruct* pNewElement;
menuElementSubStruct* pSubStruct;
menuElementSubStruct* pSubStructCurrent;
if(pMenu->numElements <= 48)
{
var_6 = pMenu->ptrNextElement;
if(var_6)
{
do
{
di = var_6;
if(var2)
{
if(!strcmp(var_6->string, menuText))
{
pNewElement = var_6;
pSubStruct = (menuElementSubStruct*)allocAndZero(sizeof(menuElementSubStruct));
ASSERT(pSubStruct);
pSubStruct->pNext = NULL;
pSubStruct->var2 = var0;
pSubStruct->var4 = var1;
pSubStructCurrent = pNewElement->ptrSub;
if(!pSubStructCurrent)
{
pNewElement->ptrSub = pSubStruct;
return;
}
if(pSubStructCurrent->pNext)
{
do
{
pSubStructCurrent = pSubStructCurrent->pNext;
}while(pSubStructCurrent->pNext);
}
pSubStructCurrent->pNext = pSubStruct;
return;
}
}
var_6 = var_6->next;
}
while(var_6);
var_6 = di;
}
pNewElement = (menuElementStruct*)allocAndZero(sizeof(menuElementStruct));
ASSERT(pNewElement);
pSubStruct = (menuElementSubStruct*)allocAndZero(sizeof(menuElementSubStruct));
ASSERT(pSubStruct);
pNewElement->string = menuText;
pNewElement->next = NULL;
pNewElement->varC = 0;
pNewElement->color = color;
pNewElement->gfx = renderText(160,(uint8*)menuText);
if(var_6 == NULL)
{
pMenu->ptrNextElement = pNewElement;
}
else
{
var_6->next = pNewElement;
}
pNewElement->ptrSub = pSubStruct;
pSubStruct->pNext = NULL;
pSubStruct->var2 = var0;
pSubStruct->var4 = var1;
pMenu->numElements++;
}
}
void updateMenuMouse(int mouseX, int mouseY, menuStruct* pMenu)
{
if(pMenu)
{
if(pMenu->gfx)
{
int height = pMenu->gfx->height; // rustine
int var_2 = 0;
menuElementStruct* pCurrentEntry = pMenu->ptrNextElement;
while(pCurrentEntry)
{
pCurrentEntry->varC = 0;
if(var_2 == 0)
{
if((mouseX > pCurrentEntry->x) && ((pCurrentEntry->x + 160) >= mouseX))
{
if((mouseY > pCurrentEntry->y) && ((pCurrentEntry->y + height) >= mouseY))
{
var_2 = 1;
pCurrentEntry->varC = 1;
}
}
}
pCurrentEntry = pCurrentEntry->next;
}
}
}
}
int processMenu(menuStruct* pMenu)
{
int16 mouseX;
int16 mouseY;
int16 mouseButton;
int di;
int si;
currentActiveMenu = 0;
mainDraw(1);
flipScreen();
di = 0;
si = 0;
do
{
getMouseStatus(&main10, &mouseX, &mouseButton, &mouseY);
updateMenuMouse(mouseX, mouseY, pMenu);
if(mouseButton)
{
if(di)
{
si = 1;
}
}
else
{
di = 1;
}
mainDraw(1);
flipScreen();
// readKeyboard();
}while(!si);
currentActiveMenu = -1;
mainDraw(1);
flipScreen();
return 0;
}
int playerMenu(int menuX, int menuY)
{
int retourMenu;
int restartGame = 0;
if(entrerMenuJoueur && affichePasMenuJoueur)
{
if(var0)
{
systemStrings.param = 0;
var24 = 0;
var23 = 0;
freeStuff2();
}
/*
if(currentMenu)
{
freeMenu(currentMenu);
currentMenu = 0;
var37 = 0;
var38 = 0;
main9 = -1;
}
if(inventoryMenu)
{
freeMenu(inventoryMenu);
inventoryMenu = 0;
var37 = 0;
var38 = 0;
main9 = -1;
}*/
/* if(mouseVar2)
{
free3(mouseVar2);
} */
/* mouseVar2 = 0;
mouseVar1 = 0; */
freeDisk();
menuTable[0] = createMenu(menuX, menuY, "Menu Joueur");
ASSERT(menuTable[0]);
addSelectableMenuEntry(0, 3, menuTable[0], 1, -1, "Lecteur de Sauvegarde");
if(userEnabled)
{
addSelectableMenuEntry(0, 4, menuTable[0], 1, -1, "Sauvegarde");
}
addSelectableMenuEntry(0, 5, menuTable[0], 1, -1, "Chargement");
addSelectableMenuEntry(0, 6, menuTable[0], 1, -1, "Recommencer le jeu");
addSelectableMenuEntry(0, 7, menuTable[0], 1, -1, "Chargement");
retourMenu = processMenu(menuTable[0]);
}
return 0;
}
void freeGfx(gfxEntryStruct* pGfx)
{
if(pGfx->imagePtr)
{
free(pGfx->imagePtr);
}
free(pGfx);
}
void freeMenu(menuStruct* pMenu)
{
menuElementStruct* pElement = pMenu->ptrNextElement;
while(pElement)
{
menuElementStruct* next;
menuElementSubStruct* pSub = pElement->ptrSub;
next = pElement->next;
while(pSub)
{
menuElementSubStruct* next;
next = pSub->pNext;
free(pSub);
pSub=next;
}
if(pElement->gfx)
{
freeGfx(pElement->gfx);
}
free(pElement);
pElement = next;
}
freeGfx(pMenu->gfx);
free(pMenu);
}
} // End of namespace Cruise

49
engines/cruise/menu.h Normal file
View file

@ -0,0 +1,49 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
namespace Cruise {
struct menuStruct
{
char* stringPtr;
gfxEntryStruct* gfx;
int x;
int y;
int numElements;
menuElementStruct* ptrNextElement;
};
typedef struct menuStruct menuStruct;
extern menuStruct* menuTable[8];
menuStruct* createMenu(int X, int Y, char* menuName);
void addSelectableMenuEntry(int var0, int var1, menuStruct* pMenu, int var2, int color, char* menuText);
void updateMenuMouse(int mouseX, int mouseY, menuStruct* pMenu);
int processMenu(menuStruct* pMenu);
void freeMenu(menuStruct* pMenu);
int playerMenu(int menuX, int menuY);
} // End of namespace Cruise

51
engines/cruise/mouse.cpp Normal file
View file

@ -0,0 +1,51 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
int16 main10;
void getMouseStatus(int16* pMouseVar, int16* pMouseX, int16* pMouseButton, int16* pMouseY)
{
// mouseStatusStruct localStatus;
// OSystem_GetMouseStatus(&localStatus);
*pMouseX = 0;
*pMouseY = 0;
*pMouseButton = 0;
/*
if(localStatus.left)
*pMouseButton |= 1;
if(localStatus.right)
*pMouseButton |= 2;
if(localStatus.middle)
*pMouseButton |= 4;
*/
}
} // End of namespace Cruise

37
engines/cruise/mouse.h Normal file
View file

@ -0,0 +1,37 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _MOUSE_H_
#define _MOUSE_H_
namespace Cruise {
extern int16 main10;
void getMouseStatus(int16* pMouseVar, int16* pMouseX, int16* pMouseButton, int16* pMouseY);
} // End of namespace Cruise
#endif

519
engines/cruise/object.cpp Normal file
View file

@ -0,0 +1,519 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
//10 values:
/*
0 = X
1 = Y
3 = fileIdx
4 = scale
*/
objDataStruct* getObjectDataFromOverlay(int ovlIdx,int objIdx)
{
objDataStruct* var_6;
if(ovlIdx<1 || objIdx <0)
return NULL;
if(!overlayTable[ovlIdx].ovlData)
return NULL;
if(overlayTable[ovlIdx].ovlData->numObjData <= objIdx)
return NULL;
var_6 = overlayTable[ovlIdx].ovlData->objDataTable;
if(!var_6)
return NULL;
return (&var_6[objIdx]);
}
int16 getMultipleObjectParam(int16 overlayIdx,int16 objectIdx,objectParamsQuery* returnParam)
{
int16 size;
int16 var_A;
int16 var_14;
objectParams* ptr2;
objDataStruct* ptr;
ovlDataStruct* ovlData;
// int16 type;
ptr = getObjectDataFromOverlay(overlayIdx,objectIdx);
if(!ptr)
return -11;
ovlData = overlayTable[overlayIdx].ovlData;
switch(ptr->var1)
{
case 0:
{
ptr2 = &ovlData->objData2SourceTable[ptr->var5];
var_14 = globalVars[*(int16*)(&overlayTable[overlayIdx].field_14 + ptr->var6)];
var_A = ptr2->var5;
break;
}
case 1:
{
ptr2 = &ovlData->objData2WorkTable[ptr->var4];
var_A = var_14 = ptr2->var5;
size = var_A + ptr->var5;
if(ptr->var5 + var_14<=ovlData->size8)
{
var_A = ovlData->objData2SourceTable[ptr->var5 + var_14].var5;
}
break;
}
default:
{
printf("unsupported case %d in getMultipleObjectParam\n", ptr->var1);
exit(1);
}
}
returnParam->X = ptr2->X;
returnParam->Y = ptr2->Y;
returnParam->baseFileIdx = ptr2->baseFileIdx;
returnParam->fileIdx = ptr2->var3;
returnParam->scale = ptr2->scale;
returnParam->var5 = var_14;
returnParam->var6 = var_A;
returnParam->var7 = ptr->var3;
return 0;
}
objectStruct* addObject(int16 overlayIdx,int16 param2,objectStruct* pHead,int16 scriptType,int16 scriptNumber,int16 scriptOverlay, int16 param3, int16 param4)
{
int16 var;
objectStruct* newElement;
objectStruct* currentHead = pHead;
objectStruct* currentHead2;
objectStruct* currentHead3;
if(getSingleObjectParam(overlayIdx,param2,2,&var)<0)
{
return 0;
}
currentHead3 = currentHead;
currentHead2 = currentHead->next;
while(currentHead2)
{
if(currentHead2->type == 3)
{
break;
}
if(currentHead2->type != 5)
{
int16 lvar2;
getSingleObjectParam(currentHead2->overlay,currentHead2->idx,2,&lvar2);
if(lvar2 > var)
break;
}
currentHead3 = currentHead2;
currentHead2 = currentHead2->next;
}
if(currentHead2)
{
if( (currentHead2->overlay == overlayIdx) &&
(currentHead2->backgroundPlane == param3) &&
(currentHead2->idx == param2) &&
(currentHead2->type == param4))
return NULL;
}
currentHead = currentHead2;
newElement = (objectStruct*)mallocAndZero(sizeof(objectStruct));
if(!newElement)
return 0;
newElement->next = currentHead3->next;
currentHead3->next = newElement;
newElement->idx = param2;
newElement->type = param4;
newElement->backgroundPlane = param3;
newElement->overlay = overlayIdx;
newElement->hide = 0;
newElement->field_16 = scriptNumber;
newElement->field_18 = scriptOverlay;
newElement->gfxPtr = NULL;
newElement->followObjectIdx = param2;
newElement->followObjectOverlayIdx = overlayIdx;
newElement->field_1A = scriptType;
newElement->field_20 = 0;
newElement->field_22 = 0;
newElement->nextAnimDelay = 0;
newElement->field_2C = 0;
newElement->currentAnimDelay = 0;
newElement->field_2A = 0;
newElement->field_26 = 0;
newElement->field_30 = 0;
if(currentHead)
{
newElement->prev = currentHead->prev;
currentHead->prev = newElement;
}
else
{
newElement->prev = pHead->prev;
pHead->prev = newElement;
}
return newElement;
}
void setObjectPosition(int16 param1,int16 objIdx,int16 param3,int16 param4)
{
objDataStruct* ptr;
objectParams* ptr2;
ptr = getObjectDataFromOverlay(param1, objIdx);
if(!ptr)
{
return;
ASSERT(0);
}
//overlayTable[param1].ovlData
switch(ptr->var1)
{
case 1:
{
ptr2 = &overlayTable[param1].ovlData->objData2WorkTable[ptr->var4];
switch(param3)
{
case 0: // x
{
ptr2->X = param4;
break;
}
case 1: // y
{
ptr2->Y = param4;
break;
}
case 2: // base file
{
ptr2->baseFileIdx = param4;
break;
}
case 3:
{
ptr2->var3 = param4;
break;
}
case 4: // scale
{
ptr2->scale = param4;
break;
}
case 5: // box colision
{
ptr2->var5 = param4;
break;
}
default:
{
ASSERT(0);
}
}
break;
}
default:
{
ASSERT(0);
}
}
}
void Op_7Sub1(int16 param1, int16 param2, objectStruct* objPtr)
{
int16 var;
objectStruct* var8;
objectStruct* var40;
objectStruct* var3E;
objectStruct* currentObjPtrPrevious;
objectStruct* currentObjPtr2;
objectStruct* match;
getSingleObjectParam(param1,param2,2,&var);
currentObjPtrPrevious = objPtr;
currentObjPtr2 = objPtr->next;
match = NULL;
var40 = NULL;
var3E = NULL;
var8 = objPtr;
while(currentObjPtr2)
{
if((currentObjPtr2->overlay == param1) && (currentObjPtr2->idx == param2)) // found
{
currentObjPtrPrevious->next = currentObjPtr2->next;
if(currentObjPtr2->next)
{
currentObjPtr2->next->prev = currentObjPtr2->prev;
}
else
{
objPtr->prev = currentObjPtr2->prev;
}
if(var40)
{
var40->prev = currentObjPtr2;
}
else
{
var3E = currentObjPtr2;
}
currentObjPtr2->prev = NULL;
currentObjPtr2->next = var40;
var40 = currentObjPtr2;
if(match == NULL)
{
match = currentObjPtr2;
}
}
else
{
if(currentObjPtr2->type == 5)
{
var2 = 32000;
}
else
{
int16 varC;
getSingleObjectParam(currentObjPtr2->overlay,currentObjPtr2->idx,2,&varC);
var2 = varC;
}
if(var>var2)
{
var8 = currentObjPtr2;
}
currentObjPtrPrevious=currentObjPtrPrevious->next;
}
currentObjPtr2 = currentObjPtr2->next;
}
if(match)
{
objectStruct* temp;
temp = var8->next;
var8->next = var40;
match->next = temp;
if(objPtr!=var8)
{
var40->prev = var8;
}
if(!temp)
{
temp = match;
}
temp->prev = match;
}
}
int16 Op_7Sub(int ovlIdx,int objIdx,int param2)
{
objDataStruct* ptr;
// uint16 param;
ovlDataStruct* ovlData;
ptr = getObjectDataFromOverlay(ovlIdx,objIdx);
if(!ptr)
return -11;
ovlData = overlayTable[ovlIdx].ovlData;
switch(ptr->var1)
{
case 0:
{
globalVars[overlayTable[ovlIdx].field_14 + ptr->var6] = param2;
Op_7Sub1(ovlIdx,param2,&objectHead);
break;
}
case 1:
{
objectParams* destEntry;
objectParams* sourceEntry;
if(ptr->var5+param2 > ovlData->size8)
{
return 0;
}
destEntry = &ovlData->objData2WorkTable[ptr->var4];
sourceEntry = &ovlData->objData2SourceTable[ptr->var5 + param2];
memcpy(destEntry,sourceEntry,sizeof(objectParams));
destEntry->var5 = param2;
Op_7Sub1(ovlIdx,param2,&objectHead);
break;
}
default:
{
printf("Unsupported param = %d in Op_7Sub\n",ptr->var1);
// exit(1);
}
}
return 0;
}
int16 getSingleObjectParam(int16 overlayIdx,int16 param2,int16 param3,int16* returnParam)
{
int var_A = 0;
char* ptr3 = NULL;
objDataStruct* ptr;
ovlDataStruct* ovlData;
objectParams* ptr2;
ptr = getObjectDataFromOverlay(overlayIdx,param2);
if(!ptr)
return -11;
ovlData = overlayTable[overlayIdx].ovlData;
switch(ptr->var1)
{
case 0:
case 3:
{
var_A = globalVars[ptr->var6];
ptr2 = &ovlData->objData2SourceTable[ptr->var5];
break;
}
case 1:
{
ptr2 = &ovlData->objData2WorkTable[ptr->var4];
var_A = ptr2->var5;
break;
}
default:
{
printf("Unsupported case %d in getSingleObjectParam\n",ptr->var1);
exit(1);
}
}
switch(param3)
{
case 0:
{
*returnParam = ptr2->X;
break;
}
case 1:
{
*returnParam = ptr2->Y;
break;
}
case 2:
{
*returnParam = ptr2->baseFileIdx;
break;
}
case 3:
{
*returnParam = ptr2->var3;
break;
}
case 4:
{
*returnParam = ptr2->scale;
break;
}
case 5:
{
*returnParam = var_A;
break;
}
default:
{
printf("Unsupported case %d in getSingleObjectParam case 1\n",param3);
exit(1);
}
}
return 0;
}
} // End of namespace Cruise

94
engines/cruise/object.h Normal file
View file

@ -0,0 +1,94 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _OBJECT_H_
#define _OBJECT_H_
namespace Cruise {
struct gfxEntryStruct
{
uint8* imagePtr;
int imageSize;
int fontIndex;
int height;
int width; // for font: max right border; for sprite: just width
};
typedef struct gfxEntryStruct gfxEntryStruct;
struct objectStruct
{
struct objectStruct* next;
struct objectStruct* prev;
int16 idx;
int16 type;
int16 overlay ;
int16 field_A ;
int16 field_C ;
int16 spriteIdx ;
int16 field_10;
int16 backgroundPlane;
int16 hide;
int16 field_16;
int16 field_18;
int16 field_1A;
int16 followObjectOverlayIdx;
int16 followObjectIdx;
int16 field_20;
int16 field_22;
int16 nextAnimDelay;
int16 field_26;
int16 field_28;
int16 field_2A;
int16 field_2C;
int16 currentAnimDelay;
int16 field_30;
gfxEntryStruct* gfxPtr;
};
typedef struct objectStruct objectStruct;
struct objectParamsQuery
{
int16 X;
int16 Y;
int16 baseFileIdx;
int16 fileIdx;
int16 scale;
int16 var5;
int16 var6;
int16 var7;
};
typedef struct objectParamsQuery objectParamsQuery;
objectStruct* addObject(int16 overlayIdx,int16 param2,objectStruct* pHead,int16 scriptType,int16 scriptNumber,int16 scriptOverlay, int16 param3, int16 param4);
objDataStruct* getObjectDataFromOverlay(int ovlIdx,int objIdx);
int16 getSingleObjectParam(int16 overlayIdx,int16 param2,int16 param3,int16* returnParam);
int16 getMultipleObjectParam(int16 overlayIdx,int16 objectIdx,objectParamsQuery* returnParam);
} // End of namespace Cruise
#endif

772
engines/cruise/overlay.cpp Normal file
View file

@ -0,0 +1,772 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
overlayStruct overlayTable[90];
int numOfLoadedOverlay;
void initOverlayTable(void)
{
int i;
for(i=0;i<90;i++)
{
overlayTable[i].overlayName[0] = 0;
overlayTable[i].ovlData = NULL;
overlayTable[i].alreadyLoaded = 0;
overlayTable[i].executeScripts = 0;
}
numOfLoadedOverlay = 1;
}
int loadOverlay(uint8* scriptName)
{
int newNumberOfScript;
bool scriptNotLoadedBefore;
int scriptIdx;
uint8 fileName[50];
int fileIdx;
int unpackedSize;
char* unpackedBuffer;
char* scriptPtr;
ovlDataStruct* ovlData;
printf("Load overlay: %s\n",scriptName);
newNumberOfScript = numOfLoadedOverlay;
scriptNotLoadedBefore = false;
scriptIdx = findOverlayByName((char*)scriptName);
if(scriptIdx == -4)
{
scriptIdx = numOfLoadedOverlay;
newNumberOfScript++;
scriptNotLoadedBefore = true;
}
if(overlayTable[scriptIdx].alreadyLoaded)
{
return (scriptIdx);
}
overlayTable[scriptIdx].ovlData = (ovlDataStruct*) mallocAndZero(sizeof(ovlDataStruct));
if(!overlayTable[scriptIdx].ovlData)
return(-2);
strcpyuint8(overlayTable[scriptIdx].overlayName, scriptName);
overlayTable[scriptIdx].alreadyLoaded = 1;
numOfLoadedOverlay = newNumberOfScript;
overlayTable[scriptIdx].ovlData->scriptNumber = scriptIdx;
strcpyuint8(fileName,scriptName);
strcatuint8(fileName,".OVL");
printf("Attempting to load overlay file %s...\n", fileName);
fileIdx = findFileInDisks(fileName);
if(fileIdx<0)
{
printf("Unable to load overlay %s !\n", scriptName);
//releaseScript(scriptName);
return(-18);
}
unpackedSize = volumePtrToFileDescriptor[fileIdx].extSize + 2;
// TODO: here, can unpack in gfx module buffer
unpackedBuffer = (char*)mallocAndZero(unpackedSize);
if(!unpackedBuffer)
{
return(-2);
}
if(volumePtrToFileDescriptor[fileIdx].size +2 != unpackedSize)
{
char* tempBuffer;
uint16 realUnpackedSize;
char* pakedBuffer = (char*) mallocAndZero(volumePtrToFileDescriptor[fileIdx].size +2);
loadPakedFileToMem(fileIdx,(uint8*)pakedBuffer);
realUnpackedSize = *(int16*)(pakedBuffer+volumePtrToFileDescriptor[fileIdx].size-2);
flipShort(&realUnpackedSize);
tempBuffer = (char*)mallocAndZero(realUnpackedSize);
decomp((uint8*)pakedBuffer+volumePtrToFileDescriptor[fileIdx].size-4,(uint8*)unpackedBuffer+realUnpackedSize,realUnpackedSize);
free(pakedBuffer);
}
else
{
loadPakedFileToMem(fileIdx,(uint8*)unpackedBuffer);
}
printf("OVL loading done...\n");
scriptPtr = unpackedBuffer;
ovlData = overlayTable[scriptIdx].ovlData;
memcpy(ovlData,scriptPtr, sizeof(ovlDataStruct));
ovlData->data3Table = NULL;
ovlData->ptr1 = NULL;
ovlData->objDataTable = NULL;
ovlData->objData2SourceTable = NULL;
ovlData->objData2WorkTable = NULL;
ovlData->stringTable = NULL;
ovlData->exportDataPtr = NULL;
ovlData->importDataPtr = NULL;
ovlData->linkDataPtr = NULL;
ovlData->specialString1 = NULL;
ovlData->specialString2 = NULL;
ovlData->importNamePtr = NULL;
ovlData->exportNamesPtr = NULL;
ovlData->data4Ptr = NULL;
ovlData->ptr8 = NULL;
ovlData->numScripts1 = readB16(scriptPtr+60);
ovlData->numScripts2 = readB16(scriptPtr+62);
ovlData->numExport = readB16(scriptPtr+64);
ovlData->numImport = readB16(scriptPtr+66);
ovlData->numLinkData = readB16(scriptPtr+68);
ovlData->numObjData = readB16(scriptPtr+70);
ovlData->numStrings = readB16(scriptPtr+72);
ovlData->size8 = readB16(scriptPtr+74);
ovlData->size9 = readB16(scriptPtr+76);
ovlData->nameExportSize = readB16(scriptPtr+78);
ovlData->exportNamesSize = readB16(scriptPtr+80);
ovlData->specialString2Length = readB16(scriptPtr+82);
ovlData->sizeOfData4 = readB16(scriptPtr+84);
ovlData->size12 = readB16(scriptPtr+86);
ovlData->specialString1Length = readB16(scriptPtr+88);
ovlData->scriptNumber = readB16(scriptPtr+90);
scriptPtr += 92;
if(ovlData->numExport) // export data
{
int i;
ovlData->exportDataPtr = (exportEntryStruct*)mallocAndZero(ovlData->numExport*sizeof(exportEntryStruct));
if(!ovlData->exportDataPtr)
{
return(-2);
}
for(i=0;i<ovlData->numExport;i++)
{
ovlData->exportDataPtr[i].var0 = readB16(scriptPtr);
ovlData->exportDataPtr[i].var2 = readB16(scriptPtr+2);
ovlData->exportDataPtr[i].var4 = readB16(scriptPtr+4);
ovlData->exportDataPtr[i].idx = readB16(scriptPtr+6);
ovlData->exportDataPtr[i].offsetToName = readB16(scriptPtr+8);
scriptPtr+=10;
}
}
if(ovlData->exportNamesSize) // export names
{
ovlData->exportNamesPtr = (uint8*)mallocAndZero(ovlData->exportNamesSize);
if(!ovlData->exportNamesPtr)
{
return(-2);
}
memcpy(ovlData->exportNamesPtr, scriptPtr, ovlData->exportNamesSize);
scriptPtr += ovlData->exportNamesSize;
}
if(ovlData->numImport) // import data
{
int i;
ovlData->importDataPtr = (importDataStruct*)mallocAndZero(ovlData->numImport * sizeof(importDataStruct));
if(!ovlData->importDataPtr)
{
return(-2);
}
for(i=0;i<ovlData->numImport;i++)
{
ovlData->importDataPtr[i].var0 = readB16(scriptPtr);
ovlData->importDataPtr[i].var1 = readB16(scriptPtr+2);
ovlData->importDataPtr[i].linkType = readB16(scriptPtr+4);
ovlData->importDataPtr[i].linkIdx = readB16(scriptPtr+6);
ovlData->importDataPtr[i].nameOffset = readB16(scriptPtr+8);
scriptPtr+=10;
}
}
if(ovlData->nameExportSize) // import name
{
ovlData->importNamePtr = (uint8*)mallocAndZero(ovlData->nameExportSize);
if(!ovlData->importNamePtr)
{
return(-2);
}
memcpy(ovlData->importNamePtr, scriptPtr, ovlData->nameExportSize);
scriptPtr += ovlData->nameExportSize;
}
if(ovlData->numLinkData) // link data
{
ASSERT(sizeof(linkDataStruct) == 0x22);
ovlData->linkDataPtr = (linkDataStruct*)mallocAndZero(ovlData->numLinkData*sizeof(linkDataStruct));
if(!ovlData->linkDataPtr)
{
return(-2);
}
memcpy(ovlData->linkDataPtr, scriptPtr, ovlData->numLinkData*sizeof(linkDataStruct));
scriptPtr += ovlData->numLinkData*sizeof(linkDataStruct);
flipGen(ovlData->linkDataPtr,ovlData->numLinkData*sizeof(linkDataStruct));
}
if(ovlData->numScripts1) // script
{
ovlData3Struct* tempPtr;
int i;
ovlData->data3Table = (ovlData3Struct*)mallocAndZero(ovlData->numScripts1 * sizeof(ovlData3Struct));
if(!ovlData->data3Table)
{
/* releaseScript(scriptIdx,scriptName);
if(freeIsNeeded)
{
freePtr(unpackedBuffer);
} */
return(-2);
}
memcpy(ovlData->data3Table, scriptPtr, ovlData->numScripts1 * sizeof(ovlData3Struct));
scriptPtr += ovlData->numScripts1 * 0x1C;
flipGen(ovlData->data3Table,ovlData->numScripts1 * sizeof(ovlData3Struct));
tempPtr = ovlData->data3Table;
for(i=0;i<ovlData->numScripts1;i++)
{
uint8* ptr = tempPtr->dataPtr = (uint8*) mallocAndZero(tempPtr->sizeOfData);
if(!ptr)
{
/* releaseScript(scriptIdx,scriptName);
if(freeIsNeeded)
{
freePtr(unpackedBuffer);
} */
return(-2);
}
memcpy( ptr, scriptPtr, tempPtr->sizeOfData );
scriptPtr+= tempPtr->sizeOfData;
if(tempPtr->offsetToImportData)
{
flipGen(ptr+tempPtr->offsetToImportData,tempPtr->numImport*10);
}
if(tempPtr->offsetToSubData2)
{
flipGen(ptr+tempPtr->offsetToImportData,tempPtr->subData2Size*10);
}
tempPtr++;
}
}
if(ovlData->numScripts2)
{
ovlData3Struct* tempPtr;
int i;
ovlData->ptr1 = (uint8*)mallocAndZero(ovlData->numScripts2*0x1C);
if(!ovlData->ptr1)
{
return(-2);
}
memcpy(ovlData->ptr1, scriptPtr, ovlData->numScripts2 * 0x1C);
scriptPtr += ovlData->numScripts2*0x1C;
flipGen(ovlData->ptr1,ovlData->numScripts2*0x1C);
tempPtr = (ovlData3Struct*)ovlData->ptr1;
for(i=0;i<ovlData->numScripts2;i++)
{
uint8* ptr = tempPtr->dataPtr = (uint8*) mallocAndZero(tempPtr->sizeOfData);
if(!ptr)
{
/* releaseScript(scriptIdx,scriptName);
if(freeIsNeeded)
{
freePtr(unpackedBuffer);
} */
return(-2);
}
memcpy( ptr, scriptPtr, tempPtr->sizeOfData );
scriptPtr+= tempPtr->sizeOfData;
if(tempPtr->offsetToImportData)
{
flipGen(ptr+tempPtr->offsetToImportData,tempPtr->numImport*10);
}
if(tempPtr->offsetToSubData2)
{
flipGen(ptr+tempPtr->offsetToImportData,tempPtr->subData2Size*10);
}
tempPtr++;
}
}
if(ovlData->size12)
{
ovlData->ptr8 = (uint8*)mallocAndZero(ovlData->size12);
if(!ovlData->ptr8)
{
/* releaseScript(scriptIdx,scriptName);
if(freeIsNeeded)
{
freePtr(unpackedBuffer);
} */
return(-2);
}
memcpy(ovlData->ptr8, scriptPtr, ovlData->size12);
scriptPtr += ovlData->size12;
}
if(ovlData->numObjData)
{
int i;
ovlData->objDataTable = (objDataStruct*)mallocAndZero(ovlData->numObjData*sizeof(objDataStruct));
if(!ovlData->objDataTable)
{
/* releaseScript(scriptIdx,scriptName);
if(freeIsNeeded)
{
freePtr(unpackedBuffer);
} */
return(-2);
}
for(i=0;i<ovlData->numObjData;i++)
{
ovlData->objDataTable[i].var0 = *(int16*)scriptPtr;
scriptPtr+=2;
flipShort(&ovlData->objDataTable[i].var0);
ovlData->objDataTable[i].var1 = *(int16*)scriptPtr;
scriptPtr+=2;
flipShort(&ovlData->objDataTable[i].var1);
ovlData->objDataTable[i].var2 = *(int16*)scriptPtr;
scriptPtr+=2;
flipShort(&ovlData->objDataTable[i].var2);
ovlData->objDataTable[i].var3 = *(int16*)scriptPtr;
scriptPtr+=2;
flipShort(&ovlData->objDataTable[i].var3);
ovlData->objDataTable[i].var4 = *(int16*)scriptPtr;
scriptPtr+=2;
flipShort(&ovlData->objDataTable[i].var4);
ovlData->objDataTable[i].var5 = *(int16*)scriptPtr;
scriptPtr+=2;
flipShort(&ovlData->objDataTable[i].var5);
ovlData->objDataTable[i].var6 = *(int16*)scriptPtr;
scriptPtr+=2;
flipShort(&ovlData->objDataTable[i].var6);
}
if(scriptNotLoadedBefore)
{
int var1;
int var2;
overlayTable[scriptIdx].field_14 = (char)setup1;
var1 = loadScriptSub1(scriptIdx,3);
var2 = loadScriptSub1(scriptIdx,0);
setup1 = var1 + var2;
}
}
if(ovlData->size9)
{
ovlData->objData2WorkTable = (objectParams*)mallocAndZero(ovlData->size9 * sizeof(objectParams));
memset(ovlData->objData2WorkTable, 0, ovlData->size9 * sizeof(objectParams));
if(!ovlData->objData2WorkTable)
{
/* releaseScript(scriptIdx,scriptName);
if(freeIsNeeded)
{
freePtr(unpackedBuffer);
} */
return(-2);
}
}
if(ovlData->size8)
{
ovlData->objData2SourceTable = (objectParams*)mallocAndZero(ovlData->size8 * sizeof(objectParams));
if(!ovlData->objData2SourceTable)
{
/* releaseScript(scriptIdx,scriptName);
if(freeIsNeeded)
{
freePtr(unpackedBuffer);
} */
return(-2);
}
memcpy(ovlData->objData2SourceTable, scriptPtr, ovlData->size8*12); // TODO: made read item by item
scriptPtr += ovlData->size8*12;
flipGen(ovlData->objData2SourceTable,ovlData->size8*12);
}
if(ovlData->numStrings)
{
int i;
ovlData->stringTable = (stringEntryStruct*)mallocAndZero(ovlData->numStrings*sizeof(stringEntryStruct));
for(i=0;i<ovlData->numStrings;i++)
{
ovlData->stringTable[i].idx = *(int16*)scriptPtr;
flipShort(&ovlData->stringTable[i].idx);
scriptPtr+=2;
}
}
/* if(freeIsNeeded)
{
freePtr(unpackedBuffer);
} */
if(ovlData->sizeOfData4)
{
ovlData->data4Ptr = (uint8*)mallocAndZero(ovlData->sizeOfData4);
memset(ovlData->data4Ptr,0,ovlData->sizeOfData4);
if(!ovlData->data4Ptr)
{
//releaseScript(scriptIdx,scriptName);
return(-2);
}
}
if(ovlData->specialString1Length /*|| ovlData->specialString2Length*/ || ovlData->stringTable)
{
int i;
int unpackedSize;
int fileIdx;
uint8 fileName[50];
char* unpackedBuffer;
strcpyuint8(fileName,scriptName);
strcatuint8(fileName,".FR");
fileIdx = findFileInDisks(fileName);
if(fileIdx<0)
{
//releaseScript(scriptName);
return(-18);
}
unpackedSize = volumePtrToFileDescriptor[fileIdx].extSize + 2;
// TODO: here, can unpack in gfx module buffer
unpackedBuffer = (char*)mallocAndZero(unpackedSize);
if(!unpackedBuffer)
{
return(-2);
}
if(volumePtrToFileDescriptor[fileIdx].size +2 != unpackedSize)
{
short int realUnpackedSize;
char* pakedBuffer = (char*) mallocAndZero(volumePtrToFileDescriptor[fileIdx].size +2);
loadPakedFileToMem(fileIdx,(uint8*)pakedBuffer);
realUnpackedSize = *(int16*)(pakedBuffer+volumePtrToFileDescriptor[fileIdx].size-2);
flipShort(&realUnpackedSize);
decomp((uint8*)pakedBuffer+volumePtrToFileDescriptor[fileIdx].size-4,(uint8*)unpackedBuffer+realUnpackedSize,realUnpackedSize);
free(pakedBuffer);
}
else
{
loadPakedFileToMem(fileIdx,(uint8*)unpackedBuffer);
}
scriptPtr = unpackedBuffer;
memcpy(&ovlData->specialString1Length,scriptPtr,2);
scriptPtr+=2;
flipShort(&ovlData->specialString1Length); // recheck if needed
if(ovlData->specialString1Length)
{
ovlData->specialString1 = (uint8*)mallocAndZero(ovlData->specialString1Length);
if(!ovlData->specialString1)
{
/* releaseScript(scriptIdx,scriptName);
if(freeIsNeeded)
{
freePtr(unpackedBuffer);
} */
return(-2);
}
memcpy(ovlData->specialString1, scriptPtr, ovlData->specialString1Length);
scriptPtr += ovlData->specialString1Length;
}
memcpy(&ovlData->specialString2Length,scriptPtr,2);
scriptPtr+=2;
flipShort(&ovlData->specialString2Length); // recheck if needed
if(ovlData->specialString2Length)
{
ovlData->specialString2 = (uint8*)mallocAndZero(ovlData->specialString2Length);
if(!ovlData->specialString2)
{
/* releaseScript(scriptIdx,scriptName);
if(freeIsNeeded)
{
freePtr(unpackedBuffer);
} */
return(-2);
}
memcpy(ovlData->specialString2, scriptPtr, ovlData->specialString2Length);
scriptPtr += ovlData->specialString2Length;
}
for(i=0;i<ovlData->numStrings;i++)
{
ovlData->stringTable[i].length = *(int16*)scriptPtr;
scriptPtr +=2;
flipShort(&ovlData->stringTable[i].length);
if(ovlData->stringTable[i].length)
{
ovlData->stringTable[i].string = (char*)mallocAndZero(ovlData->stringTable[i].length);
if(!ovlData->stringTable[i].string)
{
/* releaseScript(scriptIdx,scriptName);
if(freeIsNeeded)
{
freePtr(unpackedBuffer);
} */
return(-2);
}
memcpy(ovlData->stringTable[i].string,scriptPtr,ovlData->stringTable[i].length);
scriptPtr += ovlData->stringTable[i].length;
}
}
}
#ifdef DUMP_SCRIPT
{
int i;
for(i=0;i<ovlData->numScripts1;i++)
{
dumpScript(scriptName,ovlData,i);
}
}
#endif
#ifdef DUMP_OBJECT
{
int i;
FILE* fHandle;
char nameBundle[100];
sprintf(nameBundle, "%s-objs.txt",scriptName);
fHandle = fopen(nameBundle, "w+");
ASSERT(fHandle);
for(i=0;i<ovlData->numLinkData;i++)
{
linkDataStruct* var_34;
var_34 = &ovlData->linkDataPtr[i];
if(ovlData->specialString2)
{
fprintf(fHandle,"----- object %02d -----\n", i);
if(var_34->stringNameOffset != 0xFFFF)
{
fprintf(fHandle,"name: %s\n",getObjectName(var_34->stringNameOffset, ovlData->specialString2));
}
}
}
fclose(fHandle);
}
#endif
return(scriptIdx);
}
int releaseOverlay(const char* name)
{
int overlayIdx;
ovlDataStruct* ovlDataPtr;
overlayIdx = findOverlayByName(name);
if(overlayIdx == -4)
return -4;
if(overlayTable[overlayIdx].alreadyLoaded == 0)
return -4;
overlayTable[overlayIdx].alreadyLoaded = 0;
ovlDataPtr = overlayTable[overlayIdx].ovlData;
if(!ovlDataPtr)
return -4;
/*
if(overlayTable[overlayIdx].var1E)
{
free(overlayTable[overlayIdx].var1E);
overlayTable[overlayIdx].var1E = NULL;
}
if(overlayTable[overlayIdx].var16)
{
free(overlayTable[overlayIdx].var16);
overlayTable[overlayIdx].var16 = NULL;
} */
removeScript(overlayIdx,-1,&scriptHandle2);
removeScript(overlayIdx,-1,&scriptHandle2);
removeScript(overlayIdx,-1,&scriptHandle1);
removeScript(overlayIdx,-1,&scriptHandle1);
printf("releaseOverlay: finish !\n");
return 0;
}
int32 findOverlayByName2(uint8* name)
{
int i;
for(i=1;i<numOfLoadedOverlay;i++)
{
if(!strcmpuint8(overlayTable[i].overlayName,name))
return(i);
}
return(-4);
}
int findOverlayByName(const char* overlayName)
{
int i;
for(i=1;i<numOfLoadedOverlay;i++)
{
if(!strcmp(overlayTable[i].overlayName,overlayName))
{
return(i);
}
}
return(-4);
}
} // End of namespace Cruise

217
engines/cruise/overlay.h Normal file
View file

@ -0,0 +1,217 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _OVERLAY_H_
#define _OVERLAY_H_
namespace Cruise {
struct importScriptStruct
{
uint16 var0;
uint16 var1;
uint16 type;
uint16 offset;
uint16 offsetToName;
};
typedef struct importScriptStruct importScriptStruct;
struct exportEntryStruct
{
uint16 var0;
uint16 var2;
uint16 var4;
uint16 idx;
uint16 offsetToName;
};
typedef struct exportEntryStruct exportEntryStruct;
struct ovlData3Struct
{
uint8* dataPtr; //0
short int sizeOfData; //4
short int offsetToSubData3; //6
short int offsetToImportData; //8
short int offsetToSubData2;
short int offsetToImportName;
short int offsetToSubData5;
short int sysKey;
short int var12;
short int numImport;
short int subData2Size;
short int var18;
short int var1A;
};
typedef struct ovlData3Struct ovlData3Struct;
struct stringEntryStruct
{
char* string;
short int length;
short int idx;
};
typedef struct stringEntryStruct stringEntryStruct;
struct linkDataStruct
{
uint16 field_0;
uint16 field_2;
uint16 field_4;
uint16 varIdx;
uint16 varNameOffset;
uint16 stringIdx;
uint16 stringNameOffset;
uint16 procIdx;
uint16 procNameOffset;
int16 field_12;
int16 field_14;
int16 field_16;
int16 field_18;
int16 field_1A;
int16 field_1C;
int16 field_1E;
int16 field_20;
};
typedef struct linkDataStruct linkDataStruct;
struct importDataStruct
{
uint16 var0; // 0
uint16 var1; // 2
uint16 linkType; // 4
uint16 linkIdx; // 6
uint16 nameOffset;
};
typedef struct importDataStruct importDataStruct;
struct objDataStruct
{
int16 var0;
int16 var1;
int16 var2;
int16 var3;
int16 var4;
int16 var5;
int16 var6;
};
typedef struct objDataStruct objDataStruct;
struct objectParams
{
int16 X;
int16 Y;
int16 baseFileIdx;
int16 var3;
int16 scale;
int16 var5;
};
typedef struct objectParams objectParams;
struct ovlDataStruct
{
ovlData3Struct* data3Table;
uint8* ptr1;
objDataStruct* objDataTable;
objectParams* objData2SourceTable;
objectParams* objData2WorkTable;
stringEntryStruct* stringTable;
exportEntryStruct* exportDataPtr;
importDataStruct* importDataPtr;
linkDataStruct* linkDataPtr;
uint8* specialString1;
uint8* specialString2;
uint8* importNamePtr;
uint8* exportNamesPtr;
uint8* data4Ptr;
uint8* ptr8;
unsigned short int numScripts1;
unsigned short int numScripts2;
unsigned short int numExport;
unsigned short int numImport;
unsigned short int numLinkData;
unsigned short int numObjData;
unsigned short int numStrings;
unsigned short int size8;
unsigned short int size9;
unsigned short int nameExportSize;
unsigned short int exportNamesSize;
unsigned short int specialString2Length;
unsigned short int sizeOfData4;
unsigned short int size12;
unsigned short int specialString1Length;
unsigned short int scriptNumber;
};
typedef struct ovlDataStruct ovlDataStruct;
struct overlayStruct
{
char overlayName[14];
ovlDataStruct* ovlData;
short int alreadyLoaded;
char field_14;
char field_15;
char field_16;
char field_17;
char field_18;
char field_19;
char field_1A;
char field_1B;
char field_1C;
char field_1D;
char field_1E;
char field_1F;
char field_20;
char field_21;
char field_22;
char field_23;
char field_24;
char field_25;
short int executeScripts;
};
typedef struct overlayStruct overlayStruct;
extern overlayStruct overlayTable[90];
extern int numOfLoadedOverlay;
void initOverlayTable(void);
int loadOverlay(uint8* scriptName);
int32 findOverlayByName2(uint8* name);
int findOverlayByName(const char* overlayName);
int releaseOverlay(const char* name);
} // End of namespace Cruise
#endif

260
engines/cruise/perso.cpp Normal file
View file

@ -0,0 +1,260 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
persoStruct* persoTable[10];
int16 computedVar14;
void freePerso(int persoIdx)
{
if(persoTable[persoIdx])
{
free(persoTable[persoIdx]);
persoTable[persoIdx] = NULL;
}
}
void freeAllPerso(void)
{
int i;
for(i=0;i<10;i++)
{
freePerso(i);
}
if(polyStruct)
{
free(polyStruct);
}
ctpVar17 = NULL;
polyStruct = NULL;
strcpy((char*)currentCtpName, "");
}
int pathVar0;
unsigned int inc_droite2,inc_jo;
int direction( int x1, int y1, int x2, int y2, int inc_jo1, int inc_jo2 )
{
int h, v, h1, v1;
h1 = x1-x2; h = abs(h1);
v1 = y1-y2; v = abs(v1);
if ( v > h )
{
if ( h > 30 ) inc_jo = inc_jo1-inc_jo2;
else inc_jo = inc_jo2;
if ( v1 < 0 ) return ( 2 );
else return ( 0 );
}
else
{
inc_jo = inc_jo1;
if ( h1 < 0 ) return ( 1 );
else return ( 3 );
}
}
void cor_droite(int x1,int y1,int x2,int y2, int16 cor_joueur[400][2])
{
int16* di = (int16*)cor_joueur;
int dx;
int dy;
int mD0;
int mD1;
int mA0;
int mA1;
int bp;
int cx;
int si;
int ax;
int bx;
di[0] = x1;
di[1] = y1;
di+=2;
dx = x2-x1;
dy = y2-y1;
mD0 = mD1 = 1;
if(dx<0)
{
dx = -dx;
mD0 = -1;
}
if(dy<0)
{
dy = -dy;
mD1 = -1;
}
if(dx<dy)
{
mA0 = 0;
bp = dx;
cx = dy;
mA1 = mD1;
}
else
{
mA1 = 0;
bp = dy;
cx = dx;
mA0 = mD0;
}
bp=bp*2;
dx=bp-cx;
si=dx-cx;
ax = x1;
bx = y1;
while(--cx)
{
if(dx>0)
{
ax+=mD0;
bx+=mD1;
dx+=si;
}
else
{
ax+=mA0;
bx+=mA1;
dx+=bp;
}
di[0] = ax;
di[1] = bx;
di+=2;
}
flag_obstacle = 0;
inc_droite2 = (di-(int16*)cor_joueur)/2;
}
void processActorWalk(int16 resx_y[4], int16* inc_droite, int16* inc_droite0, int16* inc_chemin, int16 cor_joueur[400][2], int16 solution0[NUM_NODES+3][2], int16* inc_jo1, int16* inc_jo2, int16* dir_perso, int16* inc_jo0, int16 num)
{
int x1, x2, y1, y2;
int i, u;
u = 0;
inc_jo = *inc_jo0;
i = *inc_chemin;
if ( ! *inc_droite )
{
x1 = solution0[i][0];
y1 = solution0[i][1];
i++;
if ( solution0[i][0] != -1 )
{
do
{
if (solution0[i][0]!=-2)
{
x2 = solution0[i][0];
y2 = solution0[i][1];
if ( (x1==x2) && (y1==y2))
{
resx_y[0]=-1;
resx_y[1]=-1;
freePerso(num);
return;
}
cor_droite(x1,y1,x2,y2,cor_joueur);
*inc_droite0=inc_droite2;
*dir_perso=resx_y[2]=direction(x1,y1,x2,y2,*inc_jo1,*inc_jo2);
*inc_jo0=inc_jo;
u=1;
}
else i++;
} while ( solution0[i][0] !=-1 && !u );
}
if ( !u )
{
resx_y[0]=-1;
resx_y[1]=-1;
freePerso(num);
return;
}
*inc_chemin=i;
}
resx_y[0]=cor_joueur[*inc_droite][0];
resx_y[1]=cor_joueur[*inc_droite][1];
resx_y[2]=*dir_perso;
resx_y[3]=subOp22(resx_y[1]);
getPixel(resx_y[0],resx_y[1]);
resx_y[4]=computedVar14;
u=subOp23(resx_y[3],inc_jo);
if (!u) u=1;
*inc_droite+=u;
if ((*inc_droite)>=(*inc_droite0))
{
*inc_droite=0;
resx_y[0]=solution0[*inc_chemin][0];
resx_y[1]=solution0[*inc_chemin][1];
}
}
void affiche_chemin(int16 persoIdx, int16* returnVar)
{
persoStruct* pPerso = persoTable[persoIdx];
ASSERT(pPerso);
processActorWalk(returnVar, &pPerso->inc_droite, &pPerso->inc_droite0, &pPerso->inc_chemin, pPerso->coordinates, pPerso->solution, &pPerso->inc_jo1, &pPerso->inc_jo2, &pPerso->dir_perso, &pPerso->inc_jo0, persoIdx);
}
} // End of namespace Cruise

56
engines/cruise/perso.h Normal file
View file

@ -0,0 +1,56 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _PERSO_H_
#define _PERSO_H_
namespace Cruise {
#define NUM_NODES 20
struct persoStruct
{
int16 inc_droite; // 2
int16 inc_droite0; // 2
int16 inc_chemin; // 2
int16 coordinates[400][2]; // 1600
int16 solution[NUM_NODES+3][2]; //((20+3)*2*2)
int16 inc_jo1; // 2
int16 inc_jo2; // 2
int16 dir_perso; // 2
int16 inc_jo0; // 2
};
typedef struct persoStruct persoStruct;
extern persoStruct* persoTable[10];
extern int16 computedVar14;
void freePerso(int persoIdx);
void freeAllPerso(void);
void affiche_chemin(int16 persoIdx, int16* returnVar);
} // End of namespace Cruise
#endif

323
engines/cruise/polys.cpp Normal file
View file

@ -0,0 +1,323 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
#include <stdlib.h>
#include <math.h>
typedef char ColorP;
#define SCREENHEIGHT 200
#define MAXPTS 10
#define putdot(x,y) {if ((y >= 0) && (y < SCREENHEIGHT)) dots[y][counters[y]++] = x;}
#define SWAP(x,y) {int temp = x; x = y; y = temp;}
int MAX(int x, int y) {if(x>y){return x;}else{return y;}}
int MIN(int x, int y) {if(x<y){return x;}else{return y;}}
void hline(int x1, int x2, int y, char c) {
for (; x1 <= x2; x1++) {
pixel(x1, y, c);
}
}
void vline(int x, int y1, int y2, char c) {
for (; y1 <= y2; y1++) {
pixel(x, y1, c);
}
}
void bsubline_1(int x1, int y1, int x2, int y2, char c) {
int x, y, ddx, ddy, e;
ddx = abs(x2 - x1);
ddy = abs(y2 - y1) << 1;
e = ddx - ddy;
ddx <<= 1;
if (x1 > x2) {
SWAP(x1, x2);
SWAP(y1, y2);
}
for (x = x1, y = y1; x <= x2; x++) {
pixel(x, y, c);
if (e < 0) {
y++;
e += ddx - ddy;
} else {
e -= ddy;
}
}
}
void bsubline_2(int x1, int y1, int x2, int y2, char c) {
int x, y, ddx, ddy, e;
ddx = abs(x2 - x1) << 1;
ddy = abs(y2 - y1);
e = ddy - ddx;
ddy <<= 1;
if (y1 > y2) {
SWAP(x1, x2);
SWAP(y1, y2);
}
for (y = y1, x = x1; y <= y2; y++) {
pixel(x, y, c);
if (e < 0) {
x++;
e += ddy - ddx;
} else {
e -= ddx;
}
}
}
void bsubline_3(int x1, int y1, int x2, int y2, char c) {
int x, y, ddx, ddy, e;
ddx = abs(x1 - x2) << 1;
ddy = abs(y2 - y1);
e = ddy - ddx;
ddy <<= 1;
if (y1 > y2) {
SWAP(x1, x2);
SWAP(y1, y2);
}
for (y = y1, x = x1; y <= y2; y++) {
pixel(x, y, c);
if (e < 0) {
x--;
e += ddy - ddx;
} else {
e -= ddx;
}
}
}
void bsubline_4(int x1, int y1, int x2, int y2, char c) {
int x, y, ddx, ddy, e;
ddy = abs(y2 - y1) << 1;
ddx = abs(x1 - x2);
e = ddx - ddy;
ddx <<= 1;
if (x1 > x2) {
SWAP(x1, x2);
SWAP(y1, y2);
}
for (x = x1, y = y1; x <= x2; x++) {
pixel(x, y, c);
if (e < 0) {
y--;
e += ddx - ddy;
} else {
e -= ddy;
}
}
}
void line(int x1, int y1, int x2, int y2, char c) {
float k;
if ((x1 == x2) && (y1 == y2)) {
pixel(x1, y1, c);
return;
}
if (x1 == x2) {
vline(x1, MIN(y1, y2), MAX(y1, y2), c);
return;
}
if (y1 == y2) {
hline(MIN(x1, x2), MAX(x1, x2), y1, c);
return;
}
k = (float)(y2 - y1) / (float)(x2 - x1);
if ((k >= 0) && (k <= 1)) {
bsubline_1(x1, y1, x2, y2, c);
} else if (k > 1) {
bsubline_2(x1, y1, x2, y2, c);
} else if ((k < 0) && (k >= -1)) {
bsubline_4(x1, y1, x2, y2, c);
} else {
bsubline_3(x1, y1, x2, y2, c);
}
}
void fillpoly(short int* datas, int lineCount, ColorP color)
{
static int dots[SCREENHEIGHT][MAXPTS];
static int counters[SCREENHEIGHT];
short int x1, y1, x2, y2;
int i, j, k, dir = -2;
double step, curx;
switch (lineCount)
{
case 0: // do nothing
return;
case 1: // draw pixel
pixel(datas[0], datas[1], color);
return;
case 2: // draw line
line(datas[0], datas[1], datas[2], datas[3], color);
return;
default: // go on and draw polygon
break;
}
// Reinit array counters
for (i = 0; i < SCREENHEIGHT; i++)
{
counters[i] = 0;
}
// Drawing lines
x2 = datas[lineCount * 2 - 2];
y2 = datas[lineCount * 2 - 1];
for (i = 0; i < lineCount; i++) {
x1 = x2;
y1 = y2;
x2 = datas[i * 2];
y2 = datas[i * 2 + 1];
// line(x1, y1, x2, y2, color);
// continue;
if (y1 == y2)
{
// printf("Horizontal line. x1: %i, y1: %i, x2: %i, y2: %i\n", x1, y1, x2, y2);
if (dir)
{
putdot(x1, y1);
dir = 0;
}
}
else
{
step = (double) (x2 - x1) / (y2 - y1);
// printf("x1: %i, y1 = %i, x2 = %i, y2 = %i, step: %f\n", x1, y1, x2, y2, step);
curx = x1;
if (y1 < y2) {
for (j = y1; j < y2; j++, curx += step) {
// printf("j = %i, curx = %f\n", j, curx);
putdot((int)(curx + 0.5), j);
}
if (dir == -1) {
// printf("Adding extra (%i, %i)\n", x1, y1);
putdot(x1, y1);
}
dir = 1;
} else {
for (j = y1; j > y2; j--, curx -= step) {
// printf("j = %i, curx = %f\n", j, curx);
putdot((int)(curx + 0.5), j);
}
if (dir == 1) {
// printf("Adding extra (%i, %i)\n", x1, y1);
putdot(x1, y1);
}
dir = -1;
}
}
}
x1 = x2;
y1 = y2;
x2 = datas[0];
y2 = datas[1];
if (((y1 < y2) && (dir == -1)) || ((y1 > y2) && (dir == 1)) || ((y1 == y2) && (dir == 0))) {
// printf("Adding final extra (%i, %i)\n", x1, y1);
putdot(x1, y1);
}
// NOTE: all counters should be even now. If not, this is a bad (color) thing :-P
// Sorting datas
for (i = 0; i < SCREENHEIGHT; i++) {
// Very bad sorting... but arrays are very small (0, 2 or 4), so it's no quite use...
for (j = 0; j < (counters[i] - 1); j++) {
for (k = 0; k < (counters[i] - 1); k++) {
if (dots[i][k] > dots[i][k + 1])
{
int temp;
temp = dots[i][k];
dots[i][k] = dots[i][k + 1];
dots[i][k + 1] = temp;
}
}
}
}
// Drawing.
for (i = 0; i < SCREENHEIGHT; i++) {
if (counters[i]) {
// printf("%i dots on line %i\n", counters[i], i);
for (j = 0; j < counters[i] - 1; j += 2) {
// printf("Drawing line (%i, %i)-%i\n", dots[i][j], dots[i][j + 1], i);
hline(dots[i][j], dots[i][j + 1], i, color);
#ifdef DEBUGGING_POLYS
if ((!dots[i][j]) || !(dots[i][j + 1])) {
printf("fillpoly: BLARGH!\n");
exit(-1);
}
#endif
}
}
}
}
} // End of namespace Cruise

32
engines/cruise/polys.h Normal file
View file

@ -0,0 +1,32 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
namespace Cruise {
typedef char ColorP;
void fillpoly(short int * datas, int n, ColorP c);
void line(int x1, int y1, int x2, int y2, ColorP color);
} // End of namespace Cruise

861
engines/cruise/script.cpp Normal file
View file

@ -0,0 +1,861 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
scriptInstanceStruct scriptHandle1;
scriptInstanceStruct scriptHandle2;
scriptInstanceStruct* currentScriptPtr;
uint8 getByteFromScript(void)
{
uint8 var = currentData3DataPtr[currentScriptPtr->var4];
currentScriptPtr->var4 = currentScriptPtr->var4+1;
return(var);
}
short int getShortFromScript(void)
{
short int var = *(int16*)(currentData3DataPtr+currentScriptPtr->var4);
currentScriptPtr->var4 = currentScriptPtr->var4+2;
flipShort(&var);
return(var);
}
int32 opcodeType0(void) // load opcode
{
switch(currentScriptOpcodeType)
{
case 0:
{
pushVar(getShortFromScript());
return(0);
}
case 1:
{
uint8* ptr;
int byte1 = getByteFromScript();
int byte2 = getByteFromScript();
short int short1 = getShortFromScript();
int var_E = byte1 & 7;
if(!var_E)
{
return(-10);
}
if(!byte2)
{
ptr = scriptDataPtrTable[var_E] + short1;
}
else // TODO:
{
if(!overlayTable[byte2].alreadyLoaded)
{
return(-7);
}
if(!overlayTable[byte2].ovlData)
{
return(-4);
}
if(var_E == 5)
{
ptr = overlayTable[byte2].ovlData->data4Ptr + short1;
}
else
{
assert(0);
}
}
if(((byte1 & 0x18)>>3)==1)
{
pushVar(loadShort(ptr));
return(0);
}
else
if(((byte1 & 0x18)>>3)==2)
{
pushVar(*ptr);
return(0);
}
else
{
printf("Unsupported code in opcodeType0 case 1!\n");
exit(1);
}
return(0);
}
case 2:
{
int16 var_16;
int di = getByteFromScript();
int si = getByteFromScript();
int var_2 = getShortFromScript();
if(!si)
{
si = currentScriptPtr->overlayNumber;
}
if(getSingleObjectParam(si, var_2, di, &var_16))
{
return -10;
}
pushVar(var_16);
return(0);
break;
}
case 5:
{
int byte1 = getByteFromScript();
int byte2 = getByteFromScript();
short int short1 = getShortFromScript();
short int var_12 = short1;
// short int var_10 = saveOpcodeVar;
int var_E = byte1 & 7;
uint8* ptr;
if(!var_E)
{
return(-10);
}
if(!byte2)
{
ptr = scriptDataPtrTable[var_E] + var_12;
}
else // TODO:
{
if(!overlayTable[byte2].alreadyLoaded)
{
return(-7);
}
if(!overlayTable[byte2].ovlData)
{
return(-4);
}
if(var_E == 5)
{
ptr = overlayTable[byte2].ovlData->data4Ptr + var_12;
}
else
{
assert(0);
}
}
if(((byte1 & 0x18)>>3)==1)
{
pushVar(loadShort(ptr+saveOpcodeVar*2)); // TODO: check this !
return(0);
}
else
if(((byte1 & 0x18)>>3)==2)
{
pushVar(*(ptr+saveOpcodeVar));
return(0);
}
else
{
printf("Unsupported code in opcodeType0 case 1!\n");
exit(1);
}
return(0);
}
default:
{
printf("Unsupported type %d in opcodeType0\n",currentScriptOpcodeType);
exit(1);
}
}
return 0;
}
int32 opcodeType1(void) // save opcode
{
int var = popVar();
int offset = 0;
switch(currentScriptOpcodeType)
{
case 0:
{
return(0); // strange, but happens also in original interpreter
}
case 5:
{
offset = saveOpcodeVar;
}
case 1:
{
int var_A = 0;
int byte1 = getByteFromScript();
int byte2 = getByteFromScript();
int short1 = getShortFromScript();
int var_6 = byte1 & 7;
int var_C = short1;
uint8* ptr;
int type2;
if(!var_6)
return(-10);
var_C = short1;
if(byte2)
{
if(!overlayTable[byte2].alreadyLoaded)
{
return(-7);
}
if(!overlayTable[byte2].ovlData)
{
return(-4);
}
if(var_6 == 5)
{
ptr = overlayTable[byte2].ovlData->data4Ptr + var_C;
}
else
{
ASSERT(0);
}
}
else
{
ptr = scriptDataPtrTable[var_6] + var_C;
}
type2 = ((byte1 & 0x18)>>3);
switch(type2)
{
case 1:
{
saveShort(ptr+var_A+offset*2,var);
return 0;
}
case 2:
{
*(ptr+var_A+offset) = var;
return(0);
}
default:
{
printf("Unsupported code in opcodeType1 case 1!\n");
exit(1);
}
}
break;
}
case 2:
{
int mode = getByteFromScript();
int di = getByteFromScript();
int var_4 = getShortFromScript();
if(!di)
{
di = currentScriptPtr->overlayNumber;
}
if(var == 0x85) // Special case to handle...
{
ASSERT(0);
}
setObjectPosition(di, var_4, mode, var);
break;
}
case 4:
{
saveOpcodeVar = var;
break;
}
default:
{
printf("Unsupported type %d in opcodeType1\n",currentScriptOpcodeType);
exit(1);
}
}
return(0);
}
int32 opcodeType2(void)
{
int offset = saveOpcodeVar;
int byte1 = getByteFromScript();
int byte2 = getByteFromScript();
short int short1 = getShortFromScript();
ASSERT(currentScriptOpcodeType == 1 || currentScriptOpcodeType == 5);
if(currentScriptOpcodeType == 5)
short1 += saveOpcodeVar;
ASSERT(byte1 & 7);
if(!(byte1 & 7))
{
return(-10);
}
if(!byte2)
{
int type2;
uint8* ptr = scriptDataPtrTable[byte1 & 7] + short1;
type2 = ((byte1&0x18)>>3);
ASSERT(type2 == 1 || type2 == 2);
switch(type2)
{
case 1:
{
pushPtr(ptr + offset);
return(0);
}
case 2:
{
pushPtr(ptr);
return(0);
}
default :
{
return(-10);
}
}
}
else
{
printf("Unsupported code in opcodeType2 case 1!\n");
exit(1);
}
return 0;
}
int32 opcodeType10(void) // break
{
return(0);
}
int32 opcodeType11(void) // break
{
return(1);
}
int32 opcodeType4(void) // test
{
int boolVar = 0;
int var1 = popVar();
int var2 = popVar();
switch(currentScriptOpcodeType)
{
case 0:
{
if(var2!=var1)
boolVar = 1;
break;
}
case 1:
{
if(var2==var1)
boolVar = 1;
break;
}
case 2:
{
if(var2<var1)
boolVar = 1;
break;
}
case 3:
{
if(var2<=var1)
boolVar = 1;
break;
}
case 4:
{
if(var2>var1)
boolVar = 1;
break;
}
case 5:
{
if(var2>=var1)
boolVar = 1;
break;
}
}
pushVar(boolVar);
return(0);
}
int32 opcodeType6(void)
{
int si = 0;
int pop = popVar();
if(!pop)
si = 1;
if(pop<0)
{
si |= 4;
}
if(pop>0)
{
si |= 2;
}
currentScriptPtr->bitMask = si;
return(0);
}
int32 opcodeType7(void)
{
int var1 = popVar();
int var2 = popVar();
pushVar(var1);
pushVar(var2);
return(0);
}
int32 opcodeType5(void)
{
int offset = currentScriptPtr->var4;
int short1 = getShortFromScript();
int newSi = short1 + offset;
int bitMask = currentScriptPtr->bitMask;
switch(currentScriptOpcodeType)
{
case 0:
{
if(!(bitMask & 1))
{
currentScriptPtr->var4 = newSi;
}
break;
}
case 1:
{
if(bitMask & 1)
{
currentScriptPtr->var4 = newSi;
}
break;
}
case 2:
{
if(bitMask & 2)
{
currentScriptPtr->var4 = newSi;
}
break;
}
case 3:
{
if(bitMask & 3)
{
currentScriptPtr->var4 = newSi;
}
break;
}
case 4:
{
if(bitMask & 4)
{
currentScriptPtr->var4 = newSi;
}
break;
}
case 5:
{
if(bitMask & 5)
{
currentScriptPtr->var4 = newSi;
}
break;
}
case 6:
{
break; // never
}
case 7:
{
currentScriptPtr->var4 = newSi; //always
}
}
return(0);
}
int32 opcodeType3(void) // math
{
int pop1 = popVar();
int pop2 = popVar();
switch(currentScriptOpcodeType)
{
case 0:
{
pushVar(pop1+pop2);
return(0);
}
case 1:
{
pushVar(pop1/pop2);
return(0);
}
case 2:
{
pushVar(pop1-pop2);
return(0);
}
case 3:
{
pushVar(pop1*pop2);
return(0);
}
case 4:
{
pushVar(pop1%pop2);
return(0);
}
case 7:
case 5:
{
pushVar(pop2|pop1);
return(0);
}
case 6:
{
pushVar(pop2&pop1);
return(0);
}
}
return 0;
}
int32 opcodeType9(void) // stop script
{
//printf("Stop a script of overlay %s\n",overlayTable[currentScriptPtr->overlayNumber].overlayName);
currentScriptPtr->scriptNumber = -1;
return(1);
}
void setupFuncArray()
{
int i;
for(i=0;i<64;i++)
{
opcodeTypeTable[i] = NULL;
}
opcodeTypeTable[1] = opcodeType0;
opcodeTypeTable[2] = opcodeType1;
opcodeTypeTable[3] = opcodeType2;
opcodeTypeTable[4] = opcodeType3;
opcodeTypeTable[5] = opcodeType4;
opcodeTypeTable[6] = opcodeType5;
opcodeTypeTable[7] = opcodeType6;
opcodeTypeTable[8] = opcodeType7;
opcodeTypeTable[9] = opcodeType8;
opcodeTypeTable[10] = opcodeType9;
opcodeTypeTable[11] = opcodeType10;
opcodeTypeTable[12] = opcodeType11;
}
int removeScript(int overlay,int idx,scriptInstanceStruct* headPtr)
{
scriptInstanceStruct* scriptPtr;
scriptPtr = headPtr->nextScriptPtr;
if(scriptPtr)
{
do
{
if(scriptPtr->overlayNumber == overlay && (scriptPtr->scriptNumber == idx || idx == -1))
{
scriptPtr->scriptNumber = -1;
}
scriptPtr = scriptPtr->nextScriptPtr;
}
while(scriptPtr);
}
return(0);
}
uint8* attacheNewScriptToTail(int16 overlayNumber,scriptInstanceStruct* scriptHandlePtr,int16 param, int16 arg0, int16 arg1, int16 arg2, scriptTypeEnum scriptType)
{
int useArg3Neg = 0;
ovlData3Struct* data3Ptr;
scriptInstanceStruct* tempPtr;
int var_C;
scriptInstanceStruct* oldTail;
//printf("Starting script %d of overlay %s\n",param,overlayTable[overlayNumber].overlayName);
if(scriptType<0)
{
useArg3Neg = 1;
scriptType = (scriptTypeEnum)-scriptType;
}
if(scriptType == 20)
{
data3Ptr = getOvlData3Entry(overlayNumber,param);
}
else
{
if(scriptType == 30)
{
data3Ptr = scriptFunc1Sub2(overlayNumber,param);
}
else
{
return(NULL);
}
}
if(!data3Ptr)
{
return(NULL);
}
if(!data3Ptr->dataPtr)
{
return(NULL);
}
var_C = data3Ptr->sysKey;
oldTail = scriptHandlePtr;
while(oldTail->nextScriptPtr) // go to the end of the list
{
oldTail=oldTail->nextScriptPtr;
}
tempPtr = (scriptInstanceStruct*)mallocAndZero(sizeof(scriptInstanceStruct));
if(!tempPtr)
return(NULL);
tempPtr->var6 = NULL;
if(var_C)
{
tempPtr->var6 = (uint8*)mallocAndZero(var_C);
}
tempPtr->varA = var_C;
tempPtr->nextScriptPtr = NULL;
tempPtr->var4 = 0;
tempPtr->scriptNumber = param;
tempPtr->overlayNumber = overlayNumber;
if(scriptType == 20) // Obj or not ?
{
tempPtr->sysKey = useArg3Neg;
}
else
{
tempPtr->sysKey = 1;
}
tempPtr->var12 = 0;
tempPtr->type = scriptType;
tempPtr->var18 = arg2;
tempPtr->var16 = arg1;
tempPtr->var1A = arg0;
tempPtr->nextScriptPtr = oldTail->nextScriptPtr; // should always be NULL as it's the tail
oldTail->nextScriptPtr = tempPtr; // attache the new node to the list
return(tempPtr->var6);
}
int executeScripts(scriptInstanceStruct* ptr)
{
int numScript2;
ovlData3Struct* ptr2;
ovlDataStruct* ovlData;
uint8 opcodeType;
numScript2 = ptr->scriptNumber;
if(ptr->type == 20)
{
ptr2 = getOvlData3Entry(ptr->overlayNumber,numScript2);
if(!ptr2)
{
return(-4);
}
}
else
{
if(ptr->type == 30)
{
ptr2 = scriptFunc1Sub2(ptr->overlayNumber,numScript2);
if(!ptr2)
{
return(-4);
}
}
else
{
return(-6);
}
}
if(!overlayTable[ptr->overlayNumber].alreadyLoaded)
{
return(-7);
}
ovlData = overlayTable[ptr->overlayNumber].ovlData;
if(!ovlData)
return(-4);
currentData3DataPtr = ptr2->dataPtr;
scriptDataPtrTable[1] = (uint8*)ptr->var6;
scriptDataPtrTable[2] = getDataFromData3(ptr2, 1);
scriptDataPtrTable[5] = ovlData->data4Ptr; // free strings
scriptDataPtrTable[6] = ovlData->ptr8;
currentScriptPtr = ptr;
positionInStack = 0;
do
{
if(currentScriptPtr->var4 == 290 && currentScriptPtr->overlayNumber == 4 && currentScriptPtr->scriptNumber == 0)
{
currentScriptPtr->var4 = 923;
}
opcodeType = getByteFromScript();
//printf("opType: %d\n",(opcodeType&0xFB)>>3);
currentScriptOpcodeType = opcodeType & 7;
if(!opcodeTypeTable[(opcodeType&0xFB)>>3])
{
printf("Unsupported opcode type %d\n",(opcodeType&0xFB)>>3);
exit(1);
return(-21);
}
}while(!opcodeTypeTable[(opcodeType&0xFB)>>3]());
return(0);
}
void manageScripts(scriptInstanceStruct* scriptHandle)
{
scriptInstanceStruct* ptr = scriptHandle;
if(ptr)
{
do
{
if(!overlayTable[ptr->overlayNumber].executeScripts)
{
if(ptr->scriptNumber != -1 && ptr->var12 == 0 && ptr->sysKey != 0)
{
executeScripts(ptr);
}
if(ptr->sysKey == 0)
{
ptr->sysKey = 1;
}
}
ptr = ptr->nextScriptPtr;
}while(ptr);
}
}
} // End of namespace Cruise

73
engines/cruise/script.h Normal file
View file

@ -0,0 +1,73 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _SCRIPT_H_
#define _SCRIPT_H_
namespace Cruise {
enum scriptTypeEnum
{
scriptType_Minus20 = -20,
scriptType_Minus30 = -30,
scriptType_20 = 20,
scriptType_30 = 30
};
typedef enum scriptTypeEnum scriptTypeEnum;
struct scriptInstanceStruct
{
struct scriptInstanceStruct* nextScriptPtr;
int16 var4;
uint8* var6;
int16 varA;
int16 scriptNumber;
int16 overlayNumber;
int16 sysKey;
int16 var12;
scriptTypeEnum type;
int16 var16;
int16 var18;
int16 var1A;
////// EXTRA ! not in original code. Needed for cross platform.
int16 bitMask;
};
typedef struct scriptInstanceStruct scriptInstanceStruct;
extern scriptInstanceStruct scriptHandle1;
extern scriptInstanceStruct scriptHandle2;
extern scriptInstanceStruct* currentScriptPtr;
void setupFuncArray(void);
uint8 getByteFromScript(void);
int removeScript(int overlay,int idx,scriptInstanceStruct* headPtr);
uint8* attacheNewScriptToTail(int16 overlayNumber,scriptInstanceStruct* scriptHandlePtr,int16 param, int16 arg0, int16 arg1, int16 arg2, scriptTypeEnum scriptType);
void manageScripts(scriptInstanceStruct* scriptHandle);
} // End of namespace Cruise
#endif

85
engines/cruise/stack.cpp Normal file
View file

@ -0,0 +1,85 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
// 4 type bigger than the old one, but much safer/cleaner
stackElementStruct scriptStack[SIZE_STACK];
// VAR
void pushVar(int16 var)
{
if(positionInStack<SIZE_STACK)
{
scriptStack[positionInStack].data.shortVar = var;
scriptStack[positionInStack].type = STACK_SHORT;
positionInStack++;
}
}
int16 popVar(void)
{
if(positionInStack<=0)
{
return(0);
}
positionInStack--;
ASSERT(scriptStack[positionInStack].type == STACK_SHORT);
return(scriptStack[positionInStack].data.shortVar);
}
//// PTR
void pushPtr(void* ptr)
{
if(positionInStack<SIZE_STACK)
{
scriptStack[positionInStack].data.ptrVar = ptr;
scriptStack[positionInStack].type = STACK_PTR;
positionInStack++;
}
}
void* popPtr()
{
if(positionInStack<=0)
{
return(0);
}
positionInStack--;
ASSERT(scriptStack[positionInStack].type == STACK_PTR);
return(scriptStack[positionInStack].data.ptrVar);
}
} // End of namespace Cruise

61
engines/cruise/stack.h Normal file
View file

@ -0,0 +1,61 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _STACK_H_
#define _STACK_H_
namespace Cruise {
#define SIZE_STACK 0x200
enum stackElementTypeEnum
{
STACK_SHORT,
STACK_PTR
};
typedef enum stackElementTypeEnum stackElementTypeEnum;
struct stackElementStruct
{
stackElementTypeEnum type;
union
{
void* ptrVar;
int16 shortVar;
} data;
};
typedef struct stackElementStruct stackElementStruct;
int16 popVar(void);
void pushVar(int16 var);
void pushPtr(void* ptr);
void* popPtr(void);
} // End of namespace Cruise
#endif

View file

@ -0,0 +1,49 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
void strcpyuint8(void* dest, void* source)
{
strcpy((char*)dest,(char*)source);
}
void strcatuint8(void* dest, void* source)
{
strcat((char*)dest,(char*)source);
}
uint8 strcmpuint8(void* string1, void* string2)
{
return strcmp((char*)string1,(char*)string2);
}
FILE* fopenuint8(void* name, void* param)
{
return fopen((char*)name,(char*)param);
}
} // End of namespace Cruise

View file

@ -0,0 +1,37 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _STRING_SUPPORT_H_
#define _STRING_SUPPORT_H_
namespace Cruise {
void strcpyuint8(void* dest, void* source);
void strcatuint8(void* dest, void* source);
uint8 strcmpuint8(void* string1, void* string2);
FILE* fopenuint8(void* name, void* param);
} // End of namespace Cruise
#endif

187
engines/cruise/various.cpp Normal file
View file

@ -0,0 +1,187 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
uint16 var0 = 0;
uint16 fadeVar;
uint16 main15;
int16 readB16(void* ptr)
{
int16 temp;
temp = *(int16*)ptr;
flipShort(&temp);
return temp;
}
void freeObject(objectStruct* objPtr)
{
if(objPtr)
{
/* if(objPtr->next)
free(objPtr->next); */
//free(objPtr);
}
}
void removeObjectFromList(int ovlNumber, int objectIdx, objectStruct* objPtr, int backgroundPlane, int arg)
{
objectStruct* currentObj = objPtr->next;
objectStruct* previous;
while(currentObj)
{
objectStruct* si;
si = currentObj;
if( (si->overlay == ovlNumber || ovlNumber == -1) &&
(si->idx == objectIdx || objectIdx == -1) &&
(si->type == arg || arg == -1) &&
(si->backgroundPlane == backgroundPlane || backgroundPlane == -1) )
{
si->type = -1;
}
currentObj = si->next;
}
previous = objPtr;
currentObj = objPtr->next;
while(currentObj)
{
objectStruct* si;
si = currentObj;
if(si->type == -1)
{
objectStruct* dx;
previous->next = si->next;
dx = si->next;
if(!si->next)
{
dx = objPtr;
}
dx->prev = si->prev;
freeObject(si);
free(si);
currentObj = dx;
}
else
{
currentObj = si->next;
previous = si;
}
}
}
char* getText(int textIndex, int overlayIndex)
{
if(!overlayTable[overlayIndex].ovlData)
{
return NULL;
}
if(!overlayTable[overlayIndex].ovlData->stringTable)
{
return NULL;
}
return overlayTable[overlayIndex].ovlData->stringTable[textIndex].string;
}
void createTextObject(int overlayIdx, int oldVar8, objectStruct *pObject, int scriptNumber, int scriptOverlayNumber, int backgroundPlane, int16 color, int oldVar2, int oldVar4, int oldVar6)
{
char* ax;
objectStruct* savePObject = pObject;
objectStruct* cx;
objectStruct* pNewElement;
objectStruct* si = pObject->next;
objectStruct* var_2;
while(si)
{
pObject = si;
si = si->next;
}
var_2 = si;
pNewElement = (objectStruct*)malloc(sizeof(objectStruct));
pNewElement->next = pObject->next;
pObject->next = pNewElement;
pNewElement->idx = oldVar8;
pNewElement->type = 5;
pNewElement->backgroundPlane = backgroundPlane;
pNewElement->overlay = overlayIdx;
pNewElement->field_A = oldVar6;
pNewElement->field_C = oldVar4;
pNewElement->spriteIdx = oldVar2;
pNewElement->field_10 = color;
pNewElement->hide = 0;
pNewElement->field_16 = scriptNumber;
pNewElement->field_18 = scriptOverlayNumber;
pNewElement->gfxPtr = NULL;
if(var_2)
{
cx = var_2;
}
else
{
cx = savePObject;
}
pNewElement->prev = cx->prev;
cx->prev = pNewElement;
ax = getText(oldVar8, overlayIdx);
if(ax)
{
pNewElement->gfxPtr = renderText(oldVar2, (uint8*)ax);
}
}
} // End of namespace Cruise

43
engines/cruise/various.h Normal file
View file

@ -0,0 +1,43 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _VARIOUS_H_
#define _VARIOUS_H_
namespace Cruise {
extern uint16 var0;
extern uint16 fadeVar;
extern uint16 main15;
int16 readB16(void* ptr);
void createTextObject(int overlayIdx, int oldVar8, objectStruct *pObject, int scriptNumber, int scriptOverlayNumber, int backgroundPlane, int16 color, int oldVar2, int oldVar4, int oldVar6);
void removeObjectFromList(int ovlNumber, int objectIdx, objectStruct* objPtr, int backgroundPlane, int arg);
objectStruct* addObject(int16 overlayIdx,int16 param2,objectStruct* pHead,int16 scriptType,int16 scriptNumber,int16 scriptOverlay, int16 param3, int16 param4);
int16 Op_7Sub(int ovlIdx,int param1,int param2);
} // End of namespace Cruise
#endif

182
engines/cruise/vars.cpp Normal file
View file

@ -0,0 +1,182 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
uint8* _systemFNT;
uint8 video2 = 1;
uint8 video3 = 3;
uint8 video4 = 2;
uint8 colorOfSelectedSaveDrive = 5;
int16 initVar1;
int16 initVar2;
int16 initVar3;
uint8 initVar4[90];
int16 currentActiveBackgroundPlane;
int16 main5;
int16 var22 = 0;
filesDataStruct filesData[90];
filesData2Struct filesData2[90];
mediumVarStruct mediumVar[64];
volumeDataStruct volumeData[20];
int32 volumeDataLoaded = 0;
int16 numOfDisks;
uint8 scriptNameBuffer[15];
int16 currentActiveMenu;
int16 main14;
int16 mouseVar1;
int16 main21;
int16 main22;
int16 main7;
int16 main8;
int16 currentDiskNumber = 1;
Common::File currentVolumeFile;
int16 currentCursor;
int16 volumeNumEntry;
fileEntry* volumePtrToFileDescriptor = NULL;
uint32 volumeFileDescriptorSize;
int16 volumeSizeOfEntry;
int16 volumeNumberOfEntry;
int16 affichePasMenuJoueur = 1;
int16 globalVars[2000];
dataFileEntry filesDatabase[257];
int16 bootOverlayNumber;
int16 initVar5[12];
objectStruct objectHead;
opcodeTypeFunction opcodeTypeTable[64];
int16 positionInStack;
actorStruct actorHead;
int16 setup1;
uint8* currentData3DataPtr;
uint8* scriptDataPtrTable[7];
int16 currentScriptOpcodeType;
int16 saveOpcodeVar;
int16 var30 = 0;
int16 var31 = 0;
int16 var1;
int16 var2;
int16 var3;
int16 var4;
int16 userEnabled;
int16 var5;
int16 var6;
int16 var7;
int16 var8;
int16 userDelay;
int16 sysKey = -1;
int16 var11 = 0;
int16 var12;
int16 var13;
int16 var14;
int16 var20;
int16 var23;
int16 var24;
int16 automaticMode;
int16 var34;
int16 var35;
int16 animationStart;
int16 main17;
int16 var39;
int16 entrerMenuJoueur;
int16 var41;
int16 var42;
int16 var45;
int16 var46;
int16 var47;
int16 var48;
int16 flagCt;
int8 var50[64];
int16 palette[256*3];
systemStringsStruct systemStrings;
uint8 currentCtpName[40];
int16 saveVar1;
uint8 saveVar2[97]; // recheck size
int16 numberOfWalkboxes; // saveVar3
int16 walkboxType[15]; // saveVar4
int16 walkboxChange[15]; // saveVar5
uint8 saveVar6[16];
int32 loadFileVar1;
int16 ctpVar1 = 0;
int16 ctp_routeCoordCount; // ctpVar2
int16 ctp_routeCoords[20][2]; // ctpVar3
int16 ctp_routes[20][10];
uint16 ctp_walkboxTable[15 * 40]; // ctpVar5
int8 ctpVar6[32];
int16 ctp_scale[15]; // ctpVar7
int16 ctpVar8[200];
int16 ctpVar14;
int16 bgVar1;
int16 bgVar2;
int16 bgVar3;
uint8 globalScreen[320*200];
uint8 scaledScreen[640*400];
//OSystem *osystem;
} // End of namespace Cruise

340
engines/cruise/vars.h Normal file
View file

@ -0,0 +1,340 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _VARS_H_
#define _VARS_H_
#include "common/file.h"
namespace Cruise {
struct menuElementSubStruct
{
struct menuElementSubStruct* pNext;
int16 var2;
int16 var4;
};
typedef struct menuElementSubStruct menuElementSubStruct;
struct menuElementStruct
{
struct menuElementStruct* next;
char* string;
int x;
int y;
int varA;
int varC;
unsigned char color;
gfxEntryStruct* gfx;
menuElementSubStruct* ptrSub;
};
typedef struct menuElementStruct menuElementStruct;
typedef int32(*opcodeTypeFunction)(void);
typedef int16(*opcodeFunction)(void);
extern uint8* _systemFNT;
extern int16 fontFileIndex;
extern uint8 video2;
extern uint8 video3;
extern uint8 video4;
extern uint8 colorOfSelectedSaveDrive;
extern int16 initVar1;
extern int16 initVar2;
extern int16 initVar3;
extern uint8 initVar4[90];
extern int16 currentActiveBackgroundPlane;
extern int16 main5;
extern int16 var22;
struct mediumVarStruct
{
uint8 name[16];
int16 field_10;
int16 field_12;
int16 field_14;
int16 field_16;
uint8* ptr;
int16 field_1C;
int16 field_1E;
int16 field_20;
};
typedef struct mediumVarStruct mediumVarStruct;
struct filesDataStruct
{
uint8* field_0;
uint8* field_4;
};
typedef struct filesDataStruct filesDataStruct;
struct filesData2Struct
{
int16 field_0;
int16 field_2;
};
typedef struct filesData2Struct filesData2Struct;
struct fileName
{
uint8 name[13];
};
typedef struct fileName fileName;
struct setHeaderEntry
{
int16 field_0; // offset ptr part 1
int16 field_2; // offset ptr part 2
int16 width;
int16 height;
int16 type; // resource type, ie. sprites 0,1,4,5 and 8
int16 transparency;
int16 field_C;
int16 field_E;
};
typedef struct setHeaderEntry setHeaderEntry;
struct volumeDataStruct
{
char ident[10];
fileName* ptr;
int16 diskNumber;
int32 size;
};
typedef struct volumeDataStruct volumeDataStruct;
struct fileEntry
{
uint8 name[14];
int32 offset;
int32 size;
int32 extSize;
int32 unk3; // unused
};
typedef struct fileEntry fileEntry;
struct dataFileEntrySub
{
uint8* ptr;
int16 index; // sprite index
char name[14];
int16 transparency; // sprite transparency
uint8* ptr2;
uint8 resourceType; // sprite and image type 2,4,8 , fnt = 7, spl = 6
uint8 field_1B;
int16 field_1C;
};
typedef struct dataFileEntrySub dataFileEntrySub;
struct dataFileEntry
{
int16 widthInColumn;
int16 width;
int16 resType;
int16 height;
dataFileEntrySub subData;
};
typedef struct dataFileEntry dataFileEntry;
struct systemStringsStruct
{
int8 param;
uint8 string[12];
uint8 bootScriptName[8];
};
typedef struct systemStringsStruct systemStringsStruct;
extern filesDataStruct filesData[90];
extern filesData2Struct filesData2[90];
extern mediumVarStruct mediumVar[64];
extern volumeDataStruct volumeData[20];
extern int32 volumeDataLoaded;
extern int16 numOfDisks;
extern uint8 scriptNameBuffer[15];
extern int16 currentActiveMenu;
extern int16 main14;
extern int16 mouseVar1;
extern int16 main21;
extern int16 main22;
extern int16 main7;
extern int16 main8;
extern int16 currentDiskNumber;
extern Common::File currentVolumeFile;
extern int16 currentCursor;
extern int16 volumeNumEntry;
extern fileEntry* volumePtrToFileDescriptor;
extern uint32 volumeFileDescriptorSize;
extern int16 volumeSizeOfEntry;
extern int16 volumeNumberOfEntry;
extern int16 affichePasMenuJoueur;
extern int16 globalVars[2000];
extern dataFileEntry filesDatabase[257];
extern int16 bootOverlayNumber;
extern int16 initVar5[12];
extern objectStruct objectHead;
extern opcodeTypeFunction opcodeTypeTable[64];
extern int16 positionInStack;
extern actorStruct actorHead;
extern int16 setup1;
extern uint8* currentData3DataPtr;
extern uint8* scriptDataPtrTable[7];
extern int16 currentScriptOpcodeType;
extern int16 saveOpcodeVar;
extern int16 var30;
extern int16 var31;
extern int16 var1;
extern int16 var2;
extern int16 var3;
extern int16 var4;
extern int16 userEnabled;
extern int16 var5;
extern int16 var6;
extern int16 var7;
extern int16 var8;
extern int16 userDelay;
extern int16 sysKey;
extern int16 var11;
extern int16 var12;
extern int16 var13;
extern int16 var14;
extern int16 var20;
extern int16 var23;
extern int16 var24;
extern int16 automaticMode;
extern int16 var34;
extern int16 var35;
extern int16 animationStart;
extern int16 main17;
extern int16 var39;
extern int16 entrerMenuJoueur;
extern int16 var39;
extern int16 var41;
extern int16 var42;
extern int16 var45;
extern int16 var46;
extern int16 var47;
extern int16 var48;
extern int16 flagCt;
extern int8 var50[64];
extern int16 palette[256*3];
extern systemStringsStruct systemStrings;
extern uint8 currentCtpName[40];
extern int16 saveVar1;
extern uint8 saveVar2[97]; // recheck size
extern int16 numberOfWalkboxes; // saveVar3
extern int16 walkboxType[15]; // saveVar4 // Type: 0x00 - non walkable, 0x01 - walkable, 0x02 - exit zone
extern int16 walkboxChange[15]; // saveVar5 // walkbox can change its type: 0x00 - not changeable, 0x01 - changeable
// Assumption: To change the type: walkboxType[i] -= walkboxChane[i] and vice versa
extern uint8 saveVar6[16];
extern int32 loadFileVar1;
extern int16 ctpVar1;
extern int16 ctp_routeCoordCount; // ctpVar2 // number of path-finding coordinates
extern int16 ctp_routeCoords[20][2]; // ctpVar3 // path-finding coordinates array
/* ctp_routeCoords:
correct size would be: ctp_routes[routeCoordCount * 4]
coordinate information with x (2 bytes) and y (2 bytes)
*/
extern int16 ctp_routes[20][10]; // path-finding line information
/* ctp_routes:
correct size would be: ctp_routes[routeCoordCount * 20 * 2]
array is seperate in 20 * 2 bytes slices.
first 2 bytes of the slice indicate how many coordinates/lines are following (lineCount)
after that there are lineCount * 2 bytes following with indexes pointing on the routeCoords table
the root x,y for the lines is the coordinate in the routeCoords array, which fits to the current slice
for the 20 * i slice the root x,y is routeCoords[i], routeCoords[i+2]
the unused rest of the slice if filled up with 0xFF
*/
extern uint16 ctp_walkboxTable[15 * 40]; // ctpVar5 // walkboxes coordinates and lines
extern int8 ctpVar6[32];
extern int16 ctp_scale[15]; // ctpVar7 // scaling information for walkboxes
extern int16 ctpVar8[200];
extern int16 ctpVar14;
extern int16 bgVar1;
extern int16 bgVar2;
extern int16 bgVar3;
extern uint8 globalScreen[320*200];
extern uint8 scaledScreen[640*400];
//extern OSystem *osystem;
} // End of namespace Cruise
#endif

518
engines/cruise/volume.cpp Normal file
View file

@ -0,0 +1,518 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#include "cruise/cruise_main.h"
namespace Cruise {
FILE* PAL_fileHandle = NULL;
uint8* PAL_ptr = NULL;
int16 numLoadedPal;
int16 fileData2;
void loadPal(volumeDataStruct* entry)
{
char name[20];
return;
if(PAL_fileHandle)
{
fclose(PAL_fileHandle);
}
removeExtention(entry->ident, name);
strcat(name,".PAL");
PAL_fileHandle = fopen(name,"rb");
fread(&numLoadedPal, 2, 1, PAL_fileHandle);
fread(&fileData2, 2, 1, PAL_fileHandle);
flipShort(&numLoadedPal);
flipShort(&fileData2);
PAL_ptr = (uint8*)malloc(numLoadedPal*fileData2);
}
int getVolumeDataEntry(volumeDataStruct* entry)
{
char buffer[256];
int i;
volumeNumEntry = 0;
volumeNumberOfEntry = 0;
if(currentVolumeFile.isOpen())
{
freeDisk();
}
askDisk(-1);
strcpyuint8(buffer,entry->ident);
currentVolumeFile.open(buffer);
if(!currentVolumeFile.isOpen())
{
return(-14);
}
changeCursor(1);
currentVolumeFile.read(&volumeNumberOfEntry,2);
currentVolumeFile.read(&volumeSizeOfEntry,2);
flipShort(&volumeNumberOfEntry);
flipShort(&volumeSizeOfEntry);
volumeNumEntry = volumeNumberOfEntry;
assert(volumeSizeOfEntry == 14+4+4+4+4);
volumePtrToFileDescriptor = (fileEntry*)mallocAndZero(sizeof(fileEntry) * volumeNumEntry);
for(i=0;i<volumeNumEntry;i++)
{
volumePtrToFileDescriptor[i].name[0] = 0;
volumePtrToFileDescriptor[i].offset = 0;
volumePtrToFileDescriptor[i].size = 0;
volumePtrToFileDescriptor[i].extSize = 0;
volumePtrToFileDescriptor[i].unk3 = 0;
}
for(i=0;i<volumeNumEntry;i++)
{
currentVolumeFile.read(&volumePtrToFileDescriptor[i].name, 14);
currentVolumeFile.read(&volumePtrToFileDescriptor[i].offset, 4);
currentVolumeFile.read(&volumePtrToFileDescriptor[i].size, 4);
currentVolumeFile.read(&volumePtrToFileDescriptor[i].extSize, 4);
currentVolumeFile.read(&volumePtrToFileDescriptor[i].unk3, 4);
}
for(i=0;i<volumeNumEntry;i++)
{
flipLong(&volumePtrToFileDescriptor[i].offset);
flipLong(&volumePtrToFileDescriptor[i].size);
flipLong(&volumePtrToFileDescriptor[i].extSize);
}
loadPal(entry);
return 0;
}
int searchFileInVolCnf(uint8* fileName,int32 diskNumber)
{
int foundDisk = -1;
int i;
for(i=0;i<numOfDisks;i++)
{
if(volumeData[i].diskNumber == diskNumber)
{
int j;
int numOfEntry = volumeData[i].size / 13;
for(j=0;j<numOfEntry;j++)
{
if(!strcmpuint8(volumeData[i].ptr[j].name,fileName))
{
return(i);
}
}
}
}
return(foundDisk);
}
int32 findFileInDisksSub1(uint8* fileName)
{
int foundDisk = -1;
int i;
for(i=0;i<numOfDisks;i++)
{
int j;
int numOfEntry = volumeData[i].size / 13;
for(j=0;j<numOfEntry;j++)
{
if(!strcmpuint8(volumeData[i].ptr[j].name,fileName))
{
return(i);
}
}
}
return(foundDisk);
}
void strToUpper(uint8* fileName)
{
char character;
do
{
character = *fileName;
if(character>='a' && character<='z')
{
character&=0xDF;
*fileName = character;
}
fileName++;
}while(character);
}
int16 fileExist(uint8* fileName)
{
FILE* fHandle;
fHandle = fopenuint8(fileName,"rb");
if(fHandle)
{
fclose(fHandle);
return(0);
}
return(1);
}
void freeDisk(void)
{
if(currentVolumeFile.isOpen())
{
currentVolumeFile.close();
free(volumePtrToFileDescriptor);
}
/* TODO
if(PAL_fileHandle)
{
freeAllDataPtr();
}
*/
}
int16 findFileInList(uint8* fileName)
{
int i;
if(!currentVolumeFile.isOpen())
{
return(-1);
}
strToUpper(fileName);
if(volumeNumEntry<=0)
{
return(-1);
}
for(i=0;i<volumeNumEntry;i++)
{
if(!strcmpuint8(volumePtrToFileDescriptor[i].name,fileName))
{
return(i);
}
}
return(-1);
}
void askDisk(int16 discNumber)
{
char diskNumberString[256];
uint8 fileName[256];
uint8 string[256];
char messageDrawn = 0;
if(discNumber != -1)
{
currentDiskNumber = discNumber;
}
// skip drive selection stuff
strcpyuint8(fileName,"VOL.");
sprintf(diskNumberString,"%d",currentDiskNumber);
strcatuint8(fileName,diskNumberString);
strcpyuint8(string,"INSERER LE DISQUE ");
strcatuint8(string,diskNumberString);
strcatuint8(string," EN ");
// while(fileExist(fileName))
{
if(!messageDrawn)
{
drawMsgString(string);
messageDrawn = 1;
}
}
changeCursor(currentCursor);
}
int16 findFileInDisks(uint8* fileName)
{
int disk;
int fileIdx;
strToUpper(fileName);
if(!volumeDataLoaded)
{
printf("CNF wasn't loaded, reading now...\n");
if(currentVolumeFile.isOpen())
{
askDisk(-1);
freeDisk();
}
askDisk(1);
readVolCnf();
}
if(currentVolumeFile.isOpen())
{
askDisk(-1);
}
fileIdx = findFileInList(fileName);
if(fileIdx>=0)
{
return(fileIdx);
}
disk = searchFileInVolCnf(fileName,currentDiskNumber);
if(disk>=0)
{
int temp;
printf("File found on disk %d\n", disk);
if(currentVolumeFile.isOpen())
{
askDisk(-1);
}
freeDisk();
askDisk(volumeData[disk].diskNumber);
getVolumeDataEntry(&volumeData[disk]);
temp = findFileInList(fileName);
if(temp>=0)
return(temp);
return(-1);
}
else
{
int temp;
temp = findFileInDisksSub1(fileName);
if(temp>=0)
{
int temp2;
askDisk(volumeData[temp].diskNumber);
getVolumeDataEntry(&volumeData[temp]);
temp2 = findFileInList(fileName);
if(temp2>=0)
return(temp2);
}
return(-1);
}
}
int16 readVolCnf(void)
{
int i;
Common::File fileHandle;
short int sizeHEntry;
volumeDataLoaded = 0;
for(i=0;i<20;i++)
{
volumeData[i].ident[0] = 0;
volumeData[i].ptr = NULL;
volumeData[i].diskNumber = i+1;
volumeData[i].size = 0;
}
fileHandle.open("VOL.CNF");
if(!fileHandle.isOpen())
{
return(0);
}
fileHandle.read(&numOfDisks,2);
flipShort(&numOfDisks);
fileHandle.read(&sizeHEntry,2);
flipShort(&sizeHEntry); // size of one header entry - 20 bytes
for(i=0;i<numOfDisks;i++)
{
// fread(&volumeData[i],20,1,fileHandle);
fileHandle.read(&volumeData[i].ident, 10);
fileHandle.read(&volumeData[i].ptr, 4);
fileHandle.read(&volumeData[i].diskNumber, 2);
fileHandle.read(&volumeData[i].size, 4);
flipShort(&volumeData[i].diskNumber);
printf("Disk number: %d\n", volumeData[i].diskNumber);
flipLong(&volumeData[i].size);
}
for(i=0;i<numOfDisks;i++)
{
fileName* ptr;
fileHandle.read(&volumeData[i].size,4);
flipLong(&volumeData[i].size);
ptr = (fileName*)mallocAndZero(volumeData[i].size);
volumeData[i].ptr = ptr;
if(!ptr)
{
fileHandle.close();
return(-2);
}
fileHandle.read(ptr,volumeData[i].size);
}
fileHandle.close();
volumeDataLoaded = 1;
//#define dumpResources
#ifdef dumpResources
for(i=0;i<numOfDisks;i++)
{
int j;
char nameBuffer[256];
fileEntry* buffer;
sprintf(nameBuffer,"D%d.",i+1);
fileHandle = fopen(nameBuffer,"rb");
short int numEntry;
short int sizeEntry;
fread(&numEntry,2,1,fileHandle);
fread(&sizeEntry,2,1,fileHandle);
flipShort(&numEntry);
flipShort(&sizeEntry);
buffer = (fileEntry*)mallocAndZero(numEntry*sizeEntry);
fread(buffer,numEntry*sizeEntry,1,fileHandle);
for(j=0;j<numEntry;j++)
{
flipLong(&buffer[j].offset);
flipLong(&buffer[j].size);
flipLong(&buffer[j].unk2);
flipLong(&buffer[j].unk3);
fseek(fileHandle, buffer[j].offset, SEEK_SET);
char* bufferLocal;
bufferLocal = (char*)mallocAndZero(buffer[j].size);
fread(bufferLocal,buffer[j].size,1,fileHandle);
char nameBuffer[256];
sprintf(nameBuffer,"D%d.dmp/%s",i+1,buffer[j].name);
if(buffer[j].size == buffer[j].unk2)
{
FILE* fOut = fopen(nameBuffer,"wb+");
fwrite(bufferLocal,buffer[j].size,1,fOut);
fclose(fOut);
}
else
{
char* uncompBuffer = (char*)mallocAndZero(buffer[j].unk2+500);
decomp((uint8*)bufferLocal+buffer[j].size-4,(uint8*)uncompBuffer+buffer[j].unk2+500,buffer[j].unk2);
FILE* fOut = fopen(nameBuffer,"wb+");
fwrite(uncompBuffer+500,buffer[j].unk2,1,fOut);
fclose(fOut);
//free(uncompBuffer);
}
free(bufferLocal);
}
}
#endif
return(1);
}
///////////////////////////::
void drawMsgString(uint8* string)
{
//printf("%s\n",string);
}
} // End of namespace Cruise

45
engines/cruise/volume.h Normal file
View file

@ -0,0 +1,45 @@
/* ScummVM - Scumm Interpreter
* Copyright (C) 2006 The ScummVM project
*
* cinE Engine is (C) 2004-2005 by CinE Team
*
* 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.
*
* $URL$
* $Id$
*
*/
#ifndef _VOLUME_H_
#define _VOLUME_H_
namespace Cruise {
int16 readVolCnf(void);
int16 findFileInDisks(uint8* fileName);
int16 fileExist(uint8* fileName);
void freeDisk(void);
int16 findFileInList(uint8* fileName);
////////////////
void strToUpper(uint8* fileName);
void drawMsgString(uint8* string);
void askDisk(int16 discNumber);
void setObjectPosition(int16 param1,int16 param2,int16 param3,int16 param4);
} // End of namespace Cruise
#endif