view lib/alib/rnd.as @ 3141:717ced83b885

coco3: Build SD card device descriptors for CoCo3FPGA Added "CC3FPGAFLAGS = $(AFLAGS) -DCC3FPGA=1 $(FLAGS)" to "level2/coco3/modules/makefile" for flagging Coco3FPGA specific features in modules sources. Added "llcoco3fpga", "ddsd0_coco3fpga", "sd0_coco3fpga", and "sd1_coco3fpga" to the "coco3/modules/makefile" - RBF section, which also now adds all to the "NITROS9/MODULES/RBF" on all disk images for building new Coco3FPGA disks from NitrOS9. Added new descriptor section to the "level2/coco3/modules/makefile" reflecting the new Coco3FPGA SD card descriptors and their flags.
author Bill Pierce <merlinious999@gmail.com>
date Sat, 04 Feb 2017 11:06:28 +0100
parents 03f26e88b809
children
line wrap: on
line source

***************************************

* 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


 section .bss

SEED rmb 4

 endsect

 section .text

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