home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / Epoc / Palmtime / files / FrotzS5_src.ZIP / MAIN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-18  |  12.5 KB  |  461 lines

  1. /*
  2.  * main.c
  3.  *
  4.  * Frotz V2.32 main function
  5.  *
  6.  * This is an interpreter for Infocom V1 to V6 games. It also supports
  7.  * the recently defined V7 and V8 games. Please report bugs to
  8.  *
  9.  *    s.jokisch@avu.de
  10.  *
  11.  * Frotz is freeware. It may be used and distributed freely provided
  12.  * no commercial profit is involved. (c) 1995-1997 Stefan Jokisch
  13.  *
  14.  */
  15.  
  16. #include "frotz.h"
  17. #include "S5api.h"
  18.  
  19. extern void interpret (struct sg *g);
  20. extern void init_memory (struct sg *g);
  21. extern void init_undo (struct sg *g);
  22. extern void reset_memory (struct sg *g);
  23.  
  24. /*
  25.  * runtime_error
  26.  *
  27.  * An error has occured. Ignore it or pass it to os_fatal.
  28.  *
  29.  */
  30.  
  31. void runtime_error (struct sg *g, const char *s)
  32. {
  33.  
  34.     if (!g->option_ignore_errors)
  35.     { flush_buffer (g); os_fatal (g,s); }
  36.  
  37. }/* runtime_error */
  38.  
  39. /*
  40.  * z_piracy, branch if the story file is a legal copy.
  41.  *
  42.  *      no zargs used
  43.  *
  44.  */
  45.  
  46. void z_piracy (struct sg *g)
  47. {
  48.  
  49.     branch (g,!g->option_piracy);
  50.  
  51. }/* z_piracy */
  52.  
  53. /*
  54.  * main
  55.  *
  56.  * Prepare and run the game.
  57.  *
  58.  */
  59. void reset_var(struct sg *g)
  60. {
  61. int i;
  62.  
  63. g->input.pos = 0;
  64. g->input.length = 0;
  65. g->history.latest = 0;
  66. g->history.current = 0;
  67. for(i = 0; i < HISTORY_BUFSIZE; i++)
  68.   g->history.buffer[i] = 0;
  69. g->script_valid = FALSE;
  70. g->locked = FALSE;
  71. g->flag = FALSE;
  72. g->pos = 1;
  73. g->first_restart = TRUE;
  74. g->mapper[0].story_id = ZORK_ZERO;
  75. g->mapper[1].pic = 5;
  76. g->mapper[2].pic1 = 497;
  77. g->mapper[3].pic2 = 498;
  78. g->mapper[4].story_id = ZORK_ZERO;
  79. g->mapper[5].pic = 6;
  80. g->mapper[6].pic1 = 501;
  81. g->mapper[7].pic2 = 502;
  82. g->mapper[8].story_id = ZORK_ZERO;
  83. g->mapper[9].pic = 7;
  84. g->mapper[10].pic1 = 499;
  85. g->mapper[11].pic2 = 500;
  86. g->mapper[12].story_id = ZORK_ZERO;
  87. g->mapper[13].pic = 8;
  88. g->mapper[14].pic1 = 503;
  89. g->mapper[15].pic2 = 504;
  90. g->mapper[16].story_id = ARTHUR;
  91. g->mapper[17].pic = 54;
  92. g->mapper[18].pic1 = 170;
  93. g->mapper[19].pic2 = 171;
  94. g->mapper[20].story_id = SHOGUN;
  95. g->mapper[21].pic = 50;
  96. g->mapper[22].pic1 = 61;
  97. g->mapper[23].pic2 = 62;
  98. g->mapper[24].story_id = UNKNOWN;
  99. g->mapper[25].pic = 0;
  100. g->mapper[26].pic1 = 0;
  101. g->mapper[27].pic2 = 0;
  102. g->current_bg = 0;
  103. g->current_fg = 1;
  104. g->current_style = 0;
  105. g->current_font = 0;
  106. g->text_bg = 0;
  107. g->text_fg = 1;
  108. g->bg = 0;
  109. g->fg = 1;
  110. g->scrn_attr = 0;
  111. g->cursor_x = 0;
  112. g->cursor_y = 0;
  113. g->graphics_font = NULL;
  114. g->mcga_font = NULL;
  115. g->mcga_width = NULL;
  116. g->serif_font = NULL;
  117. g->serif_width = NULL;
  118. g->limit = 0;
  119. g->overwrite = FALSE;
  120. g->progname = NULL;
  121. g->display = -1;
  122. g->user_background = -1;
  123. g->user_foreground = -1;
  124. g->user_emphasis = -1;
  125. g->user_bold_typing = -1;
  126. g->user_reverse_bg = -1;
  127. g->user_reverse_fg = -1;
  128. g->user_screen_height = -1;
  129. g->user_screen_width = -1;
  130. g->user_tandy_bit = -1;
  131. g->user_random_seed = -1;
  132. g->user_font = 1;
  133. g->old_video_mode = 0;
  134. g->op0_opcodes[0] = z_rtrue;
  135. g->op0_opcodes[1] = z_rfalse;
  136. g->op0_opcodes[2] = z_print;
  137. g->op0_opcodes[3] = z_print_ret;
  138. g->op0_opcodes[4] = z_nop;
  139. g->op0_opcodes[5] = z_save;
  140. g->op0_opcodes[6] = z_restore;
  141. g->op0_opcodes[7] = z_restart;
  142. g->op0_opcodes[8] = z_ret_popped;
  143. g->op0_opcodes[9] = z_catch;
  144. g->op0_opcodes[10] = z_quit;
  145. g->op0_opcodes[11] = z_new_line;
  146. g->op0_opcodes[12] = z_show_status;
  147. g->op0_opcodes[13] = z_verify;
  148. g->op0_opcodes[14] = __extended__;
  149. g->op0_opcodes[15] = z_piracy;
  150. g->op1_opcodes[0] = z_jz;
  151. g->op1_opcodes[1] = z_get_sibling;
  152. g->op1_opcodes[2] = z_get_child;
  153. g->op1_opcodes[3] = z_get_parent;
  154. g->op1_opcodes[4] = z_get_prop_len;
  155. g->op1_opcodes[5] = z_inc;
  156. g->op1_opcodes[6] = z_dec;
  157. g->op1_opcodes[7] = z_print_addr;
  158. g->op1_opcodes[8] = z_call_s;
  159. g->op1_opcodes[9] = z_remove_obj;
  160. g->op1_opcodes[10] = z_print_obj;
  161. g->op1_opcodes[11] = z_ret;
  162. g->op1_opcodes[12] = z_jump;
  163. g->op1_opcodes[13] = z_print_paddr;
  164. g->op1_opcodes[14] = z_load;
  165. g->op1_opcodes[15] = z_call_n;
  166.  
  167. g->var_opcodes[0] = __illegal__;
  168. g->var_opcodes[1] = z_je;
  169. g->var_opcodes[2] = z_jl;
  170. g->var_opcodes[3] = z_jg;
  171. g->var_opcodes[4] = z_dec_chk;
  172. g->var_opcodes[5] = z_inc_chk;
  173. g->var_opcodes[6] = z_jin;
  174. g->var_opcodes[7] = z_test;
  175. g->var_opcodes[8] = z_or;
  176. g->var_opcodes[9] = z_and;
  177. g->var_opcodes[10] = z_test_attr;
  178. g->var_opcodes[11] = z_set_attr;
  179. g->var_opcodes[12] = z_clear_attr;
  180. g->var_opcodes[13] = z_store;
  181. g->var_opcodes[14] = z_insert_obj;
  182. g->var_opcodes[15] = z_loadw;
  183. g->var_opcodes[16] = z_loadb;
  184. g->var_opcodes[17] = z_get_prop;
  185. g->var_opcodes[18] = z_get_prop_addr;
  186. g->var_opcodes[19] = z_get_next_prop;
  187. g->var_opcodes[20] = z_add;
  188. g->var_opcodes[21] = z_sub;
  189. g->var_opcodes[22] = z_mul;
  190. g->var_opcodes[23] = z_div;
  191. g->var_opcodes[24] = z_mod;
  192. g->var_opcodes[25] = z_call_s;
  193. g->var_opcodes[26] = z_call_n;
  194. g->var_opcodes[27] = z_set_colour;
  195. g->var_opcodes[28] = z_throw;
  196. g->var_opcodes[29] = __illegal__;
  197. g->var_opcodes[30] = __illegal__;
  198. g->var_opcodes[31] = __illegal__;
  199. g->var_opcodes[32] = z_call_s;
  200. g->var_opcodes[33] = z_storew;
  201. g->var_opcodes[34] = z_storeb;
  202. g->var_opcodes[35] = z_put_prop;
  203. g->var_opcodes[36] = z_read;
  204. g->var_opcodes[37] = z_print_char;
  205. g->var_opcodes[38] = z_print_num;
  206. g->var_opcodes[39] = z_random;
  207. g->var_opcodes[40] = z_push;
  208. g->var_opcodes[41] = z_pull;
  209. g->var_opcodes[42] = z_split_window;
  210. g->var_opcodes[43] = z_set_window;
  211. g->var_opcodes[44] = z_call_s;
  212. g->var_opcodes[45] = z_erase_window;
  213. g->var_opcodes[46] = z_erase_line;
  214. g->var_opcodes[47] = z_set_cursor;
  215. g->var_opcodes[48] = z_get_cursor;
  216. g->var_opcodes[49] = z_set_text_style;
  217. g->var_opcodes[50] = z_buffer_mode;
  218. g->var_opcodes[51] = z_output_stream;
  219. g->var_opcodes[52] = z_input_stream;
  220. g->var_opcodes[53] = z_sound_effect;
  221. g->var_opcodes[54] = z_read_char;
  222. g->var_opcodes[55] = z_scan_table;
  223. g->var_opcodes[56] = z_not;
  224. g->var_opcodes[57] = z_call_n;
  225. g->var_opcodes[58] = z_call_n;
  226. g->var_opcodes[59] = z_tokenise;
  227. g->var_opcodes[60] = z_encode_text;
  228. g->var_opcodes[61] = z_copy_table;
  229. g->var_opcodes[62] = z_print_table;
  230. g->var_opcodes[63] = z_check_arg_count;
  231.  
  232. g->ext_opcodes[0] = z_save;
  233. g->ext_opcodes[1] = z_restore;
  234. g->ext_opcodes[2] = z_log_shift;
  235. g->ext_opcodes[3] = z_art_shift;
  236. g->ext_opcodes[4] = z_set_font;
  237. g->ext_opcodes[5] = z_draw_picture;
  238. g->ext_opcodes[6] = z_picture_data;
  239. g->ext_opcodes[7] = z_erase_picture;
  240. g->ext_opcodes[8] = z_set_margins;
  241. g->ext_opcodes[9] = z_save_undo;
  242. g->ext_opcodes[10] = z_restore_undo;
  243. g->ext_opcodes[11] = z_print_unicode;
  244. g->ext_opcodes[12] = z_check_unicode;
  245. g->ext_opcodes[13] = __illegal__;
  246. g->ext_opcodes[14] = __illegal__;
  247. g->ext_opcodes[15] = __illegal__;
  248. g->ext_opcodes[16] = z_move_window;
  249. g->ext_opcodes[17] = z_window_size;
  250. g->ext_opcodes[18] = z_window_style;
  251. g->ext_opcodes[19] = z_get_wind_prop;
  252. g->ext_opcodes[20] = z_scroll_window;
  253. g->ext_opcodes[21] = z_pop_stack;
  254. g->ext_opcodes[22] = z_read_mouse;
  255. g->ext_opcodes[23] = z_mouse_window;
  256. g->ext_opcodes[24] = z_push_stack;
  257. g->ext_opcodes[25] = z_put_wind_prop;
  258. g->ext_opcodes[26] = z_print_form;
  259. g->ext_opcodes[27] = z_make_menu;
  260. g->ext_opcodes[28] = z_picture_table;
  261. g->optarg = NULL;
  262. Srvstrcpy(g->script_name,DEFAULT_SCRIPT_NAME);
  263. Srvstrcpy(g->command_name,DEFAULT_COMMAND_NAME);
  264. g->records[0].story_id = SHERLOCK;
  265. g->records[0].release =  21;
  266. Srvstrcpy((char *)g->records[0].serial, "871214");
  267. g->records[1].story_id = SHERLOCK;
  268. g->records[1].release =  26;
  269. Srvstrcpy((char *)g->records[1].serial, "880127");
  270. g->records[2].story_id = BEYOND_ZORK;
  271. g->records[2].release =  47;
  272. Srvstrcpy((char *)g->records[2].serial, "870915");
  273. g->records[3].story_id = BEYOND_ZORK;
  274. g->records[3].release =  49;
  275. Srvstrcpy( (char *)g->records[3].serial, "870917");
  276. g->records[4].story_id = BEYOND_ZORK;
  277. g->records[4].release =  51;
  278. Srvstrcpy((char *)g->records[4].serial, "870923");
  279. g->records[5].story_id = BEYOND_ZORK;
  280. g->records[5].release =  57;
  281. Srvstrcpy((char *)g->records[5].serial, "871221");
  282. g->records[6].story_id = ZORK_ZERO;
  283. g->records[6].release = 296;
  284. Srvstrcpy((char *)g->records[6].serial, "881019");
  285. g->records[7].story_id = ZORK_ZERO;
  286. g->records[7].release = 366;
  287. Srvstrcpy((char *)g->records[7].serial, "890323");
  288. g->records[8].story_id = ZORK_ZERO;
  289. g->records[8].release = 383;
  290. Srvstrcpy((char *)g->records[8].serial, "890602");
  291. g->records[9].story_id = ZORK_ZERO;
  292. g->records[9].release = 393;
  293. Srvstrcpy((char *)g->records[9].serial, "890714");
  294. g->records[10].story_id = SHOGUN;
  295. g->records[10].release = 292;
  296. Srvstrcpy((char *)g->records[10].serial, "890314");
  297. g->records[11].story_id = SHOGUN;
  298. g->records[11].release = 295;
  299. Srvstrcpy((char *)g->records[11].serial, "890321");
  300. g->records[12].story_id = SHOGUN;
  301. g->records[12].release = 311;
  302. Srvstrcpy((char *)g->records[12].serial, "890510");
  303. g->records[13].story_id = SHOGUN;
  304. g->records[13].release = 322;
  305. Srvstrcpy((char *)g->records[13].serial, "890706");
  306. g->records[14].story_id = ARTHUR;
  307. g->records[14].release = 54;
  308. Srvstrcpy((char *)g->records[14].serial, "890606");
  309. g->records[15].story_id = ARTHUR;
  310. g->records[15].release = 63;
  311. Srvstrcpy((char *)g->records[15].serial, "890622");
  312. g->records[16].story_id = ARTHUR;
  313. g->records[16].release = 74;
  314. Srvstrcpy((char *)g->records[16].serial, "890714");
  315. g->records[17].story_id = JOURNEY;
  316. g->records[17].release = 26;
  317. Srvstrcpy((char *)g->records[17].serial, "890316");
  318. g->records[18].story_id = JOURNEY;
  319. g->records[18].release = 30;
  320. Srvstrcpy((char *)g->records[18].serial, "890322");
  321. g->records[19].story_id = JOURNEY;
  322. g->records[19].release = 77;
  323. Srvstrcpy((char *)g->records[19].serial, "890616");
  324. g->records[20].story_id = JOURNEY;
  325. g->records[20].release = 83;
  326. Srvstrcpy((char *)g->records[20].serial, "890706");
  327. g->records[21].story_id = LURKING_HORROR;
  328. g->records[21].release = 203;
  329. Srvstrcpy((char *)g->records[21].serial, "870506");
  330. g->records[22].story_id = LURKING_HORROR;
  331. g->records[22].release = 219;
  332. Srvstrcpy((char *)g->records[22].serial, "870912");
  333. g->records[23].story_id = LURKING_HORROR;
  334. g->records[23].release = 221;
  335. Srvstrcpy((char *)g->records[23].serial, "870918");
  336. g->records[24].story_id = UNKNOWN;
  337. g->records[24].release = 0;
  338. Srvstrcpy((char *)g->records[24].serial, "------");
  339. Srvstrcpy(g->save_name, DEFAULT_SAVE_NAME);
  340. Srvstrcpy(g->auxilary_name, DEFAULT_AUXILARY_NAME);
  341. g->story_name = 0;
  342. g->story_size = 0;
  343. g->h_version = 0;
  344. g->h_config = 0;
  345. g->h_release = 0;
  346. g->h_resident_size = 0;
  347. g->h_start_pc = 0;
  348. g->h_dictionary = 0;
  349. g->h_objects = 0;
  350. g->h_globals = 0;
  351. g->h_dynamic_size = 0;
  352. g->h_flags = 0;
  353. for(i = 0; i < 6; i++)g->h_serial[i] = 0;
  354. g->h_abbreviations = 0;
  355. g->h_file_size = 0;
  356. g->h_checksum = 0;
  357. g->h_interpreter_number = 0;
  358. g->h_interpreter_version = 0;
  359. g->h_screen_rows = 0;
  360. g->h_screen_cols = 0;
  361. g->h_screen_width = 0;
  362. g->h_screen_height = 0;
  363. g->h_font_height = 1;
  364. g->h_font_width = 1;
  365. g->h_functions_offset = 0;
  366. g->h_strings_offset = 0;
  367. g->h_default_background = 0;
  368. g->h_default_foreground = 0;
  369. g->h_terminating_keys = 0;
  370. g->h_line_width = 0;
  371. g->h_standard_high = 1;
  372. g->h_standard_low = 0;
  373. g->h_alphabet = 0;
  374. g->h_extension_table = 0;
  375. for(i = 0; i < 8; i++)g->h_user_name[i] = 0;
  376. g->hx_table_size = 0;
  377. g->hx_mouse_x = 0;
  378. g->hx_mouse_y = 0;
  379. g->hx_unicode_table = 0;
  380. g->sp = 0;
  381. g->fp = 0;
  382. g->ostream_screen = TRUE;
  383. g->ostream_script = FALSE;
  384. g->ostream_memory = FALSE;
  385. g->ostream_record = FALSE;
  386. g->istream_replay = FALSE;
  387. g->message = FALSE;
  388. g->cwin = 0;
  389. g->mwin = 0;
  390. g->mouse_y = 0;
  391. g->mouse_x = 0;
  392. g->enable_wrapping = FALSE;
  393. g->enable_scripting = FALSE;
  394. g->enable_scrolling = FALSE;
  395. g->enable_buffering = FALSE;
  396. g->option_attribute_assignment = 0;
  397. g->option_attribute_testing = 0;
  398. g->option_context_lines = 0;
  399. g->option_object_locating = 0;
  400. g->option_object_movement = 0;
  401. g->option_left_margin = 0;
  402. g->option_right_margin = 0;
  403. g->option_ignore_errors = 0;
  404. g->option_piracy = 0;
  405. g->option_undo_slots = MAX_UNDO_SLOTS;
  406. g->option_expand_abbreviations = 0;
  407. g->option_script_cols = 80;
  408. g->reserve_mem = 0;
  409. g->bufpos = 0;
  410. g->prev_c = 0;
  411. g->zmp = NULL;
  412. g->pcp = NULL;
  413. g->story_fp = NULL;
  414. g->undo_slots = 0;
  415. g->undo_count = 0;
  416. g->undo_valid = 0;
  417. g->script_width = 0;
  418. g->sfp = NULL;
  419. g->rfp = NULL;
  420. g->pfp = NULL;
  421. g->optind = 1;
  422. g->optopt = 0;
  423. g->finished = 0;
  424. g->interval = 0;
  425. g->counter = 0;
  426. g->depth = -1;
  427. g->font_height = 1;
  428. g->font_width = 1;
  429. g->input_redraw = FALSE;
  430. g->more_prompts = TRUE;
  431. g->discarding = FALSE;
  432. g->cursor = TRUE;
  433. g->input_window = 0;
  434. }
  435.  
  436.  
  437. short frotzmain (short argc, char *argv[], struct sg *g)
  438. {
  439.  
  440.     reset_var(g);
  441.  
  442.     os_process_arguments (g, argc, argv);
  443.  
  444.     init_memory (g);
  445.  
  446.     os_init_screen (g);
  447.  
  448.     init_undo (g);
  449.  
  450.     z_restart (g);
  451.  
  452.     interpret (g);
  453.  
  454.     reset_memory (g);
  455.  
  456.     os_reset_screen (g);
  457.  
  458.     return 0;
  459.  
  460. }/* main */
  461.