Skip to content

Commit 4741e38

Browse files
committed
Merge remote-tracking branch 'Engineer12798/fix/array_gate_pulse' into dev
2 parents 2877f0e + f64705f commit 4741e38

1 file changed

Lines changed: 40 additions & 5 deletions

File tree

src/main/scala/mrtjp/projectred/integration/gatepartarray.scala

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,48 @@ trait TArrayCellTopOnly extends ArrayGateLogic {
424424
def sendSignalUpdate() { gate.getWriteStreamOf(11).writeByte(signal) }
425425

426426
override def onSignalUpdate() { sendSignalUpdate() }
427+
428+
override def onChange(gate: ArrayGatePart) {
429+
val iMask = inputMask(gate.shape)
430+
val rMask = redwireMask(gate.shape)
431+
val oMask = outputMask(gate.shape)
432+
val fMask = feedbackMask(gate.shape)
433+
val oldInput = gate.state & 0xf
434+
val newInput = getInput(gate, iMask | fMask) | getRedwireInput(rMask);
435+
if (oldInput != newInput) {
436+
gate.setState(gate.state & 0xf0 | newInput)
437+
gate.onInputChange()
438+
}
439+
440+
val newOutput = calcOutput(gate, gate.state & (iMask | rMask)) & oMask
441+
if (newOutput != (gate.state >> 4)) gate.scheduleTick(getDelay(gate.shape))
442+
}
443+
444+
override def scheduledTick(gate: ArrayGatePart) {
445+
val iMask = inputMask(gate.shape)
446+
val rMask = redwireMask(gate.shape)
447+
val oMask = outputMask(gate.shape)
448+
val oldOutput = gate.state >> 4
449+
val newOutput = calcOutput(gate, gate.state & (iMask | rMask)) & oMask
450+
if (oldOutput != newOutput) {
451+
gate.setState(gate.state & 0xf | newOutput << 4)
452+
gate.onOutputChange(oMask)
453+
}
454+
onChange(gate)
455+
}
456+
457+
def getDelay(shape: Int) = 2
458+
459+
def feedbackMask(shape: Int) = 0
460+
461+
def getRedwireInput(mask: Int) = if (getSignal(mask) != 0) mask else 0
462+
463+
def calcOutput(gate: ArrayGatePart, input: Int) = 0
427464
}
428465

429466
class ANDCell(gate: ArrayGatePart)
430467
extends ArrayGateLogic(gate)
431468
with TArrayCellTopOnly
432-
with TSimpleRSGateLogic[ArrayGatePart]
433469
with IGateWireRenderConnect {
434470
override def inputMask(shape: Int) = 4
435471
override def outputMask(shape: Int) = 1
@@ -438,7 +474,7 @@ class ANDCell(gate: ArrayGatePart)
438474
override def getHeight(r: Int) = 10.0d
439475

440476
override def calcOutput(gate: ArrayGatePart, input: Int) =
441-
if (input == 4 && signal != 0) 1 else 0
477+
if (((input & 4) != 0) && ((input & 0xa) != 0)) 1 else 0
442478

443479
override def getOcclusions(gate: ArrayGatePart) =
444480
ArrayGatePart.oBoxes(gate.side)
@@ -447,13 +483,12 @@ class ANDCell(gate: ArrayGatePart)
447483

448484
class StackingLatch(gate: ArrayGatePart)
449485
extends ArrayGateLogic(gate)
450-
with TArrayCellTopOnly
451-
with TSimpleRSGateLogic[ArrayGatePart] {
486+
with TArrayCellTopOnly {
452487
override def inputMask(shape: Int) = 4
453488
override def outputMask(shape: Int) = 1
454489

455490
override def calcOutput(gate: ArrayGatePart, input: Int) =
456-
if (signal == 0) gate.state >> 4
491+
if ((input & 0xa) == 0) gate.state >> 4
457492
else if ((input & 4) == 0) 0
458493
else 1
459494
}

0 commit comments

Comments
 (0)