Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IDEAL
- MODEL small
- STACK 100h
- DATASEG
- board db 0,0,0,0,0,0,0,0
- db 0,0,0,0,0,0,0,0
- db 0,0,0,0,0,0,0,0
- db 0,0,0,1,2,0,0,0
- db 0,0,0,2,1,0,0,0
- db 0,0,0,0,0,0,0,0
- db 0,0,0,0,0,0,0,0
- db 0,0,0,0,0,0,0,0
- ; 0 - Nothing
- ; 1 - White
- ; 2 - Red
- currturn db 1
- immediate db ? ; used when the situation is getting fucking intense. DON'T ATTEMPT THIS AT HOME, KIDS
- ;TODO:
- ;don't let the player play a turn on a block that already exists
- CODESEG
- proc up
- ;params
- ; bx - Pointer to board
- ; si - Offset of point where the turn is
- ; cl - 1 for white, 2 for red (for convenience)
- ; dx - return value. 1 for success in that path and 0 for this path leads to nothing
- ;certify that there is an upper square on the board if there is not, jmp cancel
- cmp si, 7 ;8-1
- jnae cancel_u
- sub si, 8
- cmp [byte ptr bx+si], cl
- jne con_u
- cmp [byte ptr bx+si+8], cl
- je cancel_u
- cmp [byte ptr bx+si+8], 0
- je cancel_u
- jmp succ_u
- ;and then like "jmp con"
- con_u: ;if (board[i]==0) { goto cancel; } if (up(board, i, cl,)!=1) {goto
- cmp [byte ptr bx+si], 0
- je cancel_u
- push si
- call up
- pop si
- cmp dx, 1
- je succ_u
- ;jmp cancel
- cancel_u:
- xor dx, dx
- ret
- succ_u:
- add si, 8
- mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
- mov dx, 1
- ret
- endp up
- proc down
- ;params
- ; bx - Pointer to board
- ; si - Offset of point where the turn is
- ; cl - 1 for white, 2 for red (for convenience)
- ; dx - return value. 1 for success in that path and 0 for this path leads to nothing
- ;certify that there is an lower square on the board if there is not, jmp cancel
- cmp si, 56 ;8 * 7 - 1
- jnbe cancel_d
- add si, 8
- cmp [byte ptr bx+si], cl
- jne con_d
- cmp [byte ptr bx+si-8], cl
- je cancel_d
- cmp [byte ptr bx+si-8], 0
- je cancel_d
- jmp succ_d
- ;and then like "jmp con"
- con_d: ;if (board[i]==0) { goto cancel; } if (up(board, i, cl,)!=1) {goto
- cmp [byte ptr bx+si], 0
- je cancel_d
- push si
- call down
- pop si
- cmp dx, 1
- je succ_d
- ;jmp cancel
- cancel_d:
- xor dx, dx
- ret
- succ_d:
- sub si, 8
- mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
- mov dx, 1
- ret
- endp down
- proc right
- ;params
- ; bx - Pointer to board
- ; si - Offset of point where the turn is
- ; cl - 1 for white, 2 for red (for convenience)
- ; dx - return value. 1 for success in that path and 0 for this path leads to nothing
- ;certify that there is a square to the right on the board if there is not, jmp cancel
- ;if (si%8 == 7) {goto cancel;}
- push ax
- push cx
- mov ax, si
- mov ch, 8
- div cx
- pop cx
- cmp ah, 7 ; si % 8
- je cancel_r
- add si, 1
- cmp [byte ptr bx+si], cl
- jne con_r
- cmp [byte ptr bx+si-1], cl
- je cancel_r
- cmp [byte ptr bx+si-1], 0
- je cancel_r
- jmp succ_r
- ;and then like "jmp con"
- con_r: ;if (board[i]==0) { goto cancel; } if (up(board, i, cl,)!=1) {goto
- cmp [byte ptr bx+si], 0
- je cancel_r
- push si
- call right
- pop si
- cmp dx, 1
- je succ_r
- ;jmp cancel
- cancel_r:
- xor dx, dx
- pop ax ; from certifying that si%8!=7
- ret
- succ_r:
- sub si, 1
- mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
- mov dx, 1
- pop ax ; from certifying that si%8!=7
- ret
- endp right
- proc left
- ;params
- ; bx - Pointer to board
- ; si - Offset of point where the turn is
- ; cl - 1 for white, 2 for red (for convenience)
- ; dx - return value. 1 for success in that path and 0 for this path leads to nothing
- ;certify that there is a square to the left on the board if there is not, jmp cancel
- ;if (si%8 == 1) {goto cancel;}
- push ax
- push cx
- mov ax, si
- mov ch, 8
- div cx
- pop cx
- cmp ah, 1 ; si % 8
- je cancel_l
- sub si, 1
- cmp [byte ptr bx+si], cl
- jne con_l
- cmp [byte ptr bx+si+1], cl
- je cancel_l
- cmp [byte ptr bx+si+1], 0
- je cancel_l
- jmp succ_l
- ;and then like "jmp con"
- con_l: ;if (board[i]==0) { goto cancel; } if (up(board, i, cl,)!=1) {goto
- cmp [byte ptr bx+si], 0
- je cancel_l
- push si
- call left
- pop si
- cmp dx, 1
- je succ_l
- ;jmp cancel
- cancel_l:
- xor dx, dx
- pop ax ; from certifying that si%8!=1
- ret
- succ_l:
- add si, 1
- mov [bx+si], cl ;may change to add to a queue of turns for animation (but no one uses animation in assembly)
- mov dx, 1
- pop ax ; from certifying that si%8!=1
- ret
- endp left
- proc doturn
- ;params
- ; bx - Pointer to board
- ; si - Offset of point where the turn is
- ; cl - 1 for white, 2 for red (for convenience)
- ; dx - return value. 1 for success in that path and 0 for all paths lead to nothing
- push ax
- push si
- call up
- pop si
- add ax ,dx
- push si
- call down
- pop si
- add ax, dx
- push si
- call right
- pop si
- add ax, dx
- push si
- call left
- pop si
- add ax, dx
- cmp ax, 0
- je fail
- ;succeeded
- mov dx, 1
- pop ax
- ret
- fail:
- ;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)
- pop ax
- ret
- endp doturn
- start:
- mov ax, @data
- mov ds, ax
- ;Let's start coding!
- mov ax, 13h
- int 10h
- mov ax, 0
- int 33h
- drawtiles:
- mov cx, 120
- xor dx, dx
- xor bl, bl
- mov ax, 0C19h
- drawthlp:
- hlp1: ;horizontal loop 1
- int 10h
- inc cx
- cmp cx, 320
- jb hlp1
- mov cx, 120
- add dx, 24
- hlp2: ;horizontal loop 2
- int 10h
- inc cx
- cmp cx, 320
- jb hlp2
- inc dx
- mov cx, 120
- cmp dx, 200
- jb drawthlp
- mov cx, 120
- xor dx, dx
- drawtvlp:
- vlp1: ;vertical loop 1
- int 10h
- inc dx
- cmp dx, 200
- jb vlp1
- xor dx, dx
- add cx, 24
- vlp2: ;vertical loop 2
- int 10h
- inc dx
- cmp dx, 200
- jb vlp2
- inc cx
- xor dx, dx
- cmp cx, 320
- jb drawtvlp
- gameloop:
- ;---draw pieces
- drawpieces:
- xor si, si
- xor dx, dx
- mov cx, 120
- mov ah, 0Ch
- dplp: ; draw pieces loop
- mov bx, offset board
- mov al, [bx+si]
- xor bl, bl
- int 10h
- add cx, 25
- inc si
- cmp cx, 320
- jb dplp
- mov cx, 120
- add dx, 25
- cmp si, 3Fh
- jb dplp
- ;---end draw pieces
- ;---handle mouse
- handlemouse:
- mov ax, 3
- int 33h
- cmp bx, 1
- ;---end handle mouse
- drawmouse:
- ;drawing the mouse after everything because it doesn't draw stuff under the mouse
- mov ax, 1
- int 33h
- jmp gameloop
- exit:
- mov ax, 4c00h
- int 21h
- END start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement