Advertisement
paul_nicholls

boulder dash random number

Feb 12th, 2020 (edited)
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.02 KB | None | 0 0
  1. byte RandSeed1 = 0;
  2. byte RandSeed2 = 0;
  3. byte TempRand1;
  4. byte TempRand2;
  5.  
  6. void randInit2(byte a,byte b) {
  7.   RandSeed1 = a;
  8.   RandSeed2 = b;
  9. }
  10.  
  11. asm byte randInt() {
  12. // This is the mathematical random number generator from the Commodore 64
  13. // implementation of Boulder Dash I. The 6510 disassembly is given in
  14. // comments, and the C translation follows.
  15. // http://www.elmerproductions.com/sp/peterb/insideBoulderdash.html#Random%20numbers
  16.  
  17.   lda RandSeed1
  18.   ror
  19.   ror
  20.   and #$80
  21.   sta TempRand1
  22.  
  23.   lda RandSeed2
  24.   ror
  25.   and #$7F
  26.   sta TempRand2
  27.  
  28.   lda RandSeed2
  29.   ror
  30.   ror
  31.   and #$80
  32.   clc
  33.   adc RandSeed2
  34.  
  35.   adc #$13
  36.   sta RandSeed2
  37.  
  38.   lda RandSeed1
  39.   adc TempRand1
  40.  
  41.   adc TempRand2
  42.   sta RandSeed1
  43.   rts
  44. }
  45.  
  46. byte randIntRange(byte range) {
  47. word v;
  48. byte r;
  49.   r = range;
  50.   v = randInt();
  51.   v = v * r;
  52.   v = v / 256;
  53.   return v.lo;
  54. }
  55.  
  56. byte randIntRange2(byte lo,byte hi) {
  57. word v;
  58. byte r;
  59.   r = hi-lo+1;
  60.   v = randInt();
  61.   v = v * r;
  62.   v = v / 256;
  63.   v = v + lo;
  64.  
  65.   return v.lo;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement