D42FULL DUPLEX
The task
Transmit host bytes and deliver received bytes, both at once.
The order terminal and the depot talk at the same time. Bytes from the host go out on the line, bytes from the line go to the host, and neither side waits for the other.
Transmit every host byte; the end of a host message sends nothing. Deliver every received byte to the host. The receive buffer holds only 4 bytes, so the line cannot wait while the card waits for the host.
RXN reads how many received bytes are waiting. HIN A, LOOP works with the timer just as IN does: it jumps to LOOP if no host byte comes before the timer runs out.
The board
Key idea
Serve the line first: its buffer is small, and the host keeps its bytes until they are read.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
Never wait on one side while the other has something. JEQ RXN, 0, HOST checks the line without waiting for it.
Hint 2Show
HIN takes two ticks even when a byte is ready, so a timer of 1 or 2 always runs out first. TMR 3, then HIN A, LOOP gives the host a short chance.
Hint 3Show
LOOP: JEQ RXN, 0, HOST, IN A, HOUT A, JMP LOOP. HOST: TMR 3, HIN A, LOOP, JEQ A, -1, LOOP, OUT A, JMP LOOP.
Solution
Reveal the Full SolutionThe complete program for FULL DUPLEX. 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.
LOOP: JEQ RXN, 0, HOST
IN A
HOUT A
JMP LOOP
HOST: TMR 3
HIN A, LOOP
JEQ A, -1, LOOP
OUT A
JMP LOOP- TICKS
- 361
- at par
- LINES
- 9
- at par
Another way: Host first
A second program that also passes. It beats par on LINES and gives some back on TICKS.
LOOP: TMR 3
HIN A, LINE
JEQ A, -1, LINE
OUT A
LINE: JEQ RXN, 0, LOOP
IN A
HOUT A
JMP LOOP- TICKS
- 368
- over par
- LINES
- 8
- under par