On Sat, 26 Aug 2000, you wrote:
> I've been working on a game for some time now (Bomberman, MAYBE FutureDisk
> will show a demo of it on the Bussum-fair) but I'm having some troubles
> with generating random numbers. I'm now using the refresh register which I
> add to the previous offset in a look-up table, but it isn't random enough
> for me. And the math-pack is too slow to be of any use. Does somebody have
> a fast algorythm/code (assembly) for me?
Below I pasted an assembly source of a random number generator that uses an
algorithm based on multiplication with a prime number and XOR-ing with a
fixed mask.
In its current form, it produces numbers in the range 0..27, but you can
easily change that. You have to know that the middle bits of the seed are the
most "random", so use those for the result.
;============================================================================
; RANDOM.ASM
; JoyNet Tetris
; Kryten/Mayhem 1998
;============================================================================
BDOS: equ #F37D
BDOS_GTIME: equ #2C
RANDOM_PATTERNH: equ #B5
RANDOM_PATTERNL: equ #AD
randomInit:
;In: -
;Out: RandomSeed initialised
;Chg: HL, DE, BC, AF
;Note: calls BDOS
ld c,BDOS_GTIME
call BDOS
ld a,l
add a
add a
add h
xor d
ld l,a
ld a,r
ld h,a
ld (RandomSeed),hl
ret
randomNext:
;In: RandomSeed
;Out: A = random value 0-27
; RandomSeed updated
;Chg: HL, BC, F
ld hl,(RandomSeed)
ld c,l
ld b,h
add hl,hl ;2x
add hl,bc ;3x
add hl,hl ;6x
add hl,bc ;7x
add hl,hl ;14x
add hl,hl ;28x
add hl,bc ;29x
ld a,l
xor RANDOM_PATTERNL
ld l,a
ld a,h
xor RANDOM_PATTERNH
ld h,a
ld (RandomSeed),hl
and %1111 1000
rrca
rrca
rrca
cp 28
jr nc,randomNext
ret
RandomSeed:
dw 0
;============================================================================
; End of RANDOM.ASM
;============================================================================
Bye,
Maarten
****
Problems? contact [EMAIL PROTECTED] See also http://www.faq.msxnet.org/
****