From 25dfe00203b2e81f605272818f7a62063777f1b1 Mon Sep 17 00:00:00 2001 From: nattthebear Date: Fri, 11 Nov 2016 18:42:44 -0500 Subject: [PATCH] nes: vs lightgun stuff. hogan's alley seems to do something now --- .../Consoles/Nintendo/NES/NES.Core.cs | 10 ++-- .../Consoles/Nintendo/NES/PPU.cs | 59 +++++++++++++++++-- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs index a5b33c264c..c1a9e96e7b 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs @@ -940,11 +940,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { switch (cart.palette) { - case "2C05": SetPalette(Palettes.palette_2c03_2c05); break; - case "2C04-1": SetPalette(Palettes.palette_2c04_001); break; - case "2C04-2": SetPalette(Palettes.palette_2c04_002); break; - case "2C04-3": SetPalette(Palettes.palette_2c04_003); break; - case "2C04-4": SetPalette(Palettes.palette_2c04_004); break; + case "2C05": SetPalette(Palettes.palette_2c03_2c05); ppu.CurrentLuma = PPU.PaletteLuma2C03; break; + case "2C04-1": SetPalette(Palettes.palette_2c04_001); ppu.CurrentLuma = PPU.PaletteLuma2C04_1; break; + case "2C04-2": SetPalette(Palettes.palette_2c04_002); ppu.CurrentLuma = PPU.PaletteLuma2C04_2; break; + case "2C04-3": SetPalette(Palettes.palette_2c04_003); ppu.CurrentLuma = PPU.PaletteLuma2C04_3; break; + case "2C04-4": SetPalette(Palettes.palette_2c04_004); ppu.CurrentLuma = PPU.PaletteLuma2C04_4; break; } //since this will run for every VS game, let's get security setting too diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs index d39592cd2c..16c986736f 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/PPU.cs @@ -40,6 +40,60 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES public DebugCallback NTViewCallback; public DebugCallback PPUViewCallback; + // luminance of each palette value for lightgun calculations + // this is all 101% guesses, and most certainly various levels of wrong + public static readonly int[] PaletteLumaNES = + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 0, 0, + 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0, 0, + 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 0, 0 + }; + + public static readonly int[] PaletteLuma2C03 = + { + 27, 9, 3, 22, 9, 11, 16, 20, 18, 14, 19, 25, 14, 0, 0, 0, + 45, 23, 17, 12, 14, 16, 13, 30, 27, 27, 25, 34, 28, 0, 0, 0, + 63, 42, 37, 35, 18, 37, 39, 45, 50, 44, 45, 52, 49, 0, 0, 0, + 63, 52, 48, 50, 43, 48, 54, 59, 60, 55, 54, 52, 50, 0, 0, 0, + }; + + public static readonly int[] PaletteLuma2C04_1 = + { + 48, 35, 13, 37, 28, 14, 18, 16, 63, 27, 45, 11, 9, 50, 18, 63, + 42, 45, 12, 44, 50, 48, 54, 17, 52, 52, 0, 3, 54, 36, 18, 9, + 1, 52, 50, 45, 49, 14, 34, 14, 0, 20, 43, 16, 12, 3, 39, 0, + 0, 27, 45, 19, 55, 22, 58, 30, 12, 23, 25, 9, 60, 37, 27, 54, + }; + + public static readonly int[] PaletteLuma2C04_2 = + { + 0, 45, 27, 55, 54, 37, 28, 52, 13, 12, 60, 43, 63, 35, 50, 25, + 12, 42, 16, 54, 34, 44, 3, 37, 18, 18, 1, 52, 48, 18, 0, 22, + 9, 54, 39, 50, 23, 12, 45, 3, 14, 52, 27, 14, 17, 0, 50, 63, + 45, 9, 45, 30, 14, 9, 16, 27, 0, 49, 20, 58, 48, 11, 19, 36, + }; + + public static readonly int[] PaletteLuma2C04_3 = + { + 14, 37, 54, 45, 25, 63, 52, 14, 9, 0, 54, 18, 16, 54, 45, 50, + 37, 28, 11, 17, 27, 27, 30, 34, 27, 22, 0, 3, 13, 16, 43, 48, + 35, 12, 1, 58, 9, 45, 39, 63, 44, 9, 42, 18, 23, 36, 0, 12, + 49, 3, 55, 50, 20, 45, 50, 18, 19, 0, 48, 60, 12, 52, 52, 14, + }; + + public static readonly int[] PaletteLuma2C04_4 = + { + 27, 22, 28, 50, 0, 48, 9, 30, 45, 12, 45, 1, 54, 58, 25, 55, + 37, 3, 17, 43, 0, 18, 16, 39, 45, 34, 37, 27, 9, 0, 54, 42, + 11, 19, 20, 3, 12, 14, 27, 16, 14, 54, 23, 12, 9, 60, 36, 18, + 50, 63, 18, 13, 52, 52, 63, 50, 0, 45, 35, 52, 44, 48, 49, 14, + }; + + private int[] _currentLuma = PaletteLumaNES; + + public int[] CurrentLuma { get { return _currentLuma; } set { _currentLuma = value; } } + // true = light sensed public bool LightGunCallback(int x, int y) { @@ -65,10 +119,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES goto loopout; short s = xbuf[j * 256 + i]; - int lum = s & 0x30; - if ((s & 0x0f) >= 0x0e) - lum = 0; - sum += lum; + sum += _currentLuma[s]; } } loopout: