Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.72 KB | None | 0 0
  1. IDEAL
  2. MODEL small
  3. STACK 100h
  4. DATASEG
  5. board db 0, 0, 0, 0, 0, 0, 0, 0
  6. db 0, 0, 0, 0, 0, 0, 0, 0
  7. db 0, 0, 0, 0, 0, 0, 0, 0
  8. db 0, 0, 0, 15, 4, 4, 4, 4
  9. db 0, 0, 0, 4, 15,0, 0, 0
  10. db 0, 0, 0, 0, 0, 0, 0, 0
  11. db 0, 0, 0, 0, 0, 0, 0, 0
  12. db 0, 0, 0, 0, 0, 0, 0, 0
  13.  
  14.  
  15. empty equ 0
  16. white equ 15
  17. red equ 4
  18.  
  19. currturn db white
  20. mousepressed db 0
  21.  
  22.  
  23. ;TODO:
  24. ;don't let the player play a turn on a block that already exists
  25.  
  26. CODESEG
  27.  
  28. proc up
  29. ;params
  30. ; bx - Pointer to board
  31. ; si - Offset of point where the turn is
  32. ; cl - white const for white, red const for red
  33. ; dx - return value. 1 for success in that path and 0 for this path leads to nothing
  34.  
  35. ;certify that there is an upper square on the board if there is not, jmp cancel
  36. cmp si, 7 ;8-1
  37. jnae cancel_u
  38.  
  39. sub si, 8
  40.  
  41. cmp [byte ptr bx+si], cl
  42. jne con_u
  43.  
  44. cmp [byte ptr bx+si+8], cl
  45. je cancel_u
  46. cmp [byte ptr bx+si+8], empty
  47. je cancel_u
  48. jmp succ_u
  49.  
  50. ;and then like "jmp con"
  51.  
  52. con_u: ;if (board[i]==empty) { goto cancel; } if (up(board, i, cl,)!=1) {goto
  53. cmp [byte ptr bx+si], empty
  54. je cancel_u
  55.  
  56. push si
  57. call up
  58. pop si
  59. cmp dx, 1
  60. je succ_u
  61.  
  62. ;jmp cancel
  63.  
  64. cancel_u:
  65. xor dx, dx
  66. ret
  67.  
  68. succ_u:
  69. add si, 8
  70. mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
  71. mov dx, 1
  72.  
  73. ret
  74. endp up
  75.  
  76.  
  77. proc down
  78. ;params
  79. ; bx - Pointer to board
  80. ; si - Offset of point where the turn is
  81. ; cl - white const for white, red const for red
  82. ; dx - return value. 1 for success in that path and 0 for this path leads to nothing
  83.  
  84. ;certify that there is an lower square on the board if there is not, jmp cancel
  85. cmp si, 56 ;8 * 7 - 1
  86. jnbe cancel_d
  87.  
  88. add si, 8
  89.  
  90. cmp [byte ptr bx+si], cl
  91. jne con_d
  92.  
  93. cmp [byte ptr bx+si-8], cl
  94. je cancel_d
  95. cmp [byte ptr bx+si-8], empty
  96. je cancel_d
  97. jmp succ_d
  98.  
  99. ;and then like "jmp con"
  100.  
  101. con_d: ;if (board[i]==empty) { goto cancel; } if (up(board, i, cl,)!=1) {goto
  102. cmp [byte ptr bx+si], empty
  103. je cancel_d
  104.  
  105. push si
  106. call down
  107. pop si
  108. cmp dx, 1
  109. je succ_d
  110.  
  111. ;jmp cancel
  112.  
  113. cancel_d:
  114. xor dx, dx
  115. ret
  116.  
  117. succ_d:
  118. sub si, 8
  119. mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
  120. mov dx, 1
  121.  
  122. ret
  123. endp down
  124.  
  125. proc right
  126. ;params
  127. ; bx - Pointer to board
  128. ; si - Offset of point where the turn is
  129. ; cl - white const for white, red const for red
  130. ; dx - return value. 1 for success in that path and 0 for this path leads to nothing
  131.  
  132. ;certify that there is a square to the right on the board if there is not, jmp cancel
  133. ;if (si%8 == 7) {goto cancel;}
  134. push ax
  135. push cx
  136. mov ax, si
  137. mov ch, 8
  138. div cx
  139. pop cx
  140. cmp ah, 7 ; si % 8
  141. je cancel_r
  142.  
  143. add si, 1
  144.  
  145. cmp [byte ptr bx+si], cl
  146. jne con_r
  147.  
  148. cmp [byte ptr bx+si-1], cl
  149. je cancel_r
  150. cmp [byte ptr bx+si-1], empty
  151. je cancel_r
  152. jmp succ_r
  153.  
  154. ;and then like "jmp con"
  155.  
  156. con_r: ;if (board[i]==empty) { goto cancel; } if (up(board, i, cl,)!=1) {goto
  157. cmp [byte ptr bx+si], empty
  158. je cancel_r
  159.  
  160. push si
  161. call right
  162. pop si
  163. cmp dx, 1
  164. je succ_r
  165.  
  166. ;jmp cancel
  167.  
  168. cancel_r:
  169. xor dx, dx
  170. pop ax ; from certifying that si%8!=7
  171. ret
  172.  
  173. succ_r:
  174. sub si, 1
  175. mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
  176. mov dx, 1
  177.  
  178.  
  179. pop ax ; from certifying that si%8!=7
  180. ret
  181. endp right
  182.  
  183. proc left
  184. ;params
  185. ; bx - Pointer to board
  186. ; si - Offset of point where the turn is
  187. ; cl - white const for white, red const for red
  188. ; dx - return value. 1 for success in that path and 0 for this path leads to nothing
  189.  
  190. ;certify that there is a square to the left on the board if there is not, jmp cancel
  191. ;if (si%8 == 1) {goto cancel;}
  192. push ax
  193. push cx
  194. mov ax, si
  195. mov ch, 8
  196. div cx
  197. pop cx
  198. cmp ah, 1 ; si % 8
  199. je cancel_l
  200.  
  201. sub si, 1
  202.  
  203. cmp [byte ptr bx+si], cl
  204. jne con_l
  205.  
  206. cmp [byte ptr bx+si+1], cl
  207. je cancel_l
  208. cmp [byte ptr bx+si+1], empty
  209. je cancel_l
  210. jmp succ_l
  211.  
  212. ;and then like "jmp con"
  213.  
  214. con_l: ;if (board[i]==empty) { goto cancel; } if (up(board, i, cl,)!=1) {goto
  215. cmp [byte ptr bx+si], empty
  216. je cancel_l
  217.  
  218. push si
  219. call left
  220. pop si
  221. cmp dx, 1
  222. je succ_l
  223.  
  224. ;jmp cancel
  225.  
  226. cancel_l:
  227. xor dx, dx
  228. pop ax ; from certifying that si%8!=1
  229. ret
  230.  
  231. succ_l:
  232. add si, 1
  233. mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
  234. mov dx, 1
  235.  
  236.  
  237. pop ax ; from certifying that si%8!=1
  238. ret
  239. endp left
  240.  
  241. proc doturn
  242. ;params
  243. ; bx - Pointer to board
  244. ; si - Offset of point where the turn is
  245. ; cl - white const for white, red const for red
  246. ; dx - return value. 1 for success in that path and 0 for all paths lead to nothing
  247.  
  248. push ax
  249. xor ax, ax
  250.  
  251. push si
  252. call up
  253. pop si
  254. add ax ,dx
  255.  
  256. push si
  257. call down
  258. pop si
  259. add ax, dx
  260.  
  261. push si
  262. call right
  263. pop si
  264. add ax, dx
  265.  
  266. push si
  267. call left
  268. pop si
  269. add ax, dx
  270.  
  271. cmp ax, 0
  272. je fail
  273.  
  274. ;succeeded
  275.  
  276. mov dx, 1
  277. pop ax
  278. ret
  279.  
  280. fail:
  281. ;I technically don't need to set dx to 0 because if the program reached "fail" then the last call to a function returned 0 (dx = 0)
  282. mov dx, 0
  283. pop ax
  284. ret
  285. endp doturn
  286.  
  287. proc drawpiece
  288. ;al - color
  289. ;cx - starting x coord
  290. ;dx - starting y coord
  291.  
  292. push bx
  293. push ax
  294. push di
  295. push dx
  296. push si
  297. push cx
  298.  
  299. add cx, 6
  300. add dx, 6
  301.  
  302. mov ah, 0Ch
  303.  
  304. xor si, si
  305. xor di, di
  306.  
  307. dpflp: ;draw pieces function loop
  308. int 10h
  309. inc si
  310. add cx, 1
  311.  
  312. cmp si, 13
  313. jb dpflp
  314.  
  315. pop cx
  316. push cx
  317. add cx, 6
  318.  
  319. xor si, si
  320.  
  321. inc di
  322. inc dx
  323.  
  324. cmp di, 13
  325. jb dpflp
  326.  
  327.  
  328. pop cx
  329. pop si
  330. pop dx
  331. pop di
  332. pop ax
  333. pop bx
  334.  
  335. ret
  336. endp drawpiece
  337.  
  338. start:
  339. mov ax, @data
  340. mov ds, ax
  341.  
  342. ;Let's start coding!
  343.  
  344. mov ax, 13h
  345. int 10h
  346.  
  347. mov ax, 0
  348. int 33h
  349.  
  350. ;draw tiles
  351. drawtiles:
  352. mov cx, 120
  353. xor dx, dx
  354. xor bl, bl
  355. mov ax, 0C19h
  356.  
  357. drawthlp:
  358.  
  359. hlp1: ;horizontal loop 1
  360. int 10h
  361. inc cx
  362. cmp cx, 320
  363. jb hlp1
  364.  
  365. mov cx, 120
  366. add dx, 24
  367.  
  368. hlp2: ;horizontal loop 2
  369. int 10h
  370. inc cx
  371. cmp cx, 320
  372. jb hlp2
  373.  
  374. inc dx
  375. mov cx, 120
  376. cmp dx, 200
  377. jb drawthlp
  378.  
  379. mov cx, 120
  380. xor dx, dx
  381.  
  382. drawtvlp:
  383.  
  384. vlp1: ;vertical loop 1
  385. int 10h
  386. inc dx
  387. cmp dx, 200
  388. jb vlp1
  389.  
  390. xor dx, dx
  391. add cx, 24
  392.  
  393. vlp2: ;vertical loop 2
  394. int 10h
  395. inc dx
  396. cmp dx, 200
  397. jb vlp2
  398.  
  399. inc cx
  400. xor dx, dx
  401. cmp cx, 320
  402. jb drawtvlp
  403. ;end draw tiles
  404.  
  405. gameloop:
  406.  
  407. ;---draw pieces
  408. drawpieces:
  409. xor si, si
  410. xor dx, dx
  411. mov cx, 120
  412. mov ah, 0Ch
  413.  
  414. dplp: ;draw pieces loop
  415.  
  416. mov bx, offset board
  417.  
  418. mov al, [bx+si]
  419. xor bl, bl
  420. call drawpiece
  421.  
  422. add cx, 25
  423. inc si
  424.  
  425. cmp cx, 320
  426. jb dplp
  427.  
  428. mov cx, 120
  429. add dx, 25
  430. cmp si, 3Fh
  431. jb dplp
  432. ;---end draw pieces
  433.  
  434.  
  435. ;---handle mouse
  436. handlemouse:
  437. mov ax, 3
  438. int 33h
  439.  
  440. cmp bx, 1
  441. jne changemousepressed
  442.  
  443. cmp [mousepressed], 1
  444. je endmousehandle
  445.  
  446. mov [mousepressed], 1
  447.  
  448. ;because cx comes in range 0-639
  449. shr cx, 1
  450.  
  451. cmp cx, 120
  452. jb exit
  453.  
  454. sub cx, 120
  455.  
  456. add cx, 1
  457. add dx, 1
  458.  
  459. ;si = (cx/25)
  460. mov ax, cx
  461. mov bl, 25
  462. div bl
  463. xor ah, ah
  464. mov si, ax
  465.  
  466. ;ax = (dx/25)
  467. mov ax, dx
  468. div bl ; bl = 25
  469.  
  470. ;ax = al * 8
  471. mov bl, 8
  472. mul bl
  473.  
  474. add si, ax
  475.  
  476. mov bx, offset board
  477.  
  478. cmp [byte ptr bx+si], empty
  479. jne endmousehandle
  480.  
  481. mov cl, [currturn]
  482.  
  483. call doturn
  484. cmp dx, 1
  485. jne endmousehandle
  486.  
  487. cmp [currturn], white
  488. je changetored
  489.  
  490. mov [currturn], white
  491. jmp endmousehandle
  492.  
  493. changetored:
  494. mov [currturn], red
  495. jmp endmousehandle
  496.  
  497. changemousepressed:
  498. mov [mousepressed], 0
  499.  
  500. endmousehandle:
  501. ;---end handle mouse
  502.  
  503. drawmouse:
  504. ;drawing the mouse after everything because it doesn't draw stuff under the mouse
  505. mov ax, 1
  506. int 33h
  507.  
  508. jmp gameloop
  509.  
  510. exit:
  511. mov ax, 4c00h
  512. int 21h
  513. END start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement