Syscall 2: Firmware, home

DriverChapter 5: Half duplex

D8UNPACK

The task

Deliver the payload of each length prefixed frame to the host.

Each frame from the logger is a length byte followed by exactly that many bytes of payload, and frames follow one another with nothing between them.

Deliver every payload byte to the host, in order. Do not deliver the length bytes. A length of 0 means a frame with no payload, and the byte after it is the next frame's length.

The board

The line card of UNPACKThe line card: registers A B, 9 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 BROM9 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

Watch for a length of 0: DJN would count it down from 0, wrap around, and treat the frames after it as payload.

Hints

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

Hint 1Show

Receive the length into B, then receive and deliver B bytes.

Hint 2Show

DJN B, LOOP subtracts first and stops when B reaches 0. If B starts at 0, it would wrap around to 65535, so check for a zero length before the loop.

Hint 3Show

TOP: IN B, JEQ B, 0, TOP. LOOP: IN A, HOUT A, DJN B, LOOP. The card wraps back to TOP.

Solution

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

TOP:    IN B
        JEQ B, 0, TOP
LOOP:   IN A
        HOUT A
        DJN B, LOOP
TICKS
178
at par
LINES
5
at par