Prev: $290F Up: Map Next: $298B
$292F: Generate a safe combination code
Used by the routines at $2BB0 and $2E13.
$292F LDX #$04 There are 4 letters in the safe combination code.
$2931 LDA $D41B Generate a random value between 0 and 31.
$2934 AND #$1F
$2936 CLC Add $41 (the ASCII code for 'A').
$2937 ADC #$41
$2939 CMP #$5B Is the result greater than $5A (the code for 'Z')?
$293B BCS $2931 Branch back if so.
$293D CMP $90,X Does this randomly chosen letter match the character at $90+X (which might be the first digit of MR CREAK's year of birth at $94)?
$293F BEQ $2931 Branch back if so to get another one.
$2941 DEX Decrement the letter counter.
$2942 STA $90,X Store a randomly chosen letter at $90-$93.
$2944 STA $4E,X Store a copy of it at $4E-$51.
$2946 BNE $2931 Branch back until 4 letters have been generated.
$2948 LDA #$0A Initialise the shuffle counter at $55 to $0A.
$294A STA $55
$294C LDA $D41B Generate a random number between 1 and 3. Call it P.
$294F AND #$03
$2951 BNE $2955
$2953 LDA #$01
$2955 STA $56 Store P at $56.
$2957 INX Increment X for no apparent reason.
$2958 STA $FD Set the LSB of the lesson clock at $FD to P for no apparent reason.
$295A LDA $D41B Generate a random number between 1 and 3. Call it Q.
$295D AND #$03
$295F BNE $2963
$2961 LDA #$01
$2963 STA $57 Store Q at $57.
$2965 LDX $57 Swap the letters stored at $4E+P and $4E+Q.
$2967 LDA $4E,X
$2969 STA $54
$296B LDX $56
$296D LDA $4E,X
$296F LDX $57
$2971 STA $4E,X
$2973 LDX $56
$2975 LDA $54
$2977 STA $4E,X
$2979 DEC $55 Decrement the shuffle counter at $55.
$297B LDA $55 Pick up the shuffle counter from $55.
$297D BNE $294C Branch unless it's zero now.
$297F LDX #$00 Copy the randomly shuffled letters at $4E-$51 to $03-$06.
$2981 LDA $4E,X
$2983 STA $03,X
$2985 INX
$2986 CPX #$04
$2988 BNE $2981
$298A RTS
Prev: $290F Up: Map Next: $298B