From 3612ceda1108126505df834882d81ef7da796a61 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 9 Nov 2008 23:15:26 +0000 Subject: [PATCH] fix SF [ 2217044 ] Rotation bug - 90 and 270 crash the emu also repair the mouse x/y transform which suffered from similar bugs and rendered rotate modes unusable. change a typo in a function name "releasTouch" --- desmume/src/NDSSystem.cpp | 2 +- desmume/src/NDSSystem.h | 2 +- desmume/src/cli/main.cpp | 2 +- desmume/src/gtk-glade/callbacks_IO.cpp | 2 +- desmume/src/gtk/main.cpp | 2 +- desmume/src/windows/main.cpp | 92 ++++++++------------------ 6 files changed, 32 insertions(+), 70 deletions(-) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 34afe4bd5..7438885dc 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -254,7 +254,7 @@ void NDS_setTouchPos(u16 x, u16 y) MMU.ARM7_REG[0x136] &= 0xBF; } -void NDS_releasTouch(void) +void NDS_releaseTouch(void) { nds.touchX = 0; nds.touchY = 0; diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 8e3af9b6b..fe0e5f3ab 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -186,7 +186,7 @@ BOOL NDS_SetROM(u8 * rom, u32 mask); NDS_header * NDS_getROMHeader(void); void NDS_setTouchPos(u16 x, u16 y); -void NDS_releasTouch(void); +void NDS_releaseTouch(void); int NDS_LoadROM(const char *filename, int bmtype, u32 bmsize, const char *cflash_disk_image_file); diff --git a/desmume/src/cli/main.cpp b/desmume/src/cli/main.cpp index 18359ccfe..9f2944dd6 100644 --- a/desmume/src/cli/main.cpp +++ b/desmume/src/cli/main.cpp @@ -767,7 +767,7 @@ int main(int argc, char ** argv) { if(mouse.down) NDS_setTouchPos(mouse.x, mouse.y); if(mouse.click) { - NDS_releasTouch(); + NDS_releaseTouch(); mouse.click = FALSE; } diff --git a/desmume/src/gtk-glade/callbacks_IO.cpp b/desmume/src/gtk-glade/callbacks_IO.cpp index 2008ebd94..aced287b1 100755 --- a/desmume/src/gtk-glade/callbacks_IO.cpp +++ b/desmume/src/gtk-glade/callbacks_IO.cpp @@ -249,7 +249,7 @@ gboolean on_wDrawScreen_button_press_event (GtkWidget *widget, GdkEventButton gboolean on_wDrawScreen_button_release_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data) { int scr = dyn_CAST(int,user_data); if ((scr==1) ^ ScreenInvert) { - if (click) NDS_releasTouch(); + if (click) NDS_releaseTouch(); click = FALSE; } return TRUE; diff --git a/desmume/src/gtk/main.cpp b/desmume/src/gtk/main.cpp index 6bb43a648..39f039a24 100644 --- a/desmume/src/gtk/main.cpp +++ b/desmume/src/gtk/main.cpp @@ -902,7 +902,7 @@ static gboolean Stylus_Press(GtkWidget *w, GdkEventButton *e, gpointer data) } static gboolean Stylus_Release(GtkWidget *w, GdkEventButton *e, gpointer data) { - if(click) NDS_releasTouch(); + if(click) NDS_releaseTouch(); click = FALSE; return TRUE; } diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 5e8a0e62e..8714b2b13 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -462,27 +462,25 @@ void ScaleScreen(HWND hwnd, float factor) } } -void translateXY(s32 *x, s32*y) +void translateXY(s32& x, s32& y) { - s32 tmp; - switch(GPU_rotation) - { - case 90: - tmp = *x; - *x = *y; - *y = 192*2 -tmp; - break; - case 180: - *x = 256-*x; - *y = 192*2-*y; - break; - case 270: - tmp = *x; - *x = 255-*y; - *y = tmp; - break; - } - *y-=192; + s32 tx=x, ty=y; + switch(GPU_rotation) + { + case 90: + x = ty; + y = 191-tx; + break; + case 180: + x = 255-tx; + y = 383-ty; + y -= 192; + break; + case 270: + x = 255-ty; + y = (tx-192); + break; + } } // END Rotation definitions @@ -562,7 +560,6 @@ void Display() case 90: { u32 start; - memset(buffer,0,384*ddsd.lPitch); for (j=0; j<256; j++) { start=98304+j; @@ -589,7 +586,6 @@ void Display() case 270: { u32 start; - memset(buffer,0,384*ddsd.lPitch); for (j=0; j<256; j++) { start=256-j; @@ -1546,13 +1542,14 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM } return 0; case WM_MOUSEMOVE: + case WM_LBUTTONDOWN: if (wParam & MK_LBUTTON) { RECT r ; s32 x = (s32)((s16)LOWORD(lParam)); s32 y = (s32)((s16)HIWORD(lParam)); GetClientRect(hwnd,&r) ; - /* translate from scaling (screen reoltution to 256x384 or 512x192) */ + // translate from scaling (screen resolution to 256x384 or 512x192) switch (GPU_rotation) { case 0: @@ -1562,13 +1559,13 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM break ; case 90: case 270: - x = (x*512) / (r.right - r.left) ; - y = (y*192) / (r.bottom - r.top) ; + x = (x*384) / (r.right - r.left) ; + y = (y*256) / (r.bottom - r.top) ; break ; } - /* translate for rotation */ + //translate for rotation if (GPU_rotation != 0) - translateXY(&x,&y); + translateXY(x,y); else y-=192; if(x<0) x = 0; else if(x>255) x = 255; @@ -1576,48 +1573,13 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM NDS_setTouchPos(x, y); return 0; } - NDS_releasTouch(); - return 0; - case WM_LBUTTONDOWN: - if(HIWORD(lParam)>=192) - { - RECT r ; - s32 x = (s32)((s16)LOWORD(lParam)); - s32 y = (s32)((s16)HIWORD(lParam)); - GetClientRect(hwnd,&r) ; - /* translate from scaling (screen reoltution to 256x384 or 512x192) */ - switch (GPU_rotation) - { - case 0: - case 180: - x = (x*256) / (r.right - r.left) ; - y = (y*384) / (r.bottom - r.top) ; - break ; - case 90: - case 270: - x = (x*512) / (r.right - r.left) ; - y = (y*192) / (r.bottom - r.top) ; - break ; - } - /* translate for rotation */ - if (GPU_rotation != 0) - translateXY(&x,&y); - else - y-=192; - if(y>=0) - { - SetCapture(hwnd); - if(x<0) x = 0; else if(x>255) x = 255; - if(y<0) y = 0; else if(y>192) y = 192; - NDS_setTouchPos(x, y); - click = TRUE; - } - } + NDS_releaseTouch(); return 0; + case WM_LBUTTONUP: if(click) ReleaseCapture(); - NDS_releasTouch(); + NDS_releaseTouch(); return 0; case WM_COMMAND: