Debian Codegraph @

extras/graphic_lcd/src/sed1520.cc

raw
1 /*
2 Copyright (C) 2005 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 #include <config.h>
22 #ifdef HAVE_GUI
23
24 #define IN_MODULE
25
26 #include <cstdio>
27 #include <cstdlib>
28
29 #include "sed1520.h"
30
31 //------------------------------------------------------------------------
32 SED1520::SED1520()
33 : m_bE(true), m_controlState(0), m_dataBus(0),
34 m_page(0), m_columnAddress(0)
35 {
36 randomizeRAM();
37 }
38
39
40 //------------------------------------------------------------------------
41 void SED1520::setA0(bool newA0)
42 {
43 m_controlState &= ~eA0;
44 m_controlState |= (newA0 ? eA0 : 0);
45 }
46
47
48 void SED1520::setRW(bool newRW)
49 {
50 m_controlState &= ~eRW;
51 m_controlState |= (newRW ? eRW : 0);
52 }
53
54
55 void SED1520::setE(bool newE)
56 {
57 if (m_bE != newE && newE) {
58 switch (m_controlState) {
59 case eDataRead:
60 driveDataBus(getData());
61 advanceColumnAddress();
62 break;
63
64 case eDataWrite:
65 storeData();
66 advanceColumnAddress();
67 break;
68
69 case eStatusRead:
70 driveDataBus(getStatus());
71 break;
72
73 case eCommandWrite:
74 executeCommand();
75 break;
76 }
77 }
78
79 m_bE = newE;
80 }
81
82
83 void SED1520::setData(unsigned int d)
84 {
85 m_dataBus = d;
86 }
87
88
89 void SED1520::driveDataBus(unsigned int d)
90 {
91 m_dataBus = d;
92 }
93
94
95 void SED1520::advanceColumnAddress()
96 {
97 m_columnAddress += (m_columnAddress < eNCOLUMNS_PER_PAGE) ? 1 : 0;
98 }
99
100
101 void SED1520::storeData()
102 {
103 m_ram[eNCOLUMNS_PER_PAGE * m_page + m_columnAddress] = m_dataBus;
104 }
105
106
107 unsigned int SED1520::getData()
108 {
109 m_dataBus = m_ram[eNCOLUMNS_PER_PAGE * m_page + m_columnAddress];
110 return m_dataBus;
111 }
112
113
114 unsigned int SED1520::getStatus()
115 {
116 return 0;
117 }
118
119
120 void SED1520::executeCommand()
121 {
122 // decode the command
123 if ((m_dataBus & 0x80) == 0) {
124 // Set column address
125 m_columnAddress = (m_dataBus & 0x7f) % eNCOLUMNS_PER_PAGE;
126
127 } else {
128 if ((m_dataBus & 0x7C) == 0x38)
129 // set Page Address
130 {
131 m_page = m_dataBus & 3;
132 }
133 }
134 }
135
136
137 //------------------------------------------------------------------------
138 bool SED1520::dataBusDirection()
139 {
140 return (m_controlState & (eE | eRW)) == (eE | eRW);
141 }
142
143
144 //------------------------------------------------------------------------
145 unsigned int SED1520::getDataBus()
146 {
147 return m_dataBus;
148 }
149
150
151 //------------------------------------------------------------------------
152
153 void SED1520::randomizeRAM()
154 {
155 for (unsigned int i = 0; i < eNCOLUMNS_PER_PAGE * eNPAGES; i++) {
156 m_ram[i] = (rand() >> 8) & 0xff;
157 }
158 }
159
160
161 //------------------------------------------------------------------------
162 // prBadRam - private function called when ever an illegal access is made
163 // to the RAM
164 unsigned int &SED1520::prBadRam(unsigned int index)
165 {
166 static unsigned int si;
167 printf("WARNING SED1520 - illegal RAM access index=%u\n", index);
168 return si;
169 }
170
171 #endif // HAVE_GUI