📄 tetris.asm
字号:
inc edx
cmp byte [ebx],1
jne adr_25
mov [edx],al
adr_25: inc ebx
add edx,LEN_X-3
loop adr_21
ret
;--------------------------------------------------------------
; DRAW_TABLE
;--------------------------------------------------------------
draw_table: mov esi,table_tetris+LEN_X*BORDER_TOP+BORDER_LEFT
mov ebx,X_LOCATION*65536+ADOBE_SIZE
mov ecx,Y_LOCATION*65536+ADOBE_SIZE
mov edi,LEN_Y-BORDER_TOP-BORDER_BOTTOM
y_draw: push edi
mov edi,LEN_X-BORDER_LEFT-BORDER_RIGHT
x_draw: push edi
mov ax,13
movzx edx,byte [esi]
mov edx,[color_table+edx*4]
int 0x40
call draw_frames
inc esi
add ebx,65536*ADOBE_SIZE
pop edi
dec edi
jnz x_draw
add esi,BORDER_LEFT+BORDER_RIGHT
mov ebx,X_LOCATION*65536+ADOBE_SIZE
add ecx,65536*ADOBE_SIZE
pop edi
dec edi
jnz y_draw
ret
;--------------------------------------------------------------
;DRAW BLOCK
;
; ebx=x [0..LEN_X-1]
; ecx=y [0..LEN_Y-1]
; edi=pointer block
;--------------------------------------------------------------
draw_block: mov eax,13
mov edx,[color_table+edx*4]
mov ebx,[current_block_x]
mov ecx,[current_block_y]
mov edi,[current_block_pointer]
sub ebx,BORDER_LEFT
imul ebx,ADOBE_SIZE
add ebx,X_LOCATION
shl ebx,16
mov bx,ADOBE_SIZE
sub ecx,BORDER_TOP
imul ecx,ADOBE_SIZE
add ecx,Y_LOCATION
shl ecx,16
mov cx,ADOBE_SIZE
mov dword [TMP_1],4
adr_122: mov dword [TMP_0],4
adr_121: cmp byte [edi],0
je adr_120
int 040h
call draw_frames
adr_120: inc edi
add ebx,ADOBE_SIZE*65536
dec dword [TMP_0]
jnz adr_121
sub ebx,4*ADOBE_SIZE*65536
add ecx,ADOBE_SIZE*65536
dec dword [TMP_1]
jnz adr_122
ret
draw_frames:
cmp edx,0
jne df1
ret
df1:
pusha
mov bx,1
add edx,0x282828
mov eax,13
int 0x40
popa
pusha
mov cx,1
add edx,0x282828
mov eax,13
int 0x40
popa
pusha
push ebx
sub bx,1
add [esp+2],bx
pop ebx
mov bx,1
shr edx,1
and edx,0x7f7f7f
mov eax,13
int 0x40
popa
pusha
push ecx
sub cx,1
add [esp+2],cx
pop ecx
mov cx,1
shr edx,1
and edx,0x7f7f7f
mov eax,13
int 0x40
popa
ret
;--------------------------------------------------------------
clear_table_tetris:
cld
mov al,1
mov edi,table_tetris
mov ecx,LEN_X*BORDER_TOP
rep stosb
mov edx,LEN_Y-BORDER_TOP-BORDER_BOTTOM
adr300: mov cl,BORDER_LEFT
rep stosb
dec ax ;AL=0
mov cl,LEN_X-BORDER_LEFT-BORDER_RIGHT
rep stosb
inc ax ;AL=1
mov cl,BORDER_RIGHT
rep stosb
dec dx
jne adr300
mov ecx,LEN_X*BORDER_BOTTOM
rep stosb
ret
;--------------------------------------------------------------
;edx = pointer
;ebx = contatore
check_full_line:
std
mov al,0
mov edx,table_tetris+LEN_X*(LEN_Y-BORDER_BOTTOM)-1
mov ebx,(LEN_Y-BORDER_TOP-BORDER_BOTTOM-1)*LEN_X
adr_5000: mov edi,edx
mov ecx,LEN_X-BORDER_LEFT-BORDER_RIGHT
repne scasb
jz no_full_line
lea esi,[edx-LEN_X]
mov edi,edx
mov ecx,ebx
rep movsb
sub edi,BORDER_RIGHT
mov ecx,LEN_X-BORDER_LEFT-BORDER_RIGHT
rep stosb
add dword [score],50
jmp adr_5000
no_full_line: sub edx,LEN_X
sub ebx,LEN_X
jnz adr_5000
ret
;--------------------------------------------------------------
random: mov eax,[generator]
sub eax,43ab45b5h
ror eax,1
xor eax,32c4324fh
ror eax,1
mov [generator],eax
ret
;--------------------------------------------------------------
number_to_str: mov edi,end_number_str-1
mov ecx,9;size_of_number_str
mov ebx,10
cld
new_digit: xor edx,edx
div ebx
add dl,'0'
mov [edi],dl
dec edi
loop new_digit
ret
;--------------------------------------------------------------
write_score:
mov eax,[score]
call number_to_str
mov ebx,100*65536+100 ;clear box to write new score
mov ecx,35*65536+15
mov edx,BACKGROUND
mov eax,13
int 40h
mov ebx,100*65536+35 ; draw info text with function 4
mov ecx,0xffff00 ; color
mov edx,number_str
mov esi,size_of_number_str
mov eax,4
int 0x40
ret
; DATA AREA
;--------------------------------------------------------------
;DEFINITION BLOCKS
;--------------------------------------------------------------
t_block_0: db 0,0,0,0
db 1,1,1,0
db 0,1,0,0
db 0,0,0,0
dd t_block_3
t_block_1: db 0,1,0,0
db 1,1,0,0
db 0,1,0,0
db 0,0,0,0
dd t_block_0
t_block_2: db 0,1,0,0
db 1,1,1,0
db 0,0,0,0
db 0,0,0,0
dd t_block_1
t_block_3 db 0,1,0,0
db 0,1,1,0
db 0,1,0,0
db 0,0,0,0
dd t_block_2
;--------------------------------------------------------------
i_block_0: db 0,1,0,0
db 0,1,0,0
db 0,1,0,0
db 0,1,0,0
dd i_block_1
i_block_1: db 0,0,0,0
db 1,1,1,1
db 0,0,0,0
db 0,0,0,0
dd i_block_0
;--------------------------------------------------------------
q_block_0: db 0,1,1,0
db 0,1,1,0
db 0,0,0,0
db 0,0,0,0
dd q_block_0
;--------------------------------------------------------------
s_block_0: db 0,0,0,0
db 0,1,1,0
db 1,1,0,0
db 0,0,0,0
dd s_block_1
s_block_1: db 1,0,0,0
db 1,1,0,0
db 0,1,0,0
db 0,0,0,0
dd s_block_0
;--------------------------------------------------------------
l_block_0: db 0,0,0,0
db 1,1,1,0
db 1,0,0,0
db 0,0,0,0
dd l_block_3
l_block_1: db 1,1,0,0
db 0,1,0,0
db 0,1,0,0
db 0,0,0,0
dd l_block_0
l_block_2: db 0,0,1,0
db 1,1,1,0
db 0,0,0,0
db 0,0,0,0
dd l_block_1
l_block_3: db 0,1,0,0
db 0,1,0,0
db 0,1,1,0
db 0,0,0,0
dd l_block_2
color_table: dd 00000000h ;black 0
dd 00cccccch ;white 1
dd 00cc0000h ;red 2
dd 0000cc00h ;green 3
dd 000000cch ;blue 4
dd 00cccc00h ;yellow 5
dd 0000cccch ;cyan 6
dd 00cc00cch ;pink 7
block_table: dd t_block_1
dd t_block_2
dd t_block_3
dd t_block_3
dd i_block_1
dd i_block_1
dd i_block_1
dd q_block_0
dd q_block_0
dd q_block_0
dd s_block_1
dd s_block_1
dd s_block_1
dd l_block_1
dd l_block_2
dd l_block_3
window_label:
db 'TETRIS',0
score: dd 0
text: db 'Score :'
game_finished: db ' NEW GAME'
size_of_game_finished:
TMP_0: dd 0
TMP_1: dd 0
generator: dd 0
current_block_x: dd 0
current_block_y: dd 0
current_block_pointer: dd 0
current_block_color: db 0
number_str: db 0,0,0,0,0,0,0,0,0
end_number_str:
size_of_number_str dd 9
delay: db 0
table_tetris:
I_END:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -