IC10 code is rarely written once and never touched again. By the time the base grows, at the latest, you open the chip again and wonder what blt r3 r7 12 was actually supposed to do. The rules here make sure you can still see it at a glance weeks later.
The rules
1. Every number gets a define
Every prefab hash and every threshold sits at the top as a define, with a comment after it saying what it means. The actual program never contains a raw hash number.
define AKKU -1388288459 # Station battery (large)
define START_UNTER 0.30 # below 30 % generator on
2. Every register gets an alias
Right after the define lines comes the alias block. Every register used in the program has a name. r0 reads badly, akku (battery) is clear at once.
alias akku r0
alias laeuft r1
3. Devices via lbn and sbn by name
Devices are addressed over the data network by type and name, not via the pins d0–d5:
lbn akku AKKU HASH("Akku") Ratio 0
That has three advantages: no limit of six devices, no pin setting on the housing that gets lost when you rebuild, and several devices with the same name are automatically handled together. You name the devices in game with the Labeller. Without umlauts, see below.
4. Batch mode always 0
When reading with lbn, the last value is always 0 (Average). If three batteries named "Akku" (battery) are on the network, you get the average, and for a charge level that is exactly what you want. With Sum, three half-full batteries would add up to one and a half times full.
5. yield in every main loop
Without yield the chip stubbornly works through its 128 instructions per tick, reading the same not-yet-updated values over and over. With yield the loop runs exactly once per tick.
6. Endless loop is mandatory
When the chip reaches the end of the program, it stops and does not restart on its own. No error, no warning, just silence. That is why every program ends with j start.
7. Only labels as jump targets
Jumps go to start:, an:, aus:, never to a line number.
8. Temperatures in Kelvin with Celsius in the comment
The game calculates in Kelvin. So thresholds go into the define as a Kelvin number, with the Celsius value in the comment after it:
define WARM 298.15 # 25 C
If you prefer to think in Celsius, convert once at the start:
define CELSIUSOFFSET 273.15 # 0 C in Kelvin
alias ziel r2
add ziel 21 CELSIUSOFFSET # 21 C
9. Tidy code
- Comments in German in my own chips (on this English page they are in English), without umlauts in the code (ae, oe, ue, ss).
- Sections with a heading as a comment:
# --- 1. Measure ---. - No obsolete commands like
ld,sd,getd,putdorlabel.l,s,getandputdo the same job.
The example: backup generator
A Gas Fuel Generator should start when the batteries drop below 30 %, and only switch off again once they are above 90 %. A small LED display shows the charge level in percent.
Name the devices in game:
| Device | Name |
|---|---|
| Station Battery (Large), one or more | Akku (battery) |
| Gas Fuel Generator | Generator |
| LED Display (Small) | Akkustand (charge level) |
All of them are on the same data network as the IC housing.
# Backup power: generator by battery level
# --- 0. Constants ---
define AKKU -1388288459 # Station battery (large)
define GENERATOR 1165997963 # Gas fuel generator
define ANZEIGE -815193061 # LED display (small)
define START_UNTER 0.30 # below 30 % on
define STOPP_UEBER 0.90 # above 90 % off
# --- Registers ---
alias akku r0
alias laeuft r1
alias prozent r2
move laeuft 0
start:
yield
# --- 1. Measure ---
lbn akku AKKU HASH("Akku") Ratio 0
bnan akku start
# --- 2. Decide ---
blt akku START_UNTER an
bgt akku STOPP_UEBER aus
j schalten
an:
move laeuft 1
j schalten
aus:
move laeuft 0
# --- 3. Switch and display ---
schalten:
sbn GENERATOR HASH("Generator") On laeuft
mul prozent akku 100
sbn ANZEIGE HASH("Akkustand") Setting prozent
j start
What you may adjust:
START_UNTERandSTOPP_UEBER: the switching thresholds as a fraction from 0 to 1. The gap between them prevents constant on and off.- The names in
HASH("..."), if your devices are named differently.
If a device is missing:
- No battery named "Akku" on the network:
lbnreturns NaN,bnanjumps back, nothing gets switched. The generator stays as it was. - No generator named "Generator":
sbnwrites into the void, the program keeps running anyway.
Why all this effort?
Because you find errors in a program like this in seconds. Every number has a name, every register a meaning, every jump a target that makes sense. And anyone who wants to adapt the program to their base changes two lines at the top instead of twenty further down.
The IC10 Editor Tablet can check these rules too if you want, and its templates build code in exactly this style. The most common mistakes are listed under Common Mistakes.