diff --git a/BizHawk.Emulation.Cores/Calculator/TI83.IDebuggable.cs b/BizHawk.Emulation.Cores/Calculator/TI83.IDebuggable.cs index 1574e819d7..ab88799f79 100644 --- a/BizHawk.Emulation.Cores/Calculator/TI83.IDebuggable.cs +++ b/BizHawk.Emulation.Cores/Calculator/TI83.IDebuggable.cs @@ -12,36 +12,36 @@ namespace BizHawk.Emulation.Cores.Calculators { return new Dictionary { - ["A"] = Cpu.RegisterA, - ["AF"] = Cpu.RegisterAF, - ["B"] = Cpu.RegisterB, - ["BC"] = Cpu.RegisterBC, - ["C"] = Cpu.RegisterC, - ["D"] = Cpu.RegisterD, - ["DE"] = Cpu.RegisterDE, - ["E"] = Cpu.RegisterE, - ["F"] = Cpu.RegisterF, - ["H"] = Cpu.RegisterH, - ["HL"] = Cpu.RegisterHL, - ["I"] = Cpu.RegisterI, - ["IX"] = Cpu.RegisterIX, - ["IY"] = Cpu.RegisterIY, - ["L"] = Cpu.RegisterL, - ["PC"] = Cpu.RegisterPC, - ["R"] = Cpu.RegisterR, - ["Shadow AF"] = Cpu.RegisterShadowAF, - ["Shadow BC"] = Cpu.RegisterShadowBC, - ["Shadow DE"] = Cpu.RegisterShadowDE, - ["Shadow HL"] = Cpu.RegisterShadowHL, - ["SP"] = Cpu.RegisterSP, - ["Flag C"] = Cpu.RegisterF.Bit(0), - ["Flag N"] = Cpu.RegisterF.Bit(1), - ["Flag P/V"] = Cpu.RegisterF.Bit(2), - ["Flag 3rd"] = Cpu.RegisterF.Bit(3), - ["Flag H"] = Cpu.RegisterF.Bit(4), - ["Flag 5th"] = Cpu.RegisterF.Bit(5), - ["Flag Z"] = Cpu.RegisterF.Bit(6), - ["Flag S"] = Cpu.RegisterF.Bit(7) + ["A"] = _cpu.RegisterA, + ["AF"] = _cpu.RegisterAF, + ["B"] = _cpu.RegisterB, + ["BC"] = _cpu.RegisterBC, + ["C"] = _cpu.RegisterC, + ["D"] = _cpu.RegisterD, + ["DE"] = _cpu.RegisterDE, + ["E"] = _cpu.RegisterE, + ["F"] = _cpu.RegisterF, + ["H"] = _cpu.RegisterH, + ["HL"] = _cpu.RegisterHL, + ["I"] = _cpu.RegisterI, + ["IX"] = _cpu.RegisterIX, + ["IY"] = _cpu.RegisterIY, + ["L"] = _cpu.RegisterL, + ["PC"] = _cpu.RegisterPC, + ["R"] = _cpu.RegisterR, + ["Shadow AF"] = _cpu.RegisterShadowAF, + ["Shadow BC"] = _cpu.RegisterShadowBC, + ["Shadow DE"] = _cpu.RegisterShadowDE, + ["Shadow HL"] = _cpu.RegisterShadowHL, + ["SP"] = _cpu.RegisterSP, + ["Flag C"] = _cpu.RegisterF.Bit(0), + ["Flag N"] = _cpu.RegisterF.Bit(1), + ["Flag P/V"] = _cpu.RegisterF.Bit(2), + ["Flag 3rd"] = _cpu.RegisterF.Bit(3), + ["Flag H"] = _cpu.RegisterF.Bit(4), + ["Flag 5th"] = _cpu.RegisterF.Bit(5), + ["Flag Z"] = _cpu.RegisterF.Bit(6), + ["Flag S"] = _cpu.RegisterF.Bit(7) }; } @@ -52,70 +52,70 @@ namespace BizHawk.Emulation.Cores.Calculators default: throw new InvalidOperationException(); case "A": - Cpu.RegisterA = (byte)value; + _cpu.RegisterA = (byte)value; break; case "AF": - Cpu.RegisterAF = (byte)value; + _cpu.RegisterAF = (byte)value; break; case "B": - Cpu.RegisterB = (byte)value; + _cpu.RegisterB = (byte)value; break; case "BC": - Cpu.RegisterBC = (byte)value; + _cpu.RegisterBC = (byte)value; break; case "C": - Cpu.RegisterC = (byte)value; + _cpu.RegisterC = (byte)value; break; case "D": - Cpu.RegisterD = (byte)value; + _cpu.RegisterD = (byte)value; break; case "DE": - Cpu.RegisterDE = (byte)value; + _cpu.RegisterDE = (byte)value; break; case "E": - Cpu.RegisterE = (byte)value; + _cpu.RegisterE = (byte)value; break; case "F": - Cpu.RegisterF = (byte)value; + _cpu.RegisterF = (byte)value; break; case "H": - Cpu.RegisterH = (byte)value; + _cpu.RegisterH = (byte)value; break; case "HL": - Cpu.RegisterHL = (byte)value; + _cpu.RegisterHL = (byte)value; break; case "I": - Cpu.RegisterI = (byte)value; + _cpu.RegisterI = (byte)value; break; case "IX": - Cpu.RegisterIX = (byte)value; + _cpu.RegisterIX = (byte)value; break; case "IY": - Cpu.RegisterIY = (byte)value; + _cpu.RegisterIY = (byte)value; break; case "L": - Cpu.RegisterL = (byte)value; + _cpu.RegisterL = (byte)value; break; case "PC": - Cpu.RegisterPC = (ushort)value; + _cpu.RegisterPC = (ushort)value; break; case "R": - Cpu.RegisterR = (byte)value; + _cpu.RegisterR = (byte)value; break; case "Shadow AF": - Cpu.RegisterShadowAF = (byte)value; + _cpu.RegisterShadowAF = (byte)value; break; case "Shadow BC": - Cpu.RegisterShadowBC = (byte)value; + _cpu.RegisterShadowBC = (byte)value; break; case "Shadow DE": - Cpu.RegisterShadowDE = (byte)value; + _cpu.RegisterShadowDE = (byte)value; break; case "Shadow HL": - Cpu.RegisterShadowHL = (byte)value; + _cpu.RegisterShadowHL = (byte)value; break; case "SP": - Cpu.RegisterSP = (byte)value; + _cpu.RegisterSP = (byte)value; break; } } @@ -133,6 +133,6 @@ namespace BizHawk.Emulation.Cores.Calculators return false; } - public int TotalExecutedCycles => Cpu.TotalExecutedCycles; + public int TotalExecutedCycles => _cpu.TotalExecutedCycles; } } diff --git a/BizHawk.Emulation.Cores/Calculator/TI83.IEmulator.cs b/BizHawk.Emulation.Cores/Calculator/TI83.IEmulator.cs index 5b0a165d8a..f1de9171dd 100644 --- a/BizHawk.Emulation.Cores/Calculator/TI83.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Calculator/TI83.IEmulator.cs @@ -4,31 +4,30 @@ namespace BizHawk.Emulation.Cores.Calculators { public partial class TI83 : IEmulator { - public IEmulatorServiceProvider ServiceProvider { get; private set; } + public IEmulatorServiceProvider ServiceProvider { get; } - public ControllerDefinition ControllerDefinition - { - get { return TI83Controller; } - } + public ControllerDefinition ControllerDefinition => TI83Controller; public void FrameAdvance(IController controller, bool render, bool rendersound) { _controller = controller; _lagged = true; - Cpu.Debug = Tracer.Enabled; + _cpu.Debug = _tracer.Enabled; - if (Cpu.Debug && Cpu.Logger == null) // TODO, lets not do this on each frame. But lets refactor CoreComm/CoreComm first - Cpu.Logger = (s) => Tracer.Put(s); + if (_cpu.Debug && _cpu.Logger == null) // TODO, lets not do this on each frame. But lets refactor CoreComm/CoreComm first + { + _cpu.Logger = s => _tracer.Put(s); + } - //I eyeballed this speed + // I eyeballed this speed for (int i = 0; i < 5; i++) { _onPressed = controller.IsPressed("ON"); - //and this was derived from other emus - Cpu.ExecuteCycles(10000); - Cpu.Interrupt = true; + // and this was derived from other emus + _cpu.ExecuteCycles(10000); + _cpu.Interrupt = true; } Frame++; @@ -44,22 +43,24 @@ namespace BizHawk.Emulation.Cores.Calculators public int Frame { get { return _frame; } - set { _frame = value; } + private set { _frame = value; } } - public string SystemId { get { return "TI83"; } } + public string SystemId => "TI83"; - public bool DeterministicEmulation { get { return true; } } + public bool DeterministicEmulation => true; - public void ResetCounters() + public void ResetCounters() { Frame = 0; _lagCount = 0; _isLag = false; } - public CoreComm CoreComm { get; private set; } + public CoreComm CoreComm { get; } - public void Dispose() { } + public void Dispose() + { + } } } diff --git a/BizHawk.Emulation.Cores/Calculator/TI83.IMemoryDomains.cs b/BizHawk.Emulation.Cores/Calculator/TI83.IMemoryDomains.cs index bac3d10f71..a1bd4aa083 100644 --- a/BizHawk.Emulation.Cores/Calculator/TI83.IMemoryDomains.cs +++ b/BizHawk.Emulation.Cores/Calculator/TI83.IMemoryDomains.cs @@ -8,8 +8,8 @@ namespace BizHawk.Emulation.Cores.Calculators { public partial class TI83 { - private IMemoryDomains _memoryDomains; private readonly Dictionary _byteArrayDomains = new Dictionary(); + private IMemoryDomains _memoryDomains; private bool _memoryDomainsInit = false; private void SetupMemoryDomains() @@ -21,13 +21,13 @@ namespace BizHawk.Emulation.Cores.Calculators { if (addr < 0 || addr >= 65536) throw new ArgumentOutOfRangeException(); - return Cpu.ReadMemory((ushort)addr); + return _cpu.ReadMemory((ushort)addr); }, (addr, value) => { if (addr < 0 || addr >= 65536) throw new ArgumentOutOfRangeException(); - Cpu.WriteMemory((ushort)addr, value); + _cpu.WriteMemory((ushort)addr, value); }, 1); domains.Add(systemBusDomain); diff --git a/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs b/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs index b63f2ac4fa..e6927d9962 100644 --- a/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs +++ b/BizHawk.Emulation.Cores/Calculator/TI83.IStatable.cs @@ -9,10 +9,7 @@ namespace BizHawk.Emulation.Cores.Calculators { private byte[] _stateBuffer; - public bool BinarySaveStatesPreferred - { - get { return false; } - } + public bool BinarySaveStatesPreferred => false; public void SaveStateBinary(BinaryWriter bw) { @@ -58,7 +55,7 @@ namespace BizHawk.Emulation.Cores.Calculators private void SyncState(Serializer ser) { ser.BeginSection("TI83"); - Cpu.SyncState(ser); + _cpu.SyncState(ser); ser.Sync("RAM", ref _ram, false); ser.Sync("romPageLow3Bits", ref _romPageLow3Bits); ser.Sync("romPageHighBit", ref _romPageHighBit); @@ -70,7 +67,7 @@ namespace BizHawk.Emulation.Cores.Calculators ser.Sync("maskOn", ref _maskOn); ser.Sync("onPressed", ref _onPressed); ser.Sync("keyboardMask", ref _keyboardMask); - ser.Sync("m_LinkOutput", ref LinkOutput); + ser.Sync("m_LinkOutput", ref _linkOutput); ser.Sync("VRAM", ref _vram, false); ser.Sync("Frame", ref _frame); ser.Sync("LagCount", ref _lagCount); diff --git a/BizHawk.Emulation.Cores/Calculator/TI83.cs b/BizHawk.Emulation.Cores/Calculator/TI83.cs index 826e7c0f20..28ab8bc4a8 100644 --- a/BizHawk.Emulation.Cores/Calculator/TI83.cs +++ b/BizHawk.Emulation.Cores/Calculator/TI83.cs @@ -18,19 +18,20 @@ namespace BizHawk.Emulation.Cores.Calculators [CoreConstructor("TI83")] public TI83(CoreComm comm, GameInfo game, byte[] rom, object Settings) { - ServiceProvider = new BasicServiceProvider(this); + var ser = new BasicServiceProvider(this); + ServiceProvider = ser; PutSettings((TI83Settings)Settings ?? new TI83Settings()); CoreComm = comm; - Cpu.ReadMemory = ReadMemory; - Cpu.WriteMemory = WriteMemory; - Cpu.ReadHardware = ReadHardware; - Cpu.WriteHardware = WriteHardware; - Cpu.IRQCallback = IRQCallback; - Cpu.NMICallback = NMICallback; - Cpu.MemoryCallbacks = MemoryCallbacks; + _cpu.ReadMemory = ReadMemory; + _cpu.WriteMemory = WriteMemory; + _cpu.ReadHardware = ReadHardware; + _cpu.WriteHardware = WriteHardware; + _cpu.IRQCallback = IRQCallback; + _cpu.NMICallback = NMICallback; + _cpu.MemoryCallbacks = MemoryCallbacks; - Rom = rom; + _rom = rom; LinkPort = new TI83LinkPort(this); // different calculators (different revisions?) have different initPC. we track this in the game database by rom hash @@ -44,21 +45,19 @@ namespace BizHawk.Emulation.Cores.Calculators HardReset(); SetupMemoryDomains(); - Tracer = new TraceBuffer { Header = Cpu.TraceHeader }; + _tracer = new TraceBuffer { Header = _cpu.TraceHeader }; - var serviceProvider = ServiceProvider as BasicServiceProvider; - - serviceProvider.Register(Tracer); - serviceProvider.Register(new Disassembler()); + ser.Register(_tracer); + ser.Register(new Disassembler()); } - private readonly TraceBuffer Tracer; + private readonly TraceBuffer _tracer; - // hardware - private const ushort RamSizeMask = 0x7FFF; + private readonly Z80A _cpu = new Z80A(); + private readonly byte[] _rom; - private readonly Z80A Cpu = new Z80A(); - private readonly byte[] Rom; + // configuration + private readonly ushort _startPC; private IController _controller; @@ -76,16 +75,16 @@ namespace BizHawk.Emulation.Cores.Calculators private bool _cursorMoved; private int _frame; - // configuration - private ushort _startPC; - // Link Cable public TI83LinkPort LinkPort { get; } - internal bool LinkActive; - internal int LinkOutput, LinkInput; + private int _linkOutput; - internal int LinkState => (LinkOutput | LinkInput) ^ 3; + internal int LinkOutput => _linkOutput; + internal bool LinkActive { private get; set; } + internal int LinkInput { private get; set; } + + internal int LinkState => (_linkOutput | LinkInput) ^ 3; private static readonly ControllerDefinition TI83Controller = new ControllerDefinition @@ -93,7 +92,7 @@ namespace BizHawk.Emulation.Cores.Calculators Name = "TI83 Controller", BoolButtons = { - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","DOT", + "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "DOT", "ON", "ENTER", "DOWN", "LEFT", "UP", "RIGHT", "PLUS", "MINUS", "MULTIPLY", "DIVIDE", @@ -111,11 +110,11 @@ namespace BizHawk.Emulation.Cores.Calculators if (addr < 0x4000) { - ret = Rom[addr]; // ROM zero-page + ret = _rom[addr]; // ROM zero-page } else if (addr < 0x8000) { - ret = Rom[(romPage * 0x4000) + addr - 0x4000]; // other rom page + ret = _rom[(romPage * 0x4000) + addr - 0x4000]; // other rom page } else { @@ -129,11 +128,11 @@ namespace BizHawk.Emulation.Cores.Calculators { if (addr < 0x4000) { - return; // ROM zero-page + // ROM zero-page } else if (addr < 0x8000) { - return; // other rom page + // other rom page } else { @@ -147,12 +146,12 @@ namespace BizHawk.Emulation.Cores.Calculators { case 0: // PORT_LINK _romPageHighBit = (value >> 4) & 1; - LinkOutput = value & 3; + _linkOutput = value & 3; if (LinkActive) { // Prevent rom calls from disturbing link port activity - if (LinkActive && Cpu.RegisterPC < 0x4000) + if (LinkActive && _cpu.RegisterPC < 0x4000) { return; } @@ -164,7 +163,7 @@ namespace BizHawk.Emulation.Cores.Calculators case 1: // PORT_KEYBOARD: _lagged = false; _keyboardMask = value; - //Console.WriteLine("write PORT_KEYBOARD {0:X2}",value); + ////Console.WriteLine("write PORT_KEYBOARD {0:X2}",value); break; case 2: // PORT_ROMPAGE _romPageLow3Bits = value & 0x7; @@ -173,11 +172,11 @@ namespace BizHawk.Emulation.Cores.Calculators _maskOn = (byte)(value & 1); break; case 16: // PORT_DISPCTRL - //Console.WriteLine("write PORT_DISPCTRL {0}",value); + ////Console.WriteLine("write PORT_DISPCTRL {0}",value); WriteDispCtrl(value); break; case 17: // PORT_DISPDATA - //Console.WriteLine("write PORT_DISPDATA {0}",value); + ////Console.WriteLine("write PORT_DISPDATA {0}",value); WriteDispData(value); break; } @@ -191,7 +190,7 @@ namespace BizHawk.Emulation.Cores.Calculators LinkPort.Update(); return (byte)((_romPageHighBit << 4) | (LinkState << 2) | LinkOutput); case 1: // PORT_KEYBOARD: - //Console.WriteLine("read PORT_KEYBOARD"); + ////Console.WriteLine("read PORT_KEYBOARD"); return ReadKeyboard(); case 2: // PORT_ROMPAGE return (byte)_romPageLow3Bits; @@ -204,32 +203,33 @@ namespace BizHawk.Emulation.Cores.Calculators // 2 - Unknown, but used // 3 - Set if ON key is up // 4-7 - Unknown - //if (onPressed && maskOn) ret |= 1; - //if (!onPressed) ret |= 0x8; - return (byte)((_controller.IsPressed("ON") ? _maskOn : 8) | (LinkActive ? 0 : 2)); + ////if (onPressed && maskOn) ret |= 1; + ////if (!onPressed) ret |= 0x8; + return (byte)((Controller.IsPressed("ON") ? _maskOn : 8) | (LinkActive ? 0 : 2)); } case 4: // PORT_INTCTRL - //Console.WriteLine("read PORT_INTCTRL"); + ////Console.WriteLine("read PORT_INTCTRL"); return 0xFF; case 16: // PORT_DISPCTRL - //Console.WriteLine("read DISPCTRL"); + ////Console.WriteLine("read DISPCTRL"); break; case 17: // PORT_DISPDATA return ReadDispData(); } + return 0xFF; } private byte ReadKeyboard() { InputCallbacks.Call(); - //ref TI-9X + // ref TI-9X int ret = 0xFF; - //Console.WriteLine("keyboardMask: {0:X2}",keyboardMask); + ////Console.WriteLine("keyboardMask: {0:X2}",keyboardMask); if ((_keyboardMask & 1) == 0) { if (_controller.IsPressed("DOWN")) ret ^= 1; @@ -326,7 +326,7 @@ namespace BizHawk.Emulation.Cores.Calculators else { int column = 6 * (int)_displayX; - int offset = (int)_displayY * 12 + (column >> 3); + int offset = (int)(_displayY * 12) + (column >> 3); int shift = 10 - (column & 7); ret = (byte)(((_vram[offset] << 8) | _vram[offset + 1]) >> shift); } @@ -340,13 +340,13 @@ namespace BizHawk.Emulation.Cores.Calculators int offset; if (_displayMode == 1) { - offset = (int)_displayY * 12 + (int)_displayX; + offset = (int)(_displayY * 12) + (int)_displayX; _vram[offset] = value; } else { int column = 6 * (int)_displayX; - offset = (int)_displayY * 12 + (column >> 3); + offset = (int)(_displayY * 12) + (column >> 3); if (offset < 0x300) { int shift = column & 7; @@ -372,10 +372,18 @@ namespace BizHawk.Emulation.Cores.Calculators { switch (_displayMove) { - case 0: _displayY--; break; - case 1: _displayY++; break; - case 2: _displayX--; break; - case 3: _displayX++; break; + case 0: + _displayY--; + break; + case 1: + _displayY++; + break; + case 2: + _displayX--; + break; + case 3: + _displayX++; + break; } _displayX &= 0xF; // 0xF or 0x1F? dunno @@ -416,37 +424,34 @@ namespace BizHawk.Emulation.Cores.Calculators else if (value == 3) { } - else - { - } } private void IRQCallback() { // Console.WriteLine("IRQ with vec {0} and cpu.InterruptMode {1}", cpu.RegisterI, cpu.InterruptMode); - Cpu.Interrupt = false; + _cpu.Interrupt = false; } private void NMICallback() { Console.WriteLine("NMI"); - Cpu.NonMaskableInterrupt = false; + _cpu.NonMaskableInterrupt = false; } private void HardReset() { - Cpu.Reset(); + _cpu.Reset(); _ram = new byte[0x8000]; for (int i = 0; i < 0x8000; i++) { _ram[i] = 0xFF; } - Cpu.RegisterPC = _startPC; + _cpu.RegisterPC = _startPC; - Cpu.IFF1 = false; - Cpu.IFF2 = false; - Cpu.InterruptMode = 2; + _cpu.IFF1 = false; + _cpu.IFF2 = false; + _cpu.InterruptMode = 2; _maskOn = 1; _romPageHighBit = 0;