+// --------- 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;
+}
+
+// ------------ cheats menu ------------
+
+static void draw_cheatlist(int sel)
+{
+ int max_cnt, start, i, pos, active;
+
+ max_cnt = g_menuscreen_h / me_sfont_h;
+ start = max_cnt / 2 - sel;
+
+ menu_draw_begin(1);
+
+ for (i = 0; i < NumCheats; i++) {
+ pos = start + i;
+ if (pos < 0) continue;
+ if (pos >= max_cnt) break;
+ active = Cheats[i].Enabled;
+ smalltext_out16(14, pos * me_sfont_h,
+ active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
+ smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h,
+ Cheats[i].Descr, active ? 0xfff6 : 0xffff);
+ }
+ pos = start + i;
+ if (pos < max_cnt)
+ smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
+
+ text_out16(5, max_cnt / 2 * me_sfont_h, ">");
+ menu_draw_end();
+}
+
+static void menu_loop_cheats(void)
+{
+ static int menu_sel = 0;
+ int inp;
+
+ for (;;)
+ {
+ draw_cheatlist(menu_sel);
+ inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R
+ |PBTN_MOK|PBTN_MBACK, NULL, 33);
+ if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = NumCheats; }
+ if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > NumCheats) menu_sel = 0; }
+ if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
+ if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > NumCheats) menu_sel = NumCheats; }
+ if (inp & PBTN_MOK) { // action
+ if (menu_sel < NumCheats)
+ Cheats[menu_sel].Enabled = !Cheats[menu_sel].Enabled;
+ else break;
+ }
+ if (inp & PBTN_MBACK)
+ break;
+ }
+}
+
+// --------- main menu help ----------