Advertisement
Chdata

1024's GetRand Subroutine

Apr 4th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;-------------------------------; Random Number Generator
  2. GetRand:                        ; By: 1024
  3.     PHY                         ; Comments By: Fakescaper
  4.     LDY #$01                    ;
  5.     JSR .Maths                  ;
  6.     DEY                         ;
  7.     JSR .Maths                  ;
  8.     PLY                         ;
  9.     RTL                         ;
  10. .Maths  LDA $148B               ;
  11.     ASL #2                      ;
  12.     SEC                         ;
  13.     ADC $148B                   ;
  14.     STA $148B                   ;
  15.     ASL $148C                   ;
  16.     LDA #$20                    ;
  17.     BIT $148C                   ;
  18.     BCC .Label1                 ; If any of the ADC or ASL cleared carry,
  19.     BEQ .Label2                 ; reverse the results of the BIT test
  20.     BNE .Label3                 ;
  21. .Label1  BNE .Label2            ;
  22. .Label3                         ;
  23.     INC $148C                   ; when determining whether or not we INC
  24. .Label2                         ;
  25.     LDA $148C                   ;
  26.     EOR $148B                   ;
  27.     STA $148D,Y                 ; Output gets stored in this RAM Address, 16 bit result.
  28.     RTS                         ; You might want to add an ADC $13 or SBC $94 before this STA for extra "random"
  29. ;-------------------------------; (or you can just do it after calling this routine)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement