⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tetris.asm

📁 Application sources:A084.ZIP
💻 ASM
📖 第 1 页 / 共 2 页
字号:
; Date : 1st April 2001
; TETRIS for MENUET
; Author : Paolo Minazzi (email paolo.minazzi@inwind.it)
;
; -Note-
; 1. This program requires a PENTIUM or higher because uses the RDTSC
;    instrucion for get a random number.
; 2. You must use NASM to compile. Compiling is OK with NASM 0.98, I
;    don't know what happen with other versions.
; 3. You must use the arrow key to move and rotate a block.
; 4. In the near future there will be a new version of TETRIS. This is
;    only the beginning.
;
; Thanks to Ville, the author of this wonderful OS !
; Join with us to code !
;
;
; Changelog:
;
; 28.06.2001 - fasm port & framed blocks - Ville Turjanmaa
; 31.10.2001 - rdtsc replaced            - quickcode <quickcode@mail.ru>
;
   
LEN_X equ 19
LEN_Y equ 29
BORDER_LEFT equ 1
BORDER_RIGHT equ 1
BORDER_TOP equ 1
BORDER_BOTTOM equ 1
ADOBE_SIZE equ 12
X_LOCATION equ 30
Y_LOCATION equ 50
UP_KEY equ 130+48
DOWN_KEY equ 129+48
LEFT_KEY equ 128+48
RIGHT_KEY equ 131+48
BACKGROUND equ 04000080h
   
use32
   
                org     0x0
   
                db      'MENUET00'              ; 8 byte id
                dd      38                      ; required os
                dd      START                   ; program start
                dd      I_END                   ; program image size
                dd      0x100000                ; reguired amount of memory
                dd      0x00000000              ; reserved=no extended header
   
   
START:                          ; start of execution
   
   
    ; --  quickcode - start
   
    mov   eax,3
    int   0x40
    mov   cl,16
    ror   eax,cl ; to make seconds more significant
    mov   [generator],eax
    call  random
   
    ; --  quickcode - end
   
   
    call clear_table_tetris
    call new_block
    call draw_window            ; at first, draw the window
   
still:
    xor edx,edx
    call draw_block
   
attesa:
    mov  eax,11                 ; get event
    int  0x40
   
    cmp  eax,1                  ; redraw request ?
    jz   red
    cmp  eax,2                  ; key in buffer ?
    jnz  check_button
    jmp key
check_button:
    cmp  eax,3                  ; button in buffer ?
    jnz   scendi
    jmp  button
   
  red:                          ; redraw
    call draw_window
    jmp  still
   
   
scendi:         inc dword [current_block_y]
                call check_crash
                jne block_crash
draw:           movzx edx,byte [current_block_color]
                call draw_block
                mov eax,5
                movzx ebx,byte [delay]
                int 0x40
                jmp  still
   
block_crash:    dec dword [current_block_y]
                movzx edx,byte [current_block_color]
                call draw_block
                call fix_block
                call check_full_line
                call draw_table
                call new_block
                inc dword [score]
                call write_score
                call check_crash
                jz adr400
aspetta:        mov eax,10
                int 0x40
                cmp eax,1
                jne adr10000
                call draw_window
adr10000:       cmp eax,3
                jne aspetta
new_game:       mov eax,17
                int 0x40
                cmp ah,1
                jnz adr401
                jmp end_program
   
adr401:         mov dword [score],0
                call clear_table_tetris
                call new_block
                call draw_window
   
adr400:         movzx edx,byte [current_block_color]
                call draw_block
                mov eax,5
                movzx ebx,byte [delay]
                int 0x40
                jmp still
   
key:            mov  eax,2
                int  0x40
   
adr32:          cmp ah,LEFT_KEY
                jne adr_30
                dec dword [current_block_x]
                call check_crash
                jz adr4000
                inc dword [current_block_x]
adr4000:        jmp scendi
   
adr_30:         cmp ah,RIGHT_KEY
                jne adr_31
                inc dword [current_block_x]
                call check_crash
                jz adr3000
                dec dword [current_block_x]
adr3000:        jmp scendi
   
adr_31:         cmp ah,UP_KEY
                jne adr51
                mov edx,[current_block_pointer]
                mov edx,[edx+16]
                mov esi,[current_block_pointer]
                mov [current_block_pointer],edx
                call check_crash
                jz adr50
                mov [current_block_pointer],esi
adr50:          jmp scendi
   
adr51:          cmp ah,DOWN_KEY
                jne adr61
                mov byte [delay],2
adr52:          jmp scendi
   
adr61:          cmp ah,' '
                jne adr62
                mov byte [delay],2
adr62:          jmp scendi
   
   
button:                       ; button
    mov  eax,17
    int  0x40
    cmp  ah,1                   ; button id=1 ?
    jz  end_program
    cmp ah,2
    jz go_new_game
    jmp still
   
end_program:
    mov  eax,0xffffffff         ; close this program
    int  0x40
   
go_new_game:
    jmp new_game
   
   
;   *********************************************
;   *******  WINDOW DEFINITIONS AND DRAW ********
;   *********************************************
   
   
   
draw_window:
   
   
    mov  eax,12                    ; function 12:tell os about windowdraw
    mov  ebx,1                     ; 1, start of draw
    int  0x40
   
                                 ; DRAW WINDOW
  mov  eax,0                     ; function 0 : define and draw window
  mov  ebx,320*65536+(LEN_X-BORDER_LEFT-BORDER_RIGHT)*ADOBE_SIZE+X_LOCATION*2
  mov  ecx,25*65536+ (LEN_Y-BORDER_TOP-BORDER_BOTTOM)*ADOBE_SIZE+Y_LOCATION+30
  mov  edx,BACKGROUND            ; color of work area RRGGBB
  mov  esi,window_label          ; color of grab bar  RRGGBB,8->col
  mov  edi,0                     ; color of frames    RRGGBB
  int  0x40
   
                                   ; CLOSE BUTTON
    mov  eax,8                     ; function 8 : define and draw button
    mov  ebx,243*65536+12          ; [x start] *65536 + [x size]
    mov  ecx,5*65536+12            ; [y start] *65536 + [y size]
    mov  edx,1                     ; button id
    mov  esi,0x5580cc;22aacc              ; button color RRGGBB
;    int  0x40
   
    mov eax,8
    mov ebx,30*65536+204
    mov ecx,378*65536+18
    mov edx,2
    mov esi,0x224466;5580cc;22aacc
    int 0x40
   
    mov eax,4
    mov ebx,34*65536+384
    xor ecx,ecx
    mov ecx,0x10ffffff
    mov edx,game_finished
    mov esi,size_of_game_finished-game_finished
    int 0x40
   
    call draw_table
   
    movzx edx,byte [current_block_color]
    call draw_block
   
    cld
    mov  ebx,38*65536+35           ; draw info text with function 4
    mov  ecx,0x10ffffff              ; color
    mov  edx,text
    mov  esi,7
    mov  eax,4
    int  0x40
   
    call write_score
   
    mov  eax,12                    ; function 12:tell os about windowdraw
    mov  ebx,2                     ; 2, end of draw
    int  0x40
   
    ret
   
   
   
;-------------------------------------------------------------
; CHECK CRASH
; output        Z  flag => OK
;               NZ flag => NO
;-------------------------------------------------------------
   
check_crash:    mov ebx,[current_block_pointer]
   
                mov edx,[current_block_y]
                imul edx,LEN_X
                add edx,[current_block_x]          ;find the offset in tetris_t
   
                add edx,table_tetris
   
                mov ecx,4
                xor ax,ax
   
adr_1:          cmp byte [ebx],1
                jne adr_2
                add al,[edx]
                adc ah,0
adr_2:          inc ebx
                inc edx
   
                cmp byte [ebx],1
                jne adr_3
                add al,[edx]
                adc ah,0
adr_3:          inc ebx
                inc edx
   
                cmp byte [ebx],1
                jne adr_4
                add al,[edx]
                adc ah,0
adr_4:          inc ebx
                inc edx
   
                cmp byte [ebx],1
                jne adr_5
                add al,[edx]
                adc ah,0
adr_5:          inc ebx
                add edx,LEN_X-3
   
                loop adr_1
                or ax,ax
                ret
;-------------------------------------------------------------
;NEW BLOCK
;-------------------------------------------------------------
new_block:      mov dword [current_block_y],1
                mov dword [current_block_x],7
   
                call random
                and al,7
                setz ah
                add al,ah
                mov [current_block_color],al
   
                call random
                and eax,15
                mov edx,[block_table+eax*4]
                mov [current_block_pointer],edx
   
                mov byte [delay],15
                ret
;-------------------------------------------------------------
; FIX BLOCK
;-------------------------------------------------------------
fix_block:      mov ebx,[current_block_pointer]
   
                mov edx,[current_block_y]
                imul edx,LEN_X
                add edx,[current_block_x]       ;find the offset in tetris_t
   
                add edx,table_tetris
   
                mov ecx,4
                mov al,[current_block_color]
   
adr_21:         cmp byte [ebx],1
                jne adr_22
                mov [edx],al
adr_22:         inc ebx
                inc edx
   
                cmp byte [ebx],1
                jne adr_23
                mov [edx],al
adr_23:         inc ebx
                inc edx
   
                cmp byte [ebx],1
                jne adr_24
                mov [edx],al
adr_24:         inc ebx

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -