forked from pdaxrom/pyldin2012
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vgasim.h
230 lines (186 loc) · 4.96 KB
/
vgasim.h
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
////////////////////////////////////////////////////////////////////////////////
//
// Filename: vgasim.h
//
// Project: vgasim, a Verilator based VGA simulator demonstration
//
// Purpose:
//
// Creator: Dan Gisselquist, Ph.D.
// Gisselquist Technology, LLC
//
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017, Gisselquist Technology, LLC
//
// This program is free software (firmware): 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.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY 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 this program. (It's in the $(ROOT)/doc directory. Run make with no
// target there if the PDF file isn't present.) If not, see
// <http://www.gnu.org/licenses/> for a copy.
//
// License: GPL, v3, as defined and found on www.gnu.org,
// http://www.gnu.org/licenses/gpl.html
//
//
////////////////////////////////////////////////////////////////////////////////
//
//
#ifndef VGASIM_H
#define VGASIM_H
#include <gtkmm.h>
#include "image.h"
#include "videomode.h"
class VGASIM : public Gtk::DrawingArea {
public:
// Type definitions ... just to make using these types easier and
// simpler on the fingers.
typedef Cairo::RefPtr<Cairo::Context> CAIROGC;
typedef const Cairo::RefPtr<Cairo::Context> CONTEXT;
typedef Cairo::RefPtr<Cairo::ImageSurface> CAIROIMG;
static const bool m_debug;
CAIROIMG m_pix;
CAIROGC m_gc;
IMAGE<unsigned> *m_data;
VIDEOMODE m_mode;
int m_vsync_count, m_hsync_count;
bool m_out_of_sync;
int m_last_vsync, m_last_hsync, m_last_r, m_last_g, m_last_b,
m_pixel_clock_count;
void initialize(void) {
m_data = new IMAGE<unsigned>(m_mode.height(), m_mode.width());
m_data->zeroize();
m_vsync_count = 0;
m_hsync_count = 0;
m_out_of_sync = true;
m_last_hsync = 1;
m_last_vsync = 1;
set_has_window(true);
Widget::set_can_focus(false);
set_size_request(m_mode.width(), m_mode.height());
}
public:
static const int CLOCKS_PER_PIXEL,
BITS_PER_COLOR;
VGASIM(void) : Gtk::DrawingArea(), m_mode(640,480) {
initialize();
}
VGASIM(const int w, const int h) : Gtk::DrawingArea(), m_mode(w, h) {
initialize();
}
VGASIM(const char *h, const char *v) : Gtk::DrawingArea(), m_mode(h,v) {
initialize();
}
void get_preferred_width_vfunc(int &min, int &nw) const;
void get_preferred_height_vfunc(int &min, int &nw) const;
void get_preferred_height_for_width_vfunc(int w, int &min, int &nw) const;
void get_preferred_width_for_height_vfunc(int w, int &min, int &nw) const;
#ifdef UNNECESSARY
virtual void on_show() {
if (m_debug)
printf("SHOW\n");
Gtk::DrawingArea::on_show();
printf("SHOWN\n");
}
virtual void on_hide() {
if (m_debug)
printf("HIDE\n");
Gtk::DrawingArea::on_hide();
}
virtual void on_map(void) {
if (m_debug)
printf("ON-MAP\n");
Gtk::Widget::on_map();
}
virtual void on_my_map(void) {
printf("ON-MY-MAP\n");
}
virtual void signal_map(void) {
if (m_debug)
printf("SIGNAL-MAP\n");
Gtk::DrawingArea::signal_map();
}
virtual bool on_configure_event(GdkEventConfigure *ev) {
if (m_debug)
printf("ON-CONFIGURE\n");
return Gtk::DrawingArea::on_configure_event(ev);
}
#endif
virtual void on_realize();
void operator()(const int vsync, const int hsync,
const int r, const int g, const int b);
virtual bool on_draw(CONTEXT &gc);
bool syncd(void) { return !m_out_of_sync; }
int width(void) {
return m_mode.width();
}
int height(void) {
return m_mode.height();
}
int raw_width(void) {
return m_mode.raw_width();
}
int raw_height(void) {
return m_mode.raw_height();
}
int hsync(void) {
return m_mode.hsync();
}
int vsync(void) {
return m_mode.vsync();
}
int hporch(void) {
return m_mode.hporch();
}
int vporch(void) {
return m_mode.vporch();
}
};
class VGAWIN : public Gtk::Window {
private:
VGASIM *m_vgasim;
void init(void);
public:
VGAWIN(void);
VGAWIN(const int w, const int h);
VGAWIN(const char *h, const char *v);
~VGAWIN(void) { delete m_vgasim; }
void operator()(const int vsync, const int hsync, const int r, const int g, const int b) {
(*m_vgasim)(vsync, hsync, r, g, b);
}
bool syncd(void) { return m_vgasim->syncd(); }
int width(void) {
return m_vgasim->width();
}
int height(void) {
return m_vgasim->height();
}
int raw_width(void) {
return m_vgasim->raw_width();
}
int raw_height(void) {
return m_vgasim->raw_height();
}
int hsync(void) {
return m_vgasim->hsync();
}
int vsync(void) {
return m_vgasim->vsync();
}
int hporch(void) {
return m_vgasim->hporch();
}
int vporch(void) {
return m_vgasim->vporch();
}
};
#endif