Syscall 2: Firmware, home

DriverChapter 11: Capstones

D45WILL AND WONT

The task

Deliver the text between Telnet commands, and refuse every option.

Remote readers reach the catalog over Telnet. Commands come mixed in with their text, each starting with IAC, $FF. The catalog only wants the text, and this card refuses every option the far end proposes.

After IAC, $FB (WILL), $FC (WONT), $FD (DO), or $FE (DONT) is followed by an option byte. Answer DO x with IAC WONT x, and WILL x with IAC DONT x. Send nothing for WONT and DONT.

IAC IAC stands for one text byte, $FF. IAC followed by any other byte is a command of two bytes in all: drop it. Deliver every text byte to the host.

The board

The line card of WILL AND WONTThe line card: registers A B, 22 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 BROM22 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

A refusal never needs an answer, so answering only DO and WILL can never start an endless exchange.

Hints

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

Hint 1Show

Most bytes are text and go straight to the host. Only $FF needs a second look at the byte after it.

Hint 2Show

After IAC: $FF is text. Below $FB the command is over. Otherwise read the option byte, then decide whether to answer.

Hint 3Show

IAC: IN A, JEQ A, $FF, TEXT, JLT A, $FB, TOP, IN B, JEQ A, $FD, DO, JEQ A, $FB, WILL, JMP TOP. DO: OUT $FF, OUT $FC, OUT B.

Solution

Reveal the Full SolutionThe complete program for WILL AND WONT. 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 A
        JEQ A, $FF, IAC
TEXT:   HOUT A
        JMP TOP
IAC:    IN A
        JEQ A, $FF, TEXT
        JLT A, $FB, TOP
        IN B
        JEQ A, $FD, DO
        JEQ A, $FB, WILL
        JMP TOP
DO:     OUT $FF
        OUT $FC
        OUT B
        JMP TOP
WILL:   OUT $FF
        OUT $FE
        OUT B
TICKS
96
at par
LINES
18
at par