Skip to content

Commit

Permalink
Program counter register
Browse files Browse the repository at this point in the history
  • Loading branch information
ramidzkh authored and fnuecke committed Jul 10, 2021
1 parent 5a3df2c commit 8ed4bd1
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public MachineImpl(final ExecutionModule module, final Face face) {
this.state = new MachineState();
this.module = module;
this.interfaces = ImmutableMap.<Target, TargetInterface>builder().
put(Target.PC, new PcTargetInterface(this)).
put(Target.ACC, new AccTargetInterface(this)).
put(Target.BAK, new BakTargetInterface(this)).
put(Target.NIL, new NilTargetInterface(this)).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package li.cil.tis3d.common.module.execution.target;

import li.cil.tis3d.common.module.execution.Machine;

/**
* Interface for the {@link Target#PC} target.
* <p>
* Provides instant read and write on the program counter
*/
public final class PcTargetInterface extends AbstractTargetInterface {
public PcTargetInterface(final Machine machine) {
super(machine);
}

// --------------------------------------------------------------------- //
// TargetInterface

@Override
public boolean beginWrite(final short value) {
getState().pc = value;
return true;
}

@Override
public boolean isWriting() {
return false;
}

@Override
public void beginRead() {
}

@Override
public boolean isReading() {
return false;
}

@Override
public boolean canTransfer() {
return true;
}

@Override
public short read() {
return (short) getState().pc;
}

// --------------------------------------------------------------------- //
// Object

@Override
public String toString() {
return "PC";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Valid sources and sinks for move operations.
*/
public enum Target {
PC,
ACC,
BAK,
NIL,
Expand Down

0 comments on commit 8ed4bd1

Please sign in to comment.