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