Dedicated memory cells

This commit is contained in:
Anuken
2020-08-11 10:50:12 -04:00
parent 7e8326a3af
commit bb3c80c055
29 changed files with 3535 additions and 3467 deletions
+27 -14
View File
@@ -9,6 +9,7 @@ import mindustry.entities.*;
import mindustry.game.*;
import mindustry.gen.*;
import mindustry.world.blocks.logic.LogicDisplay.*;
import mindustry.world.blocks.logic.MemoryBlock.*;
import mindustry.world.blocks.logic.MessageBlock.*;
import static mindustry.Vars.*;
@@ -23,7 +24,6 @@ public class LExecutor{
maxGraphicsBuffer = 512,
maxTextBuffer = 256;
public double[] memory = {};
public LInstruction[] instructions = {};
public Var[] vars = {};
@@ -162,11 +162,12 @@ public class LExecutor{
}
public static class ReadI implements LInstruction{
public int from, to;
public int target, position, output;
public ReadI(int from, int to){
this.from = from;
this.to = to;
public ReadI(int target, int position, int output){
this.target = target;
this.position = position;
this.output = output;
}
public ReadI(){
@@ -174,18 +175,24 @@ public class LExecutor{
@Override
public void run(LExecutor exec){
int address = exec.numi(from);
int address = exec.numi(position);
Building from = exec.building(target);
exec.setnum(to,address < 0 || address >= exec.memory.length ? 0 : exec.memory[address]);
if(from instanceof MemoryEntity){
MemoryEntity mem = (MemoryEntity)from;
exec.setnum(output, address < 0 || address >= mem.memory.length ? 0 : mem.memory[address]);
}
}
}
public static class WriteI implements LInstruction{
public int from, to;
public int target, position, value;
public WriteI(int from, int to){
this.from = from;
this.to = to;
public WriteI(int target, int position, int value){
this.target = target;
this.position = position;
this.value = value;
}
public WriteI(){
@@ -193,10 +200,16 @@ public class LExecutor{
@Override
public void run(LExecutor exec){
int address = exec.numi(to);
int address = exec.numi(position);
Building from = exec.building(target);
if(from instanceof MemoryEntity){
MemoryEntity mem = (MemoryEntity)from;
if(address >= 0 && address < mem.memory.length){
mem.memory[address] = exec.num(value);
}
if(address >= 0 && address < exec.memory.length){
exec.memory[address] = exec.num(from);
}
}
}
+26 -12
View File
@@ -58,16 +58,23 @@ public class LStatements{
@RegisterStatement("write")
public static class WriteStatement extends LStatement{
public String to = "0";
public String from = "result";
public String input = "result", target = "@0", address = "0";
@Override
public void build(Table table){
field(table, to, str -> to = str);
table.add(" write ");
table.add(" = ");
field(table, input, str -> input = str);
field(table, from, str -> from = str);
table.add(" to ");
fields(table, target, str -> target = str);
table.row();
table.add(" at ");
field(table, address, str -> address = str);
}
@Override
@@ -77,22 +84,29 @@ public class LStatements{
@Override
public LInstruction build(LAssembler builder){
return new WriteI(builder.var(from), builder.var(to));
return new WriteI(builder.var(target), builder.var(address), builder.var(input));
}
}
@RegisterStatement("read")
public static class ReadStatement extends LStatement{
public String to = "result";
public String from = "0";
public String output = "result", target = "@0", address = "0";
@Override
public void build(Table table){
field(table, to, str -> to = str);
table.add(" read ");
table.add(" = mem:: ");
field(table, output, str -> output = str);
field(table, from, str -> from = str);
table.add(" = ");
fields(table, target, str -> target = str);
table.row();
table.add(" at ");
field(table, address, str -> address = str);
}
@Override
@@ -102,7 +116,7 @@ public class LStatements{
@Override
public LInstruction build(LAssembler builder){
return new ReadI(builder.var(from), builder.var(to));
return new ReadI(builder.var(target), builder.var(address), builder.var(output));
}
}