Re: [stella] Random Numbers

Subject: Re: [stella] Random Numbers
From: "Joe Grand" <joe@xxxxxxxxxxxxxx>
Date: Tue, 27 Jan 2004 12:52:19 -0800
There are a few ways to do pseudo RNGs, but nothing that I'd use for
cryptography :) Erik Mooney posted something back in March 1997 about this
and it's in the archives here:
http://www.biglist.com/lists/stella/archives/199703/msg00296.html

I used the routine in SCSIcide to determine the starting positions and
colors of the data bits. In is here:
http://www.pixelspast.com/games/scsicide/index.php?ID=games&subID=scsicide
and code is here: http://www.pixelspast.com/games/scsicide/scsi131.s.txt

I had to use 4 bytes of RAM:

rand1                   ds      1       ; Variables for random bit/byte
generation routine
rand2                   ds      1
rand3                   ds      1
rand4                   ds      1

Maybe it could be optimized in some way, but it worked well for me.

I had to seed the RNG at the beginning of my game calculations:

JSR  RandomBit  ; Seed the PRNG

And the actual routines are:

;
; rand1, rand2, rand3, rand4 are RAM locations, initialized to any non-zero
; value at program start
;
; RandomBit generates one random bit.
; RandomByte generates one random byte and returns it in the accumulator.
;

RandomBit
        LDA  rand4
        ASL
        ASL
        ASL
        EOR  rand4      ; New bit is now in bit 6 of A
        ASL
        ASL             ; New bit is now in carry
        ROL  rand1      ; Shift new bit into bit 0 of register, bit 7 goes
into carry
        ROL  rand2      ; Shift old bit 7 into bit 8, etc.
        ROL  rand3
        ROL  rand4
        RTS

RandomByte
        LDX  #8
RandomByte1
        JSR  RandomBit
        DEX
        BNE  RandomByte1
        LDA  rand1
        RTS


Have fun,

Joe



---- Original Message ----
From: "David Davies" <davidwyn.davies@xxxxxxxxxxxx>
To: <stella@xxxxxxxxxxx>
Sent: Tuesday, January 27, 2004 12:16 PM
Subject: [stella] Random Numbers

> Just started on a game for the 2600 based on the 1977 arcade game,
> Depthcharge (well, okay, it's a straight port with added game
> variations). It's my first attempt at taming the 2600, so please be
> gentle :-)
>
> I've been doing some thinking as to what needs doing on the game. I
> definately need a random number generator. Is there a way of doing
> that on the 2600?
>
> David Wyn Davies



----------------------------------------------------------------------------------------------
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/


Current Thread