Syscall 2: Firmware, home

DriverChapter 12: Shared buses

D46AT COMMANDS

The task

Answer each command line with OK or ERROR, as the modem would.

The modems in the pool take commands as lines of text, each ending with $0D. This card answers for one of them.

A line is good when it is AT followed by any number of commands, where a command is one of the letters E, H, Q, V, or Z, then at most one digit, 0 or 1. ATE0V1 and AT are good; ATX, ATE2, and ATE01 are not.

Transmit OK for a good line and ERROR for any other, empty lines included, each followed by $0D $0A. Letters are always capitals.

The board

The line card of AT COMMANDSThe line card: registers A, 32 lines of ROM, no RAM, a 16 byte receive buffer, a stack 8 deep. It talks to the line.LINETHE FAR ENDRXTXCARDREGISTERSAROM32 LINESRAMNONERX BUFFER16 BYTESSTACK8 DEEPUNITSNONE
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

Every answer waits for the $0D, even an error found on the first character, or the rest of the line would be read as the next one.

Hints

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

Hint 1Show

Work through the line one character at a time and jump to an error path at the first character that cannot be right. The error path reads up to the $0D before it answers.

Hint 2Show

After a command letter, a digit may follow but does not have to. After a digit, only a letter or $0D may follow.

Hint 3Show

Check A, then T. Then loop: $0D answers OK, and a command letter reads one more character; a 0 or 1 there goes back for the next letter, and anything else is checked as if it came first.

Solution

Reveal the Full SolutionThe complete program for AT COMMANDS. 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
        JNE A, 'A', BAD
        IN A
        JNE A, 'T', BAD
CMD:    IN A
LETTER: JEQ A, $0D, OK
        JEQ A, 'E', ARG
        JEQ A, 'H', ARG
        JEQ A, 'Q', ARG
        JEQ A, 'V', ARG
        JNE A, 'Z', BAD
ARG:    IN A
        JEQ A, '0', CMD
        JEQ A, '1', CMD
        JMP LETTER
BAD:    JEQ A, $0D, ERR
        IN A
        JMP BAD
OK:     OUT 'O'
        OUT 'K'
        JMP EOL
ERR:    OUT 'E'
        OUT 'R'
        OUT 'R'
        OUT 'O'
        OUT 'R'
EOL:    OUT $0D
        OUT $0A
TICKS
362
at par
LINES
28
at par