Skip to content

Commit

Permalink
Some debug stuff work.
Browse files Browse the repository at this point in the history
  • Loading branch information
KrossX committed Aug 19, 2013
1 parent bbe0a0b commit c6db4c5
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 27 deletions.
48 changes: 48 additions & 0 deletions Pokopom/DebugStuff.cpp
Original file line number Diff line number Diff line change
@@ -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);
}







23 changes: 23 additions & 0 deletions Pokopom/DebugStuff.h
Original file line number Diff line number Diff line change
@@ -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
8 changes: 1 addition & 7 deletions Pokopom/General.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
31 changes: 19 additions & 12 deletions Pokopom/PlayStation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down Expand Up @@ -160,6 +160,7 @@ DllExport void CALLBACK PADshutdown() // PAD SHUTDOWN
DllExport s32 CALLBACK PADopen(void* pDisplay) // PAD OPEN
{
DebugFunc();

Input::Pause(false);

GetDisplay(pDisplay);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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)
Expand Down Expand Up @@ -350,6 +353,7 @@ DllExport u32 CALLBACK PADfreeze(s32 mode, freezeData *data)
DllExport keyEvent* CALLBACK PADkeyEvent()
{
DebugFunc();

static keyEvent pochy;

if(!isPs2Emulator)
Expand All @@ -373,23 +377,25 @@ 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;
}

DllExport void CALLBACK PADsetSettingsDir(const char *dir)
{
Debug("Pokopom -> PadsetSettingsDir: %s\n", dir);
DebugPrint("%s", dir);

if(dir)
memcpy(settingsDirectory, dir, strlen(dir)+1);
}

DllExport void PADWriteEvent(keyEvent &evt)
{
DebugFunc();

switch(evt.evt)
{
case 0x02:
Expand All @@ -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;

Expand All @@ -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);
}


Expand Down
2 changes: 2 additions & 0 deletions Pokopom/Pokopom_vs11.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<ClInclude Include="ConfigDialog.h" />
<ClInclude Include="ConsoleOutput.h" />
<ClInclude Include="Controller.h" />
<ClInclude Include="DebugStuff.h" />
<ClInclude Include="FileIO.h" />
<ClInclude Include="General.h" />
<ClInclude Include="Input.h" />
Expand All @@ -116,6 +117,7 @@
<ClCompile Include="Controller2.cpp" />
<ClCompile Include="ControllerGuitar.cpp" />
<ClCompile Include="ControllerMtap.cpp" />
<ClCompile Include="DebugStuff.cpp" />
<ClCompile Include="FileIO.cpp" />
<ClCompile Include="Input_Linux.cpp" />
<ClCompile Include="Input_Shared.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions Pokopom/Pokopom_vs11.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
<ClInclude Include="nullDC_plugin_types_old.h">
<Filter>Systems\Dreamcast\Headers</Filter>
</ClInclude>
<ClInclude Include="DebugStuff.h">
<Filter>General\Headers</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Settings.cpp">
Expand Down Expand Up @@ -158,6 +161,9 @@
<ClCompile Include="FileIO.cpp">
<Filter>General</Filter>
</ClCompile>
<ClCompile Include="DebugStuff.cpp">
<Filter>General</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Background.bmp">
Expand Down
7 changes: 4 additions & 3 deletions Pokopom/Stuff_Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ void ScrollLockStuff(bool init)
static bool scrollLock = false;
static bool scrollLockSaved = false;


if(!scrollLockSaved && init)
{
scrollLock = GetKeyState(VK_SCROLL)&0x1;
Expand All @@ -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;
Expand Down
11 changes: 6 additions & 5 deletions Pokopom/nullDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand All @@ -358,15 +359,15 @@ 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);
}

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////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit c6db4c5

Please sign in to comment.