diff --git a/blinkTest.s b/blinkTest.s index a16b78c..dcd51ba 100644 --- a/blinkTest.s +++ b/blinkTest.s @@ -1,6 +1,6 @@ .text -jal delay1S #NEED THIS DONT KNOW WHY +#jal delay1S #NEED THIS DONT KNOW WHY j begin @@ -19,16 +19,19 @@ jr $31 #FUNCTION END------------------------------------------------ #FUNCTION drawPixel------------------------------------------ -#Draws the pixel at x = $25, y = $26, color = $27 +#Draws the pixel at x = $4, y = $5, color = $6 #Dicks with registers: all the T registers from 8 to 15 #--------------------------- drawPixel: -lw $8, vgaStart($0) #Load VGAStart into $8 +#lw $8, vgaStart($0) #Load VGAStart into $8 +move $8, $gp lw $9, screenWidth($0) #Load width into $9 -mul $9, $9, $26 #Multiply width * Y +mul $9, $9, $5 #Multiply width * Y +sll $9, $9, 2 +sll $4, $4, 2 add $8, $8, $9 #Add Y offset to $8 -add $8, $8, $25 #Add X offset to $8 -sw $27, 0($8) #Draw the pixel +add $8, $8, $4 #Add X offset to $8 +sw $6, 0($8) #Draw the pixel jr $31 #FUNCTION END------------------------------------------------ @@ -40,21 +43,21 @@ jr $31 drawRect: addi $15, $31, 0 #BACK DAT STACK -addi $25, $20, 0 -addi $26, $21, 0 -addi $27, $24, 0 +addi $4, $20, 0 +addi $5, $21, 0 +addi $6, $24, 0 add $10, $20, $22 #The end limit in X add $11, $21, $23 #The end limit in Y drawRow: jal drawPixel -addi $25, $25, 1 -blt $25, $10, drawRow +addi $4, $4, 4 +blt $4, $10, drawRow -addi $26, $26, 1 -addi $25, $20, 0 -blt $26, $11, drawRow +addi $5, $5, 4 +addi $4, $20, 0 +blt $5, $11, drawRow addi $31, $15, 0 #UNBACK DAT STACK jr $31 @@ -69,10 +72,10 @@ addi $20, $20, 1 addi $21, $20, 0 addi $22, $20, 0 addi $23, $19, 0 -addi $24, $19, 0 +li $24, 0x0022cc22 jal drawRect -jal delay1S +#jal delay1S j begin diff --git a/flappyBird.s b/flappyBird.s index 7d1ae84..527a125 100644 --- a/flappyBird.s +++ b/flappyBird.s @@ -24,50 +24,54 @@ mainInit: # Load player info lw $4, playerX # lw $5, playerY - jal coordToAddr # Convert player position to address - - add $16, $0, $2 # Store player start position in $16 + lw $6, playerColor + + # draw initial player + jal drawPlayer # Convert player position to address lw $20, defaultDir # Store default dir in $20 - # Load color info - lw $22, playerColor # Store drawing color in $22 - lw $23, bgndColor # Store background color in $23 + # Store player location + add $22, $0, $4 # Store playerX in $22 + add $23, $0, $5 # Store playerY in $23 # Prepare the arena - add $4, $0, $23 # Fill stage with background color + lw $4, bgndColor # Fill stage with background color jal fillColor -# jal AddBounds # Add walls - - # Draw initial player - add $4, $0, $16 - jal drawPlayer + jal AddBounds # Add walls # Draw initial pipes - lw $4, pipeSpace # start first pipe + lw $16, pipeSpace # store x of first pipe + add $4, $0, $16 add $5, $0, $0 - jal coordToAddr - - add $17, $0, $2 # Store address of first pipe - add $4, $0, $17 - lw $6, playerColor + lw $6, pipeHeight + lw $7, playerColor jal drawPipe - + + lw $17, pipeWidth lw $18, pipeSpace - sll $18, $18, 2 - add $17, $17, $18 # Go to next pipe - add $4, $0, $17 - lw $6, playerColor + add $16, $16, $17 # second pipe + add $16, $16, $18 + add $4, $0, $16 + add $5, $0, $0 + lw $6, pipeHeight + lw $7, playerColor jal drawPipe - add $17, $17, $18 # Go to next pipe - add $4, $0, $17 - lw $6, playerColor + add $16, $16, $17 # third pipe + add $16, $16, $18 + add $4, $0, $16 + add $5, $0, $0 + lw $6, pipeHeight + lw $7, playerColor jal drawPipe - - add $17, $17, $18 # Go to next pipe - add $4, $0, $17 - lw $6, playerColor + + add $16, $16, $17 # fourth pipe + add $16, $16, $18 + add $4, $0, $16 + add $5, $0, $0 + lw $6, pipeHeight + lw $7, playerColor jal drawPipe #mainWaitToStart: @@ -77,7 +81,6 @@ mainInit: mainGame: # Actual game - # Update bird jal GetDir # Get direction from keyboard add $20, $0, $2 # $20 is direction from keyboard @@ -87,72 +90,24 @@ mainGame: mainMoveUp: bne, $20, 0x02000000, mainMoveDown lw $5, boost - jal moveUp # Up + add $23, $23, $5 # update bird y j mainGameCtd mainMoveDown: lw $5, gravity - jal moveDown # Down + add $23, $23, $5 # Down mainGameCtd: - - # erase old player position by retracing with background color - add $4, $0, $16 - lw $5, bgndColor - jal drawPlayer - # update player with new position - add $16, $0, $2 # Update address - add $4, $0, $16 + add $4, $0, $22 + add $5, $0, $23 + lw $6, playerColor jal drawPlayer # Update player's location on screen - # clear pipes by tracing them with background color - lw $6, bgndColor - jal drawPipe # Draw the rightmost pipe - - lw $18, pipeSpace - sll $18, $18, 2 - sub $17, $17, $18 # Go to next pipe - add $4, $0, $17 - lw $6, bgndColor - jal drawPipe - - sub $17, $17, $18 # Go to next pipe - add $4, $0, $17 - lw $6, bgndColor - jal drawPipe - - sub $17, $17, $18 # Go to next pipe - add $4, $0, $17 - lw $6, bgndColor - jal drawPipe - # draw in updated pipes - add $4, $0, $17 - addi $5, $0, 1 - jal moveLeft # Move rightmost pipe left by 1 unit - - add $17, $0, $2 - add $4, $0, $17 - lw $6, playerColor - jal drawPipe # Draw the leftmost pipe - - lw $18, pipeSpace - sll $18, $18, 2 - add $17, $17, $18 # Go to next pipe - add $4, $0, $17 - lw $6, playerColor - jal drawPipe - - add $17, $17, $18 # Go to next pipe - add $4, $0, $17 - lw $6, playerColor - jal drawPipe - - add $17, $17, $18 # Go to next pipe - add $4, $0, $17 - lw $6, playerColor - jal drawPipe + addi $16, $16, -1 # move pipes left + add $4, $0, $16 # redraw the pipes + lw $5, playerColor jal collisionDetect # Check for collisions @@ -163,6 +118,7 @@ mainGameOver: b mainInit ########################################################################################### +# Unused # Get x,y coordinates stored in $4,$5 and returns pixel address in $2 coordToAddr: #address = 4*(x + y*width) + gp @@ -175,6 +131,20 @@ coordToAddr: add $2, $2, $28 # Add $28 to $2 to give stage memory address jr $31 # ########################################################################################### +# Get x,y coordinates stored in $4,$5 and draws in color $6 +drawPixel: + #address = 4*(x + y*width) + gp + add $8, $0, $4 # Move x to $8 + lw $4, stageWidth # + multu $4, $5 # Multiply y by the stage width + mflo $4 # Get result of $4*$5 + addu $8, $8, $4 # Add the result to the x coordinate and store in $2 + sll $8, $8, 2 # Multiply $2 by 4 bytes + add $8, $8, $28 # Add $28 to $2 to give stage memory address + sw $6, 0($8) # color in the pixel + jr $31 # +########################################################################################### +# Unused # Function to add a given stage memory address right by a given number of tiles # Takes a0 = address, a1 = distance # Returns v0 = new address @@ -185,6 +155,7 @@ moveLeft: sub $2, $2, $4 # Add result to $2 jr $31 # ########################################################################################### +# Unused # Function to add a given stage memory address up by a given number of tiles # Takes $4 = address, $5 = distance # Returns $2 = new address @@ -199,6 +170,7 @@ moveUp: jr $31 # ########################################################################################### +# Unused # Function to add a given stage memory address down by a given number of tiles # Takes $4 = address, $5 = distance # Returns $2 = new address @@ -225,48 +197,35 @@ GetDir_done: ########################################################################################### # Fill stage with color, $4 fillColor: - lw $5, stageWidth # Calculate ending position - lw $6, stageHeight - multu $5, $6 # Multiply screen width by screen height - mflo $6 # Set end point - sll $6, $6, 2 # Multiply by 4 - add $6, $6, $28 # Add global pointer - add $5, $0, $28 # Set start point -fillColorLoop: - sw $4, 0($5) - add $5, $5, 4 # Add 4 - bne $5, $6, fillColorLoop # Keep looping until reached end + add $8, $0, $31 # back up $31 + add $30, $0, $4 # back up color + + add $4, $0, $0 + add $5, $0, $0 + lw $6, stageWidth + lw $7, stageHeight + + jal drawRect # fill screen + + add $31, $0, $8 jr $31 ########################################################################################### # Add bot wall AddBounds: - add $12, $0, $31 # Back up $31 + add $8, $0, $31 # back up $31 - lw $8, stageWidth # Calculate final ending position - lw $9, stageHeight - addi $8, $8, -1 - addi $9, $9, -1 - - add $4, $0, $0 # Convert (0, stageHeight) to address - add $5, $0, $9 - jal coordToAddr - - add $10, $0, $2 # Save the address to $10 - - add $4, $0, $8 # Convert (stageWidth, stageHeight) to address - add $5, $0, $9 - jal coordToAddr - - add $11, $0, $2 # Save the address to $11 - - add $4, $0, $10 - add $5, $0, $11 - lw $6, playerColor - jal drawLineHoriz # draw line from (0, stageHeight) to (stageWidth, stageHeight) + add $4, $0, $0 # draw line from x + lw $5, stageWidth # to end of screen + lw $6, stageHeight # at stageHeight + addi $6, $6, -1 # minus 1 + lw $7, playerColor + + jal drawLineHorizXY - add $31, $0, $12 + add $31, $0, $8 jr $31 ########################################################################################### +# Unused # Draw horizontal line from $4 to $5 in color $6 drawLineHoriz: sw $6, 0($4) # color @@ -274,6 +233,7 @@ drawLineHoriz: bne $4, $5, drawLineHoriz # keep doing this until $5 jr $31 ########################################################################################### +# Unused # Draw vertical line from $4 to $5 in color $6 drawLineVert: sw $6, 0($4) # color @@ -283,100 +243,143 @@ drawLineVert: bne $4, $5, drawLineVert # keep doing this until $5 jr $31 ########################################################################################### -# Draw the player given an address, $4, of top left corner, in the color $5 -drawPlayer: - add $14, $0, $31 # back up $31 +# Draw horizontal line from $4, $6 (x1, y) to $5, $6 (x2, y) in color $7 +drawLineHorizXY: + add $8, $0, $31 # back up $31 - add $8, $0, $4 # back up start address (top left coord) - add $13, $0, $5 # back up color - lw $9, playerSize - sll $9, $9, 2 # playerSize*4 stored in $9 - add $10, $8, $9 # player top right coord - lw $11, stageWidth - multu $9, $11 # for player vertical distance in pixels - mflo $11 - add $11, $11, $8 # player bottom left coord - add $12, $11, $9 # player bottom right coord - - add $6, $0, $13 - add $5, $0, $10 - jal drawLineHoriz # draw top line of player - - add $4, $0, $8 - add $5, $0, $11 - jal drawLineVert # draw left line of player - - add $4, $0, $11 - add $5, $0, $12 - jal drawLineHoriz # draw bottom line of player + add $9, $0, $4 # back up $4 (x1) + add $10, $0, $5 # back up $5 (x2) + add $11, $0, $6 # back up $6 (y) + + add $5, $0, $6 # move y to $5 + jal drawPixel # draw (x1, y) +keepMovingRight: + addi $9, $9, 1 # move x1 right by 1 coord + add $4, $0, $9 # move x1 to $4 + add $5, $0, $11 # move y to $5 + jal drawPixel + blt $9, $10, keepMovingRight + + add $31, $0, $8 + jr $31 +########################################################################################### +# Unused +# Draw vertical line from $4, $5 (x, y1) to $4, $6 (x, y2) in color $7 +drawLineVertXY: + add $8, $0, $31 # back up $31 + + add $9, $0, $4 # back up $4 (x) + add $10, $0, $5 # back up $5 (y1) + add $11, $0, $6 # back up $6 (y2) + + jal drawPixel # draw (x, y1) +keepMovingDown: + addi $10, $10, 1 # move y1 down by 1 coord + add $4, $0, $9 # move x to $4 + add $5, $0, $10 # move y1 to $5 + jal drawPixel + blt $10, $11, keepMovingDown + + add $31, $0, $8 + jr $31 +########################################################################################### +# Draw rectangle from $4, $5 (x, y) with width $6, and height $7, in color $30 +drawRect: + add $8, $0, $31 # back up $31 + + add $9, $0, $4 # back up $4 (x) + add $10, $0, $5 # back up $5 (y) + + add $11, $9, $6 # calculate end x + add $12, $10, $7 # calculate end y + + add $5, $0, $11 # move end x to $5 + add $6, $0, $10 # move y to $6 + add $7, $0, $30 # move color to $7 + jal drawLineHorizXY # draw line from x, y to end x, y +keepDrawingAcross: + addi $10, $10, 1 # move y down by 1 coord + add $4, $0, $9 # move x to $4 + add $5, $0, $11 # move end x to $5 + add $6, $0, $10 # move y to $6 + jal drawLineHorizXY + blt $10, $11, keepDrawingAcross + + add $31, $0, $8 + jr $31 +########################################################################################### - add $4, $0, $10 - add $5, $0, $12 - jal drawLineVert # draw right line of player +# Draw the player given an x, y coord $4, $5, of top left corner, in the color $6 +drawPlayer: + add $8, $0, $31 # back up $31 + lw $6, playerSize # width + lw $7, playerSize # heigth = width + add $30, $0, $6 + jal drawRect - add $31, $0, $14 + add $31, $0, $8 jr $31 ########################################################################################### -# Draw pipe from an address $4 in top left corner with height $5 in color $6 +# Draw pipe from x at $4 in top left corner with height $5 in color $6 drawPipe: - add $24, $0, $31 # back up $31 + add $24, $0, $31 # back up $31 - add $8, $0, $4 # Back up $4-$6 bc will call other functions - add $9, $0, $5 - lw $11, pipeWidth - sll $11, $11, 2 # pipeWidth*4 stored in $11 - - lw $12, pipeHeight - lw $10, stageWidth - multu $12, $10 - mflo $12 - sll $12, $12, 2 # pipeHeight*stageWidth*4 stored in $12 - - add $13, $8, $12 # $13 is bottom left corner of top part of pipe - add $5, $0, $13 - jal drawLineVert # draw line from $8/$4 down to $13 - - add $14, $13, $11 # $14 is bottom right corner of top part of pipe - add $4, $0, $13 - add $5, $0, $14 - jal drawLineHoriz # draw line from $13 to $14 - - add $15, $8, $11 # $15 is top right corner of top part of pipe - add $4, $0, $15 - add $5, $0, $14 - jal drawLineVert # draw line from $15 down to $14 - - lw $12, pipeGap - lw $10, stageWidth - multu $12, $10 - mflo $12 - sll $12, $12, 2 # pipeGap*stageWidth*4 stored in $12 - - add $14, $13, $12 # $14 is now top left corner of bot part of pipe - add $15, $14, $11 # $15 is now top right corner of bot part of pipe - add $4, $0, $14 - add $5, $0, $15 - jal drawLineHoriz # draw line from $14 to $15 - + add $8, $0, $4 # back up x + add $9, $0, $5 # back up height + add $30, $0, $7 # color + + add $5, $0, $0 + lw $6, pipeWidth + add $7, $0, $9 # height + jal drawRect + + lw $11, pipeGap + add $5, $10, $11 # move y to bottom half of pipe + add $4, $0, $8 # move x to $4 + lw $6, pipeWidth lw $12, stageHeight - subi $12, $12, 1 - lw $13, stageWidth - multu $12, $13 - mflo $12 - sll $12, $12, 2 # (stageHeight-1)*stageWidth*4 stored in $12 - add $13, $12, $8 # $13 is now bottom left corner of bot part of pipe - add $4, $0, $14 - add $5, $0, $13 - jal drawLineVert # draw line from $14 to $13 - - add $12, $13, $11 # $12 is now bottom right corner of bot part of pipe - add $4, $0, $15 - add $5, $0, $12 - jal drawLineVert # draw line from $15 to $12 + sub $7, $12, $5 # calculate height of this + jal drawRect add $31, $0, $24 jr $31 ########################################################################################### +# Draw all pipes from x at $4 in top left corner in color $5 +drawAllPipe: + add $8, $0, $31 + add $9, $0, $4 + add $10, $0, $5 + + lw $5, pipeHeight + lw $6, playerColor + jal drawPipe + + lw $11, pipeWidth + lw $12, pipeSpace + add $8, $8, $11 # second pipe + add $8, $8, $12 + add $4, $0, $8 + lw $5, pipeHeight + lw $6, playerColor + jal drawPipe + + add $8, $8, $11 # second pipe + add $8, $8, $12 + add $4, $0, $8 + lw $5, pipeHeight + lw $6, playerColor + jal drawPipe + + add $8, $8, $11 # second pipe + add $8, $8, $12 + add $4, $0, $8 + lw $5, pipeHeight + lw $6, playerColor + jal drawPipe + + add $31, $0, $8 + jr $31 +########################################################################################### # Detects collision between bird and pipe collisionDetect: jr $31 \ No newline at end of file