aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorTechnus <daniel112092@gmail.com>2019-07-24 13:10:31 +0200
committerTechnus <daniel112092@gmail.com>2019-07-24 13:10:31 +0200
commit9c0ed5651b40d644a9ec9c961baf4cdd66402eb9 (patch)
tree1555ccf34d8aa4b48228b59e60bb611ee4e97c16 /src/main/java
parent42f082bc0bc3f27775ea3a3f45995487e93a6d5e (diff)
downloadGT5-Unofficial-9c0ed5651b40d644a9ec9c961baf4cdd66402eb9.tar.gz
GT5-Unofficial-9c0ed5651b40d644a9ec9c961baf4cdd66402eb9.tar.bz2
GT5-Unofficial-9c0ed5651b40d644a9ec9c961baf4cdd66402eb9.zip
persistence?
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/github/technus/tectech/thing/tileEntity/MicroControllerTileEntity.java63
1 files changed, 46 insertions, 17 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 d4cb8afb0f..394f1272dc 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
@@ -1,42 +1,63 @@
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.InstructionRegistry;
+import com.github.technus.avrClone.memory.EepromMemory;
+import com.github.technus.avrClone.memory.RemovableMemory;
import com.github.technus.avrClone.memory.program.ProgramMemory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class MicroControllerTileEntity extends TileEntity {
- public final AvrCore core;
+ private final AvrCore core;
+ private int[] tempData;
public MicroControllerTileEntity(){
- core=new AvrCore(InstructionRegistry.INSTRUCTION_REGISTRY_OP,false);
+ core=new AvrCore();
+ core.setUsingImmersiveOperands(false);
+ core.setInstructionRegistry(InstructionRegistry.INSTRUCTION_REGISTRY_OP);
+ core.setDataMemory(1<<getBlockMetadata(),1<<getBlockMetadata());
+ core.setCpuRegisters(0x30);
}
@Override
public void readFromNBT(NBTTagCompound tag) {
super.readFromNBT(tag);
core.programCounter=tag.getInteger("programCounter");
- if(core.getProgramMemory()!=null){
- ProgramMemory programMemory=core.getProgramMemory();
- NBTTagCompound program=new NBTTagCompound();
- program.setIntArray("instructions",programMemory.instructions);
- program.setIntArray("param0",programMemory.param0);
- program.setIntArray("param1",programMemory.param1);
- tag.setTag("program",program);
+ if(tag.hasKey("instructions")){
+ int[] instructions=tag.getIntArray("instructions");
+ int[] param0=tag.getIntArray("param0");
+ int[] param1=tag.getIntArray("param1");
+ core.setProgramMemory(new ProgramMemory(
+ core.getInstructionRegistry(),core.isUsingImmersiveOperands(),
+ instructions,param0,param1));
}
+ if(tag.hasKey("eepromSize")){
+ core.setEepromDefinition(EepromMemory.make(tag.getInteger("eepromSize")));
+ }
+ if(tag.hasKey("dataMemory")){
+ tempData=tag.getIntArray("dataMemory");
+ }
+ core.checkValid();
}
@Override
public void writeToNBT(NBTTagCompound tag) {
super.writeToNBT(tag);
tag.setInteger("programCounter",core.programCounter);
- if(tag.hasKey("program")){
- NBTTagCompound program=tag.getCompoundTag("program");
- int[] instructions=program.getIntArray("instructions");
- int[] param0=program.getIntArray("param0");
- int[] param1=program.getIntArray("param1");
- //core.setProgramMemory(new ProgramMemory(instructions,param0,param1,core.getInstructionRegistry()));
+ ProgramMemory programMemory=core.getProgramMemory();
+ if(programMemory!=null){
+ tag.setIntArray("instructions",programMemory.instructions);
+ tag.setIntArray("param0",programMemory.param0);
+ tag.setIntArray("param1",programMemory.param1);
+ }
+ RemovableMemory<EepromMemory> eeprom=core.getEepromMemory();
+ if(eeprom!=null){
+ tag.setInteger("eepromSize",eeprom.getDefinition().getSize());
+ }
+ if(core.dataMemory!=null){
+ tag.setIntArray("dataMemory",core.dataMemory);
}
}
@@ -48,8 +69,16 @@ public class MicroControllerTileEntity extends TileEntity {
@Override
public void updateEntity() {
super.updateEntity();
- if(core.checkValid()){
-
+ if (tempData != null) {
+ //todo discovery of components
+ 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;
+ }
}
}
}