trace/logger fine tuning

This commit is contained in:
CaH4e3 2012-09-30 16:36:45 +00:00
parent f346020de2
commit 32774646fd
9 changed files with 170 additions and 299 deletions

View File

@ -224,13 +224,11 @@ int getBank(int offs)
//NSF data is easy to overflow the return on.
//Anything over FFFFF will kill it.
//GetNesFileAddress doesn't work well with Unif files
int addr = GetNesFileAddress(offs)-16;
if (GameInfo && GameInfo->type==GIT_NSF) {
return addr != -1 ? addr / 0x1000 : -1;
}
if (GameInfo && GameInfo->type==GIT_NSF)
return addr != -1 ? addr / 0x1000 : -1;
return addr != -1 ? addr / 0x4000 : -1;
}
@ -377,9 +375,7 @@ int debug_loggingCD;
void LogCDVectors(int which){
int j;
j = GetPRGAddress(which);
if(j == -1){
return;
}
if(j == -1) return;
if(!(cdloggerdata[j] & 2)){
cdloggerdata[j] |= 0x0E; // we're in the last bank and recording it as data so 0x1110 or 0xE should be what we need
@ -395,24 +391,12 @@ void LogCDVectors(int which){
}
}
void LogCDData(){
void LogCDData(uint8 *opcode, uint16 A, int size) {
int i, j;
uint16 A = 0;
uint8 opcode[3] = {0}, memop = 0;
uint8 memop = 0;
opcode[0] = GetMem(_PC);
switch (opsize[opcode[0]]) {
case 2:
opcode[1] = GetMem(_PC + 1);
break;
case 3:
opcode[1] = GetMem(_PC + 1);
opcode[2] = GetMem(_PC + 2);
break;
}
if((j = GetPRGAddress(_PC)) != -1)
for (i = 0; i < opsize[opcode[0]]; i++) {
for (i = 0; i < size; i++) {
if(cdloggerdata[j+i] & 1)continue; //this has been logged so skip
cdloggerdata[j+i] |= 1;
cdloggerdata[j+i] |=((_PC+i)>>11)&0x0c;
@ -422,25 +406,14 @@ void LogCDData(){
}
//log instruction jumped to in an indirect jump
if(opcode[0] == 0x6c) indirectnext = 1; else indirectnext = 0;
if(opcode[0] == 0x6c)
indirectnext = 1;
else
indirectnext = 0;
switch (optype[opcode[0]]) {
case 0: break;
case 1:
A = (opcode[1]+_X) & 0xFF;
A = GetMem(A) | (GetMem(A+1)<<8);
memop = 0x20;
break;
case 2: A = opcode[1]; break;
case 3: A = opcode[1] | opcode[2]<<8; break;
case 4:
A = (GetMem(opcode[1]) | (GetMem(opcode[1]+1)<<8))+_Y;
memop = 0x20;
break;
case 5: A = opcode[1]+_X; break;
case 6: A = (opcode[1] | (opcode[2]<<8))+_Y; break;
case 7: A = (opcode[1] | (opcode[2]<<8))+_X; break;
case 8: A = opcode[1]+_Y; break;
case 4: memop = 0x20; break;
}
if((j = GetPRGAddress(A)) != -1) {
@ -518,8 +491,6 @@ void BreakHit(int bp_num, bool force = false)
FCEUI_SetEmulationPaused(1); //mbg merge 7/19/06 changed to use EmulationPaused()
//MBG TODO - was this commented out before the gnu refactoring?
//if((!logtofile) && (logging))PauseLoggingSequence();
#ifdef WIN32
FCEUD_DebugBreakpoint(bp_num);
#endif
@ -529,11 +500,9 @@ uint8 StackAddrBackup = X.S;
uint16 StackNextIgnorePC = 0xFFFF;
///fires a breakpoint
void breakpoint()
{
int i,j;
uint16 A=0;
uint8 brk_type,opcode[3] = {0};
static void breakpoint(uint8 *opcode, uint16 A, int size) {
int i, j;
uint8 brk_type;
uint8 stackop=0;
uint8 stackopstartaddr,stackopendaddr;
@ -542,18 +511,16 @@ void breakpoint()
if (break_on_instructions && (total_instructions > break_instructions_limit))
BreakHit(BREAK_TYPE_INSTRUCTIONS_EXCEED, true);
//inspect the current opcode
opcode[0] = GetMem(_PC);
//if the current instruction is bad, and we are breaking on bad opcodes, then hit the breakpoint
if(dbgstate.badopbreak && (opsize[opcode[0]] == 0))
if(dbgstate.badopbreak && (size == 0))
BreakHit(BREAK_TYPE_BADOP, true);
//if we're stepping out, track the nest level
if (dbgstate.stepout) {
if (opcode[0] == 0x20) dbgstate.jsrcount++;
else if (opcode[0] == 0x60) {
if (dbgstate.jsrcount) dbgstate.jsrcount--;
if (dbgstate.jsrcount)
dbgstate.jsrcount--;
else {
dbgstate.stepout = false;
dbgstate.step = true;
@ -568,8 +535,8 @@ void breakpoint()
BreakHit(BREAK_TYPE_STEP, true);
return;
}
//if we're running for a scanline, we want to check if we've hit the cycle limit
if (dbgstate.runline) {
uint64 ts = timestampbase;
ts+=timestamp;
@ -581,6 +548,7 @@ void breakpoint()
return;
}
}
//check the step over address and break if we've hit it
if ((watchpoint[64].address == _PC) && (watchpoint[64].flags)) {
watchpoint[64].address = 0;
@ -589,22 +557,7 @@ void breakpoint()
return;
}
for (i = 1; i < opsize[opcode[0]]; i++) opcode[i] = GetMem(_PC+i);
brk_type = opbrktype[opcode[0]] | WP_X;
switch (optype[opcode[0]]) {
case 0: /*A = _PC;*/ break;
case 1:
A = (opcode[1]+_X) & 0xFF;
A = GetMem(A) | (GetMem(A+1))<<8;
break;
case 2: A = opcode[1]; break;
case 3: A = opcode[1] | opcode[2]<<8; break;
case 4: A = (GetMem(opcode[1]) | (GetMem(opcode[1]+1))<<8)+_Y; break;
case 5: A = opcode[1]+_X; break;
case 6: A = (opcode[1] | opcode[2]<<8)+_Y; break;
case 7: A = (opcode[1] | opcode[2]<<8)+_X; break;
case 8: A = opcode[1]+_Y; break;
}
switch (opcode[0]) {
//Push Ops
@ -763,6 +716,9 @@ int debug_tracing;
void DebugCycle()
{
uint8 opcode[3] = {0};
uint16 A = 0;
int size;
#ifdef WIN32
// since this function is called once for every instruction, we can use it for keeping statistics
@ -784,19 +740,45 @@ void DebugCycle()
if ((_PC >= 0x3801) && (_PC <= 0x3824)) return;
}
if (numWPs || dbgstate.step || dbgstate.runline || dbgstate.stepout || watchpoint[64].flags || dbgstate.badopbreak || break_on_cycles || break_on_instructions)
breakpoint();
opcode[0] = GetMem(_PC);
size = opsize[opcode[0]];
switch (size)
{
case 2:
opcode[1] = GetMem(_PC + 1);
break;
case 3:
opcode[1] = GetMem(_PC + 1);
opcode[2] = GetMem(_PC + 2);
break;
}
if(debug_loggingCD) LogCDData();
switch (optype[opcode[0]])
{
case 0: break;
case 1:
A = (opcode[1] + _X) & 0xFF;
A = GetMem(A) | (GetMem(A + 1) << 8);
break;
case 2: A = opcode[1]; break;
case 3: A = opcode[1] | (opcode[2] << 8); break;
case 4: A = (GetMem(opcode[1]) | (GetMem(opcode[1]+1) << 8)) + _Y; break;
case 5: A = opcode[1] + _X; break;
case 6: A = (opcode[1] | (opcode[2] << 8)) + _Y; break;
case 7: A = (opcode[1] | (opcode[2] << 8)) + _X; break;
case 8: A = opcode[1] + _Y; break;
}
if (numWPs || dbgstate.step || dbgstate.runline || dbgstate.stepout || watchpoint[64].flags || dbgstate.badopbreak || break_on_cycles || break_on_instructions)
breakpoint(opcode, A, size);
if(debug_loggingCD)
LogCDData(opcode, A, size);
//mbg 6/30/06 - this was commented out when i got here. i dont understand it anyway
//if(logging || (hMemView && (EditingMode == 2))) LogInstruction();
//This needs to be windows only or else the linux build system will fail since logging is declared in a
//windows source file
#ifdef WIN32
extern volatile int logging; //UGETAB: This is required to be an extern, because the info isn't set here
if(logging) FCEUD_TraceInstruction();
//This needs to be windows only or else the linux build system will fail since logging is declared in a
//windows source file
FCEUD_TraceInstruction(opcode, size);
#endif
}

View File

@ -73,7 +73,7 @@ uint8 GetPPUMem(uint8 A);
//---------CDLogger
void LogCDVectors(int which);
void LogCDData();
void LogCDData(uint8 *opcode, uint16 A, int size);
extern volatile int codecount, datacount, undefinedcount;
extern unsigned char *cdloggerdata;

View File

@ -315,7 +315,7 @@ void FCEUD_CmdOpen(void);
void FCEUD_DebugBreakpoint(int bp_num);
///the driver should log the current instruction, if it wants (we should move the code in the win driver that does this to the shared area)
void FCEUD_TraceInstruction();
void FCEUD_TraceInstruction(uint8 *opcode, int size);
///the driver might should update its NTView (only used if debugging support is compiled in)
void FCEUD_UpdateNTView(int scanline, bool drawall);

View File

@ -69,10 +69,9 @@ BOOL CALLBACK CDLoggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
UINT len;
char *ftmp;
len=DragQueryFile((HDROP)wParam,0,0,0)+1;
if((ftmp=(char*)malloc(len)))
{
DragQueryFile((HDROP)wParam,0,ftmp,len);
len=DragQueryFile((HDROP)wParam,0,0,0)+1;
if((ftmp=(char*)malloc(len))) {
DragQueryFile((HDROP)wParam,0,ftmp,len);
string fileDropped = ftmp;
//adelikat: Drag and Drop only checks file extension, the internal functions are responsible for file error checking
//-------------------------------------------------------
@ -87,7 +86,7 @@ BOOL CALLBACK CDLoggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
std::string str = "Could not open " + fileDropped;
MessageBox(hwndDlg, str.c_str(), "File error", 0);
}
}
}
}
break;
@ -126,8 +125,7 @@ BOOL CALLBACK CDLoggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
if((logging) && (logging_options & LOG_NEW_INSTRUCTIONS)){
MessageBox(hCDLogger,
"The Trace logger is currently using this for some of its features.\
Please turn the trace logger off and try again.","Unable to Pause Code/Data Logger",
MB_OK);
Please turn the trace logger off and try again.","Unable to Pause Code/Data Logger", MB_OK);
break;
}
FCEUI_SetLoggingCD(0);
@ -161,8 +159,7 @@ MB_OK);
if((logging) && (logging_options & LOG_NEW_INSTRUCTIONS)){
MessageBox(hCDLogger,
"The Trace logger is currently using this for some of its features.\
Please turn the trace logger off and try again.","Unable to Pause Code/Data Logger",
MB_OK);
Please turn the trace logger off and try again.","Unable to Pause Code/Data Logger", MB_OK);
break;
}
FCEUI_SetLoggingCD(0);
@ -267,7 +264,7 @@ void LoadCDLogFile(){
void SaveCDLogFileAs()
{
const char filter[]="Code Data Log File (*.CDL)\0*.cdl\0All Files (*.*)\0*.*\0\0";
char nameo[2048];
char nameo[2048];
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize=sizeof(ofn);
@ -280,25 +277,24 @@ void SaveCDLogFileAs()
ofn.nMaxFile=256;
ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
ofn.hwndOwner = hCDLogger;
if(!GetSaveFileName(&ofn))return;
if(!GetSaveFileName(&ofn))
return;
strcpy(loadedcdfile,nameo);
SaveCDLogFile();
return;
}
void SaveCDLogFile(){ //todo make this button work before you've saved as
FILE *FP;
FP = fopen(loadedcdfile,"wb");
if(FP == NULL)
if(FP == NULL) // removed deadly recurrence
{
SaveCDLogFileAs();
FCEUD_PrintError("Error Saving File");
return;
}
fwrite(cdloggerdata,PRGsize[0],1,FP);
if(VROM_size)
fwrite(cdloggervdata,CHRsize[0],1,FP);
fclose(FP);
return;
}
void DoCDLogger()
@ -320,7 +316,7 @@ void DoCDLogger()
void UpdateCDLogger(){
if(!hCDLogger)return;
char str[50];
float fcodecount = codecount;
float fdatacount = datacount;
@ -330,7 +326,7 @@ void UpdateCDLogger(){
float fundefinedvromcount = undefinedvromcount;
float fromsize = PRGsize[0];
float fvromsize = VROM_size ? CHRsize[0] : 1;
sprintf(str,"0x%06x %.2f%%",codecount,fcodecount/fromsize*100);
SetDlgItemText(hCDLogger,LBL_CDLOGGER_CODECOUNT,str);
sprintf(str,"0x%06x %.2f%%",datacount,fdatacount/fromsize*100);
@ -392,7 +388,7 @@ void SaveStrippedRom(int invert){ //this is based off of iNesSave()
//static uint16 LoadAddr;
//LoadAddr=NSFHeader.LoadAddressLow;
//LoadAddr|=(NSFHeader.LoadAddressHigh&0x7F)<<8;
//Simple store/restore for writing a working NSF header
NSFLoadLow = NSFHeader.LoadAddressLow;
NSFLoadHigh = NSFHeader.LoadAddressHigh;
@ -401,7 +397,7 @@ void SaveStrippedRom(int invert){ //this is based off of iNesSave()
fwrite(&NSFHeader,1,0x8,fp);
NSFHeader.LoadAddressLow = NSFLoadLow;
NSFHeader.LoadAddressHigh = NSFLoadHigh;
fseek(fp,0x8,SEEK_SET);
for(i = 0;i < ((NSFMaxBank+1)*4096);i++){
unsigned char pchar;
@ -437,21 +433,14 @@ void SaveStrippedRom(int invert){ //this is based off of iNesSave()
if(VROM_size)
{
if(!newppu)
{
for(i = 0; i < (int)CHRsize[0]; i++)
{
unsigned char vchar;
if(cdloggervdata[i] & 1)
vchar = invert?0:VROM[i];
else
vchar = invert?VROM[i]:0;
fputc(vchar, fp);
}
} else
{
// since old ppu doesn't log VROM access, just dump it to the file
fwrite(VROM,CHRsize[0],1,fp);
// since an old ppu at least log the 2007 ppu read accesses, so need to save anyway...
for(i = 0; i < (int)CHRsize[0]; i++) {
unsigned char vchar;
if(cdloggervdata[i] & 3)
vchar = invert?0:VROM[i];
else
vchar = invert?VROM[i]:0;
fputc(vchar, fp);
}
}
}

View File

@ -220,7 +220,8 @@ BOOL CALLBACK AddbpCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
char str[8] = {0};
int tmp;
switch(uMsg) {
switch(uMsg)
{
case WM_INITDIALOG:
CenterWindow(hwndDlg);
SendDlgItemMessage(hwndDlg,IDC_ADDBP_ADDR_START,EM_SETLIMITTEXT,4,0);
@ -601,16 +602,6 @@ int *GetEditHexData(HWND hwndDlg, int id){
return data;
}
/*
int GetEditStack(HWND hwndDlg) {
char str[85];
int tmp;
GetDlgItemText(hwndDlg,IDC_DEBUGGER_STACK_CONTENTS,str,85);
sscanf(str,"%2x,%2x,%2x,%2x,\r\n",&tmp);
return tmp;
}
*/
void UpdateRegs(HWND hwndDlg) {
if (DebuggerWasUpdated) {
X.A = GetEditHex(hwndDlg,IDC_DEBUGGER_VAL_A);
@ -1123,9 +1114,10 @@ BOOL CALLBACK PatcherCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam
case BN_CLICKED:
switch(LOWORD(wParam)) {
case IDC_ROMPATCHER_BTN_EDIT: //todo: maybe get rid of this button and cause iapoffset to update every time you change the text
if(IsDlgButtonChecked(hwndDlg,IDC_ROMPATCHER_DOTNES_OFFSET) == BST_CHECKED){
if(IsDlgButtonChecked(hwndDlg,IDC_ROMPATCHER_DOTNES_OFFSET) == BST_CHECKED)
iapoffset = GetEditHex(hwndDlg,IDC_ROMPATCHER_OFFSET);
} else iapoffset = GetNesFileAddress(GetEditHex(hwndDlg,IDC_ROMPATCHER_OFFSET));
else
iapoffset = GetNesFileAddress(GetEditHex(hwndDlg,IDC_ROMPATCHER_OFFSET));
if((iapoffset < 16) && (iapoffset != -1)){
MessageBox(hDebug, "Sorry, iNes Header editing isn't supported", "Error", MB_OK);
iapoffset = -1;
@ -1477,13 +1469,13 @@ BOOL CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
break;
case WM_MOVE:
if (!IsIconic(hwndDlg)) {
GetWindowRect(hwndDlg,&wrect);
DbgPosX = wrect.left;
DbgPosY = wrect.top;
GetWindowRect(hwndDlg,&wrect);
DbgPosX = wrect.left;
DbgPosY = wrect.top;
#ifdef WIN32
WindowBoundsCheckResize(DbgPosX,DbgPosY,DbgSizeX,wrect.right);
#endif
#ifdef WIN32
WindowBoundsCheckResize(DbgPosX,DbgPosY,DbgSizeX,wrect.right);
#endif
}
break;
@ -1607,11 +1599,6 @@ BOOL CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
case WM_KEYDOWN:
MessageBox(hwndDlg,"Die!","I'm dead!",MB_YESNO|MB_ICONINFORMATION);
//i=0;
//if(uMsg == WM_KEYDOWN){
// if(wParam == VK_PRIOR) i = -1;
// if(wParam == VK_NEXT) i = 1;
//}
break;
case WM_MOUSEMOVE:
@ -1739,18 +1726,16 @@ BOOL CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
}
break;
case IDC_DEBUGGER_STEP_IN:
if (FCEUI_EmulationPaused()) {
if (FCEUI_EmulationPaused())
UpdateRegs(hwndDlg);
}
FCEUI_Debugger().step = true;
FCEUI_SetEmulationPaused(0);
UpdateOtherDebuggingDialogs();
break;
case IDC_DEBUGGER_RUN_LINE:
if (FCEUI_EmulationPaused()) {
if (FCEUI_EmulationPaused())
UpdateRegs(hwndDlg);
}
FCEUI_Debugger().runline = true;
{
uint64 ts=timestampbase;
@ -1764,9 +1749,8 @@ BOOL CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
UpdateOtherDebuggingDialogs();
break;
case IDC_DEBUGGER_RUN_FRAME2:
if (FCEUI_EmulationPaused()) {
if (FCEUI_EmulationPaused())
UpdateRegs(hwndDlg);
}
FCEUI_Debugger().runline = true;
{
uint64 ts=timestampbase;

View File

@ -710,7 +710,7 @@ void AddDebuggerBookmark(HWND hwnd)
void DeleteDebuggerBookmark(HWND hwnd)
{
// Get the selected bookmark
int selectedItem = SendDlgItemMessage(hwnd, LIST_DEBUGGER_BOOKMARKS, LB_GETCURSEL, 0, 0);
unsigned int selectedItem = SendDlgItemMessage(hwnd, LIST_DEBUGGER_BOOKMARKS, LB_GETCURSEL, 0, 0);
if (selectedItem == LB_ERR)
{

View File

@ -12,7 +12,7 @@
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Íåéòðàëüíûé resources
// Neutral resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
@ -1586,8 +1586,8 @@ BEGIN
LTEXT "Itsa me the Code/Data Logger! Press Start to play!",65530,69,80,172,12
PUSHBUTTON "Reset Log",BTN_CDLOGGER_RESET,7,90,50,14
PUSHBUTTON "Save as...",BTN_CDLOGGER_SAVE_AS,257,90,50,14
PUSHBUTTON "Save Stripped iNes Rom...",BTN_CDLOGGER_SAVE_STRIPPED,208,126,99,14
PUSHBUTTON "Save Unused Data...",BTN_CDLOGGER_SAVE_UNUSED,208,141,99,14
PUSHBUTTON "Save Stripped iNes Rom...",BTN_CDLOGGER_SAVE_STRIPPED,208,125,99,14
PUSHBUTTON "Save Unused Data...",BTN_CDLOGGER_SAVE_UNUSED,208,140,99,14
LTEXT "4067 - 29.5%",LBL_CDLOGGER_RENDERCOUNT,40,60,68,11
GROUPBOX "CHR Rendered",-1,29,50,84,27
GROUPBOX "CHR Logged as Data",-1,117,50,84,27
@ -2124,12 +2124,12 @@ BEGIN
END
#endif // APSTUDIO_INVOKED
#endif // Íåéòðàëüíûé resources
#endif // Neutral resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// Àíãëèéñêèé (ÑØÀ) resources
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
@ -2363,7 +2363,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 // Àíãëèéñêèé (ÑØÀ) resources
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////

View File

@ -88,9 +88,7 @@ int Tracer_wndx=0, Tracer_wndy=0;
void ShowLogDirDialog(void);
void BeginLoggingSequence(void);
void LogInstruction(void);
void EndLoggingSequence(void);
//void PauseLoggingSequence(void);
void UpdateLogWindow(void);
void UpdateLogText(void);
void EnableTracerMenuItems(void);
@ -240,7 +238,6 @@ BOOL CALLBACK TracerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
string pauseMessage = m1 + m2 + m3;
SetDlgItemText(hTracer, IDC_TRACER_LOG, pauseMessage.c_str());
}
//PauseLoggingSequence();
break;
}
case IDC_BTN_LOG_BROWSE:
@ -255,39 +252,35 @@ BOOL CALLBACK TracerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
//if (logging && !logtofile) {
switch(uMsg) {
case WM_VSCROLL:
if (lParam) {
//if ((!logging) || (logging && logtofile))break;
//if(!(logging && !logtofile))break;
if ((!logging) || logtofile) break;
switch(uMsg) {
case WM_VSCROLL:
if (lParam) {
if ((!logging) || logtofile) break;
if(!FCEUI_EmulationPaused() && !log_update_window) break; //mbg merge 7/19/06 changd to use EmulationPaused()
if(!FCEUI_EmulationPaused() && !log_update_window) break; //mbg merge 7/19/06 changd to use EmulationPaused()
GetScrollInfo((HWND)lParam,SB_CTL,&tracesi);
switch(LOWORD(wParam))
{
case SB_ENDSCROLL:
case SB_TOP:
case SB_BOTTOM: break;
case SB_LINEUP: tracesi.nPos--; break;
case SB_LINEDOWN:tracesi.nPos++; break;
case SB_PAGEUP: tracesi.nPos -= tracesi.nPage; break;
case SB_PAGEDOWN: tracesi.nPos += tracesi.nPage; break;
case SB_THUMBPOSITION: //break;
case SB_THUMBTRACK: tracesi.nPos = tracesi.nTrackPos; break;
}
if ((tracesi.nPos + (int)tracesi.nPage) > tracesi.nMax)
tracesi.nPos = tracesi.nMax - (int)tracesi.nPage;
if (tracesi.nPos < tracesi.nMin)
tracesi.nPos = tracesi.nMin;
SetScrollInfo((HWND)lParam,SB_CTL,&tracesi,TRUE);
UpdateLogText();
GetScrollInfo((HWND)lParam,SB_CTL,&tracesi);
switch(LOWORD(wParam))
{
case SB_ENDSCROLL:
case SB_TOP:
case SB_BOTTOM: break;
case SB_LINEUP: tracesi.nPos--; break;
case SB_LINEDOWN:tracesi.nPos++; break;
case SB_PAGEUP: tracesi.nPos -= tracesi.nPage; break;
case SB_PAGEDOWN: tracesi.nPos += tracesi.nPage; break;
case SB_THUMBPOSITION: //break;
case SB_THUMBTRACK: tracesi.nPos = tracesi.nTrackPos; break;
}
break;
}
//}
if ((tracesi.nPos + (int)tracesi.nPage) > tracesi.nMax)
tracesi.nPos = tracesi.nMax - (int)tracesi.nPage;
if (tracesi.nPos < tracesi.nMin)
tracesi.nPos = tracesi.nMin;
SetScrollInfo((HWND)lParam,SB_CTL,&tracesi,TRUE);
UpdateLogText();
}
break;
}
return FALSE;
}
@ -342,50 +335,15 @@ void BeginLoggingSequence(void)
SetDlgItemText(hTracer, IDC_BTN_START_STOP_LOGGING,"Stop Logging");
return;
}
/*
void LogInstructionOld(){
char str[96], chr[32];
int addr=X.PC;
int size, j;
uint8 opcode[3];
sprintf(str, "$%04X:", addr);
if ((size = opsize[GetMem(addr)]) == 0) {
sprintf(chr, "%02X UNDEFINED", GetMem(addr)); addr++;
strcat(str,chr);
}
else {
if ((addr+size) > 0xFFFF) {
sprintf(chr, "%02X OVERFLOW", GetMem(addr));
strcat(str,chr);
goto done;
}
for (j = 0; j < size; j++) {
sprintf(chr, "%02X ", opcode[j] = GetMem(addr)); addr++;
strcat(str,chr);
}
while (size < 3) {
strcat(str," "); //pad output to align ASM
size++;
}
strcat(strcat(str," "),BinToASM(addr,opcode));
}
done:
strcat(str,"\n");
if(logtofile){
fprintf(LOG_FP,str);
}
}*/
//todo: really speed this up
void FCEUD_TraceInstruction()
void FCEUD_TraceInstruction(uint8 *opcode, int size)
{
if (!logging)
return;
unsigned int addr = X.PC;
int size, j;
uint8 opcode[3], tmp;
uint8 tmp;
static int unloggedlines;
if(((logging_options & LOG_NEW_INSTRUCTIONS) && (oldcodecount != codecount)) ||
@ -411,10 +369,9 @@ void FCEUD_TraceInstruction()
}
}
size = opsize[GetMem(addr)];
if ((addr+size) > 0xFFFF)
if ((addr + size) > 0xFFFF)
{
sprintf(str_data, "%02X ", GetMem(addr&0xFFFF));
sprintf(str_data, "%02X ", opcode[0]);
sprintf(str_disassembly, "OVERFLOW");
} else
{
@ -422,12 +379,11 @@ void FCEUD_TraceInstruction()
switch (size)
{
case 0:
sprintf(str_data, "%02X ", GetMem(addr));
sprintf(str_data, "%02X ", opcode[0]);
sprintf(str_disassembly,"UNDEFINED");
break;
case 1:
{
opcode[0]=GetMem(addr++);
sprintf(str_data, "%02X ", opcode[0]);
a = Disassemble(addr, opcode);
// special case: an RTS opcode
@ -442,15 +398,10 @@ void FCEUD_TraceInstruction()
break;
}
case 2:
opcode[0]=GetMem(addr++);
opcode[1]=GetMem(addr++);
sprintf(str_data, "%02X %02X ", opcode[0],opcode[1]);
a = Disassemble(addr, opcode);
break;
case 3:
opcode[0]=GetMem(addr++);
opcode[1]=GetMem(addr++);
opcode[2]=GetMem(addr++);
sprintf(str_data, "%02X %02X %02X ", opcode[0],opcode[1],opcode[2]);
a = Disassemble(addr, opcode);
break;
@ -462,7 +413,7 @@ void FCEUD_TraceInstruction()
{
// Insert Name and Comment lines if needed
str_decoration[0] = 0;
decorateAddress(X.PC, str_decoration);
decorateAddress(addr, str_decoration);
if (str_decoration[0])
{
// divide the str_decoration into strings (Name, Comment1, Comment2, ...)
@ -490,16 +441,16 @@ void FCEUD_TraceInstruction()
// special case: an RTS opcode
// add "----------" to emphasize the end of subroutine
strcat(str_disassembly, " ");
for (int j = strlen(str_disassembly); j < (LOG_DISASSEMBLY_MAX_LEN - 1); ++j)
str_disassembly[j] = '-';
for (int i = strlen(str_disassembly); i < (LOG_DISASSEMBLY_MAX_LEN - 1); ++i)
str_disassembly[i] = '-';
str_disassembly[LOG_DISASSEMBLY_MAX_LEN - 1] = 0;
} else
{
// stretch the disassembly string out if we have to output other stuff.
if ((logging_options & (LOG_REGISTERS|LOG_PROCESSOR_STATUS)) && !(logging_options & LOG_TO_THE_LEFT))
{
for (j = strlen(str_disassembly); j < (LOG_DISASSEMBLY_MAX_LEN - 1); ++j)
str_disassembly[j] = ' ';
for (int i = strlen(str_disassembly); i < (LOG_DISASSEMBLY_MAX_LEN - 1); ++i)
str_disassembly[i] = ' ';
str_disassembly[LOG_DISASSEMBLY_MAX_LEN - 1] = 0;
}
}
@ -551,7 +502,7 @@ void FCEUD_TraceInstruction()
strcat(str_temp, str_tabs);
}
sprintf(str_address, "$%04X:", X.PC);
sprintf(str_address, "$%04X:", addr);
strcat(str_temp, str_address);
strcat(str_temp, str_data);
strcat(str_temp, str_disassembly);
@ -612,7 +563,6 @@ void EndLoggingSequence(void){
}
//void PauseLoggingSequence(void){
void UpdateLogWindow(void)
{
//we don't want to continue if the trace logger isn't logging, or if its logging to a file.
@ -651,13 +601,6 @@ void UpdateLogText(void)
int i, j;
char str[3000];
str[0] = 0;
/*
for(i = 21;i > 0;i--){
j = tracelogbufpos-i-1;
if((tracelogbufusedsize == tracelogbufsize) && (j < 0))j = tracelogbufsize+j;
if(j >= 0)strcat(str,tracelogbuf[j]);
}
*/
for(i = tracesi.nPos;i < std::min(tracesi.nMax,tracesi.nPos+21);i++)
{
@ -675,14 +618,6 @@ void UpdateLogText(void)
}
void EnableTracerMenuItems(void){
//if(logging_options & LOG_NEW_INSTRUCTIONS){
//EnableWindow(GetDlgItem(hTracer,IDC_CHECK_LOG_NEW_DATA),TRUE);
//} else {
// CheckDlgButton(hTracer, IDC_CHECK_LOG_NEW_DATA, BST_UNCHECKED);
//EnableWindow(GetDlgItem(hTracer,IDC_CHECK_LOG_NEW_DATA),FALSE);
//}
if(logging)
{
EnableWindow(GetDlgItem(hTracer,IDC_RADIO_LOG_LAST),FALSE);
@ -711,21 +646,6 @@ void EnableTracerMenuItems(void){
EnableWindow(GetDlgItem(hTracer,IDC_CHECK_LOG_UPDATE_WINDOW),TRUE);
}
/*
if(FCEUI_GetLoggingCD()){
EnableWindow(GetDlgItem(hTracer,IDC_CHECK_LOG_NEW_INSTRUCTIONS),TRUE);
if(logging_options & LOG_NEW_INSTRUCTIONS){
EnableWindow(GetDlgItem(hTracer,IDC_CHECK_LOG_NEW_DATA),TRUE);
} else EnableWindow(GetDlgItem(hTracer,IDC_CHECK_LOG_NEW_DATA),FALSE);
}
else{
EnableWindow(GetDlgItem(hTracer,IDC_CHECK_LOG_NEW_INSTRUCTIONS),FALSE);
EnableWindow(GetDlgItem(hTracer,IDC_CHECK_LOG_NEW_DATA),FALSE);
CheckDlgButton(hTracer, IDC_CHECK_LOG_NEW_INSTRUCTIONS, BST_UNCHECKED);
CheckDlgButton(hTracer, IDC_CHECK_LOG_NEW_DATA, BST_UNCHECKED);
logging_options &= 3;
}
*/
return;
}
@ -736,47 +656,45 @@ int PromptForCDLogger(void){
the Code/Data Logger must also be running.\
Would you like to Start the Code/Data Logger Now?","Start Code/Data Logger?",
MB_YESNO) == IDYES){
DoCDLogger();
FCEUI_SetLoggingCD(1);
//EnableTracerMenuItems();
SetDlgItemText(hCDLogger, BTN_CDLOGGER_START_PAUSE, "Pause");
return 1;
}
DoCDLogger();
FCEUI_SetLoggingCD(1);
SetDlgItemText(hCDLogger, BTN_CDLOGGER_START_PAUSE, "Pause");
return 1;
}
return 0; //user selected no so 0 is returned
}
return 1;
}
void ShowLogDirDialog(void){
const char filter[]="6502 Trace Log File (*.log)\0*.log;*.txt\0" "6502 Trace Log File (*.txt)\0*.log;*.txt\0All Files (*.*)\0*.*\0\0"; //'" "' used to prevent octal conversion on the numbers
char nameo[2048];
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize=sizeof(ofn);
ofn.hInstance=fceu_hInstance;
ofn.lpstrTitle="Log Trace As...";
ofn.lpstrFilter=filter;
strcpy(nameo,GetRomName());
ofn.lpstrFile=nameo;
ofn.nMaxFile=256;
ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
ofn.hwndOwner = hTracer;
if(GetSaveFileName(&ofn)){
if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(nameo, sizeof(nameo), ".log");
else if (ofn.nFilterIndex == 2)
AddExtensionIfMissing(nameo, sizeof(nameo), ".txt");
if(logfilename)free(logfilename);
logfilename = (char*)malloc(strlen(nameo)+1); //mbg merge 7/19/06 added cast
strcpy(logfilename,nameo);
}
return;
const char filter[]="6502 Trace Log File (*.log)\0*.log;*.txt\0" "6502 Trace Log File (*.txt)\0*.log;*.txt\0All Files (*.*)\0*.*\0\0"; //'" "' used to prevent octal conversion on the numbers
char nameo[2048];
OPENFILENAME ofn;
memset(&ofn,0,sizeof(ofn));
ofn.lStructSize=sizeof(ofn);
ofn.hInstance=fceu_hInstance;
ofn.lpstrTitle="Log Trace As...";
ofn.lpstrFilter=filter;
strcpy(nameo,GetRomName());
ofn.lpstrFile=nameo;
ofn.nMaxFile=256;
ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
ofn.hwndOwner = hTracer;
if(GetSaveFileName(&ofn)){
if (ofn.nFilterIndex == 1)
AddExtensionIfMissing(nameo, sizeof(nameo), ".log");
else if (ofn.nFilterIndex == 2)
AddExtensionIfMissing(nameo, sizeof(nameo), ".txt");
if(logfilename)
free(logfilename);
logfilename = (char*)malloc(strlen(nameo)+1); //mbg merge 7/19/06 added cast
strcpy(logfilename,nameo);
}
return;
}
void DoTracer()
{
if (!GameInfo) {
FCEUD_PrintError("You must have a game loaded before you can use the Trace Logger.");
return;
@ -792,7 +710,6 @@ void DoTracer()
//hTracer gets set in WM_INITDIALOG
} else
{
//SetWindowPos(hTracer,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_NOOWNERZORDER);
ShowWindow(hTracer, SW_SHOWNORMAL);
SetForegroundWindow(hTracer);
}

View File

@ -38,6 +38,5 @@ extern bool log_old_emu_paused;
void EnableTracerMenuItems(void);
void LogInstruction(void);
void DoTracer();
//void PauseLoggingSequence();
void UpdateLogWindow(void);
void OutputLogLine(const char *str, bool add_newline = true);