📄 win32.cpp
字号:
} else if (OPENGL_MODE) { GUI.ScreenDepth = 16; GUI.RedShift = 0; GUI.GreenShift = 5; GUI.BlueShift = 11; Settings.SixteenBit = TRUE; } else { GUI.ScreenDepth = DirectX.DDPixelFormat.dwRGBBitCount; if (GUI.ScreenDepth == 15) GUI.ScreenDepth = 16; GUI.RedShift = ffs (DirectX.DDPixelFormat.dwRBitMask); GUI.GreenShift = ffs (DirectX.DDPixelFormat.dwGBitMask); GUI.BlueShift = ffs (DirectX.DDPixelFormat.dwBBitMask); if((DirectX.DDPixelFormat.dwFlags&DDPF_RGB) != 0 && GUI.ScreenDepth == 16 && DirectX.DDPixelFormat.dwRBitMask == 0xF800 && DirectX.DDPixelFormat.dwGBitMask == 0x07E0 && DirectX.DDPixelFormat.dwBBitMask == 0x001F) { S9xSetRenderPixelFormat (RGB565); Init_2xSaI (565); } else if( (DirectX.DDPixelFormat.dwFlags&DDPF_RGB) != 0 && GUI.ScreenDepth == 16 && DirectX.DDPixelFormat.dwRBitMask == 0x7C00 && DirectX.DDPixelFormat.dwGBitMask == 0x03E0 && DirectX.DDPixelFormat.dwBBitMask == 0x001F) { S9xSetRenderPixelFormat (RGB555); Init_2xSaI (555); } else if((DirectX.DDPixelFormat.dwFlags&DDPF_RGB) != 0 && GUI.ScreenDepth == 16 && DirectX.DDPixelFormat.dwRBitMask == 0x001F && DirectX.DDPixelFormat.dwGBitMask == 0x07E0 && DirectX.DDPixelFormat.dwBBitMask == 0xF800) { S9xSetRenderPixelFormat (BGR565); Init_2xSaI (565); } else if( (DirectX.DDPixelFormat.dwFlags&DDPF_RGB) != 0 && GUI.ScreenDepth == 16 && DirectX.DDPixelFormat.dwRBitMask == 0x001F && DirectX.DDPixelFormat.dwGBitMask == 0x03E0 && DirectX.DDPixelFormat.dwBBitMask == 0x7C00) { S9xSetRenderPixelFormat (BGR555); Init_2xSaI (555); } else if (DirectX.DDPixelFormat.dwRGBBitCount == 8 || DirectX.DDPixelFormat.dwRGBBitCount == 24 || DirectX.DDPixelFormat.dwRGBBitCount == 32) { S9xSetRenderPixelFormat (RGB565); Init_2xSaI (565); } if (!VOODOO_MODE && !OPENGL_MODE && ((GUI.ScreenDepth == 8 && Settings.SixteenBit) || (GUI.ScreenDepth == 16 && !Settings.SixteenBit) || GUI.ScreenDepth == 24 || GUI.ScreenDepth == 32)) GUI.NeedDepthConvert = TRUE; if (Settings.SixteenBit && (GUI.ScreenDepth == 24 || GUI.ScreenDepth == 32)) { GUI.RedShift += 3; GUI.GreenShift += 3; GUI.BlueShift += 3; } } int l = 0; int i; for (i = 0; i < 6; i++) { int r = (i * 31) / (6 - 1); for (int j = 0; j < 6; j++) { int g = (j * 31) / (6 - 1); for (int k = 0; k < 6; k++) { int b = (k * 31) / (6 - 1); FixedColours [l].red = r << 3; FixedColours [l].green = g << 3; FixedColours [l++].blue = b << 3; } } } int *color_diff = new int [0x10000]; int diffr, diffg, diffb, maxdiff = 0, won = 0, lost; int r, d = 8; for (r = 0; r <= (int) MAX_RED; r++) { int cr, g, q; int k = 6 - 1; cr = (r * k) / MAX_RED; q = (r * k) % MAX_RED; if (q > d && cr < k) cr++; diffr = abs (cr * k - r); for (g = 0; g <= (int) MAX_GREEN; g++) { int cg, b; k = 6 - 1; cg = (g * k) / MAX_GREEN; q = (g * k) % MAX_GREEN; if(q > d && cg < k) cg++; diffg = abs (cg * k - g); for (b = 0; b <= (int) MAX_BLUE; b++) { int cb; int rgb = BUILD_PIXEL2(r, g, b); k = 6 - 1; cb = (b * k) / MAX_BLUE; q = (b * k) % MAX_BLUE; if (q > d && cb < k) cb++; diffb = abs (cb * k - b); palette[rgb] = (cr * 6 + cg) * 6 + cb; color_diff[rgb] = diffr + diffg + diffb; if (color_diff[rgb] > maxdiff) maxdiff = color_diff[rgb]; } } } while (maxdiff > 0 && l < 256) { int newmaxdiff = 0; lost = 0; won++; for (r = MAX_RED; r >= 0; r--) { int g; for (g = MAX_GREEN; g >= 0; g--) { int b; for (b = MAX_BLUE; b >= 0; b--) { int rgb = BUILD_PIXEL2(r, g, b); if (color_diff[rgb] == maxdiff) { if (l >= 256) lost++; else { FixedColours [l].red = r << 3; FixedColours [l].green = g << 3; FixedColours [l].blue = b << 3; palette [rgb] = l++; } color_diff[rgb] = 0; } else if (color_diff[rgb] > newmaxdiff) newmaxdiff = color_diff[rgb]; } } } maxdiff = newmaxdiff; } delete color_diff;}void Convert8To24 (SSurface *src, SSurface *dst, RECT *srect){ uint32 brightness = IPPU.MaxBrightness >> 1; uint32 conv [256]; int height = srect->bottom - srect->top; int width = srect->right - srect->left; int offset = ((dst->Height - height) >> 1) * dst->Pitch + ((dst->Width - width) >> 1) * sizeof (uint32); for (int p = 0; p < 256; p++) { uint32 pixel = PPU.CGDATA [p]; conv [p] = (((pixel & 0x1f) * brightness) << GUI.RedShift) | ((((pixel >> 5) & 0x1f) * brightness) << GUI.GreenShift) | ((((pixel >> 10) & 0x1f) * brightness) << GUI.BlueShift); } for (register int y = 0; y < height; y++) { register uint8 *s = ((uint8 *) src->Surface + y * src->Pitch); register uint32 *d = (uint32 *) ((uint8 *) dst->Surface + y * dst->Pitch + offset); for (register int x = 0; x < width; x++) *d++ = conv [PPU.CGDATA [*s++]]; }}void Convert16To24 (SSurface *src, SSurface *dst, RECT *srect){ int height = srect->bottom - srect->top; int width = srect->right - srect->left; int offset = ((dst->Height - height) >> 1) * dst->Pitch + ((dst->Width - width) >> 1) * sizeof (uint32); for (register int y = 0; y < height; y++) { register uint16 *s = ((uint16 *) src->Surface + y * src->Pitch); register uint32 *d = (uint32 *) ((uint8 *) dst->Surface + y * dst->Pitch + offset); for (register int x = 0; x < width; x++) { uint32 pixel = *s++; *d++ = (((pixel >> 11) & 0x1f) << GUI.RedShift) | (((pixel >> 6) & 0x1f) << GUI.GreenShift) | ((pixel & 0x1f) << GUI.BlueShift); } }}void Convert8To24Packed (SSurface *src, SSurface *dst, RECT *srect){ uint32 brightness = IPPU.MaxBrightness >> 1; uint8 levels [32]; int height = srect->bottom - srect->top; int width = srect->right - srect->left; int offset = ((dst->Height - height) >> 1) * dst->Pitch + ((dst->Width - width) >> 1) * 3; for (int l = 0; l < 32; l++) levels [l] = l * brightness; for (register int y = 0; y < height; y++) { register uint8 *s = ((uint8 *) src->Surface + y * src->Pitch); register uint8 *d = ((uint8 *) dst->Surface + y * dst->Pitch + offset); #ifdef LSB_FIRST if (GUI.RedShift < GUI.BlueShift)#else if (GUI.RedShift > GUI.BlueShift)#endif { // Order is RGB for (register int x = 0; x < width; x++) { uint16 pixel = PPU.CGDATA [*s++]; *(d + 0) = levels [(pixel & 0x1f)]; *(d + 1) = levels [((pixel >> 5) & 0x1f)]; *(d + 2) = levels [((pixel >> 10) & 0x1f)]; d += 3; } } else { // Order is BGR for (register int x = 0; x < width; x++) { uint16 pixel = PPU.CGDATA [*s++]; *(d + 0) = levels [((pixel >> 10) & 0x1f)]; *(d + 1) = levels [((pixel >> 5) & 0x1f)]; *(d + 2) = levels [(pixel & 0x1f)]; d += 3; } } }}void Convert16To24Packed (SSurface *src, SSurface *dst, RECT *srect){ int height = srect->bottom - srect->top; int width = srect->right - srect->left; int offset = ((dst->Height - height) >> 1) * dst->Pitch + ((dst->Width - width) >> 1) * 3; for (register int y = 0; y < height; y++) { register uint16 *s = (uint16 *) ((uint8 *) src->Surface + y * src->Pitch); register uint8 *d = ((uint8 *) dst->Surface + y * dst->Pitch + offset); #ifdef LSB_FIRST if (GUI.RedShift < GUI.BlueShift)#else if (GUI.RedShift > GUI.BlueShift)#endif { // Order is RGB for (register int x = 0; x < width; x++) { uint32 pixel = *s++; *(d + 0) = (pixel >> (11 - 3)) & 0xf8; *(d + 1) = (pixel >> (6 - 3)) & 0xf8; *(d + 2) = (pixel & 0x1f) << 3; d += 3; } } else { // Order is BGR for (register int x = 0; x < width; x++) { uint32 pixel = *s++; *(d + 0) = (pixel & 0x1f) << 3; *(d + 1) = (pixel >> (6 - 3)) & 0xf8; *(d + 2) = (pixel >> (11 - 3)) & 0xf8; d += 3; } } }}void Convert16To8 (SSurface *src, SSurface *dst, RECT *srect){ int height = srect->bottom - srect->top; int width = srect->right - srect->left; int offset = ((dst->Height - height) >> 1) * dst->Pitch + ((dst->Width - width) >> 1); for (register int y = 0; y < height; y++) { register uint16 *s = (uint16 *) ((uint8 *) src->Surface + y * src->Pitch); register uint8 *d = ((uint8 *) dst->Surface + y * dst->Pitch + offset); for (register int x = 0; x < width; x++) *d++ = palette [*s++]; }}void Convert8To16 (SSurface *src, SSurface *dst, RECT *srect){ uint32 levels [32]; uint32 conv [256]; int height = srect->bottom - srect->top; int width = srect->right - srect->left; int offset = ((dst->Height - height) >> 1) * dst->Pitch + ((dst->Width - width) >> 1) * sizeof (uint16); for (int l = 0; l < 32; l++) levels [l] = (l * IPPU.MaxBrightness) >> 4; for (int p = 0; p < 256; p++) { uint32 pixel = PPU.CGDATA [p]; conv [p] = (levels [pixel & 0x1f] << GUI.RedShift) | (levels [(pixel >> 5) & 0x1f] << GUI.GreenShift) | (levels [(pixel >> 10) & 0x1f] << GUI.BlueShift); } for (register int y = 0; y < height; y++) { register uint8 *s = ((uint8 *) src->Surface + y * src->Pitch); register uint16 *d = (uint16 *) ((uint8 *) dst->Surface + y * dst->Pitch + offset); for (register int x = 0; x < width; x += 2) { *(uint32 *) d = conv [*s] | (conv [*(s + 1)] << 16); s += 2; d += 2; } }}void ConvertDepth (SSurface *src, SSurface *dst, RECT *srect){ if (Settings.SixteenBit) { // SNES image has been rendered in 16-bit, RGB565 format switch (GUI.ScreenDepth) { case 8: Convert16To8 (src, dst, srect); break; case 15: case 16: break; case 24: Convert16To24Packed (src, dst, srect); break; case 32: Convert16To24 (src, dst, srect); break; } } else { // SNES image has been rendered only in 8-bits switch (GUI.ScreenDepth) { case 8: break; case 15: case 16: Convert8To16 (src, dst, srect); break; case 24: Convert8To24Packed (src, dst, srect); break; case 32: Convert8To24 (src, dst, srect); break; } } srect->left = (dst->Width - src->Width) >> 1; srect->right = srect->left + src->Width; srect->top = (dst->Height - src->Height) >> 1; srect->bottom = srect->top + src->Height;}void S9xAutoSaveSRAM (){ Memory.SaveSRAM (S9xGetFilename (".srm"));}void S9xSetPause (uint32 mask){ Settings.ForcedPause |= mask;}void S9xClearPause (uint32 mask){ Settings.ForcedPause &= ~mask; if (!Settings.ForcedPause) { // Wake up the main loop thread just if its blocked in a GetMessage // call. PostMessage (GUI.hWnd, WM_NULL, 0, 0); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -