Rev 109 | Rev 551 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 109 | Rev 485 | ||
---|---|---|---|
1 | ; |
1 | ; |
2 | ; The famous game 15 |
2 | ; The famous game 15 |
3 | ; Author: Lloyd, coded by Ivushkin Andrey |
3 | ; Author: Lloyd, coded by Ivushkin Andrey |
4 | ; Compile with FASM |
4 | ; Compile with FASM |
5 | ; |
5 | ; |
6 | include 'lang.inc' |
6 | include 'lang.inc' |
7 | include 'macros.inc' ; decreases program size (not required) |
7 | include '..\..\..\macros.inc' ; decreases program size (not required) |
8 | - | ||
9 | BgdColor equ 0x02aabbcc |
8 | |
10 | StatusColor equ 0x02ffffff |
9 | StatusColor equ 0x02ffffff |
11 | StatusColor2 equ 0x02dc1e14 |
10 | StatusColor2 equ 0x02dc1e14 |
12 | BgdColor equ 0x03aabbcc |
11 | BgdColor equ 0x03aabbcc |
13 | 12 | ||
14 | ; Main window dimensions |
13 | ; Main window dimensions |
15 | XXwindow equ 200 shl 16+276 |
14 | XXwindow equ 200 shl 16+276 |
16 | YYwindow equ 200 shl 16+300 |
15 | YYwindow equ 200 shl 16+300 |
17 | ; Status bar |
16 | ; Status bar |
18 | XYstatus equ 35 shl 16+283 |
17 | XYstatus equ 35 shl 16+283 |
19 | XXbar equ 35 shl 16+136 |
18 | XXbar equ 35 shl 16+136 |
20 | YYbar equ 280 shl 16+15 |
19 | YYbar equ 280 shl 16+15 |
21 | ; Buttons |
20 | ; Buttons |
22 | BtnTop equ 28 |
21 | BtnTop equ 28 |
23 | BtnLeft equ 13 |
22 | BtnLeft equ 13 |
24 | BtnSize equ 60 |
23 | BtnSize equ 60 |
25 | BtnColor equ 0xafbb55 |
24 | BtnColor equ 0xafbb55 |
26 | BtnColor2 equ 0x0228c314 |
25 | BtnColor2 equ 0x0228c314 |
27 | 26 | ||
28 | NumColor equ 0x10000000 |
27 | NumColor equ 0x10000000 |
29 | ; Number shifting for nice look |
28 | ; Number shifting for nice look |
30 | NumShift equ 24 shl 16+27 |
29 | NumShift equ 24 shl 16+27 |
31 | NumShift2 equ 4 shl 16 |
30 | NumShift2 equ 4 shl 16 |
32 | ; Shuffle button |
31 | ; Shuffle button |
33 | XXSh equ 202 shl 16+60 |
32 | XXSh equ 202 shl 16+60 |
34 | YYSh equ 280 shl 16+12 |
33 | YYSh equ 280 shl 16+12 |
35 | XYShText equ 212 shl 16+283 |
34 | XYShText equ 212 shl 16+283 |
36 | 35 | ||
37 | ; Conf button |
36 | ; Conf button |
38 | XXCnf equ 13 shl 16+13 |
37 | XXCnf equ 13 shl 16+13 |
39 | YYCnf equ 280 shl 16+12 |
38 | YYCnf equ 280 shl 16+12 |
40 | XYCnfText equ 18 shl 16+283 |
39 | XYCnfText equ 18 shl 16+283 |
41 | 40 | ||
42 | ; Position of the 'hole' |
41 | ; Position of the 'hole' |
43 | null equ (curconf+16) |
42 | null equ (curconf+16) |
44 | ; Amount of moves to perform shuffle |
43 | ; Amount of moves to perform shuffle |
45 | SH_CYCLES equ 400 |
44 | SH_CYCLES equ 400 |
46 | ; (Amount of tasks)-1 |
45 | ; (Amount of tasks)-1 |
47 | CONF_COUNT equ 2 |
46 | CONF_COUNT equ 2 |
48 | 47 | ||
49 | use32 |
48 | use32 |
50 | 49 | ||
51 | org 0x0 |
50 | org 0x0 |
52 | 51 | ||
53 | db 'MENUET01' |
52 | db 'MENUET01' |
54 | dd 0x01 |
53 | dd 0x01 |
55 | dd START |
54 | dd START |
56 | dd I_END |
55 | dd I_END |
57 | dd 0x2000 ; 8 Kb |
56 | dd 0x2000 ; 8 Kb |
58 | dd 0x2000 |
57 | dd 0x2000 |
59 | dd 0x0 |
58 | dd 0x0 |
60 | dd 0x0 |
59 | dd 0x0 |
61 | 60 | ||
62 | 61 | ||
63 | START: |
62 | START: |
64 | mov [cptr],CONF_COUNT ; number of task |
63 | mov [cptr],CONF_COUNT ; number of task |
65 | mov eax,3 |
64 | mov eax,3 |
66 | int 0x40 |
65 | mcall |
67 | mov cl,16 |
66 | mov cl,16 |
68 | ror eax,cl |
67 | ror eax,cl |
69 | mov [generator],eax ; random generator from Tetris |
68 | mov [generator],eax ; random generator from Tetris |
70 | init: |
69 | init: |
71 | mov ecx,17 |
70 | mov ecx,17 |
72 | movzx eax,[cptr] |
71 | movzx eax,[cptr] |
73 | inc eax |
72 | inc eax |
74 | cmp eax,CONF_COUNT |
73 | cmp eax,CONF_COUNT |
75 | jna init_ok |
74 | jna init_ok |
76 | xor eax,eax ; cycling 0..CONF_COUNT |
75 | xor eax,eax ; cycling 0..CONF_COUNT |
77 | init_ok: |
76 | init_ok: |
78 | mov [cptr],al |
77 | mov [cptr],al |
79 | mov esi,eax |
78 | mov esi,eax |
80 | shl esi,4 |
79 | shl esi,4 |
81 | add esi,conf |
80 | add esi,conf |
82 | add esi,eax |
81 | add esi,eax |
83 | add al,0x31 |
82 | add al,0x31 |
84 | mov [lenTitle-1],al ;task number to program title |
83 | mov [lenTitle-1],al ;task number to program title |
85 | mov [task],esi |
84 | mov [task],esi |
86 | mov edi,curconf |
85 | mov edi,curconf |
87 | rep movsb ; initial configuration |
86 | rep movsb ; initial configuration |
88 | 87 | ||
89 | mov [sts],4 |
88 | mov [sts],4 |
90 | jmp red |
89 | jmp red |
91 | SHUF: |
90 | SHUF: |
92 | call shuffle ; immediate shuffle |
91 | call shuffle ; immediate shuffle |
93 | red: ; window redraw |
92 | red: ; window redraw |
94 | 93 | ||
95 | call draw_window |
94 | call draw_window |
96 | 95 | ||
97 | still: ; MAIN PROGRAM CYCLE |
96 | still: ; MAIN PROGRAM CYCLE |
98 | 97 | ||
99 | mov eax,10 ; wait for event |
98 | mov eax,10 ; wait for event |
100 | int 0x40 |
99 | mcall |
101 | 100 | ||
102 | cmp eax,1 ; redraw? - |
101 | cmp eax,1 ; redraw? - |
103 | je red ; goto red |
102 | je red ; goto red |
104 | cmp eax,2 ; key pressed? - |
103 | cmp eax,2 ; key pressed? - |
105 | je key ; goto key |
104 | je key ; goto key |
106 | cmp eax,3 ; button pressed? - |
105 | cmp eax,3 ; button pressed? - |
107 | je button ; goto button |
106 | je button ; goto button |
108 | 107 | ||
109 | jmp still ; no more events to process |
108 | jmp still ; no more events to process |
110 | 109 | ||
111 | key: ; Key pressed |
110 | key: ; Key pressed |
112 | mov eax,2 |
111 | mov eax,2 |
113 | int 0x40 |
112 | mcall |
114 | shr eax,8 |
113 | shr eax,8 |
115 | cmp eax,32 ; |
114 | cmp eax,32 ; |
116 | je SHUF |
115 | je SHUF |
117 | cmp eax,13 ; |
116 | cmp eax,13 ; |
118 | je init |
117 | je init |
119 | cmp eax,176 |
118 | cmp eax,176 |
120 | jl still |
119 | jl still |
121 | sub eax,176 |
120 | sub eax,176 |
122 | cmp eax,3 |
121 | cmp eax,3 |
123 | ja still |
122 | ja still |
124 | movzx eax,byte [eax+correct] ; 'delta' value from correct[] |
123 | movzx eax,byte [eax+correct] ; 'delta' value from correct[] |
125 | jmp m_check |
124 | jmp m_check |
126 | 125 | ||
127 | button: ; Button pressed |
126 | button: ; Button pressed |
128 | mov eax,17 |
127 | mov eax,17 |
129 | int 0x40 |
128 | mcall |
130 | shr eax,8 |
129 | shr eax,8 |
131 | sub eax,2 |
130 | sub eax,2 |
132 | 131 | ||
133 | cmp eax,-1 ; id == 1 (closeme)? |
132 | cmp eax,-1 ; id == 1 (closeme)? |
134 | jne noclose |
133 | jne noclose |
135 | int 0x40 |
134 | mcall |
136 | 135 | ||
137 | noclose: |
136 | noclose: |
138 | jl SHUF ; Shuffle (id=0) pressed |
137 | jl SHUF ; Shuffle (id=0) pressed |
139 | cmp eax,18 |
138 | cmp eax,18 |
140 | je init ; Conf button pressed |
139 | je init ; Conf button pressed |
141 | sub al,byte [null] |
140 | sub al,byte [null] |
142 | mov edi,correct |
141 | mov edi,correct |
143 | mov ecx,4 |
142 | mov ecx,4 |
144 | repne scasb ; checking for valid move-part 1 |
143 | repne scasb ; checking for valid move-part 1 |
145 | jne fail |
144 | jne fail |
146 | m_check: |
145 | m_check: |
147 | cmp byte[sts],4 ; puzzle completed, blocking buttons |
146 | cmp byte[sts],4 ; puzzle completed, blocking buttons |
148 | ja still |
147 | ja still |
149 | call move_check ; checking for valid move-part 2 |
148 | call move_check ; checking for valid move-part 2 |
150 | jnc fail |
149 | jnc fail |
151 | inc [move_count] |
150 | inc [move_count] |
152 | call draw_moves |
151 | call draw_moves |
153 | fail: |
152 | fail: |
154 | jmp still ; ¢®§¢à é ¥¬áï |
153 | jmp still ; ¢®§¢à é ¥¬áï |
155 | 154 | ||
156 | ; ******************************* |
155 | ; ******************************* |
157 | ; ******* WINDOW DRAWING ******* |
156 | ; ******* WINDOW DRAWING ******* |
158 | ; ******************************* |
157 | ; ******************************* |
159 | 158 | ||
160 | draw_window: |
159 | draw_window: |
161 | mov eax,12 |
160 | mov eax,12 |
162 | mov ebx,1 ; begin draw |
161 | mov ebx,1 ; begin draw |
163 | int 0x40 |
162 | mcall |
164 | 163 | ||
165 | ; CREATING WINDOW |
164 | ; CREATING WINDOW |
166 | mov eax,0 |
165 | mov eax,0 |
167 | mov ebx,XXwindow |
166 | mov ebx,XXwindow |
168 | mov ecx,YYwindow |
167 | mov ecx,YYwindow |
169 | mov edx,BgdColor |
168 | mov edx,BgdColor |
170 | mov esi,0x805080d0 |
169 | mov esi,0x805080d0 |
171 | mov edi,0x005080d0 |
170 | mov edi,0x005080d0 |
172 | int 0x40 |
171 | mcall |
173 | 172 | ||
174 | ; PROGRAM TITLE |
173 | ; PROGRAM TITLE |
175 | mov eax,4 |
174 | mov eax,4 |
176 | mov ebx,8*65536+8 |
175 | mov ebx,8*65536+8 |
177 | mov ecx,0x10ddeeff |
176 | mov ecx,0x10000000 |
178 | mov edx,txtTitle |
177 | mov edx,txtTitle |
179 | mov esi,lenTitle-txtTitle |
178 | mov esi,lenTitle-txtTitle |
180 | int 0x40 |
179 | mcall |
181 | 180 | ||
182 | mov eax,8 ; SHUFFLE BUTTON |
181 | mov eax,8 ; SHUFFLE BUTTON |
183 | mov ebx,XXSh |
182 | mov ebx,XXSh |
184 | mov ecx,YYSh |
183 | mov ecx,YYSh |
185 | xor edx,edx |
184 | xor edx,edx |
186 | mov esi,BtnColor |
185 | mov esi,BtnColor |
187 | int 0x40 |
186 | mcall |
188 | 187 | ||
189 | mov ebx,XXCnf ; CONF BUTTON |
188 | mov ebx,XXCnf ; CONF BUTTON |
190 | mov ecx,YYCnf |
189 | mov ecx,YYCnf |
191 | mov edx,20 |
190 | mov edx,20 |
192 | mov esi,BtnColor |
191 | mov esi,BtnColor |
193 | int 0x40 |
192 | mcall |
194 | 193 | ||
195 | mov ebx, XYShText ; SHUFFLE TEXT |
194 | mov ebx, XYShText ; SHUFFLE TEXT |
196 | mov ecx, StatusColor |
195 | mov ecx, StatusColor |
197 | mov edx,txtSh |
196 | mov edx,txtSh |
198 | mov esi,lenSh-txtSh |
197 | mov esi,lenSh-txtSh |
199 | mov eax,4 |
198 | mov eax,4 |
200 | int 0x40 |
199 | mcall |
201 | 200 | ||
202 | mov ebx, XYCnfText ; CONF TEXT |
201 | mov ebx, XYCnfText ; CONF TEXT |
203 | mov edx,lenVictory-1 |
202 | mov edx,lenVictory-1 |
204 | mov esi,1 |
203 | mov esi,1 |
205 | int 0x40 |
204 | mcall |
206 | 205 | ||
207 | mov ecx, 16 ; FIELD BUTTONS |
206 | mov ecx, 16 ; FIELD BUTTONS |
208 | dbut: |
207 | dbut: |
209 | call draw_button |
208 | call draw_button |
210 | loop dbut |
209 | loop dbut |
211 | 210 | ||
212 | call draw_moves |
211 | call draw_moves |
213 | 212 | ||
214 | mov eax,12 |
213 | mov eax,12 |
215 | mov ebx,2 ; end of drawing |
214 | mov ebx,2 ; end of drawing |
216 | int 0x40 |
215 | mcall |
217 | ret |
216 | ret |
218 | 217 | ||
219 | 218 | ||
220 | ; ********************************************* |
219 | ; ********************************************* |
221 | ; ******* DRAWING A FIELD BUTTON ************** |
220 | ; ******* DRAWING A FIELD BUTTON ************** |
222 | ; ********************************************* |
221 | ; ********************************************* |
223 | ; ECX - button number |
222 | ; ECX - button number |
224 | 223 | ||
225 | draw_button: |
224 | draw_button: |
226 | pusha |
225 | pusha |
227 | dec ecx |
226 | dec ecx |
228 | ; calculating button dimensions |
227 | ; calculating button dimensions |
229 | mov edi, ecx |
228 | mov edi, ecx |
230 | lea edx,[ecx+2] |
229 | lea edx,[ecx+2] |
231 | mov ebx,ecx |
230 | mov ebx,ecx |
232 | and ebx,11b |
231 | and ebx,11b |
233 | shr ecx,2 |
232 | shr ecx,2 |
234 | 233 | ||
235 | imul ebx,BtnSize+3 |
234 | imul ebx,BtnSize+3 |
236 | add ebx,BtnLeft |
235 | add ebx,BtnLeft |
237 | shl ebx,16 |
236 | shl ebx,16 |
238 | add ebx,BtnSize |
237 | add ebx,BtnSize |
239 | 238 | ||
240 | imul ecx,BtnSize+3 |
239 | imul ecx,BtnSize+3 |
241 | add ecx,BtnTop |
240 | add ecx,BtnTop |
242 | shl ecx,16 |
241 | shl ecx,16 |
243 | add ecx,BtnSize |
242 | add ecx,BtnSize |
244 | movzx eax,byte [null] |
243 | movzx eax,byte [null] |
245 | cmp eax,edi |
244 | cmp eax,edi |
246 | jne no_hole |
245 | jne no_hole |
247 | 246 | ||
248 | pusha |
247 | pusha |
249 | inc ebx |
248 | inc ebx |
250 | inc ecx |
249 | inc ecx |
251 | mov edx,BgdColor |
250 | mov edx,BgdColor |
252 | mov eax,13 ; clearing - 'hole' |
251 | mov eax,13 ; clearing - 'hole' |
253 | int 0x40 |
252 | mcall |
254 | popa |
253 | popa |
255 | 254 | ||
256 | or edx,0x80000000 ; and removing button under it |
255 | or edx,0x80000000 ; and removing button under it |
257 | no_hole: |
256 | no_hole: |
258 | mov al,byte[edi+curconf] |
257 | mov al,byte[edi+curconf] |
259 | mov esi,[task] |
258 | mov esi,[task] |
260 | cmp al,byte[edi+esi] |
259 | cmp al,byte[edi+esi] |
261 | je highlight |
260 | je highlight |
262 | mov esi,BtnColor |
261 | mov esi,BtnColor |
263 | jmp s_rbutton |
262 | jmp s_rbutton |
264 | highlight: |
263 | highlight: |
265 | mov esi,BtnColor2 |
264 | mov esi,BtnColor2 |
266 | s_rbutton: |
265 | s_rbutton: |
267 | mov eax,8 ; set/remove button |
266 | mov eax,8 ; set/remove button |
268 | int 0x40 |
267 | mcall |
269 | movzx eax,byte [null] |
268 | movzx eax,byte [null] |
270 | cmp eax,edi |
269 | cmp eax,edi |
271 | je no_text ; no digits - that's hole |
270 | je no_text ; no digits - that's hole |
272 | mov edx,ebx |
271 | mov edx,ebx |
273 | shr ecx,16 |
272 | shr ecx,16 |
274 | mov dx,cx |
273 | mov dx,cx |
275 | add edx,NumShift |
274 | add edx,NumShift |
276 | mov ebx,0x20000 |
275 | mov ebx,0x20000 |
277 | movzx ecx,byte [edi+curconf] |
276 | movzx ecx,byte [edi+curconf] |
278 | cmp ecx,9 |
277 | cmp ecx,9 |
279 | ja two_num |
278 | ja two_num |
280 | add edx,NumShift2 ; shift to center digits |
279 | add edx,NumShift2 ; shift to center digits |
281 | sub ebx,0x10000 |
280 | sub ebx,0x10000 |
282 | two_num: |
281 | two_num: |
283 | mov esi,NumColor |
282 | mov esi,NumColor |
284 | mov eax,47 |
283 | mov eax,47 |
285 | int 0x40 |
284 | mcall |
286 | no_text: |
285 | no_text: |
287 | popa |
286 | popa |
288 | ret |
287 | ret |
289 | 288 | ||
290 | 289 | ||
291 | ; ********************************************* |
290 | ; ********************************************* |
292 | ; ******* DRAWING STATUS LINE ***************** |
291 | ; ******* DRAWING STATUS LINE ***************** |
293 | ; ********************************************* |
292 | ; ********************************************* |
294 | 293 | ||
295 | draw_moves: |
294 | draw_moves: |
296 | mov eax, 13 ; clear area |
295 | mov eax, 13 ; clear area |
297 | mov ebx, XXbar |
296 | mov ebx, XXbar |
298 | mov ecx, YYbar |
297 | mov ecx, YYbar |
299 | mov edx, BgdColor |
298 | mov edx, BgdColor |
300 | int 0x40 |
299 | mcall |
301 | 300 | ||
302 | mov eax, 4 |
301 | mov eax, 4 |
303 | mov ebx, XYstatus |
302 | mov ebx, XYstatus |
304 | mov ecx, StatusColor |
303 | mov ecx, StatusColor |
305 | cmp ax, [sts] |
304 | cmp ax, [sts] |
306 | jl report_victory |
305 | jl report_victory |
307 | jne report_moves |
306 | jne report_moves |
308 | mov edx,txtCnf ; prompt to choose configuration |
307 | mov edx,txtCnf ; prompt to choose configuration |
309 | mov esi,lenCnf-txtCnf |
308 | mov esi,lenCnf-txtCnf |
310 | jmp e_dm |
309 | jmp e_dm |
311 | report_moves: |
310 | report_moves: |
312 | mov edx,txtMoves ; how many moves done |
311 | mov edx,txtMoves ; how many moves done |
313 | mov esi,lenMoves-txtMoves |
312 | mov esi,lenMoves-txtMoves |
314 | mov eax,4 |
313 | mov eax,4 |
315 | int 0x40 |
314 | mcall |
316 | mov esi,ecx |
315 | mov esi,ecx |
317 | mov edx,ebx |
316 | mov edx,ebx |
318 | add edx, 40 shl 16 |
317 | add edx, 40 shl 16 |
319 | mov ebx,0x030000 |
318 | mov ebx,0x030000 |
320 | movzx ecx, byte[move_count] |
319 | movzx ecx, byte[move_count] |
321 | mov eax,47 |
320 | mov eax,47 |
322 | jmp e_dm |
321 | jmp e_dm |
323 | report_victory: ; puzzle completed |
322 | report_victory: ; puzzle completed |
324 | mov ecx,StatusColor2 |
323 | mov ecx,StatusColor2 |
325 | mov edx,txtVictory |
324 | mov edx,txtVictory |
326 | mov esi,lenVictory-txtVictory |
325 | mov esi,lenVictory-txtVictory |
327 | e_dm: |
326 | e_dm: |
328 | int 0x40 |
327 | mcall |
329 | ret |
328 | ret |
330 | 329 | ||
331 | 330 | ||
332 | ; ********************************************* |
331 | ; ********************************************* |
333 | ; ********* SHUFFLE *************************** |
332 | ; ********* SHUFFLE *************************** |
334 | ; ********************************************* |
333 | ; ********************************************* |
335 | 334 | ||
336 | shuffle: |
335 | shuffle: |
337 | xor eax,eax |
336 | xor eax,eax |
338 | mov [sts],ax |
337 | mov [sts],ax |
339 | mov [move_count],ax ; reset moves to 0 |
338 | mov [move_count],ax ; reset moves to 0 |
340 | mov [sh_off],al |
339 | mov [sh_off],al |
341 | mov eax, [generator] |
340 | mov eax, [generator] |
342 | 341 | ||
343 | mov ecx,SH_CYCLES |
342 | mov ecx,SH_CYCLES |
344 | sh_cycle: |
343 | sh_cycle: |
345 | sub eax,0x43ab45b5 ; next random number |
344 | sub eax,0x43ab45b5 ; next random number |
346 | ror eax,1 |
345 | ror eax,1 |
347 | xor eax,0x32c4324f |
346 | xor eax,0x32c4324f |
348 | ror eax,1 |
347 | ror eax,1 |
349 | mov [generator],eax |
348 | mov [generator],eax |
350 | 349 | ||
351 | push eax |
350 | push eax |
352 | and eax,11b ; direction 0..3 |
351 | and eax,11b ; direction 0..3 |
353 | movzx eax,byte [eax+correct] |
352 | movzx eax,byte [eax+correct] |
354 | call move_check |
353 | call move_check |
355 | pop eax |
354 | pop eax |
356 | jnc sh_cycle ; if fails then retry |
355 | jnc sh_cycle ; if fails then retry |
357 | loop sh_cycle |
356 | loop sh_cycle |
358 | inc byte[sh_off] ; shuffling complete |
357 | inc byte[sh_off] ; shuffling complete |
359 | ret |
358 | ret |
360 | 359 | ||
361 | 360 | ||
362 | ; ********************************************* |
361 | ; ********************************************* |
363 | ; ********* MOVE VALIDITY CHECK *************** |
362 | ; ********* MOVE VALIDITY CHECK *************** |
364 | ; ********************************************* |
363 | ; ********************************************* |
365 | ; AL - 'DELTA' DIRECTION |
364 | ; AL - 'DELTA' DIRECTION |
366 | 365 | ||
367 | move_check: |
366 | move_check: |
368 | pusha |
367 | pusha |
369 | mov ah,byte [null] |
368 | mov ah,byte [null] |
370 | mov bx,ax |
369 | mov bx,ax |
371 | cmp bh,3 |
370 | cmp bh,3 |
372 | ja no_top |
371 | ja no_top |
373 | cmp al,-4 ; top of field |
372 | cmp al,-4 ; top of field |
374 | je no_move |
373 | je no_move |
375 | no_top: |
374 | no_top: |
376 | cmp bh,12 |
375 | cmp bh,12 |
377 | jb no_bottom |
376 | jb no_bottom |
378 | cmp al,4 ; bottom of field |
377 | cmp al,4 ; bottom of field |
379 | je no_move |
378 | je no_move |
380 | no_bottom: |
379 | no_bottom: |
381 | and bh,11b |
380 | and bh,11b |
382 | cmp bh,0 |
381 | cmp bh,0 |
383 | jnz no_left |
382 | jnz no_left |
384 | cmp al,-1 ; left of field |
383 | cmp al,-1 ; left of field |
385 | je no_move |
384 | je no_move |
386 | no_left: |
385 | no_left: |
387 | cmp bh,11b |
386 | cmp bh,11b |
388 | jnz ok |
387 | jnz ok |
389 | cmp al,1 ; right of field |
388 | cmp al,1 ; right of field |
390 | je no_move |
389 | je no_move |
391 | ok: |
390 | ok: |
392 | mov bx,ax |
391 | mov bx,ax |
393 | add bh,bl ; bh-new hole |
392 | add bh,bl ; bh-new hole |
394 | mov byte [null],bh |
393 | mov byte [null],bh |
395 | movzx ecx,ah |
394 | movzx ecx,ah |
396 | mov al,byte[ecx+curconf] |
395 | mov al,byte[ecx+curconf] |
397 | movzx edx,bh |
396 | movzx edx,bh |
398 | mov bl,byte[edx+curconf] ; swapping button & hole |
397 | mov bl,byte[edx+curconf] ; swapping button & hole |
399 | mov byte[ecx+curconf],bl |
398 | mov byte[ecx+curconf],bl |
400 | mov byte[edx+curconf],al |
399 | mov byte[edx+curconf],al |
401 | 400 | ||
402 | cmp byte[sh_off],0 ; if shuffle in progress, |
401 | cmp byte[sh_off],0 ; if shuffle in progress, |
403 | jz no_win ; then no redraw |
402 | jz no_win ; then no redraw |
404 | 403 | ||
405 | ; drawing button & hole |
404 | ; drawing button & hole |
406 | inc ecx |
405 | inc ecx |
407 | call draw_button |
406 | call draw_button |
408 | movzx ecx,bh |
407 | movzx ecx,bh |
409 | inc ecx |
408 | inc ecx |
410 | call draw_button |
409 | call draw_button |
411 | ; testing if task completed |
410 | ; testing if task completed |
412 | mov esi,[task] |
411 | mov esi,[task] |
413 | mov edi,curconf |
412 | mov edi,curconf |
414 | mov ecx,16 |
413 | mov ecx,16 |
415 | repe cmpsb |
414 | repe cmpsb |
416 | cmp ecx,0 |
415 | cmp ecx,0 |
417 | jne no_win |
416 | jne no_win |
418 | mov word[sts],6 ; puzzle done. Victory! |
417 | mov word[sts],6 ; puzzle done. Victory! |
419 | no_win: |
418 | no_win: |
420 | popa |
419 | popa |
421 | stc |
420 | stc |
422 | ret |
421 | ret |
423 | no_move: |
422 | no_move: |
424 | popa |
423 | popa |
425 | clc |
424 | clc |
426 | ret |
425 | ret |
427 | ; this is deprecated debug routine |
426 | ; this is deprecated debug routine |
428 | ;ud: |
427 | ;ud: |
429 | ; ud2 |
428 | ; ud2 |
430 | 429 | ||
431 | ; These are data used by program |
430 | ; These are data used by program |
432 | 431 | ||
433 | correct db 1,-4,4,-1 |
432 | correct db 1,-4,4,-1 |
434 | 433 | ||
435 | conf db 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,15 |
434 | conf db 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,15 |
436 | db 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0 |
435 | db 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0 |
437 | db 1,2,3,4,12,13,14,5,11,0,15,6,10,9,8,7,9 |
436 | db 1,2,3,4,12,13,14,5,11,0,15,6,10,9,8,7,9 |
438 | 437 | ||
439 | txtMoves: |
438 | txtMoves: |
440 | if lang eq ru |
439 | if lang eq ru |
441 | db '®¤®¢:' |
440 | db '®¤®¢:' |
442 | else |
441 | else |
443 | db 'Moves:' |
442 | db 'Moves:' |
444 | end if |
443 | end if |
445 | lenMoves: |
444 | lenMoves: |
446 | 445 | ||
447 | txtSh: |
446 | txtSh: |
448 | if lang eq ru |
447 | if lang eq ru |
449 | db ' ᮢª ' |
448 | db ' ᮢª ' |
450 | else |
449 | else |
451 | db 'Shuffle' |
450 | db 'Shuffle' |
452 | end if |
451 | end if |
453 | lenSh: |
452 | lenSh: |
454 | 453 | ||
455 | txtCnf: |
454 | txtCnf: |
456 | if lang eq ru |
455 | if lang eq ru |
457 | db 'ë¡¥à¨â¥ § ¤ çã ¨ ¦¬¨â¥->' |
456 | db 'ë¡¥à¨â¥ § ¤ çã ¨ ¦¬¨â¥->' |
458 | else |
457 | else |
459 | db 'Select task, then press ->' |
458 | db 'Select task, then press ->' |
460 | end if |
459 | end if |
461 | lenCnf: |
460 | lenCnf: |
462 | 461 | ||
463 | txtTitle: ; áâப § £®«®¢ª |
462 | txtTitle: ; áâப § £®«®¢ª |
464 | if lang eq ru |
463 | if lang eq ru |
465 | db '£à 15 - § ¤ ç X' |
464 | db '£à 15 - § ¤ ç X' |
466 | else |
465 | else |
467 | db 'Game 15 - puzzle X' |
466 | db 'Game 15 - puzzle X' |
468 | end if |
467 | end if |
469 | lenTitle: ; ¨ ¥ñ ª®¥æ |
468 | lenTitle: ; ¨ ¥ñ ª®¥æ |
470 | 469 | ||
471 | txtVictory: |
470 | txtVictory: |
472 | if lang eq ru |
471 | if lang eq ru |
473 | db 'ë à¥è¨«¨ § ¤ çã! ¦¬¨â¥->' |
472 | db 'ë à¥è¨«¨ § ¤ çã! ¦¬¨â¥->' |
474 | else |
473 | else |
475 | db 'Puzzle completed! Press->' |
474 | db 'Puzzle completed! Press->' |
476 | end if |
475 | end if |
477 | lenVictory: |
476 | lenVictory: |
478 | 477 | ||
479 | arrow equ lenVictory-2 |
478 | arrow equ lenVictory-2 |
480 | 479 | ||
481 | I_END: ; ª®¥æ ¯à®£à ¬¬ë |
480 | I_END: ; ª®¥æ ¯à®£à ¬¬ë |
482 | ;null db ? |
481 | ;null db ? |
483 | move_count dw ? |
482 | move_count dw ? |
484 | cptr db ? |
483 | cptr db ? |
485 | sts dw ? |
484 | sts dw ? |
486 | sh_off db ? |
485 | sh_off db ? |
487 | task dd ? |
486 | task dd ? |
488 | generator dd ? |
487 | generator dd ? |
489 | curconf: |
488 | curconf: |