Permalink
Browse files

STARTREK: Fixes to file loading.

The "numbered" files that I implemented can also use letters as the last
character.
  • Loading branch information...
Drenn1 authored and sev- committed Jan 19, 2018
1 parent f2260d1 commit 60d672db7315f9a131cfb128a3a10b29ece10112
Showing with 21 additions and 6 deletions.
  1. +5 −0 engines/startrek/graphics.cpp
  2. +8 −2 engines/startrek/lzss.cpp
  3. +8 −4 engines/startrek/startrek.cpp
@@ -89,6 +89,11 @@ void Graphics::drawImage(const char *filename) {
uint16 width = (_vm->getPlatform() == Common::kPlatformAmiga) ? imageStream->readUint16BE() : imageStream->readUint16LE();
uint16 height = (_vm->getPlatform() == Common::kPlatformAmiga) ? imageStream->readUint16BE() : imageStream->readUint16LE();

if (xoffset >= 320)
xoffset = 0;
if (yoffset >= 200)
yoffset = 0;

byte *pixels = (byte *)malloc(width * height);

if (_egaMode && _egaData) {
@@ -23,9 +23,11 @@
*
*/

#include "startrek/lzss.h"
#include "common/util.h"
#include "common/textconsole.h"
#include "common/memstream.h"
#include "common/util.h"

#include "startrek/lzss.h"

namespace StarTrek {

@@ -72,6 +74,10 @@ Common::SeekableReadStream *decodeLZSS(Common::SeekableReadStream *indata, uint3
}

delete[] histbuff;

if (outstreampos != uncompressedSize)
error("Size mismatch in LZSS decompression; expected %d bytes, got %d bytes", uncompressedSize, outstreampos);

return new Common::MemoryReadStream(outLzssBufData, uncompressedSize, DisposeAfterUse::YES);
}

@@ -100,7 +100,6 @@ Common::Error StarTrekEngine::run() {
_gfx->setPalette("BRIDGE.PAL");
//_gfx->loadEGAData("BRIDGE.EGA");
_gfx->drawImage("DEMON5.BMP");
//_gfx->drawImage("BRIDGE.BMP");
}

if (getPlatform() == Common::kPlatformAmiga)
@@ -134,6 +133,7 @@ Common::Error StarTrekEngine::run() {
}

Common::SeekableReadStream *StarTrekEngine::openFile(Common::String filename, int fileIndex) {
filename.toUppercase();
Common::String basename, extension;

for (int i=filename.size()-1; ; i--) {
@@ -216,9 +216,10 @@ Common::SeekableReadStream *StarTrekEngine::openFile(Common::String filename, in
delete indexFile;

if (!foundData) {
// Files with a number at the end are stored a bit differently; they are accessed
// based on a "base number". See if there's an earlier number that can be opened.
if (basename.lastChar() >= '1' && basename.lastChar() <= '9') {
// Files can be accessed "sequentially" if their filenames are the same except for
// the last character being incremented by one.
if ((basename.lastChar() >= '1' && basename.lastChar() <= '9') ||
(basename.lastChar() >= 'B' && basename.lastChar() <= 'Z')) {
basename.setChar(basename.lastChar()-1, basename.size()-1);
return openFile(basename + "." + extension, fileIndex+1);
} else
@@ -252,6 +253,7 @@ Common::SeekableReadStream *StarTrekEngine::openFile(Common::String filename, in
assert(fileCount == 1); // Sanity check...
Common::SeekableReadStream *stream = dataFile->readStream(uncompressedSize);
delete dataFile;
delete dataRunFile;
return stream;
} else {
if (fileCount != 1) {
@@ -271,7 +273,9 @@ Common::SeekableReadStream *StarTrekEngine::openFile(Common::String filename, in
uint16 compressedSize = (getPlatform() == Common::kPlatformAmiga) ? dataFile->readUint16BE() : dataFile->readUint16LE();

Common::SeekableReadStream *stream = decodeLZSS(dataFile->readStream(compressedSize), uncompressedSize);

delete dataFile;
delete dataRunFile;
return stream;
}

0 comments on commit 60d672d

Please sign in to comment.