aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/github/technus/tectech/Converter.java59
-rw-r--r--src/main/java/com/github/technus/tectech/compatibility/openComputers/AvrArchitecture.java267
-rw-r--r--src/main/java/com/github/technus/tectech/loader/MainLoader.java8
-rw-r--r--src/main/java/com/github/technus/tectech/loader/gui/CreativeTabTecTech.java16
-rw-r--r--src/main/java/com/github/technus/tectech/loader/gui/ModGuiHandler.java4
-rw-r--r--src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java36
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/avr/SidedRedstone.java248
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/templates/cElementalPrimitive.java4
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/elementalMatter/core/transformations/bTransformationInfo.java38
-rw-r--r--src/main/java/com/github/technus/tectech/mechanics/elementalMatter/definitions/complex/dHadronDefinition.java57
-rw-r--r--src/main/java/com/github/technus/tectech/thing/CustomItemList.java4
-rw-r--r--src/main/java/com/github/technus/tectech/thing/block/QuantumGlassBlock.java2
-rw-r--r--src/main/java/com/github/technus/tectech/thing/casing/GT_Block_CasingsNH.java3
-rw-r--r--src/main/java/com/github/technus/tectech/thing/casing/GT_Block_CasingsTT.java3
-rw-r--r--src/main/java/com/github/technus/tectech/thing/casing/GT_Block_HintTT.java3
-rw-r--r--src/main/java/com/github/technus/tectech/thing/item/AvrProgrammer.java215
-rw-r--r--src/main/java/com/github/technus/tectech/thing/item/ConstructableTriggerItem.java2
-rw-r--r--src/main/java/com/github/technus/tectech/thing/item/DebugElementalInstanceContainer_EM.java8
-rw-r--r--src/main/java/com/github/technus/tectech/thing/item/ElementalDefinitionContainer_EM.java4
-rw-r--r--src/main/java/com/github/technus/tectech/thing/item/ElementalDefinitionScanStorage_EM.java4
-rw-r--r--src/main/java/com/github/technus/tectech/thing/item/EuMeterGT.java4
-rw-r--r--src/main/java/com/github/technus/tectech/thing/item/FrontRotationTriggerItem.java3
-rw-r--r--src/main/java/com/github/technus/tectech/thing/item/ParametrizerMemoryCard.java2
-rw-r--r--src/main/java/com/github/technus/tectech/thing/item/gui/ProgrammerScreen.java13
-rw-r--r--src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_DataReader.java2
-rw-r--r--src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_MicroController.java187
26 files changed, 1133 insertions, 63 deletions
diff --git a/src/main/java/com/github/technus/tectech/Converter.java b/src/main/java/com/github/technus/tectech/Converter.java
new file mode 100644
index 0000000000..5d1f5c802e
--- /dev/null
+++ b/src/main/java/com/github/technus/tectech/Converter.java
@@ -0,0 +1,59 @@
+package com.github.technus.tectech;
+
+import java.io.*;
+
+public final class Converter {
+ private Converter() {}
+
+ public static void writeInts(int [] array,ByteArrayOutputStream byteArrayOutputStream) {
+ try {
+ DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
+ for (int i = 0; i < array.length; i++) {
+ dataOutputStream.writeInt(array[i]);
+ }
+ dataOutputStream.flush();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static void readInts(ByteArrayInputStream byteArrayInputStream,int[] array) {
+ try {
+ DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
+ for (int i = 0; i < array.length; i++) {
+ array[i] = dataInputStream.readInt();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static byte[] writeInts(int[] array) {
+ try {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream(array.length * 4);
+ DataOutputStream dos = new DataOutputStream(bos);
+ for (int i = 0; i < array.length; i++) {
+ dos.writeInt(array[i]);
+ }
+
+ return bos.toByteArray();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public static int[] readInts(byte[] array) {
+ try {
+ ByteArrayInputStream bis = new ByteArrayInputStream(array);
+ DataInputStream dataInputStream = new DataInputStream(bis);
+ int size = array.length / Integer.BYTES;
+ int[] res = new int[size];
+ for (int i = 0; i < size; i++) {
+ res[i] = dataInputStream.readInt();
+ }
+ return res;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/src/main/java/com/github/technus/tectech/compatibility/openComputers/AvrArchitecture.java b/src/main/java/com/github/technus/tectech/compatibility/openComputers/AvrArchitecture.java
new file mode 100644
index 0000000000..fcbb65d609
--- /dev/null
+++ b/src/main/java/com/github/technus/tectech/compatibility/openComputers/AvrArchitecture.java
@@ -0,0 +1,267 @@
+package com.github.technus.tectech.compatibility.openComputers;
+
+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.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.Converter;
+import com.github.technus.tectech.TecTech;
+import li.cil.oc.Settings;
+import li.cil.oc.api.Driver;
+import li.cil.oc.api.driver.Item;
+import li.cil.oc.api.driver.item.Memory;
+import li.cil.oc.api.machine.Architecture;
+import li.cil.oc.api.machine.ExecutionResult;
+import li.cil.oc.api.machine.Machine;
+import li.cil.oc.api.machine.Signal;
+import li.cil.oc.common.SaveHandler;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import org.apache.commons.io.IOUtils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.zip.GZIPInputStream;
+import java.util.zip.GZIPOutputStream;
+
+@Architecture.Name("AVR 32Bit Clone")
+@Architecture.NoMemoryRequirements
+public class AvrArchitecture implements Architecture {
+ private final Machine machine;
+ private AvrCore core;
+ private boolean debugRun;
+ private int delay;
+ private int[] tempData;
+ private int memSize;
+
+ public AvrArchitecture(Machine machine) {
+ this.machine = machine;
+ }
+
+ @Override
+ public boolean isInitialized() {
+ return core!=null && core.checkValid();
+ }
+
+ @Override
+ public boolean recomputeMemory(Iterable<ItemStack> components) {
+ computeMemory(components);
+ return true;
+ }
+
+ private void computeMemory(Iterable<ItemStack> components) {
+ int memory = 0;
+ for (ItemStack component : components) {
+ Item driver = Driver.driverFor(component);
+ if (driver instanceof Memory) {
+ Memory memoryDriver = (Memory) driver;
+ memory += memoryDriver.amount(component) * 256;//in integers
+ }// else if (driver instanceof DriverEEPROM$) {
+
+ //}
+ }
+ memory = Math.min(Math.max(memory, 0), Settings.get().maxTotalRam());
+ if(memory!=memSize){
+
+ }
+ }
+
+ @Override
+ public boolean initialize() {
+ core=new AvrCore();
+
+ computeMemory(this.machine.host().internalComponents());
+
+ if(isInitialized()) {
+ machine.beep(".");
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void close() {
+ core=null;
+ tempData=null;
+ delay=0;
+ }
+
+ @Override
+ public void runSynchronized() {
+ core.cycle();
+ }
+
+ @Override
+ public ExecutionResult runThreaded(boolean isSynchronizedReturn) {
+ if (core.awoken) {
+ delay=0;
+ for (int load=0; load < 512;) {
+ load+=core.getInstruction().getCost(core);
+ ExecutionEvent executionEvent = core.cpuCycleForce();
+ if (executionEvent != null) {
+ if (executionEvent.throwable instanceof DelayEvent) {
+ delay = executionEvent.data[0];
+ break;
+ } else if (executionEvent.throwable instanceof DebugEvent) {
+ if(debugRun) {
+ //aBaseMetaTileEntity.setActive(false);
+ break;
+ }
+ }
+ }
+ }
+ }else if(delay>0){
+ delay--;
+ if(delay==0){
+ core.awoken=true;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void onSignal() {
+ Signal signal=machine.popSignal();
+
+ core.interruptsHandle();
+ }
+
+ @Override
+ public void onConnect() {
+ //init network components, in case init was called from load logic (pre first tick?)
+ }
+
+ @Override
+ public void load(NBTTagCompound avr) {
+ debugRun = avr.getBoolean("debugRun");
+ delay = avr.getInteger("delay");
+ core.active = avr.getBoolean("active");
+ core.awoken = (avr.getBoolean("awoken"));
+ core.programCounter = avr.getInteger("programCounter");
+ InstructionRegistry registry =
+ InstructionRegistry.REGISTRIES.
+ get(avr.getString("instructionRegistry"));
+ if (registry != null) {
+ byte[] instructions = SaveHandler.load(avr, this.machine.node().address() + "_instructionsMemory");
+ byte[] param0 = SaveHandler.load(avr, this.machine.node().address() + "_param0Memory");
+ byte[] param1 = SaveHandler.load(avr, this.machine.node().address() + "_param1Memory");
+ if (instructions != null && param0 != null && param1 != null &&
+ instructions.length > 0 && param0.length > 0 && param1.length > 0) {
+ int[] instr = null, par0 = null, par1 = null;
+ try {
+ GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(instructions));
+ instr = Converter.readInts(IOUtils.toByteArray(gzis));
+ IOUtils.closeQuietly(gzis);
+ } catch (IOException e) {
+ TecTech.LOGGER.error("Failed to decompress instructions memory from disk.");
+ e.printStackTrace();
+ }
+ try {
+ GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(param0));
+ par0 = Converter.readInts(IOUtils.toByteArray(gzis));
+ IOUtils.closeQuietly(gzis);
+ } catch (IOException e) {
+ TecTech.LOGGER.error("Failed to decompress param0 memory from disk.");
+ e.printStackTrace();
+ }
+ try {
+ GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(param1));
+ par1 = Converter.readInts(IOUtils.toByteArray(gzis));
+ IOUtils.closeQuietly(gzis);
+ } catch (IOException e) {
+ TecTech.LOGGER.error("Failed to decompress param1 memory from disk.");
+ e.printStackTrace();
+ }
+ if (instr != null && par0 != null && par1 != null &&
+ instr.length==par0.length && instr.length==par1.length) {
+ core.setProgramMemory(new ProgramMemory(
+ registry,
+ avr.getBoolean("immersive"),
+ instr,
+ par0,
+ par1));
+ }
+ }
+ }
+ if(avr.hasKey("eepromSize")){
+ core.restoreEepromDefinition(EepromMemory.make(avr.getInteger("eepromSize")));
+ }
+ byte[] data = SaveHandler.load(avr, this.machine.node().address() + "_dataMemory");
+ if(data!=null && data.length > 0) {
+ try {
+ GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(data));
+ tempData = Converter.readInts(IOUtils.toByteArray(gzis));
+ IOUtils.closeQuietly(gzis);
+ } catch (IOException e) {
+ TecTech.LOGGER.error("Failed to decompress data memory from disk.");
+ e.printStackTrace();
+ }
+ }
+ core.checkValid();
+ }
+
+ @Override
+ public void save(NBTTagCompound avr) {
+ avr.setBoolean("debugRun",debugRun);
+ avr.setInteger("delay",delay);
+ avr.setBoolean("active",core.active);
+ avr.setBoolean("awoken",core.awoken);
+ avr.setInteger("programCounter",core.programCounter);
+ ProgramMemory programMemory=core.getProgramMemory();
+ if(programMemory!=null){
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ GZIPOutputStream gzos = new GZIPOutputStream(baos);
+ gzos.write(Converter.writeInts(programMemory.instructions));
+ gzos.close();
+ SaveHandler.scheduleSave(machine.host(), avr, machine.node().address() + "_instructionsMemory", baos.toByteArray());
+ } catch (IOException e) {
+ TecTech.LOGGER.error("Failed to compress instructions memory to disk");
+ e.printStackTrace();
+ }
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ GZIPOutputStream gzos = new GZIPOutputStream(baos);
+ gzos.write(Converter.writeInts(programMemory.param0));
+ gzos.close();
+ SaveHandler.scheduleSave(machine.host(), avr, machine.node().address() + "_param0Memory", baos.toByteArray());
+ } catch (IOException e) {
+ TecTech.LOGGER.error("Failed to compress param0 memory to disk");
+ e.printStackTrace();
+ }
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ GZIPOutputStream gzos = new GZIPOutputStream(baos);
+ gzos.write(Converter.writeInts(programMemory.param1));
+ gzos.close();
+ SaveHandler.scheduleSave(machine.host(), avr, machine.node().address() + "_param1Memory", baos.toByteArray());
+ } catch (IOException e) {
+ TecTech.LOGGER.error("Failed to compress param1 memory to disk");
+ e.printStackTrace();
+ }
+ avr.setBoolean("immersive",programMemory.immersiveOperands);
+ avr.setString("instructionRegistry",programMemory.registry.toString());
+ }
+ RemovableMemory<EepromMemory> eeprom=core.getEepromMemory();
+ if(eeprom!=null){
+ avr.setInteger("eepromSize",eeprom.getDefinition().getSize());
+ }
+ if(core.dataMemory!=null) {
+ try {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ GZIPOutputStream gzos = new GZIPOutputStream(baos);
+ gzos.write(Converter.writeInts(core.dataMemory));
+ gzos.close();
+ SaveHandler.scheduleSave(machine.host(), avr, machine.node().address() + "_dataMemory", baos.toByteArray());
+ } catch (IOException e) {
+ TecTech.LOGGER.error("Failed to compress data memory to disk");
+ e.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/github/technus/tectech/loader/MainLoader.java b/src/main/java/com/github/technus/tectech/loader/MainLoader.java
index 1c3ec67972..d7d23d7461 100644
--- a/src/main/java/com/github/technus/tectech/loader/MainLoader.java
+++ b/src/main/java/com/github/technus/tectech/loader/MainLoader.java
@@ -61,6 +61,7 @@ public final class MainLoader {
}
public static void preLoad(){
+ creativeTabTecTech =new CreativeTabTecTech("TecTech");
//set expanded texture arrays for tiers
try {
@@ -120,7 +121,7 @@ public final class MainLoader {
}
public static void postLoad() {
- ProgressManager.ProgressBar progressBarPostLoad = ProgressManager.push("TecTech Post Loader", 6);
+ ProgressManager.ProgressBar progressBarPostLoad = ProgressManager.push("TecTech Post Loader", 5);
progressBarPostLoad.step("Dreamcraft Compatibility");
if(Loader.isModLoaded(Reference.DREAMCRAFT)){
@@ -146,13 +147,8 @@ public final class MainLoader {
progressBarPostLoad.step("Recipes");
new RecipeLoader().run();
-
TecTech.LOGGER.info("Recipe Init Done");
- progressBarPostLoad.step("Creative Tab");
- creativeTabTecTech =new CreativeTabTecTech("TecTech");
- TecTech.LOGGER.info("CreativeTab initiation complete");
-
progressBarPostLoad.step("Register Extra Hazmat Suits");
registerExtraHazmats();
TecTech.LOGGER.info("Hazmat additions done");
diff --git a/src/main/java/com/github/technus/tectech/loader/gui/CreativeTabTecTech.java b/src/main/java/com/github/technus/tectech/loader/gui/CreativeTabTecTech.java
index 295e1aeb7d..d360162fb6 100644
--- a/src/main/java/com/github/technus/tectech/loader/gui/CreativeTabTecTech.java
+++ b/src/main/java/com/github/technus/tectech/loader/gui/CreativeTabTecTech.java
@@ -1,12 +1,7 @@
package com.github.technus.tectech.loader.gui;
import com.github.technus.tectech.thing.CustomItemList;
-import com.github.technus.tectech.thing.block.QuantumGlassBlock;
-import com.github.technus.tectech.thing.casing.TT_Container_Casings;
-import com.github.technus.tectech.thing.item.ConstructableTriggerItem;
import com.github.technus.tectech.thing.item.DebugElementalInstanceContainer_EM;
-import com.github.technus.tectech.thing.item.ElementalDefinitionScanStorage_EM;
-import com.github.technus.tectech.thing.item.ParametrizerMemoryCard;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.GregTech_API;
@@ -20,7 +15,6 @@ public class CreativeTabTecTech extends CreativeTabs {
public CreativeTabTecTech(String name) {
super(name);
- registerThingsInTabs();
}
@SideOnly(Side.CLIENT)
@@ -38,14 +32,4 @@ public class CreativeTabTecTech extends CreativeTabs {
}
super.displayAllReleventItems(stuffToShow);
}
-
- private static void registerThingsInTabs() {
- QuantumGlassBlock.INSTANCE.setCreativeTab(creativeTabTecTech);
- TT_Container_Casings.sBlockCasingsTT.setCreativeTab(creativeTabTecTech);
- TT_Container_Casings.sHintCasingsTT.setCreativeTab(creativeTabTecTech);
- DebugElementalInstanceContainer_EM.INSTANCE.setCreativeTab(creativeTabTecTech);
- ConstructableTriggerItem.INSTANCE.setCreativeTab(creativeTabTecTech);
- ParametrizerMemoryCard.INSTANCE.setCreativeTab(creativeTabTecTech);
- ElementalDefinitionScanStorage_EM.INSTANCE.setCreativeTab(creativeTabTecTech);
- }
}
diff --git a/src/main/java/com/github/technus/tectech/loader/gui/ModGuiHandler.java b/src/main/java/com/github/technus/tectech/loader/gui/ModGuiHandler.java
index 44585d1b91..e555437104 100644
--- a/src/main/java/com/github/technus/tectech/loader/gui/ModGuiHandler.java
+++ b/src/main/java/com/github/technus/tectech/loader/gui/ModGuiHandler.java
@@ -1,5 +1,6 @@
package com.github.technus.tectech.loader.gui;
+import com.github.technus.tectech.thing.item.gui.ProgrammerScreen;
import com.github.technus.tectech.thing.item.gui.ScanDisplayScreen;
import cpw.mods.fml.common.network.IGuiHandler;
import net.minecraft.entity.player.EntityPlayer;
@@ -10,6 +11,7 @@ import net.minecraft.world.World;
*/
public class ModGuiHandler implements IGuiHandler {
public static final int SCAN_DISPLAY_SCREEN_ID =0;
+ public static final int PROGRAMMER_DISPLAY_SCREEN_ID =1;
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
@@ -20,6 +22,8 @@ public class ModGuiHandler implements IGuiHandler {
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID == SCAN_DISPLAY_SCREEN_ID) {
return new ScanDisplayScreen(player);
+ }else if(ID==PROGRAMMER_DISPLAY_SCREEN_ID){
+ return new ProgrammerScreen(player);
}
return null;
}
diff --git a/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java b/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java
index 856ba8dd13..0f127f9f6f 100644
--- a/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java
+++ b/src/main/java/com/github/technus/tectech/loader/thing/MachineLoader.java
@@ -90,6 +90,42 @@ public class MachineLoader implements Runnable {
eM_muffler_UXV.set(new GT_MetaTileEntity_Hatch_OverflowElemental(
15025, "hatch.emmuffler.tier.13", "UXV Overflow Output Hatch", 13, 125e12f).getStackForm(1L));
+
+ // ===================================================================================================
+ // Microcontrollers
+ // ===================================================================================================
+
+ eM_avr_HV.set(new GT_MetaTileEntity_MicroController(
+ 15030, "machine.avr.tier.08", "HV AVR Micro-controller", 3).getStackForm(1L));
+
+ eM_avr_EV.set(new GT_MetaTileEntity_MicroController(
+ 15031, "machine.avr.tier.08", "EV AVR Micro-controller", 4).getStackForm(1L));
+
+ eM_avr_IV.set(new GT_MetaTileEntity_MicroController(
+ 15032, "machine.avr.tier.08", "IV AVR Micro-controller", 5).getStackForm(1L));
+
+ eM_avr_LuV.set(new GT_MetaTileEntity_MicroController(
+ 15033, "machine.avr.tier.08", "LuV AVR Micro-controller", 6).getStackForm(1L));
+
+ eM_avr_ZPM.set(new GT_MetaTileEntity_MicroController(
+ 15034, "machine.avr.tier.08", "ZPM AVR Micro-controller", 7).getStackForm(1L));
+
+ eM_avr_UV.set(new GT_MetaTileEntity_MicroController(
+ 15035, "machine.avr.tier.08", "UV AVR Micro-controller", 8).getStackForm(1L));
+
+ eM_avr_UHV.set(new GT_MetaTileEntity_MicroController(
+ 15036, "machine.avr.tier.09", "UHV AVR Micro-controller", 9).getStackForm(1L));
+
+ eM_avr_UEV.set(new GT_MetaTileEntity_MicroController(
+ 15037, "machine.avr.tier.10", "UEV AVR Micro-controller", 10).getStackForm(1L));
+
+ eM_avr_UIV.set(new GT_MetaTileEntity_MicroController(
+ 15038, "machine.avr.tier.11", "UIV AVR Micro-controller", 11).getStackForm(1L));
+
+ eM_avr_UMV.set(new GT_MetaTileEntity_MicroController(
+ 15039, "machine.avr.tier.12", "UMV AVR Micro-controller", 12).getStackForm(1L));
+
+
// ===================================================================================================
// Multi AMP Power INPUTS
// ===================================================================================================
diff --git a/src/main/java/com/github/technus/tectech/mechanics/avr/SidedRedstone.java b/src/main/java/com/github/technus/tectech/mechanics/avr/SidedRedstone.java
new file mode 100644
index 0000000000..fd351631f3
--- /dev/null
+++ b/src/main/java/com/github/technus/tectech/mechanics/avr/SidedRedstone.java
@@ -0,0 +1,248 @@
+package com.github.technus.tectech.mechanics.avr;
+
+import com.github.technus.avrClone.AvrCore;
+import com.github.technus.avrClone.registerPackages.*;
+import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+
+public class SidedRedstone extends RegisterPackageSync<IGregTechTileEntity> {
+ public static final RSINT RSINT =new RSINT();
+
+ public SidedRedstone(int offset) {
+ super(offset, Register.values().length);
+ addRegisters(Register.values());
+ addBits(RegisterBitsPCMSK.values());
+ addBits(RegisterBitsPCFR.values());
+ addBits(RegisterBitsPCINT.values());
+ addBits(RegisterBitsPNEW.values());
+ addBits(RegisterBitsPOLD.values());
+ addInterrupts(RSINT);
+ }
+
+ @Override
+ public void preSync(AvrCore core,IGregTechTileEntity iGregTechTileEntity) {
+ int addr=this.getOffset();
+ int sides=0;
+ for(byte i=0;i<6;i++){
+ int val=iGregTechTileEntity.getInternalInputRedstoneSignal(i);
+ sides|=(val > 0?1:0)<<i;
+ core.setDataValue(addr++,iGregTechTileEntity.getInputRedstoneSignal(i));
+ core.setDataValue(addr++,val);
+ addr++;
+ }
+ int sidesOld = core.getDataValue(Register.PNEW.getAddress(this));
+ core.setDataValue(Register.POLD.getAddress(this),sidesOld);
+ core.setDataValue(Register.PNEW.getAddress(this),sides);
+
+ if(core.getInterruptEnable()) {
+ int pcint=core.getDataValue(Register.PCINT.getAddress(this));
+ int changesDetected=0;
+ switch (pcint&0b1100){//PCISC1 PCISC0
+ case 0b0000://low
+ changesDetected= ~sides & core.getDataValue(Register.PCMSK.getAddress(this));
+ break;
+ case 0b0100://any
+ changesDetected= (sides ^ sidesOld) & core.getDataValue(Register.PCMSK.getAddress(this));
+ break;
+ case 0b1000://falling
+ changesDetected= ~sides & sidesOld & core.getDataValue(Register.PCMSK.getAddress(this));
+ break;
+ case 0b1100://rising
+ changesDetected= sides & ~sidesOld & core.getDataValue(Register.PCMSK.getAddress(this));
+ break;
+ }
+
+ core.setDataValue(Register.PCFR.getAddress(this),
+ core.getDataValue(Register.PCFR.getAddress(this) | changesDetected));
+
+ if (changesDetected > 0) {
+ if (core.getDataBitsOr(Register.PCINT.getAddress(this), RegisterBitsPCINT.PCEN.mask)) {
+ core.setDataBits(Register.PCINT.getAddress(this), RegisterBitsPCINT.PCIF.mask);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void postSync(AvrCore core,IGregTechTileEntity iGregTechTileEntity) {
+ int addr=this.getOffset();
+ for(byte i=0;i<6;i++){
+ iGregTechTileEntity.setOutputRedstoneSignal(i,(byte)core.getDataValue(addr));//allows edge detection hack?
+ addr+=3;
+ }
+ }
+
+ public enum Register implements IRegister<SidedRedstone>{
+ PIN0,PINT0,PORT0,
+ PIN1,PINT1,PORT1,
+ PIN2,PINT2,PORT2,
+ PIN3,PINT3,PORT3,
+ PIN4,PINT4,PORT4,
+ PIN5,PINT5,PORT5,
+ PCMSK,PCFR,PCINT,PNEW,POLD;
+
+ public final int relativeOffset;
+
+ Register(){
+ this.relativeOffset =ordinal();
+ }
+
+ @Override
+ public int getAddress(SidedRedstone registerPackage) {
+ return registerPackage.getOffset()+relativeOffset;
+ }
+ }
+
+ public enum RegisterBitsPCMSK implements IRegisterBit<SidedRedstone>{
+ PCINT0,PCINT1,PCINT2,PCINT3,PCINT4,PCINT5;
+
+ private final int bit,mask;
+
+ RegisterBitsPCMSK(){
+ bit=ordinal();
+ mask=1<<bit;
+ }
+
+ @Override
+ public int getBitPosition() {
+ return bit;
+ }
+
+ @Override
+ public int getBitMask() {
+ return mask;
+ }
+
+ @Override
+ public int getOffset(SidedRedstone registerPackage) {
+ return 18;
+ }
+ }
+
+ public enum RegisterBitsPCFR implements IRegisterBit<SidedRedstone>{
+ PCF0,PCF1,PCF2,PCF3,PCF4,PCF5;
+
+ private final int bit,mask;
+
+ RegisterBitsPCFR(){
+ bit=ordinal();
+ mask=1<<bit;
+ }
+
+ @Override
+ public int getBitPosition() {
+ return bit;
+ }
+
+ @Override
+ public int getBitMask() {
+ return mask;
+ }
+
+ @Override
+ public int getOffset(SidedRedstone registerPackage) {
+ return 19;
+ }
+ }
+
+ public enum RegisterBitsPCINT implements IRegisterBit<SidedRedstone>{
+ PCIF,PCEN,PCISC0,PCISC1;
+
+ private final int bit,mask;
+
+ RegisterBitsPCINT(){
+ bit=ordinal();
+ mask=1<<bit;
+ }
+
+ @Override
+ public int getBitPosition() {
+ return bit;
+ }
+
+ @Override
+ public int getBitMask() {
+ return mask;
+ }
+
+ @Override
+ public int getOffset(SidedRedstone registerPackage) {
+ return 20;
+ }
+ }
+
+ public enum RegisterBitsPNEW implements IRegisterBit<SidedRedstone>{
+ PNEW0,PNEW1,PNEW2,PNEW3,PNEW4,PNEW5;
+
+ private final int bit,mask;
+
+ RegisterBitsPNEW(){
+ bit=ordinal();
+ mask=1<<bit;
+ }
+
+ @Override
+ public int getBitPosition() {
+ return bit;
+ }
+
+ @Override
+ public int getBitMask() {
+ return mask;
+ }
+
+ @Override
+ public int getOffset(SidedRedstone registerPackage) {
+ return 21;
+ }
+ }
+
+ public enum RegisterBitsPOLD implements IRegisterBit<SidedRedstone>{
+ POLD0,POLD1,POLD2,POLD3,POLD4,POLD5;
+
+ private final int bit,mask;
+
+ RegisterBitsPOLD(){
+ bit=ordinal();
+ mask=1<<bit;
+ }
+
+ @Override
+ public int getBitPosition() {
+ return bit;
+ }
+
+ @Override
+ public int getBitMask() {
+ return mask;
+ }
+
+ @Override
+ public int getOffset(SidedRedstone registerPackage) {
+ return 22;
+ }
+ }
+
+ public static class RSINT implements IInterrupt<SidedRedstone>{
+ @Override
+ public int getVector() {
+ return 1;
+ }
+
+ @Override
+ public boolean getTrigger(AvrCore core, SidedRedstone registerPackage) {
+ return (core.getDataValue(Register.PCINT.getAddress(registerPackage))&1)==1;
+ }
+
+ @Override
+ public void setTrigger(AvrCore core, SidedRedstone registerPackage, boolean value) {
+ int val=core.getDataValue(Register.PCINT.getAddress(registerPackage));
+ core.setDataValue(Register.PCINT.getAddress(registerPackage),
+ value?val|RegisterBitsPCINT.PCIF.mask:val&~RegisterBitsPCINT.PCIF.mask);
+ }
+
+ @Override
+ public String name() {
+ return "RSINT";