Prev: 09717 Up: Map Next: 09767
09720: THE 'SCANNING RND' ROUTINE
The address of this routine is derived from an offset found in the scanning function table.
Input
Output
S_RND 09720 CALL SYNTAX_Z Unless syntax is being checked, jump to calculate a random number.
09723 JR Z,S_RND_END
09725 LD BC,(23670) Fetch the current value of SEED.
09729 CALL STACK_BC Put it on the calculator stack.
09732 RST 40 Now use the calculator.
09733 DEFB 161 stk_one
09734 DEFB 15 addition: The 'last value' is now SEED+1.
09735 DEFB 52 stk_data: Put the number 75 on the calculator stack.
09736 DEFB 55,22
09738 DEFB 4 multiply: 'last value' (SEED+1)*75.
09739 DEFB 52 stk_data: Put the number 65537 on the calculator stack.
09740 DEFB 128,65,0,0,128
09745 DEFB 50 n_mod_m: Divide (SEED+1)*75 by 65537 to give a 'remainder' and an 'answer'.
09746 DEFB 2 delete: Discard the 'answer'.
09747 DEFB 161 stk_one
09748 DEFB 3 subtract: The 'last value' is now 'remainder' - 1.
09749 DEFB 49 duplicate: Make a copy of the 'last value'.
09750 DEFB 56 end_calc: The calculation is finished.
09751 CALL FP_TO_BC Use the 'last value' to give the new value for SEED.
09754 LD (23670),BC
09758 LD A,(HL) Fetch the exponent of 'last value'.
09759 AND A Jump forward if the exponent is zero.
09760 JR Z,S_RND_END
09762 SUB 16 Reduce the exponent, i.e. divide 'last value' by 65536 to give the required 'last value'.
09764 LD (HL),A
S_RND_END 09765 JR S_PI_END Jump past the S_PI routine.
Prev: 09717 Up: Map Next: 09767