1. The description of the bookmarks in Hex Editor can be edited instead of delete and add again.

2. When click close button of the bookmark name window, the operation can be canceled.
3. Detail.
This commit is contained in:
owomomo 2020-05-12 17:25:23 +08:00
parent b20093f572
commit 2024d321b7
8 changed files with 236 additions and 86 deletions

View File

@ -63,7 +63,6 @@ char temp_chr[40] = {0};
char delimiterChar[2] = "#";
extern INT_PTR CALLBACK nameBookmarkCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
extern char bookmarkDescription[];
MemoryMappedRegister RegNames[] = {
{"$2000", "PPU_CTRL"},
@ -857,10 +856,10 @@ void NameDebuggerBookmark(HWND hwnd)
return;
} else
{
char bookmarkDescription[51] = { 0 };
if (bookmarks_name[selectedItem].size())
{
strcpy(bookmarkDescription, bookmarks_name[selectedItem].c_str());
} else
else
{
bookmarkDescription[0] = 0;
// try to find the same address in bookmarks
@ -874,7 +873,7 @@ void NameDebuggerBookmark(HWND hwnd)
}
}
// Show the bookmark name dialog
if (DialogBox(fceu_hInstance, "NAMEBOOKMARKDLG", hwnd, nameBookmarkCallB))
if (DialogBoxParam(fceu_hInstance, "NAMEBOOKMARKDLG", hwnd, nameBookmarkCallB, (LPARAM)bookmarkDescription))
{
// Rename the selected bookmark
bookmarks_name[selectedItem] = bookmarkDescription;

View File

@ -888,7 +888,6 @@ bool WriteHeaderData(HWND hwnd, iNES_HEADER* header)
SetFocus(GetDlgItem(hwnd, IDC_MAPPER_COMBO));
return false;
}
printf("mapper: %d\n", mapper);
if (mapper < 4096)
{
@ -1091,7 +1090,8 @@ bool WriteHeaderData(HWND hwnd, iNES_HEADER* header)
return false;
}
}
else {
else
{
MessageBox(hwnd, "PRG NVRAM size exceeded the limit (4096KB)", "Error", MB_OK | MB_ICONERROR);
SetFocus(GetDlgItem(hwnd, IDC_PRGNVRAM_COMBO));
return false;

View File

@ -64,7 +64,9 @@ using namespace std;
#define ID_ADDRESS_ADDBP_X 4
#define ID_ADDRESS_SEEK_IN_ROM 5
#define ID_ADDRESS_CREATE_GG_CODE 6
#define ID_ADDRESS_BOOKMARK 20
#define ID_ADDRESS_ADD_BOOKMARK 20
#define ID_ADDRESS_REMOVE_BOOKMARK 21
#define ID_ADDRESS_EDIT_BOOKMARK 22
#define ID_ADDRESS_SYMBOLIC_NAME 30
#define BOOKMARKS_SUBMENU_POS 4
@ -122,11 +124,7 @@ popupmenu[] =
{0x0000,0x3FFF, MODE_NES_PPU, ID_ADDRESS_ADDBP_W, "Add Debugger Write Breakpoint"},
{0x0000,0xFFFF, MODE_NES_MEMORY, ID_ADDRESS_ADDBP_X, "Add Debugger Execute Breakpoint"},
{0x8000,0xFFFF, MODE_NES_MEMORY, ID_ADDRESS_SEEK_IN_ROM, "Go Here In ROM File"},
{0x8000,0xFFFF, MODE_NES_MEMORY, ID_ADDRESS_CREATE_GG_CODE, "Create Game Genie Code At This Address"},
{0x0000,0xFFFF, MODE_NES_MEMORY, ID_ADDRESS_BOOKMARK, "Add / Remove bookmark"},
{0x0000,0xFFFF, MODE_NES_PPU, ID_ADDRESS_BOOKMARK, "Add / Remove bookmark"},
{0x0000,0xFFFF, MODE_NES_OAM, ID_ADDRESS_BOOKMARK, "Add / Remove bookmark"},
{0x0000,0xFFFF, MODE_NES_FILE, ID_ADDRESS_BOOKMARK, "Add / Remove bookmark"},
{0x8000,0xFFFF, MODE_NES_MEMORY, ID_ADDRESS_CREATE_GG_CODE, "Create Game Genie Code At This Address"}
};
#define POPUPNUM (sizeof popupmenu / sizeof popupmenu[0])
@ -849,7 +847,7 @@ void dumpToFile(const char* buffer, unsigned int size)
bool loadFromFile(char* buffer, unsigned int size)
{
char name[513] = {0};
char name[513] = { 0 };
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
@ -914,8 +912,73 @@ void UnfreezeAllRam() {
return;
}
/*
int saveBookmarks(HWND hwnd)
{
char name[513] = { 0 };
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hInstance = fceu_hInstance;
ofn.lpstrTitle = "Save bookmarks as...";
ofn.lpstrFilter = "Bookmark list (*.bld)\0*.lst\0All Files (*.*)\0*.*\0\0";
strcpy(name, mass_replace(GetRomName(), "|", ".").c_str());
ofn.lpstrFile = name;
ofn.lpstrDefExt = "bld";
ofn.nMaxFile = 256;
ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY;
ofn.hwndOwner = hwnd;
bool success = false;
if (GetSaveFileName(&ofn))
{
FILE* bld = fopen(name, "wb");
if (bld)
{
fwrite("BOOKMARKLIST", strlen("BOOKMARKLIST"), 1, bld);
extern int storeHexPreferences(FILE*);
success = storeHexPreferences(bld);
fclose(bld);
}
}
return success;
}
int loadBookmarks(HWND hwnd)
{
char nameo[2048] = { 0 };
OPENFILENAME ofn;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hInstance = fceu_hInstance;
ofn.lpstrTitle = "Load bookmarks...";
ofn.lpstrFilter = "Bookmark list (*.bld)\0*.lst\0All Files (*.*)\0*.*\0\0";
ofn.lpstrFile = nameo;
ofn.nMaxFile = 256;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
ofn.hwndOwner = hwnd;
int success = 0;
if (GetOpenFileName(&ofn))
{
char buffer[13] = { 0 };
FILE* bld = fopen(nameo, "r");
if (bld)
{
fread(bld, strlen("BOOKMARKLIST"), 1, bld);
if (!strcpy(buffer, "BOOKMARKLIST"))
{
extern int loadHexPreferences(FILE*);
success = loadHexPreferences(bld);
}
fclose(bld);
}
}
return success;
}
*/
void FreezeRam(int address, int mode, int final){
// mode: -1 == Unfreeze; 0 == Toggle; 1 == Freeze
if(FrozenAddressCount <= 256 && (address < 0x2000) || ((address >= 0x6000) && (address <= 0x7FFF))){
@ -1198,7 +1261,6 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
HGLOBAL hGlobal ;
PTSTR pGlobal ;
HMENU hMenu;
MENUITEMINFO MenuInfo;
POINT point;
PAINTSTRUCT ps ;
TEXTMETRIC tm;
@ -1525,11 +1587,11 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
//sprintf(str,"x = %d, y = %d, j = %d",mousex,mousey,j);
//MessageBox(hMemView,str, "mouse wheel dance!", MB_OK);
hMenu = CreatePopupMenu();
for(i = 0;i < POPUPNUM;i++)
{
if((j >= popupmenu[i].minaddress) && (j <= popupmenu[i].maxaddress) && (EditingMode == popupmenu[i].editingmode))
{
memset(&MenuInfo,0,sizeof(MENUITEMINFO));
switch(popupmenu[i].id)
{
//this will set the text for the menu dynamically based on the id
@ -1608,15 +1670,21 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
break;
}
}
MenuInfo.cbSize = sizeof(MENUITEMINFO);
MenuInfo.fMask = MIIM_TYPE | MIIM_ID | MIIM_DATA;
MenuInfo.fType = MF_STRING;
MenuInfo.dwTypeData = popupmenu[i].text;
MenuInfo.cch = strlen(popupmenu[i].text);
MenuInfo.wID = popupmenu[i].id;
InsertMenuItem(hMenu,i+1,1,&MenuInfo);
AppendMenu(hMenu, MF_STRING, popupmenu[i].id, popupmenu[i].text);
}
}
// Add / Edit / Remove bookmark
int foundBookmark = findBookmark(CursorStartAddy, EditingMode);
if (foundBookmark != -1)
{
AppendMenu(hMenu, MF_STRING, ID_ADDRESS_EDIT_BOOKMARK, "Edit Bookmark");
AppendMenu(hMenu, MF_STRING, ID_ADDRESS_REMOVE_BOOKMARK, "Remove Bookmark");
}
else
AppendMenu(hMenu, MF_STRING, ID_ADDRESS_ADD_BOOKMARK, "Add Bookmark");
if (i != 0)
i = TrackPopupMenuEx(hMenu, TPM_RETURNCMD | TPM_RIGHTBUTTON, x, y, hMemView, NULL);
switch(i)
@ -1766,19 +1834,59 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case ID_ADDRESS_CREATE_GG_CODE:
SetGGConvFocus(j,GetMem(j));
break;
case ID_ADDRESS_BOOKMARK:
case ID_ADDRESS_ADD_BOOKMARK:
{
if (toggleBookmark(hwnd, CursorStartAddy, EditingMode))
if (foundBookmark == -1)
{
MessageBox(hDebug, "Can't set more than 64 bookmarks", "Error", MB_OK | MB_ICONERROR);
}
else
{
updateBookmarkMenus(GetSubMenu(GetMenu(hwnd), BOOKMARKS_SUBMENU_POS));
UpdateColorTable();
if (nextBookmark >= 64)
MessageBox(hwnd, "Can't set more than 64 bookmarks.", "Error", MB_OK | MB_ICONERROR);
else
{
int ret = addBookmark(hwnd, CursorStartAddy, EditingMode);
if (ret == -1)
MessageBox(hwnd, "Error adding bookmark.", "Error", MB_OK | MB_ICONERROR);
else if (ret == 0)
{
updateBookmarkMenus(GetSubMenu(GetMenu(hwnd), BOOKMARKS_SUBMENU_POS));
UpdateColorTable();
}
}
}
else // usually it cannot reach here.
MessageBox(hwnd, "This address already has a bookmark.", "Error", MB_OK | MB_ICONERROR);
break;
}
case ID_ADDRESS_EDIT_BOOKMARK:
if (foundBookmark != -1)
{
int ret = editBookmark(hwnd, foundBookmark);
if (ret == -1)
MessageBox(hwnd, "Error editing bookmark.", "Error", MB_OK | MB_ICONERROR);
else if (ret == 0)
{
updateBookmarkMenus(GetSubMenu(GetMenu(hwnd), BOOKMARKS_SUBMENU_POS));
UpdateColorTable();
}
}
else // usually it cannot reach here.
MessageBox(hwnd, "This address doesn't have a bookmark.", "Error", MB_OK | MB_ICONERROR);
break;
case ID_ADDRESS_REMOVE_BOOKMARK:
if (foundBookmark != -1)
{
int ret = removeBookmark(foundBookmark);
if (ret == -1)
MessageBox(hwnd, "Error removing bookmark.", "Error", MB_OK | MB_ICONERROR);
else if (ret == 0)
{
updateBookmarkMenus(GetSubMenu(GetMenu(hwnd), BOOKMARKS_SUBMENU_POS));
UpdateColorTable();
}
}
else
// usually it cannot reach here.
MessageBox(hwnd, "This address doesn't have a bookmark.", "Error", MB_OK | MB_ICONERROR);
break;
case ID_ADDRESS_SYMBOLIC_NAME:
{
if (DoSymbolicDebugNaming(j, hMemView))
@ -2117,14 +2225,22 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case MENU_MV_BOOKMARKS_RM_ALL:
if (nextBookmark)
{
if (MessageBox(hwnd, "Remove All Bookmarks?", "Bookmarks", MB_YESNO) == IDYES)
if (MessageBox(hwnd, "Remove All Bookmarks?", "Bookmarks", MB_YESNO | MB_ICONINFORMATION) == IDYES)
{
removeAllBookmarks(GetSubMenu(GetMenu(hwnd), BOOKMARKS_SUBMENU_POS));
UpdateColorTable();
}
}
return 0;
/*
case MENU_MV_BOOKMARKS_EXPORT:
if (!saveBookmarks(hwnd))
MessageBox(hwnd, "Error saving bookmarks.", "Error", MB_OK | MB_ICONERROR);
return 0;
case MENU_MV_BOOKMARKS_IMPORT:
loadBookmarks(hwnd);
return 0;
*/
case MENU_MV_HELP:
OpenHelpWindow(memviewhelp);
return 0;
@ -2201,7 +2317,11 @@ void DoMemView()
wndclass.lpszMenuName = "MEMVIEWMENU";
wndclass.lpszClassName = "MEMVIEW";
if(!RegisterClassEx(&wndclass)) {FCEUD_PrintError("Error Registering MEMVIEW Window Class."); return;}
if(!RegisterClassEx(&wndclass))
{
FCEUD_PrintError("Error Registering MEMVIEW Window Class.");
return;
}
hMemView = CreateWindowEx(0,"MEMVIEW","Memory Editor",
//WS_OVERLAPPEDWINDOW|WS_CLIPSIBLINGS, /* Style */

View File

@ -4,7 +4,10 @@ void UpdateMemoryView(int draw_all);
void UpdateColorTable();
void ChangeMemViewFocus(int newEditingMode, int StartOffset,int EndOffset);
void UpdateCaption();
/*
int saveBookmarks(HWND hwnd);
int loadBookmarks(HWND hwnd);
*/
void ApplyPatch(int addr,int size, uint8* data);
void UndoLastPatch();
@ -13,5 +16,4 @@ void SetHexEditorAddress(int gotoaddress);
extern HWND hMemView, hMemFind;
extern int EditingMode;
extern char EditString[4][20];
extern char EditString[4][20];

View File

@ -52,13 +52,13 @@ int findBookmark(unsigned int address, int editmode)
return -1;
}
char bookmarkDescription[51] = {0};
BOOL CenterWindow(HWND hwndDlg);
/// Callback function for the name bookmark dialog
INT_PTR CALLBACK nameBookmarkCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static char* description;
switch (uMsg)
{
case WM_INITDIALOG:
@ -67,7 +67,9 @@ INT_PTR CALLBACK nameBookmarkCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA
// Put the current bookmark description into the edit field
// and set focus to that edit field.
SetDlgItemText(hwndDlg, IDC_BOOKMARK_DESCRIPTION, bookmarkDescription);
description = (char*)lParam;
SetDlgItemText(hwndDlg, IDC_BOOKMARK_DESCRIPTION, description);
SetFocus(GetDlgItem(hwndDlg, IDC_BOOKMARK_DESCRIPTION));
break;
case WM_CLOSE:
@ -83,7 +85,7 @@ INT_PTR CALLBACK nameBookmarkCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA
case IDOK:
{
// Update the bookmark description
GetDlgItemText(hwndDlg, IDC_BOOKMARK_DESCRIPTION, bookmarkDescription, 50);
GetDlgItemText(hwndDlg, IDC_BOOKMARK_DESCRIPTION, description, 50);
EndDialog(hwndDlg, 1);
break;
}
@ -99,38 +101,63 @@ INT_PTR CALLBACK nameBookmarkCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARA
/// @param hwnd HWND of the FCEU window
/// @param address Address of the new bookmark
/// @param editmode The editing mode of the hex editor (RAM/PPU/OAM/ROM)
/// @return Returns 0 if everything's OK and an error flag otherwise.
/// @return Returns 0 if everything's OK, 1 if user canceled and an error flag otherwise.
int addBookmark(HWND hwnd, unsigned int address, int editmode)
{
// Enforce a maximum of 64 bookmarks
if (nextBookmark < 64)
{
sprintf(bookmarkDescription, "%s %04X", EditString[editmode], address);
char description[51] = { 0 };
sprintf(description, "%s %04X", EditString[editmode], address);
// Show the bookmark name dialog
DialogBox(fceu_hInstance, "NAMEBOOKMARKDLG", hwnd, nameBookmarkCallB);
// Update the bookmark description
hexBookmarks[nextBookmark].address = address;
hexBookmarks[nextBookmark].editmode = editmode;
strcpy(hexBookmarks[nextBookmark].description, bookmarkDescription);
nextBookmark++;
if (DialogBoxParam(fceu_hInstance, "NAMEBOOKMARKDLG", hwnd, nameBookmarkCallB, (LPARAM)description))
{
// Add the bookmark
hexBookmarks[nextBookmark].address = address;
hexBookmarks[nextBookmark].editmode = editmode;
strcpy(hexBookmarks[nextBookmark].description, description);
nextBookmark++;
return 0;
}
else
return 1;
}
else
return -1;
}
/// Edit a bookmark in the bookmark list
/// @param hwnd HWND of the FCEU window
/// @param index Index of the bookmark to edit
/// @return Returns 0 if everything's OK, 1 if user canceled and an error flag otherwise.
int editBookmark(HWND hwnd, unsigned int index)
{
if (index >= 64) return -1;
char description[51] = { 0 };
strcpy(description, hexBookmarks[index].description);
// Show the bookmark name dialog
if (DialogBoxParam(fceu_hInstance, "NAMEBOOKMARKDLG", hwnd, nameBookmarkCallB, (LPARAM)description))
{
// Update the bookmark information
strcpy(hexBookmarks[index].description, description);
return 0;
}
else
{
return 1;
}
return -1;
}
/// Removes a bookmark from the bookmark list
/// @param index Index of the bookmark to remove
void removeBookmark(unsigned int index)
/// @return Returns 0 if everything's OK, 1 if user canceled and an error flag otherwise.
int removeBookmark(unsigned int index)
{
// TODO: Range checking
if (index >= 64) return -1;
// At this point it's necessary to move the content of the bookmark list
for (int i=index;i<nextBookmark - 1;i++)
{
@ -138,8 +165,10 @@ void removeBookmark(unsigned int index)
}
--nextBookmark;
}
return 0;
}
/*
/// Adds or removes a bookmark from a given address
/// @param hwnd HWND of the emu window
/// @param address Address of the bookmark
@ -159,35 +188,28 @@ int toggleBookmark(HWND hwnd, uint32 address, int editmode)
return 0;
}
}
*/
/// Updates the bookmark menu in the hex window
/// @param menu Handle of the bookmark menu
void updateBookmarkMenus(HMENU menu)
{
int i;
MENUITEMINFO mi;
mi.cbSize = sizeof(MENUITEMINFO);
mi.fMask = MIIM_TYPE | MIIM_ID | MIIM_DATA;
mi.fType = MF_STRING;
// Remove all bookmark menus
for (i = 0;i<nextBookmark + 1;i++)
{
for (int i = 0; i<nextBookmark + 1; i++)
RemoveMenu(menu, ID_FIRST_BOOKMARK + i, MF_BYCOMMAND);
}
// Add the menus again
for (i = 0;i<nextBookmark;i++)
RemoveMenu(menu, ID_BOOKMARKLIST_SEP, MF_BYCOMMAND);
if (nextBookmark != 0)
{
// Get the text of the menu
char buffer[0x100];
sprintf(buffer, i < 10 ? "&%d. $%04X - %s\tCtrl+%d" : "%d. $%04X - %s",i, hexBookmarks[i].address, hexBookmarks[i].description, i);
// Add the menus again
AppendMenu(menu, MF_SEPARATOR, ID_BOOKMARKLIST_SEP, NULL);
for (int i = 0;i<nextBookmark;i++)
{
// Get the text of the menu
char buffer[0x100];
sprintf(buffer, i < 10 ? "&%d. $%04X - %s\tCtrl+%d" : "%d. $%04X - %s",i, hexBookmarks[i].address, hexBookmarks[i].description, i);
mi.dwTypeData = buffer;
mi.cch = strlen(buffer);
mi.wID = ID_FIRST_BOOKMARK + i;
InsertMenuItem(menu, 2 + i , TRUE, &mi);
AppendMenu(menu, MF_STRING, ID_FIRST_BOOKMARK + i, buffer);
}
}
}
@ -212,6 +234,7 @@ void removeAllBookmarks(HMENU menu)
{
RemoveMenu(menu, ID_FIRST_BOOKMARK + i, MF_BYCOMMAND);
}
RemoveMenu(menu, ID_BOOKMARKLIST_SEP, MF_BYCOMMAND);
nextBookmark = 0;
}
}

View File

@ -21,6 +21,7 @@
#include "types.h"
#define ID_FIRST_BOOKMARK 30
#define ID_BOOKMARKLIST_SEP (ID_FIRST_BOOKMARK - 1)
typedef struct
{
@ -32,8 +33,11 @@ typedef struct
extern HexBookmark hexBookmarks[64];
extern int nextBookmark;
int toggleBookmark(HWND hwnd, uint32 address, int mode);
int findBookmark(unsigned int address, int editmode);
int addBookmark(HWND hwnd, unsigned int address, int editmode);
int editBookmark(HWND hwnd, unsigned int index);
int removeBookmark(unsigned int index);
// int toggleBookmark(HWND hwnd, uint32 address, int mode);
void updateBookmarkMenus(HMENU menu);
int handleBookmarkMenu(int bookmark);
void removeAllBookmarks(HMENU menu);

View File

@ -797,19 +797,21 @@ INT_PTR CALLBACK EditWatchProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
addrCtrlID = IDC_EDIT_COMPAREADDRESS;
// limit the length to 4 since currently doesn't support batch editing
SendDlgItemMessage(hDlg, addrCtrlID, EM_SETLIMITTEXT, 4, 0);
strcpy(title, "Edit ");
strcpy(title, "Edit");
break;
case WATCHER_MSG_ADD:
strcpy(title, "Add ");
strcpy(title, "Add");
addrCtrlID = IDC_EDIT_COMPAREADDRESSES;
break;
case WATCHER_MSG_DUP:
default:
strcpy(title, "Duplicate ");
strcpy(title, "Duplicate");
addrCtrlID = IDC_EDIT_COMPAREADDRESSES;
break;
}
strcat(title, " ");
// The information is needed to fill to the UI, and separetor doesn't have them
if (msg->Type != 'S')
{

View File

@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ 生成的包含文件。
// 供 res.rc 使用
// Microsoft Visual C++ generated include file.
// Used for res.rc
//
#define CLOSE_BUTTON 1
#define BUTTON_CLOSE 1