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