home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / MAXONC3_6OF8.DMS / in.adf / LIBSRC.LHA / LIBSRC / random.asm < prev    next >
Encoding:
Assembly Source File  |  1994-04-15  |  894 b   |  66 lines

  1.  
  2. * Maxon C++ Library:
  3. * Modul "random"
  4. * Jens Gelhar 24.09.91, 15.04.94
  5.  
  6.     xdef    _srand,srand__Ui
  7.     xdef    _rand,rand_
  8.     xdef    Random_,Random__Ui
  9.  
  10.     xref    uintdiv
  11.  
  12. _srand:
  13. srand__Ui:
  14.     move.l    4(a7),LastRand
  15.     rts
  16.  
  17. _rand:
  18. rand_:    move.l    LastRand(pc),d0
  19.     mulu    #26731,d0
  20.     add.l    #47110815,d0
  21.     move.l    d0,LastRand
  22.     and.l    #$7FFF,d0
  23.     rts
  24.  
  25. Random__Ui:    ; Stackparameter: int
  26.     move.l    d1,-(a7)
  27.     bsr.b    SpecialRand
  28.     move.l    8(a7),d1
  29.     jsr    uintdiv
  30.     move.l    d1,d0
  31.     move.l    (a7)+,d1
  32.     rts
  33.  
  34. Random_:
  35.     ; Double zurückgeben:
  36.     move.l    d2,-(a7)
  37.     bsr.b    SpecialRand
  38.     move.l    d0,d1
  39.     bsr.b    SpecialRand
  40.     and.l    #$000FFFFF,d0
  41.     move.l    #$3FF,d2
  42. .loop    btst    #20,d0
  43.     bne.b    .end
  44.     subq.w    #1,d2
  45.     rol.l    #1,d1
  46.     roxl.l    #1,d0
  47.     bra.b    .loop
  48. .end    bclr    #20,d0
  49.     swap    d2
  50.     asl.l    #4,d2
  51.     or.l    d2,d0
  52.     move.l    (a7)+,d2
  53.     rts
  54.  
  55. SpecialRand:
  56.     move.l    LastRand(pc),d0
  57.     mulu    #26731,d0
  58.     add.l    #47110815,d0
  59.     add.l    $DFF004,d0
  60.     move.l    d0,LastRand
  61.     rts
  62.  
  63. LastRand:    blk.l 1
  64.  
  65.     end
  66.