Prev: 5B00 Up: Map Next: 5BAB
5B80: The loader's routine: unscramble the game and start it
Loaded from the tape into the printer buffer and run by the BASIC loader's PRINT USR. It sets bit 7 of the R register, which the refresh count never changes and which the game checks at every new game (STOCK_BUILDINGS); unscrambles the game block, which the tape loaded 512 bytes higher, a pair of bytes at a time -- RLD with the second byte swaps a nibble between the two; moves it all down to ENTRY; and jumps there. The build does the same to the tape's block and checks the result is the snapshot's (check_loader in scripts/build_nightshade.py).
The DI here is for good: nothing in the game enables interrupts again, so FRAMES, which the interrupt counts, keeps the value the tape gave it for as long as the game runs (SYSTEM_VARIABLES).
LOADER 5B80 DI interrupts off, never to come back on
5B81 LD A,R set bit 7 of R, the mark STOCK_BUILDINGS looks for; the refresh counts only the low seven bits
5B83 OR $80
5B85 LD R,A
5B87 LD DE,$6000 DE and HL on the first pair of the loaded block; 17408 pairs
5B8A LD HL,$6001
5B8D LD BC,$4400
LOADER_0 5B90 LD A,(DE) the first byte becomes its own high nibble and the second's; the second, its own low nibble and the first's
5B91 RLD
5B93 LD (DE),A
5B94 INC DE on to the next pair, until all are done
5B95 INC DE
5B96 INC HL
5B97 INC HL
5B98 DEC BC
5B99 LD A,B
5B9A OR C
5B9B JR NZ,LOADER_0
5B9D LD HL,$6000 move the whole block down 512 bytes, to where it runs
5BA0 LD DE,ENTRY
5BA3 LD BC,$8800
5BA6 LDIR
5BA8 JP ENTRY and start it
Prev: 5B00 Up: Map Next: 5BAB