Answered step by step
Verified Expert Solution
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
drawcursor:
push ra
la t displaysprtable
move t s
# multiply by
sll t t
sb tt
move t s
# multiply by
sll t t
sb tt
sb zero, t
li tx
sb tt
pop ra
jr ra
This is what I have so far for this method:
#this is what I have so far for lab
drawcursor:
push ra
la t displaysprtable
# get mouse coordinates
lw t displaymousex
lw t displaymousey
# calculate cursor coordinates
addi t t
addi t t
sb zero, t
pop ra
jr ra
This is my prompt for the method
drawcursor
Just like lab you need to draw a cursor on the screen. Unlike lab 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 drawcursor function will be almost exactly the same as lab s with a couple changes:
the coordinates will be displaymousex and displaymousey
the tile number will be CURSORTILE instead of
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
drawcursor function will be almost exactly the same as lab s with a couple
: PM
changes:
the coordinates will be
displaymousex and
displaymousey
the tile number will be CURSORTILE
instead of
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:
displaymousex
displaymousey
If you Iw from them, you will get the coordinates of the mouse measured from
the topleft of the display. Both and range However, if the mouse
cursor is outside of the display, both variables will instead be You only
have to check one: either they're both or neither is
There is a minor bug that happens when you click and drag on the display,
which allows the displaymousexy variables to go outside the range
if you drag the cursor off the edges of the display. Im not 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:
endiflbutton:
The mouse button variables are:
displaymousepressed to check if a button went from notheld to
held this frame just pressed it
displaymouseheld to check if a button is being held down or not
displaymousereleased 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:
MOUSELBUTTON left button trackpad normal click
MOUSERBUTTON right button trackpad twofinger click or bottomright
click
MOUSEMBUTTON middle button scroll wheel click; trackpad threefinger
click sometimes
checkinput and the drawmodefunctions
Although it's called checkinput 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 checkinput does is essentially switch on the drawmode variable
and based on which value it is calls one of drawmodenothing
drawmodebrush, or drawmodecolor
You already know enough to do this. You know how to make a switchcase,
you know how to call functions, you know how to stub them out. Go do it
But,
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started