Syscall 2: Firmware, home

BenchChapter 10: Meshes

B79INTERLOCK

The task

P0 asks the hoist to go up, P1 asks it to go down. P2 drives up, P3 drives down.

A request is granted only while the other direction is off; it then holds until released.

A request that waited is granted as soon as the other side lets go.

The board

The chip of INTERLOCKChip u1 with 4 ports: P0 digital in, reaching V1, CH1; P1 digital in, reaching V3, CH2; P2 digital out, reaching R1, D1, CH3; P3 digital out, reaching R2, D2, CH4.u1CHIP SC-2P0DIGITAL INV1, CH1P1DIGITAL INV3, CH2P2DIGITAL OUTR1, D1, CH3P3DIGITAL OUTR2, D2, CH4
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes. On a narrow screen, scroll the board sideways to see all of it.
Sources
V1 5 V, V2 5 V square at 20 Hz, V3 5 V, and V4 5 V square at 12.5 Hz
Resistors
R1 330 Ω and R2 330 Ω
LEDs
D1 green and D2 red
Probes
CH1, CH2, CH3, and CH4

Key idea

Never drive both: while one output is on, ignore the other request.

Hints

Each hint goes a step further than the one before. Open them one at a time.

Hint 1Show

When nothing is on, check both requests and grant the first you find.

Hint 2Show

Write a loop for each direction that holds until its request drops.

Solution

Reveal the Full SolutionThe complete program for INTERLOCK. Open it only when you want the answer.

The reference program

The game's own solution. It passes every test and scores exactly par on every benchmark.

One direction at a time; each holds until released.

u1SC-2 standard

I: IN P0
JNZ U
IN P1
JZ I
OUT P3
DN: IN P1
JNZ DN
OUT P3
JMP I
U: OUT P2
W: IN P0
JNZ W
OUT P2
CYCLES
1800
at par
ENERGY
3600
at par
NODES
1
at par
INSTRUCTIONS
13
at par