Question: drawmode _ nothing: push ra # Check if left mouse button is pressed lw t 0 , display _ mouse _ pressed and t 0

drawmode_nothing:
push ra
# Check if left mouse button is pressed
lw t0, display_mouse_pressed
and t0, t0, MOUSE_LBUTTON # Check if bit 0(left mouse button) is set
beq t0,0,_endif_lnotpressed # If left mouse button is not pressed, skip drawing
_endif_lnotpressed:
pop ra
jr ra
# Set drawmode to MODE_BRUSH
li t0, MODE_BRUSH
sw t0, drawmode
# Draw a 1-pixel-long line at current mouse coordinates in current color
lw a0, display_mouse_x # Load current mouse x coordinate
lw a1, display_mouse_y # Load current mouse y coordinate
lw a2, display_mouse_x # Load current mouse x coordinate
lw a3, display_mouse_y
lw v1, color
jal display_draw_line
lw a0, display_mouse_x # Load current mouse x coordinate
lw a1, display_mouse_y # Load current mouse y coordinate
# Set last_x and last_y to current mouse coordinates
sw a0, last_x
sw a1, last_y
li t0, KEY_C
sw t0, display_key_pressed
lw t0, display_key_pressed
beq t0, zero, _return
li t0, MODE_COLOR
sw t0, drawmode
la t9, display_spr_table
addi t9, t9,4
#inside your
#initialize outer loop counter
li s0,0
#nested for loop
outer_loop:
#initialize inner loop counter
li s1,0
inner_loop:
#t0= calculate x cord
mul t1, s1,8
add t0, t1, PALETTE_X
sb t0,0(t9)
#calculate y cord
li t1, PALETTE_Y
mul t1, s0,8
add t0, t1, PALETTE_Y
sb t0,1(t9)
#calc which tile to use
li t2, PALETTE_TILE
add t3, t2, s1
sb t3,2(t9)
#UP TO U
sb t0,2(t9)
#flags are just 1
li t0,1
sb t0,3(t9)
#finally, add 4 to t9 to move to the next sprite
add t9, t9,4
#inner loop increment and branch here
add s1, s1,1
blt s1,8, inner_loop
#outer loop increment and branch here
add s0, s0,1
blt s1,2, outer_loop
_return: # Define the _return label
pop ra
jr ra
drawmode_brush:
push ra
lw t0, display_mouse_released
and t0, t0, MOUSE_LBUTTON # Check if bit 0(left mouse button) is set
beq t0,1,_endif_offscreen # If left mouse button is not released, skip drawing
lw a0, display_mouse_x # Load current mouse x coordinate
lw a1, display_mouse_y # Load current mouse y coordinate
lw a2, last_x # Load last mouse x coordinate
lw a3, last_y
lw v1, color
#if user is off screen
blt, a0,0,_endif_offscreen
blt, a1,0,_endif_offscreen
bge, a0,128,_endif_offscreen
bge, a1,128,_endif_offscreen
j _current_last
_endif_offscreen:
li t0, MODE_NOTHING
sw t0, drawmode
j _return
_current_last: # Load last mouse y coordinate
bne a0, a2,_drawline # If current x does not equal last x, draw line
bne a1, a3,_drawline # If current y does not equal last y, draw line
_drawline:
#draw a line from last_x/y to the current mouse coordinates in the current color
#set the last_x and last_y to the current mouse coordinates.
li t0, MODE_BRUSH
sw t0, drawmode
lw a0, display_mouse_x # Load current mouse x coordinate
lw a1, display_mouse_y # Load current mouse y coordinate
lw a2, last_x # Load last mouse x coordinate
lw a3, last_y
lw v1, color
jal display_draw_line
lw a0, display_mouse_x # Load current mouse x coordinate
lw a1, display_mouse_y
sw a0, last_x
sw a1, last_y
_return:
pop ra
jr ra
 drawmode_nothing: push ra # Check if left mouse button is pressed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!