Syscall 2: Firmware, home

BenchChapter 8: Scarcity

B56ENVELOPE

The task

P0 is a gate, a slow square wave from V1. P2 ticks every 10 cycles.

While the gate is high, raise the duty on P1 by 25 percent a tick until it reaches 100.

While the gate is low, lower it by 10 percent a tick until it reaches 0.

The board

The chip of ENVELOPEChip u1 with 3 ports: P0 digital in, reaching V1, CH1; P1 pwm out, reaching R1, C1, CH2; P2 timer 10 cycles.u1CHIP SC-2P0DIGITAL INV1, CH1P1PWM OUTR1, C1, CH2P2TIMER 10 CYCLES
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 square at 25 Hz
Resistors
R1 1 kΩ
Capacitors
C1 1 µF
Probes
CH1 and CH2

Key idea

B holds the duty between ticks.

Hints

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

Hint 1Show

Check the gate first, then whether the duty is already at its end.

Hint 2Show

At 100 or at 0 there is nothing to change, so go back and wait for the next tick.

Solution

Reveal the Full SolutionThe complete program for ENVELOPE. 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.

A fast attack while the gate is high, a slow release after.

u1SC-2 standard

L: IN P2
IN P0
JZ DN
MOV A, B
SUB 100
JZ L
ADD 125
JMP S
DN: MOV A, B
JZ L
SUB 10
S: MOV B, A
OUT P1
CYCLES
793
at par
ENERGY
1586
at par
NODES
1
at par
INSTRUCTIONS
13
at par