From: Javier S. Pedro Date: Wed, 19 Jan 2011 01:23:51 +0000 (+0100) Subject: completely remove paletted color support X-Git-Url: https://vcs.maemo.org/git/?p=drnoksnes;a=commitdiff_plain;h=8f77a3a3f10d94477f0c0734adfbd39e81173d6f completely remove paletted color support --- diff --git a/display.h b/display.h index 49fa741..1b75875 100644 --- a/display.h +++ b/display.h @@ -42,8 +42,6 @@ #define _DISPLAY_H_ START_EXTERN_C -// Routines the port specific code has to implement -void S9xSetPalette (); void S9xTextMode (); void S9xGraphicsMode (); const char *S9xParseArgs (int argc, const char **argv); diff --git a/gfx.cpp b/gfx.cpp index f5992dc..a2714f5 100644 --- a/gfx.cpp +++ b/gfx.cpp @@ -221,8 +221,6 @@ bool8_32 S9xGraphicsInit () DrawHiResClippedTilePtr = DrawHiResClippedTile16; S9xFixColourBrightness(); - if (Settings.SixteenBit) - { if (!(GFX.X2 = (uint16 *) malloc (sizeof (uint16) * 0x10000))) return (FALSE); @@ -369,13 +367,6 @@ bool8_32 S9xGraphicsInit () } } } - } - else - { - GFX.X2 = NULL; - GFX.ZERO_OR_X2 = NULL; - GFX.ZERO = NULL; - } return (TRUE); } @@ -497,24 +488,7 @@ void S9xEndScreenRefresh() IPPU.RenderedFramesCount++; if (IPPU.ColorsChanged) { - uint32 saved = PPU.CGDATA[0]; - - if (!Settings.SixteenBit) { - // Hack for Super Mario World - to get its sky blue - // (It uses Fixed colour addition on the backdrop colour) - if (!(Memory.FillRAM [0x2131] & 0x80) && - (Memory.FillRAM[0x2131] & 0x20) && - (PPU.FixedColourRed || PPU.FixedColourGreen || - PPU.FixedColourBlue)) { - PPU.CGDATA[0] = PPU.FixedColourRed | - (PPU.FixedColourGreen << 5) | - (PPU.FixedColourBlue << 10); - } - } - IPPU.ColorsChanged = FALSE; - S9xSetPalette(); - PPU.CGDATA[0] = saved; } if (Settings.DisplayFrameRate) { @@ -525,9 +499,7 @@ void S9xEndScreenRefresh() S9xDisplayString(GFX.InfoString); } - S9xDeinitUpdate( - IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, - Settings.SixteenBit); + S9xDeinitUpdate(IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight); } #ifndef RC_OPTIMIZED @@ -2893,10 +2865,7 @@ static void DisplayChar(uint8 *Screen, uint8 c) { int line = (((c & 0x7f) - 32) >> 4) * font_height; int offset = (((c & 0x7f) - 32) & 15) * font_width; -#ifndef _SNESPPC - if (Settings.SixteenBit) -#endif - { + int h, w; uint16 *s = (uint16 *) Screen; for (h = 0; h < font_height; h++, line++, @@ -2913,39 +2882,15 @@ static void DisplayChar(uint8 *Screen, uint8 c) *s = BLACK; } } - } -#ifndef _SNESPPC - else - { - int h, w; - uint8 *s = Screen; - for (h = 0; h < font_height; h++, line++, - s += GFX.PPL - font_width) - { - for (w = 0; w < font_width; w++, s++) - { - uint8 p = font [line][offset + w]; - - if (p == '#') - *s = 255; - else - if (p == '.') - *s = BLACK; - } - } - } -#endif } static void S9xDisplayFrameRate() { + const unsigned int char_width = (font_width - 1) * sizeof (uint16); uint8 *Screen = GFX.Screen + 2 + (IPPU.RenderedScreenHeight - font_height - 1) * GFX.Pitch; char string[12]; int len; - const unsigned int char_width = Settings.SixteenBit ? - (font_width - 1) * sizeof (uint16) : - (font_width - 1); if (Settings.TurboMode) { len = sprintf(string, "%u", @@ -2964,6 +2909,7 @@ static void S9xDisplayFrameRate() static void S9xDisplayString(const char *string) { + const unsigned int char_width = (font_width - 1) * sizeof (uint16); uint8 *Screen = GFX.Screen + 2 + (IPPU.RenderedScreenHeight - font_height * 5) * GFX.Pitch; int len = strlen (string); @@ -2975,9 +2921,7 @@ static void S9xDisplayString(const char *string) { if (char_count >= max_chars || string [i] < 32) { - Screen -= Settings.SixteenBit ? - (font_width - 1) * sizeof (uint16) * max_chars : - (font_width - 1) * max_chars; + Screen -= char_width * max_chars; Screen += font_height * GFX.Pitch; if (Screen >= GFX.Screen + GFX.Pitch * IPPU.RenderedScreenHeight) break; @@ -2986,8 +2930,7 @@ static void S9xDisplayString(const char *string) if (string [i] < 32) continue; DisplayChar (Screen, string [i]); - Screen += Settings.SixteenBit ? (font_width - 1) * sizeof (uint16) : - (font_width - 1); + Screen += char_width; } } @@ -3050,27 +2993,15 @@ void S9xUpdateScreen () // ~30-50ms! (called from FLUSH_REDRAW()) if (!IPPU.DoubleWidthPixels) { // The game has switched from lo-res to hi-res mode part way down // the screen. Scale any existing lo-res pixels on screen - if (Settings.SixteenBit) { - for (register uint32 y = 0; y < GFX.StartY; y++) { - register uint16 *p = - (uint16 *) (GFX.Screen + y * GFX.Pitch) + 255; - register uint16 *q = - (uint16 *) (GFX.Screen + y * GFX.Pitch) + 510; - for (register int x = 255; x >= 0; x--, p--, q -= 2) { - *q = *(q + 1) = *p; - } - } - } else { - for (register uint32 y = 0; y < GFX.StartY; y++) { - register uint8 *p = - GFX.Screen + y * GFX.Pitch + 255; - register uint8 *q = - GFX.Screen + y * GFX.Pitch + 510; - for (register int x = 255; x >= 0; x--, p--, q -= 2) { - *q = *(q + 1) = *p; - } + for (register uint32 y = 0; y < GFX.StartY; y++) { + register uint16 *p = + (uint16 *) (GFX.Screen + y * GFX.Pitch) + 255; + register uint16 *q = + (uint16 *) (GFX.Screen + y * GFX.Pitch) + 510; + for (register int x = 255; x >= 0; x--, p--, q -= 2) { + *q = *(q + 1) = *p; } - } + } IPPU.DoubleWidthPixels = TRUE; } @@ -3080,7 +3011,7 @@ void S9xUpdateScreen () // ~30-50ms! (called from FLUSH_REDRAW()) uint32 black = BLACK | (BLACK << 16); // Are we worrying about transparencies? - if (Settings.Transparency && Settings.SixteenBit) + if (Settings.Transparency) { if (GFX.Pseudo) { @@ -3651,57 +3582,39 @@ void S9xUpdateScreen () // ~30-50ms! (called from FLUSH_REDRAW()) } else // Transparencys are disabled, ahh lovely ... nice and easy. { -#ifndef _SNESPPC - if (Settings.SixteenBit) -#endif + // get back colour to be used in clearing the screen + register uint32 back; + if (!(Memory.FillRAM [0x2131] & 0x80) &&(Memory.FillRAM[0x2131] & 0x20) && + (PPU.FixedColourRed || PPU.FixedColourGreen || PPU.FixedColourBlue)) { - // get back colour to be used in clearing the screen - register uint32 back; - if (!(Memory.FillRAM [0x2131] & 0x80) &&(Memory.FillRAM[0x2131] & 0x20) && - (PPU.FixedColourRed || PPU.FixedColourGreen || PPU.FixedColourBlue)) - { - back = (IPPU.XB[PPU.FixedColourRed]<<11) | - (IPPU.XB[PPU.FixedColourGreen] << 6) | - (IPPU.XB[PPU.FixedColourBlue] << 1) | 1; - back = (back << 16) | back; - } - else - { - back = IPPU.ScreenColors [0] | (IPPU.ScreenColors [0] << 16); - } - - // if Forcedblanking in use then back colour becomes black - if (PPU.ForcedBlanking) - back = black; - else - { - SelectTileRenderer (TRUE); //selects the tile renderers to be used - // TRUE means to use the default - // FALSE means use best renderer based on current - // graphics register settings - } - - // now clear all graphics lines which are being updated using the back colour - for (register uint32 y = starty; y <= endy; y++) - { - memset32 ((uint32_t*)(GFX.Screen + y * GFX.Pitch), back, - IPPU.RenderedScreenWidth>>1); - } + back = (IPPU.XB[PPU.FixedColourRed]<<11) | + (IPPU.XB[PPU.FixedColourGreen] << 6) | + (IPPU.XB[PPU.FixedColourBlue] << 1) | 1; + back = (back << 16) | back; } -#ifndef _SNESPPC - else // Settings.SixteenBit == false + else { - // because we are in 8 bit we can just use 0 to clear the screen - // this means we can use the Zero Memory function - - // Loop through all lines being updated and clear the pixels to 0 - for (uint32 y = starty; y <= endy; y++) - { - ZeroMemory (GFX.Screen + y * GFX.Pitch, - IPPU.RenderedScreenWidth); - } + back = IPPU.ScreenColors [0] | (IPPU.ScreenColors [0] << 16); } -#endif + + // if Forcedblanking in use then back colour becomes black + if (PPU.ForcedBlanking) + back = black; + else + { + SelectTileRenderer (TRUE); //selects the tile renderers to be used + // TRUE means to use the default + // FALSE means use best renderer based on current + // graphics register settings + } + + // now clear all graphics lines which are being updated using the back colour + for (register uint32 y = starty; y <= endy; y++) + { + memset32 ((uint32_t*)(GFX.Screen + y * GFX.Pitch), back, + IPPU.RenderedScreenWidth>>1); + } + if (!PPU.ForcedBlanking) { // Loop through all lines being updated and clear the @@ -3815,12 +3728,6 @@ else \ bg = 0; } -#ifndef _SNESPPC - if (!Settings.SixteenBit) - DrawBGMode7Background (GFX.Screen, bg); - else -#endif - { if (!Settings.Mode7Interpolate) { DrawBGMode7Background16 (GFX.Screen, bg); @@ -3829,7 +3736,6 @@ else \ { DrawBGMode7Background16_i (GFX.Screen, bg); } - } } } } @@ -3841,10 +3747,6 @@ else \ { // Mixure of background modes used on screen - scale width // of all non-mode 5 and 6 pixels. -#ifndef _SNESPPC - if (Settings.SixteenBit) -#endif - { for (register uint32 y = GFX.StartY; y <= GFX.EndY; y++) { register uint16 *p = (uint16 *) (GFX.Screen + y * GFX.Pitch) + 255; @@ -3852,19 +3754,6 @@ else \ for (register int x = 255; x >= 0; x--, p--, q -= 2) *q = *(q + 1) = *p; } - } -#ifndef _SNESPPC - else - { - for (register uint32 y = GFX.StartY; y <= GFX.EndY; y++) - { - register uint8 *p = GFX.Screen + y * GFX.Pitch + 255; - register uint8 *q = GFX.Screen + y * GFX.Pitch + 510; - for (register int x = 255; x >= 0; x--, p--, q -= 2) - *q = *(q + 1) = *p; - } - } -#endif } if (IPPU.LatchedInterlace) diff --git a/gfx.h b/gfx.h index dc8eb48..85b4416 100644 --- a/gfx.h +++ b/gfx.h @@ -228,8 +228,7 @@ extern struct SGFX GFX; bool8_32 S9xGraphicsInit (); void S9xGraphicsDeinit(); bool8_32 S9xInitUpdate (void); -bool8_32 S9xDeinitUpdate (int Width, int Height, bool8_32 sixteen_bit); -void S9xSetPalette (); +bool8_32 S9xDeinitUpdate (int Width, int Height); void S9xSyncSpeed (); #ifdef GFX_MULTI_FORMAT diff --git a/platform/config.cpp b/platform/config.cpp index 6caa569..91b3a47 100644 --- a/platform/config.cpp +++ b/platform/config.cpp @@ -208,7 +208,6 @@ static void loadDefaults() Settings.ForceTransparency = FALSE; // We'll enable those later Settings.Transparency = FALSE; - Settings.SixteenBit = TRUE; Settings.SupportHiRes = FALSE; Settings.ApplyCheats = FALSE; @@ -304,7 +303,6 @@ static void parseArgs(poptContext optCon) Config.fullscreen = true; break; case 5: - Settings.SixteenBit = TRUE; Settings.Transparency = TRUE; break; case 6: diff --git a/platform/platform.h b/platform/platform.h index 9093b7e..e3fe831 100644 --- a/platform/platform.h +++ b/platform/platform.h @@ -62,7 +62,7 @@ void S9xAudioOutputEnable(bool enable); void S9xInitInputDevices(); void S9xDeinitInputDevices(); void S9xInputScreenChanged(); -void S9xInputScreenDraw(int pixelSize, void * buffer, int pitch); +void S9xInputScreenDraw(void * buffer, int pitch); void S9xProcessEvents(bool block); // Input actions diff --git a/platform/sdli.cpp b/platform/sdli.cpp index 5a3e7bf..63265b3 100644 --- a/platform/sdli.cpp +++ b/platform/sdli.cpp @@ -328,16 +328,8 @@ static void drawControls(T * buffer, const int pitch) } } -void S9xInputScreenDraw(int pixelSize, void * buffer, int pitch) +void S9xInputScreenDraw(void * buffer, int pitch) { - switch (pixelSize) - { - case 1: - drawControls(reinterpret_cast(buffer), pitch); - break; - case 2: - drawControls(reinterpret_cast(buffer), pitch / 2); - break; - } + drawControls(reinterpret_cast(buffer), pitch / 2); } diff --git a/platform/sdlv.cpp b/platform/sdlv.cpp index 9896494..5b54a1d 100644 --- a/platform/sdlv.cpp +++ b/platform/sdlv.cpp @@ -129,13 +129,11 @@ static void setupVideoSurface() if (gameHeight > GUI.Height || gameWidth > GUI.Width) DIE("Video is larger than window size!"); - const ScalerFactory* sFactory = - searchForScaler(Settings.SixteenBit ? 16 : 8, gameWidth, gameHeight); + const ScalerFactory* sFactory = searchForScaler(16, gameWidth, gameHeight); + + screen = SDL_SetVideoMode(GUI.Width, GUI.Height, 16, + SDL_SWSURFACE | (Config.fullscreen ? SDL_FULLSCREEN : 0)); - screen = SDL_SetVideoMode(GUI.Width, GUI.Height, - Settings.SixteenBit ? 16 : 8, - SDL_SWSURFACE | - (Config.fullscreen ? SDL_FULLSCREEN : 0)); if (!screen) DIE("SDL_SetVideoMode: %s", SDL_GetError()); @@ -177,8 +175,7 @@ static void drawOnscreenControls() if (Config.touchscreenShow) { scaler->pause(); SDL_FillRect(screen, NULL, 0); - S9xInputScreenDraw(Settings.SixteenBit ? 2 : 1, - screen->pixels, screen->pitch); + S9xInputScreenDraw(screen->pixels, screen->pitch); SDL_Flip(screen); scaler->resume(); } @@ -226,23 +223,6 @@ bool videoEventFilter(const SDL_Event& event) return false; } -// This is here for completeness, but palette mode is mostly useless (slow). -void S9xSetPalette () -{ - if (Settings.SixteenBit) return; - - SDL_Color colors[256]; - int brightness = IPPU.MaxBrightness *138; - for (int i = 0; i < 256; i++) - { - colors[i].r = ((PPU.CGDATA[i] >> 0) & 0x1F) * brightness; - colors[i].g = ((PPU.CGDATA[i] >> 5) & 0x1F) * brightness; - colors[i].b = ((PPU.CGDATA[i] >> 10) & 0x1F) * brightness; - } - - SDL_SetColors(screen, colors, 0, 256); -} - /** Called before rendering a frame. This function must ensure GFX.Screen points to something, but we did that while initializing video output. @@ -267,7 +247,7 @@ bool8_32 S9xInitUpdate () 478 if hi-res. SNES screen modes are being supported. */ // TODO Above. -bool8_32 S9xDeinitUpdate (int width, int height, bool8_32 sixteenBit) +bool8_32 S9xDeinitUpdate (int width, int height) { scaler->finish(); diff --git a/ppu.cpp b/ppu.cpp index b9a5963..7dcc9cf 100644 --- a/ppu.cpp +++ b/ppu.cpp @@ -128,10 +128,6 @@ void S9xUpdateHTimer () void S9xFixColourBrightness () { IPPU.XB = mul_brightness [PPU.Brightness]; -#ifndef _SNESPPC - if (Settings.SixteenBit) -#endif - { for (int i = 0; i < 256; i++) { IPPU.Red [i] = IPPU.XB [PPU.CGDATA [i] & 0x1f]; @@ -140,7 +136,6 @@ void S9xFixColourBrightness () IPPU.ScreenColors [i] = BUILD_PIXEL (IPPU.Red [i], IPPU.Green [i], IPPU.Blue [i]); } - } } /**********************************************************************************************/ diff --git a/ppu.h b/ppu.h index 20e44a1..8a84838 100644 --- a/ppu.h +++ b/ppu.h @@ -484,22 +484,18 @@ STATIC INLINE void REGISTER_2122(uint8 Byte) { if ((Byte & 0x7f) != (PPU.CGDATA[PPU.CGADD] >> 8)) { - if (Settings.SixteenBit&& !(Settings.os9x_hack&PPU_IGNORE_PALWRITE)){ + if (!(Settings.os9x_hack&PPU_IGNORE_PALWRITE)){ FLUSH_REDRAW (); } PPU.CGDATA[PPU.CGADD] &= 0x00FF; PPU.CGDATA[PPU.CGADD] |= (Byte & 0x7f) << 8; IPPU.ColorsChanged = TRUE; -#ifndef _SNESPPC - if (Settings.SixteenBit) -#endif - { + IPPU.Blue [PPU.CGADD] = IPPU.XB [(Byte >> 2) & 0x1f]; IPPU.Green [PPU.CGADD] = IPPU.XB [(PPU.CGDATA[PPU.CGADD] >> 5) & 0x1f]; IPPU.ScreenColors [PPU.CGADD] = (uint16) BUILD_PIXEL (IPPU.Red [PPU.CGADD], IPPU.Green [PPU.CGADD], IPPU.Blue [PPU.CGADD]); - } } PPU.CGADD++; } @@ -507,22 +503,18 @@ STATIC INLINE void REGISTER_2122(uint8 Byte) { if (Byte != (uint8) (PPU.CGDATA[PPU.CGADD] & 0xff)) { - if (Settings.SixteenBit&& !(Settings.os9x_hack&PPU_IGNORE_PALWRITE)){ + if (!(Settings.os9x_hack&PPU_IGNORE_PALWRITE)){ FLUSH_REDRAW (); } PPU.CGDATA[PPU.CGADD] &= 0x7F00; PPU.CGDATA[PPU.CGADD] |= Byte; IPPU.ColorsChanged = TRUE; -#ifndef _SNESPPC - if (Settings.SixteenBit) -#endif - { + IPPU.Red [PPU.CGADD] = IPPU.XB [Byte & 0x1f]; IPPU.Green [PPU.CGADD] = IPPU.XB [(PPU.CGDATA[PPU.CGADD] >> 5) & 0x1f]; IPPU.ScreenColors [PPU.CGADD] = (uint16) BUILD_PIXEL (IPPU.Red [PPU.CGADD], IPPU.Green [PPU.CGADD], IPPU.Blue [PPU.CGADD]); - } } } PPU.CGFLIP ^= 1; diff --git a/screenshot.cpp b/screenshot.cpp index f33b240..c810a55 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -163,30 +163,16 @@ bool8 S9xDoScreenshot(int width, int height){ } png_init_io(png_ptr, fp); - if(!Settings.SixteenBit){ - // BJ: credit sanmaiwashi for the idea to do palettized pngs, and to - // S9xSetPalette in x11.cpp for how to calculate the RGB values - int b=IPPU.MaxBrightness*140; - for(int i=0; i<256; i++){ - pngpal[i].red = (PPU.CGDATA[i] & 0x1f)*b>>8; - pngpal[i].green = ((PPU.CGDATA[i] >> 5) & 0x1f)*b>>8; - pngpal[i].blue = ((PPU.CGDATA[i] >> 10) & 0x1f)*b>>8; - } - png_set_PLTE(png_ptr, info_ptr, pngpal, 256); - } png_set_IHDR(png_ptr, info_ptr, imgwidth, imgheight, 8, - (Settings.SixteenBit?PNG_COLOR_TYPE_RGB:PNG_COLOR_TYPE_PALETTE), - PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT); - - if(Settings.SixteenBit){ - /* 5 bits per color */ - sig_bit.red=5; - sig_bit.green=5; - sig_bit.blue=5; - png_set_sBIT(png_ptr, info_ptr, &sig_bit); - png_set_shift(png_ptr, &sig_bit); - } + PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + + /* 5 bits per color */ + sig_bit.red=5; + sig_bit.green=5; + sig_bit.blue=5; + png_set_sBIT(png_ptr, info_ptr, &sig_bit); + png_set_shift(png_ptr, &sig_bit); png_write_info(png_ptr, info_ptr); @@ -197,21 +183,15 @@ bool8 S9xDoScreenshot(int width, int height){ for(int y=0; y