Merge branch 'master' into waterbox2

This commit is contained in:
adelikat 2017-05-30 17:31:30 -05:00
commit 1a54ff1818
83 changed files with 754 additions and 566 deletions

View File

@ -271,6 +271,9 @@ sha1:1C3771B7F116F439D684D04DF792570271C93F86 75 Bingo (Sachen-English) [U] NES
sha1:4097D5A814308E39D592466B60B64862699CC22A 2-in-1 - Yuu Yuu + Dragonball Z [p1][!] NES board=MAPPER023_BMC sha1:4097D5A814308E39D592466B60B64862699CC22A 2-in-1 - Yuu Yuu + Dragonball Z [p1][!] NES board=MAPPER023_BMC
sha1:4C499A857087E6C121522435786792A2E4105AC1 Fuuun Shaolin Kyo (FDS Conversion) (Unl) [U][!] NES board=UNIF_UNL-LH10;WRAM=8;VRAM=8 sha1:4C499A857087E6C121522435786792A2E4105AC1 Fuuun Shaolin Kyo (FDS Conversion) (Unl) [U][!] NES board=UNIF_UNL-LH10;WRAM=8;VRAM=8
sha1:CAAC1E829133851648BA7C7CD6EAA7D26A464999 Metal Fighter (Asia) (Unl) (Sachen) NES board=UNIF_UNL-SA-016-1M;PRG=32;CHR=32;PAD_V=0;PAD_H=1 sha1:CAAC1E829133851648BA7C7CD6EAA7D26A464999 Metal Fighter (Asia) (Unl) (Sachen) NES board=UNIF_UNL-SA-016-1M;PRG=32;CHR=32;PAD_V=0;PAD_H=1
sha1:B9902886D1739983B315B67B02133E44620E4381 Challenge of the Dragon (Asia) (PAL) (Unl) NES board=MAPPER147;PAD_V=0;PAD_H=1;system=NES-PAL
sha1:0CDE48DB89896946F0C2E78936EA290348994ED5 Pipemania (Australia) (HES) (Unl) NES board=MAPPER113;PRG=32;CHR=16;WRAM=0;VRAM=0
sha1:E843AB3D779D4F0BB1F933D6EE99DAA526EFBCF1 Gaiapolis (Asia) (Unl) NES board=UNIF_NES-TLROM;PRG=128;CHR=256;WRAM=0;VRAM=0
;;;;;;;;;;;;;;;;;;;----------------------------------------------------------------------- ;;;;;;;;;;;;;;;;;;;-----------------------------------------------------------------------
;;;;;;;;;;;;;;;;;;;----------------------------------------------------------------------- ;;;;;;;;;;;;;;;;;;;-----------------------------------------------------------------------

View File

@ -66,8 +66,6 @@ namespace BizHawk.Client.Common
/// </summary> /// </summary>
public static readonly ClickyVirtualPadController ClickyVirtualPadController = new ClickyVirtualPadController(); public static readonly ClickyVirtualPadController ClickyVirtualPadController = new ClickyVirtualPadController();
public static SimpleController MovieOutputController = new SimpleController();
public static Controller ClientControls; public static Controller ClientControls;
// Input state which has been estine for game controller inputs are coalesce here // Input state which has been estine for game controller inputs are coalesce here

View File

@ -84,7 +84,8 @@ namespace BizHawk.Client.Common
var ret = new TasMovieMarkerList(_movie); var ret = new TasMovieMarkerList(_movie);
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)
{ {
ret.Add(new TasMovieMarker(this[i].Frame, this[i].Message)); // used to copy markers between branches
ret.Add(new TasMovieMarker(this[i].Frame, this[i].Message), skipHistory: true);
} }
return ret; return ret;
@ -115,14 +116,14 @@ namespace BizHawk.Client.Common
Add(item, false); Add(item, false);
} }
public void Add(TasMovieMarker item, bool fromHistory) public void Add(TasMovieMarker item, bool skipHistory)
{ {
var existingItem = this.FirstOrDefault(m => m.Frame == item.Frame); var existingItem = this.FirstOrDefault(m => m.Frame == item.Frame);
if (existingItem != null) if (existingItem != null)
{ {
if (existingItem.Message != item.Message) if (existingItem.Message != item.Message)
{ {
if (!fromHistory) if (!skipHistory)
{ {
_movie.ChangeLog.AddMarkerChange(item, item.Frame, existingItem.Message); _movie.ChangeLog.AddMarkerChange(item, item.Frame, existingItem.Message);
} }
@ -133,7 +134,7 @@ namespace BizHawk.Client.Common
} }
else else
{ {
if (!fromHistory) if (!skipHistory)
{ {
_movie.ChangeLog.AddMarkerChange(item); _movie.ChangeLog.AddMarkerChange(item);
} }

View File

@ -18,7 +18,7 @@ namespace BizHawk.Client.EmuHawk
private void ColecoControllerSettings_Load(object sender, EventArgs e) private void ColecoControllerSettings_Load(object sender, EventArgs e)
{ {
_syncSettings = (Global.Emulator as ColecoVision)._syncSettings.Clone(); _syncSettings = ((ColecoVision)Global.Emulator).GetSyncSettings().Clone();
var possibleControllers = ColecoVisionControllerDeck.ValidControllerTypes.Select(t => t.Key); var possibleControllers = ColecoVisionControllerDeck.ValidControllerTypes.Select(t => t.Key);

View File

@ -1,5 +1,4 @@
using System; using System;
using System.Data;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
@ -19,7 +18,7 @@ namespace BizHawk.Client.EmuHawk
private void IntvControllerSettings_Load(object sender, EventArgs e) private void IntvControllerSettings_Load(object sender, EventArgs e)
{ {
_syncSettings = (Global.Emulator as Intellivision).GetSyncSettings().Clone(); _syncSettings = ((Intellivision)Global.Emulator).GetSyncSettings().Clone();
var possibleControllers = IntellivisionControllerDeck.ValidControllerTypes.Select(t => t.Key); var possibleControllers = IntellivisionControllerDeck.ValidControllerTypes.Select(t => t.Key);

View File

@ -21,7 +21,7 @@ namespace BizHawk.Client.EmuHawk
return; return;
} }
string[] coresToHide = { "C64" }; string[] coresToHide = { };
foreach (var core in coresToHide) foreach (var core in coresToHide)
{ {

View File

@ -50,18 +50,7 @@ namespace BizHawk.Emulation.Common
} }
} }
public IEnumerable<SystemInfo> AllSystems public IEnumerable<SystemInfo> AllSystems => _systems;
{
get
{
if (VersionInfo.DeveloperBuild)
{
return _systems;
}
return _systems.Where(s => s.SystemId != "C64");
}
}
public class SystemInfo public class SystemInfo
{ {

View File

@ -229,6 +229,7 @@
<Compile Include="Computers\Commodore64\C64.MotherboardInput.cs" /> <Compile Include="Computers\Commodore64\C64.MotherboardInput.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper0001.cs" /> <Compile Include="Computers\Commodore64\Cartridge\Mapper0001.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper0005.cs" /> <Compile Include="Computers\Commodore64\Cartridge\Mapper0005.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper0007.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper0008.cs" /> <Compile Include="Computers\Commodore64\Cartridge\Mapper0008.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper000A.cs" /> <Compile Include="Computers\Commodore64\Cartridge\Mapper000A.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper000B.cs" /> <Compile Include="Computers\Commodore64\Cartridge\Mapper000B.cs" />
@ -1394,4 +1395,4 @@
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>

View File

@ -53,7 +53,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
return _selectedDebuggable.CanStep(type); return _selectedDebuggable.CanStep(type);
} }
public void Step(StepType type) public void Step(StepType type)
{ {
if (_selectedDebuggable == null) if (_selectedDebuggable == null)
@ -64,10 +63,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
_selectedDebuggable.Step(type); _selectedDebuggable.Step(type);
} }
public int TotalExecutedCycles public int TotalExecutedCycles => _selectedDebuggable.TotalExecutedCycles;
{
get { return _selectedDebuggable.TotalExecutedCycles; }
}
private readonly IMemoryCallbackSystem _memoryCallbacks; private readonly IMemoryCallbackSystem _memoryCallbacks;

View File

@ -31,8 +31,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
SetDefaultDisassemblable(); SetDefaultDisassemblable();
} }
return _selectedDisassemblable.Cpu; return _selectedDisassemblable.Cpu;
} }
set set
{ {
var currentSelectedDisassemblable = _selectedDisassemblable; var currentSelectedDisassemblable = _selectedDisassemblable;
@ -52,6 +54,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
SetDefaultDisassemblable(); SetDefaultDisassemblable();
} }
return _selectedDisassemblable.PCRegisterName; return _selectedDisassemblable.PCRegisterName;
} }
} }
@ -67,6 +70,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
SetDefaultDisassemblable(); SetDefaultDisassemblable();
} }
return _selectedDisassemblable.Disassemble(m, addr, out length); return _selectedDisassemblable.Disassemble(m, addr, out length);
} }
} }

View File

@ -4,7 +4,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public partial class C64 : IDriveLight public partial class C64 : IDriveLight
{ {
public bool DriveLightEnabled { get { return _board != null && (_board.CartPort.DriveLightEnabled || _board.Serial.DriveLightEnabled); } } public bool DriveLightEnabled => _board != null && (_board.CartPort.DriveLightEnabled || _board.Serial.DriveLightEnabled);
public bool DriveLightOn { get { return _board != null && (_board.CartPort.DriveLightOn || _board.Serial.DriveLightOn); } } public bool DriveLightOn => _board != null && (_board.CartPort.DriveLightOn || _board.Serial.DriveLightOn);
} }
} }

View File

@ -4,7 +4,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public sealed partial class C64 : IEmulator public sealed partial class C64 : IEmulator
{ {
public IEmulatorServiceProvider ServiceProvider { get; private set; } public IEmulatorServiceProvider ServiceProvider { get; }
public ControllerDefinition ControllerDefinition => C64ControllerDefinition; public ControllerDefinition ControllerDefinition => C64ControllerDefinition;
@ -12,7 +12,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
_board.Controller = controller; _board.Controller = controller;
if (_tracer.Enabled) if (_tracer.Enabled)
{ {
_board.Cpu.TraceCallback = s => _tracer.Put(s); _board.Cpu.TraceCallback = s => _tracer.Put(s);
@ -52,7 +51,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
public int Frame => _frame; public int Frame => _frame;
public string SystemId { get { return "C64"; } } public string SystemId => "C64";
public bool DeterministicEmulation => true; public bool DeterministicEmulation => true;
@ -64,20 +63,14 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
_frameCycles = 0; _frameCycles = 0;
} }
public CoreComm CoreComm { get; private set; } public CoreComm CoreComm { get; }
public void Dispose() public void Dispose()
{ {
if (_board != null) if (_board != null)
{ {
if (_board.TapeDrive != null) _board.TapeDrive?.RemoveMedia();
{ _board.DiskDrive?.RemoveMedia();
_board.TapeDrive.RemoveMedia();
}
if (_board.DiskDrive != null)
{
_board.DiskDrive.RemoveMedia();
}
_board = null; _board = null;
} }
} }

View File

@ -16,7 +16,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
set { _lagCount = value; } set { _lagCount = value; }
} }
public IInputCallbackSystem InputCallbacks { get; private set; } public IInputCallbackSystem InputCallbacks { get; }
private bool _isLagFrame; private bool _isLagFrame;
private int _lagCount; private int _lagCount;

View File

@ -38,7 +38,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
domains.AddRange(new[] domains.AddRange(new[]
{ {
C64MemoryDomainFactory.Create("Tape Data", _board.TapeDrive.TapeDataDomain.Length, a => _board.TapeDrive.TapeDataDomain[a], (a,v) => _board.TapeDrive.TapeDataDomain[a] = (byte)v) C64MemoryDomainFactory.Create("Tape Data", _board.TapeDrive.TapeDataDomain.Length, a => _board.TapeDrive.TapeDataDomain[a], (a, v) => _board.TapeDrive.TapeDataDomain[a] = (byte)v)
}); });
} }

View File

@ -148,11 +148,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
KernalRom = new Chip23128(); KernalRom = new Chip23128();
} }
public int ClockNumerator { get; private set; } public int ClockNumerator { get; }
public int ClockDenominator { get; private set; } public int ClockDenominator { get; }
// ----------------------------------------- // -----------------------------------------
public void Execute() public void Execute()
{ {
_vicBank = (0x3 - ((Cia1.PrA | ~Cia1.DdrA) & 0x3)) << 14; _vicBank = (0x3 - ((Cia1.PrA | ~Cia1.DdrA) & 0x3)) << 14;
@ -173,7 +172,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
} }
// ----------------------------------------- // -----------------------------------------
public void HardReset() public void HardReset()
{ {
Bus = 0xFF; Bus = 0xFF;

View File

@ -5,12 +5,14 @@
private bool[] _joystickPressed = new bool[10]; private bool[] _joystickPressed = new bool[10];
private bool[] _keyboardPressed = new bool[64]; private bool[] _keyboardPressed = new bool[64];
private static readonly string[][] JoystickMatrix = { private static readonly string[][] JoystickMatrix =
new[] {"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Button"}, {
new[] {"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button"} new[] {"P1 Up", "P1 Down", "P1 Left", "P1 Right", "P1 Button" },
new[] {"P2 Up", "P2 Down", "P2 Left", "P2 Right", "P2 Button" }
}; };
private static readonly string[][] KeyboardMatrix = { private static readonly string[][] KeyboardMatrix =
{
new[] { "Key Insert/Delete", "Key Return", "Key Cursor Left/Right", "Key F7", "Key F1", "Key F3", "Key F5", "Key Cursor Up/Down" }, new[] { "Key Insert/Delete", "Key Return", "Key Cursor Left/Right", "Key F7", "Key F1", "Key F3", "Key F5", "Key Cursor Up/Down" },
new[] { "Key 3", "Key W", "Key A", "Key 4", "Key Z", "Key S", "Key E", "Key Left Shift" }, new[] { "Key 3", "Key W", "Key A", "Key 4", "Key Z", "Key S", "Key E", "Key Left Shift" },
new[] { "Key 5", "Key R", "Key D", "Key 6", "Key C", "Key F", "Key T", "Key X" }, new[] { "Key 5", "Key R", "Key D", "Key 6", "Key C", "Key F", "Key T", "Key X" },

View File

@ -64,7 +64,10 @@
{ {
var data = 0x1F; var data = 0x1F;
if (!Cassette.ReadSenseBuffer()) if (!Cassette.ReadSenseBuffer())
{
data &= 0xEF; data &= 0xEF;
}
return data; return data;
} }

View File

@ -13,12 +13,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
"C64Hawk", "C64Hawk",
"SaxxonPike", "SaxxonPike",
isPorted: false, isPorted: false,
isReleased: false)] isReleased: true)]
public sealed partial class C64 : IEmulator, IRegionable, IBoardInfo public sealed partial class C64 : IEmulator, IRegionable, IBoardInfo
{ {
public C64(CoreComm comm, IEnumerable<byte[]> roms, GameInfo game, object settings, object syncSettings) public C64(CoreComm comm, IEnumerable<byte[]> roms, GameInfo game, object settings, object syncSettings)
{ {
PutSyncSettings((C64SyncSettings)syncSettings ?? new C64SyncSettings()); PutSyncSettings((C64SyncSettings)syncSettings ?? new C64SyncSettings());
PutSettings((C64Settings)settings ?? new C64Settings()); PutSettings((C64Settings)settings ?? new C64Settings());
@ -27,12 +26,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
InputCallbacks = new InputCallbackSystem(); InputCallbacks = new InputCallbackSystem();
CoreComm = comm; CoreComm = comm;
Roms = roms?.ToList() ?? new List<byte[]>(); _roms = roms?.ToList() ?? new List<byte[]>();
_currentDisk = 0; _currentDisk = 0;
RomSanityCheck(); RomSanityCheck();
Init(SyncSettings.VicType, Settings.BorderType, SyncSettings.SidType, SyncSettings.TapeDriveType, SyncSettings.DiskDriveType); Init(SyncSettings.VicType, Settings.BorderType, SyncSettings.SidType, SyncSettings.TapeDriveType, SyncSettings.DiskDriveType);
_cyclesPerFrame = _board.Vic.CyclesPerFrame; _cyclesPerFrame = _board.Vic.CyclesPerFrame;
_memoryCallbacks = new MemoryCallbackSystem(); _memoryCallbacks = new MemoryCallbackSystem();
HardReset(); HardReset();
@ -64,7 +63,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
if (_board.CartPort.IsConnected) if (_board.CartPort.IsConnected)
{ {
// There are no multi-cart cart games, so just hardcode .First() // There are no multi-cart cart games, so just hardcode .First()
CoreComm.RomStatusDetails = $"{game.Name}\r\nSHA1:{roms.First().HashSHA1()}\r\nMD5:{roms.First().HashMD5()}\r\nMapper Impl \"{_board.CartPort.CartridgeType}\""; CoreComm.RomStatusDetails = $"{game.Name}\r\nSHA1:{_roms.First().HashSHA1()}\r\nMD5:{roms.First().HashMD5()}\r\nMapper Impl \"{_board.CartPort.CartridgeType}\"";
} }
SetupMemoryDomains(); SetupMemoryDomains();
@ -74,12 +73,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
// Given a good enough use case we could in theory expand those requirements, but for now we need a sanity check // Given a good enough use case we could in theory expand those requirements, but for now we need a sanity check
private void RomSanityCheck() private void RomSanityCheck()
{ {
if (Roms.Count == 0) if (_roms.Count == 0)
{ {
throw new NotSupportedException("Currently, a Rom is required to run this core."); throw new NotSupportedException("Currently, a Rom is required to run this core.");
} }
var formats = Roms.Select(rom => C64FormatFinder.GetFormat(rom)); var formats = _roms.Select(C64FormatFinder.GetFormat);
HashSet<C64Format> uniqueFormats = new HashSet<C64Format>(); HashSet<C64Format> uniqueFormats = new HashSet<C64Format>();
@ -119,11 +118,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
} }
// IRegionable // IRegionable
public DisplayType Region { get; private set; } public DisplayType Region { get; }
private readonly int _cyclesPerFrame; private readonly int _cyclesPerFrame;
private List<byte[]> Roms = new List<byte[]>(); private readonly List<byte[]> _roms;
private static readonly ControllerDefinition C64ControllerDefinition = new ControllerDefinition private static readonly ControllerDefinition C64ControllerDefinition = new ControllerDefinition
{ {
@ -147,19 +146,19 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
private int _frameCycles; private int _frameCycles;
private int _frame; private int _frame;
private ITraceable _tracer; private readonly ITraceable _tracer;
// Disk stuff
// Disk stuff
private bool _nextPressed; private bool _nextPressed;
private bool _prevPressed; private bool _prevPressed;
private int _currentDisk; private int _currentDisk;
public int CurrentDisk => _currentDisk; public int CurrentDisk => _currentDisk;
public int DiskCount => Roms.Count; public int DiskCount => _roms.Count;
private void IncrementDisk() private void IncrementDisk()
{ {
_currentDisk++; _currentDisk++;
if (CurrentDisk >= Roms.Count) if (CurrentDisk >= _roms.Count)
{ {
_currentDisk = 0; _currentDisk = 0;
} }
@ -172,7 +171,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
_currentDisk--; _currentDisk--;
if (_currentDisk < 0) if (_currentDisk < 0)
{ {
_currentDisk = Roms.Count - 1; _currentDisk = _roms.Count - 1;
} }
InitDisk(); InitDisk();
@ -180,7 +179,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
private void InitDisk() private void InitDisk()
{ {
InitMedia(Roms[_currentDisk]); InitMedia(_roms[_currentDisk]);
} }
public void SetDisk(int discNum) public void SetDisk(int discNum)
@ -229,14 +228,17 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
var result = names.Select(n => CoreComm.CoreFileProvider.GetFirmware("C64", n, false)).FirstOrDefault(b => b != null && b.Length == length); var result = names.Select(n => CoreComm.CoreFileProvider.GetFirmware("C64", n, false)).FirstOrDefault(b => b != null && b.Length == length);
if (result == null) if (result == null)
throw new MissingFirmwareException(string.Format("At least one of these firmwares is required: {0}", string.Join(", ", names))); {
throw new MissingFirmwareException($"At least one of these firmwares is required: {string.Join(", ", names)}");
}
return result; return result;
} }
private void Init(VicType initRegion, BorderType borderType, SidType sidType, TapeDriveType tapeDriveType, DiskDriveType diskDriveType) private void Init(VicType initRegion, BorderType borderType, SidType sidType, TapeDriveType tapeDriveType, DiskDriveType diskDriveType)
{ {
// Force certain drive types to be available depending on ROM type // Force certain drive types to be available depending on ROM type
var rom = Roms.First(); var rom = _roms.First();
switch (C64FormatFinder.GetFormat(rom)) switch (C64FormatFinder.GetFormat(rom))
{ {
@ -244,7 +246,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
case C64Format.G64: case C64Format.G64:
case C64Format.X64: case C64Format.X64:
if (diskDriveType == DiskDriveType.None) if (diskDriveType == DiskDriveType.None)
{
diskDriveType = DiskDriveType.Commodore1541; diskDriveType = DiskDriveType.Commodore1541;
}
break; break;
case C64Format.T64: case C64Format.T64:
case C64Format.TAP: case C64Format.TAP:
@ -252,6 +257,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
tapeDriveType = TapeDriveType.Commodore1530; tapeDriveType = TapeDriveType.Commodore1530;
} }
break; break;
case C64Format.CRT: case C64Format.CRT:
// Nothing required. // Nothing required.
@ -261,8 +267,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
throw new Exception("The image format is not known, and too large to be used as a PRG."); throw new Exception("The image format is not known, and too large to be used as a PRG.");
} }
if (diskDriveType == DiskDriveType.None) if (diskDriveType == DiskDriveType.None)
{
diskDriveType = DiskDriveType.Commodore1541; diskDriveType = DiskDriveType.Commodore1541;
}
break; break;
default: default:
throw new Exception("The image format is not yet supported by the Commodore 64 core."); throw new Exception("The image format is not yet supported by the Commodore 64 core.");
@ -348,7 +358,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
private void HardReset() private void HardReset()
{ {
InitMedia(Roms[_currentDisk]); InitMedia(_roms[_currentDisk]);
_board.HardReset(); _board.HardReset();
} }
} }

View File

@ -61,7 +61,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
chipData.Add(reader.ReadBytes(chipDataLength).Select(x => (int)x).ToArray()); chipData.Add(reader.ReadBytes(chipDataLength).Select(x => (int)x).ToArray());
chipLength -= chipDataLength + 0x10; chipLength -= chipDataLength + 0x10;
if (chipLength > 0) if (chipLength > 0)
{
reader.ReadBytes(chipLength); reader.ReadBytes(chipLength);
}
} }
if (chipData.Count <= 0) if (chipData.Count <= 0)
@ -81,6 +83,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
case 0x0005: // Ocean case 0x0005: // Ocean
result = new Mapper0005(chipAddress, chipBank, chipData); result = new Mapper0005(chipAddress, chipBank, chipData);
break; break;
case 0x0007: // Fun Play
result = new Mapper0007(chipData, game, exrom);
break;
case 0x0008: // SuperGame case 0x0008: // SuperGame
result = new Mapper0008(chipData); result = new Mapper0008(chipData);
break; break;
@ -147,21 +152,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{ {
} }
public bool ExRom public bool ExRom => pinExRom;
{
get
{
return pinExRom;
}
}
public bool Game public bool Game => pinGame;
{
get
{
return pinGame;
}
}
public virtual void HardReset() public virtual void HardReset()
{ {
@ -170,21 +163,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
pinReset = true; pinReset = true;
} }
public bool IRQ public bool IRQ => pinIRQ;
{
get
{
return pinIRQ;
}
}
public bool NMI public bool NMI => pinNMI;
{
get
{
return pinNMI;
}
}
public virtual int Peek8000(int addr) public virtual int Peek8000(int addr)
{ {
@ -242,13 +223,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
return ReadOpenBus(); return ReadOpenBus();
} }
public bool Reset public bool Reset => pinReset;
{
get
{
return pinReset;
}
}
protected abstract void SyncStateInternal(Serializer ser); protected abstract void SyncStateInternal(Serializer ser);
@ -264,13 +239,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
ser.Sync("_driveLightOn", ref _driveLightOn); ser.Sync("_driveLightOn", ref _driveLightOn);
} }
public bool Valid public bool Valid => validCartridge;
{
get
{
return validCartridge;
}
}
public virtual void Write8000(int addr, int val) public virtual void Write8000(int addr, int val)
{ {

View File

@ -99,7 +99,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
public void ExecutePhase() public void ExecutePhase()
{ {
if (_connected) if (_connected)
{
_cartridgeDevice.ExecutePhase(); _cartridgeDevice.ExecutePhase();
}
} }
public void HardReset() public void HardReset()
@ -111,13 +113,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
} }
} }
public bool IsConnected public bool IsConnected => _connected;
{
get
{
return _connected;
}
}
public bool ReadIrq() public bool ReadIrq()
{ {
@ -138,7 +134,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
ser.EndSection(); ser.EndSection();
} }
public bool DriveLightEnabled { get { return _connected && _cartridgeDevice.DriveLightEnabled; } } public bool DriveLightEnabled => _connected && _cartridgeDevice.DriveLightEnabled;
public bool DriveLightOn { get { return _connected && _cartridgeDevice.DriveLightOn; } } public bool DriveLightOn => _connected && _cartridgeDevice.DriveLightOn;
} }
} }

View File

@ -14,7 +14,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// standard cartridge mapper (Commodore) // standard cartridge mapper (Commodore)
// note that this format also covers Ultimax carts // note that this format also covers Ultimax carts
public Mapper0000(IList<int> newAddresses, IList<int[]> newData, bool game, bool exrom) public Mapper0000(IList<int> newAddresses, IList<int[]> newData, bool game, bool exrom)
{ {
pinGame = game; pinGame = game;
@ -45,6 +44,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
case 0x4000: case 0x4000:
_romAMask = 0x1FFF; _romAMask = 0x1FFF;
_romBMask = 0x1FFF; _romBMask = 0x1FFF;
// split the rom into two banks // split the rom into two banks
_romA = new int[0x2000]; _romA = new int[0x2000];
_romB = new int[0x2000]; _romB = new int[0x2000];
@ -70,6 +70,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
validCartridge = false; validCartridge = false;
return; return;
} }
_romB = newData[i]; _romB = newData[i];
} }
} }

View File

@ -22,8 +22,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
for (var i = 0; i < newData.Count; i++) for (var i = 0; i < newData.Count; i++)
{ {
if (newAddresses[i] == 0x8000) if (newAddresses[i] == 0x8000)
{
Array.Copy(newData[i], 0, _rom, 0x2000 * newBanks[i], 0x2000); Array.Copy(newData[i], 0, _rom, 0x2000 * newBanks[i], 0x2000);
}
} }
_romOffset = 0; _romOffset = 0;
_cartEnabled = true; _cartEnabled = true;
} }
@ -42,7 +45,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
pinExRom = false; pinExRom = false;
pinGame = false; pinGame = false;
for (var i = 0; i < 0x2000; i++) for (var i = 0; i < 0x2000; i++)
{
_ram[i] = 0x00; _ram[i] = 0x00;
}
_romOffset = 0; _romOffset = 0;
_cartEnabled = true; _cartEnabled = true;
} }
@ -146,7 +152,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
private int GetIo2(int addr) private int GetIo2(int addr)
{ {
if (!_cartEnabled) if (!_cartEnabled)
{
return ReadOpenBus(); return ReadOpenBus();
}
return _ramEnabled return _ramEnabled
? _ram[(addr & 0xFF) | 0x1F00] ? _ram[(addr & 0xFF) | 0x1F00]

View File

@ -28,7 +28,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// build dummy bank // build dummy bank
_dummyBank = new int[0x2000]; _dummyBank = new int[0x2000];
for (var i = 0; i < 0x2000; i++) for (var i = 0; i < 0x2000; i++)
{
_dummyBank[i] = 0xFF; // todo: determine if this is correct _dummyBank[i] = 0xFF; // todo: determine if this is correct
}
switch (count) switch (count)
{ {
@ -82,9 +84,14 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// for safety, initialize all banks to dummy // for safety, initialize all banks to dummy
for (var i = 0; i < _banksA.Length; i++) for (var i = 0; i < _banksA.Length; i++)
{
_banksA[i] = _dummyBank; _banksA[i] = _dummyBank;
}
for (var i = 0; i < _banksB.Length; i++) for (var i = 0; i < _banksB.Length; i++)
{
_banksB[i] = _dummyBank; _banksB[i] = _dummyBank;
}
// now load in the banks // now load in the banks
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
@ -130,7 +137,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
public override void PokeDE00(int addr, int val) public override void PokeDE00(int addr, int val)
{ {
if (addr == 0x00) if (addr == 0x00)
{
BankSet(val); BankSet(val);
}
} }
public override int Read8000(int addr) public override int Read8000(int addr)
@ -146,14 +155,18 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
public override void WriteDE00(int addr, int val) public override void WriteDE00(int addr, int val)
{ {
if (addr == 0x00) if (addr == 0x00)
{
BankSet(val); BankSet(val);
}
} }
public override void SyncState(Serializer ser) public override void SyncState(Serializer ser)
{ {
base.SyncState(ser); base.SyncState(ser);
if (ser.IsReader) if (ser.IsReader)
{
BankSet(_bankNumber); BankSet(_bankNumber);
}
} }
} }
} }

View File

@ -0,0 +1,88 @@
using System.Collections.Generic;
using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{
internal sealed class Mapper0007 : CartridgeDevice
{
private readonly int[,] _banks = new int[16, 0x2000];
private int _bankNumber;
private bool _disabled;
// Fun Play mapper
// bank switching is done from DE00
public Mapper0007(IList<int[]> newData, bool game, bool exrom)
{
pinGame = game;
pinExRom = exrom;
_disabled = false;
// load data into the banks from the list
for (var j = 0; j < 16; j++)
{
for (var i = 0; i < 0x2000; i++)
{
_banks[j, i] = newData[j][i];
}
}
_bankNumber = 0;
}
protected override void SyncStateInternal(Serializer ser)
{
ser.Sync("BankNumber", ref _bankNumber);
ser.Sync("Disabled", ref _disabled);
}
public override int Peek8000(int addr)
{
if (!_disabled)
{
return _banks[_bankNumber, addr];
}
return base.Read8000(addr);
}
public override void PokeDE00(int addr, int val)
{
if (addr == 0)
{
byte tempBank = (byte)((val & 0x1) << 3);
tempBank |= (byte)((val & 0x38) >> 3);
_bankNumber = tempBank;
if (val == 0x86)
{
_disabled = true;
}
}
}
public override int Read8000(int addr)
{
if (!_disabled)
{
return _banks[_bankNumber, addr];
}
return base.Read8000(addr);
}
public override void WriteDE00(int addr, int val)
{
if (addr == 0)
{
byte tempBank = (byte)((val & 0x1) << 3);
tempBank |= (byte)((val & 0x38) >> 3);
_bankNumber = tempBank;
if (val == 0x86)
{
_disabled = true;
}
}
}
}
}

View File

@ -1,12 +1,11 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{ {
internal sealed class Mapper0008 : CartridgeDevice internal sealed class Mapper0008 : CartridgeDevice
{ {
private int[,] _banks = new int[4,0x4000]; private readonly int[,] _banks = new int[4, 0x4000];
private int _bankMask; private int _bankMask;
private int _bankNumber; private int _bankNumber;
@ -15,7 +14,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// SuperGame mapper // SuperGame mapper
// bank switching is done from DF00 // bank switching is done from DF00
public Mapper0008(IList<int[]> newData) public Mapper0008(IList<int[]> newData)
{ {
pinGame = false; pinGame = false;
@ -30,9 +28,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{ {
for (var i = 0; i < 0x4000; i++) for (var i = 0; i < 0x4000; i++)
{ {
_banks[j,i] = newData[j][i]; _banks[j, i] = newData[j][i];
} }
} }
BankSet(0); BankSet(0);
} }
@ -44,7 +43,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
ser.Sync("Latchedvalue", ref _latchedval); ser.Sync("Latchedvalue", ref _latchedval);
} }
public void BankSet(int index) private void BankSet(int index)
{ {
if (!_disabled) if (!_disabled)
{ {
@ -69,7 +68,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
public override void PokeDF00(int addr, int val) public override void PokeDF00(int addr, int val)
{ {
if (addr == 0) if (addr == 0)
{
BankSet(val); BankSet(val);
}
} }
public override int Read8000(int addr) public override int Read8000(int addr)
@ -85,7 +86,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
public override void WriteDF00(int addr, int val) public override void WriteDF00(int addr, int val)
{ {
if (addr == 0) if (addr == 0)
{
BankSet(val); BankSet(val);
}
} }
public override int ReadDF00(int addr) public override int ReadDF00(int addr)
@ -97,8 +100,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{ {
base.SyncState(ser); base.SyncState(ser);
if (ser.IsReader) if (ser.IsReader)
{
BankSet(_bankNumber); BankSet(_bankNumber);
}
} }
} }
} }

View File

@ -16,9 +16,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// This constant differs depending on whose research you reference. TODO: Verify. // This constant differs depending on whose research you reference. TODO: Verify.
private const int RESET_CAPACITOR_CYCLES = 512; private const int RESET_CAPACITOR_CYCLES = 512;
private int _capacitorCycles;
private readonly int[] _rom; private readonly int[] _rom;
private int _capacitorCycles;
public Mapper000A(IList<int[]> newData) public Mapper000A(IList<int[]> newData)
{ {

View File

@ -20,7 +20,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
validCartridge = false; validCartridge = false;
for (var i = 0; i < 0x4000; i++) for (var i = 0; i < 0x4000; i++)
{
_rom[i] = 0xFF; _rom[i] = 0xFF;
}
if (newAddresses[0] != 0x8000) if (newAddresses[0] != 0x8000)
{ {

View File

@ -30,7 +30,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// build dummy bank // build dummy bank
var dummyBank = new int[0x2000]; var dummyBank = new int[0x2000];
for (var i = 0; i < 0x2000; i++) for (var i = 0; i < 0x2000; i++)
{
dummyBank[i] = 0xFF; // todo: determine if this is correct dummyBank[i] = 0xFF; // todo: determine if this is correct
}
switch (count) switch (count)
{ {
@ -68,7 +70,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// for safety, initialize all banks to dummy // for safety, initialize all banks to dummy
for (var i = 0; i < _banks.Length; i++) for (var i = 0; i < _banks.Length; i++)
{
_banks[i] = dummyBank; _banks[i] = dummyBank;
}
// now load in the banks // now load in the banks
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
@ -124,7 +128,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{ {
base.SyncState(ser); base.SyncState(ser);
if (ser.IsReader) if (ser.IsReader)
{
BankSet(_bankNumber); BankSet(_bankNumber);
}
} }
} }
} }

View File

@ -18,7 +18,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// Zaxxon and Super Zaxxon cartridges // Zaxxon and Super Zaxxon cartridges
// - read to 8xxx selects bank 0 in A000-BFFF // - read to 8xxx selects bank 0 in A000-BFFF
// - read to 9xxx selects bank 1 in A000-BFFF // - read to 9xxx selects bank 1 in A000-BFFF
public Mapper0012(IList<int> newAddresses, IList<int> newBanks, IList<int[]> newData) public Mapper0012(IList<int> newAddresses, IList<int> newBanks, IList<int[]> newData)
{ {
_bankMain = new int[0x2000]; _bankMain = new int[0x2000];
@ -27,7 +26,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// create dummy bank just in case // create dummy bank just in case
for (var i = 0; i < 0x2000; i++) for (var i = 0; i < 0x2000; i++)
{
dummyBank[i] = 0xFF; dummyBank[i] = 0xFF;
}
_bankHigh[0] = dummyBank; _bankHigh[0] = dummyBank;
_bankHigh[1] = dummyBank; _bankHigh[1] = dummyBank;
@ -36,9 +37,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
for (var i = 0; i < newAddresses.Count; i++) for (var i = 0; i < newAddresses.Count; i++)
{ {
if (newAddresses[i] == 0x8000) if (newAddresses[i] == 0x8000)
{
Array.Copy(newData[i], _bankMain, 0x1000); Array.Copy(newData[i], _bankMain, 0x1000);
}
else if ((newAddresses[i] == 0xA000 || newAddresses[i] == 0xE000) && newBanks[i] < 2) else if ((newAddresses[i] == 0xA000 || newAddresses[i] == 0xE000) && newBanks[i] < 2)
{
_bankHigh[newBanks[i]] = newData[i]; _bankHigh[newBanks[i]] = newData[i];
}
} }
// mirror the main rom from 8000 to 9000 // mirror the main rom from 8000 to 9000
@ -47,7 +52,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// set both pins low for 16k rom config // set both pins low for 16k rom config
pinExRom = false; pinExRom = false;
pinGame = false; pinGame = false;
} }
protected override void SyncStateInternal(Serializer ser) protected override void SyncStateInternal(Serializer ser)
@ -82,7 +86,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{ {
base.SyncState(ser); base.SyncState(ser);
if (ser.IsReader) if (ser.IsReader)
{
_bankHighSelected = _bankHigh[_bankIndex]; _bankHighSelected = _bankHigh[_bankIndex];
}
} }
} }
} }

View File

@ -34,7 +34,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// build dummy bank // build dummy bank
var dummyBank = new int[0x2000]; var dummyBank = new int[0x2000];
for (var i = 0; i < 0x2000; i++) for (var i = 0; i < 0x2000; i++)
{
dummyBank[i] = 0xFF; // todo: determine if this is correct dummyBank[i] = 0xFF; // todo: determine if this is correct
}
switch (count) switch (count)
{ {
@ -56,7 +58,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
// for safety, initialize all banks to dummy // for safety, initialize all banks to dummy
for (var i = 0; i < _banks.Length; i++) for (var i = 0; i < _banks.Length; i++)
{
_banks[i] = dummyBank; _banks[i] = dummyBank;
}
// now load in the banks // now load in the banks
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
@ -92,7 +96,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
public override void PokeDE00(int addr, int val) public override void PokeDE00(int addr, int val)
{ {
if (addr == 0x00) if (addr == 0x00)
{
BankSet(val); BankSet(val);
}
} }
public override int Read8000(int addr) public override int Read8000(int addr)
@ -118,14 +124,18 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
public override void WriteDE00(int addr, int val) public override void WriteDE00(int addr, int val)
{ {
if (addr == 0x00) if (addr == 0x00)
{
BankSet(val); BankSet(val);
}
} }
public override void SyncState(Serializer ser) public override void SyncState(Serializer ser)
{ {
base.SyncState(ser); base.SyncState(ser);
if (ser.IsReader) if (ser.IsReader)
{
BankSet(_bankNumber | (_romEnable ? 0x00 : 0x80)); BankSet(_bankNumber | (_romEnable ? 0x00 : 0x80));
}
} }
} }
} }

View File

@ -34,7 +34,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
private bool _boardLed; private bool _boardLed;
private bool _jumper = false; private bool _jumper;
private int _stateBits; private int _stateBits;
@ -138,9 +138,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{ {
addr &= 0x02; addr &= 0x02;
if (addr == 0x00) if (addr == 0x00)
{
BankSet(val); BankSet(val);
}
else else
{
StateSet(val); StateSet(val);
}
} }
public override void PokeDF00(int addr, int val) public override void PokeDF00(int addr, int val)
@ -181,6 +185,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
case 0x0002: case 0x0002:
return 0x00; return 0x00;
} }
break; break;
case 0xA0: case 0xA0:
break; break;
@ -195,9 +200,14 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{ {
_stateBits = val &= 0x87; _stateBits = val &= 0x87;
if ((val & 0x04) != 0) if ((val & 0x04) != 0)
{
pinGame = (val & 0x01) == 0; pinGame = (val & 0x01) == 0;
}
else else
{
pinGame = _jumper; pinGame = _jumper;
}
pinExRom = (val & 0x02) == 0; pinExRom = (val & 0x02) == 0;
_boardLed = (val & 0x80) != 0; _boardLed = (val & 0x80) != 0;
_internalRomState = 0; _internalRomState = 0;
@ -242,6 +252,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
addr &= 0x1FFF; addr &= 0x1FFF;
_banksB[addr | _bankOffset] = val & 0xFF; _banksB[addr | _bankOffset] = val & 0xFF;
} }
break; break;
} }
} }
@ -282,9 +293,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{ {
addr &= 0x02; addr &= 0x02;
if (addr == 0x00) if (addr == 0x00)
{
BankSet(val); BankSet(val);
}
else else
{
StateSet(val); StateSet(val);
}
} }
public override void WriteDF00(int addr, int val) public override void WriteDF00(int addr, int val)

View File

@ -17,10 +17,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cassette
public override void HardReset() public override void HardReset()
{ {
if (_tape != null) _tape?.Rewind();
{
_tape.Rewind();
}
} }
public override bool ReadDataInputBuffer() public override bool ReadDataInputBuffer()

View File

@ -3,7 +3,6 @@
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
// used as Color RAM in C64 // used as Color RAM in C64
public sealed class Chip2114 public sealed class Chip2114
{ {
private int[] _ram = new int[0x400]; private int[] _ram = new int[0x400];

View File

@ -12,7 +12,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// 4464 typically // 4464 typically
// memory is striped 00/FF at intervals of 0x40 // memory is striped 00/FF at intervals of 0x40
public sealed class Chip4864 public sealed class Chip4864
{ {
private int[] _ram; private int[] _ram;
@ -27,7 +26,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
// stripe the ram // stripe the ram
for (var i = 0; i < 10000; i++) for (var i = 0; i < 10000; i++)
{
_ram[i] = (i & 0x40) != 0 ? 0xFF : 0x00; _ram[i] = (i & 0x40) != 0 ? 0xFF : 0x00;
}
} }
public int Peek(int addr) public int Peek(int addr)

View File

@ -11,19 +11,19 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
return new Dictionary<string, RegisterValue> return new Dictionary<string, RegisterValue>
{ {
{ "A", _cpu.A }, ["A"] = _cpu.A,
{ "X", _cpu.X }, ["X"] = _cpu.X,
{ "Y", _cpu.Y }, ["Y"] = _cpu.Y,
{ "S", _cpu.S }, ["S"] = _cpu.S,
{ "PC", _cpu.PC }, ["PC"] = _cpu.PC,
{ "Flag C", _cpu.FlagC }, ["Flag C"] = _cpu.FlagC,
{ "Flag Z", _cpu.FlagZ }, ["Flag Z"] = _cpu.FlagZ,
{ "Flag I", _cpu.FlagI }, ["Flag I"] = _cpu.FlagI,
{ "Flag D", _cpu.FlagD }, ["Flag D"] = _cpu.FlagD,
{ "Flag B", _cpu.FlagB }, ["Flag B"] = _cpu.FlagB,
{ "Flag V", _cpu.FlagV }, ["Flag V"] = _cpu.FlagV,
{ "Flag N", _cpu.FlagN }, ["Flag N"] = _cpu.FlagN,
{ "Flag T", _cpu.FlagT } ["Flag T"] = _cpu.FlagT
}; };
} }
@ -64,7 +64,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
} }
void IDebuggable.Step(StepType type) void IDebuggable.Step(StepType type)
{ {
switch (type) switch (type)
@ -81,10 +80,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
} }
int IDebuggable.TotalExecutedCycles int IDebuggable.TotalExecutedCycles => _cpu.TotalExecutedCycles;
{
get { return _cpu.TotalExecutedCycles; }
}
private void StepInto() private void StepInto()
{ {
@ -92,6 +88,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
DebuggerStep(); DebuggerStep();
} }
while (!_cpu.AtInstructionStart()) while (!_cpu.AtInstructionStart())
{ {
DebuggerStep(); DebuggerStep();
@ -151,8 +148,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private const byte JsrSize = 3; private const byte JsrSize = 3;
private IMemoryCallbackSystem _memoryCallbacks = new MemoryCallbackSystem(); IMemoryCallbackSystem IDebuggable.MemoryCallbacks { get; } = new MemoryCallbackSystem();
IMemoryCallbackSystem IDebuggable.MemoryCallbacks { get { return _memoryCallbacks; } }
} }
} }

View File

@ -1,8 +1,6 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Components.M6502;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
@ -15,20 +13,21 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public string Cpu public string Cpu
{ {
get { return "6510"; } get
{
return "6510";
}
set set
{ {
} }
} }
public string PCRegisterName public string PCRegisterName => "PC";
{
get { return "PC"; }
}
public string Disassemble(MemoryDomain m, uint addr, out int length) public string Disassemble(MemoryDomain m, uint addr, out int length)
{ {
return Components.M6502.MOS6502X.Disassemble((ushort)addr, out length, CpuPeek); return MOS6502X.Disassemble((ushort)addr, out length, CpuPeek);
} }
} }
} }

View File

@ -7,12 +7,10 @@ using BizHawk.Emulation.Cores.Components.M6502;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
// an extension of the 6502 processor // an extension of the 6502 processor
public sealed partial class Chip6510 public sealed partial class Chip6510
{ {
// ------------------------------------ // ------------------------------------
private readonly MOS6502X _cpu;
private MOS6502X _cpu;
private bool _pinNmiLast; private bool _pinNmiLast;
private LatchedPort _port; private LatchedPort _port;
private bool _thisNmi; private bool _thisNmi;
@ -47,10 +45,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
HardReset(); HardReset();
} }
public string TraceHeader public string TraceHeader => "6510: PC, machine code, mnemonic, operands, registers (A, X, Y, P, SP), flags (NVTBDIZCR)";
{
get { return "6510: PC, machine code, mnemonic, operands, registers (A, X, Y, P, SP), flags (NVTBDIZCR)"; }
}
public Action<TraceInfo> TraceCallback public Action<TraceInfo> TraceCallback
{ {
@ -89,7 +84,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
// ------------------------------------ // ------------------------------------
public void ExecutePhase() public void ExecutePhase()
{ {
_cpu.RDY = ReadRdy(); _cpu.RDY = ReadRdy();
@ -116,7 +110,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
// ------------------------------------ // ------------------------------------
public ushort Pc public ushort Pc
{ {
get get
@ -153,14 +146,14 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
set { _cpu.S = unchecked((byte)value); } set { _cpu.S = unchecked((byte)value); }
} }
public bool FlagC { get { return _cpu.FlagC; } } public bool FlagC => _cpu.FlagC;
public bool FlagZ { get { return _cpu.FlagZ; } } public bool FlagZ => _cpu.FlagZ;
public bool FlagI { get { return _cpu.FlagI; } } public bool FlagI => _cpu.FlagI;
public bool FlagD { get { return _cpu.FlagD; } } public bool FlagD => _cpu.FlagD;
public bool FlagB { get { return _cpu.FlagB; } } public bool FlagB => _cpu.FlagB;
public bool FlagV { get { return _cpu.FlagV; } } public bool FlagV => _cpu.FlagV;
public bool FlagN { get { return _cpu.FlagN; } } public bool FlagN => _cpu.FlagN;
public bool FlagT { get { return _cpu.FlagT; } } public bool FlagT => _cpu.FlagT;
public int Peek(int addr) public int Peek(int addr)
{ {
@ -191,17 +184,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
} }
public int PortData public int PortData => _port.ReadInput(ReadPort());
{
get
{
return _port.ReadInput(ReadPort());
}
set
{
_port.Latch = value;
}
}
public int Read(int addr) public int Read(int addr)
{ {

View File

@ -1,7 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {

View File

@ -1,5 +1,4 @@
using System; using System;
using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
@ -8,7 +7,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// emulation notes: // emulation notes:
// * CS, R/W and RS# pins are not emulated. (not needed) // * CS, R/W and RS# pins are not emulated. (not needed)
// * A low RES pin is emulated via HardReset(). // * A low RES pin is emulated via HardReset().
public static class Chip6526 public static class Chip6526
{ {
public static Cia Create(C64.CiaType type, Func<int> readIec) public static Cia Create(C64.CiaType type, Func<int> readIec)

View File

@ -17,12 +17,13 @@
private static readonly int[] Ba = Vic.TimingBuilder_BA(Fetch); private static readonly int[] Ba = Vic.TimingBuilder_BA(Fetch);
private static readonly int[] Act = Vic.TimingBuilder_Act(Timing, 0x004, 0x154, 0x164); private static readonly int[] Act = Vic.TimingBuilder_Act(Timing, 0x004, 0x154, 0x164);
private static readonly int[][] Pipeline = { private static readonly int[][] Pipeline =
Timing, {
Fetch, Timing,
Ba, Fetch,
Act Ba,
}; Act
};
public static Vic Create(C64.BorderType borderType) public static Vic Create(C64.BorderType borderType)
{ {
@ -33,8 +34,8 @@
HblankStart, HblankEnd, HblankStart, HblankEnd,
Vblankstart, VblankEnd, Vblankstart, VblankEnd,
borderType, borderType,
762, 1000 762,
); 1000);
} }
} }
} }

View File

@ -17,12 +17,13 @@
private static readonly int[] Ba = Vic.TimingBuilder_BA(Fetch); private static readonly int[] Ba = Vic.TimingBuilder_BA(Fetch);
private static readonly int[] Act = Vic.TimingBuilder_Act(Timing, 0x004, 0x154, 0x16C); private static readonly int[] Act = Vic.TimingBuilder_Act(Timing, 0x004, 0x154, 0x16C);
private static readonly int[][] Pipeline = { private static readonly int[][] Pipeline =
Timing, {
Fetch, Timing,
Ba, Fetch,
Act Ba,
}; Act
};
public static Vic Create(C64.BorderType borderType) public static Vic Create(C64.BorderType borderType)
{ {
@ -33,8 +34,8 @@
HblankStart, HblankEnd, HblankStart, HblankEnd,
VblankStart, VblankEnd, VblankStart, VblankEnd,
borderType, borderType,
6136, 8182 6136,
); 8182);
} }
} }
} }

View File

@ -17,12 +17,13 @@
private static readonly int[] Ba = Vic.TimingBuilder_BA(Fetch); private static readonly int[] Ba = Vic.TimingBuilder_BA(Fetch);
private static readonly int[] Act = Vic.TimingBuilder_Act(Timing, 0x004, 0x14C, 0x164); private static readonly int[] Act = Vic.TimingBuilder_Act(Timing, 0x004, 0x14C, 0x164);
private static readonly int[][] Pipeline = { private static readonly int[][] Pipeline =
Timing, {
Fetch, Timing,
Ba, Fetch,
Act Ba,
}; Act
};
public static Vic Create(C64.BorderType borderType) public static Vic Create(C64.BorderType borderType)
{ {
@ -33,8 +34,8 @@
HblankStart, HblankEnd, HblankStart, HblankEnd,
VblankStart, VblankEnd, VblankStart, VblankEnd,
borderType, borderType,
7375, 7882 7375,
); 7882);
} }
} }
} }

View File

@ -17,12 +17,13 @@
private static readonly int[] Ba = Vic.TimingBuilder_BA(Fetch); private static readonly int[] Ba = Vic.TimingBuilder_BA(Fetch);
private static readonly int[] Act = Vic.TimingBuilder_Act(Timing, 0x004, 0x154, 0x16C); private static readonly int[] Act = Vic.TimingBuilder_Act(Timing, 0x004, 0x154, 0x16C);
private static readonly int[][] Pipeline = { private static readonly int[][] Pipeline =
Timing, {
Fetch, Timing,
Ba, Fetch,
Act Ba,
}; Act
};
public static Vic Create(C64.BorderType borderType) public static Vic Create(C64.BorderType borderType)
{ {
@ -33,8 +34,8 @@
HblankStart, HblankEnd, HblankStart, HblankEnd,
VblankStart, VblankEnd, VblankStart, VblankEnd,
borderType, borderType,
908, 1000 908,
); 1000);
} }
} }
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,11 +5,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
// emulates the PLA // emulates the PLA
// which handles all bank switching // which handles all bank switching
public sealed class Chip90611401 public sealed class Chip90611401
{ {
// ------------------------------------ // ------------------------------------
public Func<int, int> PeekBasicRom; public Func<int, int> PeekBasicRom;
public Func<int, int> PeekCartridgeLo; public Func<int, int> PeekCartridgeLo;
public Func<int, int> PeekCartridgeHi; public Func<int, int> PeekCartridgeHi;
@ -65,7 +63,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public Action<int, int> WriteVic; public Action<int, int> WriteVic;
// ------------------------------------ // ------------------------------------
private enum PlaBank private enum PlaBank
{ {
None, None,
@ -85,7 +82,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
// ------------------------------------ // ------------------------------------
private bool _p24; private bool _p24;
private bool _p25; private bool _p25;
private bool _p26; private bool _p26;
@ -122,21 +118,38 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// character rom, banked in at D000-DFFF // character rom, banked in at D000-DFFF
_charen = ReadCharen(); _charen = ReadCharen();
if (read && !_charen && (((_hiram || _loram) && _game) || (_hiram && !_exrom && !_game))) if (read && !_charen && (((_hiram || _loram) && _game) || (_hiram && !_exrom && !_game)))
{
return PlaBank.CharRom; return PlaBank.CharRom;
}
// io block, banked in at D000-DFFF // io block, banked in at D000-DFFF
if ((_charen && (_hiram || _loram)) || (_exrom && !_game)) if ((_charen && (_hiram || _loram)) || (_exrom && !_game))
{ {
if (addr < 0xD400) if (addr < 0xD400)
{
return PlaBank.Vic; return PlaBank.Vic;
}
if (addr < 0xD800) if (addr < 0xD800)
{
return PlaBank.Sid; return PlaBank.Sid;
}
if (addr < 0xDC00) if (addr < 0xDC00)
{
return PlaBank.ColorRam; return PlaBank.ColorRam;
}
if (addr < 0xDD00) if (addr < 0xDD00)
{
return PlaBank.Cia0; return PlaBank.Cia0;
}
if (addr < 0xDE00) if (addr < 0xDE00)
{
return PlaBank.Cia1; return PlaBank.Cia1;
}
return addr < 0xDF00 return addr < 0xDF00
? PlaBank.Expansion0 ? PlaBank.Expansion0
: PlaBank.Expansion1; : PlaBank.Expansion1;
@ -145,31 +158,41 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// cartridge high, banked either at A000-BFFF or E000-FFFF depending // cartridge high, banked either at A000-BFFF or E000-FFFF depending
if (_a13 && !_game && ((_hiram && !_a14 && read && !_exrom) || (_a14 && _exrom))) if (_a13 && !_game && ((_hiram && !_a14 && read && !_exrom) || (_a14 && _exrom)))
{
return PlaBank.CartridgeHi; return PlaBank.CartridgeHi;
}
// cartridge low, banked at 8000-9FFF // cartridge low, banked at 8000-9FFF
if (!_a14 && !_a13 && ((_loram && _hiram && read && !_exrom) || (_exrom && !_game))) if (!_a14 && !_a13 && ((_loram && _hiram && read && !_exrom) || (_exrom && !_game)))
{
return PlaBank.CartridgeLo; return PlaBank.CartridgeLo;
}
// kernal rom, banked at E000-FFFF // kernal rom, banked at E000-FFFF
if (_hiram && _a14 && _a13 && read && (_game || (!_exrom && !_game))) if (_hiram && _a14 && _a13 && read && (_game || (!_exrom && !_game)))
{
return PlaBank.KernalRom; return PlaBank.KernalRom;
}
// basic rom, banked at A000-BFFF // basic rom, banked at A000-BFFF
if (_loram && _hiram && !_a14 && _a13 && read && _game) if (_loram && _hiram && !_a14 && _a13 && read && _game)
{
return PlaBank.BasicRom; return PlaBank.BasicRom;
}
} }
// ultimax mode ram exclusion // ultimax mode ram exclusion
if (_exrom && !_game) if (_exrom && !_game)
{ {
_p24 = !_a15 && !_a14 && _a12; //00x1 1000-1FFF, 3000-3FFF _p24 = !_a15 && !_a14 && _a12; // 00x1 1000-1FFF, 3000-3FFF
_p25 = !_a15 && !_a14 && _a13; //001x 2000-3FFF _p25 = !_a15 && !_a14 && _a13; // 001x 2000-3FFF
_p26 = !_a15 && _a14; //01xx 4000-7FFF _p26 = !_a15 && _a14; // 01xx 4000-7FFF
_p27 = _a15 && !_a14 && _a13; //101x A000-BFFF _p27 = _a15 && !_a14 && _a13; // 101x A000-BFFF
_p28 = _a15 && _a14 && !_a13 && !_a12; //1100 C000-CFFF _p28 = _a15 && _a14 && !_a13 && !_a12; // 1100 C000-CFFF
if (_p24 || _p25 || _p26 || _p27 || _p28) if (_p24 || _p25 || _p26 || _p27 || _p28)
{
return PlaBank.None; return PlaBank.None;
}
} }
return PlaBank.Ram; return PlaBank.Ram;
@ -206,6 +229,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
case PlaBank.Vic: case PlaBank.Vic:
return PeekVic(addr); return PeekVic(addr);
} }
return 0xFF; return 0xFF;
} }
@ -277,6 +301,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
case PlaBank.Vic: case PlaBank.Vic:
return ReadVic(addr); return ReadVic(addr);
} }
return 0xFF; return 0xFF;
} }
@ -308,11 +333,15 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// read char rom at 1000-1FFF and 9000-9FFF // read char rom at 1000-1FFF and 9000-9FFF
if (_a14 && !_a13 && _a12 && (_game || !_exrom)) if (_a14 && !_a13 && _a12 && (_game || !_exrom))
{
return ReadCharRom(addr); return ReadCharRom(addr);
}
// read cartridge rom in ultimax mode // read cartridge rom in ultimax mode
if (_a13 && _a12 && _exrom && !_game) if (_a13 && _a12 && _exrom && !_game)
{
return ReadCartridgeHi(addr); return ReadCartridgeHi(addr);
}
return ReadMemory(addr); return ReadMemory(addr);
} }
@ -327,6 +356,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
WriteMemory(addr, val); WriteMemory(addr, val);
} }
break; break;
case PlaBank.CartridgeLo: case PlaBank.CartridgeLo:
WriteCartridgeLo(addr, val); WriteCartridgeLo(addr, val);
@ -334,6 +364,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
WriteMemory(addr, val); WriteMemory(addr, val);
} }
break; break;
case PlaBank.Cia0: case PlaBank.Cia0:
WriteCia0(addr, val); WriteCia0(addr, val);

View File

@ -78,8 +78,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
} }
} }
activeColumns >>= 1; activeColumns >>= 1;
} }
return result; return result;
} }
@ -98,11 +100,14 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
result &= ~(1 << r); result &= ~(1 << r);
} }
i += 0x8; i += 0x8;
} }
} }
activeRows >>= 1; activeRows >>= 1;
} }
return result; return result;
} }

View File

@ -1,9 +1,4 @@
using System; namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
public sealed partial class Cia public sealed partial class Cia
{ {
@ -42,6 +37,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_icr = 0; _icr = 0;
return icrTemp; return icrTemp;
} }
return ReadRegister(addr); return ReadRegister(addr);
} }
@ -82,6 +78,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
case 0xF: case 0xF:
return _crb; return _crb;
} }
return 0; return 0;
} }
@ -179,7 +176,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// Toggle output begins high when timer starts. // Toggle output begins high when timer starts.
if ((_cra & 0x05) == 0x05 && (oldCra & 0x01) == 0) if ((_cra & 0x05) == 0x05 && (oldCra & 0x01) == 0)
{
_prb |= 0x40; _prb |= 0x40;
}
break; break;
case 0xF: case 0xF:
var oldCrb = _crb; var oldCrb = _crb;
@ -187,7 +186,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// Toggle output begins high when timer starts. // Toggle output begins high when timer starts.
if ((_crb & 0x05) == 0x05 && (oldCrb & 0x01) == 0) if ((_crb & 0x05) == 0x05 && (oldCrb & 0x01) == 0)
{
_prb |= 0x80; _prb |= 0x80;
}
break; break;
default: default:
WriteRegister(addr, val); WriteRegister(addr, val);
@ -261,34 +262,16 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
} }
public int DdrA public int DdrA => _ddra;
{
get { return _ddra; }
}
public int DdrB public int DdrB => _ddrb;
{
get { return _ddrb; }
}
public int PrA public int PrA => _pra;
{
get { return _pra; }
}
public int PrB public int PrB => _prb;
{
get { return _prb; }
}
public int EffectivePrA public int EffectivePrA => _pra | ~_ddra;
{
get { return _pra | ~_ddra; }
}
public int EffectivePrB public int EffectivePrB => _prb | ~_ddrb;
{
get { return _prb | ~_ddrb; }
}
} }
} }

View File

@ -1,19 +1,19 @@
using BizHawk.Common; using System;
using System; using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
public sealed partial class Cia public sealed partial class Cia
{ {
/* /*
Commodore CIA 6526 core. Commodore CIA 6526 core.
Many thanks to: Many thanks to:
- 6502.org for hosting the 6526 datasheet - 6502.org for hosting the 6526 datasheet
http://archive.6502.org/datasheets/mos_6526_cia.pdf http://archive.6502.org/datasheets/mos_6526_cia.pdf
- Christian Bauer for information on the delayed interrupt mechanism on the 6526 - Christian Bauer for information on the delayed interrupt mechanism on the 6526
http://frodo.cebix.net/ http://frodo.cebix.net/
*/ */
private enum TimerState private enum TimerState
{ {
@ -139,6 +139,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_taIrqNextCycle = false; _taIrqNextCycle = false;
TriggerInterrupt(1); TriggerInterrupt(1);
} }
if (_tbIrqNextCycle) if (_tbIrqNextCycle)
{ {
_tbIrqNextCycle = false; _tbIrqNextCycle = false;
@ -159,13 +160,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_prb &= 0xBF; _prb &= 0xBF;
_taPrb6NegativeNextCycle = false; _taPrb6NegativeNextCycle = false;
} }
if (_tbPrb7NegativeNextCycle) if (_tbPrb7NegativeNextCycle)
{ {
_prb &= 0x7F; _prb &= 0x7F;
_tbPrb7NegativeNextCycle = false; _tbPrb7NegativeNextCycle = false;
} }
switch (_taState) switch (_taState)
{ {
case TimerState.WaitThenCount: case TimerState.WaitThenCount:
@ -196,6 +197,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
_ta = _latcha; _ta = _latcha;
} }
Ta_Idle(); Ta_Idle();
break; break;
case TimerState.Count: case TimerState.Count:
@ -236,6 +238,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
_tb = _latchb; _tb = _latchb;
} }
Tb_Idle(); Tb_Idle();
break; break;
case TimerState.Count: case TimerState.Count:
@ -262,6 +265,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
TriggerInterrupt(16); TriggerInterrupt(16);
} }
_flagLatch = _flagInput; _flagLatch = _flagInput;
if (!DelayedInterrupts) if (!DelayedInterrupts)
@ -270,9 +274,14 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
if ((_cra & 0x02) != 0) if ((_cra & 0x02) != 0)
{
_ddra |= 0x40; _ddra |= 0x40;
}
if ((_crb & 0x02) != 0) if ((_crb & 0x02) != 0)
{
_ddrb |= 0x80; _ddrb |= 0x80;
}
} }
private void Ta_Count() private void Ta_Count()
@ -285,9 +294,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
Ta_Interrupt(); Ta_Interrupt();
} }
_taUnderflow = true; _taUnderflow = true;
} }
} }
Ta_Idle(); Ta_Idle();
} }
@ -319,6 +330,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
_prb ^= 0x40; _prb ^= 0x40;
} }
_ddrb |= 0x40; _ddrb |= 0x40;
} }
} }
@ -344,6 +356,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_taState = TimerState.LoadThenStop; _taState = TimerState.LoadThenStop;
} }
} }
break; break;
case TimerState.Count: case TimerState.Count:
if ((_newCra & 0x01) != 0) if ((_newCra & 0x01) != 0)
@ -359,6 +372,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
? TimerState.LoadThenStop ? TimerState.LoadThenStop
: TimerState.CountThenStop; : TimerState.CountThenStop;
} }
break; break;
case TimerState.LoadThenCount: case TimerState.LoadThenCount:
case TimerState.WaitThenCount: case TimerState.WaitThenCount:
@ -378,8 +392,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
_taState = TimerState.Stop; _taState = TimerState.Stop;
} }
break; break;
} }
_cra = _newCra & 0xEF; _cra = _newCra & 0xEF;
_hasNewCra = false; _hasNewCra = false;
} }
@ -397,6 +413,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
} }
} }
Tb_Idle(); Tb_Idle();
} }
@ -452,6 +469,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_tbState = TimerState.LoadThenStop; _tbState = TimerState.LoadThenStop;
} }
} }
break; break;
case TimerState.Count: case TimerState.Count:
if ((_newCrb & 0x01) != 0) if ((_newCrb & 0x01) != 0)
@ -467,6 +485,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
? TimerState.LoadThenStop ? TimerState.LoadThenStop
: TimerState.CountThenStop; : TimerState.CountThenStop;
} }
break; break;
case TimerState.LoadThenCount: case TimerState.LoadThenCount:
case TimerState.WaitThenCount: case TimerState.WaitThenCount:
@ -486,8 +505,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
_tbState = TimerState.Stop; _tbState = TimerState.Stop;
} }
break; break;
} }
_crb = _newCrb & 0xEF; _crb = _newCrb & 0xEF;
_hasNewCrb = false; _hasNewCrb = false;
} }
@ -496,7 +517,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private void TriggerInterrupt(int bit) private void TriggerInterrupt(int bit)
{ {
_icr |= bit; _icr |= bit;
if ((_intMask & bit) == 0) return; if ((_intMask & bit) == 0)
{
return;
}
_icr |= 0x80; _icr |= 0x80;
} }

View File

@ -1,5 +1,4 @@
using System; using BizHawk.Common;
using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
@ -26,7 +25,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// cause the pull-up resistors not to be enough to keep the bus bit set to 1 when // cause the pull-up resistors not to be enough to keep the bus bit set to 1 when
// both the direction and latch are 1 (the keyboard and joystick port 2 can do this.) // both the direction and latch are 1 (the keyboard and joystick port 2 can do this.)
// the class does not handle this case as it must be handled differently in every occurrence. // the class does not handle this case as it must be handled differently in every occurrence.
public int ReadInput(int bus) public int ReadInput(int bus)
{ {
return (Latch & Direction) | ((Direction ^ 0xFF) & bus); return (Latch & Direction) | ((Direction ^ 0xFF) & bus);
@ -75,7 +73,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public bool ReadOutput() public bool ReadOutput()
{ {
return (Latch || !Direction); return Latch || !Direction;
} }
public void SyncState(Serializer ser) public void SyncState(Serializer ser)

View File

@ -64,6 +64,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_lfsr = ((_lfsr << 1) & 0x7FFF) | feedback; _lfsr = ((_lfsr << 1) & 0x7FFF) | feedback;
return; return;
} }
_lfsr = 0x7FFF; _lfsr = 0x7FFF;
if (_state != StateAttack && ++_expCounter != _expPeriod) if (_state != StateAttack && ++_expCounter != _expPeriod)

View File

@ -1,9 +1,4 @@
using System; namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
public sealed partial class Sid public sealed partial class Sid
{ {

View File

@ -5,15 +5,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
public sealed partial class Sid : ISoundProvider public sealed partial class Sid : ISoundProvider
{ {
public bool CanProvideAsync public bool CanProvideAsync => false;
{
get { return false; }
}
public SyncSoundMode SyncMode public SyncSoundMode SyncMode => SyncSoundMode.Sync;
{
get { return SyncSoundMode.Sync; }
}
public void SetSyncMode(SyncSoundMode mode) public void SetSyncMode(SyncSoundMode mode)
{ {

View File

@ -102,12 +102,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private void ResetShiftReg() private void ResetShiftReg()
{ {
_shiftRegister = 0x7FFFFF;
{ _shiftRegisterReset = 0;
_shiftRegister = 0x7FFFFF; SetNoise();
_shiftRegisterReset = 0;
SetNoise();
}
} }
private void SetNoise() private void SetNoise()
@ -129,20 +126,17 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private void WriteShiftReg() private void WriteShiftReg()
{ {
_output &=
{ 0xBB5DA |
_output &= ((_output & 0x800) << 9) |
0xBB5DA | ((_output & 0x400) << 8) |
((_output & 0x800) << 9) | ((_output & 0x200) << 5) |
((_output & 0x400) << 8) | ((_output & 0x100) << 3) |
((_output & 0x200) << 5) | ((_output & 0x040) >> 1) |
((_output & 0x100) << 3) | ((_output & 0x020) >> 3) |
((_output & 0x040) >> 1) | ((_output & 0x010) >> 4);
((_output & 0x020) >> 3) | _noise &= _output;
((_output & 0x010) >> 4); _noNoiseOrNoise = _noNoise | _noise;
_noise &= _output;
_noNoiseOrNoise = _noNoise | _noise;
}
} }
// ------------------------------------ // ------------------------------------
@ -218,13 +212,18 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_waveformIndex = (_accumulator ^ (ringModSource._accumulator & _ringMsbMask)) >> 12; _waveformIndex = (_accumulator ^ (ringModSource._accumulator & _ringMsbMask)) >> 12;
_output = _wave[_waveformIndex] & (_noPulse | _pulse) & _noNoiseOrNoise; _output = _wave[_waveformIndex] & (_noPulse | _pulse) & _noNoiseOrNoise;
if (_waveform > 8) if (_waveform > 8)
{
WriteShiftReg(); WriteShiftReg();
}
} }
else else
{ {
if (_floatOutputTtl != 0 && --_floatOutputTtl == 0) if (_floatOutputTtl != 0 && --_floatOutputTtl == 0)
{
_output = 0x000; _output = 0x000;
}
} }
_pulse = _accumulator >> 12 >= _pulseWidth ? 0xFFF : 0x000; _pulse = _accumulator >> 12 >= _pulseWidth ? 0xFFF : 0x000;
return _output; return _output;
} }
@ -236,6 +235,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
return _pulseWidth & 0xFF; return _pulseWidth & 0xFF;
} }
set set
{ {
_pulseWidth &= 0x0F00; _pulseWidth &= 0x0F00;
@ -249,6 +249,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
return _pulseWidth >> 8; return _pulseWidth >> 8;
} }
set set
{ {
_pulseWidth &= 0x00FF; _pulseWidth &= 0x00FF;
@ -256,46 +257,23 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
} }
public bool RingMod public bool RingMod => _ringMod;
{
get
{
return _ringMod;
}
}
public bool Sync public bool Sync => _sync;
{
get
{
return _sync;
}
}
public void Synchronize(Voice target, Voice source) public void Synchronize(Voice target, Voice source)
{ {
if (_msbRising && target._sync && !(_sync && source._msbRising)) if (_msbRising && target._sync && !(_sync && source._msbRising))
{
target._accumulator = 0; target._accumulator = 0;
}
public bool Test
{
get
{
return _test;
} }
} }
public int Waveform public bool Test => _test;
{
get public int Waveform => _waveform;
{
return _waveform;
}
}
// ------------------------------------ // ------------------------------------
public void SyncState(Serializer ser) public void SyncState(Serializer ser)
{ {
ser.Sync("_accBits", ref _accBits); ser.Sync("_accBits", ref _accBits);

View File

@ -1,7 +1,6 @@
using System; using System;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
@ -124,10 +123,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_potX = ReadPotX(); _potX = ReadPotX();
_potY = ReadPotY(); _potY = ReadPotY();
} }
_potCounter--; _potCounter--;
} }
public void Flush(bool flush_filter) public void Flush(bool flushFilter)
{ {
while (_cachedCycles > 0) while (_cachedCycles > 0)
@ -198,7 +198,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
//here we need to apply filtering to the samples and add them back to the buffer //here we need to apply filtering to the samples and add them back to the buffer
if (flush_filter) if (flushFilter)
{ {
if (_filterEnable[0] | _filterEnable[1] | _filterEnable[2]) if (_filterEnable[0] | _filterEnable[1] | _filterEnable[2])
{ {

View File

@ -108,8 +108,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
(_readClock() ? 0x04 : 0x00) | (_readClock() ? 0x04 : 0x00) |
(_readData() ? 0x01 : 0x00) | (_readData() ? 0x01 : 0x00) |
(_readAtn() ? 0x80 : 0x00) | (_readAtn() ? 0x80 : 0x00) |
_driveNumber) _driveNumber));
);
} }
public int ReadExternalPra() public int ReadExternalPra()
@ -120,10 +119,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public int ReadExternalPrb() public int ReadExternalPrb()
{ {
return return
(_readClock() ? 0x04 : 0x00) | (_readClock() ? 0x04 : 0x00) |
(_readData() ? 0x01 : 0x00) | (_readData() ? 0x01 : 0x00) |
(_readAtn() ? 0x80 : 0x00) | (_readAtn() ? 0x80 : 0x00) |
_driveNumber; _driveNumber;
} }
public void SyncState(Serializer ser) public void SyncState(Serializer ser)

View File

@ -47,6 +47,7 @@
} }
break; break;
} }
return ReadRegister(addr); return ReadRegister(addr);
} }
@ -87,6 +88,7 @@
case 0xF: case 0xF:
return _port.ReadPra(_pra, _ddra); return _port.ReadPra(_pra, _ddra);
} }
return 0xFF; return 0xFF;
} }
@ -109,6 +111,7 @@
{ {
_handshakeCa2NextClock = true; _handshakeCa2NextClock = true;
} }
WriteRegister(addr, val); WriteRegister(addr, val);
break; break;
case 0x4: case 0x4:
@ -137,6 +140,7 @@
_t2C = _t2L; _t2C = _t2L;
_t2CLoaded = true; _t2CLoaded = true;
} }
_t2Delayed = 1; _t2Delayed = 1;
break; break;
case 0xA: case 0xA:
@ -221,44 +225,20 @@
} }
} }
public int DdrA public int DdrA => _ddra;
{
get { return _ddra; }
}
public int DdrB public int DdrB => _ddrb;
{
get { return _ddrb; }
}
public int PrA public int PrA => _pra;
{
get { return _pra; }
}
public int PrB public int PrB => _prb;
{
get { return _prb; }
}
public int EffectivePrA public int EffectivePrA => _pra | ~_ddra;
{
get { return _pra | ~_ddra; }
}
public int EffectivePrB public int EffectivePrB => _prb | ~_ddrb;
{
get { return _prb | ~_ddrb; }
}
public int ActualPrA public int ActualPrA => _acrPaLatchEnable ? _paLatch : _port.ReadPra(_pra, _ddra);
{
get { return _acrPaLatchEnable ? _paLatch : _port.ReadPra(_pra, _ddra); }
}
public int ActualPrB public int ActualPrB => _acrPbLatchEnable ? _pbLatch : _port.ReadPrb(_prb, _ddrb);
{
get { return _acrPbLatchEnable ? _pbLatch : _port.ReadPrb(_prb, _ddrb); }
}
} }
} }

View File

@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Cores.Computers.Commodore64.Media;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
@ -102,10 +98,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_ca1L = true; _ca1L = true;
} }
public bool Irq public bool Irq => (_ifr & 0x80) == 0;
{
get { return (_ifr & 0x80) == 0; }
}
public void HardReset() public void HardReset()
{ {
@ -158,7 +151,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_interruptNextClock = 0; _interruptNextClock = 0;
// Process 'pulse' and 'handshake' outputs on CA2 and CB2 // Process 'pulse' and 'handshake' outputs on CA2 and CB2
if (_resetCa2NextClock) if (_resetCa2NextClock)
{ {
Ca2 = true; Ca2 = true;
@ -184,7 +176,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
// Count timers // Count timers
if (_t1Delayed > 0) if (_t1Delayed > 0)
{ {
_t1Delayed--; _t1Delayed--;
@ -199,6 +190,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_interruptNextClock |= 0x40; _interruptNextClock |= 0x40;
_t1CLoaded = false; _t1CLoaded = false;
} }
switch (_acrT1Control) switch (_acrT1Control)
{ {
case ACR_T1_CONTROL_CONTINUOUS_INTERRUPTS: case ACR_T1_CONTROL_CONTINUOUS_INTERRUPTS:
@ -211,6 +203,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_t1CLoaded = true; _t1CLoaded = true;
break; break;
} }
_t1C &= 0xFFFF; _t1C &= 0xFFFF;
} }
} }
@ -252,7 +245,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
// Process CA2 // Process CA2
switch (_pcrCa2Control) switch (_pcrCa2Control)
{ {
case PCR_CONTROL_INPUT_NEGATIVE_ACTIVE_EDGE: case PCR_CONTROL_INPUT_NEGATIVE_ACTIVE_EDGE:
@ -283,7 +275,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
// Process CB2 // Process CB2
switch (_pcrCb2Control) switch (_pcrCb2Control)
{ {
case PCR_CONTROL_INPUT_NEGATIVE_ACTIVE_EDGE: case PCR_CONTROL_INPUT_NEGATIVE_ACTIVE_EDGE:
@ -314,7 +305,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
} }
// interrupt generation // interrupt generation
if ((_pcrCb1IntControl == PCR_INT_CONTROL_POSITIVE_EDGE && Cb1 && !_cb1L) || if ((_pcrCb1IntControl == PCR_INT_CONTROL_POSITIVE_EDGE && Cb1 && !_cb1L) ||
(_pcrCb1IntControl == PCR_INT_CONTROL_NEGATIVE_EDGE && !Cb1 && _cb1L)) (_pcrCb1IntControl == PCR_INT_CONTROL_NEGATIVE_EDGE && !Cb1 && _cb1L))
{ {

View File

@ -80,6 +80,7 @@
_dataC = 0; _dataC = 0;
_bufferC[_vmli] = _dataC; _bufferC[_vmli] = _dataC;
} }
_srColorSync |= 0x01 << (7 - _xScroll); _srColorSync |= 0x01 << (7 - _xScroll);
break; break;
case FetchTypeGraphics: case FetchTypeGraphics:
@ -91,6 +92,7 @@
else else
_parseAddr = _rc | ((_dataC & 0xFF) << 3) | (_pointerCb << 11); _parseAddr = _rc | ((_dataC & 0xFF) << 3) | (_pointerCb << 11);
} }
if (_extraColorModeBuffer) if (_extraColorModeBuffer)
_parseAddr &= AddressMaskEc; _parseAddr &= AddressMaskEc;
_dataG = ReadMemory(_parseAddr); _dataG = ReadMemory(_parseAddr);
@ -151,7 +153,9 @@
foreach (var spr in _sprites) // sprite rule 1 foreach (var spr in _sprites) // sprite rule 1
{ {
if (!spr.YExpand) if (!spr.YExpand)
{
spr.YCrunch = true; spr.YCrunch = true;
}
} }
if ((_parseAct & PipelineUpdateMcBase) != 0) // VIC addendum sprite rule 7 if ((_parseAct & PipelineUpdateMcBase) != 0) // VIC addendum sprite rule 7
@ -187,7 +191,9 @@
foreach (var spr in _sprites) foreach (var spr in _sprites)
{ {
if (spr.Dma && spr.YExpand) if (spr.Dma && spr.YExpand)
{
spr.YCrunch ^= true; spr.YCrunch ^= true;
}
} }
} }
@ -199,7 +205,9 @@
if (spr.Dma) if (spr.Dma)
{ {
if (spr.Enable && spr.Y == (_rasterLine & 0xFF)) if (spr.Enable && spr.Y == (_rasterLine & 0xFF))
{
spr.Display = true; spr.Display = true;
}
} }
else else
{ {
@ -216,7 +224,9 @@
_srColorIndexLatch = 0; _srColorIndexLatch = 0;
_vmli = 0; _vmli = 0;
if (_badline) if (_badline)
{
_rc = 0; _rc = 0;
}
} }
if ((_parseAct & PipelineUpdateRc) != 0) // VC/RC rule 5 if ((_parseAct & PipelineUpdateRc) != 0) // VC/RC rule 5
@ -226,6 +236,7 @@
_idle = true; _idle = true;
_vcbase = _vc; _vcbase = _vc;
} }
if (!_idle || _badline) if (!_idle || _badline)
{ {
_rc = (_rc + 1) & 0x7; _rc = (_rc + 1) & 0x7;

View File

@ -197,9 +197,11 @@
{ {
spr.Mc = (0x2a & spr.Mcbase & spr.Mc) | (0x15 & (spr.Mcbase | spr.Mc)); spr.Mc = (0x2a & spr.Mcbase & spr.Mc) | (0x15 & (spr.Mcbase | spr.Mc));
} }
spr.YCrunch = true; spr.YCrunch = true;
} }
} }
WriteRegister(addr, val); WriteRegister(addr, val);
break; break;
case 0x19: case 0x19:

View File

@ -300,9 +300,14 @@
} }
if (_pixBufferBorderIndex >= PixBorderBufferSize) if (_pixBufferBorderIndex >= PixBorderBufferSize)
{
_pixBufferBorderIndex = 0; _pixBufferBorderIndex = 0;
}
if (_pixBufferIndex >= PixBufferSize) if (_pixBufferIndex >= PixBufferSize)
{
_pixBufferIndex = 0; _pixBufferIndex = 0;
}
} }
} }
} }

View File

@ -1,9 +1,4 @@
using System; using BizHawk.Common;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {

View File

@ -140,7 +140,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// reset sprites // reset sprites
for (var i = 0; i < 8; i++) for (var i = 0; i < 8; i++)
{
_sprites[i].HardReset(); _sprites[i].HardReset();
}
// clear C buffer // clear C buffer
for (var i = 0; i < 40; i++) for (var i = 0; i < 40; i++)

View File

@ -17,7 +17,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private const int LastDmaLine = 0x0F7; private const int LastDmaLine = 0x0F7;
// The special actions taken by the Vic are in the same order and interval on all chips, just different offsets. // The special actions taken by the Vic are in the same order and interval on all chips, just different offsets.
private static readonly int[] TimingBuilderCycle14Act = { private static readonly int[] TimingBuilderCycle14Act =
{
PipelineUpdateVc, 0, PipelineUpdateVc, 0,
PipelineSpriteCrunch, 0, PipelineSpriteCrunch, 0,
PipelineUpdateMcBase, 0, PipelineUpdateMcBase, 0,

View File

@ -1,6 +1,4 @@
using System.Drawing; using BizHawk.Common;
using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
@ -25,38 +23,29 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// palette // palette
private static readonly int[] Palette = private static readonly int[] Palette =
{ {
Colors.ARGB(0x00, 0x00, 0x00), Colors.ARGB(0x00, 0x00, 0x00),
Colors.ARGB(0xFF, 0xFF, 0xFF), Colors.ARGB(0xFF, 0xFF, 0xFF),
Colors.ARGB(0x68, 0x37, 0x2B), Colors.ARGB(0x68, 0x37, 0x2B),
Colors.ARGB(0x70, 0xA4, 0xB2), Colors.ARGB(0x70, 0xA4, 0xB2),
Colors.ARGB(0x6F, 0x3D, 0x86), Colors.ARGB(0x6F, 0x3D, 0x86),
Colors.ARGB(0x58, 0x8D, 0x43), Colors.ARGB(0x58, 0x8D, 0x43),
Colors.ARGB(0x35, 0x28, 0x79), Colors.ARGB(0x35, 0x28, 0x79),
Colors.ARGB(0xB8, 0xC7, 0x6F), Colors.ARGB(0xB8, 0xC7, 0x6F),
Colors.ARGB(0x6F, 0x4F, 0x25), Colors.ARGB(0x6F, 0x4F, 0x25),
Colors.ARGB(0x43, 0x39, 0x00), Colors.ARGB(0x43, 0x39, 0x00),
Colors.ARGB(0x9A, 0x67, 0x59), Colors.ARGB(0x9A, 0x67, 0x59),
Colors.ARGB(0x44, 0x44, 0x44), Colors.ARGB(0x44, 0x44, 0x44),
Colors.ARGB(0x6C, 0x6C, 0x6C), Colors.ARGB(0x6C, 0x6C, 0x6C),
Colors.ARGB(0x9A, 0xD2, 0x84), Colors.ARGB(0x9A, 0xD2, 0x84),
Colors.ARGB(0x6C, 0x5E, 0xB5), Colors.ARGB(0x6C, 0x5E, 0xB5),
Colors.ARGB(0x95, 0x95, 0x95) Colors.ARGB(0x95, 0x95, 0x95)
}; };
public int BackgroundColor public int BackgroundColor => BgColor;
{
get { return BgColor; }
}
public int BufferHeight public int BufferHeight => _bufHeight;
{
get { return _bufHeight; }
}
public int BufferWidth public int BufferWidth => _bufWidth;
{
get { return _bufWidth; }
}
public int[] GetVideoBuffer() public int[] GetVideoBuffer()
{ {

View File

@ -1,27 +1,25 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing;
using System.Linq; using System.Linq;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
public sealed partial class Vic public sealed partial class Vic
{ {
/* /*
Commodore VIC-II 6567/6569/6572 core. Commodore VIC-II 6567/6569/6572 core.
Many thanks to: Many thanks to:
- Christian Bauer for the VIC-II document. - Christian Bauer for the VIC-II document.
http://www.zimmers.net/cbmpics/cbm/c64/vic-ii.txt http://www.zimmers.net/cbmpics/cbm/c64/vic-ii.txt
- VICE team for the addendum to the above document. - VICE team for the addendum to the above document.
http://vice-emu.sourceforge.net/plain/VIC-Addendum.txt http://vice-emu.sourceforge.net/plain/VIC-Addendum.txt
- Whoever scanned the CSG 6567 preliminary datasheet. - Whoever scanned the CSG 6567 preliminary datasheet.
http://www.classiccmp.org/cini/pdf/Commodore/ds_6567.pdf http://www.classiccmp.org/cini/pdf/Commodore/ds_6567.pdf
- Michael Huth for die shots of the 6569R3 chip (to get ideas how to implement) - Michael Huth for die shots of the 6569R3 chip (to get ideas how to implement)
http://mail.lipsia.de/~enigma/neu/6581.html http://mail.lipsia.de/~enigma/neu/6581.html
*/ */
public Func<int, int> ReadColorRam; public Func<int, int> ReadColorRam;
public Func<int, int> ReadMemory; public Func<int, int> ReadMemory;
@ -42,8 +40,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private int _hblankStartCheckXRaster; private int _hblankStartCheckXRaster;
private int _hblankEndCheckXRaster; private int _hblankEndCheckXRaster;
private int _pixelRatioNum; private readonly int _pixelRatioNum;
private int _pixelRatioDen; private readonly int _pixelRatioDen;
public Vic(int newCycles, int newLines, IList<int[]> newPipeline, int newCyclesPerSec, int hblankStart, int hblankEnd, int vblankStart, int vblankEnd, C64.BorderType borderType, int pixelRatioNum, int pixelRatioDen) public Vic(int newCycles, int newLines, IList<int[]> newPipeline, int newCyclesPerSec, int hblankStart, int hblankEnd, int vblankStart, int vblankEnd, C64.BorderType borderType, int pixelRatioNum, int pixelRatioDen)
{ {
@ -69,7 +67,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_sprites = new Sprite[8]; _sprites = new Sprite[8];
for (var i = 0; i < 8; i++) for (var i = 0; i < 8; i++)
{
_sprites[i] = new Sprite(); _sprites[i] = new Sprite();
}
_sprite0 = _sprites[0]; _sprite0 = _sprites[0];
_sprite1 = _sprites[1]; _sprite1 = _sprites[1];
_sprite2 = _sprites[2]; _sprite2 = _sprites[2];
@ -161,28 +162,18 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
val -= width; val -= width;
} }
while (val < min) while (val < min)
{ {
val += width; val += width;
} }
return val; return val;
} }
public int CyclesPerFrame public int CyclesPerFrame => _totalCycles * _totalLines;
{
get
{
return _totalCycles * _totalLines;
}
}
public int CyclesPerSecond public int CyclesPerSecond => _cyclesPerSec;
{
get
{
return _cyclesPerSec;
}
}
public void ExecutePhase() public void ExecutePhase()
{ {
@ -194,9 +185,14 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{ {
// border check // border check
if (_rasterLine == _borderB) if (_rasterLine == _borderB)
{
_borderOnVertical = true; _borderOnVertical = true;
}
if (_rasterLine == _borderT && _displayEnable) if (_rasterLine == _borderT && _displayEnable)
{
_borderOnVertical = false; _borderOnVertical = false;
}
// vblank check // vblank check
if (_rasterLine == _vblankStart) if (_rasterLine == _vblankStart)
@ -262,7 +258,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
if (!_rasterInterruptTriggered) if (!_rasterInterruptTriggered)
{ {
_rasterInterruptTriggered = true; _rasterInterruptTriggered = true;
_intRaster = true;
// interrupt needs to be enabled to be set to true
if (_enableIntRaster)
{
_intRaster = true;
}
} }
} }
@ -278,7 +279,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// display enable compare // display enable compare
if (_rasterLine == FirstDmaLine) if (_rasterLine == FirstDmaLine)
{
_badlineEnable |= _displayEnable; _badlineEnable |= _displayEnable;
}
// badline compare // badline compare
if (_badlineEnable) if (_badlineEnable)
@ -346,26 +349,31 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_videoMode = VideoMode000; _videoMode = VideoMode000;
return; return;
} }
if (!_extraColorMode && !_bitmapMode && _multicolorMode) if (!_extraColorMode && !_bitmapMode && _multicolorMode)
{ {
_videoMode = VideoMode001; _videoMode = VideoMode001;
return; return;
} }
if (!_extraColorMode && _bitmapMode && !_multicolorMode) if (!_extraColorMode && _bitmapMode && !_multicolorMode)
{ {
_videoMode = VideoMode010; _videoMode = VideoMode010;
return; return;
} }
if (!_extraColorMode && _bitmapMode && _multicolorMode) if (!_extraColorMode && _bitmapMode && _multicolorMode)
{ {
_videoMode = VideoMode011; _videoMode = VideoMode011;
return; return;
} }
if (_extraColorMode && !_bitmapMode && !_multicolorMode) if (_extraColorMode && !_bitmapMode && !_multicolorMode)
{ {
_videoMode = VideoMode100; _videoMode = VideoMode100;
return; return;
} }
_videoMode = VideoModeInvalid; _videoMode = VideoModeInvalid;
} }
} }

View File

@ -20,10 +20,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
private static readonly int[] GcrDecodeTable = private static readonly int[] GcrDecodeTable =
{ {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //00xxx 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 00xxx
0xFF, 0x08, 0x00, 0x01, 0xFF, 0x0C, 0x04, 0x05, //01xxx 0xFF, 0x08, 0x00, 0x01, 0xFF, 0x0C, 0x04, 0x05, // 01xxx
0xFF, 0xFF, 0x02, 0x03, 0xFF, 0x0F, 0x06, 0x07, //10xxx 0xFF, 0xFF, 0x02, 0x03, 0xFF, 0x0F, 0x06, 0x07, // 10xxx
0xFF, 0x09, 0x0A, 0x0B, 0xFF, 0x0D, 0x0E, 0xFF //11xxx 0xFF, 0x09, 0x0A, 0x0B, 0xFF, 0x0D, 0x0E, 0xFF // 11xxx
}; };
private static readonly int[] GcrEncodeTable = private static readonly int[] GcrEncodeTable =
@ -69,7 +69,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
byte result = 0; byte result = 0;
for (var i = 0; i < count; i++) for (var i = 0; i < count; i++)
{
result ^= source[i]; result ^= source[i];
}
return result; return result;
} }

View File

@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
public const int FluxBitsPerEntry = 32; public const int FluxBitsPerEntry = 32;
public const int FluxBitsPerTrack = 16000000 / 5; public const int FluxBitsPerTrack = 16000000 / 5;
public const int FluxEntriesPerTrack = FluxBitsPerTrack / FluxBitsPerEntry; public const int FluxEntriesPerTrack = FluxBitsPerTrack / FluxBitsPerEntry;
private int[][] _tracks; private readonly int[][] _tracks;
private readonly int[] _originalMedia; private readonly int[] _originalMedia;
public bool Valid; public bool Valid;
public bool WriteProtected; public bool WriteProtected;
@ -33,7 +33,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
/// <param name="trackData">Raw bit data.</param> /// <param name="trackData">Raw bit data.</param>
/// <param name="trackNumbers">Track numbers for the raw bit data.</param> /// <param name="trackNumbers">Track numbers for the raw bit data.</param>
/// <param name="trackDensities">Density zones for the raw bit data.</param> /// <param name="trackDensities">Density zones for the raw bit data.</param>
/// <param name="trackLengths">Length, in bits, of each raw bit data.</param>
/// <param name="trackCapacity">Total number of tracks on the media.</param> /// <param name="trackCapacity">Total number of tracks on the media.</param>
public Disk(IList<byte[]> trackData, IList<int> trackNumbers, IList<int> trackDensities, int trackCapacity) public Disk(IList<byte[]> trackData, IList<int> trackNumbers, IList<int> trackDensities, int trackCapacity)
{ {
@ -43,6 +42,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
{ {
_tracks[trackNumbers[i]] = ConvertToFluxTransitions(trackDensities[i], trackData[i], 0); _tracks[trackNumbers[i]] = ConvertToFluxTransitions(trackDensities[i], trackData[i], 0);
} }
FillMissingTracks(); FillMissingTracks();
Valid = true; Valid = true;
_originalMedia = SerializeTracks(_tracks); _originalMedia = SerializeTracks(_tracks);
@ -95,10 +95,15 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
byteData <<= 1; byteData <<= 1;
remainingBits--; remainingBits--;
if (remainingBits <= 0) if (remainingBits <= 0)
{
break; break;
}
} }
if (remainingBits <= 0) if (remainingBits <= 0)
{
break; break;
}
} }
return result; return result;

View File

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Linq.Expressions;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
@ -21,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
protected class BamEntry protected class BamEntry
{ {
public int Data { get; private set; } public int Data { get; private set; }
public int Sectors { get; private set; } public int Sectors { get; }
public BamEntry(int sectors) public BamEntry(int sectors)
{ {
@ -31,6 +29,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
Data >>= 1; Data >>= 1;
Data |= 0x800000; Data |= 0x800000;
} }
Data |= (sectors << 24); Data |= (sectors << 24);
Sectors = sectors; Sectors = sectors;
} }
@ -64,20 +63,25 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
} }
} }
public int SectorsRemaining public int SectorsRemaining => (Data >> 24) & 0xFF;
{
get { return (Data >> 24) & 0xFF; }
}
public bool this[int sector] public bool this[int sector]
{ {
get { return (Data & (1 << sector)) != 0; } get
{
return (Data & (1 << sector)) != 0;
}
set set
{ {
if (value) if (value)
{
Free(sector); Free(sector);
}
else else
{
Allocate(sector); Allocate(sector);
}
} }
} }
@ -241,14 +245,18 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
} }
if (dataRemaining <= 0) if (dataRemaining <= 0)
{
break; break;
}
bytes[outputOffset + 0] = (byte)(currentTrack + 1); bytes[outputOffset + 0] = (byte)(currentTrack + 1);
bytes[outputOffset + 1] = (byte)currentSector; bytes[outputOffset + 1] = (byte)currentSector;
} }
if (diskFull) if (diskFull)
{
break; break;
}
} }
// write Directory // write Directory
@ -276,8 +284,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
bytes[directoryOutputOffset + directoryOffset + 0x03] = (byte)(entry.Track + 1); bytes[directoryOutputOffset + directoryOffset + 0x03] = (byte)(entry.Track + 1);
bytes[directoryOutputOffset + directoryOffset + 0x04] = (byte)entry.Sector; bytes[directoryOutputOffset + directoryOffset + 0x04] = (byte)entry.Sector;
for (var i = 0x05; i <= 0x14; i++) for (var i = 0x05; i <= 0x14; i++)
{
bytes[directoryOutputOffset + directoryOffset + i] = 0xA0; bytes[directoryOutputOffset + directoryOffset + i] = 0xA0;
var fileNameBytes = Encoding.ASCII.GetBytes(entry.Entry.Name ?? string.Format("FILE{0:D3}", fileIndex)); }
var fileNameBytes = Encoding.ASCII.GetBytes(entry.Entry.Name ?? $"FILE{fileIndex:D3}");
Array.Copy(fileNameBytes, 0, bytes, directoryOutputOffset + directoryOffset + 0x05, Math.Min(fileNameBytes.Length, 0x10)); Array.Copy(fileNameBytes, 0, bytes, directoryOutputOffset + directoryOffset + 0x05, Math.Min(fileNameBytes.Length, 0x10));
bytes[directoryOutputOffset + directoryOffset + 0x1E] = (byte)(entry.LengthInSectors & 0xFF); bytes[directoryOutputOffset + directoryOffset + 0x1E] = (byte)(entry.LengthInSectors & 0xFF);
bytes[directoryOutputOffset + directoryOffset + 0x1F] = (byte)((entry.LengthInSectors >> 8) & 0xFF); bytes[directoryOutputOffset + directoryOffset + 0x1F] = (byte)((entry.LengthInSectors >> 8) & 0xFF);
@ -295,10 +306,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
{ {
Array.Copy(bam[i].GetBytes(), 0, bytes, bamOutputOffset + 4 + (i * 4), 4); Array.Copy(bam[i].GetBytes(), 0, bytes, bamOutputOffset + 4 + (i * 4), 4);
} }
for (var i = 0x90; i <= 0xAA; i++) for (var i = 0x90; i <= 0xAA; i++)
{ {
bytes[bamOutputOffset + i] = 0xA0; bytes[bamOutputOffset + i] = 0xA0;
} }
var titleBytes = Encoding.ASCII.GetBytes(Title ?? "UNTITLED"); var titleBytes = Encoding.ASCII.GetBytes(Title ?? "UNTITLED");
Array.Copy(titleBytes, 0, bytes, bamOutputOffset + 0x90, Math.Min(titleBytes.Length, 0x10)); Array.Copy(titleBytes, 0, bytes, bamOutputOffset + 0x90, Math.Min(titleBytes.Length, 0x10));

View File

@ -20,19 +20,22 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
if (id == @"GCR-1541") if (id == @"GCR-1541")
{ {
reader.ReadByte(); // version
reader.ReadByte(); //version
int trackCount = reader.ReadByte(); int trackCount = reader.ReadByte();
reader.ReadInt16(); //max track size in bytes reader.ReadInt16(); // max track size in bytes
var trackOffsetTable = new int[trackCount]; var trackOffsetTable = new int[trackCount];
var trackSpeedTable = new int[trackCount]; var trackSpeedTable = new int[trackCount];
for (var i = 0; i < trackCount; i++) for (var i = 0; i < trackCount; i++)
{
trackOffsetTable[i] = reader.ReadInt32(); trackOffsetTable[i] = reader.ReadInt32();
}
for (var i = 0; i < trackCount; i++) for (var i = 0; i < trackCount; i++)
{
trackSpeedTable[i] = reader.ReadInt32(); trackSpeedTable[i] = reader.ReadInt32();
}
for (var i = 0; i < trackCount; i++) for (var i = 0; i < trackCount; i++)
{ {

View File

@ -83,14 +83,20 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
if (Encoding.ASCII.GetString(tapeFile, 0, 12) == "C64-TAPE-RAW") if (Encoding.ASCII.GetString(tapeFile, 0, 12) == "C64-TAPE-RAW")
{ {
var version = tapeFile[12]; var version = tapeFile[12];
if (version > 1) throw new Exception("This tape has an unsupported version"); if (version > 1)
{
throw new Exception("This tape has an unsupported version");
}
var size = BitConverter.ToUInt32(tapeFile, 16); var size = BitConverter.ToUInt32(tapeFile, 16);
if (size + 20 != tapeFile.Length) if (size + 20 != tapeFile.Length)
{ {
throw new Exception("Tape file header specifies a length that doesn't match the file size"); throw new Exception("Tape file header specifies a length that doesn't match the file size");
} }
result = new Tape(version, tapeFile, 20, tapeFile.Length); result = new Tape(version, tapeFile, 20, tapeFile.Length);
} }
return result; return result;
} }

View File

@ -15,6 +15,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
delta[i] = source[i] ^ data[i]; delta[i] = source[i] ^ data[i];
} }
return delta; return delta;
} }
@ -25,6 +26,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
delta = GetDelta(source, data); delta = GetDelta(source, data);
} }
ser.Sync(name, ref delta, false); ser.Sync(name, ref delta, false);
if (ser.IsReader && delta != null) if (ser.IsReader && delta != null)
{ {

View File

@ -24,7 +24,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
private void AdvanceRng() private void AdvanceRng()
{ {
if (_rngCurrent == 0) if (_rngCurrent == 0)
{
_rngCurrent = 1; _rngCurrent = 1;
}
_rngCurrent = (int)(_rngCurrent * LEHMER_RNG_PRIME % int.MaxValue); _rngCurrent = (int)(_rngCurrent * LEHMER_RNG_PRIME % int.MaxValue);
} }
@ -52,15 +55,18 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
{ {
_diskByteOffset = 0; _diskByteOffset = 0;
} }
_diskBits = _trackImageData[_diskByteOffset]; _diskBits = _trackImageData[_diskByteOffset];
_diskBitsLeft = Disk.FluxBitsPerEntry; _diskBitsLeft = Disk.FluxBitsPerEntry;
} }
} }
if ((_diskBits & 1) != 0) if ((_diskBits & 1) != 0)
{ {
_countsBeforeRandomTransition = 0; _countsBeforeRandomTransition = 0;
_diskFluxReversalDetected = true; _diskFluxReversalDetected = true;
} }
_diskBits >>= 1; _diskBits >>= 1;
_diskBitsLeft--; _diskBitsLeft--;
} }
@ -73,6 +79,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
{ {
_diskFluxReversalDetected = true; _diskFluxReversalDetected = true;
AdvanceRng(); AdvanceRng();
// This constant is what VICE uses. TODO: Determine accuracy. // This constant is what VICE uses. TODO: Determine accuracy.
_countsBeforeRandomTransition = (_rngCurrent % 367) + 33; _countsBeforeRandomTransition = (_rngCurrent % 367) + 33;
} }
@ -87,6 +94,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
if (_countsBeforeRandomTransition == 0) if (_countsBeforeRandomTransition == 0)
{ {
AdvanceRng(); AdvanceRng();
// This constant is what VICE uses. TODO: Determine accuracy. // This constant is what VICE uses. TODO: Determine accuracy.
_countsBeforeRandomTransition = (_rngCurrent & 0x1F) + 289; _countsBeforeRandomTransition = (_rngCurrent & 0x1F) + 289;
} }

View File

@ -11,19 +11,19 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
{ {
return new Dictionary<string, RegisterValue> return new Dictionary<string, RegisterValue>
{ {
{ "A", _cpu.A }, ["A"] = _cpu.A,
{ "X", _cpu.X }, ["X"] = _cpu.X,
{ "Y", _cpu.Y }, ["Y"] = _cpu.Y,
{ "S", _cpu.S }, ["S"] = _cpu.S,
{ "PC", _cpu.PC }, ["PC"] = _cpu.PC,
{ "Flag C", _cpu.FlagC }, ["Flag C"] = _cpu.FlagC,
{ "Flag Z", _cpu.FlagZ }, ["Flag Z"] = _cpu.FlagZ,
{ "Flag I", _cpu.FlagI }, ["Flag I"] = _cpu.FlagI,
{ "Flag D", _cpu.FlagD }, ["Flag D"] = _cpu.FlagD,
{ "Flag B", _cpu.FlagB }, ["Flag B"] = _cpu.FlagB,
{ "Flag V", _cpu.FlagV }, ["Flag V"] = _cpu.FlagV,
{ "Flag N", _cpu.FlagN }, ["Flag N"] = _cpu.FlagN,
{ "Flag T", _cpu.FlagT } ["Flag T"] = _cpu.FlagT
}; };
} }
@ -64,7 +64,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
} }
} }
void IDebuggable.Step(StepType type) void IDebuggable.Step(StepType type)
{ {
switch (type) switch (type)
@ -81,10 +80,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
} }
} }
int IDebuggable.TotalExecutedCycles int IDebuggable.TotalExecutedCycles => _cpu.TotalExecutedCycles;
{
get { return _cpu.TotalExecutedCycles; }
}
private void StepInto() private void StepInto()
{ {
@ -92,6 +88,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
{ {
DebuggerStep(); DebuggerStep();
} }
while (!_cpu.AtInstructionStart()) while (!_cpu.AtInstructionStart())
{ {
DebuggerStep(); DebuggerStep();

View File

@ -12,16 +12,17 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
string IDisassemblable.Cpu string IDisassemblable.Cpu
{ {
get { return "Disk Drive 6502"; } get
{
return "Disk Drive 6502";
}
set set
{ {
} }
} }
string IDisassemblable.PCRegisterName string IDisassemblable.PCRegisterName => "PC";
{
get { return "PC"; }
}
string IDisassemblable.Disassemble(MemoryDomain m, uint addr, out int length) string IDisassemblable.Disassemble(MemoryDomain m, uint addr, out int length)
{ {

View File

@ -17,14 +17,22 @@
if (_tempStep != _motorStep) if (_tempStep != _motorStep)
{ {
if (_tempStep == ((_motorStep - 1) & 0x3)) if (_tempStep == ((_motorStep - 1) & 0x3))
{
_trackNumber--; _trackNumber--;
}
else if (_tempStep == ((_motorStep + 1) & 0x3)) else if (_tempStep == ((_motorStep + 1) & 0x3))
{
_trackNumber++; _trackNumber++;
}
if (_trackNumber < 0) if (_trackNumber < 0)
{
_trackNumber = 0; _trackNumber = 0;
}
else if (_trackNumber > 83) else if (_trackNumber > 83)
{
_trackNumber = 83; _trackNumber = 83;
}
_motorStep = _tempStep; _motorStep = _tempStep;
UpdateMediaData(); UpdateMediaData();

View File

@ -58,10 +58,17 @@
case 0x1C00: case 0x1C00:
return Via1.Peek(addr); return Via1.Peek(addr);
} }
if ((addr & 0x8000) != 0) if ((addr & 0x8000) != 0)
{
return DriveRom.Peek(addr & 0x3FFF); return DriveRom.Peek(addr & 0x3FFF);
}
if ((addr & 0x1F00) < 0x800) if ((addr & 0x1F00) < 0x800)
{
return _ram[addr & 0x7FF]; return _ram[addr & 0x7FF];
}
return (addr >> 8) & 0xFF; return (addr >> 8) & 0xFF;
} }
@ -87,7 +94,10 @@
break; break;
default: default:
if ((addr & 0x8000) == 0 && (addr & 0x1F00) < 0x800) if ((addr & 0x8000) == 0 && (addr & 0x1F00) < 0x800)
{
_ram[addr & 0x7FF] = val & 0xFF; _ram[addr & 0x7FF] = val & 0xFF;
}
break; break;
} }
} }
@ -111,10 +121,17 @@
case 0x1C00: case 0x1C00:
return Via1.Read(addr); return Via1.Read(addr);
} }
if ((addr & 0x8000) != 0) if ((addr & 0x8000) != 0)
{
return DriveRom.Read(addr & 0x3FFF); return DriveRom.Read(addr & 0x3FFF);
}
if ((addr & 0x1F00) < 0x800) if ((addr & 0x1F00) < 0x800)
{
return _ram[addr & 0x7FF]; return _ram[addr & 0x7FF];
}
return (addr >> 8) & 0xFF; return (addr >> 8) & 0xFF;
} }
@ -130,7 +147,10 @@
break; break;
default: default:
if ((addr & 0x8000) == 0 && (addr & 0x1F00) < 0x800) if ((addr & 0x8000) == 0 && (addr & 0x1F00) < 0x800)
{
_ram[addr & 0x7FF] = val & 0xFF; _ram[addr & 0x7FF] = val & 0xFF;
}
break; break;
} }
} }

View File

@ -1,11 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Components.M6502; using BizHawk.Emulation.Cores.Components.M6502;
using BizHawk.Emulation.Cores.Computers.Commodore64.Media; using BizHawk.Emulation.Cores.Computers.Commodore64.Media;
using BizHawk.Emulation.Cores.Computers.Commodore64.MOS; using BizHawk.Emulation.Cores.Computers.Commodore64.MOS;
@ -115,6 +110,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
_ratioDifference -= _cpuClockNum; _ratioDifference -= _cpuClockNum;
_clocks++; _clocks++;
} }
ExecutePhaseInternal(); ExecutePhaseInternal();
} }
@ -136,6 +132,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
{ {
_cpu.SetOverflow(); _cpu.SetOverflow();
} }
_overflowFlagDelaySr >>= 1; _overflowFlagDelaySr >>= 1;
_cpu.IRQ = !(Via0.Irq && Via1.Irq); // active low IRQ line _cpu.IRQ = !(Via0.Irq && Via1.Irq); // active low IRQ line

View File

@ -74,8 +74,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
_device.ReadMasterData = () => ReadMasterData(); _device.ReadMasterData = () => ReadMasterData();
} }
public bool DriveLightEnabled { get { return true; } } public bool DriveLightEnabled => true;
public bool DriveLightOn { get { return ReadDeviceLight(); } } public bool DriveLightOn => ReadDeviceLight();
public bool IsConnected { get { return _connected; } } public bool IsConnected => _connected;
} }
} }

View File

@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
{ {
public ColecoSettings GetSettings() public ColecoSettings GetSettings()
{ {
return Settings.Clone(); return _settings.Clone();
} }
public ColecoSyncSettings GetSyncSettings() public ColecoSyncSettings GetSyncSettings()
@ -20,7 +20,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
public bool PutSettings(ColecoSettings o) public bool PutSettings(ColecoSettings o)
{ {
Settings = o; _settings = o;
return false; return false;
} }
@ -40,8 +40,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision
} }
} }
public ColecoSettings Settings = new ColecoSettings(); private ColecoSettings _settings = new ColecoSettings();
public ColecoSyncSettings _syncSettings = new ColecoSyncSettings(); private ColecoSyncSettings _syncSettings = new ColecoSyncSettings();
public class ColecoSyncSettings public class ColecoSyncSettings
{ {
@ -53,7 +53,11 @@ namespace BizHawk.Emulation.Cores.ColecoVision
[JsonIgnore] [JsonIgnore]
public string Port1 public string Port1
{ {
get { return _port1; } get
{
return _port1;
}
set set
{ {
if (!ColecoVisionControllerDeck.ValidControllerTypes.ContainsKey(value)) if (!ColecoVisionControllerDeck.ValidControllerTypes.ContainsKey(value))
@ -68,7 +72,11 @@ namespace BizHawk.Emulation.Cores.ColecoVision
[JsonIgnore] [JsonIgnore]
public string Port2 public string Port2
{ {
get { return _port2; } get
{
return _port2;
}
set set
{ {
if (!ColecoVisionControllerDeck.ValidControllerTypes.ContainsKey(value)) if (!ColecoVisionControllerDeck.ValidControllerTypes.ContainsKey(value))

View File

@ -26,6 +26,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
_chrBankMask_8k = Cart.chr_size / 8 - 1; _chrBankMask_8k = Cart.chr_size / 8 - 1;
_prgBankMask_32k = Cart.prg_size / 32 - 1; _prgBankMask_32k = Cart.prg_size / 32 - 1;
SetMirrorType(Cart.pad_h, Cart.pad_v);
return true; return true;
} }

View File

@ -501,42 +501,58 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
byte[] nesheader = new byte[16]; byte[] nesheader = new byte[16];
Buffer.BlockCopy(file, 0, nesheader, 0, 16); Buffer.BlockCopy(file, 0, nesheader, 0, 16);
bool exists = true;
if (!DetectFromINES(nesheader, out iNesHeaderInfo, out iNesHeaderInfoV2)) if (!DetectFromINES(nesheader, out iNesHeaderInfo, out iNesHeaderInfoV2))
throw new InvalidOperationException("iNES header not found");
//now that we know we have an iNES header, we can try to ignore it.
hash_sha1 = "sha1:" + file.HashSHA1(16, file.Length - 16);
hash_sha1_several.Add(hash_sha1);
hash_md5 = "md5:" + file.HashMD5(16, file.Length - 16);
LoadWriteLine("Found iNES header:");
LoadWriteLine(iNesHeaderInfo.ToString());
if (iNesHeaderInfoV2 != null)
{ {
LoadWriteLine("Found iNES V2 header:"); // we don't have an ines header, check if the game hash is in the game db
LoadWriteLine(iNesHeaderInfoV2); exists = false;
Console.WriteLine("headerless ROM, using Game DB");
hash_md5 = "md5:" + file.HashMD5(0, file.Length);
hash_sha1 = "sha1:" + file.HashSHA1(0, file.Length);
if (hash_md5 != null) choice = IdentifyFromGameDB(hash_md5);
if (choice == null)
choice = IdentifyFromGameDB(hash_sha1);
if (choice == null)
throw new InvalidOperationException("iNES header not found and no gamedb entry");
} }
LoadWriteLine("Since this is iNES we can (somewhat) confidently parse PRG/CHR banks to hash.");
LoadWriteLine("headerless rom hash: {0}", hash_sha1); if (exists)
LoadWriteLine("headerless rom hash: {0}", hash_md5);
if (iNesHeaderInfo.prg_size == 16)
{ {
//8KB prg can't be stored in iNES format, which counts 16KB prg banks. //now that we know we have an iNES header, we can try to ignore it.
//so a correct hash will include only 8KB.
LoadWriteLine("Since this rom has a 16 KB PRG, we'll hash it as 8KB too for bootgod's DB:"); hash_sha1 = "sha1:" + file.HashSHA1(16, file.Length - 16);
var msTemp = new MemoryStream(); hash_sha1_several.Add(hash_sha1);
msTemp.Write(file, 16, 8 * 1024); //add prg hash_md5 = "md5:" + file.HashMD5(16, file.Length - 16);
msTemp.Write(file, 16 + 16 * 1024, iNesHeaderInfo.chr_size * 1024); //add chr
msTemp.Flush(); LoadWriteLine("Found iNES header:");
var bytes = msTemp.ToArray(); LoadWriteLine(iNesHeaderInfo.ToString());
var hash = "sha1:" + bytes.HashSHA1(0, bytes.Length); if (iNesHeaderInfoV2 != null)
LoadWriteLine(" PRG (8KB) + CHR hash: {0}", hash); {
hash_sha1_several.Add(hash); LoadWriteLine("Found iNES V2 header:");
hash = "md5:" + bytes.HashMD5(0, bytes.Length); LoadWriteLine(iNesHeaderInfoV2);
LoadWriteLine(" PRG (8KB) + CHR hash: {0}", hash); }
LoadWriteLine("Since this is iNES we can (somewhat) confidently parse PRG/CHR banks to hash.");
LoadWriteLine("headerless rom hash: {0}", hash_sha1);
LoadWriteLine("headerless rom hash: {0}", hash_md5);
if (iNesHeaderInfo.prg_size == 16)
{
//8KB prg can't be stored in iNES format, which counts 16KB prg banks.
//so a correct hash will include only 8KB.
LoadWriteLine("Since this rom has a 16 KB PRG, we'll hash it as 8KB too for bootgod's DB:");
var msTemp = new MemoryStream();
msTemp.Write(file, 16, 8 * 1024); //add prg
msTemp.Write(file, 16 + 16 * 1024, iNesHeaderInfo.chr_size * 1024); //add chr
msTemp.Flush();
var bytes = msTemp.ToArray();
var hash = "sha1:" + bytes.HashSHA1(0, bytes.Length);
LoadWriteLine(" PRG (8KB) + CHR hash: {0}", hash);
hash_sha1_several.Add(hash);
hash = "md5:" + bytes.HashMD5(0, bytes.Length);
LoadWriteLine(" PRG (8KB) + CHR hash: {0}", hash);
}
} }
} }
@ -727,11 +743,29 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
if (choice.prg_size != iNesHeaderInfo.prg_size || choice.chr_size != iNesHeaderInfo.chr_size) if (choice.prg_size != iNesHeaderInfo.prg_size || choice.chr_size != iNesHeaderInfo.chr_size)
LoadWriteLine("Warning: Detected choice has different filesizes than the INES header!"); LoadWriteLine("Warning: Detected choice has different filesizes than the INES header!");
} }
else else if (unif != null)
{ {
Board.ROM = unif.PRG; Board.ROM = unif.PRG;
Board.VROM = unif.CHR; Board.VROM = unif.CHR;
} }
else
{
// we should only get here for boards with no header
var ms = new MemoryStream(file, false);
ms.Seek(0, SeekOrigin.Begin);
Board.ROM = new byte[choice.prg_size * 1024];
ms.Read(Board.ROM, 0, Board.ROM.Length);
if (choice.chr_size > 0)
{
Board.VROM = new byte[choice.chr_size * 1024];
int vrom_copy_size = ms.Read(Board.VROM, 0, Board.VROM.Length);
if (vrom_copy_size < Board.VROM.Length)
LoadWriteLine("Less than the expected VROM was found in the file: {0} < {1}", vrom_copy_size, Board.VROM.Length);
}
}
LoadReport.Flush(); LoadReport.Flush();
CoreComm.RomStatusDetails = LoadReport.ToString(); CoreComm.RomStatusDetails = LoadReport.ToString();

View File

@ -28,6 +28,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1126/@EntryIndexedValue">DO_NOT_SHOW</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1126/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1200/@EntryIndexedValue">DO_NOT_SHOW</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1200/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1204/@EntryIndexedValue">DO_NOT_SHOW</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1204/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1215/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1309/@EntryIndexedValue">DO_NOT_SHOW</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1309/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1402/@EntryIndexedValue">DO_NOT_SHOW</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1402/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1502/@EntryIndexedValue">DO_NOT_SHOW</s:String> <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1502/@EntryIndexedValue">DO_NOT_SHOW</s:String>