From 9137dfbf3fcbfd9f75b86d5e4b220866bd508543 Mon Sep 17 00:00:00 2001 From: aquanull Date: Thu, 5 Apr 2018 18:51:16 +0800 Subject: [PATCH] Tiny refactoring on input display. --- src/video.cpp | 134 +++++++++++++++++--------------------------------- 1 file changed, 44 insertions(+), 90 deletions(-) diff --git a/src/video.cpp b/src/video.cpp index 3634d78e..d9654c96 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -178,6 +178,31 @@ static void ReallySnap(void) FCEU_DispMessage("Screen snapshot %d saved.",0,x-1); } +static uint32 GetButtonColor(uint32 held, uint32 c, uint32 ci, int bit) +{ + uint32 on = FCEUMOV_Mode(MOVIEMODE_PLAY) ? 0x90 : 0xA7; //Standard, or Gray depending on movie mode + uint32 oni = 0xA0; //Color for immediate keyboard buttons + uint32 blend = 0xB6; //Blend of immiate and last held buttons + uint32 ahold = 0x87; //Auto hold + uint32 off = 0xCF; + + uint32 color; + uint8 mask = 1u << bit; + if (held & mask) { //If auto-hold + if (!(ci & mask)) + color = ahold; + else + color = (c & mask) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed! + } + else { + if (c & mask) + color = (ci & mask) ? blend : on; //If immedaite buttons are pressed and they match the previous frame, blend the colors + else + color = (ci & mask) ? oni : off; + } + return color; +} + void FCEU_PutImage(void) { if(dosnapsave==2) //Save screenshot as, currently only flagged & run by the Win32 build. //TODO SDL: implement this? @@ -247,19 +272,10 @@ void FCEU_PutImage(void) if(input_display) { extern uint32 JSAutoHeld; - uint32 held; - - int controller, c, ci, color; int i, j; - uint32 on = FCEUMOV_Mode(MOVIEMODE_PLAY) ? 0x90:0xA7; //Standard, or Gray depending on movie mode - uint32 oni = 0xA0; //Color for immediate keyboard buttons - uint32 blend = 0xB6; //Blend of immiate and last held buttons - uint32 ahold = 0x87; //Auto hold - uint32 off = 0xCF; - uint8 *t = XBuf+(FSettings.LastSLine-9)*256 + 20; //mbg merge 7/17/06 changed t to uint8* if(input_display > 4) input_display = 4; - for(controller = 0; controller < input_display; controller++, t += 56) + for(int controller = 0; controller < input_display; controller++, t += 56) { for(i = 0; i < 34;i++) for(j = 0; j <9 ; j++) @@ -267,33 +283,27 @@ void FCEU_PutImage(void) for(i = 3; i < 6; i++) for(j = 3; j< 6; j++) t[i+j*256] = 0xCF; - c = cur_input_display >> (controller * 8); + uint32 held = 0; + uint32 c = cur_input_display >> (controller * 8); + uint32 ci = 0; + uint32 color; + +#ifdef WIN32 // This doesn't work in anything except windows for now. // It doesn't get set anywhere in other ports. -#ifdef WIN32 - if (!oldInputDisplay) ci = FCEUMOV_Mode(MOVIEMODE_PLAY) ? 0:GetGamepadPressedImmediate() >> (controller * 8); - else ci = 0; + if (!oldInputDisplay) + ci = FCEUMOV_Mode(MOVIEMODE_PLAY) ? 0 : GetGamepadPressedImmediate() >> (controller * 8); - if (!oldInputDisplay && !FCEUMOV_Mode(MOVIEMODE_PLAY)) held = (JSAutoHeld >> (controller * 8)); - else held = 0; + if (!oldInputDisplay && !FCEUMOV_Mode(MOVIEMODE_PLAY)) + held = (JSAutoHeld >> (controller * 8)); #else // Put other port info here - ci = 0; - held = 0; #endif //adelikat: I apologize to anyone who ever sifts through this color assignment //A - if (held&1) { //If auto-hold - if (!(ci&1) ) color = ahold; - else - color = (c&1) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed! - } - else { - if (c&1) color = (ci&1) ? blend : on; //If immedaite buttons are pressed and they match the previous frame, blend the colors - else color = (ci&1) ? oni : off; - } + color = GetButtonColor(held, c, ci, 0); for(i=0; i < 4; i++) { for(j = 0; j < 4; j++) @@ -304,15 +314,7 @@ void FCEU_PutImage(void) } } //B - if (held&2) { //If auto-hold - if (!(ci&2) ) color = ahold; - else - color = (c&2) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed! - } - else { - if (c&2) color = (ci&2) ? blend : on; //If immedaite buttons are pressed and they match the previous frame, blend the colors - else color = (ci&2) ? oni : off; - } + color = GetButtonColor(held, c, ci, 1); for(i=0; i < 4; i++) { for(j = 0; j < 4; j++) @@ -323,45 +325,21 @@ void FCEU_PutImage(void) } } //Select - if (held&4) { //If auto-hold - if (!(ci&4) ) color = ahold; - else - color = (c&4) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed! - } - else { - if (c&4) color = (ci&4) ? blend : on; //If immedaite buttons are pressed and they match the previous frame, blend the colors - else color = (ci&4) ? oni : off; - } + color = GetButtonColor(held, c, ci, 2); for(i = 0; i < 4; i++) { t[11+5*256+i] = color; t[11+6*256+i] = color; } //Start - if (held&8) { //If auto-hold - if (!(ci&8) ) color = ahold; - else - color = (c&8) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed! - } - else { - if (c&8) color = (ci&8) ? blend : on; //If immedaite buttons are pressed and they match the previous frame, blend the colors - else color = (ci&8) ? oni : off; - } + color = GetButtonColor(held, c, ci, 3); for(i = 0; i < 4; i++) { t[17+5*256+i] = color; t[17+6*256+i] = color; } //Up - if (held&16) { //If auto-hold - if (!(ci&16) ) color = ahold; - else - color = (c&16) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed! - } - else { - if (c&16) color = (ci&16) ? blend : on; //If immedaite buttons are pressed and they match the previous frame, blend the colors - else color = (ci&16) ? oni : off; - } + color = GetButtonColor(held, c, ci, 4); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) @@ -370,15 +348,7 @@ void FCEU_PutImage(void) } } //Down - if (held&32) { //If auto-hold - if (!(ci&32) ) color = ahold; - else - color = (c&32) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed! - } - else { - if (c&32) color = (ci&32) ? blend : on; //If immedaite buttons are pressed and they match the previous frame, blend the colors - else color = (ci&32) ? oni : off; - } + color = GetButtonColor(held, c, ci, 5); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) @@ -387,15 +357,7 @@ void FCEU_PutImage(void) } } //Left - if (held&64) { //If auto-hold - if (!(ci&64) ) color = ahold; - else - color = (c&64) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed! - } - else { - if (c&64) color = (ci&64) ? blend : on; //If immedaite buttons are pressed and they match the previous frame, blend the colors - else color = (ci&64) ? oni : off; - } + color = GetButtonColor(held, c, ci, 6); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++) @@ -404,15 +366,7 @@ void FCEU_PutImage(void) } } //Right - if (held&128) { //If auto-hold - if (!(ci&128) ) color = ahold; - else - color = (c&128) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed! - } - else { - if (c&128) color = (ci&128) ? blend : on; //If immedaite buttons are pressed and they match the previous frame, blend the colors - else color = (ci&128) ? oni : off; - } + color = GetButtonColor(held, c, ci, 7); for(i = 0; i < 3; i++) { for(j = 0; j < 3; j++)