+// --------- memcard manager ---------
+
+static void draw_mc_icon(int dx, int dy, const u16 *s)
+{
+ u16 *d;
+ int x, y, l, p;
+
+ d = (u16 *)g_menuscreen_ptr + g_menuscreen_w * dy + dx;
+
+ for (y = 0; y < 16; y++, s += 16) {
+ for (l = 0; l < 2; l++, d += g_menuscreen_w) {
+ for (x = 0; x < 16; x++) {
+ p = s[x];
+ d[x*2] = d[x*2 + 1] = ((p & 0x7c00) >> 10)
+ | ((p & 0x03e0) << 1) | ((p & 0x1f) << 11);
+ }
+ }
+ }
+}
+
+static void draw_mc_bg(void)
+{
+ McdBlock *blocks1, *blocks2;
+ int maxicons = 15;
+ int i, y, row2;
+
+ blocks1 = malloc(15 * sizeof(blocks1[0]));
+ blocks2 = malloc(15 * sizeof(blocks1[0]));
+ if (blocks1 == NULL || blocks2 == NULL)
+ goto out;
+
+ for (i = 0; i < 15; i++) {
+ GetMcdBlockInfo(1, i + 1, &blocks1[i]);
+ GetMcdBlockInfo(2, i + 1, &blocks2[i]);
+ }
+
+ menu_draw_begin(1);
+
+ memcpy(g_menuscreen_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
+
+ y = g_menuscreen_h / 2 - 15 * 32 / 2;
+ if (y < 0) {
+ // doesn't fit..
+ y = 0;
+ maxicons = g_menuscreen_h / 32;
+ }
+
+ row2 = g_menuscreen_w / 2;
+ for (i = 0; i < maxicons; i++) {
+ draw_mc_icon(8, y + i * 32, (u16 *)blocks1[i].Icon);
+ smalltext_out16(10+32, y + i * 32 + 8, blocks1[i].sTitle, 0xf71e);
+
+ draw_mc_icon(row2 + 8, y + i * 32, (u16 *)blocks2[i].Icon);
+ smalltext_out16(row2 + 10+32, y + i * 32 + 8, blocks2[i].sTitle, 0xf71e);
+ }
+
+ menu_darken_bg(g_menubg_ptr, g_menuscreen_ptr, g_menuscreen_w * g_menuscreen_h, 0);
+
+ menu_draw_end();
+out:
+ free(blocks1);
+ free(blocks2);
+}
+
+static void handle_memcard_sel(void)
+{
+ Config.Mcd1[0] = 0;
+ if (memcard1_sel != 0)
+ snprintf(Config.Mcd1, sizeof(Config.Mcd1), ".%s%s", MEMCARD_DIR, memcards[memcard1_sel]);
+ Config.Mcd2[0] = 0;
+ if (memcard2_sel != 0)
+ snprintf(Config.Mcd2, sizeof(Config.Mcd2), ".%s%s", MEMCARD_DIR, memcards[memcard2_sel]);
+ LoadMcds(Config.Mcd1, Config.Mcd2);
+ draw_mc_bg();
+}
+
+static menu_entry e_memcard_options[] =
+{
+ mee_enum("Memory card 1", 0, memcard1_sel, memcards),
+ mee_enum("Memory card 2", 0, memcard2_sel, memcards),
+ mee_end,
+};
+
+static int menu_loop_memcards(int id, int keys)
+{
+ static int sel = 0;
+ char *p;
+ int i;
+
+ memcard1_sel = memcard2_sel = 0;
+ p = strrchr(Config.Mcd1, '/');
+ if (p != NULL)
+ for (i = 0; memcards[i] != NULL; i++)
+ if (strcmp(p + 1, memcards[i]) == 0)
+ { memcard1_sel = i; break; }
+ p = strrchr(Config.Mcd2, '/');
+ if (p != NULL)
+ for (i = 0; memcards[i] != NULL; i++)
+ if (strcmp(p + 1, memcards[i]) == 0)
+ { memcard2_sel = i; break; }
+
+ me_loop_d(e_memcard_options, &sel, handle_memcard_sel, NULL);
+
+ memcpy(g_menubg_ptr, g_menubg_src_ptr, g_menuscreen_w * g_menuscreen_h * 2);
+
+ return 0;
+}
+
+// --------- main menu help ----------