From 9e1f1d82e987fa74aafe7d719d09d461eff7f880 Mon Sep 17 00:00:00 2001 From: zeromus Date: Tue, 13 May 2008 00:17:49 +0000 Subject: [PATCH] faster memwatch? --- src/drivers/win/debugger.cpp | 19 +++++++++++ src/drivers/win/debugger.h | 9 +++++ src/drivers/win/main.cpp | 4 +++ src/drivers/win/memview.cpp | 46 +++++++++++++------------- src/drivers/win/memwatch.cpp | 62 +++++++++++++++++++++++++++-------- src/drivers/win/res.rc | Bin 148002 -> 145562 bytes src/drivers/win/resource.h | 2 ++ src/drivers/win/window.cpp | 4 ++- 8 files changed, 110 insertions(+), 36 deletions(-) diff --git a/src/drivers/win/debugger.cpp b/src/drivers/win/debugger.cpp index 68e6a16c..be5fe189 100644 --- a/src/drivers/win/debugger.cpp +++ b/src/drivers/win/debugger.cpp @@ -1320,3 +1320,22 @@ void DoDebug(uint8 halt) { if (GameInfo) UpdateDebugger(); } } + +//----------------------------------------- +DebugSystem* debugSystem; + +DebugSystem::DebugSystem() +{ + hFixedFont = CreateFont(13,8, /*Height,Width*/ + 0,0, /*escapement,orientation*/ + 400,FALSE,FALSE,FALSE, /*weight, italic,, underline, strikeout*/ + ANSI_CHARSET,OUT_DEVICE_PRECIS,CLIP_MASK, /*charset, precision, clipping*/ + DEFAULT_QUALITY, DEFAULT_PITCH, /*quality, and pitch*/ + "Courier"); /*font name*/ +} + +DebugSystem::~DebugSystem() +{ + DeleteObject(hFixedFont); +} + diff --git a/src/drivers/win/debugger.h b/src/drivers/win/debugger.h index 37cdd654..9536135f 100644 --- a/src/drivers/win/debugger.h +++ b/src/drivers/win/debugger.h @@ -31,6 +31,15 @@ void DoDebug(uint8 halt); extern bool inDebugger; +extern class DebugSystem { +public: + DebugSystem(); + ~DebugSystem(); + + HFONT hFixedFont; + static const int fixedFontWidth = 8; + static const int fixedFontHeight = 13; +} *debugSystem; #endif diff --git a/src/drivers/win/main.cpp b/src/drivers/win/main.cpp index d27b92d9..4e4f682a 100644 --- a/src/drivers/win/main.cpp +++ b/src/drivers/win/main.cpp @@ -547,6 +547,7 @@ int main(int argc,char *argv[]) } InitCommonControls(); + debugSystem = new DebugSystem(); if(!FCEUI_Initialize()) { @@ -673,6 +674,9 @@ doloopy: DriverKill(); timeEndPeriod(1); FCEUI_Kill(); + + delete debugSystem; + return(0); } diff --git a/src/drivers/win/memview.cpp b/src/drivers/win/memview.cpp index 814f8934..90c49621 100644 --- a/src/drivers/win/memview.cpp +++ b/src/drivers/win/memview.cpp @@ -91,10 +91,7 @@ HWND hMemView, hMemFind; HDC mDC; //int tempdummy; //char dummystr[100]; -HFONT hMemFont; int CurOffset; -int MemFontHeight; -int MemFontWidth; int ClientHeight; int NoColors; int EditingMode; @@ -299,7 +296,11 @@ void UnloadTableFile(){ TableFileLoaded = 0; return; } -void UpdateMemoryView(int draw_all){ +void UpdateMemoryView(int draw_all) +{ + int MemFontWidth = debugSystem->fixedFontWidth; + int MemFontHeight = debugSystem->fixedFontHeight; + int i, j; //LPVOID lpMsgBuf; //int curlength; @@ -728,18 +729,22 @@ void ChangeMemViewFocus(int newEditingMode, int StartOffset,int EndOffset){ int GetHexScreenCoordx(int offset){ - return (8*MemFontWidth)+((offset%16)*3*MemFontWidth); //todo: add Curoffset to this and to below function + return (8*debugSystem->fixedFontWidth)+((offset%16)*3*debugSystem->fixedFontWidth); //todo: add Curoffset to this and to below function } int GetHexScreenCoordy(int offset){ - return (offset/16)*MemFontHeight; + return (offset/16)*debugSystem->fixedFontHeight; } //0000E0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................ //if the mouse is in the text field, this function will set AddyWasText to 1 otherwise it is 0 //if the mouse wasn't in any range, this function returns -1 -int GetAddyFromCoord(int x,int y){ +int GetAddyFromCoord(int x,int y) +{ + int MemFontWidth = debugSystem->fixedFontWidth; + int MemFontHeight = debugSystem->fixedFontHeight; + if(y < 0)y = 0; if(x < 8*MemFontWidth)x = 8*MemFontWidth+1; @@ -758,7 +763,8 @@ int GetAddyFromCoord(int x,int y){ return -1; } -void AutoScrollFromCoord(int x,int y){ +void AutoScrollFromCoord(int x,int y) +{ SCROLLINFO si; if(y < 0){ ZeroMemory(&si, sizeof(SCROLLINFO)); @@ -787,8 +793,8 @@ void AutoScrollFromCoord(int x,int y){ } } -void KillMemView(){ - DeleteObject(hMemFont); +void KillMemView() +{ ReleaseDC(hMemView,mDC); DestroyWindow(hMemView); UnregisterClass("MEMVIEW",fceu_hInstance); @@ -796,7 +802,8 @@ void KillMemView(){ return; } -LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ +LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ HDC hdc; HGLOBAL hGlobal ; PTSTR pGlobal ; @@ -808,6 +815,9 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa SCROLLINFO si; int x, y, i, j; + const int MemFontWidth = debugSystem->fixedFontWidth; + const int MemFontHeight = debugSystem->fixedFontHeight; + char c[2]; char str[100]; // ################################## Start of SP CODE ########################### @@ -831,18 +841,10 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa // ################################## End of SP CODE ########################### mDC = GetDC(hwnd); HDataDC = mDC;//deleteme - hMemFont = CreateFont(13,8, /*Height,Width*/ - 0,0, /*escapement,orientation*/ - 400,FALSE,FALSE,FALSE, /*weight, italic,, underline, strikeout*/ - ANSI_CHARSET,OUT_DEVICE_PRECIS,CLIP_MASK, /*charset, precision, clipping*/ - DEFAULT_QUALITY, DEFAULT_PITCH, /*quality, and pitch*/ - "Courier"); /*font name*/ - SelectObject (HDataDC, hMemFont); + SelectObject (HDataDC, debugSystem->hFixedFont); SetTextAlign(HDataDC,TA_UPDATECP | TA_TOP | TA_LEFT); - GetTextMetrics (HDataDC, &tm) ; - MemFontWidth = 8; - MemFontHeight = 13; + GetTextMetrics (HDataDC, &tm); MaxSize = 0x10000; //Allocate Memory for color lists @@ -1264,7 +1266,7 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return 0; case WM_SIZE: - ClientHeight = HIWORD (lParam) ; + ClientHeight = HIWORD (lParam); if(DataAmount != ((ClientHeight/MemFontHeight)*16)){ DataAmount = ((ClientHeight/MemFontHeight)*16); if(DataAmount+CurOffset > MaxSize)CurOffset = MaxSize-DataAmount; diff --git a/src/drivers/win/memwatch.cpp b/src/drivers/win/memwatch.cpp index 0892014f..9e471db0 100644 --- a/src/drivers/win/memwatch.cpp +++ b/src/drivers/win/memwatch.cpp @@ -22,7 +22,9 @@ #include "..\..\fceu.h" #include "memwatch.h" #include "..\..\debug.h" +#include "debugger.h" +static HDC hdc; static HWND hwndMemWatch=0; static char addresses[24][16]; static char labels[24][24]; @@ -120,6 +122,9 @@ static const int MW_ADDR_Lookup[] = { static const int MWNUM = ARRAY_SIZE(MW_ADDR_Lookup); +static int yPositions[MWNUM]; +static int xPositions[MWNUM]; + static struct MWRec { static int findIndex(WORD ctl) @@ -170,43 +175,46 @@ void UpdateMemWatch() { if(hwndMemWatch) { + SetTextColor(hdc,RGB(0,0,0)); + SetBkColor(hdc,GetSysColor(COLOR_3DFACE)); + for(int i = 0; i < MWNUM; i++) { MWRec& mwrec = mwrecs[i]; - uint16& a = mwrec.addr; - bool& hex = mwrec.hex; - bool& twobytes = mwrec.twobytes; - bool& valid = mwrec.valid; - if(mwrec.valid) + char* text; + if(mwrec.valid && GameInfo) { if(mwrec.hex) { if(mwrec.twobytes) { - SetDlgItemText(hwndMemWatch,1002+i*3,(LPTSTR)U8ToStr(GetMem(mwrec.addr))); + text = U16ToHexStr(GetMem(mwrec.addr)+(GetMem(mwrec.addr+1)<<8)); } else { - SetDlgItemText(hwndMemWatch,1002+i*3,(LPTSTR)U16ToDecStr(GetMem(mwrec.addr)+(GetMem(mwrec.addr+1)<<8))); + text = U8ToHexStr(GetMem(mwrec.addr)); } } else { if(mwrec.twobytes) { - SetDlgItemText(hwndMemWatch,1002+i*3,(LPTSTR)U8ToHexStr(GetMem(mwrec.addr))); + text = U16ToDecStr(GetMem(mwrec.addr)+(GetMem(mwrec.addr+1)<<8)); } else { - SetDlgItemText(hwndMemWatch,1002+i*3,(LPTSTR)U16ToHexStr(GetMem(mwrec.addr)+(GetMem(mwrec.addr+1)<<8))); + text = U8ToStr(GetMem(mwrec.addr)); } } } else { - SetDlgItemText(hwndMemWatch,1002+i*3,(LPTSTR)"---"); + text = "-"; } + + MoveToEx(hdc,xPositions[i],yPositions[i],NULL); + TextOut(hdc,0,0,text,strlen(text)); } } } @@ -387,18 +395,45 @@ static void LoadMemWatch() } } - static BOOL CALLBACK MemWatchCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { - //mbg 5/7/08 - wtf? - //DSMFix(uMsg); + const int kLabelControls[] = {MW_ValueLabel1,MW_ValueLabel2}; + switch(uMsg) { case WM_INITDIALOG: + hdc = GetDC(hwndDlg); + SelectObject (hdc, debugSystem->hFixedFont); + SetTextAlign(hdc,TA_UPDATECP | TA_TOP | TA_LEFT); + + //find the positions where we should draw string values + for(int i=0;i=MWNUM/2) + col=1; + RECT r; + GetWindowRect(GetDlgItem(hwndDlg,MW_ADDR_Lookup[i]),&r); + ScreenToClient(hwndDlg,(LPPOINT)&r); + ScreenToClient(hwndDlg,(LPPOINT)&r.right); + yPositions[i] = r.top; + yPositions[i] += ((r.bottom-r.top)-debugSystem->fixedFontHeight)/2; //vertically center + GetWindowRect(GetDlgItem(hwndDlg,kLabelControls[col]),&r); + ScreenToClient(hwndDlg,(LPPOINT)&r); + xPositions[i] = r.left; + } break; + + case WM_PAINT: { + PAINTSTRUCT ps; + BeginPaint(hwndDlg, &ps); + EndPaint(hwndDlg, &ps); + UpdateMemWatch(); + break; + } case WM_CLOSE: case WM_QUIT: SaveStrings(); + DeleteObject(hdc); DestroyWindow(hwndMemWatch); hwndMemWatch=0; break; @@ -490,6 +525,7 @@ void CreateMemWatch(HWND parent) //Create //hwndMemWatch=CreateDialog(fceu_hInstance,"MEMWATCH",parent,MemWatchCallB); hwndMemWatch=CreateDialog(fceu_hInstance,"MEMWATCH",NULL,MemWatchCallB); + UpdateMemWatch(); //Initialize values to previous entered addresses/labels { diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index 2afdaaf9c7a47d90d1994a08db80b4ab15215eb5..a44f53c94adf6d8ca41502bd8e03041b90605525 100644 GIT binary patch delta 138 zcmZ3~!a3_B#|Am3=}O#8i<%EHZ9l}sn58D|%Mi{G&k)9t$dJQO%8<(717sxu=^O^b z>86^D%9Ah5R+_xQj$^u(G2;Pc+^UTjbQp{njDfmrH5sMBy6(N;Xm>DS-0on)^o0j( K?erUtOkMy&1tt#w delta 1042 zcmZ{jF-yZh6vyulNiFCoPO*p*v}Ev-CQTPX+?*nQ0cWA$CvdUg?tupmQlz6p2BB*l zyZ9M&aw&qlgZJ_{bI}(930!{nfA8Kex&K;yoOFvVp(dT#bt&eh;1|J0$`UqU5ldOf zBs(xy$P)Fw+|-}1Jn$oDSsFAnDBPvl6snh}V^x%%k1M!2t|BNZbFv0x)_Lyv(xFl^ z3n)|lx7}fD*3h9wRMu^>vK>_~?AhT-923FV$&+RhFswf(MbMq5WN~}qsF9dZiFY00 z^_m_)+P}&b=bDf#Ys>S&MPwSoX%lHGKSLLmqP+qIE-XcR1qxhPiuO7^^?aNt_C(yKC54S@4HLJg8u5yW}c(?YN`t4mH05GxG#>@_4ks`be@TmA5lZRumAu6 diff --git a/src/drivers/win/resource.h b/src/drivers/win/resource.h index f4c9d544..ddd821c3 100644 --- a/src/drivers/win/resource.h +++ b/src/drivers/win/resource.h @@ -270,6 +270,8 @@ #define MENU_MEMORY_WATCH 40081 #define MENU_RAMFILTER 40082 #define MENU_LOG_SOUND 40120 +#define MW_ValueLabel2 65423 +#define MW_ValueLabel1 65426 #define GUI_BOT_DEBUG 65436 #define GUI_BOT_ERROR 65438 #define LBL_INPUT_HELP 65488 diff --git a/src/drivers/win/window.cpp b/src/drivers/win/window.cpp index 4298b6e1..c8e8e1ed 100644 --- a/src/drivers/win/window.cpp +++ b/src/drivers/win/window.cpp @@ -1158,7 +1158,9 @@ LRESULT FAR PASCAL AppWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam) goto proco; case WM_CLOSE: case WM_DESTROY: - case WM_QUIT:DoFCEUExit();break; + case WM_QUIT: + DoFCEUExit(); + break; case WM_ACTIVATEAPP: if((BOOL)wParam) {