Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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,1,2,0,0,0
  9.           db 0,0,0,2,1,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. ; 0 - Nothing
  15. ; 1 - White
  16. ; 2 - Red
  17.  
  18.     currturn db 1
  19.     immediate db ? ; used when the situation is getting fucking intense. DON'T ATTEMPT THIS AT HOME, KIDS
  20.    
  21.    
  22. ;TODO:
  23. ;don't let the player play a turn on a block that already exists
  24.    
  25. CODESEG
  26.  
  27. proc up
  28. ;params
  29. ;   bx - Pointer to board
  30. ;   si - Offset of point where the turn is
  31. ;   cl - 1 for white, 2 for red (for convenience)
  32. ;   dx - return value. 1 for success in that path and 0 for this path leads to nothing
  33.    
  34.     ;certify that there is an upper square on the board if there is not, jmp cancel
  35.     cmp si, 7 ;8-1
  36.     jnae cancel_u
  37.    
  38.     sub si, 8
  39.    
  40.     cmp [byte ptr bx+si], cl
  41.     jne con_u
  42.    
  43.     cmp [byte ptr bx+si+8], cl
  44.     je cancel_u
  45.     cmp [byte ptr bx+si+8], 0
  46.     je cancel_u
  47.     jmp succ_u
  48.    
  49.     ;and then like "jmp con"
  50.    
  51. con_u:  ;if (board[i]==0) { goto cancel; } if (up(board, i, cl,)!=1) {goto
  52.     cmp [byte ptr bx+si], 0
  53.     je cancel_u
  54.    
  55.     push si
  56.     call up
  57.     pop si
  58.     cmp dx, 1
  59.     je succ_u
  60.    
  61.     ;jmp cancel
  62.    
  63. cancel_u:
  64.     xor dx, dx
  65.     ret
  66.    
  67. succ_u:
  68.     add si, 8
  69.     mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
  70.     mov dx, 1
  71.    
  72.     ret
  73. endp up
  74.  
  75.  
  76. proc down
  77. ;params
  78. ;   bx - Pointer to board
  79. ;   si - Offset of point where the turn is
  80. ;   cl - 1 for white, 2 for red (for convenience)
  81. ;   dx - return value. 1 for success in that path and 0 for this path leads to nothing
  82.    
  83.     ;certify that there is an lower square on the board if there is not, jmp cancel
  84.     cmp si, 56 ;8 * 7 - 1
  85.     jnbe cancel_d
  86.    
  87.     add si, 8
  88.    
  89.     cmp [byte ptr bx+si], cl
  90.     jne con_d
  91.    
  92.     cmp [byte ptr bx+si-8], cl
  93.     je cancel_d
  94.     cmp [byte ptr bx+si-8], 0
  95.     je cancel_d
  96.     jmp succ_d
  97.    
  98.     ;and then like "jmp con"
  99.    
  100. con_d:  ;if (board[i]==0) { goto cancel; } if (up(board, i, cl,)!=1) {goto
  101.     cmp [byte ptr bx+si], 0
  102.     je cancel_d
  103.    
  104.     push si
  105.     call down
  106.     pop si
  107.     cmp dx, 1
  108.     je succ_d
  109.    
  110.     ;jmp cancel
  111.    
  112. cancel_d:
  113.     xor dx, dx
  114.     ret
  115.    
  116. succ_d:
  117.     sub si, 8
  118.     mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
  119.     mov dx, 1
  120.    
  121.     ret
  122. endp down
  123.  
  124. proc right
  125. ;params
  126. ;   bx - Pointer to board
  127. ;   si - Offset of point where the turn is
  128. ;   cl - 1 for white, 2 for red (for convenience)
  129. ;   dx - return value. 1 for success in that path and 0 for this path leads to nothing
  130.    
  131.     ;certify that there is a square to the right on the board if there is not, jmp cancel
  132.     ;if (si%8 == 7) {goto cancel;}
  133.     push ax
  134.     push cx
  135.     mov ax, si
  136.     mov ch, 8
  137.     div cx
  138.     pop cx
  139.     cmp ah, 7 ; si % 8
  140.     je cancel_r
  141.    
  142.     add si, 1
  143.    
  144.     cmp [byte ptr bx+si], cl
  145.     jne con_r
  146.    
  147.     cmp [byte ptr bx+si-1], cl
  148.     je cancel_r
  149.     cmp [byte ptr bx+si-1], 0
  150.     je cancel_r
  151.     jmp succ_r
  152.    
  153.     ;and then like "jmp con"
  154.    
  155. con_r:  ;if (board[i]==0) { goto cancel; } if (up(board, i, cl,)!=1) {goto
  156.     cmp [byte ptr bx+si], 0
  157.     je cancel_r
  158.    
  159.     push si
  160.     call right
  161.     pop si
  162.     cmp dx, 1
  163.     je succ_r
  164.    
  165.     ;jmp cancel
  166.    
  167. cancel_r:
  168.     xor dx, dx
  169.     pop ax ; from certifying that si%8!=7
  170.     ret
  171.    
  172. succ_r:
  173.     sub si, 1
  174.     mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
  175.     mov dx, 1
  176.    
  177.    
  178.     pop ax ; from certifying that si%8!=7
  179.     ret
  180. endp right
  181.  
  182. proc left
  183. ;params
  184. ;   bx - Pointer to board
  185. ;   si - Offset of point where the turn is
  186. ;   cl - 1 for white, 2 for red (for convenience)
  187. ;   dx - return value. 1 for success in that path and 0 for this path leads to nothing
  188.    
  189.     ;certify that there is a square to the left on the board if there is not, jmp cancel
  190.     ;if (si%8 == 1) {goto cancel;}
  191.     push ax
  192.     push cx
  193.     mov ax, si
  194.     mov ch, 8
  195.     div cx
  196.     pop cx
  197.     cmp ah, 1 ; si % 8
  198.     je cancel_l
  199.    
  200.     sub si, 1
  201.    
  202.     cmp [byte ptr bx+si], cl
  203.     jne con_l
  204.    
  205.     cmp [byte ptr bx+si+1], cl
  206.     je cancel_l
  207.     cmp [byte ptr bx+si+1], 0
  208.     je cancel_l
  209.     jmp succ_l
  210.    
  211.     ;and then like "jmp con"
  212.    
  213. con_l:  ;if (board[i]==0) { goto cancel; } if (up(board, i, cl,)!=1) {goto
  214.     cmp [byte ptr bx+si], 0
  215.     je cancel_l
  216.    
  217.     push si
  218.     call left
  219.     pop si
  220.     cmp dx, 1
  221.     je succ_l
  222.    
  223.     ;jmp cancel
  224.    
  225. cancel_l:
  226.     xor dx, dx
  227.     pop ax ; from certifying that si%8!=1
  228.     ret
  229.    
  230. succ_l:
  231.     add si, 1
  232.     mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
  233.     mov dx, 1
  234.    
  235.    
  236.     pop ax ; from certifying that si%8!=1
  237.     ret
  238. endp left
  239.  
  240. proc doturn
  241. ;params
  242. ;   bx - Pointer to board
  243. ;   si - Offset of point where the turn is
  244. ;   cl - 1 for white, 2 for red (for convenience)
  245. ;   dx - return value. 1 for success in that path and 0 for all paths lead to nothing
  246.  
  247.     push ax
  248.    
  249.     push si
  250.     call up
  251.     pop si
  252.     add ax ,dx
  253.    
  254.     push si
  255.     call down
  256.     pop si
  257.     add ax, dx
  258.    
  259.     push si
  260.     call right
  261.     pop si
  262.     add ax, dx
  263.    
  264.     push si
  265.     call left
  266.     pop si
  267.     add ax, dx
  268.    
  269.     cmp ax, 0
  270.     je fail
  271.    
  272.     ;succeeded
  273.    
  274.     mov dx, 1
  275.     pop ax
  276.     ret
  277.    
  278. fail:
  279.     ;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)
  280.     pop ax
  281.     ret
  282. endp doturn
  283.  
  284. start:
  285.     mov ax, @data
  286.     mov ds, ax
  287.    
  288.     ;Let's start coding!
  289.    
  290.     mov ax, 13h
  291.     int 10h
  292.    
  293.     mov ax, 0
  294.     int 33h
  295.  
  296. drawtiles:
  297.     mov cx, 120
  298.     xor dx, dx
  299.     xor bl, bl
  300.     mov ax, 0C19h
  301.  
  302. drawthlp:
  303.    
  304.     hlp1: ;horizontal loop 1
  305.     int 10h
  306.     inc cx
  307.     cmp cx, 320
  308.     jb hlp1
  309.    
  310.     mov cx, 120
  311.     add dx, 24
  312.    
  313. hlp2: ;horizontal loop 2
  314.     int 10h
  315.     inc cx
  316.     cmp cx, 320
  317.     jb hlp2
  318.    
  319.     inc dx
  320.     mov cx, 120
  321.     cmp dx, 200
  322.     jb drawthlp
  323.    
  324.     mov cx, 120
  325.     xor dx, dx
  326.    
  327. drawtvlp:
  328.    
  329. vlp1: ;vertical loop 1
  330.     int 10h
  331.     inc dx
  332.     cmp dx, 200
  333.     jb vlp1
  334.    
  335.     xor dx, dx
  336.     add cx, 24
  337.    
  338. vlp2: ;vertical loop 2
  339.     int 10h
  340.     inc dx
  341.     cmp dx, 200
  342.     jb vlp2
  343.    
  344.     inc cx
  345.     xor dx, dx
  346.     cmp cx, 320
  347.     jb drawtvlp
  348.    
  349. gameloop:
  350.  
  351. ;---draw pieces
  352. drawpieces:
  353.     xor si, si
  354.     xor dx, dx
  355.     mov cx, 120
  356.     mov ah, 0Ch
  357.    
  358. dplp: ; draw pieces loop
  359.     mov bx, offset board
  360.     mov al, [bx+si]
  361.     xor bl, bl
  362.     int 10h
  363.    
  364.     add cx, 25
  365.     inc si
  366.    
  367.     cmp cx, 320
  368.     jb dplp
  369.    
  370.     mov cx, 120
  371.     add dx, 25
  372.     cmp si, 3Fh
  373.     jb dplp
  374. ;---end draw pieces
  375.  
  376. ;---handle mouse
  377. handlemouse:
  378.     mov ax, 3
  379.     int 33h
  380.    
  381.     cmp bx, 1
  382.    
  383. ;---end handle mouse
  384.  
  385. drawmouse:
  386.     ;drawing the mouse after everything because it doesn't draw stuff under the mouse
  387.     mov ax, 1
  388.     int 33h
  389.  
  390.     jmp gameloop
  391.    
  392.    
  393. exit:
  394.     mov ax, 4c00h
  395.     int 21h
  396. END start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement