2006-01-03 10:43:31 +01:00
/*******************************************************************************
MenuetOS MineSweeper
2006-08-14 16:06:52 +02:00
Copyright (C) 2003, 2004 Ivan Poddubny
2006-01-03 10:43:31 +01:00
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*******************************************************************************/
2006-08-14 16:06:52 +02:00
? pragma option LST // generate ASM listing file - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
? warning TRUE // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2006-01-03 10:43:31 +01:00
? jumptomain NONE
2006-08-14 16:06:52 +02:00
? include "msys.h--" // MenuetOS system functions - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> MenuetOS
//? define DEBUG 1
2006-01-03 10:43:31 +01:00
2006-08-14 16:06:52 +02:00
? print "\n<> <6E> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> Ŀ"
? print "\n<> MenuetOS MineSweeper v0.4 <20> "
? print "\n<> (C) Ivan Poddubny (ivan-yar@bk.ru) 2003,2004 <20> "
? print "\n<> <6E> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> \n\n"
2006-01-03 10:43:31 +01:00
/************************************** DATA **************************************/
? define XPX 16 // X pixels by square - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
? define YPX 16 // Y pixels by square
2006-08-14 16:06:52 +02:00
? define MINE 255 // <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> , <20> <> <EFBFBD> <EFBFBD> value = MINE
2006-01-03 10:43:31 +01:00
struct
{
byte value; // number of mines - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
byte open; // square is open - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
byte press; // reserved - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
byte mark; // square is marked - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
} massiv[30*30];
struct
{
byte a_inc;
byte b_inc;
} matrix[8] = {-1,-1,1,0,1,0,0,1,-2,0,0,1,1,0,1,0};
struct
{
byte x_size;
byte y_size;
byte nmines;
} stdmodes[3] = {9,9,10, 16,16,40, 30,16,99}; // {x,y,m}
int XST, // offset of first pixel X - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
YST,
2006-08-14 16:06:52 +02:00
ncx, // number of squares in X - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
2006-01-03 10:43:31 +01:00
ncy,
cmines, // mines discovered - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD>
initmines, // number of initial mines - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD>
sqclosed; // squares still closed - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
dword xpos = 100, // window coordinates - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
ypos = 100,
xsize, // window size
ysize;
byte stop_game = FALSE, // game stopped - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
mouse_en = TRUE, // mouse enabled - <20> <> <EFBFBD> <EFBFBD>
mode = 3, // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> 1-<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 2-<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> 3-<2D> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> (0 <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
mouse_status,
firstmine;
ProcessInfo procinfo;
SystemColors colors;
/************************************** CODE **************************************/
inline void fastcall mouse_enable()
{
$mov eax,40
$mov ebx,100111b
$int 0x40
}
2006-08-14 16:06:52 +02:00
2006-01-03 10:43:31 +01:00
inline void fastcall mouse_disable()
{
$mov eax,40
$mov ebx,000111b
$int 0x40
}
2006-08-14 16:06:52 +02:00
2006-01-03 10:43:31 +01:00
? include "timer.h--" // timer functions
? include "draw.h--" // drawing functions
? include "access.h--" // get & set functions
? include "random.h--" // random number generator
//? include "uf.h--" // user field window
2006-08-14 16:06:52 +02:00
2006-01-03 10:43:31 +01:00
void init()
2006-08-14 16:06:52 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2006-01-03 10:43:31 +01:00
{
XST = 10; YST = 52; // FIELD POSITION IN WINDOW
ECX = mode;
IF (ECX != 0)
{
//ncx = stdmodes[ECX-1].x_size;
//ncy = stdmodes[ECX-1].y_size;
//cmines = initmines = stdmodes[ECX-1].nmines;
EBX = #stdmodes;
ECX--; ECX *= 3;
EBX += ECX;
ncx = DSBYTE[EBX]; EBX++;
ncy = DSBYTE[EBX]; EBX++;
cmines = initmines = DSBYTE[EBX];
}
xsize = ncx * XPX + XST + XST;
ysize = ncy * YPX + YST + XST;
} // init
2006-08-14 16:06:52 +02:00
2006-01-03 10:43:31 +01:00
void clear_all()
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
{
EAX = 0;
EDI = #massiv;
ECX = ncx * ncy;
$REP $STOSD
} // clear_all
2006-08-14 16:06:52 +02:00
2006-01-03 10:43:31 +01:00
void new_game()
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
{
2006-08-14 16:06:52 +02:00
init(); // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
2006-01-03 10:43:31 +01:00
randomize(); // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
clear_all(); // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
firstmine = TRUE; // <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
mouse_en = TRUE; // <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
stop_game = FALSE; // <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
stop_timer();
time = 0; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> = 0
} // new_game
2006-08-14 16:06:52 +02:00
2006-01-03 10:43:31 +01:00
void set_mines(int nminas, no_x, no_y)
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
{
int i, x, y, a, b;
2006-08-14 16:06:52 +02:00
#ifdef DEBUG
sys_debug_write_string("MINE: set_mines called\n");
#endif
2006-01-03 10:43:31 +01:00
sqclosed = ncx * ncy - nminas; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> = <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> - <20> <> <EFBFBD> -<2D> <> <20> <> <EFBFBD>
FOR (i = nminas; i > 0; i--) // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
{
2006-08-14 16:06:52 +02:00
x = random(ncx);
y = random(ncy);
2006-01-03 10:43:31 +01:00
WHILE ((get_value(x, y) == MINE) || ((x == no_x) && (y == no_y)))
{
x = random(ncx);
y = random(ncy);
}
set_value(x, y, MINE);
}
for (x = ncx-1; x >= 0; x--) // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
{
for (y = ncy-1; y >= 0; y--)
{
IF (get_value(x, y) == MINE)
continue;
EDX = x * ncy + y*4 + #massiv;
a = x; b = y;
FOR (i = 0; i < 8; i++)
{
AL = matrix[i].a_inc;
$movsx eax,al
a += EAX;
AL = matrix[i].b_inc;
$movsx eax,al
b += EAX;
IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (get_value(a, b) == MINE))
DSBYTE[EDX]++;
}
}
}
} // set_mines
2006-08-14 16:06:52 +02:00
2006-01-03 10:43:31 +01:00
inline void do_mouse(void)
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
{
int x,y;
EAX = sys_read_mouse(2); // <20> <> <EFBFBD> <EFBFBD> <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> -> <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
2006-08-14 16:06:52 +02:00
IF (EAX == 0)
{
// sys_debug_write_string("Strange\n");
return;
}
2006-01-03 10:43:31 +01:00
mouse_status = AL;
EAX = sys_read_mouse(1); // <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> -> <20> <> <EFBFBD> <EFBFBD> <EFBFBD>
EBX = EAX; EAX >>= 16; EBX &= 0xffff;
ECX = ncx * XPX + XST - 1;
EDX = ncy * YPX + YST - 1;
IF ((EAX < XST) || (EBX < YST) || (EAX > ECX) || (EBX > EDX)) return;
EAX -= XST; EAX /= XPX; x = EAX; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> x <20> y
EBX -= YST; EBX /= YPX; y = EBX;
IF ((mouse_status == 1) && (!get_open(x, y)) && (get_mark(x, y) != 1))
{
// <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
// left mouse button is pressed
IF (firstmine == TRUE)
{
firstmine = FALSE;
2006-08-14 16:06:52 +02:00
set_mines(initmines, x, y);
2006-01-03 10:43:31 +01:00
start_timer();
2006-08-14 16:06:52 +02:00
time = 1;
draw_time();
2006-01-03 10:43:31 +01:00
}
IF (get_value(x, y) == MINE)
{
end_game();
return;
}
open_square(x, y);
}
else IF ((mouse_status == 2) && (!get_open(x, y)))
{
// <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
// right mouse button is pressed
EBX = get_mark(x, y); EBX++;
EBX = EBX%3;
SWITCH (EBX)
{
CASE 2: cmines++; BREAK;
CASE 1: cmines--;
}
set_mark(x, y, EBX);
draw_minesi();
draw_square(x, y);
return;
}
ELSE IF ((mouse_status == 3) && (get_open(x, y)))
{
// <20> <> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
// both mouse buttons are pressed
IF (open_near_squares(x, y) == TRUE)
end_game();
}
2006-08-14 16:06:52 +02:00
IF (sqclosed == 0)
2006-01-03 10:43:31 +01:00
{
2006-08-14 16:06:52 +02:00
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// all squares are opened
2006-01-03 10:43:31 +01:00
mouse_en = FALSE; // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
stop_timer();
stop_game = TRUE; // <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
FOR (x = 0; x < ncx; x++)
FOR (y = 0; y < ncy; y++)
IF ((get_value(x, y) == MINE) && (get_mark(x, y) != 1))
{
set_mark(x, y, 1);
cmines--;
draw_square(x, y);
}
draw_minesi();
}
} // do_mouse
2006-08-14 16:06:52 +02:00
2006-01-03 10:43:31 +01:00
void open_square(int x, y)
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
{
int a, b, i;
2006-08-14 16:06:52 +02:00
#ifdef DEBUG
sys_debug_write_string("MINE: open_square called\n");
#endif
2006-01-03 10:43:31 +01:00
set_open(x, y, TRUE);
sqclosed--;
IF (get_value(x, y) != 0)
{
draw_square(x, y);
}
else
{
draw_square(x, y);
a = x; b = y;
FOR (i = 0; i < 8; i++)
{
//a += matrix[i].a_inc;
//b += matrix[i].b_inc;
AL = matrix[i].a_inc;
$movsx eax,al
a += EAX;
AL = matrix[i].b_inc;
$movsx eax,al
b += EAX;
IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (!get_open(a, b)) && (get_mark(a, b) != 1))
open_square(a, b);
}
}
} // open_square
2006-08-14 16:06:52 +02:00
2006-01-03 10:43:31 +01:00
int open_near_squares(int x, y)
// <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> (<28> <> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> )
{
int a, b, i;
dword suma = 0;
2006-08-14 16:06:52 +02:00
#ifdef DEBUG
sys_debug_write_string("MINE: open_near_squares called\n");
#endif
2006-01-03 10:43:31 +01:00
a = x;
b = y;
FOR (i = 0; i < 8; i++)
{
//a+=matrix[i].a_inc;
//b+=matrix[i].b_inc;
AL = matrix[i].a_inc;
$movsx eax,al
a += EAX;
AL = matrix[i].b_inc;
$movsx eax,al
b += EAX;
IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (get_mark(a, b) == 1))
suma++;
}
if (suma == get_value(x, y))
{
suma = 0;
a = x;
b = y;
for (i = 0; i < 8; i++)
{
//a+=matrix[i].a_inc;
//b+=matrix[i].b_inc;
AL = matrix[i].a_inc;
$movsx eax,al
a += EAX;
AL = matrix[i].b_inc;
$movsx eax,al
b += EAX;
IF ((a >= 0) && (b >= 0) && (a < ncx) && (b < ncy) && (!get_open(a, b)) && (get_mark(a, b) != 1))
{
IF (get_value(a, b) == MINE)
suma = 1;
open_square(a, b);
}
}
2006-08-14 16:06:52 +02:00
return suma;
2006-01-03 10:43:31 +01:00
}
ELSE
2006-08-14 16:06:52 +02:00
return 0;
2006-01-03 10:43:31 +01:00
} // open_near_squares
2006-08-14 16:06:52 +02:00
2006-01-03 10:43:31 +01:00
void end_game()
{
int x,y;
2006-08-14 16:06:52 +02:00
#ifdef DEBUG
sys_debug_write_string("MINE: end_game called\n");
#endif
2006-01-03 10:43:31 +01:00
stop_game = TRUE;
stop_timer();
for (x=0; x<ncx; x++)
{
for (y=0; y<ncy; y++)
{
IF (get_value(x, y) == MINE)
{
set_mark(x, y, FALSE); // <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
open_square(x, y);
}
ELSE IF (get_mark(x, y) == 1) // <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> , <20> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD>
{
EBX = XPX * x + XST; // x left
ECX = EBX + XPX - 1; // x right
EBX <<= 16; EBX += ECX;
$PUSH EBX
ECX = YPX * y + YST; // y top
$PUSH ECX
EDX = ECX + YPX - 1; // y bottom
ECX <<= 16; ECX += EDX;
sys_draw_line(EBX, ECX, clBlack);
$POP EDX
ECX = EDX + YPX - 1;
ECX <<= 16; ECX += EDX;
$POP EBX
sys_draw_line(EBX, ECX, clBlack);
CONTINUE;
}
}
}
} // end_game
void main()
{
2006-08-14 16:06:52 +02:00
//sys_delay(5); // for old kernel only!
2006-01-03 10:43:31 +01:00
new_game();
draw_window();
mouse_enable();
while()
{
switch (sys_wait_event_timeout(100)) // wait for 1 second
{
2006-08-14 16:06:52 +02:00
case evReDraw:
2006-01-03 10:43:31 +01:00
draw_window();
continue;
2006-08-14 16:06:52 +02:00
case evKey:
2006-01-03 10:43:31 +01:00
IF (sys_get_key() == 27)
sys_exit_process();
continue;
2006-08-14 16:06:52 +02:00
case evButton:
2006-01-03 10:43:31 +01:00
EAX = sys_get_button_id();
IF (EAX == 911) // new game
{
new_game();
draw_squares();
draw_time();
draw_minesi();
}
ELSE IF (EAX == 1001) // change mode
{
// mode++; mode%=3; mode++;
EAX = mode; EAX++; EAX = EAX%3; EAX++; mode = AL;
2006-08-14 16:06:52 +02:00
new_game();
EBX = ECX = -1;
EDX = xsize;
ESI = ysize;
EAX = 67;
$int 0x40
continue;
2006-01-03 10:43:31 +01:00
}
2006-08-14 16:06:52 +02:00
// ELSE IF (EAX == 1002)
// {
// start_uf();
// }
2006-01-03 10:43:31 +01:00
ELSE IF (EAX == 1) // close window
sys_exit_process();
2006-08-14 16:06:52 +02:00
continue;
2006-01-03 10:43:31 +01:00
case evMouse:
IF (!mouse_en) // is mouse enabled ?
2006-08-14 16:06:52 +02:00
continue;
2006-01-03 10:43:31 +01:00
do_mouse();
// wait for mouse release - <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD> <20> <> <EFBFBD> <EFBFBD> <EFBFBD> <EFBFBD>
WHILE (sys_read_mouse(2) == mouse_status)
{
check_timer();
2006-08-14 16:06:52 +02:00
sys_delay(3);
2006-01-03 10:43:31 +01:00
CONTINUE;
}
check_timer();
IF (stop_game) // disable mouse if game is stopped
mouse_en = FALSE;
CONTINUE;
}
check_timer();
sys_delay(2);
}
2006-08-14 16:06:52 +02:00
} // main