| 1 |
/* |
| 2 |
Copyright (C) 2007 T. Scott Dattalo |
| 3 |
|
| 4 |
This file is part of gpsim. |
| 5 |
|
| 6 |
gpsim is free software; you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation; either version 2, or (at your option) |
| 9 |
any later version. |
| 10 |
|
| 11 |
gpsim is distributed in the hope that it will be useful, |
| 12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
GNU General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with gpsim; see the file COPYING. If not, write to |
| 18 |
the Free Software Foundation, 59 Temple Place - Suite 330, |
| 19 |
Boston, MA 02111-1307, USA. */ |
| 20 |
|
| 21 |
|
| 22 |
#include <config.h> |
| 23 |
|
| 24 |
#ifdef HAVE_GUI |
| 25 |
|
| 26 |
#include "glcd.h" |
| 27 |
#include <src/trace.h> |
| 28 |
|
| 29 |
//------------------------------------------------------------------------ |
| 30 |
gLCD::gLCD(unsigned int cols, |
| 31 |
unsigned int rows, |
| 32 |
unsigned int pixel_size_x, |
| 33 |
unsigned int pixel_size_y, |
| 34 |
unsigned int pixel_gap, |
| 35 |
unsigned int nColors |
| 36 |
) |
| 37 |
: m_nColumns(cols), m_nRows(rows), m_border(3), |
| 38 |
m_xPixel(pixel_size_x), m_yPixel(pixel_size_y), |
| 39 |
m_pixelGap(pixel_gap) |
| 40 |
{ |
| 41 |
m_nColors = nColors < 2 ? 2 : nColors; |
| 42 |
m_Colors = new LCDColor[m_nColors]; |
| 43 |
setColor(0, double(0x78) / 255.0, double(0xa8) / 255.0, double(0x78) / 255.0); |
| 44 |
setColor(1, double(0x11) / 255.0, double(0x33) / 255.0, double(0x11) / 255.0); |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
gLCD::~gLCD() |
| 49 |
{ |
| 50 |
delete [] m_Colors; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
void gLCD::clear(cairo_t *cr) |
| 55 |
{ |
| 56 |
double r = m_Colors[0].r; |
| 57 |
double g = m_Colors[0].g; |
| 58 |
double b = m_Colors[0].b; |
| 59 |
cairo_set_source_rgb(cr, r, g, b); |
| 60 |
cairo_rectangle(cr, 0.0, 0.0, |
| 61 |
m_xPixel * (m_nColumns + 2 * m_border), m_yPixel * (m_nRows + 2 * m_border)); |
| 62 |
cairo_fill(cr); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
void gLCD::setPixel(cairo_t *cr, unsigned int col, unsigned int row, double r, double g, double b) |
| 67 |
{ |
| 68 |
double x = (col + m_border) * m_xPixel; |
| 69 |
double y = (row + m_border) * m_yPixel; |
| 70 |
double px = m_xPixel - m_pixelGap; |
| 71 |
double py = m_yPixel - m_pixelGap; |
| 72 |
cairo_set_source_rgb(cr, r, g, b); |
| 73 |
cairo_set_line_width(cr, 0.5); |
| 74 |
cairo_rectangle(cr, x, y, px, py); |
| 75 |
cairo_fill(cr); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
void gLCD::setPixel(cairo_t *cr, unsigned int col, unsigned int row) |
| 80 |
{ |
| 81 |
if (col < m_nColumns && row < m_nRows) { |
| 82 |
double r = m_Colors[1].r; |
| 83 |
double g = m_Colors[1].g; |
| 84 |
double b = m_Colors[1].b; |
| 85 |
setPixel(cr, col, row, r, g, b); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
void gLCD::setPixel(cairo_t *cr, unsigned int col, unsigned int row, unsigned int colorIdx) |
| 91 |
{ |
| 92 |
if (colorIdx < m_nColors) { |
| 93 |
setPixel(cr, col, row, m_Colors[colorIdx].r, m_Colors[colorIdx].g, m_Colors[colorIdx].b); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
void gLCD::setColor(unsigned int colorIdx, double r, double g, double b) |
| 99 |
{ |
| 100 |
if (colorIdx < m_nColors) { |
| 101 |
m_Colors[colorIdx].r = r; |
| 102 |
m_Colors[colorIdx].g = g; |
| 103 |
m_Colors[colorIdx].b = b; |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
//======================================================================== |
| 109 |
// |
| 110 |
// LCD interface to the simulator |
| 111 |
// |
| 112 |
gLCD_Interface::gLCD_Interface(gLCD_Module *_lcd) |
| 113 |
: Interface((gpointer *) _lcd), plcd(_lcd) |
| 114 |
{ |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
//-------------------------------------------------- |
| 119 |
// SimulationHasStopped (gpointer) |
| 120 |
// |
| 121 |
// gpsim will call this function when the simulation |
| 122 |
// has halt (e.g. a break point was hit.) |
| 123 |
|
| 124 |
void gLCD_Interface::SimulationHasStopped(gpointer) |
| 125 |
{ |
| 126 |
if (plcd) { |
| 127 |
plcd->Update(); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
void gLCD_Interface::Update(gpointer) |
| 133 |
{ |
| 134 |
if (plcd) { |
| 135 |
plcd->Update(); |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
//======================================================================== |
| 141 |
// |
| 142 |
// |
| 143 |
|
| 144 |
gLCD_Module::gLCD_Module(const char *new_name, const char *desc, |
| 145 |
unsigned int nCols, unsigned int nRows) |
| 146 |
: Module(new_name, desc), |
| 147 |
window(nullptr), darea(nullptr), m_plcd(nullptr), |
| 148 |
m_nColumns(nCols), m_nRows(nRows) |
| 149 |
{ |
| 150 |
interface_seq_no = get_interface().add_interface(new gLCD_Interface(this)); |
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
gLCD_Module::~gLCD_Module() |
| 155 |
{ |
| 156 |
get_interface().remove_interface(interface_seq_no); |
| 157 |
delete m_plcd; |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
void gLCD_Module::Update(GtkWidget * ) |
| 162 |
{ |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
//======================================================================== |
| 167 |
// |
| 168 |
LcdPortRegister::LcdPortRegister(gLCD_Module *plcd, const char * _name, const char *_desc) |
| 169 |
: PortRegister(plcd, _name, _desc, 8, 0), m_pLCD(plcd) |
| 170 |
{ |
| 171 |
mMTT = new ModuleTraceType(plcd, 1, " Graphic LCD"); |
| 172 |
trace.allocateTraceType(mMTT); |
| 173 |
RegisterValue rv(mMTT->type(), mMTT->type() + (1 << 22)); |
| 174 |
set_write_trace(rv); |
| 175 |
rv = RegisterValue(mMTT->type() + (2 << 22), mMTT->type() + (3 << 22)); |
| 176 |
set_read_trace(rv); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
LcdPortRegister::~LcdPortRegister() |
| 181 |
{ |
| 182 |
delete mMTT; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
#endif //HAVE_GUI |