Subversion Repositories Kolibri OS

Rev

Rev 109 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 109 Rev 126
Line 1... Line 1...
1
/*******************************************************************************
1
/*******************************************************************************
Line 2... Line 2...
2
 
2
 
3
    MenuetOS MineSweeper
3
    MenuetOS MineSweeper
Line 4... Line 4...
4
    Copyright (C) 2003  Ivan Poddubny
4
    Copyright (C) 2003, 2004  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
Line 24... Line 24...
24
byte px,py,pm;
24
byte px,py,pm;
Line 25... Line 25...
25
 
25
 
26
byte uf_open = FALSE;
26
byte uf_open = FALSE;
Line 27... Line 27...
27
byte uf_stack[2048];
27
byte uf_stack[2048];
28
 
-
 
29
byte str1[5];
-
 
Line -... Line 28...
-
 
28
 
-
 
29
dword active_textbox = #str1;
-
 
30
 
-
 
31
byte str1[4] = {'1','1','1',0};
30
byte str2[5];
32
byte str2[4] = {'2','2','2',0};
31
byte str3[5];
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--;
Line 32... Line 71...
32
 
71
  }
33
dword uf_x,
72
  $POPA
-
 
73
}
-
 
74
 
-
 
75
void draw_uf_window()
-
 
76
{
34
      uf_y;
77
  #ifdef DEBUG
35
 
78
  sys_debug_write_string("MINE: îòðèñîâêà UF\n"w);
Line 36... Line 79...
36
void draw_uf_window()
79
  #endif
37
{
80
 
-
 
81
  sys_get_colors(#colors, 40);
-
 
82
  sys_window_redraw(1);
38
  sys_get_colors(#colors, 40);
83
 
39
  sys_window_redraw(1);
84
  EDX = colors.w_work;
40
 
85
  $bts edx,25
41
  EDX = colors.w_work;
86
  EBX = uf_x;
42
  $bts edx,25
-
 
43
  sys_draw_window(uf_x, uf_y, EDX, colors.w_grab | 0x80000000, colors.w_frames);
-
 
44
  ECX = colors.w_grab_text | 0x10000000;
-
 
45
  sys_write_text(8<<16+8, colors.w_grab_text | 0x10000000, "USER FIELD", 10);
-
 
46
  sys_draw_button(81<<16+12, 5<<16+12, 1, colors.w_grab_button);
-
 
Line 47... Line 87...
47
 
87
  ECX = uf_y;
48
  ECX = colors.w_work_text | 0x10000000;
88
  sys_draw_window(EBX, ECX, EDX, colors.w_grab | 0x80000000, colors.w_frames);
49
  sys_write_text(8<<16+31, ECX, "WIDTH",  5);
89
  ECX = colors.w_grab_text | 0x10000000;
50
  sys_write_text(8<<16+49, ECX, "HEIGHT", 6);
90
  sys_write_text(7<<16+8, colors.w_grab_text | 0x10000000, "USER FIELD"n, 10);
Line 64... Line 104...
64
  ESI = colors.w_work_button;
104
  ESI = colors.w_work_button;
65
  ECX = 84<<16+10;
105
  ECX = 84<<16+10;
66
  sys_draw_button( 8<<16+38, ECX, 20,  ESI); EDX++;
106
  sys_draw_button( 8<<16+38, ECX, 20,  ESI); EDX++;
67
  sys_draw_button(54<<16+38, ECX, EDX, ESI);
107
  sys_draw_button(54<<16+38, ECX, EDX, ESI);
Line -... Line 108...
-
 
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);
68
 
117
 
Line 69... Line 118...
69
  sys_write_text(21<<16+85, colors.w_work_button_text, "OK    Cancel", 12);
118
  sys_write_text(21<<16+86, colors.w_work_button_text, "OK    Cancel", 12);
70
 
119
 
Line -... Line 120...
-
 
120
  sys_window_redraw(2);
71
  sys_window_redraw(2);
121
}
72
}
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);
73
 
131
//  EAX = str2dword(#str3);
74
void uf_main()
132
//  dword2str(EAX, #str2);
75
{
133
 
Line -... Line 134...
-
 
134
  uf_x <<= 16; uf_x += 100;
-
 
135
  uf_y <<= 16; uf_y += 104;
-
 
136
  draw_uf_window();
-
 
137
 
76
  uf_x <<= 16; uf_x += 100;
138
  #ifdef DEBUG
77
  uf_y <<= 16; uf_y += 104;
139
  sys_debug_write_string("MINE: æäó ñîáûòèé\n"w);
78
  draw_uf_window();
140
  #endif
79
 
141
 
80
  WHILE()
142
  WHILE()
81
  {
143
  {
Line 82... Line 144...
82
    SWITCH (sys_wait_event())
144
    SWITCH (sys_wait_event())
83
    {
145
    {
84
      case 1: draw_uf_window();
146
      case 1: draw_uf_window();
85
              break;
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;
86
 
159
                DSBYTE[EBX] = 'A';
87
      case 2: IF (sys_get_key() == 27)
160
                DSBYTE[EBX]   = DSBYTE[EBX+1];
Line 88... Line 161...
88
              {
161
                DSBYTE[EBX+1] = DSBYTE[EBX+2];
89
                uf_open = FALSE;
162
                DSBYTE[EBX+2] = AL;
Line 98... Line 171...
98
 
171
 
99
uf_button()
172
uf_button()
100
{
173
{
101
  switch (sys_get_button_id())
174
  switch (sys_get_button_id())
102
  {
175
  {
-
 
176
    case 10:
-
 
177
      // set [width] INPUT active
103
    //case 10:
178
      active_textbox = #str1; break;
-
 
179
    case 11:
-
 
180
      // set [height] INPUT active
104
    //case 11:
181
      active_textbox = #str2; break;
-
 
182
    case 12:
-
 
183
      // set [mines] INPUT active
Line 105... Line 184...
105
    //case 12:
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);
106
 
190
      pm = str2dword(#str3);
-
 
191
      mode = 4;
Line 107... Line 192...
107
    case 20:
192
    case 21:
108
    case 21:
193
      // close UF window, forget all changes
109
 
194
 
110
    case 1:
195
    case 1:
111
    uf_open = FALSE;
196
      uf_open = FALSE;
Line 112... Line 197...
112
    sys_exit_process();
197
      sys_exit_process();
113
  }
198
  }
-
 
199
}
-
 
200
 
-
 
201
void start_uf()
-
 
202
{
114
}
203
  #ifdef DEBUG
115
 
204
  sys_debug_write_string("MINE: âûçâàíà start_uf\n"w);
116
void start_uf()
205
  #endif
Line -... Line 206...
-
 
206
 
-
 
207
  sys_process_info(#procinfo, -1);
-
 
208
  uf_x = procinfo.xstart + XST;
-
 
209
  uf_y = procinfo.ystart + YST;
117
{
210
 
-
 
211
  #ifdef DEBUG
-
 
212
  sys_debug_write_string("MINE: ñîçäàþ ïîòîê...\n"w);
-
 
213
  #endif
-
 
214
 
118
  sys_process_info(#procinfo, -1);
215
  sys_create_thread(#uf_main, #uf_stack + 2048);
119
  uf_x = procinfo.xstart + XST;
216
 
120
  uf_y = procinfo.ystart + YST;
217
  IF(EAX > 0x80000000)
121
 
218
    return;
122
  sys_create_thread(#uf_main, #uf_stack + 2048);
219