Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "freescape/freescape.h"
#include "freescape/games/castle/castle.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
byte kAmigaCastlePalette[16][3] = {
{0x00, 0x00, 0x00},
{0x44, 0x44, 0x44},
{0x66, 0x66, 0x66},
{0x88, 0x88, 0x88},
{0xaa, 0xaa, 0xaa},
{0xcc, 0xcc, 0xcc},
{0x00, 0x00, 0x88},
{0x66, 0xaa, 0x00},
{0x88, 0xcc, 0x00},
{0xcc, 0xee, 0x00},
{0xee, 0xee, 0x66},
{0x44, 0x88, 0x00},
{0xee, 0xaa, 0x00},
{0xcc, 0x44, 0x00},
{0x88, 0x44, 0x00},
{0xee, 0xee, 0xee},
};
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanesVertical(Common::SeekableReadStream *file, int widthInBytes, int height) {
Graphics::ManagedSurface *surface;
surface = new Graphics::ManagedSurface();
surface->create(widthInBytes * 8 / 4, height, Graphics::PixelFormat::createFormatCLUT8());
surface->fillRect(Common::Rect(0, 0, widthInBytes * 8 / 4, height), 0);
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 0);
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 1);
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 2);
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 3);
return surface;
}
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanesInternalVertical(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, int plane) {
byte *colors = (byte *)malloc(sizeof(byte) * height * width);
file->read(colors, height * width);
for (int i = 0; i < height * width; i++) {
byte color = colors[i];
for (int n = 0; n < 8; n++) {
int y = i / width;
int x = (i % width) * 8 + (7 - n);
int bit = ((color >> n) & 0x01) << plane;
int sample = surface->getPixel(x, y) | bit;
assert(sample < 16);
surface->setPixel(x, y, sample);
}
}
free(colors);
return surface;
}
void CastleEngine::loadAssetsAmigaDemo() {
Common::File file;
file.open("x");
if (!file.isOpen())
error("Failed to open 'x' file");
_viewArea = Common::Rect(40, 29, 280, 154);
loadMessagesVariableSize(&file, 0x8bb2, 178);
loadRiddles(&file, 0x96c8 - 2 - 19 * 2, 19);
file.seek(0x11eec);
Common::Array<Graphics::ManagedSurface *> chars;
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *img = loadFrameFromPlanes(&file, 8, 8);
//Graphics::ManagedSurface *imgRiddle = new Graphics::ManagedSurface();
//imgRiddle->copyFrom(*img);
chars.push_back(img);
chars[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)kAmigaCastlePalette, 16);
//charsRiddle.push_back(imgRiddle);
//charsRiddle[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGARiddleFontPalette, 16);
}
// 0x1356c
_font = Font(chars);
_font.setCharWidth(9);
load8bitBinary(&file, 0x162a6, 16);
for (int i = 0; i < 3; i++) {
debugC(1, kFreescapeDebugParser, "Continue to parse area index %d at offset %x", _areaMap.size() + i + 1, (int)file.pos());
Area *newArea = load8bitArea(&file, 16);
if (newArea) {
if (!_areaMap.contains(newArea->getAreaID()))
_areaMap[newArea->getAreaID()] = newArea;
else
error("Repeated area ID: %d", newArea->getAreaID());
} else {
error("Invalid area %d?", i);
}
}
loadPalettes(&file, 0x151a6);
file.seek(0x2be96); // Area 255
_areaMap[255] = load8bitArea(&file, 16);
file.seek(0x2cf28 + 0x28 - 0x2 + 0x28);
_border = loadFrameFromPlanesVertical(&file, 160, 200);
_border->convertToInPlace(_gfx->_texturePixelFormat, (byte *)kAmigaCastlePalette, 16);
file.close();
_areaMap[2]->_groundColor = 1;
for (auto &it : _areaMap)
it._value->addStructure(_areaMap[255]);
}
void CastleEngine::drawAmigaAtariSTUI(Graphics::Surface *surface) {
drawStringInSurface(_currentArea->_name, 97, 182, 0, 0, surface);
}
} // End of namespace Freescape

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,164 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
namespace Freescape {
struct RiddleText {
int8 _dx;
int8 _dy;
Common::String _text;
RiddleText(int8 dx, int8 dy, const Common::String &text) : _dx(dx), _dy(dy), _text(text) {}
};
struct Riddle {
Common::Point _origin;
Common::Array<RiddleText> _lines;
};
class CastleEngine : public FreescapeEngine {
public:
CastleEngine(OSystem *syst, const ADGameDescription *gd);
~CastleEngine();
// Only in DOS
Graphics::ManagedSurface *_option;
Graphics::ManagedSurface *_menuButtons;
Graphics::ManagedSurface *_menuCrawlIndicator;
Graphics::ManagedSurface *_menuWalkIndicator;
Graphics::ManagedSurface *_menuRunIndicator;
Graphics::ManagedSurface *_menuFxOnIndicator;
Graphics::ManagedSurface *_menuFxOffIndicator;
Graphics::ManagedSurface *_menu;
void beforeStarting() override;
void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
void initGameState() override;
void endGame() override;
void drawInfoMenu() override;
void loadAssets() override;
void loadAssetsDOSFullGame() override;
void loadAssetsDOSDemo() override;
void loadAssetsAmigaDemo() override;
void loadAssetsZXFullGame() override;
void loadAssetsCPCFullGame() override;
void borderScreen() override;
void selectCharacterScreen();
void drawOption();
void initZX();
void initDOS();
void initCPC();
void drawDOSUI(Graphics::Surface *surface) override;
void drawZXUI(Graphics::Surface *surface) override;
void drawCPCUI(Graphics::Surface *surface) override;
void drawAmigaAtariSTUI(Graphics::Surface *surface) override;
void drawEnergyMeter(Graphics::Surface *surface, Common::Point origin);
void drawLiftingGate(Graphics::Surface *surface);
void drawDroppingGate(Graphics::Surface *surface);
void pressedKey(const int keycode) override;
void checkSensors() override;
void updateTimeVariables() override;
void drawBackground() override;
bool checkIfGameEnded() override;
void drawSensorShoot(Sensor *sensor) override;
void executePrint(FCLInstruction &instruction) override;
void executeDestroy(FCLInstruction &instruction) override;
void executeRedraw(FCLInstruction &instruction) override;
void gotoArea(uint16 areaID, int entranceID) override;
Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false) override;
Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override;
Common::Array<Riddle> _riddleList;
Common::BitArray _fontPlane1;
Common::BitArray _fontPlane2;
Common::BitArray _fontPlane3;
void drawRiddleStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface);
Graphics::ManagedSurface *loadFrameWithHeaderDOS(Common::SeekableReadStream *file);
Common::Array <Graphics::ManagedSurface *>loadFramesWithHeaderDOS(Common::SeekableReadStream *file, int numFrames);
Common::Array<Graphics::ManagedSurface *> loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 front, uint32 back);
Graphics::ManagedSurface *loadFrameWithHeader(Common::SeekableReadStream *file, int pos, uint32 front, uint32 back);
Graphics::ManagedSurface *loadFrame(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, uint32 back);
Graphics::ManagedSurface *loadFrameFromPlanes(Common::SeekableReadStream *file, int widthInBytes, int height);
Graphics::ManagedSurface *loadFrameFromPlanesInternal(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height);
Graphics::ManagedSurface *loadFrameFromPlanesVertical(Common::SeekableReadStream *file, int widthInBytes, int height);
Graphics::ManagedSurface *loadFrameFromPlanesInternalVertical(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, int plane);
Common::Array<Graphics::ManagedSurface *>_keysBorderFrames;
Common::Array<Graphics::ManagedSurface *>_keysMenuFrames;
Graphics::ManagedSurface *_spiritsMeterIndicatorBackgroundFrame;
Graphics::ManagedSurface *_spiritsMeterIndicatorFrame;
Graphics::ManagedSurface *_spiritsMeterIndicatorSideFrame;
Graphics::ManagedSurface *_strenghtBackgroundFrame;
Graphics::ManagedSurface *_strenghtBarFrame;
Common::Array<Graphics::ManagedSurface *> _strenghtWeightsFrames;
Common::Array<Graphics::ManagedSurface *> _flagFrames;
Common::Array<Graphics::ManagedSurface *> _thunderFrames;
Graphics::ManagedSurface *_riddleTopFrame;
Graphics::ManagedSurface *_riddleBackgroundFrame;
Graphics::ManagedSurface *_riddleBottomFrame;
Graphics::ManagedSurface *_endGameThroneFrame;
Graphics::ManagedSurface *_endGameBackgroundFrame;
Graphics::ManagedSurface *_gameOverBackgroundFrame;
Common::Array<int> _keysCollected;
bool _useRockTravel;
int _spiritsMeter;
int _spiritsMeterPosition;
int _spiritsMeterMax;
int _spiritsToKill;
int _lastTenSeconds;
int _soundIndexStartFalling;
private:
Common::SeekableReadStream *decryptFile(const Common::Path &filename);
void loadRiddles(Common::SeekableReadStream *file, int offset, int number);
void loadDOSFonts(Common::SeekableReadStream *file, int pos);
void drawFullscreenRiddleAndWait(uint16 riddle);
void drawFullscreenEndGameAndWait();
void drawFullscreenGameOverAndWait();
void drawRiddle(uint16 riddle, uint32 front, uint32 back, Graphics::Surface *surface);
void tryToCollectKey();
void addGhosts();
bool ghostInArea();
void updateThunder();
Audio::SoundHandle _soundFxGhostHandle;
Texture *_optionTexture;
Font _fontRiddle;
int _droppingGateStartTicks;
int _thunderTicks;
int _thunderFrameDuration;
Math::Vector3d _thunderOffset;
Common::Array<Texture *>_thunderTextures;
};
}

View File

@@ -0,0 +1,345 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "freescape/freescape.h"
#include "freescape/games/castle/castle.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void CastleEngine::initCPC() {
_viewArea = Common::Rect(40, 33 - 2, 280, 152);
_soundIndexShoot = 5;
_soundIndexCollide = -1;
_soundIndexFallen = -1;
_soundIndexStepUp = -1;
_soundIndexStepDown = -1;
_soundIndexMenu = -1;
_soundIndexStart = 6;
_soundIndexAreaChange = 7;
}
byte kCPCPaletteCastleTitleData[4][3] = {
{0x00, 0x00, 0x00},
{0x00, 0x00, 0xff},
{0xff, 0xff, 0x00},
{0xff, 0x00, 0x00},
};
byte kCPCPaletteCastleBorderData[4][3] = {
{0x00, 0x00, 0x00},
{0x80, 0x80, 0x80},
{0x00, 0x80, 0x00},
{0xff, 0xff, 0xff},
};
// Data for the mountains background. This is not included in the original game for some reason
// but all the other releases have it. This is coming from the ZX Spectrum version.
byte mountainsData[288] {
0x06, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b,
0x00, 0x00, 0x38, 0x01, 0xa0, 0x00, 0x00, 0x00,
0x00, 0x1e, 0x30, 0x00, 0x00, 0x00, 0x00, 0x17,
0x80, 0x00, 0x7c, 0x03, 0xd0, 0x00, 0x00, 0x01,
0x00, 0x3f, 0x5c, 0x80, 0x0, 0x18, 0x0, 0x23,
0xc0, 0x00, 0xfe, 0x0d, 0xfe, 0x6, 0x00, 0x02,
0x80, 0x7e, 0xbe, 0xc0, 0x0, 0x3c, 0x0, 0x47,
0xe0, 0x1, 0x57, 0x56, 0xff, 0xf, 0x80, 0x5,
0x40, 0xf5, 0xfb, 0x40, 0x0, 0x76, 0x0, 0x93,
0xd0, 0xa, 0xab, 0xab, 0xff, 0xaf, 0xc3, 0x2a,
0xa1, 0xeb, 0xfe, 0xa8, 0x0, 0xde, 0x0, 0x21,
0xa8, 0x75, 0x55, 0x41, 0xff, 0xd6, 0xef, 0xd5,
0x53, 0x57, 0xfc, 0x14, 0x1, 0xb7, 0x7, 0x42,
0xd5, 0xea, 0xaa, 0x92, 0xfb, 0xeb, 0xab, 0xea,
0xaa, 0xae, 0xfa, 0x4a, 0x82, 0xea, 0xbe, 0x97,
0xab, 0xd5, 0x55, 0x25, 0xdd, 0x75, 0x45, 0xf5,
0x55, 0x7d, 0xdd, 0x25, 0x55, 0xd5, 0x54, 0x2f,
0xf7, 0xaa, 0xaa, 0x53, 0xea, 0xa8, 0x13, 0xfa,
0xaa, 0xea, 0xbe, 0x42, 0xab, 0xaa, 0xa9, 0x5f,
0xdd, 0xd5, 0x55, 0x7, 0x55, 0x2, 0x45, 0xfd,
0x51, 0x55, 0x57, 0x15, 0x57, 0xd5, 0x52, 0xaf,
0xee, 0xfa, 0xaa, 0x2b, 0xaa, 0x80, 0x8b, 0xfe,
0xaa, 0xaa, 0xae, 0xaa, 0xbe, 0xaa, 0xa4, 0x5a,
0xb5, 0x5d, 0x5c, 0x56, 0xd5, 0x29, 0x1f, 0xff,
0x55, 0x55, 0x5b, 0x55, 0x7d, 0x55, 0x9, 0xb5,
0x5a, 0xaf, 0xba, 0xad, 0xaa, 0x92, 0x3e, 0xbf,
0xea, 0xaa, 0xaf, 0xab, 0xea, 0xaa, 0x2, 0x5a,
0xf5, 0x55, 0xfd, 0x57, 0x55, 0x5, 0x5f, 0x57,
0xfd, 0x55, 0x55, 0x57, 0x55, 0x50, 0x15, 0xaf,
0xba, 0xaa, 0xfe, 0xae, 0xfa, 0xaa, 0xbe, 0xaa,
0xbf, 0xaa, 0xaa, 0xaa, 0xaa, 0x82, 0xaa, 0x55,
0x55, 0x55, 0x5f, 0xd5, 0xfd, 0x55, 0x55, 0x55,
0x5f, 0xfd, 0x55, 0x55, 0x55, 0x55, 0x55, 0xea,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
extern Graphics::ManagedSurface *readCPCImage(Common::SeekableReadStream *file, bool mode0);
void CastleEngine::loadAssetsCPCFullGame() {
Common::File file;
uint8 r, g, b;
Common::Array<Graphics::ManagedSurface *> chars;
file.open("CMLOAD.BIN");
if (!file.isOpen())
error("Failed to open CMLOAD.BIN");
_title = readCPCImage(&file, true);
_title->setPalette((byte*)&kCPCPaletteCastleTitleData, 0, 4);
file.close();
file.open("CMSCR.BIN");
if (!file.isOpen())
error("Failed to open CMSCR.BIN");
_border = readCPCImage(&file, true);
_border->setPalette((byte*)&kCPCPaletteCastleBorderData, 0, 4);
file.close();
file.open("CM.BIN");
if (!file.isOpen())
error("Failed to open TECODE.BIN/TE2.BI2");
loadMessagesVariableSize(&file, 0x16c6, 71);
switch (_language) {
/*case Common::ES_ESP:
loadRiddles(&file, 0x1470 - 4 - 2 - 9 * 2, 9);
loadMessagesVariableSize(&file, 0xf3d, 71);
load8bitBinary(&file, 0x6aab - 2, 16);
loadSpeakerFxZX(&file, 0xca0, 0xcdc);
file.seek(0x1218 + 16);
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
}
_font = Font(chars);
_font.setCharWidth(9);
_fontLoaded = true;
break;*/
case Common::EN_ANY:
loadRiddles(&file, 0x1b75 - 2 - 9 * 2, 9);
load8bitBinary(&file, 0x791a, 16);
file.seek(0x2724);
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
}
_font = Font(chars);
_font.setCharWidth(9);
_fontLoaded = true;
break;
default:
error("Language not supported");
break;
}
loadColorPalette();
int backgroundWidth = 16;
int backgroundHeight = 18;
Graphics::ManagedSurface *background = new Graphics::ManagedSurface();
background->create(backgroundWidth * 8, backgroundHeight, _gfx->_texturePixelFormat);
background->fillRect(Common::Rect(0, 0, backgroundWidth * 8, backgroundHeight), 0);
Common::MemoryReadStream mountainsStream(mountainsData, sizeof(mountainsData));
_gfx->readFromPalette(11, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_background = loadFrame(&mountainsStream, background, backgroundWidth, backgroundHeight, front);
/*_gfx->readFromPalette(2, r, g, b);
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(7, r, g, b);
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_keysBorderFrames.push_back(loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xe06 : 0xdf7, red, white));
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
_spiritsMeterIndicatorFrame = loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xe5e : 0xe4f, green, white);
_gfx->readFromPalette(4, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int backgroundWidth = 16;
int backgroundHeight = 18;
Graphics::ManagedSurface *background = new Graphics::ManagedSurface();
background->create(backgroundWidth * 8, backgroundHeight, _gfx->_texturePixelFormat);
background->fillRect(Common::Rect(0, 0, backgroundWidth * 8, backgroundHeight), 0);
file.seek(_language == Common::ES_ESP ? 0xfd3 : 0xfc4);
_background = loadFrame(&file, background, backgroundWidth, backgroundHeight, front);
_gfx->readFromPalette(6, r, g, b);
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0, 0);
_strenghtBackgroundFrame = loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xee6 : 0xed7, yellow, black);
_strenghtBarFrame = loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xf72 : 0xf63, yellow, black);
Graphics::ManagedSurface *bar = new Graphics::ManagedSurface();
bar->create(_strenghtBarFrame->w - 4, _strenghtBarFrame->h, _gfx->_texturePixelFormat);
_strenghtBarFrame->copyRectToSurface(*bar, 4, 0, Common::Rect(4, 0, _strenghtBarFrame->w - 4, _strenghtBarFrame->h));
_strenghtBarFrame->free();
delete _strenghtBarFrame;
_strenghtBarFrame = bar;
_strenghtWeightsFrames = loadFramesWithHeader(&file, _language == Common::ES_ESP ? 0xf92 : 0xf83, 4, yellow, black);
_flagFrames = loadFramesWithHeader(&file, (_language == Common::ES_ESP ? 0x10e4 + 15 : 0x10e4), 4, green, black);
int thunderWidth = 4;
int thunderHeight = 43;
_thunderFrame = new Graphics::ManagedSurface();
_thunderFrame->create(thunderWidth * 8, thunderHeight, _gfx->_texturePixelFormat);
_thunderFrame->fillRect(Common::Rect(0, 0, thunderWidth * 8, thunderHeight), 0);
_thunderFrame = loadFrame(&file, _thunderFrame, thunderWidth, thunderHeight, front);
Graphics::Surface *tmp;
tmp = loadBundledImage("castle_riddle_top_frame");
_riddleTopFrame = new Graphics::ManagedSurface;
_riddleTopFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleTopFrame->convertToInPlace(_gfx->_texturePixelFormat);
tmp = loadBundledImage("castle_riddle_background_frame");
_riddleBackgroundFrame = new Graphics::ManagedSurface();
_riddleBackgroundFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat);
tmp = loadBundledImage("castle_riddle_bottom_frame");
_riddleBottomFrame = new Graphics::ManagedSurface();
_riddleBottomFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleBottomFrame->convertToInPlace(_gfx->_texturePixelFormat);*/
for (auto &it : _areaMap) {
it._value->addStructure(_areaMap[255]);
it._value->addObjectFromArea(164, _areaMap[255]);
it._value->addObjectFromArea(174, _areaMap[255]);
it._value->addObjectFromArea(175, _areaMap[255]);
for (int16 id = 136; id < 140; id++) {
it._value->addObjectFromArea(id, _areaMap[255]);
}
it._value->addObjectFromArea(195, _areaMap[255]);
for (int16 id = 214; id < 228; id++) {
it._value->addObjectFromArea(id, _areaMap[255]);
}
}
// Discard some global conditions
// It is unclear why they hide/unhide objects that formed the spirits
for (int i = 0; i < 3; i++) {
debugC(kFreescapeDebugParser, "Discarding condition %s", _conditionSources[0].c_str());
_conditions.remove_at(0);
_conditionSources.remove_at(0);
}
}
void CastleEngine::drawCPCUI(Graphics::Surface *surface) {
uint32 color = _gfx->_paperColor;
//uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = 1;
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
Common::Rect backRect(97, 181, 232, 190);
surface->fillRect(backRect, back);
Common::String message;
int deadline = -1;
getLatestMessages(message, deadline);
if (deadline > 0 && deadline <= _countdown) {
drawStringInSurface(message, 97, 182, front, back, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_gameStateControl == kFreescapeGameStatePlaying) {
drawStringInSurface(_currentArea->_name, 97, 182, front, back, surface);
}
}
/*uint32 color = 5;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = 0;
_gfx->readFromPalette(color, r, g, b);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
Common::Rect backRect(123, 179, 242 + 5, 188);
surface->fillRect(backRect, black);
Common::String message;
int deadline = -1;
getLatestMessages(message, deadline);
if (deadline > 0 && deadline <= _countdown) {
//debug("deadline: %d countdown: %d", deadline, _countdown);
drawStringInSurface(message, 120, 179, front, black, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_gameStateControl == kFreescapeGameStatePlaying) {
drawStringInSurface(_currentArea->_name, 120, 179, front, black, surface);
}
}
for (int k = 0; k < int(_keysCollected.size()); k++) {
surface->copyRectToSurface((const Graphics::Surface)*_keysBorderFrames[0], 99 - k * 4, 177, Common::Rect(0, 0, 6, 11));
}
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
surface->fillRect(Common::Rect(152, 156, 216, 164), green);
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorFrame, 140 + _spiritsMeterPosition, 156, Common::Rect(0, 0, 15, 8));
drawEnergyMeter(surface, Common::Point(63, 154));
int ticks = g_system->getMillis() / 20;
int flagFrameIndex = (ticks / 10) % 4;
surface->copyRectToSurface(*_flagFrames[flagFrameIndex], 264, 9, Common::Rect(0, 0, _flagFrames[flagFrameIndex]->w, _flagFrames[flagFrameIndex]->h));*/
}
} // End of namespace Freescape

View File

@@ -0,0 +1,476 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "freescape/freescape.h"
#include "freescape/games/castle/castle.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
Common::SeekableReadStream *CastleEngine::decryptFile(const Common::Path &filename) {
Common::File file;
file.open(filename);
if (!file.isOpen())
error("Failed to open %s", filename.toString().c_str());
int size = file.size();
byte *encryptedBuffer = (byte *)malloc(size);
file.read(encryptedBuffer, size);
file.close();
int seed = 24;
for (int i = 0; i < size; i++) {
if (i > 1)
encryptedBuffer[i] ^= seed;
seed = (seed + 1) & 0xff;
}
return (new Common::MemoryReadStream(encryptedBuffer, size));
}
extern byte kEGADefaultPalette[16][3];
extern Common::MemoryReadStream *unpackEXE(Common::File &ms);
byte kEGARiddleFontPalette[16][3] = {
{0x00, 0x00, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00}
};
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanes(Common::SeekableReadStream *file, int widthInBytes, int height) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(widthInBytes * 8 / 4, height, Graphics::PixelFormat::createFormatCLUT8());
surface->fillRect(Common::Rect(0, 0, widthInBytes * 8 / 4, height), 0);
loadFrameFromPlanesInternal(file, surface, widthInBytes, height);
return surface;
}
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanesInternal(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height) {
byte *colors = (byte *)malloc(sizeof(byte) * height * width);
file->read(colors, height * width);
for (int p = 0; p < 4; p++) {
for (int i = 0; i < height * width; i++) {
byte color = colors[i];
for (int n = 0; n < 8; n++) {
int y = i / width;
int x = (i % width) * 8 + (7 - n);
// Check that we are in the right plane
if (x < width * (8 / 4) * p || x >= width * (8 / 4) * (p + 1))
continue;
int bit = ((color >> n) & 0x01) << p;
int sample = surface->getPixel(x % (width * 8 / 4), y) | bit;
assert(sample < 16);
surface->setPixel(x % (width * 8 / 4), y, sample);
}
}
}
return surface;
}
Common::Array <Graphics::ManagedSurface *>CastleEngine::loadFramesWithHeaderDOS(Common::SeekableReadStream *file, int numFrames) {
uint8 header1 = file->readByte();
uint8 header2 = file->readByte();
int height = file->readByte();
uint8 mask = file->readByte();
int size = file->readUint16LE();
assert(size % height == 0);
int widthBytes = (size / height);
Common::Array<Graphics::ManagedSurface *> frames;
for (int i = 0; i < numFrames; i++) {
Graphics::ManagedSurface *frame = loadFrameFromPlanes(file, widthBytes, height);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
frames.push_back(frame);
}
debug("header: %x %x, height: %d, mask: %x, widthBytes: %d, size: %d", header1, header2, height, mask, widthBytes, size);
return frames;
}
Graphics::ManagedSurface *CastleEngine::loadFrameWithHeaderDOS(Common::SeekableReadStream *file) {
uint8 header1 = file->readByte();
uint8 header2 = file->readByte();
int height = file->readByte();
uint8 mask = file->readByte();
int size = file->readUint16LE();
assert(size % height == 0);
int widthBytes = (size / height);
Graphics::ManagedSurface *frame = loadFrameFromPlanes(file, widthBytes, height);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
debug("header: %x %x, height: %d, mask: %x, widthBytes: %d, size: %d", header1, header2, height, mask, widthBytes, size);
debug("pos: %x", (int32)file->pos());
return frame;
}
void CastleEngine::initDOS() {
_viewArea = Common::Rect(40, 33 - 2, 280, 152);
}
void CastleEngine::loadAssetsDOSFullGame() {
Common::File file;
Common::SeekableReadStream *stream = nullptr;
if (_renderMode == Common::kRenderEGA) {
file.open("CME.EXE");
stream = unpackEXE(file);
if (stream) {
loadSpeakerFxDOS(stream, 0x636d + 0x200, 0x63ed + 0x200, 30);
stream->seek(0x197c0);
_endGameBackgroundFrame = loadFrameFromPlanes(stream, 112, 108);
_endGameBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_background = loadFrameFromPlanes(stream, 504, 18);
_background->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
debug("%x", (int32)stream->pos());
// Eye widget is next to 0x1f058
stream->seek(0x1f4e3);
for (int i = 0; i < 6; i++)
debug("i: %d -> %x", i, stream->readByte());
debug("%x", (int32)stream->pos());
debug("extra: %x", stream->readByte());
for (int i = 0; i < 10; i++) {
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_keysBorderFrames.push_back(frame);
}
for (int i = 0; i < 10; i++) {
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_keysMenuFrames.push_back(frame);
}
//for (int i = 0; i < 6; i++)
// debug("i: %d -> %x", i, stream->readByte());
//loadFrameWithHeaderDOS(stream);
//debug("%lx", stream->pos());
//assert(0);
stream->seek(0x20262);
_strenghtBackgroundFrame = loadFrameWithHeaderDOS(stream);
_strenghtBarFrame = loadFrameWithHeaderDOS(stream);
_strenghtWeightsFrames = loadFramesWithHeaderDOS(stream, 4);
_spiritsMeterIndicatorBackgroundFrame = loadFrameWithHeaderDOS(stream);
_spiritsMeterIndicatorFrame = loadFrameWithHeaderDOS(stream);
_spiritsMeterIndicatorSideFrame = loadFrameWithHeaderDOS(stream); // side
loadFrameWithHeaderDOS(stream); // ???
/*for (int i = 0; i < 6; i++)
debug("i: %d -> %x", i, stream->readByte());
debug("%lx", stream->pos());*/
//assert(0);
stream->seek(0x221ae);
// No header?
_menu = loadFrameFromPlanes(stream, 112, 115);
_menu->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
Common::Array <Graphics::ManagedSurface *> menuFrames = loadFramesWithHeaderDOS(stream, 5);
_menuCrawlIndicator = menuFrames[0];
_menuWalkIndicator = menuFrames[1];
_menuRunIndicator = menuFrames[2];
_menuFxOffIndicator = menuFrames[3];
_menuFxOnIndicator = menuFrames[4];
_flagFrames = loadFramesWithHeaderDOS(stream, 4);
_riddleTopFrame = loadFrameWithHeaderDOS(stream);
_riddleBackgroundFrame = loadFrameWithHeaderDOS(stream);
_riddleBottomFrame = loadFrameWithHeaderDOS(stream);
_endGameThroneFrame = loadFrameWithHeaderDOS(stream);
// No header
Graphics::ManagedSurface *thunderFrame = loadFrameFromPlanes(stream, 32, 128);
thunderFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_thunderFrames.push_back(thunderFrame);
stream->seek(0x29696);
Common::Array<Graphics::ManagedSurface *> chars;
Common::Array<Graphics::ManagedSurface *> charsRiddle;
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *img = loadFrameFromPlanes(stream, 8, 8);
Graphics::ManagedSurface *imgRiddle = new Graphics::ManagedSurface();
imgRiddle->copyFrom(*img);
chars.push_back(img);
chars[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
charsRiddle.push_back(imgRiddle);
charsRiddle[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGARiddleFontPalette, 16);
}
_font = Font(chars);
_font.setCharWidth(9);
_fontRiddle = Font(charsRiddle);
_fontRiddle.setCharWidth(9);
_fontLoaded = true;
}
delete stream;
file.close();
file.open("CMLE.DAT");
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
file.open("CMOE.DAT");
_option = load8bitBinImage(&file, 0x0);
_option->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
file.open("CME.DAT");
_border = load8bitBinImage(&file, 0x0);
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
switch (_language) {
case Common::ES_ESP:
stream = decryptFile("CMLS");
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
// Fixes for incorrect or wrong translations
Common::replace(_riddleList[16]._lines[5]._text, "IN", "EN");
break;
case Common::FR_FRA:
stream = decryptFile("CMLF");
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
break;
case Common::DE_DEU:
stream = decryptFile("CMLG");
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
break;
case Common::EN_ANY:
stream = decryptFile("CMLE");
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
break;
default:
error("Invalid or unsupported language: %x", _language);
}
loadMessagesVariableSize(stream, 0x11, 164);
delete stream;
stream = decryptFile("CMEDF");
load8bitBinary(stream, 0, 16);
delete stream;
} else
error("Not implemented yet");
// CPC
// file = gameDir.createReadStreamForMember("cm.bin");
// if (file == nullptr)
// error("Failed to open cm.bin");
// load8bitBinary(file, 0x791a, 16);
}
void CastleEngine::loadAssetsDOSDemo() {
Common::File file;
Common::SeekableReadStream *stream = nullptr;
if (_renderMode == Common::kRenderEGA) {
file.open("CMDE.EXE");
stream = unpackEXE(file);
if (stream) {
loadSpeakerFxDOS(stream, 0x636d + 0x200, 0x63ed + 0x200, 30);
stream->seek(0x197c0 - 0x2a0);
_endGameBackgroundFrame = loadFrameFromPlanes(stream, 112, 108);
_endGameBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_background = loadFrameFromPlanes(stream, 504, 18);
_background->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
stream->seek(0x1f4e3 - 0x2a0);
for (int i = 0; i < 6; i++)
debug("i: %d -> %x", i, stream->readByte());
debug("%x", (int32)stream->pos());
debug("extra: %x", stream->readByte());
for (int i = 0; i < 9; i++) {
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_keysBorderFrames.push_back(frame);
}
for (int i = 0; i < 11; i++) {
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_keysMenuFrames.push_back(frame);
}
stream->seek(0x20262 - 0x2a0);
_strenghtBackgroundFrame = loadFrameWithHeaderDOS(stream);
_strenghtBarFrame = loadFrameWithHeaderDOS(stream);
_strenghtWeightsFrames = loadFramesWithHeaderDOS(stream, 4);
_spiritsMeterIndicatorBackgroundFrame = loadFrameWithHeaderDOS(stream);
_spiritsMeterIndicatorFrame = loadFrameWithHeaderDOS(stream);
_spiritsMeterIndicatorSideFrame = loadFrameWithHeaderDOS(stream); // side
loadFrameWithHeaderDOS(stream); // ???
stream->seek(0x221ae - 0x2a0);
// No header?
_menu = loadFrameFromPlanes(stream, 112, 115);
_menu->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
Common::Array <Graphics::ManagedSurface *> menuFrames = loadFramesWithHeaderDOS(stream, 5);
_menuCrawlIndicator = menuFrames[0];
_menuWalkIndicator = menuFrames[1];
_menuRunIndicator = menuFrames[2];
_menuFxOffIndicator = menuFrames[3];
_menuFxOnIndicator = menuFrames[4];
_flagFrames = loadFramesWithHeaderDOS(stream, 4);
_riddleTopFrame = loadFrameWithHeaderDOS(stream);
_riddleBackgroundFrame = loadFrameWithHeaderDOS(stream);
_riddleBottomFrame = loadFrameWithHeaderDOS(stream);
_endGameThroneFrame = loadFrameWithHeaderDOS(stream);
// No header
Graphics::ManagedSurface *thunderFrame = loadFrameFromPlanes(stream, 32, 128);
thunderFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_thunderFrames.push_back(thunderFrame);
stream->seek(0x293f6); // TODO: check this
Common::Array<Graphics::ManagedSurface *> chars;
Common::Array<Graphics::ManagedSurface *> charsRiddle;
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *img = loadFrameFromPlanes(stream, 8, 8);
Graphics::ManagedSurface *imgRiddle = new Graphics::ManagedSurface();
imgRiddle->copyFrom(*img);
chars.push_back(img);
chars[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
charsRiddle.push_back(imgRiddle);
charsRiddle[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGARiddleFontPalette, 16);
}
_font = Font(chars);
_font.setCharWidth(9);
_fontRiddle = Font(charsRiddle);
_fontRiddle.setCharWidth(9);
_fontLoaded = true;
}
delete stream;
file.close();
file.open("CMLE.DAT");
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
file.open("CMOE.DAT");
_option = load8bitBinImage(&file, 0x0);
_option->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
file.open("CME.DAT");
_border = load8bitBinImage(&file, 0x0);
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
stream = decryptFile("CMLD"); // Only english
loadMessagesVariableSize(stream, 0x11, 164);
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
delete stream;
stream = decryptFile("CDEDF");
load8bitBinary(stream, 0, 16);
delete stream;
} else
error("Not implemented yet");
}
void CastleEngine::drawDOSUI(Graphics::Surface *surface) {
uint32 color = 10;
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
uint8 r, g, b;
drawLiftingGate(surface);
drawDroppingGate(surface);
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = 0;
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
Common::Rect backRect(97, 181, 232, 190);
surface->fillRect(backRect, back);
Common::String message;
int deadline = -1;
getLatestMessages(message, deadline);
if (deadline > 0 && deadline <= _countdown) {
drawStringInSurface(message, 97, 182, front, back, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_gameStateControl != kFreescapeGameStateEnd) {
if (ghostInArea())
drawStringInSurface(_messagesList[116], 97, 182, front, back, surface);
else
drawStringInSurface(_currentArea->_name, 97, 182, front, back, surface);
}
}
for (int k = 0; k < int(_keysCollected.size()); k++) {
surface->copyRectToSurfaceWithKey((const Graphics::Surface)*_keysBorderFrames[k], 76 - k * 3, 179, Common::Rect(0, 0, 6, 14), black);
}
drawEnergyMeter(surface, Common::Point(38, 158));
int flagFrameIndex = (_ticks / 10) % 4;
surface->copyRectToSurface(*_flagFrames[flagFrameIndex], 285, 5, Common::Rect(0, 0, _flagFrames[flagFrameIndex]->w, _flagFrames[flagFrameIndex]->h));
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorBackgroundFrame, 136, 162, Common::Rect(0, 0, _spiritsMeterIndicatorBackgroundFrame->w, _spiritsMeterIndicatorBackgroundFrame->h));
surface->copyRectToSurfaceWithKey((const Graphics::Surface)*_spiritsMeterIndicatorFrame, 125 + 6 + _spiritsMeterPosition, 161, Common::Rect(0, 0, _spiritsMeterIndicatorFrame->w, _spiritsMeterIndicatorFrame->h), black);
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorSideFrame, 122 + 5 + 1, 157 + 5 - 1, Common::Rect(0, 0, _spiritsMeterIndicatorSideFrame->w / 2, _spiritsMeterIndicatorSideFrame->h));
//surface->copyRectToSurface(*_spiritsMeterIndicatorFrame, 100, 50, Common::Rect(0, 0, _spiritsMeterIndicatorFrame->w, _spiritsMeterIndicatorFrame->h));
}
} // End of namespace Freescape

View File

@@ -0,0 +1,286 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/castle/castle.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void CastleEngine::initZX() {
_viewArea = Common::Rect(64, 36, 256, 148);
_soundIndexShoot = 5;
_soundIndexCollide = 3;
_soundIndexStartFalling = -1;
_soundIndexFallen = 1;
_soundIndexFall = 6;
_soundIndexStepUp = 12;
_soundIndexStepDown = 12;
_soundIndexMenu = 3;
_soundIndexStart = 7;
_soundIndexAreaChange = 7;
}
Graphics::ManagedSurface *CastleEngine::loadFrameWithHeader(Common::SeekableReadStream *file, int pos, uint32 front, uint32 back) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
file->seek(pos);
int16 width = file->readByte();
int16 height = file->readByte();
debugC(kFreescapeDebugParser, "Frame size: %d x %d", width, height);
surface->create(width * 8, height, _gfx->_texturePixelFormat);
/*byte mask =*/ file->readByte();
surface->fillRect(Common::Rect(0, 0, width * 8, height), back);
/*int frameSize =*/ file->readUint16LE();
return loadFrame(file, surface, width, height, front);
}
Common::Array<Graphics::ManagedSurface *> CastleEngine::loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 front, uint32 back) {
Graphics::ManagedSurface *surface = nullptr;
file->seek(pos);
int16 width = file->readByte();
int16 height = file->readByte();
/*byte mask =*/ file->readByte();
/*int frameSize =*/ file->readUint16LE();
Common::Array<Graphics::ManagedSurface *> frames;
for (int i = 0; i < numFrames; i++) {
surface = new Graphics::ManagedSurface();
surface->create(width * 8, height, _gfx->_texturePixelFormat);
surface->fillRect(Common::Rect(0, 0, width * 8, height), back);
frames.push_back(loadFrame(file, surface, width, height, front));
}
return frames;
}
Graphics::ManagedSurface *CastleEngine::loadFrame(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, uint32 front) {
for (int i = 0; i < width * height; i++) {
byte color = file->readByte();
for (int n = 0; n < 8; n++) {
int y = i / width;
int x = (i % width) * 8 + (7 - n);
if ((color & (1 << n)))
surface->setPixel(x, y, front);
}
}
return surface;
}
void CastleEngine::loadAssetsZXFullGame() {
Common::File file;
uint8 r, g, b;
Common::Array<Graphics::ManagedSurface *> chars;
file.open("castlemaster.zx.title");
if (file.isOpen()) {
_title = loadAndConvertScrImage(&file);
} else
error("Unable to find castlemaster.zx.title");
file.close();
file.open("castlemaster.zx.border");
if (file.isOpen()) {
_border = loadAndConvertScrImage(&file);
} else
error("Unable to find castlemaster.zx.border");
file.close();
file.open("castlemaster.zx.data");
if (!file.isOpen())
error("Failed to open castlemaster.zx.data");
loadMessagesVariableSize(&file, 0x4bd, 71);
switch (_language) {
case Common::ES_ESP:
loadRiddles(&file, 0x1458, 9);
load8bitBinary(&file, 0x6aa9, 16);
loadSpeakerFxZX(&file, 0xca0, 0xcdc);
file.seek(0x1228);
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
}
_font = Font(chars);
_font.setCharWidth(9);
_fontLoaded = true;
break;
case Common::EN_ANY:
if (_variant & GF_ZX_RETAIL) {
loadRiddles(&file, 0x1448, 9);
load8bitBinary(&file, 0x6a3b, 16);
loadSpeakerFxZX(&file, 0xc91, 0xccd);
file.seek(0x1219);
} else if (_variant & GF_ZX_DISC) {
loadRiddles(&file, 0x1457, 9);
load8bitBinary(&file, 0x6a9b, 16);
loadSpeakerFxZX(&file, 0xca0, 0xcdc);
file.seek(0x1228);
} else {
error("Unknown Castle Master ZX variant");
}
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
}
_font = Font(chars);
_font.setCharWidth(9);
_fontLoaded = true;
break;
default:
error("Language not supported");
break;
}
loadColorPalette();
_gfx->readFromPalette(2, r, g, b);
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(7, r, g, b);
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_keysBorderFrames.push_back(loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xe06 : 0xdf7, red, white));
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
_spiritsMeterIndicatorFrame = loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xe5e : 0xe4f, green, white);
_gfx->readFromPalette(4, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int backgroundWidth = 16;
int backgroundHeight = 18;
Graphics::ManagedSurface *background = new Graphics::ManagedSurface();
background->create(backgroundWidth * 8, backgroundHeight, _gfx->_texturePixelFormat);
background->fillRect(Common::Rect(0, 0, backgroundWidth * 8, backgroundHeight), 0);
file.seek(_variant & GF_ZX_DISC ? 0xfd3 : 0xfc4);
_background = loadFrame(&file, background, backgroundWidth, backgroundHeight, front);
_gfx->readFromPalette(6, r, g, b);
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0, 0);
_strenghtBackgroundFrame = loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xee6 : 0xed7, yellow, black);
_strenghtBarFrame = loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xf72 : 0xf63, yellow, black);
_strenghtWeightsFrames = loadFramesWithHeader(&file, _variant & GF_ZX_DISC ? 0xf92 : 0xf83, 4, yellow, black);
_flagFrames = loadFramesWithHeader(&file, (_variant & GF_ZX_DISC ? 0x10e4 + 15 : 0x10e4), 4, green, black);
file.skip(24);
int thunderWidth = 4;
int thunderHeight = 44;
Graphics::ManagedSurface *thunderFrame = new Graphics::ManagedSurface();
thunderFrame->create(thunderWidth * 8, thunderHeight, _gfx->_texturePixelFormat);
thunderFrame->fillRect(Common::Rect(0, 0, thunderWidth * 8, thunderHeight), 0);
thunderFrame = loadFrame(&file, thunderFrame, thunderWidth, thunderHeight, front);
_thunderFrames.push_back(new Graphics::ManagedSurface);
_thunderFrames.push_back(new Graphics::ManagedSurface);
_thunderFrames[0]->create(thunderWidth * 8 / 2, thunderHeight, _gfx->_texturePixelFormat);
_thunderFrames[1]->create(thunderWidth * 8 / 2, thunderHeight, _gfx->_texturePixelFormat);
_thunderFrames[0]->copyRectToSurface(*thunderFrame, 0, 0, Common::Rect(0, 0, thunderWidth * 8 / 2, thunderHeight));
_thunderFrames[1]->copyRectToSurface(*thunderFrame, 0, 0, Common::Rect(thunderWidth * 8 / 2, 0, thunderWidth * 8, thunderHeight));
Graphics::Surface *tmp;
tmp = loadBundledImage("castle_riddle_top_frame");
_riddleTopFrame = new Graphics::ManagedSurface;
_riddleTopFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleTopFrame->convertToInPlace(_gfx->_texturePixelFormat);
tmp = loadBundledImage("castle_riddle_background_frame");
_riddleBackgroundFrame = new Graphics::ManagedSurface();
_riddleBackgroundFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat);
tmp = loadBundledImage("castle_riddle_bottom_frame");
_riddleBottomFrame = new Graphics::ManagedSurface();
_riddleBottomFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleBottomFrame->convertToInPlace(_gfx->_texturePixelFormat);
}
void CastleEngine::drawZXUI(Graphics::Surface *surface) {
uint32 color = 5;
uint8 r, g, b;
drawLiftingGate(surface);
drawDroppingGate(surface);
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = 0;
_gfx->readFromPalette(color, r, g, b);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
Common::Rect backRect(123, 179, 242 + 5, 188);
surface->fillRect(backRect, black);
Common::String message;
int deadline = -1;
getLatestMessages(message, deadline);
if (deadline > 0 && deadline <= _countdown) {
//debug("deadline: %d countdown: %d", deadline, _countdown);
drawStringInSurface(message, 120, 179, front, black, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_gameStateControl != kFreescapeGameStateEnd) {
if (getGameBit(31)) { // The final cutscene is playing but it is not ended yet
drawStringInSurface(_messagesList[5], 120, 179, front, black, surface); // "You did it!"
} else
drawStringInSurface(_currentArea->_name, 120, 179, front, black, surface);
}
}
for (int k = 0; k < int(_keysCollected.size()); k++) {
surface->copyRectToSurface((const Graphics::Surface)*_keysBorderFrames[0], 99 - k * 4, 177, Common::Rect(0, 0, 6, 11));
}
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
surface->fillRect(Common::Rect(152, 156, 216, 164), green);
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorFrame, 140 + _spiritsMeterPosition, 156, Common::Rect(0, 0, 15, 8));
surface->fillRect(Common::Rect(64, 155, 64 + 72, 155 + 15), _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00));
drawEnergyMeter(surface, Common::Point(64, 155));
int ticks = g_system->getMillis() / 20;
int flagFrameIndex = (ticks / 10) % 4;
surface->copyRectToSurface(*_flagFrames[flagFrameIndex], 264, 9, Common::Rect(0, 0, _flagFrames[flagFrameIndex]->w, _flagFrames[flagFrameIndex]->h));
}
} // End of namespace Freescape

View File

@@ -0,0 +1,170 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/dark/dark.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void DarkEngine::loadAssetsAmigaFullGame() {
Common::File file;
file.open("0.drk");
_title = loadAndConvertNeoImage(&file, 0x9930);
file.close();
Common::SeekableReadStream *stream = decryptFileAmigaAtari("1.drk", "0.drk", 798);
parseAmigaAtariHeader(stream);
_border = loadAndConvertNeoImage(stream, 0x1b762);
load8bitBinary(stream, 0x2e96a, 16);
loadPalettes(stream, 0x2e528);
loadGlobalObjects(stream, 0x30f0 - 50, 24);
loadMessagesVariableSize(stream, 0x3d37, 66);
loadSoundsFx(stream, 0x34738 + 2, 11);
Common::Array<Graphics::ManagedSurface *> chars;
chars = getCharsAmigaAtariInternal(8, 8, - 7 - 8, 16, 16, stream, 0x1b0bc, 85);
_fontBig = Font(chars);
chars = getCharsAmigaAtariInternal(8, 8, 0, 10, 8, stream, 0x1b0bc + 0x430, 85);
_fontMedium = Font(chars);
chars = getCharsAmigaAtariInternal(8, 5, - 7 - 8, 10, 16, stream, 0x1b0bc + 0x430, 85);
_fontSmall = Font(chars);
_fontSmall.setCharWidth(4);
_fontLoaded = true;
GeometricObject *obj = nullptr;
obj = (GeometricObject *)_areaMap[15]->objectWithID(18);
assert(obj);
obj->_cyclingColors = true;
obj = (GeometricObject *)_areaMap[15]->objectWithID(26);
assert(obj);
obj->_cyclingColors = true;
for (int i = 0; i < 3; i++) {
int16 id = 227 + i * 6 - 2;
for (int j = 0; j < 2; j++) {
//debugC(1, kFreescapeDebugParser, "Restoring object %d to from ECD %d", id, index);
obj = (GeometricObject *)_areaMap[255]->objectWithID(id);
assert(obj);
obj->_cyclingColors = true;
id--;
}
}
for (auto &area : _areaMap) {
// Center and pad each area name so we do not have to do it at each frame
area._value->_name = centerAndPadString(area._value->_name, 26);
}
}
void DarkEngine::drawAmigaAtariSTUI(Graphics::Surface *surface) {
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0xFF);
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xEE, 0xCC, 0x00);
uint32 orange = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xEE, 0x88, 0x00);
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xEE, 0x00, 0x00);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
uint32 transparent = _gfx->_texturePixelFormat.ARGBToColor(0x00, 0x00, 0x00, 0x00);
uint32 grey = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x60, 0x60, 0x60);
uint32 grey8 = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x88, 0x88, 0x88);
uint32 greyA = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xAA, 0xAA, 0xAA);
int score = _gameStateVars[k8bitVariableScore];
int ecds = _gameStateVars[kVariableActiveECDs];
drawString(kDarkFontSmall, Common::String::format("%04d", int(2 * _position.x())), 19, 178, red, red, black, surface);
drawString(kDarkFontSmall, Common::String::format("%04d", int(2 * _position.z())), 19, 184, red, red, black, surface);
drawString(kDarkFontSmall, Common::String::format("%04d", int(2 * _position.y())), 19, 190, red, red, black, surface);
drawString(kDarkFontBig, Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 73, 178, red, red, black, surface);
drawString(kDarkFontBig, Common::String::format("%3d", _playerSteps[_playerStepIndex]), 73, 186, red, red, black, surface);
drawString(kDarkFontBig, Common::String::format("%07d", score), 93, 16, orange, yellow, black, surface);
drawString(kDarkFontBig, Common::String::format("%3d%%", ecds), 181, 16, orange, yellow, black, surface);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawString(kDarkFontSmall, message, 32, 157, grey8, greyA, transparent, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
}
drawString(kDarkFontSmall, _currentArea->_name, 32, 151, grey8, greyA, transparent, surface);
drawBinaryClock(surface, 6, 110, white, grey);
int x = 229;
int y = 180;
for (int i = 0; i < _maxShield / 2; i++) {
if (i < _gameStateVars[k8bitVariableShield] / 2) {
surface->drawLine(x, y, x, y + 3, orange);
surface->drawLine(x, y + 1, x, y + 2, yellow);
} else
surface->drawLine(x, y, x, y + 3, red);
x += 2;
}
x = 229;
y = 188;
for (int i = 0; i < _maxEnergy / 2; i++) {
if (i < _gameStateVars[k8bitVariableEnergy] / 2) {
surface->drawLine(x, y, x, y + 3, orange);
surface->drawLine(x, y + 1, x, y + 2, yellow);
} else
surface->drawLine(x, y, x, y + 3, red);
x += 2;
}
}
void DarkEngine::initAmigaAtari() {
_viewArea = Common::Rect(32, 33, 287, 130);
}
void DarkEngine::drawString(const DarkFontSize size, const Common::String &str, int x, int y, uint32 primaryColor, uint32 secondaryColor, uint32 backColor, Graphics::Surface *surface) {
if (!_fontLoaded)
return;
Font *font = nullptr;
if (size == kDarkFontBig) {
font = &_fontBig;
} else if (size == kDarkFontMedium) {
font = &_fontMedium;
} else if (size == kDarkFontSmall) {
font = &_fontSmall;
} else {
error("Invalid font size %d", size);
return;
}
Common::String ustr = str;
ustr.toUppercase();
font->setBackground(backColor);
font->setSecondaryColor(secondaryColor);
font->drawString(surface, ustr, x, y, _screenW, primaryColor);
}
} // End of namespace Freescape

View File

@@ -0,0 +1,84 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/dark/dark.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void DarkEngine::loadAssetsAtariFullGame() {
Common::File file;
file.open("0.drk");
_title = loadAndConvertNeoImage(&file, 0x13ec);
file.close();
Common::SeekableReadStream *stream = decryptFileAmigaAtari("1.drk", "0.drk", 840);
parseAmigaAtariHeader(stream);
_border = loadAndConvertNeoImage(stream, 0xd710);
Common::Array<Graphics::ManagedSurface *> chars;
chars = getCharsAmigaAtariInternal(8, 8, - 7 - 8, 16, 16, stream, 0xd06a, 85);
_fontBig = Font(chars);
chars = getCharsAmigaAtariInternal(8, 8, 0, 10, 8, stream, 0xd49a, 85);
_fontMedium = Font(chars);
chars = getCharsAmigaAtariInternal(8, 5, - 7 - 8, 10, 16, stream, 0xd49a, 85);
_fontSmall = Font(chars);
_fontSmall.setCharWidth(4);
_fontLoaded = true;
load8bitBinary(stream, 0x20918, 16);
loadMessagesVariableSize(stream, 0x3f6f, 66);
loadPalettes(stream, 0x204d6);
loadGlobalObjects(stream, 0x32f6, 24);
loadSoundsFx(stream, 0x266e8, 11);
GeometricObject *obj = nullptr;
obj = (GeometricObject *)_areaMap[15]->objectWithID(18);
assert(obj);
obj->_cyclingColors = true;
obj = (GeometricObject *)_areaMap[15]->objectWithID(26);
assert(obj);
obj->_cyclingColors = true;
for (int i = 0; i < 3; i++) {
int16 id = 227 + i * 6 - 2;
for (int j = 0; j < 2; j++) {
//debugC(1, kFreescapeDebugParser, "Restoring object %d to from ECD %d", id, index);
obj = (GeometricObject *)_areaMap[255]->objectWithID(id);
assert(obj);
obj->_cyclingColors = true;
id--;
}
}
for (auto &area : _areaMap) {
// Center and pad each area name so we do not have to do it at each frame
area._value->_name = centerAndPadString(area._value->_name, 26);
}
}
} // End of namespace Freescape

View File

@@ -0,0 +1,249 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "freescape/freescape.h"
#include "freescape/games/dark/dark.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void DarkEngine::initC64() {
_viewArea = Common::Rect(32, 24, 288, 127);
}
extern byte kC64Palette[16][3];
void DarkEngine::loadAssetsC64FullGame() {
Common::File file;
file.open("darkside.c64.data");
if (_variant & GF_C64_TAPE) {
int size = file.size();
byte *buffer = (byte *)malloc(size * sizeof(byte));
file.read(buffer, file.size());
_extraBuffer = decompressC64RLE(buffer, &size, 0xdf);
// size should be the size of the decompressed data
Common::MemoryReadStream dfile(_extraBuffer, size, DisposeAfterUse::NO);
loadMessagesFixedSize(&dfile, 0x1edf, 16, 27);
loadFonts(&dfile, 0xc3e);
loadGlobalObjects(&dfile, 0x20bd, 23);
load8bitBinary(&dfile, 0x9b3e, 16);
} else if (_variant & GF_C64_DISC) {
loadMessagesFixedSize(&file, 0x16a3, 16, 27);
loadFonts(&file, 0x402);
// It is unclear why this C64 has this byte changed at 0x1881
// Once the game is loaded, it will be set to 0x66
// and the game will work
file.seek(0x1881);
_extraBuffer = (byte *)malloc(0x300 * sizeof(byte));
file.read(_extraBuffer, 0x300);
_extraBuffer[0] = 0x66;
Common::MemoryReadStream stream(_extraBuffer, 0x300, DisposeAfterUse::NO);
loadGlobalObjects(&stream, 0x0, 23);
load8bitBinary(&file, 0x8914, 16);
} else
error("Unknown C64 variant %x", _variant);
// The color map from the data is not correct,
// so we'll just hardcode the one that we found in the executable
for (int i = 0; i < 15; i++) {
_colorMap[i][0] = 0;
_colorMap[i][1] = 0;
_colorMap[i][2] = 0;
_colorMap[i][3] = 0;
}
_colorMap[1][0] = 0x55;
_colorMap[1][1] = 0x55;
_colorMap[1][2] = 0x55;
_colorMap[1][3] = 0x55;
_colorMap[2][0] = 0xaa;
_colorMap[2][1] = 0xaa;
_colorMap[2][2] = 0xaa;
_colorMap[2][3] = 0xaa;
_colorMap[3][0] = 0xff;
_colorMap[3][1] = 0xff;
_colorMap[3][2] = 0xff;
_colorMap[3][3] = 0xff;
_colorMap[4][0] = 0x44;
_colorMap[4][1] = 0x11;
_colorMap[4][2] = 0x44;
_colorMap[4][3] = 0x11;
_colorMap[5][0] = 0x88;
_colorMap[5][1] = 0x22;
_colorMap[5][2] = 0x88;
_colorMap[5][3] = 0x22;
_colorMap[6][0] = 0xcc;
_colorMap[6][1] = 0x33;
_colorMap[6][2] = 0xcc;
_colorMap[6][3] = 0x33;
_colorMap[7][0] = 0x66;
_colorMap[7][1] = 0x99;
_colorMap[7][2] = 0x66;
_colorMap[7][3] = 0x99;
_colorMap[8][0] = 0x77;
_colorMap[8][1] = 0xdd;
_colorMap[8][2] = 0x77;
_colorMap[8][3] = 0xdd;
_colorMap[9][0] = 0xbb;
_colorMap[9][1] = 0xee;
_colorMap[9][2] = 0xbb;
_colorMap[9][3] = 0xee;
_colorMap[10][0] = 0x5a;
_colorMap[10][1] = 0xa5;
_colorMap[10][2] = 0x5a;
_colorMap[10][3] = 0xa5;
// TODO
_colorMap[12][0] = 0x00;
_colorMap[12][1] = 0x00;
_colorMap[12][2] = 0x00;
_colorMap[12][3] = 0x00;
_colorMap[13][0] = 0x77;
_colorMap[13][1] = 0xdd;
_colorMap[13][2] = 0x77;
_colorMap[13][3] = 0xdd;
// TODO
_colorMap[14][0] = 0xcc;
_colorMap[14][1] = 0xcc;
_colorMap[14][2] = 0xcc;
_colorMap[14][3] = 0xcc;
Graphics::Surface *surf = loadBundledImage("dark_border");
surf->convertToInPlace(_gfx->_texturePixelFormat);
_border = new Graphics::ManagedSurface();
_border->copyFrom(*surf);
surf->free();
delete surf;
file.close();
file.open("darkside.c64.title.bitmap");
Common::File colorFile1;
colorFile1.open("darkside.c64.title.colors1");
Common::File colorFile2;
colorFile2.open("darkside.c64.title.colors2");
_title = loadAndConvertDoodleImage(&file, &colorFile1, &colorFile2, (byte *)&kC64Palette);
}
void DarkEngine::drawC64UI(Graphics::Surface *surface) {
uint8 r, g, b;
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xAA, 0xAA, 0xAA);
uint32 color = _currentArea->_usualBackgroundColor;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int score = _gameStateVars[k8bitVariableScore];
int ecds = _gameStateVars[kVariableActiveECDs];
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 206, 137 + 8, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 206, 145 + 8, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 206, 153 + 8, front, back, surface);
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 68 + 5 + 5, 168 + 9, front, back, surface);
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 70, 177 + 8, front, back, surface);
drawStringInSurface(Common::String::format("%07d", score), 86, 8, front, back, surface);
drawStringInSurface(Common::String::format("%3d%%", ecds), 198, 8, front, back, surface);
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 120, 185, back, front, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else
drawStringInSurface(_currentArea->_name, 120, 185, front, back, surface);
int energy = _gameStateVars[k8bitVariableEnergy]; // called fuel in this game
int shield = _gameStateVars[k8bitVariableShield];
_gfx->readFromPalette(6, r, g, b); // Violet Blue
uint32 outBarColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(14, r, g, b); // Violet
uint32 inBarColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(3, r, g, b); // Light Blue
uint32 lineColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
Common::Rect coverBar;
coverBar = Common::Rect(64, 144, 135, 151);
surface->fillRect(coverBar, back);
if (shield >= 0) {
Common::Rect shieldBar;
shieldBar = Common::Rect(64, 144, 127 - (_maxShield - shield), 151);
surface->fillRect(shieldBar, outBarColor);
shieldBar = Common::Rect(64, 146, 127 - (_maxShield - shield), 149);
surface->fillRect(shieldBar, inBarColor);
if (shield >= 1)
surface->drawLine(64, 147, 127 - (_maxShield - shield) - 1, 147, lineColor);
}
coverBar = Common::Rect(64, 144 + 8, 127, 159);
surface->fillRect(coverBar, back);
if (energy >= 0) {
Common::Rect energyBar;
energyBar = Common::Rect(64, 144 + 8, 127 - (_maxEnergy - energy), 159);
surface->fillRect(energyBar, outBarColor);
energyBar = Common::Rect(64, 146 + 8, 127 - (_maxEnergy - energy), 157);
surface->fillRect(energyBar, inBarColor);
if (energy >= 1)
surface->drawLine(64, 147 + 8, 127 - (_maxEnergy - energy) - 1, 155, lineColor);
}
drawBinaryClock(surface, 304, 124, front, back);
drawVerticalCompass(surface, 17, 77, _pitch, front);
}
} // End of namespace Freescape

View File

@@ -0,0 +1,171 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "freescape/freescape.h"
#include "freescape/games/dark/dark.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void DarkEngine::initCPC() {
_viewArea = Common::Rect(36, 24, 284, 125);
_soundIndexShoot = 0xa;
_soundIndexStart = 0x17;
_soundIndexAreaChange = 0x1c;
_soundIndexDestroyECD = 0x1b;
_soundIndexRestoreECD = 8;
}
extern byte kCPCPaletteTitleData[4][3];
extern byte kCPCPaletteBorderData[4][3];
byte kCPCPaletteDarkTitle[16][3] = {
{0x00, 0x00, 0x00}, // 0: X
{0xff, 0xff, 0xff}, // 1: ?
{0x80, 0x80, 0x80}, // 2: X
{0xff, 0x00, 0xff}, // 3: X
{0x80, 0x80, 0x80}, // 4: X
{0xff, 0xff, 0x00}, // 5: X
{0x80, 0x00, 0x00}, // 6: X
{0xff, 0x00, 0x00}, // 7: X
{0x00, 0x80, 0x80}, // 8: X
{0xff, 0x00, 0x80}, // 9: X
{0xff, 0x80, 0x00}, // 10: X
{0xff, 0x80, 0x80}, // 11: X
{0x00, 0xff, 0x00}, // 12: X
{0x00, 0x00, 0x80}, // 13: X
{0x00, 0x00, 0xff}, // 14: X
{0x00, 0x80, 0x00}, // 15: X
};
extern Graphics::ManagedSurface *readCPCImage(Common::SeekableReadStream *file, bool mode0);
void DarkEngine::loadAssetsCPCFullGame() {
Common::File file;
file.open("DARK1.SCR");
if (!file.isOpen())
error("Failed to open DARK1.SCR");
_title = readCPCImage(&file, false);
_title->setPalette((byte*)&kCPCPaletteDarkTitle, 0, 16);
file.close();
file.open("DARK2.SCR");
if (!file.isOpen())
error("Failed to open DARK2.SCR");
_border = readCPCImage(&file, true);
_border->setPalette((byte*)&kCPCPaletteBorderData, 0, 4);
file.close();
file.open("DARKCODE.BIN");
if (!file.isOpen())
error("Failed to open DARKCODE.BIN");
loadMessagesFixedSize(&file, 0x5d9, 16, 27);
loadFonts(&file, 0x60f3);
loadGlobalObjects(&file, 0x9a, 23);
load8bitBinary(&file, 0x6255, 16);
_indicators.push_back(loadBundledImage("dark_fallen_indicator"));
_indicators.push_back(loadBundledImage("dark_crouch_indicator"));
_indicators.push_back(loadBundledImage("dark_walk_indicator"));
_indicators.push_back(loadBundledImage("dark_jet_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
void DarkEngine::drawCPCUI(Graphics::Surface *surface) {
uint32 color = _currentArea->_underFireBackgroundColor;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_usualBackgroundColor;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
// Drawing the horizontal compass should be done first, so that the background is properly filled
drawHorizontalCompass(200, 143, _yaw, front, back, surface);
int score = _gameStateVars[k8bitVariableScore];
int ecds = _gameStateVars[kVariableActiveECDs];
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 200, 137, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 200, 145, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 200, 153, front, back, surface);
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 72, 168, front, back, surface);
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 72, 177, front, back, surface);
drawStringInSurface(Common::String::format("%07d", score), 95, 8, front, back, surface);
drawStringInSurface(Common::String::format("%3d%%", ecds), 191, 8, front, back, surface);
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 111, 173 + 4, back, front, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else
drawStringInSurface(_currentArea->_name, 111, 173 + 4, front, back, surface);
int energy = _gameStateVars[k8bitVariableEnergy]; // called fuel in this game
int shield = _gameStateVars[k8bitVariableShield];
_gfx->readFromPalette(_gfx->_inkColor, r, g, b);
uint32 inkColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
if (shield >= 0) {
Common::Rect shieldBar;
shieldBar = Common::Rect(72, 141 - 1, 143 - (_maxShield - shield), 146);
surface->fillRect(shieldBar, inkColor);
shieldBar = Common::Rect(72, 143 - 1, 143 - (_maxShield - shield), 144);
surface->fillRect(shieldBar, front);
}
if (energy >= 0) {
Common::Rect energyBar;
energyBar = Common::Rect(72, 147 + 1, 143 - (_maxEnergy - energy), 155 - 1);
surface->fillRect(energyBar, inkColor);
energyBar = Common::Rect(72, 148 + 2, 143 - (_maxEnergy - energy), 154 - 2);
surface->fillRect(energyBar, front);
}
drawBinaryClock(surface, 300, 124, front, back);
drawIndicator(surface, 160, 136);
drawVerticalCompass(surface, 24, 76, _pitch, front);
}
} // End of namespace Freescape

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,125 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "audio/mixer.h"
namespace Freescape {
enum {
kVariableDarkEnding = 28,
kVariableDarkECD = 29,
kVariableActiveECDs = 60,
};
enum {
kDarkEndingEvathDestroyed = 1,
kDarkEndingECDsDestroyed = 2,
};
struct ECD {
uint16 _area;
int _id;
};
enum DarkFontSize {
kDarkFontSmall,
kDarkFontMedium,
kDarkFontBig,
};
class DarkEngine : public FreescapeEngine {
public:
DarkEngine(OSystem *syst, const ADGameDescription *gd);
uint32 _initialEnergy;
uint32 _initialShield;
uint32 _jetFuelSeconds;
void addSkanner(Area *area);
void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
void initGameState() override;
void borderScreen() override;
bool checkIfGameEnded() override;
void endGame() override;
void gotoArea(uint16 areaID, int entranceID) override;
void pressedKey(const int keycode) override;
void executePrint(FCLInstruction &instruction) override;
void initDOS();
void initC64();
void initAmigaAtari();
void initZX();
void initCPC();
void loadAssets() override;
void loadAssetsDOSFullGame() override;
void loadAssetsDOSDemo() override;
void loadAssetsC64FullGame() override;
void loadAssetsAmigaFullGame() override;
void loadAssetsAtariFullGame() override;
void loadAssetsCPCFullGame() override;
void loadAssetsZXDemo() override;
void loadAssetsZXFullGame() override;
void loadMessagesVariableSize(Common::SeekableReadStream *file, int offset, int number) override;
int _lastTenSeconds;
int _lastSecond;
void updateTimeVariables() override;
void drawBinaryClock(Graphics::Surface *surface, int xPosition, int yPosition, uint32 front, uint32 back);
void drawIndicator(Graphics::Surface *surface, int xPosition, int yPosition);
void drawSensorShoot(Sensor *sensor) override;
void drawDOSUI(Graphics::Surface *surface) override;
void drawC64UI(Graphics::Surface *surface) override;
void drawZXUI(Graphics::Surface *surface) override;
void drawCPCUI(Graphics::Surface *surface) override;
void drawAmigaAtariSTUI(Graphics::Surface *surface) override;
Font _fontBig;
Font _fontMedium;
Font _fontSmall;
int _soundIndexRestoreECD;
int _soundIndexDestroyECD;
Audio::SoundHandle _soundFxHandleJetpack;
void drawString(const DarkFontSize size, const Common::String &str, int x, int y, uint32 primaryColor, uint32 secondaryColor, uint32 backColor, Graphics::Surface *surface);
void drawInfoMenu() override;
Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false) override;
Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override;
private:
void addECDs(Area *area);
void addECD(Area *area, const Math::Vector3d position, int index);
void restoreECD(Area &area, int index);
bool checkECD(uint16 areaID, int index);
bool tryDestroyECD(int index);
bool tryDestroyECDFullGame(int index);
void addWalls(Area *area);
void drawVerticalCompass(Graphics::Surface *surface, int x, int y, float angle, uint32 color);
void drawHorizontalCompass(int x, int y, float angle, uint32 front, uint32 back, Graphics::Surface *surface);
};
}

View File

@@ -0,0 +1,250 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/dark/dark.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
extern byte kEGADefaultPalette[16][3];
byte kDarkCGAPalettePinkBlue[4][3] = {
{0x00, 0x00, 0x00},
{0x00, 0xaa, 0xaa},
{0xaa, 0x00, 0xaa},
{0xaa, 0xaa, 0xaa},
};
byte kDarkCGAPaletteRedGreen[4][3] = {
{0x00, 0x00, 0x00},
{0x00, 0xaa, 0x00},
{0xaa, 0x00, 0x00},
{0xaa, 0x55, 0x00},
};
void DarkEngine::initDOS() {
if (_renderMode == Common::kRenderEGA)
_viewArea = Common::Rect(40, 24, 280, 125);
else if (_renderMode == Common::kRenderCGA)
_viewArea = Common::Rect(40, 24, 280, 125);
else
error("Invalid or unknown render mode");
_maxEnergy = 79;
_maxShield = 79;
}
void DarkEngine::loadAssetsDOSDemo() {
Common::File file;
if (_renderMode == Common::kRenderEGA) {
file.open("SCN1E.DAT");
if (file.isOpen()) {
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
}
file.close();
file.open("DSIDEE.EXE");
if (!file.isOpen())
error("Failed to open DSIDEE.EXE");
loadSpeakerFxDOS(&file, 0x4837 + 0x200, 0x46e8 + 0x200, 20);
loadMessagesFixedSize(&file, 0x4525, 16, 27);
loadMessagesFixedSize(&file, 0x993f - 2, 308, 5);
loadFonts(&file, 0xa598);
loadGlobalObjects(&file, 0x3d04, 23);
load8bitBinary(&file, 0xa700, 16);
_border = load8bitBinImage(&file, 0x210);
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
_indicators.push_back(loadBundledImage("dark_fallen_indicator"));
_indicators.push_back(loadBundledImage("dark_crouch_indicator"));
_indicators.push_back(loadBundledImage("dark_walk_indicator"));
_indicators.push_back(loadBundledImage("dark_jet_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
} else if (_renderMode == Common::kRenderCGA) {
file.open("SCN1C.DAT");
if (file.isOpen()) {
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte *)&kDarkCGAPalettePinkBlue, 0, 4);
}
file.close();
file.open("DSIDEC.EXE");
if (!file.isOpen())
error("Failed to open DSIDEC.EXE");
loadSpeakerFxDOS(&file, 0x3077 + 0x200, 0x2f28 + 0x200, 20);
loadFonts(&file, 0x8907);
loadMessagesFixedSize(&file, 0x2d65, 16, 27);
loadMessagesFixedSize(&file, 0x7c3a, 308, 5);
loadGlobalObjects(&file, 0x2554, 23);
load8bitBinary(&file, 0x8a70, 4);
_border = load8bitBinImage(&file, 0x210);
_border->setPalette((byte *)&kDarkCGAPalettePinkBlue, 0, 4);
swapPalette(1);
} else
error("Invalid or unsupported render mode %s for Dark Side", Common::getRenderModeDescription(_renderMode));
}
void DarkEngine::loadAssetsDOSFullGame() {
Common::File file;
if (_renderMode == Common::kRenderEGA) {
file.open("SCN1E.DAT");
if (file.isOpen()) {
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
}
file.close();
file.open("DSIDEE.EXE");
if (!file.isOpen())
error("Failed to open DSIDEE.EXE");
loadSpeakerFxDOS(&file, 0x4837 + 0x200, 0x46e8 + 0x200, 20);
loadFonts(&file, 0xa113);
loadMessagesFixedSize(&file, 0x4525, 16, 27);
loadGlobalObjects(&file, 0x3d04, 23);
load8bitBinary(&file, 0xa280, 16);
_border = load8bitBinImage(&file, 0x210);
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
_indicators.push_back(loadBundledImage("dark_fallen_indicator"));
_indicators.push_back(loadBundledImage("dark_crouch_indicator"));
_indicators.push_back(loadBundledImage("dark_walk_indicator"));
_indicators.push_back(loadBundledImage("dark_jet_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
} else if (_renderMode == Common::kRenderCGA) {
file.open("SCN1C.DAT");
if (file.isOpen()) {
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte *)&kDarkCGAPalettePinkBlue, 0, 4);
}
file.close();
file.open("DSIDEC.EXE");
if (!file.isOpen())
error("Failed to open DSIDEC.EXE");
loadSpeakerFxDOS(&file, 0x3077 + 0x200, 0x2f28 + 0x200, 20);
loadFonts(&file, 0x8497);
loadMessagesFixedSize(&file, 0x2d65, 16, 27);
loadGlobalObjects(&file, 0x2554, 23);
load8bitBinary(&file, 0x8600, 16);
_border = load8bitBinImage(&file, 0x210);
_border->setPalette((byte *)&kDarkCGAPalettePinkBlue, 0, 4);
swapPalette(1);
} else
error("Invalid or unsupported render mode %s for Dark Side", Common::getRenderModeDescription(_renderMode));
}
void DarkEngine::drawDOSUI(Graphics::Surface *surface) {
uint32 color = _renderMode == Common::kRenderCGA ? 3 : 14;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_usualBackgroundColor;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
// Drawing the horizontal compass should be done first, so that the background is properly filled
drawHorizontalCompass(200, 143, _yaw, front, back, surface);
Common::Rect stepBackgroundRect = Common::Rect(69, 177, 98, 185);
surface->fillRect(stepBackgroundRect, back);
Common::Rect positionBackgroundRect = Common::Rect(199, 135, 232, 160);
surface->fillRect(positionBackgroundRect, back);
int score = _gameStateVars[k8bitVariableScore];
int ecds = _gameStateVars[kVariableActiveECDs];
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 199, 137, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 199, 145, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 199, 153, front, back, surface);
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 71, 168, front, back, surface);
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 71, 177, front, back, surface);
drawStringInSurface(Common::String::format("%07d", score), 95, 8, front, back, surface);
drawStringInSurface(Common::String::format("%3d%%", ecds), 192, 8, front, back, surface);
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 112, 177, back, front, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else
drawStringInSurface(_currentArea->_name, 112, 177, front, back, surface);
int energy = _gameStateVars[k8bitVariableEnergy]; // called fuel in this game
int shield = _gameStateVars[k8bitVariableShield];
_gfx->readFromPalette(_renderMode == Common::kRenderCGA ? 1 : 9, r, g, b);
uint32 blue = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
if (shield >= 0) {
Common::Rect shieldBar;
shieldBar = Common::Rect(72, 140, 151 - (_maxShield - shield), 141); // Upper outer shieldBar
surface->fillRect(shieldBar, front);
shieldBar = Common::Rect(72, 145, 151 - (_maxShield - shield), 146); // Lower outer shieldBar
surface->fillRect(shieldBar, front);
shieldBar = Common::Rect(72, 142, 151 - (_maxShield - shield), 144); // Inner shieldBar
surface->fillRect(shieldBar, blue);
}
if (energy >= 0) {
Common::Rect energyBar;
energyBar = Common::Rect(72, 148, 151 - (_maxEnergy - energy), 149); // Upper outer energyBar
surface->fillRect(energyBar, front);
energyBar = Common::Rect(72, 153, 151 - (_maxEnergy - energy), 154); // Lower outer energyBar
surface->fillRect(energyBar, front);
energyBar = Common::Rect(72, 150, 151 - (_maxEnergy - energy), 152); // Inner energyBar
surface->fillRect(energyBar, blue);
}
uint32 clockColor = _renderMode == Common::kRenderCGA ? front : _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0xFF);
drawBinaryClock(surface, 300, 124, clockColor, back);
drawIndicator(surface, 160, 136);
drawVerticalCompass(surface, 24, 76, _pitch, blue);
}
} // End of namespace Freescape

View File

@@ -0,0 +1,206 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/dark/dark.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void DarkEngine::initZX() {
_viewArea = Common::Rect(56, 28, 265, 132);
_maxEnergy = 63;
_maxShield = 63;
_soundIndexShoot = 1;
_soundIndexCollide = -1; // Scripted
_soundIndexStepDown = 3;
_soundIndexStepUp = 4;
_soundIndexMenu = 25;
_soundIndexStart = 11;
_soundIndexAreaChange = 0x1c;
_soundIndexRestoreECD = 30;
_soundIndexNoShield = 14;
_soundIndexNoEnergy = 14;
_soundIndexFallen = 7;
_soundIndexTimeout = 14;
_soundIndexForceEndGame = 14;
_soundIndexCrushed = 25;
_soundIndexMissionComplete = 8;
}
void DarkEngine::loadAssetsZXFullGame() {
Common::File file;
file.open("darkside.zx.title");
if (file.isOpen()) {
_title = loadAndConvertScrImage(&file);
} else
error("Unable to find darkside.zx.title");
file.close();
file.open("darkside.zx.border");
if (file.isOpen()) {
_border = loadAndConvertScrImage(&file);
} else
error("Unable to find driller.zx.border");
file.close();
file.open("darkside.zx.data");
if (!file.isOpen())
error("Failed to open darksize.zx.data");
loadMessagesFixedSize(&file, 0x56b - 6, 16, 27);
loadFonts(&file, 0x5d60 - 6);
loadGlobalObjects(&file, 0x1a, 23);
load8bitBinary(&file, 0x5ec0 - 4, 4);
loadSpeakerFxZX(&file, 0x9c1, 0xa55);
_indicators.push_back(loadBundledImage("dark_fallen_indicator"));
_indicators.push_back(loadBundledImage("dark_crouch_indicator"));
_indicators.push_back(loadBundledImage("dark_walk_indicator"));
_indicators.push_back(loadBundledImage("dark_jet_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
void DarkEngine::loadAssetsZXDemo() {
Common::File file;
file.open("darkside.zx.title");
if (file.isOpen()) {
_title = loadAndConvertScrImage(&file);
} else
error("Unable to find darkside.zx.title");
file.close();
file.open("darkside.zx.border");
if (file.isOpen()) {
_border = loadAndConvertScrImage(&file);
} else
error("Unable to find driller.zx.border");
file.close();
file.open("darkside.zx.data");
if (!file.isOpen())
error("Failed to open darksize.zx.data");
loadMessagesFixedSize(&file, 0x56b, 16, 27);
loadMessagesFixedSize(&file, 0x5761, 264, 5);
loadSpeakerFxZX(&file, 0x9c7, 0xa5b);
loadFonts(&file, 0x6164);
loadGlobalObjects(&file, 0x20, 23);
load8bitBinary(&file, 0x62c6, 4);
_indicators.push_back(loadBundledImage("dark_fallen_indicator"));
_indicators.push_back(loadBundledImage("dark_crouch_indicator"));
_indicators.push_back(loadBundledImage("dark_walk_indicator"));
_indicators.push_back(loadBundledImage("dark_jet_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
void DarkEngine::drawZXUI(Graphics::Surface *surface) {
uint32 color = 7;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_usualBackgroundColor;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
uint32 transparent = _gfx->_texturePixelFormat.ARGBToColor(0x00, 0x00, 0x00, 0x00);
// Drawing the horizontal compass should be done first, so that the background is properly filled
drawHorizontalCompass(192, 141, _yaw, front, back, surface);
int score = _gameStateVars[k8bitVariableScore];
int ecds = _gameStateVars[kVariableActiveECDs];
surface->fillRect(Common::Rect(193, 140, 223, 163), back);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 191, 141, front, transparent, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 191, 149, front, transparent, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 191, 157, front, transparent, surface);
surface->fillRect(Common::Rect(80, 165, 95, 172), back);
surface->fillRect(Common::Rect(80, 172, 102, 179), back);
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 79, 165, front, transparent, surface);
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 79, 173, front, transparent, surface);
surface->fillRect(Common::Rect(96, 12, 151, 19), back);
drawStringInSurface(Common::String::format("%07d", score), 95, 13, front, transparent, surface);
drawStringInSurface(Common::String::format("%3d%%", ecds), 191, 13, front, back, surface);
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 112, 173, back, front, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else
drawStringInSurface(_currentArea->_name, 112, 173, front, back, surface);
int energy = _gameStateVars[k8bitVariableEnergy]; // called fuel in this game
int shield = _gameStateVars[k8bitVariableShield];
if (shield >= 0) {
Common::Rect shieldBar;
shieldBar = Common::Rect(80, 141, 143 - (_maxShield - shield), 148);
surface->fillRect(shieldBar, back);
shieldBar = Common::Rect(80, 142, 143 - (_maxShield - shield), 147);
surface->fillRect(shieldBar, front);
shieldBar = Common::Rect(80, 144, 143 - (_maxShield - shield), 145);
surface->fillRect(shieldBar, back);
}
if (energy >= 0) {
Common::Rect energyBar;
energyBar = Common::Rect(80, 148, 143 - (_maxEnergy - energy), 155);
surface->fillRect(energyBar, back);
energyBar = Common::Rect(80, 149, 143 - (_maxEnergy - energy), 154);
surface->fillRect(energyBar, front);
energyBar = Common::Rect(80, 151, 143 - (_maxEnergy - energy), 152);
surface->fillRect(energyBar, back);
}
uint32 clockColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0x00, 0x00);
drawBinaryClock(surface, 273, 128, clockColor, back);
drawIndicator(surface, 152, 140);
drawVerticalCompass(surface, 47, 79, _pitch, front);
}
} // End of namespace Freescape

View File

@@ -0,0 +1,349 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/driller/driller.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void DrillerEngine::loadAssetsAmigaFullGame() {
Common::File file;
if (_variant & GF_AMIGA_RETAIL) {
file.open("driller");
if (!file.isOpen())
error("Failed to open 'driller' executable for Amiga");
_border = loadAndConvertNeoImage(&file, 0x137f4);
_title = loadAndConvertNeoImage(&file, 0xce);
loadFonts(&file, 0x8940);
Common::Array<Graphics::ManagedSurface *> chars;
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, &file, 0x8940 + 112 * 33 + 1, 100);
_fontSmall = Font(chars);
_fontSmall.setCharWidth(5);
loadMessagesFixedSize(&file, 0xc66e, 14, 20);
loadGlobalObjects(&file, 0xbd62, 8);
load8bitBinary(&file, 0x29c16, 16);
loadPalettes(&file, 0x297d4);
loadSoundsFx(&file, 0x30e80, 25);
} else if (_variant & GF_AMIGA_BUDGET) {
file.open("lift.neo");
if (!file.isOpen())
error("Failed to open 'lift.neo' file");
_title = loadAndConvertNeoImage(&file, 0);
file.close();
file.open("console.neo");
if (!file.isOpen())
error("Failed to open 'console.neo' file");
_border = loadAndConvertNeoImage(&file, 0);
file.close();
file.open("driller");
if (!file.isOpen())
error("Failed to open 'driller' executable for Amiga");
loadFonts(&file, 0xa62);
Common::Array<Graphics::ManagedSurface *> chars;
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, &file, 0xa62 + 112 * 33 + 1, 100);
_fontSmall = Font(chars);
_fontSmall.setCharWidth(5);
loadMessagesFixedSize(&file, 0x499a, 14, 20);
loadGlobalObjects(&file, 0x4098, 8);
load8bitBinary(&file, 0x21a3e, 16);
loadPalettes(&file, 0x215fc);
file.close();
file.open("soundfx");
if (!file.isOpen())
error("Failed to open 'soundfx' executable for Amiga");
loadSoundsFx(&file, 0, 25);
} else
error("Invalid or unknown Amiga release");
for (auto &area : _areaMap) {
// Center and pad each area name so we do not have to do it at each frame
area._value->_name = centerAndPadString(area._value->_name, 14);
}
_indicators.push_back(loadBundledImage("driller_tank_indicator_0"));
_indicators.push_back(loadBundledImage("driller_tank_indicator_1"));
_indicators.push_back(loadBundledImage("driller_tank_indicator_2"));
_indicators.push_back(loadBundledImage("driller_tank_indicator_3"));
_indicators.push_back(loadBundledImage("driller_ship_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
void DrillerEngine::loadAssetsAmigaDemo() {
Common::File file;
file.open("lift.neo");
if (!file.isOpen())
error("Failed to open 'lift.neo' file");
_title = loadAndConvertNeoImage(&file, 0);
file.close();
file.open("console.neo");
if (!file.isOpen())
error("Failed to open 'console.neo' file");
_border = loadAndConvertNeoImage(&file, 0);
file.close();
file.open("demo.cmd");
if (!file.isOpen())
error("Failed to open 'demo.cmd' file");
loadDemoData(&file, 0, 0x1000);
file.close();
file.open("driller");
if (!file.isOpen())
error("Failed to open 'driller' file");
if (_variant & GF_AMIGA_MAGAZINE_DEMO) {
loadMessagesFixedSize(&file, 0x3df0, 14, 20);
loadGlobalObjects(&file, 0x3ba6, 8);
_demoMode = false;
loadFonts(&file, 0xa62);
Common::Array<Graphics::ManagedSurface *> chars;
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, &file, 0xa62 + 112 * 33 + 1, 100);
_fontSmall = Font(chars);
_fontSmall.setCharWidth(5);
} else {
loadFonts(&file, 0xa30);
loadMessagesFixedSize(&file, 0x3960, 14, 20);
loadGlobalObjects(&file, 0x3716, 8);
}
file.close();
file.open("data");
if (!file.isOpen())
error("Failed to open 'data' file");
load8bitBinary(&file, 0x442, 16);
loadPalettes(&file, 0x0);
file.close();
file.open("soundfx");
if (!file.isOpen())
error("Failed to open 'soundfx' executable for Amiga");
loadSoundsFx(&file, 0, 25);
_indicators.push_back(loadBundledImage("driller_tank_indicator_0"));
_indicators.push_back(loadBundledImage("driller_tank_indicator_1"));
_indicators.push_back(loadBundledImage("driller_tank_indicator_2"));
_indicators.push_back(loadBundledImage("driller_tank_indicator_3"));
_indicators.push_back(loadBundledImage("driller_ship_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
/*
The following function contains specific UI code for both Amiga and AtariST
*/
void DrillerEngine::drawAmigaAtariSTUI(Graphics::Surface *surface) {
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0xFF);
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0x55);
uint32 brownish = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x9E, 0x80, 0x20);
uint32 brown = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x7E, 0x60, 0x19);
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xE0, 0x00, 0x00);
uint32 redish = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xE0, 0x60, 0x20);
uint32 primaryFontColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xA0, 0x80, 0x00);
uint32 secondaryFontColor = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x60, 0x40, 0x00);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
uint32 transparent = _gfx->_texturePixelFormat.ARGBToColor(0x00, 0x00, 0x00, 0x00);
int score = _gameStateVars[k8bitVariableScore];
Common::String coords;
// It seems that some demos will not include the complete font
if (!isDemo() || (_variant & GF_AMIGA_MAGAZINE_DEMO) || (_variant & GF_ATARI_MAGAZINE_DEMO)) {
drawString(kDrillerFontSmall, ":", 38, 18, white, white, transparent, surface); // ":" is the next character to "9" representing "x"
coords = Common::String::format("%04d", 2 * int(_position.x()));
drawString(kDrillerFontSmall, coords, 47, 18, white, transparent, transparent, surface);
drawString(kDrillerFontSmall, ";", 37, 26, white, white, transparent, surface); // ";" is the next character to ":" representing "y"
coords = Common::String::format("%04d", 2 * int(_position.z())); // Coords y and z are swapped!
drawString(kDrillerFontSmall, coords, 47, 26, white, transparent, transparent, surface);
drawString(kDrillerFontSmall, "<", 37, 34, white, white, transparent, surface); // "<" is the next character to ";" representing "z"
coords = Common::String::format("%04d", 2 * int(_position.y())); // Coords y and z are swapped!
drawString(kDrillerFontSmall, coords, 47, 34, white, transparent, transparent, surface);
}
drawStringInSurface(_currentArea->_name, 189, 185, primaryFontColor, secondaryFontColor, black, surface);
drawStringInSurface(Common::String::format("%07d", score), 241, 129, primaryFontColor, secondaryFontColor, black, surface);
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
drawStringInSurface(Common::String::format("%02d:", hours), 210, 7, primaryFontColor, secondaryFontColor, black, surface);
drawStringInSurface(Common::String::format("%02d:", minutes), 230, 7, primaryFontColor, secondaryFontColor, black, surface);
drawStringInSurface(Common::String::format("%02d", seconds), 254, 7, primaryFontColor, secondaryFontColor, black, surface);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 188, 177, yellow, secondaryFontColor, black, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_currentArea->_gasPocketRadius == 0)
message = _messagesList[2];
else if (_drillStatusByArea[_currentArea->getAreaID()])
message = _messagesList[0];
else
message = _messagesList[1];
drawStringInSurface(message, 188, 177, primaryFontColor, secondaryFontColor, black, surface);
}
int energy = _gameStateVars[k8bitVariableEnergy];
int shield = _gameStateVars[k8bitVariableShield];
if (shield >= 0) {
Common::Rect shieldBar;
shieldBar = Common::Rect(11, 178, 74 - (_maxShield - shield), 184);
surface->fillRect(shieldBar, brown);
if (shield > 11)
shieldBar = Common::Rect(11, 178, 25, 184);
else
shieldBar = Common::Rect(11, 178, 74 - (_maxShield - shield), 184);
surface->fillRect(shieldBar, red);
shieldBar = Common::Rect(11, 179, 74 - (_maxShield - shield), 183);
surface->fillRect(shieldBar, brownish);
if (shield > 11)
shieldBar = Common::Rect(11, 179, 25, 183);
else
shieldBar = Common::Rect(11, 179, 74 - (_maxShield - shield), 183);
surface->fillRect(shieldBar, redish);
shieldBar = Common::Rect(11, 180, 74 - (_maxShield - shield), 182);
surface->fillRect(shieldBar, yellow);
}
if (energy >= 0) {
Common::Rect energyBar;
energyBar = Common::Rect(11, 186, 74 - (_maxEnergy - energy), 192);
surface->fillRect(energyBar, brown);
if (energy > 11)
energyBar = Common::Rect(11, 186, 24, 192);
else
energyBar = Common::Rect(11, 186, 74 - (_maxEnergy - energy), 192);
surface->fillRect(energyBar, red);
energyBar = Common::Rect(11, 187, 74 - (_maxEnergy - energy), 191);
surface->fillRect(energyBar, brownish);
if (energy > 11)
energyBar = Common::Rect(11, 187, 24, 191);
else
energyBar = Common::Rect(11, 187, 74 - (_maxEnergy - energy), 191);
surface->fillRect(energyBar, redish);
energyBar = Common::Rect(11, 188, 74 - (_maxEnergy - energy), 190);
surface->fillRect(energyBar, yellow);
}
if (_indicators.size() > 0) {
if (_flyMode)
surface->copyRectToSurface(*_indicators[4], 106, 128, Common::Rect(_indicators[1]->w, _indicators[1]->h));
else
surface->copyRectToSurface(*_indicators[_playerHeightNumber], 106, 128, Common::Rect(_indicators[1]->w, _indicators[1]->h));
}
}
void DrillerEngine::drawString(const DrillerFontSize size, const Common::String &str, int x, int y, uint32 primaryColor, uint32 secondaryColor, uint32 backColor, Graphics::Surface *surface) {
if (!_fontLoaded)
return;
Font *font = nullptr;
if (size == kDrillerFontNormal) {
font = &_font;
} else if (size == kDrillerFontSmall) {
font = &_fontSmall;
} else {
error("Invalid font size %d", size);
return;
}
Common::String ustr = str;
ustr.toUppercase();
font->setBackground(backColor);
font->setSecondaryColor(secondaryColor);
font->drawString(surface, ustr, x, y, _screenW, primaryColor);
}
void DrillerEngine::initAmigaAtari() {
_viewArea = Common::Rect(36, 16, 284, 118);
_moveFowardArea = Common::Rect(184, 125, 199, 144);
_moveLeftArea = Common::Rect(161, 145, 174, 164);
_moveRightArea = Common::Rect(207, 145, 222, 164);
_moveBackArea = Common::Rect(184, 152, 199, 171);
_moveUpArea = Common::Rect(231, 145, 246, 164);
_moveDownArea = Common::Rect(254, 145, 269, 164);
_deployDrillArea = Common::Rect(284, 145, 299, 166);
_infoScreenArea = Common::Rect(125, 172, 152, 197);
_saveGameArea = Common::Rect(9, 145, 39, 154);
_loadGameArea = Common::Rect(9, 156, 39, 164);
_borderExtra = nullptr;
_borderExtraTexture = nullptr;
_soundIndexShoot = 1;
_soundIndexCollide = 19;
_soundIndexStepDown = 19;
_soundIndexStepUp = 19;
_soundIndexAreaChange = 5;
_soundIndexHit = 2;
_soundIndexFall = 25;
_soundIndexFallen = 11;
_soundIndexForceEndGame = 11;
_soundIndexNoShield = 11;
_soundIndexNoEnergy = 11;
_soundIndexTimeout = 11;
_soundIndexCrushed = 11;
}
} // End of namespace Freescape

View File

@@ -0,0 +1,386 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "common/endian.h"
#include "freescape/freescape.h"
#include "freescape/games/driller/driller.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
namespace {
// A simple implementation of memmem, which is a non-standard GNU extension.
const void *local_memmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len) {
if (needle_len == 0) {
return haystack;
}
if (haystack_len < needle_len) {
return nullptr;
}
const char *h = (const char *)haystack;
for (size_t i = 0; i <= haystack_len - needle_len; ++i) {
if (memcmp(h + i, needle, needle_len) == 0) {
return h + i;
}
}
return nullptr;
}
} // namespace
Common::SeekableReadStream *DrillerEngine::decryptFileAtariVirtualWorlds(const Common::Path &filename) {
Common::File file;
if (!file.open(filename)) {
error("Failed to open %s", filename.toString().c_str());
}
const int size = file.size();
byte *data = (byte *)malloc(size);
file.read(data, size);
int start = 0;
int valid_offset = -1;
int chunk_size = 0;
while (true) {
const byte *found = (const byte *)local_memmem(data + start, size - start, "CBCP", 4);
if (!found) break;
int idx = found - data;
if (idx + 8 <= size) {
int sz = READ_BE_UINT32(data + idx + 4);
if (sz > 0 && sz < size + 0x20000) {
valid_offset = idx;
chunk_size = sz;
}
}
start = idx + 1;
}
if (valid_offset == -1) {
error("No valid CBCP chunk found in %s", filename.toString().c_str());
}
const byte *payload = data + valid_offset + 8;
const int payload_size = chunk_size;
if (payload_size < 12) {
error("Payload too short in %s", filename.toString().c_str());
}
uint32 bit_buf_init = READ_BE_UINT32(payload + payload_size - 12);
uint32 checksum_init = READ_BE_UINT32(payload + payload_size - 8);
uint32 decoded_size = READ_BE_UINT32(payload + payload_size - 4);
byte *out_buffer = (byte *)malloc(decoded_size);
int dst_idx = decoded_size;
struct BitStream {
const byte *_src_data;
int _src_idx;
uint32 _bit_buffer;
uint32 _checksum;
int _refill_carry;
BitStream(const byte *src_data, int start_idx, uint32 bit_buffer, uint32 checksum) :
_src_data(src_data), _src_idx(start_idx), _bit_buffer(bit_buffer), _checksum(checksum), _refill_carry(0) {}
void refill() {
if (_src_idx < 0) {
_refill_carry = 0;
_bit_buffer = 0x80000000;
return;
}
uint32 val = READ_BE_UINT32(_src_data + _src_idx);
_src_idx -= 4;
_checksum ^= val;
_refill_carry = val & 1;
_bit_buffer = (val >> 1) | 0x80000000;
}
int getBits(int count) {
uint32 result = 0;
for (int i = 0; i < count; ++i) {
int carry = _bit_buffer & 1;
_bit_buffer >>= 1;
if (_bit_buffer == 0) {
refill();
carry = _refill_carry;
}
result = (result << 1) | carry;
}
return result;
}
};
int src_idx = payload_size - 16;
uint32 checksum = checksum_init ^ bit_buf_init;
BitStream bs(payload, src_idx, bit_buf_init, checksum);
while (dst_idx > 0) {
if (bs.getBits(1) == 0) {
if (bs.getBits(1) == 1) {
int offset = bs.getBits(8);
for (int i = 0; i < 2; ++i) {
dst_idx--;
if (dst_idx >= 0) {
out_buffer[dst_idx] = out_buffer[dst_idx + offset];
}
}
} else {
int count = bs.getBits(3) + 1;
for (int i = 0; i < count; ++i) {
dst_idx--;
if (dst_idx >= 0) {
out_buffer[dst_idx] = bs.getBits(8);
}
}
}
} else {
int tag = bs.getBits(2);
if (tag == 3) {
int count = bs.getBits(8) + 9;
for (int i = 0; i < count; ++i) {
dst_idx--;
if (dst_idx >= 0) {
out_buffer[dst_idx] = bs.getBits(8);
}
}
} else if (tag == 2) {
int length = bs.getBits(8) + 1;
int offset = bs.getBits(12);
for (int i = 0; i < length; ++i) {
dst_idx--;
if (dst_idx >= 0) {
out_buffer[dst_idx] = out_buffer[dst_idx + offset];
}
}
} else {
int bits_offset = 9 + tag;
int length = 3 + tag;
int offset = bs.getBits(bits_offset);
for (int i = 0; i < length; ++i) {
dst_idx--;
if (dst_idx >= 0) {
out_buffer[dst_idx] = out_buffer[dst_idx + offset];
}
}
}
}
}
free(data);
return new Common::MemoryReadStream(out_buffer, decoded_size);
}
Common::SeekableReadStream *DrillerEngine::decryptFileAtari(const Common::Path &filename) {
Common::File file;
file.open(filename);
if (!file.isOpen())
error("Failed to open %s", filename.toString().c_str());
int size = file.size();
byte *encryptedBuffer = (byte *)malloc(size);
file.read(encryptedBuffer, size);
file.close();
byte *a6 = encryptedBuffer + 0x118;
byte *a5 = encryptedBuffer + size - 4;
uint64 key = 0xb9f11bce;
while (a6 <= a5) {
uint64 d0 = (a6[0] << 24) | (a6[1] << 16) | (a6[2] << 8) | a6[3];
d0 += key;
d0 = uint32(d0);
a6[0] = byte((d0 >> 24) & 0xFF);
a6[1] = byte((d0 >> 16) & 0xFF);
a6[2] = byte((d0 >> 8) & 0xFF);
a6[3] = byte(d0 & 0xFF);
key += 0x51684624;
key = uint32(key);
a6 += 4;
}
return (new Common::MemoryReadStream(encryptedBuffer, size));
}
void DrillerEngine::loadAssetsAtariFullGame() {
Common::SeekableReadStream *stream = nullptr;
if (_variant & GF_ATARI_RETAIL) {
stream = decryptFileAtari("x.prg");
_border = loadAndConvertNeoImage(stream, 0x14b96);
_borderExtra = loadAndConvertNeoImage(stream, 0x1c916);
_title = loadAndConvertNeoImage(stream, 0x3f6);
loadFonts(stream, 0x8a92);
Common::Array<Graphics::ManagedSurface *> chars;
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, stream, 0x8a92 + 112 * 33 + 1, 100);
_fontSmall = Font(chars);
_fontSmall.setCharWidth(5);
loadMessagesFixedSize(stream, 0xda22, 14, 20);
loadGlobalObjects(stream, 0xd116, 8);
load8bitBinary(stream, 0x2afb8, 16);
loadPalettes(stream, 0x2ab76);
loadSoundsFx(stream, 0x30da6 + 0x147c, 25);
} else if (_variant & GF_ATARI_BUDGET) {
Common::File file;
file.open("x.prg");
if (!file.isOpen()) {
stream = decryptFileAtariVirtualWorlds("dril.all");
} else
stream = &file;
if (isSpaceStationOblivion()) {
_border = loadAndConvertNeoImage(&file, 0x13544);
byte palette[16 * 3];
for (int i = 0; i < 16; i++) { // gray scale palette
palette[i * 3 + 0] = i * (255 / 16);
palette[i * 3 + 1] = i * (255 / 16);
palette[i * 3 + 2] = i * (255 / 16);
}
_title = loadAndConvertNeoImage(&file, 0x10, palette);
loadFonts(&file, 0x8a32 - 0x1d6);
loadMessagesFixedSize(&file, 0xc5d8 - 0x1da, 14, 20);
loadGlobalObjects(&file, 0xbccc - 0x1da, 8);
load8bitBinary(&file, 0x29b3c - 0x1d6, 16);
loadPalettes(&file, 0x296fa - 0x1d6);
loadSoundsFx(&file, 0x30da6 - 0x1d6, 25);
} else {
_border = loadAndConvertNeoImage(stream, 0x1371a);
_title = loadAndConvertNeoImage(stream, 0x396);
loadFonts(stream, 0x8a32);
Common::Array<Graphics::ManagedSurface *> chars;
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, stream, 0x8a32 + 112 * 33 + 1, 100);
_fontSmall = Font(chars);
_fontSmall.setCharWidth(5);
loadMessagesFixedSize(stream, 0xc5d8, 14, 20);
loadGlobalObjects(stream, 0xbccc, 8);
load8bitBinary(stream, 0x29b3c, 16);
loadPalettes(stream, 0x296fa);
loadSoundsFx(stream, 0x30da6, 25);
}
} else
error("Unknown Atari ST Driller variant");
for (auto &area : _areaMap) {
// Center and pad each area name so we do not have to do it at each frame
area._value->_name = centerAndPadString(area._value->_name, 14);
}
_indicators.push_back(loadBundledImage("driller_tank_indicator_0_Amiga", false));
_indicators.push_back(loadBundledImage("driller_tank_indicator_1_Amiga", false));
_indicators.push_back(loadBundledImage("driller_tank_indicator_2_Amiga", false));
_indicators.push_back(loadBundledImage("driller_tank_indicator_3_Amiga", false));
_indicators.push_back(loadBundledImage("driller_ship_indicator_Amiga", false));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
void DrillerEngine::loadAssetsAtariDemo() {
Common::File file;
file.open("lift.neo");
if (!file.isOpen())
error("Failed to open 'lift.neo' file");
_title = loadAndConvertNeoImage(&file, 0);
file.close();
file.open("console.neo");
if (!file.isOpen())
error("Failed to open 'console.neo' file");
_border = loadAndConvertNeoImage(&file, 0);
file.close();
file.open("demo.cmd");
if (!file.isOpen())
error("Failed to open 'demo.cmd' file");
loadDemoData(&file, 0, 0x1000);
file.close();
if (_variant & GF_ATARI_MAGAZINE_DEMO) {
file.open("auto_x.prg");
if (!file.isOpen())
error("Failed to open 'auto_x.prg' file");
_demoMode = false;
} else {
file.open("x.prg");
if (!file.isOpen())
error("Failed to open 'x.prg' file");
}
if (_variant & GF_ATARI_MAGAZINE_DEMO) {
loadMessagesFixedSize(&file, 0x40d2, 14, 20);
loadGlobalObjects(&file, 0x3e88, 8);
loadFonts(&file, 0x7ee);
Common::Array<Graphics::ManagedSurface *> chars;
chars = getCharsAmigaAtariInternal(8, 8, -3, 33, 32, &file, 0x7ee + 112 * 33 + 1, 100);
_fontSmall = Font(chars);
_fontSmall.setCharWidth(5);
} else {
loadFonts(&file, 0x7bc);
loadMessagesFixedSize(&file, 0x3b90, 14, 20);
loadGlobalObjects(&file, 0x3946, 8);
}
file.close();
file.open("data");
if (!file.isOpen())
error("Failed to open 'data' file");
load8bitBinary(&file, 0x442, 16);
loadPalettes(&file, 0x0);
file.close();
file.open("soundfx");
if (!file.isOpen())
error("Failed to open 'soundfx' executable for AtariST demo");
loadSoundsFx(&file, 0, 25);
for (auto &area : _areaMap) {
// Center and pad each area name so we do not have to do it at each frame
area._value->_name = centerAndPadString(area._value->_name, 14);
}
_indicators.push_back(loadBundledImage("driller_tank_indicator_0_Amiga", false));
_indicators.push_back(loadBundledImage("driller_tank_indicator_1_Amiga", false));
_indicators.push_back(loadBundledImage("driller_tank_indicator_2_Amiga", false));
_indicators.push_back(loadBundledImage("driller_tank_indicator_3_Amiga", false));
_indicators.push_back(loadBundledImage("driller_ship_indicator_Amiga", false));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
} // End of namespace Freescape

View File

@@ -0,0 +1,249 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/driller/driller.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
extern byte kC64Palette[16][3];
void DrillerEngine::initC64() {
_viewArea = Common::Rect(32, 16, 288, 120);
}
void DrillerEngine::loadAssetsC64FullGame() {
Common::File file;
if (_targetName.hasPrefix("spacestationoblivion")) {
file.open("spacestationoblivion.c64.data");
loadMessagesFixedSize(&file, 0x167a, 14, 20);
//loadFonts(&file, 0xae54);
load8bitBinary(&file, 0x8e02, 4);
loadGlobalObjects(&file, 0x1855, 8);
} else if (_targetName.hasPrefix("driller")) {
file.open("driller.c64.data");
if (_variant) {
loadMessagesFixedSize(&file, 0x167a, 14, 20);
loadGlobalObjects(&file, 0x1855, 8);
loadFonts(&file, 0x402);
load8bitBinary(&file, 0x8b04, 16);
/*} else if (_variant & GF_C64_BUDGET) {
//loadFonts(&file, 0x402);
load8bitBinary(&file, 0x7df7, 16);
loadMessagesFixedSize(&file, 0x1399, 14, 20);
loadGlobalObjects(&file, 0x150a, 8);*/
} else
error("Unknown C64 variant %x", _variant);
// The color map from the data is not correct,
// so we'll just hardcode the one that we found in the executable
for (int i = 0; i < 15; i++) {
_colorMap[i][0] = 0;
_colorMap[i][1] = 0;
_colorMap[i][2] = 0;
_colorMap[i][3] = 0;
}
_colorMap[1][0] = 0x55;
_colorMap[1][1] = 0x55;
_colorMap[1][2] = 0x55;
_colorMap[1][3] = 0x55;
_colorMap[2][0] = 0xaa;
_colorMap[2][1] = 0xaa;
_colorMap[2][2] = 0xaa;
_colorMap[2][3] = 0xaa;
_colorMap[3][0] = 0xff;
_colorMap[3][1] = 0xff;
_colorMap[3][2] = 0xff;
_colorMap[3][3] = 0xff;
_colorMap[4][0] = 0x44;
_colorMap[4][1] = 0x11;
_colorMap[4][2] = 0x44;
_colorMap[4][3] = 0x11;
_colorMap[5][0] = 0x88;
_colorMap[5][1] = 0x22;
_colorMap[5][2] = 0x88;
_colorMap[5][3] = 0x22;
_colorMap[6][0] = 0xcc;
_colorMap[6][1] = 0x33;
_colorMap[6][2] = 0xcc;
_colorMap[6][3] = 0x33;
_colorMap[7][0] = 0x66;
_colorMap[7][1] = 0x99;
_colorMap[7][2] = 0x66;
_colorMap[7][3] = 0x99;
_colorMap[8][0] = 0x77;
_colorMap[8][1] = 0xdd;
_colorMap[8][2] = 0x77;
_colorMap[8][3] = 0xdd;
_colorMap[9][0] = 0xbb;
_colorMap[9][1] = 0xee;
_colorMap[9][2] = 0xbb;
_colorMap[9][3] = 0xee;
_colorMap[10][0] = 0x5a;
_colorMap[10][1] = 0xa5;
_colorMap[10][2] = 0x5a;
_colorMap[10][3] = 0xa5;
_colorMap[11][0] = 0xaf;
_colorMap[11][1] = 0xfa;
_colorMap[11][2] = 0xaf;
_colorMap[11][3] = 0xfa;
_colorMap[12][0] = 0x77;
_colorMap[12][1] = 0xdd;
_colorMap[12][2] = 0x77;
_colorMap[12][3] = 0xdd;
_colorMap[13][0] = 0xcc;
_colorMap[13][1] = 0xcc;
_colorMap[13][2] = 0xcc;
_colorMap[13][3] = 0xcc;
// TODO
_colorMap[14][0] = 0x77;
_colorMap[14][1] = 0xdd;
_colorMap[14][2] = 0x77;
_colorMap[14][3] = 0xdd;
Graphics::Surface *surf = loadBundledImage("driller_border");
surf->convertToInPlace(_gfx->_texturePixelFormat);
_border = new Graphics::ManagedSurface();
_border->copyFrom(*surf);
surf->free();
delete surf;
file.close();
file.open("driller.c64.title.bitmap");
Common::File colorFile1;
colorFile1.open("driller.c64.title.colors1");
Common::File colorFile2;
colorFile2.open("driller.c64.title.colors2");
_title = loadAndConvertDoodleImage(&file, &colorFile1, &colorFile2, (byte *)&kC64Palette);
} else
error("Unknown C64 release");
_playerSid = new DrillerSIDPlayer();
}
void DrillerEngine::drawC64UI(Graphics::Surface *surface) {
uint8 r, g, b;
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xAA, 0xAA, 0xAA);
Common::Rect cover;
uint32 color = 0;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int score = _gameStateVars[k8bitVariableScore];
drawStringInSurface(_currentArea->_name, 200, 184, front, back, surface);
cover = Common::Rect(150, 143, 183, 167);
surface->fillRect(cover, back);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 150, 148 - 4, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 150, 156 - 4, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 150, 164 - 4, front, back, surface);
if (_playerHeightNumber >= 0)
drawStringInSurface(Common::String::format("%d", _playerHeightNumber), 54 + 6, 164 - 3, front, back, surface);
else
drawStringInSurface(Common::String::format("%s", "J"), 54 + 6, 164 - 3, front, back, surface);
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 46, 148 - 3, front, back, surface);
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 46, 156 - 3, front, back, surface);
drawStringInSurface(Common::String::format("%07d", score), 239, 128, front, back, surface);
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
drawStringInSurface(Common::String::format("%02d", hours), 207, 8, front, back, surface);
drawStringInSurface(Common::String::format("%02d", minutes), 230, 8, front, back, surface);
drawStringInSurface(Common::String::format("%02d", seconds), 254, 8, front, back, surface);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 191, 176, back, front, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_currentArea->_gasPocketRadius == 0)
message = _messagesList[2];
else if (_drillStatusByArea[_currentArea->getAreaID()])
message = _messagesList[0];
else
message = _messagesList[1];
drawStringInSurface(message, 191, 176, front, back, surface);
}
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x68, 0xa9, 0x41);
int energy = _gameStateVars[k8bitVariableEnergy];
int shield = _gameStateVars[k8bitVariableShield];
if (energy >= 0) {
Common::Rect backBar(21, 183, 85 - energy, 190);
surface->fillRect(backBar, back);
Common::Rect energyBar(84 - energy, 184, 84, 190);
surface->fillRect(energyBar, green);
}
if (shield >= 0) {
Common::Rect backBar(25 - 4, 180 - 4, 89 - shield - 4, 186 - 4);
surface->fillRect(backBar, back);
Common::Rect shieldBar(88 - 4 - shield, 180 - 4, 88 - 4, 186 - 4);
surface->fillRect(shieldBar, green);
}
_gfx->readFromPalette(7, r, g, b);
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
surface->fillRect(Common::Rect(87, 156, 104, 166), back);
drawCompass(surface, 94, 156, _yaw - 30, 11, 75, yellow);
surface->fillRect(Common::Rect(224, 151, 235, 160), back);
drawCompass(surface, 223, 156, _pitch - 30, 12, 60, yellow);
}
} // End of namespace Freescape

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,239 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "audio/sid.h"
#include "common/debug.h"
namespace Freescape {
class DrillerSIDPlayer {
// --- Voice State Structure ---
struct VoiceState {
// Pointers & Indices
const uint8_t *trackDataPtr; // Pointer to current track data array
uint8_t trackIndex; // Index within trackDataPtr
const uint8_t *patternDataPtr; // Pointer to current pattern data array
uint8_t patternIndex; // Index within patternDataPtr
uint8_t instrumentIndex; // Current instrument (0-21, scaled by 8 for lookup)
// Playback Control & Tempo
int8_t delayCounter; // Counts down frames for note duration (maps to voiceX_ctrl2)
uint8_t noteDuration; // Duration set by FD xx (maps to voiceX_something+2)
uint8_t gateMask; // Control gating/retriggering (maps to control3 behavior)
// Note & Frequency
uint8_t currentNote; // Current raw note value (0-95)
uint8_t portaTargetNote; // Target note for portamento
uint16_t currentFreq; // Current frequency being sent to SID
uint16_t baseFreq; // Note frequency without effects
uint16_t targetFreq; // Used for portamento target
// Pulse Width
uint16_t pulseWidth; // Current pulse width
// Placeholder for PWM effects if needed later
// ADSR
uint8_t attackDecay; // SID Attack / Decay register value
uint8_t sustainRelease; // SID Sustain / Release register value
// Effects State
uint8_t effect; // Current active effect (0:None, 1:Arpeggio, 2:Vibrato, 3:Portamento Up, 4:Portamento Down, 5: PWM LFO?)
uint8_t arpeggioIndex; // Index in arpeggio table
uint8_t arpeggioSpeed; // Counter divisor for arpeggio step
uint8_t arpeggioCounter; // Counter for arpeggio step
uint8_t arpeggioNoteOffsetIndex; // 0, 1, 2 for arpeggio notes
int16_t vibratoDepth; // Depth for vibrato effect
uint8_t vibratoSpeed; // Speed/delay for vibrato effect
uint8_t vibratoDelay; // Counter for vibrato step
uint8_t vibratoDirection; // 0: up, 1: down
int16_t vibratoCurrentOffset; // Current frequency offset for vibrato
int16_t portaSpeed; // Speed for portamento effect (positive for up, negative for down)
// Hard Restart / Buzz Effect (from L1005, possibly instrument related)
uint8_t hardRestartValue; // Value from instrument table (a1+5)
uint8_t hardRestartDelay; // Counter for delay phase (voiceX_whatever+3)
uint8_t hardRestartCounter; // Counter for frequency change phase (voiceX_whatever+4)
bool hardRestartActive; // Is the effect currently running?
// From disassembly variables (mapping might need refinement)
// voice1_whatever: 0CCE[5] - effect state? (arp, vib, porta)
uint8_t whatever0; // 0CCE - Vibrato state? (0=off, 1=active, 3-4=sweep?)
uint8_t whatever1; // 0CCF - Arpeggio state? (0=off, 1=active)
uint8_t whatever2; // 0CD0 - Portamento type (0=off, 1=down(FB), 2=up(FC), 3=down H(FB), 4=up H(FC))?
uint8_t whatever3; // 0CD1 - Hard restart delay counter
uint8_t whatever4; // 0CD2 - Hard restart step counter
// voice1_whatever2: 0CD4 - Vibrato direction toggle?
uint8_t whatever2_vibDirToggle;
// voice1_something: 0CE3[3] - Porta speed?, Note duration
uint16_t portaStepRaw; // 0CE3/4 - Raw value from FB/FC command
// uint8_t noteDuration // 0CE5 - Covered above
// voice1_something_else: 0CE7[3] - PW Low, PW High? (ADSR in disassembly?) - Needs clarification
uint8_t something_else[3]; // Re-add this array as it's used in the code logic
// voice1_ctrl0: 0CF8 - ADSR lower nibble (Sustain/Release)
uint8_t ctrl0; // Re-add this as it's used in the code logic
// voice1_ctrl1: 0CF9 - Arpeggio table index / Arp speed upper nibble
uint8_t arpTableIndex;
uint8_t arpSpeedHiNibble;
// voice1_ctrl2: 0CFE - Note delay counter (covered by delayCounter)
// voice1_stuff: 0D14[7] - Current freq, base freq, hard restart freq store? Arp counter?
uint16_t stuff_freq_porta_vib; // 0D14/15 - Current frequency including porta/vib
uint16_t stuff_freq_base; // 0D16/17 - Base frequency of the note
uint16_t stuff_freq_hard_restart; // 0D18/19 - Frequency stored during hard restart buzz
uint8_t stuff_arp_counter; // 0D1A - Arpeggio counter (0..speed-1)
uint8_t stuff_arp_note_index; // 0D1B - Index into arp notes (0, 1, 2)
// voice1_things: 0D29[7] - Vibrato state/params
uint8_t things_vib_state; // 0D29 - Vibrato state (0=down1, 1=up, 2=down2, 3=sweepdown1, 4=sweepup)
uint16_t things_vib_depth; // 0D2A/2B - Vibrato depth
uint8_t things_vib_delay_reload; // 0D2C - Vibrato delay reload value
uint8_t things_vib_delay_ctr; // 0D2D - Vibrato delay counter
// 0D2E/F unused?
uint8_t currentNoteSlideTarget; // 0D30 - Last played note (used for slide target?)
// voice1_two_ctr: 0D3E - Glide down timer? (Instrument related)
uint8_t glideDownTimer;
// Temp values during processing
uint8_t waveform; // Current waveform for SID
bool keyOn; // Current key state (attack vs release)
bool sync; // Sync bit state
bool ringMod; // Ring mod bit state
// Pulse width parts matching something_else (if it maps to PW)
uint8_t pwLo() const { return something_else[0]; } // Example mapping
uint8_t pwHi() const { return something_else[2]; } // Example mapping
void setPwLo(uint8_t val) { something_else[0] = val; }
void setPwHi(uint8_t val) { something_else[2] = val; }
void reset() {
trackDataPtr = nullptr;
trackIndex = 0;
patternDataPtr = nullptr;
patternIndex = 0;
instrumentIndex = 0;
delayCounter = 0;
noteDuration = 0;
gateMask = 0xFF;
currentNote = 0;
portaTargetNote = 0;
currentFreq = 0;
baseFreq = 0;
targetFreq = 0;
pulseWidth = 0;
attackDecay = 0;
sustainRelease = 0;
effect = 0;
arpeggioIndex = 0;
arpeggioSpeed = 0;
arpeggioCounter = 0;
arpeggioNoteOffsetIndex = 0;
vibratoDepth = 0;
vibratoSpeed = 0;
vibratoDelay = 0;
vibratoDirection = 0;
vibratoCurrentOffset = 0;
portaSpeed = 0;
hardRestartValue = 0;
hardRestartDelay = 0;
hardRestartCounter = 0;
hardRestartActive = false;
waveform = 0x10; // Default to triangle?
keyOn = false;
sync = false;
ringMod = false;
// Reset mapped vars
whatever0 = 0;
whatever1 = 0;
whatever2 = 0;
whatever3 = 0;
whatever4 = 0;
whatever2_vibDirToggle = 0;
portaStepRaw = 0;
memset(something_else, 0, sizeof(something_else)); // Reset the array
ctrl0 = 0; // Reset the added member
arpTableIndex = 0;
arpSpeedHiNibble = 0;
stuff_freq_porta_vib = 0;
stuff_freq_base = 0;
stuff_freq_hard_restart = 0;
stuff_arp_counter = 0;
stuff_arp_note_index = 0;
things_vib_state = 0;
things_vib_depth = 0;
things_vib_delay_reload = 0;
things_vib_delay_ctr = 0;
currentNoteSlideTarget = 0;
glideDownTimer = 0;
}
};
// --- Member Variables ---
SID::SID *_sid;
// Player State
enum PlayState { STOPPED,
PLAYING,
CHANGING_TUNE };
PlayState _playState;
uint8_t _targetTuneIndex; // Tune index requested via startMusic
// Global Timing
uint8_t _globalTempo; // Tempo value for current tune (0xD10)
int8_t _globalTempoCounter; // Frame counter for tempo (0xD12), signed to handle < 0 check
uint8_t _framePhase; // Tracks which voice is being processed (0, 7, 14)
// Voice States
VoiceState _voiceState[3];
// Internal helpers
uint8_t _tempControl3; // Temporary storage for gate mask (0xD13)
// uint8_t _tempControl1; // Temp storage from instrument data (0xD11)
public:
DrillerSIDPlayer();
~DrillerSIDPlayer();
void startMusic(int tuneIndex = 1);
void stopMusic();
private:
void SID_Write(int reg, uint8_t data);
void initSID();
void onTimer();
void handleChangeTune(int tuneIndex);
void handleResetVoices();
void playVoice(int voiceIndex);
void applyNote(VoiceState &v, int sidOffset, const uint8_t *instA0, const uint8_t *instA1, int voiceIndex);
void applyContinuousEffects(VoiceState &v, int sidOffset, const uint8_t *instA0, const uint8_t *instA1);
void applyHardRestart(VoiceState &v, int sidOffset, const uint8_t *instA0, const uint8_t *instA1);
};
} // namespace Freescape

View File

@@ -0,0 +1,243 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "freescape/freescape.h"
#include "freescape/games/driller/driller.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void DrillerEngine::initCPC() {
_viewArea = Common::Rect(36, 16, 284, 117);
}
byte kCPCPaletteTitleData[4][3] = {
{0x00, 0x00, 0x00},
{0x00, 0x80, 0xff},
{0xff, 0x00, 0x00},
{0xff, 0xff, 0x00},
};
byte kCPCPaletteBorderData[4][3] = {
{0x00, 0x00, 0x00},
{0xff, 0x80, 0x00},
{0x80, 0xff, 0xff},
{0x00, 0x80, 0x00},
};
byte getCPCPixelMode1(byte cpc_byte, int index) {
if (index == 0)
return ((cpc_byte & 0x08) >> 2) | ((cpc_byte & 0x80) >> 7);
else if (index == 1)
return ((cpc_byte & 0x04) >> 1) | ((cpc_byte & 0x40) >> 6);
else if (index == 2)
return (cpc_byte & 0x02) | ((cpc_byte & 0x20) >> 5);
else if (index == 3)
return ((cpc_byte & 0x01) << 1) | ((cpc_byte & 0x10) >> 4);
else
error("Invalid index %d requested", index);
}
byte getCPCPixelMode0(byte cpc_byte, int index) {
if (index == 0) {
// Extract Pixel 0 from the byte
return ((cpc_byte & 0x02) >> 1) | // Bit 1 -> Bit 3 (MSB)
((cpc_byte & 0x20) >> 4) | // Bit 5 -> Bit 2
((cpc_byte & 0x08) >> 1) | // Bit 3 -> Bit 1
((cpc_byte & 0x80) >> 7); // Bit 7 -> Bit 0 (LSB)
}
else if (index == 2) {
// Extract Pixel 1 from the byte
return ((cpc_byte & 0x01) << 3) | // Bit 0 -> Bit 3 (MSB)
((cpc_byte & 0x10) >> 2) | // Bit 4 -> Bit 2
((cpc_byte & 0x04) >> 1) | // Bit 2 -> Bit 1
((cpc_byte & 0x40) >> 6); // Bit 6 -> Bit 0 (LSB)
}
else {
error("Invalid index %d requested", index);
}
}
byte getCPCPixel(byte cpc_byte, int index, bool mode1) {
if (mode1)
return getCPCPixelMode1(cpc_byte, index);
else
return getCPCPixelMode0(cpc_byte, index);
}
Graphics::ManagedSurface *readCPCImage(Common::SeekableReadStream *file, bool mode1) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
surface->fillRect(Common::Rect(0, 0, 320, 200), 0);
int x, y;
file->seek(0x80);
for (int block = 0; block < 8; block++) {
for (int line = 0; line < 25; line++) {
for (int offset = 0; offset < 320 / 4; offset++) {
byte cpc_byte = file->readByte(); // Get CPC byte
// Process first pixel
int pixel_0 = getCPCPixel(cpc_byte, 0, mode1); // %Aa
y = line * 8 + block ; // Coord Y for the pixel
x = 4 * offset + 0; // Coord X for the pixel
surface->setPixel(x, y, pixel_0);
// Process second pixel
y = line * 8 + block ; // Coord Y for the pixel
x = 4 * offset + 1; // Coord X for the pixel
if (mode1) {
int pixel_1 = getCPCPixel(cpc_byte, 1, mode1); // %Bb
surface->setPixel(x, y, pixel_1);
} else
surface->setPixel(x, y, pixel_0);
// Process third pixel
int pixel_2 = getCPCPixel(cpc_byte, 2, mode1); // %Cc
y = line * 8 + block ; // Coord Y for the pixel
x = 4 * offset + 2; // Coord X for the pixel
surface->setPixel(x, y, pixel_2);
// Process fourth pixel
y = line * 8 + block ; // Coord Y for the pixel
x = 4 * offset + 3; // Coord X for the pixel
if (mode1) {
int pixel_3 = getCPCPixel(cpc_byte, 3, mode1); // %Dd
surface->setPixel(x, y, pixel_3);
} else
surface->setPixel(x, y, pixel_2);
}
}
// We should skip the next 48 bytes, because they are padding the block to be 2048 bytes
file->seek(48, SEEK_CUR);
}
return surface;
}
void DrillerEngine::loadAssetsCPCFullGame() {
Common::File file;
file.open("DSCN1.BIN");
if (!file.isOpen())
error("Failed to open DSCN1.BIN");
_title = readCPCImage(&file, true);
_title->setPalette((byte*)&kCPCPaletteTitleData, 0, 4);
file.close();
file.open("DSCN2.BIN");
if (!file.isOpen())
error("Failed to open DSCN2.BIN");
_border = readCPCImage(&file, true);
_border->setPalette((byte*)&kCPCPaletteBorderData, 0, 4);
file.close();
file.open("DRILL.BIN");
if (!file.isOpen())
error("Failed to open DRILL.BIN");
loadMessagesFixedSize(&file, 0x214c, 14, 20);
loadFonts(&file, 0x5b69);
loadGlobalObjects(&file, 0x1d07, 8);
load8bitBinary(&file, 0x5ccb, 16);
}
void DrillerEngine::drawCPCUI(Graphics::Surface *surface) {
uint32 color = _currentArea->_underFireBackgroundColor;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_usualBackgroundColor;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int score = _gameStateVars[k8bitVariableScore];
drawStringInSurface(_currentArea->_name, 200, 185, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 151, 145, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 151, 153, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 151, 161, front, back, surface);
if (_playerHeightNumber >= 0)
drawStringInSurface(Common::String::format("%d", _playerHeightNumber), 54, 161, front, back, surface);
else
drawStringInSurface(Common::String::format("%s", "J"), 54, 161, front, back, surface);
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 47, 145, front, back, surface);
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 44, 153, front, back, surface);
drawStringInSurface(Common::String::format("%07d", score), 239, 129, front, back, surface);
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
drawStringInSurface(Common::String::format("%02d", hours), 209, 8, front, back, surface);
drawStringInSurface(Common::String::format("%02d", minutes), 232, 8, front, back, surface);
drawStringInSurface(Common::String::format("%02d", seconds), 255, 8, front, back, surface);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 191, 177, back, front, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else if (_messagesList.size() > 0) {
if (_currentArea->_gasPocketRadius == 0)
message = _messagesList[2];
else if (_drillStatusByArea[_currentArea->getAreaID()])
message = _messagesList[0];
else
message = _messagesList[1];
drawStringInSurface(message, 191, 177, front, back, surface);
}
int energy = _gameStateVars[k8bitVariableEnergy];
int shield = _gameStateVars[k8bitVariableShield];
if (energy >= 0) {
Common::Rect backBar(25, 184, 89 - energy, 191);
surface->fillRect(backBar, back);
Common::Rect energyBar(88 - energy, 184, 88, 191);
surface->fillRect(energyBar, front);
}
if (shield >= 0) {
Common::Rect backBar(25, 177, 89 - shield, 183);
surface->fillRect(backBar, back);
Common::Rect shieldBar(88 - shield, 177, 88, 183);
surface->fillRect(shieldBar, front);
}
drawCompass(surface, 87, 156, _yaw - 30, 10, 75, front);
drawCompass(surface, 230, 156, _pitch - 30, 10, 60, front);
}
} // End of namespace Freescape

View File

@@ -0,0 +1,457 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/driller/driller.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
extern byte kEGADefaultPalette[16][3];
extern byte kCGAPaletteRedGreen[4][3];
extern byte kCGAPalettePinkBlue[4][3];
extern byte kHerculesPaletteGreen[2][3];
void DrillerEngine::initDOS() {
if (_renderMode == Common::kRenderEGA)
_viewArea = Common::Rect(40, 16, 280, 117);
else if (_renderMode == Common::kRenderHercG)
_viewArea = Common::Rect(112, 64, 607, 224);
else if (_renderMode == Common::kRenderCGA)
_viewArea = Common::Rect(36, 16, 284, 117);
else
error("Invalid or unknown render mode");
_moveFowardArea = Common::Rect(73, 144, 101, 152);
_moveLeftArea = Common::Rect(73, 150, 86, 159);
_moveRightArea = Common::Rect(88, 152, 104, 160);
_moveBackArea = Common::Rect(73, 160, 101, 168);
_moveUpArea = Common::Rect(219, 144, 243, 155);
_moveDownArea = Common::Rect(219, 157, 243, 167);
_deployDrillArea = Common::Rect(140, 175, 179, 191);
_infoScreenArea = Common::Rect(130, 125, 188, 144);
_soundIndexShoot = 1;
_soundIndexCollide = 2;
_soundIndexStepDown = 3;
_soundIndexStepUp = 4;
_soundIndexMenu = 2;
_soundIndexStart = 9;
_soundIndexAreaChange = 5;
_soundIndexHit = 2;
_soundIndexFall = 14;
_soundIndexNoShield = 20;
_soundIndexNoEnergy = 20;
_soundIndexFallen = 20;
_soundIndexTimeout = 20;
_soundIndexForceEndGame = 20;
_soundIndexCrushed = 20;
}
/*
The following functions are only used for decoding title images for
the US release of Driller ("Space Station Oblivion")
*/
uint32 DrillerEngine::getPixel8bitTitleImage(int index) {
if (index < 4 || _renderMode == Common::kRenderEGA) {
return index;
}
return index / 4;
}
void DrillerEngine::renderPixels8bitTitleImage(Graphics::ManagedSurface *surface, int &x, int &y, int pixels) {
int c1 = pixels >> 4;
int c2 = pixels & 0xf;
if (x == 320) {
return;
}
if (_renderMode == Common::kRenderCGA) {
surface->setPixel(x, y, getPixel8bitTitleImage(c1 / 4));
x++;
if (x == 320) {
return;
}
}
surface->setPixel(x, y, getPixel8bitTitleImage(c1));
x++;
if (x == 320) {
return;
}
if (_renderMode == Common::kRenderCGA) {
surface->setPixel(x, y, getPixel8bitTitleImage(c2 / 4));
x++;
if (x == 320) {
return;
}
}
surface->setPixel(x, y, getPixel8bitTitleImage(c2));
x++;
}
Graphics::ManagedSurface *DrillerEngine::load8bitTitleImage(Common::SeekableReadStream *file, int offset) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(_screenW, _screenH, Graphics::PixelFormat::createFormatCLUT8());
surface->fillRect(Common::Rect(0, 0, 320, 200), 0);
file->seek(offset);
for (int y = 0; y < 200; ++y) {
if (file->eos ()) break;
// Start of line data (0x02) or [premature] end of data (0x00)
int sol = file->readByte();
if (sol == 0) break;
assert(sol == 2);
int x = 0;
while (x < 320) {
int command = file->readByte();
if (command & 0x80) {
// Copy 2*N bytes verbatim
int repeat = (257 - command) * 2;
for (int i = 0; i < repeat; ++i) {
int pixels = file->readByte();
renderPixels8bitTitleImage(surface, x, y, pixels);
}
} else {
// Repeat 2 bytes of the input N times
int repeat = command + 1;
int pixels1 = file->readByte();
int pixels2 = file->readByte();
for (int i = 0; i < repeat; ++i) {
renderPixels8bitTitleImage(surface, x, y, pixels1);
renderPixels8bitTitleImage(surface, x, y, pixels2);
}
}
}
}
return surface;
}
byte kCGAPalettePinkBlueWhiteData[4][3] = {
{0x00, 0x00, 0x00},
{0x55, 0xff, 0xff},
{0xff, 0x55, 0xff},
{0xff, 0xff, 0xff},
};
/*
The following function is only used for decoding images for
the Driller DOS demo
*/
Graphics::ManagedSurface *DrillerEngine::load8bitDemoImage(Common::SeekableReadStream *file, int offset) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(320, 200, Graphics::PixelFormat::createFormatCLUT8());
surface->fillRect(Common::Rect(0, 0, 320, 200), 0);
file->seek(offset);
int i = 0;
int j = 0;
while (true) {
byte pixels = file->readByte();
for (int b = 0; b < 4; b++) {
int color = pixels & 3;
pixels = pixels >> 2;
surface->setPixel(i + (3 - b), 2 * j, color);
}
i = i + 4;
if (i == 320) {
i = 0;
j++;
}
if (j == 100)
break;
}
file->seek(0xc0, SEEK_CUR);
i = 0;
j = 0;
while (true) {
byte pixels = file->readByte();
for (int b = 0; b < 4; b++) {
int color = pixels & 3;
pixels = pixels >> 2;
surface->setPixel(i + (3 - b), 2 * j + 1, color);
}
i = i + 4;
if (i == 320) {
i = 0;
j++;
}
if (j == 100)
break;
}
return surface;
}
void DrillerEngine::loadAssetsDOSFullGame() {
Common::File file;
if (_renderMode == Common::kRenderEGA) {
file.open("SCN1E.DAT");
if (file.isOpen()) {
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte*)&kEGADefaultPalette, 0, 16);
}
file.close();
file.open("EGATITLE.RL");
if (file.isOpen()) {
_title = load8bitTitleImage(&file, 0x1b2);
_title->setPalette((byte*)&kEGADefaultPalette, 0, 16);
}
file.close();
file.open("DRILLE.EXE");
if (!file.isOpen())
error("Failed to open DRILLE.EXE");
loadSpeakerFxDOS(&file, 0x4397 + 0x200, 0x4324 + 0x200, 20);
loadMessagesFixedSize(&file, 0x4135, 14, 20);
loadFonts(&file, 0x99dd);
loadGlobalObjects(&file, 0x3b42, 8);
load8bitBinary(&file, 0x9b40, 16);
_border = load8bitBinImage(&file, 0x210);
_border->setPalette((byte*)&kEGADefaultPalette, 0, 16);
} else if (_renderMode == Common::kRenderCGA) {
file.open("SCN1C.DAT");
if (file.isOpen()) {
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
}
file.close();
file.open("CGATITLE.RL");
if (file.isOpen()) {
_title = load8bitTitleImage(&file, 0x1b2);
_title->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
}
file.close();
file.open("DRILLC.EXE");
if (!file.isOpen())
error("Failed to open DRILLC.EXE");
loadSpeakerFxDOS(&file, 0x27e7 + 0x200, 0x2774 + 0x200, 20);
loadFonts(&file, 0x07a4a);
loadMessagesFixedSize(&file, 0x2585, 14, 20);
loadGlobalObjects(&file, 0x1fa2, 8);
load8bitBinary(&file, 0x7bb0, 4);
_border = load8bitBinImage(&file, 0x210);
_border->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
swapPalette(1);
} else if (_renderMode == Common::kRenderHercG) {
file.open("SCN1H.DAT");
if (file.isOpen()) {
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte*)&kHerculesPaletteGreen, 0, 2);
}
file.close();
file.open("DRILLH.EXE");
if (!file.isOpen())
error("Failed to open DRILLH.EXE");
//loadSpeakerFxDOS(&file, 0x27e7 + 0x200, 0x2774 + 0x200, 20);
loadFonts(&file, 0x8871);
loadMessagesFixedSize(&file, 0x3411, 14, 20);
load8bitBinary(&file, 0x89e0, 4);
loadGlobalObjects(&file, 0x2d02, 8);
_border = load8bitBinImage(&file, 0x210);
_border->setPalette((byte*)&kHerculesPaletteGreen, 0, 2);
} else
error("Unsupported video mode for DOS");
if (_renderMode != Common::kRenderHercG) {
_indicators.push_back(loadBundledImage("driller_tank_indicator"));
_indicators.push_back(loadBundledImage("driller_ship_indicator"));
_indicators[0]->convertToInPlace(_gfx->_texturePixelFormat);
_indicators[1]->convertToInPlace(_gfx->_texturePixelFormat);
}
}
void DrillerEngine::loadAssetsDOSDemo() {
Common::File file;
_renderMode = Common::kRenderCGA; // DOS demos is CGA only
_viewArea = Common::Rect(36, 16, 284, 117); // correct view area
_gfx->_renderMode = _renderMode;
file.open("d1");
if (!file.isOpen())
error("Failed to open 'd1' file");
_title = load8bitDemoImage(&file, 0x0);
_title->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
file.close();
file.open("d2");
if (!file.isOpen())
error("Failed to open 'd2' file");
loadFonts(&file, 0x4eb0);
loadMessagesFixedSize(&file, 0x636, 14, 20);
loadGlobalObjects(&file, 0x53, 8);
load8bitBinary(&file, 0x55b0, 4);
_border = load8bitDemoImage(&file, 0x6220);
_border->setPalette((byte*)&kCGAPalettePinkBlueWhiteData, 0, 4);
// Fixes corrupted area names in the demo data
_areaMap[2]->_name = "LAPIS LAZULI";
_areaMap[3]->_name = "EMERALD";
_areaMap[8]->_name = "TOPAZ";
file.close();
_indicators.push_back(loadBundledImage("driller_tank_indicator"));
_indicators.push_back(loadBundledImage("driller_ship_indicator"));
_indicators[0]->convertToInPlace(_gfx->_texturePixelFormat);
_indicators[1]->convertToInPlace(_gfx->_texturePixelFormat);
}
void DrillerEngine::drawDOSUI(Graphics::Surface *surface) {
uint32 color = _renderMode == Common::kRenderCGA || _renderMode == Common::kRenderHercG ? 1 : 14;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_usualBackgroundColor;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int score = _gameStateVars[k8bitVariableScore];
Common::Point currentAreaPos = _renderMode == Common::kRenderHercG ? Common::Point(437, 293) : Common::Point(197, 185);
drawStringInSurface(_currentArea->_name, currentAreaPos.x, currentAreaPos.y, front, back, surface);
Common::Point coordinateXPos = _renderMode == Common::kRenderHercG ? Common::Point(345, 253) : Common::Point(151, 145);
Common::Point coordinateYPos = _renderMode == Common::kRenderHercG ? Common::Point(345, 261) : Common::Point(151, 153);
Common::Point coordinateZPos = _renderMode == Common::kRenderHercG ? Common::Point(345, 269) : Common::Point(151, 161);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), coordinateXPos.x, coordinateXPos.y, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), coordinateYPos.x, coordinateYPos.y, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), coordinateZPos.x, coordinateZPos.y, front, back, surface);
Common::Point playerHeightPos = _renderMode == Common::kRenderHercG ? Common::Point(157, 269) : Common::Point(57, 161);
if (_playerHeightNumber >= 0)
drawStringInSurface(Common::String::format("%d", _playerHeightNumber), playerHeightPos.x, playerHeightPos.y, front, back, surface);
else
drawStringInSurface(Common::String::format("%s", "J"), playerHeightPos.x, playerHeightPos.y, front, back, surface);
Common::Point anglePos = _renderMode == Common::kRenderHercG ? Common::Point(141, 253) : Common::Point(47, 145);
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), anglePos.x, anglePos.y, front, back, surface);
Common::Point playerStepsPos;
if (_renderMode == Common::kRenderHercG)
playerStepsPos = Common::Point(130, 261);
else if (_renderMode == Common::kRenderCGA)
playerStepsPos = Common::Point(44, 153);
else
playerStepsPos = Common::Point(47, 153);
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), playerStepsPos.x, playerStepsPos.y, front, back, surface);
Common::Point scorePos = _renderMode == Common::kRenderHercG ? Common::Point(522, 237) : Common::Point(239, 129);
drawStringInSurface(Common::String::format("%07d", score), scorePos.x, scorePos.y, front, back, surface);
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
Common::Point hoursPos = _renderMode == Common::kRenderHercG ? Common::Point(462, 56) : Common::Point(208, 8);
drawStringInSurface(Common::String::format("%02d", hours), hoursPos.x, hoursPos.y, front, back, surface);
Common::Point minutesPos = _renderMode == Common::kRenderHercG ? Common::Point(506, 56) : Common::Point(231, 8);
drawStringInSurface(Common::String::format("%02d", minutes), minutesPos.x, minutesPos.y, front, back, surface);
Common::Point secondsPos = _renderMode == Common::kRenderHercG ? Common::Point(554, 56) : Common::Point(255, 8);
drawStringInSurface(Common::String::format("%02d", seconds), secondsPos.x, secondsPos.y, front, back, surface);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
Common::Point messagePos = _renderMode == Common::kRenderHercG ? Common::Point(424, 285) : Common::Point(191, 177);
if (deadline <= _countdown) {
drawStringInSurface(message, messagePos.x, messagePos.y, back, front, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_currentArea->_gasPocketRadius == 0)
message = _messagesList[2];
else if (_drillStatusByArea[_currentArea->getAreaID()])
message = _messagesList[0];
else
message = _messagesList[1];
drawStringInSurface(message, messagePos.x, messagePos.y, front, back, surface);
}
int energy = _gameStateVars[k8bitVariableEnergy];
int shield = _gameStateVars[k8bitVariableShield];
if (_renderMode != Common::kRenderHercG) {
if (energy >= 0) {
Common::Rect backBar(20, 185, 88 - energy, 191);
surface->fillRect(backBar, back);
Common::Rect energyBar(87 - energy, 185, 88, 191);
surface->fillRect(energyBar, front);
}
if (shield >= 0) {
Common::Rect backBar(20, 177, 88 - shield, 183);
surface->fillRect(backBar, back);
Common::Rect shieldBar(87 - shield, 177, 88, 183);
surface->fillRect(shieldBar, front);
}
}
if (_indicators.size() >= 2) {
if (!_flyMode)
surface->copyRectToSurface(*_indicators[0], 132, 127, Common::Rect(_indicators[0]->w, _indicators[0]->h));
else
surface->copyRectToSurface(*_indicators[1], 132, 127, Common::Rect(_indicators[1]->w, _indicators[1]->h));
}
color = _renderMode == Common::kRenderHercG ? 1 : 2;
_gfx->readFromPalette(color, r, g, b);
uint32 other = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
Common::Point compassYawPos = _renderMode == Common::kRenderHercG ? Common::Point(214, 264) : Common::Point(87, 156);
drawCompass(surface, compassYawPos.x, compassYawPos.y, _yaw - 30, 10, 75, other);
Common::Point compassPitchPos = _renderMode == Common::kRenderHercG ? Common::Point(502, 264) : Common::Point(230, 156);
drawCompass(surface, compassPitchPos.x, compassPitchPos.y, _pitch - 30, 10, 60, other);
}
} // End of namespace Freescape

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,134 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "audio/audiostream.h"
#include "audio/mixer.h"
#include "engines/freescape/games/driller/c64.music.h"
namespace Freescape {
enum DrillerFontSize {
kDrillerFontSmall,
kDrillerFontNormal,
};
class DrillerEngine : public FreescapeEngine {
public:
DrillerEngine(OSystem *syst, const ADGameDescription *gd);
~DrillerEngine();
uint32 _initialJetEnergy;
uint32 _initialJetShield;
uint32 _initialTankEnergy;
uint32 _initialTankShield;
bool _useAutomaticDrilling;
DrillerSIDPlayer *_playerSid;
// Only used for Amiga and Atari ST
Font _fontSmall;
void drawString(const DrillerFontSize size, const Common::String &str, int x, int y, uint32 primaryColor, uint32 secondaryColor, uint32 backColor, Graphics::Surface *surface);
Common::HashMap<uint16, uint32> _drillStatusByArea;
Common::HashMap<uint16, uint32> _drillMaxScoreByArea;
Common::HashMap<uint16, uint32> _drillSuccessByArea;
void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
void initGameState() override;
bool checkIfGameEnded() override;
void endGame() override;
void gotoArea(uint16 areaID, int entranceID) override;
void drawInfoMenu() override;
void drawSensorShoot(Sensor *sensor) override;
void drawCompass(Graphics::Surface *surface, int x, int y, double degrees, double magnitude, double fov, uint32 color);
void pressedKey(const int keycode) override;
Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false) override;
Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override;
private:
bool drillDeployed(Area *area);
GeometricObject *_drillBase;
Math::Vector3d drillPosition();
void addDrill(const Math::Vector3d position, bool gasFound);
bool checkDrill(const Math::Vector3d position);
void removeDrill(Area *area);
void addSkanner(Area *area);
void loadAssets() override;
void loadAssetsAtariFullGame() override;
void loadAssetsAtariDemo() override;
void loadAssetsAmigaFullGame() override;
void loadAssetsAmigaDemo() override;
void loadAssetsDOSFullGame() override;
void loadAssetsDOSDemo() override;
void loadAssetsZXFullGame() override;
void loadAssetsCPCFullGame() override;
void loadAssetsC64FullGame() override;
void drawDOSUI(Graphics::Surface *surface) override;
void drawZXUI(Graphics::Surface *surface) override;
void drawCPCUI(Graphics::Surface *surface) override;
void drawC64UI(Graphics::Surface *surface) override;
void drawAmigaAtariSTUI(Graphics::Surface *surface) override;
bool onScreenControls(Common::Point mouse) override;
void initAmigaAtari();
void initDOS();
void initZX();
void initCPC();
void initC64();
void updateTimeVariables() override;
Common::Rect _moveFowardArea;
Common::Rect _moveLeftArea;
Common::Rect _moveRightArea;
Common::Rect _moveBackArea;
Common::Rect _moveUpArea;
Common::Rect _moveDownArea;
Common::Rect _deployDrillArea;
Common::Rect _infoScreenArea;
Common::Rect _saveGameArea;
Common::Rect _loadGameArea;
Graphics::ManagedSurface *load8bitTitleImage(Common::SeekableReadStream *file, int offset);
Graphics::ManagedSurface *load8bitDemoImage(Common::SeekableReadStream *file, int offset);
uint32 getPixel8bitTitleImage(int index);
void renderPixels8bitTitleImage(Graphics::ManagedSurface *surface, int &i, int &j, int pixels);
Graphics::ManagedSurface *_borderExtra;
Texture *_borderExtraTexture;
Common::SeekableReadStream *decryptFileAtari(const Common::Path &filename);
Common::SeekableReadStream *decryptFileAtariVirtualWorlds(const Common::Path &filename);
};
enum DrillerReleaseFlags {
GF_AMIGA_MAGAZINE_DEMO = (1 << 0),
GF_ATARI_MAGAZINE_DEMO = (1 << 1),
};
}

View File

@@ -0,0 +1,160 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/driller/driller.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void DrillerEngine::initZX() {
_viewArea = Common::Rect(56, 20, 264, 124);
_soundIndexAreaChange = 10;
}
void DrillerEngine::loadAssetsZXFullGame() {
Common::File file;
file.open("driller.zx.title");
if (file.isOpen()) {
_title = loadAndConvertScrImage(&file);
} else
error("Unable to find driller.zx.title");
file.close();
file.open("driller.zx.border");
if (file.isOpen()) {
_border = loadAndConvertScrImage(&file);
} else
error("Unable to find driller.zx.border");
file.close();
file.open("driller.zx.data");
if (!file.isOpen())
error("Failed to open driller.zx.data");
if (_variant & GF_ZX_DISC)
loadMessagesFixedSize(&file, 0x2164, 14, 20);
else
loadMessagesFixedSize(&file, 0x20e4, 14, 20);
if (_variant & GF_ZX_RETAIL)
loadFonts(&file, 0x62ca);
else if (_variant & GF_ZX_BUDGET)
loadFonts(&file, 0x5aa8);
else if (_variant & GF_ZX_DISC)
loadFonts(&file, 0x63f0);
if (_variant & GF_ZX_DISC)
loadGlobalObjects(&file, 0x1d13, 8);
else
loadGlobalObjects(&file, 0x1c93, 8);
if (_variant & GF_ZX_RETAIL)
load8bitBinary(&file, 0x642c, 4);
else if (_variant & GF_ZX_BUDGET)
load8bitBinary(&file, 0x5c0a, 4);
else if (_variant & GF_ZX_DISC)
load8bitBinary(&file, 0x6552, 4);
else
error("Unknown ZX spectrum variant");
}
void DrillerEngine::drawZXUI(Graphics::Surface *surface) {
uint32 color = 5;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_usualBackgroundColor;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0xFF);
int score = _gameStateVars[k8bitVariableScore];
drawStringInSurface(_currentArea->_name, 174, 188, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.x())), 151, 149, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.z())), 151, 157, front, back, surface);
drawStringInSurface(Common::String::format("%04d", int(2 * _position.y())), 151, 165, front, back, surface);
if (_playerHeightNumber >= 0)
drawStringInSurface(Common::String::format("%d", _playerHeightNumber), 72, 165, front, back, surface);
else
drawStringInSurface(Common::String::format("%s", "J"), 72, 165, front, back, surface);
drawStringInSurface(Common::String::format("%02d", int(_angleRotations[_angleRotationIndex])), 63, 149, front, back, surface);
drawStringInSurface(Common::String::format("%3d", _playerSteps[_playerStepIndex]), 63, 157, front, back, surface);
drawStringInSurface(Common::String::format("%07d", score), 215, 133, white, back, surface);
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
drawStringInSurface(Common::String::format("%02d", hours), 185, 12, front, back, surface);
drawStringInSurface(Common::String::format("%02d", minutes), 207, 12, front, back, surface);
drawStringInSurface(Common::String::format("%02d", seconds), 231, 12, front, back, surface);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 168, 181, back, front, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_currentArea->_gasPocketRadius == 0)
message = _messagesList[2];
else if (_drillStatusByArea[_currentArea->getAreaID()])
message = _messagesList[0];
else
message = _messagesList[1];
drawStringInSurface(message, 168, 181, front, back, surface);
}
int energy = _gameStateVars[k8bitVariableEnergy];
int shield = _gameStateVars[k8bitVariableShield];
if (energy >= 0) {
Common::Rect backBar(43, 188, 107 - energy, 194);
surface->fillRect(backBar, back);
Common::Rect energyBar(106 - energy, 188, 106, 194);
surface->fillRect(energyBar, front);
}
if (shield >= 0) {
Common::Rect backBar(43, 181, 107 - shield, 187);
surface->fillRect(backBar, back);
Common::Rect shieldBar(106 - shield, 181, 106, 187);
surface->fillRect(shieldBar, front);
}
drawCompass(surface, 103, 160, _yaw - 30, 10, 75, front);
drawCompass(surface, 220 - 3, 160, _pitch - 30, 10, 60, front);
}
} // End of namespace Freescape

View File

@@ -0,0 +1,190 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "freescape/freescape.h"
#include "freescape/games/eclipse/eclipse.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void EclipseEngine::initAmigaAtari() {
_viewArea = Common::Rect(32, 16, 288, 118);
}
/*void EclipseEngine::loadAssetsCPCFullGame() {
Common::File file;
if (isEclipse2())
file.open("TE2.BI1");
else
file.open("TESCR.SCR");
if (!file.isOpen())
error("Failed to open TESCR.SCR/TE2.BI1");
_title = readCPCImage(&file, true);
_title->setPalette((byte*)&kCPCPaletteTitleData, 0, 4);
file.close();
if (isEclipse2())
file.open("TE2.BI3");
else
file.open("TECON.SCR");
if (!file.isOpen())
error("Failed to open TECON.SCR/TE2.BI3");
_border = readCPCImage(&file, true);
_border->setPalette((byte*)&kCPCPaletteTitleData, 0, 4);
file.close();
if (isEclipse2())
file.open("TE2.BI2");
else
file.open("TECODE.BIN");
if (!file.isOpen())
error("Failed to open TECODE.BIN/TE2.BI2");
if (isEclipse2()) {
loadFonts(&file, 0x60bc, _font);
loadMessagesFixedSize(&file, 0x326, 16, 30);
load8bitBinary(&file, 0x62b4, 16);
} else {
loadFonts(&file, 0x6076, _font);
loadMessagesFixedSize(&file, 0x326, 16, 30);
load8bitBinary(&file, 0x626e, 16);
}
for (auto &it : _areaMap) {
it._value->addStructure(_areaMap[255]);
if (isEclipse2() && it._value->getAreaID() == 1)
continue;
if (isEclipse2() && it._value->getAreaID() == _startArea)
continue;
for (int16 id = 183; id < 207; id++)
it._value->addObjectFromArea(id, _areaMap[255]);
}
loadColorPalette();
swapPalette(1);
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
void EclipseEngine::drawCPCUI(Graphics::Surface *surface) {
uint32 color = _currentArea->_underFireBackgroundColor;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_usualBackgroundColor;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_inkColor;
_gfx->readFromPalette(color, r, g, b);
uint32 other = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int score = _gameStateVars[k8bitVariableScore];
int shield = _gameStateVars[k8bitVariableShield] * 100 / _maxShield;
shield = shield < 0 ? 0 : shield;
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 102, 135, back, front, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else if (!_currentAreaMessages.empty())
drawStringInSurface(_currentArea->_name, 102, 135, back, front, surface);
Common::String scoreStr = Common::String::format("%07d", score);
drawStringInSurface(scoreStr, 136, 6, back, other, surface, 'Z' - '0' + 1);
int x = 171;
if (shield < 10)
x = 179;
else if (shield < 100)
x = 175;
Common::String shieldStr = Common::String::format("%d", shield);
drawStringInSurface(shieldStr, x, 162, back, other, surface);
drawStringInSurface(Common::String('0' + _angleRotationIndex - 3), 79, 135, back, front, surface, 'Z' - '$' + 1);
drawStringInSurface(Common::String('3' - _playerStepIndex), 63, 135, back, front, surface, 'Z' - '$' + 1);
drawStringInSurface(Common::String('7' - _playerHeightNumber), 240, 135, back, front, surface, 'Z' - '$' + 1);
if (_shootingFrames > 0) {
drawStringInSurface("4", 232, 135, back, front, surface, 'Z' - '$' + 1);
drawStringInSurface("<", 240, 135, back, front, surface, 'Z' - '$' + 1);
}
drawAnalogClock(surface, 90, 172, back, other, front);
drawIndicator(surface, 45, 4, 12);
drawEclipseIndicator(surface, 228, 0, front, other);
}*/
void EclipseEngine::loadAssetsAtariFullGame() {
Common::File file;
file.open("0.tec");
_title = loadAndConvertNeoImage(&file, 0x17ac);
file.close();
Common::SeekableReadStream *stream = decryptFileAmigaAtari("1.tec", "0.tec", 0x1774 - 4 * 1024);
parseAmigaAtariHeader(stream);
loadMessagesVariableSize(stream, 0x87a6, 28);
load8bitBinary(stream, 0x2a53c, 16);
_border = loadAndConvertNeoImage(stream, 0x139c8);
loadPalettes(stream, 0x2a0fa);
loadSoundsFx(stream, 0x3030c, 6);
/*
loadFonts(stream, 0xd06b, _fontBig);
loadFonts(stream, 0xd49a, _fontMedium);
loadFonts(stream, 0xd49b, _fontSmall);
load8bitBinary(stream, 0x20918, 16);
loadMessagesVariableSize(stream, 0x3f6f, 66);
loadPalettes(stream, 0x204d6);
loadGlobalObjects(stream, 0x32f6, 24);
loadSoundsFx(stream, 0x266e8, 11);*/
}
} // End of namespace Freescape

View File

@@ -0,0 +1,180 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/eclipse/eclipse.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void EclipseEngine::initC64() {
_viewArea = Common::Rect(32, 32, 288, 136);
_maxEnergy = 35;
}
extern byte kC64Palette[16][3];
void EclipseEngine::loadAssetsC64FullGame() {
Common::File file;
file.open(isEclipse2() ? "totaleclipse2.c64.data" : "totaleclipse.c64.data");
if (_variant & GF_C64_TAPE) {
int size = file.size();
byte *buffer = (byte *)malloc(size * sizeof(byte));
file.read(buffer, file.size());
_extraBuffer = decompressC64RLE(buffer, &size, isEclipse2() ? 0xd2 : 0xe1);
// size should be the size of the decompressed data
Common::MemoryReadStream dfile(_extraBuffer, size, DisposeAfterUse::NO);
loadMessagesFixedSize(&dfile, 0x1d84, 16, 30);
loadFonts(&dfile, 0xc3e);
load8bitBinary(&dfile, 0x9a3e, 16);
} else if (_variant & GF_C64_DISC) {
loadMessagesFixedSize(&file, 0x1534, 16, 30);
loadFonts(&file, 0x3f2);
if (isEclipse2())
load8bitBinary(&file, 0x7ac4, 16);
else
load8bitBinary(&file, 0x7ab4, 16);
} else
error("Unknown C64 variant %x", _variant);
Graphics::Surface *surf = loadBundledImage("eclipse_border");
surf->convertToInPlace(_gfx->_texturePixelFormat);
_border = new Graphics::ManagedSurface();
_border->copyFrom(*surf);
surf->free();
delete surf;
file.close();
file.open(isEclipse2() ? "totaleclipse2.c64.title.bitmap" : "totaleclipse.c64.title.bitmap");
Common::File colorFile1;
colorFile1.open(isEclipse2() ? "totaleclipse2.c64.title.colors1" : "totaleclipse.c64.title.colors1");
Common::File colorFile2;
colorFile2.open(isEclipse2() ? "totaleclipse2.c64.title.colors2" : "totaleclipse.c64.title.colors2");
_title = loadAndConvertDoodleImage(&file, &colorFile1, &colorFile2, (byte *)&kC64Palette);
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
void EclipseEngine::drawC64UI(Graphics::Surface *surface) {
uint32 color = _currentArea->_underFireBackgroundColor;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_usualBackgroundColor;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(13, r, g, b);
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(3, r, g, b);
uint32 blue = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(2, r, g, b);
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(0, r, g, b);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(1, r, g, b);
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int score = _gameStateVars[k8bitVariableScore];
int shield = _gameStateVars[k8bitVariableShield] * 100 / _maxShield;
int energy = _gameStateVars[k8bitVariableEnergy];
shield = shield < 0 ? 0 : shield;
_gfx->readFromPalette(7, r, g, b);
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 104, 138, back, yellow, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else if (!_currentAreaMessages.empty())
drawStringInSurface(_currentArea->_name, 104, 138, back, yellow, surface);
drawScoreString(score, 128, 7, black, white, surface);
Common::String shieldStr = Common::String::format("%d", shield);
int x = 174;
if (shield < 10)
x = 182;
else if (shield < 100)
x = 179;
if (energy < 0)
energy = 0;
drawStringInSurface(shieldStr, x, 161, back, red, surface);
Common::Rect jarBackground(112, 170, 144, 196);
surface->fillRect(jarBackground, back);
Common::Rect jarWater(112, 196 - energy, 144, 196);
surface->fillRect(jarWater, blue);
// TODO
/*drawStringInSurface(shiftStr("0", 'Z' - '$' + 1 - _angleRotationIndex), 79, 138, back, yellow, surface);
drawStringInSurface(shiftStr("3", 'Z' - '$' + 1 - _playerStepIndex), 63, 138, back, yellow, surface);
drawStringInSurface(shiftStr("7", 'Z' - '$' + 1 - _playerHeightNumber), 240, 138, back, yellow, surface);
if (_shootingFrames > 0) {
drawStringInSurface(shiftStr("4", 'Z' - '$' + 1), 232, 138, back, yellow, surface);
drawStringInSurface(shiftStr("<", 'Z' - '$' + 1) , 240, 138, back, yellow, surface);
}*/
drawAnalogClockHand(surface, 72, 172, 38 * 6 - 90, 11, white);
drawAnalogClockHand(surface, 72, 172, 37 * 6 - 90, 11, white);
drawAnalogClockHand(surface, 72, 172, 36 * 6 - 90, 11, white);
drawAnalogClock(surface, 72, 172, back, red, white);
surface->fillRect(Common::Rect(236, 170, 258, 187), white);
drawCompass(surface, 247, 177, _yaw, 13, back);
drawIndicator(surface, 56, 4, 8);
drawEclipseIndicator(surface, 224, 0, front, green);
}
} // End of namespace Freescape

View File

@@ -0,0 +1,203 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "freescape/freescape.h"
#include "freescape/games/eclipse/eclipse.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void EclipseEngine::initCPC() {
_viewArea = Common::Rect(36 + 3, 24 + 8, 284, 130 + 3);
}
byte kCPCPaletteEclipseTitleData[4][3] = {
{0x00, 0x00, 0x00},
{0xff, 0xff, 0x00},
{0xff, 0x00, 0xff},
{0xff, 0x80, 0x00},
};
byte kCPCPaletteEclipseBorderData[4][3] = {
{0x00, 0x00, 0x00},
{0xff, 0x80, 0x00},
{0x80, 0xff, 0xff},
{0x00, 0x80, 0x00},
};
extern Graphics::ManagedSurface *readCPCImage(Common::SeekableReadStream *file, bool mode0);
void EclipseEngine::loadAssetsCPCFullGame() {
Common::File file;
if (isEclipse2())
file.open("TE2.BI1");
else
file.open("TESCR.SCR");
if (!file.isOpen())
error("Failed to open TESCR.SCR/TE2.BI1");
_title = readCPCImage(&file, true);
_title->setPalette((byte*)&kCPCPaletteEclipseTitleData, 0, 4);
file.close();
if (isEclipse2())
file.open("TE2.BI3");
else
file.open("TECON.SCR");
if (!file.isOpen())
error("Failed to open TECON.SCR/TE2.BI3");
_border = readCPCImage(&file, true);
_border->setPalette((byte*)&kCPCPaletteEclipseBorderData, 0, 4);
file.close();
if (isEclipse2())
file.open("TE2.BI2");
else
file.open("TECODE.BIN");
if (!file.isOpen())
error("Failed to open TECODE.BIN/TE2.BI2");
if (isEclipse2()) {
loadFonts(&file, 0x60bc);
loadMessagesFixedSize(&file, 0x326, 16, 30);
load8bitBinary(&file, 0x62b4, 16);
} else {
loadFonts(&file, 0x6076);
loadMessagesFixedSize(&file, 0x326, 16, 30);
load8bitBinary(&file, 0x626e, 16);
}
loadColorPalette();
swapPalette(1);
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
void EclipseEngine::loadAssetsCPCDemo() {
Common::File file;
file.open("TECON.BIN");
if (!file.isOpen())
error("Failed to open TECON.BIN");
_border = readCPCImage(&file, true);
_border->setPalette((byte*)&kCPCPaletteEclipseTitleData, 0, 4);
file.close();
file.open("TEPROG.BIN");
if (!file.isOpen())
error("Failed to open TEPROG.BIN");
loadFonts(&file, 0x63ce);
loadMessagesFixedSize(&file, 0x362, 16, 23);
loadMessagesFixedSize(&file, 0x570b, 264, 5);
load8bitBinary(&file, 0x65c6, 16);
loadColorPalette();
swapPalette(1);
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
void EclipseEngine::drawCPCUI(Graphics::Surface *surface) {
uint32 color = _currentArea->_underFireBackgroundColor;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_usualBackgroundColor;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_inkColor;
_gfx->readFromPalette(color, r, g, b);
uint32 other = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int score = _gameStateVars[k8bitVariableScore];
int shield = _gameStateVars[k8bitVariableShield] * 100 / _maxShield;
shield = shield < 0 ? 0 : shield;
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 102, 135, back, front, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else if (!_currentAreaMessages.empty())
drawStringInSurface(_currentArea->_name, 102, 135, back, front, surface);
drawScoreString(score, 136, 6, back, other, surface);
int x = 171;
if (shield < 10)
x = 179;
else if (shield < 100)
x = 175;
Common::String shieldStr = Common::String::format("%d", shield);
drawStringInSurface(shieldStr, x, 162, back, other, surface);
drawStringInSurface(shiftStr("0", 'Z' - '$' + 1 - _angleRotationIndex), 79, 135, back, front, surface);
drawStringInSurface(shiftStr("3", 'Z' - '$' + 1 - _playerStepIndex), 63, 135, back, front, surface);
drawStringInSurface(shiftStr("7", 'Z' - '$' + 1 - _playerHeightNumber), 240, 135, back, front, surface);
if (_shootingFrames > 0) {
drawStringInSurface(shiftStr("4", 'Z' - '$' + 1), 232, 135, back, front, surface);
drawStringInSurface(shiftStr("<", 'Z' - '$' + 1), 240, 135, back, front, surface);
}
drawAnalogClock(surface, 90, 172, back, other, front);
drawIndicator(surface, 45, 4, 12);
drawEclipseIndicator(surface, 228, 0, front, other);
Common::Rect jarBackground(124, 165, 148, 192);
surface->fillRect(jarBackground, back);
Common::Rect jarWater(124, 192 - _gameStateVars[k8bitVariableEnergy], 148, 192);
surface->fillRect(jarWater, color);
surface->fillRect(Common::Rect(225, 168, 235, 187), front);
drawCompass(surface, 229, 177, _yaw, 10, back);
}
} // End of namespace Freescape

View File

@@ -0,0 +1,207 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "audio/audiostream.h"
#include "audio/decoders/raw.h"
#include "freescape/freescape.h"
#include "freescape/games/eclipse/eclipse.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
extern byte kEGADefaultPalette[16][3];
extern byte kCGAPaletteRedGreen[4][3];
extern byte kCGAPalettePinkBlue[4][3];
void EclipseEngine::initDOS() {
_viewArea = Common::Rect(40, 33, 280, 133);
_soundIndexShoot = 18;
_soundIndexCollide = 1;
_soundIndexStepDown = 3;
_soundIndexStepUp = 3;
_soundIndexMenu = -1;
_soundIndexStart = 9;
_soundIndexAreaChange = 5;
}
void EclipseEngine::loadAssetsDOSFullGame() {
Common::File file;
if (_renderMode == Common::kRenderEGA) {
file.open("SCN1E.DAT");
if (file.isOpen()) {
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
}
file.close();
file.open("TOTEE.EXE");
if (!file.isOpen())
error("Failed to open TOTEE.EXE");
loadMessagesFixedSize(&file, 0x710f, 16, 20);
loadSoundsFx(&file, 0xd670, 5);
loadSpeakerFxDOS(&file, 0x7396 + 0x200, 0x72a1 + 0x200, 20);
loadFonts(&file, 0xd403);
load8bitBinary(&file, 0x3ce0, 16);
_border = load8bitBinImage(&file, 0x210);
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
} else if (_renderMode == Common::kRenderCGA) {
file.open("SCN1C.DAT");
if (file.isOpen()) {
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte *)&kCGAPaletteRedGreen, 0, 4);
}
file.close();
file.open("TOTEC.EXE");
if (!file.isOpen())
error("Failed to open TOTEC.EXE");
loadMessagesFixedSize(&file, 0x594f, 16, 20);
loadSoundsFx(&file, 0xb9f0, 5);
loadFonts(&file, 0xb785);
load8bitBinary(&file, 0x2530, 4);
_border = load8bitBinImage(&file, 0x210);
_border->setPalette((byte *)&kCGAPaletteRedGreen, 0, 4);
swapPalette(_startArea);
} else
error("Invalid or unsupported render mode %s for Total Eclipse", Common::getRenderModeDescription(_renderMode));
}
void EclipseEngine::drawDOSUI(Graphics::Surface *surface) {
int score = _gameStateVars[k8bitVariableScore];
int shield = _gameStateVars[k8bitVariableShield] * 100 / _maxShield;
shield = shield < 0 ? 0 : shield;
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0x55);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0xFF);
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0x00, 0x00);
uint32 blue = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x55, 0x55, 0xFF);
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x55, 0xFF, 0x55);
uint32 redish = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0x55, 0x55);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 102, 135, black, yellow, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else if (!_currentAreaMessages.empty())
drawStringInSurface(_currentArea->_name, 102, 135, black, yellow, surface);
drawScoreString(score, 136, 6, black, white, surface);
int x = 171;
if (shield < 10)
x = 179;
else if (shield < 100)
x = 175;
Common::String shieldStr = Common::String::format("%d", shield);
drawStringInSurface(shieldStr, x, 162, black, redish, surface);
drawStringInSurface(shiftStr("0", 'Z' - '$' + 1 - _angleRotationIndex), 79, 135, black, yellow, surface);
drawStringInSurface(shiftStr("3", 'Z' - '$' + 1 - _playerStepIndex), 63, 135, black, yellow, surface);
drawStringInSurface(shiftStr("7", 'Z' - '$' + 1 - _playerHeightNumber), 240, 135, black, yellow, surface);
if (_shootingFrames > 0) {
drawStringInSurface(shiftStr("4", 'Z' - '$' + 1), 232, 135, black, yellow, surface);
drawStringInSurface(shiftStr("<", 'Z' - '$' + 1), 240, 135, black, yellow, surface);
}
drawAnalogClock(surface, 90, 172, black, red, white);
Common::Rect jarBackground(124, 165, 148, 192);
surface->fillRect(jarBackground, black);
Common::Rect jarWater(124, 192 - _gameStateVars[k8bitVariableEnergy], 148, 192);
surface->fillRect(jarWater, blue);
drawIndicator(surface, 41, 4, 16);
drawEclipseIndicator(surface, 228, 0, yellow, green);
surface->fillRect(Common::Rect(225, 168, 235, 187), white);
drawCompass(surface, 229, 177, _yaw, 10, black);
}
soundFx *EclipseEngine::load1bPCM(Common::SeekableReadStream *file, int offset) {
soundFx *sound = (soundFx *)malloc(sizeof(soundFx));
file->seek(offset);
sound->size = file->readUint16LE();
debugC(1, kFreescapeDebugParser, "size: %d", sound->size);
sound->sampleRate = file->readUint16LE();
debugC(1, kFreescapeDebugParser, "sample rate?: %f", sound->sampleRate);
uint8 *data = (uint8 *)malloc(sound->size * sizeof(uint8) * 8);
for (int i = 0; i < sound->size; i++) {
uint8 byte = file->readByte();
for (int j = 0; j < 8; j++) {
data[8 * i + j] = byte & 1 ? 255 : 0;
byte = byte >> 1;
}
}
sound->size = sound->size * 8;
sound->data = (byte *)data;
return sound;
}
void EclipseEngine::loadSoundsFx(Common::SeekableReadStream *file, int offset, int number) {
if (isAmiga() || isAtariST()) {
FreescapeEngine::loadSoundsFx(file, offset, number);
return;
}
for (int i = 0; i < number; i++) {
_soundsFx[i] = load1bPCM(file, offset);
offset += (_soundsFx[i]->size / 8) + 4;
}
}
void EclipseEngine::playSoundFx(int index, bool sync) {
if (isAmiga() || isAtariST()) {
FreescapeEngine::playSoundFx(index, sync);
return;
}
if (_soundsFx.size() == 0) {
debugC(1, kFreescapeDebugMedia, "WARNING: Sounds are not loaded");
return;
}
int size = _soundsFx[index]->size;
//int sampleRate = _soundsFx[index]->sampleRate;
byte *data = _soundsFx[index]->data;
Audio::SeekableAudioStream *stream = Audio::makeRawStream(data, size, 11025, Audio::FLAG_UNSIGNED, DisposeAfterUse::NO);
_mixer->playStream(Audio::Mixer::kSFXSoundType, &_soundFxHandle, stream, -1, kFreescapeDefaultVolume / 10);
}
} // End of namespace Freescape

View File

@@ -0,0 +1,812 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "backends/keymapper/action.h"
#include "backends/keymapper/keymap.h"
#include "backends/keymapper/standard-actions.h"
#include "common/translation.h"
#include "freescape/freescape.h"
#include "freescape/games/eclipse/eclipse.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
EclipseEngine::EclipseEngine(OSystem *syst, const ADGameDescription *gd) : FreescapeEngine(syst, gd) {
// These sounds can be overriden by the class of each platform
_soundIndexStartFalling = -1;
_soundIndexEndFalling = -1;
_soundIndexNoShield = -1;
_soundIndexNoEnergy = -1;
_soundIndexFallen = -1;
_soundIndexTimeout = -1;
_soundIndexForceEndGame = -1;
_soundIndexCrushed = -1;
_soundIndexMissionComplete = -1;
_maxEnergy = 27;
_maxShield = 50;
_initialEnergy = 16;
_initialShield = 50;
if (isDOS())
initDOS();
else if (isCPC())
initCPC();
else if (isC64())
initC64();
else if (isSpectrum())
initZX();
else if (isAmiga() || isAtariST())
initAmigaAtari();
_playerHeightNumber = 1;
_playerHeightMaxNumber = 1;
_playerWidth = 8;
_playerDepth = 8;
_stepUpDistance = 32;
_playerStepIndex = 2;
_playerSteps.clear();
_playerSteps.push_back(2);
_playerSteps.push_back(30);
_playerSteps.push_back(60);
_angleRotationIndex = 1;
_angleRotations.push_back(5);
_angleRotations.push_back(10);
_angleRotations.push_back(15);
_endArea = 1;
_endEntrance = 33;
_lastThirtySeconds = 0;
_lastFiveSeconds = 0;
_lastSecond = -1;
_resting = false;
}
void EclipseEngine::initGameState() {
FreescapeEngine::initGameState();
_playerHeightNumber = 1;
_gameStateVars[k8bitVariableEnergy] = _initialEnergy;
_gameStateVars[k8bitVariableShield] = _initialShield;
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
_lastThirtySeconds = seconds / 30;
_lastFiveSeconds = seconds / 5;
_resting = false;
// Start playing music, if any, in any supported format
playMusic("Total Eclipse Theme");
}
void EclipseEngine::loadAssets() {
FreescapeEngine::loadAssets();
Common::List<int> globalIds = _areaMap[255]->getEntranceIds();
for (auto &it : _areaMap) {
if (it._value->getAreaID() == 255)
continue;
it._value->addStructure(_areaMap[255]);
if (isDemo()) {
it._value->_name = " NOW TRAINING ";
}
for (auto &id : globalIds) {
if (it._value->entranceWithID(id))
continue;
Object *obj = _areaMap[255]->entranceWithID(id);
assert(obj);
assert(obj->getType() == ObjectType::kEntranceType);
// The entrance is not in the current area, so we need to add it
it._value->addObjectFromArea(id, _areaMap[255]);
}
}
_timeoutMessage = _messagesList[1];
_noShieldMessage = _messagesList[0];
//_noEnergyMessage = _messagesList[16];
_fallenMessage = _messagesList[3];
_crushedMessage = _messagesList[2];
_areaMap[1]->addFloor();
if (isSpectrum())
_areaMap[1]->_paperColor = 1;
if (!isDemo() && !isEclipse2()) {
_areaMap[51]->addFloor();
_areaMap[51]->_paperColor = 1;
// Workaround for fixing some planar objects from area 9 that have null size
Object *obj = nullptr;
obj = _areaMap[9]->objectWithID(7);
assert(obj);
obj->_size = 32 * Math::Vector3d(3, 0, 2);
obj = _areaMap[9]->objectWithID(8);
assert(obj);
obj->_size = 32 * Math::Vector3d(3, 0, 2);
obj = _areaMap[9]->objectWithID(9);
assert(obj);
obj->_size = 32 * Math::Vector3d(3, 0, 2);
}
}
bool EclipseEngine::checkIfGameEnded() {
if (_gameStateControl == kFreescapeGameStatePlaying) {
if (_hasFallen && _avoidRenderingFrames == 0) {
_hasFallen = false;
if (isDOS())
playSoundFx(4, false);
else
playSound(_soundIndexStartFalling, false, _soundFxHandle);
stopMovement();
// If shield is less than 11 after a fall, the game ends
if (_gameStateVars[k8bitVariableShield] > 15 + 11) {
_gameStateVars[k8bitVariableShield] -= 15;
return false; // Game can continue
}
if (!_fallenMessage.empty())
insertTemporaryMessage(_fallenMessage, _countdown - 4);
_gameStateControl = kFreescapeGameStateEnd;
} else if (getGameBit(16)) {
_gameStateControl = kFreescapeGameStateEnd;
insertTemporaryMessage(_messagesList[4], INT_MIN);
}
FreescapeEngine::checkIfGameEnded();
}
return false;
}
void EclipseEngine::endGame() {
FreescapeEngine::endGame();
if (!_endGamePlayerEndArea)
return;
if (_gameStateControl == kFreescapeGameStateEnd) {
removeTimers();
if (getGameBit(16)) {
if (_countdown > - 3600)
_countdown -= 10;
else
_countdown = -3600;
} else {
if (_countdown > 0)
_countdown -= 10;
else
_countdown = 0;
}
}
if (_endGameKeyPressed && (_countdown == 0 || _countdown == -3600)) {
if (isSpectrum())
playSound(5, true, _soundFxHandle);
_gameStateControl = kFreescapeGameStateRestart;
}
_endGameKeyPressed = false;
}
void EclipseEngine::initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) {
FreescapeEngine::initKeymaps(engineKeyMap, infoScreenKeyMap, target);
Common::Action *act;
act = new Common::Action("SAVE", _("Save game"));
act->setCustomEngineActionEvent(kActionSave);
act->addDefaultInputMapping("s");
infoScreenKeyMap->addAction(act);
act = new Common::Action("LOAD", _("Load game"));
act->setCustomEngineActionEvent(kActionLoad);
act->addDefaultInputMapping("l");
infoScreenKeyMap->addAction(act);
act = new Common::Action("QUIT", _("Quit game"));
act->setCustomEngineActionEvent(kActionEscape);
if (isSpectrum())
act->addDefaultInputMapping("1");
else
act->addDefaultInputMapping("ESCAPE");
infoScreenKeyMap->addAction(act);
act = new Common::Action("TOGGLESOUND", _("Toggle Sound"));
act->setCustomEngineActionEvent(kActionToggleSound);
act->addDefaultInputMapping("t");
infoScreenKeyMap->addAction(act);
act = new Common::Action("ROTL", _("Rotate Left"));
act->setCustomEngineActionEvent(kActionRotateLeft);
act->addDefaultInputMapping("q");
engineKeyMap->addAction(act);
act = new Common::Action("ROTR", _("Rotate Right"));
act->setCustomEngineActionEvent(kActionRotateRight);
act->addDefaultInputMapping("w");
engineKeyMap->addAction(act);
// I18N: Illustrates the angle at which you turn left or right.
act = new Common::Action("CHNGANGLE", _("Change Angle"));
act->setCustomEngineActionEvent(kActionIncreaseAngle);
act->addDefaultInputMapping("a");
engineKeyMap->addAction(act);
// I18N: STEP SIZE: Measures the size of one movement in the direction you are facing (1-250 standard distance units (SDUs))
act = new Common::Action("CHNGSTEPSIZE", _("Change Step Size"));
act->setCustomEngineActionEvent(kActionChangeStepSize);
act->addDefaultInputMapping("s");
engineKeyMap->addAction(act);
act = new Common::Action("TGGLHEIGHT", _("Toggle Height"));
act->setCustomEngineActionEvent(kActionToggleRiseLower);
act->addDefaultInputMapping("JOY_B");
act->addDefaultInputMapping("h");
engineKeyMap->addAction(act);
act = new Common::Action("REST", _("Rest"));
act->setCustomEngineActionEvent(kActionRest);
act->addDefaultInputMapping("JOY_Y");
act->addDefaultInputMapping("r");
engineKeyMap->addAction(act);
act = new Common::Action("FACEFRWARD", _("Face Forward"));
act->setCustomEngineActionEvent(kActionFaceForward);
act->addDefaultInputMapping("f");
engineKeyMap->addAction(act);
}
void EclipseEngine::gotoArea(uint16 areaID, int entranceID) {
debugC(1, kFreescapeDebugMove, "Jumping to area: %d, entrance: %d", areaID, entranceID);
assert(_areaMap.contains(areaID));
_currentArea = _areaMap[areaID];
_currentArea->show();
_currentAreaMessages.clear();
_currentAreaMessages.push_back(_currentArea->_name);
if (entranceID > 0)
traverseEntrance(entranceID);
else if (entranceID == -1)
debugC(1, kFreescapeDebugMove, "Loading game, no change in position");
else
error("Invalid area change!");
_lastPosition = _position;
if (areaID == _startArea && entranceID == _startEntrance) {
if (_pitch >= 180)
_pitch = 360 - _pitch;
playSound(_soundIndexStart, false, _soundFxHandle);
if (isEclipse2()) {
_gameStateControl = kFreescapeGameStateStart;
_pitch = -10;
}
} if (areaID == _endArea && entranceID == _endEntrance) {
_flyMode = true;
if (isDemo())
_pitch = 20;
else
_pitch = 10;
} else {
playSound(_soundIndexAreaChange, false, _soundFxHandle);
}
_gfx->_keyColor = 0;
swapPalette(areaID);
_currentArea->_usualBackgroundColor = isCPC() ? 1 : 0;
if (isAmiga() || isAtariST())
_currentArea->_skyColor = 15;
resetInput();
}
void EclipseEngine::drawBackground() {
clearBackground();
_gfx->drawBackground(_currentArea->_skyColor);
if (_currentArea && _currentArea->getAreaID() == 1) {
if (ABS(_countdown) <= 15 * 60) // Last 15 minutes
_gfx->drawBackground(5);
if (ABS(_countdown) <= 10) // Last 10 seconds
_gfx->drawBackground(1);
float progress = 0;
if (_countdown >= 0 || getGameBit(16))
progress = float(_countdown) / _initialCountdown;
uint8 color1 = 15;
uint8 color2 = 10;
if (isSpectrum() || isCPC() || isC64()) {
color1 = 2;
color2 = 10;
} else if (isAmiga() || isAtariST()) {
color1 = 8;
color2 = 14;
}
_gfx->drawEclipse(color1, color2, progress);
}
}
void EclipseEngine::titleScreen() {
if (isDOS())
playSoundFx(2, true);
FreescapeEngine::titleScreen();
}
void EclipseEngine::borderScreen() {
if (_border) {
drawBorder();
if (isDemo() && isCPC()) {
drawFullscreenMessageAndWait(_messagesList[23]);
drawFullscreenMessageAndWait(_messagesList[24]);
drawFullscreenMessageAndWait(_messagesList[25]);
} else if (isDemo() && isSpectrum()) {
if (_variant & GF_ZX_DEMO_MICROHOBBY) {
drawFullscreenMessageAndWait(_messagesList[23]);
} else if (_variant & GF_ZX_DEMO_CRASH) {
drawFullscreenMessageAndWait(_messagesList[9]);
drawFullscreenMessageAndWait(_messagesList[10]);
drawFullscreenMessageAndWait(_messagesList[11]);
}
} else {
FreescapeEngine::borderScreen();
}
}
}
void EclipseEngine::drawInfoMenu() {
PauseToken pauseToken = pauseEngine();
if (_savedScreen) {
_savedScreen->free();
delete _savedScreen;
}
_savedScreen = _gfx->getScreenshot();
uint32 color = 0;
switch (_renderMode) {
case Common::kRenderCGA:
color = 1;
break;
case Common::kRenderZX:
color = 6;
break;
default:
color = 14;
}
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
Graphics::Surface *surface = new Graphics::Surface();
surface->create(_screenW, _screenH, _gfx->_texturePixelFormat);
surface->fillRect(Common::Rect(88, 48, 231, 103), black);
surface->frameRect(Common::Rect(88, 48, 231, 103), front);
surface->frameRect(Common::Rect(90, 50, 229, 101), front);
drawStringInSurface("L-LOAD S-SAVE", 105, 56, front, black, surface);
if (isSpectrum())
drawStringInSurface("1-TERMINATE", 105, 64, front, black, surface);
else
drawStringInSurface("ESC-TERMINATE", 105, 64, front, black, surface);
drawStringInSurface("T-TOGGLE", 128, 81, front, black, surface);
drawStringInSurface("SOUND ON/OFF", 113, 88, front, black, surface);
Texture *menuTexture = _gfx->createTexture(surface);
Common::Event event;
bool cont = true;
while (!shouldQuit() && cont) {
while (_eventManager->pollEvent(event)) {
// Events
switch (event.type) {
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
if (event.customType == kActionLoad) {
_gfx->setViewport(_fullscreenViewArea);
_eventManager->purgeKeyboardEvents();
loadGameDialog();
_gfx->setViewport(_viewArea);
} else if (event.customType == kActionSave) {
_gfx->setViewport(_fullscreenViewArea);
_eventManager->purgeKeyboardEvents();
saveGameDialog();
_gfx->setViewport(_viewArea);
} else if (isDOS() && event.customType == kActionToggleSound) {
playSound(_soundIndexMenu, false, _soundFxHandle);
} else if ((isDOS() || isCPC() || isSpectrum()) && event.customType == kActionEscape) {
_forceEndGame = true;
cont = false;
} else
cont = false;
break;
case Common::EVENT_KEYDOWN:
cont = false;
break;
case Common::EVENT_SCREEN_CHANGED:
_gfx->computeScreenViewport();
break;
default:
break;
}
}
drawFrame();
_gfx->drawTexturedRect2D(_fullscreenViewArea, _fullscreenViewArea, menuTexture);
_gfx->flipBuffer();
g_system->updateScreen();
g_system->delayMillis(15); // try to target ~60 FPS
}
_savedScreen->free();
delete _savedScreen;
_savedScreen = nullptr;
surface->free();
delete surface;
delete menuTexture;
pauseToken.clear();
}
void EclipseEngine::pressedKey(const int keycode) {
if (keycode == kActionIncreaseAngle) {
changeAngle(1, true);
} else if (keycode == kActionChangeStepSize) {
changeStepSize();
} else if (keycode == kActionToggleRiseLower) {
if (_playerHeightNumber == 0)
rise();
else if (_playerHeightNumber == 1)
lower();
else
error("Invalid player height index: %d", _playerHeightNumber);
} else if (keycode == kActionRest) {
if (_currentArea->getAreaID() == 1) {
playSoundFx(3, false);
if (_temporaryMessages.empty())
insertTemporaryMessage(_messagesList[6], _countdown - 2);
} else {
_resting = true;
if (_temporaryMessages.empty())
insertTemporaryMessage(_messagesList[7], _countdown - 2);
_countdown = _countdown - 5;
}
} else if (keycode == kActionFaceForward) {
_pitch = 0;
updateCamera();
}
}
void EclipseEngine::releasedKey(const int keycode) {
if (keycode == kActionRiseOrFlyUp)
_resting = false;
}
void EclipseEngine::drawAnalogClock(Graphics::Surface *surface, int x, int y, uint32 colorHand1, uint32 colorHand2, uint32 colorBack) {
// These calls will cover the pixels of the hardcoded clock image
drawAnalogClockHand(surface, x, y, 6 * 6 - 90, 12, colorBack);
drawAnalogClockHand(surface, x, y, 7 * 6 - 90, 12, colorBack);
drawAnalogClockHand(surface, x, y, 41 * 6 - 90, 11, colorBack);
drawAnalogClockHand(surface, x, y, 42 * 6 - 90, 11, colorBack);
drawAnalogClockHand(surface, x, y, 0 * 6 - 90, 11, colorBack);
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
hours = 7 + 2 - hours; // It's 7 o-clock when the game starts
minutes = 59 - minutes;
seconds = 59 - seconds;
drawAnalogClockHand(surface, x, y, hours * 30 - 90, 11, colorHand1);
drawAnalogClockHand(surface, x, y, minutes * 6 - 90, 11, colorHand1);
drawAnalogClockHand(surface, x, y, seconds * 6 - 90, 11, colorHand2);
}
void EclipseEngine::drawAnalogClockHand(Graphics::Surface *surface, int x, int y, double degrees, double magnitude, uint32 color) {
const double degtorad = (M_PI * 2) / 360;
double w = magnitude * cos(degrees * degtorad);
double h = magnitude * sin(degrees * degtorad);
surface->drawLine(x, y, x+(int)w, y+(int)h, color);
if (isC64()) {
surface->drawLine(x+1, y, x+1+(int)w, y+(int)h, color);
}
}
void EclipseEngine::drawCompass(Graphics::Surface *surface, int x, int y, double degrees, double magnitude, uint32 color) {
const double degtorad = (M_PI * 2) / 360;
double w = magnitude * cos(-degrees * degtorad);
double h = magnitude * sin(-degrees * degtorad);
int dx = 0;
int dy = 0;
// Adjust dx and dy to make the compass look like a compass
if (degrees == 0 || degrees == 360) {
dx = 1;
dy = 2;
} else if (degrees > 0 && degrees < 90) {
dx = 2;
dy = 1;
} else if (degrees == 90) {
dx = 2;
dy = 1;
} else if (degrees > 90 && degrees < 180) {
dx = 2;
dy = -1;
} else if (degrees == 180) {
dx = 1;
dy = 2;
} else if (degrees > 180 && degrees < 270) {
dx = -2;
dy = -1;
} else if (degrees == 270) {
dx = 2;
dy = 1;
} else if (degrees > 270 && degrees < 360) {
dx = -2;
dy = 1;
}
surface->drawLine(x, y, x+(int)w, y+(int)h, color);
surface->drawLine(x - dx, y - dy, x+(int)w, y+(int)h, color);
surface->drawLine(x + dx, y + dy, x+(int)w, y+(int)h, color);
surface->drawLine(x - dx, y - dy, x+(int)-w, y+(int)-h, color);
surface->drawLine(x + dx, y + dy, x+(int)-w, y+(int)-h, color);
}
// Copied from BITMAP::circlefill in engines/ags/lib/allegro/surface.cpp
void fillCircle(Graphics::Surface *surface, int x, int y, int radius, int color) {
int cx = 0;
int cy = radius;
int df = 1 - radius;
int d_e = 3;
int d_se = -2 * radius + 5;
do {
surface->hLine(x - cy, y - cx, x + cy, color);
if (cx)
surface->hLine(x - cy, y + cx, x + cy, color);
if (df < 0) {
df += d_e;
d_e += 2;
d_se += 2;
} else {
if (cx != cy) {
surface->hLine(x - cx, y - cy, x + cx, color);
if (cy)
surface->hLine(x - cx, y + cy, x + cx, color);
}
df += d_se;
d_e += 2;
d_se += 4;
cy--;
}
cx++;
} while (cx <= cy);
}
void EclipseEngine::drawEclipseIndicator(Graphics::Surface *surface, int x, int y, uint32 color1, uint32 color2) {
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
// These calls will cover the pixels of the hardcoded eclipse image
surface->fillRect(Common::Rect(x, y, x + 50, y + 20), black);
float progress = 0;
if (_countdown >= 0)
progress = float(_countdown) / _initialCountdown;
int difference = 14 * progress;
fillCircle(surface, x + 7, y + 10, 7, color1); // Sun
fillCircle(surface, x + 7 + difference, y + 10, 7, color2); // Moon
}
void EclipseEngine::drawIndicator(Graphics::Surface *surface, int xPosition, int yPosition, int separation) {
if (_indicators.size() == 0)
return;
for (int i = 0; i < 5; i++) {
if (isSpectrum() || isC64()) {
if (_gameStateVars[kVariableEclipseAnkhs] <= i)
continue;
} else if (_gameStateVars[kVariableEclipseAnkhs] > i)
continue;
surface->copyRectToSurface(*_indicators[0], xPosition + separation * i, yPosition, Common::Rect(_indicators[0]->w, _indicators[0]->h));
}
}
void EclipseEngine::drawSensorShoot(Sensor *sensor) {
Math::Vector3d target;
float distance = 5;
int axisToSkip = -1;
if (sensor->_axis == 0x1 || sensor->_axis == 0x2)
axisToSkip = 0;
if (sensor->_axis == 0x10 || sensor->_axis == 0x20)
axisToSkip = 2;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) {
target = sensor->getOrigin();
if (i != axisToSkip)
target.setValue(i, target.getValue(i) + distance);
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
target = sensor->getOrigin();
if (i != axisToSkip)
target.setValue(i, target.getValue(i) - distance);
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
} else {
target = sensor->getOrigin();
if (i != axisToSkip)
target.setValue(i, target.getValue(i) + distance);
if (j != axisToSkip)
target.setValue(j, target.getValue(j) + distance);
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
target = sensor->getOrigin();
if (i != axisToSkip)
target.setValue(i, target.getValue(i) + distance);
if (j != axisToSkip)
target.setValue(j, target.getValue(j) - distance);
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
target = sensor->getOrigin();
if (i != axisToSkip)
target.setValue(i, target.getValue(i) - distance);
if (j != axisToSkip)
target.setValue(j, target.getValue(j) - distance);
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
target = sensor->getOrigin();
if (i != axisToSkip)
target.setValue(i, target.getValue(i) - distance);
if (j != axisToSkip)
target.setValue(j, target.getValue(j) + distance);
_gfx->renderSensorShoot(1, sensor->getOrigin(), target, _viewArea);
}
}
}
}
void EclipseEngine::drawScoreString(int score, int x, int y, uint32 front, uint32 back, Graphics::Surface *surface) {
Common::String scoreStr = Common::String::format("%07d", score);
if (isDOS() || isCPC() || isSpectrum()) {
scoreStr = shiftStr(scoreStr, 'Z' - '0' + 1);
if (_renderMode == Common::RenderMode::kRenderEGA || isSpectrum()) {
drawStringInSurface(scoreStr, x, y, front, back, surface);
return;
}
}
// Start in x,y and draw each digit, from left to right, adding a gap every 3 digits
int gapSize = isC64() ? 8 : 4;
for (int i = 0; i < int(scoreStr.size()); i++) {
drawStringInSurface(Common::String(scoreStr[i]), x, y, front, back, surface);
x += 8;
if ((i - scoreStr.size() + 1) % 3 == 1)
x += gapSize;
}
}
void EclipseEngine::updateTimeVariables() {
if (isEclipse2() && _gameStateControl == kFreescapeGameStateStart) {
executeLocalGlobalConditions(false, true, false);
_gameStateControl = kFreescapeGameStatePlaying;
}
if (_gameStateControl != kFreescapeGameStatePlaying)
return;
// This function only executes "on collision" room/global conditions
int seconds, minutes, hours;
getTimeFromCountdown(seconds, minutes, hours);
if (_lastFiveSeconds != seconds / 5) {
_lastFiveSeconds = seconds / 5;
executeLocalGlobalConditions(false, false, true);
}
if (_lastThirtySeconds != seconds / 30) {
_lastThirtySeconds = seconds / 30;
if (!_resting && _gameStateVars[k8bitVariableEnergy] > 0) {
_gameStateVars[k8bitVariableEnergy] -= 1;
}
if (_gameStateVars[k8bitVariableShield] < _maxShield) {
_gameStateVars[k8bitVariableShield] += 1;
}
}
if (isEclipse() && isSpectrum() && _currentArea->getAreaID() == 42) {
if (_lastSecond != seconds) { // Swap ink and paper colors every second
_lastSecond = seconds;
int tmp = _gfx->_inkColor;
_gfx->_inkColor = _gfx->_paperColor;
_gfx->_paperColor = tmp;
}
}
}
void EclipseEngine::executePrint(FCLInstruction &instruction) {
uint16 index = instruction._source - 1;
debugC(1, kFreescapeDebugCode, "Printing message %d", index);
if (index > 127) {
index = _messagesList.size() - (index - 254) - 2;
drawFullscreenMessageAndWait(_messagesList[index]);
return;
}
insertTemporaryMessage(_messagesList[index], _countdown - 2);
}
Common::Error EclipseEngine::saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave) {
return Common::kNoError;
}
Common::Error EclipseEngine::loadGameStreamExtended(Common::SeekableReadStream *stream) {
return Common::kNoError;
}
} // End of namespace Freescape

View File

@@ -0,0 +1,108 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/sound.h"
namespace Freescape {
enum EclipseReleaseFlags {
GF_ZX_DEMO_CRASH = (1 << 0),
GF_ZX_DEMO_MICROHOBBY = (1 << 1),
};
enum {
kVariableEclipseAnkhs = 32,
};
class EclipseEngine : public FreescapeEngine {
public:
EclipseEngine(OSystem *syst, const ADGameDescription *gd);
void gotoArea(uint16 areaID, int entranceID) override;
void borderScreen() override;
void titleScreen() override;
void drawInfoMenu() override;
void drawIndicator(Graphics::Surface *surface, int xPosition, int yPosition, int separation);
void drawSensorShoot(Sensor *sensor) override;
void loadAssets() override;
void loadAssetsDOSFullGame() override;
void pressedKey(const int keycode) override;
void releasedKey(const int keycode) override;
uint32 _initialEnergy;
uint32 _initialShield;
int _soundIndexStartFalling;
int _soundIndexEndFalling;
bool _resting;
int _lastThirtySeconds;
int _lastFiveSeconds;
int _lastSecond;
void updateTimeVariables() override;
void initDOS();
void initCPC();
void initZX();
void initC64();
void initAmigaAtari();
void loadAssetsZXFullGame() override;
void loadAssetsCPCFullGame() override;
void loadAssetsC64FullGame() override;
void loadAssetsAtariFullGame() override;
void loadAssetsCPCDemo() override;
void loadAssetsZXDemo() override;
void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
void initGameState() override;
void executePrint(FCLInstruction &instruction) override;
void drawBackground() override;
void drawDOSUI(Graphics::Surface *surface) override;
void drawCPCUI(Graphics::Surface *surface) override;
void drawC64UI(Graphics::Surface *surface) override;
void drawZXUI(Graphics::Surface *surface) override;
void drawAnalogClock(Graphics::Surface *surface, int x, int y, uint32 colorHand1, uint32 colorHand2, uint32 colorBack);
void drawAnalogClockHand(Graphics::Surface *surface, int x, int y, double degrees, double magnitude, uint32 color);
void drawCompass(Graphics::Surface *surface, int x, int y, double degrees, double magnitude, uint32 color);
void drawEclipseIndicator(Graphics::Surface *surface, int x, int y, uint32 color1, uint32 color2);
Common::String getScoreString(int score);
void drawScoreString(int score, int x, int y, uint32 front, uint32 back, Graphics::Surface *surface);
soundFx *load1bPCM(Common::SeekableReadStream *file, int offset);
bool checkIfGameEnded() override;
void endGame() override;
void loadSoundsFx(Common::SeekableReadStream *file, int offset, int number) override;
void playSoundFx(int index, bool sync) override;
Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false) override;
Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override;
};
}

View File

@@ -0,0 +1,220 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/eclipse/eclipse.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void EclipseEngine::initZX() {
_viewArea = Common::Rect(56, 36, 265, 139);
_maxEnergy = 25;
_maxShield = 50;
_soundIndexShoot = 5;
_soundIndexCollide = -1; // Scripted
_soundIndexStepDown = 12;
_soundIndexStepUp = 12;
_soundIndexMenu = -1;
_soundIndexStart = 7;
_soundIndexAreaChange = 7;
_soundIndexStartFalling = 6;
_soundIndexEndFalling = 5;
_soundIndexNoShield = 8;
_soundIndexNoEnergy = -1;
_soundIndexFallen = 8;
_soundIndexTimeout = 8;
_soundIndexForceEndGame = 8;
_soundIndexCrushed = 8;
_soundIndexMissionComplete = 16;
}
void EclipseEngine::loadAssetsZXFullGame() {
Common::File file;
file.open("totaleclipse.zx.title");
if (file.isOpen()) {
_title = loadAndConvertScrImage(&file);
} else
error("Unable to find totaleclipse.zx.title");
file.close();
file.open("totaleclipse.zx.border");
if (file.isOpen()) {
_border = loadAndConvertScrImage(&file);
} else
error("Unable to find totaleclipse.zx.border");
file.close();
file.open("totaleclipse.zx.data");
if (!file.isOpen())
error("Failed to open totaleclipse.zx.data");
if (isEclipse2()) {
loadMessagesFixedSize(&file, 0x2ac, 16, 30);
loadFonts(&file, 0x61c3);
loadSpeakerFxZX(&file, 0x8c6, 0x91a);
load8bitBinary(&file, 0x63bb, 4);
} else {
loadMessagesFixedSize(&file, 0x2ac, 16, 23);
loadFonts(&file, 0x6163);
loadSpeakerFxZX(&file, 0x816, 0x86a);
load8bitBinary(&file, 0x635b, 4);
// These paper colors are also invalid, but to signal the use of a special effect (only in zx release)
_areaMap[42]->_paperColor = 0;
_areaMap[42]->_underFireBackgroundColor = 0;
}
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
void EclipseEngine::loadAssetsZXDemo() {
Common::File file;
file.open("totaleclipse.zx.title");
if (file.isOpen()) {
_title = loadAndConvertScrImage(&file);
} else
error("Unable to find totaleclipse.zx.title");
file.close();
file.open("totaleclipse.zx.border");
if (file.isOpen()) {
_border = loadAndConvertScrImage(&file);
} else
error("Unable to find totaleclipse.zx.border");
file.close();
file.open("totaleclipse.zx.data");
if (!file.isOpen())
error("Failed to open totaleclipse.zx.data");
if (_variant & GF_ZX_DEMO_MICROHOBBY) {
loadSpeakerFxZX(&file, 0x798, 0x7ec);
loadMessagesFixedSize(&file, 0x2ac, 16, 23);
loadMessagesFixedSize(&file, 0x56e6, 264, 1);
loadFonts(&file, 0x5f7b);
load8bitBinary(&file, 0x6173, 4);
} else if (_variant & GF_ZX_DEMO_CRASH) {
loadSpeakerFxZX(&file, 0x65c, 0x6b0);
loadMessagesFixedSize(&file, 0x364, 16, 9);
loadMessagesFixedSize(&file, 0x5901, 264, 5);
loadFonts(&file, 0x6589);
load8bitBinary(&file, 0x6781, 4);
} else
error("Unknown ZX Spectrum demo variant");
_indicators.push_back(loadBundledImage("eclipse_ankh_indicator"));
for (auto &it : _indicators)
it->convertToInPlace(_gfx->_texturePixelFormat);
}
void EclipseEngine::drawZXUI(Graphics::Surface *surface) {
uint32 color = _currentArea->_underFireBackgroundColor;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = _currentArea->_usualBackgroundColor;
if (_gfx->_colorRemaps && _gfx->_colorRemaps->contains(color)) {
color = (*_gfx->_colorRemaps)[color];
}
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(7, r, g, b);
uint32 gray = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(5, r, g, b);
uint32 blue = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(2, r, g, b);
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int score = _gameStateVars[k8bitVariableScore];
int shield = _gameStateVars[k8bitVariableShield] * 100 / _maxShield;
int energy = _gameStateVars[k8bitVariableEnergy];
shield = shield < 0 ? 0 : shield;
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0xFF, 0xFF, 0);
Common::String message;
int deadline;
getLatestMessages(message, deadline);
if (deadline <= _countdown) {
drawStringInSurface(message, 102, 141, back, yellow, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else if (!_currentAreaMessages.empty())
drawStringInSurface(_currentArea->_name, 102, 141, back, yellow, surface);
drawScoreString(score, 135, 11, back, gray, surface);
Common::String shieldStr = Common::String::format("%d", shield);
int x = 171;
if (shield < 10)
x = 179;
else if (shield < 100)
x = 175;
if (energy < 0)
energy = 0;
drawStringInSurface(shieldStr, x, 161, back, red, surface);
Common::Rect jarBackground(120, 162, 144, 192 - 4);
surface->fillRect(jarBackground, back);
Common::Rect jarWater(120, 192 - energy - 4, 144, 192 - 4);
surface->fillRect(jarWater, blue);
drawStringInSurface(shiftStr("0", 'Z' - '$' + 1 - _angleRotationIndex), 79, 141, back, yellow, surface);
drawStringInSurface(shiftStr("3", 'Z' - '$' + 1 - _playerStepIndex), 63, 141, back, yellow, surface);
drawStringInSurface(shiftStr("7", 'Z' - '$' + 1 - _playerHeightNumber), 240, 141, back, yellow, surface);
if (_shootingFrames > 0) {
drawStringInSurface(shiftStr("4", 'Z' - '$' + 1), 232, 141, back, yellow, surface);
drawStringInSurface(shiftStr("<", 'Z' - '$' + 1) , 240, 141, back, yellow, surface);
}
drawAnalogClock(surface, 89, 172, back, back, gray);
surface->fillRect(Common::Rect(227, 168, 235, 187), gray);
drawCompass(surface, 231, 177, _yaw, 10, back);
drawIndicator(surface, 65, 7, 8);
drawEclipseIndicator(surface, 215, 3, front, gray);
}
} // End of namespace Freescape

View File

@@ -0,0 +1,265 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "freescape/freescape.h"
namespace Freescape {
byte kEGADefaultPalette[16][3] = {
{0x00, 0x00, 0x00},
{0x00, 0x00, 0xaa},
{0x00, 0xaa, 0x00},
{0x00, 0xaa, 0xaa},
{0xaa, 0x00, 0x00},
{0xaa, 0x00, 0xaa},
{0xaa, 0x55, 0x00},
{0xaa, 0xaa, 0xaa},
{0x55, 0x55, 0x55},
{0x55, 0x55, 0xff},
{0x55, 0xff, 0x55},
{0x55, 0xff, 0xff},
{0xff, 0x55, 0x55},
{0xff, 0x55, 0xff},
{0xff, 0xff, 0x55},
{0xff, 0xff, 0xff}
};
byte kCGAPalettePinkBlue[4][3] = {
{0x00, 0x00, 0x00},
{0x00, 0xaa, 0xaa},
{0xaa, 0x00, 0xaa},
{0xaa, 0xaa, 0xaa},
};
byte kCGAPaletteRedGreen[4][3] = {
{0x00, 0x00, 0x00},
{0x00, 0xaa, 0x00},
{0xaa, 0x00, 0x00},
{0xaa, 0x55, 0x00},
};
byte kHerculesPaletteGreen[2][3] = {
{0x00, 0x00, 0x00},
{0x00, 0xff, 0x00},
};
byte kC64Palette[16][3] = {
{0x00, 0x00, 0x00},
{0xFF, 0xFF, 0xFF},
{0x68, 0x37, 0x2B},
{0x70, 0xA4, 0xB2},
{0x6F, 0x3D, 0x86},
{0x58, 0x8D, 0x43},
{0x35, 0x28, 0x79},
{0xB8, 0xC7, 0x6F},
{0x6F, 0x4F, 0x25},
{0x43, 0x39, 0x00},
{0x9A, 0x67, 0x59},
{0x44, 0x44, 0x44},
{0x6C, 0x6C, 0x6C},
{0x9A, 0xD2, 0x84},
{0x6C, 0x5E, 0xB5},
{0x95, 0x95, 0x95}
};
byte kDrillerZXPalette[9][3] = {
{0x00, 0x00, 0x00},
{0x00, 0x00, 0xd8},
{0xd8, 0x00, 0x00},
{0xd8, 0x00, 0xd8},
{0x00, 0xd8, 0x00},
{0x00, 0xd8, 0xd8},
{0xd8, 0xd8, 0x00},
{0xd8, 0xd8, 0xd8},
{0x00, 0x00, 0x00},
};
byte kDrillerCPCPalette[32][3] = {
{0x80, 0x80, 0x80}, // 0: special case?
{0x00, 0x00, 0x00}, // 1: used in dark only?
{0x00, 0x80, 0xff}, // 2
{0xff, 0xff, 0x80}, // 3
{0x00, 0x00, 0x80}, // 4
{0xff, 0x00, 0x80}, // 5
{0x00, 0x80, 0x80}, // 6
{0xff, 0x80, 0x80}, // 7
{0x80, 0x00, 0xff}, // 8
{0x00, 0x80, 0x00}, // 9
{0xff, 0xff, 0x00}, // 10
{0xff, 0xff, 0xff}, // 11
{0xff, 0x00, 0x00}, // 12
{0x11, 0x22, 0x33},
{0xff, 0x80, 0x00}, // 14
{0xff, 0x80, 0xff}, // 15
{0x11, 0x22, 0x33},
{0x00, 0xff, 0x80}, // 17
{0x00, 0xff, 0x00}, // 18
{0x80, 0xff, 0xff}, // 19
{0x80, 0x80, 0x80}, // 20
{0x00, 0x00, 0xff}, // 21
{0x00, 0x80, 0x00}, // 22
{0x00, 0x80, 0xff}, // 23
{0x80, 0x00, 0x80}, // 24
{0x80, 0xff, 0x80}, // 25
{0x80, 0xff, 0x00}, // 26
{0x00, 0xff, 0xff}, // 27
{0x80, 0x00, 0x00}, // 28
{0x80, 0x00, 0xff}, // 29
{0x80, 0x80, 0x00}, // 30
{0x80, 0x80, 0xff}, // 31
};
void FreescapeEngine::loadColorPalette() {
if (_renderMode == Common::kRenderEGA) {
_gfx->_palette = (byte *)&kEGADefaultPalette;
} else if (_renderMode == Common::kRenderC64) {
_gfx->_palette = (byte *)&kC64Palette;
} else if (_renderMode == Common::kRenderZX) {
_gfx->_palette = (byte *)kDrillerZXPalette;
} else if (_renderMode == Common::kRenderCPC) {
_gfx->_palette = (byte *)kDrillerCPCPalette;
} else if (_renderMode == Common::kRenderHercG) {
_gfx->_palette = (byte *)&kHerculesPaletteGreen;
} else if (_renderMode == Common::kRenderCGA) {
// palette depends on the area
} else if (_renderMode == Common::kRenderAmiga || _renderMode == Common::kRenderAtariST) {
// palette depends on the area
} else
error("Invalid render mode, no palette selected");
_gfx->setColorMap(&_colorMap);
}
byte *FreescapeEngine::loadPalette(Common::SeekableReadStream *file) {
int r, g, b;
auto palette = new byte[16][3];
for (int c = 0; c < 16; c++) {
int v = file->readUint16BE();
r = (v & 0xf00) >> 8;
r = r << 4 | r;
palette[c][0] = r & 0xff;
g = (v & 0xf0) >> 4;
g = g << 4 | g;
palette[c][1] = g & 0xff;
b = v & 0xf;
b = b << 4 | b;
palette[c][2] = b & 0xff;
debugC(1, kFreescapeDebugParser, "Color %d: (%04x) %02x %02x %02x", c, v, palette[c][0], palette[c][1], palette[c][2]);
}
return (byte *)palette;
}
void FreescapeEngine::loadPalettes(Common::SeekableReadStream *file, int offset) {
file->seek(offset);
int r, g, b;
uint numberOfAreas = _areaMap.size();
// This loop will load all the available palettes, which are more
// than the current areas. This indicates that more areas
// were originally planned, but they are not in the final game
if (isDriller())
numberOfAreas += 2;
else if (isDark())
numberOfAreas += 5;
else if (isCastle())
numberOfAreas += 20;
for (uint i = 0; i < numberOfAreas; i++) {
int label = readField(file, 8);
if (label == 255)
break;
auto palette = new byte[16][3];
debugC(1, kFreescapeDebugParser, "Loading palette for area: %d at %" PRIx64, label, file->pos());
for (int c = 0; c < 16; c++) {
int v = file->readUint16BE();
r = (v & 0xf00) >> 8;
r = r << 4 | r;
palette[c][0] = r & 0xff;
g = (v & 0xf0) >> 4;
g = g << 4 | g;
palette[c][1] = g & 0xff;
b = v & 0xf;
b = b << 4 | b;
palette[c][2] = b & 0xff;
debugC(1, kFreescapeDebugParser, "Color %d: (%04x) %02x %02x %02x", c, v, palette[c][0], palette[c][1], palette[c][2]);
}
assert(!_paletteByArea.contains(label));
_paletteByArea[label] = (byte *)palette;
}
}
void FreescapeEngine::swapPalette(uint16 levelID) {
if (isAmiga() || isAtariST()) {
// The following palette was not available in the demo, so we select another one
if (isDriller() && isDemo() && levelID == 32)
levelID = 31;
_gfx->_palette = _paletteByArea[levelID];
} else if (isSpectrum() || isCPC() || isC64()) {
_gfx->_inkColor = _areaMap[levelID]->_inkColor;
_gfx->_paperColor = _areaMap[levelID]->_paperColor;
_gfx->_underFireBackgroundColor = _areaMap[levelID]->_underFireBackgroundColor;
if (isC64()) {
_gfx->_inkColor %= 16;
_gfx->_paperColor %= 16;
_gfx->_underFireBackgroundColor %= 16;
return; // C64 does not have to process the border
}
if (!_border)
return;
byte *palette = (byte *)malloc(sizeof(byte) * 4 * 3);
for (int c = 0; c < 4; c++) {
byte r, g, b;
_gfx->selectColorFromFourColorPalette(c, r, g, b);
palette[3 * c + 0] = r;
palette[3 * c + 1] = g;
palette[3 * c + 2] = b;
}
_border->setPalette(palette, 0, 4);
free(palette);
processBorder();
} else if (isDOS() && _renderMode == Common::kRenderCGA) {
_gfx->_palette = findCGAPalette(levelID);
if (!_border)
return;
_border->setPalette(_gfx->_palette, 0, 4);
processBorder();
} else if (isDOS() && _renderMode == Common::kRenderEGA) {
if (!_border)
return;
_border->setPalette(_gfx->_palette, 0, 4);
processBorder();
}
}
byte *FreescapeEngine::findCGAPalette(uint16 levelID) {
if (levelID % 2 == 0)
return (byte *)&kCGAPalettePinkBlue;
else
return (byte *)&kCGAPaletteRedGreen;
}
} // End of namespace Freescape