Prev: F216 Up: Map Next: F260
F21E: Code sheet - hash/randomize the security code co-ordinates required for input
Used by the routine at F274.
This routine provides random code sheet co-ordinates for security code entry.
The first 4 bytes at F216 contain random values (generated at F289 from the FRAMES system variable timer).
This routine then uses a combination of bit shift and XOR operations to further obfuscate the data at F216. Ultimately a randomized byte #4 of this set is used to generate the random codesheet co-ordinates.
F21E PUSH HL Store registers
F21F PUSH BC
F220 PUSH IX
F222 LD B,$08 8 x iterations of the below
The first 4 pseudo-random bytes at F216 are altered (using XOR/shifts) with the following 4 (fixed) bytes at F21A.
This process is started once bits 7 is set in the 4th byte just to ensure we've got some data to combine.
F224 LD IX,$F216 Pointer to byte 1 of 8 byte data set
F228 AND A Sets (A=0) or unsets (A<>0) zero flag, though the zero flag will be changed in the next instruction anyway
F229 BIT 7,(IX+$03) Top bit of 4th byte in data set (F216)
F22D JR Z,$F246 If it's zero (bit not set), rotate left first 4 bytes of data set and jump back to F224
Combine some bytes to further mix up the numbers:
F22F LD HL,$F21A Pointer to byte 5 of 8 byte data set
F232 LD C,$03 3 iterations
F234 LD A,(IX+$00) Mash together (XOR) bytes 1-3 in the table with (fixed) bytes 5-7
F237 XOR (HL)
F238 LD (IX+$00),A ...re-storing each one
F23B INC IX Increment both pointers
F23D INC HL
F23E DEC C
F23F JR NZ,$F234 Repeat for first three 3 bytes in table
F241 LD IX,$F216 Point to the start of the 8 byte set
F245 SCF Set the carry flag ready for the next loop
F246 RL (IX+$00) Rotate each of the first 4 bytes
F24A RL (IX+$01)
F24E RL (IX+$02)
F252 RL (IX+$03)
F256 DJNZ $F224 ...and repeat from F224 (8 iterations)
F258 LD A,(IX+$03) Grab the randomized/hashed 4th btye of the table in the A register - this will be used to generate the co-ordinates
F25B POP IX Retrieve registers
F25D POP BC
F25E POP HL
F25F RET A register returned with the number to use to pick the code sheet co-ordinates.
Prev: F216 Up: Map Next: F260