diff src/win32/BugReport.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/win32/BugReport.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,235 @@
     1.4 +// BugReport.cpp : implementation file
     1.5 +//
     1.6 +
     1.7 +#include "stdafx.h"
     1.8 +#include "resource.h"
     1.9 +#include "BugReport.h"
    1.10 +#include "VBA.h"
    1.11 +
    1.12 +#include "../version.h"
    1.13 +#include "../gba/agbprint.h"
    1.14 +#include "../gba/Flash.h"
    1.15 +#include "../gba/GBACheats.h"
    1.16 +#include "../gba/GBAGlobals.h"
    1.17 +#include "../gb/gbCheats.h"
    1.18 +#include "../gb/gbGlobals.h"
    1.19 +#include "../gba/RTC.h"
    1.20 +#include "../gba/GBASound.h"
    1.21 +#include "../common/vbalua.h"
    1.22 +
    1.23 +/////////////////////////////////////////////////////////////////////////////
    1.24 +// BugReport dialog
    1.25 +
    1.26 +BugReport::BugReport(CWnd*pParent /*=NULL*/)
    1.27 +	: CDialog(BugReport::IDD, pParent)
    1.28 +{
    1.29 +	//{{AFX_DATA_INIT(BugReport)
    1.30 +	// NOTE: the ClassWizard will add member initialization here
    1.31 +	//}}AFX_DATA_INIT
    1.32 +}
    1.33 +
    1.34 +void BugReport::DoDataExchange(CDataExchange*pDX)
    1.35 +{
    1.36 +	CDialog::DoDataExchange(pDX);
    1.37 +	//{{AFX_DATA_MAP(BugReport)
    1.38 +	DDX_Control(pDX, IDC_BUG_REPORT, m_report);
    1.39 +	//}}AFX_DATA_MAP
    1.40 +}
    1.41 +
    1.42 +BEGIN_MESSAGE_MAP(BugReport, CDialog)
    1.43 +//{{AFX_MSG_MAP(BugReport)
    1.44 +ON_BN_CLICKED(IDC_COPY, OnCopy)
    1.45 +ON_BN_CLICKED(ID_OK, OnOk)
    1.46 +//}}AFX_MSG_MAP
    1.47 +END_MESSAGE_MAP()
    1.48 +
    1.49 +/////////////////////////////////////////////////////////////////////////////
    1.50 +// BugReport message handlers
    1.51 +
    1.52 +void BugReport::OnCopy()
    1.53 +{
    1.54 +	OpenClipboard();
    1.55 +
    1.56 +	EmptyClipboard();
    1.57 +	CString report;
    1.58 +	m_report.GetWindowText(report);
    1.59 +
    1.60 +	HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE,
    1.61 +	                               (report.GetLength() + 1) * sizeof(CHAR));
    1.62 +	if (hglbCopy == NULL)
    1.63 +	{
    1.64 +		CloseClipboard();
    1.65 +		return;
    1.66 +	}
    1.67 +
    1.68 +	// Lock the handle and copy the text to the buffer.
    1.69 +
    1.70 +	LPSTR lptstrCopy = (LPSTR)GlobalLock(hglbCopy);
    1.71 +	memcpy(lptstrCopy, (const char *)report,
    1.72 +	       report.GetLength() * sizeof(CHAR));
    1.73 +	lptstrCopy[report.GetLength()] = (TCHAR) 0;  // null character
    1.74 +	GlobalUnlock(hglbCopy);
    1.75 +
    1.76 +	// Place the handle on the clipboard.
    1.77 +
    1.78 +	SetClipboardData(CF_TEXT, hglbCopy);
    1.79 +	CloseClipboard();
    1.80 +
    1.81 +	systemMessage(IDS_BUG_REPORT, "Bug report has been copied to the Clipboard");
    1.82 +}
    1.83 +
    1.84 +void BugReport::OnOk()
    1.85 +{
    1.86 +	EndDialog(TRUE);
    1.87 +}
    1.88 +
    1.89 +BOOL BugReport::OnInitDialog()
    1.90 +{
    1.91 +	CDialog::OnInitDialog();
    1.92 +
    1.93 +	CenterWindow();
    1.94 +
    1.95 +	CString report = createReport();
    1.96 +
    1.97 +	m_report.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)));
    1.98 +
    1.99 +	m_report.SetWindowText(report);
   1.100 +
   1.101 +	return TRUE; // return TRUE unless you set the focus to a control
   1.102 +	// EXCEPTION: OCX Property Pages should return FALSE
   1.103 +}
   1.104 +
   1.105 +static void AppendFormat(CString& report, const char *format, ...)
   1.106 +{
   1.107 +	CString buffer;
   1.108 +	va_list valist;
   1.109 +
   1.110 +	va_start(valist, format);
   1.111 +	buffer.FormatV(format, valist);
   1.112 +	va_end(valist);
   1.113 +	report += buffer;
   1.114 +}
   1.115 +
   1.116 +CString BugReport::createReport()
   1.117 +{
   1.118 +	theApp.winCheckFullscreen();
   1.119 +
   1.120 +	CString report = "";
   1.121 +	AppendFormat(report, "Emu version  : %s\r\n", VBA_VERSION_STRING);
   1.122 +AppendFormat(report, "Emu type     : %s\r\n", VBA_BUILDTYPE_STRING);
   1.123 +
   1.124 +	if (systemIsEmulating())
   1.125 +	{
   1.126 +		AppendFormat(report, "Game         : %s\r\n", theApp.gameFilename);
   1.127 +
   1.128 +		char buffer[20];
   1.129 +		if (systemCartridgeType == 0)
   1.130 +		{
   1.131 +			u32 check = 0;
   1.132 +			for (int i = 0; i < 0x4000; i += 4)
   1.133 +			{
   1.134 +				check += *((u32 *)&bios[i]);
   1.135 +			}
   1.136 +			AppendFormat(report, "BIOS checksum: %08X\r\n", check);
   1.137 +
   1.138 +			strncpy(buffer, (const char *)&rom[0xa0], 12);
   1.139 +			buffer[12] = 0;
   1.140 +			AppendFormat(report, "Internal name: %s\r\n", buffer);
   1.141 +
   1.142 +			strncpy(buffer, (const char *)&rom[0xac], 4);
   1.143 +			buffer[4] = 0;
   1.144 +			AppendFormat(report, "Game code    : %s\r\n", buffer);
   1.145 +
   1.146 +			CString res = "";
   1.147 +			u32 *   p   = (u32 *)rom;
   1.148 +			u32 *   end = (u32 *)((char *)rom+theApp.romSize);
   1.149 +			while (p  < end)
   1.150 +			{
   1.151 +				u32 d = READ32LE(p);
   1.152 +
   1.153 +				if (d == 0x52504545)
   1.154 +				{
   1.155 +					if (memcmp(p, "EEPROM_", 7) == 0)
   1.156 +					{
   1.157 +						res += (const char *)p;
   1.158 +						res += ' ';
   1.159 +					}
   1.160 +				}
   1.161 +				else if (d == 0x4D415253)
   1.162 +				{
   1.163 +					if (memcmp(p, "SRAM_", 5) == 0)
   1.164 +					{
   1.165 +						res += (const char *)p;
   1.166 +						res += ' ';
   1.167 +					}
   1.168 +				}
   1.169 +				else if (d == 0x53414C46)
   1.170 +				{
   1.171 +					if (memcmp(p, "FLASH1M_", 8) == 0)
   1.172 +					{
   1.173 +						res += (const char *)p;
   1.174 +						res += ' ';
   1.175 +					}
   1.176 +				}
   1.177 +				else if (memcmp(p, "FLASH", 5) == 0)
   1.178 +				{
   1.179 +					res += (const char *)p;
   1.180 +					res += ' ';
   1.181 +				}
   1.182 +				else if (d == 0x52494953)
   1.183 +				{
   1.184 +					if (memcmp(p, "SIIRTC_V", 8) == 0)
   1.185 +					{
   1.186 +						res += (const char *)p;
   1.187 +						res += ' ';
   1.188 +					}
   1.189 +				}
   1.190 +				p++;
   1.191 +			}
   1.192 +			if (res.GetLength() > 0)
   1.193 +				AppendFormat(report, "Cart Save    : %s\r\n", res);
   1.194 +		}
   1.195 +		else if (systemCartridgeType == 1)
   1.196 +		{
   1.197 +			strncpy(buffer, (const char *)&gbRom[0x134], 15);
   1.198 +			buffer[15] = 0;
   1.199 +			AppendFormat(report, "Game title   : %s\r\n", buffer);
   1.200 +		}
   1.201 +	}
   1.202 +
   1.203 +	AppendFormat(report, "Using BIOS   : %d\r\n", useBios);
   1.204 +	AppendFormat(report, "Skip BIOS    : %d\r\n", theApp.skipBiosFile);
   1.205 +	AppendFormat(report, "Disable SFX  : %d\r\n", cpuDisableSfx);
   1.206 +///  AppendFormat(report, "Skip intro   : %d\r\n", theApp.removeIntros);
   1.207 +	AppendFormat(report, "Throttle     : %d\r\n", theApp.throttle);
   1.208 +	AppendFormat(report, "Rewind       : %d\r\n", theApp.rewindTimer);
   1.209 +	AppendFormat(report, "Lua          : %d\r\n", VBALuaRunning());
   1.210 +///  AppendFormat(report, "Auto frame   : %d\r\n", theApp.autoFrameSkip);
   1.211 +	AppendFormat(report, "Video option : %d\r\n", theApp.videoOption);
   1.212 +	AppendFormat(report, "Render type  : %d\r\n", theApp.renderMethod);
   1.213 +	AppendFormat(report, "Color depth  : %d\r\n", systemColorDepth);
   1.214 +	AppendFormat(report, "Red shift    : %08x\r\n", systemRedShift);
   1.215 +	AppendFormat(report, "Green shift  : %08x\r\n", systemGreenShift);
   1.216 +	AppendFormat(report, "Blue shift   : %08x\r\n", systemBlueShift);
   1.217 +	AppendFormat(report, "Layer setting: %04X\r\n", layerSettings);
   1.218 +	AppendFormat(report, "Save type    : %d (%d)\r\n",
   1.219 +	             theApp.winSaveType, cpuSaveType);
   1.220 +	AppendFormat(report, "Flash size   : %08X (%08x)\r\n",
   1.221 +	             theApp.winFlashSize, flashSize);
   1.222 +	AppendFormat(report, "RTC          : %d (%d)\r\n", theApp.winRtcEnable,
   1.223 +	             rtcIsEnabled());
   1.224 +	AppendFormat(report, "AGBPrint     : %d\r\n", agbPrintIsEnabled());
   1.225 +	AppendFormat(report, "Turbo Mode   : %d\r\n", theApp.speedupToggle);
   1.226 +	AppendFormat(report, "Synchronize  : %d\r\n", synchronize);
   1.227 +	AppendFormat(report, "Sound OFF    : %d\r\n", soundOffFlag);
   1.228 +	AppendFormat(report, "Channels     : %04x\r\n", soundGetEnabledChannels() & 0x30f);
   1.229 +	AppendFormat(report, "Old Sync     : %d\r\n", theApp.useOldSync);
   1.230 +	AppendFormat(report, "Priority     : %d\r\n", theApp.threadPriority);
   1.231 +	AppendFormat(report, "Filters      : %d (%d)\r\n", theApp.filterType, theApp.ifbType);
   1.232 +	AppendFormat(report, "Cheats       : %d\r\n", cheatsNumber);
   1.233 +	AppendFormat(report, "GB Cheats    : %d\r\n", gbCheatNumber);
   1.234 +	AppendFormat(report, "GB Emu Type  : %d\r\n", gbEmulatorType);
   1.235 +
   1.236 +	return report;
   1.237 +}
   1.238 +