Fix Issue #89, Hex Editor features etc (#295)

* 1. Fix a bug that VS System, Extend System and Input Device Combobox don't change any value of the header.
2. Add hex preview to iNES Header Editor.

* Detail bug fix.

* Header Editor Hotfix

* ...

* ...

* Trying to fix Issue #89.

* Add array symbolic debug naming feature to Hex Editor.

* Separate the focus of Hex Editor cursor in different color, and Tab key to switch between them.

* 1. Shift+ArrowKeys to select a range of bytes (Shift+Home/End/PageUp/PageDown currently not supported)
2. Tab to switch between Hex and Text column, and use different color to make it clearer.
3. Sorted out some codes of Hex Editor, they are somehow crowded mess with ambiguous.
4. Detail.

* ...

* I hope there's no more bugs digging out...

* Fix calc bug of GetScreenCoordy(int offset).

* Some document says ExtTextOut is a bit faster than TextOut.

* Ctrl, Shift with arrow keys

* ...

* ...

* ...
This commit is contained in:
owomomo 2021-01-13 18:32:11 +08:00 committed by GitHub
parent 8ab8db5809
commit 0e0d75cea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 775 additions and 485 deletions

View File

@ -123,6 +123,12 @@ extern int HexBackColorB;
extern int HexForeColorR;
extern int HexForeColorG;
extern int HexForeColorB;
extern int HexHlBackColorR;
extern int HexHlBackColorG;
extern int HexHlBackColorB;
extern int HexHlForeColorR;
extern int HexHlForeColorG;
extern int HexHlForeColorB;
extern int HexFreezeColorR;
extern int HexFreezeColorG;
extern int HexFreezeColorB;
@ -132,6 +138,12 @@ extern int RomFreezeColorB;
extern int HexBoundColorR;
extern int HexBoundColorG;
extern int HexBoundColorB;
extern int HexHlShdBackColorR;
extern int HexHlShdBackColorG;
extern int HexHlShdBackColorB;
extern int HexHlShdForeColorR;
extern int HexHlShdForeColorG;
extern int HexHlShdForeColorB;
extern int importBookmarkProps;
//adelikat: Hacky fix for Ram Watch recent menu
@ -451,6 +463,18 @@ static CFGSTRUCT fceuconfig[] =
AC(HexForeColorR),
AC(HexForeColorG),
AC(HexForeColorB),
AC(HexHlBackColorR),
AC(HexHlBackColorG),
AC(HexHlBackColorB),
AC(HexHlForeColorR),
AC(HexHlForeColorG),
AC(HexHlForeColorB),
AC(HexHlShdBackColorR),
AC(HexHlShdBackColorG),
AC(HexHlShdBackColorB),
AC(HexHlShdForeColorR),
AC(HexHlShdForeColorG),
AC(HexHlShdForeColorB),
AC(HexFreezeColorR),
AC(HexFreezeColorG),
AC(HexFreezeColorB),

View File

@ -910,7 +910,9 @@ INT_PTR CALLBACK SymbolicNamingCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA
case WM_INITDIALOG:
{
CenterWindow(hwndDlg);
unsigned int newAddress = lParam;
unsigned int* range = (unsigned int*)lParam;
unsigned int newAddress = range[0];
unsigned int arraySize = range[1];
// filename
generateNLFilenameForAddress(newAddress);
SetDlgItemText(hwndDlg, IDC_SYMBOLIC_FILENAME, NLfilename);
@ -925,20 +927,29 @@ INT_PTR CALLBACK SymbolicNamingCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA
if (node->comment && node->comment[0])
SetDlgItemText(hwndDlg, IDC_SYMBOLIC_COMMENT, node->comment);
}
SetDlgItemText(hwndDlg, IDC_EDIT_SYMBOLIC_ARRAY, "10");
SetDlgItemText(hwndDlg, IDC_EDIT_SYMBOLIC_INIT, "0");
// set focus to IDC_SYMBOLIC_NAME
SendMessage(hwndDlg, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwndDlg, IDC_SYMBOLIC_NAME), true);
//always set the limits
SendDlgItemMessage(hwndDlg, IDC_SYMBOLIC_NAME, EM_SETLIMITTEXT, NL_MAX_NAME_LEN, 0);
SendDlgItemMessage(hwndDlg, IDC_SYMBOLIC_COMMENT, EM_SETLIMITTEXT, NL_MAX_MULTILINE_COMMENT_LEN, 0);
SendDlgItemMessage(hwndDlg, IDC_EDIT_SYMBOLIC_ARRAY, EM_SETLIMITTEXT, 2, 0);
SendDlgItemMessage(hwndDlg, IDC_EDIT_SYMBOLIC_INIT, EM_SETLIMITTEXT, 2, 0);
SendDlgItemMessage(hwndDlg, IDC_EDIT_SYMBOLIC_ARRAY, EM_SETLIMITTEXT, 4, 0);
SendDlgItemMessage(hwndDlg, IDC_EDIT_SYMBOLIC_INIT, EM_SETLIMITTEXT, 4, 0);
DefaultEditCtrlProc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_EDIT_SYMBOLIC_ARRAY), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc);
DefaultEditCtrlProc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_EDIT_SYMBOLIC_INIT), GWLP_WNDPROC, (LONG_PTR)FilterEditCtrlProc);
CheckDlgButton(hwndDlg, IDC_CHECK_SYMBOLIC_NAME_OVERWRITE, BST_CHECKED);
CheckDlgButton(hwndDlg, IDC_CHECK_SYMBOLIC_COMMENT_ARRAY_HEAD, BST_CHECKED);
if (arraySize != -1)
{
char str[4];
sprintf(str, "%X", arraySize);
SetDlgItemText(hwndDlg, IDC_EDIT_SYMBOLIC_ARRAY, str);
CheckDlgButton(hwndDlg, IDC_CHECK_SYMBOLIC_ARRAY, BST_CHECKED);
goto symbolic_array;
} else
SetDlgItemText(hwndDlg, IDC_EDIT_SYMBOLIC_ARRAY, "10");
break;
}
case WM_CLOSE:
@ -980,6 +991,7 @@ INT_PTR CALLBACK SymbolicNamingCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA
}
case IDC_CHECK_SYMBOLIC_ARRAY:
{
symbolic_array:
bool array_chk = IsDlgButtonChecked(hwndDlg, IDC_CHECK_SYMBOLIC_ARRAY) == BST_CHECKED;
bool delete_mode = IsDlgButtonChecked(hwndDlg, IDC_CHECK_SYMBOLIC_DELETE) == BST_CHECKED;
bool comment_head_only = IsDlgButtonChecked(hwndDlg, IDC_CHECK_SYMBOLIC_COMMENT_ARRAY_HEAD) == BST_CHECKED;
@ -1054,11 +1066,17 @@ INT_PTR CALLBACK SymbolicNamingCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPA
// returns true if user pressed OK, false if Cancel
bool DoSymbolicDebugNaming(int offset, HWND parentHWND)
{
return DoSymbolicDebugNaming(offset, -1, parentHWND);
}
bool DoSymbolicDebugNaming(int offsetStart, int size, HWND parentHWND)
{
if (!FCEUI_EmulationPaused())
FCEUI_ToggleEmulationPause();
loadNameFiles();
if (DialogBoxParam(fceu_hInstance, MAKEINTRESOURCE(IDD_SYMBOLIC_DEBUG_NAMING), parentHWND, SymbolicNamingCallB, offset))
int range[2] = { offsetStart, size };
if (DialogBoxParam(fceu_hInstance, MAKEINTRESOURCE(IDD_SYMBOLIC_DEBUG_NAMING), parentHWND, SymbolicNamingCallB, (LPARAM)range))
return true;
return false;
}

View File

@ -64,6 +64,7 @@ void GoToDebuggerBookmark(HWND hwnd);
extern bool IsLetterLegalHex(char c);
bool DoSymbolicDebugNaming(int offset, HWND parentHWND);
bool DoSymbolicDebugNaming(int offset, int size, HWND parentHWND);
void AddNewSymbolicName(uint16 newAddress, char* newOffset, char* newName, char* newComment, int size, int init, bool nameOverwrite, bool commentHeadOnly, bool commentOverwrite);
void DeleteSymbolicName(uint16 address, int size);
void WriteNameFileToDisk(const char* filename, Name* node);

View File

@ -1085,11 +1085,11 @@ bool WriteHeaderData(HWND hwnd, iNES_HEADER* header)
SetFocus(GetDlgItem(hwnd, IDC_PRGROM_COMBO));
SendDlgItemMessage(hwnd, IDC_PRGROM_COMBO, EM_SETSEL, 0, -1);
}
return false;
}
else
SetDlgItemText(hwnd, IDC_HEX_HEADER_EDIT, "");
return false;
}
}
else {
@ -1307,29 +1307,29 @@ bool WriteHeaderData(HWND hwnd, iNES_HEADER* header)
if (!fit)
{
int result10 = (chr_rom / 1024 / 8 + 1) * 8 * 1024;
if (result10 < result)
result = result10;
char buf2[64];
if (result % 1024 != 0)
sprintf(buf2, "%dB", result);
else
sprintf(buf2, "%dKB", result / 1024);
sprintf(buf, "CHR ROM size you entered is invalid in iNES 2.0, do you want to set to its nearest value %s?", buf2);
if (MessageBox(hwnd, buf, "Error", MB_YESNO | MB_ICONERROR) == IDYES)
SetDlgItemText(hwnd, IDC_CHRROM_COMBO, buf2);
else
if (header)
{
if (header)
int result10 = (chr_rom / 1024 / 8 + 1) * 8 * 1024;
if (result10 < result)
result = result10;
char buf2[64];
if (result % 1024 != 0)
sprintf(buf2, "%dB", result);
else
sprintf(buf2, "%dKB", result / 1024);
sprintf(buf, "CHR ROM size you entered is invalid in iNES 2.0, do you want to set to its nearest value %s?", buf2);
if (MessageBox(hwnd, buf, "Error", MB_YESNO | MB_ICONERROR) == IDYES)
SetDlgItemText(hwnd, IDC_CHRROM_COMBO, buf2);
else
{
SetFocus(GetDlgItem(hwnd, IDC_CHRROM_COMBO));
SendDlgItemMessage(hwnd, IDC_CHRROM_COMBO, EM_SETSEL, 0, -1);
}
else
SetDlgItemText(hwnd, IDC_HEX_HEADER_EDIT, "");
return false;
}
else
SetDlgItemText(hwnd, IDC_HEX_HEADER_EDIT, "");
return false;
}
}
else {
@ -1657,12 +1657,9 @@ bool WriteHeaderData(HWND hwnd, iNES_HEADER* header)
{
SetFocus(GetDlgItem(hwnd, IDC_MAPPER_COMBO));
SendDlgItemMessage(hwnd, IDC_MAPPER_COMBO, EM_SETSEL, 0, -1);
return false;
}
}
else
SetDlgItemText(hwnd, IDC_HEX_HEADER_EDIT, "");
return false;
}
memcpy(_header.ID, "NES\x1A", 4);
@ -1719,30 +1716,30 @@ int GetComboBoxByteSize(HWND hwnd, UINT id, int* value, iNES_HEADER* header)
}
}
if (header)
if (err)
{
switch (err)
if (header)
{
case errors::FORMAT_ERR:
sprintf(buf, "%s size you entered is invalid, it should be positive decimal integer followed with unit, e.g. 1024B, 128KB, 4MB", name);
break;
case errors::UNIT_ERR:
sprintf(buf, "The unit of %s size you entered is invalid, it must be B, KB or MB", name);
break;
case errors::MINUS_ERR:
sprintf(buf, "Negative value of %s is not supported by iNES header.", name);
break;
}
switch (err)
{
case errors::FORMAT_ERR:
sprintf(buf, "%s size you entered is invalid, it should be positive decimal integer followed with unit, e.g. 1024B, 128KB, 4MB", name);
break;
case errors::UNIT_ERR:
sprintf(buf, "The unit of %s size you entered is invalid, it must be B, KB or MB", name);
break;
case errors::MINUS_ERR:
sprintf(buf, "Negative value of %s is not supported by iNES header.", name);
break;
}
if (err)
{
MessageBox(hwnd, buf, "Error", MB_OK | MB_ICONERROR);
SetFocus(GetDlgItem(hwnd, id));
SendDlgItemMessage(hwnd, id, EM_SETSEL, 0, -1);
}
else
SetDlgItemText(hwnd, IDC_HEX_HEADER_EDIT, "");
}
else
SetDlgItemText(hwnd, IDC_HEX_HEADER_EDIT, "");
return err;
}

File diff suppressed because it is too large Load Diff

View File

@ -12,7 +12,7 @@
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
// Ó¢Óï(ÃÀ¹ú) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
@ -1695,33 +1695,33 @@ BEGIN
GROUPBOX "Settings",IDC_STATIC,6,4,91,177
END
IDD_SYMBOLIC_DEBUG_NAMING DIALOGEX 0, 0, 253, 168
IDD_SYMBOLIC_DEBUG_NAMING DIALOGEX 0, 0, 269, 167
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Symbolic Debug Naming"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LTEXT "&File:",IDC_STATIC,7,7,15,9
EDITTEXT IDC_SYMBOLIC_FILENAME,26,6,220,12,ES_AUTOHSCROLL | ES_READONLY
EDITTEXT IDC_SYMBOLIC_FILENAME,26,6,234,12,ES_AUTOHSCROLL | ES_READONLY
LTEXT "&Address:",IDC_STATIC_SYMBOLIC_ADDRESS,13,26,30,10
EDITTEXT IDC_SYMBOLIC_ADDRESS,45,24,33,13,ES_AUTOHSCROLL | ES_READONLY
CONTROL "A&rray size: 0x",IDC_CHECK_SYMBOLIC_ARRAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,83,25,60,10
EDITTEXT IDC_EDIT_SYMBOLIC_ARRAY,144,23,20,14,ES_UPPERCASE | ES_AUTOHSCROLL | WS_DISABLED
LTEXT "byte(s)",IDC_STATIC_SYMBOLIC_BYTE,168,26,24,8,WS_DISABLED
LTEXT "&Init: 0x",IDC_STATIC_SYMBOLIC_INIT,199,26,26,8,WS_DISABLED
EDITTEXT IDC_EDIT_SYMBOLIC_INIT,226,23,20,14,ES_UPPERCASE | ES_AUTOHSCROLL | WS_DISABLED
EDITTEXT IDC_EDIT_SYMBOLIC_ARRAY,144,23,26,14,ES_UPPERCASE | ES_AUTOHSCROLL | WS_DISABLED
LTEXT "byte(s)",IDC_STATIC_SYMBOLIC_BYTE,175,26,25,8,WS_DISABLED
LTEXT "&Init: 0x",IDC_STATIC_SYMBOLIC_INIT,205,26,26,8,WS_DISABLED
EDITTEXT IDC_EDIT_SYMBOLIC_INIT,234,23,26,14,ES_UPPERCASE | ES_AUTOHSCROLL | WS_DISABLED
LTEXT "&Name:",IDC_STATIC_SYMBOLIC_NAME,20,44,22,10
EDITTEXT IDC_SYMBOLIC_NAME,45,42,201,13,ES_AUTOHSCROLL
EDITTEXT IDC_SYMBOLIC_NAME,45,42,215,13,ES_AUTOHSCROLL
CONTROL "&Overwrite names in array body",IDC_CHECK_SYMBOLIC_NAME_OVERWRITE,
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,45,59,117,10
LTEXT "&Comment:",IDC_STATIC_SYMBOLIC_COMMENT,6,75,37,10
EDITTEXT IDC_SYMBOLIC_COMMENT,45,75,201,43,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
EDITTEXT IDC_SYMBOLIC_COMMENT,45,75,215,43,ES_MULTILINE | ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN
CONTROL "Co&mment head address only",IDC_CHECK_SYMBOLIC_COMMENT_ARRAY_HEAD,
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,45,122,108,10
CONTROL "O&verwrite comments in array body",IDC_CHECK_SYMBOLIC_COMMENT_OVERWRITE,
"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,45,134,129,10
CONTROL "De&lete",IDC_CHECK_SYMBOLIC_DELETE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,151,37,10
DEFPUSHBUTTON "OK",IDOK,142,149,50,14
PUSHBUTTON "Cancel",IDCANCEL,195,149,50,14
DEFPUSHBUTTON "OK",IDOK,158,148,50,14
PUSHBUTTON "Cancel",IDCANCEL,211,148,50,14
END
IDD_REPLAY_METADATA DIALOGEX 0, 0, 325, 250
@ -2088,8 +2088,8 @@ BEGIN
IDD_SYMBOLIC_DEBUG_NAMING, DIALOG
BEGIN
RIGHTMARGIN, 252
BOTTOMMARGIN, 167
RIGHTMARGIN, 268
BOTTOMMARGIN, 166
END
"IDD_REPLAY_METADATA", DIALOG
@ -3088,7 +3088,7 @@ IDB_BITMAP_SELECTED17 BITMAP "res\\te_17_selected.bmp"
IDB_BITMAP_SELECTED18 BITMAP "res\\te_18_selected.bmp"
IDB_BITMAP_SELECTED19 BITMAP "res\\te_19_selected.bmp"
IDB_BRANCH_SPRITESHEET BITMAP "res\\branch_spritesheet.bmp"
#endif // English (United States) resources
#endif // Ó¢Óï(ÃÀ¹ú) resources
/////////////////////////////////////////////////////////////////////////////