Subversion Repositories Kolibri OS

Rev

Rev 109 | Blame | Last modification | View Log | Download | RSS feed

  1. /*******************************************************************************
  2.  
  3.     MenuetOS MineSweeper
  4.     Copyright (C) 2003, 2004  Ivan Poddubny
  5.  
  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
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  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
  18.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20. *******************************************************************************/
  21.  
  22. // USER FIELD WINDOW
  23.  
  24. byte px,py,pm;
  25.  
  26. byte uf_open = FALSE;
  27. byte uf_stack[2048];
  28.  
  29. dword active_textbox = #str1;
  30.  
  31. byte str1[4] = {'1','1','1',0};
  32. byte str2[4] = {'2','2','2',0};
  33. byte str3[4] = {'3','2','1',0};
  34.  
  35. dword uf_x=0,
  36.       uf_y=0;
  37.  
  38. :fastcall dword str2dword(dword EAX)
  39. // str2byte ïåðåâîäèò ñòðîêó èç 3¸õ öèôð â áàéò
  40. // IN:  EAX = àäðåñ ñòîðêè
  41. // OUT: EAX = áàéò
  42. {
  43.   EDX = 0;
  44.   ECX = 0;
  45.   WHILE(ECX<3)
  46.   {
  47.     EDX *= 10;
  48.     EBX = DSBYTE[EAX+ECX];
  49.     EBX -= '0';
  50.     EDX += EBX;
  51.     ECX++;
  52.   }
  53.   EAX = EDX;
  54. }
  55.  
  56. :fastcall void dword2str(dword EAX,ESI)
  57. {
  58.   $PUSHA
  59.   DSDWORD[ESI]=0;
  60. //  EAX &= 255;
  61.   EDI = 10;
  62.   ECX = 2;
  63.   WHILE(ECX>=0)
  64.   {
  65.     IF(!EAX) BREAK;
  66.     $XOR EDX,EDX
  67.     $DIV EDI              // al = div; dl = mod
  68.     DL += '0';
  69.     DSBYTE[ESI+ECX] = DL;
  70.     ECX--;
  71.   }
  72.   $POPA
  73. }
  74.  
  75. void draw_uf_window()
  76. {
  77.   #ifdef DEBUG
  78.   sys_debug_write_string("MINE: îòðèñîâêà UF\n"w);
  79.   #endif
  80.  
  81.   sys_get_colors(#colors, 40);
  82.   sys_window_redraw(1);
  83.  
  84.   EDX = colors.w_work;
  85.   $bts edx,25
  86.   EBX = uf_x;
  87.   ECX = uf_y;
  88.   sys_draw_window(EBX, ECX, EDX, colors.w_grab | 0x80000000, colors.w_frames);
  89.   ECX = colors.w_grab_text | 0x10000000;
  90.   sys_write_text(7<<16+8, colors.w_grab_text | 0x10000000, "USER FIELD"n, 10);
  91.   sys_draw_button(83<<16+12, 5<<16+12, 1, colors.w_grab_button);
  92.  
  93.   // three buttons:
  94.   //  1) WIDTH  10
  95.   //  2) HEIGHT 11
  96.   //  3) MINES  12
  97.   // and also:
  98.   //  OK, Cancel - 20,21
  99.  
  100.   sys_draw_button(54<<16+38,  30<<16+10, 10,  0xe0e0e0); // WIDTH
  101.   EDX++; sys_draw_button(EBX, 48<<16+10, EDX, ESI);      // HEIGHT
  102.   EDX++; sys_draw_button(EBX, 66<<16+10, EDX, ESI);      // MINES
  103.  
  104.   ESI = colors.w_work_button;
  105.   ECX = 84<<16+10;
  106.   sys_draw_button( 8<<16+38, ECX, 20,  ESI); EDX++;
  107.   sys_draw_button(54<<16+38, ECX, EDX, ESI);
  108.  
  109.   ECX = colors.w_work_text | 0x10000000;
  110.   sys_write_text(8<<16+32, ECX, "WIDTH"n,  5);
  111.   sys_write_text(8<<16+50, ECX, "HEIGHT"n, 6);
  112.   sys_write_text(8<<16+68, ECX, "MINES"n,  5);
  113.  
  114.   sys_write_text(72<<16+32, 0, #str1, 3);
  115.   sys_write_text(72<<16+50, 0, #str2, 3);
  116.   sys_write_text(72<<16+68, 0, #str3, 3);
  117.  
  118.   sys_write_text(21<<16+86, colors.w_work_button_text, "OK    Cancel", 12);
  119.  
  120.   sys_window_redraw(2);
  121. }
  122.  
  123.  
  124. void uf_main()
  125. {
  126.   #ifdef DEBUG
  127.   sys_debug_write_string("MINE: ïîòîê ñîçäàí\n"w);
  128.   #endif
  129.  
  130. //  dword2str(13, #str1);
  131. //  EAX = str2dword(#str3);
  132. //  dword2str(EAX, #str2);
  133.  
  134.   uf_x <<= 16; uf_x += 100;
  135.   uf_y <<= 16; uf_y += 104;
  136.   draw_uf_window();
  137.  
  138.   #ifdef DEBUG
  139.   sys_debug_write_string("MINE: æäó ñîáûòèé\n"w);
  140.   #endif
  141.  
  142.   WHILE()
  143.   {
  144.     SWITCH (sys_wait_event())
  145.     {
  146.       case 1: draw_uf_window();
  147.               break;
  148.  
  149.       case 2: //IF (sys_get_key() == 27)
  150.               //{
  151.               //  uf_open = FALSE;
  152.               //  sys_exit_process();
  153.               //}
  154.               //EAX = key now!
  155.               EAX = sys_get_key();
  156.               if (active_textbox != 0)
  157.               {
  158.                 EBX = #str1; //active_textbox;
  159.                 DSBYTE[EBX] = 'A';
  160.                 DSBYTE[EBX]   = DSBYTE[EBX+1];
  161.                 DSBYTE[EBX+1] = DSBYTE[EBX+2];
  162.                 DSBYTE[EBX+2] = AL;
  163.                 draw_uf_window();
  164.               }
  165.               break;
  166.  
  167.       case 3: uf_button();
  168.     }
  169.   }
  170. }
  171.  
  172. uf_button()
  173. {
  174.   switch (sys_get_button_id())
  175.   {
  176.     case 10:
  177.       // set [width] INPUT active
  178.       active_textbox = #str1; break;
  179.     case 11:
  180.       // set [height] INPUT active
  181.       active_textbox = #str2; break;
  182.     case 12:
  183.       // set [mines] INPUT active
  184.       active_textbox = #str3; break;
  185.  
  186.     case 20:
  187.       // [string -> byte] three times and save them
  188.       px = str2dword(#str1);
  189.       py = str2dword(#str2);
  190.       pm = str2dword(#str3);
  191.       mode = 4;
  192.     case 21:
  193.       // close UF window, forget all changes
  194.  
  195.     case 1:
  196.       uf_open = FALSE;
  197.       sys_exit_process();
  198.   }
  199. }
  200.  
  201. void start_uf()
  202. {
  203.   #ifdef DEBUG
  204.   sys_debug_write_string("MINE: âûçâàíà start_uf\n"w);
  205.   #endif
  206.  
  207.   sys_process_info(#procinfo, -1);
  208.   uf_x = procinfo.xstart + XST;
  209.   uf_y = procinfo.ystart + YST;
  210.  
  211.   #ifdef DEBUG
  212.   sys_debug_write_string("MINE: ñîçäàþ ïîòîê...\n"w);
  213.   #endif
  214.  
  215.   sys_create_thread(#uf_main, #uf_stack + 2048);
  216.  
  217.   IF(EAX > 0x80000000)
  218.     return;
  219.  
  220.   uf_open = TRUE;
  221.   mouse_disable();
  222.   WHILE (uf_open == TRUE)
  223.   {
  224.     SWITCH (sys_wait_event_timeout(5))
  225.     {
  226.       CASE 1: draw_window();       CONTINUE;
  227.       CASE 2: sys_get_key();       CONTINUE;
  228.       CASE 3: sys_get_button_id(); CONTINUE;
  229.     }
  230.   }
  231.   mouse_enable();
  232. }