123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664 |
- /*
- * PicoDrive
- * (C) notaz, 2010,2011
- *
- * This work is licensed under the terms of MAME license.
- * See COPYING file in the top-level directory.
- */
- #include <stdio.h>
- #include <string.h>
- #include <time.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <SDL/SDL_ttf.h>
- #include <SDL/SDL_image.h>
- #include "emu.h"
- #include "configfile_fk.h"
- #include "menu_pico.h"
- #include "input_pico.h"
- #include "../libpicofe/input.h"
- #include "version.h"
- #include <pico/pico_int.h>
- #include <pico/patch.h>
- #ifdef PANDORA
- #define MENU_X2 1
- #else
- #define MENU_X2 0
- #endif
- #if defined USE_BGR555
- #define COL_ROM 0x5eff
- #define COL_OTH 0x5ff5
- #elif defined USE_BGR565
- #define COL_ROM 0xfdf7
- #define COL_OTH 0xaff5
- #else
- #define COL_ROM 0xbdff
- #define COL_OTH 0xaff5
- #endif
- // FIXME
- #define REVISION "0"
- static const char *rom_exts[] = {
- "zip",
- "bin", "smd", "gen", "md",
- "iso", "cso", "cue", "chd",
- "32x",
- "sms",
- NULL
- };
- // rrrr rggg gggb bbbb
- static unsigned short fname2color(const char *fname)
- {
- static const char *other_exts[] = { "gmv", "pat" };
- const char *ext;
- int i;
- ext = strrchr(fname, '.');
- if (ext++ == NULL) {
- ext = fname + strlen(fname) - 3;
- if (ext < fname) ext = fname;
- }
- for (i = 0; rom_exts[i] != NULL; i++)
- if (strcasecmp(ext, rom_exts[i]) == 0) return COL_ROM;
- for (i = 0; i < array_size(other_exts); i++)
- if (strcasecmp(ext, other_exts[i]) == 0) return COL_OTH;
- return 0xffff;
- }
- #include <platform/libpicofe/menu.c>
- static const char *men_dummy[] = { NULL };
- /* platform specific options and handlers */
- #if defined(__GP2X__)
- #include <platform/gp2x/menu.c>
- #elif defined(__PSP__)
- #include <platform/psp/menu.c>
- #elif defined(PANDORA)
- #include <platform/pandora/menu.c>
- #else
- #include <platform/linux/menu.c>
- #endif
- /// -------------- DEFINES --------------
- #define MIN(a,b) (((a)<(b))?(a):(b))
- #define MAX(a,b) (((a)>(b))?(a):(b))
- #define ABS(x) (((x) < 0) ? (-x) : (x))
- //#define MENU_DEBUG
- #define MENU_ERROR
- #ifdef MENU_DEBUG
- #define MENU_DEBUG_PRINTF(...) printf(__VA_ARGS__);
- #else
- #define MENU_DEBUG_PRINTF(...)
- #endif //MENU_DEBUG
- #ifdef MENU_ERROR
- #define MENU_ERROR_PRINTF(...) printf(__VA_ARGS__);
- #else
- #define MENU_ERROR_PRINTF(...)
- #endif //MENU_ERROR
- #define RES_HW_SCREEN_HORIZONTAL 240
- #define RES_HW_SCREEN_VERTICAL 240
- #define SCREEN_HORIZONTAL_SIZE 240
- #define SCREEN_VERTICAL_SIZE 240
- #define SCROLL_SPEED_PX 30
- #define FPS_MENU 50
- #define ARROWS_PADDING 8
- #define MENU_ZONE_WIDTH SCREEN_HORIZONTAL_SIZE
- #define MENU_ZONE_HEIGHT SCREEN_VERTICAL_SIZE
- #define MENU_BG_SQUARE_WIDTH 180
- #define MENU_BG_SQUARE_HEIGHT 140
- #define MENU_FONT_NAME_TITLE "/usr/games/menu_resources/OpenSans-Bold.ttf"
- #define MENU_FONT_SIZE_TITLE 22
- #define MENU_FONT_NAME_INFO "/usr/games/menu_resources/OpenSans-Bold.ttf"
- #define MENU_FONT_SIZE_INFO 16
- #define MENU_FONT_NAME_SMALL_INFO "/usr/games/menu_resources/OpenSans-Regular.ttf"
- #define MENU_FONT_SIZE_SMALL_INFO 13
- #define MENU_PNG_BG_PATH "/usr/games/menu_resources/zone_bg.png"
- #define MENU_PNG_ARROW_TOP_PATH "/usr/games/menu_resources/arrow_top.png"
- #define MENU_PNG_ARROW_BOTTOM_PATH "/usr/games/menu_resources/arrow_bottom.png"
- #define GRAY_MAIN_R 85
- #define GRAY_MAIN_G 85
- #define GRAY_MAIN_B 85
- #define WHITE_MAIN_R 236
- #define WHITE_MAIN_G 236
- #define WHITE_MAIN_B 236
- #define MAX_SAVE_SLOTS 9
- #define MAXPATHLEN 512
- /// -------------- STATIC VARIABLES --------------
- extern SDL_Surface * hw_screen;
- extern SDL_Surface * virtual_hw_screen;
- SDL_Surface * draw_screen;
- static int backup_key_repeat_delay, backup_key_repeat_interval;
- static SDL_Surface * backup_hw_screen = NULL;
- static TTF_Font *menu_title_font = NULL;
- static TTF_Font *menu_info_font = NULL;
- static TTF_Font *menu_small_info_font = NULL;
- static SDL_Surface *img_arrow_top = NULL;
- static SDL_Surface *img_arrow_bottom = NULL;
- static SDL_Surface ** menu_zone_surfaces = NULL;
- static int * idx_menus = NULL;
- static int nb_menu_zones = 0;
- static int menuItem = 0;
- int stop_menu_loop = 0;
- static SDL_Color text_color = {GRAY_MAIN_R, GRAY_MAIN_G, GRAY_MAIN_B};
- static int padding_y_from_center_menu_zone = 18;
- static uint16_t width_progress_bar = 100;
- static uint16_t height_progress_bar = 20;
- static uint16_t x_volume_bar = 0;
- static uint16_t y_volume_bar = 0;
- static uint16_t x_brightness_bar = 0;
- static uint16_t y_brightness_bar = 0;
- int volume_percentage = 0;
- int brightness_percentage = 0;
- static int quick_load_slot_chosen = 0;
- #undef X
- #define X(a, b) b,
- const char *resume_options_str[] = {RESUME_OPTIONS};
- /// -------------- FUNCTIONS IMPLEMENTATION --------------
- void init_menu_SDL(){
- /// ----- Loading the fonts -----
- menu_title_font = TTF_OpenFont(MENU_FONT_NAME_TITLE, MENU_FONT_SIZE_TITLE);
- if(!menu_title_font){
- MENU_ERROR_PRINTF("ERROR in init_menu_SDL: Could not open menu font %s, %s\n", MENU_FONT_NAME_TITLE, SDL_GetError());
- }
- menu_info_font = TTF_OpenFont(MENU_FONT_NAME_INFO, MENU_FONT_SIZE_INFO);
- if(!menu_info_font){
- MENU_ERROR_PRINTF("ERROR in init_menu_SDL: Could not open menu font %s, %s\n", MENU_FONT_NAME_INFO, SDL_GetError());
- }
- menu_small_info_font = TTF_OpenFont(MENU_FONT_NAME_SMALL_INFO, MENU_FONT_SIZE_SMALL_INFO);
- if(!menu_small_info_font){
- MENU_ERROR_PRINTF("ERROR in init_menu_SDL: Could not open menu font %s, %s\n", MENU_FONT_NAME_SMALL_INFO, SDL_GetError());
- }
- /// ----- Copy draw_screen at init ------
- backup_hw_screen = SDL_CreateRGBSurface(SDL_SWSURFACE,
- virtual_hw_screen->w, virtual_hw_screen->h, 16, 0, 0, 0, 0);
- if(backup_hw_screen == NULL){
- MENU_ERROR_PRINTF("ERROR in init_menu_SDL: Could not create backup_hw_screen: %s\n", SDL_GetError());
- }
- draw_screen = SDL_CreateRGBSurface(SDL_SWSURFACE,
- virtual_hw_screen->w, virtual_hw_screen->h, 16, 0, 0, 0, 0);
- if(draw_screen == NULL){
- MENU_ERROR_PRINTF("ERROR in init_menu_SDL: Could not create draw_screen: %s\n", SDL_GetError());
- }
- /// ------ Load arrows imgs -------
- img_arrow_top = IMG_Load(MENU_PNG_ARROW_TOP_PATH);
- if(!img_arrow_top) {
- MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
- }
- img_arrow_bottom = IMG_Load(MENU_PNG_ARROW_BOTTOM_PATH);
- if(!img_arrow_bottom) {
- MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
- }
- /// ------ Init menu zones ------
- init_menu_zones();
- }
- void deinit_menu_SDL(){
- /// ------ Close font -------
- TTF_CloseFont(menu_title_font);
- TTF_CloseFont(menu_info_font);
- TTF_CloseFont(menu_small_info_font);
- /// ------ Free Surfaces -------
- for(int i=0; i < nb_menu_zones; i++){
- SDL_FreeSurface(menu_zone_surfaces[i]);
- }
- SDL_FreeSurface(backup_hw_screen);
- SDL_FreeSurface(draw_screen);
- SDL_FreeSurface(img_arrow_top);
- SDL_FreeSurface(img_arrow_bottom);
- /// ------ Free Menu memory and reset vars -----
- if(idx_menus){
- free(idx_menus);
- }
- idx_menus=NULL;
- nb_menu_zones = 0;
- }
- void draw_progress_bar(SDL_Surface * surface, uint16_t x, uint16_t y, uint16_t width,
- uint16_t height, uint8_t percentage, uint16_t nb_bars){
- /// ------ Init Variables ------
- uint16_t line_width = 1; //px
- uint16_t padding_bars_ratio = 3;
- uint16_t nb_full_bars = 0;
- /// ------ Check values ------
- percentage = (percentage > 100)?100:percentage;
- x = (x > (surface->w-1))?(surface->w-1):x;
- y = (y > surface->h-1)?(surface->h-1):y;
- width = (width < line_width*2+1)?(line_width*2+1):width;
- width = (width > surface->w-x-1)?(surface->w-x-1):width;
- height = (height < line_width*2+1)?(line_width*2+1):height;
- height = (height > surface->h-y-1)?(surface->h-y-1):height;
- uint16_t nb_bars_max = ( width * padding_bars_ratio / (line_width*2+1) + 1 ) / (padding_bars_ratio+1);
- nb_bars = (nb_bars > nb_bars_max)?nb_bars_max:nb_bars;
- uint16_t bar_width = (width / nb_bars)*padding_bars_ratio/(padding_bars_ratio+1)+1;
- uint16_t bar_padding_x = bar_width/padding_bars_ratio;
- nb_full_bars = nb_bars*percentage/100;
- /// ------ draw full bars ------
- for (int i = 0; i < nb_full_bars; ++i)
- {
- /// ---- draw one bar ----
- //MENU_DEBUG_PRINTF("Drawing filled bar %d\n", i);
- SDL_Rect rect = {x+ i*(bar_width +bar_padding_x),
- y, bar_width, height};
- SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, GRAY_MAIN_R, GRAY_MAIN_G, GRAY_MAIN_B));
- }
- /// ------ draw full bars ------
- for (int i = 0; i < (nb_bars-nb_full_bars); ++i)
- {
- /// ---- draw one bar ----
- //MENU_DEBUG_PRINTF("Drawing empty bar %d\n", i);
- SDL_Rect rect = {x+ i*(bar_width +bar_padding_x) + nb_full_bars*(bar_width +bar_padding_x),
- y, bar_width, height};
- SDL_FillRect(surface, &rect, SDL_MapRGB(surface->format, GRAY_MAIN_R, GRAY_MAIN_G, GRAY_MAIN_B));
- SDL_Rect rect2 = {x+ i*(bar_width +bar_padding_x) + line_width + nb_full_bars*(bar_width +bar_padding_x),
- y + line_width, bar_width - line_width*2, height - line_width*2};
- SDL_FillRect(surface, &rect2, SDL_MapRGB(surface->format, WHITE_MAIN_R, WHITE_MAIN_R, WHITE_MAIN_R));
- }
- }
- void add_menu_zone(ENUM_MENU_TYPE menu_type){
- /// ------ Increase nb of menu zones -------
- nb_menu_zones++;
- /// ------ Realoc idx Menus array -------
- if(!idx_menus){
- idx_menus = malloc(nb_menu_zones*sizeof(int));
- menu_zone_surfaces = malloc(nb_menu_zones*sizeof(SDL_Surface*));
- }
- else{
- int *temp = realloc(idx_menus, nb_menu_zones*sizeof(int));
- idx_menus = temp;
- menu_zone_surfaces = realloc(menu_zone_surfaces, nb_menu_zones*sizeof(SDL_Surface*));
- }
- idx_menus[nb_menu_zones-1] = menu_type;
- /// ------ Reinit menu surface with height increased -------
- menu_zone_surfaces[nb_menu_zones-1] = IMG_Load(MENU_PNG_BG_PATH);
- if(!menu_zone_surfaces[nb_menu_zones-1]) {
- MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
- }
- /// --------- Init Common Variables --------
- SDL_Surface *text_surface = NULL;
- SDL_Surface *surface = menu_zone_surfaces[nb_menu_zones-1];
- SDL_Rect text_pos;
- /// --------- Add new zone ---------
- switch(menu_type){
- case MENU_TYPE_VOLUME:
- MENU_DEBUG_PRINTF("Init MENU_TYPE_VOLUME\n");
- /// ------ Text ------
- text_surface = TTF_RenderText_Blended(menu_title_font, "VOLUME", text_color);
- text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone;
- SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
- x_volume_bar = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - width_progress_bar)/2;
- y_volume_bar = surface->h - MENU_ZONE_HEIGHT/2 - height_progress_bar/2 + padding_y_from_center_menu_zone;
- draw_progress_bar(surface, x_volume_bar, y_volume_bar,
- width_progress_bar, height_progress_bar, 0, 100/STEP_CHANGE_VOLUME);
- break;
- case MENU_TYPE_BRIGHTNESS:
- MENU_DEBUG_PRINTF("Init MENU_TYPE_BRIGHTNESS\n");
- /// ------ Text ------
- text_surface = TTF_RenderText_Blended(menu_title_font, "BRIGHTNESS", text_color);
- text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone;
- SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
- x_brightness_bar = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - width_progress_bar)/2;
- y_brightness_bar = surface->h - MENU_ZONE_HEIGHT/2 - height_progress_bar/2 + padding_y_from_center_menu_zone;
- draw_progress_bar(surface, x_brightness_bar, y_brightness_bar,
- width_progress_bar, height_progress_bar, 0, 100/STEP_CHANGE_BRIGHTNESS);
- break;
- case MENU_TYPE_SAVE:
- MENU_DEBUG_PRINTF("Init MENU_TYPE_SAVE\n");
- /// ------ Text ------
- text_surface = TTF_RenderText_Blended(menu_title_font, "SAVE", text_color);
- text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone*2;
- SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
- break;
- case MENU_TYPE_LOAD:
- MENU_DEBUG_PRINTF("Init MENU_TYPE_LOAD\n");
- /// ------ Text ------
- text_surface = TTF_RenderText_Blended(menu_title_font, "LOAD", text_color);
- text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone*2;
- SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
- break;
- case MENU_TYPE_ASPECT_RATIO:
- MENU_DEBUG_PRINTF("Init MENU_TYPE_ASPECT_RATIO\n");
- /// ------ Text ------
- text_surface = TTF_RenderText_Blended(menu_title_font, "ASPECT RATIO", text_color);
- text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 - padding_y_from_center_menu_zone;
- SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
- break;
- case MENU_TYPE_EXIT:
- MENU_DEBUG_PRINTF("Init MENU_TYPE_EXIT\n");
- /// ------ Text ------
- text_surface = TTF_RenderText_Blended(menu_title_font, "EXIT GAME", text_color);
- text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
- SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
- break;
- case MENU_TYPE_POWERDOWN:
- MENU_DEBUG_PRINTF("Init MENU_TYPE_POWERDOWN\n");
- /// ------ Text ------
- text_surface = TTF_RenderText_Blended(menu_title_font, "POWERDOWN", text_color);
- text_pos.x = (surface->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = surface->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
- SDL_BlitSurface(text_surface, NULL, surface, &text_pos);
- break;
- default:
- MENU_DEBUG_PRINTF("Warning - In add_menu_zone, unknown MENU_TYPE: %d\n", menu_type);
- break;
- }
- /// ------ Free Surfaces -------
- SDL_FreeSurface(text_surface);
- }
- void init_menu_zones(){
- /// Init Volume Menu
- add_menu_zone(MENU_TYPE_VOLUME);
- /// Init Brightness Menu
- add_menu_zone(MENU_TYPE_BRIGHTNESS);
- /// Init Save Menu
- add_menu_zone(MENU_TYPE_SAVE);
- /// Init Load Menu
- add_menu_zone(MENU_TYPE_LOAD);
- /// Init Aspect Ratio Menu
- add_menu_zone(MENU_TYPE_ASPECT_RATIO);
- /// Init Exit Menu
- add_menu_zone(MENU_TYPE_EXIT);
- /// Init Powerdown Menu
- //add_menu_zone(MENU_TYPE_POWERDOWN);
- }
- void init_menu_system_values(){
- FILE *fp;
- char res[100];
- /// ------- Get system volume percentage --------
- fp = popen(SHELL_CMD_VOLUME_GET, "r");
- if (fp == NULL) {
- MENU_ERROR_PRINTF("Failed to run command %s\n", SHELL_CMD_VOLUME_GET );
- volume_percentage = 50; ///wrong value: setting default to 50
- }
- else{
- fgets(res, sizeof(res)-1, fp);
- pclose(fp);
- /// Check if Volume is a number (at least the first char)
- if(res[0] < '0' || res[0] > '9'){
- MENU_ERROR_PRINTF("Wrong return value: %s for volume cmd: %s\n",res, SHELL_CMD_VOLUME_GET);
- volume_percentage = 50; ///wrong value: setting default to 50
- }
- else{
- volume_percentage = atoi(res);
- MENU_DEBUG_PRINTF("System volume = %d%%\n", volume_percentage);
- }
- }
- /// ------- Get system brightness percentage -------
- fp = popen(SHELL_CMD_BRIGHTNESS_GET, "r");
- if (fp == NULL) {
- MENU_ERROR_PRINTF("Failed to run command %s\n", SHELL_CMD_BRIGHTNESS_GET );
- brightness_percentage = 50; ///wrong value: setting default to 50
- }
- else{
- fgets(res, sizeof(res)-1, fp);
- pclose(fp);
- /// Check if brightness is a number (at least the first char)
- if(res[0] < '0' || res[0] > '9'){
- MENU_ERROR_PRINTF("Wrong return value: %s for volume cmd: %s\n",res, SHELL_CMD_BRIGHTNESS_GET);
- brightness_percentage = 50; ///wrong value: setting default to 50
- }
- else{
- brightness_percentage = atoi(res);
- MENU_DEBUG_PRINTF("System brightness = %d%%\n", brightness_percentage);
- }
- }
- /// ------ Save prev key repeat params and set new Key repeat -------
- SDL_GetKeyRepeat(&backup_key_repeat_delay, &backup_key_repeat_interval);
- if(SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL)){
- MENU_ERROR_PRINTF("ERROR with SDL_EnableKeyRepeat: %s\n", SDL_GetError());
- }
- /// Get save slot from game
- state_slot = (state_slot%MAX_SAVE_SLOTS); // security
- }
- void menu_screen_refresh(int menuItem, int prevItem, int scroll, uint8_t menu_confirmation, uint8_t menu_action){
- /// --------- Vars ---------
- int print_arrows = (scroll==0)?1:0;
- /// --------- Clear HW screen ----------
- //SDL_FillRect(draw_screen, NULL, SDL_MapRGB(draw_screen->format, 255, 0, 0));
- if(SDL_BlitSurface(backup_hw_screen, NULL, draw_screen, NULL)){
- MENU_ERROR_PRINTF("ERROR Could not Clear draw_screen: %s\n", SDL_GetError());
- }
- /// --------- Setup Blit Window ----------
- SDL_Rect menu_blit_window;
- menu_blit_window.x = 0;
- menu_blit_window.w = SCREEN_HORIZONTAL_SIZE;
- /// --------- Blit prev menu Zone going away ----------
- menu_blit_window.y = scroll;
- menu_blit_window.h = SCREEN_VERTICAL_SIZE;
- if(SDL_BlitSurface(menu_zone_surfaces[prevItem], &menu_blit_window, draw_screen, NULL)){
- MENU_ERROR_PRINTF("ERROR Could not Blit surface on draw_screen: %s\n", SDL_GetError());
- }
- /// --------- Blit new menu Zone going in (only during animations) ----------
- if(scroll>0){
- menu_blit_window.y = SCREEN_VERTICAL_SIZE-scroll;
- menu_blit_window.h = SCREEN_VERTICAL_SIZE;
- if(SDL_BlitSurface(menu_zone_surfaces[menuItem], NULL, draw_screen, &menu_blit_window)){
- MENU_ERROR_PRINTF("ERROR Could not Blit surface on draw_screen: %s\n", SDL_GetError());
- }
- }
- else if(scroll<0){
- menu_blit_window.y = SCREEN_VERTICAL_SIZE+scroll;
- menu_blit_window.h = SCREEN_VERTICAL_SIZE;
- if(SDL_BlitSurface(menu_zone_surfaces[menuItem], &menu_blit_window, draw_screen, NULL)){
- MENU_ERROR_PRINTF("ERROR Could not Blit surface on draw_screen: %s\n", SDL_GetError());
- }
- }
- /// --------- No Scroll ? Blitting menu-specific info
- else{
- SDL_Surface * text_surface = NULL;
- char text_tmp[40];
- SDL_Rect text_pos;
- /*char fname[MAXPATHLEN];
- memset(fname, 0, MAXPATHLEN);*/
- char *fname = NULL;
- uint16_t limit_filename_size = 24;
- switch(idx_menus[menuItem]){
- case MENU_TYPE_VOLUME:
- draw_progress_bar(draw_screen, x_volume_bar, y_volume_bar,
- width_progress_bar, height_progress_bar, volume_percentage, 100/STEP_CHANGE_VOLUME);
- break;
- case MENU_TYPE_BRIGHTNESS:
- draw_progress_bar(draw_screen, x_volume_bar, y_volume_bar,
- width_progress_bar, height_progress_bar, brightness_percentage, 100/STEP_CHANGE_BRIGHTNESS);
- break;
- case MENU_TYPE_SAVE:
- /// ---- Write slot -----
- sprintf(text_tmp, "IN SLOT < %d >", state_slot+1);
- text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
- text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
- SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
- if(menu_action){
- sprintf(text_tmp, "Saving...");
- text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
- }
- else{
- if(menu_confirmation){
- sprintf(text_tmp, "Are you sure ?");
- text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
- }
- else{
- fname = emu_get_save_fname(1, 0, state_slot, NULL);
- if (fname == NULL) {
- text_surface = TTF_RenderText_Blended(menu_info_font, "Free", text_color);
- }
- else{
- printf("Found saved file: %s\n", fname);
- char *p = strrchr (fname, '/');
- char *basename = p ? p + 1 : (char *) fname;
- if(strlen(basename) > limit_filename_size){basename[limit_filename_size]=0;} //limiting size
- text_surface = TTF_RenderText_Blended(menu_small_info_font, basename, text_color);
- }
- }
- }
- text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 + 2*padding_y_from_center_menu_zone;
- SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
- break;
- case MENU_TYPE_LOAD:
- /// ---- Write slot -----
- if(quick_load_slot_chosen){
- sprintf(text_tmp, "FROM AUTO SAVE");
- }
- else{
- sprintf(text_tmp, "FROM SLOT < %d >", state_slot+1);
- }
- text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
- text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
- SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
- if(menu_action){
- sprintf(text_tmp, "Loading...");
- text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
- }
- else{
- if(menu_confirmation){
- sprintf(text_tmp, "Are you sure ?");
- text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
- }
- else{
- if(quick_load_slot_chosen){
- text_surface = TTF_RenderText_Blended(menu_info_font, " ", text_color);
- }
- else{
- fname = emu_get_save_fname(1, 0, state_slot, NULL);
- if (fname == NULL) {
- text_surface = TTF_RenderText_Blended(menu_info_font, "Free", text_color);
- }
- else{
- printf("Found saved file: %s\n", fname);
- char *p = strrchr (fname, '/');
- char *basename = p ? p + 1 : (char *) fname;
- if(strlen(basename) > limit_filename_size){basename[limit_filename_size]=0;} //limiting size
- text_surface = TTF_RenderText_Blended(menu_small_info_font, basename, text_color);
- }
- }
- }
- }
- text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 + 2*padding_y_from_center_menu_zone;
- SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
- break;
- case MENU_TYPE_ASPECT_RATIO:
- sprintf(text_tmp, "< %s >", aspect_ratio_name[aspect_ratio]);
- text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
- text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 + padding_y_from_center_menu_zone;
- SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
- break;
- case MENU_TYPE_EXIT:
- case MENU_TYPE_POWERDOWN:
- if(menu_confirmation){
- sprintf(text_tmp, "Are you sure ?");
- text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
- text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 + 2*padding_y_from_center_menu_zone;
- SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
- }
- break;
- default:
- break;
- }
- /// ------ Free Surfaces -------
- if(text_surface)
- SDL_FreeSurface(text_surface);
- }
- /// --------- Print arrows --------
- if(print_arrows){
- /// Top arrow
- SDL_Rect pos_arrow_top;
- pos_arrow_top.x = (draw_screen->w - img_arrow_top->w)/2;
- pos_arrow_top.y = (draw_screen->h - MENU_BG_SQUARE_HEIGHT)/4 - img_arrow_top->h/2;
- SDL_BlitSurface(img_arrow_top, NULL, draw_screen, &pos_arrow_top);
- /// Bottom arrow
- SDL_Rect pos_arrow_bottom;
- pos_arrow_bottom.x = (draw_screen->w - img_arrow_bottom->w)/2;
- pos_arrow_bottom.y = draw_screen->h -
- (draw_screen->h - MENU_BG_SQUARE_HEIGHT)/4 - img_arrow_bottom->h/2;
- SDL_BlitSurface(img_arrow_bottom, NULL, draw_screen, &pos_arrow_bottom);
- }
- // Rotate
- //SDL_Rotate_270(hw_screen, virtual_hw_screen);
- SDL_BlitSurface(draw_screen, NULL, hw_screen, NULL);
- /// --- Real Flip ---
- SDL_Flip(hw_screen);
- }
- void run_menu_loop()
- {
- MENU_DEBUG_PRINTF("Launch Menu\n");
- SDL_Event event;
- uint32_t prev_ms = SDL_GetTicks();
- uint32_t cur_ms = SDL_GetTicks();
- int scroll=0;
- int start_scroll=0;
- uint8_t screen_refresh = 1;
- char shell_cmd[100];
- uint8_t menu_confirmation = 0;
- stop_menu_loop = 0;
- char fname[MAXPATHLEN];
- /// ------ Load default keymap ------
- system(SHELL_CMD_KEYMAP_DEFAULT);
- /// ------ Get init values -------
- init_menu_system_values();
- int prevItem=menuItem;
- /// ------ Copy currently displayed screen -------
- /* if(SDL_BlitSurface(virtual_hw_screen, NULL, backup_hw_screen, NULL)){
- MENU_ERROR_PRINTF("ERROR Could not copy draw_screen: %s\n", SDL_GetError());
- }*/
- memcpy(backup_hw_screen->pixels, (uint16_t*) virtual_hw_screen->pixels,
- RES_HW_SCREEN_HORIZONTAL * RES_HW_SCREEN_VERTICAL * sizeof(uint16_t));
- /* Stop Ampli */
- system(SHELL_CMD_AUDIO_AMP_OFF);
- /// ------ Wait for menu UP key event ------
- int actions[IN_BINDTYPE_COUNT] = { 0, };
- while(event.type != SDL_KEYUP || event.key.keysym.sym != SDLK_q){
- while (SDL_PollEvent(&event)){
- SDL_PushEvent(&event);
- in_update(actions);
- }
- /* 500ms timeout */
- if(SDL_GetTicks() - cur_ms > 500){
- MENU_ERROR_PRINTF("Timeout waiting for SDLK_q UP\n");
- break;
- }
- }
- /// -------- Main loop ---------
- while (!stop_menu_loop)
- {
- /// -------- Handle Keyboard Events ---------
- if(!scroll){
- while (SDL_PollEvent(&event))
- switch(event.type)
- {
- case SDL_QUIT:
- engineState = PGS_Quit;
- stop_menu_loop = 1;
- break;
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym)
- {
- case SDLK_b:
- if(menu_confirmation){
- /// ------ Reset menu confirmation ------
- menu_confirmation = 0;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- /*else{
- stop_menu_loop = 1;
- }*/
- break;
- case SDLK_q:
- case SDLK_ESCAPE:
- stop_menu_loop = 1;
- break;
- case SDLK_d:
- case SDLK_DOWN:
- MENU_DEBUG_PRINTF("DOWN\n");
- /// ------ Start scrolling to new menu -------
- menuItem++;
- if (menuItem>=nb_menu_zones) menuItem=0;
- scroll=1;
- /// ------ Reset menu confirmation ------
- menu_confirmation = 0;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- break;
- case SDLK_u:
- case SDLK_UP:
- MENU_DEBUG_PRINTF("UP\n");
- /// ------ Start scrolling to new menu -------
- menuItem--;
- if (menuItem<0) menuItem=nb_menu_zones-1;
- scroll=-1;
- /// ------ Reset menu confirmation ------
- menu_confirmation = 0;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- break;
- case SDLK_l:
- case SDLK_LEFT:
- //MENU_DEBUG_PRINTF("LEFT\n");
- if(idx_menus[menuItem] == MENU_TYPE_VOLUME){
- MENU_DEBUG_PRINTF("Volume DOWN\n");
- /// ----- Compute new value -----
- volume_percentage = (volume_percentage < STEP_CHANGE_VOLUME)?
- 0:(volume_percentage-STEP_CHANGE_VOLUME);
- /// ----- Shell cmd ----
- sprintf(shell_cmd, "%s %d", SHELL_CMD_VOLUME_SET, volume_percentage);
- system(shell_cmd);
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- else if(idx_menus[menuItem] == MENU_TYPE_BRIGHTNESS){
- MENU_DEBUG_PRINTF("Brightness DOWN\n");
- /// ----- Compute new value -----
- brightness_percentage = (brightness_percentage < STEP_CHANGE_BRIGHTNESS)?
- 0:(brightness_percentage-STEP_CHANGE_BRIGHTNESS);
- /// ----- Shell cmd ----
- sprintf(shell_cmd, "%s %d", SHELL_CMD_BRIGHTNESS_SET, brightness_percentage);
- system(shell_cmd);
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- else if(idx_menus[menuItem] == MENU_TYPE_SAVE){
- MENU_DEBUG_PRINTF("Save Slot DOWN\n");
- state_slot = (!state_slot)?(MAX_SAVE_SLOTS-1):(state_slot-1);
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- else if(idx_menus[menuItem] == MENU_TYPE_LOAD){
- MENU_DEBUG_PRINTF("Load Slot DOWN\n");
- /** Choose quick save file or standard saveslot for loading */
- if(!quick_load_slot_chosen &&
- state_slot == 0 &&
- access(quick_save_file, F_OK ) != -1){
- quick_load_slot_chosen = 1;
- }
- else if(quick_load_slot_chosen){
- quick_load_slot_chosen = 0;
- state_slot = MAX_SAVE_SLOTS-1;
- }
- else{
- state_slot = (!state_slot)?(MAX_SAVE_SLOTS-1):(state_slot-1);
- }
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- else if(idx_menus[menuItem] == MENU_TYPE_ASPECT_RATIO){
- MENU_DEBUG_PRINTF("Aspect Ratio DOWN\n");
- aspect_ratio = (!aspect_ratio)?(NB_ASPECT_RATIOS_TYPES-1):(aspect_ratio-1);
-
- /// ------ Refresh screen ------
- screen_refresh = 1;
- // Save config file
- configfile_save(cfg_file_rom);
- }
- break;
- case SDLK_r:
- case SDLK_RIGHT:
- //MENU_DEBUG_PRINTF("RIGHT\n");
- if(idx_menus[menuItem] == MENU_TYPE_VOLUME){
- MENU_DEBUG_PRINTF("Volume UP\n");
- /// ----- Compute new value -----
- volume_percentage = (volume_percentage > 100 - STEP_CHANGE_VOLUME)?
- 100:(volume_percentage+STEP_CHANGE_VOLUME);
- /// ----- Shell cmd ----
- sprintf(shell_cmd, "%s %d", SHELL_CMD_VOLUME_SET, volume_percentage);
- system(shell_cmd);
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- else if(idx_menus[menuItem] == MENU_TYPE_BRIGHTNESS){
- MENU_DEBUG_PRINTF("Brightness UP\n");
- /// ----- Compute new value -----
- brightness_percentage = (brightness_percentage > 100 - STEP_CHANGE_BRIGHTNESS)?
- 100:(brightness_percentage+STEP_CHANGE_BRIGHTNESS);
- /// ----- Shell cmd ----
- sprintf(shell_cmd, "%s %d", SHELL_CMD_BRIGHTNESS_SET, brightness_percentage);
- system(shell_cmd);
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- else if(idx_menus[menuItem] == MENU_TYPE_SAVE){
- MENU_DEBUG_PRINTF("Save Slot UP\n");
- state_slot = (state_slot+1)%MAX_SAVE_SLOTS;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- else if(idx_menus[menuItem] == MENU_TYPE_LOAD){
- MENU_DEBUG_PRINTF("Load Slot UP\n");
- /** Choose quick save file or standard saveslot for loading */
- if(!quick_load_slot_chosen &&
- state_slot == MAX_SAVE_SLOTS-1 &&
- access(quick_save_file, F_OK ) != -1){
- quick_load_slot_chosen = 1;
- }
- else if(quick_load_slot_chosen){
- quick_load_slot_chosen = 0;
- state_slot = 0;
- }
- else{
- state_slot = (state_slot+1)%MAX_SAVE_SLOTS;
- }
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- else if(idx_menus[menuItem] == MENU_TYPE_ASPECT_RATIO){
- MENU_DEBUG_PRINTF("Aspect Ratio UP\n");
- aspect_ratio = (aspect_ratio+1)%NB_ASPECT_RATIOS_TYPES;
-
- /// ------ Refresh screen ------
- screen_refresh = 1;
- // Save config file
- configfile_save(cfg_file_rom);
- }
- break;
- case SDLK_a:
- case SDLK_RETURN:
- if(idx_menus[menuItem] == MENU_TYPE_SAVE){
- if(menu_confirmation){
- MENU_DEBUG_PRINTF("Saving in slot %d\n", state_slot);
- /// ------ Refresh Screen -------
- menu_screen_refresh(menuItem, prevItem, scroll, menu_confirmation, 1);
- /// ------ Save game ------
- int ret = emu_save_load_game(0, 0);
- /// ----- Hud Msg -----
- if(ret){
- MENU_ERROR_PRINTF("Save Failed\n");
- sprintf(shell_cmd, "%s %d \" SAVE FAILED\"",
- SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP);
- }
- else{
- sprintf(shell_cmd, "%s %d \" SAVED IN SLOT %d\"",
- SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP, state_slot+1);
- }
- system(shell_cmd);
- stop_menu_loop = 1;
- }
- else{
- MENU_DEBUG_PRINTF("Save game - asking confirmation\n");
- menu_confirmation = 1;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- }
- else if(idx_menus[menuItem] == MENU_TYPE_LOAD){
- if(menu_confirmation){
- MENU_DEBUG_PRINTF("Loading in slot %d\n", state_slot);
- /// ------ Refresh Screen -------
- menu_screen_refresh(menuItem, prevItem, scroll, menu_confirmation, 1);
- /// ------ Load game ------
- int ret;
- if(quick_load_slot_chosen){
- ret = emu_save_load_game_from_file(1, quick_save_file);
- }
- else{
- ret = emu_save_load_game(1, 0);
- }
- /// ----- Hud Msg -----
- if(ret){
- MENU_ERROR_PRINTF("Load Failed\n");
- sprintf(shell_cmd, "%s %d \" LOAD FAILED\"",
- SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP);
- }
- else{
- if(quick_load_slot_chosen){
- sprintf(shell_cmd, "%s %d \" LOADED FROM AUTO SAVE\"",
- SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP);
- }
- else{
- sprintf(shell_cmd, "%s %d \" LOADED FROM SLOT %d\"",
- SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP, state_slot+1);
- }
- }
- system(shell_cmd);
- /*snprintf(hud_msg, sizeof(hud_msg), ret == 0 ? "LOADED" : "FAIL!");
- hud_new_msg = 3;*/
- stop_menu_loop = 1;
- }
- else{
- MENU_DEBUG_PRINTF("Save game - asking confirmation\n");
- menu_confirmation = 1;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- }
- else if(idx_menus[menuItem] == MENU_TYPE_EXIT){
- MENU_DEBUG_PRINTF("Exit game\n");
- if(menu_confirmation){
- MENU_DEBUG_PRINTF("Exit game - confirmed\n");
- /// ----- The game should be saved here ----
- int ret = emu_save_load_game_from_file(0, quick_save_file);
- /// ----- Exit game and back to launcher ----
- engineState = PGS_Quit;
- stop_menu_loop = 1;
- }
- else{
- MENU_DEBUG_PRINTF("Exit game - asking confirmation\n");
- menu_confirmation = 1;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- }
- else if(idx_menus[menuItem] == MENU_TYPE_POWERDOWN){
- if(menu_confirmation){
- MENU_DEBUG_PRINTF("Powerdown - confirmed\n");
- /// ----- Shell cmd ----
- execlp(SHELL_CMD_SHUTDOWN_FUNKEY, SHELL_CMD_SHUTDOWN_FUNKEY, NULL);
- MENU_ERROR_PRINTF("Failed to run command %s\n", SHELL_CMD_SHUTDOWN_FUNKEY);
- exit(0);
- }
- else{
- MENU_DEBUG_PRINTF("Powerdown - asking confirmation\n");
- menu_confirmation = 1;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- }
- break;
- default:
- //MENU_DEBUG_PRINTF("Keydown: %d\n", event.key.keysym.sym);
- break;
- }
- break;
- }
- }
- /// --------- Handle Scroll effect ---------
- if ((scroll>0) || (start_scroll>0)){
- scroll+=MIN(SCROLL_SPEED_PX, MENU_ZONE_HEIGHT-scroll);
- start_scroll = 0;
- screen_refresh = 1;
- }
- else if ((scroll<0) || (start_scroll<0)){
- scroll-=MIN(SCROLL_SPEED_PX, MENU_ZONE_HEIGHT+scroll);
- start_scroll = 0;
- screen_refresh = 1;
- }
- if (scroll>=MENU_ZONE_HEIGHT || scroll<=-MENU_ZONE_HEIGHT) {
- prevItem=menuItem;
- scroll=0;
- screen_refresh = 1;
- }
- /// --------- Handle FPS ---------
- cur_ms = SDL_GetTicks();
- if(cur_ms-prev_ms < 1000/FPS_MENU){
- SDL_Delay(1000/FPS_MENU - (cur_ms-prev_ms));
- }
- prev_ms = SDL_GetTicks();
- /// --------- Refresh screen
- if(screen_refresh){
- menu_screen_refresh(menuItem, prevItem, scroll, menu_confirmation, 0);
- }
- /// --------- reset screen refresh ---------
- screen_refresh = 0;
- }
- /// ------ Restore last keymap ------
- system(SHELL_CMD_KEYMAP_RESUME);
- /// ------ Reset prev key repeat params -------
- if(SDL_EnableKeyRepeat(backup_key_repeat_delay, backup_key_repeat_interval)){
- MENU_ERROR_PRINTF("ERROR with SDL_EnableKeyRepeat: %s\n", SDL_GetError());
- }
- /* Start Ampli */
- system(SHELL_CMD_AUDIO_AMP_ON);
- /// ------ Reset last screen ------
- SDL_BlitSurface(backup_hw_screen, NULL, hw_screen, NULL);
- SDL_Flip(hw_screen);
- }
- /****************************/
- /* Quick Resume Menu */
- /****************************/
- int launch_resume_menu_loop()
- {
- MENU_DEBUG_PRINTF("Init resume menu\n");
- /* Decare vars */
- SDL_Surface *text_surface = NULL;
- char text_tmp[40];
- SDL_Rect text_pos;
- SDL_Event event;
- uint32_t prev_ms = SDL_GetTicks();
- uint32_t cur_ms = SDL_GetTicks();
- stop_menu_loop = 0;
- uint8_t screen_refresh = 1;
- uint8_t menu_confirmation = 0;
- int option_idx=RESUME_YES;
- /* Stop Ampli */
- system(SHELL_CMD_AUDIO_AMP_OFF);
- /* Save prev key repeat params and set new Key repeat */
- SDL_GetKeyRepeat(&backup_key_repeat_delay, &backup_key_repeat_interval);
- if(SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL)){
- MENU_ERROR_PRINTF("ERROR with SDL_EnableKeyRepeat: %s\n", SDL_GetError());
- }
- /* Load BG */
- SDL_Surface *img_square_bg = IMG_Load(MENU_PNG_BG_PATH);
- if(!img_square_bg) {
- MENU_ERROR_PRINTF("ERROR IMG_Load: %s\n", IMG_GetError());
- }
- SDL_Surface *bg_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, hw_screen->w, hw_screen->h, 16, 0, 0, 0, 0);
- SDL_BlitSurface(img_square_bg, NULL, bg_surface, NULL);
- SDL_FreeSurface(img_square_bg);
- /* Print top arrow */
- SDL_Rect pos_arrow_top;
- pos_arrow_top.x = (bg_surface->w - img_arrow_top->w)/2;
- pos_arrow_top.y = (bg_surface->h - MENU_BG_SQUARE_HEIGHT)/4 - img_arrow_top->h/2;
- SDL_BlitSurface(img_arrow_top, NULL, bg_surface, &pos_arrow_top);
- /* Print bottom arrow */
- SDL_Rect pos_arrow_bottom;
- pos_arrow_bottom.x = (bg_surface->w - img_arrow_bottom->w)/2;
- pos_arrow_bottom.y = bg_surface->h -
- (bg_surface->h - MENU_BG_SQUARE_HEIGHT)/4 - img_arrow_bottom->h/2;
- SDL_BlitSurface(img_arrow_bottom, NULL, bg_surface, &pos_arrow_bottom);
- if (text_surface)
- SDL_FreeSurface(text_surface);
- /* Main loop */
- while (!stop_menu_loop)
- {
- /* Handle keyboard events */
- while (SDL_PollEvent(&event))
- switch(event.type)
- {
- case SDL_QUIT:
- engineState = PGS_Quit;
- stop_menu_loop = 1;
- break;
- case SDL_KEYDOWN:
- switch (event.key.keysym.sym)
- {
- case SDLK_b:
- if(menu_confirmation){
- /// ------ Reset menu confirmation ------
- menu_confirmation = 0;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- /*else{
- stop_menu_loop = 1;
- }*/
- break;
- case SDLK_q:
- case SDLK_ESCAPE:
- /*stop_menu_loop = 1;*/
- break;
- case SDLK_u:
- case SDLK_UP:
- MENU_DEBUG_PRINTF("Option UP\n");
- option_idx = (!option_idx)?(NB_RESUME_OPTIONS-1):(option_idx-1);
- /// ------ Reset menu confirmation ------
- menu_confirmation = 0;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- break;
- case SDLK_d:
- case SDLK_DOWN:
- MENU_DEBUG_PRINTF("Option DWON\n");
- option_idx = (option_idx+1)%NB_RESUME_OPTIONS;
- /// ------ Reset menu confirmation ------
- menu_confirmation = 0;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- break;
- case SDLK_a:
- case SDLK_RETURN:
- MENU_DEBUG_PRINTF("Pressed A\n");
- if(menu_confirmation){
- MENU_DEBUG_PRINTF("Confirmed\n");
- /// ----- exit menu ----
- stop_menu_loop = 1;
- }
- else{
- MENU_DEBUG_PRINTF("Asking confirmation\n");
- menu_confirmation = 1;
- /// ------ Refresh screen ------
- screen_refresh = 1;
- }
- break;
- default:
- //MENU_DEBUG_PRINTF("Keydown: %d\n", event.key.keysym.sym);
- break;
- }
- break;
- }
- /* Handle FPS */
- cur_ms = SDL_GetTicks();
- if(cur_ms-prev_ms < 1000/FPS_MENU){
- SDL_Delay(1000/FPS_MENU - (cur_ms-prev_ms));
- }
- prev_ms = SDL_GetTicks();
- /* Refresh screen */
- if(screen_refresh){
- /* Clear and draw BG */
- SDL_FillRect(hw_screen, NULL, 0);
- if(SDL_BlitSurface(bg_surface, NULL, hw_screen, NULL)){
- MENU_ERROR_PRINTF("ERROR Could not draw background: %s\n", SDL_GetError());
- }
- /* Draw resume or reset option */
- text_surface = TTF_RenderText_Blended(menu_title_font, resume_options_str[option_idx], text_color);
- text_pos.x = (hw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = hw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2;
- SDL_BlitSurface(text_surface, NULL, hw_screen, &text_pos);
- /* Draw confirmation */
- if(menu_confirmation){
- sprintf(text_tmp, "Are you sure ?");
- text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
- text_pos.x = (hw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
- text_pos.y = hw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 + 2*padding_y_from_center_menu_zone;
- SDL_BlitSurface(text_surface, NULL, hw_screen, &text_pos);
- }
- /* Flip Screen */
- SDL_Flip(hw_screen);
- }
- /* reset screen refresh */
- screen_refresh = 0;
- }
- /// ----- Clear screen -----
- SDL_FillRect(hw_screen, NULL, 0);
- SDL_Flip(hw_screen);
- /* Free SDL Surfaces */
- if(bg_surface)
- SDL_FreeSurface(bg_surface);
- if(text_surface)
- SDL_FreeSurface(text_surface);
- /* Reset prev key repeat params */
- if(SDL_EnableKeyRepeat(backup_key_repeat_delay, backup_key_repeat_interval)){
- MENU_ERROR_PRINTF("ERROR with SDL_EnableKeyRepeat: %s\n", SDL_GetError());
- }
- /* Start Ampli */
- system(SHELL_CMD_AUDIO_AMP_ON);
- return option_idx;
- }
- static void make_bg(int no_scale, int from_screen)
- {
- unsigned short *src = (void *)g_menubg_src_ptr;
- int w = g_menubg_src_w ? g_menubg_src_w : g_screen_width;
- int h = g_menubg_src_h ? g_menubg_src_h : g_screen_height;
- int pp = g_menubg_src_pp ? g_menubg_src_pp : g_screen_ppitch;
- short *dst;
- int x, y;
- if (from_screen) {
- src = g_screen_ptr;
- w = g_screen_width;
- h = g_screen_height;
- pp = g_screen_ppitch;
- }
- if (src == NULL) {
- memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
- return;
- }
- if (!no_scale && g_menuscreen_w / w >= 2 && g_menuscreen_h / h >= 2)
- {
- u32 t, *d = g_menubg_ptr;
- d += (g_menuscreen_h / 2 - h * 2 / 2)
- * g_menuscreen_w / 2;
- d += (g_menuscreen_w / 2 - w * 2 / 2) / 2;
- for (y = 0; y < h; y++, src += pp, d += g_menuscreen_w*2/2) {
- for (x = 0; x < w; x++) {
- t = src[x];
- t = ((t & 0xf79e)>>1) - ((t & 0xc618)>>3);
- t |= t << 16;
- d[x] = d[x + g_menuscreen_w / 2] = t;
- }
- }
- return;
- }
- if (w > g_menuscreen_w)
- w = g_menuscreen_w;
- if (h > g_menuscreen_h)
- h = g_menuscreen_h;
- dst = (short *)g_menubg_ptr +
- (g_menuscreen_h / 2 - h / 2) * g_menuscreen_w +
- (g_menuscreen_w / 2 - w / 2);
- // darken the active framebuffer
- for (; h > 0; dst += g_menuscreen_w, src += pp, h--)
- menu_darken_bg(dst, src, w, 1);
- }
- static void copy_bg(int dir)
- {
- unsigned short *bg = (void *)g_menubg_ptr;
- unsigned short *sc = (void *)g_menuscreen_ptr;
- int h = g_menuscreen_h;
- for (; h > 0; sc += g_menuscreen_pp, bg += g_menuscreen_w, h--) {
- if (dir)
- memcpy(bg, sc, g_menuscreen_w * 2);
- else
- memcpy(sc, bg, g_menuscreen_w * 2);
- }
- }
- static void menu_enter(int is_rom_loaded)
- {
- if (is_rom_loaded)
- {
- make_bg(0, 0);
- }
- else
- {
- int pos;
- char buff[256];
- pos = plat_get_skin_dir(buff, 256);
- strcpy(buff + pos, "background.png");
- // should really only happen once, on startup..
- if (readpng(g_menubg_ptr, buff, READPNG_BG,
- g_menuscreen_w, g_menuscreen_h) < 0)
- memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2);
- }
- plat_video_menu_enter(is_rom_loaded);
- }
- static void draw_savestate_bg(int slot)
- {
- const char *fname;
- void *tmp_state;
- fname = emu_get_save_fname(1, 0, slot, NULL);
- if (!fname)
- return;
- tmp_state = PicoTmpStateSave();
- PicoStateLoadGfx(fname);
- /* do a frame and fetch menu bg */
- pemu_forced_frame(0, 0);
- make_bg(0, 1);
- PicoTmpStateRestore(tmp_state);
- }
- // --------- loading ROM screen ----------
- static int cdload_called = 0;
- static void load_progress_cb(int percent)
- {
- int ln, len = percent * g_menuscreen_w / 100;
- unsigned short *dst;
- if (len > g_menuscreen_w)
- len = g_menuscreen_w;
- menu_draw_begin(0, 1);
- copy_bg(0);
- dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_pp * me_sfont_h * 2;
- for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_pp)
- memset(dst, 0xff, len * 2);
- menu_draw_end();
- }
- static void cdload_progress_cb(const char *fname, int percent)
- {
- int ln, len = percent * g_menuscreen_w / 100;
- unsigned short *dst;
- menu_draw_begin(0, 1);
- dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_pp * me_sfont_h * 2;
- copy_bg(0);
- menuscreen_memset_lines(dst, 0xff, me_sfont_h - 2);
- smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);
- smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);
- dst += g_menuscreen_pp * me_sfont_h * 3;
- if (len > g_menuscreen_w)
- len = g_menuscreen_w;
- for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_pp)
- memset(dst, 0xff, len * 2);
- menu_draw_end();
- cdload_called = 1;
- }
- void menu_romload_prepare(const char *rom_name)
- {
- #ifndef ALLOW_TEXT_OUT
- return;
- #endif //ALLOW_TEXT_OUT
- const char *p = rom_name + strlen(rom_name);
- while (p > rom_name && *p != '/')
- p--;
- menu_draw_begin(1, 1);
- smalltext_out16(1, 1, "Loading", 0xffff);
- smalltext_out16(1, me_sfont_h, p, 0xffff);
- /* copy menu to bg for callbacks. OK since we are not in menu_loop here */
- copy_bg(1);
- menu_draw_end();
- PicoCartLoadProgressCB = load_progress_cb;
- PicoCDLoadProgressCB = cdload_progress_cb;
- cdload_called = 0;
- }
- void menu_romload_end(void)
- {
- #ifndef ALLOW_TEXT_OUT
- return;
- #endif //ALLOW_TEXT_OUT
- PicoCartLoadProgressCB = NULL;
- PicoCDLoadProgressCB = NULL;
- menu_draw_begin(0, 1);
- copy_bg(0);
- smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,
- "Starting emulation...", 0xffff);
- menu_draw_end();
- }
- // ------------ patch/gg menu ------------
- static void draw_patchlist(int sel)
- {
- int max_cnt, start, i, pos, active;
- max_cnt = g_menuscreen_h / me_sfont_h;
- start = max_cnt / 2 - sel;
- menu_draw_begin(1, 0);
- for (i = 0; i < PicoPatchCount; i++) {
- pos = start + i;
- if (pos < 0) continue;
- if (pos >= max_cnt) break;
- active = PicoPatches[i].active;
- smalltext_out16(14, pos * me_sfont_h, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);
- smalltext_out16(14 + me_sfont_w*4, pos * me_sfont_h, PicoPatches[i].name, active ? 0xfff6 : 0xffff);
- }
- pos = start + i;
- if (pos < max_cnt)
- smalltext_out16(14, pos * me_sfont_h, "done", 0xffff);
- text_out16(5, max_cnt / 2 * me_sfont_h, ">");
- menu_draw_end();
- }
- static void menu_loop_patches(void)
- {
- static int menu_sel = 0;
- int inp;
- for (;;)
- {
- draw_patchlist(menu_sel);
- inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R
- |PBTN_MOK|PBTN_MBACK, NULL, 33);
- if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
- if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
- if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
- if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }
- if (inp & PBTN_MOK) { // action
- if (menu_sel < PicoPatchCount)
- PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;
- else break;
- }
- if (inp & PBTN_MBACK)
- break;
- }
- }
- // -------------- key config --------------
- // PicoIn.pad[] format: MXYZ SACB RLDU
- me_bind_action me_ctrl_actions[] =
- {
- { "UP ", 0x0001 },
- { "DOWN ", 0x0002 },
- { "LEFT ", 0x0004 },
- { "RIGHT ", 0x0008 },
- { "A ", 0x0040 },
- { "B ", 0x0010 },
- { "C ", 0x0020 },
- { "A turbo", 0x4000 },
- { "B turbo", 0x1000 },
- { "C turbo", 0x2000 },
- { "START ", 0x0080 },
- { "MODE ", 0x0800 },
- { "X ", 0x0400 },
- { "Y ", 0x0200 },
- { "Z ", 0x0100 },
- { NULL, 0 },
- };
- me_bind_action emuctrl_actions[] =
- {
- { "Load State ", PEV_STATE_LOAD },
- { "Save State ", PEV_STATE_SAVE },
- { "Prev Save Slot ", PEV_SSLOT_PREV },
- { "Next Save Slot ", PEV_SSLOT_NEXT },
- { "Switch Renderer ", PEV_SWITCH_RND },
- { "Volume Down ", PEV_VOL_DOWN },
- { "Volume Up ", PEV_VOL_UP },
- { "Fast forward ", PEV_FF },
- { "Reset Game ", PEV_RESET },
- { "Enter Menu ", PEV_MENU },
- { "Pico Next page ", PEV_PICO_PNEXT },
- { "Pico Prev page ", PEV_PICO_PPREV },
- { "Pico Switch input", PEV_PICO_SWINP },
- { NULL, 0 }
- };
- static int key_config_loop_wrap(int id, int keys)
- {
- switch (id) {
- case MA_CTRL_PLAYER1:
- key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 0);
- break;
- case MA_CTRL_PLAYER2:
- key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions) - 1, 1);
- break;
- case MA_CTRL_EMU:
- key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);
- break;
- default:
- break;
- }
- return 0;
- }
- static const char *mgn_dev_name(int id, int *offs)
- {
- const char *name = NULL;
- static int it = 0;
- if (id == MA_CTRL_DEV_FIRST)
- it = 0;
- for (; it < IN_MAX_DEVS; it++) {
- name = in_get_dev_name(it, 1, 1);
- if (name != NULL)
- break;
- }
- it++;
- return name;
- }
- static int mh_saveloadcfg(int id, int keys);
- static const char *mgn_saveloadcfg(int id, int *offs);
- const char *indev_names[] = { "none", "3 button pad", "6 button pad", NULL };
- static menu_entry e_menu_keyconfig[] =
- {
- mee_handler_id("Player 1", MA_CTRL_PLAYER1, key_config_loop_wrap),
- mee_handler_id("Player 2", MA_CTRL_PLAYER2, key_config_loop_wrap),
- mee_handler_id("Emulator controls", MA_CTRL_EMU, key_config_loop_wrap),
- mee_enum ("Input device 1", MA_OPT_INPUT_DEV0, currentConfig.input_dev0, indev_names),
- mee_enum ("Input device 2", MA_OPT_INPUT_DEV1, currentConfig.input_dev1, indev_names),
- mee_range ("Turbo rate", MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),
- mee_range ("Analog deadzone", MA_CTRL_DEADZONE, currentConfig.analog_deadzone, 1, 99),
- mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
- mee_cust_nosave("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
- mee_label (""),
- mee_label ("Input devices:"),
- mee_label_mk (MA_CTRL_DEV_FIRST, mgn_dev_name),
- mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
- mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
- mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
- mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
- mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
- mee_label_mk (MA_CTRL_DEV_NEXT, mgn_dev_name),
- mee_end,
- };
- static int menu_loop_keyconfig(int id, int keys)
- {
- static int sel = 0;
- me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
- me_loop(e_menu_keyconfig, &sel);
- PicoSetInputDevice(0, currentConfig.input_dev0);
- PicoSetInputDevice(1, currentConfig.input_dev1);
- return 0;
- }
- // ------------ SCD options menu ------------
- static const char h_cdleds[] = "Show power/CD LEDs of emulated console";
- static const char h_cdda[] = "Play audio tracks from mp3s/wavs/bins";
- static const char h_cdpcm[] = "Emulate PCM audio chip for effects/voices/music";
- static const char h_srcart[] = "Emulate the save RAM cartridge accessory\n"
- "most games don't need this";
- static const char h_scfx[] = "Emulate scale/rotate ASIC chip for graphics effects\n"
- "disable to improve performance";
- static menu_entry e_menu_cd_options[] =
- {
- mee_onoff_h("CD LEDs", MA_CDOPT_LEDS, currentConfig.EmuOpt, EOPT_EN_CD_LEDS, h_cdleds),
- mee_onoff_h("CDDA audio", MA_CDOPT_CDDA, PicoIn.opt, POPT_EN_MCD_CDDA, h_cdda),
- mee_onoff_h("PCM audio", MA_CDOPT_PCM, PicoIn.opt, POPT_EN_MCD_PCM, h_cdpcm),
- mee_onoff_h("SaveRAM cart", MA_CDOPT_SAVERAM, PicoIn.opt, POPT_EN_MCD_RAMCART, h_srcart),
- mee_onoff_h("Scale/Rot. fx", MA_CDOPT_SCALEROT_CHIP, PicoIn.opt, POPT_EN_MCD_GFX, h_scfx),
- mee_end,
- };
- static int menu_loop_cd_options(int id, int keys)
- {
- static int sel = 0;
- me_loop(e_menu_cd_options, &sel);
- return 0;
- }
- // ------------ 32X options menu ------------
- #ifndef NO_32X
- // convert from multiplier of VClk
- static int mh_opt_sh2cycles(int id, int keys)
- {
- int *khz = (id == MA_32XOPT_MSH2_CYCLES) ?
- ¤tConfig.msh2_khz : ¤tConfig.ssh2_khz;
- if (keys & (PBTN_LEFT|PBTN_RIGHT))
- *khz += (keys & PBTN_LEFT) ? -50 : 50;
- if (keys & (PBTN_L|PBTN_R))
- *khz += (keys & PBTN_L) ? -500 : 500;
- if (*khz < 1)
- *khz = 1;
- else if (*khz > 0x7fffffff / 1000)
- *khz = 0x7fffffff / 1000;
- return 0;
- }
- static const char *mgn_opt_sh2cycles(int id, int *offs)
- {
- int khz = (id == MA_32XOPT_MSH2_CYCLES) ?
- currentConfig.msh2_khz : currentConfig.ssh2_khz;
- sprintf(static_buff, "%d", khz);
- return static_buff;
- }
- static const char h_32x_enable[] = "Enable emulation of the 32X addon";
- static const char h_pwm[] = "Disabling may improve performance, but break sound";
- static const char h_sh2cycles[] = "Cycles/millisecond (similar to DOSBox)\n"
- "lower values speed up emulation but break games\n"
- "at least 11000 recommended for compatibility";
- static menu_entry e_menu_32x_options[] =
- {
- mee_onoff_h ("32X enabled", MA_32XOPT_ENABLE_32X, PicoIn.opt, POPT_EN_32X, h_32x_enable),
- mee_enum ("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, renderer_names32x),
- mee_onoff_h ("PWM sound", MA_32XOPT_PWM, PicoIn.opt, POPT_EN_PWM, h_pwm),
- mee_cust_h ("Master SH2 cycles", MA_32XOPT_MSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
- mee_cust_h ("Slave SH2 cycles", MA_32XOPT_SSH2_CYCLES, mh_opt_sh2cycles, mgn_opt_sh2cycles, h_sh2cycles),
- mee_end,
- };
- static int menu_loop_32x_options(int id, int keys)
- {
- static int sel = 0;
- me_enable(e_menu_32x_options, MA_32XOPT_RENDERER, renderer_names32x[0] != NULL);
- me_loop(e_menu_32x_options, &sel);
- Pico32xSetClocks(currentConfig.msh2_khz * 1000, currentConfig.msh2_khz * 1000);
- return 0;
- }
- #endif
- // ------------ adv options menu ------------
- static const char h_ovrclk[] = "Will break some games, keep at 0";
- static menu_entry e_menu_adv_options[] =
- {
- mee_onoff ("Disable sprite limit", MA_OPT2_NO_SPRITE_LIM, PicoIn.opt, POPT_DIS_SPRITE_LIM),
- mee_range_h ("Overclock M68k (%)", MA_OPT2_OVERCLOCK_M68K,currentConfig.overclock_68k, 0, 1000, h_ovrclk),
- mee_onoff ("Emulate Z80", MA_OPT2_ENABLE_Z80, PicoIn.opt, POPT_EN_Z80),
- mee_onoff ("Emulate YM2612 (FM)", MA_OPT2_ENABLE_YM2612, PicoIn.opt, POPT_EN_FM),
- mee_onoff ("Disable YM2612 SSG-EG", MA_OPT2_DISABLE_YM_SSG,PicoIn.opt, POPT_DIS_FM_SSGEG),
- mee_onoff ("Emulate SN76496 (PSG)", MA_OPT2_ENABLE_SN76496,PicoIn.opt, POPT_EN_PSG),
- mee_onoff ("Emulate YM2413 (FM)", MA_OPT2_ENABLE_YM2413 ,PicoIn.opt, POPT_EN_YM2413),
- mee_onoff ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoIn.opt, POPT_DIS_IDLE_DET),
- mee_onoff ("Disable frame limiter", MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),
- mee_onoff ("Enable dynarecs", MA_OPT2_DYNARECS, PicoIn.opt, POPT_EN_DRC),
- mee_range ("Max auto frameskip", MA_OPT2_MAX_FRAMESKIP, currentConfig.max_skip, 1, 10),
- mee_onoff ("PWM IRQ optimization", MA_OPT2_PWM_IRQ_OPT, PicoIn.opt, POPT_PWM_IRQ_OPT),
- MENU_OPTIONS_ADV
- mee_end,
- };
- static int menu_loop_adv_options(int id, int keys)
- {
- static int sel = 0;
- me_loop(e_menu_adv_options, &sel);
- PicoIn.overclockM68k = currentConfig.overclock_68k; // int vs short
- return 0;
- }
- // ------------ sound options menu ------------
- static int sndrate_prevnext(int rate, int dir)
- {
- static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
- int i;
- for (i = 0; i < 5; i++)
- if (rates[i] == rate) break;
- i += dir ? 1 : -1;
- if (i > 4) {
- if (!(PicoIn.opt & POPT_EN_STEREO)) {
- PicoIn.opt |= POPT_EN_STEREO;
- return rates[0];
- }
- return rates[4];
- }
- if (i < 0) {
- if (PicoIn.opt & POPT_EN_STEREO) {
- PicoIn.opt &= ~POPT_EN_STEREO;
- return rates[4];
- }
- return rates[0];
- }
- return rates[i];
- }
- static int mh_opt_snd(int id, int keys)
- {
- PicoIn.sndRate = sndrate_prevnext(PicoIn.sndRate, keys & PBTN_RIGHT);
- return 0;
- }
- static const char *mgn_opt_sound(int id, int *offs)
- {
- const char *str2;
- *offs = -8;
- str2 = (PicoIn.opt & POPT_EN_STEREO) ? "stereo" : "mono";
- sprintf(static_buff, "%5iHz %s", PicoIn.sndRate, str2);
- return static_buff;
- }
- static int mh_opt_alpha(int id, int keys)
- {
- int val = (PicoIn.sndFilterAlpha * 100 + 0x08000) / 0x10000;
- if (keys & PBTN_LEFT) val--;
- if (keys & PBTN_RIGHT) val++;
- if (val < 1) val = 1;
- if (val > 99) val = 99;
- PicoIn.sndFilterAlpha = val * 0x10000 / 100;
- return 0;
- }
- static const char *mgn_opt_alpha(int id, int *offs)
- {
- int val = (PicoIn.sndFilterAlpha * 100 + 0x08000) / 0x10000;
- sprintf(static_buff, "0.%02d", val);
- return static_buff;
- }
- static const char h_lowpass[] = "Low pass filter for sound closer to real hardware";
- static menu_entry e_menu_snd_options[] =
- {
- mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
- mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_snd, mgn_opt_sound),
- mee_onoff_h ("Sound filter", MA_OPT_SOUND_FILTER, PicoIn.opt, POPT_EN_SNDFILTER, h_lowpass),
- mee_cust ("Filter strength", MA_OPT_SOUND_ALPHA, mh_opt_alpha, mgn_opt_alpha),
- mee_end,
- };
- static int menu_loop_snd_options(int id, int keys)
- {
- static int sel = 0;
- me_loop(e_menu_snd_options, &sel);
- return 0;
- }
- // ------------ gfx options menu ------------
- static const char h_gamma[] = "Gamma/brightness adjustment (default 1.00)";
- static const char *mgn_opt_fskip(int id, int *offs)
- {
- if (currentConfig.Frameskip < 0)
- return "Auto";
- sprintf(static_buff, "%d", currentConfig.Frameskip);
- return static_buff;
- }
- static const char *mgn_aopt_gamma(int id, int *offs)
- {
- sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma % 100);
- return static_buff;
- }
- static menu_entry e_menu_gfx_options[] =
- {
- mee_enum ("Video output mode", MA_OPT_VOUT_MODE, plat_target.vout_method, men_dummy),
- mee_enum ("Renderer", MA_OPT_RENDERER, currentConfig.renderer, renderer_names),
- mee_range_cust("Frameskip", MA_OPT_FRAMESKIP, currentConfig.Frameskip, -1, 16, mgn_opt_fskip),
- mee_enum ("Filter", MA_OPT3_FILTERING, currentConfig.filter, men_dummy),
- mee_range_cust_h("Gamma correction", MA_OPT2_GAMMA, currentConfig.gamma, 1, 300, mgn_aopt_gamma, h_gamma),
- MENU_OPTIONS_GFX
- mee_end,
- };
- static int menu_loop_gfx_options(int id, int keys)
- {
- static int sel = 0;
- me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names[0] != NULL);
- me_loop(e_menu_gfx_options, &sel);
- return 0;
- }
- // ------------ UI options menu ------------
- static const char *men_confirm_save[] = { "OFF", "writes", "loads", "both", NULL };
- static const char h_confirm_save[] = "Ask for confirmation when overwriting save,\n"
- "loading state or both";
- static menu_entry e_menu_ui_options[] =
- {
- mee_onoff ("Show FPS", MA_OPT_SHOW_FPS, currentConfig.EmuOpt, EOPT_SHOW_FPS),
- mee_enum_h ("Confirm savestate", MA_OPT_CONFIRM_STATES, currentConfig.confirm_save, men_confirm_save, h_confirm_save),
- mee_onoff ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM, currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),
- mee_end,
- };
- static int menu_loop_ui_options(int id, int keys)
- {
- static int sel = 0;
- me_loop(e_menu_ui_options, &sel);
- return 0;
- }
- // ------------ options menu ------------
- static menu_entry e_menu_options[];
- static void region_prevnext(int right)
- {
- // jp_ntsc=1, jp_pal=2, usa=4, eu=8
- static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };
- int i;
- if (right) {
- if (!PicoIn.regionOverride) {
- for (i = 0; i < 6; i++)
- if (rgn_orders[i] == PicoIn.autoRgnOrder) break;
- if (i < 5) PicoIn.autoRgnOrder = rgn_orders[i+1];
- else PicoIn.regionOverride=1;
- }
- else
- PicoIn.regionOverride <<= 1;
- if (PicoIn.regionOverride > 8)
- PicoIn.regionOverride = 8;
- } else {
- if (!PicoIn.regionOverride) {
- for (i = 0; i < 6; i++)
- if (rgn_orders[i] == PicoIn.autoRgnOrder) break;
- if (i > 0) PicoIn.autoRgnOrder = rgn_orders[i-1];
- }
- else
- PicoIn.regionOverride >>= 1;
- }
- }
- static int mh_opt_misc(int id, int keys)
- {
- switch (id) {
- case MA_OPT_REGION:
- region_prevnext(keys & PBTN_RIGHT);
- break;
- default:
- break;
- }
- return 0;
- }
- static int mh_saveloadcfg(int id, int keys)
- {
- int ret;
- if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice
- config_slot += (keys & PBTN_LEFT) ? -1 : 1;
- if (config_slot < 0) config_slot = 9;
- else if (config_slot > 9) config_slot = 0;
- me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
- return 0;
- }
- switch (id) {
- case MA_OPT_SAVECFG:
- case MA_OPT_SAVECFG_GAME:
- if (emu_write_config(id == MA_OPT_SAVECFG_GAME ? 1 : 0))
- menu_update_msg("config saved");
- else
- menu_update_msg("failed to write config");
- break;
- case MA_OPT_LOADCFG:
- ret = emu_read_config(rom_fname_loaded, 1);
- if (!ret) ret = emu_read_config(NULL, 1);
- if (ret) menu_update_msg("config loaded");
- else menu_update_msg("failed to load config");
- break;
- default:
- return 0;
- }
- return 1;
- }
- static int mh_restore_defaults(int id, int keys)
- {
- emu_set_defconfig();
- menu_update_msg("defaults restored");
- return 1;
- }
- static const char *mgn_opt_region(int id, int *offs)
- {
- static const char *names[] = { "Auto", " Japan NTSC", " Japan PAL", " USA", " Europe" };
- static const char *names_short[] = { "", " JP", " JP", " US", " EU" };
- int code = PicoIn.regionOverride;
- int u, i = 0;
- *offs = -6;
- if (code) {
- code <<= 1;
- while ((code >>= 1)) i++;
- if (i > 4)
- return "unknown";
- return names[i];
- } else {
- strcpy(static_buff, "Auto:");
- for (u = 0; u < 3; u++) {
- code = (PicoIn.autoRgnOrder >> u*4) & 0xf;
- for (i = 0; code; code >>= 1, i++)
- ;
- strcat(static_buff, names_short[i]);
- }
- return static_buff;
- }
- }
- static const char *mgn_saveloadcfg(int id, int *offs)
- {
- static_buff[0] = 0;
- if (config_slot != 0)
- sprintf(static_buff, "[%i]", config_slot);
- return static_buff;
- }
- static menu_entry e_menu_options[] =
- {
- mee_range ("Save slot", MA_OPT_SAVE_SLOT, state_slot, 0, 9),
- mee_cust ("Region", MA_OPT_REGION, mh_opt_misc, mgn_opt_region),
- mee_range ("", MA_OPT_CPU_CLOCKS, currentConfig.CPUclock, 20, 3200),
- mee_handler ("[Interface options]", menu_loop_ui_options),
- mee_handler ("[Display options]", menu_loop_gfx_options),
- mee_handler ("[Sound options]", menu_loop_snd_options),
- mee_handler ("[Sega/Mega CD options]", menu_loop_cd_options),
- #ifndef NO_32X
- mee_handler ("[32X options]", menu_loop_32x_options),
- #endif
- mee_handler ("[Advanced options]", menu_loop_adv_options),
- mee_cust_nosave("Save global config", MA_OPT_SAVECFG, mh_saveloadcfg, mgn_saveloadcfg),
- mee_cust_nosave("Save cfg for loaded game",MA_OPT_SAVECFG_GAME, mh_saveloadcfg, mgn_saveloadcfg),
- mee_cust_nosave("Load cfg from profile", MA_OPT_LOADCFG, mh_saveloadcfg, mgn_saveloadcfg),
- mee_handler ("Restore defaults", mh_restore_defaults),
- mee_end,
- };
- static int menu_loop_options(int id, int keys)
- {
- static int sel = 0;
- me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, PicoGameLoaded);
- me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);
- me_loop(e_menu_options, &sel);
- return 0;
- }
- // ------------ debug menu ------------
- #include <pico/debug.h>
- extern void SekStepM68k(void);
- static void mplayer_loop(void)
- {
- pemu_sound_start();
- while (1)
- {
- PDebugZ80Frame();
- if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
- break;
- emu_sound_wait();
- }
- emu_sound_stop();
- }
- static void draw_text_debug(const char *str, int skip, int from)
- {
- const char *p;
- int line;
- p = str;
- while (skip-- > 0)
- {
- while (*p && *p != '\n')
- p++;
- if (*p == 0 || p[1] == 0)
- return;
- p++;
- }
- str = p;
- for (line = from; line < g_menuscreen_h / me_sfont_h; line++)
- {
- smalltext_out16(1, line * me_sfont_h, str, 0xffff);
- while (*p && *p != '\n')
- p++;
- if (*p == 0)
- break;
- p++; str = p;
- }
- }
- #ifdef __GNUC__
- #define COMPILER "gcc " __VERSION__
- #else
- #define COMPILER
- #endif
- static void draw_frame_debug(void)
- {
- char layer_str[48] = "layers: ";
- struct PicoVideo *pv = &Pico.video;
- if (!(pv->debug_p & PVD_KILL_B)) memcpy(layer_str + 8, "B", 1);
- if (!(pv->debug_p & PVD_KILL_A)) memcpy(layer_str + 10, "A", 1);
- if (!(pv->debug_p & PVD_KILL_S_LO)) memcpy(layer_str + 12, "spr_lo", 6);
- if (!(pv->debug_p & PVD_KILL_S_HI)) memcpy(layer_str + 19, "spr_hi", 6);
- if (!(pv->debug_p & PVD_KILL_32X)) memcpy(layer_str + 26, "32x", 4);
- pemu_forced_frame(1, 0);
- make_bg(1, 1);
- smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff);
- smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff);
- }
- static void debug_menu_loop(void)
- {
- struct PicoVideo *pv = &Pico.video;
- int inp, mode = 0;
- int spr_offs = 0, dumped = 0;
- char *tmp;
- while (1)
- {
- menu_draw_begin(1, 0);
- switch (mode)
- {
- case 0: tmp = PDebugMain();
- plat_debug_cat(tmp);
- draw_text_debug(tmp, 0, 0);
- if (dumped) {
- smalltext_out16(g_menuscreen_w - 6 * me_sfont_h,
- g_menuscreen_h - me_mfont_h, "dumped", 0xffff);
- dumped = 0;
- }
- break;
- case 1: draw_frame_debug();
- break;
- case 2: pemu_forced_frame(1, 0);
- make_bg(1, 1);
- PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr
- + (g_menuscreen_h/2 - 240/2) * g_menuscreen_pp
- + g_menuscreen_w/2 - 320/2, g_menuscreen_pp);
- break;
- case 3: menuscreen_memset_lines(g_menuscreen_ptr, 0, g_menuscreen_h);
- PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_pp);
- PDebugShowSprite((unsigned short *)g_menuscreen_ptr
- + g_menuscreen_pp * 120 + g_menuscreen_w / 2 + 16,
- g_menuscreen_pp, spr_offs);
- draw_text_debug(PDebugSpriteList(), spr_offs, 6);
- break;
- case 4: tmp = PDebug32x();
- draw_text_debug(tmp, 0, 0);
- break;
- }
- menu_draw_end();
- inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
- PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 70);
- if (inp & PBTN_MBACK) return;
- if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
- if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
- switch (mode)
- {
- case 0:
- if (inp & PBTN_MOK)
- PDebugCPUStep();
- if (inp & PBTN_MA3) {
- while (inp & PBTN_MA3)
- inp = in_menu_wait_any(NULL, -1);
- mplayer_loop();
- }
- if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
- mkdir("dumps", 0777);
- PDebugDumpMem();
- while (inp & PBTN_MA2) inp = in_menu_wait_any(NULL, -1);
- dumped = 1;
- }
- break;
- case 1:
- if (inp & PBTN_LEFT) pv->debug_p ^= PVD_KILL_B;
- if (inp & PBTN_RIGHT) pv->debug_p ^= PVD_KILL_A;
- if (inp & PBTN_DOWN) pv->debug_p ^= PVD_KILL_S_LO;
- if (inp & PBTN_UP) pv->debug_p ^= PVD_KILL_S_HI;
- if (inp & PBTN_MA2) pv->debug_p ^= PVD_KILL_32X;
- if (inp & PBTN_MOK) {
- PicoIn.sndOut = NULL; // just in case
- PicoIn.skipFrame = 1;
- PicoFrame();
- PicoIn.skipFrame = 0;
- while (inp & PBTN_MOK) inp = in_menu_wait_any(NULL, -1);
- }
- break;
- case 3:
- if (inp & PBTN_DOWN) spr_offs++;
- if (inp & PBTN_UP) spr_offs--;
- if (spr_offs < 0) spr_offs = 0;
- break;
- }
- }
- }
- // ------------ main menu ------------
- static void draw_frame_credits(void)
- {
- smalltext_out16(4, 1, "build: " __DATE__ " " __TIME__, 0xe7fc);
- }
- static const char credits[] =
- "PicoDrive v" VERSION "\n"
- "(c) notaz, 2006-2013; irixxxx, 2018-2020\n\n"
- "Credits:\n"
- "fDave: initial code\n"
- #ifdef EMU_C68K
- " Cyclone 68000 core\n"
- #else
- "Stef, Chui: FAME/C 68k core\n"
- #endif
- #ifdef _USE_DRZ80
- "Reesy & FluBBa: DrZ80 core\n"
- #else
- "Stef, NJ: CZ80 core\n"
- #endif
- "MAME devs: SH2, YM2612 and SN76496 cores\n"
- "Eke, Stef: some Sega CD code\n"
- "Inder, ketchupgun: graphics\n"
- #ifdef __GP2X__
- "Squidge: mmuhack\n"
- "Dzz: ARM940 sample\n"
- #endif
- "\n"
- "special thanks (for docs, ideas):\n"
- " Charles MacDonald, Haze,\n"
- " Stephane Dallongeville,\n"
- " Lordus, Exophase, Rokas,\n"
- " Eke, Nemesis, Tasco Deluxe";
- static void menu_main_draw_status(void)
- {
- static time_t last_bat_read = 0;
- static int last_bat_val = -1;
- unsigned short *bp = g_menuscreen_ptr;
- int bat_h = me_mfont_h * 2 / 3;
- int i, u, w, wfill, batt_val;
- struct tm *tmp;
- time_t ltime;
- char time_s[16];
- if (!(currentConfig.EmuOpt & EOPT_SHOW_RTC))
- return;
- ltime = time(NULL);
- tmp = gmtime(<ime);
- strftime(time_s, sizeof(time_s), "%H:%M", tmp);
- text_out16(g_menuscreen_w - me_mfont_w * 6, me_mfont_h + 2, time_s);
- if (ltime - last_bat_read > 10) {
- last_bat_read = ltime;
- last_bat_val = batt_val = plat_target_bat_capacity_get();
- }
- else
- batt_val = last_bat_val;
- if (batt_val < 0 || batt_val > 100)
- return;
- /* battery info */
- bp += (me_mfont_h * 2 + 2) * g_menuscreen_pp + g_menuscreen_w - me_mfont_w * 3 - 3;
- for (i = 0; i < me_mfont_w * 2; i++)
- bp[i] = menu_text_color;
- for (i = 0; i < me_mfont_w * 2; i++)
- bp[i + g_menuscreen_pp * bat_h] = menu_text_color;
- for (i = 0; i <= bat_h; i++)
- bp[i * g_menuscreen_pp] =
- bp[i * g_menuscreen_pp + me_mfont_w * 2] = menu_text_color;
- for (i = 2; i < bat_h - 1; i++)
- bp[i * g_menuscreen_pp - 1] =
- bp[i * g_menuscreen_pp - 2] = menu_text_color;
- w = me_mfont_w * 2 - 1;
- wfill = batt_val * w / 100;
- for (u = 1; u < bat_h; u++)
- for (i = 0; i < wfill; i++)
- bp[(w - i) + g_menuscreen_pp * u] = menu_text_color;
- }
- static int main_menu_handler(int id, int keys)
- {
- const char *ret_name;
- switch (id)
- {
- case MA_MAIN_RESUME_GAME:
- if (PicoGameLoaded)
- return 1;
- break;
- case MA_MAIN_SAVE_STATE:
- if (PicoGameLoaded)
- return menu_loop_savestate(0);
- break;
- case MA_MAIN_LOAD_STATE:
- if (PicoGameLoaded)
- return menu_loop_savestate(1);
- break;
- case MA_MAIN_RESET_GAME:
- if (PicoGameLoaded) {
- emu_reset_game();
- return 1;
- }
- break;
- case MA_MAIN_LOAD_ROM:
- rom_fname_reload = NULL;
- ret_name = menu_loop_romsel(rom_fname_loaded,
- sizeof(rom_fname_loaded), rom_exts, NULL);
- if (ret_name != NULL) {
- lprintf("selected file: %s\n", ret_name);
- rom_fname_reload = ret_name;
- engineState = PGS_ReloadRom;
- return 1;
- }
- break;
- case MA_MAIN_CHANGE_CD:
- if (PicoIn.AHW & PAHW_MCD) {
- // if cd is loaded, cdd_unload() triggers eject and
- // returns 1, else we'll select and load new CD here
- if (!cdd_unload())
- menu_loop_tray();
- return 1;
- }
- break;
- case MA_MAIN_CREDITS:
- draw_menu_message(credits, draw_frame_credits);
- in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
- break;
- case MA_MAIN_EXIT:
- engineState = PGS_Quit;
- return 1;
- case MA_MAIN_PATCHES:
- if (PicoGameLoaded && PicoPatches) {
- menu_loop_patches();
- PicoPatchApply();
- menu_update_msg("Patches applied");
- }
- break;
- default:
- lprintf("%s: something unknown selected\n", __FUNCTION__);
- break;
- }
- return 0;
- }
- static menu_entry e_menu_main[] =
- {
- mee_label ("PicoDrive " VERSION),
- mee_label (""),
- mee_label (""),
- mee_label (""),
- mee_handler_id("Resume game", MA_MAIN_RESUME_GAME, main_menu_handler),
- mee_handler_id("Save State", MA_MAIN_SAVE_STATE, main_menu_handler),
- mee_handler_id("Load State", MA_MAIN_LOAD_STATE, main_menu_handler),
- mee_handler_id("Reset game", MA_MAIN_RESET_GAME, main_menu_handler),
- mee_handler_id("Load new ROM/ISO", MA_MAIN_LOAD_ROM, main_menu_handler),
- mee_handler_id("Change CD/ISO", MA_MAIN_CHANGE_CD, main_menu_handler),
- mee_handler ("Change options", menu_loop_options),
- mee_handler ("Configure controls", menu_loop_keyconfig),
- mee_handler_id("Credits", MA_MAIN_CREDITS, main_menu_handler),
- mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES, main_menu_handler),
- mee_handler_id("Exit", MA_MAIN_EXIT, main_menu_handler),
- mee_end,
- };
- void menu_loop(void)
- {
- static int sel = 0;
- me_enable(e_menu_main, MA_MAIN_RESUME_GAME, PicoGameLoaded);
- me_enable(e_menu_main, MA_MAIN_SAVE_STATE, PicoGameLoaded);
- me_enable(e_menu_main, MA_MAIN_LOAD_STATE, PicoGameLoaded);
- me_enable(e_menu_main, MA_MAIN_RESET_GAME, PicoGameLoaded);
- me_enable(e_menu_main, MA_MAIN_CHANGE_CD, PicoIn.AHW & PAHW_MCD);
- me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);
- menu_enter(PicoGameLoaded);
- in_set_config_int(0, IN_CFG_BLOCKING, 1);
- me_loop_d(e_menu_main, &sel, NULL, menu_main_draw_status);
- if (PicoGameLoaded) {
- if (engineState == PGS_Menu)
- engineState = PGS_Running;
- /* wait until menu, ok, back is released */
- while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
- ;
- }
- in_set_config_int(0, IN_CFG_BLOCKING, 0);
- plat_video_menu_leave();
- }
- void menu_loop_funkey(void)
- {
- in_set_config_int(0, IN_CFG_BLOCKING, 1);
- run_menu_loop();
- if (PicoGameLoaded) {
- if (engineState == PGS_Menu)
- engineState = PGS_Running;
- /* wait until menu, ok, back is released */
- /*while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
- ;*/
- }
- in_set_config_int(0, IN_CFG_BLOCKING, 0);
- plat_video_menu_leave();
- }
- // --------- CD tray close menu ----------
- static int mh_tray_load_cd(int id, int keys)
- {
- const char *ret_name;
- rom_fname_reload = NULL;
- ret_name = menu_loop_romsel(rom_fname_loaded,
- sizeof(rom_fname_loaded), rom_exts, NULL);
- if (ret_name == NULL)
- return 0;
- rom_fname_reload = ret_name;
- engineState = PGS_RestartRun;
- return emu_swap_cd(ret_name);
- }
- static int mh_tray_nothing(int id, int keys)
- {
- return 1;
- }
- static menu_entry e_menu_tray[] =
- {
- mee_label ("The CD tray has opened."),
- mee_label (""),
- mee_label (""),
- mee_handler("Load CD image", mh_tray_load_cd),
- mee_handler("Insert nothing", mh_tray_nothing),
- mee_end,
- };
- int menu_loop_tray(void)
- {
- int ret = 1, sel = 0;
- menu_enter(PicoGameLoaded);
- in_set_config_int(0, IN_CFG_BLOCKING, 1);
- me_loop(e_menu_tray, &sel);
- if (engineState != PGS_RestartRun) {
- engineState = PGS_RestartRun;
- ret = 0; /* no CD inserted */
- }
- while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
- ;
- in_set_config_int(0, IN_CFG_BLOCKING, 0);
- plat_video_menu_leave();
- return ret;
- }
- void menu_update_msg(const char *msg)
- {
- strncpy(menu_error_msg, msg, sizeof(menu_error_msg));
- menu_error_msg[sizeof(menu_error_msg) - 1] = 0;
- menu_error_time = plat_get_ticks_ms();
- lprintf("msg: %s\n", menu_error_msg);
- }
- // ------------ util ------------
- /* hidden options for config engine only */
- static menu_entry e_menu_hidden[] =
- {
- mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoIn.opt, POPT_ACC_SPRITES),
- mee_onoff("autoload savestates", MA_OPT_AUTOLOAD_SAVE, g_autostateld_opt, 1),
- mee_end,
- };
- static menu_entry *e_menu_table[] =
- {
- e_menu_options,
- e_menu_ui_options,
- e_menu_snd_options,
- e_menu_gfx_options,
- e_menu_adv_options,
- e_menu_cd_options,
- #ifndef NO_32X
- e_menu_32x_options,
- #endif
- e_menu_keyconfig,
- e_menu_hidden,
- };
- static menu_entry *me_list_table = NULL;
- static menu_entry *me_list_i = NULL;
- menu_entry *me_list_get_first(void)
- {
- me_list_table = me_list_i = e_menu_table[0];
- return me_list_i;
- }
- menu_entry *me_list_get_next(void)
- {
- int i;
- me_list_i++;
- if (me_list_i->name != NULL)
- return me_list_i;
- for (i = 0; i < array_size(e_menu_table); i++)
- if (me_list_table == e_menu_table[i])
- break;
- if (i + 1 < array_size(e_menu_table))
- me_list_table = me_list_i = e_menu_table[i + 1];
- else
- me_list_table = me_list_i = NULL;
- return me_list_i;
- }
- void menu_init(void)
- {
- int i;
- menu_init_base();
- i = 0;
- #if defined(_SVP_DRC) || defined(DRC_SH2)
- i = 1;
- #endif
- me_enable(e_menu_adv_options, MA_OPT2_DYNARECS, i);
- i = me_id2offset(e_menu_gfx_options, MA_OPT_VOUT_MODE);
- e_menu_gfx_options[i].data = plat_target.vout_methods;
- me_enable(e_menu_gfx_options, MA_OPT_VOUT_MODE,
- plat_target.vout_methods != NULL);
- i = me_id2offset(e_menu_gfx_options, MA_OPT3_FILTERING);
- e_menu_gfx_options[i].data = plat_target.hwfilters;
- me_enable(e_menu_gfx_options, MA_OPT3_FILTERING,
- plat_target.hwfilters != NULL);
- me_enable(e_menu_gfx_options, MA_OPT2_GAMMA,
- plat_target.gamma_set != NULL);
- i = me_id2offset(e_menu_options, MA_OPT_CPU_CLOCKS);
- e_menu_options[i].enabled = 0;
- if (plat_target.cpu_clock_set != NULL) {
- e_menu_options[i].name = "CPU clock";
- e_menu_options[i].enabled = 1;
- }
- }
|