From d87d5eb0e0312a465043cd226072968691840ff8 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Thu, 2 Mar 2017 11:58:36 +0800 Subject: [PATCH] Coleco Turbo Controller Functional --- .../Consoles/Coleco/ColecoControllers.cs | 75 ++++++------------- .../Consoles/Coleco/ColecoVision.cs | 12 +-- .../Consoles/Coleco/TMS9918A.cs | 36 ++------- 3 files changed, 36 insertions(+), 87 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs index f42d2588ee..ee0a832e19 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoControllers.cs @@ -143,42 +143,24 @@ namespace BizHawk.Emulation.Cores.ColecoVision { if (left_mode) { - byte retval = 0x7B; + byte retval = 0x4B; if (c.IsPressed(Definition.BoolButtons[0])) retval &= 0x3F; - /* - if (c.IsPressed(Definition.BoolButtons[1])) retval &= 0xF7; - if (c.IsPressed(Definition.BoolButtons[2])) retval &= 0xFB; - if (c.IsPressed(Definition.BoolButtons[3])) retval &= 0xFD; - if (c.IsPressed(Definition.BoolButtons[4])) retval &= 0xFE; - if (c.IsPressed(Definition.BoolButtons[5])) retval &= 0x7F; - if (c.IsPressed(Definition.BoolButtons[6])) retval &= 0xDF; - if (c.IsPressed(Definition.BoolButtons[7])) retval &= 0xEF; - */ + int x = (int)c.GetFloat(Definition.FloatControls[0]); int y = (int)c.GetFloat(Definition.FloatControls[1]); - retval &= CalcDirection(x, y); + retval |= CalcDirection(x, y); - //Console.WriteLine(retval); return retval; } else { - byte retval = 0x7B; + byte retval = 0x4B; if (c.IsPressed(Definition.BoolButtons[0])) retval &= 0x3F; - /* - if (c.IsPressed(Definition.BoolButtons[1])) retval &= 0xF7; - if (c.IsPressed(Definition.BoolButtons[2])) retval &= 0xFB; - if (c.IsPressed(Definition.BoolButtons[3])) retval &= 0xFD; - if (c.IsPressed(Definition.BoolButtons[4])) retval &= 0xFE; - if (c.IsPressed(Definition.BoolButtons[5])) retval &= 0x7F; - if (c.IsPressed(Definition.BoolButtons[6])) retval &= 0xDF; - if (c.IsPressed(Definition.BoolButtons[7])) retval &= 0xEF; - */ + int x = (int)c.GetFloat(Definition.FloatControls[0]); int y = (int)c.GetFloat(Definition.FloatControls[1]); - retval &= CalcDirection(x, y); + retval |= CalcDirection(x, y); - //Console.WriteLine(retval); return retval; } } @@ -190,7 +172,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision private static readonly string[] BaseBoolDefinition = { - "Pedal", "T1", "T2", "T3", "T4", "T5", "T6", "T7" + "Pedal" }; // x and y are both assumed to be in [-127, 127] @@ -199,41 +181,26 @@ namespace BizHawk.Emulation.Cores.ColecoVision private static byte CalcDirection(int x, int y) { y = -y; // vflip to match the arrangement of FloatControllerButtons - + /* // deadzone: if we're less than ? units from the origin, return no direction if (x * x + y * y < Deadzone * Deadzone) { - return 0x7F; // nothing pressed + return 0x0F; // nothing pressed } + */ + if ((y >= 0 && y>=Math.Abs(x))) + return 0x3F; + if ((y < 0 && Math.Abs(y) >= Math.Abs(x))) + return 0x1F; + if ((x > 0 && Math.Abs(y) < x)) + return 0x0F; + if ((x < 0 && Math.Abs(y) < Math.Abs(x))) + return 0x2F; - double t = Math.Atan2(y, x) * 8.0 / Math.PI; - int i = (int)Math.Round(t); - return FloatControllerButtons[i & 15]; + Console.WriteLine("Error"); + return 0x1F; } - private const int Deadzone = 50; - - private static byte[] FloatControllerButtons = new byte[] - { - 0x6F, // E - 0x4F, // ENE - 0x4F, // NE - 0x4F, // NNE - - 0x4F, // N - 0x5F, // NNW - 0x5F, // NW - 0x5F, // WNW - - 0x5F, // W - 0x7F, // WSW - 0x7F, // SW - 0x7F, // SSW - - 0x7F, // S - 0x6F, // SSE - 0x6F, // SE - 0x6F, // ESE - }; + //private const int Deadzone = 50; } } diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.cs index f1609a02ca..cce91df496 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/ColecoVision.cs @@ -1,6 +1,7 @@ using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Components; using BizHawk.Emulation.Cores.Components.Z80; +using BizHawk.Common.NumberExtensions; using System; namespace BizHawk.Emulation.Cores.ColecoVision @@ -48,7 +49,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision ControllerDeck = new ColecoVisionControllerDeck(this._syncSettings.Port1, this._syncSettings.Port2); - VDP = new TMS9918A(Cpu, ControllerDeck); + VDP = new TMS9918A(Cpu); (ServiceProvider as BasicServiceProvider).Register(VDP); // TODO: hack to allow bios-less operation would be nice, no idea if its feasible @@ -65,8 +66,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision var serviceProvider = ServiceProvider as BasicServiceProvider; serviceProvider.Register(new Disassembler()); serviceProvider.Register(Tracer); - - VDP.Controller = Controller; } public IEmulatorServiceProvider ServiceProvider { get; private set; } @@ -91,8 +90,11 @@ namespace BizHawk.Emulation.Cores.ColecoVision { Cpu.Logger = (s) => Tracer.Put(s); } - VDP.Controller = Controller; - VDP.ExecuteFrame(); + + byte temp_ret1 = ControllerDeck.ReadPort1(Controller, true); + byte temp_ret2 = ControllerDeck.ReadPort2(Controller, true); + + VDP.ExecuteFrame(!temp_ret1.Bit(4), !temp_ret2.Bit(4)); PSG.EndFrame(Cpu.TotalExecutedCycles); if (_isLag) diff --git a/BizHawk.Emulation.Cores/Consoles/Coleco/TMS9918A.cs b/BizHawk.Emulation.Cores/Consoles/Coleco/TMS9918A.cs index e20cb0c604..191a921753 100644 --- a/BizHawk.Emulation.Cores/Consoles/Coleco/TMS9918A.cs +++ b/BizHawk.Emulation.Cores/Consoles/Coleco/TMS9918A.cs @@ -1,11 +1,9 @@ using System; using System.Globalization; -using System.IO; using BizHawk.Common; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Components.Z80; -using BizHawk.Common.NumberExtensions; namespace BizHawk.Emulation.Cores.ColecoVision { @@ -21,9 +19,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision byte VdpBuffer; int TmsMode; - // interrupt control for quadrature reads - bool spin_on1, spin_on2; - bool Mode1Bit { get { return (Registers[1] & 16) > 0; } } bool Mode2Bit { get { return (Registers[0] & 2) > 0; } } bool Mode3Bit { get { return (Registers[1] & 8) > 0; } } @@ -46,12 +41,12 @@ namespace BizHawk.Emulation.Cores.ColecoVision int TmsPatternNameTableBase; int TmsSpriteAttributeBase; - public void ExecuteFrame() + public void ExecuteFrame(bool spin1_I, bool spin2_I) { for (int scanLine = 0; scanLine < 262; scanLine++) { RenderScanline(scanLine); - + if (scanLine == 192) { @@ -63,25 +58,13 @@ namespace BizHawk.Emulation.Cores.ColecoVision Cpu.ExecuteCycles(228); - byte temp_ret1 = Deck.ReadPort1(Controller, true); - byte temp_ret2 = Deck.ReadPort2(Controller, true); - - if (((temp_ret1.Bit(4) && !spin_on1) | ( temp_ret2.Bit(4) && !spin_on2)) && scanLine == 50) + + Cpu.Interrupt = false; + if ((spin1_I | spin2_I) && scanLine == 50) { - if (EnableInterrupts) - Cpu.NonMaskableInterrupt = true; - - if (temp_ret1.Bit(4) && !spin_on1) - spin_on1 = true; - - if (temp_ret2.Bit(4) && !spin_on2) - spin_on2 = true; + Cpu.Interrupt = true; } - if (!temp_ret1.Bit(4)) - spin_on1 = false; - if (!temp_ret2.Bit(4)) - spin_on2 = false; } } @@ -464,13 +447,10 @@ namespace BizHawk.Emulation.Cores.ColecoVision } Z80A Cpu; - ColecoVisionControllerDeck Deck; - public IController Controller; - - public TMS9918A(Z80A cpu, ColecoVisionControllerDeck deck) + + public TMS9918A(Z80A cpu) { this.Cpu = cpu; - this.Deck = deck; } public int[] FrameBuffer = new int[256 * 192];