From f35d14a8b4fb55b0ea0f8eddbcb17ee90d3e26fc Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 26 Oct 2016 19:29:10 -0400 Subject: [PATCH 1/3] 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<<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<<5}, + {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 From 42d1bc65f1c4e0ab16f9c80ae9e4eae5b49457d6 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 26 Oct 2016 19:30:18 -0400 Subject: [PATCH 2/3] VS system initial commits --- .../Consoles/Nintendo/NES/Boards/VS_M99.cs | 152 ++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VS_M99.cs diff --git a/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VS_M99.cs b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VS_M99.cs new file mode 100644 index 0000000000..e2f46362eb --- /dev/null +++ b/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/Boards/VS_M99.cs @@ -0,0 +1,152 @@ +using System; +using BizHawk.Common; + +namespace BizHawk.Emulation.Cores.Nintendo.NES +{ + //VS System Mapper 99 + + [NES.INESBoardImplPriority] + public sealed class MAPPER99 : NES.NESBoardBase + { + //configuration + int prg_byte_mask, chr_mask; + + //state + int chr; + + [MapperProp] + public byte Dip_Switch_1; + [MapperProp] + public byte Dip_Switch_2; + [MapperProp] + public byte Dip_Switch_3; + [MapperProp] + public byte Dip_Switch_4; + [MapperProp] + public byte Dip_Switch_5; + [MapperProp] + public byte Dip_Switch_6; + [MapperProp] + public byte Dip_Switch_7; + [MapperProp] + public byte Dip_Switch_8; + + //the VS actually does have 2 KB of nametable address space + //let's make the extra space here, instead of in the main NES to avoid confusion + byte[] CIRAM_VS = new byte[0x800]; + + public override bool Configure(NES.EDetectionOrigin origin) + { + //configure + switch (Cart.board_type) + { + case "MAPPER099": + NES._isVS = true; + break; + default: + return false; + } + + prg_byte_mask = Cart.prg_size * 1024 - 1; + chr_mask = (Cart.chr_size / 8) - 1; + + AutoMapperProps.Apply(this); + + + //update the state of the dip switches + //this is only done at power on + NES.VS_dips[0] = (byte)(Dip_Switch_1 & 1); + NES.VS_dips[1] = (byte)(Dip_Switch_2 & 1); + NES.VS_dips[2] = (byte)(Dip_Switch_3 & 1); + NES.VS_dips[3] = (byte)(Dip_Switch_4 & 1); + NES.VS_dips[4] = (byte)(Dip_Switch_5 & 1); + NES.VS_dips[5] = (byte)(Dip_Switch_6 & 1); + NES.VS_dips[6] = (byte)(Dip_Switch_7 & 1); + NES.VS_dips[7] = (byte)(Dip_Switch_8 & 1); + + return true; + } + + // this now tracks coins + public override void WriteEXP(int addr, byte value) + { + //but we don't actually need to do anything yet + } + + public override byte ReadEXP(int addr) + { + //what are we reading? + return 0; + } + + public override byte ReadPPU(int addr) + { + if (addr < 0x2000) + { + return VROM[(addr & 0x1FFF) + (NES.VS_chr_reg << 13)]; + } + else + { + addr = addr - 0x2000; + if (addr<0x800) + { + return NES.CIRAM[addr]; + } + else + { + return CIRAM_VS[addr-0x800]; + } + + } + } + + public override void WritePPU(int addr, byte value) + { + if (addr < 0x2000) + { + if (VRAM != null) + VRAM[addr] = value; + } + else + { + addr = addr - 0x2000; + if (addr < 0x800) + { + NES.CIRAM[addr] = value; + } + else + { + CIRAM_VS[addr-0x800] = value; + } + } + } + + public override void SyncState(Serializer ser) + { + base.SyncState(ser); + ser.Sync("chr", ref chr); + ser.Sync("VS_CIRAM", ref CIRAM_VS, false); + ser.Sync("Dip_1", ref Dip_Switch_1); + ser.Sync("Dip_2", ref Dip_Switch_2); + ser.Sync("Dip_3", ref Dip_Switch_3); + ser.Sync("Dip_4", ref Dip_Switch_4); + ser.Sync("Dip_5", ref Dip_Switch_5); + ser.Sync("Dip_6", ref Dip_Switch_6); + ser.Sync("Dip_7", ref Dip_Switch_7); + ser.Sync("Dip_8", ref Dip_Switch_8); + } + + public override byte ReadPRG(int addr) + { + if (Cart.prg_size==40) + { + return ROM[(addr & 0x1FFF) + (NES.VS_prg_reg << 13)]; + } + else + { + return ROM[addr]; + } + + } + } +} From 53a96f3b910c987271b1aa69137ebc346d23c075 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Wed, 26 Oct 2016 19:32:55 -0400 Subject: [PATCH 3/3] Update BizHawk.Emulation.Cores.csproj --- BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index bdd367a11f..5bbdcae4d5 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -780,6 +780,7 @@ + @@ -1190,4 +1191,4 @@ --> - \ No newline at end of file +