Subject: Re: [stella] ASM comparison question From: "B. Watson" <atari@xxxxxxxxxxxxxx> Date: Wed, 25 May 2005 13:03:37 -0400 |
On Wed, 25 May 2005, Dennis Debro wrote: > > jsr getRandomByte ; byte is 0-255 > > lsr a ; now it's 0-127, carry may or may not be set > > adc #9 ; now it's 9-137, done > > sta whereever > > I like this one. Sure the right side get's cheated but I'm okay with the > max here. If this is the only place you ever use getRandomByte, you could change it to a routine that gets 7 random bits in the first place, and avoid the LSR... however, your range then becomes 9-136 (or 10-137, depending how the getRandom* routine leave the carry flag). It's also possible to write a getRandomByte routine with multiple entry points, so you can get any number of random bits as needed. Assuming the existence of a getRandomBit that returns a random bit in the carry flag: getRandomByte: jsr getRandomBit rol a ; You need to make sure A is zero before calling any of the ; getRandom0to* entry points! ; Use something like: ; lda #0 ; jsr getRandom0to7 ; This could be hidden behind macros... getRandom0to127: jsr getRandomBit rol a getRandom0to63: jsr getRandomBit rol a getRandom0to31: jsr getRandomBit rol a getRandom0to15: jsr getRandomBit rol a getRandom0to7: jsr getRandomBit rol a getRandom0to3: jsr getRandomBit rol a getRandom0to1: ; not very useful, really jsr getRandomBit rol a rts ...Of course this wastes a lot of bytes. It might be better to write a loop version of it, that takes a parameter (number of bits), but it'd be a bit slower... Probably no 2600 game would ever need this, anyway. It's just an exercise.. > BTW, I don't know why my responses haven't been showing up. Then again > maybe they are and they're just not coming to me. I'm seeing them just fine... -- B. Archives (includes files) at http://www.biglist.com/lists/stella/archives/ Unsub & more at http://stella.biglist.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [stella] ASM comparison questio, Dennis Debro | Thread | Re: [stella] ASM comparison questio, eeid |
Re: [stella] ASM comparison questio, Dennis Debro | Date | Re: [stella] sample of Atari sounds, Glenn Saunders |
Month |