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)); } }
bool SavePartVars::read(Common::ReadStream &stream) { if (!_header.verify(stream)) return false; if (stream.read(_data, _size) != _size) return false; return !stream.err(); }
bool SaveContainer::read(Common::ReadStream &stream) { // Verify the header and get the container's size if (!_header.verifyReadSize(stream)) return false; // The part count has to be correct if (stream.readUint32LE() != _partCount) return false; // Iterate over all parts for (PartIterator it = _parts.begin(); it != _parts.end(); ++it) { // Read the size uint32 size = stream.readUint32LE(); if (stream.err()) { clear(); return false; } Part *&p = *it; delete p; // Create a suitable part p = new Part(size); } // Update size _header.setSize(calcSize()); // Iterate over all parts for (PartIterator it = _parts.begin(); it != _parts.end(); ++it) { Part *&p = *it; // Read the part if (stream.read(p->data, p->size) != p->size) { clear(); return false; } } return !stream.err(); }
bool SaveHeader::read(Common::ReadStream &stream) { // Read the header and verify the global IDs if (stream.readUint32BE() != kID1) return false; if (stream.readUint32BE() != kID2) return false; _type = stream.readUint32BE(); _version = stream.readUint32LE(); _size = stream.readUint32LE(); return !stream.err(); }
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); }
bool SaveHeader::verify(Common::ReadStream &stream) const { // Compare the header with the stream's content if (stream.readUint32BE() != kID1) return false; if (stream.readUint32BE() != kID2) return false; if (stream.readUint32BE() != _type) return false; if (stream.readUint32LE() != _version) return false; if (stream.readUint32LE() != _size) return false; return !stream.err(); }
bool SaveHeader::verifyReadSize(Common::ReadStream &stream) { // Compare the header with the stream's content, expect for the size if (stream.readUint32BE() != kID1) return false; if (stream.readUint32BE() != kID2) return false; if (stream.readUint32BE() != _type) return false; if (stream.readUint32LE() != _version) return false; // Read the size out of the stream instead _size = stream.readUint32LE(); return !stream.err(); }
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(); }
void Display::loadFrameBuffer(Common::ReadStream &stream) { byte *dst = _frameBuf; for (uint j = 0; j < 8; ++j) { for (uint i = 0; i < 8; ++i) { stream.read(dst, DISPLAY_PITCH); dst += DISPLAY_PITCH * 64; stream.read(dst, DISPLAY_PITCH); dst += DISPLAY_PITCH * 64; stream.read(dst, DISPLAY_PITCH); stream.readUint32LE(); stream.readUint32LE(); dst -= DISPLAY_PITCH * 120; } dst -= DISPLAY_PITCH * 63; } if (stream.eos() || stream.err()) error("Failed to read frame buffer"); }
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(); }
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); } }