Project64: Code clean up

This commit is contained in:
zilmar 2022-09-21 14:46:07 +09:30
parent a2981ff4d8
commit a65086579f
108 changed files with 3500 additions and 3311 deletions

View File

@ -1,10 +1,11 @@
#include "stdafx.h" #include "stdafx.h"
#include <io.h>
#include "PluginList.h" #include "PluginList.h"
#include <Project64-core/Plugins/PluginBase.h> #include <Project64-core/Plugins/PluginBase.h>
#include <io.h>
CPluginList::CPluginList(bool bAutoFill /* = true */) : CPluginList::CPluginList(bool bAutoFill /* = true */) :
m_PluginDir(g_Settings->LoadStringVal(Directory_Plugin), "") m_PluginDir(g_Settings->LoadStringVal(Directory_Plugin), "")
{ {
if (bAutoFill) if (bAutoFill)
{ {
@ -75,14 +76,14 @@ void CPluginList::AddPluginFromDir(CPath Dir)
continue; continue;
} }
void(CALL *GetDllInfo) (PLUGIN_INFO * PluginInfo); void(CALL * GetDllInfo)(PLUGIN_INFO * PluginInfo);
GetDllInfo = (void(CALL *)(PLUGIN_INFO *))GetProcAddress(hLib, "GetDllInfo"); GetDllInfo = (void(CALL *)(PLUGIN_INFO *))GetProcAddress(hLib, "GetDllInfo");
if (GetDllInfo == nullptr) if (GetDllInfo == nullptr)
{ {
continue; continue;
} }
PLUGIN Plugin = { 0 }; PLUGIN Plugin = {0};
Plugin.Info.Reserved2 = true; Plugin.Info.Reserved2 = true;
GetDllInfo(&Plugin.Info); GetDllInfo(&Plugin.Info);
if (!CPlugin::ValidPluginVersion(Plugin.Info)) if (!CPlugin::ValidPluginVersion(Plugin.Info))

View File

@ -1,6 +1,6 @@
#include "stdafx.h" #include "stdafx.h"
int CGuiSettings::m_RefCount = 0; int CGuiSettings::m_RefCount = 0;
bool CGuiSettings::m_bCPURunning; bool CGuiSettings::m_bCPURunning;
bool CGuiSettings::m_bAutoSleep; bool CGuiSettings::m_bAutoSleep;
@ -9,8 +9,8 @@ CGuiSettings::CGuiSettings()
m_RefCount += 1; m_RefCount += 1;
if (m_RefCount == 1) if (m_RefCount == 1)
{ {
g_Settings->RegisterChangeCB(GameRunning_CPU_Running,nullptr,RefreshSettings); g_Settings->RegisterChangeCB(GameRunning_CPU_Running, nullptr, RefreshSettings);
g_Settings->RegisterChangeCB((SettingID)Setting_AutoSleep,nullptr,RefreshSettings); g_Settings->RegisterChangeCB((SettingID)Setting_AutoSleep, nullptr, RefreshSettings);
RefreshSettings(nullptr); RefreshSettings(nullptr);
} }
} }
@ -20,8 +20,8 @@ CGuiSettings::~CGuiSettings()
m_RefCount -= 1; m_RefCount -= 1;
if (m_RefCount == 0) if (m_RefCount == 0)
{ {
g_Settings->UnregisterChangeCB(GameRunning_CPU_Running,nullptr,RefreshSettings); g_Settings->UnregisterChangeCB(GameRunning_CPU_Running, nullptr, RefreshSettings);
g_Settings->UnregisterChangeCB((SettingID)Setting_AutoSleep,nullptr,RefreshSettings); g_Settings->UnregisterChangeCB((SettingID)Setting_AutoSleep, nullptr, RefreshSettings);
} }
} }

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "UISettings.h" #include "UISettings.h"
#include <Project64-core/Settings/SettingType/SettingsType-Application.h> #include <Project64-core/Settings/SettingType/SettingsType-Application.h>
#include <Project64-core/Settings/SettingType/SettingsType-ApplicationIndex.h> #include <Project64-core/Settings/SettingType/SettingsType-ApplicationIndex.h>
@ -13,7 +14,7 @@ void AddUISetting(UISettingID TypeID, CSettingType * Handler)
g_Settings->AddHandler((SettingID)TypeID, Handler); g_Settings->AddHandler((SettingID)TypeID, Handler);
} }
void RegisterUISettings (void) void RegisterUISettings(void)
{ {
// Information - temporary keys // Information - temporary keys
AddUISetting(Info_ShortCutsChanged, new CSettingTypeTempBool(false)); AddUISetting(Info_ShortCutsChanged, new CSettingTypeTempBool(false));
@ -24,10 +25,10 @@ void RegisterUISettings (void)
// Settings location // Settings location
AddUISetting(Setting_PluginPageFirst, new CSettingTypeApplication("Settings", "Plugin Page First", false)); AddUISetting(Setting_PluginPageFirst, new CSettingTypeApplication("Settings", "Plugin Page First", false));
AddUISetting(Setting_DisableScrSaver, new CSettingTypeApplication("Settings", "Disable Screen Saver", (uint32_t)true)); AddUISetting(Setting_DisableScrSaver, new CSettingTypeApplication("Settings", "Disable Screen Saver", (uint32_t) true));
AddUISetting(Setting_EnableDiscordRPC, new CSettingTypeApplication("Settings", "Enable Discord RPC", true)); AddUISetting(Setting_EnableDiscordRPC, new CSettingTypeApplication("Settings", "Enable Discord RPC", true));
AddUISetting(Setting_AutoSleep, new CSettingTypeApplication("Settings", "Auto Sleep", (uint32_t)true)); AddUISetting(Setting_AutoSleep, new CSettingTypeApplication("Settings", "Auto Sleep", (uint32_t) true));
AddUISetting(Setting_AutoFullscreen, new CSettingTypeApplication("Settings", "Auto Full Screen", (uint32_t)false)); AddUISetting(Setting_AutoFullscreen, new CSettingTypeApplication("Settings", "Auto Full Screen", (uint32_t) false));
// RDB settings // RDB settings
AddUISetting(Rdb_Status, new CSettingTypeRomDatabase("Status", "Unknown")); AddUISetting(Rdb_Status, new CSettingTypeRomDatabase("Status", "Unknown"));
@ -38,7 +39,7 @@ void RegisterUISettings (void)
AddUISetting(UserInterface_InFullScreen, new CSettingTypeTempBool(false)); AddUISetting(UserInterface_InFullScreen, new CSettingTypeTempBool(false));
AddUISetting(UserInterface_MainWindowTop, new CSettingTypeApplication("Main Window", "Top", Default_None)); AddUISetting(UserInterface_MainWindowTop, new CSettingTypeApplication("Main Window", "Top", Default_None));
AddUISetting(UserInterface_MainWindowLeft, new CSettingTypeApplication("Main Window", "Left", Default_None)); AddUISetting(UserInterface_MainWindowLeft, new CSettingTypeApplication("Main Window", "Left", Default_None));
AddUISetting(UserInterface_AlwaysOnTop, new CSettingTypeApplication("Settings", "Always on top", (uint32_t)false)); AddUISetting(UserInterface_AlwaysOnTop, new CSettingTypeApplication("Settings", "Always on top", (uint32_t) false));
AddUISetting(UserInterface_ShowStatusBar, new CSettingTypeApplication("Settings", "Show Status Bar", true)); AddUISetting(UserInterface_ShowStatusBar, new CSettingTypeApplication("Settings", "Show Status Bar", true));
AddUISetting(UserInterface_ExitFullscreenOnLoseFocus, new CSettingTypeApplication("Settings", "Exit Full Screen On Lose Focus", false)); AddUISetting(UserInterface_ExitFullscreenOnLoseFocus, new CSettingTypeApplication("Settings", "Exit Full Screen On Lose Focus", false));
AddUISetting(UserInterface_ShowingNagWindow, new CSettingTypeTempBool(false)); AddUISetting(UserInterface_ShowingNagWindow, new CSettingTypeTempBool(false));
@ -77,7 +78,7 @@ void RegisterUISettings (void)
AddUISetting(DebuggerUI_ExceptionBPPos, new CSettingTypeApplication("Debugger UI", "Exception BP Pos", Default_None)); AddUISetting(DebuggerUI_ExceptionBPPos, new CSettingTypeApplication("Debugger UI", "Exception BP Pos", Default_None));
} }
float DPIScale(void) float DPIScale(void)
{ {
return CClientDC(0).GetDeviceCaps(LOGPIXELSX) / 96.0f; return CClientDC(0).GetDeviceCaps(LOGPIXELSX) / 96.0f;
} }
@ -124,7 +125,7 @@ bool UISettingsLoadBool(UISettingID Type)
bool UISettingsLoadBoolIndex(UISettingID Type, int32_t index) bool UISettingsLoadBoolIndex(UISettingID Type, int32_t index)
{ {
return g_Settings->LoadBoolIndex((SettingID)Type,index); return g_Settings->LoadBoolIndex((SettingID)Type, index);
} }
uint32_t UISettingsLoadDword(UISettingID Type) uint32_t UISettingsLoadDword(UISettingID Type)
@ -162,5 +163,5 @@ std::string UISettingsLoadStringVal(UISettingID Type)
bool UISettingsLoadStringVal(UISettingID Type, char * Buffer, int32_t BufferSize) bool UISettingsLoadStringVal(UISettingID Type, char * Buffer, int32_t BufferSize)
{ {
return g_Settings->LoadStringVal((SettingID)Type,Buffer,BufferSize); return g_Settings->LoadStringVal((SettingID)Type, Buffer, BufferSize);
} }

View File

@ -1,4 +1,5 @@
#include <stdafx.h> #include "stdafx.h"
#include <Project64\UserInterface\About.h> #include <Project64\UserInterface\About.h>
CAboutDlg::CAboutDlg(CProjectSupport & Support) : CAboutDlg::CAboutDlg(CProjectSupport & Support) :
@ -20,7 +21,7 @@ LRESULT CAboutDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPara
CDC hDC = GetDC(); CDC hDC = GetDC();
float DPIScale = hDC.GetDeviceCaps(LOGPIXELSX) / 96.0f; float DPIScale = hDC.GetDeviceCaps(LOGPIXELSX) / 96.0f;
LOGFONT lf = { 0 }; LOGFONT lf = {0};
CFontHandle(GetDlgItem(IDC_VERSION).GetFont()).GetLogFont(&lf); CFontHandle(GetDlgItem(IDC_VERSION).GetFont()).GetLogFont(&lf);
lf.lfHeight = (int)(16 * DPIScale); lf.lfHeight = (int)(16 * DPIScale);
m_TextFont.CreateFontIndirect(&lf); m_TextFont.CreateFontIndirect(&lf);
@ -38,7 +39,7 @@ LRESULT CAboutDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPara
return TRUE; return TRUE;
} }
void CAboutDlg::SetWindowDetais(int nIDDlgItem, int nAboveIDDlgItem, const wchar_t * Text, const HFONT &font) void CAboutDlg::SetWindowDetais(int nIDDlgItem, int nAboveIDDlgItem, const wchar_t * Text, const HFONT & font)
{ {
CWindow Wnd = GetDlgItem(nIDDlgItem); CWindow Wnd = GetDlgItem(nIDDlgItem);
Wnd.SetWindowText(Text); Wnd.SetWindowText(Text);
@ -55,7 +56,7 @@ void CAboutDlg::SetWindowDetais(int nIDDlgItem, int nAboveIDDlgItem, const wchar
{ {
Wnd.SetWindowPos(nullptr, 0, 0, rcWin.Width(), rcWin.Height(), SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER); Wnd.SetWindowPos(nullptr, 0, 0, rcWin.Width(), rcWin.Height(), SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER);
} }
CWindow AboveWnd = GetDlgItem(nAboveIDDlgItem); CWindow AboveWnd = GetDlgItem(nAboveIDDlgItem);
AboveWnd.GetWindowRect(&rcWin); AboveWnd.GetWindowRect(&rcWin);
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2); ::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2);
@ -66,8 +67,7 @@ void CAboutDlg::SetWindowDetais(int nIDDlgItem, int nAboveIDDlgItem, const wchar
Wnd.SetWindowPos(nullptr, rcWin.left, Top, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER); Wnd.SetWindowPos(nullptr, rcWin.left, Top, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
} }
LRESULT CAboutDlg::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
LRESULT CAboutDlg::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{ {
HDC hdcStatic = (HDC)wParam; HDC hdcStatic = (HDC)wParam;
SetTextColor(hdcStatic, RGB(0, 0, 0)); SetTextColor(hdcStatic, RGB(0, 0, 0));
@ -75,7 +75,7 @@ LRESULT CAboutDlg::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/
return (LONG)(LRESULT)((HBRUSH)GetStockObject(NULL_BRUSH)); return (LONG)(LRESULT)((HBRUSH)GetStockObject(NULL_BRUSH));
} }
LRESULT CAboutDlg::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CAboutDlg::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
static HPEN outline = CreatePen(PS_SOLID, 1, 0x00FFFFFF); static HPEN outline = CreatePen(PS_SOLID, 1, 0x00FFFFFF);
static HBRUSH fill = CreateSolidBrush(0x00FFFFFF); static HBRUSH fill = CreateSolidBrush(0x00FFFFFF);

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/N64System/Enhancement/Enhancements.h> #include <Project64-core/N64System/Enhancement/Enhancements.h>
CCheatsUI::CCheatsUI(void) : CCheatsUI::CCheatsUI(void) :
@ -36,7 +37,7 @@ void CCheatsUI::Display(HWND hParent, bool BlockExecution)
} }
} }
LRESULT CCheatsUI::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CCheatsUI::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
bool inBasicMode = g_Settings->LoadBool(UserInterface_BasicMode); bool inBasicMode = g_Settings->LoadBool(UserInterface_BasicMode);
m_StateBtn.Attach(GetDlgItem(IDC_STATE)); m_StateBtn.Attach(GetDlgItem(IDC_STATE));
@ -96,13 +97,13 @@ LRESULT CCheatsUI::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPara
return 0; return 0;
} }
LRESULT CCheatsUI::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CCheatsUI::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
m_StateBtn.Detach(); m_StateBtn.Detach();
return 0; return 0;
} }
LRESULT CCheatsUI::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CCheatsUI::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
if (m_EditCheat.ValuesChanged()) if (m_EditCheat.ValuesChanged())
{ {
@ -124,7 +125,7 @@ LRESULT CCheatsUI::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl
return 0; return 0;
} }
LRESULT CCheatsUI::OnStateChange(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CCheatsUI::OnStateChange(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
WINDOWPLACEMENT WndPlac; WINDOWPLACEMENT WndPlac;
WndPlac.length = sizeof(WndPlac); WndPlac.length = sizeof(WndPlac);
@ -169,7 +170,7 @@ CCheatList::~CCheatList()
{ {
} }
LRESULT CCheatList::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CCheatList::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
GetDlgItem(IDC_NOTESFRAME).SetWindowText(wGS(CHEAT_NOTES_FRAME).c_str()); GetDlgItem(IDC_NOTESFRAME).SetWindowText(wGS(CHEAT_NOTES_FRAME).c_str());
GetDlgItem(IDC_UNMARK).SetWindowText(wGS(CHEAT_MARK_NONE).c_str()); GetDlgItem(IDC_UNMARK).SetWindowText(wGS(CHEAT_MARK_NONE).c_str());
@ -180,8 +181,8 @@ LRESULT CCheatList::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPar
CRect hCheatTreeRect(6, 4, rcList.right - rcList.left - 13, rcButton.top - rcList.top - 8); CRect hCheatTreeRect(6, 4, rcList.right - rcList.left - 13, rcButton.top - rcList.top - 8);
m_hCheatTree.Create(m_hWnd, &hCheatTreeRect, L"", m_hCheatTree.Create(m_hWnd, &hCheatTreeRect, L"",
WS_CHILD | WS_VISIBLE | WS_VSCROLL | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_DISABLEDRAGDROP | WS_TABSTOP | TVS_FULLROWSELECT, WS_CHILD | WS_VISIBLE | WS_VSCROLL | TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT | TVS_DISABLEDRAGDROP | WS_TABSTOP | TVS_FULLROWSELECT,
WS_EX_CLIENTEDGE, (HMENU)IDC_MYTREE); WS_EX_CLIENTEDGE, (HMENU)IDC_MYTREE);
m_hCheatTree.SetWindowLong(GWL_STYLE, TVS_CHECKBOXES | TVS_SHOWSELALWAYS | m_hCheatTree.GetWindowLong(GWL_STYLE)); m_hCheatTree.SetWindowLong(GWL_STYLE, TVS_CHECKBOXES | TVS_SHOWSELALWAYS | m_hCheatTree.GetWindowLong(GWL_STYLE));
CImageList hImageList; CImageList hImageList;
@ -193,17 +194,17 @@ LRESULT CCheatList::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPar
return true; return true;
} }
LRESULT CCheatList::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CCheatList::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
m_hCheatTree.Detach(); m_hCheatTree.Detach();
return 0; return 0;
} }
LRESULT CCheatList::OnChangeCodeExtension(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/) LRESULT CCheatList::OnChangeCodeExtension(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL & /*bHandled*/)
{ {
m_hSelectedItem = (HTREEITEM)lParam; m_hSelectedItem = (HTREEITEM)lParam;
TVITEM item = { 0 }; TVITEM item = {0};
item.mask = TVIF_PARAM; item.mask = TVIF_PARAM;
item.hItem = m_hSelectedItem; item.hItem = m_hSelectedItem;
if (!m_hCheatTree.GetItem(&item) || item.lParam == NULL) if (!m_hCheatTree.GetItem(&item) || item.lParam == NULL)
@ -232,7 +233,7 @@ LRESULT CCheatList::OnChangeCodeExtension(UINT /*uMsg*/, WPARAM /*wParam*/, LPAR
return 0; return 0;
} }
LRESULT CCheatList::OnPopupDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CCheatList::OnPopupDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
int Response = MessageBox(wGS(MSG_DEL_SURE).c_str(), wGS(MSG_DEL_TITLE).c_str(), MB_YESNO | MB_ICONQUESTION); int Response = MessageBox(wGS(MSG_DEL_SURE).c_str(), wGS(MSG_DEL_TITLE).c_str(), MB_YESNO | MB_ICONQUESTION);
if (Response != IDYES) if (Response != IDYES)
@ -240,7 +241,7 @@ LRESULT CCheatList::OnPopupDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWn
return 0; return 0;
} }
TVITEM item = { 0 }; TVITEM item = {0};
item.hItem = m_hSelectedItem; item.hItem = m_hSelectedItem;
item.mask = TVIF_PARAM; item.mask = TVIF_PARAM;
m_hCheatTree.GetItem(&item); m_hCheatTree.GetItem(&item);
@ -251,7 +252,7 @@ LRESULT CCheatList::OnPopupDelete(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWn
return 0; return 0;
} }
LRESULT CCheatList::OnUnmark(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CCheatList::OnUnmark(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
ChangeChildrenStatus(TVI_ROOT, false); ChangeChildrenStatus(TVI_ROOT, false);
if (g_Enhancements != nullptr) if (g_Enhancements != nullptr)
@ -261,10 +262,10 @@ LRESULT CCheatList::OnUnmark(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*
return 0; return 0;
} }
LRESULT CCheatList::OnTreeClicked(NMHDR* lpnmh) LRESULT CCheatList::OnTreeClicked(NMHDR * lpnmh)
{ {
uint32_t dwpos = GetMessagePos(); uint32_t dwpos = GetMessagePos();
TVHITTESTINFO ht = { 0 }; TVHITTESTINFO ht = {0};
ht.pt.x = GET_X_LPARAM(dwpos); ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos); ht.pt.y = GET_Y_LPARAM(dwpos);
::MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1); ::MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
@ -279,10 +280,10 @@ LRESULT CCheatList::OnTreeClicked(NMHDR* lpnmh)
case TV_STATE_INDETERMINATE: case TV_STATE_INDETERMINATE:
if (m_hCheatTree.GetChildItem(ht.hItem) == nullptr) if (m_hCheatTree.GetChildItem(ht.hItem) == nullptr)
{ {
TVITEM item = { 0 }; TVITEM item = {0};
item.mask = TVIF_PARAM; item.mask = TVIF_PARAM;
item.hItem = ht.hItem; item.hItem = ht.hItem;
m_hCheatTree.GetItem(&item); m_hCheatTree.GetItem(&item);
if (item.lParam != NULL) if (item.lParam != NULL)
{ {
CEnhancement * Enhancement = (CEnhancement *)item.lParam; CEnhancement * Enhancement = (CEnhancement *)item.lParam;
@ -310,7 +311,7 @@ LRESULT CCheatList::OnTreeClicked(NMHDR* lpnmh)
case TV_STATE_CLEAR: TV_SetCheckState(ht.hItem, TV_STATE_CHECKED); break; case TV_STATE_CLEAR: TV_SetCheckState(ht.hItem, TV_STATE_CHECKED); break;
case TV_STATE_INDETERMINATE: TV_SetCheckState(ht.hItem, TV_STATE_CLEAR); break; case TV_STATE_INDETERMINATE: TV_SetCheckState(ht.hItem, TV_STATE_CLEAR); break;
} }
if (g_Enhancements != nullptr) if (g_Enhancements != nullptr)
{ {
g_Enhancements->UpdateCheats(); g_Enhancements->UpdateCheats();
@ -319,12 +320,12 @@ LRESULT CCheatList::OnTreeClicked(NMHDR* lpnmh)
return 0; return 0;
} }
LRESULT CCheatList::OnTreeRClicked(NMHDR* lpnmh) LRESULT CCheatList::OnTreeRClicked(NMHDR * lpnmh)
{ {
if (g_Settings->LoadBool(UserInterface_BasicMode)) { return true; } if (g_Settings->LoadBool(UserInterface_BasicMode)) { return true; }
// Work out what item is selected // Work out what item is selected
TVHITTESTINFO ht = { 0 }; TVHITTESTINFO ht = {0};
uint32_t dwpos = GetMessagePos(); uint32_t dwpos = GetMessagePos();
// Include <windowsx.h> and <windows.h> header files // Include <windowsx.h> and <windows.h> header files
@ -354,10 +355,10 @@ LRESULT CCheatList::OnTreeRClicked(NMHDR* lpnmh)
return true; return true;
} }
LRESULT CCheatList::OnTreeDClicked(NMHDR* lpnmh) LRESULT CCheatList::OnTreeDClicked(NMHDR * lpnmh)
{ {
uint32_t dwpos = GetMessagePos(); uint32_t dwpos = GetMessagePos();
TVHITTESTINFO ht = { 0 }; TVHITTESTINFO ht = {0};
ht.pt.x = GET_X_LPARAM(dwpos); ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos); ht.pt.y = GET_Y_LPARAM(dwpos);
::MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1); ::MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
@ -377,7 +378,7 @@ LRESULT CCheatList::OnTreeSelChanged(NMHDR * /*lpnmh*/)
GetDlgItem(IDC_NOTES).SetWindowText(L""); GetDlgItem(IDC_NOTES).SetWindowText(L"");
if (m_hCheatTree.GetChildItem(hItem) == nullptr) if (m_hCheatTree.GetChildItem(hItem) == nullptr)
{ {
TVITEM item = { 0 }; TVITEM item = {0};
item.mask = TVIF_PARAM; item.mask = TVIF_PARAM;
item.hItem = hItem; item.hItem = hItem;
m_hCheatTree.GetItem(&item); m_hCheatTree.GetItem(&item);
@ -405,15 +406,15 @@ void CCheatList::RefreshItems()
for (CEnhancementList::iterator itr = m_Cheats.begin(); itr != m_Cheats.end(); itr++) for (CEnhancementList::iterator itr = m_Cheats.begin(); itr != m_Cheats.end(); itr++)
{ {
std::string Name = itr->second.GetNameAndExtension(); std::string Name = itr->second.GetNameAndExtension();
if (Name.length() == 0) if (Name.length() == 0)
{ {
continue; continue;
} }
AddCodeLayers((LPARAM)&itr->second, stdstr(Name).ToUTF16(), TVI_ROOT, itr->second.Active()); AddCodeLayers((LPARAM)&itr->second, stdstr(Name).ToUTF16(), TVI_ROOT, itr->second.Active());
} }
} }
void CCheatList::AddCodeLayers(LPARAM Enhancement, const std::wstring &Name, HTREEITEM hParent, bool CheatActive) void CCheatList::AddCodeLayers(LPARAM Enhancement, const std::wstring & Name, HTREEITEM hParent, bool CheatActive)
{ {
TV_INSERTSTRUCT tv; TV_INSERTSTRUCT tv;
@ -551,7 +552,7 @@ void CCheatList::DeleteCheat(LPARAM Enhancement)
CCheatList::TV_CHECK_STATE CCheatList::TV_GetCheckState(HTREEITEM hItem) CCheatList::TV_CHECK_STATE CCheatList::TV_GetCheckState(HTREEITEM hItem)
{ {
TVITEM tvItem = { 0 }; TVITEM tvItem = {0};
tvItem.mask = TVIF_HANDLE | TVIF_STATE; tvItem.mask = TVIF_HANDLE | TVIF_STATE;
tvItem.hItem = hItem; tvItem.hItem = hItem;
tvItem.stateMask = TVIS_STATEIMAGEMASK; tvItem.stateMask = TVIS_STATEIMAGEMASK;
@ -569,7 +570,7 @@ CCheatList::TV_CHECK_STATE CCheatList::TV_GetCheckState(HTREEITEM hItem)
bool CCheatList::TV_SetCheckState(HTREEITEM hItem, TV_CHECK_STATE state) bool CCheatList::TV_SetCheckState(HTREEITEM hItem, TV_CHECK_STATE state)
{ {
TVITEM tvItem = { 0 }; TVITEM tvItem = {0};
tvItem.mask = TVIF_HANDLE | TVIF_STATE; tvItem.mask = TVIF_HANDLE | TVIF_STATE;
tvItem.hItem = (HTREEITEM)hItem; tvItem.hItem = (HTREEITEM)hItem;
tvItem.stateMask = TVIS_STATEIMAGEMASK; tvItem.stateMask = TVIS_STATEIMAGEMASK;
@ -591,7 +592,7 @@ void CCheatList::MenuSetText(HMENU hMenu, int MenuPos, const wchar_t * Title, co
return; return;
} }
MENUITEMINFO MenuInfo = { 0 }; MENUITEMINFO MenuInfo = {0};
wchar_t String[256]; wchar_t String[256];
MenuInfo.cbSize = sizeof(MENUITEMINFO); MenuInfo.cbSize = sizeof(MENUITEMINFO);
MenuInfo.fMask = MIIM_TYPE; MenuInfo.fMask = MIIM_TYPE;
@ -618,7 +619,7 @@ CEditCheat::~CEditCheat()
{ {
} }
LRESULT CEditCheat::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CEditCheat::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
GetDlgItem(IDC_NAME).SetWindowText(wGS(CHEAT_ADDCHEAT_NAME).c_str()); GetDlgItem(IDC_NAME).SetWindowText(wGS(CHEAT_ADDCHEAT_NAME).c_str());
GetDlgItem(IDC_CODE).SetWindowText(wGS(CHEAT_ADDCHEAT_CODE).c_str()); GetDlgItem(IDC_CODE).SetWindowText(wGS(CHEAT_ADDCHEAT_CODE).c_str());
@ -632,7 +633,7 @@ LRESULT CEditCheat::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPar
return 0; return 0;
} }
LRESULT CEditCheat::OnEditCheat(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CEditCheat::OnEditCheat(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
if (ValuesChanged()) if (ValuesChanged())
{ {
@ -679,7 +680,7 @@ LRESULT CEditCheat::OnEditCheat(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/,
return 0; return 0;
} }
LRESULT CEditCheat::OnAddCheat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CEditCheat::OnAddCheat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
std::string NewCheatName = GetCWindowText(GetDlgItem(IDC_CODE_NAME)); std::string NewCheatName = GetCWindowText(GetDlgItem(IDC_CODE_NAME));
for (CEnhancementList::const_iterator itr = m_Cheats.begin(); itr != m_Cheats.end(); itr++) for (CEnhancementList::const_iterator itr = m_Cheats.begin(); itr != m_Cheats.end(); itr++)
@ -722,7 +723,7 @@ LRESULT CEditCheat::OnAddCheat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCt
return 0; return 0;
} }
LRESULT CEditCheat::OnNewCheat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CEditCheat::OnNewCheat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
if (ValuesChanged()) if (ValuesChanged())
{ {
@ -740,19 +741,19 @@ LRESULT CEditCheat::OnNewCheat(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCt
return 0; return 0;
} }
LRESULT CEditCheat::OnCodeNameChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CEditCheat::OnCodeNameChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
DetailsChanged(); DetailsChanged();
return 0; return 0;
} }
LRESULT CEditCheat::OnCheatCodeChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CEditCheat::OnCheatCodeChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
DetailsChanged(); DetailsChanged();
return 0; return 0;
} }
LRESULT CEditCheat::OnCheatOptionsChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CEditCheat::OnCheatOptionsChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
DetailsChanged(); DetailsChanged();
return 0; return 0;
@ -902,7 +903,7 @@ CEnhancementCodeEx::CEnhancementCodeEx(CEnhancement * Enhancement) :
{ {
} }
LRESULT CEnhancementCodeEx::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CEnhancementCodeEx::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
SetWindowText(wGS(CHEAT_CODE_EXT_TITLE).c_str()); SetWindowText(wGS(CHEAT_CODE_EXT_TITLE).c_str());
GetDlgItem(IDC_NOTE).SetWindowText(wGS(CHEAT_CODE_EXT_TXT).c_str()); GetDlgItem(IDC_NOTE).SetWindowText(wGS(CHEAT_CODE_EXT_TXT).c_str());
@ -910,7 +911,7 @@ LRESULT CEnhancementCodeEx::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARA
GetDlgItem(IDCANCEL).SetWindowText(wGS(CHEAT_CANCEL).c_str()); GetDlgItem(IDCANCEL).SetWindowText(wGS(CHEAT_CANCEL).c_str());
GetDlgItem(IDC_CHEAT_NAME).SetWindowText(stdstr(m_Enhancement->GetName()).ToUTF16().c_str()); GetDlgItem(IDC_CHEAT_NAME).SetWindowText(stdstr(m_Enhancement->GetName()).ToUTF16().c_str());
CListBox CheatList = GetDlgItem(IDC_CHEAT_LIST); CListBox CheatList = GetDlgItem(IDC_CHEAT_LIST);
CEnhancement::CodeOptions Options = m_Enhancement->GetOptions(); CEnhancement::CodeOptions Options = m_Enhancement->GetOptions();
bool OptionSelected = m_Enhancement->OptionSelected(); bool OptionSelected = m_Enhancement->OptionSelected();
@ -931,13 +932,13 @@ LRESULT CEnhancementCodeEx::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARA
return 0; return 0;
} }
LRESULT CEnhancementCodeEx::OnListDblClick(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CEnhancementCodeEx::OnListDblClick(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
PostMessage(WM_COMMAND, IDOK, 0); PostMessage(WM_COMMAND, IDOK, 0);
return 0; return 0;
} }
LRESULT CEnhancementCodeEx::OnOkCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CEnhancementCodeEx::OnOkCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
CListBox CheatList = GetDlgItem(IDC_CHEAT_LIST); CListBox CheatList = GetDlgItem(IDC_CHEAT_LIST);
int index = CheatList.GetCurSel(); int index = CheatList.GetCurSel();
@ -955,7 +956,7 @@ LRESULT CEnhancementCodeEx::OnOkCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*h
return 0; return 0;
} }
LRESULT CEnhancementCodeEx::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CEnhancementCodeEx::OnCloseCmd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
EndDialog(0); EndDialog(0);
return 0; return 0;

View File

@ -1,39 +1,39 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "stdafx.h" #include "stdafx.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Assembler.h" #include "Assembler.h"
#include "Project64-core/N64System/Mips/R4300iOpcode.h" #include "Project64-core/N64System/Mips/R4300iOpcode.h"
ASM_PARSE_ERROR CAssembler::m_ParseError = ERR_NONE; ASM_PARSE_ERROR CAssembler::m_ParseError = ERR_NONE;
uint32_t CAssembler::m_Address = 0; uint32_t CAssembler::m_Address = 0;
char* CAssembler::m_TokContext = nullptr; char * CAssembler::m_TokContext = nullptr;
const ASM_SYNTAX_FN CAssembler::syn_jump[] = { arg_jump, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_jump[] = {arg_jump, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_loadstore[] = { arg_reg_t, arg_imm16, arg_reg_s, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_loadstore[] = {arg_reg_t, arg_imm16, arg_reg_s, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_arith[] = { arg_reg_d, arg_reg_s, arg_reg_t, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_arith[] = {arg_reg_d, arg_reg_s, arg_reg_t, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_arith2[] = { arg_reg_s, arg_reg_t, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_arith2[] = {arg_reg_s, arg_reg_t, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_shiftv[] = { arg_reg_d, arg_reg_t, arg_reg_s, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_shiftv[] = {arg_reg_d, arg_reg_t, arg_reg_s, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_arith_i[] = { arg_reg_t, arg_reg_s, arg_imm16, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_arith_i[] = {arg_reg_t, arg_reg_s, arg_imm16, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_load_i[] = { arg_reg_t, arg_imm16, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_load_i[] = {arg_reg_t, arg_imm16, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_branch_z[] = { arg_reg_s, arg_bra_target, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_branch_z[] = {arg_reg_s, arg_bra_target, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_branch[] = { arg_reg_s, arg_reg_t, arg_bra_target, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_branch[] = {arg_reg_s, arg_reg_t, arg_bra_target, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_branch_unc[] = { arg_bra_target, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_branch_unc[] = {arg_bra_target, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_trap_i[] = { arg_reg_s, arg_imm16, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_trap_i[] = {arg_reg_s, arg_imm16, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_shift[] = { arg_reg_d, arg_reg_t, arg_shamt, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_shift[] = {arg_reg_d, arg_reg_t, arg_shamt, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_mf[] = { arg_reg_d, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_mf[] = {arg_reg_d, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_jr[] = { arg_reg_s, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_jr[] = {arg_reg_s, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_jalr[] = { arg_reg_d, arg_reg_s, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_jalr[] = {arg_reg_d, arg_reg_s, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_cop1_arith[] = { arg_reg_fd, arg_reg_fs, arg_reg_ft, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_cop1_arith[] = {arg_reg_fd, arg_reg_fs, arg_reg_ft, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_cop1[] = { arg_reg_fd, arg_reg_fs, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_cop1[] = {arg_reg_fd, arg_reg_fs, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_cop1_cmp[] = { arg_reg_fs, arg_reg_ft, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_cop1_cmp[] = {arg_reg_fs, arg_reg_ft, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_cop_mv[] = { arg_reg_t, arg_reg_d, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_cop_mv[] = {arg_reg_t, arg_reg_d, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_cache[] = { arg_cache_op, arg_imm16, arg_reg_s, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_cache[] = {arg_cache_op, arg_imm16, arg_reg_s, nullptr};
const ASM_SYNTAX_FN CAssembler::syn_syscall[] = { arg_syscall_code, nullptr }; const ASM_SYNTAX_FN CAssembler::syn_syscall[] = {arg_syscall_code, nullptr};
const ASM_INSTRUCTION CAssembler::m_Instructions[] = const ASM_INSTRUCTION CAssembler::m_Instructions[] =
{ {
@ -293,7 +293,7 @@ const ASM_REGISTER CAssembler::m_Registers[] =
{ nullptr } { nullptr }
}; };
bool CAssembler::AssembleLine(const char* line, uint32_t* opcode, uint32_t address) bool CAssembler::AssembleLine(const char * line, uint32_t * opcode, uint32_t address)
{ {
m_ParseError = ERR_NONE; m_ParseError = ERR_NONE;
m_Address = address; m_Address = address;
@ -308,21 +308,21 @@ bool CAssembler::AssembleLine(const char* line, uint32_t* opcode, uint32_t addre
return true; return true;
} }
char* name = strtok_s(line_c, " \t", &m_TokContext); char * name = strtok_s(line_c, " \t", &m_TokContext);
// Attempt to assemble the line // Attempt to assemble the line
// If a syntax error occurs, check if the command has alternative syntax forms and retry // If a syntax error occurs, check if the command has alternative syntax forms and retry
for(int nFallback = 0;; nFallback++) for (int nFallback = 0;; nFallback++)
{ {
const ASM_INSTRUCTION* instruction = LookupInstruction(name, nFallback); const ASM_INSTRUCTION * instruction = LookupInstruction(name, nFallback);
if (instruction == nullptr) if (instruction == nullptr)
{ {
m_ParseError = ERR_UNKNOWN_CMD; m_ParseError = ERR_UNKNOWN_CMD;
return false; return false;
} }
m_ParseError = ERR_NONE; m_ParseError = ERR_NONE;
if (nFallback > 0) if (nFallback > 0)
@ -358,7 +358,7 @@ bool CAssembler::AssembleLine(const char* line, uint32_t* opcode, uint32_t addre
} }
} }
const ASM_INSTRUCTION* CAssembler::LookupInstruction(char* name, int nFallback) const ASM_INSTRUCTION * CAssembler::LookupInstruction(char * name, int nFallback)
{ {
for (int i = 0; m_Instructions[i].name != nullptr; i++) for (int i = 0; m_Instructions[i].name != nullptr; i++)
{ {
@ -375,7 +375,7 @@ const ASM_INSTRUCTION* CAssembler::LookupInstruction(char* name, int nFallback)
return nullptr; return nullptr;
} }
const ASM_REGISTER* CAssembler::LookupRegister(char* name) const ASM_REGISTER * CAssembler::LookupRegister(char * name)
{ {
for (int i = 0; m_Registers[i].name != nullptr; i++) for (int i = 0; m_Registers[i].name != nullptr; i++)
{ {
@ -387,7 +387,7 @@ const ASM_REGISTER* CAssembler::LookupRegister(char* name)
return nullptr; return nullptr;
} }
void CAssembler::StrToLower(char* str) void CAssembler::StrToLower(char * str)
{ {
while (*str) while (*str)
{ {
@ -401,7 +401,7 @@ void CAssembler::StrToLower(char* str)
uint32_t CAssembler::pop_reg() uint32_t CAssembler::pop_reg()
{ {
char* r = strtok_s(nullptr, " \t,()", &m_TokContext); char * r = strtok_s(nullptr, " \t,()", &m_TokContext);
if (r == nullptr) if (r == nullptr)
{ {
@ -409,7 +409,7 @@ uint32_t CAssembler::pop_reg()
return 0; return 0;
} }
const ASM_REGISTER* reg = LookupRegister(r); const ASM_REGISTER * reg = LookupRegister(r);
if (reg == nullptr) if (reg == nullptr)
{ {
@ -422,7 +422,7 @@ uint32_t CAssembler::pop_reg()
uint32_t CAssembler::pop_val() uint32_t CAssembler::pop_val()
{ {
char* v = strtok_s(nullptr, " \t,()", &m_TokContext); char * v = strtok_s(nullptr, " \t,()", &m_TokContext);
if (v == nullptr) if (v == nullptr)
{ {
@ -444,7 +444,7 @@ uint32_t CAssembler::pop_val()
v++; v++;
} }
char* endptr; char * endptr;
uint32_t val = strtoul(v, &endptr, base); uint32_t val = strtoul(v, &endptr, base);
@ -517,63 +517,63 @@ uint32_t CAssembler::base_cop1_bc(uint32_t val)
return (R4300i_CP1 << 26) | (R4300i_COP1_BC << 21) | (val << 16); return (R4300i_CP1 << 26) | (R4300i_COP1_BC << 21) | (val << 16);
} }
void CAssembler::arg_reg_t(uint32_t* opcode) void CAssembler::arg_reg_t(uint32_t * opcode)
{ {
*opcode |= pop_reg() << 16; *opcode |= pop_reg() << 16;
} }
void CAssembler::arg_reg_s(uint32_t* opcode) void CAssembler::arg_reg_s(uint32_t * opcode)
{ {
*opcode |= pop_reg() << 21; *opcode |= pop_reg() << 21;
} }
void CAssembler::arg_reg_d(uint32_t* opcode) void CAssembler::arg_reg_d(uint32_t * opcode)
{ {
*opcode |= pop_reg() << 11; *opcode |= pop_reg() << 11;
} }
void CAssembler::arg_reg_ft(uint32_t* opcode) void CAssembler::arg_reg_ft(uint32_t * opcode)
{ {
*opcode |= pop_reg() << 16; *opcode |= pop_reg() << 16;
} }
void CAssembler::arg_reg_fs(uint32_t* opcode) void CAssembler::arg_reg_fs(uint32_t * opcode)
{ {
*opcode |= pop_reg() << 11; *opcode |= pop_reg() << 11;
} }
void CAssembler::arg_reg_fd(uint32_t* opcode) void CAssembler::arg_reg_fd(uint32_t * opcode)
{ {
*opcode |= pop_reg() << 6; *opcode |= pop_reg() << 6;
} }
void CAssembler::arg_jump(uint32_t* opcode) void CAssembler::arg_jump(uint32_t * opcode)
{ {
*opcode |= (pop_val() / 4) & 0x3FFFFFF; *opcode |= (pop_val() / 4) & 0x3FFFFFF;
} }
void CAssembler::arg_imm16(uint32_t* opcode) void CAssembler::arg_imm16(uint32_t * opcode)
{ {
*opcode |= (pop_val() & 0xFFFF); *opcode |= (pop_val() & 0xFFFF);
} }
void CAssembler::arg_bra_target(uint32_t* opcode) void CAssembler::arg_bra_target(uint32_t * opcode)
{ {
uint16_t relTarget = (((pop_val() - m_Address) / 4) & 0xFFFF) - 1; uint16_t relTarget = (((pop_val() - m_Address) / 4) & 0xFFFF) - 1;
*opcode |= relTarget; *opcode |= relTarget;
} }
void CAssembler::arg_shamt(uint32_t* opcode) void CAssembler::arg_shamt(uint32_t * opcode)
{ {
*opcode |= (pop_val() & 0x1F) << 6; *opcode |= (pop_val() & 0x1F) << 6;
} }
void CAssembler::arg_cache_op(uint32_t* opcode) void CAssembler::arg_cache_op(uint32_t * opcode)
{ {
*opcode |= (pop_val() & 0x1F) << 16; *opcode |= (pop_val() & 0x1F) << 16;
} }
void CAssembler::arg_syscall_code(uint32_t* opcode) void CAssembler::arg_syscall_code(uint32_t * opcode)
{ {
*opcode |= (pop_val() & 0xFFFFF) << 6; *opcode |= (pop_val() & 0xFFFFF) << 6;
} }

View File

@ -1,10 +1,10 @@
#include "stdafx.h" #include "stdafx.h"
#include "Breakpoints.h"
#include <Project64-core/N64System/Mips/Register.h> #include "Breakpoints.h"
#include <Project64-core/N64System/SystemGlobals.h>
#include <Project64-core/N64System/Mips/R4300iInstruction.h> #include <Project64-core/N64System/Mips/R4300iInstruction.h>
#include <Project64-core/N64System/Mips/Register.h>
#include <Project64-core/N64System/N64System.h> #include <Project64-core/N64System/N64System.h>
#include <Project64-core/N64System/SystemGlobals.h>
CBreakpoints::CBreakpoints() : CBreakpoints::CBreakpoints() :
m_bHaveRegBP(false), m_bHaveRegBP(false),
@ -259,7 +259,7 @@ CBreakpoints::BPSTATE CBreakpoints::WriteBPExists64(uint32_t address)
CBreakpoints::BPSTATE CBreakpoints::WriteBPExistsInChunk(uint32_t address, uint32_t nBytes) CBreakpoints::BPSTATE CBreakpoints::WriteBPExistsInChunk(uint32_t address, uint32_t nBytes)
{ {
uint32_t endAddr = address + nBytes; uint32_t endAddr = address + nBytes;
for (breakpoints_t::iterator breakpoint = m_WriteMem.begin(); breakpoint != m_WriteMem.end(); breakpoint++) for (breakpoints_t::iterator breakpoint = m_WriteMem.begin(); breakpoint != m_WriteMem.end(); breakpoint++)
{ {
uint32_t wbpAddr = breakpoint->first; uint32_t wbpAddr = breakpoint->first;

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "CPULog.h" #include "CPULog.h"
#include <Project64-core/N64System/Mips/R4300iInstruction.h> #include <Project64-core/N64System/Mips/R4300iInstruction.h>
@ -24,7 +25,7 @@ CCPULog::CCPULog(size_t size) :
m_Array = nullptr; m_Array = nullptr;
return; return;
} }
m_Array = new CPUState[m_Size]; m_Array = new CPUState[m_Size];
} }
@ -50,7 +51,7 @@ void CCPULog::PushState()
m_bMaxed = true; m_bMaxed = true;
} }
CPUState* state = &m_Array[m_Index++]; CPUState * state = &m_Array[m_Index++];
state->pc = g_Reg->m_PROGRAM_COUNTER; state->pc = g_Reg->m_PROGRAM_COUNTER;
state->opcode = R4300iOp::m_Opcode; state->opcode = R4300iOp::m_Opcode;
@ -81,7 +82,7 @@ size_t CCPULog::GetSize(void)
return m_Size; return m_Size;
} }
CPUState* CCPULog::GetEntry(size_t index) CPUState * CCPULog::GetEntry(size_t index)
{ {
if (m_Array == nullptr) if (m_Array == nullptr)
{ {
@ -108,7 +109,7 @@ CPUState* CCPULog::GetEntry(size_t index)
void CCPULog::Reset() void CCPULog::Reset()
{ {
size_t newSize; size_t newSize;
if (!g_Settings->LoadBool(Debugger_CPULoggingEnabled)) if (!g_Settings->LoadBool(Debugger_CPULoggingEnabled))
{ {
newSize = 0; newSize = 0;
@ -130,7 +131,7 @@ void CCPULog::Reset()
delete[] m_Array; delete[] m_Array;
m_Array = nullptr; m_Array = nullptr;
} }
if (m_Size != 0) if (m_Size != 0)
{ {
m_Array = new CPUState[m_Size]; m_Array = new CPUState[m_Size];
@ -138,23 +139,23 @@ void CCPULog::Reset()
} }
} }
CCPULog* CCPULog::Clone(void) CCPULog * CCPULog::Clone(void)
{ {
if (m_Array == nullptr) if (m_Array == nullptr)
{ {
return nullptr; return nullptr;
} }
CCPULog *clone = new CCPULog(m_Size); CCPULog * clone = new CCPULog(m_Size);
clone->m_bMaxed = m_bMaxed; clone->m_bMaxed = m_bMaxed;
clone->m_Index = m_Index; clone->m_Index = m_Index;
memcpy(clone->m_Array, m_Array, sizeof(CPUState) * m_Size); memcpy(clone->m_Array, m_Array, sizeof(CPUState) * m_Size);
return clone; return clone;
} }
void CCPULog::DumpToFile(const char* path) void CCPULog::DumpToFile(const char * path)
{ {
FILE* fp = fopen(path, "wb"); FILE * fp = fopen(path, "wb");
if (fp == nullptr) if (fp == nullptr)
{ {
@ -165,7 +166,7 @@ void CCPULog::DumpToFile(const char* path)
for (size_t i = 0; i < count; i++) for (size_t i = 0; i < count; i++)
{ {
CPUState* state = GetEntry(i); CPUState * state = GetEntry(i);
R4300iInstruction Instruction(state->pc, state->opcode.Value); R4300iInstruction Instruction(state->pc, state->opcode.Value);
fprintf(fp, "%08X: %08X %s %s\n", state->pc, state->opcode.Value, Instruction.Name(), Instruction.Param()); fprintf(fp, "%08X: %08X %s %s\n", state->pc, state->opcode.Value, Instruction.Name(), Instruction.Param());
} }

View File

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdafx.h>
typedef struct typedef struct
{ {
uint32_t pc; uint32_t pc;

View File

@ -1,9 +1,10 @@
#include "stdafx.h" #include "stdafx.h"
#include "DMALog.h" #include "DMALog.h"
void CDMALog::AddEntry(uint32_t romAddr, uint32_t ramAddr, uint32_t length) void CDMALog::AddEntry(uint32_t romAddr, uint32_t ramAddr, uint32_t length)
{ {
DMALOGENTRY entry = { romAddr, ramAddr, length }; DMALOGENTRY entry = {romAddr, ramAddr, length};
m_Log.push_back(entry); m_Log.push_back(entry);
} }
@ -17,7 +18,7 @@ size_t CDMALog::GetNumEntries()
return m_Log.size(); return m_Log.size();
} }
DMALOGENTRY* CDMALog::GetEntryByIndex(uint32_t index) DMALOGENTRY * CDMALog::GetEntryByIndex(uint32_t index)
{ {
if (index < m_Log.size()) if (index < m_Log.size())
{ {
@ -26,7 +27,7 @@ DMALOGENTRY* CDMALog::GetEntryByIndex(uint32_t index)
return nullptr; return nullptr;
} }
DMALOGENTRY* CDMALog::GetEntryByRamAddress(uint32_t ramAddr) DMALOGENTRY * CDMALog::GetEntryByRamAddress(uint32_t ramAddr)
{ {
uint32_t nEntries = GetNumEntries(); uint32_t nEntries = GetNumEntries();
@ -48,9 +49,9 @@ DMALOGENTRY* CDMALog::GetEntryByRamAddress(uint32_t ramAddr)
return nullptr; return nullptr;
} }
DMALOGENTRY* CDMALog::GetEntryByRamAddress(uint32_t ramAddr, uint32_t* lpRomAddr, uint32_t* lpOffset) DMALOGENTRY * CDMALog::GetEntryByRamAddress(uint32_t ramAddr, uint32_t * lpRomAddr, uint32_t * lpOffset)
{ {
DMALOGENTRY* lpEntry = GetEntryByRamAddress(ramAddr); DMALOGENTRY * lpEntry = GetEntryByRamAddress(ramAddr);
if (lpEntry == nullptr) if (lpEntry == nullptr)
{ {
@ -63,7 +64,7 @@ DMALOGENTRY* CDMALog::GetEntryByRamAddress(uint32_t ramAddr, uint32_t* lpRomAddr
return lpEntry; return lpEntry;
} }
DMALOGENTRY* CDMALog::GetEntryByRomAddress(uint32_t romAddr) DMALOGENTRY * CDMALog::GetEntryByRomAddress(uint32_t romAddr)
{ {
uint32_t nEntries = GetNumEntries(); uint32_t nEntries = GetNumEntries();
@ -72,7 +73,7 @@ DMALOGENTRY* CDMALog::GetEntryByRomAddress(uint32_t romAddr)
return nullptr; return nullptr;
} }
for (uint32_t i = nEntries - 1; i-- > 0; ) for (uint32_t i = nEntries - 1; i-- > 0;)
{ {
uint32_t min = m_Log[i].romAddr; uint32_t min = m_Log[i].romAddr;
uint32_t max = min + m_Log[i].length - 1; uint32_t max = min + m_Log[i].length - 1;
@ -85,9 +86,9 @@ DMALOGENTRY* CDMALog::GetEntryByRomAddress(uint32_t romAddr)
return nullptr; return nullptr;
} }
DMALOGENTRY* CDMALog::GetEntryByRomAddress(uint32_t romAddr, uint32_t* lpRamAddr, uint32_t* lpOffset) DMALOGENTRY * CDMALog::GetEntryByRomAddress(uint32_t romAddr, uint32_t * lpRamAddr, uint32_t * lpOffset)
{ {
DMALOGENTRY* lpEntry = GetEntryByRomAddress(romAddr); DMALOGENTRY * lpEntry = GetEntryByRomAddress(romAddr);
if (lpEntry == nullptr) if (lpEntry == nullptr)
{ {

View File

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdafx.h>
struct DMALOGENTRY struct DMALOGENTRY
{ {
uint32_t romAddr; uint32_t romAddr;

View File

@ -1,36 +1,36 @@
#include <stdafx.h> #include "stdafx.h"
#include "DebugMMU.h" #include "DebugMMU.h"
#include <Common/MemoryManagement.h> #include <Common/MemoryManagement.h>
#include <Project64-core/N64System/N64Disk.h> #include <Project64-core/N64System/N64Disk.h>
#define PJMEM_CARTROM 1 #define PJMEM_CARTROM 1
uint8_t* CDebugMMU::GetPhysicalPtr(uint32_t paddr, WORD* flags) uint8_t * CDebugMMU::GetPhysicalPtr(uint32_t paddr, WORD * flags)
{ {
if (g_MMU == nullptr) if (g_MMU == nullptr)
{ {
return nullptr; return nullptr;
} }
uint8_t* ptr = nullptr; uint8_t * ptr = nullptr;
int nbyte = paddr & 3; int nbyte = paddr & 3;
paddr = paddr & ~3; paddr = paddr & ~3;
bool bBigEndian = false; bool bBigEndian = false;
bool bCartRom = false; bool bCartRom = false;
if (paddr < g_MMU->RdramSize()) if (paddr < g_MMU->RdramSize())
{ {
ptr = (uint8_t*)(g_MMU->Rdram() + paddr); ptr = (uint8_t *)(g_MMU->Rdram() + paddr);
} }
else if (paddr >= 0x04000000 && paddr <= 0x04000FFF) else if (paddr >= 0x04000000 && paddr <= 0x04000FFF)
{ {
ptr = (uint8_t*)(g_MMU->Dmem() + paddr - 0x04000000); ptr = (uint8_t *)(g_MMU->Dmem() + paddr - 0x04000000);
} }
else if (paddr >= 0x04001000 && paddr <= 0x04001FFF) else if (paddr >= 0x04001000 && paddr <= 0x04001FFF)
{ {
ptr = (uint8_t*)(g_MMU->Imem() + paddr - 0x04001000); ptr = (uint8_t *)(g_MMU->Imem() + paddr - 0x04001000);
} }
else if (paddr >= 0x05000000 && paddr <= 0x050004FF) // 64DD buffer else if (paddr >= 0x05000000 && paddr <= 0x050004FF) // 64DD buffer
{ {
@ -42,7 +42,7 @@ uint8_t* CDebugMMU::GetPhysicalPtr(uint32_t paddr, WORD* flags)
if (g_DDRom != nullptr && iplRomOffset < g_DDRom->GetRomSize()) if (g_DDRom != nullptr && iplRomOffset < g_DDRom->GetRomSize())
{ {
ptr = (uint8_t*)(g_MMU->Rdram() + paddr); ptr = (uint8_t *)(g_MMU->Rdram() + paddr);
} }
} }
else if (paddr >= 0x10000000 && paddr <= 0x1FBFFFFF) // Cartridge ROM else if (paddr >= 0x10000000 && paddr <= 0x1FBFFFFF) // Cartridge ROM
@ -50,14 +50,14 @@ uint8_t* CDebugMMU::GetPhysicalPtr(uint32_t paddr, WORD* flags)
uint32_t cartRomOffset = paddr - 0x10000000; uint32_t cartRomOffset = paddr - 0x10000000;
if (g_Rom != nullptr && cartRomOffset < g_Rom->GetRomSize()) if (g_Rom != nullptr && cartRomOffset < g_Rom->GetRomSize())
{ {
ptr = (uint8_t*)(g_Rom->GetRomAddress() + cartRomOffset); ptr = (uint8_t *)(g_Rom->GetRomAddress() + cartRomOffset);
bCartRom = true; bCartRom = true;
} }
} }
else if (paddr >= 0x1FC007C0 && paddr <= 0x1FC007FF) // PIF RAM else if (paddr >= 0x1FC007C0 && paddr <= 0x1FC007FF) // PIF RAM
{ {
uint32_t pifRamOffset = paddr - 0x1FC007C0; uint32_t pifRamOffset = paddr - 0x1FC007C0;
ptr = (uint8_t*)(g_MMU->PifRam() + pifRamOffset); ptr = (uint8_t *)(g_MMU->PifRam() + pifRamOffset);
bBigEndian = true; bBigEndian = true;
} }
else else
@ -65,85 +65,85 @@ uint8_t* CDebugMMU::GetPhysicalPtr(uint32_t paddr, WORD* flags)
// Note: write-only registers are excluded // Note: write-only registers are excluded
switch (paddr) switch (paddr)
{ {
case 0x03F00000: ptr = (uint8_t*)&g_Reg->RDRAM_CONFIG_REG; break; case 0x03F00000: ptr = (uint8_t *)&g_Reg->RDRAM_CONFIG_REG; break;
case 0x03F00004: ptr = (uint8_t*)&g_Reg->RDRAM_DEVICE_ID_REG; break; case 0x03F00004: ptr = (uint8_t *)&g_Reg->RDRAM_DEVICE_ID_REG; break;
case 0x03F00008: ptr = (uint8_t*)&g_Reg->RDRAM_DELAY_REG; break; case 0x03F00008: ptr = (uint8_t *)&g_Reg->RDRAM_DELAY_REG; break;
case 0x03F0000C: ptr = (uint8_t*)&g_Reg->RDRAM_MODE_REG; break; case 0x03F0000C: ptr = (uint8_t *)&g_Reg->RDRAM_MODE_REG; break;
case 0x03F00010: ptr = (uint8_t*)&g_Reg->RDRAM_REF_INTERVAL_REG; break; case 0x03F00010: ptr = (uint8_t *)&g_Reg->RDRAM_REF_INTERVAL_REG; break;
case 0x03F00014: ptr = (uint8_t*)&g_Reg->RDRAM_REF_ROW_REG; break; case 0x03F00014: ptr = (uint8_t *)&g_Reg->RDRAM_REF_ROW_REG; break;
case 0x03F00018: ptr = (uint8_t*)&g_Reg->RDRAM_RAS_INTERVAL_REG; break; case 0x03F00018: ptr = (uint8_t *)&g_Reg->RDRAM_RAS_INTERVAL_REG; break;
case 0x03F0001C: ptr = (uint8_t*)&g_Reg->RDRAM_MIN_INTERVAL_REG; break; case 0x03F0001C: ptr = (uint8_t *)&g_Reg->RDRAM_MIN_INTERVAL_REG; break;
case 0x03F00020: ptr = (uint8_t*)&g_Reg->RDRAM_ADDR_SELECT_REG; break; case 0x03F00020: ptr = (uint8_t *)&g_Reg->RDRAM_ADDR_SELECT_REG; break;
case 0x03F00024: ptr = (uint8_t*)&g_Reg->RDRAM_DEVICE_MANUF_REG; break; case 0x03F00024: ptr = (uint8_t *)&g_Reg->RDRAM_DEVICE_MANUF_REG; break;
case 0x04040010: ptr = (uint8_t*)&g_Reg->SP_STATUS_REG; break; case 0x04040010: ptr = (uint8_t *)&g_Reg->SP_STATUS_REG; break;
case 0x04040014: ptr = (uint8_t*)&g_Reg->SP_DMA_FULL_REG; break; case 0x04040014: ptr = (uint8_t *)&g_Reg->SP_DMA_FULL_REG; break;
case 0x04040018: ptr = (uint8_t*)&g_Reg->SP_DMA_BUSY_REG; break; case 0x04040018: ptr = (uint8_t *)&g_Reg->SP_DMA_BUSY_REG; break;
case 0x0404001C: ptr = (uint8_t*)&g_Reg->SP_SEMAPHORE_REG; break; case 0x0404001C: ptr = (uint8_t *)&g_Reg->SP_SEMAPHORE_REG; break;
case 0x04080000: ptr = (uint8_t*)&g_Reg->SP_PC_REG; break; case 0x04080000: ptr = (uint8_t *)&g_Reg->SP_PC_REG; break;
case 0x0410000C: ptr = (uint8_t*)&g_Reg->DPC_STATUS_REG; break; case 0x0410000C: ptr = (uint8_t *)&g_Reg->DPC_STATUS_REG; break;
case 0x04100010: ptr = (uint8_t*)&g_Reg->DPC_CLOCK_REG; break; case 0x04100010: ptr = (uint8_t *)&g_Reg->DPC_CLOCK_REG; break;
case 0x04100014: ptr = (uint8_t*)&g_Reg->DPC_BUFBUSY_REG; break; case 0x04100014: ptr = (uint8_t *)&g_Reg->DPC_BUFBUSY_REG; break;
case 0x04100018: ptr = (uint8_t*)&g_Reg->DPC_PIPEBUSY_REG; break; case 0x04100018: ptr = (uint8_t *)&g_Reg->DPC_PIPEBUSY_REG; break;
case 0x0410001C: ptr = (uint8_t*)&g_Reg->DPC_TMEM_REG; break; case 0x0410001C: ptr = (uint8_t *)&g_Reg->DPC_TMEM_REG; break;
case 0x04300000: ptr = (uint8_t*)&g_Reg->MI_MODE_REG; break; case 0x04300000: ptr = (uint8_t *)&g_Reg->MI_MODE_REG; break;
case 0x04300004: ptr = (uint8_t*)&g_Reg->MI_VERSION_REG; break; case 0x04300004: ptr = (uint8_t *)&g_Reg->MI_VERSION_REG; break;
case 0x04300008: ptr = (uint8_t*)&g_Reg->MI_INTR_REG; break; case 0x04300008: ptr = (uint8_t *)&g_Reg->MI_INTR_REG; break;
case 0x0430000C: ptr = (uint8_t*)&g_Reg->MI_INTR_MASK_REG; break; case 0x0430000C: ptr = (uint8_t *)&g_Reg->MI_INTR_MASK_REG; break;
case 0x04400000: ptr = (uint8_t*)&g_Reg->VI_STATUS_REG; break; case 0x04400000: ptr = (uint8_t *)&g_Reg->VI_STATUS_REG; break;
case 0x04400004: ptr = (uint8_t*)&g_Reg->VI_ORIGIN_REG; break; case 0x04400004: ptr = (uint8_t *)&g_Reg->VI_ORIGIN_REG; break;
case 0x04400008: ptr = (uint8_t*)&g_Reg->VI_WIDTH_REG; break; case 0x04400008: ptr = (uint8_t *)&g_Reg->VI_WIDTH_REG; break;
case 0x0440000C: ptr = (uint8_t*)&g_Reg->VI_INTR_REG; break; case 0x0440000C: ptr = (uint8_t *)&g_Reg->VI_INTR_REG; break;
case 0x04400010: ptr = (uint8_t*)&g_Reg->VI_V_CURRENT_LINE_REG; break; case 0x04400010: ptr = (uint8_t *)&g_Reg->VI_V_CURRENT_LINE_REG; break;
case 0x04400014: ptr = (uint8_t*)&g_Reg->VI_BURST_REG; break; case 0x04400014: ptr = (uint8_t *)&g_Reg->VI_BURST_REG; break;
case 0x04400018: ptr = (uint8_t*)&g_Reg->VI_V_SYNC_REG; break; case 0x04400018: ptr = (uint8_t *)&g_Reg->VI_V_SYNC_REG; break;
case 0x0440001C: ptr = (uint8_t*)&g_Reg->VI_H_SYNC_REG; break; case 0x0440001C: ptr = (uint8_t *)&g_Reg->VI_H_SYNC_REG; break;
case 0x04400020: ptr = (uint8_t*)&g_Reg->VI_LEAP_REG; break; case 0x04400020: ptr = (uint8_t *)&g_Reg->VI_LEAP_REG; break;
case 0x04400024: ptr = (uint8_t*)&g_Reg->VI_H_START_REG; break; case 0x04400024: ptr = (uint8_t *)&g_Reg->VI_H_START_REG; break;
case 0x04400028: ptr = (uint8_t*)&g_Reg->VI_V_START_REG; break; case 0x04400028: ptr = (uint8_t *)&g_Reg->VI_V_START_REG; break;
case 0x0440002C: ptr = (uint8_t*)&g_Reg->VI_V_BURST_REG; break; case 0x0440002C: ptr = (uint8_t *)&g_Reg->VI_V_BURST_REG; break;
case 0x04400030: ptr = (uint8_t*)&g_Reg->VI_X_SCALE_REG; break; case 0x04400030: ptr = (uint8_t *)&g_Reg->VI_X_SCALE_REG; break;
case 0x04400034: ptr = (uint8_t*)&g_Reg->VI_Y_SCALE_REG; break; case 0x04400034: ptr = (uint8_t *)&g_Reg->VI_Y_SCALE_REG; break;
case 0x04600000: ptr = (uint8_t*)&g_Reg->PI_DRAM_ADDR_REG; break; case 0x04600000: ptr = (uint8_t *)&g_Reg->PI_DRAM_ADDR_REG; break;
case 0x04600004: ptr = (uint8_t*)&g_Reg->PI_CART_ADDR_REG; break; case 0x04600004: ptr = (uint8_t *)&g_Reg->PI_CART_ADDR_REG; break;
case 0x04600008: ptr = (uint8_t*)&g_Reg->PI_RD_LEN_REG; break; case 0x04600008: ptr = (uint8_t *)&g_Reg->PI_RD_LEN_REG; break;
case 0x0460000C: ptr = (uint8_t*)&g_Reg->PI_WR_LEN_REG; break; case 0x0460000C: ptr = (uint8_t *)&g_Reg->PI_WR_LEN_REG; break;
case 0x04600010: ptr = (uint8_t*)&g_Reg->PI_STATUS_REG; break; case 0x04600010: ptr = (uint8_t *)&g_Reg->PI_STATUS_REG; break;
case 0x04600014: ptr = (uint8_t*)&g_Reg->PI_DOMAIN1_REG; break; case 0x04600014: ptr = (uint8_t *)&g_Reg->PI_DOMAIN1_REG; break;
case 0x04600018: ptr = (uint8_t*)&g_Reg->PI_BSD_DOM1_PWD_REG; break; case 0x04600018: ptr = (uint8_t *)&g_Reg->PI_BSD_DOM1_PWD_REG; break;
case 0x0460001C: ptr = (uint8_t*)&g_Reg->PI_BSD_DOM1_PGS_REG; break; case 0x0460001C: ptr = (uint8_t *)&g_Reg->PI_BSD_DOM1_PGS_REG; break;
case 0x04600020: ptr = (uint8_t*)&g_Reg->PI_BSD_DOM1_RLS_REG; break; case 0x04600020: ptr = (uint8_t *)&g_Reg->PI_BSD_DOM1_RLS_REG; break;
case 0x04600024: ptr = (uint8_t*)&g_Reg->PI_DOMAIN2_REG; break; case 0x04600024: ptr = (uint8_t *)&g_Reg->PI_DOMAIN2_REG; break;
case 0x04600028: ptr = (uint8_t*)&g_Reg->PI_BSD_DOM2_PWD_REG; break; case 0x04600028: ptr = (uint8_t *)&g_Reg->PI_BSD_DOM2_PWD_REG; break;
case 0x0460002C: ptr = (uint8_t*)&g_Reg->PI_BSD_DOM2_PGS_REG; break; case 0x0460002C: ptr = (uint8_t *)&g_Reg->PI_BSD_DOM2_PGS_REG; break;
case 0x04600030: ptr = (uint8_t*)&g_Reg->PI_BSD_DOM2_RLS_REG; break; case 0x04600030: ptr = (uint8_t *)&g_Reg->PI_BSD_DOM2_RLS_REG; break;
case 0x04700000: ptr = (uint8_t*)&g_Reg->RI_MODE_REG; break; case 0x04700000: ptr = (uint8_t *)&g_Reg->RI_MODE_REG; break;
case 0x04700004: ptr = (uint8_t*)&g_Reg->RI_CONFIG_REG; break; case 0x04700004: ptr = (uint8_t *)&g_Reg->RI_CONFIG_REG; break;
case 0x04700008: ptr = (uint8_t*)&g_Reg->RI_CURRENT_LOAD_REG; break; case 0x04700008: ptr = (uint8_t *)&g_Reg->RI_CURRENT_LOAD_REG; break;
case 0x0470000C: ptr = (uint8_t*)&g_Reg->RI_SELECT_REG; break; case 0x0470000C: ptr = (uint8_t *)&g_Reg->RI_SELECT_REG; break;
case 0x04700010: ptr = (uint8_t*)&g_Reg->RI_REFRESH_REG; break; case 0x04700010: ptr = (uint8_t *)&g_Reg->RI_REFRESH_REG; break;
case 0x04700014: ptr = (uint8_t*)&g_Reg->RI_LATENCY_REG; break; case 0x04700014: ptr = (uint8_t *)&g_Reg->RI_LATENCY_REG; break;
case 0x04700018: ptr = (uint8_t*)&g_Reg->RI_RERROR_REG; break; case 0x04700018: ptr = (uint8_t *)&g_Reg->RI_RERROR_REG; break;
case 0x0470001C: ptr = (uint8_t*)&g_Reg->RI_WERROR_REG; break; case 0x0470001C: ptr = (uint8_t *)&g_Reg->RI_WERROR_REG; break;
case 0x04800018: ptr = (uint8_t*)&g_Reg->SI_STATUS_REG; break; case 0x04800018: ptr = (uint8_t *)&g_Reg->SI_STATUS_REG; break;
case 0x05000500: ptr = (uint8_t*)&g_Reg->ASIC_DATA; break; case 0x05000500: ptr = (uint8_t *)&g_Reg->ASIC_DATA; break;
case 0x05000504: ptr = (uint8_t*)&g_Reg->ASIC_MISC_REG; break; case 0x05000504: ptr = (uint8_t *)&g_Reg->ASIC_MISC_REG; break;
case 0x05000508: ptr = (uint8_t*)&g_Reg->ASIC_STATUS; break; case 0x05000508: ptr = (uint8_t *)&g_Reg->ASIC_STATUS; break;
case 0x0500050C: ptr = (uint8_t*)&g_Reg->ASIC_CUR_TK; break; case 0x0500050C: ptr = (uint8_t *)&g_Reg->ASIC_CUR_TK; break;
case 0x05000510: ptr = (uint8_t*)&g_Reg->ASIC_BM_STATUS; break; case 0x05000510: ptr = (uint8_t *)&g_Reg->ASIC_BM_STATUS; break;
case 0x05000514: ptr = (uint8_t*)&g_Reg->ASIC_ERR_SECTOR; break; case 0x05000514: ptr = (uint8_t *)&g_Reg->ASIC_ERR_SECTOR; break;
case 0x05000518: ptr = (uint8_t*)&g_Reg->ASIC_SEQ_STATUS; break; case 0x05000518: ptr = (uint8_t *)&g_Reg->ASIC_SEQ_STATUS; break;
case 0x0500051C: ptr = (uint8_t*)&g_Reg->ASIC_CUR_SECTOR; break; case 0x0500051C: ptr = (uint8_t *)&g_Reg->ASIC_CUR_SECTOR; break;
case 0x05000520: ptr = (uint8_t*)&g_Reg->ASIC_HARD_RESET; break; case 0x05000520: ptr = (uint8_t *)&g_Reg->ASIC_HARD_RESET; break;
case 0x05000524: ptr = (uint8_t*)&g_Reg->ASIC_C1_S0; break; case 0x05000524: ptr = (uint8_t *)&g_Reg->ASIC_C1_S0; break;
case 0x05000528: ptr = (uint8_t*)&g_Reg->ASIC_HOST_SECBYTE; break; case 0x05000528: ptr = (uint8_t *)&g_Reg->ASIC_HOST_SECBYTE; break;
case 0x0500052C: ptr = (uint8_t*)&g_Reg->ASIC_C1_S2; break; case 0x0500052C: ptr = (uint8_t *)&g_Reg->ASIC_C1_S2; break;
case 0x05000530: ptr = (uint8_t*)&g_Reg->ASIC_SEC_BYTE; break; case 0x05000530: ptr = (uint8_t *)&g_Reg->ASIC_SEC_BYTE; break;
case 0x05000534: ptr = (uint8_t*)&g_Reg->ASIC_C1_S4; break; case 0x05000534: ptr = (uint8_t *)&g_Reg->ASIC_C1_S4; break;
case 0x05000538: ptr = (uint8_t*)&g_Reg->ASIC_C1_S6; break; case 0x05000538: ptr = (uint8_t *)&g_Reg->ASIC_C1_S6; break;
case 0x0500053C: ptr = (uint8_t*)&g_Reg->ASIC_CUR_ADDR; break; case 0x0500053C: ptr = (uint8_t *)&g_Reg->ASIC_CUR_ADDR; break;
case 0x05000540: ptr = (uint8_t*)&g_Reg->ASIC_ID_REG; break; case 0x05000540: ptr = (uint8_t *)&g_Reg->ASIC_ID_REG; break;
case 0x05000544: ptr = (uint8_t*)&g_Reg->ASIC_TEST_REG; break; case 0x05000544: ptr = (uint8_t *)&g_Reg->ASIC_TEST_REG; break;
case 0x05000548: ptr = (uint8_t*)&g_Reg->ASIC_TEST_PIN_SEL; break; case 0x05000548: ptr = (uint8_t *)&g_Reg->ASIC_TEST_PIN_SEL; break;
} }
} }
@ -167,9 +167,9 @@ uint8_t* CDebugMMU::GetPhysicalPtr(uint32_t paddr, WORD* flags)
} }
} }
bool CDebugMMU::GetPhysicalByte(uint32_t paddr, uint8_t* value) bool CDebugMMU::GetPhysicalByte(uint32_t paddr, uint8_t * value)
{ {
uint8_t* ptr = GetPhysicalPtr(paddr, nullptr); uint8_t * ptr = GetPhysicalPtr(paddr, nullptr);
if (ptr != nullptr) if (ptr != nullptr)
{ {
@ -201,7 +201,7 @@ bool CDebugMMU::GetPhysicalByte(uint32_t paddr, uint8_t* value)
return true; return true;
} }
} }
if (paddr >= 0x04500004 && paddr <= 0x04500007) if (paddr >= 0x04500004 && paddr <= 0x04500007)
{ {
uint32_t audioLength; uint32_t audioLength;
@ -212,7 +212,7 @@ bool CDebugMMU::GetPhysicalByte(uint32_t paddr, uint8_t* value)
} }
else else
{ {
CAudioPlugin* audioPlg = g_Plugins->Audio(); CAudioPlugin * audioPlg = g_Plugins->Audio();
audioLength = audioPlg->AiReadLength != nullptr ? audioPlg->AiReadLength() : 0; audioLength = audioPlg->AiReadLength != nullptr ? audioPlg->AiReadLength() : 0;
} }
@ -233,7 +233,7 @@ bool CDebugMMU::GetPhysicalByte(uint32_t paddr, uint8_t* value)
bool CDebugMMU::SetPhysicalByte(uint32_t paddr, uint8_t value) bool CDebugMMU::SetPhysicalByte(uint32_t paddr, uint8_t value)
{ {
WORD flags; WORD flags;
uint8_t* ptr = GetPhysicalPtr(paddr, &flags); uint8_t * ptr = GetPhysicalPtr(paddr, &flags);
bool bCartRom = flags & PJMEM_CARTROM; bool bCartRom = flags & PJMEM_CARTROM;
if (ptr != nullptr) if (ptr != nullptr)
@ -246,7 +246,7 @@ bool CDebugMMU::SetPhysicalByte(uint32_t paddr, uint8_t value)
{ {
ProtectMemory(g_Rom->GetRomAddress(), g_Rom->GetRomSize(), MEM_READWRITE); ProtectMemory(g_Rom->GetRomAddress(), g_Rom->GetRomSize(), MEM_READWRITE);
*ptr = value; *ptr = value;
ProtectMemory(g_Rom->GetRomAddress(), g_Rom->GetRomSize(), MEM_READONLY); ProtectMemory(g_Rom->GetRomAddress(), g_Rom->GetRomSize(), MEM_READONLY);
} }
return true; return true;
} }
@ -273,7 +273,7 @@ bool CDebugMMU::SetPhysicalByte(uint32_t paddr, uint8_t value)
return false; return false;
} }
size_t CDebugMMU::ReadPhysical(uint32_t paddr, size_t length, uint8_t* buffer) size_t CDebugMMU::ReadPhysical(uint32_t paddr, size_t length, uint8_t * buffer)
{ {
size_t nByte; size_t nByte;
for (nByte = 0; nByte < length; nByte++) for (nByte = 0; nByte < length; nByte++)
@ -286,7 +286,7 @@ size_t CDebugMMU::ReadPhysical(uint32_t paddr, size_t length, uint8_t* buffer)
return nByte; return nByte;
} }
size_t CDebugMMU::ReadVirtual(uint32_t vaddr, size_t length, uint8_t* buffer) size_t CDebugMMU::ReadVirtual(uint32_t vaddr, size_t length, uint8_t * buffer)
{ {
size_t nByte; size_t nByte;
for (nByte = 0; nByte < length; nByte++) for (nByte = 0; nByte < length; nByte++)
@ -304,7 +304,7 @@ size_t CDebugMMU::ReadVirtual(uint32_t vaddr, size_t length, uint8_t* buffer)
return nByte; return nByte;
} }
size_t CDebugMMU::WritePhysical(uint32_t paddr, size_t length, uint8_t* buffer) size_t CDebugMMU::WritePhysical(uint32_t paddr, size_t length, uint8_t * buffer)
{ {
size_t nByte; size_t nByte;
for (nByte = 0; nByte < length; nByte++) for (nByte = 0; nByte < length; nByte++)
@ -317,7 +317,7 @@ size_t CDebugMMU::WritePhysical(uint32_t paddr, size_t length, uint8_t* buffer)
return nByte; return nByte;
} }
size_t CDebugMMU::WriteVirtual(uint32_t vaddr, size_t length, uint8_t* buffer) size_t CDebugMMU::WriteVirtual(uint32_t vaddr, size_t length, uint8_t * buffer)
{ {
size_t nByte; size_t nByte;
for (nByte = 0; nByte < length; nByte++) for (nByte = 0; nByte < length; nByte++)

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#include <stdafx.h>
class CDebugMMU class CDebugMMU
{ {

View File

@ -2,7 +2,7 @@
#include "DebuggerUI.h" #include "DebuggerUI.h"
LRESULT CAddBreakpointDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CAddBreakpointDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
CenterWindow(); CenterWindow();
m_AddressEdit.Attach(GetDlgItem(IDC_ADDR_EDIT)); m_AddressEdit.Attach(GetDlgItem(IDC_ADDR_EDIT));
@ -12,7 +12,7 @@ LRESULT CAddBreakpointDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
return FALSE; return FALSE;
} }
LRESULT CAddBreakpointDlg::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& /*bHandled*/) LRESULT CAddBreakpointDlg::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL & /*bHandled*/)
{ {
switch (wID) switch (wID)
{ {
@ -21,7 +21,7 @@ LRESULT CAddBreakpointDlg::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL&
std::string addrStr = GetCWindowText(m_AddressEdit); std::string addrStr = GetCWindowText(m_AddressEdit);
uint32_t address = stoul(addrStr.c_str(), nullptr, 16); uint32_t address = stoul(addrStr.c_str(), nullptr, 16);
CBreakpoints* breakpoints = m_Debugger->Breakpoints(); CBreakpoints * breakpoints = m_Debugger->Breakpoints();
if (m_ReadCheck.GetCheck()) if (m_ReadCheck.GetCheck())
{ {

View File

@ -3,7 +3,7 @@
#include "DebuggerUI.h" #include "DebuggerUI.h"
#include "Symbols.h" #include "Symbols.h"
LRESULT CAddSymbolDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CAddSymbolDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
CenterWindow(); CenterWindow();
@ -15,14 +15,14 @@ LRESULT CAddSymbolDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*l
for (int i = 0;; i++) for (int i = 0;; i++)
{ {
const char* typeName = CSymbolTable::m_SymbolTypes[i].name; const char * typeName = CSymbolTable::m_SymbolTypes[i].name;
if (typeName == nullptr) if (typeName == nullptr)
{ {
break; break;
} }
m_TypeComboBox.AddString(stdstr(typeName).ToUTF16().c_str()); m_TypeComboBox.AddString(stdstr(typeName).ToUTF16().c_str());
} }
m_AddressEdit.SetWindowText(L""); m_AddressEdit.SetWindowText(L"");
m_AddressEdit.SetFocus(); m_AddressEdit.SetFocus();
@ -32,7 +32,7 @@ LRESULT CAddSymbolDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*l
m_TypeComboBox.SetFocus(); m_TypeComboBox.SetFocus();
} }
if(m_bHaveType) if (m_bHaveType)
{ {
m_TypeComboBox.SetCurSel(m_InitType); m_TypeComboBox.SetCurSel(m_InitType);
m_NameEdit.SetFocus(); m_NameEdit.SetFocus();
@ -41,11 +41,11 @@ LRESULT CAddSymbolDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*l
{ {
m_TypeComboBox.SetCurSel(SYM_DATA); m_TypeComboBox.SetCurSel(SYM_DATA);
} }
return FALSE; return FALSE;
} }
LRESULT CAddSymbolDlg::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CAddSymbolDlg::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
switch (wID) switch (wID)
{ {
@ -66,13 +66,13 @@ LRESULT CAddSymbolDlg::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*
int nameLen = m_NameEdit.GetWindowTextLength(); int nameLen = m_NameEdit.GetWindowTextLength();
int descLen = m_DescriptionEdit.GetWindowTextLength(); int descLen = m_DescriptionEdit.GetWindowTextLength();
if (!nameLen && !descLen) if (!nameLen && !descLen)
{ {
MessageBox(L"Name and/or description required", L"Error", MB_OK); MessageBox(L"Name and/or description required", L"Error", MB_OK);
return 0; return 0;
} }
m_Debugger->SymbolTable()->AddSymbol(type, address, GetCWindowText(m_NameEdit).c_str(), GetCWindowText(m_DescriptionEdit).c_str()); m_Debugger->SymbolTable()->AddSymbol(type, address, GetCWindowText(m_NameEdit).c_str(), GetCWindowText(m_DescriptionEdit).c_str());
m_Debugger->SymbolTable()->Save(); m_Debugger->SymbolTable()->Save();
@ -84,7 +84,7 @@ LRESULT CAddSymbolDlg::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*
return 0; return 0;
} }
INT_PTR CAddSymbolDlg::DoModal(CDebuggerUI* debugger) INT_PTR CAddSymbolDlg::DoModal(CDebuggerUI * debugger)
{ {
m_Debugger = debugger; m_Debugger = debugger;
m_bHaveAddress = false; m_bHaveAddress = false;
@ -92,7 +92,7 @@ INT_PTR CAddSymbolDlg::DoModal(CDebuggerUI* debugger)
return CDialogImpl<CAddSymbolDlg>::DoModal(); return CDialogImpl<CAddSymbolDlg>::DoModal();
} }
INT_PTR CAddSymbolDlg::DoModal(CDebuggerUI* debugger, uint32_t initAddress) INT_PTR CAddSymbolDlg::DoModal(CDebuggerUI * debugger, uint32_t initAddress)
{ {
m_Debugger = debugger; m_Debugger = debugger;
m_bHaveAddress = true; m_bHaveAddress = true;
@ -101,7 +101,7 @@ INT_PTR CAddSymbolDlg::DoModal(CDebuggerUI* debugger, uint32_t initAddress)
return CDialogImpl<CAddSymbolDlg>::DoModal(); return CDialogImpl<CAddSymbolDlg>::DoModal();
} }
INT_PTR CAddSymbolDlg::DoModal(CDebuggerUI* debugger, uint32_t initAddress, int initType) INT_PTR CAddSymbolDlg::DoModal(CDebuggerUI * debugger, uint32_t initAddress, int initType)
{ {
m_Debugger = debugger; m_Debugger = debugger;
m_bHaveAddress = true; m_bHaveAddress = true;

View File

@ -1,14 +1,15 @@
#include "stdafx.h" #include "stdafx.h"
#include "DebuggerUI.h"
#include "CPULog.h" #include "CPULog.h"
#include "DebuggerUI.h"
#include "Debugger-CPULogView.h" #include "Debugger-CPULogView.h"
#include <Project64-core/N64System/Mips/R4300iInstruction.h> #include <Project64-core/N64System/Mips/R4300iInstruction.h>
CDebugCPULogView* CDebugCPULogView::_this = nullptr; CDebugCPULogView * CDebugCPULogView::_this = nullptr;
HHOOK CDebugCPULogView::hWinMessageHook = nullptr; HHOOK CDebugCPULogView::hWinMessageHook = nullptr;
CDebugCPULogView::CDebugCPULogView(CDebuggerUI* debugger) : CDebugCPULogView::CDebugCPULogView(CDebuggerUI * debugger) :
CDebugDialog<CDebugCPULogView>(debugger), CDebugDialog<CDebugCPULogView>(debugger),
m_CPULogCopy(nullptr), m_CPULogCopy(nullptr),
m_LogStartIndex(0), m_LogStartIndex(0),
@ -24,7 +25,7 @@ CDebugCPULogView::~CDebugCPULogView()
} }
} }
LRESULT CDebugCPULogView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugCPULogView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
DlgResize_Init(false, true); DlgResize_Init(false, true);
DlgToolTip_Init(); DlgToolTip_Init();
@ -45,7 +46,7 @@ LRESULT CDebugCPULogView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
m_CPUListView.SetColumnWidth(0, 65); m_CPUListView.SetColumnWidth(0, 65);
m_CPUListView.SetColumnWidth(1, 60); m_CPUListView.SetColumnWidth(1, 60);
m_CPUListView.SetColumnWidth(2, 120); m_CPUListView.SetColumnWidth(2, 120);
bool bLoggingEnabled = g_Settings->LoadBool(Debugger_CPULoggingEnabled); bool bLoggingEnabled = g_Settings->LoadBool(Debugger_CPULoggingEnabled);
uint32_t bufferSize = g_Settings->LoadDword(Debugger_CPULogBufferSize); uint32_t bufferSize = g_Settings->LoadDword(Debugger_CPULogBufferSize);
@ -54,7 +55,7 @@ LRESULT CDebugCPULogView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
m_BuffSizeEdit.SetDisplayType(CEditNumber32::DisplayDec); m_BuffSizeEdit.SetDisplayType(CEditNumber32::DisplayDec);
m_BuffSizeEdit.SetValue(bufferSize); m_BuffSizeEdit.SetValue(bufferSize);
m_BuffSizeEdit.EnableWindow(!bLoggingEnabled); m_BuffSizeEdit.EnableWindow(!bLoggingEnabled);
RefreshList(true); RefreshList(true);
m_ExportBtn.EnableWindow(false); m_ExportBtn.EnableWindow(false);
@ -94,7 +95,7 @@ LRESULT CDebugCPULogView::OnDestroy(void)
LRESULT CALLBACK CDebugCPULogView::HookProc(int nCode, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK CDebugCPULogView::HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{ {
MSG *pMsg = (MSG*)lParam; MSG * pMsg = (MSG *)lParam;
switch (pMsg->message) switch (pMsg->message)
{ {
@ -111,7 +112,7 @@ LRESULT CALLBACK CDebugCPULogView::HookProc(int nCode, WPARAM wParam, LPARAM lPa
return 0; return 0;
} }
LRESULT CDebugCPULogView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& /*bHandled*/) LRESULT CDebugCPULogView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL & /*bHandled*/)
{ {
switch (wID) switch (wID)
{ {
@ -128,18 +129,18 @@ LRESULT CDebugCPULogView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL&
Export(); Export();
break; break;
} }
return FALSE; return FALSE;
} }
LRESULT CDebugCPULogView::OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugCPULogView::OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
return FALSE; return FALSE;
} }
LRESULT CDebugCPULogView::OnListItemChanged(NMHDR* pNMHDR) LRESULT CDebugCPULogView::OnListItemChanged(NMHDR * pNMHDR)
{ {
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR); NMITEMACTIVATE * pIA = reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);
int nItem = pIA->iItem; int nItem = pIA->iItem;
ShowRegStates(m_LogStartIndex + nItem); ShowRegStates(m_LogStartIndex + nItem);
@ -147,12 +148,12 @@ LRESULT CDebugCPULogView::OnListItemChanged(NMHDR* pNMHDR)
return FALSE; return FALSE;
} }
LRESULT CDebugCPULogView::OnListDblClicked(NMHDR* pNMHDR) LRESULT CDebugCPULogView::OnListDblClicked(NMHDR * pNMHDR)
{ {
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR); NMITEMACTIVATE * pIA = reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);
int nItem = pIA->iItem; int nItem = pIA->iItem;
CPUState* state = m_CPULogCopy->GetEntry(m_LogStartIndex + nItem); CPUState * state = m_CPULogCopy->GetEntry(m_LogStartIndex + nItem);
if (state == nullptr) if (state == nullptr)
{ {
@ -164,7 +165,7 @@ LRESULT CDebugCPULogView::OnListDblClicked(NMHDR* pNMHDR)
return FALSE; return FALSE;
} }
LRESULT CDebugCPULogView::OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) LRESULT CDebugCPULogView::OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/)
{ {
if (wParam == IDC_CPU_LIST) if (wParam == IDC_CPU_LIST)
{ {
@ -175,13 +176,13 @@ LRESULT CDebugCPULogView::OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lPa
m_RowHeight = tm.tmHeight + tm.tmExternalLeading; m_RowHeight = tm.tmHeight + tm.tmExternalLeading;
MEASUREITEMSTRUCT* lpMeasureItem = (MEASUREITEMSTRUCT*)lParam; MEASUREITEMSTRUCT * lpMeasureItem = (MEASUREITEMSTRUCT *)lParam;
lpMeasureItem->itemHeight = m_RowHeight; lpMeasureItem->itemHeight = m_RowHeight;
} }
return FALSE; return FALSE;
} }
LRESULT CDebugCPULogView::OnScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) LRESULT CDebugCPULogView::OnScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/)
{ {
WORD type = LOWORD(wParam); WORD type = LOWORD(wParam);
HWND hScrollbar = (HWND)lParam; HWND hScrollbar = (HWND)lParam;
@ -318,7 +319,7 @@ void CDebugCPULogView::RefreshList(bool bUpdateBuffer)
for (size_t i = start; i < end; i++) for (size_t i = start; i < end; i++)
{ {
CPUState* state = m_CPULogCopy->GetEntry(i); CPUState * state = m_CPULogCopy->GetEntry(i);
if (state == nullptr) if (state == nullptr)
{ {
@ -340,7 +341,7 @@ void CDebugCPULogView::RefreshList(bool bUpdateBuffer)
void CDebugCPULogView::ShowRegStates(size_t stateIndex) void CDebugCPULogView::ShowRegStates(size_t stateIndex)
{ {
CPUState* state = m_CPULogCopy->GetEntry(stateIndex); CPUState * state = m_CPULogCopy->GetEntry(stateIndex);
if (state == nullptr) if (state == nullptr)
{ {
@ -348,7 +349,7 @@ void CDebugCPULogView::ShowRegStates(size_t stateIndex)
} }
char szRegStates[2048]; char szRegStates[2048];
char* out = szRegStates; char * out = szRegStates;
out += sprintf(out, "PC: %08X\r\n\r\n", state->pc); out += sprintf(out, "PC: %08X\r\n\r\n", state->pc);
@ -368,8 +369,8 @@ void CDebugCPULogView::ShowRegStates(size_t stateIndex)
{ {
int regl = i, regr = i + 16; int regl = i, regr = i + 16;
out += sprintf(out, "%-3s: %08X %-3s: %08X\r\n", out += sprintf(out, "%-3s: %08X %-3s: %08X\r\n",
CRegName::FPR[regl], *(uint32_t*)&state->fpr[regl], CRegName::FPR[regl], *(uint32_t *)&state->fpr[regl],
CRegName::FPR[regr], *(uint32_t*)&state->fpr[regr]); CRegName::FPR[regr], *(uint32_t *)&state->fpr[regr]);
} }
out += sprintf(out, "FPCR: %08X\r\n", state->fpcr); out += sprintf(out, "FPCR: %08X\r\n", state->fpcr);
@ -386,7 +387,7 @@ void CDebugCPULogView::Export(void)
OPENFILENAMEA openfilename; OPENFILENAMEA openfilename;
char filePath[255]; char filePath[255];
memset(&filePath, 0, sizeof(filePath)); memset(&filePath, 0, sizeof(filePath));
memset(&openfilename, 0, sizeof(openfilename)); memset(&openfilename, 0, sizeof(openfilename));
@ -408,7 +409,7 @@ void CDebugCPULogView::Export(void)
// Utility // Utility
int CDebugCPULogView::GetNumVisibleRows(CListViewCtrl& list) int CDebugCPULogView::GetNumVisibleRows(CListViewCtrl & list)
{ {
CHeaderCtrl header = list.GetHeader(); CHeaderCtrl header = list.GetHeader();
CRect listRect, headRect; CRect listRect, headRect;

View File

@ -1,6 +1,4 @@
#pragma once #pragma once
#include <stdafx.h>
#include "DebuggerUI.h" #include "DebuggerUI.h"
class CDebugCPULogView : class CDebugCPULogView :

View File

@ -1,10 +1,11 @@
#include "stdafx.h" #include "stdafx.h"
#include "DebuggerUI.h" #include "DebuggerUI.h"
#include "Symbols.h"
#include "Breakpoints.h"
#include "Assembler.h" #include "Assembler.h"
#include "Breakpoints.h"
#include "OpInfo.h" #include "OpInfo.h"
#include "Symbols.h"
#include <Project64-core/N64System/Mips/R4300iInstruction.h> #include <Project64-core/N64System/Mips/R4300iInstruction.h>
@ -31,10 +32,10 @@ void CCommandList::Attach(HWND hWndNew)
SetColumnWidth(COL_SYMBOL, 180); SetColumnWidth(COL_SYMBOL, 180);
} }
CDebugCommandsView* CDebugCommandsView::_this = nullptr; CDebugCommandsView * CDebugCommandsView::_this = nullptr;
HHOOK CDebugCommandsView::hWinMessageHook = nullptr; HHOOK CDebugCommandsView::hWinMessageHook = nullptr;
CDebugCommandsView::CDebugCommandsView(CDebuggerUI * debugger, SyncEvent &StepEvent) : CDebugCommandsView::CDebugCommandsView(CDebuggerUI * debugger, SyncEvent & StepEvent) :
CDebugDialog<CDebugCommandsView>(debugger), CDebugDialog<CDebugCommandsView>(debugger),
CToolTipDialog<CDebugCommandsView>(), CToolTipDialog<CDebugCommandsView>(),
m_StepEvent(StepEvent), m_StepEvent(StepEvent),
@ -56,7 +57,7 @@ CDebugCommandsView::~CDebugCommandsView()
g_Settings->UnregisterChangeCB(GameRunning_CPU_Running, this, (CSettings::SettingChangedFunc)GameCpuRunningChanged); g_Settings->UnregisterChangeCB(GameRunning_CPU_Running, this, (CSettings::SettingChangedFunc)GameCpuRunningChanged);
} }
LRESULT CDebugCommandsView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
m_StartAddress = g_Reg ? g_Reg->m_PROGRAM_COUNTER : 0x80000000; m_StartAddress = g_Reg ? g_Reg->m_PROGRAM_COUNTER : 0x80000000;
@ -164,11 +165,11 @@ void CDebugCommandsView::RecompilerCheck(void)
!g_Settings->LoadBool(Setting_ForceInterpreterCPU) && !g_Settings->LoadBool(Setting_ForceInterpreterCPU) &&
(CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_Interpreter) (CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_Interpreter)
{ {
// TODO: Remove this or fix? // TODO: Remove this or fix?
MessageBox(L"Debugger support for the recompiler core is experimental.\n\n" MessageBox(L"Debugger support for the recompiler core is experimental.\n\n"
L"For optimal experience, enable \"Always use interpreter core\" " L"For optimal experience, enable \"Always use interpreter core\" "
L"in advanced settings and restart the emulator.", L"in advanced settings and restart the emulator.",
L"Warning", MB_ICONWARNING | MB_OK); L"Warning", MB_ICONWARNING | MB_OK);
} }
} }
@ -206,7 +207,7 @@ void CDebugCommandsView::InterceptKeyDown(WPARAM wParam, LPARAM /*lParam*/)
switch (wParam) switch (wParam)
{ {
case VK_F1: CPUSkip(); break; case VK_F1: CPUSkip(); break;
case VK_F2: case VK_F2:
if (WaitingForStep()) if (WaitingForStep())
{ {
m_StepEvent.Trigger(); m_StepEvent.Trigger();
@ -228,7 +229,7 @@ void CDebugCommandsView::InterceptMouseWheel(WPARAM wParam, LPARAM /*lParam*/)
LRESULT CALLBACK CDebugCommandsView::HookProc(int nCode, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK CDebugCommandsView::HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{ {
MSG *pMsg = (MSG*)lParam; MSG * pMsg = (MSG *)lParam;
if (pMsg->message == WM_KEYDOWN) if (pMsg->message == WM_KEYDOWN)
{ {
@ -294,7 +295,7 @@ void CDebugCommandsView::AddBranchArrow(int startPos, int endPos)
} }
} }
m_BranchArrows.push_back({ startPos, endPos, startMargin, endMargin, margin }); m_BranchArrows.push_back({startPos, endPos, startMargin, endMargin, margin});
} }
void CDebugCommandsView::HistoryPushState() void CDebugCommandsView::HistoryPushState()
@ -304,7 +305,7 @@ void CDebugCommandsView::HistoryPushState()
ToggleHistoryButtons(); ToggleHistoryButtons();
} }
const char* CDebugCommandsView::GetDataAddressNotes(uint32_t vAddr) const char * CDebugCommandsView::GetDataAddressNotes(uint32_t vAddr)
{ {
switch (vAddr) switch (vAddr)
{ {
@ -424,7 +425,7 @@ const char* CDebugCommandsView::GetDataAddressNotes(uint32_t vAddr)
return nullptr; return nullptr;
} }
const char* CDebugCommandsView::GetCodeAddressNotes(uint32_t vAddr) const char * CDebugCommandsView::GetCodeAddressNotes(uint32_t vAddr)
{ {
switch (vAddr) switch (vAddr)
{ {
@ -447,8 +448,8 @@ const char* CDebugCommandsView::GetCodeAddressNotes(uint32_t vAddr)
return nullptr; return nullptr;
} }
uint8_t* rom = g_Rom->GetRomAddress(); uint8_t * rom = g_Rom->GetRomAddress();
uint32_t gameEntryPoint = *(uint32_t*)&rom[0x08]; uint32_t gameEntryPoint = *(uint32_t *)&rom[0x08];
if (vAddr == gameEntryPoint) if (vAddr == gameEntryPoint)
{ {
@ -485,7 +486,7 @@ void CDebugCommandsView::ShowAddress(uint32_t address, bool top, bool bUserInput
else else
{ {
bool bOutOfView = address < m_StartAddress || bool bOutOfView = address < m_StartAddress ||
address > m_StartAddress + (m_CommandListRows - 1) * 4; address > m_StartAddress + (m_CommandListRows - 1) * 4;
if (bOutOfView) if (bOutOfView)
{ {
@ -531,7 +532,7 @@ void CDebugCommandsView::ShowAddress(uint32_t address, bool top, bool bUserInput
m_CommandList.AddItem(i, CCommandList::COL_ADDRESS, stdstr(addrStr).ToUTF16().c_str()); m_CommandList.AddItem(i, CCommandList::COL_ADDRESS, stdstr(addrStr).ToUTF16().c_str());
COpInfo OpInfo; COpInfo OpInfo;
R4300iOpcode& OpCode = OpInfo.m_OpCode; R4300iOpcode & OpCode = OpInfo.m_OpCode;
if (!m_Debugger->DebugLoad_VAddr(opAddr, OpCode.Value)) if (!m_Debugger->DebugLoad_VAddr(opAddr, OpCode.Value))
{ {
@ -557,7 +558,7 @@ void CDebugCommandsView::ShowAddress(uint32_t address, bool top, bool bUserInput
} }
// Detect reads and writes to mapped registers, cart header data, etc. // Detect reads and writes to mapped registers, cart header data, etc.
const char* annotation = nullptr; const char * annotation = nullptr;
bool bLoadStoreAnnotation = false; bool bLoadStoreAnnotation = false;
CSymbol memSymbol; CSymbol memSymbol;
@ -618,7 +619,7 @@ void CDebugCommandsView::ShowAddress(uint32_t address, bool top, bool bUserInput
} }
else if (annotation != nullptr) else if (annotation != nullptr)
{ {
const char* annotationFormat = bLoadStoreAnnotation ? "// (%s)" : "// %s"; const char * annotationFormat = bLoadStoreAnnotation ? "// (%s)" : "// %s";
m_CommandList.AddItem(i, CCommandList::COL_SYMBOL, stdstr_f(annotationFormat, annotation).ToUTF16().c_str()); m_CommandList.AddItem(i, CCommandList::COL_SYMBOL, stdstr_f(annotationFormat, annotation).ToUTF16().c_str());
m_bvAnnotatedLines.push_back(true); m_bvAnnotatedLines.push_back(true);
} }
@ -661,9 +662,9 @@ void CDebugCommandsView::ShowAddress(uint32_t address, bool top, bool bUserInput
} }
// Highlight command list items and draw branch arrows // Highlight command list items and draw branch arrows
LRESULT CDebugCommandsView::OnCustomDrawList(NMHDR* pNMHDR) LRESULT CDebugCommandsView::OnCustomDrawList(NMHDR * pNMHDR)
{ {
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR); NMLVCUSTOMDRAW * pLVCD = reinterpret_cast<NMLVCUSTOMDRAW *>(pNMHDR);
DWORD drawStage = pLVCD->nmcd.dwDrawStage; DWORD drawStage = pLVCD->nmcd.dwDrawStage;
switch (drawStage) switch (drawStage)
@ -734,49 +735,50 @@ LRESULT CDebugCommandsView::OnCustomDrawList(NMHDR* pNMHDR)
// Command and arguments // Command and arguments
COpInfo OpInfo; COpInfo OpInfo;
R4300iOpcode& OpCode = OpInfo.m_OpCode; R4300iOpcode & OpCode = OpInfo.m_OpCode;
bool bAddrOkay = m_Debugger->DebugLoad_VAddr(address, OpCode.Value); bool bAddrOkay = m_Debugger->DebugLoad_VAddr(address, OpCode.Value);
struct { struct
{
COLORREF bg; COLORREF bg;
COLORREF fg; COLORREF fg;
} colors; } colors;
if (!bAddrOkay) if (!bAddrOkay)
{ {
colors = { 0xFFFFFF, 0xFF0000 }; colors = {0xFFFFFF, 0xFF0000};
} }
else if (address == pc && isStepping()) else if (address == pc && isStepping())
{ {
colors = { 0xFFFFAA, 0x222200 }; colors = {0xFFFFAA, 0x222200};
} }
else if (IsOpEdited(address)) else if (IsOpEdited(address))
{ {
colors = { 0xFFEEFF, 0xFF00FF }; colors = {0xFFEEFF, 0xFF00FF};
} }
else if (OpInfo.IsStackAlloc()) else if (OpInfo.IsStackAlloc())
{ {
colors = { 0xCCDDFF, 0x001144 }; colors = {0xCCDDFF, 0x001144};
} }
else if (OpInfo.IsStackFree()) else if (OpInfo.IsStackFree())
{ {
colors = { 0xFFDDDD, 0x440000 }; colors = {0xFFDDDD, 0x440000};
} }
else if (OpInfo.IsNOP()) else if (OpInfo.IsNOP())
{ {
colors = { 0xFFFFFF, 0x888888 }; colors = {0xFFFFFF, 0x888888};
} }
else if (OpInfo.IsJump()) else if (OpInfo.IsJump())
{ {
colors = { 0xEEFFEE, 0x006600 }; colors = {0xEEFFEE, 0x006600};
} }
else if (OpInfo.IsBranch()) else if (OpInfo.IsBranch())
{ {
colors = { 0xFFFFFF, 0x337700 }; colors = {0xFFFFFF, 0x337700};
} }
else else
{ {
colors = { 0xFFFFFF, 0x0000000 }; colors = {0xFFFFFF, 0x0000000};
} }
// Gray annotations // Gray annotations
@ -798,7 +800,7 @@ LRESULT CDebugCommandsView::OnCustomDrawList(NMHDR* pNMHDR)
// Color register usage // Color register usage
// TODO: localize to temporary register context (don't look before/after jumps and frame shifts) // TODO: localize to temporary register context (don't look before/after jumps and frame shifts)
COLORREF clrUsedRegister = RGB(0xF5, 0xF0, 0xFF); // Light purple COLORREF clrUsedRegister = RGB(0xF5, 0xF0, 0xFF); // Light purple
COLORREF clrAffectedRegister = RGB(0xFF, 0xF0, 0xFF); // Light pink COLORREF clrAffectedRegister = RGB(0xFF, 0xF0, 0xFF); // Light pink
int pcUsedRegA = 0, pcUsedRegB = 0, pcChangedReg = 0; int pcUsedRegA = 0, pcUsedRegB = 0, pcChangedReg = 0;
@ -845,7 +847,7 @@ LRESULT CDebugCommandsView::OnCustomDrawList(NMHDR* pNMHDR)
return CDRF_DODEFAULT; return CDRF_DODEFAULT;
} }
LRESULT CDebugCommandsView::OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/)
{ {
if (wParam == IDC_CMD_LIST) if (wParam == IDC_CMD_LIST)
{ {
@ -856,7 +858,7 @@ LRESULT CDebugCommandsView::OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM l
m_RowHeight = tm.tmHeight + tm.tmExternalLeading; m_RowHeight = tm.tmHeight + tm.tmExternalLeading;
MEASUREITEMSTRUCT* lpMeasureItem = (MEASUREITEMSTRUCT*)lParam; MEASUREITEMSTRUCT * lpMeasureItem = (MEASUREITEMSTRUCT *)lParam;
lpMeasureItem->itemHeight = m_RowHeight; lpMeasureItem->itemHeight = m_RowHeight;
} }
return FALSE; return FALSE;
@ -866,18 +868,18 @@ LRESULT CDebugCommandsView::OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM l
void CDebugCommandsView::DrawBranchArrows(HDC listDC) void CDebugCommandsView::DrawBranchArrows(HDC listDC)
{ {
COLORREF colors[] = COLORREF colors[] =
{ {
RGB(240, 240, 240), // White RGB(240, 240, 240), // White
RGB(30, 135, 255), // Blue RGB(30, 135, 255), // Blue
RGB(255, 0, 200), // Pink RGB(255, 0, 200), // Pink
RGB(215, 155, 0), // Yellow RGB(215, 155, 0), // Yellow
RGB(100, 180, 0), // Green RGB(100, 180, 0), // Green
RGB(200, 100, 255), // Purple RGB(200, 100, 255), // Purple
RGB(120, 120, 120), // Gray RGB(120, 120, 120), // Gray
RGB(0, 220, 160), // Cyan RGB(0, 220, 160), // Cyan
RGB(255, 100, 0), // Orange RGB(255, 100, 0), // Orange
RGB(255, 255, 0), // Yellow RGB(255, 255, 0), // Yellow
}; };
int nColors = sizeof(colors) / sizeof(COLORREF); int nColors = sizeof(colors) / sizeof(COLORREF);
@ -1077,7 +1079,7 @@ void CDebugCommandsView::CPUStepOver()
} }
} }
LRESULT CDebugCommandsView::OnBackButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnBackButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
if (m_HistoryIndex > 0) if (m_HistoryIndex > 0)
{ {
@ -1088,7 +1090,7 @@ LRESULT CDebugCommandsView::OnBackButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWN
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnForwardButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnForwardButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
if (m_History.size() > 0 && m_HistoryIndex < (int)m_History.size() - 1) if (m_History.size() > 0 && m_HistoryIndex < (int)m_History.size() - 1)
{ {
@ -1099,7 +1101,7 @@ LRESULT CDebugCommandsView::OnForwardButton(WORD /*wNotifyCode*/, WORD /*wID*/,
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnViewPCButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnViewPCButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
if (g_Reg != nullptr && isStepping()) if (g_Reg != nullptr && isStepping())
{ {
@ -1108,27 +1110,27 @@ LRESULT CDebugCommandsView::OnViewPCButton(WORD /*wNotifyCode*/, WORD /*wID*/, H
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnSymbolsButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnSymbolsButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
m_Debugger->OpenSymbolsWindow(); m_Debugger->OpenSymbolsWindow();
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnPopupmenuRunTo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnPopupmenuRunTo(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
// Add temp breakpoints and resume // Add temp breakpoints and resume
m_Breakpoints->AddExecution(m_SelectedAddress, true); m_Breakpoints->AddExecution(m_SelectedAddress, true);
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnGoButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnGoButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CPUResume(); CPUResume();
m_AddressEdit.SetFocus(); m_AddressEdit.SetFocus();
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnStepButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnStepButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
if (WaitingForStep()) if (WaitingForStep())
{ {
@ -1137,20 +1139,20 @@ LRESULT CDebugCommandsView::OnStepButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWN
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnStepOverButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnStepOverButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CPUStepOver(); CPUStepOver();
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnSkipButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnSkipButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CPUSkip(); CPUSkip();
m_AddressEdit.SetFocus(); m_AddressEdit.SetFocus();
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnClearBPButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnClearBPButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
m_Breakpoints->BPClear(); m_Breakpoints->BPClear();
RefreshBreakpointList(); RefreshBreakpointList();
@ -1158,7 +1160,7 @@ LRESULT CDebugCommandsView::OnClearBPButton(WORD /*wNotifyCode*/, WORD /*wID*/,
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnAddBPButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnAddBPButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
m_AddBreakpointDlg.DoModal(m_Debugger); m_AddBreakpointDlg.DoModal(m_Debugger);
RefreshBreakpointList(); RefreshBreakpointList();
@ -1166,65 +1168,65 @@ LRESULT CDebugCommandsView::OnAddBPButton(WORD /*wNotifyCode*/, WORD /*wID*/, HW
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnRemoveBPButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnRemoveBPButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
RemoveSelectedBreakpoints(); RemoveSelectedBreakpoints();
ShowAddress(m_StartAddress, TRUE); ShowAddress(m_StartAddress, TRUE);
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnCopyTabRegistersButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnCopyTabRegistersButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
m_RegisterTabs.CopyTabRegisters(); m_RegisterTabs.CopyTabRegisters();
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnCopyAllRegistersButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnCopyAllRegistersButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
m_RegisterTabs.CopyAllRegisters(); m_RegisterTabs.CopyAllRegisters();
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
EndDialog(0); EndDialog(0);
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnPopupmenuEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnPopupmenuEdit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
BeginOpEdit(m_SelectedAddress); BeginOpEdit(m_SelectedAddress);
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnPopupmenuInsertNOP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnPopupmenuInsertNOP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
EditOp(m_SelectedAddress, 0x00000000); EditOp(m_SelectedAddress, 0x00000000);
ShowAddress(m_StartAddress, TRUE); ShowAddress(m_StartAddress, TRUE);
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnPopupmenuRestore(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnPopupmenuRestore(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
RestoreOp(m_SelectedAddress); RestoreOp(m_SelectedAddress);
ShowAddress(m_StartAddress, TRUE); ShowAddress(m_StartAddress, TRUE);
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnPopupmenuRestoreAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnPopupmenuRestoreAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
RestoreAllOps(); RestoreAllOps();
ShowAddress(m_StartAddress, TRUE); ShowAddress(m_StartAddress, TRUE);
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnPopupmenuAddSymbol(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnPopupmenuAddSymbol(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
m_AddSymbolDlg.DoModal(m_Debugger, m_SelectedAddress, SYM_CODE); m_AddSymbolDlg.DoModal(m_Debugger, m_SelectedAddress, SYM_CODE);
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnPopupmenuFollowJump(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnPopupmenuFollowJump(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
HistoryPushState(); HistoryPushState();
ShowAddress(m_FollowAddress, TRUE); ShowAddress(m_FollowAddress, TRUE);
@ -1232,13 +1234,13 @@ LRESULT CDebugCommandsView::OnPopupmenuFollowJump(WORD /*wNotifyCode*/, WORD /*w
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnPopupmenuViewMemory(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnPopupmenuViewMemory(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
m_Debugger->Debug_ShowMemoryLocation(m_FollowAddress, true); m_Debugger->Debug_ShowMemoryLocation(m_FollowAddress, true);
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnPopupmenuToggleBP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnPopupmenuToggleBP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
if (m_Breakpoints->ExecutionBPExists(m_SelectedAddress)) if (m_Breakpoints->ExecutionBPExists(m_SelectedAddress))
{ {
@ -1252,7 +1254,7 @@ LRESULT CDebugCommandsView::OnPopupmenuToggleBP(WORD /*wNotifyCode*/, WORD /*wID
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnPopupmenuClearBP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnPopupmenuClearBP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
m_Breakpoints->EBPClear(); m_Breakpoints->EBPClear();
ShowAddress(m_StartAddress, TRUE); ShowAddress(m_StartAddress, TRUE);
@ -1280,7 +1282,7 @@ void CDebugCommandsView::BeginOpEdit(uint32_t address)
//itemRect.bottom += 0; //itemRect.bottom += 0;
itemRect.left += listRect.left + 3; itemRect.left += listRect.left + 3;
itemRect.right += 100; itemRect.right += 100;
m_OpEdit.ShowWindow(SW_SHOW); m_OpEdit.ShowWindow(SW_SHOW);
m_OpEdit.MoveWindow(&itemRect); m_OpEdit.MoveWindow(&itemRect);
m_OpEdit.BringWindowToTop(); m_OpEdit.BringWindowToTop();
@ -1299,7 +1301,7 @@ void CDebugCommandsView::EndOpEdit()
m_OpEdit.ShowWindow(SW_HIDE); m_OpEdit.ShowWindow(SW_HIDE);
} }
LRESULT CDebugCommandsView::OnAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
if (!m_Attached) if (!m_Attached)
{ {
@ -1317,7 +1319,7 @@ LRESULT CDebugCommandsView::OnAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HW
return 0; return 0;
} }
LRESULT CDebugCommandsView::OnPCChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnPCChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
if (!m_Attached) if (!m_Attached)
{ {
@ -1335,16 +1337,16 @@ LRESULT CDebugCommandsView::OnPCChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND
return 0; return 0;
} }
LRESULT CDebugCommandsView::OnCommandListClicked(NMHDR* /*pNMHDR*/) LRESULT CDebugCommandsView::OnCommandListClicked(NMHDR * /*pNMHDR*/)
{ {
EndOpEdit(); EndOpEdit();
return 0; return 0;
} }
LRESULT CDebugCommandsView::OnCommandListDblClicked(NMHDR* pNMHDR) LRESULT CDebugCommandsView::OnCommandListDblClicked(NMHDR * pNMHDR)
{ {
// Set PC breakpoint // Set PC breakpoint
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR); NMITEMACTIVATE * pIA = reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);
int nItem = pIA->iItem; int nItem = pIA->iItem;
uint32_t address = m_StartAddress + nItem * 4; uint32_t address = m_StartAddress + nItem * 4;
@ -1363,11 +1365,11 @@ LRESULT CDebugCommandsView::OnCommandListDblClicked(NMHDR* pNMHDR)
return 0; return 0;
} }
LRESULT CDebugCommandsView::OnCommandListRightClicked(NMHDR* pNMHDR) LRESULT CDebugCommandsView::OnCommandListRightClicked(NMHDR * pNMHDR)
{ {
EndOpEdit(); EndOpEdit();
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR); NMITEMACTIVATE * pIA = reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);
int nItem = pIA->iItem; int nItem = pIA->iItem;
uint32_t address = m_StartAddress + nItem * 4; uint32_t address = m_StartAddress + nItem * 4;
@ -1380,7 +1382,7 @@ LRESULT CDebugCommandsView::OnCommandListRightClicked(NMHDR* pNMHDR)
HMENU hMenu = LoadMenu(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDR_OP_POPUP)); HMENU hMenu = LoadMenu(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDR_OP_POPUP));
HMENU hPopupMenu = GetSubMenu(hMenu, 0); HMENU hPopupMenu = GetSubMenu(hMenu, 0);
if (m_SelectedOpInfo.IsStaticJump()) if (m_SelectedOpInfo.IsStaticJump())
{ {
m_FollowAddress = (m_SelectedAddress & 0xF0000000) | (m_SelectedOpCode.target * 4); m_FollowAddress = (m_SelectedAddress & 0xF0000000) | (m_SelectedOpCode.target * 4);
@ -1433,7 +1435,7 @@ LRESULT CDebugCommandsView::OnCommandListRightClicked(NMHDR* pNMHDR)
return 0; return 0;
} }
LRESULT CDebugCommandsView::OnListBoxClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnListBoxClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
if (wID == IDC_BP_LIST) if (wID == IDC_BP_LIST)
{ {
@ -1456,7 +1458,7 @@ LRESULT CDebugCommandsView::OnListBoxClicked(WORD /*wNotifyCode*/, WORD wID, HWN
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnActivate(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
if (!m_Attached) if (!m_Attached)
{ {
@ -1495,13 +1497,13 @@ void CDebugCommandsView::RedrawCommandsAndRegisters()
listHead.ResizeClient(listRect.Width(), headRect.Height()); listHead.ResizeClient(listRect.Width(), headRect.Height());
} }
LRESULT CDebugCommandsView::OnSizing(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnSizing(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
RedrawCommandsAndRegisters(); RedrawCommandsAndRegisters();
return FALSE; return FALSE;
} }
LRESULT CDebugCommandsView::OnScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
WORD type = LOWORD(wParam); WORD type = LOWORD(wParam);
@ -1597,7 +1599,7 @@ void CDebugCommandsView::EditOp(uint32_t address, uint32_t op, bool bRefresh)
if (!IsOpEdited(address)) if (!IsOpEdited(address))
{ {
m_EditedOps.push_back({ address, currentOp }); m_EditedOps.push_back({address, currentOp});
} }
if (bRefresh) if (bRefresh)
@ -1635,7 +1637,7 @@ void CDebugCommandsView::ShowPIRegTab()
m_RegisterTabs.ShowTab(2); m_RegisterTabs.ShowTab(2);
} }
LRESULT CDebugCommandsView::OnRegisterTabChange(NMHDR* /*pNMHDR*/) LRESULT CDebugCommandsView::OnRegisterTabChange(NMHDR * /*pNMHDR*/)
{ {
int nPage = m_RegisterTabs.GetCurSel(); int nPage = m_RegisterTabs.GetCurSel();
m_RegisterTabs.ShowTab(nPage); m_RegisterTabs.ShowTab(nPage);
@ -1659,7 +1661,7 @@ void CDebugCommandsView::ToggleHistoryButtons()
// Opcode editor // Opcode editor
LRESULT CDebugCommandsView::OnOpEditKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled) LRESULT CDebugCommandsView::OnOpEditKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & bHandled)
{ {
if (wParam == VK_UP) if (wParam == VK_UP)
{ {
@ -1694,7 +1696,7 @@ LRESULT CDebugCommandsView::OnOpEditKeyDown(UINT /*uMsg*/, WPARAM wParam, LPARAM
return 1; return 1;
} }
LRESULT CDebugCommandsView::OnOpEditChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugCommandsView::OnOpEditChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
// Handle multiline input // Handle multiline input
std::string text = GetCWindowText(m_OpEdit); std::string text = GetCWindowText(m_OpEdit);
@ -1705,7 +1707,7 @@ LRESULT CDebugCommandsView::OnOpEditChanged(WORD /*wNotifyCode*/, WORD /*wID*/,
EndOpEdit(); EndOpEdit();
for (size_t i = 0 , n = text.size(); i < n; i++) for (size_t i = 0, n = text.size(); i < n; i++)
{ {
if (text[i] == '\r') if (text[i] == '\r')
{ {
@ -1745,7 +1747,7 @@ LRESULT CDebugCommandsView::OnOpEditChanged(WORD /*wNotifyCode*/, WORD /*wID*/,
return FALSE; return FALSE;
} }
LRESULT CEditOp::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT CEditOp::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled)
{ {
if (m_CommandsWindow == nullptr) if (m_CommandsWindow == nullptr)
{ {
@ -1754,7 +1756,7 @@ LRESULT CEditOp::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandl
return m_CommandsWindow->OnOpEditKeyDown(uMsg, wParam, lParam, bHandled); return m_CommandsWindow->OnOpEditKeyDown(uMsg, wParam, lParam, bHandled);
} }
void CEditOp::SetCommandsWindow(CDebugCommandsView* commandsWindow) void CEditOp::SetCommandsWindow(CDebugCommandsView * commandsWindow)
{ {
m_CommandsWindow = commandsWindow; m_CommandsWindow = commandsWindow;
} }

View File

@ -1,10 +1,11 @@
#include "stdafx.h" #include "stdafx.h"
#include "DebuggerUI.h"
#include "DMALog.h" #include "DMALog.h"
#include "DebuggerUI.h"
#include <fstream> #include <fstream>
CDebugDMALogView::CDebugDMALogView(CDebuggerUI* debugger) : CDebugDMALogView::CDebugDMALogView(CDebuggerUI * debugger) :
CDebugDialog<CDebugDMALogView>(debugger) CDebugDialog<CDebugDMALogView>(debugger)
{ {
m_DMALog = debugger->DMALog(); m_DMALog = debugger->DMALog();
m_bFilterChanged = false; m_bFilterChanged = false;
@ -42,9 +43,9 @@ void CDebugDMALogView::RefreshList()
{ {
return; return;
} }
uint8_t* rom = g_Rom->GetRomAddress(); uint8_t * rom = g_Rom->GetRomAddress();
// Get scrollbar state // Get scrollbar state
SCROLLINFO scroll; SCROLLINFO scroll;
scroll.cbSize = sizeof(SCROLLINFO); scroll.cbSize = sizeof(SCROLLINFO);
@ -60,7 +61,7 @@ void CDebugDMALogView::RefreshList()
int startIndex; int startIndex;
int dmaLogSize = m_Debugger->DMALog()->GetNumEntries(); int dmaLogSize = m_Debugger->DMALog()->GetNumEntries();
HWND hWndExportBtn = GetDlgItem(IDC_EXPORT_BTN); HWND hWndExportBtn = GetDlgItem(IDC_EXPORT_BTN);
if (dmaLogSize == 0) if (dmaLogSize == 0)
@ -77,51 +78,51 @@ void CDebugDMALogView::RefreshList()
startIndex = m_nLastStartIndex; startIndex = m_nLastStartIndex;
::EnableWindow(hWndExportBtn, TRUE); ::EnableWindow(hWndExportBtn, TRUE);
} }
m_DMAList.SetRedraw(FALSE); m_DMAList.SetRedraw(FALSE);
int itemIndex = m_DMAList.GetItemCount(); int itemIndex = m_DMAList.GetItemCount();
for (int i = startIndex; i < dmaLogSize; i++) for (int i = startIndex; i < dmaLogSize; i++)
{ {
DMALOGENTRY* lpEntry = m_DMALog->GetEntryByIndex(i); DMALOGENTRY * lpEntry = m_DMALog->GetEntryByIndex(i);
//if (!FilterEntry(i)) //if (!FilterEntry(i))
//{ //{
// continue; // continue;
//} //}
m_DMAList.AddItem(itemIndex, 0, stdstr_f("%08X", lpEntry->romAddr).ToUTF16().c_str()); m_DMAList.AddItem(itemIndex, 0, stdstr_f("%08X", lpEntry->romAddr).ToUTF16().c_str());
m_DMAList.AddItem(itemIndex, 1, stdstr_f("%08X", lpEntry->ramAddr).ToUTF16().c_str()); m_DMAList.AddItem(itemIndex, 1, stdstr_f("%08X", lpEntry->ramAddr).ToUTF16().c_str());
m_DMAList.AddItem(itemIndex, 2, stdstr_f("%08X (%d)", lpEntry->length, lpEntry->length).ToUTF16().c_str()); m_DMAList.AddItem(itemIndex, 2, stdstr_f("%08X (%d)", lpEntry->length, lpEntry->length).ToUTF16().c_str());
union union
{ {
uint32_t u32; uint32_t u32;
uint8_t sz[5]; uint8_t sz[5];
} sig = { 0 }; } sig = {0};
if (lpEntry->romAddr < g_Rom->GetRomSize()) if (lpEntry->romAddr < g_Rom->GetRomSize())
{ {
sig.u32 = _byteswap_ulong(*(uint32_t*)&rom[lpEntry->romAddr]); sig.u32 = _byteswap_ulong(*(uint32_t *)&rom[lpEntry->romAddr]);
} }
// TODO: checkbox to display all in hex // TODO: checkbox to display all in hex
if (isalnum(sig.sz[0]) && isalnum(sig.sz[1]) && isalnum(sig.sz[2]) && isalnum(sig.sz[3])) if (isalnum(sig.sz[0]) && isalnum(sig.sz[1]) && isalnum(sig.sz[2]) && isalnum(sig.sz[3]))
{ {
m_DMAList.AddItem(itemIndex, 4, stdstr((char*)sig.sz).ToUTF16().c_str()); m_DMAList.AddItem(itemIndex, 4, stdstr((char *)sig.sz).ToUTF16().c_str());
} }
itemIndex++; itemIndex++;
} }
if (bScrolledDown) if (bScrolledDown)
{ {
m_DMAList.EnsureVisible(m_DMAList.GetItemCount() - 1, FALSE); m_DMAList.EnsureVisible(m_DMAList.GetItemCount() - 1, FALSE);
} }
m_DMAList.SetRedraw(TRUE); m_DMAList.SetRedraw(TRUE);
m_nLastStartIndex = dmaLogSize; m_nLastStartIndex = dmaLogSize;
} }
@ -132,15 +133,15 @@ void CDebugDMALogView::Export(void)
memset(&filePath, 0, sizeof(filePath)); memset(&filePath, 0, sizeof(filePath));
memset(&openfilename, 0, sizeof(openfilename)); memset(&openfilename, 0, sizeof(openfilename));
wsprintf(filePath, L"*.csv"); wsprintf(filePath, L"*.csv");
const TCHAR* filters = ( const TCHAR * filters = (
/*1*/ L"Comma separated values (*.csv)\0*.csv;\0" /*1*/ L"Comma separated values (*.csv)\0*.csv;\0"
/*2*/ L"Plain text (*.txt)\0*.txt;\0" /*2*/ L"Plain text (*.txt)\0*.txt;\0"
); );
const char *extensions[] = { "", ".csv", ".txt" }; const char * extensions[] = {"", ".csv", ".txt"};
openfilename.lStructSize = sizeof(openfilename); openfilename.lStructSize = sizeof(openfilename);
openfilename.hwndOwner = (HWND)m_hWnd; openfilename.hwndOwner = (HWND)m_hWnd;
@ -174,23 +175,23 @@ void CDebugDMALogView::Export(void)
for (size_t nEntry = 0; nEntry < numEntries; nEntry++) for (size_t nEntry = 0; nEntry < numEntries; nEntry++)
{ {
DMALOGENTRY* entry = m_DMALog->GetEntryByIndex(nEntry); DMALOGENTRY * entry = m_DMALog->GetEntryByIndex(nEntry);
file << stdstr_f("0x%08X,0x%08X,0x%08X\r\n", file << stdstr_f("0x%08X,0x%08X,0x%08X\r\n",
entry->romAddr, entry->ramAddr, entry->length); entry->romAddr, entry->ramAddr, entry->length);
} }
file.close(); file.close();
} }
} }
LRESULT CDebugDMALogView::OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugDMALogView::OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
//RefreshList(); //RefreshList();
return FALSE; return FALSE;
} }
LRESULT CDebugDMALogView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugDMALogView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
DlgResize_Init(false, true); DlgResize_Init(false, true);
DlgSavePos_Init(DebuggerUI_DMALogPos); DlgSavePos_Init(DebuggerUI_DMALogPos);
@ -219,7 +220,7 @@ LRESULT CDebugDMALogView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
//m_DMAList.SetColumnWidth(3, 50); //m_DMAList.SetColumnWidth(3, 50);
//m_DMAList.SetColumnWidth(4, 50); //m_DMAList.SetColumnWidth(4, 50);
//m_DMAList.SetColumnWidth(5, 50); //m_DMAList.SetColumnWidth(5, 50);
m_DMARamEdit.SetLimitText(8); m_DMARamEdit.SetLimitText(8);
m_DMARomEdit.SetLimitText(8); m_DMARomEdit.SetLimitText(8);
@ -245,7 +246,7 @@ void CDebugDMALogView::RefreshDMALogWindow(bool bReset)
PostMessage(WM_REFRESH, bReset); PostMessage(WM_REFRESH, bReset);
} }
LRESULT CDebugDMALogView::OnRefresh(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugDMALogView::OnRefresh(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
bool bReset = (wParam != 0); bool bReset = (wParam != 0);
@ -273,7 +274,7 @@ LRESULT CDebugDMALogView::OnDestroy(void)
return 0; return 0;
} }
LRESULT CDebugDMALogView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& /*bHandled*/) LRESULT CDebugDMALogView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL & /*bHandled*/)
{ {
switch (wID) switch (wID)
{ {
@ -294,7 +295,7 @@ LRESULT CDebugDMALogView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL&
return FALSE; return FALSE;
} }
LRESULT CDebugDMALogView::OnRamAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CDebugDMALogView::OnRamAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
if (m_bConvertingAddress) if (m_bConvertingAddress)
{ {
@ -317,14 +318,14 @@ LRESULT CDebugDMALogView::OnRamAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, H
szRomAddr = "????????"; szRomAddr = "????????";
m_BlockInfo.SetWindowText(L"Block: ?"); m_BlockInfo.SetWindowText(L"Block: ?");
} }
m_bConvertingAddress = true; m_bConvertingAddress = true;
m_DMARomEdit.SetWindowText(szRomAddr.ToUTF16().c_str()); m_DMARomEdit.SetWindowText(szRomAddr.ToUTF16().c_str());
m_bConvertingAddress = false; m_bConvertingAddress = false;
return FALSE; return FALSE;
} }
LRESULT CDebugDMALogView::OnRomAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CDebugDMALogView::OnRomAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
if (m_bConvertingAddress) if (m_bConvertingAddress)
{ {
@ -334,7 +335,7 @@ LRESULT CDebugDMALogView::OnRomAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, H
stdstr szRamAddr = GetCWindowText(m_DMARomEdit); stdstr szRamAddr = GetCWindowText(m_DMARomEdit);
uint32_t romAddr = strtoul(szRamAddr.c_str(), nullptr, 16); uint32_t romAddr = strtoul(szRamAddr.c_str(), nullptr, 16);
uint32_t ramAddr, offset; uint32_t ramAddr, offset;
DMALOGENTRY* lpEntry = m_DMALog->GetEntryByRomAddress(romAddr, &ramAddr, &offset); DMALOGENTRY * lpEntry = m_DMALog->GetEntryByRomAddress(romAddr, &ramAddr, &offset);
if (lpEntry != nullptr) if (lpEntry != nullptr)
{ {
@ -354,10 +355,9 @@ LRESULT CDebugDMALogView::OnRomAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, H
return FALSE; return FALSE;
} }
LRESULT CDebugDMALogView::OnCustomDrawList(NMHDR * pNMHDR)
LRESULT CDebugDMALogView::OnCustomDrawList(NMHDR* pNMHDR)
{ {
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR); NMLVCUSTOMDRAW * pLVCD = reinterpret_cast<NMLVCUSTOMDRAW *>(pNMHDR);
DWORD drawStage = pLVCD->nmcd.dwDrawStage; DWORD drawStage = pLVCD->nmcd.dwDrawStage;
switch (drawStage) switch (drawStage)
@ -367,7 +367,7 @@ LRESULT CDebugDMALogView::OnCustomDrawList(NMHDR* pNMHDR)
case (CDDS_ITEMPREPAINT | CDDS_SUBITEM): break; case (CDDS_ITEMPREPAINT | CDDS_SUBITEM): break;
default: return CDRF_DODEFAULT; default: return CDRF_DODEFAULT;
} }
DWORD nItem = pLVCD->nmcd.dwItemSpec; DWORD nItem = pLVCD->nmcd.dwItemSpec;
DWORD nSubItem = pLVCD->iSubItem; DWORD nSubItem = pLVCD->iSubItem;
@ -375,19 +375,19 @@ LRESULT CDebugDMALogView::OnCustomDrawList(NMHDR* pNMHDR)
{ {
return CDRF_DODEFAULT; return CDRF_DODEFAULT;
} }
size_t nEntries = m_DMALog->GetNumEntries(); size_t nEntries = m_DMALog->GetNumEntries();
if (nEntries == 0) if (nEntries == 0)
{ {
return CDRF_DODEFAULT; return CDRF_DODEFAULT;
} }
DMALOGENTRY* lpEntry = m_DMALog->GetEntryByIndex(nItem); DMALOGENTRY * lpEntry = m_DMALog->GetEntryByIndex(nItem);
if (nItem >= 1) // Continuation if (nItem >= 1) // Continuation
{ {
DMALOGENTRY* lpPrevEntry = m_DMALog->GetEntryByIndex(nItem - 1); DMALOGENTRY * lpPrevEntry = m_DMALog->GetEntryByIndex(nItem - 1);
if (lpEntry->romAddr == lpPrevEntry->romAddr + lpPrevEntry->length) if (lpEntry->romAddr == lpPrevEntry->romAddr + lpPrevEntry->length)
{ {
@ -398,7 +398,7 @@ LRESULT CDebugDMALogView::OnCustomDrawList(NMHDR* pNMHDR)
if (nEntries >= 2 && nItem <= nEntries - 2) // Head if (nEntries >= 2 && nItem <= nEntries - 2) // Head
{ {
DMALOGENTRY* lpNextEntry = m_DMALog->GetEntryByIndex(nItem + 1); DMALOGENTRY * lpNextEntry = m_DMALog->GetEntryByIndex(nItem + 1);
if (lpNextEntry->romAddr == lpEntry->romAddr + lpEntry->length) if (lpNextEntry->romAddr == lpEntry->romAddr + lpEntry->length)
{ {
@ -406,6 +406,6 @@ LRESULT CDebugDMALogView::OnCustomDrawList(NMHDR* pNMHDR)
return CDRF_DODEFAULT; return CDRF_DODEFAULT;
} }
} }
return CDRF_DODEFAULT; return CDRF_DODEFAULT;
} }

View File

@ -1,6 +1,4 @@
#pragma once #pragma once
#include <stdafx.h>
#include "DebuggerUI.h" #include "DebuggerUI.h"
class CDebugDMALogView : class CDebugDMALogView :

View File

@ -1,61 +1,62 @@
#include "stdafx.h" #include "stdafx.h"
#include "DebuggerUI.h" #include "DebuggerUI.h"
CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::ExcCheckboxMap[] = { CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::ExcCheckboxMap[] = {
{ IDC_CHK_INT, 0 }, {IDC_CHK_INT, 0},
{ IDC_CHK_MOD, 1 }, {IDC_CHK_MOD, 1},
{ IDC_CHK_RMISS, 2 }, {IDC_CHK_RMISS, 2},
{ IDC_CHK_WMISS, 3 }, {IDC_CHK_WMISS, 3},
{ IDC_CHK_RADE, 4 }, {IDC_CHK_RADE, 4},
{ IDC_CHK_WADE, 5 }, {IDC_CHK_WADE, 5},
{ IDC_CHK_IBE, 6 }, {IDC_CHK_IBE, 6},
{ IDC_CHK_DBE, 7 }, {IDC_CHK_DBE, 7},
{ IDC_CHK_SYSCALL, 8 }, {IDC_CHK_SYSCALL, 8},
{ IDC_CHK_BREAK, 9 }, {IDC_CHK_BREAK, 9},
{ IDC_CHK_II, 10 }, {IDC_CHK_II, 10},
{ IDC_CHK_CPU, 11 }, {IDC_CHK_CPU, 11},
{ IDC_CHK_OV, 12 }, {IDC_CHK_OV, 12},
{ IDC_CHK_TRAP, 13 }, {IDC_CHK_TRAP, 13},
{ IDC_CHK_VCEI, 14 }, {IDC_CHK_VCEI, 14},
{ IDC_CHK_FPE, 15 }, {IDC_CHK_FPE, 15},
{ IDC_CHK_WATCH, 23 }, {IDC_CHK_WATCH, 23},
{ IDC_CHK_VCED, 31 }, {IDC_CHK_VCED, 31},
{ 0, 0 } { 0, 0 }
}; };
CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::FpExcCheckboxMap[] = { CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::FpExcCheckboxMap[] = {
{ IDC_CHK_FP_CI, (1 << 0) }, {IDC_CHK_FP_CI, (1 << 0)},
{ IDC_CHK_FP_CU, (1 << 1) }, {IDC_CHK_FP_CU, (1 << 1)},
{ IDC_CHK_FP_CO, (1 << 2) }, {IDC_CHK_FP_CO, (1 << 2)},
{ IDC_CHK_FP_CZ, (1 << 3) }, {IDC_CHK_FP_CZ, (1 << 3)},
{ IDC_CHK_FP_CV, (1 << 4) }, {IDC_CHK_FP_CV, (1 << 4)},
{ IDC_CHK_FP_CE, (1 << 5) }, {IDC_CHK_FP_CE, (1 << 5)},
{ 0, 0 } { 0, 0 }
}; };
CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::IntrCheckboxMap[] = { CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::IntrCheckboxMap[] = {
{ IDC_CHK_INTR_IP0, (1 << 0) }, {IDC_CHK_INTR_IP0, (1 << 0)},
{ IDC_CHK_INTR_IP1, (1 << 1) }, {IDC_CHK_INTR_IP1, (1 << 1)},
{ IDC_CHK_INTR_IP2, (1 << 2) }, {IDC_CHK_INTR_IP2, (1 << 2)},
{ IDC_CHK_INTR_IP3, (1 << 3) }, {IDC_CHK_INTR_IP3, (1 << 3)},
{ IDC_CHK_INTR_IP4, (1 << 4) }, {IDC_CHK_INTR_IP4, (1 << 4)},
{ IDC_CHK_INTR_IP5, (1 << 5) }, {IDC_CHK_INTR_IP5, (1 << 5)},
{ IDC_CHK_INTR_IP6, (1 << 6) }, {IDC_CHK_INTR_IP6, (1 << 6)},
{ IDC_CHK_INTR_IP7, (1 << 7) }, {IDC_CHK_INTR_IP7, (1 << 7)},
{ 0, 0 } { 0, 0 }
}; };
CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::RcpIntrCheckboxMap[] = { CDebugExcBreakpoints::ExcCheckboxMeta CDebugExcBreakpoints::RcpIntrCheckboxMap[] = {
{ IDC_CHK_INTR_SP, (1 << 0) }, {IDC_CHK_INTR_SP, (1 << 0)},
{ IDC_CHK_INTR_SI, (1 << 1) }, {IDC_CHK_INTR_SI, (1 << 1)},
{ IDC_CHK_INTR_AI, (1 << 2) }, {IDC_CHK_INTR_AI, (1 << 2)},
{ IDC_CHK_INTR_VI, (1 << 3) }, {IDC_CHK_INTR_VI, (1 << 3)},
{ IDC_CHK_INTR_PI, (1 << 4) }, {IDC_CHK_INTR_PI, (1 << 4)},
{ IDC_CHK_INTR_DP, (1 << 5) }, {IDC_CHK_INTR_DP, (1 << 5)},
{ 0, 0 } { 0, 0 }
}; };
CDebugExcBreakpoints::CDebugExcBreakpoints(CDebuggerUI* debugger) : CDebugExcBreakpoints::CDebugExcBreakpoints(CDebuggerUI * debugger) :
CDebugDialog<CDebugExcBreakpoints>(debugger) CDebugDialog<CDebugExcBreakpoints>(debugger)
{ {
} }
@ -64,7 +65,7 @@ CDebugExcBreakpoints::~CDebugExcBreakpoints()
{ {
} }
LRESULT CDebugExcBreakpoints::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugExcBreakpoints::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
DlgSavePos_Init(DebuggerUI_ExceptionBPPos); DlgSavePos_Init(DebuggerUI_ExceptionBPPos);
@ -94,7 +95,7 @@ LRESULT CDebugExcBreakpoints::OnDestroy(void)
return 0; return 0;
} }
LRESULT CDebugExcBreakpoints::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& /*bHandled*/) LRESULT CDebugExcBreakpoints::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL & /*bHandled*/)
{ {
switch (wID) switch (wID)
{ {
@ -112,7 +113,7 @@ LRESULT CDebugExcBreakpoints::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BO
bool toggleRcpIntr = bChecked && (g_Settings->LoadDword(Debugger_IntrBreakpoints) & 0x04); bool toggleRcpIntr = bChecked && (g_Settings->LoadDword(Debugger_IntrBreakpoints) & 0x04);
EnableCheckboxes(RcpIntrCheckboxMap, toggleRcpIntr); EnableCheckboxes(RcpIntrCheckboxMap, toggleRcpIntr);
} }
if (wID == IDC_CHK_FPE) if (wID == IDC_CHK_FPE)
{ {
EnableCheckboxes(FpExcCheckboxMap, bChecked); EnableCheckboxes(FpExcCheckboxMap, bChecked);
@ -136,7 +137,7 @@ void CDebugExcBreakpoints::OnExitSizeMove(void)
SaveWindowPos(0); SaveWindowPos(0);
} }
void CDebugExcBreakpoints::InitCheckboxes(ExcCheckboxMeta* checkboxMap, SettingID settingID, bool bShift) void CDebugExcBreakpoints::InitCheckboxes(ExcCheckboxMeta * checkboxMap, SettingID settingID, bool bShift)
{ {
uint32_t excBits = g_Settings->LoadDword(settingID); uint32_t excBits = g_Settings->LoadDword(settingID);
@ -151,7 +152,7 @@ void CDebugExcBreakpoints::InitCheckboxes(ExcCheckboxMeta* checkboxMap, SettingI
} }
} }
void CDebugExcBreakpoints::UpdateBpSetting(ExcCheckboxMeta* checkboxMap, SettingID settingID, WORD wID, bool bChecked, bool bShift) void CDebugExcBreakpoints::UpdateBpSetting(ExcCheckboxMeta * checkboxMap, SettingID settingID, WORD wID, bool bChecked, bool bShift)
{ {
for (int i = 0; checkboxMap[i].ctrlId != 0; i++) for (int i = 0; checkboxMap[i].ctrlId != 0; i++)
{ {
@ -175,7 +176,7 @@ void CDebugExcBreakpoints::UpdateBpSetting(ExcCheckboxMeta* checkboxMap, Setting
} }
} }
void CDebugExcBreakpoints::EnableCheckboxes(ExcCheckboxMeta* checkboxMap, bool bEnable) void CDebugExcBreakpoints::EnableCheckboxes(ExcCheckboxMeta * checkboxMap, bool bEnable)
{ {
for (int i = 0; checkboxMap[i].ctrlId != 0; i++) for (int i = 0; checkboxMap[i].ctrlId != 0; i++)
{ {

View File

@ -1,6 +1,4 @@
#pragma once #pragma once
#include <stdafx.h>
#include "DebuggerUI.h" #include "DebuggerUI.h"

View File

@ -5,7 +5,7 @@
#include <Project64-core/N64System/Mips/R4300iInstruction.h> #include <Project64-core/N64System/Mips/R4300iInstruction.h>
CDumpMemory::CDumpMemory(CDebuggerUI * debugger) : CDumpMemory::CDumpMemory(CDebuggerUI * debugger) :
CDebugDialog<CDumpMemory>(debugger) CDebugDialog<CDumpMemory>(debugger)
{ {
} }
@ -13,7 +13,7 @@ CDumpMemory::~CDumpMemory()
{ {
} }
LRESULT CDumpMemory::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDumpMemory::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
DlgSavePos_Init(DebuggerUI_MemoryDumpPos); DlgSavePos_Init(DebuggerUI_MemoryDumpPos);
@ -33,7 +33,7 @@ LRESULT CDumpMemory::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lPa
m_StartAddress.SetValue(startAddress, DisplayMode::AllHex); m_StartAddress.SetValue(startAddress, DisplayMode::AllHex);
m_EndAddress.SetValue(endAddress, DisplayMode::AllHex); m_EndAddress.SetValue(endAddress, DisplayMode::AllHex);
m_PC.SetValue(startAddress); m_PC.SetValue(startAddress);
int nIndex = m_FormatList.AddString(L"TEXT - Disassembly + PC"); int nIndex = m_FormatList.AddString(L"TEXT - Disassembly + PC");
m_FormatList.SetItemData(nIndex, (DWORD_PTR)DisassemblyWithPC); m_FormatList.SetItemData(nIndex, (DWORD_PTR)DisassemblyWithPC);
@ -52,7 +52,7 @@ void CDumpMemory::OnExitSizeMove(void)
SaveWindowPos(0); SaveWindowPos(0);
} }
LRESULT CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
switch (wID) switch (wID)
{ {
@ -66,7 +66,7 @@ LRESULT CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/,
int CurrentFormatSel = m_FormatList.GetCurSel(); int CurrentFormatSel = m_FormatList.GetCurSel();
DumpFormat Format = (DumpFormat)m_FormatList.GetItemData(CurrentFormatSel); DumpFormat Format = (DumpFormat)m_FormatList.GetItemData(CurrentFormatSel);
const char* FileFilter = "All files (*.*)\0*.*\0"; const char * FileFilter = "All files (*.*)\0*.*\0";
if (Format == RawBigEndian) if (Format == RawBigEndian)
{ {
@ -78,7 +78,7 @@ LRESULT CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/,
} }
CPath FileName; CPath FileName;
if (FileName.SelectFile(m_hWnd, CPath(CPath::MODULE_DIRECTORY), FileFilter, false)) if (FileName.SelectFile(m_hWnd, CPath(CPath::MODULE_DIRECTORY), FileFilter, false))
{ {
if (FileName.GetExtension().length() == 0) if (FileName.GetExtension().length() == 0)
@ -94,8 +94,8 @@ LRESULT CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/,
{ {
TCHAR FileName[MAX_PATH]; TCHAR FileName[MAX_PATH];
int CurrentFormatSel = m_FormatList.GetCurSel(); int CurrentFormatSel = m_FormatList.GetCurSel();
DumpFormat Format = (DumpFormat) m_FormatList.GetItemData(CurrentFormatSel); DumpFormat Format = (DumpFormat)m_FormatList.GetItemData(CurrentFormatSel);
DWORD StartPC = m_StartAddress.GetValue(); DWORD StartPC = m_StartAddress.GetValue();
DWORD EndPC = m_EndAddress.GetValue(); DWORD EndPC = m_EndAddress.GetValue();
DWORD DumpPC = m_PC.GetValue(); DWORD DumpPC = m_PC.GetValue();
@ -129,8 +129,8 @@ LRESULT CDumpMemory::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/,
} }
g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_DumpMemory); g_BaseSystem->ExternalEvent(SysEvent_ResumeCPU_DumpMemory);
} }
EndDialog(0); EndDialog(0);
break; break;
} }
return FALSE; return FALSE;
} }

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#include "stdafx.h"
struct FieldPair struct FieldPair
{ {

View File

@ -4,7 +4,7 @@
#include "OpInfo.h" #include "OpInfo.h"
bool CRegisterTabs::m_bColorsEnabled = false; bool CRegisterTabs::m_bColorsEnabled = false;
CDebuggerUI* CRegisterTabs::m_Debugger = nullptr; CDebuggerUI * CRegisterTabs::m_Debugger = nullptr;
CRegisterTabs::CRegisterTabs() : CRegisterTabs::CRegisterTabs() :
m_attached(false) m_attached(false)
@ -15,7 +15,7 @@ CRegisterTabs::~CRegisterTabs()
{ {
} }
void CRegisterTabs::Attach(HWND hWndNew, CDebuggerUI* debugger) void CRegisterTabs::Attach(HWND hWndNew, CDebuggerUI * debugger)
{ {
m_Debugger = debugger; m_Debugger = debugger;
CTabCtrl::Attach(hWndNew); CTabCtrl::Attach(hWndNew);
@ -154,7 +154,7 @@ void CRegisterTabs::RefreshEdits()
CAUSE cause; CAUSE cause;
cause.intval = (uint32_t)g_Reg->CAUSE_REGISTER; cause.intval = (uint32_t)g_Reg->CAUSE_REGISTER;
const char* szExceptionCode = ExceptionCodes[cause.exceptionCode]; const char * szExceptionCode = ExceptionCodes[cause.exceptionCode];
m_CauseTip.SetWindowText(stdstr(szExceptionCode).ToUTF16().c_str()); m_CauseTip.SetWindowText(stdstr(szExceptionCode).ToUTF16().c_str());
m_RDRAMEdits[0].SetValue(g_Reg->RDRAM_CONFIG_REG, DisplayMode::ZeroExtend); // or device type m_RDRAMEdits[0].SetValue(g_Reg->RDRAM_CONFIG_REG, DisplayMode::ZeroExtend); // or device type
@ -305,22 +305,22 @@ void CRegisterTabs::RegisterChanged(HWND hDlg, TAB_ID srcTabId, WPARAM wParam)
} }
int nReg = TabData::FPR.GetEditIndex(ctrlId); int nReg = TabData::FPR.GetEditIndex(ctrlId);
*(uint32_t*)g_Reg->m_FPR_S[nReg] = value; *(uint32_t *)g_Reg->m_FPR_S[nReg] = value;
return; return;
} }
switch (ctrlId) switch (ctrlId)
{ {
case IDC_COP0_0_EDIT: g_Reg->INDEX_REGISTER = value; break; case IDC_COP0_0_EDIT: g_Reg->INDEX_REGISTER = value; break;
case IDC_COP0_1_EDIT: g_Reg->RANDOM_REGISTER = value; break; case IDC_COP0_1_EDIT: g_Reg->RANDOM_REGISTER = value; break;
case IDC_COP0_2_EDIT: g_Reg->ENTRYLO0_REGISTER = value; break; case IDC_COP0_2_EDIT: g_Reg->ENTRYLO0_REGISTER = value; break;
case IDC_COP0_3_EDIT: g_Reg->ENTRYLO1_REGISTER = value; break; case IDC_COP0_3_EDIT: g_Reg->ENTRYLO1_REGISTER = value; break;
case IDC_COP0_4_EDIT: g_Reg->CONTEXT_REGISTER.Value = value; break; case IDC_COP0_4_EDIT: g_Reg->CONTEXT_REGISTER.Value = value; break;
case IDC_COP0_5_EDIT: g_Reg->PAGE_MASK_REGISTER = value; break; case IDC_COP0_5_EDIT: g_Reg->PAGE_MASK_REGISTER = value; break;
case IDC_COP0_6_EDIT: g_Reg->WIRED_REGISTER = value; break; case IDC_COP0_6_EDIT: g_Reg->WIRED_REGISTER = value; break;
case IDC_COP0_7_EDIT: g_Reg->BAD_VADDR_REGISTER = value; break; case IDC_COP0_7_EDIT: g_Reg->BAD_VADDR_REGISTER = value; break;
case IDC_COP0_8_EDIT: g_Reg->COUNT_REGISTER = value; break; case IDC_COP0_8_EDIT: g_Reg->COUNT_REGISTER = value; break;
case IDC_COP0_9_EDIT: g_Reg->ENTRYHI_REGISTER = value; break; case IDC_COP0_9_EDIT: g_Reg->ENTRYHI_REGISTER = value; break;
case IDC_COP0_10_EDIT: g_Reg->COMPARE_REGISTER = value; break; case IDC_COP0_10_EDIT: g_Reg->COMPARE_REGISTER = value; break;
case IDC_COP0_11_EDIT: g_Reg->STATUS_REGISTER = value; break; case IDC_COP0_11_EDIT: g_Reg->STATUS_REGISTER = value; break;
case IDC_COP0_12_EDIT: g_Reg->CAUSE_REGISTER = value; break; case IDC_COP0_12_EDIT: g_Reg->CAUSE_REGISTER = value; break;
@ -342,14 +342,14 @@ void CRegisterTabs::RegisterChanged(HWND hDlg, TAB_ID srcTabId, WPARAM wParam)
case IDC_RDRAM20_EDIT: g_Reg->RDRAM_ADDR_SELECT_REG = value; break; case IDC_RDRAM20_EDIT: g_Reg->RDRAM_ADDR_SELECT_REG = value; break;
case IDC_RDRAM24_EDIT: g_Reg->RDRAM_DEVICE_MANUF_REG = value; break; case IDC_RDRAM24_EDIT: g_Reg->RDRAM_DEVICE_MANUF_REG = value; break;
case IDC_SP00_EDIT: g_Reg->SP_MEM_ADDR_REG = value; break; case IDC_SP00_EDIT: g_Reg->SP_MEM_ADDR_REG = value; break;
case IDC_SP04_EDIT: g_Reg->SP_DRAM_ADDR_REG = value; break; case IDC_SP04_EDIT: g_Reg->SP_DRAM_ADDR_REG = value; break;
case IDC_SP08_EDIT: g_Reg->SP_RD_LEN_REG = value; break; case IDC_SP08_EDIT: g_Reg->SP_RD_LEN_REG = value; break;
case IDC_SP0C_EDIT: g_Reg->SP_WR_LEN_REG = value; break; case IDC_SP0C_EDIT: g_Reg->SP_WR_LEN_REG = value; break;
case IDC_SP10_EDIT: g_Reg->SP_STATUS_REG = value; break; case IDC_SP10_EDIT: g_Reg->SP_STATUS_REG = value; break;
case IDC_SP14_EDIT: g_Reg->SP_DMA_FULL_REG = value; break; case IDC_SP14_EDIT: g_Reg->SP_DMA_FULL_REG = value; break;
case IDC_SP18_EDIT: g_Reg->SP_DMA_BUSY_REG = value; break; case IDC_SP18_EDIT: g_Reg->SP_DMA_BUSY_REG = value; break;
case IDC_SP1C_EDIT: g_Reg->SP_SEMAPHORE_REG = value; break; case IDC_SP1C_EDIT: g_Reg->SP_SEMAPHORE_REG = value; break;
case IDC_SP_PC_EDIT: g_Reg->SP_PC_REG = value; break; case IDC_SP_PC_EDIT: g_Reg->SP_PC_REG = value; break;
case IDC_DPC00_EDIT: g_Reg->DPC_START_REG = value; break; case IDC_DPC00_EDIT: g_Reg->DPC_START_REG = value; break;
@ -362,8 +362,8 @@ void CRegisterTabs::RegisterChanged(HWND hDlg, TAB_ID srcTabId, WPARAM wParam)
case IDC_DPC1C_EDIT: g_Reg->DPC_TMEM_REG = value; break; case IDC_DPC1C_EDIT: g_Reg->DPC_TMEM_REG = value; break;
case IDC_MI00_EDIT: g_Reg->MI_INIT_MODE_REG = value; break; // or MI_MODE ? case IDC_MI00_EDIT: g_Reg->MI_INIT_MODE_REG = value; break; // or MI_MODE ?
case IDC_MI04_EDIT: g_Reg->MI_VERSION_REG = value; break; // or MI_NOOP ? case IDC_MI04_EDIT: g_Reg->MI_VERSION_REG = value; break; // or MI_NOOP ?
case IDC_MI08_EDIT: g_Reg->MI_INTR_REG = value; break; // or MI_INTR ? case IDC_MI08_EDIT: g_Reg->MI_INTR_REG = value; break; // or MI_INTR ?
case IDC_MI0C_EDIT: g_Reg->MI_INTR_MASK_REG = value; break; // or MI_INTR_MASK ? case IDC_MI0C_EDIT: g_Reg->MI_INTR_MASK_REG = value; break; // or MI_INTR_MASK ?
case IDC_VI00_EDIT: g_Reg->VI_STATUS_REG = value; break; case IDC_VI00_EDIT: g_Reg->VI_STATUS_REG = value; break;
@ -481,7 +481,7 @@ INT_PTR CALLBACK CRegisterTabs::TabProcGPR(HWND hDlg, UINT msg, WPARAM wParam, L
} }
HWND hWnd = (HWND)lParam; HWND hWnd = (HWND)lParam;
WORD ctrlId = (WORD) ::GetWindowLong(hWnd, GWL_ID); WORD ctrlId = (WORD)::GetWindowLong(hWnd, GWL_ID);
COpInfo opInfo; COpInfo opInfo;
m_Debugger->DebugLoad_VAddr(g_Reg->m_PROGRAM_COUNTER, opInfo.m_OpCode.Value); m_Debugger->DebugLoad_VAddr(g_Reg->m_PROGRAM_COUNTER, opInfo.m_OpCode.Value);
@ -555,9 +555,9 @@ INT_PTR CALLBACK CRegisterTabs::TabProcGPR(HWND hDlg, UINT msg, WPARAM wParam, L
} }
HWND hWnd = (HWND)wParam; HWND hWnd = (HWND)wParam;
WORD ctrlId = (WORD) ::GetWindowLong(hWnd, GWL_ID); WORD ctrlId = (WORD)::GetWindowLong(hWnd, GWL_ID);
CBreakpoints* breakpoints = m_Debugger->Breakpoints(); CBreakpoints * breakpoints = m_Debugger->Breakpoints();
if (ctrlId == IDC_HI_LBL) if (ctrlId == IDC_HI_LBL)
{ {
@ -594,7 +594,7 @@ INT_PTR CALLBACK CRegisterTabs::TabProcGPR(HWND hDlg, UINT msg, WPARAM wParam, L
HWND hWnd = (HWND)lParam; HWND hWnd = (HWND)lParam;
WORD ctrlId = LOWORD(wParam); WORD ctrlId = LOWORD(wParam);
CBreakpoints* breakpoints = m_Debugger->Breakpoints(); CBreakpoints * breakpoints = m_Debugger->Breakpoints();
if (ctrlId == IDC_HI_LBL) if (ctrlId == IDC_HI_LBL)
{ {
@ -629,8 +629,7 @@ INT_PTR CALLBACK CRegisterTabs::TabProcGPR(HWND hDlg, UINT msg, WPARAM wParam, L
} }
HWND hWnd = (HWND)lParam; HWND hWnd = (HWND)lParam;
WORD ctrlId = (WORD) ::GetWindowLong(hWnd, GWL_ID); WORD ctrlId = (WORD)::GetWindowLong(hWnd, GWL_ID);
HDC hdc = (HDC)wParam; HDC hdc = (HDC)wParam;
@ -638,8 +637,8 @@ INT_PTR CALLBACK CRegisterTabs::TabProcGPR(HWND hDlg, UINT msg, WPARAM wParam, L
COLORREF colorWrite = RGB(255, 200, 200); COLORREF colorWrite = RGB(255, 200, 200);
COLORREF colorBoth = RGB(220, 170, 255); COLORREF colorBoth = RGB(220, 170, 255);
CBreakpoints* breakpoints = m_Debugger->Breakpoints(); CBreakpoints * breakpoints = m_Debugger->Breakpoints();
bool haveRead, haveWrite; bool haveRead, haveWrite;
if (ctrlId == IDC_HI_LBL) if (ctrlId == IDC_HI_LBL)
@ -669,11 +668,11 @@ INT_PTR CALLBACK CRegisterTabs::TabProcGPR(HWND hDlg, UINT msg, WPARAM wParam, L
{ {
SetBkColor(hdc, colorBoth); SetBkColor(hdc, colorBoth);
} }
else if(haveRead) else if (haveRead)
{ {
SetBkColor(hdc, colorRead); SetBkColor(hdc, colorRead);
} }
else if(haveWrite) else if (haveWrite)
{ {
SetBkColor(hdc, colorWrite); SetBkColor(hdc, colorWrite);
} }
@ -684,7 +683,7 @@ INT_PTR CALLBACK CRegisterTabs::TabProcGPR(HWND hDlg, UINT msg, WPARAM wParam, L
return (LRESULT)GetStockObject(DC_BRUSH); return (LRESULT)GetStockObject(DC_BRUSH);
} }
return FALSE; return FALSE;
} }
@ -716,7 +715,7 @@ CRect CRegisterTabs::GetPageRect()
return pageRect; return pageRect;
} }
CWindow CRegisterTabs::AddTab(char* caption, int dialogId, DLGPROC dlgProc) CWindow CRegisterTabs::AddTab(char * caption, int dialogId, DLGPROC dlgProc)
{ {
AddItem(stdstr(caption).ToUTF16().c_str()); AddItem(stdstr(caption).ToUTF16().c_str());
@ -774,13 +773,13 @@ void CRegisterTabs::SetColorsEnabled(bool bColorsEnabled)
m_bColorsEnabled = bColorsEnabled; m_bColorsEnabled = bColorsEnabled;
} }
void CRegisterTabs::InitRegisterEdit(CWindow& tab, CEditNumber32& edit, FieldPair ctrl) void CRegisterTabs::InitRegisterEdit(CWindow & tab, CEditNumber32 & edit, FieldPair ctrl)
{ {
edit.Attach(tab.GetDlgItem(ctrl.EditId)); edit.Attach(tab.GetDlgItem(ctrl.EditId));
edit.SetDisplayType(CEditNumber32::DisplayHex); edit.SetDisplayType(CEditNumber32::DisplayHex);
} }
void CRegisterTabs::InitRegisterEdits(CWindow& tab, CEditNumber32* edits, const TabRecord* ctrlIds) void CRegisterTabs::InitRegisterEdits(CWindow & tab, CEditNumber32 * edits, const TabRecord * ctrlIds)
{ {
for (int i = 0, n = ctrlIds->FieldCount; i < n; i++) for (int i = 0, n = ctrlIds->FieldCount; i < n; i++)
{ {
@ -788,12 +787,12 @@ void CRegisterTabs::InitRegisterEdits(CWindow& tab, CEditNumber32* edits, const
} }
} }
void CRegisterTabs::InitRegisterEdit64(CWindow& tab, CEditReg64& edit, FieldPair ctrl) void CRegisterTabs::InitRegisterEdit64(CWindow & tab, CEditReg64 & edit, FieldPair ctrl)
{ {
edit.Attach(tab.GetDlgItem(ctrl.EditId)); edit.Attach(tab.GetDlgItem(ctrl.EditId));
} }
void CRegisterTabs::InitRegisterEdits64(CWindow& tab, CEditReg64* edits, const TabRecord* ctrlIds) void CRegisterTabs::InitRegisterEdits64(CWindow & tab, CEditReg64 * edits, const TabRecord * ctrlIds)
{ {
for (int i = 0, n = ctrlIds->FieldCount; i < n; i++) for (int i = 0, n = ctrlIds->FieldCount; i < n; i++)
{ {
@ -801,12 +800,12 @@ void CRegisterTabs::InitRegisterEdits64(CWindow& tab, CEditReg64* edits, const T
} }
} }
void CRegisterTabs::ZeroRegisterEdit(CEditNumber32& edit) void CRegisterTabs::ZeroRegisterEdit(CEditNumber32 & edit)
{ {
edit.SetValue(0, DisplayMode::ZeroExtend); edit.SetValue(0, DisplayMode::ZeroExtend);
} }
void CRegisterTabs::ZeroRegisterEdits(CEditNumber32* edits, uint32_t ctrlIdsCount) void CRegisterTabs::ZeroRegisterEdits(CEditNumber32 * edits, uint32_t ctrlIdsCount)
{ {
for (int i = 0, n = ctrlIdsCount; i < n; i++) for (int i = 0, n = ctrlIdsCount; i < n; i++)
{ {
@ -814,12 +813,12 @@ void CRegisterTabs::ZeroRegisterEdits(CEditNumber32* edits, uint32_t ctrlIdsCoun
} }
} }
void CRegisterTabs::ZeroRegisterEdit64(CEditReg64& edit) void CRegisterTabs::ZeroRegisterEdit64(CEditReg64 & edit)
{ {
edit.SetValue(0); edit.SetValue(0);
} }
void CRegisterTabs::ZeroRegisterEdits64(CEditReg64* edits, uint32_t ctrlIdsCount) void CRegisterTabs::ZeroRegisterEdits64(CEditReg64 * edits, uint32_t ctrlIdsCount)
{ {
for (uint32_t i = 0, n = ctrlIdsCount; i < n; i++) for (uint32_t i = 0, n = ctrlIdsCount; i < n; i++)
{ {
@ -827,12 +826,13 @@ void CRegisterTabs::ZeroRegisterEdits64(CEditReg64* edits, uint32_t ctrlIdsCount
} }
} }
void CRegisterTabs::CopyTabRegisters() { void CRegisterTabs::CopyTabRegisters()
{
int nPage = GetCurSel(); int nPage = GetCurSel();
stdstr str = CopyTabRegisters(nPage); stdstr str = CopyTabRegisters(nPage);
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.length() + 1); HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.length() + 1);
strncpy((char*)GlobalLock(hMem), str.c_str(), str.length()); strncpy((char *)GlobalLock(hMem), str.c_str(), str.length());
GlobalUnlock(hMem); GlobalUnlock(hMem);
OpenClipboard(); OpenClipboard();
EmptyClipboard(); EmptyClipboard();
@ -840,15 +840,17 @@ void CRegisterTabs::CopyTabRegisters() {
CloseClipboard(); CloseClipboard();
} }
void CRegisterTabs::CopyAllRegisters() { void CRegisterTabs::CopyAllRegisters()
{
stdstr str; stdstr str;
for (int i = 0; i <= 12; i++) { for (int i = 0; i <= 12; i++)
{
if (!str.empty()) str += "\r\n"; if (!str.empty()) str += "\r\n";
str += CopyTabRegisters(i); str += CopyTabRegisters(i);
} }
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.length() + 1); HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.length() + 1);
strncpy((char*)GlobalLock(hMem), str.c_str(), str.length()); strncpy((char *)GlobalLock(hMem), str.c_str(), str.length());
GlobalUnlock(hMem); GlobalUnlock(hMem);
OpenClipboard(); OpenClipboard();
EmptyClipboard(); EmptyClipboard();
@ -870,52 +872,52 @@ stdstr CRegisterTabs::CopyTabRegisters(int id)
str += stdstr().FromUTF16(item.pszText); str += stdstr().FromUTF16(item.pszText);
const TabRecord *record = nullptr; const TabRecord * record = nullptr;
switch (id) switch (id)
{ {
case 0: record = &TabData::GPR; break; case 0: record = &TabData::GPR; break;
case 1: record = &TabData::FPR; break; case 1: record = &TabData::FPR; break;
case 2: record = &TabData::COP0; break; case 2: record = &TabData::COP0; break;
case 3: case 3:
record = &TabData::RDRAM; record = &TabData::RDRAM;
str += " (A3F00000)"; str += " (A3F00000)";
break; break;
case 4: case 4:
record = &TabData::SP; record = &TabData::SP;
str += " (A4040000)"; str += " (A4040000)";
break; break;
case 5: case 5:
record = &TabData::DPC; record = &TabData::DPC;
str += " (A4100000)"; str += " (A4100000)";
break; break;
case 6: case 6:
record = &TabData::MI; record = &TabData::MI;
str += " (A4300000)"; str += " (A4300000)";
break; break;
case 7: case 7:
record = &TabData::VI; record = &TabData::VI;
str += " (A4400000)"; str += " (A4400000)";
break; break;
case 8: case 8:
record = &TabData::AI; record = &TabData::AI;
str += " (A4500000)"; str += " (A4500000)";
break; break;
case 9: case 9:
record = &TabData::PI; record = &TabData::PI;
str += " (A4600000)"; str += " (A4600000)";
break; break;
case 10: case 10:
record = &TabData::RI; record = &TabData::RI;
str += " (A4700000)"; str += " (A4700000)";
break; break;
case 11: case 11:
record = &TabData::SI; record = &TabData::SI;
str += " (A4800000)"; str += " (A4800000)";
break; break;
case 12: case 12:
record = &TabData::DD; record = &TabData::DD;
str += " (A5000500)"; str += " (A5000500)";
break; break;
} }
record->Iterate(tab, [&str](const CWindow & label, const CWindow & edit) record->Iterate(tab, [&str](const CWindow & label, const CWindow & edit)
@ -925,16 +927,16 @@ stdstr CRegisterTabs::CopyTabRegisters(int id)
switch (id) switch (id)
{ {
case 0: case 0:
str += stdstr_f("\r\nHI %s", GetCWindowText(m_HIEdit).c_str()); str += stdstr_f("\r\nHI %s", GetCWindowText(m_HIEdit).c_str());
str += stdstr_f("\r\nLO %s", GetCWindowText(m_LOEdit).c_str()); str += stdstr_f("\r\nLO %s", GetCWindowText(m_LOEdit).c_str());
break; break;
case 1: case 1:
str += stdstr_f("\r\nFCSR %s", GetCWindowText(m_FCSREdit).c_str()); str += stdstr_f("\r\nFCSR %s", GetCWindowText(m_FCSREdit).c_str());
break; break;
case 4: case 4:
str += stdstr_f("\r\nSP (A4080000)\r\n00 SP_PC %s", GetCWindowText(m_SPPCEdit).c_str()); str += stdstr_f("\r\nSP (A4080000)\r\n00 SP_PC %s", GetCWindowText(m_SPPCEdit).c_str());
break; break;
} }
str += "\r\n"; str += "\r\n";
@ -942,7 +944,7 @@ stdstr CRegisterTabs::CopyTabRegisters(int id)
} }
// CEditReg64 for GPR // CEditReg64 for GPR
uint64_t CEditReg64::ParseValue(const char* wordPair) uint64_t CEditReg64::ParseValue(const char * wordPair)
{ {
uint32_t a, b; uint32_t a, b;
uint64_t ret; uint64_t ret;
@ -964,7 +966,7 @@ BOOL CEditReg64::Attach(HWND hWndNew)
return SubclassWindow(hWndNew); return SubclassWindow(hWndNew);
} }
LRESULT CEditReg64::OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT CEditReg64::OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled)
{ {
bHandled = TRUE; bHandled = TRUE;
if (!isStepping()) if (!isStepping())
@ -1015,7 +1017,7 @@ uint64_t CEditReg64::GetValue()
return ParseValue(GetCWindowText(*this).c_str()); return ParseValue(GetCWindowText(*this).c_str());
} }
LRESULT CEditReg64::OnLostFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) LRESULT CEditReg64::OnLostFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & bHandled)
{ {
SetValue(GetValue()); SetValue(GetValue());
bHandled = FALSE; bHandled = FALSE;

View File

@ -1,7 +1,8 @@
#include "stdafx.h" #include "stdafx.h"
#include "DebuggerUI.h" #include "DebuggerUI.h"
CDebugScripts::CDebugScripts(CDebuggerUI* debugger) : CDebugScripts::CDebugScripts(CDebuggerUI * debugger) :
CDebugDialog<CDebugScripts>(debugger), CDebugDialog<CDebugScripts>(debugger),
CToolTipDialog<CDebugScripts>(), CToolTipDialog<CDebugScripts>(),
m_hQuitScriptDirWatchEvent(nullptr), m_hQuitScriptDirWatchEvent(nullptr),
@ -21,21 +22,21 @@ CDebugScripts::~CDebugScripts(void)
m_InputHistory.clear(); m_InputHistory.clear();
} }
LRESULT CDebugScripts::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugScripts::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
DlgResize_Init(false, true); DlgResize_Init(false, true);
DlgSavePos_Init(DebuggerUI_ScriptsPos); DlgSavePos_Init(DebuggerUI_ScriptsPos);
DlgToolTip_Init(); DlgToolTip_Init();
m_MonoFont = CreateFont(-12, 0, 0, 0, m_MonoFont = CreateFont(-12, 0, 0, 0,
FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, FF_DONTCARE, L"Consolas"); CLEARTYPE_QUALITY, FF_DONTCARE, L"Consolas");
m_MonoBoldFont = CreateFont(-13, 0, 0, 0, m_MonoBoldFont = CreateFont(-13, 0, 0, 0,
FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET, FW_BOLD, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, FF_DONTCARE, L"Consolas"); CLEARTYPE_QUALITY, FF_DONTCARE, L"Consolas");
m_ScriptList.Attach(GetDlgItem(IDC_SCRIPT_LIST)); m_ScriptList.Attach(GetDlgItem(IDC_SCRIPT_LIST));
m_ScriptList.AddColumn(L"Status", 0); m_ScriptList.AddColumn(L"Status", 0);
@ -55,7 +56,7 @@ LRESULT CDebugScripts::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*l
::SendMessage(GetDlgItem(IDC_EVAL_LBL), WM_SETFONT, (WPARAM)m_MonoBoldFont, 0); ::SendMessage(GetDlgItem(IDC_EVAL_LBL), WM_SETFONT, (WPARAM)m_MonoBoldFont, 0);
int statusPaneWidths[] = { -1 }; int statusPaneWidths[] = {-1};
m_StatusBar.Attach(GetDlgItem(IDC_STATUSBAR)); m_StatusBar.Attach(GetDlgItem(IDC_STATUSBAR));
m_StatusBar.SetParts(1, statusPaneWidths); m_StatusBar.SetParts(1, statusPaneWidths);
@ -69,7 +70,7 @@ LRESULT CDebugScripts::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*l
SetTimer(CONFLUSH_TIMER_ID, CONFLUSH_TIMER_INTERVAL, nullptr); SetTimer(CONFLUSH_TIMER_ID, CONFLUSH_TIMER_INTERVAL, nullptr);
m_hQuitScriptDirWatchEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); m_hQuitScriptDirWatchEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
m_hScriptDirWatchThread = CreateThread(nullptr, 0, ScriptDirWatchProc, (void*)this, 0, nullptr); m_hScriptDirWatchThread = CreateThread(nullptr, 0, ScriptDirWatchProc, (void *)this, 0, nullptr);
m_ConOutputEdit.SetWindowText(m_Debugger->ScriptSystem()->GetConsoleBuffer().ToUTF16().c_str()); m_ConOutputEdit.SetWindowText(m_Debugger->ScriptSystem()->GetConsoleBuffer().ToUTF16().c_str());
@ -93,11 +94,11 @@ LRESULT CDebugScripts::OnDestroy(void)
return 0; return 0;
} }
LRESULT CDebugScripts::OnCtlColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) LRESULT CDebugScripts::OnCtlColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/)
{ {
HDC hDC = (HDC)wParam; HDC hDC = (HDC)wParam;
HWND hCtrl = (HWND)lParam; HWND hCtrl = (HWND)lParam;
WORD ctrlId = (WORD) ::GetWindowLong(hCtrl, GWL_ID); WORD ctrlId = (WORD)::GetWindowLong(hCtrl, GWL_ID);
if (ctrlId == IDC_CONSOLE_EDIT) if (ctrlId == IDC_CONSOLE_EDIT)
{ {
@ -110,11 +111,11 @@ LRESULT CDebugScripts::OnCtlColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM lPa
return FALSE; return FALSE;
} }
LRESULT CDebugScripts::OnCtlColorEdit(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) LRESULT CDebugScripts::OnCtlColorEdit(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/)
{ {
HDC hDC = (HDC)wParam; HDC hDC = (HDC)wParam;
HWND hCtrl = (HWND)lParam; HWND hCtrl = (HWND)lParam;
WORD ctrlId = (WORD) ::GetWindowLong(hCtrl, GWL_ID); WORD ctrlId = (WORD)::GetWindowLong(hCtrl, GWL_ID);
if (ctrlId == IDC_EVAL_EDIT) if (ctrlId == IDC_EVAL_EDIT)
{ {
@ -127,9 +128,9 @@ LRESULT CDebugScripts::OnCtlColorEdit(UINT /*uMsg*/, WPARAM wParam, LPARAM lPara
return FALSE; return FALSE;
} }
DWORD WINAPI CDebugScripts::ScriptDirWatchProc(void* ctx) DWORD WINAPI CDebugScripts::ScriptDirWatchProc(void * ctx)
{ {
CDebugScripts* _this = (CDebugScripts*)ctx; CDebugScripts * _this = (CDebugScripts *)ctx;
HANDLE hEvents[2]; HANDLE hEvents[2];
@ -161,7 +162,7 @@ DWORD WINAPI CDebugScripts::ScriptDirWatchProc(void* ctx)
} }
} }
done: done:
FindCloseChangeNotification(hEvents[0]); FindCloseChangeNotification(hEvents[0]);
return 0; return 0;
} }
@ -189,7 +190,7 @@ void CDebugScripts::ConsoleCopy()
return; return;
} }
wchar_t* memBuf = (wchar_t*)GlobalLock(hMem); wchar_t * memBuf = (wchar_t *)GlobalLock(hMem);
if (memBuf == nullptr) if (memBuf == nullptr)
{ {
@ -207,12 +208,12 @@ void CDebugScripts::ConsoleCopy()
CloseClipboard(); CloseClipboard();
} }
void CDebugScripts::ConsolePrint(const char* text) void CDebugScripts::ConsolePrint(const char * text)
{ {
if (m_hWnd != nullptr) if (m_hWnd != nullptr)
{ {
// OnConsolePrint will free this // OnConsolePrint will free this
char* textCopy = _strdup(text); char * textCopy = _strdup(text);
PostMessage(WM_CONSOLE_PRINT, (WPARAM)textCopy); PostMessage(WM_CONSOLE_PRINT, (WPARAM)textCopy);
} }
} }
@ -233,7 +234,7 @@ void CDebugScripts::RefreshList()
} }
} }
LRESULT CDebugScripts::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CDebugScripts::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
switch (wID) switch (wID)
{ {
@ -269,9 +270,9 @@ LRESULT CDebugScripts::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*
return FALSE; return FALSE;
} }
LRESULT CDebugScripts::OnScriptListDblClicked(NMHDR* pNMHDR) LRESULT CDebugScripts::OnScriptListDblClicked(NMHDR * pNMHDR)
{ {
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR); NMITEMACTIVATE * pIA = reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);
int nItem = pIA->iItem; int nItem = pIA->iItem;
if (nItem == -1) if (nItem == -1)
@ -304,13 +305,13 @@ void CDebugScripts::RefreshStatus()
} }
m_ConInputEdit.EnableWindow(FALSE); m_ConInputEdit.EnableWindow(FALSE);
} }
m_StatusBar.SetText(0, statusText.ToUTF16().c_str()); m_StatusBar.SetText(0, statusText.ToUTF16().c_str());
} }
LRESULT CDebugScripts::OnScriptListRClicked(NMHDR* pNMHDR) LRESULT CDebugScripts::OnScriptListRClicked(NMHDR * pNMHDR)
{ {
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR); NMITEMACTIVATE * pIA = reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);
int nItem = pIA->iItem; int nItem = pIA->iItem;
if (nItem == -1) if (nItem == -1)
@ -331,7 +332,7 @@ LRESULT CDebugScripts::OnScriptListRClicked(NMHDR* pNMHDR)
{ {
EnableMenuItem(hPopupMenu, ID_POPUP_STOP, MF_DISABLED | MF_GRAYED); EnableMenuItem(hPopupMenu, ID_POPUP_STOP, MF_DISABLED | MF_GRAYED);
} }
POINT mouse; POINT mouse;
GetCursorPos(&mouse); GetCursorPos(&mouse);
TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN, mouse.x, mouse.y, 0, m_hWnd, nullptr); TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN, mouse.x, mouse.y, 0, m_hWnd, nullptr);
@ -340,9 +341,9 @@ LRESULT CDebugScripts::OnScriptListRClicked(NMHDR* pNMHDR)
return 0; return 0;
} }
LRESULT CDebugScripts::OnScriptListCustomDraw(NMHDR* pNMHDR) LRESULT CDebugScripts::OnScriptListCustomDraw(NMHDR * pNMHDR)
{ {
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR); NMLVCUSTOMDRAW * pLVCD = reinterpret_cast<NMLVCUSTOMDRAW *>(pNMHDR);
DWORD drawStage = pLVCD->nmcd.dwDrawStage; DWORD drawStage = pLVCD->nmcd.dwDrawStage;
switch (drawStage) switch (drawStage)
@ -381,10 +382,10 @@ LRESULT CDebugScripts::OnScriptListCustomDraw(NMHDR* pNMHDR)
return CDRF_DODEFAULT; return CDRF_DODEFAULT;
} }
LRESULT CDebugScripts::OnScriptListItemChanged(NMHDR* pNMHDR) LRESULT CDebugScripts::OnScriptListItemChanged(NMHDR * pNMHDR)
{ {
NMLISTVIEW* lpStateChange = reinterpret_cast<NMLISTVIEW*>(pNMHDR); NMLISTVIEW * lpStateChange = reinterpret_cast<NMLISTVIEW *>(pNMHDR);
if ((lpStateChange->uNewState ^ lpStateChange->uOldState) & LVIS_SELECTED) if ((lpStateChange->uNewState ^ lpStateChange->uOldState) & LVIS_SELECTED)
{ {
if (lpStateChange->iItem == -1) if (lpStateChange->iItem == -1)
{ {
@ -405,22 +406,22 @@ LRESULT CDebugScripts::OnScriptListItemChanged(NMHDR* pNMHDR)
return FALSE; return FALSE;
} }
LRESULT CDebugScripts::OnConsolePrint(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugScripts::OnConsolePrint(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
char *text = (char*)wParam; char * text = (char *)wParam;
m_ConOutputBuffer += text; m_ConOutputBuffer += text;
free(text); free(text);
return FALSE; return FALSE;
} }
LRESULT CDebugScripts::OnConsoleClear(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugScripts::OnConsoleClear(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
m_ConOutputBuffer = ""; m_ConOutputBuffer = "";
m_ConOutputEdit.SetWindowText(L""); m_ConOutputEdit.SetWindowText(L"");
return FALSE; return FALSE;
} }
LRESULT CDebugScripts::OnRefreshList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugScripts::OnRefreshList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
int nIndex = m_ScriptList.GetSelectedIndex(); int nIndex = m_ScriptList.GetSelectedIndex();
CPath searchPath(m_ScriptsDir.c_str(), "*"); CPath searchPath(m_ScriptsDir.c_str(), "*");
@ -439,19 +440,18 @@ LRESULT CDebugScripts::OnRefreshList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*
fileNames.push_back(searchPath.GetNameExtension()); fileNames.push_back(searchPath.GetNameExtension());
} }
} while (searchPath.FindNext()); } while (searchPath.FindNext());
fileNames.sort([](stdstr a, stdstr b) { fileNames.sort([](stdstr a, stdstr b)
return a.ToLower() < b.ToLower(); { return a.ToLower() < b.ToLower(); });
});
m_ScriptList.SetRedraw(false); m_ScriptList.SetRedraw(false);
m_ScriptList.DeleteAllItems(); m_ScriptList.DeleteAllItems();
int nItem = 0; int nItem = 0;
for (const stdstr& fileName : fileNames) for (const stdstr & fileName : fileNames)
{ {
JSInstanceStatus status = m_Debugger->ScriptSystem()->GetStatus(fileName.c_str()); JSInstanceStatus status = m_Debugger->ScriptSystem()->GetStatus(fileName.c_str());
const wchar_t* statusIcon = L""; const wchar_t * statusIcon = L"";
switch (status) switch (status)
{ {
@ -482,7 +482,7 @@ LRESULT CDebugScripts::OnRefreshList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*
return FALSE; return FALSE;
} }
void CDebugScripts::SendInput(const char* name, const char* code) void CDebugScripts::SendInput(const char * name, const char * code)
{ {
m_Debugger->ScriptSystem()->Input(name, code); m_Debugger->ScriptSystem()->Input(name, code);
} }
@ -524,15 +524,15 @@ void CDebugScripts::EditSelected()
ShellExecuteA(nullptr, "edit", scriptPath.c_str(), nullptr, m_InstallDir.c_str(), SW_SHOWNORMAL); ShellExecuteA(nullptr, "edit", scriptPath.c_str(), nullptr, m_InstallDir.c_str(), SW_SHOWNORMAL);
} }
LRESULT CDebugScripts::OnInputSpecialKey(NMHDR* pNMHDR) LRESULT CDebugScripts::OnInputSpecialKey(NMHDR * pNMHDR)
{ {
NMCISPECIALKEY* pnmsk = (NMCISPECIALKEY*)pNMHDR; NMCISPECIALKEY * pnmsk = (NMCISPECIALKEY *)pNMHDR;
if (pnmsk->vkey == VK_UP) if (pnmsk->vkey == VK_UP)
{ {
if (m_InputHistoryIndex > 0) if (m_InputHistoryIndex > 0)
{ {
wchar_t* code = m_InputHistory[--m_InputHistoryIndex]; wchar_t * code = m_InputHistory[--m_InputHistoryIndex];
m_ConInputEdit.SetWindowText(code); m_ConInputEdit.SetWindowText(code);
int selEnd = wcslen(code); int selEnd = wcslen(code);
m_ConInputEdit.SetSel(selEnd, selEnd); m_ConInputEdit.SetSel(selEnd, selEnd);
@ -552,7 +552,7 @@ LRESULT CDebugScripts::OnInputSpecialKey(NMHDR* pNMHDR)
if (m_InputHistoryIndex < size) if (m_InputHistoryIndex < size)
{ {
wchar_t* code = m_InputHistory[m_InputHistoryIndex]; wchar_t * code = m_InputHistory[m_InputHistoryIndex];
m_ConInputEdit.SetWindowText(code); m_ConInputEdit.SetWindowText(code);
int selEnd = wcslen(code); int selEnd = wcslen(code);
m_ConInputEdit.SetSel(selEnd, selEnd); m_ConInputEdit.SetSel(selEnd, selEnd);
@ -574,7 +574,7 @@ LRESULT CDebugScripts::OnInputSpecialKey(NMHDR* pNMHDR)
return 0; return 0;
} }
wchar_t* code = new wchar_t[codeLength + 1]; wchar_t * code = new wchar_t[codeLength + 1];
m_ConInputEdit.GetWindowText(code, codeLength + 1); m_ConInputEdit.GetWindowText(code, codeLength + 1);
m_ConInputEdit.SetWindowText(L""); m_ConInputEdit.SetWindowText(L"");
@ -585,7 +585,7 @@ LRESULT CDebugScripts::OnInputSpecialKey(NMHDR* pNMHDR)
{ {
if (wcscmp(code, m_InputHistory[i]) == 0) if (wcscmp(code, m_InputHistory[i]) == 0)
{ {
wchar_t* str = m_InputHistory[i]; wchar_t * str = m_InputHistory[i];
m_InputHistory.erase(m_InputHistory.begin() + i); m_InputHistory.erase(m_InputHistory.begin() + i);
m_InputHistory.push_back(str); m_InputHistory.push_back(str);
m_InputHistoryIndex = m_InputHistory.size(); m_InputHistoryIndex = m_InputHistory.size();
@ -615,7 +615,7 @@ void CDebugScripts::OnTimer(UINT_PTR nIDEvent)
scroll.cbSize = sizeof(SCROLLINFO); scroll.cbSize = sizeof(SCROLLINFO);
scroll.fMask = SIF_ALL; scroll.fMask = SIF_ALL;
m_ConOutputEdit.GetScrollInfo(SB_VERT, &scroll); m_ConOutputEdit.GetScrollInfo(SB_VERT, &scroll);
m_ConOutputEdit.SetRedraw(FALSE); m_ConOutputEdit.SetRedraw(FALSE);
m_ConOutputEdit.AppendText(m_ConOutputBuffer.ToUTF16().c_str()); m_ConOutputEdit.AppendText(m_ConOutputBuffer.ToUTF16().c_str());
m_ConOutputEdit.SetRedraw(TRUE); m_ConOutputEdit.SetRedraw(TRUE);

View File

@ -1,4 +1,5 @@
#include <stdafx.h> #include "stdafx.h"
#include "DebuggerUI.h" #include "DebuggerUI.h"
#include <sstream> #include <sstream>
@ -17,7 +18,7 @@ CScriptsAutorunDlg::~CScriptsAutorunDlg()
{ {
} }
INT_PTR CScriptsAutorunDlg::DoModal(CDebuggerUI* debugger, stdstr selectedScriptName) INT_PTR CScriptsAutorunDlg::DoModal(CDebuggerUI * debugger, stdstr selectedScriptName)
{ {
m_Debugger = debugger; m_Debugger = debugger;
m_ScriptSystem = debugger->ScriptSystem(); m_ScriptSystem = debugger->ScriptSystem();
@ -25,7 +26,7 @@ INT_PTR CScriptsAutorunDlg::DoModal(CDebuggerUI* debugger, stdstr selectedScript
return CDialogImpl<CScriptsAutorunDlg>::DoModal(); return CDialogImpl<CScriptsAutorunDlg>::DoModal();
} }
LRESULT CScriptsAutorunDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CScriptsAutorunDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
CenterWindow(); CenterWindow();
@ -35,13 +36,13 @@ LRESULT CScriptsAutorunDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARA
m_ScriptListView.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER); m_ScriptListView.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
m_ScriptListView.AddColumn(L"Script", 0); m_ScriptListView.AddColumn(L"Script", 0);
m_ScriptListView.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER); m_ScriptListView.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
m_AutorunListView.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER); m_AutorunListView.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER);
m_AutorunListView.AddColumn(L"Script", 0); m_AutorunListView.AddColumn(L"Script", 0);
m_AutorunListView.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER); m_AutorunListView.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
m_hQuitScriptDirWatchEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); m_hQuitScriptDirWatchEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr);
m_hScriptDirWatchThread = CreateThread(nullptr, 0, ScriptDirWatchProc, (void*)this, 0, nullptr); m_hScriptDirWatchThread = CreateThread(nullptr, 0, ScriptDirWatchProc, (void *)this, 0, nullptr);
m_ScriptSystem->LoadAutorunList(); m_ScriptSystem->LoadAutorunList();
@ -63,38 +64,37 @@ LRESULT CScriptsAutorunDlg::OnDestroy(void)
return 0; return 0;
} }
LRESULT CScriptsAutorunDlg::OnOKCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CScriptsAutorunDlg::OnOKCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
EndDialog(0); EndDialog(0);
return 0; return 0;
} }
LRESULT CScriptsAutorunDlg::OnAdd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
LRESULT CScriptsAutorunDlg::OnAdd(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/)
{ {
m_bScriptListNeedsRefocus = true; m_bScriptListNeedsRefocus = true;
AddSelected(); AddSelected();
return 0; return 0;
} }
LRESULT CScriptsAutorunDlg::OnRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CScriptsAutorunDlg::OnRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
m_bAutorunListNeedsRefocus = true; m_bAutorunListNeedsRefocus = true;
RemoveSelected(); RemoveSelected();
return 0; return 0;
} }
LRESULT CScriptsAutorunDlg::OnScriptListDblClicked(NMHDR* /*pNMHDR*/) LRESULT CScriptsAutorunDlg::OnScriptListDblClicked(NMHDR * /*pNMHDR*/)
{ {
AddSelected(); AddSelected();
return 0; return 0;
} }
LRESULT CScriptsAutorunDlg::OnCtrlSetFocus(NMHDR* pNMHDR) LRESULT CScriptsAutorunDlg::OnCtrlSetFocus(NMHDR * pNMHDR)
{ {
bool bEnableScriptButtons = false; bool bEnableScriptButtons = false;
bool bEnableAutorunButtons = false; bool bEnableAutorunButtons = false;
switch (pNMHDR->idFrom) switch (pNMHDR->idFrom)
{ {
case IDC_SCRIPT_LIST: case IDC_SCRIPT_LIST:
@ -108,20 +108,20 @@ LRESULT CScriptsAutorunDlg::OnCtrlSetFocus(NMHDR* pNMHDR)
bEnableScriptButtons = false; bEnableScriptButtons = false;
break; break;
} }
::EnableWindow(GetDlgItem(IDC_ADD_BTN), bEnableScriptButtons); ::EnableWindow(GetDlgItem(IDC_ADD_BTN), bEnableScriptButtons);
::EnableWindow(GetDlgItem(IDC_REMOVE_BTN), bEnableAutorunButtons); ::EnableWindow(GetDlgItem(IDC_REMOVE_BTN), bEnableAutorunButtons);
return 0; return 0;
} }
LRESULT CScriptsAutorunDlg::OnAutorunListDblClicked(NMHDR* /*pNMHDR*/) LRESULT CScriptsAutorunDlg::OnAutorunListDblClicked(NMHDR * /*pNMHDR*/)
{ {
RemoveSelected(); RemoveSelected();
return 0; return 0;
} }
LRESULT CScriptsAutorunDlg::OnRefreshScriptList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CScriptsAutorunDlg::OnRefreshScriptList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
int nSelectedItem = m_ScriptListView.GetSelectedIndex(); int nSelectedItem = m_ScriptListView.GetSelectedIndex();
@ -152,7 +152,7 @@ LRESULT CScriptsAutorunDlg::OnRefreshScriptList(UINT /*uMsg*/, WPARAM /*wParam*/
m_ScriptListView.DeleteAllItems(); m_ScriptListView.DeleteAllItems();
int nItem = 0; int nItem = 0;
for (const stdstr& fileName : fileNames) for (const stdstr & fileName : fileNames)
{ {
m_ScriptListView.AddItem(nItem, 0, fileName.ToUTF16().c_str()); m_ScriptListView.AddItem(nItem, 0, fileName.ToUTF16().c_str());
if (fileName == m_InitSelectedScriptName) if (fileName == m_InitSelectedScriptName)
@ -183,7 +183,7 @@ LRESULT CScriptsAutorunDlg::OnRefreshScriptList(UINT /*uMsg*/, WPARAM /*wParam*/
return 0; return 0;
} }
LRESULT CScriptsAutorunDlg::OnRefreshAutorunList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CScriptsAutorunDlg::OnRefreshAutorunList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
int nSelectedItem = m_AutorunListView.GetSelectedIndex(); int nSelectedItem = m_AutorunListView.GetSelectedIndex();
@ -196,7 +196,7 @@ LRESULT CScriptsAutorunDlg::OnRefreshAutorunList(UINT /*uMsg*/, WPARAM /*wParam*
m_AutorunListView.DeleteAllItems(); m_AutorunListView.DeleteAllItems();
int nItem = 0; int nItem = 0;
for (const stdstr& fileName : fileNames) for (const stdstr & fileName : fileNames)
{ {
m_AutorunListView.AddItem(nItem, 0, fileName.ToUTF16().c_str()); m_AutorunListView.AddItem(nItem, 0, fileName.ToUTF16().c_str());
if (fileName == m_InitSelectedScriptName) if (fileName == m_InitSelectedScriptName)
@ -225,9 +225,9 @@ LRESULT CScriptsAutorunDlg::OnRefreshAutorunList(UINT /*uMsg*/, WPARAM /*wParam*
return 0; return 0;
} }
DWORD WINAPI CScriptsAutorunDlg::ScriptDirWatchProc(void* ctx) DWORD WINAPI CScriptsAutorunDlg::ScriptDirWatchProc(void * ctx)
{ {
CScriptsAutorunDlg* _this = (CScriptsAutorunDlg*)ctx; CScriptsAutorunDlg * _this = (CScriptsAutorunDlg *)ctx;
stdstr scriptsDir = _this->m_ScriptSystem->ScriptsDirPath(); stdstr scriptsDir = _this->m_ScriptSystem->ScriptsDirPath();

View File

@ -3,9 +3,9 @@
#include "DebuggerUI.h" #include "DebuggerUI.h"
#include "Symbols.h" #include "Symbols.h"
CDebugStackTrace::CDebugStackTrace(CDebuggerUI* debugger) : CDebugStackTrace::CDebugStackTrace(CDebuggerUI * debugger) :
CDebugDialog<CDebugStackTrace>(debugger), CDebugDialog<CDebugStackTrace>(debugger),
m_EntriesIndex(0) m_EntriesIndex(0)
{ {
} }
@ -13,15 +13,15 @@ CDebugStackTrace::~CDebugStackTrace()
{ {
} }
LRESULT CDebugStackTrace::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugStackTrace::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
DlgResize_Init(); DlgResize_Init();
DlgSavePos_Init(DebuggerUI_StackTracePos); DlgSavePos_Init(DebuggerUI_StackTracePos);
m_List.Attach(GetDlgItem(IDC_STACKTRACE_LIST)); m_List.Attach(GetDlgItem(IDC_STACKTRACE_LIST));
m_List.AddColumn(L"Caller", 0); m_List.AddColumn(L"Caller", 0);
m_List.AddColumn(L"Routine", 1); m_List.AddColumn(L"Routine", 1);
m_List.AddColumn(L"Name", 2); m_List.AddColumn(L"Name", 2);
m_List.SetColumnWidth(0, 70); m_List.SetColumnWidth(0, 70);
m_List.SetColumnWidth(1, 70); m_List.SetColumnWidth(1, 70);
@ -39,7 +39,7 @@ void CDebugStackTrace::OnExitSizeMove(void)
SaveWindowPos(true); SaveWindowPos(true);
} }
LRESULT CDebugStackTrace::OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugStackTrace::OnActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
Refresh(); Refresh();
return FALSE; return FALSE;
@ -51,7 +51,7 @@ LRESULT CDebugStackTrace::OnDestroy(void)
return FALSE; return FALSE;
} }
LRESULT CDebugStackTrace::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CDebugStackTrace::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
switch (wID) switch (wID)
{ {
@ -62,9 +62,9 @@ LRESULT CDebugStackTrace::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndC
return FALSE; return FALSE;
} }
LRESULT CDebugStackTrace::OnListDblClicked(NMHDR* pNMHDR) LRESULT CDebugStackTrace::OnListDblClicked(NMHDR * pNMHDR)
{ {
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR); NMITEMACTIVATE * pIA = reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);
int nItem = pIA->iItem; int nItem = pIA->iItem;
uint32_t address = m_List.GetItemData(nItem); uint32_t address = m_List.GetItemData(nItem);
@ -90,7 +90,7 @@ void CDebugStackTrace::Refresh()
{ {
uint32_t routineAddress = m_Entries[i].routineAddress; uint32_t routineAddress = m_Entries[i].routineAddress;
uint32_t callingAddress = m_Entries[i].callingAddress; uint32_t callingAddress = m_Entries[i].callingAddress;
m_List.AddItem(i, 0, stdstr_f("%08X", callingAddress).ToUTF16().c_str()); m_List.AddItem(i, 0, stdstr_f("%08X", callingAddress).ToUTF16().c_str());
m_List.AddItem(i, 1, stdstr_f("%08X", routineAddress).ToUTF16().c_str()); m_List.AddItem(i, 1, stdstr_f("%08X", routineAddress).ToUTF16().c_str());
@ -103,7 +103,7 @@ void CDebugStackTrace::Refresh()
{ {
m_List.AddItem(i, 2, L""); m_List.AddItem(i, 2, L"");
} }
m_List.SetItemData(i, routineAddress); m_List.SetItemData(i, routineAddress);
} }

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "DebuggerUI.h" #include "DebuggerUI.h"
#include "Symbols.h" #include "Symbols.h"
@ -11,7 +12,7 @@ CDebugStackView::~CDebugStackView(void)
{ {
} }
LRESULT CDebugStackView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugStackView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
DlgResize_Init(false, true); DlgResize_Init(false, true);
DlgSavePos_Init(DebuggerUI_StackPos); DlgSavePos_Init(DebuggerUI_StackPos);
@ -32,8 +33,8 @@ LRESULT CDebugStackView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /
m_SPStatic.Attach(GetDlgItem(IDC_SP_STATIC)); m_SPStatic.Attach(GetDlgItem(IDC_SP_STATIC));
LoadWindowPos(); LoadWindowPos();
WindowCreated(); WindowCreated();
return 0; return 0;
} }
@ -50,7 +51,7 @@ LRESULT CDebugStackView::OnDestroy(void)
return 0; return 0;
} }
LRESULT CDebugStackView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CDebugStackView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
switch (wID) switch (wID)
{ {

View File

@ -1,27 +1,28 @@
#include "stdafx.h" #include "stdafx.h"
#include "DebuggerUI.h" #include "DebuggerUI.h"
#include <stdio.h>
#include <Common/path.h> #include <Common/path.h>
#include <stdio.h>
#include "Symbols.h" #include "Symbols.h"
const CSetValueDlg::ComboItem CDebugSymbols::ModalChangeTypeItems[] = { const CSetValueDlg::ComboItem CDebugSymbols::ModalChangeTypeItems[] = {
{ "code", SYM_CODE }, {"code", SYM_CODE},
{ "data", SYM_DATA }, {"data", SYM_DATA},
{ "uint8", SYM_U8 }, {"uint8", SYM_U8},
{ "int8", SYM_S8 }, {"int8", SYM_S8},
{ "uint16", SYM_U16 }, {"uint16", SYM_U16},
{ "int16", SYM_S16 }, {"int16", SYM_S16},
{ "uint32", SYM_U32 }, {"uint32", SYM_U32},
{ "int32", SYM_S32 }, {"int32", SYM_S32},
{ "uint64", SYM_U64 }, {"uint64", SYM_U64},
{ "int64", SYM_S64 }, {"int64", SYM_S64},
{ "float", SYM_FLOAT }, {"float", SYM_FLOAT},
{ "double", SYM_DOUBLE }, {"double", SYM_DOUBLE},
{ "v2", SYM_VECTOR2 }, {"v2", SYM_VECTOR2},
{ "v3", SYM_VECTOR3 }, {"v3", SYM_VECTOR3},
{ "v4", SYM_VECTOR4 }, {"v4", SYM_VECTOR4},
{ nullptr, 0 } { nullptr, 0 }
}; };
@ -34,7 +35,7 @@ CDebugSymbols::CDebugSymbols(CDebuggerUI * debugger) :
memset(m_FilterText, 0, sizeof(m_FilterText)); memset(m_FilterText, 0, sizeof(m_FilterText));
} }
LRESULT CDebugSymbols::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugSymbols::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
DlgResize_Init(false, true); DlgResize_Init(false, true);
DlgSavePos_Init(DebuggerUI_SymbolsPos); DlgSavePos_Init(DebuggerUI_SymbolsPos);
@ -85,7 +86,7 @@ void CDebugSymbols::OnTimer(UINT_PTR nIDEvent)
} }
} }
LRESULT CDebugSymbols::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CDebugSymbols::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
switch (wID) switch (wID)
{ {
@ -96,35 +97,35 @@ LRESULT CDebugSymbols::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*
m_AddSymbolDlg.DoModal(m_Debugger); m_AddSymbolDlg.DoModal(m_Debugger);
break; break;
case IDC_REMOVESYMBOL_BTN: case IDC_REMOVESYMBOL_BTN:
{
int nItem = m_SymbolsListView.GetSelectedIndex();
int id = -1;
if (m_bFiltering)
{ {
int nItem = m_SymbolsListView.GetSelectedIndex(); id = m_FilteredSymbols[nItem].m_Id;
int id = -1;
if (m_bFiltering)
{
id = m_FilteredSymbols[nItem].m_Id;
}
else
{
CSymbol symbol;
m_SymbolTable->GetSymbolByIndex(nItem, &symbol);
id = symbol.m_Id;
}
if (id != -1)
{
m_SymbolTable->RemoveSymbolById(id);
m_SymbolTable->Save();
Refresh();
}
} }
break; else
{
CSymbol symbol;
m_SymbolTable->GetSymbolByIndex(nItem, &symbol);
id = symbol.m_Id;
}
if (id != -1)
{
m_SymbolTable->RemoveSymbolById(id);
m_SymbolTable->Save();
Refresh();
}
}
break;
} }
return FALSE; return FALSE;
} }
LRESULT CDebugSymbols::OnListDblClicked(NMHDR* pNMHDR) LRESULT CDebugSymbols::OnListDblClicked(NMHDR * pNMHDR)
{ {
NMITEMACTIVATE* pIA = reinterpret_cast<NMITEMACTIVATE*>(pNMHDR); NMITEMACTIVATE * pIA = reinterpret_cast<NMITEMACTIVATE *>(pNMHDR);
if (pIA->iItem == -1) if (pIA->iItem == -1)
{ {
@ -175,8 +176,8 @@ LRESULT CDebugSymbols::OnListDblClicked(NMHDR* pNMHDR)
break; break;
case SymbolsListView_Col_Value: case SymbolsListView_Col_Value:
char szValue[256]; char szValue[256];
const char* x; const char * x;
const char* y; const char * y;
m_SymbolTable->GetValueString(szValue, &symbol); m_SymbolTable->GetValueString(szValue, &symbol);
if (m_SetValueDlg.DoModal("Change value", "New value:", szValue)) if (m_SetValueDlg.DoModal("Change value", "New value:", szValue))
{ {
@ -269,7 +270,7 @@ LRESULT CDebugSymbols::OnListDblClicked(NMHDR* pNMHDR)
m_SymbolTable->AddSymbol(symbol.m_Type, symbol.m_Address, symbol.m_Name, m_SetValueDlg.GetEnteredString().c_str()); m_SymbolTable->AddSymbol(symbol.m_Type, symbol.m_Address, symbol.m_Name, m_SetValueDlg.GetEnteredString().c_str());
} }
break; break;
} }
m_SymbolTable->Save(); m_SymbolTable->Save();
Refresh(); Refresh();
@ -277,10 +278,10 @@ LRESULT CDebugSymbols::OnListDblClicked(NMHDR* pNMHDR)
return 0; return 0;
} }
LRESULT CDebugSymbols::OnListGetDispInfo(NMHDR* pNMHDR) LRESULT CDebugSymbols::OnListGetDispInfo(NMHDR * pNMHDR)
{ {
NMLVDISPINFO* plvdi = (NMLVDISPINFO*)pNMHDR; NMLVDISPINFO * plvdi = (NMLVDISPINFO *)pNMHDR;
int index = plvdi->item.iItem; int index = plvdi->item.iItem;
if (index == -1) if (index == -1)
@ -288,7 +289,7 @@ LRESULT CDebugSymbols::OnListGetDispInfo(NMHDR* pNMHDR)
return TRUE; return TRUE;
} }
std::vector<SymbolCacheItem>& cache = m_bFiltering ? m_FilteredSymbols : m_SymbolCache; std::vector<SymbolCacheItem> & cache = m_bFiltering ? m_FilteredSymbols : m_SymbolCache;
if (!m_bFiltering) if (!m_bFiltering)
{ {
@ -319,8 +320,8 @@ LRESULT CDebugSymbols::OnListGetDispInfo(NMHDR* pNMHDR)
LRESULT CDebugSymbols::OnListCacheHint(NMHDR * pNMHDR) LRESULT CDebugSymbols::OnListCacheHint(NMHDR * pNMHDR)
{ {
NMLVCACHEHINT* plvch = (NMLVCACHEHINT*)pNMHDR; NMLVCACHEHINT * plvch = (NMLVCACHEHINT *)pNMHDR;
if (m_bFiltering) if (m_bFiltering)
{ {
return 0; return 0;
@ -344,7 +345,7 @@ LRESULT CDebugSymbols::OnListCacheHint(NMHDR * pNMHDR)
return 0; return 0;
} }
LRESULT CDebugSymbols::OnFilterChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CDebugSymbols::OnFilterChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
if (::GetWindowTextLength(GetDlgItem(IDC_FILTER_EDIT)) == 0) if (::GetWindowTextLength(GetDlgItem(IDC_FILTER_EDIT)) == 0)
{ {
@ -352,17 +353,17 @@ LRESULT CDebugSymbols::OnFilterChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND
Refresh(); Refresh();
return FALSE; return FALSE;
} }
m_bFiltering = true; m_bFiltering = true;
::GetWindowText(GetDlgItem(IDC_FILTER_EDIT), m_FilterText, sizeof(m_FilterText) / sizeof(wchar_t)); ::GetWindowText(GetDlgItem(IDC_FILTER_EDIT), m_FilterText, sizeof(m_FilterText) / sizeof(wchar_t));
UpdateFilteredSymbols(); UpdateFilteredSymbols();
m_SymbolsListView.SetItemCount(m_FilteredSymbols.size()); m_SymbolsListView.SetItemCount(m_FilteredSymbols.size());
return FALSE; return FALSE;
} }
int CDebugSymbols::ColumnHitTest(POINT& pt) int CDebugSymbols::ColumnHitTest(POINT & pt)
{ {
int nHitCol = -1; int nHitCol = -1;
RECT listRect; RECT listRect;

View File

@ -11,7 +11,7 @@ CDebugTlb::~CDebugTlb()
{ {
} }
LRESULT CDebugTlb::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugTlb::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
DlgSavePos_Init(DebuggerUI_TLBPos); DlgSavePos_Init(DebuggerUI_TLBPos);
@ -79,7 +79,7 @@ void CDebugTlb::OnExitSizeMove(void)
SaveWindowPos(0); SaveWindowPos(0);
} }
LRESULT CDebugTlb::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL& /*bHandled*/) LRESULT CDebugTlb::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL & /*bHandled*/)
{ {
switch (wID) switch (wID)
{ {
@ -202,7 +202,7 @@ void CDebugTlb::RefreshTLBWindow(void)
} }
} }
CTLB::FASTTLB * FastTlb = g_TLB->m_FastTlb; CTLB::FASTTLB * FastTlb = g_TLB->m_FastTlb;
hList = GetDlgItem(IDC_LIST2); hList = GetDlgItem(IDC_LIST2);
for (count = 0; count < 64; count++) for (count = 0; count < 64; count++)
{ {
@ -266,7 +266,7 @@ void CDebugTlb::RefreshTLBWindow(void)
if (FastTlb[count].ValidEntry && FastTlb[count].VALID) if (FastTlb[count].ValidEntry && FastTlb[count].VALID)
{ {
swprintf(Output, sizeof(Output), L"%08X:%08X -> %08X:%08X", FastTlb[count].VSTART, FastTlb[count].VEND, swprintf(Output, sizeof(Output), L"%08X:%08X -> %08X:%08X", FastTlb[count].VSTART, FastTlb[count].VEND,
FastTlb[count].PHYSSTART, FastTlb[count].PHYSEND); FastTlb[count].PHYSSTART, FastTlb[count].PHYSEND);
} }
else else
{ {

View File

@ -1,32 +1,33 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/ExceptionHandler.h>
#include <Common/MemoryManagement.h> #include <Common/MemoryManagement.h>
#include <Project64-core/ExceptionHandler.h>
#include <UserInterface/WTLControls/HexEditCtrl.h> #include <UserInterface/WTLControls/HexEditCtrl.h>
#include "DMALog.h"
#include "DebuggerUI.h" #include "DebuggerUI.h"
#include "Symbols.h" #include "Symbols.h"
#include "DMALog.h"
CDebugMemoryView::jump_item_t CDebugMemoryView::JumpItems[] = { CDebugMemoryView::jump_item_t CDebugMemoryView::JumpItems[] = {
{ 0x80000000, 0x00000000, 0x0800000, "RDRAM" }, {0x80000000, 0x00000000, 0x0800000, "RDRAM"},
{ 0xA3F00000, 0x03F00000, 0x0000028, "RDRAM registers" }, {0xA3F00000, 0x03F00000, 0x0000028, "RDRAM registers"},
{ 0xA4000000, 0x04000000, 0x0001000, "SP DMEM" }, {0xA4000000, 0x04000000, 0x0001000, "SP DMEM"},
{ 0xA4001000, 0x04001000, 0x0001000, "SP IMEM" }, {0xA4001000, 0x04001000, 0x0001000, "SP IMEM"},
{ 0xA4040000, 0x04040000, 0x0000020, "SP registers" }, {0xA4040000, 0x04040000, 0x0000020, "SP registers"},
{ 0xA4080000, 0x04080000, 0x0000004, "SP PC register" }, {0xA4080000, 0x04080000, 0x0000004, "SP PC register"},
{ 0xA4100000, 0x04100000, 0x0000020, "DP control registers" }, {0xA4100000, 0x04100000, 0x0000020, "DP control registers"},
{ 0xA4300000, 0x04300000, 0x0000010, "MI registers" }, {0xA4300000, 0x04300000, 0x0000010, "MI registers"},
{ 0xA4400000, 0x04400000, 0x0000038, "VI registers" }, {0xA4400000, 0x04400000, 0x0000038, "VI registers"},
{ 0xA4500000, 0x04500000, 0x0000018, "AI registers" }, {0xA4500000, 0x04500000, 0x0000018, "AI registers"},
{ 0xA4600000, 0x04600000, 0x0000034, "PI registers" }, {0xA4600000, 0x04600000, 0x0000034, "PI registers"},
{ 0xA4700000, 0x04700000, 0x0000020, "RI registers" }, {0xA4700000, 0x04700000, 0x0000020, "RI registers"},
{ 0xA4800000, 0x04800000, 0x0000010, "SI registers" }, {0xA4800000, 0x04800000, 0x0000010, "SI registers"},
{ 0xA5000500, 0x05000500, 0x000004C, "DD registers" }, {0xA5000500, 0x05000500, 0x000004C, "DD registers"},
{ 0xA8000000, 0x08000000, 0x1000000, "Cartridge save data" }, {0xA8000000, 0x08000000, 0x1000000, "Cartridge save data"},
{ 0xB0000000, 0x10000000, 0xFC00000, "Cartridge ROM" }, {0xB0000000, 0x10000000, 0xFC00000, "Cartridge ROM"},
{ 0xBFC00000, 0x1FC00000, 0x00007C0, "PIF ROM" }, {0xBFC00000, 0x1FC00000, 0x00007C0, "PIF ROM"},
{ 0xBFC007C0, 0x1FC007C0, 0x0000040, "PIF RAM" }, {0xBFC007C0, 0x1FC007C0, 0x0000040, "PIF RAM"},
{ 0, NULL} { 0, NULL}
}; };
@ -62,7 +63,7 @@ void CDebugMemoryView::ShowAddress(uint32_t address, bool bVirtual)
SendMessage(WM_SHOWADDRESS, (WPARAM)address, (LPARAM)bVirtual); SendMessage(WM_SHOWADDRESS, (WPARAM)address, (LPARAM)bVirtual);
} }
bool CDebugMemoryView::GetByte(uint32_t address, uint8_t* value) bool CDebugMemoryView::GetByte(uint32_t address, uint8_t * value)
{ {
if (m_bVirtualMemory) if (m_bVirtualMemory)
{ {
@ -86,11 +87,11 @@ bool CDebugMemoryView::SetByte(uint32_t address, uint8_t value)
} }
} }
void CDebugMemoryView::CopyTextToClipboard(const char* text) void CDebugMemoryView::CopyTextToClipboard(const char * text)
{ {
size_t length = strlen(text); size_t length = strlen(text);
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, length + 1); HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, length + 1);
strcpy((char*)GlobalLock(hMem), text); strcpy((char *)GlobalLock(hMem), text);
GlobalUnlock(hMem); GlobalUnlock(hMem);
OpenClipboard(); OpenClipboard();
EmptyClipboard(); EmptyClipboard();
@ -113,7 +114,7 @@ void CDebugMemoryView::CopyBytesToClipboard(uint32_t startAddress, uint32_t endA
uint8_t value; uint8_t value;
GetByte(address, &value); GetByte(address, &value);
if (bIncludeAddresses) if (bIncludeAddresses)
{ {
if ((bRowAddresses && offsetFromBase % rowSize == 0) || if ((bRowAddresses && offsetFromBase % rowSize == 0) ||
@ -157,7 +158,7 @@ void CDebugMemoryView::CopyGameSharkCodeToClipboard(uint32_t startAddress, uint3
str += stdstr_f("%08X %04X\r\n", startAddress, value); str += stdstr_f("%08X %04X\r\n", startAddress, value);
startAddress++; startAddress++;
} }
for (uint32_t address = startAddress; address < endAddress; address += 2) for (uint32_t address = startAddress; address < endAddress; address += 2)
{ {
uint8_t value0 = 0, value1 = 0; uint8_t value0 = 0, value1 = 0;
@ -217,7 +218,6 @@ void CDebugMemoryView::FollowPointer(bool bContextMenuAddress)
} }
} }
void CDebugMemoryView::JumpToSelection(void) void CDebugMemoryView::JumpToSelection(void)
{ {
uint32_t startAddress, endAddress; uint32_t startAddress, endAddress;
@ -226,14 +226,14 @@ void CDebugMemoryView::JumpToSelection(void)
m_MemAddr.SetValue(targetAddress, DisplayMode::ZeroExtend); m_MemAddr.SetValue(targetAddress, DisplayMode::ZeroExtend);
} }
bool CDebugMemoryView::GetSafeEditValue(uint32_t address, uint8_t* value) bool CDebugMemoryView::GetSafeEditValue(uint32_t address, uint8_t * value)
{ {
if (m_SafeEditQueue.size() == 0) if (m_SafeEditQueue.size() == 0)
{ {
return false; return false;
} }
for(size_t i = m_SafeEditQueue.size(); i-- > 0;) for (size_t i = m_SafeEditQueue.size(); i-- > 0;)
{ {
edit_t edit = m_SafeEditQueue[i]; edit_t edit = m_SafeEditQueue[i];
if (address >= edit.startAddress && address <= edit.endAddress) if (address >= edit.startAddress && address <= edit.endAddress)
@ -266,7 +266,7 @@ void CDebugMemoryView::SetupJumpMenu(bool bVirtual)
for (int i = 0;; i++) for (int i = 0;; i++)
{ {
jump_item_t* item = &JumpItems[i]; jump_item_t * item = &JumpItems[i];
if (item->caption == nullptr) if (item->caption == nullptr)
{ {
@ -299,7 +299,7 @@ int CDebugMemoryView::GetJumpItemIndex(uint32_t address, bool bVirtual)
return -1; return -1;
} }
LRESULT CDebugMemoryView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugMemoryView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
DlgResize_Init(false, true); DlgResize_Init(false, true);
DlgSavePos_Init(DebuggerUI_MemoryPos); DlgSavePos_Init(DebuggerUI_MemoryPos);
@ -348,7 +348,7 @@ LRESULT CDebugMemoryView::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
SetupJumpMenu(true); SetupJumpMenu(true);
m_CmbJump.SetCurSel(0); m_CmbJump.SetCurSel(0);
m_TabData.clear(); m_TabData.clear();
AddTab(0x80000000, true, 4); AddTab(0x80000000, true, 4);
@ -520,7 +520,7 @@ void CDebugMemoryView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
m_MemAddr.SetValue(address < 0xFFFFFEFF ? address + numVisibleBytes : 0xFFFFFFFF, DisplayMode::ZeroExtend); m_MemAddr.SetValue(address < 0xFFFFFEFF ? address + numVisibleBytes : 0xFFFFFFFF, DisplayMode::ZeroExtend);
break; break;
case SB_PAGEUP: case SB_PAGEUP:
m_MemAddr.SetValue(address >(uint32_t)numVisibleBytes ? address - numVisibleBytes : 0, DisplayMode::ZeroExtend); m_MemAddr.SetValue(address > (uint32_t)numVisibleBytes ? address - numVisibleBytes : 0, DisplayMode::ZeroExtend);
break; break;
case SB_THUMBPOSITION: case SB_THUMBPOSITION:
m_MemAddr.SetValue((DWORD)nPos << 0x10, DisplayMode::ZeroExtend); m_MemAddr.SetValue((DWORD)nPos << 0x10, DisplayMode::ZeroExtend);
@ -534,7 +534,7 @@ void CDebugMemoryView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar pScrollBar)
LRESULT CDebugMemoryView::OnHxCtrlKeyPressed(LPNMHDR lpNMHDR) LRESULT CDebugMemoryView::OnHxCtrlKeyPressed(LPNMHDR lpNMHDR)
{ {
NMHXCTRLKEYPRESSED* nmck = reinterpret_cast<NMHXCTRLKEYPRESSED*>(lpNMHDR); NMHXCTRLKEYPRESSED * nmck = reinterpret_cast<NMHXCTRLKEYPRESSED *>(lpNMHDR);
uint32_t address = m_HexEditCtrl.GetCaretAddress(); uint32_t address = m_HexEditCtrl.GetCaretAddress();
if (nmck->nChar >= '1' && nmck->nChar <= '9') if (nmck->nChar >= '1' && nmck->nChar <= '9')
@ -611,7 +611,7 @@ LRESULT CDebugMemoryView::OnHxSetNibble(LPNMHDR lpNMHDR)
return FALSE; return FALSE;
} }
NMHXSETNIBBLE* nmsn = reinterpret_cast<NMHXSETNIBBLE*>(lpNMHDR); NMHXSETNIBBLE * nmsn = reinterpret_cast<NMHXSETNIBBLE *>(lpNMHDR);
uint8_t curValue; uint8_t curValue;
bool bValid = GetByte(nmsn->address, &curValue); bool bValid = GetByte(nmsn->address, &curValue);
@ -631,7 +631,7 @@ LRESULT CDebugMemoryView::OnHxSetNibble(LPNMHDR lpNMHDR)
newValue = (curValue & mask) | (nmsn->value << (nmsn->bLoNibble ? 0 : 4)); newValue = (curValue & mask) | (nmsn->value << (nmsn->bLoNibble ? 0 : 4));
} }
m_SafeEditQueue.push_back({ SE_FILL, nmsn->address, nmsn->address, newValue }); m_SafeEditQueue.push_back({SE_FILL, nmsn->address, nmsn->address, newValue});
} }
else else
{ {
@ -643,7 +643,7 @@ LRESULT CDebugMemoryView::OnHxSetNibble(LPNMHDR lpNMHDR)
LRESULT CDebugMemoryView::OnHxSetByte(LPNMHDR lpNMHDR) LRESULT CDebugMemoryView::OnHxSetByte(LPNMHDR lpNMHDR)
{ {
NMHXSETBYTE* nmsb = reinterpret_cast<NMHXSETBYTE*>(lpNMHDR); NMHXSETBYTE * nmsb = reinterpret_cast<NMHXSETBYTE *>(lpNMHDR);
if (g_MMU == nullptr) if (g_MMU == nullptr)
{ {
@ -652,7 +652,7 @@ LRESULT CDebugMemoryView::OnHxSetByte(LPNMHDR lpNMHDR)
if (nmsb->bInsert) if (nmsb->bInsert)
{ {
m_SafeEditQueue.push_back({ SE_FILL, nmsb->address, nmsb->address, nmsb->value }); m_SafeEditQueue.push_back({SE_FILL, nmsb->address, nmsb->address, nmsb->value});
} }
else else
{ {
@ -663,11 +663,11 @@ LRESULT CDebugMemoryView::OnHxSetByte(LPNMHDR lpNMHDR)
LRESULT CDebugMemoryView::OnHxFillRange(LPNMHDR lpNMHDR) LRESULT CDebugMemoryView::OnHxFillRange(LPNMHDR lpNMHDR)
{ {
NMHXFILLRANGE* nmfr = reinterpret_cast<NMHXFILLRANGE*>(lpNMHDR); NMHXFILLRANGE * nmfr = reinterpret_cast<NMHXFILLRANGE *>(lpNMHDR);
if (nmfr->bInsert) if (nmfr->bInsert)
{ {
m_SafeEditQueue.push_back({ SE_FILL, nmfr->startAddress, nmfr->endAddress, nmfr->value }); m_SafeEditQueue.push_back({SE_FILL, nmfr->startAddress, nmfr->endAddress, nmfr->value});
return FALSE; return FALSE;
} }
@ -705,7 +705,7 @@ LRESULT CDebugMemoryView::OnHxSelectionChanged(LPNMHDR /*lpNMHDR*/)
} }
uint32_t romAddr, offset; uint32_t romAddr, offset;
DMALOGENTRY* entry = m_Debugger->DMALog()->GetEntryByRamAddress(startAddress, &romAddr, &offset); DMALOGENTRY * entry = m_Debugger->DMALog()->GetEntryByRamAddress(startAddress, &romAddr, &offset);
m_StatusBar.SetText(MEMSB_DMAINFO, entry != nullptr ? L"Have DMA" : L""); m_StatusBar.SetText(MEMSB_DMAINFO, entry != nullptr ? L"Have DMA" : L"");
return FALSE; return FALSE;
@ -740,7 +740,7 @@ LRESULT CDebugMemoryView::OnHxRedrawStarted(LPNMHDR /*lpNMHDR*/)
LRESULT CDebugMemoryView::OnHxGetByteInfo(LPNMHDR lpNMHDR) LRESULT CDebugMemoryView::OnHxGetByteInfo(LPNMHDR lpNMHDR)
{ {
NMHXGETBYTEINFO *nmgbi = reinterpret_cast<NMHXGETBYTEINFO*>(lpNMHDR); NMHXGETBYTEINFO * nmgbi = reinterpret_cast<NMHXGETBYTEINFO *>(lpNMHDR);
bool bHaveWriteTarget = false, bHaveReadTarget = false; bool bHaveWriteTarget = false, bHaveReadTarget = false;
uint32_t cpuReadWriteAddress = 0; uint32_t cpuReadWriteAddress = 0;
@ -767,8 +767,8 @@ LRESULT CDebugMemoryView::OnHxGetByteInfo(LPNMHDR lpNMHDR)
{ {
uint32_t address = nmgbi->address + i; uint32_t address = nmgbi->address + i;
uint32_t paddress = address; uint32_t paddress = address;
HXBYTEINFO* oldByte = &nmgbi->oldBytes[i]; HXBYTEINFO * oldByte = &nmgbi->oldBytes[i];
HXBYTEINFO* newByte = &nmgbi->newBytes[i]; HXBYTEINFO * newByte = &nmgbi->newBytes[i];
newByte->bkColor = BKCOLOR_DEFAULT; newByte->bkColor = BKCOLOR_DEFAULT;
newByte->color = COLOR_DEFAULT; newByte->color = COLOR_DEFAULT;
@ -885,7 +885,7 @@ LRESULT CDebugMemoryView::OnHxGetByteInfo(LPNMHDR lpNMHDR)
LRESULT CDebugMemoryView::OnHxRightClick(LPNMHDR lpNMHDR) LRESULT CDebugMemoryView::OnHxRightClick(LPNMHDR lpNMHDR)
{ {
NMHXRCLICK *nmrc = reinterpret_cast<NMHXRCLICK*>(lpNMHDR); NMHXRCLICK * nmrc = reinterpret_cast<NMHXRCLICK *>(lpNMHDR);
m_ContextMenuAddress = nmrc->address; m_ContextMenuAddress = nmrc->address;
@ -958,7 +958,7 @@ LRESULT CDebugMemoryView::OnHxCopy(LPNMHDR /*lpNMHDR*/)
LRESULT CDebugMemoryView::OnHxPaste(LPNMHDR lpNMHDR) LRESULT CDebugMemoryView::OnHxPaste(LPNMHDR lpNMHDR)
{ {
NMHXPASTE *nmp = reinterpret_cast<NMHXPASTE*>(lpNMHDR); NMHXPASTE * nmp = reinterpret_cast<NMHXPASTE *>(lpNMHDR);
if (g_MMU == nullptr) if (g_MMU == nullptr)
{ {
@ -967,7 +967,7 @@ LRESULT CDebugMemoryView::OnHxPaste(LPNMHDR lpNMHDR)
OpenClipboard(); OpenClipboard();
HANDLE hData = GetClipboardData(CF_TEXT); HANDLE hData = GetClipboardData(CF_TEXT);
char* text = (char*)GlobalLock(hData); char * text = (char *)GlobalLock(hData);
int retDataLength = 0; int retDataLength = 0;
if (nmp->column == HX_COL_HEXDATA) if (nmp->column == HX_COL_HEXDATA)
@ -1005,7 +1005,6 @@ LRESULT CDebugMemoryView::OnHxPaste(LPNMHDR lpNMHDR)
return retDataLength; return retDataLength;
} }
LRESULT CDebugMemoryView::OnTabSelChange(LPNMHDR /*lpNMHDR*/) LRESULT CDebugMemoryView::OnTabSelChange(LPNMHDR /*lpNMHDR*/)
{ {
TabSelChanged(); TabSelChanged();
@ -1014,16 +1013,16 @@ LRESULT CDebugMemoryView::OnTabSelChange(LPNMHDR /*lpNMHDR*/)
void CDebugMemoryView::TabSelChanged(void) void CDebugMemoryView::TabSelChanged(void)
{ {
TCITEM item = { 0 }; TCITEM item = {0};
item.mask = TCIF_PARAM; item.mask = TCIF_PARAM;
int nItem = m_TabCtrl.GetCurSel(); int nItem = m_TabCtrl.GetCurSel();
if (m_TabCtrl.GetItem(nItem, &item)) if (m_TabCtrl.GetItem(nItem, &item))
{ {
tab_info_t tabInfo = m_TabData[nItem]; tab_info_t tabInfo = m_TabData[nItem];
uint32_t address = tabInfo.address; uint32_t address = tabInfo.address;
m_MemAddr.SetValue(address, DisplayMode::ZeroExtend); m_MemAddr.SetValue(address, DisplayMode::ZeroExtend);
if (m_bVirtualMemory != tabInfo.bVirtual) if (m_bVirtualMemory != tabInfo.bVirtual)
@ -1042,13 +1041,13 @@ int CDebugMemoryView::AddTab(uint32_t address, bool bVirtual, int numBytesPerGro
{ {
stdstr szAddress; stdstr szAddress;
szAddress.Format("%08X", address); szAddress.Format("%08X", address);
m_TabData.push_back({ address, bVirtual, numBytesPerGroup }); m_TabData.push_back({address, bVirtual, numBytesPerGroup});
return m_TabCtrl.AddItem(TCIF_TEXT | TCIF_PARAM, szAddress.ToUTF16().c_str(), 0, (LPARAM)address); return m_TabCtrl.AddItem(TCIF_TEXT | TCIF_PARAM, szAddress.ToUTF16().c_str(), 0, (LPARAM)address);
} }
int CDebugMemoryView::InsertTab(int nItem, uint32_t address, bool bVirtual, int numBytesPerGroup) int CDebugMemoryView::InsertTab(int nItem, uint32_t address, bool bVirtual, int numBytesPerGroup)
{ {
m_TabData.insert(m_TabData.begin() + nItem + 1, { address, bVirtual, numBytesPerGroup }); m_TabData.insert(m_TabData.begin() + nItem + 1, {address, bVirtual, numBytesPerGroup});
m_TabCtrl.SetRedraw(FALSE); m_TabCtrl.SetRedraw(FALSE);
m_TabCtrl.DeleteAllItems(); m_TabCtrl.DeleteAllItems();
for (size_t i = 0; i < m_TabData.size(); i++) for (size_t i = 0; i < m_TabData.size(); i++)
@ -1069,13 +1068,13 @@ void CDebugMemoryView::UpdateCurrentTab(uint32_t address)
{ {
std::wstring szAddress = stdstr_f("%08X", address).ToUTF16(); std::wstring szAddress = stdstr_f("%08X", address).ToUTF16();
int nItem = m_TabCtrl.GetCurSel(); int nItem = m_TabCtrl.GetCurSel();
if (nItem == -1) if (nItem == -1)
{ {
return; return;
} }
TCITEM item = { 0 }; TCITEM item = {0};
item.mask = TCIF_TEXT; item.mask = TCIF_TEXT;
item.pszText = (LPWSTR)szAddress.c_str(); item.pszText = (LPWSTR)szAddress.c_str();
@ -1102,7 +1101,7 @@ void CDebugMemoryView::OpenNewTab(uint32_t address, bool bVirtual, int numBytesP
} }
} }
} }
if (bInsert) if (bInsert)
{ {
int nCurSelItem = m_TabCtrl.GetCurSel(); int nCurSelItem = m_TabCtrl.GetCurSel();
@ -1119,7 +1118,7 @@ void CDebugMemoryView::OpenNewTab(uint32_t address, bool bVirtual, int numBytesP
void CDebugMemoryView::OpenDuplicateTab(void) void CDebugMemoryView::OpenDuplicateTab(void)
{ {
int nItem = m_TabCtrl.GetCurSel(); int nItem = m_TabCtrl.GetCurSel();
tab_info_t tabInfo = m_TabData[nItem]; tab_info_t tabInfo = m_TabData[nItem];
int nItemNew = InsertTab(nItem, tabInfo.address, tabInfo.bVirtual, tabInfo.numBytesPerGroup); int nItemNew = InsertTab(nItem, tabInfo.address, tabInfo.bVirtual, tabInfo.numBytesPerGroup);
m_TabCtrl.SetCurSel(nItemNew); m_TabCtrl.SetCurSel(nItemNew);
@ -1130,12 +1129,12 @@ void CDebugMemoryView::CloseTab(int nItem)
{ {
int itemCount = m_TabCtrl.GetItemCount(); int itemCount = m_TabCtrl.GetItemCount();
int nSelItem = m_TabCtrl.GetCurSel(); int nSelItem = m_TabCtrl.GetCurSel();
if (itemCount < 2 || nItem == -1) if (itemCount < 2 || nItem == -1)
{ {
return; return;
} }
if (nItem == nSelItem) if (nItem == nSelItem)
{ {
if (nItem == m_TabCtrl.GetItemCount() - 1) if (nItem == m_TabCtrl.GetItemCount() - 1)
@ -1151,7 +1150,7 @@ void CDebugMemoryView::CloseTab(int nItem)
TabSelChanged(); TabSelChanged();
} }
DeleteTab(nItem); DeleteTab(nItem);
} }
void CDebugMemoryView::CloseCurrentTab(void) void CDebugMemoryView::CloseCurrentTab(void)
@ -1167,14 +1166,14 @@ LRESULT CDebugMemoryView::OnTabDblClick(LPNMHDR /*lpNMHDR*/)
LRESULT CDebugMemoryView::OnTabRClick(LPNMHDR lpNMHDR) LRESULT CDebugMemoryView::OnTabRClick(LPNMHDR lpNMHDR)
{ {
NMMTRCLICK *nmrc = reinterpret_cast<NMMTRCLICK*>(lpNMHDR); NMMTRCLICK * nmrc = reinterpret_cast<NMMTRCLICK *>(lpNMHDR);
CloseTab(nmrc->nItem); CloseTab(nmrc->nItem);
return FALSE; return FALSE;
} }
LRESULT CDebugMemoryView::OnStatusBarClick(LPNMHDR lpNMHDR) LRESULT CDebugMemoryView::OnStatusBarClick(LPNMHDR lpNMHDR)
{ {
NMMOUSE *nmm = reinterpret_cast<NMMOUSE*>(lpNMHDR); NMMOUSE * nmm = reinterpret_cast<NMMOUSE *>(lpNMHDR);
uint32_t startAddress, endAddress; uint32_t startAddress, endAddress;
bool bHaveSelection = m_HexEditCtrl.GetSelectionRange(&startAddress, &endAddress); bool bHaveSelection = m_HexEditCtrl.GetSelectionRange(&startAddress, &endAddress);
@ -1182,7 +1181,7 @@ LRESULT CDebugMemoryView::OnStatusBarClick(LPNMHDR lpNMHDR)
if (nmm->dwItemSpec == MEMSB_DMAINFO) if (nmm->dwItemSpec == MEMSB_DMAINFO)
{ {
uint32_t romAddress, blockOffset; uint32_t romAddress, blockOffset;
DMALOGENTRY* entry = m_Debugger->DMALog()->GetEntryByRamAddress(startAddress, &romAddress, &blockOffset); DMALOGENTRY * entry = m_Debugger->DMALog()->GetEntryByRamAddress(startAddress, &romAddress, &blockOffset);
if (entry == nullptr) if (entry == nullptr)
{ {
@ -1191,7 +1190,7 @@ LRESULT CDebugMemoryView::OnStatusBarClick(LPNMHDR lpNMHDR)
stdstr strDmaTitle = stdstr_f("DMA information for 0x%08X", startAddress); stdstr strDmaTitle = stdstr_f("DMA information for 0x%08X", startAddress);
stdstr strDmaInfo = stdstr_f("Block:\nROM 0x%08X -> RAM 0x%08X ( 0x%X bytes )\n\nROM address of byte:\n0x%08X ( 0x%08X + 0x%08X )", stdstr strDmaInfo = stdstr_f("Block:\nROM 0x%08X -> RAM 0x%08X ( 0x%X bytes )\n\nROM address of byte:\n0x%08X ( 0x%08X + 0x%08X )",
entry->romAddr, entry->ramAddr, entry->length, romAddress, entry->romAddr, blockOffset); entry->romAddr, entry->ramAddr, entry->length, romAddress, entry->romAddr, blockOffset);
MessageBox(strDmaInfo.ToUTF16().c_str(), strDmaTitle.ToUTF16().c_str(), MB_OK); MessageBox(strDmaInfo.ToUTF16().c_str(), strDmaTitle.ToUTF16().c_str(), MB_OK);
} }
else if (nmm->dwItemSpec == MEMSB_BLOCK) else if (nmm->dwItemSpec == MEMSB_BLOCK)
@ -1226,7 +1225,7 @@ void CDebugMemoryView::OnJumpComboSelChange(UINT /*uNotifyCode*/, int /*nID*/, C
{ {
address = JumpItems[nItem].paddr; address = JumpItems[nItem].paddr;
} }
m_MemAddr.SetValue(address, DisplayMode::ZeroExtend); m_MemAddr.SetValue(address, DisplayMode::ZeroExtend);
m_HexEditCtrl.SetFocus(); m_HexEditCtrl.SetFocus();
} }

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "DebuggerUI.h" #include "DebuggerUI.h"
#include "CPULog.h" #include "CPULog.h"
@ -112,7 +113,7 @@ void CDebuggerUI::GamePausedChanged(CDebuggerUI * _this)
_this->m_ScriptSystem->InvokeAppCallbacks(JS_HOOK_EMUSTATECHANGE, &env); _this->m_ScriptSystem->InvokeAppCallbacks(JS_HOOK_EMUSTATECHANGE, &env);
} }
void CDebuggerUI::WaitingForStepChanged(CDebuggerUI* _this) void CDebuggerUI::WaitingForStepChanged(CDebuggerUI * _this)
{ {
if (g_Settings->LoadBool(Debugger_WaitingForStep)) if (g_Settings->LoadBool(Debugger_WaitingForStep))
{ {
@ -360,7 +361,7 @@ void CDebuggerUI::Debug_RefreshScriptsWindow()
} }
} }
void CDebuggerUI::Debug_LogScriptsWindow(const char* text) void CDebuggerUI::Debug_LogScriptsWindow(const char * text)
{ {
if (m_Scripts != nullptr) if (m_Scripts != nullptr)
{ {
@ -462,37 +463,37 @@ void CDebuggerUI::Debug_RefreshCPULogWindow(void)
} }
} }
CBreakpoints* CDebuggerUI::Breakpoints() CBreakpoints * CDebuggerUI::Breakpoints()
{ {
return m_Breakpoints; return m_Breakpoints;
} }
CScriptSystem* CDebuggerUI::ScriptSystem() CScriptSystem * CDebuggerUI::ScriptSystem()
{ {
return m_ScriptSystem; return m_ScriptSystem;
} }
CDebugScripts* CDebuggerUI::ScriptConsole() CDebugScripts * CDebuggerUI::ScriptConsole()
{ {
return m_Scripts; return m_Scripts;
} }
CDMALog* CDebuggerUI::DMALog() CDMALog * CDebuggerUI::DMALog()
{ {
return m_DMALog; return m_DMALog;
} }
CCPULog* CDebuggerUI::CPULog() CCPULog * CDebuggerUI::CPULog()
{ {
return m_CPULog; return m_CPULog;
} }
CSymbolTable* CDebuggerUI::SymbolTable() CSymbolTable * CDebuggerUI::SymbolTable()
{ {
return m_SymbolTable; return m_SymbolTable;
} }
SyncEvent& CDebuggerUI::StepEvent() SyncEvent & CDebuggerUI::StepEvent()
{ {
return m_StepEvent; return m_StepEvent;
} }
@ -511,7 +512,7 @@ void CDebuggerUI::HandleCPUException(void)
int intr = (g_Reg->CAUSE_REGISTER >> 8) & 0xFF; int intr = (g_Reg->CAUSE_REGISTER >> 8) & 0xFF;
int fpExc = (g_Reg->m_FPCR[31] >> 12) & 0x3F; int fpExc = (g_Reg->m_FPCR[31] >> 12) & 0x3F;
int rcpIntr = g_Reg->MI_INTR_REG & 0x2F; int rcpIntr = g_Reg->MI_INTR_REG & 0x2F;
if ((ExceptionBreakpoints() & (1 << exc))) if ((ExceptionBreakpoints() & (1 << exc)))
{ {
if (exc == 15) // Floating-point exception if (exc == 15) // Floating-point exception
@ -568,7 +569,7 @@ void CDebuggerUI::HandleCartToRamDMA(void)
m_DMALog->AddEntry(dmaRomAddr, dmaRamAddr, dmaLen); m_DMALog->AddEntry(dmaRomAddr, dmaRamAddr, dmaLen);
Debug_RefreshDMALogWindow(); Debug_RefreshDMALogWindow();
// Break if write breakpoint exists anywhere in target buffer // Break if write breakpoint exists anywhere in target buffer
if (m_Breakpoints->WriteBPExistsInChunk(dmaRamAddr, dmaLen)) if (m_Breakpoints->WriteBPExistsInChunk(dmaRamAddr, dmaLen))
{ {
@ -584,7 +585,7 @@ void CDebuggerUI::CPUStepStarted()
Debug_RefreshCPULogWindow(); Debug_RefreshCPULogWindow();
} }
if(m_Breakpoints->NumMemLocks() > 0) if (m_Breakpoints->NumMemLocks() > 0)
{ {
COpInfo opInfo(R4300iOp::m_Opcode); COpInfo opInfo(R4300iOp::m_Opcode);
bool bStoreOp = opInfo.IsStoreCommand(); bool bStoreOp = opInfo.IsStoreCommand();
@ -607,20 +608,20 @@ void CDebuggerUI::CPUStepStarted()
hookEnv.pc = g_Reg->m_PROGRAM_COUNTER; hookEnv.pc = g_Reg->m_PROGRAM_COUNTER;
hookEnv.opInfo = COpInfo(R4300iOp::m_Opcode); hookEnv.opInfo = COpInfo(R4300iOp::m_Opcode);
if(m_ScriptSystem->HaveCpuExecCallbacks(hookEnv.pc)) if (m_ScriptSystem->HaveCpuExecCallbacks(hookEnv.pc))
{ {
m_ScriptSystem->InvokeAppCallbacks(JS_HOOK_CPU_EXEC, (void*)&hookEnv); m_ScriptSystem->InvokeAppCallbacks(JS_HOOK_CPU_EXEC, (void *)&hookEnv);
} }
if (hookEnv.opInfo.IsLoadCommand() && if (hookEnv.opInfo.IsLoadCommand() &&
m_ScriptSystem->HaveCpuReadCallbacks(hookEnv.opInfo.GetLoadStoreAddress())) m_ScriptSystem->HaveCpuReadCallbacks(hookEnv.opInfo.GetLoadStoreAddress()))
{ {
m_ScriptSystem->InvokeAppCallbacks(JS_HOOK_CPU_READ, (void*)&hookEnv); m_ScriptSystem->InvokeAppCallbacks(JS_HOOK_CPU_READ, (void *)&hookEnv);
} }
else if (hookEnv.opInfo.IsStoreCommand() && else if (hookEnv.opInfo.IsStoreCommand() &&
m_ScriptSystem->HaveCpuWriteCallbacks(hookEnv.opInfo.GetLoadStoreAddress())) m_ScriptSystem->HaveCpuWriteCallbacks(hookEnv.opInfo.GetLoadStoreAddress()))
{ {
m_ScriptSystem->InvokeAppCallbacks(JS_HOOK_CPU_WRITE, (void*)&hookEnv); m_ScriptSystem->InvokeAppCallbacks(JS_HOOK_CPU_WRITE, (void *)&hookEnv);
} }
} }
@ -691,7 +692,7 @@ void CDebuggerUI::CPUStepEnded()
{ {
return; return;
} }
R4300iOpcode Opcode = R4300iOp::m_Opcode; R4300iOpcode Opcode = R4300iOp::m_Opcode;
uint32_t op = Opcode.op; uint32_t op = Opcode.op;
uint32_t funct = Opcode.funct; uint32_t funct = Opcode.funct;

View File

@ -1,36 +1,37 @@
#include "stdafx.h" #include "stdafx.h"
#include "MemoryScanner.h" #include "MemoryScanner.h"
CMixed::TypeNameEntry CMixed::TypeNames[] = { CMixed::TypeNameEntry CMixed::TypeNames[] = {
{ "uint8", ValueType_uint8 }, {"uint8", ValueType_uint8},
{ "int8", ValueType_int8 }, {"int8", ValueType_int8},
{ "uint16", ValueType_uint16 }, {"uint16", ValueType_uint16},
{ "int16", ValueType_int16 }, {"int16", ValueType_int16},
{ "uint32", ValueType_uint32 }, {"uint32", ValueType_uint32},
{ "int32", ValueType_int32 }, {"int32", ValueType_int32},
{ "uint64", ValueType_uint64 }, {"uint64", ValueType_uint64},
{ "int64", ValueType_int64 }, {"int64", ValueType_int64},
{ "float", ValueType_float }, {"float", ValueType_float},
{ "double", ValueType_double }, {"double", ValueType_double},
{ "char", ValueType_string }, {"char", ValueType_string},
{ "char", ValueType_unkstring }, {"char", ValueType_unkstring},
{ "char", ValueType_unkstring }, {"char", ValueType_unkstring},
{ nullptr, ValueType_invalid} { nullptr, ValueType_invalid}
}; };
const char* CMixed::GetTypeName(void) const char * CMixed::GetTypeName(void)
{ {
switch (m_Type) switch (m_Type)
{ {
case ValueType_uint8: return "uint8"; case ValueType_uint8: return "uint8";
case ValueType_int8: return "int8"; case ValueType_int8: return "int8";
case ValueType_uint16: return "uint16"; case ValueType_uint16: return "uint16";
case ValueType_int16: return "int16"; case ValueType_int16: return "int16";
case ValueType_uint32: return "uint32"; case ValueType_uint32: return "uint32";
case ValueType_int32: return "int32"; case ValueType_int32: return "int32";
case ValueType_uint64: return "uint64"; case ValueType_uint64: return "uint64";
case ValueType_int64: return "int64"; case ValueType_int64: return "int64";
case ValueType_float: return "float"; case ValueType_float: return "float";
case ValueType_double: return "double"; case ValueType_double: return "double";
case ValueType_string: case ValueType_string:
case ValueType_istring: case ValueType_istring:
@ -41,7 +42,7 @@ const char* CMixed::GetTypeName(void)
return nullptr; return nullptr;
} }
ValueType CMixed::GetTypeFromString(const char* name, int* charArrayLength) ValueType CMixed::GetTypeFromString(const char * name, int * charArrayLength)
{ {
for (int i = 0; TypeNames[i].name != nullptr; i++) for (int i = 0; TypeNames[i].name != nullptr; i++)
{ {
@ -64,15 +65,15 @@ int CMixed::GetTypeSize(void)
{ {
switch (m_Type) switch (m_Type)
{ {
case ValueType_uint8: return sizeof(uint8_t); case ValueType_uint8: return sizeof(uint8_t);
case ValueType_int8: return sizeof(int8_t); case ValueType_int8: return sizeof(int8_t);
case ValueType_uint16: return sizeof(uint16_t); case ValueType_uint16: return sizeof(uint16_t);
case ValueType_int16: return sizeof(int16_t); case ValueType_int16: return sizeof(int16_t);
case ValueType_uint32: return sizeof(uint32_t); case ValueType_uint32: return sizeof(uint32_t);
case ValueType_int32: return sizeof(int32_t); case ValueType_int32: return sizeof(int32_t);
case ValueType_uint64: return sizeof(uint64_t); case ValueType_uint64: return sizeof(uint64_t);
case ValueType_int64: return sizeof(int64_t); case ValueType_int64: return sizeof(int64_t);
case ValueType_float: return sizeof(float); case ValueType_float: return sizeof(float);
case ValueType_double: return sizeof(double); case ValueType_double: return sizeof(double);
case ValueType_string: case ValueType_string:
case ValueType_istring: case ValueType_istring:
@ -96,7 +97,7 @@ bool CMixed::IsStringType(void)
return false; return false;
} }
int CMixed::ToString(char* buffer, bool bHex, size_t size) int CMixed::ToString(char * buffer, bool bHex, size_t size)
{ {
if (bHex) if (bHex)
{ {
@ -123,15 +124,15 @@ int CMixed::ToString(char* buffer, bool bHex, size_t size)
switch (m_Type) switch (m_Type)
{ {
case ValueType_uint8: return snprintf(buffer, size, "%d", m_Value._uint8); case ValueType_uint8: return snprintf(buffer, size, "%d", m_Value._uint8);
case ValueType_int8: return snprintf(buffer, size, "%d", m_Value._sint8); case ValueType_int8: return snprintf(buffer, size, "%d", m_Value._sint8);
case ValueType_uint16: return snprintf(buffer, size, "%d", m_Value._uint16); case ValueType_uint16: return snprintf(buffer, size, "%d", m_Value._uint16);
case ValueType_int16: return snprintf(buffer, size, "%d", m_Value._sint16); case ValueType_int16: return snprintf(buffer, size, "%d", m_Value._sint16);
case ValueType_uint32: return snprintf(buffer, size, "%lu", m_Value._uint32); case ValueType_uint32: return snprintf(buffer, size, "%lu", m_Value._uint32);
case ValueType_int32: return snprintf(buffer, size, "%d", m_Value._sint32); case ValueType_int32: return snprintf(buffer, size, "%d", m_Value._sint32);
case ValueType_uint64: return snprintf(buffer, size, "%llu", m_Value._uint64); case ValueType_uint64: return snprintf(buffer, size, "%llu", m_Value._uint64);
case ValueType_int64: return snprintf(buffer, size, "%lld", m_Value._sint64); case ValueType_int64: return snprintf(buffer, size, "%lld", m_Value._sint64);
case ValueType_float: return snprintf(buffer, size, "%f", m_Value._float); case ValueType_float: return snprintf(buffer, size, "%f", m_Value._float);
case ValueType_double: return snprintf(buffer, size, "%f", m_Value._double); case ValueType_double: return snprintf(buffer, size, "%f", m_Value._double);
default: return snprintf(buffer, size, "?"); default: return snprintf(buffer, size, "?");
} }
@ -149,7 +150,7 @@ CScanResult::~CScanResult(void)
{ {
} }
void CScanResult::SetDescription(const char* str) void CScanResult::SetDescription(const char * str)
{ {
m_Description = str; m_Description = str;
} }
@ -159,18 +160,18 @@ void CScanResult::DeleteDescription(void)
m_Description.clear(); m_Description.clear();
} }
const char* CScanResult::GetDescription(void) const char * CScanResult::GetDescription(void)
{ {
return m_Description.c_str(); return m_Description.c_str();
} }
int CScanResult::GetValueString(char *buffer, size_t size) int CScanResult::GetValueString(char * buffer, size_t size)
{ {
bool bHex = (m_DisplayFormat == DisplayHex); bool bHex = (m_DisplayFormat == DisplayHex);
return ToString(buffer, bHex, size); return ToString(buffer, bHex, size);
} }
bool CScanResult::GetMemoryValue(CMixed* v) bool CScanResult::GetMemoryValue(CMixed * v)
{ {
if (g_MMU == nullptr) if (g_MMU == nullptr)
{ {
@ -184,41 +185,41 @@ bool CScanResult::GetMemoryValue(CMixed* v)
return false; return false;
} }
uint8_t* mem = CMemoryScanner::GetMemoryPool(paddr); uint8_t * mem = CMemoryScanner::GetMemoryPool(paddr);
uint64_t raw64 = 0; uint64_t raw64 = 0;
if (GetTypeSize() == 8) if (GetTypeSize() == 8)
{ {
raw64 = ((uint64_t)*(uint32_t*)&mem[paddr] << 32) | *(uint32_t*)&mem[paddr + 4]; raw64 = ((uint64_t) * (uint32_t *)&mem[paddr] << 32) | *(uint32_t *)&mem[paddr + 4];
} }
switch (m_Type) switch (m_Type)
{ {
case ValueType_uint8: v->Set(*(uint8_t*) &mem[paddr ^ 3]); break; case ValueType_uint8: v->Set(*(uint8_t *)&mem[paddr ^ 3]); break;
case ValueType_int8: v->Set(*(int8_t*) &mem[paddr ^ 3]); break; case ValueType_int8: v->Set(*(int8_t *)&mem[paddr ^ 3]); break;
case ValueType_uint16: v->Set(*(uint16_t*)&mem[paddr ^ 2]); break; case ValueType_uint16: v->Set(*(uint16_t *)&mem[paddr ^ 2]); break;
case ValueType_int16: v->Set(*(int16_t*) &mem[paddr ^ 2]); break; case ValueType_int16: v->Set(*(int16_t *)&mem[paddr ^ 2]); break;
case ValueType_uint32: v->Set(*(uint32_t*)&mem[paddr]); break; case ValueType_uint32: v->Set(*(uint32_t *)&mem[paddr]); break;
case ValueType_int32: v->Set(*(int32_t*)&mem[paddr]); break; case ValueType_int32: v->Set(*(int32_t *)&mem[paddr]); break;
case ValueType_uint64: v->Set(*(uint64_t*)&raw64); break; case ValueType_uint64: v->Set(*(uint64_t *)&raw64); break;
case ValueType_int64: v->Set(*(int64_t*)&raw64); break; case ValueType_int64: v->Set(*(int64_t *)&raw64); break;
case ValueType_float: v->Set(*(float*)&mem[paddr]); break; case ValueType_float: v->Set(*(float *)&mem[paddr]); break;
case ValueType_double: v->Set(*(double*)&raw64); break; case ValueType_double: v->Set(*(double *)&raw64); break;
default: return false; // (primitives only) default: return false; // (primitives only)
} }
return true; return true;
} }
int CScanResult::GetMemoryValueString(char* buffer, size_t size, bool bIgnoreHex) int CScanResult::GetMemoryValueString(char * buffer, size_t size, bool bIgnoreHex)
{ {
if (g_MMU == nullptr) if (g_MMU == nullptr)
{ {
sprintf(buffer, "?"); sprintf(buffer, "?");
return 1; return 1;
} }
bool bHex = (m_DisplayFormat == DisplayHex) && !bIgnoreHex; bool bHex = (m_DisplayFormat == DisplayHex) && !bIgnoreHex;
uint32_t paddr = m_Address & 0x1FFFFFFF; uint32_t paddr = m_Address & 0x1FFFFFFF;
@ -228,15 +229,15 @@ int CScanResult::GetMemoryValueString(char* buffer, size_t size, bool bIgnoreHex
return sprintf(buffer, "?"); return sprintf(buffer, "?");
} }
uint8_t* mem = CMemoryScanner::GetMemoryPool(paddr); uint8_t * mem = CMemoryScanner::GetMemoryPool(paddr);
if (m_Type == ValueType_istring || if (m_Type == ValueType_istring ||
m_Type == ValueType_string || m_Type == ValueType_string ||
m_Type == ValueType_unkstring) m_Type == ValueType_unkstring)
{ {
if (bHex) if (bHex)
{ {
char* out = buffer; char * out = buffer;
for (int i = 0; i < m_StrLength; i++) for (int i = 0; i < m_StrLength; i++)
{ {
@ -268,7 +269,7 @@ int CScanResult::GetMemoryValueString(char* buffer, size_t size, bool bIgnoreHex
return memVal.ToString(buffer, bHex, size); return memVal.ToString(buffer, bHex, size);
} }
int CScanResult::GetAddressString(char *buffer) int CScanResult::GetAddressString(char * buffer)
{ {
return sprintf(buffer, "0x%08X", m_Address); return sprintf(buffer, "0x%08X", m_Address);
} }
@ -286,7 +287,7 @@ uint32_t CScanResult::GetVirtualAddress(void)
} }
} }
bool CScanResult::SetMemoryValueFromString(const char* str) bool CScanResult::SetMemoryValueFromString(const char * str)
{ {
if (g_MMU == nullptr) if (g_MMU == nullptr)
{ {
@ -303,9 +304,9 @@ bool CScanResult::SetMemoryValueFromString(const char* str)
return false; return false;
} }
uint8_t* mem = CMemoryScanner::GetMemoryPool(m_Address & 0x1FFFFFFF); uint8_t * mem = CMemoryScanner::GetMemoryPool(m_Address & 0x1FFFFFFF);
char* endptr; char * endptr;
uint64_t intVal = strtoull(str, &endptr, 0); uint64_t intVal = strtoull(str, &endptr, 0);
double doubleVal = strtod(str, &endptr); double doubleVal = strtod(str, &endptr);
@ -317,32 +318,32 @@ bool CScanResult::SetMemoryValueFromString(const char* str)
break; break;
case ValueType_uint16: case ValueType_uint16:
case ValueType_int16: case ValueType_int16:
*(uint16_t*)&mem[paddr ^ 2] = intVal & 0xFFFF; *(uint16_t *)&mem[paddr ^ 2] = intVal & 0xFFFF;
break; break;
case ValueType_uint32: case ValueType_uint32:
case ValueType_int32: case ValueType_int32:
*(uint32_t*)&mem[paddr] = intVal & 0xFFFFFFFF; *(uint32_t *)&mem[paddr] = intVal & 0xFFFFFFFF;
break; break;
case ValueType_uint64: case ValueType_uint64:
case ValueType_int64: case ValueType_int64:
*(uint64_t*)&mem[paddr] = (intVal << 32) | (intVal >> 32); *(uint64_t *)&mem[paddr] = (intVal << 32) | (intVal >> 32);
break; break;
case ValueType_float: case ValueType_float:
if (bHex) if (bHex)
{ {
*(uint32_t*)&mem[paddr] = intVal & 0xFFFFFFFF; *(uint32_t *)&mem[paddr] = intVal & 0xFFFFFFFF;
break; break;
} }
*(float*)&mem[paddr] = (float)doubleVal; *(float *)&mem[paddr] = (float)doubleVal;
break; break;
case ValueType_double: case ValueType_double:
if (bHex) if (bHex)
{ {
*(uint64_t*)&mem[paddr] = (intVal << 32) | (intVal >> 32); *(uint64_t *)&mem[paddr] = (intVal << 32) | (intVal >> 32);
break; break;
} }
intVal = *(uint64_t*)&doubleVal; intVal = *(uint64_t *)&doubleVal;
*(uint64_t*)&mem[paddr] = (intVal << 32) | (intVal >> 32); *(uint64_t *)&mem[paddr] = (intVal << 32) | (intVal >> 32);
break; break;
case ValueType_string: case ValueType_string:
case ValueType_istring: case ValueType_istring:
@ -355,7 +356,7 @@ bool CScanResult::SetMemoryValueFromString(const char* str)
return false; return false;
} }
char* buff = new char[size]; char * buff = new char[size];
CMemoryScanner::ParseHexString(buff, str); CMemoryScanner::ParseHexString(buff, str);
for (int i = 0; i < m_StrLength; i++) for (int i = 0; i < m_StrLength; i++)
@ -488,15 +489,15 @@ bool CMemoryScanner::PAddrValid(uint32_t physAddr)
uint32_t romSize = g_Rom->GetRomSize(); uint32_t romSize = g_Rom->GetRomSize();
return (AddrCheck(physAddr, 0x00000000, 0x00000000 + ramSize - 1) || return (AddrCheck(physAddr, 0x00000000, 0x00000000 + ramSize - 1) ||
AddrCheck(physAddr, 0x10000000, 0x10000000 + romSize - 1) || AddrCheck(physAddr, 0x10000000, 0x10000000 + romSize - 1) ||
AddrCheck(physAddr, 0x04000000, 0x04001FFF)); AddrCheck(physAddr, 0x04000000, 0x04001FFF));
} }
bool CMemoryScanner::PAddrRangeValid(uint32_t physAddrStart, uint32_t physAddrEnd) bool CMemoryScanner::PAddrRangeValid(uint32_t physAddrStart, uint32_t physAddrEnd)
{ {
return (RangeCheck(physAddrStart, physAddrEnd, 0x00000000, g_MMU->RdramSize()) || return (RangeCheck(physAddrStart, physAddrEnd, 0x00000000, g_MMU->RdramSize()) ||
RangeCheck(physAddrStart, physAddrEnd, 0x04000000, 0x04001FFF) || RangeCheck(physAddrStart, physAddrEnd, 0x04000000, 0x04001FFF) ||
RangeCheck(physAddrStart, physAddrEnd, 0x10000000, 0x15FFFFFF)); RangeCheck(physAddrStart, physAddrEnd, 0x10000000, 0x15FFFFFF));
} }
void CMemoryScanner::SetAddressType(AddressType addressType) void CMemoryScanner::SetAddressType(AddressType addressType)
@ -510,7 +511,7 @@ void CMemoryScanner::Reset(void)
m_ValueType = ValueType_uint8; m_ValueType = ValueType_uint8;
m_SearchType = SearchType_ExactValue; m_SearchType = SearchType_ExactValue;
m_Results.clear(); m_Results.clear();
} }
@ -521,7 +522,7 @@ bool CMemoryScanner::SetAddressRange(uint32_t startAddress, uint32_t endAddress)
return false; return false;
} }
if(m_DidFirstScan) if (m_DidFirstScan)
{ {
return false; return false;
} }
@ -571,7 +572,7 @@ bool CMemoryScanner::SetAddressRange(uint32_t startAddress, uint32_t endAddress)
{ {
return false; // Invalid range return false; // Invalid range
} }
m_Memory = GetMemoryPool(startAddress); m_Memory = GetMemoryPool(startAddress);
m_RangeStartAddress = startAddress; m_RangeStartAddress = startAddress;
@ -579,7 +580,7 @@ bool CMemoryScanner::SetAddressRange(uint32_t startAddress, uint32_t endAddress)
return true; return true;
} }
uint8_t* CMemoryScanner::GetMemoryPool(uint32_t physAddr) uint8_t * CMemoryScanner::GetMemoryPool(uint32_t physAddr)
{ {
if (!g_MMU || !g_Rom) if (!g_MMU || !g_Rom)
{ {
@ -599,17 +600,16 @@ uint8_t* CMemoryScanner::GetMemoryPool(uint32_t physAddr)
{ {
return nullptr; return nullptr;
} }
} }
bool CMemoryScanner::SetValueType(ValueType type) bool CMemoryScanner::SetValueType(ValueType type)
{ {
if(m_DidFirstScan) if (m_DidFirstScan)
{ {
return false; return false;
} }
switch(type) switch (type)
{ {
case ValueType_string: case ValueType_string:
case ValueType_istring: case ValueType_istring:
@ -620,7 +620,7 @@ bool CMemoryScanner::SetValueType(ValueType type)
m_bDataTypePrimitive = true; m_bDataTypePrimitive = true;
break; break;
} }
m_ValueType = type; m_ValueType = type;
return true; return true;
} }
@ -632,12 +632,12 @@ void CMemoryScanner::SetStringValueLength(int length)
bool CMemoryScanner::SetSearchType(SearchType searchType) bool CMemoryScanner::SetSearchType(SearchType searchType)
{ {
if(!m_bDataTypePrimitive) if (!m_bDataTypePrimitive)
{ {
return false; return false;
} }
switch(searchType) switch (searchType)
{ {
case SearchType_UnknownValue: case SearchType_UnknownValue:
case SearchType_JalTo: case SearchType_JalTo:
@ -650,13 +650,13 @@ bool CMemoryScanner::SetSearchType(SearchType searchType)
case SearchType_UnchangedValue: case SearchType_UnchangedValue:
case SearchType_IncreasedValue: case SearchType_IncreasedValue:
case SearchType_DecreasedValue: case SearchType_DecreasedValue:
if(!m_DidFirstScan) if (!m_DidFirstScan)
{ {
return false; return false;
} }
break; break;
} }
m_SearchType = searchType; m_SearchType = searchType;
return true; return true;
} }
@ -671,7 +671,7 @@ size_t CMemoryScanner::GetNumResults(void)
return m_Results.size(); return m_Results.size();
} }
CScanResult* CMemoryScanner::GetResult(size_t index) CScanResult * CMemoryScanner::GetResult(size_t index)
{ {
if (index >= m_Results.size()) if (index >= m_Results.size())
{ {
@ -679,7 +679,7 @@ CScanResult* CMemoryScanner::GetResult(size_t index)
} }
return &m_Results[index]; return &m_Results[index];
} }
void CMemoryScanner::RemoveResult(size_t index) void CMemoryScanner::RemoveResult(size_t index)
{ {
@ -714,7 +714,7 @@ void CMemoryScanner::FirstScanLoopString(DisplayFormat resultDisplayFormat)
} }
result.m_Address = addr | m_VAddrBits; result.m_Address = addr | m_VAddrBits;
result.Set((const wchar_t*)nullptr); result.Set((const wchar_t *)nullptr);
m_Results.push_back(result); m_Results.push_back(result);
next_addr:; next_addr:;
} }
@ -743,7 +743,7 @@ void CMemoryScanner::FirstScanLoopIString(DisplayFormat resultDisplayFormat)
} }
result.m_Address = addr | m_VAddrBits; result.m_Address = addr | m_VAddrBits;
result.Set((const wchar_t*)nullptr); result.Set((const wchar_t *)nullptr);
m_Results.push_back(result); m_Results.push_back(result);
next_addr:; next_addr:;
} }
@ -752,9 +752,9 @@ void CMemoryScanner::FirstScanLoopIString(DisplayFormat resultDisplayFormat)
// Scan for text of unknown single-byte encoding // Scan for text of unknown single-byte encoding
void CMemoryScanner::FirstScanLoopUnkString(void) void CMemoryScanner::FirstScanLoopUnkString(void)
{ {
const char* str = stdstr().FromUTF16(m_Value._string).c_str(); const char * str = stdstr().FromUTF16(m_Value._string).c_str();
int length = m_StringValueLength; int length = m_StringValueLength;
uint32_t startAddr = m_RangeStartAddress; uint32_t startAddr = m_RangeStartAddress;
uint32_t endAddr = m_RangeEndAddress - length; uint32_t endAddr = m_RangeEndAddress - length;
@ -816,7 +816,7 @@ void CMemoryScanner::FirstScanLoopUnkString(void)
} }
result.m_Address = addr | m_VAddrBits; result.m_Address = addr | m_VAddrBits;
result.Set((const wchar_t*)nullptr); result.Set((const wchar_t *)nullptr);
m_Results.push_back(result); m_Results.push_back(result);
next_addr:; next_addr:;
@ -826,19 +826,19 @@ void CMemoryScanner::FirstScanLoopUnkString(void)
#define _FirstScanLoopPrimitive(T, Compare, resDisplayFormat) FirstScanLoopPrimitive<T>(Compare<T>, resDisplayFormat) #define _FirstScanLoopPrimitive(T, Compare, resDisplayFormat) FirstScanLoopPrimitive<T>(Compare<T>, resDisplayFormat)
#define _FirstScanLoopPrimitive64(T, Compare, resDisplayFormat) FirstScanLoopPrimitive64<T>(Compare<T>, resDisplayFormat) #define _FirstScanLoopPrimitive64(T, Compare, resDisplayFormat) FirstScanLoopPrimitive64<T>(Compare<T>, resDisplayFormat)
#define FIRST_SCAN_PRIMITIVES(CompareFunc) \ #define FIRST_SCAN_PRIMITIVES(CompareFunc) \
switch(m_ValueType) \ switch (m_ValueType) \
{ \ { \
case ValueType_uint8: _FirstScanLoopPrimitive(uint8_t, CompareFunc, resDisplayFormat); break; \ case ValueType_uint8: _FirstScanLoopPrimitive(uint8_t, CompareFunc, resDisplayFormat); break; \
case ValueType_int8: _FirstScanLoopPrimitive(int8_t, CompareFunc, resDisplayFormat); break; \ case ValueType_int8: _FirstScanLoopPrimitive(int8_t, CompareFunc, resDisplayFormat); break; \
case ValueType_uint16: _FirstScanLoopPrimitive(uint16_t, CompareFunc, resDisplayFormat); break; \ case ValueType_uint16: _FirstScanLoopPrimitive(uint16_t, CompareFunc, resDisplayFormat); break; \
case ValueType_int16: _FirstScanLoopPrimitive(int16_t, CompareFunc, resDisplayFormat); break; \ case ValueType_int16: _FirstScanLoopPrimitive(int16_t, CompareFunc, resDisplayFormat); break; \
case ValueType_uint32: _FirstScanLoopPrimitive(uint32_t, CompareFunc, resDisplayFormat); break; \ case ValueType_uint32: _FirstScanLoopPrimitive(uint32_t, CompareFunc, resDisplayFormat); break; \
case ValueType_int32: _FirstScanLoopPrimitive(int32_t, CompareFunc, resDisplayFormat); break; \ case ValueType_int32: _FirstScanLoopPrimitive(int32_t, CompareFunc, resDisplayFormat); break; \
case ValueType_uint64: _FirstScanLoopPrimitive64(uint64_t, CompareFunc, resDisplayFormat); break; \ case ValueType_uint64: _FirstScanLoopPrimitive64(uint64_t, CompareFunc, resDisplayFormat); break; \
case ValueType_int64: _FirstScanLoopPrimitive64(int64_t, CompareFunc, resDisplayFormat); break; \ case ValueType_int64: _FirstScanLoopPrimitive64(int64_t, CompareFunc, resDisplayFormat); break; \
case ValueType_float: _FirstScanLoopPrimitive(float, CompareFunc, resDisplayFormat); break; \ case ValueType_float: _FirstScanLoopPrimitive(float, CompareFunc, resDisplayFormat); break; \
case ValueType_double: _FirstScanLoopPrimitive64(double, CompareFunc, resDisplayFormat); break; \ case ValueType_double: _FirstScanLoopPrimitive64(double, CompareFunc, resDisplayFormat); break; \
} }
bool CMemoryScanner::FirstScan(DisplayFormat resDisplayFormat) bool CMemoryScanner::FirstScan(DisplayFormat resDisplayFormat)
@ -902,35 +902,35 @@ bool CMemoryScanner::FirstScan(DisplayFormat resDisplayFormat)
#define _NextScanLoopPrimitiveResults64(T, Compare) NextScanLoopPrimitiveResults64<T>(Compare<T>) #define _NextScanLoopPrimitiveResults64(T, Compare) NextScanLoopPrimitiveResults64<T>(Compare<T>)
// Compare result's current value in memory against m_Value // Compare result's current value in memory against m_Value
#define NEXT_SCAN_PRIMITIVES_AGAINST_VALUE(CompareFunc) \ #define NEXT_SCAN_PRIMITIVES_AGAINST_VALUE(CompareFunc) \
switch(m_ValueType) \ switch (m_ValueType) \
{ \ { \
case ValueType_uint8: _NextScanLoopPrimitive(uint8_t, CompareFunc); break; \ case ValueType_uint8: _NextScanLoopPrimitive(uint8_t, CompareFunc); break; \
case ValueType_int8: _NextScanLoopPrimitive(int8_t, CompareFunc); break; \ case ValueType_int8: _NextScanLoopPrimitive(int8_t, CompareFunc); break; \
case ValueType_uint16: _NextScanLoopPrimitive(uint16_t, CompareFunc); break; \ case ValueType_uint16: _NextScanLoopPrimitive(uint16_t, CompareFunc); break; \
case ValueType_int16: _NextScanLoopPrimitive(int16_t, CompareFunc); break; \ case ValueType_int16: _NextScanLoopPrimitive(int16_t, CompareFunc); break; \
case ValueType_uint32: _NextScanLoopPrimitive(uint32_t, CompareFunc); break; \ case ValueType_uint32: _NextScanLoopPrimitive(uint32_t, CompareFunc); break; \
case ValueType_int32: _NextScanLoopPrimitive(int32_t, CompareFunc); break; \ case ValueType_int32: _NextScanLoopPrimitive(int32_t, CompareFunc); break; \
case ValueType_uint64: _NextScanLoopPrimitive64(uint64_t, CompareFunc); break; \ case ValueType_uint64: _NextScanLoopPrimitive64(uint64_t, CompareFunc); break; \
case ValueType_int64: _NextScanLoopPrimitive64(int64_t, CompareFunc); break; \ case ValueType_int64: _NextScanLoopPrimitive64(int64_t, CompareFunc); break; \
case ValueType_float: _NextScanLoopPrimitive(float, CompareFunc); break; \ case ValueType_float: _NextScanLoopPrimitive(float, CompareFunc); break; \
case ValueType_double: _NextScanLoopPrimitive64(double, CompareFunc); break; \ case ValueType_double: _NextScanLoopPrimitive64(double, CompareFunc); break; \
} }
// Compare result's current value in memory against result's old value // Compare result's current value in memory against result's old value
#define NEXT_SCAN_PRIMITIVES_AGAINST_RESULTS(CompareFunc) \ #define NEXT_SCAN_PRIMITIVES_AGAINST_RESULTS(CompareFunc) \
switch(m_ValueType) \ switch (m_ValueType) \
{ \ { \
case ValueType_uint8: _NextScanLoopPrimitiveResults(uint8_t, CompareFunc); break; \ case ValueType_uint8: _NextScanLoopPrimitiveResults(uint8_t, CompareFunc); break; \
case ValueType_int8: _NextScanLoopPrimitiveResults(int8_t, CompareFunc); break; \ case ValueType_int8: _NextScanLoopPrimitiveResults(int8_t, CompareFunc); break; \
case ValueType_uint16: _NextScanLoopPrimitiveResults(uint16_t, CompareFunc); break; \ case ValueType_uint16: _NextScanLoopPrimitiveResults(uint16_t, CompareFunc); break; \
case ValueType_int16: _NextScanLoopPrimitiveResults(int16_t, CompareFunc); break; \ case ValueType_int16: _NextScanLoopPrimitiveResults(int16_t, CompareFunc); break; \
case ValueType_uint32: _NextScanLoopPrimitiveResults(uint32_t, CompareFunc); break; \ case ValueType_uint32: _NextScanLoopPrimitiveResults(uint32_t, CompareFunc); break; \
case ValueType_int32: _NextScanLoopPrimitiveResults(int32_t, CompareFunc); break; \ case ValueType_int32: _NextScanLoopPrimitiveResults(int32_t, CompareFunc); break; \
case ValueType_uint64: _NextScanLoopPrimitiveResults64(uint64_t, CompareFunc); break; \ case ValueType_uint64: _NextScanLoopPrimitiveResults64(uint64_t, CompareFunc); break; \
case ValueType_int64: _NextScanLoopPrimitiveResults64(int64_t, CompareFunc); break; \ case ValueType_int64: _NextScanLoopPrimitiveResults64(int64_t, CompareFunc); break; \
case ValueType_float: _NextScanLoopPrimitiveResults(float, CompareFunc); break; \ case ValueType_float: _NextScanLoopPrimitiveResults(float, CompareFunc); break; \
case ValueType_double: _NextScanLoopPrimitiveResults64(double, CompareFunc); break; \ case ValueType_double: _NextScanLoopPrimitiveResults64(double, CompareFunc); break; \
} }
bool CMemoryScanner::NextScan() bool CMemoryScanner::NextScan()
@ -940,8 +940,8 @@ bool CMemoryScanner::NextScan()
// NextScan does not support complex data // NextScan does not support complex data
return false; return false;
} }
switch(m_SearchType) switch (m_SearchType)
{ {
case SearchType_ExactValue: case SearchType_ExactValue:
NEXT_SCAN_PRIMITIVES_AGAINST_VALUE(CompareEqual); NEXT_SCAN_PRIMITIVES_AGAINST_VALUE(CompareEqual);
@ -972,11 +972,10 @@ bool CMemoryScanner::NextScan()
NEXT_SCAN_PRIMITIVES_AGAINST_RESULTS(CompareLessThan); NEXT_SCAN_PRIMITIVES_AGAINST_RESULTS(CompareLessThan);
break; break;
} }
return true; return true;
} }
int CMemoryScanner::HexDigitVal(char c) int CMemoryScanner::HexDigitVal(char c)
{ {
if (c >= '0' && c <= '9') return (c - '0'); if (c >= '0' && c <= '9') return (c - '0');
@ -985,7 +984,7 @@ int CMemoryScanner::HexDigitVal(char c)
return 0; return 0;
} }
int CMemoryScanner::ParseHexString(char *dst, const char* src) int CMemoryScanner::ParseHexString(char * dst, const char * src)
{ {
bool bHiNibble = true; bool bHiNibble = true;
uint8_t curByte = 0; uint8_t curByte = 0;

View File

@ -1,6 +1,4 @@
#pragma once #pragma once
#include <stdafx.h>
#include <string> #include <string>
enum ValueType enum ValueType

View File

@ -1,7 +1,5 @@
#pragma once #pragma once
#include <stdafx.h>
#include <Project64-core/N64System/Mips/R4300iOpcode.h> #include <Project64-core/N64System/Mips/R4300iOpcode.h>
class COpInfo class COpInfo

View File

@ -1,9 +1,10 @@
#include <stdafx.h> #include "stdafx.h"
#include "JSIntervalWorker.h"
#include "../ScriptInstance.h" #include "../ScriptInstance.h"
#include "JSIntervalWorker.h"
#include "ScriptAPI.h" #include "ScriptAPI.h"
CJSIntervalWorker::CJSIntervalWorker(CScriptInstance* inst, void* dukObjectHeapPtr, int delayMS, bool bOnce) : CJSIntervalWorker::CJSIntervalWorker(CScriptInstance * inst, void * dukObjectHeapPtr, int delayMS, bool bOnce) :
CScriptWorker(inst, dukObjectHeapPtr), CScriptWorker(inst, dukObjectHeapPtr),
m_DelayMS(delayMS), m_DelayMS(delayMS),
m_bOnce(bOnce) m_bOnce(bOnce)
@ -25,7 +26,7 @@ void CJSIntervalWorker::WorkerProc()
liTime.QuadPart = -m_DelayMS * 10000; liTime.QuadPart = -m_DelayMS * 10000;
SetWaitableTimer(hTimer, &liTime, m_DelayMS, nullptr, nullptr, true); SetWaitableTimer(hTimer, &liTime, m_DelayMS, nullptr, nullptr, true);
HANDLE hWaitHandles[] = { hTimer, m_hTimerQuitEvent }; HANDLE hWaitHandles[] = {hTimer, m_hTimerQuitEvent};
while (true) while (true)
{ {

View File

@ -1,4 +1,5 @@
#include <stdafx.h> #include "stdafx.h"
#include "JSServerWorker.h" #include "JSServerWorker.h"
#include "JSSocketWorker.h" #include "JSSocketWorker.h"
@ -171,7 +172,7 @@ unsigned short CJSServerWorker::GetPort()
return m_Address.port; return m_Address.port;
} }
const char* CJSServerWorker::GetFamily() const char * CJSServerWorker::GetFamily()
{ {
CGuard guard(m_CS); CGuard guard(m_CS);
return m_Address.family; return m_Address.family;
@ -180,32 +181,32 @@ const char* CJSServerWorker::GetFamily()
void CJSServerWorker::JSEmitConnection(SOCKET c) void CJSServerWorker::JSEmitConnection(SOCKET c)
{ {
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js__Emitter_emit, m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js__Emitter_emit,
CbArgs_EmitConnection, (void*)&c, sizeof(c)); CbArgs_EmitConnection, (void *)&c, sizeof(c));
} }
void CJSServerWorker::JSEmitClose() void CJSServerWorker::JSEmitClose()
{ {
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js__Emitter_emit, m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js__Emitter_emit,
CbArgs_EmitClose); CbArgs_EmitClose);
} }
void CJSServerWorker::JSEmitListening() void CJSServerWorker::JSEmitListening()
{ {
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js__Emitter_emit, m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js__Emitter_emit,
CbArgs_EmitListening); CbArgs_EmitListening);
} }
void CJSServerWorker::JSEmitError(const char* errMessage) void CJSServerWorker::JSEmitError(const char * errMessage)
{ {
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js__Emitter_emit, m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js__Emitter_emit,
CbArgs_EmitError, (void*)errMessage, strlen(errMessage) + 1); CbArgs_EmitError, (void *)errMessage, strlen(errMessage) + 1);
} }
duk_idx_t CJSServerWorker::CbArgs_EmitConnection(duk_context* ctx, void* _env) duk_idx_t CJSServerWorker::CbArgs_EmitConnection(duk_context * ctx, void * _env)
{ {
duk_push_string(ctx, "connection"); duk_push_string(ctx, "connection");
SOCKET client = *(SOCKET*)_env; SOCKET client = *(SOCKET *)_env;
duk_push_global_object(ctx); duk_push_global_object(ctx);
duk_get_prop_string(ctx, -1, "Socket"); duk_get_prop_string(ctx, -1, "Socket");
duk_remove(ctx, -2); duk_remove(ctx, -2);
@ -214,7 +215,7 @@ duk_idx_t CJSServerWorker::CbArgs_EmitConnection(duk_context* ctx, void* _env)
ScriptAPI::RefObject(ctx, -1); ScriptAPI::RefObject(ctx, -1);
duk_get_prop_string(ctx, -1, HS_socketWorkerPtr); duk_get_prop_string(ctx, -1, HS_socketWorkerPtr);
CJSSocketWorker* socketWorker = (CJSSocketWorker*)duk_get_pointer(ctx, -1); CJSSocketWorker * socketWorker = (CJSSocketWorker *)duk_get_pointer(ctx, -1);
duk_pop(ctx); duk_pop(ctx);
socketWorker->Init(client); socketWorker->Init(client);
@ -223,21 +224,21 @@ duk_idx_t CJSServerWorker::CbArgs_EmitConnection(duk_context* ctx, void* _env)
return 2; return 2;
} }
duk_idx_t CJSServerWorker::CbArgs_EmitClose(duk_context* ctx, void* /*_env*/) duk_idx_t CJSServerWorker::CbArgs_EmitClose(duk_context * ctx, void * /*_env*/)
{ {
duk_push_string(ctx, "close"); duk_push_string(ctx, "close");
return 1; return 1;
} }
duk_idx_t CJSServerWorker::CbArgs_EmitListening(duk_context* ctx, void* /*_env*/) duk_idx_t CJSServerWorker::CbArgs_EmitListening(duk_context * ctx, void * /*_env*/)
{ {
duk_push_string(ctx, "listening"); duk_push_string(ctx, "listening");
return 1; return 1;
} }
duk_idx_t CJSServerWorker::CbArgs_EmitError(duk_context* ctx, void* _env) duk_idx_t CJSServerWorker::CbArgs_EmitError(duk_context * ctx, void * _env)
{ {
const char* errMessage = (const char*)_env; const char * errMessage = (const char *)_env;
duk_push_string(ctx, "error"); duk_push_string(ctx, "error");
duk_push_error_object(ctx, DUK_ERR_ERROR, errMessage); duk_push_error_object(ctx, DUK_ERR_ERROR, errMessage);
return 2; return 2;

View File

@ -1,8 +1,9 @@
#include <stdafx.h> #include "stdafx.h"
#include "JSSocketWorker.h" #include "JSSocketWorker.h"
#include "ScriptAPI.h" #include "ScriptAPI.h"
CJSSocketWorker::CJSSocketWorker(CScriptInstance* inst, void* objectHeapPtr, bool bAllowHalfOpen) : CJSSocketWorker::CJSSocketWorker(CScriptInstance * inst, void * objectHeapPtr, bool bAllowHalfOpen) :
CScriptWorker(inst, objectHeapPtr), CScriptWorker(inst, objectHeapPtr),
m_Socket(INVALID_SOCKET), m_Socket(INVALID_SOCKET),
m_bAllowHalfOpen(bAllowHalfOpen), m_bAllowHalfOpen(bAllowHalfOpen),
@ -43,7 +44,7 @@ bool CJSSocketWorker::Init(SOCKET sock)
return true; return true;
} }
bool CJSSocketWorker::Init(const char* host, unsigned short port) bool CJSSocketWorker::Init(const char * host, unsigned short port)
{ {
if (!m_bWinsockOK) if (!m_bWinsockOK)
{ {
@ -64,7 +65,7 @@ bool CJSSocketWorker::Init(const char* host, unsigned short port)
return true; return true;
} }
bool CJSSocketWorker::Write(const char* data, size_t length, duk_int_t callbackId, bool bEnd) bool CJSSocketWorker::Write(const char * data, size_t length, duk_int_t callbackId, bool bEnd)
{ {
CGuard guard(m_Queue.cs); CGuard guard(m_Queue.cs);
@ -75,7 +76,7 @@ bool CJSSocketWorker::Write(const char* data, size_t length, duk_int_t callbackI
return false; return false;
} }
if(bEnd) if (bEnd)
{ {
m_Queue.bSendClosePending = true; m_Queue.bSendClosePending = true;
} }
@ -150,8 +151,8 @@ void CJSSocketWorker::WorkerProc()
int numFds; int numFds;
fd_set readFds, writeFds; fd_set readFds, writeFds;
fd_set* pWriteFds = nullptr; fd_set * pWriteFds = nullptr;
fd_set* pReadFds = nullptr; fd_set * pReadFds = nullptr;
if (!bRecvClosed) if (!bRecvClosed)
{ {
@ -284,7 +285,7 @@ bool CJSSocketWorker::ProcConnect()
void CJSSocketWorker::ProcSendData() void CJSSocketWorker::ProcSendData()
{ {
CGuard guard(m_Queue.cs); CGuard guard(m_Queue.cs);
BufferedWrite& bufferedWrite = m_Queue.writes.front(); BufferedWrite & bufferedWrite = m_Queue.writes.front();
int avail = bufferedWrite.data.size() - bufferedWrite.offset; int avail = bufferedWrite.data.size() - bufferedWrite.offset;
int numBytesSent = send(m_Socket, &bufferedWrite.data[bufferedWrite.offset], avail, 0); int numBytesSent = send(m_Socket, &bufferedWrite.data[bufferedWrite.offset], avail, 0);
@ -297,7 +298,7 @@ void CJSSocketWorker::ProcSendData()
if (bufferedWrite.callbackId != -1) if (bufferedWrite.callbackId != -1)
{ {
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js_Socket__invokeWriteCallback, m_Instance->PostCMethodCall(m_DukObjectHeapPtr, ScriptAPI::js_Socket__invokeWriteCallback,
CbArgs_Write, &bufferedWrite.callbackId, sizeof(bufferedWrite.callbackId)); CbArgs_Write, &bufferedWrite.callbackId, sizeof(bufferedWrite.callbackId));
} }
m_Queue.writes.erase(m_Queue.writes.begin()); m_Queue.writes.erase(m_Queue.writes.begin());
} }
@ -356,21 +357,23 @@ void CJSSocketWorker::UpdateAddresses()
WSAPROTOCOL_INFO protocolInfo; WSAPROTOCOL_INFO protocolInfo;
int protocolInfoSize = sizeof(protocolInfo); int protocolInfoSize = sizeof(protocolInfo);
if (getsockopt(m_Socket, SOL_SOCKET, SO_PROTOCOL_INFO, (char*)&protocolInfo, &protocolInfoSize) != 0) if (getsockopt(m_Socket, SOL_SOCKET, SO_PROTOCOL_INFO, (char *)&protocolInfo, &protocolInfoSize) != 0)
{ {
return; return;
} }
int& family = protocolInfo.iAddressFamily; int & family = protocolInfo.iAddressFamily;
sockaddr* pLocalAddr = nullptr; sockaddr * pLocalAddr = nullptr;
sockaddr* pRemoteAddr = nullptr; sockaddr * pRemoteAddr = nullptr;
union { union
{
sockaddr_in ipv4; sockaddr_in ipv4;
sockaddr_in6 ipv6; sockaddr_in6 ipv6;
} localAddr; } localAddr;
union { union
{
sockaddr_in ipv4; sockaddr_in ipv4;
sockaddr_in6 ipv6; sockaddr_in6 ipv6;
} remoteAddr; } remoteAddr;
@ -379,14 +382,14 @@ void CJSSocketWorker::UpdateAddresses()
if (family == AF_INET) if (family == AF_INET)
{ {
pLocalAddr = (sockaddr*)&localAddr.ipv4; pLocalAddr = (sockaddr *)&localAddr.ipv4;
pRemoteAddr = (sockaddr*)&remoteAddr.ipv4; pRemoteAddr = (sockaddr *)&remoteAddr.ipv4;
addrSize = sizeof(sockaddr_in); addrSize = sizeof(sockaddr_in);
} }
else if (family == AF_INET6) else if (family == AF_INET6)
{ {
pLocalAddr = (sockaddr*)&localAddr.ipv6; pLocalAddr = (sockaddr *)&localAddr.ipv6;
pRemoteAddr = (sockaddr*)&remoteAddr.ipv6; pRemoteAddr = (sockaddr *)&remoteAddr.ipv6;
addrSize = sizeof(sockaddr_in6); addrSize = sizeof(sockaddr_in6);
} }
else else
@ -397,14 +400,14 @@ void CJSSocketWorker::UpdateAddresses()
getsockname(m_Socket, pLocalAddr, &addrSize); getsockname(m_Socket, pLocalAddr, &addrSize);
getpeername(m_Socket, pRemoteAddr, &addrSize); getpeername(m_Socket, pRemoteAddr, &addrSize);
getnameinfo(pLocalAddr, addrSize, getnameinfo(pLocalAddr, addrSize,
m_LocalAddress.address, sizeof(m_LocalAddress.address), m_LocalAddress.address, sizeof(m_LocalAddress.address),
0, 0, NI_NUMERICHOST); 0, 0, NI_NUMERICHOST);
getnameinfo(pRemoteAddr, addrSize, getnameinfo(pRemoteAddr, addrSize,
m_RemoteAddress.address, sizeof(m_RemoteAddress.address), m_RemoteAddress.address, sizeof(m_RemoteAddress.address),
0, 0, NI_NUMERICHOST); 0, 0, NI_NUMERICHOST);
if (family == AF_INET) if (family == AF_INET)
{ {
@ -427,10 +430,10 @@ void CJSSocketWorker::UpdateAddresses()
void CJSSocketWorker::JSEmitConnect() void CJSSocketWorker::JSEmitConnect()
{ {
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, m_Instance->PostCMethodCall(m_DukObjectHeapPtr,
ScriptAPI::js__Emitter_emit, CbArgs_EmitConnect); ScriptAPI::js__Emitter_emit, CbArgs_EmitConnect);
} }
void CJSSocketWorker::JSEmitData(const char* data, size_t size) void CJSSocketWorker::JSEmitData(const char * data, size_t size)
{ {
JSEmitDataEnv env; JSEmitDataEnv env;
env.data = new char[size]; env.data = new char[size];
@ -439,50 +442,50 @@ void CJSSocketWorker::JSEmitData(const char* data, size_t size)
memcpy(env.data, data, size); memcpy(env.data, data, size);
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, m_Instance->PostCMethodCall(m_DukObjectHeapPtr,
ScriptAPI::js__Emitter_emit, CbArgs_EmitData, (void*)&env, sizeof(env)); ScriptAPI::js__Emitter_emit, CbArgs_EmitData, (void *)&env, sizeof(env));
} }
void CJSSocketWorker::JSEmitEnd() void CJSSocketWorker::JSEmitEnd()
{ {
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, m_Instance->PostCMethodCall(m_DukObjectHeapPtr,
ScriptAPI::js__Emitter_emit, CbArgs_EmitEnd); ScriptAPI::js__Emitter_emit, CbArgs_EmitEnd);
} }
void CJSSocketWorker::JSEmitClose() void CJSSocketWorker::JSEmitClose()
{ {
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, m_Instance->PostCMethodCall(m_DukObjectHeapPtr,
ScriptAPI::js__Emitter_emit, CbArgs_EmitClose); ScriptAPI::js__Emitter_emit, CbArgs_EmitClose);
} }
void CJSSocketWorker::JSEmitDrain() void CJSSocketWorker::JSEmitDrain()
{ {
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, m_Instance->PostCMethodCall(m_DukObjectHeapPtr,
ScriptAPI::js__Emitter_emit, CbArgs_EmitDrain); ScriptAPI::js__Emitter_emit, CbArgs_EmitDrain);
} }
void CJSSocketWorker::JSEmitLookup(JSSocketAddrInfo& addr) void CJSSocketWorker::JSEmitLookup(JSSocketAddrInfo & addr)
{ {
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, m_Instance->PostCMethodCall(m_DukObjectHeapPtr,
ScriptAPI::js__Emitter_emit, CbArgs_EmitLookup, (void*)&addr, sizeof(addr)); ScriptAPI::js__Emitter_emit, CbArgs_EmitLookup, (void *)&addr, sizeof(addr));
} }
void CJSSocketWorker::JSEmitError(const char* errMessage) void CJSSocketWorker::JSEmitError(const char * errMessage)
{ {
m_Instance->PostCMethodCall(m_DukObjectHeapPtr, m_Instance->PostCMethodCall(m_DukObjectHeapPtr,
ScriptAPI::js__Emitter_emit, CbArgs_EmitError, (void*)errMessage, strlen(errMessage) + 1); ScriptAPI::js__Emitter_emit, CbArgs_EmitError, (void *)errMessage, strlen(errMessage) + 1);
} }
duk_idx_t CJSSocketWorker::CbArgs_EmitConnect(duk_context* ctx, void* /*_env*/) duk_idx_t CJSSocketWorker::CbArgs_EmitConnect(duk_context * ctx, void * /*_env*/)
{ {
duk_push_string(ctx, "connect"); duk_push_string(ctx, "connect");
return 1; return 1;
} }
duk_idx_t CJSSocketWorker::CbArgs_EmitData(duk_context* ctx, void* _env) duk_idx_t CJSSocketWorker::CbArgs_EmitData(duk_context * ctx, void * _env)
{ {
JSEmitDataEnv* env = (JSEmitDataEnv*)_env; JSEmitDataEnv * env = (JSEmitDataEnv *)_env;
duk_push_string(ctx, "data"); duk_push_string(ctx, "data");
char* buffer = (char*)duk_push_fixed_buffer(ctx, env->size); char * buffer = (char *)duk_push_fixed_buffer(ctx, env->size);
memcpy(buffer, env->data, env->size); memcpy(buffer, env->data, env->size);
delete[] env->data; delete[] env->data;
@ -492,27 +495,27 @@ duk_idx_t CJSSocketWorker::CbArgs_EmitData(duk_context* ctx, void* _env)
return 2; return 2;
} }
duk_idx_t CJSSocketWorker::CbArgs_EmitEnd(duk_context* ctx, void* /*_env*/) duk_idx_t CJSSocketWorker::CbArgs_EmitEnd(duk_context * ctx, void * /*_env*/)
{ {
duk_push_string(ctx, "end"); duk_push_string(ctx, "end");
return 1; return 1;
} }
duk_idx_t CJSSocketWorker::CbArgs_EmitClose(duk_context* ctx, void* /*_env*/) duk_idx_t CJSSocketWorker::CbArgs_EmitClose(duk_context * ctx, void * /*_env*/)
{ {
duk_push_string(ctx, "close"); duk_push_string(ctx, "close");
return 1; return 1;
} }
duk_idx_t CJSSocketWorker::CbArgs_EmitDrain(duk_context* ctx, void* /*_env*/) duk_idx_t CJSSocketWorker::CbArgs_EmitDrain(duk_context * ctx, void * /*_env*/)
{ {
duk_push_string(ctx, "drain"); duk_push_string(ctx, "drain");
return 1; return 1;
} }
duk_idx_t CJSSocketWorker::CbArgs_EmitLookup(duk_context* ctx, void* _env) duk_idx_t CJSSocketWorker::CbArgs_EmitLookup(duk_context * ctx, void * _env)
{ {
JSSocketAddrInfo* addr = (JSSocketAddrInfo*)_env; JSSocketAddrInfo * addr = (JSSocketAddrInfo *)_env;
duk_push_string(ctx, "lookup"); duk_push_string(ctx, "lookup");
duk_push_object(ctx); duk_push_object(ctx);
@ -525,7 +528,7 @@ duk_idx_t CJSSocketWorker::CbArgs_EmitLookup(duk_context* ctx, void* _env)
{ {
duk_push_error_object(ctx, DUK_ERR_ERROR, "dns lookup error"); duk_push_error_object(ctx, DUK_ERR_ERROR, "dns lookup error");
} }
duk_put_prop_string(ctx, -2, "err"); duk_put_prop_string(ctx, -2, "err");
duk_push_string(ctx, addr->address); duk_push_string(ctx, addr->address);
duk_put_prop_string(ctx, -2, "address"); duk_put_prop_string(ctx, -2, "address");
@ -536,17 +539,17 @@ duk_idx_t CJSSocketWorker::CbArgs_EmitLookup(duk_context* ctx, void* _env)
return 2; return 2;
} }
duk_idx_t CJSSocketWorker::CbArgs_EmitError(duk_context* ctx, void* _env) duk_idx_t CJSSocketWorker::CbArgs_EmitError(duk_context * ctx, void * _env)
{ {
const char* errMessage = (const char*)_env; const char * errMessage = (const char *)_env;
duk_push_string(ctx, "error"); duk_push_string(ctx, "error");
duk_push_error_object(ctx, DUK_ERR_ERROR, errMessage); duk_push_error_object(ctx, DUK_ERR_ERROR, errMessage);
return 2; return 2;
} }
duk_idx_t CJSSocketWorker::CbArgs_Write(duk_context* ctx, void* _env) duk_idx_t CJSSocketWorker::CbArgs_Write(duk_context * ctx, void * _env)
{ {
duk_int_t callbackId = *(duk_int_t*)_env; duk_int_t callbackId = *(duk_int_t *)_env;
duk_push_int(ctx, callbackId); duk_push_int(ctx, callbackId);
return 1; return 1;
} }
@ -575,7 +578,7 @@ unsigned short CJSSocketWorker::GetRemotePort()
return m_RemoteAddress.port; return m_RemoteAddress.port;
} }
const char* CJSSocketWorker::GetFamily() const char * CJSSocketWorker::GetFamily()
{ {
CGuard guard(m_CS); CGuard guard(m_CS);
return m_LocalAddress.family; return m_LocalAddress.family;
@ -588,7 +591,7 @@ void CJSSocketWorker::ClearAddress()
m_LocalAddress.port = 0; m_LocalAddress.port = 0;
memset(m_LocalAddress.address, 0, sizeof(m_LocalAddress.address)); memset(m_LocalAddress.address, 0, sizeof(m_LocalAddress.address));
m_LocalAddress.family = ""; m_LocalAddress.family = "";
m_RemoteAddress.port = 0; m_RemoteAddress.port = 0;
memset(m_RemoteAddress.address, 0, sizeof(m_RemoteAddress.address)); memset(m_RemoteAddress.address, 0, sizeof(m_RemoteAddress.address));
m_RemoteAddress.family = ""; m_RemoteAddress.family = "";

View File

@ -1,23 +1,25 @@
#include <stdafx.h> #include "stdafx.h"
#include "N64Image.h" #include "N64Image.h"
struct ImgFormatInfo { struct ImgFormatInfo
{
int bitsPerPixel; int bitsPerPixel;
int paletteColorCount; int paletteColorCount;
}; };
static const std::map<int, ImgFormatInfo> FormatInfo = { static const std::map<int, ImgFormatInfo> FormatInfo = {
{ IMG_I4, { 4, 0 } }, {IMG_I4, {4, 0}},
{ IMG_IA4, { 4, 0 } }, {IMG_IA4, {4, 0}},
{ IMG_I8, { 8, 0 } }, {IMG_I8, {8, 0}},
{ IMG_IA8, { 8, 0 } }, {IMG_IA8, {8, 0}},
{ IMG_IA16, { 16, 0 } }, {IMG_IA16, {16, 0}},
{ IMG_RGBA16, { 16, 0 } }, {IMG_RGBA16, {16, 0}},
{ IMG_RGBA32, { 32, 0 } }, {IMG_RGBA32, {32, 0}},
{ IMG_CI4_RGBA16, { 4, 16 } }, {IMG_CI4_RGBA16, {4, 16}},
{ IMG_CI4_IA16, { 4, 16 } }, {IMG_CI4_IA16, {4, 16}},
{ IMG_CI8_RGBA16, { 8, 256 } }, {IMG_CI8_RGBA16, {8, 256}},
{ IMG_CI8_IA16, { 8, 256 } }, {IMG_CI8_IA16, {8, 256}},
}; };
CN64Image::CN64Image() : CN64Image::CN64Image() :
@ -31,8 +33,8 @@ CN64Image::CN64Image() :
} }
int CN64Image::Init(int format, size_t width, size_t height, int CN64Image::Init(int format, size_t width, size_t height,
void* pixelData, size_t pixelDataSize, void * pixelData, size_t pixelDataSize,
void* paletteData, size_t paletteDataSize) void * paletteData, size_t paletteDataSize)
{ {
m_Format = format; m_Format = format;
m_PixelSize = BitsPerPixel(format); m_PixelSize = BitsPerPixel(format);
@ -83,7 +85,7 @@ int CN64Image::Init(int format, size_t width, size_t height,
return N64IMG_OK; return N64IMG_OK;
} }
int CN64Image::Init(int format, uint8_t* pngData, size_t pngSize) int CN64Image::Init(int format, uint8_t * pngData, size_t pngSize)
{ {
m_Format = format; m_Format = format;
m_PixelSize = BitsPerPixel(format); m_PixelSize = BitsPerPixel(format);
@ -115,44 +117,44 @@ int CN64Image::Init(int format, uint8_t* pngData, size_t pngSize)
return N64IMG_OK; return N64IMG_OK;
} }
void CN64Image::ToPNG(std::vector<uint8_t>& outPngImage) void CN64Image::ToPNG(std::vector<uint8_t> & outPngImage)
{ {
WritePNG(m_BitmapRgba32.data(), m_Width, m_Height, outPngImage); WritePNG(m_BitmapRgba32.data(), m_Width, m_Height, outPngImage);
} }
uint16_t* CN64Image::PalettePtr(size_t index) uint16_t * CN64Image::PalettePtr(size_t index)
{ {
size_t offset = index * sizeof(uint16_t); size_t offset = index * sizeof(uint16_t);
if (offset + sizeof(uint16_t) > m_PaletteData.size()) if (offset + sizeof(uint16_t) > m_PaletteData.size())
{ {
return nullptr; return nullptr;
} }
return (uint16_t*)&m_PaletteData[offset]; return (uint16_t *)&m_PaletteData[offset];
} }
void* CN64Image::TexelPtr(size_t index) void * CN64Image::TexelPtr(size_t index)
{ {
size_t offset = (index * m_PixelSize) / 8; size_t offset = (index * m_PixelSize) / 8;
if (offset + max(1, (m_PixelSize / 8)) > m_PixelData.size()) if (offset + max(1, (m_PixelSize / 8)) > m_PixelData.size())
{ {
return nullptr; return nullptr;
} }
return (void*)&m_PixelData[offset]; return (void *)&m_PixelData[offset];
} }
uint32_t* CN64Image::BitmapPtr(size_t index) uint32_t * CN64Image::BitmapPtr(size_t index)
{ {
size_t offset = index * sizeof(uint32_t); size_t offset = index * sizeof(uint32_t);
if (offset + sizeof(uint32_t) > m_BitmapRgba32.size()) if (offset + sizeof(uint32_t) > m_BitmapRgba32.size())
{ {
return nullptr; return nullptr;
} }
return (uint32_t*)&m_BitmapRgba32[offset]; return (uint32_t *)&m_BitmapRgba32[offset];
} }
unsigned int CN64Image::GetTexel(size_t index) unsigned int CN64Image::GetTexel(size_t index)
{ {
void* pTexel = TexelPtr(index); void * pTexel = TexelPtr(index);
if (pTexel == nullptr) if (pTexel == nullptr)
{ {
@ -164,18 +166,18 @@ unsigned int CN64Image::GetTexel(size_t index)
case 4: case 4:
if ((index % 2) == 0) if ((index % 2) == 0)
{ {
return (*(uint8_t*)pTexel & 0xF0) >> 4; return (*(uint8_t *)pTexel & 0xF0) >> 4;
} }
else else
{ {
return (*(uint8_t*)pTexel & 0x0F); return (*(uint8_t *)pTexel & 0x0F);
} }
case 8: case 8:
return *(uint8_t*)pTexel; return *(uint8_t *)pTexel;
case 16: case 16:
return _byteswap_ushort(*(uint16_t*)pTexel); return _byteswap_ushort(*(uint16_t *)pTexel);
case 32: case 32:
return _byteswap_ulong(*(uint32_t*)pTexel); return _byteswap_ulong(*(uint32_t *)pTexel);
} }
return 0; return 0;
@ -203,20 +205,20 @@ void CN64Image::SetTexel(size_t index, unsigned int value)
} }
break; break;
case 8: case 8:
*(uint8_t*)&m_PixelData[offset] = (uint8_t)value; *(uint8_t *)&m_PixelData[offset] = (uint8_t)value;
break; break;
case 16: case 16:
*(uint16_t*)&m_PixelData[offset] = _byteswap_ushort((uint16_t)value); *(uint16_t *)&m_PixelData[offset] = _byteswap_ushort((uint16_t)value);
break; break;
case 32: case 32:
*(uint32_t*)&m_PixelData[offset] = _byteswap_ulong(value); *(uint32_t *)&m_PixelData[offset] = _byteswap_ulong(value);
break; break;
} }
} }
bool CN64Image::GetPaletteColor(size_t index, unsigned int* color) bool CN64Image::GetPaletteColor(size_t index, unsigned int * color)
{ {
uint16_t* pColor = PalettePtr(index); uint16_t * pColor = PalettePtr(index);
if (pColor == nullptr) if (pColor == nullptr)
{ {
@ -230,7 +232,7 @@ bool CN64Image::GetPaletteColor(size_t index, unsigned int* color)
bool CN64Image::SetPaletteColor(size_t index, unsigned int color) bool CN64Image::SetPaletteColor(size_t index, unsigned int color)
{ {
uint16_t* pColor = PalettePtr(index); uint16_t * pColor = PalettePtr(index);
if (pColor == nullptr) if (pColor == nullptr)
{ {
@ -241,9 +243,9 @@ bool CN64Image::SetPaletteColor(size_t index, unsigned int color)
return true; return true;
} }
bool CN64Image::GetBitmapColor(size_t index, uint32_t* color) bool CN64Image::GetBitmapColor(size_t index, uint32_t * color)
{ {
uint32_t* pColor = BitmapPtr(index); uint32_t * pColor = BitmapPtr(index);
if (pColor == nullptr) if (pColor == nullptr)
{ {
*color = 0; *color = 0;
@ -255,7 +257,7 @@ bool CN64Image::GetBitmapColor(size_t index, uint32_t* color)
bool CN64Image::SetBitmapColor(size_t index, unsigned int color) bool CN64Image::SetBitmapColor(size_t index, unsigned int color)
{ {
uint32_t* pColor = BitmapPtr(index); uint32_t * pColor = BitmapPtr(index);
if (pColor == nullptr) if (pColor == nullptr)
{ {
return false; return false;
@ -350,17 +352,17 @@ int CN64Image::UpdatePixelsAndPaletteFromBitmap()
return N64IMG_OK; return N64IMG_OK;
} }
std::vector<uint8_t>& CN64Image::PaletteData() std::vector<uint8_t> & CN64Image::PaletteData()
{ {
return m_PaletteData; return m_PaletteData;
} }
std::vector<uint8_t>& CN64Image::PixelData() std::vector<uint8_t> & CN64Image::PixelData()
{ {
return m_PixelData; return m_PixelData;
} }
std::vector<uint8_t>& CN64Image::Bitmap() std::vector<uint8_t> & CN64Image::Bitmap()
{ {
return m_BitmapRgba32; return m_BitmapRgba32;
} }
@ -394,8 +396,8 @@ unsigned int CN64Image::ColorFromRgba32(int dstFormat, uint32_t rgba32)
uint8_t r = ((rgba32 >> 24) & 0xFF); uint8_t r = ((rgba32 >> 24) & 0xFF);
uint8_t g = ((rgba32 >> 16) & 0xFF); uint8_t g = ((rgba32 >> 16) & 0xFF);
uint8_t b = ((rgba32 >> 8) & 0xFF); uint8_t b = ((rgba32 >> 8) & 0xFF);
uint8_t a = ((rgba32 >> 0) & 0xFF); uint8_t a = ((rgba32 >> 0) & 0xFF);
uint8_t i; uint8_t i;
@ -404,7 +406,7 @@ unsigned int CN64Image::ColorFromRgba32(int dstFormat, uint32_t rgba32)
case IMG_RGBA16: case IMG_RGBA16:
case IMG_CI8_RGBA16: case IMG_CI8_RGBA16:
case IMG_CI4_RGBA16: case IMG_CI4_RGBA16:
return ((r / 8) << 11) | ((g / 8) << 6) | ((b / 8) << 1) | (a / 128); return ((r / 8) << 11) | ((g / 8) << 6) | ((b / 8) << 1) | (a / 128);
case IMG_IA16: case IMG_IA16:
case IMG_CI8_IA16: case IMG_CI8_IA16:
case IMG_CI4_IA16: case IMG_CI4_IA16:
@ -439,8 +441,8 @@ uint32_t CN64Image::ColorToRgba32(int srcFormat, unsigned int color)
case IMG_CI8_RGBA16: case IMG_CI8_RGBA16:
case IMG_CI4_RGBA16: case IMG_CI4_RGBA16:
r = (((color >> 11) & 0x1F) * 255) / 31; r = (((color >> 11) & 0x1F) * 255) / 31;
g = (((color >> 6) & 0x1F) * 255) / 31; g = (((color >> 6) & 0x1F) * 255) / 31;
b = (((color >> 1) & 0x1F) * 255) / 31; b = (((color >> 1) & 0x1F) * 255) / 31;
a = (color & 1) * 255; a = (color & 1) * 255;
break; break;
case IMG_IA16: case IMG_IA16:
@ -467,7 +469,7 @@ uint32_t CN64Image::ColorToRgba32(int srcFormat, unsigned int color)
break; break;
} }
return (r << 24) | (g << 16) | (b << 8) | a; return (r << 24) | (g << 16) | (b << 8) | a;
} }
int CN64Image::BitsPerPixel(int format) int CN64Image::BitsPerPixel(int format)
@ -497,17 +499,17 @@ bool CN64Image::UsesPalette(int format)
return false; return false;
} }
const char* CN64Image::ResultCodeName(int resultCode) const char * CN64Image::ResultCodeName(int resultCode)
{ {
static const std::map<int, const char*> names = { static const std::map<int, const char *> names = {
{ N64IMG_OK, "OK" }, {N64IMG_OK, "OK"},
{ N64IMG_DATA_SIZE_INCORRECT, "ERR_DATA_SIZE_INCORRECT" }, {N64IMG_DATA_SIZE_INCORRECT, "ERR_DATA_SIZE_INCORRECT"},
{ N64IMG_INVALID_COLOR_INDEX, "ERR_INVALID_COLOR_INDEX" }, {N64IMG_INVALID_COLOR_INDEX, "ERR_INVALID_COLOR_INDEX"},
{ N64IMG_INCOMPATIBLE_COLOR, "ERR_INCOMPATIBLE_COLOR" }, {N64IMG_INCOMPATIBLE_COLOR, "ERR_INCOMPATIBLE_COLOR"},
{ N64IMG_TOO_MANY_COLORS, "ERR_TOO_MANY_COLORS" }, {N64IMG_TOO_MANY_COLORS, "ERR_TOO_MANY_COLORS"},
{ N64IMG_PNG_HEADER_MISSING, "ERR_PNG_HEADER_MISSING" }, {N64IMG_PNG_HEADER_MISSING, "ERR_PNG_HEADER_MISSING"},
{ N64IMG_PNG_OUT_OF_MEMORY, "ERR_PNG_OUT_OF_MEMORY" }, {N64IMG_PNG_OUT_OF_MEMORY, "ERR_PNG_OUT_OF_MEMORY"},
{ N64IMG_PNG_EXCEPTION, "ERR_PNG_EXCEPTION" }, {N64IMG_PNG_EXCEPTION, "ERR_PNG_EXCEPTION"},
{ N64IMG_PNG_PARSER_FAILED, "ERR_PNG_PARSER_FAILED" } { N64IMG_PNG_PARSER_FAILED, "ERR_PNG_PARSER_FAILED" }
}; };

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#include <stdafx.h>
#include "ScriptAPI.h" #include "ScriptAPI.h"
enum { enum {

View File

@ -1,21 +1,23 @@
#include <stdafx.h> #include "stdafx.h"
#include <3rdParty/png/png.h>
#include "N64Image.h" #include "N64Image.h"
#include <3rdParty/png/png.h>
#pragma warning (disable:4611) // disable setjmp/c++ deconstruction warning #pragma warning(disable : 4611) // disable setjmp/c++ deconstruction warning
struct PNGReadState { struct PNGReadState
uint8_t* pngData; {
size_t pngSize; uint8_t * pngData;
size_t pngSize;
png_size_t offset; png_size_t offset;
}; };
static void PNGReadCallback(png_structp png_ptr, png_bytep data, png_size_t length); static void PNGReadCallback(png_structp png_ptr, png_bytep data, png_size_t length);
static void PNGWriteCallback(png_structp png_ptr, png_bytep data, png_size_t length); static void PNGWriteCallback(png_structp png_ptr, png_bytep data, png_size_t length);
static void PNGFlushCallback(png_structp png_ptr); static void PNGFlushCallback(png_structp png_ptr);
static bool ParsePNGRow(png_byte* row, png_size_t rowSize, int bitDepth, int colorType, std::vector<uint8_t>& outRGBA32); static bool ParsePNGRow(png_byte * row, png_size_t rowSize, int bitDepth, int colorType, std::vector<uint8_t> & outRGBA32);
int CN64Image::ReadPNG(uint8_t* pngData, size_t pngSize, size_t* outWidth, size_t* outHeight, std::vector<uint8_t>& outRGBA32) int CN64Image::ReadPNG(uint8_t * pngData, size_t pngSize, size_t * outWidth, size_t * outHeight, std::vector<uint8_t> & outRGBA32)
{ {
if (!png_check_sig(pngData, 8)) if (!png_check_sig(pngData, 8))
{ {
@ -57,7 +59,7 @@ int CN64Image::ReadPNG(uint8_t* pngData, size_t pngSize, size_t* outWidth, size_
png_uint_32 width, height; png_uint_32 width, height;
int bitDepth, colorType; int bitDepth, colorType;
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bitDepth, png_get_IHDR(png_ptr, info_ptr, &width, &height, &bitDepth,
&colorType, nullptr, nullptr, nullptr); &colorType, nullptr, nullptr, nullptr);
png_size_t rowSize = png_get_rowbytes(png_ptr, info_ptr); png_size_t rowSize = png_get_rowbytes(png_ptr, info_ptr);
std::vector<png_bytep> rowPointers(height); std::vector<png_bytep> rowPointers(height);
@ -86,7 +88,7 @@ int CN64Image::ReadPNG(uint8_t* pngData, size_t pngSize, size_t* outWidth, size_
return N64IMG_OK; return N64IMG_OK;
} }
void CN64Image::WritePNG(uint8_t* rgba32, size_t width, size_t height, std::vector<uint8_t>& buffer) void CN64Image::WritePNG(uint8_t * rgba32, size_t width, size_t height, std::vector<uint8_t> & buffer)
{ {
png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
@ -111,8 +113,8 @@ void CN64Image::WritePNG(uint8_t* rgba32, size_t width, size_t height, std::vect
} }
png_set_IHDR(png_ptr, info_ptr, width, height, png_set_IHDR(png_ptr, info_ptr, width, height,
8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
png_set_write_fn(png_ptr, &buffer, PNGWriteCallback, PNGFlushCallback); png_set_write_fn(png_ptr, &buffer, PNGWriteCallback, PNGFlushCallback);
png_write_info(png_ptr, info_ptr); png_write_info(png_ptr, info_ptr);
@ -132,7 +134,7 @@ void CN64Image::WritePNG(uint8_t* rgba32, size_t width, size_t height, std::vect
static void PNGReadCallback(png_structp png_ptr, png_bytep data, png_size_t length) static void PNGReadCallback(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
PNGReadState* state = (PNGReadState*)png_get_io_ptr(png_ptr); PNGReadState * state = (PNGReadState *)png_get_io_ptr(png_ptr);
if (state->offset + length > state->pngSize) if (state->offset + length > state->pngSize)
{ {
return; return;
@ -143,7 +145,7 @@ static void PNGReadCallback(png_structp png_ptr, png_bytep data, png_size_t leng
static void PNGWriteCallback(png_structp png_ptr, png_bytep data, png_size_t length) static void PNGWriteCallback(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
std::vector<uint8_t>* buffer = (std::vector<uint8_t>*)png_get_io_ptr(png_ptr); std::vector<uint8_t> * buffer = (std::vector<uint8_t> *)png_get_io_ptr(png_ptr);
buffer->insert(buffer->end(), &data[0], &data[length]); buffer->insert(buffer->end(), &data[0], &data[length]);
} }
@ -151,7 +153,7 @@ static void PNGFlushCallback(png_structp /*png_ptr*/)
{ {
} }
static bool ParsePNGRow(png_byte* row, png_size_t rowSize, int bitDepth, int colorType, std::vector<uint8_t>& outRGBA32) static bool ParsePNGRow(png_byte * row, png_size_t rowSize, int bitDepth, int colorType, std::vector<uint8_t> & outRGBA32)
{ {
if (colorType == PNG_COLOR_TYPE_RGBA) if (colorType == PNG_COLOR_TYPE_RGBA)
{ {

View File

@ -1,11 +1,12 @@
#include <stdafx.h> #include "stdafx.h"
#include <dwrite.h>
#include "ScriptAPI.h"
#include "N64Image.h" #include "N64Image.h"
#include "ScriptAPI.h"
#include <dwrite.h>
#pragma warning(disable: 4702) // disable unreachable code warning #pragma warning(disable : 4702) // disable unreachable code warning
void ScriptAPI::InitEnvironment(duk_context* ctx, CScriptInstance* inst) void ScriptAPI::InitEnvironment(duk_context * ctx, CScriptInstance * inst)
{ {
duk_push_global_object(ctx); duk_push_global_object(ctx);
duk_push_string(ctx, "global"); duk_push_string(ctx, "global");
@ -58,29 +59,29 @@ void ScriptAPI::InitEnvironment(duk_context* ctx, CScriptInstance* inst)
Define_mem(ctx); Define_mem(ctx);
Define_pj64(ctx); Define_pj64(ctx);
Define_script(ctx); Define_script(ctx);
Define_alert(ctx); Define_alert(ctx);
Define_exec(ctx); Define_exec(ctx);
Define_interval(ctx); Define_interval(ctx);
Define_AddressRange(ctx); Define_AddressRange(ctx);
Define_N64Image(ctx); Define_N64Image(ctx);
Define_Server(ctx); Define_Server(ctx);
Define_Socket(ctx); Define_Socket(ctx);
Define_Number_prototype_hex(ctx); Define_Number_prototype_hex(ctx);
DefineGlobalConstants(ctx); DefineGlobalConstants(ctx);
if(duk_get_top(ctx) > 0) if (duk_get_top(ctx) > 0)
{ {
inst->System()->ConsoleLog("[SCRIPTSYS]: warning: duktape stack is dirty after API init"); inst->System()->ConsoleLog("[SCRIPTSYS]: warning: duktape stack is dirty after API init");
} }
} }
void ScriptAPI::DefineGlobalClass(duk_context* ctx, const char* className, void ScriptAPI::DefineGlobalClass(duk_context * ctx, const char * className,
duk_c_function constructorFunc, duk_c_function constructorFunc,
const DukPropListEntry* prototypeProps, const DukPropListEntry * prototypeProps,
const DukPropListEntry* staticProps) const DukPropListEntry * staticProps)
{ {
duk_push_global_object(ctx); duk_push_global_object(ctx);
duk_push_string(ctx, className); duk_push_string(ctx, className);
@ -112,7 +113,7 @@ void ScriptAPI::DefineGlobalClass(duk_context* ctx, const char* className,
duk_pop(ctx); duk_pop(ctx);
} }
void ScriptAPI::DefineGlobalInterface(duk_context* ctx, const char* name, const DukPropListEntry* props) void ScriptAPI::DefineGlobalInterface(duk_context * ctx, const char * name, const DukPropListEntry * props)
{ {
duk_push_global_object(ctx); duk_push_global_object(ctx);
duk_push_string(ctx, name); duk_push_string(ctx, name);
@ -123,7 +124,7 @@ void ScriptAPI::DefineGlobalInterface(duk_context* ctx, const char* name, const
duk_pop(ctx); duk_pop(ctx);
} }
void ScriptAPI::DefineGlobalFunction(duk_context* ctx, const char* name, duk_c_function func) void ScriptAPI::DefineGlobalFunction(duk_context * ctx, const char * name, duk_c_function func)
{ {
duk_push_global_object(ctx); duk_push_global_object(ctx);
duk_push_string(ctx, name); duk_push_string(ctx, name);
@ -133,222 +134,222 @@ void ScriptAPI::DefineGlobalFunction(duk_context* ctx, const char* name, duk_c_f
duk_pop(ctx); duk_pop(ctx);
} }
void ScriptAPI::DefineGlobalConstants(duk_context* ctx) void ScriptAPI::DefineGlobalConstants(duk_context * ctx)
{ {
const duk_number_list_entry numbers[] = { const duk_number_list_entry numbers[] = {
{ "u8", U8 }, {"u8", U8},
{ "u16", U16 }, {"u16", U16},
{ "u32", U32 }, {"u32", U32},
{ "s8", S8 }, {"s8", S8},
{ "s16", S16 }, {"s16", S16},
{ "s32", S32 }, {"s32", S32},
{ "f32", F32 }, {"f32", F32},
{ "f64", F64 }, {"f64", F64},
{ "s64", S64 }, {"s64", S64},
{ "u64", U64 }, {"u64", U64},
{ "GPR_R0", GPR_R0 }, {"GPR_R0", GPR_R0},
{ "GPR_AT", GPR_AT }, {"GPR_AT", GPR_AT},
{ "GPR_V0", GPR_V0 }, {"GPR_V0", GPR_V0},
{ "GPR_V1", GPR_V1 }, {"GPR_V1", GPR_V1},
{ "GPR_A0", GPR_A0 }, {"GPR_A0", GPR_A0},
{ "GPR_A1", GPR_A1 }, {"GPR_A1", GPR_A1},
{ "GPR_A2", GPR_A2 }, {"GPR_A2", GPR_A2},
{ "GPR_A3", GPR_A3 }, {"GPR_A3", GPR_A3},
{ "GPR_T0", GPR_T0 }, {"GPR_T0", GPR_T0},
{ "GPR_T1", GPR_T1 }, {"GPR_T1", GPR_T1},
{ "GPR_T2", GPR_T2 }, {"GPR_T2", GPR_T2},
{ "GPR_T3", GPR_T3 }, {"GPR_T3", GPR_T3},
{ "GPR_T4", GPR_T4 }, {"GPR_T4", GPR_T4},
{ "GPR_T5", GPR_T5 }, {"GPR_T5", GPR_T5},
{ "GPR_T6", GPR_T6 }, {"GPR_T6", GPR_T6},
{ "GPR_T7", GPR_T7 }, {"GPR_T7", GPR_T7},
{ "GPR_S0", GPR_S0 }, {"GPR_S0", GPR_S0},
{ "GPR_S1", GPR_S1 }, {"GPR_S1", GPR_S1},
{ "GPR_S2", GPR_S2 }, {"GPR_S2", GPR_S2},
{ "GPR_S3", GPR_S3 }, {"GPR_S3", GPR_S3},
{ "GPR_S4", GPR_S4 }, {"GPR_S4", GPR_S4},
{ "GPR_S5", GPR_S5 }, {"GPR_S5", GPR_S5},
{ "GPR_S6", GPR_S6 }, {"GPR_S6", GPR_S6},
{ "GPR_S7", GPR_S7 }, {"GPR_S7", GPR_S7},
{ "GPR_T8", GPR_T8 }, {"GPR_T8", GPR_T8},
{ "GPR_T9", GPR_T9 }, {"GPR_T9", GPR_T9},
{ "GPR_K0", GPR_K0 }, {"GPR_K0", GPR_K0},
{ "GPR_K1", GPR_K1 }, {"GPR_K1", GPR_K1},
{ "GPR_GP", GPR_GP }, {"GPR_GP", GPR_GP},
{ "GPR_SP", GPR_SP }, {"GPR_SP", GPR_SP},
{ "GPR_FP", GPR_FP }, {"GPR_FP", GPR_FP},
{ "GPR_RA", GPR_RA }, {"GPR_RA", GPR_RA},
//{ "GPR_S8", GPR_S8 }, //{ "GPR_S8", GPR_S8 },
{ "GPR_ANY", 0xFFFFFFFF }, {"GPR_ANY", 0xFFFFFFFF},
{ "RDRAM_CONFIG_REG", 0xA3F00000 }, {"RDRAM_CONFIG_REG", 0xA3F00000},
{ "RDRAM_DEVICE_TYPE_REG", 0xA3F00000 }, {"RDRAM_DEVICE_TYPE_REG", 0xA3F00000},
{ "RDRAM_DEVICE_ID_REG", 0xA3F00004 }, {"RDRAM_DEVICE_ID_REG", 0xA3F00004},
{ "RDRAM_DELAY_REG", 0xA3F00008 }, {"RDRAM_DELAY_REG", 0xA3F00008},
{ "RDRAM_MODE_REG", 0xA3F0000C }, {"RDRAM_MODE_REG", 0xA3F0000C},
{ "RDRAM_REF_INTERVAL_REG", 0xA3F00010 }, {"RDRAM_REF_INTERVAL_REG", 0xA3F00010},
{ "RDRAM_REF_ROW_REG", 0xA3F00014 }, {"RDRAM_REF_ROW_REG", 0xA3F00014},
{ "RDRAM_RAS_INTERVAL_REG", 0xA3F00018 }, {"RDRAM_RAS_INTERVAL_REG", 0xA3F00018},
{ "RDRAM_MIN_INTERVAL_REG", 0xA3F0001C }, {"RDRAM_MIN_INTERVAL_REG", 0xA3F0001C},
{ "RDRAM_ADDR_SELECT_REG", 0xA3F00020 }, {"RDRAM_ADDR_SELECT_REG", 0xA3F00020},
{ "RDRAM_DEVICE_MANUF_REG", 0xA3F00024 }, {"RDRAM_DEVICE_MANUF_REG", 0xA3F00024},
{ "SP_MEM_ADDR_REG", 0xA4040000 }, {"SP_MEM_ADDR_REG", 0xA4040000},
{ "SP_DRAM_ADDR_REG", 0xA4040004 }, {"SP_DRAM_ADDR_REG", 0xA4040004},
{ "SP_RD_LEN_REG", 0xA4040008 }, {"SP_RD_LEN_REG", 0xA4040008},
{ "SP_WR_LEN_REG", 0xA404000C }, {"SP_WR_LEN_REG", 0xA404000C},
{ "SP_STATUS_REG", 0xA4040010 }, {"SP_STATUS_REG", 0xA4040010},
{ "SP_DMA_FULL_REG", 0xA4040014 }, {"SP_DMA_FULL_REG", 0xA4040014},
{ "SP_DMA_BUSY_REG", 0xA4040018 }, {"SP_DMA_BUSY_REG", 0xA4040018},
{ "SP_SEMAPHORE_REG", 0xA404001C }, {"SP_SEMAPHORE_REG", 0xA404001C},
{ "SP_PC_REG", 0xA4080000 }, {"SP_PC_REG", 0xA4080000},
{ "SP_IBIST_REG", 0xA4080004 }, {"SP_IBIST_REG", 0xA4080004},
{ "DPC_START_REG", 0xA4100000 }, {"DPC_START_REG", 0xA4100000},
{ "DPC_END_REG", 0xA4100004 }, {"DPC_END_REG", 0xA4100004},
{ "DPC_CURRENT_REG", 0xA4100008 }, {"DPC_CURRENT_REG", 0xA4100008},
{ "DPC_STATUS_REG", 0xA410000C }, {"DPC_STATUS_REG", 0xA410000C},
{ "DPC_CLOCK_REG", 0xA4100010 }, {"DPC_CLOCK_REG", 0xA4100010},
{ "DPC_BUFBUSY_REG", 0xA4100014 }, {"DPC_BUFBUSY_REG", 0xA4100014},
{ "DPC_PIPEBUSY_REG", 0xA4100018 }, {"DPC_PIPEBUSY_REG", 0xA4100018},
{ "DPC_TMEM_REG", 0xA410001C }, {"DPC_TMEM_REG", 0xA410001C},
{ "DPS_TBIST_REG", 0xA4200000 }, {"DPS_TBIST_REG", 0xA4200000},
{ "DPS_TEST_MODE_REG", 0xA4200004 }, {"DPS_TEST_MODE_REG", 0xA4200004},
{ "DPS_BUFTEST_ADDR_REG", 0xA4200008 }, {"DPS_BUFTEST_ADDR_REG", 0xA4200008},
{ "DPS_BUFTEST_DATA_REG", 0xA420000C }, {"DPS_BUFTEST_DATA_REG", 0xA420000C},
{ "MI_INIT_MODE_REG", 0xA4300000 }, {"MI_INIT_MODE_REG", 0xA4300000},
{ "MI_MODE_REG", 0xA4300000 }, {"MI_MODE_REG", 0xA4300000},
{ "MI_VERSION_REG", 0xA4300004 }, {"MI_VERSION_REG", 0xA4300004},
{ "MI_NOOP_REG", 0xA4300004 }, {"MI_NOOP_REG", 0xA4300004},
{ "MI_INTR_REG", 0xA4300008 }, {"MI_INTR_REG", 0xA4300008},
{ "MI_INTR_MASK_REG", 0xA430000C }, {"MI_INTR_MASK_REG", 0xA430000C},
{ "VI_STATUS_REG", 0xA4400000 }, {"VI_STATUS_REG", 0xA4400000},
{ "VI_CONTROL_REG", 0xA4400000 }, {"VI_CONTROL_REG", 0xA4400000},
{ "VI_ORIGIN_REG", 0xA4400004 }, {"VI_ORIGIN_REG", 0xA4400004},
{ "VI_DRAM_ADDR_REG", 0xA4400004 }, {"VI_DRAM_ADDR_REG", 0xA4400004},
{ "VI_WIDTH_REG", 0xA4400008 }, {"VI_WIDTH_REG", 0xA4400008},
{ "VI_H_WIDTH_REG", 0xA4400008 }, {"VI_H_WIDTH_REG", 0xA4400008},
{ "VI_INTR_REG", 0xA440000C }, {"VI_INTR_REG", 0xA440000C},
{ "VI_V_INTR_REG", 0xA440000C }, {"VI_V_INTR_REG", 0xA440000C},
{ "VI_CURRENT_REG", 0xA4400010 }, {"VI_CURRENT_REG", 0xA4400010},
{ "VI_V_CURRENT_LINE_REG", 0xA4400010 }, {"VI_V_CURRENT_LINE_REG", 0xA4400010},
{ "VI_BURST_REG", 0xA4400014 }, {"VI_BURST_REG", 0xA4400014},
{ "VI_TIMING_REG", 0xA4400014 }, {"VI_TIMING_REG", 0xA4400014},
{ "VI_V_SYNC_REG", 0xA4400018 }, {"VI_V_SYNC_REG", 0xA4400018},
{ "VI_H_SYNC_REG", 0xA440001C }, {"VI_H_SYNC_REG", 0xA440001C},
{ "VI_LEAP_REG", 0xA4400020 }, {"VI_LEAP_REG", 0xA4400020},
{ "VI_H_SYNC_LEAP_REG", 0xA4400020 }, {"VI_H_SYNC_LEAP_REG", 0xA4400020},
{ "VI_H_START_REG", 0xA4400024 }, {"VI_H_START_REG", 0xA4400024},
{ "VI_H_VIDEO_REG", 0xA4400024 }, {"VI_H_VIDEO_REG", 0xA4400024},
{ "VI_V_START_REG", 0xA4400028 }, {"VI_V_START_REG", 0xA4400028},
{ "VI_V_VIDEO_REG", 0xA4400028 }, {"VI_V_VIDEO_REG", 0xA4400028},
{ "VI_V_BURST_REG", 0xA440002C }, {"VI_V_BURST_REG", 0xA440002C},
{ "VI_X_SCALE_REG", 0xA4400030 }, {"VI_X_SCALE_REG", 0xA4400030},
{ "VI_Y_SCALE_REG", 0xA4400034 }, {"VI_Y_SCALE_REG", 0xA4400034},
{ "AI_DRAM_ADDR_REG", 0xA4500000 }, {"AI_DRAM_ADDR_REG", 0xA4500000},
{ "AI_LEN_REG", 0xA4500004 }, {"AI_LEN_REG", 0xA4500004},
{ "AI_CONTROL_REG", 0xA4500008 }, {"AI_CONTROL_REG", 0xA4500008},
{ "AI_STATUS_REG", 0xA450000C }, {"AI_STATUS_REG", 0xA450000C},
{ "AI_DACRATE_REG", 0xA4500010 }, {"AI_DACRATE_REG", 0xA4500010},
{ "AI_BITRATE_REG", 0xA4500014 }, {"AI_BITRATE_REG", 0xA4500014},
{ "PI_DRAM_ADDR_REG", 0xA4600000 }, {"PI_DRAM_ADDR_REG", 0xA4600000},
{ "PI_CART_ADDR_REG", 0xA4600004 }, {"PI_CART_ADDR_REG", 0xA4600004},
{ "PI_RD_LEN_REG", 0xA4600008 }, {"PI_RD_LEN_REG", 0xA4600008},
{ "PI_WR_LEN_REG", 0xA460000C }, {"PI_WR_LEN_REG", 0xA460000C},
{ "PI_STATUS_REG", 0xA4600010 }, {"PI_STATUS_REG", 0xA4600010},
{ "PI_BSD_DOM1_LAT_REG", 0xA4600014 }, {"PI_BSD_DOM1_LAT_REG", 0xA4600014},
{ "PI_BSD_DOM1_PWD_REG", 0xA4600018 }, {"PI_BSD_DOM1_PWD_REG", 0xA4600018},
{ "PI_BSD_DOM1_PGS_REG", 0xA460001C }, {"PI_BSD_DOM1_PGS_REG", 0xA460001C},
{ "PI_BSD_DOM1_RLS_REG", 0xA4600020 }, {"PI_BSD_DOM1_RLS_REG", 0xA4600020},
{ "PI_BSD_DOM2_LAT_REG", 0xA4600024 }, {"PI_BSD_DOM2_LAT_REG", 0xA4600024},
{ "PI_BSD_DOM2_PWD_REG", 0xA4600028 }, {"PI_BSD_DOM2_PWD_REG", 0xA4600028},
{ "PI_BSD_DOM2_PGS_REG", 0xA460002C }, {"PI_BSD_DOM2_PGS_REG", 0xA460002C},
{ "PI_BSD_DOM2_RLS_REG", 0xA4600030 }, {"PI_BSD_DOM2_RLS_REG", 0xA4600030},
{ "RI_MODE_REG", 0xA4700000 }, {"RI_MODE_REG", 0xA4700000},
{ "RI_CONFIG_REG", 0xA4700004 }, {"RI_CONFIG_REG", 0xA4700004},
{ "RI_CURRENT_LOAD_REG", 0xA4700008 }, {"RI_CURRENT_LOAD_REG", 0xA4700008},
{ "RI_SELECT_REG", 0xA470000C }, {"RI_SELECT_REG", 0xA470000C},
{ "RI_REFRESH_REG", 0xA4700010 }, {"RI_REFRESH_REG", 0xA4700010},
{ "RI_COUNT_REG", 0xA4700010 }, {"RI_COUNT_REG", 0xA4700010},
{ "RI_LATENCY_REG", 0xA4700014 }, {"RI_LATENCY_REG", 0xA4700014},
{ "RI_RERROR_REG", 0xA4700018 }, {"RI_RERROR_REG", 0xA4700018},
{ "RI_WERROR_REG", 0xA470001C }, {"RI_WERROR_REG", 0xA470001C},
{ "SI_DRAM_ADDR_REG", 0xA4800000 }, {"SI_DRAM_ADDR_REG", 0xA4800000},
{ "SI_PIF_ADDR_RD64B_REG", 0xA4800004 }, {"SI_PIF_ADDR_RD64B_REG", 0xA4800004},
{ "SI_PIF_ADDR_WR64B_REG", 0xA4800010 }, {"SI_PIF_ADDR_WR64B_REG", 0xA4800010},
{ "SI_STATUS_REG", 0xA4800018 }, {"SI_STATUS_REG", 0xA4800018},
{ "PIF_ROM_START", 0xBFC00000 }, {"PIF_ROM_START", 0xBFC00000},
{ "PIF_RAM_START", 0xBFC007C0 }, {"PIF_RAM_START", 0xBFC007C0},
{ "SP_DMEM_START", 0xA4000000 }, {"SP_DMEM_START", 0xA4000000},
{ "SP_IMEM_START", 0xA4001000 }, {"SP_IMEM_START", 0xA4001000},
{ "KUBASE", 0x00000000 }, {"KUBASE", 0x00000000},
{ "K0BASE", 0x80000000 }, {"K0BASE", 0x80000000},
{ "K1BASE", 0xA0000000 }, {"K1BASE", 0xA0000000},
{ "K2BASE", 0xC0000000 }, {"K2BASE", 0xC0000000},
{ "UT_VEC", 0x80000000 }, {"UT_VEC", 0x80000000},
{ "R_VEC", 0xBFC00000 }, {"R_VEC", 0xBFC00000},
{ "XUT_VEC", 0x80000080 }, {"XUT_VEC", 0x80000080},
{ "ECC_VEC", 0x80000100 }, {"ECC_VEC", 0x80000100},
{ "E_VEC", 0x80000180 }, {"E_VEC", 0x80000180},
{ "M_GFXTASK", 1 },
{ "M_AUDTASK", 2 },
{ "OS_READ", 0 },
{ "OS_WRITE", 1 },
{ "COLOR_BLACK", 0x000000FF },
{ "COLOR_WHITE", 0xFFFFFFFF },
{ "COLOR_GRAY", 0x808080FF },
{ "COLOR_RED", 0xFF0000FF },
{ "COLOR_GREEN", 0x00FF00FF },
{ "COLOR_BLUE", 0x0000FFFF },
{ "COLOR_YELLOW", 0xFFFF00FF },
{ "COLOR_CYAN", 0x00FFFFFF },
{ "COLOR_MAGENTA", 0xFF00FFFF },
{ "EMU_STARTED", JS_EMU_STARTED }, {"M_GFXTASK", 1},
{ "EMU_STOPPED", JS_EMU_STOPPED }, {"M_AUDTASK", 2},
{ "EMU_PAUSED", JS_EMU_PAUSED }, {"OS_READ", 0},
{ "EMU_RESUMED", JS_EMU_RESUMED }, {"OS_WRITE", 1},
{ "EMU_RESETTING", JS_EMU_RESETTING },
{ "EMU_RESET", JS_EMU_RESET },
{ "EMU_LOADED_ROM", JS_EMU_LOADED_ROM },
{ "EMU_LOADED_STATE", JS_EMU_LOADED_STATE },
{ "EMU_DEBUG_PAUSED", JS_EMU_DEBUG_PAUSED },
{ "EMU_DEBUG_RESUMED", JS_EMU_DEBUG_RESUMED },
{ "IMG_I4", IMG_I4 }, {"COLOR_BLACK", 0x000000FF},
{ "IMG_I8", IMG_I8 }, {"COLOR_WHITE", 0xFFFFFFFF},
{ "IMG_IA4", IMG_IA4 }, {"COLOR_GRAY", 0x808080FF},
{ "IMG_IA8", IMG_IA8 }, {"COLOR_RED", 0xFF0000FF},
{ "IMG_IA16", IMG_IA16 }, {"COLOR_GREEN", 0x00FF00FF},
{ "IMG_RGBA16", IMG_RGBA16 }, {"COLOR_BLUE", 0x0000FFFF},
{ "IMG_RGBA32", IMG_RGBA32 }, {"COLOR_YELLOW", 0xFFFF00FF},
{ "IMG_CI8_RGBA16", IMG_CI8_RGBA16 }, {"COLOR_CYAN", 0x00FFFFFF},
{ "IMG_CI4_RGBA16", IMG_CI4_RGBA16 }, {"COLOR_MAGENTA", 0xFF00FFFF},
{ "IMG_CI8_IA16", IMG_CI8_IA16 },
{ "IMG_CI4_IA16", IMG_CI4_IA16 },
{ "G_IM_FMT_RGBA", G_IM_FMT_RGBA }, {"EMU_STARTED", JS_EMU_STARTED},
{ "G_IM_FMT_YUV", G_IM_FMT_YUV }, {"EMU_STOPPED", JS_EMU_STOPPED},
{ "G_IM_FMT_CI", G_IM_FMT_CI }, {"EMU_PAUSED", JS_EMU_PAUSED},
{ "G_IM_FMT_IA", G_IM_FMT_IA }, {"EMU_RESUMED", JS_EMU_RESUMED},
{ "G_IM_FMT_I", G_IM_FMT_I }, {"EMU_RESETTING", JS_EMU_RESETTING},
{"EMU_RESET", JS_EMU_RESET},
{"EMU_LOADED_ROM", JS_EMU_LOADED_ROM},
{"EMU_LOADED_STATE", JS_EMU_LOADED_STATE},
{"EMU_DEBUG_PAUSED", JS_EMU_DEBUG_PAUSED},
{"EMU_DEBUG_RESUMED", JS_EMU_DEBUG_RESUMED},
{ "G_IM_SIZ_4b", G_IM_SIZ_4b }, {"IMG_I4", IMG_I4},
{ "G_IM_SIZ_8b", G_IM_SIZ_8b }, {"IMG_I8", IMG_I8},
{ "G_IM_SIZ_16b", G_IM_SIZ_16b }, {"IMG_IA4", IMG_IA4},
{ "G_IM_SIZ_32b", G_IM_SIZ_32b }, {"IMG_IA8", IMG_IA8},
{"IMG_IA16", IMG_IA16},
{"IMG_RGBA16", IMG_RGBA16},
{"IMG_RGBA32", IMG_RGBA32},
{"IMG_CI8_RGBA16", IMG_CI8_RGBA16},
{"IMG_CI4_RGBA16", IMG_CI4_RGBA16},
{"IMG_CI8_IA16", IMG_CI8_IA16},
{"IMG_CI4_IA16", IMG_CI4_IA16},
{ "G_TT_NONE", G_TT_NONE }, {"G_IM_FMT_RGBA", G_IM_FMT_RGBA},
{ "G_TT_RGBA16", G_TT_RGBA16 }, {"G_IM_FMT_YUV", G_IM_FMT_YUV},
{ "G_TT_IA16", G_TT_IA16 }, {"G_IM_FMT_CI", G_IM_FMT_CI},
{"G_IM_FMT_IA", G_IM_FMT_IA},
{"G_IM_FMT_I", G_IM_FMT_I},
{ nullptr, 0 }, {"G_IM_SIZ_4b", G_IM_SIZ_4b},
{"G_IM_SIZ_8b", G_IM_SIZ_8b},
{"G_IM_SIZ_16b", G_IM_SIZ_16b},
{"G_IM_SIZ_32b", G_IM_SIZ_32b},
{"G_TT_NONE", G_TT_NONE},
{"G_TT_RGBA16", G_TT_RGBA16},
{"G_TT_IA16", G_TT_IA16},
{nullptr, 0},
}; };
duk_push_global_object(ctx); duk_push_global_object(ctx);
@ -356,28 +357,28 @@ void ScriptAPI::DefineGlobalConstants(duk_context* ctx)
duk_pop(ctx); duk_pop(ctx);
} }
CScriptInstance* ScriptAPI::GetInstance(duk_context* ctx) CScriptInstance * ScriptAPI::GetInstance(duk_context * ctx)
{ {
duk_get_global_string(ctx, HS_gInstancePtr); duk_get_global_string(ctx, HS_gInstancePtr);
CScriptInstance* instance = (CScriptInstance*)duk_get_pointer(ctx, -1); CScriptInstance * instance = (CScriptInstance *)duk_get_pointer(ctx, -1);
duk_pop(ctx); duk_pop(ctx);
return instance; return instance;
} }
JSAppCallbackID ScriptAPI::AddAppCallback(duk_context* ctx, duk_idx_t callbackIdx, JSAppHookID hookId, JSAppCallbackID ScriptAPI::AddAppCallback(duk_context * ctx, duk_idx_t callbackIdx, JSAppHookID hookId,
JSDukArgSetupFunc argSetupFunc, JSAppCallbackCondFunc conditionFunc, JSAppCallbackCleanupFunc cleanupFunc) JSDukArgSetupFunc argSetupFunc, JSAppCallbackCondFunc conditionFunc, JSAppCallbackCleanupFunc cleanupFunc)
{ {
void* dukFuncHeapPtr = duk_get_heapptr(ctx, callbackIdx); void * dukFuncHeapPtr = duk_get_heapptr(ctx, callbackIdx);
JSAppCallback cb(GetInstance(ctx), dukFuncHeapPtr, conditionFunc, argSetupFunc, cleanupFunc); JSAppCallback cb(GetInstance(ctx), dukFuncHeapPtr, conditionFunc, argSetupFunc, cleanupFunc);
return AddAppCallback(ctx, hookId, cb); return AddAppCallback(ctx, hookId, cb);
} }
JSAppCallbackID ScriptAPI::AddAppCallback(duk_context* ctx, JSAppHookID hookId, JSAppCallback& callback) JSAppCallbackID ScriptAPI::AddAppCallback(duk_context * ctx, JSAppHookID hookId, JSAppCallback & callback)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
JSAppCallbackID callbackId = inst->System()->RawAddAppCallback(hookId, callback); JSAppCallbackID callbackId = inst->System()->RawAddAppCallback(hookId, callback);
if(callbackId == JS_INVALID_CALLBACK) if (callbackId == JS_INVALID_CALLBACK)
{ {
inst->System()->ConsoleLog("[SCRIPTSYS]: error: callback was not added"); inst->System()->ConsoleLog("[SCRIPTSYS]: error: callback was not added");
return JS_INVALID_CALLBACK; return JS_INVALID_CALLBACK;
@ -403,24 +404,24 @@ JSAppCallbackID ScriptAPI::AddAppCallback(duk_context* ctx, JSAppHookID hookId,
return callbackId; return callbackId;
} }
bool ScriptAPI::RemoveAppCallback(duk_context* ctx, JSAppCallbackID callbackId) bool ScriptAPI::RemoveAppCallback(duk_context * ctx, JSAppCallbackID callbackId)
{ {
duk_get_global_string(ctx, HS_gAppCallbacks); duk_get_global_string(ctx, HS_gAppCallbacks);
duk_bool_t bExists = duk_has_prop_index(ctx, -1, callbackId); duk_bool_t bExists = duk_has_prop_index(ctx, -1, callbackId);
if(bExists) if (bExists)
{ {
// will invoke CallbackFinalizer // will invoke CallbackFinalizer
duk_del_prop_index(ctx, -1, callbackId); duk_del_prop_index(ctx, -1, callbackId);
} }
duk_pop(ctx); duk_pop(ctx);
return bExists != 0; return bExists != 0;
} }
duk_ret_t ScriptAPI::js__AppCallbackFinalizer(duk_context* ctx) duk_ret_t ScriptAPI::js__AppCallbackFinalizer(duk_context * ctx)
{ {
CScriptInstance* inst = ScriptAPI::GetInstance(ctx); CScriptInstance * inst = ScriptAPI::GetInstance(ctx);
duk_get_prop_string(ctx, 0, "hookId"); duk_get_prop_string(ctx, 0, "hookId");
duk_get_prop_string(ctx, 0, "callbackId"); duk_get_prop_string(ctx, 0, "callbackId");
@ -434,10 +435,10 @@ duk_ret_t ScriptAPI::js__AppCallbackFinalizer(duk_context* ctx)
return 0; return 0;
} }
void ScriptAPI::RefObject(duk_context* ctx, duk_idx_t idx) void ScriptAPI::RefObject(duk_context * ctx, duk_idx_t idx)
{ {
idx = duk_normalize_index(ctx, idx); idx = duk_normalize_index(ctx, idx);
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
if (duk_has_prop_string(ctx, idx, HS_objectRefId)) if (duk_has_prop_string(ctx, idx, HS_objectRefId))
{ {
@ -458,16 +459,16 @@ void ScriptAPI::RefObject(duk_context* ctx, duk_idx_t idx)
duk_get_prop_string(ctx, -1, HS_gObjectRefs); duk_get_prop_string(ctx, -1, HS_gObjectRefs);
duk_dup(ctx, idx); duk_dup(ctx, idx);
duk_put_prop_index(ctx, -2, curObjectId); duk_put_prop_index(ctx, -2, curObjectId);
duk_pop_n(ctx, 2); duk_pop_n(ctx, 2);
inst->IncRefCount(); inst->IncRefCount();
} }
void ScriptAPI::UnrefObject(duk_context* ctx, duk_idx_t idx) void ScriptAPI::UnrefObject(duk_context * ctx, duk_idx_t idx)
{ {
idx = duk_normalize_index(ctx, idx); idx = duk_normalize_index(ctx, idx);
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
if (!duk_has_prop_string(ctx, idx, HS_objectRefId)) if (!duk_has_prop_string(ctx, idx, HS_objectRefId))
{ {
@ -481,21 +482,21 @@ void ScriptAPI::UnrefObject(duk_context* ctx, duk_idx_t idx)
duk_push_global_object(ctx); duk_push_global_object(ctx);
duk_get_prop_string(ctx, -1, HS_gObjectRefs); duk_get_prop_string(ctx, -1, HS_gObjectRefs);
duk_del_prop_index(ctx, -1, objectId); duk_del_prop_index(ctx, -1, objectId);
duk_pop_n(ctx, 2); duk_pop_n(ctx, 2);
inst->DecRefCount(); inst->DecRefCount();
} }
// PostCMethodCall variant // PostCMethodCall variant
duk_ret_t ScriptAPI::js__UnrefObject(duk_context* ctx) duk_ret_t ScriptAPI::js__UnrefObject(duk_context * ctx)
{ {
duk_push_this(ctx); duk_push_this(ctx);
UnrefObject(ctx, -1); UnrefObject(ctx, -1);
return 0; return 0;
} }
void ScriptAPI::InitEmitter(duk_context* ctx, duk_idx_t obj_idx, const std::vector<std::string>& eventNames) void ScriptAPI::InitEmitter(duk_context * ctx, duk_idx_t obj_idx, const std::vector<std::string> & eventNames)
{ {
obj_idx = duk_normalize_index(ctx, obj_idx); obj_idx = duk_normalize_index(ctx, obj_idx);
@ -514,9 +515,9 @@ void ScriptAPI::InitEmitter(duk_context* ctx, duk_idx_t obj_idx, const std::vect
duk_put_prop_string(ctx, obj_idx, HS_emitterNextListenerId); duk_put_prop_string(ctx, obj_idx, HS_emitterNextListenerId);
} }
duk_ret_t ScriptAPI::js__Emitter_emit(duk_context* ctx) duk_ret_t ScriptAPI::js__Emitter_emit(duk_context * ctx)
{ {
const char* eventName = duk_get_string(ctx, 0); const char * eventName = duk_get_string(ctx, 0);
duk_idx_t numListenerArgs = duk_get_top(ctx) - 1; duk_idx_t numListenerArgs = duk_get_top(ctx) - 1;
duk_push_this(ctx); duk_push_this(ctx);
@ -533,7 +534,7 @@ duk_ret_t ScriptAPI::js__Emitter_emit(duk_context* ctx)
int count = 0; int count = 0;
while (duk_next(ctx, -1, (duk_bool_t)true)) while (duk_next(ctx, -1, (duk_bool_t) true))
{ {
duk_push_this(ctx); duk_push_this(ctx);
for (duk_idx_t nArg = 0; nArg < numListenerArgs; nArg++) for (duk_idx_t nArg = 0; nArg < numListenerArgs; nArg++)
@ -542,7 +543,7 @@ duk_ret_t ScriptAPI::js__Emitter_emit(duk_context* ctx)
} }
// [ listenerFunc this args... ] -> [ retval ] // [ listenerFunc this args... ] -> [ retval ]
if (duk_pcall_method(ctx, numListenerArgs) != 0) if (duk_pcall_method(ctx, numListenerArgs) != 0)
{ {
duk_throw(ctx); duk_throw(ctx);
} }
@ -561,11 +562,11 @@ duk_ret_t ScriptAPI::js__Emitter_emit(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js__Emitter_on(duk_context* ctx) duk_ret_t ScriptAPI::js__Emitter_on(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_String, Arg_Function }); CheckArgs(ctx, {Arg_String, Arg_Function});
const char* eventName = duk_get_string(ctx, 0); const char * eventName = duk_get_string(ctx, 0);
duk_push_this(ctx); duk_push_this(ctx);
duk_get_prop_string(ctx, -1, HS_emitterListeners); duk_get_prop_string(ctx, -1, HS_emitterListeners);
@ -591,11 +592,11 @@ duk_ret_t ScriptAPI::js__Emitter_on(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js__Emitter_off(duk_context* ctx) duk_ret_t ScriptAPI::js__Emitter_off(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_String, Arg_Function }); CheckArgs(ctx, {Arg_String, Arg_Function});
const char* eventName = duk_get_string(ctx, 0); const char * eventName = duk_get_string(ctx, 0);
duk_push_this(ctx); duk_push_this(ctx);
duk_get_prop_string(ctx, -1, HS_emitterListeners); duk_get_prop_string(ctx, -1, HS_emitterListeners);
@ -608,7 +609,7 @@ duk_ret_t ScriptAPI::js__Emitter_off(duk_context* ctx)
duk_get_prop_string(ctx, -1, eventName); duk_get_prop_string(ctx, -1, eventName);
duk_enum(ctx, -1, 0); duk_enum(ctx, -1, 0);
while (duk_next(ctx, -1, (duk_bool_t)true)) while (duk_next(ctx, -1, (duk_bool_t) true))
{ {
if (duk_equals(ctx, 1, -1)) if (duk_equals(ctx, 1, -1))
{ {
@ -625,14 +626,14 @@ duk_ret_t ScriptAPI::js__Emitter_off(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_Duktape_modSearch(duk_context* ctx) duk_ret_t ScriptAPI::js_Duktape_modSearch(duk_context * ctx)
{ {
if (!duk_is_string(ctx, 0)) if (!duk_is_string(ctx, 0))
{ {
return ThrowInvalidArgsError(ctx); return ThrowInvalidArgsError(ctx);
} }
const char* id = duk_get_string(ctx, 0); const char * id = duk_get_string(ctx, 0);
stdstr strPath = GetInstance(ctx)->System()->ModulesDirPath() + id; stdstr strPath = GetInstance(ctx)->System()->ModulesDirPath() + id;
CPath path(strPath); CPath path(strPath);
@ -644,7 +645,7 @@ duk_ret_t ScriptAPI::js_Duktape_modSearch(duk_context* ctx)
if (hModule == nullptr) if (hModule == nullptr)
{ {
duk_push_error_object(ctx, DUK_ERR_ERROR, duk_push_error_object(ctx, DUK_ERR_ERROR,
"failed to load native module (\"%s\")", strPath.c_str()); "failed to load native module (\"%s\")", strPath.c_str());
return duk_throw(ctx); return duk_throw(ctx);
} }
@ -655,7 +656,7 @@ duk_ret_t ScriptAPI::js_Duktape_modSearch(duk_context* ctx)
{ {
FreeLibrary(hModule); FreeLibrary(hModule);
duk_push_error_object(ctx, DUK_ERR_ERROR, duk_push_error_object(ctx, DUK_ERR_ERROR,
"failed to locate module entry-point (\"%s\")", strProcName.c_str()); "failed to locate module entry-point (\"%s\")", strProcName.c_str());
return duk_throw(ctx); return duk_throw(ctx);
} }
@ -682,7 +683,7 @@ duk_ret_t ScriptAPI::js_Duktape_modSearch(duk_context* ctx)
uint32_t length = file.GetLength(); uint32_t length = file.GetLength();
char* sourceCode = new char[length + 1]; char * sourceCode = new char[length + 1];
sourceCode[length] = '\0'; sourceCode[length] = '\0';
if (file.Read(sourceCode, length) != length) if (file.Read(sourceCode, length) != length)
@ -696,7 +697,7 @@ duk_ret_t ScriptAPI::js_Duktape_modSearch(duk_context* ctx)
return 1; return 1;
} }
void ScriptAPI::RegisterNativeModule(duk_context* ctx, HMODULE hModule) void ScriptAPI::RegisterNativeModule(duk_context * ctx, HMODULE hModule)
{ {
duk_get_global_string(ctx, HS_gNativeModules); duk_get_global_string(ctx, HS_gNativeModules);
duk_size_t index = duk_get_length(ctx, -1); duk_size_t index = duk_get_length(ctx, -1);
@ -709,7 +710,7 @@ void ScriptAPI::RegisterNativeModule(duk_context* ctx, HMODULE hModule)
duk_pop(ctx); duk_pop(ctx);
} }
duk_ret_t ScriptAPI::js__NativeModuleFinalizer(duk_context* ctx) duk_ret_t ScriptAPI::js__NativeModuleFinalizer(duk_context * ctx)
{ {
duk_get_prop_string(ctx, 0, "modPtr"); duk_get_prop_string(ctx, 0, "modPtr");
HMODULE hModule = (HMODULE)duk_get_pointer(ctx, -1); HMODULE hModule = (HMODULE)duk_get_pointer(ctx, -1);
@ -717,10 +718,10 @@ duk_ret_t ScriptAPI::js__NativeModuleFinalizer(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::ThrowInvalidArgsError(duk_context* ctx) duk_ret_t ScriptAPI::ThrowInvalidArgsError(duk_context * ctx)
{ {
duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR, "invalid argument(s)"); duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR, "invalid argument(s)");
return duk_throw(ctx); return duk_throw(ctx);
} }
duk_ret_t ScriptAPI::ThrowInvalidArgError(duk_context * ctx, duk_idx_t idx, ArgType wantType) duk_ret_t ScriptAPI::ThrowInvalidArgError(duk_context * ctx, duk_idx_t idx, ArgType wantType)
@ -735,32 +736,32 @@ duk_ret_t ScriptAPI::ThrowTooManyArgsError(duk_context * ctx)
return duk_throw(ctx); return duk_throw(ctx);
} }
duk_ret_t ScriptAPI::ThrowInvalidAssignmentError(duk_context* ctx, ArgType wantType) duk_ret_t ScriptAPI::ThrowInvalidAssignmentError(duk_context * ctx, ArgType wantType)
{ {
duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR, "invalid assignment, expected %s", ArgTypeName(wantType)); duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR, "invalid assignment, expected %s", ArgTypeName(wantType));
return duk_throw(ctx); return duk_throw(ctx);
} }
duk_ret_t ScriptAPI::ThrowNotCallableError(duk_context* ctx) duk_ret_t ScriptAPI::ThrowNotCallableError(duk_context * ctx)
{ {
duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR, "not callable"); duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR, "not callable");
return duk_throw(ctx); return duk_throw(ctx);
} }
void ScriptAPI::DebugStack(duk_context* ctx, const char* file, int line) void ScriptAPI::DebugStack(duk_context * ctx, const char * file, int line)
{ {
duk_push_context_dump(ctx); duk_push_context_dump(ctx);
GetInstance(ctx)->System()->ConsoleLog("[SCRIPTSYS] <%s:%d> %s", file, line, duk_to_string(ctx, -1)); GetInstance(ctx)->System()->ConsoleLog("[SCRIPTSYS] <%s:%d> %s", file, line, duk_to_string(ctx, -1));
duk_pop(ctx); duk_pop(ctx);
} }
void ScriptAPI::AllowPrivateCall(duk_context* ctx, bool bAllow) void ScriptAPI::AllowPrivateCall(duk_context * ctx, bool bAllow)
{ {
duk_push_boolean(ctx, (duk_bool_t)bAllow); duk_push_boolean(ctx, (duk_bool_t)bAllow);
duk_put_global_string(ctx, HS_gPrivateCallEnabled); duk_put_global_string(ctx, HS_gPrivateCallEnabled);
} }
bool ScriptAPI::PrivateCallAllowed(duk_context* ctx) bool ScriptAPI::PrivateCallAllowed(duk_context * ctx)
{ {
if (!duk_get_global_string(ctx, HS_gPrivateCallEnabled)) if (!duk_get_global_string(ctx, HS_gPrivateCallEnabled))
{ {
@ -773,12 +774,12 @@ bool ScriptAPI::PrivateCallAllowed(duk_context* ctx)
return bAllowed; return bAllowed;
} }
duk_ret_t ScriptAPI::js_DummyConstructor(duk_context* ctx) duk_ret_t ScriptAPI::js_DummyConstructor(duk_context * ctx)
{ {
return ThrowNotCallableError(ctx); return ThrowNotCallableError(ctx);
} }
void ScriptAPI::PushNewDummyConstructor(duk_context* ctx, bool bFrozen) void ScriptAPI::PushNewDummyConstructor(duk_context * ctx, bool bFrozen)
{ {
duk_push_c_function(ctx, js_DummyConstructor, 0); duk_push_c_function(ctx, js_DummyConstructor, 0);
duk_push_object(ctx); duk_push_object(ctx);
@ -790,7 +791,7 @@ void ScriptAPI::PushNewDummyConstructor(duk_context* ctx, bool bFrozen)
} }
} }
void ScriptAPI::DefineGlobalDummyConstructors(duk_context* ctx, const char* constructorNames[], bool bFreeze) void ScriptAPI::DefineGlobalDummyConstructors(duk_context * ctx, const char * constructorNames[], bool bFreeze)
{ {
duk_push_global_object(ctx); duk_push_global_object(ctx);
@ -808,7 +809,7 @@ void ScriptAPI::DefineGlobalDummyConstructors(duk_context* ctx, const char* cons
duk_pop(ctx); duk_pop(ctx);
} }
void ScriptAPI::SetDummyConstructor(duk_context* ctx, duk_idx_t obj_idx, const char* globalConstructorName) void ScriptAPI::SetDummyConstructor(duk_context * ctx, duk_idx_t obj_idx, const char * globalConstructorName)
{ {
obj_idx = duk_normalize_index(ctx, obj_idx); obj_idx = duk_normalize_index(ctx, obj_idx);
duk_get_global_string(ctx, globalConstructorName); duk_get_global_string(ctx, globalConstructorName);
@ -817,13 +818,13 @@ void ScriptAPI::SetDummyConstructor(duk_context* ctx, duk_idx_t obj_idx, const c
duk_pop(ctx); duk_pop(ctx);
} }
void ScriptAPI::DukPutPropList(duk_context* ctx, duk_idx_t obj_idx, const DukPropListEntry* props) void ScriptAPI::DukPutPropList(duk_context * ctx, duk_idx_t obj_idx, const DukPropListEntry * props)
{ {
obj_idx = duk_normalize_index(ctx, obj_idx); obj_idx = duk_normalize_index(ctx, obj_idx);
for (size_t i = 0;; i++) for (size_t i = 0;; i++)
{ {
const DukPropListEntry& prop = props[i]; const DukPropListEntry & prop = props[i];
if (prop.key == nullptr) if (prop.key == nullptr)
{ {
@ -832,7 +833,7 @@ void ScriptAPI::DukPutPropList(duk_context* ctx, duk_idx_t obj_idx, const DukPro
duk_uint_t propFlags = 0; duk_uint_t propFlags = 0;
bool bHiddenSymbol = (prop.key[0] == '\xFF'); bool bHiddenSymbol = (prop.key[0] == '\xFF');
if (!bHiddenSymbol) if (!bHiddenSymbol)
{ {
propFlags |= prop.writable ? DUK_DEFPROP_SET_WRITABLE : 0; propFlags |= prop.writable ? DUK_DEFPROP_SET_WRITABLE : 0;
@ -881,17 +882,17 @@ void ScriptAPI::DukPutPropList(duk_context* ctx, duk_idx_t obj_idx, const DukPro
duk_push_c_function(ctx, prop.value.dukCFunction.func, prop.value.dukCFunction.nargs); duk_push_c_function(ctx, prop.value.dukCFunction.func, prop.value.dukCFunction.nargs);
break; break;
case Type_DukDupIndex: case Type_DukDupIndex:
{
propFlags |= DUK_DEFPROP_HAVE_VALUE;
duk_idx_t fixedDupIndex = prop.value.dukDupIndex.value;
if (fixedDupIndex < 0)
{ {
propFlags |= DUK_DEFPROP_HAVE_VALUE; // -1 to account for prop.key push above
duk_idx_t fixedDupIndex = prop.value.dukDupIndex.value; fixedDupIndex = duk_normalize_index(ctx, fixedDupIndex - 1);
if (fixedDupIndex < 0)
{
// -1 to account for prop.key push above
fixedDupIndex = duk_normalize_index(ctx, fixedDupIndex - 1);
}
duk_dup(ctx, fixedDupIndex);
} }
break; duk_dup(ctx, fixedDupIndex);
}
break;
case Type_DukGetter: case Type_DukGetter:
propFlags |= DUK_DEFPROP_HAVE_GETTER; propFlags |= DUK_DEFPROP_HAVE_GETTER;
duk_push_c_function(ctx, prop.value.dukGetter.value, 0); duk_push_c_function(ctx, prop.value.dukGetter.value, 0);
@ -935,7 +936,7 @@ void ScriptAPI::DukPutPropList(duk_context* ctx, duk_idx_t obj_idx, const DukPro
} }
} }
duk_bool_t ScriptAPI::ArgTypeMatches(duk_context* ctx, duk_idx_t idx, ArgType wantType) duk_bool_t ScriptAPI::ArgTypeMatches(duk_context * ctx, duk_idx_t idx, ArgType wantType)
{ {
ArgType argType = (ArgType)(wantType & (~ArgAttrs)); ArgType argType = (ArgType)(wantType & (~ArgAttrs));
@ -965,18 +966,17 @@ duk_bool_t ScriptAPI::ArgTypeMatches(duk_context* ctx, duk_idx_t idx, ArgType wa
return false; return false;
} }
const char* ScriptAPI::ArgTypeName(ArgType argType) const char * ScriptAPI::ArgTypeName(ArgType argType)
{ {
static const std::map<ArgType, std::string> argTypeNames = { static const std::map<ArgType, std::string> argTypeNames = {
{ Arg_Any, "any" }, {Arg_Any, "any"},
{ Arg_Number, "number" }, {Arg_Number, "number"},
{ Arg_BufferData, "bufferdata" }, {Arg_BufferData, "bufferdata"},
{ Arg_String, "string" }, {Arg_String, "string"},
{ Arg_Function, "function" }, {Arg_Function, "function"},
{ Arg_Object, "object" }, {Arg_Object, "object"},
{ Arg_Array, "array" }, {Arg_Array, "array"},
{ Arg_Boolean, "boolean" } {Arg_Boolean, "boolean"}};
};
if (argTypeNames.count(argType) == 0) if (argTypeNames.count(argType) == 0)
{ {
@ -986,7 +986,7 @@ const char* ScriptAPI::ArgTypeName(ArgType argType)
return argTypeNames.at(argType).c_str(); return argTypeNames.at(argType).c_str();
} }
duk_ret_t ScriptAPI::CheckSetterAssignment(duk_context* ctx, ArgType wantType) duk_ret_t ScriptAPI::CheckSetterAssignment(duk_context * ctx, ArgType wantType)
{ {
if (!ArgTypeMatches(ctx, 0, wantType)) if (!ArgTypeMatches(ctx, 0, wantType))
{ {
@ -995,7 +995,7 @@ duk_ret_t ScriptAPI::CheckSetterAssignment(duk_context* ctx, ArgType wantType)
return 0; return 0;
} }
duk_ret_t ScriptAPI::CheckArgs(duk_context* ctx, const std::vector<ArgType>& argTypes) duk_ret_t ScriptAPI::CheckArgs(duk_context * ctx, const std::vector<ArgType> & argTypes)
{ {
duk_idx_t nargs = duk_get_top(ctx); duk_idx_t nargs = duk_get_top(ctx);

View File

@ -1,38 +1,43 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptAPI.h" #include "ScriptAPI.h"
#pragma warning(disable: 4702) // disable unreachable code warning #pragma warning(disable : 4702) // disable unreachable code warning
static void GetRange(duk_context* ctx, duk_idx_t idx, uint32_t* start, uint32_t* end); static void GetRange(duk_context * ctx, duk_idx_t idx, uint32_t * start, uint32_t * end);
void ScriptAPI::Define_AddressRange(duk_context* ctx) void ScriptAPI::Define_AddressRange(duk_context * ctx)
{ {
const DukPropListEntry prototype[] = { const DukPropListEntry prototype[] = {
{ "size", DukCFunction(js_AddressRange_size) }, {"size", DukCFunction(js_AddressRange_size)},
{ "includes", DukCFunction(js_AddressRange_includes) }, {"includes", DukCFunction(js_AddressRange_includes)},
{ "offset", DukCFunction(js_AddressRange_offset) }, {"offset", DukCFunction(js_AddressRange_offset)},
{ "address", DukCFunction(js_AddressRange_address) }, {"address", DukCFunction(js_AddressRange_address)},
{ nullptr } { nullptr }
}; };
DefineGlobalClass(ctx, "AddressRange", js_AddressRange__constructor, prototype); DefineGlobalClass(ctx, "AddressRange", js_AddressRange__constructor, prototype);
struct { const char* key; uint32_t start, end; } ranges[] = { struct
{ "ADDR_ANY", 0x00000000, 0xFFFFFFFF }, {
{ "ADDR_ANY_KUSEG", 0x00000000, 0x7FFFFFFF }, const char * key;
{ "ADDR_ANY_KSEG0", 0x80000000, 0x9FFFFFFF }, uint32_t start, end;
{ "ADDR_ANY_KSEG1", 0xA0000000, 0xBFFFFFFF }, } ranges[] = {
{ "ADDR_ANY_KSEG2", 0xC0000000, 0xFFFFFFFF }, {"ADDR_ANY", 0x00000000, 0xFFFFFFFF},
{ "ADDR_ANY_RDRAM", 0x80000000, 0x807FFFFF }, {"ADDR_ANY_KUSEG", 0x00000000, 0x7FFFFFFF},
{ "ADDR_ANY_RDRAM_UNC", 0xA0000000, 0xA07FFFFF }, {"ADDR_ANY_KSEG0", 0x80000000, 0x9FFFFFFF},
{ "ADDR_ANY_CART_ROM", 0x90000000, 0x95FFFFFF }, {"ADDR_ANY_KSEG1", 0xA0000000, 0xBFFFFFFF},
{ "ADDR_ANY_CART_ROM_UNC", 0xB0000000, 0xB5FFFFFF }, {"ADDR_ANY_KSEG2", 0xC0000000, 0xFFFFFFFF},
{"ADDR_ANY_RDRAM", 0x80000000, 0x807FFFFF},
{"ADDR_ANY_RDRAM_UNC", 0xA0000000, 0xA07FFFFF},
{"ADDR_ANY_CART_ROM", 0x90000000, 0x95FFFFFF},
{"ADDR_ANY_CART_ROM_UNC", 0xB0000000, 0xB5FFFFFF},
{ nullptr, 0, 0 } { nullptr, 0, 0 }
}; };
duk_push_global_object(ctx); duk_push_global_object(ctx);
for(int i = 0; ranges[i].key != nullptr; i++) for (int i = 0; ranges[i].key != nullptr; i++)
{ {
duk_push_string(ctx, ranges[i].key); duk_push_string(ctx, ranges[i].key);
duk_get_global_string(ctx, "AddressRange"); duk_get_global_string(ctx, "AddressRange");
@ -45,16 +50,16 @@ void ScriptAPI::Define_AddressRange(duk_context* ctx)
duk_pop(ctx); duk_pop(ctx);
} }
duk_ret_t ScriptAPI::js_AddressRange__constructor(duk_context* ctx) duk_ret_t ScriptAPI::js_AddressRange__constructor(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number, Arg_Number }); CheckArgs(ctx, {Arg_Number, Arg_Number});
duk_to_uint32(ctx, 0); duk_to_uint32(ctx, 0);
duk_to_uint32(ctx, 1); duk_to_uint32(ctx, 1);
duk_uint_t start = duk_get_uint(ctx, 0); duk_uint_t start = duk_get_uint(ctx, 0);
duk_uint_t end = duk_get_uint(ctx, 1); duk_uint_t end = duk_get_uint(ctx, 1);
if (end < start) if (end < start)
{ {
duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "invalid range; end cannot be less than start"); duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "invalid range; end cannot be less than start");
@ -72,7 +77,7 @@ duk_ret_t ScriptAPI::js_AddressRange__constructor(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_AddressRange_size(duk_context* ctx) duk_ret_t ScriptAPI::js_AddressRange_size(duk_context * ctx)
{ {
CheckArgs(ctx, {}); CheckArgs(ctx, {});
duk_uint_t start, end; duk_uint_t start, end;
@ -84,9 +89,9 @@ duk_ret_t ScriptAPI::js_AddressRange_size(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_AddressRange_includes(duk_context* ctx) duk_ret_t ScriptAPI::js_AddressRange_includes(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number }); CheckArgs(ctx, {Arg_Number});
duk_to_uint32(ctx, 0); duk_to_uint32(ctx, 0);
duk_uint_t address = duk_get_uint(ctx, 0); duk_uint_t address = duk_get_uint(ctx, 0);
duk_uint_t start, end; duk_uint_t start, end;
@ -98,9 +103,9 @@ duk_ret_t ScriptAPI::js_AddressRange_includes(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_AddressRange_offset(duk_context* ctx) duk_ret_t ScriptAPI::js_AddressRange_offset(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number }); CheckArgs(ctx, {Arg_Number});
duk_to_uint32(ctx, 0); duk_to_uint32(ctx, 0);
duk_uint_t address = duk_get_uint(ctx, 0); duk_uint_t address = duk_get_uint(ctx, 0);
duk_uint_t start, end; duk_uint_t start, end;
@ -108,7 +113,8 @@ duk_ret_t ScriptAPI::js_AddressRange_offset(duk_context* ctx)
duk_push_this(ctx); duk_push_this(ctx);
GetRange(ctx, -1, &start, &end); GetRange(ctx, -1, &start, &end);
if (address < start || address > end) { if (address < start || address > end)
{
duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "address out of bounds"); duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "address out of bounds");
return duk_throw(ctx); return duk_throw(ctx);
} }
@ -117,9 +123,9 @@ duk_ret_t ScriptAPI::js_AddressRange_offset(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_AddressRange_address(duk_context* ctx) duk_ret_t ScriptAPI::js_AddressRange_address(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number }); CheckArgs(ctx, {Arg_Number});
duk_int_t offset = duk_get_int(ctx, 0); duk_int_t offset = duk_get_int(ctx, 0);
duk_uint_t start, end; duk_uint_t start, end;
@ -129,7 +135,8 @@ duk_ret_t ScriptAPI::js_AddressRange_address(duk_context* ctx)
duk_uint_t address = start + offset; duk_uint_t address = start + offset;
if (address < start || address > end) { if (address < start || address > end)
{
duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "offset out of bounds"); duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, "offset out of bounds");
return duk_throw(ctx); return duk_throw(ctx);
} }
@ -138,7 +145,7 @@ duk_ret_t ScriptAPI::js_AddressRange_address(duk_context* ctx)
return 1; return 1;
} }
static void GetRange(duk_context* ctx, duk_idx_t idx, uint32_t* start, uint32_t* end) static void GetRange(duk_context * ctx, duk_idx_t idx, uint32_t * start, uint32_t * end)
{ {
idx = duk_normalize_index(ctx, idx); idx = duk_normalize_index(ctx, idx);
duk_get_prop_string(ctx, idx, "start"); duk_get_prop_string(ctx, idx, "start");

View File

@ -1,16 +1,17 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptAPI.h"
#include "N64Image.h"
#pragma warning(disable: 4702) // disable unreachable code warning #include "N64Image.h"
#include "ScriptAPI.h"
#pragma warning(disable : 4702) // disable unreachable code warning
using namespace ScriptAPI; using namespace ScriptAPI;
static CN64Image* GetThisImage(duk_context* ctx) static CN64Image * GetThisImage(duk_context * ctx)
{ {
duk_push_this(ctx); duk_push_this(ctx);
duk_get_prop_string(ctx, -1, HS_n64ImagePtr); duk_get_prop_string(ctx, -1, HS_n64ImagePtr);
CN64Image* image = (CN64Image*)duk_get_pointer(ctx, -1); CN64Image * image = (CN64Image *)duk_get_pointer(ctx, -1);
duk_pop_n(ctx, 2); duk_pop_n(ctx, 2);
if (image == nullptr) if (image == nullptr)
@ -22,25 +23,25 @@ static CN64Image* GetThisImage(duk_context* ctx)
return image; return image;
} }
void ScriptAPI::Define_N64Image(duk_context* ctx) void ScriptAPI::Define_N64Image(duk_context * ctx)
{ {
const DukPropListEntry prototype[] = { const DukPropListEntry prototype[] = {
{ "toPNG", DukCFunction(js_N64Image_toPNG) }, {"toPNG", DukCFunction(js_N64Image_toPNG)},
{ "update", DukCFunction(js_N64Image_update) }, {"update", DukCFunction(js_N64Image_update)},
{ nullptr} { nullptr}
}; };
const DukPropListEntry staticProps[] = { const DukPropListEntry staticProps[] = {
{ "fromPNG", DukCFunction(js_N64Image_static_fromPNG) }, {"fromPNG", DukCFunction(js_N64Image_static_fromPNG)},
{ "format", DukCFunction(js_N64Image_static_format) }, {"format", DukCFunction(js_N64Image_static_format)},
{ "bpp", DukCFunction(js_N64Image_static_bpp) }, {"bpp", DukCFunction(js_N64Image_static_bpp)},
{ nullptr } { nullptr }
}; };
DefineGlobalClass(ctx, "N64Image", js_N64Image__constructor, prototype, staticProps); DefineGlobalClass(ctx, "N64Image", js_N64Image__constructor, prototype, staticProps);
} }
static void InitImageObjectProps(duk_context* ctx, duk_idx_t idx, CN64Image* image) static void InitImageObjectProps(duk_context * ctx, duk_idx_t idx, CN64Image * image)
{ {
idx = duk_normalize_index(ctx, idx); idx = duk_normalize_index(ctx, idx);
@ -66,11 +67,11 @@ static void InitImageObjectProps(duk_context* ctx, duk_idx_t idx, CN64Image* ima
duk_idx_t palette_idx = duk_normalize_index(ctx, -1); duk_idx_t palette_idx = duk_normalize_index(ctx, -1);
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ HS_n64ImagePtr, DukPointer(image) }, {HS_n64ImagePtr, DukPointer(image)},
{ "pixels", DukDupIndex(pixels_idx) }, {"pixels", DukDupIndex(pixels_idx)},
{ "palette", DukDupIndex(palette_idx) }, {"palette", DukDupIndex(palette_idx)},
{ "width", DukUInt(image->Width()) }, {"width", DukUInt(image->Width())},
{ "height", DukUInt(image->Height()) }, {"height", DukUInt(image->Height())},
{ nullptr } { nullptr }
}; };
@ -82,9 +83,9 @@ static void InitImageObjectProps(duk_context* ctx, duk_idx_t idx, CN64Image* ima
duk_set_finalizer(ctx, idx); duk_set_finalizer(ctx, idx);
} }
duk_ret_t ScriptAPI::js_N64Image__constructor(duk_context* ctx) duk_ret_t ScriptAPI::js_N64Image__constructor(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number, Arg_Number, Arg_OptNumber, Arg_OptBufferData, Arg_OptBufferData }); CheckArgs(ctx, {Arg_Number, Arg_Number, Arg_OptNumber, Arg_OptBufferData, Arg_OptBufferData});
if (!duk_is_constructor_call(ctx)) if (!duk_is_constructor_call(ctx))
{ {
@ -96,16 +97,16 @@ duk_ret_t ScriptAPI::js_N64Image__constructor(duk_context* ctx)
size_t width = duk_get_uint(ctx, 0); size_t width = duk_get_uint(ctx, 0);
size_t height = duk_get_uint(ctx, 1); size_t height = duk_get_uint(ctx, 1);
int format = duk_get_int_default(ctx, 2, IMG_RGBA32); int format = duk_get_int_default(ctx, 2, IMG_RGBA32);
void* pixelData = duk_get_buffer_data_default(ctx, 3, &pixelDataSize, nullptr, 0); void * pixelData = duk_get_buffer_data_default(ctx, 3, &pixelDataSize, nullptr, 0);
void* paletteData = duk_get_buffer_data_default(ctx, 4, &paletteDataSize, nullptr, 0); void * paletteData = duk_get_buffer_data_default(ctx, 4, &paletteDataSize, nullptr, 0);
CN64Image* image = new CN64Image(); CN64Image * image = new CN64Image();
int result = image->Init(format, width, height, pixelData, pixelDataSize, paletteData, paletteDataSize); int result = image->Init(format, width, height, pixelData, pixelDataSize, paletteData, paletteDataSize);
if (result != N64IMG_OK) if (result != N64IMG_OK)
{ {
duk_push_error_object(ctx, DUK_ERR_ERROR, "failed to initialize image (%s)", duk_push_error_object(ctx, DUK_ERR_ERROR, "failed to initialize image (%s)",
CN64Image::ResultCodeName(result)); CN64Image::ResultCodeName(result));
return duk_throw(ctx); return duk_throw(ctx);
} }
@ -114,10 +115,10 @@ duk_ret_t ScriptAPI::js_N64Image__constructor(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_N64Image__finalizer(duk_context* ctx) duk_ret_t ScriptAPI::js_N64Image__finalizer(duk_context * ctx)
{ {
duk_get_prop_string(ctx, 0, HS_n64ImagePtr); duk_get_prop_string(ctx, 0, HS_n64ImagePtr);
CN64Image* image = (CN64Image*)duk_get_pointer(ctx, -1); CN64Image * image = (CN64Image *)duk_get_pointer(ctx, -1);
if (image == nullptr) if (image == nullptr)
{ {
return 0; return 0;
@ -126,12 +127,12 @@ duk_ret_t ScriptAPI::js_N64Image__finalizer(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_N64Image_static_fromPNG(duk_context* ctx) duk_ret_t ScriptAPI::js_N64Image_static_fromPNG(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_BufferData, Arg_OptNumber }); CheckArgs(ctx, {Arg_BufferData, Arg_OptNumber});
int format = duk_get_int_default(ctx, 1, IMG_RGBA32); int format = duk_get_int_default(ctx, 1, IMG_RGBA32);
if (CN64Image::BitsPerPixel(format) == 0) if (CN64Image::BitsPerPixel(format) == 0)
{ {
duk_push_error_object(ctx, DUK_RET_TYPE_ERROR, "invalid format"); duk_push_error_object(ctx, DUK_RET_TYPE_ERROR, "invalid format");
@ -139,18 +140,18 @@ duk_ret_t ScriptAPI::js_N64Image_static_fromPNG(duk_context* ctx)
} }
size_t pngSize; size_t pngSize;
uint8_t* pngData = (uint8_t*)duk_get_buffer_data(ctx, 0, &pngSize); uint8_t * pngData = (uint8_t *)duk_get_buffer_data(ctx, 0, &pngSize);
CN64Image* image = new CN64Image(); CN64Image * image = new CN64Image();
int result = image->Init(format, pngData, pngSize); int result = image->Init(format, pngData, pngSize);
if (result != N64IMG_OK) if (result != N64IMG_OK)
{ {
delete image; delete image;
duk_push_error_object(ctx, DUK_ERR_ERROR, "failed to initialize image (%s)", duk_push_error_object(ctx, DUK_ERR_ERROR, "failed to initialize image (%s)",
CN64Image::ResultCodeName(result), result); CN64Image::ResultCodeName(result), result);
return duk_throw(ctx); return duk_throw(ctx);
} }
duk_push_object(ctx); duk_push_object(ctx);
duk_get_global_string(ctx, "N64Image"); duk_get_global_string(ctx, "N64Image");
duk_get_prop_string(ctx, -1, "prototype"); duk_get_prop_string(ctx, -1, "prototype");
@ -161,9 +162,9 @@ duk_ret_t ScriptAPI::js_N64Image_static_fromPNG(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_N64Image_static_format(duk_context* ctx) duk_ret_t ScriptAPI::js_N64Image_static_format(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number, Arg_Number, Arg_OptNumber }); CheckArgs(ctx, {Arg_Number, Arg_Number, Arg_OptNumber});
duk_uint_t gbiFmt = duk_get_uint(ctx, 0); duk_uint_t gbiFmt = duk_get_uint(ctx, 0);
duk_uint_t gbiSiz = duk_get_uint(ctx, 1); duk_uint_t gbiSiz = duk_get_uint(ctx, 1);
@ -193,9 +194,9 @@ duk_ret_t ScriptAPI::js_N64Image_static_format(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_N64Image_static_bpp(duk_context* ctx) duk_ret_t ScriptAPI::js_N64Image_static_bpp(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number }); CheckArgs(ctx, {Arg_Number});
duk_uint_t format = duk_get_uint(ctx, 0); duk_uint_t format = duk_get_uint(ctx, 0);
@ -214,28 +215,28 @@ duk_ret_t ScriptAPI::js_N64Image_static_bpp(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_N64Image_toPNG(duk_context* ctx) duk_ret_t ScriptAPI::js_N64Image_toPNG(duk_context * ctx)
{ {
CN64Image* image = GetThisImage(ctx); CN64Image * image = GetThisImage(ctx);
std::vector<uint8_t> png; std::vector<uint8_t> png;
image->ToPNG(png); image->ToPNG(png);
void* pngCopy = duk_push_buffer(ctx, png.size(), false); void * pngCopy = duk_push_buffer(ctx, png.size(), false);
duk_push_buffer_object(ctx, -1, 0, png.size(), DUK_BUFOBJ_NODEJS_BUFFER); duk_push_buffer_object(ctx, -1, 0, png.size(), DUK_BUFOBJ_NODEJS_BUFFER);
memcpy(pngCopy, png.data(), png.size()); memcpy(pngCopy, png.data(), png.size());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_N64Image_update(duk_context* ctx) duk_ret_t ScriptAPI::js_N64Image_update(duk_context * ctx)
{ {
CN64Image* image = GetThisImage(ctx); CN64Image * image = GetThisImage(ctx);
int result = image->UpdateBitmap(); int result = image->UpdateBitmap();
if (result != N64IMG_OK) if (result != N64IMG_OK)
{ {
duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap update failed (%s)", duk_push_error_object(ctx, DUK_ERR_ERROR, "bitmap update failed (%s)",
CN64Image::ResultCodeName(result)); CN64Image::ResultCodeName(result));
} }
return 0; return 0;
} }

View File

@ -1,7 +1,8 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptAPI.h" #include "ScriptAPI.h"
void ScriptAPI::Define_Number_prototype_hex(duk_context *ctx) void ScriptAPI::Define_Number_prototype_hex(duk_context * ctx)
{ {
duk_get_global_string(ctx, "Number"); duk_get_global_string(ctx, "Number");
duk_get_prop_string(ctx, -1, "prototype"); duk_get_prop_string(ctx, -1, "prototype");
@ -10,9 +11,9 @@ void ScriptAPI::Define_Number_prototype_hex(duk_context *ctx)
duk_pop_n(ctx, 2); duk_pop_n(ctx, 2);
} }
duk_ret_t ScriptAPI::js_Number_prototype_hex(duk_context *ctx) duk_ret_t ScriptAPI::js_Number_prototype_hex(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_OptNumber }); CheckArgs(ctx, {Arg_OptNumber});
duk_uint_t value; duk_uint_t value;
duk_uint_t length = 8; duk_uint_t length = 8;

View File

@ -1,26 +1,27 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptAPI.h"
#include "JSServerWorker.h" #include "JSServerWorker.h"
#include "ScriptAPI.h"
static CJSServerWorker* GetThisServer(duk_context* ctx); static CJSServerWorker * GetThisServer(duk_context * ctx);
void ScriptAPI::Define_Server(duk_context* ctx) void ScriptAPI::Define_Server(duk_context * ctx)
{ {
const DukPropListEntry prototype[] = { const DukPropListEntry prototype[] = {
{ "listen", DukCFunction(js_Server_listen) }, {"listen", DukCFunction(js_Server_listen)},
{ "close", DukCFunction(js_Server_close) }, {"close", DukCFunction(js_Server_close)},
{ "on", DukCFunction(js__Emitter_on) }, {"on", DukCFunction(js__Emitter_on)},
{ "off", DukCFunction(js__Emitter_off) }, {"off", DukCFunction(js__Emitter_off)},
{ "port", DukGetter(js_Server__get_port) }, {"port", DukGetter(js_Server__get_port)},
{ "address", DukGetter(js_Server__get_address) }, {"address", DukGetter(js_Server__get_address)},
{ "addressFamily", DukGetter(js_Server__get_addressFamily) }, {"addressFamily", DukGetter(js_Server__get_addressFamily)},
{ nullptr } { nullptr }
}; };
DefineGlobalClass(ctx, "Server", js_Server__constructor, prototype); DefineGlobalClass(ctx, "Server", js_Server__constructor, prototype);
} }
duk_ret_t ScriptAPI::js_Server__constructor(duk_context* ctx) duk_ret_t ScriptAPI::js_Server__constructor(duk_context * ctx)
{ {
CheckArgs(ctx, {}); CheckArgs(ctx, {});
@ -29,44 +30,39 @@ duk_ret_t ScriptAPI::js_Server__constructor(duk_context* ctx)
return DUK_RET_ERROR; return DUK_RET_ERROR;
} }
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
duk_push_this(ctx); duk_push_this(ctx);
void* objectHeapPtr = duk_get_heapptr(ctx, -1); void * objectHeapPtr = duk_get_heapptr(ctx, -1);
InitEmitter(ctx, -1, {"close", "connection", "error", "listening"});
InitEmitter(ctx, -1, {
"close",
"connection",
"error",
"listening"
});
duk_push_c_function(ctx, js_Server__finalizer, 1); duk_push_c_function(ctx, js_Server__finalizer, 1);
duk_set_finalizer(ctx, -2); duk_set_finalizer(ctx, -2);
CJSServerWorker* serverWorker = new CJSServerWorker(inst, objectHeapPtr); CJSServerWorker * serverWorker = new CJSServerWorker(inst, objectHeapPtr);
duk_push_pointer(ctx, serverWorker); duk_push_pointer(ctx, serverWorker);
duk_put_prop_string(ctx, -2, HS_serverWorkerPtr); duk_put_prop_string(ctx, -2, HS_serverWorkerPtr);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Server__finalizer(duk_context* ctx) duk_ret_t ScriptAPI::js_Server__finalizer(duk_context * ctx)
{ {
UnrefObject(ctx, 0); UnrefObject(ctx, 0);
duk_get_prop_string(ctx, 0, HS_serverWorkerPtr); duk_get_prop_string(ctx, 0, HS_serverWorkerPtr);
CJSServerWorker* serverWorker = (CJSServerWorker*)duk_get_pointer(ctx, -1); CJSServerWorker * serverWorker = (CJSServerWorker *)duk_get_pointer(ctx, -1);
delete serverWorker; delete serverWorker;
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Server_listen(duk_context* ctx) duk_ret_t ScriptAPI::js_Server_listen(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number, Arg_OptString, Arg_OptFunction }); CheckArgs(ctx, {Arg_Number, Arg_OptString, Arg_OptFunction});
CJSServerWorker* serverWorker = GetThisServer(ctx); CJSServerWorker * serverWorker = GetThisServer(ctx);
unsigned short port = (unsigned short)duk_get_int(ctx, 0); unsigned short port = (unsigned short)duk_get_int(ctx, 0);
const char* address = duk_get_string_default(ctx, 1, "0.0.0.0"); const char * address = duk_get_string_default(ctx, 1, "0.0.0.0");
// todo callback // todo callback
@ -79,41 +75,41 @@ duk_ret_t ScriptAPI::js_Server_listen(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Server_close(duk_context* ctx) duk_ret_t ScriptAPI::js_Server_close(duk_context * ctx)
{ {
CheckArgs(ctx, {}); CheckArgs(ctx, {});
CJSServerWorker* serverWorker = GetThisServer(ctx); CJSServerWorker * serverWorker = GetThisServer(ctx);
serverWorker->StopWorkerProc(); serverWorker->StopWorkerProc();
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Server__get_port(duk_context* ctx) duk_ret_t ScriptAPI::js_Server__get_port(duk_context * ctx)
{ {
CJSServerWorker* serverWorker = GetThisServer(ctx); CJSServerWorker * serverWorker = GetThisServer(ctx);
duk_push_uint(ctx, serverWorker->GetPort()); duk_push_uint(ctx, serverWorker->GetPort());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_Server__get_address(duk_context* ctx) duk_ret_t ScriptAPI::js_Server__get_address(duk_context * ctx)
{ {
CJSServerWorker* serverWorker = GetThisServer(ctx); CJSServerWorker * serverWorker = GetThisServer(ctx);
duk_push_string(ctx, serverWorker->GetAddress().c_str()); duk_push_string(ctx, serverWorker->GetAddress().c_str());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_Server__get_addressFamily(duk_context* ctx) duk_ret_t ScriptAPI::js_Server__get_addressFamily(duk_context * ctx)
{ {
CJSServerWorker* serverWorker = GetThisServer(ctx); CJSServerWorker * serverWorker = GetThisServer(ctx);
duk_push_string(ctx, serverWorker->GetFamily()); duk_push_string(ctx, serverWorker->GetFamily());
return 1; return 1;
} }
CJSServerWorker* GetThisServer(duk_context* ctx) CJSServerWorker * GetThisServer(duk_context * ctx)
{ {
duk_push_this(ctx); duk_push_this(ctx);
duk_get_prop_string(ctx, -1, HS_serverWorkerPtr); duk_get_prop_string(ctx, -1, HS_serverWorkerPtr);
CJSServerWorker* serverWorker = (CJSServerWorker*)duk_get_pointer(ctx, -1); CJSServerWorker * serverWorker = (CJSServerWorker *)duk_get_pointer(ctx, -1);
duk_pop_n(ctx, 2); duk_pop_n(ctx, 2);
return serverWorker; return serverWorker;
} }

View File

@ -1,37 +1,38 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptAPI.h"
#include "JSSocketWorker.h" #include "JSSocketWorker.h"
#include "ScriptAPI.h"
#pragma warning(disable: 4702) // disable unreachable code warning #pragma warning(disable : 4702) // disable unreachable code warning
static CJSSocketWorker* GetThisSocket(duk_context* ctx); static CJSSocketWorker * GetThisSocket(duk_context * ctx);
static duk_ret_t RequireBufferDataOrString(duk_context* ctx, duk_idx_t idx, const char** data, duk_size_t* size); static duk_ret_t RequireBufferDataOrString(duk_context * ctx, duk_idx_t idx, const char ** data, duk_size_t * size);
static duk_int_t RegisterWriteCallback(duk_context* ctx, duk_idx_t idx); static duk_int_t RegisterWriteCallback(duk_context * ctx, duk_idx_t idx);
static void RegisterWriteEndCallback(duk_context* ctx, duk_idx_t idx); static void RegisterWriteEndCallback(duk_context * ctx, duk_idx_t idx);
void ScriptAPI::Define_Socket(duk_context* ctx) void ScriptAPI::Define_Socket(duk_context * ctx)
{ {
const DukPropListEntry prototype[] = { const DukPropListEntry prototype[] = {
{ "connect", DukCFunction(js_Socket_connect) }, {"connect", DukCFunction(js_Socket_connect)},
{ "write", DukCFunction(js_Socket_write) }, {"write", DukCFunction(js_Socket_write)},
{ "end", DukCFunction(js_Socket_end) }, {"end", DukCFunction(js_Socket_end)},
{ "close", DukCFunction(js_Socket_close) }, {"close", DukCFunction(js_Socket_close)},
{ "on", DukCFunction(js__Emitter_on) }, {"on", DukCFunction(js__Emitter_on)},
{ "off", DukCFunction(js__Emitter_off) }, {"off", DukCFunction(js__Emitter_off)},
{ "localAddress", DukGetter(js_Socket__get_localAddress) }, {"localAddress", DukGetter(js_Socket__get_localAddress)},
{ "localPort", DukGetter(js_Socket__get_localPort) }, {"localPort", DukGetter(js_Socket__get_localPort)},
{ "remoteAddress", DukGetter(js_Socket__get_remoteAddress) }, {"remoteAddress", DukGetter(js_Socket__get_remoteAddress)},
{ "remotePort", DukGetter(js_Socket__get_remotePort) }, {"remotePort", DukGetter(js_Socket__get_remotePort)},
{ "addressFamily", DukGetter(js_Socket__get_addressFamily) }, {"addressFamily", DukGetter(js_Socket__get_addressFamily)},
{ nullptr } { nullptr }
}; };
DefineGlobalClass(ctx, "Socket", js_Socket__constructor, prototype, nullptr); DefineGlobalClass(ctx, "Socket", js_Socket__constructor, prototype, nullptr);
} }
duk_ret_t ScriptAPI::js_Socket__constructor(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket__constructor(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_OptObject }); CheckArgs(ctx, {Arg_OptObject});
if (!duk_is_constructor_call(ctx)) if (!duk_is_constructor_call(ctx))
{ {
@ -40,7 +41,7 @@ duk_ret_t ScriptAPI::js_Socket__constructor(duk_context* ctx)
bool bAllowHalfOpen = false; bool bAllowHalfOpen = false;
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
if (duk_is_object(ctx, 0)) if (duk_is_object(ctx, 0))
{ {
@ -53,17 +54,9 @@ duk_ret_t ScriptAPI::js_Socket__constructor(duk_context* ctx)
} }
duk_push_this(ctx); duk_push_this(ctx);
void* objectHeapPtr = duk_get_heapptr(ctx, -1); void * objectHeapPtr = duk_get_heapptr(ctx, -1);
InitEmitter(ctx, -1, { InitEmitter(ctx, -1, {"data", "end", "connect", "error", "close", "drain", "lookup"});
"data",
"end",
"connect",
"error",
"close",
"drain",
"lookup"
});
duk_push_uint(ctx, 0); duk_push_uint(ctx, 0);
duk_put_prop_string(ctx, -2, HS_socketNextWriteCallbackId); duk_put_prop_string(ctx, -2, HS_socketNextWriteCallbackId);
@ -74,9 +67,9 @@ duk_ret_t ScriptAPI::js_Socket__constructor(duk_context* ctx)
duk_push_array(ctx); duk_push_array(ctx);
duk_put_prop_string(ctx, -2, HS_socketWriteEndCallbacks); duk_put_prop_string(ctx, -2, HS_socketWriteEndCallbacks);
CJSSocketWorker* socketWorker = new CJSSocketWorker(inst, objectHeapPtr, bAllowHalfOpen); CJSSocketWorker * socketWorker = new CJSSocketWorker(inst, objectHeapPtr, bAllowHalfOpen);
duk_push_pointer(ctx, (void*)socketWorker); duk_push_pointer(ctx, (void *)socketWorker);
duk_put_prop_string(ctx, -2, HS_socketWorkerPtr); duk_put_prop_string(ctx, -2, HS_socketWorkerPtr);
duk_push_c_function(ctx, js_Socket__finalizer, 1); duk_push_c_function(ctx, js_Socket__finalizer, 1);
@ -85,10 +78,10 @@ duk_ret_t ScriptAPI::js_Socket__constructor(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Socket__finalizer(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket__finalizer(duk_context * ctx)
{ {
duk_get_prop_string(ctx, 0, HS_socketWorkerPtr); duk_get_prop_string(ctx, 0, HS_socketWorkerPtr);
CJSSocketWorker* socketWorker = (CJSSocketWorker*)duk_get_pointer(ctx, -1); CJSSocketWorker * socketWorker = (CJSSocketWorker *)duk_get_pointer(ctx, -1);
if (socketWorker == nullptr) if (socketWorker == nullptr)
{ {
@ -101,15 +94,15 @@ duk_ret_t ScriptAPI::js_Socket__finalizer(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Socket_connect(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket_connect(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number, Arg_String, Arg_OptFunction }); CheckArgs(ctx, {Arg_Number, Arg_String, Arg_OptFunction});
CJSSocketWorker * socketWorker = GetThisSocket(ctx);
CJSSocketWorker* socketWorker = GetThisSocket(ctx);
duk_idx_t nargs = duk_get_top(ctx); duk_idx_t nargs = duk_get_top(ctx);
unsigned short port = (unsigned short)duk_get_uint(ctx, 0); unsigned short port = (unsigned short)duk_get_uint(ctx, 0);
const char* host = duk_get_string(ctx, 1); const char * host = duk_get_string(ctx, 1);
if (nargs == 3) if (nargs == 3)
{ {
@ -131,14 +124,14 @@ duk_ret_t ScriptAPI::js_Socket_connect(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Socket_write(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket_write(duk_context * ctx)
{ {
CJSSocketWorker* socketWorker = GetThisSocket(ctx); CJSSocketWorker * socketWorker = GetThisSocket(ctx);
const char* data; const char * data;
duk_size_t size; duk_size_t size;
duk_int_t callbackId = -1; duk_int_t callbackId = -1;
duk_idx_t nargs = duk_get_top(ctx); duk_idx_t nargs = duk_get_top(ctx);
RequireBufferDataOrString(ctx, 0, &data, &size); RequireBufferDataOrString(ctx, 0, &data, &size);
@ -147,15 +140,15 @@ duk_ret_t ScriptAPI::js_Socket_write(duk_context* ctx)
callbackId = RegisterWriteCallback(ctx, 1); callbackId = RegisterWriteCallback(ctx, 1);
} }
socketWorker->Write((char*)data, size, callbackId, false); socketWorker->Write((char *)data, size, callbackId, false);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Socket_end(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket_end(duk_context * ctx)
{ {
CJSSocketWorker* socketWorker = GetThisSocket(ctx); CJSSocketWorker * socketWorker = GetThisSocket(ctx);
const char* data; const char * data;
duk_size_t size; duk_size_t size;
duk_int_t callbackId = -1; duk_int_t callbackId = -1;
@ -167,11 +160,11 @@ duk_ret_t ScriptAPI::js_Socket_end(duk_context* ctx)
RegisterWriteEndCallback(ctx, 1); RegisterWriteEndCallback(ctx, 1);
} }
socketWorker->Write((char*)data, size, callbackId, true); socketWorker->Write((char *)data, size, callbackId, true);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Socket__invokeWriteCallback(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket__invokeWriteCallback(duk_context * ctx)
{ {
duk_int_t callbackId = duk_get_int(ctx, 0); duk_int_t callbackId = duk_get_int(ctx, 0);
@ -191,7 +184,7 @@ duk_ret_t ScriptAPI::js_Socket__invokeWriteCallback(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Socket__invokeWriteEndCallbacks(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket__invokeWriteEndCallbacks(duk_context * ctx)
{ {
duk_push_this(ctx); duk_push_this(ctx);
duk_get_prop_string(ctx, -1, HS_socketWriteEndCallbacks); duk_get_prop_string(ctx, -1, HS_socketWriteEndCallbacks);
@ -212,59 +205,59 @@ duk_ret_t ScriptAPI::js_Socket__invokeWriteEndCallbacks(duk_context* ctx)
duk_pop(ctx); duk_pop(ctx);
// reset array // reset array
duk_push_array(ctx); duk_push_array(ctx);
duk_put_prop_string(ctx, -2, HS_socketWriteEndCallbacks); duk_put_prop_string(ctx, -2, HS_socketWriteEndCallbacks);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Socket_close(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket_close(duk_context * ctx)
{ {
CJSSocketWorker* socketWorker = GetThisSocket(ctx); CJSSocketWorker * socketWorker = GetThisSocket(ctx);
socketWorker->StopWorkerProc(); socketWorker->StopWorkerProc();
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_Socket__get_localAddress(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket__get_localAddress(duk_context * ctx)
{ {
CJSSocketWorker* socketWorker = GetThisSocket(ctx); CJSSocketWorker * socketWorker = GetThisSocket(ctx);
duk_push_string(ctx, socketWorker->GetLocalAddress().c_str()); duk_push_string(ctx, socketWorker->GetLocalAddress().c_str());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_Socket__get_localPort(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket__get_localPort(duk_context * ctx)
{ {
CJSSocketWorker* socketWorker = GetThisSocket(ctx); CJSSocketWorker * socketWorker = GetThisSocket(ctx);
duk_push_uint(ctx, socketWorker->GetLocalPort()); duk_push_uint(ctx, socketWorker->GetLocalPort());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_Socket__get_remoteAddress(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket__get_remoteAddress(duk_context * ctx)
{ {
CJSSocketWorker* socketWorker = GetThisSocket(ctx); CJSSocketWorker * socketWorker = GetThisSocket(ctx);
duk_push_string(ctx, socketWorker->GetRemoteAddress().c_str()); duk_push_string(ctx, socketWorker->GetRemoteAddress().c_str());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_Socket__get_remotePort(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket__get_remotePort(duk_context * ctx)
{ {
CJSSocketWorker* socketWorker = GetThisSocket(ctx); CJSSocketWorker * socketWorker = GetThisSocket(ctx);
duk_push_uint(ctx, socketWorker->GetRemotePort()); duk_push_uint(ctx, socketWorker->GetRemotePort());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_Socket__get_addressFamily(duk_context* ctx) duk_ret_t ScriptAPI::js_Socket__get_addressFamily(duk_context * ctx)
{ {
CJSSocketWorker* socketWorker = GetThisSocket(ctx); CJSSocketWorker * socketWorker = GetThisSocket(ctx);
duk_push_string(ctx, socketWorker->GetFamily()); duk_push_string(ctx, socketWorker->GetFamily());
return 1; return 1;
} }
CJSSocketWorker* GetThisSocket(duk_context* ctx) CJSSocketWorker * GetThisSocket(duk_context * ctx)
{ {
duk_push_this(ctx); duk_push_this(ctx);
duk_get_prop_string(ctx, -1, HS_socketWorkerPtr); duk_get_prop_string(ctx, -1, HS_socketWorkerPtr);
CJSSocketWorker* socketWorker = (CJSSocketWorker*)duk_get_pointer(ctx, -1); CJSSocketWorker * socketWorker = (CJSSocketWorker *)duk_get_pointer(ctx, -1);
duk_pop_n(ctx, 2); duk_pop_n(ctx, 2);
if (socketWorker == nullptr) if (socketWorker == nullptr)
@ -276,11 +269,11 @@ CJSSocketWorker* GetThisSocket(duk_context* ctx)
return socketWorker; return socketWorker;
} }
duk_ret_t RequireBufferDataOrString(duk_context* ctx, duk_idx_t idx, const char** data, duk_size_t* size) duk_ret_t RequireBufferDataOrString(duk_context * ctx, duk_idx_t idx, const char ** data, duk_size_t * size)
{ {
if (duk_is_buffer_data(ctx, idx)) if (duk_is_buffer_data(ctx, idx))
{ {
*data = (const char*)duk_get_buffer_data(ctx, idx, size); *data = (const char *)duk_get_buffer_data(ctx, idx, size);
return 0; return 0;
} }
else if (duk_is_string(ctx, idx)) else if (duk_is_string(ctx, idx))
@ -293,7 +286,7 @@ duk_ret_t RequireBufferDataOrString(duk_context* ctx, duk_idx_t idx, const char*
return duk_throw(ctx); return duk_throw(ctx);
} }
duk_int_t RegisterWriteCallback(duk_context* ctx, duk_idx_t idx) duk_int_t RegisterWriteCallback(duk_context * ctx, duk_idx_t idx)
{ {
idx = duk_normalize_index(ctx, idx); idx = duk_normalize_index(ctx, idx);
@ -313,7 +306,7 @@ duk_int_t RegisterWriteCallback(duk_context* ctx, duk_idx_t idx)
return callbackId; return callbackId;
} }
void RegisterWriteEndCallback(duk_context* ctx, duk_idx_t idx) void RegisterWriteEndCallback(duk_context * ctx, duk_idx_t idx)
{ {
idx = duk_normalize_index(ctx, idx); idx = duk_normalize_index(ctx, idx);

View File

@ -1,19 +1,20 @@
#include <stdafx.h> #include "stdafx.h"
#include <windows.h>
#include "ScriptAPI.h"
void ScriptAPI::Define_alert(duk_context* ctx) #include "ScriptAPI.h"
#include <windows.h>
void ScriptAPI::Define_alert(duk_context * ctx)
{ {
DefineGlobalFunction(ctx, "alert", js_alert); DefineGlobalFunction(ctx, "alert", js_alert);
} }
duk_ret_t ScriptAPI::js_alert(duk_context* ctx) duk_ret_t ScriptAPI::js_alert(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Any, Arg_OptAny }); CheckArgs(ctx, {Arg_Any, Arg_OptAny});
duk_idx_t nargs = duk_get_top(ctx); duk_idx_t nargs = duk_get_top(ctx);
const char* message = duk_safe_to_string(ctx, 0); const char * message = duk_safe_to_string(ctx, 0);
const char* caption = (nargs == 2) ? duk_safe_to_string(ctx, 1) : ""; const char * caption = (nargs == 2) ? duk_safe_to_string(ctx, 1) : "";
HWND mainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle(); HWND mainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle();
MessageBoxA(mainWindow, message, caption, MB_OK); MessageBoxA(mainWindow, message, caption, MB_OK);

View File

@ -1,30 +1,31 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptAPI.h"
#include "../Assembler.h" #include "../Assembler.h"
#include "ScriptAPI.h"
#include <Project64-core/N64System/Mips/R4300iInstruction.h> #include <Project64-core/N64System/Mips/R4300iInstruction.h>
void ScriptAPI::Define_asm(duk_context *ctx) void ScriptAPI::Define_asm(duk_context * ctx)
{ {
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "gprname", DukCFunction(js_asm_gprname) }, {"gprname", DukCFunction(js_asm_gprname)},
{ "encode", DukCFunction(js_asm_encode) }, {"encode", DukCFunction(js_asm_encode)},
{ "decode", DukCFunction(js_asm_decode) }, {"decode", DukCFunction(js_asm_decode)},
{ nullptr } { nullptr }
}; };
DefineGlobalInterface(ctx, "asm", props); DefineGlobalInterface(ctx, "asm", props);
} }
duk_ret_t ScriptAPI::js_asm_gprname(duk_context* ctx) duk_ret_t ScriptAPI::js_asm_gprname(duk_context * ctx)
{ {
const char* names[32] = { const char * names[32] = {
"r0", "at", "v0", "v1", "a0", "a1", "a2", "a3", "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
"t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra" "t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra"
}; };
CheckArgs(ctx, { Arg_Number }); CheckArgs(ctx, {Arg_Number});
duk_uint_t idx = duk_get_uint(ctx, 0); duk_uint_t idx = duk_get_uint(ctx, 0);
@ -40,11 +41,11 @@ duk_ret_t ScriptAPI::js_asm_gprname(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_asm_encode(duk_context* ctx) duk_ret_t ScriptAPI::js_asm_encode(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_String, Arg_OptNumber }); CheckArgs(ctx, {Arg_String, Arg_OptNumber});
const char *code = duk_get_string(ctx, 0); const char * code = duk_get_string(ctx, 0);
uint32_t address = duk_get_uint_default(ctx, 1, 0); uint32_t address = duk_get_uint_default(ctx, 1, 0);
// TODO: CAssembler's state is not thread safe. // TODO: CAssembler's state is not thread safe.
@ -61,9 +62,9 @@ duk_ret_t ScriptAPI::js_asm_encode(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_asm_decode(duk_context* ctx) duk_ret_t ScriptAPI::js_asm_decode(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number, Arg_OptNumber }); CheckArgs(ctx, {Arg_Number, Arg_OptNumber});
uint32_t opcode = duk_get_uint(ctx, 0); uint32_t opcode = duk_get_uint(ctx, 0);
uint32_t address = duk_get_uint_default(ctx, 1, 0); uint32_t address = duk_get_uint_default(ctx, 1, 0);

View File

@ -1,24 +1,25 @@
#include <stdafx.h> #include "stdafx.h"
#include <windows.h>
#include "ScriptAPI.h" #include "ScriptAPI.h"
#include <windows.h>
static void ConcatArgs(duk_context* ctx, stdstr& out); static void ConcatArgs(duk_context * ctx, stdstr & out);
void ScriptAPI::Define_console(duk_context* ctx) void ScriptAPI::Define_console(duk_context * ctx)
{ {
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "print", DukCFunction(js_console_print) }, {"print", DukCFunction(js_console_print)},
{ "log", DukCFunction(js_console_log) }, {"log", DukCFunction(js_console_log)},
{ "error", DukCFunction(js_console_error) }, {"error", DukCFunction(js_console_error)},
{ "clear", DukCFunction(js_console_clear) }, {"clear", DukCFunction(js_console_clear)},
{ "listen", DukCFunction(js_console_listen) }, {"listen", DukCFunction(js_console_listen)},
{ nullptr } { nullptr }
}; };
DefineGlobalInterface(ctx, "console", props); DefineGlobalInterface(ctx, "console", props);
} }
duk_ret_t ScriptAPI::js_console_print(duk_context* ctx) duk_ret_t ScriptAPI::js_console_print(duk_context * ctx)
{ {
stdstr out; stdstr out;
ConcatArgs(ctx, out); ConcatArgs(ctx, out);
@ -26,7 +27,7 @@ duk_ret_t ScriptAPI::js_console_print(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_console_log(duk_context* ctx) duk_ret_t ScriptAPI::js_console_log(duk_context * ctx)
{ {
stdstr out; stdstr out;
ConcatArgs(ctx, out); ConcatArgs(ctx, out);
@ -34,14 +35,14 @@ duk_ret_t ScriptAPI::js_console_log(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_console_error(duk_context* ctx) duk_ret_t ScriptAPI::js_console_error(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_OptAny }); CheckArgs(ctx, {Arg_OptAny});
if (duk_is_error(ctx, 0)) if (duk_is_error(ctx, 0))
{ {
duk_get_prop_string(ctx, 0, "stack"); duk_get_prop_string(ctx, 0, "stack");
const char* message = duk_get_string(ctx, -1); const char * message = duk_get_string(ctx, -1);
GetInstance(ctx)->System()->ConsoleLog("%s", message); GetInstance(ctx)->System()->ConsoleLog("%s", message);
return 0; return 0;
} }
@ -50,16 +51,16 @@ duk_ret_t ScriptAPI::js_console_error(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_console_clear(duk_context* ctx) duk_ret_t ScriptAPI::js_console_clear(duk_context * ctx)
{ {
CheckArgs(ctx, {}); CheckArgs(ctx, {});
GetInstance(ctx)->System()->ConsoleClear(); GetInstance(ctx)->System()->ConsoleClear();
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_console_listen(duk_context* ctx) duk_ret_t ScriptAPI::js_console_listen(duk_context * ctx)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
duk_push_global_object(ctx); duk_push_global_object(ctx);
duk_bool_t haveListener = duk_has_prop_string(ctx, -1, HS_gInputListener); duk_bool_t haveListener = duk_has_prop_string(ctx, -1, HS_gInputListener);
@ -87,11 +88,11 @@ duk_ret_t ScriptAPI::js_console_listen(duk_context* ctx)
return ThrowInvalidArgsError(ctx); return ThrowInvalidArgsError(ctx);
} }
void ConcatArgs(duk_context* ctx, stdstr& out) void ConcatArgs(duk_context * ctx, stdstr & out)
{ {
out = ""; out = "";
duk_idx_t nargs = duk_get_top(ctx); duk_idx_t nargs = duk_get_top(ctx);
// note: global JSON.stringify must be intact // note: global JSON.stringify must be intact
duk_get_global_string(ctx, "JSON"); duk_get_global_string(ctx, "JSON");

View File

@ -1,24 +1,25 @@
#include "stdafx.h" #include "stdafx.h"
#include "ScriptAPI.h" #include "ScriptAPI.h"
#include <Project64-core/N64System/Mips/Register.h> #include <Project64-core/N64System/Mips/Register.h>
#pragma warning(disable: 4702) // disable unreachable code warning #pragma warning(disable : 4702) // disable unreachable code warning
static duk_ret_t GPRGetImpl(duk_context* ctx, bool bUpper); static duk_ret_t GPRGetImpl(duk_context * ctx, bool bUpper);
static duk_ret_t GPRSetImpl(duk_context* ctx, bool bUpper); static duk_ret_t GPRSetImpl(duk_context * ctx, bool bUpper);
static duk_ret_t FPRGetImpl(duk_context* ctx, bool bDouble); static duk_ret_t FPRGetImpl(duk_context * ctx, bool bDouble);
static duk_ret_t FPRSetImpl(duk_context* ctx, bool bDouble); static duk_ret_t FPRSetImpl(duk_context * ctx, bool bDouble);
static int FPRIndex(const char* regName); static int FPRIndex(const char * regName);
static int GPRIndex(const char* regName); static int GPRIndex(const char * regName);
static uint32_t* COP0RegPtr(const char* regName); static uint32_t * COP0RegPtr(const char * regName);
static uint32_t* CPURegPtr(const char *regName); static uint32_t * CPURegPtr(const char * regName);
static duk_ret_t ThrowRegInvalidError(duk_context* ctx); static duk_ret_t ThrowRegInvalidError(duk_context * ctx);
static duk_ret_t ThrowRegContextUnavailableError(duk_context* ctx); static duk_ret_t ThrowRegContextUnavailableError(duk_context * ctx);
static duk_ret_t ThrowRegAssignmentTypeError(duk_context* ctx); static duk_ret_t ThrowRegAssignmentTypeError(duk_context * ctx);
void ScriptAPI::Define_cpu(duk_context* ctx) void ScriptAPI::Define_cpu(duk_context * ctx)
{ {
// todo cleanup // todo cleanup
@ -28,15 +29,16 @@ void ScriptAPI::Define_cpu(duk_context* ctx)
{ nullptr, nullptr, 0 } \ { nullptr, nullptr, 0 } \
} }
const struct { const struct
const char *key; {
const char * key;
const duk_function_list_entry functions[3]; const duk_function_list_entry functions[3];
} proxies[] = { } proxies[] = {
{ "gpr", REG_PROXY_FUNCTIONS(js_cpu_gpr_get, js_cpu_gpr_set) }, {"gpr", REG_PROXY_FUNCTIONS(js_cpu_gpr_get, js_cpu_gpr_set)},
{ "ugpr", REG_PROXY_FUNCTIONS(js_cpu_ugpr_get, js_cpu_ugpr_set) }, {"ugpr", REG_PROXY_FUNCTIONS(js_cpu_ugpr_get, js_cpu_ugpr_set)},
{ "fpr", REG_PROXY_FUNCTIONS(js_cpu_fpr_get, js_cpu_fpr_set) }, {"fpr", REG_PROXY_FUNCTIONS(js_cpu_fpr_get, js_cpu_fpr_set)},
{ "dfpr", REG_PROXY_FUNCTIONS(js_cpu_dfpr_get, js_cpu_dfpr_set) }, {"dfpr", REG_PROXY_FUNCTIONS(js_cpu_dfpr_get, js_cpu_dfpr_set)},
{ "cop0", REG_PROXY_FUNCTIONS(js_cpu_cop0_get, js_cpu_cop0_set) }, {"cop0", REG_PROXY_FUNCTIONS(js_cpu_cop0_get, js_cpu_cop0_set)},
{ nullptr, nullptr } { nullptr, nullptr }
}; };
@ -65,15 +67,15 @@ void ScriptAPI::Define_cpu(duk_context* ctx)
duk_pop(ctx); duk_pop(ctx);
} }
duk_ret_t ScriptAPI::js_cpu_get(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_get(duk_context * ctx)
{ {
if (g_Reg == nullptr) if (g_Reg == nullptr)
{ {
return ThrowRegContextUnavailableError(ctx); return ThrowRegContextUnavailableError(ctx);
} }
const char* key = duk_get_string(ctx, 1); const char * key = duk_get_string(ctx, 1);
uint32_t* pReg = CPURegPtr(key); uint32_t * pReg = CPURegPtr(key);
if (pReg == nullptr) if (pReg == nullptr)
{ {
@ -85,14 +87,14 @@ duk_ret_t ScriptAPI::js_cpu_get(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_cpu_set(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_set(duk_context * ctx)
{ {
if (g_Reg == nullptr) if (g_Reg == nullptr)
{ {
return ThrowRegContextUnavailableError(ctx); return ThrowRegContextUnavailableError(ctx);
} }
uint32_t* pReg = CPURegPtr(duk_get_string(ctx, 1)); uint32_t * pReg = CPURegPtr(duk_get_string(ctx, 1));
if (!duk_is_number(ctx, 2) || pReg == nullptr) if (!duk_is_number(ctx, 2) || pReg == nullptr)
{ {
@ -104,47 +106,47 @@ duk_ret_t ScriptAPI::js_cpu_set(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_cpu_gpr_get(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_gpr_get(duk_context * ctx)
{ {
return GPRGetImpl(ctx, false); return GPRGetImpl(ctx, false);
} }
duk_ret_t ScriptAPI::js_cpu_gpr_set(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_gpr_set(duk_context * ctx)
{ {
return GPRSetImpl(ctx, false); return GPRSetImpl(ctx, false);
} }
duk_ret_t ScriptAPI::js_cpu_ugpr_get(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_ugpr_get(duk_context * ctx)
{ {
return GPRGetImpl(ctx, true); return GPRGetImpl(ctx, true);
} }
duk_ret_t ScriptAPI::js_cpu_ugpr_set(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_ugpr_set(duk_context * ctx)
{ {
return GPRSetImpl(ctx, true); return GPRSetImpl(ctx, true);
} }
duk_ret_t ScriptAPI::js_cpu_fpr_get(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_fpr_get(duk_context * ctx)
{ {
return FPRGetImpl(ctx, false); return FPRGetImpl(ctx, false);
} }
duk_ret_t ScriptAPI::js_cpu_fpr_set(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_fpr_set(duk_context * ctx)
{ {
return FPRSetImpl(ctx, false); return FPRSetImpl(ctx, false);
} }
duk_ret_t ScriptAPI::js_cpu_dfpr_get(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_dfpr_get(duk_context * ctx)
{ {
return FPRGetImpl(ctx, true); return FPRGetImpl(ctx, true);
} }
duk_ret_t ScriptAPI::js_cpu_dfpr_set(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_dfpr_set(duk_context * ctx)
{ {
return FPRSetImpl(ctx, true); return FPRSetImpl(ctx, true);
} }
duk_ret_t ScriptAPI::js_cpu_cop0_get(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_cop0_get(duk_context * ctx)
{ {
if (g_Reg == nullptr) if (g_Reg == nullptr)
{ {
@ -156,15 +158,15 @@ duk_ret_t ScriptAPI::js_cpu_cop0_get(duk_context* ctx)
return ThrowRegInvalidError(ctx); return ThrowRegInvalidError(ctx);
} }
const char* name = duk_get_string(ctx, 1); const char * name = duk_get_string(ctx, 1);
if (strcmp(name, "cause") == 0) if (strcmp(name, "cause") == 0)
{ {
duk_push_uint(ctx, (uint32_t)(g_Reg->FAKE_CAUSE_REGISTER | g_Reg->CAUSE_REGISTER)); duk_push_uint(ctx, (uint32_t)(g_Reg->FAKE_CAUSE_REGISTER | g_Reg->CAUSE_REGISTER));
return 1; return 1;
} }
uint32_t* reg = COP0RegPtr(name); uint32_t * reg = COP0RegPtr(name);
if (reg == nullptr) if (reg == nullptr)
{ {
@ -175,7 +177,7 @@ duk_ret_t ScriptAPI::js_cpu_cop0_get(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_cpu_cop0_set(duk_context* ctx) duk_ret_t ScriptAPI::js_cpu_cop0_set(duk_context * ctx)
{ {
if (g_Reg == nullptr) if (g_Reg == nullptr)
{ {
@ -187,8 +189,8 @@ duk_ret_t ScriptAPI::js_cpu_cop0_set(duk_context* ctx)
return ThrowRegInvalidError(ctx); return ThrowRegInvalidError(ctx);
} }
const char* name = duk_get_string(ctx, 1); const char * name = duk_get_string(ctx, 1);
if (!duk_is_number(ctx, 2)) if (!duk_is_number(ctx, 2))
{ {
return ThrowRegAssignmentTypeError(ctx); return ThrowRegAssignmentTypeError(ctx);
@ -205,7 +207,7 @@ duk_ret_t ScriptAPI::js_cpu_cop0_set(duk_context* ctx)
return 1; return 1;
} }
uint32_t* reg = COP0RegPtr(name); uint32_t * reg = COP0RegPtr(name);
if (reg == nullptr) if (reg == nullptr)
{ {
@ -217,7 +219,7 @@ duk_ret_t ScriptAPI::js_cpu_cop0_set(duk_context* ctx)
return 1; return 1;
} }
static duk_ret_t GPRGetImpl(duk_context* ctx, bool bUpper) static duk_ret_t GPRGetImpl(duk_context * ctx, bool bUpper)
{ {
int regIndex = -1; int regIndex = -1;
@ -239,12 +241,12 @@ static duk_ret_t GPRGetImpl(duk_context* ctx, bool bUpper)
{ {
return ThrowRegInvalidError(ctx); return ThrowRegInvalidError(ctx);
} }
duk_push_uint(ctx, g_Reg->m_GPR[regIndex].UW[bUpper ? 1: 0]); duk_push_uint(ctx, g_Reg->m_GPR[regIndex].UW[bUpper ? 1 : 0]);
return 1; return 1;
} }
static duk_ret_t GPRSetImpl(duk_context* ctx, bool bUpper) static duk_ret_t GPRSetImpl(duk_context * ctx, bool bUpper)
{ {
int regIndex = -1; int regIndex = -1;
@ -285,7 +287,7 @@ static duk_ret_t GPRSetImpl(duk_context* ctx, bool bUpper)
return 1; return 1;
} }
static duk_ret_t FPRGetImpl(duk_context* ctx, bool bDouble) static duk_ret_t FPRGetImpl(duk_context * ctx, bool bDouble)
{ {
int regIndex = -1; int regIndex = -1;
@ -320,7 +322,7 @@ static duk_ret_t FPRGetImpl(duk_context* ctx, bool bDouble)
return 1; return 1;
} }
static duk_ret_t FPRSetImpl(duk_context* ctx, bool bDouble) static duk_ret_t FPRSetImpl(duk_context * ctx, bool bDouble)
{ {
int regIndex = -1; int regIndex = -1;
@ -363,9 +365,9 @@ static duk_ret_t FPRSetImpl(duk_context* ctx, bool bDouble)
return 1; return 1;
} }
static int GPRIndex(const char* regName) static int GPRIndex(const char * regName)
{ {
const char* names[] = { const char * names[] = {
"r0", "at", "v0", "v1", "a0", "a1", "a2", "a3", "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3",
"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
@ -383,10 +385,10 @@ static int GPRIndex(const char* regName)
return -1; return -1;
} }
static int FPRIndex(const char* regName) static int FPRIndex(const char * regName)
{ {
const char* names[32] = { const char * names[32] = {
"f0", "f1", "f2", "f3", "f4","f5", "f6", "f7", "f8", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8",
"f9", "f10", "f11", "f12", "f13", "f14", "f15", "f16", "f9", "f10", "f11", "f12", "f13", "f14", "f15", "f16",
"f17", "f18", "f19", "f20", "f21", "f22", "f23", "f24", "f17", "f18", "f19", "f20", "f21", "f22", "f23", "f24",
"f25", "f26", "f27", "f28", "f29", "f30", "f31" "f25", "f26", "f27", "f28", "f29", "f30", "f31"
@ -403,35 +405,36 @@ static int FPRIndex(const char* regName)
return -1; return -1;
} }
static uint32_t* COP0RegPtr(const char *regName) static uint32_t * COP0RegPtr(const char * regName)
{ {
if (g_Reg == nullptr) if (g_Reg == nullptr)
{ {
return nullptr; return nullptr;
} }
struct { struct
const char* name; {
uint32_t *ptr; const char * name;
uint32_t * ptr;
} names[] = { } names[] = {
{ "index", (uint32_t*)&g_Reg->INDEX_REGISTER }, {"index", (uint32_t *)&g_Reg->INDEX_REGISTER},
{ "random", (uint32_t*)&g_Reg->RANDOM_REGISTER }, {"random", (uint32_t *)&g_Reg->RANDOM_REGISTER},
{ "entrylo0", (uint32_t*)&g_Reg->ENTRYLO0_REGISTER }, {"entrylo0", (uint32_t *)&g_Reg->ENTRYLO0_REGISTER},
{ "entrylo1", (uint32_t*)&g_Reg->ENTRYLO1_REGISTER }, {"entrylo1", (uint32_t *)&g_Reg->ENTRYLO1_REGISTER},
{ "context", (uint32_t*)&g_Reg->CONTEXT_REGISTER }, {"context", (uint32_t *)&g_Reg->CONTEXT_REGISTER},
{ "pagemask", (uint32_t*)&g_Reg->PAGE_MASK_REGISTER }, {"pagemask", (uint32_t *)&g_Reg->PAGE_MASK_REGISTER},
{ "wired", (uint32_t*)&g_Reg->WIRED_REGISTER }, {"wired", (uint32_t *)&g_Reg->WIRED_REGISTER},
{ "badvaddr", (uint32_t*)&g_Reg->BAD_VADDR_REGISTER }, {"badvaddr", (uint32_t *)&g_Reg->BAD_VADDR_REGISTER},
{ "count", (uint32_t*)&g_Reg->COUNT_REGISTER }, {"count", (uint32_t *)&g_Reg->COUNT_REGISTER},
{ "entryhi", (uint32_t*)&g_Reg->ENTRYHI_REGISTER }, {"entryhi", (uint32_t *)&g_Reg->ENTRYHI_REGISTER},
{ "compare", (uint32_t*)&g_Reg->COMPARE_REGISTER }, {"compare", (uint32_t *)&g_Reg->COMPARE_REGISTER},
{ "status", (uint32_t*)&g_Reg->STATUS_REGISTER }, {"status", (uint32_t *)&g_Reg->STATUS_REGISTER},
//{ "cause", (uint32_t*)&g_Reg->CAUSE_REGISTER }, //{ "cause", (uint32_t*)&g_Reg->CAUSE_REGISTER },
{ "epc", (uint32_t*)&g_Reg->EPC_REGISTER }, {"epc", (uint32_t *)&g_Reg->EPC_REGISTER},
{ "config", (uint32_t*)&g_Reg->CONFIG_REGISTER }, {"config", (uint32_t *)&g_Reg->CONFIG_REGISTER},
{ "taglo", (uint32_t*)&g_Reg->TAGLO_REGISTER }, {"taglo", (uint32_t *)&g_Reg->TAGLO_REGISTER},
{ "taghi",(uint32_t*)&g_Reg->TAGHI_REGISTER }, {"taghi", (uint32_t *)&g_Reg->TAGHI_REGISTER},
{ "errorepc", (uint32_t*)&g_Reg->ERROREPC_REGISTER }, {"errorepc", (uint32_t *)&g_Reg->ERROREPC_REGISTER},
{ nullptr, nullptr } { nullptr, nullptr }
}; };
@ -446,7 +449,7 @@ static uint32_t* COP0RegPtr(const char *regName)
return nullptr; return nullptr;
} }
static uint32_t* CPURegPtr(const char* key) static uint32_t * CPURegPtr(const char * key)
{ {
if (g_Reg == nullptr) if (g_Reg == nullptr)
{ {
@ -481,19 +484,19 @@ static uint32_t* CPURegPtr(const char* key)
return nullptr; return nullptr;
} }
static duk_ret_t ThrowRegInvalidError(duk_context* ctx) static duk_ret_t ThrowRegInvalidError(duk_context * ctx)
{ {
duk_push_error_object(ctx, DUK_ERR_REFERENCE_ERROR, "invalid register name or number"); duk_push_error_object(ctx, DUK_ERR_REFERENCE_ERROR, "invalid register name or number");
return duk_throw(ctx); return duk_throw(ctx);
} }
static duk_ret_t ThrowRegContextUnavailableError(duk_context* ctx) static duk_ret_t ThrowRegContextUnavailableError(duk_context * ctx)
{ {
duk_push_error_object(ctx, DUK_ERR_ERROR, "CPU register context is unavailable"); duk_push_error_object(ctx, DUK_ERR_ERROR, "CPU register context is unavailable");
return duk_throw(ctx); return duk_throw(ctx);
} }
static duk_ret_t ThrowRegAssignmentTypeError(duk_context* ctx) static duk_ret_t ThrowRegAssignmentTypeError(duk_context * ctx)
{ {
duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR, "invalid register value assignment"); duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR, "invalid register value assignment");
return duk_throw(ctx); return duk_throw(ctx);

View File

@ -1,16 +1,17 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptAPI.h" #include "ScriptAPI.h"
#include <Project64-core/Settings/DebugSettings.h> #include <Project64-core/Settings/DebugSettings.h>
void ScriptAPI::Define_debug(duk_context* ctx) void ScriptAPI::Define_debug(duk_context * ctx)
{ {
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "breakhere", DukCFunction(js_debug_breakhere) }, {"breakhere", DukCFunction(js_debug_breakhere)},
{ "step", DukCFunction(js_debug_step) }, {"step", DukCFunction(js_debug_step)},
{ "skip", DukCFunction(js_debug_skip) }, {"skip", DukCFunction(js_debug_skip)},
{ "resume", DukCFunction(js_debug_resume) }, {"resume", DukCFunction(js_debug_resume)},
{ "showmemory", DukCFunction(js_debug_showmemory) }, {"showmemory", DukCFunction(js_debug_showmemory)},
{ "showcommands", DukCFunction(js_debug_showcommands) }, {"showcommands", DukCFunction(js_debug_showcommands)},
{ "paused", DukGetter(js_debug__get_paused) }, { "paused", DukGetter(js_debug__get_paused) },
{ nullptr } { nullptr }
}; };
@ -18,11 +19,11 @@ void ScriptAPI::Define_debug(duk_context* ctx)
DefineGlobalInterface(ctx, "debug", props); DefineGlobalInterface(ctx, "debug", props);
} }
duk_ret_t ScriptAPI::js_debug_breakhere(duk_context* ctx) duk_ret_t ScriptAPI::js_debug_breakhere(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_OptBoolean }); CheckArgs(ctx, {Arg_OptBoolean});
if (duk_get_boolean_default(ctx, 0, (duk_bool_t)false) == 1) if (duk_get_boolean_default(ctx, 0, (duk_bool_t) false) == 1)
{ {
g_Settings->SaveBool(Debugger_SilentBreak, true); g_Settings->SaveBool(Debugger_SilentBreak, true);
} }
@ -30,11 +31,11 @@ duk_ret_t ScriptAPI::js_debug_breakhere(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_debug_step(duk_context* ctx) duk_ret_t ScriptAPI::js_debug_step(duk_context * ctx)
{ {
CheckArgs(ctx, {}); CheckArgs(ctx, {});
if (g_Settings->LoadBool(Debugger_SteppingOps) && if (g_Settings->LoadBool(Debugger_SteppingOps) &&
CDebugSettings::WaitingForStep()) CDebugSettings::WaitingForStep())
{ {
g_Settings->SaveBool(Debugger_SilentBreak, true); g_Settings->SaveBool(Debugger_SilentBreak, true);
@ -43,7 +44,7 @@ duk_ret_t ScriptAPI::js_debug_step(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_debug_skip(duk_context* ctx) duk_ret_t ScriptAPI::js_debug_skip(duk_context * ctx)
{ {
CheckArgs(ctx, {}); CheckArgs(ctx, {});
@ -57,9 +58,9 @@ duk_ret_t ScriptAPI::js_debug_skip(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_debug_showmemory(duk_context* ctx) duk_ret_t ScriptAPI::js_debug_showmemory(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number, Arg_OptBoolean }); CheckArgs(ctx, {Arg_Number, Arg_OptBoolean});
uint32_t address = duk_get_uint(ctx, 0); uint32_t address = duk_get_uint(ctx, 0);
bool bPhysical = duk_get_boolean_default(ctx, 1, 0) ? true : false; bool bPhysical = duk_get_boolean_default(ctx, 1, 0) ? true : false;
@ -68,15 +69,15 @@ duk_ret_t ScriptAPI::js_debug_showmemory(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_debug_showcommands(duk_context* ctx) duk_ret_t ScriptAPI::js_debug_showcommands(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number }); CheckArgs(ctx, {Arg_Number});
uint32_t address = duk_get_uint(ctx, 0); uint32_t address = duk_get_uint(ctx, 0);
GetInstance(ctx)->Debugger()->Debug_ShowCommandsLocation(address, true); GetInstance(ctx)->Debugger()->Debug_ShowCommandsLocation(address, true);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_debug_resume(duk_context* ctx) duk_ret_t ScriptAPI::js_debug_resume(duk_context * ctx)
{ {
CheckArgs(ctx, {}); CheckArgs(ctx, {});
@ -89,7 +90,7 @@ duk_ret_t ScriptAPI::js_debug_resume(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_debug__get_paused(duk_context* ctx) duk_ret_t ScriptAPI::js_debug__get_paused(duk_context * ctx)
{ {
duk_push_boolean(ctx, CDebugSettings::WaitingForStep() && g_Settings->LoadBool(Debugger_SteppingOps)); duk_push_boolean(ctx, CDebugSettings::WaitingForStep() && g_Settings->LoadBool(Debugger_SteppingOps));
return 1; return 1;

View File

@ -1,47 +1,48 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptAPI.h"
#include "../OpInfo.h"
#pragma warning(disable: 4702) // disable unreachable code warning #include "../OpInfo.h"
#include "ScriptAPI.h"
#pragma warning(disable : 4702) // disable unreachable code warning
using namespace ScriptAPI; using namespace ScriptAPI;
static bool CbCond_PcBetween(JSAppCallback* cb, void* env); static bool CbCond_PcBetween(JSAppCallback * cb, void * env);
static bool CbCond_ReadAddrBetween(JSAppCallback* cb, void* env); static bool CbCond_ReadAddrBetween(JSAppCallback * cb, void * env);
static bool CbCond_WriteAddrBetween(JSAppCallback* cb, void* env); static bool CbCond_WriteAddrBetween(JSAppCallback * cb, void * env);
static bool CbCond_PcBetween_OpcodeEquals(JSAppCallback* cb, void* env); static bool CbCond_PcBetween_OpcodeEquals(JSAppCallback * cb, void * env);
static bool CbCond_PcBetween_GprValueEquals(JSAppCallback* cb, void* env); static bool CbCond_PcBetween_GprValueEquals(JSAppCallback * cb, void * env);
static duk_idx_t CbArgs_GenericEventObject(duk_context* ctx, void* env); static duk_idx_t CbArgs_GenericEventObject(duk_context * ctx, void * env);
static duk_idx_t CbArgs_EmuStateChangeEventObject(duk_context* ctx, void* env); static duk_idx_t CbArgs_EmuStateChangeEventObject(duk_context * ctx, void * env);
static duk_idx_t CbArgs_ExecEventObject(duk_context* ctx, void* env); static duk_idx_t CbArgs_ExecEventObject(duk_context * ctx, void * env);
static duk_idx_t CbArgs_ReadEventObject(duk_context* ctx, void* env); static duk_idx_t CbArgs_ReadEventObject(duk_context * ctx, void * env);
static duk_idx_t CbArgs_WriteEventObject(duk_context* ctx, void* env); static duk_idx_t CbArgs_WriteEventObject(duk_context * ctx, void * env);
static duk_idx_t CbArgs_OpcodeEventObject(duk_context* ctx, void* env); static duk_idx_t CbArgs_OpcodeEventObject(duk_context * ctx, void * env);
static duk_idx_t CbArgs_RegValueEventObject(duk_context* ctx, void* env); static duk_idx_t CbArgs_RegValueEventObject(duk_context * ctx, void * env);
static duk_idx_t CbArgs_MouseEventObject(duk_context* ctx, void* env); static duk_idx_t CbArgs_MouseEventObject(duk_context * ctx, void * env);
static duk_idx_t CbArgs_SPTaskEventObject(duk_context* ctx, void* env); static duk_idx_t CbArgs_SPTaskEventObject(duk_context * ctx, void * env);
static duk_idx_t CbArgs_PIEventObject(duk_context* ctx, void* env); static duk_idx_t CbArgs_PIEventObject(duk_context * ctx, void * env);
static duk_ret_t RequireAddressOrAddressRange(duk_context* ctx, duk_idx_t idx, uint32_t* addrStart, uint32_t *addrEnd); static duk_ret_t RequireAddressOrAddressRange(duk_context * ctx, duk_idx_t idx, uint32_t * addrStart, uint32_t * addrEnd);
static duk_ret_t RequireInterpreterCPU(duk_context* ctx); static duk_ret_t RequireInterpreterCPU(duk_context * ctx);
void ScriptAPI::Define_events(duk_context* ctx) void ScriptAPI::Define_events(duk_context * ctx)
{ {
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "onstatechange", DukCFunction(js_events_onstatechange) }, {"onstatechange", DukCFunction(js_events_onstatechange)},
{ "onexec", DukCFunction(js_events_onexec) }, {"onexec", DukCFunction(js_events_onexec)},
{ "onread", DukCFunction(js_events_onread) }, {"onread", DukCFunction(js_events_onread)},
{ "onwrite", DukCFunction(js_events_onwrite) }, {"onwrite", DukCFunction(js_events_onwrite)},
{ "ongprvalue", DukCFunction(js_events_ongprvalue) }, {"ongprvalue", DukCFunction(js_events_ongprvalue)},
{ "onopcode", DukCFunction(js_events_onopcode) }, {"onopcode", DukCFunction(js_events_onopcode)},
{ "onpifread", DukCFunction(js_events_onpifread) }, {"onpifread", DukCFunction(js_events_onpifread)},
{ "onsptask", DukCFunction(js_events_onsptask) }, {"onsptask", DukCFunction(js_events_onsptask)},
{ "onpidma", DukCFunction(js_events_onpidma) }, {"onpidma", DukCFunction(js_events_onpidma)},
{ "onmouseup", DukCFunction(js_events_onmouseup) }, {"onmouseup", DukCFunction(js_events_onmouseup)},
{ "onmousedown", DukCFunction(js_events_onmousedown) }, {"onmousedown", DukCFunction(js_events_onmousedown)},
{ "onmousemove", DukCFunction(js_events_onmousemove) }, {"onmousemove", DukCFunction(js_events_onmousemove)},
{ "remove", DukCFunction(js_events_remove) }, {"remove", DukCFunction(js_events_remove)},
{ nullptr } { nullptr }
}; };
@ -58,10 +59,10 @@ void ScriptAPI::Define_events(duk_context* ctx)
DefineGlobalClass(ctx, "DrawEvent", js_DummyConstructor); DefineGlobalClass(ctx, "DrawEvent", js_DummyConstructor);
const DukPropListEntry mouseEventStaticProps[] = { const DukPropListEntry mouseEventStaticProps[] = {
{ "NONE", DukNumber(-1) }, {"NONE", DukNumber(-1)},
{ "LEFT", DukNumber(0) }, {"LEFT", DukNumber(0)},
{ "MIDDLE", DukNumber(1) }, {"MIDDLE", DukNumber(1)},
{ "RIGHT", DukNumber(2) }, {"RIGHT", DukNumber(2)},
{nullptr} {nullptr}
}; };
@ -70,17 +71,17 @@ void ScriptAPI::Define_events(duk_context* ctx)
duk_ret_t ScriptAPI::js_events_onstatechange(duk_context * ctx) duk_ret_t ScriptAPI::js_events_onstatechange(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Function }); CheckArgs(ctx, {Arg_Function});
JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_EMUSTATECHANGE, JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_EMUSTATECHANGE,
CbArgs_EmuStateChangeEventObject); CbArgs_EmuStateChangeEventObject);
duk_push_uint(ctx, callbackId); duk_push_uint(ctx, callbackId);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_onexec(duk_context* ctx) duk_ret_t ScriptAPI::js_events_onexec(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Any, Arg_Function }); CheckArgs(ctx, {Arg_Any, Arg_Function});
uint32_t addrStart, addrEnd; uint32_t addrStart, addrEnd;
RequireAddressOrAddressRange(ctx, 0, &addrStart, &addrEnd); RequireAddressOrAddressRange(ctx, 0, &addrStart, &addrEnd);
@ -88,7 +89,7 @@ duk_ret_t ScriptAPI::js_events_onexec(duk_context* ctx)
RequireInterpreterCPU(ctx); RequireInterpreterCPU(ctx);
JSAppCallback cb(GetInstance(ctx), duk_get_heapptr(ctx, 1), JSAppCallback cb(GetInstance(ctx), duk_get_heapptr(ctx, 1),
CbCond_PcBetween, CbArgs_ExecEventObject); CbCond_PcBetween, CbArgs_ExecEventObject);
cb.m_Params.addrStart = addrStart; cb.m_Params.addrStart = addrStart;
cb.m_Params.addrEnd = addrEnd; cb.m_Params.addrEnd = addrEnd;
@ -98,9 +99,9 @@ duk_ret_t ScriptAPI::js_events_onexec(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_onread(duk_context* ctx) duk_ret_t ScriptAPI::js_events_onread(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Any, Arg_Function }); CheckArgs(ctx, {Arg_Any, Arg_Function});
uint32_t addrStart, addrEnd; uint32_t addrStart, addrEnd;
RequireAddressOrAddressRange(ctx, 0, &addrStart, &addrEnd); RequireAddressOrAddressRange(ctx, 0, &addrStart, &addrEnd);
@ -108,7 +109,7 @@ duk_ret_t ScriptAPI::js_events_onread(duk_context* ctx)
RequireInterpreterCPU(ctx); RequireInterpreterCPU(ctx);
JSAppCallback cb(GetInstance(ctx), duk_get_heapptr(ctx, 1), JSAppCallback cb(GetInstance(ctx), duk_get_heapptr(ctx, 1),
CbCond_ReadAddrBetween, CbArgs_ReadEventObject); CbCond_ReadAddrBetween, CbArgs_ReadEventObject);
cb.m_Params.addrStart = addrStart; cb.m_Params.addrStart = addrStart;
cb.m_Params.addrEnd = addrEnd; cb.m_Params.addrEnd = addrEnd;
@ -118,9 +119,9 @@ duk_ret_t ScriptAPI::js_events_onread(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_onwrite(duk_context* ctx) duk_ret_t ScriptAPI::js_events_onwrite(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Any, Arg_Function }); CheckArgs(ctx, {Arg_Any, Arg_Function});
uint32_t addrStart, addrEnd; uint32_t addrStart, addrEnd;
RequireAddressOrAddressRange(ctx, 0, &addrStart, &addrEnd); RequireAddressOrAddressRange(ctx, 0, &addrStart, &addrEnd);
@ -128,7 +129,7 @@ duk_ret_t ScriptAPI::js_events_onwrite(duk_context* ctx)
RequireInterpreterCPU(ctx); RequireInterpreterCPU(ctx);
JSAppCallback cb(GetInstance(ctx), duk_get_heapptr(ctx, 1), JSAppCallback cb(GetInstance(ctx), duk_get_heapptr(ctx, 1),
CbCond_WriteAddrBetween, CbArgs_WriteEventObject); CbCond_WriteAddrBetween, CbArgs_WriteEventObject);
cb.m_Params.addrStart = addrStart; cb.m_Params.addrStart = addrStart;
cb.m_Params.addrEnd = addrEnd; cb.m_Params.addrEnd = addrEnd;
@ -138,9 +139,9 @@ duk_ret_t ScriptAPI::js_events_onwrite(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_onopcode(duk_context* ctx) duk_ret_t ScriptAPI::js_events_onopcode(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Any, Arg_Number, Arg_Number, Arg_Function }); CheckArgs(ctx, {Arg_Any, Arg_Number, Arg_Number, Arg_Function});
uint32_t addrStart, addrEnd; uint32_t addrStart, addrEnd;
RequireAddressOrAddressRange(ctx, 0, &addrStart, &addrEnd); RequireAddressOrAddressRange(ctx, 0, &addrStart, &addrEnd);
@ -151,7 +152,7 @@ duk_ret_t ScriptAPI::js_events_onopcode(duk_context* ctx)
uint32_t mask = duk_get_uint(ctx, 2); uint32_t mask = duk_get_uint(ctx, 2);
JSAppCallback cb(GetInstance(ctx), duk_get_heapptr(ctx, 3), JSAppCallback cb(GetInstance(ctx), duk_get_heapptr(ctx, 3),
CbCond_PcBetween_OpcodeEquals, CbArgs_OpcodeEventObject); CbCond_PcBetween_OpcodeEquals, CbArgs_OpcodeEventObject);
cb.m_Params.addrStart = addrStart; cb.m_Params.addrStart = addrStart;
cb.m_Params.addrEnd = addrEnd; cb.m_Params.addrEnd = addrEnd;
cb.m_Params.opcode = opcode; cb.m_Params.opcode = opcode;
@ -163,9 +164,9 @@ duk_ret_t ScriptAPI::js_events_onopcode(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_ongprvalue(duk_context* ctx) duk_ret_t ScriptAPI::js_events_ongprvalue(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Any, Arg_Number, Arg_Number, Arg_Function }); CheckArgs(ctx, {Arg_Any, Arg_Number, Arg_Number, Arg_Function});
uint32_t addrStart, addrEnd; uint32_t addrStart, addrEnd;
RequireAddressOrAddressRange(ctx, 0, &addrStart, &addrEnd); RequireAddressOrAddressRange(ctx, 0, &addrStart, &addrEnd);
@ -173,7 +174,7 @@ duk_ret_t ScriptAPI::js_events_ongprvalue(duk_context* ctx)
RequireInterpreterCPU(ctx); RequireInterpreterCPU(ctx);
JSAppCallback cb(GetInstance(ctx), duk_get_heapptr(ctx, 3), JSAppCallback cb(GetInstance(ctx), duk_get_heapptr(ctx, 3),
CbCond_PcBetween_GprValueEquals, CbArgs_RegValueEventObject); CbCond_PcBetween_GprValueEquals, CbArgs_RegValueEventObject);
cb.m_Params.addrStart = addrStart; cb.m_Params.addrStart = addrStart;
cb.m_Params.addrEnd = addrEnd; cb.m_Params.addrEnd = addrEnd;
cb.m_Params.regIndices = duk_get_uint(ctx, 1); cb.m_Params.regIndices = duk_get_uint(ctx, 1);
@ -185,63 +186,63 @@ duk_ret_t ScriptAPI::js_events_ongprvalue(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_onpifread(duk_context* ctx) duk_ret_t ScriptAPI::js_events_onpifread(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Function }); CheckArgs(ctx, {Arg_Function});
JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_PIFREAD, CbArgs_GenericEventObject); JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_PIFREAD, CbArgs_GenericEventObject);
duk_push_uint(ctx, callbackId); duk_push_uint(ctx, callbackId);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_onsptask(duk_context* ctx) duk_ret_t ScriptAPI::js_events_onsptask(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Function }); CheckArgs(ctx, {Arg_Function});
JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_RSPTASK, CbArgs_SPTaskEventObject); JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_RSPTASK, CbArgs_SPTaskEventObject);
duk_push_uint(ctx, callbackId); duk_push_uint(ctx, callbackId);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_onpidma(duk_context* ctx) duk_ret_t ScriptAPI::js_events_onpidma(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Function }); CheckArgs(ctx, {Arg_Function});
JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_PIDMA, CbArgs_PIEventObject); JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_PIDMA, CbArgs_PIEventObject);
duk_push_uint(ctx, callbackId); duk_push_uint(ctx, callbackId);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_onmouseup(duk_context* ctx) duk_ret_t ScriptAPI::js_events_onmouseup(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Function }); CheckArgs(ctx, {Arg_Function});
JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_MOUSEUP, CbArgs_MouseEventObject); JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_MOUSEUP, CbArgs_MouseEventObject);
duk_push_uint(ctx, callbackId); duk_push_uint(ctx, callbackId);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_onmousedown(duk_context* ctx) duk_ret_t ScriptAPI::js_events_onmousedown(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Function }); CheckArgs(ctx, {Arg_Function});
JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_MOUSEDOWN, CbArgs_MouseEventObject); JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_MOUSEDOWN, CbArgs_MouseEventObject);
duk_push_uint(ctx, callbackId); duk_push_uint(ctx, callbackId);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_onmousemove(duk_context* ctx) duk_ret_t ScriptAPI::js_events_onmousemove(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Function }); CheckArgs(ctx, {Arg_Function});
JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_MOUSEMOVE, CbArgs_MouseEventObject); JSAppCallbackID callbackId = AddAppCallback(ctx, 0, JS_HOOK_MOUSEMOVE, CbArgs_MouseEventObject);
duk_push_uint(ctx, callbackId); duk_push_uint(ctx, callbackId);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_events_remove(duk_context* ctx) duk_ret_t ScriptAPI::js_events_remove(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number }); CheckArgs(ctx, {Arg_Number});
JSAppCallbackID callbackId = (JSAppCallbackID)duk_get_uint(ctx, 0); JSAppCallbackID callbackId = (JSAppCallbackID)duk_get_uint(ctx, 0);
@ -254,9 +255,9 @@ duk_ret_t ScriptAPI::js_events_remove(duk_context* ctx)
return 0; return 0;
} }
bool CbCond_ReadAddrBetween(JSAppCallback* cb, void* _env) bool CbCond_ReadAddrBetween(JSAppCallback * cb, void * _env)
{ {
JSHookCpuStepEnv* env = (JSHookCpuStepEnv*)_env; JSHookCpuStepEnv * env = (JSHookCpuStepEnv *)_env;
if (!env->opInfo.IsLoadCommand()) if (!env->opInfo.IsLoadCommand())
{ {
@ -269,9 +270,9 @@ bool CbCond_ReadAddrBetween(JSAppCallback* cb, void* _env)
addr <= cb->m_Params.addrEnd); addr <= cb->m_Params.addrEnd);
} }
bool CbCond_WriteAddrBetween(JSAppCallback* cb, void* _env) bool CbCond_WriteAddrBetween(JSAppCallback * cb, void * _env)
{ {
JSHookCpuStepEnv* env = (JSHookCpuStepEnv*)_env; JSHookCpuStepEnv * env = (JSHookCpuStepEnv *)_env;
if (!env->opInfo.IsStoreCommand()) if (!env->opInfo.IsStoreCommand())
{ {
@ -284,38 +285,38 @@ bool CbCond_WriteAddrBetween(JSAppCallback* cb, void* _env)
addr <= cb->m_Params.addrEnd); addr <= cb->m_Params.addrEnd);
} }
bool CbCond_PcBetween(JSAppCallback* cb, void* _env) bool CbCond_PcBetween(JSAppCallback * cb, void * _env)
{ {
JSHookCpuStepEnv* env = (JSHookCpuStepEnv*)_env; JSHookCpuStepEnv * env = (JSHookCpuStepEnv *)_env;
return (env->pc >= cb->m_Params.addrStart && return (env->pc >= cb->m_Params.addrStart &&
env->pc <= cb->m_Params.addrEnd); env->pc <= cb->m_Params.addrEnd);
} }
bool CbCond_PcBetween_OpcodeEquals(JSAppCallback* cb, void* _env) bool CbCond_PcBetween_OpcodeEquals(JSAppCallback * cb, void * _env)
{ {
if (!CbCond_PcBetween(cb, _env)) if (!CbCond_PcBetween(cb, _env))
{ {
return false; return false;
} }
JSHookCpuStepEnv* env = (JSHookCpuStepEnv*)_env; JSHookCpuStepEnv * env = (JSHookCpuStepEnv *)_env;
return cb->m_Params.opcode == (env->opInfo.m_OpCode.Value & cb->m_Params.opcodeMask); return cb->m_Params.opcode == (env->opInfo.m_OpCode.Value & cb->m_Params.opcodeMask);
} }
static bool CbCond_PcBetween_GprValueEquals(JSAppCallback* cb, void* _env) static bool CbCond_PcBetween_GprValueEquals(JSAppCallback * cb, void * _env)
{ {
if (!CbCond_PcBetween(cb, _env)) if (!CbCond_PcBetween(cb, _env))
{ {
return false; return false;
} }
JSHookCpuStepEnv* env = (JSHookCpuStepEnv*)_env; JSHookCpuStepEnv * env = (JSHookCpuStepEnv *)_env;
for(int i = 0; i < 32; i++) for (int i = 0; i < 32; i++)
{ {
if(cb->m_Params.regIndices & (1 << i)) if (cb->m_Params.regIndices & (1 << i))
{ {
if(g_Reg->m_GPR[i].UW[0] == cb->m_Params.regValue) if (g_Reg->m_GPR[i].UW[0] == cb->m_Params.regValue)
{ {
env->outAffectedRegIndex = i; env->outAffectedRegIndex = i;
return true; return true;
@ -326,16 +327,16 @@ static bool CbCond_PcBetween_GprValueEquals(JSAppCallback* cb, void* _env)
return false; return false;
} }
duk_idx_t CbArgs_EmuStateChangeEventObject(duk_context* ctx, void* _env) duk_idx_t CbArgs_EmuStateChangeEventObject(duk_context * ctx, void * _env)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
JSHookEmuStateChangeEnv* env = (JSHookEmuStateChangeEnv*)_env; JSHookEmuStateChangeEnv * env = (JSHookEmuStateChangeEnv *)_env;
duk_push_object(ctx); duk_push_object(ctx);
SetDummyConstructor(ctx, -1, "EmuStateChangeEvent"); SetDummyConstructor(ctx, -1, "EmuStateChangeEvent");
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "callbackId", DukUInt(inst->CallbackId()) }, {"callbackId", DukUInt(inst->CallbackId())},
{ "state", DukUInt(env->state) }, {"state", DukUInt(env->state)},
{ nullptr } { nullptr }
}; };
@ -344,14 +345,14 @@ duk_idx_t CbArgs_EmuStateChangeEventObject(duk_context* ctx, void* _env)
return 1; return 1;
} }
duk_idx_t CbArgs_GenericEventObject(duk_context* ctx, void* /*_env*/) duk_idx_t CbArgs_GenericEventObject(duk_context * ctx, void * /*_env*/)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
duk_push_object(ctx); duk_push_object(ctx);
SetDummyConstructor(ctx, -1, "GenericEvent"); SetDummyConstructor(ctx, -1, "GenericEvent");
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "callbackId", DukUInt(inst->CallbackId()) }, {"callbackId", DukUInt(inst->CallbackId())},
{ nullptr } { nullptr }
}; };
@ -360,16 +361,16 @@ duk_idx_t CbArgs_GenericEventObject(duk_context* ctx, void* /*_env*/)
return 1; return 1;
} }
duk_idx_t CbArgs_ExecEventObject(duk_context* ctx, void* _env) duk_idx_t CbArgs_ExecEventObject(duk_context * ctx, void * _env)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
JSHookCpuStepEnv* env = (JSHookCpuStepEnv*)_env; JSHookCpuStepEnv * env = (JSHookCpuStepEnv *)_env;
duk_push_object(ctx); duk_push_object(ctx);
SetDummyConstructor(ctx, -1, "CPUExecEvent"); SetDummyConstructor(ctx, -1, "CPUExecEvent");
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "callbackId", DukUInt(inst->CallbackId()) }, {"callbackId", DukUInt(inst->CallbackId())},
{ "pc", DukUInt(env->pc) }, {"pc", DukUInt(env->pc)},
{ nullptr } { nullptr }
}; };
@ -378,12 +379,12 @@ duk_idx_t CbArgs_ExecEventObject(duk_context* ctx, void* _env)
return 1; return 1;
} }
duk_idx_t CbArgs_ReadEventObject(duk_context* ctx, void* _env) duk_idx_t CbArgs_ReadEventObject(duk_context * ctx, void * _env)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
CDebuggerUI* debugger = inst->Debugger(); CDebuggerUI * debugger = inst->Debugger();
JSHookCpuStepEnv* env = (JSHookCpuStepEnv*)_env; JSHookCpuStepEnv * env = (JSHookCpuStepEnv *)_env;
uint32_t address = env->opInfo.GetLoadStoreAddress(); uint32_t address = env->opInfo.GetLoadStoreAddress();
uint8_t op = env->opInfo.m_OpCode.op; uint8_t op = env->opInfo.m_OpCode.op;
@ -394,17 +395,18 @@ duk_idx_t CbArgs_ReadEventObject(duk_context* ctx, void* _env)
SetDummyConstructor(ctx, -1, "CPUReadWriteEvent"); SetDummyConstructor(ctx, -1, "CPUReadWriteEvent");
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "callbackId", DukUInt(inst->CallbackId()) }, {"callbackId", DukUInt(inst->CallbackId())},
{ "pc", DukUInt(env->pc) }, {"pc", DukUInt(env->pc)},
{ "address", DukUInt(address) }, {"address", DukUInt(address)},
{ "reg", DukUInt(rt) }, {"reg", DukUInt(rt)},
{ "fpu", DukBoolean(bFPU) }, {"fpu", DukBoolean(bFPU)},
{ nullptr } { nullptr }
}; };
DukPutPropList(ctx, -1, props); DukPutPropList(ctx, -1, props);
union { union
{
uint8_t u8; uint8_t u8;
int8_t s8; int8_t s8;
uint16_t u16; uint16_t u16;
@ -415,9 +417,9 @@ duk_idx_t CbArgs_ReadEventObject(duk_context* ctx, void* _env)
double f64; double f64;
uint64_t u64; uint64_t u64;
} value = {0}; } value = {0};
bool bNeedUpper32 = false; bool bNeedUpper32 = false;
switch (env->opInfo.m_OpCode.op) switch (env->opInfo.m_OpCode.op)
{ {
case R4300i_LB: case R4300i_LB:
@ -528,11 +530,11 @@ duk_idx_t CbArgs_ReadEventObject(duk_context* ctx, void* _env)
return 1; return 1;
} }
duk_idx_t CbArgs_WriteEventObject(duk_context* ctx, void* _env) duk_idx_t CbArgs_WriteEventObject(duk_context * ctx, void * _env)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
CDebuggerUI* debugger = inst->Debugger(); CDebuggerUI * debugger = inst->Debugger();
JSHookCpuStepEnv* env = (JSHookCpuStepEnv*)_env; JSHookCpuStepEnv * env = (JSHookCpuStepEnv *)_env;
uint32_t address = env->opInfo.GetLoadStoreAddress(); uint32_t address = env->opInfo.GetLoadStoreAddress();
@ -544,11 +546,11 @@ duk_idx_t CbArgs_WriteEventObject(duk_context* ctx, void* _env)
SetDummyConstructor(ctx, -1, "CPUReadWriteEvent"); SetDummyConstructor(ctx, -1, "CPUReadWriteEvent");
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "callbackId", DukUInt(inst->CallbackId()) }, {"callbackId", DukUInt(inst->CallbackId())},
{ "pc", DukUInt(env->pc) }, {"pc", DukUInt(env->pc)},
{ "address", DukUInt(address) }, {"address", DukUInt(address)},
{ "reg", DukUInt(rt) }, {"reg", DukUInt(rt)},
{ "fpu", DukBoolean(bFPU) }, {"fpu", DukBoolean(bFPU)},
{ nullptr } { nullptr }
}; };
@ -640,21 +642,21 @@ duk_idx_t CbArgs_WriteEventObject(duk_context* ctx, void* _env)
} }
duk_freeze(ctx, -1); duk_freeze(ctx, -1);
return 1; return 1;
} }
duk_idx_t CbArgs_OpcodeEventObject(duk_context* ctx, void* _env) duk_idx_t CbArgs_OpcodeEventObject(duk_context * ctx, void * _env)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
JSHookCpuStepEnv* env = (JSHookCpuStepEnv*)_env; JSHookCpuStepEnv * env = (JSHookCpuStepEnv *)_env;
duk_push_object(ctx); duk_push_object(ctx);
SetDummyConstructor(ctx, -1, "CPUOpcodeEvent"); SetDummyConstructor(ctx, -1, "CPUOpcodeEvent");
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "callbackId", DukUInt(inst->CallbackId()) }, {"callbackId", DukUInt(inst->CallbackId())},
{ "pc", DukUInt(env->pc) }, {"pc", DukUInt(env->pc)},
{ "opcode", DukUInt(env->opInfo.m_OpCode.Value) }, {"opcode", DukUInt(env->opInfo.m_OpCode.Value)},
{ nullptr } { nullptr }
}; };
@ -663,18 +665,18 @@ duk_idx_t CbArgs_OpcodeEventObject(duk_context* ctx, void* _env)
return 1; return 1;
} }
duk_idx_t CbArgs_RegValueEventObject(duk_context* ctx, void* _env) duk_idx_t CbArgs_RegValueEventObject(duk_context * ctx, void * _env)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
JSHookCpuStepEnv* env = (JSHookCpuStepEnv*)_env; JSHookCpuStepEnv * env = (JSHookCpuStepEnv *)_env;
duk_push_object(ctx); duk_push_object(ctx);
SetDummyConstructor(ctx, -1, "CPURegValueEvent"); SetDummyConstructor(ctx, -1, "CPURegValueEvent");
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "callbackId", DukUInt(inst->CallbackId()) }, {"callbackId", DukUInt(inst->CallbackId())},
{ "pc", DukUInt(env->pc) }, {"pc", DukUInt(env->pc)},
{ "value", DukUInt(g_Reg->m_GPR[env->outAffectedRegIndex].UW[0]) }, {"value", DukUInt(g_Reg->m_GPR[env->outAffectedRegIndex].UW[0])},
{ "reg", DukUInt(env->outAffectedRegIndex) }, {"reg", DukUInt(env->outAffectedRegIndex)},
{ nullptr } { nullptr }
}; };
@ -683,18 +685,18 @@ duk_idx_t CbArgs_RegValueEventObject(duk_context* ctx, void* _env)
return 1; return 1;
} }
static duk_idx_t CbArgs_MouseEventObject(duk_context* ctx, void* _env) static duk_idx_t CbArgs_MouseEventObject(duk_context * ctx, void * _env)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
JSHookMouseEnv* env = (JSHookMouseEnv*)_env; JSHookMouseEnv * env = (JSHookMouseEnv *)_env;
duk_push_object(ctx); duk_push_object(ctx);
SetDummyConstructor(ctx, -1, "MouseEvent"); SetDummyConstructor(ctx, -1, "MouseEvent");
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "callbackId", DukUInt(inst->CallbackId()) }, {"callbackId", DukUInt(inst->CallbackId())},
{ "button", DukInt(env->button) }, {"button", DukInt(env->button)},
{ "x", DukInt(env->x) }, {"x", DukInt(env->x)},
{ "y", DukInt(env->y) }, {"y", DukInt(env->y)},
{ nullptr } { nullptr }
}; };
@ -703,31 +705,31 @@ static duk_idx_t CbArgs_MouseEventObject(duk_context* ctx, void* _env)
return 1; return 1;
} }
static duk_idx_t CbArgs_SPTaskEventObject(duk_context* ctx, void* _env) static duk_idx_t CbArgs_SPTaskEventObject(duk_context * ctx, void * _env)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
JSHookSpTaskEnv* env = (JSHookSpTaskEnv*)_env; JSHookSpTaskEnv * env = (JSHookSpTaskEnv *)_env;
duk_push_object(ctx); duk_push_object(ctx);
SetDummyConstructor(ctx, -1, "SPTaskEvent"); SetDummyConstructor(ctx, -1, "SPTaskEvent");
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "callbackId", DukUInt(inst->CallbackId()) }, {"callbackId", DukUInt(inst->CallbackId())},
{ "taskType", DukUInt(env->taskType) }, {"taskType", DukUInt(env->taskType)},
{ "taskFlags", DukUInt(env->taskFlags) }, {"taskFlags", DukUInt(env->taskFlags)},
{ "ucodeBootAddress", DukUInt(env->ucodeBootAddress | 0x80000000) }, {"ucodeBootAddress", DukUInt(env->ucodeBootAddress | 0x80000000)},
{ "ucodeBootSize", DukUInt(env->ucodeBootSize) }, {"ucodeBootSize", DukUInt(env->ucodeBootSize)},
{ "ucodeAddress", DukUInt(env->ucodeAddress | 0x80000000) }, {"ucodeAddress", DukUInt(env->ucodeAddress | 0x80000000)},
{ "ucodeSize", DukUInt(env->ucodeSize) }, {"ucodeSize", DukUInt(env->ucodeSize)},
{ "ucodeDataAddress", DukUInt(env->ucodeDataAddress | 0x80000000) }, {"ucodeDataAddress", DukUInt(env->ucodeDataAddress | 0x80000000)},
{ "ucodeDataSize", DukUInt(env->ucodeDataSize) }, {"ucodeDataSize", DukUInt(env->ucodeDataSize)},
{ "dramStackAddress", DukUInt(env->dramStackAddress | 0x80000000) }, {"dramStackAddress", DukUInt(env->dramStackAddress | 0x80000000)},
{ "dramStackSize", DukUInt(env->dramStackSize) }, {"dramStackSize", DukUInt(env->dramStackSize)},
{ "outputBuffAddress", DukUInt(env->outputBuffAddress | 0x80000000) }, {"outputBuffAddress", DukUInt(env->outputBuffAddress | 0x80000000)},
{ "outputBuffSize", DukUInt(env->outputBuffSize) }, {"outputBuffSize", DukUInt(env->outputBuffSize)},
{ "dataAddress", DukUInt(env->dataAddress | 0x80000000) }, {"dataAddress", DukUInt(env->dataAddress | 0x80000000)},
{ "dataSize", DukUInt(env->dataSize) }, {"dataSize", DukUInt(env->dataSize)},
{ "yieldDataAddress", DukUInt(env->yieldDataAddress | 0x80000000) }, {"yieldDataAddress", DukUInt(env->yieldDataAddress | 0x80000000)},
{ "yieldDataSize", DukUInt(env->yieldDataSize) }, {"yieldDataSize", DukUInt(env->yieldDataSize)},
{ nullptr } { nullptr }
}; };
@ -736,19 +738,19 @@ static duk_idx_t CbArgs_SPTaskEventObject(duk_context* ctx, void* _env)
return 1; return 1;
} }
static duk_idx_t CbArgs_PIEventObject(duk_context* ctx, void* _env) static duk_idx_t CbArgs_PIEventObject(duk_context * ctx, void * _env)
{ {
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
JSHookPiDmaEnv* env = (JSHookPiDmaEnv*)_env; JSHookPiDmaEnv * env = (JSHookPiDmaEnv *)_env;
duk_push_object(ctx); duk_push_object(ctx);
SetDummyConstructor(ctx, -1, "PIEvent"); SetDummyConstructor(ctx, -1, "PIEvent");
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "callbackId", DukUInt(inst->CallbackId()) }, {"callbackId", DukUInt(inst->CallbackId())},
{ "direction", DukUInt(env->direction) }, {"direction", DukUInt(env->direction)},
{ "dramAddress", DukUInt(env->dramAddress | 0x80000000) }, {"dramAddress", DukUInt(env->dramAddress | 0x80000000)},
{ "cartAddress", DukUInt(env->cartAddress | 0xA0000000) }, {"cartAddress", DukUInt(env->cartAddress | 0xA0000000)},
{ "length", DukUInt(env->length + 1) }, {"length", DukUInt(env->length + 1)},
{ nullptr } { nullptr }
}; };
@ -757,14 +759,14 @@ static duk_idx_t CbArgs_PIEventObject(duk_context* ctx, void* _env)
return 1; return 1;
} }
duk_ret_t RequireAddressOrAddressRange(duk_context* ctx, duk_idx_t idx, uint32_t* addrStart, uint32_t* addrEnd) duk_ret_t RequireAddressOrAddressRange(duk_context * ctx, duk_idx_t idx, uint32_t * addrStart, uint32_t * addrEnd)
{ {
if(duk_is_number(ctx, idx)) if (duk_is_number(ctx, idx))
{ {
if (abs(duk_get_number(ctx, idx)) > 0xFFFFFFFF) if (abs(duk_get_number(ctx, idx)) > 0xFFFFFFFF)
{ {
duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR,
"address is out of range"); "address is out of range");
return duk_throw(ctx); return duk_throw(ctx);
} }
@ -774,25 +776,25 @@ duk_ret_t RequireAddressOrAddressRange(duk_context* ctx, duk_idx_t idx, uint32_t
return 0; return 0;
} }
if(duk_is_object(ctx, idx)) if (duk_is_object(ctx, idx))
{ {
if(!duk_has_prop_string(ctx, idx, "start") || if (!duk_has_prop_string(ctx, idx, "start") ||
!duk_has_prop_string(ctx, idx, "end")) !duk_has_prop_string(ctx, idx, "end"))
{ {
duk_push_error_object(ctx, DUK_ERR_REFERENCE_ERROR, duk_push_error_object(ctx, DUK_ERR_REFERENCE_ERROR,
"object is missing 'start' or 'end' property"); "object is missing 'start' or 'end' property");
return duk_throw(ctx); return duk_throw(ctx);
} }
duk_get_prop_string(ctx, idx, "start"); duk_get_prop_string(ctx, idx, "start");
duk_get_prop_string(ctx, idx, "end"); duk_get_prop_string(ctx, idx, "end");
if(!duk_is_number(ctx, -2) || if (!duk_is_number(ctx, -2) ||
!duk_is_number(ctx, -1)) !duk_is_number(ctx, -1))
{ {
duk_pop_n(ctx, 2); duk_pop_n(ctx, 2);
duk_push_error_object(ctx, DUK_ERR_REFERENCE_ERROR, duk_push_error_object(ctx, DUK_ERR_REFERENCE_ERROR,
"'start' and 'end' properties must be numbers"); "'start' and 'end' properties must be numbers");
return duk_throw(ctx); return duk_throw(ctx);
} }
@ -800,7 +802,7 @@ duk_ret_t RequireAddressOrAddressRange(duk_context* ctx, duk_idx_t idx, uint32_t
abs(duk_get_number(ctx, -1)) > 0xFFFFFFFF) abs(duk_get_number(ctx, -1)) > 0xFFFFFFFF)
{ {
duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR, duk_push_error_object(ctx, DUK_ERR_RANGE_ERROR,
"'start' or 'end' property out of range"); "'start' or 'end' property out of range");
return duk_throw(ctx); return duk_throw(ctx);
} }
@ -811,17 +813,17 @@ duk_ret_t RequireAddressOrAddressRange(duk_context* ctx, duk_idx_t idx, uint32_t
} }
duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR, duk_push_error_object(ctx, DUK_ERR_TYPE_ERROR,
"argument %d invalid; expected number or object", idx); "argument %d invalid; expected number or object", idx);
return duk_throw(ctx); return duk_throw(ctx);
} }
duk_ret_t RequireInterpreterCPU(duk_context* ctx) duk_ret_t RequireInterpreterCPU(duk_context * ctx)
{ {
if (!g_Settings->LoadBool(Setting_ForceInterpreterCPU) && if (!g_Settings->LoadBool(Setting_ForceInterpreterCPU) &&
(CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_Interpreter) (CPU_TYPE)g_Settings->LoadDword(Game_CpuType) != CPU_Interpreter)
{ {
duk_push_error_object(ctx, DUK_ERR_ERROR, duk_push_error_object(ctx, DUK_ERR_ERROR,
"this feature requires the interpreter core"); "this feature requires the interpreter core");
return duk_throw(ctx); return duk_throw(ctx);
} }

View File

@ -1,20 +1,21 @@
#include <stdafx.h> #include "stdafx.h"
#include <windows.h>
#include "ScriptAPI.h"
void ScriptAPI::Define_exec(duk_context* ctx) #include "ScriptAPI.h"
#include <windows.h>
void ScriptAPI::Define_exec(duk_context * ctx)
{ {
DefineGlobalFunction(ctx, "exec", js_exec); DefineGlobalFunction(ctx, "exec", js_exec);
} }
duk_ret_t ScriptAPI::js_exec(duk_context* ctx) duk_ret_t ScriptAPI::js_exec(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_String, Arg_OptObject }); CheckArgs(ctx, {Arg_String, Arg_OptObject});
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
CScriptSystem* sys = inst->System(); CScriptSystem * sys = inst->System();
const char* command = duk_get_string(ctx, 0); const char * command = duk_get_string(ctx, 0);
struct struct
{ {
@ -45,7 +46,7 @@ duk_ret_t ScriptAPI::js_exec(duk_context* ctx)
stdstr resultStdOut; stdstr resultStdOut;
stdstr resultStdErr; stdstr resultStdErr;
DWORD resultExitCode = EXIT_FAILURE; DWORD resultExitCode = EXIT_FAILURE;
SECURITY_ATTRIBUTES secAttr; SECURITY_ATTRIBUTES secAttr;
secAttr.nLength = sizeof(SECURITY_ATTRIBUTES); secAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
@ -76,7 +77,7 @@ duk_ret_t ScriptAPI::js_exec(duk_context* ctx)
PROCESS_INFORMATION processInfo; PROCESS_INFORMATION processInfo;
BOOL bSuccess = CreateProcessA(nullptr, (LPSTR)stdstr_f("cmd /c %s", command).c_str(), nullptr, nullptr, TRUE, BOOL bSuccess = CreateProcessA(nullptr, (LPSTR)stdstr_f("cmd /c %s", command).c_str(), nullptr, nullptr, TRUE,
0, nullptr, options.cwd.c_str(), &startupInfo, &processInfo); 0, nullptr, options.cwd.c_str(), &startupInfo, &processInfo);
if (bSuccess) if (bSuccess)
{ {
@ -130,10 +131,10 @@ duk_ret_t ScriptAPI::js_exec(duk_context* ctx)
if (!bSuccess || resultExitCode != 0) if (!bSuccess || resultExitCode != 0)
{ {
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "status", DukInt(resultExitCode) }, {"status", DukInt(resultExitCode)},
{ "stdout", DukString(resultStdOut.c_str()) }, {"stdout", DukString(resultStdOut.c_str())},
{ "stderr", DukString(resultStdErr.c_str()) }, {"stderr", DukString(resultStdErr.c_str())},
{ "pid", DukUInt(processInfo.dwProcessId) }, {"pid", DukUInt(processInfo.dwProcessId)},
{ nullptr } { nullptr }
}; };

View File

@ -1,13 +1,14 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptAPI.h"
#include "JSIntervalWorker.h" #include "JSIntervalWorker.h"
#include "ScriptAPI.h"
using namespace ScriptAPI; using namespace ScriptAPI;
static int AddIntervalContext(duk_context* ctx, duk_idx_t func_idx, int delayMS, bool bOnce); static int AddIntervalContext(duk_context * ctx, duk_idx_t func_idx, int delayMS, bool bOnce);
static void RemoveIntervalContext(duk_context* ctx, int intervalId); static void RemoveIntervalContext(duk_context * ctx, int intervalId);
void ScriptAPI::Define_interval(duk_context* ctx) void ScriptAPI::Define_interval(duk_context * ctx)
{ {
DefineGlobalFunction(ctx, "setInterval", js_setInterval); DefineGlobalFunction(ctx, "setInterval", js_setInterval);
DefineGlobalFunction(ctx, "clearInterval", js_clearInterval); DefineGlobalFunction(ctx, "clearInterval", js_clearInterval);
@ -15,41 +16,41 @@ void ScriptAPI::Define_interval(duk_context* ctx)
DefineGlobalFunction(ctx, "clearTimeout", js_clearTimeout); DefineGlobalFunction(ctx, "clearTimeout", js_clearTimeout);
} }
duk_ret_t ScriptAPI::js_setInterval(duk_context* ctx) duk_ret_t ScriptAPI::js_setInterval(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Function, Arg_Number }); CheckArgs(ctx, {Arg_Function, Arg_Number});
int delayMS = duk_get_int(ctx, 1); int delayMS = duk_get_int(ctx, 1);
int intervalId = AddIntervalContext(ctx, 0, delayMS, false); int intervalId = AddIntervalContext(ctx, 0, delayMS, false);
duk_push_int(ctx, intervalId); duk_push_int(ctx, intervalId);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_clearInterval(duk_context* ctx) duk_ret_t ScriptAPI::js_clearInterval(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number }); CheckArgs(ctx, {Arg_Number});
int intervalId = duk_get_int(ctx, 0); int intervalId = duk_get_int(ctx, 0);
RemoveIntervalContext(ctx, intervalId); RemoveIntervalContext(ctx, intervalId);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_setTimeout(duk_context* ctx) duk_ret_t ScriptAPI::js_setTimeout(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Function, Arg_Number }); CheckArgs(ctx, {Arg_Function, Arg_Number});
int delayMS = duk_get_int(ctx, 1); int delayMS = duk_get_int(ctx, 1);
int intervalId = AddIntervalContext(ctx, 0, delayMS, true); int intervalId = AddIntervalContext(ctx, 0, delayMS, true);
duk_push_int(ctx, intervalId); duk_push_int(ctx, intervalId);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_clearTimeout(duk_context* ctx) duk_ret_t ScriptAPI::js_clearTimeout(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number }); CheckArgs(ctx, {Arg_Number});
int intervalId = duk_get_int(ctx, 0); int intervalId = duk_get_int(ctx, 0);
RemoveIntervalContext(ctx, intervalId); RemoveIntervalContext(ctx, intervalId);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js__IntervalContext_invokeFunc(duk_context* ctx) duk_ret_t ScriptAPI::js__IntervalContext_invokeFunc(duk_context * ctx)
{ {
duk_push_this(ctx); duk_push_this(ctx);
duk_get_prop_string(ctx, -1, "func"); duk_get_prop_string(ctx, -1, "func");
@ -57,7 +58,7 @@ duk_ret_t ScriptAPI::js__IntervalContext_invokeFunc(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js__IntervalContext_remove(duk_context* ctx) duk_ret_t ScriptAPI::js__IntervalContext_remove(duk_context * ctx)
{ {
duk_push_this(ctx); duk_push_this(ctx);
duk_get_prop_string(ctx, -1, "id"); duk_get_prop_string(ctx, -1, "id");
@ -66,11 +67,11 @@ duk_ret_t ScriptAPI::js__IntervalContext_remove(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js__IntervalContext_finalizer(duk_context* ctx) duk_ret_t ScriptAPI::js__IntervalContext_finalizer(duk_context * ctx)
{ {
duk_get_prop_string(ctx, 0, "worker"); duk_get_prop_string(ctx, 0, "worker");
CJSIntervalWorker* intervalWorker = (CJSIntervalWorker*)duk_get_pointer(ctx, -1); CJSIntervalWorker * intervalWorker = (CJSIntervalWorker *)duk_get_pointer(ctx, -1);
if (intervalWorker != nullptr) if (intervalWorker != nullptr)
{ {
delete intervalWorker; delete intervalWorker;
@ -79,11 +80,11 @@ duk_ret_t ScriptAPI::js__IntervalContext_finalizer(duk_context* ctx)
return 0; return 0;
} }
int AddIntervalContext(duk_context* ctx, duk_idx_t func_idx, int delayMS, bool bOnce) int AddIntervalContext(duk_context * ctx, duk_idx_t func_idx, int delayMS, bool bOnce)
{ {
func_idx = duk_normalize_index(ctx, func_idx); func_idx = duk_normalize_index(ctx, func_idx);
CScriptInstance* inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
duk_push_global_object(ctx); duk_push_global_object(ctx);
duk_get_prop_string(ctx, -1, HS_gNextInvervalId); duk_get_prop_string(ctx, -1, HS_gNextInvervalId);
@ -97,8 +98,8 @@ int AddIntervalContext(duk_context* ctx, duk_idx_t func_idx, int delayMS, bool b
duk_push_object(ctx); duk_push_object(ctx);
RefObject(ctx, -1); RefObject(ctx, -1);
void* objectHeapPtr = duk_get_heapptr(ctx, -1); void * objectHeapPtr = duk_get_heapptr(ctx, -1);
CJSIntervalWorker* intervalWorker = new CJSIntervalWorker(inst, objectHeapPtr, delayMS, bOnce); CJSIntervalWorker * intervalWorker = new CJSIntervalWorker(inst, objectHeapPtr, delayMS, bOnce);
duk_dup(ctx, func_idx); duk_dup(ctx, func_idx);
duk_put_prop_string(ctx, -2, "func"); duk_put_prop_string(ctx, -2, "func");
@ -120,7 +121,7 @@ int AddIntervalContext(duk_context* ctx, duk_idx_t func_idx, int delayMS, bool b
return intervalId; return intervalId;
} }
void RemoveIntervalContext(duk_context* ctx, int intervalId) void RemoveIntervalContext(duk_context * ctx, int intervalId)
{ {
duk_push_global_object(ctx); duk_push_global_object(ctx);
duk_get_prop_string(ctx, -1, HS_gIntervals); duk_get_prop_string(ctx, -1, HS_gIntervals);
@ -135,7 +136,7 @@ void RemoveIntervalContext(duk_context* ctx, int intervalId)
duk_get_prop_string(ctx, -1, "worker"); duk_get_prop_string(ctx, -1, "worker");
CJSIntervalWorker* intervalWorker = (CJSIntervalWorker*)duk_get_pointer(ctx, -1); CJSIntervalWorker * intervalWorker = (CJSIntervalWorker *)duk_get_pointer(ctx, -1);
intervalWorker->StopWorkerProc(); intervalWorker->StopWorkerProc();
delete intervalWorker; delete intervalWorker;

View File

@ -1,41 +1,42 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptAPI.h" #include "ScriptAPI.h"
#include <Project64/UserInterface/Debugger/debugger.h>
#include <Project64/UserInterface/Debugger/DebugMMU.h> #include <Project64/UserInterface/Debugger/DebugMMU.h>
#include <Project64/UserInterface/Debugger/debugger.h>
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
#pragma warning(disable: 4702) // disable unreachable code warning #pragma warning(disable : 4702) // disable unreachable code warning
using namespace ScriptAPI; using namespace ScriptAPI;
static size_t MemTypeSize(MemType t); static size_t MemTypeSize(MemType t);
static duk_ret_t ThrowMemoryError(duk_context* ctx, uint32_t address); static duk_ret_t ThrowMemoryError(duk_context * ctx, uint32_t address);
void ScriptAPI::Define_mem(duk_context *ctx) void ScriptAPI::Define_mem(duk_context * ctx)
{ {
#define MEM_PROXY_FUNCS(T) js_mem__get<T>, js_mem__set<T> #define MEM_PROXY_FUNCS(T) js_mem__get<T>, js_mem__set<T>
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "getblock", DukCFunction(js_mem_getblock) }, {"getblock", DukCFunction(js_mem_getblock)},
{ "setblock", DukCFunction(js_mem_setblock) }, {"setblock", DukCFunction(js_mem_setblock)},
{ "getstring", DukCFunction(js_mem_getstring) }, {"getstring", DukCFunction(js_mem_getstring)},
{ "setstring", DukCFunction(js_mem_setblock) }, {"setstring", DukCFunction(js_mem_setblock)},
{ "bindvar", DukCFunction(js_mem_bindvar) }, {"bindvar", DukCFunction(js_mem_bindvar)},
{ "bindvars", DukCFunction(js_mem_bindvars) }, {"bindvars", DukCFunction(js_mem_bindvars)},
{ "bindstruct", DukCFunction(js_mem_bindstruct) }, {"bindstruct", DukCFunction(js_mem_bindstruct)},
{ "typedef", DukCFunction(js_mem_typedef) }, {"typedef", DukCFunction(js_mem_typedef)},
{ "ramSize", DukGetter(js_mem__get_ramsize) }, {"ramSize", DukGetter(js_mem__get_ramsize)},
{ "romSize", DukGetter(js_mem__get_romsize) }, {"romSize", DukGetter(js_mem__get_romsize)},
{ "ptr", DukGetter(js_mem__get_ptr) }, {"ptr", DukGetter(js_mem__get_ptr)},
{ "u32", DukProxy(MEM_PROXY_FUNCS(uint32_t)) }, {"u32", DukProxy(MEM_PROXY_FUNCS(uint32_t))},
{ "u16", DukProxy(MEM_PROXY_FUNCS(uint16_t)) }, {"u16", DukProxy(MEM_PROXY_FUNCS(uint16_t))},
{ "u8", DukProxy(MEM_PROXY_FUNCS(uint8_t)) }, {"u8", DukProxy(MEM_PROXY_FUNCS(uint8_t))},
{ "s32", DukProxy(MEM_PROXY_FUNCS(int32_t)) }, {"s32", DukProxy(MEM_PROXY_FUNCS(int32_t))},
{ "s16", DukProxy(MEM_PROXY_FUNCS(int16_t)) }, {"s16", DukProxy(MEM_PROXY_FUNCS(int16_t))},
{ "s8", DukProxy(MEM_PROXY_FUNCS(int8_t)) }, {"s8", DukProxy(MEM_PROXY_FUNCS(int8_t))},
{ "f64", DukProxy(MEM_PROXY_FUNCS(double)) }, {"f64", DukProxy(MEM_PROXY_FUNCS(double))},
{ "f32", DukProxy(MEM_PROXY_FUNCS(float)) }, {"f32", DukProxy(MEM_PROXY_FUNCS(float))},
{ nullptr } { nullptr }
}; };
@ -43,14 +44,14 @@ void ScriptAPI::Define_mem(duk_context *ctx)
} }
template <class T> template <class T>
duk_ret_t ScriptAPI::js_mem__get(duk_context *ctx) duk_ret_t ScriptAPI::js_mem__get(duk_context * ctx)
{ {
CScriptInstance *inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
uint32_t addr = (uint32_t)duk_to_number(ctx, 1); uint32_t addr = (uint32_t)duk_to_number(ctx, 1);
T value; T value;
if(inst->Debugger()->DebugLoad_VAddr<T>(addr, value)) if (inst->Debugger()->DebugLoad_VAddr<T>(addr, value))
{ {
duk_push_number(ctx, value); duk_push_number(ctx, value);
return 1; return 1;
@ -60,14 +61,14 @@ duk_ret_t ScriptAPI::js_mem__get(duk_context *ctx)
} }
template <class T> template <class T>
duk_ret_t ScriptAPI::js_mem__set(duk_context *ctx) duk_ret_t ScriptAPI::js_mem__set(duk_context * ctx)
{ {
CScriptInstance *inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
uint32_t addr = (uint32_t)duk_to_number(ctx, 1); uint32_t addr = (uint32_t)duk_to_number(ctx, 1);
T value = (T)duk_to_number(ctx, 2); T value = (T)duk_to_number(ctx, 2);
if(inst->Debugger()->DebugStore_VAddr<T>(addr, value)) if (inst->Debugger()->DebugStore_VAddr<T>(addr, value))
{ {
duk_push_true(ctx); duk_push_true(ctx);
return 1; return 1;
@ -76,19 +77,19 @@ duk_ret_t ScriptAPI::js_mem__set(duk_context *ctx)
return ThrowMemoryError(ctx, addr); return ThrowMemoryError(ctx, addr);
} }
duk_ret_t ScriptAPI::js_mem_getblock(duk_context *ctx) duk_ret_t ScriptAPI::js_mem_getblock(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number, Arg_Number }); CheckArgs(ctx, {Arg_Number, Arg_Number});
CScriptInstance *inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
duk_uint_t addr = duk_to_uint(ctx, 0); duk_uint_t addr = duk_to_uint(ctx, 0);
duk_uint_t length = duk_to_uint(ctx, 1); duk_uint_t length = duk_to_uint(ctx, 1);
uint8_t *data = (uint8_t*)duk_push_fixed_buffer(ctx, length); uint8_t * data = (uint8_t *)duk_push_fixed_buffer(ctx, length);
duk_push_buffer_object(ctx, -1, 0, length, DUK_BUFOBJ_NODEJS_BUFFER); duk_push_buffer_object(ctx, -1, 0, length, DUK_BUFOBJ_NODEJS_BUFFER);
uint32_t paddr; uint32_t paddr;
uint8_t* memsrc = nullptr; uint8_t * memsrc = nullptr;
uint32_t offsetStart = 0; uint32_t offsetStart = 0;
if (addr < 0x80000000 || addr >= 0xC0000000) if (addr < 0x80000000 || addr >= 0xC0000000)
@ -124,9 +125,9 @@ duk_ret_t ScriptAPI::js_mem_getblock(duk_context *ctx)
uint32_t middleLen = alignedOffsetEnd - alignedOffsetStart; uint32_t middleLen = alignedOffsetEnd - alignedOffsetStart;
uint32_t suffixLen = offsetEnd - alignedOffsetEnd; uint32_t suffixLen = offsetEnd - alignedOffsetEnd;
uint32_t* middleDst = (uint32_t*)&data[0 + prefixLen]; uint32_t * middleDst = (uint32_t *)&data[0 + prefixLen];
uint32_t* middleDstEnd = (uint32_t*)&data[0 + prefixLen + middleLen]; uint32_t * middleDstEnd = (uint32_t *)&data[0 + prefixLen + middleLen];
uint32_t* middleSrc = (uint32_t*)&memsrc[alignedOffsetStart]; uint32_t * middleSrc = (uint32_t *)&memsrc[alignedOffsetStart];
for (size_t i = 0; i < prefixLen; i++) for (size_t i = 0; i < prefixLen; i++)
{ {
@ -165,10 +166,10 @@ duk_ret_t ScriptAPI::js_mem_getblock(duk_context *ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_mem_getstring(duk_context *ctx) duk_ret_t ScriptAPI::js_mem_getstring(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number, Arg_OptNumber }); CheckArgs(ctx, {Arg_Number, Arg_OptNumber});
CScriptInstance *inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
duk_idx_t nargs = duk_get_top(ctx); duk_idx_t nargs = duk_get_top(ctx);
@ -176,15 +177,15 @@ duk_ret_t ScriptAPI::js_mem_getstring(duk_context *ctx)
duk_uint_t maxLength = nargs > 1 ? duk_to_uint(ctx, 1) : 0xFFFFFFFF; duk_uint_t maxLength = nargs > 1 ? duk_to_uint(ctx, 1) : 0xFFFFFFFF;
size_t length = 0; size_t length = 0;
for(size_t i = 0; i < maxLength; i++) for (size_t i = 0; i < maxLength; i++)
{ {
char c; char c;
if(!inst->Debugger()->DebugLoad_VAddr<char>(addr + i, c)) if (!inst->Debugger()->DebugLoad_VAddr<char>(addr + i, c))
{ {
return ThrowMemoryError(ctx, addr); return ThrowMemoryError(ctx, addr);
} }
if(c == 0) if (c == 0)
{ {
break; break;
} }
@ -192,12 +193,12 @@ duk_ret_t ScriptAPI::js_mem_getstring(duk_context *ctx)
length++; length++;
} }
char *str = new char[length + 1]; char * str = new char[length + 1];
str[length] = '\0'; str[length] = '\0';
for(size_t i = 0; i < length; i++) for (size_t i = 0; i < length; i++)
{ {
if(!inst->Debugger()->DebugLoad_VAddr<char>(addr + i, str[i])) if (!inst->Debugger()->DebugLoad_VAddr<char>(addr + i, str[i]))
{ {
delete[] str; delete[] str;
return ThrowMemoryError(ctx, addr); return ThrowMemoryError(ctx, addr);
@ -209,26 +210,26 @@ duk_ret_t ScriptAPI::js_mem_getstring(duk_context *ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_mem_setblock(duk_context *ctx) duk_ret_t ScriptAPI::js_mem_setblock(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Number, Arg_Any, Arg_OptNumber }); CheckArgs(ctx, {Arg_Number, Arg_Any, Arg_OptNumber});
CScriptInstance *inst = GetInstance(ctx); CScriptInstance * inst = GetInstance(ctx);
CDebuggerUI *debugger = inst->Debugger(); CDebuggerUI * debugger = inst->Debugger();
duk_idx_t nargs = duk_get_top(ctx); duk_idx_t nargs = duk_get_top(ctx);
char* data; char * data;
duk_size_t dataSize, length; duk_size_t dataSize, length;
uint32_t address = duk_get_uint(ctx, 0); uint32_t address = duk_get_uint(ctx, 0);
if (duk_is_buffer_data(ctx, 1)) if (duk_is_buffer_data(ctx, 1))
{ {
data = (char*)duk_get_buffer_data(ctx, 1, &dataSize); data = (char *)duk_get_buffer_data(ctx, 1, &dataSize);
} }
else if(duk_is_string(ctx, 1)) else if (duk_is_string(ctx, 1))
{ {
data = (char*)duk_get_lstring(ctx, 1, &dataSize); data = (char *)duk_get_lstring(ctx, 1, &dataSize);
} }
else else
{ {
@ -262,14 +263,15 @@ duk_ret_t ScriptAPI::js_mem_setblock(duk_context *ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_mem__boundget(duk_context *ctx) duk_ret_t ScriptAPI::js_mem__boundget(duk_context * ctx)
{ {
CDebuggerUI *debugger = GetInstance(ctx)->Debugger(); CDebuggerUI * debugger = GetInstance(ctx)->Debugger();
uint32_t addr = duk_get_uint(ctx, 0); uint32_t addr = duk_get_uint(ctx, 0);
duk_int_t type = duk_get_int(ctx, 1); duk_int_t type = duk_get_int(ctx, 1);
union { union
{
uint8_t u8; uint8_t u8;
uint16_t u16; uint16_t u16;
uint32_t u32; uint32_t u32;
@ -283,8 +285,8 @@ duk_ret_t ScriptAPI::js_mem__boundget(duk_context *ctx)
#define MEM_BOUNDGET_TRY(addr, T, result, dukpush) \ #define MEM_BOUNDGET_TRY(addr, T, result, dukpush) \
if(debugger->DebugLoad_VAddr<T>(addr, result)) { dukpush(ctx, result); } \ if(debugger->DebugLoad_VAddr<T>(addr, result)) { dukpush(ctx, result); } \
else { goto memory_error; } else { goto memory_error; }
switch(type) switch (type)
{ {
case U8: case U8:
MEM_BOUNDGET_TRY(addr, uint8_t, retval.u8, duk_push_uint); MEM_BOUNDGET_TRY(addr, uint8_t, retval.u8, duk_push_uint);
@ -316,9 +318,9 @@ memory_error:
return ThrowMemoryError(ctx, addr); return ThrowMemoryError(ctx, addr);
} }
duk_ret_t ScriptAPI::js_mem__boundset(duk_context *ctx) duk_ret_t ScriptAPI::js_mem__boundset(duk_context * ctx)
{ {
CDebuggerUI *debugger = GetInstance(ctx)->Debugger(); CDebuggerUI * debugger = GetInstance(ctx)->Debugger();
uint32_t addr = duk_get_uint(ctx, 0); uint32_t addr = duk_get_uint(ctx, 0);
duk_int_t type = duk_get_int(ctx, 1); duk_int_t type = duk_get_int(ctx, 1);
@ -327,7 +329,7 @@ duk_ret_t ScriptAPI::js_mem__boundset(duk_context *ctx)
if(debugger->DebugStore_VAddr<T>(addr, value)) { return 1; } \ if(debugger->DebugStore_VAddr<T>(addr, value)) { return 1; } \
else { goto memory_error; } else { goto memory_error; }
switch(type) switch (type)
{ {
case U8: case U8:
MEM_BOUNDSET_TRY(addr, uint8_t, duk_get_uint(ctx, 2) & 0xFF); MEM_BOUNDSET_TRY(addr, uint8_t, duk_get_uint(ctx, 2) & 0xFF);
@ -361,12 +363,12 @@ memory_error:
return ThrowMemoryError(ctx, addr); return ThrowMemoryError(ctx, addr);
} }
duk_ret_t ScriptAPI::js_mem_bindvar(duk_context *ctx) duk_ret_t ScriptAPI::js_mem_bindvar(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Object, Arg_Number, Arg_String, Arg_Number }); CheckArgs(ctx, {Arg_Object, Arg_Number, Arg_String, Arg_Number});
duk_uint_t addr = duk_get_uint(ctx, 1); duk_uint_t addr = duk_get_uint(ctx, 1);
const char* key = duk_get_string(ctx, 2); const char * key = duk_get_string(ctx, 2);
duk_int_t type = duk_get_int(ctx, 3); duk_int_t type = duk_get_int(ctx, 3);
duk_push_string(ctx, key); duk_push_string(ctx, key);
@ -393,17 +395,17 @@ duk_ret_t ScriptAPI::js_mem_bindvar(duk_context *ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_mem_bindvars(duk_context *ctx) duk_ret_t ScriptAPI::js_mem_bindvars(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Object, Arg_Array }); CheckArgs(ctx, {Arg_Object, Arg_Array});
duk_size_t length = duk_get_length(ctx, 1); duk_size_t length = duk_get_length(ctx, 1);
for(duk_uarridx_t i = 0; i < length; i++) for (duk_uarridx_t i = 0; i < length; i++)
{ {
duk_get_prop_index(ctx, 1, i); duk_get_prop_index(ctx, 1, i);
if(!duk_is_array(ctx, -1) || if (!duk_is_array(ctx, -1) ||
duk_get_length(ctx, -1) != 3) duk_get_length(ctx, -1) != 3)
{ {
return DUK_RET_TYPE_ERROR; return DUK_RET_TYPE_ERROR;
} }
@ -414,7 +416,7 @@ duk_ret_t ScriptAPI::js_mem_bindvars(duk_context *ctx)
duk_get_prop_index(ctx, -4, 1); duk_get_prop_index(ctx, -4, 1);
duk_get_prop_index(ctx, -5, 2); duk_get_prop_index(ctx, -5, 2);
if(duk_pcall(ctx, 4) != DUK_EXEC_SUCCESS) if (duk_pcall(ctx, 4) != DUK_EXEC_SUCCESS)
{ {
return duk_throw(ctx); return duk_throw(ctx);
} }
@ -426,15 +428,15 @@ duk_ret_t ScriptAPI::js_mem_bindvars(duk_context *ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_mem_bindstruct(duk_context *ctx) duk_ret_t ScriptAPI::js_mem_bindstruct(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Object, Arg_Number, Arg_Object }); CheckArgs(ctx, {Arg_Object, Arg_Number, Arg_Object});
uint32_t curAddr = duk_get_uint(ctx, 1); uint32_t curAddr = duk_get_uint(ctx, 1);
duk_enum(ctx, 2, DUK_ENUM_OWN_PROPERTIES_ONLY); duk_enum(ctx, 2, DUK_ENUM_OWN_PROPERTIES_ONLY);
while(duk_next(ctx, -1, 1)) while (duk_next(ctx, -1, 1))
{ {
MemType type = (MemType)duk_get_int(ctx, -1); MemType type = (MemType)duk_get_int(ctx, -1);
@ -444,7 +446,7 @@ duk_ret_t ScriptAPI::js_mem_bindstruct(duk_context *ctx)
duk_pull(ctx, -5); duk_pull(ctx, -5);
duk_pull(ctx, -5); duk_pull(ctx, -5);
if(duk_pcall(ctx, 4) != DUK_EXEC_SUCCESS) if (duk_pcall(ctx, 4) != DUK_EXEC_SUCCESS)
{ {
return duk_throw(ctx); return duk_throw(ctx);
} }
@ -459,16 +461,16 @@ duk_ret_t ScriptAPI::js_mem_bindstruct(duk_context *ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_mem__type_constructor(duk_context* ctx) duk_ret_t ScriptAPI::js_mem__type_constructor(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Object, Arg_Number }); CheckArgs(ctx, {Arg_Object, Arg_Number});
duk_push_c_function(ctx, js_mem_bindstruct, 3); duk_push_c_function(ctx, js_mem_bindstruct, 3);
duk_push_this(ctx); duk_push_this(ctx);
duk_pull(ctx, 1); duk_pull(ctx, 1);
duk_pull(ctx, 0); duk_pull(ctx, 0);
if(duk_pcall(ctx, 3) != DUK_EXEC_SUCCESS) if (duk_pcall(ctx, 3) != DUK_EXEC_SUCCESS)
{ {
return duk_throw(ctx); return duk_throw(ctx);
} }
@ -476,9 +478,9 @@ duk_ret_t ScriptAPI::js_mem__type_constructor(duk_context* ctx)
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_mem_typedef(duk_context* ctx) duk_ret_t ScriptAPI::js_mem_typedef(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Object }); CheckArgs(ctx, {Arg_Object});
duk_push_c_function(ctx, js_mem__type_constructor, DUK_VARARGS); duk_push_c_function(ctx, js_mem__type_constructor, DUK_VARARGS);
duk_push_string(ctx, "bind"); duk_push_string(ctx, "bind");
@ -488,19 +490,19 @@ duk_ret_t ScriptAPI::js_mem_typedef(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_mem__get_ramsize(duk_context* ctx) duk_ret_t ScriptAPI::js_mem__get_ramsize(duk_context * ctx)
{ {
duk_push_number(ctx, g_MMU ? g_MMU->RdramSize() : 0); duk_push_number(ctx, g_MMU ? g_MMU->RdramSize() : 0);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_mem__get_romsize(duk_context* ctx) duk_ret_t ScriptAPI::js_mem__get_romsize(duk_context * ctx)
{ {
duk_push_number(ctx, g_Rom ? g_Rom->GetRomSize() : 0); duk_push_number(ctx, g_Rom ? g_Rom->GetRomSize() : 0);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_mem__get_ptr(duk_context* ctx) duk_ret_t ScriptAPI::js_mem__get_ptr(duk_context * ctx)
{ {
duk_push_pointer(ctx, g_MMU ? g_MMU->Rdram() : nullptr); duk_push_pointer(ctx, g_MMU ? g_MMU->Rdram() : nullptr);
return 1; return 1;
@ -508,7 +510,7 @@ duk_ret_t ScriptAPI::js_mem__get_ptr(duk_context* ctx)
size_t MemTypeSize(MemType t) size_t MemTypeSize(MemType t)
{ {
switch(t) switch (t)
{ {
case U8: case U8:
case S8: case S8:
@ -526,7 +528,7 @@ size_t MemTypeSize(MemType t)
return 0; return 0;
} }
duk_ret_t ThrowMemoryError(duk_context* ctx, uint32_t address) duk_ret_t ThrowMemoryError(duk_context * ctx, uint32_t address)
{ {
duk_push_error_object(ctx, DUK_ERR_ERROR, "memory error (can't access 0x%08X)", address); duk_push_error_object(ctx, DUK_ERR_ERROR, "memory error (can't access 0x%08X)", address);
return duk_throw(ctx); return duk_throw(ctx);

View File

@ -1,93 +1,94 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptAPI.h" #include "ScriptAPI.h"
#include <Project64/UserInterface/DiscordRPC.h> #include <Project64/UserInterface/DiscordRPC.h>
#include <Project64/UserInterface/MainWindow.h> #include <Project64/UserInterface/MainWindow.h>
void ScriptAPI::Define_pj64(duk_context* ctx) void ScriptAPI::Define_pj64(duk_context * ctx)
{ {
const DukPropListEntry romInfoProps[] = { const DukPropListEntry romInfoProps[] = {
{ "goodName", DukGetter(js_pj64_romInfo__get_goodName) }, {"goodName", DukGetter(js_pj64_romInfo__get_goodName)},
{ "fileName", DukGetter(js_pj64_romInfo__get_fileName) }, {"fileName", DukGetter(js_pj64_romInfo__get_fileName)},
{ "filePath", DukGetter(js_pj64_romInfo__get_filePath) }, {"filePath", DukGetter(js_pj64_romInfo__get_filePath)},
{ "crc1", DukGetter(js_pj64_romInfo__get_headerCrc1) }, {"crc1", DukGetter(js_pj64_romInfo__get_headerCrc1)},
{ "crc2", DukGetter(js_pj64_romInfo__get_headerCrc2) }, {"crc2", DukGetter(js_pj64_romInfo__get_headerCrc2)},
{ "name", DukGetter(js_pj64_romInfo__get_headerName) }, {"name", DukGetter(js_pj64_romInfo__get_headerName)},
{ "mediaFormat", DukGetter(js_pj64_romInfo__get_headerMediaFormat) }, {"mediaFormat", DukGetter(js_pj64_romInfo__get_headerMediaFormat)},
{ "id", DukGetter(js_pj64_romInfo__get_headerId) }, {"id", DukGetter(js_pj64_romInfo__get_headerId)},
{ "countryCode", DukGetter(js_pj64_romInfo__get_headerCountryCode) }, {"countryCode", DukGetter(js_pj64_romInfo__get_headerCountryCode)},
{ "version", DukGetter(js_pj64_romInfo__get_headerVersion) }, {"version", DukGetter(js_pj64_romInfo__get_headerVersion)},
{ nullptr } { nullptr }
}; };
const DukPropListEntry props[] = { const DukPropListEntry props[] = {
{ "open", DukCFunction(js_pj64_open) }, {"open", DukCFunction(js_pj64_open)},
{ "close", DukCFunction(js_pj64_close) }, {"close", DukCFunction(js_pj64_close)},
{ "reset", DukCFunction(js_pj64_reset) }, {"reset", DukCFunction(js_pj64_reset)},
{ "pause", DukCFunction(js_pj64_pause) }, {"pause", DukCFunction(js_pj64_pause)},
{ "resume", DukCFunction(js_pj64_resume) }, {"resume", DukCFunction(js_pj64_resume)},
{ "limitfps", DukCFunction(js_pj64_limitfps) }, {"limitfps", DukCFunction(js_pj64_limitfps)},
//{ "savestate", DukCFunction(js_pj64_savestate) }, //{ "savestate", DukCFunction(js_pj64_savestate) },
//{ "loadstate", DukCFunction(js_pj64_loadstate) }, //{ "loadstate", DukCFunction(js_pj64_loadstate) },
{ "installDirectory", DukGetter(js_pj64__get_installDirectory) }, {"installDirectory", DukGetter(js_pj64__get_installDirectory)},
{ "scriptsDirectory", DukGetter(js_pj64__get_scriptsDirectory) }, {"scriptsDirectory", DukGetter(js_pj64__get_scriptsDirectory)},
{ "modulesDirectory", DukGetter(js_pj64__get_modulesDirectory) }, {"modulesDirectory", DukGetter(js_pj64__get_modulesDirectory)},
{ "romDirectory", DukGetter(js_pj64__get_romDirectory) }, {"romDirectory", DukGetter(js_pj64__get_romDirectory)},
{ DUK_HIDDEN_SYMBOL("romInfo"), DukObject(romInfoProps) }, {DUK_HIDDEN_SYMBOL("romInfo"), DukObject(romInfoProps)},
{ "romInfo", DukGetter(js_pj64__get_romInfo) }, {"romInfo", DukGetter(js_pj64__get_romInfo)},
{ nullptr } { nullptr }
}; };
DefineGlobalInterface(ctx, "pj64", props); DefineGlobalInterface(ctx, "pj64", props);
} }
duk_ret_t ScriptAPI::js_pj64_open(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_open(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_String }); CheckArgs(ctx, {Arg_String});
const char* romPath = duk_get_string(ctx, 0); const char * romPath = duk_get_string(ctx, 0);
HWND hMainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle(); HWND hMainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle();
char* romPathCopy = new char[MAX_PATH]; // main window proc deletes char * romPathCopy = new char[MAX_PATH]; // main window proc deletes
strncpy(romPathCopy, romPath, MAX_PATH); strncpy(romPathCopy, romPath, MAX_PATH);
PostMessage(hMainWindow, WM_JSAPI_ACTION, JSAPI_ACT_OPEN_ROM, (WPARAM)romPath); PostMessage(hMainWindow, WM_JSAPI_ACTION, JSAPI_ACT_OPEN_ROM, (WPARAM)romPath);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_pj64_close(duk_context* /*ctx*/) duk_ret_t ScriptAPI::js_pj64_close(duk_context * /*ctx*/)
{ {
HWND hMainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle(); HWND hMainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle();
PostMessage(hMainWindow, WM_JSAPI_ACTION, JSAPI_ACT_CLOSE_ROM, 0); PostMessage(hMainWindow, WM_JSAPI_ACTION, JSAPI_ACT_CLOSE_ROM, 0);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_pj64_reset(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_reset(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_OptBoolean }); CheckArgs(ctx, {Arg_OptBoolean});
bool bSoftReset = (bool)duk_get_boolean_default(ctx, 0, (duk_bool_t)false); bool bSoftReset = (bool)duk_get_boolean_default(ctx, 0, (duk_bool_t) false);
HWND hMainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle(); HWND hMainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle();
PostMessage(hMainWindow, WM_JSAPI_ACTION, JSAPI_ACT_RESET, (WPARAM)bSoftReset); PostMessage(hMainWindow, WM_JSAPI_ACTION, JSAPI_ACT_RESET, (WPARAM)bSoftReset);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_pj64_pause(duk_context* /*ctx*/) duk_ret_t ScriptAPI::js_pj64_pause(duk_context * /*ctx*/)
{ {
HWND hMainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle(); HWND hMainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle();
PostMessage(hMainWindow, WM_JSAPI_ACTION, JSAPI_ACT_PAUSE, 0); PostMessage(hMainWindow, WM_JSAPI_ACTION, JSAPI_ACT_PAUSE, 0);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_pj64_resume(duk_context* /*ctx*/) duk_ret_t ScriptAPI::js_pj64_resume(duk_context * /*ctx*/)
{ {
HWND hMainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle(); HWND hMainWindow = (HWND)g_Plugins->MainWindow()->GetWindowHandle();
PostMessage(hMainWindow, WM_JSAPI_ACTION, JSAPI_ACT_RESUME, 0); PostMessage(hMainWindow, WM_JSAPI_ACTION, JSAPI_ACT_RESUME, 0);
return 0; return 0;
} }
duk_ret_t ScriptAPI::js_pj64_limitfps(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_limitfps(duk_context * ctx)
{ {
CheckArgs(ctx, { Arg_Boolean }); CheckArgs(ctx, {Arg_Boolean});
bool bLimitFps = duk_get_boolean(ctx, 0); bool bLimitFps = duk_get_boolean(ctx, 0);
g_Settings->SaveBool(GameRunning_LimitFPS, bLimitFps); g_Settings->SaveBool(GameRunning_LimitFPS, bLimitFps);
return 0; return 0;
@ -117,21 +118,21 @@ duk_ret_t ScriptAPI::js_pj64_loadstate(duk_context* ctx)
} }
*/ */
duk_ret_t ScriptAPI::js_pj64__get_installDirectory(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64__get_installDirectory(duk_context * ctx)
{ {
stdstr dirPath = GetInstance(ctx)->System()->InstallDirPath(); stdstr dirPath = GetInstance(ctx)->System()->InstallDirPath();
duk_push_string(ctx, dirPath.c_str()); duk_push_string(ctx, dirPath.c_str());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64__get_scriptsDirectory(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64__get_scriptsDirectory(duk_context * ctx)
{ {
stdstr dirPath = GetInstance(ctx)->System()->ScriptsDirPath(); stdstr dirPath = GetInstance(ctx)->System()->ScriptsDirPath();
duk_push_string(ctx, dirPath.c_str()); duk_push_string(ctx, dirPath.c_str());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64__get_modulesDirectory(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64__get_modulesDirectory(duk_context * ctx)
{ {
stdstr dirPath = GetInstance(ctx)->System()->ModulesDirPath(); stdstr dirPath = GetInstance(ctx)->System()->ModulesDirPath();
duk_push_string(ctx, dirPath.c_str()); duk_push_string(ctx, dirPath.c_str());
@ -144,7 +145,7 @@ duk_ret_t ScriptAPI::js_pj64__get_romDirectory(duk_context * ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64__get_romInfo(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64__get_romInfo(duk_context * ctx)
{ {
if (g_Settings->LoadStringVal(Game_GameName) != "") if (g_Settings->LoadStringVal(Game_GameName) != "")
{ {
@ -158,45 +159,45 @@ duk_ret_t ScriptAPI::js_pj64__get_romInfo(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64_romInfo__get_goodName(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_romInfo__get_goodName(duk_context * ctx)
{ {
duk_push_string(ctx, g_Settings->LoadStringVal(Rdb_GoodName).c_str()); duk_push_string(ctx, g_Settings->LoadStringVal(Rdb_GoodName).c_str());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64_romInfo__get_fileName(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_romInfo__get_fileName(duk_context * ctx)
{ {
duk_push_string(ctx, CPath(g_Settings->LoadStringVal(Game_File)).GetNameExtension().c_str()); duk_push_string(ctx, CPath(g_Settings->LoadStringVal(Game_File)).GetNameExtension().c_str());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64_romInfo__get_filePath(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_romInfo__get_filePath(duk_context * ctx)
{ {
duk_push_string(ctx, g_Settings->LoadStringVal(Game_File).c_str()); duk_push_string(ctx, g_Settings->LoadStringVal(Game_File).c_str());
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerCrc1(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerCrc1(duk_context * ctx)
{ {
CDebuggerUI* debugger = GetInstance(ctx)->Debugger(); CDebuggerUI * debugger = GetInstance(ctx)->Debugger();
uint32_t crc1 = 0; uint32_t crc1 = 0;
debugger->DebugLoad_VAddr<uint32_t>(0xB0000010, crc1); debugger->DebugLoad_VAddr<uint32_t>(0xB0000010, crc1);
duk_push_uint(ctx, crc1); duk_push_uint(ctx, crc1);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerCrc2(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerCrc2(duk_context * ctx)
{ {
CDebuggerUI* debugger = GetInstance(ctx)->Debugger(); CDebuggerUI * debugger = GetInstance(ctx)->Debugger();
uint32_t crc2 = 0; uint32_t crc2 = 0;
debugger->DebugLoad_VAddr<uint32_t>(0xB0000014, crc2); debugger->DebugLoad_VAddr<uint32_t>(0xB0000014, crc2);
duk_push_uint(ctx, crc2); duk_push_uint(ctx, crc2);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerName(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerName(duk_context * ctx)
{ {
CDebuggerUI* debugger = GetInstance(ctx)->Debugger(); CDebuggerUI * debugger = GetInstance(ctx)->Debugger();
char headerName[0x15] = ""; char headerName[0x15] = "";
for (size_t i = 0; i < 0x14; i++) for (size_t i = 0; i < 0x14; i++)
{ {
@ -207,18 +208,18 @@ duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerName(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerMediaFormat(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerMediaFormat(duk_context * ctx)
{ {
CDebuggerUI* debugger = GetInstance(ctx)->Debugger(); CDebuggerUI * debugger = GetInstance(ctx)->Debugger();
uint32_t mediaFormat = 0; uint32_t mediaFormat = 0;
debugger->DebugLoad_VAddr<uint32_t>(0xB0000038, mediaFormat); debugger->DebugLoad_VAddr<uint32_t>(0xB0000038, mediaFormat);
duk_push_uint(ctx, mediaFormat); duk_push_uint(ctx, mediaFormat);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerId(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerId(duk_context * ctx)
{ {
CDebuggerUI* debugger = GetInstance(ctx)->Debugger(); CDebuggerUI * debugger = GetInstance(ctx)->Debugger();
char headerId[3] = ""; char headerId[3] = "";
debugger->DebugLoad_VAddr<char>(0xB000003C, headerId[0]); debugger->DebugLoad_VAddr<char>(0xB000003C, headerId[0]);
debugger->DebugLoad_VAddr<char>(0xB000003D, headerId[1]); debugger->DebugLoad_VAddr<char>(0xB000003D, headerId[1]);
@ -226,18 +227,18 @@ duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerId(duk_context* ctx)
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerCountryCode(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerCountryCode(duk_context * ctx)
{ {
CDebuggerUI* debugger = GetInstance(ctx)->Debugger(); CDebuggerUI * debugger = GetInstance(ctx)->Debugger();
char countryCode[2] = ""; char countryCode[2] = "";
debugger->DebugLoad_VAddr<char>(0xB000003E, countryCode[0]); debugger->DebugLoad_VAddr<char>(0xB000003E, countryCode[0]);
duk_push_string(ctx, countryCode); duk_push_string(ctx, countryCode);
return 1; return 1;
} }
duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerVersion(duk_context* ctx) duk_ret_t ScriptAPI::js_pj64_romInfo__get_headerVersion(duk_context * ctx)
{ {
CDebuggerUI* debugger = GetInstance(ctx)->Debugger(); CDebuggerUI * debugger = GetInstance(ctx)->Debugger();
uint8_t headerVersion = 0; uint8_t headerVersion = 0;
debugger->DebugLoad_VAddr<uint8_t>(0xB000003F, headerVersion); debugger->DebugLoad_VAddr<uint8_t>(0xB000003F, headerVersion);
duk_push_uint(ctx, headerVersion); duk_push_uint(ctx, headerVersion);

View File

@ -1,18 +1,20 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptTypes.h"
#include "ScriptInstance.h"
#include "ScriptAPI/ScriptAPI.h" #include "ScriptAPI/ScriptAPI.h"
#include "ScriptInstance.h"
#include "ScriptTypes.h"
#include <sys/stat.h> #include <sys/stat.h>
extern "C" { extern "C"
int DukTimeoutCheck(void* udata) {
int DukTimeoutCheck(void * udata)
{ {
CScriptInstance* inst = (CScriptInstance*)udata; CScriptInstance * inst = (CScriptInstance *)udata;
return (int)inst->IsTimedOut(); return (int)inst->IsTimedOut();
} }
} }
CScriptInstance::CScriptInstance(CScriptSystem* sys, const char* name) : CScriptInstance::CScriptInstance(CScriptSystem * sys, const char * name) :
m_System(sys), m_System(sys),
m_InstanceName(name), m_InstanceName(name),
m_Ctx(nullptr), m_Ctx(nullptr),
@ -31,17 +33,17 @@ CScriptInstance::~CScriptInstance()
Cleanup(); Cleanup();
} }
std::string& CScriptInstance::Name() std::string & CScriptInstance::Name()
{ {
return m_InstanceName; return m_InstanceName;
} }
CScriptSystem* CScriptInstance::System() CScriptSystem * CScriptInstance::System()
{ {
return m_System; return m_System;
} }
CDebuggerUI* CScriptInstance::Debugger() CDebuggerUI * CScriptInstance::Debugger()
{ {
return m_System->Debugger(); return m_System->Debugger();
} }
@ -51,22 +53,22 @@ JSAppCallbackID CScriptInstance::CallbackId()
return m_CurExecCallbackId; return m_CurExecCallbackId;
} }
bool CScriptInstance::Run(const char* path) bool CScriptInstance::Run(const char * path)
{ {
if(m_Ctx != nullptr) if (m_Ctx != nullptr)
{ {
return false; return false;
} }
m_Ctx = duk_create_heap(nullptr, nullptr, nullptr, this, nullptr); m_Ctx = duk_create_heap(nullptr, nullptr, nullptr, this, nullptr);
if(m_Ctx == nullptr) if (m_Ctx == nullptr)
{ {
goto error_cleanup; goto error_cleanup;
} }
struct stat statBuf; struct stat statBuf;
if(stat(path, &statBuf) != 0) if (stat(path, &statBuf) != 0)
{ {
m_System->ConsoleLog("[SCRIPTSYS]: error: could not stat '%s'", path); m_System->ConsoleLog("[SCRIPTSYS]: error: could not stat '%s'", path);
goto error_cleanup; goto error_cleanup;
@ -76,7 +78,7 @@ bool CScriptInstance::Run(const char* path)
m_SourceCode[statBuf.st_size] = '\0'; m_SourceCode[statBuf.st_size] = '\0';
m_SourceFile.open(path, std::ios::in | std::ios::binary); m_SourceFile.open(path, std::ios::in | std::ios::binary);
if(!m_SourceFile.is_open()) if (!m_SourceFile.is_open())
{ {
m_System->ConsoleLog("[SCRIPTSYS]: error: could not open '%s'", path); m_System->ConsoleLog("[SCRIPTSYS]: error: could not open '%s'", path);
goto error_cleanup; goto error_cleanup;
@ -84,7 +86,7 @@ bool CScriptInstance::Run(const char* path)
m_SourceFile.read(m_SourceCode, statBuf.st_size); m_SourceFile.read(m_SourceCode, statBuf.st_size);
if((size_t)m_SourceFile.tellg() != (size_t)statBuf.st_size) if ((size_t)m_SourceFile.tellg() != (size_t)statBuf.st_size)
{ {
m_System->ConsoleLog("[SCRIPTSYS]: error: could not read '%s'", path); m_System->ConsoleLog("[SCRIPTSYS]: error: could not read '%s'", path);
goto error_cleanup; goto error_cleanup;
@ -108,13 +110,12 @@ bool CScriptInstance::Run(const char* path)
duk_pop(m_Ctx); duk_pop(m_Ctx);
} }
catch (std::runtime_error& exc) catch (std::runtime_error & exc)
{ {
FatalHandler(exc); FatalHandler(exc);
} }
return true; return true;
error_cleanup: error_cleanup:
Cleanup(); Cleanup();
@ -128,7 +129,7 @@ void CScriptInstance::IncRefCount()
void CScriptInstance::DecRefCount() void CScriptInstance::DecRefCount()
{ {
if(m_RefCount > 0) if (m_RefCount > 0)
{ {
m_RefCount--; m_RefCount--;
} }
@ -150,7 +151,7 @@ bool CScriptInstance::PrepareAbort()
return false; return false;
} }
void CScriptInstance::RawCMethodCall(void* dukThisHeapPtr, duk_c_function func, JSDukArgSetupFunc argSetupFunc, void *argSetupParam) void CScriptInstance::RawCMethodCall(void * dukThisHeapPtr, duk_c_function func, JSDukArgSetupFunc argSetupFunc, void * argSetupParam)
{ {
try try
{ {
@ -168,22 +169,22 @@ void CScriptInstance::RawCMethodCall(void* dukThisHeapPtr, duk_c_function func,
duk_pop(m_Ctx); duk_pop(m_Ctx);
} }
catch (std::runtime_error& exc) catch (std::runtime_error & exc)
{ {
FatalHandler(exc); FatalHandler(exc);
} }
} }
void CScriptInstance::PostCMethodCall(void* dukThisHeapPtr, duk_c_function func, JSDukArgSetupFunc argSetupFunc, void CScriptInstance::PostCMethodCall(void * dukThisHeapPtr, duk_c_function func, JSDukArgSetupFunc argSetupFunc,
void* argSetupParam, size_t argSetupParamSize) void * argSetupParam, size_t argSetupParamSize)
{ {
m_System->PostCMethodCall(m_InstanceName.c_str(), dukThisHeapPtr, func, argSetupFunc, argSetupParam, argSetupParamSize); m_System->PostCMethodCall(m_InstanceName.c_str(), dukThisHeapPtr, func, argSetupFunc, argSetupParam, argSetupParamSize);
} }
void CScriptInstance::RawConsoleInput(const char* code) void CScriptInstance::RawConsoleInput(const char * code)
{ {
m_System->ConsoleLog("> %s", code); m_System->ConsoleLog("> %s", code);
try try
{ {
duk_get_global_string(m_Ctx, HS_gInputListener); duk_get_global_string(m_Ctx, HS_gInputListener);
@ -234,8 +235,8 @@ void CScriptInstance::RawConsoleInput(const char* code)
duk_push_int(m_Ctx, 2); duk_push_int(m_Ctx, 2);
duk_pcall(m_Ctx, 3); duk_pcall(m_Ctx, 3);
const char* str = duk_safe_to_string(m_Ctx, -2); const char * str = duk_safe_to_string(m_Ctx, -2);
const char* res = duk_get_string(m_Ctx, -1); const char * res = duk_get_string(m_Ctx, -1);
m_System->ConsoleLog("%s %s", str, res); m_System->ConsoleLog("%s %s", str, res);
duk_pop(m_Ctx); duk_pop(m_Ctx);
@ -247,7 +248,7 @@ void CScriptInstance::RawConsoleInput(const char* code)
} }
duk_pop(m_Ctx); duk_pop(m_Ctx);
} }
catch (std::runtime_error& exc) catch (std::runtime_error & exc)
{ {
FatalHandler(exc); FatalHandler(exc);
} }
@ -260,7 +261,7 @@ void CScriptInstance::SetExecTimeout(uint64_t timeout)
bool CScriptInstance::IsTimedOut() bool CScriptInstance::IsTimedOut()
{ {
if(m_ExecStartTime == 0 || m_ExecTimeout == 0) if (m_ExecStartTime == 0 || m_ExecTimeout == 0)
{ {
return false; return false;
} }
@ -283,23 +284,23 @@ uint64_t CScriptInstance::Timestamp()
void CScriptInstance::Cleanup() void CScriptInstance::Cleanup()
{ {
if(m_Ctx != nullptr) if (m_Ctx != nullptr)
{ {
duk_destroy_heap(m_Ctx); duk_destroy_heap(m_Ctx);
m_Ctx = nullptr; m_Ctx = nullptr;
} }
if(m_SourceCode != nullptr) if (m_SourceCode != nullptr)
{ {
delete[] m_SourceCode; delete[] m_SourceCode;
m_SourceCode = nullptr; m_SourceCode = nullptr;
} }
if(m_SourceFile.is_open()) if (m_SourceFile.is_open())
{ {
m_SourceFile.close(); m_SourceFile.close();
} }
} }
bool CScriptInstance::RegisterWorker(CScriptWorker* worker) bool CScriptInstance::RegisterWorker(CScriptWorker * worker)
{ {
if (IsStopping()) if (IsStopping())
{ {
@ -310,9 +311,9 @@ bool CScriptInstance::RegisterWorker(CScriptWorker* worker)
return true; return true;
} }
void CScriptInstance::UnregisterWorker(CScriptWorker* worker) void CScriptInstance::UnregisterWorker(CScriptWorker * worker)
{ {
std::vector<CScriptWorker*>::iterator it; std::vector<CScriptWorker *>::iterator it;
for (it = m_Workers.begin(); it != m_Workers.end(); it++) for (it = m_Workers.begin(); it != m_Workers.end(); it++)
{ {
@ -326,15 +327,15 @@ void CScriptInstance::UnregisterWorker(CScriptWorker* worker)
void CScriptInstance::StopRegisteredWorkers() void CScriptInstance::StopRegisteredWorkers()
{ {
std::vector<CScriptWorker*>::iterator it; std::vector<CScriptWorker *>::iterator it;
for (it = m_Workers.begin(); it != m_Workers.end(); it++) for (it = m_Workers.begin(); it != m_Workers.end(); it++)
{ {
CScriptWorker* worker = *it; CScriptWorker * worker = *it;
worker->StopWorkerProc(); worker->StopWorkerProc();
} }
} }
void CScriptInstance::FatalHandler(std::runtime_error& exc) void CScriptInstance::FatalHandler(std::runtime_error & exc)
{ {
if (m_bAborting) if (m_bAborting)
{ {

View File

@ -1,14 +1,15 @@
#include <stdafx.h> #include "stdafx.h"
#include <sys/stat.h>
#include <sstream>
#include "ScriptTypes.h"
#include "ScriptSystem.h"
#include "ScriptInstance.h"
#include "ScriptAPI/ScriptAPI.h"
#include "Debugger.h" #include "Debugger.h"
#include "Project64\UserInterface\DiscordRPC.h" #include "Project64\UserInterface\DiscordRPC.h"
#include "ScriptAPI/ScriptAPI.h"
#include "ScriptInstance.h"
#include "ScriptSystem.h"
#include "ScriptTypes.h"
#include <sstream>
#include <sys/stat.h>
CScriptSystem::CScriptSystem(CDebuggerUI *debugger) : CScriptSystem::CScriptSystem(CDebuggerUI * debugger) :
m_Debugger(debugger), m_Debugger(debugger),
m_NextAppCallbackId(0), m_NextAppCallbackId(0),
m_AppCallbackCount(0), m_AppCallbackCount(0),
@ -30,7 +31,7 @@ CScriptSystem::~CScriptSystem()
CloseHandle(m_hCmdEvent); CloseHandle(m_hCmdEvent);
} }
JSInstanceStatus CScriptSystem::GetStatus(const char* name) JSInstanceStatus CScriptSystem::GetStatus(const char * name)
{ {
CGuard guard(m_UIStateCS); CGuard guard(m_UIStateCS);
if (m_UIInstanceStatus.count(name) == 0) if (m_UIInstanceStatus.count(name) == 0)
@ -43,7 +44,7 @@ JSInstanceStatus CScriptSystem::GetStatus(const char* name)
} }
} }
void CScriptSystem::NotifyStatus(const char* name, JSInstanceStatus status) void CScriptSystem::NotifyStatus(const char * name, JSInstanceStatus status)
{ {
CGuard guard(m_UIStateCS); CGuard guard(m_UIStateCS);
if (status == JS_STATUS_STOPPED) if (status == JS_STATUS_STOPPED)
@ -57,7 +58,7 @@ void CScriptSystem::NotifyStatus(const char* name, JSInstanceStatus status)
m_Debugger->Debug_RefreshScriptsWindow(); m_Debugger->Debug_RefreshScriptsWindow();
} }
void CScriptSystem::ConsoleLog(const char* format, ...) void CScriptSystem::ConsoleLog(const char * format, ...)
{ {
CGuard guard(m_UIStateCS); CGuard guard(m_UIStateCS);
@ -65,11 +66,11 @@ void CScriptSystem::ConsoleLog(const char* format, ...)
va_start(args, format); va_start(args, format);
int size = vsnprintf(nullptr, 0, format, args) + 1; int size = vsnprintf(nullptr, 0, format, args) + 1;
char* str = new char[size]; char * str = new char[size];
vsnprintf(str, size, format, args); vsnprintf(str, size, format, args);
stdstr formattedMsg = FixStringReturns(str) + "\r\n"; stdstr formattedMsg = FixStringReturns(str) + "\r\n";
m_Debugger->Debug_LogScriptsWindow(formattedMsg.c_str()); m_Debugger->Debug_LogScriptsWindow(formattedMsg.c_str());
m_UILog += formattedMsg; m_UILog += formattedMsg;
@ -77,7 +78,7 @@ void CScriptSystem::ConsoleLog(const char* format, ...)
va_end(args); va_end(args);
} }
void CScriptSystem::ConsolePrint(const char* format, ...) void CScriptSystem::ConsolePrint(const char * format, ...)
{ {
CGuard guard(m_UIStateCS); CGuard guard(m_UIStateCS);
@ -85,11 +86,11 @@ void CScriptSystem::ConsolePrint(const char* format, ...)
va_start(args, format); va_start(args, format);
int size = vsnprintf(nullptr, 0, format, args) + 1; int size = vsnprintf(nullptr, 0, format, args) + 1;
char* str = new char[size]; char * str = new char[size];
vsnprintf(str, size, format, args); vsnprintf(str, size, format, args);
stdstr formattedMsg = FixStringReturns(str); stdstr formattedMsg = FixStringReturns(str);
m_Debugger->Debug_LogScriptsWindow(formattedMsg.c_str()); m_Debugger->Debug_LogScriptsWindow(formattedMsg.c_str());
m_UILog += formattedMsg; m_UILog += formattedMsg;
@ -142,17 +143,17 @@ void CScriptSystem::InitDirectories()
} }
} }
void CScriptSystem::StartScript(const char *name, const char *path) void CScriptSystem::StartScript(const char * name, const char * path)
{ {
PostCommand(JS_CMD_START_SCRIPT, name, path); PostCommand(JS_CMD_START_SCRIPT, name, path);
} }
void CScriptSystem::StopScript(const char *name) void CScriptSystem::StopScript(const char * name)
{ {
PostCommand(JS_CMD_STOP_SCRIPT, name); PostCommand(JS_CMD_STOP_SCRIPT, name);
} }
void CScriptSystem::Input(const char *name, const char *code) void CScriptSystem::Input(const char * name, const char * code)
{ {
PostCommand(JS_CMD_INPUT, name, code); PostCommand(JS_CMD_INPUT, name, code);
} }
@ -165,19 +166,19 @@ bool CScriptSystem::HaveAppCallbacks(JSAppHookID hookId)
m_AppCallbackHooks[hookId].size() > 0); m_AppCallbackHooks[hookId].size() > 0);
} }
void CScriptSystem::InvokeAppCallbacks(JSAppHookID hookId, void* env) void CScriptSystem::InvokeAppCallbacks(JSAppHookID hookId, void * env)
{ {
CGuard guard(m_InstancesCS); CGuard guard(m_InstancesCS);
JSAppCallbackList& callbacks = m_AppCallbackHooks[hookId]; JSAppCallbackList & callbacks = m_AppCallbackHooks[hookId];
size_t numCallbacks = callbacks.size(); size_t numCallbacks = callbacks.size();
bool bNeedSweep = false; bool bNeedSweep = false;
for (size_t i = 0; i < numCallbacks; i++) for (size_t i = 0; i < numCallbacks; i++)
{ {
JSAppCallback& callback = callbacks[i]; JSAppCallback & callback = callbacks[i];
CScriptInstance* instance = callback.m_Instance; CScriptInstance * instance = callback.m_Instance;
if (callback.m_bDisabled || if (callback.m_bDisabled ||
instance->IsStopping() || instance->IsStopping() ||
@ -201,14 +202,14 @@ void CScriptSystem::InvokeAppCallbacks(JSAppHookID hookId, void* env)
} }
} }
void CScriptSystem::UpdateCpuCbListInfo(volatile JSCpuCbListInfo& info, JSAppCallbackList& callbacks) void CScriptSystem::UpdateCpuCbListInfo(volatile JSCpuCbListInfo & info, JSAppCallbackList & callbacks)
{ {
uint32_t minAddrStart = 0; uint32_t minAddrStart = 0;
uint32_t maxAddrEnd = 0; uint32_t maxAddrEnd = 0;
int numCacheEntries = 0; int numCacheEntries = 0;
bool bCacheExceeded = false; bool bCacheExceeded = false;
for (JSAppCallback& callback : callbacks) for (JSAppCallback & callback : callbacks)
{ {
size_t i; size_t i;
for (i = 0; i < numCacheEntries; i++) for (i = 0; i < numCacheEntries; i++)
@ -238,7 +239,7 @@ void CScriptSystem::UpdateCpuCbListInfo(volatile JSCpuCbListInfo& info, JSAppCal
numCacheEntries++; numCacheEntries++;
} }
} }
if (callback.m_Params.addrStart < minAddrStart) if (callback.m_Params.addrStart < minAddrStart)
{ {
minAddrStart = callback.m_Params.addrStart; minAddrStart = callback.m_Params.addrStart;
@ -259,7 +260,7 @@ void CScriptSystem::UpdateCpuCbListInfo(volatile JSCpuCbListInfo& info, JSAppCal
void CScriptSystem::RefreshCallbackMaps() void CScriptSystem::RefreshCallbackMaps()
{ {
for (JSAppCallbackList& callbacks : m_AppCallbackHooks) for (JSAppCallbackList & callbacks : m_AppCallbackHooks)
{ {
JSAppCallbackList::iterator it = callbacks.begin(); JSAppCallbackList::iterator it = callbacks.begin();
@ -301,23 +302,23 @@ void CScriptSystem::DoMouseEvent(JSAppHookID hookId, int x, int y, DWORD uMsg)
break; break;
} }
JSHookMouseEnv env = { x, y, button }; JSHookMouseEnv env = {x, y, button};
InvokeAppCallbacks(hookId, (void*)&env); InvokeAppCallbacks(hookId, (void *)&env);
} }
void CScriptSystem::PostCMethodCall(const char* name, void *dukThisHeapPtr, duk_c_function func, void CScriptSystem::PostCMethodCall(const char * name, void * dukThisHeapPtr, duk_c_function func,
JSDukArgSetupFunc argSetupFunc, void *argSetupParam, size_t argSetupParamSize) JSDukArgSetupFunc argSetupFunc, void * argSetupParam, size_t argSetupParamSize)
{ {
CGuard guard(m_CmdQueueCS); CGuard guard(m_CmdQueueCS);
// Will be deleted by command handler // Will be deleted by command handler
JSSysCMethodCall* methodCall = new JSSysCMethodCall(dukThisHeapPtr, func, argSetupFunc, argSetupParam, argSetupParamSize); JSSysCMethodCall * methodCall = new JSSysCMethodCall(dukThisHeapPtr, func, argSetupFunc, argSetupParam, argSetupParamSize);
PostCommand(JS_CMD_C_METHOD_CALL, name, "", (void*)methodCall); PostCommand(JS_CMD_C_METHOD_CALL, name, "", (void *)methodCall);
} }
void CScriptSystem::PostCommand(JSSysCommandID id, stdstr paramA, stdstr paramB, void* paramC) void CScriptSystem::PostCommand(JSSysCommandID id, stdstr paramA, stdstr paramB, void * paramC)
{ {
CGuard guard(m_CmdQueueCS); CGuard guard(m_CmdQueueCS);
JSSysCommand cmd = { id, paramA, paramB, paramC }; JSSysCommand cmd = {id, paramA, paramB, paramC};
if (id == JS_CMD_STOP_SCRIPT) if (id == JS_CMD_STOP_SCRIPT)
{ {
@ -336,7 +337,7 @@ void CScriptSystem::PostCommand(JSSysCommandID id, stdstr paramA, stdstr paramB,
SetEvent(m_hCmdEvent); SetEvent(m_hCmdEvent);
} }
DWORD CScriptSystem::ThreadProc(void *_this) DWORD CScriptSystem::ThreadProc(void * _this)
{ {
((CScriptSystem *)_this)->ThreadProc(); ((CScriptSystem *)_this)->ThreadProc();
return 0; return 0;
@ -346,7 +347,7 @@ void CScriptSystem::ThreadProc()
{ {
std::vector<JSSysCommand> queue; std::vector<JSSysCommand> queue;
while(true) while (true)
{ {
WaitForSingleObject(m_hCmdEvent, INFINITE); WaitForSingleObject(m_hCmdEvent, INFINITE);
@ -363,18 +364,18 @@ void CScriptSystem::ThreadProc()
} }
} }
void CScriptSystem::OnStartScript(const char *name, const char *path) void CScriptSystem::OnStartScript(const char * name, const char * path)
{ {
if (m_Instances.count(name) != 0) if (m_Instances.count(name) != 0)
{ {
ConsoleLog("[SCRIPTSYS]: error: START_SCRIPT aborted; '%s' is already instanced", name); ConsoleLog("[SCRIPTSYS]: error: START_SCRIPT aborted; '%s' is already instanced", name);
} }
CScriptInstance *inst = new CScriptInstance(this, name); CScriptInstance * inst = new CScriptInstance(this, name);
NotifyStatus(name, JS_STATUS_STARTING); NotifyStatus(name, JS_STATUS_STARTING);
if(inst->Run(path) && inst->GetRefCount() > 0) if (inst->Run(path) && inst->GetRefCount() > 0)
{ {
m_Instances[name] = inst; m_Instances[name] = inst;
NotifyStatus(name, JS_STATUS_STARTED); NotifyStatus(name, JS_STATUS_STARTED);
@ -386,7 +387,7 @@ void CScriptSystem::OnStartScript(const char *name, const char *path)
} }
} }
void CScriptSystem::OnStopScript(const char *name) void CScriptSystem::OnStopScript(const char * name)
{ {
if (m_Instances.count(name) == 0) if (m_Instances.count(name) == 0)
{ {
@ -399,26 +400,26 @@ void CScriptSystem::OnStopScript(const char *name)
NotifyStatus(name, JS_STATUS_STOPPED); NotifyStatus(name, JS_STATUS_STOPPED);
} }
void CScriptSystem::OnInput(const char *name, const char *code) void CScriptSystem::OnInput(const char * name, const char * code)
{ {
if(m_Instances.count(name) == 0) if (m_Instances.count(name) == 0)
{ {
ConsoleLog("[SCRIPTSYS]: error: INPUT aborted; instance '%s' does not exist", name); ConsoleLog("[SCRIPTSYS]: error: INPUT aborted; instance '%s' does not exist", name);
return; return;
} }
CScriptInstance* inst = m_Instances[name]; CScriptInstance * inst = m_Instances[name];
inst->RawConsoleInput(code); inst->RawConsoleInput(code);
if(!inst->IsStopping() && inst->GetRefCount() == 0) if (!inst->IsStopping() && inst->GetRefCount() == 0)
{ {
NotifyStatus(name, JS_STATUS_STOPPED); NotifyStatus(name, JS_STATUS_STOPPED);
RawRemoveInstance(name); RawRemoveInstance(name);
} }
} }
void CScriptSystem::OnCMethodCall(const char *name, JSSysCMethodCall* methodCall) void CScriptSystem::OnCMethodCall(const char * name, JSSysCMethodCall * methodCall)
{ {
if (m_Instances.count(name) == 0) if (m_Instances.count(name) == 0)
{ {
@ -430,7 +431,7 @@ void CScriptSystem::OnCMethodCall(const char *name, JSSysCMethodCall* methodCall
return; return;
} }
CScriptInstance* inst = m_Instances[name]; CScriptInstance * inst = m_Instances[name];
inst->RawCMethodCall(methodCall->m_DukThisHeapPtr, methodCall->m_Func, methodCall->m_ArgSetupFunc, methodCall->m_ArgSetupParam); inst->RawCMethodCall(methodCall->m_DukThisHeapPtr, methodCall->m_Func, methodCall->m_ArgSetupFunc, methodCall->m_ArgSetupParam);
@ -444,10 +445,10 @@ void CScriptSystem::OnCMethodCall(const char *name, JSSysCMethodCall* methodCall
void CScriptSystem::OnSweep(bool bIfDone) void CScriptSystem::OnSweep(bool bIfDone)
{ {
JSInstanceMap::iterator it = m_Instances.begin(); JSInstanceMap::iterator it = m_Instances.begin();
while(it != m_Instances.end()) while (it != m_Instances.end())
{ {
CScriptInstance*& inst = it->second; CScriptInstance *& inst = it->second;
if(!bIfDone || inst->GetRefCount() == 0) if (!bIfDone || inst->GetRefCount() == 0)
{ {
NotifyStatus(inst->Name().c_str(), JS_STATUS_STOPPED); NotifyStatus(inst->Name().c_str(), JS_STATUS_STOPPED);
delete inst; delete inst;
@ -460,14 +461,14 @@ void CScriptSystem::OnSweep(bool bIfDone)
} }
} }
bool CScriptSystem::RawRemoveInstance(const char *name) bool CScriptSystem::RawRemoveInstance(const char * name)
{ {
if(m_Instances.count(name) == 0) if (m_Instances.count(name) == 0)
{ {
return false; return false;
} }
CScriptInstance*& inst = m_Instances[name]; CScriptInstance *& inst = m_Instances[name];
if (inst->IsStopping()) if (inst->IsStopping())
{ {
@ -476,7 +477,7 @@ bool CScriptSystem::RawRemoveInstance(const char *name)
inst->SetStopping(true); inst->SetStopping(true);
inst->StopRegisteredWorkers(); inst->StopRegisteredWorkers();
std::vector<JSSysCommand> pendingCalls; std::vector<JSSysCommand> pendingCalls;
PullCommands(JS_CMD_C_METHOD_CALL, pendingCalls); PullCommands(JS_CMD_C_METHOD_CALL, pendingCalls);
ProcessCommandQueue(pendingCalls); ProcessCommandQueue(pendingCalls);
@ -486,9 +487,9 @@ bool CScriptSystem::RawRemoveInstance(const char *name)
return true; return true;
} }
JSAppCallbackID CScriptSystem::RawAddAppCallback(JSAppHookID hookId, JSAppCallback& callback) JSAppCallbackID CScriptSystem::RawAddAppCallback(JSAppHookID hookId, JSAppCallback & callback)
{ {
if(hookId >= JS_NUM_APP_HOOKS) if (hookId >= JS_NUM_APP_HOOKS)
{ {
return JS_INVALID_CALLBACK; return JS_INVALID_CALLBACK;
} }
@ -533,7 +534,7 @@ void CScriptSystem::ExecAutorunList()
} }
} }
std::set<std::string>& CScriptSystem::AutorunList() std::set<std::string> & CScriptSystem::AutorunList()
{ {
return m_AutorunList; return m_AutorunList;
} }
@ -568,12 +569,12 @@ void CScriptSystem::SaveAutorunList()
g_Settings->SaveString(Debugger_AutorunScripts, joinedNames.c_str()); g_Settings->SaveString(Debugger_AutorunScripts, joinedNames.c_str());
} }
CDebuggerUI* CScriptSystem::Debugger() CDebuggerUI * CScriptSystem::Debugger()
{ {
return m_Debugger; return m_Debugger;
} }
stdstr CScriptSystem::FixStringReturns(const char* str) stdstr CScriptSystem::FixStringReturns(const char * str)
{ {
stdstr fstr = str; stdstr fstr = str;
size_t pos = 0; size_t pos = 0;
@ -585,7 +586,7 @@ stdstr CScriptSystem::FixStringReturns(const char* str)
return fstr; return fstr;
} }
bool CScriptSystem::ProcessCommandQueue(std::vector<JSSysCommand>& queue) bool CScriptSystem::ProcessCommandQueue(std::vector<JSSysCommand> & queue)
{ {
std::vector<JSSysCommand>::iterator it; std::vector<JSSysCommand>::iterator it;
for (it = queue.begin(); it != queue.end(); it++) for (it = queue.begin(); it != queue.end(); it++)
@ -599,7 +600,7 @@ bool CScriptSystem::ProcessCommandQueue(std::vector<JSSysCommand>& queue)
return true; return true;
} }
bool CScriptSystem::ProcessCommand(JSSysCommand& cmd) bool CScriptSystem::ProcessCommand(JSSysCommand & cmd)
{ {
CGuard guard(m_InstancesCS); CGuard guard(m_InstancesCS);
@ -615,12 +616,12 @@ bool CScriptSystem::ProcessCommand(JSSysCommand& cmd)
OnInput(cmd.paramA.c_str(), cmd.paramB.c_str()); OnInput(cmd.paramA.c_str(), cmd.paramB.c_str());
break; break;
case JS_CMD_C_METHOD_CALL: case JS_CMD_C_METHOD_CALL:
{ {
JSSysCMethodCall* methodCall = (JSSysCMethodCall*)cmd.paramC; JSSysCMethodCall * methodCall = (JSSysCMethodCall *)cmd.paramC;
OnCMethodCall(cmd.paramA.c_str(), methodCall); OnCMethodCall(cmd.paramA.c_str(), methodCall);
delete methodCall; delete methodCall;
} }
break; break;
case JS_CMD_SWEEP: case JS_CMD_SWEEP:
OnSweep(true); OnSweep(true);
break; break;
@ -633,7 +634,7 @@ bool CScriptSystem::ProcessCommand(JSSysCommand& cmd)
return true; return true;
} }
void CScriptSystem::PullCommands(JSSysCommandID id, std::vector<JSSysCommand>& out) void CScriptSystem::PullCommands(JSSysCommandID id, std::vector<JSSysCommand> & out)
{ {
CGuard guard(m_CmdQueueCS); CGuard guard(m_CmdQueueCS);

View File

@ -1,8 +1,9 @@
#include <stdafx.h> #include "stdafx.h"
#include "ScriptWorker.h"
#include "ScriptInstance.h"
CScriptWorker::CScriptWorker(CScriptInstance* instance, void* dukObjectHeapPtr) : #include "ScriptInstance.h"
#include "ScriptWorker.h"
CScriptWorker::CScriptWorker(CScriptInstance * instance, void * dukObjectHeapPtr) :
m_bStopping(false), m_bStopping(false),
m_bRegistered(false), m_bRegistered(false),
m_hThread(nullptr), m_hThread(nullptr),
@ -21,8 +22,9 @@ CScriptWorker::~CScriptWorker()
} }
} }
DWORD WINAPI CScriptWorker::ThreadProc(void* _this) { DWORD WINAPI CScriptWorker::ThreadProc(void * _this)
((CScriptWorker*)_this)->WorkerProc(); {
((CScriptWorker *)_this)->WorkerProc();
return 0; return 0;
} }
@ -38,7 +40,7 @@ void CScriptWorker::StartWorkerProc()
return; return;
} }
m_hThread = CreateThread(0, 0, ThreadProc, (void*)this, 0, nullptr); m_hThread = CreateThread(0, 0, ThreadProc, (void *)this, 0, nullptr);
} }
void CScriptWorker::StopWorkerProc() void CScriptWorker::StopWorkerProc()

View File

@ -1,7 +1,8 @@
#include "stdafx.h" #include "stdafx.h"
#include "Symbols.h" #include "Symbols.h"
CSymbolTable::CSymbolTable(CDebuggerUI* debugger) : CSymbolTable::CSymbolTable(CDebuggerUI * debugger) :
m_Debugger(debugger), m_Debugger(debugger),
m_NextSymbolId(0), m_NextSymbolId(0),
m_SymFileBuffer(nullptr), m_SymFileBuffer(nullptr),
@ -22,27 +23,27 @@ CSymbolTable::~CSymbolTable()
} }
symbol_type_info_t CSymbolTable::m_SymbolTypes[] = { symbol_type_info_t CSymbolTable::m_SymbolTypes[] = {
{ SYM_CODE, "code", 1 }, {SYM_CODE, "code", 1},
{ SYM_DATA, "data", 1 }, {SYM_DATA, "data", 1},
{ SYM_U8, "u8", 1 }, {SYM_U8, "u8", 1},
{ SYM_U16, "u16", 2 }, {SYM_U16, "u16", 2},
{ SYM_U32, "u32", 4 }, {SYM_U32, "u32", 4},
{ SYM_U64, "u64", 8 }, {SYM_U64, "u64", 8},
{ SYM_S8, "s8", 1 }, {SYM_S8, "s8", 1},
{ SYM_S16, "s16", 2 }, {SYM_S16, "s16", 2},
{ SYM_S32, "s32", 4 }, {SYM_S32, "s32", 4},
{ SYM_S64, "s64", 8 }, {SYM_S64, "s64", 8},
{ SYM_FLOAT, "float", 4 }, {SYM_FLOAT, "float", 4},
{ SYM_DOUBLE, "double", 8 }, {SYM_DOUBLE, "double", 8},
{ SYM_VECTOR2, "v2", 8 }, {SYM_VECTOR2, "v2", 8},
{ SYM_VECTOR3, "v3", 12 }, {SYM_VECTOR3, "v3", 12},
{ SYM_VECTOR4, "v4", 16 }, {SYM_VECTOR4, "v4", 16},
{ SYM_INVALID, nullptr, 0 } { SYM_INVALID, nullptr, 0 }
}; };
symbol_type_id_t CSymbolTable::GetTypeId(char* typeName) symbol_type_id_t CSymbolTable::GetTypeId(char * typeName)
{ {
const char* name; const char * name;
for (int i = 0; (name = m_SymbolTypes[i].name) != nullptr; i++) for (int i = 0; (name = m_SymbolTypes[i].name) != nullptr; i++)
{ {
if (strcmp(typeName, name) == 0) if (strcmp(typeName, name) == 0)
@ -53,7 +54,7 @@ symbol_type_id_t CSymbolTable::GetTypeId(char* typeName)
return SYM_INVALID; return SYM_INVALID;
} }
const char* CSymbolTable::GetTypeName(int typeId) const char * CSymbolTable::GetTypeName(int typeId)
{ {
if (typeId >= NUM_SYM_TYPES) if (typeId >= NUM_SYM_TYPES)
{ {
@ -94,7 +95,7 @@ CPath CSymbolTable::GetSymFilePath()
return symFilePath; return symFilePath;
} }
void CSymbolTable::ParserFetchToken(const char* delim) void CSymbolTable::ParserFetchToken(const char * delim)
{ {
if (!m_bHaveFirstToken) if (!m_bHaveFirstToken)
{ {
@ -106,7 +107,7 @@ void CSymbolTable::ParserFetchToken(const char* delim)
{ {
m_ParserToken = strtok_s(nullptr, delim, &m_TokPos); m_ParserToken = strtok_s(nullptr, delim, &m_TokPos);
} }
if (m_ParserToken != nullptr) if (m_ParserToken != nullptr)
{ {
m_ParserTokenLength = strlen(m_ParserToken); m_ParserTokenLength = strlen(m_ParserToken);
@ -133,16 +134,16 @@ void CSymbolTable::Load()
MessageBox(nullptr, L"Game must be loaded", L"Symbols", MB_ICONWARNING | MB_OK); MessageBox(nullptr, L"Game must be loaded", L"Symbols", MB_ICONWARNING | MB_OK);
return; return;
} }
CPath symFilePath = GetSymFilePath(); CPath symFilePath = GetSymFilePath();
bool bOpened = m_SymFileHandle.Open(symFilePath, CFileBase::modeRead); bool bOpened = m_SymFileHandle.Open(symFilePath, CFileBase::modeRead);
if (!bOpened) if (!bOpened)
{ {
return; return;
} }
if (m_SymFileBuffer != nullptr) if (m_SymFileBuffer != nullptr)
{ {
delete[] m_SymFileBuffer; delete[] m_SymFileBuffer;
@ -159,7 +160,7 @@ void CSymbolTable::Load()
m_SymFileHandle.Read(m_SymFileBuffer, m_SymFileSize); m_SymFileHandle.Read(m_SymFileBuffer, m_SymFileSize);
m_SymFileHandle.Close(); m_SymFileHandle.Close();
m_SymFileBuffer[m_SymFileSize] = '\0'; m_SymFileBuffer[m_SymFileSize] = '\0';
strcpy(m_SymFileParseBuffer, m_SymFileBuffer); strcpy(m_SymFileParseBuffer, m_SymFileBuffer);
m_bHaveFirstToken = false; m_bHaveFirstToken = false;
@ -170,9 +171,9 @@ void CSymbolTable::Load()
{ {
uint32_t address = 0; uint32_t address = 0;
int type = 0; int type = 0;
char* name = nullptr; char * name = nullptr;
char* description = nullptr; char * description = nullptr;
// Address // Address
ParserFetchToken(",\n\0"); ParserFetchToken(",\n\0");
@ -183,22 +184,22 @@ void CSymbolTable::Load()
break; break;
} }
char* endptr; char * endptr;
address = (uint32_t)strtoull(m_ParserToken, &endptr, 16); address = (uint32_t)strtoull(m_ParserToken, &endptr, 16);
if (endptr == m_ParserToken) if (endptr == m_ParserToken)
{ {
errorCode = ERR_INVALID_ADDR; errorCode = ERR_INVALID_ADDR;
break; break;
} }
// Type // Type
if (m_ParserDelimeter != ',') if (m_ParserDelimeter != ',')
{ {
errorCode = ERR_MISSING_FIELDS; errorCode = ERR_MISSING_FIELDS;
break; break;
} }
ParserFetchToken(",\n\0"); ParserFetchToken(",\n\0");
type = GetTypeId(m_ParserToken); type = GetTypeId(m_ParserToken);
@ -207,7 +208,7 @@ void CSymbolTable::Load()
errorCode = ERR_INVALID_TYPE; errorCode = ERR_INVALID_TYPE;
break; break;
} }
// Name // Name
if (m_ParserDelimeter != ',') if (m_ParserDelimeter != ',')
{ {
@ -224,7 +225,7 @@ void CSymbolTable::Load()
ParserFetchToken("\n\0"); ParserFetchToken("\n\0");
description = m_ParserToken; description = m_ParserToken;
} }
// Add symbol object to the vector // Add symbol object to the vector
AddSymbol(type, address, name, description, false); AddSymbol(type, address, name, description, false);
@ -239,7 +240,7 @@ void CSymbolTable::Load()
sort(m_Symbols.begin(), m_Symbols.end(), CmpSymbolAddresses); sort(m_Symbols.begin(), m_Symbols.end(), CmpSymbolAddresses);
UpdateAddressMap(); UpdateAddressMap();
delete[] m_SymFileParseBuffer; delete[] m_SymFileParseBuffer;
m_SymFileParseBuffer = nullptr; m_SymFileParseBuffer = nullptr;
@ -274,9 +275,9 @@ void CSymbolTable::Save()
for (size_t i = 0; i < m_Symbols.size(); i++) for (size_t i = 0; i < m_Symbols.size(); i++)
{ {
CSymbol& symbol = m_Symbols[i]; CSymbol & symbol = m_Symbols[i];
stdstr strLine = stdstr_f("%08X,%s,%s", symbol.m_Address, symbol.TypeName(), symbol.m_Name); stdstr strLine = stdstr_f("%08X,%s,%s", symbol.m_Address, symbol.TypeName(), symbol.m_Name);
if (symbol.m_Description != nullptr) if (symbol.m_Description != nullptr)
{ {
strLine += stdstr_f(",%s", symbol.m_Description); strLine += stdstr_f(",%s", symbol.m_Description);
@ -290,20 +291,20 @@ void CSymbolTable::Save()
m_SymFileHandle.Close(); m_SymFileHandle.Close();
} }
void CSymbolTable::GetValueString(char* dst, CSymbol* symbol) void CSymbolTable::GetValueString(char * dst, CSymbol * symbol)
{ {
union union
{ {
uint8_t u8; uint8_t u8;
int8_t s8; int8_t s8;
uint16_t u16; uint16_t u16;
int16_t s16; int16_t s16;
uint32_t u32; uint32_t u32;
int32_t s32; int32_t s32;
uint64_t u64; uint64_t u64;
int64_t s64; int64_t s64;
float f32; float f32;
double f64; double f64;
} value; } value;
uint32_t address = symbol->m_Address; uint32_t address = symbol->m_Address;
@ -356,21 +357,24 @@ void CSymbolTable::GetValueString(char* dst, CSymbol* symbol)
sprintf(dst, "%f", value.f64); sprintf(dst, "%f", value.f64);
break; break;
case SYM_VECTOR2: case SYM_VECTOR2:
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++)
{
m_Debugger->DebugLoad_VAddr(address + (i * sizeof(float)), value.f32); m_Debugger->DebugLoad_VAddr(address + (i * sizeof(float)), value.f32);
xyzw[i] = value.f32; xyzw[i] = value.f32;
} }
sprintf(dst, "%f, %f", xyzw[0], xyzw[1]); sprintf(dst, "%f, %f", xyzw[0], xyzw[1]);
break; break;
case SYM_VECTOR3: case SYM_VECTOR3:
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++)
{
m_Debugger->DebugLoad_VAddr(address + (i * sizeof(float)), value.f32); m_Debugger->DebugLoad_VAddr(address + (i * sizeof(float)), value.f32);
xyzw[i] = value.f32; xyzw[i] = value.f32;
} }
sprintf(dst, "%f, %f, %f", xyzw[0], xyzw[1], xyzw[2]); sprintf(dst, "%f, %f, %f", xyzw[0], xyzw[1], xyzw[2]);
break; break;
case SYM_VECTOR4: case SYM_VECTOR4:
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++)
{
m_Debugger->DebugLoad_VAddr(address + (i * sizeof(float)), value.f32); m_Debugger->DebugLoad_VAddr(address + (i * sizeof(float)), value.f32);
xyzw[i] = value.f32; xyzw[i] = value.f32;
} }
@ -382,7 +386,7 @@ void CSymbolTable::GetValueString(char* dst, CSymbol* symbol)
} }
} }
void CSymbolTable::ParseErrorAlert(char* message, int lineNumber) void CSymbolTable::ParseErrorAlert(char * message, int lineNumber)
{ {
stdstr messageFormatted = stdstr_f("%s\nLine %d", message, lineNumber); stdstr messageFormatted = stdstr_f("%s\nLine %d", message, lineNumber);
MessageBox(nullptr, messageFormatted.ToUTF16().c_str(), L"Symbol parse error", MB_OK | MB_ICONWARNING); MessageBox(nullptr, messageFormatted.ToUTF16().c_str(), L"Symbol parse error", MB_OK | MB_ICONWARNING);
@ -394,12 +398,12 @@ void CSymbolTable::Reset()
m_Symbols.clear(); m_Symbols.clear();
} }
bool CSymbolTable::CmpSymbolAddresses(CSymbol& a, CSymbol& b) bool CSymbolTable::CmpSymbolAddresses(CSymbol & a, CSymbol & b)
{ {
return (a.m_Address < b.m_Address); return (a.m_Address < b.m_Address);
} }
void CSymbolTable::AddSymbol(int type, uint32_t address, const char* name, const char* description, bool bSortAfter) void CSymbolTable::AddSymbol(int type, uint32_t address, const char * name, const char * description, bool bSortAfter)
{ {
CGuard guard(m_CS); CGuard guard(m_CS);
@ -441,7 +445,7 @@ int CSymbolTable::GetCount()
return m_Symbols.size(); return m_Symbols.size();
} }
bool CSymbolTable::GetSymbolByIndex(size_t index, CSymbol* symbol) bool CSymbolTable::GetSymbolByIndex(size_t index, CSymbol * symbol)
{ {
CGuard guard(m_CS); CGuard guard(m_CS);
if (index < 0 || index >= m_Symbols.size()) if (index < 0 || index >= m_Symbols.size())
@ -452,7 +456,7 @@ bool CSymbolTable::GetSymbolByIndex(size_t index, CSymbol* symbol)
return true; return true;
} }
bool CSymbolTable::GetSymbolByAddress(uint32_t address, CSymbol* symbol) bool CSymbolTable::GetSymbolByAddress(uint32_t address, CSymbol * symbol)
{ {
CGuard guard(m_CS); CGuard guard(m_CS);
@ -466,7 +470,7 @@ bool CSymbolTable::GetSymbolByAddress(uint32_t address, CSymbol* symbol)
return true; return true;
} }
bool CSymbolTable::GetSymbolById(int id, CSymbol* symbol) bool CSymbolTable::GetSymbolById(int id, CSymbol * symbol)
{ {
CGuard guard(m_CS); CGuard guard(m_CS);
for (size_t i = 0; i < m_Symbols.size(); i++) for (size_t i = 0; i < m_Symbols.size(); i++)

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#include "stdafx.h"
class CSymbol; class CSymbol;

View File

@ -1,77 +1,80 @@
#include "stdafx.h" #include "stdafx.h"
#include <3rdParty\discord-rpc\include\discord_rpc.h>
#include "DiscordRPC.h"
#define UNIX_TIME_START 0x019DB1DED53E8000 #include "DiscordRPC.h"
#define TICKS_PER_SECOND 10000000 #include <3rdParty\discord-rpc\include\discord_rpc.h>
#define UNIX_TIME_START 0x019DB1DED53E8000
#define TICKS_PER_SECOND 10000000
// Discord Project64 app ID // Discord Project64 app ID
#define PJ64_DISCORD_APPID "704794684387491891" #define PJ64_DISCORD_APPID "704794684387491891"
void CDiscord::Init() void CDiscord::Init()
{ {
DiscordEventHandlers handlers = {}; DiscordEventHandlers handlers = {};
Discord_Initialize(PJ64_DISCORD_APPID, &handlers, 1, nullptr); Discord_Initialize(PJ64_DISCORD_APPID, &handlers, 1, nullptr);
} }
void CDiscord::Shutdown() void CDiscord::Shutdown()
{ {
Discord_ClearPresence(); Discord_ClearPresence();
Discord_Shutdown(); Discord_Shutdown();
} }
static stdstr GetTitle() static stdstr GetTitle()
{ {
stdstr Default = ""; stdstr Default = "";
bool existsInRdb = g_Settings->LoadStringVal(Rdb_GoodName, Default); bool existsInRdb = g_Settings->LoadStringVal(Rdb_GoodName, Default);
if (existsInRdb) if (existsInRdb)
return g_Settings->LoadStringVal(Rdb_GoodName); return g_Settings->LoadStringVal(Rdb_GoodName);
else { else
Default = CPath(g_Settings->LoadStringVal(Game_File)).GetName().c_str(); {
if (strstr(const_cast<char*>(Default.c_str()), "?") != nullptr) { Default = CPath(g_Settings->LoadStringVal(Game_File)).GetName().c_str();
return Default.substr(Default.find("?") + 1); if (strstr(const_cast<char *>(Default.c_str()), "?") != nullptr)
} {
return Default; return Default.substr(Default.find("?") + 1);
} }
return Default;
}
} }
void CDiscord::Update(bool bHaveGame) void CDiscord::Update(bool bHaveGame)
{ {
// Variables we use later // Variables we use later
// Title uses the Rdb_GoodName to display a proper game name over DiscordRPC // Title uses the Rdb_GoodName to display a proper game name over DiscordRPC
// Artwork uses the header of the ROM to easily add game images through the Discord developer panel using the ID above // Artwork uses the header of the ROM to easily add game images through the Discord developer panel using the ID above
stdstr title = bHaveGame ? GetTitle() : ""; stdstr title = bHaveGame ? GetTitle() : "";
stdstr artwork = bHaveGame ? g_Settings->LoadStringVal(Rdb_RPCKey) : ""; stdstr artwork = bHaveGame ? g_Settings->LoadStringVal(Rdb_RPCKey) : "";
// Load game into DiscordRPC // Load game into DiscordRPC
DiscordRichPresence discordPresence = {}; // Activates DiscordRPC DiscordRichPresence discordPresence = {}; // Activates DiscordRPC
if (artwork.empty()) if (artwork.empty())
{ {
discordPresence.largeImageKey = "pj64_icon"; discordPresence.largeImageKey = "pj64_icon";
discordPresence.largeImageText = "Project64"; discordPresence.largeImageText = "Project64";
} }
else else
{ {
discordPresence.largeImageKey = artwork.c_str(); discordPresence.largeImageKey = artwork.c_str();
discordPresence.largeImageText = title.c_str(); discordPresence.largeImageText = title.c_str();
discordPresence.smallImageKey = "pj64_icon"; discordPresence.smallImageKey = "pj64_icon";
discordPresence.smallImageText = "Project64"; discordPresence.smallImageText = "Project64";
} }
discordPresence.details = title.empty() ? "Not in-game" : title.c_str(); discordPresence.details = title.empty() ? "Not in-game" : title.c_str();
discordPresence.startTimestamp = Timestamp(); discordPresence.startTimestamp = Timestamp();
Discord_UpdatePresence(&discordPresence); // End DiscordRPC Discord_UpdatePresence(&discordPresence); // End DiscordRPC
} }
int64_t CDiscord::Timestamp() int64_t CDiscord::Timestamp()
{ {
FILETIME ft; FILETIME ft;
GetSystemTimeAsFileTime(&ft); GetSystemTimeAsFileTime(&ft);
LARGE_INTEGER li; LARGE_INTEGER li;
li.LowPart = ft.dwLowDateTime; li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime; li.HighPart = ft.dwHighDateTime;
return (li.QuadPart - UNIX_TIME_START) / TICKS_PER_SECOND; return (li.QuadPart - UNIX_TIME_START) / TICKS_PER_SECOND;
} }

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64\UserInterface\EnhancementUI.h> #include <Project64\UserInterface\EnhancementUI.h>
#include <Project64-core/N64System/Enhancement/Enhancements.h> #include <Project64-core/N64System/Enhancement/Enhancements.h>

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64-core/Logging.h> #include <Project64-core/Logging.h>
#include <Project64-core/Settings/LoggingSettings.h> #include <Project64-core/Settings/LoggingSettings.h>
#include <prsht.h> #include <prsht.h>
@ -102,7 +103,7 @@ LRESULT CALLBACK LogPifProc(HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lPar
} }
break; break;
case WM_NOTIFY: case WM_NOTIFY:
if (((NMHDR FAR *) lParam)->code != PSN_APPLY) if (((NMHDR FAR *)lParam)->code != PSN_APPLY)
{ {
break; break;
} }
@ -138,7 +139,7 @@ LRESULT CALLBACK LogRegProc(HWND hDlg, UINT uMsg, WPARAM /*wParam*/, LPARAM lPar
} }
break; break;
case WM_NOTIFY: case WM_NOTIFY:
if (((NMHDR FAR *) lParam)->code != PSN_APPLY) if (((NMHDR FAR *)lParam)->code != PSN_APPLY)
{ {
break; break;
} }

View File

@ -1,12 +1,13 @@
#include "stdafx.h" #include "stdafx.h"
#include "RomInformation.h"
#include "Debugger/Breakpoints.h" #include "Debugger/Breakpoints.h"
#include "Debugger/ScriptSystem.h" #include "Debugger/ScriptSystem.h"
#include "DiscordRPC.h" #include "DiscordRPC.h"
#include "RomInformation.h"
#include <Project64-core/N64System/N64Disk.h> #include <Project64-core/N64System/N64Disk.h>
#include <Project64\UserInterface\About.h> #include <Project64\UserInterface\About.h>
#include <windows.h>
#include <commdlg.h> #include <commdlg.h>
#include <windows.h>
CMainMenu::CMainMenu(CMainGui * hMainWindow) : CMainMenu::CMainMenu(CMainGui * hMainWindow) :
CBaseMenu(), CBaseMenu(),
@ -150,7 +151,7 @@ void CMainMenu::OnOpenRom(HWND hWnd)
{ {
return; return;
} }
stdstr ext = CPath(File).GetExtension(); stdstr ext = CPath(File).GetExtension();
if ((_stricmp(ext.c_str(), "ndd") != 0) && (_stricmp(ext.c_str(), "d64") != 0)) if ((_stricmp(ext.c_str(), "ndd") != 0) && (_stricmp(ext.c_str(), "d64") != 0))
{ {
@ -203,10 +204,10 @@ void CMainMenu::OnEndEmulation(void)
} }
m_Gui->SaveWindowLoc(); m_Gui->SaveWindowLoc();
if (UISettingsLoadBool(Setting_EnableDiscordRPC)) if (UISettingsLoadBool(Setting_EnableDiscordRPC))
{ {
CDiscord::Update(false); CDiscord::Update(false);
} }
} }
void CMainMenu::OnScreenShot(void) void CMainMenu::OnScreenShot(void)
@ -333,7 +334,7 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI
WriteTrace(TraceUserInterface, TraceDebug, "ID_FILE_ROMDIRECTORY 3"); WriteTrace(TraceUserInterface, TraceDebug, "ID_FILE_ROMDIRECTORY 3");
break; break;
case ID_FILE_REFRESHROMLIST: m_Gui->RefreshRomList(); break; case ID_FILE_REFRESHROMLIST: m_Gui->RefreshRomList(); break;
case ID_FILE_EXIT: DestroyWindow((HWND)hWnd); break; case ID_FILE_EXIT: DestroyWindow((HWND)hWnd); break;
case ID_SYSTEM_RESET_SOFT: case ID_SYSTEM_RESET_SOFT:
WriteTrace(TraceUserInterface, TraceDebug, "ID_SYSTEM_RESET_SOFT"); WriteTrace(TraceUserInterface, TraceDebug, "ID_SYSTEM_RESET_SOFT");
g_BaseSystem->ExternalEvent(SysEvent_ResetCPU_Soft); g_BaseSystem->ExternalEvent(SysEvent_ResetCPU_Soft);
@ -348,7 +349,9 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI
g_BaseSystem->ExternalEvent(g_Settings->LoadBool(GameRunning_CPU_Paused) ? SysEvent_ResumeCPU_FromMenu : SysEvent_PauseCPU_FromMenu); g_BaseSystem->ExternalEvent(g_Settings->LoadBool(GameRunning_CPU_Paused) ? SysEvent_ResumeCPU_FromMenu : SysEvent_PauseCPU_FromMenu);
WriteTrace(TraceUserInterface, TraceDebug, "ID_SYSTEM_PAUSE 1"); WriteTrace(TraceUserInterface, TraceDebug, "ID_SYSTEM_PAUSE 1");
break; break;
case ID_SYSTEM_BITMAP: OnScreenShot(); break; case ID_SYSTEM_BITMAP:
OnScreenShot();
break;
break; break;
case ID_SYSTEM_LIMITFPS: case ID_SYSTEM_LIMITFPS:
WriteTrace(TraceUserInterface, TraceDebug, "ID_SYSTEM_LIMITFPS"); WriteTrace(TraceUserInterface, TraceDebug, "ID_SYSTEM_LIMITFPS");
@ -419,7 +422,7 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI
ShowCursor(true); ShowCursor(true);
m_Gui->ShowStatusBar(g_Settings->LoadBool((SettingID)UserInterface_ShowStatusBar)); m_Gui->ShowStatusBar(g_Settings->LoadBool((SettingID)UserInterface_ShowStatusBar));
m_Gui->MakeWindowOnTop(UISettingsLoadBool(UserInterface_AlwaysOnTop)); m_Gui->MakeWindowOnTop(UISettingsLoadBool(UserInterface_AlwaysOnTop));
UISettingsSaveBool(UserInterface_InFullScreen, (DWORD)false); UISettingsSaveBool(UserInterface_InFullScreen, (DWORD) false);
} }
else else
{ {
@ -491,7 +494,7 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI
g_Settings->SaveBool(UserInterface_ShowCPUPer, true); g_Settings->SaveBool(UserInterface_ShowCPUPer, true);
} }
break; break;
case ID_OPTIONS_SETTINGS: OnSettings(hWnd); break; case ID_OPTIONS_SETTINGS: OnSettings(hWnd); break;
case ID_PROFILE_PROFILE: case ID_PROFILE_PROFILE:
g_Settings->SaveBool(Debugger_RecordExecutionTimes, !g_Settings->LoadBool(Debugger_RecordExecutionTimes)); g_Settings->SaveBool(Debugger_RecordExecutionTimes, !g_Settings->LoadBool(Debugger_RecordExecutionTimes));
g_BaseSystem->ExternalEvent(SysEvent_ResetFunctionTimes); g_BaseSystem->ExternalEvent(SysEvent_ResetFunctionTimes);
@ -649,7 +652,7 @@ bool CMainMenu::ProcessMessage(HWND hWnd, DWORD /*FromAccelerator*/, DWORD MenuI
stdstr CMainMenu::GetFileLastMod(const CPath & FileName) stdstr CMainMenu::GetFileLastMod(const CPath & FileName)
{ {
HANDLE hFile = CreateFileA(FileName, GENERIC_READ, FILE_SHARE_READ, nullptr, HANDLE hFile = CreateFileA(FileName, GENERIC_READ, FILE_SHARE_READ, nullptr,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, nullptr); OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, nullptr);
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
{ {
return ""; return "";

File diff suppressed because it is too large Load Diff

View File

@ -192,7 +192,7 @@ CMenuShortCutKey::CMenuShortCutKey(WORD key, bool bCtrl, bool bAlt, bool bShift,
m_ShortCutName = ShortCutName.ToUTF16(); m_ShortCutName = ShortCutName.ToUTF16();
} }
VIRTUAL_KEY * CMenuShortCutKey::VirtualKeyList(int &Size) VIRTUAL_KEY * CMenuShortCutKey::VirtualKeyList(int & Size)
{ {
Size = sizeof(m_VirtualKeyList) / sizeof(m_VirtualKeyList[0]); Size = sizeof(m_VirtualKeyList) / sizeof(m_VirtualKeyList[0]);
return (VIRTUAL_KEY *)m_VirtualKeyList; return (VIRTUAL_KEY *)m_VirtualKeyList;
@ -479,7 +479,7 @@ void CShortCuts::Load(bool InitialValues)
CMenuShortCutKey::ACCESS_MODE AccessMode; CMenuShortCutKey::ACCESS_MODE AccessMode;
int ID, key, bCtrl, bAlt, bShift, bUserAdded, bInactive; int ID, key, bCtrl, bAlt, bShift, bUserAdded, bInactive;
FILE *file = fopen(ShortCutFile, "r"); FILE * file = fopen(ShortCutFile, "r");
if (file) if (file)
{ {
do do
@ -488,7 +488,7 @@ void CShortCuts::Load(bool InitialValues)
if (fgets(Line, sizeof(Line), file) != nullptr) if (fgets(Line, sizeof(Line), file) != nullptr)
{ {
sscanf(Line, "%d,%d,%d,%d,%d,%d,%d,%d", &ID, &key, &bCtrl, &bAlt, &bShift, &AccessMode, sscanf(Line, "%d,%d,%d,%d,%d,%d,%d,%d", &ID, &key, &bCtrl, &bAlt, &bShift, &AccessMode,
&bUserAdded, &bInactive); &bUserAdded, &bInactive);
MSC_MAP::iterator item = m_ShortCuts.find(ID); MSC_MAP::iterator item = m_ShortCuts.find(ID);
if (item == m_ShortCuts.end()) { continue; } if (item == m_ShortCuts.end()) { continue; }
@ -505,7 +505,7 @@ void CShortCuts::Save(void)
CGuard CS(m_CS); CGuard CS(m_CS);
stdstr FileName = UISettingsLoadStringVal(SupportFile_ShortCuts); stdstr FileName = UISettingsLoadStringVal(SupportFile_ShortCuts);
FILE *file = fopen(FileName.c_str(), "w"); FILE * file = fopen(FileName.c_str(), "w");
if (file == nullptr) if (file == nullptr)
{ {
return; return;
@ -516,14 +516,14 @@ void CShortCuts::Save(void)
for (SHORTCUT_KEY_LIST::const_iterator ShortCut = Item->second.GetAccelItems().begin(); ShortCut != Item->second.GetAccelItems().end(); ShortCut++) for (SHORTCUT_KEY_LIST::const_iterator ShortCut = Item->second.GetAccelItems().begin(); ShortCut != Item->second.GetAccelItems().end(); ShortCut++)
{ {
fprintf(file, "%d,%d,%d,%d,%d,%d,%d,%d\n", fprintf(file, "%d,%d,%d,%d,%d,%d,%d,%d\n",
Item->first, Item->first,
ShortCut->Key(), ShortCut->Key(),
ShortCut->Ctrl(), ShortCut->Ctrl(),
ShortCut->Alt(), ShortCut->Alt(),
ShortCut->Shift(), ShortCut->Shift(),
ShortCut->AccessMode(), ShortCut->AccessMode(),
ShortCut->UserAdded(), ShortCut->UserAdded(),
ShortCut->Inactive()); ShortCut->Inactive());
} }
} }
fclose(file); fclose(file);

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include <time.h> #include <time.h>
CNotificationImp & Notify(void) CNotificationImp & Notify(void)

View File

@ -1,8 +1,9 @@
#include "stdafx.h" #include "stdafx.h"
#include <Common/md5.h> #include <Common/md5.h>
#include <Wininet.h>
#include <time.h> #include <time.h>
#include <windows.h> #include <windows.h>
#include <Wininet.h>
#pragma comment(lib, "Wininet.lib") #pragma comment(lib, "Wininet.lib")
@ -78,7 +79,7 @@ bool CProjectSupport::ValidateCode(const char * Code)
m_SupportInfo.Validated = true; m_SupportInfo.Validated = true;
SaveSupportInfo(); SaveSupportInfo();
} }
} }
return m_SupportInfo.Validated; return m_SupportInfo.Validated;
} }
@ -88,7 +89,7 @@ std::string CProjectSupport::GenerateMachineID(void)
DWORD Length = sizeof(ComputerName) / sizeof(ComputerName[0]); DWORD Length = sizeof(ComputerName) / sizeof(ComputerName[0]);
GetComputerName(ComputerName, &Length); GetComputerName(ComputerName, &Length);
wchar_t SysPath[MAX_PATH] = { 0 }, VolumePath[MAX_PATH] = { 0 }; wchar_t SysPath[MAX_PATH] = {0}, VolumePath[MAX_PATH] = {0};
GetSystemDirectory(SysPath, sizeof(SysPath) / sizeof(SysPath[0])); GetSystemDirectory(SysPath, sizeof(SysPath) / sizeof(SysPath[0]));
GetVolumePathName(SysPath, VolumePath, sizeof(VolumePath) / sizeof(VolumePath[0])); GetVolumePathName(SysPath, VolumePath, sizeof(VolumePath) / sizeof(VolumePath[0]));
@ -96,7 +97,7 @@ std::string CProjectSupport::GenerateMachineID(void)
DWORD SerialNumber = 0; DWORD SerialNumber = 0;
GetVolumeInformation(VolumePath, nullptr, NULL, &SerialNumber, nullptr, nullptr, nullptr, NULL); GetVolumeInformation(VolumePath, nullptr, NULL, &SerialNumber, nullptr, nullptr, nullptr, NULL);
wchar_t MachineGuid[200] = { 0 }; wchar_t MachineGuid[200] = {0};
HKEY hKey; HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_QUERY_VALUE | KEY_WOW64_64KEY, &hKey) == ERROR_SUCCESS) if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Cryptography", 0, KEY_QUERY_VALUE | KEY_WOW64_64KEY, &hKey) == ERROR_SUCCESS)
{ {

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include <Project64/Settings/UISettings.h> #include <Project64/Settings/UISettings.h>
#include <commctrl.h> #include <commctrl.h>

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "RomInformation.h" #include "RomInformation.h"
#include <Project64-core/N64System/N64Disk.h> #include <Project64-core/N64System/N64Disk.h>

View File

@ -25,7 +25,7 @@ CAdvancedOptionsPage::CAdvancedOptionsPage(HWND hParent, const RECT & rcDispay)
AddModCheckBox(GetDlgItem(IDC_START_ON_ROM_OPEN), Setting_AutoStart); AddModCheckBox(GetDlgItem(IDC_START_ON_ROM_OPEN), Setting_AutoStart);
AddModCheckBox(GetDlgItem(IDC_ZIP), Setting_AutoZipInstantSave); AddModCheckBox(GetDlgItem(IDC_ZIP), Setting_AutoZipInstantSave);
AddModCheckBox(GetDlgItem(IDC_DEBUGGER), Debugger_Enabled); AddModCheckBox(GetDlgItem(IDC_DEBUGGER), Debugger_Enabled);
AddModCheckBox(GetDlgItem(IDC_INTERPRETER), Setting_ForceInterpreterCPU); AddModCheckBox(GetDlgItem(IDC_INTERPRETER), Setting_ForceInterpreterCPU);
AddModCheckBox(GetDlgItem(IDC_REMEMBER_CHEAT), Setting_RememberCheats); AddModCheckBox(GetDlgItem(IDC_REMEMBER_CHEAT), Setting_RememberCheats);
AddModCheckBox(GetDlgItem(IDC_UNIQUE_SAVE_DIR), Setting_UniqueSaveDir); AddModCheckBox(GetDlgItem(IDC_UNIQUE_SAVE_DIR), Setting_UniqueSaveDir);
AddModCheckBox(GetDlgItem(IDC_CHECK_RUNNING), Setting_CheckEmuRunning); AddModCheckBox(GetDlgItem(IDC_CHECK_RUNNING), Setting_CheckEmuRunning);
@ -64,7 +64,10 @@ void CAdvancedOptionsPage::ApplySettings(bool UpdateScreen)
bool CAdvancedOptionsPage::EnableReset(void) bool CAdvancedOptionsPage::EnableReset(void)
{ {
if (CSettingsPageImpl<CAdvancedOptionsPage>::EnableReset()) { return true; } if (CSettingsPageImpl<CAdvancedOptionsPage>::EnableReset())
{
return true;
}
return false; return false;
} }

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "SettingsPage.h" #include "SettingsPage.h"
CDefaultsOptionsPage::CDefaultsOptionsPage(HWND hParent, const RECT & rcDispay) CDefaultsOptionsPage::CDefaultsOptionsPage(HWND hParent, const RECT & rcDispay)
@ -89,7 +90,10 @@ void CDefaultsOptionsPage::ApplySettings(bool UpdateScreen)
bool CDefaultsOptionsPage::EnableReset(void) bool CDefaultsOptionsPage::EnableReset(void)
{ {
if (CSettingsPageImpl<CDefaultsOptionsPage>::EnableReset()) { return true; } if (CSettingsPageImpl<CDefaultsOptionsPage>::EnableReset())
{
return true;
}
return false; return false;
} }

View File

@ -3,7 +3,7 @@
#include "SettingsPage.h" #include "SettingsPage.h"
COptionsDirectoriesPage::COptionsDirectoriesPage(HWND hParent, const RECT & rcDispay) : COptionsDirectoriesPage::COptionsDirectoriesPage(HWND hParent, const RECT & rcDispay) :
m_InUpdateSettings(false) m_InUpdateSettings(false)
{ {
Create(hParent); Create(hParent);
if (m_hWnd == nullptr) if (m_hWnd == nullptr)
@ -94,35 +94,50 @@ void COptionsDirectoriesPage::SelectDirectory(LanguageStringID Title, CModifiedE
void COptionsDirectoriesPage::PluginDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsDirectoriesPage::PluginDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
if (m_InUpdateSettings) { return; } if (m_InUpdateSettings)
{
return;
}
m_PluginDir.SetChanged(true); m_PluginDir.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void COptionsDirectoriesPage::AutoSaveDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsDirectoriesPage::AutoSaveDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
if (m_InUpdateSettings) { return; } if (m_InUpdateSettings)
{
return;
}
m_AutoSaveDir.SetChanged(true); m_AutoSaveDir.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void COptionsDirectoriesPage::InstantSaveDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsDirectoriesPage::InstantSaveDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
if (m_InUpdateSettings) { return; } if (m_InUpdateSettings)
{
return;
}
m_InstantSaveDir.SetChanged(true); m_InstantSaveDir.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void COptionsDirectoriesPage::SnapShotDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsDirectoriesPage::SnapShotDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
if (m_InUpdateSettings) { return; } if (m_InUpdateSettings)
{
return;
}
m_ScreenShotDir.SetChanged(true); m_ScreenShotDir.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void COptionsDirectoriesPage::TextureDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void COptionsDirectoriesPage::TextureDirChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
if (m_InUpdateSettings) { return; } if (m_InUpdateSettings)
{
return;
}
m_TextureDir.SetChanged(true); m_TextureDir.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
@ -312,16 +327,46 @@ void COptionsDirectoriesPage::ApplySettings(bool UpdateScreen)
bool COptionsDirectoriesPage::EnableReset(void) bool COptionsDirectoriesPage::EnableReset(void)
{ {
if (m_PluginDir.IsChanged()) { return true; } if (m_PluginDir.IsChanged())
if (m_AutoSaveDir.IsChanged()) { return true; } {
if (m_InstantSaveDir.IsChanged()) { return true; } return true;
if (m_ScreenShotDir.IsChanged()) { return true; } }
if (m_TextureDir.IsChanged()) { return true; } if (m_AutoSaveDir.IsChanged())
if (m_PluginDefault.IsChanged()) { return true; } {
if (m_AutoSaveDefault.IsChanged()) { return true; } return true;
if (m_InstantDefault.IsChanged()) { return true; } }
if (m_ScreenShotDefault.IsChanged()) { return true; } if (m_InstantSaveDir.IsChanged())
if (m_TextureDefault.IsChanged()) { return true; } {
return true;
}
if (m_ScreenShotDir.IsChanged())
{
return true;
}
if (m_TextureDir.IsChanged())
{
return true;
}
if (m_PluginDefault.IsChanged())
{
return true;
}
if (m_AutoSaveDefault.IsChanged())
{
return true;
}
if (m_InstantDefault.IsChanged())
{
return true;
}
if (m_ScreenShotDefault.IsChanged())
{
return true;
}
if (m_TextureDefault.IsChanged())
{
return true;
}
return false; return false;
} }

View File

@ -74,7 +74,10 @@ void CDiskDrivePage::ApplySettings(bool UpdateScreen)
bool CDiskDrivePage::EnableReset(void) bool CDiskDrivePage::EnableReset(void)
{ {
if (CSettingsPageImpl<CDiskDrivePage>::EnableReset()) { return true; } if (CSettingsPageImpl<CDiskDrivePage>::EnableReset())
{
return true;
}
return false; return false;
} }
@ -100,21 +103,30 @@ void CDiskDrivePage::SelectIplDirTl(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
void CDiskDrivePage::IplDirJpChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void CDiskDrivePage::IplDirJpChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
if (m_InUpdateSettings) { return; } if (m_InUpdateSettings)
{
return;
}
m_IplDirJp.SetChanged(true); m_IplDirJp.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void CDiskDrivePage::IplDirUsChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void CDiskDrivePage::IplDirUsChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
if (m_InUpdateSettings) { return; } if (m_InUpdateSettings)
{
return;
}
m_IplDirUs.SetChanged(true); m_IplDirUs.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }
void CDiskDrivePage::IplDirTlChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/) void CDiskDrivePage::IplDirTlChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{ {
if (m_InUpdateSettings) { return; } if (m_InUpdateSettings)
{
return;
}
m_IplDirTl.SetChanged(true); m_IplDirTl.SetChanged(true);
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0); SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
} }

View File

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "SettingsPage.h"
#include "SettingsPage-Game-DiskDrive.h" #include "SettingsPage-Game-DiskDrive.h"
#include "SettingsPage.h"
CGameDiskDrivePage::CGameDiskDrivePage(HWND hParent, const RECT & rcDispay) CGameDiskDrivePage::CGameDiskDrivePage(HWND hParent, const RECT & rcDispay)
{ {
@ -13,7 +13,7 @@ CGameDiskDrivePage::CGameDiskDrivePage(HWND hParent, const RECT & rcDispay)
// Set the text for all GUI items // Set the text for all GUI items
SetDlgItemText(IDC_DISKSEEKTIMING_TEXT2, wGS(ROM_DISK_SEEK_TIMING).c_str()); SetDlgItemText(IDC_DISKSEEKTIMING_TEXT2, wGS(ROM_DISK_SEEK_TIMING).c_str());
CModifiedComboBox* ComboBox; CModifiedComboBox * ComboBox;
ComboBox = AddModComboBox(GetDlgItem(IDC_DISKSEEKTIMING2), Game_DiskSeekTiming); ComboBox = AddModComboBox(GetDlgItem(IDC_DISKSEEKTIMING2), Game_DiskSeekTiming);
if (ComboBox) if (ComboBox)
{ {
@ -42,7 +42,10 @@ void CGameDiskDrivePage::ApplySettings(bool UpdateScreen)
bool CGameDiskDrivePage::EnableReset(void) bool CGameDiskDrivePage::EnableReset(void)
{ {
if (CSettingsPageImpl<CGameDiskDrivePage>::EnableReset()) { return true; } if (CSettingsPageImpl<CGameDiskDrivePage>::EnableReset())
{
return true;
}
return false; return false;
} }

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "../WTLControls/ModifiedCheckBox.h" #include "SettingsPage.h"
#include <Project64\UserInterface\WTLControls\ModifiedCheckBox.h>
#include <Project64-core/N64System/N64Types.h> #include <Project64-core/N64System/N64Types.h>
class CGameDiskDrivePage : class CGameDiskDrivePage :

View File

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "SettingsPage.h"
#include "SettingsPage-Game-General.h" #include "SettingsPage-Game-General.h"
#include "SettingsPage.h"
CGameGeneralPage::CGameGeneralPage(HWND hParent, const RECT & rcDispay) CGameGeneralPage::CGameGeneralPage(HWND hParent, const RECT & rcDispay)
{ {
@ -81,10 +81,10 @@ CGameGeneralPage::CGameGeneralPage(HWND hParent, const RECT & rcDispay)
TxtBox = AddModTextBox(GetDlgItem(IDC_OVER_CLOCK_MODIFIER), Game_OverClockModifier, false); TxtBox = AddModTextBox(GetDlgItem(IDC_OVER_CLOCK_MODIFIER), Game_OverClockModifier, false);
TxtBox->SetTextField(GetDlgItem(IDC_OVER_CLOCK_MODIFIER_TEXT)); TxtBox->SetTextField(GetDlgItem(IDC_OVER_CLOCK_MODIFIER_TEXT));
if (!g_Settings->LoadBool(Setting_SyncViaAudioEnabled)) if (!g_Settings->LoadBool(Setting_SyncViaAudioEnabled))
{ {
GetDlgItem(IDC_SYNC_AUDIO).EnableWindow(false); GetDlgItem(IDC_SYNC_AUDIO).EnableWindow(false);
} }
UpdatePageSettings(); UpdatePageSettings();
} }
@ -106,7 +106,10 @@ void CGameGeneralPage::ApplySettings(bool UpdateScreen)
bool CGameGeneralPage::EnableReset(void) bool CGameGeneralPage::EnableReset(void)
{ {
if (CSettingsPageImpl<CGameGeneralPage>::EnableReset()) { return true; } if (CSettingsPageImpl<CGameGeneralPage>::EnableReset())
{
return true;
}
return false; return false;
} }

View File

@ -1,7 +1,8 @@
#pragma once #pragma once
#include "../WTLControls/ModifiedCheckBox.h" #include <Project64\UserInterface\WTLControls\ModifiedCheckBox.h>
#include <Project64-core/N64System/N64Types.h> #include <Project64-core/N64System/N64Types.h>
#include "SettingsPage.h"
class CGameGeneralPage : class CGameGeneralPage :
public CSettingsPageImpl<CGameGeneralPage>, public CSettingsPageImpl<CGameGeneralPage>,

View File

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "SettingsPage.h"
#include "SettingsPage-Game-Plugin.h" #include "SettingsPage-Game-Plugin.h"
#include "SettingsPage.h"
CGamePluginPage::CGamePluginPage(HWND hParent, const RECT & rcDispay) CGamePluginPage::CGamePluginPage(HWND hParent, const RECT & rcDispay)
{ {
@ -116,7 +116,7 @@ void CGamePluginPage::ShowAboutButton(int id)
} }
// Get DLL about // Get DLL about
void(CALL *DllAbout) (HWND hWnd); void(CALL * DllAbout)(HWND hWnd);
DllAbout = (void(CALL *)(HWND))GetProcAddress(hLib, "DllAbout"); DllAbout = (void(CALL *)(HWND))GetProcAddress(hLib, "DllAbout");
// Call the function from the DLL // Call the function from the DLL
@ -190,7 +190,8 @@ void CGamePluginPage::UpdatePageSettings(void)
ComboBox->SetDefault((WPARAM)Plugin); ComboBox->SetDefault((WPARAM)Plugin);
} }
} }
else { else
{
ComboBox->SetDefault(NULL); ComboBox->SetDefault(NULL);
} }
} }
@ -217,7 +218,10 @@ void CGamePluginPage::ApplySettings(bool UpdateScreen)
bool CGamePluginPage::EnableReset(void) bool CGamePluginPage::EnableReset(void)
{ {
if (CSettingsPageImpl<CGamePluginPage>::EnableReset()) { return true; } if (CSettingsPageImpl<CGamePluginPage>::EnableReset())
{
return true;
}
return false; return false;
} }
@ -254,7 +258,8 @@ void CGamePluginPage::ApplyComboBoxes(void)
g_Settings->SaveString(cb_iter->first, Plugin->FileName.c_str()); g_Settings->SaveString(cb_iter->first, Plugin->FileName.c_str());
} }
} }
else { else
{
g_Settings->DeleteSetting(cb_iter->first); g_Settings->DeleteSetting(cb_iter->first);
} }
} }
@ -324,7 +329,7 @@ void CGamePluginPage::HleAudioChanged(UINT /*Code*/, int id, HWND /*ctl*/)
continue; continue;
} }
if ((Button->GetCheck() & BST_CHECKED) != 0) if ((Button->GetCheck() & BST_CHECKED) != 0)
{ {
if (!g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SET_HLE_AUD_MSG).c_str())) if (!g_Notify->AskYesNoQuestion(g_Lang->GetString(MSG_SET_HLE_AUD_MSG).c_str()))
{ {
Button->SetCheck(BST_UNCHECKED); Button->SetCheck(BST_UNCHECKED);

View File

@ -2,6 +2,7 @@
#include <Project64-core/Plugin.h> #include <Project64-core/Plugin.h>
#include <Project64/Plugins/PluginList.h> #include <Project64/Plugins/PluginList.h>
#include "SettingsPage.h"
class CGamePluginPage : class CGamePluginPage :
public CSettingsPageImpl<CGamePluginPage>, public CSettingsPageImpl<CGamePluginPage>,

View File

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "SettingsPage.h"
#include "SettingsPage-Game-Recompiler.h" #include "SettingsPage-Game-Recompiler.h"
#include "SettingsPage.h"
CGameRecompilePage::CGameRecompilePage(HWND hParent, const RECT & rcDispay) CGameRecompilePage::CGameRecompilePage(HWND hParent, const RECT & rcDispay)
{ {
@ -76,7 +76,10 @@ void CGameRecompilePage::ApplySettings(bool UpdateScreen)
bool CGameRecompilePage::EnableReset(void) bool CGameRecompilePage::EnableReset(void)
{ {
if (CSettingsPageImpl<CGameRecompilePage>::EnableReset()) { return true; } if (CSettingsPageImpl<CGameRecompilePage>::EnableReset())
{
return true;
}
return false; return false;
} }

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "SettingsPage.h"
class CGameRecompilePage : class CGameRecompilePage :
public CSettingsPageImpl<CGameRecompilePage>, public CSettingsPageImpl<CGameRecompilePage>,

View File

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "SettingsPage.h"
#include "SettingsPage-Game-Status.h" #include "SettingsPage-Game-Status.h"
#include "SettingsPage.h"
CGameStatusPage::CGameStatusPage(HWND hParent, const RECT & rcDispay) CGameStatusPage::CGameStatusPage(HWND hParent, const RECT & rcDispay)
{ {
@ -11,7 +11,7 @@ CGameStatusPage::CGameStatusPage(HWND hParent, const RECT & rcDispay)
} }
CIniFile RomIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str()); CIniFile RomIniFile(g_Settings->LoadStringVal(SupportFile_RomDatabase).c_str());
CIniFile::strlist Keys; CIniFile::strlist Keys;
RomIniFile.GetKeyList("ROM Status", Keys); RomIniFile.GetKeyList("ROM Status", Keys);
stdstr Status = UISettingsLoadStringVal(Rdb_Status); stdstr Status = UISettingsLoadStringVal(Rdb_Status);
@ -21,8 +21,14 @@ CGameStatusPage::CGameStatusPage(HWND hParent, const RECT & rcDispay)
{ {
for (CIniFile::strlist::iterator item = Keys.begin(); item != Keys.end(); item++) for (CIniFile::strlist::iterator item = Keys.begin(); item != Keys.end(); item++)
{ {
if (strstr(item->c_str(), ".Sel") != nullptr) { continue; } if (strstr(item->c_str(), ".Sel") != nullptr)
if (strstr(item->c_str(), ".Auto") != nullptr) { continue; } {
continue;
}
if (strstr(item->c_str(), ".Auto") != nullptr)
{
continue;
}
ComboBox->AddItem(stdstr(*item).ToUTF16().c_str(), item->c_str()); ComboBox->AddItem(stdstr(*item).ToUTF16().c_str(), item->c_str());
} }
ComboBox->SetTextField(GetDlgItem(IDC_STATUS_TEXT)); ComboBox->SetTextField(GetDlgItem(IDC_STATUS_TEXT));
@ -53,7 +59,10 @@ void CGameStatusPage::ApplySettings(bool UpdateScreen)
bool CGameStatusPage::EnableReset(void) bool CGameStatusPage::EnableReset(void)
{ {
if (CSettingsPageImpl<CGameStatusPage>::EnableReset()) { return true; } if (CSettingsPageImpl<CGameStatusPage>::EnableReset())
{
return true;
}
return false; return false;
} }

View File

@ -1,4 +1,5 @@
#pragma once #pragma once
#include "SettingsPage.h"
class CGameStatusPage : class CGameStatusPage :
public CSettingsPageImpl<CGameStatusPage>, public CSettingsPageImpl<CGameStatusPage>,

View File

@ -54,7 +54,10 @@ void COptionsGameBrowserPage::UpdateFieldList(const ROMBROWSER_FIELDS_LIST & Fie
continue; continue;
} }
int listCount = m_Using.GetCount(); int listCount = m_Using.GetCount();
if (Pos > listCount) { Pos = listCount; } if (Pos > listCount)
{
Pos = listCount;
}
m_Using.SetItemData(m_Using.InsertString(Pos, wGS(Fields[i].LangID()).c_str()), i); m_Using.SetItemData(m_Using.InsertString(Pos, wGS(Fields[i].LangID()).c_str()), i);
} }
} }
@ -66,13 +69,13 @@ void COptionsGameBrowserPage::UpdatePageSettings(void)
FixCtrlState(); FixCtrlState();
} }
void COptionsGameBrowserPage::UseRomBrowserChanged(UINT Code, int id, HWND ctl) void COptionsGameBrowserPage::UseRomBrowserChanged(UINT Code, int id, HWND ctl)
{ {
CheckBoxChanged(Code, id, ctl); CheckBoxChanged(Code, id, ctl);
FixCtrlState(); FixCtrlState();
} }
void COptionsGameBrowserPage::FixCtrlState(void) void COptionsGameBrowserPage::FixCtrlState(void)
{ {
bool bEnabled = (SendDlgItemMessage(IDC_USE_ROMBROWSER, BM_GETCHECK, 0, 0) == BST_CHECKED); bool bEnabled = (SendDlgItemMessage(IDC_USE_ROMBROWSER, BM_GETCHECK, 0, 0) == BST_CHECKED);
::EnableWindow(GetDlgItem(IDC_ROMSEL_TEXT5), bEnabled); ::EnableWindow(GetDlgItem(IDC_ROMSEL_TEXT5), bEnabled);
@ -99,7 +102,10 @@ void COptionsGameBrowserPage::AddFieldClicked(UINT /*Code*/, int /*id*/, HWND /*
// Select next in list // Select next in list
int listCount = m_Avaliable.GetCount(); int listCount = m_Avaliable.GetCount();
if (index >= listCount) { index -= 1; } if (index >= listCount)
{
index -= 1;
}
m_Avaliable.SetCurSel(index); m_Avaliable.SetCurSel(index);
// Add to list // Add to list
@ -125,7 +131,10 @@ void COptionsGameBrowserPage::RemoveFieldClicked(UINT /*Code*/, int /*id*/, HWND
// Select next in list // Select next in list
int listCount = m_Using.GetCount(); int listCount = m_Using.GetCount();
if (index >= listCount) { index -= 1; } if (index >= listCount)
{
index -= 1;
}
m_Using.SetCurSel(index); m_Using.SetCurSel(index);
// Add to list // Add to list
@ -231,7 +240,10 @@ void COptionsGameBrowserPage::ApplySettings(bool UpdateScreen)
bool COptionsGameBrowserPage::EnableReset(void) bool COptionsGameBrowserPage::EnableReset(void)
{ {
if (m_OrderChanged) { return true; } if (m_OrderChanged)
{
return true;
}
return CSettingsPageImpl<COptionsGameBrowserPage>::EnableReset(); return CSettingsPageImpl<COptionsGameBrowserPage>::EnableReset();
} }

View File

@ -218,7 +218,10 @@ void COptionsShortCutsPage::OnShortCutChanged(UINT /*Code*/, int /*id*/, HWND /*
{ {
// Get the virtual key info // Get the virtual key info
int index = m_VirtualKeyList.GetCurSel(); int index = m_VirtualKeyList.GetCurSel();
if (index < 0) { return; } if (index < 0)
{
return;
}
WORD key = (WORD)m_VirtualKeyList.GetItemData(index); WORD key = (WORD)m_VirtualKeyList.GetItemData(index);
bool bCtrl = (SendDlgItemMessage(IDC_CTL, BM_GETCHECK, 0, 0) == BST_CHECKED); bool bCtrl = (SendDlgItemMessage(IDC_CTL, BM_GETCHECK, 0, 0) == BST_CHECKED);
bool bAlt = (SendDlgItemMessage(IDC_ALT, BM_GETCHECK, 0, 0) == BST_CHECKED); bool bAlt = (SendDlgItemMessage(IDC_ALT, BM_GETCHECK, 0, 0) == BST_CHECKED);
@ -266,7 +269,7 @@ void COptionsShortCutsPage::RefreshShortCutOptions(HTREEITEM hItem)
} }
const std::wstring & Name = ShortCut_item->Name(); const std::wstring & Name = ShortCut_item->Name();
m_CurrentKeys.SetItemData(m_CurrentKeys.AddString(Name.c_str()), (DWORD_PTR)&*ShortCut_item); m_CurrentKeys.SetItemData(m_CurrentKeys.AddString(Name.c_str()), (DWORD_PTR) & *ShortCut_item);
} }
} }
@ -297,22 +300,39 @@ void COptionsShortCutsPage::InputGetKeys(void)
::EnableWindow(GetParent(), false); ::EnableWindow(GetParent(), false);
MSG msg; MSG msg;
for (bool fDone = false; !fDone; MsgWaitForMultipleObjects(0, nullptr, false, 45, QS_ALLINPUT)) { for (bool fDone = false; !fDone; MsgWaitForMultipleObjects(0, nullptr, false, 45, QS_ALLINPUT))
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { {
if (msg.message == WM_QUIT) { while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
fDone = true; fDone = true;
::PostMessage(nullptr, WM_QUIT, 0, 0); ::PostMessage(nullptr, WM_QUIT, 0, 0);
break; break;
} }
if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN) { if (msg.message == WM_KEYDOWN || msg.message == WM_SYSKEYDOWN)
{
int nVirtKey = (int)msg.wParam; int nVirtKey = (int)msg.wParam;
if (nVirtKey == VK_SHIFT) { continue; } if (nVirtKey == VK_SHIFT)
if (nVirtKey == VK_CONTROL) { continue; } {
if (nVirtKey == VK_MENU) { continue; } continue;
}
if (nVirtKey == VK_CONTROL)
{
continue;
}
if (nVirtKey == VK_MENU)
{
continue;
}
SendDlgItemMessage(IDC_VIRTUALKEY, CB_SETCURSEL, (WPARAM)-1, 0); SendDlgItemMessage(IDC_VIRTUALKEY, CB_SETCURSEL, (WPARAM)-1, 0);
for (int count = 0; count < SendDlgItemMessage(IDC_VIRTUALKEY, CB_GETCOUNT, 0, 0); count++) { for (int count = 0; count < SendDlgItemMessage(IDC_VIRTUALKEY, CB_GETCOUNT, 0, 0); count++)
{
int Data = (int)SendDlgItemMessage(IDC_VIRTUALKEY, CB_GETITEMDATA, count, 0); int Data = (int)SendDlgItemMessage(IDC_VIRTUALKEY, CB_GETITEMDATA, count, 0);
if (Data != nVirtKey) { continue; } if (Data != nVirtKey)
{
continue;
}
SendDlgItemMessage(IDC_VIRTUALKEY, CB_SETCURSEL, count, 0); SendDlgItemMessage(IDC_VIRTUALKEY, CB_SETCURSEL, count, 0);
SendDlgItemMessage(IDC_CTL, BM_SETCHECK, (GetKeyState(VK_CONTROL) & 0x80) != 0 ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(IDC_CTL, BM_SETCHECK, (GetKeyState(VK_CONTROL) & 0x80) != 0 ? BST_CHECKED : BST_UNCHECKED, 0);
SendDlgItemMessage(IDC_ALT, BM_SETCHECK, (GetKeyState(VK_MENU) & 0x80) != 0 ? BST_CHECKED : BST_UNCHECKED, 0); SendDlgItemMessage(IDC_ALT, BM_SETCHECK, (GetKeyState(VK_MENU) & 0x80) != 0 ? BST_CHECKED : BST_UNCHECKED, 0);
@ -323,13 +343,17 @@ void COptionsShortCutsPage::InputGetKeys(void)
} }
continue; continue;
} }
if (!::IsDialogMessage(hKeyDlg, &msg)) { if (!::IsDialogMessage(hKeyDlg, &msg))
{
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessage(&msg);
} }
} }
if (!::IsWindow(hKeyDlg)) { fDone = true; } if (!::IsWindow(hKeyDlg))
{
fDone = true;
}
} }
::SetFocus(GetParent()); ::SetFocus(GetParent());
::EnableWindow(GetParent(), true); ::EnableWindow(GetParent(), true);

View File

@ -3,7 +3,7 @@
#include "SettingsPage.h" #include "SettingsPage.h"
CGeneralOptionsPage::CGeneralOptionsPage(CSettingConfig * SettingsConfig, HWND hParent, const RECT & rcDispay) : CGeneralOptionsPage::CGeneralOptionsPage(CSettingConfig * SettingsConfig, HWND hParent, const RECT & rcDispay) :
m_SettingsConfig(SettingsConfig) m_SettingsConfig(SettingsConfig)
{ {
if (!Create(hParent, rcDispay)) if (!Create(hParent, rcDispay))
{ {
@ -25,7 +25,7 @@ m_SettingsConfig(SettingsConfig)
AddModCheckBox(GetDlgItem(IDC_AUTOSLEEP), (SettingID)Setting_AutoSleep); AddModCheckBox(GetDlgItem(IDC_AUTOSLEEP), (SettingID)Setting_AutoSleep);
AddModCheckBox(GetDlgItem(IDC_LOAD_FULLSCREEN), (SettingID)Setting_AutoFullscreen); AddModCheckBox(GetDlgItem(IDC_LOAD_FULLSCREEN), (SettingID)Setting_AutoFullscreen);
AddModCheckBox(GetDlgItem(IDC_SCREEN_SAVER), (SettingID)Setting_DisableScrSaver); AddModCheckBox(GetDlgItem(IDC_SCREEN_SAVER), (SettingID)Setting_DisableScrSaver);
AddModCheckBox(GetDlgItem(IDC_DISCORD_RPC), (SettingID)Setting_EnableDiscordRPC); AddModCheckBox(GetDlgItem(IDC_DISCORD_RPC), (SettingID)Setting_EnableDiscordRPC);
AddModCheckBox(GetDlgItem(IDC_BASIC_MODE), UserInterface_BasicMode); AddModCheckBox(GetDlgItem(IDC_BASIC_MODE), UserInterface_BasicMode);
CModifiedEditBox * TxtBox = AddModTextBox(GetDlgItem(IDC_REMEMBER), (SettingID)File_RecentGameFileCount, false); CModifiedEditBox * TxtBox = AddModTextBox(GetDlgItem(IDC_REMEMBER), (SettingID)File_RecentGameFileCount, false);
@ -54,7 +54,10 @@ void CGeneralOptionsPage::ApplySettings(bool UpdateScreen)
bool CGeneralOptionsPage::EnableReset(void) bool CGeneralOptionsPage::EnableReset(void)
{ {
if (CSettingsPageImpl<CGeneralOptionsPage>::EnableReset()) { return true; } if (CSettingsPageImpl<CGeneralOptionsPage>::EnableReset())
{
return true;
}
return false; return false;
} }

View File

@ -108,7 +108,7 @@ void COptionPluginPage::ShowAboutButton(int id)
} }
// Get DLL about // Get DLL about
void(CALL *DllAbout) (HWND hWnd); void(CALL * DllAbout)(HWND hWnd);
DllAbout = (void(CALL *)(HWND))GetProcAddress(hLib, "DllAbout"); DllAbout = (void(CALL *)(HWND))GetProcAddress(hLib, "DllAbout");
// Call the function from the DLL // Call the function from the DLL
@ -207,7 +207,10 @@ void COptionPluginPage::ApplySettings(bool UpdateScreen)
bool COptionPluginPage::EnableReset(void) bool COptionPluginPage::EnableReset(void)
{ {
if (CSettingsPageImpl<COptionPluginPage>::EnableReset()) { return true; } if (CSettingsPageImpl<COptionPluginPage>::EnableReset())
{
return true;
}
return false; return false;
} }

View File

@ -3,30 +3,30 @@
#include "SettingsPage.h" #include "SettingsPage.h"
CConfigSettingSection::CConfigSettingSection(LPCWSTR PageTitle) : CConfigSettingSection::CConfigSettingSection(LPCWSTR PageTitle) :
m_PageTitle(PageTitle) m_PageTitle(PageTitle)
{ {
} }
CConfigSettingSection::~CConfigSettingSection() CConfigSettingSection::~CConfigSettingSection()
{ {
for (size_t i = 0; i < m_Pages.size(); i++) for (size_t i = 0; i < m_Pages.size(); i++)
{ {
CSettingsPage * Page = m_Pages[i]; CSettingsPage * Page = m_Pages[i];
delete Page; delete Page;
} }
m_Pages.clear(); m_Pages.clear();
} }
void CConfigSettingSection::AddPage(CSettingsPage * Page) void CConfigSettingSection::AddPage(CSettingsPage * Page)
{ {
m_Pages.push_back(Page); m_Pages.push_back(Page);
} }
CSettingsPage * CConfigSettingSection::GetPage(int PageNo) CSettingsPage * CConfigSettingSection::GetPage(int PageNo)
{ {
if (PageNo < 0 || PageNo >= (int)m_Pages.size()) if (PageNo < 0 || PageNo >= (int)m_Pages.size())
{ {
return nullptr; return nullptr;
} }
return m_Pages[PageNo]; return m_Pages[PageNo];
} }

View File

@ -1,7 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "SettingsConfig.h"
#include "Settings/SettingsPage.h" #include "Settings/SettingsPage.h"
#include "SettingsConfig.h"
#include <Project64-core/Settings/SettingType/SettingsType-Application.h> #include <Project64-core/Settings/SettingType/SettingsType-Application.h>
CSettingConfig::CSettingConfig(bool bJustGameSetting /* = false */) : CSettingConfig::CSettingConfig(bool bJustGameSetting /* = false */) :

View File

@ -1,7 +1,8 @@
#include "stdafx.h" #include "stdafx.h"
#include "SupportEnterCode.h" #include "SupportEnterCode.h"
#include <Project64-core/Settings/SettingType/SettingsType-Application.h>
#include "resource.h" #include "resource.h"
#include <Project64-core/Settings/SettingType/SettingsType-Application.h>
class CRequestCode : class CRequestCode :
public CDialogImpl<CRequestCode> public CDialogImpl<CRequestCode>

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "SupportEnterCode.h" #include "SupportEnterCode.h"
#include <time.h> #include <time.h>
@ -56,7 +57,7 @@ void CSupportWindow::EnableContinue()
::EnableWindow(GetDlgItem(IDCANCEL), true); ::EnableWindow(GetDlgItem(IDCANCEL), true);
} }
LRESULT CSupportWindow::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CSupportWindow::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
m_Logo.SubclassWindow(GetDlgItem(IDC_BMP_LOGO)); m_Logo.SubclassWindow(GetDlgItem(IDC_BMP_LOGO));
m_Logo.SetBitmap(MAKEINTRESOURCE(IDB_ABOUT_LOGO)); m_Logo.SetBitmap(MAKEINTRESOURCE(IDB_ABOUT_LOGO));
@ -72,37 +73,37 @@ LRESULT CSupportWindow::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*
m_EnterLink.EnableWindow(!m_Support.Validated()); m_EnterLink.EnableWindow(!m_Support.Validated());
CWindow hInfo = GetDlgItem(IDC_INFO); CWindow hInfo = GetDlgItem(IDC_INFO);
CRect rcWin = { 0 }; CRect rcWin = {0};
hInfo.GetClientRect(&rcWin); hInfo.GetClientRect(&rcWin);
CDC hDC = hInfo.GetDC(); CDC hDC = hInfo.GetDC();
HFONT hFont = hInfo.GetFont(); HFONT hFont = hInfo.GetFont();
if(hFont == nullptr) if (hFont == nullptr)
{ {
hFont = (HFONT)::GetStockObject(SYSTEM_FONT); hFont = (HFONT)::GetStockObject(SYSTEM_FONT);
} }
hDC.SelectFont(hFont); hDC.SelectFont(hFont);
if (hDC.DrawText(InfoText.c_str(),InfoText.length(),&rcWin,DT_LEFT | DT_CALCRECT | DT_WORDBREAK | DT_NOCLIP) > 0) if (hDC.DrawText(InfoText.c_str(), InfoText.length(), &rcWin, DT_LEFT | DT_CALCRECT | DT_WORDBREAK | DT_NOCLIP) > 0)
{ {
hInfo.SetWindowPos(nullptr,0,0,rcWin.right, rcWin.bottom,SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOOWNERZORDER); hInfo.SetWindowPos(nullptr, 0, 0, rcWin.right, rcWin.bottom, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER);
} }
hInfo.SetWindowText(InfoText.c_str()); hInfo.SetWindowText(InfoText.c_str());
hInfo.GetWindowRect(&rcWin); hInfo.GetWindowRect(&rcWin);
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2); ::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2);
CWindow EnterCode = GetDlgItem(IDC_ENTER_CODE); CWindow EnterCode = GetDlgItem(IDC_ENTER_CODE);
EnterCode.SetWindowPos(nullptr,rcWin.left,rcWin.bottom + 4,0,0,SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOOWNERZORDER); EnterCode.SetWindowPos(nullptr, rcWin.left, rcWin.bottom + 4, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
EnterCode.GetWindowRect(&rcWin); EnterCode.GetWindowRect(&rcWin);
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2); ::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&rcWin, 2);
CWindow SupportBtn = GetDlgItem(ID_SUPPORT_PJ64); CWindow SupportBtn = GetDlgItem(ID_SUPPORT_PJ64);
RECT SupportBtnWin = { 0 }; RECT SupportBtnWin = {0};
SupportBtn.GetWindowRect(&SupportBtnWin); SupportBtn.GetWindowRect(&SupportBtnWin);
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&SupportBtnWin, 2); ::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&SupportBtnWin, 2);
SupportBtn.SetWindowPos(nullptr, SupportBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER); SupportBtn.SetWindowPos(nullptr, SupportBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
CWindow CancelBtn = GetDlgItem(IDCANCEL); CWindow CancelBtn = GetDlgItem(IDCANCEL);
RECT CancelBtnWin = { 0 }; RECT CancelBtnWin = {0};
CancelBtn.GetWindowRect(&CancelBtnWin); CancelBtn.GetWindowRect(&CancelBtnWin);
::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&CancelBtnWin, 2); ::MapWindowPoints(nullptr, m_hWnd, (LPPOINT)&CancelBtnWin, 2);
CancelBtn.SetWindowPos(nullptr, CancelBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER); CancelBtn.SetWindowPos(nullptr, CancelBtnWin.left, rcWin.bottom + 40, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOOWNERZORDER);
@ -114,7 +115,7 @@ LRESULT CSupportWindow::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*
AdjustWindowRectEx(&rcWin, GetStyle(), GetMenu() != nullptr, GetExStyle()); AdjustWindowRectEx(&rcWin, GetStyle(), GetMenu() != nullptr, GetExStyle());
int32_t Left = (GetSystemMetrics(SM_CXSCREEN) - rcWin.Width()) / 2; int32_t Left = (GetSystemMetrics(SM_CXSCREEN) - rcWin.Width()) / 2;
int32_t Top = (GetSystemMetrics(SM_CYSCREEN) - rcWin.Height()) / 2; int32_t Top = (GetSystemMetrics(SM_CYSCREEN) - rcWin.Height()) / 2;
MoveWindow(Left, Top, rcWin.Width(), rcWin.Height(), TRUE); MoveWindow(Left, Top, rcWin.Width(), rcWin.Height(), TRUE);
@ -127,13 +128,13 @@ LRESULT CSupportWindow::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*
SetWindowLong(GWL_STYLE, dwStyle); SetWindowLong(GWL_STYLE, dwStyle);
GetDlgItem(IDCANCEL).EnableWindow(false); GetDlgItem(IDCANCEL).EnableWindow(false);
srand ((uint32_t)time(nullptr)); srand((uint32_t)time(nullptr));
SetTimer(0, 1000, nullptr); SetTimer(0, 1000, nullptr);
} }
return TRUE; return TRUE;
} }
LRESULT CSupportWindow::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CSupportWindow::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
CDCHandle hdcStatic = (HDC)wParam; CDCHandle hdcStatic = (HDC)wParam;
hdcStatic.SetTextColor(RGB(0, 0, 0)); hdcStatic.SetTextColor(RGB(0, 0, 0));
@ -141,7 +142,7 @@ LRESULT CSupportWindow::OnColorStatic(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lPa
return (LONG)(LRESULT)((HBRUSH)GetStockObject(NULL_BRUSH)); return (LONG)(LRESULT)((HBRUSH)GetStockObject(NULL_BRUSH));
} }
LRESULT CSupportWindow::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CSupportWindow::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
static HPEN Outline = CreatePen(PS_SOLID, 1, 0x00FFFFFF); static HPEN Outline = CreatePen(PS_SOLID, 1, 0x00FFFFFF);
static HBRUSH Fill = CreateSolidBrush(0x00FFFFFF); static HBRUSH Fill = CreateSolidBrush(0x00FFFFFF);
@ -156,7 +157,7 @@ LRESULT CSupportWindow::OnEraseBackground(UINT /*uMsg*/, WPARAM wParam, LPARAM /
return TRUE; return TRUE;
} }
LRESULT CSupportWindow::OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CSupportWindow::OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
m_TimeOutTime -= 1; m_TimeOutTime -= 1;
if (m_TimeOutTime == 0) if (m_TimeOutTime == 0)
@ -169,21 +170,21 @@ LRESULT CSupportWindow::OnTimer(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/,
return true; return true;
} }
LRESULT CSupportWindow::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CSupportWindow::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
UISettingsSaveBool(UserInterface_ShowingNagWindow, false); UISettingsSaveBool(UserInterface_ShowingNagWindow, false);
EndDialog(wID); EndDialog(wID);
return TRUE; return TRUE;
} }
LRESULT CSupportWindow::OnSupportProject64(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CSupportWindow::OnSupportProject64(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
stdstr SupportURL = stdstr_f("https://www.pj64-emu.com/support-project64.html?ver=%s&machine=%s", VER_FILE_VERSION_STR, m_Support.MachineID()); stdstr SupportURL = stdstr_f("https://www.pj64-emu.com/support-project64.html?ver=%s&machine=%s", VER_FILE_VERSION_STR, m_Support.MachineID());
ShellExecute(nullptr, L"open", SupportURL.ToUTF16().c_str(), nullptr, nullptr, SW_SHOWMAXIMIZED); ShellExecute(nullptr, L"open", SupportURL.ToUTF16().c_str(), nullptr, nullptr, SW_SHOWMAXIMIZED);
return TRUE; return TRUE;
} }
LRESULT CSupportWindow::OnEnterCode(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) LRESULT CSupportWindow::OnEnterCode(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL & /*bHandled*/)
{ {
CSupportEnterCode EnterCodeWindow(m_Support); CSupportEnterCode EnterCodeWindow(m_Support);
EnterCodeWindow.DoModal(m_hWnd); EnterCodeWindow.DoModal(m_hWnd);

View File

@ -1,5 +1,3 @@
#include "stdafx.h"
#pragma once #pragma once
enum { enum {

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "EditNumber32.h" #include "EditNumber32.h"
CEditNumber32::CEditNumber32(void) : CEditNumber32::CEditNumber32(void) :
@ -72,7 +73,7 @@ bool CEditNumber32::IsHexConvertableText(LPTSTR _text)
for (; i < wcslen(_text); i++) for (; i < wcslen(_text); i++)
{ {
wchar_t c = _text[i]; wchar_t c = _text[i];
if (!(c >= 48 && c <= 57 || c >= L'A'&&c <= L'F' || c >= L'a'&&c <= L'f' || c == L' ')) if (!(c >= 48 && c <= 57 || c >= L'A' && c <= L'F' || c >= L'a' && c <= L'f' || c == L' '))
{ {
bPaste = false; bPaste = false;
break; break;
@ -83,7 +84,7 @@ bool CEditNumber32::IsHexConvertableText(LPTSTR _text)
void CEditNumber32::FormatClipboard() void CEditNumber32::FormatClipboard()
{ {
LPTSTR lptstr, lptstrCopy; LPTSTR lptstr, lptstrCopy;
HGLOBAL hglb; HGLOBAL hglb;
if (!this->OpenClipboard() || !IsClipboardFormatAvailable(CF_UNICODETEXT)) if (!this->OpenClipboard() || !IsClipboardFormatAvailable(CF_UNICODETEXT))
{ {
@ -95,7 +96,7 @@ void CEditNumber32::FormatClipboard()
lptstr = (LPTSTR)GlobalLock(hglb); lptstr = (LPTSTR)GlobalLock(hglb);
for (unsigned int i = 0; i < wcslen(lptstr); i++) for (unsigned int i = 0; i < wcslen(lptstr); i++)
{ {
if (lptstr[i] != L'X'&&lptstr[i] != L'x') if (lptstr[i] != L'X' && lptstr[i] != L'x')
{ {
lptstr[i] = (char)toupper(lptstr[i]); lptstr[i] = (char)toupper(lptstr[i]);
} }
@ -123,13 +124,13 @@ void CEditNumber32::FormatClipboard()
} }
} }
LRESULT CEditNumber32::OnValidateValue(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) LRESULT CEditNumber32::OnValidateValue(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & bHandled)
{ {
bHandled = true; bHandled = true;
return true; return true;
} }
LRESULT CEditNumber32::OnPaste(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) LRESULT CEditNumber32::OnPaste(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & bHandled)
{ {
// Paste // Paste
bHandled = false; bHandled = false;
@ -148,7 +149,7 @@ LRESULT CEditNumber32::OnPaste(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam
HGLOBAL hglb = GetClipboardData(CF_UNICODETEXT); HGLOBAL hglb = GetClipboardData(CF_UNICODETEXT);
if (hglb != nullptr) if (hglb != nullptr)
{ {
LPTSTR lptstr = (LPTSTR)GlobalLock(hglb); LPTSTR lptstr = (LPTSTR)GlobalLock(hglb);
// Check invalid hex string // Check invalid hex string
if (!IsHexConvertableText(lptstr)) if (!IsHexConvertableText(lptstr))
{ {
@ -164,7 +165,7 @@ LRESULT CEditNumber32::OnPaste(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam
return true; return true;
} }
LRESULT CEditNumber32::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) LRESULT CEditNumber32::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL & bHandled)
{ {
int start, end; int start, end;
GetSel(start, end); GetSel(start, end);
@ -192,7 +193,8 @@ LRESULT CEditNumber32::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
// Does not allow to delete '0' before x // Does not allow to delete '0' before x
bHandled = true; bHandled = true;
} }
else { else
{
bHandled = false; bHandled = false;
} }
return TRUE; return TRUE;
@ -214,7 +216,8 @@ LRESULT CEditNumber32::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
SendMessage(uMsg, L'x', lParam); SendMessage(uMsg, L'x', lParam);
bHandled = true; bHandled = true;
} }
else { else
{
bHandled = false; bHandled = false;
} }
return true; return true;
@ -324,7 +327,7 @@ void CEditNumber32::SetValue(uint32_t Value, DisplayMode Display)
} }
else else
{ {
text.Format("%s%0*X",(Display & DisplayMode::ShowHexIdent) == DisplayMode::ShowHexIdent ? "0x" : "", (Display & DisplayMode::ZeroExtend) == DisplayMode::ZeroExtend ? 8 : 0, Value); text.Format("%s%0*X", (Display & DisplayMode::ShowHexIdent) == DisplayMode::ShowHexIdent ? "0x" : "", (Display & DisplayMode::ZeroExtend) == DisplayMode::ZeroExtend ? 8 : 0, Value);
} }
SetWindowText(text.ToUTF16().c_str()); SetWindowText(text.ToUTF16().c_str());
} }

View File

@ -1,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "GetCWindowText.h" #include "GetCWindowText.h"
#include <Common/StdString.h> #include <Common/StdString.h>

View File

@ -1,6 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "HexEditCtrl.h" #include "HexEditCtrl.h"
#include <unordered_map> #include <unordered_map>
CHexEditCtrl::CHexEditCtrl(void) : CHexEditCtrl::CHexEditCtrl(void) :
m_BaseAddress(0x80000000), m_BaseAddress(0x80000000),
@ -54,9 +55,9 @@ CHexEditCtrl::~CHexEditCtrl(void)
{ {
} }
int CALLBACK CHexEditCtrl::HaveFontCb(CONST LOGFONTW* lplf, CONST TEXTMETRICW* /*lptm*/, DWORD /*FontType*/, LPARAM lParam) int CALLBACK CHexEditCtrl::HaveFontCb(CONST LOGFONTW * lplf, CONST TEXTMETRICW * /*lptm*/, DWORD /*FontType*/, LPARAM lParam)
{ {
const wchar_t * name = (const wchar_t*)lParam; const wchar_t * name = (const wchar_t *)lParam;
if (wcscmp(lplf->lfFaceName, name) == 0) if (wcscmp(lplf->lfFaceName, name) == 0)
{ {
return 0; return 0;
@ -64,7 +65,7 @@ int CALLBACK CHexEditCtrl::HaveFontCb(CONST LOGFONTW* lplf, CONST TEXTMETRICW* /
return 1; return 1;
} }
bool CHexEditCtrl::HaveFont(HDC hdc, const char* name) bool CHexEditCtrl::HaveFont(HDC hdc, const char * name)
{ {
if (EnumFonts(hdc, stdstr(name).ToUTF16().c_str(), HaveFontCb, (LPARAM)stdstr(name).ToUTF16().c_str()) == 0) if (EnumFonts(hdc, stdstr(name).ToUTF16().c_str(), HaveFontCb, (LPARAM)stdstr(name).ToUTF16().c_str()) == 0)
{ {
@ -93,7 +94,7 @@ BOOL CHexEditCtrl::Attach(HWND hWnd)
HDC hdc = GetDC(); HDC hdc = GetDC();
HBITMAP hOldBMP; HBITMAP hOldBMP;
HFONT hOldFont; HFONT hOldFont;
m_BackDC = CreateCompatibleDC(hdc); m_BackDC = CreateCompatibleDC(hdc);
m_BackBMP = CreateCompatibleBitmap(hdc, wndRc.Width(), wndRc.Height()); m_BackBMP = CreateCompatibleBitmap(hdc, wndRc.Width(), wndRc.Height());
@ -108,16 +109,16 @@ BOOL CHexEditCtrl::Attach(HWND hWnd)
if (HaveFont(hdc, "Consolas")) if (HaveFont(hdc, "Consolas"))
{ {
m_Font = CreateFont((int)(14 * dpiScale), 0, 0, 0, m_Font = CreateFont((int)(14 * dpiScale), 0, 0, 0,
FW_DONTCARE, FW_DONTCARE,
FALSE, FALSE,
FALSE, FALSE,
FALSE, FALSE,
DEFAULT_CHARSET, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, DEFAULT_QUALITY,
FF_DONTCARE | FIXED_PITCH, FF_DONTCARE | FIXED_PITCH,
L"Consolas"); L"Consolas");
} }
else else
{ {
@ -142,7 +143,7 @@ BOOL CHexEditCtrl::Attach(HWND hWnd)
SetTimer(TIMER_ID_AUTO_REFRESH, 20, nullptr); SetTimer(TIMER_ID_AUTO_REFRESH, 20, nullptr);
SetTimer(TIMER_ID_DRAG_SCROLL, 50, nullptr); SetTimer(TIMER_ID_DRAG_SCROLL, 50, nullptr);
ReleaseDC(hdc); ReleaseDC(hdc);
return TRUE; return TRUE;
@ -163,13 +164,13 @@ HWND CHexEditCtrl::Detach(void)
DeleteObject(m_BackBMP); DeleteObject(m_BackBMP);
m_BackBMP = nullptr; m_BackBMP = nullptr;
} }
if (m_BackDC != nullptr) if (m_BackDC != nullptr)
{ {
DeleteObject(m_BackDC); DeleteObject(m_BackDC);
m_BackDC = nullptr; m_BackDC = nullptr;
} }
if (m_Font != nullptr) if (m_Font != nullptr)
{ {
DeleteObject(m_Font); DeleteObject(m_Font);
@ -194,7 +195,7 @@ HWND CHexEditCtrl::Detach(void)
void CHexEditCtrl::Draw(void) void CHexEditCtrl::Draw(void)
{ {
Notify(HXN_REDRAWSTARTED); Notify(HXN_REDRAWSTARTED);
int startCellIndex = 0; int startCellIndex = 0;
uint32_t startAddress = m_BaseAddress; uint32_t startAddress = m_BaseAddress;
int numBytesToUpdate = m_NumVisibleBytes; int numBytesToUpdate = m_NumVisibleBytes;
@ -212,7 +213,7 @@ void CHexEditCtrl::Draw(void)
int numBytesScrolled = abs(rowDelta) * m_NumBytesPerRow; int numBytesScrolled = abs(rowDelta) * m_NumBytesPerRow;
int numBytesToShift = (m_NumVisibleBytes - numBytesScrolled) - m_NumBytesPerRow; int numBytesToShift = (m_NumVisibleBytes - numBytesScrolled) - m_NumBytesPerRow;
int shiftSrcIndex = 0, shiftDstIndex = 0; int shiftSrcIndex = 0, shiftDstIndex = 0;
numBytesToUpdate = numBytesScrolled + m_NumBytesPerRow; numBytesToUpdate = numBytesScrolled + m_NumBytesPerRow;
CRect rcScrollArea; CRect rcScrollArea;
@ -278,9 +279,9 @@ void CHexEditCtrl::Draw(void)
{ {
uint32_t address = startAddress + i; uint32_t address = startAddress + i;
HXBYTEINFO* oldByte = &m_OldBytes[startCellIndex + i]; HXBYTEINFO * oldByte = &m_OldBytes[startCellIndex + i];
HXBYTEINFO* newByte = &m_NewBytes[startCellIndex + i]; HXBYTEINFO * newByte = &m_NewBytes[startCellIndex + i];
if (IsSelected(address)) if (IsSelected(address))
{ {
// Override owner-provided colors if selected // Override owner-provided colors if selected
@ -311,14 +312,14 @@ void CHexEditCtrl::Draw(void)
// Check if a similar HXBYTEINFO has already been drawn // Check if a similar HXBYTEINFO has already been drawn
std::unordered_map<HXBYTEINFO, HXRECTPAIR>::const_iterator drawnByte = drawnByteRects.find(*newByte); std::unordered_map<HXBYTEINFO, HXRECTPAIR>::const_iterator drawnByte = drawnByteRects.find(*newByte);
if (drawnByte != drawnByteRects.end()) if (drawnByte != drawnByteRects.end())
{ {
HXRECTPAIR src = drawnByte->second; HXRECTPAIR src = drawnByte->second;
BitBlt(m_BackDC, rcHex.left, rcHex.top, src.rcHex.Width(), src.rcHex.Height(), BitBlt(m_BackDC, rcHex.left, rcHex.top, src.rcHex.Width(), src.rcHex.Height(),
m_BackDC, src.rcHex.left, src.rcHex.top, SRCCOPY); m_BackDC, src.rcHex.left, src.rcHex.top, SRCCOPY);
BitBlt(m_BackDC, rcAscii.left, rcAscii.top, src.rcAscii.Width(), src.rcAscii.Height(), BitBlt(m_BackDC, rcAscii.left, rcAscii.top, src.rcAscii.Width(), src.rcAscii.Height(),
m_BackDC, src.rcAscii.left, src.rcAscii.top, SRCCOPY); m_BackDC, src.rcAscii.left, src.rcAscii.top, SRCCOPY);
InvalidateRect(&rcHex, false); InvalidateRect(&rcHex, false);
InvalidateRect(&rcAscii, false); InvalidateRect(&rcAscii, false);
} }
@ -376,13 +377,13 @@ void CHexEditCtrl::Draw(void)
UpdateCaretUI(false); UpdateCaretUI(false);
} }
void CHexEditCtrl::HitTest(int x, int y, HXHITTEST* pht) void CHexEditCtrl::HitTest(int x, int y, HXHITTEST * pht)
{ {
memset(pht, 0, sizeof(HXHITTEST)); memset(pht, 0, sizeof(HXHITTEST));
pht->column = HX_COL_NONE; pht->column = HX_COL_NONE;
CPoint pt(x, y); CPoint pt(x, y);
if (PtInRect(&m_AddressColumnRect, pt)) if (PtInRect(&m_AddressColumnRect, pt))
{ {
pht->column = HX_COL_ADDRESS; pht->column = HX_COL_ADDRESS;
@ -396,7 +397,7 @@ void CHexEditCtrl::HitTest(int x, int y, HXHITTEST* pht)
row = min(m_NumVisibleRows - 1, row); row = min(m_NumVisibleRows - 1, row);
uint32_t rowAddress = SatAdd32(m_BaseAddress, row * m_NumBytesPerRow); uint32_t rowAddress = SatAdd32(m_BaseAddress, row * m_NumBytesPerRow);
if (x >= m_HexDataColumnRect.left && x < m_HexDataColumnRect.right) if (x >= m_HexDataColumnRect.left && x < m_HexDataColumnRect.right)
{ {
if (PtInRect(&m_HexDataColumnRect, pt)) if (PtInRect(&m_HexDataColumnRect, pt))
@ -411,7 +412,7 @@ void CHexEditCtrl::HitTest(int x, int y, HXHITTEST* pht)
uint32_t address = SatAdd32(rowAddress, nGroup * m_NumBytesPerGroup + groupCharIdx / 2); uint32_t address = SatAdd32(rowAddress, nGroup * m_NumBytesPerGroup + groupCharIdx / 2);
pht->hexAddress = address; pht->hexAddress = address;
pht->hexCellSide = (groupCharIdx & 1) ? HX_RIGHT : HX_LEFT; // TODO: Fix for wrap pht->hexCellSide = (groupCharIdx & 1) ? HX_RIGHT : HX_LEFT; // TODO: Fix for wrap
pht->asciiAddress = address; // Approximate pht->asciiAddress = address; // Approximate
pht->asciiCellSide = HX_LEFT; pht->asciiCellSide = HX_LEFT;
} }
else if (x >= m_AsciiColumnRect.left && x < m_AsciiColumnRect.right) else if (x >= m_AsciiColumnRect.left && x < m_AsciiColumnRect.right)
@ -506,7 +507,7 @@ bool CHexEditCtrl::UpdateCaretUI(bool bEnsureVisible, bool bTop)
return true; return true;
} }
void CHexEditCtrl::Text(int x, int y, const char *text, COLORREF bg, COLORREF fg, CRect *rcOut) void CHexEditCtrl::Text(int x, int y, const char * text, COLORREF bg, COLORREF fg, CRect * rcOut)
{ {
std::wstring textOuput = stdstr(text).ToUTF16(CP_ACP); std::wstring textOuput = stdstr(text).ToUTF16(CP_ACP);
size_t length = textOuput.length(); size_t length = textOuput.length();
@ -551,7 +552,7 @@ void CHexEditCtrl::UpdateRealSelection(void)
swap(start, end); swap(start, end);
} }
else if(start == end) else if (start == end)
{ {
if (m_SelStartCellSide == m_SelEndCellSide) if (m_SelStartCellSide == m_SelEndCellSide)
{ {
@ -600,7 +601,7 @@ void CHexEditCtrl::DrawHeader()
{ {
CRect rcClient; CRect rcClient;
GetClientRect(&rcClient); GetClientRect(&rcClient);
CRect rcHeader = { 0, 0, rcClient.Width(), m_CharHeight }; CRect rcHeader = {0, 0, rcClient.Width(), m_CharHeight};
HBRUSH br = CreateSolidBrush(BKCOLOR_ADDR); HBRUSH br = CreateSolidBrush(BKCOLOR_ADDR);
FillRect(m_BackDC, &rcHeader, br); FillRect(m_BackDC, &rcHeader, br);
DeleteObject(br); DeleteObject(br);
@ -618,7 +619,7 @@ void CHexEditCtrl::DrawHeader()
InvalidateRect(&rcHeader, false); InvalidateRect(&rcHeader, false);
} }
void CHexEditCtrl::GetHexCellPos(int index, CRect* rc) void CHexEditCtrl::GetHexCellPos(int index, CRect * rc)
{ {
int nRow = index / m_NumBytesPerRow; int nRow = index / m_NumBytesPerRow;
int rowOffs = (index % m_NumBytesPerRow); int rowOffs = (index % m_NumBytesPerRow);
@ -628,7 +629,7 @@ void CHexEditCtrl::GetHexCellPos(int index, CRect* rc)
int addrColumnWidth = (m_CharWidth * 11); int addrColumnWidth = (m_CharWidth * 11);
int byteWidth = (m_CharWidth * 2); int byteWidth = (m_CharWidth * 2);
int hexGroupWidth = (byteWidth * m_NumBytesPerGroup) + (m_CharWidth * 1); int hexGroupWidth = (byteWidth * m_NumBytesPerGroup) + (m_CharWidth * 1);
int headerHeight = m_CharHeight; int headerHeight = m_CharHeight;
rc->left = addrColumnWidth + (nGroup * hexGroupWidth) + (byteOffs * byteWidth); rc->left = addrColumnWidth + (nGroup * hexGroupWidth) + (byteOffs * byteWidth);
@ -637,7 +638,7 @@ void CHexEditCtrl::GetHexCellPos(int index, CRect* rc)
rc->bottom = rc->top + m_CharHeight; rc->bottom = rc->top + m_CharHeight;
} }
void CHexEditCtrl::GetAsciiCellPos(int index, CRect* rc) void CHexEditCtrl::GetAsciiCellPos(int index, CRect * rc)
{ {
int nRow = index / m_NumBytesPerRow; int nRow = index / m_NumBytesPerRow;
int rowOffs = (index % m_NumBytesPerRow); int rowOffs = (index % m_NumBytesPerRow);
@ -713,7 +714,7 @@ void CHexEditCtrl::OnTimer(UINT_PTR nIDEvent)
{ {
int numBytesToScroll = m_DragScrollDelta * m_NumBytesPerRow; int numBytesToScroll = m_DragScrollDelta * m_NumBytesPerRow;
int64_t newCaretAddress = (int64_t)m_CaretAddress + numBytesToScroll; int64_t newCaretAddress = (int64_t)m_CaretAddress + numBytesToScroll;
if (newCaretAddress < 0 && m_BaseAddress == 0) if (newCaretAddress < 0 && m_BaseAddress == 0)
{ {
return; return;
@ -740,11 +741,11 @@ void CHexEditCtrl::OnPaint(CDCHandle dc)
CRect rc = ps.rcPaint; CRect rc = ps.rcPaint;
BitBlt(hdc, BitBlt(hdc,
rc.left, rc.top, rc.left, rc.top,
rc.Width(), rc.Height(), rc.Width(), rc.Height(),
m_BackDC, m_BackDC,
rc.left, rc.top, rc.left, rc.top,
SRCCOPY); SRCCOPY);
EndPaint(&ps); EndPaint(&ps);
} }
@ -800,7 +801,7 @@ void CHexEditCtrl::OnLButtonDown(UINT nFlags, CPoint point)
HitTest(point.x, point.y, &ht); HitTest(point.x, point.y, &ht);
m_FocusedColumn = ht.column; m_FocusedColumn = ht.column;
if (m_FocusedColumn == HX_COL_HEXDATA) if (m_FocusedColumn == HX_COL_HEXDATA)
{ {
m_CaretAddress = ht.hexAddress; m_CaretAddress = ht.hexAddress;
@ -811,7 +812,7 @@ void CHexEditCtrl::OnLButtonDown(UINT nFlags, CPoint point)
m_SelEndAddress = ht.hexAddress; m_SelEndAddress = ht.hexAddress;
m_SelEndCellSide = ht.hexCellSide; m_SelEndCellSide = ht.hexCellSide;
UpdateRealSelection(); UpdateRealSelection();
if (GetSelDirection() > 0) if (GetSelDirection() > 0)
{ {
m_CaretAddress = m_RealSelEndAddress + 1; m_CaretAddress = m_RealSelEndAddress + 1;
@ -1080,7 +1081,7 @@ void CHexEditCtrl::OnChar(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/)
{ {
m_CaretAddress = m_SelEndAddress; m_CaretAddress = m_SelEndAddress;
} }
else if(selDirection > 0) else if (selDirection > 0)
{ {
m_CaretAddress = m_SelStartAddress; m_CaretAddress = m_SelStartAddress;
} }
@ -1156,7 +1157,7 @@ int CHexEditCtrl::GetNumBytesPerGroup(void)
return m_NumBytesPerGroup; return m_NumBytesPerGroup;
} }
bool CHexEditCtrl::GetSelectionRange(uint32_t* startAddress, uint32_t* endAddress) bool CHexEditCtrl::GetSelectionRange(uint32_t * startAddress, uint32_t * endAddress)
{ {
*startAddress = m_RealSelStartAddress; *startAddress = m_RealSelStartAddress;
*endAddress = m_RealSelEndAddress; *endAddress = m_RealSelEndAddress;
@ -1208,7 +1209,6 @@ void CHexEditCtrl::OnKeyDown(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/)
} }
} }
if (nChar == VK_DOWN) if (nChar == VK_DOWN)
{ {
m_CaretAddress = SatAdd32(m_CaretAddress, m_NumBytesPerRow); m_CaretAddress = SatAdd32(m_CaretAddress, m_NumBytesPerRow);
@ -1228,7 +1228,7 @@ void CHexEditCtrl::OnKeyDown(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/)
{ {
CancelSelection(); CancelSelection();
} }
UpdateCaretUI(true); UpdateCaretUI(true);
} }
else if (nChar == VK_UP) else if (nChar == VK_UP)
@ -1250,7 +1250,7 @@ void CHexEditCtrl::OnKeyDown(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/)
{ {
CancelSelection(); CancelSelection();
} }
UpdateCaretUI(true); UpdateCaretUI(true);
} }
else if (nChar == VK_RIGHT) else if (nChar == VK_RIGHT)
@ -1313,7 +1313,7 @@ void CHexEditCtrl::OnKeyDown(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/)
{ {
if (m_FocusedColumn == HX_COL_HEXDATA) if (m_FocusedColumn == HX_COL_HEXDATA)
{ {
if(GetKeyState(VK_SHIFT) & 0x8000) if (GetKeyState(VK_SHIFT) & 0x8000)
{ {
m_SelEndCellSide = HX_LEFT; m_SelEndCellSide = HX_LEFT;
m_SelEndAddress--; m_SelEndAddress--;
@ -1437,10 +1437,10 @@ void CHexEditCtrl::OnKeyDown(UINT nChar, UINT /*nRepCnt*/, UINT /*nFlags*/)
int CHexEditCtrl::GetSelDirection(void) int CHexEditCtrl::GetSelDirection(void)
{ {
if (m_SelStartAddress < m_SelEndAddress) return 1; // Right if (m_SelStartAddress < m_SelEndAddress) return 1; // Right
if (m_SelStartAddress > m_SelEndAddress) return -1; // Left if (m_SelStartAddress > m_SelEndAddress) return -1; // Left
if (m_SelStartCellSide == m_SelEndCellSide) return 0; // No selection if (m_SelStartCellSide == m_SelEndCellSide) return 0; // No selection
if (m_SelStartCellSide == HX_LEFT && m_SelEndCellSide == HX_RIGHT) return 1; // Right (single byte) if (m_SelStartCellSide == HX_LEFT && m_SelEndCellSide == HX_RIGHT) return 1; // Right (single byte)
if (m_SelStartCellSide == HX_RIGHT && m_SelEndCellSide == HX_LEFT) return -1; // Left (single byte) if (m_SelStartCellSide == HX_RIGHT && m_SelEndCellSide == HX_LEFT) return -1; // Left (single byte)
return 0; return 0;
} }
@ -1500,56 +1500,56 @@ void CHexEditCtrl::EnsureCaretAddressVisible(bool bTop)
LRESULT CHexEditCtrl::Notify(UINT code) LRESULT CHexEditCtrl::Notify(UINT code)
{ {
UINT_PTR nID = ::GetDlgCtrlID(m_hWnd); UINT_PTR nID = ::GetDlgCtrlID(m_hWnd);
NMHDR nmh = { m_hWnd, nID, code }; NMHDR nmh = {m_hWnd, nID, code};
return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmh); return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmh);
} }
LRESULT CHexEditCtrl::NotifySetByte(uint32_t address, uint8_t value) LRESULT CHexEditCtrl::NotifySetByte(uint32_t address, uint8_t value)
{ {
UINT_PTR nID = ::GetDlgCtrlID(m_hWnd); UINT_PTR nID = ::GetDlgCtrlID(m_hWnd);
NMHXSETBYTE nmsb = { { m_hWnd, nID, HXN_SETBYTE }, m_bInsertMode, address, value }; NMHXSETBYTE nmsb = {{m_hWnd, nID, HXN_SETBYTE}, m_bInsertMode, address, value};
return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmsb); return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmsb);
} }
LRESULT CHexEditCtrl::NotifySetNibble(uint32_t address, bool bLoNibble, uint8_t value) LRESULT CHexEditCtrl::NotifySetNibble(uint32_t address, bool bLoNibble, uint8_t value)
{ {
UINT_PTR nID = ::GetDlgCtrlID(m_hWnd); UINT_PTR nID = ::GetDlgCtrlID(m_hWnd);
NMHXSETNIBBLE nmsn = { { m_hWnd, nID, HXN_SETNIBBLE }, m_bInsertMode, address, bLoNibble, value }; NMHXSETNIBBLE nmsn = {{m_hWnd, nID, HXN_SETNIBBLE}, m_bInsertMode, address, bLoNibble, value};
return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmsn); return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmsn);
} }
LRESULT CHexEditCtrl::NotifyFillRange(uint32_t startAddress, uint32_t endAddress, uint8_t value) LRESULT CHexEditCtrl::NotifyFillRange(uint32_t startAddress, uint32_t endAddress, uint8_t value)
{ {
UINT_PTR nID = ::GetDlgCtrlID(m_hWnd); UINT_PTR nID = ::GetDlgCtrlID(m_hWnd);
NMHXFILLRANGE nmfr = { { m_hWnd, nID, HXN_FILLRANGE }, m_bInsertMode, startAddress, endAddress, value }; NMHXFILLRANGE nmfr = {{m_hWnd, nID, HXN_FILLRANGE}, m_bInsertMode, startAddress, endAddress, value};
return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmfr); return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmfr);
} }
LRESULT CHexEditCtrl::NotifyCtrlKeyPressed(int nChar) LRESULT CHexEditCtrl::NotifyCtrlKeyPressed(int nChar)
{ {
UINT_PTR nID = ::GetDlgCtrlID(m_hWnd); UINT_PTR nID = ::GetDlgCtrlID(m_hWnd);
NMHXCTRLKEYPRESSED nmck = { { m_hWnd, nID, HXN_CTRLKEYPRESSED }, nChar }; NMHXCTRLKEYPRESSED nmck = {{m_hWnd, nID, HXN_CTRLKEYPRESSED}, nChar};
return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmck); return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmck);
} }
LRESULT CHexEditCtrl::NotifyPaste(uint32_t address) LRESULT CHexEditCtrl::NotifyPaste(uint32_t address)
{ {
UINT_PTR nID = ::GetDlgCtrlID(m_hWnd); UINT_PTR nID = ::GetDlgCtrlID(m_hWnd);
NMHXPASTE nmp = { { m_hWnd, nID, HXN_PASTE }, address, m_FocusedColumn }; NMHXPASTE nmp = {{m_hWnd, nID, HXN_PASTE}, address, m_FocusedColumn};
return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmp); return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmp);
} }
LRESULT CHexEditCtrl::NotifyRightClick(uint32_t address) LRESULT CHexEditCtrl::NotifyRightClick(uint32_t address)
{ {
UINT_PTR nID = ::GetDlgCtrlID(m_hWnd); UINT_PTR nID = ::GetDlgCtrlID(m_hWnd);
NMHXRCLICK nmrc = { { m_hWnd, nID, HXN_RCLICK }, address }; NMHXRCLICK nmrc = {{m_hWnd, nID, HXN_RCLICK}, address};
return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmrc); return ::SendMessage(GetParent(), WM_NOTIFY, (WPARAM)nID, (LPARAM)&nmrc);
} }
LRESULT CHexEditCtrl::NotifyGetByteInfo(uint32_t address, size_t numBytes, bool bIgnoreDiff, HXBYTEINFO* oldBytes, HXBYTEINFO* newBytes) LRESULT CHexEditCtrl::NotifyGetByteInfo(uint32_t address, size_t numBytes, bool bIgnoreDiff, HXBYTEINFO * oldBytes, HXBYTEINFO * newBytes)
{ {
UINT_PTR nID = ::GetDlgCtrlID(m_hWnd); UINT_PTR nID = ::GetDlgCtrlID(m_hWnd);
NMHXGETBYTEINFO nmgbi = { { m_hWnd, nID, HXN_GETBYTEINFO }, address, numBytes, bIgnoreDiff, oldBytes, newBytes }; NMHXGETBYTEINFO nmgbi = {{m_hWnd, nID, HXN_GETBYTEINFO}, address, numBytes, bIgnoreDiff, oldBytes, newBytes};
return ::SendMessage(GetParent(), WM_NOTIFY, nmgbi.nmh.idFrom, (LPARAM)&nmgbi); return ::SendMessage(GetParent(), WM_NOTIFY, nmgbi.nmh.idFrom, (LPARAM)&nmgbi);
} }
@ -1622,7 +1622,7 @@ COLORREF CHexEditCtrl::BlendColor(COLORREF c1, COLORREF c2)
int r2 = GetRValue(c2); int r2 = GetRValue(c2);
int g2 = GetGValue(c2); int g2 = GetGValue(c2);
int b2 = GetBValue(c2); int b2 = GetBValue(c2);
return RGB((r1+r2*2)/3, (g1+g2*2)/3, (b1+b2*2)/3); return RGB((r1 + r2 * 2) / 3, (g1 + g2 * 2) / 3, (b1 + b2 * 2) / 3);
} }
void CHexEditCtrl::UpdateLayoutInfo(void) void CHexEditCtrl::UpdateLayoutInfo(void)
@ -1654,22 +1654,22 @@ void CHexEditCtrl::UpdateLayoutInfo(void)
int columnsTop = 0 + headerHeight; int columnsTop = 0 + headerHeight;
int columnsBottom = columnsTop + m_NumVisibleRows * m_CharHeight; int columnsBottom = columnsTop + m_NumVisibleRows * m_CharHeight;
m_AddressColumnRect = { addressColumnLeft, columnsTop, addressColumnRight, columnsBottom }; m_AddressColumnRect = {addressColumnLeft, columnsTop, addressColumnRight, columnsBottom};
m_HexDataColumnRect = { hexDataColumnLeft, columnsTop, hexDataColumnRight, columnsBottom }; m_HexDataColumnRect = {hexDataColumnLeft, columnsTop, hexDataColumnRight, columnsBottom};
m_AsciiColumnRect = { asciiColumnLeft, columnsTop, asciiColumnRight, columnsBottom }; m_AsciiColumnRect = {asciiColumnLeft, columnsTop, asciiColumnRight, columnsBottom};
m_bLayoutChanged = true; m_bLayoutChanged = true;
} }
void CHexEditCtrl::ReallocByteBuffers(void) void CHexEditCtrl::ReallocByteBuffers(void)
{ {
m_NewBytes = (HXBYTEINFO*)realloc(m_NewBytes, m_NumVisibleBytes * sizeof(HXBYTEINFO)); m_NewBytes = (HXBYTEINFO *)realloc(m_NewBytes, m_NumVisibleBytes * sizeof(HXBYTEINFO));
m_OldBytes = (HXBYTEINFO*)realloc(m_OldBytes, m_NumVisibleBytes * sizeof(HXBYTEINFO)); m_OldBytes = (HXBYTEINFO *)realloc(m_OldBytes, m_NumVisibleBytes * sizeof(HXBYTEINFO));
for (int i = 0; i < m_NumVisibleBytes; i++) for (int i = 0; i < m_NumVisibleBytes; i++)
{ {
m_NewBytes[i] = { 0 }; m_NewBytes[i] = {0};
m_OldBytes[i] = { 0 }; m_OldBytes[i] = {0};
} }
} }
@ -1722,6 +1722,6 @@ void CHexEditCtrl::SetByteGroupSize(int nBytes)
int addressColumnWidth = 11 * m_CharWidth; int addressColumnWidth = 11 * m_CharWidth;
int headerHeight = m_CharHeight; int headerHeight = m_CharHeight;
CRect rcInv = { addressColumnWidth, headerHeight, rc.Width(), rc.Height() }; CRect rcInv = {addressColumnWidth, headerHeight, rc.Width(), rc.Height()};
InvalidateRect(&rcInv, true); InvalidateRect(&rcInv, true);
} }

Some files were not shown because too many files have changed in this diff Show More