![]() |
Routines |
| Prev: 4000 | Up: Map | Next: 5C00 |
|
The loader copies this routine here and runs it once the encrypted game has been loaded to 5E80. The helper at 6000 copies this stub here and the move routine to FC00. It first moves the game down to its home at 5C80 (see CopyGameDown) and then decrypts it, one byte at a time and from the top down, by running RRD over 9E00 bytes starting at FA00. Each RRD passes a nibble along from one byte to the next, so the whole game is stored shifted by half a byte. Control then goes to StartGame. Once the game is running the space up to 5BFF is reused, for the records of the segments of the four tiles that DrawTerrain makes (starting at 5B80, 5BA5, 5BCA and 5BEF). That routine also sets the stack pointer to 5B7A.
|
||||
|
Set up the stack and move the game down into place.
|
||||
| GameEntry | 5B80 | LD SP,$FE00 | Set the stack pointer to FE00. | |
| 5B83 | DI | Disable interrupts. | ||
| 5B84 | CALL CopyGameDown | Call CopyGameDown to move the game down to 5C80. | ||
|
Decrypt every byte from FA00 down to 5C01.
|
||||
| 5B87 | LD HL,$FA00 | Set the start address in HL to FA00. | ||
| 5B8A | XOR A | Clear the nibble carried between bytes in A. | ||
| 5B8B | LD BC,$9E00 | Set the byte count in BC to 9E00. | ||
| Decryption_Loop | 5B8E | RRD | Rotate the nibbles of the current byte through A. | |
| 5B90 | DEC HL | Move down to the previous byte. | ||
| 5B91 | DEC C | Decrease the low byte of the counter by one and loop back to Decryption_Loop until none remain. | ||
| 5B92 | JR NZ,Decryption_Loop | |||
| 5B94 | DJNZ Decryption_Loop | Decrease the high byte of the counter by one and loop back to Decryption_Loop until every byte has been decrypted. | ||
| 5B96 | JP StartGame | Jump to StartGame. | ||
| Prev: 4000 | Up: Map | Next: 5C00 |