[comp.sys.atari.st] problems with rnd# from assembler

gdr@pbhya.UUCP (Guy Ridley) (05/19/87)

Does anyone have some good documentation on calling trap #17 (the random
number generator) from assembler?  Acc'd to what I have the rnd# generator
is reseeded when the machine is turned on, and calling trap #17 puts a
random number in D0.  However, what I seem to be getting (based on what
note comes out of my synthesizer, to which the contents of D0 are sent via
MIDI) is a lot of decimal "40"'s.  This is completely mystifying, and the
Assempro documentation doesn't say much more that "ST Internals" does.
Can anyone send me a small sample of such a call that works? 
 
Also, I would like to communicate with others who are doing MIDI & Assembler.
My synth is a DX-7.

john@viper.Lynx.MN.ORG (John Stanley) (05/19/87)

In article <2088@pbhya.UUCP> gdr@pbhya.UUCP (Guy Ridley) writes:
 >
 >Does anyone have some good documentation on calling trap #17 (the random
 >number generator) from assembler?  Acc'd to what I have the rnd# generator
 >is reseeded when the machine is turned on, and calling trap #17 puts a
 >random number in D0.  However, what I seem to be getting (based on what
 >note comes out of my synthesizer, to which the contents of D0 are sent via
 >MIDI) is a lot of decimal "40"'s.  This is completely mystifying, and the
 >Assempro documentation doesn't say much more that "ST Internals" does.
 >Can anyone send me a small sample of such a call that works? 
 > 

  No, no, no...  It's xbios subfunction 17, NOT trap 17..  
(God knows what's on trap 17...)

  Try:
	move.w	#17,-(sp)
	trap	#14
	addq.l	#2,sp		* random number now in D0

  I haven't tried it, but I also haven't heard about anyone else
having problems with it, so it "should" work.  (Note:  The random
number returned is only 24 bits long so you'll only get from zero
to 16777215 ($00ffffff)...)

--- 
John Stanley (john@viper.UUCP)
Software Consultant - DynaSoft Systems
UUCP: ...{amdahl,ihnp4,rutgers}!{meccts,dayton}!viper!john

makaiwi@cory.Berkeley.EDU (Hikaru Ichijo, Valkyrie Pilot SDF Macross) (05/20/87)

In article <1021@viper.Lynx.MN.ORG> john@viper.UUCP (John Stanley) writes:
>
>  No, no, no...  It's xbios subfunction 17, NOT trap 17..  
>(God knows what's on trap 17...)
>
>  Try:
>	move.w	#17,-(sp)
>	trap	#14
>	addq.l	#2,sp		* random number now in D0
>
>  I haven't tried it, but I also haven't heard about anyone else
>having problems with it, so it "should" work.  (Note:  The random
>number returned is only 24 bits long so you'll only get from zero
>to 16777215 ($00ffffff)...)
>
>John Stanley (john@viper.UUCP)

The code is correct, but it hangs my machine.  At least it did the last ten
times I tried to generate random numbers in assembly language (no problems
from Pascal).  Is there a speed limit on XBIOS(17)?  I was using it to
generate random 16-bit values to fill the screen with garbage.  Did not
work until I remove the 'trap #14' instruction.  Any ideas what is wrong?

	H. Ichijo

---
I am posting this for a friend without net access, I will forward replies
to him.
	Jeff Makaiwi

braner@batcomputer.tn.cornell.edu (braner) (05/21/87)

[]

I don't know whether xbios(17) works or not: I don't trust system-supplied
random number generators for statistical reasons (and purpose).

I have my own assembly-langauge random generator that yields a 32-bit
number in about 20 microseconds, and it passed all the statistical tests
I tried (uniformity, runs in halftiles, 2d lagged-correlation plots...).
(If you only need 16 bits you can make it faster still!)
I also have an AL extension to convert it to a FP number in (0,1).  It takes
about 60 microsecs to call from C and get a double var stuffed.

- Moshe Braner