1111
1212using namespace std ;
1313
14- void randFunc (int a) {
15- cout << " Here is a button action! " << a << endl;
16- }
17-
1814int main (int argc, char * args[]) {
1915 // Variables
2016 Logger logger;
@@ -31,17 +27,15 @@ int main(int argc, char* args[]) {
3127 Uint8 cursorState = 0 ; // 0 -> normal, 1 -> hover, 2 -> normal clicked, 3 -> hover clicked
3228 Cursor cursor = JsonManager::getCursor ();
3329 vector<HitBox2d> hitboxes = {HitBox2d (0 , 0 , 10 , 10 ), HitBox2d (0 , 100 , 16 , 16 )}; // Vector of all hitboxes
34- Uint8 inHitboxes = 0 ;
35- bool clicked = false ;
30+ Uint8 inHitboxes = 0 , phaseNow, phaseNext ;
31+ bool clicked = false , refresh = true , constantRefresh = false ;
3632
3733 // Interpreter
3834 SystemBus SB;
3935 CentralMemory CM (&SB, settings.interpreter .ramSize );
4036 InputOutputDevices IOD (&SB);
4137 CentralProcessingUnit CPU (&SB, &CM, &IOD, settings.interpreter .start );
4238 CM.loadProgram (settings.interpreter .file , settings.interpreter .binary , &logger);
43- CPU.fetchInstruction ();
44- CPU.decodeInstruction ();
4539
4640 // Capturing cout in log file
4741 if (settings.console .log ) freopen (" log.txt" , " w" , stdout);
@@ -205,27 +199,52 @@ int main(int argc, char* args[]) {
205199 if (cursorState >= 2 ) fastButton.changePressed ();
206200 else fastButton.changeNormal ();
207201 inHitboxes++;
202+ if (clicked) constantRefresh = true ;
208203 }
209204 if (guiCursorPosition == *playButton.getHitBox ()) {
210205 if (cursorState >= 2 ) playButton.changePressed ();
211206 else playButton.changeNormal ();
212207 inHitboxes++;
213- if (clicked) playButton. action (randFunc) ;
208+ if (clicked) refresh = true ;
214209 }
215210 if (guiCursorPosition == *nextButton.getHitBox ()) {
216211 if (cursorState >= 2 ) nextButton.changePressed ();
217212 else nextButton.changeNormal ();
218213 inHitboxes++;
214+ if (clicked) {
215+ refresh = true ;
216+ switch (phaseNext) {
217+ case 0 :
218+ CPU.fetchInstruction ();
219+ break ;
220+ case 1 :
221+ CPU.decodeInstruction ();
222+ break ;
223+ case 2 :
224+ CPU.fetchOperand ();
225+ break ;
226+ case 3 :
227+ CPU.executeInstruction ();
228+ }
229+ }
219230 }
220231 if (guiCursorPosition == *pauseButton.getHitBox ()) {
221232 if (cursorState >= 2 ) pauseButton.changePressed ();
222233 else pauseButton.changeNormal ();
223234 inHitboxes++;
235+ if (clicked) {
236+ constantRefresh = false ;
237+ refresh = true ;
238+ }
224239 }
225240 if (guiCursorPosition == *stopButton.getHitBox ()) {
226241 if (cursorState >= 2 ) stopButton.changePressed ();
227242 else stopButton.changeNormal ();
228243 inHitboxes++;
244+ if (clicked) {
245+ constantRefresh = false ;
246+ refresh = true ;
247+ }
229248 }
230249 if (inHitboxes > 0 ) {
231250 if (cursorState == 0 ) cursorState = 1 ;
@@ -243,13 +262,22 @@ int main(int argc, char* args[]) {
243262 }
244263
245264 instNameValue = CPU.getInstName ();
246- // CPU Values
247- pcValue = " 0x" + math::Uint16Tohexstr (CPU.getPC ());
248- irValue = " 0x" + math::Uint16Tohexstr (CPU.getIR ());
249- srValue = math::StatusRegisterToHexstr (CPU.getSR ());
250- arValue = " 0x" + math::Uint16Tohexstr (CPU.getAR ());
251- drValue = " 0x" + math::Uint16Tohexstr (CPU.getDR ());
252- spValue = " 0x" + math::Uint16Tohexstr (CPU.getSP ());
265+ if (refresh || constantRefresh) {
266+ // CPU Values
267+ pcValue = " 0x" + math::Uint16Tohexstr (CPU.getPC ());
268+ irValue = " 0x" + math::Uint16Tohexstr (CPU.getIR ());
269+ srValue = math::StatusRegisterToHexstr (CPU.getSR ());
270+ arValue = " 0x" + math::Uint16Tohexstr (CPU.getAR ());
271+ drValue = " 0x" + math::Uint16Tohexstr (CPU.getDR ());
272+ spValue = " 0x" + math::Uint16Tohexstr (CPU.getSP ());
273+ refresh = false ;
274+ for (Uint8 i = 0 ; i < 16 ; i++) {
275+ registriesValues[i] = " 0x" + math::Uint16Tohexstr (CPU.getR (i));
276+ }
277+ CPU.getPhases (phaseNow, phaseNext);
278+ progressBarNowEntity.setX (178 + 8 * phaseNow);
279+ progressBarNextEntity.setX (178 + 8 * phaseNext);
280+ }
253281 // GUI backgrounds
254282 Window.renderGui (cpuGui);
255283 // CPU Render
@@ -283,8 +311,12 @@ int main(int argc, char* args[]) {
283311 Window.renderText (progressBarOfTitle);
284312 Window.renderText (progressBarIeTitle);
285313 Window.renderGui (progressBarEntity);
286- Window.renderGui (progressBarNowEntity);
287- Window.renderGui (progressBarNextEntity);
314+ if (phaseNow < 4 ) {
315+ Window.renderGui (progressBarNowEntity);
316+ }
317+ if (phaseNext < 4 ) {
318+ Window.renderGui (progressBarNextEntity);
319+ }
288320 // Buttons
289321 Window.renderButton (fastButton);
290322 Window.renderButton (playButton);
0 commit comments