Syscall 2: Firmware, home

DriverChapter 10: Meshes

D39THE OTHER END

The task

Check each house frame's CRC: deliver the payload and answer $06, or answer $15.

This time the card is the far end. House frames arrive as before: $C1 $67, a length byte, a flags byte, the payload, and the CRC-16 of every byte before it, high byte first.

For each frame, feed every byte from $C1 to the end of the payload to the CRC engine and compare the result with the two CRC bytes. If they match, deliver the payload to the host and transmit $06 (ACK). If not, transmit $15 (NAK) and deliver nothing.

Frames follow one another with nothing between them. The damage never touches the sync or the length, payloads are at most 16 bytes, and this card has 16 cells of RAM.

The board

The line card of THE OTHER ENDThe line card: registers A B C D, 36 lines of ROM, 16 cells of RAM, a 16 byte receive buffer, a stack 8 deep, and CRC. It talks to the line and to a host.LINETHE FAR ENDRXTXCARDREGISTERSA B C DROM36 LINESRAM16 CELLSRX BUFFER16 BYTESSTACK8 DEEPUNITSCRCHOSTMESSAGES
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 CRC engine works the same at both ends. The sender's result travels with the frame, and the receiver repeats the work to see if it gets the same answer.

Hints

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

Hint 1Show

Hold the payload in RAM until the CRC is checked. Start with MOV CRC, $FFFF, and feed $C1, $67, the length, the flags, and every payload byte to the engine as they arrive.

Hint 2Show

Read the two CRC bytes into one register: the high byte into DH, the low byte into DL. Then JNE D, CRC, BAD compares all 16 bits at once.

Hint 3Show

Keep the length in B, since the payload loop needs it twice. A length of 0 skips both loops. BAD: OUT $15, and back to the top for the next frame.

Solution

Reveal the Full SolutionThe complete program for THE OTHER END. 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:    MOV CRC, $FFFF
        IN A
        CRC A
        IN A
        CRC A
        IN B
        CRC B
        IN A
        CRC A
        MOV C, 0
        JEQ B, 0, CHECK
READ:   IN A
        CRC A
        MOV [C], A
        ADD C, 1
        JNE C, B, READ
CHECK:  IN A
        MOV DH, A
        IN A
        MOV DL, A
        JNE D, CRC, BAD
        MOV C, 0
        JEQ B, 0, ACK
EMIT:   MOV A, [C]
        HOUT A
        ADD C, 1
        JNE C, B, EMIT
ACK:    OUT $06
        JMP TOP
BAD:    OUT $15
TICKS
516
at par
LINES
30
at par