-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathop_v6.c
345 lines (251 loc) · 7.21 KB
/
op_v6.c
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
334
335
336
337
338
339
340
341
342
343
344
/* Nitfol - z-machine interpreter using Glk for output.
Copyright (C) 1999 Evin Robertson
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., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
The author can be reached at [email protected]
*/
#include "nitfol.h"
typedef enum { z6_text, z6_picture, z6_rectangle } z6_type;
struct graph_piece {
struct graph_piece *next;
struct graph_piece *prev;
int window;
zword x, y;
zword width, height;
z6_type type;
char *text;
zword picnum;
int color; /* -1 means erase to background color */
};
static struct graph_piece *older_pieces;
static zwinid lower_win;
static zword window_props[8][16];
static int current_window;
typedef enum { w_y_coord, w_x_coord, w_y_size, w_x_size,
w_y_cursor, w_x_cursor, w_l_margin, w_r_margin,
w_nl_routine, w_int_count, w_text_style, w_colour_data,
w_font_number, w_font_size, w_attributes, w_line_count
} win_prop_names;
typedef enum { wa_wrapping, wa_scrolling, wa_transcript, wa_buffered } win_attributes;
static int get_window_num(int arg)
{
if(numoperands <= arg || operand[arg] == neg(3))
return current_window;
if(operand[arg] > 7) {
n_show_error(E_OUTPUT, "illegal window number", operand[arg]);
return current_window;
}
return operand[arg];
}
static BOOL check_window_prop(int prop_num)
{
if(prop_num > 15) {
n_show_error(E_OUTPUT, "illegal wind_prop number", prop_num);
return FALSE;
}
return TRUE;
}
int is_in_bounds(glui32 x1, glui32 y1, glui32 width1, glui32 height1,
glui32 x2, glui32 y2, glui32 width2, glui32 height2)
{
return (x1 >= x2 && y1 >= y2 &&
x1 + width1 <= x2 + width2 && y1 + height1 <= y2 + height2);
}
static void add_piece(struct graph_piece new_piece)
{
struct graph_piece *p, *q;
return;
if(new_piece.x + new_piece.width >
window_props[current_window][w_x_coord] +
window_props[current_window][w_x_size]) {
new_piece.width = window_props[current_window][w_x_coord] +
window_props[current_window][w_x_size] -
new_piece.x;
}
if(new_piece.y + new_piece.height >
window_props[current_window][w_y_coord] +
window_props[current_window][w_y_size]) {
new_piece.height = window_props[current_window][w_y_coord] +
window_props[current_window][w_y_size] -
new_piece.y;
}
q = NULL;
p = older_pieces;
while(p) {
if(is_in_bounds(p->x, p->y, p->width, p->height,
new_piece.x, new_piece.y,
new_piece.width, new_piece.height)) {
if(q) {
q->next = p->next;
n_free(p);
p = q->next;
} else {
LEremove(older_pieces);
p = older_pieces;
}
} else {
p = p-> next;
}
q = p;
}
LEadd(older_pieces, new_piece);
}
void v6_main_window_is(zwinid win)
{
lower_win = win;
}
void op_set_window6(void)
{
int win = get_window_num(0);
current_window = win;
}
void op_set_margins(void)
{
int win = get_window_num(2);
#ifdef DEBUG_IO
n_show_debug(E_OUTPUT, "set_margins w=", operand[2]);
n_show_debug(E_OUTPUT, "set_margins l=", operand[0]);
n_show_debug(E_OUTPUT, "set_margins r=", operand[1]);
#endif
window_props[win][w_l_margin] = operand[0];
window_props[win][w_r_margin] = operand[1];
/* FIXME: move cursor */
}
void op_move_window(void)
{
int win = get_window_num(0);
#ifdef DEBUG_IO
n_show_debug(E_OUTPUT, "move_window w=", operand[0]);
n_show_debug(E_OUTPUT, "move_window y=", operand[1]);
n_show_debug(E_OUTPUT, "move_window x=", operand[2]);
#endif
window_props[win][w_y_coord] = operand[1];
window_props[win][w_x_coord] = operand[2];
}
void op_window_size(void)
{
int win = get_window_num(0);
#ifdef DEBUG_IO
n_show_debug(E_OUTPUT, "window_size w=", operand[0]);
n_show_debug(E_OUTPUT, "window_size y=", operand[1]);
n_show_debug(E_OUTPUT, "window_size x=", operand[2]);
#endif
window_props[win][w_y_size] = operand[1];
window_props[win][w_x_size] = operand[2];
}
void op_window_style(void)
{
zword attr;
int win = get_window_num(0);
if(numoperands < 3)
operand[2] = 0;
attr = window_props[win][w_attributes];
switch(operand[2]) {
case 0: attr = operand[1]; break;
case 1: attr |= operand[1]; break;
case 2: attr &= ~(operand[1]); break;
case 3: attr ^= operand[1]; break;
default: n_show_error(E_OUTPUT, "invalid flag operation", operand[2]);
}
window_props[win][w_attributes] = attr;
}
void op_get_wind_prop(void)
{
int win = get_window_num(0);
if(!check_window_prop(operand[1])) {
mop_store_result(0);
return;
}
mop_store_result(window_props[win][operand[1]]);
}
void op_put_wind_prop(void)
{
int win = get_window_num(0);
if(!check_window_prop(operand[1])) {
mop_store_result(0);
return;
}
window_props[win][operand[1]] = operand[2];
}
void op_scroll_window(void)
{
;
}
void op_read_mouse(void)
{
;
}
void op_mouse_window(void)
{
;
}
void op_print_form(void)
{
;
}
void op_make_menu(void)
{
mop_skip_branch();
}
void op_picture_table(void)
{
; /* Glk contains no image prefetching facilities, so nothing to do here */
}
void op_draw_picture(void)
{
struct graph_piece new_piece;
glui32 width, height;
z_put_char(lower_win, 13); /* Work around a bug in xglk */
draw_intext_picture(lower_win, operand[0], imagealign_MarginLeft);
/*
new_piece.window = current_window;
new_piece.x = operand[2] + window_props[current_window][w_x_coord];
new_piece.y = operand[1] + window_props[current_window][w_y_coord];
wrap_glk_image_get_info(operand[0], &width, &height);
new_piece.width = width;
new_piece.height = height;
new_piece.type = z6_picture;
new_piece.picnum = operand[0];
add_piece(new_piece);
*/
}
void op_picture_data(void)
{
if(glk_gestalt(gestalt_Graphics, 0)) {
glui32 width, height;
if(operand[0] == 0) {
LOWORDwrite(operand[1], imagecount);
LOWORDwrite(operand[1], 42); /* FIXME: where do I get picture release? */
}
else if(wrap_glk_image_get_info(operand[0], &width, &height)) {
LOWORDwrite(operand[1], height);
LOWORDwrite(operand[1] + ZWORD_SIZE, width);
mop_take_branch();
return;
}
}
mop_skip_branch();
}
void op_erase_picture(void)
{
struct graph_piece new_piece;
glui32 width, height;
new_piece.window = current_window;
new_piece.x = operand[2] + window_props[current_window][w_x_coord];
new_piece.y = operand[1] + window_props[current_window][w_y_coord];
wrap_glk_image_get_info(operand[0], &width, &height);
new_piece.width = width;
new_piece.height = height;
new_piece.type = z6_rectangle;
new_piece.color = -1;
add_piece(new_piece);
}