Rev 109 | Rev 180 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
31 | halyavin | 1 | ; Date : 1st April 2001 |
2 | ; TETRIS for MENUET |
||
3 | ; Author : Paolo Minazzi (email paolo.minazzi@inwind.it) |
||
4 | ; |
||
5 | ; -Note- |
||
6 | ; 1. This program requires a PENTIUM or higher because uses the RDTSC |
||
7 | ; instrucion for get a random number. |
||
8 | ; 2. You must use NASM to compile. Compiling is OK with NASM 0.98, I |
||
9 | ; don't know what happen with other versions. |
||
10 | ; 3. You must use the arrow key to move and rotate a block. |
||
11 | ; 4. In the near future there will be a new version of TETRIS. This is |
||
12 | ; only the beginning. |
||
13 | ; |
||
14 | ; Thanks to Ville, the author of this wonderful OS ! |
||
15 | ; Join with us to code ! |
||
16 | ; |
||
17 | ; |
||
18 | ; Changelog: |
||
131 | diamond | 19 | ; 09.11.2005 - fix for work under MeosDebug & better random - Andrey Halyavin |
20 | ; 23.09.2005 - fixed bug, when 011111111111111-like sequence interpreted |
||
21 | ; as _11111111111111 in check_full_line - Sergey Kuzmin aka Wildwest |
||
22 | ; 18.09.2005 - added 'Pause' button and made appropriate code and interface redesign |
||
23 | ; BTW, you can MOVE and ROTATE block during Pause ;) - Sergey Kuzmin aka Wildwest |
||
24 | ; 03.11.2003 - added new blocks & random - Ivan Poddubny |
||
25 | ; 31.10.2001 - rdtsc replaced - quickcode |
||
31 | halyavin | 26 | ; 28.06.2001 - fasm port & framed blocks - Ville Turjanmaa |
131 | diamond | 27 | ; |
31 | halyavin | 28 | ; |
29 | |||
131 | diamond | 30 | LEN_X equ 19 ;width of table |
31 | LEN_Y equ 29 ; height of table |
||
32 | BORDER_LEFT equ 1 |
||
33 | BORDER_RIGHT equ 1 |
||
31 | halyavin | 34 | BORDER_TOP equ 1 |
35 | BORDER_BOTTOM equ 1 |
||
36 | ADOBE_SIZE equ 12 |
||
131 | diamond | 37 | |
38 | X_LOCATION equ 30 ; distance to table from left side |
||
39 | Y_LOCATION equ 50 ; distance to table from header |
||
40 | |||
41 | UP_KEY equ 130+48 |
||
42 | DOWN_KEY equ 129+48 |
||
43 | LEFT_KEY equ 128+48 |
||
44 | RIGHT_KEY equ 131+48 |
||
45 | BACKGROUND equ 03000080h |
||
46 | |||
31 | halyavin | 47 | _MAXBLOCKS_ = 7*4 |
48 | |||
49 | use32 |
||
50 | |||
131 | diamond | 51 | org 0x0 |
31 | halyavin | 52 | |
131 | diamond | 53 | db 'MENUET01' ; 8 byte id |
54 | dd 0x01 ; header version |
||
55 | dd START ; program start |
||
56 | dd I_END ; program image size |
||
57 | dd I_END+1024 ; reguired amount of memory |
||
58 | dd I_END+1024 ; esp |
||
59 | dd 0x0,0x0 ; I_PARAM, I_ICON |
||
31 | halyavin | 60 | include 'lang.inc' |
131 | diamond | 61 | include 'macros.inc' |
31 | halyavin | 62 | |
63 | |||
131 | diamond | 64 | START: ; start of execution |
31 | halyavin | 65 | |
66 | |||
131 | diamond | 67 | ; -- quickcode - start |
31 | halyavin | 68 | |
131 | diamond | 69 | mov eax,3 |
70 | int 0x40 |
||
71 | mov cl,16 |
||
72 | ror eax,cl ; to make seconds more significant |
||
73 | mov [generator],eax |
||
74 | call random |
||
31 | halyavin | 75 | |
131 | diamond | 76 | ; -- quickcode - end |
77 | |||
78 | |||
79 | call clear_table_tetris |
||
80 | call new_block |
||
81 | call draw_window ; at first, draw the window |
||
82 | |||
83 | still: |
||
31 | halyavin | 84 | xor edx,edx |
85 | call draw_block |
||
86 | |||
87 | attesa: |
||
88 | |||
131 | diamond | 89 | mov eax,11 ; get event |
31 | halyavin | 90 | int 0x40 |
91 | |||
131 | diamond | 92 | cmp eax,1 ; redraw request ? |
93 | jz red |
||
94 | cmp eax,2 ; key in buffer ? |
||
31 | halyavin | 95 | jnz check_button |
96 | jmp key |
||
97 | check_button: |
||
131 | diamond | 98 | cmp eax,3 ; button in buffer ? |
31 | halyavin | 99 | jnz scendi |
131 | diamond | 100 | jmp button |
31 | halyavin | 101 | |
131 | diamond | 102 | red: ; redraw |
31 | halyavin | 103 | call draw_window |
104 | jmp still |
||
105 | |||
106 | |||
107 | |||
131 | diamond | 108 | scendi: |
109 | ;///////////////////////////////////////////////// Wildwest |
||
110 | cmp dword [pauses], 0 |
||
111 | je ok |
||
112 | jne not_ok |
||
113 | not_ok: |
||
114 | inc dword [current_block_y] |
||
115 | dec dword [current_block_y] |
||
116 | call check_crash |
||
117 | jne block_crash |
||
118 | jmp draw |
||
119 | ok: |
||
120 | ;///////////////////////////////////////////////// |
||
121 | inc dword [current_block_y] |
||
122 | call check_crash |
||
123 | jne block_crash |
||
124 | draw: movzx edx,byte [current_block_color] |
||
125 | call draw_block |
||
126 | mov eax,5 |
||
127 | movzx ebx,byte [delay] |
||
128 | int 0x40 |
||
129 | jmp still |
||
31 | halyavin | 130 | |
131 | diamond | 131 | block_crash: dec dword [current_block_y] |
132 | movzx edx,byte [current_block_color] |
||
133 | call draw_block |
||
134 | call fix_block |
||
135 | call check_full_line |
||
136 | call draw_table |
||
137 | call new_block |
||
138 | inc dword [score] |
||
139 | call write_score |
||
140 | call check_crash |
||
141 | jz adr400 |
||
142 | aspetta: mov eax,10 |
||
143 | int 0x40 |
||
144 | cmp eax,1 |
||
145 | jne adr10000 |
||
146 | call draw_window |
||
147 | adr10000: cmp eax,3 |
||
148 | jne aspetta |
||
149 | new_game: mov eax,17 |
||
150 | int 0x40 |
||
151 | cmp ah,1 |
||
152 | jnz adr401 |
||
153 | jmp end_program |
||
154 | adr401: |
||
155 | ;///////////////////////////////////////////////////// Wildwest |
||
156 | mov dword [pauses], 0 |
||
157 | ;//////////////////////////////////////////////////// |
||
158 | mov dword [score],0 |
||
159 | call clear_table_tetris |
||
160 | call new_block |
||
161 | call draw_window |
||
31 | halyavin | 162 | |
131 | diamond | 163 | adr400: movzx edx,byte [current_block_color] |
164 | call draw_block |
||
165 | mov eax,5 |
||
166 | movzx ebx,byte [delay] |
||
167 | int 0x40 |
||
168 | jmp still |
||
31 | halyavin | 169 | |
131 | diamond | 170 | key: mov eax,2 |
171 | int 0x40 |
||
31 | halyavin | 172 | |
131 | diamond | 173 | adr32: cmp ah,LEFT_KEY |
174 | jne adr_30 |
||
175 | dec dword [current_block_x] |
||
176 | call check_crash |
||
177 | jz adr4000 |
||
178 | inc dword [current_block_x] |
||
179 | adr4000: jmp scendi |
||
31 | halyavin | 180 | |
131 | diamond | 181 | adr_30: cmp ah,RIGHT_KEY |
182 | jne adr_31 |
||
183 | inc dword [current_block_x] |
||
184 | call check_crash |
||
185 | jz adr3000 |
||
186 | dec dword [current_block_x] |
||
187 | adr3000: jmp scendi |
||
31 | halyavin | 188 | |
131 | diamond | 189 | adr_31: cmp ah,UP_KEY |
190 | jne adr51 |
||
191 | mov edx,[current_block_pointer] |
||
192 | mov edx,[edx+16] |
||
193 | mov esi,[current_block_pointer] |
||
194 | mov [current_block_pointer],edx |
||
195 | call check_crash |
||
196 | jz adr50 |
||
197 | mov [current_block_pointer],esi |
||
198 | adr50: jmp scendi |
||
31 | halyavin | 199 | |
131 | diamond | 200 | adr51: cmp ah,DOWN_KEY |
201 | jne adr61 |
||
202 | mov byte [delay],5 ;!!! 2 |
||
203 | adr52: jmp scendi |
||
204 | |||
205 | adr61: cmp ah,' ' |
||
206 | jne adr62 |
||
207 | mov byte [delay],5 ;!!! 2 |
||
208 | adr62: jmp scendi |
||
209 | |||
210 | |||
211 | button: ; button |
||
212 | mov eax,17 |
||
213 | int 0x40 |
||
214 | cmp ah,1 ; button id=1 ? |
||
215 | jz end_program |
||
216 | cmp ah,2 |
||
217 | jz go_new_game |
||
218 | cmp ah,3 ; button id=3 ? ///Wildwest's 'Pause' button |
||
219 | jz pause_program |
||
220 | jmp still |
||
221 | |||
222 | end_program: |
||
223 | mov eax,0xffffffff ; close this program |
||
224 | int 0x40 |
||
225 | |||
226 | go_new_game: |
||
227 | jmp new_game |
||
228 | ;//////////////////////////////////////////////////// Wildwest |
||
229 | pause_program: |
||
230 | cmp dword [pauses], 0 |
||
231 | je incr |
||
232 | mov dword [pauses], 0 |
||
233 | jmp still |
||
234 | incr: |
||
235 | mov dword [pauses], 1 |
||
236 | jmp still |
||
237 | ;//////////////////////////////////////////////////// |
||
238 | ; ********************************************* |
||
239 | ; ******* WINDOW DEFINITIONS AND DRAW ******** |
||
240 | ; ********************************************* |
||
241 | draw_window: |
||
242 | |||
243 | |||
244 | mov eax,12 ; function 12:tell os about windowdraw |
||
245 | mov ebx,1 ; 1, start of draw |
||
246 | int 0x40 |
||
247 | |||
248 | ; DRAW WINDOW |
||
249 | mov eax,0 ; function 0 : define and draw window |
||
250 | mov ebx,320*65536+(LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2 |
||
251 | mov ecx,25*65536+ (LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION+30 |
||
252 | mov edx,BACKGROUND ; color of work area RRGGBB |
||
253 | mov esi,0x006688ee;99bbff ; color of grab bar RRGGBB,8->col |
||
254 | mov edi,0x007799ff;99bbee ; color of frames RRGGBB |
||
255 | int 0x40 |
||
256 | |||
257 | ; WINDOW LABEL |
||
258 | mov eax,4 ; function 4 : write text to window |
||
259 | mov ebx,8*65536+8 ; [x start] *65536 + [y start] |
||
260 | mov ecx,0x10ffffff ; color of text RRGGBB |
||
261 | mov edx,labelt ; pointer to text beginning |
||
262 | mov esi,labellen-labelt ; text length |
||
263 | int 0x40 |
||
264 | |||
265 | ; CLOSE BUTTON |
||
266 | ; mov eax,8 ; function 8 : define and draw button |
||
267 | ; mov ebx,243*65536+12 ; [x start] *65536 + [x size] |
||
268 | ; mov ecx,5*65536+12 ; [y start] *65536 + [y size] |
||
269 | ; mov edx,1 ; button id |
||
270 | ; mov esi,0x5580cc;22aacc ; button color RRGGBB |
||
271 | ; int 0x40 |
||
272 | |||
273 | mov eax,8 |
||
274 | mov ebx,30*65536+102 |
||
275 | mov ecx,378*65536+18 |
||
276 | mov edx,2 |
||
277 | mov esi,0xA24466;5580cc;22aacc |
||
278 | int 0x40 |
||
279 | ;/////////////////////////////////////////////// Wildwest's 'Pause' button |
||
280 | mov eax,8 |
||
281 | mov ebx,132*65536+102 |
||
282 | mov ecx,378*65536+18 |
||
283 | mov edx,3 |
||
284 | mov esi,0x0FA0F0; |
||
285 | int 0x40 |
||
286 | |||
287 | mov eax,4 ; function 4 : write text to window |
||
288 | mov ebx,164*65536+384 ; [x start] *65536 + [y start] |
||
289 | mov ecx,0x10ffffff ; color of text RRGGBB |
||
290 | mov edx,labe ; pointer to text beginning |
||
291 | mov esi,labelen-labe ; text length |
||
292 | int 0x40 |
||
293 | ;/////////////////////////////////////////////// |
||
294 | mov eax,4 |
||
295 | mov ebx,49*65536+384 |
||
296 | xor ecx,ecx |
||
297 | mov ecx,0x10ffffff |
||
298 | mov edx,game_finished |
||
299 | mov esi,size_of_game_finished-game_finished |
||
300 | int 0x40 |
||
301 | |||
302 | call draw_table |
||
303 | |||
304 | movzx edx,byte [current_block_color] |
||
305 | call draw_block |
||
306 | |||
307 | cld |
||
308 | mov ebx,38*65536+35 ; draw info text with function 4 |
||
309 | mov ecx,0x10ffffff ; color |
||
310 | mov edx,text |
||
311 | mov esi,7 |
||
312 | mov eax,4 |
||
313 | int 0x40 |
||
314 | |||
315 | call write_score |
||
316 | |||
317 | mov eax,12 ; function 12:tell os about windowdraw |
||
318 | mov ebx,2 ; 2, end of draw |
||
319 | int 0x40 |
||
320 | |||
321 | ret |
||
322 | |||
323 | ;------------------------------------------------------------- |
||
324 | ; CHECK CRASH |
||
325 | ; output Z flag => OK |
||
326 | ; NZ flag => NO |
||
327 | ;------------------------------------------------------------- |
||
328 | |||
329 | check_crash: mov ebx,[current_block_pointer] |
||
330 | |||
331 | mov edx,[current_block_y] |
||
332 | imul edx,LEN_X |
||
333 | add edx,[current_block_x] ;find the offset in tetris_t |
||
334 | |||
335 | add edx,table_tetris |
||
336 | |||
337 | mov ecx,4 |
||
338 | xor ax,ax |
||
339 | |||
340 | adr_1: cmp byte [ebx],1 |
||
341 | jne adr_2 |
||
342 | add al,[edx] |
||
343 | adc ah,0 |
||
344 | adr_2: inc ebx |
||
345 | inc edx |
||
346 | |||
347 | cmp byte [ebx],1 |
||
348 | jne adr_3 |
||
349 | add al,[edx] |
||
350 | adc ah,0 |
||
351 | adr_3: inc ebx |
||
352 | inc edx |
||
353 | |||
354 | cmp byte [ebx],1 |
||
355 | jne adr_4 |
||
356 | add al,[edx] |
||
357 | adc ah,0 |
||
358 | adr_4: inc ebx |
||
359 | inc edx |
||
360 | |||
361 | cmp byte [ebx],1 |
||
362 | jne adr_5 |
||
363 | add al,[edx] |
||
364 | adc ah,0 |
||
365 | adr_5: inc ebx |
||
366 | add edx,LEN_X-3 |
||
367 | |||
368 | loop adr_1 |
||
369 | or ax,ax |
||
370 | ret |
||
371 | ;------------------------------------------------------------- |
||
372 | ;NEW BLOCK |
||
373 | ;------------------------------------------------------------- |
||
374 | new_block: mov dword [current_block_y],1 |
||
375 | mov dword [current_block_x],7 |
||
376 | |||
377 | call random |
||
378 | and al,7 |
||
379 | setz ah |
||
380 | add al,ah |
||
381 | mov [current_block_color],al |
||
382 | |||
383 | call random |
||
384 | ;and eax,15 |
||
385 | ; ---- Ivan ---- |
||
386 | and eax,0xff |
||
387 | @@: |
||
388 | cmp eax,_MAXBLOCKS_ |
||
389 | jl @f |
||
390 | add eax,-(_MAXBLOCKS_) |
||
391 | jmp @b |
||
392 | @@: |
||
393 | ; ---- Ivan ---- |
||
394 | mov edx,[block_table+eax*4] |
||
395 | mov [current_block_pointer],edx |
||
396 | |||
397 | mov byte [delay],22 ;19 ;!!! 15 |
||
398 | ret |
||
399 | ;------------------------------------------------------------- |
||
400 | ; FIX BLOCK |
||
401 | ;------------------------------------------------------------- |
||
402 | fix_block: mov ebx,[current_block_pointer] |
||
403 | |||
404 | mov edx,[current_block_y] |
||
405 | imul edx,LEN_X |
||
406 | add edx,[current_block_x] ;find the offset in tetris_t |
||
407 | |||
408 | add edx,table_tetris |
||
409 | |||
410 | mov ecx,4 |
||
411 | mov al,[current_block_color] |
||
412 | |||
413 | adr_21: cmp byte [ebx],1 |
||
414 | jne adr_22 |
||
415 | mov [edx],al |
||
416 | adr_22: inc ebx |
||
417 | inc edx |
||
418 | |||
419 | cmp byte [ebx],1 |
||
420 | jne adr_23 |
||
421 | mov [edx],al |
||
422 | adr_23: inc ebx |
||
423 | inc edx |
||
424 | |||
425 | cmp byte [ebx],1 |
||
426 | jne adr_24 |
||
427 | mov [edx],al |
||
428 | adr_24: inc ebx |
||
429 | inc edx |
||
430 | |||
431 | cmp byte [ebx],1 |
||
432 | jne adr_25 |
||
433 | mov [edx],al |
||
434 | adr_25: inc ebx |
||
435 | add edx,LEN_X-3 |
||
436 | |||
437 | loop adr_21 |
||
438 | ret |
||
439 | |||
440 | ;-------------------------------------------------------------- |
||
441 | ; DRAW_TABLE |
||
442 | ;-------------------------------------------------------------- |
||
443 | draw_table: mov esi,table_tetris+LEN_X*BORDER_TOP+BORDER_LEFT |
||
444 | |||
445 | mov ebx,X_LOCATION*65536+ADOBE_SIZE |
||
446 | mov ecx,Y_LOCATION*65536+ADOBE_SIZE |
||
447 | mov edi,LEN_Y-BORDER_TOP-BORDER_BOTTOM |
||
448 | y_draw: push edi |
||
449 | |||
450 | mov edi,LEN_X-BORDER_LEFT-BORDER_RIGHT |
||
451 | x_draw: push edi |
||
452 | ; pusha |
||
453 | ; mov eax,5 |
||
454 | ; mov ebx,10 |
||
455 | ; int 0x40 |
||
456 | ; popa |
||
457 | mov ax,13 |
||
458 | movzx edx,byte [esi] |
||
459 | mov edx,[color_table+edx*4] |
||
460 | int 0x40 |
||
461 | call draw_frames |
||
462 | inc esi |
||
463 | add ebx,65536*ADOBE_SIZE |
||
464 | pop edi |
||
465 | dec edi |
||
466 | jnz x_draw |
||
467 | |||
468 | add esi,BORDER_LEFT+BORDER_RIGHT |
||
469 | mov ebx,X_LOCATION*65536+ADOBE_SIZE |
||
470 | add ecx,65536*ADOBE_SIZE |
||
471 | pop edi |
||
472 | dec edi |
||
473 | jnz y_draw |
||
474 | |||
475 | ret |
||
476 | ;-------------------------------------------------------------- |
||
477 | ;DRAW BLOCK |
||
478 | ; |
||
479 | ; ebx=x [0..LEN_X-1] |
||
480 | ; ecx=y [0..LEN_Y-1] |
||
481 | ; edi=pointer block |
||
482 | ;-------------------------------------------------------------- |
||
483 | draw_block: |
||
484 | |||
485 | mov eax,13 |
||
486 | mov edx,[color_table+edx*4] |
||
487 | |||
488 | mov ebx,[current_block_x] |
||
489 | mov ecx,[current_block_y] |
||
490 | mov edi,[current_block_pointer] |
||
491 | |||
492 | sub ebx,BORDER_LEFT |
||
493 | imul ebx,ADOBE_SIZE |
||
494 | add ebx,X_LOCATION |
||
495 | shl ebx,16 |
||
496 | mov bx,ADOBE_SIZE |
||
497 | |||
498 | sub ecx,BORDER_TOP |
||
499 | imul ecx,ADOBE_SIZE |
||
500 | add ecx,Y_LOCATION |
||
501 | shl ecx,16 |
||
502 | mov cx,ADOBE_SIZE |
||
503 | |||
504 | mov dword [TMP_1],4 |
||
505 | adr_122: mov dword [TMP_0],4 |
||
506 | adr_121: cmp byte [edi],0 |
||
507 | je adr_120 |
||
508 | |||
509 | int 040h |
||
510 | |||
511 | call draw_frames |
||
512 | |||
513 | adr_120: inc edi |
||
514 | add ebx,ADOBE_SIZE*65536 |
||
515 | dec dword [TMP_0] |
||
516 | jnz adr_121 |
||
517 | sub ebx,4*ADOBE_SIZE*65536 |
||
518 | add ecx,ADOBE_SIZE*65536 |
||
519 | dec dword [TMP_1] |
||
520 | jnz adr_122 |
||
521 | |||
522 | ret |
||
523 | |||
524 | draw_frames: |
||
525 | cmp edx,0 |
||
526 | jne df1 |
||
527 | ret |
||
528 | df1: |
||
529 | pusha |
||
530 | mov bx,1 |
||
531 | add edx,0x282828 |
||
532 | mov eax,13 |
||
533 | int 0x40 |
||
534 | popa |
||
535 | |||
536 | pusha |
||
537 | mov cx,1 |
||
538 | add edx,0x282828 |
||
539 | mov eax,13 |
||
540 | int 0x40 |
||
541 | popa |
||
542 | |||
543 | pusha |
||
544 | push ebx |
||
545 | sub bx,1 |
||
546 | add [esp+2],bx |
||
547 | pop ebx |
||
548 | mov bx,1 |
||
549 | shr edx,1 |
||
550 | and edx,0x7f7f7f |
||
551 | mov eax,13 |
||
552 | int 0x40 |
||
553 | popa |
||
554 | |||
555 | pusha |
||
556 | push ecx |
||
557 | sub cx,1 |
||
558 | add [esp+2],cx |
||
559 | pop ecx |
||
560 | mov cx,1 |
||
561 | shr edx,1 |
||
562 | and edx,0x7f7f7f |
||
563 | mov eax,13 |
||
564 | int 0x40 |
||
565 | popa |
||
566 | |||
567 | ret |
||
568 | |||
569 | |||
570 | ;-------------------------------------------------------------- |
||
571 | clear_table_tetris: |
||
572 | cld |
||
573 | mov al,1 |
||
574 | mov edi,table_tetris |
||
575 | mov ecx,LEN_X*BORDER_TOP |
||
576 | rep stosb |
||
577 | |||
578 | mov edx,LEN_Y-BORDER_TOP-BORDER_BOTTOM |
||
579 | adr300: mov cl,BORDER_LEFT |
||
580 | rep stosb |
||
581 | dec ax ;AL=0 |
||
582 | mov cl,LEN_X-BORDER_LEFT-BORDER_RIGHT |
||
583 | rep stosb |
||
584 | inc ax ;AL=1 |
||
585 | mov cl,BORDER_RIGHT |
||
586 | rep stosb |
||
587 | dec dx |
||
588 | jne adr300 |
||
589 | |||
590 | mov ecx,LEN_X*BORDER_BOTTOM |
||
591 | rep stosb |
||
592 | ret |
||
593 | ;-------------------------------------------------------------- |
||
594 | ;edx = pointer |
||
595 | ;ebx = contatore |
||
596 | check_full_line: |
||
597 | std |
||
598 | mov al,0 |
||
599 | mov edx,table_tetris+LEN_X*(LEN_Y-BORDER_BOTTOM)-1 |
||
600 | mov ebx,(LEN_Y-BORDER_TOP-BORDER_BOTTOM-1)*LEN_X |
||
601 | |||
602 | adr_5000: mov edi,edx |
||
603 | mov ecx,LEN_X-BORDER_LEFT-BORDER_RIGHT+1;Wildwest's fix for bug |
||
604 | ;(was LEN_X-BORDER_LEFT-BORDER_RIGHT) |
||
605 | repne scasb |
||
606 | jz no_full_line |
||
607 | |||
608 | lea esi,[edx-LEN_X] |
||
609 | mov edi,edx |
||
610 | mov ecx,ebx |
||
611 | rep movsb |
||
612 | sub edi,BORDER_RIGHT |
||
613 | mov ecx,LEN_X-BORDER_LEFT-BORDER_RIGHT |
||
614 | rep stosb |
||
615 | add dword [score],50 |
||
616 | jmp adr_5000 |
||
617 | |||
618 | no_full_line: sub edx,LEN_X |
||
619 | sub ebx,LEN_X |
||
620 | jnz adr_5000 |
||
621 | |||
622 | ret |
||
623 | ;-------------------------------------------------------------- |
||
624 | random: mov eax,[generator] |
||
625 | add eax,-43ab45b5h |
||
626 | ror eax,1 |
||
627 | xor eax,32c4324fh |
||
628 | ror eax,1 |
||
629 | mov [generator],eax |
||
630 | ; --- IVAN --- |
||
631 | push ebx |
||
632 | mov eax,26 |
||
633 | mov ebx,9 |
||
634 | int 0x40 |
||
635 | pop ebx |
||
636 | xor eax,0xdeadbeef |
||
637 | add eax,[generator] |
||
638 | ; --- IVAN --- |
||
639 | mov [generator],eax ; Halyavin |
||
640 | ret |
||
641 | ;-------------------------------------------------------------- |
||
642 | number_to_str: mov edi,end_number_str-1 |
||
643 | mov ecx,9;size_of_number_str |
||
644 | mov ebx,10 |
||
645 | cld |
||
646 | new_digit: xor edx,edx |
||
647 | div ebx |
||
648 | add dl,'0' |
||
649 | mov [edi],dl |
||
650 | dec edi |
||
651 | loop new_digit |
||
652 | ret |
||
653 | ;-------------------------------------------------------------- |
||
654 | write_score: |
||
655 | mov eax,[score] |
||
656 | call number_to_str |
||
657 | |||
658 | mov ebx,100*65536+100 ;clear box to write new score |
||
659 | mov ecx,35*65536+15 |
||
660 | mov edx,BACKGROUND |
||
661 | mov eax,13 |
||
662 | int 40h |
||
663 | |||
664 | mov ebx,100*65536+35 ; draw info text with function 4 |
||
665 | mov ecx,0xffff00 ; color |
||
666 | mov edx,number_str |
||
667 | mov esi,[size_of_number_str] |
||
668 | mov eax,4 |
||
669 | int 0x40 |
||
670 | ret |
||
671 | |||
31 | halyavin | 672 | ; DATA AREA |
673 | |||
131 | diamond | 674 | ;-------------------------------------------------------------- |
675 | ;DEFINITION BLOCKS |
||
676 | ;-------------------------------------------------------------- |
||
677 | t_block_0: db 0,0,0,0 |
||
678 | db 1,1,1,0 |
||
679 | db 0,1,0,0 |
||
680 | db 0,0,0,0 |
||
681 | dd t_block_3 |
||
31 | halyavin | 682 | |
131 | diamond | 683 | t_block_1: db 0,1,0,0 |
684 | db 1,1,0,0 |
||
685 | db 0,1,0,0 |
||
686 | db 0,0,0,0 |
||
687 | dd t_block_0 |
||
31 | halyavin | 688 | |
131 | diamond | 689 | t_block_2: db 0,1,0,0 |
690 | db 1,1,1,0 |
||
691 | db 0,0,0,0 |
||
692 | db 0,0,0,0 |
||
693 | dd t_block_1 |
||
31 | halyavin | 694 | |
131 | diamond | 695 | t_block_3 db 0,1,0,0 |
696 | db 0,1,1,0 |
||
697 | db 0,1,0,0 |
||
698 | db 0,0,0,0 |
||
699 | dd t_block_2 |
||
700 | ;-------------------------------------------------------------- |
||
701 | i_block_0: db 0,1,0,0 |
||
702 | db 0,1,0,0 |
||
703 | db 0,1,0,0 |
||
704 | db 0,1,0,0 |
||
705 | dd i_block_1 |
||
31 | halyavin | 706 | |
131 | diamond | 707 | i_block_1: db 0,0,0,0 |
708 | db 1,1,1,1 |
||
709 | db 0,0,0,0 |
||
710 | db 0,0,0,0 |
||
711 | dd i_block_0 |
||
712 | ;-------------------------------------------------------------- |
||
713 | q_block_0: db 0,1,1,0 |
||
714 | db 0,1,1,0 |
||
715 | db 0,0,0,0 |
||
716 | db 0,0,0,0 |
||
717 | dd q_block_0 |
||
718 | ;-------------------------------------------------------------- |
||
719 | s_block_0: |
||
720 | db 0,0,0,0 |
||
721 | db 0,1,1,0 |
||
722 | db 1,1,0,0 |
||
723 | db 0,0,0,0 |
||
724 | dd s_block_1 |
||
31 | halyavin | 725 | |
131 | diamond | 726 | s_block_1: db 1,0,0,0 |
727 | db 1,1,0,0 |
||
728 | db 0,1,0,0 |
||
729 | db 0,0,0,0 |
||
730 | dd s_block_0 |
||
731 | ;-------------------------------------------------------------- |
||
732 | l_block_0: db 0,0,0,0 |
||
733 | db 1,1,1,0 |
||
734 | db 1,0,0,0 |
||
735 | db 0,0,0,0 |
||
736 | dd l_block_3 |
||
31 | halyavin | 737 | |
131 | diamond | 738 | l_block_1: db 1,1,0,0 |
739 | db 0,1,0,0 |
||
740 | db 0,1,0,0 |
||
741 | db 0,0,0,0 |
||
742 | dd l_block_0 |
||
31 | halyavin | 743 | |
131 | diamond | 744 | l_block_2: db 0,0,1,0 |
745 | db 1,1,1,0 |
||
746 | db 0,0,0,0 |
||
747 | db 0,0,0,0 |
||
748 | dd l_block_1 |
||
749 | |||
750 | l_block_3: db 0,1,0,0 |
||
751 | db 0,1,0,0 |
||
752 | db 0,1,1,0 |
||
753 | db 0,0,0,0 |
||
754 | dd l_block_2 |
||
755 | ;----------------------------------------------- |
||
756 | |||
757 | g_block_0: |
||
758 | |||
759 | db 0,1,0,0 |
||
760 | db 0,1,0,0 |
||
761 | db 1,1,0,0 |
||
762 | db 0,0,0,0 |
||
763 | dd g_block_1 |
||
764 | |||
765 | g_block_1: |
||
766 | db 0,0,0,0 |
||
767 | db 1,1,1,0 |
||
768 | db 0,0,1,0 |
||
769 | db 0,0,0,0 |
||
770 | dd g_block_2 |
||
771 | |||
772 | g_block_2: |
||
773 | db 0,1,1,0 |
||
774 | db 0,1,0,0 |
||
775 | db 0,1,0,0 |
||
776 | db 0,0,0,0 |
||
777 | dd g_block_3 |
||
778 | |||
779 | g_block_3: |
||
780 | db 1,0,0,0 |
||
781 | db 1,1,1,0 |
||
782 | db 0,0,0,0 |
||
783 | db 0,0,0,0 |
||
784 | dd g_block_0 |
||
785 | |||
786 | ;----------------------------------- |
||
787 | |||
788 | k_block_0: |
||
789 | db 0,0,0,0 |
||
790 | db 1,1,0,0 |
||
791 | db 0,1,1,0 |
||
792 | db 0,0,0,0 |
||
793 | dd k_block_1 |
||
794 | |||
795 | k_block_1: |
||
796 | db 0,1,0,0 |
||
797 | db 1,1,0,0 |
||
798 | db 1,0,0,0 |
||
799 | db 0,0,0,0 |
||
800 | dd k_block_0 |
||
801 | |||
802 | ;----------------------------------- |
||
803 | |||
804 | color_table: dd 00000000h ;black 0 |
||
805 | dd 00cccccch ;white 1 |
||
806 | dd 00cc0000h ;red 2 |
||
807 | dd 0000cc00h ;green 3 |
||
808 | dd 000000cch ;blue 4 |
||
809 | dd 00cccc00h ;yellow 5 |
||
810 | dd 0000cccch ;cyan 6 |
||
811 | dd 00cc00cch ;pink 7 |
||
812 | |||
813 | block_table: |
||
814 | dd t_block_0 ; t |
||
815 | dd t_block_1 |
||
816 | dd t_block_2 |
||
817 | dd t_block_3 |
||
818 | dd i_block_0 ; i |
||
819 | dd i_block_1 |
||
820 | dd i_block_0 |
||
821 | dd i_block_1 |
||
822 | dd q_block_0 ; q |
||
823 | dd q_block_0 |
||
824 | dd q_block_0 |
||
825 | dd q_block_0 |
||
826 | dd s_block_0 ; s |
||
827 | dd s_block_1 |
||
828 | dd s_block_0 |
||
829 | dd s_block_1 |
||
830 | dd l_block_0 ; l |
||
831 | dd l_block_1 |
||
832 | dd l_block_2 |
||
833 | dd l_block_3 |
||
834 | dd g_block_0 ; g |
||
835 | dd g_block_1 |
||
836 | dd g_block_2 |
||
837 | dd g_block_3 |
||
838 | dd k_block_0 ; k |
||
839 | dd k_block_1 |
||
840 | dd k_block_0 |
||
841 | dd k_block_1 |
||
842 | |||
843 | if lang eq ru |
||
844 | |||
845 | labelt: |
||
846 | db ' 1.6 - ' |
||
847 | labellen: |
||
848 | labe: |
||
849 | db '' |
||
850 | labelen: |
||
851 | text: db '窨: ' |
||
852 | game_finished: db ' ' |
||
853 | size_of_game_finished: |
||
854 | |||
855 | else |
||
856 | |||
857 | labelt: |
||
858 | db 'TETRIS 1.6 - ARROWS & SPACE' |
||
859 | labellen: |
||
860 | labe: |
||
861 | db 'PAUSE' |
||
862 | labelen: |
||
863 | text: db 'Score: ' |
||
864 | game_finished: db 'NEW GAME' |
||
865 | size_of_game_finished: |
||
866 | |||
867 | end if |
||
868 | |||
869 | pauses dd 0 ;/// Wildwest |
||
870 | parallel dd 1 |
||
871 | score: dd 0 |
||
872 | TMP_0: dd 0 |
||
873 | TMP_1: dd 0 |
||
874 | generator: dd 0 |
||
875 | current_block_x: dd 0 |
||
876 | current_block_y: dd 0 |
||
877 | current_block_pointer: dd 0 |
||
878 | current_block_color: db 0 |
||
879 | number_str: db 0,0,0,0,0,0,0,0,0 |
||
31 | halyavin | 880 | end_number_str: |
131 | diamond | 881 | size_of_number_str dd 9 |
882 | delay: db 40 |
||
883 | table_tetris: |
||
31 | halyavin | 884 | |
131 | diamond | 885 | I_END: |