Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: awanderin Newsgroups: comp.sys.apple2.programmer Subject: Re: ProDOS and the random seed RNDL Date: Tue, 22 Dec 2015 23:38:25 -0700 Organization: A noiseless patient Spider Lines: 69 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="3f7daab8c080c0d7ccea7a857596d713"; logging-data="3117"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qTahffe2IJIWWUs4ipA5qgeWmrOEE2L8=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:dpSCk8qLPn8+NFDK6ObNIxHjnBc= sha1:+QhLguLYry/uXNiROVUA5yRT9DE= Xref: csiph.com comp.sys.apple2.programmer:2016 D Finnigan writes: > Since converting the Marina IP source from DOS 3.3 to ProDOS, I've noticed > that link-local addresses, which were previously randomly generated, were no > longer random. I took the time to track down this issue yesterday. > > I'm using ProDOS 8 v1.9 on an enhanced (platinum) Apple IIe but I believe > all versions of ProDOS have this problem. > > I had been using RNDL and RNDH ($4E and $4F) as my random seed. I put > together this program to test what was happening: > > A5 4E > 20 DA FD > A5 4F > 20 DA FD > 4C D0 03 > > ]BRUN RND > 0D80 > > *8000G > 958E > > When I saved it as RND and did BRUN from the Applesoft prompt, I always got > 0D80. But when I ran the program using the Monitor G command, I got changing > results, which is what I expected. It looked like ProDOS was setting RNDL > and RNDH to some constant value. Neither the white ProDOS Technical > Reference Manual nor Gary B. Little's Apple ProDOS book mentioned this > behavior. Nor could I find any mention of it from searching these > newsgroups. > > Poking around in the LC RAM area for ProDOS I found this code at $E189: > LDY #1 > LDA ($40),y > STA $4E > INY > LDA ($40),Y > STA $4F > > I went back to the ProDOS 8 source in MliSrc.aii and found that it's a part > of the get_prefix routine: > > getprefx clc ; calculate how big a buffer is needed to > ldy #c_path ; get index to users pathname buffer > lda (par),y > sta usrbuf > iny > lda (par),y > sta usrbuf+1 > > So it is seen that RNDL and RNDH are being used as part of a buffer for > ProDOS. > > My work-around was to insert a call to GETLN ($FD6A) at the beginning of > Marina in order to reseed the random number. > > Hum-ho. Nice detective work! I don't know the internals of Marina, but if you have control of when ProDOS is called, perhaps Get_Prefix in particular, you could just save RNDL/H on the stack before issuing the MLI call. Having to call an interactive routine seems an ugly workaround unless you actually want some user input. -- Jerry awanderin at gmail dot com