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
|
/* 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();
Window &win = _wp[cwin];
if (!x || !y) {
// use cursor column if x-coordinate is 0
if (!x)
x = win[X_CURSOR];
// use cursor line if y-coordinate is 0
if (!y)
y = win[Y_CURSOR];
}
y += win[Y_POS] - 1;
x += win[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) {
uint height1, width1;
uint 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, Point(x + delta, y + height1));
os_draw_picture(mapper[i].pic2, Point(x + width1 - width2 - delta, y + height1));
}
}
os_draw_picture(pic, Point(x, y));
if (_storyId == SHOGUN && pic == 3) {
uint height, width;
os_picture_data(59, &height, &width);
os_draw_picture(59, Point(h_screen_width - width + 1, y));
}
}
void Processor::z_picture_data() {
zword pic = zargs[0];
zword table = zargs[1];
uint 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) {
uint 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) {
flush_buffer();
zword win = winarg0();
_wp[win].setPosition(Point(zargs[2], zargs[1]));
}
void Processor::z_window_size() {
flush_buffer();
zword win = winarg0();
_wp[win].setSize(Point(zargs[2], zargs[1]));
}
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() {
flush_buffer();
zword win = winarg0();
zword prop = zargs[1];
if (prop <= TRUE_BG_COLOR)
store(_wp[win][(WindowProperty)prop]);
else
runtimeError(ERR_ILL_WIN_PROP);
}
void Processor::z_put_wind_prop() {
flush_buffer();
zword win = winarg0();
WindowProperty prop = (WindowProperty)zargs[1];
zword val = zargs[2];
if (prop >= TRUE_FG_COLOR)
runtimeError(ERR_ILL_WIN_PROP);
_wp[win][prop] = val;
}
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 Frotz
} // End of namespace Glk
|