D10CHECKSUM GATE
The task
Deliver the payloads of frames whose sum check matches; drop the rest.
The receiver decides which reports to believe. Frames arrive in the format the stations send: $C1, a length byte, the payload, and a check byte that is the sum of the payload bytes, keeping only the low 8 bits.
Deliver the payload of every frame whose check byte matches the sum of its payload. Deliver nothing from a frame whose check does not match. A frame with no payload delivers nothing either way.
Between frames the line may carry noise, which never includes $C1. The radio damages only payload bytes and check bytes, never the sync or the length. Payloads are at most 12 bytes long, and this card has 16 cells of RAM.
The board
Key idea
Hold the payload in RAM until the check byte matches. A byte delivered to the host cannot be taken back.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
Store the payload in RAM and add it up as it arrives. Compare the sum with the check byte before delivering anything.
Hint 2Show
Registers hold 16 bits, so a sum past 255 will not equal the check byte until you keep only its low 8 bits: AND D, $FF.
Hint 3Show
After the sync: IN B for the length, then a loop that stores into [C] and adds into D. Then IN A for the check, AND D, $FF, JNE A, D, HUNT. Otherwise deliver the stored bytes from cell 0 up to, but not including, cell B, and go back to hunting.
Solution
Reveal the Full SolutionThe complete program for CHECKSUM GATE. 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.
HUNT: IN A
JNE A, $C1, HUNT
IN B
MOV C, 0
MOV D, 0
READ: JEQ C, B, CHECK
IN A
MOV [C], A
ADD D, A
ADD C, 1
JMP READ
CHECK: IN A
AND D, $FF
JNE A, D, HUNT
MOV C, 0
COPY: JEQ C, B, HUNT
MOV A, [C]
HOUT A
ADD C, 1
JMP COPY- TICKS
- 493
- at par
- LINES
- 20
- at par