home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / Epoc / Palmtime / files / FrotzS5_src.ZIP / S5init.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-11  |  9.7 KB  |  409 lines

  1. /*
  2.  * file "S5init.c"
  3.  *
  4.  *
  5.  */
  6.  
  7. #include "frotz.h"
  8. #include "S5frotz.h"
  9. #include "S5api.h"
  10.  
  11. /*
  12. #define INFORMATION "\
  13. \n\
  14. FROTZ V2.32 - interpreter for all Infocom games. Complies with standard\n\
  15. 1.0 of Graham Nelson's specification. Written by Stefan Jokisch in 1995-7\n\
  16. \n\
  17. Syntax: frotz [options] story-file\n\
  18. \n\
  19.   -a   watch attribute setting  \t -l # left margin\n\
  20.   -A   watch attribute testing  \t -o   watch object movement\n\
  21.   -b # background colour        \t -O   watch object locating\n\
  22.   -B # reverse background colour\t -p   alter piracy opcode\n\
  23.   -c # context lines            \t -r # right margin\n\
  24.   -d # display mode (see below) \t -s # random number seed value\n\
  25.   -e # emphasis colour [mode 1] \t -S # transscript width\n\
  26.   -f # foreground colour        \t -t   set Tandy bit\n\
  27.   -F # reverse foreground colour\t -T   bold typing [modes 2+4+5]\n\
  28.   -g # font [mode 5] (see below)\t -u # slots for multiple undo\n\
  29.   -h # screen height            \t -w # screen width\n\
  30.   -i   ignore runtime errors    \t -x   expand abbreviations g/x/z\n\
  31. \n\
  32. Fonts are 0 (fixed), 1 (sans serif), 2 (comic), 3 (times), 4 (serif).\n\
  33. \n\
  34. Display modes are 0 (mono), 1 (text), 2 (CGA), 3 (MCGA), 4 (EGA), 5 (Amiga)."
  35. */
  36.  
  37. short getopt (struct sg *g, short, char *[], const char *);
  38.  
  39. /*
  40.  * dectoi
  41.  *
  42.  * Convert a string containing a decimal number to integer. The string may
  43.  * be NULL, but it must not be empty.
  44.  *
  45.  */
  46.  
  47. /* short dectoi (struct sg *g, const char *s)
  48. {
  49.     short n = 0;
  50.  
  51.     if (s != NULL)
  52.  
  53.     do {
  54.  
  55.         n = 10 * n + (*s & 15);
  56.  
  57.     } while (*++s > ' ');
  58.  
  59.     return n;
  60.  
  61. }*/ /* dectoi */
  62.  
  63. /*
  64.  * hextoi
  65.  *
  66.  * Convert a string containing a hex number to integer. The string may be
  67.  * NULL, but it must not be empty.
  68.  *
  69.  */
  70.  
  71. /* short hextoi (struct sg *g, const char *s)
  72. {
  73.     short n = 0;
  74.  
  75.     if (s != NULL)
  76.  
  77.     do {
  78.  
  79.         n = 16 * n + (*s & 15);
  80.  
  81.         if (*s > '9')
  82.         n += 9;
  83.  
  84.     } while (*++s > ' ');
  85.  
  86.     return n;
  87.  
  88. }*/ /* hextoi */
  89.  
  90. /*
  91.  * cleanup
  92.  *
  93.  * Shut down the IO interface: free memory, close files, restore
  94.  * interrupt pointers and return to the previous video mode.
  95.  *
  96.  */
  97.  
  98. void cleanup (struct sg *g)
  99. {
  100. }/* cleanup */
  101.  
  102. /*
  103.  * os_fatal
  104.  *
  105.  * Display error message and exit program.
  106.  *
  107.  */
  108.  
  109. void os_fatal (struct sg *g, const char *s)
  110. {
  111.  
  112.     if (g->h_interpreter_number)
  113.     os_reset_screen (g);
  114.  
  115.     /* Display error message */
  116.  
  117.     SrvPrintf(g," --- Fatal error: ");
  118.     SrvPrintf(g,s);
  119.     os_read_key (g, 0, TRUE);
  120.  
  121.     /* Abort program */
  122.  
  123.     SrvExit(g);
  124.  
  125. }/* os_fatal */
  126.  
  127. /*
  128.  * parse_options
  129.  *
  130.  * Parse program options and set global flags accordingly.
  131.  *
  132.  */
  133.  
  134. /*void parse_options (struct sg *g, short argc, char **argv)
  135. {
  136.     short c;
  137.  
  138.     do {
  139.  
  140.     short num = 0;
  141.  
  142.     c = getopt (g,argc, argv, "aAb:B:c:d:e:f:F:g:h:il:oOpr:s:S:tTu:w:x");
  143.  
  144.     if (g->optarg != NULL)
  145.         num = dectoi (g,g->optarg);
  146.  
  147.     if (c == 'a')
  148.         g->option_attribute_assignment = 1;
  149.     if (c == 'A')
  150.         g->option_attribute_testing = 1;
  151.     if (c == 'b')
  152.         g->user_background = num;
  153.     if (c == 'B')
  154.         g->user_reverse_bg = num;
  155.     if (c == 'c')
  156.         g->option_context_lines = num;
  157.     if (c == 'd')
  158.         g->display = g->optarg[0] | 32;
  159.     if (c == 'e')
  160.         g->user_emphasis = num;
  161.     if (c == 'T')
  162.         g->user_bold_typing = 1;
  163.     if (c == 'f')
  164.         g->user_foreground = num;
  165.     if (c == 'F')
  166.         g->user_reverse_fg = num;
  167.     if (c == 'g')
  168.         g->user_font = num;
  169.     if (c == 'h')
  170.         g->user_screen_height = num;
  171.     if (c == 'i')
  172.         g->option_ignore_errors = 1;
  173.     if (c == 'l')
  174.         g->option_left_margin = num;
  175.     if (c == 'o')
  176.         g->option_object_movement = 1;
  177.     if (c == 'O')
  178.         g->option_object_locating = 1;
  179.     if (c == 'p')
  180.         g->option_piracy = 1;
  181.     if (c == 'r')
  182.         g->option_right_margin = num;
  183.     if (c == 's')
  184.         g->user_random_seed = num;
  185.     if (c == 'S')
  186.         g->option_script_cols = num;
  187.     if (c == 't')
  188.         g->user_tandy_bit = 1;
  189.     if (c == 'u')
  190.         g->option_undo_slots = num;
  191.     if (c == 'w')
  192.         g->user_screen_width = num;
  193.     if (c == 'x')
  194.         g->option_expand_abbreviations = 1;
  195.  
  196.     } while (c != 0);
  197.  
  198. } */ /* parse_options */
  199.  
  200. /*
  201.  * os_process_arguments
  202.  *
  203.  * Handle command line switches. Some variables may be set to activate
  204.  * special features of Frotz:
  205.  *
  206.  *     option_attribute_assignment
  207.  *     option_attribute_testing
  208.  *     option_context_lines
  209.  *     option_object_locating
  210.  *     option_object_movement
  211.  *     option_left_margin
  212.  *     option_right_margin
  213.  *     option_ignore_errors
  214.  *     option_piracy
  215.  *     option_undo_slots
  216.  *     option_expand_abbreviations
  217.  *     option_script_cols
  218.  *
  219.  * The global pointer "story_name" is set to the story file name.
  220.  *
  221.  */
  222.  
  223. void os_process_arguments (struct sg *g, short argc, char *argv[])
  224. {
  225.     const char *p;
  226.     short i;
  227.  
  228.     /* Parse command line options */
  229.  
  230.     // parse_options (g,argc, argv);
  231.  
  232.     if (g->optind != argc - 1) {
  233.         return;
  234.     }
  235.  
  236.     /* Set the story file name */
  237.     SrvGetStoryName(g, &(g->story_name));//argv[g->optind];
  238.  
  239.     /* Strip path and extension off the story file name */
  240.  
  241.     p = g->story_name;
  242.  
  243.     for (i = 0; g->story_name[i] != 0; i++)
  244.     if (g->story_name[i] == '\\' || g->story_name[i] == ':')
  245.         p = g->story_name + i + 1;
  246.  
  247.     for (i = 0; p[i] != 0 && p[i] != '.' && i < 8; i++)
  248.     g->stripped_story_name[i] = p[i];
  249.  
  250.     g->stripped_story_name[i] = 0;
  251.  
  252.     /* Create nice default file names */
  253.  
  254.     Srvstrcpy (g->script_name, g->stripped_story_name);
  255.     Srvstrcpy (g->command_name, g->stripped_story_name);
  256.     Srvstrcpy (g->save_name, g->stripped_story_name);
  257.     Srvstrcpy (g->auxilary_name, g->stripped_story_name);
  258.  
  259.     Srvstrcat (g->script_name, ".scr");
  260.     Srvstrcat (g->command_name, ".rec");
  261.     Srvstrcat (g->save_name, ".sav");
  262.     Srvstrcat (g->auxilary_name, ".aux");
  263.  
  264.     /* Save the executable file name */
  265.  
  266.     g->progname = argv[0];
  267.  
  268. }/* os_process_arguments */
  269.  
  270. /*
  271.  * os_init_screen
  272.  *
  273.  * Initialise the IO interface. Prepare the screen and other devices
  274.  * (mouse, sound board). Set various OS depending story file header
  275.  * entries:
  276.  *
  277.  *     h_config (aka flags 1)
  278.  *     h_flags (aka flags 2)
  279.  *     h_screen_cols (aka screen width in characters)
  280.  *     h_screen_rows (aka screen height in lines)
  281.  *     h_screen_width
  282.  *     h_screen_height
  283.  *     h_font_height (defaults to 1)
  284.  *     h_font_width (defaults to 1)
  285.  *     h_default_foreground
  286.  *     h_default_background
  287.  *     h_interpreter_number
  288.  *     h_interpreter_version
  289.  *     h_user_name (optional; not used by any game)
  290.  *
  291.  * Finally, set reserve_mem to the amount of memory (in bytes) that
  292.  * should not be used for multiple undo and reserved for later use.
  293.  *
  294.  */
  295.  
  296. void os_init_screen (struct sg *g)
  297. {
  298.     int scrh, scrw;
  299.  
  300.     /* If the display mode has not already been set by the user then see
  301.        if this is a monochrome board. If so, set the display mode to 0.
  302.        Otherwise check the graphics flag of the story. Select a graphic
  303.        mode if it is set or if this is a V6 game. Select text mode if it
  304.        is not. */
  305.  
  306.     if (g->h_version == V3)
  307.     g->h_config |= CONFIG_SPLITSCREEN;
  308.     if (g->h_version >= V4)
  309.     g->h_config |= CONFIG_BOLDFACE;
  310.     if (g->h_version >= V4)
  311.     g->h_config |= CONFIG_EMPHASIS | CONFIG_FIXED | CONFIG_TIMEDINPUT;
  312.  
  313.     /* Handle various game flags. These flags are set if the game wants
  314.        to use certain features. The flags must be cleared if the feature
  315.        is not available. */
  316.  
  317.     if (g->h_flags & GRAPHICS_FLAG)
  318.         g->h_flags &= ~GRAPHICS_FLAG;
  319.     if (g->h_version == V3 && (g->h_flags & OLD_SOUND_FLAG))
  320.     g->h_flags &= ~OLD_SOUND_FLAG;
  321.     if (g->h_version >= V5 && (g->h_flags & UNDO_FLAG))
  322.     if (!g->option_undo_slots)
  323.         g->h_flags &= ~UNDO_FLAG;
  324.     g->h_flags &= ~COLOUR_FLAG;
  325.     g->h_flags &= ~MENU_FLAG;
  326.  
  327.     /* Set the screen dimensions, font size and default colour */
  328.     SrvScreenSize(g, &scrw, &scrh);
  329.     g->h_screen_width = scrw;
  330.     g->h_screen_height = scrh;
  331.     g->h_font_height = 1;
  332.     g->h_font_width = 1;
  333.     g->h_default_foreground = 1;
  334.     g->h_default_background = 0;
  335.  
  336.     if (g->user_screen_width != -1)
  337.     g->h_screen_width = g->user_screen_width;
  338.     if (g->user_screen_height != -1)
  339.     g->h_screen_height = g->user_screen_height;
  340.  
  341.     g->h_screen_cols = g->h_screen_width / g->h_font_width;
  342.     g->h_screen_rows = g->h_screen_height / g->h_font_height;
  343.  
  344.     /* Set the interpreter number (a constant telling the game which
  345.        operating system it runs on) and the interpreter version. The
  346.        interpreter number has effect on V6 games and "Beyond Zork". */
  347.  
  348.     g->h_interpreter_number = INTERP_PSIONS5;
  349.     g->h_interpreter_version = 'S';
  350.  
  351.  
  352. }/* os_init_screen */
  353.  
  354. /*
  355.  * os_reset_screen
  356.  *
  357.  * Reset the screen before the program stops.
  358.  *
  359.  */
  360.  
  361. void os_reset_screen (struct sg *g)
  362. {
  363.  
  364.     os_set_font (g,TEXT_FONT);
  365.     os_set_text_style (g,0);
  366.     os_display_string (g,(zchar *) "[Press any key to continue]");
  367.     os_read_key (g, 0, TRUE);
  368.  
  369.     cleanup (g);
  370.  
  371. }/* os_reset_screen */
  372.  
  373. /*
  374.  * os_restart_game
  375.  *
  376.  * This routine allows the interface to interfere with the process of
  377.  * restarting a game at various stages:
  378.  *
  379.  *     RESTART_BEGIN - restart has just begun
  380.  *     RESTART_WPROP_SET - window properties have been initialised
  381.  *     RESTART_END - restart is complete
  382.  *
  383.  */
  384.  
  385. void os_restart_game (struct sg *g, short stage)
  386. {
  387.     stage;
  388. }/* os_restart_game */
  389.  
  390. /*
  391.  * os_random_seed
  392.  *
  393.  * Return an appropriate random seed value in the range from 0 to
  394.  * 32767, possibly by using the current system time.
  395.  *
  396.  */
  397.  
  398. /*short os_random_seed (void)
  399. {
  400.  
  401.     if (user_random_seed == -1) {
  402.  
  403.     return SrvRandom();
  404.  
  405.     } else return user_random_seed;
  406.  
  407. }
  408. *//* os_random_seed */
  409.