Advertisement
Guest User

Untitled

a guest
Apr 26th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.47 KB | None | 0 0
  1. ; ----------------------------------------------------------------------------------------
  2. ; tetris like v1.1 26/04/2020
  3. ; ----------------------------------------------------------------------------------------
  4. use16
  5.  
  6.  
  7. ; ORG 0x7c00
  8. ORG 0x0100
  9.  
  10. global _start
  11.  
  12. _start:
  13. clc
  14. cld
  15. ; push cs
  16. ; pop ss
  17. ; push cs
  18. ; pop ds
  19. mov ax, 0x13
  20. int 0x10 ;video mode 320x200 256 couleurs
  21. push ds
  22. pop es
  23.  
  24. ; loadPalette
  25. mov dx, 0x03C8 ; registre pour modifier la palette }
  26. sub al, 0x12 ; Start at colour index 1 }
  27. out dx, al
  28. inc dx ; dx=0x03c9 :tranfert des couleurs(rvb)
  29. mov cx, 7 ; 7 pieces
  30. xor bl, bl
  31. PALLOOP:
  32. inc bl
  33. mov al, 0x3f
  34. call palette
  35. mov al, 0x1f
  36. call palette
  37. mov al, 0x2f
  38. call palette
  39. loop PALLOOP ;creation de couleurs vives en 3 degradés
  40.  
  41.  
  42. ; emplacement memoire (32*20=640 octets) terrain de jeu
  43. mov di, 0x2000 ; va ecrire en ds:0x2000
  44. xor al, al
  45. mov cx, 608
  46. rep stosb ; met à zero les 19 premieres lignes
  47. mov al, 7
  48. mov cx, 32
  49. rep stosb ;bloc n°7 sur la derniere ligne
  50.  
  51. mov di, 0x2009
  52. boucle:
  53. stosb
  54. add di, 11
  55. stosb
  56. add di, 19
  57. cmp di, 0x2260
  58. jb boucle ; ajoute 2 colonnes en x=9 et x=20
  59.  
  60.  
  61.  
  62. _deb: ;debut du jeu
  63. mov ax, 0xa000 ; pointe la memoire video
  64. mov es, ax
  65.  
  66. ; teste si des lignes sont completes
  67. mov bx, 19 ; nb de lignes
  68.  
  69. sss2:
  70. mov cx, 11 ;briques par ligne
  71. dec bx
  72. mov si, bx
  73. shl si, 5 ;*32
  74. add si, 0x200A
  75. xor dx, dx
  76. sss0:
  77. lodsb
  78. test al, al
  79. jz sss
  80. inc dl
  81. sss:
  82. loop sss0
  83. mov al, [vitesse]
  84. cmp dl, 11
  85. jb sss1
  86. call effaceligne
  87. mov al, [vitesse]
  88. dec al
  89. cmp al, 5
  90. ja sss1
  91. inc al
  92. sss1:
  93. mov [vitesse], al ;on augmente la vitesse
  94. test bx, bx
  95. jnz sss2
  96.  
  97. mov dx, 0x0d00
  98. mov [x], dh ; init x=13 y=0
  99. mov [y], dl
  100. mov [rotation], dl
  101.  
  102. ; affiche terrain a l'ecran
  103. mov di, 0x2000
  104. mov bx, di ;data du terrain
  105. xor dx, dx ; x=0 y=0
  106. pix:
  107. xor ax, ax
  108. mov al, [bx] ; y a t il un bloc ici ?
  109. test al, al ;
  110. jnz ok
  111. mov ah, 1
  112. ok:
  113. mov [opaque], ah
  114. dec al
  115. mov [piece], al ;couleur de la piece
  116. call affBrick2
  117. inc bx
  118. inc dh
  119. cmp dh, 32
  120. jnz pix
  121. xor dh, dh
  122. inc dl
  123. cmp dl, 20
  124. jnz pix
  125.  
  126. ; choisit une piece au "hasard"
  127. xor ax, ax
  128. int 0x1a ;int timer resultat dans CX:DX 1/18 de seconde
  129. mov [time], dx
  130.  
  131. mov ax, dx
  132. add ax, cx
  133. mul cx ;dx:ax = ax*cx
  134. add ax, dx
  135. rol ax, 7
  136. shl ax, 13
  137. shr ax, 13
  138. cmp al, 7
  139. jb nxt
  140. dec al
  141. nxt:
  142. mov [piece], al
  143.  
  144.  
  145. _cycle:
  146. xor al, al
  147. call affOuEff ;affiche la piece
  148.  
  149. _cycle0:
  150. xor ah, ah
  151. int 0x1a ;int timer resultat dans CX:DX 1/18 de seconde
  152. mov ax, [time]
  153. pushf
  154. sub dx, ax
  155. popf
  156. xor ax, ax
  157. mov al, [vitesse]
  158. cmp dx, ax ;temps de chute de la piece
  159. jb _continue
  160. jmp _down
  161.  
  162. _continue:
  163. mov ax, 0x0100 ; test si touche
  164. int 0x16 ; clavier appuyée
  165. jz _cycle0
  166. xor ax, ax
  167. int 0x16 ; on purge la touche du buffer
  168.  
  169. inc al ; opaque=1, pour effacer
  170.  
  171. cmp ah, 0x50 ; touche fleche bas
  172. je _down
  173. cmp ah, 0x4B ; touche fleche gauche
  174. je leftOrRight
  175. cmp ah, 0x4D ; touche fleche droite
  176. je leftOrRight
  177. cmp ah, 0x48 ; touche fleche haut
  178. je _rotate
  179. cmp ah, 0x01 ; touche ESC
  180. jne _cycle0
  181.  
  182. ret ; exit (touche ESC)
  183.  
  184.  
  185. _loadvars:
  186. mov dh, [x]
  187. mov dl, [y]
  188. mov cl, [rotation]
  189. ret
  190.  
  191. _testCol0:
  192. push cx
  193. call testCol
  194. pop cx
  195. mov al, [collision]
  196. test al,al ; y a t il une collision ?
  197. jz __e
  198. call _loadvars
  199. __e:
  200. ret
  201.  
  202. _rotate:
  203. call affOuEff
  204. inc cl
  205. and cx, 3 ; == cx mod 4
  206. call _testCol0
  207. mov [rotation], cl
  208. jmp _cycle
  209.  
  210. leftOrRight:
  211. push ax
  212. call affOuEff
  213. pop ax
  214. sub ah, 0x4c
  215. add dh, ah
  216. call _testCol0
  217. mov [x], dh
  218. jmp _cycle
  219.  
  220. _down:
  221. call affOuEff
  222. inc dl
  223. call _testCol0
  224. jz _desc
  225. call freeze ;la piece touche le sol
  226. jmp _deb
  227. _desc: ;la piece continue de chuter
  228. mov [y], dl
  229. xor ah, ah
  230. int 0x1a ;int timer resultat dans CX:DX 1/18 de seconde
  231. mov [time], dx
  232. jmp _cycle
  233.  
  234.  
  235. freeze:
  236. mov ax, ds
  237. mov es, ax
  238. mov cl, [rotation]
  239. call _pointepiece
  240. mov bx, freezebrick
  241. mov [fonction], bx
  242. call boucle4x4
  243. ret
  244.  
  245. effaceligne:
  246. sst2:
  247. dec bx
  248. sub si, 43
  249. mov cx, 11
  250. sst0:
  251. lodsb
  252. mov [ds:si+31], al
  253. loop sst0
  254. test bx, bx
  255. jnz sst2
  256. mov bx, 19
  257. ret
  258.  
  259. mul32:
  260. xor ax, ax
  261. xor bx, bx
  262. mov bl, dh ;bl =x
  263. mov al, dl ;al =y
  264. shl ax, 5 ;ax =y*32
  265. add ax, bx ;ax= y*32+x
  266. add ax, 0x2000
  267. ret
  268.  
  269. freezebrick:
  270. pusha
  271. call mul32
  272. mov di, ax
  273. mov al, [piece]
  274. inc al
  275. stosb
  276. popa
  277. ret
  278.  
  279. _pointepiece:
  280. xor ax, ax
  281. mov [collision],al
  282. mov al, [piece] ; n° de la piece (0-6)
  283. shl al, 1
  284. mov bx, pieces
  285. add bx, ax
  286. mov ax, 14
  287. mul cl
  288. add bx, ax
  289. mov ax, [bx]
  290. ret
  291.  
  292. boucle4x4:
  293. mov bl, 4
  294. dc_:
  295. mov bh, 4
  296. cc_:
  297. test ax, 1
  298. jz videc_
  299. call [fonction]
  300. videc_:
  301. shr ax, 1
  302. inc dh
  303. dec bh
  304. jnz cc_
  305. sub dh, 4
  306. inc dl
  307. dec bl
  308. jnz dc_
  309. sub dl, 4
  310. ret
  311.  
  312. testCol:
  313. call _pointepiece
  314. mov bx, testBrick
  315. mov [fonction], bx
  316. call boucle4x4
  317. ret
  318.  
  319. testBrick:
  320. pusha
  321. call mul32
  322. mov si, ax
  323. lodsb
  324. test al, al
  325. jz okt
  326. mov al, 1
  327. mov [collision],al
  328. okt:
  329. popa
  330. ret
  331.  
  332. ;parcours des 4x4 briques de la piece
  333. affOuEff:
  334. mov [opaque], al
  335. call _loadvars
  336. call _pointepiece
  337. mov bx, affBrick2
  338. mov [fonction], bx
  339. call boucle4x4
  340. call _loadvars
  341. ret
  342.  
  343. affBrick2:
  344. pusha
  345.  
  346. mov cx,dx
  347. xor ax,ax
  348. mov al,cl
  349. mov bx,320
  350. mul bx
  351. xor bx,bx
  352. mov bl,ch
  353. add ax,bx
  354. mov bx,10
  355. mul bx
  356. mov di,ax ;di = 10*(320y+x)
  357.  
  358. mov al,[piece] ; N° piece (0..6)
  359. mov bl,3
  360. mul bl
  361. inc al ; al = 3n + 1 -> couleur de base
  362.  
  363. mov ah,[opaque]
  364. test ah,ah
  365. jz o0
  366. xor al,al ; couleur à 0 pour effacer
  367.  
  368. o0:
  369. mov bl,10
  370. back:
  371. mov cx,10
  372. rep stosb ; carré de 10x10 couleur n°1
  373. add di,310
  374. dec bl
  375. jnz back
  376.  
  377. test ah,ah
  378. jnz o1
  379.  
  380. inc al
  381. sub di,319
  382. mov bx,9
  383. back1:
  384. mov cx,bx
  385. rep stosb ; triangle de 10x10 couleur n°2
  386. sub di,319
  387. sub di,bx
  388. dec bx
  389. jnz back1
  390. mov bl,10
  391.  
  392. inc al
  393. add di,2*320 -8
  394. mov bl,6
  395. mov dx,6
  396. back2:
  397. mov cx,dx
  398. rep stosb ; carré de 6x6 couleur n°3
  399. add di,320
  400. sub di,dx
  401. dec bl
  402. jnz back2
  403.  
  404. o1:
  405. popa
  406. ret
  407.  
  408.  
  409. palette:
  410. mov bh, 1
  411. mov si, 3
  412. r:
  413. call test0
  414. shl bh, 1
  415. dec si
  416. jnz r
  417. ret
  418.  
  419. test0:
  420. test bl, bh
  421. jz next2
  422. out dx, al
  423. jmp n2
  424. next2:
  425. xchg al, ah
  426. out dx, al
  427. xchg al, ah
  428. n2:
  429. ret
  430.  
  431.  
  432.  
  433. vitesse:
  434. db 18
  435. fonction:
  436. dw 0
  437. rotation:
  438. db 0
  439. collision:
  440. db 0
  441. opaque:
  442. db 0
  443. piece:
  444. db 0
  445. time:
  446. dw 0
  447. x:
  448. db 13
  449. y:
  450. db 0
  451. pieces:
  452. dw 0x4444
  453. dw 0x4640
  454. dw 0x0660
  455. dw 0x2640
  456. dw 0x4620
  457. dw 0x6440
  458. dw 0x6220
  459.  
  460. dw 0x0f00
  461. dw 0x0e40
  462. dw 0x0660
  463. dw 0x0c60
  464. dw 0x06c0
  465. dw 0x0e20
  466. dw 0x02e0
  467.  
  468. dw 0x4444
  469. dw 0x4c40
  470. dw 0x0660
  471. dw 0x2640
  472. dw 0x4620
  473. dw 0x44c0
  474. dw 0x4460
  475.  
  476. dw 0x0f00
  477. dw 0x4e00
  478. dw 0x0660
  479. dw 0x0c60
  480. dw 0x06c0
  481. dw 0x08e0
  482. dw 0x0e80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement