/* These C language subroutines implement random number generation for the runtime library. The Run Time Library for the C Language. Gordon A. Sterling (617) 461 - 3076 DSP Development Tools Engineering Created on 2/14/91 Updated on 5/94 by AS #include
void srand(int seed); int rand(void); */ #include "lib_glob.h" #include "sdl_glob.h" #define a_value 1664525 #define c_value 32767 .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL _rand, _srand; _srand: ram_ireg=___lib_rand_seed; JUMP (PC, restore_state) (DB); FETCH_RETURN rammem(ram_ireg,ram_0)=R4; _rand: ram_ireg=___lib_rand_seed; R2=a_value; /*Base*/ R0=rammem(ram_ireg,ram_0); /*Read seed value*/ R0=R0*R2 (UUI); /*Compute mod(a*x)*/ R2=c_value; R0=R0+R2, FETCH_RETURN /*Compute mod(a*x + c)*/ rammem(ram_ireg,ram_0)=R0; /*Write out new seed*/ R0=BCLR R0 BY 31; /*Always return positive*/ restore_state: RETURN (DB); RESTORE_STACK RESTORE_FRAME .ENDSEG; .SEGMENT/RAM_SPACE Ram_Space_Name; .GLOBAL ___lib_rand_seed; .VAR ___lib_rand_seed = 1; .ENDSEG;