home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / screen / m / modesel / !ModeSel_c_modes < prev    next >
Encoding:
Text File  |  1994-06-20  |  5.8 KB  |  304 lines

  1. #include "Modes.h"
  2. #include "os.h"
  3. #include "modes.h"
  4. #include "stdio.h"
  5. #include "stdlib.h"
  6. #include "hourglass.h"
  7.  
  8. #define SrtMod  0
  9. #define SrtX    1
  10. #define SrtY    2
  11. #define SrtSze  3
  12. #define SrtArea 4
  13.  
  14. typedef struct
  15. {
  16.    int   mode,
  17.          pix_x,
  18.          pix_y,
  19.          bpp,
  20.          size,
  21.          icon,
  22.          s22;
  23. } ModeInf;
  24.  
  25. static ModeInf      Modes[128];
  26. static int         ModesLoop=0;
  27. static int         totalModes;
  28. static int         Exception[128];
  29.  
  30. int percent_complete(void);
  31. int GetModeInf(int mode,int opt);
  32. int calc_area(int position);
  33.  
  34.  
  35.  
  36. void start_modes_get (bits *event_mask)
  37. {
  38.   *event_mask &= !wimp_MASK_NULL;
  39.   ModesLoop=0;
  40. }
  41.  
  42. void end_modes_get (bits *event_mask)
  43. {
  44.   *event_mask |= wimp_MASK_NULL;
  45.   ModesLoop=-1;
  46. }
  47.  
  48. bool got_modes(void)
  49. {
  50.   return(ModesLoop==-1);
  51. }
  52.  
  53. int percent_complete(void)
  54. {
  55.   return((ModesLoop*100)/128);
  56. }
  57.  
  58. void set_icon(int position, wimp_i icon)
  59. {
  60.   Modes[position].icon = icon;
  61. }
  62.  
  63. wimp_i get_icon(int position)
  64. {
  65.   return(Modes[position].icon);
  66. }
  67.  
  68. int get_bpp(int position)
  69. {
  70.   return(Modes[position].bpp);
  71. }
  72.  
  73.  
  74. int get_except(int position)
  75. {
  76.   return(Exception[position]);
  77. }
  78.  
  79. int total_modes(void)
  80. {
  81.   return(totalModes);
  82. }
  83.  
  84. int find_mode_clicked(wimp_i i)
  85. {
  86.   int Loop=0;
  87.  
  88.   while ((Loop<totalModes) && (Modes[Loop].icon != i)) Loop++;
  89.   if (Loop ==totalModes)
  90.       return(-1);
  91.   else
  92.       return (Modes[Loop].mode);
  93. }
  94.  
  95. void create_string (int position, char *str)
  96. {
  97.   sprintf(str,"%3d  %4d x %4d  %3dK",   Modes[position].mode,
  98.                                                       Modes[position].pix_x,
  99.                                                       Modes[position].pix_y,
  100.                                                       Modes[position].size);
  101. }
  102.  
  103. void get_res(int position, char* res)
  104. {
  105.   sprintf(res,"%4d x %4d",Modes[position].pix_x, Modes[position].pix_y);
  106. }
  107. bool hi_res(int position)
  108. {
  109.   return (Modes[position].s22==1);
  110. }
  111.  
  112. int get_mode_no(int position)
  113. {
  114.   return(Modes[position].mode);
  115. }
  116.  
  117. void new_except(int mode)
  118. {
  119.   int loop, total=0, insert=-1;
  120.  
  121.   while (Exception[total] != -1)
  122.   {
  123.     if (Exception[total]<=mode) insert = total;
  124.     total++;
  125.   }
  126.  
  127.   if ((Exception[insert] != mode))
  128.   {
  129.     for(loop = total; loop> insert; loop--)
  130.       Exception[loop+1] = Exception[loop];
  131.   }
  132.   Exception[insert+1] = mode;
  133. }
  134.  
  135. void remove_except(int pos)
  136. {
  137.   while (Exception[pos] != -1)
  138.   {
  139.     Exception[pos] = Exception[pos+1];
  140.     pos++;
  141.   }
  142. }
  143.  
  144. int calc_area(int position)
  145. {
  146.   if(Modes[position].s22 == 1)
  147.      return(Modes[position].pix_x * Modes[position].pix_y);
  148.   else
  149.      return(Modes[position].pix_x * (Modes[position].pix_y * 2));
  150. }
  151.  
  152. void sort_modes(int field)
  153. {
  154.    int      Loop1,Loop2;
  155.    bool     Bigger;
  156.    ModeInf  Swap;
  157.  
  158.    for(Loop1= 0; Loop1<totalModes; Loop1 ++ )
  159.    {
  160.       for(Loop2 = (Loop1+1); Loop2<totalModes; Loop2++)
  161.       {
  162.          Bigger=FALSE;
  163.          switch (field)
  164.          {
  165.          case SrtMod   :  if (Modes[Loop1].mode > Modes[Loop2].mode)
  166.                              Bigger=TRUE;
  167.                           break;
  168.          case SrtX     :  if (Modes[Loop1].pix_x>Modes[Loop2].pix_x)
  169.                              Bigger=TRUE;
  170.                           break;
  171.          case SrtY     :  if (Modes[Loop1].pix_y>Modes[Loop2].pix_y)
  172.                              Bigger=TRUE;
  173.                           break;
  174.          case SrtSze   :  if (Modes[Loop1].size>Modes[Loop2].size)
  175.                              Bigger=TRUE;
  176.                           break;
  177.          case SrtArea  :  if (calc_area(Loop1) > calc_area(Loop2))
  178.                                Bigger=TRUE;
  179.                             break;
  180.          }
  181.          if (Bigger==TRUE)
  182.          {
  183.             Swap=Modes[Loop1];
  184.             Modes[Loop1]=Modes[Loop2];
  185.             Modes[Loop2]=Swap;
  186.          }
  187.       }
  188.    }
  189. }
  190.  
  191. int GetModeInf(int mode,int opt)
  192. {
  193.    int var_val;
  194.  
  195.    os_read_mode_variable ((os_mode) mode, opt, &var_val);
  196.    return(var_val);
  197. }
  198.  
  199. bool get_modes(void)
  200. {
  201.    static int ExcepLoop=0;
  202.    int Ok,Ok2;
  203.  
  204.    if (ModesLoop==0)
  205.    {
  206.       totalModes =0;
  207.       ExcepLoop=0;
  208.    }
  209.  
  210.    if((ModesLoop<2 || ModesLoop>7)  && ModesLoop!=10)
  211.    {
  212.       if(ModesLoop != Exception[ExcepLoop])
  213.       {
  214.          os_check_mode_valid ((os_mode)  ModesLoop, &Ok,NULL);
  215.  
  216.          if (Ok!=-1)      /* mode is available */
  217.          {
  218.             Ok2 = GetModeInf(ModesLoop,0);
  219.             if ((Ok2 && 3) == 0 )   /* not a teletext or a non graphic mode */
  220.             {
  221.                Modes[totalModes].mode = ModesLoop;
  222.                Modes[totalModes].pix_x = GetModeInf(ModesLoop,11)+1;
  223.                Modes[totalModes].pix_y = GetModeInf(ModesLoop,12)+1;
  224.                Modes[totalModes].bpp=1 << GetModeInf(ModesLoop,9) ;
  225.                Modes[totalModes].size = GetModeInf(ModesLoop,7)/1024;
  226.                Modes[totalModes].s22 = GetModeInf(ModesLoop,5);
  227.                totalModes++;
  228.             }
  229.          }
  230.       }
  231.       else
  232.       {
  233.          ExcepLoop++;
  234.       }
  235.    }
  236.  
  237.    if (ModesLoop==127)
  238.    {
  239.       return(TRUE);
  240.    }
  241.    else
  242.    {
  243.       ModesLoop++;
  244.       return (FALSE);
  245.    }
  246.  
  247. }
  248.  
  249. void get_all_modes(void)
  250. {
  251.   hourglass_on ();
  252.   while(get_modes() == FALSE)
  253.   {
  254.     hourglass_percentage (percent_complete());
  255.   }
  256.   hourglass_off();
  257. }
  258.  
  259. void load_excepts(FILE *Config)
  260. {
  261.   int Loop;
  262.   int Excepts;
  263.  
  264.   fscanf(Config,"%d\n",&Excepts);
  265.    for(Loop=0; Loop<Excepts; Loop++)
  266.    {
  267.       fscanf(Config,"%d\n",&Exception[Loop]);
  268.    }
  269.    Exception[Excepts]=-1;
  270. }
  271.  
  272. void save_excepts(FILE *Config)
  273. {
  274.   int Loop;
  275.   int Excepts=0;
  276.  
  277.   while (Exception[Excepts] != -1) Excepts++;
  278.  
  279.   fprintf(Config,"%d\n",Excepts);
  280.    for(Loop=0; Loop<Excepts; Loop++)
  281.    {
  282.       fprintf(Config,"%d\n",Exception[Loop]);
  283.    }
  284. }
  285.  
  286. int sel_find_mode(int bpp, char *selStr)
  287. {
  288.   int XRes;
  289.   int YRes;
  290.   int Loop;
  291.  
  292.   XRes = atoi(selStr);
  293.   while(*selStr != 'x') selStr++;
  294.   selStr++;
  295.   YRes = atoi(selStr);
  296.  
  297.   Loop=0;
  298.   while(  (Modes[Loop].pix_x != XRes) ||
  299.         (Modes[Loop].pix_y != YRes) ||
  300.         (Modes[Loop].bpp != bpp)       )  Loop++;
  301.  
  302.   return(Modes[Loop].mode);
  303. }
  304.