Skip to content

Commit

Permalink
riscos: Fix off-by-one issues with mouse coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
ccawley2011 committed Sep 21, 2020
1 parent f59677f commit c412dc9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
12 changes: 8 additions & 4 deletions src/video/riscos/SDL_riscosFullScreenVideo.c
Expand Up @@ -712,12 +712,14 @@ const RISCOS_SDL_PixelFormat *FULLSCREEN_SetMode(int width, int height, int bpp)
void FULLSCREEN_SetupBanks(_THIS)
{
_kernel_swi_regs regs;
int block[5];
int block[7];
block[0] = 148; /* Write screen start */
block[1] = 149; /* Display screen start */
block[2] = 4; /* X eig factor */
block[3] = 5; /* Y eig factor */
block[4] = -1; /* End of list of variables to request */
block[2] = 4; /* X eig factor */
block[3] = 5; /* Y eig factor */
block[4] = 11; /* Screen Width - 1 */
block[5] = 12; /* Screen Height - 1 */
block[6] = -1; /* End of list of variables to request */

regs.r[0] = (int)block;
regs.r[1] = (int)block;
Expand All @@ -727,6 +729,8 @@ void FULLSCREEN_SetupBanks(_THIS)
this->hidden->bank[1] = (void *)block[1];
this->hidden->xeig = block[2];
this->hidden->yeig = block[3];
this->hidden->screen_width = block[4];
this->hidden->screen_height = block[5];
}

/* Toggle to full screen mode from the WIMP */
Expand Down
4 changes: 2 additions & 2 deletions src/video/riscos/SDL_riscosevents.c
Expand Up @@ -293,7 +293,7 @@ void RISCOS_PollMouseHelper(_THIS, int fullscreen)
if (fullscreen)
{
topLeftX = 0;
topLeftY = (this->hidden->height << this->hidden->yeig) - 1;
topLeftY = this->hidden->screen_height << this->hidden->yeig;
} else
{
int window_state[9];
Expand All @@ -304,7 +304,7 @@ void RISCOS_PollMouseHelper(_THIS, int fullscreen)
_kernel_swi(Wimp_GetWindowState, &regs, &regs);

topLeftX = window_state[1];
topLeftY = window_state[4];
topLeftY = window_state[4] - 2;
}

/* Convert co-ordinates to workspace */
Expand Down
14 changes: 7 additions & 7 deletions src/video/riscos/SDL_riscosmouse.c
Expand Up @@ -188,10 +188,10 @@ void FULLSCREEN_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
int os_x, os_y;
int topLeftY;

topLeftY = (this->hidden->height << this->hidden->yeig) - 1; /* As per RISCOS_PollMouseHelper */
topLeftY = this->hidden->screen_height << this->hidden->yeig; /* As per RISCOS_PollMouseHelper */

os_x = x << this->hidden->xeig;
os_y = topLeftY - (y << this->hidden->yeig);
os_x = x << 1;
os_y = topLeftY - (y << 1);

move_block[0] = 3; /* Move cursor */
move_block[1] = os_x & 0xFF;
Expand Down Expand Up @@ -224,8 +224,8 @@ void WIMP_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
_kernel_swi(Wimp_GetWindowState, &regs, &regs);

/* 90 DPI mapping from SDL pixels to OS units */
osX = (x << 1) + window_state[1];
osY = window_state[4] - (y << 1);
osX = (x << 1) + window_state[1];
osY = (window_state[4] - 2) - (y << 1);

block[0] = 3;
block[1] = osX & 0xFF;
Expand Down Expand Up @@ -258,8 +258,8 @@ SDL_GrabMode RISCOS_GrabInput(_THIS, SDL_GrabMode mode)
{
/* Clip to whole screen */

int r = (this->hidden->screen_width << this->hidden->xeig) - 1;
int t = (this->hidden->screen_height << this->hidden->yeig) - 1;
int r = this->hidden->screen_width << this->hidden->xeig;
int t = this->hidden->screen_height << this->hidden->yeig;

block[1] = 0; block[2] = 0; /* Left*/
block[3] = 0; block[4] = 0; /* Bottom */
Expand Down
10 changes: 5 additions & 5 deletions src/video/riscos/SDL_wimpvideo.c
Expand Up @@ -169,16 +169,16 @@ void WIMP_ReadModeInfo(_THIS)
vars[1] = 5; /* YEig */
vars[2] = 9; /* Log base 2 bpp */
vars[3] = 11; /* Screen Width - 1 */
vars[4] = 12; /* Screen Depth - 1 */
vars[4] = 12; /* Screen Height - 1 */
vars[5] = -1; /* Terminate list */

regs.r[0] = (int)vars;
regs.r[1] = (int)vals;
_kernel_swi(OS_ReadVduVariables, &regs, &regs);
this->hidden->xeig = vals[0];
this->hidden->yeig = vals[1];
this->hidden->screen_width = vals[3] + 1;
this->hidden->screen_height = vals[4] + 1;
this->hidden->screen_width = vals[3];
this->hidden->screen_height = vals[4];
}

/* Set device function to call the correct versions for running
Expand Down Expand Up @@ -214,8 +214,8 @@ unsigned int WIMP_SetupWindow(_THIS, SDL_Surface *surface)
_kernel_oserror *error;
int window_data[23];
int *window_block = window_data+1;
int x = ((this->hidden->screen_width << this->hidden->xeig) - (surface->w << 1)) / 2;
int y = ((this->hidden->screen_height << this->hidden->yeig) - (surface->h << 1)) / 2;
int x = (((this->hidden->screen_width + 1) << this->hidden->xeig) - (surface->w << 1)) / 2;
int y = (((this->hidden->screen_height + 1) << this->hidden->yeig) - (surface->h << 1)) / 2;

/* Always delete the window and recreate on a change */
if (this->hidden->window_handle) WIMP_DeleteWindow(this);
Expand Down

0 comments on commit c412dc9

Please sign in to comment.