void HiRes4Engine_Atari::initGameState() { _state.vars.resize(IDI_HR4_NUM_VARS); StreamPtr stream(createReadStream(_boot, 0x03, 0x1, 0x0e, 9)); loadRooms(*stream, IDI_HR4_NUM_ROOMS); stream.reset(createReadStream(_boot, 0x02, 0xc, 0x00, 12)); loadItems(*stream); // FIXME _display->moveCursorTo(Common::Point(0, 23)); }
void HiRes4Engine_Atari::loadCommonData() { _messages.clear(); StreamPtr stream(createReadStream(_boot, 0x0a, 0x4, 0x00, 3)); loadMessages(*stream, IDI_HR4_NUM_MESSAGES); _pictures.clear(); stream.reset(createReadStream(_boot, 0x05, 0xe, 0x80)); loadPictures(*stream); _itemPics.clear(); stream.reset(createReadStream(_boot, 0x09, 0xe, 0x05)); loadItemPictures(*stream, IDI_HR4_NUM_ITEM_PICS); }
bool HTTP_Stream::open(const HTTP_Stream_Position& position) { bool success = false; CFStreamClientContext CTX = { 0, this, NULL, NULL, NULL }; /* Already opened a read stream, return */ if (m_readStream) { goto out; } /* Reset state */ m_position = position; m_readPending = false; m_httpHeadersParsed = false; m_contentType = ""; m_icyStream = false; m_icyHeaderCR = false; m_icyHeadersRead = false; m_icyHeadersParsed = false; m_icyHeaderLines.clear(); m_icyMetaDataInterval = 0; m_dataByteReadCount = 0; m_metaDataBytesRemaining = 0; if (!m_url) { goto out; } /* Failed to create a stream */ if (!(m_readStream = createReadStream(m_url))) { goto out; } if (!CFReadStreamSetClient(m_readStream, kCFStreamEventHasBytesAvailable | kCFStreamEventEndEncountered | kCFStreamEventErrorOccurred, readCallBack, &CTX)) { CFRelease(m_readStream), m_readStream = 0; goto out; } setScheduledInRunLoop(true); if (!CFReadStreamOpen(m_readStream)) { /* Open failed: clean */ CFReadStreamSetClient(m_readStream, 0, NULL, NULL); setScheduledInRunLoop(false); if (m_readStream) { CFRelease(m_readStream), m_readStream = 0; } goto out; } success = true; out: return success; }
void HiRes4Engine_Atari::init() { _graphics = new Graphics_v2(*_display); _boot = new DiskImage(); if (!_boot->open(atariDisks[0])) error("Failed to open disk image '%s'", atariDisks[0]); insertDisk(1); loadCommonData(); StreamPtr stream(createReadStream(_boot, 0x06, 0x2)); _strings.verbError = readStringAt(*stream, 0x4f); _strings.nounError = readStringAt(*stream, 0x83); _strings.enterCommand = readStringAt(*stream, 0xa6); stream.reset(createReadStream(_boot, 0x05, 0xb, 0xd7)); _strings_v2.time = readString(*stream, 0xff); stream.reset(createReadStream(_boot, 0x06, 0x7, 0x00, 2)); _strings_v2.saveInsert = readStringAt(*stream, 0x62); _strings_v2.saveReplace = readStringAt(*stream, 0xdd); _strings_v2.restoreInsert = readStringAt(*stream, 0x12a); _strings_v2.restoreReplace = readStringAt(*stream, 0x1b8); _strings.playAgain = readStringAt(*stream, 0x21b); // TODO: restart sequence has "insert side a/b" strings _messageIds.cantGoThere = IDI_HR4_MSG_CANT_GO_THERE; _messageIds.dontUnderstand = IDI_HR4_MSG_DONT_UNDERSTAND; _messageIds.itemDoesntMove = IDI_HR4_MSG_ITEM_DOESNT_MOVE; _messageIds.itemNotHere = IDI_HR4_MSG_ITEM_NOT_HERE; _messageIds.thanksForPlaying = IDI_HR4_MSG_THANKS_FOR_PLAYING; stream.reset(createReadStream(_boot, 0x06, 0xd, 0x12, 2)); loadItemDescriptions(*stream, IDI_HR4_NUM_ITEM_DESCS); stream.reset(createReadStream(_boot, 0x07, 0x1, 0xf4)); loadDroppedItemOffsets(*stream, IDI_HR4_NUM_ITEM_OFFSETS); stream.reset(createReadStream(_boot, 0x08, 0xe, 0xa5, 5)); readCommands(*stream, _roomCommands); stream.reset(createReadStream(_boot, 0x0a, 0x9, 0x00, 3)); readCommands(*stream, _globalCommands); stream.reset(createReadStream(_boot, 0x05, 0x4, 0x00, 3)); loadWords(*stream, _verbs, _priVerbs); stream.reset(createReadStream(_boot, 0x03, 0xb, 0x00, 6)); loadWords(*stream, _nouns, _priNouns); }
uint32 Resource::getFileSize(const char *file) { Common::SeekableReadStream *stream = createReadStream(file); if (!stream) return 0; uint32 size = stream->size(); delete stream; return size; }
bool Resource::loadFileToBuf(const char *file, void *buf, uint32 maxSize) { Common::SeekableReadStream *stream = createReadStream(file); if (!stream) return false; memset(buf, 0, maxSize); stream->read(buf, ((int32)maxSize <= stream->size()) ? maxSize : stream->size()); delete stream; return true; }
uint8 *Resource::fileData(const char *file, uint32 *size) { Common::SeekableReadStream *stream = createReadStream(file); if (!stream) return 0; uint32 bufferSize = stream->size(); uint8 *buffer = new uint8[bufferSize]; assert(buffer); if (size) *size = bufferSize; stream->read(buffer, bufferSize); delete stream; return buffer; }
void test_seek() { for (unsigned int i = 0; i < 50; i++) { uint8 buffer[MAX_BUFFER]; uint32 size = (cOSRand::rand() % (MAX_BUFFER - 2)) + 2; for (uint32 i = 0; i < size; i++) { buffer[i] = (uint8)cOSRand::rand(); } int type = cOSRand::rand(); // Create the stream { cSmartPtr<basicIO> stream = createStream(type); stream->pipeWrite(buffer, size); closeStream(type, stream); } // Read from the stream with seeking... { cSmartPtr<basicIO> rstream = createReadStream(type); // From begin unsigned int idx; for (idx = 0; idx < 10; idx++) { int positionFromBegin = cOSRand::rand() % size; rstream->seek(positionFromBegin, basicInput::IO_SEEK_SET); uint8 ch; TESTS_ASSERT_EQUAL(rstream->pipeRead(&ch, 1), 1); TESTS_ASSERT_EQUAL(buffer[positionFromBegin], ch); } // From end for (idx = 0; idx < 10; idx++) { int positionFromEnd = (cOSRand::rand() % (size - 1)) + 1; positionFromEnd = -positionFromEnd; rstream->seek(positionFromEnd, basicInput::IO_SEEK_END); uint8 ch; TESTS_ASSERT_EQUAL(rstream->pipeRead(&ch, 1), 1); TESTS_ASSERT_EQUAL(buffer[size + positionFromEnd], ch); } } cout << '-'; cout.flush(); } }
void HiRes4Engine_Atari::rebindDisk() { // As room.data is bound to the DiskImage, we need to rebind them here // We cannot simply reload the rooms as that would reset their state // FIXME: Remove DataBlockPtr-DiskImage coupling? StreamPtr stream(createReadStream(_boot, 0x03, 0x1, 0x0e, 9)); for (uint i = 0; i < IDI_HR4_NUM_ROOMS; ++i) { stream->skip(7); _state.rooms[i].data = readDataBlockPtr(*stream); stream->skip(3); } // Rebind data that is on both side B and C loadCommonData(); }
void test_read_write() { for (unsigned int i = 0; i < 50; i++) { uint8 buffer[MAX_BUFFER]; uint8 read[MAX_BUFFER]; uint32 size = (cOSRand::rand() % (MAX_BUFFER - 1)) + 1; for (uint32 i = 0; i < size; i++) { buffer[i] = (uint8)cOSRand::rand(); read[i] = 0; } int type = cOSRand::rand(); // Write out to the stream { cSmartPtr<basicIO> stream = createStream(type); stream->pipeWrite(buffer, size); closeStream(type, stream); } // Read from the stream { cSmartPtr<basicIO> rstream = createReadStream(type); rstream->pipeRead(read, size); // Test the reading for (uint32 j = 0; j < size; j++) { TESTS_ASSERT_EQUAL(read[j], buffer[j]); } TESTS_ASSERT(rstream->isEOS()); } cout << ','; cout.flush(); } }
bool Resource::loadFileList(const Common::String &filedata) { Common::SeekableReadStream *f = createReadStream(filedata); if (!f) return false; uint32 filenameOffset = 0; while ((filenameOffset = f->readUint32LE()) != 0) { uint32 offset = f->pos(); f->seek(filenameOffset, SEEK_SET); uint8 buffer[13]; f->read(buffer, sizeof(buffer)-1); buffer[12] = 0; f->seek(offset + 16, SEEK_SET); Common::String filename = Common::String((char *)buffer); filename.toUppercase(); if (filename.hasSuffix(".PAK")) { if (!exists(filename.c_str()) && _vm->gameFlags().isDemo) { // the demo version supplied with Kyra3 does not // contain all pak files listed in filedata.fdt // so we don't do anything here if they are non // existant. } else if (!loadPakFile(filename)) { delete f; error("couldn't load file '%s'", filename.c_str()); return false; // for compilers that don't support NORETURN } } } delete f; return true; }