Skip to content

Commit

Permalink
ACCESS: Implement decoding of game cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Aug 2, 2014
1 parent 4d24209 commit 857f944
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 15 deletions.
27 changes: 26 additions & 1 deletion engines/access/access.cpp
Expand Up @@ -33,11 +33,13 @@ AccessEngine::AccessEngine(OSystem *syst, const AccessGameDescription *gameDesc)
_gameDescription(gameDesc), Engine(syst), _randomSource("Access") {
_debugger = nullptr;
_events = nullptr;
_graphics = nullptr;
}

AccessEngine::~AccessEngine() {
delete _debugger;
delete _events;
delete _graphics;
}

void AccessEngine::initialize() {
Expand All @@ -48,19 +50,42 @@ void AccessEngine::initialize() {

_debugger = new Debugger(this);
_events = new EventsManager(this);
_graphics = new GraphicsManager(this);
}

Common::Error AccessEngine::run() {
initialize();

setVGA();
_graphics->setPalettte();
_graphics->setPanel(0);
_events->setCursor(CURSOR_0);
_events->showCursor();

dummyLoop();
return Common::kNoError;
}

void AccessEngine::dummyLoop() {
// Dummy game loop
while (!shouldQuit()) {
_events->pollEvents();
g_system->delayMillis(50);
g_system->updateScreen();

if (_events->_leftButton) {
CursorType cursorId = _events->getCursor();
_events->setCursor((cursorId == CURSOR_HELP) ? CURSOR_0 : (CursorType)(cursorId + 1));
}
}

}

int AccessEngine::getRandomNumber(int maxNumber) {
return _randomSource.getRandomNumber(maxNumber);
}

void AccessEngine::SETVGA() {
void AccessEngine::setVGA() {
initGraphics(320, 200, false);
}

Expand Down
20 changes: 11 additions & 9 deletions engines/access/access.h
Expand Up @@ -32,6 +32,7 @@
#include "graphics/surface.h"
#include "access/debugger.h"
#include "access/events.h"
#include "access/graphics.h"

/**
* This is the namespace of the Access engine.
Expand All @@ -58,27 +59,28 @@ struct AccessGameDescription;

class AccessEngine : public Engine {
private:
const AccessGameDescription *_gameDescription;
Common::RandomSource _randomSource;

Graphics::Surface _buffer1;
Graphics::Surface _buffer2;
Graphics::Surface _vidbuf;
Graphics::Surface _plotBuf;

/**
* Handles basic initialisation
*/
void initialize();

void SETVGA();
/**
* Set VGA mode
*/
void setVGA();

void dummyLoop();
protected:
const AccessGameDescription *_gameDescription;
Common::RandomSource _randomSource;

// Engine APIs
virtual Common::Error run();
virtual bool hasFeature(EngineFeature f) const;
public:
Debugger *_debugger;
EventsManager *_events;
GraphicsManager *_graphics;
public:
AccessEngine(OSystem *syst, const AccessGameDescription *gameDesc);
virtual ~AccessEngine();
Expand Down
54 changes: 51 additions & 3 deletions engines/access/events.cpp
Expand Up @@ -23,9 +23,14 @@
#include "common/scummsys.h"
#include "graphics/cursorman.h"
#include "common/events.h"
#include "common/endian.h"
#include "engines/util.h"
#include "access/access.h"
#include "access/events.h"
#include "access/resources.h"

#define CURSOR_WIDTH 16
#define CURSOR_HEIGHT 16

namespace Access {

Expand All @@ -40,7 +45,49 @@ EventsManager::~EventsManager() {
}

void EventsManager::setCursor(CursorType cursorId) {
if (cursorId == _cursorId)
return;
_cursorId = cursorId;

// Get a pointer to the mouse data to use, and get the cursor hotspot
const byte *srcP = Amazon::CURSORS[cursorId];
int hotspotX = (int16)READ_LE_UINT16(srcP);
int hotspotY = (int16)READ_LE_UINT16(srcP + 2);
srcP += 4;

// Create a surface to build up the cursor on
Graphics::Surface cursorSurface;
cursorSurface.create(16, 16, Graphics::PixelFormat::createFormatCLUT8());
byte *destP = (byte *)cursorSurface.getPixels();
Common::fill(destP, destP + CURSOR_WIDTH * CURSOR_HEIGHT, 0);

// Loop to build up the cursor
for (int y = 0; y < CURSOR_HEIGHT; ++y) {
destP = (byte *)cursorSurface.getBasePtr(0, y);
int width = CURSOR_WIDTH;
int skip = *srcP++;
int plot = *srcP++;
if (skip >= width)
break;

// Skip over pixels
destP += skip;
width -= skip;

// Write out the pixels to plot
while (plot > 0 && width > 0) {
*destP++ = *srcP++;
--plot;
--width;
}
}

// Set the cursor
CursorMan.replaceCursor(cursorSurface.getPixels(), CURSOR_WIDTH, CURSOR_HEIGHT,
hotspotX, hotspotY, 0);

// Free the cursor surface
cursorSurface.free();
}

void EventsManager::showCursor() {
Expand All @@ -58,6 +105,8 @@ bool EventsManager::isCursorVisible() {
void EventsManager::pollEvents() {
checkForNextFrameCounter();

_leftButton = false;

Common::Event event;
while (g_system->getEventManager()->pollEvent(event)) {
// Handle keypress
Expand All @@ -78,10 +127,9 @@ void EventsManager::pollEvents() {
return;
case Common::EVENT_LBUTTONDOWN:
_leftButton = true;
break;
return;
case Common::EVENT_LBUTTONUP:
_leftButton = false;
break;
return;
default:
break;
}
Expand Down
11 changes: 10 additions & 1 deletion engines/access/events.h
Expand Up @@ -29,7 +29,11 @@

namespace Access {

enum CursorType { CURSOR_NONE = 0 };
enum CursorType {
CURSOR_NONE = -1,
CURSOR_0 = 0, CURSOR_1, CURSOR_2, CURSOR_3, CURSOR_EYE, CURSOR_HAND,
CURSOR_GET, CURSOR_CLIMB, CURSOR_TALK, CURSOR_HELP
};

#define GAME_FRAME_RATE 50
#define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE)
Expand Down Expand Up @@ -63,6 +67,11 @@ class EventsManager {
*/
void setCursor(CursorType cursorId);

/**
* Return the current cursor Id
*/
CursorType getCursor() const { return _cursorId; }

/**
* Show the mouse cursor
*/
Expand Down
46 changes: 46 additions & 0 deletions engines/access/graphics.cpp
@@ -0,0 +1,46 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#include "graphics/palette.h"
#include "access/access.h"
#include "access/graphics.h"
#include "access/resources.h"

namespace Access {

GraphicsManager::GraphicsManager(AccessEngine *vm) : _vm(vm) {
_vesaCurrentWin = 0;
_currentPanel = 0;
_hideFlag = true;
}

void GraphicsManager::setPanel(int num) {
assert(num < 4);
_currentPanel = num;
_msVirtualOffset = _virtualOffsetsTable[num];
}

void GraphicsManager::setPalettte() {
g_system->getPaletteManager()->setPalette(INITIAL_PALETTE, 0, 18);
}

} // End of namespace Access
51 changes: 51 additions & 0 deletions engines/access/graphics.h
@@ -0,0 +1,51 @@
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/

#ifndef ACCESS_GRAPHICS_H
#define ACCESS_GRAPHICS_H

#include "common/rect.h"
#include "graphics/surface.h"

namespace Access {

class AccessEngine;

class GraphicsManager {
private:
AccessEngine *_vm;
public:
int _vesaCurrentWin;
int _currentPanel;
Common::Point _msVirtualOffset;
Common::Point _virtualOffsetsTable[4];
bool _hideFlag;
public:
GraphicsManager(AccessEngine *vm);

void setPanel(int num);
void setPalettte();
};

} // End of namespace Access

#endif /* ACCESS_GRAPHICS_H */
1 change: 1 addition & 0 deletions engines/access/module.mk
Expand Up @@ -5,6 +5,7 @@ MODULE_OBJS := \
debugger.o \
detection.o \
events.o \
graphics.o \
resources.o \
amazon\amazon_game.o

Expand Down
24 changes: 23 additions & 1 deletion engines/access/resources.cpp
Expand Up @@ -24,14 +24,36 @@

namespace Access {

const byte INITIAL_PALETTE[18 * 3] = {
0x00, 0x00, 0x00,
0xff, 0xff, 0xff,
0xf0, 0xf0, 0xf0,
0xe0, 0xe0, 0xe0,
0xd0, 0xd0, 0xd0,
0xc0, 0xc0, 0xc0,
0xb0, 0xb0, 0xb0,
0xa0, 0xa0, 0xa0,
0x90, 0x90, 0x90,
0x80, 0x80, 0x80,
0x70, 0x70, 0x70,
0x60, 0x60, 0x60,
0x50, 0x50, 0x50,
0x40, 0x40, 0x40,
0x30, 0x30, 0x30,
0x20, 0x20, 0x20,
0x10, 0x10, 0x10,
0x00, 0x00, 0x00
};

namespace Amazon {

const byte *CURSORS[10] = {
MOUSE0, MOUSE1, MOUSE2, MOUSE3, CURSEYE, CURSHAND, CURSGET, CURSCLIMB, CURSTALK, CURSHELP
};

const byte MOUSE0[] = {
0, 0, 0, 0, 0, 2, 6, 1, 0, 3, 6, 6, 1, 0, 3, 6, 6, 1,
0, 0, 0, 0,
0, 2, 6, 1, 0, 3, 6, 6, 1, 0, 3, 6, 6, 1,
0, 4, 6, 6, 6, 1, 0, 4, 6, 6, 6, 1, 0, 5, 6, 6, 6, 6,
1, 0, 5, 6, 6, 6, 6, 1, 0, 6, 6, 6, 6, 6, 6, 1, 0, 6,
6, 6, 6, 6, 6, 1, 0, 7, 6, 6, 6, 6, 6, 6, 1, 0, 6, 6,
Expand Down
2 changes: 2 additions & 0 deletions engines/access/resources.h
Expand Up @@ -27,6 +27,8 @@

namespace Access {

extern const byte INITIAL_PALETTE[18 * 3];

namespace Amazon {

extern const byte MOUSE0[];
Expand Down

0 comments on commit 857f944

Please sign in to comment.