Jump to content

Photo

Help with seeding rand values in DPC+


3 replies to this topic

#1 gbennett0321 OFFLINE  

gbennett0321

    Space Invader

  • 25 posts
  • Location:South Jordan, UT

Posted Fri Feb 9, 2018 4:24 AM

I am working on a DPC+ BB game, and would like to seed the random number generator so I can reproduce the same ordered sequence of random numbers. If I set (seed) the standard 'rand' variable in a non-DPC+ kernel, the 'rand' call always return the same ordered random results as predicted. However, when seeding the 'rand16' variable I was unable to generate a predictable random sequence.

 

Now that I have moved to the DPC+ kernel, I have no idea how to seed its 32-bit rand value (or if it is even possible). I tried assigning rand to a seed value, but it doesn't appear to have any effect on the random sequence.  

Does anyone know how to seed the DPC+ rand variable to generate a predictable random sequence?

 

If I can't seed the DPC+ rand value, is it somehow possible to use the standard 'rand' call in a DPC+ build (which does appear to work as expected)?

 

Any help would be appreciated.

 

GB



#2 Mountain King OFFLINE  

Mountain King

    Dragonstomper

  • 684 posts
  • Location:Philadelphia, PA

Posted Fri Feb 9, 2018 6:40 AM

I sequenced my trees in The Terrible blizzard of firn by calling an empty data table.

 

 h=otree[p]

 

p was the screen counter.

 

Then otree looked like this.

 

 data otree

end

 

 I found it would populate the same values in the same order every time.

 

I'm not sure if that helps you, but that's how I did it.


Edited by Mountain King, Fri Feb 9, 2018 6:42 AM.


#3 bogax OFFLINE  

bogax

    Dragonstomper

  • 761 posts

Posted Fri Feb 9, 2018 7:28 AM

from the DPCplus.h file

 

;----------------------------------------
; Random Number Initialization
;----------------------------------------
; The random number generate defaults to a value that spells out DPC+.
; Store any value to RRESET to set the random number back to DPC+, or you
; can use RWRITE0-3 to change the 32 bit value to anything you desire.
;
; reset random number
; LDA #0
; STA RRESET
;
; set a specific random number (spells out 2600)
; LDA #$32
; STA RWRITE0
; LDA #$36
; STA RWRITE1
; LDA #$30
; STA RWRITE2
; STA RWRITE3
;
; NOTE: do not set all 4 bytes to 0, as that will disable the generator.
;----------------------------------------
RRESET        DS 1    ; $70
RWRITE0       DS 1    ; $71
RWRITE1       DS 1    ; $72
RWRITE2       DS 1    ; $73
RWRITE3       DS 1    ; $74


#4 gbennett0321 OFFLINE  

gbennett0321

    Space Invader

  • Topic Starter
  • 25 posts
  • Location:South Jordan, UT

Posted Fri Feb 9, 2018 10:38 AM

 

from the DPCplus.h file

 

;----------------------------------------
; Random Number Initialization
;----------------------------------------
; The random number generate defaults to a value that spells out DPC+.
; Store any value to RRESET to set the random number back to DPC+, or you
; can use RWRITE0-3 to change the 32 bit value to anything you desire.
;
; reset random number
; LDA #0
; STA RRESET
;
; set a specific random number (spells out 2600)
; LDA #$32
; STA RWRITE0
; LDA #$36
; STA RWRITE1
; LDA #$30
; STA RWRITE2
; STA RWRITE3
;
; NOTE: do not set all 4 bytes to 0, as that will disable the generator.
;----------------------------------------
RRESET        DS 1    ; $70
RWRITE0       DS 1    ; $71
RWRITE1       DS 1    ; $72
RWRITE2       DS 1    ; $73
RWRITE3       DS 1    ; $74

 

Thanks, that's exactly what I need. I stupidly didn't even bother to look at the assembly code.

 

GB


Edited by gbennett0321, Fri Feb 9, 2018 12:40 PM.





0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users