home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c011 / 1.ddi / SOURCE / FXSR.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-06-01  |  4.5 KB  |  148 lines

  1.   PAGE    60,132
  2.   TITLE   fxSR.ASM -- PCX F/X
  3.   SUBTTL  Copyright (c) Genus Microprogramming, Inc. 1988-89
  4.  
  5. ; fxSR.ASM                                                                   ;
  6. ; Copyright (c) Genus Microprogramming, Inc. 1988-89  All Rights Reserved.   ;
  7.  
  8. ;****************************************************************************;
  9. ;                                                                            ;
  10. ; This file contains procedures for setting a random number seed, and for    ;
  11. ; getting a random number. These are INTERNAL routines.                      ;
  12. ;                                                                            ;
  13. ; Procedures: fxSetRand                                                      ;
  14. ;             fxGetRand                                                      ;
  15. ;                                                                            ;
  16. ; Microsoft ASM 5.x version.              Programmer: Chris Howard  5/04/89  ;
  17. ;                                                                            ;
  18. ;****************************************************************************;
  19.  
  20. ; Include files
  21.   INCLUDE ..\inc\pcxDefs.inc
  22.   INCLUDE ..\inc\pcxMacs.inc
  23.   INCLUDE ..\inc\pcxErrs.inc
  24.  
  25.   INCLUDE ..\inc\fxDefs.inc
  26.   INCLUDE ..\inc\fxMacs.inc
  27.   INCLUDE ..\inc\fxErrs.inc
  28.  
  29.   @SetModel
  30.  
  31.   @BegData
  32.  
  33.           EXTRN     fxRand                  : WORD
  34.  
  35.   @EndData
  36.  
  37.   @BegCode
  38.  
  39.           PUBLIC    fxSetRand,fxGetRand
  40.  
  41. ;**********
  42.  
  43. ;
  44. ; This procedure records the given random number seed, for later use by the  
  45. ; fxGetRand function.
  46. ;
  47. ; Calling: retcode = fxSetRand(int seed)
  48. ;
  49. ;
  50.  
  51. ;Define variable locations on the stack  (pascal model)
  52. srrand    equ       <[bp+6]>
  53. srparm    equ       2
  54.  
  55. ;Define local variables
  56. srret     equ       <[bp-2]>                ;return code
  57. srlocal   equ       2                       ;Total local space needed
  58.  
  59. fxSetRand           PROC FAR
  60.  
  61.           @Entry    srlocal                 ;Set up frame and save regs
  62.  
  63.           mov       ax,srrand
  64.  
  65.           mov       WORD PTR fxRand,ax      ;Store
  66.           mov       WORD PTR fxRand[2],0    ; and clear the high word
  67.  
  68.           @SetRet   srret,fxSUCCESS         ;Set successful code
  69.  
  70.           @Exit     srret,srparm            ;Return
  71.  
  72. fxSetRand           ENDP
  73.  
  74. ;**********
  75.  
  76. ;
  77. ; This procedure gets the effect type previously set by the fxSetEffect
  78. ; call.
  79. ;
  80. ; Calling: rand = fxGetRand(int range)
  81. ;
  82. ;
  83.  
  84. ;Define variable locations on the stack, depending on model
  85. grrange   equ       <[bp+6]>
  86. grparm    equ       2
  87.  
  88. ;Define local variables
  89. grret     equ       <[bp-2]>                ;return code
  90. grlocal   equ       2                       ;Total local space needed
  91.  
  92. fxGetRand           PROC FAR
  93.  
  94.           @Entry    grlocal                 ;Set up frame and save regs
  95.  
  96.           push      bx                      ;Preserve all regs
  97.           push      cx
  98.           push      dx
  99.  
  100.           mov       ax,0CH                  ;Set up a bogus number
  101.  
  102.           mov       bx,fxRand[2]            ;Multiply by random hi word
  103.           mul       bx
  104.  
  105.           mov       cx,ax                   ;Keep the result
  106.  
  107.           mov       ax,0DADAH               ;Get another bogus number
  108.           mul       fxRand                  ; and multiply by random lo word
  109.  
  110.           add       cx,ax                   ;Add to previous result
  111.  
  112.           mov       ax,0DADAH               ;Get same bogus number
  113.           mul       bx                      ; and multiply by random hi word
  114.  
  115.           add       dx,cx                   ;Add previous result
  116.  
  117.           add       ax,0FEEDH               ;Add in another bogus number
  118.           adc       dx,0CH
  119.  
  120.           mov       WORD PTR fxRand,ax      ;Store the next seed
  121.           mov       WORD PTR fxRand[2],dx
  122.  
  123.           mov       ax,dx                   ;Move into position to return
  124.           and       ah,7FH                  ; and mask, to limit to 32767
  125.  
  126.           xor       dx,dx                   ;Clear hi word
  127.  
  128.           mov       bx,grrange              ;Get the range
  129.           mul       bx                      ; and multiply
  130.  
  131.           mov       bx,7FFFH                ;Now divide by 32767
  132.           div       bx
  133.  
  134.           @SetRet   grret,ax                ;Return random number
  135.  
  136.           pop       dx                      ;Restore regs
  137.           pop       cx
  138.           pop       bx
  139.  
  140.           @Exit     grret,grparm            ;Return
  141.  
  142. fxGetRand           ENDP
  143.  
  144.   @EndCode
  145.  
  146.           END
  147.  
  148.