Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ----------------------------------------------------------------------------------------
- ; tetris like v1.1 26/04/2020
- ; ----------------------------------------------------------------------------------------
- use16
- ; ORG 0x7c00
- ORG 0x0100
- global _start
- _start:
- clc
- cld
- ; push cs
- ; pop ss
- ; push cs
- ; pop ds
- mov ax, 0x13
- int 0x10 ;video mode 320x200 256 couleurs
- push ds
- pop es
- ; loadPalette
- mov dx, 0x03C8 ; registre pour modifier la palette }
- sub al, 0x12 ; Start at colour index 1 }
- out dx, al
- inc dx ; dx=0x03c9 :tranfert des couleurs(rvb)
- mov cx, 7 ; 7 pieces
- xor bl, bl
- PALLOOP:
- inc bl
- mov al, 0x3f
- call palette
- mov al, 0x1f
- call palette
- mov al, 0x2f
- call palette
- loop PALLOOP ;creation de couleurs vives en 3 degradés
- ; 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
- mov al, 7
- mov cx, 32
- rep stosb ;bloc n°7 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 bx, 19 ; nb de lignes
- sss2:
- mov cx, 11 ;briques par ligne
- dec bx
- mov si, bx
- shl si, 5 ;*32
- add si, 0x200A
- xor dx, dx
- sss0:
- lodsb
- test al, al
- jz sss
- inc dl
- sss:
- loop sss0
- mov al, [vitesse]
- cmp dl, 11
- jb sss1
- call effaceligne
- mov al, [vitesse]
- dec al
- cmp al, 5
- ja sss1
- inc al
- sss1:
- mov [vitesse], al ;on augmente la vitesse
- test bx, bx
- jnz sss2
- mov dx, 0x0d00
- mov [x], dh ; init x=13 y=0
- mov [y], dl
- 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
- xor ax, ax
- mov al, [vitesse]
- 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 dh, [x]
- mov dl, [y]
- mov cl, [rotation]
- ret
- _testCol0:
- push cx
- call testCol
- pop cx
- 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:
- dec bx
- sub si, 43
- mov cx, 11
- sst0:
- lodsb
- mov [ds:si+31], al
- loop sst0
- test bx, bx
- jnz sst2
- mov bx, 19
- ret
- mul32:
- xor ax, ax
- xor bx, bx
- mov bl, dh ;bl =x
- mov al, dl ;al =y
- 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 ax, 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 al, 1
- 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
- xor ax,ax
- mov al,cl
- 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)
- mov bl,3
- mul bl
- inc al ; al = 3n + 1 -> 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
- test ah,ah
- jnz o1
- inc al
- sub di,319
- mov bx,9
- back1:
- mov cx,bx
- rep stosb ; triangle de 10x10 couleur n°2
- sub di,319
- sub di,bx
- dec bx
- jnz back1
- mov bl,10
- inc al
- add di,2*320 -8
- mov bl,6
- mov dx,6
- back2:
- mov cx,dx
- rep stosb ; carré de 6x6 couleur n°3
- add di,320
- sub di,dx
- dec bl
- jnz back2
- o1:
- popa
- ret
- palette:
- mov bh, 1
- mov si, 3
- r:
- call test0
- shl bh, 1
- dec si
- jnz r
- ret
- test0:
- test bl, bh
- jz next2
- out dx, al
- jmp n2
- next2:
- xchg al, ah
- out dx, al
- xchg al, ah
- n2:
- ret
- vitesse:
- db 18
- fonction:
- dw 0
- rotation:
- db 0
- collision:
- db 0
- opaque:
- db 0
- piece:
- db 0
- time:
- dw 0
- x:
- db 13
- y:
- 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