1 /* Nitfol - z-machine interpreter using Glk for output.
2 Copyright (C) 1999 Evin Robertson
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 The author can be reached at nitfol@deja.com
27 if(automap_unexplore())
30 file = n_file_prompt(fileusage_SavedGame | fileusage_BinaryMode,
35 result = savequetzal(file);
37 glk_stream_close(file, NULL);
75 n_show_error(E_INSTR, "call save with bad number of operands", numoperands);
79 file = n_file_prompt(fileusage_Data | fileusage_BinaryMode,
83 length = LOBYTE(operand[2]);
85 n_show_port(E_INSTR, "save with filename > 13 characters", length);
86 for(i = 0; i < length; i++)
87 filename[i] = glk_char_to_upper(LOBYTE(operand[2] + 1 + i));
89 file = n_file_name(fileusage_Data | fileusage_BinaryMode,
90 filemode_Write, filename);
97 end = ((offset) operand[0]) + operand[1];
98 if(end > 65535 || end > total_size) {
99 n_show_error(E_MEMORY, "attempt to save data out of range", end);
104 w_glk_put_buffer_stream(file, (char *) z_memory + operand[0], operand[1]);
105 glk_stream_close(file, NULL);
111 BOOL restoregame(void)
116 if(automap_unexplore())
119 file = n_file_prompt(fileusage_SavedGame | fileusage_BinaryMode,
124 result = restorequetzal(file);
126 glk_stream_close(file, NULL);
130 z_find_size(&wid, &hei);
131 set_header(wid, hei);
138 void op_restore1(void)
146 void op_restore4(void)
155 void op_restore5(void)
162 switch(numoperands) {
167 n_show_error(E_INSTR, "call restore with bad number of operands", numoperands);
171 file = n_file_prompt(fileusage_Data | fileusage_BinaryMode,
175 length = LOBYTE(operand[2]);
177 n_show_port(E_INSTR, "save with filename > 13 characters", length);
178 for(i = 0; i < length; i++)
179 filename[i] = glk_char_to_upper(LOBYTE(operand[2] + 1 + i));
180 filename[length] = 0;
181 file = n_file_name(fileusage_Data | fileusage_BinaryMode,
182 filemode_Read, filename);
188 end = ((offset) operand[0]) + operand[1];
189 if(end > 65535 || end > dynamic_size) {
190 n_show_error(E_MEMORY, "attempt to restore data out of range", end);
195 length = glk_get_buffer_stream(file, (char *) z_memory + operand[0],
197 glk_stream_close(file, NULL);
198 mop_store_result(length);
202 void op_restart(void)
204 if(automap_unexplore())
206 z_init(current_zfile);
210 void op_save_undo(void)
220 void op_restore_undo(void)
229 if(automap_unexplore())
232 /* puts("@quit\n"); */
237 BOOL check_game_for_save(strid_t gamefile, zword release, const char serial[6],
241 unsigned char header[64];
242 glk_stream_set_position(gamefile, 0, seekmode_Start);
243 if(glk_get_buffer_stream(gamefile, (char *) header, 64) != 64)
245 if(header[HD_ZVERSION] == 0 || header[HD_ZVERSION] > 8)
247 if(MSBdecodeZ(header + HD_RELNUM) != release)
249 if(MSBdecodeZ(header + HD_CHECKSUM) != checksum)
251 for(i = 0; i < 6; i++) {
252 if(header[HD_SERNUM + i] != serial[i])