From 177206cc2efba4a2991f29f67a2d4f68d2bcc899 Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Sun, 28 Aug 2016 18:10:59 +0200 Subject: ADL: Load hires4 commands and item pictures --- engines/adl/adl_v2.cpp | 7 +++++++ engines/adl/adl_v2.h | 1 + engines/adl/disk.cpp | 2 +- engines/adl/hires0.cpp | 5 +---- engines/adl/hires2.cpp | 5 +---- engines/adl/hires4.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++------ engines/adl/hires4.h | 11 +++++++++-- engines/adl/hires6.cpp | 5 +---- 8 files changed, 67 insertions(+), 21 deletions(-) diff --git a/engines/adl/adl_v2.cpp b/engines/adl/adl_v2.cpp index ae4c2d8d84..4522591620 100644 --- a/engines/adl/adl_v2.cpp +++ b/engines/adl/adl_v2.cpp @@ -429,6 +429,13 @@ void AdlEngine_v2::loadPictures(Common::SeekableReadStream &stream) { } } +void AdlEngine_v2::loadItemPictures(Common::SeekableReadStream &stream, byte count) { + for (uint i = 0; i < count; ++i) { + stream.readByte(); // number + _itemPics.push_back(readDataBlockPtr(stream)); + } +} + int AdlEngine_v2::o2_isFirstTime(ScriptEnv &e) { OP_DEBUG_0("\t&& IS_FIRST_TIME()"); diff --git a/engines/adl/adl_v2.h b/engines/adl/adl_v2.h index 4136afb857..85c7544563 100644 --- a/engines/adl/adl_v2.h +++ b/engines/adl/adl_v2.h @@ -57,6 +57,7 @@ protected: void loadRooms(Common::SeekableReadStream &stream, byte count); void loadMessages(Common::SeekableReadStream &stream, byte count); void loadPictures(Common::SeekableReadStream &stream); + void loadItemPictures(Common::SeekableReadStream &stream, byte count); void checkTextOverflow(char c); diff --git a/engines/adl/disk.cpp b/engines/adl/disk.cpp index 6a5cf0b20c..d429556670 100644 --- a/engines/adl/disk.cpp +++ b/engines/adl/disk.cpp @@ -265,7 +265,7 @@ Common::SeekableReadStream *DiskImage::createReadStream(uint track, uint sector, bytesRemInTrack = bytesToRead - dataOffset; if (_stream->read(data + dataOffset, bytesRemInTrack) < bytesRemInTrack) - error("Error reading disk image"); + error("Error reading disk image at track %d; sector %d", track, sector); ++track; diff --git a/engines/adl/hires0.cpp b/engines/adl/hires0.cpp index 1c18123571..d5f7ab552e 100644 --- a/engines/adl/hires0.cpp +++ b/engines/adl/hires0.cpp @@ -77,10 +77,7 @@ void HiRes0Engine::init() { // Load item picture data stream.reset(_disk->createReadStream(0x1e, 0x9, 0x05)); - for (uint i = 0; i < IDI_HR0_NUM_ITEM_PICS; ++i) { - stream->readByte(); // number - _itemPics.push_back(readDataBlockPtr(*stream)); - } + loadItemPictures(*stream, IDI_HR0_NUM_ITEM_PICS); // Load commands from executable stream.reset(_disk->createReadStream(0x1d, 0x7, 0x00, 2)); diff --git a/engines/adl/hires2.cpp b/engines/adl/hires2.cpp index 69e7e74589..25a3bbacf2 100644 --- a/engines/adl/hires2.cpp +++ b/engines/adl/hires2.cpp @@ -100,10 +100,7 @@ void HiRes2Engine::init() { // Load item picture data stream.reset(_disk->createReadStream(0x1e, 0x9, 0x05)); - for (uint i = 0; i < IDI_HR2_NUM_ITEM_PICS; ++i) { - stream->readByte(); // number - _itemPics.push_back(readDataBlockPtr(*stream)); - } + loadItemPictures(*stream, IDI_HR2_NUM_ITEM_PICS); // Load commands from executable stream.reset(_disk->createReadStream(0x1d, 0x7, 0x00, 4)); diff --git a/engines/adl/hires4.cpp b/engines/adl/hires4.cpp index 7d20457b30..ae04a66f94 100644 --- a/engines/adl/hires4.cpp +++ b/engines/adl/hires4.cpp @@ -45,9 +45,7 @@ void HiRes4Engine::init() { if (!_boot->open(getDiskImageName(0))) error("Failed to open disk image '%s'", getDiskImageName(0)); - _disk = new DiskImage(); - if (!_disk->open(getDiskImageName(1))) - error("Failed to open disk image '%s'", getDiskImageName(1)); + insertDisk(1); loadCommonData(); @@ -65,6 +63,12 @@ void HiRes4Engine::init() { stream.reset(createReadStream(_boot, 0x06, 0xd, 0x12, 2)); loadItemDescriptions(*stream, IDI_HR4_NUM_ITEM_DESCS); + 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); @@ -72,6 +76,31 @@ void HiRes4Engine::init() { loadWords(*stream, _nouns, _priNouns); } +void HiRes4Engine::loadRoom(byte roomNr) { + if (roomNr >= 59 && roomNr < 113) { + insertDisk(2); + rebindDisk(); + } else { + insertDisk(1); + rebindDisk(); + } + + if (roomNr == 121) { + // Room 121 is not present in the Atari version. This causes + // problems when we're dumping scripts with the debugger, so + // we intercept this room load here. + // FIXME: Find out if the Apple II version does have this room + // FIXME: Implement more generic handling of invalid rooms? + debug("Warning: attempt to load non-existent room 121"); + _roomData.description.clear(); + _roomData.pictures.clear(); + _roomData.commands.clear(); + return; + } + + AdlEngine_v3::loadRoom(roomNr); +} + Common::String HiRes4Engine::formatVerbError(const Common::String &verb) const { Common::String err = _strings.verbError; for (uint i = 0; i < verb.size(); ++i) @@ -88,13 +117,20 @@ Common::String HiRes4Engine::formatNounError(const Common::String &verb, const C return err; } -void HiRes4Engine::goToSideC() { +void HiRes4Engine::insertDisk(byte diskNr) { + if (_curDisk == diskNr) + return; + + _curDisk = diskNr; + delete _disk; _disk = new DiskImage(); - if (!_disk->open(getDiskImageName(2))) - error("Failed to open disk image '%s'", getDiskImageName(2)); + if (!_disk->open(getDiskImageName(diskNr))) + error("Failed to open disk image '%s'", getDiskImageName(diskNr)); +} +void HiRes4Engine::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 @@ -119,6 +155,10 @@ void HiRes4Engine::loadCommonData() { _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); } void HiRes4Engine::initGameState() { diff --git a/engines/adl/hires4.h b/engines/adl/hires4.h index 1d21e0c55b..fd682cb13d 100644 --- a/engines/adl/hires4.h +++ b/engines/adl/hires4.h @@ -32,6 +32,7 @@ namespace Adl { #define IDI_HR4_NUM_ROOMS 164 #define IDI_HR4_NUM_MESSAGES 255 #define IDI_HR4_NUM_VARS 40 +#define IDI_HR4_NUM_ITEM_PICS 41 #define IDI_HR4_NUM_ITEM_DESCS 44 // Messages used outside of scripts @@ -46,20 +47,26 @@ public: ~HiRes4Engine(); protected: - HiRes4Engine(OSystem *syst, const AdlGameDescription *gd) : AdlEngine_v3(syst, gd) { } + HiRes4Engine(OSystem *syst, const AdlGameDescription *gd) : + AdlEngine_v3(syst, gd), + _boot(nullptr), + _curDisk(0) { } // AdlEngine void init(); void initGameState(); + void loadRoom(byte roomNr); Common::String formatVerbError(const Common::String &verb) const; Common::String formatNounError(const Common::String &verb, const Common::String &noun) const; Common::SeekableReadStream *createReadStream(DiskImage *disk, byte track, byte sector, byte offset = 0, byte size = 0) const; void loadCommonData(); - void goToSideC(); + void insertDisk(byte diskNr); + void rebindDisk(); virtual const char *getDiskImageName(byte index) const = 0; DiskImage *_boot; + byte _curDisk; }; class HiRes4Engine_Atari : public HiRes4Engine { diff --git a/engines/adl/hires6.cpp b/engines/adl/hires6.cpp index c2843ea141..314d8174b4 100644 --- a/engines/adl/hires6.cpp +++ b/engines/adl/hires6.cpp @@ -186,10 +186,7 @@ void HiRes6Engine::loadDisk(byte disk) { // Load item picture data (indexed on boot disk) StreamPtr stream(_boot->createReadStream(0xb, 0xd, 0x08)); _itemPics.clear(); - for (uint i = 0; i < IDI_HR6_NUM_ITEM_PICS; ++i) { - stream->readByte(); - _itemPics.push_back(readDataBlockPtr(*stream)); - } + loadItemPictures(*stream, IDI_HR6_NUM_ITEM_PICS); _curDisk = disk; -- cgit v1.2.3