Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I ' m having trouble with this code in mips assembly checking if the C key is pressed. drawmode _ nothing: push ra # Check

I'm having trouble with this code in mips assembly checking if the C key is pressed.
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_notclicked # If left mouse button is not pressed, skip drawing
# 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,0,_endif_notclicked
j _c_clicked
j _endif_notclicked
_c_clicked:
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 #sprite_x = PALETTE_X + x *8
sb t0,0(t9)
#calculate y cord
li t1, PALETTE_Y
mul t1, s0,8
add t0, t1, PALETTE_Y #sprite_y = PALETTE_Y + y *8
sb t0,1(t9)
#calc which tile to use
li t2, PALETTE_TILE
add t0, t2, s1 # Calculate the tile index by adding s1 to PALETTE_TILE
#add t, t2, s0
sb t0,2(t9)
#set__tile(sprite_index, PALETTE_TILE + sprite_index -1)
#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 s0,2,_outer_loop
_endif_notclicked:
pop ra
jr ra
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago