📄 win32.cpp
字号:
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 offset1 = srect->top * src->Pitch + srect->left; int offset2 = ((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 + offset1); register uint32 *d = (uint32 *) ((uint8 *) dst->Surface + y * dst->Pitch + offset2); 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 offset1 = srect->top * src->Pitch + srect->left * 2; int offset2 = ((dst->Height - height) >> 1) * dst->Pitch + ((dst->Width - width) >> 1) * sizeof (uint32); for (register int y = 0; y < height; y++) { register uint16 *s = (uint16 *) ((uint8 *) src->Surface + y * src->Pitch + offset1); register uint32 *d = (uint32 *) ((uint8 *) dst->Surface + y * dst->Pitch + offset2); 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 offset1 = srect->top * src->Pitch + srect->left; int offset2 = ((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 + offset1); register uint8 *d = ((uint8 *) dst->Surface + y * dst->Pitch + offset2); #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 offset1 = srect->top * src->Pitch + srect->left * 2; int offset2 = ((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 + offset1); register uint8 *d = ((uint8 *) dst->Surface + y * dst->Pitch + offset2); #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 offset1 = srect->top * src->Pitch + srect->left * 2; int offset2 = ((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 + offset1); register uint8 *d = ((uint8 *) dst->Surface + y * dst->Pitch + offset2); 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 offset1 = srect->top * src->Pitch + srect->left; int offset2 = ((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 + offset1); register uint16 *d = (uint16 *) ((uint8 *) dst->Surface + y * dst->Pitch + offset2); 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); }}static int S9xCompareSDD1IndexEntries (const void *p1, const void *p2){ return (*(uint32 *) p1 - *(uint32 *) p2);}void S9xLoadSDD1Data (){ char filename [_MAX_PATH + 1]; char index [_MAX_PATH + 1]; char data [_MAX_PATH + 1]; Settings.SDD1Pack=FALSE; Memory.FreeSDD1Data (); if (strncmp (Memory.ROMName, TEXT("Star Ocean"), 10) == 0) { if(strlen(GUI.StarOceanPack)!=0) strcpy(filename, GUI.StarOceanPack); else Settings.SDD1Pack=TRUE; } else if(strncmp(Memory.ROMName, TEXT("STREET FIGHTER ALPHA2"), 21)==0) { if(Memory.ROMRegion==1) { if(strlen(GUI.SFA2NTSCPack)!=0) strcpy(filename, GUI.SFA2NTSCPack); else Settings.SDD1Pack=TRUE; } else { if(strlen(GUI.SFA2PALPack)!=0) strcpy(filename, GUI.SFA2PALPack); else Settings.SDD1Pack=TRUE; } } else { if(strlen(GUI.SFZ2Pack)!=0) strcpy(filename, GUI.SFZ2Pack); else Settings.SDD1Pack=TRUE; } if(Settings.SDD1Pack==TRUE) return; strcpy (index, filename); strcat (index, "\\SDD1GFX.IDX"); strcpy (data, filename); strcat (data, "\\SDD1GFX.DAT"); FILE *fs = fopen (index, "rb"); int len = 0; if (fs) { // Index is stored as a sequence of entries, each entry being // 12 bytes consisting of: // 4 byte key: (24bit address & 0xfffff * 16) | translated block // 4 byte ROM offset // 4 byte length fseek (fs, 0, SEEK_END); len = ftell (fs); rewind (fs); Memory.SDD1Index = (uint8 *) malloc (len); fread (Memory.SDD1Index, 1, len, fs); fclose (fs); Memory.SDD1Entries = len / 12; if (!(fs = fopen (data, "rb"))) { free ((char *) Memory.SDD1Index); Memory.SDD1Index = NULL; Memory.SDD1Entries = 0; } else { fseek (fs, 0, SEEK_END); len = ftell (fs); rewind (fs); Memory.SDD1Data = (uint8 *) malloc (len); fread (Memory.SDD1Data, 1, len, fs); fclose (fs); qsort (Memory.SDD1Index, Memory.SDD1Entries, 12, S9xCompareSDD1IndexEntries); } }}bool JustifierOffscreen(){ return (bool)((GUI.MouseButtons&2)!=0);}void JustifierButtons(uint32& justifiers){ if(IPPU.Controller==SNES_JUSTIFIER_2) { if((GUI.MouseButtons&1)||(GUI.MouseButtons&2)) { justifiers|=0x00200; } if(GUI.MouseButtons&4) { justifiers|=0x00800; } } else { if((GUI.MouseButtons&1)||(GUI.MouseButtons&2)) { justifiers|=0x00100; } if(GUI.MouseButtons&4) { justifiers|=0x00400; } }}#ifdef MK_APU_RESAMPLEvoid ResampleTo16000HzM16(uint16* input, uint16*output,int output_samples){ int i=0; for(i=0;i<output_samples;i++) { output[i]=(input[i*2]+input[(2*i)+1])>>1; }}void ResampleTo16000HzS16(uint16* input, uint16*output,int output_samples){ int i=0; for(i=0;i<output_samples;i+=2) { output[i]=(input[i*2]+input[(2*(i+1))])>>1; output[i+1]=(input[(i*2)+1]+input[(2*(i+1))+1])>>1; }}void ResampleTo8000HzM16(uint16* input, uint16*output,int output_samples){ int i=0; for(i=0;i<output_samples;i++) { output[i]=(input[i*4]+input[(4*i)+1]+input[(4*i)+2]+input[(4*i)+3])>>2; }}void ResampleTo8000HzS16(uint16* input, uint16*output,int output_samples){ int i=0; for(i=0;i<output_samples;i+=2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -