Greetings,
As we are going to get rid of ROM in Space 1999, I need to replace the random number generator routine with one of my own. I don't need anything sophisticated, so it would be best if it is quick and compact.
Any ideas out there?
Of course one can allways copy the ROM routine (I don't have it, btw), but I wondered if there was any simpler and more elegant solution for this case.
Cheers.
Random number generator
Perhaps either of these two can be used?
http://www.ffd2.com/fridge/math/rand1.s
http://www.ffd2.com/fridge/math/rand2.s
You might also be interested in the books "Numerical Recipes", available online (through a free subscription system called FileOpen) in editions for C, Fortran 77 and Fortran 90:
http://www.nrbook.com/a/
Through those books, you could navigate yourself through handy algorithms for random number generators (and a lot more) and find one to implement if you don't have pseudo code from someplace else.
http://www.ffd2.com/fridge/math/rand1.s
http://www.ffd2.com/fridge/math/rand2.s
You might also be interested in the books "Numerical Recipes", available online (through a free subscription system called FileOpen) in editions for C, Fortran 77 and Fortran 90:
http://www.nrbook.com/a/
Through those books, you could navigate yourself through handy algorithms for random number generators (and a lot more) and find one to implement if you don't have pseudo code from someplace else.
Anders Carlsson
Well, you can find one in the 4KKong archive here:
http://www.defence-force.org/download/4kkong.zip
First some variables:
Then we need to initialise the values before first use
Then the routine itself:
For what I remember, the output of the two values is very different, one is "more random" than the other, and some bits are very not random.
Let's say it was good enough for my 4K Kong game
http://www.defence-force.org/download/4kkong.zip
First some variables:
Code: Select all
rand_low .dsb 1 ;// Random number generator, low part
rand_high .dsb 1 ;// Random number generator, high part
Code: Select all
lda #23
sta rand_low
lda #35
sta rand_high
Code: Select all
_GetRand
lda rand_high
sta b_tmp1
lda rand_low
asl
rol b_tmp1
asl
rol b_tmp1
asl
rol b_tmp1
asl
rol b_tmp1
clc
adc rand_low
pha
lda b_tmp1
adc rand_high
sta rand_high
pla
adc #$11
sta rand_low
lda rand_high
adc #$36
sta rand_high
rts
Let's say it was good enough for my 4K Kong game