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, 15, 4, 4, 4, 4
- db 0, 0, 0, 4, 15,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
- empty equ 0
- white equ 15
- red equ 4
- currturn db white
- mousepressed db 0
- ;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 - white const for white, red const for red
- ; 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], empty
- je cancel_u
- jmp succ_u
- ;and then like "jmp con"
- con_u: ;if (board[i]==empty) { goto cancel; } if (up(board, i, cl,)!=1) {goto
- cmp [byte ptr bx+si], empty
- 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 - white const for white, red const for red
- ; 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], empty
- je cancel_d
- jmp succ_d
- ;and then like "jmp con"
- con_d: ;if (board[i]==empty) { goto cancel; } if (up(board, i, cl,)!=1) {goto
- cmp [byte ptr bx+si], empty
- 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 - white const for white, red const for red
- ; 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], empty
- je cancel_r
- jmp succ_r
- ;and then like "jmp con"
- con_r: ;if (board[i]==empty) { goto cancel; } if (up(board, i, cl,)!=1) {goto
- cmp [byte ptr bx+si], empty
- 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 - white const for white, red const for red
- ; 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], empty
- je cancel_l
- jmp succ_l
- ;and then like "jmp con"
- con_l: ;if (board[i]==empty) { goto cancel; } if (up(board, i, cl,)!=1) {goto
- cmp [byte ptr bx+si], empty
- 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 - white const for white, red const for red
- ; dx - return value. 1 for success in that path and 0 for all paths lead to nothing
- push ax
- xor ax, 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)
- mov dx, 0
- pop ax
- ret
- endp doturn
- proc drawpiece
- ;al - color
- ;cx - starting x coord
- ;dx - starting y coord
- push bx
- push ax
- push di
- push dx
- push si
- push cx
- add cx, 6
- add dx, 6
- mov ah, 0Ch
- xor si, si
- xor di, di
- dpflp: ;draw pieces function loop
- int 10h
- inc si
- add cx, 1
- cmp si, 13
- jb dpflp
- pop cx
- push cx
- add cx, 6
- xor si, si
- inc di
- inc dx
- cmp di, 13
- jb dpflp
- pop cx
- pop si
- pop dx
- pop di
- pop ax
- pop bx
- ret
- endp drawpiece
- start:
- mov ax, @data
- mov ds, ax
- ;Let's start coding!
- mov ax, 13h
- int 10h
- mov ax, 0
- int 33h
- ;draw tiles
- 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
- ;end draw tiles
- 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
- call drawpiece
- 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
- jne changemousepressed
- cmp [mousepressed], 1
- je endmousehandle
- mov [mousepressed], 1
- ;because cx comes in range 0-639
- shr cx, 1
- cmp cx, 120
- jb exit
- sub cx, 120
- add cx, 1
- add dx, 1
- ;si = (cx/25)
- mov ax, cx
- mov bl, 25
- div bl
- xor ah, ah
- mov si, ax
- ;ax = (dx/25)
- mov ax, dx
- div bl ; bl = 25
- ;ax = al * 8
- mov bl, 8
- mul bl
- add si, ax
- mov bx, offset board
- cmp [byte ptr bx+si], empty
- jne endmousehandle
- mov cl, [currturn]
- call doturn
- cmp dx, 1
- jne endmousehandle
- cmp [currturn], white
- je changetored
- mov [currturn], white
- jmp endmousehandle
- changetored:
- mov [currturn], red
- jmp endmousehandle
- changemousepressed:
- mov [mousepressed], 0
- endmousehandle:
- ;---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