Prev: $2500 Up: Map Next: $2552
$253E: Generate a random value in a given range
Used by the routine at $2241.
Input
X Minimum (m)
Y Maximum (M)
Output
A Random value
$253E STX $E3 Store the minimum value (m) at $E3.
$2540 INY Store 1+M-m at $E4.
$2541 TYA
$2542 SEC
$2543 SBC $E3
$2545 STA $E4
$2547 LDA $D41B Generate a random value (R) in A.
$254A SEC Now A=R-m (if R>=m) or 256-m+R (if R<m).
$254B SBC $E3
$254D CMP $E4 Is 0<=A<=M-m (i.e. m<=R<=M)?
$254F BCS $2547 Branch back to generate another random value if not.
$2551 RTS Return without first adding m back to A to get R. (This is a bug.)
Prev: $2500 Up: Map Next: $2552