summaryrefslogtreecommitdiffstats
path: root/ue4/mycpu/ccpu.h
diff options
context:
space:
mode:
Diffstat (limited to 'ue4/mycpu/ccpu.h')
-rw-r--r--ue4/mycpu/ccpu.h241
1 files changed, 241 insertions, 0 deletions
diff --git a/ue4/mycpu/ccpu.h b/ue4/mycpu/ccpu.h
new file mode 100644
index 0000000..6849623
--- /dev/null
+++ b/ue4/mycpu/ccpu.h
@@ -0,0 +1,241 @@
1/**
2 * @module ccpu
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief CPU implementation. Used as a container for memory and instructions.
5 * Implements a run method to execute the program (= the instructions).
6 * @date 10.05.2009
7 */
8
9#ifndef CCPU_H
10#define CCPU_H 1
11
12#include <iostream>
13#include <set>
14#include "cdat.h"
15#include "cmem.h"
16#include "cprogram.h"
17#include "cdisplay.h"
18
19/**
20 * @class CCPU
21 *
22 * CPU implementation. Used as a container for memory and instructions.
23 * Implements a run method to execute the program (= the instructions).
24 */
25class CCPU
26{
27 public:
28 /**
29 * @method CCPU
30 * @brief Default ctor
31 * @param cnt number of registers to allocate for this cpu
32 * @return -
33 * @globalvars none
34 * @exception none
35 * @conditions none
36 */
37 CCPU(const unsigned cnt);
38
39 /**
40 * @method ~CCPU
41 * @brief Default dtor
42 * @param -
43 * @return -
44 * @globalvars none
45 * @exception none
46 * @conditions none
47 */
48 ~CCPU();
49
50 /**
51 * @method getRegisterCount
52 * @brief get number of registers
53 * @param -
54 * @return number of registers
55 * @globalvars none
56 * @exception none
57 * @conditions none
58 */
59 const unsigned getRegisterCount() const
60 {
61 return m_regcnt;
62 }
63
64 /**
65 * @method getRegisters
66 * @brief get pointer to registers array
67 * @param -
68 * @return pointer to registers array
69 * @globalvars none
70 * @exception none
71 * @conditions none
72 */
73 CDat *getRegisters() const
74 {
75 return m_registers;
76 }
77
78 /**
79 * @method setMemory
80 * @brief set memory of cpu
81 * @param memory pointer to memory
82 * @return -
83 * @globalvars none
84 * @exception none
85 * @conditions none
86 */
87 void setMemory(CMem *memory)
88 {
89 m_memory = memory;
90 }
91
92 /**
93 * @method getMemory
94 * @brief get pointer to memory
95 * @param -
96 * @return pointer to memory
97 * @globalvars none
98 * @exception none
99 * @conditions none
100 */
101 CMem *getMemory() const
102 {
103 return m_memory;
104 }
105
106 /**
107 * @method setProgram
108 * @brief set program to execute
109 * @param program pointer to program
110 * @return -
111 * @globalvars none
112 * @exception none
113 * @conditions none
114 */
115 void setProgram(const CProgram *program)
116 {
117 m_program = program;
118 }
119
120 /**
121 * @method getProgram
122 * @brief get pointer to program
123 * @param -
124 * @return pointer to program
125 * @globalvars none
126 * @exception none
127 * @conditions none
128 */
129 const CProgram *getProgram()
130 {
131 return m_program;
132 }
133
134 /**
135 * @method getDisplays
136 * @brief get set of pointers to displays
137 * @param -
138 * @return reference to set of pointers to displays
139 * @globalvars none
140 * @exception none
141 * @conditions none
142 */
143 const std::set<CDisplay *>& getDisplays()
144 {
145 return m_displays;
146 }
147
148 /**
149 * @method setFlagZero
150 * @brief set zero flag
151 * @param value new value of zero flag
152 * @return -
153 * @globalvars none
154 * @exception none
155 * @conditions none
156 */
157 void setFlagZero(const bool value)
158 {
159 m_flagzero = value;
160 }
161
162 /**
163 * @method getFlagZero
164 * @brief get value of zero flag
165 * @param -
166 * @return value of zero flag
167 * @globalvars none
168 * @exception none
169 * @conditions none
170 */
171 const bool getFlagZero()
172 {
173 return m_flagzero;
174 }
175
176 /**
177 * @method setFlagSign
178 * @brief set sign flag
179 * @param value new value of sign flag
180 * @return -
181 * @globalvars none
182 * @exception none
183 * @conditions none
184 */
185 void setFlagSign(const bool value)
186 {
187 m_flagsign = value;
188 }
189
190 /**
191 * @method getFlagSign
192 * @brief get value of sign flag
193 * @param -
194 * @return value of sign flag
195 * @globalvars none
196 * @exception none
197 * @conditions none
198 */
199 const bool getFlagSign()
200 {
201 return m_flagsign;
202 }
203
204 /**
205 * @method run
206 * @brief execute current program
207 * @param -
208 * @return -
209 * @globalvars none
210 * @exception std::runtime_error
211 * @conditions none
212 */
213 void run();
214
215#if DEBUG
216 /**
217 * @method dumpRegisters
218 * @brief dump content of registers to outputstream
219 * @param out outputstream to write to
220 * @return void
221 * @globalvars none
222 * @exception none
223 * @conditions none
224 */
225 void dumpRegisters(std::ostream& out);
226#endif
227
228 private:
229 /* members */
230 CDat *m_registers;
231 unsigned m_regcnt;
232 CMem *m_memory;
233 const CProgram *m_program;
234 std::set<CDisplay *> m_displays;
235 bool m_flagzero;
236 bool m_flagsign;
237};
238
239#endif
240
241/* vim: set et sw=2 ts=2: */