Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- byte RandSeed1 = 0;
- byte RandSeed2 = 0;
- byte TempRand1;
- byte TempRand2;
- void randInit2(byte a,byte b) {
- RandSeed1 = a;
- RandSeed2 = b;
- }
- asm byte randInt() {
- // This is the mathematical random number generator from the Commodore 64
- // implementation of Boulder Dash I. The 6510 disassembly is given in
- // comments, and the C translation follows.
- // http://www.elmerproductions.com/sp/peterb/insideBoulderdash.html#Random%20numbers
- lda RandSeed1
- ror
- ror
- and #$80
- sta TempRand1
- lda RandSeed2
- ror
- and #$7F
- sta TempRand2
- lda RandSeed2
- ror
- ror
- and #$80
- clc
- adc RandSeed2
- adc #$13
- sta RandSeed2
- lda RandSeed1
- adc TempRand1
- adc TempRand2
- sta RandSeed1
- rts
- }
- byte randIntRange(byte range) {
- word v;
- byte r;
- r = range;
- v = randInt();
- v = v * r;
- v = v / 256;
- return v.lo;
- }
- byte randIntRange2(byte lo,byte hi) {
- word v;
- byte r;
- r = hi-lo+1;
- v = randInt();
- v = v * r;
- v = v / 256;
- v = v + lo;
- return v.lo;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement