pandora: tripplebuffer fbdev out, refactoring
[libpicofe.git] / gp2x / menu.c
1 #include <time.h>
2 #include "soc.h"
3
4 static void menu_main_plat_draw(void)
5 {
6         static time_t last_bat_read = 0;
7         static int last_bat_val = -1;
8         unsigned short *bp = g_screen_ptr;
9         int bat_h = me_mfont_h * 2 / 3;
10         int i, u, w, wfill, batt_val;
11         struct tm *tmp;
12         time_t ltime;
13         char time_s[16];
14
15         if (!(currentConfig.EmuOpt & EOPT_SHOW_RTC))
16                 return;
17
18         ltime = time(NULL);
19         tmp = gmtime(&ltime);
20         strftime(time_s, sizeof(time_s), "%H:%M", tmp);
21
22         text_out16(g_screen_width - me_mfont_w * 6, me_mfont_h + 2, time_s);
23
24         if (ltime - last_bat_read > 10) {
25                 last_bat_read = ltime;
26                 last_bat_val = batt_val = gp2x_read_battery();
27         }
28         else
29                 batt_val = last_bat_val;
30
31         if (batt_val < 0 || batt_val > 100)
32                 return;
33
34         /* battery info */
35         bp += (me_mfont_h * 2 + 2) * g_screen_width + g_screen_width - me_mfont_w * 3 - 3;
36         for (i = 0; i < me_mfont_w * 2; i++)
37                 bp[i] = menu_text_color;
38         for (i = 0; i < me_mfont_w * 2; i++)
39                 bp[i + g_screen_width * bat_h] = menu_text_color;
40         for (i = 0; i <= bat_h; i++)
41                 bp[i * g_screen_width] =
42                 bp[i * g_screen_width + me_mfont_w * 2] = menu_text_color;
43         for (i = 2; i < bat_h - 1; i++)
44                 bp[i * g_screen_width - 1] =
45                 bp[i * g_screen_width - 2] = menu_text_color;
46
47         w = me_mfont_w * 2 - 1;
48         wfill = batt_val * w / 100;
49         for (u = 1; u < bat_h; u++)
50                 for (i = 0; i < wfill; i++)
51                         bp[(w - i) + g_screen_width * u] = menu_text_color;
52 }
53
54 // ------------ gfx options menu ------------
55
56 static const char *mgn_opt_renderer(menu_id id, int *offs)
57 {
58         *offs = -11;
59         if (PicoOpt & POPT_ALT_RENDERER)
60                 return "     8bit fast";
61         else if (currentConfig.EmuOpt & EOPT_16BPP)
62                 return "16bit accurate";
63         else
64                 return " 8bit accurate";
65 }
66
67 static const char *mgn_opt_scaling(menu_id id, int *offs)
68 {
69         *offs = -13;
70         switch (currentConfig.scaling) {
71                 default:               return "             OFF";
72                 case EOPT_SCALE_HW_H:  return "   hw horizontal";
73                 case EOPT_SCALE_HW_HV: return "hw horiz. + vert";
74                 case EOPT_SCALE_SW_H:  return "   sw horizontal";
75         }
76 }
77
78 static const char *mgn_aopt_gamma(menu_id id, int *offs)
79 {
80         sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100);
81         return static_buff;
82 }
83
84
85 #define MENU_OPTIONS_GFX \
86         mee_range_cust("Scaling",                  MA_OPT_SCALING,        currentConfig.scaling, 0, 3, mgn_opt_scaling), \
87         mee_onoff     ("Tearing Fix",              MA_OPT_TEARING_FIX,    currentConfig.EmuOpt, EOPT_WIZ_TEAR_FIX), \
88         mee_range_cust("Gamma correction",         MA_OPT2_GAMMA,         currentConfig.gamma, 1, 300, mgn_aopt_gamma), \
89         mee_onoff     ("A_SN's gamma curve",       MA_OPT2_A_SN_GAMMA,    currentConfig.EmuOpt, EOPT_A_SN_GAMMA), \
90         mee_onoff     ("Vsync",                    MA_OPT2_VSYNC,         currentConfig.EmuOpt, EOPT_VSYNC),
91
92 #define MENU_OPTIONS_ADV \
93         mee_onoff     ("Use second CPU for sound", MA_OPT_ARM940_SOUND,   PicoOpt, POPT_EXT_FM), \
94         mee_onoff     ("RAM overclock",            MA_OPT2_RAMTIMINGS,    currentConfig.EmuOpt, EOPT_RAM_TIMINGS), \
95         mee_onoff     ("MMU hack",                 MA_OPT2_SQUIDGEHACK,   currentConfig.EmuOpt, EOPT_MMUHACK), \
96         mee_onoff     ("SVP dynarec",              MA_OPT2_SVP_DYNAREC,   PicoOpt, POPT_EN_SVP_DRC), \
97         mee_onoff     ("Status line in main menu", MA_OPT2_STATUS_LINE,   currentConfig.EmuOpt, EOPT_SHOW_RTC),
98