Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win32 debugger tweaks and fixes #368

Open
wants to merge 103 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
a3689c3
kill combined label/offset disassembly
warmCabin Jun 9, 2021
3e21f15
change loop condition and update comments
warmCabin Jun 9, 2021
3995dfc
get rid of address/label debugging once and for all
warmCabin Jun 9, 2021
fbe8bf8
add that == L' ' line back in
warmCabin Jun 9, 2021
77b4181
don't do symbolic address coloring on comment lines
warmCabin Jun 9, 2021
41f5be8
add lines to RTI opcodes
warmCabin Jun 9, 2021
07c81ea
initial attempt at .byte directive
warmCabin Jun 9, 2021
91cfeb4
fix incredibly simple build errors
warmCabin Jun 9, 2021
239e03b
Revert "fix incredibly simple build errors"
warmCabin Jun 9, 2021
a1b2a8c
Revert "initial attempt at .byte directive"
warmCabin Jun 9, 2021
bf8639f
add inlineAddressEnabled flag
warmCabin Jun 21, 2021
4669de1
split out a replaceRegNames method
warmCabin Jun 22, 2021
000dac3
add button to toggle combined label/offset disassembly
warmCabin Jun 22, 2021
66d5025
clean up some REALLY crufty comments
warmCabin Jun 22, 2021
8c71886
tweak vxxproj to work on VSCode 2017
warmCabin Jun 22, 2021
21270c7
rename to inline addresses
warmCabin Jun 22, 2021
ab45f90
add the toggle to an options menu and rename it
warmCabin Jun 22, 2021
ef7ac99
consolidate some things into a Symbols menu item
warmCabin Jun 22, 2021
e40b2a4
put actual functionality in the menu items
warmCabin Jun 23, 2021
97b0e74
MISSED ONE
warmCabin Jun 23, 2021
9123765
rename to restore defaults
warmCabin Jun 23, 2021
712d6ef
add load .DEB file and define a macro
warmCabin Jun 23, 2021
636ea70
replace macros with inline functions
warmCabin Jun 23, 2021
92e258f
add skeleton for options menu
warmCabin Jun 23, 2021
ab7a4f0
MISSED ANOTHER ONE
warmCabin Jun 23, 2021
545a25b
implement the Options menu
warmCabin Jun 23, 2021
7bc2d5e
put color menu item labels in title case
warmCabin Jun 23, 2021
b1db239
add tools menu
warmCabin Jun 23, 2021
a44232d
add a few comments
warmCabin Jun 23, 2021
c1d2af7
split out the "gameless" window callbacks into dedicated functions
warmCabin Jun 24, 2021
6b004b4
split out some of the "gameful" callbacks into dedicated functions
warmCabin Jun 24, 2021
d3a15d7
move UpdateSymbolsPopup calls into DebuggerInitMenuPopup
warmCabin Jun 24, 2021
ca11b64
split out the context menu
warmCabin Jun 24, 2021
8dec80e
move UpdateOptionsPopup call into InitMenuPopup
warmCabin Jun 24, 2021
31a90b9
split out the mousey ones
warmCabin Jun 25, 2021
5dfa77a
initial implementation of code dumping
warmCabin Jun 25, 2021
6527ab4
add logic to make it respect labels
warmCabin Jun 25, 2021
ff41cbc
refine the logic so it still writes the raw bytes
warmCabin Jun 25, 2021
e1a73c3
refactor to avoid goto
warmCabin Jun 25, 2021
ff4c742
remove trace info
warmCabin Jun 25, 2021
af47c8c
clean things up a bit
warmCabin Jun 25, 2021
e178581
split patcher, assembler, and some disassembly logic to where it belongs
warmCabin Jun 26, 2021
c262b08
initial commit for code dumper UI
warmCabin Jun 26, 2021
784771f
tweak dumper window in editor
warmCabin Jun 26, 2021
eb7847e
split Dump stuff to dumper.cpp and add some frontend
warmCabin Jun 28, 2021
86aee79
fix input handling in dumper dialog
warmCabin Jun 28, 2021
b9359d8
split out separate handler methods
warmCabin Jun 28, 2021
a57ecb8
support .NES file addresses checkbox
warmCabin Jun 28, 2021
db071d0
clean up message handling for more fluent control
warmCabin Jun 28, 2021
34fcc12
add file browsing functionality
warmCabin Jun 28, 2021
81e62e1
add loading cursor and wait beep for long dumps
warmCabin Jun 28, 2021
fc60358
add IDCANCEL and IDOK processing to patcher
warmCabin Jun 28, 2021
cd13ee2
revive that "dead" EN_CHANGE code in a new callback
warmCabin Jun 28, 2021
53c36d9
use new callbacks instead of DebuggerCallB when posible
warmCabin Jun 28, 2021
58b1510
replace remaining instances of that confusing comment with my verbiage
warmCabin Jun 28, 2021
e23e643
add enter-press functionality to a few text fields
warmCabin Jun 28, 2021
2312ff3
Add enter-press functionality for break-when-exceed fields
warmCabin Jun 28, 2021
c376a44
add "break on bad opcodes" to menu
warmCabin Jun 28, 2021
86d6c1b
rename stuff and add comments
warmCabin Jun 28, 2021
2b0e483
obfuscate callback return type so it compiles on 64-bit machines
warmCabin Jun 29, 2021
4e0f034
janky merge conflict dodge
warmCabin Jun 29, 2021
d55e8ec
show a blank screen when no game is loaded
warmCabin Jun 29, 2021
e2cb9da
fix '>' in comments highlighting like the PC
warmCabin Jun 29, 2021
4370400
initial attempt at making scrolling comment-sensitive
warmCabin Jun 30, 2021
8afeb34
make scrolling comment-sensitive (for real)
warmCabin Jun 30, 2021
aa2c6ae
combine PCLine and PC_pointerOffset
warmCabin Jun 30, 2021
7c5f08f
remove the unused permanent buttons
warmCabin Jul 4, 2021
fbb6176
remove SP CODE comments
warmCabin Jul 5, 2021
d143c69
refactor the comment offset stuff into methods that deal with it for you
warmCabin Jul 7, 2021
557f73c
remove ancient comments
warmCabin Jul 7, 2021
d8043b7
add showTrace param to asm.cpp functions
warmCabin Jul 8, 2021
61842ca
make DisassembleLine just call DisassembleData
warmCabin Jul 8, 2021
cb830bf
add ROM offsets param to DisassembleToLine
warmCabin Jul 8, 2021
639d04a
change "bad opcodes" to "unofficial opcodes"
warmCabin Jul 8, 2021
be59ac9
fix PC relative screen position not working
warmCabin Jul 8, 2021
80ee06a
add toggle for showing trace info
warmCabin Jul 8, 2021
fe9b714
cheat the merge conflict
warmCabin Jul 9, 2021
49a20c9
delete duplicate resource
warmCabin Jul 9, 2021
6e0a3a8
add toggles for CDL breaks
warmCabin Jul 10, 2021
ac71eb4
initial hotkey ideas
warmCabin Jul 23, 2021
13bd9dd
make color dialog a sub menu
warmCabin Aug 2, 2021
2d1cd5e
add run and step over hotkeys
warmCabin Aug 2, 2021
052be52
fixup the hotkey method
warmCabin Aug 2, 2021
a9205ea
down with hotkeys, long live accelerators!
warmCabin Aug 11, 2021
5f368af
comments and menu label change
warmCabin Aug 11, 2021
5a483e3
make it actually work
warmCabin Aug 11, 2021
b7f5dbf
fix annoying BRK scroll bug
warmCabin Aug 23, 2022
b32d9f1
initial commit for data blocks
warmCabin Aug 23, 2022
97b0f83
move some logic to asm.cpp
warmCabin Aug 23, 2022
e92e84d
further cleanup
warmCabin Aug 23, 2022
7321ee3
add toggle to show unlogged bytes as data
warmCabin Aug 23, 2022
883b542
add comma
warmCabin Aug 23, 2022
5d5963a
make InstructionUp and InstructionDown respect data blocks
warmCabin Aug 23, 2022
c90cc26
gray out CDL-related options if CDL is inactive
warmCabin Aug 23, 2022
9f9354a
fix accidental fallthrough
warmCabin Aug 23, 2022
3457863
add a submenu for CDL flags
warmCabin Aug 23, 2022
9350618
add some accelerators
warmCabin Aug 23, 2022
d4f7de3
clean up syntax highlighter
warmCabin Aug 23, 2022
959a3fd
futz with the menu
warmCabin Aug 24, 2022
bd3b4df
add option to toggle PC following
warmCabin Aug 24, 2022
3cf3379
change accelerator
warmCabin Aug 24, 2022
56c1fcd
comment
warmCabin Aug 24, 2022
44b8295
remove jankyHandle
warmCabin Aug 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 106 additions & 16 deletions src/asm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ int Assemble(unsigned char *output, int addr, char *str) {
return 0;
}

///disassembles the opcodes in the buffer assuming the provided address. Uses GetMem() and 6502 current registers to query referenced values. returns a static string buffer.
char *Disassemble(int addr, uint8 *opcode) {
///Disassembles the instruction bytes in the buffer using the provided address for trace info. Uses GetMem() and 6502 current registers to query referenced values. Returns a static string buffer.
char *Disassemble(int addr, uint8 *opcode, bool showTrace) {
static char str[64]={0},chr[5]={0};
uint16 tmp,tmp2;

Expand Down Expand Up @@ -333,7 +333,9 @@ char *Disassemble(int addr, uint8 *opcode) {
case 0xE1: strcpy(chr,"SBC"); goto _indirectx;
_indirectx:
indirectX(tmp);
sprintf(str,"%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
showTrace
? sprintf(str,"%s ($%02X,X) @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp))
: sprintf(str,"%s ($%02X,X)", chr,opcode[1]);
break;

//Zero Page
Expand All @@ -359,10 +361,10 @@ char *Disassemble(int addr, uint8 *opcode) {
case 0xE5: strcpy(chr,"SBC"); goto _zeropage;
case 0xE6: strcpy(chr,"INC"); goto _zeropage;
_zeropage:
// ################################## Start of SP CODE ###########################
// Change width to %04X // don't!
sprintf(str,"%s $%02X = #$%02X", chr,opcode[1],GetMem(opcode[1]));
// ################################## End of SP CODE ###########################
showTrace
? sprintf(str,"%s $%02X = #$%02X", chr,opcode[1],GetMem(opcode[1]))
: sprintf(str,"%s $%02X", chr,opcode[1]);
break;

//#Immediate
Expand Down Expand Up @@ -406,7 +408,9 @@ char *Disassemble(int addr, uint8 *opcode) {
case 0xEE: strcpy(chr,"INC"); goto _absolute;
_absolute:
absolute(tmp);
sprintf(str,"%s $%04X = #$%02X", chr,tmp,GetMem(tmp));
showTrace
? sprintf(str,"%s $%04X = #$%02X", chr,tmp,GetMem(tmp))
: sprintf(str,"%s $%04X", chr,tmp);
break;

//branches
Expand Down Expand Up @@ -434,7 +438,9 @@ char *Disassemble(int addr, uint8 *opcode) {
case 0xF1: strcpy(chr,"SBC"); goto _indirecty;
_indirecty:
indirectY(tmp);
sprintf(str,"%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
showTrace
? sprintf(str,"%s ($%02X),Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp))
: sprintf(str,"%s ($%02X),Y", chr,opcode[1]);
break;

//Zero Page,X
Expand All @@ -456,10 +462,10 @@ char *Disassemble(int addr, uint8 *opcode) {
case 0xF6: strcpy(chr,"INC"); goto _zeropagex;
_zeropagex:
zpIndex(tmp,RX);
// ################################## Start of SP CODE ###########################
// Change width to %04X // don't!
sprintf(str,"%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
// ################################## End of SP CODE ###########################
showTrace
? sprintf(str,"%s $%02X,X @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp))
: sprintf(str,"%s $%02X,X", chr,opcode[1]);
break;

//Absolute,Y
Expand All @@ -475,7 +481,9 @@ char *Disassemble(int addr, uint8 *opcode) {
_absolutey:
absolute(tmp);
tmp2=(tmp+RY);
sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2));
showTrace
? sprintf(str,"%s $%04X,Y @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2))
: sprintf(str,"%s $%04X,Y", chr,tmp);
break;

//Absolute,X
Expand All @@ -497,7 +505,9 @@ char *Disassemble(int addr, uint8 *opcode) {
_absolutex:
absolute(tmp);
tmp2=(tmp+RX);
sprintf(str,"%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2));
showTrace
? sprintf(str,"%s $%04X,X @ $%04X = #$%02X", chr,tmp,tmp2,GetMem(tmp2))
: sprintf(str,"%s $%04X,X", chr,tmp);
break;

//jumps
Expand All @@ -514,10 +524,10 @@ char *Disassemble(int addr, uint8 *opcode) {
case 0xB6: strcpy(chr,"LDX"); goto _zeropagey;
_zeropagey:
zpIndex(tmp,RY);
// ################################## Start of SP CODE ###########################
// Change width to %04X // don't!
sprintf(str,"%s $%02X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp));
// ################################## End of SP CODE ###########################
showTrace
? sprintf(str,"%s $%02X,Y @ $%04X = #$%02X", chr,opcode[1],tmp,GetMem(tmp))
: sprintf(str,"%s $%02X,Y", chr,opcode[1]);
break;

//UNDEFINED
Expand All @@ -527,3 +537,83 @@ char *Disassemble(int addr, uint8 *opcode) {

return str;
}

char *DisassembleLine(int addr, bool showTrace, bool showRomOffsets) {
uint8 instruction[] = {GetMem(addr), GetMem(addr + 1), GetMem(addr + 2)};
return DisassembleData(addr, instruction, showTrace, showRomOffsets);
}

int formatAddress(char *str, int addr, bool showRomOffsets) {
if (addr >= 0x8000)
{
if (showRomOffsets && GetNesFileAddress(addr) != -1)
{
return sprintf(str, " %06X: ", GetNesFileAddress(addr));
}
else
{
return sprintf(str, "%02X:%04X: ", getBank(addr), addr);
}
}
else
{
return sprintf(str, " :%04X: ", addr);
}
}

char *DisassembleData(int addr, uint8 *opcode, bool showTrace, bool showRomOffsets) {
static char str[64] = { 0 }, chr[25] = { 0 };
char *c;
int size, j;

formatAddress(str, addr, showRomOffsets);

size = opsize[opcode[0]];
if (size == 0)
{
sprintf(chr, "%02X UNDEFINED", opcode[0]);
strcat(str, chr);
}
else
{
if ((addr + size) > 0x10000)
{
sprintf(chr, "%02X OVERFLOW", opcode[0]);
strcat(str, chr);
}
else
{
for (j = 0; j < size; j++)
{
sprintf(chr, "%02X ", opcode[j]);
addr++;
strcat(str, chr);
}
while (size < 3)
{
strcat(str, " "); //pad output to align ASM
size++;
}
strcat(strcat(str, " "), Disassemble(addr, opcode, showTrace));
}
}
return str;
}

/// Disassembles a data block of the given length, regardless of any cdlogger info.
char *DisassembleDataBlock(int addr, int length, bool showTrace, bool showRomOffsets) {
static char str[64] = { 0 }, chr[25] = { 0 };
int size;

formatAddress(str, addr, showRomOffsets);

sprintf(chr, ".db $%02X", GetMem(addr));
strcat(str, chr);

for (int i = addr + 1; i < addr + length && i < 0x10000; i++) {
sprintf(chr, ", $%02X", GetMem(i));
strcat(str, chr);
}

return str;
}
7 changes: 6 additions & 1 deletion src/asm.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
#pragma once

int Assemble(unsigned char *output, int addr, char *str);
char *Disassemble(int addr, uint8 *opcode);
char *Disassemble(int addr, uint8 *opcode, bool showTrace = false);
char *DisassembleLine(int addr, bool showTrace = false, bool showRomOffsets = false);
char *DisassembleData(int addr, uint8 *opcode, bool showTrace = false, bool showRomOffsets = false);
char *DisassembleDataBlock(int addr, int length, bool showTrace = false, bool showRomOffsets = false);
159 changes: 159 additions & 0 deletions src/drivers/win/assembler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#include <Windows.h>

#include "types.h"
#include "gui.h"
#include "resource.h"
#include "debugger.h"
#include "../../debug.h"
#include "asm.h"
#include "../../x6502.h"
#include "../../fceu.h"
#include "../../debug.h"
#include "../../nsf.h"
#include "../../ppu.h"
#include "../../cart.h"
#include "../../ines.h"
#include "../../asm.h"

int AddAsmHistory(HWND hwndDlg, int id, char *str) {
int index;
index = SendDlgItemMessage(hwndDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)(LPSTR)str);
if (index == CB_ERR) {
SendDlgItemMessage(hwndDlg, id, CB_INSERTSTRING, -1, (LPARAM)(LPSTR)str);
return 0;
}
return 1;
}

INT_PTR CALLBACK AssemblerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
int romaddr, count, i, j;
char str[128], *dasm;
static int patchlen, applied, saved, lastundo;
static uint8 patchdata[64][3], undodata[64 * 3];
uint8 *ptr;

switch (uMsg) {
case WM_INITDIALOG:
CenterWindow(hwndDlg);

//set font
SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_DISASSEMBLY, WM_SETFONT, (WPARAM)debugSystem->hFixedFont, FALSE);
SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_PATCH_DISASM, WM_SETFONT, (WPARAM)debugSystem->hFixedFont, FALSE);

//set limits
SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_HISTORY, CB_LIMITTEXT, 20, 0);

SetDlgItemText(hwndDlg, IDC_ASSEMBLER_DISASSEMBLY, DisassembleLine(iaPC));
SetFocus(GetDlgItem(hwndDlg, IDC_ASSEMBLER_HISTORY));

patchlen = 0;
applied = 0;
saved = 0;
lastundo = 0;
break;
case WM_CLOSE:
case WM_QUIT:
EndDialog(hwndDlg, 0);
break;
case WM_COMMAND:
{
switch (HIWORD(wParam))
{
case BN_CLICKED:
{
switch (LOWORD(wParam))
{
case IDC_ASSEMBLER_APPLY:
if (patchlen) {
ptr = GetNesPRGPointer(GetNesFileAddress(iaPC) - 16);
count = 0;
for (i = 0; i < patchlen; i++) {
for (j = 0; j < opsize[patchdata[i][0]]; j++) {
if (count == lastundo) undodata[lastundo++] = ptr[count];
ptr[count++] = patchdata[i][j];
}
}
SetWindowText(hwndDlg, "Inline Assembler *Patches Applied*");
applied = 1;
}
break;
case IDC_ASSEMBLER_SAVE:
if (applied) {
count = romaddr = GetNesFileAddress(iaPC);
for (i = 0; i < patchlen; i++)
{
count += opsize[patchdata[i][0]];
}
if (patchlen) sprintf(str, "Write patch data to file at addresses 0x%06X - 0x%06X?", romaddr, count - 1);
else sprintf(str, "Undo all previously applied patches?");
if (MessageBox(hwndDlg, str, "Save changes to file?", MB_YESNO | MB_ICONINFORMATION) == IDYES) {
if (iNesSave()) {
saved = 1;
applied = 0;
}
else MessageBox(hwndDlg, "Unable to save changes to file", "Error saving to file", MB_OK | MB_ICONERROR);
}
}
break;
case IDC_ASSEMBLER_UNDO:
if ((count = SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_PATCH_DISASM, LB_GETCOUNT, 0, 0))) {
SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_PATCH_DISASM, LB_DELETESTRING, count - 1, 0);
patchlen--;
count = 0;
for (i = 0; i < patchlen; i++)
{
count += opsize[patchdata[i][0]];
}
if (count < lastundo) {
ptr = GetNesPRGPointer(GetNesFileAddress(iaPC) - 16);
j = opsize[patchdata[patchlen][0]];
for (i = count; i < (count + j); i++) {
ptr[i] = undodata[i];
}
lastundo -= j;
applied = 1;
}
SetDlgItemText(hwndDlg, IDC_ASSEMBLER_DISASSEMBLY, DisassembleLine(iaPC + count));
}
break;
case IDC_ASSEMBLER_DEFPUSHBUTTON:
count = 0;
for (i = 0; i < patchlen; i++)
{
count += opsize[patchdata[i][0]];
}
GetDlgItemText(hwndDlg, IDC_ASSEMBLER_HISTORY, str, 21);
if (!Assemble(patchdata[patchlen], (iaPC + count), str)) {
count = iaPC;
for (i = 0; i <= patchlen; i++)
{
count += opsize[patchdata[i][0]];
}
if (count > 0x10000) { //note: don't use 0xFFFF!
MessageBox(hwndDlg, "Patch data cannot exceed address 0xFFFF", "Address error", MB_OK | MB_ICONERROR);
break;
}
SetDlgItemText(hwndDlg, IDC_ASSEMBLER_HISTORY, "");
if (count < 0x10000) SetDlgItemText(hwndDlg, IDC_ASSEMBLER_DISASSEMBLY, DisassembleLine(count));
else SetDlgItemText(hwndDlg, IDC_ASSEMBLER_DISASSEMBLY, "OVERFLOW");
dasm = DisassembleData((count - opsize[patchdata[patchlen][0]]), patchdata[patchlen]);
SendDlgItemMessage(hwndDlg, IDC_ASSEMBLER_PATCH_DISASM, LB_INSERTSTRING, -1, (LPARAM)(LPSTR)dasm);
AddAsmHistory(hwndDlg, IDC_ASSEMBLER_HISTORY, dasm + 16);
SetWindowText(hwndDlg, "Inline Assembler");
patchlen++;
}
else { //ERROR!
SetWindowText(hwndDlg, "Inline Assembler *Syntax Error*");
MessageBeep(MB_ICONEXCLAMATION);
}
break;
}
SetFocus(GetDlgItem(hwndDlg, IDC_ASSEMBLER_HISTORY)); //set focus to combo box after anything is pressed!
break;
}
}
break;
}
}
return FALSE;
}
5 changes: 5 additions & 0 deletions src/drivers/win/assembler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include <Windows.h>

INT_PTR CALLBACK AssemblerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
Loading