home *** CD-ROM | disk | FTP | other *** search
- PAGE 60,132
- TITLE fxSR.ASM -- PCX F/X
- SUBTTL Copyright (c) Genus Microprogramming, Inc. 1988-89
-
- ; fxSR.ASM ;
- ; Copyright (c) Genus Microprogramming, Inc. 1988-89 All Rights Reserved. ;
-
- ;****************************************************************************;
- ; ;
- ; This file contains procedures for setting a random number seed, and for ;
- ; getting a random number. These are INTERNAL routines. ;
- ; ;
- ; Procedures: fxSetRand ;
- ; fxGetRand ;
- ; ;
- ; Microsoft ASM 5.x version. Programmer: Chris Howard 5/04/89 ;
- ; ;
- ;****************************************************************************;
-
- ; Include files
- INCLUDE ..\inc\pcxDefs.inc
- INCLUDE ..\inc\pcxMacs.inc
- INCLUDE ..\inc\pcxErrs.inc
-
- INCLUDE ..\inc\fxDefs.inc
- INCLUDE ..\inc\fxMacs.inc
- INCLUDE ..\inc\fxErrs.inc
-
- @SetModel
-
- @BegData
-
- EXTRN fxRand : WORD
-
- @EndData
-
- @BegCode
-
- PUBLIC fxSetRand,fxGetRand
-
- ;**********
-
- ;
- ; This procedure records the given random number seed, for later use by the
- ; fxGetRand function.
- ;
- ; Calling: retcode = fxSetRand(int seed)
- ;
- ;
-
- ;Define variable locations on the stack (pascal model)
- srrand equ <[bp+6]>
- srparm equ 2
-
- ;Define local variables
- srret equ <[bp-2]> ;return code
- srlocal equ 2 ;Total local space needed
-
- fxSetRand PROC FAR
-
- @Entry srlocal ;Set up frame and save regs
-
- mov ax,srrand
-
- mov WORD PTR fxRand,ax ;Store
- mov WORD PTR fxRand[2],0 ; and clear the high word
-
- @SetRet srret,fxSUCCESS ;Set successful code
-
- @Exit srret,srparm ;Return
-
- fxSetRand ENDP
-
- ;**********
-
- ;
- ; This procedure gets the effect type previously set by the fxSetEffect
- ; call.
- ;
- ; Calling: rand = fxGetRand(int range)
- ;
- ;
-
- ;Define variable locations on the stack, depending on model
- grrange equ <[bp+6]>
- grparm equ 2
-
- ;Define local variables
- grret equ <[bp-2]> ;return code
- grlocal equ 2 ;Total local space needed
-
- fxGetRand PROC FAR
-
- @Entry grlocal ;Set up frame and save regs
-
- push bx ;Preserve all regs
- push cx
- push dx
-
- mov ax,0CH ;Set up a bogus number
-
- mov bx,fxRand[2] ;Multiply by random hi word
- mul bx
-
- mov cx,ax ;Keep the result
-
- mov ax,0DADAH ;Get another bogus number
- mul fxRand ; and multiply by random lo word
-
- add cx,ax ;Add to previous result
-
- mov ax,0DADAH ;Get same bogus number
- mul bx ; and multiply by random hi word
-
- add dx,cx ;Add previous result
-
- add ax,0FEEDH ;Add in another bogus number
- adc dx,0CH
-
- mov WORD PTR fxRand,ax ;Store the next seed
- mov WORD PTR fxRand[2],dx
-
- mov ax,dx ;Move into position to return
- and ah,7FH ; and mask, to limit to 32767
-
- xor dx,dx ;Clear hi word
-
- mov bx,grrange ;Get the range
- mul bx ; and multiply
-
- mov bx,7FFFH ;Now divide by 32767
- div bx
-
- @SetRet grret,ax ;Return random number
-
- pop dx ;Restore regs
- pop cx
- pop bx
-
- @Exit grret,grparm ;Return
-
- fxGetRand ENDP
-
- @EndCode
-
- END
-
-