menu_pico.c 85 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664
  1. /*
  2. * PicoDrive
  3. * (C) notaz, 2010,2011
  4. *
  5. * This work is licensed under the terms of MAME license.
  6. * See COPYING file in the top-level directory.
  7. */
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <time.h>
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <SDL/SDL_ttf.h>
  14. #include <SDL/SDL_image.h>
  15. #include "emu.h"
  16. #include "configfile_fk.h"
  17. #include "menu_pico.h"
  18. #include "input_pico.h"
  19. #include "../libpicofe/input.h"
  20. #include "version.h"
  21. #include <pico/pico_int.h>
  22. #include <pico/patch.h>
  23. #ifdef PANDORA
  24. #define MENU_X2 1
  25. #else
  26. #define MENU_X2 0
  27. #endif
  28. #if defined USE_BGR555
  29. #define COL_ROM 0x5eff
  30. #define COL_OTH 0x5ff5
  31. #elif defined USE_BGR565
  32. #define COL_ROM 0xfdf7
  33. #define COL_OTH 0xaff5
  34. #else
  35. #define COL_ROM 0xbdff
  36. #define COL_OTH 0xaff5
  37. #endif
  38. // FIXME
  39. #define REVISION "0"
  40. static const char *rom_exts[] = {
  41. "zip",
  42. "bin", "smd", "gen", "md",
  43. "iso", "cso", "cue", "chd",
  44. "32x",
  45. "sms",
  46. NULL
  47. };
  48. // rrrr rggg gggb bbbb
  49. static unsigned short fname2color(const char *fname)
  50. {
  51. static const char *other_exts[] = { "gmv", "pat" };
  52. const char *ext;
  53. int i;
  54. ext = strrchr(fname, '.');
  55. if (ext++ == NULL) {
  56. ext = fname + strlen(fname) - 3;
  57. if (ext < fname) ext = fname;
  58. }
  59. for (i = 0; rom_exts[i] != NULL; i++)
  60. if (strcasecmp(ext, rom_exts[i]) == 0) return COL_ROM;
  61. for (i = 0; i < array_size(other_exts); i++)
  62. if (strcasecmp(ext, other_exts[i]) == 0) return COL_OTH;
  63. return 0xffff;
  64. }
  65. #include <platform/libpicofe/menu.c>
  66. static const char *men_dummy[] = { NULL };
  67. /* platform specific options and handlers */
  68. #if defined(__GP2X__)
  69. #include <platform/gp2x/menu.c>
  70. #elif defined(__PSP__)
  71. #include <platform/psp/menu.c>
  72. #elif defined(PANDORA)
  73. #include <platform/pandora/menu.c>
  74. #else
  75. #include <platform/linux/menu.c>
  76. #endif
  77. /// -------------- DEFINES --------------
  78. #define MIN(a,b) (((a)<(b))?(a):(b))
  79. #define MAX(a,b) (((a)>(b))?(a):(b))
  80. #define ABS(x) (((x) < 0) ? (-x) : (x))
  81. //#define MENU_DEBUG
  82. #define MENU_ERROR
  83. #ifdef MENU_DEBUG
  84. #define MENU_DEBUG_PRINTF(...) printf(__VA_ARGS__);
  85. #else
  86. #define MENU_DEBUG_PRINTF(...)
  87. #endif //MENU_DEBUG
  88. #ifdef MENU_ERROR
  89. #define MENU_ERROR_PRINTF(...) printf(__VA_ARGS__);
  90. #else
  91. #define MENU_ERROR_PRINTF(...)
  92. #endif //MENU_ERROR
  93. #define RES_HW_SCREEN_HORIZONTAL 240
  94. #define RES_HW_SCREEN_VERTICAL 240
  95. #define SCREEN_HORIZONTAL_SIZE 240
  96. #define SCREEN_VERTICAL_SIZE 240
  97. #define SCROLL_SPEED_PX 30
  98. #define FPS_MENU 50
  99. #define ARROWS_PADDING 8
  100. #define MENU_ZONE_WIDTH SCREEN_HORIZONTAL_SIZE
  101. #define MENU_ZONE_HEIGHT SCREEN_VERTICAL_SIZE
  102. #define MENU_BG_SQUARE_WIDTH 180
  103. #define MENU_BG_SQUARE_HEIGHT 140
  104. #define MENU_FONT_NAME_TITLE "/usr/games/menu_resources/OpenSans-Bold.ttf"
  105. #define MENU_FONT_SIZE_TITLE 22
  106. #define MENU_FONT_NAME_INFO "/usr/games/menu_resources/OpenSans-Bold.ttf"
  107. #define MENU_FONT_SIZE_INFO 16
  108. #define MENU_FONT_NAME_SMALL_INFO "/usr/games/menu_resources/OpenSans-Regular.ttf"
  109. #define MENU_FONT_SIZE_SMALL_INFO 13
  110. #define MENU_PNG_BG_PATH "/usr/games/menu_resources/zone_bg.png"
  111. #define MENU_PNG_ARROW_TOP_PATH "/usr/games/menu_resources/arrow_top.png"
  112. #define MENU_PNG_ARROW_BOTTOM_PATH "/usr/games/menu_resources/arrow_bottom.png"
  113. #define GRAY_MAIN_R 85
  114. #define GRAY_MAIN_G 85
  115. #define GRAY_MAIN_B 85
  116. #define WHITE_MAIN_R 236
  117. #define WHITE_MAIN_G 236
  118. #define WHITE_MAIN_B 236
  119. #define MAX_SAVE_SLOTS 9
  120. #define MAXPATHLEN 512
  121. /// -------------- STATIC VARIABLES --------------
  122. extern SDL_Surface * hw_screen;
  123. extern SDL_Surface * virtual_hw_screen;
  124. SDL_Surface * draw_screen;
  125. static int backup_key_repeat_delay, backup_key_repeat_interval;
  126. static SDL_Surface * backup_hw_screen = NULL;
  127. static TTF_Font *menu_title_font = NULL;
  128. static TTF_Font *menu_info_font = NULL;
  129. static TTF_Font *menu_small_info_font = NULL;
  130. static SDL_Surface *img_arrow_top = NULL;
  131. static SDL_Surface *img_arrow_bottom = NULL;
  132. static SDL_Surface ** menu_zone_surfaces = NULL;
  133. static int * idx_menus = NULL;
  134. static int nb_menu_zones = 0;
  135. static int menuItem = 0;
  136. int stop_menu_loop = 0;
  137. static SDL_Color text_color = {GRAY_MAIN_R, GRAY_MAIN_G, GRAY_MAIN_B};
  138. static int padding_y_from_center_menu_zone = 18;
  139. static uint16_t width_progress_bar = 100;
  140. static uint16_t height_progress_bar = 20;
  141. static uint16_t x_volume_bar = 0;
  142. static uint16_t y_volume_bar = 0;
  143. static uint16_t x_brightness_bar = 0;
  144. static uint16_t y_brightness_bar = 0;
  145. int volume_percentage = 0;
  146. int brightness_percentage = 0;
  147. static int quick_load_slot_chosen = 0;
  148. #undef X
  149. #define X(a, b) b,
  150. const char *resume_options_str[] = {RESUME_OPTIONS};
  151. /// -------------- FUNCTIONS IMPLEMENTATION --------------
  152. void init_menu_SDL(){
  153. /// ----- Loading the fonts -----
  154. menu_title_font = TTF_OpenFont(MENU_FONT_NAME_TITLE, MENU_FONT_SIZE_TITLE);
  155. if(!menu_title_font){
  156. MENU_ERROR_PRINTF("ERROR in init_menu_SDL: Could not open menu font %s, %s\n", MENU_FONT_NAME_TITLE, SDL_GetError());
  157. }
  158. menu_info_font = TTF_OpenFont(MENU_FONT_NAME_INFO, MENU_FONT_SIZE_INFO);
  159. if(!menu_info_font){
  160. MENU_ERROR_PRINTF("ERROR in init_menu_SDL: Could not open menu font %s, %s\n", MENU_FONT_NAME_INFO, SDL_GetError());
  161. }
  162. menu_small_info_font = TTF_OpenFont(MENU_FONT_NAME_SMALL_INFO, MENU_FONT_SIZE_SMALL_INFO);
  163. if(!menu_small_info_font){
  164. MENU_ERROR_PRINTF("ERROR in init_menu_SDL: Could not open menu font %s, %s\n", MENU_FONT_NAME_SMALL_INFO, SDL_GetError());
  165. }
  166. /// ----- Copy draw_screen at init ------
  167. backup_hw_screen = SDL_CreateRGBSurface(SDL_SWSURFACE,
  168. virtual_hw_screen->w, virtual_hw_screen->h, 16, 0, 0, 0, 0);
  169. if(backup_hw_screen == NULL){
  170. MENU_ERROR_PRINTF("ERROR in init_menu_SDL: Could not create backup_hw_screen: %s\n", SDL_GetError());
  171. }
  172. draw_screen = SDL_CreateRGBSurface(SDL_SWSURFACE,
  173. virtual_hw_screen->w, virtual_hw_screen->h, 16, 0, 0, 0, 0);
  174. if(draw_screen == NULL){
  175. MENU_ERROR_PRINTF("ERROR in init_menu_SDL: Could not create draw_screen: %s\n", SDL_GetError());
  176. }
  177. /// ------ Load arrows imgs -------
  178. img_arrow_top = IMG_Load(MENU_PNG_ARROW_TOP_PATH);
  179. if(!img_arrow_top) {
  180. MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
  181. }
  182. img_arrow_bottom = IMG_Load(MENU_PNG_ARROW_BOTTOM_PATH);
  183. if(!img_arrow_bottom) {
  184. MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
  185. }
  186. /// ------ Init menu zones ------
  187. init_menu_zones();
  188. }
  189. void deinit_menu_SDL(){
  190. /// ------ Close font -------
  191. TTF_CloseFont(menu_title_font);
  192. TTF_CloseFont(menu_info_font);
  193. TTF_CloseFont(menu_small_info_font);
  194. /// ------ Free Surfaces -------
  195. for(int i=0; i < nb_menu_zones; i++){
  196. SDL_FreeSurface(menu_zone_surfaces[i]);
  197. }
  198. SDL_FreeSurface(backup_hw_screen);
  199. SDL_FreeSurface(draw_screen);
  200. SDL_FreeSurface(img_arrow_top);
  201. SDL_FreeSurface(img_arrow_bottom);
  202. /// ------ Free Menu memory and reset vars -----
  203. if(idx_menus){
  204. free(idx_menus);
  205. }
  206. idx_menus=NULL;
  207. nb_menu_zones = 0;
  208. }
  209. void draw_progress_bar(SDL_Surface * surface, uint16_t x, uint16_t y, uint16_t width,
  210. uint16_t height, uint8_t percentage, uint16_t nb_bars){
  211. /// ------ Init Variables ------
  212. uint16_t line_width = 1; //px
  213. uint16_t padding_bars_ratio = 3;
  214. uint16_t nb_full_bars = 0;
  215. /// ------ Check values ------
  216. percentage = (percentage > 100)?100:percentage;
  217. x = (x > (surface->w-1))?(surface->w-1):x;
  218. y = (y > surface->h-1)?(surface->h-1):y;
  219. width = (width < line_width*2+1)?(line_width*2+1):width;
  220. width = (width > surface->w-x-1)?(surface->w-x-1):width;
  221. height = (height < line_width*2+1)?(line_width*2+1):height;
  222. height = (height > surface->h-y-1)?(surface->h-y-1):height;
  223. uint16_t nb_bars_max = ( width * padding_bars_ratio / (line_width*2+1) + 1 ) / (padding_bars_ratio+1);
  224. nb_bars = (nb_bars > nb_bars_max)?nb_bars_max:nb_bars;
  225. uint16_t bar_width = (width / nb_bars)*padding_bars_ratio/(padding_bars_ratio+1)+1;
  226. uint16_t bar_padding_x = bar_width/padding_bars_ratio;
  227. nb_full_bars = nb_bars*percentage/100;
  228. /// ------ draw full bars ------
  229. for (int i = 0; i < nb_full_bars; ++i)
  230. {
  231. /// ---- draw one bar ----
  232. //MENU_DEBUG_PRINTF("Drawing filled bar %d\n", i);
  233. SDL_Rect rect = {x+ i*(bar_width +bar_padding_x),
  234. y, bar_width, height};
  235. SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, GRAY_MAIN_R, GRAY_MAIN_G, GRAY_MAIN_B));
  236. }
  237. /// ------ draw full bars ------
  238. for (int i = 0; i < (nb_bars-nb_full_bars); ++i)
  239. {
  240. /// ---- draw one bar ----
  241. //MENU_DEBUG_PRINTF("Drawing empty bar %d\n", i);
  242. SDL_Rect rect = {x+ i*(bar_width +bar_padding_x) + nb_full_bars*(bar_width +bar_padding_x),
  243. y, bar_width, height};
  244. SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, GRAY_MAIN_R, GRAY_MAIN_G, GRAY_MAIN_B));
  245. SDL_Rect rect2 = {x+ i*(bar_width +bar_padding_x) + line_width + nb_full_bars*(bar_width +bar_padding_x),
  246. y + line_width, bar_width - line_width*2, height - line_width*2};
  247. SDL_FillRect(surface, &rect2, SDL_MapRGB(surface->format, WHITE_MAIN_R, WHITE_MAIN_R, WHITE_MAIN_R));
  248. }
  249. }
  250. void add_menu_zone(ENUM_MENU_TYPE menu_type){
  251. /// ------ Increase nb of menu zones -------
  252. nb_menu_zones++;
  253. /// ------ Realoc idx Menus array -------
  254. if(!idx_menus){
  255. idx_menus = malloc(nb_menu_zones*sizeof(int));
  256. menu_zone_surfaces = malloc(nb_menu_zones*sizeof(SDL_Surface*));
  257. }
  258. else{
  259. int *temp = realloc(idx_menus, nb_menu_zones*sizeof(int));
  260. idx_menus = temp;
  261. menu_zone_surfaces = realloc(menu_zone_surfaces, nb_menu_zones*sizeof(SDL_Surface*));
  262. }
  263. idx_menus[nb_menu_zones-1] = menu_type;
  264. /// ------ Reinit menu surface with height increased -------
  265. menu_zone_surfaces[nb_menu_zones-1] = IMG_Load(MENU_PNG_BG_PATH);
  266. if(!menu_zone_surfaces[nb_menu_zones-1]) {
  267. MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
  268. }
  269. /// --------- Init Common Variables --------
  270. SDL_Surface *text_surface = NULL;
  271. SDL_Surface *surface = menu_zone_surfaces[nb_menu_zones-1];
  272. SDL_Rect text_pos;
  273. /// --------- Add new zone ---------
  274. switch(menu_type){
  275. case MENU_TYPE_VOLUME:
  276. MENU_DEBUG_PRINTF("Init MENU_TYPE_VOLUME\n");
  277. /// ------ Text ------
  278. text_surface = TTF_RenderText_Blended(menu_title_font, "VOLUME", text_color);
  279. text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  280. text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone;
  281. SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
  282. x_volume_bar = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - width_progress_bar)/2;
  283. y_volume_bar = surface->h - MENU_ZONE_HEIGHT/2 - height_progress_bar/2 + padding_y_from_center_menu_zone;
  284. draw_progress_bar(surface, x_volume_bar, y_volume_bar,
  285. width_progress_bar, height_progress_bar, 0, 100/STEP_CHANGE_VOLUME);
  286. break;
  287. case MENU_TYPE_BRIGHTNESS:
  288. MENU_DEBUG_PRINTF("Init MENU_TYPE_BRIGHTNESS\n");
  289. /// ------ Text ------
  290. text_surface = TTF_RenderText_Blended(menu_title_font, "BRIGHTNESS", text_color);
  291. text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  292. text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone;
  293. SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
  294. x_brightness_bar = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - width_progress_bar)/2;
  295. y_brightness_bar = surface->h - MENU_ZONE_HEIGHT/2 - height_progress_bar/2 + padding_y_from_center_menu_zone;
  296. draw_progress_bar(surface, x_brightness_bar, y_brightness_bar,
  297. width_progress_bar, height_progress_bar, 0, 100/STEP_CHANGE_BRIGHTNESS);
  298. break;
  299. case MENU_TYPE_SAVE:
  300. MENU_DEBUG_PRINTF("Init MENU_TYPE_SAVE\n");
  301. /// ------ Text ------
  302. text_surface = TTF_RenderText_Blended(menu_title_font, "SAVE", text_color);
  303. text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  304. text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone*2;
  305. SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
  306. break;
  307. case MENU_TYPE_LOAD:
  308. MENU_DEBUG_PRINTF("Init MENU_TYPE_LOAD\n");
  309. /// ------ Text ------
  310. text_surface = TTF_RenderText_Blended(menu_title_font, "LOAD", text_color);
  311. text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  312. text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone*2;
  313. SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
  314. break;
  315. case MENU_TYPE_ASPECT_RATIO:
  316. MENU_DEBUG_PRINTF("Init MENU_TYPE_ASPECT_RATIO\n");
  317. /// ------ Text ------
  318. text_surface = TTF_RenderText_Blended(menu_title_font, "ASPECT RATIO", text_color);
  319. text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  320. text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone;
  321. SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
  322. break;
  323. case MENU_TYPE_EXIT:
  324. MENU_DEBUG_PRINTF("Init MENU_TYPE_EXIT\n");
  325. /// ------ Text ------
  326. text_surface = TTF_RenderText_Blended(menu_title_font, "EXIT GAME", text_color);
  327. text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  328. text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
  329. SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
  330. break;
  331. case MENU_TYPE_POWERDOWN:
  332. MENU_DEBUG_PRINTF("Init MENU_TYPE_POWERDOWN\n");
  333. /// ------ Text ------
  334. text_surface = TTF_RenderText_Blended(menu_title_font, "POWERDOWN", text_color);
  335. text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  336. text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
  337. SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
  338. break;
  339. default:
  340. MENU_DEBUG_PRINTF("Warning - In add_menu_zone, unknown MENU_TYPE: %d\n", menu_type);
  341. break;
  342. }
  343. /// ------ Free Surfaces -------
  344. SDL_FreeSurface(text_surface);
  345. }
  346. void init_menu_zones(){
  347. /// Init Volume Menu
  348. add_menu_zone(MENU_TYPE_VOLUME);
  349. /// Init Brightness Menu
  350. add_menu_zone(MENU_TYPE_BRIGHTNESS);
  351. /// Init Save Menu
  352. add_menu_zone(MENU_TYPE_SAVE);
  353. /// Init Load Menu
  354. add_menu_zone(MENU_TYPE_LOAD);
  355. /// Init Aspect Ratio Menu
  356. add_menu_zone(MENU_TYPE_ASPECT_RATIO);
  357. /// Init Exit Menu
  358. add_menu_zone(MENU_TYPE_EXIT);
  359. /// Init Powerdown Menu
  360. //add_menu_zone(MENU_TYPE_POWERDOWN);
  361. }
  362. void init_menu_system_values(){
  363. FILE *fp;
  364. char res[100];
  365. /// ------- Get system volume percentage --------
  366. fp = popen(SHELL_CMD_VOLUME_GET, "r");
  367. if (fp == NULL) {
  368. MENU_ERROR_PRINTF("Failed to run command %s\n", SHELL_CMD_VOLUME_GET );
  369. volume_percentage = 50; ///wrong value: setting default to 50
  370. }
  371. else{
  372. fgets(res, sizeof(res)-1, fp);
  373. pclose(fp);
  374. /// Check if Volume is a number (at least the first char)
  375. if(res[0] < '0' || res[0] > '9'){
  376. MENU_ERROR_PRINTF("Wrong return value: %s for volume cmd: %s\n",res, SHELL_CMD_VOLUME_GET);
  377. volume_percentage = 50; ///wrong value: setting default to 50
  378. }
  379. else{
  380. volume_percentage = atoi(res);
  381. MENU_DEBUG_PRINTF("System volume = %d%%\n", volume_percentage);
  382. }
  383. }
  384. /// ------- Get system brightness percentage -------
  385. fp = popen(SHELL_CMD_BRIGHTNESS_GET, "r");
  386. if (fp == NULL) {
  387. MENU_ERROR_PRINTF("Failed to run command %s\n", SHELL_CMD_BRIGHTNESS_GET );
  388. brightness_percentage = 50; ///wrong value: setting default to 50
  389. }
  390. else{
  391. fgets(res, sizeof(res)-1, fp);
  392. pclose(fp);
  393. /// Check if brightness is a number (at least the first char)
  394. if(res[0] < '0' || res[0] > '9'){
  395. MENU_ERROR_PRINTF("Wrong return value: %s for volume cmd: %s\n",res, SHELL_CMD_BRIGHTNESS_GET);
  396. brightness_percentage = 50; ///wrong value: setting default to 50
  397. }
  398. else{
  399. brightness_percentage = atoi(res);
  400. MENU_DEBUG_PRINTF("System brightness = %d%%\n", brightness_percentage);
  401. }
  402. }
  403. /// ------ Save prev key repeat params and set new Key repeat -------
  404. SDL_GetKeyRepeat(&backup_key_repeat_delay, &backup_key_repeat_interval);
  405. if(SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL)){
  406. MENU_ERROR_PRINTF("ERROR with SDL_EnableKeyRepeat: %s\n", SDL_GetError());
  407. }
  408. /// Get save slot from game
  409. state_slot = (state_slot%MAX_SAVE_SLOTS); // security
  410. }
  411. void menu_screen_refresh(int menuItem, int prevItem, int scroll, uint8_t menu_confirmation, uint8_t menu_action){
  412. /// --------- Vars ---------
  413. int print_arrows = (scroll==0)?1:0;
  414. /// --------- Clear HW screen ----------
  415. //SDL_FillRect(draw_screen, NULL, SDL_MapRGB(draw_screen->format, 255, 0, 0));
  416. if(SDL_BlitSurface(backup_hw_screen, NULL, draw_screen, NULL)){
  417. MENU_ERROR_PRINTF("ERROR Could not Clear draw_screen: %s\n", SDL_GetError());
  418. }
  419. /// --------- Setup Blit Window ----------
  420. SDL_Rect menu_blit_window;
  421. menu_blit_window.x = 0;
  422. menu_blit_window.w = SCREEN_HORIZONTAL_SIZE;
  423. /// --------- Blit prev menu Zone going away ----------
  424. menu_blit_window.y = scroll;
  425. menu_blit_window.h = SCREEN_VERTICAL_SIZE;
  426. if(SDL_BlitSurface(menu_zone_surfaces[prevItem], &menu_blit_window, draw_screen, NULL)){
  427. MENU_ERROR_PRINTF("ERROR Could not Blit surface on draw_screen: %s\n", SDL_GetError());
  428. }
  429. /// --------- Blit new menu Zone going in (only during animations) ----------
  430. if(scroll>0){
  431. menu_blit_window.y = SCREEN_VERTICAL_SIZE-scroll;
  432. menu_blit_window.h = SCREEN_VERTICAL_SIZE;
  433. if(SDL_BlitSurface(menu_zone_surfaces[menuItem], NULL, draw_screen, &menu_blit_window)){
  434. MENU_ERROR_PRINTF("ERROR Could not Blit surface on draw_screen: %s\n", SDL_GetError());
  435. }
  436. }
  437. else if(scroll<0){
  438. menu_blit_window.y = SCREEN_VERTICAL_SIZE+scroll;
  439. menu_blit_window.h = SCREEN_VERTICAL_SIZE;
  440. if(SDL_BlitSurface(menu_zone_surfaces[menuItem], &menu_blit_window, draw_screen, NULL)){
  441. MENU_ERROR_PRINTF("ERROR Could not Blit surface on draw_screen: %s\n", SDL_GetError());
  442. }
  443. }
  444. /// --------- No Scroll ? Blitting menu-specific info
  445. else{
  446. SDL_Surface * text_surface = NULL;
  447. char text_tmp[40];
  448. SDL_Rect text_pos;
  449. /*char fname[MAXPATHLEN];
  450. memset(fname, 0, MAXPATHLEN);*/
  451. char *fname = NULL;
  452. uint16_t limit_filename_size = 24;
  453. switch(idx_menus[menuItem]){
  454. case MENU_TYPE_VOLUME:
  455. draw_progress_bar(draw_screen, x_volume_bar, y_volume_bar,
  456. width_progress_bar, height_progress_bar, volume_percentage, 100/STEP_CHANGE_VOLUME);
  457. break;
  458. case MENU_TYPE_BRIGHTNESS:
  459. draw_progress_bar(draw_screen, x_volume_bar, y_volume_bar,
  460. width_progress_bar, height_progress_bar, brightness_percentage, 100/STEP_CHANGE_BRIGHTNESS);
  461. break;
  462. case MENU_TYPE_SAVE:
  463. /// ---- Write slot -----
  464. sprintf(text_tmp, "IN SLOT < %d >", state_slot+1);
  465. text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
  466. text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  467. text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
  468. SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
  469. if(menu_action){
  470. sprintf(text_tmp, "Saving...");
  471. text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
  472. }
  473. else{
  474. if(menu_confirmation){
  475. sprintf(text_tmp, "Are you sure ?");
  476. text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
  477. }
  478. else{
  479. fname = emu_get_save_fname(1, 0, state_slot, NULL);
  480. if (fname == NULL) {
  481. text_surface = TTF_RenderText_Blended(menu_info_font, "Free", text_color);
  482. }
  483. else{
  484. printf("Found saved file: %s\n", fname);
  485. char *p = strrchr (fname, '/');
  486. char *basename = p ? p + 1 : (char *) fname;
  487. if(strlen(basename) > limit_filename_size){basename[limit_filename_size]=0;} //limiting size
  488. text_surface = TTF_RenderText_Blended(menu_small_info_font, basename, text_color);
  489. }
  490. }
  491. }
  492. text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  493. text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 + 2*padding_y_from_center_menu_zone;
  494. SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
  495. break;
  496. case MENU_TYPE_LOAD:
  497. /// ---- Write slot -----
  498. if(quick_load_slot_chosen){
  499. sprintf(text_tmp, "FROM AUTO SAVE");
  500. }
  501. else{
  502. sprintf(text_tmp, "FROM SLOT < %d >", state_slot+1);
  503. }
  504. text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
  505. text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  506. text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
  507. SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
  508. if(menu_action){
  509. sprintf(text_tmp, "Loading...");
  510. text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
  511. }
  512. else{
  513. if(menu_confirmation){
  514. sprintf(text_tmp, "Are you sure ?");
  515. text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
  516. }
  517. else{
  518. if(quick_load_slot_chosen){
  519. text_surface = TTF_RenderText_Blended(menu_info_font, " ", text_color);
  520. }
  521. else{
  522. fname = emu_get_save_fname(1, 0, state_slot, NULL);
  523. if (fname == NULL) {
  524. text_surface = TTF_RenderText_Blended(menu_info_font, "Free", text_color);
  525. }
  526. else{
  527. printf("Found saved file: %s\n", fname);
  528. char *p = strrchr (fname, '/');
  529. char *basename = p ? p + 1 : (char *) fname;
  530. if(strlen(basename) > limit_filename_size){basename[limit_filename_size]=0;} //limiting size
  531. text_surface = TTF_RenderText_Blended(menu_small_info_font, basename, text_color);
  532. }
  533. }
  534. }
  535. }
  536. text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  537. text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 + 2*padding_y_from_center_menu_zone;
  538. SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
  539. break;
  540. case MENU_TYPE_ASPECT_RATIO:
  541. sprintf(text_tmp, "< %s >", aspect_ratio_name[aspect_ratio]);
  542. text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
  543. text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  544. text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 + padding_y_from_center_menu_zone;
  545. SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
  546. break;
  547. case MENU_TYPE_EXIT:
  548. case MENU_TYPE_POWERDOWN:
  549. if(menu_confirmation){
  550. sprintf(text_tmp, "Are you sure ?");
  551. text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
  552. text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  553. text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 + 2*padding_y_from_center_menu_zone;
  554. SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
  555. }
  556. break;
  557. default:
  558. break;
  559. }
  560. /// ------ Free Surfaces -------
  561. if(text_surface)
  562. SDL_FreeSurface(text_surface);
  563. }
  564. /// --------- Print arrows --------
  565. if(print_arrows){
  566. /// Top arrow
  567. SDL_Rect pos_arrow_top;
  568. pos_arrow_top.x = (draw_screen->w - img_arrow_top->w)/2;
  569. pos_arrow_top.y = (draw_screen->h - MENU_BG_SQUARE_HEIGHT)/4 - img_arrow_top->h/2;
  570. SDL_BlitSurface(img_arrow_top, NULL, draw_screen, &pos_arrow_top);
  571. /// Bottom arrow
  572. SDL_Rect pos_arrow_bottom;
  573. pos_arrow_bottom.x = (draw_screen->w - img_arrow_bottom->w)/2;
  574. pos_arrow_bottom.y = draw_screen->h -
  575. (draw_screen->h - MENU_BG_SQUARE_HEIGHT)/4 - img_arrow_bottom->h/2;
  576. SDL_BlitSurface(img_arrow_bottom, NULL, draw_screen, &pos_arrow_bottom);
  577. }
  578. // Rotate
  579. //SDL_Rotate_270(hw_screen, virtual_hw_screen);
  580. SDL_BlitSurface(draw_screen, NULL, hw_screen, NULL);
  581. /// --- Real Flip ---
  582. SDL_Flip(hw_screen);
  583. }
  584. void run_menu_loop()
  585. {
  586. MENU_DEBUG_PRINTF("Launch Menu\n");
  587. SDL_Event event;
  588. uint32_t prev_ms = SDL_GetTicks();
  589. uint32_t cur_ms = SDL_GetTicks();
  590. int scroll=0;
  591. int start_scroll=0;
  592. uint8_t screen_refresh = 1;
  593. char shell_cmd[100];
  594. uint8_t menu_confirmation = 0;
  595. stop_menu_loop = 0;
  596. char fname[MAXPATHLEN];
  597. /// ------ Load default keymap ------
  598. system(SHELL_CMD_KEYMAP_DEFAULT);
  599. /// ------ Get init values -------
  600. init_menu_system_values();
  601. int prevItem=menuItem;
  602. /// ------ Copy currently displayed screen -------
  603. /* if(SDL_BlitSurface(virtual_hw_screen, NULL, backup_hw_screen, NULL)){
  604. MENU_ERROR_PRINTF("ERROR Could not copy draw_screen: %s\n", SDL_GetError());
  605. }*/
  606. memcpy(backup_hw_screen->pixels, (uint16_t*) virtual_hw_screen->pixels,
  607. RES_HW_SCREEN_HORIZONTAL * RES_HW_SCREEN_VERTICAL * sizeof(uint16_t));
  608. /* Stop Ampli */
  609. system(SHELL_CMD_AUDIO_AMP_OFF);
  610. /// ------ Wait for menu UP key event ------
  611. int actions[IN_BINDTYPE_COUNT] = { 0, };
  612. while(event.type != SDL_KEYUP || event.key.keysym.sym != SDLK_q){
  613. while (SDL_PollEvent(&event)){
  614. SDL_PushEvent(&event);
  615. in_update(actions);
  616. }
  617. /* 500ms timeout */
  618. if(SDL_GetTicks() - cur_ms > 500){
  619. MENU_ERROR_PRINTF("Timeout waiting for SDLK_q UP\n");
  620. break;
  621. }
  622. }
  623. /// -------- Main loop ---------
  624. while (!stop_menu_loop)
  625. {
  626. /// -------- Handle Keyboard Events ---------
  627. if(!scroll){
  628. while (SDL_PollEvent(&event))
  629. switch(event.type)
  630. {
  631. case SDL_QUIT:
  632. engineState = PGS_Quit;
  633. stop_menu_loop = 1;
  634. break;
  635. case SDL_KEYDOWN:
  636. switch (event.key.keysym.sym)
  637. {
  638. case SDLK_b:
  639. if(menu_confirmation){
  640. /// ------ Reset menu confirmation ------
  641. menu_confirmation = 0;
  642. /// ------ Refresh screen ------
  643. screen_refresh = 1;
  644. }
  645. /*else{
  646. stop_menu_loop = 1;
  647. }*/
  648. break;
  649. case SDLK_q:
  650. case SDLK_ESCAPE:
  651. stop_menu_loop = 1;
  652. break;
  653. case SDLK_d:
  654. case SDLK_DOWN:
  655. MENU_DEBUG_PRINTF("DOWN\n");
  656. /// ------ Start scrolling to new menu -------
  657. menuItem++;
  658. if (menuItem>=nb_menu_zones) menuItem=0;
  659. scroll=1;
  660. /// ------ Reset menu confirmation ------
  661. menu_confirmation = 0;
  662. /// ------ Refresh screen ------
  663. screen_refresh = 1;
  664. break;
  665. case SDLK_u:
  666. case SDLK_UP:
  667. MENU_DEBUG_PRINTF("UP\n");
  668. /// ------ Start scrolling to new menu -------
  669. menuItem--;
  670. if (menuItem<0) menuItem=nb_menu_zones-1;
  671. scroll=-1;
  672. /// ------ Reset menu confirmation ------
  673. menu_confirmation = 0;
  674. /// ------ Refresh screen ------
  675. screen_refresh = 1;
  676. break;
  677. case SDLK_l:
  678. case SDLK_LEFT:
  679. //MENU_DEBUG_PRINTF("LEFT\n");
  680. if(idx_menus[menuItem] == MENU_TYPE_VOLUME){
  681. MENU_DEBUG_PRINTF("Volume DOWN\n");
  682. /// ----- Compute new value -----
  683. volume_percentage = (volume_percentage < STEP_CHANGE_VOLUME)?
  684. 0:(volume_percentage-STEP_CHANGE_VOLUME);
  685. /// ----- Shell cmd ----
  686. sprintf(shell_cmd, "%s %d", SHELL_CMD_VOLUME_SET, volume_percentage);
  687. system(shell_cmd);
  688. /// ------ Refresh screen ------
  689. screen_refresh = 1;
  690. }
  691. else if(idx_menus[menuItem] == MENU_TYPE_BRIGHTNESS){
  692. MENU_DEBUG_PRINTF("Brightness DOWN\n");
  693. /// ----- Compute new value -----
  694. brightness_percentage = (brightness_percentage < STEP_CHANGE_BRIGHTNESS)?
  695. 0:(brightness_percentage-STEP_CHANGE_BRIGHTNESS);
  696. /// ----- Shell cmd ----
  697. sprintf(shell_cmd, "%s %d", SHELL_CMD_BRIGHTNESS_SET, brightness_percentage);
  698. system(shell_cmd);
  699. /// ------ Refresh screen ------
  700. screen_refresh = 1;
  701. }
  702. else if(idx_menus[menuItem] == MENU_TYPE_SAVE){
  703. MENU_DEBUG_PRINTF("Save Slot DOWN\n");
  704. state_slot = (!state_slot)?(MAX_SAVE_SLOTS-1):(state_slot-1);
  705. /// ------ Refresh screen ------
  706. screen_refresh = 1;
  707. }
  708. else if(idx_menus[menuItem] == MENU_TYPE_LOAD){
  709. MENU_DEBUG_PRINTF("Load Slot DOWN\n");
  710. /** Choose quick save file or standard saveslot for loading */
  711. if(!quick_load_slot_chosen &&
  712. state_slot == 0 &&
  713. access(quick_save_file, F_OK ) != -1){
  714. quick_load_slot_chosen = 1;
  715. }
  716. else if(quick_load_slot_chosen){
  717. quick_load_slot_chosen = 0;
  718. state_slot = MAX_SAVE_SLOTS-1;
  719. }
  720. else{
  721. state_slot = (!state_slot)?(MAX_SAVE_SLOTS-1):(state_slot-1);
  722. }
  723. /// ------ Refresh screen ------
  724. screen_refresh = 1;
  725. }
  726. else if(idx_menus[menuItem] == MENU_TYPE_ASPECT_RATIO){
  727. MENU_DEBUG_PRINTF("Aspect Ratio DOWN\n");
  728. aspect_ratio = (!aspect_ratio)?(NB_ASPECT_RATIOS_TYPES-1):(aspect_ratio-1);
  729. /// ------ Refresh screen ------
  730. screen_refresh = 1;
  731. // Save config file
  732. configfile_save(cfg_file_rom);
  733. }
  734. break;
  735. case SDLK_r:
  736. case SDLK_RIGHT:
  737. //MENU_DEBUG_PRINTF("RIGHT\n");
  738. if(idx_menus[menuItem] == MENU_TYPE_VOLUME){
  739. MENU_DEBUG_PRINTF("Volume UP\n");
  740. /// ----- Compute new value -----
  741. volume_percentage = (volume_percentage > 100 - STEP_CHANGE_VOLUME)?
  742. 100:(volume_percentage+STEP_CHANGE_VOLUME);
  743. /// ----- Shell cmd ----
  744. sprintf(shell_cmd, "%s %d", SHELL_CMD_VOLUME_SET, volume_percentage);
  745. system(shell_cmd);
  746. /// ------ Refresh screen ------
  747. screen_refresh = 1;
  748. }
  749. else if(idx_menus[menuItem] == MENU_TYPE_BRIGHTNESS){
  750. MENU_DEBUG_PRINTF("Brightness UP\n");
  751. /// ----- Compute new value -----
  752. brightness_percentage = (brightness_percentage > 100 - STEP_CHANGE_BRIGHTNESS)?
  753. 100:(brightness_percentage+STEP_CHANGE_BRIGHTNESS);
  754. /// ----- Shell cmd ----
  755. sprintf(shell_cmd, "%s %d", SHELL_CMD_BRIGHTNESS_SET, brightness_percentage);
  756. system(shell_cmd);
  757. /// ------ Refresh screen ------
  758. screen_refresh = 1;
  759. }
  760. else if(idx_menus[menuItem] == MENU_TYPE_SAVE){
  761. MENU_DEBUG_PRINTF("Save Slot UP\n");
  762. state_slot = (state_slot+1)%MAX_SAVE_SLOTS;
  763. /// ------ Refresh screen ------
  764. screen_refresh = 1;
  765. }
  766. else if(idx_menus[menuItem] == MENU_TYPE_LOAD){
  767. MENU_DEBUG_PRINTF("Load Slot UP\n");
  768. /** Choose quick save file or standard saveslot for loading */
  769. if(!quick_load_slot_chosen &&
  770. state_slot == MAX_SAVE_SLOTS-1 &&
  771. access(quick_save_file, F_OK ) != -1){
  772. quick_load_slot_chosen = 1;
  773. }
  774. else if(quick_load_slot_chosen){
  775. quick_load_slot_chosen = 0;
  776. state_slot = 0;
  777. }
  778. else{
  779. state_slot = (state_slot+1)%MAX_SAVE_SLOTS;
  780. }
  781. /// ------ Refresh screen ------
  782. screen_refresh = 1;
  783. }
  784. else if(idx_menus[menuItem] == MENU_TYPE_ASPECT_RATIO){
  785. MENU_DEBUG_PRINTF("Aspect Ratio UP\n");
  786. aspect_ratio = (aspect_ratio+1)%NB_ASPECT_RATIOS_TYPES;
  787. /// ------ Refresh screen ------
  788. screen_refresh = 1;
  789. // Save config file
  790. configfile_save(cfg_file_rom);
  791. }
  792. break;
  793. case SDLK_a:
  794. case SDLK_RETURN:
  795. if(idx_menus[menuItem] == MENU_TYPE_SAVE){
  796. if(menu_confirmation){
  797. MENU_DEBUG_PRINTF("Saving in slot %d\n", state_slot);
  798. /// ------ Refresh Screen -------
  799. menu_screen_refresh(menuItem, prevItem, scroll, menu_confirmation, 1);
  800. /// ------ Save game ------
  801. int ret = emu_save_load_game(0, 0);
  802. /// ----- Hud Msg -----
  803. if(ret){
  804. MENU_ERROR_PRINTF("Save Failed\n");
  805. sprintf(shell_cmd, "%s %d \" SAVE FAILED\"",
  806. SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP);
  807. }
  808. else{
  809. sprintf(shell_cmd, "%s %d \" SAVED IN SLOT %d\"",
  810. SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP, state_slot+1);
  811. }
  812. system(shell_cmd);
  813. stop_menu_loop = 1;
  814. }
  815. else{
  816. MENU_DEBUG_PRINTF("Save game - asking confirmation\n");
  817. menu_confirmation = 1;
  818. /// ------ Refresh screen ------
  819. screen_refresh = 1;
  820. }
  821. }
  822. else if(idx_menus[menuItem] == MENU_TYPE_LOAD){
  823. if(menu_confirmation){
  824. MENU_DEBUG_PRINTF("Loading in slot %d\n", state_slot);
  825. /// ------ Refresh Screen -------
  826. menu_screen_refresh(menuItem, prevItem, scroll, menu_confirmation, 1);
  827. /// ------ Load game ------
  828. int ret;
  829. if(quick_load_slot_chosen){
  830. ret = emu_save_load_game_from_file(1, quick_save_file);
  831. }
  832. else{
  833. ret = emu_save_load_game(1, 0);
  834. }
  835. /// ----- Hud Msg -----
  836. if(ret){
  837. MENU_ERROR_PRINTF("Load Failed\n");
  838. sprintf(shell_cmd, "%s %d \" LOAD FAILED\"",
  839. SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP);
  840. }
  841. else{
  842. if(quick_load_slot_chosen){
  843. sprintf(shell_cmd, "%s %d \" LOADED FROM AUTO SAVE\"",
  844. SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP);
  845. }
  846. else{
  847. sprintf(shell_cmd, "%s %d \" LOADED FROM SLOT %d\"",
  848. SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP, state_slot+1);
  849. }
  850. }
  851. system(shell_cmd);
  852. /*snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!");
  853. hud_new_msg = 3;*/
  854. stop_menu_loop = 1;
  855. }
  856. else{
  857. MENU_DEBUG_PRINTF("Save game - asking confirmation\n");
  858. menu_confirmation = 1;
  859. /// ------ Refresh screen ------
  860. screen_refresh = 1;
  861. }
  862. }
  863. else if(idx_menus[menuItem] == MENU_TYPE_EXIT){
  864. MENU_DEBUG_PRINTF("Exit game\n");
  865. if(menu_confirmation){
  866. MENU_DEBUG_PRINTF("Exit game - confirmed\n");
  867. /// ----- The game should be saved here ----
  868. int ret = emu_save_load_game_from_file(0, quick_save_file);
  869. /// ----- Exit game and back to launcher ----
  870. engineState = PGS_Quit;
  871. stop_menu_loop = 1;
  872. }
  873. else{
  874. MENU_DEBUG_PRINTF("Exit game - asking confirmation\n");
  875. menu_confirmation = 1;
  876. /// ------ Refresh screen ------
  877. screen_refresh = 1;
  878. }
  879. }
  880. else if(idx_menus[menuItem] == MENU_TYPE_POWERDOWN){
  881. if(menu_confirmation){
  882. MENU_DEBUG_PRINTF("Powerdown - confirmed\n");
  883. /// ----- Shell cmd ----
  884. execlp(SHELL_CMD_SHUTDOWN_FUNKEY, SHELL_CMD_SHUTDOWN_FUNKEY, NULL);
  885. MENU_ERROR_PRINTF("Failed to run command %s\n", SHELL_CMD_SHUTDOWN_FUNKEY);
  886. exit(0);
  887. }
  888. else{
  889. MENU_DEBUG_PRINTF("Powerdown - asking confirmation\n");
  890. menu_confirmation = 1;
  891. /// ------ Refresh screen ------
  892. screen_refresh = 1;
  893. }
  894. }
  895. break;
  896. default:
  897. //MENU_DEBUG_PRINTF("Keydown: %d\n", event.key.keysym.sym);
  898. break;
  899. }
  900. break;
  901. }
  902. }
  903. /// --------- Handle Scroll effect ---------
  904. if ((scroll>0) || (start_scroll>0)){
  905. scroll+=MIN(SCROLL_SPEED_PX, MENU_ZONE_HEIGHT-scroll);
  906. start_scroll = 0;
  907. screen_refresh = 1;
  908. }
  909. else if ((scroll<0) || (start_scroll<0)){
  910. scroll-=MIN(SCROLL_SPEED_PX, MENU_ZONE_HEIGHT+scroll);
  911. start_scroll = 0;
  912. screen_refresh = 1;
  913. }
  914. if (scroll>=MENU_ZONE_HEIGHT || scroll<=-MENU_ZONE_HEIGHT) {
  915. prevItem=menuItem;
  916. scroll=0;
  917. screen_refresh = 1;
  918. }
  919. /// --------- Handle FPS ---------
  920. cur_ms = SDL_GetTicks();
  921. if(cur_ms-prev_ms < 1000/FPS_MENU){
  922. SDL_Delay(1000/FPS_MENU - (cur_ms-prev_ms));
  923. }
  924. prev_ms = SDL_GetTicks();
  925. /// --------- Refresh screen
  926. if(screen_refresh){
  927. menu_screen_refresh(menuItem, prevItem, scroll, menu_confirmation, 0);
  928. }
  929. /// --------- reset screen refresh ---------
  930. screen_refresh = 0;
  931. }
  932. /// ------ Restore last keymap ------
  933. system(SHELL_CMD_KEYMAP_RESUME);
  934. /// ------ Reset prev key repeat params -------
  935. if(SDL_EnableKeyRepeat(backup_key_repeat_delay, backup_key_repeat_interval)){
  936. MENU_ERROR_PRINTF("ERROR with SDL_EnableKeyRepeat: %s\n", SDL_GetError());
  937. }
  938. /* Start Ampli */
  939. system(SHELL_CMD_AUDIO_AMP_ON);
  940. /// ------ Reset last screen ------
  941. SDL_BlitSurface(backup_hw_screen, NULL, hw_screen, NULL);
  942. SDL_Flip(hw_screen);
  943. }
  944. /****************************/
  945. /* Quick Resume Menu */
  946. /****************************/
  947. int launch_resume_menu_loop()
  948. {
  949. MENU_DEBUG_PRINTF("Init resume menu\n");
  950. /* Decare vars */
  951. SDL_Surface *text_surface = NULL;
  952. char text_tmp[40];
  953. SDL_Rect text_pos;
  954. SDL_Event event;
  955. uint32_t prev_ms = SDL_GetTicks();
  956. uint32_t cur_ms = SDL_GetTicks();
  957. stop_menu_loop = 0;
  958. uint8_t screen_refresh = 1;
  959. uint8_t menu_confirmation = 0;
  960. int option_idx=RESUME_YES;
  961. /* Stop Ampli */
  962. system(SHELL_CMD_AUDIO_AMP_OFF);
  963. /* Save prev key repeat params and set new Key repeat */
  964. SDL_GetKeyRepeat(&backup_key_repeat_delay, &backup_key_repeat_interval);
  965. if(SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL)){
  966. MENU_ERROR_PRINTF("ERROR with SDL_EnableKeyRepeat: %s\n", SDL_GetError());
  967. }
  968. /* Load BG */
  969. SDL_Surface *img_square_bg = IMG_Load(MENU_PNG_BG_PATH);
  970. if(!img_square_bg) {
  971. MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
  972. }
  973. SDL_Surface *bg_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, hw_screen->w, hw_screen->h, 16, 0, 0, 0, 0);
  974. SDL_BlitSurface(img_square_bg, NULL, bg_surface, NULL);
  975. SDL_FreeSurface(img_square_bg);
  976. /* Print top arrow */
  977. SDL_Rect pos_arrow_top;
  978. pos_arrow_top.x = (bg_surface->w - img_arrow_top->w)/2;
  979. pos_arrow_top.y = (bg_surface->h - MENU_BG_SQUARE_HEIGHT)/4 - img_arrow_top->h/2;
  980. SDL_BlitSurface(img_arrow_top, NULL, bg_surface, &pos_arrow_top);
  981. /* Print bottom arrow */
  982. SDL_Rect pos_arrow_bottom;
  983. pos_arrow_bottom.x = (bg_surface->w - img_arrow_bottom->w)/2;
  984. pos_arrow_bottom.y = bg_surface->h -
  985. (bg_surface->h - MENU_BG_SQUARE_HEIGHT)/4 - img_arrow_bottom->h/2;
  986. SDL_BlitSurface(img_arrow_bottom, NULL, bg_surface, &pos_arrow_bottom);
  987. if (text_surface)
  988. SDL_FreeSurface(text_surface);
  989. /* Main loop */
  990. while (!stop_menu_loop)
  991. {
  992. /* Handle keyboard events */
  993. while (SDL_PollEvent(&event))
  994. switch(event.type)
  995. {
  996. case SDL_QUIT:
  997. engineState = PGS_Quit;
  998. stop_menu_loop = 1;
  999. break;
  1000. case SDL_KEYDOWN:
  1001. switch (event.key.keysym.sym)
  1002. {
  1003. case SDLK_b:
  1004. if(menu_confirmation){
  1005. /// ------ Reset menu confirmation ------
  1006. menu_confirmation = 0;
  1007. /// ------ Refresh screen ------
  1008. screen_refresh = 1;
  1009. }
  1010. /*else{
  1011. stop_menu_loop = 1;
  1012. }*/
  1013. break;
  1014. case SDLK_q:
  1015. case SDLK_ESCAPE:
  1016. /*stop_menu_loop = 1;*/
  1017. break;
  1018. case SDLK_u:
  1019. case SDLK_UP:
  1020. MENU_DEBUG_PRINTF("Option UP\n");
  1021. option_idx = (!option_idx)?(NB_RESUME_OPTIONS-1):(option_idx-1);
  1022. /// ------ Reset menu confirmation ------
  1023. menu_confirmation = 0;
  1024. /// ------ Refresh screen ------
  1025. screen_refresh = 1;
  1026. break;
  1027. case SDLK_d:
  1028. case SDLK_DOWN:
  1029. MENU_DEBUG_PRINTF("Option DWON\n");
  1030. option_idx = (option_idx+1)%NB_RESUME_OPTIONS;
  1031. /// ------ Reset menu confirmation ------
  1032. menu_confirmation = 0;
  1033. /// ------ Refresh screen ------
  1034. screen_refresh = 1;
  1035. break;
  1036. case SDLK_a:
  1037. case SDLK_RETURN:
  1038. MENU_DEBUG_PRINTF("Pressed A\n");
  1039. if(menu_confirmation){
  1040. MENU_DEBUG_PRINTF("Confirmed\n");
  1041. /// ----- exit menu ----
  1042. stop_menu_loop = 1;
  1043. }
  1044. else{
  1045. MENU_DEBUG_PRINTF("Asking confirmation\n");
  1046. menu_confirmation = 1;
  1047. /// ------ Refresh screen ------
  1048. screen_refresh = 1;
  1049. }
  1050. break;
  1051. default:
  1052. //MENU_DEBUG_PRINTF("Keydown: %d\n", event.key.keysym.sym);
  1053. break;
  1054. }
  1055. break;
  1056. }
  1057. /* Handle FPS */
  1058. cur_ms = SDL_GetTicks();
  1059. if(cur_ms-prev_ms < 1000/FPS_MENU){
  1060. SDL_Delay(1000/FPS_MENU - (cur_ms-prev_ms));
  1061. }
  1062. prev_ms = SDL_GetTicks();
  1063. /* Refresh screen */
  1064. if(screen_refresh){
  1065. /* Clear and draw BG */
  1066. SDL_FillRect(hw_screen, NULL, 0);
  1067. if(SDL_BlitSurface(bg_surface, NULL, hw_screen, NULL)){
  1068. MENU_ERROR_PRINTF("ERROR Could not draw background: %s\n", SDL_GetError());
  1069. }
  1070. /* Draw resume or reset option */
  1071. text_surface = TTF_RenderText_Blended(menu_title_font, resume_options_str[option_idx], text_color);
  1072. text_pos.x = (hw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  1073. text_pos.y = hw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
  1074. SDL_BlitSurface(text_surface, NULL, hw_screen, &text_pos);
  1075. /* Draw confirmation */
  1076. if(menu_confirmation){
  1077. sprintf(text_tmp, "Are you sure ?");
  1078. text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
  1079. text_pos.x = (hw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
  1080. text_pos.y = hw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 + 2*padding_y_from_center_menu_zone;
  1081. SDL_BlitSurface(text_surface, NULL, hw_screen, &text_pos);
  1082. }
  1083. /* Flip Screen */
  1084. SDL_Flip(hw_screen);
  1085. }
  1086. /* reset screen refresh */
  1087. screen_refresh = 0;
  1088. }
  1089. /// ----- Clear screen -----
  1090. SDL_FillRect(hw_screen, NULL, 0);
  1091. SDL_Flip(hw_screen);
  1092. /* Free SDL Surfaces */
  1093. if(bg_surface)
  1094. SDL_FreeSurface(bg_surface);
  1095. if(text_surface)
  1096. SDL_FreeSurface(text_surface);
  1097. /* Reset prev key repeat params */
  1098. if(SDL_EnableKeyRepeat(backup_key_repeat_delay, backup_key_repeat_interval)){
  1099. MENU_ERROR_PRINTF("ERROR with SDL_EnableKeyRepeat: %s\n", SDL_GetError());
  1100. }
  1101. /* Start Ampli */
  1102. system(SHELL_CMD_AUDIO_AMP_ON);
  1103. return option_idx;
  1104. }
  1105. static void make_bg(int no_scale, int from_screen)
  1106. {
  1107. unsigned short *src = (void *)g_menubg_src_ptr;
  1108. int w = g_menubg_src_w ? g_menubg_src_w : g_screen_width;
  1109. int h = g_menubg_src_h ? g_menubg_src_h : g_screen_height;
  1110. int pp = g_menubg_src_pp ? g_menubg_src_pp : g_screen_ppitch;
  1111. short *dst;
  1112. int x, y;
  1113. if (from_screen) {
  1114. src = g_screen_ptr;
  1115. w = g_screen_width;
  1116. h = g_screen_height;
  1117. pp = g_screen_ppitch;
  1118. }
  1119. if (src == NULL) {
  1120. memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
  1121. return;
  1122. }
  1123. if (!no_scale && g_menuscreen_w / w >= 2 && g_menuscreen_h / h >= 2)
  1124. {
  1125. u32 t, *d = g_menubg_ptr;
  1126. d += (g_menuscreen_h / 2 - h * 2 / 2)
  1127. * g_menuscreen_w / 2;
  1128. d += (g_menuscreen_w / 2 - w * 2 / 2) / 2;
  1129. for (y = 0; y < h; y++, src += pp, d += g_menuscreen_w*2/2) {
  1130. for (x = 0; x < w; x++) {
  1131. t = src[x];
  1132. t = ((t & 0xf79e)>>1) - ((t & 0xc618)>>3);
  1133. t |= t << 16;
  1134. d[x] = d[x + g_menuscreen_w / 2] = t;
  1135. }
  1136. }
  1137. return;
  1138. }
  1139. if (w > g_menuscreen_w)
  1140. w = g_menuscreen_w;
  1141. if (h > g_menuscreen_h)
  1142. h = g_menuscreen_h;
  1143. dst = (short *)g_menubg_ptr +
  1144. (g_menuscreen_h / 2 - h / 2) * g_menuscreen_w +
  1145. (g_menuscreen_w / 2 - w / 2);
  1146. // darken the active framebuffer
  1147. for (; h > 0; dst += g_menuscreen_w, src += pp, h--)
  1148. menu_darken_bg(dst, src, w, 1);
  1149. }
  1150. static void copy_bg(int dir)
  1151. {
  1152. unsigned short *bg = (void *)g_menubg_ptr;
  1153. unsigned short *sc = (void *)g_menuscreen_ptr;
  1154. int h = g_menuscreen_h;
  1155. for (; h > 0; sc += g_menuscreen_pp, bg += g_menuscreen_w, h--) {
  1156. if (dir)
  1157. memcpy(bg, sc, g_menuscreen_w * 2);
  1158. else
  1159. memcpy(sc, bg, g_menuscreen_w * 2);
  1160. }
  1161. }
  1162. static void menu_enter(int is_rom_loaded)
  1163. {
  1164. if (is_rom_loaded)
  1165. {
  1166. make_bg(0, 0);
  1167. }
  1168. else
  1169. {
  1170. int pos;
  1171. char buff[256];
  1172. pos = plat_get_skin_dir(buff, 256);
  1173. strcpy(buff + pos, "background.png");
  1174. // should really only happen once, on startup..
  1175. if (readpng(g_menubg_ptr, buff, READPNG_BG,
  1176. g_menuscreen_w, g_menuscreen_h) < 0)
  1177. memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
  1178. }
  1179. plat_video_menu_enter(is_rom_loaded);
  1180. }
  1181. static void draw_savestate_bg(int slot)
  1182. {
  1183. const char *fname;
  1184. void *tmp_state;
  1185. fname = emu_get_save_fname(1, 0, slot, NULL);
  1186. if (!fname)
  1187. return;
  1188. tmp_state = PicoTmpStateSave();
  1189. PicoStateLoadGfx(fname);
  1190. /* do a frame and fetch menu bg */
  1191. pemu_forced_frame(0, 0);
  1192. make_bg(0, 1);
  1193. PicoTmpStateRestore(tmp_state);
  1194. }
  1195. // --------- loading ROM screen ----------
  1196. static int cdload_called = 0;
  1197. static void load_progress_cb(int percent)
  1198. {
  1199. int ln, len = percent * g_menuscreen_w / 100;
  1200. unsigned short *dst;
  1201. if (len > g_menuscreen_w)
  1202. len = g_menuscreen_w;
  1203. menu_draw_begin(0, 1);
  1204. copy_bg(0);
  1205. dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_pp * me_sfont_h * 2;
  1206. for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_pp)
  1207. memset(dst, 0xff, len * 2);
  1208. menu_draw_end();
  1209. }
  1210. static void cdload_progress_cb(const char *fname, int percent)
  1211. {
  1212. int ln, len = percent * g_menuscreen_w / 100;
  1213. unsigned short *dst;
  1214. menu_draw_begin(0, 1);
  1215. dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_pp * me_sfont_h * 2;
  1216. copy_bg(0);
  1217. menuscreen_memset_lines(dst, 0xff, me_sfont_h - 2);
  1218. smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
  1219. smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);
  1220. dst += g_menuscreen_pp * me_sfont_h * 3;
  1221. if (len > g_menuscreen_w)
  1222. len = g_menuscreen_w;
  1223. for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_pp)
  1224. memset(dst, 0xff, len * 2);
  1225. menu_draw_end();
  1226. cdload_called = 1;
  1227. }
  1228. void menu_romload_prepare(const char *rom_name)
  1229. {
  1230. #ifndef ALLOW_TEXT_OUT
  1231. return;
  1232. #endif //ALLOW_TEXT_OUT
  1233. const char *p = rom_name + strlen(rom_name);
  1234. while (p > rom_name && *p != '/')
  1235. p--;
  1236. menu_draw_begin(1, 1);
  1237. smalltext_out16(1, 1, "Loading", 0xffff);
  1238. smalltext_out16(1, me_sfont_h, p, 0xffff);
  1239. /* copy menu to bg for callbacks. OK since we are not in menu_loop here */
  1240. copy_bg(1);
  1241. menu_draw_end();
  1242. PicoCartLoadProgressCB = load_progress_cb;
  1243. PicoCDLoadProgressCB = cdload_progress_cb;
  1244. cdload_called = 0;
  1245. }
  1246. void menu_romload_end(void)
  1247. {
  1248. #ifndef ALLOW_TEXT_OUT
  1249. return;
  1250. #endif //ALLOW_TEXT_OUT
  1251. PicoCartLoadProgressCB = NULL;
  1252. PicoCDLoadProgressCB = NULL;
  1253. menu_draw_begin(0, 1);
  1254. copy_bg(0);
  1255. smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
  1256. "Starting emulation...", 0xffff);
  1257. menu_draw_end();
  1258. }
  1259. // ------------ patch/gg menu ------------
  1260. static void draw_patchlist(int sel)
  1261. {
  1262. int max_cnt, start, i, pos, active;
  1263. max_cnt = g_menuscreen_h / me_sfont_h;
  1264. start = max_cnt / 2 - sel;
  1265. menu_draw_begin(1, 0);
  1266. for (i = 0; i < PicoPatchCount; i++) {
  1267. pos = start + i;
  1268. if (pos < 0) continue;
  1269. if (pos >= max_cnt) break;
  1270. active = PicoPatches[i].active;
  1271. smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
  1272. smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
  1273. }
  1274. pos = start + i;
  1275. if (pos < max_cnt)
  1276. smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
  1277. text_out16(5, max_cnt / 2 * me_sfont_h, ">");
  1278. menu_draw_end();
  1279. }
  1280. static void menu_loop_patches(void)
  1281. {
  1282. static int menu_sel = 0;
  1283. int inp;
  1284. for (;;)
  1285. {
  1286. draw_patchlist(menu_sel);
  1287. inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R
  1288. |PBTN_MOK|PBTN_MBACK, NULL, 33);
  1289. if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
  1290. if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
  1291. if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
  1292. if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
  1293. if (inp & PBTN_MOK) { // action
  1294. if (menu_sel < PicoPatchCount)
  1295. PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
  1296. else break;
  1297. }
  1298. if (inp & PBTN_MBACK)
  1299. break;
  1300. }
  1301. }
  1302. // -------------- key config --------------
  1303. // PicoIn.pad[] format: MXYZ SACB RLDU
  1304. me_bind_action me_ctrl_actions[] =
  1305. {
  1306. { "UP ", 0x0001 },
  1307. { "DOWN ", 0x0002 },
  1308. { "LEFT ", 0x0004 },
  1309. { "RIGHT ", 0x0008 },
  1310. { "A ", 0x0040 },
  1311. { "B ", 0x0010 },
  1312. { "C ", 0x0020 },
  1313. { "A turbo", 0x4000 },
  1314. { "B turbo", 0x1000 },
  1315. { "C turbo", 0x2000 },
  1316. { "START ", 0x0080 },
  1317. { "MODE ", 0x0800 },
  1318. { "X ", 0x0400 },
  1319. { "Y ", 0x0200 },
  1320. { "Z ", 0x0100 },
  1321. { NULL, 0 },
  1322. };
  1323. me_bind_action emuctrl_actions[] =
  1324. {
  1325. { "Load State ", PEV_STATE_LOAD },
  1326. { "Save State ", PEV_STATE_SAVE },
  1327. { "Prev Save Slot ", PEV_SSLOT_PREV },
  1328. { "Next Save Slot ", PEV_SSLOT_NEXT },
  1329. { "Switch Renderer ", PEV_SWITCH_RND },
  1330. { "Volume Down ", PEV_VOL_DOWN },
  1331. { "Volume Up ", PEV_VOL_UP },
  1332. { "Fast forward ", PEV_FF },
  1333. { "Reset Game ", PEV_RESET },
  1334. { "Enter Menu ", PEV_MENU },
  1335. { "Pico Next page ", PEV_PICO_PNEXT },
  1336. { "Pico Prev page ", PEV_PICO_PPREV },
  1337. { "Pico Switch input", PEV_PICO_SWINP },
  1338. { NULL, 0 }
  1339. };
  1340. static int key_config_loop_wrap(int id, int keys)
  1341. {
  1342. switch (id) {
  1343. case MA_CTRL_PLAYER1:
  1344. key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
  1345. break;
  1346. case MA_CTRL_PLAYER2:
  1347. key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
  1348. break;
  1349. case MA_CTRL_EMU:
  1350. key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
  1351. break;
  1352. default:
  1353. break;
  1354. }
  1355. return 0;
  1356. }
  1357. static const char *mgn_dev_name(int id, int *offs)
  1358. {
  1359. const char *name = NULL;
  1360. static int it = 0;
  1361. if (id == MA_CTRL_DEV_FIRST)
  1362. it = 0;
  1363. for (; it < IN_MAX_DEVS; it++) {
  1364. name = in_get_dev_name(it, 1, 1);
  1365. if (name != NULL)
  1366. break;
  1367. }
  1368. it++;
  1369. return name;
  1370. }
  1371. static int mh_saveloadcfg(int id, int keys);
  1372. static const char *mgn_saveloadcfg(int id, int *offs);
  1373. const char *indev_names[] = { "none", "3 button pad", "6 button pad", NULL };
  1374. static menu_entry e_menu_keyconfig[] =
  1375. {
  1376. mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
  1377. mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
  1378. mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
  1379. mee_enum ("Input device 1", MA_OPT_INPUT_DEV0, currentConfig.input_dev0, indev_names),
  1380. mee_enum ("Input device 2", MA_OPT_INPUT_DEV1, currentConfig.input_dev1, indev_names),
  1381. mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
  1382. mee_range ("Analog deadzone", MA_CTRL_DEADZONE, currentConfig.analog_deadzone, 1, 99),
  1383. mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
  1384. mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
  1385. mee_label (""),
  1386. mee_label ("Input devices:"),
  1387. mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
  1388. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  1389. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  1390. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  1391. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  1392. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  1393. mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
  1394. mee_end,
  1395. };
  1396. static int menu_loop_keyconfig(int id, int keys)
  1397. {
  1398. static int sel = 0;
  1399. me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
  1400. me_loop(e_menu_keyconfig, &sel);
  1401. PicoSetInputDevice(0, currentConfig.input_dev0);
  1402. PicoSetInputDevice(1, currentConfig.input_dev1);
  1403. return 0;
  1404. }
  1405. // ------------ SCD options menu ------------
  1406. static const char h_cdleds[] = "Show power/CD LEDs of emulated console";
  1407. static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins";
  1408. static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music";
  1409. static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n"
  1410. "most games don't need this";
  1411. static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n"
  1412. "disable to improve performance";
  1413. static menu_entry e_menu_cd_options[] =
  1414. {
  1415. mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds),
  1416. mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoIn.opt, POPT_EN_MCD_CDDA, h_cdda),
  1417. mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoIn.opt, POPT_EN_MCD_PCM, h_cdpcm),
  1418. mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoIn.opt, POPT_EN_MCD_RAMCART, h_srcart),
  1419. mee_onoff_h("Scale/Rot. fx", MA_CDOPT_SCALEROT_CHIP, PicoIn.opt, POPT_EN_MCD_GFX, h_scfx),
  1420. mee_end,
  1421. };
  1422. static int menu_loop_cd_options(int id, int keys)
  1423. {
  1424. static int sel = 0;
  1425. me_loop(e_menu_cd_options, &sel);
  1426. return 0;
  1427. }
  1428. // ------------ 32X options menu ------------
  1429. #ifndef NO_32X
  1430. // convert from multiplier of VClk
  1431. static int mh_opt_sh2cycles(int id, int keys)
  1432. {
  1433. int *khz = (id == MA_32XOPT_MSH2_CYCLES) ?
  1434. &currentConfig.msh2_khz : &currentConfig.ssh2_khz;
  1435. if (keys & (PBTN_LEFT|PBTN_RIGHT))
  1436. *khz += (keys & PBTN_LEFT) ? -50 : 50;
  1437. if (keys & (PBTN_L|PBTN_R))
  1438. *khz += (keys & PBTN_L) ? -500 : 500;
  1439. if (*khz < 1)
  1440. *khz = 1;
  1441. else if (*khz > 0x7fffffff / 1000)
  1442. *khz = 0x7fffffff / 1000;
  1443. return 0;
  1444. }
  1445. static const char *mgn_opt_sh2cycles(int id, int *offs)
  1446. {
  1447. int khz = (id == MA_32XOPT_MSH2_CYCLES) ?
  1448. currentConfig.msh2_khz : currentConfig.ssh2_khz;
  1449. sprintf(static_buff, "%d", khz);
  1450. return static_buff;
  1451. }
  1452. static const char h_32x_enable[] = "Enable emulation of the 32X addon";
  1453. static const char h_pwm[] = "Disabling may improve performance, but break sound";
  1454. static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n"
  1455. "lower values speed up emulation but break games\n"
  1456. "at least 11000 recommended for compatibility";
  1457. static menu_entry e_menu_32x_options[] =
  1458. {
  1459. mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoIn.opt, POPT_EN_32X, h_32x_enable),
  1460. mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x),
  1461. mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoIn.opt, POPT_EN_PWM, h_pwm),
  1462. mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
  1463. mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
  1464. mee_end,
  1465. };
  1466. static int menu_loop_32x_options(int id, int keys)
  1467. {
  1468. static int sel = 0;
  1469. me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
  1470. me_loop(e_menu_32x_options, &sel);
  1471. Pico32xSetClocks(currentConfig.msh2_khz * 1000, currentConfig.msh2_khz * 1000);
  1472. return 0;
  1473. }
  1474. #endif
  1475. // ------------ adv options menu ------------
  1476. static const char h_ovrclk[] = "Will break some games, keep at 0";
  1477. static menu_entry e_menu_adv_options[] =
  1478. {
  1479. mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoIn.opt, POPT_DIS_SPRITE_LIM),
  1480. mee_range_h ("Overclock M68k (%)", MA_OPT2_OVERCLOCK_M68K,currentConfig.overclock_68k, 0, 1000, h_ovrclk),
  1481. mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoIn.opt, POPT_EN_Z80),
  1482. mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoIn.opt, POPT_EN_FM),
  1483. mee_onoff ("Disable YM2612 SSG-EG", MA_OPT2_DISABLE_YM_SSG,PicoIn.opt, POPT_DIS_FM_SSGEG),
  1484. mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoIn.opt, POPT_EN_PSG),
  1485. mee_onoff ("Emulate YM2413 (FM)", MA_OPT2_ENABLE_YM2413 ,PicoIn.opt, POPT_EN_YM2413),
  1486. mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoIn.opt, POPT_DIS_IDLE_DET),
  1487. mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
  1488. mee_onoff ("Enable dynarecs", MA_OPT2_DYNARECS, PicoIn.opt, POPT_EN_DRC),
  1489. mee_range ("Max auto frameskip", MA_OPT2_MAX_FRAMESKIP, currentConfig.max_skip, 1, 10),
  1490. mee_onoff ("PWM IRQ optimization", MA_OPT2_PWM_IRQ_OPT, PicoIn.opt, POPT_PWM_IRQ_OPT),
  1491. MENU_OPTIONS_ADV
  1492. mee_end,
  1493. };
  1494. static int menu_loop_adv_options(int id, int keys)
  1495. {
  1496. static int sel = 0;
  1497. me_loop(e_menu_adv_options, &sel);
  1498. PicoIn.overclockM68k = currentConfig.overclock_68k; // int vs short
  1499. return 0;
  1500. }
  1501. // ------------ sound options menu ------------
  1502. static int sndrate_prevnext(int rate, int dir)
  1503. {
  1504. static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
  1505. int i;
  1506. for (i = 0; i < 5; i++)
  1507. if (rates[i] == rate) break;
  1508. i += dir ? 1 : -1;
  1509. if (i > 4) {
  1510. if (!(PicoIn.opt & POPT_EN_STEREO)) {
  1511. PicoIn.opt |= POPT_EN_STEREO;
  1512. return rates[0];
  1513. }
  1514. return rates[4];
  1515. }
  1516. if (i < 0) {
  1517. if (PicoIn.opt & POPT_EN_STEREO) {
  1518. PicoIn.opt &= ~POPT_EN_STEREO;
  1519. return rates[4];
  1520. }
  1521. return rates[0];
  1522. }
  1523. return rates[i];
  1524. }
  1525. static int mh_opt_snd(int id, int keys)
  1526. {
  1527. PicoIn.sndRate = sndrate_prevnext(PicoIn.sndRate, keys & PBTN_RIGHT);
  1528. return 0;
  1529. }
  1530. static const char *mgn_opt_sound(int id, int *offs)
  1531. {
  1532. const char *str2;
  1533. *offs = -8;
  1534. str2 = (PicoIn.opt & POPT_EN_STEREO) ? "stereo" : "mono";
  1535. sprintf(static_buff, "%5iHz %s", PicoIn.sndRate, str2);
  1536. return static_buff;
  1537. }
  1538. static int mh_opt_alpha(int id, int keys)
  1539. {
  1540. int val = (PicoIn.sndFilterAlpha * 100 + 0x08000) / 0x10000;
  1541. if (keys & PBTN_LEFT) val--;
  1542. if (keys & PBTN_RIGHT) val++;
  1543. if (val < 1) val = 1;
  1544. if (val > 99) val = 99;
  1545. PicoIn.sndFilterAlpha = val * 0x10000 / 100;
  1546. return 0;
  1547. }
  1548. static const char *mgn_opt_alpha(int id, int *offs)
  1549. {
  1550. int val = (PicoIn.sndFilterAlpha * 100 + 0x08000) / 0x10000;
  1551. sprintf(static_buff, "0.%02d", val);
  1552. return static_buff;
  1553. }
  1554. static const char h_lowpass[] = "Low pass filter for sound closer to real hardware";
  1555. static menu_entry e_menu_snd_options[] =
  1556. {
  1557. mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
  1558. mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_snd, mgn_opt_sound),
  1559. mee_onoff_h ("Sound filter", MA_OPT_SOUND_FILTER, PicoIn.opt, POPT_EN_SNDFILTER, h_lowpass),
  1560. mee_cust ("Filter strength", MA_OPT_SOUND_ALPHA, mh_opt_alpha, mgn_opt_alpha),
  1561. mee_end,
  1562. };
  1563. static int menu_loop_snd_options(int id, int keys)
  1564. {
  1565. static int sel = 0;
  1566. me_loop(e_menu_snd_options, &sel);
  1567. return 0;
  1568. }
  1569. // ------------ gfx options menu ------------
  1570. static const char h_gamma[] = "Gamma/brightness adjustment (default 1.00)";
  1571. static const char *mgn_opt_fskip(int id, int *offs)
  1572. {
  1573. if (currentConfig.Frameskip < 0)
  1574. return "Auto";
  1575. sprintf(static_buff, "%d", currentConfig.Frameskip);
  1576. return static_buff;
  1577. }
  1578. static const char *mgn_aopt_gamma(int id, int *offs)
  1579. {
  1580. sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma % 100);
  1581. return static_buff;
  1582. }
  1583. static menu_entry e_menu_gfx_options[] =
  1584. {
  1585. mee_enum ("Video output mode", MA_OPT_VOUT_MODE, plat_target.vout_method, men_dummy),
  1586. mee_enum ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
  1587. mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
  1588. mee_enum ("Filter", MA_OPT3_FILTERING, currentConfig.filter, men_dummy),
  1589. mee_range_cust_h("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma, h_gamma),
  1590. MENU_OPTIONS_GFX
  1591. mee_end,
  1592. };
  1593. static int menu_loop_gfx_options(int id, int keys)
  1594. {
  1595. static int sel = 0;
  1596. me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
  1597. me_loop(e_menu_gfx_options, &sel);
  1598. return 0;
  1599. }
  1600. // ------------ UI options menu ------------
  1601. static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
  1602. static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
  1603. "loading state or both";
  1604. static menu_entry e_menu_ui_options[] =
  1605. {
  1606. mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
  1607. mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES, currentConfig.confirm_save, men_confirm_save, h_confirm_save),
  1608. mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
  1609. mee_end,
  1610. };
  1611. static int menu_loop_ui_options(int id, int keys)
  1612. {
  1613. static int sel = 0;
  1614. me_loop(e_menu_ui_options, &sel);
  1615. return 0;
  1616. }
  1617. // ------------ options menu ------------
  1618. static menu_entry e_menu_options[];
  1619. static void region_prevnext(int right)
  1620. {
  1621. // jp_ntsc=1, jp_pal=2, usa=4, eu=8
  1622. static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
  1623. int i;
  1624. if (right) {
  1625. if (!PicoIn.regionOverride) {
  1626. for (i = 0; i < 6; i++)
  1627. if (rgn_orders[i] == PicoIn.autoRgnOrder) break;
  1628. if (i < 5) PicoIn.autoRgnOrder = rgn_orders[i+1];
  1629. else PicoIn.regionOverride=1;
  1630. }
  1631. else
  1632. PicoIn.regionOverride <<= 1;
  1633. if (PicoIn.regionOverride > 8)
  1634. PicoIn.regionOverride = 8;
  1635. } else {
  1636. if (!PicoIn.regionOverride) {
  1637. for (i = 0; i < 6; i++)
  1638. if (rgn_orders[i] == PicoIn.autoRgnOrder) break;
  1639. if (i > 0) PicoIn.autoRgnOrder = rgn_orders[i-1];
  1640. }
  1641. else
  1642. PicoIn.regionOverride >>= 1;
  1643. }
  1644. }
  1645. static int mh_opt_misc(int id, int keys)
  1646. {
  1647. switch (id) {
  1648. case MA_OPT_REGION:
  1649. region_prevnext(keys & PBTN_RIGHT);
  1650. break;
  1651. default:
  1652. break;
  1653. }
  1654. return 0;
  1655. }
  1656. static int mh_saveloadcfg(int id, int keys)
  1657. {
  1658. int ret;
  1659. if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
  1660. config_slot += (keys & PBTN_LEFT) ? -1 : 1;
  1661. if (config_slot < 0) config_slot = 9;
  1662. else if (config_slot > 9) config_slot = 0;
  1663. me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
  1664. return 0;
  1665. }
  1666. switch (id) {
  1667. case MA_OPT_SAVECFG:
  1668. case MA_OPT_SAVECFG_GAME:
  1669. if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
  1670. menu_update_msg("config saved");
  1671. else
  1672. menu_update_msg("failed to write config");
  1673. break;
  1674. case MA_OPT_LOADCFG:
  1675. ret = emu_read_config(rom_fname_loaded, 1);
  1676. if (!ret) ret = emu_read_config(NULL, 1);
  1677. if (ret) menu_update_msg("config loaded");
  1678. else menu_update_msg("failed to load config");
  1679. break;
  1680. default:
  1681. return 0;
  1682. }
  1683. return 1;
  1684. }
  1685. static int mh_restore_defaults(int id, int keys)
  1686. {
  1687. emu_set_defconfig();
  1688. menu_update_msg("defaults restored");
  1689. return 1;
  1690. }
  1691. static const char *mgn_opt_region(int id, int *offs)
  1692. {
  1693. static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
  1694. static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
  1695. int code = PicoIn.regionOverride;
  1696. int u, i = 0;
  1697. *offs = -6;
  1698. if (code) {
  1699. code <<= 1;
  1700. while ((code >>= 1)) i++;
  1701. if (i > 4)
  1702. return "unknown";
  1703. return names[i];
  1704. } else {
  1705. strcpy(static_buff, "Auto:");
  1706. for (u = 0; u < 3; u++) {
  1707. code = (PicoIn.autoRgnOrder >> u*4) & 0xf;
  1708. for (i = 0; code; code >>= 1, i++)
  1709. ;
  1710. strcat(static_buff, names_short[i]);
  1711. }
  1712. return static_buff;
  1713. }
  1714. }
  1715. static const char *mgn_saveloadcfg(int id, int *offs)
  1716. {
  1717. static_buff[0] = 0;
  1718. if (config_slot != 0)
  1719. sprintf(static_buff, "[%i]", config_slot);
  1720. return static_buff;
  1721. }
  1722. static menu_entry e_menu_options[] =
  1723. {
  1724. mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
  1725. mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
  1726. mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 3200),
  1727. mee_handler ("[Interface options]", menu_loop_ui_options),
  1728. mee_handler ("[Display options]", menu_loop_gfx_options),
  1729. mee_handler ("[Sound options]", menu_loop_snd_options),
  1730. mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
  1731. #ifndef NO_32X
  1732. mee_handler ("[32X options]", menu_loop_32x_options),
  1733. #endif
  1734. mee_handler ("[Advanced options]", menu_loop_adv_options),
  1735. mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
  1736. mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
  1737. mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
  1738. mee_handler ("Restore defaults", mh_restore_defaults),
  1739. mee_end,
  1740. };
  1741. static int menu_loop_options(int id, int keys)
  1742. {
  1743. static int sel = 0;
  1744. me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
  1745. me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
  1746. me_loop(e_menu_options, &sel);
  1747. return 0;
  1748. }
  1749. // ------------ debug menu ------------
  1750. #include <pico/debug.h>
  1751. extern void SekStepM68k(void);
  1752. static void mplayer_loop(void)
  1753. {
  1754. pemu_sound_start();
  1755. while (1)
  1756. {
  1757. PDebugZ80Frame();
  1758. if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
  1759. break;
  1760. emu_sound_wait();
  1761. }
  1762. emu_sound_stop();
  1763. }
  1764. static void draw_text_debug(const char *str, int skip, int from)
  1765. {
  1766. const char *p;
  1767. int line;
  1768. p = str;
  1769. while (skip-- > 0)
  1770. {
  1771. while (*p && *p != '\n')
  1772. p++;
  1773. if (*p == 0 || p[1] == 0)
  1774. return;
  1775. p++;
  1776. }
  1777. str = p;
  1778. for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
  1779. {
  1780. smalltext_out16(1, line * me_sfont_h, str, 0xffff);
  1781. while (*p && *p != '\n')
  1782. p++;
  1783. if (*p == 0)
  1784. break;
  1785. p++; str = p;
  1786. }
  1787. }
  1788. #ifdef __GNUC__
  1789. #define COMPILER "gcc " __VERSION__
  1790. #else
  1791. #define COMPILER
  1792. #endif
  1793. static void draw_frame_debug(void)
  1794. {
  1795. char layer_str[48] = "layers: ";
  1796. struct PicoVideo *pv = &Pico.video;
  1797. if (!(pv->debug_p & PVD_KILL_B)) memcpy(layer_str + 8, "B", 1);
  1798. if (!(pv->debug_p & PVD_KILL_A)) memcpy(layer_str + 10, "A", 1);
  1799. if (!(pv->debug_p & PVD_KILL_S_LO)) memcpy(layer_str + 12, "spr_lo", 6);
  1800. if (!(pv->debug_p & PVD_KILL_S_HI)) memcpy(layer_str + 19, "spr_hi", 6);
  1801. if (!(pv->debug_p & PVD_KILL_32X)) memcpy(layer_str + 26, "32x", 4);
  1802. pemu_forced_frame(1, 0);
  1803. make_bg(1, 1);
  1804. smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
  1805. smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
  1806. }
  1807. static void debug_menu_loop(void)
  1808. {
  1809. struct PicoVideo *pv = &Pico.video;
  1810. int inp, mode = 0;
  1811. int spr_offs = 0, dumped = 0;
  1812. char *tmp;
  1813. while (1)
  1814. {
  1815. menu_draw_begin(1, 0);
  1816. switch (mode)
  1817. {
  1818. case 0: tmp = PDebugMain();
  1819. plat_debug_cat(tmp);
  1820. draw_text_debug(tmp, 0, 0);
  1821. if (dumped) {
  1822. smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
  1823. g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
  1824. dumped = 0;
  1825. }
  1826. break;
  1827. case 1: draw_frame_debug();
  1828. break;
  1829. case 2: pemu_forced_frame(1, 0);
  1830. make_bg(1, 1);
  1831. PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr
  1832. + (g_menuscreen_h/2 - 240/2) * g_menuscreen_pp
  1833. + g_menuscreen_w/2 - 320/2, g_menuscreen_pp);
  1834. break;
  1835. case 3: menuscreen_memset_lines(g_menuscreen_ptr, 0, g_menuscreen_h);
  1836. PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_pp);
  1837. PDebugShowSprite((unsigned short *)g_menuscreen_ptr
  1838. + g_menuscreen_pp * 120 + g_menuscreen_w / 2 + 16,
  1839. g_menuscreen_pp, spr_offs);
  1840. draw_text_debug(PDebugSpriteList(), spr_offs, 6);
  1841. break;
  1842. case 4: tmp = PDebug32x();
  1843. draw_text_debug(tmp, 0, 0);
  1844. break;
  1845. }
  1846. menu_draw_end();
  1847. inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
  1848. PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 70);
  1849. if (inp & PBTN_MBACK) return;
  1850. if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
  1851. if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
  1852. switch (mode)
  1853. {
  1854. case 0:
  1855. if (inp & PBTN_MOK)
  1856. PDebugCPUStep();
  1857. if (inp & PBTN_MA3) {
  1858. while (inp & PBTN_MA3)
  1859. inp = in_menu_wait_any(NULL, -1);
  1860. mplayer_loop();
  1861. }
  1862. if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
  1863. mkdir("dumps", 0777);
  1864. PDebugDumpMem();
  1865. while (inp & PBTN_MA2) inp = in_menu_wait_any(NULL, -1);
  1866. dumped = 1;
  1867. }
  1868. break;
  1869. case 1:
  1870. if (inp & PBTN_LEFT) pv->debug_p ^= PVD_KILL_B;
  1871. if (inp & PBTN_RIGHT) pv->debug_p ^= PVD_KILL_A;
  1872. if (inp & PBTN_DOWN) pv->debug_p ^= PVD_KILL_S_LO;
  1873. if (inp & PBTN_UP) pv->debug_p ^= PVD_KILL_S_HI;
  1874. if (inp & PBTN_MA2) pv->debug_p ^= PVD_KILL_32X;
  1875. if (inp & PBTN_MOK) {
  1876. PicoIn.sndOut = NULL; // just in case
  1877. PicoIn.skipFrame = 1;
  1878. PicoFrame();
  1879. PicoIn.skipFrame = 0;
  1880. while (inp & PBTN_MOK) inp = in_menu_wait_any(NULL, -1);
  1881. }
  1882. break;
  1883. case 3:
  1884. if (inp & PBTN_DOWN) spr_offs++;
  1885. if (inp & PBTN_UP) spr_offs--;
  1886. if (spr_offs < 0) spr_offs = 0;
  1887. break;
  1888. }
  1889. }
  1890. }
  1891. // ------------ main menu ------------
  1892. static void draw_frame_credits(void)
  1893. {
  1894. smalltext_out16(4, 1, "build: " __DATE__ " " __TIME__, 0xe7fc);
  1895. }
  1896. static const char credits[] =
  1897. "PicoDrive v" VERSION "\n"
  1898. "(c) notaz, 2006-2013; irixxxx, 2018-2020\n\n"
  1899. "Credits:\n"
  1900. "fDave: initial code\n"
  1901. #ifdef EMU_C68K
  1902. " Cyclone 68000 core\n"
  1903. #else
  1904. "Stef, Chui: FAME/C 68k core\n"
  1905. #endif
  1906. #ifdef _USE_DRZ80
  1907. "Reesy & FluBBa: DrZ80 core\n"
  1908. #else
  1909. "Stef, NJ: CZ80 core\n"
  1910. #endif
  1911. "MAME devs: SH2, YM2612 and SN76496 cores\n"
  1912. "Eke, Stef: some Sega CD code\n"
  1913. "Inder, ketchupgun: graphics\n"
  1914. #ifdef __GP2X__
  1915. "Squidge: mmuhack\n"
  1916. "Dzz: ARM940 sample\n"
  1917. #endif
  1918. "\n"
  1919. "special thanks (for docs, ideas):\n"
  1920. " Charles MacDonald, Haze,\n"
  1921. " Stephane Dallongeville,\n"
  1922. " Lordus, Exophase, Rokas,\n"
  1923. " Eke, Nemesis, Tasco Deluxe";
  1924. static void menu_main_draw_status(void)
  1925. {
  1926. static time_t last_bat_read = 0;
  1927. static int last_bat_val = -1;
  1928. unsigned short *bp = g_menuscreen_ptr;
  1929. int bat_h = me_mfont_h * 2 / 3;
  1930. int i, u, w, wfill, batt_val;
  1931. struct tm *tmp;
  1932. time_t ltime;
  1933. char time_s[16];
  1934. if (!(currentConfig.EmuOpt & EOPT_SHOW_RTC))
  1935. return;
  1936. ltime = time(NULL);
  1937. tmp = gmtime(&ltime);
  1938. strftime(time_s, sizeof(time_s), "%H:%M", tmp);
  1939. text_out16(g_menuscreen_w - me_mfont_w * 6, me_mfont_h + 2, time_s);
  1940. if (ltime - last_bat_read > 10) {
  1941. last_bat_read = ltime;
  1942. last_bat_val = batt_val = plat_target_bat_capacity_get();
  1943. }
  1944. else
  1945. batt_val = last_bat_val;
  1946. if (batt_val < 0 || batt_val > 100)
  1947. return;
  1948. /* battery info */
  1949. bp += (me_mfont_h * 2 + 2) * g_menuscreen_pp + g_menuscreen_w - me_mfont_w * 3 - 3;
  1950. for (i = 0; i < me_mfont_w * 2; i++)
  1951. bp[i] = menu_text_color;
  1952. for (i = 0; i < me_mfont_w * 2; i++)
  1953. bp[i + g_menuscreen_pp * bat_h] = menu_text_color;
  1954. for (i = 0; i <= bat_h; i++)
  1955. bp[i * g_menuscreen_pp] =
  1956. bp[i * g_menuscreen_pp + me_mfont_w * 2] = menu_text_color;
  1957. for (i = 2; i < bat_h - 1; i++)
  1958. bp[i * g_menuscreen_pp - 1] =
  1959. bp[i * g_menuscreen_pp - 2] = menu_text_color;
  1960. w = me_mfont_w * 2 - 1;
  1961. wfill = batt_val * w / 100;
  1962. for (u = 1; u < bat_h; u++)
  1963. for (i = 0; i < wfill; i++)
  1964. bp[(w - i) + g_menuscreen_pp * u] = menu_text_color;
  1965. }
  1966. static int main_menu_handler(int id, int keys)
  1967. {
  1968. const char *ret_name;
  1969. switch (id)
  1970. {
  1971. case MA_MAIN_RESUME_GAME:
  1972. if (PicoGameLoaded)
  1973. return 1;
  1974. break;
  1975. case MA_MAIN_SAVE_STATE:
  1976. if (PicoGameLoaded)
  1977. return menu_loop_savestate(0);
  1978. break;
  1979. case MA_MAIN_LOAD_STATE:
  1980. if (PicoGameLoaded)
  1981. return menu_loop_savestate(1);
  1982. break;
  1983. case MA_MAIN_RESET_GAME:
  1984. if (PicoGameLoaded) {
  1985. emu_reset_game();
  1986. return 1;
  1987. }
  1988. break;
  1989. case MA_MAIN_LOAD_ROM:
  1990. rom_fname_reload = NULL;
  1991. ret_name = menu_loop_romsel(rom_fname_loaded,
  1992. sizeof(rom_fname_loaded), rom_exts, NULL);
  1993. if (ret_name != NULL) {
  1994. lprintf("selected file: %s\n", ret_name);
  1995. rom_fname_reload = ret_name;
  1996. engineState = PGS_ReloadRom;
  1997. return 1;
  1998. }
  1999. break;
  2000. case MA_MAIN_CHANGE_CD:
  2001. if (PicoIn.AHW & PAHW_MCD) {
  2002. // if cd is loaded, cdd_unload() triggers eject and
  2003. // returns 1, else we'll select and load new CD here
  2004. if (!cdd_unload())
  2005. menu_loop_tray();
  2006. return 1;
  2007. }
  2008. break;
  2009. case MA_MAIN_CREDITS:
  2010. draw_menu_message(credits, draw_frame_credits);
  2011. in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
  2012. break;
  2013. case MA_MAIN_EXIT:
  2014. engineState = PGS_Quit;
  2015. return 1;
  2016. case MA_MAIN_PATCHES:
  2017. if (PicoGameLoaded && PicoPatches) {
  2018. menu_loop_patches();
  2019. PicoPatchApply();
  2020. menu_update_msg("Patches applied");
  2021. }
  2022. break;
  2023. default:
  2024. lprintf("%s: something unknown selected\n", __FUNCTION__);
  2025. break;
  2026. }
  2027. return 0;
  2028. }
  2029. static menu_entry e_menu_main[] =
  2030. {
  2031. mee_label ("PicoDrive " VERSION),
  2032. mee_label (""),
  2033. mee_label (""),
  2034. mee_label (""),
  2035. mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
  2036. mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
  2037. mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
  2038. mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
  2039. mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
  2040. mee_handler_id("Change CD/ISO", MA_MAIN_CHANGE_CD, main_menu_handler),
  2041. mee_handler ("Change options", menu_loop_options),
  2042. mee_handler ("Configure controls", menu_loop_keyconfig),
  2043. mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
  2044. mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
  2045. mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
  2046. mee_end,
  2047. };
  2048. void menu_loop(void)
  2049. {
  2050. static int sel = 0;
  2051. me_enable(e_menu_main, MA_MAIN_RESUME_GAME, PicoGameLoaded);
  2052. me_enable(e_menu_main, MA_MAIN_SAVE_STATE, PicoGameLoaded);
  2053. me_enable(e_menu_main, MA_MAIN_LOAD_STATE, PicoGameLoaded);
  2054. me_enable(e_menu_main, MA_MAIN_RESET_GAME, PicoGameLoaded);
  2055. me_enable(e_menu_main, MA_MAIN_CHANGE_CD, PicoIn.AHW & PAHW_MCD);
  2056. me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
  2057. menu_enter(PicoGameLoaded);
  2058. in_set_config_int(0, IN_CFG_BLOCKING, 1);
  2059. me_loop_d(e_menu_main, &sel, NULL, menu_main_draw_status);
  2060. if (PicoGameLoaded) {
  2061. if (engineState == PGS_Menu)
  2062. engineState = PGS_Running;
  2063. /* wait until menu, ok, back is released */
  2064. while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
  2065. ;
  2066. }
  2067. in_set_config_int(0, IN_CFG_BLOCKING, 0);
  2068. plat_video_menu_leave();
  2069. }
  2070. void menu_loop_funkey(void)
  2071. {
  2072. in_set_config_int(0, IN_CFG_BLOCKING, 1);
  2073. run_menu_loop();
  2074. if (PicoGameLoaded) {
  2075. if (engineState == PGS_Menu)
  2076. engineState = PGS_Running;
  2077. /* wait until menu, ok, back is released */
  2078. /*while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
  2079. ;*/
  2080. }
  2081. in_set_config_int(0, IN_CFG_BLOCKING, 0);
  2082. plat_video_menu_leave();
  2083. }
  2084. // --------- CD tray close menu ----------
  2085. static int mh_tray_load_cd(int id, int keys)
  2086. {
  2087. const char *ret_name;
  2088. rom_fname_reload = NULL;
  2089. ret_name = menu_loop_romsel(rom_fname_loaded,
  2090. sizeof(rom_fname_loaded), rom_exts, NULL);
  2091. if (ret_name == NULL)
  2092. return 0;
  2093. rom_fname_reload = ret_name;
  2094. engineState = PGS_RestartRun;
  2095. return emu_swap_cd(ret_name);
  2096. }
  2097. static int mh_tray_nothing(int id, int keys)
  2098. {
  2099. return 1;
  2100. }
  2101. static menu_entry e_menu_tray[] =
  2102. {
  2103. mee_label ("The CD tray has opened."),
  2104. mee_label (""),
  2105. mee_label (""),
  2106. mee_handler("Load CD image", mh_tray_load_cd),
  2107. mee_handler("Insert nothing", mh_tray_nothing),
  2108. mee_end,
  2109. };
  2110. int menu_loop_tray(void)
  2111. {
  2112. int ret = 1, sel = 0;
  2113. menu_enter(PicoGameLoaded);
  2114. in_set_config_int(0, IN_CFG_BLOCKING, 1);
  2115. me_loop(e_menu_tray, &sel);
  2116. if (engineState != PGS_RestartRun) {
  2117. engineState = PGS_RestartRun;
  2118. ret = 0; /* no CD inserted */
  2119. }
  2120. while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
  2121. ;
  2122. in_set_config_int(0, IN_CFG_BLOCKING, 0);
  2123. plat_video_menu_leave();
  2124. return ret;
  2125. }
  2126. void menu_update_msg(const char *msg)
  2127. {
  2128. strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
  2129. menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
  2130. menu_error_time = plat_get_ticks_ms();
  2131. lprintf("msg: %s\n", menu_error_msg);
  2132. }
  2133. // ------------ util ------------
  2134. /* hidden options for config engine only */
  2135. static menu_entry e_menu_hidden[] =
  2136. {
  2137. mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoIn.opt, POPT_ACC_SPRITES),
  2138. mee_onoff("autoload savestates", MA_OPT_AUTOLOAD_SAVE, g_autostateld_opt, 1),
  2139. mee_end,
  2140. };
  2141. static menu_entry *e_menu_table[] =
  2142. {
  2143. e_menu_options,
  2144. e_menu_ui_options,
  2145. e_menu_snd_options,
  2146. e_menu_gfx_options,
  2147. e_menu_adv_options,
  2148. e_menu_cd_options,
  2149. #ifndef NO_32X
  2150. e_menu_32x_options,
  2151. #endif
  2152. e_menu_keyconfig,
  2153. e_menu_hidden,
  2154. };
  2155. static menu_entry *me_list_table = NULL;
  2156. static menu_entry *me_list_i = NULL;
  2157. menu_entry *me_list_get_first(void)
  2158. {
  2159. me_list_table = me_list_i = e_menu_table[0];
  2160. return me_list_i;
  2161. }
  2162. menu_entry *me_list_get_next(void)
  2163. {
  2164. int i;
  2165. me_list_i++;
  2166. if (me_list_i->name != NULL)
  2167. return me_list_i;
  2168. for (i = 0; i < array_size(e_menu_table); i++)
  2169. if (me_list_table == e_menu_table[i])
  2170. break;
  2171. if (i + 1 < array_size(e_menu_table))
  2172. me_list_table = me_list_i = e_menu_table[i + 1];
  2173. else
  2174. me_list_table = me_list_i = NULL;
  2175. return me_list_i;
  2176. }
  2177. void menu_init(void)
  2178. {
  2179. int i;
  2180. menu_init_base();
  2181. i = 0;
  2182. #if defined(_SVP_DRC) || defined(DRC_SH2)
  2183. i = 1;
  2184. #endif
  2185. me_enable(e_menu_adv_options, MA_OPT2_DYNARECS, i);
  2186. i = me_id2offset(e_menu_gfx_options, MA_OPT_VOUT_MODE);
  2187. e_menu_gfx_options[i].data = plat_target.vout_methods;
  2188. me_enable(e_menu_gfx_options, MA_OPT_VOUT_MODE,
  2189. plat_target.vout_methods != NULL);
  2190. i = me_id2offset(e_menu_gfx_options, MA_OPT3_FILTERING);
  2191. e_menu_gfx_options[i].data = plat_target.hwfilters;
  2192. me_enable(e_menu_gfx_options, MA_OPT3_FILTERING,
  2193. plat_target.hwfilters != NULL);
  2194. me_enable(e_menu_gfx_options, MA_OPT2_GAMMA,
  2195. plat_target.gamma_set != NULL);
  2196. i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
  2197. e_menu_options[i].enabled = 0;
  2198. if (plat_target.cpu_clock_set != NULL) {
  2199. e_menu_options[i].name = "CPU clock";
  2200. e_menu_options[i].enabled = 1;
  2201. }
  2202. }