Prev: 4000 Up: Map Next: 5BA4
5B80: Decrypt Game
The stub which the tape loader runs once the game has been loaded at 6000. It decrypts the whole game, 8000 bytes, two bytes at a time, and then moves the game down by 0200 bytes to its real home at GameStart before starting it.
The tape loader sets up this stub, and the game checks for the loader's signature in the frame counter (see InitialiseGame).
Set up the first pair and the number of pairs to decrypt.
DecryptGame 5B80 LD DE,$6000 Set DE to 6000, the address of the first byte of the pair to decrypt.
5B83 LD HL,$6001 Set HL to 6001, the address of the second byte of the pair.
5B86 LD BC,$4000 Set BC to 4000, the number of byte pairs to decrypt.
Start rotating each byte through A to decrypt it.
DecryptGame_Loop 5B89 LD A,(DE) Fetch the first byte of the pair.
5B8A RLD Rotate the nibbles of the two bytes through A.
5B8C LD (DE),A Write the decrypted byte back.
5B8D INC DE Move on to the first byte of the next pair.
5B8E INC DE
5B8F INC HL Move HL onto the second byte of the next pair.
5B90 INC HL
5B91 DEC BC Decrease the pair counter by one.
5B92 LD A,B Loop back to DecryptGame_Loop until every pair has been decrypted.
5B93 OR C
5B94 JR NZ,DecryptGame_Loop
Move the decrypted game down to its real address and start it.
5B96 LD HL,$6000 Copy 8000 bytes of the game from 6000 to GameStart.
5B99 LD DE,$5E00
5B9C LD BC,$8000
5B9F LDIR
5BA1 JP GameStart Jump to GameStart to start the game.
Prev: 4000 Up: Map Next: 5BA4