Fix some compiler warnings. Border is still odd, needs the other half of the border unit logic. Also, a marginal performance boost from sealing classes.

This commit is contained in:
saxxonpike 2013-08-24 17:30:46 +00:00
parent 7ff1675d7f
commit 4ef73eb676
24 changed files with 566 additions and 687 deletions

View File

@ -2,7 +2,7 @@
namespace BizHawk.Emulation.Computers.Commodore64
{
public partial class Motherboard
sealed public partial class Motherboard
{
private int[] joystickPressed = new int[10];
private int[] keyboardPressed = new int[64];
@ -28,9 +28,9 @@ namespace BizHawk.Emulation.Computers.Commodore64
static private byte[] inputBitMask = new byte[] { 0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F };
static private byte[] inputBitSelect = new byte[] { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
protected byte cia0InputLatchA;
protected byte cia0InputLatchB;
protected int pollIndex;
byte cia0InputLatchA;
byte cia0InputLatchB;
int pollIndex;
public void PollInput()
{

View File

@ -48,7 +48,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
pla = new MOSPLA();
ram = new Chip4864();
serPort = new SerialPort();
sid = new MOS6581(44100, initRegion);
sid = MOS6581.Create(44100, initRegion);
switch (initRegion)
{
case Region.NTSC: vic = MOS6567.Create(); break;
@ -61,16 +61,16 @@ namespace BizHawk.Emulation.Computers.Commodore64
public void Execute()
{
cia0.ExecutePhase1();
cia1.ExecutePhase1();
vic.ExecutePhase1();
cpu.ExecutePhase1();
cia0.ExecutePhase1();
cia1.ExecutePhase1();
cia0.ExecutePhase2();
cia1.ExecutePhase2();
sid.ExecutePhase2();
vic.ExecutePhase2();
cpu.ExecutePhase2();
cia0.ExecutePhase2();
cia1.ExecutePhase2();
sid.ExecutePhase2();
}
public void Flush()

View File

@ -7,9 +7,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals
{
sealed public class Ram
{
protected int addressMask;
protected int dataMask;
protected int[] memory;
int addressMask;
int dataMask;
int[] memory;
public Ram(int size, int addressMask, int dataMask)
{

View File

@ -7,8 +7,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals
{
public class Rom
{
protected int addressMask;
protected int[] memory;
int addressMask;
int[] memory;
public Rom(int size, int addressMask, byte[] data)
{

View File

@ -8,8 +8,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public Func<bool> ReadIRQ;
public Func<bool> ReadNMI;
protected Cart cart;
protected bool connected;
Cart cart;
bool connected;
public CartridgePort()
{

View File

@ -2,9 +2,9 @@
{
// used as Color RAM in C64
public class Chip2114
sealed public class Chip2114
{
protected byte[] ram;
byte[] ram;
public Chip2114()
{

View File

@ -7,17 +7,17 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// 2364: 64 kbit (8kbyte)
// 23128: 128 kbit (16kbyte)
public enum Chip23XXmodel
public enum Chip23XXmodel
{
Chip2332,
Chip2364,
Chip23128
}
public class Chip23XX
sealed public class Chip23XX
{
protected int addrMask;
protected byte[] rom;
int addrMask;
byte[] rom;
public Chip23XX(Chip23XXmodel model, byte[] data)
{

View File

@ -11,9 +11,9 @@
// memory is striped 00/FF at intervals of 0x40
public class Chip4864
sealed public class Chip4864
{
protected byte[] ram;
byte[] ram;
public Chip4864()
{

View File

@ -7,14 +7,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
// an extension of the 6502 processor
public class MOS6510
sealed public class MOS6510
{
// ------------------------------------
protected MOS6502X cpu;
protected bool pinNMILast;
protected LatchedPort port;
protected bool thisNMI;
MOS6502X cpu;
bool pinNMILast;
LatchedPort port;
bool thisNMI;
public Func<int, byte> PeekMemory;
public Action<int, byte> PokeMemory;

View File

@ -8,11 +8,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// * CS, R/W and RS# pins are not emulated. (not needed)
// * A low RES pin is emulated via HardReset().
public class MOS6526 : Timer
sealed public class MOS6526
{
// ------------------------------------
protected enum InMode
enum InMode
{
Phase2,
CNT,
@ -20,26 +20,26 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
TimerAUnderflowCNT
}
protected enum OutMode
enum OutMode
{
Pulse,
Toggle
}
protected enum RunMode
enum RunMode
{
Continuous,
Oneshot
}
protected enum SPMode
enum SPMode
{
Input,
Output
}
protected static byte[] PBOnBit = new byte[] { 0x40, 0x80 };
protected static byte[] PBOnMask = new byte[] { 0xBF, 0x7F };
static byte[] PBOnBit = new byte[] { 0x40, 0x80 };
static byte[] PBOnMask = new byte[] { 0xBF, 0x7F };
// ------------------------------------
@ -49,36 +49,36 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// ------------------------------------
protected bool alarmSelect;
protected Region chipRegion;
protected bool cntPos;
protected bool enableIntAlarm;
protected bool enableIntFlag;
protected bool enableIntSP;
protected bool[] enableIntTimer;
protected bool intAlarm;
protected bool intFlag;
protected bool intSP;
protected bool[] intTimer;
protected bool pinCnt;
protected bool pinCntLast;
protected bool pinPC;
protected bool pinSP;
protected byte sr;
protected int[] timerDelay;
protected InMode[] timerInMode;
protected OutMode[] timerOutMode;
protected bool[] timerPortEnable;
protected bool[] timerPulse;
protected RunMode[] timerRunMode;
protected SPMode timerSPMode;
protected byte[] tod;
protected byte[] todAlarm;
protected bool todAlarmPM;
protected int todCounter;
protected int todCounterLatch;
protected bool todIn;
protected bool todPM;
bool alarmSelect;
Region chipRegion;
bool cntPos;
bool enableIntAlarm;
bool enableIntFlag;
bool enableIntSP;
bool[] enableIntTimer;
bool intAlarm;
bool intFlag;
bool intSP;
bool[] intTimer;
bool pinCnt;
bool pinCntLast;
bool pinPC;
bool pinSP;
byte sr;
int[] timerDelay;
InMode[] timerInMode;
OutMode[] timerOutMode;
bool[] timerPortEnable;
bool[] timerPulse;
RunMode[] timerRunMode;
SPMode timerSPMode;
byte[] tod;
byte[] todAlarm;
bool todAlarmPM;
int todCounter;
int todCounterLatch;
bool todIn;
bool todPM;
// ------------------------------------
@ -95,23 +95,21 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
timerRunMode = new RunMode[2];
tod = new byte[4];
todAlarm = new byte[4];
SetTodIn(chipRegion);
}
portA = new LatchedPort();
portB = new LatchedPort();
timer = new int[2];
timerLatch = new int[2];
timerOn = new bool[2];
underflow = new bool[2];
}
// ------------------------------------
public void ExecutePhase1()
{
// unsure if the timer actually operates in ph1
pinIRQ = !(
(intTimer[0] && enableIntTimer[0]) ||
(intTimer[1] && enableIntTimer[1]) ||
(intAlarm && enableIntAlarm) ||
(intSP && enableIntSP) ||
(intFlag && enableIntFlag)
);
}
public void ExecutePhase2()
@ -153,6 +151,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
cntPos = false;
underflow[0] = false;
underflow[1] = false;
pinIRQ = !(
(intTimer[0] && enableIntTimer[0]) ||
(intTimer[1] && enableIntTimer[1]) ||
(intAlarm && enableIntAlarm) ||
(intSP && enableIntSP) ||
(intFlag && enableIntFlag)
);
}
}
@ -295,7 +301,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// underflow?
if (u)
{
timerDelay[index]++;
//timerDelay[index] = 2;
t = timerLatch[index];
if (timerRunMode[index] == RunMode.Oneshot)
timerOn[index] = false;
@ -698,5 +704,78 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
}
// ------------------------------------
}
public byte PortAMask = 0xFF;
public byte PortBMask = 0xFF;
bool pinIRQ;
LatchedPort portA;
LatchedPort portB;
int[] timer;
int[] timerLatch;
bool[] timerOn;
bool[] underflow;
public Func<byte> ReadPortA = (() => { return 0xFF; });
public Func<byte> ReadPortB = (() => { return 0xFF; });
void HardResetInternal()
{
timer[0] = 0xFFFF;
timer[1] = 0xFFFF;
timerLatch[0] = timer[0];
timerLatch[1] = timer[1];
pinIRQ = true;
}
public byte PortAData
{
get
{
return portA.ReadOutput();
}
}
public byte PortADirection
{
get
{
return portA.Direction;
}
}
public byte PortALatch
{
get
{
return portA.Latch;
}
}
public byte PortBData
{
get
{
return portB.ReadOutput();
}
}
public byte PortBDirection
{
get
{
return portB.Direction;
}
}
public byte PortBLatch
{
get
{
return portB.Latch;
}
}
public bool ReadIRQBuffer() { return pinIRQ; }
}
}

View File

@ -3,7 +3,19 @@
// vic ntsc
static public class MOS6567
{
static int[][] pipeline = new int[5][];
static int[] timing = Vic.TimingBuilder_XRaster(0x19C, 0x200, 0x208, 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);
static int[][] pipeline = new int[][]
{
timing,
fetch,
ba,
act
};
static public Vic Create()
{
return new Vic(65, 263, pipeline, 14318181 / 14);

View File

@ -1,95 +1,19 @@
namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
// vic pal
public class MOS6569
static public class MOS6569
{
static int[] timing = Vic.TimingBuilder_XRaster(0x194, 0x1F8, 0x1F8, -1, -1);
static int[] fetch = Vic.TimingBuilder_Fetch(timing, 0x164);
static int[] ba = Vic.TimingBuilder_BA(fetch);
static int[] act = Vic.TimingBuilder_Act(timing, 0x004, 0x14C);
static int[][] pipeline = new int[][]
{
timing,
fetch,
ba,
new int[] // actions
{
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, Vic.pipelineUpdateVc,
0, Vic.pipelineChkSprChunch,
0, Vic.pipelineUpdateMcBase,
0, Vic.pipelineChkBrdL1,
0, Vic.pipelineChkBrdL0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0,
Vic.pipelineChkSprDma, 0,
Vic.pipelineChkSprDma, Vic.pipelineChkBrdR0 | Vic.pipelineChkSprExp,
0, Vic.pipelineChkBrdR1,
Vic.pipelineChkSprDisp, Vic.pipelineUpdateRc,
0, 0,
0, 0,
0, 0,
0, 0,
0, 0
}
act
};
static public Vic Create()

View File

@ -1,9 +1,9 @@
namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
// sid
public class MOS6581 : Sid
static public class MOS6581
{
static protected int[][] waveTable = new int[][]
static int[][] waveTable = new int[][]
{
new int[] {
0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF,
@ -4119,8 +4119,9 @@
}
};
public MOS6581(int newSampleRate, Region newRegion) : base(waveTable, newSampleRate, newRegion)
{
}
static public Sid Create(int newSampleRate, Region newRegion)
{
return new Sid(waveTable, newSampleRate, newRegion);
}
}
}

View File

@ -5,7 +5,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// emulates the PLA
// which handles all bank switching
public class MOSPLA
sealed public class MOSPLA
{
// ------------------------------------
@ -65,7 +65,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// ------------------------------------
protected enum PLABank
enum PLABank
{
None,
RAM,
@ -86,35 +86,20 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// ------------------------------------
protected bool p0;
protected bool p1;
protected bool p2;
protected bool p3;
protected bool p4;
protected bool p5;
protected bool p9;
protected bool p11;
protected bool p13;
protected bool p15;
protected bool p17;
protected bool p19;
protected bool p20;
protected bool p21;
protected bool p22;
protected bool p24;
protected bool p25;
protected bool p26;
protected bool p27;
protected bool p28;
protected bool loram;
protected bool hiram;
protected bool game;
protected bool exrom;
protected bool charen;
protected bool a15;
protected bool a14;
protected bool a13;
protected bool a12;
bool p24;
bool p25;
bool p26;
bool p27;
bool p28;
bool loram;
bool hiram;
bool game;
bool exrom;
bool charen;
bool a15;
bool a14;
bool a13;
bool a12;
private PLABank Bank(int addr, bool read)
{
@ -126,96 +111,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
a14 = (addr & 0x04000) != 0;
a13 = (addr & 0x02000) != 0;
a12 = (addr & 0x01000) != 0;
#region OLDPLA
//// io/character access
//if (a15 && a14 && !a13 && a12)
//{
// // character rom, banked in at D000-DFFF
// charen = ReadCharen();
// if (read && !charen)
// {
// p3 = hiram && game;
// p4 = loram && game;
// p5 = hiram && !exrom && !game;
// if (p3 || p4 || p5)
// return PLABank.CharROM;
// }
// // io block, banked in at D000-DFFF
// p9 = hiram && charen && game;
// p11 = loram && charen && game;
// p13 = hiram && charen && !exrom && !game;
// p15 = loram && charen && !exrom && !game;
// p17 = exrom && !game;
// if (p9 || p11 || p13 || p15 || p17)
// {
// 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;
// if (addr < 0xDF00)
// return PLABank.Expansion0;
// return PLABank.Expansion1;
// }
//}
//// basic rom, banked at A000-BFFF
//p0 = loram && hiram && a15 && !a14 && a13 && read && game;
//if (p0)
// return PLABank.BasicROM;
//// kernal rom, banked at E000-FFFF
//exrom = ReadExRom();
//if (hiram && a15 && a14 && a13 && read)
//{
// p1 = game;
// p2 = !exrom && !game;
// if (p1 || p2)
// return PLABank.KernalROM;
//}
//// cartridge low, banked at 8000-9FFF
//if (a15 && !a14 && !a13)
//{
// p19 = loram && hiram && read && !exrom;
// p20 = exrom && !game;
// if (p19 || p20)
// return PLABank.CartridgeLo;
//}
//// cartridge high, banked either at A000-BFFF or E000-FFFF depending
//if (a15 && a13 && !game)
//{
// p21 = hiram && !a14 && read && !exrom;
// p22 = a14 && exrom;
// if (p21 || p22)
// return PLABank.CartridgeHi;
//}
//// ultimax mode ram exclusion
//if (exrom && !game)
//{
// p24 = !a15 && !a14 && a12;
// p25 = !a15 && !a14 && a13;
// p26 = !a15 && a14;
// p27 = a15 && !a14 && a13;
// p28 = a15 && a14 && !a13 && !a12;
// if (!(p24 || p25 || p26 || p27 || p28))
// return PLABank.RAM;
//}
//else
//{
// return PLABank.RAM;
//}
//return PLABank.None;
#endregion
// upper memory regions 8000-FFFF
exrom = ReadExRom();

View File

@ -2,7 +2,7 @@
namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
public class LatchedPort
sealed public class LatchedPort
{
public byte Direction;
public byte Latch;
@ -42,7 +42,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
}
}
public class LatchedBooleanPort
sealed public class LatchedBooleanPort
{
public bool Direction;
public bool Latch;

View File

@ -2,31 +2,31 @@
namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
public abstract partial class Sid
sealed public partial class Sid
{
// ------------------------------------
protected class Envelope
sealed class Envelope
{
protected const int stateAttack = 0;
protected const int stateDecay = 1;
protected const int stateRelease = 2;
const int stateAttack = 0;
const int stateDecay = 1;
const int stateRelease = 2;
protected int attack;
protected int decay;
protected bool delay;
protected int envCounter;
protected int expCounter;
protected int expPeriod;
protected bool freeze;
protected int lfsr;
protected bool gate;
protected int rate;
protected int release;
protected int state;
protected int sustain;
int attack;
int decay;
bool delay;
int envCounter;
int expCounter;
int expPeriod;
bool freeze;
int lfsr;
bool gate;
int rate;
int release;
int state;
int sustain;
protected static int[] adsrTable = new int[]
static int[] adsrTable = new int[]
{
0x7F00, 0x0006, 0x003C, 0x0330,
0x20C0, 0x6755, 0x3800, 0x500E,
@ -34,17 +34,17 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
0x3840, 0x77E2, 0x7625, 0x0A93
};
protected static int[] expCounterTable = new int[]
static int[] expCounterTable = new int[]
{
0xFF, 0x5D, 0x36, 0x1A, 0x0E, 0x06, 0x00
};
protected static int[] expPeriodTable = new int[]
static int[] expPeriodTable = new int[]
{
0x01, 0x02, 0x04, 0x08, 0x10, 0x1E, 0x01
};
protected static int[] sustainTable = new int[]
static int[] sustainTable = new int[]
{
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF
@ -247,34 +247,34 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// ------------------------------------
}
protected class Voice
sealed class Voice
{
protected int accBits;
protected int accNext;
protected int accumulator;
protected bool controlTestPrev;
protected int controlWavePrev;
protected int delay;
protected int floatOutputTTL;
protected int frequency;
protected bool msbRising;
protected int noise;
protected int noNoise;
protected int noNoiseOrNoise;
protected int noPulse;
protected int output;
protected int pulse;
protected int pulseWidth;
protected bool ringMod;
protected int ringMsbMask;
protected int shiftRegister;
protected int shiftRegisterReset;
protected bool sync;
protected bool test;
protected int[] wave;
protected int waveform;
protected int waveformIndex;
protected int[][] waveTable;
int accBits;
int accNext;
int accumulator;
bool controlTestPrev;
int controlWavePrev;
int delay;
int floatOutputTTL;
int frequency;
bool msbRising;
int noise;
int noNoise;
int noNoiseOrNoise;
int noPulse;
int output;
int pulse;
int pulseWidth;
bool ringMod;
int ringMsbMask;
int shiftRegister;
int shiftRegisterReset;
bool sync;
bool test;
int[] wave;
int waveform;
int waveformIndex;
int[][] waveTable;
public Voice(int[][] newWaveTable)
{
@ -584,28 +584,28 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public Sound.Utilities.SpeexResampler resampler;
protected static int[] syncNextTable = new int[] { 1, 2, 0 };
protected static int[] syncPrevTable = new int[] { 2, 0, 1 };
static int[] syncNextTable = new int[] { 1, 2, 0 };
static int[] syncPrevTable = new int[] { 2, 0, 1 };
protected int cachedCycles;
protected bool disableVoice3;
protected int[] envelopeOutput;
protected Envelope[] envelopes;
protected bool[] filterEnable;
protected int filterFrequency;
protected int filterResonance;
protected bool filterSelectBandPass;
protected bool filterSelectLoPass;
protected bool filterSelectHiPass;
protected int mixer;
protected int potCounter;
protected int potX;
protected int potY;
protected short sample;
protected int[] voiceOutput;
protected Voice[] voices;
protected int volume;
protected int[][] waveformTable;
int cachedCycles;
bool disableVoice3;
int[] envelopeOutput;
Envelope[] envelopes;
bool[] filterEnable;
int filterFrequency;
int filterResonance;
bool filterSelectBandPass;
bool filterSelectLoPass;
bool filterSelectHiPass;
int mixer;
int potCounter;
int potX;
int potY;
short sample;
int[] voiceOutput;
Voice[] voices;
int volume;
int[][] waveformTable;
public Func<byte> ReadPotX;
public Func<byte> ReadPotY;

View File

@ -2,91 +2,4 @@
namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
// base class for MOS Technology timer chips
public abstract class Timer
{
public byte PortAMask = 0xFF;
public byte PortBMask = 0xFF;
protected bool pinIRQ;
protected LatchedPort portA;
protected LatchedPort portB;
protected int[] timer;
protected int[] timerLatch;
protected bool[] timerOn;
protected bool[] underflow;
public Func<byte> ReadPortA = (() => { return 0xFF; });
public Func<byte> ReadPortB = (() => { return 0xFF; });
public Timer()
{
portA = new LatchedPort();
portB = new LatchedPort();
timer = new int[2];
timerLatch = new int[2];
timerOn = new bool[2];
underflow = new bool[2];
}
protected void HardResetInternal()
{
timer[0] = 0xFFFF;
timer[1] = 0xFFFF;
timerLatch[0] = timer[0];
timerLatch[1] = timer[1];
pinIRQ = true;
}
public byte PortAData
{
get
{
return portA.ReadOutput();
}
}
public byte PortADirection
{
get
{
return portA.Direction;
}
}
public byte PortALatch
{
get
{
return portA.Latch;
}
}
public byte PortBData
{
get
{
return portB.ReadOutput();
}
}
public byte PortBDirection
{
get
{
return portB.Direction;
}
}
public byte PortBLatch
{
get
{
return portB.Latch;
}
}
public bool ReadIRQBuffer() { return pinIRQ; }
}
}

View File

@ -7,7 +7,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
sealed public partial class Vic
{
public const int baResetCounter = 6;
public const int baResetCounter = 7;
public const int pipelineUpdateVc = 1;
public const int pipelineChkSprChunch = 2;
public const int pipelineUpdateMcBase = 4;
@ -19,18 +19,19 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public const int pipelineChkBrdR1 = 256;
public const int pipelineChkSprDisp = 512;
public const int pipelineUpdateRc = 1024;
public const int pipelineHoldX = 0x40000000;
public const int rasterIrqLine0Cycle = 1;
public const int rasterIrqLineXCycle = 0;
protected int parseaddr;
protected int parsecycleBAsprite0;
protected int parsecycleBAsprite1;
protected int parsecycleBAsprite2;
protected int parsecycleFetchSpriteIndex;
protected int parsefetch;
protected int parsefetchType;
protected int parseba;
protected int parseact;
int parseaddr;
int parsecycleBAsprite0;
int parsecycleBAsprite1;
int parsecycleBAsprite2;
int parsecycleFetchSpriteIndex;
int parsefetch;
int parsefetchType;
int parseba;
int parseact;
private void ParseCycle()
{
@ -111,140 +112,136 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
else
{
parsecycleFetchSpriteIndex = (parsefetch & 0x7);
switch (parsefetch & 0xF0)
if ((parsefetch & 0xF0) == 0)
{
case 0x00:
// fetch P
parseaddr = (0x3F8 | (pointerVM << 10) | parsecycleFetchSpriteIndex);
sprites[parsecycleFetchSpriteIndex].pointer = ReadMemory(parseaddr);
sprites[parsecycleFetchSpriteIndex].shiftEnable = false;
break;
case 0x10:
case 0x20:
case 0x30:
// fetch S
if (sprites[parsecycleFetchSpriteIndex].dma)
{
Sprite spr = sprites[parsecycleFetchSpriteIndex];
parseaddr = (spr.mc | (spr.pointer << 6));
spr.sr <<= 8;
spr.sr |= ReadMemory(parseaddr);
spr.mc++;
}
break;
// fetch P
parseaddr = (0x3F8 | (pointerVM << 10) | parsecycleFetchSpriteIndex);
sprites[parsecycleFetchSpriteIndex].pointer = ReadMemory(parseaddr);
sprites[parsecycleFetchSpriteIndex].shiftEnable = false;
}
else
{
// fetch S
if (sprites[parsecycleFetchSpriteIndex].dma)
{
Sprite spr = sprites[parsecycleFetchSpriteIndex];
parseaddr = (spr.mc | (spr.pointer << 6));
spr.sr <<= 8;
spr.sr |= ReadMemory(parseaddr);
spr.mc++;
}
}
}
// perform BA flag manipulation
switch (parseba)
if (parseba == 0x0000)
{
case 0x0000:
pinBA = true;
}
else if (parseba == 0x1000)
{
pinBA = !badline;
}
else
{
parsecycleBAsprite0 = (parseba & 0x000F);
parsecycleBAsprite1 = (parseba & 0x00F0) >> 4;
parsecycleBAsprite2 = (parseba & 0x0F00) >> 8;
if ((parsecycleBAsprite0 < 8 && sprites[parsecycleBAsprite0].dma) ||
(parsecycleBAsprite1 < 8 && sprites[parsecycleBAsprite1].dma) ||
(parsecycleBAsprite2 < 8 && sprites[parsecycleBAsprite2].dma))
pinBA = false;
else
pinBA = true;
break;
case 0x1000:
pinBA = !badline;
break;
default:
parsecycleBAsprite0 = (parseba & 0x000F);
parsecycleBAsprite1 = (parseba & 0x00F0) >> 4;
parsecycleBAsprite2 = (parseba & 0x0F00) >> 8;
if ((parsecycleBAsprite0 < 8 && sprites[parsecycleBAsprite0].dma) ||
(parsecycleBAsprite1 < 8 && sprites[parsecycleBAsprite1].dma) ||
(parsecycleBAsprite2 < 8 && sprites[parsecycleBAsprite2].dma))
pinBA = false;
else
pinBA = true;
break;
}
// perform actions
borderCheckLEnable = true;
borderCheckREnable = true;
borderCheckLEnable = ((parseact & (pipelineChkBrdL0 | pipelineChkBrdL1)) != 0);
borderCheckREnable = ((parseact & (pipelineChkBrdR0 | pipelineChkBrdR1)) != 0);
rasterXHold = ((parseact & pipelineHoldX) != 0);
if ((parseact & pipelineChkSprChunch) != 0)
if (parseact != 0)
{
//for (int i = 0; i < 8; i++)
foreach (Sprite spr in sprites)
if ((parseact & pipelineChkSprChunch) != 0)
{
//Sprite spr = sprites[i];
if (spr.yCrunch)
spr.mcbase += 2;
spr.shiftEnable = false;
spr.xCrunch = !spr.xExpand;
spr.multicolorCrunch = !spr.multicolor;
}
}
if ((parseact & pipelineChkSprDisp) != 0)
{
//for (int i = 0; i < 8; i++)
foreach (Sprite spr in sprites)
{
//Sprite spr = sprites[i];
spr.mc = spr.mcbase;
if (spr.dma && spr.y == (rasterLine & 0xFF))
foreach (Sprite spr in sprites)
{
spr.display = true;
if (spr.yCrunch)
spr.mcbase += 2;
spr.shiftEnable = false;
spr.xCrunch = !spr.xExpand;
spr.multicolorCrunch = !spr.multicolor;
}
}
}
if ((parseact & pipelineChkSprDma) != 0)
{
//for (int i = 0; i < 8; i++)
foreach (Sprite spr in sprites)
else if ((parseact & pipelineChkSprDisp) != 0)
{
//Sprite spr = sprites[i];
if (spr.enable && spr.y == (rasterLine & 0xFF) && !spr.dma)
foreach (Sprite spr in sprites)
{
spr.dma = true;
spr.mcbase = 0;
spr.yCrunch = !spr.yExpand;
}
}
}
if ((parseact & pipelineChkSprExp) != 0)
{
if (sprites[0].yExpand) sprites[0].yCrunch ^= true;
if (sprites[1].yExpand) sprites[1].yCrunch ^= true;
if (sprites[2].yExpand) sprites[2].yCrunch ^= true;
if (sprites[3].yExpand) sprites[3].yCrunch ^= true;
if (sprites[4].yExpand) sprites[4].yCrunch ^= true;
if (sprites[5].yExpand) sprites[5].yCrunch ^= true;
if (sprites[6].yExpand) sprites[6].yCrunch ^= true;
if (sprites[7].yExpand) sprites[7].yCrunch ^= true;
}
if ((parseact & pipelineUpdateMcBase) != 0)
{
//for (int i = 0; i < 8; i++)
foreach (Sprite spr in sprites)
{
//Sprite spr = sprites[i];
if (spr.yCrunch)
{
spr.mcbase++;
if (spr.mcbase == 63)
spr.mc = spr.mcbase;
if (spr.dma && spr.y == (rasterLine & 0xFF))
{
spr.dma = false;
spr.display = false;
spr.display = true;
}
}
}
}
if ((parseact & pipelineUpdateRc) != 0)
{
if (rc == 7)
else if ((parseact & pipelineChkSprDma) != 0)
{
idle = true;
vcbase = vc;
foreach (Sprite spr in sprites)
{
if (spr.enable && spr.y == (rasterLine & 0xFF) && !spr.dma)
{
spr.dma = true;
spr.mcbase = 0;
spr.yCrunch = !spr.yExpand;
}
}
}
else if ((parseact & pipelineChkSprExp) != 0)
{
foreach (Sprite spr in sprites)
{
if (spr.yExpand)
spr.yCrunch ^= true;
}
}
else if ((parseact & pipelineUpdateMcBase) != 0)
{
foreach (Sprite spr in sprites)
{
if (spr.yCrunch)
{
spr.mcbase++;
if (spr.mcbase == 63)
{
spr.dma = false;
spr.display = false;
}
}
}
}
else if ((parseact & pipelineUpdateRc) != 0)
{
if (rc == 7)
{
idle = true;
vcbase = vc;
}
if (!idle)
rc = (rc + 1) & 0x7;
}
else if ((parseact & pipelineUpdateVc) != 0)
{
vc = vcbase;
vmli = 0;
if (badline)
rc = 0;
}
if (!idle)
rc = (rc + 1) & 0x7;
}
if ((parseact & pipelineUpdateVc) != 0)
{
vc = vcbase;
vmli = 0;
if (badline)
rc = 0;
}
cycleIndex++;

View File

@ -7,21 +7,21 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
sealed public partial class Vic
{
protected int ecmPixel;
protected int pixel;
protected int[] pixelBackgroundBuffer;
protected int pixelBackgroundBufferDelay;
protected int pixelBackgroundBufferIndex;
protected int[] pixelBuffer;
protected int pixelBufferDelay;
protected int pixelBufferIndex;
protected int pixelData;
protected int pixelOwner;
protected int sprData;
protected int sprPixel;
protected VicVideoMode videoMode;
int ecmPixel;
int pixel;
int[] pixelBackgroundBuffer;
int pixelBackgroundBufferDelay;
int pixelBackgroundBufferIndex;
int[] pixelBuffer;
int pixelBufferDelay;
int pixelBufferIndex;
int pixelData;
int pixelOwner;
int sprData;
int sprPixel;
VicVideoMode videoMode;
protected enum VicVideoMode : int
enum VicVideoMode : int
{
Mode000,
Mode001,
@ -37,18 +37,22 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
for (int i = 0; i < 4; i++)
{
if (borderCheckLEnable && rasterX == borderL)
if (borderCheckLEnable)
{
if (rasterLine == borderB)
borderOnVertical = true;
if (rasterLine == borderT && displayEnable)
borderOnVertical = false;
if (!borderOnVertical)
borderOnMain = false;
if (rasterX == borderL)
{
if (rasterLine == borderB)
borderOnVertical = true;
if (rasterLine == borderT && displayEnable)
borderOnVertical = false;
if (!borderOnVertical)
borderOnMain = false;
}
}
if (borderCheckREnable && rasterX == borderR)
if (borderCheckREnable)
{
borderOnMain = true;
if (rasterX == borderR)
borderOnMain = true;
}
// recall pixel from buffer
@ -91,14 +95,14 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
if (spr.multicolor)
{
sprData = (spr.sr & 0xC00000);
if (spr.multicolorCrunch && spr.xCrunch)
if (spr.multicolorCrunch && spr.xCrunch && !rasterXHold)
spr.sr <<= 2;
spr.multicolorCrunch ^= spr.xCrunch;
}
else
{
sprData = (spr.sr & 0x800000);
if (spr.xCrunch)
if (spr.xCrunch && !rasterXHold)
spr.sr <<= 1;
}
spr.xCrunch ^= spr.xExpand;

View File

@ -7,7 +7,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
sealed public partial class Vic
{
protected class Sprite
class Sprite
{
public bool collideData;
public bool collideSprite;

View File

@ -8,72 +8,73 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
sealed public partial class Vic
{
protected int backgroundColor0;
protected int backgroundColor1;
protected int backgroundColor2;
protected int backgroundColor3;
protected int baCount;
protected bool badline;
protected bool badlineEnable;
protected int bitmapColumn;
protected bool bitmapMode;
protected int borderB;
protected bool borderCheckLEnable;
protected bool borderCheckREnable;
protected int borderColor;
protected int borderL;
protected bool borderOnMain;
protected bool borderOnVertical;
protected int borderR;
protected int borderT;
protected int[] bufferC;
protected int[] bufferG;
protected int cycle;
protected int cycleIndex;
protected bool columnSelect;
protected int dataC;
protected int dataG;
protected bool debugScreen;
protected bool displayEnable;
protected int displayIndex;
protected int displayC;
protected bool enableIntLightPen;
protected bool enableIntRaster;
protected bool enableIntSpriteCollision;
protected bool enableIntSpriteDataCollision;
protected bool extraColorMode;
protected bool idle;
protected bool intLightPen;
protected bool intRaster;
protected bool intSpriteCollision;
protected bool intSpriteDataCollision;
protected int lastRasterLine;
protected int lightPenX;
protected int lightPenY;
protected bool multicolorMode;
protected bool pinAEC = true;
protected bool pinBA = true;
protected bool pinIRQ = true;
protected int[] pixelDataBuffer;
protected int pointerCB;
protected int pointerVM;
protected int rasterInterruptLine;
protected int rasterLine;
protected int rasterX;
protected int rc;
protected int refreshCounter;
protected bool renderEnabled;
protected bool rowSelect;
protected int spriteMulticolor0;
protected int spriteMulticolor1;
protected Sprite[] sprites;
protected int sr;
protected int vc;
protected int vcbase;
protected int vmli;
protected int xOffset;
protected int xScroll;
protected int yScroll;
int backgroundColor0;
int backgroundColor1;
int backgroundColor2;
int backgroundColor3;
int baCount;
bool badline;
bool badlineEnable;
int bitmapColumn;
bool bitmapMode;
int borderB;
bool borderCheckLEnable;
bool borderCheckREnable;
int borderColor;
int borderL;
bool borderOnMain;
bool borderOnVertical;
int borderR;
int borderT;
int[] bufferC;
int[] bufferG;
int cycle;
int cycleIndex;
bool columnSelect;
int dataC;
int dataG;
bool debugScreen;
bool displayEnable;
int displayIndex;
int displayC;
bool enableIntLightPen;
bool enableIntRaster;
bool enableIntSpriteCollision;
bool enableIntSpriteDataCollision;
bool extraColorMode;
bool idle;
bool intLightPen;
bool intRaster;
bool intSpriteCollision;
bool intSpriteDataCollision;
int lastRasterLine;
int lightPenX;
int lightPenY;
bool multicolorMode;
bool pinAEC = true;
bool pinBA = true;
bool pinIRQ = true;
int[] pixelDataBuffer;
int pointerCB;
int pointerVM;
int rasterInterruptLine;
int rasterLine;
int rasterX;
bool rasterXHold;
int rc;
int refreshCounter;
bool renderEnabled;
bool rowSelect;
int spriteMulticolor0;
int spriteMulticolor1;
Sprite[] sprites;
int sr;
int vc;
int vcbase;
int vmli;
int xOffset;
int xScroll;
int yScroll;
public void HardReset()
{

View File

@ -7,10 +7,61 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
sealed public partial class Vic
{
static int[] TimingBuilder_Cycle14Act = new int[]
{
pipelineUpdateVc, 0,
pipelineChkSprChunch, 0,
pipelineUpdateMcBase, 0,
};
static int[] TimingBuilder_Cycle55Act = new int[]
{
pipelineChkSprDma, 0,
pipelineChkSprDma, pipelineChkSprExp,
0, 0,
pipelineChkSprDisp, pipelineUpdateRc
};
static public int[] TimingBuilder_Act(int[] timing, int cycle14, int cycle55)
{
List<int> result = new List<int>();
int length = timing.Length;
for (int i = 0; i < length; i++)
{
while (i < result.Count)
i++;
if (timing[i] == cycle14)
result.AddRange(TimingBuilder_Cycle14Act);
else if (timing[i] == cycle55)
result.AddRange(TimingBuilder_Cycle55Act);
else
result.Add(0);
}
for (int i = 0; i < length; i++)
{
// pipeline raster X delay
if (timing[(i + 1) % length] == timing[i])
result[i] |= pipelineHoldX;
// pipeline border checks
if (timing[i] == 0x01C)
result[i] |= pipelineChkBrdL1;
if (timing[i] == 0x020)
result[i] |= pipelineChkBrdL0;
if (timing[i] == 0x150)
result[i] |= pipelineChkBrdR0;
if (timing[i] == 0x15C)
result[i] |= pipelineChkBrdR1;
}
return result.ToArray();
}
static public int[] TimingBuilder_BA(int[] fetch)
{
int baRestart = 7;
int bacounter = 0;
int start = 0;
int length = fetch.Length;
int[] result = new int[length];
@ -151,6 +202,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
int rasterX = start;
bool delayed = false;
count >>= 2;
delayAmount >>= 2;
for (int i = 0; i < count; i++)
{

View File

@ -4,16 +4,16 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{
sealed public partial class Vic : IVideoProvider
{
protected int[] buf;
protected int bufHeight;
protected int bufLength;
protected int bufOffset;
protected Point bufPoint;
protected Rectangle bufRect;
protected int bufWidth;
int[] buf;
int bufHeight;
int bufLength;
int bufOffset;
Point bufPoint;
Rectangle bufRect;
int bufWidth;
// palette
protected int[] palette =
int[] palette =
{
Colors.ARGB(0x00, 0x00, 0x00),
Colors.ARGB(0xFF, 0xFF, 0xFF),

View File

@ -12,10 +12,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public bool ReadBABuffer() { return pinBA; }
public bool ReadIRQBuffer() { return pinIRQ; }
protected int cyclesPerSec;
protected int[][] pipeline;
protected int totalCycles;
protected int totalLines;
int cyclesPerSec;
int irqShift;
int[][] pipeline;
int totalCycles;
int totalLines;
public Vic(int newCycles, int newLines, int[][] newPipeline, int newCyclesPerSec)
{
@ -125,7 +126,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
pinAEC = false;
// must always come last
UpdatePins();
//UpdatePins();
}
}
@ -166,21 +167,20 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
private void UpdateBA()
{
{
if (pinBA)
baCount = baResetCounter;
else if (baCount > 0)
baCount--;
}
if (pinBA)
baCount = baResetCounter;
else if (baCount > 0)
baCount--;
}
private void UpdateBorder()
{
{
borderL = columnSelect ? 0x018 : 0x01F;
borderR = columnSelect ? 0x158 : 0x14F;
//borderL = columnSelect ? 0x018 : 0x01F;
//borderR = columnSelect ? 0x158 : 0x14F;
borderL = columnSelect ? 28 : 35;
borderR = columnSelect ? 348 : 339;
borderT = rowSelect ? 0x033 : 0x037;
borderB = rowSelect ? 0x0FB : 0x0F7;
}
@ -188,14 +188,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
private void UpdatePins()
{
{
pinIRQ = !(
(enableIntRaster & intRaster) |
(enableIntSpriteDataCollision & intSpriteDataCollision) |
(enableIntSpriteCollision & intSpriteCollision) |
(enableIntLightPen & intLightPen));
}
bool irqTemp = !(
(enableIntRaster & intRaster) |
(enableIntSpriteDataCollision & intSpriteDataCollision) |
(enableIntSpriteCollision & intSpriteCollision) |
(enableIntLightPen & intLightPen));
irqShift <<= 1;
irqShift |= (irqTemp ? 0x1 : 0x0);
pinIRQ = (irqShift & 0x2) != 0;
}
private void UpdateVideoMode()