diff options
author | neonloop | 2021-04-03 00:39:16 +0000 |
---|---|---|
committer | neonloop | 2021-04-03 00:39:16 +0000 |
commit | 92c860d1d31e4fcaaf978d7fb5fd93b657b51ee4 (patch) | |
tree | 5026ec21d6f5770122e23142e8abd4ba88cf6131 | |
parent | 08ba753083031def20d86a6b7daff1754a4d3c8a (diff) | |
parent | e2303a4166ec3b78219115c18a0113e24fa48cf6 (diff) | |
download | snesemu-92c860d1d31e4fcaaf978d7fb5fd93b657b51ee4.tar.gz snesemu-92c860d1d31e4fcaaf978d7fb5fd93b657b51ee4.tar.bz2 snesemu-92c860d1d31e4fcaaf978d7fb5fd93b657b51ee4.zip |
Merge branch 'eggs-improvements' into trimui-s
-rw-r--r-- | shell/audio/sdl/sound_output.c | 4 | ||||
-rw-r--r-- | shell/emu/core.c | 2 | ||||
-rw-r--r-- | shell/headers/shared.h | 2 | ||||
-rw-r--r-- | shell/menu/config.h | 1 | ||||
-rw-r--r-- | shell/menu/menu.c | 81 | ||||
-rw-r--r-- | shell/scalers/scaler.c | 58 | ||||
-rw-r--r-- | shell/scalers/scaler.h | 3 | ||||
-rw-r--r-- | shell/video/sdl/video_blit.c | 30 | ||||
-rw-r--r-- | source/gfx.c | 52 | ||||
-rw-r--r-- | source/gfx.h | 1 | ||||
-rw-r--r-- | source/ppu.c | 2 | ||||
-rw-r--r-- | source/ppu.h | 2 |
12 files changed, 188 insertions, 50 deletions
diff --git a/shell/audio/sdl/sound_output.c b/shell/audio/sdl/sound_output.c index 0758718..0e0d504 100644 --- a/shell/audio/sdl/sound_output.c +++ b/shell/audio/sdl/sound_output.c @@ -7,7 +7,7 @@ #include "sound_output.h" -#define UNDERRUN_THRESHOLD 0.5 +#define UNDERRUN_THRESHOLD 0.75 static int32_t BUFFSIZE; static uint8_t *buffer; @@ -63,7 +63,7 @@ uint32_t Audio_Init() { SDL_AudioSpec aspec, obtained; - BUFFSIZE = (SOUND_SAMPLES_SIZE * 2 * 2) * 4; + BUFFSIZE = (SOUND_SAMPLES_SIZE * 2 * 2) * 8; buffer = (uint8_t *) malloc(BUFFSIZE); /* Add some silence to the buffer */ diff --git a/shell/emu/core.c b/shell/emu/core.c index d4ff19d..f53def5 100644 --- a/shell/emu/core.c +++ b/shell/emu/core.c @@ -275,7 +275,7 @@ static const uint32_t TblSkip[4][4] = { #endif #ifdef AUDIO_FRAMESKIP -#define MAX_SKIP_COUNT 3 +#define MAX_SKIP_COUNT 4 static uint32_t SkipCnt = 0; #endif diff --git a/shell/headers/shared.h b/shell/headers/shared.h index 0ceff9d..e16ac07 100644 --- a/shell/headers/shared.h +++ b/shell/headers/shared.h @@ -6,7 +6,7 @@ #define SOUND_SAMPLES_SIZE 1024 #elif defined(TRIMUI) #define SOUND_OUTPUT_FREQUENCY 32000 -#define SOUND_SAMPLES_SIZE 1024 +#define SOUND_SAMPLES_SIZE 512 #elif defined(RS97) #define SOUND_OUTPUT_FREQUENCY 22050 #define SOUND_SAMPLES_SIZE 1024 diff --git a/shell/menu/config.h b/shell/menu/config.h index 9b71fc2..dfe4b6e 100644 --- a/shell/menu/config.h +++ b/shell/menu/config.h @@ -5,6 +5,7 @@ typedef struct { int32_t fullscreen; /* For input remapping */ uint32_t config_buttons[6][19]; + int32_t showfps; } t_config; extern t_config option; diff --git a/shell/menu/menu.c b/shell/menu/menu.c index 9db4539..7dcf229 100644 --- a/shell/menu/menu.c +++ b/shell/menu/menu.c @@ -34,7 +34,7 @@ extern void SRAM_Save(char* path, uint_fast8_t state); static uint8_t selectpressed = 0; static uint8_t save_slot = 0; -static const int8_t upscalers_available = 2 +static const int8_t upscalers_available = 4 #ifdef SCALE2X_UPSCALER +1 #endif @@ -93,7 +93,8 @@ static void config_load() option.config_buttons[0][10] = BTN_START; option.config_buttons[0][11] = BTN_SELECT; - option.fullscreen = 0; + option.fullscreen = 3; + option.showfps = 0; } } @@ -355,7 +356,7 @@ void Menu() SRAM_Menu(0); RTC_Menu(0); - while (((currentselection != 1) && (currentselection != 6)) || (!pressed)) + while (((currentselection != 1) && (currentselection != 7) && (currentselection != 8)) || (!pressed)) { pressed = 0; @@ -363,34 +364,39 @@ void Menu() print_string("SNESEmu - Built on " __DATE__, TextWhite, 0, 5, 15, backbuffer->pixels); - if (currentselection == 1) print_string("Continue", TextRed, 0, 5, 45, backbuffer->pixels); - else print_string("Continue", TextWhite, 0, 5, 45, backbuffer->pixels); +#define MENU_Y(y) 29 + (18*y) + + if (currentselection == 1) print_string("Continue", TextRed, 0, 5, MENU_Y(1), backbuffer->pixels); + else print_string("Continue", TextWhite, 0, 5, MENU_Y(1), backbuffer->pixels); snprintf(text, sizeof(text), "Load State %d", save_slot); - if (currentselection == 2) print_string(text, TextRed, 0, 5, 65, backbuffer->pixels); - else print_string(text, TextWhite, 0, 5, 65, backbuffer->pixels); + if (currentselection == 2) print_string(text, TextRed, 0, 5, MENU_Y(2), backbuffer->pixels); + else print_string(text, TextWhite, 0, 5, MENU_Y(2), backbuffer->pixels); snprintf(text, sizeof(text), "Save State %d", save_slot); - if (currentselection == 3) print_string(text, TextRed, 0, 5, 85, backbuffer->pixels); - else print_string(text, TextWhite, 0, 5, 85, backbuffer->pixels); + if (currentselection == 3) print_string(text, TextRed, 0, 5, MENU_Y(3), backbuffer->pixels); + else print_string(text, TextWhite, 0, 5, MENU_Y(3), backbuffer->pixels); if (currentselection == 4) { switch(option.fullscreen) { case 0: - print_string("Scaling : Native", TextRed, 0, 5, 105, backbuffer->pixels); + print_string("Scaling : Native", TextRed, 0, 5, MENU_Y(4), backbuffer->pixels); break; case 1: - print_string("Scaling : Stretched", TextRed, 0, 5, 105, backbuffer->pixels); + print_string("Scaling : FS Sharp", TextRed, 0, 5, MENU_Y(4), backbuffer->pixels); break; case 2: - print_string("Scaling : Bilinear", TextRed, 0, 5, 105, backbuffer->pixels); + print_string("Scaling : FS Smooth", TextRed, 0, 5, MENU_Y(4), backbuffer->pixels); break; case 3: - print_string("Scaling : EPX/Scale2x", TextRed, 0, 5, 105, backbuffer->pixels); + print_string("Scaling : Bilinear", TextRed, 0, 5, MENU_Y(4), backbuffer->pixels); + break; + case 4: + print_string("Scaling : Overscan", TextRed, 0, 5, MENU_Y(4), backbuffer->pixels); break; } } @@ -399,25 +405,36 @@ void Menu() switch(option.fullscreen) { case 0: - print_string("Scaling : Native", TextWhite, 0, 5, 105, backbuffer->pixels); + print_string("Scaling : Native", TextWhite, 0, 5, MENU_Y(4), backbuffer->pixels); break; case 1: - print_string("Scaling : Stretched", TextWhite, 0, 5, 105, backbuffer->pixels); + print_string("Scaling : FS Sharp", TextWhite, 0, 5, MENU_Y(4), backbuffer->pixels); break; case 2: - print_string("Scaling : Bilinear", TextWhite, 0, 5, 105, backbuffer->pixels); + print_string("Scaling : FS Smooth", TextWhite, 0, 5, MENU_Y(4), backbuffer->pixels); break; case 3: - print_string("Scaling : EPX/Scale2x", TextWhite, 0, 5, 105, backbuffer->pixels); + print_string("Scaling : Bilinear", TextWhite, 0, 5, MENU_Y(4), backbuffer->pixels); + break; + case 4: + print_string("Scaling : Overscan", TextWhite, 0, 5, MENU_Y(4), backbuffer->pixels); break; } } - if (currentselection == 5) print_string("Input remapping", TextRed, 0, 5, 125, backbuffer->pixels); - else print_string("Input remapping", TextWhite, 0, 5, 125, backbuffer->pixels); + if (option.showfps == 0) snprintf(text, sizeof(text), "Show FPS : OFF"); + else snprintf(text, sizeof(text), "Show FPS : ON"); + if (currentselection == 5) print_string(text, TextRed, 0, 5, MENU_Y(5), backbuffer->pixels); + else print_string(text, TextWhite, 0, 5, MENU_Y(5), backbuffer->pixels); - if (currentselection == 6) print_string("Quit", TextRed, 0, 5, 145, backbuffer->pixels); - else print_string("Quit", TextWhite, 0, 5, 145, backbuffer->pixels); + if (currentselection == 6) print_string("Input remapping", TextRed, 0, 5, MENU_Y(6), backbuffer->pixels); + else print_string("Input remapping", TextWhite, 0, 5, MENU_Y(6), backbuffer->pixels); + + if (currentselection == 7) print_string("Reset", TextRed, 0, 5, MENU_Y(7), backbuffer->pixels); + else print_string("Reset", TextWhite, 0, 5, MENU_Y(7), backbuffer->pixels); + + if (currentselection == 8) print_string("Quit", TextRed, 0, 5, MENU_Y(8), backbuffer->pixels); + else print_string("Quit", TextWhite, 0, 5, MENU_Y(8), backbuffer->pixels); print_string("Libretro Fork by gameblabla", TextWhite, 0, 5, 205, backbuffer->pixels); print_string("Credits: Snes9x dev team, libretro", TextWhite, 0, 5, 225, backbuffer->pixels); @@ -431,11 +448,11 @@ void Menu() case BTN_UP: currentselection--; if (currentselection == 0) - currentselection = 6; + currentselection = 8; break; case BTN_DOWN: currentselection++; - if (currentselection == 7) + if (currentselection == 9) currentselection = 1; break; case BTN_L2: @@ -460,6 +477,9 @@ void Menu() if (option.fullscreen < 0) option.fullscreen = upscalers_available; break; + case 5: + option.showfps ^= 1; + break; } break; case BTN_RIGHT: @@ -476,6 +496,9 @@ void Menu() if (option.fullscreen > upscalers_available) option.fullscreen = 0; break; + case 5: + option.showfps ^= 1; + break; } break; default: @@ -484,7 +507,7 @@ void Menu() } else if (Event.type == SDL_QUIT) { - currentselection = 6; + currentselection = 8; pressed = 1; } } @@ -493,9 +516,15 @@ void Menu() { switch(currentselection) { - case 5: + case 7: + S9xReset(); + break; + case 6: Input_Remapping(); break; + case 5: + option.showfps ^= 1; + break; case 4 : option.fullscreen++; if (option.fullscreen > upscalers_available) @@ -524,7 +553,7 @@ void Menu() SDL_Flip(sdl_screen); #endif - if (currentselection == 6) + if (currentselection == 8) { exit_snes = 1; } diff --git a/shell/scalers/scaler.c b/shell/scalers/scaler.c index 81644aa..6bd7a4f 100644 --- a/shell/scalers/scaler.c +++ b/shell/scalers/scaler.c @@ -27,6 +27,48 @@ // Halves
#define Weight1_1(A, B) (Half(A) + Half(B) + Corr1_1(A, B))
+#define AVERAGE16(c1, c2) (((c1) + (c2) + (((c1) ^ (c2)) & 0x0821))>>1) //More accurate
+
+void upscale_240x208_to_320x240(uint16_t *dst, uint16_t *src, uint32_t width)
+{
+ int Eh = 0;
+ int dh = 8;
+ int vf = 0;
+
+ for (int y = 0; y < 240; y++)
+ {
+ int source = dh * width + 8;
+ for (int x = 0; x < 320/4; x++)
+ {
+ register uint16_t a, b, c;
+
+ a = src[source];
+ b = src[source+1];
+ c = src[source+2];
+
+ if(vf == 1){
+ a = AVERAGE16(a, src[source+width]);
+ b = AVERAGE16(b, src[source+width+1]);
+ c = AVERAGE16(c, src[source+width+2]);
+ }
+ *dst++ = a;
+ *dst++ = (AVERAGE16(a,b) & 0b0000000000011111) | (b & 0b1111111111100000);
+ *dst++ = (b & 0b0000011111111111) | (AVERAGE16(b,c) & 0b1111100000000000);
+ *dst++ = c;
+ source+=3;
+
+ }
+ Eh += 208;
+ if(Eh >= 240) {
+ Eh -= 240;
+ dh++;
+ vf = 0;
+ }
+ else
+ vf = 1;
+ }
+}
+
void upscale_256x240_to_320x240_bilinearish(uint32_t* restrict dst, uint32_t* restrict src, uint_fast16_t width, uint_fast16_t height)
{
@@ -35,8 +77,9 @@ void upscale_256x240_to_320x240_bilinearish(uint32_t* restrict dst, uint32_t* re // There are 64 blocks of 4 pixels horizontally, and 239 of 1 vertically.
// Each block of 4x1 becomes 5x1.
uint32_t BlockX, BlockY;
- uint16_t* BlockSrc;
- uint16_t* BlockDst;
+ register uint16_t _1,_2,_3,_4;
+ register uint16_t* BlockSrc;
+ register uint16_t* BlockDst;
for (BlockY = 0; BlockY < height; BlockY++)
{
BlockSrc = Src16 + BlockY * width * 1;
@@ -51,13 +94,13 @@ void upscale_256x240_to_320x240_bilinearish(uint32_t* restrict dst, uint32_t* re */
// -- Row 1 --
- uint16_t _1 = *(BlockSrc );
+ _1 = *(BlockSrc );
*(BlockDst ) = _1;
- uint16_t _2 = *(BlockSrc + 1);
+ _2 = *(BlockSrc + 1);
*(BlockDst + 1) = Weight1_3( _1, _2);
- uint16_t _3 = *(BlockSrc + 2);
+ _3 = *(BlockSrc + 2);
*(BlockDst + 2) = Weight1_1( _2, _3);
- uint16_t _4 = *(BlockSrc + 3);
+ _4 = *(BlockSrc + 3);
*(BlockDst + 3) = Weight3_1( _3, _4);
*(BlockDst + 4) = _4;
@@ -67,9 +110,8 @@ void upscale_256x240_to_320x240_bilinearish(uint32_t* restrict dst, uint32_t* re }
}
-void upscale_256xXXX_to_320x240(uint32_t* restrict dst, uint32_t* restrict src, uint_fast16_t width, uint_fast16_t height)
+void upscale_256xXXX_to_320x240(uint32_t* restrict dst, uint32_t* restrict src, uint_fast16_t width, uint_fast16_t height, uint32_t midh)
{
- uint32_t midh = 240 / 2;
uint32_t Eh = 0;
uint32_t source;
uint32_t dh = 0;
diff --git a/shell/scalers/scaler.h b/shell/scalers/scaler.h index f220800..b2ed1f0 100644 --- a/shell/scalers/scaler.h +++ b/shell/scalers/scaler.h @@ -5,7 +5,8 @@ /* Generic */
extern void bitmap_scale(uint32_t startx, uint32_t starty, uint32_t viswidth, uint32_t visheight, uint32_t newwidth, uint32_t newheight,uint32_t pitchsrc,uint32_t pitchdest, uint16_t* restrict src, uint16_t* restrict dst);
-extern void upscale_256xXXX_to_320x240(uint32_t* restrict dst, uint32_t* restrict src, uint_fast16_t width, uint_fast16_t height);
+extern void upscale_256xXXX_to_320x240(uint32_t* restrict dst, uint32_t* restrict src, uint_fast16_t width, uint_fast16_t height, uint32_t midh);
extern void upscale_256x240_to_320x240_bilinearish(uint32_t* restrict dst, uint32_t* restrict src, uint_fast16_t width, uint_fast16_t height);
+extern void upscale_240x208_to_320x240(uint16_t *dst, uint16_t *src, uint32_t width);
#endif
diff --git a/shell/video/sdl/video_blit.c b/shell/video/sdl/video_blit.c index 6a8f748..3e6a0a3 100644 --- a/shell/video/sdl/video_blit.c +++ b/shell/video/sdl/video_blit.c @@ -87,23 +87,35 @@ void Update_Video_Ingame() uint16_t *s, *d; uint32_t h, w; uint8_t PAL = !!(Memory.FillRAM[0x2133] & 4); + uint32_t width = IPPU.RenderedScreenWidth; + uint32_t height = IPPU.RenderedScreenHeight; + if (height == SNES_HEIGHT_EXTENDED) height++; // 239 to 240 SDL_LockSurface(sdl_screen); switch(option.fullscreen) { - case 0: - s = (uint16_t*) GFX.Screen; - d = (uint16_t*) sdl_screen->pixels + ((sdl_screen->w - IPPU.RenderedScreenWidth)/2 + (sdl_screen->h - IPPU.RenderedScreenHeight) * 160) - (PAL ? 0 : 2*320); - for(uint8_t y = 0; y < IPPU.RenderedScreenHeight; y++, s += IPPU.RenderedScreenWidth, d += sdl_screen->w) memmove(d, s, IPPU.RenderedScreenWidth * 2); + case 0: // Native + s = (uint16_t*) GFX.Screen; + d = (uint16_t*) sdl_screen->pixels + ((sdl_screen->w - width)/2 + (sdl_screen->h - height) * 160) - (PAL ? 0 : 2*320); + for(uint8_t y = 0; y < height; y++, s += width, d += sdl_screen->w) memmove(d, s, width * 2); break; - case 1: - upscale_256xXXX_to_320x240((uint32_t*) sdl_screen->pixels, (uint32_t*) GFX.Screen, IPPU.RenderedScreenWidth, PAL ? 240 : 224); + case 1: // FS Sharp + upscale_256xXXX_to_320x240((uint32_t*) sdl_screen->pixels, (uint32_t*) GFX.Screen, width, height, height); break; - case 2: - if (IPPU.RenderedScreenHeight == 240) upscale_256x240_to_320x240_bilinearish((uint32_t*) sdl_screen->pixels, (uint32_t*) GFX.Screen, IPPU.RenderedScreenWidth, 239); - else upscale_256x240_to_320x240_bilinearish((uint32_t*) sdl_screen->pixels + (160*8), (uint32_t*) GFX.Screen, IPPU.RenderedScreenWidth, 224); + case 2: // FS Smooth + upscale_256xXXX_to_320x240((uint32_t*) sdl_screen->pixels, (uint32_t*) GFX.Screen, width, height, 240/2); break; + case 3: // Bilinear + if (height == 240) + upscale_256x240_to_320x240_bilinearish((uint32_t*) sdl_screen->pixels, (uint32_t*) GFX.Screen, width, 239); + else upscale_256x240_to_320x240_bilinearish((uint32_t*) sdl_screen->pixels + (160*8), (uint32_t*) GFX.Screen, width, 224); + break; + case 4: // Overscan + if (height == 240) + upscale_240x208_to_320x240((uint16_t*) sdl_screen->pixels, (uint16_t*) GFX.Screen + (width*8), width); + else upscale_240x208_to_320x240((uint16_t*) sdl_screen->pixels, (uint16_t*) GFX.Screen, width); + break; } //bitmap_scale(0, 0, IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, sdl_screen->w, sdl_screen->h, SNES_WIDTH*2, 0, GFX.Screen, sdl_screen->pixels); diff --git a/source/gfx.c b/source/gfx.c index 0cf0ac8..a17f80c 100644 --- a/source/gfx.c +++ b/source/gfx.c @@ -9,6 +9,7 @@ #include "gfx.h" #include "apu.h" #include "cheats.h" +#include "config.h" #include <retro_inline.h> @@ -344,6 +345,7 @@ void S9xStartScreenRefresh(void) GFX.ZPitch = GFX.RealPitch; GFX.ZPitch >>= 1; } + IPPU.RenderedFramesCount++; } PPU.RecomputeClipWindows = true; @@ -351,8 +353,11 @@ void S9xStartScreenRefresh(void) GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1; } - if (++IPPU.FrameCount % Memory.ROMFramesPerSecond == 0) - IPPU.FrameCount = 0; + if (++IPPU.FrameCount % Memory.ROMFramesPerSecond == 0) { + IPPU.DisplayedRenderedFrameCount = IPPU.RenderedFramesCount; + IPPU.RenderedFramesCount = 0; + IPPU.FrameCount = 0; + } } void RenderLine(uint8_t C) @@ -415,6 +420,8 @@ void S9xEndScreenRefresh(void) GFX.Pitch = GFX.Pitch2 = GFX.RealPitch; GFX.PPL = GFX.PPLx2 >> 1; + + if (option.showfps == 1) S9xDisplayFrameRate(); } #ifdef LAGFIX finishedFrame = true; @@ -3207,3 +3214,44 @@ void S9xUpdateScreen(void) #endif IPPU.PreviousLine = IPPU.CurrentLine; } + +#include "font.h" + +void DisplayChar(uint8_t* Screen, uint8_t c) +{ + int line = (((c & 0x7f) - 32) >> 4) * font_height; + int offset = (((c & 0x7f) - 32) & 15) * font_width; + int h, w; + uint16_t* s = (uint16_t*) Screen; + for (h = 0; h < font_height; h++, line++, + s += IPPU.RenderedScreenWidth - font_width) + { + for (w = 0; w < font_width; w++, s++) + { + uint8_t p = font [line][offset + w]; + + if (p == '#') + *s = 0xffff; + else if (p == '.') + *s = BLACK; + } + } +} + +void S9xDisplayFrameRate() +{ + char string[16]; + uint8_t *Screen = GFX.Screen; +#ifdef TRIMUI + if (option.fullscreen == 4) { // for Overscan + Screen += IPPU.RenderedScreenWidth * 16 +16; + if (IPPU.RenderedScreenHeight == SNES_HEIGHT_EXTENDED) Screen += IPPU.RenderedScreenWidth * 16; + } +#endif + sprintf(string, "%02d/%02d", IPPU.DisplayedRenderedFrameCount, (int)Memory.ROMFramesPerSecond); + + for (int i = 0; i < 5; i++) { + DisplayChar(Screen, string[i]); + Screen += (font_width - 1) * sizeof(uint16_t); + } +} diff --git a/source/gfx.h b/source/gfx.h index fc4806b..f6fc3ee 100644 --- a/source/gfx.h +++ b/source/gfx.h @@ -16,6 +16,7 @@ void S9xSetupOBJ(void); void S9xUpdateScreen(void); void RenderLine(uint8_t line); void S9xBuildDirectColourMaps(void); +void S9xDisplayFrameRate(void); bool S9xInitGFX(void); void S9xDeinitGFX(void); diff --git a/source/ppu.c b/source/ppu.c index 1f5df0b..5db22be 100644 --- a/source/ppu.c +++ b/source/ppu.c @@ -1758,6 +1758,8 @@ static void CommonPPUReset() IPPU.RenderThisFrame = true; IPPU.DirectColourMapsNeedRebuild = true; IPPU.FrameCount = 0; + IPPU.RenderedFramesCount = 0; + IPPU.DisplayedRenderedFrameCount = 0; memset(IPPU.TileCached [TILE_2BIT], 0, MAX_2BIT_TILES); memset(IPPU.TileCached [TILE_4BIT], 0, MAX_4BIT_TILES); memset(IPPU.TileCached [TILE_8BIT], 0, MAX_8BIT_TILES); diff --git a/source/ppu.h b/source/ppu.h index 447f7f1..934df06 100644 --- a/source/ppu.h +++ b/source/ppu.h @@ -40,6 +40,8 @@ typedef struct bool RenderThisFrame; bool DirectColourMapsNeedRebuild; uint32_t FrameCount; + uint32_t RenderedFramesCount; + uint32_t DisplayedRenderedFrameCount; uint8_t* TileCache [3]; uint8_t* TileCached [3]; bool FirstVRAMRead; |