Cleanup namespaces in C64

This commit is contained in:
adelikat 2013-11-12 19:22:09 +00:00
parent aaf5f17df8
commit 6f2bd4eca3
89 changed files with 3466 additions and 3486 deletions

View File

@ -12,7 +12,7 @@ using BizHawk.Common;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Emulation; using BizHawk.Emulation;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Computers.Commodore64; using BizHawk.Emulation.Cores.Computers.Commodore64;
using BizHawk.Emulation.Cores.Calculator; using BizHawk.Emulation.Cores.Calculator;
using BizHawk.Emulation.Consoles.Coleco; using BizHawk.Emulation.Consoles.Coleco;
using BizHawk.Emulation.Consoles.GB; using BizHawk.Emulation.Consoles.GB;

View File

@ -2,12 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Computers.Commodore64.Cartridge;
using BizHawk.Emulation.Computers.Commodore64.Disk;
using BizHawk.Emulation.Computers.Commodore64.MOS;
namespace BizHawk.Emulation.Cores.Computers.Commodore64
namespace BizHawk.Emulation.Computers.Commodore64
{ {
public enum Region public enum Region
{ {

View File

@ -1,6 +1,4 @@
using BizHawk.Emulation.Computers.Commodore64.MOS; namespace BizHawk.Emulation.Cores.Computers.Commodore64
namespace BizHawk.Emulation.Computers.Commodore64
{ {
sealed public partial class Motherboard sealed public partial class Motherboard
{ {
@ -28,48 +26,48 @@ namespace BizHawk.Emulation.Computers.Commodore64
static private byte[] inputBitMask = new byte[] { 0xFE, 0xFD, 0xFB, 0xF7, 0xEF, 0xDF, 0xBF, 0x7F }; 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 }; static private byte[] inputBitSelect = new byte[] { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
byte cia0InputLatchA; byte cia0InputLatchA;
byte cia0InputLatchB; byte cia0InputLatchB;
int pollIndex; int pollIndex;
public void PollInput() public void PollInput()
{ {
// scan joysticks // scan joysticks
pollIndex = 0; pollIndex = 0;
for (int j = 0; j < 5; j++) for (int j = 0; j < 5; j++)
{ {
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
joystickPressed[pollIndex++] = controller[joystickMatrix[i, j]] ? -1 : 0; joystickPressed[pollIndex++] = controller[joystickMatrix[i, j]] ? -1 : 0;
} }
} }
// scan keyboard // scan keyboard
pollIndex = 0; pollIndex = 0;
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
for (int j = 0; j < 8; j++) for (int j = 0; j < 8; j++)
{ {
keyboardPressed[pollIndex++] = controller[keyboardMatrix[i, j]] ? -1 : 0; keyboardPressed[pollIndex++] = controller[keyboardMatrix[i, j]] ? -1 : 0;
} }
} }
} }
private void WriteInputPort() private void WriteInputPort()
{ {
byte portA = cia0.PortAData; byte portA = cia0.PortAData;
byte portB = cia0.PortBData; byte portB = cia0.PortBData;
byte resultA = 0xFF; byte resultA = 0xFF;
byte resultB = 0xFF; byte resultB = 0xFF;
byte joyA = 0xFF; byte joyA = 0xFF;
byte joyB = 0xFF; byte joyB = 0xFF;
pollIndex = 0; pollIndex = 0;
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
for (int j = 0; j < 8; j++) for (int j = 0; j < 8; j++)
{ {
if (keyboardPressed[pollIndex++] != 0) if (keyboardPressed[pollIndex++] != 0)
{ {
if (((portA & inputBitSelect[i]) == 0) || ((portB & inputBitSelect[j]) == 0)) if (((portA & inputBitSelect[i]) == 0) || ((portB & inputBitSelect[j]) == 0))
{ {
@ -80,23 +78,23 @@ namespace BizHawk.Emulation.Computers.Commodore64
} }
} }
pollIndex = 0; pollIndex = 0;
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
if (joystickPressed[pollIndex++] != 0) if (joystickPressed[pollIndex++] != 0)
joyB &= inputBitMask[i]; joyB &= inputBitMask[i];
if (joystickPressed[pollIndex++] != 0) if (joystickPressed[pollIndex++] != 0)
joyA &= inputBitMask[i]; joyA &= inputBitMask[i];
} }
resultA &= joyA; resultA &= joyA;
resultB &= joyB; resultB &= joyB;
cia0InputLatchA = resultA; cia0InputLatchA = resultA;
cia0InputLatchB = resultB; cia0InputLatchB = resultB;
// this joystick has special rules. // this joystick has special rules.
cia0.PortAMask = joyA; cia0.PortAMask = joyA;
} }
} }
} }

View File

@ -1,10 +1,9 @@
using BizHawk.Emulation.Computers.Commodore64.MOS; using System.Reflection;
using System.Reflection;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Computers.Commodore64 namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
/// <summary> /// <summary>
/// Contains the onboard chipset and glue. /// Contains the onboard chipset and glue.

View File

@ -1,141 +1,139 @@
using BizHawk.Emulation.Computers.Commodore64.MOS; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64 namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Motherboard sealed public partial class Motherboard
{ {
bool CassPort_ReadDataOutput() bool CassPort_ReadDataOutput()
{ {
return (cpu.PortData & 0x08) != 0; return (cpu.PortData & 0x08) != 0;
} }
bool CassPort_ReadMotor() bool CassPort_ReadMotor()
{ {
return (cpu.PortData & 0x20) != 0; return (cpu.PortData & 0x20) != 0;
} }
bool Cia0_ReadCnt() bool Cia0_ReadCnt()
{ {
return (userPort.ReadCounter1Buffer() && cia0.ReadCNTBuffer()); return (userPort.ReadCounter1Buffer() && cia0.ReadCNTBuffer());
} }
byte Cia0_ReadPortA() byte Cia0_ReadPortA()
{ {
return cia0InputLatchA; return cia0InputLatchA;
} }
byte Cia0_ReadPortB() byte Cia0_ReadPortB()
{ {
return cia0InputLatchB; return cia0InputLatchB;
} }
bool Cia0_ReadSP() bool Cia0_ReadSP()
{ {
return (userPort.ReadSerial1Buffer() && cia0.ReadSPBuffer()); return (userPort.ReadSerial1Buffer() && cia0.ReadSPBuffer());
} }
bool Cia1_ReadCnt() bool Cia1_ReadCnt()
{ {
return (userPort.ReadCounter2Buffer() && cia1.ReadCNTBuffer()); return (userPort.ReadCounter2Buffer() && cia1.ReadCNTBuffer());
} }
byte Cia1_ReadPortA() byte Cia1_ReadPortA()
{ {
// the low bits are actually the VIC memory address. // the low bits are actually the VIC memory address.
byte result = 0xFF; byte result = 0xFF;
if (serPort.WriteDataIn()) if (serPort.WriteDataIn())
result &= 0x7F; result &= 0x7F;
if (serPort.WriteClockIn()) if (serPort.WriteClockIn())
result &= 0xBF; result &= 0xBF;
return result; return result;
} }
bool Cia1_ReadSP() bool Cia1_ReadSP()
{ {
return (userPort.ReadSerial2Buffer() && cia1.ReadSPBuffer()); return (userPort.ReadSerial2Buffer() && cia1.ReadSPBuffer());
} }
byte Cpu_ReadPort() byte Cpu_ReadPort()
{ {
byte data = 0x1F; byte data = 0x1F;
if (!cassPort.ReadSenseBuffer()) if (!cassPort.ReadSenseBuffer())
data &= 0xEF; data &= 0xEF;
return data; return data;
} }
bool Glue_ReadIRQ() bool Glue_ReadIRQ()
{ {
return cia0.ReadIRQBuffer() & vic.ReadIRQBuffer() & cartPort.ReadIRQBuffer(); return cia0.ReadIRQBuffer() & vic.ReadIRQBuffer() & cartPort.ReadIRQBuffer();
} }
bool Pla_ReadCharen() bool Pla_ReadCharen()
{ {
return (cpu.PortData & 0x04) != 0; return (cpu.PortData & 0x04) != 0;
} }
byte Pla_ReadCia0(int addr) byte Pla_ReadCia0(int addr)
{ {
if (addr == 0xDC00 || addr == 0xDC01) if (addr == 0xDC00 || addr == 0xDC01)
{ {
WriteInputPort(); WriteInputPort();
inputRead = true; inputRead = true;
} }
return cia0.Read(addr); return cia0.Read(addr);
} }
byte Pla_ReadColorRam(int addr) byte Pla_ReadColorRam(int addr)
{ {
byte result = bus; byte result = bus;
result &= 0xF0; result &= 0xF0;
result |= colorRam.Read(addr); result |= colorRam.Read(addr);
return result; return result;
} }
bool Pla_ReadHiRam() bool Pla_ReadHiRam()
{ {
return (cpu.PortData & 0x02) != 0; return (cpu.PortData & 0x02) != 0;
} }
bool Pla_ReadLoRam() bool Pla_ReadLoRam()
{ {
return (cpu.PortData & 0x01) != 0; return (cpu.PortData & 0x01) != 0;
} }
bool SerPort_ReadAtnOut() bool SerPort_ReadAtnOut()
{ {
return (cia1.PortBData & 0x08) == 0; return (cia1.PortBData & 0x08) == 0;
} }
bool SerPort_ReadClockOut() bool SerPort_ReadClockOut()
{ {
return (cia1.PortAData & 0x10) == 0; return (cia1.PortAData & 0x10) == 0;
} }
bool SerPort_ReadDataOut() bool SerPort_ReadDataOut()
{ {
return (cia1.PortAData & 0x20) == 0; return (cia1.PortAData & 0x20) == 0;
} }
byte Sid_ReadPotX() byte Sid_ReadPotX()
{ {
return 0; return 0;
} }
byte Sid_ReadPotY() byte Sid_ReadPotY()
{ {
return 0; return 0;
} }
byte Vic_ReadMemory(int addr) byte Vic_ReadMemory(int addr)
{ {
// the system sees (cia1.PortAData & 0x3) but we use a shortcut // the system sees (cia1.PortAData & 0x3) but we use a shortcut
addr |= (0x3 - (((cia1.PortALatch & cia1.PortADirection) | (~cia1.PortADirection)) & 0x3)) << 14; addr |= (0x3 - (((cia1.PortALatch & cia1.PortADirection) | (~cia1.PortADirection)) & 0x3)) << 14;
return pla.VicRead(addr); return pla.VicRead(addr);
} }
} }
} }

View File

@ -3,7 +3,7 @@
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Computers.Commodore64 namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class C64 : IEmulator sealed public partial class C64 : IEmulator
{ {

View File

@ -4,7 +4,7 @@ using System.IO;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Computers.Commodore64 namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class C64 : IEmulator sealed public partial class C64 : IEmulator
{ {
@ -118,7 +118,7 @@ namespace BizHawk.Emulation.Computers.Commodore64
// board.ram.Poke(0x0039, inputFileInfo.Data[4]); // board.ram.Poke(0x0039, inputFileInfo.Data[4]);
// board.ram.Poke(0x003A, inputFileInfo.Data[5]); // board.ram.Poke(0x003A, inputFileInfo.Data[5]);
//} //}
Media.PRG.Load(board.pla, inputFileInfo.Data); PRG.Load(board.pla, inputFileInfo.Data);
loadPrg = false; loadPrg = false;
} }
} }

View File

@ -4,7 +4,7 @@ using System.IO;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Cartridge namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// this is the base cartridge class // this is the base cartridge class

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace BizHawk.Emulation.Computers.Commodore64.Cartridge namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public class Mapper0000 : Cart public class Mapper0000 : Cart
{ {

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Cartridge namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public class Mapper0005 : Cart public class Mapper0005 : Cart
{ {

View File

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace BizHawk.Emulation.Computers.Commodore64.Cartridge namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// Westermann Learning mapper. // Westermann Learning mapper.
// Starts up with both banks enabled, any read to DFxx // Starts up with both banks enabled, any read to DFxx

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Cartridge namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// This is a mapper used commonly by System 3. It is // This is a mapper used commonly by System 3. It is
// also utilized by the short-lived C64 Game System. // also utilized by the short-lived C64 Game System.

View File

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace BizHawk.Emulation.Computers.Commodore64.Cartridge namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// This mapper comes from Dinamic. It is in fact identical // This mapper comes from Dinamic. It is in fact identical
// to the System 3 mapper (000F) except that bank switching is // to the System 3 mapper (000F) except that bank switching is

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Cartridge namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public class Mapper0012 : Cart public class Mapper0012 : Cart
{ {

View File

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Cartridge namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// Mapper for a few Domark and HES Australia games. // Mapper for a few Domark and HES Australia games.
// It seems a lot of people dumping these have remapped // It seems a lot of people dumping these have remapped

View File

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Cartridge namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// EasyFlash cartridge // EasyFlash cartridge
// No official games came on one of these but there // No official games came on one of these but there

View File

@ -1,6 +1,6 @@
using System; using System;
namespace BizHawk.Emulation.Computers.Commodore64.Disk namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public class VIC1541PLA public class VIC1541PLA
{ {

View File

@ -1,10 +1,9 @@
using BizHawk.Emulation.CPUs.M6502; using System;
using BizHawk.Emulation.Computers.Commodore64.MOS; using BizHawk.Emulation.CPUs.M6502;
using System;
#if false #if false
namespace BizHawk.Emulation.Computers.Commodore64.Disk namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public class VIC1541 public class VIC1541
{ {

View File

@ -3,159 +3,159 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public sealed partial class C64 public sealed partial class C64
{ {
public void InitializeConnections() public void InitializeConnections()
{ {
cia1.InputCNT = user.OutputCNT1; cia1.InputCNT = user.OutputCNT1;
cia1.InputFlag = ReadCia1Flag; cia1.InputFlag = ReadCia1Flag;
cia1.InputPortA = ReadCia1PortA; cia1.InputPortA = ReadCia1PortA;
cia1.InputPortB = ReadCia1PortB; cia1.InputPortB = ReadCia1PortB;
cia1.InputSP = user.OutputSP1; cia1.InputSP = user.OutputSP1;
cia2.InputCNT = user.OutputCNT2; cia2.InputCNT = user.OutputCNT2;
cia2.InputFlag = user.OutputFLAG2; cia2.InputFlag = user.OutputFLAG2;
cia2.InputPortA = ReadCia2PortA; cia2.InputPortA = ReadCia2PortA;
cia2.InputPortB = user.OutputData; cia2.InputPortB = user.OutputData;
cia2.InputSP = user.OutputSP2; cia2.InputSP = user.OutputSP2;
cpu.InputAEC = vic.OutputAEC; cpu.InputAEC = vic.OutputAEC;
cpu.InputIRQ = ReadIRQ; cpu.InputIRQ = ReadIRQ;
cpu.InputNMI = ReadNMI; cpu.InputNMI = ReadNMI;
cpu.InputPort = ReadCPUPort; cpu.InputPort = ReadCPUPort;
cpu.InputRDY = vic.OutputBA; cpu.InputRDY = vic.OutputBA;
cpu.ReadMemory = pla.ReadMemory; cpu.ReadMemory = pla.ReadMemory;
cpu.WriteMemory = pla.WriteMemory; cpu.WriteMemory = pla.WriteMemory;
//expansion.InputBA = vic.OutputBA; //expansion.InputBA = vic.OutputBA;
//expansion.InputData = ReadData; //expansion.InputData = ReadData;
//expansion.InputHiExpansion = ReadHiExpansion; //expansion.InputHiExpansion = ReadHiExpansion;
//expansion.InputHiRom = pla.OutputRomHi; //expansion.InputHiRom = pla.OutputRomHi;
//expansion.InputIRQ = ReadIRQ; //expansion.InputIRQ = ReadIRQ;
//expansion.InputLoExpansion = ReadLoExpansion; //expansion.InputLoExpansion = ReadLoExpansion;
//expansion.InputLoRom = pla.OutputRomLo; //expansion.InputLoRom = pla.OutputRomLo;
//expansion.InputNMI = ReadNMI; //expansion.InputNMI = ReadNMI;
//pla.InputAEC = vic.OutputAEC; //pla.InputAEC = vic.OutputAEC;
//pla.InputBA = vic.OutputBA; //pla.InputBA = vic.OutputBA;
//pla.InputCharen = ReadCharen; //pla.InputCharen = ReadCharen;
//pla.InputExRom = expansion.OutputExRom; //pla.InputExRom = expansion.OutputExRom;
//pla.InputGame = expansion.OutputGame; //pla.InputGame = expansion.OutputGame;
//pla.InputHiRam = ReadHiRam; //pla.InputHiRam = ReadHiRam;
//pla.InputLoRam = ReadLoRam; //pla.InputLoRam = ReadLoRam;
//pla.InputVA = ReadVicAddress; //pla.InputVA = ReadVicAddress;
//serial.InputATN = ReadSerialATN; //serial.InputATN = ReadSerialATN;
//serial.InputClock = ReadSerialCLK; //serial.InputClock = ReadSerialCLK;
//serial.InputData = ReadSerialDTA; //serial.InputData = ReadSerialDTA;
//user.InputCNT1 = cia1.OutputCNT; //user.InputCNT1 = cia1.OutputCNT;
//user.InputCNT2 = cia2.OutputCNT; //user.InputCNT2 = cia2.OutputCNT;
//user.InputData = cia2.OutputPortB; //user.InputData = cia2.OutputPortB;
//user.InputPA2 = ReadUserPA2; //user.InputPA2 = ReadUserPA2;
//user.InputPC2 = cia2.OutputPC; //user.InputPC2 = cia2.OutputPC;
//user.InputSP1 = cia1.OutputSP; //user.InputSP1 = cia1.OutputSP;
//user.InputSP2 = cia2.OutputSP; //user.InputSP2 = cia2.OutputSP;
} }
bool ReadCia1Cnt() bool ReadCia1Cnt()
{ {
// this pin is not connected // this pin is not connected
return true; return true;
} }
bool ReadCia1Flag() bool ReadCia1Flag()
{ {
return serial.SRQ && cassette.Data; return serial.SRQ && cassette.Data;
} }
int ReadCia1PortA() int ReadCia1PortA()
{ {
return joystickB.Data & keyboard.Column; return joystickB.Data & keyboard.Column;
} }
int ReadCia1PortB() int ReadCia1PortB()
{ {
return joystickA.Data & keyboard.Row; return joystickA.Data & keyboard.Row;
} }
int ReadCia2PortA() int ReadCia2PortA()
{ {
int result = 0xFF; int result = 0xFF;
if (!user.PA2) if (!user.PA2)
result &= 0xFB; result &= 0xFB;
if (!serial.Clock) if (!serial.Clock)
result &= 0xBF; result &= 0xBF;
if (!serial.Data) if (!serial.Data)
result &= 0x7F; result &= 0x7F;
return result; return result;
} }
int ReadCPUPort() int ReadCPUPort()
{ {
return 0xFF; return 0xFF;
} }
bool ReadHiExpansion() bool ReadHiExpansion()
{ {
int addr = 0xFFFF; int addr = 0xFFFF;
return (addr >= 0xDF00 && addr < 0xE000); return (addr >= 0xDF00 && addr < 0xE000);
} }
bool ReadIRQ() bool ReadIRQ()
{ {
return ( return (
cia1.IRQ && cia1.IRQ &&
vic.IRQ && vic.IRQ &&
expansion.IRQ expansion.IRQ
); );
} }
bool ReadLoExpansion() bool ReadLoExpansion()
{ {
int addr = 0xFFFF; int addr = 0xFFFF;
return (addr >= 0xDE00 && addr < 0xDF00); return (addr >= 0xDE00 && addr < 0xDF00);
} }
bool ReadLoRam() bool ReadLoRam()
{ {
return (cpu.Port & 0x1) != 0; return (cpu.Port & 0x1) != 0;
} }
bool ReadNMI() bool ReadNMI()
{ {
return ( return (
cia2.IRQ && cia2.IRQ &&
expansion.NMI expansion.NMI
); );
} }
bool ReadSerialATN() bool ReadSerialATN()
{ {
return (cia2.PortA & 0x08) != 0; return (cia2.PortA & 0x08) != 0;
} }
bool ReadSerialCLK() bool ReadSerialCLK()
{ {
return (cia2.PortA & 0x10) != 0; return (cia2.PortA & 0x10) != 0;
} }
bool ReadSerialDTA() bool ReadSerialDTA()
{ {
return (cia2.PortA & 0x20) != 0; return (cia2.PortA & 0x20) != 0;
} }
bool ReadUserPA2() bool ReadUserPA2()
{ {
return (cia2.PortA & 0x04) != 0; return (cia2.PortA & 0x04) != 0;
} }
int ReadVicAddress() int ReadVicAddress()
{ {
//return (vic.Address | ((cia2.PortA & 0x3) << 14)); //return (vic.Address | ((cia2.PortA & 0x3) << 14));
return 0xFFFF; return 0xFFFF;
} }
} }
} }

View File

@ -1,132 +1,131 @@
using BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public sealed partial class C64 : IMotherboard public sealed partial class C64 : IMotherboard
{ {
public Rom basicRom; public Rom basicRom;
public Cassette cassette; public Cassette cassette;
public Rom characterRom; public Rom characterRom;
public Cia cia1; public Cia cia1;
public Cia cia2; public Cia cia2;
public Ram colorRam; public Ram colorRam;
public Cpu cpu; public Cpu cpu;
public Expansion expansion; public Expansion expansion;
public Joystick joystickA; public Joystick joystickA;
public Joystick joystickB; public Joystick joystickB;
public Rom kernalRom; public Rom kernalRom;
public Keyboard keyboard; public Keyboard keyboard;
public Ram memory; public Ram memory;
public Pla pla; public Pla pla;
public Serial serial; public Serial serial;
public Sid sid; public Sid sid;
public Userport user; public Userport user;
public Vic vic; public Vic vic;
public C64(C64Timing timing) public C64(C64Timing timing)
{ {
} }
public void ExecuteFrame() public void ExecuteFrame()
{ {
} }
public byte PeekBasicRom(int addr) public byte PeekBasicRom(int addr)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public byte PeekCartridge(int addr) public byte PeekCartridge(int addr)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public byte PeekCharRom(int addr) public byte PeekCharRom(int addr)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public byte PeekCpu(int addr) public byte PeekCpu(int addr)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public byte PeekKernalRom(int addr) public byte PeekKernalRom(int addr)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public byte PeekRam(int addr) public byte PeekRam(int addr)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public byte PeekSerial(int addr) public byte PeekSerial(int addr)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public byte PeekSid(int addr) public byte PeekSid(int addr)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public byte PeekVic(int addr) public byte PeekVic(int addr)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void PokeBasicRom(int addr, byte val) public void PokeBasicRom(int addr, byte val)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void PokeCartridge(int addr, byte val) public void PokeCartridge(int addr, byte val)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void PokeCharRom(int addr, byte val) public void PokeCharRom(int addr, byte val)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void PokeCpu(int addr, byte val) public void PokeCpu(int addr, byte val)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void PokeKernalRom(int addr, byte val) public void PokeKernalRom(int addr, byte val)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void PokeRam(int addr, byte val) public void PokeRam(int addr, byte val)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void PokeSerial(int addr, byte val) public void PokeSerial(int addr, byte val)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void PokeSid(int addr, byte val) public void PokeSid(int addr, byte val)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public void PokeVic(int addr, byte val) public void PokeVic(int addr, byte val)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }
public class C64Timing public class C64Timing
{ {
} }
} }

View File

@ -1,42 +1,40 @@
using BizHawk.Emulation.Computers.Commodore64.Experimental.Chips; using System;
using BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
static public partial class C64ChipPresets static public partial class C64ChipPresets
{ {
static public C64 NTSC(byte[] basic, byte[] kernal, byte[] character) static public C64 NTSC(byte[] basic, byte[] kernal, byte[] character)
{ {
C64 result = new C64(NTSCTiming()); C64 result = new C64(NTSCTiming());
result.basicRom = ChipPresets.Rom2364(basic); result.basicRom = ChipPresets.Rom2364(basic);
result.cassette = new Cassette(); result.cassette = new Cassette();
result.characterRom = ChipPresets.Rom2332(character); result.characterRom = ChipPresets.Rom2332(character);
result.cia1 = ChipPresets.Cia6526(true); result.cia1 = ChipPresets.Cia6526(true);
result.cia2 = ChipPresets.Cia6526(true); result.cia2 = ChipPresets.Cia6526(true);
result.colorRam = ChipPresets.Ram2114(); result.colorRam = ChipPresets.Ram2114();
result.cpu = new Cpu(); result.cpu = new Cpu();
result.expansion = new Expansion(); result.expansion = new Expansion();
result.joystickA = new Joystick(); result.joystickA = new Joystick();
result.joystickB = new Joystick(); result.joystickB = new Joystick();
result.kernalRom = ChipPresets.Rom2364(kernal); result.kernalRom = ChipPresets.Rom2364(kernal);
result.keyboard = new Keyboard(); result.keyboard = new Keyboard();
result.memory = ChipPresets.Ram4864(); result.memory = ChipPresets.Ram4864();
result.pla = new Pla(); result.pla = new Pla();
result.serial = new Serial(); result.serial = new Serial();
result.sid = ChipPresets.Sid6581(); result.sid = ChipPresets.Sid6581();
result.user = new Userport(); result.user = new Userport();
result.vic = ChipPresets.Vic6567(); result.vic = ChipPresets.Vic6567();
result.InitializeConnections(); result.InitializeConnections();
return result; return result;
} }
static public C64Timing NTSCTiming() static public C64Timing NTSCTiming()
{ {
return new C64Timing(); return new C64Timing();
} }
} }
} }

View File

@ -1,42 +1,40 @@
using BizHawk.Emulation.Computers.Commodore64.Experimental.Chips; using System;
using BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
static public partial class C64ChipPresets static public partial class C64ChipPresets
{ {
static public C64 PAL(byte[] basic, byte[] kernal, byte[] character) static public C64 PAL(byte[] basic, byte[] kernal, byte[] character)
{ {
C64 result = new C64(PALTiming()); C64 result = new C64(PALTiming());
result.basicRom = ChipPresets.Rom2364(basic); result.basicRom = ChipPresets.Rom2364(basic);
result.cassette = new Cassette(); result.cassette = new Cassette();
result.characterRom = ChipPresets.Rom2332(character); result.characterRom = ChipPresets.Rom2332(character);
result.cia1 = ChipPresets.Cia6526(true); result.cia1 = ChipPresets.Cia6526(true);
result.cia2 = ChipPresets.Cia6526(true); result.cia2 = ChipPresets.Cia6526(true);
result.colorRam = ChipPresets.Ram2114(); result.colorRam = ChipPresets.Ram2114();
result.cpu = new Cpu(); result.cpu = new Cpu();
result.expansion = new Expansion(); result.expansion = new Expansion();
result.joystickA = new Joystick(); result.joystickA = new Joystick();
result.joystickB = new Joystick(); result.joystickB = new Joystick();
result.kernalRom = ChipPresets.Rom2364(kernal); result.kernalRom = ChipPresets.Rom2364(kernal);
result.keyboard = new Keyboard(); result.keyboard = new Keyboard();
result.memory = ChipPresets.Ram4864(); result.memory = ChipPresets.Ram4864();
result.pla = new Pla(); result.pla = new Pla();
result.serial = new Serial(); result.serial = new Serial();
result.sid = ChipPresets.Sid6581(); result.sid = ChipPresets.Sid6581();
result.user = new Userport(); result.user = new Userport();
result.vic = ChipPresets.Vic6569(); result.vic = ChipPresets.Vic6569();
result.InitializeConnections(); result.InitializeConnections();
return result; return result;
} }
static public C64Timing PALTiming() static public C64Timing PALTiming()
{ {
return new C64Timing(); return new C64Timing();
} }
} }
} }

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public class Cassette public class Cassette
{ {

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Cia sealed public partial class Cia
{ {

View File

@ -3,17 +3,17 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Cia sealed public partial class Cia
{ {
public Cia(CiaSettings settings) public Cia(CiaSettings settings)
{ {
Reset(); Reset();
} }
public void Reset() public void Reset()
{ {
} }
} }
} }

View File

@ -3,27 +3,27 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Cia sealed public partial class Cia
{ {
public int Peek(int addr) public int Peek(int addr)
{ {
return 0xFF; return 0xFF;
} }
public void Poke(int addr, int val) public void Poke(int addr, int val)
{ {
} }
public int Read(int addr) public int Read(int addr)
{ {
return Peek(addr); return Peek(addr);
} }
public void Write(int addr, int val) public void Write(int addr, int val)
{ {
Poke(addr, val); Poke(addr, val);
} }
} }
} }

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public class CiaSettings public class CiaSettings
{ {
} }
} }

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Cpu sealed public partial class Cpu
{ {

View File

@ -4,87 +4,87 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Cpu sealed public partial class Cpu
{ {
int cachedAddress; int cachedAddress;
int cachedData; int cachedData;
bool cachedNMI; bool cachedNMI;
int delayCycles; int delayCycles;
bool nmiBuffer; bool nmiBuffer;
int portDirection; int portDirection;
int portLatch; int portLatch;
MOS6502X processor; MOS6502X processor;
int resetPC; int resetPC;
public Cpu() public Cpu()
{ {
processor = new MOS6502X(); processor = new MOS6502X();
processor.DummyReadMemory = CoreReadMemory; processor.DummyReadMemory = CoreReadMemory;
processor.ReadMemory = CoreReadMemory; processor.ReadMemory = CoreReadMemory;
processor.WriteMemory = CoreWriteMemory; processor.WriteMemory = CoreWriteMemory;
Reset(); Reset();
} }
public void Clock() public void Clock()
{ {
if (delayCycles > 0) if (delayCycles > 0)
{ {
delayCycles--; delayCycles--;
if (delayCycles == 1) if (delayCycles == 1)
{ {
resetPC = ReadMemory(0xFFFC); resetPC = ReadMemory(0xFFFC);
} }
else if (delayCycles == 0) else if (delayCycles == 0)
{ {
resetPC |= ReadMemory(0xFFFD) << 8; resetPC |= ReadMemory(0xFFFD) << 8;
processor.PC = (ushort)resetPC; processor.PC = (ushort)resetPC;
} }
} }
else else
{ {
if (InputAEC()) if (InputAEC())
{ {
processor.IRQ = !InputIRQ(); //6502 core expects inverted input processor.IRQ = !InputIRQ(); //6502 core expects inverted input
nmiBuffer = InputNMI(); nmiBuffer = InputNMI();
if (!nmiBuffer && cachedNMI) if (!nmiBuffer && cachedNMI)
processor.NMI = true; //6502 core expects inverted input processor.NMI = true; //6502 core expects inverted input
cachedNMI = nmiBuffer; cachedNMI = nmiBuffer;
processor.RDY = InputRDY(); processor.RDY = InputRDY();
processor.ExecuteOne(); processor.ExecuteOne();
} }
} }
} }
byte CoreReadMemory(ushort addr) byte CoreReadMemory(ushort addr)
{ {
if (addr == 0x0000) if (addr == 0x0000)
return (byte)(portDirection & 0xFF); return (byte)(portDirection & 0xFF);
else if (addr == 0x0001) else if (addr == 0x0001)
return (byte)((InputPort() | (portDirection ^ 0xFF)) & 0xFF); return (byte)((InputPort() | (portDirection ^ 0xFF)) & 0xFF);
else else
return (byte)(ReadMemory(addr) & 0xFF); return (byte)(ReadMemory(addr) & 0xFF);
} }
void CoreWriteMemory(ushort addr, byte val) void CoreWriteMemory(ushort addr, byte val)
{ {
cachedAddress = addr; cachedAddress = addr;
cachedData = val; cachedData = val;
if (addr == 0x0000) if (addr == 0x0000)
portDirection = val; portDirection = val;
else if (addr == 0x0001) else if (addr == 0x0001)
portLatch = val; portLatch = val;
else else
WriteMemory(addr, val); WriteMemory(addr, val);
} }
public void Reset() public void Reset()
{ {
delayCycles = 6; delayCycles = 6;
processor.Reset(); processor.Reset();
processor.BCD_Enabled = true; processor.BCD_Enabled = true;
processor.PC = (ushort)((CoreReadMemory(0xFFFD) << 8) | CoreReadMemory(0xFFFC)); processor.PC = (ushort)((CoreReadMemory(0xFFFD) << 8) | CoreReadMemory(0xFFFC));
} }
} }
} }

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Cpu sealed public partial class Cpu
{ {

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public class Expansion public class Expansion
{ {

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public class Joystick public class Joystick
{ {

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public class Keyboard public class Keyboard
{ {

View File

@ -3,322 +3,322 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public class Pla sealed public class Pla
{ {
public Func<bool> InputCharen; public Func<bool> InputCharen;
public Func<bool> InputExRom; public Func<bool> InputExRom;
public Func<bool> InputGame; public Func<bool> InputGame;
public Func<bool> InputHiRam; public Func<bool> InputHiRam;
public Func<bool> InputLoRam; public Func<bool> InputLoRam;
public Func<int, int> PeekBasicRom; public Func<int, int> PeekBasicRom;
public Func<int, int> PeekCartridgeLo; public Func<int, int> PeekCartridgeLo;
public Func<int, int> PeekCartridgeHi; public Func<int, int> PeekCartridgeHi;
public Func<int, int> PeekCharRom; public Func<int, int> PeekCharRom;
public Func<int, int> PeekCia1; public Func<int, int> PeekCia1;
public Func<int, int> PeekCia2; public Func<int, int> PeekCia2;
public Func<int, int> PeekColorRam; public Func<int, int> PeekColorRam;
public Func<int, int> PeekExpansionLo; public Func<int, int> PeekExpansionLo;
public Func<int, int> PeekExpansionHi; public Func<int, int> PeekExpansionHi;
public Func<int, int> PeekKernalRom; public Func<int, int> PeekKernalRom;
public Func<int, int> PeekMemory; public Func<int, int> PeekMemory;
public Func<int, int> PeekSid; public Func<int, int> PeekSid;
public Func<int, int> PeekVic; public Func<int, int> PeekVic;
public Action<int, int> PokeCartridgeLo; public Action<int, int> PokeCartridgeLo;
public Action<int, int> PokeCartridgeHi; public Action<int, int> PokeCartridgeHi;
public Action<int, int> PokeCia1; public Action<int, int> PokeCia1;
public Action<int, int> PokeCia2; public Action<int, int> PokeCia2;
public Action<int, int> PokeColorRam; public Action<int, int> PokeColorRam;
public Action<int, int> PokeExpansionLo; public Action<int, int> PokeExpansionLo;
public Action<int, int> PokeExpansionHi; public Action<int, int> PokeExpansionHi;
public Action<int, int> PokeMemory; public Action<int, int> PokeMemory;
public Action<int, int> PokeSid; public Action<int, int> PokeSid;
public Action<int, int> PokeVic; public Action<int, int> PokeVic;
public Func<int, int> ReadBasicRom; public Func<int, int> ReadBasicRom;
public Func<int, int> ReadCartridgeLo; public Func<int, int> ReadCartridgeLo;
public Func<int, int> ReadCartridgeHi; public Func<int, int> ReadCartridgeHi;
public Func<int, int> ReadCharRom; public Func<int, int> ReadCharRom;
public Func<int, int> ReadCia1; public Func<int, int> ReadCia1;
public Func<int, int> ReadCia2; public Func<int, int> ReadCia2;
public Func<int, int> ReadColorRam; public Func<int, int> ReadColorRam;
public Func<int, int> ReadExpansionLo; public Func<int, int> ReadExpansionLo;
public Func<int, int> ReadExpansionHi; public Func<int, int> ReadExpansionHi;
public Func<int, int> ReadKernalRom; public Func<int, int> ReadKernalRom;
public Func<int, int> ReadMemory; public Func<int, int> ReadMemory;
public Func<int, int> ReadSid; public Func<int, int> ReadSid;
public Func<int, int> ReadVic; public Func<int, int> ReadVic;
public Action<int, int> WriteCartridgeLo; public Action<int, int> WriteCartridgeLo;
public Action<int, int> WriteCartridgeHi; public Action<int, int> WriteCartridgeHi;
public Action<int, int> WriteCia1; public Action<int, int> WriteCia1;
public Action<int, int> WriteCia2; public Action<int, int> WriteCia2;
public Action<int, int> WriteColorRam; public Action<int, int> WriteColorRam;
public Action<int, int> WriteExpansionLo; public Action<int, int> WriteExpansionLo;
public Action<int, int> WriteExpansionHi; public Action<int, int> WriteExpansionHi;
public Action<int, int> WriteMemory; public Action<int, int> WriteMemory;
public Action<int, int> WriteSid; public Action<int, int> WriteSid;
public Action<int, int> WriteVic; public Action<int, int> WriteVic;
enum PLABank enum PLABank
{ {
None, None,
RAM, RAM,
BasicROM, BasicROM,
KernalROM, KernalROM,
CharROM, CharROM,
IO, IO,
CartridgeLo, CartridgeLo,
CartridgeHi, CartridgeHi,
Vic, Vic,
Sid, Sid,
ColorRam, ColorRam,
Cia1, Cia1,
Cia2, Cia2,
ExpansionLo, ExpansionLo,
ExpansionHi ExpansionHi
} }
bool loram; bool loram;
bool hiram; bool hiram;
bool game; bool game;
bool exrom; bool exrom;
bool charen; bool charen;
bool a15; bool a15;
bool a14; bool a14;
bool a13; bool a13;
bool a12; bool a12;
public int Peek(int addr) public int Peek(int addr)
{ {
switch (Resolve(addr, true)) switch (Resolve(addr, true))
{ {
case PLABank.BasicROM: case PLABank.BasicROM:
return PeekBasicRom(addr); return PeekBasicRom(addr);
case PLABank.CartridgeHi: case PLABank.CartridgeHi:
return PeekCartridgeHi(addr); return PeekCartridgeHi(addr);
case PLABank.CartridgeLo: case PLABank.CartridgeLo:
return PeekCartridgeLo(addr); return PeekCartridgeLo(addr);
case PLABank.CharROM: case PLABank.CharROM:
return PeekCharRom(addr); return PeekCharRom(addr);
case PLABank.Cia1: case PLABank.Cia1:
return PeekCia1(addr); return PeekCia1(addr);
case PLABank.Cia2: case PLABank.Cia2:
return PeekCia2(addr); return PeekCia2(addr);
case PLABank.ColorRam: case PLABank.ColorRam:
return PeekColorRam(addr); return PeekColorRam(addr);
case PLABank.ExpansionLo: case PLABank.ExpansionLo:
return PeekExpansionLo(addr); return PeekExpansionLo(addr);
case PLABank.ExpansionHi: case PLABank.ExpansionHi:
return PeekExpansionHi(addr); return PeekExpansionHi(addr);
case PLABank.KernalROM: case PLABank.KernalROM:
return PeekKernalRom(addr); return PeekKernalRom(addr);
case PLABank.RAM: case PLABank.RAM:
return PeekMemory(addr); return PeekMemory(addr);
case PLABank.Sid: case PLABank.Sid:
return PeekSid(addr); return PeekSid(addr);
case PLABank.Vic: case PLABank.Vic:
return PeekVic(addr); return PeekVic(addr);
} }
return 0xFF; return 0xFF;
} }
public void Poke(int addr, int val) public void Poke(int addr, int val)
{ {
switch (Resolve(addr, false)) switch (Resolve(addr, false))
{ {
case PLABank.CartridgeHi: case PLABank.CartridgeHi:
PokeCartridgeHi(addr, val); PokeCartridgeHi(addr, val);
break; break;
case PLABank.CartridgeLo: case PLABank.CartridgeLo:
PokeCartridgeLo(addr, val); PokeCartridgeLo(addr, val);
break; break;
case PLABank.Cia1: case PLABank.Cia1:
PokeCia1(addr, val); PokeCia1(addr, val);
break; break;
case PLABank.Cia2: case PLABank.Cia2:
PokeCia2(addr, val); PokeCia2(addr, val);
break; break;
case PLABank.ColorRam: case PLABank.ColorRam:
PokeColorRam(addr, val); PokeColorRam(addr, val);
break; break;
case PLABank.ExpansionLo: case PLABank.ExpansionLo:
PokeExpansionLo(addr, val); PokeExpansionLo(addr, val);
break; break;
case PLABank.ExpansionHi: case PLABank.ExpansionHi:
PokeExpansionHi(addr, val); PokeExpansionHi(addr, val);
break; break;
case PLABank.RAM: case PLABank.RAM:
PokeMemory(addr, val); PokeMemory(addr, val);
break; break;
case PLABank.Sid: case PLABank.Sid:
PokeSid(addr, val); PokeSid(addr, val);
break; break;
case PLABank.Vic: case PLABank.Vic:
PokeVic(addr, val); PokeVic(addr, val);
break; break;
} }
} }
public int Read(int addr) public int Read(int addr)
{ {
switch (Resolve(addr, true)) switch (Resolve(addr, true))
{ {
case PLABank.BasicROM: case PLABank.BasicROM:
return ReadBasicRom(addr); return ReadBasicRom(addr);
case PLABank.CartridgeHi: case PLABank.CartridgeHi:
return ReadCartridgeHi(addr); return ReadCartridgeHi(addr);
case PLABank.CartridgeLo: case PLABank.CartridgeLo:
return ReadCartridgeLo(addr); return ReadCartridgeLo(addr);
case PLABank.CharROM: case PLABank.CharROM:
return ReadCharRom(addr); return ReadCharRom(addr);
case PLABank.Cia1: case PLABank.Cia1:
return ReadCia1(addr); return ReadCia1(addr);
case PLABank.Cia2: case PLABank.Cia2:
return ReadCia2(addr); return ReadCia2(addr);
case PLABank.ColorRam: case PLABank.ColorRam:
return ReadColorRam(addr); return ReadColorRam(addr);
case PLABank.ExpansionLo: case PLABank.ExpansionLo:
return ReadExpansionLo(addr); return ReadExpansionLo(addr);
case PLABank.ExpansionHi: case PLABank.ExpansionHi:
return ReadExpansionHi(addr); return ReadExpansionHi(addr);
case PLABank.KernalROM: case PLABank.KernalROM:
return ReadKernalRom(addr); return ReadKernalRom(addr);
case PLABank.RAM: case PLABank.RAM:
return ReadMemory(addr); return ReadMemory(addr);
case PLABank.Sid: case PLABank.Sid:
return ReadSid(addr); return ReadSid(addr);
case PLABank.Vic: case PLABank.Vic:
return ReadVic(addr); return ReadVic(addr);
} }
return 0xFF; return 0xFF;
} }
PLABank Resolve(int addr, bool read) PLABank Resolve(int addr, bool read)
{ {
loram = InputLoRam(); loram = InputLoRam();
hiram = InputHiRam(); hiram = InputHiRam();
game = InputGame(); game = InputGame();
exrom = InputExRom(); exrom = InputExRom();
a15 = (addr & 0x08000) != 0; a15 = (addr & 0x08000) != 0;
a14 = (addr & 0x04000) != 0; a14 = (addr & 0x04000) != 0;
a13 = (addr & 0x02000) != 0; a13 = (addr & 0x02000) != 0;
a12 = (addr & 0x01000) != 0; a12 = (addr & 0x01000) != 0;
// upper memory regions 8000-FFFF // upper memory regions 8000-FFFF
if (a15) if (a15)
{ {
// io/character access // io/character access
if (a14 && !a13 && a12) if (a14 && !a13 && a12)
{ {
// character rom, banked in at D000-DFFF // character rom, banked in at D000-DFFF
charen = InputCharen(); charen = InputCharen();
if (read && !charen && (((hiram || loram) && game) || (hiram && !exrom && !game))) if (read && !charen && (((hiram || loram) && game) || (hiram && !exrom && !game)))
return PLABank.CharROM; return PLABank.CharROM;
// io block, banked in at D000-DFFF // io block, banked in at D000-DFFF
if ((charen && (hiram || loram)) || (exrom && !game)) if ((charen && (hiram || loram)) || (exrom && !game))
{ {
if (addr < 0xD400) if (addr < 0xD400)
return PLABank.Vic; return PLABank.Vic;
if (addr < 0xD800) if (addr < 0xD800)
return PLABank.Sid; return PLABank.Sid;
if (addr < 0xDC00) if (addr < 0xDC00)
return PLABank.ColorRam; return PLABank.ColorRam;
if (addr < 0xDD00) if (addr < 0xDD00)
return PLABank.Cia1; return PLABank.Cia1;
if (addr < 0xDE00) if (addr < 0xDE00)
return PLABank.Cia2; return PLABank.Cia2;
if (addr < 0xDF00) if (addr < 0xDF00)
return PLABank.ExpansionLo; return PLABank.ExpansionLo;
return PLABank.ExpansionHi; return PLABank.ExpansionHi;
} }
} }
if (read) if (read)
{ {
// cartridge high, banked either at A000-BFFF or E000-FFFF depending // cartridge high, banked either at A000-BFFF or E000-FFFF depending
if (a13 && !game && ((hiram && !a14 && !exrom) || (a14 && exrom))) if (a13 && !game && ((hiram && !a14 && !exrom) || (a14 && exrom)))
return PLABank.CartridgeHi; return PLABank.CartridgeHi;
// cartridge low, banked at 8000-9FFF // cartridge low, banked at 8000-9FFF
if (!a14 && !a13 && ((loram && hiram && !exrom) || (exrom && !game))) if (!a14 && !a13 && ((loram && hiram && !exrom) || (exrom && !game)))
return PLABank.CartridgeLo; return PLABank.CartridgeLo;
// kernal rom, banked at E000-FFFF // kernal rom, banked at E000-FFFF
if (hiram && a14 && a13 && (game || (!exrom && !game))) if (hiram && a14 && a13 && (game || (!exrom && !game)))
return PLABank.KernalROM; return PLABank.KernalROM;
// basic rom, banked at A000-BFFF // basic rom, banked at A000-BFFF
if (loram && hiram && !a14 && a13 && game) if (loram && hiram && !a14 && a13 && game)
return PLABank.BasicROM; return PLABank.BasicROM;
} }
} }
// ultimax mode ram exclusion // ultimax mode ram exclusion
if (exrom && !game && ((a15 && ((!a14 && a13) || (a14 && !a13 && !a12))) || (!a15 && (a14 || (!a14 && (a12 || a13)))))) if (exrom && !game && ((a15 && ((!a14 && a13) || (a14 && !a13 && !a12))) || (!a15 && (a14 || (!a14 && (a12 || a13))))))
return PLABank.None; return PLABank.None;
return PLABank.RAM; return PLABank.RAM;
} }
public int VicRead(int addr) public int VicRead(int addr)
{ {
game = InputGame(); game = InputGame();
exrom = InputExRom(); exrom = InputExRom();
a14 = (addr & 0x04000) == 0; a14 = (addr & 0x04000) == 0;
a13 = (addr & 0x02000) != 0; a13 = (addr & 0x02000) != 0;
a12 = (addr & 0x01000) != 0; a12 = (addr & 0x01000) != 0;
// read char rom at 1000-1FFF and 9000-9FFF // read char rom at 1000-1FFF and 9000-9FFF
if (a14 && !a13 && a12 && (game || !exrom)) if (a14 && !a13 && a12 && (game || !exrom))
return ReadCharRom(addr); return ReadCharRom(addr);
// read cartridge rom in ultimax mode // read cartridge rom in ultimax mode
if (a13 && a12 && exrom && !game) if (a13 && a12 && exrom && !game)
return ReadCartridgeHi(addr); return ReadCartridgeHi(addr);
return ReadMemory(addr); return ReadMemory(addr);
} }
public void Write(int addr, int val) public void Write(int addr, int val)
{ {
switch (Resolve(addr, false)) switch (Resolve(addr, false))
{ {
case PLABank.CartridgeHi: case PLABank.CartridgeHi:
WriteCartridgeHi(addr, val); WriteCartridgeHi(addr, val);
WriteMemory(addr, val); WriteMemory(addr, val);
break; break;
case PLABank.CartridgeLo: case PLABank.CartridgeLo:
WriteCartridgeLo(addr, val); WriteCartridgeLo(addr, val);
WriteMemory(addr, val); WriteMemory(addr, val);
break; break;
case PLABank.Cia1: case PLABank.Cia1:
WriteCia1(addr, val); WriteCia1(addr, val);
break; break;
case PLABank.Cia2: case PLABank.Cia2:
WriteCia2(addr, val); WriteCia2(addr, val);
break; break;
case PLABank.ColorRam: case PLABank.ColorRam:
WriteColorRam(addr, val); WriteColorRam(addr, val);
break; break;
case PLABank.ExpansionLo: case PLABank.ExpansionLo:
WriteExpansionLo(addr, val); WriteExpansionLo(addr, val);
return; return;
case PLABank.ExpansionHi: case PLABank.ExpansionHi:
WriteExpansionHi(addr, val); WriteExpansionHi(addr, val);
return; return;
case PLABank.RAM: case PLABank.RAM:
WriteMemory(addr, val); WriteMemory(addr, val);
break; break;
case PLABank.Sid: case PLABank.Sid:
WriteSid(addr, val); WriteSid(addr, val);
break; break;
case PLABank.Vic: case PLABank.Vic:
WriteVic(addr, val); WriteVic(addr, val);
break; break;
} }
} }
} }
} }

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public class Ram sealed public class Ram
{ {

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public class Rom public class Rom
{ {

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public class Serial public class Serial
{ {

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Sid sealed public partial class Sid
{ {

View File

@ -3,23 +3,23 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Sid sealed public partial class Sid
{ {
public Sid(SidSettings settings) public Sid(SidSettings settings)
{ {
Reset(); Reset();
} }
public void Clock() public void Clock()
{ {
} }
public void Reset() public void Reset()
{ {
for (int i = 0; i < 0x20; i++) for (int i = 0; i < 0x20; i++)
Poke(i, 0); Poke(i, 0);
} }
} }
} }

View File

@ -3,27 +3,27 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Sid sealed public partial class Sid
{ {
public int Peek(int addr) public int Peek(int addr)
{ {
return 0xFF; return 0xFF;
} }
public void Poke(int addr, int val) public void Poke(int addr, int val)
{ {
} }
public int Read(int addr) public int Read(int addr)
{ {
return Peek(addr); return Peek(addr);
} }
public void Write(int addr, int val) public void Write(int addr, int val)
{ {
Poke(addr, val); Poke(addr, val);
} }
} }
} }

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public class SidSettings public class SidSettings
{ {
} }
} }

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Sid sealed public partial class Sid
{ {

View File

@ -3,36 +3,36 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public class Userport public class Userport
{ {
public Func<bool> InputCNT1; public Func<bool> InputCNT1;
public Func<bool> InputCNT2; public Func<bool> InputCNT2;
public Func<int> InputData; public Func<int> InputData;
public Func<bool> InputPA2; public Func<bool> InputPA2;
public Func<bool> InputPC2; public Func<bool> InputPC2;
public Func<bool> InputReset; public Func<bool> InputReset;
public Func<bool> InputSP1; public Func<bool> InputSP1;
public Func<bool> InputSP2; public Func<bool> InputSP2;
virtual public bool ATN { get { return true; } } virtual public bool ATN { get { return true; } }
virtual public bool CNT1 { get { return true; } } virtual public bool CNT1 { get { return true; } }
virtual public bool CNT2 { get { return true; } } virtual public bool CNT2 { get { return true; } }
virtual public int Data { get { return 0xFF; } } virtual public int Data { get { return 0xFF; } }
virtual public bool FLAG2 { get { return true; } } virtual public bool FLAG2 { get { return true; } }
public bool OutputATN() { return ATN; } public bool OutputATN() { return ATN; }
public bool OutputCNT1() { return CNT1; } public bool OutputCNT1() { return CNT1; }
public bool OutputCNT2() { return CNT2; } public bool OutputCNT2() { return CNT2; }
public int OutputData() { return Data; } public int OutputData() { return Data; }
public bool OutputFLAG2() { return FLAG2; } public bool OutputFLAG2() { return FLAG2; }
public bool OutputPA2() { return PA2; } public bool OutputPA2() { return PA2; }
public bool OutputReset() { return Reset; } public bool OutputReset() { return Reset; }
public bool OutputSP1() { return SP1; } public bool OutputSP1() { return SP1; }
public bool OutputSP2() { return SP2; } public bool OutputSP2() { return SP2; }
virtual public bool PA2 { get { return true; } } virtual public bool PA2 { get { return true; } }
virtual public bool Reset { get { return true; } } virtual public bool Reset { get { return true; } }
virtual public bool SP1 { get { return true; } } virtual public bool SP1 { get { return true; } }
virtual public bool SP2 { get { return true; } } virtual public bool SP2 { get { return true; } }
} }
} }

View File

@ -6,150 +6,150 @@ using System.Text;
#pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete
#pragma warning disable 169 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 169 //adelikat: Disable dumb warnings until this file is complete
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Vic sealed public partial class Vic
{ {
const int GRAPHICS_DATA_00 = 0; const int GRAPHICS_DATA_00 = 0;
const int GRAPHICS_DATA_01 = 0x4000; const int GRAPHICS_DATA_01 = 0x4000;
const int GRAPHICS_DATA_10 = GRAPHICS_DATA_01 << 1; const int GRAPHICS_DATA_10 = GRAPHICS_DATA_01 << 1;
const int GRAPHICS_DATA_11 = GRAPHICS_DATA_01 | GRAPHICS_DATA_10; const int GRAPHICS_DATA_11 = GRAPHICS_DATA_01 | GRAPHICS_DATA_10;
const int GRAPHICS_DATA_OUTPUT_MASK = GRAPHICS_DATA_11; const int GRAPHICS_DATA_OUTPUT_MASK = GRAPHICS_DATA_11;
enum GraphicsMode enum GraphicsMode
{ {
Mode000, Mode000,
Mode001, Mode001,
Mode010, Mode010,
Mode011, Mode011,
Mode100, Mode100,
Mode101, Mode101,
Mode110, Mode110,
Mode111 Mode111
} }
int g_BufferC; int g_BufferC;
int g_BufferG; int g_BufferG;
int g_DataC; int g_DataC;
int g_DataG; int g_DataG;
bool g_Idle; bool g_Idle;
int g_FillRasterX; int g_FillRasterX;
GraphicsMode g_Mode; GraphicsMode g_Mode;
int g_OutData; int g_OutData;
int g_OutPixel; int g_OutPixel;
int g_ShiftRegister; int g_ShiftRegister;
void RenderGraphics() void RenderGraphics()
{ {
if ((rasterX & 0x7) == g_FillRasterX) if ((rasterX & 0x7) == g_FillRasterX)
{ {
if (g_Idle) if (g_Idle)
g_DataC = 0; g_DataC = 0;
else else
g_DataC = g_BufferC; g_DataC = g_BufferC;
if (multiColorMode && (bitmapMode || (g_DataC & 0x8) != 0)) if (multiColorMode && (bitmapMode || (g_DataC & 0x8) != 0))
{ {
// load multicolor bits // load multicolor bits
// xx00xx11xx22xx33 // xx00xx11xx22xx33
g_ShiftRegister = g_ShiftRegister =
((g_DataG & 0x03) << 0) | ((g_DataG & 0x03) << 0) |
((g_DataG & 0x0C) << 2) | ((g_DataG & 0x0C) << 2) |
((g_DataG & 0x30) << 4) | ((g_DataG & 0x30) << 4) |
((g_DataG & 0xC0) << 6) ((g_DataG & 0xC0) << 6)
; ;
// duplicate bits // duplicate bits
// 0000111122223333 // 0000111122223333
g_ShiftRegister |= g_ShiftRegister << 2; g_ShiftRegister |= g_ShiftRegister << 2;
} }
else else
{ {
// load single color bits // load single color bits
// 0x1x2x3x4x5x6x7x // 0x1x2x3x4x5x6x7x
g_ShiftRegister = g_ShiftRegister =
((g_DataG & 0x01) << 1) | ((g_DataG & 0x01) << 1) |
((g_DataG & 0x02) << 2) | ((g_DataG & 0x02) << 2) |
((g_DataG & 0x04) << 3) | ((g_DataG & 0x04) << 3) |
((g_DataG & 0x08) << 4) | ((g_DataG & 0x08) << 4) |
((g_DataG & 0x10) << 5) | ((g_DataG & 0x10) << 5) |
((g_DataG & 0x20) << 6) | ((g_DataG & 0x20) << 6) |
((g_DataG & 0x40) << 7) | ((g_DataG & 0x40) << 7) |
((g_DataG & 0x80) << 8) ((g_DataG & 0x80) << 8)
; ;
if (!bitmapMode) if (!bitmapMode)
{ {
// duplicate bits // duplicate bits
// 0011223344556677 // 0011223344556677
g_ShiftRegister |= g_ShiftRegister << 1; g_ShiftRegister |= g_ShiftRegister << 1;
} }
else else
{ {
// convert to bitmap format // convert to bitmap format
g_ShiftRegister = (g_ShiftRegister | 0x5555) ^ (g_ShiftRegister >> 1); g_ShiftRegister = (g_ShiftRegister | 0x5555) ^ (g_ShiftRegister >> 1);
} }
} }
} }
g_OutData = g_ShiftRegister & GRAPHICS_DATA_OUTPUT_MASK; g_OutData = g_ShiftRegister & GRAPHICS_DATA_OUTPUT_MASK;
switch (g_Mode) switch (g_Mode)
{ {
case GraphicsMode.Mode000: case GraphicsMode.Mode000:
case GraphicsMode.Mode001: case GraphicsMode.Mode001:
if (g_OutData == GRAPHICS_DATA_00) if (g_OutData == GRAPHICS_DATA_00)
g_OutPixel = backgroundColor[0]; g_OutPixel = backgroundColor[0];
else if (g_OutData == GRAPHICS_DATA_11) else if (g_OutData == GRAPHICS_DATA_11)
g_OutPixel = ((g_DataC >> 8) & 0x7); g_OutPixel = ((g_DataC >> 8) & 0x7);
else if (g_OutData == GRAPHICS_DATA_01) else if (g_OutData == GRAPHICS_DATA_01)
g_OutPixel = backgroundColor[1]; g_OutPixel = backgroundColor[1];
else else
g_OutPixel = backgroundColor[2]; g_OutPixel = backgroundColor[2];
break; break;
case GraphicsMode.Mode010: case GraphicsMode.Mode010:
case GraphicsMode.Mode011: case GraphicsMode.Mode011:
if (g_OutData == GRAPHICS_DATA_00) if (g_OutData == GRAPHICS_DATA_00)
g_OutPixel = backgroundColor[0]; g_OutPixel = backgroundColor[0];
else if (g_OutData == GRAPHICS_DATA_01) else if (g_OutData == GRAPHICS_DATA_01)
g_OutPixel = ((g_DataC >> 4) & 0xF); g_OutPixel = ((g_DataC >> 4) & 0xF);
else if (g_OutData == GRAPHICS_DATA_10) else if (g_OutData == GRAPHICS_DATA_10)
g_OutPixel = (g_DataC & 0xF); g_OutPixel = (g_DataC & 0xF);
else else
g_OutPixel = (g_DataC >> 8); g_OutPixel = (g_DataC >> 8);
break; break;
case GraphicsMode.Mode100: case GraphicsMode.Mode100:
if (g_OutData == GRAPHICS_DATA_00) if (g_OutData == GRAPHICS_DATA_00)
g_OutPixel = backgroundColor[(g_DataC >> 6) & 0x3]; g_OutPixel = backgroundColor[(g_DataC >> 6) & 0x3];
else else
g_OutPixel = (g_DataC >> 8); g_OutPixel = (g_DataC >> 8);
break; break;
default: default:
g_OutPixel = 0; g_OutPixel = 0;
break; break;
} }
g_ShiftRegister <<= 2; g_ShiftRegister <<= 2;
} }
void UpdateGraphicsMode() void UpdateGraphicsMode()
{ {
if (!extraColorMode && !bitmapMode && !multiColorMode) if (!extraColorMode && !bitmapMode && !multiColorMode)
g_Mode = GraphicsMode.Mode000; g_Mode = GraphicsMode.Mode000;
else if (!extraColorMode && !bitmapMode && multiColorMode) else if (!extraColorMode && !bitmapMode && multiColorMode)
g_Mode = GraphicsMode.Mode001; g_Mode = GraphicsMode.Mode001;
else if (!extraColorMode && bitmapMode && !multiColorMode) else if (!extraColorMode && bitmapMode && !multiColorMode)
g_Mode = GraphicsMode.Mode010; g_Mode = GraphicsMode.Mode010;
else if (!extraColorMode && bitmapMode && multiColorMode) else if (!extraColorMode && bitmapMode && multiColorMode)
g_Mode = GraphicsMode.Mode011; g_Mode = GraphicsMode.Mode011;
else if (extraColorMode && !bitmapMode && !multiColorMode) else if (extraColorMode && !bitmapMode && !multiColorMode)
g_Mode = GraphicsMode.Mode100; g_Mode = GraphicsMode.Mode100;
else if (extraColorMode && !bitmapMode && multiColorMode) else if (extraColorMode && !bitmapMode && multiColorMode)
g_Mode = GraphicsMode.Mode101; g_Mode = GraphicsMode.Mode101;
else if (extraColorMode && bitmapMode && !multiColorMode) else if (extraColorMode && bitmapMode && !multiColorMode)
g_Mode = GraphicsMode.Mode110; g_Mode = GraphicsMode.Mode110;
else if (extraColorMode && bitmapMode && multiColorMode) else if (extraColorMode && bitmapMode && multiColorMode)
g_Mode = GraphicsMode.Mode111; g_Mode = GraphicsMode.Mode111;
} }
} }
} }

View File

@ -3,28 +3,28 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Vic sealed public partial class Vic
{ {
// inputs // inputs
public Action ClockPhi0; public Action ClockPhi0;
public Func<int, int> ReadColorRam; public Func<int, int> ReadColorRam;
public Func<int, int> ReadRam; public Func<int, int> ReadRam;
// outputs // outputs
public bool AEC { get { return true; } } public bool AEC { get { return true; } }
public bool BA { get { return true; } } public bool BA { get { return true; } }
public bool IRQ { get { return true; } } public bool IRQ { get { return true; } }
public bool OutputAEC() { return true; } public bool OutputAEC() { return true; }
public bool OutputBA() { return true; } public bool OutputBA() { return true; }
public bool OutputIRQ() { return true; } public bool OutputIRQ() { return true; }
// exposed internal data // exposed internal data
public int Address { get { return address; } } public int Address { get { return address; } }
public int CyclesPerFrame { get { return rasterCount * rasterWidth / 8; } } public int CyclesPerFrame { get { return rasterCount * rasterWidth / 8; } }
public int CyclesPerSecond { get { return frequency; } } public int CyclesPerSecond { get { return frequency; } }
public int Data { get { return data; } } public int Data { get { return data; } }
public int DataPhi1 { get { return phi1Data; } } public int DataPhi1 { get { return phi1Data; } }
} }
} }

View File

@ -6,28 +6,28 @@ using System.Text;
#pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete
#pragma warning disable 169 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 169 //adelikat: Disable dumb warnings until this file is complete
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Vic sealed public partial class Vic
{ {
int address; int address;
bool aec; bool aec;
bool ba; bool ba;
int data; int data;
int phi1Data; int phi1Data;
int rasterX; int rasterX;
public Vic(VicSettings settings) public Vic(VicSettings settings)
{ {
} }
public void Clock() public void Clock()
{ {
Render(); Render();
} }
public void Reset() public void Reset()
{ {
} }
} }
} }

View File

@ -5,424 +5,424 @@ using System.Text;
#pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Vic sealed public partial class Vic
{ {
int[] backgroundColor; int[] backgroundColor;
bool bitmapMode; bool bitmapMode;
int borderColor; int borderColor;
int characterBitmap; int characterBitmap;
bool columnSelect; bool columnSelect;
bool dataCollisionInterrupt; bool dataCollisionInterrupt;
bool dataCollisionInterruptEnable; bool dataCollisionInterruptEnable;
bool displayEnable; bool displayEnable;
bool extraColorMode; bool extraColorMode;
bool irq; bool irq;
bool lightPenInterrupt; bool lightPenInterrupt;
bool lightPenInterruptEnable; bool lightPenInterruptEnable;
int lightPenX; int lightPenX;
int lightPenY; int lightPenY;
bool multiColorMode; bool multiColorMode;
bool rasterInterrupt; bool rasterInterrupt;
bool rasterInterruptEnable; bool rasterInterruptEnable;
int rasterY; int rasterY;
int rasterYCompare; int rasterYCompare;
bool reset; bool reset;
bool rowSelect; bool rowSelect;
bool spriteCollisionInterrupt; bool spriteCollisionInterrupt;
bool spriteCollisionInterruptEnable; bool spriteCollisionInterruptEnable;
int[] spriteMultiColor; int[] spriteMultiColor;
int videoMemory; int videoMemory;
int xScroll; int xScroll;
int yScroll; int yScroll;
public int Peek(int addr) public int Peek(int addr)
{ {
switch (addr) switch (addr)
{ {
case 0x00: return sprites[0].X & 0xFF; case 0x00: return sprites[0].X & 0xFF;
case 0x01: return sprites[1].X & 0xFF; case 0x01: return sprites[1].X & 0xFF;
case 0x02: return sprites[2].X & 0xFF; case 0x02: return sprites[2].X & 0xFF;
case 0x03: return sprites[3].X & 0xFF; case 0x03: return sprites[3].X & 0xFF;
case 0x04: return sprites[4].X & 0xFF; case 0x04: return sprites[4].X & 0xFF;
case 0x05: return sprites[5].X & 0xFF; case 0x05: return sprites[5].X & 0xFF;
case 0x06: return sprites[6].X & 0xFF; case 0x06: return sprites[6].X & 0xFF;
case 0x07: return sprites[7].X & 0xFF; case 0x07: return sprites[7].X & 0xFF;
case 0x08: return sprites[0].Y; case 0x08: return sprites[0].Y;
case 0x09: return sprites[1].Y; case 0x09: return sprites[1].Y;
case 0x0A: return sprites[2].Y; case 0x0A: return sprites[2].Y;
case 0x0B: return sprites[3].Y; case 0x0B: return sprites[3].Y;
case 0x0C: return sprites[4].Y; case 0x0C: return sprites[4].Y;
case 0x0D: return sprites[5].Y; case 0x0D: return sprites[5].Y;
case 0x0E: return sprites[6].Y; case 0x0E: return sprites[6].Y;
case 0x0F: return sprites[7].Y; case 0x0F: return sprites[7].Y;
case 0x10: return ( case 0x10: return (
((sprites[0].X & 0x80) >> 7) | ((sprites[0].X & 0x80) >> 7) |
((sprites[1].X & 0x80) >> 6) | ((sprites[1].X & 0x80) >> 6) |
((sprites[2].X & 0x80) >> 5) | ((sprites[2].X & 0x80) >> 5) |
((sprites[3].X & 0x80) >> 4) | ((sprites[3].X & 0x80) >> 4) |
((sprites[4].X & 0x80) >> 3) | ((sprites[4].X & 0x80) >> 3) |
((sprites[5].X & 0x80) >> 2) | ((sprites[5].X & 0x80) >> 2) |
((sprites[6].X & 0x80) >> 1) | ((sprites[6].X & 0x80) >> 1) |
(sprites[7].X & 0x80) (sprites[7].X & 0x80)
); );
case 0x11: return ( case 0x11: return (
yScroll | yScroll |
(rowSelect ? 0x08 : 0x00) | (rowSelect ? 0x08 : 0x00) |
(displayEnable ? 0x10 : 0x00) | (displayEnable ? 0x10 : 0x00) |
(bitmapMode ? 0x20 : 0x00) | (bitmapMode ? 0x20 : 0x00) |
(extraColorMode ? 0x40 : 0x00) | (extraColorMode ? 0x40 : 0x00) |
((rasterY & 0x100) >> 1) ((rasterY & 0x100) >> 1)
); );
case 0x12: return (rasterY & 0xFF); case 0x12: return (rasterY & 0xFF);
case 0x13: return lightPenX; case 0x13: return lightPenX;
case 0x14: return lightPenY; case 0x14: return lightPenY;
case 0x15: return ( case 0x15: return (
(sprites[0].Enabled ? 0x01 : 0x00) | (sprites[0].Enabled ? 0x01 : 0x00) |
(sprites[1].Enabled ? 0x02 : 0x00) | (sprites[1].Enabled ? 0x02 : 0x00) |
(sprites[2].Enabled ? 0x04 : 0x00) | (sprites[2].Enabled ? 0x04 : 0x00) |
(sprites[3].Enabled ? 0x08 : 0x00) | (sprites[3].Enabled ? 0x08 : 0x00) |
(sprites[4].Enabled ? 0x10 : 0x00) | (sprites[4].Enabled ? 0x10 : 0x00) |
(sprites[5].Enabled ? 0x20 : 0x00) | (sprites[5].Enabled ? 0x20 : 0x00) |
(sprites[6].Enabled ? 0x40 : 0x00) | (sprites[6].Enabled ? 0x40 : 0x00) |
(sprites[7].Enabled ? 0x80 : 0x00) (sprites[7].Enabled ? 0x80 : 0x00)
); );
case 0x16: return ( case 0x16: return (
xScroll | xScroll |
(columnSelect ? 0x08 : 0x00) | (columnSelect ? 0x08 : 0x00) |
(multiColorMode ? 0x10 : 0x00) | (multiColorMode ? 0x10 : 0x00) |
(reset ? 0x20 : 0x00) | (reset ? 0x20 : 0x00) |
0xC0 0xC0
); );
case 0x17: return ( case 0x17: return (
(sprites[0].ExpandY ? 0x01 : 0x00) | (sprites[0].ExpandY ? 0x01 : 0x00) |
(sprites[1].ExpandY ? 0x02 : 0x00) | (sprites[1].ExpandY ? 0x02 : 0x00) |
(sprites[2].ExpandY ? 0x04 : 0x00) | (sprites[2].ExpandY ? 0x04 : 0x00) |
(sprites[3].ExpandY ? 0x08 : 0x00) | (sprites[3].ExpandY ? 0x08 : 0x00) |
(sprites[4].ExpandY ? 0x10 : 0x00) | (sprites[4].ExpandY ? 0x10 : 0x00) |
(sprites[5].ExpandY ? 0x20 : 0x00) | (sprites[5].ExpandY ? 0x20 : 0x00) |
(sprites[6].ExpandY ? 0x40 : 0x00) | (sprites[6].ExpandY ? 0x40 : 0x00) |
(sprites[7].ExpandY ? 0x80 : 0x00) (sprites[7].ExpandY ? 0x80 : 0x00)
); );
case 0x18: return ( case 0x18: return (
(videoMemory >> 6) | (videoMemory >> 6) |
(characterBitmap >> 10) (characterBitmap >> 10)
); );
case 0x19: return ( case 0x19: return (
(rasterInterrupt ? 0x01 : 0x00) | (rasterInterrupt ? 0x01 : 0x00) |
(dataCollisionInterrupt ? 0x02 : 0x00) | (dataCollisionInterrupt ? 0x02 : 0x00) |
(spriteCollisionInterrupt ? 0x04 : 0x00) | (spriteCollisionInterrupt ? 0x04 : 0x00) |
(lightPenInterrupt ? 0x08 : 0x00) | (lightPenInterrupt ? 0x08 : 0x00) |
0x70 | 0x70 |
(irq ? 0x80 : 0x00) (irq ? 0x80 : 0x00)
); );
case 0x1A: return ( case 0x1A: return (
(rasterInterruptEnable ? 0x01 : 0x00) | (rasterInterruptEnable ? 0x01 : 0x00) |
(dataCollisionInterruptEnable ? 0x02 : 0x00) | (dataCollisionInterruptEnable ? 0x02 : 0x00) |
(spriteCollisionInterruptEnable ? 0x04 : 0x00) | (spriteCollisionInterruptEnable ? 0x04 : 0x00) |
(lightPenInterruptEnable ? 0x08 : 0x00) | (lightPenInterruptEnable ? 0x08 : 0x00) |
0xF0 0xF0
); );
case 0x1B: return ( case 0x1B: return (
(sprites[0].Priority ? 0x01 : 0x00) | (sprites[0].Priority ? 0x01 : 0x00) |
(sprites[1].Priority ? 0x02 : 0x00) | (sprites[1].Priority ? 0x02 : 0x00) |
(sprites[2].Priority ? 0x04 : 0x00) | (sprites[2].Priority ? 0x04 : 0x00) |
(sprites[3].Priority ? 0x08 : 0x00) | (sprites[3].Priority ? 0x08 : 0x00) |
(sprites[4].Priority ? 0x10 : 0x00) | (sprites[4].Priority ? 0x10 : 0x00) |
(sprites[5].Priority ? 0x20 : 0x00) | (sprites[5].Priority ? 0x20 : 0x00) |
(sprites[6].Priority ? 0x40 : 0x00) | (sprites[6].Priority ? 0x40 : 0x00) |
(sprites[7].Priority ? 0x80 : 0x00) (sprites[7].Priority ? 0x80 : 0x00)
); );
case 0x1C: return ( case 0x1C: return (
(sprites[0].Multicolor ? 0x01 : 0x00) | (sprites[0].Multicolor ? 0x01 : 0x00) |
(sprites[1].Multicolor ? 0x02 : 0x00) | (sprites[1].Multicolor ? 0x02 : 0x00) |
(sprites[2].Multicolor ? 0x04 : 0x00) | (sprites[2].Multicolor ? 0x04 : 0x00) |
(sprites[3].Multicolor ? 0x08 : 0x00) | (sprites[3].Multicolor ? 0x08 : 0x00) |
(sprites[4].Multicolor ? 0x10 : 0x00) | (sprites[4].Multicolor ? 0x10 : 0x00) |
(sprites[5].Multicolor ? 0x20 : 0x00) | (sprites[5].Multicolor ? 0x20 : 0x00) |
(sprites[6].Multicolor ? 0x40 : 0x00) | (sprites[6].Multicolor ? 0x40 : 0x00) |
(sprites[7].Multicolor ? 0x80 : 0x00) (sprites[7].Multicolor ? 0x80 : 0x00)
); );
case 0x1D: return ( case 0x1D: return (
(sprites[0].ExpandX ? 0x01 : 0x00) | (sprites[0].ExpandX ? 0x01 : 0x00) |
(sprites[1].ExpandX ? 0x02 : 0x00) | (sprites[1].ExpandX ? 0x02 : 0x00) |
(sprites[2].ExpandX ? 0x04 : 0x00) | (sprites[2].ExpandX ? 0x04 : 0x00) |
(sprites[3].ExpandX ? 0x08 : 0x00) | (sprites[3].ExpandX ? 0x08 : 0x00) |
(sprites[4].ExpandX ? 0x10 : 0x00) | (sprites[4].ExpandX ? 0x10 : 0x00) |
(sprites[5].ExpandX ? 0x20 : 0x00) | (sprites[5].ExpandX ? 0x20 : 0x00) |
(sprites[6].ExpandX ? 0x40 : 0x00) | (sprites[6].ExpandX ? 0x40 : 0x00) |
(sprites[7].ExpandX ? 0x80 : 0x00) (sprites[7].ExpandX ? 0x80 : 0x00)
); );
case 0x1E: return ( case 0x1E: return (
(sprites[0].SpriteCollision ? 0x01 : 0x00) | (sprites[0].SpriteCollision ? 0x01 : 0x00) |
(sprites[1].SpriteCollision ? 0x02 : 0x00) | (sprites[1].SpriteCollision ? 0x02 : 0x00) |
(sprites[2].SpriteCollision ? 0x04 : 0x00) | (sprites[2].SpriteCollision ? 0x04 : 0x00) |
(sprites[3].SpriteCollision ? 0x08 : 0x00) | (sprites[3].SpriteCollision ? 0x08 : 0x00) |
(sprites[4].SpriteCollision ? 0x10 : 0x00) | (sprites[4].SpriteCollision ? 0x10 : 0x00) |
(sprites[5].SpriteCollision ? 0x20 : 0x00) | (sprites[5].SpriteCollision ? 0x20 : 0x00) |
(sprites[6].SpriteCollision ? 0x40 : 0x00) | (sprites[6].SpriteCollision ? 0x40 : 0x00) |
(sprites[7].SpriteCollision ? 0x80 : 0x00) (sprites[7].SpriteCollision ? 0x80 : 0x00)
); );
case 0x1F: return ( case 0x1F: return (
(sprites[0].DataCollision ? 0x01 : 0x00) | (sprites[0].DataCollision ? 0x01 : 0x00) |
(sprites[1].DataCollision ? 0x02 : 0x00) | (sprites[1].DataCollision ? 0x02 : 0x00) |
(sprites[2].DataCollision ? 0x04 : 0x00) | (sprites[2].DataCollision ? 0x04 : 0x00) |
(sprites[3].DataCollision ? 0x08 : 0x00) | (sprites[3].DataCollision ? 0x08 : 0x00) |
(sprites[4].DataCollision ? 0x10 : 0x00) | (sprites[4].DataCollision ? 0x10 : 0x00) |
(sprites[5].DataCollision ? 0x20 : 0x00) | (sprites[5].DataCollision ? 0x20 : 0x00) |
(sprites[6].DataCollision ? 0x40 : 0x00) | (sprites[6].DataCollision ? 0x40 : 0x00) |
(sprites[7].DataCollision ? 0x80 : 0x00) (sprites[7].DataCollision ? 0x80 : 0x00)
); );
case 0x20: return borderColor | 0xF0; case 0x20: return borderColor | 0xF0;
case 0x21: return backgroundColor[0] | 0xF0; case 0x21: return backgroundColor[0] | 0xF0;
case 0x22: return backgroundColor[1] | 0xF0; case 0x22: return backgroundColor[1] | 0xF0;
case 0x23: return backgroundColor[2] | 0xF0; case 0x23: return backgroundColor[2] | 0xF0;
case 0x24: return backgroundColor[3] | 0xF0; case 0x24: return backgroundColor[3] | 0xF0;
case 0x25: return spriteMultiColor[0] | 0xF0; case 0x25: return spriteMultiColor[0] | 0xF0;
case 0x26: return spriteMultiColor[1] | 0xF0; case 0x26: return spriteMultiColor[1] | 0xF0;
case 0x27: return sprites[0].Color | 0xF0; case 0x27: return sprites[0].Color | 0xF0;
case 0x28: return sprites[1].Color | 0xF0; case 0x28: return sprites[1].Color | 0xF0;
case 0x29: return sprites[2].Color | 0xF0; case 0x29: return sprites[2].Color | 0xF0;
case 0x2A: return sprites[3].Color | 0xF0; case 0x2A: return sprites[3].Color | 0xF0;
case 0x2B: return sprites[4].Color | 0xF0; case 0x2B: return sprites[4].Color | 0xF0;
case 0x2C: return sprites[5].Color | 0xF0; case 0x2C: return sprites[5].Color | 0xF0;
case 0x2D: return sprites[6].Color | 0xF0; case 0x2D: return sprites[6].Color | 0xF0;
case 0x2E: return sprites[7].Color | 0xF0; case 0x2E: return sprites[7].Color | 0xF0;
default: return 0xFF; default: return 0xFF;
} }
} }
public byte PeekByte(int addr) public byte PeekByte(int addr)
{ {
return (byte)(Peek(addr) & 0xFF); return (byte)(Peek(addr) & 0xFF);
} }
public void Poke(int addr, int val) public void Poke(int addr, int val)
{ {
switch (addr) switch (addr)
{ {
case 0x00: sprites[0].X = (sprites[0].X & 0x100 | val); return; case 0x00: sprites[0].X = (sprites[0].X & 0x100 | val); return;
case 0x01: sprites[1].X = (sprites[1].X & 0x100 | val); return; case 0x01: sprites[1].X = (sprites[1].X & 0x100 | val); return;
case 0x02: sprites[2].X = (sprites[2].X & 0x100 | val); return; case 0x02: sprites[2].X = (sprites[2].X & 0x100 | val); return;
case 0x03: sprites[3].X = (sprites[3].X & 0x100 | val); return; case 0x03: sprites[3].X = (sprites[3].X & 0x100 | val); return;
case 0x04: sprites[4].X = (sprites[4].X & 0x100 | val); return; case 0x04: sprites[4].X = (sprites[4].X & 0x100 | val); return;
case 0x05: sprites[5].X = (sprites[5].X & 0x100 | val); return; case 0x05: sprites[5].X = (sprites[5].X & 0x100 | val); return;
case 0x06: sprites[6].X = (sprites[6].X & 0x100 | val); return; case 0x06: sprites[6].X = (sprites[6].X & 0x100 | val); return;
case 0x07: sprites[7].X = (sprites[7].X & 0x100 | val); return; case 0x07: sprites[7].X = (sprites[7].X & 0x100 | val); return;
case 0x08: sprites[0].Y = val; return; case 0x08: sprites[0].Y = val; return;
case 0x09: sprites[1].Y = val; return; case 0x09: sprites[1].Y = val; return;
case 0x0A: sprites[2].Y = val; return; case 0x0A: sprites[2].Y = val; return;
case 0x0B: sprites[3].Y = val; return; case 0x0B: sprites[3].Y = val; return;
case 0x0C: sprites[4].Y = val; return; case 0x0C: sprites[4].Y = val; return;
case 0x0D: sprites[5].Y = val; return; case 0x0D: sprites[5].Y = val; return;
case 0x0E: sprites[6].Y = val; return; case 0x0E: sprites[6].Y = val; return;
case 0x0F: sprites[7].Y = val; return; case 0x0F: sprites[7].Y = val; return;
case 0x10: case 0x10:
sprites[0].X = (sprites[0].X & 0xFF) | ((val & 0x01) << 8); sprites[0].X = (sprites[0].X & 0xFF) | ((val & 0x01) << 8);
sprites[1].X = (sprites[1].X & 0xFF) | ((val & 0x02) << 7); sprites[1].X = (sprites[1].X & 0xFF) | ((val & 0x02) << 7);
sprites[2].X = (sprites[2].X & 0xFF) | ((val & 0x04) << 6); sprites[2].X = (sprites[2].X & 0xFF) | ((val & 0x04) << 6);
sprites[3].X = (sprites[3].X & 0xFF) | ((val & 0x08) << 5); sprites[3].X = (sprites[3].X & 0xFF) | ((val & 0x08) << 5);
sprites[4].X = (sprites[4].X & 0xFF) | ((val & 0x10) << 4); sprites[4].X = (sprites[4].X & 0xFF) | ((val & 0x10) << 4);
sprites[5].X = (sprites[5].X & 0xFF) | ((val & 0x20) << 3); sprites[5].X = (sprites[5].X & 0xFF) | ((val & 0x20) << 3);
sprites[6].X = (sprites[6].X & 0xFF) | ((val & 0x40) << 2); sprites[6].X = (sprites[6].X & 0xFF) | ((val & 0x40) << 2);
sprites[7].X = (sprites[7].X & 0xFF) | ((val & 0x80) << 1); sprites[7].X = (sprites[7].X & 0xFF) | ((val & 0x80) << 1);
return; return;
case 0x11: case 0x11:
yScroll = (val & 0x07); yScroll = (val & 0x07);
rowSelect = ((val & 0x08) != 0); rowSelect = ((val & 0x08) != 0);
displayEnable = ((val & 0x10) != 0); displayEnable = ((val & 0x10) != 0);
bitmapMode = ((val & 0x20) != 0); bitmapMode = ((val & 0x20) != 0);
extraColorMode = ((val & 0x40) != 0); extraColorMode = ((val & 0x40) != 0);
rasterYCompare = (rasterYCompare & 0xFF) | ((val & 0x80) << 1); rasterYCompare = (rasterYCompare & 0xFF) | ((val & 0x80) << 1);
return; return;
case 0x12: rasterYCompare = (rasterYCompare & 0x100) | val; return; case 0x12: rasterYCompare = (rasterYCompare & 0x100) | val; return;
case 0x13: lightPenX = val; return; case 0x13: lightPenX = val; return;
case 0x14: lightPenY = val; return; case 0x14: lightPenY = val; return;
case 0x15: case 0x15:
sprites[0].Enabled = ((val & 0x01) != 0); sprites[0].Enabled = ((val & 0x01) != 0);
sprites[1].Enabled = ((val & 0x02) != 0); sprites[1].Enabled = ((val & 0x02) != 0);
sprites[2].Enabled = ((val & 0x04) != 0); sprites[2].Enabled = ((val & 0x04) != 0);
sprites[3].Enabled = ((val & 0x08) != 0); sprites[3].Enabled = ((val & 0x08) != 0);
sprites[4].Enabled = ((val & 0x10) != 0); sprites[4].Enabled = ((val & 0x10) != 0);
sprites[5].Enabled = ((val & 0x20) != 0); sprites[5].Enabled = ((val & 0x20) != 0);
sprites[6].Enabled = ((val & 0x40) != 0); sprites[6].Enabled = ((val & 0x40) != 0);
sprites[7].Enabled = ((val & 0x80) != 0); sprites[7].Enabled = ((val & 0x80) != 0);
return; return;
case 0x16: case 0x16:
xScroll = (val & 0x07); xScroll = (val & 0x07);
columnSelect = ((val & 0x08) != 0); columnSelect = ((val & 0x08) != 0);
multiColorMode = ((val & 0x10) != 0); multiColorMode = ((val & 0x10) != 0);
reset = ((val & 0x20) != 0); reset = ((val & 0x20) != 0);
return; return;
case 0x17: case 0x17:
sprites[0].ExpandY = ((val & 0x01) != 0); sprites[0].ExpandY = ((val & 0x01) != 0);
sprites[1].ExpandY = ((val & 0x02) != 0); sprites[1].ExpandY = ((val & 0x02) != 0);
sprites[2].ExpandY = ((val & 0x04) != 0); sprites[2].ExpandY = ((val & 0x04) != 0);
sprites[3].ExpandY = ((val & 0x08) != 0); sprites[3].ExpandY = ((val & 0x08) != 0);
sprites[4].ExpandY = ((val & 0x10) != 0); sprites[4].ExpandY = ((val & 0x10) != 0);
sprites[5].ExpandY = ((val & 0x20) != 0); sprites[5].ExpandY = ((val & 0x20) != 0);
sprites[6].ExpandY = ((val & 0x40) != 0); sprites[6].ExpandY = ((val & 0x40) != 0);
sprites[7].ExpandY = ((val & 0x80) != 0); sprites[7].ExpandY = ((val & 0x80) != 0);
return; return;
case 0x18: case 0x18:
videoMemory = (val & 0xF0) << 6; videoMemory = (val & 0xF0) << 6;
characterBitmap = (val & 0x0E) << 10; characterBitmap = (val & 0x0E) << 10;
return; return;
case 0x19: case 0x19:
rasterInterrupt = ((val & 0x01) != 0); rasterInterrupt = ((val & 0x01) != 0);
dataCollisionInterrupt = ((val & 0x02) != 0); dataCollisionInterrupt = ((val & 0x02) != 0);
spriteCollisionInterrupt = ((val & 0x04) != 0); spriteCollisionInterrupt = ((val & 0x04) != 0);
lightPenInterrupt = ((val & 0x08) != 0); lightPenInterrupt = ((val & 0x08) != 0);
irq = ((val & 0x80) != 0); irq = ((val & 0x80) != 0);
return; return;
case 0x1A: case 0x1A:
rasterInterruptEnable = ((val & 0x01) != 0); rasterInterruptEnable = ((val & 0x01) != 0);
dataCollisionInterruptEnable = ((val & 0x02) != 0); dataCollisionInterruptEnable = ((val & 0x02) != 0);
spriteCollisionInterruptEnable = ((val & 0x04) != 0); spriteCollisionInterruptEnable = ((val & 0x04) != 0);
lightPenInterruptEnable = ((val & 0x08) != 0); lightPenInterruptEnable = ((val & 0x08) != 0);
return; return;
case 0x1B: case 0x1B:
sprites[0].Priority = ((val & 0x01) != 0); sprites[0].Priority = ((val & 0x01) != 0);
sprites[1].Priority = ((val & 0x02) != 0); sprites[1].Priority = ((val & 0x02) != 0);
sprites[2].Priority = ((val & 0x04) != 0); sprites[2].Priority = ((val & 0x04) != 0);
sprites[3].Priority = ((val & 0x08) != 0); sprites[3].Priority = ((val & 0x08) != 0);
sprites[4].Priority = ((val & 0x10) != 0); sprites[4].Priority = ((val & 0x10) != 0);
sprites[5].Priority = ((val & 0x20) != 0); sprites[5].Priority = ((val & 0x20) != 0);
sprites[6].Priority = ((val & 0x40) != 0); sprites[6].Priority = ((val & 0x40) != 0);
sprites[7].Priority = ((val & 0x80) != 0); sprites[7].Priority = ((val & 0x80) != 0);
return; return;
case 0x1C: case 0x1C:
sprites[0].Multicolor = ((val & 0x01) != 0); sprites[0].Multicolor = ((val & 0x01) != 0);
sprites[1].Multicolor = ((val & 0x02) != 0); sprites[1].Multicolor = ((val & 0x02) != 0);
sprites[2].Multicolor = ((val & 0x04) != 0); sprites[2].Multicolor = ((val & 0x04) != 0);
sprites[3].Multicolor = ((val & 0x08) != 0); sprites[3].Multicolor = ((val & 0x08) != 0);
sprites[4].Multicolor = ((val & 0x10) != 0); sprites[4].Multicolor = ((val & 0x10) != 0);
sprites[5].Multicolor = ((val & 0x20) != 0); sprites[5].Multicolor = ((val & 0x20) != 0);
sprites[6].Multicolor = ((val & 0x40) != 0); sprites[6].Multicolor = ((val & 0x40) != 0);
sprites[7].Multicolor = ((val & 0x80) != 0); sprites[7].Multicolor = ((val & 0x80) != 0);
return; return;
case 0x1D: case 0x1D:
sprites[0].ExpandX = ((val & 0x01) != 0); sprites[0].ExpandX = ((val & 0x01) != 0);
sprites[1].ExpandX = ((val & 0x02) != 0); sprites[1].ExpandX = ((val & 0x02) != 0);
sprites[2].ExpandX = ((val & 0x04) != 0); sprites[2].ExpandX = ((val & 0x04) != 0);
sprites[3].ExpandX = ((val & 0x08) != 0); sprites[3].ExpandX = ((val & 0x08) != 0);
sprites[4].ExpandX = ((val & 0x10) != 0); sprites[4].ExpandX = ((val & 0x10) != 0);
sprites[5].ExpandX = ((val & 0x20) != 0); sprites[5].ExpandX = ((val & 0x20) != 0);
sprites[6].ExpandX = ((val & 0x40) != 0); sprites[6].ExpandX = ((val & 0x40) != 0);
sprites[7].ExpandX = ((val & 0x80) != 0); sprites[7].ExpandX = ((val & 0x80) != 0);
return; return;
case 0x1E: case 0x1E:
sprites[0].SpriteCollision = ((val & 0x01) != 0); sprites[0].SpriteCollision = ((val & 0x01) != 0);
sprites[1].SpriteCollision = ((val & 0x02) != 0); sprites[1].SpriteCollision = ((val & 0x02) != 0);
sprites[2].SpriteCollision = ((val & 0x04) != 0); sprites[2].SpriteCollision = ((val & 0x04) != 0);
sprites[3].SpriteCollision = ((val & 0x08) != 0); sprites[3].SpriteCollision = ((val & 0x08) != 0);
sprites[4].SpriteCollision = ((val & 0x10) != 0); sprites[4].SpriteCollision = ((val & 0x10) != 0);
sprites[5].SpriteCollision = ((val & 0x20) != 0); sprites[5].SpriteCollision = ((val & 0x20) != 0);
sprites[6].SpriteCollision = ((val & 0x40) != 0); sprites[6].SpriteCollision = ((val & 0x40) != 0);
sprites[7].SpriteCollision = ((val & 0x80) != 0); sprites[7].SpriteCollision = ((val & 0x80) != 0);
return; return;
case 0x1F: case 0x1F:
sprites[0].DataCollision = ((val & 0x01) != 0); sprites[0].DataCollision = ((val & 0x01) != 0);
sprites[1].DataCollision = ((val & 0x02) != 0); sprites[1].DataCollision = ((val & 0x02) != 0);
sprites[2].DataCollision = ((val & 0x04) != 0); sprites[2].DataCollision = ((val & 0x04) != 0);
sprites[3].DataCollision = ((val & 0x08) != 0); sprites[3].DataCollision = ((val & 0x08) != 0);
sprites[4].DataCollision = ((val & 0x10) != 0); sprites[4].DataCollision = ((val & 0x10) != 0);
sprites[5].DataCollision = ((val & 0x20) != 0); sprites[5].DataCollision = ((val & 0x20) != 0);
sprites[6].DataCollision = ((val & 0x40) != 0); sprites[6].DataCollision = ((val & 0x40) != 0);
sprites[7].DataCollision = ((val & 0x80) != 0); sprites[7].DataCollision = ((val & 0x80) != 0);
return; return;
case 0x20: borderColor = val & 0x0F; return; case 0x20: borderColor = val & 0x0F; return;
case 0x21: backgroundColor[0] = val & 0x0F; return; case 0x21: backgroundColor[0] = val & 0x0F; return;
case 0x22: backgroundColor[1] = val & 0x0F; return; case 0x22: backgroundColor[1] = val & 0x0F; return;
case 0x23: backgroundColor[2] = val & 0x0F; return; case 0x23: backgroundColor[2] = val & 0x0F; return;
case 0x24: backgroundColor[3] = val & 0x0F; return; case 0x24: backgroundColor[3] = val & 0x0F; return;
case 0x25: spriteMultiColor[0] = val & 0x0F; return; case 0x25: spriteMultiColor[0] = val & 0x0F; return;
case 0x26: spriteMultiColor[1] = val & 0x0F; return; case 0x26: spriteMultiColor[1] = val & 0x0F; return;
case 0x27: sprites[0].Color = val & 0x0F; return; case 0x27: sprites[0].Color = val & 0x0F; return;
case 0x28: sprites[1].Color = val & 0x0F; return; case 0x28: sprites[1].Color = val & 0x0F; return;
case 0x29: sprites[2].Color = val & 0x0F; return; case 0x29: sprites[2].Color = val & 0x0F; return;
case 0x2A: sprites[3].Color = val & 0x0F; return; case 0x2A: sprites[3].Color = val & 0x0F; return;
case 0x2B: sprites[4].Color = val & 0x0F; return; case 0x2B: sprites[4].Color = val & 0x0F; return;
case 0x2C: sprites[5].Color = val & 0x0F; return; case 0x2C: sprites[5].Color = val & 0x0F; return;
case 0x2D: sprites[6].Color = val & 0x0F; return; case 0x2D: sprites[6].Color = val & 0x0F; return;
case 0x2E: sprites[7].Color = val & 0x0F; return; case 0x2E: sprites[7].Color = val & 0x0F; return;
default: return; default: return;
} }
} }
public void PokeByte(int addr, byte val) public void PokeByte(int addr, byte val)
{ {
Poke(addr, val); Poke(addr, val);
} }
public int Read(int addr) public int Read(int addr)
{ {
int result; int result;
addr &= 0x3F; addr &= 0x3F;
switch (addr) switch (addr)
{ {
case 0x1E: case 0x1E:
case 0x1F: case 0x1F:
result = Peek(addr); result = Peek(addr);
Poke(addr, 0); Poke(addr, 0);
return result; return result;
default: default:
return Peek(addr & 0x3F); return Peek(addr & 0x3F);
} }
} }
public byte ReadByte(int addr) public byte ReadByte(int addr)
{ {
return (byte)(Read(addr) & 0xFF); return (byte)(Read(addr) & 0xFF);
} }
public void Write(int addr, int val) public void Write(int addr, int val)
{ {
addr &= 0x3F; addr &= 0x3F;
val &= 0xFF; val &= 0xFF;
switch (addr) switch (addr)
{ {
case 0x19: case 0x19:
if ((val & 0x01) != 0) if ((val & 0x01) != 0)
rasterInterrupt = false; rasterInterrupt = false;
if ((val & 0x02) != 0) if ((val & 0x02) != 0)
dataCollisionInterrupt = false; dataCollisionInterrupt = false;
if ((val & 0x04) != 0) if ((val & 0x04) != 0)
spriteCollisionInterrupt = false; spriteCollisionInterrupt = false;
if ((val & 0x08) != 0) if ((val & 0x08) != 0)
lightPenInterrupt = false; lightPenInterrupt = false;
return; return;
case 0x1E: case 0x1E:
case 0x1F: case 0x1F:
case 0x2F: case 0x2F:
case 0x30: case 0x30:
case 0x31: case 0x31:
case 0x32: case 0x32:
case 0x33: case 0x33:
case 0x34: case 0x34:
case 0x35: case 0x35:
case 0x36: case 0x36:
case 0x37: case 0x37:
case 0x38: case 0x38:
case 0x39: case 0x39:
case 0x3A: case 0x3A:
case 0x3B: case 0x3B:
case 0x3C: case 0x3C:
case 0x3D: case 0x3D:
case 0x3E: case 0x3E:
case 0x3F: case 0x3F:
return; return;
default: default:
Poke(addr, val); Poke(addr, val);
return; return;
} }
} }
public void WriteByte(int addr, byte val) public void WriteByte(int addr, byte val)
{ {
Write(addr, val); Write(addr, val);
} }
} }
} }

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public class VicSettings sealed public class VicSettings
{ {
} }
} }

View File

@ -5,123 +5,123 @@ using System.Text;
#pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Vic sealed public partial class Vic
{ {
const int SPRITE_DATA_00 = 0; const int SPRITE_DATA_00 = 0;
const int SPRITE_DATA_01 = 0x400000; const int SPRITE_DATA_01 = 0x400000;
const int SPRITE_DATA_10 = SPRITE_DATA_01 << 1; const int SPRITE_DATA_10 = SPRITE_DATA_01 << 1;
const int SPRITE_DATA_11 = SPRITE_DATA_01 | SPRITE_DATA_10; const int SPRITE_DATA_11 = SPRITE_DATA_01 | SPRITE_DATA_10;
const int SPRITE_DATA_OUTPUT_MASK = SPRITE_DATA_11; const int SPRITE_DATA_OUTPUT_MASK = SPRITE_DATA_11;
sealed class Sprite
{
public bool CrunchMC;
public bool CrunchX;
public bool CrunchY;
public bool Display;
public int ShiftRegister;
public bool ShiftRegisterEnable;
public int Color; sealed class Sprite
public bool DataCollision; {
public bool Enabled; public bool CrunchMC;
public bool ExpandX; public bool CrunchX;
public bool ExpandY; public bool CrunchY;
public bool Multicolor; public bool Display;
public bool Priority; public int ShiftRegister;
public bool SpriteCollision; public bool ShiftRegisterEnable;
public int X;
public int Y;
public Sprite() public int Color;
{ public bool DataCollision;
} public bool Enabled;
public bool ExpandX;
public bool ExpandY;
public bool Multicolor;
public bool Priority;
public bool SpriteCollision;
public int X;
public int Y;
public void Clock() public Sprite()
{ {
} }
public void LoadP(int value) public void Clock()
{ {
} }
public void LoadS(int value) public void LoadP(int value)
{ {
} }
}
Sprite s_CollideSprite; public void LoadS(int value)
int s_Data; {
bool s_OutData; }
int s_OutPixel; }
bool s_Priority;
Sprite[] sprites;
void RenderSprites() Sprite s_CollideSprite;
{ int s_Data;
s_OutData = false; bool s_OutData;
s_CollideSprite = null; int s_OutPixel;
bool s_Priority;
Sprite[] sprites;
foreach (Sprite sprite in sprites) void RenderSprites()
{ {
if (sprite.Display && rasterX == sprite.X) s_OutData = false;
sprite.ShiftRegisterEnable = true; s_CollideSprite = null;
if (sprite.ShiftRegisterEnable) foreach (Sprite sprite in sprites)
{ {
if (sprite.ShiftRegister == 0) if (sprite.Display && rasterX == sprite.X)
{ sprite.ShiftRegisterEnable = true;
sprite.ShiftRegisterEnable = false;
sprite.CrunchMC = true;
sprite.CrunchX = true;
}
else
{
sprite.CrunchX = !sprite.CrunchX || !sprite.ExpandX;
if (sprite.CrunchX)
sprite.CrunchMC = !sprite.CrunchMC || !sprite.Multicolor;
if (sprite.Multicolor) if (sprite.ShiftRegisterEnable)
s_Data = sprite.ShiftRegister & SPRITE_DATA_11; {
else if (sprite.ShiftRegister == 0)
s_Data = (sprite.ShiftRegister << 1) & SPRITE_DATA_10; {
sprite.ShiftRegisterEnable = false;
sprite.CrunchMC = true;
sprite.CrunchX = true;
}
else
{
sprite.CrunchX = !sprite.CrunchX || !sprite.ExpandX;
if (sprite.CrunchX)
sprite.CrunchMC = !sprite.CrunchMC || !sprite.Multicolor;
if (s_CollideSprite == null) if (sprite.Multicolor)
{ s_Data = sprite.ShiftRegister & SPRITE_DATA_11;
if (s_Data == SPRITE_DATA_10) else
s_OutPixel = sprite.Color; s_Data = (sprite.ShiftRegister << 1) & SPRITE_DATA_10;
else if (s_Data == SPRITE_DATA_01)
s_OutPixel = spriteMultiColor[0];
else if (s_Data == SPRITE_DATA_11)
s_OutPixel = spriteMultiColor[1];
if (s_Data != SPRITE_DATA_00) if (s_CollideSprite == null)
{ {
s_CollideSprite = sprite; if (s_Data == SPRITE_DATA_10)
s_OutData = true; s_OutPixel = sprite.Color;
s_Priority = sprite.Priority; else if (s_Data == SPRITE_DATA_01)
} s_OutPixel = spriteMultiColor[0];
} else if (s_Data == SPRITE_DATA_11)
else if (s_Data != SPRITE_DATA_00) s_OutPixel = spriteMultiColor[1];
{
s_CollideSprite.SpriteCollision = true;
sprite.SpriteCollision = true;
spriteCollisionInterrupt = true;
}
if (s_Data != SPRITE_DATA_00 && g_OutData >= GRAPHICS_DATA_10) if (s_Data != SPRITE_DATA_00)
{ {
sprite.DataCollision = true; s_CollideSprite = sprite;
dataCollisionInterrupt = true; s_OutData = true;
} s_Priority = sprite.Priority;
}
}
else if (s_Data != SPRITE_DATA_00)
{
s_CollideSprite.SpriteCollision = true;
sprite.SpriteCollision = true;
spriteCollisionInterrupt = true;
}
if (sprite.CrunchMC && sprite.CrunchX) if (s_Data != SPRITE_DATA_00 && g_OutData >= GRAPHICS_DATA_10)
sprite.ShiftRegister <<= sprite.Multicolor ? 2 : 1; {
} sprite.DataCollision = true;
} dataCollisionInterrupt = true;
} }
}
} if (sprite.CrunchMC && sprite.CrunchX)
sprite.ShiftRegister <<= sprite.Multicolor ? 2 : 1;
}
}
}
}
}
} }

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Vic sealed public partial class Vic
{ {

View File

@ -3,28 +3,28 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Vic sealed public partial class Vic
{ {
int v_Pixel; int v_Pixel;
public void Render() public void Render()
{ {
RenderGraphics(); RenderGraphics();
RenderSprites(); RenderSprites();
if (s_OutData && (!s_Priority || g_OutData < GRAPHICS_DATA_10)) if (s_OutData && (!s_Priority || g_OutData < GRAPHICS_DATA_10))
{ {
if (s_Priority && g_OutData < GRAPHICS_DATA_10) if (s_Priority && g_OutData < GRAPHICS_DATA_10)
v_Pixel = s_OutPixel; v_Pixel = s_OutPixel;
else else
v_Pixel = g_OutPixel; v_Pixel = g_OutPixel;
} }
else else
{ {
v_Pixel = g_OutPixel; v_Pixel = g_OutPixel;
} }
} }
} }
} }

View File

@ -6,81 +6,81 @@ using System.Text;
#pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete
#pragma warning disable 169 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 169 //adelikat: Disable dumb warnings until this file is complete
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public class VicColumnState sealed public class VicColumnState
{ {
public VicBAType BA; public VicBAType BA;
public VicFetchType Fetch; public VicFetchType Fetch;
public bool HBlank; public bool HBlank;
public int RasterX; public int RasterX;
} }
public enum VicActType public enum VicActType
{ {
None, None,
SpriteDMA, SpriteDMA,
SpriteExpandY, SpriteExpandY,
RCAdvance, RCAdvance,
RasterAdvance, RasterAdvance,
RasterAdvanceBottom, RasterAdvanceBottom,
VCReset, VCReset,
} }
public enum VicBAType public enum VicBAType
{ {
None, None,
Badline, Badline,
Sprite0, Sprite0,
Sprite01, Sprite01,
Sprite012, Sprite012,
Sprite12, Sprite12,
Sprite123, Sprite123,
Sprite23, Sprite23,
Sprite234, Sprite234,
Sprite34, Sprite34,
Sprite345, Sprite345,
Sprite45, Sprite45,
Sprite456, Sprite456,
Sprite56, Sprite56,
Sprite567, Sprite567,
Sprite67, Sprite67,
Sprite7 Sprite7
} }
public enum VicFetchType public enum VicFetchType
{ {
None, None,
Graphics, Graphics,
Color, Color,
Idle, Idle,
Refresh, Refresh,
Sprite, Sprite,
Pointer Pointer
} }
public enum VicRowType public enum VicRowType
{ {
None, None,
ScreenVisible, ScreenVisible,
ScreenBlank, ScreenBlank,
ResetVCBase ResetVCBase
} }
sealed public class VicTiming sealed public class VicTiming
{ {
public int ColumnCount; public int ColumnCount;
public int DelayColumn; public int DelayColumn;
public int RasterAdvanceColumn; public int RasterAdvanceColumn;
public int RasterCount; public int RasterCount;
public int RasterWidth; public int RasterWidth;
} }
sealed public partial class Vic sealed public partial class Vic
{ {
int frequency; int frequency;
VicColumnState[] pipelineColumns; VicColumnState[] pipelineColumns;
VicRowType[] pipelineRows; VicRowType[] pipelineRows;
int rasterCount; int rasterCount;
int rasterWidth; int rasterWidth;
} }
} }

View File

@ -8,7 +8,7 @@ using BizHawk.Emulation.Common;
#pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 649 //adelikat: Disable dumb warnings until this file is complete
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
sealed public partial class Vic : IVideoProvider sealed public partial class Vic : IVideoProvider
{ {

View File

@ -1,59 +1,58 @@
using BizHawk.Emulation.Computers.Commodore64.Experimental.Chips.Internals; using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental.Chips namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
static public class ChipPresets static public class ChipPresets
{ {
static public Cia Cia6526(bool todJumper) { return new Cia(Settings6526(todJumper)); } static public Cia Cia6526(bool todJumper) { return new Cia(Settings6526(todJumper)); }
static public Cia Cia6526A(bool todJumper) { return new Cia(Settings6526A(todJumper)); } static public Cia Cia6526A(bool todJumper) { return new Cia(Settings6526A(todJumper)); }
static public Cpu Cpu6510() { return new Cpu(); } static public Cpu Cpu6510() { return new Cpu(); }
static public Ram Ram2114() { return new Ram(0x1000, 0x0FFF, 0x0F); } static public Ram Ram2114() { return new Ram(0x1000, 0x0FFF, 0x0F); }
static public Ram Ram4864() { return new Ram(0x10000, 0xFFFF, 0xFF); } static public Ram Ram4864() { return new Ram(0x10000, 0xFFFF, 0xFF); }
static public Rom Rom2332(byte[] data) { return new Rom(0x1000, 0xFFF, data); } static public Rom Rom2332(byte[] data) { return new Rom(0x1000, 0xFFF, data); }
static public Rom Rom2364(byte[] data) { return new Rom(0x2000, 0x1FFF, data); } static public Rom Rom2364(byte[] data) { return new Rom(0x2000, 0x1FFF, data); }
static public Sid Sid6581() { return new Sid(Settings6581()); } static public Sid Sid6581() { return new Sid(Settings6581()); }
static public Sid Sid8580() { return new Sid(Settings8580()); } static public Sid Sid8580() { return new Sid(Settings8580()); }
static public Vic Vic6567() { return new Vic(Settings6567()); } static public Vic Vic6567() { return new Vic(Settings6567()); }
static public Vic Vic6569() { return new Vic(Settings6569()); } static public Vic Vic6569() { return new Vic(Settings6569()); }
static private CiaSettings Settings6526(bool todJumper) static private CiaSettings Settings6526(bool todJumper)
{ {
CiaSettings result = new CiaSettings(); CiaSettings result = new CiaSettings();
return result; return result;
} }
static private CiaSettings Settings6526A(bool todJumper) static private CiaSettings Settings6526A(bool todJumper)
{ {
CiaSettings result = new CiaSettings(); CiaSettings result = new CiaSettings();
return result; return result;
} }
static private VicSettings Settings6567() static private VicSettings Settings6567()
{ {
VicSettings result = new VicSettings(); VicSettings result = new VicSettings();
return result; return result;
} }
static private VicSettings Settings6569() static private VicSettings Settings6569()
{ {
VicSettings result = new VicSettings(); VicSettings result = new VicSettings();
return result; return result;
} }
static private SidSettings Settings6581() static private SidSettings Settings6581()
{ {
SidSettings result = new SidSettings(); SidSettings result = new SidSettings();
return result; return result;
} }
static private SidSettings Settings8580() static private SidSettings Settings8580()
{ {
SidSettings result = new SidSettings(); SidSettings result = new SidSettings();
return result; return result;
} }
} }
} }

View File

@ -3,30 +3,30 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.Experimental namespace BizHawk.Emulation.Cores.Computers.Commodore64.Experimental
{ {
public interface IMotherboard public interface IMotherboard
{ {
void ExecuteFrame(); void ExecuteFrame();
byte PeekBasicRom(int addr); byte PeekBasicRom(int addr);
byte PeekCartridge(int addr); byte PeekCartridge(int addr);
byte PeekCharRom(int addr); byte PeekCharRom(int addr);
byte PeekCpu(int addr); byte PeekCpu(int addr);
byte PeekKernalRom(int addr); byte PeekKernalRom(int addr);
byte PeekRam(int addr); byte PeekRam(int addr);
byte PeekSerial(int addr); byte PeekSerial(int addr);
byte PeekSid(int addr); byte PeekSid(int addr);
byte PeekVic(int addr); byte PeekVic(int addr);
void PokeBasicRom(int addr, byte val); void PokeBasicRom(int addr, byte val);
void PokeCartridge(int addr, byte val); void PokeCartridge(int addr, byte val);
void PokeCharRom(int addr, byte val); void PokeCharRom(int addr, byte val);
void PokeCpu(int addr, byte val); void PokeCpu(int addr, byte val);
void PokeKernalRom(int addr, byte val); void PokeKernalRom(int addr, byte val);
void PokeRam(int addr, byte val); void PokeRam(int addr, byte val);
void PokeSerial(int addr, byte val); void PokeSerial(int addr, byte val);
void PokeSid(int addr, byte val); void PokeSid(int addr, byte val);
void PokeVic(int addr, byte val); void PokeVic(int addr, byte val);
} }
} }

View File

@ -3,11 +3,11 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64 namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public struct InputFileInfo public struct InputFileInfo
{ {
public byte[] Data; public byte[] Data;
public string Extension; public string Extension;
} }
} }

View File

@ -1,9 +1,7 @@
using System; using System;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Computers.Commodore64.Cartridge;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public class CartridgePort sealed public class CartridgePort
{ {

View File

@ -1,7 +1,7 @@
using System; using System;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public class CassettePort public class CassettePort
{ {

View File

@ -1,6 +1,6 @@
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// used as Color RAM in C64 // used as Color RAM in C64

View File

@ -1,24 +1,24 @@
using System; using System;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// ROM chips // ROM chips
// 2332: 32 kbit (4kbyte) // 2332: 32 kbit (4kbyte)
// 2364: 64 kbit (8kbyte) // 2364: 64 kbit (8kbyte)
// 23128: 128 kbit (16kbyte) // 23128: 128 kbit (16kbyte)
public enum Chip23XXmodel public enum Chip23XXmodel
{ {
Chip2332, Chip2332,
Chip2364, Chip2364,
Chip23128 Chip23128
} }
sealed public class Chip23XX sealed public class Chip23XX
{ {
int addrMask; int addrMask;
byte[] rom; byte[] rom;
public Chip23XX(Chip23XXmodel model, byte[] data) public Chip23XX(Chip23XXmodel model, byte[] data)
{ {
@ -55,6 +55,6 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public void SyncState(Serializer ser) public void SyncState(Serializer ser)
{ {
SaveState.SyncObject(ser, this); SaveState.SyncObject(ser, this);
} }
} }
} }

View File

@ -1,6 +1,6 @@
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// DRAM for the c64 // DRAM for the c64
// 4164 = 64 kbit // 4164 = 64 kbit

View File

@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// an extension of the 6502 processor // an extension of the 6502 processor

View File

@ -1,7 +1,7 @@
using System; using System;
#if false #if false
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// via // via
public class MOS6522 : Timer public class MOS6522 : Timer

View File

@ -1,7 +1,7 @@
using System; using System;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// MOS technology 6526 "CIA" // MOS technology 6526 "CIA"
// //
@ -9,11 +9,11 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// * CS, R/W and RS# pins are not emulated. (not needed) // * CS, R/W and RS# pins are not emulated. (not needed)
// * A low RES pin is emulated via HardReset(). // * A low RES pin is emulated via HardReset().
sealed public class MOS6526 sealed public class MOS6526
{ {
// ------------------------------------ // ------------------------------------
enum InMode enum InMode
{ {
Phase2, Phase2,
CNT, CNT,
@ -21,36 +21,36 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
TimerAUnderflowCNT TimerAUnderflowCNT
} }
enum OutMode enum OutMode
{ {
Pulse, Pulse,
Toggle Toggle
} }
enum RunMode enum RunMode
{ {
Continuous, Continuous,
Oneshot Oneshot
} }
enum SPMode enum SPMode
{ {
Input, Input,
Output Output
} }
static byte[] PBOnBit = new byte[] { 0x40, 0x80 }; static byte[] PBOnBit = new byte[] { 0x40, 0x80 };
static byte[] PBOnMask = new byte[] { 0xBF, 0x7F }; static byte[] PBOnMask = new byte[] { 0xBF, 0x7F };
// ------------------------------------ // ------------------------------------
public Func<bool> ReadCNT; public Func<bool> ReadCNT;
public Func<bool> ReadFlag; public Func<bool> ReadFlag;
public Func<bool> ReadSP; public Func<bool> ReadSP;
// ------------------------------------ // ------------------------------------
bool alarmSelect; bool alarmSelect;
Region chipRegion; Region chipRegion;
bool cntPos; bool cntPos;
bool enableIntAlarm; bool enableIntAlarm;
@ -62,9 +62,9 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
bool intSP; bool intSP;
bool[] intTimer; bool[] intTimer;
bool pinCnt; bool pinCnt;
bool pinCntLast; bool pinCntLast;
bool pinPC; bool pinPC;
bool pinSP; bool pinSP;
byte sr; byte sr;
int[] timerDelay; int[] timerDelay;
InMode[] timerInMode; InMode[] timerInMode;
@ -98,47 +98,47 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
todAlarm = new byte[4]; todAlarm = new byte[4];
SetTodIn(chipRegion); SetTodIn(chipRegion);
portA = new LatchedPort(); portA = new LatchedPort();
portB = new LatchedPort(); portB = new LatchedPort();
timer = new int[2]; timer = new int[2];
timerLatch = new int[2]; timerLatch = new int[2];
timerOn = new bool[2]; timerOn = new bool[2];
underflow = new bool[2]; underflow = new bool[2];
pinSP = true; pinSP = true;
} }
// ------------------------------------ // ------------------------------------
public void ExecutePhase1() public void ExecutePhase1()
{ {
// unsure if the timer actually operates in ph1 // unsure if the timer actually operates in ph1
pinIRQ = !( pinIRQ = !(
(intTimer[0] && enableIntTimer[0]) || (intTimer[0] && enableIntTimer[0]) ||
(intTimer[1] && enableIntTimer[1]) || (intTimer[1] && enableIntTimer[1]) ||
(intAlarm && enableIntAlarm) || (intAlarm && enableIntAlarm) ||
(intSP && enableIntSP) || (intSP && enableIntSP) ||
(intFlag && enableIntFlag) (intFlag && enableIntFlag)
); );
} }
public void ExecutePhase2() public void ExecutePhase2()
{ {
{ {
bool sumCnt = ReadCNT(); bool sumCnt = ReadCNT();
cntPos |= (!pinCntLast && sumCnt); cntPos |= (!pinCntLast && sumCnt);
pinCntLast = sumCnt; pinCntLast = sumCnt;
pinPC = true; pinPC = true;
TODRun(); TODRun();
if (timerPulse[0]) if (timerPulse[0])
{ {
portA.Latch &= PBOnMask[0]; portA.Latch &= PBOnMask[0];
} }
if (timerPulse[1]) if (timerPulse[1])
{ {
portB.Latch &= PBOnMask[1]; portB.Latch &= PBOnMask[1];
} }
if (timerDelay[0] == 0) if (timerDelay[0] == 0)
@ -209,7 +209,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
pinCnt = false; pinCnt = false;
pinPC = true; pinPC = true;
} }
private void SetTodIn(Region region) private void SetTodIn(Region region)
{ {
@ -230,7 +230,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
private byte BCDAdd(byte i, byte j, out bool overflow) private byte BCDAdd(byte i, byte j, out bool overflow)
{ {
{ {
int lo; int lo;
int hi; int hi;
@ -255,13 +255,13 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
private void TimerRun(int index) private void TimerRun(int index)
{ {
{ {
if (timerOn[index]) if (timerOn[index])
{ {
int t = timer[index]; int t = timer[index];
bool u = false; bool u = false;
{ {
switch (timerInMode[index]) switch (timerInMode[index])
{ {
@ -270,8 +270,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
if (cntPos) if (cntPos)
{ {
t--; t--;
u = (t == 0); u = (t == 0);
intTimer[index] |= (t == 0); intTimer[index] |= (t == 0);
} }
break; break;
case InMode.Phase2: case InMode.Phase2:
@ -285,8 +285,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
if (underflow[0]) if (underflow[0])
{ {
t--; t--;
u = (t == 0); u = (t == 0);
intTimer[index] |= (t == 0); intTimer[index] |= (t == 0);
} }
break; break;
case InMode.TimerAUnderflowCNT: case InMode.TimerAUnderflowCNT:
@ -294,8 +294,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
if (underflow[0] && pinCnt) if (underflow[0] && pinCnt)
{ {
t--; t--;
u = (t == 0); u = (t == 0);
intTimer[index] |= (t == 0); intTimer[index] |= (t == 0);
} }
break; break;
} }
@ -303,23 +303,23 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// underflow? // underflow?
if (u) if (u)
{ {
timerDelay[index] = 1; timerDelay[index] = 1;
t = timerLatch[index]; t = timerLatch[index];
if (timerRunMode[index] == RunMode.Oneshot) if (timerRunMode[index] == RunMode.Oneshot)
timerOn[index] = false; timerOn[index] = false;
if (timerPortEnable[index]) if (timerPortEnable[index])
{ {
// force port B bit to output // force port B bit to output
portB.Direction |= PBOnBit[index]; portB.Direction |= PBOnBit[index];
switch (timerOutMode[index]) switch (timerOutMode[index])
{ {
case OutMode.Pulse: case OutMode.Pulse:
timerPulse[index] = true; timerPulse[index] = true;
portB.Latch |= PBOnBit[index]; portB.Latch |= PBOnBit[index];
break; break;
case OutMode.Toggle: case OutMode.Toggle:
portB.Latch ^= PBOnBit[index]; portB.Latch ^= PBOnBit[index];
break; break;
} }
} }
@ -334,7 +334,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
private void TODRun() private void TODRun()
{ {
{ {
bool todV; bool todV;
@ -416,15 +416,15 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
return val; return val;
} }
public bool ReadCNTBuffer() public bool ReadCNTBuffer()
{ {
return pinCnt; return pinCnt;
} }
public bool ReadPCBuffer() public bool ReadPCBuffer()
{ {
return pinPC; return pinPC;
} }
private byte ReadRegister(int addr) private byte ReadRegister(int addr)
{ {
@ -440,10 +440,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
val = (byte)(portB.ReadInput(ReadPortB()) & PortBMask); val = (byte)(portB.ReadInput(ReadPortB()) & PortBMask);
break; break;
case 0x2: case 0x2:
val = portA.Direction; val = portA.Direction;
break; break;
case 0x3: case 0x3:
val = portB.Direction; val = portB.Direction;
break; break;
case 0x4: case 0x4:
timerVal = ReadTimerValue(0); timerVal = ReadTimerValue(0);
@ -527,10 +527,10 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
return val; return val;
} }
public bool ReadSPBuffer() public bool ReadSPBuffer()
{ {
return pinSP; return pinSP;
} }
private int ReadTimerValue(int index) private int ReadTimerValue(int index)
{ {
@ -549,7 +549,7 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
public void SyncState(Serializer ser) public void SyncState(Serializer ser)
{ {
SaveState.SyncObject(ser, this); SaveState.SyncObject(ser, this);
} }
public void Write(int addr, byte val) public void Write(int addr, byte val)
@ -602,16 +602,16 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
switch (addr) switch (addr)
{ {
case 0x0: case 0x0:
portA.Latch = val; portA.Latch = val;
break; break;
case 0x1: case 0x1:
portB.Latch = val; portB.Latch = val;
break; break;
case 0x2: case 0x2:
portA.Direction = val; portA.Direction = val;
break; break;
case 0x3: case 0x3:
portB.Direction = val; portB.Direction = val;
break; break;
case 0x4: case 0x4:
timerLatch[0] &= 0xFF00; timerLatch[0] &= 0xFF00;
@ -707,13 +707,13 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// ------------------------------------ // ------------------------------------
public byte PortAMask = 0xFF; public byte PortAMask = 0xFF;
public byte PortBMask = 0xFF; public byte PortBMask = 0xFF;
bool pinIRQ; bool pinIRQ;
LatchedPort portA; LatchedPort portA;
LatchedPort portB; LatchedPort portB;
int[] timer; int[] timer;
int[] timerLatch; int[] timerLatch;
bool[] timerOn; bool[] timerOn;
bool[] underflow; bool[] underflow;
@ -730,54 +730,54 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
pinIRQ = true; pinIRQ = true;
} }
public byte PortAData public byte PortAData
{ {
get get
{ {
return portA.ReadOutput(); return portA.ReadOutput();
} }
} }
public byte PortADirection public byte PortADirection
{ {
get get
{ {
return portA.Direction; return portA.Direction;
} }
} }
public byte PortALatch public byte PortALatch
{ {
get get
{ {
return portA.Latch; return portA.Latch;
} }
} }
public byte PortBData public byte PortBData
{ {
get get
{ {
return portB.ReadOutput(); return portB.ReadOutput();
} }
} }
public byte PortBDirection public byte PortBDirection
{ {
get get
{ {
return portB.Direction; return portB.Direction;
} }
} }
public byte PortBLatch public byte PortBLatch
{ {
get get
{ {
return portB.Latch; return portB.Latch;
} }
} }
public bool ReadIRQBuffer() { return pinIRQ; } public bool ReadIRQBuffer() { return pinIRQ; }
} }
} }

View File

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

View File

@ -1,41 +1,41 @@
using System.Drawing; using System.Drawing;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// vic pal // vic pal
static public class MOS6569 static public class MOS6569
{ {
static int cycles = 63; static int cycles = 63;
static int scanwidth = cycles * 8; static int scanwidth = cycles * 8;
static int lines = 312; static int lines = 312;
static int vblankstart = 0x12C % lines; static int vblankstart = 0x12C % lines;
static int vblankend = 0x00F % lines; static int vblankend = 0x00F % lines;
static int hblankoffset = 20; static int hblankoffset = 20;
static int hblankstart = (0x17C + hblankoffset) % scanwidth; static int hblankstart = (0x17C + hblankoffset) % scanwidth;
static int hblankend = (0x1E0 + hblankoffset) % scanwidth; static int hblankend = (0x1E0 + hblankoffset) % scanwidth;
static int[] timing = Vic.TimingBuilder_XRaster(0x194, 0x1F8, scanwidth, -1, -1); static int[] timing = Vic.TimingBuilder_XRaster(0x194, 0x1F8, scanwidth, -1, -1);
static int[] fetch = Vic.TimingBuilder_Fetch(timing, 0x164); static int[] fetch = Vic.TimingBuilder_Fetch(timing, 0x164);
static int[] ba = Vic.TimingBuilder_BA(fetch); static int[] ba = Vic.TimingBuilder_BA(fetch);
static int[] act = Vic.TimingBuilder_Act(timing, 0x004, 0x14C, hblankstart, hblankend); static int[] act = Vic.TimingBuilder_Act(timing, 0x004, 0x14C, hblankstart, hblankend);
static int[][] pipeline = new int[][] static int[][] pipeline = new int[][]
{ {
timing, timing,
fetch, fetch,
ba, ba,
act act
}; };
static public Vic Create() static public Vic Create()
{ {
return new Vic( return new Vic(
cycles, lines, cycles, lines,
pipeline, pipeline,
17734472 / 18, 17734472 / 18,
hblankstart, hblankend, hblankstart, hblankend,
vblankstart, vblankend vblankstart, vblankend
); );
} }
} }
} }

View File

@ -1,9 +1,9 @@
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// sid // sid
static public class MOS6581 static public class MOS6581
{ {
static int[][] waveTable = new int[][] static int[][] waveTable = new int[][]
{ {
new int[] { new int[] {
0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF, 0xFFF,

View File

@ -1,7 +1,7 @@
using System; using System;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// emulates the PLA // emulates the PLA
// which handles all bank switching // which handles all bank switching

View File

@ -1,7 +1,7 @@
using System; using System;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public class LatchedPort sealed public class LatchedPort
{ {

View File

@ -1,7 +1,7 @@
using System; using System;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// the functions on this port are at the point of // the functions on this port are at the point of
// view of an external device. // view of an external device.

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Sid sealed public partial class Sid
{ {

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Sid sealed public partial class Sid
{ {

View File

@ -5,7 +5,7 @@ using BizHawk.Common;
#pragma warning disable 169 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 169 //adelikat: Disable dumb warnings until this file is complete
#pragma warning disable 219 //adelikat: Disable dumb warnings until this file is complete #pragma warning disable 219 //adelikat: Disable dumb warnings until this file is complete
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Sid sealed public partial class Sid
{ {

View File

@ -1,7 +1,7 @@
using System; using System;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public class UserPort public class UserPort
{ {

View File

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

View File

@ -3,256 +3,256 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Vic sealed public partial class Vic
{ {
const int baResetCounter = 7; const int baResetCounter = 7;
const int pipelineUpdateVc = 1; const int pipelineUpdateVc = 1;
const int pipelineChkSprChunch = 2; const int pipelineChkSprChunch = 2;
const int pipelineUpdateMcBase = 4; const int pipelineUpdateMcBase = 4;
const int pipelineChkBrdL1 = 8; const int pipelineChkBrdL1 = 8;
const int pipelineChkBrdL0 = 16; const int pipelineChkBrdL0 = 16;
const int pipelineChkSprDma = 32; const int pipelineChkSprDma = 32;
const int pipelineChkBrdR0 = 64; const int pipelineChkBrdR0 = 64;
const int pipelineChkSprExp = 128; const int pipelineChkSprExp = 128;
const int pipelineChkBrdR1 = 256; const int pipelineChkBrdR1 = 256;
const int pipelineChkSprDisp = 512; const int pipelineChkSprDisp = 512;
const int pipelineUpdateRc = 1024; const int pipelineUpdateRc = 1024;
const int pipelineHBlankL = 0x10000000; const int pipelineHBlankL = 0x10000000;
const int pipelineHBlankR = 0x20000000; const int pipelineHBlankR = 0x20000000;
const int pipelineHoldX = 0x40000000; const int pipelineHoldX = 0x40000000;
const int rasterIrqLine0Cycle = 1; const int rasterIrqLine0Cycle = 1;
const int rasterIrqLineXCycle = 0; const int rasterIrqLineXCycle = 0;
int parseaddr; int parseaddr;
int parsecycleBAsprite0; int parsecycleBAsprite0;
int parsecycleBAsprite1; int parsecycleBAsprite1;
int parsecycleBAsprite2; int parsecycleBAsprite2;
int parsecycleFetchSpriteIndex; int parsecycleFetchSpriteIndex;
int parsefetch; int parsefetch;
int parsefetchType; int parsefetchType;
int parseba; int parseba;
int parseact; int parseact;
private void ParseCycle() private void ParseCycle()
{ {
{ {
parseaddr = 0x3FFF; parseaddr = 0x3FFF;
parsefetch = pipeline[1][cycleIndex]; parsefetch = pipeline[1][cycleIndex];
parseba = pipeline[2][cycleIndex]; parseba = pipeline[2][cycleIndex];
parseact = pipeline[3][cycleIndex]; parseact = pipeline[3][cycleIndex];
// apply X location // apply X location
rasterX = pipeline[0][cycleIndex]; rasterX = pipeline[0][cycleIndex];
rasterXHold = ((parseact & pipelineHoldX) != 0); rasterXHold = ((parseact & pipelineHoldX) != 0);
// perform fetch // perform fetch
parsefetchType = parsefetch & 0xFF00; parsefetchType = parsefetch & 0xFF00;
if (parsefetchType == 0x100) if (parsefetchType == 0x100)
{ {
// fetch R // fetch R
refreshCounter = (refreshCounter - 1) & 0xFF; refreshCounter = (refreshCounter - 1) & 0xFF;
parseaddr = (0x3F00 | refreshCounter); parseaddr = (0x3F00 | refreshCounter);
ReadMemory(parseaddr); ReadMemory(parseaddr);
} }
else if (parsefetchType == 0x200) else if (parsefetchType == 0x200)
{ {
delayC = xScroll; delayC = xScroll;
if (!idle) if (!idle)
{ {
if (badline) if (badline)
{ {
parseaddr = (pointerVM | vc); parseaddr = (pointerVM | vc);
dataC = ReadMemory(parseaddr); dataC = ReadMemory(parseaddr);
dataC |= ((int)ReadColorRam(parseaddr) & 0xF) << 8; dataC |= ((int)ReadColorRam(parseaddr) & 0xF) << 8;
bufferC[vmli] = dataC; bufferC[vmli] = dataC;
} }
else else
{ {
dataC = bufferC[vmli]; dataC = bufferC[vmli];
} }
} }
else else
{ {
dataC = 0; dataC = 0;
bufferC[vmli] = dataC; bufferC[vmli] = dataC;
} }
srC <<= 12; srC <<= 12;
srC |= dataC; srC |= dataC;
} }
else if (parsefetchType == 0x300) else if (parsefetchType == 0x300)
{ {
// fetch G // fetch G
if (idle) if (idle)
parseaddr = 0x3FFF; parseaddr = 0x3FFF;
else else
{ {
if (bitmapMode) if (bitmapMode)
parseaddr = (rc | (vc << 3) | ((pointerCB & 0x4) << 11)); parseaddr = (rc | (vc << 3) | ((pointerCB & 0x4) << 11));
else else
parseaddr = (rc | ((dataC & 0xFF) << 3) | (pointerCB << 11)); parseaddr = (rc | ((dataC & 0xFF) << 3) | (pointerCB << 11));
} }
if (extraColorMode) if (extraColorMode)
parseaddr &= 0x39FF; parseaddr &= 0x39FF;
dataG = ReadMemory(parseaddr); dataG = ReadMemory(parseaddr);
sr |= dataG << (7 - xScroll); sr |= dataG << (7 - xScroll);
srSync |= 0xAA << (7 - xScroll); srSync |= 0xAA << (7 - xScroll);
if (!idle) if (!idle)
{ {
bufferG[vmli] = dataG; bufferG[vmli] = dataG;
vmli = (vmli + 1) & 0x3F; vmli = (vmli + 1) & 0x3F;
vc = (vc + 1) & 0x3FF; vc = (vc + 1) & 0x3FF;
} }
} }
else if (parsefetchType == 0x400) else if (parsefetchType == 0x400)
{ {
// fetch I // fetch I
parseaddr = (extraColorMode ? 0x39FF : 0x3FFF); parseaddr = (extraColorMode ? 0x39FF : 0x3FFF);
dataG = ReadMemory(parseaddr); dataG = ReadMemory(parseaddr);
} }
else if (parsefetchType == 0x500) else if (parsefetchType == 0x500)
{ {
// fetch none // fetch none
} }
else else
{ {
parsecycleFetchSpriteIndex = (parsefetch & 0x7); parsecycleFetchSpriteIndex = (parsefetch & 0x7);
if ((parsefetch & 0xF0) == 0) if ((parsefetch & 0xF0) == 0)
{ {
// fetch P // fetch P
parseaddr = (0x3F8 | pointerVM | parsecycleFetchSpriteIndex); parseaddr = (0x3F8 | pointerVM | parsecycleFetchSpriteIndex);
sprites[parsecycleFetchSpriteIndex].pointer = ReadMemory(parseaddr); sprites[parsecycleFetchSpriteIndex].pointer = ReadMemory(parseaddr);
sprites[parsecycleFetchSpriteIndex].shiftEnable = false; sprites[parsecycleFetchSpriteIndex].shiftEnable = false;
} }
else else
{ {
// fetch S // fetch S
if (sprites[parsecycleFetchSpriteIndex].dma) if (sprites[parsecycleFetchSpriteIndex].dma)
{ {
SpriteGenerator spr = sprites[parsecycleFetchSpriteIndex]; SpriteGenerator spr = sprites[parsecycleFetchSpriteIndex];
parseaddr = (spr.mc | (spr.pointer << 6)); parseaddr = (spr.mc | (spr.pointer << 6));
spr.sr <<= 8; spr.sr <<= 8;
spr.sr |= ReadMemory(parseaddr); spr.sr |= ReadMemory(parseaddr);
spr.mc++; spr.mc++;
} }
} }
} }
// perform BA flag manipulation // perform BA flag manipulation
if (parseba == 0x0000) if (parseba == 0x0000)
{ {
pinBA = true; pinBA = true;
} }
else if (parseba == 0x1000) else if (parseba == 0x1000)
{ {
pinBA = !badline; pinBA = !badline;
} }
else else
{ {
parsecycleBAsprite0 = (parseba & 0x000F); parsecycleBAsprite0 = (parseba & 0x000F);
parsecycleBAsprite1 = (parseba & 0x00F0) >> 4; parsecycleBAsprite1 = (parseba & 0x00F0) >> 4;
parsecycleBAsprite2 = (parseba & 0x0F00) >> 8; parsecycleBAsprite2 = (parseba & 0x0F00) >> 8;
if ((parsecycleBAsprite0 < 8 && sprites[parsecycleBAsprite0].dma) || if ((parsecycleBAsprite0 < 8 && sprites[parsecycleBAsprite0].dma) ||
(parsecycleBAsprite1 < 8 && sprites[parsecycleBAsprite1].dma) || (parsecycleBAsprite1 < 8 && sprites[parsecycleBAsprite1].dma) ||
(parsecycleBAsprite2 < 8 && sprites[parsecycleBAsprite2].dma)) (parsecycleBAsprite2 < 8 && sprites[parsecycleBAsprite2].dma))
pinBA = false; pinBA = false;
else else
pinBA = true; pinBA = true;
} }
// perform actions // perform actions
borderCheckLEnable = ((parseact & (pipelineChkBrdL0 | pipelineChkBrdL1)) != 0); borderCheckLEnable = ((parseact & (pipelineChkBrdL0 | pipelineChkBrdL1)) != 0);
borderCheckREnable = ((parseact & (pipelineChkBrdR0 | pipelineChkBrdR1)) != 0); borderCheckREnable = ((parseact & (pipelineChkBrdR0 | pipelineChkBrdR1)) != 0);
hblankCheckEnableL = ((parseact & pipelineHBlankL) != 0); hblankCheckEnableL = ((parseact & pipelineHBlankL) != 0);
hblankCheckEnableR = ((parseact & pipelineHBlankR) != 0); hblankCheckEnableR = ((parseact & pipelineHBlankR) != 0);
if (parseact != 0) if (parseact != 0)
{ {
if ((parseact & pipelineChkSprChunch) != 0) if ((parseact & pipelineChkSprChunch) != 0)
{ {
foreach (SpriteGenerator spr in sprites) foreach (SpriteGenerator spr in sprites)
{ {
if (spr.yCrunch) if (spr.yCrunch)
spr.mcbase += 2; spr.mcbase += 2;
spr.shiftEnable = false; spr.shiftEnable = false;
spr.xCrunch = !spr.xExpand; spr.xCrunch = !spr.xExpand;
spr.multicolorCrunch = !spr.multicolor; spr.multicolorCrunch = !spr.multicolor;
} }
} }
else if ((parseact & pipelineChkSprDisp) != 0) else if ((parseact & pipelineChkSprDisp) != 0)
{ {
foreach (SpriteGenerator spr in sprites) foreach (SpriteGenerator spr in sprites)
{ {
spr.mc = spr.mcbase; spr.mc = spr.mcbase;
if (spr.dma && spr.y == (rasterLine & 0xFF)) if (spr.dma && spr.y == (rasterLine & 0xFF))
{ {
spr.display = true; spr.display = true;
} }
} }
} }
else if ((parseact & pipelineChkSprDma) != 0) else if ((parseact & pipelineChkSprDma) != 0)
{ {
foreach (SpriteGenerator spr in sprites) foreach (SpriteGenerator spr in sprites)
{ {
if (spr.enable && spr.y == (rasterLine & 0xFF) && !spr.dma) if (spr.enable && spr.y == (rasterLine & 0xFF) && !spr.dma)
{ {
spr.dma = true; spr.dma = true;
spr.mcbase = 0; spr.mcbase = 0;
spr.yCrunch = !spr.yExpand; spr.yCrunch = !spr.yExpand;
} }
} }
} }
else if ((parseact & pipelineChkSprExp) != 0) else if ((parseact & pipelineChkSprExp) != 0)
{ {
foreach (SpriteGenerator spr in sprites) foreach (SpriteGenerator spr in sprites)
{ {
if (spr.yExpand) if (spr.yExpand)
spr.yCrunch ^= true; spr.yCrunch ^= true;
} }
} }
else if ((parseact & pipelineUpdateMcBase) != 0) else if ((parseact & pipelineUpdateMcBase) != 0)
{ {
foreach (SpriteGenerator spr in sprites) foreach (SpriteGenerator spr in sprites)
{ {
if (spr.yCrunch) if (spr.yCrunch)
{ {
spr.mcbase++; spr.mcbase++;
if (spr.mcbase == 63) if (spr.mcbase == 63)
{ {
spr.dma = false; spr.dma = false;
spr.display = false; spr.display = false;
} }
} }
} }
} }
else if ((parseact & pipelineUpdateRc) != 0) else if ((parseact & pipelineUpdateRc) != 0)
{ {
if (rc == 7) if (rc == 7)
{ {
idle = true; idle = true;
vcbase = vc; vcbase = vc;
} }
if (!idle) if (!idle)
rc = (rc + 1) & 0x7; rc = (rc + 1) & 0x7;
} }
else if ((parseact & pipelineUpdateVc) != 0) else if ((parseact & pipelineUpdateVc) != 0)
{ {
vc = vcbase; vc = vcbase;
vmli = 0; vmli = 0;
if (badline) if (badline)
rc = 0; rc = 0;
} }
} }
cycleIndex++; cycleIndex++;
} }
} }
} }
} }

View File

@ -3,496 +3,496 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Vic sealed public partial class Vic
{ {
public byte Peek(int addr) public byte Peek(int addr)
{ {
return ReadRegister((addr & 0x3F)); return ReadRegister((addr & 0x3F));
} }
public void Poke(int addr, byte val) public void Poke(int addr, byte val)
{ {
WriteRegister((addr & 0x3F), val); WriteRegister((addr & 0x3F), val);
} }
public byte Read(int addr) public byte Read(int addr)
{ {
byte result; byte result;
addr &= 0x3F; addr &= 0x3F;
switch (addr) switch (addr)
{ {
case 0x1E: case 0x1E:
case 0x1F: case 0x1F:
// reading clears these // reading clears these
result = ReadRegister(addr); result = ReadRegister(addr);
WriteRegister(addr, 0); WriteRegister(addr, 0);
break; break;
default: default:
result = ReadRegister((addr & 0x3F)); result = ReadRegister((addr & 0x3F));
break; break;
} }
return result; return result;
} }
private byte ReadRegister(int addr) private byte ReadRegister(int addr)
{ {
byte result = 0xFF; //unused bit value byte result = 0xFF; //unused bit value
switch (addr) switch (addr)
{ {
case 0x00: case 0x00:
case 0x02: case 0x02:
case 0x04: case 0x04:
case 0x06: case 0x06:
case 0x08: case 0x08:
case 0x0A: case 0x0A:
case 0x0C: case 0x0C:
case 0x0E: case 0x0E:
result = (byte)(sprites[addr >> 1].x & 0xFF); result = (byte)(sprites[addr >> 1].x & 0xFF);
break; break;
case 0x01: case 0x01:
case 0x03: case 0x03:
case 0x05: case 0x05:
case 0x07: case 0x07:
case 0x09: case 0x09:
case 0x0B: case 0x0B:
case 0x0D: case 0x0D:
case 0x0F: case 0x0F:
result = (byte)(sprites[addr >> 1].y & 0xFF); result = (byte)(sprites[addr >> 1].y & 0xFF);
break; break;
case 0x10: case 0x10:
result = (byte)( result = (byte)(
((sprites[0].x >> 8) & 0x01) | ((sprites[0].x >> 8) & 0x01) |
((sprites[1].x >> 7) & 0x02) | ((sprites[1].x >> 7) & 0x02) |
((sprites[2].x >> 6) & 0x04) | ((sprites[2].x >> 6) & 0x04) |
((sprites[3].x >> 5) & 0x08) | ((sprites[3].x >> 5) & 0x08) |
((sprites[4].x >> 4) & 0x10) | ((sprites[4].x >> 4) & 0x10) |
((sprites[5].x >> 3) & 0x20) | ((sprites[5].x >> 3) & 0x20) |
((sprites[6].x >> 2) & 0x40) | ((sprites[6].x >> 2) & 0x40) |
((sprites[7].x >> 1) & 0x80) ((sprites[7].x >> 1) & 0x80)
); );
break; break;
case 0x11: case 0x11:
result = (byte)( result = (byte)(
(yScroll & 0x7) | (yScroll & 0x7) |
(rowSelect ? 0x08 : 0x00) | (rowSelect ? 0x08 : 0x00) |
(displayEnable ? 0x10 : 0x00) | (displayEnable ? 0x10 : 0x00) |
(bitmapMode ? 0x20 : 0x00) | (bitmapMode ? 0x20 : 0x00) |
(extraColorMode ? 0x40 : 0x00) | (extraColorMode ? 0x40 : 0x00) |
((rasterLine & 0x100) >> 1) ((rasterLine & 0x100) >> 1)
); );
break; break;
case 0x12: case 0x12:
result = (byte)(rasterLine & 0xFF); result = (byte)(rasterLine & 0xFF);
break; break;
case 0x13: case 0x13:
result = (byte)(lightPenX & 0xFF); result = (byte)(lightPenX & 0xFF);
break; break;
case 0x14: case 0x14:
result = (byte)(lightPenY & 0xFF); result = (byte)(lightPenY & 0xFF);
break; break;
case 0x15: case 0x15:
result = (byte)( result = (byte)(
(sprites[0].enable ? 0x01 : 0x00) | (sprites[0].enable ? 0x01 : 0x00) |
(sprites[1].enable ? 0x02 : 0x00) | (sprites[1].enable ? 0x02 : 0x00) |
(sprites[2].enable ? 0x04 : 0x00) | (sprites[2].enable ? 0x04 : 0x00) |
(sprites[3].enable ? 0x08 : 0x00) | (sprites[3].enable ? 0x08 : 0x00) |
(sprites[4].enable ? 0x10 : 0x00) | (sprites[4].enable ? 0x10 : 0x00) |
(sprites[5].enable ? 0x20 : 0x00) | (sprites[5].enable ? 0x20 : 0x00) |
(sprites[6].enable ? 0x40 : 0x00) | (sprites[6].enable ? 0x40 : 0x00) |
(sprites[7].enable ? 0x80 : 0x00) (sprites[7].enable ? 0x80 : 0x00)
); );
break; break;
case 0x16: case 0x16:
result &= 0xC0; result &= 0xC0;
result |= (byte)( result |= (byte)(
(xScroll & 0x7) | (xScroll & 0x7) |
(columnSelect ? 0x08 : 0x00) | (columnSelect ? 0x08 : 0x00) |
(multicolorMode ? 0x10 : 0x00) (multicolorMode ? 0x10 : 0x00)
); );
break; break;
case 0x17: case 0x17:
result = (byte)( result = (byte)(
(sprites[0].yExpand ? 0x01 : 0x00) | (sprites[0].yExpand ? 0x01 : 0x00) |
(sprites[1].yExpand ? 0x02 : 0x00) | (sprites[1].yExpand ? 0x02 : 0x00) |
(sprites[2].yExpand ? 0x04 : 0x00) | (sprites[2].yExpand ? 0x04 : 0x00) |
(sprites[3].yExpand ? 0x08 : 0x00) | (sprites[3].yExpand ? 0x08 : 0x00) |
(sprites[4].yExpand ? 0x10 : 0x00) | (sprites[4].yExpand ? 0x10 : 0x00) |
(sprites[5].yExpand ? 0x20 : 0x00) | (sprites[5].yExpand ? 0x20 : 0x00) |
(sprites[6].yExpand ? 0x40 : 0x00) | (sprites[6].yExpand ? 0x40 : 0x00) |
(sprites[7].yExpand ? 0x80 : 0x00) (sprites[7].yExpand ? 0x80 : 0x00)
); );
break; break;
case 0x18: case 0x18:
result &= 0x01; result &= 0x01;
result |= (byte)( result |= (byte)(
((pointerVM & 0x3C00) >> 6) | ((pointerVM & 0x3C00) >> 6) |
((pointerCB & 0x7) << 1) ((pointerCB & 0x7) << 1)
); );
break; break;
case 0x19: case 0x19:
result &= 0x70; result &= 0x70;
result |= (byte)( result |= (byte)(
(intRaster ? 0x01 : 0x00) | (intRaster ? 0x01 : 0x00) |
(intSpriteDataCollision ? 0x02 : 0x00) | (intSpriteDataCollision ? 0x02 : 0x00) |
(intSpriteCollision ? 0x04 : 0x00) | (intSpriteCollision ? 0x04 : 0x00) |
(intLightPen ? 0x08 : 0x00) | (intLightPen ? 0x08 : 0x00) |
(pinIRQ ? 0x00 : 0x80) (pinIRQ ? 0x00 : 0x80)
); );
break; break;
case 0x1A: case 0x1A:
result &= 0xF0; result &= 0xF0;
result |= (byte)( result |= (byte)(
(enableIntRaster ? 0x01 : 0x00) | (enableIntRaster ? 0x01 : 0x00) |
(enableIntSpriteDataCollision ? 0x02 : 0x00) | (enableIntSpriteDataCollision ? 0x02 : 0x00) |
(enableIntSpriteCollision ? 0x04 : 0x00) | (enableIntSpriteCollision ? 0x04 : 0x00) |
(enableIntLightPen ? 0x08 : 0x00) (enableIntLightPen ? 0x08 : 0x00)
); );
break; break;
case 0x1B: case 0x1B:
result = (byte)( result = (byte)(
(sprites[0].priority ? 0x01 : 0x00) | (sprites[0].priority ? 0x01 : 0x00) |
(sprites[1].priority ? 0x02 : 0x00) | (sprites[1].priority ? 0x02 : 0x00) |
(sprites[2].priority ? 0x04 : 0x00) | (sprites[2].priority ? 0x04 : 0x00) |
(sprites[3].priority ? 0x08 : 0x00) | (sprites[3].priority ? 0x08 : 0x00) |
(sprites[4].priority ? 0x10 : 0x00) | (sprites[4].priority ? 0x10 : 0x00) |
(sprites[5].priority ? 0x20 : 0x00) | (sprites[5].priority ? 0x20 : 0x00) |
(sprites[6].priority ? 0x40 : 0x00) | (sprites[6].priority ? 0x40 : 0x00) |
(sprites[7].priority ? 0x80 : 0x00) (sprites[7].priority ? 0x80 : 0x00)
); );
break; break;
case 0x1C: case 0x1C:
result = (byte)( result = (byte)(
(sprites[0].multicolor ? 0x01 : 0x00) | (sprites[0].multicolor ? 0x01 : 0x00) |
(sprites[1].multicolor ? 0x02 : 0x00) | (sprites[1].multicolor ? 0x02 : 0x00) |
(sprites[2].multicolor ? 0x04 : 0x00) | (sprites[2].multicolor ? 0x04 : 0x00) |
(sprites[3].multicolor ? 0x08 : 0x00) | (sprites[3].multicolor ? 0x08 : 0x00) |
(sprites[4].multicolor ? 0x10 : 0x00) | (sprites[4].multicolor ? 0x10 : 0x00) |
(sprites[5].multicolor ? 0x20 : 0x00) | (sprites[5].multicolor ? 0x20 : 0x00) |
(sprites[6].multicolor ? 0x40 : 0x00) | (sprites[6].multicolor ? 0x40 : 0x00) |
(sprites[7].multicolor ? 0x80 : 0x00) (sprites[7].multicolor ? 0x80 : 0x00)
); );
break; break;
case 0x1D: case 0x1D:
result = (byte)( result = (byte)(
(sprites[0].xExpand ? 0x01 : 0x00) | (sprites[0].xExpand ? 0x01 : 0x00) |
(sprites[1].xExpand ? 0x02 : 0x00) | (sprites[1].xExpand ? 0x02 : 0x00) |
(sprites[2].xExpand ? 0x04 : 0x00) | (sprites[2].xExpand ? 0x04 : 0x00) |
(sprites[3].xExpand ? 0x08 : 0x00) | (sprites[3].xExpand ? 0x08 : 0x00) |
(sprites[4].xExpand ? 0x10 : 0x00) | (sprites[4].xExpand ? 0x10 : 0x00) |
(sprites[5].xExpand ? 0x20 : 0x00) | (sprites[5].xExpand ? 0x20 : 0x00) |
(sprites[6].xExpand ? 0x40 : 0x00) | (sprites[6].xExpand ? 0x40 : 0x00) |
(sprites[7].xExpand ? 0x80 : 0x00) (sprites[7].xExpand ? 0x80 : 0x00)
); );
break; break;
case 0x1E: case 0x1E:
result = (byte)( result = (byte)(
(sprites[0].collideSprite ? 0x01 : 0x00) | (sprites[0].collideSprite ? 0x01 : 0x00) |
(sprites[1].collideSprite ? 0x02 : 0x00) | (sprites[1].collideSprite ? 0x02 : 0x00) |
(sprites[2].collideSprite ? 0x04 : 0x00) | (sprites[2].collideSprite ? 0x04 : 0x00) |
(sprites[3].collideSprite ? 0x08 : 0x00) | (sprites[3].collideSprite ? 0x08 : 0x00) |
(sprites[4].collideSprite ? 0x10 : 0x00) | (sprites[4].collideSprite ? 0x10 : 0x00) |
(sprites[5].collideSprite ? 0x20 : 0x00) | (sprites[5].collideSprite ? 0x20 : 0x00) |
(sprites[6].collideSprite ? 0x40 : 0x00) | (sprites[6].collideSprite ? 0x40 : 0x00) |
(sprites[7].collideSprite ? 0x80 : 0x00) (sprites[7].collideSprite ? 0x80 : 0x00)
); );
break; break;
case 0x1F: case 0x1F:
result = (byte)( result = (byte)(
(sprites[0].collideData ? 0x01 : 0x00) | (sprites[0].collideData ? 0x01 : 0x00) |
(sprites[1].collideData ? 0x02 : 0x00) | (sprites[1].collideData ? 0x02 : 0x00) |
(sprites[2].collideData ? 0x04 : 0x00) | (sprites[2].collideData ? 0x04 : 0x00) |
(sprites[3].collideData ? 0x08 : 0x00) | (sprites[3].collideData ? 0x08 : 0x00) |
(sprites[4].collideData ? 0x10 : 0x00) | (sprites[4].collideData ? 0x10 : 0x00) |
(sprites[5].collideData ? 0x20 : 0x00) | (sprites[5].collideData ? 0x20 : 0x00) |
(sprites[6].collideData ? 0x40 : 0x00) | (sprites[6].collideData ? 0x40 : 0x00) |
(sprites[7].collideData ? 0x80 : 0x00) (sprites[7].collideData ? 0x80 : 0x00)
); );
break; break;
case 0x20: case 0x20:
result &= 0xF0; result &= 0xF0;
result |= (byte)(borderColor & 0x0F); result |= (byte)(borderColor & 0x0F);
break; break;
case 0x21: case 0x21:
result &= 0xF0; result &= 0xF0;
result |= (byte)(backgroundColor0 & 0x0F); result |= (byte)(backgroundColor0 & 0x0F);
break; break;
case 0x22: case 0x22:
result &= 0xF0; result &= 0xF0;
result |= (byte)(backgroundColor1 & 0x0F); result |= (byte)(backgroundColor1 & 0x0F);
break; break;
case 0x23: case 0x23:
result &= 0xF0; result &= 0xF0;
result |= (byte)(backgroundColor2 & 0x0F); result |= (byte)(backgroundColor2 & 0x0F);
break; break;
case 0x24: case 0x24:
result &= 0xF0; result &= 0xF0;
result |= (byte)(backgroundColor3 & 0x0F); result |= (byte)(backgroundColor3 & 0x0F);
break; break;
case 0x25: case 0x25:
result &= 0xF0; result &= 0xF0;
result |= (byte)(spriteMulticolor0 & 0x0F); result |= (byte)(spriteMulticolor0 & 0x0F);
break; break;
case 0x26: case 0x26:
result &= 0xF0; result &= 0xF0;
result |= (byte)(spriteMulticolor1 & 0x0F); result |= (byte)(spriteMulticolor1 & 0x0F);
break; break;
case 0x27: case 0x27:
case 0x28: case 0x28:
case 0x29: case 0x29:
case 0x2A: case 0x2A:
case 0x2B: case 0x2B:
case 0x2C: case 0x2C:
case 0x2D: case 0x2D:
case 0x2E: case 0x2E:
result &= 0xF0; result &= 0xF0;
result |= (byte)(sprites[addr - 0x27].color & 0xF); result |= (byte)(sprites[addr - 0x27].color & 0xF);
break; break;
default: default:
// not connected // not connected
break; break;
} }
return result; return result;
} }
public void Write(int addr, byte val) public void Write(int addr, byte val)
{ {
addr &= 0x3F; addr &= 0x3F;
switch (addr) switch (addr)
{ {
case 0x19: case 0x19:
// interrupts are cleared by writing a 1 // interrupts are cleared by writing a 1
if ((val & 0x01) != 0) if ((val & 0x01) != 0)
intRaster = false; intRaster = false;
if ((val & 0x02) != 0) if ((val & 0x02) != 0)
intSpriteDataCollision = false; intSpriteDataCollision = false;
if ((val & 0x04) != 0) if ((val & 0x04) != 0)
intSpriteCollision = false; intSpriteCollision = false;
if ((val & 0x08) != 0) if ((val & 0x08) != 0)
intLightPen = false; intLightPen = false;
UpdatePins(); UpdatePins();
break; break;
case 0x1A: case 0x1A:
WriteRegister(addr, val); WriteRegister(addr, val);
break; break;
case 0x1E: case 0x1E:
case 0x1F: case 0x1F:
// can't write to these // can't write to these
break; break;
case 0x2F: case 0x2F:
case 0x30: case 0x30:
case 0x31: case 0x31:
case 0x32: case 0x32:
case 0x33: case 0x33:
case 0x34: case 0x34:
case 0x35: case 0x35:
case 0x36: case 0x36:
case 0x37: case 0x37:
case 0x38: case 0x38:
case 0x39: case 0x39:
case 0x3A: case 0x3A:
case 0x3B: case 0x3B:
case 0x3C: case 0x3C:
case 0x3D: case 0x3D:
case 0x3E: case 0x3E:
case 0x3F: case 0x3F:
// not connected // not connected
break; break;
default: default:
WriteRegister(addr, val); WriteRegister(addr, val);
break; break;
} }
} }
private void WriteRegister(int addr, byte val) private void WriteRegister(int addr, byte val)
{ {
switch (addr) switch (addr)
{ {
case 0x00: case 0x00:
case 0x02: case 0x02:
case 0x04: case 0x04:
case 0x06: case 0x06:
case 0x08: case 0x08:
case 0x0A: case 0x0A:
case 0x0C: case 0x0C:
case 0x0E: case 0x0E:
sprites[addr >> 1].x &= 0x100; sprites[addr >> 1].x &= 0x100;
sprites[addr >> 1].x |= val; sprites[addr >> 1].x |= val;
break; break;
case 0x01: case 0x01:
case 0x03: case 0x03:
case 0x05: case 0x05:
case 0x07: case 0x07:
case 0x09: case 0x09:
case 0x0B: case 0x0B:
case 0x0D: case 0x0D:
case 0x0F: case 0x0F:
sprites[addr >> 1].y = val; sprites[addr >> 1].y = val;
break; break;
case 0x10: case 0x10:
sprites[0].x = (sprites[0].x & 0xFF) | ((val & 0x01) << 8); sprites[0].x = (sprites[0].x & 0xFF) | ((val & 0x01) << 8);
sprites[1].x = (sprites[1].x & 0xFF) | ((val & 0x02) << 7); sprites[1].x = (sprites[1].x & 0xFF) | ((val & 0x02) << 7);
sprites[2].x = (sprites[2].x & 0xFF) | ((val & 0x04) << 6); sprites[2].x = (sprites[2].x & 0xFF) | ((val & 0x04) << 6);
sprites[3].x = (sprites[3].x & 0xFF) | ((val & 0x08) << 5); sprites[3].x = (sprites[3].x & 0xFF) | ((val & 0x08) << 5);
sprites[4].x = (sprites[4].x & 0xFF) | ((val & 0x10) << 4); sprites[4].x = (sprites[4].x & 0xFF) | ((val & 0x10) << 4);
sprites[5].x = (sprites[5].x & 0xFF) | ((val & 0x20) << 3); sprites[5].x = (sprites[5].x & 0xFF) | ((val & 0x20) << 3);
sprites[6].x = (sprites[6].x & 0xFF) | ((val & 0x40) << 2); sprites[6].x = (sprites[6].x & 0xFF) | ((val & 0x40) << 2);
sprites[7].x = (sprites[7].x & 0xFF) | ((val & 0x80) << 1); sprites[7].x = (sprites[7].x & 0xFF) | ((val & 0x80) << 1);
break; break;
case 0x11: case 0x11:
yScroll = (val & 0x07); yScroll = (val & 0x07);
rowSelect = ((val & 0x08) != 0); rowSelect = ((val & 0x08) != 0);
displayEnable = ((val & 0x10) != 0); displayEnable = ((val & 0x10) != 0);
bitmapMode = ((val & 0x20) != 0); bitmapMode = ((val & 0x20) != 0);
extraColorMode = ((val & 0x40) != 0); extraColorMode = ((val & 0x40) != 0);
rasterInterruptLine &= 0xFF; rasterInterruptLine &= 0xFF;
rasterInterruptLine |= (val & 0x80) << 1; rasterInterruptLine |= (val & 0x80) << 1;
UpdateBorder(); UpdateBorder();
UpdateVideoMode(); UpdateVideoMode();
break; break;
case 0x12: case 0x12:
rasterInterruptLine &= 0x100; rasterInterruptLine &= 0x100;
rasterInterruptLine |= val; rasterInterruptLine |= val;
break; break;
case 0x13: case 0x13:
lightPenX = val; lightPenX = val;
break; break;
case 0x14: case 0x14:
lightPenY = val; lightPenY = val;
break; break;
case 0x15: case 0x15:
sprites[0].enable = ((val & 0x01) != 0); sprites[0].enable = ((val & 0x01) != 0);
sprites[1].enable = ((val & 0x02) != 0); sprites[1].enable = ((val & 0x02) != 0);
sprites[2].enable = ((val & 0x04) != 0); sprites[2].enable = ((val & 0x04) != 0);
sprites[3].enable = ((val & 0x08) != 0); sprites[3].enable = ((val & 0x08) != 0);
sprites[4].enable = ((val & 0x10) != 0); sprites[4].enable = ((val & 0x10) != 0);
sprites[5].enable = ((val & 0x20) != 0); sprites[5].enable = ((val & 0x20) != 0);
sprites[6].enable = ((val & 0x40) != 0); sprites[6].enable = ((val & 0x40) != 0);
sprites[7].enable = ((val & 0x80) != 0); sprites[7].enable = ((val & 0x80) != 0);
break; break;
case 0x16: case 0x16:
xScroll = (val & 0x07); xScroll = (val & 0x07);
columnSelect = ((val & 0x08) != 0); columnSelect = ((val & 0x08) != 0);
multicolorMode = ((val & 0x10) != 0); multicolorMode = ((val & 0x10) != 0);
UpdateBorder(); UpdateBorder();
UpdateVideoMode(); UpdateVideoMode();
break; break;
case 0x17: case 0x17:
sprites[0].yExpand = ((val & 0x01) != 0); sprites[0].yExpand = ((val & 0x01) != 0);
sprites[1].yExpand = ((val & 0x02) != 0); sprites[1].yExpand = ((val & 0x02) != 0);
sprites[2].yExpand = ((val & 0x04) != 0); sprites[2].yExpand = ((val & 0x04) != 0);
sprites[3].yExpand = ((val & 0x08) != 0); sprites[3].yExpand = ((val & 0x08) != 0);
sprites[4].yExpand = ((val & 0x10) != 0); sprites[4].yExpand = ((val & 0x10) != 0);
sprites[5].yExpand = ((val & 0x20) != 0); sprites[5].yExpand = ((val & 0x20) != 0);
sprites[6].yExpand = ((val & 0x40) != 0); sprites[6].yExpand = ((val & 0x40) != 0);
sprites[7].yExpand = ((val & 0x80) != 0); sprites[7].yExpand = ((val & 0x80) != 0);
break; break;
case 0x18: case 0x18:
pointerVM = ((val << 6) & 0x3C00); pointerVM = ((val << 6) & 0x3C00);
pointerCB = ((val >> 1) & 0x7); pointerCB = ((val >> 1) & 0x7);
break; break;
case 0x19: case 0x19:
intRaster = ((val & 0x01) != 0); intRaster = ((val & 0x01) != 0);
intSpriteDataCollision = ((val & 0x02) != 0); intSpriteDataCollision = ((val & 0x02) != 0);
intSpriteCollision = ((val & 0x04) != 0); intSpriteCollision = ((val & 0x04) != 0);
intLightPen = ((val & 0x08) != 0); intLightPen = ((val & 0x08) != 0);
UpdatePins(); UpdatePins();
break; break;
case 0x1A: case 0x1A:
enableIntRaster = ((val & 0x01) != 0); enableIntRaster = ((val & 0x01) != 0);
enableIntSpriteDataCollision = ((val & 0x02) != 0); enableIntSpriteDataCollision = ((val & 0x02) != 0);
enableIntSpriteCollision = ((val & 0x04) != 0); enableIntSpriteCollision = ((val & 0x04) != 0);
enableIntLightPen = ((val & 0x08) != 0); enableIntLightPen = ((val & 0x08) != 0);
UpdatePins(); UpdatePins();
break; break;
case 0x1B: case 0x1B:
sprites[0].priority = ((val & 0x01) != 0); sprites[0].priority = ((val & 0x01) != 0);
sprites[1].priority = ((val & 0x02) != 0); sprites[1].priority = ((val & 0x02) != 0);
sprites[2].priority = ((val & 0x04) != 0); sprites[2].priority = ((val & 0x04) != 0);
sprites[3].priority = ((val & 0x08) != 0); sprites[3].priority = ((val & 0x08) != 0);
sprites[4].priority = ((val & 0x10) != 0); sprites[4].priority = ((val & 0x10) != 0);
sprites[5].priority = ((val & 0x20) != 0); sprites[5].priority = ((val & 0x20) != 0);
sprites[6].priority = ((val & 0x40) != 0); sprites[6].priority = ((val & 0x40) != 0);
sprites[7].priority = ((val & 0x80) != 0); sprites[7].priority = ((val & 0x80) != 0);
break; break;
case 0x1C: case 0x1C:
sprites[0].multicolor = ((val & 0x01) != 0); sprites[0].multicolor = ((val & 0x01) != 0);
sprites[1].multicolor = ((val & 0x02) != 0); sprites[1].multicolor = ((val & 0x02) != 0);
sprites[2].multicolor = ((val & 0x04) != 0); sprites[2].multicolor = ((val & 0x04) != 0);
sprites[3].multicolor = ((val & 0x08) != 0); sprites[3].multicolor = ((val & 0x08) != 0);
sprites[4].multicolor = ((val & 0x10) != 0); sprites[4].multicolor = ((val & 0x10) != 0);
sprites[5].multicolor = ((val & 0x20) != 0); sprites[5].multicolor = ((val & 0x20) != 0);
sprites[6].multicolor = ((val & 0x40) != 0); sprites[6].multicolor = ((val & 0x40) != 0);
sprites[7].multicolor = ((val & 0x80) != 0); sprites[7].multicolor = ((val & 0x80) != 0);
break; break;
case 0x1D: case 0x1D:
sprites[0].xExpand = ((val & 0x01) != 0); sprites[0].xExpand = ((val & 0x01) != 0);
sprites[1].xExpand = ((val & 0x02) != 0); sprites[1].xExpand = ((val & 0x02) != 0);
sprites[2].xExpand = ((val & 0x04) != 0); sprites[2].xExpand = ((val & 0x04) != 0);
sprites[3].xExpand = ((val & 0x08) != 0); sprites[3].xExpand = ((val & 0x08) != 0);
sprites[4].xExpand = ((val & 0x10) != 0); sprites[4].xExpand = ((val & 0x10) != 0);
sprites[5].xExpand = ((val & 0x20) != 0); sprites[5].xExpand = ((val & 0x20) != 0);
sprites[6].xExpand = ((val & 0x40) != 0); sprites[6].xExpand = ((val & 0x40) != 0);
sprites[7].xExpand = ((val & 0x80) != 0); sprites[7].xExpand = ((val & 0x80) != 0);
break; break;
case 0x1E: case 0x1E:
sprites[0].collideSprite = ((val & 0x01) != 0); sprites[0].collideSprite = ((val & 0x01) != 0);
sprites[1].collideSprite = ((val & 0x02) != 0); sprites[1].collideSprite = ((val & 0x02) != 0);
sprites[2].collideSprite = ((val & 0x04) != 0); sprites[2].collideSprite = ((val & 0x04) != 0);
sprites[3].collideSprite = ((val & 0x08) != 0); sprites[3].collideSprite = ((val & 0x08) != 0);
sprites[4].collideSprite = ((val & 0x10) != 0); sprites[4].collideSprite = ((val & 0x10) != 0);
sprites[5].collideSprite = ((val & 0x20) != 0); sprites[5].collideSprite = ((val & 0x20) != 0);
sprites[6].collideSprite = ((val & 0x40) != 0); sprites[6].collideSprite = ((val & 0x40) != 0);
sprites[7].collideSprite = ((val & 0x80) != 0); sprites[7].collideSprite = ((val & 0x80) != 0);
break; break;
case 0x1F: case 0x1F:
sprites[0].collideData = ((val & 0x01) != 0); sprites[0].collideData = ((val & 0x01) != 0);
sprites[1].collideData = ((val & 0x02) != 0); sprites[1].collideData = ((val & 0x02) != 0);
sprites[2].collideData = ((val & 0x04) != 0); sprites[2].collideData = ((val & 0x04) != 0);
sprites[3].collideData = ((val & 0x08) != 0); sprites[3].collideData = ((val & 0x08) != 0);
sprites[4].collideData = ((val & 0x10) != 0); sprites[4].collideData = ((val & 0x10) != 0);
sprites[5].collideData = ((val & 0x20) != 0); sprites[5].collideData = ((val & 0x20) != 0);
sprites[6].collideData = ((val & 0x40) != 0); sprites[6].collideData = ((val & 0x40) != 0);
sprites[7].collideData = ((val & 0x80) != 0); sprites[7].collideData = ((val & 0x80) != 0);
break; break;
case 0x20: case 0x20:
borderColor = (val & 0xF); borderColor = (val & 0xF);
break; break;
case 0x21: case 0x21:
backgroundColor0 = (val & 0xF); backgroundColor0 = (val & 0xF);
break; break;
case 0x22: case 0x22:
backgroundColor1 = (val & 0xF); backgroundColor1 = (val & 0xF);
break; break;
case 0x23: case 0x23:
backgroundColor2 = (val & 0xF); backgroundColor2 = (val & 0xF);
break; break;
case 0x24: case 0x24:
backgroundColor3 = (val & 0xF); backgroundColor3 = (val & 0xF);
break; break;
case 0x25: case 0x25:
spriteMulticolor0 = (val & 0xF); spriteMulticolor0 = (val & 0xF);
break; break;
case 0x26: case 0x26:
spriteMulticolor1 = (val & 0xF); spriteMulticolor1 = (val & 0xF);
break; break;
case 0x27: case 0x27:
case 0x28: case 0x28:
case 0x29: case 0x29:
case 0x2A: case 0x2A:
case 0x2B: case 0x2B:
case 0x2C: case 0x2C:
case 0x2D: case 0x2D:
case 0x2E: case 0x2E:
sprites[addr - 0x27].color = (val & 0xF); sprites[addr - 0x27].color = (val & 0xF);
break; break;
default: default:
break; break;
} }
} }
} }
} }

View File

@ -3,226 +3,226 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Vic sealed public partial class Vic
{ {
int delayC; int delayC;
int ecmPixel; int ecmPixel;
int pixel; int pixel;
int pixelData; int pixelData;
SpriteGenerator pixelOwner; SpriteGenerator pixelOwner;
int sprData; int sprData;
int sprPixel; int sprPixel;
int srC = 0; int srC = 0;
int srSync = 0; int srSync = 0;
VicVideoMode videoMode; VicVideoMode videoMode;
enum VicVideoMode : int enum VicVideoMode : int
{ {
Mode000, Mode000,
Mode001, Mode001,
Mode010, Mode010,
Mode011, Mode011,
Mode100, Mode100,
ModeBad ModeBad
} }
private void Render() private void Render()
{ {
if (hblankCheckEnableL) if (hblankCheckEnableL)
{ {
if (rasterX == hblankEnd) if (rasterX == hblankEnd)
hblank = false; hblank = false;
} }
else if (hblankCheckEnableR) else if (hblankCheckEnableR)
{ {
if (rasterX == hblankStart) if (rasterX == hblankStart)
hblank = true; hblank = true;
} }
renderEnabled = (!hblank && !vblank); renderEnabled = (!hblank && !vblank);
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
if (delayC > 0) if (delayC > 0)
delayC--; delayC--;
else else
displayC = (srC >> 12) & 0xFFF; displayC = (srC >> 12) & 0xFFF;
if (borderCheckLEnable && (rasterX == borderL)) if (borderCheckLEnable && (rasterX == borderL))
{ {
if (rasterLine == borderB) if (rasterLine == borderB)
borderOnVertical = true; borderOnVertical = true;
if (rasterLine == borderT && displayEnable) if (rasterLine == borderT && displayEnable)
borderOnVertical = false; borderOnVertical = false;
if (!borderOnVertical) if (!borderOnVertical)
borderOnMain = false; borderOnMain = false;
} }
switch (videoMode) switch (videoMode)
{ {
case VicVideoMode.Mode000: case VicVideoMode.Mode000:
pixelData = sr & srMask2; pixelData = sr & srMask2;
pixel = (pixelData != 0) ? (displayC >> 8) : backgroundColor0; pixel = (pixelData != 0) ? (displayC >> 8) : backgroundColor0;
break; break;
case VicVideoMode.Mode001: case VicVideoMode.Mode001:
if ((displayC & 0x800) != 0) if ((displayC & 0x800) != 0)
{ {
// multicolor 001 // multicolor 001
if ((srSync & srMask2) != 0) if ((srSync & srMask2) != 0)
pixelData = sr & srMask3; pixelData = sr & srMask3;
if (pixelData == 0) if (pixelData == 0)
pixel = backgroundColor0; pixel = backgroundColor0;
else if (pixelData == srMask1) else if (pixelData == srMask1)
pixel = backgroundColor1; pixel = backgroundColor1;
else if (pixelData == srMask2) else if (pixelData == srMask2)
pixel = backgroundColor2; pixel = backgroundColor2;
else else
pixel = (displayC & 0x700) >> 8; pixel = (displayC & 0x700) >> 8;
} }
else else
{ {
// standard 001 // standard 001
pixelData = sr & srMask2; pixelData = sr & srMask2;
pixel = (pixelData != 0) ? (displayC >> 8) : backgroundColor0; pixel = (pixelData != 0) ? (displayC >> 8) : backgroundColor0;
} }
break; break;
case VicVideoMode.Mode010: case VicVideoMode.Mode010:
pixelData = sr & srMask2; pixelData = sr & srMask2;
pixel = (pixelData != 0) ? (displayC >> 4) : (displayC); pixel = (pixelData != 0) ? (displayC >> 4) : (displayC);
break; break;
case VicVideoMode.Mode011: case VicVideoMode.Mode011:
if ((srSync & srMask2) != 0) if ((srSync & srMask2) != 0)
pixelData = sr & srMask3; pixelData = sr & srMask3;
if (pixelData == 0) if (pixelData == 0)
pixel = backgroundColor0; pixel = backgroundColor0;
else if (pixelData == srMask1) else if (pixelData == srMask1)
pixel = (displayC >> 4); pixel = (displayC >> 4);
else if (pixelData == srMask2) else if (pixelData == srMask2)
pixel = displayC; pixel = displayC;
else else
pixel = (displayC >> 8); pixel = (displayC >> 8);
break; break;
case VicVideoMode.Mode100: case VicVideoMode.Mode100:
pixelData = sr & srMask2; pixelData = sr & srMask2;
if (pixelData != 0) if (pixelData != 0)
{ {
pixel = displayC >> 8; pixel = displayC >> 8;
} }
else else
{ {
ecmPixel = (displayC) & 0xC0; ecmPixel = (displayC) & 0xC0;
if (ecmPixel == 0x00) if (ecmPixel == 0x00)
pixel = backgroundColor0; pixel = backgroundColor0;
else if (ecmPixel == 0x40) else if (ecmPixel == 0x40)
pixel = backgroundColor1; pixel = backgroundColor1;
else if (ecmPixel == 0x80) else if (ecmPixel == 0x80)
pixel = backgroundColor2; pixel = backgroundColor2;
else else
pixel = backgroundColor3; pixel = backgroundColor3;
} }
break; break;
default: default:
pixelData = 0; pixelData = 0;
pixel = 0; pixel = 0;
break; break;
} }
pixel &= 0xF; pixel &= 0xF;
sr <<= 1; sr <<= 1;
srSync <<= 1; srSync <<= 1;
// render sprite
pixelOwner = null;
foreach (SpriteGenerator spr in sprites)
{
sprData = 0;
sprPixel = pixel;
if (spr.x == rasterX) // render sprite
spr.shiftEnable = true; pixelOwner = null;
foreach (SpriteGenerator spr in sprites)
{
sprData = 0;
sprPixel = pixel;
if (spr.shiftEnable) if (spr.x == rasterX)
{ spr.shiftEnable = true;
if (spr.multicolor)
{
sprData = (spr.sr & srSpriteMaskMC);
if (spr.multicolorCrunch && spr.xCrunch && !rasterXHold)
spr.sr <<= 2;
spr.multicolorCrunch ^= spr.xCrunch;
}
else
{
sprData = (spr.sr & srSpriteMask);
if (spr.xCrunch && !rasterXHold)
spr.sr <<= 1;
}
spr.xCrunch ^= spr.xExpand;
if (sprData != 0) if (spr.shiftEnable)
{ {
// sprite-sprite collision if (spr.multicolor)
if (pixelOwner == null) {
{ sprData = (spr.sr & srSpriteMaskMC);
if (!spr.priority || (pixelData == 0)) if (spr.multicolorCrunch && spr.xCrunch && !rasterXHold)
{ spr.sr <<= 2;
if (sprData == srSpriteMask1) spr.multicolorCrunch ^= spr.xCrunch;
pixel = spriteMulticolor0; }
else if (sprData == srSpriteMask2) else
pixel = spr.color; {
else if (sprData == srSpriteMask3) sprData = (spr.sr & srSpriteMask);
pixel = spriteMulticolor1; if (spr.xCrunch && !rasterXHold)
} spr.sr <<= 1;
pixelOwner = spr; }
} spr.xCrunch ^= spr.xExpand;
else
{
if (!borderOnVertical)
{
spr.collideSprite = true;
pixelOwner.collideSprite = true;
}
}
// sprite-data collision if (sprData != 0)
if (!borderOnVertical && (pixelData < srMask2)) {
{ // sprite-sprite collision
spr.collideData = true; if (pixelOwner == null)
} {
} if (!spr.priority || (pixelData == 0))
if (spr.sr == 0) {
spr.shiftEnable = false; //optimization if (sprData == srSpriteMask1)
} pixel = spriteMulticolor0;
} else if (sprData == srSpriteMask2)
pixel = spr.color;
else if (sprData == srSpriteMask3)
pixel = spriteMulticolor1;
}
pixelOwner = spr;
}
else
{
if (!borderOnVertical)
{
spr.collideSprite = true;
pixelOwner.collideSprite = true;
}
}
if (borderCheckREnable && (rasterX == borderR)) // sprite-data collision
borderOnMain = true; if (!borderOnVertical && (pixelData < srMask2))
{
spr.collideData = true;
}
}
if (spr.sr == 0)
spr.shiftEnable = false; //optimization
}
}
// border doesn't work with the background buffer if (borderCheckREnable && (rasterX == borderR))
if (borderOnMain || borderOnVertical) borderOnMain = true;
pixel = borderColor;
// plot pixel if within viewing area // border doesn't work with the background buffer
if (renderEnabled) if (borderOnMain || borderOnVertical)
{ pixel = borderColor;
buf[bufOffset] = palette[pixBuffer[pixBufferIndex]];
bufOffset++;
if (bufOffset == bufLength)
bufOffset = 0;
}
pixBuffer[pixBufferIndex] = pixel;
pixBufferIndex++;
if (!rasterXHold) // plot pixel if within viewing area
rasterX++; if (renderEnabled)
bitmapColumn++; {
} buf[bufOffset] = palette[pixBuffer[pixBufferIndex]];
bufOffset++;
if (bufOffset == bufLength)
bufOffset = 0;
}
pixBuffer[pixBufferIndex] = pixel;
pixBufferIndex++;
if (pixBufferIndex >= pixBufferSize) if (!rasterXHold)
pixBufferIndex = 0; rasterX++;
} bitmapColumn++;
} }
if (pixBufferIndex >= pixBufferSize)
pixBufferIndex = 0;
}
}
} }

View File

@ -5,7 +5,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Vic sealed public partial class Vic
{ {

View File

@ -6,7 +6,7 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Vic sealed public partial class Vic
{ {

View File

@ -3,23 +3,23 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Vic sealed public partial class Vic
{ {
const int BORDER_LEFT_38 = 0x01F; const int BORDER_LEFT_38 = 0x01F;
const int BORDER_LEFT_40 = 0x018; const int BORDER_LEFT_40 = 0x018;
const int BORDER_RIGHT_38 = 0x14F; const int BORDER_RIGHT_38 = 0x14F;
const int BORDER_RIGHT_40 = 0x158; const int BORDER_RIGHT_40 = 0x158;
// The special actions taken by the Vic are in the same order and interval on all chips, just different offsets. // The special actions taken by the Vic are in the same order and interval on all chips, just different offsets.
static int[] TimingBuilder_Cycle14Act = new int[] static int[] TimingBuilder_Cycle14Act = new int[]
{ {
pipelineUpdateVc, 0, pipelineUpdateVc, 0,
pipelineChkSprChunch, 0, pipelineChkSprChunch, 0,
pipelineUpdateMcBase, 0, pipelineUpdateMcBase, 0,
}; };
static int[] TimingBuilder_Cycle55Act = new int[] static int[] TimingBuilder_Cycle55Act = new int[]
{ {
pipelineChkSprDma, 0, pipelineChkSprDma, 0,
pipelineChkSprDma, pipelineChkSprExp, pipelineChkSprDma, pipelineChkSprExp,
@ -27,251 +27,251 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
pipelineChkSprDisp, pipelineUpdateRc pipelineChkSprDisp, pipelineUpdateRc
}; };
// This builds a table of special actions to take on each half-cycle. Cycle14 is the X-raster position where // This builds a table of special actions to take on each half-cycle. Cycle14 is the X-raster position where
// pre-display operations happen, and Cycle55 is the X-raster position where post-display operations happen. // pre-display operations happen, and Cycle55 is the X-raster position where post-display operations happen.
static public int[] TimingBuilder_Act(int[] timing, int cycle14, int cycle55, int hblankStart, int hblankEnd) static public int[] TimingBuilder_Act(int[] timing, int cycle14, int cycle55, int hblankStart, int hblankEnd)
{ {
List<int> result = new List<int>(); List<int> result = new List<int>();
int length = timing.Length; int length = timing.Length;
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
while (i < result.Count) while (i < result.Count)
i++; i++;
if (timing[i] == cycle14) if (timing[i] == cycle14)
result.AddRange(TimingBuilder_Cycle14Act); result.AddRange(TimingBuilder_Cycle14Act);
else if (timing[i] == cycle55) else if (timing[i] == cycle55)
result.AddRange(TimingBuilder_Cycle55Act); result.AddRange(TimingBuilder_Cycle55Act);
else else
result.Add(0); result.Add(0);
} }
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
// pipeline raster X delay // pipeline raster X delay
if (timing[(i + 1) % length] == timing[i]) if (timing[(i + 1) % length] == timing[i])
result[i] |= pipelineHoldX; result[i] |= pipelineHoldX;
// pipeline border checks // pipeline border checks
if (timing[i] == (BORDER_LEFT_40 & 0xFFC)) if (timing[i] == (BORDER_LEFT_40 & 0xFFC))
result[i] |= pipelineChkBrdL1; result[i] |= pipelineChkBrdL1;
if (timing[i] == (BORDER_LEFT_38 & 0xFFC)) if (timing[i] == (BORDER_LEFT_38 & 0xFFC))
result[i] |= pipelineChkBrdL0; result[i] |= pipelineChkBrdL0;
if (timing[i] == (BORDER_RIGHT_38 & 0xFFC)) if (timing[i] == (BORDER_RIGHT_38 & 0xFFC))
result[i] |= pipelineChkBrdR0; result[i] |= pipelineChkBrdR0;
if (timing[i] == (BORDER_RIGHT_40 & 0xFFC)) if (timing[i] == (BORDER_RIGHT_40 & 0xFFC))
result[i] |= pipelineChkBrdR1; result[i] |= pipelineChkBrdR1;
if (timing[i] == (hblankStart & 0xFFC)) if (timing[i] == (hblankStart & 0xFFC))
result[i] |= pipelineHBlankR; result[i] |= pipelineHBlankR;
if (timing[i] == (hblankEnd & 0xFFC)) if (timing[i] == (hblankEnd & 0xFFC))
result[i] |= pipelineHBlankL; result[i] |= pipelineHBlankL;
} }
return result.ToArray(); return result.ToArray();
} }
// This builds a table of how the BA pin is supposed to act on each half-cycle. // This builds a table of how the BA pin is supposed to act on each half-cycle.
static public int[] TimingBuilder_BA(int[] fetch) static public int[] TimingBuilder_BA(int[] fetch)
{ {
int baRestart = 7; int baRestart = 7;
int start = 0; int start = 0;
int length = fetch.Length; int length = fetch.Length;
int[] result = new int[length]; int[] result = new int[length];
int[] spriteBA = new int[8]; int[] spriteBA = new int[8];
int charBA = 0; int charBA = 0;
while (true) while (true)
{ {
if (fetch[start] == 0) if (fetch[start] == 0)
break; break;
start++; start++;
} }
while (true) while (true)
{ {
if (fetch[start] == 0x200) if (fetch[start] == 0x200)
break; break;
start--; start--;
} }
if (start < 0) if (start < 0)
start += length; start += length;
int offset = start; int offset = start;
while (true) while (true)
{ {
int ba = 0x0888; int ba = 0x0888;
if (fetch[offset] == 0x200) if (fetch[offset] == 0x200)
charBA = baRestart; charBA = baRestart;
else if ((fetch[offset] & 0xFF00) == 0x0000) else if ((fetch[offset] & 0xFF00) == 0x0000)
spriteBA[fetch[offset] & 0x007] = baRestart; spriteBA[fetch[offset] & 0x007] = baRestart;
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
if (spriteBA[i] > 0) if (spriteBA[i] > 0)
{ {
ba <<= 4; ba <<= 4;
ba |= i; ba |= i;
spriteBA[i]--; spriteBA[i]--;
} }
} }
ba &= 0x0FFF; ba &= 0x0FFF;
if (charBA > 0) if (charBA > 0)
{ {
ba = 0x1000; ba = 0x1000;
charBA--; charBA--;
} }
result[offset] = ba; result[offset] = ba;
offset--; offset--;
if (offset < 0) if (offset < 0)
offset += length; offset += length;
if (offset == start) if (offset == start)
break; break;
} }
for (int i = 0; i < length; i += 2) for (int i = 0; i < length; i += 2)
{ {
result[i] = result[i + 1]; result[i] = result[i + 1];
} }
return result; return result;
} }
// This builds a table of the fetch operations to take on each half-cycle. // This builds a table of the fetch operations to take on each half-cycle.
static public int[] TimingBuilder_Fetch(int[] timing, int sprite) static public int[] TimingBuilder_Fetch(int[] timing, int sprite)
{ {
int length = timing.Length; int length = timing.Length;
int[] result = new int[length]; int[] result = new int[length];
int offset; int offset;
int index = -1; int index = -1;
int refreshCounter = 0; int refreshCounter = 0;
bool spriteActive = false; bool spriteActive = false;
int spriteIndex = 0; int spriteIndex = 0;
int spritePhase = 0; int spritePhase = 0;
int charCounter = 0; int charCounter = 0;
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
result[i++] = 0x500; result[i++] = 0x500;
result[i] = 0x100; result[i] = 0x100;
} }
while (true) while (true)
{ {
index++; index++;
if (index >= length) if (index >= length)
index -= length; index -= length;
offset = timing[index]; offset = timing[index];
if (charCounter > 0) if (charCounter > 0)
{ {
result[index] = (charCounter & 1) == 0 ? 0x200 : 0x300; result[index] = (charCounter & 1) == 0 ? 0x200 : 0x300;
charCounter--; charCounter--;
if (charCounter == 0) if (charCounter == 0)
break; break;
} }
if (refreshCounter > 0) if (refreshCounter > 0)
{ {
result[index] = (refreshCounter & 1) == 0 ? 0x500 : 0x100; result[index] = (refreshCounter & 1) == 0 ? 0x500 : 0x100;
refreshCounter--; refreshCounter--;
if (refreshCounter == 0) if (refreshCounter == 0)
charCounter = 80; charCounter = 80;
} }
if (offset == sprite) if (offset == sprite)
{ {
spriteActive = true; spriteActive = true;
} }
if (spriteActive) if (spriteActive)
{ {
result[index] = (spriteIndex | (spritePhase << 4)); result[index] = (spriteIndex | (spritePhase << 4));
spritePhase++; spritePhase++;
if (spritePhase == 4) if (spritePhase == 4)
{ {
spritePhase = 0; spritePhase = 0;
spriteIndex++; spriteIndex++;
if (spriteIndex == 8) if (spriteIndex == 8)
{ {
spriteActive = false; spriteActive = false;
refreshCounter = 9; refreshCounter = 9;
} }
} }
} }
} }
return result.ToArray(); return result.ToArray();
} }
// This uses the vBlank values to determine the height of the visible screen. // This uses the vBlank values to determine the height of the visible screen.
static public int TimingBuilder_ScreenHeight(int vblankStart, int vblankEnd, int lines) static public int TimingBuilder_ScreenHeight(int vblankStart, int vblankEnd, int lines)
{ {
int offset = vblankEnd; int offset = vblankEnd;
int result = 0; int result = 0;
while (true) while (true)
{ {
if (offset >= lines) if (offset >= lines)
offset -= lines; offset -= lines;
if (offset == vblankStart) if (offset == vblankStart)
return result; return result;
offset++; offset++;
result++; result++;
} }
} }
// This uses the hBlank values to determine the width of the visible screen. // This uses the hBlank values to determine the width of the visible screen.
static public int TimingBuilder_ScreenWidth(int[] timing, int hblankStart, int hblankEnd) static public int TimingBuilder_ScreenWidth(int[] timing, int hblankStart, int hblankEnd)
{ {
int length = timing.Length; int length = timing.Length;
int result = 0; int result = 0;
int offset = 0; int offset = 0;
while (timing[offset] != hblankEnd) { offset = (offset + 1) % length; } while (timing[offset] != hblankEnd) { offset = (offset + 1) % length; }
while (timing[offset] != hblankStart) { offset = (offset + 1) % length; result++; } while (timing[offset] != hblankStart) { offset = (offset + 1) % length; result++; }
return (result * 4); return (result * 4);
} }
// This builds the table of X-raster positions. Start marks the position where the // This builds the table of X-raster positions. Start marks the position where the
// Y-raster is incremented. Width is the position where the X-raster is reset to zero. Count // Y-raster is incremented. Width is the position where the X-raster is reset to zero. Count
// is the width of a rasterline in pixels. DelayOffset is the X-raster position where lag begins // is the width of a rasterline in pixels. DelayOffset is the X-raster position where lag begins
// (specifically on an NTSC 6567R8) and DelayAmount is the number of positions to lag. // (specifically on an NTSC 6567R8) and DelayAmount is the number of positions to lag.
static public int[] TimingBuilder_XRaster(int start, int width, int count, int delayOffset, int delayAmount) static public int[] TimingBuilder_XRaster(int start, int width, int count, int delayOffset, int delayAmount)
{ {
List<int> result = new List<int>(); List<int> result = new List<int>();
int rasterX = start; int rasterX = start;
bool delayed = false; bool delayed = false;
count >>= 2; count >>= 2;
delayAmount >>= 2; delayAmount >>= 2;
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
result.Add(rasterX); result.Add(rasterX);
if (!delayed) if (!delayed)
{ {
rasterX += 4; rasterX += 4;
if (rasterX >= width) if (rasterX >= width)
rasterX -= width; rasterX -= width;
} }
else else
{ {
delayAmount--; delayAmount--;
if (delayAmount <= 0) if (delayAmount <= 0)
delayed = false; delayed = false;
continue; continue;
} }
if (rasterX == delayOffset && delayAmount > 0) if (rasterX == delayOffset && delayAmount > 0)
delayed = true; delayed = true;
} }
return result.ToArray(); return result.ToArray();
} }
} }
} }

View File

@ -3,7 +3,7 @@
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Vic : IVideoProvider sealed public partial class Vic : IVideoProvider
{ {
@ -18,24 +18,24 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
// palette // palette
int[] palette = int[] palette =
{ {
Colors.ARGB(0x00, 0x00, 0x00), Colors.ARGB(0x00, 0x00, 0x00),
Colors.ARGB(0xFF, 0xFF, 0xFF), Colors.ARGB(0xFF, 0xFF, 0xFF),
Colors.ARGB(0x68, 0x37, 0x2B), Colors.ARGB(0x68, 0x37, 0x2B),
Colors.ARGB(0x70, 0xA4, 0xB2), Colors.ARGB(0x70, 0xA4, 0xB2),
Colors.ARGB(0x6F, 0x3D, 0x86), Colors.ARGB(0x6F, 0x3D, 0x86),
Colors.ARGB(0x58, 0x8D, 0x43), Colors.ARGB(0x58, 0x8D, 0x43),
Colors.ARGB(0x35, 0x28, 0x79), Colors.ARGB(0x35, 0x28, 0x79),
Colors.ARGB(0xB8, 0xC7, 0x6F), Colors.ARGB(0xB8, 0xC7, 0x6F),
Colors.ARGB(0x6F, 0x4F, 0x25), Colors.ARGB(0x6F, 0x4F, 0x25),
Colors.ARGB(0x43, 0x39, 0x00), Colors.ARGB(0x43, 0x39, 0x00),
Colors.ARGB(0x9A, 0x67, 0x59), Colors.ARGB(0x9A, 0x67, 0x59),
Colors.ARGB(0x44, 0x44, 0x44), Colors.ARGB(0x44, 0x44, 0x44),
Colors.ARGB(0x6C, 0x6C, 0x6C), Colors.ARGB(0x6C, 0x6C, 0x6C),
Colors.ARGB(0x9A, 0xD2, 0x84), Colors.ARGB(0x9A, 0xD2, 0x84),
Colors.ARGB(0x6C, 0x5E, 0xB5), Colors.ARGB(0x6C, 0x5E, 0xB5),
Colors.ARGB(0x95, 0x95, 0x95) Colors.ARGB(0x95, 0x95, 0x95)
}; };
public int BackgroundColor public int BackgroundColor
{ {

View File

@ -1,157 +1,157 @@
using System; using System;
using System.Drawing; using System.Drawing;
namespace BizHawk.Emulation.Computers.Commodore64.MOS namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
sealed public partial class Vic sealed public partial class Vic
{ {
public Func<int, byte> ReadColorRam; public Func<int, byte> ReadColorRam;
public Func<int, byte> ReadMemory; public Func<int, byte> ReadMemory;
public bool ReadAECBuffer() { return pinAEC; } public bool ReadAECBuffer() { return pinAEC; }
public bool ReadBABuffer() { return pinBA; } public bool ReadBABuffer() { return pinBA; }
public bool ReadIRQBuffer() { return pinIRQ; } public bool ReadIRQBuffer() { return pinIRQ; }
int cyclesPerSec; int cyclesPerSec;
int irqShift; int irqShift;
int[][] pipeline; int[][] pipeline;
int totalCycles; int totalCycles;
int totalLines; int totalLines;
public Vic(int newCycles, int newLines, int[][] newPipeline, int newCyclesPerSec, int hblankStart, int hblankEnd, int vblankStart, int vblankEnd) public Vic(int newCycles, int newLines, int[][] newPipeline, int newCyclesPerSec, int hblankStart, int hblankEnd, int vblankStart, int vblankEnd)
{ {
{ {
this.hblankStart = hblankStart; this.hblankStart = hblankStart;
this.hblankEnd = hblankEnd; this.hblankEnd = hblankEnd;
this.vblankStart = vblankStart; this.vblankStart = vblankStart;
this.vblankEnd = vblankEnd; this.vblankEnd = vblankEnd;
totalCycles = newCycles; totalCycles = newCycles;
totalLines = newLines; totalLines = newLines;
pipeline = newPipeline; pipeline = newPipeline;
cyclesPerSec = newCyclesPerSec; cyclesPerSec = newCyclesPerSec;
bufWidth = TimingBuilder_ScreenWidth(pipeline[0], hblankStart, hblankEnd); bufWidth = TimingBuilder_ScreenWidth(pipeline[0], hblankStart, hblankEnd);
bufHeight = TimingBuilder_ScreenHeight(vblankStart, vblankEnd, newLines); bufHeight = TimingBuilder_ScreenHeight(vblankStart, vblankEnd, newLines);
buf = new int[bufWidth * bufHeight]; buf = new int[bufWidth * bufHeight];
bufLength = buf.Length; bufLength = buf.Length;
sprites = new SpriteGenerator[8]; sprites = new SpriteGenerator[8];
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
sprites[i] = new SpriteGenerator(); sprites[i] = new SpriteGenerator();
bufferC = new int[40]; bufferC = new int[40];
bufferG = new int[40]; bufferG = new int[40];
} }
} }
public int CyclesPerFrame public int CyclesPerFrame
{ {
get get
{ {
return (totalCycles * totalLines); return (totalCycles * totalLines);
} }
} }
public int CyclesPerSecond public int CyclesPerSecond
{ {
get get
{ {
return cyclesPerSec; return cyclesPerSec;
} }
} }
public void ExecutePhase1() public void ExecutePhase1()
{ {
//xScroll = 1; //xScroll = 1;
{ {
// raster IRQ compare // raster IRQ compare
if ((cycle == rasterIrqLineXCycle && rasterLine > 0) || (cycle == rasterIrqLine0Cycle && rasterLine == 0)) if ((cycle == rasterIrqLineXCycle && rasterLine > 0) || (cycle == rasterIrqLine0Cycle && rasterLine == 0))
{ {
if (rasterLine != lastRasterLine) if (rasterLine != lastRasterLine)
if (rasterLine == rasterInterruptLine) if (rasterLine == rasterInterruptLine)
intRaster = true; intRaster = true;
lastRasterLine = rasterLine; lastRasterLine = rasterLine;
} }
// display enable compare // display enable compare
if (rasterLine == 0x030) if (rasterLine == 0x030)
badlineEnable |= displayEnable; badlineEnable |= displayEnable;
// badline compare // badline compare
if (badlineEnable && rasterLine >= 0x030 && rasterLine < 0x0F7 && ((rasterLine & 0x7) == yScroll)) if (badlineEnable && rasterLine >= 0x030 && rasterLine < 0x0F7 && ((rasterLine & 0x7) == yScroll))
{ {
badline = true; badline = true;
} }
else else
{ {
badline = false; badline = false;
} }
// go into display state on a badline // go into display state on a badline
if (badline) if (badline)
idle = false; idle = false;
// process some sprite crunch vars // process some sprite crunch vars
foreach (SpriteGenerator spr in sprites) foreach (SpriteGenerator spr in sprites)
if (!spr.yExpand) spr.yCrunch = true; if (!spr.yExpand) spr.yCrunch = true;
ParseCycle(); ParseCycle();
//xOffset = 0; //xOffset = 0;
Render(); Render();
// if the BA counter is nonzero, allow CPU bus access // if the BA counter is nonzero, allow CPU bus access
UpdateBA(); UpdateBA();
pinAEC = false; pinAEC = false;
// must always come last // must always come last
//UpdatePins(); //UpdatePins();
} }
} }
public void ExecutePhase2() public void ExecutePhase2()
{ {
{ {
ParseCycle(); ParseCycle();
// advance cycle and optionally raster line // advance cycle and optionally raster line
cycle++; cycle++;
if (cycle == totalCycles) if (cycle == totalCycles)
{ {
if (rasterLine == borderB) if (rasterLine == borderB)
borderOnVertical = true; borderOnVertical = true;
if (rasterLine == borderT && displayEnable) if (rasterLine == borderT && displayEnable)
borderOnVertical = false; borderOnVertical = false;
if (rasterLine == vblankStart) if (rasterLine == vblankStart)
vblank = true; vblank = true;
if (rasterLine == vblankEnd) if (rasterLine == vblankEnd)
vblank = false; vblank = false;
cycleIndex = 0; cycleIndex = 0;
cycle = 0; cycle = 0;
rasterLine++; rasterLine++;
if (rasterLine == totalLines) if (rasterLine == totalLines)
{ {
rasterLine = 0; rasterLine = 0;
vcbase = 0; vcbase = 0;
vc = 0; vc = 0;
} }
} }
Render(); Render();
UpdateBA(); UpdateBA();
pinAEC = (baCount > 0); pinAEC = (baCount > 0);
// must always come last // must always come last
UpdatePins(); UpdatePins();
} }
} }
private void UpdateBA() private void UpdateBA()
{ {
if (pinBA) if (pinBA)
baCount = baResetCounter; baCount = baResetCounter;
@ -163,8 +163,8 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
{ {
borderL = columnSelect ? 0x018 : 0x01F; borderL = columnSelect ? 0x018 : 0x01F;
borderR = columnSelect ? 0x158 : 0x14F; borderR = columnSelect ? 0x158 : 0x14F;
//borderL = columnSelect ? 28 : 35; //borderL = columnSelect ? 28 : 35;
//borderR = columnSelect ? 348 : 339; //borderR = columnSelect ? 348 : 339;
borderT = rowSelect ? 0x033 : 0x037; borderT = rowSelect ? 0x033 : 0x037;
borderB = rowSelect ? 0x0FB : 0x0F7; borderB = rowSelect ? 0x0FB : 0x0F7;
} }
@ -177,39 +177,39 @@ namespace BizHawk.Emulation.Computers.Commodore64.MOS
(enableIntSpriteCollision & intSpriteCollision) | (enableIntSpriteCollision & intSpriteCollision) |
(enableIntLightPen & intLightPen)); (enableIntLightPen & intLightPen));
irqShift <<= 1; irqShift <<= 1;
irqShift |= (irqTemp ? 0x1 : 0x0); irqShift |= (irqTemp ? 0x1 : 0x0);
pinIRQ = (irqShift & 0x1) != 0; pinIRQ = (irqShift & 0x1) != 0;
} }
private void UpdateVideoMode() private void UpdateVideoMode()
{ {
if (!extraColorMode && !bitmapMode && !multicolorMode) if (!extraColorMode && !bitmapMode && !multicolorMode)
{ {
videoMode = VicVideoMode.Mode000; videoMode = VicVideoMode.Mode000;
return; return;
} }
else if (!extraColorMode && !bitmapMode && multicolorMode) else if (!extraColorMode && !bitmapMode && multicolorMode)
{ {
videoMode = VicVideoMode.Mode001; videoMode = VicVideoMode.Mode001;
return; return;
} }
else if (!extraColorMode && bitmapMode && !multicolorMode) else if (!extraColorMode && bitmapMode && !multicolorMode)
{ {
videoMode = VicVideoMode.Mode010; videoMode = VicVideoMode.Mode010;
return; return;
} }
else if (!extraColorMode && bitmapMode && multicolorMode) else if (!extraColorMode && bitmapMode && multicolorMode)
{ {
videoMode = VicVideoMode.Mode011; videoMode = VicVideoMode.Mode011;
return; return;
} }
else if (extraColorMode && !bitmapMode && !multicolorMode) else if (extraColorMode && !bitmapMode && !multicolorMode)
{ {
videoMode = VicVideoMode.Mode100; videoMode = VicVideoMode.Mode100;
return; return;
} }
videoMode = VicVideoMode.ModeBad; videoMode = VicVideoMode.ModeBad;
} }
} }
} }

View File

@ -1,7 +1,7 @@
using System; using System;
using System.IO; using System.IO;
namespace BizHawk.Emulation.Computers.Commodore64.Media namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public static class D64 public static class D64
{ {

View File

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace BizHawk.Emulation.Computers.Commodore64.Media namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public class Track public class Track
{ {

View File

@ -1,6 +1,6 @@
using System.IO; using System.IO;
namespace BizHawk.Emulation.Computers.Commodore64.Media namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
public static class G64 public static class G64
{ {

View File

@ -1,6 +1,4 @@
using BizHawk.Emulation.Computers.Commodore64.MOS; namespace BizHawk.Emulation.Cores.Computers.Commodore64
namespace BizHawk.Emulation.Computers.Commodore64.Media
{ {
public static class PRG public static class PRG
{ {

View File

@ -8,158 +8,158 @@ using System.Text;
using BizHawk.Common; using BizHawk.Common;
namespace BizHawk.Emulation.Computers.Commodore64 namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
static class SaveState static class SaveState
{ {
static public void SyncObject(Serializer ser, object obj) static public void SyncObject(Serializer ser, object obj)
{ {
BindingFlags defaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy; BindingFlags defaultFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy;
MemberInfo[] members = obj.GetType().GetMembers(defaultFlags); MemberInfo[] members = obj.GetType().GetMembers(defaultFlags);
Bit refBit; Bit refBit;
Boolean refBool; Boolean refBool;
Byte refByte; Byte refByte;
ByteBuffer refByteBuffer; ByteBuffer refByteBuffer;
Int16 refInt16; Int16 refInt16;
Int32 refInt32; Int32 refInt32;
IntBuffer refIntBuffer; IntBuffer refIntBuffer;
Int32 refPointX; Int32 refPointX;
Int32 refPointY; Int32 refPointY;
SByte refSByte; SByte refSByte;
UInt16 refUInt16; UInt16 refUInt16;
UInt32 refUInt32; UInt32 refUInt32;
Int32 refRectHeight; Int32 refRectHeight;
Int32 refRectWidth; Int32 refRectWidth;
foreach (MemberInfo member in members) foreach (MemberInfo member in members)
{ {
object currentValue = null; object currentValue = null;
bool fail = false; bool fail = false;
FieldInfo fieldInfo = null; FieldInfo fieldInfo = null;
PropertyInfo propInfo = null; PropertyInfo propInfo = null;
Type valueType = null; Type valueType = null;
if (member.MemberType == MemberTypes.Field) if (member.MemberType == MemberTypes.Field)
{ {
fieldInfo = member.ReflectedType.GetField(member.Name, defaultFlags); fieldInfo = member.ReflectedType.GetField(member.Name, defaultFlags);
valueType = fieldInfo.FieldType; valueType = fieldInfo.FieldType;
currentValue = fieldInfo.GetValue(obj); currentValue = fieldInfo.GetValue(obj);
} }
else else
{ {
fail = true; fail = true;
} }
if (!fail) if (!fail)
{ {
if (valueType.IsArray) if (valueType.IsArray)
{ {
} }
if (currentValue != null) if (currentValue != null)
{ {
switch (valueType.Name) switch (valueType.Name)
{ {
case "Bit": case "Bit":
refBit = (Bit)currentValue; refBit = (Bit)currentValue;
ser.Sync(member.Name, ref refBit); ser.Sync(member.Name, ref refBit);
currentValue = refBit; currentValue = refBit;
break; break;
case "Boolean": case "Boolean":
refBool = (Boolean)currentValue; refBool = (Boolean)currentValue;
ser.Sync(member.Name, ref refBool); ser.Sync(member.Name, ref refBool);
currentValue = refBool; currentValue = refBool;
break; break;
case "Byte": case "Byte":
refByte = (Byte)currentValue; refByte = (Byte)currentValue;
ser.Sync(member.Name, ref refByte); ser.Sync(member.Name, ref refByte);
currentValue = refByte; currentValue = refByte;
break; break;
case "Byte[]": case "Byte[]":
refByteBuffer = new ByteBuffer((byte[])currentValue); refByteBuffer = new ByteBuffer((byte[])currentValue);
ser.Sync(member.Name, ref refByteBuffer); ser.Sync(member.Name, ref refByteBuffer);
currentValue = refByteBuffer.arr; currentValue = refByteBuffer.arr;
break; break;
case "ByteBuffer": case "ByteBuffer":
refByteBuffer = (ByteBuffer)currentValue; refByteBuffer = (ByteBuffer)currentValue;
ser.Sync(member.Name, ref refByteBuffer); ser.Sync(member.Name, ref refByteBuffer);
currentValue = refByteBuffer; currentValue = refByteBuffer;
break; break;
case "Int16": case "Int16":
refInt16 = (Int16)currentValue; refInt16 = (Int16)currentValue;
ser.Sync(member.Name, ref refInt16); ser.Sync(member.Name, ref refInt16);
currentValue = refInt16; currentValue = refInt16;
break; break;
case "Int32": case "Int32":
refInt32 = (Int32)currentValue; refInt32 = (Int32)currentValue;
ser.Sync(member.Name, ref refInt32); ser.Sync(member.Name, ref refInt32);
currentValue = refInt32; currentValue = refInt32;
break; break;
case "Int32[]": case "Int32[]":
refIntBuffer = new IntBuffer((int[])currentValue); refIntBuffer = new IntBuffer((int[])currentValue);
ser.Sync(member.Name, ref refIntBuffer); ser.Sync(member.Name, ref refIntBuffer);
currentValue = refIntBuffer.arr; currentValue = refIntBuffer.arr;
break; break;
case "IntBuffer": case "IntBuffer":
refIntBuffer = (IntBuffer)currentValue; refIntBuffer = (IntBuffer)currentValue;
ser.Sync(member.Name, ref refIntBuffer); ser.Sync(member.Name, ref refIntBuffer);
currentValue = refIntBuffer; currentValue = refIntBuffer;
break; break;
case "Point": case "Point":
refPointX = ((Point)currentValue).X; refPointX = ((Point)currentValue).X;
refPointY = ((Point)currentValue).Y; refPointY = ((Point)currentValue).Y;
ser.Sync(member.Name + "_X", ref refPointX); ser.Sync(member.Name + "_X", ref refPointX);
ser.Sync(member.Name + "_Y", ref refPointY); ser.Sync(member.Name + "_Y", ref refPointY);
currentValue = new Point(refPointX, refPointY); currentValue = new Point(refPointX, refPointY);
break; break;
case "Rectangle": case "Rectangle":
refPointX = ((Rectangle)currentValue).X; refPointX = ((Rectangle)currentValue).X;
refPointY = ((Rectangle)currentValue).Y; refPointY = ((Rectangle)currentValue).Y;
refRectWidth = ((Rectangle)currentValue).Width; refRectWidth = ((Rectangle)currentValue).Width;
refRectHeight = ((Rectangle)currentValue).Height; refRectHeight = ((Rectangle)currentValue).Height;
ser.Sync(member.Name + "_X", ref refPointX); ser.Sync(member.Name + "_X", ref refPointX);
ser.Sync(member.Name + "_Y", ref refPointY); ser.Sync(member.Name + "_Y", ref refPointY);
ser.Sync(member.Name + "_Height", ref refRectHeight); ser.Sync(member.Name + "_Height", ref refRectHeight);
ser.Sync(member.Name + "_Width", ref refRectWidth); ser.Sync(member.Name + "_Width", ref refRectWidth);
currentValue = new Rectangle(refPointX, refPointY, refRectWidth, refRectHeight); currentValue = new Rectangle(refPointX, refPointY, refRectWidth, refRectHeight);
break; break;
case "SByte": case "SByte":
refSByte = (SByte)currentValue; refSByte = (SByte)currentValue;
ser.Sync(member.Name, ref refSByte); ser.Sync(member.Name, ref refSByte);
currentValue = refSByte; currentValue = refSByte;
break; break;
case "UInt16": case "UInt16":
refUInt16 = (UInt16)currentValue; refUInt16 = (UInt16)currentValue;
ser.Sync(member.Name, ref refUInt16); ser.Sync(member.Name, ref refUInt16);
currentValue = refUInt16; currentValue = refUInt16;
break; break;
case "UInt32": case "UInt32":
refUInt32 = (UInt32)currentValue; refUInt32 = (UInt32)currentValue;
ser.Sync(member.Name, ref refUInt32); ser.Sync(member.Name, ref refUInt32);
currentValue = refUInt32; currentValue = refUInt32;
break; break;
default: default:
fail = true; fail = true;
break; break;
} }
} }
if (member.MemberType == MemberTypes.Property) if (member.MemberType == MemberTypes.Property)
{ {
if (propInfo.CanWrite && !fail) if (propInfo.CanWrite && !fail)
{ {
MethodInfo setMethod = propInfo.GetSetMethod(); MethodInfo setMethod = propInfo.GetSetMethod();
setMethod.Invoke(obj, new object[] { currentValue }); setMethod.Invoke(obj, new object[] { currentValue });
} }
} }
if (member.MemberType == MemberTypes.Field) if (member.MemberType == MemberTypes.Field)
{ {
fieldInfo.SetValue(obj, currentValue); fieldInfo.SetValue(obj, currentValue);
} }
} }
} }
} }
} }
} }

View File

@ -1,4 +1,4 @@
namespace BizHawk.Emulation.Computers.Commodore64.Tape namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
// common tape drive that works with the C64. // common tape drive that works with the C64.