home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / FALCON / CPX / GENERAL.TC / TTBLIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  9.6 KB  |  463 lines

  1. /* TTBLIT.C
  2.  *==========================================================================
  3.  * DATE:    March 21, 1990
  4.  * DESCRIPTION: TT and Blitter Routines
  5.  *
  6.  * 07/29/92  cjg - No Blitter and Cache Controls for Sparrow
  7.  *         - Yes  on the Speaker tho...
  8.  */
  9.  
  10.  
  11.  /* INCLUDE FILES
  12.  *==========================================================================
  13.  */ 
  14. #include <sys\gemskel.h>
  15. #include <tos.h>
  16.  
  17. #include "country.h"
  18.  
  19. #include "general.h"
  20. #include "cache.h"
  21. #include "gen2.h"
  22.  
  23. #include "text.h"
  24.  
  25.  
  26.  
  27. /* DEFINES
  28.  *==========================================================================
  29.  */
  30. #define NO_SPEED    0
  31. #define BLITTER        1
  32. #define TTCACHE        2
  33. #define BLITCACHE    3
  34.  
  35.  
  36. #define SPEED_OFF    0
  37. #define BLIT_OFF    0
  38. #define CACHE_OFF    0
  39. #define BLIT_ON        1
  40. #define CACHE_ON    2
  41. #define BLITCACHE_ON    3
  42.  
  43.  
  44.  
  45. /* PROTOTYPES
  46.  *==========================================================================
  47.  */
  48.  
  49. void    Init_Speed( void );
  50. void    Set_Speed( void );
  51. void    Get_Speed( void );
  52. void    Do_Speed( void );
  53. void    Speed_Update( void );
  54.  
  55. int    Check_Blitter( void );
  56. void    Set_Blitter( void );
  57. void    Get_Blitter( void );
  58. BOOLEAN    IsBlitter( void );
  59.  
  60. int    Check_TT_Cache( void );
  61. long    Set_TTCache( void );
  62. long    Get_TTCache( void );
  63. BOOLEAN    IsTTCache( void );
  64.  
  65. void    Get_Pop_BlitCache( int flag );
  66. int    Set_Pop_BlitCache( void );
  67.  
  68. int    IsSparrow( void );
  69.  
  70. /* EXTERNALS
  71.  *==========================================================================
  72.  */
  73.  
  74.  
  75. /* GLOBALS 
  76.  *==========================================================================
  77.  */
  78. int speed_flag = 0;            /* 0 - no blitter/ no ttcache
  79.                      * 1 - blitter/ no ttcache
  80.                      * 2 - no blitter/ ttcache
  81.                      * 3 - Blitter / 030 cache
  82.                      */
  83.  
  84. /* FUNCTIONS
  85.  *==========================================================================
  86.  */
  87.  
  88.  
  89. /*--------------------------------------------------------------------------
  90.  * Blitter and TT Cache Routines
  91.  *--------------------------------------------------------------------------
  92.  */
  93.  
  94.  
  95. /* Init_Speed() 
  96.  *==========================================================================
  97.  * Initialize Speed_Flag -     0 -  No Blitter / No TT Cache
  98.  *                   1 -  Blitter    / No TT Cache
  99.  *                   2 -  No Blitter / TT Cache
  100.  * Called to Initialize flag for the presence of Blitter or TT Cache
  101.  * Note: We can't have both.
  102.  * cur_value.BlitTTCache   ==    0 - Off
  103.  *                     1 - On
  104.  */
  105.  void
  106.  Init_Speed( void )
  107.  {
  108.     speed_flag = NO_SPEED;
  109.  
  110.     if( !IsSparrow() )
  111.        speed_flag = ( Check_Blitter() | Check_TT_Cache() );
  112.  }
  113.  
  114.  
  115.  
  116.  
  117.  
  118. /* Set_Speed()
  119.  *==========================================================================
  120.  * Set the Blitter or 030 cache
  121.  */ 
  122. void
  123. Set_Speed( void )
  124. {
  125.   Set_Blitter();
  126.   Supexec( Set_TTCache );
  127. }
  128.  
  129.  
  130.  
  131.  
  132.  
  133. /* Get_Speed()
  134.  *==========================================================================
  135.  * Get the current status of the Blitter or TT Cache
  136.  */
  137. void
  138. Get_Speed( void )
  139. {
  140.   Get_Blitter();
  141.   Supexec( Get_TTCache );
  142. }
  143.  
  144.  
  145.  
  146.  
  147. void
  148. Do_Speed( void )
  149. {
  150.    OBJECT *tree = ( OBJECT *)rs_trindex[ GENERAL ];
  151.    char **txtptr;
  152.    int  items;
  153.    int  length;
  154.    int  flag;
  155.    int  temp;
  156.    
  157.    if( speed_flag == BLITCACHE )
  158.    {
  159.       items  = 4;
  160.       length = 17;
  161.       txtptr = chip2_text;
  162.    }
  163.    else
  164.    {
  165.       items  = 2;
  166.       length = 8;
  167.       txtptr = chip1_text;
  168.    }
  169.  
  170.    temp = Set_Pop_BlitCache();
  171.    flag = Pop_Handle( BLK1BUTT, txtptr, items, &temp, IBM, length );
  172.    if( flag != -1 )
  173.    {
  174.       Get_Pop_BlitCache( flag );
  175.       Set_Blitter();
  176.       Supexec( Set_TTCache );
  177.    }
  178.    if( speed_flag == BLITCACHE )
  179.      TedText( BLK1BUTT ) = chip_button[ cur_value.BlitCache ];
  180.    else
  181.    {
  182.      if( IsTTCache() )
  183.           TedText( BLK1BUTT ) = chip1_text[ (( cur_value.BlitCache & TTCACHE )?(FALSE):(TRUE)) ];
  184.           
  185.      if( IsBlitter() )
  186.           TedText( BLK1BUTT ) = chip1_text[ (( cur_value.BlitCache & BLITTER )?(FALSE):(TRUE)) ];
  187.    }        
  188.    Objc_draw( tree, BLK1BUTT, 0, NULL );
  189. }
  190.  
  191.  
  192.  
  193. int
  194. Set_Pop_BlitCache( void )
  195. {
  196.    int state = NO_SPEED;
  197.    
  198.    Get_Speed();
  199.    if( speed_flag == BLITCACHE )
  200.        state = cur_value.BlitCache;
  201.    else
  202.    {
  203.        if( IsBlitter() )
  204.             state = !( cur_value.BlitCache & BLITTER );
  205.  
  206.        if( IsTTCache() )
  207.                state = !( cur_value.BlitCache & TTCACHE );
  208.    }
  209.    return( state );   
  210. }
  211.  
  212.  
  213.  
  214. void
  215. Get_Pop_BlitCache( int flag )
  216. {
  217.     if( speed_flag == BLITCACHE )
  218.          cur_value.BlitCache = flag;
  219.     else
  220.     {
  221.     if( IsBlitter() )
  222.     {
  223.        /* Preserve Cache field */
  224.        cur_value.BlitCache &= TTCACHE;
  225.        cur_value.BlitCache |= (( flag ) ? ( NO_SPEED ) : ( BLITTER ) );
  226.     }
  227.     
  228.     if( IsTTCache() )
  229.     {
  230.        /* Preserve Blitter field */
  231.        cur_value.BlitCache &= BLITTER;
  232.        cur_value.BlitCache |= (( flag ) ? ( NO_SPEED ) : ( TTCACHE ) );
  233.     }
  234.     }
  235. }
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242. void
  243. Speed_Update( void )
  244. {
  245.   OBJECT *tree = ( OBJECT *)rs_trindex[ GENERAL ];
  246.   
  247.   HideObj( BLK1 );
  248.   if( speed_flag )
  249.   {
  250.       ShowObj( BLK1 );
  251.       TedText( BLK1TXT ) = Chip_Title[ speed_flag ];
  252.   
  253.       if( speed_flag == BLITCACHE )
  254.          TedText( BLK1BUTT ) = chip_button[ cur_value.BlitCache ];
  255.       else
  256.       {
  257.          if( IsTTCache() )
  258.              TedText( BLK1BUTT ) = chip1_text[ (( cur_value.BlitCache & TTCACHE )?(FALSE):(TRUE)) ];
  259.          
  260.          if( IsBlitter() )
  261.              TedText( BLK1BUTT ) = chip1_text[ (( cur_value.BlitCache & BLITTER )?(FALSE):(TRUE)) ];
  262.       }         
  263.   }
  264. }
  265.  
  266.  
  267.  
  268.  
  269.  
  270. /* Check_Blitter()
  271.  *==========================================================================
  272.  * Check for the Presence of a blitter
  273.  * IN: NONE
  274.  * OUT: Return BLITTER if detected, else NO_SPEED otherwise
  275.  */ 
  276.  int
  277.  Check_Blitter( void )
  278.  {
  279.     long flag;
  280.    
  281.    flag = xbios( 0x40, -1 ); 
  282.    if( flag & 0x02L )
  283.        return( BLITTER );
  284.    else
  285.        return( NO_SPEED );
  286.  }
  287.  
  288.  
  289.  
  290. /* Set_Blitter()
  291.  *==========================================================================
  292.  * Check to see if a blitter exists
  293.  * Slam the current state of the blitter variable into the blitter
  294.  */
  295. void
  296. Set_Blitter( void )
  297. {
  298.    BOOLEAN flag;
  299.    
  300.    if( IsBlitter() )
  301.    {
  302.       flag = ( cur_value.BlitCache & BLIT_ON );
  303.       xbios( 0x40, flag );
  304.    }
  305. }
  306.  
  307.  
  308.  
  309.  
  310. /* Get_Blitter()
  311.  *==========================================================================
  312.  * Get the current status of the blitter and store it in
  313.  * cur_value.blitter
  314.  */
  315. void
  316. Get_Blitter( void )
  317. {
  318.     long flag;
  319.     int  state;
  320.     
  321.     if( IsBlitter() )
  322.     {
  323.         flag = xbios( 0x40, -1 );
  324.         state = ( ( flag & 0x01L ) ? ( BLIT_ON ) : ( BLIT_OFF ) );
  325.         /* Preserve TTCACHE bit */
  326.         cur_value.BlitCache &= TTCACHE;
  327.         cur_value.BlitCache |= state;
  328.     }    
  329. }
  330.  
  331.  
  332.  
  333. /* IsBlitter()
  334.  *==========================================================================
  335.  * Return the status of the blitter based on speed_flag
  336.  * OUT: TRUE  - Blitter Exists
  337.  *      FALSE - Blitter does not exist
  338.  */
  339. BOOLEAN
  340. IsBlitter( void )
  341. {
  342.    return( speed_flag & BLITTER );
  343. }
  344.  
  345.  
  346.  
  347.  
  348. /*--------------------------------------------------------------------------
  349.  * TT Cache Routines
  350.  *--------------------------------------------------------------------------
  351.  */
  352.  
  353.  
  354.  /* Check_TT_Cache()
  355.   *=========================================================================
  356.   * Check for the Presence of TT Cache( Actually, just an 030 
  357.   * IN: none
  358.   * OUT: Return NO_SPEED of Non Detected or
  359.   *      TTCACHE if its there
  360.   */
  361.  int
  362.  Check_TT_Cache( void )
  363.  {
  364.    long     p_value;
  365.    
  366.    if( (*xcpb->getcookie)( 0x5f435055L, &p_value ) )
  367.    {
  368.       if( p_value == 30 )        
  369.                return( TTCACHE );
  370.    }
  371.    return( NO_SPEED );
  372.  }
  373.  
  374.  
  375.  
  376. /* Set_TTCache()
  377.  *==========================================================================
  378.  * Check if we're on a 68030 (cache exists if so) and then
  379.  * slam the cache on or off depending upon the current value 
  380.  * of:             cur_value.ttcache
  381.  * NOTE: call this routine using Supexec()
  382.  */
  383. long
  384. Set_TTCache( void )
  385. {
  386.     if( IsTTCache() )
  387.     {
  388.        if( cur_value.BlitCache & CACHE_ON )
  389.              cacheon();
  390.        else
  391.              cacheoff();
  392.     }
  393.     return( 0L );
  394. }
  395.  
  396.  
  397.  
  398. /* Get_TTCache()
  399.  *==========================================================================
  400.  * Inquire the cache, if one exists, and check whether its on or off
  401.  * Store the on/off status in cur_value.ttcache
  402.  * NOTE: Call this routine using Supexec()
  403.  */
  404. long
  405. Get_TTCache( void )
  406. {
  407.    long cachevalue;
  408.    int  state;
  409.    
  410.    if( IsTTCache() )
  411.    {
  412.         cachevalue = cacheinq();
  413.         state = (( cachevalue == 0x3111L ) ? ( CACHE_ON ) : ( CACHE_OFF ) );
  414.         /* Preserve Blitter Status */
  415.         cur_value.BlitCache &= BLITTER;
  416.         cur_value.BlitCache |= state;
  417.    }
  418.    return( 0L );      
  419. }
  420.  
  421.  
  422.  
  423.  
  424. /* IsTTCache()
  425.  *==========================================================================
  426.  * Check if speed_flag is set to at least TTCACHE
  427.  * RETURN TRUE  or FALSE
  428.  */
  429. BOOLEAN
  430. IsTTCache( void )
  431. {
  432.    return( speed_flag & TTCACHE );
  433. }
  434.  
  435.  
  436. void
  437. Speed_Redraw( void )
  438. {
  439.    OBJECT *tree = ( OBJECT *)rs_trindex[ GENERAL ];
  440.    int old_value = cur_value.BlitCache;
  441.    
  442.    Get_Speed();
  443.    Speed_Update();
  444.  
  445.    if( old_value != cur_value.BlitCache )
  446.        do_redraw( tree, BLK1BUTT );
  447. }
  448.  
  449.  
  450.  
  451. int
  452. IsSparrow( void )
  453. {
  454.    long     p_value;
  455.    
  456.    if( (*xcpb->getcookie)( 0x5f4d4348L, &p_value ) )
  457.    {
  458.       p_value = p_value >> 16;
  459.       if( p_value == 3L )        /* SPARROW 0x00030000L */
  460.             return( TRUE );
  461.    }
  462.    return( FALSE );
  463. }