@@ -48,6 +48,7 @@ void Start_Auto_Refresh_Thread(void);
4848void Scroll_Memory_View (int lines );
4949void Refresh_Memory_With_Diff (BOOL ShowDiff );
5050void Clear_Selection (void );
51+ void Copy_Selection (void );
5152int Get_Ascii_Index (POINTS pt );
5253
5354LRESULT CALLBACK Memory_Window_Proc (HWND hDlg , UINT uMsg , WPARAM wParam , LPARAM lParam );
@@ -192,8 +193,7 @@ void Insert_MemoryLineDump (unsigned int location, int InsertPos, BOOL ShowDiff)
192193 word .UB [2 ] < ' ' || word .UB [2 ] > '~' ? '.' : word .UB [2 ],
193194 word .UB [1 ] < ' ' || word .UB [1 ] > '~' ? '.' : word .UB [1 ],
194195 word .UB [0 ] < ' ' || word .UB [0 ] > '~' ? '.' : word .UB [0 ]);
195- }
196- else {
196+ } else {
197197 for (int i = 0 ; i < 4 ; i ++ ) {
198198 int index = count * 4 + i ;
199199
@@ -218,8 +218,7 @@ void Insert_MemoryLineDump (unsigned int location, int InsertPos, BOOL ShowDiff)
218218 word .UB [2 ] < ' ' || word .UB [2 ] > '~' ? '.' : word .UB [2 ],
219219 word .UB [1 ] < ' ' || word .UB [1 ] > '~' ? '.' : word .UB [1 ],
220220 word .UB [0 ] < ' ' || word .UB [0 ] > '~' ? '.' : word .UB [0 ]);
221- }
222- else {
221+ } else {
223222 for (int i = 0 ; i < 4 ; i ++ ) {
224223 int index = count * 4 + i ;
225224
@@ -239,6 +238,85 @@ void Insert_MemoryLineDump (unsigned int location, int InsertPos, BOOL ShowDiff)
239238 }
240239}
241240
241+ void Write_MemoryLineDump (char * output , unsigned int location ) {
242+ MIPS_WORD word ;
243+
244+ sprintf (output , "0x%08X " , location );
245+ output += 12 ;
246+
247+ char bytes [49 ] = { 0 };
248+ char ascii [17 ] = { 0 };
249+ char * b = bytes ;
250+ char * a = ascii ;
251+ __try {
252+ if (SendMessage (hVAddr , BM_GETSTATE , 0 , 0 ) & BST_CHECKED ) {
253+ for (int count = 0 ; count < 4 ; count ++ ) {
254+ if (r4300i_LW_VAddr_NonCPU (location , & word .UW )) {
255+ for (int i = 0 ; i < 4 ; i ++ ) {
256+ if (selection .enabled && (selection .range [0 ] > location + i || selection .range [1 ] < location + i )) {
257+ strcpy (b , " " );
258+ strcpy (a , " " );
259+ } else {
260+ sprintf (b , "%02X " , word .UB [3 - i ]);
261+ sprintf (a , "%c" , (word .UB [3 - i ] < ' ' || word .UB [3 - i ] > '~' ) ? '.' : word .UB [3 - i ]);
262+ }
263+ b += 3 ;
264+ a ++ ;
265+ }
266+ } else {
267+ for (int i = 0 ; i < 4 ; i ++ ) {
268+ if (selection .enabled && (selection .range [0 ] > location + i || selection .range [1 ] < location + i )) {
269+ strcpy (b , " " );
270+ strcpy (a , " " );
271+ } else {
272+ strcpy (b , "** " );
273+ strcpy (a , "*" );
274+ }
275+ b += 3 ;
276+ a ++ ;
277+ }
278+ }
279+ location += 4 ;
280+ }
281+ } else {
282+ for (int count = 0 ; count < 4 ; count ++ ) {
283+ if (location < 0x1FFFFFFC ) {
284+ r4300i_LW_PAddr (location , & word .UW );
285+ for (int i = 0 ; i < 4 ; i ++ ) {
286+ if (selection .enabled && (selection .range [0 ] > location + i || selection .range [1 ] < location + i )) {
287+ strcpy (b , " " );
288+ strcpy (a , " " );
289+ } else {
290+ sprintf (b , "%02X " , word .UB [3 - i ]);
291+ sprintf (a , "%c" , (word .UB [3 - i ] < ' ' || word .UB [3 - i ] > '~' ) ? '.' : word .UB [3 - i ]);
292+ }
293+ b += 3 ;
294+ a ++ ;
295+ }
296+ } else {
297+ for (int i = 0 ; i < 4 ; i ++ ) {
298+ if (selection .enabled && (selection .range [0 ] > location + i || selection .range [1 ] < location + i )) {
299+ strcpy (b , " " );
300+ strcpy (a , " " );
301+ } else {
302+ strcpy (b , "** " );
303+ strcpy (a , "*" );
304+ }
305+ b += 3 ;
306+ a ++ ;
307+ }
308+ }
309+ location += 4 ;
310+ }
311+ }
312+ } __except( r4300i_Command_MemoryFilter ( GetExceptionCode (), GetExceptionInformation ()) ) {
313+ DisplayError (GS (MSG_UNKNOWN_MEM_ACTION ));
314+ PostQuitMessage (0 );
315+ }
316+
317+ sprintf (output , "%s %s\r\n" , bytes , ascii );
318+ }
319+
242320LRESULT CALLBACK Memory_Window_Proc (HWND hDlg , UINT uMsg , WPARAM wParam , LPARAM lParam ) {
243321 PAINTSTRUCT ps ;
244322 RECT rcBox ;
@@ -549,6 +627,11 @@ LRESULT CALLBACK Memory_ListViewKeys_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, L
549627 case VK_NEXT :
550628 Scroll_Memory_View (16 );
551629 return FALSE;
630+ case 'C' :
631+ if (GetKeyState (VK_CONTROL ) & 0x8000 ) {
632+ Copy_Selection ();
633+ }
634+ return FALSE;
552635 default :
553636 break ;
554637 }
@@ -674,6 +757,37 @@ void Clear_Selection(void) {
674757 selection .range_cmp [1 ] = 0 ;
675758}
676759
760+ void Copy_Selection (void ) {
761+ if (!selection .enabled || !OpenClipboard (NULL )) {
762+ return ;
763+ }
764+ EmptyClipboard ();
765+
766+ int lines = (selection .range [1 ] - selection .range [0 ]) / 16 + 1 ;
767+
768+ // Each line is exactly 79 bytes, plus the null terminator.
769+ HGLOBAL hMemory = GlobalAlloc (GMEM_MOVEABLE , lines * 79 + 1 );
770+ if (!hMemory ) {
771+ CloseClipboard ();
772+ return ;
773+ }
774+
775+ char * memory = GlobalLock (hMemory );
776+
777+ char * output = memory ;
778+ DWORD location = selection .range [0 ] & ~15 ;
779+ for (int i = 0 ; i < lines ; i ++ ) {
780+ Write_MemoryLineDump (output , location );
781+ output += 79 ;
782+ location += 16 ;
783+ }
784+
785+ GlobalUnlock (hMemory );
786+ // TODO: Also copy the binary data
787+ SetClipboardData (CF_TEXT , memory );
788+ CloseClipboard ();
789+ }
790+
677791int Get_Ascii_Index (POINTS pt ) {
678792 RECT rc ;
679793 // The row doesn't matter because we ignore the Y coordinate
0 commit comments