Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ----------------------------------------------------------------------------------------
- ; tetris like v1.3 28/04/2020
- ; ----------------------------------------------------------------------------------------
- use16
- ; ORG 0x7c00
- ORG 0x0100
- global _start
- _start:
- clc
- cld
- mov ax, 0x13
- int 0x10 ;video mode 320x200 256 couleurs
- push ds
- pop es
- ; emplacement memoire (32*20=640 octets) terrain de jeu
- mov di, 0x2000 ; va ecrire en ds:0x2000
- xor al, al
- mov cx, 608
- rep stosb ; met à zero les 19 premieres lignes
- inc al
- mov cx, 32
- rep stosb ;bloc n°1 sur la derniere ligne
- mov di, 0x2009
- boucle:
- stosb
- add di, 11
- stosb
- add di, 19
- cmp di, 0x2260
- jb boucle ; ajoute 2 colonnes en x=9 et x=20
- _deb: ;debut du jeu
- mov ax, 0xa000 ; pointe la memoire video
- mov es, ax
- ; teste si des lignes sont completes
- mov si,8778
- sss2:
- mov cx, 11 ;briques par ligne
- mov dx, cx
- sss0:
- lodsb
- test al, al
- jz sss
- dec dl
- sss:
- loop sss0
- mov al, [vitesse]
- test dl, dl
- jnz sss1
- push ax
- call effaceligne
- pop ax
- dec al
- cmp al, 5
- ja sss1
- inc al
- sss1:
- mov [vitesse], al ;on augmente la vitesse (ou pas)
- sub si,43
- cmp si,0x1feA
- ja sss2
- mov dx, 0x0d00 ; init x=13 y=0
- mov [y], dx
- mov [rotation], dl
- ; affiche terrain a l'ecran
- mov di, 0x2000
- mov bx, di ;data du terrain
- xor dx, dx ; x=0 y=0
- pix:
- xor ax, ax
- mov al, [bx] ; y a t il un bloc ici ?
- test al, al ;
- jnz ok
- mov ah, 1
- ok:
- mov [opaque], ah
- dec al
- mov [piece], al ;couleur de la piece
- call affBrick2
- inc bx
- inc dh
- cmp dh, 32
- jnz pix
- xor dh, dh
- inc dl
- cmp dl, 20
- jnz pix
- ; choisit une piece au "hasard"
- xor ax, ax
- int 0x1a ;int timer resultat dans CX:DX 1/18 de seconde
- mov [time], dx
- mov ax, dx
- add ax, cx
- mul cx ;dx:ax = ax*cx
- add ax, dx
- rol ax, 7
- shl ax, 13
- shr ax, 13
- cmp al, 7
- jb nxt
- dec al
- nxt:
- mov [piece], al
- _cycle:
- xor al, al
- call affOuEff ;affiche la piece
- _cycle0:
- xor ah, ah
- int 0x1a ;int timer resultat dans CX:DX 1/18 de seconde
- mov ax, [time]
- pushf
- sub dx, ax
- popf
- mov al, [vitesse]
- cbw
- cmp dx, ax ;temps de chute de la piece
- jb _continue
- jmp _down
- _continue:
- mov ax, 0x0100 ; test si touche
- int 0x16 ; clavier appuyée
- jz _cycle0
- xor ax, ax
- int 0x16 ; on purge la touche du buffer
- inc al ; opaque=1, pour effacer
- cmp ah, 0x50 ; touche fleche bas
- je _down
- cmp ah, 0x4B ; touche fleche gauche
- je leftOrRight
- cmp ah, 0x4D ; touche fleche droite
- je leftOrRight
- cmp ah, 0x48 ; touche fleche haut
- je _rotate
- cmp ah, 0x01 ; touche ESC
- jne _cycle0
- ret ; exit (touche ESC)
- _loadvars:
- mov dx, [y]
- mov cl, [rotation]
- ret
- _testCol0:
- call testCol
- mov al, [collision]
- test al,al ; y a t il une collision ?
- jz __e
- call _loadvars
- __e:
- ret
- _rotate:
- call affOuEff
- inc cl
- and cx, 3 ; == cx mod 4
- call _testCol0
- mov [rotation], cl
- jmp _cycle
- leftOrRight:
- push ax
- call affOuEff
- pop ax
- sub ah, 0x4c
- add dh, ah
- call _testCol0
- mov [x], dh
- jmp _cycle
- _down:
- call affOuEff
- inc dl
- call _testCol0
- jz _desc
- call freeze ;la piece touche le sol
- jmp _deb
- _desc: ;la piece continue de chuter
- mov [y], dl
- xor ah, ah
- int 0x1a ;int timer resultat dans CX:DX 1/18 de seconde
- mov [time], dx
- jmp _cycle
- freeze:
- mov ax, ds
- mov es, ax
- mov cl, [rotation]
- call _pointepiece
- mov bx, freezebrick
- mov [fonction], bx
- call boucle4x4
- ret
- effaceligne:
- sst2:
- sub si, 43
- mov cx, 11
- sst0:
- lodsb
- mov [ds:si+31], al
- loop sst0
- cmp si,0x2015
- ja sst2
- mov si,8821
- ret
- mul32:
- xor bx, bx
- mov bl, dh ;bl =x
- mov al, dl ;al =y
- cbw
- shl ax, 5 ;ax =y*32
- add ax, bx ;ax= y*32+x
- add ax, 0x2000
- ret
- freezebrick:
- pusha
- call mul32
- mov di, ax
- mov al, [piece]
- inc al
- stosb
- popa
- ret
- _pointepiece:
- xor ax, ax
- mov [collision],al
- mov al, [piece] ; n° de la piece (0-6)
- shl al, 1
- mov bx, pieces
- add bx, ax
- mov al, 14
- mul cl
- add bx, ax
- mov ax, [bx]
- ret
- boucle4x4:
- mov bl, 4
- dc_:
- mov bh, 4
- cc_:
- test ax, 1
- jz videc_
- call [fonction]
- videc_:
- shr ax, 1
- inc dh
- dec bh
- jnz cc_
- sub dh, 4
- inc dl
- dec bl
- jnz dc_
- sub dl, 4
- ret
- testCol:
- call _pointepiece
- mov bx, testBrick
- mov [fonction], bx
- call boucle4x4
- ret
- testBrick:
- pusha
- call mul32
- mov si, ax
- lodsb
- test al, al
- jz okt
- mov [collision],al
- okt:
- popa
- ret
- ;parcours des 4x4 briques de la piece
- affOuEff:
- mov [opaque], al
- call _loadvars
- call _pointepiece
- mov bx, affBrick2
- mov [fonction], bx
- call boucle4x4
- call _loadvars
- ret
- affBrick2:
- pusha
- mov cx,dx ; dh=x dl=y , on veut di=3200y+10x
- mov al,cl
- cbw
- mov bx,320
- mul bx
- xor bx,bx
- mov bl,ch
- add ax,bx
- mov bx,10
- mul bx
- mov di,ax ;di = 10*(320y+x)
- mov al,[piece] ; N° piece (0..6)
- shl al,2
- add al,0x20 ; al = n*4 + 0x20 -> couleur de base
- mov ah,[opaque]
- test ah,ah
- jz o0
- xor al,al ; couleur à 0 pour effacer
- o0:
- mov bl,10
- back:
- mov cx,10
- rep stosb ; carré de 10x10 couleur n°1
- add di,310
- dec bl
- jnz back
- popa
- ret
- vitesse:
- db 18
- fonction:
- dw 0
- rotation:
- db 0
- collision:
- db 0
- opaque:
- db 0
- piece:
- db 0
- time:
- dw 0
- y:
- db 0
- x:
- db 0
- pieces:
- dw 0x4444
- dw 0x4640
- dw 0x0660
- dw 0x2640
- dw 0x4620
- dw 0x6440
- dw 0x6220
- dw 0x0f00
- dw 0x0e40
- dw 0x0660
- dw 0x0c60
- dw 0x06c0
- dw 0x0e20
- dw 0x02e0
- dw 0x4444
- dw 0x4c40
- dw 0x0660
- dw 0x2640
- dw 0x4620
- dw 0x44c0
- dw 0x4460
- dw 0x0f00
- dw 0x4e00
- dw 0x0660
- dw 0x0c60
- dw 0x06c0
- dw 0x08e0
- dw 0x0e80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement