Skip to content

Commit

Permalink
ADL: Clean up Display class
Browse files Browse the repository at this point in the history
  • Loading branch information
waltervn committed Mar 9, 2016
1 parent ec14c39 commit e6d478a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 59 deletions.
10 changes: 3 additions & 7 deletions engines/adl/adl.cpp
Expand Up @@ -312,7 +312,7 @@ void AdlEngine::doActions(const Command &command, byte noun, byte offset) {
if (input.size() == 0 || input[0] != APPLECHAR('N')) {
_isRestarting = true;
_display->clear(0x00);
_display->decodeFrameBuffer();
_display->updateHiResScreen();
restartGame();
return;
}
Expand Down Expand Up @@ -515,9 +515,9 @@ void AdlEngine::showRoom() {
if (!_state.isDark) {
drawPic(curRoom().curPicture);
drawItems();
_display->updateHiResScreen();
}

_display->decodeFrameBuffer();
printMessage(curRoom().description, false);
}

Expand Down Expand Up @@ -913,9 +913,7 @@ byte AdlEngine::inputKey() {
};
}

_display->updateTextSurface();
_display->updateScreen();
g_system->updateScreen();
_display->updateTextScreen();
g_system->delayMillis(16);
}

Expand All @@ -942,8 +940,6 @@ void AdlEngine::delay(uint32 ms) {
}
}
}
_display->updateScreen();
g_system->updateScreen();
g_system->delayMillis(16);
}
}
Expand Down
114 changes: 68 additions & 46 deletions engines/adl/display.cpp
Expand Up @@ -36,10 +36,12 @@

namespace Adl {

// TODO: Implement partial screen updates

#define DISPLAY_PITCH (DISPLAY_WIDTH / 7)

#define COLOR_PALETTE_SIZE 6
const byte colorPalette[COLOR_PALETTE_SIZE * 3] = {
#define COLOR_PALETTE_ENTRIES 6
const byte colorPalette[COLOR_PALETTE_ENTRIES * 3] = {
0x00, 0x00, 0x00,
0xff, 0xff, 0xff,
0xc7, 0x34, 0xff,
Expand All @@ -48,8 +50,8 @@ const byte colorPalette[COLOR_PALETTE_SIZE * 3] = {
0xf2, 0x5e, 0x00
};

#define MONO_PALETTE_SIZE 2
const byte monoPalette[MONO_PALETTE_SIZE * 3] = {
#define MONO_PALETTE_ENTRIES 2
const byte monoPalette[MONO_PALETTE_ENTRIES * 3] = {
0x00, 0x00, 0x00,
0x00, 0xc0, 0x01
};
Expand Down Expand Up @@ -100,9 +102,9 @@ Display::Display() :
_scanlines = ConfMan.getBool("scanlines");

if (_monochrome)
g_system->getPaletteManager()->setPalette(monoPalette, 0, MONO_PALETTE_SIZE);
g_system->getPaletteManager()->setPalette(monoPalette, 0, MONO_PALETTE_ENTRIES);
else
g_system->getPaletteManager()->setPalette(colorPalette, 0, COLOR_PALETTE_SIZE);
g_system->getPaletteManager()->setPalette(colorPalette, 0, COLOR_PALETTE_ENTRIES);

enableScanlines(_scanlines);

Expand Down Expand Up @@ -134,15 +136,35 @@ Display::~Display() {
delete _font;
}

void Display::updateScreen() {
if (_mode == DISPLAY_MODE_TEXT) {
void Display::setMode(DisplayMode mode) {
_mode = mode;

if (_mode == DISPLAY_MODE_TEXT || _mode == DISPLAY_MODE_MIXED)
updateTextScreen();
if (_mode == DISPLAY_MODE_HIRES || _mode == DISPLAY_MODE_MIXED)
updateHiResScreen();
}

void Display::updateTextScreen() {
updateTextSurface();

if (_mode == DISPLAY_MODE_TEXT)
g_system->copyRectToScreen(_textBufSurface->getPixels(), _textBufSurface->pitch, 0, 0, _textBufSurface->w, _textBufSurface->h);
} else if (_mode == DISPLAY_MODE_HIRES) {
else if (_mode == DISPLAY_MODE_MIXED)
g_system->copyRectToScreen(_textBufSurface->getBasePtr(0, _textBufSurface->h - 4 * 8 * 2), _textBufSurface->pitch, 0, _textBufSurface->h - 4 * 8 * 2, _textBufSurface->w, 4 * 8 * 2);

g_system->updateScreen();
}

void Display::updateHiResScreen() {
updateHiResSurface();

if (_mode == DISPLAY_MODE_HIRES)
g_system->copyRectToScreen(_frameBufSurface->getPixels(), _frameBufSurface->pitch, 0, 0, _frameBufSurface->w, _frameBufSurface->h);
} else {
else if (_mode == DISPLAY_MODE_MIXED)
g_system->copyRectToScreen(_frameBufSurface->getPixels(), _frameBufSurface->pitch, 0, 0, _frameBufSurface->w, _frameBufSurface->h - 4 * 8 * 2);
g_system->copyRectToScreen(_textBufSurface->getBasePtr(0, _textBufSurface->h - 4 * 8 * 2), _textBufSurface->pitch, 0, _textBufSurface->h - 4 * 8 * 2, _textBufSurface->w, 4 * 8 * 2);
}

g_system->updateScreen();
}

bool Display::saveThumbnail(Common::WriteStream &out) {
Expand Down Expand Up @@ -177,17 +199,6 @@ void Display::loadFrameBuffer(Common::ReadStream &stream) {
}
}

void Display::decodeFrameBuffer() {
byte *src = _frameBuf;
byte *dst = (byte *)_frameBufSurface->getPixels();

for (uint i = 0; i < DISPLAY_HEIGHT; ++i) {
decodeScanline(dst, _frameBufSurface->pitch, src);
src += DISPLAY_PITCH;
dst += _frameBufSurface->pitch * 2;
}
}

void Display::putPixel(Common::Point p, byte color) {
byte offset = p.x / 7;

Expand Down Expand Up @@ -216,27 +227,6 @@ void Display::clear(byte color) {
}
}

void Display::updateTextSurface() {
for (uint row = 0; row < 24; ++row)
for (uint col = 0; col < 40; ++col) {
int charPos = row * 40 + col;
char c = _textBuf[row * 40 + col];

if (charPos == _cursorPos && _showCursor)
c = (c & 0x3f) | 0x40;

Common::Rect r(7 * 2, 8 * 2);
r.translate(((c & 0x3f) % 16) * 7 * 2, (c & 0x3f) / 16 * 8 * 2);

if (!(c & 0x80)) {
if (!(c & 0x40) || ((g_system->getMillis() / 270) & 1))
r.translate(0, 4 * 8 * 2);
}

_textBufSurface->copyRectToSurface(*_font, col * 7 * 2, row * 8 * 2, r);
}
}

void Display::home() {
memset(_textBuf, APPLECHAR(' '), kTextBufSize);
_cursorPos = 0;
Expand Down Expand Up @@ -279,7 +269,7 @@ void Display::printString(const Common::String &str) {
scrollUp();
}

updateTextSurface();
updateTextScreen();
}

void Display::setCharAtCursor(byte c) {
Expand All @@ -291,7 +281,7 @@ void Display::showCursor(bool enable) {
}

void Display::enableScanlines(bool enable) {
byte pal[6 * 3] = { };
byte pal[COLOR_PALETTE_ENTRIES * 3] = { };

if (enable)
g_system->getPaletteManager()->setPalette(pal, 6, 6);
Expand All @@ -301,6 +291,17 @@ void Display::enableScanlines(bool enable) {
}
}

void Display::updateHiResSurface() {
byte *src = _frameBuf;
byte *dst = (byte *)_frameBufSurface->getPixels();

for (uint i = 0; i < DISPLAY_HEIGHT; ++i) {
decodeScanline(dst, _frameBufSurface->pitch, src);
src += DISPLAY_PITCH;
dst += _frameBufSurface->pitch * 2;
}
}

void Display::decodeScanlineColor(byte *dst, int pitch, byte *src) const {
// TODO: shift secondPal by half a pixel

Expand Down Expand Up @@ -370,6 +371,27 @@ void Display::decodeScanline(byte *dst, int pitch, byte *src) const {
decodeScanlineColor(dst, pitch, src);
}

void Display::updateTextSurface() {
for (uint row = 0; row < 24; ++row)
for (uint col = 0; col < 40; ++col) {
int charPos = row * 40 + col;
char c = _textBuf[row * 40 + col];

if (charPos == _cursorPos && _showCursor)
c = (c & 0x3f) | 0x40;

Common::Rect r(7 * 2, 8 * 2);
r.translate(((c & 0x3f) % 16) * 7 * 2, (c & 0x3f) / 16 * 8 * 2);

if (!(c & 0x80)) {
if (!(c & 0x40) || ((g_system->getMillis() / 270) & 1))
r.translate(0, 4 * 8 * 2);
}

_textBufSurface->copyRectToSurface(*_font, col * 7 * 2, row * 8 * 2, r);
}
}

void Display::drawChar(byte c, int x, int y) {
byte *buf = (byte *)_font->getPixels() + y * _font->pitch + x;

Expand Down
9 changes: 5 additions & 4 deletions engines/adl/display.h
Expand Up @@ -54,18 +54,17 @@ class Display {
Display();
~Display();

void setMode(DisplayMode mode) { _mode = mode; }
void updateScreen();
void setMode(DisplayMode mode);
void updateTextScreen();
void updateHiResScreen();
bool saveThumbnail(Common::WriteStream &out);

// Graphics
void loadFrameBuffer(Common::ReadStream &stream);
void decodeFrameBuffer();
void putPixel(Common::Point p1, byte color);
void clear(byte color);

// Text
void updateTextSurface();
void home();
void moveCursorTo(const Common::Point &pos);
void moveCursorForward();
Expand All @@ -79,11 +78,13 @@ class Display {
kTextBufSize = 40 * 24
};

void updateHiResSurface();
void enableScanlines(bool enable);
void decodeScanlineColor(byte *dst, int pitch, byte *src) const;
void decodeScanlineMono(byte *dst, int pitch, byte *src) const;
void decodeScanline(byte *dst, int pitch, byte *src) const;

void updateTextSurface();
void drawChar(byte c, int x, int y);
void createFont();
void scrollUp();
Expand Down
4 changes: 2 additions & 2 deletions engines/adl/hires1.cpp
Expand Up @@ -96,7 +96,7 @@ void HiRes1Engine::runIntro() {
file.seek(IDI_HR1_OFS_LOGO_0);
_display->setMode(DISPLAY_MODE_HIRES);
_display->loadFrameBuffer(file);
_display->decodeFrameBuffer();
_display->updateHiResScreen();
delay(4000);

if (shouldQuit())
Expand Down Expand Up @@ -186,7 +186,7 @@ void HiRes1Engine::runIntro() {
// Title screen shown during loading
file.seek(0x1800);
_display->loadFrameBuffer(file);
_display->decodeFrameBuffer();
_display->updateHiResScreen();
delay(2000);
}

Expand Down

0 comments on commit e6d478a

Please sign in to comment.