Rev 2811 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2811 | Rev 3003 | ||
---|---|---|---|
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 | 21 | ||
22 | dword generator; // random number generator - äëÿ ãåíåðàöèè ñëó÷àéíûõ ÷èñåë |
22 | dword generator; // random number generator - äëÿ ãåíåðàöèè ñëó÷àéíûõ ÷èñåë |
23 | 23 | ||
24 | :int random(int max) |
24 | inline fastcall int random( ECX) |
25 | // get pseudo-random number - ïîëó÷èòü ïñåâäîñëó÷àéíîå ÷èñëî |
25 | // get pseudo-random number - ïîëó÷èòü ïñåâäîñëó÷àéíîå ÷èñëî |
- | 26 | { |
|
- | 27 | $push ebx |
|
26 | { |
28 | |
27 | $rdtsc // eax & edx |
29 | $rdtsc // eax & edx |
28 | $xor eax,edx |
30 | $xor eax,edx |
29 | $not eax |
31 | $not eax |
30 | 32 | ||
31 | EBX = generator; |
33 | EBX = generator; |
32 | $ror ebx,3 |
34 | $ror ebx,3 |
33 | $xor ebx,0xdeadbeef |
35 | $xor ebx,0xdeadbeef |
34 | EBX += EAX; |
36 | EBX += EAX; |
35 | generator = EBX; |
37 | generator = EBX; |
36 | 38 | ||
37 | EAX += EBX; |
39 | EAX += EBX; |
38 | EAX = EAX % max; |
40 | EAX = EAX % ECX; |
- | 41 | ||
39 | return EAX; |
42 | $pop ebx |
40 | } |
43 | } |
41 | 44 | ||
42 | :randomize() |
45 | inline fastcall randomize() |
43 | // initialize random number generator - èíèöèàëèçèðîâàòü ãåíåðàòîð ñëó÷àéíûõ ÷èñåë |
46 | // initialize random number generator - èíèöèàëèçèðîâàòü ãåíåðàòîð ñëó÷àéíûõ ÷èñåë |
44 | { |
47 | { |
45 | asm |
48 | asm |
46 | { |
49 | { |
47 | mov eax,3 |
50 | mov eax,3 |
48 | int 0x40 |
51 | int 0x40 |
49 | ror eax,16 |
52 | ror eax,16 |
50 | } |
53 | } |
51 | generator = EAX; |
54 | generator = EAX; |
52 | } |
55 | } |