Skip to content

Commit 6016b5f

Browse files
committed
Added FUNKEY_FAST_BLIT option and handling aspect ratios
1 parent d60fb0d commit 6016b5f

File tree

5 files changed

+208
-59
lines changed

5 files changed

+208
-59
lines changed

src/drivers/input.cpp

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -836,16 +836,76 @@ void Input_Event(const SDL_Event *event)
836836
//printf("Down: %3u\n", event->key.keysym.sym);
837837
size_t s = event->key.keysym.sym;
838838

839-
/// Special case: menu FunKey
840-
if(s == SDLK_q){
841-
printf("Launching menu\n");
842-
run_menu_loop();
843-
break;
844-
}
839+
/* Special cases: */
840+
/* Menu FunKey */
841+
if(s == SDLK_q){
842+
printf("Launching menu\n");
843+
run_menu_loop();
844+
break;
845+
}
846+
/* Quick shortcut: Changing aspect Ratio */
847+
else if(s == SDLK_h){
848+
char shell_cmd[100];
849+
aspect_ratio = (aspect_ratio+1)%NB_ASPECT_RATIOS_TYPES;
850+
if(aspect_ratio == ASPECT_RATIOS_TYPE_MANUAL){
851+
sprintf(shell_cmd, "%s %d \"DISPLAY MODE: MANUAL ZOOM %d%%%%\"",
852+
SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP, aspect_ratio_factor_percent);
853+
}
854+
else{
855+
sprintf(shell_cmd, "%s %d \" DISPLAY MODE: %s\"",
856+
SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP, aspect_ratio_name[aspect_ratio]);
857+
}
858+
//hud_new_msg = 4;
859+
FILE *fp = popen(shell_cmd, "r");
860+
if (fp == NULL) {
861+
printf("Failed to run command %s\n", shell_cmd);
862+
}
863+
break;
864+
}
865+
/* Quick shortcut: Decrease manual aspect Ratio */
866+
else if(s == SDLK_j){
867+
if(aspect_ratio == ASPECT_RATIOS_TYPE_MANUAL){
868+
aspect_ratio_factor_percent = (aspect_ratio_factor_percent>aspect_ratio_factor_step)?
869+
aspect_ratio_factor_percent-aspect_ratio_factor_step:0;
870+
need_screen_cleared = 1;
871+
}
872+
else{
873+
aspect_ratio = ASPECT_RATIOS_TYPE_MANUAL;
874+
}
875+
char shell_cmd[100];
876+
sprintf(shell_cmd, "%s %d \"DISPLAY MODE: MANUAL ZOOM %d%%%%\"",
877+
SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP, aspect_ratio_factor_percent);
878+
FILE *fp = popen(shell_cmd, "r");
879+
if (fp == NULL) {
880+
printf("Failed to run command %s\n", shell_cmd);
881+
}
882+
break;
883+
}
884+
/* Quick shortcut: Increase manual aspect Ratio */
885+
else if(s == SDLK_i){
886+
if(aspect_ratio == ASPECT_RATIOS_TYPE_MANUAL){
887+
aspect_ratio_factor_percent = (aspect_ratio_factor_percent+aspect_ratio_factor_step<100)?
888+
aspect_ratio_factor_percent+aspect_ratio_factor_step:100;
889+
need_screen_cleared = 1;
890+
}
891+
else{
892+
aspect_ratio = ASPECT_RATIOS_TYPE_MANUAL;
893+
}
894+
aspect_ratio = ASPECT_RATIOS_TYPE_MANUAL;
895+
char shell_cmd[100];
896+
sprintf(shell_cmd, "%s %d \"DISPLAY MODE: MANUAL ZOOM %d%%%%\"",
897+
SHELL_CMD_NOTIF, NOTIF_SECONDS_DISP, aspect_ratio_factor_percent);
898+
FILE *fp = popen(shell_cmd, "r");
899+
if (fp == NULL) {
900+
printf("Failed to run command %s\n", shell_cmd);
901+
}
902+
break;
903+
}
845904

905+
/** Normal Handling */
846906
if(s < MKK_COUNT)
847907
{
848-
keys_untouched[s] = (keys_untouched[s] & 0x7F) | 0x01;
908+
keys_untouched[s] = (keys_untouched[s] & 0x7F) | 0x01;
849909
}
850910
}
851911
break;

src/drivers/menu.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@
124124

125125
/// -------------- STATIC VARIABLES --------------
126126
extern SDL_Surface *screen;
127-
SDL_Surface *virtual_hw_screen; // this one is not rotated
128127
extern SDL_Surface *hw_screen;
129128
SDL_Surface * draw_screen;
130129
extern int volatile pumpWrap_disabled;
@@ -158,6 +157,14 @@ static uint16_t y_brightness_bar = 0;
158157
int volume_percentage = 0;
159158
int brightness_percentage = 0;
160159

160+
#undef X
161+
#define X(a, b) b,
162+
const char *aspect_ratio_name[] = {ASPECT_RATIOS};
163+
int aspect_ratio = ASPECT_RATIOS_TYPE_STRETCHED;
164+
int aspect_ratio_factor_percent = 50;
165+
int aspect_ratio_factor_step = 10;
166+
int need_screen_cleared = 0;
167+
161168
#undef X
162169
#define X(a, b) b,
163170
const char *resume_options_str[] = {RESUME_OPTIONS};
@@ -191,15 +198,14 @@ void init_menu_SDL(){
191198
MENU_ERROR_PRINTF("ERROR in init_menu_SDL: Could not open menu font %s, %s\n", MENU_FONT_NAME_SMALL_INFO, SDL_GetError());
192199
}
193200

194-
/// ----- Copy virtual_hw_screen at init ------
195-
virtual_hw_screen = screen;
201+
/// ----- Create SDL surfaces ------
196202
backup_hw_screen = SDL_CreateRGBSurface(SDL_SWSURFACE,
197-
virtual_hw_screen->w, virtual_hw_screen->h, 32, 0, 0, 0, 0);
203+
hw_screen->w, hw_screen->h, 32, 0, 0, 0, 0);
198204
if(backup_hw_screen == NULL){
199205
MENU_ERROR_PRINTF("ERROR Could not create backup_hw_screen: %s\n", SDL_GetError());
200206
}
201207
draw_screen = SDL_CreateRGBSurface(SDL_SWSURFACE,
202-
virtual_hw_screen->w, virtual_hw_screen->h, 32, 0, 0, 0, 0);
208+
hw_screen->w, hw_screen->h, 32, 0, 0, 0, 0);
203209
if(draw_screen == NULL){
204210
MENU_ERROR_PRINTF("ERROR Could not create draw_screen: %s\n", SDL_GetError());
205211
}
@@ -411,7 +417,7 @@ void init_menu_zones(){
411417
/// Init Load Menu
412418
add_menu_zone(MENU_TYPE_LOAD);
413419
/// Init Aspect Ratio Menu
414-
//add_menu_zone(MENU_TYPE_ASPECT_RATIO);
420+
add_menu_zone(MENU_TYPE_ASPECT_RATIO);
415421
/// Init Exit Menu
416422
add_menu_zone(MENU_TYPE_EXIT);
417423
/// Init Powerdown Menu
@@ -491,7 +497,7 @@ void menu_screen_refresh(int menuItem, int prevItem, int scroll, uint8_t menu_co
491497
menu_blit_window.y = scroll;
492498
menu_blit_window.h = SCREEN_VERTICAL_SIZE;
493499
if(SDL_BlitSurface(menu_zone_surfaces[prevItem], &menu_blit_window, draw_screen, NULL)){
494-
MENU_ERROR_PRINTF("ERROR Could not Blit surface on virtual_hw_screen: %s\n", SDL_GetError());
500+
MENU_ERROR_PRINTF("ERROR Could not Blit surface on draw_screen: %s\n", SDL_GetError());
495501
}
496502

497503
/// --------- Blit new menu Zone going in (only during animations) ----------
@@ -619,13 +625,13 @@ void menu_screen_refresh(int menuItem, int prevItem, int scroll, uint8_t menu_co
619625
SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
620626
break;
621627

622-
/*case MENU_TYPE_ASPECT_RATIO:
628+
case MENU_TYPE_ASPECT_RATIO:
623629
sprintf(text_tmp, "< %s >", aspect_ratio_name[aspect_ratio]);
624630
text_surface = TTF_RenderText_Blended(menu_info_font, text_tmp, text_color);
625631
text_pos.x = (draw_screen->w - MENU_ZONE_WIDTH)/2 + (MENU_ZONE_WIDTH - text_surface->w)/2;
626632
text_pos.y = draw_screen->h - MENU_ZONE_HEIGHT/2 - text_surface->h/2 + padding_y_from_center_menu_zone;
627633
SDL_BlitSurface(text_surface, NULL, draw_screen, &text_pos);
628-
break;*/
634+
break;
629635

630636
case MENU_TYPE_EXIT:
631637
case MENU_TYPE_POWERDOWN:
@@ -693,8 +699,8 @@ void run_menu_loop()
693699
int prevItem=menuItem;
694700

695701
/// ------ Copy currently displayed screen -------
696-
if(SDL_BlitSurface(virtual_hw_screen, NULL, backup_hw_screen, NULL)){
697-
MENU_ERROR_PRINTF("ERROR Could not copy virtual_hw_screen: %s\n", SDL_GetError());
702+
if(SDL_BlitSurface(hw_screen, NULL, backup_hw_screen, NULL)){
703+
MENU_ERROR_PRINTF("ERROR Could not copy hw_screen: %s\n", SDL_GetError());
698704
}
699705
/*uint16_t *dst_virtual = (uint16_t*) sal_VirtualVideoGetBuffer();
700706
memcpy(backup_hw_screen->pixels, dst_virtual,
@@ -826,12 +832,12 @@ void run_menu_loop()
826832
/// ------ Refresh screen ------
827833
screen_refresh = 1;
828834
}
829-
/*else if(idx_menus[menuItem] == MENU_TYPE_ASPECT_RATIO){
835+
else if(idx_menus[menuItem] == MENU_TYPE_ASPECT_RATIO){
830836
MENU_DEBUG_PRINTF("Aspect Ratio DOWN\n");
831837
aspect_ratio = (!aspect_ratio)?(NB_ASPECT_RATIOS_TYPES-1):(aspect_ratio-1);
832838
/// ------ Refresh screen ------
833839
screen_refresh = 1;
834-
}*/
840+
}
835841
break;
836842

837843
case SDLK_r:
@@ -895,12 +901,12 @@ void run_menu_loop()
895901
/// ------ Refresh screen ------
896902
screen_refresh = 1;
897903
}
898-
/*else if(idx_menus[menuItem] == MENU_TYPE_ASPECT_RATIO){
904+
else if(idx_menus[menuItem] == MENU_TYPE_ASPECT_RATIO){
899905
MENU_DEBUG_PRINTF("Aspect Ratio UP\n");
900906
aspect_ratio = (aspect_ratio+1)%NB_ASPECT_RATIOS_TYPES;
901907
/// ------ Refresh screen ------
902908
screen_refresh = 1;
903-
}*/
909+
}
904910
break;
905911

906912
case SDLK_a:

src/drivers/menu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ extern const char *aspect_ratio_name[];
7373
extern int aspect_ratio;
7474
extern int aspect_ratio_factor_percent;
7575
extern int aspect_ratio_factor_step;
76+
extern int need_screen_cleared;
7677
extern int stop_menu_loop;
7778
extern char *mRomName;
7879
extern char *mRomPath;

src/drivers/nongl.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ static void BlitIScale(const MDFN_Surface *src_surface, const MDFN_Rect &sr, MDF
159159
{
160160
//puts("IScale");
161161
const uint32 src_pitchinpix = src_surface->pitchinpix;
162+
//printf("src_pitchinpix: %d\n", src_pitchinpix);
162163
int32 dpitch_diff;
163164

164165
T *src_row, *dest_row;
@@ -402,7 +403,8 @@ void MDFN_StretchBlitSurface(const MDFN_Surface* src_surface, const MDFN_Rect& s
402403
o_sr = *original_src_rect;
403404
dr = dest_rect;
404405

405-
//printf("%d:%d, %d:%d, %d:%d\n", sr.x, sr.w, sr.y, sr.h, src_surface->w, src_surface->h);
406+
//printf("src %d:%d, %d:%d, %d:%d\n", sr.x, sr.w, sr.y, sr.h, src_surface->w, src_surface->h);
407+
//printf("dst %d:%d, %d:%d, %d:%d\n", dr.x, dr.w, dr.y, dr.h, dest_surface->w, dest_surface->h);
406408

407409
if(rotated != MDFN_ROTATE0)
408410
{
@@ -438,10 +440,14 @@ void MDFN_StretchBlitSurface(const MDFN_Surface* src_surface, const MDFN_Rect& s
438440
{
439441
switch(source_alpha ? (int)src_surface->format.Ashift : -1)
440442
{
441-
case -1: if((dw_to_sw_ratio == dh_to_sh_ratio) && dw_to_sw_ratio <= 5)
443+
case -1:
444+
if((dw_to_sw_ratio == dh_to_sh_ratio) && dw_to_sw_ratio <= 5){
442445
nnx(dw_to_sw_ratio, src_surface, sr, dest_surface, dr);
443-
else
446+
}
447+
else{
444448
BlitIScale<uint32, 31>(src_surface, sr, dest_surface, dr, dw_to_sw_ratio, dh_to_sh_ratio);
449+
//printf("BlitIScale %f, %f\n", dw_to_sw_ratio, dh_to_sh_ratio);
450+
}
445451
break;
446452

447453
case 0: BlitIScale<uint32, 0>(src_surface, sr, dest_surface, dr, dw_to_sw_ratio, dh_to_sh_ratio); break;

0 commit comments

Comments
 (0)