c64 core uses ISettable now and supports 2 more video standards

This commit is contained in:
Kabuto 2015-09-28 23:52:23 +02:00
parent f7c15bfd0f
commit 004c8294fb
14 changed files with 279 additions and 100 deletions

View File

@ -672,7 +672,7 @@ namespace BizHawk.Client.Common
nextEmulator = new Atari7800(nextComm, game, rom.RomData, gamedbpath);
break;
case "C64":
var c64 = new C64(nextComm, game, rom.RomData, rom.Extension);
var c64 = new C64(nextComm, game, rom.RomData, rom.Extension, GetCoreSettings<C64>(), GetCoreSyncSettings<C64>());
nextEmulator = c64;
break;
case "GBA":

View File

@ -8,6 +8,12 @@ namespace BizHawk.Client.Common
// these are political numbers, designed to be in accord with tasvideos.org tradition. theyre not necessarily mathematical factualities (although they may be in some cases)
// it would be nice if we could turn this into a rational expression natively, and also, to write some comments about the derivation and ideal valees (since this seems to be where theyre all collected)
// are we collecting them anywhere else? for avi-writing code perhaps?
// just some constants, according to specs
private static readonly double PAL_CARRIER = 15625 * 283.75 + 25; // 4.43361875 MHz
private static readonly double NTSC_CARRIER = 4500000 * 227.5 / 286; // 3.579545454... MHz
private static readonly double PAL_N_CARRIER = 15625 * 229.25 + 25; // 3.58205625 MHz
private static readonly Dictionary<string, double> _rates = new Dictionary<string, double>
{
{ "NES", 60.098813897440515532 }, // discussion here: http://forums.nesdev.com/viewtopic.php?t=492 ; a rational expression would be (19687500 / 11) / ((341*262-0.529780.5)/3) -> (118125000 / 1965513) -> 60.098813897440515529533511098629 (so our chosen number is very close)
@ -48,6 +54,11 @@ namespace BizHawk.Client.Common
{"PSX", 44100.0*768*11/7/263/3413}, //59.292862562
{"PSX_PAL", 44100.0*768*11/7/314/3406}, //49.7645593576
{"C64_PAL", PAL_CARRIER*2/9/312/63},
{"C64_NTSC", NTSC_CARRIER*2/7/263/65},
{"C64_NTSC_OLD", NTSC_CARRIER*2/7/262/64},
{"C64_DREAN", PAL_N_CARRIER*2/7/312/65},
//according to ryphecha, using
//clocks[2] = { 53.693182e06, 53.203425e06 }; //ntsc console, pal console
//lpf[2][2] = { { 263, 262.5 }, { 314, 312.5 } }; //ntsc,pal; noninterlaced, interlaced

View File

@ -161,6 +161,7 @@
<Compile Include="Computers\Commodore64\C64.IMemoryDomains.cs">
<DependentUpon>C64.cs</DependentUpon>
</Compile>
<Compile Include="Computers\Commodore64\C64.ISettable.cs" />
<Compile Include="Computers\Commodore64\C64.IStatable.cs">
<DependentUpon>C64.cs</DependentUpon>
</Compile>
@ -185,6 +186,7 @@
<Compile Include="Computers\Commodore64\MOS\Chip2114.cs" />
<Compile Include="Computers\Commodore64\MOS\Chip23XX.cs" />
<Compile Include="Computers\Commodore64\MOS\Chip4864.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6567R56A.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6510.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6522.cs" />
<Compile Include="Computers\Commodore64\Media\D64.cs" />
@ -194,7 +196,8 @@
<Compile Include="Computers\Commodore64\MOS\MOS6526-2.Interface.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6526-2.PortIO.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6526.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6567.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6567R8.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6572.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6581.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6569.cs" />
<Compile Include="Computers\Commodore64\MOS\MOSPLA.cs" />

View File

@ -9,7 +9,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
public string Cpu
{
get { return "6510"; }
get { return "6510"; } set { }
}
public string PCRegisterName

View File

@ -0,0 +1,75 @@
using BizHawk.Emulation.Common;
using Newtonsoft.Json;
using System;
using System.ComponentModel;
using System.Drawing;
namespace BizHawk.Emulation.Cores.Computers.Commodore64
{
public partial class C64 : ISettable<C64.C64Settings, C64.C64SyncSettings>
{
public C64Settings GetSettings()
{
return Settings.Clone();
}
public C64SyncSettings GetSyncSettings()
{
return SyncSettings.Clone();
}
public bool PutSettings(C64Settings o)
{
Settings = o;
return false;
}
public bool PutSyncSettings(C64SyncSettings o)
{
SyncSettings = o;
return false;
}
internal C64Settings Settings { get; private set; }
internal C64SyncSettings SyncSettings { get; private set; }
public class C64Settings
{
public C64Settings Clone()
{
return (C64Settings)MemberwiseClone();
}
public C64Settings()
{
BizHawk.Common.SettingsUtil.SetDefaultValues(this);
}
}
public class C64SyncSettings
{
[DisplayName("VIC type")]
[Description("Set the type of video chip to use")]
[DefaultValue(VicType.PAL)]
public VicType vicType { get; set; }
public C64SyncSettings Clone()
{
return (C64SyncSettings)MemberwiseClone();
}
public C64SyncSettings()
{
BizHawk.Common.SettingsUtil.SetDefaultValues(this);
}
}
public enum VicType
{
PAL, NTSC, NTSC_OLD, DREAN
}
}
}

View File

@ -42,25 +42,48 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
private C64 _c64;
public Motherboard(C64 c64, DisplayType initRegion)
public Motherboard(C64 c64, C64.VicType initRegion)
{
// note: roms need to be added on their own externally
_c64 = c64;
int clockNum, clockDen, mainsFrq;
switch (initRegion)
{
case C64.VicType.PAL:
clockNum = 17734475;
clockDen = 18;
mainsFrq = 50;
break;
case C64.VicType.NTSC:
case C64.VicType.NTSC_OLD:
clockNum = 11250000;
clockDen = 11;
mainsFrq = 60;
break;
case C64.VicType.DREAN:
clockNum = 14328225;
clockDen = 14;
mainsFrq = 50;
break;
default:
throw new System.Exception();
}
cartPort = new CartridgePort();
cassPort = new CassettePortDevice();
cia0 = new MOS6526(initRegion);
cia1 = new MOS6526(initRegion);
cia0 = new MOS6526(clockNum, clockDen*mainsFrq);
cia1 = new MOS6526(clockNum, clockDen*mainsFrq);
colorRam = new Chip2114();
cpu = new MOS6510();
pla = new MOSPLA();
ram = new Chip4864();
serPort = new SerialPort();
sid = MOS6581.Create(44100, initRegion);
sid = MOS6581.Create(44100, clockNum, clockDen);
switch (initRegion)
{
case DisplayType.NTSC: vic = MOS6567.Create(); break;
case DisplayType.PAL: vic = MOS6569.Create(); break;
case C64.VicType.NTSC: vic = MOS6567R8.Create(); break;
case C64.VicType.PAL: vic = MOS6569.Create(); break;
case C64.VicType.NTSC_OLD: vic = MOS6567R56A.Create(); break;
case C64.VicType.DREAN: vic = MOS6572.Create(); break;
}
userPort = new UserPortDevice();
}

View File

@ -15,11 +15,14 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
isReleased: false
)]
[ServiceNotApplicable(typeof(ISettable<,>))]
sealed public partial class C64 : IEmulator, IStatable, IInputPollable, IDriveLight, IDebuggable, IDisassemblable, IRegionable
sealed public partial class C64 : IEmulator, IStatable, IInputPollable, IDriveLight, IDebuggable, IDisassemblable, IRegionable, ISettable<C64.C64Settings, C64.C64SyncSettings>
{
// framework
public C64(CoreComm comm, GameInfo game, byte[] rom, string romextension)
public C64(CoreComm comm, GameInfo game, byte[] rom, string romextension, object Settings, object SyncSettings)
{
PutSyncSettings((C64SyncSettings)SyncSettings ?? new C64SyncSettings());
PutSettings((C64Settings)Settings ?? new C64Settings());
ServiceProvider = new BasicServiceProvider(this);
InputCallbacks = new InputCallbackSystem();
@ -27,8 +30,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
inputFileInfo.Data = rom;
inputFileInfo.Extension = romextension;
CoreComm = comm;
Region = queryUserForRegion();
Init(Region);
Init(this.SyncSettings.vicType);
cyclesPerFrame = board.vic.CyclesPerFrame;
SetupMemoryDomains();
MemoryCallbacks = new MemoryCallbackSystem();
@ -38,7 +40,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
}
private DisplayType queryUserForRegion()
/*private DisplayType queryUserForRegion()
{
Form prompt = new Form() { Width = 160, Height = 120, FormBorderStyle = FormBorderStyle.FixedDialog, Text = "Region selector", StartPosition = FormStartPosition.CenterScreen };
Label textLabel = new Label() { Left = 10, Top = 10, Width = 260, Text = "Please choose a region:" };
@ -57,7 +59,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
throw new Exception("Can't construct new C64 because you didn't choose anything");
}
return palButton.Checked ? DisplayType.PAL : DisplayType.NTSC;
}
}*/
// internal variables
private int _frame = 0;
@ -205,7 +207,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
return result;
}
private void Init(DisplayType initRegion)
private void Init(VicType initRegion)
{
board = new Motherboard(this, initRegion);
InitRoms();

View File

@ -39,7 +39,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.CassettePort
{
if (cycle == 0)
{
Console.WriteLine("Tape @ " + pos.ToString());
if (pos >= end)
{
return true;

View File

@ -51,7 +51,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
// ------------------------------------
bool alarmSelect;
Common.DisplayType chipRegion;
bool cntPos;
bool enableIntAlarm;
bool enableIntFlag;
@ -77,16 +76,22 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
byte[] todAlarm;
bool todAlarmPM;
int todCounter;
int todCounterLatch;
bool todIn;
bool todPM;
bool oldFlag;
// ------------------------------------
public MOS6526(Common.DisplayType region)
int todStepsNum;
int todStepsDen;
// todStepsNum/todStepsDen is the number of clock cycles it takes the external clock source to advance one cycle
// (50 or 60 Hz depending on AC frequency in use).
// By default the CIA assumes 60 Hz and will thus count incorrectly when fed with 50 Hz.
public MOS6526(int todStepsNum, int todStepsDen)
{
chipRegion = region;
enableIntTimer = new bool[2];
this.todStepsNum = todStepsNum;
this.todStepsDen = todStepsDen;
enableIntTimer = new bool[2];
intTimer = new bool[2];
timerDelay = new int[2];
timerInMode = new InMode[2];
@ -96,7 +101,6 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
timerRunMode = new RunMode[2];
tod = new byte[4];
todAlarm = new byte[4];
SetTodIn(chipRegion);
portA = new LatchedPort();
portB = new LatchedPort();
@ -207,29 +211,14 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
todAlarm[1] = 0;
todAlarm[2] = 0;
todAlarm[3] = 0;
todCounter = todCounterLatch;
todIn = (chipRegion == Common.DisplayType.PAL);
todCounter = 0;
todIn = false;
todPM = false;
pinCnt = false;
pinPC = true;
}
private void SetTodIn(Common.DisplayType region)
{
switch (region)
{
case Common.DisplayType.NTSC:
todCounterLatch = 14318181 / 140;
todIn = false;
break;
case Common.DisplayType.PAL:
todCounterLatch = 17734472 / 180;
todIn = true;
break;
}
}
// ------------------------------------
private byte BCDAdd(byte i, byte j, out bool overflow)
@ -342,9 +331,9 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
bool todV;
if (todCounter == 0)
if (todCounter <= 0)
{
todCounter = todCounterLatch;
todCounter += todStepsNum*(todIn ? 6 : 5);
tod[0] = BCDAdd(tod[0], 1, out todV);
if (tod[0] >= 10)
{
@ -370,7 +359,7 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
}
}
}
todCounter--;
todCounter -= todStepsDen;
}
}

View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
// vic ntsc old
// TODO is everything right? it's mostly a copy from the other NTSC chip with tweaks wherever it was neccessary to fix something
static public class MOS6567R56A
{
static int cycles = 64;
static int scanwidth = cycles * 8;
static int lines = 262;
static int vblankstart = 0x00D % lines;
static int vblankend = 0x018 % lines;
static int hblankoffset = 20;
static int hblankstart = (0x18C + hblankoffset) % scanwidth;
static int hblankend = (0x1F0 + hblankoffset) % scanwidth;
static int[] timing = Vic.TimingBuilder_XRaster(0x19C, 0x200, scanwidth, -1, -1);
static int[] fetch = Vic.TimingBuilder_Fetch(timing, 0x174);
static int[] ba = Vic.TimingBuilder_BA(fetch);
static int[] act = Vic.TimingBuilder_Act(timing, 0x004, 0x14C, hblankstart, hblankend);
static int[][] pipeline = new int[][]
{
timing,
fetch,
ba,
act
};
static public Vic Create()
{
return new Vic(
cycles, lines,
pipeline,
14318181 / 14,
hblankstart, hblankend,
vblankstart, vblankend
);
}
}
}

View File

@ -1,41 +1,41 @@
using System.Drawing;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
// vic ntsc
static public class MOS6567
{
static int cycles = 65;
static int scanwidth = cycles * 8;
static int lines = 263;
static int vblankstart = 0x00D % lines;
static int vblankend = 0x018 % lines;
static int hblankoffset = 20;
static int hblankstart = (0x18C + hblankoffset) % scanwidth - 8; // -8 because the VIC repeats internal pixel cycles around 0x18C
static int hblankend = (0x1F0 + hblankoffset) % scanwidth - 8;
static int[] timing = Vic.TimingBuilder_XRaster(0x19C, 0x200, scanwidth, 0x18C, 8);
static int[] fetch = Vic.TimingBuilder_Fetch(timing, 0x174);
static int[] ba = Vic.TimingBuilder_BA(fetch);
static int[] act = Vic.TimingBuilder_Act(timing, 0x004, 0x14C, hblankstart, hblankend);
static int[][] pipeline = new int[][]
{
timing,
fetch,
ba,
act
};
static public Vic Create()
{
return new Vic(
cycles, lines,
pipeline,
14318181 / 14,
hblankstart, hblankend,
vblankstart, vblankend
);
}
}
}
using System.Drawing;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
// vic ntsc
static public class MOS6567R8
{
static int cycles = 65;
static int scanwidth = cycles * 8;
static int lines = 263;
static int vblankstart = 0x00D % lines;
static int vblankend = 0x018 % lines;
static int hblankoffset = 20;
static int hblankstart = (0x18C + hblankoffset) % scanwidth - 8; // -8 because the VIC repeats internal pixel cycles around 0x18C
static int hblankend = (0x1F0 + hblankoffset) % scanwidth - 8;
static int[] timing = Vic.TimingBuilder_XRaster(0x19C, 0x200, scanwidth, 0x18C, 8);
static int[] fetch = Vic.TimingBuilder_Fetch(timing, 0x174);
static int[] ba = Vic.TimingBuilder_BA(fetch);
static int[] act = Vic.TimingBuilder_Act(timing, 0x004, 0x14C, hblankstart, hblankend);
static int[][] pipeline = new int[][]
{
timing,
fetch,
ba,
act
};
static public Vic Create()
{
return new Vic(
cycles, lines,
pipeline,
14318181 / 14,
hblankstart, hblankend,
vblankstart, vblankend
);
}
}
}

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
{
// pal n / drean - TODO correct?
class MOS6572
{
static int cycles = 65;
static int scanwidth = cycles * 8;
static int lines = 312;
static int vblankstart = 0x12C % lines;
static int vblankend = 0x00F % lines;
static int hblankoffset = 20;
static int hblankstart = (0x18C + hblankoffset) % scanwidth - 8; // -8 because the VIC repeats internal pixel cycles around 0x18C
static int hblankend = (0x1F0 + hblankoffset) % scanwidth - 8;
static int[] timing = Vic.TimingBuilder_XRaster(0x19C, 0x200, scanwidth, 0x18C, 8);
static int[] fetch = Vic.TimingBuilder_Fetch(timing, 0x174);
static int[] ba = Vic.TimingBuilder_BA(fetch);
static int[] act = Vic.TimingBuilder_Act(timing, 0x004, 0x14C, hblankstart, hblankend);
static int[][] pipeline = new int[][]
{
timing,
fetch,
ba,
act
};
static public Vic Create()
{
return new Vic(
cycles, lines,
pipeline,
14328225 / 14,
hblankstart, hblankend,
vblankstart, vblankend
);
}
}
}

View File

@ -4119,9 +4119,9 @@
}
};
static public Sid Create(int newSampleRate, Common.DisplayType newRegion)
static public Sid Create(int newSampleRate, int clockFrqNum, int clockFrqDen)
{
return new Sid(waveTable, newSampleRate, newRegion);
return new Sid(waveTable, (uint)newSampleRate, (uint)clockFrqNum, (uint)clockFrqDen);
}
}
}

View File

@ -42,20 +42,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.MOS
public Func<byte> ReadPotX;
public Func<byte> ReadPotY;
public Sid(int[][] newWaveformTable, int newSampleRate, Common.DisplayType newRegion)
public Sid(int[][] newWaveformTable, uint sampleRate, uint cyclesNum, uint cyclesDen)
{
uint cyclesPerSec = 0;
uint cyclesNum;
uint cyclesDen;
uint sampleRate = 44100;
switch (newRegion)
{
case Common.DisplayType.NTSC: cyclesNum = 14318181; cyclesDen = 14; break;
case Common.DisplayType.PAL: cyclesNum = 17734472; cyclesDen = 18; break;
default: return;
}
waveformTable = newWaveformTable;
envelopes = new Envelope[3];