From 7dedcf1ab55bb01474729b4045eb5de52c518a1f Mon Sep 17 00:00:00 2001 From: luigi__ Date: Mon, 9 Feb 2009 22:07:49 +0000 Subject: [PATCH] Made the OSD messages totally rotation aware. Thus, for example, when using rotation, the FPS counter doesn't rotate anymore. Also a bit of cleanup (removed some unused funcs in main.cpp). --- desmume/src/GPU_osd.cpp | 85 ++++++++++- desmume/src/GPU_osd.h | 3 + desmume/src/windows/main.cpp | 265 ++++++----------------------------- 3 files changed, 131 insertions(+), 222 deletions(-) diff --git a/desmume/src/GPU_osd.cpp b/desmume/src/GPU_osd.cpp index d64f0b3d7..3eeb9b2cb 100644 --- a/desmume/src/GPU_osd.cpp +++ b/desmume/src/GPU_osd.cpp @@ -54,6 +54,8 @@ OSDCLASS::OSDCLASS(u8 core) startline=0; lastline=0; + rotAngle = 0; + needUpdate = false; if (core==0) @@ -93,6 +95,39 @@ void OSDCLASS::setOffset(u16 ofs) offset=ofs; } +void OSDCLASS::setRotate(u16 angle) +{ + rotAngle = angle; + + switch(rotAngle) + { + case 0: + case 180: + { + screenshell.width = 256; + screenshell.height = 384; + screenshell.pitch = 256; + screenshell.cx1 = 0; + screenshell.cx2 = 255; + screenshell.cy1 = 0; + screenshell.cy2 = 383; + } + break; + case 90: + case 270: + { + screenshell.width = 384; + screenshell.height = 256; + screenshell.pitch = 384; + screenshell.cx1 = 0; + screenshell.cx2 = 383; + screenshell.cy1 = 0; + screenshell.cy2 = 255; + } + break; + } +} + void OSDCLASS::clear() { memset(screen, 0, sizeof(screen)); @@ -109,8 +144,54 @@ void OSDCLASS::setColor(u16 col) void OSDCLASS::update() // don't optimized { if (!needUpdate) return; // don't update if buffer empty (speed up) - memcpy(GPU_screen, GPU_tempScreen, sizeof(GPU_screen)); - u16 *dst=(u16*)GPU_screen; + + int x, y; + u16 *src = (u16*)GPU_tempScreen; + u16 *dst = (u16*)GPU_screen; + + switch(rotAngle) + { + case 0: + for(y = 0; y < 384; y++) + { + for(x = 0; x < 256; x++) + { + dst[x + (y * 256)] = src[x + (y * 256)]; + } + } + break; + + case 90: + for(y = 0; y < 384; y++) + { + for(x = 0; x < 256; x++) + { + dst[(383 - y) + (x * 384)] = src[x + (y * 256)]; + } + } + break; + + case 180: + for(y = 0; y < 384; y++) + { + for(x = 0; x < 256; x++) + { + dst[(255 - x) + ((383 - y) * 256)] = src[x + (y * 256)]; + } + } + break; + + case 270: + for(y = 0; y < 384; y++) + { + for(x = 0; x < 256; x++) + { + dst[y + ((255 - x) * 384)] = src[x + (y * 256)]; + } + } + break; + } + if (mode!=255) dst+=offset*512; diff --git a/desmume/src/GPU_osd.h b/desmume/src/GPU_osd.h index 6af2581d1..d77c5e566 100644 --- a/desmume/src/GPU_osd.h +++ b/desmume/src/GPU_osd.h @@ -36,6 +36,8 @@ private: u64 offset; u8 mode; + u16 rotAngle; + u8 startline; u8 lastline; @@ -56,6 +58,7 @@ public: ~OSDCLASS(); void setOffset(u16 ofs); + void setRotate(u16 angle); void update(); void clear(); void setColor(u16 col); diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index c5b8b7d2c..9d3a64596 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -369,156 +369,6 @@ void SetWindowClientSize(HWND hwnd, int cx, int cy) //found at: http://blogs.msd } } -void ResizingLimit(int wParam, RECT *rc) -{ - u32 width = (rc->right - rc->left); - u32 height = (rc->bottom - rc->top); - - u32 minX = 256; - u32 minY = 414; - - //LOG("width=%i; height=%i\n", width, height); - - if (GPU_rotation == 90 || GPU_rotation == 270) - { - minX = 390; - minY = 272; - } - switch (wParam) - { - case WMSZ_LEFT: - { - if (widthleft=rc->left+(width-minX); - return; - } - - case WMSZ_RIGHT: - { - if (widthright=rc->left+minX; - return; - } - - case WMSZ_TOP: - { - if (heighttop=rc->top+(height-minY); - return; - } - - case WMSZ_BOTTOM: - { - if (heightbottom=rc->top+minY; - return; - } - - case WMSZ_TOPLEFT: - { - if (heighttop=rc->top+(height-minY); - if (widthleft=rc->left+(width-minX); - return; - } - case WMSZ_BOTTOMLEFT: - { - if (heightbottom=rc->top+minY; - if (widthleft=rc->left+(width-minX); - return; - } - - case WMSZ_TOPRIGHT: - { - if (heighttop=rc->top+(height-minY); - if (widthright=rc->left+minX; - return; - } - - case WMSZ_BOTTOMRIGHT: - { - if (heightbottom=rc->top+minY; - if (widthright=rc->left+minX; - return; - } - } - -} - -void ScaleScreen(HWND hwnd, int wParam, RECT *rc) -{ - float aspect; - u32 width; - u32 height; - u32 width2; - u32 height2; - - width = (rc->right - rc->left - widthTradeOff); - height = (rc->bottom - rc->top - heightTradeOff); - - if (width == height) return; - - if (GPU_rotation == 0 || GPU_rotation == 180) - { - aspect = DefaultWidth / DefaultHeight; - } - else - { - aspect = DefaultHeight / DefaultWidth; - } - - switch (wParam) - { - case WMSZ_LEFT: - case WMSZ_RIGHT: - { - height = (int)(width / aspect); - rc->bottom=rc->top+height+heightTradeOff; - return; - } - - case WMSZ_TOP: - case WMSZ_BOTTOM: - { - width = (int)(height * aspect); - rc->right=rc->left+width+widthTradeOff; - return; - } - - case WMSZ_TOPLEFT: - { - width = (int)(height * aspect); - rc->left=rc->right-width-widthTradeOff; - return; - } - case WMSZ_BOTTOMLEFT: - { - height = (int)(width / aspect); - rc->bottom=rc->top + height + heightTradeOff; - return; - } - - case WMSZ_TOPRIGHT: - case WMSZ_BOTTOMRIGHT: - { - width = (int)(height * aspect); - rc->right=rc->left+width+widthTradeOff; - return; - } - } -} - -void ScaleScreen(HWND hwnd, float factor) -{ - - if ((GPU_rotation==0)||(GPU_rotation==180)) - { - SetWindowPos(hwnd, NULL, WndX, WndY, widthTradeOff + DefaultWidth * factor, - heightTradeOff + DefaultHeight * factor, SWP_NOMOVE | SWP_NOZORDER); - } - else - if ((GPU_rotation==90)||(GPU_rotation==270)) - { - SetWindowPos(hwnd, NULL, WndX, WndY, heightTradeOff + DefaultHeight * factor, - widthTradeOff + DefaultWidth * factor, SWP_NOMOVE | SWP_NOZORDER); - } -} - void ScaleScreen(float factor) { if((GPU_rotation == 0) || (GPU_rotation == 180)) @@ -764,72 +614,6 @@ int CreateDDrawBuffers() } - -void applyRotation_0deg(u16 *in, u32 *out, int pitch) -{ - //this is the most normal case so we have a special branch for it - if(pitch==1024) - for(int i=0; i<98304; i++) - out[i] = RGB15TO24_REVERSE(in[i]); - else - { - pitch>>=2; - for(int y=0,i=0;y<384;y++) - { - int dst = y*(pitch); - for(int x=0;x<256;x++) - out[dst++] = RGB15TO24_REVERSE(in[i++]); - } - } - -} - -void applyRotation_90deg(u16 *in, u32 *out, int pitch) -{ - pitch>>=2; - for(int y=0,dst=0;y<256;y++) - { - int i=y+383*256; - for(int x=0;x<384;x++) - { - out[dst++] = RGB15TO24_REVERSE(in[i]); - i -= 256; - } - dst += (pitch-384); - } -} - -void applyRotation_180deg(u16 *in, u32 *out, int pitch) -{ - pitch>>=2; - int i = 256*384-1; - for(int y=0,dst=0;y<384;y++) - { - for(int x=0;x<256;x++) - { - out[dst++] = RGB15TO24_REVERSE(in[i]); - i--; - } - dst += (pitch-256); - } -} - -void applyRotation_270deg(u16 *in, u32 *out, int pitch) -{ - pitch>>=2; - for(int y=0,dst=0;y<256;y++) - { - int i=255-y; - for(int x=0;x<384;x++) - { - out[dst++] = RGB15TO24_REVERSE(in[i]); - i += 256; - } - dst += (pitch-384); - } -} - - void Display() { int res; @@ -847,10 +631,46 @@ void Display() { switch(GPU_rotation) { - case 0: applyRotation_0deg((u16*)GPU_screen,(u32*)buffer,ddsd.lPitch); break; - case 90: applyRotation_90deg((u16*)GPU_screen,(u32*)buffer,ddsd.lPitch); break; - case 180: applyRotation_180deg((u16*)GPU_screen,(u32*)buffer,ddsd.lPitch); break; - case 270: applyRotation_270deg((u16*)GPU_screen,(u32*)buffer,ddsd.lPitch); break; + case 0: + case 180: + { + if(ddsd.lPitch == 1024) + { + for(int i = 0; i < 98304; i++) + ((u32*)buffer)[i] = RGB15TO24_REVERSE(((u16*)GPU_screen)[i]); + } + else + { + for(int y = 0; y < 384; y++) + { + for(int x = 0; x < 256; x++) + ((u32*)buffer)[x] = RGB15TO24_REVERSE(((u16*)GPU_screen)[(y * 384) + x]); + + buffer += (ddsd.lPitch>>2); + } + } + } + break; + case 90: + case 270: + { + if(ddsd.lPitch == 1536) + { + for(int i = 0; i < 98304; i++) + ((u32*)buffer)[i] = RGB15TO24_REVERSE(((u16*)GPU_screen)[i]); + } + else + { + for(int y = 0; y < 256; y++) + { + for(int x = 0; x < 384; x++) + ((u32*)buffer)[x] = RGB15TO24_REVERSE(((u16*)GPU_screen)[(y * 256) + x]); + + buffer += (ddsd.lPitch>>2); + } + } + } + break; } } else @@ -947,6 +767,8 @@ DWORD WINAPI run() InitSpeedThrottle(); + osd->setRotate(GPU_rotation); + if (DirectDrawCreateEx(NULL, (LPVOID*)&lpDDraw, IID_IDirectDraw7, NULL) != DD_OK) { MessageBox(hwnd,"Unable to initialize DirectDraw","Error",MB_OK); @@ -1170,6 +992,7 @@ BOOL LoadROM(char * filename, const char *cflash_disk_image) INFO("Loading %s was successful\n",filename); frameCounter=0; UpdateRecentRoms(filename); + osd->setRotate(GPU_rotation); return TRUE; } INFO("Loading %s FAILED.\n",filename); @@ -1716,6 +1539,8 @@ void SetRotate(HWND hwnd, int rot) break; } + osd->setRotate(rot); + switch (rot) { case 0: