Prev: FA00 Up: Map Next: FE24
FDE8: Unencrypt all LOADed game data
Used by the routine at 5D0C.
The code here was copied at 5D0C after the first tape data block was loaded - the first part here is a copy of this.
Avalon's data (as stored on tape) is encrypted using a simple algorithm.
The game memory from 61A9 to FA00 is unencrypted in the instructions from FDFF.
FDE8 LD SP,$FFFA Put the stack pointer (nearly) at the top of RAM
FDEB LD IX,$61A9 IX = address pointer at start of data block to LOAD
FDEF LD DE,$9858 Data block length (code up to RAM address 64000)
FDF2 LD A,$FF Indicates a data block to load (rather than header)
FDF4 SCF Sets the carry flag, which tells the ROM routine to perform a LOAD
The next 4 instructions are in the ROM loading routine just before 1377, executed here just before the jump there at FDFC (as it's not loading a header block)
FDF5 INC D
FDF6 EX AF,AF'
FDF7 DEC D
FDF8 DI
FDF9 LD HL,$FDFF This is the address that the code in the following instructions (starting from FDFF) will be at after the copy at the start of this routine.
FDFC JP $0561 Launch the ROM loading routine
Unencrypt all game code and data. A reverse encoding of this would've been done before the data was saved to tape.
FDFF LD HL,$61A9 Start address
FE02 LD DE,$9858 Number of bytes to work through
Unencryption loop:
FE05 LD A,(HL) Get byte
FE06 XOR %01100110 XOR to reverse the bits
FE08 RRCA Rotate right/divide by 2
FE09 XOR L A second XOR to reverse the bytes, using the low byte of the address pointer
FE0A LD (HL),A Re-store the unencrypted byte into memory
FE0B INC HL Move to the next memory address
FE0C DEC DE Decrement the number-of-bytes counter
FE0D LD A,D Check for zero
FE0E OR E
FE0F JR NZ,$FE05 If not, continue to unencrypt the data
Data in memory is now unpacked/unencrypted
FE11 LD A,$02
FE13 LD ($5C6B),A Enable screen character rows 22 & 23 for INPUT/errors
FE16 EI Enable interrupts
FE17 JP $F34B Jump to the code input routine
Unused data
FE1A DEFB $20,$20,$20,$20,$20,$20,$20,$20
FE22 DEFB $20,$20
Prev: FA00 Up: Map Next: FE24