2474
|
1 ***************************************
|
|
2
|
|
3 * Subroutine to calc. a random number
|
|
4 * Based on routine by L.A. Middaugh
|
|
5 * The Rainbow Jan/85 p. 277
|
|
6
|
|
7 * Value truncated so that it is =>0 and <=passed value in D.
|
|
8
|
|
9 * OTHER MODULES NEEDED: none
|
|
10
|
|
11 * ENTRY: D=max value of number to be returned
|
|
12 * EXIT: D = value
|
|
13
|
|
14
|
|
15 nam Rnd
|
|
16 ttl Assembler Library Module
|
|
17
|
|
18
|
|
19 psect Rnd,0,0,0,0,0
|
|
20
|
|
21 vsect dp
|
|
22
|
|
23 SEED rmb 4
|
|
24
|
|
25 endsect
|
|
26
|
|
27 RND:
|
|
28 pshs d,x,u
|
|
29
|
|
30 rnd0
|
|
31 ldx #SEED point to seed
|
|
32 ldb #8 number of shifts
|
|
33 loop
|
|
34 lda 3,x exclusive or bit 28 with 31
|
|
35 rora
|
|
36 rora
|
|
37 rora
|
|
38 eora 3,x
|
|
39 rora result in carry
|
|
40 rora
|
|
41 ror 0,x rotate carry into bit0
|
|
42 ror 1,x
|
|
43 ror 2,x
|
|
44 ror 3,x
|
|
45 decb do 8 times
|
|
46 bne loop
|
|
47 ldd 1,x get rnd value
|
|
48 bne trunc ensure we never return a 0
|
|
49 inc 1,x fudge it so we get a non-zero
|
|
50 inc 3,x
|
|
51 bra rnd0
|
|
52
|
|
53 trunc
|
|
54 cmpd ,s in range specified?
|
|
55 bls exit yes
|
|
56 subd ,s
|
|
57 bra trunc
|
|
58
|
|
59 exit
|
|
60 leas 2,s forget original D
|
|
61 puls x,u,pc
|
|
62
|
|
63
|
|
64 **********************************************
|
|
65 *
|
|
66 * Subroutine to seed the random number buffer
|
|
67 * with the current system date
|
|
68
|
|
69 * ENTRY: none
|
|
70 * EXIT: none
|
|
71
|
|
72 SEEDRND:
|
|
73 pshs d,x
|
|
74 leas -6,s make room for date
|
|
75 tfr s,x point X to buffer
|
|
76 os9 F$Time
|
|
77 addd 4,x add min/secs to value in D
|
|
78 addd <SEED add to orig value
|
|
79 std <SEED set msb of seed
|
|
80 addd <SEED+2 add lsb of seed to new msb
|
|
81 std <SEED+2
|
|
82 leas 6,s
|
|
83 puls d,x,pc
|
|
84
|
|
85 endsect
|