- hmm.gif (79.77 KiB) Viewed 9633 times
Now, I'm absolutely stupid when it comes to menu stuff but one thing I've managed to get right is the cursor moving to a new position smoothly.
The gif is from S1Mousealog but it's a simplified copy from Gatoslip's battle menu with an added second X position parameter.
Here's the silly pre-calculated set of positions. Each row has 3 values with 2 bytes each (6 bytes per row, 30 bytes in total)
And here is that wacky 68k code, the commented part at the top would've defaulted the position to the bottom left corner of the screen, which isn't necessary for this case.
First we load the position table at address register a1.
We'll want to offset this table to the correct position of the menu, so we fetch the value of the internal vertical option (which is a number between 0 and 2) and store it on data register d2.
Since the instruction messes with the condition code register (CCR), we won't have to add a compare or test instruction, we can have a conditional branch right after (this happens a lot on the 68k for optimal code). In this case we use it to check if we're on position 0 on the menu and only branch to a later part of the code if it's not 0.
If the position is 0, then we use the internal horizontal option instead, overwritting what was previously on d2. On top of that, we add 3*6 to the position so we start at the 3rd row on the table.
Now theoretically (and this is the case in Gatoslip's version of the code!) I could've just used one value to represent the current menu position rather than 2 for horizontal and vertical positions... honestly I don't got any excuse for why I did it this way, like I'd said, I'm stupid with menu stuff.
Next we have an unreasonable ammount of instructions just to multiply d2 by 6, but as it turns out, the M68k's multiplication and division instructions are super costly so we want to avoid those.
We now add d2 to a1, which'll offset the address to the correct row of position values from the table, from there we wastefully move the values to data registers d0 through d5 (we could've avoided using so many data registers by fetching them later in the code when necessary and maybe even do a simple loop with another table to make the code smaller, didn't think of that at the time x.x)
We then have what's essentially the following code three times in a row for each axis :
MenuPosition = MenuPosition + (NewMenuPosition - MenuPosition / 4)
if "MenuPosition>>2" happens to be 0, then it'll snap to the final position.
.... dang it I should've made a post about the mouse peripheral instead, this tangent is stupid.