platform ps2, handle audio similar to psp
[picodrive.git] / platform / pandora / menu.c
1 #include "plat.h"
2
3 static int min(int x, int y) { return x < y ? x : y; }
4 static int max(int x, int y) { return x > y ? x : y; }
5
6 static const char *men_scaler[] = { "1x1, 1x1", "2x2, 3x2", "2x2, 2x2", "fullscreen", "custom", NULL };
7 static const char h_scaler[]    = "Scalers for 40 and 32 column modes\n"
8                                   "(320 and 256 pixel wide horizontal)";
9 static const char h_cscaler[]   = "Displays the scaler layer, you can resize it\n"
10                                   "using d-pad or move it using R+d-pad";
11
12 static int menu_loop_cscaler(int id, int keys)
13 {
14         int was_layer_clipped = 0;
15         unsigned int inp;
16
17         currentConfig.scaling = SCALE_CUSTOM;
18
19         pnd_setup_layer(1, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
20         pnd_restore_layer_data();
21
22         menu_draw_begin(0, 1);
23         menuscreen_memset_lines(g_menuscreen_ptr, 0, g_menuscreen_h);
24         menu_draw_end();
25
26         for (;;)
27         {
28                 int top_x = max(0, -g_layer_cx * g_screen_ppitch / 800) + 1;
29                 int top_y = max(0, -g_layer_cy * g_screen_height / 480) + 1;
30                 char text[128];
31                 memcpy(g_screen_ptr, g_menubg_src_ptr,
32                         g_screen_ppitch * g_screen_height * 2);
33                 snprintf(text, sizeof(text), "%d,%d %dx%d",
34                         g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
35                 basic_text_out16_nf(g_screen_ptr, g_screen_ppitch,
36                         saved_start_col + top_x, saved_start_line + top_y, text);
37                 basic_text_out16_nf(g_screen_ptr, g_screen_ppitch, 2,
38                         g_screen_height - 20, "d-pad: resize, R+d-pad: move");
39                 plat_video_flip();
40
41                 inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT
42                                    |PBTN_R|PBTN_MOK|PBTN_MBACK, NULL, 40);
43                 if (inp & PBTN_UP)    g_layer_cy--;
44                 if (inp & PBTN_DOWN)  g_layer_cy++;
45                 if (inp & PBTN_LEFT)  g_layer_cx--;
46                 if (inp & PBTN_RIGHT) g_layer_cx++;
47                 if (!(inp & PBTN_R)) {
48                         if (inp & PBTN_UP)    g_layer_ch += 2;
49                         if (inp & PBTN_DOWN)  g_layer_ch -= 2;
50                         if (inp & PBTN_LEFT)  g_layer_cw += 2;
51                         if (inp & PBTN_RIGHT) g_layer_cw -= 2;
52                 }
53                 if (inp & (PBTN_MOK|PBTN_MBACK))
54                         break;
55
56                 if (inp & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)) {
57                         int layer_clipped = 0;
58                         g_layer_cx = max(-320, min(g_layer_cx, 640));
59                         g_layer_cy = max(-240, min(g_layer_cy, 420));
60                         g_layer_cw = max(160, g_layer_cw);
61                         g_layer_ch = max( 60, g_layer_ch);
62                         if (g_layer_cx < 0 || g_layer_cx + g_layer_cw > 800)
63                                 layer_clipped = 1;
64                         if (g_layer_cw > 800+400)
65                                 g_layer_cw = 800+400;
66                         if (g_layer_cy < 0 || g_layer_cy + g_layer_ch > 480)
67                                 layer_clipped = 1;
68                         if (g_layer_ch > 480+360)
69                                 g_layer_ch = 480+360;
70                         // resize the layer
71                         pnd_setup_layer(1, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
72                         if (layer_clipped || was_layer_clipped)
73                                 emu_video_mode_change(saved_start_line, saved_line_count,
74                                         saved_start_col, saved_col_count);
75                         was_layer_clipped = layer_clipped;
76                 }
77         }
78
79         pnd_setup_layer(0, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch);
80
81         return 0;
82 }
83
84 #define MENU_OPTIONS_GFX \
85         mee_enum_h    ("Scaler",                   MA_OPT_SCALING,        currentConfig.scaling, \
86                                                                           men_scaler, h_scaler), \
87         mee_onoff     ("Vsync",                    MA_OPT2_VSYNC,         currentConfig.EmuOpt, EOPT_VSYNC), \
88         mee_cust_s_h  ("Setup custom scaler",      MA_NONE, 0,            menu_loop_cscaler, NULL, h_cscaler), \
89         mee_range_hide("layer_x",                  MA_OPT3_LAYER_X,       g_layer_cx, -320, 640), \
90         mee_range_hide("layer_y",                  MA_OPT3_LAYER_Y,       g_layer_cy, -240, 420), \
91         mee_range_hide("layer_w",                  MA_OPT3_LAYER_W,       g_layer_cw, 160, 800), \
92         mee_range_hide("layer_h",                  MA_OPT3_LAYER_H,       g_layer_ch,  60, 480), \
93
94 #define MENU_OPTIONS_ADV
95
96 static menu_entry e_menu_gfx_options[];
97 static menu_entry e_menu_options[];
98 static menu_entry e_menu_keyconfig[];
99
100 void pnd_menu_init(void)
101 {
102         me_enable(e_menu_keyconfig, MA_CTRL_DEADZONE, 0);
103 }
104