-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDebuggerUtils.cpp
146 lines (115 loc) · 3.65 KB
/
DebuggerUtils.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
// Copyright 2015 by Joseph Forgione
// This file is part of VCC (Virtual Color Computer).
//
// 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/>.
//
// Debugger Utilities - Part of the Debugger package for VCC
// Author: Chet Simpson
#include "Debugger.h"
#include "tcc1014mmu.h"
#include <sstream>
#include <iomanip>
#include <stdarg.h>
#include <memory>
#include "defines.h"
namespace VCC { namespace Debugger
{
std::string ToHexString(long value, int length, bool leadingZeros)
{
std::ostringstream fmt;
fmt << std::hex << std::setw(length) << std::uppercase << std::setfill(leadingZeros ? '0' : ' ') << value;
return fmt.str();
}
std::string ToDecimalString(long value, int length, bool leadingZeros)
{
std::ostringstream fmt;
fmt << std::dec << std::setw(length) << std::setfill(leadingZeros ? '0' : ' ') << value;
return fmt.str();
}
std::string ToByteString(std::vector<unsigned char> bytes)
{
std::ostringstream fmt;
for (auto& b : bytes)
{
if (fmt.str().size() > 0)
{
fmt << " ";
}
fmt << ToHexString(b, 2, true);
}
return fmt.str();
}
bool replace(std::string& str, const std::string& from, const std::string& to)
{
size_t start_pos = str.find(from);
if (start_pos == std::string::npos)
return false;
str.replace(start_pos, from.length(), to);
return true;
}
int roundUp(int numToRound, int multiple)
{
if (multiple == 0)
return numToRound;
int remainder = numToRound % multiple;
if (remainder == 0)
return numToRound;
return numToRound + multiple - remainder;
}
int roundDn(int numToRound, int multiple)
{
if (multiple == 0)
return numToRound;
int remainder = numToRound % multiple;
if (remainder == 0)
return numToRound;
return numToRound - remainder;
}
// Get memory for Decode, CPU address or Physical Block + Address
unsigned char DbgRead8(bool phyAddr, unsigned short block, unsigned short PC) {
if (phyAddr) {
unsigned long addr = PC + block * 0x2000;
return (unsigned char) GetMem(addr);
} else {
return SafeMemRead8(PC);
}
}
} }
namespace VCC { namespace Debugger { namespace UI
{
BackBufferInfo AttachBackBuffer(HWND hWnd, int widthAdjust, int heightAdjust)
{
BackBufferInfo backBuffer;
GetClientRect(hWnd, &backBuffer.Rect);
backBuffer.Rect.right += widthAdjust;
backBuffer.Rect.bottom += heightAdjust;
backBuffer.Width = backBuffer.Rect.right - backBuffer.Rect.left;
backBuffer.Height = backBuffer.Rect.bottom - backBuffer.Rect.top;
HDC hdc = GetDC(hWnd);
backBuffer.Bitmap = CreateCompatibleBitmap(hdc, backBuffer.Width, backBuffer.Height);
if (backBuffer.Bitmap == NULL)
{
throw std::runtime_error("failed to create backbuffer bitmap");
}
backBuffer.DeviceContext = CreateCompatibleDC(hdc);
if (backBuffer.DeviceContext == NULL)
{
throw std::runtime_error("failed to create the backbuffer device context");
}
HBITMAP oldbmp = (HBITMAP)SelectObject(backBuffer.DeviceContext, backBuffer.Bitmap);
DeleteObject(oldbmp);
ReleaseDC(hWnd, hdc);
return backBuffer;
}
} } }