.EQU SWITCHES = 0x20 ;; inputs = switches. interrupt button determines when to check which switch is up .EQU RESET = 0x0C ;; reset key .EQU VGA_HADD = 0x90 ; VGA display input .EQU VGA_LADD = 0x91 ; VGA display input .EQU VGA_COLOR = 0x92; VGA display input .CSEG .ORG 0x01 ;R0 = turn, p1 =1, p2 =2 ;r1 = hex value for which column ;r2 = match counter ;r3 = column moves ; r4 = memory location ; r5 = memory location for iteration thru whole board ; r6 = current value of memory location ; r7 = memory location #2 ; r8 = value loaded from memory location #2 ; r9 = copy of current memory location - horizontal ; r10 = copy of current memory location - vertical ; r11= copy of current memory location - diagonal1 ; r12= copy of current memory location - diagonal2 ; r13= column moves #2 ; r14 = column moves #3 ; r15 = column moves #4 ; r16 = column moves #5 ; r17 = column moves #6 ; r18 = column moves #7 ; r19 = move counter ; r28 = x coordinate ; r27 = y-coordinate ; r26 = VGA color ; 7x6 board main: SEI ;; set interrupt flag so that MCU can process received interrupts (triggered when MOV R0, 0x00 ; initialize turn register clearscratch: ; iterate through all scratch memory and clearing to all 0's to properly reset MOV R1, 0x00 ST R1, (R0) ADD R0, 0x01 CMP R0,0xFF BRNE clearscratch ; reset all registers to zero for proper reset MOV R0, 0x00; r0 = player's turn; 1 = P1, 2 = P2 MOV R1, 0x00; register for key values MOV R4, 0x00 ; register for memory location column MOV R6, 0x00 MOV R8, 0x00 MOV R9, 0x00 MOV R10, 0x00 MOV R11, 0x00 MOV R12, 0x00 MOV R3, 0x23 ; bottom of board (column 1) - decimal 35 MOV R13, 0x24 ;;bottom of board (column 2) - decimal 36 MOV R14, 0x25 ;bottom of board (column 3) - decimal 37 MOV R15, 0x26 ;;bottom of board (column 4) - decimal 38 MOV R16, 0x27 ;bottom of board (column 5) - decimal 39 MOV R17, 0x28 ;bottom of board (column 6) - decimal 40 MOV R18, 0x29 ;bottom of board (column 7) - decimal 41 (bottom right piece) MOV R2, 0x00; match counter (counts how many in a row) horizontal. 0x03 = 4 pieces in a row MOV R5, 0x00 ; memory location to iterate through whole board MOV R7, 0x00 ; memory location of the second value MOV R19, 0x00; move counter MOV R20, 0x00 ;match counter vertical MOV R21, 0x00 MOV R22, 0x00 ;match counter diagonal1 MOV R23, 0x00 MOV R24, 0x00 MOV R25, 0x00 MOV R26, 0x00 MOV R27, 0x05 ; y coordinate MOV R28, 0x00 MOV R29, 0x00 MOV R30, 0x00 ;match counter diagonal2 MOV R31, 0x00 drawboard: ; draws board on VGA display CALL draw_background ; colors the whole screen black MOV R29, 0x00 MOV R26, 0x03 ; change color to full blue "00000011" MOV R28, 0x04 ; start at top right of board (4,4) y=4 MOV R27, 0x04 ; x=4 drawc1: ; drawc and drawr functions draw blue lines of the actual board ADD R29, 0x01; add one to dot counter ADD R27, 0x01 ; draw dot one above; x coord stays same; y= 28 MOV R24, R27 MOV R25, R28 CALL draw_dot CMP R29, 0x19; see if it has drawn 25 dots (25 rows) BRNE drawc1; should end at y=5 MOV R29, 0x00; reset dot counter MOV R27, 0x05 ; y=4 MOV R28, 0x04 ; x=4 drawr1: ADD R29, 0x01; ADD R28, 0x01; top row of board drawing MOV R24, R27 MOV R25, R28 CALL draw_dot CMP r29, 0x1C; draw the top row (29 columns) BRNE drawr1 MOV R29, 0x00 ;second column, x=8, y=5 MOV R27, 0x05 ; y=5 MOV R28, 0x08 ; x=8 ; add one to y to go down column drawc2: ADD R29, 0x01; add to dot counter ADD R27, 0x01 MOV R24, R27 MOV R25, R28 CALL draw_dot CMP R29, 0x19; make sure it's done 25 times BRNE drawc2 MOV R29, 0x00 ;third column, x=12, y=5 MOV R27, 0x05 ; y=5 MOV R28, 0x0C ; x=12 drawc3: ADD R29, 0x01; add to dot counter ADD R27, 0x01 MOV R24, R27 MOV R25, R28 CALL draw_dot CMP R29, 0x19; make sure it's done 25 times BRNE drawc3 MOV R29, 0x00 ;4th column, x=16, y=5 MOV R27, 0x05 ; y=5 MOV R28, 0x10 ; x=16 drawc4: ADD R29, 0x01; add to dot counter ADD R27, 0x01 MOV R24, R27 MOV R25, R28 CALL draw_dot CMP R29, 0x19; make sure it's done 25 times BRNE drawc4 MOV R29, 0x00 ;5th column, x=20, y=5 MOV R27, 0x05 ; y=5 MOV R28, 0x14 ; x=20 drawc5: ADD R29, 0x01; add to dot counter ADD R27, 0x01 MOV R24, R27 MOV R25, R28 CALL draw_dot CMP R29, 0x19; make sure it's done 25 times BRNE drawc5 MOV R29, 0x00 ;6th column, x=24, y=5 MOV R27, 0x05 ; y=5 MOV R28, 0x18 ; x=24 drawc6: ADD R29, 0x01; add to dot counter ADD R27, 0x01 MOV R24, R27 MOV R25, R28 CALL draw_dot CMP R29, 0x19; make sure it's done 25 times BRNE drawc6 MOV R29, 0x00 ;7th column, x=28, y=5 MOV R27, 0x05 ; y=5 MOV R28, 0x1C ; x=12 drawc7: ADD R29, 0x01; add to dot counter ADD R27, 0x01 MOV R24, R27 MOV R25, R28 CALL draw_dot CMP R29, 0x19; make sure it's done 25 times BRNE drawc7 MOV R29, 0x00 ;last column, x=32, y=5 MOV R27, 0x05 ; y=5 MOV R28, 0x20 ; x=32 drawc8: ADD R29, 0x01; add to dot counter ADD R27, 0x01 MOV R24, R27 MOV R25, R28 CALL draw_dot CMP R29, 0x19; make sure it's done 25 times BRNE drawc8 MOV R29, 0x00 ; 2nd row, x=4, y=9 MOV R27, 0x09 ; y=9 MOV R28, 0x04 ; x=4 drawr2: ADD R29, 0x01; add to dot counter ADD R28, 0x01; add one to x (move to right) MOV R24, R27 MOV R25, R28 CALL draw_dot CMP r29, 0x1C; draw the full row (29 columns) BRNE drawr2 MOV R29, 0x00 ; 3RD row, x=4, y=13 MOV R27, 0x0D ; y=13 MOV R28, 0x04 ; x=4 drawr3: ADD R29, 0x01; ADD R28, 0x01; MOV R24, R27 MOV R25, R28 CALL draw_dot CMP r29, 0x1C; draw the full row (29 columns) BRNE drawr3 MOV R29, 0x00 ; 4TH row, x=4, y=17 MOV R27, 0x11 ; y=17 MOV R28, 0x04 ; x=4 drawr4: ADD R29, 0x01; ADD R28, 0x01; MOV R24, R27 MOV R25, R28 CALL draw_dot CMP r29, 0x1C; draw the full row (29 columns) BRNE drawr4 MOV R29, 0x00 ; 5TH row, x=4, y=21 MOV R27, 0x15 ; y=21 MOV R28, 0x04 ; x=4 drawr5: ADD R29, 0x01; ADD R28, 0x01; MOV R24, R27 MOV R25, R28 CALL draw_dot CMP r29, 0x1C; draw the full row (29 columns) BRNE drawr5 MOV R29, 0x00 ; 6TH row, x=4, y=25 MOV R27, 0x19 ; y=25 MOV R28, 0x04 ; x=4 drawr6: ADD R29, 0x01; ADD R28, 0x01; MOV R24, R27 MOV R25, R28 CALL draw_dot CMP r29, 0x1C; draw the full row (29 columns) BRNE drawr6 MOV R29, 0x00 ; bottom row, x=4, y=29 MOV R27, 0x1D ; y=29 MOV R28, 0x04 ; x=4 drawr7: ADD R29, 0x01; ADD R28, 0x01; MOV R24, R27 MOV R25, R28 CALL draw_dot CMP r29, 0x1C; draw the full row (29 columns) BRNE drawr7 BRN start1 ; -----Player 1 Start ------------------ start1: MOV R0, 0x01 ;; change to player1's turn. default to player1 start MOV R5, 0X00; reset memory location for iteration for next turn/check ADD R19, 0x01; add one to move counter MOV R26, 0xE0 ; P1 = RED MOV R27, 0x0B ; start a t VGA value of bottom left of piece; y=11 MOV R28, 0x22 ; x=34 MOV R24, R27 MOV R25, R28 CALL drawpiece ; draw piece to the right of board to display whose turn it is BRN noop noop: ; wait for button to be pressed to check which switch is up CMP R31, 0xFF; check if "flag" is raised BRNE noop MOV R31, 0X00; clear the "flag" ; check which switch is up to place a chip on board, down a column. CMP R1, 0x80; "10000000" BREQ col1 ; column 1 - far left CMP R1, 0x40; "01000000" BREQ col2 CMP R1, 0x20; "00100000" BREQ col3 CMP R1, 0X10; "00010000" BREQ col4 CMP R1, 0x08; "00001000" BREQ col5 CMP R1, 0x04; "00000100" BREQ col6 CMP R1, 0x02; "00000010" BREQ col7 ; column 7 - far right CMP R1, 0x01; "00000001" - RESET BREQ main; go to main - start over if reset switch is up BRNE error; if none of the cases are true, wait for valid move ; ----------Player 2 Start ---------- start2: ;;player 2's function MOV R0, 0x02 ;; change to player2's turn MOV R5, 0X00; reset memory location for iteration for next turn/check MOV R26, 0xF8 ; P2 = yellow "11111000" MOV R27, 0x0B ; y=11 MOV R28, 0x22; x=34 MOV R24, R27 MOV R25, R28 CALL drawpiece ; draw yellow chip to the right of board to show it's P2's turn BRN noop;; back to waiting to check if the button was pressed error: BRN noop ; if not valid move, waits for valid move. ; depending on key, send information to drop into the correct column. col1: ; put switch up and press button to send to this state CMP R3, 0xf9 ; check if top of column1; compare location to check if column moves = max BREQ error; branch to error subroutine if it's at the top ST R0, (R3) ; store 0x01 or 0x02 into correct chip spot, depdending on whose turn it is (P1 = 0x01, P2 = 0x02) c1r6: ; column 1 row 6 CMP R3, 0x23; compare to each spot in column (decimal 35 - bottom of column 1) BRNE c1r5 ; spot locations start at bottom left of piece drawing. (5, 28) MOV R28, 0x05 ; X=5 MOV R27, 0x1C ; Y=28 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots to create 3x3 piece BRN col1CL c1r5: ; directly above c1r6 CMP R3, 0x1C; BRNE c1r4 MOV R28, 0x05 ; X=5 MOV R27, 0x18 ; Y=24 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col1CL c1r4: CMP R3, 0x15 BRNE c1r3 ; spot locations start at bottom left of piece drawing MOV R28, 0x05 ; X=5 MOV R27, 0x14 ; Y=20 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col1CL c1r3: CMP R3, 0x0E BRNE c1r2 ; spot locations start at bottom left of piece drawing MOV R28, 0x05 ; X=5 MOV R27, 0x10 ; Y=16 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col1CL c1r2: CMP R3, 0x07 BRNE c1r1 ; spot locations start at bottom left of piece drawing MOV R28, 0x05 ; X=5 MOV R27, 0x0C ; Y=12 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col1CL c1r1: ; CMP R3, 0x00 ; implied that if it's none of the above cases, it's the top spot of column (0x00) MOV R28, 0x05 ; X=5 MOV R27, 0x08 ; Y=8 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col1CL col1CL: CALL currentlocation ;; branch to check the whole board for win SUB R3, 0x07 ;subtract 7 off the key value to get to the right memory location (the spot above the spot recently placed.) CMP R0, 0x01 BREQ start2; if r0 = 1 then switch from P1 turn to P2 BRNE start1; if r0 doesn't = 1 then it's 2. so go to P1's turn. ;-------------column 2 col2: CMP R13, 0xFA ;;compare to top column2 piece BREQ error;; branch to error subroutine if it's at the top ST R0, (R13) ;; store 0x01 or 0x02 into correct chip spot, depending on whose turn it is c2r6: CMP R13, 0x24; compare to each spot in column BRNE c2r5 ; spot locations start at bottom left of piece drawing MOV R28, 0x09 ; X=9 MOV R27, 0x1C ; Y=28 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col2CL c2r5: CMP R13, 0x1D; BRNE c2r4 MOV R28, 0x09 ; X=9 MOV R27, 0x18 ; Y=24 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col2CL c2r4: CMP R13, 0x16 BRNE c2r3 ; spot locations start at bottom left of piece drawing MOV R28, 0x09 ; X=9 MOV R27, 0x14 ; Y=20 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col2CL c2r3: CMP R13, 0x0F BRNE c2r2 ; spot locations start at bottom left of piece drawing MOV R28, 0x09 ; X=9 MOV R27, 0x10 ; Y=16 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col2CL c2r2: CMP R13, 0x08 BRNE c2r1 ; spot locations start at bottom left of piece drawing MOV R28, 0x09 ; X=9 MOV R27, 0x0C ; Y=12 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col2CL c2r1: ; CMP R13, 0x01 MOV R28, 0x09 ; X=9 MOV R27, 0x08 ; Y=8 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col2CL col2CL: CALL currentlocation ;; branch to check the whole board for win SUB R13, 0x07 ;subtract 7 off the key value to get to the right memory location (the spot above the spot recently placed.) CMP R0, 0x01 ; check whose turn it is then send to corresponding start screen BREQ start2 BRNE start1 ;------------------------- column 3 col3: CMP R14, 0xFB ;;compare location to top column3 piece BREQ error; branch to error subroutine if it's at the top ST R0, (R14) ; store 0x01 or 0x02 into correct chip spot, depending on whose turn it is c3r6: CMP R14, 0x25; compare to each spot in column BRNE c3r5 ; spot locations start at bottom left of piece drawing MOV R28, 0x0D ; X=13 MOV R27, 0x1C ; Y=28 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col3CL c3r5: CMP R14, 0x1E; BRNE c3r4 MOV R28, 0x0D ; X=13 MOV R27, 0x18 ; Y=24 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col3CL c3r4: CMP R14, 0x17 BRNE c3r3 ; spot locations start at bottom left of piece drawing MOV R28, 0x0D ; X=13 MOV R27, 0x14 ; Y=20 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col3CL c3r3: CMP R14, 0x10 BRNE c3r2 ; spot locations start at bottom left of piece drawing MOV R28, 0x0D ; X=13 MOV R27, 0x10 ; Y=16 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col3CL c3r2: CMP R14, 0x09 BRNE c3r1 ; spot locations start at bottom left of piece drawing MOV R28, 0x0D ; X=13 MOV R27, 0x0C ; Y=12 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col3CL c3r1: ; CMP R14, 0x02 MOV R28, 0x0D ; X=13 MOV R27, 0x08 ; Y=8 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col3CL col3CL: CALL currentlocation ; branch to check the whole board for win SUB R14, 0x07 ; subtract 7 off the key value to get to the right memory location (the spot above the spot recently placed.) CMP R0, 0x01 ; check whose turn it should be next BREQ start2 BRNE start1 ;------------------------column 4 col4: CMP R15, 0xFC ;compare location to top column4 piece BREQ error; branch to error subroutine if it's at the top ST R0, (R15) ; store 0x01 or 0x02 into correct chip spot, depending on whose turn it is c4r6: CMP R15, 0x26; compare to each spot in column BRNE c4r5 ; spot locations start at bottom left of piece drawing MOV R28, 0x11 ; X=17 MOV R27, 0x1C ; Y=28 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col4CL c4r5: CMP R15, 0x1F; BRNE c4r4 MOV R28, 0x11 ; X=17 MOV R27, 0x18 ; Y=24 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col4CL c4r4: CMP R15, 0x18 BRNE c4r3 ; spot locations start at bottom left of piece drawing MOV R28, 0x11 ; X=17 MOV R27, 0x14 ; Y=20 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col4CL c4r3: CMP R15, 0x11 BRNE c4r2 ; spot locations start at bottom left of piece drawing MOV R28, 0x11 ; X=17 MOV R27, 0x10 ; Y=16 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col4CL c4r2: CMP R15, 0x0A BRNE c4r1 ; spot locations start at bottom left of piece drawing MOV R28, 0x11 ; X=17 MOV R27, 0x0C ; Y=12 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col4CL c4r1: ; CMP R15, 0x03 MOV R28, 0x11 ; X=137 MOV R27, 0x08 ; Y=8 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col4CL col4CL: CALL currentlocation ;; branch to check the whole board for win SUB R15, 0x07 ;;subtract 7 off the key value to get to the right memory location (the spot above the spot recently placed.) CMP R0, 0x01 BREQ start2 BRNE start1 ;--------------- column 5 col5: CMP R16, 0xFD ;compare to top column5 piece BREQ error; branch to error subroutine if it's at the top ST R0, (R16) ; store 0x01 or 0x02 into correct chip spot, depending on whose turn it is c5r6: CMP R16, 0x27; compare to each spot in column BRNE c5r5 ; spot locations start at bottom left of piece drawing MOV R28, 0x15 ; X=21 MOV R27, 0x1C ; Y=28 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col5CL c5r5: CMP R16, 0x20; BRNE c5r4 MOV R28, 0x15 ; X=21 MOV R27, 0x18 ; Y=24 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col5CL c5r4: CMP R16, 0x19 BRNE c5r3 ; spot locations start at bottom left of piece drawing MOV R28, 0x15 ; X=21 MOV R27, 0x14 ; Y=20 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col5CL c5r3: CMP R16, 0x12 BRNE c5r2 ; spot locations start at bottom left of piece drawing MOV R28, 0x15 ; X=21 MOV R27, 0x10 ; Y=16 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col5CL c5r2: CMP R16, 0x0B BRNE c5r1 ; spot locations start at bottom left of piece drawing MOV R28, 0x15 ; X=21 MOV R27, 0x0C ; Y=12 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col5CL c5r1: ; CMP R16, 0x04 MOV R28, 0x15 ; X=21 MOV R27, 0x08 ; Y=8 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col5CL col5CL: CALL currentlocation ;; branch to check the whole board for win SUB R16, 0x07 ;;subtract 7 off the key value to get to the right memory location (the spot above the spot recently placed.) CMP R0, 0x01 ; check whose turn it is next BREQ start2 BRNE start1 ;---------------------column 6 col6: CMP R17, 0xFE ;;compare to top column6 piece BREQ error; branch to error subroutine if it's at the top ST R0, (R17) ; store 0x01 or 0x02 into correct chip spot, depending on whose turn it is c6r6: CMP R17, 0x28; compare to each spot in column BRNE c6r5 ; spot locations start at bottom left of piece drawing MOV R28, 0x19 ; X=25 MOV R27, 0x1C ; Y=28 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col6CL c6r5: CMP R17, 0x21; BRNE c6r4 MOV R28, 0x19 ; X=25 MOV R27, 0x18 ; Y=24 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col6CL c6r4: CMP R17, 0x1A BRNE c6r3 ; spot locations start at bottom left of piece drawing MOV R28, 0x19 ; X=25 MOV R27, 0x14 ; Y=20 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col6CL c6r3: CMP R17, 0x13 BRNE c6r2 ; spot locations start at bottom left of piece drawing MOV R28, 0x19 ; X=25 MOV R27, 0x10 ; Y=16 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col6CL c6r2: CMP R17, 0x0C BRNE c6r1 ; spot locations start at bottom left of piece drawing MOV R28, 0x19 ; X=25 MOV R27, 0x0C ; Y=12 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col6CL c6r1: ; CMP R17, 0x05 MOV R28, 0x19 ; X=25 MOV R27, 0x08 ; Y=8 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col6CL col6CL: CALL currentlocation ; branch to check the whole board for win SUB R17, 0x07 ;subtract 7 off the key value to get to the right memory location (the spot above the spot recently placed.) CMP R0, 0x01 ; check whose turn it is next BREQ start2 BRNE start1 ;------------------ column 7 col7: CMP R18, 0xFF ;;compare to top column7 piece BREQ error; branch to error subroutine if it's at the top ST R0, (R18) ;; store player1 = 0x01 into correct chip spot c7r6: CMP R18, 0x29; compare to each spot in column BRNE c7r5 ; spot locations start at bottom left of piece drawing MOV R28, 0x1D ; X=29 MOV R27, 0x1C ; Y=28 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col7CL c7r5: CMP R18, 0x22; BRNE c7r4 MOV R28, 0x1D ; X=29 MOV R27, 0x18 ; Y=24 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col7CL c7r4: CMP R18, 0x1B BRNE c7r3 ; spot locations start at bottom left of piece drawing MOV R28, 0x1D ; X=29 MOV R27, 0x14 ; Y=20 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col7CL c7r3: CMP R18, 0x14 BRNE c7r2 ; spot locations start at bottom left of piece drawing MOV R28, 0x1D ; X=29 MOV R27, 0x10 ; Y=16 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col7CL c7r2: CMP R18, 0x0D BRNE c7r1 ; spot locations start at bottom left of piece drawing MOV R28, 0x1D ; X=29 MOV R27, 0x0C ; Y=12 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col7CL c7r1: ;CMP R18, 0x06 MOV R28, 0x1D ; X=29 MOV R27, 0x08 ; Y=8 CALL drawpiece; draw 3x3 piece. iterate through all 9 spots for piece BRN col7CL col7CL: CALL currentlocation ;; branch to check the whole board for win SUB R18, 0x07 ;;subtract 7 off the key value to get to the right memory location (the spot above the spot recently placed.) CMP R0, 0x01 ; compare to check whose turn it is next BREQ start2 BRNE start1 ;------------------------- drawpiece: ; a 3x3 piece on the board is drawn by iterating through -y, -y, +x, +y, +y, +x, -y, -y CMP R0, 0x01 ; check turn register to see whose turn it is BREQ redgo ; if it's 1, draw a red piece BRNE yellowgo ; if it's not 1, then it's 2; draw a yellow piece yellowgo: MOV R26, 0xFC; "11111100"; P2 = yellow (all red and green) BRN drawchip redgo: MOV R26, 0xE0; P1 = RED -"11100000" BRN drawchip drawchip: MOV R24, R27 MOV R25, R28 CALL draw_dot ; draw bottom left corner of piece (location originated when drawpiece is called) SUB R27, 0x01; -y (move up one); mid left MOV R24, R27 MOV R25, R28 CALL draw_dot SUB R27, 0x01; -y (move up one); upper left MOV R24, R27 MOV R25, R28 CALL draw_dot ADD R28, 0x01; +x (move right one; upper middle MOV R24, R27 MOV R25, R28 CALL draw_dot ADD R27, 0x01; +y (move down one); center MOV R24, R27 MOV R25, R28 CALL draw_dot ADD R27, 0x01; +y (move down one); lower middle MOV R24, R27 MOV R25, R28 CALL draw_dot ADD R28, 0x01; +x (move right one); bottom right MOV R24, R27 MOV R25, R28 CALL draw_dot SUB R27, 0x01; -y (up one); right center MOV R24, R27 MOV R25, R28 CALL draw_dot SUB R27, 0x01; -y (up one); upper right MOV R24, R27 MOV R25, R28 CALL draw_dot RET; go back to column subroutine ; ------WIN checks ----------- currentlocation: MOV R9, 0x00 ; initialize current pointer (where to start checking) MOV R7, 0x01 ; initialize second pointer (piece to compare first piece to) - one to right for horizontal CALL horizontal MOV R9, 0x00 ;current pointer MOV R7, 0x07 ;second pointer - one below CALL vertical MOV R9, 0x15 ;current pointer - first piece in possible diagonal line with positive slope MOV R7, 0x0F ;second pointer - next piece in that line (up one, right one) CALL diagonal1 MOV R9, 0x1B ;current pointer - first piece in possible diagonal line with negative slope MOV R7, 0x13 ;second pointer - next piece in that line (up one, left one) CALL diagonal2 RET ; return to after CALL currentlocation in our col subroutines horizontal: LD R8, (R9); value of current location LD R6, (R7); value of second "checking" location CMP R7, 0x06 ;check 6 BREQ add2both ; if it's at the end of the horizontal line, start on first two spots on next line CMP R7, 0x0D ;check 13 BREQ add2both CMP R7, 0x14 ;check 20 BREQ add2both CMP R7, 0x1B ;check 27 BREQ add2both CMP R7, 0x22 ;check 34 BREQ add2both ADD R9, 0X01 ;iterate current pointer ADD R7, 0X01 ;iterate second pointer comph: CMP R7, 0x2A ;check one to the right of 41 ; check if it is at the end of board BREQ hret CMP R8, R6 ;compare current and second BREQ matchcounterhorizontal BRNE horizontal hret: MOV R2, 0x00 ;reset match counter RET ; back to currentlocation subroutine add2both: MOV R2, 0x00 ;reset match counter because can't match if not in same row ADD R9, 0x02 ADD R7, 0x02 BRN comph vertical: LD R8, (R9); value of current LD R6, (R7); value of second CMP R7, 0x23 ; bring to next column if at end BREQ minus27both CMP R7, 0x24 BREQ minus27both CMP R7, 0x25 BREQ minus27both CMP R7, 0x26 BREQ minus27both CMP R7, 0x27 BREQ minus27both CMP R7, 0x28 BREQ minus27both ADD R9, 0X07 ;iterate current pointer ADD R7, 0X07 ;iterate second pointer compv: CMP R7, 0x30 ;check one below 41 ; check if it is at the end BREQ vret CMP R8, R6 ;compare current and second BREQ matchcountervertical BRNE vertical vret: MOV R2, 0X00 ; reset match counter RET ; back to currentlocation. do next check minus27both: MOV R2, 0x00 ;reset match counter SUB R9, 0x1B ;minus 27 to get to next column SUB R7, 0x1B BRN compv diagonal1: LD R8, (R9); value of current LD R6, (R7); value of second CMP R7, 0x03 ; check if on upper right corner. if so, start on next diagonal line BREQ add19both ;; 0x13 hex CMP R7, 0x04 BREQ add25both ;; 0x19 hex CMP R7, 0x05 BREQ add25both ;; 0x19 hex CMP R7, 0x06 BREQ add25both ;; 0x19 hex CMP R7, 0x0D BREQ add25both ;; 0x19 hex SUB R9, 0X06 ;iterate current pointer SUB R7, 0X06 ;iterate second pointer compd1: CMP R9, 0x14 ; check if it is at the end BREQ d1ret CMP R8, R6 ;compare current and second BREQ matchcounterdiagonal1 BRNE diagonal1 d1ret: MOV R2, 0X00 ; reset match counter RET add19both: MOV R2, 0x00 ;reset match counter ADD R9, 0x13 ;add19 ADD R7, 0x13 BRN compd1 add25both: MOV R2, 0x00 ;reset match counter ADD R9, 0x19 ;add25 ADD R7, 0x19 BRN compd1 diagonal2: ; similar process to diagonal1, check potential diagonal lines LD R8, (R9); value of current LD R6, (R7);value of second CMP R7, 0x03 BREQ add23both ;; 0x17 hex CMP R7, 0x02 BREQ add31both ;; 0x1F hex CMP R7, 0x01 BREQ add31both ;; 0x1F hex CMP R7, 0x00 BREQ add31both ;; 0x1F hex CMP R7, 0x07 BREQ add23both ;; 0x17 hex SUB R9, 0X08 ;iterate current pointer SUB R7, 0X08 ;iterate second pointer compd2: CMP R9, 0x0E ; check if it is at the end BREQ d2ret CMP R8, R6 ;compare current and second BREQ matchcounterdiagonal2 BRNE diagonal2 d2ret: MOV R2, 0X00 RET add23both: MOV R2, 0x00 ;reset match counter ADD R9, 0x17 ;add23 ADD R7, 0x17 BRN compd2 add31both: MOV R2, 0x00 ;reset match counter ADD R9, 0x1F ;add31 ADD R7, 0x1F BRN compd2 matchcounterhorizontal: CMP R8, 0x00 ; if one of them are zero BREQ horizontal ADD R2, 0x01 ; add to matchcounter CMP R2, 0x03 ; 3 matches = win BREQ gameover BRN horizontal matchcountervertical: CMP R8, 0x00 BREQ vertical ADD R2, 0X01 CMP R2, 0X03 BREQ gameover BRN vertical matchcounterdiagonal1: CMP R8, 0x00 BREQ diagonal1 ADD R2, 0X01 CMP R2, 0X03 BREQ gameover BRN diagonal1 matchcounterdiagonal2: CMP R8, 0x00 BREQ diagonal2 ADD R2, 0X01 CMP R2, 0X03 BREQ gameover BRN diagonal2 ISR: IN R1, SWITCHES ;; check which switches are up mov r31, 0xff; RETIE; go back to noop gameover: ; write "win". piece drawn to right of board shows winner MOV R26, 0XFF ; change color register to white MOV R27, 0X00 ; Y-coord MOV R28, 0X09 ; X-coord MOV R29, 0x00; dot counter CALL columndown MOV R27, 0x03 MOV r28, 0x0A MOV R29, 0x00; dot counter MOV R25, R28 MOV R24, R27 CALL draw_dot MOV R27, 0x00 MOV R28, 0x0B MOV R29, 0x00; dot counter MOV R25, R28 MOV R24, R27 CALL columndown MOV R27, 0x03 MOV r28, 0x0C MOV R29, 0x00; dot counter MOV R25, R28 MOV R24, R27 CALL draw_dot MOV R27, 0x00 MOV R28, 0x0D MOV R29, 0x00; dot counter MOV R25, R28 MOV R24, R27 CALL columndown MOV R27, 0x00 MOV R28, 0x0F MOV R29, 0x00; dot counter MOV R25, R28 MOV R24, R27 CALL columndown MOV R27, 0x00 MOV R28, 0x11 MOV R29, 0x00; dot counter MOV R25, R28 MOV R24, R27 CALL columndown MOV R27, 0x01 MOV r28, 0x12 MOV R29, 0x00; dot counter MOV R25, R28 MOV R24, R27 CALL draw_dot MOV R27, 0x00 MOV R28, 0x13 MOV R29, 0x00; dot counter MOV R25, R28 MOV R24, R27 CALL columndown BRN noop columndown: ADD R29, 0x01 ADD R27, 0x01 MOV R25, R28 MOV R24, R27 CALL draw_dot CMP R29, 0x03; BRNE columndown RET ; -------------------------------------------------------------------- ; function draw_dot, courtesy of Prof. Bridget Benson ; -------------------------------------------------------------------- draw_dot: AND r25, 0x3F ; make sure top 2 bits cleared AND r24, 0x1F ; make sure top 3 bits cleared LSR r24 ;need to get the bot 2 bits of s4 into sA BRCS dd_add40 t1: LSR r24 BRCS dd_add80 dd_out: OUT r25, VGA_LADD ; write bot 8 address bits to register OUT r24, VGA_HADD ; write top 3 address bits to register OUT r26, VGA_COLOR ; write data to frame buffer RET dd_add40: OR r25, 0x40 CLC BRN t1 dd_add80: OR r25, 0x80 BRN dd_out draw_background: MOV r26,0x00 ; use default color MOV r28,0x00 ; x=0 MOV r27,0x00 ; y=0 background: MOV r24,r27 MOV r25,r28 CALL draw_dot ADD r28,0x01 ; add 1 to draw rows CMP r28,0x27 ;; end x-coord - 39 BRNE background MOV r28,0x00 ;reset x coord ADD r27,0x01 ;iterate to next row MOV R24,R27 MOV R25,R28 CMP R27,0x1D ;check if it hits last row BRNE background RET .ORG 0x3ff ; INTERRUPT brn ISR ; send it to ISR