Skip to content

Commit

Permalink
ADL: Add hires2 command loading
Browse files Browse the repository at this point in the history
  • Loading branch information
waltervn committed Jun 6, 2016
1 parent 0a6b7fb commit 7ff7e0d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
8 changes: 6 additions & 2 deletions engines/adl/adl.cpp
Expand Up @@ -273,6 +273,11 @@ void AdlEngine::readCommands(Common::ReadStream &stream, Commands &commands) {
}
}

void AdlEngine::checkInput(byte verb, byte noun) {
if (!doOneCommand(_roomCommands, verb, noun))
printMessage(_messageIds.dontUnderstand);
}

void AdlEngine::clearScreen() const {
_display->setMode(DISPLAY_MODE_MIXED);
_display->clear(0x00);
Expand Down Expand Up @@ -448,8 +453,7 @@ Common::Error AdlEngine::run() {
// If we just restored from the GMM, we skip this command
// set, as no command has been input by the user
if (!_isRestoring)
if (!doOneCommand(_roomCommands, verb, noun))
printMessage(_messageIds.dontUnderstand);
checkInput(verb, noun);
}

if (_isRestoring) {
Expand Down
1 change: 1 addition & 0 deletions engines/adl/adl.h
Expand Up @@ -163,6 +163,7 @@ class AdlEngine : public Engine {

void loadWords(Common::ReadStream &stream, WordMap &map) const;
void readCommands(Common::ReadStream &stream, Commands &commands);
virtual void checkInput(byte verb, byte noun);

// Graphics
void clearScreen() const;
Expand Down
26 changes: 24 additions & 2 deletions engines/adl/hires2.cpp
Expand Up @@ -83,6 +83,13 @@ void HiRes2Engine::init() {
_messageIds.itemNotHere = IDI_HR2_MSG_ITEM_NOT_HERE;
_messageIds.thanksForPlaying = IDI_HR2_MSG_THANKS_FOR_PLAYING;

// Load commands from executable
f.seek(IDI_HR2_OFS_CMDS_1);
readCommands(f, _roomCommands);

f.seek(IDI_HR2_OFS_CMDS_0);
// readCommands(f, _globalCommands);

f.seek(IDI_HR2_OFS_VERBS);
loadWords(f, _verbs);

Expand All @@ -91,6 +98,9 @@ void HiRes2Engine::init() {
}

void HiRes2Engine::initState() {
_state.vars.clear();
_state.vars.resize(IDI_HR2_NUM_VARS);

Common::File f;
openFile(f, IDS_HR2_DISK_IMAGE);

Expand Down Expand Up @@ -119,7 +129,7 @@ void HiRes2Engine::loadRoom(byte roomNr) {
uint offset = TSO(room.track, room.sector, room.offset);
f.seek(offset);
uint16 descOffset = f.readUint16LE();
/* uint16 commandOffset =*/ f.readUint16LE();
uint16 commandOffset = f.readUint16LE();

// There's no picture count. The original engine always checks at most
// five pictures. We use the description offset to bound our search.
Expand All @@ -134,7 +144,12 @@ void HiRes2Engine::loadRoom(byte roomNr) {
f.readByte();
_roomData.pictures.push_back(pic);
}

_roomData.description = readStringAt(f, offset + descOffset, 0xff);

f.seek(offset + commandOffset);

readCommands(f, _roomData.commands);
}

void HiRes2Engine::restartGame() {
Expand All @@ -158,16 +173,23 @@ void HiRes2Engine::drawPic(byte pic, Common::Point pos) const {

void HiRes2Engine::showRoom() {
loadRoom(_state.room);
_linesPrinted = 0;
drawPic(getCurRoom().curPicture, Common::Point());
_display->updateHiResScreen();
printString(_roomData.description);
_linesPrinted = 0;
}

void HiRes2Engine::printMessage(uint idx, bool wait) {
printString(_messages[idx - 1]);
}

void HiRes2Engine::checkInput(byte verb, byte noun) {
if (doOneCommand(_roomData.commands, verb, noun))
return;

AdlEngine::checkInput(verb, noun);
}

void HiRes2Engine::checkTextOverflow(char c) {
if (c != APPLECHAR('\r'))
return;
Expand Down
6 changes: 6 additions & 0 deletions engines/adl/hires2.h
Expand Up @@ -47,8 +47,12 @@ namespace Adl {
#define IDI_HR2_OFS_ROOMS TSO(0x21, 0x5, 0x0e) // Skip bogus room 0
#define IDI_HR2_OFS_MESSAGES TSO(0x1f, 0x2, 0x04) // Skip bogus message 0

#define IDI_HR2_OFS_CMDS_0 TS(0x1f, 0x7)
#define IDI_HR2_OFS_CMDS_1 TS(0x1d, 0x7)

#define IDI_HR2_NUM_ROOMS 135
#define IDI_HR2_NUM_MESSAGES 254
#define IDI_HR2_NUM_VARS 40

// Messages used outside of scripts
#define IDI_HR2_MSG_CANT_GO_THERE 123
Expand All @@ -73,6 +77,7 @@ struct Picture2 {
struct RoomData {
Common::String description;
Common::Array<Picture2> pictures;
Commands commands;
};

class HiRes2Engine : public AdlEngine {
Expand All @@ -89,6 +94,7 @@ class HiRes2Engine : public AdlEngine {
void drawItem(const Item &item, const Common::Point &pos) const { }
void showRoom();
void printMessage(uint idx, bool wait);
void checkInput(byte verb, byte noun);

void loadRoom(byte roomNr);
void checkTextOverflow(char c);
Expand Down

0 comments on commit 7ff7e0d

Please sign in to comment.