Trying to generate a series of random numbers on my Commodore 64 (C64) using JSR $E09A and retrieving the number from $63 and $64. (which according to all the documentation I've seen is the same routine when you use RND(0) from BASIC. But can't get it to iterate. The following will work and place a different number in $63 and $64 when executed by itself.
. C000 A5 00 LDA $00
. C002 20 9A E0 JSR $E09A
. C005 00 BRK
Now when I try to iterate say 10 times with the following code, it never returns.
. C000 A0 0A LDY #$0A
. C002 A9 00 LDA #$00
. C004 20 9A E0 JSR $E09A
. C007 88 DEY
. C008 D0 F8 BNE $C002
. C00A 00 BRK
Am I missing something so obvious I can't see it. I'm not worried about how "random" it is. At this point I just want a series of random numbers.
The SID chip can actually generate numbers that are more random than BASIC's pseudo-random numbers. Start the generator with:
LDA #$FF ; maximum frequency value
STA $D40E ; voice 3 frequency low byte
STA $D40F ; voice 3 frequency high byte
LDA #$80 ; noise waveform, gate bit off
STA $D412 ; voice 3 control register
RTS
Then you can get random numbers whenever you want with:
LDA $D41B ; get random value from 0-255
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With