Mercurial > hg > Members > kono > nitros9-code
diff lib/alib/rnd.a @ 2474:7d70b7e1cb21
Moved net and alib files into here
author | boisy |
---|---|
date | Tue, 30 Mar 2010 02:44:42 +0000 |
parents | |
children | aaba193af04f |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/alib/rnd.a Tue Mar 30 02:44:42 2010 +0000 @@ -0,0 +1,85 @@ +*************************************** + +* Subroutine to calc. a random number +* Based on routine by L.A. Middaugh +* The Rainbow Jan/85 p. 277 + +* Value truncated so that it is =>0 and <=passed value in D. + +* OTHER MODULES NEEDED: none + +* ENTRY: D=max value of number to be returned +* EXIT: D = value + + + nam Rnd + ttl Assembler Library Module + + + psect Rnd,0,0,0,0,0 + + vsect dp + +SEED rmb 4 + + endsect + +RND: + pshs d,x,u + +rnd0 + ldx #SEED point to seed + ldb #8 number of shifts +loop + lda 3,x exclusive or bit 28 with 31 + rora + rora + rora + eora 3,x + rora result in carry + rora + ror 0,x rotate carry into bit0 + ror 1,x + ror 2,x + ror 3,x + decb do 8 times + bne loop + ldd 1,x get rnd value + bne trunc ensure we never return a 0 + inc 1,x fudge it so we get a non-zero + inc 3,x + bra rnd0 + +trunc + cmpd ,s in range specified? + bls exit yes + subd ,s + bra trunc + +exit + leas 2,s forget original D + puls x,u,pc + + +********************************************** +* +* Subroutine to seed the random number buffer +* with the current system date + +* ENTRY: none +* EXIT: none + +SEEDRND: + pshs d,x + leas -6,s make room for date + tfr s,x point X to buffer + os9 F$Time + addd 4,x add min/secs to value in D + addd <SEED add to orig value + std <SEED set msb of seed + addd <SEED+2 add lsb of seed to new msb + std <SEED+2 + leas 6,s + puls d,x,pc + + endsect