From 6b36e79013d4c9273a96a9783a2bccdb516f174a Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Thu, 27 Dec 2012 18:02:03 -0500 Subject: Speed up rendering by an unknown amount. gfx.cpp, others: Avoid always checking for Settings.SixteenBit if FOREVER_16_BIT is defined. port.h: Define FOREVER_16_BIT below PIXEL_FORMAT. --- source/gfx.cpp | 148 ++++++++++++++++----- source/globals.cpp | 1 - source/nds/entry.cpp | 6 + source/port.h | 4 + source/ppu.cpp | 369 ++++++++++++--------------------------------------- source/snes9x.h | 2 + source/tile.cpp | 90 +++++++------ 7 files changed, 256 insertions(+), 364 deletions(-) (limited to 'source') diff --git a/source/gfx.cpp b/source/gfx.cpp index 16d006e..5e6c650 100644 --- a/source/gfx.cpp +++ b/source/gfx.cpp @@ -167,6 +167,7 @@ extern uint8 Mode7Depths [2]; #define BLACK BUILD_PIXEL(0,0,0) +#ifndef FOREVER_16_BIT void DrawTile (uint32 Tile, uint32 Offset, uint32 StartLine, uint32 LineCount); void DrawClippedTile (uint32 Tile, uint32 Offset, @@ -185,6 +186,7 @@ void DrawClippedTilex2x2 (uint32 Tile, uint32 Offset, void DrawLargePixel (uint32 Tile, uint32 Offset, uint32 StartPixel, uint32 Pixels, uint32 StartLine, uint32 LineCount); +#endif void DrawTile16 (uint32 Tile, uint32 Offset, uint32 StartLine, uint32 LineCount); @@ -365,7 +367,9 @@ bool8 S9xGraphicsInit () GFX.RealPitch = GFX.Pitch2 = GFX.Pitch; GFX.ZPitch = GFX.Pitch; +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) +#endif GFX.ZPitch >>= 1; GFX.Delta = (GFX.SubScreen - GFX.Screen) >> 1; GFX.DepthDelta = GFX.SubZBuffer - GFX.ZBuffer; @@ -374,13 +378,17 @@ bool8 S9xGraphicsInit () PPU.BG_Forced = 0; IPPU.OBJChanged = TRUE; +#ifndef FOREVER_16_BIT if (Settings.Transparency) Settings.SixteenBit = TRUE; +#endif IPPU.DirectColourMapsNeedRebuild = TRUE; GFX.PixSize = 1; +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) { +#endif DrawTilePtr = DrawTile16; DrawClippedTilePtr = DrawClippedTile16; DrawLargePixelPtr = DrawLargePixel16; @@ -388,6 +396,7 @@ bool8 S9xGraphicsInit () DrawHiResClippedTilePtr = DrawClippedTile16; GFX.PPL = GFX.Pitch >> 1; GFX.PPLx2 = GFX.Pitch; +#ifndef FOREVER_16_BIT } else { @@ -399,10 +408,13 @@ bool8 S9xGraphicsInit () GFX.PPL = GFX.Pitch; GFX.PPLx2 = GFX.Pitch * 2; } +#endif S9xFixColourBrightness (); +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) { +#endif if (!(GFX.X2 = (uint16 *) malloc (sizeof (uint16) * 0x10000))) return (FALSE); @@ -549,6 +561,7 @@ bool8 S9xGraphicsInit () } } } +#ifndef FOREVER_16_BIT } else { @@ -556,6 +569,7 @@ bool8 S9xGraphicsInit () GFX.ZERO_OR_X2 = NULL; GFX.ZERO = NULL; } +#endif return (TRUE); } @@ -634,20 +648,28 @@ void S9xStartScreenRefresh () IPPU.DoubleHeightPixels = TRUE; GFX.Pitch2 = GFX.RealPitch; GFX.Pitch = GFX.RealPitch * 2; +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) +#endif GFX.PPL = GFX.PPLx2 = GFX.RealPitch; +#ifndef FOREVER_16_BIT else GFX.PPL = GFX.PPLx2 = GFX.RealPitch << 1; +#endif } else { IPPU.RenderedScreenHeight = PPU.ScreenHeight; GFX.Pitch2 = GFX.Pitch = GFX.RealPitch; IPPU.DoubleHeightPixels = FALSE; +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) +#endif GFX.PPL = GFX.Pitch >> 1; +#ifndef FOREVER_16_BIT else GFX.PPL = GFX.Pitch; +#endif GFX.PPLx2 = GFX.PPL << 1; } } @@ -661,7 +683,9 @@ void S9xStartScreenRefresh () GFX.Pitch2 = GFX.Pitch = GFX.RealPitch; GFX.PPL = GFX.PPLx2 >> 1; GFX.ZPitch = GFX.RealPitch; +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) +#endif GFX.ZPitch >>= 1; } } @@ -731,9 +755,10 @@ void S9xEndScreenRefresh () FLUSH_REDRAW (); if (IPPU.ColorsChanged) { - uint32 saved = PPU.CGDATA[0]; + uint32 saved = PPU.CGDATA[0]; +#ifndef FOREVER_16_BIT 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) && @@ -742,7 +767,8 @@ void S9xEndScreenRefresh () PPU.CGDATA[0] = PPU.FixedColourRed | (PPU.FixedColourGreen << 5) | (PPU.FixedColourBlue << 10); } - } + } +#endif IPPU.ColorsChanged = FALSE; PPU.CGDATA[0] = saved; } @@ -768,7 +794,12 @@ void S9xEndScreenRefresh () } #endif S9xDeinitUpdate (IPPU.RenderedScreenWidth, IPPU.RenderedScreenHeight, - Settings.SixteenBit); +#ifndef FOREVER_16_BIT + Settings.SixteenBit +#else + TRUE +#endif + ); } S9xApplyCheats (); @@ -1083,7 +1114,7 @@ void S9xSetupOBJ () IPPU.OBJChanged = FALSE; } -void DrawOBJS (bool8 OnMain = FALSE, uint8 D = 0) +static void DrawOBJS (bool8 OnMain = FALSE, uint8 D = 0) { #ifdef MK_DEBUG_RTO if(Settings.BGLayering) fprintf(stderr, "Entering DrawOBJS() for %d-%d\n", GFX.StartY, GFX.EndY); @@ -1158,45 +1189,56 @@ if(Settings.BGLayering) { OnMain = FALSE; GFX.PixSize = 2; if (IPPU.DoubleHeightPixels) - { +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) { +#endif DrawTilePtr = DrawTile16x2x2; DrawClippedTilePtr = DrawClippedTile16x2x2; +#ifndef FOREVER_16_BIT } else { DrawTilePtr = DrawTilex2x2; DrawClippedTilePtr = DrawClippedTilex2x2; } +#endif } else { +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) { +#endif DrawTilePtr = DrawTile16x2; DrawClippedTilePtr = DrawClippedTile16x2; +#ifndef FOREVER_16_BIT } else { DrawTilePtr = DrawTilex2; DrawClippedTilePtr = DrawClippedTilex2; } +#endif } } else { +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) { +#endif DrawTilePtr = DrawTile16; DrawClippedTilePtr = DrawClippedTile16; +#ifndef FOREVER_16_BIT } else { DrawTilePtr = DrawTile; DrawClippedTilePtr = DrawClippedTile; } +#endif } } GFX.Z1 = D + 2; @@ -1294,7 +1336,7 @@ if(Settings.BGLayering) { #endif } -void DrawBackgroundMosaic (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) +static void DrawBackgroundMosaic (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { CHECK_SOUND(); @@ -1522,7 +1564,7 @@ void DrawBackgroundMosaic (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) } } -void DrawBackgroundOffset (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) +static void DrawBackgroundOffset (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { CHECK_SOUND(); @@ -1859,7 +1901,7 @@ void DrawBackgroundOffset (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) } } -void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2) +static void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2) { CHECK_SOUND(); @@ -2190,7 +2232,7 @@ void DrawBackgroundMode5 (uint32 /* BGMODE */, uint32 bg, uint8 Z1, uint8 Z2) } -void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) +static void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) { GFX.PixSize = 1; @@ -2687,17 +2729,17 @@ void DrawBackground (uint32 BGMode, uint32 bg, uint8 Z1, uint8 Z2) } \ } -void DrawBGMode7Background (uint8 *Screen, int bg) +static void DrawBGMode7Background (uint8 *Screen, int bg) { RENDER_BACKGROUND_MODE7 (uint8, (uint8) (b & GFX.Mode7Mask)) } -void DrawBGMode7Background16 (uint8 *Screen, int bg) +static void DrawBGMode7Background16 (uint8 *Screen, int bg) { RENDER_BACKGROUND_MODE7 (uint16, GFX.ScreenColors [b & GFX.Mode7Mask]); } -void DrawBGMode7Background16Add (uint8 *Screen, int bg) +static void DrawBGMode7Background16Add (uint8 *Screen, int bg) { RENDER_BACKGROUND_MODE7 (uint16, *(d + GFX.DepthDelta) ? (*(d + GFX.DepthDelta) != 1 ? @@ -2708,7 +2750,7 @@ void DrawBGMode7Background16Add (uint8 *Screen, int bg) GFX.ScreenColors [b & GFX.Mode7Mask]); } -void DrawBGMode7Background16Add1_2 (uint8 *Screen, int bg) +static void DrawBGMode7Background16Add1_2 (uint8 *Screen, int bg) { RENDER_BACKGROUND_MODE7 (uint16, *(d + GFX.DepthDelta) ? (*(d + GFX.DepthDelta) != 1 ? @@ -2719,7 +2761,7 @@ void DrawBGMode7Background16Add1_2 (uint8 *Screen, int bg) GFX.ScreenColors [b & GFX.Mode7Mask]); } -void DrawBGMode7Background16Sub (uint8 *Screen, int bg) +static void DrawBGMode7Background16Sub (uint8 *Screen, int bg) { RENDER_BACKGROUND_MODE7 (uint16, *(d + GFX.DepthDelta) ? (*(d + GFX.DepthDelta) != 1 ? @@ -2730,7 +2772,7 @@ void DrawBGMode7Background16Sub (uint8 *Screen, int bg) GFX.ScreenColors [b & GFX.Mode7Mask]); } -void DrawBGMode7Background16Sub1_2 (uint8 *Screen, int bg) +static void DrawBGMode7Background16Sub1_2 (uint8 *Screen, int bg) { RENDER_BACKGROUND_MODE7 (uint16, *(d + GFX.DepthDelta) ? (*(d + GFX.DepthDelta) != 1 ? @@ -3123,12 +3165,12 @@ STATIC uint32 Q_INTERPOLATE(uint32 A, uint32 B, uint32 C, uint32 D) return x+y; } -void DrawBGMode7Background16_i (uint8 *Screen, int bg) +static void DrawBGMode7Background16_i (uint8 *Screen, int bg) { RENDER_BACKGROUND_MODE7_i (uint16, theColor, (GFX.ScreenColors[b & GFX.Mode7Mask])); } -void DrawBGMode7Background16Add_i (uint8 *Screen, int bg) +static void DrawBGMode7Background16Add_i (uint8 *Screen, int bg) { RENDER_BACKGROUND_MODE7_i (uint16, *(d + GFX.DepthDelta) ? (*(d + GFX.DepthDelta) != 1 ? @@ -3139,7 +3181,7 @@ void DrawBGMode7Background16Add_i (uint8 *Screen, int bg) theColor, (GFX.ScreenColors[b & GFX.Mode7Mask])); } -void DrawBGMode7Background16Add1_2_i (uint8 *Screen, int bg) +static void DrawBGMode7Background16Add1_2_i (uint8 *Screen, int bg) { RENDER_BACKGROUND_MODE7_i (uint16, *(d + GFX.DepthDelta) ? (*(d + GFX.DepthDelta) != 1 ? @@ -3150,7 +3192,7 @@ void DrawBGMode7Background16Add1_2_i (uint8 *Screen, int bg) theColor, (GFX.ScreenColors[b & GFX.Mode7Mask])); } -void DrawBGMode7Background16Sub_i (uint8 *Screen, int bg) +static void DrawBGMode7Background16Sub_i (uint8 *Screen, int bg) { RENDER_BACKGROUND_MODE7_i (uint16, *(d + GFX.DepthDelta) ? (*(d + GFX.DepthDelta) != 1 ? @@ -3161,7 +3203,7 @@ void DrawBGMode7Background16Sub_i (uint8 *Screen, int bg) theColor, (GFX.ScreenColors[b & GFX.Mode7Mask])); } -void DrawBGMode7Background16Sub1_2_i (uint8 *Screen, int bg) +static void DrawBGMode7Background16Sub1_2_i (uint8 *Screen, int bg) { RENDER_BACKGROUND_MODE7_i (uint16, *(d + GFX.DepthDelta) ? (*(d + GFX.DepthDelta) != 1 ? @@ -3206,7 +3248,7 @@ TWO_LOW_BITS_MASK = RGB_LOW_BITS_MASK | (RGB_LOW_BITS_MASK << 1); \ HIGH_BITS_SHIFTED_TWO_MASK = (( (FIRST_COLOR_MASK | SECOND_COLOR_MASK | THIRD_COLOR_MASK) & \ ~TWO_LOW_BITS_MASK ) >> 2); -void RenderScreen (uint8 *Screen, bool8 sub, bool8 force_no_add, uint8 D) +static void RenderScreen (uint8 *Screen, bool8 sub, bool8 force_no_add, uint8 D) { bool8 BG0; bool8 BG1; @@ -3236,9 +3278,10 @@ void RenderScreen (uint8 *Screen, bool8 sub, bool8 force_no_add, uint8 D) } sub |= force_no_add; - - if (PPU.BGMode <= 1) - { + + switch (PPU.BGMode) { + case 0: + case 1: if (OB) { SelectTileRenderer (sub || !SUB_OR_ADD(4)); @@ -3265,9 +3308,12 @@ void RenderScreen (uint8 *Screen, bool8 sub, bool8 force_no_add, uint8 D) SelectTileRenderer (sub || !SUB_OR_ADD(3)); DrawBackground (PPU.BGMode, 3, D + 2, D + 5); } - } - else if (PPU.BGMode != 7) - { + break; + case 2: + case 3: + case 4: + case 5: + case 6: if (OB) { SelectTileRenderer (sub || !SUB_OR_ADD(4)); @@ -3278,14 +3324,13 @@ void RenderScreen (uint8 *Screen, bool8 sub, bool8 force_no_add, uint8 D) SelectTileRenderer (sub || !SUB_OR_ADD(0)); DrawBackground (PPU.BGMode, 0, D + 5, D + 13); } - if (PPU.BGMode != 6 && BG1) + if (BG1 && PPU.BGMode != 6) { SelectTileRenderer (sub || !SUB_OR_ADD(1)); DrawBackground (PPU.BGMode, 1, D + 2, D + 9); } - } - else - { + break; + case 7: if (OB) { SelectTileRenderer (sub || !SUB_OR_ADD(4)); @@ -3356,7 +3401,10 @@ void RenderScreen (uint8 *Screen, bool8 sub, bool8 force_no_add, uint8 D) } } } - } + break; + default: + break; + } } #include "font.h" @@ -3365,8 +3413,10 @@ void DisplayChar (uint8 *Screen, uint8 c) { int line = (((c & 0x7f) - 32) >> 4) * font_height; int offset = (((c & 0x7f) - 32) & 15) * font_width; +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) { +#endif int h, w; uint16 *s = (uint16 *) Screen; for (h = 0; h < font_height; h++, line++, @@ -3396,6 +3446,7 @@ void DisplayChar (uint8 *Screen, uint8 c) *s = BLACK; } } +#ifndef FOREVER_16_BIT } else { @@ -3416,6 +3467,7 @@ void DisplayChar (uint8 *Screen, uint8 c) } } } +#endif } static void S9xDisplayFrameRate () @@ -3432,8 +3484,12 @@ static void S9xDisplayFrameRate () for (i = 0; i < len; i++) { DisplayChar (Screen, string [i]); +#ifndef FOREVER_16_BIT Screen += Settings.SixteenBit ? (font_width - 1) * sizeof (uint16) : (font_width - 1); +#else + Screen += (font_width - 1) * sizeof (uint16); +#endif } } @@ -3450,9 +3506,13 @@ static void S9xDisplayString (const char *string) { if (char_count >= max_chars || string [i] < 32) { +#ifndef FOREVER_16_BIT Screen -= Settings.SixteenBit ? (font_width - 1) * sizeof (uint16) * max_chars : (font_width - 1) * max_chars; +#else + Screen -= (font_width - 1) * max_chars * sizeof (uint16); +#endif Screen += font_height * GFX.Pitch; if (Screen >= GFX.Screen + GFX.Pitch * IPPU.RenderedScreenHeight) break; @@ -3461,8 +3521,12 @@ static void S9xDisplayString (const char *string) if (string [i] < 32) continue; DisplayChar (Screen, string [i]); +#ifndef FOREVER_16_BIT Screen += Settings.SixteenBit ? (font_width - 1) * sizeof (uint16) : (font_width - 1); +#else + Screen += (font_width - 1) * sizeof (uint16); +#endif } } @@ -3528,8 +3592,10 @@ void S9xUpdateScreen () { // The game has switched from lo-res to hi-res mode part way down // the screen. Scale any existing lo-res pixels on screen +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) { +#endif for (register uint32 y = 0; y < starty; y++) { register uint16 *p = (uint16 *) (GFX.Screen + y * GFX.Pitch2) + 255; @@ -3538,6 +3604,7 @@ void S9xUpdateScreen () for (register int x = 255; x >= 0; x--, p--, q -= 2) *q = *(q + 1) = *p; } +#ifndef FOREVER_16_BIT } else { @@ -3549,6 +3616,7 @@ void S9xUpdateScreen () *q = *(q + 1) = *p; } } +#endif IPPU.DoubleWidthPixels = TRUE; } // BJ: And we have to change the height if Interlace gets set, @@ -3561,10 +3629,14 @@ void S9xUpdateScreen () IPPU.DoubleHeightPixels = TRUE; GFX.Pitch2 = GFX.RealPitch; GFX.Pitch = GFX.RealPitch * 2; +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) +#endif GFX.PPL = GFX.PPLx2 = GFX.RealPitch; +#ifndef FOREVER_16_BIT else GFX.PPL = GFX.PPLx2 = GFX.RealPitch << 1; +#endif // The game has switched from non-interlaced to interlaced mode // part way down the screen. Scale everything. @@ -3582,7 +3654,11 @@ void S9xUpdateScreen () uint32 black = BLACK | (BLACK << 16); - if (Settings.Transparency && Settings.SixteenBit) + if (Settings.Transparency +#ifndef FOREVER_16_BIT + && Settings.SixteenBit +#endif + ) { if (GFX.Pseudo) { @@ -3993,8 +4069,10 @@ void S9xUpdateScreen () { // Mixure of background modes used on screen - scale width // of all non-mode 5 and 6 pixels. +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) { +#endif for (register uint32 y = starty; y <= endy; y++) { register uint16 *p = (uint16 *) (GFX.Screen + y * GFX.Pitch2) + 255; @@ -4002,6 +4080,7 @@ void S9xUpdateScreen () for (register int x = 255; x >= 0; x--, p--, q -= 2) *q = *(q + 1) = *p; } +#ifndef FOREVER_16_BIT } else { @@ -4013,6 +4092,7 @@ void S9xUpdateScreen () *q = *(q + 1) = *p; } } +#endif } // Double the height of the pixels just drawn diff --git a/source/globals.cpp b/source/globals.cpp index adb9ab4..c804318 100644 --- a/source/globals.cpp +++ b/source/globals.cpp @@ -228,7 +228,6 @@ uint32 HIGH_BITS_SHIFTED_TWO_MASK = 0; uint32 current_graphic_format = RGB565; #endif -uint8 GetBank = 0; struct SCheatData Cheat; volatile SoundStatus so; diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index 9d0f0bc..1589c21 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -384,7 +384,9 @@ void init_sfc_setting(void) Settings.ControllerOption = SNES_JOYPAD; Settings.Transparency = TRUE; +#ifndef FOREVER_16_BIT Settings.SixteenBit = TRUE; +#endif Settings.SupportHiRes = FALSE; Settings.ThreadSound = FALSE; @@ -792,6 +794,7 @@ bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int buffer_size) void S9xGenerateSound () { +#if 0 int bytes_so_far = so.sixteen_bit ? (so.samples_mixed_so_far << 1) : so.samples_mixed_so_far; @@ -853,10 +856,12 @@ void S9xGenerateSound () S9xProcessSound (0); pending_signal = FALSE; } +#endif } void S9xProcessSound (unsigned int) { +#if 0 unsigned short *audiobuff; if (!Settings.APUEnabled || so.mute_sound ) @@ -957,6 +962,7 @@ void S9xProcessSound (unsigned int) } so.samples_mixed_so_far -= sample_count; +#endif } void Init_Timer (void) diff --git a/source/port.h b/source/port.h index ac241b6..5b94d06 100644 --- a/source/port.h +++ b/source/port.h @@ -112,6 +112,10 @@ /* #define PIXEL_FORMAT RGB565 */ #define PIXEL_FORMAT BGR555 +#define FOREVER_16_BIT +// The above is used to disable the 16-bit graphics mode checks sprinkled +// throughout the code, if the pixel format is always 16-bit. + // #define GFX_MULTI_FORMAT #if defined(TARGET_OS_MAC) && TARGET_OS_MAC diff --git a/source/ppu.cpp b/source/ppu.cpp index 5c7d690..def55e9 100644 --- a/source/ppu.cpp +++ b/source/ppu.cpp @@ -204,8 +204,10 @@ void S9xUpdateHTimer () void S9xFixColourBrightness () { IPPU.XB = mul_brightness [PPU.Brightness]; +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) { +#endif for (int i = 0; i < 256; i++) { IPPU.Red [i] = IPPU.XB [PPU.CGDATA [i] & 0x1f]; @@ -214,7 +216,9 @@ void S9xFixColourBrightness () IPPU.ScreenColors [i] = BUILD_PIXEL (IPPU.Red [i], IPPU.Green [i], IPPU.Blue [i]); } +#ifndef FOREVER_16_BIT } +#endif } /******************************************************************************/ @@ -472,8 +476,6 @@ void S9xSetPPU (uint8 Byte, uint16 Address) PPU.VMA.Increment = 32; break; case 2: - PPU.VMA.Increment = 128; - break; case 3: PPU.VMA.Increment = 128; break; @@ -882,28 +884,20 @@ void S9xSetPPU (uint8 Byte, uint16 Address) case 0x2135: case 0x2136: // Matrix 16bit x 8bit multiply result (read-only) - return; - case 0x2137: // Software latch for horizontal and vertical timers (read-only) - return; case 0x2138: // OAM read data (read-only) - return; case 0x2139: case 0x213a: // VRAM read data (read-only) - return; case 0x213b: // CG-RAM read data (read-only) - return; case 0x213c: case 0x213d: // Horizontal and vertical (low/high) read counter (read-only) - return; case 0x213e: // PPU status (time over and range over) - return; case 0x213f: // NTSC/PAL select and field (read-only) return; @@ -969,7 +963,7 @@ void S9xSetPPU (uint8 Byte, uint16 Address) if (Address == 0x2801 && Settings.SRTC) S9xSetSRTC (Byte, Address); else - if (Address < 0x3000 || Address >= 0x3000 + 768) + if (Address < 0x3000 || Address >= 0x3300) { #ifdef DEBUGGER missing.unknownppu_write = Address; @@ -1010,39 +1004,27 @@ void S9xSetPPU (uint8 Byte, uint16 Address) break; case 0x3031: - Memory.FillRAM [Address] = Byte; - break; case 0x3033: + case 0x3037: + case 0x3039: + case 0x303a: + case 0x303f: Memory.FillRAM [Address] = Byte; break; case 0x3034: - Memory.FillRAM [Address] = Byte & 0x7f; - break; case 0x3036: Memory.FillRAM [Address] = Byte & 0x7f; break; - case 0x3037: - Memory.FillRAM [Address] = Byte; - break; case 0x3038: Memory.FillRAM [Address] = Byte; fx_dirtySCBR(); break; - case 0x3039: - Memory.FillRAM [Address] = Byte; - break; - case 0x303a: - Memory.FillRAM [Address] = Byte; - break; case 0x303b: break; case 0x303c: Memory.FillRAM [Address] = Byte; fx_updateRamBank(Byte); break; - case 0x303f: - Memory.FillRAM [Address] = Byte; - break; case 0x301f: Memory.FillRAM [Address] = Byte; Memory.FillRAM [0x3000 + GSU_SFR] |= FLG_G; @@ -1185,6 +1167,16 @@ uint8 S9xGetPPU (uint16 Address) case 0x2121: case 0x2122: case 0x2123: + case 0x2127: + case 0x212b: + case 0x212c: + case 0x212d: + case 0x212e: + case 0x212f: + case 0x2130: + case 0x2131: + case 0x2132: + case 0x2133: #ifndef NO_OPEN_BUS return OpenBus; #else @@ -1194,19 +1186,6 @@ uint8 S9xGetPPU (uint16 Address) case 0x2124: case 0x2125: case 0x2126: -#ifndef NO_OPEN_BUS - return PPU.OpenBus1; -#else - return 0; // Arbitrarily chosen value [Neb] -#endif - - case 0x2127: -#ifndef NO_OPEN_BUS - return OpenBus; -#else - return 0; // Arbitrarily chosen value [Neb] -#endif - case 0x2128: case 0x2129: case 0x212a: @@ -1216,21 +1195,6 @@ uint8 S9xGetPPU (uint16 Address) return 0; // Arbitrarily chosen value [Neb] #endif - case 0x212b: - case 0x212c: - case 0x212d: - case 0x212e: - case 0x212f: - case 0x2130: - case 0x2131: - case 0x2132: - case 0x2133: -#ifndef NO_OPEN_BUS - return OpenBus; -#else - return 0; // Arbitrarily chosen value [Neb] -#endif - case 0x2134: case 0x2135: case 0x2136: @@ -1528,13 +1492,11 @@ uint8 S9xGetPPU (uint16 Address) { case 0: case 1: + case 3: CPU.BranchSkip = TRUE; break; case 2: break; - case 3: - CPU.BranchSkip = TRUE; - break; } if ((Address & 3) < 2) { @@ -1567,12 +1529,6 @@ uint8 S9xGetPPU (uint16 Address) case 0x2181: case 0x2182: case 0x2183: -#ifndef NO_OPEN_BUS - return OpenBus; -#else - return 0; // Arbitrarily chosen value [Neb] -#endif - default: #ifndef NO_OPEN_BUS return OpenBus; @@ -1938,7 +1894,6 @@ void S9xSetCPU (uint8 byte, uint16 Address) case 0x4216: case 0x4217: // Multiply product (read-only) - return; case 0x4218: case 0x4219: case 0x421a: @@ -2382,7 +2337,6 @@ uint8 S9xGetCPU (uint16 Address) case 0x4217: // Multiplcation result (for multiply) or remainder of // divison. - return (Memory.FillRAM[Address]); case 0x4218: case 0x4219: case 0x421a: @@ -2392,7 +2346,6 @@ uint8 S9xGetCPU (uint16 Address) case 0x421e: case 0x421f: // Joypads 1-4 button and direction state. - return (Memory.FillRAM [Address]); case 0x4300: case 0x4310: @@ -2403,7 +2356,6 @@ uint8 S9xGetCPU (uint16 Address) case 0x4360: case 0x4370: // DMA direction, address type, fixed flag, - return (Memory.FillRAM[Address]); case 0x4301: case 0x4311: @@ -2413,7 +2365,6 @@ uint8 S9xGetCPU (uint16 Address) case 0x4351: case 0x4361: case 0x4371: - return (Memory.FillRAM[Address]); case 0x4302: case 0x4312: @@ -2423,7 +2374,6 @@ uint8 S9xGetCPU (uint16 Address) case 0x4352: case 0x4362: case 0x4372: - return (Memory.FillRAM[Address]); case 0x4303: case 0x4313: @@ -2433,7 +2383,6 @@ uint8 S9xGetCPU (uint16 Address) case 0x4353: case 0x4363: case 0x4373: - return (Memory.FillRAM[Address]); case 0x4304: case 0x4314: @@ -2443,7 +2392,6 @@ uint8 S9xGetCPU (uint16 Address) case 0x4354: case 0x4364: case 0x4374: - return (Memory.FillRAM[Address]); case 0x4305: case 0x4315: @@ -2453,7 +2401,6 @@ uint8 S9xGetCPU (uint16 Address) case 0x4355: case 0x4365: case 0x4375: - return (Memory.FillRAM[Address]); case 0x4306: case 0x4316: @@ -2463,17 +2410,6 @@ uint8 S9xGetCPU (uint16 Address) case 0x4356: case 0x4366: case 0x4376: - return (Memory.FillRAM[Address]); - - case 0x4307: - case 0x4317: - case 0x4327: - case 0x4337: - case 0x4347: - case 0x4357: - case 0x4367: - case 0x4377: - return (DMA[(Address >> 4) & 7].IndirectBank); case 0x4308: case 0x4318: @@ -2483,7 +2419,6 @@ uint8 S9xGetCPU (uint16 Address) case 0x4358: case 0x4368: case 0x4378: - return (Memory.FillRAM[Address]); case 0x4309: case 0x4319: @@ -2495,6 +2430,16 @@ uint8 S9xGetCPU (uint16 Address) case 0x4379: return (Memory.FillRAM[Address]); + case 0x4307: + case 0x4317: + case 0x4327: + case 0x4337: + case 0x4347: + case 0x4357: + case 0x4367: + case 0x4377: + return (DMA[(Address >> 4) & 7].IndirectBank); + case 0x430A: case 0x431A: case 0x432A: @@ -2562,7 +2507,7 @@ uint8 S9xGetCPU (uint16 Address) // return (Memory.FillRAM[Address]); } -void S9xResetPPU () +static void CommonPPUReset () { PPU.BGMode = 0; PPU.BG3Priority = 0; @@ -2570,6 +2515,7 @@ void S9xResetPPU () PPU.VMA.High = 0; PPU.VMA.Increment = 1; PPU.VMA.Address = 0; + PPU.VMA.FullGraphicCount = 0; PPU.VMA.Shift = 0; @@ -2593,13 +2539,11 @@ void S9xResetPPU () PPU.ClipCounts[4] = 0; PPU.ClipCounts[5] = 0; PPU.ClipWindowOverlapLogic[4] = PPU.ClipWindowOverlapLogic[5] = CLIP_OR; - PPU.ClipWindow1Enable[4] = PPU.ClipWindow1Enable[5] = FALSE; - PPU.ClipWindow2Enable[4] = PPU.ClipWindow2Enable[5] = FALSE; - PPU.ClipWindow1Inside[4] = PPU.ClipWindow1Inside[5] = TRUE; - PPU.ClipWindow2Inside[4] = PPU.ClipWindow2Inside[5] = TRUE; + PPU.ClipWindow1Enable[4] = PPU.ClipWindow1Enable[5] = PPU.ClipWindow2Enable[4] = PPU.ClipWindow2Enable[5] = FALSE; + PPU.ClipWindow1Inside[4] = PPU.ClipWindow1Inside[5] = PPU.ClipWindow2Inside[4] = PPU.ClipWindow2Inside[5] = TRUE; PPU.CGFLIP = 0; - int c; + uint16 c; for (c = 0; c < 256; c++) { IPPU.Red [c] = (c & 7) << 2; @@ -2644,9 +2588,6 @@ void S9xResetPPU () PPU.MatrixA = PPU.MatrixB = PPU.MatrixC = PPU.MatrixD = 0; PPU.CentreX = PPU.CentreY = 0; - PPU.Joypad1ButtonReadPos = 0; - PPU.Joypad2ButtonReadPos = 0; - PPU.Joypad3ButtonReadPos = 0; PPU.CGADD = 0; PPU.FixedColourRed = PPU.FixedColourGreen = PPU.FixedColourBlue = 0; @@ -2668,9 +2609,9 @@ void S9xResetPPU () PPU.VTimerEnabled = FALSE; PPU.HTimerEnabled = FALSE; PPU.HTimerPosition = Settings.H_Max + 1; + PPU.Mosaic = 0; - PPU.BGMosaic [0] = PPU.BGMosaic [1] = FALSE; - PPU.BGMosaic [2] = PPU.BGMosaic [3] = FALSE; + PPU.BGMosaic [0] = PPU.BGMosaic [1] = PPU.BGMosaic [2] = PPU.BGMosaic [3] = FALSE; PPU.Mode7HFlip = FALSE; PPU.Mode7VFlip = FALSE; PPU.Mode7Repeat = 0; @@ -2679,6 +2620,7 @@ void S9xResetPPU () PPU.Window2Left = 1; PPU.Window2Right = 0; PPU.RecomputeClipWindows = TRUE; + PPU.CGFLIPRead = 0; PPU.Need16x8Mulitply = FALSE; PPU.MouseSpeed[0] = PPU.MouseSpeed[1] = 0; @@ -2696,6 +2638,7 @@ void S9xResetPPU () IPPU.DisplayedRenderedFrameCount = 0; IPPU.SkippedFrames = 0; IPPU.FrameSkip = 0; + ZeroMemory (IPPU.TileCached [TILE_2BIT], MAX_2BIT_TILES); ZeroMemory (IPPU.TileCached [TILE_4BIT], MAX_4BIT_TILES); ZeroMemory (IPPU.TileCached [TILE_8BIT], MAX_8BIT_TILES); @@ -2711,16 +2654,11 @@ void S9xResetPPU () IPPU.RenderedScreenWidth = SNES_WIDTH; IPPU.RenderedScreenHeight = SNES_HEIGHT; IPPU.XB = NULL; + for (c = 0; c < 256; c++) IPPU.ScreenColors [c] = c; S9xFixColourBrightness (); IPPU.PreviousLine = IPPU.CurrentLine = 0; - IPPU.Joypads[0] = IPPU.Joypads[1] = IPPU.Joypads[2] = 0; - IPPU.Joypads[3] = IPPU.Joypads[4] = 0; - IPPU.SuperScope = 0; - IPPU.Mouse[0] = IPPU.Mouse[1] = 0; - IPPU.PrevMouseX[0] = IPPU.PrevMouseX[1] = 256 / 2; - IPPU.PrevMouseY[0] = IPPU.PrevMouseY[1] = 224 / 2; if (Settings.ControllerOption == 0) IPPU.Controller = SNES_MAX_CONTROLLER_OPTIONS - 1; @@ -2736,7 +2674,31 @@ void S9xResetPPU () S9xProcessMouse (0); S9xProcessMouse (1); } - for (c = 0; c < 0x8000; c += 0x100) + + ZeroMemory (&Memory.FillRAM [0x2100], 0x100); + ZeroMemory (&Memory.FillRAM [0x4200], 0x100); + ZeroMemory (&Memory.FillRAM [0x4000], 0x100); + // For BS Suttehakkun 2... + ZeroMemory (&Memory.FillRAM [0x1000], 0x1000); + + Memory.FillRAM[0x4201]=Memory.FillRAM[0x4213]=0xFF; +} + +void S9xResetPPU () +{ + CommonPPUReset (); + PPU.Joypad1ButtonReadPos = 0; + PPU.Joypad2ButtonReadPos = 0; + PPU.Joypad3ButtonReadPos = 0; + + IPPU.Joypads[0] = IPPU.Joypads[1] = IPPU.Joypads[2] = 0; + IPPU.Joypads[3] = IPPU.Joypads[4] = 0; + IPPU.SuperScope = 0; + IPPU.Mouse[0] = IPPU.Mouse[1] = 0; + IPPU.PrevMouseX[0] = IPPU.PrevMouseX[1] = 256 / 2; + IPPU.PrevMouseY[0] = IPPU.PrevMouseY[1] = 224 / 2; + + for (uint16 c = 0; c < 0x8000; c += 0x100) { if ( !Settings.SuperFX ) { @@ -2750,168 +2712,15 @@ void S9xResetPPU () memset (&Memory.FillRAM [c], c >> 8, 0x100); } } - - ZeroMemory (&Memory.FillRAM [0x2100], 0x100); - ZeroMemory (&Memory.FillRAM [0x4200], 0x100); - ZeroMemory (&Memory.FillRAM [0x4000], 0x100); - // For BS Suttehakkun 2... - ZeroMemory (&Memory.FillRAM [0x1000], 0x1000); - - Memory.FillRAM[0x4201]=Memory.FillRAM[0x4213]=0xFF; } void S9xSoftResetPPU () { - PPU.BGMode = 0; - PPU.BG3Priority = 0; - PPU.Brightness = 0; - PPU.VMA.High = 0; - PPU.VMA.Increment = 1; - PPU.VMA.Address = 0; - PPU.VMA.FullGraphicCount = 0; - PPU.VMA.Shift = 0; - - for (uint8 B = 0; B != 4; B++) - { - PPU.BG[B].SCBase = 0; - PPU.BG[B].VOffset = 0; - PPU.BG[B].HOffset = 0; - PPU.BG[B].BGSize = 0; - PPU.BG[B].NameBase = 0; - PPU.BG[B].SCSize = 0; - - PPU.ClipCounts[B] = 0; - PPU.ClipWindowOverlapLogic [B] = CLIP_OR; - PPU.ClipWindow1Enable[B] = FALSE; - PPU.ClipWindow2Enable[B] = FALSE; - PPU.ClipWindow1Inside[B] = TRUE; - PPU.ClipWindow2Inside[B] = TRUE; - } - - PPU.ClipCounts[4] = 0; - PPU.ClipCounts[5] = 0; - PPU.ClipWindowOverlapLogic[4] = PPU.ClipWindowOverlapLogic[5] = CLIP_OR; - PPU.ClipWindow1Enable[4] = PPU.ClipWindow1Enable[5] = FALSE; - PPU.ClipWindow2Enable[4] = PPU.ClipWindow2Enable[5] = FALSE; - PPU.ClipWindow1Inside[4] = PPU.ClipWindow1Inside[5] = TRUE; - PPU.ClipWindow2Inside[4] = PPU.ClipWindow2Inside[5] = TRUE; - - PPU.CGFLIP = 0; - int c; - for (c = 0; c < 256; c++) - { - IPPU.Red [c] = (c & 7) << 2; - IPPU.Green [c] = ((c >> 3) & 7) << 2; - IPPU.Blue [c] = ((c >> 6) & 2) << 3; - PPU.CGDATA [c] = IPPU.Red [c] | (IPPU.Green [c] << 5) | - (IPPU.Blue [c] << 10); - } - - PPU.FirstSprite = 0; - PPU.LastSprite = 127; - for (int Sprite = 0; Sprite < 128; Sprite++) - { - PPU.OBJ[Sprite].HPos = 0; - PPU.OBJ[Sprite].VPos = 0; - PPU.OBJ[Sprite].VFlip = 0; - PPU.OBJ[Sprite].HFlip = 0; - PPU.OBJ[Sprite].Priority = 0; - PPU.OBJ[Sprite].Palette = 0; - PPU.OBJ[Sprite].Name = 0; - PPU.OBJ[Sprite].Size = 0; - } - PPU.OAMPriorityRotation = 0; - PPU.OAMWriteRegister = 0; - PPU.RangeTimeOver = 0; -#ifndef NO_OPEN_BUS - PPU.OpenBus1 = 0; - PPU.OpenBus2 = 0; -#endif - - PPU.OAMFlip = 0; - PPU.OAMTileAddress = 0; - PPU.OAMAddr = 0; - PPU.IRQVBeamPos = 0; - PPU.IRQHBeamPos = 0; - PPU.VBeamPosLatched = 0; - PPU.HBeamPosLatched = 0; - - PPU.HBeamFlip = 0; - PPU.VBeamFlip = 0; - PPU.HVBeamCounterLatched = 0; - - PPU.MatrixA = PPU.MatrixB = PPU.MatrixC = PPU.MatrixD = 0; - PPU.CentreX = PPU.CentreY = 0; + CommonPPUReset (); // PPU.Joypad1ButtonReadPos = 0; // PPU.Joypad2ButtonReadPos = 0; // PPU.Joypad3ButtonReadPos = 0; - PPU.CGADD = 0; - PPU.FixedColourRed = PPU.FixedColourGreen = PPU.FixedColourBlue = 0; - PPU.SavedOAMAddr = 0; - PPU.ScreenHeight = SNES_HEIGHT; - PPU.WRAM = 0; - PPU.BG_Forced = 0; - PPU.ForcedBlanking = TRUE; - PPU.OBJThroughMain = FALSE; - PPU.OBJThroughSub = FALSE; - PPU.OBJSizeSelect = 0; - PPU.OBJNameSelect = 0; - PPU.OBJNameBase = 0; - PPU.OBJAddition = FALSE; - PPU.OAMReadFlip = 0; - PPU.BGnxOFSbyte = 0; - ZeroMemory (PPU.OAMData, 512 + 32); - - PPU.VTimerEnabled = FALSE; - PPU.HTimerEnabled = FALSE; - PPU.HTimerPosition = Settings.H_Max + 1; - PPU.Mosaic = 0; - PPU.BGMosaic [0] = PPU.BGMosaic [1] = FALSE; - PPU.BGMosaic [2] = PPU.BGMosaic [3] = FALSE; - PPU.Mode7HFlip = FALSE; - PPU.Mode7VFlip = FALSE; - PPU.Mode7Repeat = 0; - PPU.Window1Left = 1; - PPU.Window1Right = 0; - PPU.Window2Left = 1; - PPU.Window2Right = 0; - PPU.RecomputeClipWindows = TRUE; - PPU.CGFLIPRead = 0; - PPU.Need16x8Mulitply = FALSE; - PPU.MouseSpeed[0] = PPU.MouseSpeed[1] = 0; - IPPU.ColorsChanged = TRUE; - IPPU.HDMA = 0; - IPPU.HDMAStarted = FALSE; - IPPU.MaxBrightness = 0; - IPPU.LatchedBlanking = 0; - IPPU.OBJChanged = TRUE; - IPPU.RenderThisFrame = TRUE; - IPPU.DirectColourMapsNeedRebuild = TRUE; - IPPU.FrameCount = 0; - IPPU.RenderedFramesCount = 0; - IPPU.DisplayedRenderedFrameCount = 0; - IPPU.SkippedFrames = 0; - IPPU.FrameSkip = 0; - ZeroMemory (IPPU.TileCached [TILE_2BIT], MAX_2BIT_TILES); - ZeroMemory (IPPU.TileCached [TILE_4BIT], MAX_4BIT_TILES); - ZeroMemory (IPPU.TileCached [TILE_8BIT], MAX_8BIT_TILES); -#ifdef CORRECT_VRAM_READS - IPPU.VRAMReadBuffer = 0; // XXX: FIXME: anything better? -#else - IPPU.FirstVRAMRead = FALSE; -#endif - IPPU.Interlace = FALSE; - IPPU.InterlaceSprites = FALSE; - IPPU.DoubleWidthPixels = FALSE; - IPPU.DoubleHeightPixels = FALSE; - IPPU.RenderedScreenWidth = SNES_WIDTH; - IPPU.RenderedScreenHeight = SNES_HEIGHT; - IPPU.XB = NULL; - for (c = 0; c < 256; c++) - IPPU.ScreenColors [c] = c; - S9xFixColourBrightness (); - IPPU.PreviousLine = IPPU.CurrentLine = 0; // IPPU.Joypads[0] = IPPU.Joypads[1] = IPPU.Joypads[2] = 0; // IPPU.Joypads[3] = IPPU.Joypads[4] = 0; // IPPU.SuperScope = 0; @@ -2919,30 +2728,8 @@ void S9xSoftResetPPU () // IPPU.PrevMouseX[0] = IPPU.PrevMouseX[1] = 256 / 2; // IPPU.PrevMouseY[0] = IPPU.PrevMouseY[1] = 224 / 2; - if (Settings.ControllerOption == 0) - IPPU.Controller = SNES_MAX_CONTROLLER_OPTIONS - 1; - else - IPPU.Controller = Settings.ControllerOption - 1; - S9xNextController (); - - for (c = 0; c < 2; c++) - memset (&IPPU.Clip [c], 0, sizeof (struct ClipData)); - - if (Settings.MouseMaster) - { - S9xProcessMouse (0); - S9xProcessMouse (1); - } - for (c = 0; c < 0x8000; c += 0x100) + for (uint16 c = 0; c < 0x8000; c += 0x100) memset (&Memory.FillRAM [c], c >> 8, 0x100); - - ZeroMemory (&Memory.FillRAM [0x2100], 0x100); - ZeroMemory (&Memory.FillRAM [0x4200], 0x100); - ZeroMemory (&Memory.FillRAM [0x4000], 0x100); - // For BS Suttehakkun 2... - ZeroMemory (&Memory.FillRAM [0x1000], 0x1000); - - Memory.FillRAM[0x4201]=Memory.FillRAM[0x4213]=0xFF; } void S9xProcessMouse (int which1) @@ -3494,7 +3281,7 @@ printf ("%06x: %d\n", t, FxEmulate (2000000)); uint8 REGISTER_4212() { - GetBank = 0; + uint8 GetBank = 0; if (CPU.V_Counter >= PPU.ScreenHeight + FIRST_VISIBLE_LINE && CPU.V_Counter < PPU.ScreenHeight + FIRST_VISIBLE_LINE + 3) GetBank = 1; @@ -3508,8 +3295,8 @@ uint8 REGISTER_4212() void FLUSH_REDRAW () { - if (IPPU.PreviousLine != IPPU.CurrentLine) - S9xUpdateScreen (); + if (IPPU.PreviousLine != IPPU.CurrentLine) + S9xUpdateScreen (); } void REGISTER_2104 (uint8 byte) @@ -3728,19 +3515,25 @@ void REGISTER_2122(uint8 Byte) { if ((Byte & 0x7f) != (PPU.CGDATA[PPU.CGADD] >> 8)) { +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) - FLUSH_REDRAW (); +#endif + FLUSH_REDRAW (); PPU.CGDATA[PPU.CGADD] &= 0x00FF; PPU.CGDATA[PPU.CGADD] |= (Byte & 0x7f) << 8; IPPU.ColorsChanged = TRUE; +#ifndef FOREVER_16_BIT 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]); +#ifndef FOREVER_16_BIT } +#endif } PPU.CGADD++; } @@ -3748,19 +3541,25 @@ void REGISTER_2122(uint8 Byte) { if (Byte != (uint8) (PPU.CGDATA[PPU.CGADD] & 0xff)) { +#ifndef FOREVER_16_BIT if (Settings.SixteenBit) - FLUSH_REDRAW (); +#endif + FLUSH_REDRAW (); PPU.CGDATA[PPU.CGADD] &= 0x7F00; PPU.CGDATA[PPU.CGADD] |= Byte; IPPU.ColorsChanged = TRUE; +#ifndef FOREVER_16_BIT 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]); +#ifndef FOREVER_16_BIT } +#endif } } PPU.CGFLIP ^= 1; diff --git a/source/snes9x.h b/source/snes9x.h index 61281aa..e9ed479 100644 --- a/source/snes9x.h +++ b/source/snes9x.h @@ -342,7 +342,9 @@ struct SSettings{ bool8 FixFrequency; /* Graphics options */ +#ifndef FOREVER_16_BIT bool8 SixteenBit; +#endif bool8 Transparency; bool8 SupportHiRes; bool8 Mode7Interpolate; diff --git a/source/tile.cpp b/source/tile.cpp index d4cdcbf..7e996a9 100644 --- a/source/tile.cpp +++ b/source/tile.cpp @@ -97,7 +97,7 @@ extern uint32 HeadMask [4]; extern uint32 TailMask [5]; -uint8 ConvertTile (uint8 *pCache, uint32 TileAddr) +static uint8 ConvertTile (uint8 *pCache, uint32 TileAddr) { register uint8 *tp = &Memory.VRAM[TileAddr]; uint32 *p = (uint32 *) pCache; @@ -215,8 +215,10 @@ uint8 ConvertTile (uint8 *pCache, uint32 TileAddr) } return (non_zero ? TRUE : BLANK_TILE); } +#define PLOT_PIXEL(screen, pixel) (pixel) -void WRITE_4PIXELS (uint32 Offset, uint8 *Pixels) +#ifndef FOREVER_16_BIT +static void WRITE_4PIXELS (uint32 Offset, uint8 *Pixels) { uint8 Pixel; uint8 *Screen = GFX.S + Offset; @@ -236,7 +238,7 @@ void WRITE_4PIXELS (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS_FLIPPED (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS_FLIPPED (uint32 Offset, uint8 *Pixels) { uint8 Pixel; uint8 *Screen = GFX.S + Offset; @@ -256,7 +258,7 @@ void WRITE_4PIXELS_FLIPPED (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELSx2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELSx2 (uint32 Offset, uint8 *Pixels) { uint8 Pixel; uint8 *Screen = GFX.S + Offset; @@ -276,7 +278,7 @@ void WRITE_4PIXELSx2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS_FLIPPEDx2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS_FLIPPEDx2 (uint32 Offset, uint8 *Pixels) { uint8 Pixel; uint8 *Screen = GFX.S + Offset; @@ -296,7 +298,7 @@ void WRITE_4PIXELS_FLIPPEDx2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELSx2x2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELSx2x2 (uint32 Offset, uint8 *Pixels) { uint8 Pixel; uint8 *Screen = GFX.S + Offset; @@ -318,7 +320,7 @@ void WRITE_4PIXELSx2x2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels) { uint8 Pixel; uint8 *Screen = GFX.S + Offset; @@ -412,14 +414,14 @@ void DrawLargePixel (uint32 Tile, uint32 Offset, register uint8 *sp = GFX.S + Offset; uint8 *Depth = GFX.DB + Offset; uint8 pixel; -#define PLOT_PIXEL(screen, pixel) (pixel) RENDER_TILE_LARGE (((uint8) GFX.ScreenColors [pixel]), PLOT_PIXEL) } +#endif -void WRITE_4PIXELS16 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.DB + Offset; @@ -437,9 +439,9 @@ void WRITE_4PIXELS16 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_FLIPPED (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_FLIPPED (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.DB + Offset; @@ -457,9 +459,9 @@ void WRITE_4PIXELS16_FLIPPED (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16x2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16x2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.DB + Offset; @@ -477,9 +479,9 @@ void WRITE_4PIXELS16x2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_FLIPPEDx2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_FLIPPEDx2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.DB + Offset; @@ -497,9 +499,9 @@ void WRITE_4PIXELS16_FLIPPEDx2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16x2x2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16x2x2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.DB + Offset; @@ -519,9 +521,9 @@ void WRITE_4PIXELS16x2x2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_FLIPPEDx2x2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.DB + Offset; @@ -614,9 +616,9 @@ void DrawLargePixel16 (uint32 Tile, uint32 Offset, RENDER_TILE_LARGE (GFX.ScreenColors [pixel], PLOT_PIXEL) } -void WRITE_4PIXELS16_ADD (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_ADD (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; @@ -646,9 +648,9 @@ void WRITE_4PIXELS16_ADD (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_FLIPPED_ADD (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_FLIPPED_ADD (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; @@ -678,9 +680,9 @@ void WRITE_4PIXELS16_FLIPPED_ADD (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_ADD1_2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_ADD1_2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; @@ -710,9 +712,9 @@ void WRITE_4PIXELS16_ADD1_2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_FLIPPED_ADD1_2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_FLIPPED_ADD1_2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; @@ -742,9 +744,9 @@ void WRITE_4PIXELS16_FLIPPED_ADD1_2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_SUB (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_SUB (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; @@ -774,9 +776,9 @@ void WRITE_4PIXELS16_SUB (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_FLIPPED_SUB (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_FLIPPED_SUB (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; @@ -806,9 +808,9 @@ void WRITE_4PIXELS16_FLIPPED_SUB (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_SUB1_2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_SUB1_2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; @@ -838,9 +840,9 @@ void WRITE_4PIXELS16_SUB1_2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_FLIPPED_SUB1_2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_FLIPPED_SUB1_2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; @@ -951,9 +953,9 @@ void DrawClippedTile16Sub1_2 (uint32 Tile, uint32 Offset, RENDER_CLIPPED_TILE(WRITE_4PIXELS16_SUB1_2, WRITE_4PIXELS16_FLIPPED_SUB1_2, 4) } -void WRITE_4PIXELS16_ADDF1_2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_ADDF1_2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; @@ -977,9 +979,9 @@ void WRITE_4PIXELS16_ADDF1_2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_FLIPPED_ADDF1_2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_FLIPPED_ADDF1_2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; @@ -1003,9 +1005,9 @@ void WRITE_4PIXELS16_FLIPPED_ADDF1_2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_SUBF1_2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_SUBF1_2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; @@ -1029,9 +1031,9 @@ void WRITE_4PIXELS16_SUBF1_2 (uint32 Offset, uint8 *Pixels) #undef FN } -void WRITE_4PIXELS16_FLIPPED_SUBF1_2 (uint32 Offset, uint8 *Pixels) +static void WRITE_4PIXELS16_FLIPPED_SUBF1_2 (uint32 Offset, uint8 *Pixels) { - uint32 Pixel; + uint8 Pixel; uint16 *Screen = (uint16 *) GFX.S + Offset; uint8 *Depth = GFX.ZBuffer + Offset; uint8 *SubDepth = GFX.SubZBuffer + Offset; -- cgit v1.2.3