diff --git a/src/debug.cpp b/src/debug.cpp index 04674cd7..b02a1513 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -22,7 +22,7 @@ int offsetStringToInt(unsigned int type, const char* offsetBuffer) { int offset = -1; - if (sscanf(offsetBuffer,"%4X",(unsigned int *)&offset) == EOF) + if (sscanf(offsetBuffer,"%7X",(unsigned int *)&offset) == EOF) { return -1; } @@ -35,6 +35,10 @@ int offsetStringToInt(unsigned int type, const char* offsetBuffer) { return offset & 0x00FF; } + else if (type & BT_R) + { + return offset; + } else // BT_C { int type = GIT_CART; @@ -62,7 +66,7 @@ int offsetStringToInt(unsigned int type, const char* offsetBuffer) } } - return offset; + return offset & 0xFFFF; } // Returns the value of a given type or register @@ -200,6 +204,9 @@ unsigned int NewBreak(const char* name, int start, int end, unsigned int type, c watchpoint[num].flags|=BT_S; watchpoint[num].flags&=~WP_X; //disable execute flag! } + if (type & BT_R) { + watchpoint[num].flags|=BT_R; + } if (watchpoint[num].desc) free(watchpoint[num].desc); @@ -635,7 +642,7 @@ uint16 StackNextIgnorePC = 0xFFFF; ///fires a breakpoint static void breakpoint(uint8 *opcode, uint16 A, int size) { - int i, j; + int i, j, romAddrPC; uint8 brk_type; uint8 stackop=0; uint8 stackopstartaddr=0,stackopendaddr=0; @@ -700,6 +707,8 @@ static void breakpoint(uint8 *opcode, uint16 A, int size) { return; } + romAddrPC = GetNesFileAddress(_PC); + brk_type = opbrktype[opcode[0]] | WP_X; switch (opcode[0]) { @@ -769,11 +778,31 @@ static void breakpoint(uint8 *opcode, uint16 A, int size) { if (((watchpoint[i].flags & (WP_R | WP_W)) && (watchpoint[i].address <= A) && (watchpoint[i].endaddress >= A)) || ((watchpoint[i].flags & WP_X) && (watchpoint[i].address <= _PC) && (watchpoint[i].endaddress >= _PC))) BREAKHIT(i); - } else + } + else { - if (((watchpoint[i].flags & (WP_R | WP_W)) && (watchpoint[i].address == A)) || - ((watchpoint[i].flags & WP_X) && (watchpoint[i].address == _PC))) - BREAKHIT(i); + if (watchpoint[i].flags & BT_R) + { + if ( (watchpoint[i].flags & WP_X) && (watchpoint[i].address == romAddrPC) ) + { + BREAKHIT(i); + } + //else if ( (watchpoint[i].flags & WP_R) && (watchpoint[i].address == A) ) + //{ + // BREAKHIT(i); + //} + } + else + { + if ( (watchpoint[i].flags & (WP_R | WP_W)) && (watchpoint[i].address == A)) + { + BREAKHIT(i); + } + else if ( (watchpoint[i].flags & WP_X) && (watchpoint[i].address == _PC) ) + { + BREAKHIT(i); + } + } } } else { diff --git a/src/debug.h b/src/debug.h index e96ce016..e1d8b573 100644 --- a/src/debug.h +++ b/src/debug.h @@ -15,6 +15,7 @@ #define BT_C 0x00 //break type, cpu mem #define BT_P 0x20 //break type, ppu mem #define BT_S 0x40 //break type, sprite mem +#define BT_R 0x80 //break type, rom mem #define BREAK_TYPE_STEP -1 #define BREAK_TYPE_BADOP -2 @@ -48,9 +49,9 @@ static const uint8 opbrktype[256] = { typedef struct { - uint16 address; - uint16 endaddress; - uint8 flags; + uint32 address; + uint32 endaddress; + uint16 flags; Condition* cond; char* condText; diff --git a/src/drivers/Qt/ConsoleDebugger.cpp b/src/drivers/Qt/ConsoleDebugger.cpp index 33955ab8..6e27220e 100644 --- a/src/drivers/Qt/ConsoleDebugger.cpp +++ b/src/drivers/Qt/ConsoleDebugger.cpp @@ -1542,7 +1542,7 @@ void ConsoleDebugger::openBpEditWindow( int editIdx, watchpointinfo *wp, bool fo QFrame *frame; QGroupBox *gbox; QPushButton *okButton, *cancelButton; - QRadioButton *cpu_radio, *ppu_radio, *sprite_radio; + QRadioButton *cpu_radio, *ppu_radio, *oam_radio, *rom_radio; if ( editIdx >= 0 ) { @@ -1595,15 +1595,17 @@ void ConsoleDebugger::openBpEditWindow( int editIdx, watchpointinfo *wp, bool fo hbox->addWidget( ebp ); hbox = new QHBoxLayout(); - cpu_radio = new QRadioButton( tr("CPU Mem") ); - ppu_radio = new QRadioButton( tr("PPU Mem") ); - sprite_radio = new QRadioButton( tr("Sprite Mem") ); + cpu_radio = new QRadioButton( tr("CPU") ); + ppu_radio = new QRadioButton( tr("PPU") ); + oam_radio = new QRadioButton( tr("OAM") ); + rom_radio = new QRadioButton( tr("ROM") ); cpu_radio->setChecked(true); gbox->setLayout( hbox ); hbox->addWidget( cpu_radio ); hbox->addWidget( ppu_radio ); - hbox->addWidget( sprite_radio ); + hbox->addWidget( oam_radio ); + hbox->addWidget( rom_radio ); grid = new QGridLayout(); @@ -1643,7 +1645,11 @@ void ConsoleDebugger::openBpEditWindow( int editIdx, watchpointinfo *wp, bool fo } else if ( wp->flags & BT_S ) { - sprite_radio->setChecked(true); + oam_radio->setChecked(true); + } + else if ( wp->flags & BT_R ) + { + rom_radio->setChecked(true); } sprintf( stmp, "%04X", wp->address ); @@ -1689,9 +1695,21 @@ void ConsoleDebugger::openBpEditWindow( int editIdx, watchpointinfo *wp, bool fo // If new breakpoint, suggest condition if in ROM Mapping area of memory. if ( wp->address >= 0x8000 ) { - char str[64]; - sprintf(str, "K==#%02X", getBank(wp->address)); - cond->setText( tr(str) ); + int romAddr = GetNesFileAddress(wp->address); + + if ( romAddr >= 0 ) + { + wp->address = romAddr; + sprintf( stmp, "%X", wp->address ); + addr1->setText( tr(stmp) ); + rom_radio->setChecked(true); + } + else + { + char str[64]; + sprintf(str, "K==#%02X", getBank(wp->address)); + cond->setText( tr(str) ); + } } } } @@ -1728,10 +1746,14 @@ void ConsoleDebugger::openBpEditWindow( int editIdx, watchpointinfo *wp, bool fo { type |= BT_P; } - else if ( sprite_radio->isChecked() ) + else if ( oam_radio->isChecked() ) { type |= BT_S; } + else if ( rom_radio->isChecked() ) + { + type |= BT_R; + } s = addr1->text().toStdString(); @@ -1875,6 +1897,10 @@ void ConsoleDebugger::bpListUpdate( bool reset ) { flags[1] = 'S'; } + else if ( watchpoint[i].flags & BT_R ) + { + flags[1] = 'R'; + } else { flags[1] = 'C'; @@ -3999,6 +4025,10 @@ void saveGameDebugBreakpoints( bool force ) { flags[1] = 'S'; } + else if ( watchpoint[i].flags & BT_R ) + { + flags[1] = 'R'; + } else { flags[1] = 'C'; @@ -4010,7 +4040,7 @@ void saveGameDebugBreakpoints( bool force ) flags[5] = (watchpoint[i].flags & WP_F) ? 'F' : '-'; flags[6] = 0; - fprintf( fp, "BreakPoint: startAddr=%04X endAddr=%04X flags=%s condition=\"%s\" desc=\"%s\" \n", + fprintf( fp, "BreakPoint: startAddr=%08X endAddr=%08X flags=%s condition=\"%s\" desc=\"%s\" \n", watchpoint[i].address, watchpoint[i].endaddress, flags, (watchpoint[i].condText != NULL) ? watchpoint[i].condText : "", (watchpoint[i].desc != NULL) ? watchpoint[i].desc : ""); @@ -4183,6 +4213,10 @@ void loadGameDebugBreakpoints(void) { type |= BT_S; } + else if ( data[1] == 'R' ) + { + type |= BT_R; + } else { type |= BT_C;