diff options
author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-05-01 13:48:28 +0000 |
---|---|---|
committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-05-01 13:48:28 +0000 |
commit | f7c45941344ecfbcdd5d9b311b61573d37c6ef58 (patch) | |
tree | 4c2fa595d7209694dd30b0e0b349a0a44116d712 /apps/plugins/frotz/fastmem.c | |
parent | 08fb3f65745a237e2c1eae55d856ff27702246e5 (diff) | |
download | rockbox-f7c45941344ecfbcdd5d9b311b61573d37c6ef58.tar.gz rockbox-f7c45941344ecfbcdd5d9b311b61573d37c6ef58.zip |
Fix further 'variable set but not used' warnings reported from GCC 4.6.0.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29809 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/frotz/fastmem.c')
-rw-r--r-- | apps/plugins/frotz/fastmem.c | 618 |
1 files changed, 308 insertions, 310 deletions
diff --git a/apps/plugins/frotz/fastmem.c b/apps/plugins/frotz/fastmem.c index ce424af1f2..39ad5510ed 100644 --- a/apps/plugins/frotz/fastmem.c +++ b/apps/plugins/frotz/fastmem.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* fastmem.c - Memory related functions (fast version without virtual memory) | 1 | /* fastmem.c - Memory related functions (fast version without virtual memory) |
2 | * Copyright (c) 1995-1997 Stefan Jokisch | 2 | * Copyright (c) 1995-1997 Stefan Jokisch |
3 | * | 3 | * |
4 | * Changes for Rockbox copyright 2009 Torne Wuff | 4 | * Changes for Rockbox copyright 2009 Torne Wuff |
5 | * | 5 | * |
@@ -93,7 +93,7 @@ zword get_header_extension (int entry) | |||
93 | zword val; | 93 | zword val; |
94 | 94 | ||
95 | if (h_extension_table == 0 || entry > hx_table_size) | 95 | if (h_extension_table == 0 || entry > hx_table_size) |
96 | return 0; | 96 | return 0; |
97 | 97 | ||
98 | addr = h_extension_table + 2 * entry; | 98 | addr = h_extension_table + 2 * entry; |
99 | LOW_WORD (addr, val) | 99 | LOW_WORD (addr, val) |
@@ -114,7 +114,7 @@ void set_header_extension (int entry, zword val) | |||
114 | zword addr; | 114 | zword addr; |
115 | 115 | ||
116 | if (h_extension_table == 0 || entry > hx_table_size) | 116 | if (h_extension_table == 0 || entry > hx_table_size) |
117 | return; | 117 | return; |
118 | 118 | ||
119 | addr = h_extension_table + 2 * entry; | 119 | addr = h_extension_table + 2 * entry; |
120 | SET_WORD (addr, val) | 120 | SET_WORD (addr, val) |
@@ -141,39 +141,39 @@ void restart_header (void) | |||
141 | SET_WORD (H_FLAGS, h_flags) | 141 | SET_WORD (H_FLAGS, h_flags) |
142 | 142 | ||
143 | if (h_version >= V4) { | 143 | if (h_version >= V4) { |
144 | SET_BYTE (H_INTERPRETER_NUMBER, h_interpreter_number) | 144 | SET_BYTE (H_INTERPRETER_NUMBER, h_interpreter_number) |
145 | SET_BYTE (H_INTERPRETER_VERSION, h_interpreter_version) | 145 | SET_BYTE (H_INTERPRETER_VERSION, h_interpreter_version) |
146 | SET_BYTE (H_SCREEN_ROWS, h_screen_rows) | 146 | SET_BYTE (H_SCREEN_ROWS, h_screen_rows) |
147 | SET_BYTE (H_SCREEN_COLS, h_screen_cols) | 147 | SET_BYTE (H_SCREEN_COLS, h_screen_cols) |
148 | } | 148 | } |
149 | 149 | ||
150 | /* It's less trouble to use font size 1x1 for V5 games, especially | 150 | /* It's less trouble to use font size 1x1 for V5 games, especially |
151 | because of a bug in the unreleased German version of "Zork 1" */ | 151 | because of a bug in the unreleased German version of "Zork 1" */ |
152 | 152 | ||
153 | if (h_version != V6) { | 153 | if (h_version != V6) { |
154 | screen_x_size = (zword) h_screen_cols; | 154 | screen_x_size = (zword) h_screen_cols; |
155 | screen_y_size = (zword) h_screen_rows; | 155 | screen_y_size = (zword) h_screen_rows; |
156 | font_x_size = 1; | 156 | font_x_size = 1; |
157 | font_y_size = 1; | 157 | font_y_size = 1; |
158 | } else { | 158 | } else { |
159 | screen_x_size = h_screen_width; | 159 | screen_x_size = h_screen_width; |
160 | screen_y_size = h_screen_height; | 160 | screen_y_size = h_screen_height; |
161 | font_x_size = h_font_width; | 161 | font_x_size = h_font_width; |
162 | font_y_size = h_font_height; | 162 | font_y_size = h_font_height; |
163 | } | 163 | } |
164 | 164 | ||
165 | if (h_version >= V5) { | 165 | if (h_version >= V5) { |
166 | SET_WORD (H_SCREEN_WIDTH, screen_x_size) | 166 | SET_WORD (H_SCREEN_WIDTH, screen_x_size) |
167 | SET_WORD (H_SCREEN_HEIGHT, screen_y_size) | 167 | SET_WORD (H_SCREEN_HEIGHT, screen_y_size) |
168 | SET_BYTE (H_FONT_HEIGHT, font_y_size) | 168 | SET_BYTE (H_FONT_HEIGHT, font_y_size) |
169 | SET_BYTE (H_FONT_WIDTH, font_x_size) | 169 | SET_BYTE (H_FONT_WIDTH, font_x_size) |
170 | SET_BYTE (H_DEFAULT_BACKGROUND, h_default_background) | 170 | SET_BYTE (H_DEFAULT_BACKGROUND, h_default_background) |
171 | SET_BYTE (H_DEFAULT_FOREGROUND, h_default_foreground) | 171 | SET_BYTE (H_DEFAULT_FOREGROUND, h_default_foreground) |
172 | } | 172 | } |
173 | 173 | ||
174 | if (h_version == V6) | 174 | if (h_version == V6) |
175 | for (i = 0; i < 8; i++) | 175 | for (i = 0; i < 8; i++) |
176 | storeb ((zword) (H_USER_NAME + i), h_user_name[i]); | 176 | storeb ((zword) (H_USER_NAME + i), h_user_name[i]); |
177 | 177 | ||
178 | SET_BYTE (H_STANDARD_HIGH, h_standard_high) | 178 | SET_BYTE (H_STANDARD_HIGH, h_standard_high) |
179 | SET_BYTE (H_STANDARD_LOW, h_standard_low) | 179 | SET_BYTE (H_STANDARD_LOW, h_standard_low) |
@@ -197,41 +197,41 @@ void init_memory (void) | |||
197 | size_t buf_size; | 197 | size_t buf_size; |
198 | 198 | ||
199 | static struct { | 199 | static struct { |
200 | enum story story_id; | 200 | enum story story_id; |
201 | zword release; | 201 | zword release; |
202 | zbyte serial[6]; | 202 | zbyte serial[6]; |
203 | } records[] = { | 203 | } records[] = { |
204 | { SHERLOCK, 21, "871214" }, | 204 | { SHERLOCK, 21, "871214" }, |
205 | { SHERLOCK, 26, "880127" }, | 205 | { SHERLOCK, 26, "880127" }, |
206 | { BEYOND_ZORK, 47, "870915" }, | 206 | { BEYOND_ZORK, 47, "870915" }, |
207 | { BEYOND_ZORK, 49, "870917" }, | 207 | { BEYOND_ZORK, 49, "870917" }, |
208 | { BEYOND_ZORK, 51, "870923" }, | 208 | { BEYOND_ZORK, 51, "870923" }, |
209 | { BEYOND_ZORK, 57, "871221" }, | 209 | { BEYOND_ZORK, 57, "871221" }, |
210 | { ZORK_ZERO, 296, "881019" }, | 210 | { ZORK_ZERO, 296, "881019" }, |
211 | { ZORK_ZERO, 366, "890323" }, | 211 | { ZORK_ZERO, 366, "890323" }, |
212 | { ZORK_ZERO, 383, "890602" }, | 212 | { ZORK_ZERO, 383, "890602" }, |
213 | { ZORK_ZERO, 393, "890714" }, | 213 | { ZORK_ZERO, 393, "890714" }, |
214 | { SHOGUN, 292, "890314" }, | 214 | { SHOGUN, 292, "890314" }, |
215 | { SHOGUN, 295, "890321" }, | 215 | { SHOGUN, 295, "890321" }, |
216 | { SHOGUN, 311, "890510" }, | 216 | { SHOGUN, 311, "890510" }, |
217 | { SHOGUN, 322, "890706" }, | 217 | { SHOGUN, 322, "890706" }, |
218 | { ARTHUR, 54, "890606" }, | 218 | { ARTHUR, 54, "890606" }, |
219 | { ARTHUR, 63, "890622" }, | 219 | { ARTHUR, 63, "890622" }, |
220 | { ARTHUR, 74, "890714" }, | 220 | { ARTHUR, 74, "890714" }, |
221 | { JOURNEY, 26, "890316" }, | 221 | { JOURNEY, 26, "890316" }, |
222 | { JOURNEY, 30, "890322" }, | 222 | { JOURNEY, 30, "890322" }, |
223 | { JOURNEY, 77, "890616" }, | 223 | { JOURNEY, 77, "890616" }, |
224 | { JOURNEY, 83, "890706" }, | 224 | { JOURNEY, 83, "890706" }, |
225 | { LURKING_HORROR, 203, "870506" }, | 225 | { LURKING_HORROR, 203, "870506" }, |
226 | { LURKING_HORROR, 219, "870912" }, | 226 | { LURKING_HORROR, 219, "870912" }, |
227 | { LURKING_HORROR, 221, "870918" }, | 227 | { LURKING_HORROR, 221, "870918" }, |
228 | { UNKNOWN, 0, "------" } | 228 | { UNKNOWN, 0, "------" } |
229 | }; | 229 | }; |
230 | 230 | ||
231 | /* Open story file */ | 231 | /* Open story file */ |
232 | 232 | ||
233 | if ((story_fp = rb->open(story_name, O_RDONLY)) < 0) | 233 | if ((story_fp = rb->open(story_name, O_RDONLY)) < 0) |
234 | os_fatal ("Cannot open story file"); | 234 | os_fatal ("Cannot open story file"); |
235 | 235 | ||
236 | /* Allocate memory for story header */ | 236 | /* Allocate memory for story header */ |
237 | 237 | ||
@@ -240,19 +240,19 @@ void init_memory (void) | |||
240 | /* Load header into memory */ | 240 | /* Load header into memory */ |
241 | 241 | ||
242 | if (fread (zmp, 1, 64, story_fp) != 64) | 242 | if (fread (zmp, 1, 64, story_fp) != 64) |
243 | os_fatal ("Story file read error"); | 243 | os_fatal ("Story file read error"); |
244 | 244 | ||
245 | /* Copy header fields to global variables */ | 245 | /* Copy header fields to global variables */ |
246 | 246 | ||
247 | LOW_BYTE (H_VERSION, h_version) | 247 | LOW_BYTE (H_VERSION, h_version) |
248 | 248 | ||
249 | if (h_version < V1 || h_version > V8) | 249 | if (h_version < V1 || h_version > V8) |
250 | os_fatal ("Unknown Z-code version"); | 250 | os_fatal ("Unknown Z-code version"); |
251 | 251 | ||
252 | LOW_BYTE (H_CONFIG, h_config) | 252 | LOW_BYTE (H_CONFIG, h_config) |
253 | 253 | ||
254 | if (h_version == V3 && (h_config & CONFIG_BYTE_SWAPPED)) | 254 | if (h_version == V3 && (h_config & CONFIG_BYTE_SWAPPED)) |
255 | os_fatal ("Byte swapped story file"); | 255 | os_fatal ("Byte swapped story file"); |
256 | 256 | ||
257 | LOW_WORD (H_RELEASE, h_release) | 257 | LOW_WORD (H_RELEASE, h_release) |
258 | LOW_WORD (H_RESIDENT_SIZE, h_resident_size) | 258 | LOW_WORD (H_RESIDENT_SIZE, h_resident_size) |
@@ -264,7 +264,7 @@ void init_memory (void) | |||
264 | LOW_WORD (H_FLAGS, h_flags) | 264 | LOW_WORD (H_FLAGS, h_flags) |
265 | 265 | ||
266 | for (i = 0, addr = H_SERIAL; i < 6; i++, addr++) | 266 | for (i = 0, addr = H_SERIAL; i < 6; i++, addr++) |
267 | LOW_BYTE (addr, h_serial[i]) | 267 | LOW_BYTE (addr, h_serial[i]) |
268 | 268 | ||
269 | /* Auto-detect buggy story files that need special fixes */ | 269 | /* Auto-detect buggy story files that need special fixes */ |
270 | 270 | ||
@@ -272,15 +272,15 @@ void init_memory (void) | |||
272 | 272 | ||
273 | for (i = 0; records[i].story_id != UNKNOWN; i++) { | 273 | for (i = 0; records[i].story_id != UNKNOWN; i++) { |
274 | 274 | ||
275 | if (h_release == records[i].release) { | 275 | if (h_release == records[i].release) { |
276 | 276 | ||
277 | for (j = 0; j < 6; j++) | 277 | for (j = 0; j < 6; j++) |
278 | if (h_serial[j] != records[i].serial[j]) | 278 | if (h_serial[j] != records[i].serial[j]) |
279 | goto no_match; | 279 | goto no_match; |
280 | 280 | ||
281 | story_id = records[i].story_id; | 281 | story_id = records[i].story_id; |
282 | 282 | ||
283 | } | 283 | } |
284 | 284 | ||
285 | no_match: ; /* null statement */ | 285 | no_match: ; /* null statement */ |
286 | 286 | ||
@@ -293,18 +293,18 @@ void init_memory (void) | |||
293 | 293 | ||
294 | if (h_file_size != 0) { | 294 | if (h_file_size != 0) { |
295 | 295 | ||
296 | story_size = (long) 2 * h_file_size; | 296 | story_size = (long) 2 * h_file_size; |
297 | 297 | ||
298 | if (h_version >= V4) | 298 | if (h_version >= V4) |
299 | story_size *= 2; | 299 | story_size *= 2; |
300 | if (h_version >= V6) | 300 | if (h_version >= V6) |
301 | story_size *= 2; | 301 | story_size *= 2; |
302 | 302 | ||
303 | } else { /* some old games lack the file size entry */ | 303 | } else { /* some old games lack the file size entry */ |
304 | 304 | ||
305 | fseek (story_fp, 0, SEEK_END); | 305 | fseek (story_fp, 0, SEEK_END); |
306 | story_size = ftell (story_fp); | 306 | story_size = ftell (story_fp); |
307 | fseek (story_fp, 64, SEEK_SET); | 307 | fseek (story_fp, 64, SEEK_SET); |
308 | 308 | ||
309 | } | 309 | } |
310 | 310 | ||
@@ -318,27 +318,27 @@ void init_memory (void) | |||
318 | /* Zork Zero Macintosh doesn't have the graphics flag set */ | 318 | /* Zork Zero Macintosh doesn't have the graphics flag set */ |
319 | 319 | ||
320 | if (story_id == ZORK_ZERO && h_release == 296) | 320 | if (story_id == ZORK_ZERO && h_release == 296) |
321 | h_flags |= GRAPHICS_FLAG; | 321 | h_flags |= GRAPHICS_FLAG; |
322 | 322 | ||
323 | /* Adjust opcode tables */ | 323 | /* Adjust opcode tables */ |
324 | 324 | ||
325 | if (h_version <= V4) { | 325 | if (h_version <= V4) { |
326 | op0_opcodes[0x09] = z_pop; | 326 | op0_opcodes[0x09] = z_pop; |
327 | op1_opcodes[0x0f] = z_not; | 327 | op1_opcodes[0x0f] = z_not; |
328 | } else { | 328 | } else { |
329 | op0_opcodes[0x09] = z_catch; | 329 | op0_opcodes[0x09] = z_catch; |
330 | op1_opcodes[0x0f] = z_call_n; | 330 | op1_opcodes[0x0f] = z_call_n; |
331 | } | 331 | } |
332 | 332 | ||
333 | /* Allocate memory for story data */ | 333 | /* Allocate memory for story data */ |
334 | 334 | ||
335 | if ((size_t)story_size > buf_size) | 335 | if ((size_t)story_size > buf_size) |
336 | { | 336 | { |
337 | audiobuf = rb->plugin_get_audio_buffer(&buf_size); | 337 | audiobuf = rb->plugin_get_audio_buffer(&buf_size); |
338 | if ((size_t)story_size > buf_size) | 338 | if ((size_t)story_size > buf_size) |
339 | os_fatal ("Out of memory"); | 339 | os_fatal ("Out of memory"); |
340 | rb->memcpy(audiobuf, zmp, 64); | 340 | rb->memcpy(audiobuf, zmp, 64); |
341 | zmp = audiobuf; | 341 | zmp = audiobuf; |
342 | } | 342 | } |
343 | 343 | ||
344 | /* Assign left over memory as the arena for undo alloc */ | 344 | /* Assign left over memory as the arena for undo alloc */ |
@@ -351,13 +351,13 @@ void init_memory (void) | |||
351 | 351 | ||
352 | for (size = 64; size < story_size; size += n) { | 352 | for (size = 64; size < story_size; size += n) { |
353 | 353 | ||
354 | if (story_size - size < 0x8000) | 354 | if (story_size - size < 0x8000) |
355 | n = (unsigned) (story_size - size); | 355 | n = (unsigned) (story_size - size); |
356 | 356 | ||
357 | SET_PC (size) | 357 | SET_PC (size) |
358 | 358 | ||
359 | if (fread (pcp, 1, n, story_fp) != (signed)n) | 359 | if (fread (pcp, 1, n, story_fp) != (signed)n) |
360 | os_fatal ("Story file read error"); | 360 | os_fatal ("Story file read error"); |
361 | 361 | ||
362 | } | 362 | } |
363 | 363 | ||
@@ -383,13 +383,13 @@ void init_undo (void) | |||
383 | + 1.5 h_dynamic_size for Quetzal diff + 2. */ | 383 | + 1.5 h_dynamic_size for Quetzal diff + 2. */ |
384 | int size = (h_dynamic_size * 5) / 2 + 2; | 384 | int size = (h_dynamic_size * 5) / 2 + 2; |
385 | if ((arena_end - arena_start) >= size) { | 385 | if ((arena_end - arena_start) >= size) { |
386 | prev_zmp = arena_start; | 386 | prev_zmp = arena_start; |
387 | undo_diff = arena_start + h_dynamic_size; | 387 | undo_diff = arena_start + h_dynamic_size; |
388 | arena_start = (void*)((intptr_t)(arena_start + size + 3) & ~3); | 388 | arena_start = (void*)((intptr_t)(arena_start + size + 3) & ~3); |
389 | arena_next = arena_start; | 389 | arena_next = arena_start; |
390 | memcpy (prev_zmp, zmp, h_dynamic_size); | 390 | memcpy (prev_zmp, zmp, h_dynamic_size); |
391 | } else | 391 | } else |
392 | f_setup.undo_slots = 0; | 392 | f_setup.undo_slots = 0; |
393 | 393 | ||
394 | }/* init_undo */ | 394 | }/* init_undo */ |
395 | 395 | ||
@@ -402,21 +402,19 @@ void init_undo (void) | |||
402 | 402 | ||
403 | static void free_undo (int count) | 403 | static void free_undo (int count) |
404 | { | 404 | { |
405 | undo_t *p; | ||
406 | |||
407 | if (count > undo_count) | 405 | if (count > undo_count) |
408 | count = undo_count; | 406 | count = undo_count; |
409 | while (count--) { | 407 | while (count--) { |
410 | p = first_undo; | 408 | |
411 | if (curr_undo == first_undo) | 409 | if (curr_undo == first_undo) |
412 | curr_undo = curr_undo->next; | 410 | curr_undo = curr_undo->next; |
413 | first_undo = first_undo->next; | 411 | first_undo = first_undo->next; |
414 | undo_count--; | 412 | undo_count--; |
415 | } | 413 | } |
416 | if (first_undo) | 414 | if (first_undo) |
417 | first_undo->prev = NULL; | 415 | first_undo->prev = NULL; |
418 | else | 416 | else |
419 | last_undo = NULL; | 417 | last_undo = NULL; |
420 | }/* free_undo */ | 418 | }/* free_undo */ |
421 | 419 | ||
422 | /* | 420 | /* |
@@ -429,7 +427,7 @@ static void free_undo (int count) | |||
429 | void reset_memory (void) | 427 | void reset_memory (void) |
430 | { | 428 | { |
431 | if (story_fp != -1) | 429 | if (story_fp != -1) |
432 | fclose (story_fp); | 430 | fclose (story_fp); |
433 | story_fp = -1; | 431 | story_fp = -1; |
434 | 432 | ||
435 | free_undo (undo_count); | 433 | free_undo (undo_count); |
@@ -452,22 +450,22 @@ void storeb (zword addr, zbyte value) | |||
452 | { | 450 | { |
453 | 451 | ||
454 | if (addr >= h_dynamic_size) | 452 | if (addr >= h_dynamic_size) |
455 | runtime_error (ERR_STORE_RANGE); | 453 | runtime_error (ERR_STORE_RANGE); |
456 | 454 | ||
457 | if (addr == H_FLAGS + 1) { /* flags register is modified */ | 455 | if (addr == H_FLAGS + 1) { /* flags register is modified */ |
458 | 456 | ||
459 | h_flags &= ~(SCRIPTING_FLAG | FIXED_FONT_FLAG); | 457 | h_flags &= ~(SCRIPTING_FLAG | FIXED_FONT_FLAG); |
460 | h_flags |= value & (SCRIPTING_FLAG | FIXED_FONT_FLAG); | 458 | h_flags |= value & (SCRIPTING_FLAG | FIXED_FONT_FLAG); |
461 | 459 | ||
462 | if (value & SCRIPTING_FLAG) { | 460 | if (value & SCRIPTING_FLAG) { |
463 | if (!ostream_script) | 461 | if (!ostream_script) |
464 | script_open (); | 462 | script_open (); |
465 | } else { | 463 | } else { |
466 | if (ostream_script) | 464 | if (ostream_script) |
467 | script_close (); | 465 | script_close (); |
468 | } | 466 | } |
469 | 467 | ||
470 | refresh_text_style (); | 468 | refresh_text_style (); |
471 | 469 | ||
472 | } | 470 | } |
473 | 471 | ||
@@ -493,7 +491,7 @@ void storew (zword addr, zword value) | |||
493 | /* | 491 | /* |
494 | * z_restart, re-load dynamic area, clear the stack and set the PC. | 492 | * z_restart, re-load dynamic area, clear the stack and set the PC. |
495 | * | 493 | * |
496 | * no zargs used | 494 | * no zargs used |
497 | * | 495 | * |
498 | */ | 496 | */ |
499 | 497 | ||
@@ -509,10 +507,10 @@ void z_restart (void) | |||
509 | 507 | ||
510 | if (!first_restart) { | 508 | if (!first_restart) { |
511 | 509 | ||
512 | fseek (story_fp, 0, SEEK_SET); | 510 | fseek (story_fp, 0, SEEK_SET); |
513 | 511 | ||
514 | if (fread (zmp, 1, h_dynamic_size, story_fp) != h_dynamic_size) | 512 | if (fread (zmp, 1, h_dynamic_size, story_fp) != h_dynamic_size) |
515 | os_fatal ("Story file read error"); | 513 | os_fatal ("Story file read error"); |
516 | 514 | ||
517 | } else first_restart = FALSE; | 515 | } else first_restart = FALSE; |
518 | 516 | ||
@@ -524,8 +522,8 @@ void z_restart (void) | |||
524 | 522 | ||
525 | if (h_version != V6) { | 523 | if (h_version != V6) { |
526 | 524 | ||
527 | long pc = (long) h_start_pc; | 525 | long pc = (long) h_start_pc; |
528 | SET_PC (pc) | 526 | SET_PC (pc) |
529 | 527 | ||
530 | } else call (h_start_pc, 0, NULL, 0); | 528 | } else call (h_start_pc, 0, NULL, 0); |
531 | 529 | ||
@@ -546,30 +544,30 @@ static void get_default_name (char *default_name, zword addr) | |||
546 | 544 | ||
547 | if (addr != 0) { | 545 | if (addr != 0) { |
548 | 546 | ||
549 | zbyte len; | 547 | zbyte len; |
550 | int i; | 548 | int i; |
551 | 549 | ||
552 | LOW_BYTE (addr, len) | 550 | LOW_BYTE (addr, len) |
553 | addr++; | 551 | addr++; |
554 | 552 | ||
555 | for (i = 0; i < len; i++) { | 553 | for (i = 0; i < len; i++) { |
556 | 554 | ||
557 | zbyte c; | 555 | zbyte c; |
558 | 556 | ||
559 | LOW_BYTE (addr, c) | 557 | LOW_BYTE (addr, c) |
560 | addr++; | 558 | addr++; |
561 | 559 | ||
562 | if (c >= 'A' && c <= 'Z') | 560 | if (c >= 'A' && c <= 'Z') |
563 | c += 'a' - 'A'; | 561 | c += 'a' - 'A'; |
564 | 562 | ||
565 | default_name[i] = c; | 563 | default_name[i] = c; |
566 | 564 | ||
567 | } | 565 | } |
568 | 566 | ||
569 | default_name[i] = 0; | 567 | default_name[i] = 0; |
570 | 568 | ||
571 | if (strchr (default_name, '.') == NULL) | 569 | if (strchr (default_name, '.') == NULL) |
572 | strcpy (default_name + i, ".AUX"); | 570 | strcpy (default_name + i, ".AUX"); |
573 | 571 | ||
574 | } else strcpy (default_name, auxilary_name); | 572 | } else strcpy (default_name, auxilary_name); |
575 | 573 | ||
@@ -578,9 +576,9 @@ static void get_default_name (char *default_name, zword addr) | |||
578 | /* | 576 | /* |
579 | * z_restore, restore [a part of] a Z-machine state from disk | 577 | * z_restore, restore [a part of] a Z-machine state from disk |
580 | * | 578 | * |
581 | * zargs[0] = address of area to restore (optional) | 579 | * zargs[0] = address of area to restore (optional) |
582 | * zargs[1] = number of bytes to restore | 580 | * zargs[1] = number of bytes to restore |
583 | * zargs[2] = address of suggested file name | 581 | * zargs[2] = address of suggested file name |
584 | * | 582 | * |
585 | */ | 583 | */ |
586 | 584 | ||
@@ -594,84 +592,84 @@ void z_restore (void) | |||
594 | 592 | ||
595 | if (zargc != 0) { | 593 | if (zargc != 0) { |
596 | 594 | ||
597 | /* Get the file name */ | 595 | /* Get the file name */ |
598 | 596 | ||
599 | get_default_name (default_name, (zargc >= 3) ? zargs[2] : 0); | 597 | get_default_name (default_name, (zargc >= 3) ? zargs[2] : 0); |
600 | 598 | ||
601 | if (os_read_file_name (new_name, default_name, FILE_LOAD_AUX) == 0) | 599 | if (os_read_file_name (new_name, default_name, FILE_LOAD_AUX) == 0) |
602 | goto finished; | 600 | goto finished; |
603 | 601 | ||
604 | strcpy (auxilary_name, default_name); | 602 | strcpy (auxilary_name, default_name); |
605 | 603 | ||
606 | /* Open auxilary file */ | 604 | /* Open auxilary file */ |
607 | 605 | ||
608 | if ((gfp = rb->open (new_name, O_RDONLY)) < 0) | 606 | if ((gfp = rb->open (new_name, O_RDONLY)) < 0) |
609 | goto finished; | 607 | goto finished; |
610 | 608 | ||
611 | /* Load auxilary file */ | 609 | /* Load auxilary file */ |
612 | 610 | ||
613 | success = fread (zmp + zargs[0], 1, zargs[1], gfp); | 611 | success = fread (zmp + zargs[0], 1, zargs[1], gfp); |
614 | 612 | ||
615 | /* Close auxilary file */ | 613 | /* Close auxilary file */ |
616 | 614 | ||
617 | fclose (gfp); | 615 | fclose (gfp); |
618 | 616 | ||
619 | } else { | 617 | } else { |
620 | 618 | ||
621 | /* Get the file name */ | 619 | /* Get the file name */ |
622 | 620 | ||
623 | if (os_read_file_name (new_name, save_name, FILE_RESTORE) == 0) | 621 | if (os_read_file_name (new_name, save_name, FILE_RESTORE) == 0) |
624 | goto finished; | 622 | goto finished; |
625 | 623 | ||
626 | strcpy (save_name, new_name); | 624 | strcpy (save_name, new_name); |
627 | 625 | ||
628 | /* Open game file */ | 626 | /* Open game file */ |
629 | 627 | ||
630 | if ((gfp = rb->open (new_name, O_RDONLY)) < 0) | 628 | if ((gfp = rb->open (new_name, O_RDONLY)) < 0) |
631 | goto finished; | 629 | goto finished; |
632 | 630 | ||
633 | success = restore_quetzal (gfp, story_fp); | 631 | success = restore_quetzal (gfp, story_fp); |
634 | 632 | ||
635 | /* Close game file */ | 633 | /* Close game file */ |
636 | 634 | ||
637 | fclose (gfp); | 635 | fclose (gfp); |
638 | 636 | ||
639 | if ((short) success >= 0) { | 637 | if ((short) success >= 0) { |
640 | 638 | ||
641 | if ((short) success > 0) { | 639 | if ((short) success > 0) { |
642 | zbyte old_screen_rows; | 640 | zbyte old_screen_rows; |
643 | zbyte old_screen_cols; | 641 | zbyte old_screen_cols; |
644 | 642 | ||
645 | /* In V3, reset the upper window. */ | 643 | /* In V3, reset the upper window. */ |
646 | if (h_version == V3) | 644 | if (h_version == V3) |
647 | split_window (0); | 645 | split_window (0); |
648 | 646 | ||
649 | LOW_BYTE (H_SCREEN_ROWS, old_screen_rows); | 647 | LOW_BYTE (H_SCREEN_ROWS, old_screen_rows); |
650 | LOW_BYTE (H_SCREEN_COLS, old_screen_cols); | 648 | LOW_BYTE (H_SCREEN_COLS, old_screen_cols); |
651 | 649 | ||
652 | /* Reload cached header fields. */ | 650 | /* Reload cached header fields. */ |
653 | restart_header (); | 651 | restart_header (); |
654 | 652 | ||
655 | /* | 653 | /* |
656 | * Since QUETZAL files may be saved on many different machines, | 654 | * Since QUETZAL files may be saved on many different machines, |
657 | * the screen sizes may vary a lot. Erasing the status window | 655 | * the screen sizes may vary a lot. Erasing the status window |
658 | * seems to cover up most of the resulting badness. | 656 | * seems to cover up most of the resulting badness. |
659 | */ | 657 | */ |
660 | if (h_version > V3 && h_version != V6 | 658 | if (h_version > V3 && h_version != V6 |
661 | && (h_screen_rows != old_screen_rows | 659 | && (h_screen_rows != old_screen_rows |
662 | || h_screen_cols != old_screen_cols)) | 660 | || h_screen_cols != old_screen_cols)) |
663 | erase_window (1); | 661 | erase_window (1); |
664 | } | 662 | } |
665 | } else | 663 | } else |
666 | os_fatal ("Error reading save file"); | 664 | os_fatal ("Error reading save file"); |
667 | } | 665 | } |
668 | 666 | ||
669 | finished: | 667 | finished: |
670 | 668 | ||
671 | if (h_version <= V3) | 669 | if (h_version <= V3) |
672 | branch (success); | 670 | branch (success); |
673 | else | 671 | else |
674 | store (success); | 672 | store (success); |
675 | 673 | ||
676 | }/* z_restore */ | 674 | }/* z_restore */ |
677 | 675 | ||
@@ -694,28 +692,28 @@ static long mem_diff (zbyte *a, zbyte *b, zword mem_size, zbyte *diff) | |||
694 | zbyte c = 0; | 692 | zbyte c = 0; |
695 | 693 | ||
696 | for (;;) { | 694 | for (;;) { |
697 | for (j = 0; size > 0 && (c = *a++ ^ *b++) == 0; j++) | 695 | for (j = 0; size > 0 && (c = *a++ ^ *b++) == 0; j++) |
698 | size--; | 696 | size--; |
699 | if (size == 0) break; | 697 | if (size == 0) break; |
700 | size--; | 698 | size--; |
701 | if (j > 0x8000) { | 699 | if (j > 0x8000) { |
702 | *p++ = 0; | 700 | *p++ = 0; |
703 | *p++ = 0xff; | 701 | *p++ = 0xff; |
704 | *p++ = 0xff; | 702 | *p++ = 0xff; |
705 | j -= 0x8000; | 703 | j -= 0x8000; |
706 | } | 704 | } |
707 | if (j > 0) { | 705 | if (j > 0) { |
708 | *p++ = 0; | 706 | *p++ = 0; |
709 | j--; | 707 | j--; |
710 | if (j <= 0x7f) { | 708 | if (j <= 0x7f) { |
711 | *p++ = j; | 709 | *p++ = j; |
712 | } else { | 710 | } else { |
713 | *p++ = (j & 0x7f) | 0x80; | 711 | *p++ = (j & 0x7f) | 0x80; |
714 | *p++ = (j & 0x7f80) >> 7; | 712 | *p++ = (j & 0x7f80) >> 7; |
715 | } | 713 | } |
716 | } | 714 | } |
717 | *p++ = c; | 715 | *p++ = c; |
718 | *(b - 1) ^= c; | 716 | *(b - 1) ^= c; |
719 | } | 717 | } |
720 | return p - diff; | 718 | return p - diff; |
721 | }/* mem_diff */ | 719 | }/* mem_diff */ |
@@ -732,27 +730,27 @@ static void mem_undiff (zbyte *diff, long diff_length, zbyte *dest) | |||
732 | zbyte c; | 730 | zbyte c; |
733 | 731 | ||
734 | while (diff_length) { | 732 | while (diff_length) { |
735 | c = *diff++; | 733 | c = *diff++; |
736 | diff_length--; | 734 | diff_length--; |
737 | if (c == 0) { | 735 | if (c == 0) { |
738 | unsigned runlen; | 736 | unsigned runlen; |
739 | 737 | ||
740 | if (!diff_length) | 738 | if (!diff_length) |
741 | return; /* Incomplete run */ | 739 | return; /* Incomplete run */ |
742 | runlen = *diff++; | 740 | runlen = *diff++; |
743 | diff_length--; | 741 | diff_length--; |
744 | if (runlen & 0x80) { | 742 | if (runlen & 0x80) { |
745 | if (!diff_length) | 743 | if (!diff_length) |
746 | return; /* Incomplete extended run */ | 744 | return; /* Incomplete extended run */ |
747 | c = *diff++; | 745 | c = *diff++; |
748 | diff_length--; | 746 | diff_length--; |
749 | runlen = (runlen & 0x7f) | (((unsigned) c) << 7); | 747 | runlen = (runlen & 0x7f) | (((unsigned) c) << 7); |
750 | } | 748 | } |
751 | 749 | ||
752 | dest += runlen + 1; | 750 | dest += runlen + 1; |
753 | } else { | 751 | } else { |
754 | *dest++ ^= c; | 752 | *dest++ ^= c; |
755 | } | 753 | } |
756 | } | 754 | } |
757 | }/* mem_undiff */ | 755 | }/* mem_undiff */ |
758 | 756 | ||
@@ -766,13 +764,13 @@ static void mem_undiff (zbyte *diff, long diff_length, zbyte *dest) | |||
766 | int restore_undo (void) | 764 | int restore_undo (void) |
767 | { | 765 | { |
768 | 766 | ||
769 | if (f_setup.undo_slots == 0) /* undo feature unavailable */ | 767 | if (f_setup.undo_slots == 0) /* undo feature unavailable */ |
770 | 768 | ||
771 | return -1; | 769 | return -1; |
772 | 770 | ||
773 | if (curr_undo == NULL) /* no saved game state */ | 771 | if (curr_undo == NULL) /* no saved game state */ |
774 | 772 | ||
775 | return 0; | 773 | return 0; |
776 | 774 | ||
777 | /* undo possible */ | 775 | /* undo possible */ |
778 | 776 | ||
@@ -783,7 +781,7 @@ int restore_undo (void) | |||
783 | frame_count = curr_undo->frame_count; | 781 | frame_count = curr_undo->frame_count; |
784 | mem_undiff ((zbyte *) (curr_undo + 1), curr_undo->diff_size, prev_zmp); | 782 | mem_undiff ((zbyte *) (curr_undo + 1), curr_undo->diff_size, prev_zmp); |
785 | memcpy (sp, (zbyte *)(curr_undo + 1) + curr_undo->diff_size, | 783 | memcpy (sp, (zbyte *)(curr_undo + 1) + curr_undo->diff_size, |
786 | curr_undo->stack_size * sizeof (*sp)); | 784 | curr_undo->stack_size * sizeof (*sp)); |
787 | 785 | ||
788 | curr_undo = curr_undo->prev; | 786 | curr_undo = curr_undo->prev; |
789 | 787 | ||
@@ -796,7 +794,7 @@ int restore_undo (void) | |||
796 | /* | 794 | /* |
797 | * z_restore_undo, restore a Z-machine state from memory. | 795 | * z_restore_undo, restore a Z-machine state from memory. |
798 | * | 796 | * |
799 | * no zargs used | 797 | * no zargs used |
800 | * | 798 | * |
801 | */ | 799 | */ |
802 | 800 | ||
@@ -810,9 +808,9 @@ void z_restore_undo (void) | |||
810 | /* | 808 | /* |
811 | * z_save, save [a part of] the Z-machine state to disk. | 809 | * z_save, save [a part of] the Z-machine state to disk. |
812 | * | 810 | * |
813 | * zargs[0] = address of memory area to save (optional) | 811 | * zargs[0] = address of memory area to save (optional) |
814 | * zargs[1] = number of bytes to save | 812 | * zargs[1] = number of bytes to save |
815 | * zargs[2] = address of suggested file name | 813 | * zargs[2] = address of suggested file name |
816 | * | 814 | * |
817 | */ | 815 | */ |
818 | 816 | ||
@@ -826,63 +824,63 @@ void z_save (void) | |||
826 | 824 | ||
827 | if (zargc != 0) { | 825 | if (zargc != 0) { |
828 | 826 | ||
829 | /* Get the file name */ | 827 | /* Get the file name */ |
830 | 828 | ||
831 | get_default_name (default_name, (zargc >= 3) ? zargs[2] : 0); | 829 | get_default_name (default_name, (zargc >= 3) ? zargs[2] : 0); |
832 | 830 | ||
833 | if (os_read_file_name (new_name, default_name, FILE_SAVE_AUX) == 0) | 831 | if (os_read_file_name (new_name, default_name, FILE_SAVE_AUX) == 0) |
834 | goto finished; | 832 | goto finished; |
835 | 833 | ||
836 | strcpy (auxilary_name, default_name); | 834 | strcpy (auxilary_name, default_name); |
837 | 835 | ||
838 | /* Open auxilary file */ | 836 | /* Open auxilary file */ |
839 | 837 | ||
840 | if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) | 838 | if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) |
841 | goto finished; | 839 | goto finished; |
842 | 840 | ||
843 | /* Write auxilary file */ | 841 | /* Write auxilary file */ |
844 | 842 | ||
845 | success = fwrite (zmp + zargs[0], zargs[1], 1, gfp); | 843 | success = fwrite (zmp + zargs[0], zargs[1], 1, gfp); |
846 | 844 | ||
847 | /* Close auxilary file */ | 845 | /* Close auxilary file */ |
848 | 846 | ||
849 | fclose (gfp); | 847 | fclose (gfp); |
850 | 848 | ||
851 | } else { | 849 | } else { |
852 | 850 | ||
853 | /* Get the file name */ | 851 | /* Get the file name */ |
854 | 852 | ||
855 | if (os_read_file_name (new_name, save_name, FILE_SAVE) == 0) | 853 | if (os_read_file_name (new_name, save_name, FILE_SAVE) == 0) |
856 | goto finished; | 854 | goto finished; |
857 | 855 | ||
858 | strcpy (save_name, new_name); | 856 | strcpy (save_name, new_name); |
859 | 857 | ||
860 | /* Open game file */ | 858 | /* Open game file */ |
861 | 859 | ||
862 | if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) | 860 | if ((gfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) |
863 | goto finished; | 861 | goto finished; |
864 | 862 | ||
865 | success = save_quetzal (gfp, story_fp); | 863 | success = save_quetzal (gfp, story_fp); |
866 | 864 | ||
867 | /* Close game file and check for errors */ | 865 | /* Close game file and check for errors */ |
868 | 866 | ||
869 | if (fclose (gfp) != 0 || ferror (story_fp)) { | 867 | if (fclose (gfp) != 0 || ferror (story_fp)) { |
870 | print_string ("Error writing save file\n"); | 868 | print_string ("Error writing save file\n"); |
871 | goto finished; | 869 | goto finished; |
872 | } | 870 | } |
873 | 871 | ||
874 | /* Success */ | 872 | /* Success */ |
875 | 873 | ||
876 | success = 1; | 874 | success = 1; |
877 | 875 | ||
878 | } | 876 | } |
879 | 877 | ||
880 | finished: | 878 | finished: |
881 | 879 | ||
882 | if (h_version <= V3) | 880 | if (h_version <= V3) |
883 | branch (success); | 881 | branch (success); |
884 | else | 882 | else |
885 | store (success); | 883 | store (success); |
886 | 884 | ||
887 | }/* z_save */ | 885 | }/* z_save */ |
888 | 886 | ||
@@ -900,57 +898,57 @@ int save_undo (void) | |||
900 | int size; | 898 | int size; |
901 | undo_t *p; | 899 | undo_t *p; |
902 | 900 | ||
903 | if (f_setup.undo_slots == 0) /* undo feature unavailable */ | 901 | if (f_setup.undo_slots == 0) /* undo feature unavailable */ |
904 | return -1; | 902 | return -1; |
905 | 903 | ||
906 | /* save undo possible */ | 904 | /* save undo possible */ |
907 | 905 | ||
908 | while (last_undo != curr_undo) { | 906 | while (last_undo != curr_undo) { |
909 | p = last_undo; | 907 | p = last_undo; |
910 | last_undo = last_undo->prev; | 908 | last_undo = last_undo->prev; |
911 | arena_next = p; | 909 | arena_next = p; |
912 | undo_count--; | 910 | undo_count--; |
913 | } | 911 | } |
914 | if (last_undo) | 912 | if (last_undo) |
915 | last_undo->next = NULL; | 913 | last_undo->next = NULL; |
916 | else | 914 | else |
917 | first_undo = NULL; | 915 | first_undo = NULL; |
918 | 916 | ||
919 | if (undo_count == f_setup.undo_slots) | 917 | if (undo_count == f_setup.undo_slots) |
920 | free_undo (1); | 918 | free_undo (1); |
921 | 919 | ||
922 | diff_size = mem_diff (zmp, prev_zmp, h_dynamic_size, undo_diff); | 920 | diff_size = mem_diff (zmp, prev_zmp, h_dynamic_size, undo_diff); |
923 | stack_size = stack + STACK_SIZE - sp; | 921 | stack_size = stack + STACK_SIZE - sp; |
924 | do { | 922 | do { |
925 | size = sizeof (undo_t) + diff_size + stack_size * sizeof (*sp); | 923 | size = sizeof (undo_t) + diff_size + stack_size * sizeof (*sp); |
926 | if (arena_next > (void*)first_undo) { | 924 | if (arena_next > (void*)first_undo) { |
927 | /* Free space is all at the end */ | 925 | /* Free space is all at the end */ |
928 | if ((arena_end - arena_next) >= size) { | 926 | if ((arena_end - arena_next) >= size) { |
929 | /* Trivial: enough room at the end */ | 927 | /* Trivial: enough room at the end */ |
930 | p = arena_next; | 928 | p = arena_next; |
931 | arena_next = (void*)((intptr_t)(arena_next + size + 3) & ~3); | 929 | arena_next = (void*)((intptr_t)(arena_next + size + 3) & ~3); |
932 | } else { | 930 | } else { |
933 | /* Need to wrap */ | 931 | /* Need to wrap */ |
934 | arena_next = arena_start; | 932 | arena_next = arena_start; |
935 | p = NULL; | 933 | p = NULL; |
936 | } | 934 | } |
937 | } else { | 935 | } else { |
938 | /* Free space is somewhere else */ | 936 | /* Free space is somewhere else */ |
939 | if (((void*)first_undo - arena_next) >= size) { | 937 | if (((void*)first_undo - arena_next) >= size) { |
940 | /* There is room before the "first" undo */ | 938 | /* There is room before the "first" undo */ |
941 | p = arena_next; | 939 | p = arena_next; |
942 | arena_next = (void*)((intptr_t)(arena_next + size + 3) & ~3); | 940 | arena_next = (void*)((intptr_t)(arena_next + size + 3) & ~3); |
943 | } else { | 941 | } else { |
944 | /* Not enough room, just need to free some */ | 942 | /* Not enough room, just need to free some */ |
945 | p = NULL; | 943 | p = NULL; |
946 | } | 944 | } |
947 | } | 945 | } |
948 | 946 | ||
949 | if (p == NULL) | 947 | if (p == NULL) |
950 | free_undo (1); | 948 | free_undo (1); |
951 | } while (!p && undo_count); | 949 | } while (!p && undo_count); |
952 | if (p == NULL) | 950 | if (p == NULL) |
953 | return -1; | 951 | return -1; |
954 | GET_PC (p->pc) | 952 | GET_PC (p->pc) |
955 | p->frame_count = frame_count; | 953 | p->frame_count = frame_count; |
956 | p->diff_size = diff_size; | 954 | p->diff_size = diff_size; |
@@ -960,11 +958,11 @@ int save_undo (void) | |||
960 | memcpy ((zbyte *)(p + 1) + diff_size, sp, stack_size * sizeof (*sp)); | 958 | memcpy ((zbyte *)(p + 1) + diff_size, sp, stack_size * sizeof (*sp)); |
961 | 959 | ||
962 | if (!first_undo) { | 960 | if (!first_undo) { |
963 | p->prev = NULL; | 961 | p->prev = NULL; |
964 | first_undo = p; | 962 | first_undo = p; |
965 | } else { | 963 | } else { |
966 | last_undo->next = p; | 964 | last_undo->next = p; |
967 | p->prev = last_undo; | 965 | p->prev = last_undo; |
968 | } | 966 | } |
969 | p->next = NULL; | 967 | p->next = NULL; |
970 | curr_undo = last_undo = p; | 968 | curr_undo = last_undo = p; |
@@ -976,7 +974,7 @@ int save_undo (void) | |||
976 | /* | 974 | /* |
977 | * z_save_undo, save the current Z-machine state for a future undo. | 975 | * z_save_undo, save the current Z-machine state for a future undo. |
978 | * | 976 | * |
979 | * no zargs used | 977 | * no zargs used |
980 | * | 978 | * |
981 | */ | 979 | */ |
982 | 980 | ||
@@ -990,7 +988,7 @@ void z_save_undo (void) | |||
990 | /* | 988 | /* |
991 | * z_verify, check the story file integrity. | 989 | * z_verify, check the story file integrity. |
992 | * | 990 | * |
993 | * no zargs used | 991 | * no zargs used |
994 | * | 992 | * |
995 | */ | 993 | */ |
996 | 994 | ||
@@ -1004,7 +1002,7 @@ void z_verify (void) | |||
1004 | fseek (story_fp, 64, SEEK_SET); | 1002 | fseek (story_fp, 64, SEEK_SET); |
1005 | 1003 | ||
1006 | for (i = 64; i < story_size; i++) | 1004 | for (i = 64; i < story_size; i++) |
1007 | checksum += fgetc (story_fp); | 1005 | checksum += fgetc (story_fp); |
1008 | 1006 | ||
1009 | /* Branch if the checksums are equal */ | 1007 | /* Branch if the checksums are equal */ |
1010 | 1008 | ||