| Routines

F855: Generate a safe combination code and set MR CREAK's birth year

Used by the routine at F8B4. Generates a new safe combination code, sets a new random birth year for MR CREAK, and adjusts the game mode (so that all the shields need to be flashed again).
Input
A | 0x00
F855 | LD HL,$7FB8 | Clear the safe combination code (stored at 7F9F), the teachers' combination letters (stored at 7FA3), and the blackboard contents buffers (at 7FA8, 7FAE and 7FB4)
F858 | LD B,$19
F85A | LD (HL),A
F85B | DEC L
F85C | DJNZ $F85A
F85E | LD D,A | DE=0000
F85F | LD E,A
F860 | LD C,$04 | There are four letters in the combination
F862 | CALL $61A1 | A=random number
F865 | AND $0F | 0x00<=A<=0x0F
F867 | JR $F87C | Store MR WACKER's safe combination letter first (at 7F9F)
F869 | LD L,$9F | HL=7F9F (first letter of the safe combination code)
F86B | ADD HL,BC | HL=7F9F+C (1<=C<=3)
F86C | CALL $61A1 | A=random number
F86F | LD E,B | E=0
F870 | RRCA | Get a random number between 0 and 3 in E
F871 | RL E
F873 | RRCA
F874 | RL E
F876 | AND $1F | Is A between 0x00 and 0x19?
F878 | CP $1A
F87A | JR NC,$F86C | Jump back if not
F87C | ADD A,$41 | A=ASCII code of an upper case letter
F87E | LD (HL),A | Store this in one of the slots at 7F9F
F87F | LD L,$A3 | Point HL at a random teacher's safe combination letter
F881 | ADD HL,DE
F882 | BIT 6,(HL) | Has this letter already been decided?
F884 | JR NZ,$F869 | Jump if so
F886 | LD (HL),A | Store the ASCII code in one of the four slots at 7FA3
F887 | DEC C | Next combination letter
F888 | JR NZ,$F869 | Jump back until all four combination letters are done
The safe combination code has been generated. Now for MR CREAK's birth year.
F88A | LD L,$9A | HL=7F9A (which holds the identifier for CREAK's birth year battle)
F88C | CALL $61A1 | Get a random number between 0x00 and 0x14 in A
F88F | CP $15
F891 | JR NC,$F88C
F893 | ADD A,A | A=random odd number between 0xD5 and 0xFD
F894 | ADD A,$D5
F896 | LD (HL),A | Store this battle identifier at 7F9A
F897 | SUB $81 | Set HL to the address of the battle year message corresponding to this battle identifier
F899 | LD E,A
F89A | LD H,D
F89B | LD L,D
F89C | ADD HL,DE
F89D | ADD HL,DE
F89E | ADD HL,DE
F89F | ADD HL,HL
F8A0 | ADD HL,HL
F8A1 | LD A,H
F8A2 | ADD A,$DF
F8A4 | LD H,A
F8A5 | LD DE,$7F9B | Store the digits of CREAK's birth year at 7F9B
F8A8 | LD C,$04
F8AA | LDIR
Finally, adjust the game mode.
F8AC | LD A,$01 | Set the game mode indicator at 7FEA to 1, indicating that the shields need to be flashed
F8AE | LD ($7FEA),A
F8B1 | RET |