platform ps2, handle audio similar to psp
[picodrive.git] / pandora / menu.c
1 #include "plat.h"
2
3 static const char *men_scaler[] = { "1x1, 1x1", "2x2, 3x2", "2x2, 2x2", "fullscreen", "custom", NULL };
4 static const char h_scaler[]    = "Scalers for 40 and 32 column modes\n"
5                                   "(320 and 256 pixel wide horizontal)";
6 static const char h_cscaler[]   = "Displays the scaler layer, you can resize it\n"
7                                   "using d-pad or move it using R+d-pad";
8 static const char *men_dummy[] = { NULL };
9 char **pnd_filter_list;
10
11 static int menu_loop_cscaler(int id, int keys)
12 {
13         unsigned int inp;
14
15         currentConfig.scaling = SCALE_CUSTOM;
16
17         pnd_setup_layer(1, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
18         pnd_restore_layer_data();
19
20         for (;;)
21         {
22                 menu_draw_begin(0);
23                 memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
24                 text_out16(2, 480 - 18, "%dx%d | d-pad to resize, R+d-pad to move", g_layer_cw, g_layer_ch);
25                 menu_draw_end();
26
27                 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_R|PBTN_MOK|PBTN_MBACK, 40);
28                 if (inp & PBTN_UP)    g_layer_cy--;
29                 if (inp & PBTN_DOWN)  g_layer_cy++;
30                 if (inp & PBTN_LEFT)  g_layer_cx--;
31                 if (inp & PBTN_RIGHT) g_layer_cx++;
32                 if (!(inp & PBTN_R)) {
33                         if (inp & PBTN_UP)    g_layer_ch += 2;
34                         if (inp & PBTN_DOWN)  g_layer_ch -= 2;
35                         if (inp & PBTN_LEFT)  g_layer_cw += 2;
36                         if (inp & PBTN_RIGHT) g_layer_cw -= 2;
37                 }
38                 if (inp & (PBTN_MOK|PBTN_MBACK))
39                         break;
40
41                 if (inp & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)) {
42                         if (g_layer_cx < 0)   g_layer_cx = 0;
43                         if (g_layer_cx > 640) g_layer_cx = 640;
44                         if (g_layer_cy < 0)   g_layer_cy = 0;
45                         if (g_layer_cy > 420) g_layer_cy = 420;
46                         if (g_layer_cw < 160) g_layer_cw = 160;
47                         if (g_layer_ch < 60)  g_layer_ch = 60;
48                         if (g_layer_cx + g_layer_cw > 800)
49                                 g_layer_cw = 800 - g_layer_cx;
50                         if (g_layer_cy + g_layer_ch > 480)
51                                 g_layer_ch = 480 - g_layer_cy;
52                         pnd_setup_layer(1, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
53                 }
54         }
55
56         pnd_setup_layer(0, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
57
58         return 0;
59 }
60
61 #define MENU_OPTIONS_GFX \
62         mee_enum_h    ("Scaler",                   MA_OPT_SCALING,        currentConfig.scaling, \
63                                                                           men_scaler, h_scaler), \
64         mee_enum      ("Filter",                   MA_OPT3_FILTERING,     currentConfig.filter, men_dummy), \
65         mee_onoff     ("Vsync",                    MA_OPT2_VSYNC,         currentConfig.EmuOpt, EOPT_VSYNC), \
66         mee_cust_h    ("Setup custom scaler",      MA_NONE,               menu_loop_cscaler, NULL, h_cscaler), \
67         mee_range_hide("layer_x",                  MA_OPT3_LAYER_X,       g_layer_cx, 0, 640), \
68         mee_range_hide("layer_y",                  MA_OPT3_LAYER_Y,       g_layer_cy, 0, 420), \
69         mee_range_hide("layer_w",                  MA_OPT3_LAYER_W,       g_layer_cw, 160, 800), \
70         mee_range_hide("layer_h",                  MA_OPT3_LAYER_H,       g_layer_ch,  60, 480), \
71
72 #define MENU_OPTIONS_ADV \
73         mee_onoff     ("SVP dynarec",              MA_OPT2_SVP_DYNAREC,   PicoOpt, POPT_EN_SVP_DRC), \
74         mee_onoff     ("Status line in main menu", MA_OPT2_STATUS_LINE,   currentConfig.EmuOpt, EOPT_SHOW_RTC),
75
76 #define menu_main_plat_draw NULL
77
78 #include <dirent.h>
79 #include <errno.h>
80
81 static menu_entry e_menu_gfx_options[];
82 static menu_entry e_menu_options[];
83 static menu_entry e_menu_keyconfig[];
84
85 void pnd_menu_init(void)
86 {
87         struct dirent *ent;
88         int i, count = 0;
89         char **mfilters;
90         char buff[64], *p;
91         DIR *dir;
92
93         dir = opendir("/etc/pandora/conf/dss_fir");
94         if (dir == NULL) {
95                 perror("filter opendir");
96                 return;
97         }
98
99         while (1) {
100                 errno = 0;
101                 ent = readdir(dir);
102                 if (ent == NULL) {
103                         if (errno != 0)
104                                 perror("readdir");
105                         break;
106                 }
107                 p = strstr(ent->d_name, "_up");
108                 if (p != NULL && (p[3] == 0 || !strcmp(p + 3, "_h")))
109                         count++;
110         }
111
112         if (count == 0)
113                 return;
114
115         mfilters = calloc(count + 1, sizeof(mfilters[0]));
116         if (mfilters == NULL)
117                 return;
118
119         rewinddir(dir);
120         for (i = 0; (ent = readdir(dir)); ) {
121                 size_t len;
122
123                 p = strstr(ent->d_name, "_up");
124                 if (p == NULL || (p[3] != 0 && strcmp(p + 3, "_h")))
125                         continue;
126
127                 len = p - ent->d_name;
128                 if (len > sizeof(buff) - 1)
129                         continue;
130
131                 strncpy(buff, ent->d_name, len);
132                 buff[len] = 0;
133                 mfilters[i] = strdup(buff);
134                 if (mfilters[i] != NULL)
135                         i++;
136         }
137         closedir(dir);
138
139         i = me_id2offset(e_menu_gfx_options, MA_OPT3_FILTERING);
140         e_menu_gfx_options[i].data = (void *)mfilters;
141         pnd_filter_list = mfilters;
142
143         i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
144         e_menu_options[i].name = "Max CPU clock";
145
146         me_enable(e_menu_keyconfig, MA_CTRL_DEADZONE, 0);
147 }
148