Beispiel #1
0
void HiRes5Engine::loadSong(Common::ReadStream &stream) {
	while (true) {
		const byte period = stream.readByte();

		if (stream.err() || stream.eos())
			error("Error loading song");

		if (period == 0xff)
			return;

		byte length = stream.readByte();

		if (stream.err() || stream.eos())
			error("Error loading song");

		const uint kLoopCycles = 20; // Delay loop cycles

		double freq = 0.0;

		// This computation ignores CPU cycles spent on overflow handling and
		// speaker control. As a result, our tone frequencies will be slightly
		// higher than those on original hardware.
		if (period != 0)
			freq = kClock / 2.0 / (period * kLoopCycles);

		const double len = (length > 0 ? length - 1 : 255) * 256 * kLoopCycles * 1000 / (double)kClock;

		_song.push_back(Tone(freq, len));
	}
}
Beispiel #2
0
Common::String *LureEngine::detectSave(int slotNumber) {
	Common::ReadStream *f = this->_saveFileMan->openForLoading(
		generateSaveName(slotNumber));
	if (f == NULL) return NULL;
	Common::String *result = NULL;

	// Check for header
	char buffer[5];
	f->read(&buffer[0], 5);
	if (memcmp(&buffer[0], "lure", 5) == 0) {
		// Check language version
		uint8 language = f->readByte();
		uint8 version = f->readByte();
		if ((language == getLanguage()) && (version >= LURE_MIN_SAVEGAME_MINOR)) {
			// Read in the savegame title
			char saveName[MAX_DESC_SIZE];
			char *p = saveName;
			int decCtr = MAX_DESC_SIZE - 1;
			while ((decCtr > 0) && ((*p++ = f->readByte()) != 0)) --decCtr;
			*p = '\0';
			result = new Common::String(saveName);
		}
	}

	delete f;
	return result;
}
Beispiel #3
0
void Parser::readBG(Common::ReadStream &in, Background &curBG) {
	curBG._verbIndex = in.readUint16BE();
	curBG._nounIndex = in.readUint16BE();
	curBG._commentIndex = in.readSint16BE();
	curBG._matchFl = (in.readByte() != 0);
	curBG._roomState = in.readByte();
	curBG._bonusIndex = in.readByte();
}
Beispiel #4
0
void Parser::readBG(Common::ReadStream &in, background_t &curBG) {
	curBG.verbIndex = in.readUint16BE();
	curBG.nounIndex = in.readUint16BE();
	curBG.commentIndex = in.readSint16BE();
	curBG.matchFl = (in.readByte() != 0);
	curBG.roomState = in.readByte();
	curBG.bonusIndex = in.readByte();
}
Beispiel #5
0
void Voice8Header::load(Common::ReadStream &stream) {
	oneShotHiSamples = stream.readUint32BE();
	repeatHiSamples = stream.readUint32BE();
	samplesPerHiCycle = stream.readUint32BE();
	samplesPerSec = stream.readUint16BE();
	octaves = stream.readByte();
	compression = stream.readByte();
	volume = stream.readUint32BE();
}
Beispiel #6
0
/**
 * Extracts a string from a data stream
 * @param df                data stream
 */
Common::String readString(Common::ReadStream &df) {
	Common::String var;
	uint8 len = df.readByte();

	for (int i = 0; i < len; i++) {
		char c;
		c = df.readByte();
		var += c;
	}

	return var;
}
Beispiel #7
0
DataBlockPtr AdlEngine_v2::readDataBlockPtr(Common::ReadStream &f) const {
	byte track = f.readByte();
	byte sector = f.readByte();
	byte offset = f.readByte();
	byte size = f.readByte();

	if (f.eos() || f.err())
		error("Error reading DataBlockPtr");

	if (track == 0 && sector == 0 && offset == 0 && size == 0)
		return DataBlockPtr();

	return _disk->getDataBlock(track, sector, offset, size);
}
Beispiel #8
0
static void deDPCM8Stereo(int16 *out, Common::ReadStream &audioStream, uint32 numBytes, uint8 &sampleL, uint8 &sampleR) {
	for (uint32 i = 0; i < numBytes; ++i) {
		const uint8 delta = audioStream.readByte();
		deDPCM8Nibble(out++, sampleL, delta >> 4);
		deDPCM8Nibble(out++, sampleR, delta & 0xf);
	}
}
Beispiel #9
0
/**
 * Read a cmd structure from Hugo.dat
 */
void Parser::readCmd(Common::ReadStream &in, cmd &curCmd) {
	curCmd.verbIndex = in.readUint16BE();
	curCmd.reqIndex = in.readUint16BE();
	curCmd.textDataNoCarryIndex = in.readUint16BE();
	curCmd.reqState = in.readByte();
	curCmd.newState = in.readByte();
	curCmd.textDataWrongIndex = in.readUint16BE();
	curCmd.textDataDoneIndex = in.readUint16BE();
	curCmd.actIndex = in.readUint16BE();
}
Beispiel #10
0
/**
 * Load a NULL-terminated string from the given stream.
 */
static Common::String loadString(Common::ReadStream &in, uint maxSize = 999) {
	Common::String result;

	while (!in.eos() && (result.size() < maxSize)) {
		char ch = (char)in.readByte();
		if (ch == '\0')
			break;

		result += ch;
	}

	return result;
}
Beispiel #11
0
bool LureEngine::loadGame(uint8 slotNumber) {
	Common::ReadStream *f = this->_saveFileMan->openForLoading(
		generateSaveName(slotNumber));
	if (f == NULL)
		return false;

	// Check for header
	char buffer[5];
	f->read(buffer, 5);
	if (memcmp(buffer, "lure", 5) != 0) {
		warning(FAILED_MSG, slotNumber);
		delete f;
		return false;
	}

	// Check language version
	uint8 language = f->readByte();
	_saveVersion = f->readByte();
	if ((language != getLureLanguage()) || (_saveVersion < LURE_MIN_SAVEGAME_MINOR)) {
		warning("loadGame: Failed to load slot %d - incorrect version", slotNumber);
		delete f;
		return false;
	}

	// Read in and discard the savegame caption
	while (f->readByte() != 0)
		;

	// Load in the data
	Resources::getReference().loadFromStream(f);
	Game::getReference().loadFromStream(f);
	Sound.loadFromStream(f);
	Fights.loadFromStream(f);
	Room::getReference().loadFromStream(f);

	delete f;
	return true;
}
Beispiel #12
0
Common::String XARCMember::readString(Common::ReadStream &stream) {
	Common::String str;

	// Read until we find a 0
	char c = 1;
	while (c != 0) {
		c = stream.readByte();
		if (stream.eos()) {
			c = 0;
		} else {
			str += c;
		}
	}

	return str;
}
Beispiel #13
0
bool SavePartSprite::read(Common::ReadStream &stream) {
	SaveHeader header;
	header.read(stream);

	if (_header != header) {
		if (!_trueColor) {
			// Header validation failed, trying again with the old version

			_header.setVersion(1);
			_header.setSize(_header.getSize() - 1);

			if (_header != header)
				// Nope, isn't it either
				return false;

			_oldFormat = true;

			_header.setVersion(kVersion);
			_header.setSize(_header.getSize() + 1);

		} else
			return false;
	}

	// The sprite's dimensions have to fit
	if (stream.readUint32LE() != _width)
		return false;
	if (stream.readUint32LE() != _height)
		return false;

	// If it's in the current format, the true color flag has to be the same too
	if (!_oldFormat)
		if ((stream.readByte() != 0) != _trueColor)
			return false;

	// Sprite data
	if (stream.read(_dataSprite, _spriteSize) != _spriteSize)
		return false;

	// Palette data
	if (stream.read(_dataPalette, 768) != 768)
		return false;

	return !stream.err();
}
Beispiel #14
0
bool SavePartInfo::read(Common::ReadStream &stream) {
	if (!_header.verify(stream))
		return false;

	if (stream.readUint32LE() != _gameID)
		return false;
	if (stream.readUint32LE() != _gameVersion)
		return false;
	if (stream.readByte() != _endian)
		return false;
	if (stream.readUint32LE() != _varCount)
		return false;
	if (stream.readUint32LE() != _descMaxLength)
		return false;

	if (stream.read(_desc, _descMaxLength) != _descMaxLength)
		return false;

	_desc[_descMaxLength] = 0;

	return !stream.err();
}
Beispiel #15
0
void Graphics_v1::drawCorners(Common::ReadStream &corners, const Common::Point &pos, byte rotation, byte scaling, byte color) const {
	const byte stepping[] = {
		0xff, 0xfe, 0xfa, 0xf4, 0xec, 0xe1, 0xd4, 0xc5,
		0xb4, 0xa1, 0x8d, 0x78, 0x61, 0x49, 0x31, 0x18,
		0xff
	};

	byte quadrant = rotation >> 4;
	rotation &= 0xf;
	byte xStep = stepping[rotation];
	byte yStep = stepping[(rotation ^ 0xf) + 1] + 1;

	Common::Point p(pos);

	while (true) {
		byte b = corners.readByte();

		if (corners.eos() || corners.err())
			error("Error reading corners");

		if (b == 0)
			return;

		do {
			byte xFrac = 0x80;
			byte yFrac = 0x80;
			for (uint j = 0; j < scaling; ++j) {
				if (xFrac + xStep + 1 > 255)
					drawCornerPixel(p, color, b, quadrant);
				xFrac += xStep + 1;
				if (yFrac + yStep > 255)
					drawCornerPixel(p, color, b, quadrant + 1);
				yFrac += yStep;
			}
			b >>= 3;
		} while (b != 0);
	}
}