+\r
+\r
+// --------- CD tray close menu ----------\r
+\r
+static void draw_menu_tray(int menu_sel)\r
+{\r
+ int tl_x = 70, tl_y = 90, y;\r
+ memset(gp2x_screen, 0xe0, 320*240);\r
+\r
+ gp2x_text_out8(tl_x, 20, "The unit is about to");\r
+ gp2x_text_out8(tl_x, 30, "close the CD tray.");\r
+\r
+ y = tl_y;\r
+ gp2x_text_out8(tl_x, y, "Load new CD image");\r
+ gp2x_text_out8(tl_x, (y+=10), "Insert nothing");\r
+\r
+ // draw cursor\r
+ gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
+ // error\r
+ if (menuErrorMsg[0]) gp2x_text_out8(5, 226, menuErrorMsg);\r
+ gp2x_video_flip2();\r
+}\r
+\r
+\r
+int menu_loop_tray(void)\r
+{\r
+ int menu_sel = 0, menu_sel_max = 1;\r
+ unsigned long inp = 0;\r
+ char curr_path[PATH_MAX], *selfname;\r
+ FILE *tstf;\r
+\r
+ gp2x_memset_all_buffers(0, 0xe0, 320*240);\r
+ menu_gfx_prepare();\r
+\r
+ if ( (tstf = fopen(currentConfig.lastRomFile, "rb")) )\r
+ {\r
+ fclose(tstf);\r
+ strcpy(curr_path, currentConfig.lastRomFile);\r
+ }\r
+ else\r
+ {\r
+ getcwd(curr_path, PATH_MAX);\r
+ }\r
+\r
+ /* make sure action buttons are not pressed on entering menu */\r
+ draw_menu_tray(menu_sel);\r
+ while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);\r
+\r
+ for (;;)\r
+ {\r
+ draw_menu_tray(menu_sel);\r
+ inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B);\r
+ if(inp & GP2X_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+ if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
+ if(inp & GP2X_B ) {\r
+ switch (menu_sel) {\r
+ case 0: // select image\r
+ selfname = romsel_loop(curr_path);\r
+ if (selfname) {\r
+ int ret = -1, cd_type;\r
+ cd_type = emu_cd_check(NULL);\r
+ if (cd_type > 0)\r
+ ret = Insert_CD(romFileName, cd_type == 2);\r
+ if (ret != 0) {\r
+ sprintf(menuErrorMsg, "Load failed, invalid CD image?");\r
+ printf("%s\n", menuErrorMsg);\r
+ continue;\r
+ }\r
+ engineState = PGS_RestartRun;\r
+ return 1;\r
+ }\r
+ break;\r
+ case 1: // insert nothing\r
+ engineState = PGS_RestartRun;\r
+ return 0;\r
+ }\r
+ }\r
+ menuErrorMsg[0] = 0; // clear error msg\r
+ }\r
+}\r
+\r
+\r