home *** CD-ROM | disk | FTP | other *** search
- #include "Modes.h"
- #include "os.h"
- #include "modes.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "hourglass.h"
-
- #define SrtMod 0
- #define SrtX 1
- #define SrtY 2
- #define SrtSze 3
- #define SrtArea 4
-
- typedef struct
- {
- int mode,
- pix_x,
- pix_y,
- bpp,
- size,
- icon,
- s22;
- } ModeInf;
-
- static ModeInf Modes[128];
- static int ModesLoop=0;
- static int totalModes;
- static int Exception[128];
-
- int percent_complete(void);
- int GetModeInf(int mode,int opt);
- int calc_area(int position);
-
-
-
- void start_modes_get (bits *event_mask)
- {
- *event_mask &= !wimp_MASK_NULL;
- ModesLoop=0;
- }
-
- void end_modes_get (bits *event_mask)
- {
- *event_mask |= wimp_MASK_NULL;
- ModesLoop=-1;
- }
-
- bool got_modes(void)
- {
- return(ModesLoop==-1);
- }
-
- int percent_complete(void)
- {
- return((ModesLoop*100)/128);
- }
-
- void set_icon(int position, wimp_i icon)
- {
- Modes[position].icon = icon;
- }
-
- wimp_i get_icon(int position)
- {
- return(Modes[position].icon);
- }
-
- int get_bpp(int position)
- {
- return(Modes[position].bpp);
- }
-
-
- int get_except(int position)
- {
- return(Exception[position]);
- }
-
- int total_modes(void)
- {
- return(totalModes);
- }
-
- int find_mode_clicked(wimp_i i)
- {
- int Loop=0;
-
- while ((Loop<totalModes) && (Modes[Loop].icon != i)) Loop++;
- if (Loop ==totalModes)
- return(-1);
- else
- return (Modes[Loop].mode);
- }
-
- void create_string (int position, char *str)
- {
- sprintf(str,"%3d %4d x %4d %3dK", Modes[position].mode,
- Modes[position].pix_x,
- Modes[position].pix_y,
- Modes[position].size);
- }
-
- void get_res(int position, char* res)
- {
- sprintf(res,"%4d x %4d",Modes[position].pix_x, Modes[position].pix_y);
- }
- bool hi_res(int position)
- {
- return (Modes[position].s22==1);
- }
-
- int get_mode_no(int position)
- {
- return(Modes[position].mode);
- }
-
- void new_except(int mode)
- {
- int loop, total=0, insert=-1;
-
- while (Exception[total] != -1)
- {
- if (Exception[total]<=mode) insert = total;
- total++;
- }
-
- if ((Exception[insert] != mode))
- {
- for(loop = total; loop> insert; loop--)
- Exception[loop+1] = Exception[loop];
- }
- Exception[insert+1] = mode;
- }
-
- void remove_except(int pos)
- {
- while (Exception[pos] != -1)
- {
- Exception[pos] = Exception[pos+1];
- pos++;
- }
- }
-
- int calc_area(int position)
- {
- if(Modes[position].s22 == 1)
- return(Modes[position].pix_x * Modes[position].pix_y);
- else
- return(Modes[position].pix_x * (Modes[position].pix_y * 2));
- }
-
- void sort_modes(int field)
- {
- int Loop1,Loop2;
- bool Bigger;
- ModeInf Swap;
-
- for(Loop1= 0; Loop1<totalModes; Loop1 ++ )
- {
- for(Loop2 = (Loop1+1); Loop2<totalModes; Loop2++)
- {
- Bigger=FALSE;
- switch (field)
- {
- case SrtMod : if (Modes[Loop1].mode > Modes[Loop2].mode)
- Bigger=TRUE;
- break;
- case SrtX : if (Modes[Loop1].pix_x>Modes[Loop2].pix_x)
- Bigger=TRUE;
- break;
- case SrtY : if (Modes[Loop1].pix_y>Modes[Loop2].pix_y)
- Bigger=TRUE;
- break;
- case SrtSze : if (Modes[Loop1].size>Modes[Loop2].size)
- Bigger=TRUE;
- break;
- case SrtArea : if (calc_area(Loop1) > calc_area(Loop2))
- Bigger=TRUE;
- break;
- }
- if (Bigger==TRUE)
- {
- Swap=Modes[Loop1];
- Modes[Loop1]=Modes[Loop2];
- Modes[Loop2]=Swap;
- }
- }
- }
- }
-
- int GetModeInf(int mode,int opt)
- {
- int var_val;
-
- os_read_mode_variable ((os_mode) mode, opt, &var_val);
- return(var_val);
- }
-
- bool get_modes(void)
- {
- static int ExcepLoop=0;
- int Ok,Ok2;
-
- if (ModesLoop==0)
- {
- totalModes =0;
- ExcepLoop=0;
- }
-
- if((ModesLoop<2 || ModesLoop>7) && ModesLoop!=10)
- {
- if(ModesLoop != Exception[ExcepLoop])
- {
- os_check_mode_valid ((os_mode) ModesLoop, &Ok,NULL);
-
- if (Ok!=-1) /* mode is available */
- {
- Ok2 = GetModeInf(ModesLoop,0);
- if ((Ok2 && 3) == 0 ) /* not a teletext or a non graphic mode */
- {
- Modes[totalModes].mode = ModesLoop;
- Modes[totalModes].pix_x = GetModeInf(ModesLoop,11)+1;
- Modes[totalModes].pix_y = GetModeInf(ModesLoop,12)+1;
- Modes[totalModes].bpp=1 << GetModeInf(ModesLoop,9) ;
- Modes[totalModes].size = GetModeInf(ModesLoop,7)/1024;
- Modes[totalModes].s22 = GetModeInf(ModesLoop,5);
- totalModes++;
- }
- }
- }
- else
- {
- ExcepLoop++;
- }
- }
-
- if (ModesLoop==127)
- {
- return(TRUE);
- }
- else
- {
- ModesLoop++;
- return (FALSE);
- }
-
- }
-
- void get_all_modes(void)
- {
- hourglass_on ();
- while(get_modes() == FALSE)
- {
- hourglass_percentage (percent_complete());
- }
- hourglass_off();
- }
-
- void load_excepts(FILE *Config)
- {
- int Loop;
- int Excepts;
-
- fscanf(Config,"%d\n",&Excepts);
- for(Loop=0; Loop<Excepts; Loop++)
- {
- fscanf(Config,"%d\n",&Exception[Loop]);
- }
- Exception[Excepts]=-1;
- }
-
- void save_excepts(FILE *Config)
- {
- int Loop;
- int Excepts=0;
-
- while (Exception[Excepts] != -1) Excepts++;
-
- fprintf(Config,"%d\n",Excepts);
- for(Loop=0; Loop<Excepts; Loop++)
- {
- fprintf(Config,"%d\n",Exception[Loop]);
- }
- }
-
- int sel_find_mode(int bpp, char *selStr)
- {
- int XRes;
- int YRes;
- int Loop;
-
- XRes = atoi(selStr);
- while(*selStr != 'x') selStr++;
- selStr++;
- YRes = atoi(selStr);
-
- Loop=0;
- while( (Modes[Loop].pix_x != XRes) ||
- (Modes[Loop].pix_y != YRes) ||
- (Modes[Loop].bpp != bpp) ) Loop++;
-
- return(Modes[Loop].mode);
- }
-