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