From b44d1590cad4ad4d561cdf119ebeb0820a8e8862 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Fri, 3 Apr 2009 01:05:28 +0000 Subject: [PATCH] Fiddle with ProcessFKeys a bit, and hack in a key to turn logging on and off(F10). git-svn-id: http://pcsx2.googlecode.com/svn/trunk@891 96395faa-99c1-11dd-bbfe-3dabce05a288 --- pcsx2/DebugTools/Debug.h | 1 + pcsx2/Linux/LnxSysExec.cpp | 190 +++++++++++++++++------------------ pcsx2/Misc.cpp | 57 +++++++---- pcsx2/Misc.h | 11 +- pcsx2/SourceLog.cpp | 9 +- pcsx2/windows/WinSysExec.cpp | 18 +++- 6 files changed, 165 insertions(+), 121 deletions(-) diff --git a/pcsx2/DebugTools/Debug.h b/pcsx2/DebugTools/Debug.h index 77152441df..95aed6fe99 100644 --- a/pcsx2/DebugTools/Debug.h +++ b/pcsx2/DebugTools/Debug.h @@ -74,6 +74,7 @@ namespace R3000A #ifdef PCSX2_DEVBUILD extern u32 varLog; +extern bool enableLogging; void SourceLog( u16 protocol, u8 source, u32 cpuPc, u32 cpuCycle, const char *fmt, ...); void __Log( const char* fmt, ... ); diff --git a/pcsx2/Linux/LnxSysExec.cpp b/pcsx2/Linux/LnxSysExec.cpp index 0080dff9bc..7a437df3c1 100644 --- a/pcsx2/Linux/LnxSysExec.cpp +++ b/pcsx2/Linux/LnxSysExec.cpp @@ -291,12 +291,6 @@ void OnStates_SaveOther(GtkMenuItem *menuitem, gpointer user_data) gdk_window_raise(FileSel->window); } -/* Quick macros for checking shift, control, alt, and caps lock. */ -#define SHIFT_EVT(evt) ((evt == XK_Shift_L) || (evt == XK_Shift_R)) -#define CTRL_EVT(evt) ((evt == XK_Control_L) || (evt == XK_Control_L)) -#define ALT_EVT(evt) ((evt == XK_Alt_L) || (evt == XK_Alt_R)) -#define CAPS_LOCK_EVT(evt) (evt == XK_Caps_Lock) - bool SysInit() { if (sinit) return true; @@ -450,98 +444,100 @@ namespace HostGui SysExecute(); } - void __fastcall KeyEvent(keyEvent* ev) +/* Quick macros for checking shift, control, alt, and caps lock. */ +#define SHIFT_EVT(evt) ((evt == XK_Shift_L) || (evt == XK_Shift_R)) +#define CTRL_EVT(evt) ((evt == XK_Control_L) || (evt == XK_Control_R)) +#define ALT_EVT(evt) ((evt == XK_Alt_L) || (evt == XK_Alt_R)) +#define CAPS_LOCK_EVT(evt) (evt == XK_Caps_Lock) + +void __fastcall KeyEvent(keyEvent* ev) +{ + struct KeyModifiers *keymod = &keymodifiers; + + if (ev == NULL) return; + + if (ev->evt == KEYRELEASE) { - static int shift = 0; - - if (ev == NULL) return; - - if (GSkeyEvent != NULL) GSkeyEvent(ev); - - if (ev->evt == KEYPRESS) - { - if (SHIFT_EVT(ev->key)) - shift = 1; - if (CAPS_LOCK_EVT(ev->key)) - { - //Set up anything we want to happen while caps lock is down. - } - - switch (ev->key) - { - case XK_F1: - case XK_F2: - case XK_F3: - case XK_F4: - case XK_F5: - case XK_F6: - case XK_F7: - case XK_F8: - case XK_F9: - case XK_F10: - case XK_F11: - case XK_F12: - try - { - ProcessFKeys(ev->key - XK_F1 + 1, shift); - } - catch (Exception::CpuStateShutdown&) - { - // Woops! Something was unrecoverable. Bummer. - // Let's give the user a RunGui! - - g_EmulationInProgress = false; - SysEndExecution(); - } - break; - - case XK_Tab: - CycleFrameLimit(0); - break; - - case XK_Escape: - signal(SIGINT, SIG_DFL); - signal(SIGPIPE, SIG_DFL); - - #ifdef PCSX2_DEVBUILD - if (g_SaveGSStream >= 3) - { - g_SaveGSStream = 4;// gs state - break; - } - #endif - SysEndExecution(); - - if (g_Startup.NoGui) exit(0); - - // fixme: The GUI is now capable of receiving control back from the - // emulator. Which means that when we call SysEscapeExecute() here, the - // emulation loop in ExecuteCpu() will exit. You should be able to set it - // up so that it returns control to the existing GTK event loop, instead of - // always starting a new one via RunGui(). (but could take some trial and - // error) -- (air) - - // Easier said then done; running gtk in two threads at the same time can't be - // done, and working around that is pretty fiddly. - RunGui(); - break; - - default: - GSkeyEvent(ev); - break; - } - } - else if (ev->evt == KEYRELEASE) - { - if (SHIFT_EVT(ev->key)) - shift = 0; - if (CAPS_LOCK_EVT(ev->key)) - { - //Release caps lock - } - } - + if (SHIFT_EVT(ev->key)) keymod->shift = FALSE; + if (CTRL_EVT(ev->key)) keymod->control = FALSE; + if (ALT_EVT(ev->key)) keymod->alt = FALSE; + if (CAPS_LOCK_EVT(ev->key)) keymod->capslock = FALSE; + GSkeyEvent(ev); return; } -} \ No newline at end of file + if (ev->evt == KEYPRESS) + { + if (SHIFT_EVT(ev->key)) keymod->shift = TRUE; + if (CTRL_EVT(ev->key)) keymod->control = TRUE; + if (ALT_EVT(ev->key)) keymod->alt = TRUE; + if (CAPS_LOCK_EVT(ev->key)) keymod->capslock = TRUE; + + switch (ev->key) + { + case XK_F1: + case XK_F2: + case XK_F3: + case XK_F4: + case XK_F5: + case XK_F6: + case XK_F7: + case XK_F8: + case XK_F9: + case XK_F10: + case XK_F11: + case XK_F12: + try + { + ProcessFKeys(ev->key - XK_F1 + 1, keymod); + } + catch (Exception::CpuStateShutdown&) + { + // Woops! Something was unrecoverable. Bummer. + // Let's give the user a RunGui! + + g_EmulationInProgress = false; + SysEndExecution(); + } + break; + + case XK_Tab: + CycleFrameLimit(0); + break; + + case XK_Escape: + signal(SIGINT, SIG_DFL); + signal(SIGPIPE, SIG_DFL); + +#ifdef PCSX2_DEVBUILD + if (g_SaveGSStream >= 3) + { + g_SaveGSStream = 4;// gs state + break; + } +#endif + SysEndExecution(); + + if (g_Startup.NoGui) exit(0); + + // fixme: The GUI is now capable of receiving control back from the + // emulator. Which means that when we call SysEscapeExecute() here, the + // emulation loop in ExecuteCpu() will exit. You should be able to set it + // up so that it returns control to the existing GTK event loop, instead of + // always starting a new one via RunGui(). (but could take some trial and + // error) -- (air) + + // Easier said then done; running gtk in two threads at the same time can't be + // done, and working around that is pretty fiddly. + RunGui(); + break; + + default: + GSkeyEvent(ev); + break; + } + } + + return; +} +} diff --git a/pcsx2/Misc.cpp b/pcsx2/Misc.cpp index 738550ad32..626830295f 100644 --- a/pcsx2/Misc.cpp +++ b/pcsx2/Misc.cpp @@ -51,6 +51,8 @@ char CdromId[12]; static int g_Pcsx2Recording = 0; // true 1 if recording video and sound bool renderswitch = 0; +struct KeyModifiers keymodifiers = {false, false, false, false}; + #define NUM_STATES 10 int StatesC = 0; @@ -489,11 +491,12 @@ void CycleFrameLimit(int dir) //SaveConfig(); } -void ProcessFKeys(int fkey, int shift) +void ProcessFKeys(int fkey, struct KeyModifiers *keymod) { assert(fkey >= 1 && fkey <= 12 ); - switch(fkey) { + switch(fkey) + { case 1: try { @@ -511,7 +514,7 @@ void ProcessFKeys(int fkey, int shift) break; case 2: - if( shift ) + if( keymod->shift ) StatesC = (StatesC+NUM_STATES-1) % NUM_STATES; else StatesC = (StatesC+1) % NUM_STATES; @@ -558,7 +561,7 @@ void ProcessFKeys(int fkey, int shift) break; case 4: - CycleFrameLimit(shift ? -1 : 1); + CycleFrameLimit(keymod->shift ? -1 : 1); break; // note: VK_F5-VK_F7 are reserved for GS @@ -567,7 +570,8 @@ void ProcessFKeys(int fkey, int shift) break; case 9: //gsdx "on the fly" renderer switching - if (!renderswitch) { + if (!renderswitch) + { StateRecovery::MakeGsOnly(); g_EmulationInProgress = false; CloseGS(); @@ -575,7 +579,8 @@ void ProcessFKeys(int fkey, int shift) StateRecovery::Recover(); HostGui::BeginExecution(); //also sets g_EmulationInProgress to true later } - else { + else + { StateRecovery::MakeGsOnly(); g_EmulationInProgress = false; CloseGS(); @@ -585,21 +590,35 @@ void ProcessFKeys(int fkey, int shift) } break; #ifdef PCSX2_DEVBUILD - + case 10: + // There's likely a better way to implement this, but this seemed useful. + // I might add turning EE, VU0, and VU1 recs on and off by hotkey at some point, too. + // --arcum42 + enableLogging = !enableLogging; + + if (enableLogging) + GSprintf(10, "Logging Enabled."); + else + GSprintf(10,"Logging Disabled."); + + break; case 11: - if( mtgsThread != NULL ) { + if( mtgsThread != NULL ) + { Console::Notice( "Cannot make gsstates in MTGS mode" ); } else { string Text; - if( strgametitle[0] != 0 ) { + if( strgametitle[0] != 0 ) + { // only take the first two words char name[256], *tok; string gsText; tok = strtok(strgametitle, " "); sprintf(name, "%s_", mystrlwr(tok)); + tok = strtok(NULL, " "); if( tok != NULL ) strcat(name, tok); @@ -607,28 +626,32 @@ void ProcessFKeys(int fkey, int shift) Text = Path::Combine( SSTATES_DIR, gsText ); } else + { Text = GetGSStateFilename(); - + } + SaveGSState(Text); } break; #endif case 12: - if( shift ) { + if( keymod->shift ) + { #ifdef PCSX2_DEVBUILD iDumpRegisters(cpuRegs.pc, 0); Console::Notice("hardware registers dumped EE:%x, IOP:%x\n", params cpuRegs.pc, psxRegs.pc); #endif } - else { + else + { g_Pcsx2Recording ^= 1; - if( mtgsThread != NULL ) { + + if( mtgsThread != NULL ) mtgsThread->SendSimplePacket(GS_RINGTYPE_RECORD, g_Pcsx2Recording, 0, 0); - } - else { - if( GSsetupRecording != NULL ) GSsetupRecording(g_Pcsx2Recording, NULL); - } + else if( GSsetupRecording != NULL ) + GSsetupRecording(g_Pcsx2Recording, NULL); + if( SPU2setupRecording != NULL ) SPU2setupRecording(g_Pcsx2Recording, NULL); } break; diff --git a/pcsx2/Misc.h b/pcsx2/Misc.h index d90a1cf020..7eb69a3498 100644 --- a/pcsx2/Misc.h +++ b/pcsx2/Misc.h @@ -19,6 +19,15 @@ #ifndef __MISC_H__ #define __MISC_H__ +struct KeyModifiers +{ + bool control; + bool alt; + bool shift; + bool capslock; +}; +extern struct KeyModifiers keymodifiers; + // Per ChickenLiver, this is being used to pass the GS plugins window handle to the Pad plugins. // So a rename to pDisplay is in the works, but it will not, in fact, be removed. extern uptr pDsp; //Used in GS, MTGS, Plugins, Misc @@ -55,7 +64,7 @@ extern u64 GetCPUTicks(); extern u64 GetTickFrequency(); // Used in Misc,and Windows/Linux files. -extern void ProcessFKeys(int fkey, int shift); // processes fkey related commands value 1-12 +extern void ProcessFKeys(int fkey, struct KeyModifiers *keymod); // processes fkey related commands value 1-12 extern int IsBIOS(const char *filename, char *description); char *ParseLang(char *id); diff --git a/pcsx2/SourceLog.cpp b/pcsx2/SourceLog.cpp index 66b4b037c1..29a42795ed 100644 --- a/pcsx2/SourceLog.cpp +++ b/pcsx2/SourceLog.cpp @@ -38,6 +38,7 @@ FILE *emuLog; #ifdef PCSX2_DEVBUILD u32 varLog; +bool enableLogging = TRUE; // these used by the depreciated _old_Log only u16 logProtocol; @@ -52,8 +53,10 @@ int connected=0; void __Log( const char* fmt, ... ) { char tmp[2024]; - va_list list; + + if (!enableLogging) return; + va_start(list, fmt); // concatenate the log message after the prefix: @@ -123,6 +126,9 @@ static __forceinline void _vSourceLog( u16 protocol, u8 source, u32 cpuPc, u32 c void SourceLog( u16 protocol, u8 source, u32 cpuPc, u32 cpuCycle, const char *fmt, ...) { va_list list; + + if (!enableLogging) return; + va_start(list, fmt); _vSourceLog( protocol, source, cpuPc, cpuCycle, fmt, list ); va_end(list); @@ -133,6 +139,7 @@ void SourceLog( u16 protocol, u8 source, u32 cpuPc, u32 cpuCycle, const char *fm bool SrcLog_##unit( const char* fmt, ... ) \ { \ va_list list; \ + if (!enableLogging) return false; \ va_start( list, fmt ); \ _vSourceLog( protocol, source, \ (source == 'E') ? cpuRegs.pc : psxRegs.pc, \ diff --git a/pcsx2/windows/WinSysExec.cpp b/pcsx2/windows/WinSysExec.cpp index f797094183..ec62fe33d0 100644 --- a/pcsx2/windows/WinSysExec.cpp +++ b/pcsx2/windows/WinSysExec.cpp @@ -386,14 +386,19 @@ namespace HostGui void __fastcall KeyEvent( keyEvent* ev ) { - static int shiftkey = 0; + struct KeyModifiers *keymod = &keymodifiers; if (ev == NULL) return; if (ev->evt == KEYRELEASE) { switch (ev->key) { - case VK_SHIFT: shiftkey = 0; break; + case VK_SHIFT: keymod->shift = FALSE; break; + case VK_CONTROL: keymod->control = FALSE; break; + /* They couldn't just name this something simple, like VK_ALT */ + case VK_MENU: keymod->alt = FALSE; break; + case VK_CAPITAL: keymod->capslock = FALSE; break; + } GSkeyEvent(ev); return; } @@ -402,14 +407,17 @@ namespace HostGui switch (ev->key) { - case VK_SHIFT: shiftkey = 1; break; - + case VK_SHIFT: keymod->shift = TRUE; break; + case VK_CONTROL: keymod->control = TRUE; break; + case VK_MENU: keymod->alt = TRUE; break; + case VK_CAPITAL: keymod->capslock = TRUE; break; + case VK_F1: case VK_F2: case VK_F3: case VK_F4: case VK_F5: case VK_F6: case VK_F7: case VK_F8: case VK_F9: case VK_F10: case VK_F11: case VK_F12: try { - ProcessFKeys(ev->key-VK_F1 + 1, shiftkey); + ProcessFKeys(ev->key-VK_F1 + 1, keymod); } catch( Exception::CpuStateShutdown& ) {