aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorTechnus <daniel112092@gmail.com>2019-07-24 22:50:18 +0200
committerTechnus <daniel112092@gmail.com>2019-07-24 22:50:18 +0200
commit4979e5460a6edeabfb089b1af9f00337952bf65f (patch)
treef28fe6a8062d182da4616f07fabc625869b0505e /src/main/java/com
parent9c0ed5651b40d644a9ec9c961baf4cdd66402eb9 (diff)
downloadGT5-Unofficial-4979e5460a6edeabfb089b1af9f00337952bf65f.tar.gz
GT5-Unofficial-4979e5460a6edeabfb089b1af9f00337952bf65f.tar.bz2
GT5-Unofficial-4979e5460a6edeabfb089b1af9f00337952bf65f.zip
this should make the microcontroller chooch
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java42
1 files changed, 38 insertions, 4 deletions
diff --git a/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java b/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java
index 394f1272dc..3167bf820d 100644
--- a/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java
+++ b/src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java
@@ -2,16 +2,25 @@ package com.github.technus.tectech.thing.tileEntity;
import com.github.technus.avrClone.AvrCore;
import com.github.technus.avrClone.instructions.ExecutionEvent;
+import com.github.technus.avrClone.instructions.Instruction;
import com.github.technus.avrClone.instructions.InstructionRegistry;
+import com.github.technus.avrClone.instructions.exceptions.DebugEvent;
+import com.github.technus.avrClone.instructions.exceptions.DelayEvent;
import com.github.technus.avrClone.memory.EepromMemory;
import com.github.technus.avrClone.memory.RemovableMemory;
import com.github.technus.avrClone.memory.program.ProgramMemory;
+import com.github.technus.tectech.TecTech;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class MicroControllerTileEntity extends TileEntity {
+ static {
+ Instruction.random= TecTech.RANDOM;
+ }
private final AvrCore core;
private int[] tempData;
+ private boolean debugRun;
+ private int delay;
public MicroControllerTileEntity(){
core=new AvrCore();
@@ -24,6 +33,10 @@ public class MicroControllerTileEntity extends TileEntity {
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
+ debugRun=tag.getBoolean("debugRun");
+ delay=tag.getInteger("delay");
+ core.active =tag.getBoolean("active");
+ core.awoken=(tag.getBoolean("awoken"));
core.programCounter=tag.getInteger("programCounter");
if(tag.hasKey("instructions")){
int[] instructions=tag.getIntArray("instructions");
@@ -45,6 +58,10 @@ public class MicroControllerTileEntity extends TileEntity {
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
+ tag.setBoolean("debugRun",debugRun);
+ tag.setInteger("delay",delay);
+ tag.setBoolean("active",core.active);
+ tag.setBoolean("awoken",core.awoken);
tag.setInteger("programCounter",core.programCounter);
ProgramMemory programMemory=core.getProgramMemory();
if(programMemory!=null){
@@ -74,10 +91,27 @@ public class MicroControllerTileEntity extends TileEntity {
core.dataMemory = tempData;
tempData = null;
}
- for (int i = 0, cycles = Math.min(1 << getBlockMetadata(), 512); i < cycles; i++) {
- ExecutionEvent executionEvent = core.cpuCycle();
- if (executionEvent != null) {
- break;
+ if (core.active) {
+ core.interruptsHandle();
+ if (core.awoken) {
+ delay=0;
+ for (int i = 0, cycles = Math.min(1 << getBlockMetadata(), 512); i < cycles; i++) {
+ ExecutionEvent executionEvent = core.cpuCycleForce();
+ if (executionEvent != null) {
+ if (executionEvent.throwable instanceof DelayEvent) {
+ delay = executionEvent.data[0];
+ break;
+ } else if (debugRun && executionEvent.throwable instanceof DebugEvent) {
+ core.active = false;
+ break;
+ }
+ }
+ }
+ }else if(delay>0){
+ delay--;
+ if(delay==0){
+ core.awoken=true;
+ }
}
}
}