deal with some gcc7+ warnings
[libpicofe.git] / menu.c
diff --git a/menu.c b/menu.c
index b40a5df..f32c3ce 100644 (file)
--- a/menu.c
+++ b/menu.c
 #include "plat.h"\r
 #include "posix.h"\r
 \r
+#if defined(__GNUC__) && __GNUC__ >= 7\r
+#pragma GCC diagnostic ignored "-Wformat-truncation"\r
+#endif\r
+\r
 static char static_buff[64];\r
 static int  menu_error_time = 0;\r
 char menu_error_msg[64] = { 0, };\r
@@ -33,6 +37,7 @@ void *g_menubg_ptr;
 \r
 int g_menuscreen_w;\r
 int g_menuscreen_h;\r
+int g_menuscreen_pp;\r
 \r
 int g_autostateld_opt;\r
 \r
@@ -53,11 +58,17 @@ static int g_menu_filter_off;
 static int g_border_style;\r
 static int border_left, border_right, border_top, border_bottom;\r
 \r
+void menuscreen_memset_lines(unsigned short *dst, int c, int l)\r
+{\r
+       for (; l > 0; l--, dst += g_menuscreen_pp)\r
+               memset(dst, c, g_menuscreen_w * 2);\r
+}\r
+\r
 // draws text to current bbp16 screen\r
 static void text_out16_(int x, int y, const char *text, int color)\r
 {\r
        int i, lh, tr, tg, tb, len;\r
-       unsigned short *dest = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_w;\r
+       unsigned short *dest = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_pp;\r
        tr = (color & 0xf800) >> 8;\r
        tg = (color & 0x07e0) >> 3;\r
        tb = (color & 0x001f) << 3;\r
@@ -86,7 +97,7 @@ static void text_out16_(int x, int y, const char *text, int color)
                unsigned short *dst = dest;\r
                int u, l;\r
 \r
-               for (l = 0; l < lh; l++, dst += g_menuscreen_w - me_mfont_w)\r
+               for (l = 0; l < lh; l++, dst += g_menuscreen_pp - me_mfont_w)\r
                {\r
                        for (u = me_mfont_w / 2; u > 0; u--, src++)\r
                        {\r
@@ -159,7 +170,7 @@ static void smalltext_out16_(int x, int y, const char *texto, int color)
                        break;\r
 \r
                src = fontdata6x8[c];\r
-               dst = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_w;\r
+               dst = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_pp;\r
 \r
                while (h--)\r
                {\r
@@ -174,7 +185,7 @@ static void smalltext_out16_(int x, int y, const char *texto, int color)
                                                dst += multiplier;\r
                                }\r
 \r
-                               dst += g_menuscreen_w - me_sfont_w;\r
+                               dst += g_menuscreen_pp - me_sfont_w;\r
                        }\r
                        src++;\r
                }\r
@@ -207,13 +218,13 @@ static void menu_draw_selection(int x, int y, int w)
        if (menu_sel_color < 0) return; // no selection hilight\r
 \r
        if (y > 0) y--;\r
-       dest = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_w + me_mfont_w * 2 - 2;\r
+       dest = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_pp + me_mfont_w * 2 - 2;\r
        for (h = me_mfont_h + 1; h > 0; h--)\r
        {\r
                dst = dest;\r
                for (i = w - (me_mfont_w * 2 - 2); i > 0; i--)\r
                        *dst++ = menu_sel_color;\r
-               dest += g_menuscreen_w;\r
+               dest += g_menuscreen_pp;\r
        }\r
 }\r
 \r
@@ -257,14 +268,14 @@ void menu_init_base(void)
                for (l = 0; l < 8; l++)\r
                {\r
                        unsigned char fd8x8 = fontdata8x8[c*8+l];\r
-                       if (fd8x8&0x80) *fd  = 0xf0;\r
-                       if (fd8x8&0x40) *fd |= 0x0f; fd++;\r
-                       if (fd8x8&0x20) *fd  = 0xf0;\r
-                       if (fd8x8&0x10) *fd |= 0x0f; fd++;\r
-                       if (fd8x8&0x08) *fd  = 0xf0;\r
-                       if (fd8x8&0x04) *fd |= 0x0f; fd++;\r
-                       if (fd8x8&0x02) *fd  = 0xf0;\r
-                       if (fd8x8&0x01) *fd |= 0x0f; fd++;\r
+                       if (fd8x8&0x80) { *fd  = 0xf0; }\r
+                       if (fd8x8&0x40) { *fd |= 0x0f; }; fd++;\r
+                       if (fd8x8&0x20) { *fd  = 0xf0; }\r
+                       if (fd8x8&0x10) { *fd |= 0x0f; }; fd++;\r
+                       if (fd8x8&0x08) { *fd  = 0xf0; }\r
+                       if (fd8x8&0x04) { *fd |= 0x0f; }; fd++;\r
+                       if (fd8x8&0x02) { *fd  = 0xf0; }\r
+                       if (fd8x8&0x01) { *fd |= 0x0f; }; fd++;\r
                }\r
                fd += 8*2/2; // 2 empty lines\r
        }\r
@@ -381,10 +392,10 @@ static void menu_darken_text_bg(void)
                ymax = g_menuscreen_h - 1;\r
 \r
        for (x = xmin; x <= xmax; x++)\r
-               screen[y * g_menuscreen_w + x] = 0xa514;\r
+               screen[y * g_menuscreen_pp + x] = 0xa514;\r
        for (y++; y < ymax; y++)\r
        {\r
-               ls = y * g_menuscreen_w;\r
+               ls = y * g_menuscreen_pp;\r
                screen[ls + xmin] = 0xffff;\r
                for (x = xmin + 1; x < xmax; x++)\r
                {\r
@@ -394,7 +405,7 @@ static void menu_darken_text_bg(void)
                }\r
                screen[ls + xmax] = 0xffff;\r
        }\r
-       ls = y * g_menuscreen_w;\r
+       ls = y * g_menuscreen_pp;\r
        for (x = xmin; x <= xmax; x++)\r
                screen[ls + x] = 0xffff;\r
 }\r
@@ -411,6 +422,8 @@ static void menu_reset_borders(void)
 \r
 static void menu_draw_begin(int need_bg, int no_borders)\r
 {\r
+       int y;\r
+\r
        plat_video_menu_begin();\r
 \r
        menu_reset_borders();\r
@@ -418,12 +431,14 @@ static void menu_draw_begin(int need_bg, int no_borders)
 \r
        if (need_bg) {\r
                if (g_border_style && no_borders) {\r
-                       menu_darken_bg(g_menuscreen_ptr, g_menubg_ptr,\r
-                               g_menuscreen_w * g_menuscreen_h, 1);\r
+                       for (y = 0; y < g_menuscreen_h; y++)\r
+                               menu_darken_bg((short *)g_menuscreen_ptr + g_menuscreen_pp * y,\r
+                                       (short *)g_menubg_ptr + g_menuscreen_w * y, g_menuscreen_w, 1);\r
                }\r
                else {\r
-                       memcpy(g_menuscreen_ptr, g_menubg_ptr,\r
-                               g_menuscreen_w * g_menuscreen_h * 2);\r
+                       for (y = 0; y < g_menuscreen_h; y++)\r
+                               memcpy((short *)g_menuscreen_ptr + g_menuscreen_pp * y,\r
+                                       (short *)g_menubg_ptr + g_menuscreen_w * y, g_menuscreen_w * 2);\r
                }\r
        }\r
 }\r
@@ -871,8 +886,8 @@ static void draw_dirlist(char *curdir, struct dirent **namelist,
 //     if (!rom_loaded)\r
 //             menu_darken_bg(gp2x_screen, 320*240, 0);\r
 \r
-       darken_ptr = (short *)g_menuscreen_ptr + g_menuscreen_w * max_cnt/2 * me_sfont_h;\r
-       menu_darken_bg(darken_ptr, darken_ptr, g_menuscreen_w * me_sfont_h * 8 / 10, 0);\r
+       darken_ptr = (short *)g_menuscreen_ptr + g_menuscreen_pp * max_cnt/2 * me_sfont_h;\r
+       menu_darken_bg(darken_ptr, darken_ptr, g_menuscreen_pp * me_sfont_h * 8 / 10, 0);\r
 \r
        x = 5 + me_mfont_w + 1;\r
        if (start - 2 >= 0)\r
@@ -893,9 +908,9 @@ static void draw_dirlist(char *curdir, struct dirent **namelist,
 \r
        if (show_help) {\r
                darken_ptr = (short *)g_menuscreen_ptr\r
-                       + g_menuscreen_w * (g_menuscreen_h - me_sfont_h * 5 / 2);\r
+                       + g_menuscreen_pp * (g_menuscreen_h - me_sfont_h * 5 / 2);\r
                menu_darken_bg(darken_ptr, darken_ptr,\r
-                       g_menuscreen_w * (me_sfont_h * 5 / 2), 1);\r
+                       g_menuscreen_pp * (me_sfont_h * 5 / 2), 1);\r
 \r
                snprintf(buff, sizeof(buff), "%s - select, %s - back",\r
                        in_get_key_name(-1, -PBTN_MOK), in_get_key_name(-1, -PBTN_MBACK));\r
@@ -937,7 +952,7 @@ static int scandir_filter(const struct dirent *ent)
        const char *ext;\r
        int i;\r
 \r
-       if (ent == NULL || ent->d_name == NULL)\r
+       if (ent == NULL)\r
                return 0;\r
 \r
        switch (ent->d_type) {\r
@@ -1381,7 +1396,8 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_
        y = (g_menuscreen_h - 4 * me_mfont_h) / 2 - (2 + opt_cnt) * me_mfont_h / 2;\r
        if (x < me_mfont_w * 2)\r
                x = me_mfont_w * 2;\r
-\r
+       if (y < 0)\r
+               y = 0;\r
        menu_draw_begin(1, 0);\r
        if (player_idx >= 0)\r
                text_out16(x, y, "Player %i controls", player_idx + 1);\r