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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/* 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 "glk/frotz/processor.h"
namespace Glk {
namespace Frotz {
static struct {
Story story_id;
int pic;
int pic1;
int pic2;
} mapper[] = {
{ ZORK_ZERO, 5, 497, 498 },
{ ZORK_ZERO, 6, 501, 502 },
{ ZORK_ZERO, 7, 499, 500 },
{ ZORK_ZERO, 8, 503, 504 },
{ ARTHUR, 54, 170, 171 },
{ SHOGUN, 50, 61, 62 },
{ UNKNOWN, 0, 0, 0 }
};
void Processor::z_draw_picture() {
zword pic = zargs[0];
zword y = zargs[1];
zword x = zargs[2];
int i;
flush_buffer ();
if (!x || !y) {
// Currently I only support getting the cursor for the text grid area
assert(cwin == 1);
Point cursPos = gos_upper->getCursor();
// use cursor column if x-coordinate is 0
if (!x)
x = cursPos.x;
// use cursor line if y-coordinate is 0
if (!y)
y = cursPos.y;
}
// y += cwp->y_pos - 1;
// x += cwp->x_pos - 1;
/* The following is necessary to make Amiga and Macintosh story
* files work with MCGA graphics files. Some screen-filling
* pictures of the original Amiga release like the borders of
* Zork Zero were split into several MCGA pictures (left, right
* and top borders). We pretend this has not happened.
*/
for (i = 0; mapper[i].story_id != UNKNOWN; i++) {
if (_storyId == mapper[i].story_id && pic == mapper[i].pic) {
glui32 height1, width1;
glui32 height2, width2;
int delta = 0;
os_picture_data(pic, &height1, &width1);
os_picture_data(mapper[i].pic2, &height2, &width2);
if (_storyId == ARTHUR && pic == 54)
delta = h_screen_width / 160;
os_draw_picture(mapper[i].pic1, gos_lower, Point(x + delta, y + height1));
os_draw_picture(mapper[i].pic2, gos_lower, Point(x + width1 - width2 - delta, y + height1));
}
}
os_draw_picture(pic, gos_lower, Point(x, y));
if (_storyId == SHOGUN && pic == 3) {
glui32 height, width;
os_picture_data(59, &height, &width);
os_draw_picture(59, gos_lower, Point(h_screen_width - width + 1, y));
}
}
void Processor::z_picture_data() {
zword pic = zargs[0];
zword table = zargs[1];
glui32 height, width;
int i;
bool avail = os_picture_data(pic, &height, &width);
for (i = 0; mapper[i].story_id != UNKNOWN; i++) {
if (_storyId == mapper[i].story_id) {
if (pic == mapper[i].pic) {
glui32 height2, width2;
avail &= os_picture_data(mapper[i].pic1, &height2, &width2);
avail &= os_picture_data(mapper[i].pic2, &height2, &width2);
height += height2;
} else if (pic == mapper[i].pic1 || pic == mapper[i].pic2) {
avail = false;
}
}
}
storew((zword)(table + 0), (zword)(height));
storew((zword)(table + 2), (zword)(width));
branch(avail);
}
void Processor::z_erase_picture() {
#ifdef TODO
int height, width;
zword y = zargs[1];
zword x = zargs[2];
flush_buffer();
/* Do nothing if the background is transparent */
if (hi(cwp->colour) == TRANSPARENT_COLOUR)
return;
if (y == 0) /* use cursor line if y-coordinate is 0 */
y = cwp->y_cursor;
if (x == 0) /* use cursor column if x-coordinate is 0 */
x = cwp->x_cursor;
os_picture_data(zargs[0], &height, &width);
y += cwp->y_pos - 1;
x += cwp->x_pos - 1;
os_erase_area(y, x, y + height - 1, x + width - 1, -1);
#endif
}
void Processor::z_set_margins() {
#ifdef TODO
zword win = winarg2();
flush_buffer();
wp[win].left = zargs[0];
wp[win].right = zargs[1];
/* Protect the margins */
if (wp[win].x_cursor <= zargs[0] || wp[win].x_cursor > wp[win].x_size - zargs[1]) {
wp[win].x_cursor = zargs[0] + 1;
if (win == cwin)
update_cursor();
}
#endif
}
void Processor::z_move_window(void) {
#ifdef TODO
zword win = winarg0();
flush_buffer();
wp[win].y_pos = zargs[1];
wp[win].x_pos = zargs[2];
if (win == cwin)
update_cursor();
#endif
}
void Processor::z_window_size() {
#ifdef TODO
zword win = winarg0();
flush_buffer();
wp[win].y_size = zargs[1];
wp[win].x_size = zargs[2];
/* Keep the cursor within the window */
if (wp[win].y_cursor > zargs[1] || wp[win].x_cursor > zargs[2])
reset_cursor(win);
os_window_height(win, wp[win].y_size);
#endif
}
void Processor::z_window_style() {
#ifdef TODO
zword win = winarg0();
zword flags = zargs[1];
flush_buffer();
/* Supply default arguments */
if (zargc < 3)
zargs[2] = 0;
/* Set window style */
switch (zargs[2]) {
case 0: wp[win].attribute = flags; break;
case 1: wp[win].attribute |= flags; break;
case 2: wp[win].attribute &= ~flags; break;
case 3: wp[win].attribute ^= flags; break;
}
if (cwin == win)
update_attributes();
#endif
}
void Processor::z_get_wind_prop() {
#ifdef TODO
flush_buffer();
if (zargs[1] < 16)
store(((zword *)(wp + winarg0()))[zargs[1]]);
else if (zargs[1] == 16)
store(os_to_true_colour(lo(wp[winarg0()].colour)));
else if (zargs[1] == 17) {
zword bg = hi(wp[winarg0()].colour);
if (bg == TRANSPARENT_COLOUR)
store((zword)-4);
else
store(os_to_true_colour(bg));
}
else
runtimeError(ERR_ILL_WIN_PROP);
#endif
}
void Processor::z_put_wind_prop() {
#ifdef TODO
flush_buffer();
if (zargs[1] >= 16)
runtimeError(ERR_ILL_WIN_PROP);
((zword *)(wp + winarg0()))[zargs[1]] = zargs[2];
#endif
}
void Processor::z_scroll_window() {
#ifdef TODO
zword win = winarg0();
zword y, x;
flush_buffer();
/* Use the correct set of colours when scrolling the window */
if (win != cwin && !amiga_screen_model())
os_set_colour(lo(wp[win].colour), hi(wp[win].colour));
y = wp[win].y_pos;
x = wp[win].x_pos;
os_scroll_area(y,
x,
y + wp[win].y_size - 1,
x + wp[win].x_size - 1,
(short)zargs[1]);
if (win != cwin && !amiga_screen_model())
os_set_colour(lo(cwp->colour), hi(cwp->colour));
#endif
}
void Processor::z_mouse_window() {
// No implementation - since ScummVM can run as a window, it's better
// not to constrain the area the mouse can move
}
void Processor::z_picture_table() {
/* This opcode is used by Shogun and Zork Zero when the player
* encounters built-in games such as Peggleboz. Nowadays it is
* not very helpful to hold the picture data in memory because
* even a small disk cache avoids re-loading of data.
*/
}
zword Processor::winarg0() {
if (h_version == V6 && (short)zargs[0] == -3)
return cwin;
if (zargs[0] >= ((h_version == V6) ? 8 : 2))
runtimeError(ERR_ILL_WIN);
return zargs[0];
}
zword Processor::winarg2() {
if (zargc < 3 || (short)zargs[2] == -3)
return cwin;
if (zargs[2] >= 8)
runtimeError(ERR_ILL_WIN);
return zargs[2];
}
} // End of namespace Scott
} // End of namespace Glk
|