Skip to content

Commit e22e9cd

Browse files
authored
Add menu item to toggle trace mode on and off. (#129)
1 parent 3d906c6 commit e22e9cd

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

src/main/java/ca/craigthomas/yacoco3e/components/Emulator.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class Emulator extends Thread
3737
private JMenuBar menuBar;
3838

3939
/* State variables */
40-
private boolean trace;
40+
public boolean trace;
4141
private boolean verbose;
4242
private volatile EmulatorStatus status;
4343
private volatile int remainingTicks;
@@ -335,6 +335,18 @@ private void initEmulatorJFrame() {
335335

336336
menuBar.add(keyboardMenu);
337337

338+
// Debug menu
339+
JMenu debugMenu = new JMenu("Debugging");
340+
debugMenu.setMnemonic(KeyEvent.VK_U);
341+
342+
JRadioButtonMenuItem traceMenuItem = new JRadioButtonMenuItem("Trace");
343+
traceMenuItem.setSelected(trace);
344+
debugMenu.add(traceMenuItem);
345+
346+
traceMenuItem.addActionListener(new SetTraceActionListener(this, traceMenuItem));
347+
348+
menuBar.add(debugMenu);
349+
338350
attachCanvas();
339351
}
340352

@@ -451,18 +463,14 @@ public void run() {
451463
/* Increment timers if necessary */
452464
io.timerTick(operationTicks);
453465

454-
// System.out.print(" new pc: " + ioController.regs.pc);
455-
456466
/* Fire interrupts if set */
457467
cpu.serviceInterrupts();
458468

459469
/* Check to see if we should trace the output */
460470
if (this.trace) {
461-
// System.out.print("PC:" + cpu.getLastPC() + " | OP:"
462-
// + cpu.getLastOperand() + " | " + cpu.instruction.getShortDescription());
463471
if (cpu.instruction != null) {
464472
System.out.print(cpu.instruction.getShortDescription());
465-
System.out.print(" new pc: " + io.regs.pc);
473+
System.out.print(" (New PC: " + io.regs.pc + ")");
466474
System.out.println();
467475
}
468476
}

src/main/java/ca/craigthomas/yacoco3e/listeners/SetPassthroughKeyboardActionListener.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ public void actionPerformed(ActionEvent e) {
3232
setPassthroughKeyboard();
3333
}
3434

35-
/**
36-
* Opens a dialog box to prompt the user to choose a cassette file
37-
* to open for playback.
38-
*/
3935
public void setPassthroughKeyboard() {
4036
emulator.switchKeyListener(new PassthroughKeyboard());
4137
emulated.setSelected(false);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2025 Craig Thomas
3+
* This project uses an MIT style license - see LICENSE for details.
4+
*/
5+
package ca.craigthomas.yacoco3e.listeners;
6+
7+
import ca.craigthomas.yacoco3e.components.Emulator;
8+
9+
import javax.swing.*;
10+
import java.awt.event.ActionEvent;
11+
import java.awt.event.ActionListener;
12+
13+
/**
14+
* An ActionListener that will start or stop debug tracing.
15+
*/
16+
public class SetTraceActionListener implements ActionListener
17+
{
18+
private Emulator emulator;
19+
private JRadioButtonMenuItem traceMenuItem;
20+
21+
public SetTraceActionListener(Emulator emulator, JRadioButtonMenuItem traceMenuItem) {
22+
super();
23+
this.emulator = emulator;
24+
this.traceMenuItem = traceMenuItem;
25+
}
26+
27+
@Override
28+
public void actionPerformed(ActionEvent e) {
29+
setTrace();
30+
}
31+
32+
public void setTrace() {
33+
emulator.trace = !emulator.trace;
34+
traceMenuItem.setSelected(emulator.trace);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)