Skip to content

Commit 29103bb

Browse files
ausbinsameer-s
authored andcommitted
Add docs, error handling for my rushed work from 2 years ago
1 parent 6e0925c commit 29103bb

10 files changed

Lines changed: 295 additions & 100 deletions

File tree

src/main/java/io/zucchini/circuitsimtester/api/BaseMemory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
import java.io.InputStream;
44
import java.util.Scanner;
55

6+
/**
7+
* Base class inherited by {@link Ram} and {@link Rom}. Handles loading {@code
8+
* .dat}s exported from CircuitSim from an {@link InputStream}.
9+
*/
610
public abstract class BaseMemory {
711
public abstract void store(int address, int value);
812

13+
// TODO: Provide some mechanism in CircuitSimExtension to open a file
14+
// and preload it into RAM/ROM
915
/**
1016
* Loads a stream of a dat file into this component's memory. Format
1117
* is the same as the .dat files saved in the CircuitSim memory

src/main/java/io/zucchini/circuitsimtester/api/Button.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
package io.zucchini.circuitsimtester.api;
22

3-
// TODO FIXME document
3+
/**
4+
* Allows pretending to push a button placed in a subcircuit.
5+
* <p>
6+
* (In reality, this manipulates an InputPin wired to where the button was;
7+
* see {@link MockPulser})
8+
*/
49
public class Button extends MockPulser {
510
public Button(InputPin mockPin, Subcircuit subcircuit) {
611
super(mockPin, subcircuit);
712
}
813

14+
/**
15+
* This pushes the button. Crazy, right?
16+
*/
917
public void press() {
1018
pulse();
1119
}

src/main/java/io/zucchini/circuitsimtester/api/Clock.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,35 @@
22

33
import java.util.function.BooleanSupplier;
44

5-
// TODO FIXME document
5+
/**
6+
* Allows pretending to tick a Clock component placed in a subcircuit.
7+
* <p>
8+
* (In reality, this manipulates an InputPin wired to where the clock component was;
9+
* see {@link MockPulser})
10+
*/
611
public class Clock extends MockPulser {
712
public Clock(InputPin mockPin, Subcircuit subcircuit) {
813
super(mockPin, subcircuit);
914
}
1015

16+
/**
17+
* Tick the clock once.
18+
*/
1119
public void tick() {
1220
pulse();
1321
}
1422

23+
/**
24+
* Tick the clock until {@code stopWhen} returns true.
25+
*
26+
* @param maxCycleCount the number of cycles before timeout (to avoid
27+
* infinitely spinning)
28+
* @param stopWhen returns true when we can stop ticking the clock (e.g.,
29+
* the student's processor has finished running and is
30+
* sending the "done" signal)
31+
* @return the number of ticks performed until stopWhen returned true. May
32+
* be zero if the condition was initially met
33+
*/
1534
public long tickUntil(long maxCycleCount, BooleanSupplier stopWhen) {
1635
long ticks = 0;
1736
while (!stopWhen.getAsBoolean()) {

src/main/java/io/zucchini/circuitsimtester/api/MockPulser.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
package io.zucchini.circuitsimtester.api;
22

3-
// TODO FIXME document
3+
/**
4+
* Similar to {@link MockRegister} but much simpler: manipulates an InputPin
5+
* which replaced a clock or button and is used to send "pulses" into the
6+
* circuit. By "pulse", I mean an input like this:
7+
* <pre>
8+
* 1 _
9+
* | |
10+
* | |
11+
* | |
12+
* 0 __________| |___________
13+
*
14+
* Time ---&gt;
15+
* </pre>
16+
* Notice that could be a button press or the rising edge of the clock signal
17+
* (in CircuitSim we do not have to worry about propagation delay, thank God),
18+
* hence this is a base class used for {@link Button} and {@link Clock}. Those
19+
* classes have their own more specialized methods for sending pulses that
20+
* ultimately call {@link #pulse()}.
21+
*/
422
public abstract class MockPulser {
523
protected InputPin mockPin;
624
protected Subcircuit subcircuit;
@@ -18,6 +36,10 @@ public Subcircuit getSubcircuit() {
1836
return subcircuit;
1937
}
2038

39+
/**
40+
* Set the mock pin to 0, then 1, then 0 again to simulate the "pulse"
41+
* drawn above in the lede.
42+
*/
2143
protected void pulse() {
2244
mockPin.set(0b0);
2345
mockPin.set(0b1);

src/main/java/io/zucchini/circuitsimtester/api/Register.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,25 @@ public com.ra4king.circuitsim.simulator.components.memory.Register getRegister()
6060
return reg;
6161
}
6262

63-
// TODO FIXME document
63+
/**
64+
* Mocks this register with a {@link MockRegister}. See {@link
65+
* MockRegister} and {@link
66+
* Subcircuit#mockRegister(com.ra4king.circuitsim.simulator.components.memory.Register)}
67+
* for details.
68+
* <p>
69+
* You probably <b>should not be calling this directly</b> — use the
70+
* following code instead and let {@link
71+
* io.zucchini.circuitsimtester.extension.CircuitSimExtension} handle this
72+
* for you:
73+
* <pre>
74+
* {@literal @}SubcircuitComponent(bits=16)
75+
* private MockRegister myFunRegister;
76+
* </pre>
77+
*
78+
* @return a mocked version of this register
79+
* @see MockRegister
80+
* @see Subcircuit#mockRegister(com.ra4king.circuitsim.simulator.components.memory.Register)
81+
*/
6482
public MockRegister mock() {
6583
return subcircuit.mockRegister(reg);
6684
}

src/main/java/io/zucchini/circuitsimtester/api/Rom.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.ra4king.circuitsim.simulator.components.memory.ROM;
44

55
/**
6-
* Wraps a CircuitSim RAM component.
6+
* Wraps a CircuitSim ROM component.
77
*
88
* @author Austin Adams
99
*/
@@ -12,10 +12,10 @@ public class Rom extends BaseMemory {
1212
private Subcircuit subcircuit;
1313

1414
/**
15-
* Creates a new Ram which wraps the provided {@code RAM}
15+
* Creates a new Rom which wraps the provided {@code ROM}
1616
* component and which lives in the provided {@code Subcircuit}.
1717
*
18-
* @param rom {@code RAM} component to wrap
18+
* @param rom {@code ROM} component to wrap
1919
* @param subcircuit where this pin lives
2020
*/
2121
public Rom(ROM rom, Subcircuit subcircuit) {
@@ -30,13 +30,13 @@ public void store(int address, int value) {
3030
}
3131

3232
/**
33-
* Returns the internal CircuitSim {@code RAM} component this
33+
* Returns the internal CircuitSim {@code ROM} component this
3434
* object wraps.
3535
* <p>
3636
* <b>This exposes an internal CircuitSim API. Do not use unless you
3737
* know what you are doing.</b>
3838
*
39-
* @return the CircuitSim {@code RAM} component wrapped by this
39+
* @return the CircuitSim {@code ROM} component wrapped by this
4040
* object.
4141
*/
4242
public ROM getROM() {

0 commit comments

Comments
 (0)