home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / win32 / BugReport.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  7.5 KB  |  250 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  4.  
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2, or(at your option)
  8. // any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software Foundation,
  17. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18.  
  19. // BugReport.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "vba.h"
  24. #include "BugReport.h"
  25.  
  26. #include "../agbprint.h"
  27. #include "../AutoBuild.h"
  28. #include "../GBA.h"
  29. #include "../Globals.h"
  30. #include "../Port.h"
  31. #include "../RTC.h"
  32. #include "../Sound.h"
  33. #include "../gb/gbCheats.h"
  34. #include "../gb/gbGlobals.h"
  35.  
  36. #ifdef _DEBUG
  37. #define new DEBUG_NEW
  38. #undef THIS_FILE
  39. static char THIS_FILE[] = __FILE__;
  40. #endif
  41.  
  42. /////////////////////////////////////////////////////////////////////////////
  43. // BugReport dialog
  44.  
  45.  
  46. BugReport::BugReport(CWnd* pParent /*=NULL*/)
  47.   : CDialog(BugReport::IDD, pParent)
  48. {
  49.   //{{AFX_DATA_INIT(BugReport)
  50.   // NOTE: the ClassWizard will add member initialization here
  51.   //}}AFX_DATA_INIT
  52. }
  53.  
  54.  
  55. void BugReport::DoDataExchange(CDataExchange* pDX)
  56. {
  57.   CDialog::DoDataExchange(pDX);
  58.   //{{AFX_DATA_MAP(BugReport)
  59.   DDX_Control(pDX, IDC_BUG_REPORT, m_report);
  60.   //}}AFX_DATA_MAP
  61. }
  62.  
  63.  
  64. BEGIN_MESSAGE_MAP(BugReport, CDialog)
  65.   //{{AFX_MSG_MAP(BugReport)
  66.   ON_BN_CLICKED(IDC_COPY, OnCopy)
  67.   ON_BN_CLICKED(ID_OK, OnOk)
  68.   //}}AFX_MSG_MAP
  69.   END_MESSAGE_MAP()
  70.  
  71.   /////////////////////////////////////////////////////////////////////////////
  72. // BugReport message handlers
  73.  
  74. void BugReport::OnCopy() 
  75. {
  76.   OpenClipboard();
  77.  
  78.   EmptyClipboard();
  79.   CString report;
  80.   m_report.GetWindowText(report);
  81.  
  82.   HGLOBAL hglbCopy = GlobalAlloc(GMEM_MOVEABLE, 
  83.                                  (report.GetLength() + 1) * sizeof(CHAR)); 
  84.   if (hglbCopy == NULL) { 
  85.     CloseClipboard(); 
  86.     return;
  87.   } 
  88.  
  89.   // Lock the handle and copy the text to the buffer. 
  90.  
  91.   LPSTR lptstrCopy = (LPSTR)GlobalLock(hglbCopy); 
  92.   memcpy(lptstrCopy, (const char *)report, 
  93.          report.GetLength() * sizeof(CHAR)); 
  94.   lptstrCopy[report.GetLength()] = (TCHAR) 0;    // null character 
  95.   GlobalUnlock(hglbCopy); 
  96.  
  97.   // Place the handle on the clipboard. 
  98.   
  99.   SetClipboardData(CF_TEXT, hglbCopy);   
  100.   CloseClipboard();
  101.  
  102.   systemMessage(IDS_BUG_REPORT, "Bug report has been copied to the Clipboard");
  103. }
  104.  
  105. void BugReport::OnOk() 
  106. {
  107.   EndDialog(TRUE);
  108. }
  109.  
  110. BOOL BugReport::OnInitDialog() 
  111. {
  112.   CDialog::OnInitDialog();
  113.     
  114.   CenterWindow();
  115.  
  116.   CString report = createReport();
  117.  
  118.   m_report.SetFont(CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FIXED_FONT)));
  119.  
  120.   m_report.SetWindowText(report);
  121.     
  122.   return TRUE;  // return TRUE unless you set the focus to a control
  123.   // EXCEPTION: OCX Property Pages should return FALSE
  124. }
  125.  
  126.  
  127. static void AppendFormat(CString& report, const char *format, ...)
  128. {
  129.   CString buffer;
  130.   va_list valist;
  131.  
  132.   va_start(valist, format);
  133.   buffer.FormatV(format, valist);
  134.   va_end(valist);
  135.   report += buffer;
  136. }
  137.  
  138. CString BugReport::createReport()
  139. {
  140.   theApp.winCheckFullscreen();
  141.  
  142.   CString report = "";
  143.   AppendFormat(report, "Emu version  : %s\r\n", VERSION);
  144.   AppendFormat(report, "Emu Type     : %s\r\n",
  145. #ifdef FINAL_VERSION
  146. #ifdef DEV_VERSION
  147.                "Development Version"
  148. #else
  149.                "Normal Version"
  150. #endif
  151. #else
  152.                "Debug Version"
  153. #endif
  154.                );
  155.  
  156.   if(emulating) {
  157.     AppendFormat(report, "File         : %s\r\n", theApp.szFile);
  158.  
  159.     char buffer[20];
  160.     if(theApp.cartridgeType == 0) {
  161.       u32 check = 0;
  162.       for(int i = 0; i < 0x4000; i += 4) {
  163.         check += *((u32 *)&bios[i]);
  164.       }
  165.       AppendFormat(report, "BIOS Checksum: %08X\r\n", check);
  166.  
  167.       strncpy(buffer, (const char *)&rom[0xa0], 12);
  168.       buffer[12] = 0;
  169.       AppendFormat(report, "Internal name: %s\r\n", buffer);
  170.       
  171.       strncpy(buffer, (const char *)&rom[0xac], 4);
  172.       buffer[4] = 0;
  173.       AppendFormat(report, "Game code    : %s\r\n", buffer);
  174.  
  175.       CString res = "";
  176.       u32 *p = (u32 *)rom;
  177.       u32 *end = (u32 *)((char *)rom+theApp.romSize);
  178.       while(p  < end) {
  179.         u32 d = READ32LE(p);
  180.     
  181.         if(d == 0x52504545) {
  182.           if(memcmp(p, "EEPROM_", 7) == 0) {
  183.             res += (const char *)p;
  184.             res += ' ';
  185.           }
  186.         } else if (d == 0x4D415253) {
  187.           if(memcmp(p, "SRAM_", 5) == 0) {
  188.             res += (const char *)p;
  189.             res += ' ';
  190.           }
  191.         } else if (d == 0x53414C46) {
  192.           if(memcmp(p, "FLASH1M_", 8) == 0) {
  193.             res += (const char *)p;
  194.             res += ' ';
  195.           }
  196.         } else if(memcmp(p, "FLASH", 5) == 0) {
  197.           res += (const char *)p;
  198.           res += ' ';
  199.         } else if (d == 0x52494953) {
  200.           if(memcmp(p, "SIIRTC_V", 8) == 0) {
  201.             res += (const char *)p;
  202.             res += ' ';
  203.           }
  204.         }
  205.         p++;
  206.       }
  207.       if(res.GetLength() > 0)
  208.         AppendFormat(report, "Cart Save    : %s\r\n", res);
  209.     } else if(theApp.cartridgeType == 1) {
  210.       strncpy(buffer, (const char *)&gbRom[0x134], 15);
  211.       buffer[15] = 0;
  212.       AppendFormat(report, "Game title   : %s\r\n", buffer);
  213.     }
  214.   }
  215.   
  216.   AppendFormat(report, "Using BIOS   : %d\r\n", theApp.useBiosFile);
  217.   AppendFormat(report, "Skip BIOS    : %d\r\n", theApp.skipBiosFile);
  218.   AppendFormat(report, "Disable SFX  : %d\r\n", cpuDisableSfx);
  219.   AppendFormat(report, "Skip intro   : %d\r\n", theApp.removeIntros);
  220.   AppendFormat(report, "Throttle     : %d\r\n", theApp.throttle);
  221.   AppendFormat(report, "Rewind       : %d\r\n", theApp.rewindTimer);
  222.   AppendFormat(report, "Auto frame   : %d\r\n", theApp.autoFrameSkip);
  223.   AppendFormat(report, "Video option : %d\r\n", theApp.videoOption);
  224.   AppendFormat(report, "Render type  : %d\r\n", theApp.renderMethod);
  225.   AppendFormat(report, "Color depth  : %d\r\n", systemColorDepth);
  226.   AppendFormat(report, "Red shift    : %08x\r\n", systemRedShift);
  227.   AppendFormat(report, "Green shift  : %08x\r\n", systemGreenShift);
  228.   AppendFormat(report, "Blue shift   : %08x\r\n", systemBlueShift);
  229.   AppendFormat(report, "Layer setting: %04X\r\n", layerSettings);
  230.   AppendFormat(report, "Save type    : %d (%d)\r\n", 
  231.                theApp.winSaveType, cpuSaveType);
  232.   AppendFormat(report, "Flash size   : %08X (%08x)\r\n", 
  233.                theApp.winFlashSize, flashSize);
  234.   AppendFormat(report, "RTC          : %d (%d)\r\n", theApp.winRtcEnable,
  235.                rtcIsEnabled());
  236.   AppendFormat(report, "AGBPrint     : %d\r\n", agbPrintIsEnabled());
  237.   AppendFormat(report, "Speed toggle : %d\r\n", theApp.speedupToggle);
  238.   AppendFormat(report, "Synchronize  : %d\r\n", synchronize);
  239.   AppendFormat(report, "Sound OFF    : %d\r\n", soundOffFlag);
  240.   AppendFormat(report, "Channels     : %04x\r\n", soundGetEnable() & 0x30f);
  241.   AppendFormat(report, "Old Sync     : %d\r\n", theApp.useOldSync);
  242.   AppendFormat(report, "Priority     : %d\r\n", theApp.threadPriority);
  243.   AppendFormat(report, "Filters      : %d (%d)\r\n", theApp.filterType, theApp.ifbType);
  244.   AppendFormat(report, "Cheats       : %d\r\n", cheatsNumber);
  245.   AppendFormat(report, "GB Cheats    : %d\r\n", gbCheatNumber);
  246.   AppendFormat(report, "GB Emu Type  : %d\r\n", gbEmulatorType);
  247.  
  248.   return report;
  249. }
  250.