📄 nestreme.cpp
字号:
TCITEM tie; // Tab item struction
char strText[128]; // Text to hold the string of the tab
// Get the dimensions of the parent window's client area, and
// create a tab control child window of that size.
GetClientRect(hwndParent, &rcClient);
hwndTab = CreateWindow(WC_TABCONTROL, "",
WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE,
0, 0, rcClient.right, rcClient.bottom,
hwndParent, NULL, g_hInstance, NULL);
if (hwndTab == NULL)
return NULL;
// Add the number of tabs passed to the function.
tie.mask = TCIF_TEXT | TCIF_IMAGE;
tie.iImage = -1;
tie.pszText = strText;
for (UINT i = 0; i < uNumTabs; i++)
{
LoadString(g_hInstance, uTextResource+i, strText, sizeof(strText));
if (TabCtrl_InsertItem(hwndTab, i, &tie) == -1)
{
DestroyWindow(hwndTab);
return NULL;
}
}
// Set the font of the control.
SendMessage(hwndTab, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
return hwndTab;
} // CreateTabControl()
//------------------------------------------------------------------------------
// Name: CreateTooltip()
// Desc: Creates a tooltip window adding the string as the text.
//------------------------------------------------------------------------------
HRESULT CreateTooltip(HWND hwnd, LPSTR strToolTip)
{
TOOLINFO ti; // struct specifying info about tool in tooltip control.
UINT uid = 0; // for ti initialization.
RECT rect; // for client area coordinates.
// Create the tooltip window.
hwndTT = CreateWindowEx(WS_EX_TOPMOST,
TOOLTIPS_CLASS,
NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
hwnd,
NULL,
g_hInstance,
NULL);
// Set the window position.
SetWindowPos(hwndTT,
HWND_TOPMOST,
0,
0,
0,
0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
// Get coordinates of the main window.
GetClientRect(hwnd, &rect);
// Initialize the members fo the tool tip info structure.
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hwnd;
ti.hinst = g_hInstance;
ti.uId = uid;
ti.lpszText = strToolTip;
// Tooltip control will cover the whole window
ti.rect.left = rect.left;
ti.rect.top = rect.top;
ti.rect.right = rect.right;
ti.rect.bottom = rect.bottom;
// Send a message to add the tooltip
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);
SendMessage(hwndTT, TTM_ACTIVATE, (WPARAM)TRUE, 0);
return S_OK;
} // end CreateTooltip()
//------------------------------------------------------------------------------
// Name: DisableBreakpoint()
// Desc: Disables a breakpoint by removing it from the breakpoint array.
//------------------------------------------------------------------------------
HRESULT DisableBreakpoint(UINT uBreakpointIndex, UINT uListViewItem)
{
// Remove the breakpoint from the array by setting it 0.
awBreakpoints[uBreakpointIndex] = 0;
// Copy all the old breakpoints into the old position.
for (int i = uBreakpointIndex; i < OPTIONS_NUM_BREAKPOINTS-1; i++)
awBreakpoints[i] = awBreakpoints[i+1];
// Uncheck the breakpoint in the list view.
ListView_UnCheck(hwndCodeLV, uListViewItem);
// Finally decrement the number of breakpoints.
dwNumBreakpoints--;
return S_OK;
} // end DisableBreakpoint()
//------------------------------------------------------------------------------
// Name: DisplayMainMemDump()
// Desc: Dumps the main memory to a string and sets the text of an edit
// control to that string.
//------------------------------------------------------------------------------
HRESULT DisplayMainMemDump(HWND hwndEditCtrl)
{
char strMemDump[0x1FFFF]; // String to hold the memory dump.
char* pstrMemDump = strMemDump; // Pointer to the memory dump string.
// Dump the first part of main memory to the string.
sprintf(pstrMemDump, "Main Memory: %c%c%c%c%c%c", 13, 13, 10, 13, 13, 10);
pstrMemDump += strlen(strMemDump);
MemoryDumpToString(&pstrMemDump, &CPU.Memory[0], 0, 0x8000);
// Set the text in the edit control.
SendMessage(hwndEditCtrl, WM_SETTEXT, 0, (LPARAM) strMemDump);
return S_OK;
} // DisplayMainMemDump()
//------------------------------------------------------------------------------
// Name: DisplayPPUMemDump()
// Desc: Dumps the PPU memory to a string and sets the text of an edit
// control to that string.
//------------------------------------------------------------------------------
HRESULT DisplayPPUMemDump(HWND hwndEditCtrl)
{
char strMemDump[0x1FFFF]; // String to hold the memory dump.
char* pstrMemDump = strMemDump; // Pointer to the memory dump string.
// Dump the first bank of CHR-ROM to the string.
sprintf(pstrMemDump, "CHR-ROM Bank 1: %c%c%c%c%c%c", 13, 13, 10, 13, 13, 10);
pstrMemDump += 22;
MemoryDumpToString(&pstrMemDump, &(*(PPU.apbyPatternTables[0])), 0, 0x1000);
// Dump the second bank of CHR-ROM to the string.
sprintf(pstrMemDump, "%c%c%c%c%c%cCHR-ROM Bank 2: %c%c%c%c%c%c",
13, 13, 10, 13, 13, 10, 13, 13, 10, 13, 13, 10);
pstrMemDump += 28;
MemoryDumpToString(&pstrMemDump, &(*(PPU.apbyPatternTables[1])), 0, 0x1000);
// Dump the first name and attribute table to the string.
sprintf(pstrMemDump, "%c%c%c%c%c%cName Table 1: %c%c%c%c%c%c",
13, 13, 10, 13, 13, 10, 13, 13, 10, 13, 13, 10);
pstrMemDump += 26;
MemoryDumpToString(&pstrMemDump, &(*(PPU.apbyNameTables[0])), 0, 0x400);
// Dump the second name and attribute table to the string.
sprintf(pstrMemDump, "%c%c%c%c%c%cName Table 2: %c%c%c%c%c%c",
13, 13, 10, 13, 13, 10, 13, 13, 10, 13, 13, 10);
pstrMemDump += 26;
MemoryDumpToString(&pstrMemDump, &(*(PPU.apbyNameTables[1])), 0, 0x400);
// Dump the third name and attribute table to the string.
sprintf(pstrMemDump, "%c%c%c%c%c%cName Table 3: %c%c%c%c%c%c",
13, 13, 10, 13, 13, 10, 13, 13, 10, 13, 13, 10);
pstrMemDump += 26;
MemoryDumpToString(&pstrMemDump, &(*(PPU.apbyNameTables[2])), 0, 0x400);
// Dump the fourth name and attribute table to the string.
sprintf(pstrMemDump, "%c%c%c%c%c%cName Table 4: %c%c%c%c%c%c",
13, 13, 10, 13, 13, 10, 13, 13, 10, 13, 13, 10);
pstrMemDump += 26;
MemoryDumpToString(&pstrMemDump, &(*(PPU.apbyNameTables[3])), 0, 0x400);
// Dump the palettes to the string.
sprintf(pstrMemDump, "%c%c%c%c%c%cPalettes: %c%c%c%c%c%c",
13, 13, 10, 13, 13, 10, 13, 13, 10, 13, 13, 10);
pstrMemDump += 22;
MemoryDumpToString(&pstrMemDump, &(PPU.abyPalettes[0]), 0, 0x20);
// Set the text in the edit control.
SendMessage(hwndEditCtrl, WM_SETTEXT, 0, (LPARAM) strMemDump);
return S_OK;
} // DisplayPPUMemDump()
//------------------------------------------------------------------------------
// Name: DisplayPRGROMMemDump()
// Desc: Dumps the stack memory to a string and sets the text of an edit
// control to that string.
//------------------------------------------------------------------------------
HRESULT DisplayPRGROMMemDump(HWND hwndEditCtrl)
{
char strMemDump[0x1FFFF]; // String to hold the memory dump.
char* pstrMemDump = strMemDump; // Pointer to the memory dump string.
// Dump the first bank of memory to the string.
sprintf(pstrMemDump, "PRG-ROM Bank 1: %c%c%c%c%c%c", 13, 13, 10, 13, 13, 10);
pstrMemDump += 22;
MemoryDumpToString(&pstrMemDump, &(*CPU.pbyPRGROMBank1), 0, 0x4000);
// Dump the second bank of memory to the string.
sprintf(pstrMemDump, "%c%c%c%c%c%cPRG-ROM Bank 2: %c%c%c%c%c%c",
13, 13, 10, 13, 13, 10, 13, 13, 10, 13, 13, 10);
pstrMemDump += 28;
MemoryDumpToString(&pstrMemDump, &(*CPU.pbyPRGROMBank2), 0, 0x4000);
// Set the text in the edit control.
SendMessage(hwndEditCtrl, WM_SETTEXT, 0, (LPARAM) strMemDump);
return S_OK;
} // DisplayPRGROMMemDump()
//------------------------------------------------------------------------------
// Name: DisplaySpriteMemDump()
// Desc: Dumps the sprite memory to a string and sets the text of an edit
// control to that string.
//------------------------------------------------------------------------------
HRESULT DisplaySpriteMemDump(HWND hwndEditCtrl)
{
char strMemDump[0xFFFF]; // String to hold the memory dump.
char* pstrMemDump = strMemDump; // Pointer to the memory dump string.
// Dump the sprite memory to the string.
sprintf(pstrMemDump, "Sprite Memory: %c%c%c%c%c%c", 13, 13, 10, 13, 13, 10);
pstrMemDump += strlen(strMemDump);
MemoryDumpToString(&pstrMemDump, abySPRRAM, 0, 0x100);
// Set the text in the edit control.
SendMessage(hwndEditCtrl, WM_SETTEXT, 0, (LPARAM) strMemDump);
return S_OK;
} // DisplaySpriteMemDump()
//------------------------------------------------------------------------------
// Name: DisplayStackMemDump()
// Desc: Dumps the stack memory to a string and sets the text of an edit
// control to that string.
//------------------------------------------------------------------------------
HRESULT DisplayStackMemDump(HWND hwndEditCtrl)
{
char strMemDump[0xFFFF]; // String to hold the memory dump.
char* pstrMemDump = strMemDump; // Pointer to the memory dump string.
// Dump the stack memory to the string.
sprintf(pstrMemDump, "Stack Memory: %c%c%c%c%c%c", 13, 13, 10, 13, 13, 10);
pstrMemDump += strlen(strMemDump);
MemoryDumpToString(&pstrMemDump, &CPU.Memory[0x100], 0, 0x100);
// Set the text in the edit control.
SendMessage(hwndEditCtrl, WM_SETTEXT, 0, (LPARAM) strMemDump);
return S_OK;
} // DisplayStackMemDump()
//------------------------------------------------------------------------------
// Name: DissassembleROM()
// Desc: Dissassembles the rom from the current PC position and displays
// the results in the code dissassemble list box.
//------------------------------------------------------------------------------
HRESULT DissassembleROM()
{
char strInstr[128]; // String to hold the instruction output.
WORD wPC = CPU.P; // Temporary PC register.
BYTE byNumBytes; // Number of bytes to add to the temp PC register.
// Clear the list view.
ListView_DeleteAllItems(hwndCodeLV);
// Display all the instructions.
for (int i = 0; i < OPTIONS_NUM_DEBUGLINES; i++)
{
// Reset the instruction string.
memset(strInstr, '\0', 128);
// Print the instruction to our string.
byNumBytes = PrintInstrToString(strInstr, wPC);
// Add the strings to the code list view.
InsertListViewText(hwndCodeLV, i, 0, &strInstr[DISASM_PC_OFFSET]);
InsertListViewText(hwndCodeLV, i, 1, &strInstr[DISASM_MACHINECODE_OFFSET]);
InsertListViewText(hwndCodeLV, i, 2, &strInstr[DISASM_INSTRUCTION_OFFSET]);
InsertListViewText(hwndCodeLV, i, 3, &strInstr[DISASM_MEMCONTENTS_OFFSET]);
// TODO: Make sure to add the breakpoint stuff here.
// Move to the next instruction.
wPC += byNumBytes;
}
return S_OK;
} // end DissassembleROM()
//------------------------------------------------------------------------------
// Name: FreeNESFile()
// Desc: Unloads the ROM that has been loaded so a new one can be loaded.
//------------------------------------------------------------------------------
HRESULT FreeNESFile()
{
// Free the mapper library.
FreeLibrary(hinstMapperLib);
// Delete our rom that we allocated.
SAFE_DELETE_ARRAY(abyPRGROM);
SAFE_DELETE_ARRAY(abyCHRROM);
return S_OK;
} // end FreeNESFile()
//------------------------------------------------------------------------------
// Name: InitializeApp()
// Desc: Does any initialization that needs to be done before the
// main windows loop begins.
//------------------------------------------------------------------------------
HRESULT InitializeApp()
{
WNDCLASS wc;
INITCOMMONCONTROLSEX icex;
// Register the frame windows class.
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hInstance = g_hInstance;
wc.lpfnWndProc = (WNDPROC)WndProcMain;
wc.lpszClassName = strClassName;
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU);
wc.style = CS_HREDRAW | CS_VREDRAW;
if (!RegisterClass(&wc))
return ERROR;
// Register the debug window class.
wc.hIcon = LoadIcon(g_hInstance, IDI_APPLICATION);
wc.lpfnWndProc = (WNDPROC)WndProcDebug;
wc.lpszClassName = strDebugClassName;
wc.lpszMenuName = (LPSTR)NULL;
if (!RegisterClass(&wc))
return ERROR;
// Register the memory window class.
wc.hIcon = LoadIcon(g_hInstance, IDI_APPLICATION);
wc.lpfnWndProc = (WNDPROC)WndProcMemory;
wc.lpszClassName = strMemoryClassName;
wc.lpszMenuName = (LPSTR)NULL;
if (!RegisterClass(&wc))
return ERROR;
// Register the run window class.
wc.hIcon = LoadIcon(g_hInstance, IDI_APPLICATION);
wc.lpfnWndProc = (WNDPROC)WndProcRun;
wc.lpszClassName = strRunClassName;
wc.lpszMenuName = (LPSTR)NULL;
if (!RegisterClass(&wc))
return ERROR;
// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex);
// Initialize the global variables
abyPRGROM = NULL;
abyCHRROM = NULL;
return S_OK;
} // InitializeApp()
//------------------------------------------------------------------------------
// Name: InsertListViewText()
// Desc: Inserts text into an item of a list view control.
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -