Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Drawing Lab mips assembly, Im trying to make a drawing lab and I am so unbelieveably confused. Please help with what you can Ill include

Drawing Lab mips assembly, Im trying to make a drawing lab and I am so unbelieveably confused. Please help with what you can Ill include as much as I can on my end.
#this is what i had for lab 3
draw_cursor:
push ra
la t2, display_spr_table
move t0, s0
# multiply by 8
sll t0, t0,3
sb t0,0(t2)
move t0, s1
# multiply by 8
sll t0, t0,3
sb t0,1(t2)
sb zero, 2(t2)
li t0,0x41
sb t0,3(t2)
pop ra
jr ra
This is what I have so far for this method:
#this is what I have so far for lab 4
draw_cursor:
push ra
la t2, display_spr_table
# get mouse coordinates
lw t0, display_mouse_x
lw t1 display_mouse_y
# calculate cursor coordinates
addi t0, t0,-3
addi t1, t1,-3
sb zero, 2(t2)
pop ra
jr ra
This is my prompt for the method
2. draw_cursor
Just like lab 3, you need to draw a cursor on the screen. Unlike lab 3, youll be using the mouse position as the cursors position instead of using your own variables and keyboard arrows to move it.
The MMIO variables for the mouses position are described in detail below. Your draw_cursor function will be almost exactly the same as lab 3s, with a couple changes:
the coordinates will be display_mouse_x -3 and display_mouse_y -3
the tile number will be CURSOR_TILE instead of 0
Done right, you should be able to see a crosshair cursor like in the image when you move your mouse over the display, and it should stick to your mouse cursor.
Also, when you move your mouse cursor off the display, it should disappear.
I will also attatch the rest of the lab instructions incase that helps: The MMIO variables for the mouse's position are described in detail below. Your
draw_cursor function will be almost exactly the same as lab 3's, with a couple
21924,4:11 PM
changes:
the coordinates will be
display_mouse_x -3 and
display_mouse_y -3
the tile number will be CURSOR_TILE
instead of 0
Done right, you should be able to see a
crosshair cursor like in the image when you
move your mouse over the display, and it
should "stick to" your mouse cursor.
Also, when you move your mouse cursor off the display, it should disappear.
How to get mouse input in the display
There are two variables for getting the mouse position:
display_mouse_x
display_mouse_y
If you Iw from them, you will get the coordinates of the mouse measured from
the top-left of the display. Both x and Y range [0,127]. However, if the mouse
cursor is outside of the display, both variables will instead be -1. You only
have to check one: either they're both -1 or neither is.
There is a minor bug that happens when you click and drag on the display,
which allows the display_mouse_x/y variables to go outside the range
0,127 if you drag the cursor off the edges of the display. I'm not 100% sure
why it happens, but it's easy to work around. Failing to work around it can
cause strange crashes if you aren't careful with what you do with those
invalid coordinates.
For getting the mouse buttons, it works a little differently from keyboard input.
Since there are only three buttons, you can get their state all at once, and use
bitwise AND to extract the state of just one. For example:
_endif_lbutton:
The mouse button variables are:
display_mouse_pressed - to check if a button went from not-held to
held this frame (just pressed it)
display_mouse_held - to check if a button is being held down or not
display_mouse_released - to check if a button went from held to not-
held this frame (just let go)
And the constants you use in the bitwise AND are:
MOUSE_LBUTTON - left button (trackpad normal click)
MOUSE_RBUTTON - right button (trackpad two-finger click or bottom-right
click)
MOUSE_MBUTTON - middle button (scroll wheel click; trackpad three-finger
click sometimes)
check_input and the drawmode_functions
Although it's called check_input it kinda ends up doing... most stuff. Lol.
(Hey, there is a "more elegant" way to do this but it ends up being a bunch of
extra complexity for not a lot of benefit in this case.)
All my check_input does is essentially switch on the drawmode variable
and based on which value it is, calls one of drawmode_nothing ,
drawmode_brush, or drawmode_color .
You already know enough to do this. You know how to make a switch-case,
you know how to call functions, you know how to stub them out. Go do it.
But,
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_2

Step: 3

blur-text-image_3

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions