Win32 - RamWatch - code cleanup

This commit is contained in:
adelikat 2009-05-08 13:18:38 +00:00
parent f085acf680
commit 63200b09c8
1 changed files with 6 additions and 112 deletions

View File

@ -32,7 +32,6 @@ int WatchCount=0;
bool QuickSaveWatches(); bool QuickSaveWatches();
bool ResetWatches(); bool ResetWatches();
//extern "C" int Clear_Sound_Buffer(void);
unsigned int GetCurrentValue(AddressWatcher& watch) unsigned int GetCurrentValue(AddressWatcher& watch)
{ {
@ -103,14 +102,6 @@ LRESULT CALLBACK PromptWatchNameProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM
switch(uMsg) switch(uMsg)
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
// Clear_Sound_Buffer();
/* if (Full_Screen)
{
while (ShowCursor(false) >= 0);
while (ShowCursor(true) < 0);
}*/
GetWindowRect(MainWindow->getHWnd(), &r); GetWindowRect(MainWindow->getHWnd(), &r);
dx1 = (r.right - r.left) / 2; dx1 = (r.right - r.left) / 2;
dy1 = (r.bottom - r.top) / 2; dy1 = (r.bottom - r.top) / 2;
@ -119,12 +110,11 @@ LRESULT CALLBACK PromptWatchNameProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM
dx2 = (r2.right - r2.left) / 2; dx2 = (r2.right - r2.left) / 2;
dy2 = (r2.bottom - r2.top) / 2; dy2 = (r2.bottom - r2.top) / 2;
//SetWindowPos(hDlg, NULL, max(0, r.left + (dx1 - dx2)), max(0, r.top + (dy1 - dy2)), NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
strcpy(Str_Tmp,"Enter a name for this RAM address."); strcpy(Str_Tmp,"Enter a name for this RAM address.");
// SendDlgItemMessage(hDlg,IDC_PROMPT_TEXT,WM_SETTEXT,0,(LPARAM)Str_Tmp); //SendDlgItemMessage(hDlg,IDC_PROMPT_TEXT,WM_SETTEXT,0,(LPARAM)Str_Tmp);
strcpy(Str_Tmp,""); strcpy(Str_Tmp,"");
// SendDlgItemMessage(hDlg,IDC_PROMPT_TEXT2,WM_SETTEXT,0,(LPARAM)Str_Tmp); //SendDlgItemMessage(hDlg,IDC_PROMPT_TEXT2,WM_SETTEXT,0,(LPARAM)Str_Tmp);
return true; return true;
break; break;
@ -133,27 +123,14 @@ LRESULT CALLBACK PromptWatchNameProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM
{ {
case IDOK: case IDOK:
{ {
/* if (Full_Screen)
{
while (ShowCursor(true) < 0);
while (ShowCursor(false) >= 0);
}*/
GetDlgItemText(hDlg,IDC_PROMPT_EDIT,Str_Tmp,80); GetDlgItemText(hDlg,IDC_PROMPT_EDIT,Str_Tmp,80);
InsertWatch(rswatches[WatchCount],Str_Tmp); InsertWatch(rswatches[WatchCount],Str_Tmp);
// DialogsOpen--;
EndDialog(hDlg, true); EndDialog(hDlg, true);
return true; return true;
break; break;
} }
// case ID_CANCEL:
case IDCANCEL: case IDCANCEL:
/* if (Full_Screen)
{
while (ShowCursor(true) < 0);
while (ShowCursor(false) >= 0);
}*/
// DialogsOpen--;
EndDialog(hDlg, false); EndDialog(hDlg, false);
return false; return false;
break; break;
@ -161,12 +138,6 @@ LRESULT CALLBACK PromptWatchNameProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM
break; break;
case WM_CLOSE: case WM_CLOSE:
/* if (Full_Screen)
{
while (ShowCursor(true) < 0);
while (ShowCursor(false) >= 0);
}*/
// DialogsOpen--;
EndDialog(hDlg, false); EndDialog(hDlg, false);
return false; return false;
break; break;
@ -413,13 +384,6 @@ void OpenRWRecentFile(int memwRFileNumber)
char mode; char mode;
fgets(Str_Tmp,1024,WatchFile); fgets(Str_Tmp,1024,WatchFile);
sscanf(Str_Tmp,"%c%*s",&mode); sscanf(Str_Tmp,"%c%*s",&mode);
/* if ((mode == '1' && !(SegaCD_Started)) || (mode == '2' && !(_32X_Started)))
{
char Device[8];
strcpy(Device,(mode > '1')?"32X":"SegaCD");
sprintf(Str_Tmp,"Warning: %s not started. \nWatches for %s addresses will be ignored.",Device,Device);
MessageBox(MESSAGEBOXPARENT,Str_Tmp,"Possible Device Mismatch",MB_OK);
}*/
int WatchAdd; int WatchAdd;
fgets(Str_Tmp,1024,WatchFile); fgets(Str_Tmp,1024,WatchFile);
sscanf(Str_Tmp,"%d%*s",&WatchAdd); sscanf(Str_Tmp,"%d%*s",&WatchAdd);
@ -487,7 +451,6 @@ bool Save_Watches()
{ {
FILE *WatchFile = fopen(Str_Tmp,"r+b"); FILE *WatchFile = fopen(Str_Tmp,"r+b");
if (!WatchFile) WatchFile = fopen(Str_Tmp,"w+b"); if (!WatchFile) WatchFile = fopen(Str_Tmp,"w+b");
// fputc(SegaCD_Started?'1':(_32X_Started?'2':'0'),WatchFile);
fputc('\n',WatchFile); fputc('\n',WatchFile);
strcpy(currentWatch,Str_Tmp); strcpy(currentWatch,Str_Tmp);
RWAddRecentFile(currentWatch); RWAddRecentFile(currentWatch);
@ -502,7 +465,6 @@ bool Save_Watches()
fclose(WatchFile); fclose(WatchFile);
RWfileChanged=false; RWfileChanged=false;
//TODO: Add to recent list function call here
return true; return true;
} }
return false; return false;
@ -511,7 +473,7 @@ bool Save_Watches()
bool QuickSaveWatches() bool QuickSaveWatches()
{ {
if (RWfileChanged==false) return true; //If file has not changed, no need to save changes if (RWfileChanged==false) return true; //If file has not changed, no need to save changes
if (currentWatch[0] == NULL) //If there is no currently loaded file, run to Save as and then return if (currentWatch[0] == NULL) //If there is no currently loaded file, run to Save as and then return
{ {
return Save_Watches(); return Save_Watches();
} }
@ -519,7 +481,6 @@ if (currentWatch[0] == NULL) //If there is no currently loaded file, run to Save
strcpy(Str_Tmp,currentWatch); strcpy(Str_Tmp,currentWatch);
FILE *WatchFile = fopen(Str_Tmp,"r+b"); FILE *WatchFile = fopen(Str_Tmp,"r+b");
if (!WatchFile) WatchFile = fopen(Str_Tmp,"w+b"); if (!WatchFile) WatchFile = fopen(Str_Tmp,"w+b");
// fputc(SegaCD_Started?'1':(_32X_Started?'2':'0'),WatchFile);
fputc('\n',WatchFile); fputc('\n',WatchFile);
sprintf(Str_Tmp,"%d\n",WatchCount); sprintf(Str_Tmp,"%d\n",WatchCount);
fputs(Str_Tmp,WatchFile); fputs(Str_Tmp,WatchFile);
@ -557,13 +518,6 @@ bool Load_Watches(bool clear, const char* filename)
char mode; char mode;
fgets(Str_Tmp,1024,WatchFile); fgets(Str_Tmp,1024,WatchFile);
sscanf(Str_Tmp,"%c%*s",&mode); sscanf(Str_Tmp,"%c%*s",&mode);
/* if ((mode == '1' && !(SegaCD_Started)) || (mode == '2' && !(_32X_Started)))
{
char Device[8];
strcpy(Device,(mode > '1')?"32X":"SegaCD");
sprintf(Str_Tmp,"Warning: %s not started. \nWatches for %s addresses will be ignored.",Device,Device);
MessageBox(MESSAGEBOXPARENT,Str_Tmp,"Possible Device Mismatch",MB_OK);
}*/
int WatchAdd; int WatchAdd;
fgets(Str_Tmp,1024,WatchFile); fgets(Str_Tmp,1024,WatchFile);
sscanf(Str_Tmp,"%d%*s",&WatchAdd); sscanf(Str_Tmp,"%d%*s",&WatchAdd);
@ -658,13 +612,6 @@ void RemoveWatch(int watchIndex)
rswatches[i] = rswatches[i+1]; rswatches[i] = rswatches[i+1];
WatchCount--; WatchCount--;
} }
/*
bool IsHardwareRAMAddressValid(unsigned int address) {
return true;
};*/
LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) //Gets info for a RAM Watch, and then inserts it into the Watch List LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) //Gets info for a RAM Watch, and then inserts it into the Watch List
{ {
@ -677,14 +624,6 @@ LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
switch(uMsg) switch(uMsg)
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
// Clear_Sound_Buffer();
/* if (Full_Screen)
{
while (ShowCursor(false) >= 0);
while (ShowCursor(true) < 0);
}*/
GetWindowRect(MainWindow->getHWnd(), &r); GetWindowRect(MainWindow->getHWnd(), &r);
dx1 = (r.right - r.left) / 2; dx1 = (r.right - r.left) / 2;
dy1 = (r.bottom - r.top) / 2; dy1 = (r.bottom - r.top) / 2;
@ -693,7 +632,6 @@ LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
dx2 = (r2.right - r2.left) / 2; dx2 = (r2.right - r2.left) / 2;
dy2 = (r2.bottom - r2.top) / 2; dy2 = (r2.bottom - r2.top) / 2;
//SetWindowPos(hDlg, NULL, max(0, r.left + (dx1 - dx2)), max(0, r.top + (dy1 - dy2)), NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW); SetWindowPos(hDlg, NULL, r.left, r.top, NULL, NULL, SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
index = (int)lParam; index = (int)lParam;
sprintf(Str_Tmp,"%08X",rswatches[index].Address); sprintf(Str_Tmp,"%08X",rswatches[index].Address);
@ -759,11 +697,6 @@ LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
return true; return true;
case IDOK: case IDOK:
{ {
/* if (Full_Screen)
{
while (ShowCursor(true) < 0);
while (ShowCursor(false) >= 0);
}*/
if (s && t) if (s && t)
{ {
AddressWatcher Temp; AddressWatcher Temp;
@ -788,7 +721,6 @@ LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
{ {
ListView_SetItemCount(GetDlgItem(RamWatchHWnd,IDC_WATCHLIST),WatchCount); ListView_SetItemCount(GetDlgItem(RamWatchHWnd,IDC_WATCHLIST),WatchCount);
} }
// DialogsOpen--;
EndDialog(hDlg, true); EndDialog(hDlg, true);
} }
else else
@ -809,14 +741,7 @@ LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
return true; return true;
break; break;
} }
// case ID_CANCEL:
case IDCANCEL: case IDCANCEL:
/* if (Full_Screen)
{
while (ShowCursor(true) < 0);
while (ShowCursor(false) >= 0);
}*/
// DialogsOpen--;
EndDialog(hDlg, false); EndDialog(hDlg, false);
return false; return false;
break; break;
@ -824,12 +749,6 @@ LRESULT CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
break; break;
case WM_CLOSE: case WM_CLOSE:
/* if (Full_Screen)
{
while (ShowCursor(true) < 0);
while (ShowCursor(false) >= 0);
}*/
// DialogsOpen--;
EndDialog(hDlg, false); EndDialog(hDlg, false);
return false; return false;
break; break;
@ -855,8 +774,6 @@ void init_list_box(HWND Box, const char* Strs[], int numColumns, int *columnWidt
ListView_SetExtendedListViewStyle(Box, LVS_EX_FULLROWSELECT); ListView_SetExtendedListViewStyle(Box, LVS_EX_FULLROWSELECT);
} }
//int ResultCount = 0; //TODO make sure this isn't breaking anything
LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
RECT r; RECT r;
@ -877,12 +794,6 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
}; };
case WM_INITDIALOG: { case WM_INITDIALOG: {
/* if (Full_Screen)
{
while (ShowCursor(false) >= 0);
while (ShowCursor(true) < 0);
}*/
GetWindowRect(MainWindow->getHWnd(), &r); //Ramwatch window GetWindowRect(MainWindow->getHWnd(), &r); //Ramwatch window
dx1 = (r.right - r.left) / 2; dx1 = (r.right - r.left) / 2;
dy1 = (r.bottom - r.top) / 2; dy1 = (r.bottom - r.top) / 2;
@ -936,7 +847,7 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
// if (!noMisalign) SendDlgItemMessage(hDlg, IDC_MISALIGN, BM_SETCHECK, BST_CHECKED, 0); // if (!noMisalign) SendDlgItemMessage(hDlg, IDC_MISALIGN, BM_SETCHECK, BST_CHECKED, 0);
// if (littleEndian) SendDlgItemMessage(hDlg, IDC_ENDIAN, BM_SETCHECK, BST_CHECKED, 0); // if (littleEndian) SendDlgItemMessage(hDlg, IDC_ENDIAN, BM_SETCHECK, BST_CHECKED, 0);
//TODO what? RamWatchAccels = LoadAccelerators(hAppInst, MAKEINTRESOURCE(IDR_ACCELERATOR1)); RamWatchAccels = LoadAccelerators(hAppInst, MAKEINTRESOURCE(IDR_ACCELERATOR1));
// due to some bug in windows, the arrow button width from the resource gets ignored, so we have to set it here // due to some bug in windows, the arrow button width from the resource gets ignored, so we have to set it here
SetWindowPos(GetDlgItem(hDlg,ID_WATCHES_UPDOWN), 0,0,0, 30,60, SWP_NOMOVE); SetWindowPos(GetDlgItem(hDlg,ID_WATCHES_UPDOWN), 0,0,0, 30,60, SWP_NOMOVE);
@ -954,7 +865,6 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
case WM_MENUSELECT: case WM_MENUSELECT:
case WM_ENTERSIZEMOVE: case WM_ENTERSIZEMOVE:
// Clear_Sound_Buffer();
break; break;
case WM_NOTIFY: case WM_NOTIFY:
@ -1019,15 +929,12 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
break; break;
case RAMMENU_FILE_SAVEAS: case RAMMENU_FILE_SAVEAS:
//case IDC_C_SAVE:
return Save_Watches(); return Save_Watches();
case RAMMENU_FILE_OPEN: case RAMMENU_FILE_OPEN:
return Load_Watches(true); return Load_Watches(true);
case RAMMENU_FILE_APPEND: case RAMMENU_FILE_APPEND:
//case IDC_C_LOAD:
return Load_Watches(false); return Load_Watches(false);
case RAMMENU_FILE_NEW: case RAMMENU_FILE_NEW:
//case IDC_C_RESET:
ResetWatches(); ResetWatches();
return true; return true;
case IDC_C_WATCH_REMOVE: case IDC_C_WATCH_REMOVE:
@ -1111,17 +1018,10 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
case IDC_C_ADDCHEAT: case IDC_C_ADDCHEAT:
{ {
watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST)) | (1 << 24); watchIndex = ListView_GetSelectionMark(GetDlgItem(hDlg,IDC_WATCHLIST)) | (1 << 24);
// DialogBoxParam(hAppInst, MAKEINTRESOURCE(IDD_EDITCHEAT), hDlg, (DLGPROC) EditCheatProc,(LPARAM) searchIndex); // DialogBoxParam(hAppInst, MAKEINTRESOURCE(IDD_EDITCHEAT), hDlg, (DLGPROC) EditCheatProc,(LPARAM) searchIndex); //TODO: made a IDD_EDITCHEAT dialog, and EditCheatProc (are they in GENS?) and integrate into cheats system
break; break;
} }
case IDOK: case IDCANCEL:
case IDCANCEL: //TODO this immediately activates and closes the window if you uncomment it
/* if (Full_Screen)
{
while (ShowCursor(true) < 0);
while (ShowCursor(false) >= 0);
}*/
// DialogsOpen--;
RamWatchHWnd = NULL; RamWatchHWnd = NULL;
DragAcceptFiles(hDlg, FALSE); DragAcceptFiles(hDlg, FALSE);
EndDialog(hDlg, true); EndDialog(hDlg, true);
@ -1145,12 +1045,6 @@ LRESULT CALLBACK RamWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
} break; } break;
case WM_CLOSE: case WM_CLOSE:
/* if (Full_Screen)
{
while (ShowCursor(true) < 0);
while (ShowCursor(false) >= 0);
}*/
// DialogsOpen--;
RamWatchHWnd = NULL; RamWatchHWnd = NULL;
DragAcceptFiles(hDlg, FALSE); DragAcceptFiles(hDlg, FALSE);
EndDialog(hDlg, true); EndDialog(hDlg, true);