Syscall 2: Firmware, home

DriverChapter 9: Special nodes

D30FIELD SELECT

The task

Deliver the third comma separated field of each line, then $0A.

The survey boat's sounder sends lines of fields split by commas, such as DPT,A,12.4,M for a depth of 12.4 meters. The depth logger only wants the third field.

Each line ends with $0A. Deliver the characters between the second and the third comma, or between the second comma and the end of the line, then $0A. A line with fewer than three fields delivers just $0A.

The board

The line card of FIELD SELECTThe line card: registers A B, 14 lines of ROM, no RAM, a 16 byte receive buffer, a stack 8 deep. It talks to the line and to a host.LINETHE FAR ENDRXTXCARDREGISTERSA BROM14 LINESRAMNONERX BUFFER16 BYTESSTACK8 DEEPUNITSNONEHOSTMESSAGES
The line card this ticket gives you, with its registers, memory, buffers, and units. On a narrow screen, scroll the board sideways to see all of it.

Key idea

The card does not need to remember the fields it skips, only how many commas have gone by.

Hints

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

Hint 1Show

Count the commas in B as they arrive. Deliver a character only while B is exactly 2.

Hint 2Show

A comma is never delivered: it only adds 1 to the count. At $0A, deliver $0A and set the count back to 0.

Hint 3Show

NEXT: IN A, JEQ A, $0A, EOL, JEQ A, ',', COMMA, JNE B, 2, NEXT, HOUT A, JMP NEXT. COMMA: ADD B, 1, JMP NEXT. EOL: HOUT $0A, MOV B, 0.

Solution

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

The reference program

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

NEXT:   IN A
        JEQ A, $0A, EOL
        JEQ A, ',', COMMA
        JNE B, 2, NEXT
        HOUT A
        JMP NEXT
COMMA:  ADD B, 1
        JMP NEXT
EOL:    HOUT $0A
        MOV B, 0
TICKS
369
at par
LINES
10
at par