-
Notifications
You must be signed in to change notification settings - Fork 22
/
MemoryMap.cpp
778 lines (666 loc) · 19.6 KB
/
MemoryMap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
//------------------------------------------------------------------
// Display VCC memory for debugging
//
// This file is part of VCC (Virtual Color Computer).
// Copyright 2015 by Joseph Forgione
//
// VCC (Virtual Color Computer) is free software: you can redistribute
// it and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// VCC (Virtual Color Computer) is distributed in the hope that it will
// be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with VCC (Virtual Color Computer). If not, see
// <http://www.gnu.org/licenses/>.
//
// Memory Map Display - Part of the Debugger package for VCC
// Authors: Mike Rojas, Chet Simpson
// Enhancements: EJJaquay
//------------------------------------------------------------------
#include "MemoryMap.h"
#include "Debugger.h"
#include "DebuggerUtils.h"
#include "defines.h"
#include "tcc1014mmu.h"
#include "resource.h"
#include "pakinterface.h"
#include "logger.h"
namespace VCC { namespace Debugger { namespace UI { namespace {
// Local functions
void SetEditing(bool);
void FlashDialogWindow();
void WriteMemory(int,unsigned char);
void SetBackBuffer(RECT);
void CreateScrollBar(RECT);
void DrawForm(HDC,LPRECT);
void DrawMemory(HDC,LPRECT);
void SetEditPosition(int,int);
void LocateMemory();
void CommitValue();
void SetMemType();
void InitializeDialog(HWND);
void DoScroll(WPARAM);
int CStrToHex(const char *);
LRESULT CALLBACK subEditValProc(HWND,UINT,WPARAM,LPARAM);
LRESULT CALLBACK subEditAdrProc(HWND,UINT,WPARAM,LPARAM);
INT_PTR CALLBACK MemoryMapDlgProc(HWND,UINT,WPARAM,LPARAM);
// Global handles
HWND hDlgMem = NULL;
HWND hScrollBar = NULL;
HWND hEditAdr = NULL;
HWND hEditVal = NULL;
// Original controls
WNDPROC EditValProc;
WNDPROC EditAdrProc;
// Enum for memory type being examined
enum AddrMode
{
Cpu,
Real,
ROM,
PAK,
NotSet
};
AddrMode AddrMode_ = AddrMode::NotSet;
int MemSize = 0;
int memoryOffset = 0;
static unsigned char *Rom = NULL;
bool Editing = false;
int editAddress = 0;
// Backing buffer used for painting memory data
BackBufferInfo BackBuf;
// Data cell X offsets relative to the backing buffer
// Cells are 18 pixels square with a 15 pixel gap between 7 & 8
const int Xoffset[16] =
{70,88,106,124,142,160,178,196,229,247,265,283,301,319,337,355};
// Help text
char DbgHelp[] =
"The default memory type displayed is 'CPU'.\n"
"Dropdown will select 'REAL', 'ROM', or 'PAK'.\n"
"\n"
"In addition to the scroll bar the mouse wheel,\n"
"Home, End, PgUp, PgDn, Up, and Down keys\n"
"will scroll the display.\n"
"\n"
"Select memory to be edited by clicking on a\n"
"value or by entering the address in the Find\n"
"box. The cell being edited will turn red and\n"
"the edit address will be displayed next to the\n"
"box. Enter byte values in hexadecimal.\n";
//------------------------------------------------------------------
// Display Memory Dialog
//------------------------------------------------------------------
INT_PTR CALLBACK MemoryMapDlgProc(
HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
switch (message) {
case WM_INITDIALOG:
InitializeDialog(hDlg);
break;
case WM_LBUTTONDOWN:
SetEditPosition(LOWORD(lParam),HIWORD(lParam));
break;
case WM_VSCROLL:
DoScroll(wParam);
break;
case WM_MOUSEWHEEL:
if ( GET_WHEEL_DELTA_WPARAM(wParam) < 0) {
DoScroll( (WPARAM) SB_LINEUP);
} else {
DoScroll( (WPARAM) SB_LINEDOWN);
}
break;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hDlg, &ps);
DrawMemory(BackBuf.DeviceContext, &BackBuf.Rect);
BitBlt(hdc, 0, 0, BackBuf.Width, BackBuf.Height,
BackBuf.DeviceContext, 0, 0, SRCCOPY);
EndPaint(hDlg, &ps);
break;
}
case WM_TIMER:
switch (wParam) {
case IDT_MEM_TIMER:
if ( AddrMode_ == AddrMode::Cpu ||
AddrMode_ == AddrMode::Real ) {
InvalidateRect(hDlg, &BackBuf.Rect, FALSE);
}
}
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDC_MEM_TYPE:
SetMemType();
InvalidateRect(hDlg, &BackBuf.Rect, FALSE);
break;
case IDC_BTN_FIND_MEM:
LocateMemory();
break;
case IDC_BTN_HELP:
MessageBox(hDlg,DbgHelp,"Usage",0);
SetFocus(hEditAdr);
break;
case IDCLOSE:
case WM_DESTROY:
KillTimer(hDlg, IDT_MEM_TIMER);
DeleteDC(BackBuf.DeviceContext);
DestroyWindow(hDlg);
hDlgMem = NULL;
break;
}
break;
}
return FALSE;
}
//------------------------------------------------------------------
// Subclassed Edit Value Proc
//------------------------------------------------------------------
LRESULT CALLBACK subEditValProc(
HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_KEYDOWN:
switch (wParam) {
case VK_RETURN:
CommitValue();
return 0;
case VK_TAB:
SetFocus(hEditAdr);
return 0;
case VK_UP:
case VK_DOWN:
case VK_PRIOR:
case VK_NEXT:
case VK_HOME:
case VK_END:
FlashDialogWindow();
return 0;
}
}
return CallWindowProc(EditValProc, wnd, msg, wParam, lParam);
}
//------------------------------------------------------------------
// Subclassed Edit Address Proc
//------------------------------------------------------------------
LRESULT CALLBACK subEditAdrProc(
HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg) {
case WM_KEYDOWN:
switch (wParam) {
case VK_RETURN:
LocateMemory();
return 0;
case VK_TAB:
SetFocus(hEditVal);
return 0;
case VK_UP:
DoScroll((WPARAM)SB_LINEUP);
return 0;
case VK_DOWN:
DoScroll((WPARAM)SB_LINEDOWN);
return 0;
case VK_PRIOR:
DoScroll((WPARAM)SB_PAGEUP);
return 0;
case VK_NEXT:
DoScroll((WPARAM)SB_PAGEDOWN);
return 0;
case VK_HOME:
DoScroll((WPARAM)SB_TOP);
return 0;
case VK_END:
DoScroll((WPARAM)SB_BOTTOM);
return 0;
}
}
return CallWindowProc(EditValProc, wnd, msg, wParam, lParam);
}
//------------------------------------------------------------------
// Read a byte from Coco Memory
//------------------------------------------------------------------
unsigned char ReadMemory(int addr)
{
switch (AddrMode_) {
case AddrMode::Cpu:
return SafeMemRead8(addr & 0xFFFF);
case AddrMode::Real:
return (unsigned char) GetMem(addr);
case AddrMode::ROM:
if (Rom == NULL) Rom = Getint_rom_pointer();
return Rom[addr & 0x7FFF];
case AddrMode::PAK:
return PackMem8Read(addr & 0x7FFF);
}
return 0;
}
//------------------------------------------------------------------
// Write a byte to Coco Memory
//------------------------------------------------------------------
void WriteMemory(int addr, unsigned char value)
{
switch (AddrMode_) {
case AddrMode::Cpu:
EmuState.Debugger.QueueWrite(addr & 0xFFFF, value);
break;
case AddrMode::Real:
SetMem(addr,value);
break;
case AddrMode::ROM:
if (Rom == NULL) Rom = Getint_rom_pointer();
Rom[addr & 0x7FFF] = value;
break;
case AddrMode::PAK: // FIXME not working
PackMem8Write(addr & 0x7FFF,value);
break;
}
}
//------------------------------------------------------------------
// Setup back buffer for data display
//------------------------------------------------------------------
void SetBackBuffer(RECT rc)
{
HDC hdc = GetDC(hDlgMem);
FillRect(hdc, &rc, (HBRUSH) (COLOR_WINDOW+1));
// Adjust backing buffer location on client
BackBuf.Rect.left = rc.left;
BackBuf.Rect.right = rc.right - 22;
BackBuf.Rect.top = rc.top + 34;
BackBuf.Rect.bottom = rc.bottom + 34;
BackBuf.Width = BackBuf.Rect.right - BackBuf.Rect.left;
BackBuf.Height = BackBuf.Rect.bottom - BackBuf.Rect.top;
BackBuf.Bitmap = CreateCompatibleBitmap
(hdc, BackBuf.Width, BackBuf.Height);
BackBuf.DeviceContext = CreateCompatibleDC(hdc);
HBITMAP old = (HBITMAP) SelectObject
(BackBuf.DeviceContext, BackBuf.Bitmap);
DeleteObject(old);
ReleaseDC(hDlgMem, hdc);
}
//------------------------------------------------------------------
// Create vertical scroll bar
//------------------------------------------------------------------
void CreateScrollBar(RECT Rect)
{
hScrollBar = CreateWindowEx(
0,
"SCROLLBAR",
NULL,
WS_VISIBLE | WS_CHILD | SBS_VERT,
Rect.right - 21, //top x
38, //top y
20, //width
Rect.bottom - 42, //height
hDlgMem,
(HMENU)IDC_MEM_VSCROLLBAR,
(HINSTANCE)GetWindowLong(hDlgMem, GWL_HINSTANCE),
NULL);
if (!hScrollBar) {
MessageBox(NULL, "Vertical Scroll Bar Failed.", "Error",
MB_OK | MB_ICONERROR);
}
}
//------------------------------------------------------------------
// Draw display form with header and vert guide lines
//------------------------------------------------------------------
void DrawForm(HDC hdc,LPRECT clientRect)
{
int top = clientRect->top;
int lft = clientRect->left;
int rgt = clientRect->right;
int bot = clientRect->bottom;
RECT rc;
// Clear background.
HBRUSH brush = (HBRUSH)GetStockObject(WHITE_BRUSH);
FillRect(hdc, clientRect, brush);
// Format for text
UINT fmt = DT_CENTER | DT_VCENTER | DT_SINGLELINE;
// Draw separator lines for border, address, and ascii
MoveToEx(hdc,lft,top,NULL); LineTo(hdc,rgt,top);
MoveToEx(hdc,lft,top+20,NULL); LineTo(hdc,rgt,top+20);
MoveToEx(hdc,lft+1,top,NULL); LineTo(hdc,lft+1,bot-1);
MoveToEx(hdc,lft+60,top,NULL); LineTo(hdc,lft+60,bot-1);
MoveToEx(hdc,rgt-135,top,NULL); LineTo(hdc,rgt-135,bot);
MoveToEx(hdc,rgt-1,top,NULL); LineTo(hdc,rgt-1,bot);
// Horizontal separators every four rows
int ltop = top + 20;
for (int lnum = 3; lnum < 32; lnum+=4) {
ltop += 18*4;
MoveToEx(hdc,lft,ltop,NULL); LineTo(hdc,rgt,ltop);
}
// Draw header
SetTextColor(hdc, RGB(138,27,255));
SetRect(&rc,lft,top,lft+60,top+20);
DrawText(hdc, "Address", 7, &rc, fmt);
for (int n = 0; n < 16; n++) {
SetRect(&rc, lft+Xoffset[n], top, lft+Xoffset[n]+15, top+20);
const std::string s(ToHexString(n, 2, false));
DrawText(hdc, s.c_str(), 2, &rc, fmt);
}
SetRect(&rc, rgt - 135, top, rgt - 5, top + 20);
DrawText(hdc, "ASCII", 6, &rc, fmt);
}
//------------------------------------------------------------------
// Fill memory data on form
//------------------------------------------------------------------
void DrawMemory(HDC hdc, LPRECT clientRect)
{
int top = clientRect->top;
int lft = clientRect->left;
int rgt = clientRect->right;
RECT rc;
bool hlfound = false;
std::string s;
UINT fmt = DT_CENTER | DT_VCENTER | DT_SINGLELINE;
int ltop = top + 20; // Back buff relative
for (int lnum = 0; lnum < 32; lnum++) {
// Draw address of start of line
SetTextColor(hdc, RGB(138, 27, 255));
s = ToHexString(memoryOffset + lnum * 16, 6, true);
SetRect(&rc, lft, ltop, lft+64, ltop+18);
DrawText(hdc, s.c_str(), s.size(), &rc, fmt);
// Fill in data cells
SetTextColor(hdc, RGB(0, 0, 0));
int hilite = false;
std::string ascii;
for (int n = 0; n < 16; n++) {
// Get data
int adr = lnum * 16 + n + memoryOffset;
unsigned char val = ReadMemory(adr);
// Get hex string to display.
s = ToHexString(val, 2, true);
// Highlight data if cell is being edited
if (Editing && editAddress == adr) {
SetTextColor(hdc, RGB(255, 0, 0)); // Red
hilite = true;
}
SetRect(&rc,lft+Xoffset[n],ltop,lft+Xoffset[n]+18,ltop+18);
DrawText(hdc, s.c_str(), 2, &rc, fmt);
// if highlight on turn it off
if (hilite) {
SetTextColor(hdc, RGB(0, 0, 0));
hlfound = true;
}
// Append to ascii
if (isprint(val)) ascii += val; else ascii += ".";
}
// Draw the ascii string
SetRect(&rc, rgt-133, ltop, rgt-5, ltop+18);
DrawText(hdc, ascii.c_str(), ascii.size(), &rc, fmt);
ltop += 18;
}
// Not editmode if no cell highlighted.
if (Editing && !hlfound) {
SetEditing(false);
}
}
//------------------------------------------------------------------
// Determine byte to edit based on click location
//------------------------------------------------------------------
void SetEditPosition(int xPos, int yPos)
{
int xStart = 70; // X Start of data cells
int yStart = 55; // Y Start of data cells (dialog relative)
// Cells have a dead zone between col 7 and 8
int leftDeadArea = xStart + (8 * 18);
int rightDeadArea = leftDeadArea + 15;
int xMax = rightDeadArea + (8 * 18);
// Stop edit if location is not in cell area
if ( yPos < yStart || xPos < xStart || xPos > xMax ||
(xPos >= leftDeadArea && xPos <= rightDeadArea) ) {
SetEditing(false);
return;
}
// Determine address per cell (18x18) row and column
int row = (yPos - yStart) / 18;
int col;
if (xPos < leftDeadArea)
col = (xPos - xStart) / 18;
else
col = (xPos - rightDeadArea) / 18 + 8;
int addr = memoryOffset + col + row * 16;
editAddress = addr;
SetEditing(true);
InvalidateRect(hDlgMem, &BackBuf.Rect, FALSE);
}
//------------------------------------------------------------------
// Determine byte to edit based on edit address box
//------------------------------------------------------------------
void LocateMemory()
{
char buf[32] = {0};
SendDlgItemMessage(hDlgMem, IDC_EDIT_ADDRESS, WM_GETTEXT,
sizeof(buf), (LPARAM) buf);
SetDlgItemText(hDlgMem, IDC_EDIT_ADDRESS, "");
int addr = CStrToHex(buf);
if (addr < 0) {
FlashDialogWindow();
SetEditing(false);
return;
}
SCROLLINFO si;
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
GetScrollInfo(hScrollBar, SB_CTL, &si);
si.nPos = roundDn(addr, 16);
si.fMask = SIF_POS;
SetScrollInfo(hScrollBar, SB_CTL, &si, TRUE);
GetScrollInfo(hScrollBar, SB_CTL, &si);
memoryOffset = si.nPos;
// If addr is on screen set editing
if (addr >= memoryOffset && addr < memoryOffset + 16 * 32) {
editAddress = addr;
SetEditing(true);
} else {
SetEditing(false);
}
InvalidateRect(hDlgMem, &BackBuf.Rect, FALSE);
}
//------------------------------------------------------------------
// Commit edit value to memory
//------------------------------------------------------------------
void CommitValue()
{
if (!Editing) {
FlashDialogWindow();
SetDlgItemText(hDlgMem, IDC_EDIT_VALUE, "");
return;
}
// Fetch then clear the data to commit
char buf[32] = {0};
SendDlgItemMessage(hDlgMem, IDC_EDIT_VALUE, WM_GETTEXT,
sizeof(buf), (LPARAM) buf);
SetDlgItemText(hDlgMem, IDC_EDIT_VALUE, "");
int val = CStrToHex(buf);
if (val < 0 || val > 255) {
FlashDialogWindow();
return;
}
// Commit the value to memory
WriteMemory(editAddress, (unsigned char) val);
InvalidateRect(hDlgMem, &BackBuf.Rect, FALSE);
// Attempt to advance to next cell
editAddress += 1;
if (editAddress >= MemSize) {
FlashDialogWindow();
editAddress = 0;
SetEditing(false);
} else {
SetEditing(true);
}
}
//------------------------------------------------------------------
// Set memory type and size as per combobox index
//------------------------------------------------------------------
void SetMemType()
{
int PhySiz[4]={0x20000,0x80000,0x200000,0x800000};
HWND hCtl = GetDlgItem(hDlgMem, IDC_MEM_TYPE);
AddrMode mode = (AddrMode) SendMessage(hCtl,CB_GETCURSEL,0,0);
if (AddrMode_ == mode) return; // Not changed
memoryOffset = 0;
AddrMode_ = mode;
switch (AddrMode_) {
case AddrMode::Cpu:
MemSize = 0x10000;
break;
case AddrMode::Real:
MemSize = PhySiz[EmuState.RamSize];
break;
case AddrMode::ROM:
MemSize = 0x8000;
break;
case AddrMode::PAK:
MemSize = 0x8000;
break;
}
SCROLLINFO si;
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_POS;
si.nMin = 0;
si.nPage = 32 * 16; // 32 lines of 16 bytes
si.nMax = MemSize - si.nPage;
si.nPos = 0;
SetScrollInfo(hScrollBar, SB_CTL, &si, TRUE);
SetEditing(false);
}
//------------------------------------------------------------------
// Memory Dialog initialization
//------------------------------------------------------------------
void InitializeDialog(HWND hDlg)
{
hDlgMem = hDlg;
RECT Rect;
GetClientRect(hDlg, &Rect);
SetBackBuffer(Rect);
CreateScrollBar(Rect);
//Subclass edit boxes
hEditAdr = GetDlgItem(hDlg, IDC_EDIT_ADDRESS);
EditAdrProc = (WNDPROC) SetWindowLongPtr
(hEditAdr, GWLP_WNDPROC, (LONG_PTR) subEditAdrProc);
hEditVal = GetDlgItem(hDlg, IDC_EDIT_VALUE);
EditValProc = (WNDPROC) SetWindowLongPtr
(hEditVal, GWLP_WNDPROC, (LONG_PTR) subEditValProc);
SetTimer(hDlg, IDT_MEM_TIMER, 64, (TIMERPROC)NULL);
// Dropdown to select memory type displayed
HWND hCtl = GetDlgItem(hDlg, IDC_MEM_TYPE);
SendMessage(hCtl,CB_ADDSTRING,(WPARAM) 0, (LPARAM) "CPU");
SendMessage(hCtl,CB_ADDSTRING,(WPARAM) 0, (LPARAM) "REAL");
SendMessage(hCtl,CB_ADDSTRING,(WPARAM) 0, (LPARAM) "ROM");
SendMessage(hCtl,CB_ADDSTRING,(WPARAM) 0, (LPARAM) "PAK");
SendMessage(hCtl,CB_SETCURSEL,(WPARAM) 0, (LPARAM) 0);
SetMemType();
// Set display pen color
HPEN pen = (HPEN) CreatePen(PS_SOLID, 1, RGB(192, 192, 192));
SelectObject(BackBuf.DeviceContext, pen);
DeleteObject(pen);
// Set display Font
HFONT hFont = CreateFont (14, 0, 0, 0, FW_BOLD, FALSE, FALSE,
FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS,
CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, FIXED_PITCH,
TEXT("Consolas"));
SelectObject(BackBuf.DeviceContext, hFont);
DeleteObject(hFont);
// Draw the form for memory data
DrawForm(BackBuf.DeviceContext, &BackBuf.Rect);
// Not edit mode
SetEditing(false);
}
//------------------------------------------------------------------
// Scroll handler
//------------------------------------------------------------------
void DoScroll(WPARAM wParam)
{
SCROLLINFO si;
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
GetScrollInfo(hScrollBar, SB_CTL, &si);
switch ((int)LOWORD(wParam)) {
case SB_PAGEUP:
si.nPos -= 16*32;
break;
case SB_PAGEDOWN:
si.nPos += 16*32;
break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
si.nPos = si.nTrackPos;
break;
case SB_TOP:
si.nPos = 0;
break;
case SB_BOTTOM:
si.nPos = si.nMax;
break;
case SB_ENDSCROLL:
break;
case SB_LINEUP:
si.nPos -= 16;
break;
case SB_LINEDOWN:
si.nPos += 16;
break;
}
si.fMask = SIF_POS;
SetScrollInfo(hScrollBar, SB_CTL, &si, TRUE);
GetScrollInfo(hScrollBar, SB_CTL, &si);
memoryOffset = si.nPos;
InvalidateRect(hDlgMem, &BackBuf.Rect, FALSE);
}
//------------------------------------------------------------------
// Convert hexadecimal string to a positive long. Return -1 on error
//------------------------------------------------------------------
int CStrToHex(const char * buf)
{
char *p;
if (*buf == 0) return -1;
//long n = strtoul(buf, &p, 16);
int n = strtoul(buf, &p, 16);
if (*p != 0) return -1;
return n;
}
//------------------------------------------------------------------
// Set edit mode
//------------------------------------------------------------------
void SetEditing(bool tf) {
Editing = tf;
if (Editing) {
std::string s = "Editing " + ToHexString(editAddress,6,true);
SetDlgItemText(hDlgMem, IDC_ADRTXT, s.c_str());
SetFocus(hEditVal);
} else {
SetDlgItemText(hDlgMem, IDC_ADRTXT, "");
SetFocus(hEditAdr);
}
SetDlgItemText(hDlgMem, IDC_EDIT_VALUE, "");
}
//------------------------------------------------------------------
// Input error flash
//------------------------------------------------------------------
void FlashDialogWindow()
{
FlashWindow(hDlgMem,true);
Sleep(350);
FlashWindow(hDlgMem,false);
}
} } } } // end namespace
//------------------------------------------------------------------
// Launch Memory Dialog
//------------------------------------------------------------------
void VCC::Debugger::UI::OpenMemoryMapWindow(HINSTANCE hInst,HWND parent)
{
if (hDlgMem == NULL) {
CreateDialog( hInst, MAKEINTRESOURCE(IDD_MEMORY_MAP),
parent, MemoryMapDlgProc );
}
if (hDlgMem == NULL)
MessageBox(NULL,"CreateDialog","Error",MB_OK|MB_ICONERROR);
ShowWindow(hDlgMem, SW_SHOWNORMAL);
SetFocus(hEditAdr);
}