home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GAMES / infocom_src.lha / init.c < prev    next >
Text File  |  1993-03-03  |  8KB  |  282 lines

  1. /*
  2. **    File:    init.c
  3. **
  4. **    (C)opyright 1987-1992 InfoTaskforce.
  5. */
  6.  
  7. #include    "infocom.h"
  8.  
  9. Void
  10. init ()
  11. {
  12.     extern word                resident_blocks ;
  13.     extern word                save_blocks ;
  14.     extern header            data_head ;
  15.     extern boolean            pre_load ;
  16.     extern boolean            stop ;
  17.     extern std_object_ptr    std_obj_list ;
  18.     extern plus_object_ptr    plus_obj_list ;
  19.     extern byte_ptr            base_ptr ;
  20.     extern byte_ptr            global_ptr ;
  21.     extern byte_ptr            common_word_ptr ;
  22.  
  23.     word                    max_blocks ;
  24.     word                    blocks_allocated ;
  25.     byte_ptr                ptr ;
  26.  
  27.     /*
  28.     **    Initialise the Game Global Variables.
  29.     */
  30.  
  31.     read_header ( &data_head ) ;
  32.     if ( stop == TRUE )
  33.         return ;
  34.     resident_blocks = data_head.resident_bytes / BLOCK_SIZE ;
  35.     if ( data_head.resident_bytes % BLOCK_SIZE )
  36.         ++resident_blocks ;
  37.  
  38.     switch ( data_head.z_code_version )
  39.     {
  40.         case VERSION_1:
  41.         case VERSION_2:
  42.                         max_blocks = STD_PAGE ( MAX_BYTES ) ;
  43.                         break ;
  44.         case VERSION_3:
  45.                         max_blocks = STD_PAGE ( data_head.verify_length ) ;
  46.                         if ( STD_OFFSET ( data_head.verify_length ) != 0 )
  47.                             ++max_blocks ;
  48.                         break ;
  49.         case VERSION_4:
  50.         case VERSION_5:
  51.         default:
  52.                         max_blocks = PLUS_PAGE ( data_head.verify_length ) ;
  53.                         if ( PLUS_OFFSET ( data_head.verify_length ) != 0 )
  54.                             ++max_blocks ;
  55.                         break ;
  56.     }
  57.  
  58.     if ((word)( blocks_allocated = allocate (max_blocks + 2)) < (word)(resident_blocks + 2))
  59.     {
  60.         /*
  61.         **    There must be enough room for the resident blocks and at
  62.         **    least two pages ( a program page being referenced by the
  63.         **    program counter and a data page ).
  64.         */
  65.         
  66.         error ( ERR_MEMORY ) ;
  67.         display ( "Not enough memory." ) ;
  68.     }
  69.     else
  70.     {
  71.         /*
  72.         **    Define Globals
  73.         */
  74.  
  75.         if (( pre_load == TRUE ) && ( blocks_allocated == ( max_blocks + 2 )))
  76.             resident_blocks = max_blocks ;
  77.         load_page ( 0,resident_blocks,base_ptr ) ;
  78.         save_blocks = data_head.save_bytes / BLOCK_SIZE ;
  79.         if ( data_head.save_bytes % BLOCK_SIZE )
  80.             ++ save_blocks ;
  81.         std_obj_list = (std_object_ptr)( base_ptr + data_head.object_list ) ;
  82.         plus_obj_list = (plus_object_ptr)( base_ptr + data_head.object_list ) ;
  83.         global_ptr = base_ptr + data_head.globals ;
  84.         common_word_ptr = base_ptr + data_head.common_word ;
  85.  
  86.  
  87.         /*
  88.         **    Initialise Page Table.
  89.         */
  90.  
  91.         ptr = base_ptr + ( (long_word)resident_blocks * BLOCK_SIZE ) ;
  92.         init_page ( ptr,( blocks_allocated - resident_blocks ) ) ;
  93.         init_input ( data_head.vocab ) ;
  94.         init_message ( data_head.z_code_version ) ;
  95.         init_opcodes ( data_head.z_code_version ) ;
  96.         seed_random () ;
  97.     }
  98. }
  99.  
  100. /*
  101. **    Opcode Initilaisation Routines
  102. */
  103.  
  104. #define        gosub3        plus_gosub
  105. #define        null2        null
  106. #define        null3        null
  107. #define        not2        not
  108. #define        new_opcode0    null
  109.  
  110. Void
  111. new_opcode1 ()
  112. {
  113.     store ( (word)0 ) ;
  114. }
  115.  
  116. Void
  117. init_opcodes ( version )
  118. byte    version ;
  119. {
  120.     extern boolean    enhanced ;
  121.     extern proc_ptr    jmp_op0[] ;
  122.     extern proc_ptr    jmp_op1[] ;
  123.     extern proc_ptr    jmp_op2[] ;
  124.     extern int        operands[] ;
  125.  
  126.     if ( version == VERSION_3 )
  127.     {
  128.         jmp_op0[0x0C] = prt_status ;
  129.         jmp_op0[0x0D] = verify ;
  130.         if ( enhanced )
  131.         {
  132.             /*
  133.             **    In the Standard Series Executor, two extra opcodes can
  134.             **    be enabled for screen formatting. Some machines may not
  135.             **    be able to support these extra commands ( opcodes $EA &
  136.             **    $EB - corresponding to entries "split_screen" ($2A) &
  137.             **    "set_current_screen" ($2B) in the array "(*jmp_op2[])()" ).
  138.             */
  139.  
  140.             jmp_op2[0x2A] = split_screen ;
  141.             jmp_op2[0x2B] = set_current_window ;
  142.  
  143.             /* Level 1 patch installed  -mlk */
  144.             operands[0x2A] = 1 ;    /* split_screen    */
  145.             operands[0x2B] = 1 ;    /* set_current_window    */
  146.  
  147.         }
  148.     }
  149.  
  150.     if (( version == VERSION_4 ) || ( version == VERSION_5 ))
  151.     {
  152.         enhanced = TRUE ;
  153.  
  154.         /*
  155.         **    Enhancements for existing Opcodes.
  156.         */
  157.  
  158.         jmp_op1[0x01] = plus_get_link ;
  159.         jmp_op1[0x02] = plus_get_holds ;
  160.         jmp_op1[0x03] = plus_get_loc ;
  161.         jmp_op1[0x04] = plus_get_p_len ;
  162.         jmp_op1[0x09] = plus_remove_obj ;
  163.         jmp_op1[0x0A] = plus_p_obj ;
  164.         jmp_op1[0x0D] = plus_print2 ;
  165.         jmp_op2[0x06] = plus_check_loc ;
  166.         jmp_op2[0x0A] = plus_test_attr ;
  167.         jmp_op2[0x0B] = plus_set_attr ;
  168.         jmp_op2[0x0C] = plus_clr_attr ;
  169.         jmp_op2[0x0E] = plus_transfer ;
  170.         jmp_op2[0x11] = plus_getprop ;
  171.         jmp_op2[0x12] = plus_get_prop_addr ;
  172.         jmp_op2[0x13] = plus_get_next_prop ;
  173.         jmp_op2[0x20] = plus_gosub ;
  174.         jmp_op2[0x23] = plus_put_prop ;
  175.         jmp_op2[0x27] = plus_random ;
  176.  
  177.         /*
  178.         **    New Opcodes.
  179.         */
  180.  
  181.         jmp_op0[0x0D] = verify ;
  182.         jmp_op1[0x08] = gosub2 ;
  183.         jmp_op2[0x19] = gosub3 ;
  184.         jmp_op2[0x2A] = split_screen ;
  185.         jmp_op2[0x2B] = set_current_window ;
  186.         jmp_op2[0x2C] = gosub3 ;
  187.         jmp_op2[0x2D] = do_clear_screen ;
  188.         jmp_op2[0x2E] = erase_line ;
  189.         jmp_op2[0x2F] = set_cursor_posn ;
  190.         jmp_op2[0x30] = null2 ;
  191.         jmp_op2[0x31] = set_text_mode ;
  192.         jmp_op2[0x32] = io_buffer_mode ;
  193.         jmp_op2[0x33] = io_mode ;
  194.         jmp_op2[0x34] = null3 ;
  195.         jmp_op2[0x35] = do_beep ;
  196.         jmp_op2[0x36] = get_key ;
  197.         jmp_op2[0x37] = plus_compare2 ;
  198.         operands[0x19] = 0 ;            /* gosub3                 */
  199.         operands[0x2A] = 1 ;            /* split_screen           */
  200.         operands[0x2B] = 1 ;            /* set_current_window     */
  201.         operands[0x2C] = 0 ;            /* gosub3                 */
  202.         operands[0x2D] = 1 ;            /* do_clear_screen           */
  203.         operands[0x2E] = 1 ;            /* erase_line             */
  204.         operands[0x2F] = 0 ;            /* set_cursor_posn        */
  205.         operands[0x30] = 0 ;            /* null2                  */
  206.         operands[0x31] = 1 ;            /* set_text_mode          */
  207.         operands[0x32] = 1 ;            /* io_buffer_mode         */
  208.         operands[0x33] = 0 ;            /* io_mode                */
  209.         operands[0x34] = 0 ;            /* null3                  */
  210.         operands[0x35] = 1 ;            /* do_beep                   */
  211.         operands[0x36] = 0 ;            /* get_key                */
  212.         operands[0x37] = 0 ;            /* plus_compare2          */
  213.  
  214.         if ( version == VERSION_5 )
  215.         {
  216.             /*
  217.             **    Enhancements for existing Opcodes.
  218.             */
  219.  
  220.             jmp_op0[0x05] = illegal_opcode ;
  221.             jmp_op0[0x06] = illegal_opcode ;
  222.             jmp_op0[0x09] = adv_pop_stack ;
  223.             jmp_op0[0x0F] = branch_true ;
  224.             jmp_op1[0x0B] = adv_rtn ;
  225.             jmp_op1[0x0F] = gosub5 ;
  226.             jmp_op2[0x19] = adv_gosub ;
  227.             jmp_op2[0x20] = adv_gosub ;
  228.             jmp_op2[0x2C] = adv_gosub ;
  229.             jmp_op2[0x37] = adv_compare2 ;
  230.  
  231.             /*
  232.             **    New Opcodes.
  233.             */
  234.  
  235.             jmp_op2[0x1A] = gosub4 ;
  236.             jmp_op2[0x1B] = new_opcode0 ;
  237.             jmp_op2[0x1C] = throw_away_stack_frame ;
  238.             jmp_op2[0x38] = not2 ;
  239.             jmp_op2[0x39] = gosub4 ;
  240.             jmp_op2[0x3A] = gosub4 ;
  241.             jmp_op2[0x3B] = parse ;
  242.             jmp_op2[0x3C] = encrypt ;
  243.             jmp_op2[0x3D] = block_copy ;
  244.             jmp_op2[0x3E] = print_text ;
  245.             jmp_op2[0x3F] = num_local_params ;
  246.             jmp_op2[0x40] = save_game ;
  247.             jmp_op2[0x41] = restore_game ;
  248.             jmp_op2[0x42] = logical_shift ;
  249.             jmp_op2[0x43] = arithmetic_shift ;
  250.             jmp_op2[0x44] = new_opcode1 ;
  251.             jmp_op2[0x45] = clear_flag ;
  252.             jmp_op2[0x46] = test_byte_array ;
  253.             jmp_op2[0x47] = set_flag ;
  254.             jmp_op2[0x48] = new_opcode0 ;
  255.             jmp_op2[0x49] = new_opcode1 ;
  256.             jmp_op2[0x4A] = new_opcode1 ;
  257.             operands[0x1A] = 0 ;        /* gosub4                 */
  258.             operands[0x1B] = 2 ;        /* new_opcode0            */
  259.             operands[0x1C] = 2 ;        /* throw_away_stack_frame */
  260.             operands[0x38] = 1 ;        /* not2                   */
  261.             operands[0x39] = 0 ;        /* gosub4                 */
  262.             operands[0x3A] = 0 ;        /* gosub4                 */
  263.             operands[0x3B] = 0 ;        /* parse                  */
  264.             operands[0x3C] = 4 ;        /* encrypt                */
  265.             operands[0x3D] = 0 ;        /* block_copy             */
  266.             operands[0x3E] = 0 ;        /* print_text             */
  267.             operands[0x3F] = 1 ;        /* num_local_params       */
  268.             operands[0x40] = 0 ;        /* save_game              */
  269.             operands[0x41] = 0 ;        /* restore_game           */
  270.             operands[0x42] = 2 ;        /* logical_shift          */
  271.             operands[0x43] = 2 ;        /* arithmetic_shift       */
  272.             operands[0x44] = 1 ;        /* new_opcode1            */
  273.             operands[0x45] = 0 ;        /* clear_flag             */
  274.             operands[0x46] = 2 ;        /* test_byte_array        */
  275.             operands[0x47] = 0 ;        /* set_flag               */
  276.             operands[0x48] = 2 ;        /* new_opcode0            */
  277.             operands[0x49] = 2 ;        /* new_opcode1            */
  278.             operands[0x4A] = 0 ;        /* new_opcode1            */
  279.         }
  280.     }
  281. }
  282.