-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackWindow.cpp
More file actions
165 lines (131 loc) · 3.44 KB
/
StackWindow.cpp
File metadata and controls
165 lines (131 loc) · 3.44 KB
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
//
// StackWindow.cpp
// Copyright © 2003 William Sheldon Simms III
//
#include <cstdio>
#include "StackWindow.h"
#include "instructions.h"
#include "AddressPeripheral.h"
#include "Prefs.h"
BEGIN_EVENT_TABLE(StackWindow, wxScrolledWindow)
EVT_PAINT(StackWindow::OnPaint)
END_EVENT_TABLE()
StackWindow::StackWindow (wxWindow * parent)
: wxScrolledWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxVSCROLL | wxSUNKEN_BORDER)
{
#if 0
SetRunning(FALSE);
#else
initial = TRUE;
#endif
SetThemeEnabled(FALSE);
SetBackgroundColour(*wxWHITE);
Prefs * prefs = Prefs::GetPrefs();
SetFont(wxFont(prefs->WindowFontSize(), wxFONTFAMILY_MODERN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
firstaddr = lastaddr = 0;
wxClientDC dc(this);
dc.SetFont(GetFont());
cwidth = dc.GetCharWidth();
cheight = dc.GetCharHeight();
#define STACKWIN_WIDTH (2 + 5 + 1 + 2 + 2)
int client_width = (STACKWIN_WIDTH * cwidth);
int scrollbar_width = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, this);
SetScrollbars(cwidth, cheight, STACKWIN_WIDTH, 256);
wxSize csz;
csz.Set(client_width + scrollbar_width + 1, cheight);
SetClientSize(csz);
SetMinClientSize(csz);
}
#if 0
void StackWindow::SetRunning (bool isRunning)
{
running = isRunning;
if (isRunning == false)
initial = true;
}
#endif
void StackWindow::OnPaint (wxPaintEvent& WXUNUSED(event))
{
char foo[16];
wxPaintDC dc(this);
PrepareDC(dc);
dc.SetFont(GetFont());
int cw, ch;
GetClientSize(&cw, &ch);
ch /= cheight;
int vx, vy;
GetViewStart(&vx, &vy);
#if 0
if (running || initial)
#else
if (initial)
#endif
{
initial = false;
// position (line number) of top-of-stack in virtual window
int spos = 0xFF - S;
// if top-of-stack is not (completely) in the visible window
if (spos < vy || spos >= (vy + ch))
{
// vh = number of lines in virtual window
int vw, vh;
GetVirtualSize(&vw, &vh);
vh /= cheight;
// if, when scrolled all the way down, top-of-stack is in window
// then scroll all the way down
// else if it is possible to scroll such that t-o-s is centered
// then scroll such that t-o-s is centered.
if ((vh - spos) < ch)
Scroll(0, vh - ch);
else if (spos >= (ch / 2))
Scroll(0, spos - (ch/2));
GetViewStart(&vx, &vy);
}
// set firstaddr & lastaddr
lastaddr = 0x1FF - vy;
firstaddr = 0x1FF - (vy + ch);
if (firstaddr < 0x100) firstaddr = 0x100;
}
for (int idx = vy; idx <= (vy + ch); ++idx)
{
int addr = 0x1FF - idx;
if (addr >= 0x100)
{
sprintf(foo, "%4.4x: %2.2x", addr, READ(addr));
if ((addr & 0xff) == S)
{
dc.SetBrush(*wxBLACK_BRUSH);
dc.DrawRectangle(0, idx*cheight, cw, cheight);
dc.SetTextForeground(*wxWHITE);
dc.DrawText(wxString::FromAscii(foo), 2*cwidth, idx*cheight);
dc.SetTextForeground(*wxBLACK);
}
else
{
dc.DrawText(wxString::FromAscii(foo), 2*cwidth, idx*cheight);
}
}
}
}
void StackWindow::TellNewValue (unsigned char b)
{
initial = true;
Refresh(FALSE);
}
void StackWindow::TellNewValue (unsigned short addr, unsigned char byte)
{
if (firstaddr >= lastaddr) return;
if (addr < firstaddr) return;
if (addr > lastaddr) return;
int cw, ch;
GetClientSize(&cw, &ch);
int y = cheight * (lastaddr - addr);
initial = true;
RefreshRect(wxRect(0, y, cw, cheight));
}
void StackWindow::ForceRefresh (void)
{
initial = true;
Refresh();
}
// end