Prev: 5F9A Up: Map Next: 5FC3
5F9E: Get Random Number
Makes a pseudo-random number by mixing the byte at a moving address in the game memory into a seed. The address moves on by one byte each time and wraps within 8000-9FFF.
Output
A The high byte of the new seed
DE The new seed
GetRandomNumber 5F9E LD DE,($5F9A) Fetch the seed.
5FA2 LD HL,($5F9C) Fetch the address of the byte of game memory to mix in.
Make the new low byte.
5FA5 LD A,(HL) Fetch the byte of game memory.
5FA6 ADD A,$05 Add 05 to it.
5FA8 LD B,A Store the result in B.
5FA9 LD A,($5CDE) Fetch the game variable at GameVariable.
5FAC ADD A,B Add the byte from game memory.
5FAD ADD A,E Add the low byte of the seed.
5FAE LD E,A Make it the new low byte of the seed.
Make the new high byte.
5FAF LD A,(HL) Fetch the byte of game memory again.
5FB0 CPL Invert it.
5FB1 ADD A,$16 Add 16.
5FB3 ADD A,D Add the high byte of the seed.
5FB4 ADD A,L Add the low byte of the address.
5FB5 LD D,A Make it the new high byte of the seed.
5FB6 LD ($5F9A),DE Store the new seed.
Move the address on.
5FBA INC HL Move onto the next byte of game memory.
5FBB LD A,H Fetch the high byte of the address.
5FBC AND %10011111 Keep the address within 8000-9FFF.
5FBE LD H,A Put the high byte back.
5FBF LD ($5F9C),HL Store the address.
5FC2 RET Return.
Prev: 5F9A Up: Map Next: 5FC3