Rev 5575 | Rev 5582 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5575 | Rev 5576 | ||
---|---|---|---|
1 | /******************************************************************************* |
1 | /******************************************************************************* |
2 | 2 | ||
3 | MenuetOS MineSweeper |
3 | MenuetOS MineSweeper |
4 | Copyright (C) 2003 Ivan Poddubny |
4 | Copyright (C) 2003 Ivan Poddubny |
5 | 5 | ||
6 | This program is free software; you can redistribute it and/or modify |
6 | This program is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. |
9 | (at your option) any later version. |
10 | 10 | ||
11 | This program is distributed in the hope that it will be useful, |
11 | This program is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
14 | GNU General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU General Public License |
16 | You should have received a copy of the GNU General Public License |
17 | along with this program; if not, write to the Free Software |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | 19 | ||
20 | *******************************************************************************/ |
20 | *******************************************************************************/ |
- | 21 | #define MASK_RAND 123456789 |
|
- | 22 | #define IQ_RAND 12773 |
|
- | 23 | #define IA_RAND 16807 |
|
- | 24 | #define IR_RAND 2836 |
|
- | 25 | #define IM_RAND 2147483647 |
|
- | 26 | #define AM_RAND (1./2147483647) |
|
21 | 27 | ||
22 | inline fastcall int random( ECX) |
28 | inline fastcall int random( ECX) |
23 | // get pseudo-random number - ïîëó÷èòü ïñåâäîñëó÷àéíîå ÷èñëî |
29 | // get pseudo-random number - ïîëó÷èòü ïñåâäîñëó÷àéíîå ÷èñëî |
24 | { |
30 | { |
25 | $push ebx |
31 | $push ebx |
26 | 32 | ||
27 | $rdtsc // eax & edx |
33 | $rdtsc // eax & edx |
28 | $xor eax,edx |
34 | $xor eax,edx |
29 | $not eax |
35 | $not eax |
30 | 36 | ||
31 | EBX = __generator; |
37 | EBX = __generator; |
32 | $ror ebx,3 |
38 | $ror ebx,3 |
33 | $xor ebx,0xdeadbeef |
39 | $xor ebx,0xdeadbeef |
34 | EBX += EAX; |
40 | EBX += EAX; |
35 | __generator = EBX; |
41 | __generator = EBX; |
36 | 42 | ||
37 | EAX += EBX; |
43 | EAX += EBX; |
38 | EAX = EAX % ECX; |
44 | EAX = EAX % ECX; |
39 | 45 | ||
40 | $pop ebx |
46 | $pop ebx |
41 | } |
47 | } |
- | 48 | ||
- | 49 | :inline long unirand0(void) |
|
- | 50 | { |
|
- | 51 | long k,ans,tmp,save; |
|
- | 52 | save = __generator; |
|
- | 53 | __generator^=MASK_RAND; /* avoid __generator==0 */ |
|
- | 54 | k=__generator/IQ_RAND; |
|
- | 55 | tmp=__generator-k*IQ_RAND; |
|
- | 56 | __generator*=IA_RAND*tmp; |
|
- | 57 | __generator-=IR_RAND*k; |
|
- | 58 | if(__generator<0) __generator+=IM_RAND; |
|
- | 59 | if(save == __generator) return unirand0(); |
|
- | 60 | ans=__generator; |
|
- | 61 | __generator^=MASK_RAND; /* restore unmasked dummy */ |
|
- | 62 | return ans; |
|
- | 63 | } |
|
- | 64 | ||
- | 65 | :long RAND_A,RAND_C,RAND_TMP; |
|
- | 66 | :inline long rand(signed long x1,x2) |
|
- | 67 | { |
|
- | 68 | long tmp,xx; |
|
- | 69 | RAND_A = __generator; |
|
- | 70 | __generator = RAND_A*__generator+RAND_C; |
|
- | 71 | RAND_C = __generator^RAND_A; |
|
- | 72 | RAND_C>>=1; |
|
- | 73 | RAND_A<<=1; |
|
- | 74 | __generator^=RAND_A; |
|
- | 75 | xx=x2; |
|
- | 76 | if(x1<0)xx+=-x1; |
|
- | 77 | tmp = __generator%xx; |
|
- | 78 | if(tmp<0)tmp=-tmp; |
|
- | 79 | tmp+=x1; |
|
- | 80 | return tmp; |
|
- | 81 | } |
|
42 | 82 | ||
43 | inline fastcall randomize() |
83 | inline fastcall randomize() |
44 | // initialize random number __generator - èíèöèàëèçèðîâàòü ãåíåðàòîð ñëó÷àéíûõ ÷èñåë |
84 | // initialize random number __generator - èíèöèàëèçèðîâàòü ãåíåðàòîð ñëó÷àéíûõ ÷èñåë |
45 | { |
85 | { |
46 | asm |
86 | asm |
47 | { |
87 | { |
48 | mov eax,3 |
88 | mov eax,3 |
49 | int 0x40 |
89 | int 0x40 |
50 | ror eax,16 |
90 | ror eax,16 |
51 | } |
91 | } |
- | 92 | //if(EAX == __generator)return randomize(); |
|
52 | __generator = EAX; |
93 | __generator = EAX; |
53 | } |
94 | }0)tmp=-tmp; |
- | 95 | >0)xx+=-x1; |
|
- | 96 | >=1; |
|
- | 97 | ><=1; |
|
- | 98 | >0)> |