Subversion Repositories Kolibri OS

Rev

Rev 4917 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4917 Rev 7134
1
LEVELCONV equ 10
1
LEVELCONV equ 10
2
SQ equ 8
2
SQ equ 8
3
FLDSIZE equ 49
3
FLDSIZE equ 49
4
FLDSIZE2 equ FLDSIZE*8
4
FLDSIZE2 equ FLDSIZE*8
5
DELAY  equ 20
5
DELAY  equ 20
6
TICKS  equ 10
6
TICKS  equ 10
7
LEV_START equ 1
7
LEV_START equ 1
8
MOBILITY equ 9;13
8
MOBILITY equ 9;13
9
 
9
 
10
  use32
10
  use32
11
  org     0x0
11
  org     0x0
12
 
12
 
13
  db     'MENUET01'              ; 8 byte id
13
  db     'MENUET01'              ; 8 byte id
14
  dd     0x01                    ; header version
14
  dd     0x01                    ; header version
15
  dd     run                   ; start of code
15
  dd     run                   ; start of code
16
  dd     I_END                   ; size of image
16
  dd     I_END                   ; size of image
17
  dd     stak+0x400             ; memory for app
17
  dd     stak+0x400             ; memory for app
18
  dd     stak+0x400             ; esp
18
  dd     stak+0x400             ; esp
19
  dd     0x0 , 0x0               ; I_Param , I_Icon
19
  dd     0x0 , 0x0               ; I_Param , I_Icon
20
include "lang.inc"
20
include "macros.inc"
21
include "MACROS.INC"
-
 
22
;include "DEBUG.INC"
21
;include "debug.inc"
23
 
22
 
24
run:
23
run:
25
if  LEVELCONV eq 1
24
if  LEVELCONV eq 1
26
    call compress_levels
25
    call compress_levels
27
    jmp  close
26
    jmp  close
28
end if
27
end if
29
    mcall 3
28
    mcall 3
30
    mov  cl,16
29
    mov  cl,16
31
    ror  eax,cl
30
    ror  eax,cl
32
    mov  [generator],eax    ; random generator from Tetris
31
    mov  [generator],eax    ; random generator from Tetris
33
reset:
32
reset:
34
    mov  [levptr],level
33
    mov  [levptr],level
35
    mov  [levnum],LEV_START
34
    mov  [levnum],LEV_START
36
  if ~ LEV_START eq 1
35
  if ~ LEV_START eq 1
37
    mov  ecx,[levnum]
36
    mov  ecx,[levnum]
38
    dec  ecx
37
    dec  ecx
39
    mov  esi,[levptr]
38
    mov  esi,[levptr]
40
    jecxz start
39
    jecxz start
41
  .lp:
40
  .lp:
42
    movzx eax,word[esi]
41
    movzx eax,word[esi]
43
    and  eax,0x7fff
42
    and  eax,0x7fff
44
    add  esi,eax ; limit
43
    add  esi,eax ; limit
45
    loop .lp
44
    loop .lp
46
    mov  [levptr],esi
45
    mov  [levptr],esi
47
;    sub  esi,level
46
;    sub  esi,level
48
;    dpd  esi
47
;    dpd  esi
49
  end if
48
  end if
50
start:
49
start:
51
    mov  ecx,[generator]
50
    mov  ecx,[generator]
52
    and  ecx,0xff
51
    and  ecx,0xff
53
  .shuf:
52
  .shuf:
54
    call random
53
    call random
55
    loop .shuf
54
    loop .shuf
56
    xor  eax,eax
55
    xor  eax,eax
57
    and  [locked],eax
56
    and  [locked],eax
58
    and  [captured],eax
57
    and  [captured],eax
59
    mov  [ticks],TICKS
58
    mov  [ticks],TICKS
60
    mov  [mode],-1
59
    mov  [mode],-1
61
    mov  ebx,FLDSIZE
60
    mov  ebx,FLDSIZE
62
    mov  eax,[generator]
61
    mov  eax,[generator]
63
    xor  edx,edx
62
    xor  edx,edx
64
    div  ebx
63
    div  ebx
65
    mov  cl,dl
64
    mov  cl,dl
66
    call random
65
    call random
67
    mov  eax,[generator]
66
    mov  eax,[generator]
68
    xor  edx,edx
67
    xor  edx,edx
69
    div  ebx
68
    div  ebx
70
    mov  ch,dl
69
    mov  ch,dl
71
    xchg eax,ecx
70
    xchg eax,ecx
72
    movzx ecx,al
71
    movzx ecx,al
73
    imul cx,bx
72
    imul cx,bx
74
    shr  ax,8
73
    shr  ax,8
75
    add  cx,ax
74
    add  cx,ax
76
    mov  esi,[levptr]
75
    mov  esi,[levptr]
77
    mov  [dot],ecx
76
    mov  [dot],ecx
78
    call decompress_level
77
    call decompress_level
79
    mov  ebx,8
78
    mov  ebx,8
80
    call  nokey
79
    call  nokey
81
red:
80
red:
82
    call  draw_window
81
    call  draw_window
83
;    and  [event],0
82
;    and  [event],0
84
 
83
 
85
still:
84
still:
86
 
85
 
87
  .flush:
86
  .flush:
88
    mcall 2
87
    mcall 2
89
    test al,al
88
    test al,al
90
    jz   .flush
89
    jz   .flush
91
 
90
 
92
    mov  ebx,DELAY
91
    mov  ebx,DELAY
93
    mov  eax,[levnum]
92
    mov  eax,[levnum]
94
    shr  eax,1
93
    shr  eax,1
95
    sub  ebx,eax
94
    sub  ebx,eax
96
    mov  eax,23
95
    mov  eax,23
97
    cmp  [mode],0
96
    cmp  [mode],0
98
    jl   .wait
97
    jl   .wait
99
    mov  eax,10
98
    mov  eax,10
100
  .wait:
99
  .wait:
101
    mcall
100
    mcall
102
  .evt:
101
  .evt:
103
    mov  ebx,8
102
    mov  ebx,8
104
    test eax,eax
103
    test eax,eax
105
    jne  .ev_yes
104
    jne  .ev_yes
106
    dec  [ticks]
105
    dec  [ticks]
107
    jne  still
106
    jne  still
108
;    mov  [ticks],TICKS
107
;    mov  [ticks],TICKS
109
;    cmp  al,[event]
108
;    cmp  al,[event]
110
    jmp   key.ex
109
    jmp   key.ex
111
;    and  [event],al
110
;    and  [event],al
112
;    jmp  still
111
;    jmp  still
113
  .ev_yes:
112
  .ev_yes:
114
    cmp  eax,2
113
    cmp  eax,2
115
    je   key
114
    je   key
116
    cmp  eax,1                  ; redraw request ?
115
    cmp  eax,1                  ; redraw request ?
117
    je   red
116
    je   red
118
    cmp  eax,3                  ; button in buffer ?
117
    cmp  eax,3                  ; button in buffer ?
119
    je   button
118
    je   button
120
key:
119
key:
121
;    mov  [event],al
120
;    mov  [event],al
122
    mcall 2
121
    mcall 2
123
	and  eax, 0xffff
122
	and  eax, 0xffff
124
    cmp  ah,13
123
    cmp  ah,13
125
    je   button.mode
124
    je   button.mode
126
    cmp  ah,27
125
    cmp  ah,27
127
    je   button.mode
126
    je   button.mode
128
    cmp  [mode],-1
127
    cmp  [mode],-1
129
    jne  still
128
    jne  still
130
    cmp  ah,104
129
    cmp  ah,104
131
    jne  .nohelp
130
    jne  .nohelp
132
    mov  [mode],4
131
    mov  [mode],4
133
    jmp  red
132
    jmp  red
134
  .nohelp:
133
  .nohelp:
135
    cmp  ah,112
134
    cmp  ah,112
136
    jne  .nopau
135
    jne  .nopau
137
    mov  [mode],3
136
    mov  [mode],3
138
    jmp  red
137
    jmp  red
139
  .nopau:
138
  .nopau:
140
    shr  eax,8
139
    shr  eax,8
141
;    dpd  eax
140
;    dpd  eax
142
    cmp  eax,' '
141
    cmp  eax,' '
143
    je   .ex
142
    je   .ex
144
    cmp  eax,176
143
    cmp  eax,176
145
    jb   still
144
    jb   still
146
    cmp  eax,179
145
    cmp  eax,179
147
    ja   still
146
    ja   still
148
    cmp  [locked],0
147
    cmp  [locked],0
149
    jnz  still
148
    jnz  still
150
    lea  ebx,[eax-176]
149
    lea  ebx,[eax-176]
151
  .ex:
150
  .ex:
152
    mov  [ticks],TICKS
151
    mov  [ticks],TICKS
153
    call nokey
152
    call nokey
154
    call evolution
153
    call evolution
155
    call  red_field
154
    call  red_field
156
    jmp  still
155
    jmp  still
157
 
156
 
158
button:                       ; BUTTON - only close supported
157
button:                       ; BUTTON - only close supported
159
    mcall 17
158
    mcall 17
160
    cmp  ah,2
159
    cmp  ah,2
161
    jne  close
160
    jne  close
162
    mcall 8,,,2+1 shl 31
161
    mcall 8,,,2+1 shl 31
163
;    mov  [event],2
162
;    mov  [event],2
164
  .mode:
163
  .mode:
165
    mov  [ticks],TICKS
164
    mov  [ticks],TICKS
166
    mov  al,[mode]
165
    mov  al,[mode]
167
    cmp  al,1
166
    cmp  al,1
168
    je   reset
167
    je   reset
169
    cmp  al,2
168
    cmp  al,2
170
    je   reset
169
    je   reset
171
    mov  [mode],-1
170
    mov  [mode],-1
172
    test  al,al
171
    test  al,al
173
    jnz  .no0
172
    jnz  .no0
174
    inc  [levnum]
173
    inc  [levnum]
175
    jmp  start
174
    jmp  start
176
  .no0:
175
  .no0:
177
    jmp  red
176
    jmp  red
178
  close:
177
  close:
179
    or   eax,-1
178
    or   eax,-1
180
    int  0x40
179
    int  0x40
181
 
180
 
182
;   *********************************************
181
;   *********************************************
183
;   *******  WINDOW DEFINITIONS AND DRAW ********
182
;   *******  WINDOW DEFINITIONS AND DRAW ********
184
;   *********************************************
183
;   *********************************************
185
draw_window:
184
draw_window:
186
    mov  [ticks],TICKS
185
    mov  [ticks],TICKS
187
    mcall 12,1
186
    mcall 12,1
188
    mcall 0,<100,FLDSIZE2+16>,<100,FLDSIZE2+38>,0x14008000, , header
187
    mcall 0,<100,FLDSIZE2+16>,<100,FLDSIZE2+38>,0x14008000, , header
189
 
188
 
190
  if lang eq ru
189
  if lang eq ru
191
    mcall 47,0x20000,[levnum],<128,8>, 0
190
    mcall 47,0x20000,[levnum],<128,8>, 0
192
  else
191
  else
193
    mcall 47,0x20000,[levnum],<117,8>, 0
192
    mcall 47,0x20000,[levnum],<117,8>, 0
194
  end if
193
  end if
195
    call  red_field
194
    call  red_field
196
    cmp   [mode],0
195
    cmp   [mode],0
197
    jl    .edraw
196
    jl    .edraw
198
    mov   ecx,(FLDSIZE2-20) shl 16+20
197
    mov   ecx,(FLDSIZE2-20) shl 16+20
199
    cmp   [mode],4
198
    cmp   [mode],4
200
    jne    .nohelp
199
    jne    .nohelp
201
    mov   ecx,100 shl 16+FLDSIZE2-35-100+38
200
    mov   ecx,100 shl 16+FLDSIZE2-35-100+38
202
  .nohelp:
201
  .nohelp:
203
    mcall 13,<5+8,FLDSIZE2-8>,,0xf5deb3;0xffff00
202
    mcall 13,<5+8,FLDSIZE2-8>,,0xf5deb3;0xffff00
204
    mcall 8,,,2,0xc0c000
203
    mcall 8,,,2,0xc0c000
205
    mcall 4,<363,FLDSIZE2-20+6>,0x100000ff,msg_ok,2
204
    mcall 4,<363,FLDSIZE2-20+6>,0x100000ff,msg_ok,2
206
    mov   ebx,(5+8+35)shl 16+FLDSIZE2-20+6
205
    mov   ebx,(5+8+35)shl 16+FLDSIZE2-20+6
207
    movzx ecx,[mode]
206
    movzx ecx,[mode]
208
    mov   edx,messages+4
207
    mov   edx,messages+4
209
    cmp   ecx,4
208
    cmp   ecx,4
210
    jne   .nxt
209
    jne   .nxt
211
    mov   edx,desc+4
210
    mov   edx,desc+4
212
    xor   ecx,ecx
211
    xor   ecx,ecx
213
    mov   ebx,20 shl 16+110
212
    mov   ebx,20 shl 16+110
214
  .nxt:
213
  .nxt:
215
    mov   esi,[edx-4]
214
    mov   esi,[edx-4]
216
    jecxz .drw
215
    jecxz .drw
217
    dec   ecx
216
    dec   ecx
218
    lea   edx,[edx+esi+4]
217
    lea   edx,[edx+esi+4]
219
    jmp   .nxt
218
    jmp   .nxt
220
  .drw:
219
  .drw:
221
    cmp   esi,-1
220
    cmp   esi,-1
222
    je    .edraw
221
    je    .edraw
223
    mcall ,,0x000000ff
222
    mcall ,,0x000000ff
224
    mov   ecx,1
223
    mov   ecx,1
225
    add   ebx,18
224
    add   ebx,18
226
    cmp   [mode],4
225
    cmp   [mode],4
227
    je    .nxt
226
    je    .nxt
228
  .edraw:
227
  .edraw:
229
    mcall 12,2
228
    mcall 12,2
230
    ret
229
    ret
231
 
230
 
232
red_field:
231
red_field:
233
    mov   edi,field
232
    mov   edi,field
234
    mov   ebp,28 shl 16+SQ ; y
233
    mov   ebp,28 shl 16+SQ ; y
235
    mov   ecx,FLDSIZE
234
    mov   ecx,FLDSIZE
236
  .lp1:
235
  .lp1:
237
    push  ecx
236
    push  ecx
238
    mov   ecx,FLDSIZE
237
    mov   ecx,FLDSIZE
239
    mov   ebx,8 shl 16+SQ  ; x
238
    mov   ebx,8 shl 16+SQ  ; x
240
  .lp2:
239
  .lp2:
241
    push  ecx
240
    push  ecx
242
    mov   edx,0x8000
241
    mov   edx,0x8000
243
    cmp   byte[edi],0
242
    cmp   byte[edi],0
244
    je    .zero
243
    je    .zero
245
    cmp   byte[edi],2
244
    cmp   byte[edi],2
246
    jne   .nored
245
    jne   .nored
247
    mov   edx,0xff0000
246
    mov   edx,0xff0000
248
    cmp   [locked],0
247
    cmp   [locked],0
249
    jz    .zero
248
    jz    .zero
250
    mov   edx,0xa00000
249
    mov   edx,0xa00000
251
    jmp   .zero
250
    jmp   .zero
252
  .nored:
251
  .nored:
253
    mov   edx,0
252
    mov   edx,0
254
  .zero:
253
  .zero:
255
    mcall 13,,ebp
254
    mcall 13,,ebp
256
    inc   edi
255
    inc   edi
257
    pop   ecx
256
    pop   ecx
258
    add   ebx,8 shl 16
257
    add   ebx,8 shl 16
259
    loop  .lp2
258
    loop  .lp2
260
    pop   ecx
259
    pop   ecx
261
    add   ebp,8 shl 16
260
    add   ebp,8 shl 16
262
    loop  .lp1
261
    loop  .lp1
263
 
262
 
264
    mov   eax,[dot]
263
    mov   eax,[dot]
265
    mov   cl,FLDSIZE
264
    mov   cl,FLDSIZE
266
    div   cl
265
    div   cl
267
 
266
 
268
;    movzx ebx,ah
267
;    movzx ebx,ah
269
;    shl   ebx,19
268
;    shl   ebx,19
270
;    add   ebx,8 shl 16+7
269
;    add   ebx,8 shl 16+7
271
;    movzx ecx,al
270
;    movzx ecx,al
272
;    shl   ecx,19
271
;    shl   ecx,19
273
;    add   ecx,28 shl 16+7
272
;    add   ecx,28 shl 16+7
274
;    push  eax
273
;    push  eax
275
;    mcall 13,,,0xff
274
;    mcall 13,,,0xff
276
;    pop   eax
275
;    pop   eax
277
 
276
 
278
    movzx ebx,ah
277
    movzx ebx,ah
279
    shl   ebx,19
278
    shl   ebx,19
280
    add   ebx,8 shl 16
279
    add   ebx,8 shl 16
281
    shld  edx,ebx,16
280
    shld  edx,ebx,16
282
    add   dx,SQ-1
281
    add   dx,SQ-1
283
    mov   bx,dx
282
    mov   bx,dx
284
    movzx ecx,al
283
    movzx ecx,al
285
    shl   ecx,19
284
    shl   ecx,19
286
    add   ecx,28 shl 16
285
    add   ecx,28 shl 16
287
    shld  edx,ecx,16
286
    shld  edx,ecx,16
288
    add   dx,SQ-1
287
    add   dx,SQ-1
289
    mov   cx,dx
288
    mov   cx,dx
290
    mcall 38,,,0xffffff
289
    mcall 38,,,0xffffff
291
    ror   ecx,16
290
    ror   ecx,16
292
    mcall
291
    mcall
293
    ret
292
    ret
294
 
293
 
295
nokey:
294
nokey:
296
    xor  eax,eax
295
    xor  eax,eax
297
    mov  edi,buff
296
    mov  edi,buff
298
    mov  ecx,FLDSIZE*FLDSIZE+3
297
    mov  ecx,FLDSIZE*FLDSIZE+3
299
    push ecx edi
298
    push ecx edi
300
    rep  stosb
299
    rep  stosb
301
    pop  edi
300
    pop  edi
302
    ;mov  esi,field
301
    ;mov  esi,field
303
    mov  edi,field
302
    mov  edi,field
304
    mov  edx,FLDSIZE
303
    mov  edx,FLDSIZE
305
    pop  ecx
304
    pop  ecx
306
  .llp:
305
  .llp:
307
    mov  eax,2
306
    mov  eax,2
308
    repne scasb
307
    repne scasb
309
    jecxz .exx
308
    jecxz .exx
310
    and  byte[edi-1],0
309
    and  byte[edi-1],0
311
    push ecx
310
    push ecx
312
    lea  eax,[edi-field-1]
311
    lea  eax,[edi-field-1]
313
    div  dl
312
    div  dl
314
    call get_cell
313
    call get_cell
315
    mov  byte[buff+ecx],2
314
    mov  byte[buff+ecx],2
316
    pop  ecx
315
    pop  ecx
317
    loop .llp
316
    loop .llp
318
  .exx:
317
  .exx:
319
    mov  edi,field
318
    mov  edi,field
320
    mov  esi,buff
319
    mov  esi,buff
321
    mov  ecx,FLDSIZE*FLDSIZE
320
    mov  ecx,FLDSIZE*FLDSIZE
322
  .lp4:
321
  .lp4:
323
    lodsb
322
    lodsb
324
    cmp  al,2
323
    cmp  al,2
325
    jne  .skip3
324
    jne  .skip3
326
    mov  [edi],al
325
    mov  [edi],al
327
  .skip3:
326
  .skip3:
328
    inc  edi
327
    inc  edi
329
    loop  .lp4
328
    loop  .lp4
330
 
329
 
331
    ret
330
    ret
332
 
331
 
333
get_cell:
332
get_cell:
334
; ax - source cell [x][y]
333
; ax - source cell [x][y]
335
; ebx - direction
334
; ebx - direction
336
;     4 2 5
335
;     4 2 5
337
;     0 . 3
336
;     0 . 3
338
;     6 1 7
337
;     6 1 7
339
; out - ecx cell ptr
338
; out - ecx cell ptr
340
 
339
 
341
    push eax ebx
340
    push eax ebx
342
    add  ax,[ebx*2+dirs]
341
    add  ax,[ebx*2+dirs]
343
    mov  ebx,FLDSIZE
342
    mov  ebx,FLDSIZE
344
  .c0:
343
  .c0:
345
    cmp  al,bl
344
    cmp  al,bl
346
    jb   .c1
345
    jb   .c1
347
    sub  al,bl
346
    sub  al,bl
348
    jmp  .c0
347
    jmp  .c0
349
  .c1:
348
  .c1:
350
    cmp  ah,bl
349
    cmp  ah,bl
351
    jb   .c2
350
    jb   .c2
352
    sub  ah,bl
351
    sub  ah,bl
353
    jmp  .c1
352
    jmp  .c1
354
  .c2:
353
  .c2:
355
    movzx ecx,al
354
    movzx ecx,al
356
    imul cx,bx
355
    imul cx,bx
357
    shr  ax,8
356
    shr  ax,8
358
    add  cx,ax
357
    add  cx,ax
359
    pop  ebx eax
358
    pop  ebx eax
360
    ret
359
    ret
361
 
360
 
362
evolution:
361
evolution:
363
    xor   edi,edi
362
    xor   edi,edi
364
    and   [locked],edi
363
    and   [locked],edi
365
    mov   edx,FLDSIZE
364
    mov   edx,FLDSIZE
366
    mov   ecx,FLDSIZE*FLDSIZE
365
    mov   ecx,FLDSIZE*FLDSIZE
367
  .l1:
366
  .l1:
368
    push  ecx
367
    push  ecx
369
    mov   eax,edi
368
    mov   eax,edi
370
    div   dl
369
    div   dl
371
    mov   ecx,8
370
    mov   ecx,8
372
    xor   ebx,ebx
371
    xor   ebx,ebx
373
    mov   word[neib],bx ; neighbour count
372
    mov   word[neib],bx ; neighbour count
374
  .l2:
373
  .l2:
375
    push  ecx
374
    push  ecx
376
    call  get_cell
375
    call  get_cell
377
    movzx esi,byte[field+ecx]
376
    movzx esi,byte[field+ecx]
378
    test   esi,esi ; 0?
377
    test   esi,esi ; 0?
379
    jz    .skip2
378
    jz    .skip2
380
    inc   byte[neib-1+esi]
379
    inc   byte[neib-1+esi]
381
  .skip2:
380
  .skip2:
382
    inc   ebx
381
    inc   ebx
383
    pop   ecx
382
    pop   ecx
384
    loop  .l2
383
    loop  .l2
385
    mov   cl,[neib]
384
    mov   cl,[neib]
386
    add   cl,[neib+1]
385
    add   cl,[neib+1]
387
    cmp   cl,2
386
    cmp   cl,2
388
    jne   .no2
387
    jne   .no2
389
    mov   al,[field+edi]
388
    mov   al,[field+edi]
390
    jmp   .writebuf
389
    jmp   .writebuf
391
  .no2:
390
  .no2:
392
    xor   al,al
391
    xor   al,al
393
    cmp   cl,3
392
    cmp   cl,3
394
    jne   .writebuf
393
    jne   .writebuf
395
    inc   al
394
    inc   al
396
    mov   cl,[neib+1]
395
    mov   cl,[neib+1]
397
    cmp   cl,[neib]
396
    cmp   cl,[neib]
398
    jb    .writebuf
397
    jb    .writebuf
399
    inc   al
398
    inc   al
400
  .writebuf:
399
  .writebuf:
401
    mov   [buff+edi],al
400
    mov   [buff+edi],al
402
    pop   ecx
401
    pop   ecx
403
    inc   edi
402
    inc   edi
404
    loop  .l1
403
    loop  .l1
405
 
404
 
406
    mov   esi,buff
405
    mov   esi,buff
407
    mov   edi,field
406
    mov   edi,field
408
    mov   ecx,FLDSIZE*FLDSIZE
407
    mov   ecx,FLDSIZE*FLDSIZE
409
    rep   movsb
408
    rep   movsb
410
    call  square_check
409
    call  square_check
411
    call  dot_move
410
    call  dot_move
412
    ret
411
    ret
413
 
412
 
414
square_check:
413
square_check:
415
    mov   ecx,FLDSIZE*FLDSIZE+3
414
    mov   ecx,FLDSIZE*FLDSIZE+3
416
    mov   edx,FLDSIZE
415
    mov   edx,FLDSIZE
417
    mov   edi,field
416
    mov   edi,field
418
    xor   eax,eax
417
    xor   eax,eax
419
    pusha
418
    pusha
420
    and   dword[cells],eax
419
    and   dword[cells],eax
421
    and   [locked],eax
420
    and   [locked],eax
422
  .nored:
421
  .nored:
423
    mov   al,[edi]
422
    mov   al,[edi]
424
    inc   edi
423
    inc   edi
425
    dec   ecx
424
    dec   ecx
426
    jecxz .ex1
425
    jecxz .ex1
427
    test   al,al
426
    test   al,al
428
    jz    .nored
427
    jz    .nored
429
    inc   [cells-2+eax*2]
428
    inc   [cells-2+eax*2]
430
    jmp   .nored
429
    jmp   .nored
431
  .ex1:
430
  .ex1:
432
    mov   ax,[cells+2]
431
    mov   ax,[cells+2]
433
    cmp   ax,[cells]
432
    cmp   ax,[cells]
434
    ja    dot_move.next_lev
433
    ja    dot_move.next_lev
435
    cmp   [cells+2],4
434
    cmp   [cells+2],4
436
    je    .sq_check
435
    je    .sq_check
437
    add   esp,32
436
    add   esp,32
438
    cmp   [cells+2],0
437
    cmp   [cells+2],0
439
    jne   .loc
438
    jne   .loc
440
    mov   [mode],1
439
    mov   [mode],1
441
    mov   dword[esp+4],red
440
    mov   dword[esp+4],red
442
  .loc:
441
  .loc:
443
    inc   [locked]
442
    inc   [locked]
444
    ret
443
    ret
445
  .sq_check:
444
  .sq_check:
446
    popa
445
    popa
447
  .nored2:
446
  .nored2:
448
    mov   eax,2
447
    mov   eax,2
449
    repne scasb
448
    repne scasb
450
    jecxz .loc
449
    jecxz .loc
451
    lea   eax,[edi-field-1]
450
    lea   eax,[edi-field-1]
452
    div   dl
451
    div   dl
453
    xor   dh,dh
452
    xor   dh,dh
454
    push  ecx
453
    push  ecx
455
    mov   ebx,1
454
    mov   ebx,1
456
    call  get_cell
455
    call  get_cell
457
    add   dh,[field+ecx]
456
    add   dh,[field+ecx]
458
    mov   ebx,3
457
    mov   ebx,3
459
    call  get_cell
458
    call  get_cell
460
    add   dh,[field+ecx]
459
    add   dh,[field+ecx]
461
    mov   ebx,7
460
    mov   ebx,7
462
    call  get_cell
461
    call  get_cell
463
    add   dh,[field+ecx]
462
    add   dh,[field+ecx]
464
    pop   ecx
463
    pop   ecx
465
    cmp   dh,6
464
    cmp   dh,6
466
    jne   .nored2
465
    jne   .nored2
467
    ret
466
    ret
468
 
467
 
469
random:
468
random:
470
    mov  eax, [generator]
469
    mov  eax, [generator]
471
    sub  eax,0x43ab45b5    ; next random number
470
    sub  eax,0x43ab45b5    ; next random number
472
    ror  eax,1
471
    ror  eax,1
473
    xor  eax,0x32c4324f
472
    xor  eax,0x32c4324f
474
    ror  eax,1
473
    ror  eax,1
475
    mov  [generator],eax
474
    mov  [generator],eax
476
    ret
475
    ret
477
 
476
 
478
dot_move:
477
dot_move:
479
    call random
478
    call random
480
    mov  eax,[generator]
479
    mov  eax,[generator]
481
    xor  edx,edx
480
    xor  edx,edx
482
    mov  ebx,MOBILITY
481
    mov  ebx,MOBILITY
483
    div  ebx
482
    div  ebx
484
    cmp  edx,8
483
    cmp  edx,8
485
    jb   .nostay
484
    jb   .nostay
486
    mov  edx,16
485
    mov  edx,16
487
  .nostay:
486
  .nostay:
488
    mov  ebx,edx
487
    mov  ebx,edx
489
    shr  ebx,1
488
    shr  ebx,1
490
    mov  eax,[dot]
489
    mov  eax,[dot]
491
;    dpd  eax
490
;    dpd  eax
492
    mov  cl,FLDSIZE
491
    mov  cl,FLDSIZE
493
    div  cl
492
    div  cl
494
    call get_cell
493
    call get_cell
495
    mov  [dot],ecx
494
    mov  [dot],ecx
496
    cmp  byte[field+ecx],2
495
    cmp  byte[field+ecx],2
497
    jne  .nocap
496
    jne  .nocap
498
    inc  [captured]
497
    inc  [captured]
499
    cmp  [captured],2
498
    cmp  [captured],2
500
    jne  .ex
499
    jne  .ex
501
  .next_lev:
500
  .next_lev:
502
    mov  [mode],0
501
    mov  [mode],0
503
    pop  eax
502
    pop  eax
504
    mov  eax,[levptr]
503
    mov  eax,[levptr]
505
    cmp  word[eax],0
504
    cmp  word[eax],0
506
    jne  .nxt
505
    jne  .nxt
507
    mov  [mode],2
506
    mov  [mode],2
508
  .nxt:
507
  .nxt:
509
    mov  dword[esp],red
508
    mov  dword[esp],red
510
    ret
509
    ret
511
  .nocap:
510
  .nocap:
512
    and  [captured],0
511
    and  [captured],0
513
  .ex:
512
  .ex:
514
    ret
513
    ret
515
 
514
 
516
if LEVELCONV eq 1
515
if LEVELCONV eq 1
517
fileinfo:
516
fileinfo:
518
 
517
 
519
     dd   2
518
     dd   2
520
     dd   0x0
519
     dd   0x0
521
     dd   0x0
520
     dd   0x0
522
.fsize dd   10000
521
.fsize dd   10000
523
.ptr dd   0x20000
522
.ptr dd   0x20000
524
     db   '/sys/newlev.bin',0
523
     db   '/sys/newlev.bin',0
525
 
524
 
526
macro flush
525
macro flush
527
{
526
{
528
  mov  [edi],dh
527
  mov  [edi],dh
529
  inc  edi
528
  inc  edi
530
}
529
}
531
 
530
 
532
compress_levels:
531
compress_levels:
533
    mov  esi,raw_level
532
    mov  esi,raw_level
534
    mov  edi,I_END
533
    mov  edi,I_END
535
    mov  [fileinfo.ptr],edi
534
    mov  [fileinfo.ptr],edi
536
    mov  ecx,(raw_level_size-raw_level)/(FLDSIZE*FLDSIZE*4) ; 19
535
    mov  ecx,(raw_level_size-raw_level)/(FLDSIZE*FLDSIZE*4) ; 19
537
  .lp1:
536
  .lp1:
538
    push ecx
537
    push ecx
539
    mov  ecx,FLDSIZE*FLDSIZE
538
    mov  ecx,FLDSIZE*FLDSIZE
540
    mov  ebx,edi
539
    mov  ebx,edi
541
    mov  eax,[esi]
540
    mov  eax,[esi]
542
;    movzx eax,byte[esi]
541
;    movzx eax,byte[esi]
543
    movzx edx,al
542
    movzx edx,al
544
    dpd  edx
543
    dpd  edx
545
    shl  eax,15
544
    shl  eax,15
546
    stosw
545
    stosw
547
  .lp2:
546
  .lp2:
548
    lodsd ;lodsb
547
    lodsd ;lodsb
549
    cmp  al,0xd
548
    cmp  al,0xd
550
    jne  .nored
549
    jne  .nored
551
    flush
550
    flush
552
    xor  al,al
551
    xor  al,al
553
    stosb
552
    stosb
554
    add  esi,4
553
    add  esi,4
555
    dec  ecx
554
    dec  ecx
556
    xor  dh,dh
555
    xor  dh,dh
557
    jmp  .eloop
556
    jmp  .eloop
558
  .nored:
557
  .nored:
559
    cmp  al,dl
558
    cmp  al,dl
560
    jne  .change
559
    jne  .change
561
    inc  dh
560
    inc  dh
562
    cmp  dh,0xff
561
    cmp  dh,0xff
563
    jb   .eloop
562
    jb   .eloop
564
    flush
563
    flush
565
    xor  dh,dh
564
    xor  dh,dh
566
    jmp  .eloop
565
    jmp  .eloop
567
  .change:
566
  .change:
568
    flush
567
    flush
569
    xor  dl,1
568
    xor  dl,1
570
    mov  dh,1
569
    mov  dh,1
571
  .eloop:
570
  .eloop:
572
    loop .lp2
571
    loop .lp2
573
    flush
572
    flush
574
    mov  eax,edi
573
    mov  eax,edi
575
    sub  eax,ebx
574
    sub  eax,ebx
576
    add  [ebx],ax
575
    add  [ebx],ax
577
    pop  ecx
576
    pop  ecx
578
    loop .lp1
577
    loop .lp1
579
    xor  eax,eax
578
    xor  eax,eax
580
    stosw
579
    stosw
581
    sub  edi,I_END
580
    sub  edi,I_END
582
    mov  [fileinfo.fsize],edi
581
    mov  [fileinfo.fsize],edi
583
    mcall 70,fileinfo
582
    mcall 70,fileinfo
584
    ret
583
    ret
585
 
584
 
586
raw_level:
585
raw_level:
587
    file 'noname1.dat'
586
    file 'noname1.dat'
588
raw_level_size:
587
raw_level_size:
589
 
588
 
590
end if
589
end if
591
 
590
 
592
decompress_level:
591
decompress_level:
593
; esi - level begin
592
; esi - level begin
594
    mov  edi,field
593
    mov  edi,field
595
    movzx edx,word[esi]
594
    movzx edx,word[esi]
596
    xor  ecx,ecx
595
    xor  ecx,ecx
597
    mov  eax,edx
596
    mov  eax,edx
598
    and  edx,0x7fff
597
    and  edx,0x7fff
599
    add  edx,esi ; limit
598
    add  edx,esi ; limit
600
    mov  [levptr],edx
599
    mov  [levptr],edx
601
    add  esi,2
600
    add  esi,2
602
    shr  eax,15
601
    shr  eax,15
603
  .next:
602
  .next:
604
    cmp  esi,edx
603
    cmp  esi,edx
605
    jae  .exloop
604
    jae  .exloop
606
    movzx ebx,byte[esi]
605
    movzx ebx,byte[esi]
607
    inc  esi
606
    inc  esi
608
    test ebx,ebx
607
    test ebx,ebx
609
    jne  .nored
608
    jne  .nored
610
    rep  stosb
609
    rep  stosb
611
    xor  al,1
610
    xor  al,1
612
    mov  word[edi],0x0202
611
    mov  word[edi],0x0202
613
    add  edi,2
612
    add  edi,2
614
    jmp  .next
613
    jmp  .next
615
  .nored:
614
  .nored:
616
    add  ecx,ebx
615
    add  ecx,ebx
617
    cmp  ebx,0xff
616
    cmp  ebx,0xff
618
    je   .next
617
    je   .next
619
    rep  stosb
618
    rep  stosb
620
    xor  al,1
619
    xor  al,1
621
    jmp  .next
620
    jmp  .next
622
  .exloop:
621
  .exloop:
623
    rep  stosb
622
    rep  stosb
624
    ret
623
    ret
625
 
624
 
626
; DATA AREA
625
; DATA AREA
627
 
626
 
628
FS1 equ (FLDSIZE-1)
627
FS1 equ (FLDSIZE-1)
629
dirs  dw  FS1 shl 8,\
628
dirs  dw  FS1 shl 8,\
630
          1,\
629
          1,\
631
          FS1,\
630
          FS1,\
632
          1 shl 8,\
631
          1 shl 8,\
633
          FS1 shl 8+FS1,\
632
          FS1 shl 8+FS1,\
634
          1 shl 8+FS1,\
633
          1 shl 8+FS1,\
635
          FS1 shl 8+1,\
634
          FS1 shl 8+1,\
636
          1 shl 8+1,\
635
          1 shl 8+1,\
637
          0
636
          0
638
level:
637
level:
639
file 'rlevels.bin'
638
file 'rlevels.bin'
640
 
639
 
641
msg_ok db 'OK'
640
msg_ok db 'OK'
642
if lang eq ru
641
if lang eq ru
643
header db 'Red Square - “஢¥­ì       h - ®¬®éì, p -  ã§ ', 0
642
header db 'Red Square - “஢¥­ì       h - ®¬®éì, p -  ã§ ', 0
644
 
643
 
645
messages mstr 'Žâ«¨ç­®! ‚ë ¯¥à¥å®¤¨â¥ ­  á«¥¤ãî騩 ã஢¥­ì.',\
644
messages mstr 'Žâ«¨ç­®! ‚ë ¯¥à¥å®¤¨â¥ ­  á«¥¤ãî騩 ã஢¥­ì.',\
646
              'Šà á­ë¥ ª«¥âª¨ ã­¨ç⮦¥­ë. ‚ë ¯à®¨£à «¨.',\
645
              'Šà á­ë¥ ª«¥âª¨ ã­¨ç⮦¥­ë. ‚ë ¯à®¨£à «¨.',\
647
              '‚ë ¯à®è«¨ ¢á¥ ã஢­¨. ®§¤à ¢«ï¥¬!',\
646
              '‚ë ¯à®è«¨ ¢á¥ ã஢­¨. ®§¤à ¢«ï¥¬!',\
648
              'ˆ£à  ¯à¨®áâ ­®¢«¥­ ...'
647
              'ˆ£à  ¯à¨®áâ ­®¢«¥­ ...'
649
 
648
 
650
desc mstr   '   ‚ë ¨£à ¥â¥ ªà á­ë¬ ª¢ ¤à â¨ª®¬. –¥«ì ¨£àë - ¢ë¦¨âì á।¨',\
649
desc mstr   '   ‚ë ¨£à ¥â¥ ªà á­ë¬ ª¢ ¤à â¨ª®¬. –¥«ì ¨£àë - ¢ë¦¨âì á।¨',\
651
            'à §¢¨¢ îé¨åáï ç¥à­ëå ª«¥â®ª. …᫨ ‚ ¬ 㤠áâáï ¯®©¬ âì ¡¥«ë©',\
650
            'à §¢¨¢ îé¨åáï ç¥à­ëå ª«¥â®ª. …᫨ ‚ ¬ 㤠áâáï ¯®©¬ âì ¡¥«ë©',\
652
            'ªà¥á⨪, ‚ë ¯à®©¤¥â¥ ã஢¥­ì.',\
651
            'ªà¥á⨪, ‚ë ¯à®©¤¥â¥ ã஢¥­ì.',\
653
            '   —â®¡ë ¯®©¬ âì ¡¥«ë© ªà¥á⨪, ®­ ¤®«¦¥­ ¡ëâì ­ ªàëâ ®¤­®©',\
652
            '   —â®¡ë ¯®©¬ âì ¡¥«ë© ªà¥á⨪, ®­ ¤®«¦¥­ ¡ëâì ­ ªàëâ ®¤­®©',\
654
            '¨§ ªà á­ëå ª«¥â®ª ­  ¯à®â殮­¨¨ 2 ¯®ª®«¥­¨© ¯®¤àï¤.',\
653
            '¨§ ªà á­ëå ª«¥â®ª ­  ¯à®â殮­¨¨ 2 ¯®ª®«¥­¨© ¯®¤àï¤.',\
655
            '   …᫨ ªà á­ë© ª¢ ¤à â à §àã襭, íâ® ¥é¥ ­¥ ¯à®¨£àëè. Œ®¦¥â',\
654
            '   …᫨ ªà á­ë© ª¢ ¤à â à §àã襭, íâ® ¥é¥ ­¥ ¯à®¨£àëè. Œ®¦¥â',\
656
            '¡ëâì, ‚ ¬ ¯®¢¥§¥â ¨ ¥á«¨ ¢ ¯à®æ¥áá¥ í¢®«î樨 ª®«¨ç¥á⢮ ‚ è¨å',\
655
            '¡ëâì, ‚ ¬ ¯®¢¥§¥â ¨ ¥á«¨ ¢ ¯à®æ¥áá¥ í¢®«î樨 ª®«¨ç¥á⢮ ‚ è¨å',\
657
            'ªà á­ëå ª«¥â®ª áâ ­¥â ¡®«ìè¥, 祬 ç¥à­ëå, ã஢¥­ì ¡ã¤¥â',\
656
            'ªà á­ëå ª«¥â®ª áâ ­¥â ¡®«ìè¥, 祬 ç¥à­ëå, ã஢¥­ì ¡ã¤¥â',\
658
            "¯à®©¤¥­.",\
657
            "¯à®©¤¥­.",\
659
            '---',\
658
            '---',\
660
            '„¦®­ •®àâ®­ Š®­ãí© ¨§®¡à¥« ¯à¥ªà á­ãî ¨£àã. ®ç⨠ª ¦¤ë©',\
659
            '„¦®­ •®àâ®­ Š®­ãí© ¨§®¡à¥« ¯à¥ªà á­ãî ¨£àã. ®ç⨠ª ¦¤ë©',\
661
            '¯à®£à ¬¬¨áâ ­ ç¨­ ¥â á¢®î ¯à ªâ¨ªã á ­¥¥. Ž¤­ ª® ॠ«ì­ë¥',\
660
            '¯à®£à ¬¬¨áâ ­ ç¨­ ¥â á¢®î ¯à ªâ¨ªã á ­¥¥. Ž¤­ ª® ॠ«ì­ë¥',\
662
            '¢®§¬®¦­®á⨠í⮩ ¨£àë ¥é¥ ¯«®å® ¨§ã祭ë.',\
661
            '¢®§¬®¦­®á⨠í⮩ ¨£àë ¥é¥ ¯«®å® ¨§ã祭ë.',\
663
            '---',\
662
            '---',\
664
            'Žà¨£¨­ « ¨£àë ¯®¤ Win32 ­ ¯¨á « ‚« ¤¨¬¨à à¨¢ «®¢, 2002',\
663
            'Žà¨£¨­ « ¨£àë ¯®¤ Win32 ­ ¯¨á « ‚« ¤¨¬¨à à¨¢ «®¢, 2002',\
665
            '‡ ¯à®£à ¬¬¨à®¢ « ­   áᥬ¡«¥à¥ Willow, 2005'
664
            '‡ ¯à®£à ¬¬¨à®¢ « ­   áᥬ¡«¥à¥ Willow, 2005'
666
else
665
else
667
header db 'Red Square - Level         h - Help,  p - Pause', 0
666
header db 'Red Square - Level         h - Help,  p - Pause', 0
668
 
667
 
669
messages mstr 'Well done! You are on the next level',\
668
messages mstr 'Well done! You are on the next level',\
670
              'Your red cells are vanished! Game over.',\
669
              'Your red cells are vanished! Game over.',\
671
              "You've completed the game. Congratulations!",\
670
              "You've completed the game. Congratulations!",\
672
              'Game paused...'
671
              'Game paused...'
673
 
672
 
674
desc mstr   '   The main goal of the game for your red square is to stay',\
673
desc mstr   '   The main goal of the game for your red square is to stay',\
675
            'alive going through the evolving black cells. If you manage to',\
674
            'alive going through the evolving black cells. If you manage to',\
676
            'catch the white cross, you will pass the level.',\
675
            'catch the white cross, you will pass the level.',\
677
            '   To catch the white cross, it must be covered by red cell',\
676
            '   To catch the white cross, it must be covered by red cell',\
678
            'during 2 generations.',\
677
            'during 2 generations.',\
679
            "   If your red square is corrupted, you haven't lost yet. You",\
678
            "   If your red square is corrupted, you haven't lost yet. You",\
680
            'may have a luck, and if your red cells is developing and the',\
679
            'may have a luck, and if your red cells is developing and the',\
681
            'quantity of black cells is bigger than that of black cells,',\
680
            'quantity of black cells is bigger than that of black cells,',\
682
            "you'll pass the level.",\
681
            "you'll pass the level.",\
683
            '---',\
682
            '---',\
684
            'John Horton Conway has created a great game. Almost every',\
683
            'John Horton Conway has created a great game. Almost every',\
685
            'programmer begins his professional work from it. But the real',\
684
            'programmer begins his professional work from it. But the real',\
686
            'possibilities of this game have not discovered yet.',\
685
            'possibilities of this game have not discovered yet.',\
687
            '---',\
686
            '---',\
688
            'Original game under Win32 by Vladimir Privalov, 2002',\
687
            'Original game under Win32 by Vladimir Privalov, 2002',\
689
            'Programmed in assembly by Willow, 2005'
688
            'Programmed in assembly by Willow, 2005'
690
end if
689
end if
691
I_END:
690
I_END:
692
neib db ?,?
691
neib db ?,?
693
cells dw ?,?
692
cells dw ?,?
694
mode db ?
693
mode db ?
695
levptr dd ?
694
levptr dd ?
696
levnum dd ?
695
levnum dd ?
697
reds dd ?
696
reds dd ?
698
locked dd ?
697
locked dd ?
699
generator dd ?
698
generator dd ?
700
dot  dd ?
699
dot  dd ?
701
ticks dd ?
700
ticks dd ?
702
captured dd ?
701
captured dd ?
703
if LEVELCONV eq 1
702
if LEVELCONV eq 1
704
  os_work rb 4096
703
  os_work rb 4096
705
end if
704
end if
706
field:
705
field:
707
    rb FLDSIZE*FLDSIZE
706
    rb FLDSIZE*FLDSIZE
708
rd 1
707
rd 1
709
buff:
708
buff:
710
    rb FLDSIZE*FLDSIZE
709
    rb FLDSIZE*FLDSIZE
711
stak:
710
stak: