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

  1. /*
  2. **    File:    print.c
  3. **
  4. **    (C)opyright 1987-1992 InfoTaskforce.
  5. */
  6.  
  7. #include    "infocom.h"
  8.  
  9. /*
  10. **    Print Routine Global Variables
  11. **
  12. **    Note:
  13. **        The variables "p_buff_ptr" and "p_buff_end" are of
  14. **        type "byte *" NOT "byte_ptr" - these definitions are
  15. **        different for MSDOS Compilers ("byte_ptr" is huge).
  16. */
  17.  
  18. byte    p_buff_strt[MAX_LINE_LENGTH] ;
  19. byte    *p_buff_ptr ;
  20. byte    *p_buff_end ;
  21.  
  22. Void
  23. init_print ()
  24. {
  25.     extern header    data_head ;
  26.     extern int        screen_width ;
  27.     extern int        linecount ;
  28.     extern boolean    enable_screen ;
  29.     extern boolean    disable_script ;
  30.     extern proc_ptr    PrintChar ;
  31.     extern boolean    windowing_enabled ;
  32.     extern word        current_window ;
  33.     extern boolean    use_buffered_io ;
  34.     extern word        top_screen_line ;
  35.  
  36.     linecount            = 0 ;
  37.     enable_screen        = TRUE ;
  38.     disable_script        = FALSE ;
  39.     PrintChar            = print_char ;
  40.     p_buff_ptr            = p_buff_strt ;
  41.     p_buff_end            = &p_buff_strt[screen_width - 1] ;
  42.     windowing_enabled    = FALSE ;
  43.     current_window        = 0 ;
  44.     use_buffered_io        = TRUE ;
  45.  
  46.     if ( data_head.z_code_version <= VERSION_3 )
  47.         top_screen_line = STD_TOP_SCREEN_LINE ;
  48.     else
  49.         top_screen_line = PLUS_TOP_SCREEN_LINE ;
  50. }
  51.  
  52. Void
  53. flush_prt_buff ()
  54. {
  55.     extern int    linecount ;
  56.  
  57.     print_buffer ( p_buff_ptr ) ;
  58.     p_buff_ptr = p_buff_strt ;
  59.     linecount = 0 ;
  60. }
  61.  
  62. Void
  63. print_num ( number )
  64. word    number ;
  65. {
  66.     extern proc_ptr    PrintChar ;
  67.     int                num ;
  68.  
  69.     if ( number == 0 )
  70.         (*PrintChar)( (word)'0' ) ;
  71.     else
  72.     {
  73.         num = (signed_word)number ;
  74.         if ( num < 0 )
  75.         {
  76.             num = -num ;
  77.             (*PrintChar)( (word)'-' ) ;
  78.         }
  79.         PrintNumber ( num ) ;
  80.     }
  81. }
  82.  
  83. Void
  84. PrintNumber ( num )
  85. int        num ;
  86. {
  87.     extern proc_ptr    PrintChar ;
  88.  
  89.     word            ch ;
  90.  
  91.     if ( num > 9 )
  92.         PrintNumber ( num / 10 ) ;
  93.     ch = '0' + ( num % 10 ) ;
  94.     (*PrintChar)( ch ) ;
  95. }
  96.  
  97. Void
  98. std_print2 ( address )
  99. word    address ;
  100. {
  101.     word    page ;
  102.     word    offset ;
  103.  
  104.     page = STD_PAGE ( address ) ;
  105.     offset = STD_OFFSET ( address ) ;
  106.     print_coded ( &page,&offset ) ;
  107. }
  108.  
  109. Void
  110. plus_print2 ( address )
  111. word    address ;
  112. {
  113.     word    page ;
  114.     word    offset ;
  115.  
  116.     page = PLUS_PAGE ( address ) ;
  117.     offset = PLUS_OFFSET ( address ) ;
  118.     print_coded ( &page,&offset ) ;
  119. }
  120.  
  121. Void
  122. print1 ( address )
  123. word    address ;
  124. {
  125.     word    page ;
  126.     word    offset ;
  127.  
  128.     page = address / BLOCK_SIZE ;
  129.     offset = address % BLOCK_SIZE ;
  130.     print_coded ( &page,&offset ) ;
  131. }
  132.  
  133. Void
  134. std_p_obj ( obj_num )
  135. word    obj_num ;
  136. {
  137.     extern std_object_ptr    std_obj_list ;
  138.  
  139.     std_object_ptr            obj ;
  140.     word                    address ;
  141.  
  142.     obj = STD_OBJ_ADDR ( obj_num ) ;
  143.     address = ((obj -> prop_ptr[0]) << 8) + (obj -> prop_ptr[1]) + 1 ;
  144.     print1 ( address ) ;
  145. }
  146.  
  147. Void
  148. plus_p_obj ( obj_num )
  149. word    obj_num ;
  150. {
  151.     extern plus_object_ptr    plus_obj_list ;
  152.  
  153.     plus_object_ptr            obj ;
  154.     word                    address ;
  155.  
  156.     obj = PLUS_OBJ_ADDR ( obj_num ) ;
  157.     address = ((obj -> prop_ptr[0]) << 8) + (obj -> prop_ptr[1]) + 1 ;
  158.     print1 ( address ) ;
  159. }
  160.  
  161. Void
  162. wrt ()
  163. {
  164.     extern word        pc_page ;
  165.     extern word        pc_offset ;
  166.  
  167.     print_coded ( &pc_page,&pc_offset ) ;
  168.     fix_pc () ;
  169. }
  170.  
  171. Void
  172. writeln ()
  173. {
  174.     wrt () ;
  175.     new_line () ;
  176.     ret_true () ;
  177. }
  178.  
  179. Void
  180. new_line ()
  181. {
  182.     *p_buff_ptr++ = '\n' ;
  183.     print_buffer ( p_buff_ptr ) ;
  184.     p_buff_ptr = p_buff_strt ;
  185. }
  186.  
  187. Void
  188. print_char ( ch )
  189. word    ch ;
  190. {
  191.     extern boolean        use_buffered_io ;
  192.     extern boolean        use_internal_buffer ;
  193.     extern byte_ptr        internal_io_ptr ;
  194.     extern word            int_io_buff_length ;
  195.  
  196.     byte                *ptr ;
  197.  
  198.     /*
  199.     **    Note:
  200.     **        The variable "ptr" is of type "byte *"
  201.     **        NOT "byte_ptr" - these definitions are
  202.     **        different for MSDOS Compilers ("byte_ptr" is huge).
  203.     */
  204.  
  205.     if ( use_internal_buffer == TRUE )
  206.     {
  207.         *internal_io_ptr++ = (byte)ch ;
  208.         ++int_io_buff_length ;
  209.         return ;
  210.     }
  211.     if ( use_buffered_io == FALSE )
  212.     {
  213.         out_char ( (char)ch ) ;
  214.         return ;
  215.     }
  216.  
  217.     if ( p_buff_ptr == p_buff_end )
  218.     {
  219.         if ( ch == (word)' ' )
  220.         {
  221.             print_buffer ( p_buff_end ) ;
  222.             out_char ( '\n' ) ;
  223.             p_buff_ptr = p_buff_strt ;
  224.             return ;
  225.         }
  226.         else
  227.         {
  228.             --p_buff_ptr ;
  229.             while ((*p_buff_ptr != (byte)' ') && (p_buff_ptr != p_buff_strt))
  230.                 --p_buff_ptr ;
  231.             if ( p_buff_ptr == p_buff_strt )
  232.             {
  233.                 print_buffer ( p_buff_end ) ;
  234.                 out_char ( '\n' ) ;
  235.             }
  236.             else
  237.             {
  238.                 print_buffer ( ++p_buff_ptr ) ;
  239.                 out_char ( '\n' ) ;
  240.                 ptr = p_buff_strt ;
  241.                 while ( p_buff_ptr != p_buff_end )
  242.                     *ptr++ = *p_buff_ptr++ ;
  243.                 p_buff_ptr = ptr ;
  244.             }
  245.         }
  246.     }
  247.     *p_buff_ptr++ = (byte)ch ;
  248. }
  249.  
  250. Void
  251. print_buffer ( buff_end )
  252. byte    *buff_end ;
  253. {
  254.     byte    *ptr = p_buff_strt ;
  255.  
  256.     /*
  257.     **    Note:
  258.     **        The parameter "buff_end" and the variable "ptr"
  259.     **        are of type "byte *" NOT "byte_ptr" - these
  260.     **        definitions are different for MSDOS Compilers ("byte_ptr" is huge).
  261.     */
  262.     
  263.     while ( ptr != buff_end )
  264.         out_char ( (char)*ptr++ ) ;
  265. }
  266.