daily pastebin goal
81%
SHARE
TWEET

rand (eZ80 optimized)

Zeda Jan 12th, 2017 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rand:
  2. ;;Input: A is the range.
  3. ;;Output: Returns in A a random number from 0 to (input)A-1.
  4. ;;  B=0
  5. ;;  DE is a pseudo-random 16-bit integer.
  6. ;;Destroys:
  7. ;;  HL
  8. ;;Speed:
  9.     push af
  10.     call prng24
  11.     ex de,hl
  12.     pop af
  13.     or a \ sbc hl,hl
  14.     ld b,h
  15.     add a,a \ jr nc,$+5 \ push de \ pop hl
  16.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
  17.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
  18.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
  19.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
  20.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
  21.     add hl,hl \ rla \ jr nc,$+4 \ add hl,de \ adc a,b
  22.     add hl,hl \ rla \ ret nc \ add hl,de \ adc a,b
  23.     ret
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top