Advertisement
Guest User

Untitled

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