From 615d8e83abc97c7424c5a0bc4bf6e0cdf63194d9 Mon Sep 17 00:00:00 2001 From: Ivan Poddubny Date: Mon, 14 Aug 2006 13:16:46 +0000 Subject: [PATCH] v0.3a (11/08/2003) git-svn-id: svn://kolibrios.org@125 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/games/mine/tags/03a/access.h-- | 68 ++ programs/games/mine/tags/03a/changelog.txt | 15 + programs/games/mine/tags/03a/draw.h-- | 184 +++++ programs/games/mine/tags/03a/mine.c-- | 468 ++++++++++++ programs/games/mine/tags/03a/msys.h-- | 806 +++++++++++++++++++++ programs/games/mine/tags/03a/random.h-- | 52 ++ programs/games/mine/tags/03a/timer.h-- | 52 ++ programs/games/mine/tags/03a/uf.h-- | 135 ++++ 8 files changed, 1780 insertions(+) create mode 100644 programs/games/mine/tags/03a/access.h-- create mode 100644 programs/games/mine/tags/03a/changelog.txt create mode 100644 programs/games/mine/tags/03a/draw.h-- create mode 100644 programs/games/mine/tags/03a/mine.c-- create mode 100644 programs/games/mine/tags/03a/msys.h-- create mode 100644 programs/games/mine/tags/03a/random.h-- create mode 100644 programs/games/mine/tags/03a/timer.h-- create mode 100644 programs/games/mine/tags/03a/uf.h-- diff --git a/programs/games/mine/tags/03a/access.h-- b/programs/games/mine/tags/03a/access.h-- new file mode 100644 index 000000000..9ff694567 --- /dev/null +++ b/programs/games/mine/tags/03a/access.h-- @@ -0,0 +1,68 @@ +/******************************************************************************* + + MenuetOS MineSweeper + Copyright (C) 2003 Ivan Poddubny + + 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 + +*******************************************************************************/ + +:int get_value(int x, y) +{ + EBX=x*ncy+y; + return massiv[EBX].value; +} + +:void set_value(int x, y, byte val) +{ + EBX=x*ncy+y; + massiv[EBX].value=val; +} + +:int get_open(int x, y) +{ + EBX=x*ncy+y; + return massiv[EBX].open; +} + +:void set_open(int x, y, byte op) +{ + EBX=x*ncy+y; + massiv[EBX].open=op; +} + +:int get_press(int x, y) +{ + EBX=x*ncy+y; + return massiv[EBX].press; +} + +:void set_press(int x, y, byte pr) +{ + EBX=x*ncy+y; + massiv[EBX].press=pr; +} + +:int get_mark(int x, y) +{ + EBX=x*ncy+y; + return massiv[EBX].mark; +} + +:void set_mark(int x, y, byte mar) +{ + EBX=x*ncy+y; + massiv[EBX].mark=mar; +} \ No newline at end of file diff --git a/programs/games/mine/tags/03a/changelog.txt b/programs/games/mine/tags/03a/changelog.txt new file mode 100644 index 000000000..f779b6ec4 --- /dev/null +++ b/programs/games/mine/tags/03a/changelog.txt @@ -0,0 +1,15 @@ +v0.3a (11/08/2003) + - fixed a bug on old kernels + +v0.3 (09/08/2003) + - fixed some bugs + - new timer + - better random number generator + - user can't blow up after first mouse click + - uses system colors + +v0.2 (29/06/2003) + - fixed a lot of bugs + +v0.1 (22/06/2003) + - first public version \ No newline at end of file diff --git a/programs/games/mine/tags/03a/draw.h-- b/programs/games/mine/tags/03a/draw.h-- new file mode 100644 index 000000000..000cc5954 --- /dev/null +++ b/programs/games/mine/tags/03a/draw.h-- @@ -0,0 +1,184 @@ +/******************************************************************************* + + MenuetOS MineSweeper + Copyright (C) 2003 Ivan Poddubny + + 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 + +*******************************************************************************/ + +void draw_window() +// Процедура отрисовки окна +{ + mouse_disable(); + + sys_window_redraw(1); + sys_get_colors(#colors, 40); + + // WINDOW + EBX = xpos << 16 + xsize; + ECX = ypos << 16 + ysize; + sys_draw_window(EBX, ECX, 0x02CCCCCC, colors.w_grab | 0x80000000, colors.w_frames); + + // LABEL + sys_write_text(8<<16+8, colors.w_grab_text | 0x10000000, "MeOS MineSweeper", 16); + + // BUTTON (1) + EBX = xsize - 19; EBX = EBX<<16 + 12; + sys_draw_button(EBX, 5<<16+12, 1, colors.w_grab_button); + + // BUTTON (911) + EBX = xsize / 2 - 10; + EBX = EBX << 16 + 20; + sys_draw_button(EBX, 25<<16+20, 911, clLightGray); + + // BUTTON (1001) + sys_draw_button(10<<16+7, 23<<16+7, 1001, 0x118811); + + // BUTTON (1002) + //sys_draw_button(20<<16+7, ECX, EDX+1, 0xddbb44); + + // BUTTON (1003) + // sys_draw_button(); + + // BUTTON (1004) + // sys_draw_button(); + + // BUTTON (1005) + // sys_draw_button(); + + sys_window_redraw(2); + + draw_time(); // draw timer + draw_minesi(); // draw mines + draw_squares(); // draw field + + mouse_enable(); +} + +dword num_colors[8]= +{ + 0x4444d0, // 1 + 0x118811, // 2 + 0xd04444, // 3 + 0x111199, // 4 + 0x991111, // 5 + 0x117089, // 6 + 0x000000, // 7 + 0x808080 // 8 +}; + +void draw_square(int x, y) +// Отрисовка одной клетки +{ + int xl, xr, yt, yb; + dword tcolor = clBlack; + byte tchar,tval; + + xl = XPX * x + XST; + xr = xl + XPX - 1; + yt = YPX * y + YST; + yb = yt + YPX - 1; + + EBX = xl << 16 + xr - xl; + ECX = yt << 16 + yb - yt; + $inc ebx + $inc ecx + sys_draw_bar(EBX, ECX, clLightGray); + + if (!get_open(x, y)) + { + ECX = yt << 16 + yb - 1; + sys_draw_line(xl<<16+xl, ECX, clWhite); + EBX = xl << 16 + xr - 1; + sys_draw_line(EBX, yt << 16 + yt, EDX); + sys_draw_line(xr << 16 + xl, yb << 16 + yb, clDarkGray); + sys_draw_line(xr << 16 + xr, yb << 16 + yt, EDX); + + SWITCH (get_mark(x, y)) + { + CASE 2: tcolor = 0x121288; tchar = '?'; BREAK; + CASE 1: tcolor = 0xd04444; tchar = 'P'; + } + + IF (get_mark(x,y)) + { + EBX = xl + 5; EBX <<= 16; EBX += yt + 4; + sys_write_text(EBX, tcolor, #tchar, 1); + EBX += 0x00010000; + /* Второй раз - регистры сохраняются */ + sys_write_text(EBX, ECX, EDX, ESI); + } + } + else // get_open(x,y)==TRUE + { + tval = get_value(x, y); + IF (tval == 0) + { + //tcolor=clLightGray; + //tchar=' '; + GOTO NOCHAR; + } + ELSE IF (tval == MINE) + { + tcolor = 0xee1111; + tchar = '*'; + } + ELSE + { + tchar = tval + '0'; + tcolor = num_colors[tval-1]; + } + + EBX = xl + 5; EBX <<= 16; EBX += yt + 5; + sys_write_text(EBX, tcolor, #tchar, 1); + EBX += 0x00010000; + sys_write_text(EBX, ECX, EDX, ESI); +NOCHAR: + sys_draw_line(xl << 16 + xl, yt << 16 + yb, clDarkGray); + sys_draw_line(xl << 16 + xr, yt << 16 + yt, EDX); + } +} + +void draw_time() +// Таймер +{ + sys_draw_bar(XST<<16+25, 31<<16+10, 0xCCCCCC); + EBX = 0x00030000; + sys_write_number(EBX, time, XST<<16+32, 0x10ff0000); +} + +void draw_minesi() +// Индикатор количества нерасставленных мин +{ + EBX = xsize - XST - 25; + $PUSH EBX + EBX = EBX << 16 + 25; + sys_draw_bar(EBX, 31<<16+12, 0xCCCCCC); + $POP EDX + EDX <<= 16; EDX += 30; + EBX = 0x00030000; + sys_write_number(EBX, cmines, EDX, 0x10ff0000); +} + +void draw_squares() +// Отрисовка минного поля +{ + int x,y; + + FOR (x=0; x < ncx; x++) + FOR (y=0; y < ncy; y++) + draw_square(x, y); +} \ No newline at end of file diff --git a/programs/games/mine/tags/03a/mine.c-- b/programs/games/mine/tags/03a/mine.c-- new file mode 100644 index 000000000..c7fe5c6cf --- /dev/null +++ b/programs/games/mine/tags/03a/mine.c-- @@ -0,0 +1,468 @@ +/******************************************************************************* + + MenuetOS MineSweeper + Copyright (C) 2003 Ivan Poddubny + + 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 + +*******************************************************************************/ + +//? pragma option LST // generate ASM listing file - создать ассемблерный листинг +//? warning TRUE // включить режим вывода предупреждений +? pragma option meos +? jumptomain NONE +? include "msys.h--" // MenuetOS system functions - системные функции MenuetOS + +? print "\nЪДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДї" +? print "\nі MeOS MineSweeper v0.3 і" +? print "\nі (C) Ivan Poddubny (ivan-yar@bk.ru) 2003 і" +? print "\nАДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДДЩ\n\n" + +/************************************** DATA **************************************/ + +? define XPX 16 // X pixels by square - размер клетки в пикселях +? define YPX 16 // Y pixels by square +? define MINE 255 // значение для мины в поле value + +struct +{ + byte value; // number of mines - количество мин в окружающих клетках + byte open; // square is open - клетка открыта + byte press; // reserved - зарезервировано + byte mark; // square is marked - клетка помечена +} 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 - смещение поля от границы окна + YST, + ncx, // number of squares in X - размер пол + ncy, + cmines, // mines discovered - количество неоткрытых мин + initmines, // number of initial mines - изначальное количество мин + sqclosed; // squares still closed - количество закрытых клеток + +dword xpos = 100, // window coordinates - координаты окна + ypos = 100, + xsize, // window size + ysize; + +byte stop_game = FALSE, // game stopped - признак конца игры + mouse_en = TRUE, // mouse enabled - мышь + mode = 3, // режим игры 1-новичок 2-любитель 3-эксперт (0 особый) + mouse_status, + firstmine; + +ProcessInfo procinfo; +SystemColors colors; + +/************************************** CODE **************************************/ + +inline void fastcall mouse_enable() +{ + $mov eax,40 + $mov ebx,100111b + $int 0x40 +} + +inline void fastcall mouse_disable() +{ + $mov eax,40 + $mov ebx,000111b + $int 0x40 +} + +? 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 + +void init() +// Инициализаци +{ + 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 + +void clear_all() +// Очистить поле +{ + EAX = 0; + EDI = #massiv; + ECX = ncx * ncy; + $REP $STOSD +} // clear_all + +void new_game() +// Новая игра +{ + init(); // инициализаци + randomize(); // генератор случайных чисел + clear_all(); // очистить поле + + firstmine = TRUE; // игра не начата + mouse_en = TRUE; // мышь разрешена + stop_game = FALSE; // игра не закончена + stop_timer(); + time = 0; // время = 0 +} // new_game + +void set_mines(int nminas, no_x, no_y) +// Расставить мины +{ + int i, x, y, a, b; + + sqclosed = ncx * ncy - nminas; // количество НЕоткрытых клеток = площадь поля - кол-во мин + + FOR (i = nminas; i > 0; i--) // расставить мины + { + x = random(ncx); y = random(ncy); + 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--) // расставить цифры + { + 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 + +inline void do_mouse(void) +// Обработчик мыши +{ + int x,y; + + EAX = sys_read_mouse(2); // мышь не нажата -> выход + IF (EAX == 0) return; + + mouse_status = AL; + + EAX = sys_read_mouse(1); // мышь вне поля -> выход + 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; // вычислить x и y + EBX -= YST; EBX /= YPX; y = EBX; + + IF ((mouse_status == 1) && (!get_open(x, y)) && (get_mark(x, y) != 1)) + { + // на неоткрытой клетке без флажка нажата левая кнопка мыши + // left mouse button is pressed + IF (firstmine == TRUE) + { + firstmine = FALSE; + set_mines(cmines, x, y); + start_timer(); + } + IF (get_value(x, y) == MINE) + { + end_game(); + return; + } + open_square(x, y); + } + else IF ((mouse_status == 2) && (!get_open(x, y))) + { + // на неоткрытой клетке нажата правая кнопка мыши + // 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))) + { + // на открытой клетке нажаты обе кнопки мыши + // both mouse buttons are pressed + IF (open_near_squares(x, y) == TRUE) + end_game(); + } + + if (sqclosed == 0) + // открыты все клетки + // all squares are opened + { + mouse_en = FALSE; // запретить мышь + stop_timer(); + stop_game = TRUE; // игра завершена + + // поставить нерасставленные мины + 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 + +void open_square(int x, y) +// Открыть клетку +{ + int a, b, i; + + 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 + +int open_near_squares(int x, y) +// Открыть близлежащие клетки (обе кнопки мыши вместе) +{ + int a, b, i; + dword 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_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); + } + } + RETURN suma; + } + ELSE + RETURN 0; +} // open_near_squares + +void end_game() +{ + int x,y; + + stop_game = TRUE; + stop_timer(); + for (x=0; x ah = key + al 1 no key in buffer + MODIFIED, see below... +*/ +inline fastcall dword sys_get_key() +{ + EAX = 2; // just read it key from buffer + $int 0x40 + $shr eax,8 +} //return eax=key code. + +/* +03 = GET SYSTEM CLOCK + ret: eax 0x00SSMMHH sec,min,hour +*/ +inline fastcall dword sys_get_clock() +{ + EAX=3; + $int 0x40 +} + +/* +04 = WRITE TEXT TO WINDOW + ebx [x start]*65536 + [y start] + ecx text color 0x00RRGGBB + edx pointer to text beginning + esi text length + ret: nothing changed +*/ +inline fastcall void sys_write_text(dword EBX, ECX, EDX, ESI) +{ + EAX = 4; + $int 0x40; +} + +/* +05 = DELAY X/100 SECS + ebx delay in 1/100 secs + ret: nothing changed +*/ +inline fastcall void sys_delay(dword EBX) +{ + EAX = 5; + $int 0x40 +} + +/* +06 = OPEN FILE FROM FLOPPY + ebx pointer to filename -> 11 capital letters + ecx set 0x00000000 - reserved + edx set 0xffffffff - reserved + esi read to mem position + ret: nothing changed +*/ +inline fastcall void sys_open_file_floppy(dword EBX, ESI) +{ + $xor ecx,ecx + EDX = -1; + EAX = 6; + $int 0x40 +} + +/* +07 = PUTIMAGE + ebx pointer to image in memory - RRGGBBRRGGBB.. + ecx image size [x]*65536+[y] + edx image position in window [x]*65536+[y] + ret: eax 0 succesful, 1 overlapped +*/ +inline fastcall dword sys_put_image(dword EBX, ECX, EDX) +{ + EAX = 7; + $int 0x40 +} + +/* +08 = DEFINE BUTTON + ebx [x start]*65536 + [x size] + ecx [y start]*65536 + [y size] + edx button id number + esi button color 0x 00 RR GG BB + ret: nothing changed +*/ +inline fastcall void sys_draw_button(dword EBX, ECX, EDX, ESI) +{ + EAX = 8; + $int 0x40 +} + +/* +09 = PROCESS INFO + ebx pointer to 1024 bytes table + ecx process number or -1 = who am I + ret: eax number of processes + table : +00 dword cpu usage + +04 word processes position in windowing stack + +06 word window stack value at ecx + +10 12 db name of the process + +22 dword start of processes memory + +26 dword memory used by process + +30 dword PID of the process + +34 dword window x start + +38 dword window y start + +42 dword window x size + +46 dword window y size +*/ +inline fastcall dword sys_process_info(dword EBX, ECX) +{ + EAX = 9; + $int 0x40 +} + +/* +10 = WAIT FOR EVENT + ret: eax event type, 1 window redraw, 2 key in buffer, 3 button pressed +*/ +inline fastcall dword sys_wait_event() +{ + EAX = 10; // wait here for event + $int 0x40 +} + +/* +11 = CHECK FOR EVENT, NO WAIT + ret: eax 0 no event, 1 window redraw, 2 key in buffer, 3 button pressed +*/ +inline fastcall dword sys_nowait_event() +{ + EAX = 11; + $int 0x40 +} + +/* 12 = WINDOW REDRAW + EBX=1 start of draw, =2 end of draw. +*/ +inline fastcall void sys_window_redraw(dword EBX) +{ + EAX = 12; // function 12:tell os about windowdraw + $int 0x40 +} + +/* +13 = DRAW BAR +DrawBar(EBX=[xstart][xsize],ECX=[ystart][ysize],EDX=[0x00RRGGBB]) + ebx [x start]*65536 + [x size] + ecx [y start]*65536 + [y size] + edx color 0x00RRGGBB + ret: nothing changed +*/ +inline fastcall void sys_draw_bar(dword EBX, ECX, EDX) +{ + EAX = 13; + $int 0x40 +} + +/* +14 = GET SCREEN MAX + ret: eax [screen x max]*65536 + [screen y max] +*/ +inline fastcall dword sys_get_screen_size() +{ + EAX = 14; + $int 0x40 +} + +/* +15 = BACKGROUND + ebx 1 : set background size + ecx x size + edx y size + ebx 2 : write to background memory - max (0x100000-16) + ecx position in memory in bytes + edx color 0x00RRGGBB + ebx 3 : draw background + ebx 4 : type of background draw + ecx 1 - tile + ecx 2 - stretch + ebx 5 : blockmove image to os bgr memory + ecx - from + edx - to where in os bgr memory + esi - count of bytes to move +*/ +inline fastcall void sys_set_background(dword EBX, ECX, EDX, ESI) +{ + EAX = 15; + $int 0x40 +} + + +/* +17 = GET PRESSED BUTTON ID + ret: al 0 successful -> ah = id number al 1 no key in buffer. + MODIFIED, see below. +*/ +inline fastcall dword sys_get_button_id() +{ + EAX = 17; // Get ID + $int 0x40 + $shr eax,8 +} //eax=id, eax=0 no id. + +/* +18 = SYSTEM SERVICE + ebx 1 - system boot + ebx 2 - force terminate , ecx process no + ebx 4 - idle clock cycles / second + ebx 5 - time stamp counter / second - cpu speed +HD-> ebx 6 - save ramdisk to /hd/1/menuet.img +*/ +inline fastcall dword sys_service(dword EBX, ECX) +{ + EAX = 18; + $int 0x40 +} + +/* +19 = START PROGRAM from RAMDISK + ebx point to 11 char filename + ecx 0, or point to ASCIIZ start parameters - max 256 bytes + ret: eax 0 successful + eax other error code +*/ +inline fastcall dword sys_exec_app_ramdisk(dword EBX, ECX) +{ + EAX = 19; + $int 0x40 +} + +/* +20 = MIDI INTERFACE - MPU401 + ebx 1 - reset device + ebx 2 - cl midi data to output +*/ +inline fastcall void sys_midi(dword EBX) +{ + EAX = 20; + $int 0x40 +} + +/* +21 = SETUP FOR DEVICES + ebx 1=roland mpu midi base , base io address + ebx 2=keyboard 1 base keymap 2 shift keymap (ecx pointer to keymap) + 9 country 1eng 2fi 3ger 4rus + ebx 3=cd base 1 pri.master 2 pri slave, + 3 sec master 4 sec slave + ebx 4=sb16 base, base io address + ebx 5=system language, 1eng 2fi 3ger 4rus + ebx 6=wss base, base io address + ebx 7=hd base, 1 pri.master 2 pri slave + 3 sec master 4 sec slave + ebx 8=fat32 partition in hd +*/ +inline fastcall void sys_setup_devices(dword EBX, ECX) +{ + EAX = 21; + $int 0x40 +} + +/* +23 = WAIT FOR EVENT WITH TIMEOUT + ebx time to delay in hs + ret: eax event type: 0 no event, 1 window redraw, + 2 key in buffer, 3 button +*/ +inline fastcall dword sys_wait_event_timeout(dword EBX) +{ + EAX = 23; + $int 0x40 +} + +/* +24 = CD AUDIO + ebx 1 - play from ecx 00 FR SS MM + ebx 2 - get playlist size of ecx to [edx] + ebx 3 - stop/pause play +*/ +inline fastcall void sys_cd_audio(dword EBX, ECX, EDX) +{ + EAX = 24; + $int 0x40 +} + +/* +25 = SB16 - mixer I + ebx 1 - set main volume cl [L]*16+[R] + ebx 2 - set cd volume cl [L]*16+[R] +*/ +inline fastcall void sys_sb16_mixer_1(dword EBX, ECX) +{ + EAX = 25; + $int 0x40 +} + +/* +26 = GET SETUP FOR DEVICES + ebx 1=roland mpu midi base , base io address + ebx 2=keyboard 1 base keymap 2 shift keymap + 9 country 1eng 2fi 3ger 4rus + ebx 3=cd base 1 pri.master 2 pri slave, + 3 sec master 4 sec slave + ebx 4=sb16 base, base io address + ebx 5=system language, 1eng 2fi 3ger 4rus + ebx 6=wss base, base io address + ebx 7=hd base, 1 pri.master 2 pri slave + 3 sec master 4 sec slave + ebx 8=fat32 partition in hd + ebx 9=1/100 timer tics from stard -> eax + return value in eax +*/ +inline fastcall dword sys_get_setup_devices(dword EBX) +{ + EAX = 26; + $int 0x40 +} + +/* +27 = WINDOWS SOUND SYSTEM + ebx 1 - set main volume to cl 0-255 + ebx 2 - set cd volume to cl 0-255 +*/ +inline fastcall void sys_windows_sound_system(dword EBX, ECX) +{ + EAX = 27; + $int 0x40 +} + +/* +28 = SB16 - mixer II + ebx 1 - set main volume to cl 0-255 + ebx 2 - set cd volume to cl 0-255 +*/ +inline fastcall void sys_sb16_mixer_2(dword EBX, ECX) +{ + EAX = 28; + $int 0x40 +} + +/* +29 = GET DATE + ret: eax 0x00YYDDMM year date month +*/ +inline fastcall dword sys_get_date() +{ + EAX = 29; + $int 0x40 +} + +/* +30 = READ HD + ebx pointer to file + ecx file lenght + edx block to read, starts from 1, blocksize = 512 bytes + esi reserved, set as 1 + edi pointer to return/work area (atleast 20 000 bytes) + return: work_area+1024 <- requested block of 512 bytes +*/ +inline fastcall dword sys_read_hd(dword EBX, ECX, EDX, ESI, EDI) +{ + EAX = 30; + $int 0x40 +} + +/* +31 = START APP FROM HD + ebx pointer to file + ecx file lenght + edx pointer to return/work area (atleast 20 000 bytes) + ret eax=0 successful, eax<>0 errorcode +*/ +inline fastcall dword sys_exec_app_hd() +{ + EAX = 31; + $int 0x40 +} + +/* +32 = DELETE FILE FROM FLOPPY IMAGE IN MEMORY + ebx pointer to filename +*/ + +inline fastcall dword sys_floppy_delete(EBX) +{ + EAX = 32; + $int 0x40 +} + +/* +33 = SAVE FILE TO FLOPPY IMAGE IN MEMORY + ebx pointer to file name + ecx pointer to data + edx count to write in bytes + esi 0 create new , ( 1 append - not implemented yet ) +*/ +inline fastcall dword sys_floppy_save(EBX,ECX,EDX) +{ + EAX = 33; + ESI = 0; + $int 0x40 +} + +/* +34 = READ DIRECTORY FROM FLOPPY + ebx reserved : set as zero + ecx reserved : set as zero + edx start 512 block to read + esi reserved : set as 1 + edi pointer to return area + + +35 = READ SCREEN PIXEL + ebx = pixel count from top left of the screen + return : eax = 0x00RRGGBB +*/ + +/* +37 = READ MOUSE POSITION + ebx=0 screen relative + ebx=1 window relative + ebx=2 buttons pressed + return in eax +*/ +inline fastcall dword sys_read_mouse(dword EBX) +{ + EAX = 37; + $int 0x40 +} + +/* +38 = DRAW LINE + ebx [x start] shl 16 + [x end] + ecx [y start] shl 16 + [y end] + edx colour 0x00RRGGBB + return : nothing changed +*/ +inline fastcall void sys_draw_line(dword EBX, ECX, EDX) +{ + EAX = 38; + $int 0x40 +} + +/* +39 = GET BACKGROUND + ebx=1 -> eax=[bgr x size] shl 16 + [bgr y size] + ebx=2 + ecx= postition of backgrounds memorymap to return in eax + ebx=4 -> eax=1 tiled, eax=2 stretched +*/ +inline fastcall dword sys_get_background(dword EBX, ECX) +{ + EAX = 39; + $int 0x40 +} + +/* +40 = SET BITFIELD FOR WANTED EVENTS + as default: + ebx = 00000000 00000000 00000000 00000111b events: + I window draw + I key in buffer + I button in buffer + I (end request) + I desktop background draw + I (mouse change) + I---------------I get irqs data + + +41 = GET IRQ OWNER + ebx = irq + return : PID of the process + + +42 = GET DATA READ BY IRQ + ebx IRQ number + return : eax number of bytes in buffer + bl data + ecx 0 = successful data read + 1 = no data in buffer + 2 = incorrect IRQ owner + + +43 = SEND DATA TO DEVICE + bx : port + cl : data + return : eax = if 0 successful, other = error + + +44 = PROGRAM IRQ's + ebx pointer to table + ecx irq number + + +45 = RESERVE/FREE IRQ + ebx 0 reserve 1 free + ecx IRQ number + ret eax 0 successful, 1 error + + +46 = RESERVE/FREE PORT AREA + ebx 0 reserve 1 free + ecx port area start + edx port area end + ret eax 0 successful, 1 error +*/ + +/* +47 = DISPLAY NUMBER TO WINDOW + ebx = print type, bl=0 -> ecx is number + bl=1 -> ecx is pointer + bh=0 -> display decimal + bh=1 -> display hexadecimal + bh=2 -> display binary + bits 16-21 = number of digits to display (0-32) + bits 22-31 = reserved + ecx = number or pointer + edx = x shl 16 + y + esi = color +*/ +inline fastcall void sys_write_number(dword EBX, ECX, EDX, ESI) +{ + EAX = 47; + $int 0x40 +} + +/* +48 = DEFINE GENERAL WINDOW PROPERTIES + ebx = 0 apply/redraw + ecx = 0 , apply/redraw desktop + ebx = 1 define button style + ecx = 0 , set flat buttons + ecx = 1 , set 3d buttons + ebx = 2 define window colors + ecx = pointer to table + edx = number of bytes defined + ebx = 3 get define window colors + ecx = pointer to table + edx = number of bytes to get +*/ + +inline fastcall void sys_redraw_desktop() +{ + EAX = 48; + EBX = ECX = 0; + $int 0x40 +} + +inline fastcall void sys_set_button_style(dword ECX) +{ + EAX = 48; + EBX = 1; + $int 0x40 +} + +inline fastcall void sys_set_colors(dword ECX,EDX) +{ + EAX = 48; + EBX = 2; + $int 0x40 +} + +inline fastcall void sys_get_colors(dword ECX,EDX) +{ + EAX = 48; + EBX = 3; + $int 0x40 +} + +/* +49 = DEFINE APPLICATIONS INTERNAL INTERRUPTS + ebx = 0 + ecx point to dword x 256 table of interrupt entries + inside the application + return : nothing changed + + +50 = FREE FORM WINDOW SHAPE AND SCALE + ebx = 0 ; shape reference area + ecx = pointer to reference area + byte per pixel, 0 not used, 1=used, other = reserved + ebx = 1 ; scale of reference area (default 1:1) + ecx : scale is set to 2^ecx + return: nothing changed + + +51 = CREATE THREAD + ebx = 1 ; create + ecx ; = thread entry point + edx ; = thread stack position + return : eax = pid or 0xfffffff0+ for error +*/ + +inline fastcall dword sys_create_thread(dword ECX,EDX) +{ + EAX = 51; + EBX = 1; + $int 0x40 +} + +/* + +52 = STACK DRIVER STATUS + - see stack.txt + + +53 = SOCKET INTERFACE + - see stack.txt + + +54 = USER EVENTS + - not ready yet + + +55 = SOUND INTERFACE + ebx = 0 ; load 44 khz 8 bit mono sound block + ecx ; = pointer to 65536 byte soundblock + ebx = 1 ; play 44 khz 8 bit mono sound block + + +56 = WRITE FILE TO HD + ebx pointer to 12 char filename + ecx bytes to write + edx pointer to data to write + esi pointer to path + path db 0 + + +57 = DELETE FILE FROM HD + ebx pointer to filename : 11 capital letters + edx pointer to path : path db 0 +*/ + + +/* +58 = SYSTEM TREE ACCESS + ebx pointer to fileinfo block + fileinfo: + dd 0x0 ; 0=read (/write/delete/append) + dd 0x0 ; 512 block to read 0+ + dd 0x1 ; blocks to read (/bytes to write/append) + dd 0x20000 ; return data pointer + dd 0x10000 ; work area for os - 16384 bytes + db '/RAMDISK/FIRST/KERNEL.ASM',0 ; ASCIIZ dir & filename +*/ +inline fastcall void sys_tree_access(dword EBX) +{ + EAX = 58; + $int 0x40 +} + +/* +59 = TRACE FOR SYSTEM CALLS FROM PROCESSES + ebx = 0 ; get system events + ecx ; pointer to table -> ; 64 bytes/system call descriptor + ; +00 PID + ; +32 EDI + ; +36 ESI + ; +40 EBP + ; +44 ESP + ; +48 EBX + ; +52 EDX + ; +56 ECX + ; +60 EAX + edx ; number of bytes to return to table (currently max 16*64) + return: eax = number of system calls from start + latest call is saved to (eax mod 16)*64 in table + ebx = 0 : above format +*/ + +/* +60 = IPC + ebx = 1 ; define receive area + ecx = pointer to start + edx = size of area + + ebx = 2 ; send message + ecx = PID + edx = pointer to message + esi = length +*/ + +inline fastcall void sys_ipc_init(dword ECX, EDX) +{ + EAX = 60; + EBX = 1; + $int 0x40 +} + +inline fastcall void sys_ipc_send(dword ECX, EDX, ESI) +{ + EAX = 60; + EBX = 2; + $int 0x40 +} + +/* -1 = EXIT PROCESS */ + +inline fastcall void sys_exit_process() +{ + $xor eax,eax + $dec eax + $int 0x40 +} diff --git a/programs/games/mine/tags/03a/random.h-- b/programs/games/mine/tags/03a/random.h-- new file mode 100644 index 000000000..11b60c117 --- /dev/null +++ b/programs/games/mine/tags/03a/random.h-- @@ -0,0 +1,52 @@ +/******************************************************************************* + + MenuetOS MineSweeper + Copyright (C) 2003 Ivan Poddubny + + 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 + +*******************************************************************************/ + +dword generator; // random number generator - для генерации случайных чисел + +:int random(int max) +// get pseudo-random number - получить псевдослучайное число +{ + $rdtsc // eax & edx + $xor eax,edx + $not eax + + EBX = generator; + $ror ebx,3 + $xor ebx,0xdeadbeef + EBX += EAX; + generator = EBX; + + EAX += EBX; + EAX = EAX % max; + return EAX; +} + +:randomize() +// initialize random number generator - инициализировать генератор случайных чисел +{ + asm + { + mov eax,3 + int 0x40 + ror eax,16 + } + generator = EAX; +} \ No newline at end of file diff --git a/programs/games/mine/tags/03a/timer.h-- b/programs/games/mine/tags/03a/timer.h-- new file mode 100644 index 000000000..59f363feb --- /dev/null +++ b/programs/games/mine/tags/03a/timer.h-- @@ -0,0 +1,52 @@ +/******************************************************************************* + + MenuetOS MineSweeper + Copyright (C) 2003 Ivan Poddubny + + 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 + +*******************************************************************************/ + +dword time, + ttime; + +byte timer_life; + +start_timer() +{ + timer_life = TRUE; + ttime = sys_get_clock(); +} + +stop_timer() +{ + timer_life = FALSE; +} + +check_timer() +{ + IF (!timer_life) return; + + EAX = sys_get_clock(); + IF (EAX == 0xffffff) return; + + IF (ttime != EAX) + { + ttime = EAX; + IF (time < 999) + time++; + draw_time(); + } +} \ No newline at end of file diff --git a/programs/games/mine/tags/03a/uf.h-- b/programs/games/mine/tags/03a/uf.h-- new file mode 100644 index 000000000..d6731951e --- /dev/null +++ b/programs/games/mine/tags/03a/uf.h-- @@ -0,0 +1,135 @@ +/******************************************************************************* + + MenuetOS MineSweeper + Copyright (C) 2003 Ivan Poddubny + + 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 + +*******************************************************************************/ + +// USER FIELD WINDOW + +byte px,py,pm; + +byte uf_open = FALSE; +byte uf_stack[2048]; + +byte str1[5]; +byte str2[5]; +byte str3[5]; + +dword uf_x, + uf_y; + +void draw_uf_window() +{ + sys_get_colors(#colors, 40); + sys_window_redraw(1); + + EDX = colors.w_work; + $bts edx,25 + sys_draw_window(uf_x, uf_y, EDX, colors.w_grab | 0x80000000, colors.w_frames); + ECX = colors.w_grab_text | 0x10000000; + sys_write_text(8<<16+8, colors.w_grab_text | 0x10000000, "USER FIELD", 10); + sys_draw_button(81<<16+12, 5<<16+12, 1, colors.w_grab_button); + + ECX = colors.w_work_text | 0x10000000; + sys_write_text(8<<16+31, ECX, "WIDTH", 5); + sys_write_text(8<<16+49, ECX, "HEIGHT", 6); + sys_write_text(8<<16+67, ECX, "MINES", 5); + + // three buttons: + // 1) WIDTH 10 + // 2) HEIGHT 11 + // 3) MINES 12 + // and also: + // OK, Cancel - 20,21 + + sys_draw_button(54<<16+38, 30<<16+10, 10, 0xe0e0e0); // WIDTH + EDX++; sys_draw_button(EBX, 48<<16+10, EDX, ESI); // HEIGHT + EDX++; sys_draw_button(EBX, 66<<16+10, EDX, ESI); // MINES + + ESI = colors.w_work_button; + ECX = 84<<16+10; + sys_draw_button( 8<<16+38, ECX, 20, ESI); EDX++; + sys_draw_button(54<<16+38, ECX, EDX, ESI); + + sys_write_text(21<<16+85, colors.w_work_button_text, "OK Cancel", 12); + + sys_window_redraw(2); +} + +void uf_main() +{ + uf_x <<= 16; uf_x += 100; + uf_y <<= 16; uf_y += 104; + draw_uf_window(); + + WHILE() + { + SWITCH (sys_wait_event()) + { + case 1: draw_uf_window(); + break; + + case 2: IF (sys_get_key() == 27) + { + uf_open = FALSE; + sys_exit_process(); + } + break; + + case 3: uf_button(); + } + } +} + +uf_button() +{ + switch (sys_get_button_id()) + { + //case 10: + //case 11: + //case 12: + + case 20: + case 21: + + case 1: + uf_open = FALSE; + sys_exit_process(); + } +} + +void start_uf() +{ + sys_process_info(#procinfo, -1); + uf_x = procinfo.xstart + XST; + uf_y = procinfo.ystart + YST; + + sys_create_thread(#uf_main, #uf_stack + 2048); + uf_open = TRUE; + mouse_disable(); + WHILE (uf_open == TRUE) + { + SWITCH (sys_wait_event_timeout(5)) + { + CASE 1: draw_window(); CONTINUE; + CASE 2: sys_get_key(); CONTINUE; + CASE 3: sys_get_button_id(); CONTINUE; + } + } + mouse_enable(); +} \ No newline at end of file