1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/* 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 "common/scummsys.h"
#include "common/system.h"
#include "common/config-manager.h"
#include "common/debug.h"
#include "common/debug-channels.h"
#include "common/file.h"
#include "common/error.h"
#include "graphics/surface.h"
#include "graphics/palette.h"
#include "hdb.h"
#include "console.h"
namespace HDB {
HDBGame::HDBGame(OSystem *syst, const ADGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
_console = nullptr;
DebugMan.addDebugChannel(kDebugExample1, "Example1", "This is just an example to test");
DebugMan.addDebugChannel(kDebugExample2, "Example2", "This is also an example");
}
HDBGame::~HDBGame() {
delete _console;
DebugMan.clearAllDebugChannels();
}
Common::Error HDBGame::run() {
// Initializes Graphics
Graphics::PixelFormat format = g_system->getScreenFormat();
initGraphics(800, 600, &format);
_console = new Console();
readMPC("hyperdemo.mpc");
while (!shouldQuit()) {
Common::Event event;
while (g_system->getEventManager()->pollEvent(event)) {
switch (event.type) {
case Common::EVENT_QUIT:
case Common::EVENT_RTL:
break;
case Common::EVENT_KEYDOWN:
debug("Key was pressed.");
break;
default:
break;
}
}
Graphics::Surface screen;
screen.create(800, 600, g_system->getScreenFormat());
screen.drawLine(100, 100, 200, 200, 0xffffffff);
g_system->copyRectToScreen(screen.getBasePtr(0, 0), screen.pitch, 0, 0, 800, 600);
g_system->updateScreen();
g_system->delayMillis(10);
}
return Common::kNoError;
}
void HDBGame::readMPC(const Common::String &filename) {
if (!_file.open(filename)) {
error("readMPC(): Error reading MPC file");
} else {
_dataHeader.signature[0] = _file.readByte();
_dataHeader.signature[1] = _file.readByte();
_dataHeader.signature[2] = _file.readByte();
_dataHeader.signature[3] = _file.readByte();
_dataHeader.signature[4] = '\0';
if (_dataHeader.isValid()) {
_dataHeader.dirOffset = _file.readUint32LE();
// FIXME: The MPC archive format considers dirOffset to be a uint32.
// However, File::seekg() takes an int32 as the offset, hence this
// would break if the dirOffset was larger than 2^31.
_file.seek((int32)_dataHeader.dirOffset, SEEK_SET);
_dataHeader.dirSize = _file.readUint32LE();
for (uint32 fileIndex = 0; fileIndex < _dataHeader.dirSize; fileIndex++) {
DataFile* dirEntry = new DataFile();
for (int fileNameIndex = 0; fileNameIndex < 64; fileNameIndex++) {
dirEntry->fileName[fileNameIndex] = _file.readByte();
}
dirEntry->fileName[64] = '\0';
dirEntry->filePosition = _file.readUint32LE();
dirEntry->fileLength = _file.readUint32LE();
dirEntry->unknownField1 = _file.readUint32LE();
dirEntry->unknownField2 = _file.readUint32LE();
_gameData.push_back(dirEntry);
}
} else {
debug("Invalid MPC file");
}
}
}
} // End of namespace HDB
|