Faxanadu includes a pseudo-random number generator used for two purposes:
1. Randomly changing horizontal direction (for sprites)
2. Randomly changing vertical direction.
These are used for flying enemies.
# How it works
At bank 15 $CA6E - $CA77, there's a function that returns a random number. It works like this:
1. A 1-byte counter storing an offset into bank 14 (covering $8000 - $80FF).
2. Each time this is called, the byte from the bank at that offset is read.
3. The result is then XOR'd with controller 1's pressed button mask.
4. The offset is then incremented (wrapping from $FF to $00).
If no buttons are pressed, each random value will be directly based on the bytes read.
If buttons are pressed, the random value can be manipulated.
# How it's used
This is used by the following blocks of code:
* `CurrentSprite_RandomlyChangeHorizDirection` (Bank 14 $A7AD - A7C8)
* `CurrentSprite_RandomlyChangeVertDirection` (Bank 14 $A7C9 - A7E4)
Both of these call the function and handle the result the same way:
1. If value is < 0x80 (bit 7 is not set), sprite will move left or up (respectively)
2. If value is >= 0x80 (bit 7 is set), sprite will move right or down (respectively)
The "A" button on the controller will impact bit 7 (1 if set, 0 if not).