From c6db4c58c07ba7526db94e3f2358613884c9dcbf Mon Sep 17 00:00:00 2001 From: KrossX Date: Mon, 19 Aug 2013 00:52:04 -0300 Subject: [PATCH] Some debug stuff work. --- Pokopom/DebugStuff.cpp | 48 ++++++++++++++++++++++++++++ Pokopom/DebugStuff.h | 23 +++++++++++++ Pokopom/General.h | 8 +---- Pokopom/PlayStation.cpp | 31 +++++++++++------- Pokopom/Pokopom_vs11.vcxproj | 2 ++ Pokopom/Pokopom_vs11.vcxproj.filters | 6 ++++ Pokopom/Stuff_Windows.cpp | 7 ++-- Pokopom/nullDC.cpp | 11 ++++--- 8 files changed, 109 insertions(+), 27 deletions(-) create mode 100644 Pokopom/DebugStuff.cpp create mode 100644 Pokopom/DebugStuff.h diff --git a/Pokopom/DebugStuff.cpp b/Pokopom/DebugStuff.cpp new file mode 100644 index 0000000..a9df59b --- /dev/null +++ b/Pokopom/DebugStuff.cpp @@ -0,0 +1,48 @@ +#include "General.h" + +FILE *logfile = NULL; + +bool _DebugOpen() +{ + logfile = fopen("pokopom.log", "w"); + if(logfile) fprintf(logfile, "DebugOpen\n"); + return !!logfile; +} + +void _DebugClose() +{ + if(logfile) fprintf(logfile, "DebugClose\n"); + if(logfile) fclose(logfile); + logfile = NULL; +} + +void _DebugFunc(const char* func) +{ + if(!logfile && !_DebugOpen()) return; + + fprintf(logfile, "%s\n", func); + fflush(logfile); +} + +void _DebugPrint(const char* func, const char* fmt, ...) +{ + if(!logfile && !_DebugOpen()) return; + + va_list args; + + fprintf(logfile, "%s : ", func); + + va_start(args,fmt); + vfprintf(logfile, fmt, args); + va_end(args); + + fprintf(logfile, "\n"); + fflush(logfile); +} + + + + + + + diff --git a/Pokopom/DebugStuff.h b/Pokopom/DebugStuff.h new file mode 100644 index 0000000..97457b2 --- /dev/null +++ b/Pokopom/DebugStuff.h @@ -0,0 +1,23 @@ +#pragma once + + +#if 0 + + bool _DebugOpen(); + void _DebugClose(); + void _DebugFunc(const char* func); + void _DebugPrint(const char* func, const char* fmt, ...); + + #define DebugOpen() _DebugOpen() + #define DebugClose() _DebugClose() + #define DebugPrint(...) _DebugPrint(__FUNCTION__, __VA_ARGS__) + #define DebugFunc() _DebugFunc(__FUNCTION__) + +#else + + #define DebugOpen() + #define DebugClose() + #define DebugPrint(...) + #define DebugFunc() + +#endif \ No newline at end of file diff --git a/Pokopom/General.h b/Pokopom/General.h index 66cba77..74fa120 100644 --- a/Pokopom/General.h +++ b/Pokopom/General.h @@ -55,10 +55,4 @@ #include "Stuff.h" #include "Settings.h" -#if 0 - #define Debug printf - #define DebugFunc() printf("Pokopom -> "__FUNCTION__"\n") -#else - #define Debug(...) - #define DebugFunc() -#endif +#include "DebugStuff.h" diff --git a/Pokopom/PlayStation.cpp b/Pokopom/PlayStation.cpp index b12aca2..52fc4c9 100644 --- a/Pokopom/PlayStation.cpp +++ b/Pokopom/PlayStation.cpp @@ -89,7 +89,7 @@ DllExport u32 CALLBACK PS2EgetLibVersion2(u32 type) DllExport s32 CALLBACK PADinit(s32 flags) // PAD INIT { FileIO::INI_LoadSettings(); - Debug("Pokopom -> PADinit [%X]\n", flags); + DebugPrint("[%X]", flags); for(int pad = 0; pad < 2; pad++) { @@ -160,6 +160,7 @@ DllExport void CALLBACK PADshutdown() // PAD SHUTDOWN DllExport s32 CALLBACK PADopen(void* pDisplay) // PAD OPEN { DebugFunc(); + Input::Pause(false); GetDisplay(pDisplay); @@ -172,6 +173,7 @@ DllExport s32 CALLBACK PADopen(void* pDisplay) // PAD OPEN DllExport s32 CALLBACK PADclose() // PAD CLOSE { DebugFunc(); + Input::Pause(true); KeyboardClose(); KeepAwake(KEEPAWAKE_CLOSE); @@ -228,7 +230,7 @@ DllExport s32 CALLBACK PADquery() s32 FASTCALL PADreadPort(s32 port, emupro::pad::DataS* ppds) { - Debug("Pokopom -> PADreadPort [%X]\n", port); + DebugPrint("[%X]", port); controller[port]->command(0, 0x01); u8 cType = controller[port]->command(1, 0x42); @@ -275,8 +277,8 @@ DllExport u8 CALLBACK PADstartPoll(s32 port) u8 data = controller[curPort]->command(bufferCount, curSlot); - //if(curPort == 0) printf("\n[%02d] [%02X|%02X]\n", bufferCount, curSlot, data); - Debug("\n[%02d|%02d] [%02X|%02X]\n", bufferCount, curPort, curSlot, data); + //if(curPort == 0) + DebugPrint("[%02d|%02d] [%02X|%02X]", bufferCount, curPort, curSlot, data); return data; } @@ -287,8 +289,8 @@ DllExport u8 CALLBACK PADpoll(u8 data) u8 doto = controller[curPort]->command(bufferCount, data); - //if(curPort == 0) printf("[%02d] [%02X|%02X]\n", bufferCount, data, doto); - Debug("[%02d|%02d] [%02X|%02X]\n", bufferCount, curPort, data, doto); + //if(curPort == 0) + DebugPrint("[%02d|%02d] [%02X|%02X]", bufferCount, curPort, data, doto); return doto; } @@ -300,7 +302,8 @@ DllExport u8 CALLBACK PADpoll(u8 data) DllExport u32 CALLBACK PADfreeze(s32 mode, freezeData *data) { - Debug("Pokopom -> PADfreeze [%X]\n", mode); + DebugPrint("[%X]", mode); + if(!data) return (u32)emupro::ERR_FATAL; switch(mode) @@ -350,6 +353,7 @@ DllExport u32 CALLBACK PADfreeze(s32 mode, freezeData *data) DllExport keyEvent* CALLBACK PADkeyEvent() { DebugFunc(); + static keyEvent pochy; if(!isPs2Emulator) @@ -373,8 +377,8 @@ DllExport s32 PADkeypressed() DllExport u32 CALLBACK PADqueryMtap(u8 port) { - printf("Pokopom -> PADqueryMtap [%X]\n", port); - + DebugPrint("[%X]", port); + if(multitap == 1 && port == 1) return 1; else if(multitap == 2) return 1; else return 0; @@ -382,7 +386,8 @@ DllExport u32 CALLBACK PADqueryMtap(u8 port) DllExport void CALLBACK PADsetSettingsDir(const char *dir) { - Debug("Pokopom -> PadsetSettingsDir: %s\n", dir); + DebugPrint("%s", dir); + if(dir) memcpy(settingsDirectory, dir, strlen(dir)+1); } @@ -390,6 +395,7 @@ DllExport void CALLBACK PADsetSettingsDir(const char *dir) DllExport void PADWriteEvent(keyEvent &evt) { DebugFunc(); + switch(evt.evt) { case 0x02: @@ -407,7 +413,8 @@ DllExport void PADWriteEvent(keyEvent &evt) DllExport u32 CALLBACK PADsetSlot(u8 port, u8 slot) { - Debug("Pokopom -> PADsetSlot [%X|%X] ", port, slot); + DebugPrint("[%X|%X]", port, slot); + curPort = port - 1; curSlot = slot; @@ -429,7 +436,7 @@ DllExport u32 CALLBACK PADsetSlot(u8 port, u8 slot) DllExport void CALLBACK PADupdate(s32 port) { - Debug("Pokopom -> PADupdate [%X]\n", port); + DebugPrint("[%X]", port); } diff --git a/Pokopom/Pokopom_vs11.vcxproj b/Pokopom/Pokopom_vs11.vcxproj index c6eb015..bb9477f 100644 --- a/Pokopom/Pokopom_vs11.vcxproj +++ b/Pokopom/Pokopom_vs11.vcxproj @@ -92,6 +92,7 @@ + @@ -116,6 +117,7 @@ + diff --git a/Pokopom/Pokopom_vs11.vcxproj.filters b/Pokopom/Pokopom_vs11.vcxproj.filters index 5f4313e..22abdc6 100644 --- a/Pokopom/Pokopom_vs11.vcxproj.filters +++ b/Pokopom/Pokopom_vs11.vcxproj.filters @@ -96,6 +96,9 @@ Systems\Dreamcast\Headers + + General\Headers + @@ -158,6 +161,9 @@ General + + General + diff --git a/Pokopom/Stuff_Windows.cpp b/Pokopom/Stuff_Windows.cpp index 7c6eae1..5aeae7f 100644 --- a/Pokopom/Stuff_Windows.cpp +++ b/Pokopom/Stuff_Windows.cpp @@ -138,7 +138,6 @@ void ScrollLockStuff(bool init) static bool scrollLock = false; static bool scrollLockSaved = false; - if(!scrollLockSaved && init) { scrollLock = GetKeyState(VK_SCROLL)&0x1; @@ -161,12 +160,14 @@ BOOL APIENTRY DllMain(HMODULE hInst, DWORD dwReason, LPVOID lpReserved) switch(dwReason) { case DLL_PROCESS_ATTACH: - case DLL_THREAD_ATTACH: + //case DLL_THREAD_ATTACH: + DebugOpen(); ScrollLockStuff(true); break; case DLL_PROCESS_DETACH: - case DLL_THREAD_DETACH: + //case DLL_THREAD_DETACH: + DebugClose(); Input::StopRumbleAll(); ScrollLockStuff(false); break; diff --git a/Pokopom/nullDC.cpp b/Pokopom/nullDC.cpp index 9c9b32c..305c583 100644 --- a/Pokopom/nullDC.cpp +++ b/Pokopom/nullDC.cpp @@ -210,7 +210,8 @@ void FASTCALL Unload() s32 FASTCALL CreateMain(nullDC::maple_device_instance* inst, u32 id, u32 flags, u32 rootmenu) { - Debug("Pokopom -> CreateMain [%X|%X]\n", inst->port >> 6, id); + DebugPrint("[%X|%X]", inst->port >> 6, id); + u32 port = (inst->port >> 6); switch(dcPlatform) @@ -294,7 +295,7 @@ s32 FASTCALL CreateSub(nullDC::maple_subdevice_instance* inst, u32 id, u32 flags { u8 port = inst->port>>6; u8 subport = GetSubport(inst->port); - Debug("Pokopom -> CreateSub [%X|%X|%X]\n", port, subport, id); + DebugPrint("[%X|%X|%X]", port, subport, id); switch(dcPlatform) { @@ -348,7 +349,7 @@ s32 FASTCALL CreateSub(nullDC::maple_subdevice_instance* inst, u32 id, u32 flags s32 FASTCALL Init(void* data, u32 id, nullDC::maple_init_params* params) { - Debug("Pokopom -> Init [%d]\n", ((nullDC::maple_device_instance*)data)->port >> 6); + DebugPrint("[%d]\n", ((nullDC::maple_device_instance*)data)->port >> 6); Input::Pause(false); KeepAwake(KEEPAWAKE_INIT); @@ -358,7 +359,7 @@ s32 FASTCALL Init(void* data, u32 id, nullDC::maple_init_params* params) void FASTCALL Term(void* data, u32 id) { - Debug("Pokopom -> Term [%d]\n", ((nullDC::maple_device_instance*)data)->port >> 6); + DebugPrint("[%d]\n", ((nullDC::maple_device_instance*)data)->port >> 6); Input::Pause(true); KeepAwake(KEEPAWAKE_CLOSE); @@ -366,7 +367,7 @@ void FASTCALL Term(void* data, u32 id) void FASTCALL Destroy(void* data, u32 id) { - Debug("Pokopom -> Destroy [%d]\n", ((nullDC::maple_device_instance*)data)->port >> 6); + DebugPrint("[%d]\n", ((nullDC::maple_device_instance*)data)->port >> 6); } //103////////////////////////////////////////////////////////////////////