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

@ -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));
@ -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);
@ -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());
@ -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,7 +280,7 @@ 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);
@ -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);
@ -413,7 +414,7 @@ void CCheatList::RefreshItems()
} }
} }
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());
@ -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,14 +308,14 @@ 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)
{ {
@ -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),

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>
@ -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)
{ {
@ -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,4 +1,4 @@
#include <stdafx.h> #include "stdafx.h"
#include "DebugMMU.h" #include "DebugMMU.h"
#include <Common/MemoryManagement.h> #include <Common/MemoryManagement.h>
@ -6,14 +6,14 @@
#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;
@ -22,15 +22,15 @@ uint8_t* CDebugMMU::GetPhysicalPtr(uint32_t paddr, WORD* flags)
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)
{ {
@ -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)
@ -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,7 +15,7 @@ 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;
@ -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();
@ -45,7 +45,7 @@ LRESULT CAddSymbolDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*l
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)
{ {
@ -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();
@ -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)
{ {
@ -132,14 +133,14 @@ LRESULT CDebugCPULogView::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND, BOOL&
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);
@ -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;
@ -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)
{ {
@ -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
@ -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;
@ -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);
@ -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;
@ -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;
@ -43,7 +44,7 @@ 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;
@ -84,7 +85,7 @@ void CDebugDMALogView::RefreshList()
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))
//{ //{
@ -99,17 +100,17 @@ void CDebugDMALogView::RefreshList()
{ {
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++;
@ -135,12 +136,12 @@ void CDebugDMALogView::Export(void)
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,7 +175,7 @@ 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);
@ -184,13 +185,13 @@ void CDebugDMALogView::Export(void)
} }
} }
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);
@ -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)
{ {
@ -324,7 +325,7 @@ LRESULT CDebugDMALogView::OnRamAddrChanged(WORD /*wNotifyCode*/, WORD /*wID*/, H
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)
@ -383,11 +383,11 @@ LRESULT CDebugDMALogView::OnCustomDrawList(NMHDR* pNMHDR)
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)
{ {

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)
{ {
@ -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);
@ -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)
{ {
@ -94,7 +94,7 @@ 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();

View File

@ -1,22 +1,23 @@
#include "stdafx.h" #include "stdafx.h"
#include "DebuggerUI.h" #include "DebuggerUI.h"
#include "MemoryScanner.h" #include "MemoryScanner.h"
CDebugMemorySearch* CDebugMemorySearch::_this = nullptr; CDebugMemorySearch * CDebugMemorySearch::_this = nullptr;
HHOOK CDebugMemorySearch::hWinMessageHook = nullptr; HHOOK CDebugMemorySearch::hWinMessageHook = nullptr;
const CSetValueDlg::ComboItem CDebugMemorySearch::ModalChangeTypeItems[] = { const CSetValueDlg::ComboItem CDebugMemorySearch::ModalChangeTypeItems[] = {
{ "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},
{ "string", ValueType_string }, {"string", ValueType_string},
{ nullptr, 0 } { nullptr, 0 }
}; };
@ -29,7 +30,7 @@ CDebugMemorySearch::~CDebugMemorySearch()
{ {
} }
LRESULT CDebugMemorySearch::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
DlgSavePos_Init(DebuggerUI_MemorySearchPos); DlgSavePos_Init(DebuggerUI_MemorySearchPos);
DlgResize_Init(false, true); DlgResize_Init(false, true);
@ -156,7 +157,7 @@ void CDebugMemorySearch::GameReset(void)
SendMessage(WM_GAMERESET); SendMessage(WM_GAMERESET);
} }
LRESULT CDebugMemorySearch::OnGameReset(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnGameReset(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
ReloadWatchList(); ReloadWatchList();
return FALSE; return FALSE;
@ -186,7 +187,7 @@ void CDebugMemorySearch::OnTimer(UINT_PTR nIDEvent)
LRESULT CALLBACK CDebugMemorySearch::HookProc(int nCode, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK CDebugMemorySearch::HookProc(int nCode, WPARAM wParam, LPARAM lParam)
{ {
MSG *pMsg = (MSG*)lParam; MSG * pMsg = (MSG *)lParam;
switch (pMsg->message) switch (pMsg->message)
{ {
@ -219,20 +220,20 @@ void CDebugMemorySearch::OnSizing(UINT /*fwSide*/, LPRECT /*pRect*/)
SetMsgHandled(FALSE); SetMsgHandled(FALSE);
} }
LRESULT CDebugMemorySearch::OnCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
EndDialog(0); EndDialog(0);
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnHexCheckbox(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnHexCheckbox(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
bool bChecked = (m_HexCheckbox.GetCheck() == BST_CHECKED); bool bChecked = (m_HexCheckbox.GetCheck() == BST_CHECKED);
m_SearchValue.SetDisplayFormat(bChecked ? DisplayHex : DisplayDefault); m_SearchValue.SetDisplayFormat(bChecked ? DisplayHex : DisplayDefault);
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnSearchButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnSearchButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_SearchMemory); g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_SearchMemory);
Search(); Search();
@ -242,13 +243,13 @@ LRESULT CDebugMemorySearch::OnSearchButton(WORD /*wNotifyCode*/, WORD /*wID*/, H
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnResetButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnResetButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
ResetResults(); ResetResults();
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnScanTypeChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnScanTypeChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
SearchType searchType = (SearchType)m_SearchTypeOptions.GetItemData(m_SearchTypeOptions.GetCurSel()); SearchType searchType = (SearchType)m_SearchTypeOptions.GetItemData(m_SearchTypeOptions.GetCurSel());
@ -273,7 +274,7 @@ LRESULT CDebugMemorySearch::OnScanTypeChanged(WORD /*wNotifyCode*/, WORD /*wID*/
m_UnsignedCheckbox.SetCheck(BST_CHECKED); m_UnsignedCheckbox.SetCheck(BST_CHECKED);
m_UnsignedCheckbox.EnableWindow(FALSE); m_UnsignedCheckbox.EnableWindow(FALSE);
} }
else if(m_bJalSelected) else if (m_bJalSelected)
{ {
m_bJalSelected = false; m_bJalSelected = false;
m_SearchValue.SetDisplayFormat(m_bJalHexWasChecked ? DisplayHex : DisplayDefault); m_SearchValue.SetDisplayFormat(m_bJalHexWasChecked ? DisplayHex : DisplayDefault);
@ -304,7 +305,7 @@ LRESULT CDebugMemorySearch::OnScanTypeChanged(WORD /*wNotifyCode*/, WORD /*wID*/
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnValueTypeChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnValueTypeChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
ValueType valueType = (ValueType)m_ValueTypeOptions.GetItemData(m_ValueTypeOptions.GetCurSel()); ValueType valueType = (ValueType)m_ValueTypeOptions.GetItemData(m_ValueTypeOptions.GetCurSel());
@ -332,7 +333,7 @@ LRESULT CDebugMemorySearch::OnValueTypeChanged(WORD /*wNotifyCode*/, WORD /*wID*
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnRdramButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnRdramButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
bool bPhysicalChecked = (m_PhysicalCheckbox.GetCheck() == BST_CHECKED); bool bPhysicalChecked = (m_PhysicalCheckbox.GetCheck() == BST_CHECKED);
uint32_t addrStart = bPhysicalChecked ? 0 : 0x80000000; uint32_t addrStart = bPhysicalChecked ? 0 : 0x80000000;
@ -342,7 +343,7 @@ LRESULT CDebugMemorySearch::OnRdramButton(WORD /*wNotifyCode*/, WORD /*wID*/, HW
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnRomButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnRomButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
bool bPhysicalChecked = (m_PhysicalCheckbox.GetCheck() == BST_CHECKED); bool bPhysicalChecked = (m_PhysicalCheckbox.GetCheck() == BST_CHECKED);
uint32_t addrStart = bPhysicalChecked ? 0x10000000 : 0xB0000000; uint32_t addrStart = bPhysicalChecked ? 0x10000000 : 0xB0000000;
@ -351,7 +352,7 @@ LRESULT CDebugMemorySearch::OnRomButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnSpmemButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnSpmemButton(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
bool bPhysicalChecked = (m_PhysicalCheckbox.GetCheck() == BST_CHECKED); bool bPhysicalChecked = (m_PhysicalCheckbox.GetCheck() == BST_CHECKED);
uint32_t addrStart = bPhysicalChecked ? 0x04000000 : 0xA4000000; uint32_t addrStart = bPhysicalChecked ? 0x04000000 : 0xA4000000;
@ -362,7 +363,7 @@ LRESULT CDebugMemorySearch::OnSpmemButton(WORD /*wNotifyCode*/, WORD /*wID*/, HW
LRESULT CDebugMemorySearch::OnResultsCustomDraw(LPNMHDR lpnmh) LRESULT CDebugMemorySearch::OnResultsCustomDraw(LPNMHDR lpnmh)
{ {
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(lpnmh); NMLVCUSTOMDRAW * pLVCD = reinterpret_cast<NMLVCUSTOMDRAW *>(lpnmh);
DWORD drawStage = pLVCD->nmcd.dwDrawStage; DWORD drawStage = pLVCD->nmcd.dwDrawStage;
switch (drawStage) switch (drawStage)
@ -376,7 +377,7 @@ LRESULT CDebugMemorySearch::OnResultsCustomDraw(LPNMHDR lpnmh)
uint32_t nItem = (uint32_t)pLVCD->nmcd.dwItemSpec; uint32_t nItem = (uint32_t)pLVCD->nmcd.dwItemSpec;
uint32_t nSubItem = pLVCD->iSubItem; uint32_t nSubItem = pLVCD->iSubItem;
size_t index = m_ResultsListCtrl.GetItemData(nItem); size_t index = m_ResultsListCtrl.GetItemData(nItem);
CScanResult *presult = m_MemoryScanner.GetResult(index); CScanResult * presult = m_MemoryScanner.GetResult(index);
switch (nSubItem) switch (nSubItem)
{ {
@ -456,9 +457,9 @@ LRESULT CDebugMemorySearch::OnResultsRClick(LPNMHDR /*lpnmh*/)
return true; return true;
} }
LRESULT CDebugMemorySearch::OnResultsPopupViewMemory(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnResultsPopupViewMemory(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CScanResult* presult = GetFirstSelectedScanResult(); CScanResult * presult = GetFirstSelectedScanResult();
if (presult == nullptr) if (presult == nullptr)
{ {
@ -470,7 +471,7 @@ LRESULT CDebugMemorySearch::OnResultsPopupViewMemory(WORD /*wNotifyCode*/, WORD
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnResultsPopupAddToWatchList(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnResultsPopupAddToWatchList(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
LONG iItem = -1; LONG iItem = -1;
@ -485,7 +486,7 @@ LRESULT CDebugMemorySearch::OnResultsPopupAddToWatchList(WORD /*wNotifyCode*/, W
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnResultsPopupAddAllToWatchList(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnResultsPopupAddAllToWatchList(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
size_t numResults = m_MemoryScanner.GetNumResults(); size_t numResults = m_MemoryScanner.GetNumResults();
@ -499,9 +500,9 @@ LRESULT CDebugMemorySearch::OnResultsPopupAddAllToWatchList(WORD /*wNotifyCode*/
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnResultsPopupSetValue(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnResultsPopupSetValue(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CScanResult* pFirstResult = GetFirstSelectedScanResult(); CScanResult * pFirstResult = GetFirstSelectedScanResult();
if (pFirstResult == nullptr) if (pFirstResult == nullptr)
{ {
@ -522,7 +523,7 @@ LRESULT CDebugMemorySearch::OnResultsPopupSetValue(WORD /*wNotifyCode*/, WORD /*
if (bSelected) if (bSelected)
{ {
int index = m_ResultsListCtrl.GetItemData(iItem); int index = m_ResultsListCtrl.GetItemData(iItem);
CScanResult* presult = m_MemoryScanner.GetResult(index); CScanResult * presult = m_MemoryScanner.GetResult(index);
const std::string & enteredString = m_SetValueDlg.GetEnteredString(); const std::string & enteredString = m_SetValueDlg.GetEnteredString();
presult->SetMemoryValueFromString(enteredString.c_str()); presult->SetMemoryValueFromString(enteredString.c_str());
m_ResultsListCtrl.SetItemText(iItem, ResultsListCtrl_Col_Value, stdstr(enteredString).ToUTF16().c_str()); m_ResultsListCtrl.SetItemText(iItem, ResultsListCtrl_Col_Value, stdstr(enteredString).ToUTF16().c_str());
@ -532,7 +533,7 @@ LRESULT CDebugMemorySearch::OnResultsPopupSetValue(WORD /*wNotifyCode*/, WORD /*
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnResultsPopupRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnResultsPopupRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
int nItems = m_ResultsListCtrl.GetItemCount(); int nItems = m_ResultsListCtrl.GetItemCount();
@ -576,7 +577,7 @@ LRESULT CDebugMemorySearch::OnWatchListItemChanged(LPNMHDR /*lpnmh*/)
LRESULT CDebugMemorySearch::OnWatchListCustomDraw(LPNMHDR lpnmh) LRESULT CDebugMemorySearch::OnWatchListCustomDraw(LPNMHDR lpnmh)
{ {
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>(lpnmh); NMLVCUSTOMDRAW * pLVCD = reinterpret_cast<NMLVCUSTOMDRAW *>(lpnmh);
DWORD drawStage = pLVCD->nmcd.dwDrawStage; DWORD drawStage = pLVCD->nmcd.dwDrawStage;
switch (drawStage) switch (drawStage)
@ -590,7 +591,7 @@ LRESULT CDebugMemorySearch::OnWatchListCustomDraw(LPNMHDR lpnmh)
uint32_t nItem = (uint32_t)pLVCD->nmcd.dwItemSpec; uint32_t nItem = (uint32_t)pLVCD->nmcd.dwItemSpec;
uint32_t nSubItem = pLVCD->iSubItem; uint32_t nSubItem = pLVCD->iSubItem;
size_t index = m_WatchListCtrl.GetItemData(nItem); size_t index = m_WatchListCtrl.GetItemData(nItem);
CScanResult *presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
switch (nSubItem) switch (nSubItem)
{ {
@ -629,7 +630,7 @@ LRESULT CDebugMemorySearch::OnWatchListDblClick(LPNMHDR /*lpnmh*/)
} }
int index = m_WatchListCtrl.GetItemData(iItem); int index = m_WatchListCtrl.GetItemData(iItem);
CScanResult *presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
int nSelectedCol = -1; int nSelectedCol = -1;
@ -694,7 +695,7 @@ LRESULT CDebugMemorySearch::OnWatchListDblClick(LPNMHDR /*lpnmh*/)
{ {
if (m_SetValueDlg.DoModal("Change type", "New type:", presult->GetType(), ModalChangeTypeItems)) if (m_SetValueDlg.DoModal("Change type", "New type:", presult->GetType(), ModalChangeTypeItems))
{ {
ValueType t = (ValueType) m_SetValueDlg.GetEnteredData(); ValueType t = (ValueType)m_SetValueDlg.GetEnteredData();
presult->SetType(t); presult->SetType(t);
if (t == ValueType_string) if (t == ValueType_string)
@ -728,7 +729,7 @@ LRESULT CDebugMemorySearch::OnWatchListRClick(LPNMHDR /*lpnmh*/)
} }
int index = m_WatchListCtrl.GetItemData(iItem); int index = m_WatchListCtrl.GetItemData(iItem);
CScanResult *presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
// Load the menu // Load the menu
HMENU hMenu = LoadMenu(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDR_MEM_WATCHLIST)); HMENU hMenu = LoadMenu(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDR_MEM_WATCHLIST));
@ -738,7 +739,7 @@ LRESULT CDebugMemorySearch::OnWatchListRClick(LPNMHDR /*lpnmh*/)
POINT Mouse; POINT Mouse;
GetCursorPos(&Mouse); GetCursorPos(&Mouse);
CBreakpoints* breakpoints = m_Debugger->Breakpoints(); CBreakpoints * breakpoints = m_Debugger->Breakpoints();
bool bHaveLock = breakpoints->MemLockExists(presult->m_Address, 1); bool bHaveLock = breakpoints->MemLockExists(presult->m_Address, 1);
bool bHaveReadBP = (breakpoints->ReadBPExists8(presult->m_Address) != CBreakpoints::BPSTATE::BP_NOT_SET); bool bHaveReadBP = (breakpoints->ReadBPExists8(presult->m_Address) != CBreakpoints::BPSTATE::BP_NOT_SET);
@ -756,9 +757,9 @@ LRESULT CDebugMemorySearch::OnWatchListRClick(LPNMHDR /*lpnmh*/)
return true; return true;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupViewMemory(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupViewMemory(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CScanResult* presult = GetFirstSelectedWatchListResult(); CScanResult * presult = GetFirstSelectedWatchListResult();
if (presult == nullptr) if (presult == nullptr)
{ {
@ -770,7 +771,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupViewMemory(WORD /*wNotifyCode*/, WOR
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupLock(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupLock(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
int nItems = m_WatchListCtrl.GetItemCount(); int nItems = m_WatchListCtrl.GetItemCount();
for (int iItem = nItems - 1; iItem >= 0; iItem--) for (int iItem = nItems - 1; iItem >= 0; iItem--)
@ -780,7 +781,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupLock(WORD /*wNotifyCode*/, WORD /*wI
if (bSelected) if (bSelected)
{ {
int index = m_WatchListCtrl.GetItemData(iItem); int index = m_WatchListCtrl.GetItemData(iItem);
CScanResult* presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
m_Debugger->Breakpoints()->ToggleMemLock(presult->m_Address); m_Debugger->Breakpoints()->ToggleMemLock(presult->m_Address);
} }
} }
@ -788,9 +789,9 @@ LRESULT CDebugMemorySearch::OnWatchListPopupLock(WORD /*wNotifyCode*/, WORD /*wI
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupReadBP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupReadBP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CScanResult* presult = GetFirstSelectedWatchListResult(); CScanResult * presult = GetFirstSelectedWatchListResult();
if (presult == nullptr) if (presult == nullptr)
{ {
@ -801,9 +802,9 @@ LRESULT CDebugMemorySearch::OnWatchListPopupReadBP(WORD /*wNotifyCode*/, WORD /*
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupWriteBP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupWriteBP(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CScanResult* presult = GetFirstSelectedWatchListResult(); CScanResult * presult = GetFirstSelectedWatchListResult();
if (presult == nullptr) if (presult == nullptr)
{ {
@ -814,9 +815,9 @@ LRESULT CDebugMemorySearch::OnWatchListPopupWriteBP(WORD /*wNotifyCode*/, WORD /
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupAddSymbol(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupAddSymbol(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CScanResult* presult = GetFirstSelectedWatchListResult(); CScanResult * presult = GetFirstSelectedWatchListResult();
if (presult == nullptr) if (presult == nullptr)
{ {
@ -845,7 +846,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupAddSymbol(WORD /*wNotifyCode*/, WORD
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupHexadecimal(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupHexadecimal(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
int nItems = m_WatchListCtrl.GetItemCount(); int nItems = m_WatchListCtrl.GetItemCount();
for (int iItem = 0; iItem < nItems; iItem++) for (int iItem = 0; iItem < nItems; iItem++)
@ -855,7 +856,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupHexadecimal(WORD /*wNotifyCode*/, WO
if (bSelected) if (bSelected)
{ {
int index = m_WatchListCtrl.GetItemData(iItem); int index = m_WatchListCtrl.GetItemData(iItem);
CScanResult* presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
if (presult->m_DisplayFormat == DisplayDefault) if (presult->m_DisplayFormat == DisplayDefault)
{ {
@ -871,9 +872,9 @@ LRESULT CDebugMemorySearch::OnWatchListPopupHexadecimal(WORD /*wNotifyCode*/, WO
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupChangeValue(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupChangeValue(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CScanResult* pFirstResult = GetFirstSelectedWatchListResult(); CScanResult * pFirstResult = GetFirstSelectedWatchListResult();
if (pFirstResult == nullptr) if (pFirstResult == nullptr)
{ {
@ -893,7 +894,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeValue(WORD /*wNotifyCode*/, WO
if (bSelected) if (bSelected)
{ {
int index = m_WatchListCtrl.GetItemData(iItem); int index = m_WatchListCtrl.GetItemData(iItem);
CScanResult* presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
// TODO: prompt for size change if string is too long // TODO: prompt for size change if string is too long
presult->SetMemoryValueFromString(m_SetValueDlg.GetEnteredString().c_str()); presult->SetMemoryValueFromString(m_SetValueDlg.GetEnteredString().c_str());
m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Value, stdstr(m_SetValueDlg.GetEnteredString()).ToUTF16().c_str()); m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Value, stdstr(m_SetValueDlg.GetEnteredString()).ToUTF16().c_str());
@ -904,9 +905,9 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeValue(WORD /*wNotifyCode*/, WO
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupChangeDescription(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupChangeDescription(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CScanResult* pFirstResult = GetFirstSelectedWatchListResult(); CScanResult * pFirstResult = GetFirstSelectedWatchListResult();
if (pFirstResult == nullptr) if (pFirstResult == nullptr)
{ {
@ -923,7 +924,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeDescription(WORD /*wNotifyCode
if (bSelected) if (bSelected)
{ {
int index = m_WatchListCtrl.GetItemData(iItem); int index = m_WatchListCtrl.GetItemData(iItem);
CScanResult* presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
stdstr description = m_SetValueDlg.GetEnteredString(); stdstr description = m_SetValueDlg.GetEnteredString();
presult->SetDescription(description.c_str()); presult->SetDescription(description.c_str());
m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Description, description.ToUTF16().c_str()); m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Description, description.ToUTF16().c_str());
@ -934,9 +935,9 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeDescription(WORD /*wNotifyCode
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupChangeType(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupChangeType(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CScanResult* pFirstResult = GetFirstSelectedWatchListResult(); CScanResult * pFirstResult = GetFirstSelectedWatchListResult();
if (pFirstResult == nullptr) if (pFirstResult == nullptr)
{ {
@ -970,7 +971,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeType(WORD /*wNotifyCode*/, WOR
if (bSelected) if (bSelected)
{ {
int index = m_WatchListCtrl.GetItemData(iItem); int index = m_WatchListCtrl.GetItemData(iItem);
CScanResult* presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
if (presult->IsStringType()) if (presult->IsStringType())
{ {
@ -990,9 +991,9 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeType(WORD /*wNotifyCode*/, WOR
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupChangeAddress(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupChangeAddress(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CScanResult* pFirstResult = GetFirstSelectedWatchListResult(); CScanResult * pFirstResult = GetFirstSelectedWatchListResult();
if (pFirstResult == nullptr) if (pFirstResult == nullptr)
{ {
@ -1012,7 +1013,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeAddress(WORD /*wNotifyCode*/,
if (bSelected) if (bSelected)
{ {
int index = m_WatchListCtrl.GetItemData(iItem); int index = m_WatchListCtrl.GetItemData(iItem);
CScanResult* presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
presult->SetAddressSafe(newAddr); presult->SetAddressSafe(newAddr);
m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Address, newAddrStr.ToUTF16().c_str()); m_WatchListCtrl.SetItemText(iItem, WatchListCtrl_Col_Address, newAddrStr.ToUTF16().c_str());
} }
@ -1022,9 +1023,9 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeAddress(WORD /*wNotifyCode*/,
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupChangeAddressBy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupChangeAddressBy(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
CScanResult* pFirstResult = GetFirstSelectedWatchListResult(); CScanResult * pFirstResult = GetFirstSelectedWatchListResult();
if (pFirstResult == nullptr) if (pFirstResult == nullptr)
{ {
@ -1043,7 +1044,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeAddressBy(WORD /*wNotifyCode*/
if (bSelected) if (bSelected)
{ {
int index = m_WatchListCtrl.GetItemData(iItem); int index = m_WatchListCtrl.GetItemData(iItem);
CScanResult* presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
uint32_t newAddr = presult->m_Address + offset; uint32_t newAddr = presult->m_Address + offset;
if (presult->SetAddressSafe(newAddr)) if (presult->SetAddressSafe(newAddr))
{ {
@ -1057,19 +1058,19 @@ LRESULT CDebugMemorySearch::OnWatchListPopupChangeAddressBy(WORD /*wNotifyCode*/
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupRemove(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
RemoveSelectedWatchListItems(); RemoveSelectedWatchListItems();
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupRemoveAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupRemoveAll(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
ClearWatchList(); ClearWatchList();
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupCopyGamesharkCode(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupCopyGamesharkCode(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
int numWatchListItems = m_WatchListCtrl.GetItemCount(); int numWatchListItems = m_WatchListCtrl.GetItemCount();
@ -1083,7 +1084,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupCopyGamesharkCode(WORD /*wNotifyCode
} }
size_t index = m_WatchListCtrl.GetItemData(i); size_t index = m_WatchListCtrl.GetItemData(i);
CScanResult* presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
uint32_t vaddr = presult->GetVirtualAddress(); uint32_t vaddr = presult->GetVirtualAddress();
@ -1152,7 +1153,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupCopyGamesharkCode(WORD /*wNotifyCode
} }
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, strGSCode.length()); HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, strGSCode.length());
strncpy((char*)GlobalLock(hMem), strGSCode.c_str(), strGSCode.length() - 1); strncpy((char *)GlobalLock(hMem), strGSCode.c_str(), strGSCode.length() - 1);
GlobalUnlock(hMem); GlobalUnlock(hMem);
OpenClipboard(); OpenClipboard();
EmptyClipboard(); EmptyClipboard();
@ -1162,7 +1163,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupCopyGamesharkCode(WORD /*wNotifyCode
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnWatchListPopupCopyAddressAndDescription(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnWatchListPopupCopyAddressAndDescription(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
int numWatchListItems = m_WatchListCtrl.GetItemCount(); int numWatchListItems = m_WatchListCtrl.GetItemCount();
@ -1176,7 +1177,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupCopyAddressAndDescription(WORD /*wNo
} }
size_t index = m_WatchListCtrl.GetItemData(i); size_t index = m_WatchListCtrl.GetItemData(i);
CScanResult* presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
str += stdstr_f("%08X %s\n", presult->m_Address, presult->GetDescription()); str += stdstr_f("%08X %s\n", presult->m_Address, presult->GetDescription());
} }
@ -1188,7 +1189,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupCopyAddressAndDescription(WORD /*wNo
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.length()); HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, str.length());
strncpy((char*)GlobalLock(hMem), str.c_str(), str.length() - 1); strncpy((char *)GlobalLock(hMem), str.c_str(), str.length() - 1);
GlobalUnlock(hMem); GlobalUnlock(hMem);
OpenClipboard(); OpenClipboard();
EmptyClipboard(); EmptyClipboard();
@ -1198,7 +1199,7 @@ LRESULT CDebugMemorySearch::OnWatchListPopupCopyAddressAndDescription(WORD /*wNo
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnSetFont(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnSetFont(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
// Set row height for the results list and watch list // Set row height for the results list and watch list
CClientDC dc(m_hWnd); CClientDC dc(m_hWnd);
@ -1209,17 +1210,17 @@ LRESULT CDebugMemorySearch::OnSetFont(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lPa
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnMeasureItem(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL & /*bHandled*/)
{ {
if (wParam == IDC_LST_RESULTS || wParam == IDC_LST_WATCHLIST) if (wParam == IDC_LST_RESULTS || wParam == IDC_LST_WATCHLIST)
{ {
MEASUREITEMSTRUCT* lpMeasureItem = (MEASUREITEMSTRUCT*)lParam; MEASUREITEMSTRUCT * lpMeasureItem = (MEASUREITEMSTRUCT *)lParam;
lpMeasureItem->itemHeight = m_ListCtrlRowHeight; lpMeasureItem->itemHeight = m_ListCtrlRowHeight;
} }
return FALSE; return FALSE;
} }
LRESULT CDebugMemorySearch::OnScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::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;
@ -1262,7 +1263,7 @@ LRESULT CDebugMemorySearch::OnScroll(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam
return 0; return 0;
} }
LRESULT CDebugMemorySearch::OnMouseDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnMouseDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
if (MouseHovering(IDC_SEPARATOR, 0, 1)) if (MouseHovering(IDC_SEPARATOR, 0, 1))
{ {
@ -1273,7 +1274,7 @@ LRESULT CDebugMemorySearch::OnMouseDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
return 0; return 0;
} }
LRESULT CDebugMemorySearch::OnMouseUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CDebugMemorySearch::OnMouseUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
if (m_bDraggingSeparator) if (m_bDraggingSeparator)
{ {
@ -1388,7 +1389,7 @@ void CDebugMemorySearch::AddResultToWatchList(int resultIndex)
m_WatchList.push_back(result); m_WatchList.push_back(result);
} }
CScanResult* CDebugMemorySearch::GetFirstSelectedScanResult(void) CScanResult * CDebugMemorySearch::GetFirstSelectedScanResult(void)
{ {
LONG iItem = m_ResultsListCtrl.GetNextItem(-1, LVNI_SELECTED); LONG iItem = m_ResultsListCtrl.GetNextItem(-1, LVNI_SELECTED);
@ -1398,11 +1399,11 @@ CScanResult* CDebugMemorySearch::GetFirstSelectedScanResult(void)
} }
int index = m_ResultsListCtrl.GetItemData(iItem); int index = m_ResultsListCtrl.GetItemData(iItem);
CScanResult *presult = m_MemoryScanner.GetResult(index); CScanResult * presult = m_MemoryScanner.GetResult(index);
return presult; return presult;
} }
CScanResult* CDebugMemorySearch::GetFirstSelectedWatchListResult(void) CScanResult * CDebugMemorySearch::GetFirstSelectedWatchListResult(void)
{ {
LONG iItem = m_WatchListCtrl.GetNextItem(-1, LVNI_SELECTED); LONG iItem = m_WatchListCtrl.GetNextItem(-1, LVNI_SELECTED);
@ -1412,11 +1413,11 @@ CScanResult* CDebugMemorySearch::GetFirstSelectedWatchListResult(void)
} }
int index = m_WatchListCtrl.GetItemData(iItem); int index = m_WatchListCtrl.GetItemData(iItem);
CScanResult *presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
return presult; return presult;
} }
void CDebugMemorySearch::SetComboBoxSelByData(CComboBox& cb, DWORD_PTR data) void CDebugMemorySearch::SetComboBoxSelByData(CComboBox & cb, DWORD_PTR data)
{ {
int numOptions = cb.GetCount(); int numOptions = cb.GetCount();
@ -1474,7 +1475,7 @@ void CDebugMemorySearch::SeparatorMoveCtrl(WORD ctrlId, int yChange, bool bResiz
::InvalidateRect(hControl, nullptr, true); ::InvalidateRect(hControl, nullptr, true);
} }
int CDebugMemorySearch::GetNumVisibleRows(CListViewCtrl& list) int CDebugMemorySearch::GetNumVisibleRows(CListViewCtrl & list)
{ {
CHeaderCtrl header = list.GetHeader(); CHeaderCtrl header = list.GetHeader();
CRect listRect, headRect; CRect listRect, headRect;
@ -1494,8 +1495,8 @@ void CDebugMemorySearch::ResetResults(void)
void CDebugMemorySearch::Search(void) void CDebugMemorySearch::Search(void)
{ {
ValueType valueType = (ValueType) m_ValueTypeOptions.GetItemData(m_ValueTypeOptions.GetCurSel()); ValueType valueType = (ValueType)m_ValueTypeOptions.GetItemData(m_ValueTypeOptions.GetCurSel());
SearchType searchType = (SearchType) m_SearchTypeOptions.GetItemData(m_SearchTypeOptions.GetCurSel()); SearchType searchType = (SearchType)m_SearchTypeOptions.GetItemData(m_SearchTypeOptions.GetCurSel());
DWORD startAddress = m_AddrStart.GetValue(); DWORD startAddress = m_AddrStart.GetValue();
DWORD endAddress = m_AddrEnd.GetValue(); DWORD endAddress = m_AddrEnd.GetValue();
@ -1635,7 +1636,7 @@ void CDebugMemorySearch::Search(void)
goto value_parse_error; goto value_parse_error;
} }
} }
m_MemoryScanner.SetValue<const wchar_t*>(value._string); m_MemoryScanner.SetValue<const wchar_t *>(value._string);
m_MemoryScanner.SetStringValueLength(stringValueLength); m_MemoryScanner.SetStringValueLength(stringValueLength);
break; break;
case ValueType_unkstring: case ValueType_unkstring:
@ -1645,7 +1646,7 @@ void CDebugMemorySearch::Search(void)
goto value_parse_error; goto value_parse_error;
} }
m_MemoryScanner.SetValue<const wchar_t*>(value._string); m_MemoryScanner.SetValue<const wchar_t *>(value._string);
m_MemoryScanner.SetStringValueLength(stringValueLength); m_MemoryScanner.SetStringValueLength(stringValueLength);
break; break;
default: default:
@ -1812,7 +1813,7 @@ void CDebugMemorySearch::UpdateResultsList(bool bUpdateScrollbar, bool bResetScr
char szCurrentValue[1024]; char szCurrentValue[1024];
char szValue[1024]; char szValue[1024];
CScanResult *presult = m_MemoryScanner.GetResult(index); CScanResult * presult = m_MemoryScanner.GetResult(index);
presult->GetAddressString(szAddress); presult->GetAddressString(szAddress);
presult->GetMemoryValueString(szCurrentValue, 1024); presult->GetMemoryValueString(szCurrentValue, 1024);
@ -1863,19 +1864,19 @@ void CDebugMemorySearch::UpdateWatchList(bool bUpdateScrollbar)
for (size_t index = start; index < end; index++) for (size_t index = start; index < end; index++)
{ {
CScanResult *presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
char szAddress[16]; char szAddress[16];
char szValue[1024]; char szValue[1024];
char szValueType[32]; char szValueType[32];
const char* pSzValueType; const char * pSzValueType;
const char* pSzDescription; const char * pSzDescription;
presult->GetAddressString(szAddress); presult->GetAddressString(szAddress);
presult->GetMemoryValueString(szValue, 1024); presult->GetMemoryValueString(szValue, 1024);
pSzValueType = presult->GetTypeName(); pSzValueType = presult->GetTypeName();
pSzDescription = presult->GetDescription(); pSzDescription = presult->GetDescription();
switch(presult->GetType()) switch (presult->GetType())
{ {
case ValueType_string: case ValueType_string:
case ValueType_istring: case ValueType_istring:
@ -1920,7 +1921,7 @@ void CDebugMemorySearch::RefreshResultsListValues(void)
for (int nItem = 0; nItem < numShownResults; nItem++) for (int nItem = 0; nItem < numShownResults; nItem++)
{ {
size_t index = m_ResultsListCtrl.GetItemData(nItem); size_t index = m_ResultsListCtrl.GetItemData(nItem);
CScanResult *presult = m_MemoryScanner.GetResult(index); CScanResult * presult = m_MemoryScanner.GetResult(index);
if (presult == nullptr) if (presult == nullptr)
{ {
@ -1954,9 +1955,9 @@ void CDebugMemorySearch::RefreshWatchListValues(void)
for (int nItem = 0; nItem < numShownWatchListEntries; nItem++) for (int nItem = 0; nItem < numShownWatchListEntries; nItem++)
{ {
size_t index = m_WatchListCtrl.GetItemData(nItem); size_t index = m_WatchListCtrl.GetItemData(nItem);
CScanResult *presult = &m_WatchList[index]; CScanResult * presult = &m_WatchList[index];
CBreakpoints *breakpoints = m_Debugger->Breakpoints(); CBreakpoints * breakpoints = m_Debugger->Breakpoints();
bool bHaveLock = breakpoints->MemLockExists(presult->m_Address, 1); bool bHaveLock = breakpoints->MemLockExists(presult->m_Address, 1);
bool bHaveReadBP = (breakpoints->ReadBPExists8(presult->m_Address) != CBreakpoints::BPSTATE::BP_NOT_SET); bool bHaveReadBP = (breakpoints->ReadBPExists8(presult->m_Address) != CBreakpoints::BPSTATE::BP_NOT_SET);
@ -2000,10 +2001,10 @@ void CDebugMemorySearch::FlushWatchList(void)
for (size_t i = 0; i < numWatchListEntries; i++) for (size_t i = 0; i < numWatchListEntries; i++)
{ {
CScanResult* presult = &m_WatchList[i]; CScanResult * presult = &m_WatchList[i];
char szValueType[32]; char szValueType[32];
const char* pSzValueType; const char * pSzValueType;
pSzValueType = presult->GetTypeName(); pSzValueType = presult->GetTypeName();
@ -2018,7 +2019,7 @@ void CDebugMemorySearch::FlushWatchList(void)
} }
char cAddrType = (presult->m_AddressType == AddressType_Physical) ? 'p' : 'v'; char cAddrType = (presult->m_AddressType == AddressType_Physical) ? 'p' : 'v';
const char* szDisplayFormat = (presult->m_DisplayFormat == DisplayDefault) ? "def" : "hex"; const char * szDisplayFormat = (presult->m_DisplayFormat == DisplayDefault) ? "def" : "hex";
stdstr line = stdstr_f("%c,%08X,%s,%s,%s\n", stdstr line = stdstr_f("%c,%08X,%s,%s,%s\n",
cAddrType, presult->m_Address, pSzValueType, szDisplayFormat, presult->GetDescription()); cAddrType, presult->m_Address, pSzValueType, szDisplayFormat, presult->GetDescription());
@ -2047,7 +2048,7 @@ void CDebugMemorySearch::LoadWatchList(void)
} }
uint32_t length = m_WatchListFile.GetLength(); uint32_t length = m_WatchListFile.GetLength();
char* szWlFile = new char[length + 1]; char * szWlFile = new char[length + 1];
m_WatchListFile.SeekToBegin(); m_WatchListFile.SeekToBegin();
m_WatchListFile.Read(szWlFile, length); m_WatchListFile.Read(szWlFile, length);
@ -2055,19 +2056,29 @@ void CDebugMemorySearch::LoadWatchList(void)
m_WatchListFile.Close(); m_WatchListFile.Close();
char* p = szWlFile; char * p = szWlFile;
while (*p) while (*p)
{ {
CScanResult result(AddressType_Virtual, DisplayDefault); CScanResult result(AddressType_Virtual, DisplayDefault);
char* szAddrType, *szAddress, *szValueType, *szDisplayFormat, *szDescription; char *szAddrType, *szAddress, *szValueType, *szDisplayFormat, *szDescription;
szAddrType = p; p = strchr(p, ','); *p++ = '\0'; szAddrType = p;
szAddress = p; p = strchr(p, ','); *p++ = '\0'; p = strchr(p, ',');
szValueType = p; p = strchr(p, ','); *p++ = '\0'; *p++ = '\0';
szDisplayFormat = p; p = strchr(p, ','); *p++ = '\0'; szAddress = p;
szDescription = p; p = strchr(p, '\n'); *p++ = '\0'; p = strchr(p, ',');
*p++ = '\0';
szValueType = p;
p = strchr(p, ',');
*p++ = '\0';
szDisplayFormat = p;
p = strchr(p, ',');
*p++ = '\0';
szDescription = p;
p = strchr(p, '\n');
*p++ = '\0';
switch (szAddrType[0]) switch (szAddrType[0])
{ {
@ -2120,12 +2131,11 @@ void CDebugMemorySearch::LoadWatchList(void)
UpdateWatchList(); UpdateWatchList();
parse_error: parse_error:
delete[] szWlFile; delete[] szWlFile;
} }
void CDebugMemorySearch::FixListHeader(CListViewCtrl& listCtrl) void CDebugMemorySearch::FixListHeader(CListViewCtrl & listCtrl)
{ {
CRect listRect, headRect; CRect listRect, headRect;
CHeaderCtrl listHead = listCtrl.GetHeader(); CHeaderCtrl listHead = listCtrl.GetHeader();
@ -2160,7 +2170,7 @@ CPath CDebugMemorySearch::GetWatchListPath(void)
return wlFilePath; return wlFilePath;
} }
INT_PTR CSetValueDlg::DoModal(const char* caption, const char* label, const char* initialText) INT_PTR CSetValueDlg::DoModal(const char * caption, const char * label, const char * initialText)
{ {
m_Mode = Mode_TextBox; m_Mode = Mode_TextBox;
m_Caption = caption; m_Caption = caption;
@ -2169,7 +2179,7 @@ INT_PTR CSetValueDlg::DoModal(const char* caption, const char* label, const char
return CDialogImpl<CSetValueDlg>::DoModal(); return CDialogImpl<CSetValueDlg>::DoModal();
} }
INT_PTR CSetValueDlg::DoModal(const char* caption, const char* label, DWORD_PTR initialData, const ComboItem items[]) INT_PTR CSetValueDlg::DoModal(const char * caption, const char * label, DWORD_PTR initialData, const ComboItem items[])
{ {
m_Mode = Mode_ComboBox; m_Mode = Mode_ComboBox;
m_Caption = caption; m_Caption = caption;
@ -2194,7 +2204,7 @@ DWORD_PTR CSetValueDlg::GetEnteredData(void)
return m_EnteredData; return m_EnteredData;
} }
LRESULT CSetValueDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) LRESULT CSetValueDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL & /*bHandled*/)
{ {
SetWindowText(stdstr(m_Caption).ToUTF16().c_str()); SetWindowText(stdstr(m_Caption).ToUTF16().c_str());
CenterWindow(); CenterWindow();
@ -2237,7 +2247,7 @@ LRESULT CSetValueDlg::OnDestroy(void)
return 0; return 0;
} }
LRESULT CSetValueDlg::OnOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CSetValueDlg::OnOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
m_EnteredString.clear(); m_EnteredString.clear();
if (m_Mode == Mode_TextBox) if (m_Mode == Mode_TextBox)
@ -2254,7 +2264,7 @@ LRESULT CSetValueDlg::OnOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BO
return FALSE; return FALSE;
} }
LRESULT CSetValueDlg::OnCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL& /*bHandled*/) LRESULT CSetValueDlg::OnCancel(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hwnd*/, BOOL & /*bHandled*/)
{ {
EndDialog(FALSE); EndDialog(FALSE);
return FALSE; return FALSE;
@ -2304,7 +2314,7 @@ BOOL CEditMixed::Attach(HWND hWndNew)
return SubclassWindow(hWndNew); return SubclassWindow(hWndNew);
} }
bool CEditMixed::GetValue(uint8_t& value) bool CEditMixed::GetValue(uint8_t & value)
{ {
uint64_t valueU64; uint64_t valueU64;
bool bValid = GetValue(valueU64); bool bValid = GetValue(valueU64);
@ -2318,11 +2328,11 @@ bool CEditMixed::GetValue(uint8_t& value)
return true; return true;
} }
bool CEditMixed::GetValue(int8_t& value) bool CEditMixed::GetValue(int8_t & value)
{ {
if (m_DisplayFormat == DisplayHex) if (m_DisplayFormat == DisplayHex)
{ {
return GetValue((uint8_t&)value); return GetValue((uint8_t &)value);
} }
int64_t valueS64; int64_t valueS64;
@ -2337,7 +2347,7 @@ bool CEditMixed::GetValue(int8_t& value)
return true; return true;
} }
bool CEditMixed::GetValue(uint16_t& value) bool CEditMixed::GetValue(uint16_t & value)
{ {
uint64_t valueU64; uint64_t valueU64;
bool bValid = GetValue(valueU64); bool bValid = GetValue(valueU64);
@ -2351,11 +2361,11 @@ bool CEditMixed::GetValue(uint16_t& value)
return true; return true;
} }
bool CEditMixed::GetValue(int16_t& value) bool CEditMixed::GetValue(int16_t & value)
{ {
if (m_DisplayFormat == DisplayHex) if (m_DisplayFormat == DisplayHex)
{ {
return GetValue((uint16_t&)value); return GetValue((uint16_t &)value);
} }
int64_t valueS64; int64_t valueS64;
@ -2370,7 +2380,7 @@ bool CEditMixed::GetValue(int16_t& value)
return true; return true;
} }
bool CEditMixed::GetValue(uint32_t& value) bool CEditMixed::GetValue(uint32_t & value)
{ {
uint64_t valueU64; uint64_t valueU64;
bool bValid = GetValue(valueU64); bool bValid = GetValue(valueU64);
@ -2384,11 +2394,11 @@ bool CEditMixed::GetValue(uint32_t& value)
return true; return true;
} }
bool CEditMixed::GetValue(int32_t& value) bool CEditMixed::GetValue(int32_t & value)
{ {
if (m_DisplayFormat == DisplayHex) if (m_DisplayFormat == DisplayHex)
{ {
return GetValue((uint32_t&)value); return GetValue((uint32_t &)value);
} }
int64_t valueS64; int64_t valueS64;
@ -2403,11 +2413,11 @@ bool CEditMixed::GetValue(int32_t& value)
return true; return true;
} }
bool CEditMixed::GetValue(uint64_t& value) bool CEditMixed::GetValue(uint64_t & value)
{ {
ReloadString(); ReloadString();
char *end; char * end;
uint64_t res = strtoull(stdstr().FromUTF16(m_String).c_str(), &end, m_DisplayFormat == DisplayHex ? 16 : 10); uint64_t res = strtoull(stdstr().FromUTF16(m_String).c_str(), &end, m_DisplayFormat == DisplayHex ? 16 : 10);
if (*end != '\0') if (*end != '\0')
@ -2419,16 +2429,16 @@ bool CEditMixed::GetValue(uint64_t& value)
return true; return true;
} }
bool CEditMixed::GetValue(int64_t& value) bool CEditMixed::GetValue(int64_t & value)
{ {
if (m_DisplayFormat == DisplayHex) if (m_DisplayFormat == DisplayHex)
{ {
return GetValue((uint64_t&)value); return GetValue((uint64_t &)value);
} }
ReloadString(); ReloadString();
char *end; char * end;
uint64_t res = strtoll(stdstr().FromUTF16(m_String).c_str(), &end, m_DisplayFormat == DisplayHex ? 16 : 10); uint64_t res = strtoll(stdstr().FromUTF16(m_String).c_str(), &end, m_DisplayFormat == DisplayHex ? 16 : 10);
if (*end != '\0') if (*end != '\0')
@ -2440,17 +2450,17 @@ bool CEditMixed::GetValue(int64_t& value)
return true; return true;
} }
bool CEditMixed::GetValue(float& value) bool CEditMixed::GetValue(float & value)
{ {
if (m_DisplayFormat == DisplayHex) if (m_DisplayFormat == DisplayHex)
{ {
return GetValue((uint32_t&)value); return GetValue((uint32_t &)value);
} }
ReloadString(); ReloadString();
float valueF32; float valueF32;
char *end; char * end;
valueF32 = strtof(stdstr().FromUTF16(m_String).c_str(), &end); valueF32 = strtof(stdstr().FromUTF16(m_String).c_str(), &end);
@ -2463,17 +2473,17 @@ bool CEditMixed::GetValue(float& value)
return true; return true;
} }
bool CEditMixed::GetValue(double& value) bool CEditMixed::GetValue(double & value)
{ {
if (m_DisplayFormat == DisplayHex) if (m_DisplayFormat == DisplayHex)
{ {
return GetValue((uint64_t&)value); return GetValue((uint64_t &)value);
} }
ReloadString(); ReloadString();
double valueF64; double valueF64;
char *end; char * end;
valueF64 = strtod(stdstr().FromUTF16(m_String).c_str(), &end); valueF64 = strtod(stdstr().FromUTF16(m_String).c_str(), &end);
@ -2486,7 +2496,7 @@ bool CEditMixed::GetValue(double& value)
return true; return true;
} }
bool CEditMixed::GetValueString(const wchar_t*& value, int& length) bool CEditMixed::GetValueString(const wchar_t *& value, int & length)
{ {
ReloadString(); ReloadString();
@ -2500,7 +2510,7 @@ bool CEditMixed::GetValueString(const wchar_t*& value, int& length)
return true; return true;
} }
bool CEditMixed::GetValueHexString(const wchar_t*& value, int& length) bool CEditMixed::GetValueHexString(const wchar_t *& value, int & length)
{ {
ReloadString(); ReloadString();
@ -2517,9 +2527,8 @@ bool CEditMixed::GetValueHexString(const wchar_t*& value, int& length)
return false; return false;
} }
char * hexString = new char[numBytes];
char *hexString = new char[numBytes]; wchar_t * wchexString = new wchar_t[numBytes];
wchar_t *wchexString = new wchar_t[numBytes];
CMemoryScanner::ParseHexString(hexString, string.c_str()); CMemoryScanner::ParseHexString(hexString, string.c_str());
wcscpy(wchexString, stdstr(hexString).ToUTF16().c_str()); wcscpy(wchexString, stdstr(hexString).ToUTF16().c_str());

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,7 +305,7 @@ 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;
} }
@ -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,7 +637,7 @@ 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;
@ -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);
} }
@ -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,7 +872,7 @@ 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;
@ -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,7 +22,7 @@ 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);
@ -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)
@ -308,9 +309,9 @@ void CDebugScripts::RefreshStatus()
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)
@ -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,9 +382,9 @@ 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(), "*");
@ -440,18 +441,17 @@ LRESULT CDebugScripts::OnRefreshList(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*
} }
} 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();

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();
@ -41,7 +42,7 @@ LRESULT CScriptsAutorunDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARA
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,34 +64,33 @@ 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;
@ -115,13 +115,13 @@ LRESULT CScriptsAutorunDlg::OnCtrlSetFocus(NMHDR* pNMHDR)
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,7 +13,7 @@ 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);
@ -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);

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);
@ -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)
{ {
@ -122,9 +123,9 @@ LRESULT CDebugSymbols::OnClicked(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*
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))
{ {
@ -277,9 +278,9 @@ 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;
@ -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,7 +320,7 @@ 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)
{ {
@ -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)
{ {
@ -362,7 +363,7 @@ LRESULT CDebugSymbols::OnFilterChanged(WORD /*wNotifyCode*/, WORD /*wID*/, HWND
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)
{ {

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();
@ -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);
@ -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,7 +1013,7 @@ 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();
@ -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++)
@ -1075,7 +1074,7 @@ void CDebugMemoryView::UpdateCurrentTab(uint32_t address)
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();
@ -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)
{ {

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

View File

@ -1,24 +1,25 @@
#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)
{ {
@ -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++)
{ {
@ -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)
{ {
@ -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,34 +185,34 @@ 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)
{ {
@ -228,7 +229,7 @@ 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 ||
@ -236,7 +237,7 @@ int CScanResult::GetMemoryValueString(char* buffer, size_t size, bool bIgnoreHex
{ {
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++)
@ -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;
} }
@ -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:
@ -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,7 +650,7 @@ 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;
} }
@ -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())
{ {
@ -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,7 +752,7 @@ 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;
@ -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:;
@ -827,7 +827,7 @@ void CMemoryScanner::FirstScanLoopUnkString(void)
#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; \
@ -903,7 +903,7 @@ bool CMemoryScanner::FirstScan(DisplayFormat resDisplayFormat)
// 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; \
@ -919,7 +919,7 @@ bool CMemoryScanner::FirstScan(DisplayFormat resDisplayFormat)
// 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; \
@ -941,7 +941,7 @@ bool CMemoryScanner::NextScan()
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);
@ -976,7 +976,6 @@ bool CMemoryScanner::NextScan()
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,7 +181,7 @@ 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()
@ -195,17 +196,17 @@ void CJSServerWorker::JSEmitListening()
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);
@ -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
@ -430,7 +433,7 @@ void CJSSocketWorker::JSEmitConnect()
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,7 +442,7 @@ 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()
@ -460,29 +463,29 @@ void CJSSocketWorker::JSEmitDrain()
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);
@ -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;

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;
} }
@ -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,11 +1,13 @@
#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; {
uint8_t * pngData;
size_t pngSize; size_t pngSize;
png_size_t offset; png_size_t offset;
}; };
@ -13,9 +15,9 @@ struct PNGReadState {
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))
{ {
@ -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);
@ -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");
@ -71,16 +72,16 @@ void ScriptAPI::InitEnvironment(duk_context* ctx, CScriptInstance* inst)
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_GFXTASK", 1},
{ "M_AUDTASK", 2 }, {"M_AUDTASK", 2},
{ "OS_READ", 0 }, {"OS_READ", 0},
{ "OS_WRITE", 1 }, {"OS_WRITE", 1},
{ "COLOR_BLACK", 0x000000FF }, {"COLOR_BLACK", 0x000000FF},
{ "COLOR_WHITE", 0xFFFFFFFF }, {"COLOR_WHITE", 0xFFFFFFFF},
{ "COLOR_GRAY", 0x808080FF }, {"COLOR_GRAY", 0x808080FF},
{ "COLOR_RED", 0xFF0000FF }, {"COLOR_RED", 0xFF0000FF},
{ "COLOR_GREEN", 0x00FF00FF }, {"COLOR_GREEN", 0x00FF00FF},
{ "COLOR_BLUE", 0x0000FFFF }, {"COLOR_BLUE", 0x0000FFFF},
{ "COLOR_YELLOW", 0xFFFF00FF }, {"COLOR_YELLOW", 0xFFFF00FF},
{ "COLOR_CYAN", 0x00FFFFFF }, {"COLOR_CYAN", 0x00FFFFFF},
{ "COLOR_MAGENTA", 0xFF00FFFF }, {"COLOR_MAGENTA", 0xFF00FFFF},
{ "EMU_STARTED", JS_EMU_STARTED }, {"EMU_STARTED", JS_EMU_STARTED},
{ "EMU_STOPPED", JS_EMU_STOPPED }, {"EMU_STOPPED", JS_EMU_STOPPED},
{ "EMU_PAUSED", JS_EMU_PAUSED }, {"EMU_PAUSED", JS_EMU_PAUSED},
{ "EMU_RESUMED", JS_EMU_RESUMED }, {"EMU_RESUMED", JS_EMU_RESUMED},
{ "EMU_RESETTING", JS_EMU_RESETTING }, {"EMU_RESETTING", JS_EMU_RESETTING},
{ "EMU_RESET", JS_EMU_RESET }, {"EMU_RESET", JS_EMU_RESET},
{ "EMU_LOADED_ROM", JS_EMU_LOADED_ROM }, {"EMU_LOADED_ROM", JS_EMU_LOADED_ROM},
{ "EMU_LOADED_STATE", JS_EMU_LOADED_STATE }, {"EMU_LOADED_STATE", JS_EMU_LOADED_STATE},
{ "EMU_DEBUG_PAUSED", JS_EMU_DEBUG_PAUSED }, {"EMU_DEBUG_PAUSED", JS_EMU_DEBUG_PAUSED},
{ "EMU_DEBUG_RESUMED", JS_EMU_DEBUG_RESUMED }, {"EMU_DEBUG_RESUMED", JS_EMU_DEBUG_RESUMED},
{ "IMG_I4", IMG_I4 }, {"IMG_I4", IMG_I4},
{ "IMG_I8", IMG_I8 }, {"IMG_I8", IMG_I8},
{ "IMG_IA4", IMG_IA4 }, {"IMG_IA4", IMG_IA4},
{ "IMG_IA8", IMG_IA8 }, {"IMG_IA8", IMG_IA8},
{ "IMG_IA16", IMG_IA16 }, {"IMG_IA16", IMG_IA16},
{ "IMG_RGBA16", IMG_RGBA16 }, {"IMG_RGBA16", IMG_RGBA16},
{ "IMG_RGBA32", IMG_RGBA32 }, {"IMG_RGBA32", IMG_RGBA32},
{ "IMG_CI8_RGBA16", IMG_CI8_RGBA16 }, {"IMG_CI8_RGBA16", IMG_CI8_RGBA16},
{ "IMG_CI4_RGBA16", IMG_CI4_RGBA16 }, {"IMG_CI4_RGBA16", IMG_CI4_RGBA16},
{ "IMG_CI8_IA16", IMG_CI8_IA16 }, {"IMG_CI8_IA16", IMG_CI8_IA16},
{ "IMG_CI4_IA16", IMG_CI4_IA16 }, {"IMG_CI4_IA16", IMG_CI4_IA16},
{ "G_IM_FMT_RGBA", G_IM_FMT_RGBA }, {"G_IM_FMT_RGBA", G_IM_FMT_RGBA},
{ "G_IM_FMT_YUV", G_IM_FMT_YUV }, {"G_IM_FMT_YUV", G_IM_FMT_YUV},
{ "G_IM_FMT_CI", G_IM_FMT_CI }, {"G_IM_FMT_CI", G_IM_FMT_CI},
{ "G_IM_FMT_IA", G_IM_FMT_IA }, {"G_IM_FMT_IA", G_IM_FMT_IA},
{ "G_IM_FMT_I", G_IM_FMT_I }, {"G_IM_FMT_I", G_IM_FMT_I},
{ "G_IM_SIZ_4b", G_IM_SIZ_4b }, {"G_IM_SIZ_4b", G_IM_SIZ_4b},
{ "G_IM_SIZ_8b", G_IM_SIZ_8b }, {"G_IM_SIZ_8b", G_IM_SIZ_8b},
{ "G_IM_SIZ_16b", G_IM_SIZ_16b }, {"G_IM_SIZ_16b", G_IM_SIZ_16b},
{ "G_IM_SIZ_32b", G_IM_SIZ_32b }, {"G_IM_SIZ_32b", G_IM_SIZ_32b},
{ "G_TT_NONE", G_TT_NONE }, {"G_TT_NONE", G_TT_NONE},
{ "G_TT_RGBA16", G_TT_RGBA16 }, {"G_TT_RGBA16", G_TT_RGBA16},
{ "G_TT_IA16", G_TT_IA16 }, {"G_TT_IA16", G_TT_IA16},
{ nullptr, 0 }, {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,12 +404,12 @@ 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);
@ -418,9 +419,9 @@ bool ScriptAPI::RemoveAppCallback(duk_context* ctx, JSAppCallbackID callbackId)
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))
{ {
@ -464,10 +465,10 @@ void ScriptAPI::RefObject(duk_context* ctx, duk_idx_t idx)
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))
{ {
@ -488,14 +489,14 @@ void ScriptAPI::UnrefObject(duk_context* ctx, duk_idx_t idx)
} }
// 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++)
@ -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);
@ -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,7 +718,7 @@ 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);
@ -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)
{ {
@ -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,9 +50,9 @@ 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);
@ -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,10 +97,10 @@ 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)
@ -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,9 +127,9 @@ 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);
@ -139,9 +140,9 @@ 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)
{ {
@ -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,23 +215,23 @@ 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)
{ {

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, { InitEmitter(ctx, -1, {"close", "connection", "error", "listening"});
"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,11 +124,11 @@ 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;
@ -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);
@ -218,53 +211,53 @@ duk_ret_t ScriptAPI::js_Socket__invokeWriteEndCallbacks(duk_context* ctx)
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,7 +88,7 @@ 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);

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,7 +158,7 @@ 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)
{ {
@ -164,7 +166,7 @@ duk_ret_t ScriptAPI::js_cpu_cop0_get(duk_context* ctx)
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,7 +189,7 @@ 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))
{ {
@ -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;
@ -240,11 +242,11 @@ 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,7 +31,7 @@ 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, {});
@ -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,7 +71,7 @@ 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);
@ -78,9 +79,9 @@ duk_ret_t ScriptAPI::js_events_onstatechange(duk_context * ctx)
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);
@ -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);
@ -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);
@ -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);
@ -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);
@ -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,11 +379,11 @@ 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();
@ -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;
@ -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 }
}; };
@ -644,17 +646,17 @@ duk_idx_t CbArgs_WriteEventObject(duk_context* ctx, void* _env)
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,9 +759,9 @@ 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)
{ {
@ -774,9 +776,9 @@ 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,
@ -787,7 +789,7 @@ duk_ret_t RequireAddressOrAddressRange(duk_context* ctx, duk_idx_t idx, uint32_t
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);
@ -815,7 +817,7 @@ duk_ret_t RequireAddressOrAddressRange(duk_context* ctx, duk_idx_t idx, uint32_t
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)

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
{ {
@ -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,10 +67,10 @@ 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)
{ {
@ -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;
@ -284,7 +286,7 @@ duk_ret_t ScriptAPI::js_mem__boundget(duk_context *ctx)
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,16 +395,16 @@ 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,14 +110,13 @@ 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();
return false; return false;
@ -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,19 +169,19 @@ 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);
@ -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,7 +66,7 @@ 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";
@ -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,7 +86,7 @@ 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);
@ -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++)
@ -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())
{ {
@ -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);
@ -616,7 +617,7 @@ bool CScriptSystem::ProcessCommand(JSSysCommand& cmd)
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;
} }
@ -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)
{ {
@ -170,8 +171,8 @@ 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,7 +184,7 @@ 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)
@ -274,7 +275,7 @@ 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)
@ -290,7 +291,7 @@ 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
{ {
@ -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,6 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include <3rdParty\discord-rpc\include\discord_rpc.h>
#include "DiscordRPC.h" #include "DiscordRPC.h"
#include <3rdParty\discord-rpc\include\discord_rpc.h>
#define UNIX_TIME_START 0x019DB1DED53E8000 #define UNIX_TIME_START 0x019DB1DED53E8000
#define TICKS_PER_SECOND 10000000 #define TICKS_PER_SECOND 10000000
@ -27,9 +28,11 @@ static stdstr GetTitle()
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(); Default = CPath(g_Settings->LoadStringVal(Game_File)).GetName().c_str();
if (strstr(const_cast<char*>(Default.c_str()), "?") != nullptr) { if (strstr(const_cast<char *>(Default.c_str()), "?") != nullptr)
{
return Default.substr(Default.find("?") + 1); return Default.substr(Default.find("?") + 1);
} }
return Default; return Default;

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(),
@ -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
{ {

View File

@ -1,12 +1,13 @@
#include "stdafx.h" #include "stdafx.h"
#include "DiscordRPC.h"
#include "RomInformation.h" #include "RomInformation.h"
#include <Project64\UserInterface\About.h>
#include <commctrl.h>
#include <Project64-core/Settings/SettingType/SettingsType-Application.h>
#include <Project64-core/N64System/Enhancement/Enhancements.h> #include <Project64-core/N64System/Enhancement/Enhancements.h>
#include <Project64-core/N64System/N64Disk.h> #include <Project64-core/N64System/N64Disk.h>
#include <Project64-core/Settings/SettingType/SettingsType-Application.h>
#include <Project64/UserInterface/Debugger/DebuggerUI.h> #include <Project64/UserInterface/Debugger/DebuggerUI.h>
#include "DiscordRPC.h" #include <Project64\UserInterface\About.h>
#include <commctrl.h>
void EnterLogOptions(HWND hwndOwner); void EnterLogOptions(HWND hwndOwner);
@ -278,7 +279,7 @@ void RomBrowserListChanged(CMainGui * Gui)
Gui->HighLightLastRom(); Gui->HighLightLastRom();
} }
void DiscordRPCChanged(CMainGui*) void DiscordRPCChanged(CMainGui *)
{ {
if (UISettingsLoadBool(Setting_EnableDiscordRPC)) if (UISettingsLoadBool(Setting_EnableDiscordRPC))
{ {
@ -387,8 +388,7 @@ void CMainGui::Caption(LPCWSTR Caption)
void CMainGui::Create(const char * WindowTitle) void CMainGui::Create(const char * WindowTitle)
{ {
stdstr_f VersionDisplay("Project64 %s", VER_FILE_VERSION_STR); stdstr_f VersionDisplay("Project64 %s", VER_FILE_VERSION_STR);
m_hMainWindow = CreateWindowEx(WS_EX_ACCEPTFILES, VersionDisplay.ToUTF16().c_str(), stdstr(WindowTitle).ToUTF16().c_str(), WS_OVERLAPPED | WS_CLIPCHILDREN | m_hMainWindow = CreateWindowEx(WS_EX_ACCEPTFILES, VersionDisplay.ToUTF16().c_str(), stdstr(WindowTitle).ToUTF16().c_str(), WS_OVERLAPPED | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_SYSMENU | WS_MINIMIZEBOX, 5, 5, 640, 480,
WS_CLIPSIBLINGS | WS_SYSMENU | WS_MINIMIZEBOX, 5, 5, 640, 480,
nullptr, nullptr, GetModuleHandle(nullptr), this); nullptr, nullptr, GetModuleHandle(nullptr), this);
m_Created = m_hMainWindow != nullptr; m_Created = m_hMainWindow != nullptr;
} }
@ -396,7 +396,7 @@ void CMainGui::Create(const char * WindowTitle)
void CMainGui::CreateStatusBar(void) void CMainGui::CreateStatusBar(void)
{ {
m_hStatusWnd = (HWND)CreateStatusWindow(WS_CHILD | WS_VISIBLE, L"", m_hMainWindow, StatusBarID); m_hStatusWnd = (HWND)CreateStatusWindow(WS_CHILD | WS_VISIBLE, L"", m_hMainWindow, StatusBarID);
SendMessage((HWND)m_hStatusWnd, SB_SETTEXT, 0, (LPARAM)""); SendMessage((HWND)m_hStatusWnd, SB_SETTEXT, 0, (LPARAM) "");
ShowWindow(m_hStatusWnd, g_Settings->LoadBool((SettingID)UserInterface_ShowStatusBar) ? SW_SHOW : SW_HIDE); ShowWindow(m_hStatusWnd, g_Settings->LoadBool((SettingID)UserInterface_ShowStatusBar) ? SW_SHOW : SW_HIDE);
} }
@ -454,7 +454,7 @@ void CMainGui::Resize(DWORD /*fwSizeType*/, WORD nWidth, WORD nHeight)
GetClientRect(m_hStatusWnd, &swrect); GetClientRect(m_hStatusWnd, &swrect);
int Parts[2]; int Parts[2];
Parts[0] = (int) (nWidth - 135 * DPIScale(m_hStatusWnd)); Parts[0] = (int)(nWidth - 135 * DPIScale(m_hStatusWnd));
Parts[1] = nWidth; Parts[1] = nWidth;
SendMessage(m_hStatusWnd, SB_SETPARTS, 2, (LPARAM)&Parts[0]); SendMessage(m_hStatusWnd, SB_SETPARTS, 2, (LPARAM)&Parts[0]);
@ -612,11 +612,12 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO
_this->SetPos(X, Y); _this->SetPos(X, Y);
_this->ChangeWinSize(int (640 * _this->DPIScale(hWnd)), int (480 * _this->DPIScale(hWnd))); _this->ChangeWinSize(int(640 * _this->DPIScale(hWnd)), int(480 * _this->DPIScale(hWnd)));
} }
break; break;
case WM_SYSCOMMAND: case WM_SYSCOMMAND:
switch (wParam) { switch (wParam)
{
case SC_SCREENSAVE: case SC_SCREENSAVE:
case SC_MONITORPOWER: case SC_MONITORPOWER:
{ {
@ -774,7 +775,8 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO
{ {
if (g_BaseSystem) if (g_BaseSystem)
{ {
if (g_Plugins && g_Plugins->Control()->WM_KeyUp) { if (g_Plugins && g_Plugins->Control()->WM_KeyUp)
{
g_Plugins->Control()->WM_KeyUp(wParam, lParam); g_Plugins->Control()->WM_KeyUp(wParam, lParam);
} }
} }
@ -832,7 +834,8 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO
g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_AppLostFocus); g_BaseSystem->ExternalEvent(SysEvent_PauseCPU_AppLostFocus);
} }
if (g_Plugins && g_Plugins->Control()->WM_KillFocus) { if (g_Plugins && g_Plugins->Control()->WM_KillFocus)
{
g_Plugins->Control()->WM_KillFocus(wParam, lParam); g_Plugins->Control()->WM_KillFocus(wParam, lParam);
} }
} }
@ -922,7 +925,7 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO
{ {
case JSAPI_ACT_OPEN_ROM: case JSAPI_ACT_OPEN_ROM:
{ {
char* romPath = (char*)lParam; char * romPath = (char *)lParam;
stdstr ext = CPath(romPath).GetExtension(); stdstr ext = CPath(romPath).GetExtension();
if ((_stricmp(ext.c_str(), "ndd") != 0) && if ((_stricmp(ext.c_str(), "ndd") != 0) &&
(_stricmp(ext.c_str(), "d64") != 0)) (_stricmp(ext.c_str(), "d64") != 0))
@ -965,9 +968,10 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN: case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
if (g_Settings->LoadBool(Debugger_Enabled)) { if (g_Settings->LoadBool(Debugger_Enabled))
{
SetCapture(hWnd); SetCapture(hWnd);
CDebuggerUI* debugger = (CDebuggerUI*)g_Debugger; CDebuggerUI * debugger = (CDebuggerUI *)g_Debugger;
debugger->ScriptSystem()->DoMouseEvent(JS_HOOK_MOUSEDOWN, debugger->ScriptSystem()->DoMouseEvent(JS_HOOK_MOUSEDOWN,
GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), uMsg); GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), uMsg);
} }
@ -975,22 +979,24 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO
case WM_LBUTTONUP: case WM_LBUTTONUP:
case WM_MBUTTONUP: case WM_MBUTTONUP:
case WM_RBUTTONUP: case WM_RBUTTONUP:
if (g_Settings->LoadBool(Debugger_Enabled)) { if (g_Settings->LoadBool(Debugger_Enabled))
{
ReleaseCapture(); ReleaseCapture();
CDebuggerUI* debugger = (CDebuggerUI*)g_Debugger; CDebuggerUI * debugger = (CDebuggerUI *)g_Debugger;
debugger->ScriptSystem()->DoMouseEvent(JS_HOOK_MOUSEUP, debugger->ScriptSystem()->DoMouseEvent(JS_HOOK_MOUSEUP,
GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), uMsg); GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), uMsg);
} }
break; break;
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
if (g_Settings->LoadBool(Debugger_Enabled)) { if (g_Settings->LoadBool(Debugger_Enabled))
{
static int lastX = 0; static int lastX = 0;
static int lastY = 0; static int lastY = 0;
int x = GET_X_LPARAM(lParam); int x = GET_X_LPARAM(lParam);
int y = GET_Y_LPARAM(lParam); int y = GET_Y_LPARAM(lParam);
if (lastX != x || lastY != y) if (lastX != x || lastY != y)
{ {
CDebuggerUI* debugger = (CDebuggerUI*)g_Debugger; CDebuggerUI * debugger = (CDebuggerUI *)g_Debugger;
debugger->ScriptSystem()->DoMouseEvent(JS_HOOK_MOUSEMOVE, x, y, (DWORD)-1); debugger->ScriptSystem()->DoMouseEvent(JS_HOOK_MOUSEMOVE, x, y, (DWORD)-1);
lastX = x; lastX = x;
lastY = y; lastY = y;
@ -1002,7 +1008,8 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO
CMainGui * _this = (CMainGui *)GetProp(hWnd, L"Class"); CMainGui * _this = (CMainGui *)GetProp(hWnd, L"Class");
if (_this == nullptr) { break; } if (_this == nullptr) { break; }
switch (LOWORD(wParam)) { switch (LOWORD(wParam))
{
case ID_POPUPMENU_PLAYGAME: case ID_POPUPMENU_PLAYGAME:
{ {
if ((CPath(_this->CurrentedSelectedRom()).GetExtension() != "ndd") && (CPath(_this->CurrentedSelectedRom()).GetExtension() != "d64")) if ((CPath(_this->CurrentedSelectedRom()).GetExtension() != "ndd") && (CPath(_this->CurrentedSelectedRom()).GetExtension() != "d64"))
@ -1082,7 +1089,7 @@ LRESULT CALLBACK CMainGui::MainGui_Proc(HWND hWnd, DWORD uMsg, DWORD wParam, DWO
} }
else if (LOWORD(wParam) == ID_POPUPMENU_EDITCHEATS) else if (LOWORD(wParam) == ID_POPUPMENU_EDITCHEATS)
{ {
CCheatsUI().Display(hWnd,true); CCheatsUI().Display(hWnd, true);
} }
if (g_Disk) if (g_Disk)

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
@ -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;

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")
@ -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

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

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)
{ {
@ -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);
} }
} }
@ -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))
{ {
@ -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,7 +3,7 @@
#include "SettingsPage.h" #include "SettingsPage.h"
CConfigSettingSection::CConfigSettingSection(LPCWSTR PageTitle) : CConfigSettingSection::CConfigSettingSection(LPCWSTR PageTitle) :
m_PageTitle(PageTitle) m_PageTitle(PageTitle)
{ {
} }

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);
@ -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;
@ -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;
@ -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,4 +1,5 @@
#include "stdafx.h" #include "stdafx.h"
#include "HexEditCtrl.h" #include "HexEditCtrl.h"
#include <unordered_map> #include <unordered_map>
@ -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)
{ {
@ -278,8 +279,8 @@ 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))
{ {
@ -376,7 +377,7 @@ 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;
@ -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);
@ -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);
@ -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);
@ -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--;
@ -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