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 / STATUS.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  10.7 KB  |  489 lines

  1. /* STATUS.C
  2.  *==========================================================================
  3.  * DATE:    February 2, 1990
  4.  * DATE:    March 22, 1990
  5.  *
  6.  * DESCRIPTION: Displays TOS version and date
  7.  *        Displays ST RAM and TT RAM ( Free and Total )
  8.  * 09/08/92 cjg - Use the softloaded value, not the ROM value
  9.  */
  10.  
  11.  
  12.  
  13.  
  14. /* INCLUDE FILES
  15.  *==========================================================================
  16.  */
  17. #include <sys\gemskel.h>
  18. #include <tos.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21.  
  22. #include "country.h"
  23.  
  24. #include "general.h"
  25. #include "gen2.h"
  26.  
  27. #include "super.h"
  28.  
  29.  
  30.  
  31. /* PROTOTYPES
  32.  *==========================================================================
  33.  */
  34. void do_os( void );
  35. void do_status( void );
  36. void clear_status( void );
  37. #if 0
  38. void do_memory( int Total_object, char *xtotal,
  39.                 int Free_object , char *xfree,
  40.                 int device );
  41. #endif
  42. void do_memory( int Free_object, char *xfree, int device );
  43.                 
  44. void wait_button( int flag );
  45. long *Fmalloc( long num, int item );
  46.  
  47. #if 0
  48. long Get_Total_Ram( int device );
  49. long get_total_ram( void );
  50. #endif
  51.  
  52. int  stat_button( int button, WORD *msg );
  53.  
  54. void Set_Date( char *osdate );
  55.  
  56.  
  57. /* DEFINES
  58.  *==========================================================================
  59.  */
  60. #define STRAM    0
  61. #define _MAGIC        0x1357bd13L
  62.  
  63. #define STRAM   0
  64. #define TTRAM   1
  65.  
  66.  
  67. /* EXTERNALS
  68.  *==========================================================================
  69.  */
  70.  
  71. /* GLOBALS
  72.  *==========================================================================
  73.  */
  74. int  errno;                /* errno declaration        */
  75.  
  76. int  max_stat;                /* max and min y value of status*/
  77. int  min_stat;                /* Note, these are y offsets... */
  78. char tosdate[10];            /* TOS VERSON DATE        */
  79. char tosvers[10];            /* TOS VERSION NUMBER        */
  80.  
  81. char total[10];                /* ST RAM total available       */
  82. char tfree[10];                /* ST RAM free...        */
  83. char ttotal[10];
  84. char ttfree[10];
  85. char ttblank[] = "         ";
  86. char tt_temp[ 10 ];
  87.  
  88. int blit_inc;                /* incrementer for scrolling of */
  89.                     /* the status box...        */
  90.                     /* see sl_y for implementation. */
  91. int stat_value;                /* y variable of status slider  */
  92.                     /* Note: it is an offset    */
  93.                     /* off of the current y value   */
  94. long Total_Ram;
  95. /*
  96. int  Ram_Device;
  97. */
  98.  
  99. int  OSDATE;                /* Object for cpx date (text)   */
  100.  
  101.  
  102. /* FUNCTIONS
  103.  *==========================================================================
  104.  */
  105.  
  106.  
  107. /* do_os()
  108.  *==========================================================================
  109.  */
  110. void
  111. do_os( void )
  112. {
  113.   OBJECT *ad_partz    = (OBJECT *)rs_trindex[PARTZ];
  114.   OBJECT *tree;
  115.   char *version;
  116.   char *osdate;
  117.   int j;
  118.   SYSHDR *osheader;
  119.   char  num;
  120.   
  121.   Enter_Super();
  122.   osheader = *((SYSHDR **)0x4f2L);
  123.   Exit_Super();
  124.   
  125.   /* Don't use the ROM version 09/08/92 cjg */
  126. /*  osheader = osheader->os_base;*/
  127.   version  = (char *)&osheader->os_version;
  128.   osdate   = (char *)&osheader->os_gendat;
  129.   
  130.   for(j = 0;j<=3;j += 2)
  131.   {
  132.     num = *version++;
  133.     tosvers[j] = ((num & 0xf0) >> 4) + '0';
  134.     tosvers[j+1] = (num & 0x0f) + '0';
  135.   }
  136.   ActiveTree( ad_partz );
  137.   Set_Date( osdate );
  138.   TedText( OSDATE ) = &tosdate[0];
  139.   TedText( VERSION ) = &tosvers[0];
  140. }
  141.  
  142.  
  143.  
  144.  
  145. /* do_status()
  146.  *==========================================================================
  147.  */
  148. void
  149. do_status( void )
  150. {
  151.   OBJECT *ad_tree  = (OBJECT *)rs_trindex[GENERAL];
  152.   OBJECT *ad_partz = (OBJECT *)rs_trindex[PARTZ];
  153.   OBJECT *tree;
  154.   int x,y;
  155.   long p_value;
  156.   
  157.   ActiveTree( ad_tree );
  158.   x = ObX( ROOT );
  159.   y = ObY( ROOT );
  160.   Deselect( STATUS );
  161.     
  162.   ActiveTree( ad_partz );
  163.   ObX( ROOT ) = x;
  164.   ObY( ROOT ) = y;
  165.  
  166.   HideObj( TOTALTXT );  
  167.   HideObj( FREETXT );
  168.   HideObj( TTTOTAL );
  169.   HideObj( TTFREE );
  170.   
  171.   do_os();
  172.   
  173.   Total_Ram = 0L;
  174.   
  175.   do_memory( STFREE, tfree, STRAM );
  176.  
  177.   /* Hide the TT data unless _FRB exists */  
  178.   if( (*xcpb->getcookie)( 0x5f465242L, &p_value ))
  179.   {
  180.      do_memory( TTFREE, ttfree, TTRAM );
  181.      
  182.      ShowObj( TOTALTXT );
  183.      ShowObj( FREETXT );
  184.      ShowObj( TTTOTAL );
  185.      ShowObj( TTFREE );
  186.  
  187.      ltoa( Total_Ram, tt_temp, 10 );
  188.      tt_temp[9] = '\0';
  189.      
  190.      strcpy( ttotal, ttblank );
  191.      ttotal[ 9 - ( int )strlen( tt_temp ) ] = '\0';
  192.      strcat( ttotal, tt_temp );
  193.  
  194.      ActiveTree( ad_partz );
  195.      ObString( TTTOTAL ) = ttotal;  
  196.     
  197.   }
  198.   xtree = tree;
  199.   Objc_draw( tree, ROOT, MAX_DEPTH, NULL );
  200. }
  201.  
  202.  
  203.  
  204. /* clear_status()
  205.  *==========================================================================
  206.  */
  207. void
  208. clear_status( void )
  209. {
  210.   OBJECT *ad_tree  = (OBJECT *)rs_trindex[GENERAL];
  211.   OBJECT *ad_partz = (OBJECT *)rs_trindex[PARTZ];
  212.   OBJECT *tree;
  213.   
  214.   ActiveTree( ad_partz );
  215.   Deselect( STATOK );
  216.   
  217.   ActiveTree( ad_tree );
  218.   Deselect( STATUS );
  219.   Objc_draw( ad_tree, GENERAL, MAX_DEPTH, NULL );
  220.   wait_button( UP );
  221. }
  222.  
  223.  
  224.  
  225. /* do_memory()
  226.  *==========================================================================
  227.  */
  228. #if 0 
  229. void
  230. do_memory( int Total_object, char *xtotal,
  231.            int Free_object,  char *xfree,
  232.            int ram_item  )
  233. #endif
  234. void
  235. do_memory( int Free_object, char *xfree, int ram_item )           
  236. {
  237.   OBJECT *ad_partz = (OBJECT *)rs_trindex[PARTZ];
  238.   OBJECT *tree;
  239.  
  240.   long freenum  = 0L;
  241.   long tempnum  = 0L;
  242.   
  243.   long *mptr;
  244.   long *head;
  245.   long *tptr;
  246.   long *xptr;
  247.  
  248.   head = mptr = tptr = 0L;
  249.   tempnum = ( long )Fmalloc( -1L, ram_item );
  250.   while( tempnum > 4L )
  251.   {
  252.      if( !head )
  253.      {
  254.         head  = mptr = Fmalloc( tempnum, ram_item );
  255.         *head = 0L;
  256.      }
  257.      else
  258.      {
  259.         tptr  = Fmalloc( tempnum, ram_item );
  260.         *tptr = 0L;
  261.         *mptr = ( long )tptr;
  262.         mptr  = tptr;
  263.      }
  264.      freenum += tempnum;
  265.      tempnum = ( long )Fmalloc( -1L, ram_item );       
  266.   }
  267.   
  268.  
  269.   if( head )
  270.   {  
  271.     tptr = 0L;
  272.     while( *head )
  273.     {
  274.        mptr = (long *)*head;
  275.        xptr = head;
  276.        while( mptr )
  277.        {
  278.             tptr = mptr;
  279.             mptr = ( long *)*mptr;
  280.             if( mptr )
  281.                 xptr = tptr;
  282.        }
  283.        if( tptr )
  284.        {
  285.           Mfree( tptr );
  286.           tptr  = ( long *)0L;
  287.           *xptr = 0L;
  288.        }
  289.     }
  290.     Mfree( head );
  291.   }
  292.  
  293.   ltoa( freenum, tt_temp, 10 );
  294.   tt_temp[9] = '\0';
  295.  
  296.   Total_Ram += freenum;
  297.   
  298.   strcpy( xfree, ttblank );
  299.   xfree[ 9 - ( int )strlen( tt_temp ) ] = '\0';
  300.   strcat( xfree, tt_temp );
  301.  
  302.   ActiveTree( ad_partz );
  303.   ObString( Free_object )  = xfree;
  304. }
  305.  
  306.  
  307.  
  308. long
  309. *Fmalloc( long num, int item )
  310. {
  311.      long p_value;
  312.      long _ramtop;
  313.      long _ramvalid;
  314.      long value = 0L;
  315.      
  316.      if( (*xcpb->getcookie)( 0x5f465242L, &p_value ))
  317.      {
  318.          if( item == TTRAM )
  319.          {
  320.             Enter_Super();
  321.             _ramvalid = *( long *)0x5a8;
  322.             _ramtop   = *( long *)0x5a4;
  323.             Exit_Super();   
  324.          
  325.             if( ( _ramvalid == _MAGIC ) &&
  326.                 ( _ramtop > 0x1000000L ) )
  327.             {
  328.                value= ( long )gemdos( (int)0x44, (long)num, (int)item );          
  329.             }
  330.          }
  331.          else
  332.             value = (long)gemdos((int)0x44,(long)num,(int)item);
  333.      }
  334.      else
  335.      {
  336.        if( item == STRAM )
  337.                value = ( long )Malloc( num );
  338.      }
  339.      return( (long *)value );
  340. }
  341.  
  342.  
  343. #if 0
  344. long
  345. Get_Total_Ram( int item )
  346. {
  347.     Ram_Device = item;
  348.     Supexec( get_total_ram );
  349.     return( Total_Ram );
  350. }
  351.  
  352.  
  353. long
  354. get_total_ram( void )
  355. {
  356.      long p_value;
  357.      long _ramtop;
  358.      long _ramvalid;
  359.      
  360.      Total_Ram = 0L;
  361.      if( ((*xcpb->getcookie)( 0x5f465242L, &p_value )) &&
  362.          Ram_Device == TTRAM )
  363.      {
  364.          _ramvalid = *( long *)0x5a8;
  365.          _ramtop   = *( long *)0x5a4;
  366.          
  367.          if( ( _ramvalid == _MAGIC ) &&
  368.              ( _ramtop > 0x1000000L ) )
  369.              Total_Ram = _ramtop - 0x1000000L;
  370.      }
  371.      
  372.      if( Ram_Device == STRAM )
  373.         Total_Ram = *(long *)0x42EL;
  374.      return( 0L );
  375. }
  376. #endif
  377.  
  378.  
  379.  
  380.  
  381.  
  382. int
  383. stat_button( int button, WORD *msg )
  384. {
  385.    OBJECT *tree = ( OBJECT *)rs_trindex[ PARTZ ];
  386.    int done = FALSE;
  387.    int x,y;
  388.    
  389.    switch( button )
  390.    {
  391.       case STATOK:  wait_button( UP );
  392.                   Deselect( button );
  393.                x = ObX( ROOT );
  394.                y = ObY( ROOT );
  395.                xtree = ( OBJECT *)rs_trindex[ GENERAL ];
  396.                ActiveTree( xtree );
  397.                ObX( ROOT ) = x;
  398.                ObY( ROOT ) = y;
  399.             Objc_draw( tree, ROOT, MAX_DEPTH, NULL );
  400.             break;
  401.       
  402.       default:    if( button == -1 )
  403.           {
  404.                 switch( msg[0] )
  405.                 {
  406.                   case AC_CLOSE:  done = TRUE;
  407.                           pop_data();    
  408.                           break;
  409.                                    
  410.              case WM_CLOSED: done = TRUE;
  411.                           Set_Data();
  412.                      break;
  413.                   default:
  414.                           break;
  415.                 }
  416.              }
  417.              break;
  418.    }
  419.    return( done );   
  420. }
  421.  
  422.  
  423.  
  424. void
  425. Set_Date( char *osdate )
  426. {
  427.   
  428.   OBJECT *tree = ( OBJECT *)rs_trindex[ PARTZ ];
  429.   
  430.   HideObj( DATE1 );
  431.   HideObj( DATE2 );
  432.   
  433.   #if USA    /* mm/dd/yyyy */
  434.       ShowObj( DATE1 );
  435.       OSDATE = DATE1;
  436.       tosdate[0] = (( *osdate & 0xf0 ) >> 4 ) + '0';
  437.       tosdate[1] = ( *( osdate++ ) & 0x0f ) + '0';
  438.       
  439.       tosdate[2] = (( *osdate & 0xf0 ) >> 4 ) + '0';
  440.       tosdate[3] = ( *( osdate++ ) & 0x0f ) + '0';
  441.       
  442.       tosdate[4] = (( *osdate & 0xf0 ) >> 4 ) + '0';
  443.       tosdate[5] = ( *( osdate++ ) & 0x0f ) + '0';
  444.       
  445.       tosdate[6] = (( *osdate & 0xf0 ) >> 4 ) + '0';
  446.       tosdate[7] = ( *( osdate++ ) & 0x0f ) + '0';
  447.   #endif
  448.  
  449.   #if SWEDEN
  450.       /* yyyy-mm-dd */
  451.       
  452.       ShowObj( DATE2 );
  453.       OSDATE = DATE2;
  454.       tosdate[0] = (( *( osdate + 2 ) & 0xf0 ) >> 4 ) + '0';
  455.       tosdate[1] = (  *( osdate + 2 ) & 0x0f ) + '0';
  456.       
  457.       tosdate[2] = (( *( osdate + 3 ) & 0xf0 ) >> 4 ) + '0';
  458.       tosdate[3] = (  *( osdate + 3 ) & 0x0f ) + '0';
  459.       
  460.       
  461.       tosdate[4] = (( *osdate & 0xf0 ) >> 4 ) + '0';
  462.       tosdate[5] = (  *( osdate ) & 0x0f ) + '0';
  463.       
  464.       tosdate[6] = (( *( osdate + 1 )  & 0xf0 ) >> 4 ) + '0';
  465.       tosdate[7] = (  *( osdate + 1 ) & 0x0f ) + '0';
  466.  #endif
  467.   
  468.   
  469.   #if UK | GERMAN | FRENCH | ITALY | SPAIN 
  470.       /* dd/mm/yyyy */
  471.       ShowObj( DATE1 );
  472.       OSDATE = DATE1;
  473.       tosdate[0] = (( *( osdate + 1 ) & 0xf0 ) >> 4 ) + '0';
  474.       tosdate[1] = (  *( osdate + 1 ) & 0x0f ) + '0';
  475.       
  476.       tosdate[2] = (( *osdate & 0xf0 ) >> 4 ) + '0';
  477.       tosdate[3] = (  *osdate & 0x0f ) + '0';
  478.       
  479.  
  480.       tosdate[4] = (( *( osdate + 2 ) & 0xf0 ) >> 4 ) + '0';
  481.       tosdate[5] = (  *( osdate + 2) & 0x0f ) + '0';
  482.       
  483.       tosdate[6] = (( *( osdate + 3 ) & 0xf0 ) >> 4 ) + '0';
  484.       tosdate[7] = (  *( osdate + 3 ) & 0x0f ) + '0';
  485.   #endif
  486.  
  487.   tosdate[8] = '\0';  
  488. }
  489.