nineko, on Dec 19 2008, 04:32 PM, said:
Is the andi really needed, since tst will check one bit anyway?
You're confusing BTST and TST. TST will test the whole operand (according to its size attribute), while BTST will test a single bit, which is specified in the left operand.
Anthall, if your number of outcomes is a power of 2 (2, 4, 8, 16, etc.), it's quite easy to set up:
Syntax Highlighted Code: ASM
[color= #00bfff;]jsr[/color] RandomNumber [color= #adadad; font-style: italic;]; call the pseudo-random number generator[/color]
[color= #00bfff;]andi[/color].[color= #00bfff;]b[/color] [color= #ff0000;]#[/color]xx,d0 [color= #adadad; font-style: italic;]; restrict the number to a valid range[/color]
[color= #00bfff;]move[/color].[color= #00bfff;]w[/color] RandomJumps(pc,d0.[color= #00bfff;]w[/color]),d0
[color= #00bfff;]jsr[/color] RandomJumps(pc,d0.[color= #00bfff;]w[/color]) [color= #adadad; font-style: italic;]; call a random jump routine[/color]
[color= #adadad; font-style: italic;]; code continues here[/color]
RandomJumps:
[color= #00bfff;]dc[/color].[color= #00bfff;]w[/color] RandomJump1-RandomJumps
[color= #00bfff;]dc[/color].[color= #00bfff;]w[/color] RandomJump2-RandomJumps
[color= #00bfff;]dc[/color].[color= #00bfff;]w[/color] RandomJump3-RandomJumps
[color= #00bfff;]dc[/color].[color= #00bfff;]w[/color] RandomJump4-RandomJumps
RandomJump1:
[color= #adadad; font-style: italic;]; code here[/color]
[color= #00bfff;]rts[/color] [color= #adadad; font-style: italic;]; don't forget the rts![/color]
[color= #adadad; font-style: italic;]; do the same for all other RandomJump routines[/color]
In the code above, replace xx with (the number of outcomes - 1) * 2 (still assuming it's a power of 2), e.g. for 16 outcomes, use (16-1)*2 = 30 (or $1E in hex). If the number of outcomes isn't a power of 2, you'll have to use a modulo instead of ANDI; use the DIVU instruction for that (which is much slower).