home *** CD-ROM | disk | FTP | other *** search
- ;
- ; SYSLIB Module Name: SRAND
- ; Author: Richard Conn
- ; SYSLIB Version Number: 3.6
- ; Module Version Number: 1.1
-
- public rnd,rndinit,rndseed
- ;
- ; EXTERNALS
- ;
- EXT PRINT
- EXT CONDIN
-
- ;
- ; RNDINIT -- INITIALIZE RANDOM NUMBER GENERATOR
- ; THIS ROUTINE PROMPTS THE USER FOR A KEYPRESS, AND THEN SETS THE
- ; SEE VALUE FOR THE RANDOM NUMBER GENERATOR (8-BIT)
- ; NO INPUT OR OUTPUT PARAMETERS
- ; GENERALLY, IT IS LEFT TO THE USER TO PRINT A MESSAGE BEFORE THIS ROUTINE
- ; IS CALLED
- ;
- RNDINIT:
- PUSH AF ; SAVE REGS
- PUSH BC
- LD B,0 ; START AT 0
- RNDIL:
- INC B ; INCREMENT SEED
- CALL CONDIN ; INPUT?
- JP Z,RNDIL
- LD A,B ; GET SEED
- RNDID:
- LD (SEED),A ; SAVE IT FOR LATER
- CALL RND ; GENERATE A RANDOM NUMBER
- LD (ADDEND),A ; SAVE A INITIAL ADDEND
- POP BC ; RESTORE REGS
- POP AF
- RET
-
- ;
- ; RNDSEED -- ALLOW USER TO SPECIFY A SEED VALUE FOR THE RANDOM NUMBER GEN
- ; SEED IS PASSED IN A; NO REGS AFFECTED
- ;
- RNDSEED:
- PUSH AF ; SAVE REGS
- PUSH BC
- JP RNDID ; SAVE SEED AND GENERATE ADDEND
-
- ;
- ; RANDOM NUMBER SEED VALUE
- ;
- SEED:
- DS 1 ; 1 BYTE
- ADDEND:
- DS 1 ; ADDEND
-
- ;
- ; RANDOM NUMBER GENERATOR
- ; RANDOM NUMBER RETURNED IN A
- ;
- RND:
- PUSH HL ; DON'T AFFECT HL
- LD HL,SEED ; PT TO SEED
- LD A,(HL) ; GET IT
- RLCA ; PLAY WITH IT
- XOR (HL)
- RRCA
- INC HL ; PT TO ADDEND
- INC (HL) ; INCREMENT IT
- ADD A,(HL) ; ADD IN ADDEND
- JP PE,SKIP
- INC (HL) ; INCREMENT ADDEND AGAIN
- SKIP:
- DEC HL ; PT TO SEED AGAIN
- LD (HL),A ; SAVE NEW SEED
- POP HL ; RESTORE HL
- RET
-
- END