C64 - misc cleanups

This commit is contained in:
adelikat 2017-05-30 13:09:46 -04:00
parent 11be8b18c1
commit 1877cce021
72 changed files with 582 additions and 520 deletions

View File

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

View File

@ -31,8 +31,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
SetDefaultDisassemblable();
}
return _selectedDisassemblable.Cpu;
}
set
{
var currentSelectedDisassemblable = _selectedDisassemblable;
@ -52,6 +54,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
SetDefaultDisassemblable();
}
return _selectedDisassemblable.PCRegisterName;
}
}
@ -67,6 +70,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
SetDefaultDisassemblable();
}
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 bool DriveLightEnabled { get { return _board != null && (_board.CartPort.DriveLightEnabled || _board.Serial.DriveLightEnabled); } }
public bool DriveLightOn { get { return _board != null && (_board.CartPort.DriveLightOn || _board.Serial.DriveLightOn); } }
public bool DriveLightEnabled => _board != null && (_board.CartPort.DriveLightEnabled || _board.Serial.DriveLightEnabled);
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 IEmulatorServiceProvider ServiceProvider { get; private set; }
public IEmulatorServiceProvider ServiceProvider { get; }
public ControllerDefinition ControllerDefinition => C64ControllerDefinition;
@ -12,7 +12,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
_board.Controller = controller;
if (_tracer.Enabled)
{
_board.Cpu.TraceCallback = s => _tracer.Put(s);
@ -52,7 +51,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
public int Frame => _frame;
public string SystemId { get { return "C64"; } }
public string SystemId => "C64";
public bool DeterministicEmulation => true;
@ -64,20 +63,14 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
_frameCycles = 0;
}
public CoreComm CoreComm { get; private set; }
public CoreComm CoreComm { get; }
public void Dispose()
{
if (_board != null)
{
if (_board.TapeDrive != null)
{
_board.TapeDrive.RemoveMedia();
}
if (_board.DiskDrive != null)
{
_board.DiskDrive.RemoveMedia();
}
_board.TapeDrive?.RemoveMedia();
_board.DiskDrive?.RemoveMedia();
_board = null;
}
}

View File

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

View File

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

View File

@ -5,12 +5,14 @@
private bool[] _joystickPressed = new bool[10];
private bool[] _keyboardPressed = new bool[64];
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"}
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" }
};
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 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" },

View File

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

View File

@ -18,7 +18,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
public C64(CoreComm comm, IEnumerable<byte[]> roms, GameInfo game, object settings, object syncSettings)
{
PutSyncSettings((C64SyncSettings)syncSettings ?? new C64SyncSettings());
PutSettings((C64Settings)settings ?? new C64Settings());
@ -27,12 +26,12 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
InputCallbacks = new InputCallbackSystem();
CoreComm = comm;
Roms = roms?.ToList() ?? new List<byte[]>();
_roms = roms?.ToList() ?? new List<byte[]>();
_currentDisk = 0;
RomSanityCheck();
Init(SyncSettings.VicType, Settings.BorderType, SyncSettings.SidType, SyncSettings.TapeDriveType, SyncSettings.DiskDriveType);
_cyclesPerFrame = _board.Vic.CyclesPerFrame;
_cyclesPerFrame = _board.Vic.CyclesPerFrame;
_memoryCallbacks = new MemoryCallbackSystem();
HardReset();
@ -64,7 +63,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
if (_board.CartPort.IsConnected)
{
// 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();
@ -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
private void RomSanityCheck()
{
if (Roms.Count == 0)
if (_roms.Count == 0)
{
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>();
@ -119,11 +118,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
}
// IRegionable
public DisplayType Region { get; private set; }
public DisplayType Region { get; }
private readonly int _cyclesPerFrame;
private List<byte[]> Roms = new List<byte[]>();
private readonly List<byte[]> _roms;
private static readonly ControllerDefinition C64ControllerDefinition = new ControllerDefinition
{
@ -147,19 +146,19 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
private int _frameCycles;
private int _frame;
private ITraceable _tracer;
// Disk stuff
private readonly ITraceable _tracer;
// Disk stuff
private bool _nextPressed;
private bool _prevPressed;
private int _currentDisk;
public int CurrentDisk => _currentDisk;
public int DiskCount => Roms.Count;
public int DiskCount => _roms.Count;
private void IncrementDisk()
{
_currentDisk++;
if (CurrentDisk >= Roms.Count)
if (CurrentDisk >= _roms.Count)
{
_currentDisk = 0;
}
@ -172,7 +171,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
_currentDisk--;
if (_currentDisk < 0)
{
_currentDisk = Roms.Count - 1;
_currentDisk = _roms.Count - 1;
}
InitDisk();
@ -180,7 +179,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
private void InitDisk()
{
InitMedia(Roms[_currentDisk]);
InitMedia(_roms[_currentDisk]);
}
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);
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;
}
private void Init(VicType initRegion, BorderType borderType, SidType sidType, TapeDriveType tapeDriveType, DiskDriveType diskDriveType)
{
// Force certain drive types to be available depending on ROM type
var rom = Roms.First();
var rom = _roms.First();
switch (C64FormatFinder.GetFormat(rom))
{
@ -244,7 +246,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
case C64Format.G64:
case C64Format.X64:
if (diskDriveType == DiskDriveType.None)
{
diskDriveType = DiskDriveType.Commodore1541;
}
break;
case C64Format.T64:
case C64Format.TAP:
@ -252,6 +257,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
tapeDriveType = TapeDriveType.Commodore1530;
}
break;
case C64Format.CRT:
// 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.");
}
if (diskDriveType == DiskDriveType.None)
{
diskDriveType = DiskDriveType.Commodore1541;
}
break;
default:
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()
{
InitMedia(Roms[_currentDisk]);
InitMedia(_roms[_currentDisk]);
_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());
chipLength -= chipDataLength + 0x10;
if (chipLength > 0)
{
reader.ReadBytes(chipLength);
}
}
if (chipData.Count <= 0)
@ -150,21 +152,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{
}
public bool ExRom
{
get
{
return pinExRom;
}
}
public bool ExRom => pinExRom;
public bool Game
{
get
{
return pinGame;
}
}
public bool Game => pinGame;
public virtual void HardReset()
{
@ -173,21 +163,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
pinReset = true;
}
public bool IRQ
{
get
{
return pinIRQ;
}
}
public bool IRQ => pinIRQ;
public bool NMI
{
get
{
return pinNMI;
}
}
public bool NMI => pinNMI;
public virtual int Peek8000(int addr)
{
@ -245,13 +223,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
return ReadOpenBus();
}
public bool Reset
{
get
{
return pinReset;
}
}
public bool Reset => pinReset;
protected abstract void SyncStateInternal(Serializer ser);
@ -267,13 +239,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
ser.Sync("_driveLightOn", ref _driveLightOn);
}
public bool Valid
{
get
{
return validCartridge;
}
}
public bool Valid => validCartridge;
public virtual void Write8000(int addr, int val)
{

View File

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

View File

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

View File

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

View File

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

View File

@ -1,19 +1,17 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{
internal sealed class Mapper0007 : CartridgeDevice
{
private int[,] _banks = new int[16,0x2000];
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;
@ -26,9 +24,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
{
for (var i = 0; i < 0x2000; i++)
{
_banks[j,i] = newData[j][i];
_banks[j, i] = newData[j][i];
}
}
_bankNumber = 0;
}
@ -41,18 +40,20 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
public override int Peek8000(int addr)
{
if (!_disabled)
{
return _banks[_bankNumber, addr];
else
return base.Read8000(addr);
}
return base.Read8000(addr);
}
public override void PokeDE00(int addr, int val)
{
if (addr == 0)
{
byte temp_bank = (byte)((val & 0x1) << 3);
temp_bank |= (byte)((val & 0x38) >> 3);
_bankNumber = temp_bank;
byte tempBank = (byte)((val & 0x1) << 3);
tempBank |= (byte)((val & 0x38) >> 3);
_bankNumber = tempBank;
if (val == 0x86)
{
_disabled = true;
@ -63,19 +64,21 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
public override int Read8000(int addr)
{
if (!_disabled)
{
return _banks[_bankNumber, addr];
else
return base.Read8000(addr);
}
return base.Read8000(addr);
}
public override void WriteDE00(int addr, int val)
{
if (addr == 0)
{
byte temp_bank = (byte)((val & 0x1) << 3);
temp_bank |= (byte)((val & 0x38) >> 3);
_bankNumber = temp_bank;
if (val==0x86)
byte tempBank = (byte)((val & 0x1) << 3);
tempBank |= (byte)((val & 0x38) >> 3);
_bankNumber = tempBank;
if (val == 0x86)
{
_disabled = true;
}
@ -83,4 +86,3 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Cartridge
}
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,4 @@
using System;
using BizHawk.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
@ -8,7 +7,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// emulation notes:
// * CS, R/W and RS# pins are not emulated. (not needed)
// * A low RES pin is emulated via HardReset().
public static class Chip6526
{
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[] Act = Vic.TimingBuilder_Act(Timing, 0x004, 0x154, 0x164);
private static readonly int[][] Pipeline = {
Timing,
Fetch,
Ba,
Act
};
private static readonly int[][] Pipeline =
{
Timing,
Fetch,
Ba,
Act
};
public static Vic Create(C64.BorderType borderType)
{
@ -33,8 +34,8 @@
HblankStart, HblankEnd,
Vblankstart, VblankEnd,
borderType,
762, 1000
);
762,
1000);
}
}
}

View File

@ -17,12 +17,13 @@
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[][] Pipeline = {
Timing,
Fetch,
Ba,
Act
};
private static readonly int[][] Pipeline =
{
Timing,
Fetch,
Ba,
Act
};
public static Vic Create(C64.BorderType borderType)
{
@ -33,8 +34,8 @@
HblankStart, HblankEnd,
VblankStart, VblankEnd,
borderType,
6136, 8182
);
6136,
8182);
}
}
}

View File

@ -17,12 +17,13 @@
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[][] Pipeline = {
Timing,
Fetch,
Ba,
Act
};
private static readonly int[][] Pipeline =
{
Timing,
Fetch,
Ba,
Act
};
public static Vic Create(C64.BorderType borderType)
{
@ -33,8 +34,8 @@
HblankStart, HblankEnd,
VblankStart, VblankEnd,
borderType,
7375, 7882
);
7375,
7882);
}
}
}

View File

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

View File

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

View File

@ -1,9 +1,4 @@
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
{
public sealed partial class Cia
{
@ -42,6 +37,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_icr = 0;
return icrTemp;
}
return ReadRegister(addr);
}
@ -82,6 +78,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
case 0xF:
return _crb;
}
return 0;
}
@ -179,7 +176,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// Toggle output begins high when timer starts.
if ((_cra & 0x05) == 0x05 && (oldCra & 0x01) == 0)
{
_prb |= 0x40;
}
break;
case 0xF:
var oldCrb = _crb;
@ -187,7 +186,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// Toggle output begins high when timer starts.
if ((_crb & 0x05) == 0x05 && (oldCrb & 0x01) == 0)
{
_prb |= 0x80;
}
break;
default:
WriteRegister(addr, val);
@ -261,34 +262,16 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
}
}
public int DdrA
{
get { return _ddra; }
}
public int DdrA => _ddra;
public int DdrB
{
get { return _ddrb; }
}
public int DdrB => _ddrb;
public int PrA
{
get { return _pra; }
}
public int PrA => _pra;
public int PrB
{
get { return _prb; }
}
public int PrB => _prb;
public int EffectivePrA
{
get { return _pra | ~_ddra; }
}
public int EffectivePrA => _pra | ~_ddra;
public int EffectivePrB
{
get { return _prb | ~_ddrb; }
}
public int EffectivePrB => _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
{
public sealed partial class Cia
{
/*
Commodore CIA 6526 core.
Commodore CIA 6526 core.
Many thanks to:
- 6502.org for hosting the 6526 datasheet
http://archive.6502.org/datasheets/mos_6526_cia.pdf
- Christian Bauer for information on the delayed interrupt mechanism on the 6526
http://frodo.cebix.net/
*/
Many thanks to:
- 6502.org for hosting the 6526 datasheet
http://archive.6502.org/datasheets/mos_6526_cia.pdf
- Christian Bauer for information on the delayed interrupt mechanism on the 6526
http://frodo.cebix.net/
*/
private enum TimerState
{
@ -139,6 +139,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_taIrqNextCycle = false;
TriggerInterrupt(1);
}
if (_tbIrqNextCycle)
{
_tbIrqNextCycle = false;
@ -159,13 +160,13 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_prb &= 0xBF;
_taPrb6NegativeNextCycle = false;
}
if (_tbPrb7NegativeNextCycle)
{
_prb &= 0x7F;
_tbPrb7NegativeNextCycle = false;
}
switch (_taState)
{
case TimerState.WaitThenCount:
@ -196,6 +197,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
_ta = _latcha;
}
Ta_Idle();
break;
case TimerState.Count:
@ -236,6 +238,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
_tb = _latchb;
}
Tb_Idle();
break;
case TimerState.Count:
@ -262,6 +265,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
TriggerInterrupt(16);
}
_flagLatch = _flagInput;
if (!DelayedInterrupts)
@ -270,9 +274,14 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
}
if ((_cra & 0x02) != 0)
{
_ddra |= 0x40;
}
if ((_crb & 0x02) != 0)
{
_ddrb |= 0x80;
}
}
private void Ta_Count()
@ -285,9 +294,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
Ta_Interrupt();
}
_taUnderflow = true;
}
}
Ta_Idle();
}
@ -319,6 +330,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
_prb ^= 0x40;
}
_ddrb |= 0x40;
}
}
@ -344,6 +356,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_taState = TimerState.LoadThenStop;
}
}
break;
case TimerState.Count:
if ((_newCra & 0x01) != 0)
@ -359,6 +372,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
? TimerState.LoadThenStop
: TimerState.CountThenStop;
}
break;
case TimerState.LoadThenCount:
case TimerState.WaitThenCount:
@ -378,8 +392,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
_taState = TimerState.Stop;
}
break;
}
_cra = _newCra & 0xEF;
_hasNewCra = false;
}
@ -397,6 +413,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
}
}
}
Tb_Idle();
}
@ -452,6 +469,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_tbState = TimerState.LoadThenStop;
}
}
break;
case TimerState.Count:
if ((_newCrb & 0x01) != 0)
@ -467,6 +485,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
? TimerState.LoadThenStop
: TimerState.CountThenStop;
}
break;
case TimerState.LoadThenCount:
case TimerState.WaitThenCount:
@ -486,8 +505,10 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
_tbState = TimerState.Stop;
}
break;
}
_crb = _newCrb & 0xEF;
_hasNewCrb = false;
}
@ -496,7 +517,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
private void TriggerInterrupt(int bit)
{
_icr |= bit;
if ((_intMask & bit) == 0) return;
if ((_intMask & bit) == 0)
{
return;
}
_icr |= 0x80;
}

View File

@ -1,5 +1,4 @@
using System;
using BizHawk.Common;
using BizHawk.Common;
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
// 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.
public int ReadInput(int bus)
{
return (Latch & Direction) | ((Direction ^ 0xFF) & bus);
@ -75,7 +73,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public bool ReadOutput()
{
return (Latch || !Direction);
return Latch || !Direction;
}
public void SyncState(Serializer ser)

View File

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

View File

@ -1,9 +1,4 @@
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
{
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 bool CanProvideAsync
{
get { return false; }
}
public bool CanProvideAsync => false;
public SyncSoundMode SyncMode
{
get { return SyncSoundMode.Sync; }
}
public SyncSoundMode SyncMode => SyncSoundMode.Sync;
public void SetSyncMode(SyncSoundMode mode)
{

View File

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

View File

@ -1,7 +1,6 @@
using System;
using BizHawk.Common;
using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
@ -124,10 +123,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
_potX = ReadPotX();
_potY = ReadPotY();
}
_potCounter--;
}
public void Flush(bool flush_filter)
public void Flush(bool flushFilter)
{
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
if (flush_filter)
if (flushFilter)
{
if (_filterEnable[0] | _filterEnable[1] | _filterEnable[2])
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
public const int FluxBitsPerEntry = 32;
public const int FluxBitsPerTrack = 16000000 / 5;
public const int FluxEntriesPerTrack = FluxBitsPerTrack / FluxBitsPerEntry;
private int[][] _tracks;
private readonly int[][] _tracks;
private readonly int[] _originalMedia;
public bool Valid;
public bool WriteProtected;
@ -33,7 +33,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
/// <param name="trackData">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="trackLengths">Length, in bits, of each raw bit data.</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)
{
@ -43,6 +42,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
{
_tracks[trackNumbers[i]] = ConvertToFluxTransitions(trackDensities[i], trackData[i], 0);
}
FillMissingTracks();
Valid = true;
_originalMedia = SerializeTracks(_tracks);
@ -95,10 +95,15 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
byteData <<= 1;
remainingBits--;
if (remainingBits <= 0)
{
break;
}
}
if (remainingBits <= 0)
{
break;
}
}
return result;

View File

@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
@ -21,7 +19,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
protected class BamEntry
{
public int Data { get; private set; }
public int Sectors { get; private set; }
public int Sectors { get; }
public BamEntry(int sectors)
{
@ -31,6 +29,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
Data >>= 1;
Data |= 0x800000;
}
Data |= (sectors << 24);
Sectors = sectors;
}
@ -64,20 +63,25 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
}
}
public int SectorsRemaining
{
get { return (Data >> 24) & 0xFF; }
}
public int SectorsRemaining => (Data >> 24) & 0xFF;
public bool this[int sector]
{
get { return (Data & (1 << sector)) != 0; }
get
{
return (Data & (1 << sector)) != 0;
}
set
{
if (value)
{
Free(sector);
}
else
{
Allocate(sector);
}
}
}
@ -241,14 +245,18 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
}
if (dataRemaining <= 0)
{
break;
}
bytes[outputOffset + 0] = (byte)(currentTrack + 1);
bytes[outputOffset + 1] = (byte)currentSector;
}
if (diskFull)
{
break;
}
}
// write Directory
@ -276,8 +284,11 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
bytes[directoryOutputOffset + directoryOffset + 0x03] = (byte)(entry.Track + 1);
bytes[directoryOutputOffset + directoryOffset + 0x04] = (byte)entry.Sector;
for (var i = 0x05; i <= 0x14; i++)
{
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));
bytes[directoryOutputOffset + directoryOffset + 0x1E] = (byte)(entry.LengthInSectors & 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);
}
for (var i = 0x90; i <= 0xAA; i++)
{
bytes[bamOutputOffset + i] = 0xA0;
}
var titleBytes = Encoding.ASCII.GetBytes(Title ?? "UNTITLED");
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")
{
reader.ReadByte(); //version
reader.ReadByte(); // version
int trackCount = reader.ReadByte();
reader.ReadInt16(); //max track size in bytes
reader.ReadInt16(); // max track size in bytes
var trackOffsetTable = new int[trackCount];
var trackSpeedTable = new int[trackCount];
for (var i = 0; i < trackCount; i++)
{
trackOffsetTable[i] = reader.ReadInt32();
}
for (var i = 0; i < trackCount; i++)
{
trackSpeedTable[i] = reader.ReadInt32();
}
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")
{
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);
if (size + 20 != tapeFile.Length)
{
throw new Exception("Tape file header specifies a length that doesn't match the file size");
}
result = new Tape(version, tapeFile, 20, tapeFile.Length);
}
return result;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Components.M6502;
using BizHawk.Emulation.Cores.Computers.Commodore64.Media;
using BizHawk.Emulation.Cores.Computers.Commodore64.MOS;
@ -115,6 +110,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
_ratioDifference -= _cpuClockNum;
_clocks++;
}
ExecutePhaseInternal();
}
@ -136,6 +132,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Serial
{
_cpu.SetOverflow();
}
_overflowFlagDelaySr >>= 1;
_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();
}
public bool DriveLightEnabled { get { return true; } }
public bool DriveLightOn { get { return ReadDeviceLight(); } }
public bool IsConnected { get { return _connected; } }
public bool DriveLightEnabled => true;
public bool DriveLightOn => ReadDeviceLight();
public bool IsConnected => _connected;
}
}

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_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_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_002ESA1402/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=StyleCop_002ESA1502/@EntryIndexedValue">DO_NOT_SHOW</s:String>