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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
/* 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.
*
* $URL$
* $Id$
*
*/
#include "kyra/kyra_lok.h"
#include "kyra/screen_lok.h"
namespace Kyra {
#define BITBLIT_RECTS 10
Screen_LoK::Screen_LoK(KyraEngine_LoK *vm, OSystem *system)
: Screen(vm, system) {
_vm = vm;
}
Screen_LoK::~Screen_LoK() {
delete[] _bitBlitRects;
for (int i = 0; i < ARRAYSIZE(_saveLoadPage); ++i) {
delete[] _saveLoadPage[i];
_saveLoadPage[i] = 0;
}
for (int i = 0; i < ARRAYSIZE(_saveLoadPageOvl); ++i) {
delete[] _saveLoadPageOvl[i];
_saveLoadPageOvl[i] = 0;
}
delete[] _unkPtr1;
delete[] _unkPtr2;
}
bool Screen_LoK::init() {
if (!Screen::init())
return false;
_bitBlitRects = new Rect[BITBLIT_RECTS];
assert(_bitBlitRects);
memset(_bitBlitRects, 0, sizeof(Rect)*BITBLIT_RECTS);
_bitBlitNum = 0;
memset(_saveLoadPage, 0, sizeof(_saveLoadPage));
memset(_saveLoadPageOvl, 0, sizeof(_saveLoadPageOvl));
_unkPtr1 = new uint8[getRectSize(1, 144)];
assert(_unkPtr1);
memset(_unkPtr1, 0, getRectSize(1, 144));
_unkPtr2 = new uint8[getRectSize(1, 144)];
assert(_unkPtr2);
memset(_unkPtr2, 0, getRectSize(1, 144));
return true;
}
void Screen_LoK::setScreenDim(int dim) {
debugC(9, kDebugLevelScreen, "Screen_LoK::setScreenDim(%d)", dim);
assert(dim < _screenDimTableCount);
_curDim = &_screenDimTable[dim];
}
const ScreenDim *Screen_LoK::getScreenDim(int dim) {
debugC(9, kDebugLevelScreen, "Screen_LoK::getScreenDim(%d)", dim);
assert(dim < _screenDimTableCount);
return &_screenDimTable[dim];
}
void Screen_LoK::fadeSpecialPalette(int palIndex, int startIndex, int size, int fadeTime) {
debugC(9, kDebugLevelScreen, "Screen_LoK::fadeSpecialPalette(%d, %d, %d, %d)", palIndex, startIndex, size, fadeTime);
assert(_vm->palTable1()[palIndex]);
assert(_currentPalette);
uint8 tempPal[768];
memcpy(tempPal, _currentPalette, 768);
memcpy(&tempPal[startIndex*3], _vm->palTable1()[palIndex], size*3);
fadePalette(tempPal, fadeTime*18);
memcpy(&_currentPalette[startIndex*3], &tempPal[startIndex*3], size*3);
setScreenPalette(_currentPalette);
_system->updateScreen();
}
void Screen_LoK::addBitBlitRect(int x, int y, int w, int h) {
debugC(9, kDebugLevelScreen, "Screen_LoK::addBitBlitRects(%d, %d, %d, %d)", x, y, w, h);
if (_bitBlitNum >= BITBLIT_RECTS)
error("too many bit blit rects");
_bitBlitRects[_bitBlitNum].x = x;
_bitBlitRects[_bitBlitNum].y = y;
_bitBlitRects[_bitBlitNum].x2 = w;
_bitBlitRects[_bitBlitNum].y2 = h;
++_bitBlitNum;
}
void Screen_LoK::bitBlitRects() {
debugC(9, kDebugLevelScreen, "Screen_LoK::bitBlitRects()");
Rect *cur = _bitBlitRects;
while (_bitBlitNum) {
_bitBlitNum--;
copyRegion(cur->x, cur->y, cur->x, cur->y, cur->x2, cur->y2, 2, 0);
++cur;
}
}
void Screen_LoK::savePageToDisk(const char *file, int page) {
debugC(9, kDebugLevelScreen, "Screen_LoK::savePageToDisk('%s', %d)", file, page);
if (!_saveLoadPage[page/2]) {
_saveLoadPage[page/2] = new uint8[SCREEN_W * SCREEN_H];
assert(_saveLoadPage[page/2]);
}
memcpy(_saveLoadPage[page/2], getPagePtr(page), SCREEN_W * SCREEN_H);
if (_useOverlays) {
if (!_saveLoadPageOvl[page/2]) {
_saveLoadPageOvl[page/2] = new uint8[SCREEN_OVL_SJIS_SIZE];
assert(_saveLoadPageOvl[page/2]);
}
uint8 *srcPage = getOverlayPtr(page);
if (!srcPage) {
warning("trying to save unsupported overlay page %d", page);
return;
}
memcpy(_saveLoadPageOvl[page/2], srcPage, SCREEN_OVL_SJIS_SIZE);
}
}
void Screen_LoK::loadPageFromDisk(const char *file, int page) {
debugC(9, kDebugLevelScreen, "Screen_LoK::loadPageFromDisk('%s', %d)", file, page);
if (!_saveLoadPage[page/2]) {
warning("trying to restore page %d, but no backup found", page);
return;
}
copyBlockToPage(page, 0, 0, SCREEN_W, SCREEN_H, _saveLoadPage[page/2]);
delete[] _saveLoadPage[page/2];
_saveLoadPage[page/2] = 0;
if (_saveLoadPageOvl[page/2]) {
uint8 *dstPage = getOverlayPtr(page);
if (!dstPage) {
warning("trying to restore unsupported overlay page %d", page);
return;
}
memcpy(dstPage, _saveLoadPageOvl[page/2], SCREEN_OVL_SJIS_SIZE);
delete[] _saveLoadPageOvl[page/2];
_saveLoadPageOvl[page/2] = 0;
}
}
void Screen_LoK::queryPageFromDisk(const char *file, int page, uint8 *buffer) {
debugC(9, kDebugLevelScreen, "Screen_LoK::queryPageFromDisk('%s', %d, %p)", file, page, (const void *)buffer);
if (!_saveLoadPage[page/2]) {
warning("trying to query page %d, but no backup found", page);
return;
}
memcpy(buffer, _saveLoadPage[page/2], SCREEN_W*SCREEN_H);
}
void Screen_LoK::deletePageFromDisk(int page) {
debugC(9, kDebugLevelScreen, "Screen_LoK::deletePageFromDisk(%d)", page);
delete[] _saveLoadPage[page/2];
_saveLoadPage[page/2] = 0;
if (_saveLoadPageOvl[page/2]) {
delete[] _saveLoadPageOvl[page/2];
_saveLoadPageOvl[page/2] = 0;
}
}
void Screen_LoK::copyBackgroundBlock(int x, int page, int flag) {
debugC(9, kDebugLevelScreen, "Screen_LoK::copyBackgroundBlock(%d, %d, %d)", x, page, flag);
if (x < 1)
return;
int height = 128;
if (flag)
height += 8;
if (!(x & 1))
++x;
if (x == 19)
x = 17;
uint8 *ptr1 = _unkPtr1;
uint8 *ptr2 = _unkPtr2;
int oldVideoPage = _curPage;
_curPage = page;
int curX = x;
hideMouse();
copyRegionToBuffer(_curPage, 8, 8, 8, height, ptr2);
for (int i = 0; i < 19; ++i) {
int tempX = curX + 1;
copyRegionToBuffer(_curPage, tempX<<3, 8, 8, height, ptr1);
copyBlockToPage(_curPage, tempX<<3, 8, 8, height, ptr2);
int newXPos = curX + x;
if (newXPos > 37)
newXPos = newXPos % 38;
tempX = newXPos + 1;
copyRegionToBuffer(_curPage, tempX<<3, 8, 8, height, ptr2);
copyBlockToPage(_curPage, tempX<<3, 8, 8, height, ptr1);
curX += x*2;
if (curX > 37) {
curX = curX % 38;
}
}
showMouse();
_curPage = oldVideoPage;
}
void Screen_LoK::copyBackgroundBlock2(int x) {
debugC(9, kDebugLevelScreen, "Screen_LoK::copyBackgroundBlock2(%d)", x);
copyBackgroundBlock(x, 4, 1);
}
void Screen_LoK::setTextColorMap(const uint8 *cmap) {
debugC(9, kDebugLevelScreen, "Screen_LoK::setTextColorMap(%p)", (const void *)cmap);
setTextColor(cmap, 0, 11);
}
int Screen_LoK::getRectSize(int x, int y) {
if (x < 1)
x = 1;
else if (x > 40)
x = 40;
if (y < 1)
y = 1;
else if (y > 200)
y = 200;
return ((x*y) << 3);
}
} // end of namespace Kyra
|