Skip to content

Commit

Permalink
ADL: Implement hires2 word wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
waltervn committed Jun 6, 2016
1 parent 0686ba9 commit b4aea80
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 24 deletions.
5 changes: 3 additions & 2 deletions engines/adl/adl.cpp
Expand Up @@ -161,12 +161,13 @@ Common::String AdlEngine::inputString(byte prompt) const {
}
}

byte AdlEngine::inputKey() const {
byte AdlEngine::inputKey(bool showCursor) const {
Common::EventManager *ev = g_system->getEventManager();

byte key = 0;

_display->showCursor(true);
if (showCursor)
_display->showCursor(true);

while (!g_engine->shouldQuit() && !_isRestoring && key == 0) {
Common::Event event;
Expand Down
4 changes: 2 additions & 2 deletions engines/adl/adl.h
Expand Up @@ -149,7 +149,7 @@ class AdlEngine : public Engine {
void delay(uint32 ms) const;

Common::String inputString(byte prompt = 0) const;
byte inputKey() const;
byte inputKey(bool showCursor = true) const;

void loadWords(Common::ReadStream &stream, WordMap &map) const;
void readCommands(Common::ReadStream &stream, Commands &commands);
Expand Down Expand Up @@ -215,7 +215,7 @@ class AdlEngine : public Engine {
virtual void initState() = 0;
virtual void restartGame() = 0;
virtual void drawItem(const Item &item, const Common::Point &pos) const = 0;
virtual void showRoom() const = 0;
virtual void showRoom() = 0;

// Engine
Common::Error run();
Expand Down
30 changes: 15 additions & 15 deletions engines/adl/display.cpp
Expand Up @@ -41,8 +41,6 @@ namespace Adl {
#define DISPLAY_PITCH (DISPLAY_WIDTH / 7)
#define DISPLAY_SIZE (DISPLAY_PITCH * DISPLAY_HEIGHT)

#define TEXT_WIDTH 40
#define TEXT_HEIGHT 24
#define TEXT_BUF_SIZE (TEXT_WIDTH * TEXT_HEIGHT)

#define COLOR_PALETTE_ENTRIES 8
Expand Down Expand Up @@ -291,21 +289,23 @@ void Display::moveCursorTo(const Common::Point &pos) {
error("Cursor position (%i, %i) out of bounds", pos.x, pos.y);
}

// FIXME: This does not currently update the surfaces
void Display::printChar(char c) {
if (c == APPLECHAR('\r'))
_cursorPos = (_cursorPos / TEXT_WIDTH + 1) * TEXT_WIDTH;
else if ((byte)c < 0x80 || (byte)c >= 0xa0) {
setCharAtCursor(c);
++_cursorPos;
}

if (_cursorPos == TEXT_BUF_SIZE)
scrollUp();
}

void Display::printString(const Common::String &str) {
Common::String::const_iterator c;
for (c = str.begin(); c != str.end(); ++c) {
byte b = *c;

if (*c == APPLECHAR('\r'))
_cursorPos = (_cursorPos / TEXT_WIDTH + 1) * TEXT_WIDTH;
else if (b < 0x80 || b >= 0xa0) {
setCharAtCursor(b);
++_cursorPos;
}

if (_cursorPos == TEXT_BUF_SIZE)
scrollUp();
}
for (c = str.begin(); c != str.end(); ++c)
printChar(*c);

updateTextScreen();
}
Expand Down
3 changes: 3 additions & 0 deletions engines/adl/display.h
Expand Up @@ -40,6 +40,8 @@ namespace Adl {

#define DISPLAY_WIDTH 280
#define DISPLAY_HEIGHT 192
#define TEXT_WIDTH 40
#define TEXT_HEIGHT 24

enum DisplayMode {
DISPLAY_MODE_HIRES,
Expand Down Expand Up @@ -71,6 +73,7 @@ class Display {
void moveCursorTo(const Common::Point &pos);
void moveCursorForward();
void moveCursorBackward();
void printChar(char c);
void printString(const Common::String &str);
void printAsciiString(const Common::String &str);
void setCharAtCursor(byte c);
Expand Down
2 changes: 1 addition & 1 deletion engines/adl/hires1.cpp
Expand Up @@ -303,7 +303,7 @@ void HiRes1Engine::drawItem(const Item &item, const Common::Point &pos) const {
drawPic(item.picture, pos);
}

void HiRes1Engine::showRoom() const {
void HiRes1Engine::showRoom() {
if (!_state.isDark) {
drawPic(getCurRoom().curPicture);
drawItems();
Expand Down
2 changes: 1 addition & 1 deletion engines/adl/hires1.h
Expand Up @@ -101,7 +101,7 @@ class HiRes1Engine : public AdlEngine {
void drawPic(byte pic, Common::Point pos = Common::Point()) const;
void printMessage(uint idx, bool wait = true) const;
void drawItem(const Item &item, const Common::Point &pos) const;
void showRoom() const;
void showRoom();

Common::File _exe;
Common::Array<uint> _corners;
Expand Down
76 changes: 75 additions & 1 deletion engines/adl/hires2.cpp
Expand Up @@ -110,6 +110,17 @@ void HiRes2Engine::initState() {
f.readByte(); // always 1, possibly disk?
_state.rooms.push_back(room);
}

loadRoom(_state.room);
}

void HiRes2Engine::loadRoom(uint i) {
Common::File f;
openFile(f, IDS_HR2_DISK_IMAGE);
Room &room = getRoom(i);
uint offset = TSO(room.track, room.sector, room.offset);
f.seek(offset);
_roomData.description = readStringAt(f, offset + f.readByte(), 0xff);
}

void HiRes2Engine::restartGame() {
Expand All @@ -126,9 +137,72 @@ void HiRes2Engine::drawPic(byte pic, Common::Point pos) const {
_graphics->drawPic(f, pos, 0);
}

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

void HiRes2Engine::checkTextOverflow(char c) {
if (c != APPLECHAR('\r'))
return;

++_linesPrinted;

if (_linesPrinted < 4)
return;

_linesPrinted = 0;
// Bell

while (true) {
char key = inputKey(false);

if (shouldQuit())
return;

if (key == APPLECHAR('\r'))
break;

// Bell
// Bell
// Bell
}
}

void HiRes2Engine::printString(const Common::String &str) {
Common::String s(str);
byte endPos = TEXT_WIDTH - 1;
byte pos = 0;

while (true) {
while (pos != endPos && pos != s.size()) {
s.setChar(APPLECHAR(s[pos]), pos);
++pos;
}

if (pos == s.size())
break;

while (s[pos] != APPLECHAR(' ') && s[pos] != APPLECHAR('\r'))
--pos;

s.setChar(APPLECHAR('\r'), pos);
endPos = pos + TEXT_WIDTH;
++pos;
}

pos = 0;
while (pos != s.size()) {
checkTextOverflow(s[pos]);
_display->printChar(s[pos]);
++pos;
}

checkTextOverflow(APPLECHAR('\r'));
_display->printChar(APPLECHAR('\r'));
_display->updateTextScreen();
}

Engine *HiRes2Engine_create(OSystem *syst, const AdlGameDescription *gd) {
Expand Down
22 changes: 20 additions & 2 deletions engines/adl/hires2.h
Expand Up @@ -63,9 +63,20 @@ namespace Adl {
#define IDI_HR2_OFS_STR_PLAY_AGAIN TSO(0x1a, 0x8, 0x25)
#define IDI_HR2_OFS_STR_PRESS_RETURN TSO(0x1a, 0x8, 0x5f)

struct Picture2 {
byte track;
byte sector;
byte offset;
};

struct RoomData {
Common::String description;
Common::Array<Picture2> pictures;
};

class HiRes2Engine : public AdlEngine {
public:
HiRes2Engine(OSystem *syst, const AdlGameDescription *gd) : AdlEngine(syst, gd) { }
HiRes2Engine(OSystem *syst, const AdlGameDescription *gd) : AdlEngine(syst, gd), _linesPrinted(0) { }

private:
// AdlEngine
Expand All @@ -75,7 +86,14 @@ class HiRes2Engine : public AdlEngine {
void restartGame();
void drawPic(byte pic, Common::Point pos) const;
void drawItem(const Item &item, const Common::Point &pos) const { }
void showRoom() const;
void showRoom();

void loadRoom(uint i);
void checkTextOverflow(char c);
void printString(const Common::String &str);

RoomData _roomData;
uint _linesPrinted;
};

} // End of namespace Adl
Expand Down

0 comments on commit b4aea80

Please sign in to comment.