From f35d14a8b4fb55b0ea0f8eddbcb17ee90d3e26fc Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 26 Oct 2016 19:29:10 -0400 Subject: [PATCH] VS System initial commits --- .../Consoles/Nintendo/NES/NES.Core.cs | 48 ++++++++++++- .../Consoles/Nintendo/NES/NES.IStatable.cs | 10 ++- .../Consoles/Nintendo/NES/NES.cs | 11 +++ .../Consoles/Nintendo/NES/Palettes.cs | 69 +++++++++++++++++++ 4 files changed, 135 insertions(+), 3 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs index e105d51117..d09c060f3d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.Core.cs @@ -37,6 +37,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES //variable to change controller read/write behaviour when keyboard is attached public bool _iskeyboard = false; + //variable set when VS system games are running + public bool _isVS = false; + //since prg reg for VS System is set in the controller regs, it is convenient to have it here + //instead of in the board + public byte VS_chr_reg; + public byte VS_prg_reg; + //various VS controls + public byte[] VS_dips = new byte[8]; + public byte VS_service = 0; + public byte VS_coin_inserted=0; + public byte VS_ROM_control; // new input system NESControlSettings ControllerSettings; // this is stored internally so that a new change of settings won't replace @@ -272,7 +283,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ram[0x701] = 0xFF; } } - } @@ -516,6 +526,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES case 0x4014: /*OAM DMA*/ break; case 0x4015: return (byte)((byte)(apu.ReadReg(addr) & 0xDF) + (byte)(DB & 0x20)); case 0x4016: + if (_isVS) + { + byte ret = 0; + // for whatever reason, in VS left and right controller have swapped regs + ret = read_joyport(0x4017); + ret &= 1; + ret = (byte)(ret | (VS_service << 2) | (VS_dips[0] << 3) | (VS_dips[1] << 4) | (VS_coin_inserted << 5) | (VS_ROM_control<<7)); + + return ret; + } + else { // special hardware glitch case ret_spec = read_joyport(addr); @@ -534,6 +555,18 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES // eventually this will be the keyboard function, but for now it is a place holder (no keys pressed) return 0x1E; } + else if (_isVS) + { + byte ret = 0; + // for whatever reason, in VS left and right controller have swapped regs + ret = read_joyport(0x4016); + ret &= 1; + + ret = (byte)(ret | (VS_dips[2] << 2) | (VS_dips[3] << 3) | (VS_dips[4] << 4) | (VS_dips[5] << 5) | (VS_dips[6] << 6) | (VS_dips[7] << 7)); + + return ret; + + } else { return read_joyport(addr); @@ -618,6 +651,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES { // eventually keyboard emulation will go here } + else if (_isVS) + { + write_joyport(val); + VS_chr_reg = (byte)((val & 0x4)>>2); + + //TODO: does other stuff for dual system + + //this is actually different then assignment + VS_prg_reg = (byte)((val & 0x4)>>2); + + } else { write_joyport(val); @@ -666,7 +710,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES /// Sets the provided palette as current. /// Applies the current deemph settings if needed to expand a 64-entry palette to 512 /// - private void SetPalette(byte[,] pal) + public void SetPalette(byte[,] pal) { int nColors = pal.GetLength(0); int nElems = pal.GetLength(1); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs index ed36a60937..61b2aa71ca 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.IStatable.cs @@ -76,8 +76,16 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES ser.Sync("special_case_delay", ref special_case_delay); ser.Sync("do_the_reread", ref do_the_reread); + //VS related + ser.Sync("VS", ref _isVS); + ser.Sync("VS_CHR", ref VS_chr_reg); + ser.Sync("VS_PRG", ref VS_prg_reg); + ser.Sync("VS_DIPS", ref VS_dips, false); + ser.Sync("VS_Service", ref VS_service); + ser.Sync("VS_Coin", ref VS_coin_inserted); + ser.Sync("VS_ROM_Control", ref VS_ROM_control); - ser.BeginSection("Board"); + ser.BeginSection("Board"); Board.SyncState(ser); if (Board is NESBoardBase && !((NESBoardBase)Board).SyncStateFlag) throw new InvalidOperationException("the current NES mapper didnt call base.SyncState"); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs index 9d025046f0..0b33278d9d 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/NES.cs @@ -57,6 +57,17 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES } PutSettings((NESSettings)Settings ?? new NESSettings()); + // we need to put this here because the line directly above will overwrite palette intialization anywhere else + if (_isVS) + { + Console.WriteLine(palette_compiled[0]); + //Settings.Palette = (byte[,])Palettes.palette_2c04.Clone(); + SetPalette(Palettes.palette_2c04_B); + Console.WriteLine(palette_compiled[0]); + Console.WriteLine(Palettes.QuickNESPalette[0, 0]); + Console.WriteLine(Palettes.palette_2c04[0, 0]); + } + ser.Register(cpu); diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs index 568fda9b05..809671e402 100644 --- a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Palettes.cs @@ -187,5 +187,74 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES {0, 0, 0}, {0, 0, 0}, }; + + public static byte[,] palette_2c04_B = + { + {4<<5, 3<<5, 0<<5}, + {3<<5, 2<<5, 6<<5}, + {0<<5, 4<<5, 4<<5}, + {6<<5, 6<<5, 0<<5}, + {0<<5, 0<<5, 0<<5}, + {7<<5, 5<<5, 5<<5}, + {0<<5, 1<<5, 4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, + {6<<5, 3<<5, 7<<5}, + {5<<5, 6<<5, 7<<5}, + {3<<5, 6<<5, 0<<5}, + {6<<5, 5<<5, 7<<5}, + {0<<5, 7<<5, 7<<5}, + {1<<5, 2<<5, 0<<5}, + }; + } //class palettes } //namespace