/[projet1]/users/coco/oruidic/rout_divers.s
Defence Force logotype

Contents of /users/coco/oruidic/rout_divers.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 373 - (show annotations)
Mon Aug 9 21:34:46 2010 UTC (9 years, 9 months ago) by coco
File size: 1705 byte(s)
- Routine de génération de nombres aléatoires
1
2 ; ---------------------------------------------------
3 ; Module de calcul de nombres aléatoires
4 ; . routine 1 : _InitRandomize initialisation des valeurs
5 ; . routine 2 : _GetRandomize generation des nombres aléatoires
6 ; ---------------------------------------------------
7
8 _RandomValueLow .byt 23
9 _RandomValueHigh .byt 35
10
11 _InitRandomize
12 lda _RandomValueHigh
13 sta _Random+1
14 lda _RandomValueLow
15 sta _Random
16 rts
17
18 _Random .dsb 2,0
19
20 ; ----------------------------------------------------
21 ; _GetRandomize()
22 ; Generate a somewhat random repeating sequence. I use
23 ; a typical linear congruential algorithm
24 ; I(n+1) = (I(n)*a + c) mod m
25 ; with m=65536, a=5, and c=13841 ($3611). c was chosen
26 ; to be a prime number near (1/2 - 1/6 sqrt(3))*m.
27 ;
28 ; Note that in general the higher bits are "more random"
29 ; than the lower bits, so for instance in this program
30 ; since only small integers (0..15, 0..39, etc.) are desired,
31 ; they should be taken from the high byte _Random+1, which
32 ; is returned in A.
33 ; -----------------------------------------------------
34 _GetRandomize
35 LDA _Random+1
36 STA RandomTMP
37 LDA _Random
38 ASL
39 ROL RandomTMP
40 ASL
41 ROL RandomTMP
42 CLC
43 ADC _Random
44 PHA
45 LDA RandomTMP
46 ADC _Random+1
47 STA _Random+1
48 PLA
49 ADC #$11
50 STA _Random
51 LDA _Random+1
52 ADC #$36
53 STA _Random+1
54 RTS
55
56 RandomTMP .dsb 1
57

  ViewVC Help
Powered by ViewVC 1.1.26