summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/ccpu.h
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-05-14 18:58:48 +0200
committermanuel <manuel@nc8430.lan>2009-05-14 18:58:48 +0200
commit53b68ac658569dea3f5a26745dacf2a9aca0b266 (patch)
tree269af83394e84e2a7142dde87fb15dce413aa5c9 /ue3/mycpu/ccpu.h
parentddf63e2765a6b225d18c59321595e69e1a126e0c (diff)
parent3563c6dfd0f5f102cb748ecc6ad318601990515e (diff)
downloadooprog-53b68ac658569dea3f5a26745dacf2a9aca0b266.tar.gz
ooprog-53b68ac658569dea3f5a26745dacf2a9aca0b266.tar.bz2
ooprog-53b68ac658569dea3f5a26745dacf2a9aca0b266.zip
trying merging cpu-mm with default branch
Diffstat (limited to 'ue3/mycpu/ccpu.h')
-rw-r--r--ue3/mycpu/ccpu.h235
1 files changed, 200 insertions, 35 deletions
diff --git a/ue3/mycpu/ccpu.h b/ue3/mycpu/ccpu.h
index 68a4b8d..6849623 100644
--- a/ue3/mycpu/ccpu.h
+++ b/ue3/mycpu/ccpu.h
@@ -1,50 +1,43 @@
1/** 1/**
2 * @module ccpu 2 * @module ccpu
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) 3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief class for parsing simple scriptfiles 4 * @brief CPU implementation. Used as a container for memory and instructions.
5 * @date 17.04.2009 5 * Implements a run method to execute the program (= the instructions).
6 * @date 10.05.2009
6 */ 7 */
7 8
8#ifndef CCPU_H 9#ifndef CCPU_H
9#define CCPU_H 10#define CCPU_H 1
10 11
11#include <stdexcept> 12#include <iostream>
12#include <string> 13#include <set>
13#include <vector> 14#include "cdat.h"
14
15#include "cprogram.h"
16#include "cmem.h" 15#include "cmem.h"
17#include "cinstruction.h" 16#include "cprogram.h"
17#include "cdisplay.h"
18
18/** 19/**
19 * @class CCPU 20 * @class CCPU
20 * 21 *
21 * Parses a simple line based scriptfile with some limitations: 22 * CPU implementation. Used as a container for memory and instructions.
22 * first function (starting a block) must be a read-command, 23 * Implements a run method to execute the program (= the instructions).
23 * last must be a write-command (ending this block).
24 *
25 * read- and write-commands have hard coded parameters, number#1 being a filetype.
26 * Classes handling certain filetypes must be of type CFile.
27 * Custom functions will be passed to CFile::callFunc().
28 *
29 * On error ParserError will be thrown.
30 */ 24 */
31class CCPU 25class CCPU
32{ 26{
33 public: 27 public:
34
35
36 /** 28 /**
37 * @method CScriptparser 29 * @method CCPU
38 * @brief Default ctor 30 * @brief Default ctor
39 * @param scriptfile filename of script to parse 31 * @param cnt number of registers to allocate for this cpu
40 * @return - 32 * @return -
41 * @globalvars none 33 * @globalvars none
42 * @exception bad_alloc 34 * @exception none
43 * @conditions none 35 * @conditions none
44 */ 36 */
45 CCPU(const std::string& progfile, const std::string& memfile); 37 CCPU(const unsigned cnt);
38
46 /** 39 /**
47 * @method ~CScriptparser 40 * @method ~CCPU
48 * @brief Default dtor 41 * @brief Default dtor
49 * @param - 42 * @param -
50 * @return - 43 * @return -
@@ -54,21 +47,193 @@ class CCPU
54 */ 47 */
55 ~CCPU(); 48 ~CCPU();
56 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 }
57 147
58 void proceed(); 148 /**
59 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 }
60 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
61 227
62 void execInstruction( CInstruction& instr, std::vector<std::string>& i_list);
63 private: 228 private:
64 /* members */ 229 /* members */
65 230 CDat *m_registers;
66 CProgram m_program; 231 unsigned m_regcnt;
67 CMem m_memory; 232 CMem *m_memory;
68 std::map<std::string, CInstruction *> m_instrHandler; 233 const CProgram *m_program;
69 bool f_zero, f_sign; 234 std::set<CDisplay *> m_displays;
70 // std::string m_memfiler; 235 bool m_flagzero;
71 236 bool m_flagsign;
72}; 237};
73 238
74#endif 239#endif