stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 30

Day 30 of 365 · Beginner · Month 2: Order and data network

The workshop style

Sections with # --- 1. ---, Kelvin values with a Celsius comment, CELSIUSOFFSET and labels instead of line numbers: the style all further programs are written in.

Lesson 11 min Week 5

What you learn today

  • Sections with # --- 1. ---
  • Kelvin literal with Celsius comment
  • CELSIUSOFFSET
  • Labels instead of line numbers

From today on all programs in the course look the same. That is not an end in itself: whoever opens a chip in the base should find within five seconds where the target is and which register holds what. Dominik has built his chips like this for years, and in this course you will read hundreds more programs in this style.

Sections

A program has a header and numbered sections:

# --- Frost guard storage ---
# --- 1. Settings ---
define LIMIT 278.15      # 5 C
# --- 2. Registers and devices ---
alias temp r0
alias cold r1
# --- 3. Main loop ---
start:
yield

Further sections inside the loop get the next number: # --- 4. Heater ---, # --- 5. Display ---. Short and in ASCII, comments count towards the character limit.

Kelvin value with a Celsius comment

The chip computes in Kelvin, people think in Celsius. That is why the value sits in Kelvin in the define and the Celsius behind it in the comment:

define TARGET 294.15    # 21 C
define ALARM 313.15     # 40 C

Or: CELSIUSOFFSET

If you want to set targets directly in Celsius, store the offset as a define and convert once before the main loop:

define CELSIUSOFFSET 273.15  # 0 C in Kelvin
define TARGET_C 21           # target in C
alias target r1
add target TARGET_C CELSIUSOFFSET
Warning

A define must not compute with another define. define TARGET TARGET_C or a define pointing at CELSIUSOFFSET gives NaN, without an error message. A define's value is only a number, a constant, a Namespace.Name or HASH("…"). That is why the conversion goes through a register with add.

Labels instead of line numbers

A jump to a line number works – until someone inserts a line above it. Then the chip jumps one line off, and nobody notices right away:

j 9       # points at yield today, at something else tomorrow

A label moves along. That is why every program in the course only jumps to labels.

The rules at a glance

RuleExample
every fixed value as a define with a commentdefine LIMIT 278.15 # 5 C
every register with an alias, right after the definesalias temp r0
numbered sections# --- 3. Main loop ---
main loop with yield and a jump backstart: … j start
only labels as jump targetsj start instead of j 9
Tip

The checker in the IC10 coder can show style hints based on these rules. Switch them on in the “Checker” tab and you see bare registers and line jumps right away.

Diagram

Program layout in the proven style # --- Heat warning --- define LIMIT 303.15 # 30 C define SENSOR HASH("…") alias temp r0 alias hot r1 start: yield … j start 1 · define everything tunable 2 · alias names for registers 3 · main loop with yield, endless
All settings sit at the top, the register names below, then the main loop with yield.

Exercise

Task

The starter code works but is written in the old style. Bring it into the workshop style without changing what it does:

  • Header and numbered sections.
  • The limit of 19 °C not as a raw number in the body: either a define in Kelvin with a Celsius comment or CELSIUSOFFSET with add.
  • Every register in use gets an alias.
  • No jump to a line number.

Hints

Hint 1

Header: # --- Frost guard storage ---, then # --- 1. Settings ---.

Hint 2

define CELSIUSOFFSET 273.15 and define LIMIT_C 19, then before the loop add limit LIMIT_C CELSIUSOFFSET.

Hint 3

j 1 becomes j start.

Quiz

4 questions. You pass from 60 % – the server does the grading.

Complete the day

  • Passed the simulator exercise
  • Passed the quiz with at least 60 %

Without an account progress is saved in this browser only.

Report a mistake in this lesson

Please sign in to report. Sign in

Esc
↑ ↓ selectEnter open/ opens search anywhere